diff --git a/rtgui/colortoning.cc b/rtgui/colortoning.cc index 38cf88230..99ad03e9f 100644 --- a/rtgui/colortoning.cc +++ b/rtgui/colortoning.cc @@ -3,6 +3,7 @@ */ #include "colortoning.h" #include "mycurve.h" +#include "rtimage.h" using namespace rtengine; using namespace rtengine::procparams; diff --git a/rtgui/diagonalcurveeditorsubgroup.cc b/rtgui/diagonalcurveeditorsubgroup.cc index ad896789f..4ca2bb159 100644 --- a/rtgui/diagonalcurveeditorsubgroup.cc +++ b/rtgui/diagonalcurveeditorsubgroup.cc @@ -30,6 +30,7 @@ #include "mydiagonalcurve.h" #include "curveeditor.h" #include "diagonalcurveeditorsubgroup.h" +#include "rtimage.h" DiagonalCurveEditorSubGroup::DiagonalCurveEditorSubGroup (CurveEditorGroup* prt, Glib::ustring& curveDir) : CurveEditorSubGroup(curveDir) { diff --git a/rtgui/editorpanel.cc b/rtgui/editorpanel.cc index 74fa2f937..621c088e3 100644 --- a/rtgui/editorpanel.cc +++ b/rtgui/editorpanel.cc @@ -29,6 +29,7 @@ #include "soundman.h" #include "rtimage.h" #include +#include "popupbutton.h" using namespace rtengine::procparams; @@ -76,7 +77,7 @@ private: void prepareIntentBox () { - PopUpButton *bt = new PopUpButton(); + PopUpButton *bt = new PopUpButton(Glib::ustring(), true); intentBox = Gtk::manage(bt); intentBox->addEntry("intent-relative.png", M("PREFERENCES_INTENT_RELATIVE")); intentBox->addEntry("intent-perceptual.png", M("PREFERENCES_INTENT_PERCEPTUAL")); diff --git a/rtgui/flatcurveeditorsubgroup.cc b/rtgui/flatcurveeditorsubgroup.cc index 516bed44a..691fbe3dd 100644 --- a/rtgui/flatcurveeditorsubgroup.cc +++ b/rtgui/flatcurveeditorsubgroup.cc @@ -31,6 +31,7 @@ #include "myflatcurve.h" #include "curveeditor.h" #include "flatcurveeditorsubgroup.h" +#include "rtimage.h" FlatCurveEditorSubGroup::FlatCurveEditorSubGroup (CurveEditorGroup* prt, Glib::ustring& curveDir) : CurveEditorSubGroup(curveDir) { diff --git a/rtgui/popupbutton.cc b/rtgui/popupbutton.cc index e0cca8bd0..554f41cc6 100644 --- a/rtgui/popupbutton.cc +++ b/rtgui/popupbutton.cc @@ -21,6 +21,8 @@ #include "popupbutton.h" +#include + /* * PopUpButton::PopUpButton (const Glib::ustring& label, bool imgRight) * @@ -28,8 +30,14 @@ * * Parameters: * label = label displayed in the button + * nextOnClicked = selects the next entry if the button is clicked */ -PopUpButton::PopUpButton (const Glib::ustring& label) : Gtk::Button(), PopUpCommon(this, label) { } +PopUpButton::PopUpButton (const Glib::ustring& label, bool nextOnClicked) + : Gtk::Button () + , PopUpCommon (this, label) + , nextOnClicked(nextOnClicked) +{ +} void PopUpButton::show() { @@ -44,3 +52,22 @@ void PopUpButton::set_sensitive (bool isSensitive) { buttonGroup->set_sensitive(isSensitive); } + +bool PopUpButton::on_button_release_event (GdkEventButton* event) +{ + if (nextOnClicked && getEntryCount () > 1) + { + const int last = getEntryCount () - 1; + int next = getSelected (); + + if (event->state & GDK_SHIFT_MASK) { + next = next > 0 ? next - 1 : last; + } else { + next = next < last ? next + 1 : 0; + } + + entrySelected (next); + } + + return Gtk::Button::on_button_release_event(event); +} diff --git a/rtgui/popupbutton.h b/rtgui/popupbutton.h index dec848b14..245d29aee 100644 --- a/rtgui/popupbutton.h +++ b/rtgui/popupbutton.h @@ -21,17 +21,24 @@ #ifndef _POPUPBUTTON_ #define _POPUPBUTTON_ -#include +#include #include "popupcommon.h" class PopUpButton : public Gtk::Button, public PopUpCommon { public: - PopUpButton (const Glib::ustring& label = ""); + PopUpButton (const Glib::ustring& label = Glib::ustring (), bool nextOnClicked = false); void show (); void set_tooltip_text (const Glib::ustring &text); void set_sensitive (bool isSensitive=true); + +protected: + bool on_button_release_event (GdkEventButton* event); + +private: + bool nextOnClicked; + }; #endif diff --git a/rtgui/popupcommon.cc b/rtgui/popupcommon.cc index 2a1387d3f..8acbd2802 100644 --- a/rtgui/popupcommon.cc +++ b/rtgui/popupcommon.cc @@ -26,6 +26,9 @@ #include "rtimage.h" PopUpCommon::PopUpCommon (Gtk::Button* thisButton, const Glib::ustring& label) + : selected (-1) // -1 means that the button is invalid + , menu (0) + , buttonImage (0) { button = thisButton; hasMenu = false; @@ -42,15 +45,6 @@ PopUpCommon::PopUpCommon (Gtk::Button* thisButton, const Glib::ustring& label) // Create the global container and put the button in it buttonGroup = Gtk::manage( new Gtk::HBox(false, 0)); buttonGroup->pack_start(*button, Gtk::PACK_EXPAND_WIDGET, 0); - // Create the list entry - imageFilenames.clear(); - images.clear(); - sItems.clear(); - items.clear(); - selected = -1; // -1 : means that the button is invalid - menu = 0; - buttonImage = 0; - buttonHint = ""; } PopUpCommon::~PopUpCommon () @@ -59,81 +53,59 @@ PopUpCommon::~PopUpCommon () delete *i; } - for (std::vector::iterator i = items.begin(); i != items.end(); ++i) { - delete *i; - } - - if (menu) { - delete menu; - } - - if (buttonImage) { - delete buttonImage; - } - + delete menu; + delete buttonImage; delete buttonGroup; } -PopUpCommon::type_signal_changed PopUpCommon::signal_changed() +bool PopUpCommon::addEntry (const Glib::ustring& fileName, const Glib::ustring& label) { - return message; -} + if (label.empty ()) + return false; -bool PopUpCommon::addEntry (Glib::ustring fileName, Glib::ustring label) -{ - bool added = false; + // Create the image + RTImage* newImage = new RTImage(fileName); + images.push_back(newImage); + imageFilenames.push_back(fileName); + int currPos = (int)images.size(); + // Create the menu item + Gtk::ImageMenuItem* newItem = Gtk::manage(new Gtk::ImageMenuItem (*newImage, label)); - if ( label.size() ) { - imageFilenames.push_back(fileName); - sItems.push_back(label); - // Create the image - RTImage* newImage = new RTImage(fileName); - images.push_back(newImage); - int currPos = (int)images.size(); - // Create the menu item - Gtk::ImageMenuItem* newItem = new Gtk::ImageMenuItem (*newImage, label); - items.push_back(newItem); - - if (selected == -1) { - // Create the menu on the first item - menu = new Gtk::Menu (); - // Create the image for the button - buttonImage = new RTImage(fileName); - // Use the first image by default - imageContainer->pack_start(*buttonImage, Gtk::PACK_EXPAND_WIDGET); - selected = 0; - } - - // When there is at least 1 choice, we add the arrow button - if (images.size() == 1) { - Gtk::Button* arrowButton = Gtk::manage( new Gtk::Button() ); - RTImage* arrowImage = Gtk::manage( new RTImage("popuparrow.png") ); - arrowButton->add(*arrowImage); //menuSymbol); - arrowButton->set_relief (Gtk::RELIEF_NONE); - arrowButton->set_border_width (0); - buttonGroup->pack_start(*arrowButton, Gtk::PACK_SHRINK, 0); - arrowButton->signal_button_release_event().connect_notify( sigc::mem_fun(*this, &PopUpCommon::showMenu) ); - hasMenu = true; - } - - newItem->signal_activate().connect (sigc::bind(sigc::mem_fun(*this, &PopUpCommon::entrySelected), currPos - 1)); - menu->attach (*newItem, 0, 1, currPos - 1, currPos); - // The item has been created - added = true; + if (selected == -1) { + // Create the menu on the first item + menu = new Gtk::Menu (); + // Create the image for the button + buttonImage = new RTImage(fileName); + // Use the first image by default + imageContainer->pack_start(*buttonImage, Gtk::PACK_EXPAND_WIDGET); + selected = 0; } - return added; + // When there is at least 1 choice, we add the arrow button + if (images.size() == 1) { + Gtk::Button* arrowButton = Gtk::manage( new Gtk::Button() ); + RTImage* arrowImage = Gtk::manage( new RTImage("popuparrow.png") ); + arrowButton->add(*arrowImage); //menuSymbol); + arrowButton->set_relief (Gtk::RELIEF_NONE); + arrowButton->set_border_width (0); + buttonGroup->pack_start(*arrowButton, Gtk::PACK_SHRINK, 0); + arrowButton->signal_button_release_event().connect_notify( sigc::mem_fun(*this, &PopUpCommon::showMenu) ); + hasMenu = true; + } + + newItem->signal_activate().connect (sigc::bind(sigc::mem_fun(*this, &PopUpCommon::entrySelected), currPos - 1)); + menu->attach (*newItem, 0, 1, currPos - 1, currPos); + + return true; } // TODO: 'PopUpCommon::removeEntry' method to be created... void PopUpCommon::entrySelected (int i) { - if (setSelected((unsigned int)i)) - // Emit a a signal if the selected item has changed - { - message.emit(selected); - } + // Emit a a signal if the selected item has changed + if (setSelected (i)) + message (selected); } void PopUpCommon::setItemSensitivity (int i, bool isSensitive) { @@ -181,7 +153,12 @@ void PopUpCommon::setButtonHint() } if (selected > -1) { - hint += sItems.at(selected); + // HACK: Gtk::MenuItem::get_label does not seem to work reliably. + Gtk::MenuItem& item = menu->items ()[selected]; + Gtk::Label* label = dynamic_cast(item.get_child ()); + + if (label) + hint += label->get_text (); } button->set_tooltip_markup(hint); diff --git a/rtgui/popupcommon.h b/rtgui/popupcommon.h index 7b05a08e9..04044fb2d 100644 --- a/rtgui/popupcommon.h +++ b/rtgui/popupcommon.h @@ -21,11 +21,21 @@ #ifndef _POPUPCOMMON_ #define _POPUPCOMMON_ +#include +#include +#include -#include -#include -#include "rtimage.h" +namespace Gtk +{ +class HBox; +class Menu; +class Button; +class ImageMenuItem; +} +typedef struct _GdkEventButton GdkEventButton; + +class RTImage; class PopUpCommon { @@ -37,12 +47,10 @@ public: PopUpCommon (Gtk::Button* button, const Glib::ustring& label = ""); virtual ~PopUpCommon (); - bool addEntry (Glib::ustring fileName, Glib::ustring label); + bool addEntry (const Glib::ustring& fileName, const Glib::ustring& label); + int getEntryCount () const; bool setSelected (int entryNum); - int getSelected () - { - return selected; - } + int getSelected () const; void setButtonHint(); void show (); void set_tooltip_text (const Glib::ustring &text); @@ -50,14 +58,8 @@ public: private: type_signal_changed message; - /* - TODO: MenuItem::get_label() doesn't return any string, or an empty string !? - That's why we store entries strings in sItems, but it would be nice to get ride of it... - */ - std::vector sItems; std::vector imageFilenames; std::vector images; - std::vector items; Glib::ustring buttonHint; RTImage* buttonImage; Gtk::HBox* imageContainer; @@ -67,9 +69,26 @@ private: bool hasMenu; void showMenu(GdkEventButton* event); - void entrySelected (int i); void setItemSensitivity (int i, bool isSensitive); +protected: + void entrySelected (int i); + }; +inline PopUpCommon::type_signal_changed PopUpCommon::signal_changed () +{ + return message; +} + +inline int PopUpCommon::getEntryCount () const +{ + return images.size(); +} + +inline int PopUpCommon::getSelected () const +{ + return selected; +} + #endif diff --git a/rtgui/popuptogglebutton.h b/rtgui/popuptogglebutton.h index 58342e66c..930fae4f2 100644 --- a/rtgui/popuptogglebutton.h +++ b/rtgui/popuptogglebutton.h @@ -21,7 +21,7 @@ #ifndef _POPUPTOGGLEBUTTON_ #define _POPUPTOGGLEBUTTON_ -#include "popupbutton.h" +#include #include "popupcommon.h" class PopUpToggleButton : public Gtk::ToggleButton, public PopUpCommon diff --git a/rtgui/retinex.cc b/rtgui/retinex.cc index b964ecbb5..43cbe4f28 100644 --- a/rtgui/retinex.cc +++ b/rtgui/retinex.cc @@ -3,6 +3,7 @@ */ #include "retinex.h" #include "mycurve.h" +#include "rtimage.h" using namespace rtengine; using namespace rtengine::procparams; diff --git a/rtgui/wavelet.cc b/rtgui/wavelet.cc index 4bebb10ad..abab1d2d1 100644 --- a/rtgui/wavelet.cc +++ b/rtgui/wavelet.cc @@ -21,6 +21,7 @@ #include #include "edit.h" #include "guiutils.h" +#include "rtimage.h" using namespace rtengine; using namespace rtengine::procparams;