static gboolean button_press_cb (GtkWidget *widget, GdkEvent *event, gpointer *user_data ) { GncCombott *combott = GNC_COMBOTT (user_data); GncCombottPrivate *priv = GNC_COMBOTT_GET_PRIVATE (combott); if(priv->model != NULL) { if (event->type == GDK_BUTTON_PRESS) { GdkEventButton *bevent = (GdkEventButton *) event; #if GTK_CHECK_VERSION(3,22,0) gtk_menu_popup_at_widget (GTK_MENU(priv->menu), widget, GDK_GRAVITY_SOUTH_WEST, GDK_GRAVITY_NORTH_WEST, event); #else gtk_menu_popup (GTK_MENU (priv->menu), NULL, NULL, gctt_combott_menu_position, combott, bevent->button, bevent->time); #endif /* Tell calling code that we have handled this event; the buck * stops here. */ return TRUE; } } /* Tell calling code that we have not handled this event; pass it on. */ return FALSE; }
static gboolean sn_item_popup_menu (GtkWidget *widget) { SnItem *item; SnItemPrivate *priv; item = SN_ITEM (widget); priv = sn_item_get_instance_private (item); if (priv->menu != NULL) { gtk_menu_popup_at_widget (priv->menu, widget, GDK_GRAVITY_SOUTH_WEST, GDK_GRAVITY_NORTH_WEST, NULL); } else { gint x; gint y; sn_item_get_action_coordinates (item, &x, &y); SN_ITEM_GET_CLASS (item)->context_menu (item, x, y); } return TRUE; }
static void popup_callback(GtkButton *button, dt_lib_module_t *module) { static dt_lib_module_info_t mi; int size = 0; g_strlcpy(mi.plugin_name, module->plugin_name, sizeof(mi.plugin_name)); mi.version = module->version(module); mi.module = module; void *params = module->get_params(module, &size); // make sure that we have enough space for params if(params && (size <= sizeof(mi.params))) { memcpy(mi.params, params, size); mi.params_size = size; free(params); } else { mi.params_size = 0; fprintf(stderr, "something went wrong: ¶ms=%p, size=%i\n", ¶ms, size); } dt_lib_presets_popup_menu_show(&mi); #if GTK_CHECK_VERSION(3, 22, 0) int c = module->container(module); GdkGravity widget_gravity, menu_gravity; if((c == DT_UI_CONTAINER_PANEL_LEFT_TOP) || (c == DT_UI_CONTAINER_PANEL_LEFT_CENTER) || (c == DT_UI_CONTAINER_PANEL_LEFT_BOTTOM)) { // FIXME: these should be _EAST, but then it goes out of the sidepanel... widget_gravity = GDK_GRAVITY_SOUTH; menu_gravity = GDK_GRAVITY_NORTH; } else { widget_gravity = GDK_GRAVITY_SOUTH_WEST; menu_gravity = GDK_GRAVITY_NORTH_WEST; } gtk_menu_popup_at_widget(darktable.gui->presets_popup_menu, dtgtk_expander_get_header(DTGTK_EXPANDER(module->expander)), widget_gravity, menu_gravity, NULL); #else gtk_menu_popup(darktable.gui->presets_popup_menu, NULL, NULL, _preset_popup_posistion, button, 0, gtk_get_current_event_time()); #endif gtk_widget_show_all(GTK_WIDGET(darktable.gui->presets_popup_menu)); gtk_menu_reposition(GTK_MENU(darktable.gui->presets_popup_menu)); }
static gboolean sn_item_button_press_event (GtkWidget *widget, GdkEventButton *event) { SnItem *item; SnItemPrivate *priv; GdkDisplay *display; GdkSeat *seat; gint x; gint y; if (event->button < 2 || event->button > 3) return GTK_WIDGET_CLASS (sn_item_parent_class)->button_press_event (widget, event); item = SN_ITEM (widget); priv = sn_item_get_instance_private (item); display = gdk_display_get_default (); seat = gdk_display_get_default_seat (display); sn_item_get_action_coordinates (item, &x, &y); if (event->button == 2) { gdk_seat_ungrab (seat); SN_ITEM_GET_CLASS (item)->secondary_activate (item, x, y); } else if (event->button == 3) { if (priv->menu != NULL) { gtk_menu_popup_at_widget (priv->menu, widget, GDK_GRAVITY_SOUTH_WEST, GDK_GRAVITY_NORTH_WEST, (GdkEvent *) event); } else { gdk_seat_ungrab (seat); SN_ITEM_GET_CLASS (item)->context_menu (item, x, y); } } else { g_assert_not_reached (); } return GTK_WIDGET_CLASS (sn_item_parent_class)->button_press_event (widget, event); }
gboolean gp_menu_button_applet_popup_menu (GpMenuButtonApplet *menu_button, GdkEvent *event) { GpMenuButtonAppletPrivate *priv; GdkGravity widget_anchor; GdkGravity menu_anchor; priv = gp_menu_button_applet_get_instance_private (menu_button); if (priv->menu == NULL) return FALSE; switch (gp_applet_get_position (GP_APPLET (menu_button))) { case GTK_POS_TOP: widget_anchor = GDK_GRAVITY_SOUTH_WEST; menu_anchor = GDK_GRAVITY_NORTH_WEST; break; case GTK_POS_LEFT: widget_anchor = GDK_GRAVITY_NORTH_EAST; menu_anchor = GDK_GRAVITY_NORTH_WEST; break; case GTK_POS_RIGHT: widget_anchor = GDK_GRAVITY_NORTH_WEST; menu_anchor = GDK_GRAVITY_NORTH_EAST; break; case GTK_POS_BOTTOM: widget_anchor = GDK_GRAVITY_NORTH_WEST; menu_anchor = GDK_GRAVITY_SOUTH_WEST; break; default: g_assert_not_reached (); break; } gtk_menu_popup_at_widget (GTK_MENU (priv->menu), priv->button, widget_anchor, menu_anchor, event); return TRUE; }
static gboolean tm_do_popup_menu(GtkWidget * toolbar, GdkEventButton * event, toolbar_info * info) { GtkWidget *menu; #if !GTK_CHECK_VERSION(3, 22, 0) int button, event_time; #endif /*GTK_CHECK_VERSION(3, 22, 0) */ guint i; GSList *group = NULL; GtkToolbarStyle default_style = tm_default_style(); if (info->menu) return FALSE; info->menu = menu = gtk_menu_new(); g_signal_connect(menu, "deactivate", G_CALLBACK(tm_popup_deactivated_cb), info); /* ... add menu items ... */ for (i = 0; i < G_N_ELEMENTS(tm_toolbar_options); i++) { GtkWidget *item; if (!tm_toolbar_options[i].text) continue; item = gtk_radio_menu_item_new_with_mnemonic(group, _(tm_toolbar_options[i]. text)); group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(item)); if (tm_toolbar_options[i].style == info->model->style) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); g_object_set_data(G_OBJECT(item), BALSA_TOOLBAR_STYLE, GINT_TO_POINTER(tm_toolbar_options[i].style)); g_signal_connect(item, "toggled", G_CALLBACK(menu_item_toggled_cb), info); } for (i = 0; i < G_N_ELEMENTS(tm_toolbar_options); i++) { if (!tm_toolbar_options[i].text) continue; if (tm_toolbar_options[i].style == default_style) { gchar *option_text, *text; GtkWidget *item; gtk_menu_shell_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new()); option_text = tm_remove_underscore(_(tm_toolbar_options[i].text)); text = g_strdup_printf(_("Use Desktop _Default (%s)"), option_text); g_free(option_text); item = gtk_radio_menu_item_new_with_mnemonic(group, text); g_free(text); if (info->model->style == (GtkToolbarStyle) (-1)) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM (item), TRUE); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); g_object_set_data(G_OBJECT(item), BALSA_TOOLBAR_STYLE, GINT_TO_POINTER(-1)); g_signal_connect(item, "toggled", G_CALLBACK(menu_item_toggled_cb), info); } } if (gtk_widget_is_sensitive(toolbar)) { /* This is a real toolbar, not the template from the * toolbar-prefs dialog. */ GtkWidget *item; gtk_menu_shell_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new()); item = gtk_menu_item_new_with_mnemonic(_("_Customize Toolbars…")); g_signal_connect(item, "activate", G_CALLBACK(customize_dialog_cb), gtk_widget_get_toplevel(toolbar)); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); /* Pass the model type to the customize widget, so that it can * show the appropriate notebook page. */ g_object_set_data(G_OBJECT(item), BALSA_TOOLBAR_MODEL_TYPE, GINT_TO_POINTER(info->model->type)); } gtk_widget_show_all(menu); #if GTK_CHECK_VERSION(3, 22, 0) gtk_menu_attach_to_widget(GTK_MENU(menu), toolbar, NULL); if (event) gtk_menu_popup_at_pointer(GTK_MENU(menu), (GdkEvent *) event); else gtk_menu_popup_at_widget(GTK_MENU(menu), GTK_WIDGET(toolbar), GDK_GRAVITY_CENTER, GDK_GRAVITY_CENTER, NULL); #else /*GTK_CHECK_VERSION(3, 22, 0) */ if (event) { button = event->button; event_time = event->time; } else { button = 0; event_time = gtk_get_current_event_time(); } gtk_menu_attach_to_widget(GTK_MENU(menu), toolbar, NULL); if (button) gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, button, event_time); else gtk_menu_popup(GTK_MENU(menu), NULL, NULL, tm_popup_position_func, toolbar, button, event_time); #endif /*GTK_CHECK_VERSION(3, 22, 0) */ return TRUE; }
static void popup_menu (GtkMenuButton *menu_button, GdkEvent *event) { GtkMenuButtonPrivate *priv = menu_button->priv; GdkGravity widget_anchor = GDK_GRAVITY_SOUTH_WEST; GdkGravity menu_anchor = GDK_GRAVITY_NORTH_WEST; if (priv->func) priv->func (priv->user_data); if (!priv->menu) return; switch (priv->arrow_type) { case GTK_ARROW_UP: g_object_set (priv->menu, "anchor-hints", (GDK_ANCHOR_FLIP_Y | GDK_ANCHOR_SLIDE | GDK_ANCHOR_RESIZE), NULL); switch (gtk_widget_get_halign (priv->menu)) { case GTK_ALIGN_FILL: case GTK_ALIGN_START: case GTK_ALIGN_BASELINE: widget_anchor = GDK_GRAVITY_NORTH_WEST; menu_anchor = GDK_GRAVITY_SOUTH_WEST; break; case GTK_ALIGN_END: widget_anchor = GDK_GRAVITY_NORTH_EAST; menu_anchor = GDK_GRAVITY_SOUTH_EAST; break; case GTK_ALIGN_CENTER: widget_anchor = GDK_GRAVITY_NORTH; menu_anchor = GDK_GRAVITY_SOUTH; break; } break; case GTK_ARROW_DOWN: /* In the common case the menu button is showing a dropdown menu, set the * corresponding type hint on the toplevel, so the WM can omit the top side * of the shadows. */ g_object_set (priv->menu, "anchor-hints", (GDK_ANCHOR_FLIP_Y | GDK_ANCHOR_SLIDE | GDK_ANCHOR_RESIZE), "menu-type-hint", GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU, NULL); switch (gtk_widget_get_halign (priv->menu)) { case GTK_ALIGN_FILL: case GTK_ALIGN_START: case GTK_ALIGN_BASELINE: widget_anchor = GDK_GRAVITY_SOUTH_WEST; menu_anchor = GDK_GRAVITY_NORTH_WEST; break; case GTK_ALIGN_END: widget_anchor = GDK_GRAVITY_SOUTH_EAST; menu_anchor = GDK_GRAVITY_NORTH_EAST; break; case GTK_ALIGN_CENTER: widget_anchor = GDK_GRAVITY_SOUTH; menu_anchor = GDK_GRAVITY_NORTH; break; } break; case GTK_ARROW_LEFT: g_object_set (priv->menu, "anchor-hints", (GDK_ANCHOR_FLIP_X | GDK_ANCHOR_SLIDE | GDK_ANCHOR_RESIZE), NULL); switch (gtk_widget_get_valign (priv->menu)) { case GTK_ALIGN_FILL: case GTK_ALIGN_START: case GTK_ALIGN_BASELINE: widget_anchor = GDK_GRAVITY_NORTH_WEST; menu_anchor = GDK_GRAVITY_NORTH_EAST; break; case GTK_ALIGN_END: widget_anchor = GDK_GRAVITY_SOUTH_WEST; menu_anchor = GDK_GRAVITY_SOUTH_EAST; break; case GTK_ALIGN_CENTER: widget_anchor = GDK_GRAVITY_WEST; menu_anchor = GDK_GRAVITY_EAST; break; } break; case GTK_ARROW_RIGHT: g_object_set (priv->menu, "anchor-hints", (GDK_ANCHOR_FLIP_X | GDK_ANCHOR_SLIDE | GDK_ANCHOR_RESIZE), NULL); switch (gtk_widget_get_valign (priv->menu)) { case GTK_ALIGN_FILL: case GTK_ALIGN_START: case GTK_ALIGN_BASELINE: widget_anchor = GDK_GRAVITY_NORTH_EAST; menu_anchor = GDK_GRAVITY_NORTH_WEST; break; case GTK_ALIGN_END: widget_anchor = GDK_GRAVITY_SOUTH_EAST; menu_anchor = GDK_GRAVITY_SOUTH_WEST; break; case GTK_ALIGN_CENTER: widget_anchor = GDK_GRAVITY_EAST; menu_anchor = GDK_GRAVITY_WEST; break; } break; case GTK_ARROW_NONE: g_object_set (priv->menu, "anchor-hints", (GDK_ANCHOR_FLIP_Y | GDK_ANCHOR_SLIDE | GDK_ANCHOR_RESIZE), NULL); break; } gtk_menu_popup_at_widget (GTK_MENU (priv->menu), GTK_WIDGET (menu_button), widget_anchor, menu_anchor, event); }