2016-05-25 23:31:32 -04:00
|
|
|
/*
|
2019-08-02 22:40:09 -04:00
|
|
|
* Copyright (C) 2016 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2017 Robin Gareus <robin@gareus.org>
|
|
|
|
* Copyright (C) 2018 Ben Loftis <ben@harrisonconsoles.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2016-05-25 23:31:32 -04:00
|
|
|
|
2017-01-02 11:13:56 -05:00
|
|
|
#include <assert.h>
|
2016-05-27 12:58:55 -04:00
|
|
|
#include <gdkmm/cursor.h>
|
2017-07-16 22:55:52 -04:00
|
|
|
|
|
|
|
#include "widgets/pane.h"
|
2016-05-25 23:31:32 -04:00
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2016-05-25 23:31:32 -04:00
|
|
|
|
|
|
|
using namespace std;
|
2017-07-16 22:55:52 -04:00
|
|
|
using namespace Gtk;
|
|
|
|
using namespace PBD;
|
|
|
|
using namespace ArdourWidgets;
|
2016-05-25 23:31:32 -04:00
|
|
|
|
|
|
|
Pane::Pane (bool h)
|
|
|
|
: horizontal (h)
|
2016-05-27 12:58:55 -04:00
|
|
|
, did_move (false)
|
2018-02-12 17:16:09 -05:00
|
|
|
, divider_width (5)
|
2016-06-13 09:52:54 -04:00
|
|
|
, check_fract (false)
|
2016-05-25 23:31:32 -04:00
|
|
|
{
|
2016-05-27 12:58:55 -04:00
|
|
|
using namespace Gdk;
|
|
|
|
|
2016-05-27 11:16:01 -04:00
|
|
|
set_name ("Pane");
|
2016-05-25 23:31:32 -04:00
|
|
|
set_has_window (false);
|
2016-05-27 12:58:55 -04:00
|
|
|
|
|
|
|
if (horizontal) {
|
|
|
|
drag_cursor = Cursor (SB_H_DOUBLE_ARROW);
|
|
|
|
} else {
|
2016-05-28 10:29:47 -04:00
|
|
|
drag_cursor = Cursor (SB_V_DOUBLE_ARROW);
|
2016-05-27 12:58:55 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-06 16:05:25 -04:00
|
|
|
Pane::~Pane ()
|
|
|
|
{
|
|
|
|
for (Children::iterator c = children.begin(); c != children.end(); ++c) {
|
2017-01-08 06:29:30 -05:00
|
|
|
(*c)->show_con.disconnect ();
|
|
|
|
(*c)->hide_con.disconnect ();
|
2017-01-19 21:13:41 -05:00
|
|
|
if ((*c)->w) {
|
|
|
|
(*c)->w->remove_destroy_notify_callback ((*c).get());
|
|
|
|
(*c)->w->unparent ();
|
|
|
|
}
|
2016-06-06 16:05:25 -04:00
|
|
|
}
|
2017-01-08 06:29:30 -05:00
|
|
|
children.clear ();
|
2016-06-06 16:05:25 -04:00
|
|
|
}
|
|
|
|
|
2016-05-27 21:26:37 -04:00
|
|
|
void
|
2016-05-28 10:07:41 -04:00
|
|
|
Pane::set_child_minsize (Gtk::Widget const& w, int32_t minsize)
|
2016-05-27 21:26:37 -04:00
|
|
|
{
|
2016-05-28 10:07:41 -04:00
|
|
|
for (Children::iterator c = children.begin(); c != children.end(); ++c) {
|
2017-01-08 06:29:30 -05:00
|
|
|
if ((*c)->w == &w) {
|
|
|
|
(*c)->minsize = minsize;
|
2016-05-28 10:07:41 -04:00
|
|
|
break;
|
2016-05-27 21:26:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-27 12:58:55 -04:00
|
|
|
void
|
|
|
|
Pane::set_drag_cursor (Gdk::Cursor c)
|
|
|
|
{
|
|
|
|
drag_cursor = c;
|
2016-05-25 23:31:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Pane::on_size_request (GtkRequisition* req)
|
|
|
|
{
|
|
|
|
GtkRequisition largest;
|
|
|
|
|
|
|
|
/* iterate over all children, get their size requests */
|
|
|
|
|
2016-05-27 12:58:55 -04:00
|
|
|
/* horizontal pane is as high as its tallest child, including the dividers.
|
|
|
|
* Its width is the sum of the children plus the dividers.
|
2016-05-25 23:31:32 -04:00
|
|
|
*
|
2016-05-27 12:58:55 -04:00
|
|
|
* vertical pane is as wide as its widest child, including the dividers.
|
|
|
|
* Its height is the sum of the children plus the dividers.
|
2016-05-25 23:31:32 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (horizontal) {
|
|
|
|
largest.width = (children.size() - 1) * divider_width;
|
|
|
|
largest.height = 0;
|
|
|
|
} else {
|
|
|
|
largest.height = (children.size() - 1) * divider_width;
|
|
|
|
largest.width = 0;
|
|
|
|
}
|
|
|
|
|
2017-01-08 06:29:30 -05:00
|
|
|
for (Children::iterator c = children.begin(); c != children.end(); ++c) {
|
2022-01-26 15:21:06 -05:00
|
|
|
if (!(*c)->w->get_visible ()) {
|
2017-01-02 11:13:56 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-01-26 16:00:02 -05:00
|
|
|
GtkRequisition r = (*c)->w->size_request ();
|
2016-05-25 23:31:32 -04:00
|
|
|
|
|
|
|
if (horizontal) {
|
|
|
|
largest.height = max (largest.height, r.height);
|
2017-01-08 06:29:30 -05:00
|
|
|
if ((*c)->minsize) {
|
|
|
|
largest.width += (*c)->minsize;
|
2017-01-02 11:13:56 -05:00
|
|
|
} else {
|
|
|
|
largest.width += r.width;
|
|
|
|
}
|
2016-05-25 23:31:32 -04:00
|
|
|
} else {
|
|
|
|
largest.width = max (largest.width, r.width);
|
2017-01-08 06:29:30 -05:00
|
|
|
if ((*c)->minsize) {
|
|
|
|
largest.height += (*c)->minsize;
|
2017-01-02 11:13:56 -05:00
|
|
|
} else {
|
|
|
|
largest.height += r.height;
|
|
|
|
}
|
2016-05-25 23:31:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*req = largest;
|
|
|
|
}
|
|
|
|
|
|
|
|
GType
|
|
|
|
Pane::child_type_vfunc() const
|
|
|
|
{
|
2016-05-27 12:58:55 -04:00
|
|
|
/* We accept any number of any types of widgets */
|
2016-05-25 23:31:32 -04:00
|
|
|
return Gtk::Widget::get_type();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Pane::add_divider ()
|
|
|
|
{
|
|
|
|
Divider* d = new Divider;
|
2016-06-01 22:23:34 -04:00
|
|
|
d->set_name (X_("Divider"));
|
2016-05-25 23:31:32 -04:00
|
|
|
d->signal_button_press_event().connect (sigc::bind (sigc::mem_fun (*this, &Pane::handle_press_event), d), false);
|
|
|
|
d->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &Pane::handle_release_event), d), false);
|
|
|
|
d->signal_motion_notify_event().connect (sigc::bind (sigc::mem_fun (*this, &Pane::handle_motion_event), d), false);
|
2016-05-27 12:58:55 -04:00
|
|
|
d->signal_enter_notify_event().connect (sigc::bind (sigc::mem_fun (*this, &Pane::handle_enter_event), d), false);
|
|
|
|
d->signal_leave_notify_event().connect (sigc::bind (sigc::mem_fun (*this, &Pane::handle_leave_event), d), false);
|
2016-05-25 23:31:32 -04:00
|
|
|
d->set_parent (*this);
|
|
|
|
d->show ();
|
2016-05-26 10:45:41 -04:00
|
|
|
d->fract = 0.5;
|
2016-05-25 23:31:32 -04:00
|
|
|
dividers.push_back (d);
|
|
|
|
}
|
|
|
|
|
2016-05-28 10:25:43 -04:00
|
|
|
void
|
|
|
|
Pane::handle_child_visibility ()
|
|
|
|
{
|
|
|
|
reallocate (get_allocation());
|
|
|
|
}
|
|
|
|
|
2016-05-25 23:31:32 -04:00
|
|
|
void
|
|
|
|
Pane::on_add (Widget* w)
|
|
|
|
{
|
2017-01-19 21:13:41 -05:00
|
|
|
children.push_back (boost::shared_ptr<Child> (new Child (this, w, 0)));
|
|
|
|
Child* kid = children.back ().get();
|
2016-05-25 23:31:32 -04:00
|
|
|
|
|
|
|
w->set_parent (*this);
|
2016-07-19 23:31:07 -04:00
|
|
|
/* Gtkmm 2.4 does not correctly arrange for ::on_remove() to be called
|
|
|
|
for custom containers that derive from Gtk::Container. So ... we need
|
|
|
|
to ensure that we hear about child destruction ourselves.
|
|
|
|
*/
|
2017-01-08 06:29:30 -05:00
|
|
|
w->add_destroy_notify_callback (kid, &Pane::notify_child_destroyed);
|
2016-05-25 23:31:32 -04:00
|
|
|
|
2017-01-08 06:29:30 -05:00
|
|
|
kid->show_con = w->signal_show().connect (sigc::mem_fun (*this, &Pane::handle_child_visibility));
|
|
|
|
kid->hide_con = w->signal_hide().connect (sigc::mem_fun (*this, &Pane::handle_child_visibility));
|
2016-05-28 10:25:43 -04:00
|
|
|
|
2016-05-25 23:31:32 -04:00
|
|
|
while (dividers.size() < (children.size() - 1)) {
|
|
|
|
add_divider ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 23:31:07 -04:00
|
|
|
void*
|
|
|
|
Pane::notify_child_destroyed (void* data)
|
|
|
|
{
|
|
|
|
Child* child = reinterpret_cast<Child*> (data);
|
|
|
|
return child->pane->child_destroyed (child->w);
|
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
|
|
|
Pane::child_destroyed (Gtk::Widget* w)
|
|
|
|
{
|
|
|
|
for (Children::iterator c = children.begin(); c != children.end(); ++c) {
|
2017-01-08 06:29:30 -05:00
|
|
|
if ((*c)->w == w) {
|
|
|
|
(*c)->show_con.disconnect ();
|
|
|
|
(*c)->hide_con.disconnect ();
|
2017-01-19 21:13:41 -05:00
|
|
|
(*c)->w = NULL; // mark invalid
|
2016-07-19 23:31:07 -04:00
|
|
|
children.erase (c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-25 23:31:32 -04:00
|
|
|
void
|
|
|
|
Pane::on_remove (Widget* w)
|
|
|
|
{
|
2016-05-27 21:26:37 -04:00
|
|
|
for (Children::iterator c = children.begin(); c != children.end(); ++c) {
|
2017-01-08 06:29:30 -05:00
|
|
|
if ((*c)->w == w) {
|
|
|
|
(*c)->show_con.disconnect ();
|
|
|
|
(*c)->hide_con.disconnect ();
|
2017-01-19 21:13:41 -05:00
|
|
|
w->remove_destroy_notify_callback ((*c).get());
|
2016-06-06 16:05:25 -04:00
|
|
|
w->unparent ();
|
2017-01-19 21:13:41 -05:00
|
|
|
(*c)->w = NULL; // mark invalid
|
2016-05-27 21:26:37 -04:00
|
|
|
children.erase (c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-05-25 23:31:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Pane::on_size_allocate (Gtk::Allocation& alloc)
|
|
|
|
{
|
|
|
|
reallocate (alloc);
|
|
|
|
Container::on_size_allocate (alloc);
|
2017-01-02 11:13:56 -05:00
|
|
|
|
|
|
|
/* minumum pane size constraints */
|
|
|
|
Dividers::size_type div = 0;
|
|
|
|
for (Dividers::const_iterator d = dividers.begin(); d != dividers.end(); ++d, ++div) {
|
2017-01-08 11:44:40 -05:00
|
|
|
// XXX skip dividers that were just hidden in reallocate()
|
2017-01-02 11:13:56 -05:00
|
|
|
Pane::set_divider (div, (*d)->fract);
|
|
|
|
}
|
|
|
|
// TODO this needs tweaking for panes with > 2 children
|
|
|
|
// if a child grows, re-check the ones before it.
|
|
|
|
assert (dividers.size () < 3);
|
2016-05-25 23:31:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Pane::reallocate (Gtk::Allocation const & alloc)
|
|
|
|
{
|
2017-01-08 11:45:21 -05:00
|
|
|
int remaining;
|
|
|
|
int xpos = alloc.get_x();
|
|
|
|
int ypos = alloc.get_y();
|
|
|
|
float fract;
|
|
|
|
|
|
|
|
if (children.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (children.size() == 1) {
|
|
|
|
/* only child gets the full allocation */
|
2022-01-26 15:21:06 -05:00
|
|
|
if (children.front()->w->get_visible ()) {
|
2017-01-08 11:45:21 -05:00
|
|
|
children.front()->w->size_allocate (alloc);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (horizontal) {
|
|
|
|
remaining = alloc.get_width ();
|
|
|
|
} else {
|
|
|
|
remaining = alloc.get_height ();
|
|
|
|
}
|
|
|
|
|
|
|
|
Children::iterator child;
|
|
|
|
Children::iterator next;
|
|
|
|
Dividers::iterator div;
|
|
|
|
|
|
|
|
child = children.begin();
|
|
|
|
|
|
|
|
/* skip initial hidden children */
|
|
|
|
|
|
|
|
while (child != children.end()) {
|
2022-01-26 15:21:06 -05:00
|
|
|
if ((*child)->w->get_visible()) {
|
2017-01-08 11:45:21 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
++child;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (div = dividers.begin(); child != children.end(); ) {
|
|
|
|
|
|
|
|
Gtk::Allocation child_alloc;
|
|
|
|
|
|
|
|
next = child;
|
|
|
|
|
|
|
|
/* Move on to next *visible* child */
|
|
|
|
|
|
|
|
while (++next != children.end()) {
|
2022-01-26 15:21:06 -05:00
|
|
|
if ((*next)->w->get_visible()) {
|
2017-01-08 11:45:21 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
child_alloc.set_x (xpos);
|
|
|
|
child_alloc.set_y (ypos);
|
|
|
|
|
|
|
|
if (next == children.end()) {
|
|
|
|
/* last child gets all the remaining space */
|
|
|
|
fract = 1.0;
|
|
|
|
} else {
|
|
|
|
/* child gets the fraction of the remaining space given by the divider that follows it */
|
|
|
|
fract = (*div)->fract;
|
|
|
|
}
|
|
|
|
|
2022-01-26 16:00:02 -05:00
|
|
|
Gtk::Requisition cr = (*child)->w->size_request ();
|
2017-01-08 11:45:21 -05:00
|
|
|
|
|
|
|
if (horizontal) {
|
|
|
|
child_alloc.set_width ((gint) floor (remaining * fract));
|
|
|
|
child_alloc.set_height (alloc.get_height());
|
|
|
|
remaining = max (0, (remaining - child_alloc.get_width()));
|
|
|
|
xpos += child_alloc.get_width();
|
|
|
|
} else {
|
|
|
|
child_alloc.set_width (alloc.get_width());
|
|
|
|
child_alloc.set_height ((gint) floor (remaining * fract));
|
|
|
|
remaining = max (0, (remaining - child_alloc.get_height()));
|
|
|
|
ypos += child_alloc.get_height ();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*child)->minsize) {
|
|
|
|
if (horizontal) {
|
|
|
|
child_alloc.set_width (max (child_alloc.get_width(), (*child)->minsize));
|
|
|
|
} else {
|
|
|
|
child_alloc.set_height (max (child_alloc.get_height(), (*child)->minsize));
|
|
|
|
}
|
2022-01-26 15:21:06 -05:00
|
|
|
} else if (!check_fract && (*child)->w->get_visible ()) {
|
2022-01-26 11:09:39 -05:00
|
|
|
if (horizontal) {
|
|
|
|
child_alloc.set_width (max (child_alloc.get_width(), cr.width));
|
|
|
|
} else {
|
|
|
|
child_alloc.set_height (max (child_alloc.get_height(), cr.height));
|
|
|
|
}
|
2017-01-08 11:45:21 -05:00
|
|
|
}
|
|
|
|
|
2022-01-26 15:21:06 -05:00
|
|
|
if ((*child)->w->get_visible ()) {
|
2017-01-08 11:45:21 -05:00
|
|
|
(*child)->w->size_allocate (child_alloc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (next == children.end()) {
|
|
|
|
/* done, no more children, no need for a divider */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
child = next;
|
|
|
|
|
|
|
|
/* add a divider between children */
|
|
|
|
|
|
|
|
Gtk::Allocation divider_allocation;
|
|
|
|
|
|
|
|
divider_allocation.set_x (xpos);
|
|
|
|
divider_allocation.set_y (ypos);
|
|
|
|
|
|
|
|
if (horizontal) {
|
|
|
|
divider_allocation.set_width (divider_width);
|
|
|
|
divider_allocation.set_height (alloc.get_height());
|
|
|
|
remaining = max (0, remaining - divider_width);
|
|
|
|
xpos += divider_width;
|
|
|
|
} else {
|
|
|
|
divider_allocation.set_width (alloc.get_width());
|
|
|
|
divider_allocation.set_height (divider_width);
|
|
|
|
remaining = max (0, remaining - divider_width);
|
|
|
|
ypos += divider_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*div)->size_allocate (divider_allocation);
|
|
|
|
(*div)->show ();
|
|
|
|
++div;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* hide all remaining dividers */
|
|
|
|
|
|
|
|
while (div != dividers.end()) {
|
|
|
|
(*div)->hide ();
|
|
|
|
++div;
|
|
|
|
}
|
2016-05-25 23:31:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Pane::on_expose_event (GdkEventExpose* ev)
|
|
|
|
{
|
2016-05-27 12:58:55 -04:00
|
|
|
Children::iterator child;
|
|
|
|
Dividers::iterator div;
|
2016-05-25 23:31:32 -04:00
|
|
|
|
2016-06-08 12:26:24 -04:00
|
|
|
for (child = children.begin(), div = dividers.begin(); child != children.end(); ++child) {
|
2016-05-25 23:31:32 -04:00
|
|
|
|
2022-01-26 15:21:06 -05:00
|
|
|
if ((*child)->w->get_visible()) {
|
2017-01-08 06:29:30 -05:00
|
|
|
propagate_expose (*((*child)->w), ev);
|
2016-05-27 21:26:37 -04:00
|
|
|
}
|
2016-05-25 23:31:32 -04:00
|
|
|
|
2016-06-08 12:26:24 -04:00
|
|
|
if (div != dividers.end()) {
|
2022-01-26 15:21:06 -05:00
|
|
|
if ((*div)->get_visible()) {
|
2016-06-08 12:26:24 -04:00
|
|
|
propagate_expose (**div, ev);
|
|
|
|
}
|
|
|
|
++div;
|
2016-05-25 23:31:32 -04:00
|
|
|
}
|
2017-01-08 11:45:21 -05:00
|
|
|
}
|
2016-05-25 23:31:32 -04:00
|
|
|
|
2017-01-08 11:45:21 -05:00
|
|
|
return true;
|
2016-05-25 23:31:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-05-27 11:16:01 -04:00
|
|
|
Pane::handle_press_event (GdkEventButton* ev, Divider* d)
|
2016-05-25 23:31:32 -04:00
|
|
|
{
|
2016-05-27 11:16:01 -04:00
|
|
|
d->dragging = true;
|
|
|
|
d->queue_draw ();
|
|
|
|
|
2016-05-25 23:31:32 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-05-27 11:16:01 -04:00
|
|
|
Pane::handle_release_event (GdkEventButton* ev, Divider* d)
|
2016-05-25 23:31:32 -04:00
|
|
|
{
|
2016-05-27 11:16:01 -04:00
|
|
|
d->dragging = false;
|
2016-05-27 12:58:55 -04:00
|
|
|
|
2016-07-19 23:31:30 -04:00
|
|
|
if (did_move && !children.empty()) {
|
2017-01-08 06:29:30 -05:00
|
|
|
children.front()->w->queue_resize ();
|
2016-05-27 12:58:55 -04:00
|
|
|
did_move = false;
|
|
|
|
}
|
2016-05-27 11:16:01 -04:00
|
|
|
|
2016-05-25 23:31:32 -04:00
|
|
|
return false;
|
|
|
|
}
|
2016-06-13 09:52:54 -04:00
|
|
|
void
|
|
|
|
Pane::set_check_divider_position (bool yn)
|
|
|
|
{
|
|
|
|
check_fract = yn;
|
|
|
|
}
|
|
|
|
|
2017-01-02 11:13:56 -05:00
|
|
|
float
|
|
|
|
Pane::constrain_fract (Dividers::size_type div, float fract)
|
2016-06-13 09:52:54 -04:00
|
|
|
{
|
2017-01-02 11:13:56 -05:00
|
|
|
if (get_allocation().get_width() == 1 && get_allocation().get_height() == 1) {
|
|
|
|
/* space not * allocated - * divider being set from startup code. Let it pass,
|
|
|
|
* since our goal is mostly to catch drags to a position that will interfere with window
|
|
|
|
* resizing.
|
|
|
|
*/
|
|
|
|
return fract;
|
2016-06-13 09:52:54 -04:00
|
|
|
}
|
|
|
|
|
2017-01-08 11:44:40 -05:00
|
|
|
if (children.size () <= div + 1) { return fract; } // XXX remove once hidden divs are skipped
|
|
|
|
assert(children.size () > div + 1);
|
|
|
|
|
2017-01-02 11:13:56 -05:00
|
|
|
const float size = horizontal ? get_allocation().get_width() : get_allocation().get_height();
|
2016-07-18 12:49:26 -04:00
|
|
|
|
2017-01-02 11:13:56 -05:00
|
|
|
// TODO: optimize: cache in Pane::on_size_request
|
2017-01-08 06:29:30 -05:00
|
|
|
Gtk::Requisition prev_req(children.at (div)->w->size_request ());
|
|
|
|
Gtk::Requisition next_req(children.at (div + 1)->w->size_request ());
|
2017-01-08 11:44:40 -05:00
|
|
|
float prev = (horizontal ? prev_req.width : prev_req.height);
|
|
|
|
float next = (horizontal ? next_req.width : next_req.height);
|
2017-01-02 11:13:56 -05:00
|
|
|
|
2017-01-08 06:29:30 -05:00
|
|
|
if (children.at (div)->minsize) {
|
|
|
|
prev = children.at (div)->minsize;
|
2016-07-18 12:49:26 -04:00
|
|
|
}
|
2017-01-08 06:29:30 -05:00
|
|
|
if (children.at (div + 1)->minsize) {
|
|
|
|
next = children.at (div + 1)->minsize;
|
2017-01-02 11:13:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (size * fract < prev) {
|
|
|
|
return prev / size;
|
|
|
|
}
|
|
|
|
if (size * (1.f - fract) < next) {
|
|
|
|
return 1.f - next / size;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!check_fract) {
|
|
|
|
return fract;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __APPLE__
|
2016-07-18 12:49:26 -04:00
|
|
|
|
2016-06-13 09:52:54 -04:00
|
|
|
/* On Quartz, if the pane handle (divider) gets to
|
|
|
|
be adjacent to the window edge, you can no longer grab it:
|
|
|
|
any attempt to do so is interpreted by the Quartz window
|
|
|
|
manager ("Finder") as a resize drag on the window edge.
|
|
|
|
*/
|
|
|
|
|
2017-01-02 11:13:56 -05:00
|
|
|
|
2016-06-13 09:52:54 -04:00
|
|
|
if (horizontal) {
|
|
|
|
if (div == dividers.size() - 1) {
|
|
|
|
if (get_allocation().get_width() * (1.0 - fract) < (divider_width*2)) {
|
|
|
|
/* too close to right edge */
|
2017-01-02 11:13:56 -05:00
|
|
|
return 1.f - (divider_width * 2.f) / (float) get_allocation().get_width();
|
2016-06-13 09:52:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (div == 0) {
|
|
|
|
if (get_allocation().get_width() * fract < (divider_width*2)) {
|
|
|
|
/* too close to left edge */
|
2017-01-02 11:13:56 -05:00
|
|
|
return (divider_width * 2.f) / (float)get_allocation().get_width();
|
2016-06-13 09:52:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (div == dividers.size() - 1) {
|
|
|
|
if (get_allocation().get_height() * (1.0 - fract) < (divider_width*2)) {
|
|
|
|
/* too close to bottom */
|
2017-01-02 11:13:56 -05:00
|
|
|
return 1.f - (divider_width * 2.f) / (float) get_allocation().get_height();
|
2016-06-13 09:52:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (div == 0) {
|
2017-01-02 11:13:56 -05:00
|
|
|
if (get_allocation().get_height() * fract < (divider_width*2)) {
|
2016-06-13 09:52:54 -04:00
|
|
|
/* too close to top */
|
2017-01-02 11:13:56 -05:00
|
|
|
return (divider_width * 2.f) / (float) get_allocation().get_height();
|
2016-06-13 09:52:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2017-01-02 11:13:56 -05:00
|
|
|
return fract;
|
2016-06-13 09:52:54 -04:00
|
|
|
}
|
2016-05-25 23:31:32 -04:00
|
|
|
|
|
|
|
bool
|
|
|
|
Pane::handle_motion_event (GdkEventMotion* ev, Divider* d)
|
|
|
|
{
|
2016-05-27 12:58:55 -04:00
|
|
|
did_move = true;
|
|
|
|
|
2016-05-27 11:16:01 -04:00
|
|
|
if (!d->dragging) {
|
2016-05-25 23:31:32 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* determine new position for handle */
|
|
|
|
|
|
|
|
float new_fract;
|
|
|
|
int px, py;
|
|
|
|
|
|
|
|
d->translate_coordinates (*this, ev->x, ev->y, px, py);
|
|
|
|
|
|
|
|
Dividers::iterator prev = dividers.end();
|
2016-06-13 09:52:54 -04:00
|
|
|
Dividers::size_type div = 0;
|
2016-05-25 23:31:32 -04:00
|
|
|
|
2016-06-13 09:52:54 -04:00
|
|
|
for (Dividers::iterator di = dividers.begin(); di != dividers.end(); ++di, ++div) {
|
2016-05-25 23:31:32 -04:00
|
|
|
if (*di == d) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
prev = di;
|
|
|
|
}
|
|
|
|
|
|
|
|
int space_remaining;
|
|
|
|
int prev_edge;
|
|
|
|
|
|
|
|
if (horizontal) {
|
|
|
|
if (prev != dividers.end()) {
|
|
|
|
prev_edge = (*prev)->get_allocation().get_x() + (*prev)->get_allocation().get_width();
|
|
|
|
} else {
|
|
|
|
prev_edge = 0;
|
|
|
|
}
|
|
|
|
space_remaining = get_allocation().get_width() - prev_edge;
|
|
|
|
new_fract = (float) (px - prev_edge) / space_remaining;
|
|
|
|
} else {
|
|
|
|
if (prev != dividers.end()) {
|
|
|
|
prev_edge = (*prev)->get_allocation().get_y() + (*prev)->get_allocation().get_height();
|
|
|
|
} else {
|
|
|
|
prev_edge = 0;
|
|
|
|
}
|
|
|
|
space_remaining = get_allocation().get_height() - prev_edge;
|
|
|
|
new_fract = (float) (py - prev_edge) / space_remaining;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_fract = min (1.0f, max (0.0f, new_fract));
|
2017-01-02 11:13:56 -05:00
|
|
|
new_fract = constrain_fract (div, new_fract);
|
2017-01-08 11:44:40 -05:00
|
|
|
new_fract = min (1.0f, max (0.0f, new_fract));
|
2016-06-13 09:52:54 -04:00
|
|
|
|
2016-05-25 23:31:32 -04:00
|
|
|
if (new_fract != d->fract) {
|
|
|
|
d->fract = new_fract;
|
|
|
|
reallocate (get_allocation ());
|
|
|
|
queue_draw ();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Pane::set_divider (Dividers::size_type div, float fract)
|
|
|
|
{
|
2016-05-27 12:58:55 -04:00
|
|
|
Dividers::iterator d = dividers.begin();
|
|
|
|
|
2016-06-06 16:05:43 -04:00
|
|
|
for (d = dividers.begin(); d != dividers.end() && div != 0; ++d, --div) {
|
|
|
|
/* relax */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d == dividers.end()) {
|
|
|
|
/* caller is trying to set divider that does not exist
|
|
|
|
* yet.
|
|
|
|
*/
|
|
|
|
return;
|
2016-05-25 23:31:32 -04:00
|
|
|
}
|
|
|
|
|
2016-05-29 13:47:08 -04:00
|
|
|
fract = max (0.0f, min (1.0f, fract));
|
2017-01-02 11:13:56 -05:00
|
|
|
fract = constrain_fract (div, fract);
|
2017-01-08 11:44:40 -05:00
|
|
|
fract = max (0.0f, min (1.0f, fract));
|
2016-06-13 09:10:36 -04:00
|
|
|
|
2016-05-27 12:58:55 -04:00
|
|
|
if (fract != (*d)->fract) {
|
|
|
|
(*d)->fract = fract;
|
2016-05-25 23:31:32 -04:00
|
|
|
/* our size hasn't changed, but our internal allocations have */
|
|
|
|
reallocate (get_allocation());
|
|
|
|
queue_draw ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
float
|
2022-04-06 23:56:32 -04:00
|
|
|
Pane::get_divider (Dividers::size_type div) const
|
2016-05-25 23:31:32 -04:00
|
|
|
{
|
2022-04-06 23:56:32 -04:00
|
|
|
Dividers::const_iterator d = dividers.begin();
|
2016-05-27 12:58:55 -04:00
|
|
|
|
2016-06-06 16:05:43 -04:00
|
|
|
for (d = dividers.begin(); d != dividers.end() && div != 0; ++d, --div) {
|
|
|
|
/* relax */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d == dividers.end()) {
|
|
|
|
/* caller is trying to set divider that does not exist
|
|
|
|
* yet.
|
|
|
|
*/
|
|
|
|
return -1.0f;
|
2016-05-25 23:31:32 -04:00
|
|
|
}
|
|
|
|
|
2016-05-27 12:58:55 -04:00
|
|
|
return (*d)->fract;
|
2016-05-25 23:31:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Pane::forall_vfunc (gboolean include_internals, GtkCallback callback, gpointer callback_data)
|
|
|
|
{
|
2016-05-27 12:58:55 -04:00
|
|
|
/* since the callback could modify the child list(s), make sure we keep
|
|
|
|
* the iterators safe;
|
|
|
|
*/
|
2017-01-19 21:13:41 -05:00
|
|
|
Children kids (children);
|
|
|
|
for (Children::const_iterator c = kids.begin(); c != kids.end(); ++c) {
|
|
|
|
if ((*c)->w) {
|
|
|
|
callback ((*c)->w->gobj(), callback_data);
|
|
|
|
}
|
2016-05-25 23:31:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (include_internals) {
|
2016-05-27 12:58:55 -04:00
|
|
|
for (Dividers::iterator d = dividers.begin(); d != dividers.end(); ) {
|
|
|
|
Dividers::iterator next = d;
|
|
|
|
++next;
|
2016-05-25 23:31:32 -04:00
|
|
|
callback (GTK_WIDGET((*d)->gobj()), callback_data);
|
2016-05-27 12:58:55 -04:00
|
|
|
d = next;
|
2016-05-25 23:31:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Pane::Divider::Divider ()
|
|
|
|
: fract (0.0)
|
2016-05-27 11:16:01 -04:00
|
|
|
, dragging (false)
|
2016-05-25 23:31:32 -04:00
|
|
|
{
|
2016-05-27 11:16:01 -04:00
|
|
|
set_events (Gdk::EventMask (Gdk::BUTTON_PRESS|
|
|
|
|
Gdk::BUTTON_RELEASE|
|
|
|
|
Gdk::MOTION_NOTIFY|
|
|
|
|
Gdk::ENTER_NOTIFY|
|
|
|
|
Gdk::LEAVE_NOTIFY));
|
2016-05-25 23:31:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Pane::Divider::on_expose_event (GdkEventExpose* ev)
|
|
|
|
{
|
2018-02-12 17:16:09 -05:00
|
|
|
Gdk::Color c = (dragging ? get_style()->get_bg (Gtk::STATE_ACTIVE) :
|
|
|
|
get_style()->get_bg (get_state()));
|
2016-05-25 23:31:32 -04:00
|
|
|
|
|
|
|
Cairo::RefPtr<Cairo::Context> draw_context = get_window()->create_cairo_context ();
|
|
|
|
draw_context->rectangle (ev->area.x, ev->area.y, ev->area.width, ev->area.height);
|
2017-01-08 11:45:21 -05:00
|
|
|
draw_context->clip_preserve ();
|
|
|
|
draw_context->set_source_rgba (c.get_red_p(), c.get_green_p(), c.get_blue_p(), 1.0);
|
|
|
|
draw_context->fill ();
|
2016-05-27 11:16:01 -04:00
|
|
|
|
2017-01-08 11:45:21 -05:00
|
|
|
return true;
|
2016-05-27 11:16:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-05-27 12:58:55 -04:00
|
|
|
Pane::handle_enter_event (GdkEventCrossing*, Divider* d)
|
2016-05-27 11:16:01 -04:00
|
|
|
{
|
2016-05-27 12:58:55 -04:00
|
|
|
d->get_window()->set_cursor (drag_cursor);
|
2018-02-12 17:16:09 -05:00
|
|
|
d->set_state (Gtk::STATE_ACTIVE);
|
2016-05-27 11:16:01 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-05-27 12:58:55 -04:00
|
|
|
Pane::handle_leave_event (GdkEventCrossing*, Divider* d)
|
2016-05-27 11:16:01 -04:00
|
|
|
{
|
2016-05-27 12:58:55 -04:00
|
|
|
d->get_window()->set_cursor ();
|
|
|
|
d->set_state (Gtk::STATE_NORMAL);
|
2016-06-01 22:30:17 -04:00
|
|
|
d->queue_draw ();
|
2016-05-25 23:31:32 -04:00
|
|
|
return true;
|
|
|
|
}
|