[glom/gtkmm4v4] Add and use popup_menu_if_button3_click().
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom/gtkmm4v4] Add and use popup_menu_if_button3_click().
- Date: Tue, 20 Jun 2017 07:32:08 +0000 (UTC)
commit e3569cf5dda7e340151f7ce287f9e5d365359f53
Author: Murray Cumming <murrayc murrayc com>
Date: Tue Jun 20 09:22:21 2017 +0200
Add and use popup_menu_if_button3_click().
To avoid repetitive code.
glom/mode_data/box_data_calendar_related.cc | 11 +--------
glom/mode_data/buttonglom.cc | 14 ++----------
glom/mode_data/datawidget/checkbutton.cc | 14 ++----------
glom/mode_data/datawidget/combo.cc | 14 +----------
.../mode_data/datawidget/combo_as_radio_buttons.cc | 12 +---------
glom/mode_data/datawidget/datawidget.cc | 13 +----------
glom/mode_data/datawidget/entry.cc | 13 +----------
glom/mode_data/datawidget/label.cc | 14 ++----------
glom/mode_data/datawidget/textview.cc | 15 ++----------
glom/mode_data/db_adddel/db_adddel.cc | 9 +-------
glom/mode_data/flowtablewithfields.cc | 14 ++----------
glom/utility_widgets/adddel/adddel.cc | 22 +++++--------------
glom/utility_widgets/notebooklabelglom.cc | 14 ++----------
glom/utils_ui.cc | 21 +++++++++++++++++++
glom/utils_ui.h | 6 +++++
15 files changed, 62 insertions(+), 144 deletions(-)
---
diff --git a/glom/mode_data/box_data_calendar_related.cc b/glom/mode_data/box_data_calendar_related.cc
index ddcf26a..5bd3c2c 100644
--- a/glom/mode_data/box_data_calendar_related.cc
+++ b/glom/mode_data/box_data_calendar_related.cc
@@ -516,16 +516,9 @@ void Box_Data_Calendar_Related::on_calendar_button_press_event(Gdk::EventButton&
}
#endif
- auto gdkwindow = get_window();
- int x = 0;
- int y = 0;
- Gdk::ModifierType mods;
- gdkwindow->get_device_position(button_event.get_device(), x, y, mods);
- if((mods & Gdk::ModifierType::BUTTON3_MASK) == Gdk::ModifierType::BUTTON3_MASK)
+ if(UiUtils::popup_menu_if_button3_click(*this, *m_menu_popup, button_event))
{
- //Give user choices of actions on this item:
- m_menu_popup->popup(button_event.get_button(), button_event.get_time());
- return; //handled.
+ return; // true; //handled.
}
else
{
diff --git a/glom/mode_data/buttonglom.cc b/glom/mode_data/buttonglom.cc
index 245f35f..d9d8d5c 100644
--- a/glom/mode_data/buttonglom.cc
+++ b/glom/mode_data/buttonglom.cc
@@ -82,18 +82,10 @@ bool ButtonGlom::on_button_press_event(Gdk::EventButton& button_event)
auto pApp = get_appwindow();
if(pApp && pApp->get_userlevel() == AppState::userlevels::DEVELOPER)
{
- auto gdkwindow = get_window();
- Gdk::ModifierType mods;
- int x = 0;
- int y = 0;
- gdkwindow->get_device_position(button_event.get_device(), x, y, mods);
- if((mods & Gdk::ModifierType::BUTTON3_MASK) == Gdk::ModifierType::BUTTON3_MASK)
- {
- //Give user choices of actions on this item:
- m_popup_menu_utils->popup(button_event.get_button(), button_event.get_time());
- return true; //We handled this event.
- }
+ if(UiUtils::popup_menu_if_button3_click(*this, *m_popup_menu_utils, button_event))
+ return true; //handled.
}
+
return Gtk::Button::on_button_press_event(button_event);
}
#endif
diff --git a/glom/mode_data/datawidget/checkbutton.cc b/glom/mode_data/datawidget/checkbutton.cc
index 850cb7a..f9c36a2 100644
--- a/glom/mode_data/datawidget/checkbutton.cc
+++ b/glom/mode_data/datawidget/checkbutton.cc
@@ -22,6 +22,7 @@
#include <gtkmm/messagedialog.h>
#include <glom/dialog_invalid_data.h>
#include <glom/appwindow.h>
+#include <glom/utils_ui.h>
namespace Glom
{
@@ -56,17 +57,8 @@ bool CheckButton::on_button_press_event(Gdk::EventButton& button_event)
//TODO: It would be better to add it somehow to the standard context menu.
if(pApp->get_userlevel() == AppState::userlevels::DEVELOPER)
{
- auto gdkwindow = get_window();
- Gdk::ModifierType mods;
- int x = 0;
- int y = 0;
- gdkwindow->get_device_position(button_event.get_device(), x, y, mods);
- if((mods & Gdk::ModifierType::BUTTON3_MASK) == Gdk::ModifierType::BUTTON3_MASK)
- {
- //Give user choices of actions on this item:
- m_menu_popup->popup(button_event.get_button(), button_event.get_time());
- return true; //We handled this event.
- }
+ if(UiUtils::popup_menu_if_button3_click(*this, *m_menu_popup, button_event))
+ return true;
}
}
diff --git a/glom/mode_data/datawidget/combo.cc b/glom/mode_data/datawidget/combo.cc
index 33d3499..ae03745 100644
--- a/glom/mode_data/datawidget/combo.cc
+++ b/glom/mode_data/datawidget/combo.cc
@@ -320,19 +320,9 @@ g_warning("ComboGlom::on_button_press_event()");
//TODO: It would be better to add it somehow to the standard context menu.
if(pApp->get_userlevel() == AppState::userlevels::DEVELOPER)
{
- auto gdkwindow = get_window();
- Gdk::ModifierType mods;
- int x = 0;
- int y = 0;
- gdkwindow->get_device_position(button_event.get_device(), x, y, mods);
- if((mods & Gdk::ModifierType::BUTTON3_MASK) == Gdk::ModifierType::BUTTON3_MASK)
- {
- //Give user choices of actions on this item:
- m_menu_popup->popup(button_event.get_button(), button_event.get_time());
- return true; //We handled this event.
- }
+ if(UiUtils::popup_menu_if_button3_click(*this, *m_menu_popup, button_event))
+ return true;
}
-
}
return Gtk::ComboBox::on_button_press_event(button_event);
diff --git a/glom/mode_data/datawidget/combo_as_radio_buttons.cc
b/glom/mode_data/datawidget/combo_as_radio_buttons.cc
index 5c51aba..e5d078e 100644
--- a/glom/mode_data/datawidget/combo_as_radio_buttons.cc
+++ b/glom/mode_data/datawidget/combo_as_radio_buttons.cc
@@ -23,6 +23,7 @@
#include <gtkmm/messagedialog.h>
#include <glom/dialog_invalid_data.h>
#include <glom/appwindow.h>
+#include <glom/utils_ui.h>
#include <libglom/db_utils.h>
#include <iostream> // for cout, endl
@@ -267,16 +268,7 @@ void ComboAsRadioButtons::show_context_menu(Gdk::EventButton& button_event)
//TODO: It would be better to add it somehow to the standard context menu.
if(pApp->get_userlevel() == AppState::userlevels::DEVELOPER)
{
- auto gdkwindow = get_window();
- Gdk::ModifierType mods;
- int x = 0;
- int y = 0;
- gdkwindow->get_device_position(button_event.get_device(), x, y, mods);
- if((mods & Gdk::ModifierType::BUTTON3_MASK) == Gdk::ModifierType::BUTTON3_MASK)
- {
- //Give user choices of actions on this item:
- m_menu_popup->popup(button_event.get_button(), button_event.get_time());
- }
+ UiUtils::popup_menu_if_button3_click(*this, *m_menu_popup, button_event);
}
}
}
diff --git a/glom/mode_data/datawidget/datawidget.cc b/glom/mode_data/datawidget/datawidget.cc
index 785e85d..81ff212 100644
--- a/glom/mode_data/datawidget/datawidget.cc
+++ b/glom/mode_data/datawidget/datawidget.cc
@@ -433,17 +433,8 @@ bool DataWidget::on_button_press_event(Gdk::EventButton& button_event)
//TODO: It would be better to add it somehow to the standard context menu.
if(pApp->get_userlevel() == AppState::userlevels::DEVELOPER)
{
- auto gdkwindow = get_window();
- Gdk::ModifierType mods;
- int x = 0;
- int y = 0;
- gdkwindow->get_device_position(button_event.get_device(), x, y, mods);
- if((mods & Gdk::ModifierType::BUTTON3_MASK) == Gdk::ModifierType::BUTTON3_MASK)
- {
- //Give user choices of actions on this item:
- m_menu_popup->popup(button_event.get_button(), button_event.get_time());
- return true; //We handled this event.
- }
+ if(UiUtils::popup_menu_if_button3_click(*this, *m_menu_popup, button_event))
+ return true;
}
}
diff --git a/glom/mode_data/datawidget/entry.cc b/glom/mode_data/datawidget/entry.cc
index 7416595..bc69909 100644
--- a/glom/mode_data/datawidget/entry.cc
+++ b/glom/mode_data/datawidget/entry.cc
@@ -196,17 +196,8 @@ bool Entry::on_button_press_event(Gdk::EventButton& button_event)
//TODO: It would be better to add it somehow to the standard context menu.
if(pApp->get_userlevel() == AppState::userlevels::DEVELOPER)
{
- auto gdkwindow = get_window();
- Gdk::ModifierType mods;
- int x = 0;
- int y = 0;
- gdkwindow->get_device_position(button_event.get_device(), x, y, mods);
- if((mods & Gdk::ModifierType::BUTTON3_MASK) == Gdk::ModifierType::BUTTON3_MASK)
- {
- //Give user choices of actions on this item:
- m_menu_popup->popup(button_event.get_button(), button_event.get_time());
- return true; //We handled this event.
- }
+ if(UiUtils::popup_menu_if_button3_click(*this, *m_menu_popup, button_event))
+ return true;
}
}
diff --git a/glom/mode_data/datawidget/label.cc b/glom/mode_data/datawidget/label.cc
index 8bc21f4..63d6750 100644
--- a/glom/mode_data/datawidget/label.cc
+++ b/glom/mode_data/datawidget/label.cc
@@ -23,6 +23,7 @@
#include <glom/appwindow.h>
#include <glom/mode_design/layout/layout_item_dialogs/dialog_textobject.h>
#include <glom/glade_utils.h>
+#include <glom/utils_ui.h>
namespace Glom
{
@@ -99,17 +100,8 @@ bool Label::on_button_press_event(Gdk::EventButton& button_event)
auto pApp = get_appwindow();
if(pApp && pApp->get_userlevel() == AppState::userlevels::DEVELOPER)
{
- auto gdkwindow = get_window();
- Gdk::ModifierType mods;
- int x = 0;
- int y = 0;
- gdkwindow->get_device_position(button_event.get_device(), x, y, mods);
- if((mods & Gdk::ModifierType::BUTTON3_MASK) == Gdk::ModifierType::BUTTON3_MASK)
- {
- //Give user choices of actions on this item:
- m_popup_menu_utils->popup(button_event.get_button(), button_event.get_time());
- return true; //We handled this event.
- }
+ if(UiUtils::popup_menu_if_button3_click(*this, *m_popup_menu_utils, button_event))
+ return true;
}
return Gtk::EventBox::on_button_press_event(button_event);
diff --git a/glom/mode_data/datawidget/textview.cc b/glom/mode_data/datawidget/textview.cc
index 5bcb33a..9a6e8b0 100644
--- a/glom/mode_data/datawidget/textview.cc
+++ b/glom/mode_data/datawidget/textview.cc
@@ -23,6 +23,7 @@
#include <gtkmm/messagedialog.h>
#include <glom/dialog_invalid_data.h>
#include <glom/appwindow.h>
+#include <glom/utils_ui.h>
#include <iostream> // for cout, endl
namespace Glom
@@ -155,19 +156,9 @@ bool TextView::on_button_press_event(Gdk::EventButton& button_event)
//TODO: It would be better to add it somehow to the standard context menu.
if(pApp->get_userlevel() == AppState::userlevels::DEVELOPER)
{
- auto gdkwindow = get_window();
- Gdk::ModifierType mods;
- int x = 0;
- int y = 0;
- gdkwindow->get_device_position(button_event.get_device(), x, y, mods);
- if((mods & Gdk::ModifierType::BUTTON3_MASK) == Gdk::ModifierType::BUTTON3_MASK)
- {
- //Give user choices of actions on this item:
- m_menu_popup->popup(button_event.get_button(), button_event.get_time());
- return true; //We handled this event.
- }
+ if(UiUtils::popup_menu_if_button3_click(*this, *m_menu_popup, button_event))
+ return true;
}
-
}
return Gtk::ScrolledWindow::on_button_press_event(button_event);
diff --git a/glom/mode_data/db_adddel/db_adddel.cc b/glom/mode_data/db_adddel/db_adddel.cc
index fca21f0..4bf30e9 100644
--- a/glom/mode_data/db_adddel/db_adddel.cc
+++ b/glom/mode_data/db_adddel/db_adddel.cc
@@ -284,15 +284,8 @@ bool DbAddDel::on_button_press_event_Popup(Gdk::EventButton& button_event)
}
#endif
- auto gdkwindow = get_window();
- Gdk::ModifierType mods;
- int x = 0;
- int y = 0;
- gdkwindow->get_device_position(button_event.get_device(), x, y, mods);
- if((mods & Gdk::ModifierType::BUTTON3_MASK) == Gdk::ModifierType::BUTTON3_MASK)
- {
- //Give user choices of actions on this item:
- m_menu_popup->popup(button_event.get_button(), button_event.get_time());
+ if(UiUtils::popup_menu_if_button3_click(*this, *m_menu_popup, button_event))
+ {
return true; //handled.
}
else
diff --git a/glom/mode_data/flowtablewithfields.cc b/glom/mode_data/flowtablewithfields.cc
index 1d65166..016a52f 100644
--- a/glom/mode_data/flowtablewithfields.cc
+++ b/glom/mode_data/flowtablewithfields.cc
@@ -1315,18 +1315,10 @@ bool FlowTableWithFields::on_button_press_event(Gdk::EventButton& button_event)
auto pApp = AppWindow::get_appwindow();
if(pApp && pApp->get_userlevel() == AppState::userlevels::DEVELOPER)
{
- auto gdkwindow = get_window();
- Gdk::ModifierType mods;
- int x = 0;
- int y = 0;
- gdkwindow->get_device_position(button_event.get_device(), x, y, mods);
- if((mods & Gdk::ModifierType::BUTTON3_MASK) == Gdk::ModifierType::BUTTON3_MASK)
- {
- //Give user choices of actions on this item:
- m_popup_menu_utils->popup(button_event.get_button(), button_event.get_time());
- return true; //We handled this event.
- }
+ if(UiUtils::popup_menu_if_button3_click(*this, *m_popup_menu_utils, button_event))
+ return true; //handled.
}
+
return Gtk::Widget::on_button_press_event(button_event);
}
diff --git a/glom/utility_widgets/adddel/adddel.cc b/glom/utility_widgets/adddel/adddel.cc
index 9376b44..0224b6d 100644
--- a/glom/utility_widgets/adddel/adddel.cc
+++ b/glom/utility_widgets/adddel/adddel.cc
@@ -217,23 +217,13 @@ void AddDel::setup_menu(Gtk::Widget* /* widget */)
void AddDel::on_button_press_event_Popup(Gdk::EventButton& button_event)
{
- auto gdkwindow = get_window();
- Gdk::ModifierType mods;
- int x = 0;
- int y = 0;
- gdkwindow->get_device_position(button_event.get_device(), x, y, mods);
- if((mods & Gdk::ModifierType::BUTTON3_MASK) == Gdk::ModifierType::BUTTON3_MASK)
- {
- //Give user choices of actions on this item:
- m_menu_popup->popup(button_event.get_button(), button_event.get_time());
- }
- else
+ if(UiUtils::popup_menu_if_button3_click(*this, *m_menu_popup, button_event))
+ return; //handled.
+
+ if(button_event.get_event_type() == Gdk::Event::Type::DOUBLE_BUTTON_PRESS)
{
- if(button_event.get_event_type() == Gdk::Event::Type::DOUBLE_BUTTON_PRESS)
- {
- //Double-click means edit.
- //Disable this, because it is confusing when single-click activates editable cells too.
- }
+ //Double-click means edit.
+ //Disable this, because it is confusing when single-click activates editable cells too.
}
//return true;
diff --git a/glom/utility_widgets/notebooklabelglom.cc b/glom/utility_widgets/notebooklabelglom.cc
index 6f2e7cb..5b88021 100644
--- a/glom/utility_widgets/notebooklabelglom.cc
+++ b/glom/utility_widgets/notebooklabelglom.cc
@@ -20,6 +20,7 @@
#include "notebooklabelglom.h"
#include <glom/appwindow.h>
+#include <glom/utils_ui.h>
#include <glibmm/i18n.h>
#include <iostream>
@@ -125,17 +126,8 @@ bool NotebookLabel::on_button_press_event(Gdk::EventButton& button_event)
auto pApp = get_appwindow();
if(pApp && pApp->get_userlevel() == AppState::userlevels::DEVELOPER)
{
- auto gdkwindow = get_window();
- Gdk::ModifierType mods;
- int x = 0;
- int y = 0;
- gdkwindow->get_device_position(button_event.get_device(), x, y, mods);
- if((mods & Gdk::ModifierType::BUTTON3_MASK) == Gdk::ModifierType::BUTTON3_MASK)
- {
- //Give user choices of actions on this item:
- m_popup_menu->popup(button_event.get_button(), button_event.get_time());
- return true; //We handled this event.
- }
+ if(UiUtils::popup_menu_if_button3_click(*this, *m_popup_menu, button_event))
+ return true; //handled.
}
return Gtk::EventBox::on_button_press_event(button_event);
diff --git a/glom/utils_ui.cc b/glom/utils_ui.cc
index e6b3f40..5f056b0 100644
--- a/glom/utils_ui.cc
+++ b/glom/utils_ui.cc
@@ -637,4 +637,25 @@ void UiUtils::load_background_color_into_css_provider(Gtk::Widget& widget, const
load_into_css_provider(widget, css);
}
+bool UiUtils::popup_menu_if_button3_click(Gtk::Widget& widget, Gtk::Menu& menu, const Gdk::EventButton&
event)
+{
+ auto gdkwindow = widget.get_window();
+ if (!gdkwindow) {
+ return false;
+ }
+
+ Gdk::ModifierType mods;
+ int x = 0;
+ int y = 0;
+ gdkwindow->get_device_position(event.get_device(), x, y, mods);
+ if((mods & Gdk::ModifierType::BUTTON3_MASK) == Gdk::ModifierType::BUTTON3_MASK)
+ {
+ //Give user choices of actions on this item:
+ menu.popup(event.get_button(), event.get_time());
+ return true; //We handled this event.
+ }
+
+ return false;
+}
+
} //namespace Glom
diff --git a/glom/utils_ui.h b/glom/utils_ui.h
index 1b383c2..5700922 100644
--- a/glom/utils_ui.h
+++ b/glom/utils_ui.h
@@ -23,6 +23,7 @@
#include "config.h"
#include <gtkmm/dialog.h>
+#include <gtkmm/menu.h>
#include <gtkmm/treeview.h>
#include <gtkmm/cssprovider.h>
#include <libglom/data_structure/field.h>
@@ -116,6 +117,11 @@ void load_font_into_css_provider(Gtk::Widget& widget, const Glib::ustring& pango
void load_color_into_css_provider(Gtk::Widget& widget, const Glib::ustring& color);
void load_background_color_into_css_provider(Gtk::Widget& widget, const Glib::ustring& color);
+/** Popup the @a menu if the @a event, on the @a widget, is a button 3 click.
+ * @result Whether the event was handled.
+ */
+bool popup_menu_if_button3_click(Gtk::Widget& widget, Gtk::Menu& menu, const Gdk::EventButton& event);
+
} //namespace UiUtils
} //namespace Glom
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]