geany  1.38
About: Geany is a text editor (using GTK2) with basic features of an integrated development environment (syntax highlighting, code folding, symbol name auto-completion, ...). F: office T: editor programming GTK+ IDE
  Fossies Dox: geany-1.38.tar.bz2  ("unofficial" and yet experimental doxygen-generated source code documentation)  

geanymenubuttonaction.c
Go to the documentation of this file.
1/*
2 * geanymenubuttonaction.c - this file is part of Geany, a fast and lightweight IDE
3 *
4 * Copyright 2009 The Geany contributors
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21/* GtkAction subclass to provide a GtkMenuToolButton in a toolbar.
22 * This class is missing the action_create_menu_item() function and so can't be
23 * used for creating menu items. */
24
25#ifdef HAVE_CONFIG_H
26# include "config.h"
27#endif
28
30
31#include "utils.h"
32
34
35#define GEANY_MENU_BUTTON_ACTION_GET_PRIVATE(obj) (GEANY_MENU_BUTTON_ACTION(obj)->priv)
36
37
39{
40 GtkWidget *menu;
41
43};
44
45enum
46{
49};
50
51enum
52{
55};
56static guint signals[LAST_SIGNAL];
57
58
59G_DEFINE_TYPE(GeanyMenubuttonAction, geany_menu_button_action, GTK_TYPE_ACTION)
60
61
62static void geany_menu_button_action_finalize(GObject *object)
63{
65
66 g_object_unref(priv->menu);
67 g_free(priv->tooltip_arrow);
68
69 (* G_OBJECT_CLASS(geany_menu_button_action_parent_class)->finalize)(object);
70}
71
72
73static void delegate_button_activated(GtkAction *action)
74{
75 g_signal_emit(action, signals[BUTTON_CLICKED], 0);
76}
77
78
79static void geany_menu_button_action_set_property(GObject *object, guint prop_id,
80 const GValue *value, GParamSpec *pspec)
81{
82 switch (prop_id)
83 {
85 {
87 g_free(priv->tooltip_arrow);
88 priv->tooltip_arrow = g_value_dup_string(value);
89 break;
90 }
91 default:
92 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
93 break;
94 }
95}
96
97
98static GtkWidget *geany_menu_button_action_create_tool_item(GtkAction *action)
99{
100 GtkWidget *toolitem;
102
103 toolitem = g_object_new(GTK_TYPE_MENU_TOOL_BUTTON, NULL);
104 gtk_menu_tool_button_set_arrow_tooltip_text(GTK_MENU_TOOL_BUTTON(toolitem), priv->tooltip_arrow);
105
106 return toolitem;
107}
108
109
111{
112 GtkActionClass *action_class = GTK_ACTION_CLASS(klass);
113 GObjectClass *g_object_class = G_OBJECT_CLASS(klass);
114
115 g_object_class->finalize = geany_menu_button_action_finalize;
116 g_object_class->set_property = geany_menu_button_action_set_property;
117
118 action_class->activate = delegate_button_activated;
119 action_class->create_tool_item = geany_menu_button_action_create_tool_item;
120 action_class->toolbar_item_type = GTK_TYPE_MENU_TOOL_BUTTON;
121
122 g_type_class_add_private(klass, sizeof(GeanyMenubuttonActionPrivate));
123
124 g_object_class_install_property(g_object_class,
126 g_param_spec_string(
127 "tooltip-arrow",
128 "Arrow tooltip",
129 "A special tooltip for the arrow button",
130 "",
131 G_PARAM_WRITABLE));
132
133 signals[BUTTON_CLICKED] = g_signal_new("button-clicked",
134 G_TYPE_FROM_CLASS(klass),
135 (GSignalFlags) 0,
136 0,
137 0,
138 NULL,
139 g_cclosure_marshal_VOID__VOID,
140 G_TYPE_NONE, 0);
141}
142
143
145{
147
148 action->priv = G_TYPE_INSTANCE_GET_PRIVATE(action,
150
151 priv = action->priv;
152 priv->tooltip_arrow = NULL;
153 priv->menu = NULL;
154}
155
156
157GtkAction *geany_menu_button_action_new(const gchar *name,
158 const gchar *label,
159 const gchar *tooltip,
160 const gchar *tooltip_arrow,
161 const gchar *stock_id)
162{
163 GtkAction *action = g_object_new(GEANY_MENU_BUTTON_ACTION_TYPE,
164 "name", name,
165 "label", label,
166 "tooltip", tooltip,
167 "tooltip-arrow", tooltip_arrow,
168 "stock-id", stock_id,
169 NULL);
170
171 return action;
172}
173
174
176{
178
179 g_return_val_if_fail(action != NULL, NULL);
180
182
183 return priv->menu;
184}
185
186
187static void menu_items_changed_cb(GtkContainer *container, GtkWidget *widget, GeanyMenubuttonAction *action)
188{
190 gboolean enable;
191 GSList *l;
192
193 g_return_if_fail(action != NULL);
194
196 if (priv->menu != NULL)
197 {
198 GList *children = gtk_container_get_children(GTK_CONTAINER(priv->menu));
199
200 enable = (g_list_length(children) > 0);
201 g_list_free(children);
202 }
203 else
204 enable = FALSE;
205
206 foreach_slist(l, gtk_action_get_proxies(GTK_ACTION(action)))
207 {
208 /* On Windows a GtkImageMenuItem proxy is created for whatever reason. So we filter
209 * by type and act only on GtkMenuToolButton proxies. */
210 /* TODO find why the GtkImageMenuItem proxy is created */
211 if (! GTK_IS_MENU_TOOL_BUTTON(l->data))
212 continue;
213
214 if (enable)
215 {
216 if (gtk_menu_tool_button_get_menu(GTK_MENU_TOOL_BUTTON(l->data)) == NULL)
217 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(l->data), priv->menu);
218 }
219 else
220 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(l->data), NULL);
221 }
222}
223
224
226{
228
229 g_return_if_fail(action != NULL);
230
232
233 if (priv->menu != NULL && GTK_IS_WIDGET(priv->menu))
234 g_signal_handlers_disconnect_by_func(priv->menu, menu_items_changed_cb, action);
235 if (menu != NULL)
236 {
237 g_signal_connect(menu, "add", G_CALLBACK(menu_items_changed_cb), action);
238 g_signal_connect(menu, "remove", G_CALLBACK(menu_items_changed_cb), action);
239 }
240
241 priv->menu = menu;
242
243 menu_items_changed_cb(GTK_CONTAINER(menu), NULL, action);
244}
const gchar * label
Definition: build.c:2676
const gchar * name
Definition: document.c:3219
static void geany_menu_button_action_finalize(GObject *object)
GtkAction * geany_menu_button_action_new(const gchar *name, const gchar *label, const gchar *tooltip, const gchar *tooltip_arrow, const gchar *stock_id)
static guint signals[LAST_SIGNAL]
static void geany_menu_button_action_init(GeanyMenubuttonAction *action)
static GtkWidget * geany_menu_button_action_create_tool_item(GtkAction *action)
@ LAST_SIGNAL
@ BUTTON_CLICKED
static void menu_items_changed_cb(GtkContainer *container, GtkWidget *widget, GeanyMenubuttonAction *action)
#define GEANY_MENU_BUTTON_ACTION_GET_PRIVATE(obj)
static void geany_menu_button_action_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
GtkWidget * geany_menu_button_action_get_menu(GeanyMenubuttonAction *action)
static void geany_menu_button_action_class_init(GeanyMenubuttonActionClass *klass)
void geany_menu_button_action_set_menu(GeanyMenubuttonAction *action, GtkWidget *menu)
@ PROP_TOOLTIP_ARROW
static void delegate_button_activated(GtkAction *action)
#define GEANY_MENU_BUTTON_ACTION_TYPE
static GeanyProjectPrivate priv
Definition: project.c:56
#define NULL
Definition: rbtree.h:150
struct _GeanyMenubuttonActionPrivate * priv
General utility functions, non-GTK related.
#define foreach_slist(node, list)
Iterates all the nodes in list.
Definition: utils.h:121