aboutsummaryrefslogtreecommitdiffstats
path: root/lib/widgets/ephy-zoom-action.c
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2004-02-05 06:25:27 +0800
committerChristian Persch <chpe@src.gnome.org>2004-02-05 06:25:27 +0800
commit74c61ab583069d84e242400b064ab0f1ca828e29 (patch)
treea4cda37f86cc5d028f6e6990267639de8cbf6c79 /lib/widgets/ephy-zoom-action.c
parent0d384021eea98605ab92c8b8842a9c0c8e9240b3 (diff)
downloadgsoc2013-epiphany-74c61ab583069d84e242400b064ab0f1ca828e29.tar
gsoc2013-epiphany-74c61ab583069d84e242400b064ab0f1ca828e29.tar.gz
gsoc2013-epiphany-74c61ab583069d84e242400b064ab0f1ca828e29.tar.bz2
gsoc2013-epiphany-74c61ab583069d84e242400b064ab0f1ca828e29.tar.lz
gsoc2013-epiphany-74c61ab583069d84e242400b064ab0f1ca828e29.tar.xz
gsoc2013-epiphany-74c61ab583069d84e242400b064ab0f1ca828e29.tar.zst
gsoc2013-epiphany-74c61ab583069d84e242400b064ab0f1ca828e29.zip
Fix toolbar overflow menu creation. Don't connect zoom control signals to
2004-02-04 Christian Persch <chpe@cvs.gnome.org> * lib/widgets/ephy-zoom-action.c: (ephy_zoom_action_get_type), (zoom_to_level_cb), (connect_proxy), (proxy_menu_activate_cb), (create_menu_item), (ephy_zoom_action_class_init): * lib/widgets/ephy-zoom-action.h: * lib/widgets/ephy-zoom-control.c: (ephy_zoom_control_class_init): * src/ephy-history-window.c: (cmd_delete), Fix toolbar overflow menu creation. Don't connect zoom control signals to a menu item.
Diffstat (limited to 'lib/widgets/ephy-zoom-action.c')
-rw-r--r--lib/widgets/ephy-zoom-action.c101
1 files changed, 82 insertions, 19 deletions
diff --git a/lib/widgets/ephy-zoom-action.c b/lib/widgets/ephy-zoom-action.c
index 33eaf96eb..c72d00cc3 100644
--- a/lib/widgets/ephy-zoom-action.c
+++ b/lib/widgets/ephy-zoom-action.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2003 Marco Pesenti Gritti
- * Copyright (C) 2003 Christian Persch
+ * Copyright (C) 2003, 2004 Christian Persch
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -20,7 +20,7 @@
*/
#ifdef HAVE_CONFIG_H
-#include <config.h>
+#include "config.h"
#endif
#include "ephy-zoom-action.h"
@@ -29,10 +29,15 @@
#include <glib-object.h>
#include <glib/gi18n.h>
+#include <gtk/gtkmenu.h>
+#include <gtk/gtkmenuitem.h>
+#include <gtk/gtkcheckmenuitem.h>
+#include <gtk/gtkradiomenuitem.h>
#define EPHY_ZOOM_ACTION_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_ZOOM_ACTION, EphyZoomActionPrivate))
-struct _EphyZoomActionPrivate {
+struct EphyZoomActionPrivate
+{
float zoom;
};
@@ -52,16 +57,16 @@ enum
LAST_SIGNAL
};
-static guint ephy_zoom_action_signals[LAST_SIGNAL] = { 0 };
+static guint signals[LAST_SIGNAL] = { 0 };
static GObjectClass *parent_class = NULL;
GType
ephy_zoom_action_get_type (void)
{
- static GType ephy_zoom_action_type = 0;
+ static GType type = 0;
- if (ephy_zoom_action_type == 0)
+ if (type == 0)
{
static const GTypeInfo our_info =
{
@@ -76,12 +81,12 @@ ephy_zoom_action_get_type (void)
(GInstanceInitFunc) ephy_zoom_action_init,
};
- ephy_zoom_action_type = g_type_register_static (GTK_TYPE_ACTION,
- "EphyZoomAction",
- &our_info, 0);
+ type = g_type_register_static (GTK_TYPE_ACTION,
+ "EphyZoomAction",
+ &our_info, 0);
}
- return ephy_zoom_action_type;
+ return type;
}
static void
@@ -89,9 +94,7 @@ zoom_to_level_cb (EphyZoomControl *control,
float zoom,
EphyZoomAction *action)
{
- g_signal_emit (action,
- ephy_zoom_action_signals[ZOOM_TO_LEVEL_SIGNAL],
- 0, zoom);
+ g_signal_emit (action, signals[ZOOM_TO_LEVEL_SIGNAL], 0, zoom);
}
static void
@@ -105,16 +108,75 @@ sync_zoom_cb (GtkAction *action, GParamSpec *pspec, GtkWidget *proxy)
static void
connect_proxy (GtkAction *action, GtkWidget *proxy)
{
- g_signal_connect_object (action, "notify::zoom",
- G_CALLBACK (sync_zoom_cb), proxy, 0);
-
- g_signal_connect (proxy, "zoom_to_level",
- G_CALLBACK (zoom_to_level_cb), action);
+ if (EPHY_IS_ZOOM_CONTROL (proxy))
+ {
+ g_signal_connect_object (action, "notify::zoom",
+ G_CALLBACK (sync_zoom_cb), proxy, 0);
+
+ g_signal_connect (proxy, "zoom_to_level",
+ G_CALLBACK (zoom_to_level_cb), action);
+ }
GTK_ACTION_CLASS (parent_class)->connect_proxy (action, proxy);
}
static void
+proxy_menu_activate_cb (GtkMenuItem *menu_item, EphyZoomAction *action)
+{
+ gint index;
+ float zoom;
+
+ /* menu item was toggled OFF */
+ if (!gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (menu_item))) return;
+
+ index = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menu_item), "zoom-level"));
+ zoom = zoom_levels[index].level;
+
+ if (zoom != action->priv->zoom)
+ {
+ g_print ("zoom_to_level emit, to %f from %f\n", zoom, action->priv->zoom);
+ g_signal_emit (action, signals[ZOOM_TO_LEVEL_SIGNAL], 0, zoom);
+ }
+}
+
+static GtkWidget *
+create_menu_item (GtkAction *action)
+{
+ EphyZoomActionPrivate *p = EPHY_ZOOM_ACTION (action)->priv;
+ GtkWidget *menu, *menu_item;
+ GSList *group = NULL;
+ int i;
+
+ menu = gtk_menu_new ();
+
+ for (i = 0; i < n_zoom_levels; i++)
+ {
+ menu_item = gtk_radio_menu_item_new_with_label (group, _(zoom_levels[i].name));
+ group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menu_item));
+
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item),
+ p->zoom == zoom_levels[i].level);
+
+ gtk_widget_show (menu_item);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
+
+ g_object_set_data (G_OBJECT (menu_item), "zoom-level", GINT_TO_POINTER (i));
+ g_signal_connect_object (G_OBJECT (menu_item), "activate",
+ G_CALLBACK (proxy_menu_activate_cb), action, 0);
+ }
+
+ gtk_widget_show (menu);
+
+ menu_item = GTK_ACTION_CLASS (parent_class)->create_menu_item (action);
+
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), menu);
+
+ gtk_widget_show (menu_item);
+
+ return menu_item;
+}
+
+static void
ephy_zoom_action_set_property (GObject *object,
guint prop_id,
const GValue *value,
@@ -164,6 +226,7 @@ ephy_zoom_action_class_init (EphyZoomActionClass *class)
action_class->toolbar_item_type = EPHY_TYPE_ZOOM_CONTROL;
action_class->connect_proxy = connect_proxy;
+ action_class->create_menu_item = create_menu_item;
g_object_class_install_property (object_class,
PROP_ZOOM,
@@ -175,7 +238,7 @@ ephy_zoom_action_class_init (EphyZoomActionClass *class)
1.0,
G_PARAM_READWRITE));
- ephy_zoom_action_signals[ZOOM_TO_LEVEL_SIGNAL] =
+ signals[ZOOM_TO_LEVEL_SIGNAL] =
g_signal_new ("zoom_to_level",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,