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);
}
}
dividers.push_back (d);
}
+void
+Pane::handle_child_visibility ()
+{
+ reallocate (get_allocation());
+}
+
void
Pane::on_add (Widget* w)
{
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 ();
-
for (Children::iterator c = children.begin(); c != children.end(); ++c) {
if (c->w == w) {
children.erase (c);
break;
}
}
+
+ w->unparent ();
}
void
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);
}
child->w->size_allocate (child_alloc);
- ++child;
- 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;
}
}
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 ();