From 00f29ea3d55d79f6e47e560b72d1ab713445ec65 Mon Sep 17 00:00:00 2001 From: Michael Fisher Date: Wed, 15 Aug 2012 00:32:35 -0500 Subject: [PATCH] Aggressive code pruning in the ButtonBar. Again, default event handlers appear to be working better than the previous overrides. Subject to re-implementation --- src/gui/widgets/button-bar.cpp | 160 +++------------------------------ src/gui/widgets/button-bar.hpp | 34 +------ 2 files changed, 12 insertions(+), 182 deletions(-) diff --git a/src/gui/widgets/button-bar.cpp b/src/gui/widgets/button-bar.cpp index ae4971d59..7c3a77a75 100644 --- a/src/gui/widgets/button-bar.cpp +++ b/src/gui/widgets/button-bar.cpp @@ -26,158 +26,20 @@ #include using namespace Gtk; -using namespace Glib; -using namespace sigc; -using namespace std; namespace gui { namespace widgets { -ButtonBar::ButtonBar() -: last_width (calculate_width()) -{ - set_orientation(Gtk::ORIENTATION_HORIZONTAL); - set_has_window(false); -} - -void -ButtonBar::append(Widget &widget) -{ - pack_start(widget, Gtk::PACK_SHRINK); - last_width = calculate_width(); -} - - -void -ButtonBar::on_size_request(Gtk::Requisition* requisition) -{ -#if 0 - REQUIRE(requisition); - - requisition->width = 0; - requisition->height = 0; + ButtonBar::ButtonBar() + { + set_orientation(ORIENTATION_HORIZONTAL); + set_has_window(false); + } - Box::BoxList &list = children(); - Box::BoxList::const_iterator i; - for(i = list.begin(); i != list.end(); i++) - { - Widget *widget = (*i).get_widget(); - REQUIRE(widget); - - Requisition child_requisition = widget->size_request(); - requisition->width += child_requisition.width; - requisition->height = max(requisition->height, - child_requisition.height); - } - - ENSURE(requisition->width >= 0); - ENSURE(requisition->height >= 0); -#endif -} + void + ButtonBar::append(Widget &widget) + { + pack_start(widget, PACK_SHRINK); + } -int -ButtonBar::calculate_width() -{ - typedef vector BoxList; - BoxList list = get_children(); - BoxList::const_iterator i; - - int w = 0; - for(i = list.begin(); i != list.end(); i++) - { - Widget *widget = *i; - REQUIRE(widget); - w += widget->get_width(); - } - REQUIRE(w >= 0); - return w; -} - -Gtk::SizeRequestMode -ButtonBar::get_request_mode_vfunc() const -{ - return Gtk::SIZE_REQUEST_CONSTANT_SIZE; -} - -void -ButtonBar::get_preferred_width_vfunc(int& minimum_width, - int& natural_width) const -{ - minimum_width = natural_width = last_width; -} - -void -ButtonBar::get_preferred_height_for_width_vfunc(int width, - int& minimum_height, - int& natural_height) const -{ - Gtk::Box::get_preferred_height_for_width_vfunc( - width, minimum_height, natural_height - ); -} - -void -ButtonBar::get_preferred_height_vfunc(int& minimum_height, - int& natural_height) const -{ - FIXME("Calculate height from child widgets"); - minimum_height = natural_height = 30; -} - -void -ButtonBar::get_preferred_width_for_height_vfunc(int height, - int& minimum_width, - int& natural_width) const -{ - minimum_width = natural_width = last_width; -} - - -void -ButtonBar::on_size_allocate(Gtk::Allocation& allocation) -{ - //Use the offered allocation for this container: - set_allocation(allocation); - - int offset = 0; - typedef vector BoxList; - BoxList list = get_children(); - BoxList::const_iterator i; - - for(i = list.begin(); i != list.end(); i++) - { - Widget *widget = *i; - REQUIRE(widget); - - int cw,ch; - widget->get_size_request(cw,ch); - Gtk::Allocation child_allocation( - allocation.get_x() + offset, - allocation.get_y(), - cw, ch); - - offset += cw; - - if(get_direction() == TEXT_DIR_RTL) - { - child_allocation.set_x( - 2*allocation.get_x() + allocation.get_width() - - child_allocation.get_x() - child_allocation.get_width()); - } - - if(offset > allocation.get_width()) - widget->set_child_visible(false); - else - { - widget->size_allocate(child_allocation); - widget->set_child_visible(true); - } - } - - /* In case we get resized */ - last_width = calculate_width(); -} - - -} // widgets -} // gui +}} /* gui::widgets */ diff --git a/src/gui/widgets/button-bar.hpp b/src/gui/widgets/button-bar.hpp index 3111a1ef5..d141ed659 100644 --- a/src/gui/widgets/button-bar.hpp +++ b/src/gui/widgets/button-bar.hpp @@ -59,40 +59,8 @@ public: button.signal_clicked().connect(clicked_slot); append(button); } - -private: - int calculate_width(); - - /* ===== Overrides ===== */ - - /** - * An event handler that is called to offer an allocation to this - * widget. - * @param requisition The area offered for this widget. - */ - void on_size_request(Gtk::Requisition* requisition); - - virtual Gtk::SizeRequestMode get_request_mode_vfunc() const; - virtual void get_preferred_width_vfunc(int& minimum_width, int& natural_width) const; - virtual void get_preferred_height_for_width_vfunc(int width, int& minimum_height, int& natural_height) const; - virtual void get_preferred_height_vfunc(int& minimum_height, int& natural_height) const; - virtual void get_preferred_width_for_height_vfunc(int height, int& minimum_width, int& natural_width) const; - - /** - * An event handler that is called to notify this widget to allocate - * a given area for itself. - * @param allocation The area to allocate for this widget. - */ - virtual void on_size_allocate(Gtk::Allocation& allocation); - - /** - * The last stored width for this widget - */ - int last_width; }; -} // gui -} // widgets +}} /* gui::widgets */ #endif // BUTTON_BAR_HPP -