Add an optional function to the pop-up button, so that it will select the next entry when clicked and also do some miscellaneous code clean-ups including forward declarations.

This commit is contained in:
Adam Reichold
2015-12-20 15:56:12 +01:00
parent e9141dd98c
commit 151556ae23
11 changed files with 127 additions and 91 deletions

View File

@@ -21,6 +21,8 @@
#include "popupbutton.h"
#include <gtkmm/box.h>
/*
* 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);
}