diff options
author | Christian Persch <chpe@cvs.gnome.org> | 2004-12-17 04:52:58 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2004-12-17 04:52:58 +0800 |
commit | fb9a15960ab8001fa51ecb794afda2738e8de4b0 (patch) | |
tree | 78943c1122617b7eb641f943e4931859d744e63b | |
parent | 7e75b259439311d98f52fbdd5f1f5e8df47f1a7f (diff) | |
download | gsoc2013-epiphany-fb9a15960ab8001fa51ecb794afda2738e8de4b0.tar gsoc2013-epiphany-fb9a15960ab8001fa51ecb794afda2738e8de4b0.tar.gz gsoc2013-epiphany-fb9a15960ab8001fa51ecb794afda2738e8de4b0.tar.bz2 gsoc2013-epiphany-fb9a15960ab8001fa51ecb794afda2738e8de4b0.tar.lz gsoc2013-epiphany-fb9a15960ab8001fa51ecb794afda2738e8de4b0.tar.xz gsoc2013-epiphany-fb9a15960ab8001fa51ecb794afda2738e8de4b0.tar.zst gsoc2013-epiphany-fb9a15960ab8001fa51ecb794afda2738e8de4b0.zip |
Implement context menu on tray icon, as per HIG. Fixes bug #152903.
2004-12-16 Christian Persch <chpe@cvs.gnome.org>
* embed/downloader-view.c: (show_downloader_cb),
(status_icon_popup_menu_cb), (show_status_icon):
* lib/egg/eggstatusicon.c: (egg_status_icon_class_init),
(egg_status_icon_init), (egg_status_icon_finalize),
(emit_activate_signal), (emit_popup_menu_signal),
(egg_status_icon_size_allocate), (egg_status_icon_button_press),
(egg_status_icon_set_tooltip):
* lib/egg/eggstatusicon.h:
* lib/ephy-gui.c: (ephy_gui_menu_position_under_widget),
(ephy_gui_menu_position_on_panel):
* lib/ephy-gui.h:
Implement context menu on tray icon, as per HIG. Fixes bug #152903.
-rw-r--r-- | ChangeLog | 16 | ||||
-rw-r--r-- | embed/downloader-view.c | 36 | ||||
-rw-r--r-- | lib/egg/eggstatusicon.c | 63 | ||||
-rw-r--r-- | lib/egg/eggstatusicon.h | 7 | ||||
-rw-r--r-- | lib/ephy-gui.c | 42 | ||||
-rw-r--r-- | lib/ephy-gui.h | 6 |
6 files changed, 129 insertions, 41 deletions
@@ -1,5 +1,21 @@ 2004-12-16 Christian Persch <chpe@cvs.gnome.org> + * embed/downloader-view.c: (show_downloader_cb), + (status_icon_popup_menu_cb), (show_status_icon): + * lib/egg/eggstatusicon.c: (egg_status_icon_class_init), + (egg_status_icon_init), (egg_status_icon_finalize), + (emit_activate_signal), (emit_popup_menu_signal), + (egg_status_icon_size_allocate), (egg_status_icon_button_press), + (egg_status_icon_set_tooltip): + * lib/egg/eggstatusicon.h: + * lib/ephy-gui.c: (ephy_gui_menu_position_under_widget), + (ephy_gui_menu_position_on_panel): + * lib/ephy-gui.h: + + Implement context menu on tray icon, as per HIG. Fixes bug #152903. + +2004-12-16 Christian Persch <chpe@cvs.gnome.org> + * src/ephy-history-window.c: (confirmation_dialog_construct): Add stock icon to the "Clear" button. diff --git a/embed/downloader-view.c b/embed/downloader-view.c index e2b7e8edd..f8e1f2400 100644 --- a/embed/downloader-view.c +++ b/embed/downloader-view.c @@ -25,6 +25,8 @@ #include "ephy-file-helpers.h" #include "ephy-embed-shell.h" #include "ephy-stock-icons.h" +#include "ephy-gui.h" +#include "ephy-debug.h" #include <libgnomevfs/gnome-vfs-utils.h> #include <eggstatusicon.h> @@ -39,6 +41,10 @@ #include <gtk/gtktreeviewcolumn.h> #include <gtk/gtkicontheme.h> #include <gtk/gtkiconfactory.h> +#include <gtk/gtkmenuitem.h> +#include <gtk/gtkmenushell.h> +#include <gtk/gtkmenu.h> +#include <gtk/gtkmain.h> #include <libgnomeui/gnome-icon-lookup.h> #include <glib/gi18n.h> @@ -157,11 +163,33 @@ downloader_view_class_init (DownloaderViewClass *klass) } static void -status_icon_activated (EggStatusIcon *icon, DownloaderView *dv) +show_downloader_cb (DownloaderView *dv) { gtk_window_present (GTK_WINDOW (dv->priv->window)); } +static gboolean +status_icon_popup_menu_cb (EggStatusIcon *icon, + DownloaderView *dv) +{ + GtkWidget *menu, *item; + guint button = 0; + + menu = gtk_menu_new (); + + item = gtk_menu_item_new_with_mnemonic (_("_Show Downloader...")); + g_signal_connect_swapped (item, "activate", + G_CALLBACK (show_downloader_cb), dv); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + gtk_widget_show_all (menu); + + gtk_menu_popup (GTK_MENU (menu), NULL, NULL, + ephy_gui_menu_position_on_panel, icon->tray_icon, + button, gtk_get_current_event_time ()); + + return TRUE; +} + static void show_status_icon (DownloaderView *dv) { @@ -171,8 +199,10 @@ show_status_icon (DownloaderView *dv) dv->priv->status_icon = egg_status_icon_new_from_pixbuf (pixbuf); g_object_unref (pixbuf); - g_signal_connect (dv->priv->status_icon, "activate", - G_CALLBACK (status_icon_activated), dv); + g_signal_connect_swapped (dv->priv->status_icon, "activate", + G_CALLBACK (show_downloader_cb), dv); + g_signal_connect (dv->priv->status_icon, "popup-menu", + G_CALLBACK(status_icon_popup_menu_cb), dv); } static void diff --git a/lib/egg/eggstatusicon.c b/lib/egg/eggstatusicon.c index 1893d4459..350bc3c11 100644 --- a/lib/egg/eggstatusicon.c +++ b/lib/egg/eggstatusicon.c @@ -101,7 +101,7 @@ static gboolean egg_status_icon_button_press (EggStatusIcon *status_icon, GdkEventButton *event); static void egg_status_icon_disable_blinking (EggStatusIcon *status_icon); static void egg_status_icon_reset_image_data (EggStatusIcon *status_icon); - +static gboolean emit_popup_menu_signal (EggStatusIcon *status_icon); static GObjectClass *parent_class = NULL; static guint status_icon_signals [LAST_SIGNAL] = { 0 }; @@ -218,15 +218,13 @@ egg_status_icon_class_init (EggStatusIconClass *klass) status_icon_signals [POPUP_MENU_SIGNAL] = g_signal_new ("popup-menu", G_TYPE_FROM_CLASS (gobject_class), - G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, + G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (EggStatusIconClass, popup_menu), + g_signal_accumulator_true_handled, NULL, - NULL, - _egg_marshal_VOID__UINT_UINT, - G_TYPE_NONE, - 2, - G_TYPE_UINT, - G_TYPE_UINT); + g_cclosure_marshal_VOID__VOID, + G_TYPE_BOOLEAN, + 0); status_icon_signals [SIZE_CHANGED_SIGNAL] = g_signal_new ("size-changed", @@ -249,23 +247,24 @@ egg_status_icon_init (EggStatusIcon *status_icon) status_icon->priv->image_type = GTK_IMAGE_EMPTY; status_icon->priv->size = G_MAXINT; - status_icon->priv->tray_icon = GTK_WIDGET (egg_tray_icon_new (NULL)); + status_icon->tray_icon = GTK_WIDGET (egg_tray_icon_new (NULL)); - gtk_widget_add_events (GTK_WIDGET (status_icon->priv->tray_icon), + gtk_widget_add_events (GTK_WIDGET (status_icon->tray_icon), GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK); - g_signal_connect_swapped (status_icon->priv->tray_icon, "button-press-event", + g_signal_connect_swapped (status_icon->tray_icon, "button-press-event", G_CALLBACK (egg_status_icon_button_press), status_icon); - + g_signal_connect_swapped (status_icon->tray_icon, "popup-menu", + G_CALLBACK (emit_popup_menu_signal), status_icon); status_icon->priv->image = gtk_image_new (); - gtk_container_add (GTK_CONTAINER (status_icon->priv->tray_icon), + gtk_container_add (GTK_CONTAINER (status_icon->tray_icon), status_icon->priv->image); g_signal_connect_swapped (status_icon->priv->image, "size-allocate", G_CALLBACK (egg_status_icon_size_allocate), status_icon); gtk_widget_show (status_icon->priv->image); - gtk_widget_show (status_icon->priv->tray_icon); + gtk_widget_show (status_icon->tray_icon); status_icon->priv->tooltips = gtk_tooltips_new (); g_object_ref (status_icon->priv->tooltips); @@ -289,7 +288,7 @@ egg_status_icon_finalize (GObject *object) g_object_unref (status_icon->priv->tooltips); status_icon->priv->tooltips = NULL; - gtk_widget_destroy (status_icon->priv->tray_icon); + gtk_widget_destroy (status_icon->tray_icon); g_free (status_icon->priv); @@ -402,22 +401,19 @@ egg_status_icon_new_from_animation (GdkPixbufAnimation *animation) static void emit_activate_signal (EggStatusIcon *status_icon) { - g_signal_emit (status_icon, - status_icon_signals [ACTIVATE_SIGNAL], 0); + g_signal_emit (status_icon, status_icon_signals [ACTIVATE_SIGNAL], 0); } -#ifdef UNUSED -static void -emit_popup_menu_signal (EggStatusIcon *status_icon, - guint button, - guint32 activate_time) +static gboolean +emit_popup_menu_signal (EggStatusIcon *status_icon) { - g_signal_emit (status_icon, - status_icon_signals [POPUP_MENU_SIGNAL], 0, - button, - activate_time); + gboolean retval = FALSE; + + g_signal_emit (status_icon, status_icon_signals [POPUP_MENU_SIGNAL], 0, + &retval); + + return retval; } -#endif static gboolean emit_size_changed_signal (EggStatusIcon *status_icon, @@ -534,7 +530,7 @@ egg_status_icon_size_allocate (EggStatusIcon *status_icon, GtkOrientation orientation; gint size; - orientation = egg_tray_icon_get_orientation (EGG_TRAY_ICON (status_icon->priv->tray_icon)); + orientation = egg_tray_icon_get_orientation (EGG_TRAY_ICON (status_icon->tray_icon)); if (orientation == GTK_ORIENTATION_HORIZONTAL) size = allocation->height; @@ -558,13 +554,18 @@ static gboolean egg_status_icon_button_press (EggStatusIcon *status_icon, GdkEventButton *event) { + gboolean handled = FALSE; if (event->button == 1 && event->type == GDK_2BUTTON_PRESS) { emit_activate_signal (status_icon); - return TRUE; + handled = TRUE; + } + else if (event->button == 3 && event->type == GDK_BUTTON_PRESS) + { + handled = emit_popup_menu_signal (status_icon); } - return FALSE; + return handled; } static void @@ -692,7 +693,7 @@ egg_status_icon_set_tooltip (EggStatusIcon *status_icon, g_return_if_fail (EGG_IS_STATUS_ICON (status_icon)); gtk_tooltips_set_tip (status_icon->priv->tooltips, - status_icon->priv->tray_icon, + status_icon->tray_icon, tooltip_text, tooltip_private); } diff --git a/lib/egg/eggstatusicon.h b/lib/egg/eggstatusicon.h index cde7ae9df..58bb59319 100644 --- a/lib/egg/eggstatusicon.h +++ b/lib/egg/eggstatusicon.h @@ -44,6 +44,9 @@ struct _EggStatusIcon { GObject parent_instance; + /*< public >*/ + GtkWidget *tray_icon; + /*< private >*/ EggStatusIconPrivate *priv; }; @@ -52,9 +55,7 @@ struct _EggStatusIconClass GObjectClass parent_class; void (* activate) (EggStatusIcon *status_icon); - void (* popup_menu) (EggStatusIcon *status_icon, - guint buttton, - guint32 activate_time); + gboolean (* popup_menu) (EggStatusIcon *status_icon); gboolean (* size_changed) (EggStatusIcon *status_icon, gint size); }; diff --git a/lib/ephy-gui.c b/lib/ephy-gui.c index ae389b01f..cd8f09e02 100644 --- a/lib/ephy-gui.c +++ b/lib/ephy-gui.c @@ -113,14 +113,11 @@ ephy_gui_menu_position_under_widget (GtkMenu *menu, { GtkWidget *w = GTK_WIDGET (user_data); GtkRequisition requisition; - gboolean rtl; - - rtl = (gtk_widget_get_direction (w) == GTK_TEXT_DIR_RTL); gdk_window_get_origin (w->window, x, y); gtk_widget_size_request (GTK_WIDGET (menu), &requisition); - if (rtl) + if (gtk_widget_get_direction (w) == GTK_TEXT_DIR_RTL) { *x += w->allocation.x + w->allocation.width - requisition.width; } @@ -134,6 +131,43 @@ ephy_gui_menu_position_under_widget (GtkMenu *menu, ephy_gui_sanitise_popup_position (menu, w, x, y); } +void +ephy_gui_menu_position_on_panel (GtkMenu *menu, + gint *x, + gint *y, + gboolean *push_in, + gpointer user_data) +{ + GtkWidget *widget = GTK_WIDGET (user_data); + GtkRequisition requisition; + GdkScreen *screen; + + screen = gtk_widget_get_screen (widget); + + gdk_window_get_origin (widget->window, x, y); + gtk_widget_size_request (GTK_WIDGET (menu), &requisition); + + if (GTK_WIDGET_NO_WINDOW (widget)) + {g_print ("NOT WINDOW!\n"); + *x += widget->allocation.x; + *y += widget->allocation.y; + } + + /* FIXME: Adapt to vertical panels, but egg_tray_icon_get_orientation doesn't seem to work */ + if (*y > gdk_screen_get_height (screen) / 2) + { + *y -= requisition.height; + } + else + { + *y += widget->allocation.height; + } + + *push_in = FALSE; + + ephy_gui_sanitise_popup_position (menu, widget, x, y); +} + gboolean ephy_gui_confirm_overwrite_file (GtkWidget *parent, const char *filename) { diff --git a/lib/ephy-gui.h b/lib/ephy-gui.h index caa4035d8..73f2e5bce 100644 --- a/lib/ephy-gui.h +++ b/lib/ephy-gui.h @@ -47,6 +47,12 @@ void ephy_gui_menu_position_under_widget (GtkMenu *menu, gboolean *push_in, gpointer user_data); +void ephy_gui_menu_position_on_panel (GtkMenu *menu, + gint *x, + gint *y, + gboolean *push_in, + gpointer user_data); + gboolean ephy_gui_is_middle_click (void); gboolean ephy_gui_select_row_by_key (GtkTreeView *treeview, |