aboutsummaryrefslogtreecommitdiffstats
path: root/lib/egg
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2003-07-02 02:28:05 +0800
committerMarco Pesenti Gritti <mpeseng@src.gnome.org>2003-07-02 02:28:05 +0800
commitc621f76b4e81a30f6d6db5eb16bf2c75d0980468 (patch)
treed2b3d20a5b3482fc27b0faa3fdfcf2624d9ab93a /lib/egg
parent0ab1c928c782530b2d5ab0ad81cb46e5aaed539d (diff)
downloadgsoc2013-epiphany-c621f76b4e81a30f6d6db5eb16bf2c75d0980468.tar
gsoc2013-epiphany-c621f76b4e81a30f6d6db5eb16bf2c75d0980468.tar.gz
gsoc2013-epiphany-c621f76b4e81a30f6d6db5eb16bf2c75d0980468.tar.bz2
gsoc2013-epiphany-c621f76b4e81a30f6d6db5eb16bf2c75d0980468.tar.lz
gsoc2013-epiphany-c621f76b4e81a30f6d6db5eb16bf2c75d0980468.tar.xz
gsoc2013-epiphany-c621f76b4e81a30f6d6db5eb16bf2c75d0980468.tar.zst
gsoc2013-epiphany-c621f76b4e81a30f6d6db5eb16bf2c75d0980468.zip
Make the location entry an EggToolItem, and provide a custom tooptip
2003-07-01 Christian Persch <chpe@cvs.gnome.org> * lib/widgets/ephy-location-entry.h: * lib/widgets/ephy-location-entry.c: (ephy_location_entry_set_tooltip), (ephy_location_entry_construct_contents), (ephy_location_entry_class_init), (ephy_location_entry_init), (ephy_location_entry_finalize): Make the location entry an EggToolItem, and provide a custom tooptip setter. Fix mem leak. * src/ephy-location-action.c: (create_tool_item), (ephy_location_action_class_init), (connect_proxy): Use the location entry EggToolItem instead of constructing it explicitly. * src/toolbar.c: (toolbar_setup_action): Set tooltip for location entry. * lib/egg/egg-action.c: (connect_proxy), (disconnect_proxy): Connect the tooltip sync'er on any EggToolItem, not just EggTollButton:s. Disconnect the tooltip sync func on disconnect, too.
Diffstat (limited to 'lib/egg')
-rw-r--r--lib/egg/egg-action.c16
-rw-r--r--lib/egg/eggtoggletoolbutton.c26
-rw-r--r--lib/egg/eggtoolbar.c74
-rw-r--r--lib/egg/eggtoolbutton.c46
-rw-r--r--lib/egg/eggtoolbutton.h2
-rw-r--r--lib/egg/eggtoolitem.c55
6 files changed, 127 insertions, 92 deletions
diff --git a/lib/egg/egg-action.c b/lib/egg/egg-action.c
index aba6d59db..054159f45 100644
--- a/lib/egg/egg-action.c
+++ b/lib/egg/egg-action.c
@@ -549,10 +549,6 @@ connect_proxy (EggAction *action, GtkWidget *proxy)
g_signal_connect_object (action, "notify::short_label",
G_CALLBACK (egg_action_sync_short_label),
proxy, 0);
- egg_action_sync_tooltip (action, NULL, proxy);
- g_signal_connect_object (action, "notify::tooltip",
- G_CALLBACK (egg_action_sync_tooltip),
- proxy, 0);
g_object_set (G_OBJECT (proxy), "stock_id", action->stock_id, NULL);
g_signal_connect_object (action, "notify::stock_id",
@@ -566,6 +562,14 @@ connect_proxy (EggAction *action, GtkWidget *proxy)
G_CALLBACK (egg_action_activate), action,
G_CONNECT_SWAPPED);
}
+
+ if (EGG_IS_TOOL_ITEM (proxy))
+ {
+ egg_action_sync_tooltip (action, NULL, proxy);
+ g_signal_connect_object (action, "notify::tooltip",
+ G_CALLBACK (egg_action_sync_tooltip),
+ proxy, 0);
+ }
}
static void
@@ -597,6 +601,10 @@ disconnect_proxy (EggAction *action, GtkWidget *proxy)
g_signal_handlers_disconnect_by_func (action,
G_CALLBACK (egg_action_sync_stock_id), proxy);
+ g_signal_handlers_disconnect_by_func (proxy,
+ G_CALLBACK (egg_action_sync_tooltip),
+ action);
+
/* menu item specific synchronisers ... */
g_signal_handlers_disconnect_by_func (action,
G_CALLBACK (egg_action_sync_label),
diff --git a/lib/egg/eggtoggletoolbutton.c b/lib/egg/eggtoggletoolbutton.c
index b755275f2..75d511709 100644
--- a/lib/egg/eggtoggletoolbutton.c
+++ b/lib/egg/eggtoggletoolbutton.c
@@ -38,7 +38,6 @@ enum {
static void egg_toggle_tool_button_init (EggToggleToolButton *button);
static void egg_toggle_tool_button_class_init (EggToggleToolButtonClass *klass);
-static void egg_toggle_tool_button_finalize (GObject *object);
static gboolean egg_toggle_tool_button_create_menu_proxy (EggToolItem *button);
@@ -90,7 +89,6 @@ egg_toggle_tool_button_class_init (EggToggleToolButtonClass *klass)
toolitem_class = (EggToolItemClass *)klass;
toolbutton_class = (EggToolButtonClass *)klass;
- object_class->finalize = egg_toggle_tool_button_finalize;
toolitem_class->create_menu_proxy = egg_toggle_tool_button_create_menu_proxy;
toolbutton_class->button_type = GTK_TYPE_TOGGLE_BUTTON;
@@ -111,18 +109,6 @@ egg_toggle_tool_button_init (EggToggleToolButton *button)
G_CALLBACK (button_toggled), button, 0);
}
-static void
-egg_toggle_tool_button_finalize (GObject *object)
-{
- EggToggleToolButton *button = EGG_TOGGLE_TOOL_BUTTON (object);
-
- if (button->menu_item)
- g_object_remove_weak_pointer (G_OBJECT (button->menu_item),
- (gpointer *)&(button->menu_item));
-
- (* G_OBJECT_CLASS (parent_class)->finalize) (object);
-}
-
static gboolean
egg_toggle_tool_button_create_menu_proxy (EggToolItem *item)
{
@@ -162,6 +148,18 @@ egg_toggle_tool_button_create_menu_proxy (EggToolItem *item)
return TRUE;
}
+/* There are two activatable widgets, a toggle button and a menu item.
+ *
+ * If a widget is activated and the state of the tool button is the same as
+ * the new state of the activated widget, then the other widget was the one
+ * that was activated by the user and updated the tool button's state.
+ *
+ * If the state of the tool button is not the same as the new state of the
+ * activated widget, then the activation was activated by the user, and the
+ * widget needs to make sure the tool button is updated before the other
+ * widget is activated. This will make sure the other widget a tool button
+ * in a state that matches its own new state.
+ */
static void
menu_item_activated (GtkWidget *menu_item,
EggToggleToolButton *toggle_tool_button)
diff --git a/lib/egg/eggtoolbar.c b/lib/egg/eggtoolbar.c
index 7f81ed677..ed4189aae 100644
--- a/lib/egg/eggtoolbar.c
+++ b/lib/egg/eggtoolbar.c
@@ -151,9 +151,8 @@ static gboolean egg_toolbar_move_focus (EggToolbar *toolbar,
static gboolean egg_toolbar_focus_ends (EggToolbar *toolbar,
gboolean home);
-static gboolean egg_toolbar_button_press (GtkWidget *button,
- GdkEventButton *event,
- EggToolbar *toolbar);
+static gboolean egg_toolbar_button_press (GtkWidget *toolbar,
+ GdkEventButton *event);
static gboolean egg_toolbar_arrow_button_press (GtkWidget *button,
GdkEventButton *event,
EggToolbar *toolbar);
@@ -285,6 +284,7 @@ egg_toolbar_class_init (EggToolbarClass *klass)
gobject_class->set_property = egg_toolbar_set_property;
gobject_class->get_property = egg_toolbar_get_property;
+ widget_class->button_press_event = egg_toolbar_button_press;
widget_class->expose_event = egg_toolbar_expose;
widget_class->size_request = egg_toolbar_size_request;
widget_class->size_allocate = egg_toolbar_size_allocate;
@@ -527,9 +527,6 @@ egg_toolbar_init (EggToolbar *toolbar)
gtk_widget_set_parent (priv->arrow_button, GTK_WIDGET (toolbar));
- g_signal_connect (GTK_WIDGET (toolbar), "button_press_event",
- G_CALLBACK (egg_toolbar_button_press), toolbar);
-
/* which child position a drop will occur at */
priv->drop_index = -1;
priv->drag_highlight = NULL;
@@ -878,9 +875,14 @@ egg_toolbar_size_request (GtkWidget *widget,
gtk_widget_size_request (priv->arrow_button, &arrow_requisition);
if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
- long_req = pack_end_size + MIN (pack_front_size, arrow_requisition.width);
+ long_req = arrow_requisition.width;
else
- long_req = pack_end_size + MIN (pack_front_size, arrow_requisition.height);
+ long_req = arrow_requisition.height;
+
+ /* There is no point requesting space for the arrow if that would take
+ * up more space than all the items combined
+ */
+ long_req = MIN (long_req, pack_front_size + pack_end_size);
}
else
{
@@ -1305,16 +1307,19 @@ egg_toolbar_focus_ends (EggToolbar *toolbar,
gboolean home)
{
GList *children, *list;
- GtkTextDirection direction = gtk_widget_get_direction (GTK_WIDGET (toolbar));
+ GtkDirectionType dir = home? GTK_DIR_RIGHT : GTK_DIR_LEFT;
- if (direction == GTK_TEXT_DIR_RTL)
- children = egg_toolbar_list_children_in_focus_order (toolbar, GTK_DIR_RIGHT);
- else
- children = egg_toolbar_list_children_in_focus_order (toolbar, GTK_DIR_LEFT);
+ children = egg_toolbar_list_children_in_focus_order (toolbar, dir);
+
+ if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
+ {
+ children = g_list_reverse (children);
+ if (dir == GTK_DIR_RIGHT)
+ dir = GTK_DIR_LEFT;
+ else
+ dir = GTK_DIR_RIGHT;
+ }
- if (home)
- children = g_list_reverse (children);
-
for (list = children; list != NULL; list = list->next)
{
GtkWidget *child = list->data;
@@ -1322,7 +1327,7 @@ egg_toolbar_focus_ends (EggToolbar *toolbar,
if (GTK_CONTAINER (toolbar)->focus_child == child)
break;
- if (GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, GTK_DIR_RIGHT))
+ if (GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
break;
}
@@ -1355,14 +1360,21 @@ egg_toolbar_move_focus (EggToolbar *toolbar,
return TRUE;
}
+/* The focus handler for the toolbar. It called when the user presses TAB or otherwise
+ * tries to focus the toolbar.
+ */
static gboolean
egg_toolbar_focus (GtkWidget *widget,
GtkDirectionType dir)
{
EggToolbar *toolbar = EGG_TOOLBAR (widget);
GList *children, *list;
- gboolean retval = FALSE;
-
+
+ /* if focus is already somewhere inside the toolbar then return FALSE.
+ * The only way focus can stay inside the toolbar is when the user presses
+ * arrow keys or Ctrl TAB (both of which are handled by the
+ * egg_toolbar_move_focus() keybinding function.
+ */
if (GTK_CONTAINER (widget)->focus_child)
return FALSE;
@@ -1372,16 +1384,13 @@ egg_toolbar_focus (GtkWidget *widget,
{
GtkWidget *child = list->data;
- if (GTK_WIDGET_MAPPED (child))
- {
- retval = gtk_widget_child_focus (child, dir);
- break;
- }
+ if (GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
+ return TRUE;
}
g_list_free (children);
- return retval;
+ return FALSE;
}
static void
@@ -1927,7 +1936,8 @@ egg_toolbar_arrow_button_clicked (GtkWidget *button,
(!priv->menu || !GTK_WIDGET_VISIBLE (GTK_WIDGET (priv->menu))))
{
/* We only get here when the button is clicked with the keybaord,
- * because mouse button presses result in the menu being shown.
+ * because mouse button presses result in the menu being shown so
+ * that priv->menu would be non-NULL and visible.
*/
show_menu (toolbar, NULL);
gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menu), FALSE);
@@ -1946,15 +1956,11 @@ egg_toolbar_arrow_button_press (GtkWidget *button,
}
static gboolean
-egg_toolbar_button_press (GtkWidget *button,
- GdkEventButton *event,
- EggToolbar *toolbar)
+egg_toolbar_button_press (GtkWidget *toolbar,
+ GdkEventButton *event)
{
if (event->button == 3)
- {
- g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0, NULL);
- return FALSE;
- }
+ g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0, NULL);
return FALSE;
}
@@ -2164,6 +2170,8 @@ egg_toolbar_set_style (EggToolbar *toolbar,
toolbar->style_set = TRUE;
g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
+
+
}
GtkToolbarStyle
diff --git a/lib/egg/eggtoolbutton.c b/lib/egg/eggtoolbutton.c
index 88b70e632..6f827e576 100644
--- a/lib/egg/eggtoolbutton.c
+++ b/lib/egg/eggtoolbutton.c
@@ -211,8 +211,15 @@ egg_tool_button_size_request (GtkWidget *widget,
{
GtkWidget *child = GTK_BIN (widget)->child;
- if (child)
- gtk_widget_size_request (child, requisition);
+ if (child && GTK_WIDGET_VISIBLE (child))
+ {
+ gtk_widget_size_request (child, requisition);
+ }
+ else
+ {
+ requisition->width = 0;
+ requisition->height = 0;
+ }
requisition->width += GTK_CONTAINER (widget)->border_width * 2;
requisition->height += GTK_CONTAINER (widget)->border_width * 2;
@@ -617,19 +624,19 @@ void
egg_tool_button_set_label (EggToolButton *button,
const gchar *label)
{
+ gchar *old_label;
+
g_return_if_fail (EGG_IS_TOOL_BUTTON (button));
- if (label != button->label_text)
- {
- if (button->label_text)
- g_free (button->label_text);
-
- button->label_text = g_strdup (label);
+ old_label = button->label_text;
- egg_tool_button_construct_contents (EGG_TOOL_ITEM (button));
+ button->label_text = g_strdup (label);
+ egg_tool_button_construct_contents (EGG_TOOL_ITEM (button));
- g_object_notify (G_OBJECT (button), "label");
- }
+ g_object_notify (G_OBJECT (button), "label");
+
+ if (old_label)
+ g_free (old_label);
}
G_CONST_RETURN gchar *
@@ -670,19 +677,18 @@ void
egg_tool_button_set_stock_id (EggToolButton *button,
const gchar *stock_id)
{
+ gchar *old_stock_id;
+
g_return_if_fail (EGG_IS_TOOL_BUTTON (button));
- if (button->stock_id != stock_id)
- {
- if (button->stock_id)
- g_free (button->stock_id);
+ old_stock_id = button->stock_id;
- button->stock_id = g_strdup (stock_id);
-
- egg_tool_button_construct_contents (EGG_TOOL_ITEM (button));
+ button->stock_id = g_strdup (stock_id);
+ egg_tool_button_construct_contents (EGG_TOOL_ITEM (button));
+
+ g_object_notify (G_OBJECT (button), "stock_id");
- g_object_notify (G_OBJECT (button), "stock_id");
- }
+ g_free (old_stock_id);
}
G_CONST_RETURN gchar *
diff --git a/lib/egg/eggtoolbutton.h b/lib/egg/eggtoolbutton.h
index 4ee7ff157..667d6547c 100644
--- a/lib/egg/eggtoolbutton.h
+++ b/lib/egg/eggtoolbutton.h
@@ -78,8 +78,6 @@ G_CONST_RETURN gchar *egg_tool_button_get_stock_id (EggToolButton *button);
void egg_tool_button_set_icon_set (EggToolButton *button,
GtkIconSet *icon_set);
GtkIconSet * egg_tool_button_get_icon_set (EggToolButton *button);
-void egg_tool_button_set_icon_set (EggToolButton *button,
- GtkIconSet *icon_set);
void egg_tool_button_set_icon_widget (EggToolButton *button,
GtkWidget *icon);
GtkWidget * egg_tool_button_get_icon_widget (EggToolButton *button);
diff --git a/lib/egg/eggtoolitem.c b/lib/egg/eggtoolitem.c
index 0e7ea5b72..b66376d36 100644
--- a/lib/egg/eggtoolitem.c
+++ b/lib/egg/eggtoolitem.c
@@ -362,8 +362,15 @@ egg_tool_item_size_request (GtkWidget *widget,
gint xthickness = widget->style->xthickness;
gint ythickness = widget->style->ythickness;
- if (child)
- gtk_widget_size_request (child, requisition);
+ if (child && GTK_WIDGET_VISIBLE (child))
+ {
+ gtk_widget_size_request (child, requisition);
+ }
+ else
+ {
+ requisition->height = 0;
+ requisition->width = 0;
+ }
requisition->width += (xthickness + GTK_CONTAINER (widget)->border_width) * 2;
requisition->height += (ythickness + GTK_CONTAINER (widget)->border_width) * 2;
@@ -405,14 +412,18 @@ egg_tool_item_size_allocate (GtkWidget *widget,
static gboolean
egg_tool_item_create_menu_proxy (EggToolItem *item)
{
- GtkWidget *menu_item = NULL;
-
if (!GTK_BIN (item)->child)
- menu_item = gtk_separator_menu_item_new();
+ {
+ GtkWidget *menu_item = NULL;
+
+ menu_item = gtk_separator_menu_item_new();
+
+ egg_tool_item_set_proxy_menu_item (item, MENU_ID, menu_item);
- egg_tool_item_set_proxy_menu_item (item, MENU_ID, menu_item);
+ return TRUE;
+ }
- return TRUE;
+ return FALSE;
}
EggToolItem *
@@ -543,9 +554,12 @@ egg_tool_item_real_set_tooltip (EggToolItem *tool_item,
const gchar *tip_text,
const gchar *tip_private)
{
- GtkBin *bin = GTK_BIN (tool_item);
+ GtkWidget *child = GTK_BIN (tool_item)->child;
- gtk_tooltips_set_tip (tooltips, bin->child, tip_text, tip_private);
+ if (!child)
+ return FALSE;
+
+ gtk_tooltips_set_tip (tooltips, child, tip_text, tip_private);
return TRUE;
}
@@ -678,19 +692,22 @@ egg_tool_item_set_proxy_menu_item (EggToolItem *tool_item,
g_return_if_fail (menu_item == NULL || GTK_IS_MENU_ITEM (menu_item));
g_return_if_fail (menu_item_id != NULL);
- if (tool_item->menu_item)
- g_object_unref (G_OBJECT (tool_item->menu_item));
-
if (tool_item->menu_item_id)
g_free (tool_item->menu_item_id);
+
+ tool_item->menu_item_id = g_strdup (menu_item_id);
- if (menu_item)
+ if (tool_item->menu_item != menu_item)
{
- g_object_ref (menu_item);
- gtk_object_sink (GTK_OBJECT (menu_item));
+ if (tool_item->menu_item)
+ g_object_unref (G_OBJECT (tool_item->menu_item));
+
+ if (menu_item)
+ {
+ g_object_ref (menu_item);
+ gtk_object_sink (GTK_OBJECT (menu_item));
+ }
+
+ tool_item->menu_item = menu_item;
}
-
- tool_item->menu_item = menu_item;
-
- tool_item->menu_item_id = g_strdup (menu_item_id);
}