gdl-dock.c 44.8 KB
Newer Older
1
2
3
4
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 
 *
 * This file is part of the GNOME Devtools Libraries.
 *
5
 * Copyright (C) 2002 Gustavo Giráldez <gustavo.giraldez@gmx.net>
6
7
 *               2007 Naba Kumar  <naba@gnome.org>
 * 
8
9
10
11
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
17
 *
18
19
20
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21
 */
22

23
24
25
26
27
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "gdl-i18n.h"
28
29
30
#include <stdlib.h>
#include <string.h>

31
32
#include "gdl-tools.h"
#include "gdl-dock.h"
33
#include "gdl-dock-master.h"
34
35
#include "gdl-dock-paned.h"
#include "gdl-dock-notebook.h"
36
#include "gdl-dock-placeholder.h"
37

38
39
#include "libgdlmarshal.h"

Naba Kumar's avatar
Naba Kumar committed
40
41
42
#ifndef __FUNCTION__
#define __FUNCTION__ __func__
#endif
43
44

/* ----- Private prototypes ----- */
45
46

static void  gdl_dock_class_init      (GdlDockClass *class);
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
static void  gdl_dock_instance_init   (GdlDock *dock);

static GObject *gdl_dock_constructor  (GType                  type,
                                       guint                  n_construct_properties,
                                       GObjectConstructParam *construct_param);
static void  gdl_dock_set_property    (GObject      *object,
                                       guint         prop_id,
                                       const GValue *value,
                                       GParamSpec   *pspec);
static void  gdl_dock_get_property    (GObject      *object,
                                       guint         prop_id,
                                       GValue       *value,
                                       GParamSpec   *pspec);
static void  gdl_dock_notify_cb       (GObject      *object,
                                       GParamSpec   *pspec,
                                       gpointer      user_data);

static void  gdl_dock_set_title       (GdlDock      *dock);

static void  gdl_dock_destroy         (GtkObject    *object);
67
68
69

static void  gdl_dock_size_request    (GtkWidget      *widget,
                                       GtkRequisition *requisition);
70
71
72
73
74
75
76
static void  gdl_dock_size_allocate   (GtkWidget      *widget,
                                       GtkAllocation  *allocation);
static void  gdl_dock_map             (GtkWidget      *widget);
static void  gdl_dock_unmap           (GtkWidget      *widget);
static void  gdl_dock_show            (GtkWidget      *widget);
static void  gdl_dock_hide            (GtkWidget      *widget);

77
78
79
80
81
82
83
84
static void  gdl_dock_add             (GtkContainer *container,
                                       GtkWidget    *widget);
static void  gdl_dock_remove          (GtkContainer *container,
                                       GtkWidget    *widget);
static void  gdl_dock_forall          (GtkContainer *container,
                                       gboolean      include_internals,
                                       GtkCallback   callback,
                                       gpointer      callback_data);
85
static GType  gdl_dock_child_type   (GtkContainer *container);
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

static void     gdl_dock_detach       (GdlDockObject    *object,
                                       gboolean          recursive);
static void     gdl_dock_reduce       (GdlDockObject    *object);
static gboolean gdl_dock_dock_request (GdlDockObject    *object,
                                       gint              x,
                                       gint              y,
                                       GdlDockRequest   *request);
static void     gdl_dock_dock         (GdlDockObject    *object,
                                       GdlDockObject    *requestor,
                                       GdlDockPlacement  position,
                                       GValue           *other_data);
static gboolean gdl_dock_reorder      (GdlDockObject    *object,
                                       GdlDockObject    *requestor,
                                       GdlDockPlacement  new_position,
                                       GValue           *other_data);

static gboolean gdl_dock_floating_window_delete_event_cb (GtkWidget *widget);

static gboolean gdl_dock_child_placement  (GdlDockObject    *object,
                                           GdlDockObject    *child,
                                           GdlDockPlacement *placement);

static void     gdl_dock_present          (GdlDockObject    *object,
                                           GdlDockObject    *child);


/* ----- Class variables and definitions ----- */

struct _GdlDockPrivate
{
    /* for floating docks */
    gboolean            floating;
    GtkWidget          *window;
    gboolean            auto_title;
    
    gint                float_x;
    gint                float_y;
    gint                width;
    gint                height;
126

127
128
129
    /* auxiliary fields */
    GdkGC              *xor_gc;
};
130
131
132
133
134
135

enum {
    LAYOUT_CHANGED,
    LAST_SIGNAL
};

136
137
138
139
140
141
142
143
144
enum {
    PROP_0,
    PROP_FLOATING,
    PROP_DEFAULT_TITLE,
    PROP_WIDTH,
    PROP_HEIGHT,
    PROP_FLOAT_X,
    PROP_FLOAT_Y
};
145
146
147
148
149

static guint dock_signals [LAST_SIGNAL] = { 0 };

#define SPLIT_RATIO  0.3

150
151
152

/* ----- Private functions ----- */

153
GDL_CLASS_BOILERPLATE (GdlDock, gdl_dock, GdlDockObject, GDL_TYPE_DOCK_OBJECT);
154
155
156
157

static void
gdl_dock_class_init (GdlDockClass *klass)
{
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
    GObjectClass       *g_object_class;
    GtkObjectClass     *gtk_object_class;
    GtkWidgetClass     *widget_class;
    GtkContainerClass  *container_class;
    GdlDockObjectClass *object_class;
    
    g_object_class = G_OBJECT_CLASS (klass);
    gtk_object_class = GTK_OBJECT_CLASS (klass);
    widget_class = GTK_WIDGET_CLASS (klass);
    container_class = GTK_CONTAINER_CLASS (klass);
    object_class = GDL_DOCK_OBJECT_CLASS (klass);
    
    g_object_class->constructor = gdl_dock_constructor;
    g_object_class->set_property = gdl_dock_set_property;
    g_object_class->get_property = gdl_dock_get_property;
    
    /* properties */

    g_object_class_install_property (
        g_object_class, PROP_FLOATING,
        g_param_spec_boolean ("floating", _("Floating"),
                              _("Whether the dock is floating in its own window"),
                              FALSE,
                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
                              GDL_DOCK_PARAM_EXPORT));
    
    g_object_class_install_property (
        g_object_class, PROP_DEFAULT_TITLE,
186
        g_param_spec_string ("default-title", _("Default title"),
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
                             _("Default title for the newly created floating docks"),
                             NULL,
                             G_PARAM_READWRITE));
    
    g_object_class_install_property (
        g_object_class, PROP_WIDTH,
        g_param_spec_int ("width", _("Width"),
                          _("Width for the dock when it's of floating type"),
                          -1, G_MAXINT, -1,
                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
                          GDL_DOCK_PARAM_EXPORT));
    
    g_object_class_install_property (
        g_object_class, PROP_HEIGHT,
        g_param_spec_int ("height", _("Height"),
                          _("Height for the dock when it's of floating type"),
                          -1, G_MAXINT, -1,
                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
                          GDL_DOCK_PARAM_EXPORT));
    
    g_object_class_install_property (
        g_object_class, PROP_FLOAT_X,
        g_param_spec_int ("floatx", _("Float X"),
                          _("X coordinate for a floating dock"),
                          G_MININT, G_MAXINT, 0,
                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
                          GDL_DOCK_PARAM_EXPORT));
    
    g_object_class_install_property (
        g_object_class, PROP_FLOAT_Y,
        g_param_spec_int ("floaty", _("Float Y"),
                          _("Y coordinate for a floating dock"),
                          G_MININT, G_MAXINT, 0,
                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
                          GDL_DOCK_PARAM_EXPORT));
    
    gtk_object_class->destroy = gdl_dock_destroy;
224
225
226
227
228

    widget_class->size_request = gdl_dock_size_request;
    widget_class->size_allocate = gdl_dock_size_allocate;
    widget_class->map = gdl_dock_map;
    widget_class->unmap = gdl_dock_unmap;
229
230
231
    widget_class->show = gdl_dock_show;
    widget_class->hide = gdl_dock_hide;
    
232
233
234
    container_class->add = gdl_dock_add;
    container_class->remove = gdl_dock_remove;
    container_class->forall = gdl_dock_forall;
235
236
237
238
239
240
241
242
243
244
245
246
247
    container_class->child_type = gdl_dock_child_type;
    
    object_class->is_compound = TRUE;
    
    object_class->detach = gdl_dock_detach;
    object_class->reduce = gdl_dock_reduce;
    object_class->dock_request = gdl_dock_dock_request;
    object_class->dock = gdl_dock_dock;
    object_class->reorder = gdl_dock_reorder;    
    object_class->child_placement = gdl_dock_child_placement;
    object_class->present = gdl_dock_present;
    
    /* signals */
248

249
    dock_signals [LAYOUT_CHANGED] = 
250
        g_signal_new ("layout-changed", 
251
252
253
254
255
256
257
258
                      G_TYPE_FROM_CLASS (klass),
                      G_SIGNAL_RUN_LAST,
                      G_STRUCT_OFFSET (GdlDockClass, layout_changed),
                      NULL, /* accumulator */
                      NULL, /* accu_data */
                      gdl_marshal_VOID__VOID,
                      G_TYPE_NONE, /* return type */
                      0);
259
260

    klass->layout_changed = NULL;
261
262
263
}

static void
264
gdl_dock_instance_init (GdlDock *dock)
265
{
266
    gtk_widget_set_has_window (GTK_WIDGET (dock), FALSE);
267
268

    dock->root = NULL;
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
    dock->_priv = g_new0 (GdlDockPrivate, 1);
    dock->_priv->width = -1;
    dock->_priv->height = -1;
}

static gboolean 
gdl_dock_floating_configure_event_cb (GtkWidget         *widget,
                                      GdkEventConfigure *event,
                                      gpointer           user_data)
{
    GdlDock *dock;
    
    g_return_val_if_fail (user_data != NULL && GDL_IS_DOCK (user_data), TRUE);

    dock = GDL_DOCK (user_data);
    dock->_priv->float_x = event->x;
    dock->_priv->float_y = event->y;
    dock->_priv->width = event->width;
    dock->_priv->height = event->height;

    return FALSE;
}

static GObject *
gdl_dock_constructor (GType                  type,
                      guint                  n_construct_properties,
                      GObjectConstructParam *construct_param)
{
    GObject *g_object;
    
299
    g_object = GDL_CALL_PARENT_WITH_DEFAULT (G_OBJECT_CLASS, 
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
                                               constructor, 
                                               (type,
                                                n_construct_properties,
                                                construct_param),
                                               NULL);
    if (g_object) {
        GdlDock *dock = GDL_DOCK (g_object);
        GdlDockMaster *master;
        
        /* create a master for the dock if none was provided in the construction */
        master = GDL_DOCK_OBJECT_GET_MASTER (GDL_DOCK_OBJECT (dock));
        if (!master) {
            GDL_DOCK_OBJECT_UNSET_FLAGS (dock, GDL_DOCK_AUTOMATIC);
            master = g_object_new (GDL_TYPE_DOCK_MASTER, NULL);
            /* the controller owns the master ref */
            gdl_dock_object_bind (GDL_DOCK_OBJECT (dock), G_OBJECT (master));
        }

        if (dock->_priv->floating) {
            GdlDockObject *controller;
            
            /* create floating window for this dock */
            dock->_priv->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
            g_object_set_data (G_OBJECT (dock->_priv->window), "dock", dock);
            
            /* set position and default size */
            gtk_window_set_position (GTK_WINDOW (dock->_priv->window),
                                     GTK_WIN_POS_MOUSE);
            gtk_window_set_default_size (GTK_WINDOW (dock->_priv->window),
                                         dock->_priv->width,
                                         dock->_priv->height);
            gtk_window_set_type_hint (GTK_WINDOW (dock->_priv->window),
                                      GDK_WINDOW_TYPE_HINT_NORMAL);
            
            /* metacity ignores this */
            gtk_window_move (GTK_WINDOW (dock->_priv->window),
                             dock->_priv->float_x,
                             dock->_priv->float_y);
            
            /* connect to the configure event so we can track down window geometry */
            g_signal_connect (dock->_priv->window, "configure_event",
                              (GCallback) gdl_dock_floating_configure_event_cb,
                              dock);
            
            /* set the title and connect to the long_name notify queue
               so we can reset the title when this prop changes */
            gdl_dock_set_title (dock);
347
            g_signal_connect (dock, "notify::long-name",
348
349
350
351
352
353
354
355
356
357
358
359
                              (GCallback) gdl_dock_notify_cb, NULL);
            
            gtk_container_add (GTK_CONTAINER (dock->_priv->window), GTK_WIDGET (dock));
    
            g_signal_connect (dock->_priv->window, "delete_event",
                              G_CALLBACK (gdl_dock_floating_window_delete_event_cb), 
                              NULL);
        }
        GDL_DOCK_OBJECT_SET_FLAGS (dock, GDL_DOCK_ATTACHED);
    }
    
    return g_object;
360
361
362
}

static void
363
364
365
366
gdl_dock_set_property  (GObject      *object,
                        guint         prop_id,
                        const GValue *value,
                        GParamSpec   *pspec)
367
368
{
    GdlDock *dock = GDL_DOCK (object);
369
370
371
372
373
374
375
376
    
    switch (prop_id) {
        case PROP_FLOATING:
            dock->_priv->floating = g_value_get_boolean (value);
            break;
        case PROP_DEFAULT_TITLE:
            if (GDL_DOCK_OBJECT (object)->master)
                g_object_set (GDL_DOCK_OBJECT (object)->master,
377
                              "default-title", g_value_get_string (value),
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
                              NULL);
            break;
        case PROP_WIDTH:
            dock->_priv->width = g_value_get_int (value);
            break;
        case PROP_HEIGHT:
            dock->_priv->height = g_value_get_int (value);
            break;
        case PROP_FLOAT_X:
            dock->_priv->float_x = g_value_get_int (value);
            break;
        case PROP_FLOAT_Y:
            dock->_priv->float_y = g_value_get_int (value);
            break;
        default:
            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
            break;
    }
396

397
398
399
400
401
402
403
404
405
406
407
    switch (prop_id) {
        case PROP_WIDTH:
        case PROP_HEIGHT:
        case PROP_FLOAT_X:
        case PROP_FLOAT_Y:
            if (dock->_priv->floating && dock->_priv->window) {
                gtk_window_resize (GTK_WINDOW (dock->_priv->window),
                                   dock->_priv->width,
                                   dock->_priv->height);
            }
            break;
408
    }
409
410
411
412
413
414
415
416
417
}

static void
gdl_dock_get_property  (GObject      *object,
                        guint         prop_id,
                        GValue       *value,
                        GParamSpec   *pspec)
{
    GdlDock *dock = GDL_DOCK (object);
418

419
420
421
422
423
424
425
426
    switch (prop_id) {
        case PROP_FLOATING:
            g_value_set_boolean (value, dock->_priv->floating);
            break;
        case PROP_DEFAULT_TITLE:
            if (GDL_DOCK_OBJECT (object)->master) {
                gchar *default_title;
                g_object_get (GDL_DOCK_OBJECT (object)->master,
427
                              "default-title", &default_title,
428
                              NULL);
429
#if GLIB_CHECK_VERSION(2,3,0)
430
                g_value_take_string (value, default_title);
431
432
433
#else
                g_value_set_string_take_ownership (value, default_title);
#endif
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
            }
            else
                g_value_set_string (value, NULL);
            break;
        case PROP_WIDTH:
            g_value_set_int (value, dock->_priv->width);
            break;
        case PROP_HEIGHT:
            g_value_set_int (value, dock->_priv->height);
            break;
        case PROP_FLOAT_X:
            g_value_set_int (value, dock->_priv->float_x);
            break;
        case PROP_FLOAT_Y:
            g_value_set_int (value, dock->_priv->float_y);
            break;
        default:
            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
            break;
453
    }
454
}
455

456
457
458
459
460
461
462
463
static void
gdl_dock_set_title (GdlDock *dock)
{
    GdlDockObject *object = GDL_DOCK_OBJECT (dock);
    gchar         *title = NULL;
    
    if (!dock->_priv->window)
        return;
464
    
465
466
467
468
    if (!dock->_priv->auto_title && object->long_name) {
        title = object->long_name;
    }
    else if (object->master) {
469
        g_object_get (object->master, "default-title", &title, NULL);
470
471
    }

472
    if (!title && dock->root) {
473
        g_object_get (dock->root, "long-name", &title, NULL);
474
    }
475
476
477
478
    
    if (!title) {
        /* set a default title in the long_name */
        dock->_priv->auto_title = TRUE;
479
        title = g_strdup_printf (
480
481
482
483
            _("Dock #%d"), GDL_DOCK_MASTER (object->master)->dock_number++);
    }

    gtk_window_set_title (GTK_WINDOW (dock->_priv->window), title);
484
485

    g_free (title);
486
487
488
489
490
491
492
493
}

static void
gdl_dock_notify_cb (GObject    *object,
                    GParamSpec *pspec,
                    gpointer    user_data)
{
    GdlDock *dock;
494
    gchar* long_name;
495
496
    
    g_return_if_fail (object != NULL || GDL_IS_DOCK (object));
497
498
499
500
501
502
503
504
505
506

    g_object_get (object, "long-name", &long_name, NULL);

    if (long_name)
    {
        dock = GDL_DOCK (object);
        dock->_priv->auto_title = FALSE;
        gdl_dock_set_title (dock);
    }
    g_free (long_name);
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
}

static void
gdl_dock_destroy (GtkObject *object)
{
    GdlDock *dock = GDL_DOCK (object);

    if (dock->_priv) {
        GdlDockPrivate *priv = dock->_priv;
        dock->_priv = NULL;

        if (priv->window) {
            gtk_widget_destroy (priv->window);
            priv->floating = FALSE;
            priv->window = NULL;
        }
        
        /* destroy the xor gc */
        if (priv->xor_gc) {
            g_object_unref (priv->xor_gc);
            priv->xor_gc = NULL;
        }

        g_free (priv);
    }
    
533
    GDL_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
534
535
536
537
538
539
}

static void
gdl_dock_size_request (GtkWidget      *widget,
                       GtkRequisition *requisition)
{
540
541
542
    GdlDock       *dock;
    GtkContainer  *container;
    guint          border_width;
543
544
545
546
547
548

    g_return_if_fail (widget != NULL);
    g_return_if_fail (GDL_IS_DOCK (widget));

    dock = GDL_DOCK (widget);
    container = GTK_CONTAINER (widget);
549
    border_width = gtk_container_get_border_width (container);
550
551

    /* make request to root */
552
    if (dock->root && gtk_widget_get_visible (GTK_WIDGET (dock->root)))
553
        gtk_widget_size_request (GTK_WIDGET (dock->root), requisition);
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
    else {
        requisition->width = 0;
        requisition->height = 0;
    };

    requisition->width += 2 * border_width;
    requisition->height += 2 * border_width;

    widget->requisition = *requisition;
}

static void
gdl_dock_size_allocate (GtkWidget     *widget,
                        GtkAllocation *allocation)
{
569
570
571
    GdlDock       *dock;
    GtkContainer  *container;
    guint          border_width;
572
573
574
575
576
577

    g_return_if_fail (widget != NULL);
    g_return_if_fail (GDL_IS_DOCK (widget));
    
    dock = GDL_DOCK (widget);
    container = GTK_CONTAINER (widget);
578
    border_width = gtk_container_get_border_width (container);
579

580
    gtk_widget_set_allocation (widget, allocation);
581
582
583
584
585
586
587

    /* reduce allocation by border width */
    allocation->x += border_width;
    allocation->y += border_width;
    allocation->width = MAX (1, allocation->width - 2 * border_width);
    allocation->height = MAX (1, allocation->height - 2 * border_width);

588
    if (dock->root && gtk_widget_get_visible (GTK_WIDGET (dock->root)))
589
        gtk_widget_size_allocate (GTK_WIDGET (dock->root), allocation);
590
591
592
}

static void
593
gdl_dock_map (GtkWidget *widget)
594
{
595
596
    GtkWidget *child;
    GdlDock   *dock;
597

598
599
600
601
602
    g_return_if_fail (widget != NULL);
    g_return_if_fail (GDL_IS_DOCK (widget));

    dock = GDL_DOCK (widget);

603
    GDL_CALL_PARENT (GTK_WIDGET_CLASS, map, (widget));
604
605
606

    if (dock->root) {
        child = GTK_WIDGET (dock->root);
607
        if (gtk_widget_get_visible (child) && !gtk_widget_get_mapped (child))
608
609
            gtk_widget_map (child);
    }
610
611
612
}

static void
613
gdl_dock_unmap (GtkWidget *widget)
614
{
615
616
617
618
619
620
621
622
    GtkWidget *child;
    GdlDock   *dock;
    
    g_return_if_fail (widget != NULL);
    g_return_if_fail (GDL_IS_DOCK (widget));

    dock = GDL_DOCK (widget);

623
    GDL_CALL_PARENT (GTK_WIDGET_CLASS, unmap, (widget));
624
625
626

    if (dock->root) {
        child = GTK_WIDGET (dock->root);
627
        if (gtk_widget_get_visible (child) && gtk_widget_get_mapped (child))
628
629
630
631
632
            gtk_widget_unmap (child);
    }
    
    if (dock->_priv->window)
        gtk_widget_unmap (dock->_priv->window);
633
634
635
}

static void
636
637
gdl_dock_foreach_automatic (GdlDockObject *object,
                            gpointer       user_data)
638
{
639
640
641
642
    void (* function) (GtkWidget *) = user_data;

    if (GDL_DOCK_OBJECT_AUTOMATIC (object))
        (* function) (GTK_WIDGET (object));
643
644
645
}

static void
646
gdl_dock_show (GtkWidget *widget)
647
648
{
    GdlDock *dock;
649
    
650
    g_return_if_fail (widget != NULL);
651
652
    g_return_if_fail (GDL_IS_DOCK (widget));
    
653
    GDL_CALL_PARENT (GTK_WIDGET_CLASS, show, (widget));
654
    
655
    dock = GDL_DOCK (widget);
656
657
    if (dock->_priv->floating && dock->_priv->window)
        gtk_widget_show (dock->_priv->window);
658

659
660
661
662
663
    if (GDL_DOCK_IS_CONTROLLER (dock)) {
        gdl_dock_master_foreach_toplevel (GDL_DOCK_OBJECT_GET_MASTER (dock),
                                          FALSE, (GFunc) gdl_dock_foreach_automatic,
                                          gtk_widget_show);
    }
664
665
666
}

static void
667
gdl_dock_hide (GtkWidget *widget)
668
669
{
    GdlDock *dock;
670
    
671
    g_return_if_fail (widget != NULL);
672
673
    g_return_if_fail (GDL_IS_DOCK (widget));
    
674
    GDL_CALL_PARENT (GTK_WIDGET_CLASS, hide, (widget));
675
    
676
    dock = GDL_DOCK (widget);
677
678
    if (dock->_priv->floating && dock->_priv->window)
        gtk_widget_hide (dock->_priv->window);
679

680
681
682
683
684
    if (GDL_DOCK_IS_CONTROLLER (dock)) {
        gdl_dock_master_foreach_toplevel (GDL_DOCK_OBJECT_GET_MASTER (dock),
                                          FALSE, (GFunc) gdl_dock_foreach_automatic,
                                          gtk_widget_hide);
    }
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
}

static void
gdl_dock_add (GtkContainer *container,
              GtkWidget    *widget)
{
    g_return_if_fail (container != NULL);
    g_return_if_fail (GDL_IS_DOCK (container));
    g_return_if_fail (GDL_IS_DOCK_ITEM (widget));

    gdl_dock_add_item (GDL_DOCK (container), 
                       GDL_DOCK_ITEM (widget), 
                       GDL_DOCK_TOP);  /* default position */
}

static void
gdl_dock_remove (GtkContainer *container,
                 GtkWidget    *widget)
{
    GdlDock  *dock;
    gboolean  was_visible;

    g_return_if_fail (container != NULL);
    g_return_if_fail (widget != NULL);

    dock = GDL_DOCK (container);
711
    was_visible = gtk_widget_get_visible (widget);
712

713
    if (GTK_WIDGET (dock->root) == widget) {
714
        dock->root = NULL;
715
        GDL_DOCK_OBJECT_UNSET_FLAGS (widget, GDL_DOCK_ATTACHED);
716
        gtk_widget_unparent (widget);
717

718
        if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
            gtk_widget_queue_resize (GTK_WIDGET (dock));
    }
}

static void
gdl_dock_forall (GtkContainer *container,
                 gboolean      include_internals,
                 GtkCallback   callback,
                 gpointer      callback_data)
{
    GdlDock *dock;

    g_return_if_fail (container != NULL);
    g_return_if_fail (GDL_IS_DOCK (container));
    g_return_if_fail (callback != NULL);

    dock = GDL_DOCK (container);

    if (dock->root)
738
        (*callback) (GTK_WIDGET (dock->root), callback_data);
739
740
}

741
static GType
742
gdl_dock_child_type (GtkContainer *container)
743
{
744
    return GDL_TYPE_DOCK_ITEM;
745
746
747
}

static void
748
749
gdl_dock_detach (GdlDockObject *object,
                 gboolean       recursive)
750
{
751
752
753
754
755
756
757
    GdlDock *dock = GDL_DOCK (object);
    
    /* detach children */
    if (recursive && dock->root) {
        gdl_dock_object_detach (dock->root, recursive);
    }
    GDL_DOCK_OBJECT_UNSET_FLAGS (object, GDL_DOCK_ATTACHED);
758
759
760
}

static void
761
gdl_dock_reduce (GdlDockObject *object)
762
{
763
    GdlDock *dock = GDL_DOCK (object);
764
    GtkWidget *parent;
765
766
767
768
769
770
771
772
773
774
775
776
777
    
    if (dock->root)
        return;
    
    if (GDL_DOCK_OBJECT_AUTOMATIC (dock)) {
        gtk_widget_destroy (GTK_WIDGET (dock));

    } else if (!GDL_DOCK_OBJECT_ATTACHED (dock)) {
        /* if the user explicitly detached the object */
        if (dock->_priv->floating)
            gtk_widget_hide (GTK_WIDGET (dock));
        else {
            GtkWidget *widget = GTK_WIDGET (object);
778
779
780
            parent = gtk_widget_get_parent (widget);
            if (parent)
                gtk_container_remove (GTK_CONTAINER (parent), widget);
781
782
        }
    }
783
784
}

785
786
787
788
789
static gboolean
gdl_dock_dock_request (GdlDockObject  *object,
                       gint            x,
                       gint            y,
                       GdlDockRequest *request)
790
{
791
792
793
794
795
796
    GdlDock            *dock;
    guint               bw;
    gint                rel_x, rel_y;
    GtkAllocation      *alloc;
    gboolean            may_dock = FALSE;
    GdlDockRequest      my_request;
797

798
    g_return_val_if_fail (GDL_IS_DOCK (object), FALSE);
799

800
801
802
803
    /* we get (x,y) in our allocation coordinates system */
    
    dock = GDL_DOCK (object);
    
804
    /* Get dock size. */
805
806
    gtk_widget_get_allocation (GTK_WIDGET (dock), alloc);
    bw = gtk_container_get_border_width (GTK_CONTAINER (dock));
807

808
809
810
    /* Get coordinates relative to our allocation area. */
    rel_x = x - alloc->x;
    rel_y = y - alloc->y;
811

812
813
814
815
816
817
    if (request)
        my_request = *request;
        
    /* Check if coordinates are in GdlDock widget. */
    if (rel_x > 0 && rel_x < alloc->width &&
        rel_y > 0 && rel_y < alloc->height) {
818
819

        /* It's inside our area. */
820
        may_dock = TRUE;
821
822

	/* Set docking indicator rectangle to the GdlDock size. */
823
824
825
826
        my_request.rect.x = alloc->x + bw;
        my_request.rect.y = alloc->y + bw;
        my_request.rect.width = alloc->width - 2*bw;
        my_request.rect.height = alloc->height - 2*bw;
827
828
829
830

	/* If GdlDock has no root item yet, set the dock itself as 
	   possible target. */
        if (!dock->root) {
831
832
            my_request.position = GDL_DOCK_TOP;
            my_request.target = object;
833
        } else {
834
            my_request.target = dock->root;
835
836

            /* See if it's in the border_width band. */
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
            if (rel_x < bw) {
                my_request.position = GDL_DOCK_LEFT;
                my_request.rect.width *= SPLIT_RATIO;
            } else if (rel_x > alloc->width - bw) {
                my_request.position = GDL_DOCK_RIGHT;
                my_request.rect.x += my_request.rect.width * (1 - SPLIT_RATIO);
                my_request.rect.width *= SPLIT_RATIO;
            } else if (rel_y < bw) {
                my_request.position = GDL_DOCK_TOP;
                my_request.rect.height *= SPLIT_RATIO;
            } else if (rel_y > alloc->height - bw) {
                my_request.position = GDL_DOCK_BOTTOM;
                my_request.rect.y += my_request.rect.height * (1 - SPLIT_RATIO);
                my_request.rect.height *= SPLIT_RATIO;
            } else {
                /* Otherwise try our children. */
                /* give them allocation coordinates (we are a
                   GTK_NO_WINDOW) widget */
                may_dock = gdl_dock_object_dock_request (GDL_DOCK_OBJECT (dock->root), 
                                                         x, y, &my_request);
857
858
859
            }
        }
    }
860
861
862

    if (may_dock && request)
        *request = my_request;
863
    
864
865
    return may_dock;
}
866

867
868
869
870
871
872
873
874
875
876
877
static void
gdl_dock_dock (GdlDockObject    *object,
               GdlDockObject    *requestor,
               GdlDockPlacement  position,
               GValue           *user_data)
{
    GdlDock *dock;
    
    g_return_if_fail (GDL_IS_DOCK (object));
    /* only dock items allowed at this time */
    g_return_if_fail (GDL_IS_DOCK_ITEM (requestor));
878

879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
    dock = GDL_DOCK (object);
    
    if (position == GDL_DOCK_FLOATING) {
        GdlDockItem *item = GDL_DOCK_ITEM (requestor);
        gint x, y, width, height;

        if (user_data && G_VALUE_HOLDS (user_data, GDK_TYPE_RECTANGLE)) {
            GdkRectangle *rect;

            rect = g_value_get_boxed (user_data);
            x = rect->x;
            y = rect->y;
            width = rect->width;
            height = rect->height;
        }
        else {
            x = y = 0;
            width = height = -1;
        }
        
        gdl_dock_add_floating_item (dock, item,
                                    x, y, width, height);
    }
    else if (dock->root) {
        /* This is somewhat a special case since we know which item to
           pass the request on because we only have on child */
        gdl_dock_object_dock (dock->root, requestor, position, NULL);
        gdl_dock_set_title (dock);
        
    }
    else { /* Item about to be added is root item. */
        GtkWidget *widget = GTK_WIDGET (requestor);
        
        dock->root = requestor;
        GDL_DOCK_OBJECT_SET_FLAGS (requestor, GDL_DOCK_ATTACHED);
        gtk_widget_set_parent (widget, GTK_WIDGET (dock));
        
        gdl_dock_item_show_grip (GDL_DOCK_ITEM (requestor));
917

918
919
        /* Realize the item (create its corresponding GdkWindow) when 
           GdlDock has been realized. */
920
        if (gtk_widget_get_realized (GTK_WIDGET (dock)))
921
            gtk_widget_realize (widget);
922
        
923
924
925
        /* Map the widget if it's visible and the parent is visible and has 
           been mapped. This is done to make sure that the GdkWindow is 
           visible. */
926
927
928
        if (gtk_widget_get_visible (GTK_WIDGET (dock)) && 
            gtk_widget_get_visible (widget)) {
            if (gtk_widget_get_mapped (GTK_WIDGET (dock)))
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
                gtk_widget_map (widget);
            
            /* Make the widget resize. */
            gtk_widget_queue_resize (widget);
        }
        gdl_dock_set_title (dock);
    }
}
    
static gboolean
gdl_dock_floating_window_delete_event_cb (GtkWidget *widget)
{
    GdlDock *dock;
    
    g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE);
    
    dock = GDL_DOCK (g_object_get_data (G_OBJECT (widget), "dock"));
    if (dock->root) {
        /* this will call reduce on ourselves, hiding the window if appropiate */
        gdl_dock_item_hide_item (GDL_DOCK_ITEM (dock->root));
    }

    return TRUE;
952
953
}

954
955
956
static void
_gdl_dock_foreach_build_list (GdlDockObject *object,
                              gpointer       user_data)
957
{
958
959
960
961
    GList **l = (GList **) user_data;

    if (GDL_IS_DOCK_ITEM (object))
        *l = g_list_prepend (*l, object);
962
}
963

964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
static gboolean
gdl_dock_reorder (GdlDockObject    *object,
                  GdlDockObject    *requestor,
                  GdlDockPlacement  new_position,
                  GValue           *other_data)
{
    GdlDock *dock = GDL_DOCK (object);
    gboolean handled = FALSE;
    
    if (dock->_priv->floating &&
        new_position == GDL_DOCK_FLOATING &&
        dock->root == requestor) {
        
        if (other_data && G_VALUE_HOLDS (other_data, GDK_TYPE_RECTANGLE)) {
            GdkRectangle *rect;

            rect = g_value_get_boxed (other_data);
            gtk_window_move (GTK_WINDOW (dock->_priv->window),
                             rect->x,
                             rect->y);
            handled = TRUE;
        }
    }
    
    return handled;
}
990

991
992
993
994
static gboolean 
gdl_dock_child_placement (GdlDockObject    *object,
                          GdlDockObject    *child,
                          GdlDockPlacement *placement)
995
{
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
    GdlDock *dock = GDL_DOCK (object);
    gboolean retval = TRUE;
    
    if (dock->root == child) {
        if (placement) {
            if (*placement == GDL_DOCK_NONE || *placement == GDL_DOCK_FLOATING)
                *placement = GDL_DOCK_TOP;
        }
    } else 
        retval = FALSE;

    return retval;
1008
1009
}

1010
1011
1012
static void 
gdl_dock_present (GdlDockObject *object,
                  GdlDockObject *child)
1013
{
1014
    GdlDock *dock = GDL_DOCK (object);
1015

1016
1017
1018
    if (dock->_priv->floating)
        gtk_window_present (GTK_WINDOW (dock->_priv->window));
}
1019
1020


1021
/* ----- Public interface ----- */
1022

1023
1024
1025
1026
GtkWidget *
gdl_dock_new (void)
{
    GObject *dock;
1027

1028
1029
1030
1031
1032
    dock = g_object_new (GDL_TYPE_DOCK, NULL);
    GDL_DOCK_OBJECT_UNSET_FLAGS (dock, GDL_DOCK_AUTOMATIC);
    
    return GTK_WIDGET (dock);
}
1033

1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
GtkWidget *
gdl_dock_new_from (GdlDock  *original,
                   gboolean  floating)
{
    GObject *new_dock;
    
    g_return_val_if_fail (original != NULL, NULL);
    
    new_dock = g_object_new (GDL_TYPE_DOCK, 
                             "master", GDL_DOCK_OBJECT_GET_MASTER (original), 
                             "floating", floating,
                             NULL);
    GDL_DOCK_OBJECT_UNSET_FLAGS (new_dock, GDL_DOCK_AUTOMATIC);
    
    return GTK_WIDGET (new_dock);
1049
1050
}

1051
1052
1053
1054
1055
1056
1057
1058
1059
/* Depending on where the dock item (where new item will be docked) locates
 * in the dock, we might need to change the docking placement. If the
 * item is does not touches the center of dock, the new-item-to-dock would
 * require a center dock on this item.
 */
static GdlDockPlacement
gdl_dock_refine_placement (GdlDock *dock, GdlDockItem *dock_item,
                           GdlDockPlacement placement)
{
1060
    GtkAllocation allocation;
1061
1062
1063
    GtkRequisition object_size;
    
    gdl_dock_item_preferred_size (dock_item, &object_size);
1064
1065
1066
1067
    gtk_widget_get_allocation (GTK_WIDGET (dock), &allocation);

    g_return_val_if_fail (allocation.width > 0, placement);
    g_return_val_if_fail (allocation.height > 0, placement);
1068
1069
1070
1071
1072
    g_return_val_if_fail (object_size.width > 0, placement);
    g_return_val_if_fail (object_size.height > 0, placement);

    if (placement == GDL_DOCK_LEFT || placement == GDL_DOCK_RIGHT) {
        /* Check if dock_object touches center in terms of width */
1073
        if (allocation.width/2 > object_size.width) {
1074
1075
1076
1077
            return GDL_DOCK_CENTER;
        }
    } else if (placement == GDL_DOCK_TOP || placement == GDL_DOCK_BOTTOM) {
        /* Check if dock_object touches center in terms of height */
1078
        if (allocation.height/2 > object_size.height) {
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
            return GDL_DOCK_CENTER;
        }
    }
    return placement;
}

/* Determines the larger item of the two based on the placement:
 * for left/right placement, height determines it.
 * for top/bottom placement, width determines it.
 * for center placement, area determines it.
 */
static GdlDockItem*
gdl_dock_select_larger_item (GdlDockItem *dock_item_1,
                             GdlDockItem *dock_item_2,
                             GdlDockPlacement placement,
                             gint level /* for debugging */)
{
    GtkRequisition size_1, size_2;
    
    g_return_val_if_fail (dock_item_1 != NULL, dock_item_2);
    g_return_val_if_fail (dock_item_2 != NULL, dock_item_1);
    
    gdl_dock_item_preferred_size (dock_item_1, &size_1);
    gdl_dock_item_preferred_size (dock_item_2, &size_2);
    
    g_return_val_if_fail (size_1.width > 0, dock_item_2);
    g_return_val_if_fail (size_1.height > 0, dock_item_2);
    g_return_val_if_fail (size_2.width > 0, dock_item_1);
    g_return_val_if_fail (size_2.height > 0, dock_item_1);
    
    if (placement == GDL_DOCK_LEFT || placement == GDL_DOCK_RIGHT)
    {
        /* For left/right placement, height is what matters */
        return (size_1.height >= size_2.height?
                    dock_item_1 : dock_item_2);
    } else if (placement == GDL_DOCK_TOP || placement == GDL_DOCK_BOTTOM)
    {
        /* For top/bottom placement, width is what matters */
        return (size_1.width >= size_2.width?
                    dock_item_1 : dock_item_2);
    } else if (placement == GDL_DOCK_CENTER) {
        /* For center place, area is what matters */
        return ((size_1.width * size_1.height)
                    >= (size_2.width * size_2.height)?
                    dock_item_1 : dock_item_2);
1124
1125
    } else if (placement == GDL_DOCK_NONE) {
	return dock_item_1;
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
    } else {
        g_warning ("Should not reach here: %s:%d", __FUNCTION__, __LINE__);
    }
    return dock_item_1;
}

/* Determines the best dock item to dock a new item with the given placement.
 * It traverses the dock tree and (based on the placement) tries to find
 * the best located item wrt to the placement. The approach is to find the
 * largest item on/around the placement side (for side placements) and to
 * find the largest item for center placement. In most situations, this is
 * what user wants and the heuristic should be therefore sufficient.
 */
static GdlDockItem*
gdl_dock_find_best_placement_item (GdlDockItem *dock_item,
                                   GdlDockPlacement placement,
                                   gint level /* for debugging */)
{
    GdlDockItem *ret_item = NULL;
    
    if (GDL_IS_DOCK_PANED (dock_item))
    {
        GtkOrientation orientation;
        GdlDockItem *dock_item_1, *dock_item_2;
        GList* children;
        
        children = gtk_container_get_children (GTK_CONTAINER (dock_item));
        
        g_assert (g_list_length (children) == 2);
        
        g_object_get (dock_item, "orientation", &orientation, NULL);
        if ((orientation == GTK_ORIENTATION_HORIZONTAL &&
             placement == GDL_DOCK_LEFT) ||
            (orientation == GTK_ORIENTATION_VERTICAL &&
             placement == GDL_DOCK_TOP)) {
            /* Return left or top pane widget */
            ret_item =
                gdl_dock_find_best_placement_item (GDL_DOCK_ITEM
                                                   (children->data),
                                                   placement, level + 1);
        } else if ((orientation == GTK_ORIENTATION_HORIZONTAL &&
                    placement == GDL_DOCK_RIGHT) ||
                   (orientation == GTK_ORIENTATION_VERTICAL &&
                    placement == GDL_DOCK_BOTTOM)) {
                        /* Return right or top pane widget */
            ret_item =
                gdl_dock_find_best_placement_item (GDL_DOCK_ITEM
                                                   (children->next->data),
                                                   placement, level + 1);
        } else {
            /* Evaluate which of the two sides is bigger */
            dock_item_1 =
                gdl_dock_find_best_placement_item (GDL_DOCK_ITEM
                                                   (children->data),
                                                   placement, level + 1);
            dock_item_2 =
                gdl_dock_find_best_placement_item (GDL_DOCK_ITEM
                                                   (children->next->data),
                                                   placement, level + 1);
            ret_item = gdl_dock_select_larger_item (dock_item_1,
                                                    dock_item_2,
                                                    placement, level);
        }
        g_list_free (children);
    }
    else if (GDL_IS_DOCK_ITEM (dock_item))
    {
        ret_item = dock_item;
    }
    else
    {
        /* should not be here */
        g_warning ("Should not reach here: %s:%d", __FUNCTION__, __LINE__);
    }
    return ret_item;
}

1203
1204
1205
1206
1207
1208
1209
1210
1211
void
gdl_dock_add_item (GdlDock          *dock,
                   GdlDockItem      *item,
                   GdlDockPlacement  placement)
{
    g_return_if_fail (dock != NULL);
    g_return_if_fail (item != NULL);

    if (placement == GDL_DOCK_FLOATING)
1212
1213
1214
1215
        /* Add the item to a new floating dock */
        gdl_dock_add_floating_item (dock, item, 0, 0, -1, -1);

    else {
1216
        GdlDockItem *best_dock_item;
1217
        /* Non-floating item. */
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
        if (dock->root) {
            GdlDockPlacement local_placement;
            GtkRequisition preferred_size;
            
            best_dock_item =
                gdl_dock_find_best_placement_item (GDL_DOCK_ITEM (dock->root),
                                                   placement, 0);
            local_placement = gdl_dock_refine_placement (dock, best_dock_item,
                                                         placement);
            gdl_dock_object_dock (GDL_DOCK_OBJECT (best_dock_item),
                                  GDL_DOCK_OBJECT (item),
                                  local_placement, NULL);
        } else {
            gdl_dock_object_dock (GDL_DOCK_OBJECT (dock),
                                  GDL_DOCK_OBJECT (item),
                                  placement, NULL);
        }
1235
1236
1237
1238
1239
1240
1241
1242
    }
}

void
gdl_dock_add_floating_item (GdlDock        *dock,
                            GdlDockItem    *item,
                            gint            x,
                            gint            y,
1243
1244
                            gint            width,
                            gint            height)
1245
{
1246
1247
    GdlDock *new_dock;
    
1248
1249
1250
    g_return_if_fail (dock != NULL);
    g_return_if_fail (item != NULL);
    
1251
1252
1253
1254
1255
1256
1257
1258
    new_dock = GDL_DOCK (g_object_new (GDL_TYPE_DOCK, 
                                       "master", GDL_DOCK_OBJECT_GET_MASTER (dock), 
                                       "floating", TRUE,
                                       "width", width,
                                       "height", height,
                                       "floatx", x,
                                       "floaty", y,
                                       NULL));
1259
    
1260
    if (gtk_widget_get_visible (GTK_WIDGET (dock))) {
1261
        gtk_widget_show (GTK_WIDGET (new_dock));
1262
        if (gtk_widget_get_mapped (GTK_WIDGET (dock)))
1263
1264
1265
1266
            gtk_widget_map (GTK_WIDGET (new_dock));
        
        /* Make the widget resize. */
        gtk_widget_queue_resize (GTK_WIDGET (new_dock));
1267
1268
    }

1269
    gdl_dock_add_item (GDL_DOCK (new_dock), item, GDL_DOCK_TOP);
1270
1271
}

1272
1273
1274
GdlDockItem *
gdl_dock_get_item_by_name (GdlDock     *dock,
                           const gchar *name)
1275
{
1276
    GdlDockObject *found;
1277
    
1278
1279
1280
1281
    g_return_val_if_fail (dock != NULL && name != NULL, NULL);
    
    /* proxy the call to our master */
    found = gdl_dock_master_get_object (GDL_DOCK_OBJECT_GET_MASTER (dock), name);
1282

1283
    return (found && GDL_IS_DOCK_ITEM (found)) ? GDL_DOCK_ITEM (found) : NULL;
1284
1285
}

1286
1287
1288
GdlDockPlaceholder *
gdl_dock_get_placeholder_by_name (GdlDock     *dock,
                                  const gchar *name)
1289
{
1290
    GdlDockObject *found;
1291
    
1292
    g_return_val_if_fail (dock != NULL && name != NULL, NULL);
1293
    
1294
1295
1296
1297
1298
    /* proxy the call to our master */
    found = gdl_dock_master_get_object (GDL_DOCK_OBJECT_GET_MASTER (dock), name);

    return (found && GDL_IS_DOCK_PLACEHOLDER (found)) ?
        GDL_DOCK_PLACEHOLDER (found) : NULL;
1299
}
1300

1301
1302
GList *
gdl_dock_get_named_items (GdlDock *dock)
1303
{
1304
1305
1306
    GList *list = NULL;
    
    g_return_val_if_fail (dock != NULL, NULL);
1307

1308
1309
    gdl_dock_master_foreach (GDL_DOCK_OBJECT_GET_MASTER (dock),
                             (GFunc) _gdl_dock_foreach_build_list, &list);
1310

1311
1312
    return list;
}
1313

1314
1315
1316
1317
1318
1319
GdlDock *
gdl_dock_object_get_toplevel (GdlDockObject *object)
{
    GdlDockObject *parent = object;
    
    g_return_val_if_fail (object != NULL, NULL);
1320

1321
1322
    while (parent && !GDL_IS_DOCK (parent))
        parent = gdl_dock_object_get_parent_object (parent);
1323

1324
    return parent ? GDL_DOCK (parent) : NULL;
1325
1326
1327
}

void
1328
1329
gdl_dock_xor_rect (GdlDock      *dock,
                   GdkRectangle *rect)
1330
{
1331
    GtkWidget *widget;
1332
    GdkWindow *window;
1333
    gint8      dash_list [2];
1334

1335
    widget = GTK_WIDGET (dock);
1336

1337
    if (!dock->_priv->xor_gc) {
1338
        if (gtk_widget_get_realized (widget)) {
1339
            GdkGCValues values;
1340

1341
1342
1343
            values.function = GDK_INVERT;
            values.subwindow_mode = GDK_INCLUDE_INFERIORS;
            dock->_priv->xor_gc = gdk_gc_new_with_values 
1344
                (gtk_widget_get_window (widget), &values, GDK_GC_FUNCTION | GDK_GC_SUBWINDOW);
1345
1346
1347
        } else 
            return;
    };
Dave Camp's avatar
Dave Camp committed
1348

1349
1350
1351
1352
    gdk_gc_set_line_attributes (dock->_priv->xor_gc, 1,
                                GDK_LINE_ON_OFF_DASH,
                                GDK_CAP_NOT_LAST,
                                GDK_JOIN_BEVEL);
1353
1354
1355

    window = gtk_widget_get_window (widget);

1356
1357
1358
1359
    dash_list [0] = 1;
    dash_list [1] = 1;
    
    gdk_gc_set_dashes (dock->_priv->xor_gc, 1, dash_list, 2);
Dave Camp's avatar
Dave Camp committed
1360

1361
    gdk_draw_rectangle (window, dock->_priv->xor_gc, FALSE,
1362
1363
                        rect->x, rect->y,
                        rect->width, rect->height);
Dave Camp's avatar
Dave Camp committed
1364

1365
    gdk_gc_set_dashes (dock->_priv->xor_gc, 0, dash_list, 2);
Dave Camp's avatar
Dave Camp committed
1366

1367
    gdk_draw_rectangle (window, dock->_priv->xor_gc, FALSE,
1368
1369
                        rect->x + 1, rect->y + 1,
                        rect->width - 2, rect->height - 2);
Dave Camp's avatar
Dave Camp committed
1370
}