1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
/*
 * CAFE panel drawer module.
 * (C) 1997 The Free Software Foundation
 *
 * Authors: Miguel de Icaza
 *          Federico Mena
 *          George Lebl
 */


#include <config.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <string.h>

#include <glib/gi18n.h>
#include <ctk/ctk.h>
#include <cdk/cdkkeysyms.h>
#include <gio/gio.h>

#include "drawer.h"
#include "drawer-private.h"

#include "applet.h"
#include "button-widget.h"
#include "panel-config-global.h"
#include "panel-profile.h"
#include "panel-util.h"
#include "panel-globals.h"
#include "panel-lockdown.h"
#include "panel-icon-names.h"
#include "panel-schemas.h"


/* Internal functions */
/* event handlers */


static void
drawer_click (CtkWidget *widget,
              Drawer    *drawer)
{
    if (!panel_toplevel_get_is_hidden (drawer->toplevel))
        panel_toplevel_hide (drawer->toplevel, FALSE, -1);
    else
        panel_toplevel_unhide (drawer->toplevel);
}

static void
drawer_focus_panel_widget (Drawer           *drawer,
                           CtkDirectionType  direction)
{
    PanelWidget *panel_widget;

    panel_widget = panel_toplevel_get_panel_widget (drawer->toplevel);

    ctk_window_present (CTK_WINDOW (drawer->toplevel));
    ctk_container_set_focus_child (CTK_CONTAINER (panel_widget), NULL);
    ctk_widget_child_focus (CTK_WIDGET (panel_widget), direction);
}

static gboolean
key_press_drawer (CtkWidget   *widget,
                  CdkEventKey *event,<--- Parameter 'event' can be declared as pointer to const
                  Drawer      *drawer)
{
    gboolean retval = TRUE;
    CtkOrientation orient;

    if (event->state & ctk_accelerator_get_default_mod_mask ())
        return FALSE;

    orient = PANEL_WIDGET (ctk_widget_get_parent (drawer->button))->orient;

    switch (event->keyval) {
    case CDK_KEY_Up:
    case CDK_KEY_KP_Up:
        if (orient == CTK_ORIENTATION_HORIZONTAL) {
            if (!panel_toplevel_get_is_hidden (drawer->toplevel))
                drawer_focus_panel_widget (drawer, CTK_DIR_TAB_BACKWARD);
        } else {
            /* let default focus movement happen */
            retval = FALSE;
        }
        break;
    case CDK_KEY_Left:
    case CDK_KEY_KP_Left:
        if (orient == CTK_ORIENTATION_VERTICAL) {
            if (!panel_toplevel_get_is_hidden (drawer->toplevel))
                drawer_focus_panel_widget (drawer, CTK_DIR_TAB_BACKWARD);
        } else {
            /* let default focus movement happen */
            retval = FALSE;
        }
        break;
    case CDK_KEY_Down:
    case CDK_KEY_KP_Down:
        if (orient == CTK_ORIENTATION_HORIZONTAL) {
            if (!panel_toplevel_get_is_hidden (drawer->toplevel))
                drawer_focus_panel_widget (drawer, CTK_DIR_TAB_FORWARD);
        } else {
            /* let default focus movement happen */
            retval = FALSE;
        }
        break;
    case CDK_KEY_Right:
    case CDK_KEY_KP_Right:
        if (orient == CTK_ORIENTATION_VERTICAL) {
            if (!panel_toplevel_get_is_hidden (drawer->toplevel))
                drawer_focus_panel_widget (drawer, CTK_DIR_TAB_FORWARD);
        } else {
            /* let default focus movement happen */
            retval = FALSE;
        }
        break;
    case CDK_KEY_Escape:
        panel_toplevel_hide (drawer->toplevel, FALSE, -1);
        break;
    default:
        retval = FALSE;
        break;
    }

    return retval;
}

/*
 * This function implements Esc moving focus from the drawer to the drawer
 * icon and closing the drawer and Shift+Esc moving focus from the drawer
 * to the drawer icon without closing the drawer when focus is in the drawer.
 */
static gboolean
key_press_drawer_widget (CtkWidget   *widget,
                         CdkEventKey *event,<--- Parameter 'event' can be declared as pointer to const
                         Drawer      *drawer)
{
    PanelWidget *panel_widget;

    if (event->keyval != CDK_KEY_Escape)
        return FALSE;

    panel_widget = panel_toplevel_get_panel_widget (drawer->toplevel);

    ctk_window_present (CTK_WINDOW (panel_widget->toplevel));

    if ((event->state & ctk_accelerator_get_default_mod_mask ()) == CDK_SHIFT_MASK ||
        panel_toplevel_get_is_hidden (drawer->toplevel))
            return TRUE;

    panel_toplevel_hide (drawer->toplevel, FALSE, -1);

    return TRUE;
}

    /* drag and drop handlers */

static void
drag_data_get_cb (CtkWidget          *widget,
                  CdkDragContext     *context,
                  CtkSelectionData   *selection_data,
                  guint               info,
                  guint               time,
                  Drawer             *drawer)
{
    char *foo;

    foo = g_strdup_printf ("DRAWER:%d", panel_find_applet_index (widget));

    ctk_selection_data_set (selection_data, ctk_selection_data_get_target (selection_data), 8, (guchar *) foo, strlen (foo));

    g_free (foo);
}

static gboolean
drag_motion_cb (CtkWidget          *widget,
                CdkDragContext     *context,
                int                 x,
                int                 y,
                guint               time_,
                Drawer             *drawer)
{
    PanelWidget *panel_widget;
    guint        info = 0;

    if (!panel_check_dnd_target_data (widget, context, &info, NULL))
        return FALSE;

    panel_widget = panel_toplevel_get_panel_widget (drawer->toplevel);

    if (!panel_check_drop_forbidden (panel_widget, context, info, time_))
        return FALSE;

    if (drawer->close_timeout_id)
        g_source_remove (drawer->close_timeout_id);

    drawer->close_timeout_id = 0;

    button_widget_set_dnd_highlight (BUTTON_WIDGET (widget), TRUE);

    if (panel_toplevel_get_is_hidden (drawer->toplevel)) {
        panel_toplevel_unhide (drawer->toplevel);
        drawer->opened_for_drag = TRUE;
    }

    return TRUE;
}

static gboolean
drag_drop_cb (CtkWidget      *widget,
              CdkDragContext *context,
              int             x,
              int             y,
              guint           time_,
              Drawer         *drawer)
{
    CdkAtom atom = NULL;

    if (!panel_check_dnd_target_data (widget, context, NULL, &atom))
        return FALSE;

    ctk_drag_get_data (widget, context, atom, time_);

    return TRUE;
}

static void
drag_data_received_cb (CtkWidget          *widget,
                       CdkDragContext     *context,
                       gint                x,
                       gint                y,
                       CtkSelectionData   *selection_data,
                       guint               info,
                       guint               time_,
                       Drawer             *drawer)
{
    PanelWidget *panel_widget;

    if (!panel_check_dnd_target_data (widget, context, &info, NULL)) {
        ctk_drag_finish (context, FALSE, FALSE, time_);
        return;
    }

    panel_widget = panel_toplevel_get_panel_widget (drawer->toplevel);

    panel_receive_dnd_data (panel_widget, info, -1, selection_data, context, time_);
}

static gboolean
close_drawer_in_idle (gpointer data)
{
    Drawer *drawer = (Drawer *) data;

    drawer->close_timeout_id = 0;

    if (drawer->opened_for_drag) {
        panel_toplevel_hide (drawer->toplevel, FALSE, -1);
        drawer->opened_for_drag = FALSE;
    }

    return FALSE;
}

static void
queue_drawer_close_for_drag (Drawer *drawer)
{
    if (!drawer->close_timeout_id)
        drawer->close_timeout_id = g_timeout_add_seconds (1, close_drawer_in_idle, drawer);
}

static void
drag_leave_cb (CtkWidget      *widget,
               CdkDragContext *context,
               guint           time_,
               Drawer         *drawer)
{
    queue_drawer_close_for_drag (drawer);

    button_widget_set_dnd_highlight (BUTTON_WIDGET (widget), FALSE);
}

    /* load_drawer_applet handlers */

static void
drawer_button_size_allocated (CtkWidget     *widget,
                              CtkAllocation *alloc,
                              Drawer        *drawer)
{
    if (!ctk_widget_get_realized (widget))
        return;

    ctk_widget_queue_resize (CTK_WIDGET (drawer->toplevel));

    g_object_set_data (G_OBJECT (widget), "allocated", GINT_TO_POINTER (TRUE));
}

static gboolean
drawer_changes_enabled (void)
{
    return !panel_lockdown_get_locked_down ();
}

    /* gsettings handlers */

static void
panel_drawer_custom_icon_changed (GSettings *settings,
                                  gchar     *key,
                                  Drawer    *drawer)
{
    g_return_if_fail (drawer != NULL);
    g_return_if_fail (drawer->button != NULL);

    gboolean use_custom_icon = g_settings_get_boolean (settings, PANEL_OBJECT_USE_CUSTOM_ICON_KEY);
    char *custom_icon = g_settings_get_string (settings, PANEL_OBJECT_CUSTOM_ICON_KEY);

    if (use_custom_icon && custom_icon != NULL && custom_icon [0] != '\0') {
        button_widget_set_icon_name (BUTTON_WIDGET (drawer->button), custom_icon);
    } else {
        button_widget_set_icon_name (BUTTON_WIDGET (drawer->button), PANEL_ICON_DRAWER);
    }

    g_free (custom_icon);
}

static void
panel_drawer_tooltip_changed (GSettings *settings,
                              gchar     *key,
                              Drawer    *drawer)
{
    gchar *tooltip = g_settings_get_string (settings, key);
    set_tooltip_and_name (drawer, tooltip);
    g_free (tooltip);
}

    /* destroy handlers */

static void
toplevel_destroyed (CtkWidget *widget,
                    Drawer    *drawer)
{
    drawer->toplevel = NULL;

    if (drawer->button) {
        ctk_widget_destroy (drawer->button);
        drawer->button = NULL;
    }
}

static void
destroy_drawer (CtkWidget *widget,
                Drawer    *drawer)
{
    if (drawer->toplevel) {
        ctk_widget_destroy (CTK_WIDGET (drawer->toplevel));
        drawer->toplevel = NULL;
    }

    if (drawer->close_timeout_id) {
        g_source_remove (drawer->close_timeout_id);
        drawer->close_timeout_id = 0;
    }
}

static void
drawer_deletion_response (CtkWidget   *dialog,
                          int          response,
                          Drawer      *drawer)
{
    if (response == CTK_RESPONSE_OK)
        panel_profile_delete_object (drawer->info);

    ctk_widget_destroy (dialog);
}

/* end event handlers */

static PanelToplevel *
create_drawer_toplevel (const char *drawer_id,
                        GSettings  *settings)
{
    PanelToplevel *toplevel;
    char          *toplevel_id;

    toplevel_id = panel_profile_find_new_id (PANEL_GSETTINGS_TOPLEVELS);
    toplevel = panel_profile_load_toplevel (toplevel_id);

    if (!toplevel) {
        g_free (toplevel_id);
        return NULL;
    }

    g_settings_set_string (settings, PANEL_OBJECT_ATTACHED_TOPLEVEL_ID_KEY, toplevel_id);
    g_free (toplevel_id);

    panel_profile_set_toplevel_enable_buttons (toplevel, TRUE);
    panel_profile_set_toplevel_enable_arrows (toplevel, TRUE);

    return toplevel;
}

static void
set_tooltip_and_name (Drawer     *drawer,
                      const char *tooltip)
{
    g_return_if_fail (drawer != NULL);
    g_return_if_fail (drawer->toplevel != NULL);

    if (tooltip != NULL && tooltip [0] != '\0') {
        panel_toplevel_set_name (drawer->toplevel, tooltip);
        panel_util_set_tooltip_text (drawer->button, tooltip);
    }
}

static Drawer *
create_drawer_applet (PanelToplevel    *toplevel,
                      PanelToplevel    *parent_toplevel,
                      const char       *tooltip,
                      const char       *custom_icon,
                      gboolean          use_custom_icon,
                      PanelOrientation  orientation)
{
    Drawer *drawer;
    AtkObject *atk_obj;

    drawer = g_new0 (Drawer, 1);

    drawer->toplevel = toplevel;

    if (!use_custom_icon || !custom_icon || !custom_icon [0]) {
        drawer->button = button_widget_new (PANEL_ICON_DRAWER, TRUE, orientation);
    } else {
        drawer->button = button_widget_new (custom_icon, TRUE, orientation);
    }

    if (!drawer->button) {
        g_free (drawer);
        return NULL;
    }

    atk_obj = ctk_widget_get_accessible (drawer->button);
    atk_object_set_name (atk_obj, _("Drawer"));

    set_tooltip_and_name (drawer, tooltip);

    g_signal_connect (drawer->button, "clicked", G_CALLBACK (drawer_click), drawer);
    g_signal_connect (drawer->button, "key_press_event", G_CALLBACK (key_press_drawer), drawer);<--- You might need to cast the function pointer here
    g_signal_connect (drawer->toplevel, "key_press_event", G_CALLBACK (key_press_drawer_widget), drawer);<--- You might need to cast the function pointer here


    ctk_drag_dest_set (drawer->button, 0, NULL, 0, 0);

    g_signal_connect (drawer->button, "drag_data_get", G_CALLBACK (drag_data_get_cb), drawer);
    g_signal_connect (drawer->button, "drag_motion", G_CALLBACK (drag_motion_cb), drawer);
    g_signal_connect (drawer->button, "drag_drop", G_CALLBACK (drag_drop_cb), drawer);
    g_signal_connect (drawer->button, "drag_data_received", G_CALLBACK (drag_data_received_cb), drawer);
    g_signal_connect (drawer->button, "drag_leave", G_CALLBACK (drag_leave_cb), drawer);


    g_signal_connect (drawer->button, "destroy", G_CALLBACK (destroy_drawer), drawer);
    g_signal_connect (drawer->toplevel, "destroy", G_CALLBACK (toplevel_destroyed), drawer);

    ctk_widget_show (drawer->button);

    panel_toplevel_attach_to_widget (drawer->toplevel, parent_toplevel, CTK_WIDGET (drawer->button));

    return drawer;
}

static void
panel_drawer_connect_to_gsettings (Drawer *drawer)
{
    g_signal_connect (drawer->info->settings,
                      "changed::" PANEL_OBJECT_USE_CUSTOM_ICON_KEY,
                      G_CALLBACK (panel_drawer_custom_icon_changed),
                      drawer);

    g_signal_connect (drawer->info->settings,
                      "changed::" PANEL_OBJECT_CUSTOM_ICON_KEY,
                      G_CALLBACK (panel_drawer_custom_icon_changed),
                      drawer);

    g_signal_connect (drawer->info->settings,
                      "changed::" PANEL_OBJECT_TOOLTIP_KEY,
                      G_CALLBACK (panel_drawer_tooltip_changed),
                      drawer);
}

static void
load_drawer_applet (char          *toplevel_id,<--- Parameter 'toplevel_id' can be declared as pointer to const
                    GSettings     *settings,
                    const char    *custom_icon,
                    gboolean       use_custom_icon,
                    const char    *tooltip,
                    PanelToplevel *parent_toplevel,
                    gboolean       locked,
                    int            pos,
                    gboolean       exactpos,
                    const char    *id)
{
    PanelOrientation  orientation;
    PanelToplevel    *toplevel = NULL;
    Drawer           *drawer = NULL;
    PanelWidget      *panel_widget;

    orientation = panel_toplevel_get_orientation (parent_toplevel);

    if (toplevel_id)
        toplevel = panel_profile_get_toplevel_by_id (toplevel_id);

    if (!toplevel)
        toplevel = create_drawer_toplevel (id, settings);

    if (toplevel) {
        panel_toplevel_hide (toplevel, FALSE, -1);
        drawer = create_drawer_applet (toplevel,
                                       parent_toplevel,
                                       tooltip,
                                       custom_icon,
                                       use_custom_icon,
                                       orientation);
    }

    if (!drawer)
        return;

    panel_widget = panel_toplevel_get_panel_widget (parent_toplevel);

    drawer->info = cafe_panel_applet_register (drawer->button, drawer,
                                          (GDestroyNotify) g_free,
                                          panel_widget,
                                          locked, pos, exactpos,
                                          PANEL_OBJECT_DRAWER, id);

    if (!drawer->info) {
        ctk_widget_destroy (CTK_WIDGET (toplevel));
        return;
    }

    g_signal_connect_after (drawer->button, "size_allocate", G_CALLBACK (drawer_button_size_allocated), drawer);

    panel_widget_add_forbidden (panel_toplevel_get_panel_widget (drawer->toplevel));
    panel_widget_set_applet_expandable (panel_widget, CTK_WIDGET (drawer->button), FALSE, TRUE);
    panel_widget_set_applet_size_constrained (panel_widget, CTK_WIDGET (drawer->button), TRUE);

    cafe_panel_applet_add_callback (drawer->info,
                               "add",
                               "list-add",
                               _("_Add to Drawer..."),
                               drawer_changes_enabled);

    cafe_panel_applet_add_callback (drawer->info,
                               "properties",
                               "document-properties",
                               _("_Properties"),
                               drawer_changes_enabled);

    cafe_panel_applet_add_callback (drawer->info,
                               "help",
                               "help-browser",
                               _("_Help"),
                               NULL);

    panel_drawer_connect_to_gsettings (drawer);
}

static void
panel_drawer_prepare (const char  *drawer_id,
                      GIcon       *custom_icon,
                      gboolean     use_custom_icon,
                      const char  *tooltip,
                      char       **attached_toplevel_id)
{
    GSettings *settings;
    char *path;

    path = g_strdup_printf ("%s%s/", PANEL_OBJECT_PATH, drawer_id);
    settings = g_settings_new_with_path (PANEL_OBJECT_SCHEMA, path);
    g_free (path);

    if (tooltip) {
        g_settings_set_string (settings, PANEL_OBJECT_TOOLTIP_KEY, tooltip);
    }

    g_settings_set_boolean (settings, PANEL_OBJECT_USE_CUSTOM_ICON_KEY, use_custom_icon);

    if (custom_icon) {
	gchar *icon_name;
	icon_name = g_icon_to_string(custom_icon);
	g_settings_set_string (settings, PANEL_OBJECT_CUSTOM_ICON_KEY, icon_name);
	g_free(icon_name);
    }

    if (attached_toplevel_id) {
        char *toplevel_id;
        char *toplevel_path;
        GSettings *toplevel_settings;

        toplevel_id = panel_profile_find_new_id (PANEL_GSETTINGS_TOPLEVELS);

        toplevel_path = g_strdup_printf (PANEL_TOPLEVEL_PATH "%s/", toplevel_id);

        toplevel_settings = g_settings_new_with_path (PANEL_TOPLEVEL_SCHEMA, toplevel_path);

        g_settings_set_string (settings, PANEL_OBJECT_ATTACHED_TOPLEVEL_ID_KEY, toplevel_id);
        g_settings_set_boolean (toplevel_settings, PANEL_TOPLEVEL_ENABLE_BUTTONS_KEY, TRUE);
        g_settings_set_boolean (toplevel_settings, PANEL_TOPLEVEL_ENABLE_ARROWS_KEY, TRUE);

        *attached_toplevel_id = toplevel_id;

        g_object_unref (toplevel_settings);
        g_free (toplevel_path);
    }
    g_object_unref (settings);
}

/* API */

void
panel_drawer_create (PanelToplevel *toplevel,
                     int            position,
                     GIcon         *custom_icon,
                     gboolean       use_custom_icon,
                     const char    *tooltip)
{
    char *id;

    id = panel_profile_prepare_object (PANEL_OBJECT_DRAWER, toplevel, position, FALSE);

    panel_drawer_prepare (id, custom_icon, use_custom_icon, tooltip, NULL);

    panel_profile_add_to_list (PANEL_GSETTINGS_OBJECTS, id);

    g_free (id);
}

char *
panel_drawer_create_with_id (const char    *toplevel_id,
                             int            position,
                             GIcon         *custom_icon,
                             gboolean       use_custom_icon,
                             const char    *tooltip)
{
    char *id;
    char *attached_toplevel_id = NULL;

    id = panel_profile_prepare_object_with_id (PANEL_OBJECT_DRAWER, toplevel_id, position, FALSE);

    panel_drawer_prepare (id, custom_icon, use_custom_icon, tooltip, &attached_toplevel_id);

    panel_profile_add_to_list (PANEL_GSETTINGS_OBJECTS, id);

    g_free (id);

    return attached_toplevel_id;
}

void
drawer_load_from_gsettings (PanelWidget *panel_widget,
                            gboolean     locked,
                            gint         position,
                            const char  *id)
{
    gboolean     use_custom_icon;
    char        *toplevel_id;
    char        *custom_icon;
    char        *tooltip;
    gchar       *path;
    GSettings   *settings;

    g_return_if_fail (panel_widget != NULL);
    g_return_if_fail (id != NULL);

    path = g_strdup_printf ("%s%s/", PANEL_OBJECT_PATH, id);
    settings = g_settings_new_with_path (PANEL_OBJECT_SCHEMA, path);
    g_free (path);

    toplevel_id = g_settings_get_string (settings, PANEL_OBJECT_ATTACHED_TOPLEVEL_ID_KEY);

    panel_profile_load_toplevel (toplevel_id);

    use_custom_icon = g_settings_get_boolean (settings, PANEL_OBJECT_USE_CUSTOM_ICON_KEY);
    custom_icon = g_settings_get_string (settings, PANEL_OBJECT_CUSTOM_ICON_KEY);

    tooltip = g_settings_get_string (settings, PANEL_OBJECT_TOOLTIP_KEY);

    load_drawer_applet (toplevel_id,
                        settings,
                        custom_icon,
                        use_custom_icon,
                        tooltip,
                        panel_widget->toplevel,
                        locked,
                        position,
                        TRUE,
                        id);

    g_free (toplevel_id);
    g_free (custom_icon);
    g_free (tooltip);
}

void
panel_drawer_set_dnd_enabled (Drawer   *drawer,
                              gboolean  dnd_enabled)
{
    if (dnd_enabled) {
        static CtkTargetEntry dnd_targets[] = {
            { "application/x-cafe-panel-applet-internal", 0, 0 }
        };

        ctk_widget_set_has_window (drawer->button, TRUE);
        ctk_drag_source_set (drawer->button,
                             CDK_BUTTON1_MASK,
                             dnd_targets, 1,
                             CDK_ACTION_MOVE);
        //FIXME: we're forgetting the use_custom_icon case, here
        ctk_drag_source_set_icon_name (drawer->button, button_widget_get_icon_name (BUTTON_WIDGET (drawer->button)));

        ctk_widget_set_has_window (drawer->button, FALSE);

    } else
        ctk_drag_source_unset (drawer->button);
}

void
drawer_query_deletion (Drawer *drawer)
{
    CtkWidget *dialog;

     if (drawer->toplevel) {
        PanelWidget *panel_widget;

        panel_widget = panel_toplevel_get_panel_widget (drawer->toplevel);

        if (!panel_global_config_get_confirm_panel_remove () ||
            !g_list_length (panel_widget->applet_list)) {
                panel_profile_delete_object (drawer->info);
                return;
        }

        dialog = panel_deletion_dialog (drawer->toplevel);

        g_signal_connect (dialog, "response", G_CALLBACK (drawer_deletion_response), drawer);

        g_signal_connect_object (drawer->toplevel, "destroy", G_CALLBACK (ctk_widget_destroy), dialog, G_CONNECT_SWAPPED);

        ctk_widget_show_all (dialog);
    }
}