1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
5
* Copyright (C) 2001-2003 Michael Natterer <mitch@gimp.org>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
#include "libgimpwidgets/gimpwidgets.h"
28
#include "widgets-types.h"
30
#include "core/gimpcontext.h"
32
#include "gimpdialogfactory.h"
35
#include "gimpdockable.h"
36
#include "gimpdockbook.h"
37
#include "gimpdocked.h"
38
#include "gimphelp-ids.h"
39
#include "gimpuimanager.h"
40
#include "gimpwidgets-utils.h"
42
#include "gimp-intl.h"
45
static void gimp_dockable_class_init (GimpDockableClass *klass);
46
static void gimp_dockable_init (GimpDockable *dockable);
48
static void gimp_dockable_destroy (GtkObject *object);
49
static void gimp_dockable_size_request (GtkWidget *widget,
50
GtkRequisition *requisition);
51
static void gimp_dockable_size_allocate (GtkWidget *widget,
52
GtkAllocation *allocation);
53
static void gimp_dockable_realize (GtkWidget *widget);
54
static void gimp_dockable_unrealize (GtkWidget *widget);
55
static void gimp_dockable_map (GtkWidget *widget);
56
static void gimp_dockable_unmap (GtkWidget *widget);
58
static gboolean gimp_dockable_drag_drop (GtkWidget *widget,
59
GdkDragContext *context,
63
static void gimp_dockable_style_set (GtkWidget *widget,
64
GtkStyle *prev_style);
65
static gboolean gimp_dockable_expose_event (GtkWidget *widget,
66
GdkEventExpose *event);
67
static gboolean gimp_dockable_drag_event_filter (GtkWidget *widget,
69
static gboolean gimp_dockable_popup_menu (GtkWidget *widget);
71
static void gimp_dockable_add (GtkContainer *container,
73
static void gimp_dockable_remove (GtkContainer *container,
75
static GType gimp_dockable_child_type (GtkContainer *container);
76
static void gimp_dockable_forall (GtkContainer *container,
77
gboolean include_internals,
79
gpointer callback_data);
81
static void gimp_dockable_get_title_area (GimpDockable *dockable,
84
static gboolean gimp_dockable_menu_button_press (GtkWidget *button,
85
GdkEventButton *bevent,
86
GimpDockable *dockable);
87
static void gimp_dockable_close_clicked (GtkWidget *button,
88
GimpDockable *dockable);
89
static gboolean gimp_dockable_show_menu (GimpDockable *dockable);
91
static void gimp_dockable_title_changed (GimpDocked *docked,
92
GimpDockable *dockable);
95
static GtkBinClass *parent_class = NULL;
97
static GtkTargetEntry dialog_target_table[] =
104
gimp_dockable_get_type (void)
106
static GType dockable_type = 0;
110
static const GTypeInfo dockable_info =
112
sizeof (GimpDockableClass),
113
NULL, /* base_init */
114
NULL, /* base_finalize */
115
(GClassInitFunc) gimp_dockable_class_init,
116
NULL, /* class_finalize */
117
NULL, /* class_data */
118
sizeof (GimpDockable),
120
(GInstanceInitFunc) gimp_dockable_init,
123
dockable_type = g_type_register_static (GTK_TYPE_BIN,
128
return dockable_type;
132
gimp_dockable_class_init (GimpDockableClass *klass)
134
GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
135
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
136
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
138
parent_class = g_type_class_peek_parent (klass);
140
object_class->destroy = gimp_dockable_destroy;
142
widget_class->size_request = gimp_dockable_size_request;
143
widget_class->size_allocate = gimp_dockable_size_allocate;
144
widget_class->realize = gimp_dockable_realize;
145
widget_class->unrealize = gimp_dockable_unrealize;
146
widget_class->map = gimp_dockable_map;
147
widget_class->unmap = gimp_dockable_unmap;
148
widget_class->style_set = gimp_dockable_style_set;
149
widget_class->drag_drop = gimp_dockable_drag_drop;
150
widget_class->expose_event = gimp_dockable_expose_event;
151
widget_class->popup_menu = gimp_dockable_popup_menu;
153
container_class->add = gimp_dockable_add;
154
container_class->remove = gimp_dockable_remove;
155
container_class->child_type = gimp_dockable_child_type;
156
container_class->forall = gimp_dockable_forall;
158
gtk_widget_class_install_style_property (widget_class,
159
g_param_spec_int ("content_border",
168
gimp_dockable_init (GimpDockable *dockable)
172
dockable->name = NULL;
173
dockable->blurb = NULL;
174
dockable->stock_id = NULL;
175
dockable->help_id = NULL;
176
dockable->tab_style = GIMP_TAB_STYLE_PREVIEW;
177
dockable->dockbook = NULL;
178
dockable->context = NULL;
180
dockable->title_layout = NULL;
181
dockable->title_window = NULL;
183
gtk_widget_push_composite_child ();
184
dockable->menu_button = gtk_button_new ();
185
gtk_widget_pop_composite_child ();
187
GTK_WIDGET_UNSET_FLAGS (dockable->menu_button, GTK_CAN_FOCUS);
188
gtk_widget_set_parent (dockable->menu_button, GTK_WIDGET (dockable));
189
gtk_button_set_relief (GTK_BUTTON (dockable->menu_button), GTK_RELIEF_NONE);
190
gtk_widget_show (dockable->menu_button);
192
image = gtk_image_new_from_stock (GIMP_STOCK_MENU_LEFT, GTK_ICON_SIZE_MENU);
193
gtk_container_add (GTK_CONTAINER (dockable->menu_button), image);
194
gtk_widget_show (image);
196
g_signal_connect (dockable->menu_button, "button_press_event",
197
G_CALLBACK (gimp_dockable_menu_button_press),
200
gtk_widget_push_composite_child ();
201
dockable->close_button = gtk_button_new ();
202
gtk_widget_pop_composite_child ();
204
GTK_WIDGET_UNSET_FLAGS (dockable->close_button, GTK_CAN_FOCUS);
205
gtk_widget_set_parent (dockable->close_button, GTK_WIDGET (dockable));
206
gtk_button_set_relief (GTK_BUTTON (dockable->close_button), GTK_RELIEF_NONE);
207
gtk_widget_show (dockable->close_button);
209
gimp_help_set_help_data (dockable->close_button, _("Close this Tab"),
210
GIMP_HELP_DOCK_TAB_CLOSE);
212
image = gtk_image_new_from_stock (GIMP_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
213
gtk_container_add (GTK_CONTAINER (dockable->close_button), image);
214
gtk_widget_show (image);
216
g_signal_connect (dockable->close_button, "clicked",
217
G_CALLBACK (gimp_dockable_close_clicked),
220
gtk_drag_dest_set (GTK_WIDGET (dockable),
221
GTK_DEST_DEFAULT_ALL,
222
dialog_target_table, G_N_ELEMENTS (dialog_target_table),
225
/* Filter out all button_press events not coming from the event window
226
over the title area. This keeps events that originate from widgets
227
in the dockable to start a drag.
229
g_signal_connect (dockable, "button_press_event",
230
G_CALLBACK (gimp_dockable_drag_event_filter),
235
gimp_dockable_destroy (GtkObject *object)
237
GimpDockable *dockable = GIMP_DOCKABLE (object);
239
if (dockable->context)
240
gimp_dockable_set_context (dockable, NULL);
242
if (dockable->blurb && dockable->blurb != dockable->name)
244
g_free (dockable->blurb);
245
dockable->blurb = NULL;
250
g_free (dockable->name);
251
dockable->name = NULL;
254
if (dockable->stock_id)
256
g_free (dockable->stock_id);
257
dockable->stock_id = NULL;
260
if (dockable->help_id)
262
g_free (dockable->help_id);
263
dockable->help_id = NULL;
266
if (dockable->title_layout)
268
g_object_unref (dockable->title_layout);
269
dockable->title_layout = NULL;
272
if (dockable->menu_button)
274
gtk_widget_unparent (dockable->menu_button);
275
dockable->menu_button = NULL;
278
if (dockable->close_button)
280
gtk_widget_unparent (dockable->close_button);
281
dockable->close_button = NULL;
284
GTK_OBJECT_CLASS (parent_class)->destroy (object);
288
gimp_dockable_size_request (GtkWidget *widget,
289
GtkRequisition *requisition)
291
GtkContainer *container = GTK_CONTAINER (widget);
292
GtkBin *bin = GTK_BIN (widget);
293
GimpDockable *dockable = GIMP_DOCKABLE (widget);
295
GtkRequisition child_requisition;
297
requisition->width = container->border_width * 2;
298
requisition->height = container->border_width * 2;
300
if (dockable->close_button && GTK_WIDGET_VISIBLE (dockable->close_button))
302
gtk_widget_size_request (dockable->close_button, &child_requisition);
305
requisition->width += child_requisition.width;
307
requisition->height += child_requisition.height;
310
if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
312
gtk_widget_size_request (bin->child, &child_requisition);
314
requisition->width += child_requisition.width;
315
requisition->height += child_requisition.height;
320
gimp_dockable_size_allocate (GtkWidget *widget,
321
GtkAllocation *allocation)
323
GtkContainer *container = GTK_CONTAINER (widget);
324
GtkBin *bin = GTK_BIN (widget);
325
GimpDockable *dockable = GIMP_DOCKABLE (widget);
327
GtkRequisition button_requisition = { 0, };
328
GtkAllocation child_allocation;
330
container = GTK_CONTAINER (widget);
331
bin = GTK_BIN (widget);
332
dockable = GIMP_DOCKABLE (widget);
334
widget->allocation = *allocation;
336
if (dockable->close_button)
338
gtk_widget_size_request (dockable->close_button, &button_requisition);
340
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
341
child_allocation.x = (allocation->x +
343
container->border_width -
344
button_requisition.width);
346
child_allocation.x = allocation->x + container->border_width;
348
child_allocation.y = allocation->y + container->border_width;
349
child_allocation.width = button_requisition.width;
350
child_allocation.height = button_requisition.height;
352
gtk_widget_size_allocate (dockable->close_button, &child_allocation);
355
if (dockable->menu_button)
357
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
358
child_allocation.x = (allocation->x +
360
container->border_width -
361
2 * button_requisition.width);
363
child_allocation.x = (allocation->x + container->border_width +
364
button_requisition.width);
366
child_allocation.y = allocation->y + container->border_width;
367
child_allocation.width = button_requisition.width;
368
child_allocation.height = button_requisition.height;
370
gtk_widget_size_allocate (dockable->menu_button, &child_allocation);
375
child_allocation.x = allocation->x + container->border_width;
376
child_allocation.y = allocation->y + container->border_width;
377
child_allocation.width = MAX (allocation->width -
378
container->border_width * 2,
380
child_allocation.height = MAX (allocation->height -
381
container->border_width * 2 -
382
button_requisition.height,
385
child_allocation.y += button_requisition.height;
387
gtk_widget_size_allocate (bin->child, &child_allocation);
390
if (dockable->title_window)
394
gimp_dockable_get_title_area (dockable, &area);
396
gdk_window_move_resize (dockable->title_window,
397
area.x, area.y, area.width, area.height);
402
gimp_dockable_realize (GtkWidget *widget)
404
GimpDockable *dockable = GIMP_DOCKABLE (widget);
406
GTK_WIDGET_CLASS (parent_class)->realize (widget);
408
if (! dockable->title_window)
410
GdkWindowAttr attributes;
414
gimp_dockable_get_title_area (dockable, &area);
416
attributes.x = area.x;
417
attributes.y = area.y;
418
attributes.width = area.width;
419
attributes.height = area.height;
420
attributes.window_type = GDK_WINDOW_TEMP;
421
attributes.wclass = GDK_INPUT_ONLY;
422
attributes.override_redirect = TRUE;
423
attributes.event_mask = (GDK_BUTTON_PRESS_MASK |
424
GDK_BUTTON_RELEASE_MASK |
425
GDK_BUTTON_MOTION_MASK |
426
gtk_widget_get_events (widget));
428
dockable->title_window = gdk_window_new (widget->window,
434
gdk_window_set_user_data (dockable->title_window, widget);
436
cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
438
gdk_window_set_cursor (dockable->title_window, cursor);
439
gdk_cursor_unref (cursor);
444
gimp_dockable_unrealize (GtkWidget *widget)
446
GimpDockable *dockable = GIMP_DOCKABLE (widget);
448
if (dockable->title_window)
450
gdk_window_set_user_data (dockable->title_window, NULL);
451
gdk_window_destroy (dockable->title_window);
452
dockable->title_window = NULL;
455
GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
459
gimp_dockable_map (GtkWidget *widget)
461
GimpDockable *dockable = GIMP_DOCKABLE (widget);
463
GTK_WIDGET_CLASS (parent_class)->map (widget);
465
if (dockable->title_window)
466
gdk_window_show (dockable->title_window);
470
gimp_dockable_unmap (GtkWidget *widget)
472
GimpDockable *dockable = GIMP_DOCKABLE (widget);
474
if (dockable->title_window)
475
gdk_window_hide (dockable->title_window);
477
GTK_WIDGET_CLASS (parent_class)->unmap (widget);
481
gimp_dockable_drag_drop (GtkWidget *widget,
482
GdkDragContext *context,
487
return gimp_dockbook_drop_dockable (GIMP_DOCKABLE (widget)->dockbook,
488
gtk_drag_get_source_widget (context));
492
gimp_dockable_style_set (GtkWidget *widget,
493
GtkStyle *prev_style)
495
GimpDockable *dockable;
498
gtk_widget_style_get (widget,
499
"content_border", &content_border,
502
gtk_container_set_border_width (GTK_CONTAINER (widget), content_border);
504
dockable = GIMP_DOCKABLE (widget);
506
if (dockable->title_layout)
508
g_object_unref (dockable->title_layout);
509
dockable->title_layout = NULL;
512
if (GTK_WIDGET_CLASS (parent_class)->style_set)
513
GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style);
517
gimp_dockable_expose_event (GtkWidget *widget,
518
GdkEventExpose *event)
520
if (GTK_WIDGET_DRAWABLE (widget))
522
GimpDockable *dockable = GIMP_DOCKABLE (widget);
523
GdkRectangle title_area;
524
GdkRectangle expose_area;
526
gimp_dockable_get_title_area (dockable, &title_area);
528
if (gdk_rectangle_intersect (&title_area, &event->area, &expose_area))
535
if (! dockable->title_layout)
537
GtkBin *bin = GTK_BIN (dockable);
541
title = gimp_docked_get_title (GIMP_DOCKED (bin->child));
544
title = g_strdup (dockable->blurb);
546
dockable->title_layout = gtk_widget_create_pango_layout (widget,
552
pango_layout_get_pixel_size (dockable->title_layout,
553
&layout_width, &layout_height);
555
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
557
text_x = title_area.x;
561
text_x = title_area.x + title_area.width - layout_width;
564
text_y = title_area.y + (title_area.height - layout_height) / 2;
566
gtk_paint_layout (widget->style, widget->window,
568
&expose_area, widget, NULL,
569
text_x, text_y, dockable->title_layout);
573
return GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
577
gimp_dockable_drag_event_filter (GtkWidget *widget,
580
/* stop processing of events not coming from the title event window */
581
return (event->window != GIMP_DOCKABLE (widget)->title_window);
585
gimp_dockable_popup_menu (GtkWidget *widget)
587
return gimp_dockable_show_menu (GIMP_DOCKABLE (widget));
591
gimp_dockable_add (GtkContainer *container,
594
g_return_if_fail (GTK_BIN (container)->child == NULL);
596
GTK_CONTAINER_CLASS (parent_class)->add (container, widget);
598
g_signal_connect (widget, "title_changed",
599
G_CALLBACK (gimp_dockable_title_changed),
604
gimp_dockable_remove (GtkContainer *container,
607
g_return_if_fail (GTK_BIN (container)->child == widget);
609
g_signal_handlers_disconnect_by_func (widget,
610
gimp_dockable_title_changed,
613
GTK_CONTAINER_CLASS (parent_class)->remove (container, widget);
617
gimp_dockable_child_type (GtkContainer *container)
619
if (GTK_BIN (container)->child)
622
return GIMP_TYPE_DOCKED;
626
gimp_dockable_forall (GtkContainer *container,
627
gboolean include_internals,
628
GtkCallback callback,
629
gpointer callback_data)
631
GimpDockable *dockable = GIMP_DOCKABLE (container);
633
if (include_internals)
635
if (dockable->menu_button)
636
(* callback) (dockable->menu_button, callback_data);
638
if (dockable->close_button)
639
(* callback) (dockable->close_button, callback_data);
642
GTK_CONTAINER_CLASS (parent_class)->forall (container, include_internals,
643
callback, callback_data);
647
gimp_dockable_new (const gchar *name,
649
const gchar *stock_id,
650
const gchar *help_id)
652
GimpDockable *dockable;
654
g_return_val_if_fail (name != NULL, NULL);
655
g_return_val_if_fail (stock_id != NULL, NULL);
656
g_return_val_if_fail (help_id != NULL, NULL);
658
dockable = g_object_new (GIMP_TYPE_DOCKABLE, NULL);
660
dockable->name = g_strdup (name);
661
dockable->stock_id = g_strdup (stock_id);
662
dockable->help_id = g_strdup (help_id);
665
dockable->blurb = g_strdup (blurb);
667
dockable->blurb = dockable->name;
669
gimp_help_set_help_data (GTK_WIDGET (dockable), NULL, help_id);
671
return GTK_WIDGET (dockable);
675
gimp_dockable_set_aux_info (GimpDockable *dockable,
678
g_return_if_fail (GIMP_IS_DOCKABLE (dockable));
680
if (GTK_BIN (dockable)->child)
681
gimp_docked_set_aux_info (GIMP_DOCKED (GTK_BIN (dockable)->child),
686
gimp_dockable_get_aux_info (GimpDockable *dockable)
688
g_return_val_if_fail (GIMP_IS_DOCKABLE (dockable), NULL);
691
if (GTK_BIN (dockable)->child)
692
return gimp_docked_get_aux_info (GIMP_DOCKED (GTK_BIN (dockable)->child));
698
gimp_dockable_set_tab_style (GimpDockable *dockable,
699
GimpTabStyle tab_style)
701
g_return_if_fail (GIMP_IS_DOCKABLE (dockable));
703
if (GTK_BIN (dockable)->child &&
704
! GIMP_DOCKED_GET_INTERFACE (GTK_BIN (dockable)->child)->get_preview)
708
case GIMP_TAB_STYLE_PREVIEW:
709
tab_style = GIMP_TAB_STYLE_ICON;
712
case GIMP_TAB_STYLE_PREVIEW_NAME:
713
tab_style = GIMP_TAB_STYLE_ICON_BLURB;
716
case GIMP_TAB_STYLE_PREVIEW_BLURB:
717
tab_style = GIMP_TAB_STYLE_ICON_BLURB;
725
dockable->tab_style = tab_style;
729
gimp_dockable_get_tab_widget (GimpDockable *dockable,
730
GimpContext *context,
731
GimpTabStyle tab_style,
734
GtkWidget *tab_widget = NULL;
735
GtkWidget *label = NULL;
736
GtkWidget *icon = NULL;
738
g_return_val_if_fail (GIMP_IS_DOCKABLE (dockable), NULL);
739
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
743
case GIMP_TAB_STYLE_NAME:
744
case GIMP_TAB_STYLE_ICON_NAME:
745
case GIMP_TAB_STYLE_PREVIEW_NAME:
746
label = gtk_label_new (dockable->name);
749
case GIMP_TAB_STYLE_BLURB:
750
case GIMP_TAB_STYLE_ICON_BLURB:
751
case GIMP_TAB_STYLE_PREVIEW_BLURB:
752
label = gtk_label_new (dockable->blurb);
761
case GIMP_TAB_STYLE_ICON:
762
case GIMP_TAB_STYLE_ICON_NAME:
763
case GIMP_TAB_STYLE_ICON_BLURB:
764
icon = gtk_image_new_from_stock (dockable->stock_id, size);
767
case GIMP_TAB_STYLE_PREVIEW:
768
case GIMP_TAB_STYLE_PREVIEW_NAME:
769
case GIMP_TAB_STYLE_PREVIEW_BLURB:
770
if (GTK_BIN (dockable)->child)
771
icon = gimp_docked_get_preview (GIMP_DOCKED (GTK_BIN (dockable)->child),
775
icon = gtk_image_new_from_stock (dockable->stock_id, size);
784
case GIMP_TAB_STYLE_ICON:
785
case GIMP_TAB_STYLE_PREVIEW:
789
case GIMP_TAB_STYLE_NAME:
790
case GIMP_TAB_STYLE_BLURB:
794
case GIMP_TAB_STYLE_ICON_NAME:
795
case GIMP_TAB_STYLE_ICON_BLURB:
796
case GIMP_TAB_STYLE_PREVIEW_NAME:
797
case GIMP_TAB_STYLE_PREVIEW_BLURB:
798
tab_widget = gtk_hbox_new (FALSE, 2);
800
gtk_box_pack_start (GTK_BOX (tab_widget), icon, FALSE, FALSE, 0);
801
gtk_widget_show (icon);
803
gtk_box_pack_start (GTK_BOX (tab_widget), label, FALSE, FALSE, 0);
804
gtk_widget_show (label);
812
gimp_dockable_set_context (GimpDockable *dockable,
813
GimpContext *context)
815
g_return_if_fail (GIMP_IS_DOCKABLE (dockable));
816
g_return_if_fail (context == NULL || GIMP_IS_CONTEXT (context));
818
if (context != dockable->context)
820
if (GTK_BIN (dockable)->child)
821
gimp_docked_set_context (GIMP_DOCKED (GTK_BIN (dockable)->child),
824
dockable->context = context;
829
gimp_dockable_get_menu (GimpDockable *dockable,
830
const gchar **ui_path,
831
gpointer *popup_data)
833
g_return_val_if_fail (GIMP_IS_DOCKABLE (dockable), NULL);
834
g_return_val_if_fail (ui_path != NULL, NULL);
835
g_return_val_if_fail (popup_data != NULL, NULL);
837
if (GTK_BIN (dockable)->child)
838
return gimp_docked_get_menu (GIMP_DOCKED (GTK_BIN (dockable)->child),
839
ui_path, popup_data);
845
gimp_dockable_detach (GimpDockable *dockable)
851
g_return_if_fail (GIMP_IS_DOCKABLE (dockable));
852
g_return_if_fail (GIMP_IS_DOCKBOOK (dockable->dockbook));
854
src_dock = dockable->dockbook->dock;
856
dock = gimp_dialog_factory_dock_new (src_dock->dialog_factory,
857
gtk_widget_get_screen (GTK_WIDGET (dockable)));
858
gimp_dock_setup (GIMP_DOCK (dock), src_dock);
860
dockbook = gimp_dockbook_new (GIMP_DOCK (dock)->dialog_factory->menu_factory);
862
gimp_dock_add_book (GIMP_DOCK (dock), GIMP_DOCKBOOK (dockbook), 0);
864
g_object_ref (dockable);
866
gimp_dockbook_remove (dockable->dockbook, dockable);
867
gimp_dockbook_add (GIMP_DOCKBOOK (dockbook), dockable, 0);
869
g_object_unref (dockable);
871
gtk_widget_show (dock);
875
gimp_dockable_get_title_area (GimpDockable *dockable,
878
GtkWidget *widget = GTK_WIDGET (dockable);
879
gint border = GTK_CONTAINER (dockable)->border_width;
881
area->x = widget->allocation.x + border;
882
area->y = widget->allocation.y + border;
883
area->width = (widget->allocation.width -
885
2 * dockable->close_button->allocation.width);
886
area->height = dockable->close_button->allocation.height;
888
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
889
area->x += 2 * dockable->close_button->allocation.width;
893
gimp_dockable_menu_button_press (GtkWidget *button,
894
GdkEventButton *bevent,
895
GimpDockable *dockable)
897
if (bevent->button == 1 && bevent->type == GDK_BUTTON_PRESS)
899
return gimp_dockable_show_menu (dockable);
906
gimp_dockable_close_clicked (GtkWidget *button,
907
GimpDockable *dockable)
909
gimp_dockbook_remove (dockable->dockbook, dockable);
913
gimp_dockable_menu_position (GtkMenu *menu,
918
GimpDockable *dockable = GIMP_DOCKABLE (data);
920
gimp_button_menu_position (dockable->menu_button, menu, GTK_POS_LEFT, x, y);
923
#define GIMP_DOCKABLE_DETACH_REF_KEY "gimp-dockable-detach-ref"
926
gimp_dockable_menu_end (GimpDockable *dockable)
928
GimpUIManager *dialog_ui_manager;
929
const gchar *dialog_ui_path;
930
gpointer dialog_popup_data;
932
dialog_ui_manager = gimp_dockable_get_menu (dockable,
936
if (dialog_ui_manager && dialog_ui_path)
938
GtkWidget *child_menu_widget;
940
child_menu_widget = gimp_ui_manager_ui_get (dialog_ui_manager,
943
if (child_menu_widget)
944
gtk_menu_detach (GTK_MENU (child_menu_widget));
947
/* release gimp_dockable_show_menu()'s references */
948
g_object_set_data (G_OBJECT (dockable), GIMP_DOCKABLE_DETACH_REF_KEY, NULL);
949
g_object_unref (dockable);
953
gimp_dockable_show_menu (GimpDockable *dockable)
955
GimpUIManager *dockbook_ui_manager = dockable->dockbook->ui_manager;
956
GimpUIManager *dialog_ui_manager;
957
const gchar *dialog_ui_path;
958
gpointer dialog_popup_data;
959
GtkWidget *parent_menu_widget;
960
GtkAction *parent_menu_action;
962
if (! dockbook_ui_manager)
966
gimp_ui_manager_ui_get (dockbook_ui_manager,
967
"/dockable-popup/dockable-menu");
970
gtk_ui_manager_get_action (GTK_UI_MANAGER (dockbook_ui_manager),
971
"/dockable-popup/dockable-menu");
973
if (! parent_menu_widget || ! parent_menu_action)
976
dialog_ui_manager = gimp_dockable_get_menu (dockable,
980
if (dialog_ui_manager && dialog_ui_path)
982
GtkWidget *child_menu_widget;
983
GtkAction *child_menu_action;
987
gimp_ui_manager_ui_get (dialog_ui_manager, dialog_ui_path);
990
gtk_ui_manager_get_action (GTK_UI_MANAGER (dialog_ui_manager),
993
if (! child_menu_widget || ! child_menu_action)
996
g_object_get (child_menu_action,
1000
g_object_set (parent_menu_action,
1002
"stock-id", dockable->stock_id,
1006
if (! GTK_IS_MENU (child_menu_widget))
1008
g_warning ("%s: child_menu_widget (%p) is not a GtkMenu",
1009
G_STRFUNC, child_menu_widget);
1015
GtkWidget *image = gtk_image_new_from_stock (dockable->stock_id,
1016
GTK_ICON_SIZE_MENU);
1018
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (parent_menu_widget),
1020
gtk_widget_show (image);
1023
gtk_menu_item_set_submenu (GTK_MENU_ITEM (parent_menu_widget),
1026
gimp_ui_manager_update (dialog_ui_manager, dialog_popup_data);
1030
g_object_set (parent_menu_action, "visible", FALSE, NULL);
1033
/* an action callback may destroy both dockable and dockbook, so
1034
* reference them for gimp_dockable_menu_end()
1036
g_object_ref (dockable);
1037
g_object_set_data_full (G_OBJECT (dockable), GIMP_DOCKABLE_DETACH_REF_KEY,
1038
g_object_ref (dockable->dockbook),
1041
gimp_ui_manager_update (dockbook_ui_manager, dockable);
1042
gimp_ui_manager_ui_popup (dockbook_ui_manager, "/dockable-popup",
1043
GTK_WIDGET (dockable),
1044
gimp_dockable_menu_position, dockable,
1045
(GtkDestroyNotify) gimp_dockable_menu_end, dockable);
1051
gimp_dockable_title_changed (GimpDocked *docked,
1052
GimpDockable *dockable)
1054
if (dockable->title_layout)
1056
g_object_unref (dockable->title_layout);
1057
dockable->title_layout = NULL;
1060
if (GTK_WIDGET (dockable)->window)
1062
GdkRectangle title_area;
1064
gimp_dockable_get_title_area (dockable, &title_area);
1066
gdk_window_invalidate_rect (GTK_WIDGET (dockable)->window,
1067
&title_area, FALSE);