2 * geanymenubuttonaction.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2009 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2009 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either vergeany 2 of the License, or
10 * (at your option) any later vergeany.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 /* GtkAction subclass to provide a GtkMenuToolButton in a toolbar.
23 * This class is missing the action_create_menu_item() function and so can't be
24 * used for creating menu items. */
30 #include "geanymenubuttonaction.h"
33 typedef struct _GeanyMenubuttonActionPrivate GeanyMenubuttonActionPrivate
;
35 #define GEANY_MENU_BUTTON_ACTION_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), \
36 GEANY_MENU_BUTTON_ACTION_TYPE, GeanyMenubuttonActionPrivate))
39 struct _GeanyMenubuttonActionPrivate
50 static guint signals
[LAST_SIGNAL
];
53 G_DEFINE_TYPE(GeanyMenubuttonAction
, geany_menu_button_action
, GTK_TYPE_ACTION
);
56 static void geany_menu_button_action_finalize(GObject
*object
)
58 GeanyMenubuttonActionPrivate
*priv
= GEANY_MENU_BUTTON_ACTION_GET_PRIVATE(object
);
60 g_object_unref(priv
->menu
);
62 (* G_OBJECT_CLASS(geany_menu_button_action_parent_class
)->finalize
)(object
);
66 static void delegate_button_activated(GtkAction
*action
)
68 g_signal_emit(action
, signals
[BUTTON_CLICKED
], 0);
72 static void geany_menu_button_action_class_init(GeanyMenubuttonActionClass
*klass
)
74 GtkActionClass
*action_class
= GTK_ACTION_CLASS(klass
);
75 GObjectClass
*g_object_class
= G_OBJECT_CLASS(klass
);
77 g_object_class
->finalize
= geany_menu_button_action_finalize
;
79 action_class
->activate
= delegate_button_activated
;
80 action_class
->toolbar_item_type
= GTK_TYPE_MENU_TOOL_BUTTON
;
82 g_type_class_add_private(klass
, sizeof(GeanyMenubuttonActionPrivate
));
84 signals
[BUTTON_CLICKED
] = g_signal_new("button-clicked",
85 G_TYPE_FROM_CLASS(klass
),
90 g_cclosure_marshal_VOID__VOID
,
95 static void geany_menu_button_action_init(GeanyMenubuttonAction
*action
)
101 GtkAction
*geany_menu_button_action_new(const gchar
*name
,
103 const gchar
*tooltip
,
104 const gchar
*stock_id
)
106 GtkAction
*action
= g_object_new(GEANY_MENU_BUTTON_ACTION_TYPE
,
110 "stock-id", stock_id
,
117 GtkWidget
*geany_menu_button_action_get_menu(GeanyMenubuttonAction
*action
)
119 GeanyMenubuttonActionPrivate
*priv
;
121 g_return_val_if_fail(action
!= NULL
, NULL
);
123 priv
= GEANY_MENU_BUTTON_ACTION_GET_PRIVATE(action
);
129 void geany_menu_button_action_set_menu(GeanyMenubuttonAction
*action
, GtkWidget
*menu
)
131 GeanyMenubuttonActionPrivate
*priv
;
134 g_return_if_fail(action
!= NULL
);
136 priv
= GEANY_MENU_BUTTON_ACTION_GET_PRIVATE(action
);
140 foreach_slist(l
, gtk_action_get_proxies(GTK_ACTION(action
)))
142 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(l
->data
), priv
->menu
);