[balsa/gtk4: 42/294] Various: Implement libbalsa_popup_widget_popup()
- From: Peter Bloomfield <peterb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa/gtk4: 42/294] Various: Implement libbalsa_popup_widget_popup()
- Date: Sun, 20 Jun 2021 23:36:35 +0000 (UTC)
commit 91327998c745e469cda40ac1be0cdd1ec11d7cd2
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Wed Jun 17 18:54:21 2020 -0400
Various: Implement libbalsa_popup_widget_popup()
Implement libbalsa_popup_widget_popup() as a wrapper for popping up
either a GtkPopover or a GtkMenu, and use it.
* libbalsa/libbalsa.c (libbalsa_popup_widget_popup):
* libbalsa/libbalsa.h:
* src/balsa-index.c (bndx_do_popup):
* src/balsa-mblist.c (bmbl_do_popup):
* src/balsa-message.c (tree_mult_selection_popup), (tree_button_press_cb):
* src/balsa-mime-widget-image.c (balsa_image_button_press_cb):
* src/balsa-mime-widget-text.c (bmwt_html_popup_context_menu):
* src/sendmsg-window.c (attachment_button_press_cb):
* src/toolbar-factory.c (tm_popup_context_menu_cb):
ChangeLog | 16 +++++++++++++
libbalsa/libbalsa.c | 54 +++++++++++++++++++++++++++++++++++++++++++
libbalsa/libbalsa.h | 11 +++++----
src/balsa-index.c | 36 +----------------------------
src/balsa-mblist.c | 28 +---------------------
src/balsa-message.c | 47 +++----------------------------------
src/balsa-mime-widget-image.c | 8 +------
src/balsa-mime-widget-text.c | 26 +--------------------
src/sendmsg-window.c | 18 ++-------------
src/toolbar-factory.c | 38 +-----------------------------
10 files changed, 87 insertions(+), 195 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5323414e4..d989ec137 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -324,6 +324,22 @@
* src/balsa-mime-widget-text.c (text_view_url_popup):
+2020-06-17 Peter Bloomfield <pbloomfield bellsouth net>
+
+ Various: Implement libbalsa_popup_widget_popup() as a wrapper for
+ popping up either a GtkPopover or a GtkMenu, and use it.
+
+ * libbalsa/libbalsa.c (libbalsa_popup_widget_popup):
+ * libbalsa/libbalsa.h:
+ * src/balsa-index.c (bndx_do_popup):
+ * src/balsa-mblist.c (bmbl_do_popup):
+ * src/balsa-message.c (tree_mult_selection_popup),
+ (tree_button_press_cb):
+ * src/balsa-mime-widget-image.c (balsa_image_button_press_cb):
+ * src/balsa-mime-widget-text.c (bmwt_html_popup_context_menu):
+ * src/sendmsg-window.c (attachment_button_press_cb):
+ * src/toolbar-factory.c (tm_popup_context_menu_cb):
+
2020-06-16 Peter Bloomfield <pbloomfield bellsouth net>
main: Sandbox all the webkit
diff --git a/libbalsa/libbalsa.c b/libbalsa/libbalsa.c
index d7660471f..4ff8d43dc 100644
--- a/libbalsa/libbalsa.c
+++ b/libbalsa/libbalsa.c
@@ -794,3 +794,57 @@ libbalsa_popup_widget_new(GtkWidget *relative_to,
return popup_widget;
}
+
+/*
+ * Pop up a widget
+ */
+void
+libbalsa_popup_widget_popup(GtkWidget *popup_widget,
+ const GdkEvent *event,
+ GtkWidget *widget)
+{
+ g_return_if_fail(GTK_IS_POPOVER(popup_widget) || GTK_IS_MENU(popup_widget));
+ g_return_if_fail(widget == NULL || GTK_IS_WIDGET(widget));
+
+ if (libbalsa_use_popover()) {
+ GtkPopover *popover = GTK_POPOVER(popup_widget);
+ gdouble x, y;
+ GdkRectangle rectangle;
+
+ if (event != NULL &&
+ gdk_event_triggers_context_menu(event) &&
+ gdk_event_get_coords(event, &x, &y)) {
+ /* Pop up to the right of the pointer */
+ if (GTK_IS_TREE_VIEW(widget)) {
+ gtk_tree_view_convert_bin_window_to_widget_coords(GTK_TREE_VIEW(widget),
+ (gint) x,
+ (gint) y,
+ &rectangle.x,
+ &rectangle.y);
+ } else {
+ rectangle.x = (gint) x;
+ rectangle.y = (gint) y;
+ }
+ } else {
+ /* Pop up centered on widget */
+ gtk_widget_get_allocation(widget, (GtkAllocation *) &rectangle);
+ rectangle.x += rectangle.width / 2;
+ rectangle.y += rectangle.height / 2;
+ }
+ rectangle.width = 0;
+ rectangle.height = 0;
+
+ gtk_popover_set_pointing_to(popover, &rectangle);
+ gtk_popover_popup(popover);
+ } else {
+ GtkMenu *menu = GTK_MENU(popup_widget);
+
+ if (event != NULL && gdk_event_triggers_context_menu(event)) {
+ gtk_menu_popup_at_pointer(menu, event);
+ } else {
+ gtk_menu_popup_at_widget(menu, widget,
+ GDK_GRAVITY_CENTER, GDK_GRAVITY_CENTER,
+ NULL);
+ }
+ }
+}
diff --git a/libbalsa/libbalsa.h b/libbalsa/libbalsa.h
index 992cb7027..24e6c2774 100644
--- a/libbalsa/libbalsa.h
+++ b/libbalsa/libbalsa.h
@@ -186,10 +186,13 @@ enum LibBalsaImageError {
gboolean libbalsa_use_headerbar(void);
GtkDialogFlags libbalsa_dialog_flags(void);
-gboolean libbalsa_use_popover(void);
-GtkWidget *libbalsa_popup_widget_new(GtkWidget *relative_to,
- GMenuModel *model,
- const gchar *action_namespace);
+gboolean libbalsa_use_popover (void);
+GtkWidget *libbalsa_popup_widget_new (GtkWidget *relative_to,
+ GMenuModel *model,
+ const gchar *action_namespace);
+void libbalsa_popup_widget_popup(GtkWidget *popup_widget,
+ const GdkEvent *event,
+ GtkWidget *widget);
#if HAVE_GTKSOURCEVIEW
GtkWidget *libbalsa_source_view_new(gboolean highlight_phrases);
diff --git a/src/balsa-index.c b/src/balsa-index.c
index 5ac8991e7..455940f33 100644
--- a/src/balsa-index.c
+++ b/src/balsa-index.c
@@ -2174,8 +2174,6 @@ bndx_do_popup(BalsaIndex * index, const GdkEvent *event)
gboolean readonly;
GMenu *mru_menu;
GMenuItem *item;
- GtkAllocation allocation;
- gdouble x, y;
g_debug("%s:%s", __FILE__, __func__);
@@ -2224,39 +2222,7 @@ bndx_do_popup(BalsaIndex * index, const GdkEvent *event)
g_menu_insert_item(index->popup_menu, index->move_position, item);
g_object_unref(item);
- if (libbalsa_use_popover()) {
- if (event != NULL &&
- gdk_event_triggers_context_menu(event) &&
- gdk_event_get_coords(event, &x, &y)) {
- /* Pop up to the right of the pointer */
- gtk_tree_view_convert_bin_window_to_widget_coords(GTK_TREE_VIEW(index),
- (gint) x,
- (gint) y,
- &allocation.x,
- &allocation.y);
- allocation.width = 0;
- allocation.height = 0;
- } else {
- /* Pop up to the right of the "From" column */
- gtk_widget_get_allocation(GTK_WIDGET(index), &allocation);
- allocation.width = balsa_app.index_num_width +
- balsa_app.index_status_width +
- balsa_app.index_attachment_width +
- balsa_app.index_from_width;
- }
- gtk_popover_set_pointing_to(GTK_POPOVER(index->popup_widget),
- (GdkRectangle *) &allocation);
-
- gtk_popover_popup(GTK_POPOVER(index->popup_widget));
- } else {
- if (event != NULL) {
- gtk_menu_popup_at_pointer(GTK_MENU(index->popup_widget), event);
- } else {
- gtk_menu_popup_at_widget(GTK_MENU(index->popup_widget), GTK_WIDGET(index),
- GDK_GRAVITY_CENTER, GDK_GRAVITY_CENTER,
- NULL);
- }
- }
+ libbalsa_popup_widget_popup(index->popup_widget, event, GTK_WIDGET(index));
}
/* End of popup stuff */
diff --git a/src/balsa-mblist.c b/src/balsa-mblist.c
index 3ea6607de..1a01ee3e0 100644
--- a/src/balsa-mblist.c
+++ b/src/balsa-mblist.c
@@ -727,7 +727,6 @@ bmbl_do_popup(GtkTreeView *tree_view,
{
BalsaMailboxNode *mbnode = NULL;
GtkWidget *menu;
- gdouble x, y;
if (path) {
GtkTreeModel *model = gtk_tree_view_get_model(tree_view);
@@ -740,32 +739,7 @@ bmbl_do_popup(GtkTreeView *tree_view,
menu = balsa_mailbox_node_get_context_menu(mbnode, GTK_WIDGET(tree_view));
- if (libbalsa_use_popover()) {
- if (event != NULL &&
- gdk_event_triggers_context_menu(event) &&
- gdk_event_get_coords(event, &x, &y)) {
- GdkRectangle rectangle;
-
- /* Pop up above the pointer */
- rectangle.x = (int) x;
- rectangle.width = 0;
- rectangle.y = (int) y;
- rectangle.height = 0;
- gtk_popover_set_pointing_to(GTK_POPOVER(menu), &rectangle);
- }
-
- gtk_popover_popup(GTK_POPOVER(menu));
- } else {
- g_object_ref(menu);
- g_object_ref_sink(menu);
- if (event)
- gtk_menu_popup_at_pointer(GTK_MENU(menu), (GdkEvent *) event);
- else
- gtk_menu_popup_at_widget(GTK_MENU(menu), GTK_WIDGET(tree_view),
- GDK_GRAVITY_CENTER, GDK_GRAVITY_CENTER,
- NULL);
- g_object_unref(menu);
- }
+ libbalsa_popup_widget_popup(menu, event, GTK_WIDGET(tree_view));
if (mbnode != NULL)
g_object_unref(mbnode);
diff --git a/src/balsa-message.c b/src/balsa-message.c
index b55dc6c9c..7ccbc20da 100644
--- a/src/balsa-message.c
+++ b/src/balsa-message.c
@@ -1152,33 +1152,7 @@ tree_mult_selection_popup(BalsaMessage *balsa_message,
if (popup_widget == NULL)
return;
- if (libbalsa_use_popover()) {
- gdouble x, y;
-
- if (event != NULL &&
- gdk_event_triggers_context_menu(event) &&
- gdk_event_get_coords(event, &x, &y)) {
- GdkRectangle rectangle;
-
- /* Pop up above the pointer */
- rectangle.x = (int) x;
- rectangle.width = 0;
- rectangle.y = (int) y;
- rectangle.height = 0;
- gtk_popover_set_pointing_to(GTK_POPOVER(popup_widget), &rectangle);
- }
-
- gtk_popover_popup(GTK_POPOVER(popup_widget));
- } else {
- if (event != NULL) {
- gtk_menu_popup_at_pointer(GTK_MENU(popup_widget), event);
- } else {
- gtk_menu_popup_at_widget(GTK_MENU(popup_widget),
- GTK_WIDGET(balsa_message),
- GDK_GRAVITY_CENTER, GDK_GRAVITY_CENTER,
- NULL);
- }
- }
+ libbalsa_popup_widget_popup(popup_widget, event, GTK_WIDGET(balsa_message));
}
static gboolean
@@ -1241,23 +1215,8 @@ tree_button_press_cb(GtkGestureMultiPress *multi_press_gesture,
if (gtk_tree_model_get_iter (model, &iter, path)) {
gtk_tree_model_get(model, &iter, PART_INFO_COLUMN, &info, -1);
if (info != NULL) {
- if (info->popup_widget != NULL) {
- if (libbalsa_use_popover()) {
- GdkRectangle rectangle;
-
- /* Pop up above the pointer */
- rectangle.x = (int) x;
- rectangle.width = 0;
- rectangle.y = (int) y;
- rectangle.height = 0;
- gtk_popover_set_pointing_to(GTK_POPOVER(info->popup_widget),
- &rectangle);
-
- gtk_popover_popup(GTK_POPOVER(info->popup_widget));
- } else {
- gtk_menu_popup_at_pointer(GTK_MENU(info->popup_widget), event);
- }
- }
+ if (info->popup_widget != NULL)
+ libbalsa_popup_widget_popup(info->popup_widget, event, NULL);
g_object_unref(info);
}
}
diff --git a/src/balsa-mime-widget-image.c b/src/balsa-mime-widget-image.c
index c3dcf1efc..33a6e6aac 100644
--- a/src/balsa-mime-widget-image.c
+++ b/src/balsa-mime-widget-image.c
@@ -155,13 +155,7 @@ balsa_image_button_press_cb(GtkGestureMultiPress *multi_press_gesture,
sequence = gtk_gesture_single_get_current_sequence(GTK_GESTURE_SINGLE(multi_press_gesture));
event = gtk_gesture_get_last_event(gesture, sequence);
- if (gdk_event_triggers_context_menu(event)) {
- if (libbalsa_use_popover())
- gtk_popover_popup(GTK_POPOVER(menu));
- else
- gtk_menu_popup_at_pointer(GTK_MENU(menu), event);
- gtk_gesture_set_sequence_state(gesture, sequence, GTK_EVENT_SEQUENCE_CLAIMED);
- }
+ libbalsa_popup_widget_popup(menu, event, NULL);
}
static void
diff --git a/src/balsa-mime-widget-text.c b/src/balsa-mime-widget-text.c
index 4be319028..3109700d9 100644
--- a/src/balsa-mime-widget-text.c
+++ b/src/balsa-mime-widget-text.c
@@ -1335,7 +1335,6 @@ bmwt_html_popup_context_menu(GtkWidget *html,
GtkWidget *popup_widget;
const GdkEvent *event;
GdkEvent *current_event = NULL;
- gdouble x, y;
popup_widget = g_object_get_data(G_OBJECT(html), "popup-widget");
if (popup_widget == NULL) {
@@ -1359,30 +1358,7 @@ bmwt_html_popup_context_menu(GtkWidget *html,
if (event == NULL)
event = current_event = gtk_get_current_event();
- if (libbalsa_use_popover()) {
- if (event != NULL &&
- gdk_event_triggers_context_menu(event) &&
- gdk_event_get_coords(event, &x, &y)) {
- GdkRectangle rectangle;
-
- /* Pop up above the pointer */
- rectangle.x = (gint) x;
- rectangle.width = 0;
- rectangle.y = (gint) y;
- rectangle.height = 0;
- gtk_popover_set_pointing_to(GTK_POPOVER(popup_widget), &rectangle);
- }
- gtk_popover_popup(GTK_POPOVER(popup_widget));
- } else {
- if (event != NULL)
- gtk_menu_popup_at_pointer(GTK_MENU(popup_widget),
- (GdkEvent *) event);
- else
- gtk_menu_popup_at_widget(GTK_MENU(popup_widget),
- GTK_WIDGET(bm),
- GDK_GRAVITY_CENTER, GDK_GRAVITY_CENTER,
- NULL);
- }
+ libbalsa_popup_widget_popup(popup_widget, event, GTK_WIDGET(bm));
if (current_event != NULL)
gdk_event_free(current_event);
diff --git a/src/sendmsg-window.c b/src/sendmsg-window.c
index d5306dce5..7624b6073 100644
--- a/src/sendmsg-window.c
+++ b/src/sendmsg-window.c
@@ -2405,22 +2405,8 @@ attachment_button_press_cb(GtkGestureMultiPress *multi_press,
gtk_tree_model_get(model, &iter, ATTACH_INFO_COLUMN, &attach_info, -1);
if (attach_info != NULL) {
- if (attach_info->popup_menu != NULL) {
- if (libbalsa_use_popover()) {
- GdkRectangle rectangle;
-
- /* Pop up above the pointer */
- rectangle.x = (gint) x;
- rectangle.width = 0;
- rectangle.y = (gint) y;
- rectangle.height = 0;
- gtk_popover_set_pointing_to(GTK_POPOVER(attach_info->popup_menu),
- &rectangle);
- gtk_popover_popup(GTK_POPOVER(attach_info->popup_menu));
- } else {
- gtk_menu_popup_at_pointer(GTK_MENU(attach_info->popup_menu), event);
- }
- }
+ if (attach_info->popup_menu != NULL)
+ libbalsa_popup_widget_popup(attach_info->popup_menu, event, NULL);
g_object_unref(attach_info);
}
}
diff --git a/src/toolbar-factory.c b/src/toolbar-factory.c
index c8f6db040..c2fd5e12c 100644
--- a/src/toolbar-factory.c
+++ b/src/toolbar-factory.c
@@ -763,43 +763,7 @@ tm_popup_context_menu_cb(GtkWidget * toolbar,
event = gtk_get_current_event();
- if (libbalsa_use_popover()) {
- if (button != -1) {
- /* We are called with (x, y) coordinates, but they are
- * "relative to the root of the screen", and we want them
- * "relative to the window". */
- gdouble x_win, y_win;
-
- if (event != NULL &&
- gdk_event_triggers_context_menu(event) &&
- gdk_event_get_coords(event, &x_win, &y_win)) {
- GdkRectangle rectangle;
-
- /* Pop up above the pointer */
- rectangle.x = (gint) x_win;
- rectangle.width = 0;
- rectangle.y = (gint) y_win;
- rectangle.height = 0;
- gtk_popover_set_pointing_to(GTK_POPOVER(popup_menu), &rectangle);
- }
- }
-
- /* Apparently, the popover is insensitive if the toolbar is
- * insensitive, but we always want it to be sensitive. */
- gtk_widget_set_sensitive(popup_menu, TRUE);
-
- gtk_popover_popup(GTK_POPOVER(popup_menu));
- } else {
- if (event != NULL && gdk_event_get_event_type(event) == GDK_BUTTON_PRESS) {
- gtk_menu_popup_at_pointer(GTK_MENU(popup_menu), event);
- } else {
- gtk_menu_popup_at_widget(GTK_MENU(popup_menu),
- GTK_WIDGET(toolbar),
- GDK_GRAVITY_NORTH,
- GDK_GRAVITY_SOUTH,
- NULL);
- }
- }
+ libbalsa_popup_widget_popup(popup_menu, event, toolbar);
if (event != NULL)
gdk_event_free(event);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]