X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtktoggletoolbutton.c;h=0ed568cbe182d3f5213c5fbd43e1b2d01fa990f9;hb=79695ee64d41c9aadfe2c6f18dc7dd1e3fd44852;hp=cabae8800cf18ca10ae5c67d51b30240e80e5157;hpb=c09cc89317d222e54e98d4e2e9f2792de13897ec;p=~andy%2Fgtk diff --git a/gtk/gtktoggletoolbutton.c b/gtk/gtktoggletoolbutton.c index cabae8800..0ed568cbe 100644 --- a/gtk/gtktoggletoolbutton.c +++ b/gtk/gtktoggletoolbutton.c @@ -1,4 +1,4 @@ -/* gtktoggletoolbutton.c + /* gtktoggletoolbutton.c * * Copyright (C) 2002 Anders Carlsson * Copyright (C) 2002 James Henstridge @@ -14,12 +14,10 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * License along with this library. If not, see . */ -#include +#include "config.h" #include "gtktoggletoolbutton.h" #include "gtkcheckmenuitem.h" #include "gtklabel.h" @@ -27,8 +25,25 @@ #include "gtkstock.h" #include "gtkintl.h" #include "gtkradiotoolbutton.h" +#include "gtktoggleaction.h" +#include "gtkactivatable.h" #include "gtkprivate.h" -#include "gtkalias.h" + + +/** + * SECTION:gtktoggletoolbutton + * @Short_description: A GtkToolItem containing a toggle button + * @Title: GtkToggleToolButton + * @See_also: #GtkToolbar, #GtkToolButton, #GtkSeparatorToolItem + * + * A #GtkToggleToolButton is a #GtkToolItem that contains a toggle + * button. + * + * Use gtk_toggle_tool_button_new() to create a new + * #GtkToggleToolButton. Use gtk_toggle_tool_button_new_from_stock() to + * create a new #GtkToggleToolButton containing a stock item. + */ + #define MENU_ID "gtk-toggle-tool-button-menu-id" @@ -43,15 +58,11 @@ enum { }; -#define GTK_TOGGLE_TOOL_BUTTON_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_TOGGLE_TOOL_BUTTON, GtkToggleToolButtonPrivate)) - struct _GtkToggleToolButtonPrivate { guint active : 1; }; -static void gtk_toggle_tool_button_init (GtkToggleToolButton *button); -static void gtk_toggle_tool_button_class_init (GtkToggleToolButtonClass *klass); static void gtk_toggle_tool_button_set_property (GObject *object, guint prop_id, @@ -69,35 +80,20 @@ static void button_toggled (GtkWidget *widget, static void menu_item_activated (GtkWidget *widget, GtkToggleToolButton *button); -static GObjectClass *parent_class = NULL; -static guint toggle_signals[LAST_SIGNAL] = { 0 }; -GType -gtk_toggle_tool_button_get_type (void) -{ - static GType type = 0; +static void gtk_toggle_tool_button_activatable_interface_init (GtkActivatableIface *iface); +static void gtk_toggle_tool_button_update (GtkActivatable *activatable, + GtkAction *action, + const gchar *property_name); +static void gtk_toggle_tool_button_sync_action_properties (GtkActivatable *activatable, + GtkAction *action); - if (!type) - { - static const GTypeInfo type_info = - { - sizeof (GtkToggleToolButtonClass), - (GBaseInitFunc) 0, - (GBaseFinalizeFunc) 0, - (GClassInitFunc) gtk_toggle_tool_button_class_init, - (GClassFinalizeFunc) 0, - NULL, - sizeof (GtkToggleToolButton), - 0, /* n_preallocs */ - (GInstanceInitFunc) gtk_toggle_tool_button_init - }; - - type = g_type_register_static (GTK_TYPE_TOOL_BUTTON, - g_intern_static_string ("GtkToggleToolButton"), &type_info, 0); - } - return type; -} +static GtkActivatableIface *parent_activatable_iface; +static guint toggle_signals[LAST_SIGNAL] = { 0 }; +G_DEFINE_TYPE_WITH_CODE (GtkToggleToolButton, gtk_toggle_tool_button, GTK_TYPE_TOOL_BUTTON, + G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE, + gtk_toggle_tool_button_activatable_interface_init)) static void gtk_toggle_tool_button_class_init (GtkToggleToolButtonClass *klass) @@ -106,8 +102,6 @@ gtk_toggle_tool_button_class_init (GtkToggleToolButtonClass *klass) GtkToolItemClass *toolitem_class; GtkToolButtonClass *toolbutton_class; - parent_class = g_type_class_peek_parent (klass); - object_class = (GObjectClass *)klass; toolitem_class = (GtkToolItemClass *)klass; toolbutton_class = (GtkToolButtonClass *)klass; @@ -121,7 +115,7 @@ gtk_toggle_tool_button_class_init (GtkToggleToolButtonClass *klass) /** * GtkToggleToolButton:active: * - * If the toggle tool button should be pressed in or not. + * If the toggle tool button should be pressed in. * * Since: 2.8 */ @@ -129,7 +123,7 @@ gtk_toggle_tool_button_class_init (GtkToggleToolButtonClass *klass) PROP_ACTIVE, g_param_spec_boolean ("active", P_("Active"), - P_("If the toggle button should be pressed in or not"), + P_("If the toggle button should be pressed in"), FALSE, GTK_PARAM_READWRITE)); @@ -140,7 +134,7 @@ gtk_toggle_tool_button_class_init (GtkToggleToolButtonClass *klass) * Emitted whenever the toggle tool button changes state. **/ toggle_signals[TOGGLED] = - g_signal_new ("toggled", + g_signal_new (I_("toggled"), G_OBJECT_CLASS_TYPE (klass), G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GtkToggleToolButtonClass, toggled), @@ -157,7 +151,9 @@ gtk_toggle_tool_button_init (GtkToggleToolButton *button) GtkToolButton *tool_button = GTK_TOOL_BUTTON (button); GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (_gtk_tool_button_get_button (tool_button)); - button->priv = GTK_TOGGLE_TOOL_BUTTON_GET_PRIVATE (button); + button->priv = G_TYPE_INSTANCE_GET_PRIVATE (button, + GTK_TYPE_TOGGLE_TOOL_BUTTON, + GtkToggleToolButtonPrivate); /* If the real button is a radio button, it may have been * active at the time it was created. @@ -179,7 +175,8 @@ gtk_toggle_tool_button_set_property (GObject *object, switch (prop_id) { case PROP_ACTIVE: - button->priv->active = g_value_get_boolean (value); + gtk_toggle_tool_button_set_active (button, + g_value_get_boolean (value)); break; default: @@ -217,12 +214,18 @@ gtk_toggle_tool_button_create_menu_proxy (GtkToolItem *item) GtkStockItem stock_item; gboolean use_mnemonic = TRUE; const char *label; + GtkWidget *label_widget; + const gchar *label_text; + const gchar *stock_id; + + if (_gtk_tool_item_create_menu_proxy (item)) + return TRUE; - GtkWidget *label_widget = gtk_tool_button_get_label_widget (tool_button); - const gchar *label_text = gtk_tool_button_get_label (tool_button); - const gchar *stock_id = gtk_tool_button_get_stock_id (tool_button); + label_widget = gtk_tool_button_get_label_widget (tool_button); + label_text = gtk_tool_button_get_label (tool_button); + stock_id = gtk_tool_button_get_stock_id (tool_button); - if (label_widget && GTK_IS_LABEL (label_widget)) + if (GTK_IS_LABEL (label_widget)) { label = gtk_label_get_label (GTK_LABEL (label_widget)); use_mnemonic = gtk_label_get_use_underline (GTK_LABEL (label_widget)); @@ -301,7 +304,9 @@ static void button_toggled (GtkWidget *widget, GtkToggleToolButton *toggle_tool_button) { - gboolean toggle_active = GTK_TOGGLE_BUTTON (widget)->active; + gboolean toggle_active; + + toggle_active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); if (toggle_tool_button->priv->active != toggle_active) { @@ -321,6 +326,52 @@ button_toggled (GtkWidget *widget, } } +static void +gtk_toggle_tool_button_activatable_interface_init (GtkActivatableIface *iface) +{ + parent_activatable_iface = g_type_interface_peek_parent (iface); + iface->update = gtk_toggle_tool_button_update; + iface->sync_action_properties = gtk_toggle_tool_button_sync_action_properties; +} + +static void +gtk_toggle_tool_button_update (GtkActivatable *activatable, + GtkAction *action, + const gchar *property_name) +{ + GtkToggleToolButton *button; + + parent_activatable_iface->update (activatable, action, property_name); + + button = GTK_TOGGLE_TOOL_BUTTON (activatable); + + if (strcmp (property_name, "active") == 0) + { + gtk_action_block_activate (action); + gtk_toggle_tool_button_set_active (button, gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))); + gtk_action_unblock_activate (action); + } +} + +static void +gtk_toggle_tool_button_sync_action_properties (GtkActivatable *activatable, + GtkAction *action) +{ + GtkToggleToolButton *button; + + parent_activatable_iface->sync_action_properties (activatable, action); + + if (!GTK_IS_TOGGLE_ACTION (action)) + return; + + button = GTK_TOGGLE_TOOL_BUTTON (activatable); + + gtk_action_block_activate (action); + gtk_toggle_tool_button_set_active (button, gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))); + gtk_action_unblock_activate (action); +} + + /** * gtk_toggle_tool_button_new: * @@ -410,6 +461,3 @@ gtk_toggle_tool_button_get_active (GtkToggleToolButton *button) return button->priv->active; } - -#define __GTK_TOGGLE_TOOL_BUTTON_C__ -#include "gtkaliasdef.c"