| File: | cut-n-paste/toolbar-editor/egg-toolbar-editor.c |
| Warning: | line 619, 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 Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * $Id$ |
| 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, |
| 325 | ctk_selection_data_get_target (selection_data), 8, |
| 326 | (const guchar *) target, strlen (target)); |
| 327 | } |
| 328 | |
| 329 | static gchar * |
| 330 | elide_underscores (const gchar *original) |
| 331 | { |
| 332 | gchar *q, *result; |
| 333 | const gchar *p; |
| 334 | gboolean last_underscore; |
| 335 | |
| 336 | q = result = g_malloc (strlen (original) + 1); |
| 337 | last_underscore = FALSE(0); |
| 338 | |
| 339 | for (p = original; *p; p++) |
| 340 | { |
| 341 | if (!last_underscore && *p == '_') |
| 342 | last_underscore = TRUE(!(0)); |
| 343 | else |
| 344 | { |
| 345 | last_underscore = FALSE(0); |
| 346 | *q++ = *p; |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | *q = '\0'; |
| 351 | |
| 352 | return result; |
| 353 | } |
| 354 | |
| 355 | static void |
| 356 | set_drag_cursor (CtkWidget *widget) |
| 357 | { |
| 358 | CdkCursor *cursor; |
| 359 | CdkScreen *screen; |
| 360 | |
| 361 | screen = ctk_widget_get_screen (widget); |
| 362 | |
| 363 | cursor = cdk_cursor_new_for_display (cdk_screen_get_display (screen), |
| 364 | CDK_HAND2); |
| 365 | cdk_window_set_cursor (ctk_widget_get_window (widget), cursor); |
| 366 | g_object_unref (cursor); |
| 367 | } |
| 368 | |
| 369 | static void |
| 370 | event_box_realize_cb (CtkWidget *widget, CtkImage *icon) |
| 371 | { |
| 372 | CtkImageType type; |
| 373 | |
| 374 | set_drag_cursor (widget); |
| 375 | |
| 376 | type = ctk_image_get_storage_type (icon); |
| 377 | if (type == CTK_IMAGE_STOCK) |
| 378 | { |
| 379 | gchar *stock_id; |
| 380 | GdkPixbuf *pixbuf; |
| 381 | |
| 382 | ctk_image_get_stock (icon, &stock_id, NULL((void*)0)); |
| 383 | pixbuf = ctk_widget_render_icon_pixbuf (widget, stock_id, |
| 384 | CTK_ICON_SIZE_LARGE_TOOLBAR); |
| 385 | ctk_drag_source_set_icon_pixbuf (widget, pixbuf); |
| 386 | g_object_unref (pixbuf); |
| 387 | } |
| 388 | else if (type == CTK_IMAGE_ICON_NAME) |
| 389 | { |
| 390 | const gchar *icon_name; |
| 391 | CdkScreen *screen; |
| 392 | CtkIconTheme *icon_theme; |
| 393 | gint width, height; |
| 394 | GdkPixbuf *pixbuf; |
| 395 | |
| 396 | ctk_image_get_icon_name (icon, &icon_name, NULL((void*)0)); |
| 397 | screen = ctk_widget_get_screen (widget); |
| 398 | icon_theme = ctk_icon_theme_get_for_screen (screen); |
| 399 | |
| 400 | if (!ctk_icon_size_lookup (CTK_ICON_SIZE_LARGE_TOOLBAR, |
| 401 | &width, &height)) |
| 402 | { |
| 403 | width = height = 24; |
| 404 | } |
| 405 | |
| 406 | pixbuf = ctk_icon_theme_load_icon (icon_theme, icon_name, |
| 407 | MIN (width, height)(((width) < (height)) ? (width) : (height)), 0, NULL((void*)0)); |
| 408 | if (G_UNLIKELY (!pixbuf)(!pixbuf)) |
| 409 | return; |
| 410 | |
| 411 | ctk_drag_source_set_icon_pixbuf (widget, pixbuf); |
| 412 | g_object_unref (pixbuf); |
| 413 | |
| 414 | } |
| 415 | else if (type == CTK_IMAGE_PIXBUF) |
| 416 | { |
| 417 | GdkPixbuf *pixbuf = ctk_image_get_pixbuf (icon); |
| 418 | ctk_drag_source_set_icon_pixbuf (widget, pixbuf); |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | static CtkWidget * |
| 423 | editor_create_item (EggToolbarEditor *editor, |
| 424 | CtkImage *icon, |
| 425 | const char *label_text, |
| 426 | CdkDragAction action) |
| 427 | { |
| 428 | CtkWidget *event_box; |
| 429 | CtkWidget *vbox; |
| 430 | CtkWidget *label; |
| 431 | gchar *label_no_mnemonic = NULL((void*)0); |
| 432 | |
| 433 | event_box = ctk_event_box_new (); |
| 434 | 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)); |
| 435 | ctk_widget_show (event_box); |
| 436 | ctk_drag_source_set (event_box, |
| 437 | CDK_BUTTON1_MASK, |
| 438 | source_drag_types, G_N_ELEMENTS (source_drag_types)(sizeof (source_drag_types) / sizeof ((source_drag_types)[0]) ), action); |
| 439 | 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) |
| 440 | 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); |
| 441 | 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 ) |
| 442 | 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 ); |
| 443 | |
| 444 | if (action == CDK_ACTION_MOVE) |
| 445 | { |
| 446 | 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) |
| 447 | G_CALLBACK (drag_begin_cb), NULL)g_signal_connect_data ((event_box), ("drag_begin"), (((GCallback ) (drag_begin_cb))), (((void*)0)), ((void*)0), (GConnectFlags ) 0); |
| 448 | 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 ) |
| 449 | G_CALLBACK (drag_end_cb), NULL)g_signal_connect_data ((event_box), ("drag_end"), (((GCallback ) (drag_end_cb))), (((void*)0)), ((void*)0), (GConnectFlags) 0 ); |
| 450 | } |
| 451 | |
| 452 | vbox = ctk_box_new (CTK_ORIENTATION_VERTICAL, 0); |
| 453 | ctk_widget_show (vbox); |
| 454 | ctk_container_add (CTK_CONTAINER (event_box)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((event_box)), ((ctk_container_get_type ())))))), vbox); |
| 455 | |
| 456 | ctk_widget_show (CTK_WIDGET (icon)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((icon)), ((ctk_widget_get_type ()))))))); |
| 457 | 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); |
| 458 | label_no_mnemonic = elide_underscores (label_text); |
| 459 | label = ctk_label_new (label_no_mnemonic); |
| 460 | g_free (label_no_mnemonic); |
| 461 | ctk_widget_show (label); |
| 462 | 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); |
| 463 | |
| 464 | return event_box; |
| 465 | } |
| 466 | |
| 467 | static CtkWidget * |
| 468 | editor_create_item_from_name (EggToolbarEditor *editor, |
| 469 | const char * name, |
| 470 | CdkDragAction drag_action) |
| 471 | { |
| 472 | CtkWidget *item; |
| 473 | const char *item_name; |
| 474 | char *short_label; |
| 475 | const char *collate_key; |
| 476 | |
| 477 | if (strcmp (name, "_separator") == 0) |
| 478 | { |
| 479 | CtkWidget *icon; |
| 480 | |
| 481 | icon = _egg_editable_toolbar_new_separator_image (); |
| 482 | short_label = _("Separator")gettext ("Separator"); |
| 483 | item_name = g_strdup (name)g_strdup_inline (name); |
| 484 | collate_key = g_utf8_collate_key (short_label, -1); |
| 485 | item = editor_create_item (editor, CTK_IMAGE (icon)((((CtkImage*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((icon)), ((ctk_image_get_type ())))))), |
| 486 | short_label, drag_action); |
| 487 | } |
| 488 | else |
| 489 | { |
| 490 | CtkAction *action; |
| 491 | CtkWidget *icon; |
| 492 | char *stock_id, *icon_name = NULL((void*)0); |
| 493 | |
| 494 | action = find_action (editor, name); |
| 495 | 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); |
| 496 | |
| 497 | g_object_get (action, |
| 498 | "icon-name", &icon_name, |
| 499 | "stock-id", &stock_id, |
| 500 | "short-label", &short_label, |
| 501 | NULL((void*)0)); |
| 502 | |
| 503 | /* This is a workaround to catch named icons. */ |
| 504 | if (icon_name) |
| 505 | icon = ctk_image_new_from_icon_name (icon_name, |
| 506 | CTK_ICON_SIZE_LARGE_TOOLBAR); |
| 507 | else |
| 508 | icon = ctk_image_new_from_icon_name (stock_id ? stock_id : "ctk-dnd", |
| 509 | CTK_ICON_SIZE_LARGE_TOOLBAR); |
| 510 | |
| 511 | item_name = g_strdup (name)g_strdup_inline (name); |
| 512 | collate_key = g_utf8_collate_key (short_label, -1); |
| 513 | item = editor_create_item (editor, CTK_IMAGE (icon)((((CtkImage*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((icon)), ((ctk_image_get_type ())))))), |
| 514 | short_label, drag_action); |
| 515 | |
| 516 | g_free (short_label); |
| 517 | g_free (stock_id); |
| 518 | g_free (icon_name); |
| 519 | } |
| 520 | |
| 521 | g_object_set_data_full (G_OBJECT (item)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((item)), (((GType) ((20) << (2)))))))), "egg-collate-key", |
| 522 | (gpointer) collate_key, g_free); |
| 523 | g_object_set_data_full (G_OBJECT (item)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((item)), (((GType) ((20) << (2)))))))), "egg-item-name", |
| 524 | (gpointer) item_name, g_free); |
| 525 | |
| 526 | return item; |
| 527 | } |
| 528 | |
| 529 | static gint |
| 530 | append_grid (CtkGrid *grid, GList *items, gint y, gint width) |
| 531 | { |
| 532 | if (items != NULL((void*)0)) |
| 533 | { |
| 534 | gint x = 0; |
| 535 | CtkWidget *item; |
| 536 | |
| 537 | if (y > 0) |
| 538 | { |
| 539 | item = ctk_separator_new (CTK_ORIENTATION_HORIZONTAL); |
| 540 | ctk_widget_set_hexpand (item, TRUE(!(0))); |
| 541 | ctk_widget_set_vexpand (item, FALSE(0)); |
| 542 | ctk_widget_show (item); |
| 543 | |
| 544 | ctk_grid_attach (grid, item, 0, y, width, 1); |
| 545 | y++; |
| 546 | } |
| 547 | |
| 548 | for (; items != NULL((void*)0); items = items->next) |
| 549 | { |
| 550 | item = items->data; |
| 551 | ctk_widget_set_hexpand (item, FALSE(0)); |
| 552 | ctk_widget_set_vexpand (item, FALSE(0)); |
| 553 | ctk_widget_show (item); |
| 554 | |
| 555 | if (x >= width) |
| 556 | { |
| 557 | x = 0; |
| 558 | y++; |
| 559 | } |
| 560 | ctk_grid_attach (grid, item, x, y, 1, 1); |
| 561 | x++; |
| 562 | } |
| 563 | |
| 564 | y++; |
| 565 | } |
| 566 | return y; |
| 567 | } |
| 568 | |
| 569 | static void |
| 570 | update_editor_sheet (EggToolbarEditor *editor) |
| 571 | { |
| 572 | gint y; |
| 573 | GPtrArray *items; |
| 574 | GList *to_move = NULL((void*)0), *to_copy = NULL((void*)0); |
| 575 | CtkWidget *grid; |
| 576 | CtkWidget *viewport; |
| 577 | |
| 578 | 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); |
| 579 | |
| 580 | /* Create new grid. */ |
| 581 | grid = ctk_grid_new (); |
| 582 | editor->priv->grid = grid; |
| 583 | ctk_container_set_border_width (CTK_CONTAINER (grid)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((grid)), ((ctk_container_get_type ())))))), 12); |
| 584 | ctk_grid_set_row_spacing (CTK_GRID (grid)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((grid)), ((ctk_grid_get_type ())))))), 24); |
| 585 | ctk_widget_show (grid); |
| 586 | ctk_drag_dest_set (grid, CTK_DEST_DEFAULT_ALL, |
| 587 | dest_drag_types, G_N_ELEMENTS (dest_drag_types)(sizeof (dest_drag_types) / sizeof ((dest_drag_types)[0])), |
| 588 | CDK_ACTION_MOVE | CDK_ACTION_COPY); |
| 589 | |
| 590 | /* Build two lists of items (one for copying, one for moving). */ |
| 591 | items = egg_toolbars_model_get_name_avail (editor->priv->model); |
| 592 | while (items->len > 0) |
| 593 | { |
| 594 | CtkWidget *item; |
| 595 | const char *name; |
| 596 | gint flags; |
| 597 | |
| 598 | name = g_ptr_array_index (items, 0)((items)->pdata)[0]; |
| 599 | g_ptr_array_remove_index_fast (items, 0); |
| 600 | |
| 601 | flags = egg_toolbars_model_get_name_flags (editor->priv->model, name); |
| 602 | if ((flags & EGG_TB_MODEL_NAME_INFINITE) == 0) |
| 603 | { |
| 604 | item = editor_create_item_from_name (editor, name, CDK_ACTION_MOVE); |
| 605 | if (item != NULL((void*)0)) |
| 606 | to_move = g_list_insert_sorted (to_move, item, compare_items); |
| 607 | } |
| 608 | else |
| 609 | { |
| 610 | item = editor_create_item_from_name (editor, name, CDK_ACTION_COPY); |
| 611 | if (item != NULL((void*)0)) |
| 612 | to_copy = g_list_insert_sorted (to_copy, item, compare_items); |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | /* Add them to the sheet. */ |
| 617 | y = 0; |
| 618 | y = append_grid (CTK_GRID (grid)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((grid)), ((ctk_grid_get_type ())))))), to_move, y, 4); |
| 619 | 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 | |
| 620 | |
| 621 | g_list_free (to_move); |
| 622 | g_list_free (to_copy); |
| 623 | g_ptr_array_free (items, TRUE(!(0))); |
| 624 | |
| 625 | /* Delete old grid. */ |
| 626 | 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 ()))))))); |
| 627 | if (viewport) |
| 628 | { |
| 629 | ctk_container_remove (CTK_CONTAINER (viewport)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((viewport)), ((ctk_container_get_type ())))))), |
| 630 | ctk_bin_get_child (CTK_BIN (viewport)((((CtkBin*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((viewport)), ((ctk_bin_get_type ())))))))); |
| 631 | } |
| 632 | |
| 633 | /* Add grid to window. */ |
| 634 | ctk_scrolled_window_add_with_viewport |
| 635 | (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); |
| 636 | } |
| 637 | |
| 638 | static void |
| 639 | setup_editor (EggToolbarEditor *editor) |
| 640 | { |
| 641 | CtkWidget *scrolled_window; |
| 642 | |
| 643 | ctk_container_set_border_width (CTK_CONTAINER (editor)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((editor)), ((ctk_container_get_type ())))))), 12); |
| 644 | scrolled_window = ctk_scrolled_window_new (NULL((void*)0), NULL((void*)0)); |
| 645 | editor->priv->scrolled_window = scrolled_window; |
| 646 | ctk_widget_show (scrolled_window); |
| 647 | 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 ())))))), |
| 648 | CTK_POLICY_NEVER, CTK_POLICY_AUTOMATIC); |
| 649 | 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); |
| 650 | } |
| 651 | |
| 652 | static void |
| 653 | egg_toolbar_editor_init (EggToolbarEditor *t) |
| 654 | { |
| 655 | ctk_orientable_set_orientation (CTK_ORIENTABLE (t)((((CtkOrientable*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((t)), ((ctk_orientable_get_type ())))))), CTK_ORIENTATION_VERTICAL); |
| 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 |