File: | cut-n-paste/toolbar-editor/egg-toolbar-editor.c |
Warning: | line 618, column 3 Value stored to 'y' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* |
2 | * Copyright (C) 2003 Marco Pesenti Gritti |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by |
6 | * the Free Software Foundation; either version 2, or (at your option) |
7 | * any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the Free Software |
16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | * |
18 | * $Id: egg-toolbar-editor.c 929 2009-02-19 14:49:56Z friemann $ |
19 | */ |
20 | |
21 | #include "config.h" |
22 | |
23 | #include "egg-toolbar-editor.h" |
24 | #include "egg-editable-toolbar.h" |
25 | |
26 | #include <string.h> |
27 | #include <libxml/tree.h> |
28 | #include <ctk/ctk.h> |
29 | #include <glib/gi18n.h> |
30 | |
31 | static const CtkTargetEntry dest_drag_types[] = { |
32 | {EGG_TOOLBAR_ITEM_TYPE"application/x-toolbar-item", CTK_TARGET_SAME_APP, 0}, |
33 | }; |
34 | |
35 | static const CtkTargetEntry source_drag_types[] = { |
36 | {EGG_TOOLBAR_ITEM_TYPE"application/x-toolbar-item", CTK_TARGET_SAME_APP, 0}, |
37 | }; |
38 | |
39 | |
40 | static void egg_toolbar_editor_finalize (GObject *object); |
41 | static void update_editor_sheet (EggToolbarEditor *editor); |
42 | |
43 | enum |
44 | { |
45 | PROP_0, |
46 | PROP_UI_MANAGER, |
47 | PROP_TOOLBARS_MODEL |
48 | }; |
49 | |
50 | enum |
51 | { |
52 | SIGNAL_HANDLER_ITEM_ADDED, |
53 | SIGNAL_HANDLER_ITEM_REMOVED, |
54 | SIGNAL_HANDLER_TOOLBAR_REMOVED, |
55 | SIGNAL_HANDLER_LIST_SIZE /* Array size */ |
56 | }; |
57 | |
58 | struct EggToolbarEditorPrivate |
59 | { |
60 | CtkUIManager *manager; |
61 | EggToolbarsModel *model; |
62 | |
63 | CtkWidget *grid; |
64 | CtkWidget *scrolled_window; |
65 | GList *actions_list; |
66 | GList *factory_list; |
67 | |
68 | /* These handlers need to be sanely disconnected when switching models */ |
69 | gulong sig_handlers[SIGNAL_HANDLER_LIST_SIZE]; |
70 | }; |
71 | |
72 | G_DEFINE_TYPE_WITH_PRIVATE (EggToolbarEditor, egg_toolbar_editor, CTK_TYPE_BOX)static void egg_toolbar_editor_init (EggToolbarEditor *self); static void egg_toolbar_editor_class_init (EggToolbarEditorClass *klass); static GType egg_toolbar_editor_get_type_once (void ); static gpointer egg_toolbar_editor_parent_class = ((void*) 0); static gint EggToolbarEditor_private_offset; static void egg_toolbar_editor_class_intern_init (gpointer klass) { egg_toolbar_editor_parent_class = g_type_class_peek_parent (klass); if (EggToolbarEditor_private_offset != 0) g_type_class_adjust_private_offset (klass, &EggToolbarEditor_private_offset); egg_toolbar_editor_class_init ((EggToolbarEditorClass*) klass); } __attribute__ ((__unused__ )) static inline gpointer egg_toolbar_editor_get_instance_private (EggToolbarEditor *self) { return (((gpointer) ((guint8*) (self ) + (glong) (EggToolbarEditor_private_offset)))); } GType egg_toolbar_editor_get_type (void) { static GType static_g_define_type_id = 0; if ((__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer), "Expression evaluates to false"); (void) ( 0 ? (gpointer) * (&static_g_define_type_id) : ((void*)0)) ; (!(__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id ) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (*(&static_g_define_type_id)) gapg_temp_newval; __typeof__ ((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id ); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5) ; gapg_temp_newval; })) && g_once_init_enter_pointer ( &static_g_define_type_id)); })) ) { GType g_define_type_id = egg_toolbar_editor_get_type_once (); (__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer) , "Expression evaluates to false"); 0 ? (void) (*(&static_g_define_type_id ) = (g_define_type_id)) : (void) 0; g_once_init_leave_pointer ((&static_g_define_type_id), (gpointer) (guintptr) (g_define_type_id )); })) ; } return static_g_define_type_id; } __attribute__ ( (__noinline__)) static GType egg_toolbar_editor_get_type_once (void) { GType g_define_type_id = g_type_register_static_simple ((ctk_box_get_type ()), g_intern_static_string ("EggToolbarEditor" ), sizeof (EggToolbarEditorClass), (GClassInitFunc)(void (*)( void)) egg_toolbar_editor_class_intern_init, sizeof (EggToolbarEditor ), (GInstanceInitFunc)(void (*)(void)) egg_toolbar_editor_init , (GTypeFlags) 0); { {{ EggToolbarEditor_private_offset = g_type_add_instance_private (g_define_type_id, sizeof (EggToolbarEditorPrivate)); };} } return g_define_type_id; } |
73 | |
74 | static gint |
75 | compare_items (gconstpointer a, |
76 | gconstpointer b) |
77 | { |
78 | const CtkWidget *item1 = a; |
79 | const CtkWidget *item2 = b; |
80 | |
81 | char *key1 = g_object_get_data (G_OBJECT (item1)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((item1)), (((GType) ((20) << (2)))))))), |
82 | "egg-collate-key"); |
83 | char *key2 = g_object_get_data (G_OBJECT (item2)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((item2)), (((GType) ((20) << (2)))))))), |
84 | "egg-collate-key"); |
85 | |
86 | return strcmp (key1, key2); |
87 | } |
88 | |
89 | static CtkAction * |
90 | find_action (EggToolbarEditor *t, |
91 | const char *name) |
92 | { |
93 | GList *l; |
94 | CtkAction *action = NULL((void*)0); |
95 | |
96 | l = ctk_ui_manager_get_action_groups (t->priv->manager); |
97 | |
98 | g_return_val_if_fail (EGG_IS_TOOLBAR_EDITOR (t), NULL)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((t)); GType __t = ((egg_toolbar_editor_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char* ) (__func__)), "EGG_IS_TOOLBAR_EDITOR (t)"); return (((void*) 0)); } } while (0); |
99 | g_return_val_if_fail (name != NULL, NULL)do { if ((name != ((void*)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "name != NULL"); return (((void*)0)); } } while (0); |
100 | |
101 | for (; l != NULL((void*)0); l = l->next) |
102 | { |
103 | CtkAction *tmp; |
104 | |
105 | tmp = ctk_action_group_get_action (CTK_ACTION_GROUP (l->data)((((CtkActionGroup*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((l->data)), ((ctk_action_group_get_type ())))))), name); |
106 | if (tmp) |
107 | action = tmp; |
108 | } |
109 | |
110 | return action; |
111 | } |
112 | |
113 | static void |
114 | egg_toolbar_editor_set_ui_manager (EggToolbarEditor *t, |
115 | CtkUIManager *manager) |
116 | { |
117 | g_return_if_fail (CTK_IS_UI_MANAGER (manager))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((manager)); GType __t = ((ctk_ui_manager_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char* ) (__func__)), "CTK_IS_UI_MANAGER (manager)"); return; } } while (0); |
118 | |
119 | t->priv->manager = g_object_ref (manager)((__typeof__ (manager)) (g_object_ref) (manager)); |
120 | } |
121 | |
122 | static void |
123 | item_added_or_removed_cb (EggToolbarsModel *model, |
124 | int tpos, |
125 | int ipos, |
126 | EggToolbarEditor *editor) |
127 | { |
128 | update_editor_sheet (editor); |
129 | } |
130 | |
131 | static void |
132 | toolbar_removed_cb (EggToolbarsModel *model, |
133 | int position, |
134 | EggToolbarEditor *editor) |
135 | { |
136 | update_editor_sheet (editor); |
137 | } |
138 | |
139 | static void |
140 | egg_toolbar_editor_disconnect_model (EggToolbarEditor *t) |
141 | { |
142 | EggToolbarEditorPrivate *priv = t->priv; |
143 | EggToolbarsModel *model = priv->model; |
144 | gulong handler; |
145 | int i; |
146 | |
147 | for (i = 0; i < SIGNAL_HANDLER_LIST_SIZE; i++) |
148 | { |
149 | handler = priv->sig_handlers[i]; |
150 | |
151 | if (handler != 0) |
152 | { |
153 | if (g_signal_handler_is_connected (model, handler)) |
154 | { |
155 | g_signal_handler_disconnect (model, handler); |
156 | } |
157 | |
158 | priv->sig_handlers[i] = 0; |
159 | } |
160 | } |
161 | } |
162 | |
163 | void |
164 | egg_toolbar_editor_set_model (EggToolbarEditor *t, |
165 | EggToolbarsModel *model) |
166 | { |
167 | EggToolbarEditorPrivate *priv; |
168 | |
169 | g_return_if_fail (EGG_IS_TOOLBAR_EDITOR (t))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((t)); GType __t = ((egg_toolbar_editor_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char* ) (__func__)), "EGG_IS_TOOLBAR_EDITOR (t)"); return; } } while (0); |
170 | g_return_if_fail (model != NULL)do { if ((model != ((void*)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "model != NULL"); return; } } while (0); |
171 | |
172 | priv = t->priv; |
173 | |
174 | if (priv->model) |
175 | { |
176 | if (G_UNLIKELY (priv->model == model)(priv->model == model)) return; |
177 | |
178 | egg_toolbar_editor_disconnect_model (t); |
179 | g_object_unref (priv->model); |
180 | } |
181 | |
182 | priv->model = g_object_ref (model)((__typeof__ (model)) (g_object_ref) (model)); |
183 | |
184 | update_editor_sheet (t); |
185 | |
186 | priv->sig_handlers[SIGNAL_HANDLER_ITEM_ADDED] = |
187 | g_signal_connect_object (model, "item_added", |
188 | G_CALLBACK (item_added_or_removed_cb)((GCallback) (item_added_or_removed_cb)), t, 0); |
189 | priv->sig_handlers[SIGNAL_HANDLER_ITEM_REMOVED] = |
190 | g_signal_connect_object (model, "item_removed", |
191 | G_CALLBACK (item_added_or_removed_cb)((GCallback) (item_added_or_removed_cb)), t, 0); |
192 | priv->sig_handlers[SIGNAL_HANDLER_TOOLBAR_REMOVED] = |
193 | g_signal_connect_object (model, "toolbar_removed", |
194 | G_CALLBACK (toolbar_removed_cb)((GCallback) (toolbar_removed_cb)), t, 0); |
195 | } |
196 | |
197 | static void |
198 | egg_toolbar_editor_set_property (GObject *object, |
199 | guint prop_id, |
200 | const GValue *value, |
201 | GParamSpec *pspec) |
202 | { |
203 | EggToolbarEditor *t = EGG_TOOLBAR_EDITOR (object)((((EggToolbarEditor*) (void *) g_type_check_instance_cast (( GTypeInstance*) ((object)), ((egg_toolbar_editor_get_type ()) ))))); |
204 | |
205 | switch (prop_id) |
206 | { |
207 | case PROP_UI_MANAGER: |
208 | egg_toolbar_editor_set_ui_manager (t, g_value_get_object (value)); |
209 | break; |
210 | case PROP_TOOLBARS_MODEL: |
211 | egg_toolbar_editor_set_model (t, g_value_get_object (value)); |
212 | break; |
213 | } |
214 | } |
215 | |
216 | static void |
217 | egg_toolbar_editor_get_property (GObject *object, |
218 | guint prop_id, |
219 | GValue *value, |
220 | GParamSpec *pspec) |
221 | { |
222 | EggToolbarEditor *t = EGG_TOOLBAR_EDITOR (object)((((EggToolbarEditor*) (void *) g_type_check_instance_cast (( GTypeInstance*) ((object)), ((egg_toolbar_editor_get_type ()) ))))); |
223 | |
224 | switch (prop_id) |
225 | { |
226 | case PROP_UI_MANAGER: |
227 | g_value_set_object (value, t->priv->manager); |
228 | break; |
229 | case PROP_TOOLBARS_MODEL: |
230 | g_value_set_object (value, t->priv->model); |
231 | break; |
232 | } |
233 | } |
234 | |
235 | static void |
236 | egg_toolbar_editor_class_init (EggToolbarEditorClass *klass) |
237 | { |
238 | GObjectClass *object_class = G_OBJECT_CLASS (klass)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((klass)), (((GType) ((20) << (2)))))))); |
239 | |
240 | object_class->finalize = egg_toolbar_editor_finalize; |
241 | object_class->set_property = egg_toolbar_editor_set_property; |
242 | object_class->get_property = egg_toolbar_editor_get_property; |
243 | |
244 | g_object_class_install_property (object_class, |
245 | PROP_UI_MANAGER, |
246 | g_param_spec_object ("ui-manager", |
247 | "UI-Manager", |
248 | "UI Manager", |
249 | CTK_TYPE_UI_MANAGER(ctk_ui_manager_get_type ()), |
250 | G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | |
251 | G_PARAM_CONSTRUCT_ONLY)); |
252 | g_object_class_install_property (object_class, |
253 | PROP_TOOLBARS_MODEL, |
254 | g_param_spec_object ("model", |
255 | "Model", |
256 | "Toolbars Model", |
257 | EGG_TYPE_TOOLBARS_MODEL(egg_toolbars_model_get_type ()), |
258 | G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | |
259 | G_PARAM_CONSTRUCT)); |
260 | |
261 | CtkWidgetClass *widget_class = CTK_WIDGET_CLASS (klass)((((CtkWidgetClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((klass)), ((ctk_widget_get_type ())))))); |
262 | ctk_widget_class_set_css_name (widget_class, "EggToolbarEditor"); |
263 | } |
264 | |
265 | static void |
266 | egg_toolbar_editor_finalize (GObject *object) |
267 | { |
268 | EggToolbarEditor *editor = EGG_TOOLBAR_EDITOR (object)((((EggToolbarEditor*) (void *) g_type_check_instance_cast (( GTypeInstance*) ((object)), ((egg_toolbar_editor_get_type ()) ))))); |
269 | |
270 | if (editor->priv->manager) |
271 | { |
272 | g_object_unref (editor->priv->manager); |
273 | } |
274 | |
275 | if (editor->priv->model) |
276 | { |
277 | egg_toolbar_editor_disconnect_model (editor); |
278 | g_object_unref (editor->priv->model); |
279 | } |
280 | |
281 | g_list_free (editor->priv->actions_list); |
282 | g_list_free (editor->priv->factory_list); |
283 | |
284 | G_OBJECT_CLASS (egg_toolbar_editor_parent_class)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((egg_toolbar_editor_parent_class)), (((GType) ((20) << (2))))))))->finalize (object); |
285 | } |
286 | |
287 | CtkWidget * |
288 | egg_toolbar_editor_new (CtkUIManager *manager, |
289 | EggToolbarsModel *model) |
290 | { |
291 | return CTK_WIDGET (g_object_new (EGG_TYPE_TOOLBAR_EDITOR,((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((g_object_new ((egg_toolbar_editor_get_type ()), "ui-manager" , manager, "model", model, ((void*)0)))), ((ctk_widget_get_type ())))))) |
292 | "ui-manager", manager,((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((g_object_new ((egg_toolbar_editor_get_type ()), "ui-manager" , manager, "model", model, ((void*)0)))), ((ctk_widget_get_type ())))))) |
293 | "model", model,((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((g_object_new ((egg_toolbar_editor_get_type ()), "ui-manager" , manager, "model", model, ((void*)0)))), ((ctk_widget_get_type ())))))) |
294 | NULL))((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((g_object_new ((egg_toolbar_editor_get_type ()), "ui-manager" , manager, "model", model, ((void*)0)))), ((ctk_widget_get_type ())))))); |
295 | } |
296 | |
297 | static void |
298 | drag_begin_cb (CtkWidget *widget, |
299 | CdkDragContext *context) |
300 | { |
301 | ctk_widget_hide (widget); |
302 | } |
303 | |
304 | static void |
305 | drag_end_cb (CtkWidget *widget, |
306 | CdkDragContext *context) |
307 | { |
308 | ctk_widget_show (widget); |
309 | } |
310 | |
311 | static void |
312 | drag_data_get_cb (CtkWidget *widget, |
313 | CdkDragContext *context, |
314 | CtkSelectionData *selection_data, |
315 | guint info, |
316 | guint32 time, |
317 | EggToolbarEditor *editor) |
318 | { |
319 | const char *target; |
320 | |
321 | target = g_object_get_data (G_OBJECT (widget)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), (((GType) ((20) << (2)))))))), "egg-item-name"); |
322 | g_return_if_fail (target != NULL)do { if ((target != ((void*)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "target != NULL") ; return; } } while (0); |
323 | |
324 | ctk_selection_data_set (selection_data, ctk_selection_data_get_target (selection_data), 8, |
325 | (const guchar *) target, strlen (target)); |
326 | } |
327 | |
328 | static gchar * |
329 | elide_underscores (const gchar *original) |
330 | { |
331 | gchar *q, *result; |
332 | const gchar *p; |
333 | gboolean last_underscore; |
334 | |
335 | q = result = g_malloc (strlen (original) + 1); |
336 | last_underscore = FALSE(0); |
337 | |
338 | for (p = original; *p; p++) |
339 | { |
340 | if (!last_underscore && *p == '_') |
341 | last_underscore = TRUE(!(0)); |
342 | else |
343 | { |
344 | last_underscore = FALSE(0); |
345 | *q++ = *p; |
346 | } |
347 | } |
348 | |
349 | *q = '\0'; |
350 | |
351 | return result; |
352 | } |
353 | |
354 | static void |
355 | set_drag_cursor (CtkWidget *widget) |
356 | { |
357 | CdkCursor *cursor; |
358 | CdkScreen *screen; |
359 | |
360 | screen = ctk_widget_get_screen (widget); |
361 | |
362 | cursor = cdk_cursor_new_for_display (cdk_screen_get_display (screen), |
363 | CDK_HAND2); |
364 | cdk_window_set_cursor (ctk_widget_get_window (widget), cursor); |
365 | g_object_unref (cursor); |
366 | } |
367 | |
368 | static void |
369 | event_box_realize_cb (CtkWidget *widget, CtkImage *icon) |
370 | { |
371 | CtkImageType type; |
372 | |
373 | set_drag_cursor (widget); |
374 | |
375 | type = ctk_image_get_storage_type (icon); |
376 | if (type == CTK_IMAGE_STOCK) |
377 | { |
378 | gchar *stock_id; |
379 | GdkPixbuf *pixbuf; |
380 | |
381 | ctk_image_get_stock (icon, &stock_id, NULL((void*)0)); |
382 | pixbuf = ctk_widget_render_icon (widget, stock_id, |
383 | CTK_ICON_SIZE_LARGE_TOOLBAR, NULL((void*)0)); |
384 | ctk_drag_source_set_icon_pixbuf (widget, pixbuf); |
385 | g_object_unref (pixbuf); |
386 | } |
387 | else if (type == CTK_IMAGE_ICON_NAME) |
388 | { |
389 | const gchar *icon_name; |
390 | CdkScreen *screen; |
391 | CtkIconTheme *icon_theme; |
392 | gint width, height; |
393 | GdkPixbuf *pixbuf; |
394 | |
395 | ctk_image_get_icon_name (icon, &icon_name, NULL((void*)0)); |
396 | screen = ctk_widget_get_screen (widget); |
397 | icon_theme = ctk_icon_theme_get_for_screen (screen); |
398 | |
399 | if (!ctk_icon_size_lookup (CTK_ICON_SIZE_LARGE_TOOLBAR, |
400 | &width, &height)) |
401 | { |
402 | width = height = 24; |
403 | } |
404 | |
405 | pixbuf = ctk_icon_theme_load_icon (icon_theme, icon_name, |
406 | MIN (width, height)(((width) < (height)) ? (width) : (height)), 0, NULL((void*)0)); |
407 | if (G_UNLIKELY (!pixbuf)(!pixbuf)) |
408 | return; |
409 | |
410 | ctk_drag_source_set_icon_pixbuf (widget, pixbuf); |
411 | g_object_unref (pixbuf); |
412 | |
413 | } |
414 | else if (type == CTK_IMAGE_PIXBUF) |
415 | { |
416 | GdkPixbuf *pixbuf = ctk_image_get_pixbuf (icon); |
417 | ctk_drag_source_set_icon_pixbuf (widget, pixbuf); |
418 | } |
419 | } |
420 | |
421 | static CtkWidget * |
422 | editor_create_item (EggToolbarEditor *editor, |
423 | CtkImage *icon, |
424 | const char *label_text, |
425 | CdkDragAction action) |
426 | { |
427 | CtkWidget *event_box; |
428 | CtkWidget *vbox; |
429 | CtkWidget *label; |
430 | gchar *label_no_mnemonic = NULL((void*)0); |
431 | |
432 | event_box = ctk_event_box_new (); |
433 | ctk_event_box_set_visible_window (CTK_EVENT_BOX (event_box)((((CtkEventBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((event_box)), ((ctk_event_box_get_type ())))))), FALSE(0)); |
434 | ctk_widget_show (event_box); |
435 | ctk_drag_source_set (event_box, |
436 | CDK_BUTTON1_MASK, |
437 | source_drag_types, G_N_ELEMENTS (source_drag_types)(sizeof (source_drag_types) / sizeof ((source_drag_types)[0]) ), action); |
438 | g_signal_connect (event_box, "drag_data_get",g_signal_connect_data ((event_box), ("drag_data_get"), (((GCallback ) (drag_data_get_cb))), (editor), ((void*)0), (GConnectFlags) 0) |
439 | G_CALLBACK (drag_data_get_cb), editor)g_signal_connect_data ((event_box), ("drag_data_get"), (((GCallback ) (drag_data_get_cb))), (editor), ((void*)0), (GConnectFlags) 0); |
440 | g_signal_connect_after (event_box, "realize",g_signal_connect_data ((event_box), ("realize"), (((GCallback ) (event_box_realize_cb))), (icon), ((void*)0), G_CONNECT_AFTER ) |
441 | G_CALLBACK (event_box_realize_cb), icon)g_signal_connect_data ((event_box), ("realize"), (((GCallback ) (event_box_realize_cb))), (icon), ((void*)0), G_CONNECT_AFTER ); |
442 | |
443 | if (action == CDK_ACTION_MOVE) |
444 | { |
445 | g_signal_connect (event_box, "drag_begin",g_signal_connect_data ((event_box), ("drag_begin"), (((GCallback ) (drag_begin_cb))), (((void*)0)), ((void*)0), (GConnectFlags ) 0) |
446 | G_CALLBACK (drag_begin_cb), NULL)g_signal_connect_data ((event_box), ("drag_begin"), (((GCallback ) (drag_begin_cb))), (((void*)0)), ((void*)0), (GConnectFlags ) 0); |
447 | g_signal_connect (event_box, "drag_end",g_signal_connect_data ((event_box), ("drag_end"), (((GCallback ) (drag_end_cb))), (((void*)0)), ((void*)0), (GConnectFlags) 0 ) |
448 | G_CALLBACK (drag_end_cb), NULL)g_signal_connect_data ((event_box), ("drag_end"), (((GCallback ) (drag_end_cb))), (((void*)0)), ((void*)0), (GConnectFlags) 0 ); |
449 | } |
450 | |
451 | vbox = ctk_box_new (CTK_ORIENTATION_VERTICAL, 0); |
452 | ctk_widget_show (vbox); |
453 | ctk_container_add (CTK_CONTAINER (event_box)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((event_box)), ((ctk_container_get_type ())))))), vbox); |
454 | |
455 | ctk_widget_show (CTK_WIDGET (icon)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((icon)), ((ctk_widget_get_type ()))))))); |
456 | ctk_box_pack_start (CTK_BOX (vbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((vbox)), ((ctk_box_get_type ())))))), CTK_WIDGET (icon)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((icon)), ((ctk_widget_get_type ())))))), FALSE(0), TRUE(!(0)), 0); |
457 | label_no_mnemonic = elide_underscores (label_text); |
458 | label = ctk_label_new (label_no_mnemonic); |
459 | g_free (label_no_mnemonic); |
460 | ctk_widget_show (label); |
461 | ctk_box_pack_start (CTK_BOX (vbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((vbox)), ((ctk_box_get_type ())))))), label, FALSE(0), TRUE(!(0)), 0); |
462 | |
463 | return event_box; |
464 | } |
465 | |
466 | static CtkWidget * |
467 | editor_create_item_from_name (EggToolbarEditor *editor, |
468 | const char * name, |
469 | CdkDragAction drag_action) |
470 | { |
471 | CtkWidget *item; |
472 | const char *item_name; |
473 | char *short_label; |
474 | const char *collate_key; |
475 | |
476 | if (strcmp (name, "_separator") == 0) |
477 | { |
478 | CtkWidget *icon; |
479 | |
480 | icon = _egg_editable_toolbar_new_separator_image (); |
481 | short_label = _("Separator")gettext ("Separator"); |
482 | item_name = g_strdup (name)g_strdup_inline (name); |
483 | collate_key = g_utf8_collate_key (short_label, -1); |
484 | item = editor_create_item (editor, CTK_IMAGE (icon)((((CtkImage*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((icon)), ((ctk_image_get_type ())))))), |
485 | short_label, drag_action); |
486 | } |
487 | else |
488 | { |
489 | CtkAction *action; |
490 | CtkWidget *icon; |
491 | char *stock_id, *icon_name = NULL((void*)0); |
492 | |
493 | action = find_action (editor, name); |
494 | g_return_val_if_fail (action != NULL, NULL)do { if ((action != ((void*)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "action != NULL") ; return (((void*)0)); } } while (0); |
495 | |
496 | g_object_get (action, |
497 | "icon-name", &icon_name, |
498 | "stock-id", &stock_id, |
499 | "short-label", &short_label, |
500 | NULL((void*)0)); |
501 | |
502 | /* This is a workaround to catch named icons. */ |
503 | if (icon_name) |
504 | icon = ctk_image_new_from_icon_name (icon_name, |
505 | CTK_ICON_SIZE_LARGE_TOOLBAR); |
506 | else |
507 | icon = ctk_image_new_from_icon_name (stock_id ? stock_id : "ctk-dnd", |
508 | CTK_ICON_SIZE_LARGE_TOOLBAR); |
509 | |
510 | item_name = g_strdup (name)g_strdup_inline (name); |
511 | collate_key = g_utf8_collate_key (short_label, -1); |
512 | item = editor_create_item (editor, CTK_IMAGE (icon)((((CtkImage*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((icon)), ((ctk_image_get_type ())))))), |
513 | short_label, drag_action); |
514 | |
515 | g_free (short_label); |
516 | g_free (stock_id); |
517 | g_free (icon_name); |
518 | } |
519 | |
520 | g_object_set_data_full (G_OBJECT (item)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((item)), (((GType) ((20) << (2)))))))), "egg-collate-key", |
521 | (gpointer) collate_key, g_free); |
522 | g_object_set_data_full (G_OBJECT (item)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((item)), (((GType) ((20) << (2)))))))), "egg-item-name", |
523 | (gpointer) item_name, g_free); |
524 | |
525 | return item; |
526 | } |
527 | |
528 | static gint |
529 | append_grid (CtkGrid *grid, GList *items, gint y, gint width) |
530 | { |
531 | if (items != NULL((void*)0)) |
532 | { |
533 | gint x = 0; |
534 | CtkWidget *item; |
535 | |
536 | if (y > 0) |
537 | { |
538 | item = ctk_separator_new (CTK_ORIENTATION_HORIZONTAL); |
539 | ctk_widget_set_hexpand (item, TRUE(!(0))); |
540 | ctk_widget_set_vexpand (item, FALSE(0)); |
541 | ctk_widget_show (item); |
542 | |
543 | ctk_grid_attach (grid, item, 0, y, width, 1); |
544 | y++; |
545 | } |
546 | |
547 | for (; items != NULL((void*)0); items = items->next) |
548 | { |
549 | item = items->data; |
550 | ctk_widget_set_hexpand (item, FALSE(0)); |
551 | ctk_widget_set_vexpand (item, FALSE(0)); |
552 | ctk_widget_show (item); |
553 | |
554 | if (x >= width) |
555 | { |
556 | x = 0; |
557 | y++; |
558 | } |
559 | ctk_grid_attach (grid, item, x, y, 1, 1); |
560 | x++; |
561 | } |
562 | |
563 | y++; |
564 | } |
565 | return y; |
566 | } |
567 | |
568 | static void |
569 | update_editor_sheet (EggToolbarEditor *editor) |
570 | { |
571 | gint y; |
572 | GPtrArray *items; |
573 | GList *to_move = NULL((void*)0), *to_copy = NULL((void*)0); |
574 | CtkWidget *grid; |
575 | CtkWidget *viewport; |
576 | |
577 | g_return_if_fail (EGG_IS_TOOLBAR_EDITOR (editor))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((editor)); GType __t = ((egg_toolbar_editor_get_type ())) ; gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0) ); else __r = g_type_check_instance_is_a (__inst, __t); __r; } )))))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "EGG_IS_TOOLBAR_EDITOR (editor)"); return ; } } while (0); |
578 | |
579 | /* Create new grid. */ |
580 | grid = ctk_grid_new (); |
581 | editor->priv->grid = grid; |
582 | ctk_container_set_border_width (CTK_CONTAINER (grid)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((grid)), ((ctk_container_get_type ())))))), 12); |
583 | ctk_grid_set_row_spacing (CTK_GRID (grid)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((grid)), ((ctk_grid_get_type ())))))), 24); |
584 | ctk_widget_show (grid); |
585 | ctk_drag_dest_set (grid, CTK_DEST_DEFAULT_ALL, |
586 | dest_drag_types, G_N_ELEMENTS (dest_drag_types)(sizeof (dest_drag_types) / sizeof ((dest_drag_types)[0])), |
587 | CDK_ACTION_MOVE | CDK_ACTION_COPY); |
588 | |
589 | /* Build two lists of items (one for copying, one for moving). */ |
590 | items = egg_toolbars_model_get_name_avail (editor->priv->model); |
591 | while (items->len > 0) |
592 | { |
593 | CtkWidget *item; |
594 | const char *name; |
595 | gint flags; |
596 | |
597 | name = g_ptr_array_index (items, 0)((items)->pdata)[0]; |
598 | g_ptr_array_remove_index_fast (items, 0); |
599 | |
600 | flags = egg_toolbars_model_get_name_flags (editor->priv->model, name); |
601 | if ((flags & EGG_TB_MODEL_NAME_INFINITE) == 0) |
602 | { |
603 | item = editor_create_item_from_name (editor, name, CDK_ACTION_MOVE); |
604 | if (item != NULL((void*)0)) |
605 | to_move = g_list_insert_sorted (to_move, item, compare_items); |
606 | } |
607 | else |
608 | { |
609 | item = editor_create_item_from_name (editor, name, CDK_ACTION_COPY); |
610 | if (item != NULL((void*)0)) |
611 | to_copy = g_list_insert_sorted (to_copy, item, compare_items); |
612 | } |
613 | } |
614 | |
615 | /* Add them to the sheet. */ |
616 | y = 0; |
617 | y = append_grid (CTK_GRID (grid)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((grid)), ((ctk_grid_get_type ())))))), to_move, y, 4); |
618 | y = append_grid (CTK_GRID (grid)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((grid)), ((ctk_grid_get_type ())))))), to_copy, y, 4); |
Value stored to 'y' is never read | |
619 | |
620 | g_list_free (to_move); |
621 | g_list_free (to_copy); |
622 | g_ptr_array_free (items, TRUE(!(0))); |
623 | |
624 | /* Delete old table/grid. */ |
625 | viewport = ctk_bin_get_child (CTK_BIN (editor->priv->scrolled_window)((((CtkBin*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((editor->priv->scrolled_window)), ((ctk_bin_get_type ()))))))); |
626 | if (viewport) |
627 | { |
628 | ctk_container_remove (CTK_CONTAINER (viewport)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((viewport)), ((ctk_container_get_type ())))))), |
629 | ctk_bin_get_child (CTK_BIN (viewport)((((CtkBin*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((viewport)), ((ctk_bin_get_type ())))))))); |
630 | } |
631 | |
632 | /* Add grid to window. */ |
633 | ctk_scrolled_window_add_with_viewport |
634 | (CTK_SCROLLED_WINDOW (editor->priv->scrolled_window)((((CtkScrolledWindow*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((editor->priv->scrolled_window)), ((ctk_scrolled_window_get_type ())))))), grid); |
635 | } |
636 | |
637 | static void |
638 | setup_editor (EggToolbarEditor *editor) |
639 | { |
640 | CtkWidget *scrolled_window; |
641 | |
642 | ctk_orientable_set_orientation (CTK_ORIENTABLE (editor)((((CtkOrientable*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((editor)), ((ctk_orientable_get_type ())))))), |
643 | CTK_ORIENTATION_VERTICAL); |
644 | |
645 | ctk_container_set_border_width (CTK_CONTAINER (editor)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((editor)), ((ctk_container_get_type ())))))), 12); |
646 | scrolled_window = ctk_scrolled_window_new (NULL((void*)0), NULL((void*)0)); |
647 | editor->priv->scrolled_window = scrolled_window; |
648 | ctk_widget_show (scrolled_window); |
649 | ctk_scrolled_window_set_policy (CTK_SCROLLED_WINDOW (scrolled_window)((((CtkScrolledWindow*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((scrolled_window)), ((ctk_scrolled_window_get_type ())))))), |
650 | CTK_POLICY_AUTOMATIC, CTK_POLICY_AUTOMATIC); |
651 | ctk_box_pack_start (CTK_BOX (editor)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((editor)), ((ctk_box_get_type ())))))), scrolled_window, TRUE(!(0)), TRUE(!(0)), 0); |
652 | } |
653 | |
654 | static void |
655 | egg_toolbar_editor_init (EggToolbarEditor *t) |
656 | { |
657 | t->priv = egg_toolbar_editor_get_instance_private (t); |
658 | |
659 | t->priv->manager = NULL((void*)0); |
660 | t->priv->actions_list = NULL((void*)0); |
661 | |
662 | setup_editor (t); |
663 | } |
664 |