From d12cb196feed4a81f1f4db3cf1bfc8c51093771d Mon Sep 17 00:00:00 2001 From: "Hombrenatureh.510" Date: Thu, 12 Mar 2015 00:00:02 +0100 Subject: [PATCH] Solving wrong behavior of the MyExpander's Enable button. --- rtgui/guiutils.cc | 35 +++++++++-------------------------- rtgui/guiutils.h | 2 ++ 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/rtgui/guiutils.cc b/rtgui/guiutils.cc index 9835246a2..0a4ec22e4 100644 --- a/rtgui/guiutils.cc +++ b/rtgui/guiutils.cc @@ -380,7 +380,7 @@ void MyExpander::init() { } MyExpander::MyExpander(bool useEnabled, Gtk::Widget* titleWidget) : - enabled(false), inconsistent(false), + enabled(false), inconsistent(false), flushEvent(false), child(NULL), headerWidget(NULL), statusImage(NULL), label(NULL), useEnabled(useEnabled) { @@ -425,7 +425,7 @@ MyExpander::MyExpander(bool useEnabled, Gtk::Widget* titleWidget) : } MyExpander::MyExpander(bool useEnabled, Glib::ustring titleLabel) : - enabled(false), inconsistent(false), + enabled(false), inconsistent(false), flushEvent(false), child(NULL), headerWidget(NULL), statusImage(NULL), label(NULL), useEnabled(useEnabled) { @@ -597,30 +597,12 @@ void MyExpander::add (Gtk::Container& widget) { widget.show(); } -/* -bool MyExpander::on_expose_event(GdkEventExpose* event) { - - Gdk::Color c; - Cairo::RefPtr cr = get_window()->create_cairo_context(); - - int w = get_width (); - int h = get_height (); - - Gtk::StateType state = !is_sensitive() ? Gtk::STATE_INSENSITIVE : Gtk::STATE_PRELIGHT; - Glib::RefPtr style = get_style(); - - // clear bg - cr->set_line_width (0.); - c = style->get_bg (state); - cr->set_source_rgb(c.get_red_p(), c.get_green_p(), c.get_blue_p()); - // draw the box's background - cr->rectangle (0., 0., double(w), double(h)); - cr->fill(); - return true; -} -*/ - bool MyExpander::on_toggle(GdkEventButton* event) { + if (flushEvent) { + flushEvent = false; + return false; + } + if (!child || event->button != 1) return false; @@ -646,7 +628,7 @@ MyExpander::type_signal_enabled_toggled MyExpander::signal_enabled_toggled() { // internal use ; when the user clicks on the toggle button, it calls this method that will emit an enabled_change event bool MyExpander::on_enabled_change(GdkEventButton* event) { - if (useEnabled && event->button == 1) { + if (event->button == 1) { if (enabled) { enabled = false; statusImage->set(disabledPBuf); @@ -656,6 +638,7 @@ bool MyExpander::on_enabled_change(GdkEventButton* event) { statusImage->set(enabledPBuf); } message.emit(); + flushEvent = true; } return false; } diff --git a/rtgui/guiutils.h b/rtgui/guiutils.h index 0511c8980..c732aa105 100644 --- a/rtgui/guiutils.h +++ b/rtgui/guiutils.h @@ -98,6 +98,7 @@ private: bool inconsistent; /// True if the enabled button is inconsistent Gtk::EventBox *titleEvBox; /// EventBox of the title, to get a connector from it Gtk::HBox *headerHBox; + bool flushEvent; /// Flag to control the weird event mechanism of Gtk (please prove me wrong!) /// Triggered on opened/closed event bool on_toggle(GdkEventButton* event); @@ -173,6 +174,7 @@ public: bool get_expanded(); /// Add a Gtk::Container for the content of the expander + /// Warning: do not manually Show/Hide the widget, because this parameter is handled by the click on the Expander's title void add (Gtk::Container& widget); };