Pane::Pane (bool h)
: horizontal (h)
, did_move (false)
- , divider_width (5)
+ , divider_width (2)
{
using namespace Gdk;
if (horizontal) {
drag_cursor = Cursor (SB_H_DOUBLE_ARROW);
} else {
- drag_cursor = Cursor (SB_H_DOUBLE_ARROW);
+ drag_cursor = Cursor (SB_V_DOUBLE_ARROW);
+ }
+}
+
+Pane::~Pane ()
+{
+ for (Children::iterator c = children.begin(); c != children.end(); ++c) {
+ c->w->unparent ();
+ }
+}
+
+void
+Pane::set_child_minsize (Gtk::Widget const& w, int32_t minsize)
+{
+ for (Children::iterator c = children.begin(); c != children.end(); ++c) {
+ if (c->w == &w) {
+ c->minsize = minsize;
+ break;
+ }
}
}
for (Children::iterator child = children.begin(); child != children.end(); ++child) {
GtkRequisition r;
- (*child)->size_request (r);
+ child->w->size_request (r);
if (horizontal) {
largest.height = max (largest.height, r.height);
Pane::add_divider ()
{
Divider* d = new Divider;
+ d->set_name (X_("Divider"));
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);
dividers.push_back (d);
}
+void
+Pane::handle_child_visibility ()
+{
+ reallocate (get_allocation());
+}
+
void
Pane::on_add (Widget* w)
{
- children.push_back (w);
+ children.push_back (Child (w, 0));
w->set_parent (*this);
+ w->signal_show().connect (sigc::mem_fun (*this, &Pane::handle_child_visibility));
+ w->signal_hide().connect (sigc::mem_fun (*this, &Pane::handle_child_visibility));
+
while (dividers.size() < (children.size() - 1)) {
add_divider ();
}
void
Pane::on_remove (Widget* w)
{
- w->unparent ();
- children.remove (w);
+ for (Children::iterator c = children.begin(); c != children.end(); ++c) {
+ if (c->w == w) {
+ w->unparent ();
+ children.erase (c);
+ break;
+ }
+ }
}
void
if (children.size() == 1) {
/* only child gets the full allocation */
- children.front()->size_allocate (alloc);
+ children.front().w->size_allocate (alloc);
return;
}
Children::iterator next;
Dividers::iterator div;
- for (child = children.begin(), div = dividers.begin(); child != children.end(); ) {
+ child = children.begin();
+
+ /* skip initial hidden children */
+
+ while (child != children.end()) {
+ if (child->w->is_visible()) {
+ break;
+ }
+ ++child;
+ }
+
+ for (div = dividers.begin(); child != children.end(); ) {
Gtk::Allocation child_alloc;
+
next = child;
- ++next;
+
+ /* Move on to next *visible* child */
+
+ while (++next != children.end()) {
+ if (next->w->is_visible()) {
+ break;
+ }
+ }
child_alloc.set_x (xpos);
child_alloc.set_y (ypos);
}
Gtk::Requisition cr;
- (*child)->size_request (cr);
+ child->w->size_request (cr);
if (horizontal) {
child_alloc.set_width ((gint) floor (remaining * fract));
ypos += child_alloc.get_height ();
}
- (*child)->size_allocate (child_alloc);
- ++child;
+ 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));
+ }
+ }
+
+ child->w->size_allocate (child_alloc);
- if (child == children.end()) {
+ 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;
}
(*div)->size_allocate (divider_allocation);
+ (*div)->show ();
+ ++div;
+ }
+
+ /* hide all remaining dividers */
+
+ while (div != dividers.end()) {
+ (*div)->hide ();
++div;
}
}
for (child = children.begin(), div = dividers.begin(); child != children.end(); ++child, ++div) {
- propagate_expose (**child, ev);
+ if (child->w->is_visible()) {
+ propagate_expose (*(child->w), ev);
+ }
- if (div != dividers.end()) {
+ if ((div != dividers.end()) && (*div)->is_visible()) {
propagate_expose (**div, ev);
}
}
d->dragging = false;
if (did_move) {
- children.front()->queue_resize ();
+ children.front().w->queue_resize ();
did_move = false;
}
void
Pane::set_divider (Dividers::size_type div, float fract)
{
- bool redraw = false;
-
Dividers::iterator d = dividers.begin();
while (div--) {
}
}
+ fract = max (0.0f, min (1.0f, fract));
+
if (fract != (*d)->fract) {
(*d)->fract = fract;
- redraw = true;
- }
-
- if (redraw) {
/* our size hasn't changed, but our internal allocations have */
reallocate (get_allocation());
queue_draw ();
* the iterators safe;
*/
- for (Children::iterator w = children.begin(); w != children.end(); ) {
- Children::iterator next = w;
+ for (Children::iterator c = children.begin(); c != children.end(); ) {
+ Children::iterator next = c;
++next;
- callback ((*w)->gobj(), callback_data);
- w = next;
+ callback (c->w->gobj(), callback_data);
+ c = next;
}
if (include_internals) {
{
d->get_window()->set_cursor ();
d->set_state (Gtk::STATE_NORMAL);
+ d->queue_draw ();
return true;
}