diff --git a/src/gui/widgets/panel-bar.cpp b/src/gui/widgets/panel-bar.cpp index 1042be5c9..416574584 100644 --- a/src/gui/widgets/panel-bar.cpp +++ b/src/gui/widgets/panel-bar.cpp @@ -24,12 +24,12 @@ #include "../util/rectangle.hpp" #include +#include using namespace Gtk; using namespace Glib; using namespace sigc; - -const int DragHandleSize = 10; +using namespace std; namespace gui { namespace widgets { @@ -44,5 +44,57 @@ PanelBar::PanelBar(const gchar *stock_id) : pack_start(panelButton, PACK_SHRINK); } +void +PanelBar::on_realize() +{ + set_flags(Gtk::NO_WINDOW); + + // Call base class: + Gtk::Container::on_realize(); + + // Create the GdkWindow: + GdkWindowAttr attributes; + memset(&attributes, 0, sizeof(attributes)); + + const Allocation allocation(get_allocation()); + + // Set initial position and size of the Gdk::Window: + attributes.x = allocation.get_x(); + attributes.y = allocation.get_y(); + attributes.width = allocation.get_width(); + attributes.height = allocation.get_height(); + + attributes.event_mask = GDK_ALL_EVENTS_MASK; + attributes.window_type = GDK_WINDOW_CHILD; + attributes.wclass = GDK_INPUT_OUTPUT; + + window = Gdk::Window::create(get_window(), &attributes, + GDK_WA_X | GDK_WA_Y); + + window->set_user_data(gobj()); + window->set_cursor(Gdk::Cursor(Gdk::LEFT_PTR)); + + set_window(window); + unset_flags(Gtk::NO_WINDOW); + + unset_bg(STATE_NORMAL); +} + +void +PanelBar::on_size_allocate(Gtk::Allocation& allocation) +{ + if(window) + { + const Requisition requisition(get_requisition()); + const int width = max(min(requisition.width, + allocation.get_width()), 0); + window->move_resize(allocation.get_x(), allocation.get_y(), + width, allocation.get_height()); + } + + allocation.set_x(0); + HBox::on_size_allocate(allocation); +} + } // widgets } // gui diff --git a/src/gui/widgets/panel-bar.hpp b/src/gui/widgets/panel-bar.hpp index b8d837fec..df4485d4f 100644 --- a/src/gui/widgets/panel-bar.hpp +++ b/src/gui/widgets/panel-bar.hpp @@ -45,7 +45,19 @@ public: * panel. **/ PanelBar(const gchar *stock_id); - + +private: + + /** + * An override to intercept realize events. + **/ + void on_realize(); + + /** + * An override to intercept size allocate events. + **/ + void on_size_allocate(Gtk::Allocation& allocation); + private: /** @@ -53,6 +65,13 @@ private: * the corner of the bar. **/ MenuButton panelButton; + + /** + * The bar window. + * @remarks This window is used only to set the cursor as an arrow for + * any child widgets. + **/ + Glib::RefPtr window; }; } // gui