1 /* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
2 /* GTK - The GIMP Toolkit
3 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
23 * file for a list of people on the GTK+ Team. See the ChangeLog
24 * files for a list of changes. These files are distributed with
25 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
29 #include "gtknotebook.h"
32 #include "gtkmenuitem.h"
34 #include <gdk/gdkkeysyms.h>
37 #include "gtkmarshalers.h"
38 #include "gtkbindings.h"
39 #include "gtkprivate.h"
43 #define SCROLL_DELAY_FACTOR 5
44 #define SCROLL_THRESHOLD 12
45 #define DND_THRESHOLD_MULTIPLIER 4
46 #define FRAMES_PER_SECOND 45
47 #define MSECS_BETWEEN_UPDATES (1000 / FRAMES_PER_SECOND)
81 } GtkNotebookPointerPosition;
86 DRAG_OPERATION_REORDER,
88 } GtkNotebookDragOperation;
90 #define ARROW_IS_LEFT(arrow) ((arrow) == ARROW_LEFT_BEFORE || (arrow) == ARROW_LEFT_AFTER)
91 #define ARROW_IS_BEFORE(arrow) ((arrow) == ARROW_LEFT_BEFORE || (arrow) == ARROW_RIGHT_BEFORE)
110 CHILD_PROP_TAB_LABEL,
111 CHILD_PROP_MENU_LABEL,
113 CHILD_PROP_TAB_EXPAND,
116 CHILD_PROP_REORDERABLE,
117 CHILD_PROP_DETACHABLE
120 #define GTK_NOTEBOOK_PAGE(_glist_) ((GtkNotebookPage *)((GList *)(_glist_))->data)
122 /* some useful defines for calculating coords */
123 #define PAGE_LEFT_X(_page_) (((GtkNotebookPage *) (_page_))->allocation.x)
124 #define PAGE_RIGHT_X(_page_) (((GtkNotebookPage *) (_page_))->allocation.x + ((GtkNotebookPage *) (_page_))->allocation.width)
125 #define PAGE_MIDDLE_X(_page_) (((GtkNotebookPage *) (_page_))->allocation.x + ((GtkNotebookPage *) (_page_))->allocation.width / 2)
126 #define PAGE_TOP_Y(_page_) (((GtkNotebookPage *) (_page_))->allocation.y)
127 #define PAGE_BOTTOM_Y(_page_) (((GtkNotebookPage *) (_page_))->allocation.y + ((GtkNotebookPage *) (_page_))->allocation.height)
128 #define PAGE_MIDDLE_Y(_page_) (((GtkNotebookPage *) (_page_))->allocation.y + ((GtkNotebookPage *) (_page_))->allocation.height / 2)
129 #define NOTEBOOK_IS_TAB_LABEL_PARENT(_notebook_,_page_) (((GtkNotebookPage *) (_page_))->tab_label->parent == ((GtkWidget *) (_notebook_)))
131 struct _GtkNotebookPage
134 GtkWidget *tab_label;
135 GtkWidget *menu_label;
136 GtkWidget *last_focus_child; /* Last descendant of the page that had focus */
138 guint default_menu : 1; /* If true, we create the menu label ourself */
139 guint default_tab : 1; /* If true, we create the tab label ourself */
143 guint reorderable : 1;
144 guint detachable : 1;
146 GtkRequisition requisition;
147 GtkAllocation allocation;
149 gulong mnemonic_activate_signal;
150 gulong notify_visible_handler;
153 #define GTK_NOTEBOOK_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_NOTEBOOK, GtkNotebookPrivate))
155 typedef struct _GtkNotebookPrivate GtkNotebookPrivate;
157 struct _GtkNotebookPrivate
164 guint switch_tab_timer;
172 GtkWidget *dnd_window;
173 GtkTargetList *source_targets;
174 GtkNotebookDragOperation operation;
175 GdkWindow *drag_window;
178 GtkNotebookPage *detached_tab;
182 guint during_reorder : 1;
183 guint during_detach : 1;
184 guint has_scrolled : 1;
187 static const GtkTargetEntry notebook_source_targets [] = {
188 { "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, 0 },
189 { "application/x-rootwindow-drop", 0, 1 }
192 static const GtkTargetEntry notebook_dest_targets[] = {
193 { "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, 0 }
196 #ifdef G_DISABLE_CHECKS
197 #define CHECK_FIND_CHILD(notebook, child) \
198 gtk_notebook_find_child (notebook, child, G_STRLOC)
200 #define CHECK_FIND_CHILD(notebook, child) \
201 gtk_notebook_find_child (notebook, child, NULL)
204 /*** GtkNotebook Methods ***/
205 static gboolean gtk_notebook_select_page (GtkNotebook *notebook,
206 gboolean move_focus);
207 static gboolean gtk_notebook_focus_tab (GtkNotebook *notebook,
208 GtkNotebookTab type);
209 static void gtk_notebook_change_current_page (GtkNotebook *notebook,
211 static void gtk_notebook_move_focus_out (GtkNotebook *notebook,
212 GtkDirectionType direction_type);
213 static void gtk_notebook_reorder_tab (GtkNotebook *notebook,
214 GtkDirectionType direction_type,
215 gboolean move_to_last);
217 /*** GtkObject Methods ***/
218 static void gtk_notebook_destroy (GtkObject *object);
219 static void gtk_notebook_set_property (GObject *object,
223 static void gtk_notebook_get_property (GObject *object,
228 /*** GtkWidget Methods ***/
229 static void gtk_notebook_map (GtkWidget *widget);
230 static void gtk_notebook_unmap (GtkWidget *widget);
231 static void gtk_notebook_realize (GtkWidget *widget);
232 static void gtk_notebook_unrealize (GtkWidget *widget);
233 static void gtk_notebook_size_request (GtkWidget *widget,
234 GtkRequisition *requisition);
235 static void gtk_notebook_size_allocate (GtkWidget *widget,
236 GtkAllocation *allocation);
237 static gint gtk_notebook_expose (GtkWidget *widget,
238 GdkEventExpose *event);
239 static gboolean gtk_notebook_scroll (GtkWidget *widget,
240 GdkEventScroll *event);
241 static gint gtk_notebook_button_press (GtkWidget *widget,
242 GdkEventButton *event);
243 static gint gtk_notebook_button_release (GtkWidget *widget,
244 GdkEventButton *event);
245 static gboolean gtk_notebook_popup_menu (GtkWidget *widget);
246 static gint gtk_notebook_leave_notify (GtkWidget *widget,
247 GdkEventCrossing *event);
248 static gint gtk_notebook_motion_notify (GtkWidget *widget,
249 GdkEventMotion *event);
250 static gint gtk_notebook_focus_in (GtkWidget *widget,
251 GdkEventFocus *event);
252 static gint gtk_notebook_focus_out (GtkWidget *widget,
253 GdkEventFocus *event);
254 static void gtk_notebook_grab_notify (GtkWidget *widget,
255 gboolean was_grabbed);
256 static void gtk_notebook_state_changed (GtkWidget *widget,
257 GtkStateType previous_state);
258 static void gtk_notebook_draw_focus (GtkWidget *widget);
259 static gint gtk_notebook_focus (GtkWidget *widget,
260 GtkDirectionType direction);
261 static void gtk_notebook_style_set (GtkWidget *widget,
264 /*** Drag and drop Methods ***/
265 static void gtk_notebook_drag_begin (GtkWidget *widget,
266 GdkDragContext *context);
267 static void gtk_notebook_drag_end (GtkWidget *widget,
268 GdkDragContext *context);
269 static gboolean gtk_notebook_drag_motion (GtkWidget *widget,
270 GdkDragContext *context,
274 static void gtk_notebook_drag_leave (GtkWidget *widget,
275 GdkDragContext *context,
277 static gboolean gtk_notebook_drag_drop (GtkWidget *widget,
278 GdkDragContext *context,
282 static void gtk_notebook_drag_data_get (GtkWidget *widget,
283 GdkDragContext *context,
284 GtkSelectionData *data,
287 static void gtk_notebook_drag_data_received (GtkWidget *widget,
288 GdkDragContext *context,
291 GtkSelectionData *data,
295 /*** GtkContainer Methods ***/
296 static void gtk_notebook_set_child_property (GtkContainer *container,
301 static void gtk_notebook_get_child_property (GtkContainer *container,
306 static void gtk_notebook_add (GtkContainer *container,
308 static void gtk_notebook_remove (GtkContainer *container,
310 static void gtk_notebook_set_focus_child (GtkContainer *container,
312 static GType gtk_notebook_child_type (GtkContainer *container);
313 static void gtk_notebook_forall (GtkContainer *container,
314 gboolean include_internals,
315 GtkCallback callback,
316 gpointer callback_data);
318 /*** GtkNotebook Methods ***/
319 static gint gtk_notebook_real_insert_page (GtkNotebook *notebook,
321 GtkWidget *tab_label,
322 GtkWidget *menu_label,
325 /*** GtkNotebook Private Functions ***/
326 static void gtk_notebook_redraw_tabs (GtkNotebook *notebook);
327 static void gtk_notebook_redraw_arrows (GtkNotebook *notebook);
328 static void gtk_notebook_real_remove (GtkNotebook *notebook,
330 static void gtk_notebook_update_labels (GtkNotebook *notebook);
331 static gint gtk_notebook_timer (GtkNotebook *notebook);
332 static void gtk_notebook_set_scroll_timer (GtkNotebook *notebook);
333 static gint gtk_notebook_page_compare (gconstpointer a,
335 static GList* gtk_notebook_find_child (GtkNotebook *notebook,
337 const gchar *function);
338 static gint gtk_notebook_real_page_position (GtkNotebook *notebook,
340 static GList * gtk_notebook_search_page (GtkNotebook *notebook,
343 gboolean find_visible);
345 /*** GtkNotebook Drawing Functions ***/
346 static void gtk_notebook_paint (GtkWidget *widget,
348 static void gtk_notebook_draw_tab (GtkNotebook *notebook,
349 GtkNotebookPage *page,
351 static void gtk_notebook_draw_arrow (GtkNotebook *notebook,
352 GtkNotebookArrow arrow);
354 /*** GtkNotebook Size Allocate Functions ***/
355 static void gtk_notebook_pages_allocate (GtkNotebook *notebook);
356 static void gtk_notebook_page_allocate (GtkNotebook *notebook,
357 GtkNotebookPage *page);
358 static void gtk_notebook_calc_tabs (GtkNotebook *notebook,
364 /*** GtkNotebook Page Switch Methods ***/
365 static void gtk_notebook_real_switch_page (GtkNotebook *notebook,
366 GtkNotebookPage *page,
369 /*** GtkNotebook Page Switch Functions ***/
370 static void gtk_notebook_switch_page (GtkNotebook *notebook,
371 GtkNotebookPage *page,
373 static gint gtk_notebook_page_select (GtkNotebook *notebook,
374 gboolean move_focus);
375 static void gtk_notebook_switch_focus_tab (GtkNotebook *notebook,
377 static void gtk_notebook_menu_switch_page (GtkWidget *widget,
378 GtkNotebookPage *page);
380 /*** GtkNotebook Menu Functions ***/
381 static void gtk_notebook_menu_item_create (GtkNotebook *notebook,
383 static void gtk_notebook_menu_label_unparent (GtkWidget *widget,
385 static void gtk_notebook_menu_detacher (GtkWidget *widget,
388 /*** GtkNotebook Private Setters ***/
389 static void gtk_notebook_set_homogeneous_tabs_internal (GtkNotebook *notebook,
390 gboolean homogeneous);
391 static void gtk_notebook_set_tab_border_internal (GtkNotebook *notebook,
393 static void gtk_notebook_set_tab_hborder_internal (GtkNotebook *notebook,
395 static void gtk_notebook_set_tab_vborder_internal (GtkNotebook *notebook,
398 static void gtk_notebook_update_tab_states (GtkNotebook *notebook);
399 static gboolean gtk_notebook_mnemonic_activate_switch_page (GtkWidget *child,
403 static gboolean focus_tabs_in (GtkNotebook *notebook);
404 static gboolean focus_child_in (GtkNotebook *notebook,
405 GtkDirectionType direction);
407 static void stop_scrolling (GtkNotebook *notebook);
410 static GtkNotebookWindowCreationFunc window_creation_hook = NULL;
411 static gpointer window_creation_hook_data;
412 static GDestroyNotify window_creation_hook_destroy = NULL;
414 static guint notebook_signals[LAST_SIGNAL] = { 0 };
416 G_DEFINE_TYPE (GtkNotebook, gtk_notebook, GTK_TYPE_CONTAINER)
419 add_tab_bindings (GtkBindingSet *binding_set,
420 GdkModifierType modifiers,
421 GtkDirectionType direction)
423 gtk_binding_entry_add_signal (binding_set, GDK_Tab, modifiers,
425 GTK_TYPE_DIRECTION_TYPE, direction);
426 gtk_binding_entry_add_signal (binding_set, GDK_KP_Tab, modifiers,
428 GTK_TYPE_DIRECTION_TYPE, direction);
432 add_arrow_bindings (GtkBindingSet *binding_set,
434 GtkDirectionType direction)
436 guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
438 gtk_binding_entry_add_signal (binding_set, keysym, GDK_CONTROL_MASK,
440 GTK_TYPE_DIRECTION_TYPE, direction);
441 gtk_binding_entry_add_signal (binding_set, keypad_keysym, GDK_CONTROL_MASK,
443 GTK_TYPE_DIRECTION_TYPE, direction);
447 add_reorder_bindings (GtkBindingSet *binding_set,
449 GtkDirectionType direction,
450 gboolean move_to_last)
452 guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
454 gtk_binding_entry_add_signal (binding_set, keysym, GDK_MOD1_MASK,
456 GTK_TYPE_DIRECTION_TYPE, direction,
457 G_TYPE_BOOLEAN, move_to_last);
458 gtk_binding_entry_add_signal (binding_set, keypad_keysym, GDK_MOD1_MASK,
460 GTK_TYPE_DIRECTION_TYPE, direction,
461 G_TYPE_BOOLEAN, move_to_last);
465 gtk_notebook_class_init (GtkNotebookClass *class)
467 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
468 GtkObjectClass *object_class = GTK_OBJECT_CLASS (class);
469 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
470 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
471 GtkBindingSet *binding_set;
473 gobject_class->set_property = gtk_notebook_set_property;
474 gobject_class->get_property = gtk_notebook_get_property;
475 object_class->destroy = gtk_notebook_destroy;
477 widget_class->map = gtk_notebook_map;
478 widget_class->unmap = gtk_notebook_unmap;
479 widget_class->realize = gtk_notebook_realize;
480 widget_class->unrealize = gtk_notebook_unrealize;
481 widget_class->size_request = gtk_notebook_size_request;
482 widget_class->size_allocate = gtk_notebook_size_allocate;
483 widget_class->expose_event = gtk_notebook_expose;
484 widget_class->scroll_event = gtk_notebook_scroll;
485 widget_class->button_press_event = gtk_notebook_button_press;
486 widget_class->button_release_event = gtk_notebook_button_release;
487 widget_class->popup_menu = gtk_notebook_popup_menu;
488 widget_class->leave_notify_event = gtk_notebook_leave_notify;
489 widget_class->motion_notify_event = gtk_notebook_motion_notify;
490 widget_class->grab_notify = gtk_notebook_grab_notify;
491 widget_class->state_changed = gtk_notebook_state_changed;
492 widget_class->focus_in_event = gtk_notebook_focus_in;
493 widget_class->focus_out_event = gtk_notebook_focus_out;
494 widget_class->focus = gtk_notebook_focus;
495 widget_class->style_set = gtk_notebook_style_set;
496 widget_class->drag_begin = gtk_notebook_drag_begin;
497 widget_class->drag_end = gtk_notebook_drag_end;
498 widget_class->drag_motion = gtk_notebook_drag_motion;
499 widget_class->drag_leave = gtk_notebook_drag_leave;
500 widget_class->drag_drop = gtk_notebook_drag_drop;
501 widget_class->drag_data_get = gtk_notebook_drag_data_get;
502 widget_class->drag_data_received = gtk_notebook_drag_data_received;
504 container_class->add = gtk_notebook_add;
505 container_class->remove = gtk_notebook_remove;
506 container_class->forall = gtk_notebook_forall;
507 container_class->set_focus_child = gtk_notebook_set_focus_child;
508 container_class->get_child_property = gtk_notebook_get_child_property;
509 container_class->set_child_property = gtk_notebook_set_child_property;
510 container_class->child_type = gtk_notebook_child_type;
512 class->switch_page = gtk_notebook_real_switch_page;
513 class->insert_page = gtk_notebook_real_insert_page;
515 class->focus_tab = gtk_notebook_focus_tab;
516 class->select_page = gtk_notebook_select_page;
517 class->change_current_page = gtk_notebook_change_current_page;
518 class->move_focus_out = gtk_notebook_move_focus_out;
519 class->reorder_tab = gtk_notebook_reorder_tab;
521 g_object_class_install_property (gobject_class,
523 g_param_spec_int ("page",
525 P_("The index of the current page"),
529 GTK_PARAM_READWRITE));
530 g_object_class_install_property (gobject_class,
532 g_param_spec_enum ("tab-pos",
534 P_("Which side of the notebook holds the tabs"),
535 GTK_TYPE_POSITION_TYPE,
537 GTK_PARAM_READWRITE));
538 g_object_class_install_property (gobject_class,
540 g_param_spec_uint ("tab-border",
542 P_("Width of the border around the tab labels"),
546 GTK_PARAM_WRITABLE));
547 g_object_class_install_property (gobject_class,
549 g_param_spec_uint ("tab-hborder",
550 P_("Horizontal Tab Border"),
551 P_("Width of the horizontal border of tab labels"),
555 GTK_PARAM_READWRITE));
556 g_object_class_install_property (gobject_class,
558 g_param_spec_uint ("tab-vborder",
559 P_("Vertical Tab Border"),
560 P_("Width of the vertical border of tab labels"),
564 GTK_PARAM_READWRITE));
565 g_object_class_install_property (gobject_class,
567 g_param_spec_boolean ("show-tabs",
569 P_("Whether tabs should be shown or not"),
571 GTK_PARAM_READWRITE));
572 g_object_class_install_property (gobject_class,
574 g_param_spec_boolean ("show-border",
576 P_("Whether the border should be shown or not"),
578 GTK_PARAM_READWRITE));
579 g_object_class_install_property (gobject_class,
581 g_param_spec_boolean ("scrollable",
583 P_("If TRUE, scroll arrows are added if there are too many tabs to fit"),
585 GTK_PARAM_READWRITE));
586 g_object_class_install_property (gobject_class,
588 g_param_spec_boolean ("enable-popup",
590 P_("If TRUE, pressing the right mouse button on the notebook pops up a menu that you can use to go to a page"),
592 GTK_PARAM_READWRITE));
593 g_object_class_install_property (gobject_class,
595 g_param_spec_boolean ("homogeneous",
597 P_("Whether tabs should have homogeneous sizes"),
599 GTK_PARAM_READWRITE));
600 g_object_class_install_property (gobject_class,
602 g_param_spec_int ("group-id",
604 P_("Group ID for tabs drag and drop"),
608 GTK_PARAM_READWRITE));
610 gtk_container_class_install_child_property (container_class,
611 CHILD_PROP_TAB_LABEL,
612 g_param_spec_string ("tab-label",
614 P_("The string displayed on the child's tab label"),
616 GTK_PARAM_READWRITE));
617 gtk_container_class_install_child_property (container_class,
618 CHILD_PROP_MENU_LABEL,
619 g_param_spec_string ("menu-label",
621 P_("The string displayed in the child's menu entry"),
623 GTK_PARAM_READWRITE));
624 gtk_container_class_install_child_property (container_class,
626 g_param_spec_int ("position",
628 P_("The index of the child in the parent"),
630 GTK_PARAM_READWRITE));
631 gtk_container_class_install_child_property (container_class,
632 CHILD_PROP_TAB_EXPAND,
633 g_param_spec_boolean ("tab-expand",
635 P_("Whether to expand the child's tab or not"),
637 GTK_PARAM_READWRITE));
638 gtk_container_class_install_child_property (container_class,
640 g_param_spec_boolean ("tab-fill",
642 P_("Whether the child's tab should fill the allocated area or not"),
644 GTK_PARAM_READWRITE));
645 gtk_container_class_install_child_property (container_class,
647 g_param_spec_enum ("tab-pack",
649 P_("A GtkPackType indicating whether the child is packed with reference to the start or end of the parent"),
650 GTK_TYPE_PACK_TYPE, GTK_PACK_START,
651 GTK_PARAM_READWRITE));
652 gtk_container_class_install_child_property (container_class,
653 CHILD_PROP_REORDERABLE,
654 g_param_spec_boolean ("reorderable",
655 P_("Tab reorderable"),
656 P_("Whether the tab is reorderable by user action or not"),
658 GTK_PARAM_READWRITE));
659 gtk_container_class_install_child_property (container_class,
660 CHILD_PROP_DETACHABLE,
661 g_param_spec_boolean ("detachable",
662 P_("Tab detachable"),
663 P_("Whether the tab is detachable"),
665 GTK_PARAM_READWRITE));
668 * GtkNotebook:has-secondary-backward-stepper:
670 * The "has-secondary-backward-stepper" property determines whether
671 * a second backward arrow button is displayed on the opposite end
676 gtk_widget_class_install_style_property (widget_class,
677 g_param_spec_boolean ("has-secondary-backward-stepper",
678 P_("Secondary backward stepper"),
679 P_("Display a second backward arrow button on the opposite end of the tab area"),
681 GTK_PARAM_READABLE));
684 * GtkNotebook:has-secondary-forward-stepper:
686 * The "has-secondary-forward-stepper" property determines whether
687 * a second forward arrow button is displayed on the opposite end
692 gtk_widget_class_install_style_property (widget_class,
693 g_param_spec_boolean ("has-secondary-forward-stepper",
694 P_("Secondary forward stepper"),
695 P_("Display a second forward arrow button on the opposite end of the tab area"),
697 GTK_PARAM_READABLE));
700 * GtkNotebook:has-backward-stepper:
702 * The "has-backward-stepper" property determines whether
703 * the standard backward arrow button is displayed.
707 gtk_widget_class_install_style_property (widget_class,
708 g_param_spec_boolean ("has-backward-stepper",
709 P_("Backward stepper"),
710 P_("Display the standard backward arrow button"),
712 GTK_PARAM_READABLE));
715 * GtkNotebook:has-forward-stepper:
717 * The "has-forward-stepper" property determines whether
718 * the standard forward arrow button is displayed.
722 gtk_widget_class_install_style_property (widget_class,
723 g_param_spec_boolean ("has-forward-stepper",
724 P_("Forward stepper"),
725 P_("Display the standard forward arrow button"),
727 GTK_PARAM_READABLE));
730 * GtkNotebook:tab-overlap:
732 * The "tab-overlap" property defines size of tab overlap
737 gtk_widget_class_install_style_property (widget_class,
738 g_param_spec_int ("tab-overlap",
740 P_("Size of tab overlap area"),
744 GTK_PARAM_READABLE));
747 * GtkNotebook:tab-curvature:
749 * The "tab-curvature" property defines size of tab curvature.
753 gtk_widget_class_install_style_property (widget_class,
754 g_param_spec_int ("tab-curvature",
756 P_("Size of tab curvature"),
760 GTK_PARAM_READABLE));
763 * GtkNotebook:arrow-spacing:
765 * The "arrow-size" property defines the spacing between the scroll
766 * arrows and the tabs.
770 gtk_widget_class_install_style_property (widget_class,
771 g_param_spec_int ("arrow-spacing",
773 _("Scroll arrow spacing"),
777 GTK_PARAM_READABLE));
779 notebook_signals[SWITCH_PAGE] =
780 g_signal_new (I_("switch_page"),
781 G_TYPE_FROM_CLASS (gobject_class),
783 G_STRUCT_OFFSET (GtkNotebookClass, switch_page),
785 _gtk_marshal_VOID__POINTER_UINT,
789 notebook_signals[FOCUS_TAB] =
790 g_signal_new (I_("focus_tab"),
791 G_TYPE_FROM_CLASS (gobject_class),
792 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
793 G_STRUCT_OFFSET (GtkNotebookClass, focus_tab),
795 _gtk_marshal_BOOLEAN__ENUM,
797 GTK_TYPE_NOTEBOOK_TAB);
798 notebook_signals[SELECT_PAGE] =
799 g_signal_new (I_("select_page"),
800 G_TYPE_FROM_CLASS (gobject_class),
801 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
802 G_STRUCT_OFFSET (GtkNotebookClass, select_page),
804 _gtk_marshal_BOOLEAN__BOOLEAN,
807 notebook_signals[CHANGE_CURRENT_PAGE] =
808 g_signal_new (I_("change_current_page"),
809 G_TYPE_FROM_CLASS (gobject_class),
810 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
811 G_STRUCT_OFFSET (GtkNotebookClass, change_current_page),
813 _gtk_marshal_VOID__INT,
816 notebook_signals[MOVE_FOCUS_OUT] =
817 g_signal_new (I_("move_focus_out"),
818 G_TYPE_FROM_CLASS (gobject_class),
819 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
820 G_STRUCT_OFFSET (GtkNotebookClass, move_focus_out),
822 _gtk_marshal_VOID__ENUM,
824 GTK_TYPE_DIRECTION_TYPE);
825 notebook_signals[REORDER_TAB] =
826 g_signal_new (I_("reorder_tab"),
827 G_TYPE_FROM_CLASS (gobject_class),
828 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
829 G_STRUCT_OFFSET (GtkNotebookClass, reorder_tab),
831 _gtk_marshal_VOID__ENUM_BOOLEAN,
833 GTK_TYPE_DIRECTION_TYPE,
836 * GtkNotebook::page-reordered:
837 * @notebook: the #GtkNotebook
838 * @child: the child #GtkWidget affected
839 * @page_num: the new page number for @child
841 * the ::page-reordered signal is emitted in the notebook
842 * right after a page has been reordered.
846 notebook_signals[PAGE_REORDERED] =
847 g_signal_new (I_("page_reordered"),
848 G_TYPE_FROM_CLASS (gobject_class),
851 _gtk_marshal_VOID__OBJECT_UINT,
856 * GtkNotebook::page-removed:
857 * @notebook: the #GtkNotebook
858 * @child: the child #GtkWidget affected
859 * @page_num: the @child page number
861 * the ::page-removed signal is emitted in the notebook
862 * right after a page is removed from the notebook.
866 notebook_signals[PAGE_REMOVED] =
867 g_signal_new (I_("page_removed"),
868 G_TYPE_FROM_CLASS (gobject_class),
871 _gtk_marshal_VOID__OBJECT_UINT,
876 * GtkNotebook::page-added:
877 * @notebook: the #GtkNotebook
878 * @child: the child #GtkWidget affected
879 * @page_num: the new page number for @child
881 * the ::page-added signal is emitted in the notebook
882 * right after a page is added to the notebook.
886 notebook_signals[PAGE_ADDED] =
887 g_signal_new (I_("page_added"),
888 G_TYPE_FROM_CLASS (gobject_class),
891 _gtk_marshal_VOID__OBJECT_UINT,
896 binding_set = gtk_binding_set_by_class (class);
897 gtk_binding_entry_add_signal (binding_set,
900 G_TYPE_BOOLEAN, FALSE);
901 gtk_binding_entry_add_signal (binding_set,
904 G_TYPE_BOOLEAN, FALSE);
906 gtk_binding_entry_add_signal (binding_set,
909 GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_FIRST);
910 gtk_binding_entry_add_signal (binding_set,
913 GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_FIRST);
914 gtk_binding_entry_add_signal (binding_set,
917 GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_LAST);
918 gtk_binding_entry_add_signal (binding_set,
921 GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_LAST);
923 gtk_binding_entry_add_signal (binding_set,
924 GDK_Page_Up, GDK_CONTROL_MASK,
925 "change_current_page", 1,
927 gtk_binding_entry_add_signal (binding_set,
928 GDK_Page_Down, GDK_CONTROL_MASK,
929 "change_current_page", 1,
932 gtk_binding_entry_add_signal (binding_set,
933 GDK_Page_Up, GDK_CONTROL_MASK | GDK_MOD1_MASK,
934 "change_current_page", 1,
936 gtk_binding_entry_add_signal (binding_set,
937 GDK_Page_Down, GDK_CONTROL_MASK | GDK_MOD1_MASK,
938 "change_current_page", 1,
941 add_arrow_bindings (binding_set, GDK_Up, GTK_DIR_UP);
942 add_arrow_bindings (binding_set, GDK_Down, GTK_DIR_DOWN);
943 add_arrow_bindings (binding_set, GDK_Left, GTK_DIR_LEFT);
944 add_arrow_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT);
946 add_reorder_bindings (binding_set, GDK_Up, GTK_DIR_UP, FALSE);
947 add_reorder_bindings (binding_set, GDK_Down, GTK_DIR_DOWN, FALSE);
948 add_reorder_bindings (binding_set, GDK_Left, GTK_DIR_LEFT, FALSE);
949 add_reorder_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT, FALSE);
950 add_reorder_bindings (binding_set, GDK_Home, GTK_DIR_LEFT, TRUE);
951 add_reorder_bindings (binding_set, GDK_Home, GTK_DIR_UP, TRUE);
952 add_reorder_bindings (binding_set, GDK_End, GTK_DIR_RIGHT, TRUE);
953 add_reorder_bindings (binding_set, GDK_End, GTK_DIR_DOWN, TRUE);
955 add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
956 add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
958 g_type_class_add_private (class, sizeof (GtkNotebookPrivate));
962 gtk_notebook_init (GtkNotebook *notebook)
964 GtkNotebookPrivate *priv;
966 GTK_WIDGET_SET_FLAGS (notebook, GTK_CAN_FOCUS);
967 GTK_WIDGET_SET_FLAGS (notebook, GTK_NO_WINDOW);
969 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
971 notebook->cur_page = NULL;
972 notebook->children = NULL;
973 notebook->first_tab = NULL;
974 notebook->focus_tab = NULL;
975 notebook->event_window = NULL;
976 notebook->menu = NULL;
978 notebook->tab_hborder = 2;
979 notebook->tab_vborder = 2;
981 notebook->show_tabs = TRUE;
982 notebook->show_border = TRUE;
983 notebook->tab_pos = GTK_POS_TOP;
984 notebook->scrollable = FALSE;
985 notebook->in_child = 0;
986 notebook->click_child = 0;
987 notebook->button = 0;
988 notebook->need_timer = 0;
989 notebook->child_has_focus = FALSE;
990 notebook->have_visible_child = FALSE;
991 notebook->focus_out = FALSE;
993 notebook->has_before_previous = 1;
994 notebook->has_before_next = 0;
995 notebook->has_after_previous = 0;
996 notebook->has_after_next = 1;
999 priv->pressed_button = -1;
1000 priv->dnd_timer = 0;
1001 priv->switch_tab_timer = 0;
1002 priv->source_targets = gtk_target_list_new (notebook_source_targets,
1003 G_N_ELEMENTS (notebook_source_targets));
1004 priv->operation = DRAG_OPERATION_NONE;
1005 priv->detached_tab = NULL;
1006 priv->during_detach = FALSE;
1007 priv->has_scrolled = FALSE;
1009 gtk_drag_dest_set (GTK_WIDGET (notebook),
1010 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP,
1011 notebook_dest_targets, G_N_ELEMENTS (notebook_dest_targets),
1014 gtk_drag_dest_set_track_motion (GTK_WIDGET (notebook), TRUE);
1018 gtk_notebook_select_page (GtkNotebook *notebook,
1019 gboolean move_focus)
1021 if (gtk_widget_is_focus (GTK_WIDGET (notebook)))
1023 gtk_notebook_page_select (notebook, move_focus);
1031 gtk_notebook_focus_tab (GtkNotebook *notebook,
1032 GtkNotebookTab type)
1036 if (gtk_widget_is_focus (GTK_WIDGET (notebook)))
1040 case GTK_NOTEBOOK_TAB_FIRST:
1041 list = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, TRUE);
1043 gtk_notebook_switch_focus_tab (notebook, list);
1045 case GTK_NOTEBOOK_TAB_LAST:
1046 list = gtk_notebook_search_page (notebook, NULL, STEP_PREV, TRUE);
1048 gtk_notebook_switch_focus_tab (notebook, list);
1059 gtk_notebook_change_current_page (GtkNotebook *notebook,
1062 GList *current = NULL;
1064 if (notebook->cur_page)
1065 current = g_list_find (notebook->children, notebook->cur_page);
1069 current = gtk_notebook_search_page (notebook, current,
1070 offset < 0 ? STEP_PREV : STEP_NEXT,
1075 gboolean wrap_around;
1077 g_object_get (gtk_widget_get_settings (GTK_WIDGET (notebook)),
1078 "gtk-keynav-wrap-around", &wrap_around,
1082 current = gtk_notebook_search_page (notebook, NULL,
1083 offset < 0 ? STEP_PREV : STEP_NEXT,
1089 offset += offset < 0 ? 1 : -1;
1093 gtk_notebook_switch_page (notebook, current->data, -1);
1095 gtk_widget_error_bell (GTK_WIDGET (notebook));
1098 static GtkDirectionType
1099 get_effective_direction (GtkNotebook *notebook,
1100 GtkDirectionType direction)
1102 /* Remap the directions into the effective direction it would be for a
1103 * GTK_POS_TOP notebook
1106 #define D(rest) GTK_DIR_##rest
1108 static const GtkDirectionType translate_direction[2][4][6] = {
1109 /* LEFT */ {{ D(TAB_FORWARD), D(TAB_BACKWARD), D(LEFT), D(RIGHT), D(UP), D(DOWN) },
1110 /* RIGHT */ { D(TAB_BACKWARD), D(TAB_FORWARD), D(LEFT), D(RIGHT), D(DOWN), D(UP) },
1111 /* TOP */ { D(TAB_FORWARD), D(TAB_BACKWARD), D(UP), D(DOWN), D(LEFT), D(RIGHT) },
1112 /* BOTTOM */ { D(TAB_BACKWARD), D(TAB_FORWARD), D(DOWN), D(UP), D(LEFT), D(RIGHT) }},
1113 /* LEFT */ {{ D(TAB_BACKWARD), D(TAB_FORWARD), D(LEFT), D(RIGHT), D(DOWN), D(UP) },
1114 /* RIGHT */ { D(TAB_FORWARD), D(TAB_BACKWARD), D(LEFT), D(RIGHT), D(UP), D(DOWN) },
1115 /* TOP */ { D(TAB_FORWARD), D(TAB_BACKWARD), D(UP), D(DOWN), D(RIGHT), D(LEFT) },
1116 /* BOTTOM */ { D(TAB_BACKWARD), D(TAB_FORWARD), D(DOWN), D(UP), D(RIGHT), D(LEFT) }},
1121 int text_dir = gtk_widget_get_direction (GTK_WIDGET (notebook)) == GTK_TEXT_DIR_RTL ? 1 : 0;
1123 return translate_direction[text_dir][notebook->tab_pos][direction];
1127 get_effective_tab_pos (GtkNotebook *notebook)
1129 if (gtk_widget_get_direction (GTK_WIDGET (notebook)) == GTK_TEXT_DIR_RTL)
1131 switch (notebook->tab_pos)
1134 return GTK_POS_RIGHT;
1136 return GTK_POS_LEFT;
1141 return notebook->tab_pos;
1145 get_tab_gap_pos (GtkNotebook *notebook)
1147 gint tab_pos = get_effective_tab_pos (notebook);
1148 gint gap_side = GTK_POS_BOTTOM;
1153 gap_side = GTK_POS_BOTTOM;
1155 case GTK_POS_BOTTOM:
1156 gap_side = GTK_POS_TOP;
1159 gap_side = GTK_POS_RIGHT;
1162 gap_side = GTK_POS_LEFT;
1170 gtk_notebook_move_focus_out (GtkNotebook *notebook,
1171 GtkDirectionType direction_type)
1173 GtkDirectionType effective_direction = get_effective_direction (notebook, direction_type);
1174 GtkWidget *toplevel;
1176 if (GTK_CONTAINER (notebook)->focus_child && effective_direction == GTK_DIR_UP)
1177 if (focus_tabs_in (notebook))
1179 if (gtk_widget_is_focus (GTK_WIDGET (notebook)) && effective_direction == GTK_DIR_DOWN)
1180 if (focus_child_in (notebook, GTK_DIR_TAB_FORWARD))
1183 /* At this point, we know we should be focusing out of the notebook entirely. We
1184 * do this by setting a flag, then propagating the focus motion to the notebook.
1186 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (notebook));
1187 if (!GTK_WIDGET_TOPLEVEL (toplevel))
1190 g_object_ref (notebook);
1192 notebook->focus_out = TRUE;
1193 g_signal_emit_by_name (toplevel, "move_focus", direction_type);
1194 notebook->focus_out = FALSE;
1196 g_object_unref (notebook);
1200 reorder_tab (GtkNotebook *notebook, GList *position, GList *tab)
1204 if (position == tab)
1205 return g_list_position (notebook->children, tab);
1207 /* check that we aren't inserting the tab in the
1208 * same relative position, taking packing into account */
1209 elem = (position) ? position->prev : g_list_last (notebook->children);
1211 while (elem && elem != tab && GTK_NOTEBOOK_PAGE (elem)->pack != GTK_NOTEBOOK_PAGE (tab)->pack)
1215 return g_list_position (notebook->children, tab);
1217 /* now actually reorder the tab */
1218 if (notebook->first_tab == tab)
1219 notebook->first_tab = gtk_notebook_search_page (notebook, notebook->first_tab,
1222 notebook->children = g_list_remove_link (notebook->children, tab);
1225 elem = g_list_last (notebook->children);
1228 elem = position->prev;
1229 position->prev = tab;
1235 notebook->children = tab;
1238 tab->next = position;
1240 return g_list_position (notebook->children, tab);
1244 gtk_notebook_reorder_tab (GtkNotebook *notebook,
1245 GtkDirectionType direction_type,
1246 gboolean move_to_last)
1248 GtkDirectionType effective_direction = get_effective_direction (notebook, direction_type);
1249 GtkNotebookPage *page;
1250 GList *last, *child;
1253 if (!gtk_widget_is_focus (GTK_WIDGET (notebook)))
1256 if (!notebook->cur_page ||
1257 !notebook->cur_page->reorderable)
1260 if (effective_direction != GTK_DIR_LEFT &&
1261 effective_direction != GTK_DIR_RIGHT)
1266 child = notebook->focus_tab;
1271 child = gtk_notebook_search_page (notebook, last,
1272 (effective_direction == GTK_DIR_RIGHT) ? STEP_NEXT : STEP_PREV,
1275 while (child && GTK_NOTEBOOK_PAGE (last)->pack == GTK_NOTEBOOK_PAGE (child)->pack);
1280 child = gtk_notebook_search_page (notebook, notebook->focus_tab,
1281 (effective_direction == GTK_DIR_RIGHT) ? STEP_NEXT : STEP_PREV,
1284 if (!child || child->data == notebook->cur_page)
1289 if (page->pack == notebook->cur_page->pack)
1291 if (effective_direction == GTK_DIR_RIGHT)
1292 page_num = reorder_tab (notebook, (page->pack == GTK_PACK_START) ? child->next : child, notebook->focus_tab);
1294 page_num = reorder_tab (notebook, (page->pack == GTK_PACK_START) ? child : child->next, notebook->focus_tab);
1296 gtk_notebook_pages_allocate (notebook);
1298 g_signal_emit (notebook,
1299 notebook_signals[PAGE_REORDERED],
1301 ((GtkNotebookPage *) notebook->focus_tab->data)->child,
1309 * Creates a new #GtkNotebook widget with no pages.
1311 * Return value: the newly created #GtkNotebook
1314 gtk_notebook_new (void)
1316 return g_object_new (GTK_TYPE_NOTEBOOK, NULL);
1319 /* Private GtkObject Methods :
1321 * gtk_notebook_destroy
1322 * gtk_notebook_set_arg
1323 * gtk_notebook_get_arg
1326 gtk_notebook_destroy (GtkObject *object)
1328 GtkNotebook *notebook = GTK_NOTEBOOK (object);
1329 GtkNotebookPrivate *priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
1332 gtk_notebook_popup_disable (notebook);
1334 if (priv->source_targets)
1336 gtk_target_list_unref (priv->source_targets);
1337 priv->source_targets = NULL;
1340 if (priv->switch_tab_timer)
1342 g_source_remove (priv->switch_tab_timer);
1343 priv->switch_tab_timer = 0;
1346 GTK_OBJECT_CLASS (gtk_notebook_parent_class)->destroy (object);
1350 gtk_notebook_set_property (GObject *object,
1352 const GValue *value,
1355 GtkNotebook *notebook;
1357 notebook = GTK_NOTEBOOK (object);
1361 case PROP_SHOW_TABS:
1362 gtk_notebook_set_show_tabs (notebook, g_value_get_boolean (value));
1364 case PROP_SHOW_BORDER:
1365 gtk_notebook_set_show_border (notebook, g_value_get_boolean (value));
1367 case PROP_SCROLLABLE:
1368 gtk_notebook_set_scrollable (notebook, g_value_get_boolean (value));
1370 case PROP_ENABLE_POPUP:
1371 if (g_value_get_boolean (value))
1372 gtk_notebook_popup_enable (notebook);
1374 gtk_notebook_popup_disable (notebook);
1376 case PROP_HOMOGENEOUS:
1377 gtk_notebook_set_homogeneous_tabs_internal (notebook, g_value_get_boolean (value));
1380 gtk_notebook_set_current_page (notebook, g_value_get_int (value));
1383 gtk_notebook_set_tab_pos (notebook, g_value_get_enum (value));
1385 case PROP_TAB_BORDER:
1386 gtk_notebook_set_tab_border_internal (notebook, g_value_get_uint (value));
1388 case PROP_TAB_HBORDER:
1389 gtk_notebook_set_tab_hborder_internal (notebook, g_value_get_uint (value));
1391 case PROP_TAB_VBORDER:
1392 gtk_notebook_set_tab_vborder_internal (notebook, g_value_get_uint (value));
1395 gtk_notebook_set_group_id (notebook, g_value_get_int (value));
1403 gtk_notebook_get_property (GObject *object,
1408 GtkNotebook *notebook;
1409 GtkNotebookPrivate *priv;
1411 notebook = GTK_NOTEBOOK (object);
1412 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
1416 case PROP_SHOW_TABS:
1417 g_value_set_boolean (value, notebook->show_tabs);
1419 case PROP_SHOW_BORDER:
1420 g_value_set_boolean (value, notebook->show_border);
1422 case PROP_SCROLLABLE:
1423 g_value_set_boolean (value, notebook->scrollable);
1425 case PROP_ENABLE_POPUP:
1426 g_value_set_boolean (value, notebook->menu != NULL);
1428 case PROP_HOMOGENEOUS:
1429 g_value_set_boolean (value, notebook->homogeneous);
1432 g_value_set_int (value, gtk_notebook_get_current_page (notebook));
1435 g_value_set_enum (value, notebook->tab_pos);
1437 case PROP_TAB_HBORDER:
1438 g_value_set_uint (value, notebook->tab_hborder);
1440 case PROP_TAB_VBORDER:
1441 g_value_set_uint (value, notebook->tab_vborder);
1444 g_value_set_int (value, priv->group_id);
1447 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1452 /* Private GtkWidget Methods :
1455 * gtk_notebook_unmap
1456 * gtk_notebook_realize
1457 * gtk_notebook_size_request
1458 * gtk_notebook_size_allocate
1459 * gtk_notebook_expose
1460 * gtk_notebook_scroll
1461 * gtk_notebook_button_press
1462 * gtk_notebook_button_release
1463 * gtk_notebook_popup_menu
1464 * gtk_notebook_leave_notify
1465 * gtk_notebook_motion_notify
1466 * gtk_notebook_focus_in
1467 * gtk_notebook_focus_out
1468 * gtk_notebook_draw_focus
1469 * gtk_notebook_style_set
1470 * gtk_notebook_drag_begin
1471 * gtk_notebook_drag_end
1472 * gtk_notebook_drag_motion
1473 * gtk_notebook_drag_drop
1474 * gtk_notebook_drag_data_get
1475 * gtk_notebook_drag_data_received
1478 gtk_notebook_get_event_window_position (GtkNotebook *notebook,
1479 GdkRectangle *rectangle)
1481 GtkWidget *widget = GTK_WIDGET (notebook);
1482 gint border_width = GTK_CONTAINER (notebook)->border_width;
1483 GtkNotebookPage *visible_page = NULL;
1485 gint tab_pos = get_effective_tab_pos (notebook);
1487 for (tmp_list = notebook->children; tmp_list; tmp_list = tmp_list->next)
1489 GtkNotebookPage *page = tmp_list->data;
1490 if (GTK_WIDGET_VISIBLE (page->child))
1492 visible_page = page;
1497 if (notebook->show_tabs && visible_page)
1501 rectangle->x = widget->allocation.x + border_width;
1502 rectangle->y = widget->allocation.y + border_width;
1507 case GTK_POS_BOTTOM:
1508 rectangle->width = widget->allocation.width - 2 * border_width;
1509 rectangle->height = visible_page->requisition.height;
1510 if (tab_pos == GTK_POS_BOTTOM)
1511 rectangle->y += widget->allocation.height - 2 * border_width - rectangle->height;
1515 rectangle->width = visible_page->requisition.width;
1516 rectangle->height = widget->allocation.height - 2 * border_width;
1517 if (tab_pos == GTK_POS_RIGHT)
1518 rectangle->x += widget->allocation.width - 2 * border_width - rectangle->width;
1529 rectangle->x = rectangle->y = 0;
1530 rectangle->width = rectangle->height = 10;
1538 gtk_notebook_map (GtkWidget *widget)
1540 GtkNotebook *notebook;
1541 GtkNotebookPage *page;
1544 g_return_if_fail (GTK_IS_NOTEBOOK (widget));
1546 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
1548 notebook = GTK_NOTEBOOK (widget);
1550 if (notebook->cur_page &&
1551 GTK_WIDGET_VISIBLE (notebook->cur_page->child) &&
1552 !GTK_WIDGET_MAPPED (notebook->cur_page->child))
1553 gtk_widget_map (notebook->cur_page->child);
1555 if (notebook->scrollable)
1556 gtk_notebook_pages_allocate (notebook);
1559 children = notebook->children;
1563 page = children->data;
1564 children = children->next;
1566 if (page->tab_label &&
1567 GTK_WIDGET_VISIBLE (page->tab_label) &&
1568 !GTK_WIDGET_MAPPED (page->tab_label))
1569 gtk_widget_map (page->tab_label);
1573 if (gtk_notebook_get_event_window_position (notebook, NULL))
1574 gdk_window_show_unraised (notebook->event_window);
1578 gtk_notebook_unmap (GtkWidget *widget)
1580 g_return_if_fail (GTK_IS_NOTEBOOK (widget));
1582 stop_scrolling (GTK_NOTEBOOK (widget));
1584 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
1586 gdk_window_hide (GTK_NOTEBOOK (widget)->event_window);
1588 GTK_WIDGET_CLASS (gtk_notebook_parent_class)->unmap (widget);
1592 gtk_notebook_realize (GtkWidget *widget)
1594 GtkNotebook *notebook;
1595 GdkWindowAttr attributes;
1596 gint attributes_mask;
1597 GdkRectangle event_window_pos;
1599 g_return_if_fail (GTK_IS_NOTEBOOK (widget));
1601 notebook = GTK_NOTEBOOK (widget);
1602 GTK_WIDGET_SET_FLAGS (notebook, GTK_REALIZED);
1604 gtk_notebook_get_event_window_position (notebook, &event_window_pos);
1606 widget->window = gtk_widget_get_parent_window (widget);
1607 g_object_ref (widget->window);
1609 attributes.window_type = GDK_WINDOW_CHILD;
1610 attributes.x = event_window_pos.x;
1611 attributes.y = event_window_pos.y;
1612 attributes.width = event_window_pos.width;
1613 attributes.height = event_window_pos.height;
1614 attributes.wclass = GDK_INPUT_ONLY;
1615 attributes.event_mask = gtk_widget_get_events (widget);
1616 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
1617 GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK |
1618 GDK_POINTER_MOTION_MASK | GDK_LEAVE_NOTIFY_MASK |
1620 attributes_mask = GDK_WA_X | GDK_WA_Y;
1622 notebook->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
1623 &attributes, attributes_mask);
1624 gdk_window_set_user_data (notebook->event_window, notebook);
1626 widget->style = gtk_style_attach (widget->style, widget->window);
1630 gtk_notebook_unrealize (GtkWidget *widget)
1632 GtkNotebook *notebook;
1633 GtkNotebookPrivate *priv;
1635 g_return_if_fail (GTK_IS_NOTEBOOK (widget));
1637 notebook = GTK_NOTEBOOK (widget);
1638 priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
1640 gdk_window_set_user_data (notebook->event_window, NULL);
1641 gdk_window_destroy (notebook->event_window);
1642 notebook->event_window = NULL;
1644 if (priv->drag_window)
1646 gdk_window_set_user_data (priv->drag_window, NULL);
1647 gdk_window_destroy (priv->drag_window);
1648 priv->drag_window = NULL;
1651 if (GTK_WIDGET_CLASS (gtk_notebook_parent_class)->unrealize)
1652 (* GTK_WIDGET_CLASS (gtk_notebook_parent_class)->unrealize) (widget);
1656 gtk_notebook_size_request (GtkWidget *widget,
1657 GtkRequisition *requisition)
1659 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
1660 GtkNotebookPage *page;
1662 GtkRequisition child_requisition;
1663 gboolean switch_page = FALSE;
1669 gint scroll_arrow_hlength;
1670 gint scroll_arrow_vlength;
1672 gtk_widget_style_get (widget,
1673 "focus-line-width", &focus_width,
1674 "tab-overlap", &tab_overlap,
1675 "tab-curvature", &tab_curvature,
1676 "arrow-spacing", &arrow_spacing,
1677 "scroll-arrow-hlength", &scroll_arrow_hlength,
1678 "scroll-arrow-vlength", &scroll_arrow_vlength,
1681 widget->requisition.width = 0;
1682 widget->requisition.height = 0;
1684 for (children = notebook->children, vis_pages = 0; children;
1685 children = children->next)
1687 page = children->data;
1689 if (GTK_WIDGET_VISIBLE (page->child))
1692 gtk_widget_size_request (page->child, &child_requisition);
1694 widget->requisition.width = MAX (widget->requisition.width,
1695 child_requisition.width);
1696 widget->requisition.height = MAX (widget->requisition.height,
1697 child_requisition.height);
1699 if (notebook->menu && page->menu_label->parent &&
1700 !GTK_WIDGET_VISIBLE (page->menu_label->parent))
1701 gtk_widget_show (page->menu_label->parent);
1705 if (page == notebook->cur_page)
1707 if (notebook->menu && page->menu_label->parent &&
1708 GTK_WIDGET_VISIBLE (page->menu_label->parent))
1709 gtk_widget_hide (page->menu_label->parent);
1713 if (notebook->show_border || notebook->show_tabs)
1715 widget->requisition.width += widget->style->xthickness * 2;
1716 widget->requisition.height += widget->style->ythickness * 2;
1718 if (notebook->show_tabs)
1721 gint tab_height = 0;
1725 for (children = notebook->children; children;
1726 children = children->next)
1728 page = children->data;
1730 if (GTK_WIDGET_VISIBLE (page->child))
1732 if (!GTK_WIDGET_VISIBLE (page->tab_label))
1733 gtk_widget_show (page->tab_label);
1735 gtk_widget_size_request (page->tab_label,
1736 &child_requisition);
1738 page->requisition.width =
1739 child_requisition.width +
1740 2 * widget->style->xthickness;
1741 page->requisition.height =
1742 child_requisition.height +
1743 2 * widget->style->ythickness;
1745 switch (notebook->tab_pos)
1748 case GTK_POS_BOTTOM:
1749 page->requisition.height += 2 * (notebook->tab_vborder +
1751 tab_height = MAX (tab_height, page->requisition.height);
1752 tab_max = MAX (tab_max, page->requisition.width);
1756 page->requisition.width += 2 * (notebook->tab_hborder +
1758 tab_width = MAX (tab_width, page->requisition.width);
1759 tab_max = MAX (tab_max, page->requisition.height);
1763 else if (GTK_WIDGET_VISIBLE (page->tab_label))
1764 gtk_widget_hide (page->tab_label);
1767 children = notebook->children;
1771 switch (notebook->tab_pos)
1774 case GTK_POS_BOTTOM:
1775 if (tab_height == 0)
1778 if (notebook->scrollable && vis_pages > 1 &&
1779 widget->requisition.width < tab_width)
1780 tab_height = MAX (tab_height, scroll_arrow_hlength);
1782 padding = 2 * (tab_curvature + focus_width +
1783 notebook->tab_hborder) - tab_overlap;
1787 page = children->data;
1788 children = children->next;
1790 if (!GTK_WIDGET_VISIBLE (page->child))
1793 if (notebook->homogeneous)
1794 page->requisition.width = tab_max;
1796 page->requisition.width += padding;
1798 tab_width += page->requisition.width;
1799 page->requisition.height = tab_height;
1802 if (notebook->scrollable && vis_pages > 1 &&
1803 widget->requisition.width < tab_width)
1804 tab_width = tab_max + 2 * (scroll_arrow_hlength + arrow_spacing);
1806 if (notebook->homogeneous && !notebook->scrollable)
1807 widget->requisition.width = MAX (widget->requisition.width,
1808 vis_pages * tab_max +
1811 widget->requisition.width = MAX (widget->requisition.width,
1812 tab_width + tab_overlap);
1814 widget->requisition.height += tab_height;
1821 if (notebook->scrollable && vis_pages > 1 &&
1822 widget->requisition.height < tab_height)
1823 tab_width = MAX (tab_width,
1824 arrow_spacing + 2 * scroll_arrow_vlength);
1826 padding = 2 * (tab_curvature + focus_width +
1827 notebook->tab_vborder) - tab_overlap;
1832 page = children->data;
1833 children = children->next;
1835 if (!GTK_WIDGET_VISIBLE (page->child))
1838 page->requisition.width = tab_width;
1840 if (notebook->homogeneous)
1841 page->requisition.height = tab_max;
1843 page->requisition.height += padding;
1845 tab_height += page->requisition.height;
1848 if (notebook->scrollable && vis_pages > 1 &&
1849 widget->requisition.height < tab_height)
1850 tab_height = tab_max + scroll_arrow_vlength + arrow_spacing;
1852 widget->requisition.width += tab_width;
1854 if (notebook->homogeneous && !notebook->scrollable)
1855 widget->requisition.height =
1856 MAX (widget->requisition.height,
1857 vis_pages * tab_max + tab_overlap);
1859 widget->requisition.height =
1860 MAX (widget->requisition.height,
1861 tab_height + tab_overlap);
1863 if (!notebook->homogeneous || notebook->scrollable)
1865 widget->requisition.height = MAX (widget->requisition.height,
1866 vis_pages * tab_max +
1874 for (children = notebook->children; children;
1875 children = children->next)
1877 page = children->data;
1879 if (page->tab_label && GTK_WIDGET_VISIBLE (page->tab_label))
1880 gtk_widget_hide (page->tab_label);
1885 widget->requisition.width += GTK_CONTAINER (widget)->border_width * 2;
1886 widget->requisition.height += GTK_CONTAINER (widget)->border_width * 2;
1892 for (children = notebook->children; children;
1893 children = children->next)
1895 page = children->data;
1896 if (GTK_WIDGET_VISIBLE (page->child))
1898 gtk_notebook_switch_page (notebook, page, -1);
1903 else if (GTK_WIDGET_VISIBLE (widget))
1905 widget->requisition.width = GTK_CONTAINER (widget)->border_width * 2;
1906 widget->requisition.height= GTK_CONTAINER (widget)->border_width * 2;
1909 if (vis_pages && !notebook->cur_page)
1911 children = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, TRUE);
1914 notebook->first_tab = children;
1915 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (children),-1);
1921 gtk_notebook_size_allocate (GtkWidget *widget,
1922 GtkAllocation *allocation)
1924 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
1925 gint tab_pos = get_effective_tab_pos (notebook);
1927 widget->allocation = *allocation;
1928 if (GTK_WIDGET_REALIZED (widget))
1930 GdkRectangle position;
1932 if (gtk_notebook_get_event_window_position (notebook, &position))
1934 gdk_window_move_resize (notebook->event_window,
1935 position.x, position.y,
1936 position.width, position.height);
1937 if (GTK_WIDGET_MAPPED (notebook))
1938 gdk_window_show_unraised (notebook->event_window);
1941 gdk_window_hide (notebook->event_window);
1944 if (notebook->children)
1946 gint border_width = GTK_CONTAINER (widget)->border_width;
1947 GtkNotebookPage *page;
1948 GtkAllocation child_allocation;
1951 child_allocation.x = widget->allocation.x + border_width;
1952 child_allocation.y = widget->allocation.y + border_width;
1953 child_allocation.width = MAX (1, allocation->width - border_width * 2);
1954 child_allocation.height = MAX (1, allocation->height - border_width * 2);
1956 if (notebook->show_tabs || notebook->show_border)
1958 child_allocation.x += widget->style->xthickness;
1959 child_allocation.y += widget->style->ythickness;
1960 child_allocation.width = MAX (1, child_allocation.width -
1961 widget->style->xthickness * 2);
1962 child_allocation.height = MAX (1, child_allocation.height -
1963 widget->style->ythickness * 2);
1965 if (notebook->show_tabs && notebook->children && notebook->cur_page)
1970 child_allocation.y += notebook->cur_page->requisition.height;
1971 case GTK_POS_BOTTOM:
1972 child_allocation.height =
1973 MAX (1, child_allocation.height -
1974 notebook->cur_page->requisition.height);
1977 child_allocation.x += notebook->cur_page->requisition.width;
1979 child_allocation.width =
1980 MAX (1, child_allocation.width -
1981 notebook->cur_page->requisition.width);
1987 children = notebook->children;
1990 page = children->data;
1991 children = children->next;
1993 if (GTK_WIDGET_VISIBLE (page->child))
1994 gtk_widget_size_allocate (page->child, &child_allocation);
1997 gtk_notebook_pages_allocate (notebook);
2002 gtk_notebook_expose (GtkWidget *widget,
2003 GdkEventExpose *event)
2005 GtkNotebook *notebook;
2006 GtkNotebookPrivate *priv;
2007 GdkRectangle child_area;
2009 g_return_val_if_fail (GTK_IS_NOTEBOOK (widget), FALSE);
2010 g_return_val_if_fail (event != NULL, FALSE);
2012 notebook = GTK_NOTEBOOK (widget);
2013 priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
2015 if (event->window == priv->drag_window)
2017 GdkRectangle area = { 0, };
2019 gdk_drawable_get_size (priv->drag_window,
2020 &area.width, &area.height);
2021 gtk_notebook_draw_tab (notebook,
2025 else if (GTK_WIDGET_DRAWABLE (widget))
2027 gtk_notebook_paint (widget, &event->area);
2028 if (notebook->show_tabs)
2030 if (notebook->cur_page &&
2031 gtk_widget_intersect (notebook->cur_page->tab_label,
2032 &event->area, &child_area))
2033 gtk_notebook_draw_focus (widget);
2037 if (notebook->cur_page)
2038 gtk_container_propagate_expose (GTK_CONTAINER (notebook),
2039 notebook->cur_page->child,
2047 gtk_notebook_show_arrows (GtkNotebook *notebook)
2049 gboolean show_arrow = FALSE;
2052 if (!notebook->scrollable)
2055 children = notebook->children;
2058 GtkNotebookPage *page = children->data;
2060 if (page->tab_label && !gtk_widget_get_child_visible (page->tab_label))
2063 children = children->next;
2070 gtk_notebook_get_arrow_rect (GtkNotebook *notebook,
2071 GdkRectangle *rectangle,
2072 GtkNotebookArrow arrow)
2074 GdkRectangle event_window_pos;
2075 gboolean before = ARROW_IS_BEFORE (arrow);
2076 gboolean left = ARROW_IS_LEFT (arrow);
2078 if (gtk_notebook_get_event_window_position (notebook, &event_window_pos))
2080 gint scroll_arrow_hlength;
2081 gint scroll_arrow_vlength;
2083 gtk_widget_style_get (GTK_WIDGET (notebook),
2084 "scroll-arrow-hlength", &scroll_arrow_hlength,
2085 "scroll-arrow-vlength", &scroll_arrow_vlength,
2088 switch (notebook->tab_pos)
2092 rectangle->width = scroll_arrow_vlength;
2093 rectangle->height = scroll_arrow_vlength;
2095 if ((before && (notebook->has_before_previous != notebook->has_before_next)) ||
2096 (!before && (notebook->has_after_previous != notebook->has_after_next)))
2097 rectangle->x = event_window_pos.x + (event_window_pos.width - rectangle->width) / 2;
2099 rectangle->x = event_window_pos.x + event_window_pos.width / 2 - rectangle->width;
2101 rectangle->x = event_window_pos.x + event_window_pos.width / 2;
2102 rectangle->y = event_window_pos.y;
2104 rectangle->y += event_window_pos.height - rectangle->height;
2108 case GTK_POS_BOTTOM:
2109 rectangle->width = scroll_arrow_hlength;
2110 rectangle->height = scroll_arrow_hlength;
2114 if (left || !notebook->has_before_previous)
2115 rectangle->x = event_window_pos.x;
2117 rectangle->x = event_window_pos.x + rectangle->width;
2121 if (!left || !notebook->has_after_next)
2122 rectangle->x = event_window_pos.x + event_window_pos.width - rectangle->width;
2124 rectangle->x = event_window_pos.x + event_window_pos.width - 2 * rectangle->width;
2126 rectangle->y = event_window_pos.y + (event_window_pos.height - rectangle->height) / 2;
2132 static GtkNotebookArrow
2133 gtk_notebook_get_arrow (GtkNotebook *notebook,
2137 GdkRectangle arrow_rect;
2138 GdkRectangle event_window_pos;
2141 GtkNotebookArrow arrow[4];
2143 arrow[0] = notebook->has_before_previous ? ARROW_LEFT_BEFORE : ARROW_NONE;
2144 arrow[1] = notebook->has_before_next ? ARROW_RIGHT_BEFORE : ARROW_NONE;
2145 arrow[2] = notebook->has_after_previous ? ARROW_LEFT_AFTER : ARROW_NONE;
2146 arrow[3] = notebook->has_after_next ? ARROW_RIGHT_AFTER : ARROW_NONE;
2148 if (gtk_notebook_show_arrows (notebook))
2150 gtk_notebook_get_event_window_position (notebook, &event_window_pos);
2151 for (i = 0; i < 4; i++)
2153 if (arrow[i] == ARROW_NONE)
2156 gtk_notebook_get_arrow_rect (notebook, &arrow_rect, arrow[i]);
2158 x0 = x - arrow_rect.x;
2159 y0 = y - arrow_rect.y;
2161 if (y0 >= 0 && y0 < arrow_rect.height &&
2162 x0 >= 0 && x0 < arrow_rect.width)
2171 gtk_notebook_do_arrow (GtkNotebook *notebook,
2172 GtkNotebookArrow arrow)
2174 GtkWidget *widget = GTK_WIDGET (notebook);
2175 GtkDirectionType dir;
2176 gboolean is_rtl, left;
2178 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2179 left = (ARROW_IS_LEFT (arrow) && !is_rtl) ||
2180 (!ARROW_IS_LEFT (arrow) && is_rtl);
2182 if (!notebook->focus_tab ||
2183 gtk_notebook_search_page (notebook, notebook->focus_tab,
2184 left ? STEP_PREV : STEP_NEXT,
2187 if (notebook->tab_pos == GTK_POS_LEFT ||
2188 notebook->tab_pos == GTK_POS_RIGHT)
2189 dir = ARROW_IS_LEFT (arrow) ? GTK_DIR_UP : GTK_DIR_DOWN;
2191 dir = ARROW_IS_LEFT (arrow) ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
2192 gtk_widget_child_focus (widget, dir);
2197 gtk_notebook_arrow_button_press (GtkNotebook *notebook,
2198 GtkNotebookArrow arrow,
2201 GtkWidget *widget = GTK_WIDGET (notebook);
2202 gboolean is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2203 gboolean left = (ARROW_IS_LEFT (arrow) && !is_rtl) ||
2204 (!ARROW_IS_LEFT (arrow) && is_rtl);
2206 if (!GTK_WIDGET_HAS_FOCUS (widget))
2207 gtk_widget_grab_focus (widget);
2209 notebook->button = button;
2210 notebook->click_child = arrow;
2214 gtk_notebook_do_arrow (notebook, arrow);
2215 gtk_notebook_set_scroll_timer (notebook);
2217 else if (button == 2)
2218 gtk_notebook_page_select (notebook, TRUE);
2219 else if (button == 3)
2220 gtk_notebook_switch_focus_tab (notebook,
2221 gtk_notebook_search_page (notebook,
2223 left ? STEP_NEXT : STEP_PREV,
2225 gtk_notebook_redraw_arrows (notebook);
2231 get_widget_coordinates (GtkWidget *widget,
2236 GdkWindow *window = ((GdkEventAny *)event)->window;
2239 if (!gdk_event_get_coords (event, &tx, &ty))
2242 while (window && window != widget->window)
2244 gint window_x, window_y;
2246 gdk_window_get_position (window, &window_x, &window_y);
2250 window = gdk_window_get_parent (window);
2265 gtk_notebook_scroll (GtkWidget *widget,
2266 GdkEventScroll *event)
2268 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2271 GtkWidget* originator;
2273 if (!notebook->cur_page)
2276 child = notebook->cur_page->child;
2277 originator = gtk_get_event_widget ((GdkEvent *)event);
2279 /* ignore scroll events from the content of the page */
2280 if (!originator || gtk_widget_is_ancestor (originator, child))
2283 switch (event->direction)
2285 case GDK_SCROLL_RIGHT:
2286 case GDK_SCROLL_DOWN:
2287 gtk_notebook_next_page (notebook);
2289 case GDK_SCROLL_LEFT:
2291 gtk_notebook_prev_page (notebook);
2299 get_tab_at_pos (GtkNotebook *notebook, gint x, gint y)
2301 GtkNotebookPage *page;
2302 GList *children = notebook->children;
2306 page = children->data;
2308 if (GTK_WIDGET_VISIBLE (page->child) &&
2309 page->tab_label && GTK_WIDGET_MAPPED (page->tab_label) &&
2310 (x >= page->allocation.x) &&
2311 (y >= page->allocation.y) &&
2312 (x <= (page->allocation.x + page->allocation.width)) &&
2313 (y <= (page->allocation.y + page->allocation.height)))
2316 children = children->next;
2323 gtk_notebook_button_press (GtkWidget *widget,
2324 GdkEventButton *event)
2326 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2327 GtkNotebookPrivate *priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
2328 GtkNotebookPage *page;
2330 GtkNotebookArrow arrow;
2333 if (event->type != GDK_BUTTON_PRESS || !notebook->children ||
2337 if (!get_widget_coordinates (widget, (GdkEvent *)event, &x, &y))
2340 arrow = gtk_notebook_get_arrow (notebook, x, y);
2342 return gtk_notebook_arrow_button_press (notebook, arrow, event->button);
2344 if (event->button == 3 && notebook->menu)
2346 gtk_menu_popup (GTK_MENU (notebook->menu), NULL, NULL,
2347 NULL, NULL, 3, event->time);
2351 if (event->button != 1)
2354 notebook->button = event->button;
2356 if ((tab = get_tab_at_pos (notebook, x, y)) != NULL)
2358 gboolean page_changed, was_focus;
2361 page_changed = page != notebook->cur_page;
2362 was_focus = gtk_widget_is_focus (widget);
2364 gtk_notebook_switch_focus_tab (notebook, tab);
2365 gtk_widget_grab_focus (widget);
2367 if (page_changed && !was_focus)
2368 gtk_widget_child_focus (page->child, GTK_DIR_TAB_FORWARD);
2370 /* save press to possibly begin a drag */
2371 if (page->reorderable || page->detachable)
2373 priv->during_detach = FALSE;
2374 priv->during_reorder = FALSE;
2375 priv->pressed_button = event->button;
2377 gdk_window_get_pointer (widget->window,
2382 priv->drag_begin_x = priv->mouse_x;
2383 priv->drag_begin_y = priv->mouse_y;
2384 priv->drag_offset_x = priv->drag_begin_x - page->allocation.x;
2385 priv->drag_offset_y = priv->drag_begin_y - page->allocation.y;
2393 popup_position_func (GtkMenu *menu,
2399 GtkNotebook *notebook = data;
2401 GtkRequisition requisition;
2403 if (notebook->focus_tab)
2405 GtkNotebookPage *page;
2407 page = notebook->focus_tab->data;
2408 w = page->tab_label;
2412 w = GTK_WIDGET (notebook);
2415 gdk_window_get_origin (w->window, x, y);
2416 gtk_widget_size_request (GTK_WIDGET (menu), &requisition);
2418 if (gtk_widget_get_direction (w) == GTK_TEXT_DIR_RTL)
2419 *x += w->allocation.x + w->allocation.width - requisition.width;
2421 *x += w->allocation.x;
2423 *y += w->allocation.y + w->allocation.height;
2429 gtk_notebook_popup_menu (GtkWidget *widget)
2431 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2435 gtk_menu_popup (GTK_MENU (notebook->menu), NULL, NULL,
2436 popup_position_func, notebook,
2437 0, gtk_get_current_event_time ());
2438 gtk_menu_shell_select_first (GTK_MENU_SHELL (notebook->menu), FALSE);
2446 stop_scrolling (GtkNotebook *notebook)
2448 if (notebook->timer)
2450 g_source_remove (notebook->timer);
2451 notebook->timer = 0;
2452 notebook->need_timer = FALSE;
2454 notebook->click_child = 0;
2455 notebook->button = 0;
2456 gtk_notebook_redraw_arrows (notebook);
2460 get_drop_position (GtkNotebook *notebook,
2463 GtkNotebookPrivate *priv;
2464 GList *children, *last_child;
2465 GtkNotebookPage *page;
2469 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
2473 is_rtl = gtk_widget_get_direction ((GtkWidget *) notebook) == GTK_TEXT_DIR_RTL;
2474 children = notebook->children;
2479 page = children->data;
2481 if ((priv->operation != DRAG_OPERATION_REORDER || page != notebook->cur_page) &&
2482 GTK_WIDGET_VISIBLE (page->child) &&
2484 GTK_WIDGET_MAPPED (page->tab_label) &&
2487 switch (notebook->tab_pos)
2490 case GTK_POS_BOTTOM:
2493 if ((page->pack == GTK_PACK_START && PAGE_MIDDLE_X (page) > x) ||
2494 (page->pack == GTK_PACK_END && PAGE_MIDDLE_X (page) < x))
2499 if ((page->pack == GTK_PACK_START && PAGE_MIDDLE_X (page) < x) ||
2500 (page->pack == GTK_PACK_END && PAGE_MIDDLE_X (page) > x))
2507 if ((page->pack == GTK_PACK_START && PAGE_MIDDLE_Y (page) > y) ||
2508 (page->pack == GTK_PACK_END && PAGE_MIDDLE_Y (page) < y))
2514 last_child = children->next;
2517 children = children->next;
2524 show_drag_window (GtkNotebook *notebook,
2525 GtkNotebookPrivate *priv,
2526 GtkNotebookPage *page)
2528 GtkWidget *widget = GTK_WIDGET (notebook);
2530 if (!priv->drag_window)
2532 GdkWindowAttr attributes;
2533 guint attributes_mask;
2535 attributes.x = page->allocation.x;
2536 attributes.y = page->allocation.y;
2537 attributes.width = page->allocation.width;
2538 attributes.height = page->allocation.height;
2539 attributes.window_type = GDK_WINDOW_CHILD;
2540 attributes.wclass = GDK_INPUT_OUTPUT;
2541 attributes.visual = gtk_widget_get_visual (widget);
2542 attributes.colormap = gtk_widget_get_colormap (widget);
2543 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
2544 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2546 priv->drag_window = gdk_window_new (gtk_widget_get_parent_window (widget),
2549 gdk_window_set_user_data (priv->drag_window, widget);
2552 g_object_ref (page->tab_label);
2553 gtk_widget_unparent (page->tab_label);
2554 gtk_widget_set_parent_window (page->tab_label, priv->drag_window);
2555 gtk_widget_set_parent (page->tab_label, widget);
2556 g_object_unref (page->tab_label);
2558 gdk_window_show (priv->drag_window);
2560 /* the grab will dissapear when the window is hidden */
2561 gdk_pointer_grab (priv->drag_window,
2563 GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK,
2564 NULL, NULL, GDK_CURRENT_TIME);
2567 /* This function undoes the reparenting that happens both when drag_window
2568 * is shown for reordering and when the DnD icon is shown for detaching
2571 hide_drag_window (GtkNotebook *notebook,
2572 GtkNotebookPrivate *priv,
2573 GtkNotebookPage *page)
2575 GtkWidget *widget = GTK_WIDGET (notebook);
2576 GtkWidget *parent = page->tab_label->parent;
2578 if (page->tab_label->window != widget->window ||
2579 !NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page))
2581 g_object_ref (page->tab_label);
2583 if (GTK_IS_WINDOW (parent))
2585 /* parent widget is the drag window */
2586 gtk_container_remove (GTK_CONTAINER (parent), page->tab_label);
2589 gtk_widget_unparent (page->tab_label);
2591 gtk_widget_set_parent_window (page->tab_label, widget->window);
2592 gtk_widget_set_parent (page->tab_label, widget);
2593 g_object_unref (page->tab_label);
2596 if (priv->drag_window &&
2597 gdk_window_is_visible (priv->drag_window))
2598 gdk_window_hide (priv->drag_window);
2602 gtk_notebook_stop_reorder (GtkNotebook *notebook)
2604 GtkNotebookPrivate *priv;
2605 GtkNotebookPage *page;
2607 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
2608 page = notebook->cur_page;
2613 priv->pressed_button = -1;
2615 if (page->reorderable || page->detachable)
2617 if (priv->during_reorder)
2619 gint old_page_num, page_num;
2622 element = get_drop_position (notebook, page->pack);
2623 old_page_num = g_list_position (notebook->children, notebook->focus_tab);
2624 page_num = reorder_tab (notebook, element, notebook->focus_tab);
2626 if (priv->has_scrolled || old_page_num != page_num)
2627 g_signal_emit (notebook,
2628 notebook_signals[PAGE_REORDERED], 0,
2629 page->child, page_num);
2631 priv->has_scrolled = FALSE;
2632 priv->during_reorder = FALSE;
2635 hide_drag_window (notebook, priv, page);
2637 priv->operation = DRAG_OPERATION_NONE;
2638 gtk_notebook_pages_allocate (notebook);
2640 if (priv->dnd_timer)
2642 g_source_remove (priv->dnd_timer);
2643 priv->dnd_timer = 0;
2649 gtk_notebook_button_release (GtkWidget *widget,
2650 GdkEventButton *event)
2652 GtkNotebook *notebook;
2653 GtkNotebookPrivate *priv;
2654 GtkNotebookPage *page;
2656 g_return_val_if_fail (GTK_IS_NOTEBOOK (widget), FALSE);
2657 g_return_val_if_fail (event != NULL, FALSE);
2659 if (event->type != GDK_BUTTON_RELEASE)
2662 notebook = GTK_NOTEBOOK (widget);
2663 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
2664 page = notebook->cur_page;
2666 if (!priv->during_detach &&
2667 page->reorderable &&
2668 event->button == priv->pressed_button)
2669 gtk_notebook_stop_reorder (notebook);
2671 if (event->button == notebook->button)
2673 stop_scrolling (notebook);
2681 gtk_notebook_leave_notify (GtkWidget *widget,
2682 GdkEventCrossing *event)
2684 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2687 if (!get_widget_coordinates (widget, (GdkEvent *)event, &x, &y))
2690 if (notebook->in_child)
2692 notebook->in_child = 0;
2693 gtk_notebook_redraw_arrows (notebook);
2699 static GtkNotebookPointerPosition
2700 get_pointer_position (GtkNotebook *notebook)
2702 GtkWidget *widget = (GtkWidget *) notebook;
2703 GtkContainer *container = (GtkContainer *) notebook;
2704 GtkNotebookPrivate *priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
2707 if (!notebook->scrollable)
2708 return POINTER_BETWEEN;
2710 if (notebook->tab_pos == GTK_POS_TOP ||
2711 notebook->tab_pos == GTK_POS_BOTTOM)
2715 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2716 x = priv->mouse_x - widget->allocation.x;
2718 if (x > widget->allocation.width - 2 * container->border_width - SCROLL_THRESHOLD)
2719 return (is_rtl) ? POINTER_BEFORE : POINTER_AFTER;
2720 else if (x < SCROLL_THRESHOLD + container->border_width)
2721 return (is_rtl) ? POINTER_AFTER : POINTER_BEFORE;
2723 return POINTER_BETWEEN;
2729 y = priv->mouse_y - widget->allocation.y;
2730 if (y > widget->allocation.height - 2 * container->border_width - SCROLL_THRESHOLD)
2731 return POINTER_AFTER;
2732 else if (y < SCROLL_THRESHOLD + container->border_width)
2733 return POINTER_BEFORE;
2735 return POINTER_BETWEEN;
2740 scroll_notebook_timer (gpointer data)
2742 GtkNotebook *notebook = (GtkNotebook *) data;
2743 GtkNotebookPrivate *priv;
2744 GtkNotebookPointerPosition pointer_position;
2745 GList *element, *first_tab;
2747 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
2748 pointer_position = get_pointer_position (notebook);
2750 element = get_drop_position (notebook, notebook->cur_page->pack);
2751 reorder_tab (notebook, element, notebook->focus_tab);
2752 first_tab = gtk_notebook_search_page (notebook, notebook->first_tab,
2753 (pointer_position == POINTER_BEFORE) ? STEP_PREV : STEP_NEXT,
2757 notebook->first_tab = first_tab;
2758 gtk_notebook_pages_allocate (notebook);
2760 gdk_window_move_resize (priv->drag_window,
2761 priv->drag_window_x,
2762 priv->drag_window_y,
2763 notebook->cur_page->allocation.width,
2764 notebook->cur_page->allocation.height);
2765 gdk_window_raise (priv->drag_window);
2772 check_threshold (GtkNotebook *notebook,
2778 GdkRectangle rectangle = { 0, }; /* shut up gcc */
2779 GtkSettings *settings;
2781 widget = GTK_WIDGET (notebook);
2782 settings = gtk_widget_get_settings (GTK_WIDGET (notebook));
2783 g_object_get (G_OBJECT (settings), "gtk-dnd-drag-threshold", &dnd_threshold, NULL);
2785 /* we want a large threshold */
2786 dnd_threshold *= DND_THRESHOLD_MULTIPLIER;
2788 gdk_window_get_position (notebook->event_window, &rectangle.x, &rectangle.y);
2789 gdk_drawable_get_size (GDK_DRAWABLE (notebook->event_window), &rectangle.width, &rectangle.height);
2791 rectangle.x -= dnd_threshold;
2792 rectangle.width += 2 * dnd_threshold;
2793 rectangle.y -= dnd_threshold;
2794 rectangle.height += 2 * dnd_threshold;
2796 return (current_x < rectangle.x ||
2797 current_x > rectangle.x + rectangle.width ||
2798 current_y < rectangle.y ||
2799 current_y > rectangle.y + rectangle.height);
2803 gtk_notebook_motion_notify (GtkWidget *widget,
2804 GdkEventMotion *event)
2806 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2807 GtkNotebookPrivate *priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
2808 GtkNotebookPage *page;
2809 GtkNotebookArrow arrow;
2810 GtkNotebookPointerPosition pointer_position;
2811 GtkSettings *settings;
2814 page = notebook->cur_page;
2819 if (!(event->state & GDK_BUTTON1_MASK) &&
2820 priv->pressed_button != -1)
2822 gtk_notebook_stop_reorder (notebook);
2823 stop_scrolling (notebook);
2826 if (event->time < priv->timestamp + MSECS_BETWEEN_UPDATES)
2829 priv->timestamp = event->time;
2830 gdk_window_get_pointer (widget->window,
2835 arrow = gtk_notebook_get_arrow (notebook, priv->mouse_x, priv->mouse_y);
2836 if (arrow != notebook->in_child)
2838 notebook->in_child = arrow;
2839 gtk_notebook_redraw_arrows (notebook);
2842 if (priv->pressed_button == -1)
2845 if (page->detachable &&
2846 check_threshold (notebook, priv->mouse_x, priv->mouse_y))
2848 priv->detached_tab = notebook->cur_page;
2849 priv->during_detach = TRUE;
2851 gtk_drag_begin (widget, priv->source_targets, GDK_ACTION_MOVE,
2852 priv->pressed_button, (GdkEvent*) event);
2856 if (page->reorderable &&
2857 (priv->during_reorder ||
2858 gtk_drag_check_threshold (widget, priv->drag_begin_x, priv->drag_begin_y, priv->mouse_x, priv->mouse_y)))
2860 priv->during_reorder = TRUE;
2861 pointer_position = get_pointer_position (notebook);
2863 if (event->window == priv->drag_window &&
2864 pointer_position != POINTER_BETWEEN &&
2865 gtk_notebook_show_arrows (notebook))
2868 if (!priv->dnd_timer)
2870 priv->has_scrolled = TRUE;
2871 settings = gtk_widget_get_settings (GTK_WIDGET (notebook));
2872 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
2874 priv->dnd_timer = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
2875 scroll_notebook_timer,
2876 (gpointer) notebook);
2881 if (priv->dnd_timer)
2883 g_source_remove (priv->dnd_timer);
2884 priv->dnd_timer = 0;
2888 if (event->window == priv->drag_window ||
2889 priv->operation != DRAG_OPERATION_REORDER)
2891 /* the drag operation is beginning, create the window */
2892 if (priv->operation != DRAG_OPERATION_REORDER)
2894 priv->operation = DRAG_OPERATION_REORDER;
2895 show_drag_window (notebook, priv, page);
2898 gtk_notebook_pages_allocate (notebook);
2899 gdk_window_move_resize (priv->drag_window,
2900 priv->drag_window_x,
2901 priv->drag_window_y,
2902 page->allocation.width,
2903 page->allocation.height);
2911 gtk_notebook_grab_notify (GtkWidget *widget,
2912 gboolean was_grabbed)
2914 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2918 gtk_notebook_stop_reorder (notebook);
2919 stop_scrolling (notebook);
2924 gtk_notebook_state_changed (GtkWidget *widget,
2925 GtkStateType previous_state)
2927 if (!GTK_WIDGET_IS_SENSITIVE (widget))
2928 stop_scrolling (GTK_NOTEBOOK (widget));
2932 gtk_notebook_focus_in (GtkWidget *widget,
2933 GdkEventFocus *event)
2935 GTK_NOTEBOOK (widget)->child_has_focus = FALSE;
2937 gtk_notebook_redraw_tabs (GTK_NOTEBOOK (widget));
2943 gtk_notebook_focus_out (GtkWidget *widget,
2944 GdkEventFocus *event)
2946 gtk_notebook_redraw_tabs (GTK_NOTEBOOK (widget));
2952 gtk_notebook_draw_focus (GtkWidget *widget)
2954 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2956 if (GTK_WIDGET_DRAWABLE (widget) && notebook->show_tabs &&
2957 notebook->focus_tab)
2959 GtkNotebookPage *page;
2963 gtk_widget_style_get (widget, "focus-line-width", &focus_width, NULL);
2965 page = notebook->focus_tab->data;
2967 area.x = page->tab_label->allocation.x - focus_width;
2968 area.y = page->tab_label->allocation.y - focus_width;
2969 area.width = page->tab_label->allocation.width + 2 * focus_width;
2970 area.height = page->tab_label->allocation.height + 2 * focus_width;
2972 gtk_notebook_draw_tab (GTK_NOTEBOOK (widget), page, &area);
2977 gtk_notebook_style_set (GtkWidget *widget,
2980 GtkNotebook *notebook;
2982 gboolean has_before_previous;
2983 gboolean has_before_next;
2984 gboolean has_after_previous;
2985 gboolean has_after_next;
2987 notebook = GTK_NOTEBOOK (widget);
2989 gtk_widget_style_get (widget,
2990 "has-backward-stepper", &has_before_previous,
2991 "has-secondary-forward-stepper", &has_before_next,
2992 "has-secondary-backward-stepper", &has_after_previous,
2993 "has-forward-stepper", &has_after_next,
2996 notebook->has_before_previous = has_before_previous;
2997 notebook->has_before_next = has_before_next;
2998 notebook->has_after_previous = has_after_previous;
2999 notebook->has_after_next = has_after_next;
3001 (* GTK_WIDGET_CLASS (gtk_notebook_parent_class)->style_set) (widget, previous);
3005 on_drag_icon_expose (GtkWidget *widget,
3006 GdkEventExpose *event,
3009 GtkWidget *notebook, *child = GTK_WIDGET (data);
3010 GtkRequisition requisition;
3013 notebook = GTK_WIDGET (data);
3014 child = GTK_BIN (widget)->child;
3015 gtk_widget_size_request (widget, &requisition);
3016 gap_pos = get_tab_gap_pos (GTK_NOTEBOOK (notebook));
3018 gtk_paint_extension (notebook->style, widget->window,
3019 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
3020 NULL, widget, "tab",
3022 requisition.width, requisition.height,
3025 gtk_container_propagate_expose (GTK_CONTAINER (widget), child, event);
3031 gtk_notebook_drag_begin (GtkWidget *widget,
3032 GdkDragContext *context)
3034 GtkNotebookPrivate *priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
3035 GtkNotebook *notebook = (GtkNotebook*) widget;
3036 GtkWidget *tab_label;
3038 if (priv->dnd_timer)
3040 g_source_remove (priv->dnd_timer);
3041 priv->dnd_timer = 0;
3044 priv->operation = DRAG_OPERATION_DETACH;
3045 gtk_notebook_pages_allocate (notebook);
3047 tab_label = priv->detached_tab->tab_label;
3049 hide_drag_window (notebook, priv, notebook->cur_page);
3050 g_object_ref (tab_label);
3051 gtk_widget_unparent (tab_label);
3053 priv->dnd_window = gtk_window_new (GTK_WINDOW_POPUP);
3054 gtk_container_add (GTK_CONTAINER (priv->dnd_window), tab_label);
3055 gtk_widget_set_size_request (priv->dnd_window,
3056 priv->detached_tab->allocation.width,
3057 priv->detached_tab->allocation.height);
3058 g_object_unref (tab_label);
3060 g_signal_connect (G_OBJECT (priv->dnd_window), "expose-event",
3061 G_CALLBACK (on_drag_icon_expose), notebook);
3063 gtk_drag_set_icon_widget (context, priv->dnd_window, -2, -2);
3067 gtk_notebook_drag_end (GtkWidget *widget,
3068 GdkDragContext *context)
3070 GtkNotebookPrivate *priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
3072 gtk_notebook_stop_reorder (GTK_NOTEBOOK (widget));
3074 GTK_BIN (priv->dnd_window)->child = NULL;
3075 gtk_widget_destroy (priv->dnd_window);
3076 priv->dnd_window = NULL;
3078 priv->operation = DRAG_OPERATION_NONE;
3082 gtk_notebook_switch_tab_timeout (gpointer data)
3084 GtkNotebook *notebook;
3085 GtkNotebookPrivate *priv;
3089 notebook = GTK_NOTEBOOK (data);
3090 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
3092 priv->switch_tab_timer = 0;
3096 if ((tab = get_tab_at_pos (notebook, x, y)) != NULL)
3098 /* FIXME: hack, we don't want the
3099 * focus to move fom the source widget
3101 notebook->child_has_focus = FALSE;
3102 gtk_notebook_switch_focus_tab (notebook, tab);
3109 gtk_notebook_drag_motion (GtkWidget *widget,
3110 GdkDragContext *context,
3115 GtkNotebook *notebook;
3116 GtkNotebookPrivate *priv;
3117 GdkRectangle position;
3118 GtkSettings *settings;
3119 GtkNotebookArrow arrow;
3121 GdkAtom target, tab_target;
3123 notebook = GTK_NOTEBOOK (widget);
3124 arrow = gtk_notebook_get_arrow (notebook,
3125 x + widget->allocation.x,
3126 y + widget->allocation.y);
3129 notebook->click_child = arrow;
3130 gtk_notebook_set_scroll_timer (notebook);
3131 gdk_drag_status (context, 0, time);
3135 stop_scrolling (notebook);
3136 target = gtk_drag_dest_find_target (widget, context, NULL);
3137 tab_target = gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB");
3139 if (target == tab_target)
3141 gint widget_group, source_widget_group;
3142 GtkWidget *source_widget;
3144 source_widget = gtk_drag_get_source_widget (context);
3145 g_assert (source_widget);
3147 widget_group = gtk_notebook_get_group_id (notebook);
3148 source_widget_group = gtk_notebook_get_group_id (GTK_NOTEBOOK (source_widget));
3150 if (widget_group != -1 &&
3151 source_widget_group != -1 &&
3152 widget_group == source_widget_group &&
3153 !(widget == GTK_NOTEBOOK (source_widget)->cur_page->child ||
3154 gtk_widget_is_ancestor (widget, GTK_NOTEBOOK (source_widget)->cur_page->child)))
3156 gdk_drag_status (context, GDK_ACTION_MOVE, time);
3161 priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
3162 x += widget->allocation.x;
3163 y += widget->allocation.y;
3165 if (target == tab_target)
3167 /* it's a tab, but doesn't share
3168 * ID with this notebook */
3169 gdk_drag_status (context, 0, time);
3172 if (gtk_notebook_get_event_window_position (notebook, &position) &&
3173 x >= position.x && x <= position.x + position.width &&
3174 y >= position.y && y <= position.y + position.height)
3179 if (!priv->switch_tab_timer)
3181 settings = gtk_widget_get_settings (widget);
3183 g_object_get (settings, "gtk-timeout-expand", &timeout, NULL);
3184 priv->switch_tab_timer = gdk_threads_add_timeout (timeout,
3185 gtk_notebook_switch_tab_timeout,
3191 if (priv->switch_tab_timer)
3193 g_source_remove (priv->switch_tab_timer);
3194 priv->switch_tab_timer = 0;
3202 gtk_notebook_drag_leave (GtkWidget *widget,
3203 GdkDragContext *context,
3206 GtkNotebookPrivate *priv;
3208 priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
3210 if (priv->switch_tab_timer)
3212 g_source_remove (priv->switch_tab_timer);
3213 priv->switch_tab_timer = 0;
3216 stop_scrolling (GTK_NOTEBOOK (widget));
3220 gtk_notebook_drag_drop (GtkWidget *widget,
3221 GdkDragContext *context,
3228 target = gtk_drag_dest_find_target (widget, context, NULL);
3230 if (target == GDK_NONE)
3231 gtk_drag_finish (context, FALSE, FALSE, time);
3237 do_detach_tab (GtkNotebook *from,
3243 GtkNotebookPrivate *priv;
3244 GtkWidget *tab_label, *menu_label;
3245 gboolean tab_expand, tab_fill, reorderable, detachable;
3250 menu_label = gtk_notebook_get_menu_label (from, child);
3253 g_object_ref (menu_label);
3255 tab_label = gtk_notebook_get_tab_label (from, child);
3258 g_object_ref (tab_label);
3260 g_object_ref (child);
3262 gtk_container_child_get (GTK_CONTAINER (from),
3264 "tab-expand", &tab_expand,
3265 "tab-fill", &tab_fill,
3266 "tab-pack", &tab_pack,
3267 "reorderable", &reorderable,
3268 "detachable", &detachable,
3271 gtk_container_remove (GTK_CONTAINER (from), child);
3273 priv = GTK_NOTEBOOK_GET_PRIVATE (to);
3274 priv->mouse_x = x + GTK_WIDGET (to)->allocation.x;
3275 priv->mouse_y = y + GTK_WIDGET (to)->allocation.y;
3277 element = get_drop_position (to, tab_pack);
3278 page_num = g_list_position (to->children, element);
3279 gtk_notebook_insert_page_menu (to, child, tab_label, menu_label, page_num);
3281 gtk_container_child_set (GTK_CONTAINER (to), child,
3282 "tab-pack", tab_pack,
3283 "tab-expand", tab_expand,
3284 "tab-fill", tab_fill,
3285 "reorderable", reorderable,
3286 "detachable", detachable,
3289 g_object_unref (child);
3292 g_object_unref (tab_label);
3295 g_object_unref (menu_label);
3297 gtk_notebook_set_current_page (to, page_num);
3301 gtk_notebook_drag_data_get (GtkWidget *widget,
3302 GdkDragContext *context,
3303 GtkSelectionData *data,
3307 GtkNotebook *dest_notebook, *notebook;
3308 GtkNotebookPrivate *priv;
3310 if (data->target != gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB") &&
3311 (data->target != gdk_atom_intern_static_string ("application/x-rootwindow-drop") ||
3312 !window_creation_hook))
3315 notebook = GTK_NOTEBOOK (widget);
3316 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
3318 if (data->target == gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB"))
3320 gtk_selection_data_set (data,
3323 (void*) &priv->detached_tab->child,
3328 GdkDisplay *display;
3331 display = gtk_widget_get_display (widget);
3332 gdk_display_get_pointer (display, NULL, &x, &y, NULL);
3334 dest_notebook = (* window_creation_hook) (notebook,
3335 priv->detached_tab->child,
3337 window_creation_hook_data);
3339 do_detach_tab (notebook, dest_notebook, priv->detached_tab->child, 0, 0);
3344 gtk_notebook_drag_data_received (GtkWidget *widget,
3345 GdkDragContext *context,
3348 GtkSelectionData *data,
3352 GtkNotebook *notebook;
3353 GtkWidget *source_widget;
3356 notebook = GTK_NOTEBOOK (widget);
3357 source_widget = gtk_drag_get_source_widget (context);
3359 if (source_widget &&
3360 data->target == gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB"))
3362 child = (void*) data->data;
3364 do_detach_tab (GTK_NOTEBOOK (source_widget), notebook, *child, x, y);
3365 gtk_drag_finish (context, TRUE, FALSE, time);
3368 gtk_drag_finish (context, FALSE, FALSE, time);
3371 /* Private GtkContainer Methods :
3373 * gtk_notebook_set_child_arg
3374 * gtk_notebook_get_child_arg
3376 * gtk_notebook_remove
3377 * gtk_notebook_focus
3378 * gtk_notebook_set_focus_child
3379 * gtk_notebook_child_type
3380 * gtk_notebook_forall
3383 gtk_notebook_set_child_property (GtkContainer *container,
3386 const GValue *value,
3391 GtkPackType pack_type;
3393 /* not finding child's page is valid for menus or labels */
3394 if (!gtk_notebook_find_child (GTK_NOTEBOOK (container), child, NULL))
3397 switch (property_id)
3399 case CHILD_PROP_TAB_LABEL:
3400 /* a NULL pointer indicates a default_tab setting, otherwise
3401 * we need to set the associated label
3403 gtk_notebook_set_tab_label_text (GTK_NOTEBOOK (container), child,
3404 g_value_get_string (value));
3406 case CHILD_PROP_MENU_LABEL:
3407 gtk_notebook_set_menu_label_text (GTK_NOTEBOOK (container), child,
3408 g_value_get_string (value));
3410 case CHILD_PROP_POSITION:
3411 gtk_notebook_reorder_child (GTK_NOTEBOOK (container), child,
3412 g_value_get_int (value));
3414 case CHILD_PROP_TAB_EXPAND:
3415 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3416 &expand, &fill, &pack_type);
3417 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (container), child,
3418 g_value_get_boolean (value),
3421 case CHILD_PROP_TAB_FILL:
3422 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3423 &expand, &fill, &pack_type);
3424 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (container), child,
3426 g_value_get_boolean (value),
3429 case CHILD_PROP_TAB_PACK:
3430 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3431 &expand, &fill, &pack_type);
3432 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (container), child,
3434 g_value_get_enum (value));
3436 case CHILD_PROP_REORDERABLE:
3437 gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (container), child,
3438 g_value_get_boolean (value));
3440 case CHILD_PROP_DETACHABLE:
3441 gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (container), child,
3442 g_value_get_boolean (value));
3445 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
3451 gtk_notebook_get_child_property (GtkContainer *container,
3458 GtkNotebook *notebook;
3462 GtkPackType pack_type;
3464 notebook = GTK_NOTEBOOK (container);
3466 /* not finding child's page is valid for menus or labels */
3467 list = gtk_notebook_find_child (notebook, child, NULL);
3470 /* nothing to set on labels or menus */
3471 g_param_value_set_default (pspec, value);
3475 switch (property_id)
3477 case CHILD_PROP_TAB_LABEL:
3478 label = gtk_notebook_get_tab_label (notebook, child);
3480 if (label && GTK_IS_LABEL (label))
3481 g_value_set_string (value, GTK_LABEL (label)->label);
3483 g_value_set_string (value, NULL);
3485 case CHILD_PROP_MENU_LABEL:
3486 label = gtk_notebook_get_menu_label (notebook, child);
3488 if (label && GTK_IS_LABEL (label))
3489 g_value_set_string (value, GTK_LABEL (label)->label);
3491 g_value_set_string (value, NULL);
3493 case CHILD_PROP_POSITION:
3494 g_value_set_int (value, g_list_position (notebook->children, list));
3496 case CHILD_PROP_TAB_EXPAND:
3497 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3498 &expand, NULL, NULL);
3499 g_value_set_boolean (value, expand);
3501 case CHILD_PROP_TAB_FILL:
3502 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3504 g_value_set_boolean (value, fill);
3506 case CHILD_PROP_TAB_PACK:
3507 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3508 NULL, NULL, &pack_type);
3509 g_value_set_enum (value, pack_type);
3511 case CHILD_PROP_REORDERABLE:
3512 g_value_set_boolean (value,
3513 gtk_notebook_get_tab_reorderable (GTK_NOTEBOOK (container), child));
3515 case CHILD_PROP_DETACHABLE:
3516 g_value_set_boolean (value,
3517 gtk_notebook_get_tab_detachable (GTK_NOTEBOOK (container), child));
3520 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
3526 gtk_notebook_add (GtkContainer *container,
3529 g_return_if_fail (GTK_IS_NOTEBOOK (container));
3531 gtk_notebook_insert_page_menu (GTK_NOTEBOOK (container), widget,
3536 gtk_notebook_remove (GtkContainer *container,
3539 GtkNotebook *notebook;
3540 GtkNotebookPage *page;
3544 g_return_if_fail (GTK_IS_NOTEBOOK (container));
3545 g_return_if_fail (widget != NULL);
3547 notebook = GTK_NOTEBOOK (container);
3549 children = notebook->children;
3552 page = children->data;
3554 if (page->child == widget)
3558 children = children->next;
3561 if (children == NULL)
3564 g_object_ref (widget);
3566 gtk_notebook_real_remove (notebook, children);
3568 g_signal_emit (notebook,
3569 notebook_signals[PAGE_REMOVED],
3574 g_object_unref (widget);
3578 focus_tabs_in (GtkNotebook *notebook)
3580 if (notebook->show_tabs && notebook->cur_page)
3582 gtk_widget_grab_focus (GTK_WIDGET (notebook));
3584 gtk_notebook_switch_focus_tab (notebook,
3585 g_list_find (notebook->children,
3586 notebook->cur_page));
3595 focus_tabs_move (GtkNotebook *notebook,
3596 GtkDirectionType direction,
3597 gint search_direction)
3601 new_page = gtk_notebook_search_page (notebook, notebook->focus_tab,
3602 search_direction, TRUE);
3605 gboolean wrap_around;
3607 g_object_get (gtk_widget_get_settings (GTK_WIDGET (notebook)),
3608 "gtk-keynav-wrap-around", &wrap_around,
3612 new_page = gtk_notebook_search_page (notebook, NULL,
3613 search_direction, TRUE);
3617 gtk_notebook_switch_focus_tab (notebook, new_page);
3619 gtk_widget_error_bell (GTK_WIDGET (notebook));
3625 focus_child_in (GtkNotebook *notebook,
3626 GtkDirectionType direction)
3628 if (notebook->cur_page)
3629 return gtk_widget_child_focus (notebook->cur_page->child, direction);
3634 /* Focus in the notebook can either be on the pages, or on
3638 gtk_notebook_focus (GtkWidget *widget,
3639 GtkDirectionType direction)
3641 GtkWidget *old_focus_child;
3642 GtkNotebook *notebook;
3643 GtkDirectionType effective_direction;
3645 gboolean widget_is_focus;
3646 GtkContainer *container;
3648 g_return_val_if_fail (GTK_IS_NOTEBOOK (widget), FALSE);
3650 container = GTK_CONTAINER (widget);
3651 notebook = GTK_NOTEBOOK (container);
3653 if (notebook->focus_out)
3655 notebook->focus_out = FALSE; /* Clear this to catch the wrap-around case */
3659 widget_is_focus = gtk_widget_is_focus (widget);
3660 old_focus_child = container->focus_child;
3662 effective_direction = get_effective_direction (notebook, direction);
3664 if (old_focus_child) /* Focus on page child */
3666 if (gtk_widget_child_focus (old_focus_child, direction))
3669 switch (effective_direction)
3671 case GTK_DIR_TAB_BACKWARD:
3673 /* Focus onto the tabs */
3674 return focus_tabs_in (notebook);
3676 case GTK_DIR_TAB_FORWARD:
3682 else if (widget_is_focus) /* Focus was on tabs */
3684 switch (effective_direction)
3686 case GTK_DIR_TAB_BACKWARD:
3689 case GTK_DIR_TAB_FORWARD:
3691 /* We use TAB_FORWARD rather than direction so that we focus a more
3692 * predictable widget for the user; users may be using arrow focusing
3693 * in this situation even if they don't usually use arrow focusing.
3695 return focus_child_in (notebook, GTK_DIR_TAB_FORWARD);
3697 return focus_tabs_move (notebook, direction, STEP_PREV);
3699 return focus_tabs_move (notebook, direction, STEP_NEXT);
3702 else /* Focus was not on widget */
3704 switch (effective_direction)
3706 case GTK_DIR_TAB_FORWARD:
3708 if (focus_tabs_in (notebook))
3710 if (focus_child_in (notebook, direction))
3713 case GTK_DIR_TAB_BACKWARD:
3715 if (focus_child_in (notebook, direction))
3717 if (focus_tabs_in (notebook))
3722 return focus_child_in (notebook, direction);
3726 g_assert_not_reached ();
3731 gtk_notebook_set_focus_child (GtkContainer *container,
3734 GtkNotebook *notebook = GTK_NOTEBOOK (container);
3735 GtkWidget *page_child;
3736 GtkWidget *toplevel;
3738 /* If the old focus widget was within a page of the notebook,
3739 * (child may either be NULL or not in this case), record it
3740 * for future use if we switch to the page with a mnemonic.
3743 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (container));
3744 if (toplevel && GTK_WIDGET_TOPLEVEL (toplevel))
3746 page_child = GTK_WINDOW (toplevel)->focus_widget;
3749 if (page_child->parent == GTK_WIDGET (container))
3751 GList *list = gtk_notebook_find_child (notebook, page_child, NULL);
3754 GtkNotebookPage *page = list->data;
3756 if (page->last_focus_child)
3757 g_object_remove_weak_pointer (G_OBJECT (page->last_focus_child), (gpointer *)&page->last_focus_child);
3759 page->last_focus_child = GTK_WINDOW (toplevel)->focus_widget;
3760 g_object_add_weak_pointer (G_OBJECT (page->last_focus_child), (gpointer *)&page->last_focus_child);
3766 page_child = page_child->parent;
3772 g_return_if_fail (GTK_IS_WIDGET (child));
3774 notebook->child_has_focus = TRUE;
3775 if (!notebook->focus_tab)
3778 GtkNotebookPage *page;
3780 children = notebook->children;
3783 page = children->data;
3784 if (page->child == child || page->tab_label == child)
3785 gtk_notebook_switch_focus_tab (notebook, children);
3786 children = children->next;
3791 GTK_CONTAINER_CLASS (gtk_notebook_parent_class)->set_focus_child (container, child);
3795 gtk_notebook_forall (GtkContainer *container,
3796 gboolean include_internals,
3797 GtkCallback callback,
3798 gpointer callback_data)
3800 GtkNotebook *notebook;
3803 g_return_if_fail (GTK_IS_NOTEBOOK (container));
3804 g_return_if_fail (callback != NULL);
3806 notebook = GTK_NOTEBOOK (container);
3808 children = notebook->children;
3811 GtkNotebookPage *page;
3813 page = children->data;
3814 children = children->next;
3815 (* callback) (page->child, callback_data);
3817 if (include_internals)
3819 if (page->tab_label)
3820 (* callback) (page->tab_label, callback_data);
3826 gtk_notebook_child_type (GtkContainer *container)
3828 return GTK_TYPE_WIDGET;
3831 /* Private GtkNotebook Methods:
3833 * gtk_notebook_real_insert_page
3836 page_visible_cb (GtkWidget *page,
3840 GtkNotebook *notebook = (GtkNotebook *) data;
3844 if (notebook->cur_page &&
3845 notebook->cur_page->child == page &&
3846 !GTK_WIDGET_VISIBLE (page))
3848 list = g_list_find (notebook->children, notebook->cur_page);
3851 next = gtk_notebook_search_page (notebook, list, STEP_NEXT, TRUE);
3853 next = gtk_notebook_search_page (notebook, list, STEP_PREV, TRUE);
3857 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (next), -1);
3862 gtk_notebook_real_insert_page (GtkNotebook *notebook,
3864 GtkWidget *tab_label,
3865 GtkWidget *menu_label,
3868 GtkNotebookPage *page;
3871 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
3872 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
3873 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
3874 g_return_val_if_fail (menu_label == NULL || GTK_IS_WIDGET (menu_label), -1);
3876 gtk_widget_freeze_child_notify (child);
3878 page = g_new (GtkNotebookPage, 1);
3879 page->child = child;
3880 page->last_focus_child = NULL;
3881 page->requisition.width = 0;
3882 page->requisition.height = 0;
3883 page->allocation.x = 0;
3884 page->allocation.y = 0;
3885 page->allocation.width = 0;
3886 page->allocation.height = 0;
3887 page->default_menu = FALSE;
3888 page->default_tab = FALSE;
3889 page->mnemonic_activate_signal = 0;
3890 page->reorderable = FALSE;
3891 page->detachable = FALSE;
3893 nchildren = g_list_length (notebook->children);
3894 if ((position < 0) || (position > nchildren))
3895 position = nchildren;
3897 notebook->children = g_list_insert (notebook->children, page, position);
3901 page->default_tab = TRUE;
3902 if (notebook->show_tabs)
3903 tab_label = gtk_label_new ("");
3905 page->tab_label = tab_label;
3906 page->menu_label = menu_label;
3907 page->expand = FALSE;
3909 page->pack = GTK_PACK_START;
3912 page->default_menu = TRUE;
3915 g_object_ref_sink (page->menu_label);
3919 gtk_notebook_menu_item_create (notebook,
3920 g_list_find (notebook->children, page));
3922 gtk_widget_set_parent (child, GTK_WIDGET (notebook));
3924 gtk_widget_set_parent (tab_label, GTK_WIDGET (notebook));
3926 gtk_notebook_update_labels (notebook);
3928 if (!notebook->first_tab)
3929 notebook->first_tab = notebook->children;
3931 /* child visible will be turned on by switch_page below */
3932 gtk_widget_set_child_visible (child, FALSE);
3936 if (notebook->show_tabs && GTK_WIDGET_VISIBLE (child))
3937 gtk_widget_show (tab_label);
3939 gtk_widget_hide (tab_label);
3941 page->mnemonic_activate_signal =
3942 g_signal_connect (tab_label,
3943 "mnemonic_activate",
3944 G_CALLBACK (gtk_notebook_mnemonic_activate_switch_page),
3948 page->notify_visible_handler = g_signal_connect (child, "notify::visible",
3949 G_CALLBACK (page_visible_cb), notebook);
3951 g_signal_emit (notebook,
3952 notebook_signals[PAGE_ADDED],
3957 if (!notebook->cur_page)
3959 gtk_notebook_switch_page (notebook, page, 0);
3960 gtk_notebook_switch_focus_tab (notebook, NULL);
3963 gtk_notebook_update_tab_states (notebook);
3965 gtk_widget_child_notify (child, "tab-expand");
3966 gtk_widget_child_notify (child, "tab-fill");
3967 gtk_widget_child_notify (child, "tab-pack");
3968 gtk_widget_child_notify (child, "tab-label");
3969 gtk_widget_child_notify (child, "menu-label");
3970 gtk_widget_child_notify (child, "position");
3971 gtk_widget_thaw_child_notify (child);
3976 /* Private GtkNotebook Functions:
3978 * gtk_notebook_redraw_tabs
3979 * gtk_notebook_real_remove
3980 * gtk_notebook_update_labels
3981 * gtk_notebook_timer
3982 * gtk_notebook_set_scroll_timer
3983 * gtk_notebook_page_compare
3984 * gtk_notebook_real_page_position
3985 * gtk_notebook_search_page
3988 gtk_notebook_redraw_tabs (GtkNotebook *notebook)
3991 GtkNotebookPage *page;
3992 GdkRectangle redraw_rect;
3994 gint tab_pos = get_effective_tab_pos (notebook);
3996 widget = GTK_WIDGET (notebook);
3997 border = GTK_CONTAINER (notebook)->border_width;
3999 if (!GTK_WIDGET_MAPPED (notebook) || !notebook->first_tab)
4002 page = notebook->first_tab->data;
4004 redraw_rect.x = border;
4005 redraw_rect.y = border;
4009 case GTK_POS_BOTTOM:
4010 redraw_rect.y = widget->allocation.height - border -
4011 page->allocation.height - widget->style->ythickness;
4013 if (page != notebook->cur_page)
4014 redraw_rect.y -= widget->style->ythickness;
4017 redraw_rect.width = widget->allocation.width - 2 * border;
4018 redraw_rect.height = page->allocation.height + widget->style->ythickness;
4020 if (page != notebook->cur_page)
4021 redraw_rect.height += widget->style->ythickness;
4024 redraw_rect.x = widget->allocation.width - border -
4025 page->allocation.width - widget->style->xthickness;
4027 if (page != notebook->cur_page)
4028 redraw_rect.x -= widget->style->xthickness;
4031 redraw_rect.width = page->allocation.width + widget->style->xthickness;
4032 redraw_rect.height = widget->allocation.height - 2 * border;
4034 if (page != notebook->cur_page)
4035 redraw_rect.width += widget->style->xthickness;
4039 redraw_rect.x += widget->allocation.x;
4040 redraw_rect.y += widget->allocation.y;
4042 gdk_window_invalidate_rect (widget->window, &redraw_rect, TRUE);
4046 gtk_notebook_redraw_arrows (GtkNotebook *notebook)
4048 if (GTK_WIDGET_MAPPED (notebook) && gtk_notebook_show_arrows (notebook))
4052 GtkNotebookArrow arrow[4];
4054 arrow[0] = notebook->has_before_previous ? ARROW_LEFT_BEFORE : ARROW_NONE;
4055 arrow[1] = notebook->has_before_next ? ARROW_RIGHT_BEFORE : ARROW_NONE;
4056 arrow[2] = notebook->has_after_previous ? ARROW_LEFT_AFTER : ARROW_NONE;
4057 arrow[3] = notebook->has_after_next ? ARROW_RIGHT_AFTER : ARROW_NONE;
4059 for (i = 0; i < 4; i++)
4061 if (arrow[i] == ARROW_NONE)
4064 gtk_notebook_get_arrow_rect (notebook, &rect, arrow[i]);
4065 gdk_window_invalidate_rect (GTK_WIDGET (notebook)->window,
4072 gtk_notebook_timer (GtkNotebook *notebook)
4074 gboolean retval = FALSE;
4076 if (notebook->timer)
4078 gtk_notebook_do_arrow (notebook, notebook->click_child);
4080 if (notebook->need_timer)
4082 GtkSettings *settings;
4085 settings = gtk_widget_get_settings (GTK_WIDGET (notebook));
4086 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
4088 notebook->need_timer = FALSE;
4089 notebook->timer = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
4090 (GSourceFunc) gtk_notebook_timer,
4091 (gpointer) notebook);
4101 gtk_notebook_set_scroll_timer (GtkNotebook *notebook)
4103 GtkWidget *widget = GTK_WIDGET (notebook);
4105 if (!notebook->timer)
4107 GtkSettings *settings = gtk_widget_get_settings (widget);
4110 g_object_get (settings, "gtk-timeout-initial", &timeout, NULL);
4112 notebook->timer = gdk_threads_add_timeout (timeout,
4113 (GSourceFunc) gtk_notebook_timer,
4114 (gpointer) notebook);
4115 notebook->need_timer = TRUE;
4120 gtk_notebook_page_compare (gconstpointer a,
4123 return (((GtkNotebookPage *) a)->child != b);
4127 gtk_notebook_find_child (GtkNotebook *notebook,
4129 const gchar *function)
4131 GList *list = g_list_find_custom (notebook->children, child,
4132 gtk_notebook_page_compare);
4134 #ifndef G_DISABLE_CHECKS
4135 if (!list && function)
4136 g_warning ("%s: unable to find child %p in notebook %p",
4137 function, child, notebook);
4144 gtk_notebook_remove_tab_label (GtkNotebook *notebook,
4145 GtkNotebookPage *page)
4147 if (page->tab_label)
4149 if (page->mnemonic_activate_signal)
4150 g_signal_handler_disconnect (page->tab_label,
4151 page->mnemonic_activate_signal);
4152 page->mnemonic_activate_signal = 0;
4154 gtk_widget_set_state (page->tab_label, GTK_STATE_NORMAL);
4155 gtk_widget_unparent (page->tab_label);
4156 page->tab_label = NULL;
4161 gtk_notebook_real_remove (GtkNotebook *notebook,
4164 GtkNotebookPrivate *priv;
4165 GtkNotebookPage *page;
4167 gint need_resize = FALSE;
4169 gboolean destroying;
4171 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
4172 destroying = GTK_OBJECT_FLAGS (notebook) & GTK_IN_DESTRUCTION;
4174 next_list = gtk_notebook_search_page (notebook, list, STEP_PREV, TRUE);
4176 next_list = gtk_notebook_search_page (notebook, list, STEP_NEXT, TRUE);
4178 if (notebook->cur_page == list->data)
4180 notebook->cur_page = NULL;
4181 if (next_list && !destroying)
4182 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (next_list), -1);
4185 if (priv->detached_tab == list->data)
4186 priv->detached_tab = NULL;
4188 if (list == notebook->first_tab)
4189 notebook->first_tab = next_list;
4190 if (list == notebook->focus_tab && !destroying)
4191 gtk_notebook_switch_focus_tab (notebook, next_list);
4195 g_signal_handler_disconnect (page->child, page->notify_visible_handler);
4197 if (GTK_WIDGET_VISIBLE (page->child) && GTK_WIDGET_VISIBLE (notebook))
4200 gtk_widget_unparent (page->child);
4202 gtk_notebook_remove_tab_label (notebook, page);
4206 gtk_container_remove (GTK_CONTAINER (notebook->menu),
4207 page->menu_label->parent);
4208 gtk_widget_queue_resize (notebook->menu);
4210 if (!page->default_menu)
4211 g_object_unref (page->menu_label);
4213 notebook->children = g_list_remove_link (notebook->children, list);
4216 if (page->last_focus_child)
4218 g_object_remove_weak_pointer (G_OBJECT (page->last_focus_child), (gpointer *)&page->last_focus_child);
4219 page->last_focus_child = NULL;
4224 gtk_notebook_update_labels (notebook);
4226 gtk_widget_queue_resize (GTK_WIDGET (notebook));
4230 gtk_notebook_update_labels (GtkNotebook *notebook)
4232 GtkNotebookPage *page;
4237 for (list = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, FALSE);
4239 list = gtk_notebook_search_page (notebook, list, STEP_NEXT, FALSE))
4242 g_snprintf (string, sizeof(string), _("Page %u"), page_num++);
4243 if (notebook->show_tabs)
4245 if (page->default_tab)
4247 if (!page->tab_label)
4249 page->tab_label = gtk_label_new (string);
4250 gtk_widget_set_parent (page->tab_label,
4251 GTK_WIDGET (notebook));
4254 gtk_label_set_text (GTK_LABEL (page->tab_label), string);
4257 if (GTK_WIDGET_VISIBLE (page->child) &&
4258 !GTK_WIDGET_VISIBLE (page->tab_label))
4259 gtk_widget_show (page->tab_label);
4260 else if (!GTK_WIDGET_VISIBLE (page->child) &&
4261 GTK_WIDGET_VISIBLE (page->tab_label))
4262 gtk_widget_hide (page->tab_label);
4264 if (notebook->menu && page->default_menu)
4266 if (page->tab_label && GTK_IS_LABEL (page->tab_label))
4267 gtk_label_set_text (GTK_LABEL (page->menu_label),
4268 GTK_LABEL (page->tab_label)->label);
4270 gtk_label_set_text (GTK_LABEL (page->menu_label), string);
4276 gtk_notebook_real_page_position (GtkNotebook *notebook,
4282 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
4283 g_return_val_if_fail (list != NULL, -1);
4285 for (work = notebook->children, count_start = 0;
4286 work && work != list; work = work->next)
4287 if (GTK_NOTEBOOK_PAGE (work)->pack == GTK_PACK_START)
4293 if (GTK_NOTEBOOK_PAGE (list)->pack == GTK_PACK_START)
4296 return (count_start + g_list_length (list) - 1);
4300 gtk_notebook_search_page (GtkNotebook *notebook,
4303 gboolean find_visible)
4305 GtkNotebookPage *page = NULL;
4306 GList *old_list = NULL;
4309 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
4314 flag = GTK_PACK_END;
4318 flag = GTK_PACK_START;
4325 if (!page || page->pack == flag)
4333 list = notebook->children;
4338 if (page->pack == flag &&
4340 (GTK_WIDGET_VISIBLE (page->child) &&
4341 (!page->tab_label || NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page)))))
4356 if (page->pack != flag &&
4358 (GTK_WIDGET_VISIBLE (page->child) &&
4359 (!page->tab_label || NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page)))))
4367 /* Private GtkNotebook Drawing Functions:
4369 * gtk_notebook_paint
4370 * gtk_notebook_draw_tab
4371 * gtk_notebook_draw_arrow
4374 gtk_notebook_paint (GtkWidget *widget,
4377 GtkNotebook *notebook;
4378 GtkNotebookPrivate *priv;
4379 GtkNotebookPage *page;
4384 gint border_width = GTK_CONTAINER (widget)->border_width;
4385 gint gap_x = 0, gap_width = 0, step = STEP_PREV;
4389 g_return_if_fail (GTK_IS_NOTEBOOK (widget));
4390 g_return_if_fail (area != NULL);
4392 if (!GTK_WIDGET_DRAWABLE (widget))
4395 notebook = GTK_NOTEBOOK (widget);
4396 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
4397 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
4398 tab_pos = get_effective_tab_pos (notebook);
4400 if ((!notebook->show_tabs && !notebook->show_border) ||
4401 !notebook->cur_page || !GTK_WIDGET_VISIBLE (notebook->cur_page->child))
4404 x = widget->allocation.x + border_width;
4405 y = widget->allocation.y + border_width;
4406 width = widget->allocation.width - border_width * 2;
4407 height = widget->allocation.height - border_width * 2;
4409 if (notebook->show_border && (!notebook->show_tabs || !notebook->children))
4411 gtk_paint_box (widget->style, widget->window,
4412 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
4413 area, widget, "notebook",
4414 x, y, width, height);
4418 if (!notebook->first_tab)
4419 notebook->first_tab = notebook->children;
4421 if (!NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, notebook->cur_page) ||
4422 !GTK_WIDGET_MAPPED (notebook->cur_page->tab_label))
4423 page = GTK_NOTEBOOK_PAGE (notebook->first_tab);
4425 page = notebook->cur_page;
4430 y += page->allocation.height;
4432 case GTK_POS_BOTTOM:
4433 height -= page->allocation.height;
4436 x += page->allocation.width;
4439 width -= page->allocation.width;
4443 if (!NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, notebook->cur_page) ||
4444 !GTK_WIDGET_MAPPED (notebook->cur_page->tab_label))
4454 case GTK_POS_BOTTOM:
4455 if (priv->operation == DRAG_OPERATION_REORDER)
4456 gap_x = priv->drag_window_x - widget->allocation.x - border_width;
4458 gap_x = notebook->cur_page->allocation.x - widget->allocation.x - border_width;
4460 gap_width = notebook->cur_page->allocation.width;
4461 step = is_rtl ? STEP_NEXT : STEP_PREV;
4465 if (priv->operation == DRAG_OPERATION_REORDER)
4466 gap_x = priv->drag_window_y - border_width - widget->allocation.y;
4468 gap_x = notebook->cur_page->allocation.y - widget->allocation.y - border_width;
4470 gap_width = notebook->cur_page->allocation.height;
4475 gtk_paint_box_gap (widget->style, widget->window,
4476 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
4477 area, widget, "notebook",
4478 x, y, width, height,
4479 tab_pos, gap_x, gap_width);
4482 children = gtk_notebook_search_page (notebook, NULL, step, TRUE);
4485 page = children->data;
4486 children = gtk_notebook_search_page (notebook, children,
4488 if (!GTK_WIDGET_VISIBLE (page->child))
4490 if (!GTK_WIDGET_MAPPED (page->tab_label))
4492 else if (page != notebook->cur_page)
4493 gtk_notebook_draw_tab (notebook, page, area);
4496 if (showarrow && notebook->scrollable)
4498 if (notebook->has_before_previous)
4499 gtk_notebook_draw_arrow (notebook, ARROW_LEFT_BEFORE);
4500 if (notebook->has_before_next)
4501 gtk_notebook_draw_arrow (notebook, ARROW_RIGHT_BEFORE);
4502 if (notebook->has_after_previous)
4503 gtk_notebook_draw_arrow (notebook, ARROW_LEFT_AFTER);
4504 if (notebook->has_after_next)
4505 gtk_notebook_draw_arrow (notebook, ARROW_RIGHT_AFTER);
4507 gtk_notebook_draw_tab (notebook, notebook->cur_page, area);
4511 gtk_notebook_draw_tab (GtkNotebook *notebook,
4512 GtkNotebookPage *page,
4515 GtkNotebookPrivate *priv;
4516 GdkRectangle child_area;
4517 GdkRectangle page_area;
4518 GtkStateType state_type;
4519 GtkPositionType gap_side;
4523 g_return_if_fail (notebook != NULL);
4524 g_return_if_fail (page != NULL);
4525 g_return_if_fail (area != NULL);
4527 if (!NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) ||
4528 !GTK_WIDGET_MAPPED (page->tab_label) ||
4529 (page->allocation.width == 0) || (page->allocation.height == 0))
4532 widget = GTK_WIDGET (notebook);
4533 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
4535 if (priv->operation == DRAG_OPERATION_REORDER && page == notebook->cur_page)
4536 window = priv->drag_window;
4538 window = widget->window;
4540 page_area.x = page->allocation.x;
4541 page_area.y = page->allocation.y;
4542 page_area.width = page->allocation.width;
4543 page_area.height = page->allocation.height;
4545 if (gdk_rectangle_intersect (&page_area, area, &child_area))
4547 gap_side = get_tab_gap_pos (notebook);
4549 if (notebook->cur_page == page)
4550 state_type = GTK_STATE_NORMAL;
4552 state_type = GTK_STATE_ACTIVE;
4554 gtk_paint_extension (widget->style, window,
4555 state_type, GTK_SHADOW_OUT,
4556 area, widget, "tab",
4557 page_area.x, page_area.y,
4558 page_area.width, page_area.height,
4561 if ((GTK_WIDGET_HAS_FOCUS (widget)) &&
4562 notebook->focus_tab && (notebook->focus_tab->data == page))
4566 gtk_widget_style_get (widget, "focus-line-width", &focus_width, NULL);
4568 gtk_paint_focus (widget->style, window, GTK_WIDGET_STATE (widget),
4569 area, widget, "tab",
4570 page->tab_label->allocation.x - focus_width,
4571 page->tab_label->allocation.y - focus_width,
4572 page->tab_label->allocation.width + 2 * focus_width,
4573 page->tab_label->allocation.height + 2 * focus_width);
4576 if (gtk_widget_intersect (page->tab_label, area, &child_area) &&
4577 GTK_WIDGET_DRAWABLE (page->tab_label))
4579 GdkEvent *expose_event = gdk_event_new (GDK_EXPOSE);
4581 /* This is a lame hack since all this code needs rewriting anyhow */
4582 expose_event->expose.window = g_object_ref (page->tab_label->window);
4583 expose_event->expose.area = child_area;
4584 expose_event->expose.region = gdk_region_rectangle (&child_area);
4585 expose_event->expose.send_event = TRUE;
4586 expose_event->expose.count = 0;
4588 gtk_widget_send_expose (page->tab_label, expose_event);
4589 gdk_event_free (expose_event);
4595 gtk_notebook_draw_arrow (GtkNotebook *notebook,
4596 GtkNotebookArrow nbarrow)
4598 GtkStateType state_type;
4599 GtkShadowType shadow_type;
4601 GdkRectangle arrow_rect;
4603 gboolean is_rtl, left;
4605 gtk_notebook_get_arrow_rect (notebook, &arrow_rect, nbarrow);
4607 widget = GTK_WIDGET (notebook);
4609 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
4610 left = (ARROW_IS_LEFT (nbarrow) && !is_rtl) ||
4611 (!ARROW_IS_LEFT (nbarrow) && is_rtl);
4613 if (GTK_WIDGET_DRAWABLE (notebook))
4615 gint scroll_arrow_hlength;
4616 gint scroll_arrow_vlength;
4619 gtk_widget_style_get (widget,
4620 "scroll-arrow-hlength", &scroll_arrow_hlength,
4621 "scroll-arrow-vlength", &scroll_arrow_vlength,
4624 if (notebook->in_child == nbarrow)
4626 if (notebook->click_child == nbarrow)
4627 state_type = GTK_STATE_ACTIVE;
4629 state_type = GTK_STATE_PRELIGHT;
4632 state_type = GTK_WIDGET_STATE (widget);
4634 if (notebook->click_child == nbarrow)
4635 shadow_type = GTK_SHADOW_IN;
4637 shadow_type = GTK_SHADOW_OUT;
4639 if (notebook->focus_tab &&
4640 !gtk_notebook_search_page (notebook, notebook->focus_tab,
4641 left? STEP_PREV : STEP_NEXT, TRUE))
4643 shadow_type = GTK_SHADOW_ETCHED_IN;
4644 state_type = GTK_STATE_INSENSITIVE;
4647 if (notebook->tab_pos == GTK_POS_LEFT ||
4648 notebook->tab_pos == GTK_POS_RIGHT)
4650 arrow = (ARROW_IS_LEFT (nbarrow) ? GTK_ARROW_UP : GTK_ARROW_DOWN);
4651 arrow_size = scroll_arrow_vlength;
4655 arrow = (ARROW_IS_LEFT (nbarrow) ? GTK_ARROW_LEFT : GTK_ARROW_RIGHT);
4656 arrow_size = scroll_arrow_hlength;
4659 gtk_paint_arrow (widget->style, widget->window, state_type,
4660 shadow_type, NULL, widget, "notebook",
4661 arrow, TRUE, arrow_rect.x, arrow_rect.y,
4662 arrow_size, arrow_size);
4666 /* Private GtkNotebook Size Allocate Functions:
4668 * gtk_notebook_tab_space
4669 * gtk_notebook_calculate_shown_tabs
4670 * gtk_notebook_calculate_tabs_allocation
4671 * gtk_notebook_pages_allocate
4672 * gtk_notebook_page_allocate
4673 * gtk_notebook_calc_tabs
4676 gtk_notebook_tab_space (GtkNotebook *notebook,
4677 gboolean *show_arrows,
4682 GtkNotebookPrivate *priv;
4685 gint tab_pos = get_effective_tab_pos (notebook);
4688 gint scroll_arrow_hlength;
4689 gint scroll_arrow_vlength;
4691 widget = GTK_WIDGET (notebook);
4692 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
4693 children = notebook->children;
4695 gtk_widget_style_get (GTK_WIDGET (notebook),
4696 "arrow-spacing", &arrow_spacing,
4697 "scroll-arrow-hlength", &scroll_arrow_hlength,
4698 "scroll-arrow-vlength", &scroll_arrow_vlength,
4704 case GTK_POS_BOTTOM:
4705 *min = widget->allocation.x + GTK_CONTAINER (notebook)->border_width;
4706 *max = widget->allocation.x + widget->allocation.width - GTK_CONTAINER (notebook)->border_width;
4710 GtkNotebookPage *page;
4712 page = children->data;
4713 children = children->next;
4715 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) &&
4716 GTK_WIDGET_VISIBLE (page->child))
4717 *tab_space += page->requisition.width;
4722 *min = widget->allocation.y + GTK_CONTAINER (notebook)->border_width;
4723 *max = widget->allocation.y + widget->allocation.height - GTK_CONTAINER (notebook)->border_width;
4727 GtkNotebookPage *page;
4729 page = children->data;
4730 children = children->next;
4732 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) &&
4733 GTK_WIDGET_VISIBLE (page->child))
4734 *tab_space += page->requisition.height;
4739 if (!notebook->scrollable)
4740 *show_arrows = FALSE;
4743 gtk_widget_style_get (widget, "tab-overlap", &tab_overlap, NULL);
4748 case GTK_POS_BOTTOM:
4749 if (*tab_space > *max - *min - tab_overlap)
4751 *show_arrows = TRUE;
4753 /* take arrows into account */
4754 *tab_space = widget->allocation.width - tab_overlap -
4755 2 * GTK_CONTAINER (notebook)->border_width;
4757 if (notebook->has_after_previous)
4759 *tab_space -= arrow_spacing + scroll_arrow_hlength;
4760 *max -= arrow_spacing + scroll_arrow_hlength;
4763 if (notebook->has_after_next)
4765 *tab_space -= arrow_spacing + scroll_arrow_hlength;
4766 *max -= arrow_spacing + scroll_arrow_hlength;
4769 if (notebook->has_before_previous)
4771 *tab_space -= arrow_spacing + scroll_arrow_hlength;
4772 *min += arrow_spacing + scroll_arrow_hlength;
4775 if (notebook->has_before_next)
4777 *tab_space -= arrow_spacing + scroll_arrow_hlength;
4778 *min += arrow_spacing + scroll_arrow_hlength;
4784 if (*tab_space > *max - *min - tab_overlap)
4786 *show_arrows = TRUE;
4788 /* take arrows into account */
4789 *tab_space = widget->allocation.height -
4790 tab_overlap - 2 * GTK_CONTAINER (notebook)->border_width;
4792 if (notebook->has_after_previous || notebook->has_after_next)
4794 *tab_space -= arrow_spacing + scroll_arrow_vlength;
4795 *max -= arrow_spacing + scroll_arrow_vlength;
4798 if (notebook->has_before_previous || notebook->has_before_next)
4800 *tab_space -= arrow_spacing + scroll_arrow_vlength;
4801 *min += arrow_spacing + scroll_arrow_vlength;
4810 gtk_notebook_calculate_shown_tabs (GtkNotebook *notebook,
4811 gboolean show_arrows,
4817 gint *remaining_space)
4820 GtkContainer *container;
4822 GtkNotebookPage *page;
4823 gint tab_pos, tab_overlap;
4825 widget = GTK_WIDGET (notebook);
4826 container = GTK_CONTAINER (notebook);
4827 gtk_widget_style_get (widget, "tab-overlap", &tab_overlap, NULL);
4828 tab_pos = get_effective_tab_pos (notebook);
4830 if (show_arrows) /* first_tab <- focus_tab */
4832 *remaining_space = tab_space;
4834 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, notebook->cur_page) &&
4835 GTK_WIDGET_VISIBLE (notebook->cur_page->child))
4837 gtk_notebook_calc_tabs (notebook,
4838 notebook->focus_tab,
4839 &(notebook->focus_tab),
4840 remaining_space, STEP_NEXT);
4843 if (*remaining_space <= 0)
4846 notebook->first_tab = notebook->focus_tab;
4847 *last_child = gtk_notebook_search_page (notebook, notebook->focus_tab,
4854 if (notebook->first_tab && notebook->first_tab != notebook->focus_tab)
4856 /* Is first_tab really predecessor of focus_tab? */
4857 page = notebook->first_tab->data;
4858 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) &&
4859 GTK_WIDGET_VISIBLE (page->child))
4860 for (children = notebook->focus_tab;
4861 children && children != notebook->first_tab;
4862 children = gtk_notebook_search_page (notebook,
4870 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, notebook->cur_page))
4871 notebook->first_tab = notebook->focus_tab;
4873 notebook->first_tab = gtk_notebook_search_page (notebook, notebook->focus_tab,
4877 /* calculate shown tabs counting backwards from the focus tab */
4878 gtk_notebook_calc_tabs (notebook,
4879 gtk_notebook_search_page (notebook,
4880 notebook->focus_tab,
4883 &(notebook->first_tab), remaining_space,
4886 if (*remaining_space < 0)
4888 notebook->first_tab =
4889 gtk_notebook_search_page (notebook, notebook->first_tab,
4891 if (!notebook->first_tab)
4892 notebook->first_tab = notebook->focus_tab;
4894 *last_child = gtk_notebook_search_page (notebook, notebook->focus_tab,
4897 else /* focus_tab -> end */
4899 if (!notebook->first_tab)
4900 notebook->first_tab = gtk_notebook_search_page (notebook,
4905 gtk_notebook_calc_tabs (notebook,
4906 gtk_notebook_search_page (notebook,
4907 notebook->focus_tab,
4910 &children, remaining_space, STEP_NEXT);
4912 if (*remaining_space <= 0)
4913 *last_child = children;
4914 else /* start <- first_tab */
4919 gtk_notebook_calc_tabs (notebook,
4920 gtk_notebook_search_page (notebook,
4921 notebook->first_tab,
4924 &children, remaining_space, STEP_PREV);
4926 if (*remaining_space == 0)
4927 notebook->first_tab = children;
4929 notebook->first_tab = gtk_notebook_search_page(notebook,
4937 if (*remaining_space < 0)
4939 /* calculate number of tabs */
4940 *remaining_space = - (*remaining_space);
4943 for (children = notebook->first_tab;
4944 children && children != *last_child;
4945 children = gtk_notebook_search_page (notebook, children,
4950 *remaining_space = 0;
4952 /* unmap all non-visible tabs */
4953 for (children = gtk_notebook_search_page (notebook, NULL,
4955 children && children != notebook->first_tab;
4956 children = gtk_notebook_search_page (notebook, children,
4959 page = children->data;
4961 if (page->tab_label &&
4962 NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page))
4963 gtk_widget_set_child_visible (page->tab_label, FALSE);
4966 for (children = *last_child; children;
4967 children = gtk_notebook_search_page (notebook, children,
4970 page = children->data;
4972 if (page->tab_label &&
4973 NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page))
4974 gtk_widget_set_child_visible (page->tab_label, FALSE);
4977 else /* !show_arrows */
4982 *remaining_space = max - min - tab_overlap - tab_space;
4983 children = notebook->children;
4984 notebook->first_tab = gtk_notebook_search_page (notebook, NULL,
4988 page = children->data;
4989 children = children->next;
4991 if (!NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) ||
4992 !GTK_WIDGET_VISIBLE (page->child))
5001 /* if notebook is homogeneous, all tabs are expanded */
5002 if (notebook->homogeneous && *n)
5008 get_allocate_at_bottom (GtkWidget *widget,
5009 gint search_direction)
5011 gboolean is_rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
5012 gboolean tab_pos = get_effective_tab_pos (GTK_NOTEBOOK (widget));
5017 case GTK_POS_BOTTOM:
5019 return (search_direction == STEP_PREV);
5021 return (search_direction == STEP_NEXT);
5026 return (search_direction == STEP_PREV);
5034 gtk_notebook_calculate_tabs_allocation (GtkNotebook *notebook,
5039 gint *remaining_space,
5040 gint *expanded_tabs,
5045 GtkContainer *container;
5046 GtkNotebookPrivate *priv;
5047 GtkNotebookPage *page;
5048 gboolean allocate_at_bottom;
5049 gint tab_overlap, tab_pos, tab_extra_space;
5050 gint left_x, right_x, top_y, bottom_y, anchor;
5051 gint xthickness, ythickness;
5052 gboolean gap_left, packing_changed;
5053 GtkAllocation child_allocation = { 0, };
5054 gboolean allocation_changed = FALSE;
5056 widget = GTK_WIDGET (notebook);
5057 container = GTK_CONTAINER (notebook);
5058 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
5059 gtk_widget_style_get (widget, "tab-overlap", &tab_overlap, NULL);
5060 tab_pos = get_effective_tab_pos (notebook);
5061 allocate_at_bottom = get_allocate_at_bottom (widget, direction);
5064 child_allocation.x = widget->allocation.x + container->border_width;
5065 child_allocation.y = widget->allocation.y + container->border_width;
5067 xthickness = widget->style->xthickness;
5068 ythickness = widget->style->ythickness;
5072 case GTK_POS_BOTTOM:
5073 child_allocation.y = widget->allocation.y + widget->allocation.height -
5074 notebook->cur_page->requisition.height - container->border_width;
5077 child_allocation.x = (allocate_at_bottom) ? max : min;
5078 child_allocation.height = notebook->cur_page->requisition.height;
5079 anchor = child_allocation.x;
5083 child_allocation.x = widget->allocation.x + widget->allocation.width -
5084 notebook->cur_page->requisition.width - container->border_width;
5087 child_allocation.y = (allocate_at_bottom) ? max : min;
5088 child_allocation.width = notebook->cur_page->requisition.width;
5089 anchor = child_allocation.y;
5093 left_x = CLAMP (priv->mouse_x - priv->drag_offset_x,
5094 min, max - notebook->cur_page->allocation.width);
5095 top_y = CLAMP (priv->mouse_y - priv->drag_offset_y,
5096 min, max - notebook->cur_page->allocation.height);
5097 right_x = left_x + notebook->cur_page->allocation.width;
5098 bottom_y = top_y + notebook->cur_page->allocation.height;
5099 gap_left = packing_changed = FALSE;
5101 while (*children && *children != last_child)
5103 page = (*children)->data;
5105 if (direction == STEP_NEXT && page->pack != GTK_PACK_START)
5109 else if (priv->operation == DRAG_OPERATION_REORDER)
5110 packing_changed = TRUE;
5113 if (direction == STEP_NEXT)
5114 *children = gtk_notebook_search_page (notebook, *children, direction, TRUE);
5117 *children = (*children)->next;
5119 if (page->pack != GTK_PACK_END || !GTK_WIDGET_VISIBLE (page->child))
5123 if (!NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page))
5126 tab_extra_space = 0;
5127 if (*expanded_tabs && (showarrow || page->expand || notebook->homogeneous))
5129 tab_extra_space = *remaining_space / *expanded_tabs;
5130 *remaining_space -= tab_extra_space;
5137 case GTK_POS_BOTTOM:
5138 child_allocation.width = page->requisition.width + tab_overlap + tab_extra_space;
5140 /* make sure that the reordered tab doesn't go past the last position */
5141 if (priv->operation == DRAG_OPERATION_REORDER &&
5142 !gap_left && packing_changed)
5144 if (!allocate_at_bottom)
5146 if ((notebook->cur_page->pack == GTK_PACK_START && left_x >= anchor) ||
5147 (notebook->cur_page->pack == GTK_PACK_END && left_x < anchor))
5149 left_x = priv->drag_window_x = anchor;
5150 anchor += notebook->cur_page->allocation.width - tab_overlap;
5155 if ((notebook->cur_page->pack == GTK_PACK_START && right_x <= anchor) ||
5156 (notebook->cur_page->pack == GTK_PACK_END && right_x > anchor))
5158 anchor -= notebook->cur_page->allocation.width;
5159 left_x = priv->drag_window_x = anchor;
5160 anchor += tab_overlap;
5167 if (priv->operation == DRAG_OPERATION_REORDER && page == notebook->cur_page)
5169 priv->drag_window_x = left_x;
5170 priv->drag_window_y = child_allocation.y;
5174 if (allocate_at_bottom)
5175 anchor -= child_allocation.width;
5177 if (priv->operation == DRAG_OPERATION_REORDER && page->pack == notebook->cur_page->pack)
5179 if (!allocate_at_bottom &&
5181 left_x <= anchor + child_allocation.width / 2)
5182 anchor += notebook->cur_page->allocation.width - tab_overlap;
5183 else if (allocate_at_bottom &&
5184 right_x >= anchor + child_allocation.width / 2 &&
5185 right_x <= anchor + child_allocation.width)
5186 anchor -= notebook->cur_page->allocation.width - tab_overlap;
5189 child_allocation.x = anchor;
5195 child_allocation.height = page->requisition.height + tab_overlap + tab_extra_space;
5197 /* make sure that the reordered tab doesn't go past the last position */
5198 if (priv->operation == DRAG_OPERATION_REORDER &&
5199 !gap_left && packing_changed)
5201 if (!allocate_at_bottom &&
5202 ((notebook->cur_page->pack == GTK_PACK_START && top_y >= anchor) ||
5203 (notebook->cur_page->pack == GTK_PACK_END && top_y < anchor)))
5205 top_y = priv->drag_window_y = anchor;
5206 anchor += notebook->cur_page->allocation.height - tab_overlap;
5212 if (priv->operation == DRAG_OPERATION_REORDER && page == notebook->cur_page)
5214 priv->drag_window_x = child_allocation.x;
5215 priv->drag_window_y = top_y;
5219 if (allocate_at_bottom)
5220 anchor -= child_allocation.height;
5222 if (priv->operation == DRAG_OPERATION_REORDER && page->pack == notebook->cur_page->pack)
5224 if (!allocate_at_bottom &&
5226 top_y <= anchor + child_allocation.height / 2)
5227 anchor += notebook->cur_page->allocation.height - tab_overlap;
5228 else if (allocate_at_bottom &&
5229 bottom_y >= anchor + child_allocation.height / 2 &&
5230 bottom_y <= anchor + child_allocation.height)
5231 anchor -= notebook->cur_page->allocation.height - tab_overlap;
5234 child_allocation.y = anchor;
5240 if ((priv->operation != DRAG_OPERATION_REORDER || page != notebook->cur_page) &&
5241 (page->allocation.x != child_allocation.x ||
5242 page->allocation.y != child_allocation.y ||
5243 page->allocation.width != child_allocation.width ||
5244 page->allocation.height != child_allocation.height))
5245 allocation_changed = TRUE;
5247 page->allocation = child_allocation;
5249 if (page == notebook->cur_page)
5251 if (priv->operation == DRAG_OPERATION_REORDER ||
5252 priv->operation == DRAG_OPERATION_DETACH)
5254 /* needs to be allocated at 0,0
5255 * to be shown in the drag window */
5256 page->allocation.x = 0;
5257 page->allocation.y = 0;
5265 page->allocation.y += ythickness;
5267 case GTK_POS_BOTTOM:
5268 page->allocation.height = MAX (1, page->allocation.height - ythickness);
5271 page->allocation.x += xthickness;
5274 page->allocation.width = MAX (1, page->allocation.width - xthickness);
5279 /* calculate whether to leave a gap based on reorder operation or not */
5283 case GTK_POS_BOTTOM:
5284 if (priv->operation != DRAG_OPERATION_REORDER ||
5285 (priv->operation == DRAG_OPERATION_REORDER && page != notebook->cur_page))
5287 if (priv->operation == DRAG_OPERATION_REORDER)
5289 if (page->pack == notebook->cur_page->pack &&
5290 !allocate_at_bottom &&
5291 left_x > anchor + child_allocation.width / 2 &&
5292 left_x <= anchor + child_allocation.width)
5293 anchor += notebook->cur_page->allocation.width - tab_overlap;
5294 else if (page->pack == notebook->cur_page->pack &&
5295 allocate_at_bottom &&
5296 right_x >= anchor &&
5297 right_x <= anchor + child_allocation.width / 2)
5298 anchor -= notebook->cur_page->allocation.width - tab_overlap;
5301 if (!allocate_at_bottom)
5302 anchor += child_allocation.width - tab_overlap;
5304 anchor += tab_overlap;
5310 if (priv->operation != DRAG_OPERATION_REORDER ||
5311 (priv->operation == DRAG_OPERATION_REORDER && page != notebook->cur_page))
5313 if (priv->operation == DRAG_OPERATION_REORDER)
5315 if (page->pack == notebook->cur_page->pack &&
5316 !allocate_at_bottom &&
5317 top_y >= anchor + child_allocation.height / 2 &&
5318 top_y <= anchor + child_allocation.height)
5319 anchor += notebook->cur_page->allocation.height - tab_overlap;
5320 else if (page->pack == notebook->cur_page->pack &&
5321 allocate_at_bottom &&
5322 bottom_y >= anchor &&
5323 bottom_y <= anchor + child_allocation.height / 2)
5324 anchor -= notebook->cur_page->allocation.height - tab_overlap;
5327 if (!allocate_at_bottom)
5328 anchor += child_allocation.height - tab_overlap;
5330 anchor += tab_overlap;
5336 /* set child visible */
5337 if (page->tab_label)
5338 gtk_widget_set_child_visible (page->tab_label, TRUE);
5341 /* Don't move the current tab past the last position during tabs reordering */
5343 priv->operation == DRAG_OPERATION_REORDER &&
5344 ((direction == STEP_NEXT && notebook->cur_page->pack == GTK_PACK_START) ||
5345 ((direction == STEP_PREV || packing_changed) && notebook->cur_page->pack == GTK_PACK_END)))
5350 case GTK_POS_BOTTOM:
5351 if (allocate_at_bottom)
5352 anchor -= notebook->cur_page->allocation.width;
5354 if ((!allocate_at_bottom && priv->drag_window_x > anchor) ||
5355 (allocate_at_bottom && priv->drag_window_x < anchor))
5356 priv->drag_window_x = anchor;
5360 if (allocate_at_bottom)
5361 anchor -= notebook->cur_page->allocation.height;
5363 if ((!allocate_at_bottom && priv->drag_window_y > anchor) ||
5364 (allocate_at_bottom && priv->drag_window_y < anchor))
5365 priv->drag_window_y = anchor;
5370 return allocation_changed;
5374 gtk_notebook_pages_allocate (GtkNotebook *notebook)
5376 GList *children = NULL;
5377 GList *last_child = NULL;
5378 gboolean showarrow = FALSE;
5379 gint tab_space, min, max, remaining_space;
5380 gint expanded_tabs, operation;
5382 if (!notebook->show_tabs || !notebook->children || !notebook->cur_page)
5385 min = max = tab_space = remaining_space = 0;
5388 gtk_notebook_tab_space (notebook, &showarrow,
5389 &min, &max, &tab_space);
5391 gtk_notebook_calculate_shown_tabs (notebook, showarrow,
5392 min, max, tab_space, &last_child,
5393 &expanded_tabs, &remaining_space);
5395 children = notebook->first_tab;
5396 gtk_notebook_calculate_tabs_allocation (notebook, &children, last_child,
5397 showarrow, STEP_NEXT,
5398 &remaining_space, &expanded_tabs, min, max);
5399 if (children && children != last_child)
5401 children = notebook->children;
5402 gtk_notebook_calculate_tabs_allocation (notebook, &children, last_child,
5403 showarrow, STEP_PREV,
5404 &remaining_space, &expanded_tabs, min, max);
5407 children = notebook->children;
5411 gtk_notebook_page_allocate (notebook, GTK_NOTEBOOK_PAGE (children));
5412 children = children->next;
5415 operation = GTK_NOTEBOOK_GET_PRIVATE (notebook)->operation;
5417 if (!notebook->first_tab)
5418 notebook->first_tab = notebook->children;
5420 gtk_notebook_redraw_tabs (notebook);
5424 gtk_notebook_page_allocate (GtkNotebook *notebook,
5425 GtkNotebookPage *page)
5427 GtkWidget *widget = GTK_WIDGET (notebook);
5428 GtkAllocation child_allocation;
5429 GtkRequisition tab_requisition;
5435 gint tab_pos = get_effective_tab_pos (notebook);
5437 if (!page->tab_label)
5440 xthickness = widget->style->xthickness;
5441 ythickness = widget->style->ythickness;
5443 gtk_widget_get_child_requisition (page->tab_label, &tab_requisition);
5444 gtk_widget_style_get (widget,
5445 "focus-line-width", &focus_width,
5446 "tab-curvature", &tab_curvature,
5451 case GTK_POS_BOTTOM:
5452 padding = tab_curvature + focus_width + notebook->tab_hborder;
5455 child_allocation.x = xthickness + focus_width + notebook->tab_hborder;
5456 child_allocation.width = MAX (1, page->allocation.width - 2 * child_allocation.x);
5457 child_allocation.x += page->allocation.x;
5461 child_allocation.x = page->allocation.x +
5462 (page->allocation.width - tab_requisition.width) / 2;
5464 child_allocation.width = tab_requisition.width;
5467 child_allocation.y = notebook->tab_vborder + focus_width + page->allocation.y;
5469 if (tab_pos == GTK_POS_TOP)
5470 child_allocation.y += ythickness;
5472 child_allocation.height = MAX (1, (page->allocation.height - ythickness -
5473 2 * (notebook->tab_vborder + focus_width)));
5477 padding = tab_curvature + focus_width + notebook->tab_vborder;
5480 child_allocation.y = ythickness + padding;
5481 child_allocation.height = MAX (1, (page->allocation.height -
5482 2 * child_allocation.y));
5483 child_allocation.y += page->allocation.y;
5487 child_allocation.y = page->allocation.y +
5488 (page->allocation.height - tab_requisition.height) / 2;
5490 child_allocation.height = tab_requisition.height;
5493 child_allocation.x = notebook->tab_hborder + focus_width + page->allocation.x;
5495 if (tab_pos == GTK_POS_LEFT)
5496 child_allocation.x += xthickness;
5498 child_allocation.width = MAX (1, (page->allocation.width - xthickness -
5499 2 * (notebook->tab_hborder + focus_width)));
5503 gtk_widget_size_allocate (page->tab_label, &child_allocation);
5507 gtk_notebook_calc_tabs (GtkNotebook *notebook,
5513 GtkNotebookPage *page = NULL;
5515 GList *last_list = NULL;
5516 GList *last_calculated_child = NULL;
5518 gint tab_pos = get_effective_tab_pos (notebook);
5519 guint real_direction;
5525 pack = GTK_NOTEBOOK_PAGE (start)->pack;
5526 if (pack == GTK_PACK_END)
5527 real_direction = (direction == STEP_PREV) ? STEP_NEXT : STEP_PREV;
5529 real_direction = direction;
5536 case GTK_POS_BOTTOM:
5539 page = children->data;
5540 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) &&
5541 GTK_WIDGET_VISIBLE (page->child))
5543 if (page->pack == pack)
5545 *tab_space -= page->requisition.width;
5546 if (*tab_space < 0 || children == *end)
5550 *tab_space = - (*tab_space +
5551 page->requisition.width);
5553 if (*tab_space == 0 && direction == STEP_PREV)
5554 children = last_calculated_child;
5561 last_calculated_child = children;
5563 last_list = children;
5565 if (real_direction == STEP_NEXT)
5566 children = children->next;
5568 children = children->prev;
5575 page = children->data;
5576 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) &&
5577 GTK_WIDGET_VISIBLE (page->child))
5579 if (page->pack == pack)
5581 *tab_space -= page->requisition.height;
5582 if (*tab_space < 0 || children == *end)
5586 *tab_space = - (*tab_space +
5587 page->requisition.height);
5589 if (*tab_space == 0 && direction == STEP_PREV)
5590 children = last_calculated_child;
5597 last_calculated_child = children;
5599 last_list = children;
5601 if (real_direction == STEP_NEXT)
5602 children = children->next;
5604 children = children->prev;
5608 if (real_direction == STEP_PREV)
5610 pack = (pack == GTK_PACK_END) ? GTK_PACK_START : GTK_PACK_END;
5611 real_direction = STEP_PREV;
5612 children = last_list;
5617 gtk_notebook_update_tab_states (GtkNotebook *notebook)
5621 for (list = notebook->children; list != NULL; list = list->next)
5623 GtkNotebookPage *page = list->data;
5625 if (page->tab_label)
5627 if (page == notebook->cur_page)
5628 gtk_widget_set_state (page->tab_label, GTK_STATE_NORMAL);
5630 gtk_widget_set_state (page->tab_label, GTK_STATE_ACTIVE);
5635 /* Private GtkNotebook Page Switch Methods:
5637 * gtk_notebook_real_switch_page
5640 gtk_notebook_real_switch_page (GtkNotebook *notebook,
5641 GtkNotebookPage *page,
5644 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
5645 g_return_if_fail (page != NULL);
5647 if (notebook->cur_page == page || !GTK_WIDGET_VISIBLE (page->child))
5650 if (notebook->cur_page)
5651 gtk_widget_set_child_visible (notebook->cur_page->child, FALSE);
5653 notebook->cur_page = page;
5655 if (!notebook->focus_tab ||
5656 notebook->focus_tab->data != (gpointer) notebook->cur_page)
5657 notebook->focus_tab =
5658 g_list_find (notebook->children, notebook->cur_page);
5660 gtk_widget_set_child_visible (notebook->cur_page->child, TRUE);
5662 /* If the focus was on the previous page, move it to the first
5663 * element on the new page, if possible, or if not, to the
5666 if (notebook->child_has_focus)
5668 if (notebook->cur_page->last_focus_child &&
5669 gtk_widget_is_ancestor (notebook->cur_page->last_focus_child, notebook->cur_page->child))
5670 gtk_widget_grab_focus (notebook->cur_page->last_focus_child);
5672 if (!gtk_widget_child_focus (notebook->cur_page->child, GTK_DIR_TAB_FORWARD))
5673 gtk_widget_grab_focus (GTK_WIDGET (notebook));
5676 gtk_notebook_update_tab_states (notebook);
5677 gtk_widget_queue_resize (GTK_WIDGET (notebook));
5678 g_object_notify (G_OBJECT (notebook), "page");
5681 /* Private GtkNotebook Page Switch Functions:
5683 * gtk_notebook_switch_page
5684 * gtk_notebook_page_select
5685 * gtk_notebook_switch_focus_tab
5686 * gtk_notebook_menu_switch_page
5689 gtk_notebook_switch_page (GtkNotebook *notebook,
5690 GtkNotebookPage *page,
5693 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
5694 g_return_if_fail (page != NULL);
5696 if (notebook->cur_page == page)
5700 page_num = g_list_index (notebook->children, page);
5702 g_signal_emit (notebook,
5703 notebook_signals[SWITCH_PAGE],
5710 gtk_notebook_page_select (GtkNotebook *notebook,
5711 gboolean move_focus)
5713 GtkNotebookPage *page;
5714 GtkDirectionType dir = GTK_DIR_DOWN; /* Quiet GCC */
5715 gint tab_pos = get_effective_tab_pos (notebook);
5717 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
5719 if (!notebook->focus_tab)
5722 page = notebook->focus_tab->data;
5723 gtk_notebook_switch_page (notebook, page, -1);
5732 case GTK_POS_BOTTOM:
5736 dir = GTK_DIR_RIGHT;
5743 if (gtk_widget_child_focus (page->child, dir))
5750 gtk_notebook_switch_focus_tab (GtkNotebook *notebook,
5754 GtkNotebookPage *page;
5756 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
5758 if (notebook->focus_tab == new_child)
5761 old_child = notebook->focus_tab;
5762 notebook->focus_tab = new_child;
5764 if (notebook->scrollable)
5765 gtk_notebook_redraw_arrows (notebook);
5767 if (!notebook->show_tabs || !notebook->focus_tab)
5770 page = notebook->focus_tab->data;
5771 if (GTK_WIDGET_MAPPED (page->tab_label))
5772 gtk_notebook_redraw_tabs (notebook);
5774 gtk_notebook_pages_allocate (notebook);
5776 gtk_notebook_switch_page (notebook, page,
5777 g_list_index (notebook->children, page));
5781 gtk_notebook_menu_switch_page (GtkWidget *widget,
5782 GtkNotebookPage *page)
5784 GtkNotebook *notebook;
5788 g_return_if_fail (widget != NULL);
5789 g_return_if_fail (page != NULL);
5791 notebook = GTK_NOTEBOOK (gtk_menu_get_attach_widget
5792 (GTK_MENU (widget->parent)));
5794 if (notebook->cur_page == page)
5798 children = notebook->children;
5799 while (children && children->data != page)
5801 children = children->next;
5805 g_signal_emit (notebook,
5806 notebook_signals[SWITCH_PAGE],
5812 /* Private GtkNotebook Menu Functions:
5814 * gtk_notebook_menu_item_create
5815 * gtk_notebook_menu_label_unparent
5816 * gtk_notebook_menu_detacher
5819 gtk_notebook_menu_item_create (GtkNotebook *notebook,
5822 GtkNotebookPage *page;
5823 GtkWidget *menu_item;
5826 if (page->default_menu)
5828 if (page->tab_label && GTK_IS_LABEL (page->tab_label))
5829 page->menu_label = gtk_label_new (GTK_LABEL (page->tab_label)->label);
5831 page->menu_label = gtk_label_new ("");
5832 gtk_misc_set_alignment (GTK_MISC (page->menu_label), 0.0, 0.5);
5835 gtk_widget_show (page->menu_label);
5836 menu_item = gtk_menu_item_new ();
5837 gtk_container_add (GTK_CONTAINER (menu_item), page->menu_label);
5838 gtk_menu_shell_insert (GTK_MENU_SHELL (notebook->menu), menu_item,
5839 gtk_notebook_real_page_position (notebook, list));
5840 g_signal_connect (menu_item, "activate",
5841 G_CALLBACK (gtk_notebook_menu_switch_page), page);
5842 if (GTK_WIDGET_VISIBLE (page->child))
5843 gtk_widget_show (menu_item);
5847 gtk_notebook_menu_label_unparent (GtkWidget *widget,
5850 gtk_widget_unparent (GTK_BIN (widget)->child);
5851 GTK_BIN (widget)->child = NULL;
5855 gtk_notebook_menu_detacher (GtkWidget *widget,
5858 GtkNotebook *notebook;
5860 g_return_if_fail (GTK_IS_NOTEBOOK (widget));
5862 notebook = GTK_NOTEBOOK (widget);
5863 g_return_if_fail (notebook->menu == (GtkWidget*) menu);
5865 notebook->menu = NULL;
5868 /* Private GtkNotebook Setter Functions:
5870 * gtk_notebook_set_homogeneous_tabs_internal
5871 * gtk_notebook_set_tab_border_internal
5872 * gtk_notebook_set_tab_hborder_internal
5873 * gtk_notebook_set_tab_vborder_internal
5876 gtk_notebook_set_homogeneous_tabs_internal (GtkNotebook *notebook,
5877 gboolean homogeneous)
5879 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
5881 if (homogeneous == notebook->homogeneous)
5884 notebook->homogeneous = homogeneous;
5885 gtk_widget_queue_resize (GTK_WIDGET (notebook));
5887 g_object_notify (G_OBJECT (notebook), "homogeneous");
5891 gtk_notebook_set_tab_border_internal (GtkNotebook *notebook,
5894 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
5896 notebook->tab_hborder = border_width;
5897 notebook->tab_vborder = border_width;
5899 if (GTK_WIDGET_VISIBLE (notebook) && notebook->show_tabs)
5900 gtk_widget_queue_resize (GTK_WIDGET (notebook));
5902 g_object_freeze_notify (G_OBJECT (notebook));
5903 g_object_notify (G_OBJECT (notebook), "tab-hborder");
5904 g_object_notify (G_OBJECT (notebook), "tab-vborder");
5905 g_object_thaw_notify (G_OBJECT (notebook));
5909 gtk_notebook_set_tab_hborder_internal (GtkNotebook *notebook,
5912 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
5914 if (notebook->tab_hborder == tab_hborder)
5917 notebook->tab_hborder = tab_hborder;
5919 if (GTK_WIDGET_VISIBLE (notebook) && notebook->show_tabs)
5920 gtk_widget_queue_resize (GTK_WIDGET (notebook));
5922 g_object_notify (G_OBJECT (notebook), "tab-hborder");
5926 gtk_notebook_set_tab_vborder_internal (GtkNotebook *notebook,
5929 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
5931 if (notebook->tab_vborder == tab_vborder)
5934 notebook->tab_vborder = tab_vborder;
5936 if (GTK_WIDGET_VISIBLE (notebook) && notebook->show_tabs)
5937 gtk_widget_queue_resize (GTK_WIDGET (notebook));
5939 g_object_notify (G_OBJECT (notebook), "tab-vborder");
5942 /* Public GtkNotebook Page Insert/Remove Methods :
5944 * gtk_notebook_append_page
5945 * gtk_notebook_append_page_menu
5946 * gtk_notebook_prepend_page
5947 * gtk_notebook_prepend_page_menu
5948 * gtk_notebook_insert_page
5949 * gtk_notebook_insert_page_menu
5950 * gtk_notebook_remove_page
5953 * gtk_notebook_append_page:
5954 * @notebook: a #GtkNotebook
5955 * @child: the #GtkWidget to use as the contents of the page.
5956 * @tab_label: the #GtkWidget to be used as the label for the page,
5957 * or %NULL to use the default label, 'page N'.
5959 * Appends a page to @notebook.
5961 * Return value: the index (starting from 0) of the appended
5962 * page in the notebook, or -1 if function fails
5965 gtk_notebook_append_page (GtkNotebook *notebook,
5967 GtkWidget *tab_label)
5969 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
5970 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
5971 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
5973 return gtk_notebook_insert_page_menu (notebook, child, tab_label, NULL, -1);
5977 * gtk_notebook_append_page_menu:
5978 * @notebook: a #GtkNotebook
5979 * @child: the #GtkWidget to use as the contents of the page.
5980 * @tab_label: the #GtkWidget to be used as the label for the page,
5981 * or %NULL to use the default label, 'page N'.
5982 * @menu_label: the widget to use as a label for the page-switch
5983 * menu, if that is enabled. If %NULL, and @tab_label
5984 * is a #GtkLabel or %NULL, then the menu label will be
5985 * a newly created label with the same text as @tab_label;
5986 * If @tab_label is not a #GtkLabel, @menu_label must be
5987 * specified if the page-switch menu is to be used.
5989 * Appends a page to @notebook, specifying the widget to use as the
5990 * label in the popup menu.
5992 * Return value: the index (starting from 0) of the appended
5993 * page in the notebook, or -1 if function fails
5996 gtk_notebook_append_page_menu (GtkNotebook *notebook,
5998 GtkWidget *tab_label,
5999 GtkWidget *menu_label)
6001 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6002 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6003 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6004 g_return_val_if_fail (menu_label == NULL || GTK_IS_WIDGET (menu_label), -1);
6006 return gtk_notebook_insert_page_menu (notebook, child, tab_label, menu_label, -1);
6010 * gtk_notebook_prepend_page:
6011 * @notebook: a #GtkNotebook
6012 * @child: the #GtkWidget to use as the contents of the page.
6013 * @tab_label: the #GtkWidget to be used as the label for the page,
6014 * or %NULL to use the default label, 'page N'.
6016 * Prepends a page to @notebook.
6018 * Return value: the index (starting from 0) of the prepended
6019 * page in the notebook, or -1 if function fails
6022 gtk_notebook_prepend_page (GtkNotebook *notebook,
6024 GtkWidget *tab_label)
6026 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6027 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6028 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6030 return gtk_notebook_insert_page_menu (notebook, child, tab_label, NULL, 0);
6034 * gtk_notebook_prepend_page_menu:
6035 * @notebook: a #GtkNotebook
6036 * @child: the #GtkWidget to use as the contents of the page.
6037 * @tab_label: the #GtkWidget to be used as the label for the page,
6038 * or %NULL to use the default label, 'page N'.
6039 * @menu_label: the widget to use as a label for the page-switch
6040 * menu, if that is enabled. If %NULL, and @tab_label
6041 * is a #GtkLabel or %NULL, then the menu label will be
6042 * a newly created label with the same text as @tab_label;
6043 * If @tab_label is not a #GtkLabel, @menu_label must be
6044 * specified if the page-switch menu is to be used.
6046 * Prepends a page to @notebook, specifying the widget to use as the
6047 * label in the popup menu.
6049 * Return value: the index (starting from 0) of the prepended
6050 * page in the notebook, or -1 if function fails
6053 gtk_notebook_prepend_page_menu (GtkNotebook *notebook,
6055 GtkWidget *tab_label,
6056 GtkWidget *menu_label)
6058 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6059 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6060 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6061 g_return_val_if_fail (menu_label == NULL || GTK_IS_WIDGET (menu_label), -1);
6063 return gtk_notebook_insert_page_menu (notebook, child, tab_label, menu_label, 0);
6067 * gtk_notebook_insert_page:
6068 * @notebook: a #GtkNotebook
6069 * @child: the #GtkWidget to use as the contents of the page.
6070 * @tab_label: the #GtkWidget to be used as the label for the page,
6071 * or %NULL to use the default label, 'page N'.
6072 * @position: the index (starting at 0) at which to insert the page,
6073 * or -1 to append the page after all other pages.
6075 * Insert a page into @notebook at the given position.
6077 * Return value: the index (starting from 0) of the inserted
6078 * page in the notebook, or -1 if function fails
6081 gtk_notebook_insert_page (GtkNotebook *notebook,
6083 GtkWidget *tab_label,
6086 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6087 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6088 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6090 return gtk_notebook_insert_page_menu (notebook, child, tab_label, NULL, position);
6095 gtk_notebook_page_compare_tab (gconstpointer a,
6098 return (((GtkNotebookPage *) a)->tab_label != b);
6102 gtk_notebook_mnemonic_activate_switch_page (GtkWidget *child,
6106 GtkNotebook *notebook = GTK_NOTEBOOK (data);
6109 list = g_list_find_custom (notebook->children, child,
6110 gtk_notebook_page_compare_tab);
6113 GtkNotebookPage *page = list->data;
6115 gtk_widget_grab_focus (GTK_WIDGET (notebook)); /* Do this first to avoid focusing new page */
6116 gtk_notebook_switch_page (notebook, page, -1);
6117 focus_tabs_in (notebook);
6124 * gtk_notebook_insert_page_menu:
6125 * @notebook: a #GtkNotebook
6126 * @child: the #GtkWidget to use as the contents of the page.
6127 * @tab_label: the #GtkWidget to be used as the label for the page,
6128 * or %NULL to use the default label, 'page N'.
6129 * @menu_label: the widget to use as a label for the page-switch
6130 * menu, if that is enabled. If %NULL, and @tab_label
6131 * is a #GtkLabel or %NULL, then the menu label will be
6132 * a newly created label with the same text as @tab_label;
6133 * If @tab_label is not a #GtkLabel, @menu_label must be
6134 * specified if the page-switch menu is to be used.
6135 * @position: the index (starting at 0) at which to insert the page,
6136 * or -1 to append the page after all other pages.
6138 * Insert a page into @notebook at the given position, specifying
6139 * the widget to use as the label in the popup menu.
6141 * Return value: the index (starting from 0) of the inserted
6142 * page in the notebook
6145 gtk_notebook_insert_page_menu (GtkNotebook *notebook,
6147 GtkWidget *tab_label,
6148 GtkWidget *menu_label,
6151 GtkNotebookClass *class;
6153 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6154 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6155 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6156 g_return_val_if_fail (menu_label == NULL || GTK_IS_WIDGET (menu_label), -1);
6158 class = GTK_NOTEBOOK_GET_CLASS (notebook);
6160 return (class->insert_page) (notebook, child, tab_label, menu_label, position);
6164 * gtk_notebook_remove_page:
6165 * @notebook: a #GtkNotebook.
6166 * @page_num: the index of a notebook page, starting
6167 * from 0. If -1, the last page will
6170 * Removes a page from the notebook given its index
6174 gtk_notebook_remove_page (GtkNotebook *notebook,
6179 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6182 list = g_list_nth (notebook->children, page_num);
6184 list = g_list_last (notebook->children);
6187 gtk_container_remove (GTK_CONTAINER (notebook),
6188 ((GtkNotebookPage *) list->data)->child);
6191 /* Public GtkNotebook Page Switch Methods :
6192 * gtk_notebook_get_current_page
6193 * gtk_notebook_page_num
6194 * gtk_notebook_set_current_page
6195 * gtk_notebook_next_page
6196 * gtk_notebook_prev_page
6199 * gtk_notebook_get_current_page:
6200 * @notebook: a #GtkNotebook
6202 * Returns the page number of the current page.
6204 * Return value: the index (starting from 0) of the current
6205 * page in the notebook. If the notebook has no pages, then
6206 * -1 will be returned.
6209 gtk_notebook_get_current_page (GtkNotebook *notebook)
6211 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6213 if (!notebook->cur_page)
6216 return g_list_index (notebook->children, notebook->cur_page);
6220 * gtk_notebook_get_nth_page:
6221 * @notebook: a #GtkNotebook
6222 * @page_num: the index of a page in the noteobok, or -1
6223 * to get the last page.
6225 * Returns the child widget contained in page number @page_num.
6227 * Return value: the child widget, or %NULL if @page_num is
6231 gtk_notebook_get_nth_page (GtkNotebook *notebook,
6234 GtkNotebookPage *page;
6237 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
6240 list = g_list_nth (notebook->children, page_num);
6242 list = g_list_last (notebook->children);
6254 * gtk_notebook_get_n_pages:
6255 * @notebook: a #GtkNotebook
6257 * Gets the number of pages in a notebook.
6259 * Return value: the number of pages in the notebook.
6264 gtk_notebook_get_n_pages (GtkNotebook *notebook)
6266 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), 0);
6268 return g_list_length (notebook->children);
6272 * gtk_notebook_page_num:
6273 * @notebook: a #GtkNotebook
6274 * @child: a #GtkWidget
6276 * Finds the index of the page which contains the given child
6279 * Return value: the index of the page containing @child, or
6280 * -1 if @child is not in the notebook.
6283 gtk_notebook_page_num (GtkNotebook *notebook,
6289 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6292 children = notebook->children;
6295 GtkNotebookPage *page = children->data;
6297 if (page->child == child)
6300 children = children->next;
6308 * gtk_notebook_set_current_page:
6309 * @notebook: a #GtkNotebook
6310 * @page_num: index of the page to switch to, starting from 0.
6311 * If negative, the last page will be used. If greater
6312 * than the number of pages in the notebook, nothing
6315 * Switches to the page number @page_num.
6317 * Note that due to historical reasons, GtkNotebook refuses
6318 * to switch to a page unless the child widget is visible.
6319 * Therefore, it is recommended to show child widgets before
6320 * adding them to a notebook.
6323 gtk_notebook_set_current_page (GtkNotebook *notebook,
6328 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6331 list = g_list_nth (notebook->children, page_num);
6333 list = g_list_last (notebook->children);
6335 page_num = g_list_index (notebook->children, list);
6338 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (list), page_num);
6342 * gtk_notebook_next_page:
6343 * @notebook: a #GtkNotebook
6345 * Switches to the next page. Nothing happens if the current page is
6349 gtk_notebook_next_page (GtkNotebook *notebook)
6353 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6355 list = g_list_find (notebook->children, notebook->cur_page);
6359 list = gtk_notebook_search_page (notebook, list, STEP_NEXT, TRUE);
6363 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (list), -1);
6367 * gtk_notebook_prev_page:
6368 * @notebook: a #GtkNotebook
6370 * Switches to the previous page. Nothing happens if the current page
6371 * is the first page.
6374 gtk_notebook_prev_page (GtkNotebook *notebook)
6378 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6380 list = g_list_find (notebook->children, notebook->cur_page);
6384 list = gtk_notebook_search_page (notebook, list, STEP_PREV, TRUE);
6388 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (list), -1);
6391 /* Public GtkNotebook/Tab Style Functions
6393 * gtk_notebook_set_show_border
6394 * gtk_notebook_set_show_tabs
6395 * gtk_notebook_set_tab_pos
6396 * gtk_notebook_set_homogeneous_tabs
6397 * gtk_notebook_set_tab_border
6398 * gtk_notebook_set_tab_hborder
6399 * gtk_notebook_set_tab_vborder
6400 * gtk_notebook_set_scrollable
6403 * gtk_notebook_set_show_border:
6404 * @notebook: a #GtkNotebook
6405 * @show_border: %TRUE if a bevel should be drawn around the notebook.
6407 * Sets whether a bevel will be drawn around the notebook pages.
6408 * This only has a visual effect when the tabs are not shown.
6409 * See gtk_notebook_set_show_tabs().
6412 gtk_notebook_set_show_border (GtkNotebook *notebook,
6413 gboolean show_border)
6415 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6417 if (notebook->show_border != show_border)
6419 notebook->show_border = show_border;
6421 if (GTK_WIDGET_VISIBLE (notebook))
6422 gtk_widget_queue_resize (GTK_WIDGET (notebook));
6424 g_object_notify (G_OBJECT (notebook), "show-border");
6429 * gtk_notebook_get_show_border:
6430 * @notebook: a #GtkNotebook
6432 * Returns whether a bevel will be drawn around the notebook pages. See
6433 * gtk_notebook_set_show_border().
6435 * Return value: %TRUE if the bevel is drawn
6438 gtk_notebook_get_show_border (GtkNotebook *notebook)
6440 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
6442 return notebook->show_border;
6446 * gtk_notebook_set_show_tabs:
6447 * @notebook: a #GtkNotebook
6448 * @show_tabs: %TRUE if the tabs should be shown.
6450 * Sets whether to show the tabs for the notebook or not.
6453 gtk_notebook_set_show_tabs (GtkNotebook *notebook,
6456 GtkNotebookPage *page;
6459 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6461 show_tabs = show_tabs != FALSE;
6463 if (notebook->show_tabs == show_tabs)
6466 notebook->show_tabs = show_tabs;
6467 children = notebook->children;
6471 GTK_WIDGET_UNSET_FLAGS (notebook, GTK_CAN_FOCUS);
6475 page = children->data;
6476 children = children->next;
6477 if (page->default_tab)
6479 gtk_widget_destroy (page->tab_label);
6480 page->tab_label = NULL;
6483 gtk_widget_hide (page->tab_label);
6488 GTK_WIDGET_SET_FLAGS (notebook, GTK_CAN_FOCUS);
6489 gtk_notebook_update_labels (notebook);
6491 gtk_widget_queue_resize (GTK_WIDGET (notebook));
6493 g_object_notify (G_OBJECT (notebook), "show-tabs");
6497 * gtk_notebook_get_show_tabs:
6498 * @notebook: a #GtkNotebook
6500 * Returns whether the tabs of the notebook are shown. See
6501 * gtk_notebook_set_show_tabs().
6503 * Return value: %TRUE if the tabs are shown
6506 gtk_notebook_get_show_tabs (GtkNotebook *notebook)
6508 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
6510 return notebook->show_tabs;
6514 * gtk_notebook_set_tab_pos:
6515 * @notebook: a #GtkNotebook.
6516 * @pos: the edge to draw the tabs at.
6518 * Sets the edge at which the tabs for switching pages in the
6519 * notebook are drawn.
6522 gtk_notebook_set_tab_pos (GtkNotebook *notebook,
6523 GtkPositionType pos)
6525 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6527 if (notebook->tab_pos != pos)
6529 notebook->tab_pos = pos;
6530 if (GTK_WIDGET_VISIBLE (notebook))
6531 gtk_widget_queue_resize (GTK_WIDGET (notebook));
6534 g_object_notify (G_OBJECT (notebook), "tab-pos");
6538 * gtk_notebook_get_tab_pos:
6539 * @notebook: a #GtkNotebook
6541 * Gets the edge at which the tabs for switching pages in the
6542 * notebook are drawn.
6544 * Return value: the edge at which the tabs are drawn
6547 gtk_notebook_get_tab_pos (GtkNotebook *notebook)
6549 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), GTK_POS_TOP);
6551 return notebook->tab_pos;
6555 * gtk_notebook_set_homogeneous_tabs:
6556 * @notebook: a #GtkNotebook
6557 * @homogeneous: %TRUE if all tabs should be the same size.
6559 * Sets whether the tabs must have all the same size or not.
6562 gtk_notebook_set_homogeneous_tabs (GtkNotebook *notebook,
6563 gboolean homogeneous)
6565 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6567 gtk_notebook_set_homogeneous_tabs_internal (notebook, homogeneous);
6571 * gtk_notebook_set_tab_border:
6572 * @notebook: a #GtkNotebook
6573 * @border_width: width of the border around the tab labels.
6575 * Sets the width the border around the tab labels
6576 * in a notebook. This is equivalent to calling
6577 * gtk_notebook_set_tab_hborder (@notebook, @border_width) followed
6578 * by gtk_notebook_set_tab_vborder (@notebook, @border_width).
6581 gtk_notebook_set_tab_border (GtkNotebook *notebook,
6584 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6586 gtk_notebook_set_tab_border_internal (notebook, border_width);
6590 * gtk_notebook_set_tab_hborder:
6591 * @notebook: a #GtkNotebook
6592 * @tab_hborder: width of the horizontal border of tab labels.
6594 * Sets the width of the horizontal border of tab labels.
6597 gtk_notebook_set_tab_hborder (GtkNotebook *notebook,
6600 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6602 gtk_notebook_set_tab_hborder_internal (notebook, tab_hborder);
6606 * gtk_notebook_set_tab_vborder:
6607 * @notebook: a #GtkNotebook
6608 * @tab_vborder: width of the vertical border of tab labels.
6610 * Sets the width of the vertical border of tab labels.
6613 gtk_notebook_set_tab_vborder (GtkNotebook *notebook,
6616 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6618 gtk_notebook_set_tab_vborder_internal (notebook, tab_vborder);
6622 * gtk_notebook_set_scrollable:
6623 * @notebook: a #GtkNotebook
6624 * @scrollable: %TRUE if scroll arrows should be added
6626 * Sets whether the tab label area will have arrows for scrolling if
6627 * there are too many tabs to fit in the area.
6630 gtk_notebook_set_scrollable (GtkNotebook *notebook,
6631 gboolean scrollable)
6633 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6635 scrollable = (scrollable != FALSE);
6637 if (scrollable != notebook->scrollable)
6639 notebook->scrollable = scrollable;
6641 if (GTK_WIDGET_VISIBLE (notebook))
6642 gtk_widget_queue_resize (GTK_WIDGET (notebook));
6644 g_object_notify (G_OBJECT (notebook), "scrollable");
6649 * gtk_notebook_get_scrollable:
6650 * @notebook: a #GtkNotebook
6652 * Returns whether the tab label area has arrows for scrolling. See
6653 * gtk_notebook_set_scrollable().
6655 * Return value: %TRUE if arrows for scrolling are present
6658 gtk_notebook_get_scrollable (GtkNotebook *notebook)
6660 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
6662 return notebook->scrollable;
6665 /* Public GtkNotebook Popup Menu Methods:
6667 * gtk_notebook_popup_enable
6668 * gtk_notebook_popup_disable
6673 * gtk_notebook_popup_enable:
6674 * @notebook: a #GtkNotebook
6676 * Enables the popup menu: if the user clicks with the right mouse button on
6677 * the bookmarks, a menu with all the pages will be popped up.
6680 gtk_notebook_popup_enable (GtkNotebook *notebook)
6684 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6689 notebook->menu = gtk_menu_new ();
6690 for (list = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, FALSE);
6692 list = gtk_notebook_search_page (notebook, list, STEP_NEXT, FALSE))
6693 gtk_notebook_menu_item_create (notebook, list);
6695 gtk_notebook_update_labels (notebook);
6696 gtk_menu_attach_to_widget (GTK_MENU (notebook->menu),
6697 GTK_WIDGET (notebook),
6698 gtk_notebook_menu_detacher);
6700 g_object_notify (G_OBJECT (notebook), "enable-popup");
6704 * gtk_notebook_popup_disable:
6705 * @notebook: a #GtkNotebook
6707 * Disables the popup menu.
6710 gtk_notebook_popup_disable (GtkNotebook *notebook)
6712 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6714 if (!notebook->menu)
6717 gtk_container_foreach (GTK_CONTAINER (notebook->menu),
6718 (GtkCallback) gtk_notebook_menu_label_unparent, NULL);
6719 gtk_widget_destroy (notebook->menu);
6721 g_object_notify (G_OBJECT (notebook), "enable-popup");
6724 /* Public GtkNotebook Page Properties Functions:
6726 * gtk_notebook_get_tab_label
6727 * gtk_notebook_set_tab_label
6728 * gtk_notebook_set_tab_label_text
6729 * gtk_notebook_get_menu_label
6730 * gtk_notebook_set_menu_label
6731 * gtk_notebook_set_menu_label_text
6732 * gtk_notebook_set_tab_label_packing
6733 * gtk_notebook_query_tab_label_packing
6734 * gtk_notebook_get_tab_reorderable
6735 * gtk_notebook_set_tab_reorderable
6736 * gtk_notebook_get_tab_detachable
6737 * gtk_notebook_set_tab_detachable
6741 * gtk_notebook_get_tab_label:
6742 * @notebook: a #GtkNotebook
6745 * Returns the tab label widget for the page @child. %NULL is returned
6746 * if @child is not in @notebook or if no tab label has specifically
6747 * been set for @child.
6749 * Return value: the tab label
6752 gtk_notebook_get_tab_label (GtkNotebook *notebook,
6757 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
6758 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
6760 list = CHECK_FIND_CHILD (notebook, child);
6764 if (GTK_NOTEBOOK_PAGE (list)->default_tab)
6767 return GTK_NOTEBOOK_PAGE (list)->tab_label;
6771 * gtk_notebook_set_tab_label:
6772 * @notebook: a #GtkNotebook
6774 * @tab_label: the tab label widget to use, or %NULL for default tab
6777 * Changes the tab label for @child. If %NULL is specified
6778 * for @tab_label, then the page will have the label 'page N'.
6781 gtk_notebook_set_tab_label (GtkNotebook *notebook,
6783 GtkWidget *tab_label)
6785 GtkNotebookPage *page;
6788 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6789 g_return_if_fail (GTK_IS_WIDGET (child));
6791 list = CHECK_FIND_CHILD (notebook, child);
6795 /* a NULL pointer indicates a default_tab setting, otherwise
6796 * we need to set the associated label
6800 if (page->tab_label == tab_label)
6804 gtk_notebook_remove_tab_label (notebook, page);
6808 page->default_tab = FALSE;
6809 page->tab_label = tab_label;
6810 gtk_widget_set_parent (page->tab_label, GTK_WIDGET (notebook));
6814 page->default_tab = TRUE;
6815 page->tab_label = NULL;
6817 if (notebook->show_tabs)
6821 g_snprintf (string, sizeof(string), _("Page %u"),
6822 gtk_notebook_real_page_position (notebook, list));
6823 page->tab_label = gtk_label_new (string);
6824 gtk_widget_set_parent (page->tab_label, GTK_WIDGET (notebook));
6828 if (page->tab_label)
6829 page->mnemonic_activate_signal =
6830 g_signal_connect (page->tab_label,
6831 "mnemonic_activate",
6832 G_CALLBACK (gtk_notebook_mnemonic_activate_switch_page),
6835 if (notebook->show_tabs && GTK_WIDGET_VISIBLE (child))
6837 gtk_widget_show (page->tab_label);
6838 gtk_widget_queue_resize (GTK_WIDGET (notebook));
6841 gtk_notebook_update_tab_states (notebook);
6842 gtk_widget_child_notify (child, "tab-label");
6846 * gtk_notebook_set_tab_label_text:
6847 * @notebook: a #GtkNotebook
6849 * @tab_text: the label text
6851 * Creates a new label and sets it as the tab label for the page
6852 * containing @child.
6855 gtk_notebook_set_tab_label_text (GtkNotebook *notebook,
6857 const gchar *tab_text)
6859 GtkWidget *tab_label = NULL;
6861 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6864 tab_label = gtk_label_new (tab_text);
6865 gtk_notebook_set_tab_label (notebook, child, tab_label);
6866 gtk_widget_child_notify (child, "tab-label");
6870 * gtk_notebook_get_tab_label_text:
6871 * @notebook: a #GtkNotebook
6872 * @child: a widget contained in a page of @notebook
6874 * Retrieves the text of the tab label for the page containing
6877 * Returns value: the text of the tab label, or %NULL if the
6878 * tab label widget is not a #GtkLabel. The
6879 * string is owned by the widget and must not
6882 G_CONST_RETURN gchar *
6883 gtk_notebook_get_tab_label_text (GtkNotebook *notebook,
6886 GtkWidget *tab_label;
6888 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
6889 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
6891 tab_label = gtk_notebook_get_tab_label (notebook, child);
6893 if (tab_label && GTK_IS_LABEL (tab_label))
6894 return gtk_label_get_text (GTK_LABEL (tab_label));
6900 * gtk_notebook_get_menu_label:
6901 * @notebook: a #GtkNotebook
6902 * @child: a widget contained in a page of @notebook
6904 * Retrieves the menu label widget of the page containing @child.
6906 * Return value: the menu label, or %NULL if the
6907 * notebook page does not have a menu label other
6908 * than the default (the tab label).
6911 gtk_notebook_get_menu_label (GtkNotebook *notebook,
6916 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
6917 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
6919 list = CHECK_FIND_CHILD (notebook, child);
6923 if (GTK_NOTEBOOK_PAGE (list)->default_menu)
6926 return GTK_NOTEBOOK_PAGE (list)->menu_label;
6930 * gtk_notebook_set_menu_label:
6931 * @notebook: a #GtkNotebook
6932 * @child: the child widget
6933 * @menu_label: the menu label, or NULL for default
6935 * Changes the menu label for the page containing @child.
6938 gtk_notebook_set_menu_label (GtkNotebook *notebook,
6940 GtkWidget *menu_label)
6942 GtkNotebookPage *page;
6945 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6946 g_return_if_fail (GTK_IS_WIDGET (child));
6948 list = CHECK_FIND_CHILD (notebook, child);
6953 if (page->menu_label)
6956 gtk_container_remove (GTK_CONTAINER (notebook->menu),
6957 page->menu_label->parent);
6959 if (!page->default_menu)
6960 g_object_unref (page->menu_label);
6965 page->menu_label = menu_label;
6966 g_object_ref_sink (page->menu_label);
6967 page->default_menu = FALSE;
6970 page->default_menu = TRUE;
6973 gtk_notebook_menu_item_create (notebook, list);
6974 gtk_widget_child_notify (child, "menu-label");
6978 * gtk_notebook_set_menu_label_text:
6979 * @notebook: a #GtkNotebook
6980 * @child: the child widget
6981 * @menu_text: the label text
6983 * Creates a new label and sets it as the menu label of @child.
6986 gtk_notebook_set_menu_label_text (GtkNotebook *notebook,
6988 const gchar *menu_text)
6990 GtkWidget *menu_label = NULL;
6992 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6995 menu_label = gtk_label_new (menu_text);
6996 gtk_notebook_set_menu_label (notebook, child, menu_label);
6997 gtk_widget_child_notify (child, "menu-label");
7001 * gtk_notebook_get_menu_label_text:
7002 * @notebook: a #GtkNotebook
7003 * @child: the child widget of a page of the notebook.
7005 * Retrieves the text of the menu label for the page containing
7008 * Returns value: the text of the tab label, or %NULL if the
7009 * widget does not have a menu label other than
7010 * the default menu label, or the menu label widget
7011 * is not a #GtkLabel. The string is owned by
7012 * the widget and must not be freed.
7014 G_CONST_RETURN gchar *
7015 gtk_notebook_get_menu_label_text (GtkNotebook *notebook,
7018 GtkWidget *menu_label;
7020 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
7021 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
7023 menu_label = gtk_notebook_get_menu_label (notebook, child);
7025 if (menu_label && GTK_IS_LABEL (menu_label))
7026 return gtk_label_get_text (GTK_LABEL (menu_label));
7031 /* Helper function called when pages are reordered
7034 gtk_notebook_child_reordered (GtkNotebook *notebook,
7035 GtkNotebookPage *page)
7039 GtkWidget *menu_item;
7041 menu_item = page->menu_label->parent;
7042 gtk_container_remove (GTK_CONTAINER (menu_item), page->menu_label);
7043 gtk_container_remove (GTK_CONTAINER (notebook->menu), menu_item);
7044 gtk_notebook_menu_item_create (notebook, g_list_find (notebook->children, page));
7047 gtk_notebook_update_tab_states (notebook);
7048 gtk_notebook_update_labels (notebook);
7052 * gtk_notebook_set_tab_label_packing:
7053 * @notebook: a #GtkNotebook
7054 * @child: the child widget
7055 * @expand: whether to expand the bookmark or not
7056 * @fill: whether the bookmark should fill the allocated area or not
7057 * @pack_type: the position of the bookmark
7059 * Sets the packing parameters for the tab label of the page
7060 * containing @child. See gtk_box_pack_start() for the exact meaning
7061 * of the parameters.
7064 gtk_notebook_set_tab_label_packing (GtkNotebook *notebook,
7068 GtkPackType pack_type)
7070 GtkNotebookPage *page;
7073 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7074 g_return_if_fail (GTK_IS_WIDGET (child));
7076 list = CHECK_FIND_CHILD (notebook, child);
7081 expand = expand != FALSE;
7082 fill = fill != FALSE;
7083 if (page->pack == pack_type && page->expand == expand && page->fill == fill)
7086 gtk_widget_freeze_child_notify (child);
7087 page->expand = expand;
7088 gtk_widget_child_notify (child, "tab-expand");
7090 gtk_widget_child_notify (child, "tab-fill");
7091 if (page->pack != pack_type)
7093 page->pack = pack_type;
7094 gtk_notebook_child_reordered (notebook, page);
7096 gtk_widget_child_notify (child, "tab-pack");
7097 gtk_widget_child_notify (child, "position");
7098 if (notebook->show_tabs)
7099 gtk_notebook_pages_allocate (notebook);
7100 gtk_widget_thaw_child_notify (child);
7104 * gtk_notebook_query_tab_label_packing:
7105 * @notebook: a #GtkNotebook
7107 * @expand: location to store the expand value (or NULL)
7108 * @fill: location to store the fill value (or NULL)
7109 * @pack_type: location to store the pack_type (or NULL)
7111 * Query the packing attributes for the tab label of the page
7112 * containing @child.
7115 gtk_notebook_query_tab_label_packing (GtkNotebook *notebook,
7119 GtkPackType *pack_type)
7123 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7124 g_return_if_fail (GTK_IS_WIDGET (child));
7126 list = CHECK_FIND_CHILD (notebook, child);
7131 *expand = GTK_NOTEBOOK_PAGE (list)->expand;
7133 *fill = GTK_NOTEBOOK_PAGE (list)->fill;
7135 *pack_type = GTK_NOTEBOOK_PAGE (list)->pack;
7139 * gtk_notebook_reorder_child:
7140 * @notebook: a #GtkNotebook
7141 * @child: the child to move
7142 * @position: the new position, or -1 to move to the end
7144 * Reorders the page containing @child, so that it appears in position
7145 * @position. If @position is greater than or equal to the number of
7146 * children in the list or negative, @child will be moved to the end
7150 gtk_notebook_reorder_child (GtkNotebook *notebook,
7154 GList *list, *new_list;
7155 GtkNotebookPage *page;
7159 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7160 g_return_if_fail (GTK_IS_WIDGET (child));
7162 list = CHECK_FIND_CHILD (notebook, child);
7166 max_pos = g_list_length (notebook->children) - 1;
7167 if (position < 0 || position > max_pos)
7170 old_pos = g_list_position (notebook->children, list);
7172 if (old_pos == position)
7176 notebook->children = g_list_delete_link (notebook->children, list);
7178 notebook->children = g_list_insert (notebook->children, page, position);
7179 new_list = g_list_nth (notebook->children, position);
7181 /* Fix up GList references in GtkNotebook structure */
7182 if (notebook->first_tab == list)
7183 notebook->first_tab = new_list;
7184 if (notebook->focus_tab == list)
7185 notebook->focus_tab = new_list;
7187 gtk_widget_freeze_child_notify (child);
7189 /* Move around the menu items if necessary */
7190 gtk_notebook_child_reordered (notebook, page);
7191 gtk_widget_child_notify (child, "tab-pack");
7192 gtk_widget_child_notify (child, "position");
7194 if (notebook->show_tabs)
7195 gtk_notebook_pages_allocate (notebook);
7197 gtk_widget_thaw_child_notify (child);
7199 g_signal_emit (notebook,
7200 notebook_signals[PAGE_REORDERED],
7207 * gtk_notebook_set_window_creation_hook:
7208 * @func: the #GtkNotebookWindowCreationFunc, or %NULL
7209 * @data: user data for @func
7210 * @destroy: Destroy notifier for @data, or %NULL
7212 * Installs a global function used to create a window
7213 * when a detached tab is dropped in an empty area.
7218 gtk_notebook_set_window_creation_hook (GtkNotebookWindowCreationFunc func,
7220 GDestroyNotify destroy)
7222 if (window_creation_hook_destroy)
7223 window_creation_hook_destroy (window_creation_hook_data);
7225 window_creation_hook = func;
7226 window_creation_hook_data = data;
7227 window_creation_hook_destroy = destroy;
7231 * gtk_notebook_set_group_id:
7232 * @notebook: a #GtkNotebook
7233 * @group_id: a group identificator, or -1 to unset it
7235 * Sets an group identificator for @notebook, notebooks sharing
7236 * the same group identificator will be able to exchange tabs
7237 * via drag and drop. A notebook with group identificator -1 will
7238 * not be able to exchange tabs with any other notebook.
7243 gtk_notebook_set_group_id (GtkNotebook *notebook,
7246 GtkNotebookPrivate *priv;
7248 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7250 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
7252 if (priv->group_id != group_id)
7254 priv->group_id = group_id;
7255 g_object_notify (G_OBJECT (notebook), "group-id");
7260 * gtk_notebook_get_group_id:
7261 * @notebook: a #GtkNotebook
7263 * Gets the current group identificator for @notebook.
7265 * Return Value: the group identificator, or -1 if none is set.
7270 gtk_notebook_get_group_id (GtkNotebook *notebook)
7272 GtkNotebookPrivate *priv;
7274 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
7276 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
7277 return priv->group_id;
7281 * gtk_notebook_get_tab_reorderable:
7282 * @notebook: a #GtkNotebook
7283 * @child: a child #GtkWidget
7285 * Gets whether the tab can be reordered via drag and drop or not.
7287 * Return Value: %TRUE if the tab is reorderable.
7292 gtk_notebook_get_tab_reorderable (GtkNotebook *notebook,
7297 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
7298 g_return_val_if_fail (GTK_IS_WIDGET (child), FALSE);
7300 list = CHECK_FIND_CHILD (notebook, child);
7304 return GTK_NOTEBOOK_PAGE (list)->reorderable;
7308 * gtk_notebook_set_tab_reorderable:
7309 * @notebook: a #GtkNotebook
7310 * @child: a child #GtkWidget
7311 * @reorderable: whether the tab is reorderable or not.
7313 * Sets whether the notebook tab can be reordered
7314 * via drag and drop or not.
7319 gtk_notebook_set_tab_reorderable (GtkNotebook *notebook,
7321 gboolean reorderable)
7325 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7326 g_return_if_fail (GTK_IS_WIDGET (child));
7328 list = CHECK_FIND_CHILD (notebook, child);
7332 if (GTK_NOTEBOOK_PAGE (list)->reorderable != reorderable)
7334 GTK_NOTEBOOK_PAGE (list)->reorderable = (reorderable == TRUE);
7335 gtk_widget_child_notify (child, "reorderable");
7340 * gtk_notebook_get_tab_detachable:
7341 * @notebook: a #GtkNotebook
7342 * @child: a child #GtkWidget
7344 * Returns whether the tab contents can be detached from @notebook.
7346 * Return Value: TRUE if the tab is detachable.
7351 gtk_notebook_get_tab_detachable (GtkNotebook *notebook,
7356 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
7357 g_return_val_if_fail (GTK_IS_WIDGET (child), FALSE);
7359 list = CHECK_FIND_CHILD (notebook, child);
7363 return GTK_NOTEBOOK_PAGE (list)->detachable;
7367 * gtk_notebook_set_tab_detachable:
7368 * @notebook: a #GtkNotebook
7369 * @child: a child #GtkWidget
7370 * @detachable: whether the tab is detachable or not
7372 * Sets whether the tab can be detached from @notebook to another
7373 * notebook or widget.
7375 * Note that 2 notebooks must share a common group identificator
7376 * (see gtk_notebook_set_group_id ()) to allow automatic tabs
7377 * interchange between them.
7379 * If you want a widget to interact with a notebook through DnD
7380 * (i.e.: accept dragged tabs from it) it must be set as a drop
7381 * destination and accept the target "GTK_NOTEBOOK_TAB". The notebook
7382 * will fill the selection with a GtkWidget** pointing to the child
7383 * widget that corresponds to the dropped tab.
7385 * <informalexample><programlisting>
7387 * on_drop_zone_drag_data_received (GtkWidget *widget,
7388 * GdkDragContext *context,
7391 * GtkSelectionData *selection_data,
7394 * gpointer user_data)
7396 * GtkWidget *notebook;
7397 * GtkWidget **child;
7399 * notebook = gtk_drag_get_source_widget (context);
7400 * child = (void*) selection_data->data;
7402 * process_widget (*child);
7403 * gtk_container_remove (GTK_CONTAINER (notebook), *child);
7405 * </programlisting></informalexample>
7407 * If you want a notebook to accept drags from other widgets,
7408 * you will have to set your own DnD code to do it.
7413 gtk_notebook_set_tab_detachable (GtkNotebook *notebook,
7415 gboolean detachable)
7419 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7420 g_return_if_fail (GTK_IS_WIDGET (child));
7422 list = CHECK_FIND_CHILD (notebook, child);
7426 if (GTK_NOTEBOOK_PAGE (list)->detachable != detachable)
7428 GTK_NOTEBOOK_PAGE (list)->detachable = (detachable == TRUE);
7429 gtk_widget_child_notify (child, "detachable");
7433 #define __GTK_NOTEBOOK_C__
7434 #include "gtkaliasdef.c"