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/.
33 #include <gdk/gdkkeysyms.h>
35 #undef GTK_DISABLE_DEPRECATED
37 #include "gtknotebook.h"
40 #include "gtkmenuitem.h"
43 #include "gtkmarshalers.h"
44 #include "gtkbindings.h"
45 #include "gtkprivate.h"
47 #include "gtkbuildable.h"
49 #define SCROLL_DELAY_FACTOR 5
50 #define SCROLL_THRESHOLD 12
51 #define DND_THRESHOLD_MULTIPLIER 4
52 #define FRAMES_PER_SECOND 45
53 #define MSECS_BETWEEN_UPDATES (1000 / FRAMES_PER_SECOND)
88 } GtkNotebookPointerPosition;
93 DRAG_OPERATION_REORDER,
95 } GtkNotebookDragOperation;
97 #define ARROW_IS_LEFT(arrow) ((arrow) == ARROW_LEFT_BEFORE || (arrow) == ARROW_LEFT_AFTER)
98 #define ARROW_IS_BEFORE(arrow) ((arrow) == ARROW_LEFT_BEFORE || (arrow) == ARROW_RIGHT_BEFORE)
113 CHILD_PROP_TAB_LABEL,
114 CHILD_PROP_MENU_LABEL,
116 CHILD_PROP_TAB_EXPAND,
119 CHILD_PROP_REORDERABLE,
120 CHILD_PROP_DETACHABLE
129 #define GTK_NOTEBOOK_PAGE(_glist_) ((GtkNotebookPage *)((GList *)(_glist_))->data)
131 /* some useful defines for calculating coords */
132 #define PAGE_LEFT_X(_page_) (((GtkNotebookPage *) (_page_))->allocation.x)
133 #define PAGE_RIGHT_X(_page_) (((GtkNotebookPage *) (_page_))->allocation.x + ((GtkNotebookPage *) (_page_))->allocation.width)
134 #define PAGE_MIDDLE_X(_page_) (((GtkNotebookPage *) (_page_))->allocation.x + ((GtkNotebookPage *) (_page_))->allocation.width / 2)
135 #define PAGE_TOP_Y(_page_) (((GtkNotebookPage *) (_page_))->allocation.y)
136 #define PAGE_BOTTOM_Y(_page_) (((GtkNotebookPage *) (_page_))->allocation.y + ((GtkNotebookPage *) (_page_))->allocation.height)
137 #define PAGE_MIDDLE_Y(_page_) (((GtkNotebookPage *) (_page_))->allocation.y + ((GtkNotebookPage *) (_page_))->allocation.height / 2)
138 #define NOTEBOOK_IS_TAB_LABEL_PARENT(_notebook_,_page_) (((GtkNotebookPage *) (_page_))->tab_label->parent == ((GtkWidget *) (_notebook_)))
140 struct _GtkNotebookPage
143 GtkWidget *tab_label;
144 GtkWidget *menu_label;
145 GtkWidget *last_focus_child; /* Last descendant of the page that had focus */
147 guint default_menu : 1; /* If true, we create the menu label ourself */
148 guint default_tab : 1; /* If true, we create the tab label ourself */
152 guint reorderable : 1;
153 guint detachable : 1;
155 /* if true, the tab label was visible on last allocation; we track this so
156 * that we know to redraw the tab area if a tab label was hidden then shown
157 * without changing position */
158 guint tab_allocated_visible : 1;
160 GtkRequisition requisition;
161 GtkAllocation allocation;
163 gulong mnemonic_activate_signal;
164 gulong notify_visible_handler;
167 #define GTK_NOTEBOOK_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_NOTEBOOK, GtkNotebookPrivate))
169 typedef struct _GtkNotebookPrivate GtkNotebookPrivate;
171 struct _GtkNotebookPrivate
178 guint switch_tab_timer;
186 GtkWidget *dnd_window;
187 GtkTargetList *source_targets;
188 GtkNotebookDragOperation operation;
189 GdkWindow *drag_window;
192 GtkNotebookPage *detached_tab;
196 GtkWidget *action_widget[N_ACTION_WIDGETS];
198 guint during_reorder : 1;
199 guint during_detach : 1;
200 guint has_scrolled : 1;
203 static const GtkTargetEntry notebook_targets [] = {
204 { "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, 0 },
207 #ifdef G_DISABLE_CHECKS
208 #define CHECK_FIND_CHILD(notebook, child) \
209 gtk_notebook_find_child (notebook, child, G_STRLOC)
211 #define CHECK_FIND_CHILD(notebook, child) \
212 gtk_notebook_find_child (notebook, child, NULL)
215 /*** GtkNotebook Methods ***/
216 static gboolean gtk_notebook_select_page (GtkNotebook *notebook,
217 gboolean move_focus);
218 static gboolean gtk_notebook_focus_tab (GtkNotebook *notebook,
219 GtkNotebookTab type);
220 static gboolean gtk_notebook_change_current_page (GtkNotebook *notebook,
222 static void gtk_notebook_move_focus_out (GtkNotebook *notebook,
223 GtkDirectionType direction_type);
224 static gboolean gtk_notebook_reorder_tab (GtkNotebook *notebook,
225 GtkDirectionType direction_type,
226 gboolean move_to_last);
227 static void gtk_notebook_remove_tab_label (GtkNotebook *notebook,
228 GtkNotebookPage *page);
229 static void gtk_notebook_set_tab_label_packing (GtkNotebook *notebook,
233 GtkPackType pack_type);
234 static void gtk_notebook_query_tab_label_packing (GtkNotebook *notebook,
238 GtkPackType *pack_type);
240 /*** GtkObject Methods ***/
241 static void gtk_notebook_destroy (GtkObject *object);
242 static void gtk_notebook_set_property (GObject *object,
246 static void gtk_notebook_get_property (GObject *object,
251 /*** GtkWidget Methods ***/
252 static void gtk_notebook_map (GtkWidget *widget);
253 static void gtk_notebook_unmap (GtkWidget *widget);
254 static void gtk_notebook_realize (GtkWidget *widget);
255 static void gtk_notebook_unrealize (GtkWidget *widget);
256 static void gtk_notebook_size_request (GtkWidget *widget,
257 GtkRequisition *requisition);
258 static void gtk_notebook_size_allocate (GtkWidget *widget,
259 GtkAllocation *allocation);
260 static gint gtk_notebook_expose (GtkWidget *widget,
261 GdkEventExpose *event);
262 static gboolean gtk_notebook_scroll (GtkWidget *widget,
263 GdkEventScroll *event);
264 static gint gtk_notebook_button_press (GtkWidget *widget,
265 GdkEventButton *event);
266 static gint gtk_notebook_button_release (GtkWidget *widget,
267 GdkEventButton *event);
268 static gboolean gtk_notebook_popup_menu (GtkWidget *widget);
269 static gint gtk_notebook_leave_notify (GtkWidget *widget,
270 GdkEventCrossing *event);
271 static gint gtk_notebook_motion_notify (GtkWidget *widget,
272 GdkEventMotion *event);
273 static gint gtk_notebook_focus_in (GtkWidget *widget,
274 GdkEventFocus *event);
275 static gint gtk_notebook_focus_out (GtkWidget *widget,
276 GdkEventFocus *event);
277 static void gtk_notebook_grab_notify (GtkWidget *widget,
278 gboolean was_grabbed);
279 static void gtk_notebook_state_changed (GtkWidget *widget,
280 GtkStateType previous_state);
281 static void gtk_notebook_draw_focus (GtkWidget *widget,
282 GdkEventExpose *event);
283 static gint gtk_notebook_focus (GtkWidget *widget,
284 GtkDirectionType direction);
285 static void gtk_notebook_style_set (GtkWidget *widget,
288 /*** Drag and drop Methods ***/
289 static void gtk_notebook_drag_begin (GtkWidget *widget,
290 GdkDragContext *context);
291 static void gtk_notebook_drag_end (GtkWidget *widget,
292 GdkDragContext *context);
293 static gboolean gtk_notebook_drag_failed (GtkWidget *widget,
294 GdkDragContext *context,
295 GtkDragResult result,
297 static gboolean gtk_notebook_drag_motion (GtkWidget *widget,
298 GdkDragContext *context,
302 static void gtk_notebook_drag_leave (GtkWidget *widget,
303 GdkDragContext *context,
305 static gboolean gtk_notebook_drag_drop (GtkWidget *widget,
306 GdkDragContext *context,
310 static void gtk_notebook_drag_data_get (GtkWidget *widget,
311 GdkDragContext *context,
312 GtkSelectionData *data,
315 static void gtk_notebook_drag_data_received (GtkWidget *widget,
316 GdkDragContext *context,
319 GtkSelectionData *data,
323 /*** GtkContainer Methods ***/
324 static void gtk_notebook_set_child_property (GtkContainer *container,
329 static void gtk_notebook_get_child_property (GtkContainer *container,
334 static void gtk_notebook_add (GtkContainer *container,
336 static void gtk_notebook_remove (GtkContainer *container,
338 static void gtk_notebook_set_focus_child (GtkContainer *container,
340 static GType gtk_notebook_child_type (GtkContainer *container);
341 static void gtk_notebook_forall (GtkContainer *container,
342 gboolean include_internals,
343 GtkCallback callback,
344 gpointer callback_data);
346 /*** GtkNotebook Methods ***/
347 static gint gtk_notebook_real_insert_page (GtkNotebook *notebook,
349 GtkWidget *tab_label,
350 GtkWidget *menu_label,
353 static GtkNotebook *gtk_notebook_create_window (GtkNotebook *notebook,
358 /*** GtkNotebook Private Functions ***/
359 static void gtk_notebook_redraw_tabs (GtkNotebook *notebook);
360 static void gtk_notebook_redraw_arrows (GtkNotebook *notebook);
361 static void gtk_notebook_real_remove (GtkNotebook *notebook,
363 static void gtk_notebook_update_labels (GtkNotebook *notebook);
364 static gint gtk_notebook_timer (GtkNotebook *notebook);
365 static void gtk_notebook_set_scroll_timer (GtkNotebook *notebook);
366 static gint gtk_notebook_page_compare (gconstpointer a,
368 static GList* gtk_notebook_find_child (GtkNotebook *notebook,
370 const gchar *function);
371 static gint gtk_notebook_real_page_position (GtkNotebook *notebook,
373 static GList * gtk_notebook_search_page (GtkNotebook *notebook,
376 gboolean find_visible);
377 static void gtk_notebook_child_reordered (GtkNotebook *notebook,
378 GtkNotebookPage *page);
380 /*** GtkNotebook Drawing Functions ***/
381 static void gtk_notebook_paint (GtkWidget *widget,
383 static void gtk_notebook_draw_tab (GtkNotebook *notebook,
384 GtkNotebookPage *page,
386 static void gtk_notebook_draw_arrow (GtkNotebook *notebook,
387 GtkNotebookArrow arrow);
389 /*** GtkNotebook Size Allocate Functions ***/
390 static void gtk_notebook_pages_allocate (GtkNotebook *notebook);
391 static gboolean gtk_notebook_page_allocate (GtkNotebook *notebook,
392 GtkNotebookPage *page);
393 static void gtk_notebook_calc_tabs (GtkNotebook *notebook,
399 /*** GtkNotebook Page Switch Methods ***/
400 static void gtk_notebook_real_switch_page (GtkNotebook *notebook,
401 GtkNotebookPage *child,
404 /*** GtkNotebook Page Switch Functions ***/
405 static void gtk_notebook_switch_page (GtkNotebook *notebook,
406 GtkNotebookPage *page);
407 static gint gtk_notebook_page_select (GtkNotebook *notebook,
408 gboolean move_focus);
409 static void gtk_notebook_switch_focus_tab (GtkNotebook *notebook,
411 static void gtk_notebook_menu_switch_page (GtkWidget *widget,
412 GtkNotebookPage *page);
414 /*** GtkNotebook Menu Functions ***/
415 static void gtk_notebook_menu_item_create (GtkNotebook *notebook,
417 static void gtk_notebook_menu_label_unparent (GtkWidget *widget,
419 static void gtk_notebook_menu_detacher (GtkWidget *widget,
422 /*** GtkNotebook Private Setters ***/
423 static void gtk_notebook_update_tab_states (GtkNotebook *notebook);
424 static gboolean gtk_notebook_mnemonic_activate_switch_page (GtkWidget *child,
428 static gboolean focus_tabs_in (GtkNotebook *notebook);
429 static gboolean focus_child_in (GtkNotebook *notebook,
430 GtkDirectionType direction);
432 static void stop_scrolling (GtkNotebook *notebook);
433 static void do_detach_tab (GtkNotebook *from,
440 static void gtk_notebook_buildable_init (GtkBuildableIface *iface);
441 static void gtk_notebook_buildable_add_child (GtkBuildable *buildable,
446 static GtkNotebookWindowCreationFunc window_creation_hook = NULL;
447 static gpointer window_creation_hook_data;
448 static GDestroyNotify window_creation_hook_destroy = NULL;
450 static guint notebook_signals[LAST_SIGNAL] = { 0 };
452 G_DEFINE_TYPE_WITH_CODE (GtkNotebook, gtk_notebook, GTK_TYPE_CONTAINER,
453 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
454 gtk_notebook_buildable_init))
457 add_tab_bindings (GtkBindingSet *binding_set,
458 GdkModifierType modifiers,
459 GtkDirectionType direction)
461 gtk_binding_entry_add_signal (binding_set, GDK_Tab, modifiers,
463 GTK_TYPE_DIRECTION_TYPE, direction);
464 gtk_binding_entry_add_signal (binding_set, GDK_KP_Tab, modifiers,
466 GTK_TYPE_DIRECTION_TYPE, direction);
470 add_arrow_bindings (GtkBindingSet *binding_set,
472 GtkDirectionType direction)
474 guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
476 gtk_binding_entry_add_signal (binding_set, keysym, GDK_CONTROL_MASK,
478 GTK_TYPE_DIRECTION_TYPE, direction);
479 gtk_binding_entry_add_signal (binding_set, keypad_keysym, GDK_CONTROL_MASK,
481 GTK_TYPE_DIRECTION_TYPE, direction);
485 add_reorder_bindings (GtkBindingSet *binding_set,
487 GtkDirectionType direction,
488 gboolean move_to_last)
490 guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
492 gtk_binding_entry_add_signal (binding_set, keysym, GDK_MOD1_MASK,
494 GTK_TYPE_DIRECTION_TYPE, direction,
495 G_TYPE_BOOLEAN, move_to_last);
496 gtk_binding_entry_add_signal (binding_set, keypad_keysym, GDK_MOD1_MASK,
498 GTK_TYPE_DIRECTION_TYPE, direction,
499 G_TYPE_BOOLEAN, move_to_last);
503 gtk_object_handled_accumulator (GSignalInvocationHint *ihint,
505 const GValue *handler_return,
508 gboolean continue_emission;
511 object = g_value_get_object (handler_return);
512 g_value_set_object (return_accu, object);
513 continue_emission = !object;
515 return continue_emission;
519 gtk_notebook_class_init (GtkNotebookClass *class)
521 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
522 GtkObjectClass *object_class = GTK_OBJECT_CLASS (class);
523 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
524 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
525 GtkBindingSet *binding_set;
527 gobject_class->set_property = gtk_notebook_set_property;
528 gobject_class->get_property = gtk_notebook_get_property;
529 object_class->destroy = gtk_notebook_destroy;
531 widget_class->map = gtk_notebook_map;
532 widget_class->unmap = gtk_notebook_unmap;
533 widget_class->realize = gtk_notebook_realize;
534 widget_class->unrealize = gtk_notebook_unrealize;
535 widget_class->size_request = gtk_notebook_size_request;
536 widget_class->size_allocate = gtk_notebook_size_allocate;
537 widget_class->expose_event = gtk_notebook_expose;
538 widget_class->scroll_event = gtk_notebook_scroll;
539 widget_class->button_press_event = gtk_notebook_button_press;
540 widget_class->button_release_event = gtk_notebook_button_release;
541 widget_class->popup_menu = gtk_notebook_popup_menu;
542 widget_class->leave_notify_event = gtk_notebook_leave_notify;
543 widget_class->motion_notify_event = gtk_notebook_motion_notify;
544 widget_class->grab_notify = gtk_notebook_grab_notify;
545 widget_class->state_changed = gtk_notebook_state_changed;
546 widget_class->focus_in_event = gtk_notebook_focus_in;
547 widget_class->focus_out_event = gtk_notebook_focus_out;
548 widget_class->focus = gtk_notebook_focus;
549 widget_class->style_set = gtk_notebook_style_set;
550 widget_class->drag_begin = gtk_notebook_drag_begin;
551 widget_class->drag_end = gtk_notebook_drag_end;
552 widget_class->drag_motion = gtk_notebook_drag_motion;
553 widget_class->drag_leave = gtk_notebook_drag_leave;
554 widget_class->drag_drop = gtk_notebook_drag_drop;
555 widget_class->drag_data_get = gtk_notebook_drag_data_get;
556 widget_class->drag_data_received = gtk_notebook_drag_data_received;
558 container_class->add = gtk_notebook_add;
559 container_class->remove = gtk_notebook_remove;
560 container_class->forall = gtk_notebook_forall;
561 container_class->set_focus_child = gtk_notebook_set_focus_child;
562 container_class->get_child_property = gtk_notebook_get_child_property;
563 container_class->set_child_property = gtk_notebook_set_child_property;
564 container_class->child_type = gtk_notebook_child_type;
566 class->switch_page = gtk_notebook_real_switch_page;
567 class->insert_page = gtk_notebook_real_insert_page;
569 class->focus_tab = gtk_notebook_focus_tab;
570 class->select_page = gtk_notebook_select_page;
571 class->change_current_page = gtk_notebook_change_current_page;
572 class->move_focus_out = gtk_notebook_move_focus_out;
573 class->reorder_tab = gtk_notebook_reorder_tab;
574 class->create_window = gtk_notebook_create_window;
576 g_object_class_install_property (gobject_class,
578 g_param_spec_int ("page",
580 P_("The index of the current page"),
584 GTK_PARAM_READWRITE));
585 g_object_class_install_property (gobject_class,
587 g_param_spec_enum ("tab-pos",
589 P_("Which side of the notebook holds the tabs"),
590 GTK_TYPE_POSITION_TYPE,
592 GTK_PARAM_READWRITE));
593 g_object_class_install_property (gobject_class,
595 g_param_spec_boolean ("show-tabs",
597 P_("Whether tabs should be shown or not"),
599 GTK_PARAM_READWRITE));
600 g_object_class_install_property (gobject_class,
602 g_param_spec_boolean ("show-border",
604 P_("Whether the border should be shown or not"),
606 GTK_PARAM_READWRITE));
607 g_object_class_install_property (gobject_class,
609 g_param_spec_boolean ("scrollable",
611 P_("If TRUE, scroll arrows are added if there are too many tabs to fit"),
613 GTK_PARAM_READWRITE));
614 g_object_class_install_property (gobject_class,
616 g_param_spec_boolean ("enable-popup",
618 P_("If TRUE, pressing the right mouse button on the notebook pops up a menu that you can use to go to a page"),
620 GTK_PARAM_READWRITE));
625 * Group for tabs drag and drop.
629 g_object_class_install_property (gobject_class,
631 g_param_spec_pointer ("group",
633 P_("Group for tabs drag and drop"),
634 GTK_PARAM_READWRITE));
636 gtk_container_class_install_child_property (container_class,
637 CHILD_PROP_TAB_LABEL,
638 g_param_spec_string ("tab-label",
640 P_("The string displayed on the child's tab label"),
642 GTK_PARAM_READWRITE));
643 gtk_container_class_install_child_property (container_class,
644 CHILD_PROP_MENU_LABEL,
645 g_param_spec_string ("menu-label",
647 P_("The string displayed in the child's menu entry"),
649 GTK_PARAM_READWRITE));
650 gtk_container_class_install_child_property (container_class,
652 g_param_spec_int ("position",
654 P_("The index of the child in the parent"),
656 GTK_PARAM_READWRITE));
657 gtk_container_class_install_child_property (container_class,
658 CHILD_PROP_TAB_EXPAND,
659 g_param_spec_boolean ("tab-expand",
661 P_("Whether to expand the child's tab or not"),
663 GTK_PARAM_READWRITE));
664 gtk_container_class_install_child_property (container_class,
666 g_param_spec_boolean ("tab-fill",
668 P_("Whether the child's tab should fill the allocated area or not"),
670 GTK_PARAM_READWRITE));
671 gtk_container_class_install_child_property (container_class,
673 g_param_spec_enum ("tab-pack",
675 P_("A GtkPackType indicating whether the child is packed with reference to the start or end of the parent"),
676 GTK_TYPE_PACK_TYPE, GTK_PACK_START,
677 GTK_PARAM_READWRITE));
678 gtk_container_class_install_child_property (container_class,
679 CHILD_PROP_REORDERABLE,
680 g_param_spec_boolean ("reorderable",
681 P_("Tab reorderable"),
682 P_("Whether the tab is reorderable by user action or not"),
684 GTK_PARAM_READWRITE));
685 gtk_container_class_install_child_property (container_class,
686 CHILD_PROP_DETACHABLE,
687 g_param_spec_boolean ("detachable",
688 P_("Tab detachable"),
689 P_("Whether the tab is detachable"),
691 GTK_PARAM_READWRITE));
694 * GtkNotebook:has-secondary-backward-stepper:
696 * The "has-secondary-backward-stepper" property determines whether
697 * a second backward arrow button is displayed on the opposite end
702 gtk_widget_class_install_style_property (widget_class,
703 g_param_spec_boolean ("has-secondary-backward-stepper",
704 P_("Secondary backward stepper"),
705 P_("Display a second backward arrow button on the opposite end of the tab area"),
707 GTK_PARAM_READABLE));
710 * GtkNotebook:has-secondary-forward-stepper:
712 * The "has-secondary-forward-stepper" property determines whether
713 * a second forward arrow button is displayed on the opposite end
718 gtk_widget_class_install_style_property (widget_class,
719 g_param_spec_boolean ("has-secondary-forward-stepper",
720 P_("Secondary forward stepper"),
721 P_("Display a second forward arrow button on the opposite end of the tab area"),
723 GTK_PARAM_READABLE));
726 * GtkNotebook:has-backward-stepper:
728 * The "has-backward-stepper" property determines whether
729 * the standard backward arrow button is displayed.
733 gtk_widget_class_install_style_property (widget_class,
734 g_param_spec_boolean ("has-backward-stepper",
735 P_("Backward stepper"),
736 P_("Display the standard backward arrow button"),
738 GTK_PARAM_READABLE));
741 * GtkNotebook:has-forward-stepper:
743 * The "has-forward-stepper" property determines whether
744 * the standard forward arrow button is displayed.
748 gtk_widget_class_install_style_property (widget_class,
749 g_param_spec_boolean ("has-forward-stepper",
750 P_("Forward stepper"),
751 P_("Display the standard forward arrow button"),
753 GTK_PARAM_READABLE));
756 * GtkNotebook:tab-overlap:
758 * The "tab-overlap" property defines size of tab overlap
763 gtk_widget_class_install_style_property (widget_class,
764 g_param_spec_int ("tab-overlap",
766 P_("Size of tab overlap area"),
770 GTK_PARAM_READABLE));
773 * GtkNotebook:tab-curvature:
775 * The "tab-curvature" property defines size of tab curvature.
779 gtk_widget_class_install_style_property (widget_class,
780 g_param_spec_int ("tab-curvature",
782 P_("Size of tab curvature"),
786 GTK_PARAM_READABLE));
789 * GtkNotebook:arrow-spacing:
791 * The "arrow-spacing" property defines the spacing between the scroll
792 * arrows and the tabs.
796 gtk_widget_class_install_style_property (widget_class,
797 g_param_spec_int ("arrow-spacing",
799 P_("Scroll arrow spacing"),
803 GTK_PARAM_READABLE));
805 notebook_signals[SWITCH_PAGE] =
806 g_signal_new (I_("switch-page"),
807 G_TYPE_FROM_CLASS (gobject_class),
809 G_STRUCT_OFFSET (GtkNotebookClass, switch_page),
811 _gtk_marshal_VOID__POINTER_UINT,
815 notebook_signals[FOCUS_TAB] =
816 g_signal_new (I_("focus-tab"),
817 G_TYPE_FROM_CLASS (gobject_class),
818 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
819 G_STRUCT_OFFSET (GtkNotebookClass, focus_tab),
821 _gtk_marshal_BOOLEAN__ENUM,
823 GTK_TYPE_NOTEBOOK_TAB);
824 notebook_signals[SELECT_PAGE] =
825 g_signal_new (I_("select-page"),
826 G_TYPE_FROM_CLASS (gobject_class),
827 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
828 G_STRUCT_OFFSET (GtkNotebookClass, select_page),
830 _gtk_marshal_BOOLEAN__BOOLEAN,
833 notebook_signals[CHANGE_CURRENT_PAGE] =
834 g_signal_new (I_("change-current-page"),
835 G_TYPE_FROM_CLASS (gobject_class),
836 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
837 G_STRUCT_OFFSET (GtkNotebookClass, change_current_page),
839 _gtk_marshal_BOOLEAN__INT,
842 notebook_signals[MOVE_FOCUS_OUT] =
843 g_signal_new (I_("move-focus-out"),
844 G_TYPE_FROM_CLASS (gobject_class),
845 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
846 G_STRUCT_OFFSET (GtkNotebookClass, move_focus_out),
848 _gtk_marshal_VOID__ENUM,
850 GTK_TYPE_DIRECTION_TYPE);
851 notebook_signals[REORDER_TAB] =
852 g_signal_new (I_("reorder-tab"),
853 G_TYPE_FROM_CLASS (gobject_class),
854 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
855 G_STRUCT_OFFSET (GtkNotebookClass, reorder_tab),
857 _gtk_marshal_BOOLEAN__ENUM_BOOLEAN,
859 GTK_TYPE_DIRECTION_TYPE,
862 * GtkNotebook::page-reordered:
863 * @notebook: the #GtkNotebook
864 * @child: the child #GtkWidget affected
865 * @page_num: the new page number for @child
867 * the ::page-reordered signal is emitted in the notebook
868 * right after a page has been reordered.
872 notebook_signals[PAGE_REORDERED] =
873 g_signal_new (I_("page-reordered"),
874 G_TYPE_FROM_CLASS (gobject_class),
877 _gtk_marshal_VOID__OBJECT_UINT,
882 * GtkNotebook::page-removed:
883 * @notebook: the #GtkNotebook
884 * @child: the child #GtkWidget affected
885 * @page_num: the @child page number
887 * the ::page-removed signal is emitted in the notebook
888 * right after a page is removed from the notebook.
892 notebook_signals[PAGE_REMOVED] =
893 g_signal_new (I_("page-removed"),
894 G_TYPE_FROM_CLASS (gobject_class),
897 _gtk_marshal_VOID__OBJECT_UINT,
902 * GtkNotebook::page-added:
903 * @notebook: the #GtkNotebook
904 * @child: the child #GtkWidget affected
905 * @page_num: the new page number for @child
907 * the ::page-added signal is emitted in the notebook
908 * right after a page is added to the notebook.
912 notebook_signals[PAGE_ADDED] =
913 g_signal_new (I_("page-added"),
914 G_TYPE_FROM_CLASS (gobject_class),
917 _gtk_marshal_VOID__OBJECT_UINT,
923 * GtkNotebook::create-window:
924 * @notebook: the #GtkNotebook emitting the signal
925 * @page: the tab of @notebook that is being detached
926 * @x: the X coordinate where the drop happens
927 * @y: the Y coordinate where the drop happens
929 * The ::create-window signal is emitted when a detachable
930 * tab is dropped on the root window.
932 * A handler for this signal can create a window containing
933 * a notebook where the tab will be attached. It is also
934 * responsible for moving/resizing the window and adding the
935 * necessary properties to the notebook (e.g. the
936 * #GtkNotebook:group ).
938 * The default handler uses the global window creation hook,
939 * if one has been set with gtk_notebook_set_window_creation_hook().
941 * Returns: a #GtkNotebook that @page should be added to, or %NULL.
945 notebook_signals[CREATE_WINDOW] =
946 g_signal_new (I_("create-window"),
947 G_TYPE_FROM_CLASS (gobject_class),
949 G_STRUCT_OFFSET (GtkNotebookClass, create_window),
950 gtk_object_handled_accumulator, NULL,
951 _gtk_marshal_OBJECT__OBJECT_INT_INT,
952 GTK_TYPE_NOTEBOOK, 3,
953 GTK_TYPE_WIDGET, G_TYPE_INT, G_TYPE_INT);
955 binding_set = gtk_binding_set_by_class (class);
956 gtk_binding_entry_add_signal (binding_set,
959 G_TYPE_BOOLEAN, FALSE);
960 gtk_binding_entry_add_signal (binding_set,
963 G_TYPE_BOOLEAN, FALSE);
965 gtk_binding_entry_add_signal (binding_set,
968 GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_FIRST);
969 gtk_binding_entry_add_signal (binding_set,
972 GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_FIRST);
973 gtk_binding_entry_add_signal (binding_set,
976 GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_LAST);
977 gtk_binding_entry_add_signal (binding_set,
980 GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_LAST);
982 gtk_binding_entry_add_signal (binding_set,
983 GDK_Page_Up, GDK_CONTROL_MASK,
984 "change-current-page", 1,
986 gtk_binding_entry_add_signal (binding_set,
987 GDK_Page_Down, GDK_CONTROL_MASK,
988 "change-current-page", 1,
991 gtk_binding_entry_add_signal (binding_set,
992 GDK_Page_Up, GDK_CONTROL_MASK | GDK_MOD1_MASK,
993 "change-current-page", 1,
995 gtk_binding_entry_add_signal (binding_set,
996 GDK_Page_Down, GDK_CONTROL_MASK | GDK_MOD1_MASK,
997 "change-current-page", 1,
1000 add_arrow_bindings (binding_set, GDK_Up, GTK_DIR_UP);
1001 add_arrow_bindings (binding_set, GDK_Down, GTK_DIR_DOWN);
1002 add_arrow_bindings (binding_set, GDK_Left, GTK_DIR_LEFT);
1003 add_arrow_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT);
1005 add_reorder_bindings (binding_set, GDK_Up, GTK_DIR_UP, FALSE);
1006 add_reorder_bindings (binding_set, GDK_Down, GTK_DIR_DOWN, FALSE);
1007 add_reorder_bindings (binding_set, GDK_Left, GTK_DIR_LEFT, FALSE);
1008 add_reorder_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT, FALSE);
1009 add_reorder_bindings (binding_set, GDK_Home, GTK_DIR_LEFT, TRUE);
1010 add_reorder_bindings (binding_set, GDK_Home, GTK_DIR_UP, TRUE);
1011 add_reorder_bindings (binding_set, GDK_End, GTK_DIR_RIGHT, TRUE);
1012 add_reorder_bindings (binding_set, GDK_End, GTK_DIR_DOWN, TRUE);
1014 add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
1015 add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
1017 g_type_class_add_private (class, sizeof (GtkNotebookPrivate));
1021 gtk_notebook_init (GtkNotebook *notebook)
1023 GtkNotebookPrivate *priv;
1025 gtk_widget_set_can_focus (GTK_WIDGET (notebook), TRUE);
1026 gtk_widget_set_has_window (GTK_WIDGET (notebook), FALSE);
1028 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
1030 notebook->cur_page = NULL;
1031 notebook->children = NULL;
1032 notebook->first_tab = NULL;
1033 notebook->focus_tab = NULL;
1034 notebook->event_window = NULL;
1035 notebook->menu = NULL;
1037 notebook->tab_hborder = 2;
1038 notebook->tab_vborder = 2;
1040 notebook->show_tabs = TRUE;
1041 notebook->show_border = TRUE;
1042 notebook->tab_pos = GTK_POS_TOP;
1043 notebook->scrollable = FALSE;
1044 notebook->in_child = 0;
1045 notebook->click_child = 0;
1046 notebook->button = 0;
1047 notebook->need_timer = 0;
1048 notebook->child_has_focus = FALSE;
1049 notebook->have_visible_child = FALSE;
1050 notebook->focus_out = FALSE;
1052 notebook->has_before_previous = 1;
1053 notebook->has_before_next = 0;
1054 notebook->has_after_previous = 0;
1055 notebook->has_after_next = 1;
1058 priv->pressed_button = -1;
1059 priv->dnd_timer = 0;
1060 priv->switch_tab_timer = 0;
1061 priv->source_targets = gtk_target_list_new (notebook_targets,
1062 G_N_ELEMENTS (notebook_targets));
1063 priv->operation = DRAG_OPERATION_NONE;
1064 priv->detached_tab = NULL;
1065 priv->during_detach = FALSE;
1066 priv->has_scrolled = FALSE;
1068 gtk_drag_dest_set (GTK_WIDGET (notebook), 0,
1069 notebook_targets, G_N_ELEMENTS (notebook_targets),
1072 g_signal_connect (G_OBJECT (notebook), "drag-failed",
1073 G_CALLBACK (gtk_notebook_drag_failed), NULL);
1075 gtk_drag_dest_set_track_motion (GTK_WIDGET (notebook), TRUE);
1079 gtk_notebook_buildable_init (GtkBuildableIface *iface)
1081 iface->add_child = gtk_notebook_buildable_add_child;
1085 gtk_notebook_buildable_add_child (GtkBuildable *buildable,
1086 GtkBuilder *builder,
1090 GtkNotebook *notebook = GTK_NOTEBOOK (buildable);
1092 if (type && strcmp (type, "tab") == 0)
1096 page = gtk_notebook_get_nth_page (notebook, -1);
1097 /* To set the tab label widget, we must have already a child
1098 * inside the tab container. */
1099 g_assert (page != NULL);
1100 gtk_notebook_set_tab_label (notebook, page, GTK_WIDGET (child));
1102 else if (type && strcmp (type, "action-start") == 0)
1104 gtk_notebook_set_action_widget (notebook, GTK_WIDGET (child), GTK_PACK_START);
1106 else if (type && strcmp (type, "action-end") == 0)
1108 gtk_notebook_set_action_widget (notebook, GTK_WIDGET (child), GTK_PACK_END);
1111 gtk_notebook_append_page (notebook, GTK_WIDGET (child), NULL);
1113 GTK_BUILDER_WARN_INVALID_CHILD_TYPE (notebook, type);
1117 gtk_notebook_select_page (GtkNotebook *notebook,
1118 gboolean move_focus)
1120 if (gtk_widget_is_focus (GTK_WIDGET (notebook)) && notebook->show_tabs)
1122 gtk_notebook_page_select (notebook, move_focus);
1130 gtk_notebook_focus_tab (GtkNotebook *notebook,
1131 GtkNotebookTab type)
1135 if (gtk_widget_is_focus (GTK_WIDGET (notebook)) && notebook->show_tabs)
1139 case GTK_NOTEBOOK_TAB_FIRST:
1140 list = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, TRUE);
1142 gtk_notebook_switch_focus_tab (notebook, list);
1144 case GTK_NOTEBOOK_TAB_LAST:
1145 list = gtk_notebook_search_page (notebook, NULL, STEP_PREV, TRUE);
1147 gtk_notebook_switch_focus_tab (notebook, list);
1158 gtk_notebook_change_current_page (GtkNotebook *notebook,
1161 GList *current = NULL;
1163 if (!notebook->show_tabs)
1166 if (notebook->cur_page)
1167 current = g_list_find (notebook->children, notebook->cur_page);
1171 current = gtk_notebook_search_page (notebook, current,
1172 offset < 0 ? STEP_PREV : STEP_NEXT,
1177 gboolean wrap_around;
1179 g_object_get (gtk_widget_get_settings (GTK_WIDGET (notebook)),
1180 "gtk-keynav-wrap-around", &wrap_around,
1184 current = gtk_notebook_search_page (notebook, NULL,
1185 offset < 0 ? STEP_PREV : STEP_NEXT,
1191 offset += offset < 0 ? 1 : -1;
1195 gtk_notebook_switch_page (notebook, current->data);
1197 gtk_widget_error_bell (GTK_WIDGET (notebook));
1202 static GtkDirectionType
1203 get_effective_direction (GtkNotebook *notebook,
1204 GtkDirectionType direction)
1206 /* Remap the directions into the effective direction it would be for a
1207 * GTK_POS_TOP notebook
1210 #define D(rest) GTK_DIR_##rest
1212 static const GtkDirectionType translate_direction[2][4][6] = {
1213 /* LEFT */ {{ D(TAB_FORWARD), D(TAB_BACKWARD), D(LEFT), D(RIGHT), D(UP), D(DOWN) },
1214 /* RIGHT */ { D(TAB_BACKWARD), D(TAB_FORWARD), D(LEFT), D(RIGHT), D(DOWN), D(UP) },
1215 /* TOP */ { D(TAB_FORWARD), D(TAB_BACKWARD), D(UP), D(DOWN), D(LEFT), D(RIGHT) },
1216 /* BOTTOM */ { D(TAB_BACKWARD), D(TAB_FORWARD), D(DOWN), D(UP), D(LEFT), D(RIGHT) }},
1217 /* LEFT */ {{ D(TAB_BACKWARD), D(TAB_FORWARD), D(LEFT), D(RIGHT), D(DOWN), D(UP) },
1218 /* RIGHT */ { D(TAB_FORWARD), D(TAB_BACKWARD), D(LEFT), D(RIGHT), D(UP), D(DOWN) },
1219 /* TOP */ { D(TAB_FORWARD), D(TAB_BACKWARD), D(UP), D(DOWN), D(RIGHT), D(LEFT) },
1220 /* BOTTOM */ { D(TAB_BACKWARD), D(TAB_FORWARD), D(DOWN), D(UP), D(RIGHT), D(LEFT) }},
1225 int text_dir = gtk_widget_get_direction (GTK_WIDGET (notebook)) == GTK_TEXT_DIR_RTL ? 1 : 0;
1227 return translate_direction[text_dir][notebook->tab_pos][direction];
1231 get_effective_tab_pos (GtkNotebook *notebook)
1233 if (gtk_widget_get_direction (GTK_WIDGET (notebook)) == GTK_TEXT_DIR_RTL)
1235 switch (notebook->tab_pos)
1238 return GTK_POS_RIGHT;
1240 return GTK_POS_LEFT;
1245 return notebook->tab_pos;
1249 get_tab_gap_pos (GtkNotebook *notebook)
1251 gint tab_pos = get_effective_tab_pos (notebook);
1252 gint gap_side = GTK_POS_BOTTOM;
1257 gap_side = GTK_POS_BOTTOM;
1259 case GTK_POS_BOTTOM:
1260 gap_side = GTK_POS_TOP;
1263 gap_side = GTK_POS_RIGHT;
1266 gap_side = GTK_POS_LEFT;
1274 gtk_notebook_move_focus_out (GtkNotebook *notebook,
1275 GtkDirectionType direction_type)
1277 GtkDirectionType effective_direction = get_effective_direction (notebook, direction_type);
1278 GtkWidget *toplevel;
1280 if (GTK_CONTAINER (notebook)->focus_child && effective_direction == GTK_DIR_UP)
1281 if (focus_tabs_in (notebook))
1283 if (gtk_widget_is_focus (GTK_WIDGET (notebook)) && effective_direction == GTK_DIR_DOWN)
1284 if (focus_child_in (notebook, GTK_DIR_TAB_FORWARD))
1287 /* At this point, we know we should be focusing out of the notebook entirely. We
1288 * do this by setting a flag, then propagating the focus motion to the notebook.
1290 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (notebook));
1291 if (!gtk_widget_is_toplevel (toplevel))
1294 g_object_ref (notebook);
1296 notebook->focus_out = TRUE;
1297 g_signal_emit_by_name (toplevel, "move-focus", direction_type);
1298 notebook->focus_out = FALSE;
1300 g_object_unref (notebook);
1304 reorder_tab (GtkNotebook *notebook, GList *position, GList *tab)
1308 if (position == tab)
1309 return g_list_position (notebook->children, tab);
1311 /* check that we aren't inserting the tab in the
1312 * same relative position, taking packing into account */
1313 elem = (position) ? position->prev : g_list_last (notebook->children);
1315 while (elem && elem != tab && GTK_NOTEBOOK_PAGE (elem)->pack != GTK_NOTEBOOK_PAGE (tab)->pack)
1319 return g_list_position (notebook->children, tab);
1321 /* now actually reorder the tab */
1322 if (notebook->first_tab == tab)
1323 notebook->first_tab = gtk_notebook_search_page (notebook, notebook->first_tab,
1326 notebook->children = g_list_remove_link (notebook->children, tab);
1329 elem = g_list_last (notebook->children);
1332 elem = position->prev;
1333 position->prev = tab;
1339 notebook->children = tab;
1342 tab->next = position;
1344 return g_list_position (notebook->children, tab);
1348 gtk_notebook_reorder_tab (GtkNotebook *notebook,
1349 GtkDirectionType direction_type,
1350 gboolean move_to_last)
1352 GtkDirectionType effective_direction = get_effective_direction (notebook, direction_type);
1353 GtkNotebookPage *page;
1354 GList *last, *child;
1357 if (!gtk_widget_is_focus (GTK_WIDGET (notebook)) || !notebook->show_tabs)
1360 if (!notebook->cur_page ||
1361 !notebook->cur_page->reorderable)
1364 if (effective_direction != GTK_DIR_LEFT &&
1365 effective_direction != GTK_DIR_RIGHT)
1370 child = notebook->focus_tab;
1375 child = gtk_notebook_search_page (notebook, last,
1376 (effective_direction == GTK_DIR_RIGHT) ? STEP_NEXT : STEP_PREV,
1379 while (child && GTK_NOTEBOOK_PAGE (last)->pack == GTK_NOTEBOOK_PAGE (child)->pack);
1384 child = gtk_notebook_search_page (notebook, notebook->focus_tab,
1385 (effective_direction == GTK_DIR_RIGHT) ? STEP_NEXT : STEP_PREV,
1388 if (!child || child->data == notebook->cur_page)
1393 if (page->pack == notebook->cur_page->pack)
1395 if (effective_direction == GTK_DIR_RIGHT)
1396 page_num = reorder_tab (notebook, (page->pack == GTK_PACK_START) ? child->next : child, notebook->focus_tab);
1398 page_num = reorder_tab (notebook, (page->pack == GTK_PACK_START) ? child : child->next, notebook->focus_tab);
1400 gtk_notebook_pages_allocate (notebook);
1402 g_signal_emit (notebook,
1403 notebook_signals[PAGE_REORDERED],
1405 ((GtkNotebookPage *) notebook->focus_tab->data)->child,
1417 * Creates a new #GtkNotebook widget with no pages.
1419 * Return value: the newly created #GtkNotebook
1422 gtk_notebook_new (void)
1424 return g_object_new (GTK_TYPE_NOTEBOOK, NULL);
1427 /* Private GtkObject Methods :
1429 * gtk_notebook_destroy
1430 * gtk_notebook_set_arg
1431 * gtk_notebook_get_arg
1434 gtk_notebook_destroy (GtkObject *object)
1436 GtkNotebook *notebook = GTK_NOTEBOOK (object);
1437 GtkNotebookPrivate *priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
1440 gtk_notebook_popup_disable (notebook);
1442 if (priv->source_targets)
1444 gtk_target_list_unref (priv->source_targets);
1445 priv->source_targets = NULL;
1448 if (priv->switch_tab_timer)
1450 g_source_remove (priv->switch_tab_timer);
1451 priv->switch_tab_timer = 0;
1454 GTK_OBJECT_CLASS (gtk_notebook_parent_class)->destroy (object);
1458 gtk_notebook_set_property (GObject *object,
1460 const GValue *value,
1463 GtkNotebook *notebook;
1465 notebook = GTK_NOTEBOOK (object);
1469 case PROP_SHOW_TABS:
1470 gtk_notebook_set_show_tabs (notebook, g_value_get_boolean (value));
1472 case PROP_SHOW_BORDER:
1473 gtk_notebook_set_show_border (notebook, g_value_get_boolean (value));
1475 case PROP_SCROLLABLE:
1476 gtk_notebook_set_scrollable (notebook, g_value_get_boolean (value));
1478 case PROP_ENABLE_POPUP:
1479 if (g_value_get_boolean (value))
1480 gtk_notebook_popup_enable (notebook);
1482 gtk_notebook_popup_disable (notebook);
1485 gtk_notebook_set_current_page (notebook, g_value_get_int (value));
1488 gtk_notebook_set_tab_pos (notebook, g_value_get_enum (value));
1491 gtk_notebook_set_group (notebook, g_value_get_pointer (value));
1494 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1500 gtk_notebook_get_property (GObject *object,
1505 GtkNotebook *notebook;
1506 GtkNotebookPrivate *priv;
1508 notebook = GTK_NOTEBOOK (object);
1509 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
1513 case PROP_SHOW_TABS:
1514 g_value_set_boolean (value, notebook->show_tabs);
1516 case PROP_SHOW_BORDER:
1517 g_value_set_boolean (value, notebook->show_border);
1519 case PROP_SCROLLABLE:
1520 g_value_set_boolean (value, notebook->scrollable);
1522 case PROP_ENABLE_POPUP:
1523 g_value_set_boolean (value, notebook->menu != NULL);
1526 g_value_set_int (value, gtk_notebook_get_current_page (notebook));
1529 g_value_set_enum (value, notebook->tab_pos);
1532 g_value_set_pointer (value, priv->group);
1535 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1540 /* Private GtkWidget Methods :
1543 * gtk_notebook_unmap
1544 * gtk_notebook_realize
1545 * gtk_notebook_size_request
1546 * gtk_notebook_size_allocate
1547 * gtk_notebook_expose
1548 * gtk_notebook_scroll
1549 * gtk_notebook_button_press
1550 * gtk_notebook_button_release
1551 * gtk_notebook_popup_menu
1552 * gtk_notebook_leave_notify
1553 * gtk_notebook_motion_notify
1554 * gtk_notebook_focus_in
1555 * gtk_notebook_focus_out
1556 * gtk_notebook_draw_focus
1557 * gtk_notebook_style_set
1558 * gtk_notebook_drag_begin
1559 * gtk_notebook_drag_end
1560 * gtk_notebook_drag_failed
1561 * gtk_notebook_drag_motion
1562 * gtk_notebook_drag_drop
1563 * gtk_notebook_drag_data_get
1564 * gtk_notebook_drag_data_received
1567 gtk_notebook_get_event_window_position (GtkNotebook *notebook,
1568 GdkRectangle *rectangle)
1570 GtkNotebookPrivate *priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
1571 GtkWidget *widget = GTK_WIDGET (notebook);
1572 gint border_width = GTK_CONTAINER (notebook)->border_width;
1573 GtkNotebookPage *visible_page = NULL;
1575 gint tab_pos = get_effective_tab_pos (notebook);
1579 for (tmp_list = notebook->children; tmp_list; tmp_list = tmp_list->next)
1581 GtkNotebookPage *page = tmp_list->data;
1582 if (gtk_widget_get_visible (page->child))
1584 visible_page = page;
1589 if (notebook->show_tabs && visible_page)
1593 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
1594 rectangle->x = widget->allocation.x + border_width;
1595 rectangle->y = widget->allocation.y + border_width;
1600 case GTK_POS_BOTTOM:
1601 rectangle->width = widget->allocation.width - 2 * border_width;
1602 rectangle->height = visible_page->requisition.height;
1603 if (tab_pos == GTK_POS_BOTTOM)
1604 rectangle->y += widget->allocation.height - 2 * border_width - rectangle->height;
1606 for (i = 0; i < N_ACTION_WIDGETS; i++)
1608 if (priv->action_widget[i] &&
1609 gtk_widget_get_visible (priv->action_widget[i]))
1611 rectangle->width -= priv->action_widget[i]->allocation.width;
1612 if ((!is_rtl && i == ACTION_WIDGET_START) ||
1613 (is_rtl && i == ACTION_WIDGET_END))
1614 rectangle->x += priv->action_widget[i]->allocation.width;
1620 rectangle->width = visible_page->requisition.width;
1621 rectangle->height = widget->allocation.height - 2 * border_width;
1622 if (tab_pos == GTK_POS_RIGHT)
1623 rectangle->x += widget->allocation.width - 2 * border_width - rectangle->width;
1625 for (i = 0; i < N_ACTION_WIDGETS; i++)
1627 if (priv->action_widget[i] &&
1628 gtk_widget_get_visible (priv->action_widget[i]))
1630 rectangle->height -= priv->action_widget[i]->allocation.height;
1632 if (i == ACTION_WIDGET_START)
1633 rectangle->y += priv->action_widget[i]->allocation.height;
1646 rectangle->x = rectangle->y = 0;
1647 rectangle->width = rectangle->height = 10;
1655 gtk_notebook_map (GtkWidget *widget)
1657 GtkNotebookPrivate *priv;
1658 GtkNotebook *notebook;
1659 GtkNotebookPage *page;
1663 gtk_widget_set_mapped (widget, TRUE);
1665 notebook = GTK_NOTEBOOK (widget);
1666 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
1668 if (notebook->cur_page &&
1669 gtk_widget_get_visible (notebook->cur_page->child) &&
1670 !gtk_widget_get_mapped (notebook->cur_page->child))
1671 gtk_widget_map (notebook->cur_page->child);
1673 for (i = 0; i < N_ACTION_WIDGETS; i++)
1675 if (priv->action_widget[i] &&
1676 gtk_widget_get_visible (priv->action_widget[i]) &&
1677 GTK_WIDGET_CHILD_VISIBLE (priv->action_widget[i]) &&
1678 !gtk_widget_get_mapped (priv->action_widget[i]))
1679 gtk_widget_map (priv->action_widget[i]);
1682 if (notebook->scrollable)
1683 gtk_notebook_pages_allocate (notebook);
1686 children = notebook->children;
1690 page = children->data;
1691 children = children->next;
1693 if (page->tab_label &&
1694 gtk_widget_get_visible (page->tab_label) &&
1695 !gtk_widget_get_mapped (page->tab_label))
1696 gtk_widget_map (page->tab_label);
1700 if (gtk_notebook_get_event_window_position (notebook, NULL))
1701 gdk_window_show_unraised (notebook->event_window);
1705 gtk_notebook_unmap (GtkWidget *widget)
1707 stop_scrolling (GTK_NOTEBOOK (widget));
1709 gtk_widget_set_mapped (widget, FALSE);
1711 gdk_window_hide (GTK_NOTEBOOK (widget)->event_window);
1713 GTK_WIDGET_CLASS (gtk_notebook_parent_class)->unmap (widget);
1717 gtk_notebook_realize (GtkWidget *widget)
1719 GtkNotebook *notebook;
1720 GdkWindowAttr attributes;
1721 gint attributes_mask;
1722 GdkRectangle event_window_pos;
1724 notebook = GTK_NOTEBOOK (widget);
1726 gtk_widget_set_realized (widget, TRUE);
1728 gtk_notebook_get_event_window_position (notebook, &event_window_pos);
1730 widget->window = gtk_widget_get_parent_window (widget);
1731 g_object_ref (widget->window);
1733 attributes.window_type = GDK_WINDOW_CHILD;
1734 attributes.x = event_window_pos.x;
1735 attributes.y = event_window_pos.y;
1736 attributes.width = event_window_pos.width;
1737 attributes.height = event_window_pos.height;
1738 attributes.wclass = GDK_INPUT_ONLY;
1739 attributes.event_mask = gtk_widget_get_events (widget);
1740 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
1741 GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK |
1742 GDK_POINTER_MOTION_MASK | GDK_LEAVE_NOTIFY_MASK |
1744 attributes_mask = GDK_WA_X | GDK_WA_Y;
1746 notebook->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
1747 &attributes, attributes_mask);
1748 gdk_window_set_user_data (notebook->event_window, notebook);
1750 widget->style = gtk_style_attach (widget->style, widget->window);
1754 gtk_notebook_unrealize (GtkWidget *widget)
1756 GtkNotebook *notebook;
1757 GtkNotebookPrivate *priv;
1759 notebook = GTK_NOTEBOOK (widget);
1760 priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
1762 gdk_window_set_user_data (notebook->event_window, NULL);
1763 gdk_window_destroy (notebook->event_window);
1764 notebook->event_window = NULL;
1766 if (priv->drag_window)
1768 gdk_window_set_user_data (priv->drag_window, NULL);
1769 gdk_window_destroy (priv->drag_window);
1770 priv->drag_window = NULL;
1773 GTK_WIDGET_CLASS (gtk_notebook_parent_class)->unrealize (widget);
1777 gtk_notebook_size_request (GtkWidget *widget,
1778 GtkRequisition *requisition)
1780 GtkNotebookPrivate *priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
1781 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
1782 GtkNotebookPage *page;
1784 GtkRequisition child_requisition;
1785 GtkRequisition action_widget_requisition[2] = { { 0 }, { 0 } };
1786 gboolean switch_page = FALSE;
1792 gint scroll_arrow_hlength;
1793 gint scroll_arrow_vlength;
1795 gtk_widget_style_get (widget,
1796 "focus-line-width", &focus_width,
1797 "tab-overlap", &tab_overlap,
1798 "tab-curvature", &tab_curvature,
1799 "arrow-spacing", &arrow_spacing,
1800 "scroll-arrow-hlength", &scroll_arrow_hlength,
1801 "scroll-arrow-vlength", &scroll_arrow_vlength,
1804 widget->requisition.width = 0;
1805 widget->requisition.height = 0;
1807 for (children = notebook->children, vis_pages = 0; children;
1808 children = children->next)
1810 page = children->data;
1812 if (gtk_widget_get_visible (page->child))
1815 gtk_widget_size_request (page->child, &child_requisition);
1817 widget->requisition.width = MAX (widget->requisition.width,
1818 child_requisition.width);
1819 widget->requisition.height = MAX (widget->requisition.height,
1820 child_requisition.height);
1822 if (notebook->menu && page->menu_label->parent &&
1823 !gtk_widget_get_visible (page->menu_label->parent))
1824 gtk_widget_show (page->menu_label->parent);
1828 if (page == notebook->cur_page)
1830 if (notebook->menu && page->menu_label->parent &&
1831 gtk_widget_get_visible (page->menu_label->parent))
1832 gtk_widget_hide (page->menu_label->parent);
1836 if (notebook->show_border || notebook->show_tabs)
1838 widget->requisition.width += widget->style->xthickness * 2;
1839 widget->requisition.height += widget->style->ythickness * 2;
1841 if (notebook->show_tabs)
1844 gint tab_height = 0;
1848 gint action_width = 0;
1849 gint action_height = 0;
1851 for (children = notebook->children; children;
1852 children = children->next)
1854 page = children->data;
1856 if (gtk_widget_get_visible (page->child))
1858 if (!gtk_widget_get_visible (page->tab_label))
1859 gtk_widget_show (page->tab_label);
1861 gtk_widget_size_request (page->tab_label,
1862 &child_requisition);
1864 page->requisition.width =
1865 child_requisition.width +
1866 2 * widget->style->xthickness;
1867 page->requisition.height =
1868 child_requisition.height +
1869 2 * widget->style->ythickness;
1871 switch (notebook->tab_pos)
1874 case GTK_POS_BOTTOM:
1875 page->requisition.height += 2 * (notebook->tab_vborder +
1877 tab_height = MAX (tab_height, page->requisition.height);
1878 tab_max = MAX (tab_max, page->requisition.width);
1882 page->requisition.width += 2 * (notebook->tab_hborder +
1884 tab_width = MAX (tab_width, page->requisition.width);
1885 tab_max = MAX (tab_max, page->requisition.height);
1889 else if (gtk_widget_get_visible (page->tab_label))
1890 gtk_widget_hide (page->tab_label);
1893 children = notebook->children;
1897 for (i = 0; i < N_ACTION_WIDGETS; i++)
1899 if (priv->action_widget[i])
1901 gtk_widget_size_request (priv->action_widget[i], &action_widget_requisition[i]);
1902 action_widget_requisition[i].width += widget->style->xthickness;
1903 action_widget_requisition[i].height += widget->style->ythickness;
1907 switch (notebook->tab_pos)
1910 case GTK_POS_BOTTOM:
1911 if (tab_height == 0)
1914 if (notebook->scrollable && vis_pages > 1 &&
1915 widget->requisition.width < tab_width)
1916 tab_height = MAX (tab_height, scroll_arrow_hlength);
1918 tab_height = MAX (tab_height, action_widget_requisition[ACTION_WIDGET_START].height);
1919 tab_height = MAX (tab_height, action_widget_requisition[ACTION_WIDGET_END].height);
1921 padding = 2 * (tab_curvature + focus_width +
1922 notebook->tab_hborder) - tab_overlap;
1926 page = children->data;
1927 children = children->next;
1929 if (!gtk_widget_get_visible (page->child))
1932 if (notebook->homogeneous)
1933 page->requisition.width = tab_max;
1935 page->requisition.width += padding;
1937 tab_width += page->requisition.width;
1938 page->requisition.height = tab_height;
1941 if (notebook->scrollable && vis_pages > 1 &&
1942 widget->requisition.width < tab_width)
1943 tab_width = tab_max + 2 * (scroll_arrow_hlength + arrow_spacing);
1945 action_width += action_widget_requisition[ACTION_WIDGET_START].width;
1946 action_width += action_widget_requisition[ACTION_WIDGET_END].width;
1947 if (notebook->homogeneous && !notebook->scrollable)
1948 widget->requisition.width = MAX (widget->requisition.width,
1949 vis_pages * tab_max +
1950 tab_overlap + action_width);
1952 widget->requisition.width = MAX (widget->requisition.width,
1953 tab_width + tab_overlap + action_width);
1955 widget->requisition.height += tab_height;
1962 if (notebook->scrollable && vis_pages > 1 &&
1963 widget->requisition.height < tab_height)
1964 tab_width = MAX (tab_width,
1965 arrow_spacing + 2 * scroll_arrow_vlength);
1967 tab_width = MAX (tab_width, action_widget_requisition[ACTION_WIDGET_START].width);
1968 tab_width = MAX (tab_width, action_widget_requisition[ACTION_WIDGET_END].width);
1970 padding = 2 * (tab_curvature + focus_width +
1971 notebook->tab_vborder) - tab_overlap;
1976 page = children->data;
1977 children = children->next;
1979 if (!gtk_widget_get_visible (page->child))
1982 page->requisition.width = tab_width;
1984 if (notebook->homogeneous)
1985 page->requisition.height = tab_max;
1987 page->requisition.height += padding;
1989 tab_height += page->requisition.height;
1992 if (notebook->scrollable && vis_pages > 1 &&
1993 widget->requisition.height < tab_height)
1994 tab_height = tab_max + (2 * scroll_arrow_vlength + arrow_spacing);
1995 action_height += action_widget_requisition[ACTION_WIDGET_START].height;
1996 action_height += action_widget_requisition[ACTION_WIDGET_END].height;
1998 if (notebook->homogeneous && !notebook->scrollable)
1999 widget->requisition.height =
2000 MAX (widget->requisition.height,
2001 vis_pages * tab_max + tab_overlap + action_height);
2003 widget->requisition.height =
2004 MAX (widget->requisition.height,
2005 tab_height + tab_overlap + action_height);
2007 if (!notebook->homogeneous || notebook->scrollable)
2009 widget->requisition.height = MAX (widget->requisition.height,
2010 vis_pages * tab_max +
2013 widget->requisition.width += tab_width;
2020 for (children = notebook->children; children;
2021 children = children->next)
2023 page = children->data;
2025 if (page->tab_label && gtk_widget_get_visible (page->tab_label))
2026 gtk_widget_hide (page->tab_label);
2031 widget->requisition.width += GTK_CONTAINER (widget)->border_width * 2;
2032 widget->requisition.height += GTK_CONTAINER (widget)->border_width * 2;
2038 for (children = notebook->children; children;
2039 children = children->next)
2041 page = children->data;
2042 if (gtk_widget_get_visible (page->child))
2044 gtk_notebook_switch_page (notebook, page);
2049 else if (gtk_widget_get_visible (widget))
2051 widget->requisition.width = GTK_CONTAINER (widget)->border_width * 2;
2052 widget->requisition.height= GTK_CONTAINER (widget)->border_width * 2;
2055 if (vis_pages && !notebook->cur_page)
2057 children = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, TRUE);
2060 notebook->first_tab = children;
2061 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (children));
2067 gtk_notebook_size_allocate (GtkWidget *widget,
2068 GtkAllocation *allocation)
2070 GtkNotebookPrivate *priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
2071 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2072 gint tab_pos = get_effective_tab_pos (notebook);
2076 gtk_widget_style_get (widget, "focus-line-width", &focus_width, NULL);
2078 widget->allocation = *allocation;
2079 if (gtk_widget_get_realized (widget))
2081 GdkRectangle position;
2083 if (gtk_notebook_get_event_window_position (notebook, &position))
2085 gdk_window_move_resize (notebook->event_window,
2086 position.x, position.y,
2087 position.width, position.height);
2088 if (gtk_widget_get_mapped (GTK_WIDGET (notebook)))
2089 gdk_window_show_unraised (notebook->event_window);
2092 gdk_window_hide (notebook->event_window);
2095 if (notebook->children)
2097 gint border_width = GTK_CONTAINER (widget)->border_width;
2098 GtkNotebookPage *page;
2099 GtkAllocation child_allocation;
2103 child_allocation.x = widget->allocation.x + border_width;
2104 child_allocation.y = widget->allocation.y + border_width;
2105 child_allocation.width = MAX (1, allocation->width - border_width * 2);
2106 child_allocation.height = MAX (1, allocation->height - border_width * 2);
2108 if (notebook->show_tabs || notebook->show_border)
2110 child_allocation.x += widget->style->xthickness;
2111 child_allocation.y += widget->style->ythickness;
2112 child_allocation.width = MAX (1, child_allocation.width -
2113 widget->style->xthickness * 2);
2114 child_allocation.height = MAX (1, child_allocation.height -
2115 widget->style->ythickness * 2);
2117 if (notebook->show_tabs && notebook->children && notebook->cur_page)
2122 child_allocation.y += notebook->cur_page->requisition.height;
2123 case GTK_POS_BOTTOM:
2124 child_allocation.height =
2125 MAX (1, child_allocation.height -
2126 notebook->cur_page->requisition.height);
2129 child_allocation.x += notebook->cur_page->requisition.width;
2131 child_allocation.width =
2132 MAX (1, child_allocation.width -
2133 notebook->cur_page->requisition.width);
2137 for (i = 0; i < N_ACTION_WIDGETS; i++)
2139 GtkAllocation widget_allocation;
2141 if (!priv->action_widget[i])
2144 widget_allocation.x = widget->allocation.x + border_width;
2145 widget_allocation.y = widget->allocation.y + border_width;
2146 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2150 case GTK_POS_BOTTOM:
2151 widget_allocation.y +=
2152 widget->allocation.height - 2 * border_width - notebook->cur_page->requisition.height;
2155 widget_allocation.width = priv->action_widget[i]->requisition.width;
2156 widget_allocation.height = notebook->cur_page->requisition.height - widget->style->ythickness;
2158 if ((i == ACTION_WIDGET_START && is_rtl) ||
2159 (i == ACTION_WIDGET_END && !is_rtl))
2160 widget_allocation.x +=
2161 widget->allocation.width - 2 * border_width -
2162 priv->action_widget[i]->requisition.width;
2163 if (tab_pos == GTK_POS_TOP) /* no fall through */
2164 widget_allocation.y += 2 * focus_width;
2167 widget_allocation.x +=
2168 widget->allocation.width - 2 * border_width - notebook->cur_page->requisition.width;
2171 widget_allocation.height = priv->action_widget[i]->requisition.height;
2172 widget_allocation.width = notebook->cur_page->requisition.width - widget->style->xthickness;
2174 if (i == ACTION_WIDGET_END)
2175 widget_allocation.y +=
2176 widget->allocation.height - 2 * border_width -
2177 priv->action_widget[i]->requisition.height;
2178 if (tab_pos == GTK_POS_LEFT) /* no fall through */
2179 widget_allocation.x += 2 * focus_width;
2183 gtk_widget_size_allocate (priv->action_widget[i], &widget_allocation);
2188 children = notebook->children;
2191 page = children->data;
2192 children = children->next;
2194 if (gtk_widget_get_visible (page->child))
2195 gtk_widget_size_allocate (page->child, &child_allocation);
2198 gtk_notebook_pages_allocate (notebook);
2203 gtk_notebook_expose (GtkWidget *widget,
2204 GdkEventExpose *event)
2206 GtkNotebook *notebook;
2207 GtkNotebookPrivate *priv;
2210 notebook = GTK_NOTEBOOK (widget);
2211 priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
2213 if (event->window == priv->drag_window)
2215 GdkRectangle area = { 0, };
2218 /* FIXME: This is a workaround to make tabs reordering work better
2219 * with engines with rounded tabs. If the drag window background
2220 * isn't set, the rounded corners would be black.
2222 * Ideally, these corners should be made transparent, Either by using
2223 * ARGB visuals or shape windows.
2225 cr = gdk_cairo_create (priv->drag_window);
2226 gdk_cairo_set_source_color (cr, &widget->style->bg [GTK_STATE_NORMAL]);
2230 gdk_drawable_get_size (priv->drag_window,
2231 &area.width, &area.height);
2232 gtk_notebook_draw_tab (notebook,
2235 gtk_notebook_draw_focus (widget, event);
2236 gtk_container_propagate_expose (GTK_CONTAINER (notebook),
2237 notebook->cur_page->tab_label, event);
2239 else if (gtk_widget_is_drawable (widget))
2241 gtk_notebook_paint (widget, &event->area);
2242 if (notebook->show_tabs)
2244 GtkNotebookPage *page;
2247 gtk_notebook_draw_focus (widget, event);
2248 pages = notebook->children;
2252 page = GTK_NOTEBOOK_PAGE (pages);
2253 pages = pages->next;
2255 if (page->tab_label->window == event->window &&
2256 gtk_widget_is_drawable (page->tab_label))
2257 gtk_container_propagate_expose (GTK_CONTAINER (notebook),
2258 page->tab_label, event);
2262 if (notebook->cur_page)
2263 gtk_container_propagate_expose (GTK_CONTAINER (notebook),
2264 notebook->cur_page->child,
2266 if (notebook->show_tabs)
2268 for (i = 0; i < N_ACTION_WIDGETS; i++)
2270 if (priv->action_widget[i] &&
2271 gtk_widget_is_drawable (priv->action_widget[i]))
2272 gtk_container_propagate_expose (GTK_CONTAINER (notebook),
2273 priv->action_widget[i], event);
2282 gtk_notebook_show_arrows (GtkNotebook *notebook)
2284 gboolean show_arrow = FALSE;
2287 if (!notebook->scrollable)
2290 children = notebook->children;
2293 GtkNotebookPage *page = children->data;
2295 if (page->tab_label && !gtk_widget_get_child_visible (page->tab_label))
2298 children = children->next;
2305 gtk_notebook_get_arrow_rect (GtkNotebook *notebook,
2306 GdkRectangle *rectangle,
2307 GtkNotebookArrow arrow)
2309 GdkRectangle event_window_pos;
2310 gboolean before = ARROW_IS_BEFORE (arrow);
2311 gboolean left = ARROW_IS_LEFT (arrow);
2313 if (gtk_notebook_get_event_window_position (notebook, &event_window_pos))
2315 gint scroll_arrow_hlength;
2316 gint scroll_arrow_vlength;
2318 gtk_widget_style_get (GTK_WIDGET (notebook),
2319 "scroll-arrow-hlength", &scroll_arrow_hlength,
2320 "scroll-arrow-vlength", &scroll_arrow_vlength,
2323 switch (notebook->tab_pos)
2327 rectangle->width = scroll_arrow_vlength;
2328 rectangle->height = scroll_arrow_vlength;
2330 if ((before && (notebook->has_before_previous != notebook->has_before_next)) ||
2331 (!before && (notebook->has_after_previous != notebook->has_after_next)))
2332 rectangle->x = event_window_pos.x + (event_window_pos.width - rectangle->width) / 2;
2334 rectangle->x = event_window_pos.x + event_window_pos.width / 2 - rectangle->width;
2336 rectangle->x = event_window_pos.x + event_window_pos.width / 2;
2337 rectangle->y = event_window_pos.y;
2339 rectangle->y += event_window_pos.height - rectangle->height;
2343 case GTK_POS_BOTTOM:
2344 rectangle->width = scroll_arrow_hlength;
2345 rectangle->height = scroll_arrow_hlength;
2349 if (left || !notebook->has_before_previous)
2350 rectangle->x = event_window_pos.x;
2352 rectangle->x = event_window_pos.x + rectangle->width;
2356 if (!left || !notebook->has_after_next)
2357 rectangle->x = event_window_pos.x + event_window_pos.width - rectangle->width;
2359 rectangle->x = event_window_pos.x + event_window_pos.width - 2 * rectangle->width;
2361 rectangle->y = event_window_pos.y + (event_window_pos.height - rectangle->height) / 2;
2367 static GtkNotebookArrow
2368 gtk_notebook_get_arrow (GtkNotebook *notebook,
2372 GdkRectangle arrow_rect;
2373 GdkRectangle event_window_pos;
2376 GtkNotebookArrow arrow[4];
2378 arrow[0] = notebook->has_before_previous ? ARROW_LEFT_BEFORE : ARROW_NONE;
2379 arrow[1] = notebook->has_before_next ? ARROW_RIGHT_BEFORE : ARROW_NONE;
2380 arrow[2] = notebook->has_after_previous ? ARROW_LEFT_AFTER : ARROW_NONE;
2381 arrow[3] = notebook->has_after_next ? ARROW_RIGHT_AFTER : ARROW_NONE;
2383 if (gtk_notebook_show_arrows (notebook))
2385 gtk_notebook_get_event_window_position (notebook, &event_window_pos);
2386 for (i = 0; i < 4; i++)
2388 if (arrow[i] == ARROW_NONE)
2391 gtk_notebook_get_arrow_rect (notebook, &arrow_rect, arrow[i]);
2393 x0 = x - arrow_rect.x;
2394 y0 = y - arrow_rect.y;
2396 if (y0 >= 0 && y0 < arrow_rect.height &&
2397 x0 >= 0 && x0 < arrow_rect.width)
2406 gtk_notebook_do_arrow (GtkNotebook *notebook,
2407 GtkNotebookArrow arrow)
2409 GtkWidget *widget = GTK_WIDGET (notebook);
2410 gboolean is_rtl, left;
2412 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2413 left = (ARROW_IS_LEFT (arrow) && !is_rtl) ||
2414 (!ARROW_IS_LEFT (arrow) && is_rtl);
2416 if (!notebook->focus_tab ||
2417 gtk_notebook_search_page (notebook, notebook->focus_tab,
2418 left ? STEP_PREV : STEP_NEXT,
2421 gtk_notebook_change_current_page (notebook, left ? -1 : 1);
2422 gtk_widget_grab_focus (widget);
2427 gtk_notebook_arrow_button_press (GtkNotebook *notebook,
2428 GtkNotebookArrow arrow,
2431 GtkWidget *widget = GTK_WIDGET (notebook);
2432 gboolean is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2433 gboolean left = (ARROW_IS_LEFT (arrow) && !is_rtl) ||
2434 (!ARROW_IS_LEFT (arrow) && is_rtl);
2436 if (!gtk_widget_has_focus (widget))
2437 gtk_widget_grab_focus (widget);
2439 notebook->button = button;
2440 notebook->click_child = arrow;
2444 gtk_notebook_do_arrow (notebook, arrow);
2445 gtk_notebook_set_scroll_timer (notebook);
2447 else if (button == 2)
2448 gtk_notebook_page_select (notebook, TRUE);
2449 else if (button == 3)
2450 gtk_notebook_switch_focus_tab (notebook,
2451 gtk_notebook_search_page (notebook,
2453 left ? STEP_NEXT : STEP_PREV,
2455 gtk_notebook_redraw_arrows (notebook);
2461 get_widget_coordinates (GtkWidget *widget,
2466 GdkWindow *window = ((GdkEventAny *)event)->window;
2469 if (!gdk_event_get_coords (event, &tx, &ty))
2472 while (window && window != widget->window)
2474 gint window_x, window_y;
2476 gdk_window_get_position (window, &window_x, &window_y);
2480 window = gdk_window_get_parent (window);
2495 gtk_notebook_scroll (GtkWidget *widget,
2496 GdkEventScroll *event)
2498 GtkNotebookPrivate *priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
2499 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2500 GtkWidget *child, *event_widget;
2503 if (!notebook->cur_page)
2506 child = notebook->cur_page->child;
2507 event_widget = gtk_get_event_widget ((GdkEvent *)event);
2509 /* ignore scroll events from the content of the page */
2510 if (!event_widget || gtk_widget_is_ancestor (event_widget, child) || event_widget == child)
2513 /* nor from the action area */
2514 for (i = 0; i < 2; i++)
2516 if (event_widget == priv->action_widget[i] ||
2517 gtk_widget_is_ancestor (event_widget, priv->action_widget[i]))
2521 switch (event->direction)
2523 case GDK_SCROLL_RIGHT:
2524 case GDK_SCROLL_DOWN:
2525 gtk_notebook_next_page (notebook);
2527 case GDK_SCROLL_LEFT:
2529 gtk_notebook_prev_page (notebook);
2537 get_tab_at_pos (GtkNotebook *notebook, gint x, gint y)
2539 GtkNotebookPage *page;
2540 GList *children = notebook->children;
2544 page = children->data;
2546 if (gtk_widget_get_visible (page->child) &&
2547 page->tab_label && gtk_widget_get_mapped (page->tab_label) &&
2548 (x >= page->allocation.x) &&
2549 (y >= page->allocation.y) &&
2550 (x <= (page->allocation.x + page->allocation.width)) &&
2551 (y <= (page->allocation.y + page->allocation.height)))
2554 children = children->next;
2561 gtk_notebook_button_press (GtkWidget *widget,
2562 GdkEventButton *event)
2564 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2565 GtkNotebookPrivate *priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
2566 GtkNotebookPage *page;
2568 GtkNotebookArrow arrow;
2571 if (event->type != GDK_BUTTON_PRESS || !notebook->children ||
2575 if (!get_widget_coordinates (widget, (GdkEvent *)event, &x, &y))
2578 arrow = gtk_notebook_get_arrow (notebook, x, y);
2580 return gtk_notebook_arrow_button_press (notebook, arrow, event->button);
2582 if (event->button == 3 && notebook->menu)
2584 gtk_menu_popup (GTK_MENU (notebook->menu), NULL, NULL,
2585 NULL, NULL, 3, event->time);
2589 if (event->button != 1)
2592 notebook->button = event->button;
2594 if ((tab = get_tab_at_pos (notebook, x, y)) != NULL)
2596 gboolean page_changed, was_focus;
2599 page_changed = page != notebook->cur_page;
2600 was_focus = gtk_widget_is_focus (widget);
2602 gtk_notebook_switch_focus_tab (notebook, tab);
2603 gtk_widget_grab_focus (widget);
2605 if (page_changed && !was_focus)
2606 gtk_widget_child_focus (page->child, GTK_DIR_TAB_FORWARD);
2608 /* save press to possibly begin a drag */
2609 if (page->reorderable || page->detachable)
2611 priv->during_detach = FALSE;
2612 priv->during_reorder = FALSE;
2613 priv->pressed_button = event->button;
2618 priv->drag_begin_x = priv->mouse_x;
2619 priv->drag_begin_y = priv->mouse_y;
2620 priv->drag_offset_x = priv->drag_begin_x - page->allocation.x;
2621 priv->drag_offset_y = priv->drag_begin_y - page->allocation.y;
2629 popup_position_func (GtkMenu *menu,
2635 GtkNotebook *notebook = data;
2637 GtkRequisition requisition;
2639 if (notebook->focus_tab)
2641 GtkNotebookPage *page;
2643 page = notebook->focus_tab->data;
2644 w = page->tab_label;
2648 w = GTK_WIDGET (notebook);
2651 gdk_window_get_origin (w->window, x, y);
2652 gtk_widget_size_request (GTK_WIDGET (menu), &requisition);
2654 if (gtk_widget_get_direction (w) == GTK_TEXT_DIR_RTL)
2655 *x += w->allocation.x + w->allocation.width - requisition.width;
2657 *x += w->allocation.x;
2659 *y += w->allocation.y + w->allocation.height;
2665 gtk_notebook_popup_menu (GtkWidget *widget)
2667 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2671 gtk_menu_popup (GTK_MENU (notebook->menu), NULL, NULL,
2672 popup_position_func, notebook,
2673 0, gtk_get_current_event_time ());
2674 gtk_menu_shell_select_first (GTK_MENU_SHELL (notebook->menu), FALSE);
2682 stop_scrolling (GtkNotebook *notebook)
2684 if (notebook->timer)
2686 g_source_remove (notebook->timer);
2687 notebook->timer = 0;
2688 notebook->need_timer = FALSE;
2690 notebook->click_child = 0;
2691 notebook->button = 0;
2692 gtk_notebook_redraw_arrows (notebook);
2696 get_drop_position (GtkNotebook *notebook,
2699 GtkNotebookPrivate *priv;
2700 GList *children, *last_child;
2701 GtkNotebookPage *page;
2705 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
2709 is_rtl = gtk_widget_get_direction ((GtkWidget *) notebook) == GTK_TEXT_DIR_RTL;
2710 children = notebook->children;
2715 page = children->data;
2717 if ((priv->operation != DRAG_OPERATION_REORDER || page != notebook->cur_page) &&
2718 gtk_widget_get_visible (page->child) &&
2720 gtk_widget_get_mapped (page->tab_label) &&
2723 switch (notebook->tab_pos)
2726 case GTK_POS_BOTTOM:
2729 if ((page->pack == GTK_PACK_START && PAGE_MIDDLE_X (page) > x) ||
2730 (page->pack == GTK_PACK_END && PAGE_MIDDLE_X (page) < x))
2735 if ((page->pack == GTK_PACK_START && PAGE_MIDDLE_X (page) < x) ||
2736 (page->pack == GTK_PACK_END && PAGE_MIDDLE_X (page) > x))
2743 if ((page->pack == GTK_PACK_START && PAGE_MIDDLE_Y (page) > y) ||
2744 (page->pack == GTK_PACK_END && PAGE_MIDDLE_Y (page) < y))
2750 last_child = children->next;
2753 children = children->next;
2760 show_drag_window (GtkNotebook *notebook,
2761 GtkNotebookPrivate *priv,
2762 GtkNotebookPage *page,
2765 GtkWidget *widget = GTK_WIDGET (notebook);
2767 if (!priv->drag_window)
2769 GdkWindowAttr attributes;
2770 guint attributes_mask;
2772 attributes.x = page->allocation.x;
2773 attributes.y = page->allocation.y;
2774 attributes.width = page->allocation.width;
2775 attributes.height = page->allocation.height;
2776 attributes.window_type = GDK_WINDOW_CHILD;
2777 attributes.wclass = GDK_INPUT_OUTPUT;
2778 attributes.visual = gtk_widget_get_visual (widget);
2779 attributes.colormap = gtk_widget_get_colormap (widget);
2780 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
2781 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2783 priv->drag_window = gdk_window_new (gtk_widget_get_parent_window (widget),
2786 gdk_window_set_user_data (priv->drag_window, widget);
2789 g_object_ref (page->tab_label);
2790 gtk_widget_unparent (page->tab_label);
2791 gtk_widget_set_parent_window (page->tab_label, priv->drag_window);
2792 gtk_widget_set_parent (page->tab_label, widget);
2793 g_object_unref (page->tab_label);
2795 gdk_window_show (priv->drag_window);
2797 /* the grab will dissapear when the window is hidden */
2798 gdk_device_grab (device, priv->drag_window,
2799 GDK_OWNERSHIP_WINDOW, FALSE,
2800 GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK,
2801 NULL, GDK_CURRENT_TIME);
2804 /* This function undoes the reparenting that happens both when drag_window
2805 * is shown for reordering and when the DnD icon is shown for detaching
2808 hide_drag_window (GtkNotebook *notebook,
2809 GtkNotebookPrivate *priv,
2810 GtkNotebookPage *page)
2812 GtkWidget *widget = GTK_WIDGET (notebook);
2813 GtkWidget *parent = page->tab_label->parent;
2815 if (page->tab_label->window != widget->window ||
2816 !NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page))
2818 g_object_ref (page->tab_label);
2820 if (GTK_IS_WINDOW (parent))
2822 /* parent widget is the drag window */
2823 gtk_container_remove (GTK_CONTAINER (parent), page->tab_label);
2826 gtk_widget_unparent (page->tab_label);
2828 gtk_widget_set_parent (page->tab_label, widget);
2829 g_object_unref (page->tab_label);
2832 if (priv->drag_window &&
2833 gdk_window_is_visible (priv->drag_window))
2834 gdk_window_hide (priv->drag_window);
2838 gtk_notebook_stop_reorder (GtkNotebook *notebook)
2840 GtkNotebookPrivate *priv;
2841 GtkNotebookPage *page;
2843 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
2845 if (priv->operation == DRAG_OPERATION_DETACH)
2846 page = priv->detached_tab;
2848 page = notebook->cur_page;
2850 if (!page || !page->tab_label)
2853 priv->pressed_button = -1;
2855 if (page->reorderable || page->detachable)
2857 if (priv->during_reorder)
2859 gint old_page_num, page_num;
2862 element = get_drop_position (notebook, page->pack);
2863 old_page_num = g_list_position (notebook->children, notebook->focus_tab);
2864 page_num = reorder_tab (notebook, element, notebook->focus_tab);
2865 gtk_notebook_child_reordered (notebook, page);
2867 if (priv->has_scrolled || old_page_num != page_num)
2868 g_signal_emit (notebook,
2869 notebook_signals[PAGE_REORDERED], 0,
2870 page->child, page_num);
2872 priv->has_scrolled = FALSE;
2873 priv->during_reorder = FALSE;
2876 hide_drag_window (notebook, priv, page);
2878 priv->operation = DRAG_OPERATION_NONE;
2879 gtk_notebook_pages_allocate (notebook);
2881 if (priv->dnd_timer)
2883 g_source_remove (priv->dnd_timer);
2884 priv->dnd_timer = 0;
2890 gtk_notebook_button_release (GtkWidget *widget,
2891 GdkEventButton *event)
2893 GtkNotebook *notebook;
2894 GtkNotebookPrivate *priv;
2895 GtkNotebookPage *page;
2897 if (event->type != GDK_BUTTON_RELEASE)
2900 notebook = GTK_NOTEBOOK (widget);
2901 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
2902 page = notebook->cur_page;
2904 if (!priv->during_detach &&
2905 page->reorderable &&
2906 event->button == priv->pressed_button)
2907 gtk_notebook_stop_reorder (notebook);
2909 if (event->button == notebook->button)
2911 stop_scrolling (notebook);
2919 gtk_notebook_leave_notify (GtkWidget *widget,
2920 GdkEventCrossing *event)
2922 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2925 if (!get_widget_coordinates (widget, (GdkEvent *)event, &x, &y))
2928 if (notebook->in_child)
2930 notebook->in_child = 0;
2931 gtk_notebook_redraw_arrows (notebook);
2937 static GtkNotebookPointerPosition
2938 get_pointer_position (GtkNotebook *notebook)
2940 GtkWidget *widget = (GtkWidget *) notebook;
2941 GtkNotebookPrivate *priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
2942 gint wx, wy, width, height;
2945 if (!notebook->scrollable)
2946 return POINTER_BETWEEN;
2948 gdk_window_get_position (notebook->event_window, &wx, &wy);
2949 gdk_drawable_get_size (GDK_DRAWABLE (notebook->event_window), &width, &height);
2951 if (notebook->tab_pos == GTK_POS_TOP ||
2952 notebook->tab_pos == GTK_POS_BOTTOM)
2956 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2957 x = priv->mouse_x - wx;
2959 if (x > width - SCROLL_THRESHOLD)
2960 return (is_rtl) ? POINTER_BEFORE : POINTER_AFTER;
2961 else if (x < SCROLL_THRESHOLD)
2962 return (is_rtl) ? POINTER_AFTER : POINTER_BEFORE;
2964 return POINTER_BETWEEN;
2970 y = priv->mouse_y - wy;
2971 if (y > height - SCROLL_THRESHOLD)
2972 return POINTER_AFTER;
2973 else if (y < SCROLL_THRESHOLD)
2974 return POINTER_BEFORE;
2976 return POINTER_BETWEEN;
2981 scroll_notebook_timer (gpointer data)
2983 GtkNotebook *notebook = (GtkNotebook *) data;
2984 GtkNotebookPrivate *priv;
2985 GtkNotebookPointerPosition pointer_position;
2986 GList *element, *first_tab;
2988 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
2989 pointer_position = get_pointer_position (notebook);
2991 element = get_drop_position (notebook, notebook->cur_page->pack);
2992 reorder_tab (notebook, element, notebook->focus_tab);
2993 first_tab = gtk_notebook_search_page (notebook, notebook->first_tab,
2994 (pointer_position == POINTER_BEFORE) ? STEP_PREV : STEP_NEXT,
2998 notebook->first_tab = first_tab;
2999 gtk_notebook_pages_allocate (notebook);
3001 gdk_window_move_resize (priv->drag_window,
3002 priv->drag_window_x,
3003 priv->drag_window_y,
3004 notebook->cur_page->allocation.width,
3005 notebook->cur_page->allocation.height);
3006 gdk_window_raise (priv->drag_window);
3013 check_threshold (GtkNotebook *notebook,
3019 GdkRectangle rectangle = { 0, }; /* shut up gcc */
3020 GtkSettings *settings;
3022 widget = GTK_WIDGET (notebook);
3023 settings = gtk_widget_get_settings (GTK_WIDGET (notebook));
3024 g_object_get (G_OBJECT (settings), "gtk-dnd-drag-threshold", &dnd_threshold, NULL);
3026 /* we want a large threshold */
3027 dnd_threshold *= DND_THRESHOLD_MULTIPLIER;
3029 gdk_window_get_position (notebook->event_window, &rectangle.x, &rectangle.y);
3030 gdk_drawable_get_size (GDK_DRAWABLE (notebook->event_window), &rectangle.width, &rectangle.height);
3032 rectangle.x -= dnd_threshold;
3033 rectangle.width += 2 * dnd_threshold;
3034 rectangle.y -= dnd_threshold;
3035 rectangle.height += 2 * dnd_threshold;
3037 return (current_x < rectangle.x ||
3038 current_x > rectangle.x + rectangle.width ||
3039 current_y < rectangle.y ||
3040 current_y > rectangle.y + rectangle.height);
3044 gtk_notebook_motion_notify (GtkWidget *widget,
3045 GdkEventMotion *event)
3047 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
3048 GtkNotebookPrivate *priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
3049 GtkNotebookPage *page;
3050 GtkNotebookArrow arrow;
3051 GtkNotebookPointerPosition pointer_position;
3052 GtkSettings *settings;
3056 page = notebook->cur_page;
3061 if (!(event->state & GDK_BUTTON1_MASK) &&
3062 priv->pressed_button != -1)
3064 gtk_notebook_stop_reorder (notebook);
3065 stop_scrolling (notebook);
3068 if (event->time < priv->timestamp + MSECS_BETWEEN_UPDATES)
3071 priv->timestamp = event->time;
3073 /* While animating the move, event->x is relative to the flying tab
3074 * (priv->drag_window has a pointer grab), but we need coordinates relative to
3075 * the notebook widget.
3077 gdk_window_get_origin (widget->window, &x_win, &y_win);
3078 priv->mouse_x = event->x_root - x_win;
3079 priv->mouse_y = event->y_root - y_win;
3081 arrow = gtk_notebook_get_arrow (notebook, priv->mouse_x, priv->mouse_y);
3082 if (arrow != notebook->in_child)
3084 notebook->in_child = arrow;
3085 gtk_notebook_redraw_arrows (notebook);
3088 if (priv->pressed_button == -1)
3091 if (page->detachable &&
3092 check_threshold (notebook, priv->mouse_x, priv->mouse_y))
3094 priv->detached_tab = notebook->cur_page;
3095 priv->during_detach = TRUE;
3097 gtk_drag_begin (widget, priv->source_targets, GDK_ACTION_MOVE,
3098 priv->pressed_button, (GdkEvent*) event);
3102 if (page->reorderable &&
3103 (priv->during_reorder ||
3104 gtk_drag_check_threshold (widget, priv->drag_begin_x, priv->drag_begin_y, priv->mouse_x, priv->mouse_y)))
3106 priv->during_reorder = TRUE;
3107 pointer_position = get_pointer_position (notebook);
3109 if (event->window == priv->drag_window &&
3110 pointer_position != POINTER_BETWEEN &&
3111 gtk_notebook_show_arrows (notebook))
3114 if (!priv->dnd_timer)
3116 priv->has_scrolled = TRUE;
3117 settings = gtk_widget_get_settings (GTK_WIDGET (notebook));
3118 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
3120 priv->dnd_timer = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
3121 scroll_notebook_timer,
3122 (gpointer) notebook);
3127 if (priv->dnd_timer)
3129 g_source_remove (priv->dnd_timer);
3130 priv->dnd_timer = 0;
3134 if (event->window == priv->drag_window ||
3135 priv->operation != DRAG_OPERATION_REORDER)
3137 /* the drag operation is beginning, create the window */
3138 if (priv->operation != DRAG_OPERATION_REORDER)
3140 priv->operation = DRAG_OPERATION_REORDER;
3141 show_drag_window (notebook, priv, page, event->device);
3144 gtk_notebook_pages_allocate (notebook);
3145 gdk_window_move_resize (priv->drag_window,
3146 priv->drag_window_x,
3147 priv->drag_window_y,
3148 page->allocation.width,
3149 page->allocation.height);
3157 gtk_notebook_grab_notify (GtkWidget *widget,
3158 gboolean was_grabbed)
3160 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
3164 gtk_notebook_stop_reorder (notebook);
3165 stop_scrolling (notebook);
3170 gtk_notebook_state_changed (GtkWidget *widget,
3171 GtkStateType previous_state)
3173 if (!gtk_widget_is_sensitive (widget))
3174 stop_scrolling (GTK_NOTEBOOK (widget));
3178 gtk_notebook_focus_in (GtkWidget *widget,
3179 GdkEventFocus *event)
3181 gtk_notebook_redraw_tabs (GTK_NOTEBOOK (widget));
3187 gtk_notebook_focus_out (GtkWidget *widget,
3188 GdkEventFocus *event)
3190 gtk_notebook_redraw_tabs (GTK_NOTEBOOK (widget));
3196 gtk_notebook_draw_focus (GtkWidget *widget,
3197 GdkEventExpose *event)
3199 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
3201 if (gtk_widget_has_focus (widget) && gtk_widget_is_drawable (widget) &&
3202 notebook->show_tabs && notebook->cur_page &&
3203 notebook->cur_page->tab_label->window == event->window)
3205 GtkNotebookPage *page;
3207 page = notebook->cur_page;
3209 if (gtk_widget_intersect (page->tab_label, &event->area, NULL))
3214 gtk_widget_style_get (widget, "focus-line-width", &focus_width, NULL);
3216 area.x = page->tab_label->allocation.x - focus_width;
3217 area.y = page->tab_label->allocation.y - focus_width;
3218 area.width = page->tab_label->allocation.width + 2 * focus_width;
3219 area.height = page->tab_label->allocation.height + 2 * focus_width;
3221 gtk_paint_focus (widget->style, event->window,
3222 gtk_widget_get_state (widget), NULL, widget, "tab",
3223 area.x, area.y, area.width, area.height);
3229 gtk_notebook_style_set (GtkWidget *widget,
3232 GtkNotebook *notebook;
3234 gboolean has_before_previous;
3235 gboolean has_before_next;
3236 gboolean has_after_previous;
3237 gboolean has_after_next;
3239 notebook = GTK_NOTEBOOK (widget);
3241 gtk_widget_style_get (widget,
3242 "has-backward-stepper", &has_before_previous,
3243 "has-secondary-forward-stepper", &has_before_next,
3244 "has-secondary-backward-stepper", &has_after_previous,
3245 "has-forward-stepper", &has_after_next,
3248 notebook->has_before_previous = has_before_previous;
3249 notebook->has_before_next = has_before_next;
3250 notebook->has_after_previous = has_after_previous;
3251 notebook->has_after_next = has_after_next;
3253 GTK_WIDGET_CLASS (gtk_notebook_parent_class)->style_set (widget, previous);
3257 on_drag_icon_expose (GtkWidget *widget,
3258 GdkEventExpose *event,
3261 GtkWidget *notebook, *child = GTK_WIDGET (data);
3262 GtkRequisition requisition;
3265 notebook = GTK_WIDGET (data);
3266 child = GTK_BIN (widget)->child;
3267 gtk_widget_size_request (widget, &requisition);
3268 gap_pos = get_tab_gap_pos (GTK_NOTEBOOK (notebook));
3270 gtk_paint_extension (notebook->style, widget->window,
3271 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
3272 NULL, widget, "tab",
3274 requisition.width, requisition.height,
3277 gtk_container_propagate_expose (GTK_CONTAINER (widget), child, event);
3283 gtk_notebook_drag_begin (GtkWidget *widget,
3284 GdkDragContext *context)
3286 GtkNotebookPrivate *priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
3287 GtkNotebook *notebook = (GtkNotebook*) widget;
3288 GtkWidget *tab_label;
3290 if (priv->dnd_timer)
3292 g_source_remove (priv->dnd_timer);
3293 priv->dnd_timer = 0;
3296 priv->operation = DRAG_OPERATION_DETACH;
3297 gtk_notebook_pages_allocate (notebook);
3299 tab_label = priv->detached_tab->tab_label;
3301 hide_drag_window (notebook, priv, notebook->cur_page);
3302 g_object_ref (tab_label);
3303 gtk_widget_unparent (tab_label);
3305 priv->dnd_window = gtk_window_new (GTK_WINDOW_POPUP);
3306 gtk_window_set_screen (GTK_WINDOW (priv->dnd_window),
3307 gtk_widget_get_screen (widget));
3308 gtk_container_add (GTK_CONTAINER (priv->dnd_window), tab_label);
3309 gtk_widget_set_size_request (priv->dnd_window,
3310 priv->detached_tab->allocation.width,
3311 priv->detached_tab->allocation.height);
3312 g_object_unref (tab_label);
3314 g_signal_connect (G_OBJECT (priv->dnd_window), "expose-event",
3315 G_CALLBACK (on_drag_icon_expose), notebook);
3317 gtk_drag_set_icon_widget (context, priv->dnd_window, -2, -2);
3321 gtk_notebook_drag_end (GtkWidget *widget,
3322 GdkDragContext *context)
3324 GtkNotebookPrivate *priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
3326 gtk_notebook_stop_reorder (GTK_NOTEBOOK (widget));
3328 if (priv->detached_tab)
3329 gtk_notebook_switch_page (GTK_NOTEBOOK (widget), priv->detached_tab);
3331 GTK_BIN (priv->dnd_window)->child = NULL;
3332 gtk_widget_destroy (priv->dnd_window);
3333 priv->dnd_window = NULL;
3335 priv->operation = DRAG_OPERATION_NONE;
3338 static GtkNotebook *
3339 gtk_notebook_create_window (GtkNotebook *notebook,
3344 if (window_creation_hook)
3345 return (* window_creation_hook) (notebook, page, x, y, window_creation_hook_data);
3351 gtk_notebook_drag_failed (GtkWidget *widget,
3352 GdkDragContext *context,
3353 GtkDragResult result,
3356 if (result == GTK_DRAG_RESULT_NO_TARGET)
3358 GtkNotebookPrivate *priv;
3359 GtkNotebook *notebook, *dest_notebook = NULL;
3360 GdkDisplay *display;
3363 notebook = GTK_NOTEBOOK (widget);
3364 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
3366 display = gtk_widget_get_display (widget);
3367 gdk_display_get_pointer (display, NULL, &x, &y, NULL);
3369 g_signal_emit (notebook, notebook_signals[CREATE_WINDOW], 0,
3370 priv->detached_tab->child, x, y, &dest_notebook);
3373 do_detach_tab (notebook, dest_notebook, priv->detached_tab->child, 0, 0);
3382 gtk_notebook_switch_tab_timeout (gpointer data)
3384 GtkNotebook *notebook;
3385 GtkNotebookPrivate *priv;
3389 notebook = GTK_NOTEBOOK (data);
3390 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
3392 priv->switch_tab_timer = 0;
3396 if ((tab = get_tab_at_pos (notebook, x, y)) != NULL)
3398 /* FIXME: hack, we don't want the
3399 * focus to move fom the source widget
3401 notebook->child_has_focus = FALSE;
3402 gtk_notebook_switch_focus_tab (notebook, tab);
3409 gtk_notebook_drag_motion (GtkWidget *widget,
3410 GdkDragContext *context,
3415 GtkNotebook *notebook;
3416 GtkNotebookPrivate *priv;
3417 GdkRectangle position;
3418 GtkSettings *settings;
3419 GtkNotebookArrow arrow;
3421 GdkAtom target, tab_target;
3423 notebook = GTK_NOTEBOOK (widget);
3424 arrow = gtk_notebook_get_arrow (notebook,
3425 x + widget->allocation.x,
3426 y + widget->allocation.y);
3429 notebook->click_child = arrow;
3430 gtk_notebook_set_scroll_timer (notebook);
3431 gdk_drag_status (context, 0, time);
3435 stop_scrolling (notebook);
3436 target = gtk_drag_dest_find_target (widget, context, NULL);
3437 tab_target = gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB");
3439 if (target == tab_target)
3441 gpointer widget_group, source_widget_group;
3442 GtkWidget *source_widget;
3444 source_widget = gtk_drag_get_source_widget (context);
3445 g_assert (source_widget);
3447 widget_group = gtk_notebook_get_group (notebook);
3448 source_widget_group = gtk_notebook_get_group (GTK_NOTEBOOK (source_widget));
3450 if (widget_group && source_widget_group &&
3451 widget_group == source_widget_group &&
3452 !(widget == GTK_NOTEBOOK (source_widget)->cur_page->child ||
3453 gtk_widget_is_ancestor (widget, GTK_NOTEBOOK (source_widget)->cur_page->child)))
3455 gdk_drag_status (context, GDK_ACTION_MOVE, time);
3460 /* it's a tab, but doesn't share
3461 * ID with this notebook */
3462 gdk_drag_status (context, 0, time);
3466 priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
3467 x += widget->allocation.x;
3468 y += widget->allocation.y;
3470 if (gtk_notebook_get_event_window_position (notebook, &position) &&
3471 x >= position.x && x <= position.x + position.width &&
3472 y >= position.y && y <= position.y + position.height)
3477 if (!priv->switch_tab_timer)
3479 settings = gtk_widget_get_settings (widget);
3481 g_object_get (settings, "gtk-timeout-expand", &timeout, NULL);
3482 priv->switch_tab_timer = gdk_threads_add_timeout (timeout,
3483 gtk_notebook_switch_tab_timeout,
3489 if (priv->switch_tab_timer)
3491 g_source_remove (priv->switch_tab_timer);
3492 priv->switch_tab_timer = 0;
3496 return (target == tab_target) ? TRUE : FALSE;
3500 gtk_notebook_drag_leave (GtkWidget *widget,
3501 GdkDragContext *context,
3504 GtkNotebookPrivate *priv;
3506 priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
3508 if (priv->switch_tab_timer)
3510 g_source_remove (priv->switch_tab_timer);
3511 priv->switch_tab_timer = 0;
3514 stop_scrolling (GTK_NOTEBOOK (widget));
3518 gtk_notebook_drag_drop (GtkWidget *widget,
3519 GdkDragContext *context,
3524 GdkAtom target, tab_target;
3526 target = gtk_drag_dest_find_target (widget, context, NULL);
3527 tab_target = gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB");
3529 if (target == tab_target)
3531 gtk_drag_get_data (widget, context, target, time);
3539 do_detach_tab (GtkNotebook *from,
3545 GtkNotebookPrivate *priv;
3546 GtkWidget *tab_label, *menu_label;
3547 gboolean tab_expand, tab_fill, reorderable, detachable;
3552 menu_label = gtk_notebook_get_menu_label (from, child);
3555 g_object_ref (menu_label);
3557 tab_label = gtk_notebook_get_tab_label (from, child);
3560 g_object_ref (tab_label);
3562 g_object_ref (child);
3564 gtk_container_child_get (GTK_CONTAINER (from),
3566 "tab-expand", &tab_expand,
3567 "tab-fill", &tab_fill,
3568 "tab-pack", &tab_pack,
3569 "reorderable", &reorderable,
3570 "detachable", &detachable,
3573 gtk_container_remove (GTK_CONTAINER (from), child);
3575 priv = GTK_NOTEBOOK_GET_PRIVATE (to);
3576 priv->mouse_x = x + GTK_WIDGET (to)->allocation.x;
3577 priv->mouse_y = y + GTK_WIDGET (to)->allocation.y;
3579 element = get_drop_position (to, tab_pack);
3580 page_num = g_list_position (to->children, element);
3581 gtk_notebook_insert_page_menu (to, child, tab_label, menu_label, page_num);
3583 gtk_container_child_set (GTK_CONTAINER (to), child,
3584 "tab-pack", tab_pack,
3585 "tab-expand", tab_expand,
3586 "tab-fill", tab_fill,
3587 "reorderable", reorderable,
3588 "detachable", detachable,
3591 g_object_unref (child);
3594 g_object_unref (tab_label);
3597 g_object_unref (menu_label);
3599 gtk_notebook_set_current_page (to, page_num);
3603 gtk_notebook_drag_data_get (GtkWidget *widget,
3604 GdkDragContext *context,
3605 GtkSelectionData *data,
3609 GtkNotebookPrivate *priv;
3611 if (data->target == gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB"))
3613 priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
3615 gtk_selection_data_set (data,
3618 (void*) &priv->detached_tab->child,
3624 gtk_notebook_drag_data_received (GtkWidget *widget,
3625 GdkDragContext *context,
3628 GtkSelectionData *data,
3632 GtkNotebook *notebook;
3633 GtkWidget *source_widget;
3636 notebook = GTK_NOTEBOOK (widget);
3637 source_widget = gtk_drag_get_source_widget (context);
3639 if (source_widget &&
3640 data->target == gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB"))
3642 child = (void*) data->data;
3644 do_detach_tab (GTK_NOTEBOOK (source_widget), notebook, *child, x, y);
3645 gtk_drag_finish (context, TRUE, FALSE, time);
3648 gtk_drag_finish (context, FALSE, FALSE, time);
3651 /* Private GtkContainer Methods :
3653 * gtk_notebook_set_child_arg
3654 * gtk_notebook_get_child_arg
3656 * gtk_notebook_remove
3657 * gtk_notebook_focus
3658 * gtk_notebook_set_focus_child
3659 * gtk_notebook_child_type
3660 * gtk_notebook_forall
3663 gtk_notebook_set_child_property (GtkContainer *container,
3666 const GValue *value,
3671 GtkPackType pack_type;
3673 /* not finding child's page is valid for menus or labels */
3674 if (!gtk_notebook_find_child (GTK_NOTEBOOK (container), child, NULL))
3677 switch (property_id)
3679 case CHILD_PROP_TAB_LABEL:
3680 /* a NULL pointer indicates a default_tab setting, otherwise
3681 * we need to set the associated label
3683 gtk_notebook_set_tab_label_text (GTK_NOTEBOOK (container), child,
3684 g_value_get_string (value));
3686 case CHILD_PROP_MENU_LABEL:
3687 gtk_notebook_set_menu_label_text (GTK_NOTEBOOK (container), child,
3688 g_value_get_string (value));
3690 case CHILD_PROP_POSITION:
3691 gtk_notebook_reorder_child (GTK_NOTEBOOK (container), child,
3692 g_value_get_int (value));
3694 case CHILD_PROP_TAB_EXPAND:
3695 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3696 &expand, &fill, &pack_type);
3697 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (container), child,
3698 g_value_get_boolean (value),
3701 case CHILD_PROP_TAB_FILL:
3702 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3703 &expand, &fill, &pack_type);
3704 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (container), child,
3706 g_value_get_boolean (value),
3709 case CHILD_PROP_TAB_PACK:
3710 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3711 &expand, &fill, &pack_type);
3712 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (container), child,
3714 g_value_get_enum (value));
3716 case CHILD_PROP_REORDERABLE:
3717 gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (container), child,
3718 g_value_get_boolean (value));
3720 case CHILD_PROP_DETACHABLE:
3721 gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (container), child,
3722 g_value_get_boolean (value));
3725 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
3731 gtk_notebook_get_child_property (GtkContainer *container,
3738 GtkNotebook *notebook;
3742 GtkPackType pack_type;
3744 notebook = GTK_NOTEBOOK (container);
3746 /* not finding child's page is valid for menus or labels */
3747 list = gtk_notebook_find_child (notebook, child, NULL);
3750 /* nothing to set on labels or menus */
3751 g_param_value_set_default (pspec, value);
3755 switch (property_id)
3757 case CHILD_PROP_TAB_LABEL:
3758 label = gtk_notebook_get_tab_label (notebook, child);
3760 if (GTK_IS_LABEL (label))
3761 g_value_set_string (value, gtk_label_get_label (GTK_LABEL (label)));
3763 g_value_set_string (value, NULL);
3765 case CHILD_PROP_MENU_LABEL:
3766 label = gtk_notebook_get_menu_label (notebook, child);
3768 if (GTK_IS_LABEL (label))
3769 g_value_set_string (value, gtk_label_get_label (GTK_LABEL (label)));
3771 g_value_set_string (value, NULL);
3773 case CHILD_PROP_POSITION:
3774 g_value_set_int (value, g_list_position (notebook->children, list));
3776 case CHILD_PROP_TAB_EXPAND:
3777 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3778 &expand, NULL, NULL);
3779 g_value_set_boolean (value, expand);
3781 case CHILD_PROP_TAB_FILL:
3782 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3784 g_value_set_boolean (value, fill);
3786 case CHILD_PROP_TAB_PACK:
3787 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3788 NULL, NULL, &pack_type);
3789 g_value_set_enum (value, pack_type);
3791 case CHILD_PROP_REORDERABLE:
3792 g_value_set_boolean (value,
3793 gtk_notebook_get_tab_reorderable (GTK_NOTEBOOK (container), child));
3795 case CHILD_PROP_DETACHABLE:
3796 g_value_set_boolean (value,
3797 gtk_notebook_get_tab_detachable (GTK_NOTEBOOK (container), child));
3800 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
3806 gtk_notebook_add (GtkContainer *container,
3809 gtk_notebook_insert_page_menu (GTK_NOTEBOOK (container), widget,
3814 gtk_notebook_remove (GtkContainer *container,
3817 GtkNotebook *notebook;
3818 GtkNotebookPage *page;
3822 notebook = GTK_NOTEBOOK (container);
3824 children = notebook->children;
3827 page = children->data;
3829 if (page->child == widget)
3833 children = children->next;
3836 if (children == NULL)
3839 g_object_ref (widget);
3841 gtk_notebook_real_remove (notebook, children);
3843 g_signal_emit (notebook,
3844 notebook_signals[PAGE_REMOVED],
3849 g_object_unref (widget);
3853 focus_tabs_in (GtkNotebook *notebook)
3855 if (notebook->show_tabs && notebook->cur_page)
3857 gtk_widget_grab_focus (GTK_WIDGET (notebook));
3859 gtk_notebook_switch_focus_tab (notebook,
3860 g_list_find (notebook->children,
3861 notebook->cur_page));
3870 focus_tabs_move (GtkNotebook *notebook,
3871 GtkDirectionType direction,
3872 gint search_direction)
3876 new_page = gtk_notebook_search_page (notebook, notebook->focus_tab,
3877 search_direction, TRUE);
3880 gboolean wrap_around;
3882 g_object_get (gtk_widget_get_settings (GTK_WIDGET (notebook)),
3883 "gtk-keynav-wrap-around", &wrap_around,
3887 new_page = gtk_notebook_search_page (notebook, NULL,
3888 search_direction, TRUE);
3892 gtk_notebook_switch_focus_tab (notebook, new_page);
3894 gtk_widget_error_bell (GTK_WIDGET (notebook));
3900 focus_child_in (GtkNotebook *notebook,
3901 GtkDirectionType direction)
3903 if (notebook->cur_page)
3904 return gtk_widget_child_focus (notebook->cur_page->child, direction);
3910 focus_action_in (GtkNotebook *notebook,
3912 GtkDirectionType direction)
3914 GtkNotebookPrivate *priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
3916 if (priv->action_widget[action] &&
3917 gtk_widget_get_visible (priv->action_widget[action]))
3918 return gtk_widget_child_focus (priv->action_widget[action], direction);
3923 /* Focus in the notebook can either be on the pages, or on
3924 * the tabs or on the action_widgets.
3927 gtk_notebook_focus (GtkWidget *widget,
3928 GtkDirectionType direction)
3930 GtkNotebookPrivate *priv;
3931 GtkWidget *old_focus_child;
3932 GtkNotebook *notebook;
3933 GtkDirectionType effective_direction;
3937 gboolean widget_is_focus;
3938 GtkContainer *container;
3940 container = GTK_CONTAINER (widget);
3941 notebook = GTK_NOTEBOOK (container);
3942 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
3944 if (notebook->tab_pos == GTK_POS_TOP ||
3945 notebook->tab_pos == GTK_POS_LEFT)
3947 first_action = ACTION_WIDGET_START;
3948 last_action = ACTION_WIDGET_END;
3952 first_action = ACTION_WIDGET_END;
3953 last_action = ACTION_WIDGET_START;
3956 if (notebook->focus_out)
3958 notebook->focus_out = FALSE; /* Clear this to catch the wrap-around case */
3962 widget_is_focus = gtk_widget_is_focus (widget);
3963 old_focus_child = container->focus_child;
3965 effective_direction = get_effective_direction (notebook, direction);
3967 if (old_focus_child) /* Focus on page child or action widget */
3969 if (gtk_widget_child_focus (old_focus_child, direction))
3972 if (old_focus_child == priv->action_widget[ACTION_WIDGET_START])
3974 switch (effective_direction)
3977 return focus_child_in (notebook, GTK_DIR_TAB_FORWARD);
3979 return focus_tabs_in (notebook);
3987 case GTK_DIR_TAB_FORWARD:
3988 if ((notebook->tab_pos == GTK_POS_RIGHT || notebook->tab_pos == GTK_POS_BOTTOM) &&
3989 focus_child_in (notebook, direction))
3991 return focus_tabs_in (notebook);
3992 case GTK_DIR_TAB_BACKWARD:
3995 g_assert_not_reached ();
3999 else if (old_focus_child == priv->action_widget[ACTION_WIDGET_END])
4001 switch (effective_direction)
4004 return focus_child_in (notebook, GTK_DIR_TAB_FORWARD);
4008 return focus_tabs_in (notebook);
4014 case GTK_DIR_TAB_FORWARD:
4016 case GTK_DIR_TAB_BACKWARD:
4017 if ((notebook->tab_pos == GTK_POS_TOP || notebook->tab_pos == GTK_POS_LEFT) &&
4018 focus_child_in (notebook, direction))
4020 return focus_tabs_in (notebook);
4022 g_assert_not_reached ();
4028 switch (effective_direction)
4030 case GTK_DIR_TAB_BACKWARD:
4032 /* Focus onto the tabs */
4033 return focus_tabs_in (notebook);
4038 case GTK_DIR_TAB_FORWARD:
4039 return focus_action_in (notebook, last_action, direction);
4043 else if (widget_is_focus) /* Focus was on tabs */
4045 switch (effective_direction)
4047 case GTK_DIR_TAB_BACKWARD:
4048 return focus_action_in (notebook, first_action, direction);
4051 case GTK_DIR_TAB_FORWARD:
4052 if (focus_child_in (notebook, GTK_DIR_TAB_FORWARD))
4054 return focus_action_in (notebook, last_action, direction);
4056 /* We use TAB_FORWARD rather than direction so that we focus a more
4057 * predictable widget for the user; users may be using arrow focusing
4058 * in this situation even if they don't usually use arrow focusing.
4060 return focus_child_in (notebook, GTK_DIR_TAB_FORWARD);
4062 return focus_tabs_move (notebook, direction, STEP_PREV);
4064 return focus_tabs_move (notebook, direction, STEP_NEXT);
4067 else /* Focus was not on widget */
4069 switch (effective_direction)
4071 case GTK_DIR_TAB_FORWARD:
4073 if (focus_action_in (notebook, first_action, direction))
4075 if (focus_tabs_in (notebook))
4077 if (focus_action_in (notebook, last_action, direction))
4079 if (focus_child_in (notebook, direction))
4082 case GTK_DIR_TAB_BACKWARD:
4083 if (focus_action_in (notebook, last_action, direction))
4085 if (focus_child_in (notebook, direction))
4087 if (focus_tabs_in (notebook))
4089 if (focus_action_in (notebook, first_action, direction))
4094 return focus_child_in (notebook, direction);
4098 g_assert_not_reached ();
4103 gtk_notebook_set_focus_child (GtkContainer *container,
4106 GtkNotebook *notebook = GTK_NOTEBOOK (container);
4107 GtkWidget *page_child;
4108 GtkWidget *toplevel;
4110 /* If the old focus widget was within a page of the notebook,
4111 * (child may either be NULL or not in this case), record it
4112 * for future use if we switch to the page with a mnemonic.
4115 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (container));
4116 if (toplevel && gtk_widget_is_toplevel (toplevel))
4118 page_child = GTK_WINDOW (toplevel)->focus_widget;
4121 if (page_child->parent == GTK_WIDGET (container))
4123 GList *list = gtk_notebook_find_child (notebook, page_child, NULL);
4126 GtkNotebookPage *page = list->data;
4128 if (page->last_focus_child)
4129 g_object_remove_weak_pointer (G_OBJECT (page->last_focus_child), (gpointer *)&page->last_focus_child);
4131 page->last_focus_child = GTK_WINDOW (toplevel)->focus_widget;
4132 g_object_add_weak_pointer (G_OBJECT (page->last_focus_child), (gpointer *)&page->last_focus_child);
4138 page_child = page_child->parent;
4144 g_return_if_fail (GTK_IS_WIDGET (child));
4146 notebook->child_has_focus = TRUE;
4147 if (!notebook->focus_tab)
4150 GtkNotebookPage *page;
4152 children = notebook->children;
4155 page = children->data;
4156 if (page->child == child || page->tab_label == child)
4157 gtk_notebook_switch_focus_tab (notebook, children);
4158 children = children->next;
4163 notebook->child_has_focus = FALSE;
4165 GTK_CONTAINER_CLASS (gtk_notebook_parent_class)->set_focus_child (container, child);
4169 gtk_notebook_forall (GtkContainer *container,
4170 gboolean include_internals,
4171 GtkCallback callback,
4172 gpointer callback_data)
4174 GtkNotebookPrivate *priv;
4175 GtkNotebook *notebook;
4179 notebook = GTK_NOTEBOOK (container);
4180 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
4182 children = notebook->children;
4185 GtkNotebookPage *page;
4187 page = children->data;
4188 children = children->next;
4189 (* callback) (page->child, callback_data);
4191 if (include_internals)
4193 if (page->tab_label)
4194 (* callback) (page->tab_label, callback_data);
4198 if (include_internals) {
4199 for (i = 0; i < N_ACTION_WIDGETS; i++)
4201 if (priv->action_widget[i])
4202 (* callback) (priv->action_widget[i], callback_data);
4208 gtk_notebook_child_type (GtkContainer *container)
4210 return GTK_TYPE_WIDGET;
4213 /* Private GtkNotebook Methods:
4215 * gtk_notebook_real_insert_page
4218 page_visible_cb (GtkWidget *page,
4222 GtkNotebook *notebook = (GtkNotebook *) data;
4226 if (notebook->cur_page &&
4227 notebook->cur_page->child == page &&
4228 !gtk_widget_get_visible (page))
4230 list = g_list_find (notebook->children, notebook->cur_page);
4233 next = gtk_notebook_search_page (notebook, list, STEP_NEXT, TRUE);
4235 next = gtk_notebook_search_page (notebook, list, STEP_PREV, TRUE);
4239 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (next));
4244 gtk_notebook_real_insert_page (GtkNotebook *notebook,
4246 GtkWidget *tab_label,
4247 GtkWidget *menu_label,
4250 GtkNotebookPage *page;
4253 gtk_widget_freeze_child_notify (child);
4255 page = g_slice_new0 (GtkNotebookPage);
4256 page->child = child;
4258 nchildren = g_list_length (notebook->children);
4259 if ((position < 0) || (position > nchildren))
4260 position = nchildren;
4262 notebook->children = g_list_insert (notebook->children, page, position);
4266 page->default_tab = TRUE;
4267 if (notebook->show_tabs)
4268 tab_label = gtk_label_new (NULL);
4270 page->tab_label = tab_label;
4271 page->menu_label = menu_label;
4272 page->expand = FALSE;
4274 page->pack = GTK_PACK_START;
4277 page->default_menu = TRUE;
4279 g_object_ref_sink (page->menu_label);
4282 gtk_notebook_menu_item_create (notebook,
4283 g_list_find (notebook->children, page));
4285 gtk_widget_set_parent (child, GTK_WIDGET (notebook));
4287 gtk_widget_set_parent (tab_label, GTK_WIDGET (notebook));
4289 gtk_notebook_update_labels (notebook);
4291 if (!notebook->first_tab)
4292 notebook->first_tab = notebook->children;
4294 /* child visible will be turned on by switch_page below */
4295 if (notebook->cur_page != page)
4296 gtk_widget_set_child_visible (child, FALSE);
4300 if (notebook->show_tabs && gtk_widget_get_visible (child))
4301 gtk_widget_show (tab_label);
4303 gtk_widget_hide (tab_label);
4305 page->mnemonic_activate_signal =
4306 g_signal_connect (tab_label,
4307 "mnemonic-activate",
4308 G_CALLBACK (gtk_notebook_mnemonic_activate_switch_page),
4312 page->notify_visible_handler = g_signal_connect (child, "notify::visible",
4313 G_CALLBACK (page_visible_cb), notebook);
4315 g_signal_emit (notebook,
4316 notebook_signals[PAGE_ADDED],
4321 if (!notebook->cur_page)
4323 gtk_notebook_switch_page (notebook, page);
4324 /* focus_tab is set in the switch_page method */
4325 gtk_notebook_switch_focus_tab (notebook, notebook->focus_tab);
4328 gtk_notebook_update_tab_states (notebook);
4330 if (notebook->scrollable)
4331 gtk_notebook_redraw_arrows (notebook);
4333 gtk_widget_child_notify (child, "tab-expand");
4334 gtk_widget_child_notify (child, "tab-fill");
4335 gtk_widget_child_notify (child, "tab-pack");
4336 gtk_widget_child_notify (child, "tab-label");
4337 gtk_widget_child_notify (child, "menu-label");
4338 gtk_widget_child_notify (child, "position");
4339 gtk_widget_thaw_child_notify (child);
4341 /* The page-added handler might have reordered the pages, re-get the position */
4342 return gtk_notebook_page_num (notebook, child);
4345 /* Private GtkNotebook Functions:
4347 * gtk_notebook_redraw_tabs
4348 * gtk_notebook_real_remove
4349 * gtk_notebook_update_labels
4350 * gtk_notebook_timer
4351 * gtk_notebook_set_scroll_timer
4352 * gtk_notebook_page_compare
4353 * gtk_notebook_real_page_position
4354 * gtk_notebook_search_page
4357 gtk_notebook_redraw_tabs (GtkNotebook *notebook)
4360 GtkNotebookPage *page;
4361 GdkRectangle redraw_rect;
4363 gint tab_pos = get_effective_tab_pos (notebook);
4365 widget = GTK_WIDGET (notebook);
4366 border = GTK_CONTAINER (notebook)->border_width;
4368 if (!gtk_widget_get_mapped (widget) || !notebook->first_tab)
4371 page = notebook->first_tab->data;
4373 redraw_rect.x = border;
4374 redraw_rect.y = border;
4378 case GTK_POS_BOTTOM:
4379 redraw_rect.y = widget->allocation.height - border -
4380 page->allocation.height - widget->style->ythickness;
4382 if (page != notebook->cur_page)
4383 redraw_rect.y -= widget->style->ythickness;
4386 redraw_rect.width = widget->allocation.width - 2 * border;
4387 redraw_rect.height = page->allocation.height + widget->style->ythickness;
4389 if (page != notebook->cur_page)
4390 redraw_rect.height += widget->style->ythickness;
4393 redraw_rect.x = widget->allocation.width - border -
4394 page->allocation.width - widget->style->xthickness;
4396 if (page != notebook->cur_page)
4397 redraw_rect.x -= widget->style->xthickness;
4400 redraw_rect.width = page->allocation.width + widget->style->xthickness;
4401 redraw_rect.height = widget->allocation.height - 2 * border;
4403 if (page != notebook->cur_page)
4404 redraw_rect.width += widget->style->xthickness;
4408 redraw_rect.x += widget->allocation.x;
4409 redraw_rect.y += widget->allocation.y;
4411 gdk_window_invalidate_rect (widget->window, &redraw_rect, TRUE);
4415 gtk_notebook_redraw_arrows (GtkNotebook *notebook)
4417 if (gtk_widget_get_mapped (GTK_WIDGET (notebook)) &&
4418 gtk_notebook_show_arrows (notebook))
4422 GtkNotebookArrow arrow[4];
4424 arrow[0] = notebook->has_before_previous ? ARROW_LEFT_BEFORE : ARROW_NONE;
4425 arrow[1] = notebook->has_before_next ? ARROW_RIGHT_BEFORE : ARROW_NONE;
4426 arrow[2] = notebook->has_after_previous ? ARROW_LEFT_AFTER : ARROW_NONE;
4427 arrow[3] = notebook->has_after_next ? ARROW_RIGHT_AFTER : ARROW_NONE;
4429 for (i = 0; i < 4; i++)
4431 if (arrow[i] == ARROW_NONE)
4434 gtk_notebook_get_arrow_rect (notebook, &rect, arrow[i]);
4435 gdk_window_invalidate_rect (GTK_WIDGET (notebook)->window,
4442 gtk_notebook_timer (GtkNotebook *notebook)
4444 gboolean retval = FALSE;
4446 if (notebook->timer)
4448 gtk_notebook_do_arrow (notebook, notebook->click_child);
4450 if (notebook->need_timer)
4452 GtkSettings *settings;
4455 settings = gtk_widget_get_settings (GTK_WIDGET (notebook));
4456 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
4458 notebook->need_timer = FALSE;
4459 notebook->timer = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
4460 (GSourceFunc) gtk_notebook_timer,
4461 (gpointer) notebook);
4471 gtk_notebook_set_scroll_timer (GtkNotebook *notebook)
4473 GtkWidget *widget = GTK_WIDGET (notebook);
4475 if (!notebook->timer)
4477 GtkSettings *settings = gtk_widget_get_settings (widget);
4480 g_object_get (settings, "gtk-timeout-initial", &timeout, NULL);
4482 notebook->timer = gdk_threads_add_timeout (timeout,
4483 (GSourceFunc) gtk_notebook_timer,
4484 (gpointer) notebook);
4485 notebook->need_timer = TRUE;
4490 gtk_notebook_page_compare (gconstpointer a,
4493 return (((GtkNotebookPage *) a)->child != b);
4497 gtk_notebook_find_child (GtkNotebook *notebook,
4499 const gchar *function)
4501 GList *list = g_list_find_custom (notebook->children, child,
4502 gtk_notebook_page_compare);
4504 #ifndef G_DISABLE_CHECKS
4505 if (!list && function)
4506 g_warning ("%s: unable to find child %p in notebook %p",
4507 function, child, notebook);
4514 gtk_notebook_remove_tab_label (GtkNotebook *notebook,
4515 GtkNotebookPage *page)
4517 if (page->tab_label)
4519 if (page->mnemonic_activate_signal)
4520 g_signal_handler_disconnect (page->tab_label,
4521 page->mnemonic_activate_signal);
4522 page->mnemonic_activate_signal = 0;
4524 gtk_widget_set_state (page->tab_label, GTK_STATE_NORMAL);
4525 gtk_widget_unparent (page->tab_label);
4526 page->tab_label = NULL;
4531 gtk_notebook_real_remove (GtkNotebook *notebook,
4534 GtkNotebookPrivate *priv;
4535 GtkNotebookPage *page;
4537 gint need_resize = FALSE;
4538 GtkWidget *tab_label;
4540 gboolean destroying;
4542 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
4543 destroying = GTK_OBJECT_FLAGS (notebook) & GTK_IN_DESTRUCTION;
4545 next_list = gtk_notebook_search_page (notebook, list, STEP_NEXT, TRUE);
4547 next_list = gtk_notebook_search_page (notebook, list, STEP_PREV, TRUE);
4549 notebook->children = g_list_remove_link (notebook->children, list);
4551 if (notebook->cur_page == list->data)
4553 notebook->cur_page = NULL;
4554 if (next_list && !destroying)
4555 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (next_list));
4558 if (priv->detached_tab == list->data)
4559 priv->detached_tab = NULL;
4561 if (list == notebook->first_tab)
4562 notebook->first_tab = next_list;
4563 if (list == notebook->focus_tab && !destroying)
4564 gtk_notebook_switch_focus_tab (notebook, next_list);
4568 g_signal_handler_disconnect (page->child, page->notify_visible_handler);
4570 if (gtk_widget_get_visible (page->child) &&
4571 gtk_widget_get_visible (GTK_WIDGET (notebook)))
4574 gtk_widget_unparent (page->child);
4576 tab_label = page->tab_label;
4579 g_object_ref (tab_label);
4580 gtk_notebook_remove_tab_label (notebook, page);
4582 gtk_widget_destroy (tab_label);
4583 g_object_unref (tab_label);
4588 GtkWidget *parent = page->menu_label->parent;
4590 gtk_notebook_menu_label_unparent (parent, NULL);
4591 gtk_container_remove (GTK_CONTAINER (notebook->menu), parent);
4593 gtk_widget_queue_resize (notebook->menu);
4595 if (!page->default_menu)
4596 g_object_unref (page->menu_label);
4600 if (page->last_focus_child)
4602 g_object_remove_weak_pointer (G_OBJECT (page->last_focus_child), (gpointer *)&page->last_focus_child);
4603 page->last_focus_child = NULL;
4606 g_slice_free (GtkNotebookPage, page);
4608 gtk_notebook_update_labels (notebook);
4610 gtk_widget_queue_resize (GTK_WIDGET (notebook));
4614 gtk_notebook_update_labels (GtkNotebook *notebook)
4616 GtkNotebookPage *page;
4621 if (!notebook->show_tabs && !notebook->menu)
4624 for (list = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, FALSE);
4626 list = gtk_notebook_search_page (notebook, list, STEP_NEXT, FALSE))
4629 g_snprintf (string, sizeof(string), _("Page %u"), page_num++);
4630 if (notebook->show_tabs)
4632 if (page->default_tab)
4634 if (!page->tab_label)
4636 page->tab_label = gtk_label_new (string);
4637 gtk_widget_set_parent (page->tab_label,
4638 GTK_WIDGET (notebook));
4641 gtk_label_set_text (GTK_LABEL (page->tab_label), string);
4644 if (gtk_widget_get_visible (page->child) &&
4645 !gtk_widget_get_visible (page->tab_label))
4646 gtk_widget_show (page->tab_label);
4647 else if (!gtk_widget_get_visible (page->child) &&
4648 gtk_widget_get_visible (page->tab_label))
4649 gtk_widget_hide (page->tab_label);
4651 if (notebook->menu && page->default_menu)
4653 if (GTK_IS_LABEL (page->tab_label))
4654 gtk_label_set_text (GTK_LABEL (page->menu_label),
4655 gtk_label_get_label (GTK_LABEL (page->tab_label)));
4657 gtk_label_set_text (GTK_LABEL (page->menu_label), string);
4663 gtk_notebook_real_page_position (GtkNotebook *notebook,
4669 for (work = notebook->children, count_start = 0;
4670 work && work != list; work = work->next)
4671 if (GTK_NOTEBOOK_PAGE (work)->pack == GTK_PACK_START)
4677 if (GTK_NOTEBOOK_PAGE (list)->pack == GTK_PACK_START)
4680 return (count_start + g_list_length (list) - 1);
4684 gtk_notebook_search_page (GtkNotebook *notebook,
4687 gboolean find_visible)
4689 GtkNotebookPage *page = NULL;
4690 GList *old_list = NULL;
4696 flag = GTK_PACK_END;
4700 flag = GTK_PACK_START;
4707 if (!page || page->pack == flag)
4715 list = notebook->children;
4720 if (page->pack == flag &&
4722 (gtk_widget_get_visible (page->child) &&
4723 (!page->tab_label || NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page)))))
4738 if (page->pack != flag &&
4740 (gtk_widget_get_visible (page->child) &&
4741 (!page->tab_label || NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page)))))
4749 /* Private GtkNotebook Drawing Functions:
4751 * gtk_notebook_paint
4752 * gtk_notebook_draw_tab
4753 * gtk_notebook_draw_arrow
4756 gtk_notebook_paint (GtkWidget *widget,
4759 GtkNotebook *notebook;
4760 GtkNotebookPrivate *priv;
4761 GtkNotebookPage *page;
4766 gint border_width = GTK_CONTAINER (widget)->border_width;
4767 gint gap_x = 0, gap_width = 0, step = STEP_PREV;
4771 if (!gtk_widget_is_drawable (widget))
4774 notebook = GTK_NOTEBOOK (widget);
4775 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
4776 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
4777 tab_pos = get_effective_tab_pos (notebook);
4779 if ((!notebook->show_tabs && !notebook->show_border) ||
4780 !notebook->cur_page || !gtk_widget_get_visible (notebook->cur_page->child))
4783 x = widget->allocation.x + border_width;
4784 y = widget->allocation.y + border_width;
4785 width = widget->allocation.width - border_width * 2;
4786 height = widget->allocation.height - border_width * 2;
4788 if (notebook->show_border && (!notebook->show_tabs || !notebook->children))
4790 gtk_paint_box (widget->style, widget->window,
4791 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
4792 area, widget, "notebook",
4793 x, y, width, height);
4797 if (!notebook->first_tab)
4798 notebook->first_tab = notebook->children;
4800 if (!gtk_widget_get_mapped (notebook->cur_page->tab_label))
4801 page = GTK_NOTEBOOK_PAGE (notebook->first_tab);
4803 page = notebook->cur_page;
4808 y += page->allocation.height;
4810 case GTK_POS_BOTTOM:
4811 height -= page->allocation.height;
4814 x += page->allocation.width;
4817 width -= page->allocation.width;
4821 if (!NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, notebook->cur_page) ||
4822 !gtk_widget_get_mapped (notebook->cur_page->tab_label))
4832 case GTK_POS_BOTTOM:
4833 if (priv->operation == DRAG_OPERATION_REORDER)
4834 gap_x = priv->drag_window_x - widget->allocation.x - border_width;
4836 gap_x = notebook->cur_page->allocation.x - widget->allocation.x - border_width;
4838 gap_width = notebook->cur_page->allocation.width;
4839 step = is_rtl ? STEP_NEXT : STEP_PREV;
4843 if (priv->operation == DRAG_OPERATION_REORDER)
4844 gap_x = priv->drag_window_y - border_width - widget->allocation.y;
4846 gap_x = notebook->cur_page->allocation.y - widget->allocation.y - border_width;
4848 gap_width = notebook->cur_page->allocation.height;
4853 gtk_paint_box_gap (widget->style, widget->window,
4854 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
4855 area, widget, "notebook",
4856 x, y, width, height,
4857 tab_pos, gap_x, gap_width);
4860 children = gtk_notebook_search_page (notebook, NULL, step, TRUE);
4863 page = children->data;
4864 children = gtk_notebook_search_page (notebook, children,
4866 if (!gtk_widget_get_visible (page->child))
4868 if (!gtk_widget_get_mapped (page->tab_label))
4870 else if (page != notebook->cur_page)
4871 gtk_notebook_draw_tab (notebook, page, area);
4874 if (showarrow && notebook->scrollable)
4876 if (notebook->has_before_previous)
4877 gtk_notebook_draw_arrow (notebook, ARROW_LEFT_BEFORE);
4878 if (notebook->has_before_next)
4879 gtk_notebook_draw_arrow (notebook, ARROW_RIGHT_BEFORE);
4880 if (notebook->has_after_previous)
4881 gtk_notebook_draw_arrow (notebook, ARROW_LEFT_AFTER);
4882 if (notebook->has_after_next)
4883 gtk_notebook_draw_arrow (notebook, ARROW_RIGHT_AFTER);
4885 gtk_notebook_draw_tab (notebook, notebook->cur_page, area);
4889 gtk_notebook_draw_tab (GtkNotebook *notebook,
4890 GtkNotebookPage *page,
4893 GtkNotebookPrivate *priv;
4894 GdkRectangle child_area;
4895 GdkRectangle page_area;
4896 GtkStateType state_type;
4897 GtkPositionType gap_side;
4901 if (!NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) ||
4902 !gtk_widget_get_mapped (page->tab_label) ||
4903 (page->allocation.width == 0) || (page->allocation.height == 0))
4906 widget = GTK_WIDGET (notebook);
4907 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
4909 if (priv->operation == DRAG_OPERATION_REORDER && page == notebook->cur_page)
4910 window = priv->drag_window;
4912 window = widget->window;
4914 page_area.x = page->allocation.x;
4915 page_area.y = page->allocation.y;
4916 page_area.width = page->allocation.width;
4917 page_area.height = page->allocation.height;
4919 if (gdk_rectangle_intersect (&page_area, area, &child_area))
4921 gap_side = get_tab_gap_pos (notebook);
4923 if (notebook->cur_page == page)
4924 state_type = GTK_STATE_NORMAL;
4926 state_type = GTK_STATE_ACTIVE;
4928 gtk_paint_extension (widget->style, window,
4929 state_type, GTK_SHADOW_OUT,
4930 area, widget, "tab",
4931 page_area.x, page_area.y,
4932 page_area.width, page_area.height,
4938 gtk_notebook_draw_arrow (GtkNotebook *notebook,
4939 GtkNotebookArrow nbarrow)
4941 GtkStateType state_type;
4942 GtkShadowType shadow_type;
4944 GdkRectangle arrow_rect;
4946 gboolean is_rtl, left;
4948 widget = GTK_WIDGET (notebook);
4950 if (gtk_widget_is_drawable (widget))
4952 gint scroll_arrow_hlength;
4953 gint scroll_arrow_vlength;
4956 gtk_notebook_get_arrow_rect (notebook, &arrow_rect, nbarrow);
4958 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
4959 left = (ARROW_IS_LEFT (nbarrow) && !is_rtl) ||
4960 (!ARROW_IS_LEFT (nbarrow) && is_rtl);
4962 gtk_widget_style_get (widget,
4963 "scroll-arrow-hlength", &scroll_arrow_hlength,
4964 "scroll-arrow-vlength", &scroll_arrow_vlength,
4967 if (notebook->in_child == nbarrow)
4969 if (notebook->click_child == nbarrow)
4970 state_type = GTK_STATE_ACTIVE;
4972 state_type = GTK_STATE_PRELIGHT;
4975 state_type = gtk_widget_get_state (widget);
4977 if (notebook->click_child == nbarrow)
4978 shadow_type = GTK_SHADOW_IN;
4980 shadow_type = GTK_SHADOW_OUT;
4982 if (notebook->focus_tab &&
4983 !gtk_notebook_search_page (notebook, notebook->focus_tab,
4984 left ? STEP_PREV : STEP_NEXT, TRUE))
4986 shadow_type = GTK_SHADOW_ETCHED_IN;
4987 state_type = GTK_STATE_INSENSITIVE;
4990 if (notebook->tab_pos == GTK_POS_LEFT ||
4991 notebook->tab_pos == GTK_POS_RIGHT)
4993 arrow = (ARROW_IS_LEFT (nbarrow) ? GTK_ARROW_UP : GTK_ARROW_DOWN);
4994 arrow_size = scroll_arrow_vlength;
4998 arrow = (ARROW_IS_LEFT (nbarrow) ? GTK_ARROW_LEFT : GTK_ARROW_RIGHT);
4999 arrow_size = scroll_arrow_hlength;
5002 gtk_paint_arrow (widget->style, widget->window, state_type,
5003 shadow_type, NULL, widget, "notebook",
5004 arrow, TRUE, arrow_rect.x, arrow_rect.y,
5005 arrow_size, arrow_size);
5009 /* Private GtkNotebook Size Allocate Functions:
5011 * gtk_notebook_tab_space
5012 * gtk_notebook_calculate_shown_tabs
5013 * gtk_notebook_calculate_tabs_allocation
5014 * gtk_notebook_pages_allocate
5015 * gtk_notebook_page_allocate
5016 * gtk_notebook_calc_tabs
5019 gtk_notebook_tab_space (GtkNotebook *notebook,
5020 gboolean *show_arrows,
5025 GtkNotebookPrivate *priv;
5028 gint tab_pos = get_effective_tab_pos (notebook);
5031 gint scroll_arrow_hlength;
5032 gint scroll_arrow_vlength;
5036 widget = GTK_WIDGET (notebook);
5037 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
5038 children = notebook->children;
5039 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
5041 gtk_widget_style_get (GTK_WIDGET (notebook),
5042 "arrow-spacing", &arrow_spacing,
5043 "scroll-arrow-hlength", &scroll_arrow_hlength,
5044 "scroll-arrow-vlength", &scroll_arrow_vlength,
5050 case GTK_POS_BOTTOM:
5051 *min = widget->allocation.x + GTK_CONTAINER (notebook)->border_width;
5052 *max = widget->allocation.x + widget->allocation.width - GTK_CONTAINER (notebook)->border_width;
5054 for (i = 0; i < N_ACTION_WIDGETS; i++)
5056 if (priv->action_widget[i])
5058 if ((i == ACTION_WIDGET_START && !is_rtl) ||
5059 (i == ACTION_WIDGET_END && is_rtl))
5060 *min += priv->action_widget[i]->allocation.width + widget->style->xthickness;
5062 *max -= priv->action_widget[i]->allocation.width + widget->style->xthickness;
5068 GtkNotebookPage *page;
5070 page = children->data;
5071 children = children->next;
5073 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) &&
5074 gtk_widget_get_visible (page->child))
5075 *tab_space += page->requisition.width;
5080 *min = widget->allocation.y + GTK_CONTAINER (notebook)->border_width;
5081 *max = widget->allocation.y + widget->allocation.height - GTK_CONTAINER (notebook)->border_width;
5083 for (i = 0; i < N_ACTION_WIDGETS; i++)
5085 if (priv->action_widget[i])
5087 if (i == ACTION_WIDGET_START)
5088 *min += priv->action_widget[i]->allocation.height + widget->style->ythickness;
5090 *max -= priv->action_widget[i]->allocation.height + widget->style->ythickness;
5096 GtkNotebookPage *page;
5098 page = children->data;
5099 children = children->next;
5101 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) &&
5102 gtk_widget_get_visible (page->child))
5103 *tab_space += page->requisition.height;
5108 if (!notebook->scrollable)
5109 *show_arrows = FALSE;
5112 gtk_widget_style_get (widget, "tab-overlap", &tab_overlap, NULL);
5117 case GTK_POS_BOTTOM:
5118 if (*tab_space > *max - *min - tab_overlap)
5120 *show_arrows = TRUE;
5122 /* take arrows into account */
5123 *tab_space = *max - *min - tab_overlap;
5125 if (notebook->has_after_previous)
5127 *tab_space -= arrow_spacing + scroll_arrow_hlength;
5128 *max -= arrow_spacing + scroll_arrow_hlength;
5131 if (notebook->has_after_next)
5133 *tab_space -= arrow_spacing + scroll_arrow_hlength;
5134 *max -= arrow_spacing + scroll_arrow_hlength;
5137 if (notebook->has_before_previous)
5139 *tab_space -= arrow_spacing + scroll_arrow_hlength;
5140 *min += arrow_spacing + scroll_arrow_hlength;
5143 if (notebook->has_before_next)
5145 *tab_space -= arrow_spacing + scroll_arrow_hlength;
5146 *min += arrow_spacing + scroll_arrow_hlength;
5152 if (*tab_space > *max - *min - tab_overlap)
5154 *show_arrows = TRUE;
5156 /* take arrows into account */
5157 *tab_space = *max - *min - tab_overlap;
5159 if (notebook->has_after_previous || notebook->has_after_next)
5161 *tab_space -= arrow_spacing + scroll_arrow_vlength;
5162 *max -= arrow_spacing + scroll_arrow_vlength;
5165 if (notebook->has_before_previous || notebook->has_before_next)
5167 *tab_space -= arrow_spacing + scroll_arrow_vlength;
5168 *min += arrow_spacing + scroll_arrow_vlength;
5177 gtk_notebook_calculate_shown_tabs (GtkNotebook *notebook,
5178 gboolean show_arrows,
5184 gint *remaining_space)
5187 GtkContainer *container;
5189 GtkNotebookPage *page;
5190 gint tab_pos, tab_overlap;
5192 widget = GTK_WIDGET (notebook);
5193 container = GTK_CONTAINER (notebook);
5194 gtk_widget_style_get (widget, "tab-overlap", &tab_overlap, NULL);
5195 tab_pos = get_effective_tab_pos (notebook);
5197 if (show_arrows) /* first_tab <- focus_tab */
5199 *remaining_space = tab_space;
5201 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, notebook->cur_page) &&
5202 gtk_widget_get_visible (notebook->cur_page->child))
5204 gtk_notebook_calc_tabs (notebook,
5205 notebook->focus_tab,
5206 &(notebook->focus_tab),
5207 remaining_space, STEP_NEXT);
5210 if (tab_space <= 0 || *remaining_space <= 0)
5213 notebook->first_tab = notebook->focus_tab;
5214 *last_child = gtk_notebook_search_page (notebook, notebook->focus_tab,
5216 page = notebook->first_tab->data;
5217 *remaining_space = tab_space - page->requisition.width;
5224 if (notebook->first_tab && notebook->first_tab != notebook->focus_tab)
5226 /* Is first_tab really predecessor of focus_tab? */
5227 page = notebook->first_tab->data;
5228 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) &&
5229 gtk_widget_get_visible (page->child))
5230 for (children = notebook->focus_tab;
5231 children && children != notebook->first_tab;
5232 children = gtk_notebook_search_page (notebook,
5240 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, notebook->cur_page))
5241 notebook->first_tab = notebook->focus_tab;
5243 notebook->first_tab = gtk_notebook_search_page (notebook, notebook->focus_tab,
5247 /* calculate shown tabs counting backwards from the focus tab */
5248 gtk_notebook_calc_tabs (notebook,
5249 gtk_notebook_search_page (notebook,
5250 notebook->focus_tab,
5253 &(notebook->first_tab), remaining_space,
5256 if (*remaining_space < 0)
5258 notebook->first_tab =
5259 gtk_notebook_search_page (notebook, notebook->first_tab,
5261 if (!notebook->first_tab)
5262 notebook->first_tab = notebook->focus_tab;
5264 *last_child = gtk_notebook_search_page (notebook, notebook->focus_tab,
5267 else /* focus_tab -> end */
5269 if (!notebook->first_tab)
5270 notebook->first_tab = gtk_notebook_search_page (notebook,
5275 gtk_notebook_calc_tabs (notebook,
5276 gtk_notebook_search_page (notebook,
5277 notebook->focus_tab,
5280 &children, remaining_space, STEP_NEXT);
5282 if (*remaining_space <= 0)
5283 *last_child = children;
5284 else /* start <- first_tab */
5289 gtk_notebook_calc_tabs (notebook,
5290 gtk_notebook_search_page (notebook,
5291 notebook->first_tab,
5294 &children, remaining_space, STEP_PREV);
5296 if (*remaining_space == 0)
5297 notebook->first_tab = children;
5299 notebook->first_tab = gtk_notebook_search_page(notebook,
5306 if (*remaining_space < 0)
5308 /* calculate number of tabs */
5309 *remaining_space = - (*remaining_space);
5312 for (children = notebook->first_tab;
5313 children && children != *last_child;
5314 children = gtk_notebook_search_page (notebook, children,
5319 *remaining_space = 0;
5322 /* unmap all non-visible tabs */
5323 for (children = gtk_notebook_search_page (notebook, NULL,
5325 children && children != notebook->first_tab;
5326 children = gtk_notebook_search_page (notebook, children,
5329 page = children->data;
5331 if (page->tab_label &&
5332 NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page))
5333 gtk_widget_set_child_visible (page->tab_label, FALSE);
5336 for (children = *last_child; children;
5337 children = gtk_notebook_search_page (notebook, children,
5340 page = children->data;
5342 if (page->tab_label &&
5343 NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page))
5344 gtk_widget_set_child_visible (page->tab_label, FALSE);
5347 else /* !show_arrows */
5352 *remaining_space = max - min - tab_overlap - tab_space;
5353 children = notebook->children;
5354 notebook->first_tab = gtk_notebook_search_page (notebook, NULL,
5358 page = children->data;
5359 children = children->next;
5361 if (!NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) ||
5362 !gtk_widget_get_visible (page->child))
5371 /* if notebook is homogeneous, all tabs are expanded */
5372 if (notebook->homogeneous && *n)
5378 get_allocate_at_bottom (GtkWidget *widget,
5379 gint search_direction)
5381 gboolean is_rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
5382 gboolean tab_pos = get_effective_tab_pos (GTK_NOTEBOOK (widget));
5387 case GTK_POS_BOTTOM:
5389 return (search_direction == STEP_PREV);
5391 return (search_direction == STEP_NEXT);
5396 return (search_direction == STEP_PREV);
5404 gtk_notebook_calculate_tabs_allocation (GtkNotebook *notebook,
5409 gint *remaining_space,
5410 gint *expanded_tabs,
5415 GtkContainer *container;
5416 GtkNotebookPrivate *priv;
5417 GtkNotebookPage *page;
5418 gboolean allocate_at_bottom;
5419 gint tab_overlap, tab_pos, tab_extra_space;
5420 gint left_x, right_x, top_y, bottom_y, anchor;
5421 gint xthickness, ythickness;
5422 gboolean gap_left, packing_changed;
5423 GtkAllocation child_allocation = { 0, };
5425 widget = GTK_WIDGET (notebook);
5426 container = GTK_CONTAINER (notebook);
5427 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
5428 gtk_widget_style_get (widget, "tab-overlap", &tab_overlap, NULL);
5429 tab_pos = get_effective_tab_pos (notebook);
5430 allocate_at_bottom = get_allocate_at_bottom (widget, direction);
5433 child_allocation.x = widget->allocation.x + container->border_width;
5434 child_allocation.y = widget->allocation.y + container->border_width;
5436 xthickness = widget->style->xthickness;
5437 ythickness = widget->style->ythickness;
5441 case GTK_POS_BOTTOM:
5442 child_allocation.y = widget->allocation.y + widget->allocation.height -
5443 notebook->cur_page->requisition.height - container->border_width;
5446 child_allocation.x = (allocate_at_bottom) ? max : min;
5447 child_allocation.height = notebook->cur_page->requisition.height;
5448 anchor = child_allocation.x;
5452 child_allocation.x = widget->allocation.x + widget->allocation.width -
5453 notebook->cur_page->requisition.width - container->border_width;
5456 child_allocation.y = (allocate_at_bottom) ? max : min;
5457 child_allocation.width = notebook->cur_page->requisition.width;
5458 anchor = child_allocation.y;
5462 left_x = CLAMP (priv->mouse_x - priv->drag_offset_x,
5463 min, max - notebook->cur_page->allocation.width);
5464 top_y = CLAMP (priv->mouse_y - priv->drag_offset_y,
5465 min, max - notebook->cur_page->allocation.height);
5466 right_x = left_x + notebook->cur_page->allocation.width;
5467 bottom_y = top_y + notebook->cur_page->allocation.height;
5468 gap_left = packing_changed = FALSE;
5470 while (*children && *children != last_child)
5472 page = (*children)->data;
5474 if (direction == STEP_NEXT && page->pack != GTK_PACK_START)
5478 else if (priv->operation == DRAG_OPERATION_REORDER)
5479 packing_changed = TRUE;
5482 if (direction == STEP_NEXT)
5483 *children = gtk_notebook_search_page (notebook, *children, direction, TRUE);
5486 *children = (*children)->next;
5488 if (page->pack != GTK_PACK_END || !gtk_widget_get_visible (page->child))
5492 if (!NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page))
5495 tab_extra_space = 0;
5496 if (*expanded_tabs && (showarrow || page->expand || notebook->homogeneous))
5498 tab_extra_space = *remaining_space / *expanded_tabs;
5499 *remaining_space -= tab_extra_space;
5506 case GTK_POS_BOTTOM:
5507 child_allocation.width = page->requisition.width + tab_overlap + tab_extra_space;
5509 /* make sure that the reordered tab doesn't go past the last position */
5510 if (priv->operation == DRAG_OPERATION_REORDER &&
5511 !gap_left && packing_changed)
5513 if (!allocate_at_bottom)
5515 if ((notebook->cur_page->pack == GTK_PACK_START && left_x >= anchor) ||
5516 (notebook->cur_page->pack == GTK_PACK_END && left_x < anchor))
5518 left_x = priv->drag_window_x = anchor;
5519 anchor += notebook->cur_page->allocation.width - tab_overlap;
5524 if ((notebook->cur_page->pack == GTK_PACK_START && right_x <= anchor) ||
5525 (notebook->cur_page->pack == GTK_PACK_END && right_x > anchor))
5527 anchor -= notebook->cur_page->allocation.width;
5528 left_x = priv->drag_window_x = anchor;
5529 anchor += tab_overlap;
5536 if (priv->operation == DRAG_OPERATION_REORDER && page == notebook->cur_page)
5538 priv->drag_window_x = left_x;
5539 priv->drag_window_y = child_allocation.y;
5543 if (allocate_at_bottom)
5544 anchor -= child_allocation.width;
5546 if (priv->operation == DRAG_OPERATION_REORDER && page->pack == notebook->cur_page->pack)
5548 if (!allocate_at_bottom &&
5550 left_x <= anchor + child_allocation.width / 2)
5551 anchor += notebook->cur_page->allocation.width - tab_overlap;
5552 else if (allocate_at_bottom &&
5553 right_x >= anchor + child_allocation.width / 2 &&
5554 right_x <= anchor + child_allocation.width)
5555 anchor -= notebook->cur_page->allocation.width - tab_overlap;
5558 child_allocation.x = anchor;
5564 child_allocation.height = page->requisition.height + tab_overlap + tab_extra_space;
5566 /* make sure that the reordered tab doesn't go past the last position */
5567 if (priv->operation == DRAG_OPERATION_REORDER &&
5568 !gap_left && packing_changed)
5570 if (!allocate_at_bottom &&
5571 ((notebook->cur_page->pack == GTK_PACK_START && top_y >= anchor) ||
5572 (notebook->cur_page->pack == GTK_PACK_END && top_y < anchor)))
5574 top_y = priv->drag_window_y = anchor;
5575 anchor += notebook->cur_page->allocation.height - tab_overlap;
5581 if (priv->operation == DRAG_OPERATION_REORDER && page == notebook->cur_page)
5583 priv->drag_window_x = child_allocation.x;
5584 priv->drag_window_y = top_y;
5588 if (allocate_at_bottom)
5589 anchor -= child_allocation.height;
5591 if (priv->operation == DRAG_OPERATION_REORDER && page->pack == notebook->cur_page->pack)
5593 if (!allocate_at_bottom &&
5595 top_y <= anchor + child_allocation.height / 2)
5596 anchor += notebook->cur_page->allocation.height - tab_overlap;
5597 else if (allocate_at_bottom &&
5598 bottom_y >= anchor + child_allocation.height / 2 &&
5599 bottom_y <= anchor + child_allocation.height)
5600 anchor -= notebook->cur_page->allocation.height - tab_overlap;
5603 child_allocation.y = anchor;
5609 page->allocation = child_allocation;
5611 if ((page == priv->detached_tab && priv->operation == DRAG_OPERATION_DETACH) ||
5612 (page == notebook->cur_page && priv->operation == DRAG_OPERATION_REORDER))
5614 /* needs to be allocated at 0,0
5615 * to be shown in the drag window */
5616 page->allocation.x = 0;
5617 page->allocation.y = 0;
5620 if (page != notebook->cur_page)
5625 page->allocation.y += ythickness;
5627 case GTK_POS_BOTTOM:
5628 page->allocation.height = MAX (1, page->allocation.height - ythickness);
5631 page->allocation.x += xthickness;
5634 page->allocation.width = MAX (1, page->allocation.width - xthickness);
5639 /* calculate whether to leave a gap based on reorder operation or not */
5643 case GTK_POS_BOTTOM:
5644 if (priv->operation != DRAG_OPERATION_REORDER ||
5645 (priv->operation == DRAG_OPERATION_REORDER && page != notebook->cur_page))
5647 if (priv->operation == DRAG_OPERATION_REORDER)
5649 if (page->pack == notebook->cur_page->pack &&
5650 !allocate_at_bottom &&
5651 left_x > anchor + child_allocation.width / 2 &&
5652 left_x <= anchor + child_allocation.width)
5653 anchor += notebook->cur_page->allocation.width - tab_overlap;
5654 else if (page->pack == notebook->cur_page->pack &&
5655 allocate_at_bottom &&
5656 right_x >= anchor &&
5657 right_x <= anchor + child_allocation.width / 2)
5658 anchor -= notebook->cur_page->allocation.width - tab_overlap;
5661 if (!allocate_at_bottom)
5662 anchor += child_allocation.width - tab_overlap;
5664 anchor += tab_overlap;
5670 if (priv->operation != DRAG_OPERATION_REORDER ||
5671 (priv->operation == DRAG_OPERATION_REORDER && page != notebook->cur_page))
5673 if (priv->operation == DRAG_OPERATION_REORDER)
5675 if (page->pack == notebook->cur_page->pack &&
5676 !allocate_at_bottom &&
5677 top_y >= anchor + child_allocation.height / 2 &&
5678 top_y <= anchor + child_allocation.height)
5679 anchor += notebook->cur_page->allocation.height - tab_overlap;
5680 else if (page->pack == notebook->cur_page->pack &&
5681 allocate_at_bottom &&
5682 bottom_y >= anchor &&
5683 bottom_y <= anchor + child_allocation.height / 2)
5684 anchor -= notebook->cur_page->allocation.height - tab_overlap;
5687 if (!allocate_at_bottom)
5688 anchor += child_allocation.height - tab_overlap;
5690 anchor += tab_overlap;
5696 /* set child visible */
5697 if (page->tab_label)
5698 gtk_widget_set_child_visible (page->tab_label, TRUE);
5701 /* Don't move the current tab past the last position during tabs reordering */
5703 priv->operation == DRAG_OPERATION_REORDER &&
5704 ((direction == STEP_NEXT && notebook->cur_page->pack == GTK_PACK_START) ||
5705 ((direction == STEP_PREV || packing_changed) && notebook->cur_page->pack == GTK_PACK_END)))
5710 case GTK_POS_BOTTOM:
5711 if (allocate_at_bottom)
5712 anchor -= notebook->cur_page->allocation.width;
5714 if ((!allocate_at_bottom && priv->drag_window_x > anchor) ||
5715 (allocate_at_bottom && priv->drag_window_x < anchor))
5716 priv->drag_window_x = anchor;
5720 if (allocate_at_bottom)
5721 anchor -= notebook->cur_page->allocation.height;
5723 if ((!allocate_at_bottom && priv->drag_window_y > anchor) ||
5724 (allocate_at_bottom && priv->drag_window_y < anchor))
5725 priv->drag_window_y = anchor;
5732 gtk_notebook_pages_allocate (GtkNotebook *notebook)
5734 GList *children = NULL;
5735 GList *last_child = NULL;
5736 gboolean showarrow = FALSE;
5737 gint tab_space, min, max, remaining_space;
5738 gint expanded_tabs, operation;
5739 gboolean tab_allocations_changed = FALSE;
5741 if (!notebook->show_tabs || !notebook->children || !notebook->cur_page)
5744 min = max = tab_space = remaining_space = 0;
5747 gtk_notebook_tab_space (notebook, &showarrow,
5748 &min, &max, &tab_space);
5750 gtk_notebook_calculate_shown_tabs (notebook, showarrow,
5751 min, max, tab_space, &last_child,
5752 &expanded_tabs, &remaining_space);
5754 children = notebook->first_tab;
5755 gtk_notebook_calculate_tabs_allocation (notebook, &children, last_child,
5756 showarrow, STEP_NEXT,
5757 &remaining_space, &expanded_tabs, min, max);
5758 if (children && children != last_child)
5760 children = notebook->children;
5761 gtk_notebook_calculate_tabs_allocation (notebook, &children, last_child,
5762 showarrow, STEP_PREV,
5763 &remaining_space, &expanded_tabs, min, max);
5766 children = notebook->children;
5770 if (gtk_notebook_page_allocate (notebook, GTK_NOTEBOOK_PAGE (children)))
5771 tab_allocations_changed = TRUE;
5772 children = children->next;
5775 operation = GTK_NOTEBOOK_GET_PRIVATE (notebook)->operation;
5777 if (!notebook->first_tab)
5778 notebook->first_tab = notebook->children;
5780 if (tab_allocations_changed)
5781 gtk_notebook_redraw_tabs (notebook);
5785 gtk_notebook_page_allocate (GtkNotebook *notebook,
5786 GtkNotebookPage *page)
5788 GtkWidget *widget = GTK_WIDGET (notebook);
5789 GtkAllocation child_allocation;
5790 GtkRequisition tab_requisition;
5796 gint tab_pos = get_effective_tab_pos (notebook);
5797 gboolean tab_allocation_changed;
5798 gboolean was_visible = page->tab_allocated_visible;
5800 if (!page->tab_label ||
5801 !gtk_widget_get_visible (page->tab_label) ||
5802 !gtk_widget_get_child_visible (page->tab_label))
5804 page->tab_allocated_visible = FALSE;
5808 xthickness = widget->style->xthickness;
5809 ythickness = widget->style->ythickness;
5811 gtk_widget_get_child_requisition (page->tab_label, &tab_requisition);
5812 gtk_widget_style_get (widget,
5813 "focus-line-width", &focus_width,
5814 "tab-curvature", &tab_curvature,
5819 case GTK_POS_BOTTOM:
5820 padding = tab_curvature + focus_width + notebook->tab_hborder;
5823 child_allocation.x = xthickness + focus_width + notebook->tab_hborder;
5824 child_allocation.width = MAX (1, page->allocation.width - 2 * child_allocation.x);
5825 child_allocation.x += page->allocation.x;
5829 child_allocation.x = page->allocation.x +
5830 (page->allocation.width - tab_requisition.width) / 2;
5832 child_allocation.width = tab_requisition.width;
5835 child_allocation.y = notebook->tab_vborder + focus_width + page->allocation.y;
5837 if (tab_pos == GTK_POS_TOP)
5838 child_allocation.y += ythickness;
5840 child_allocation.height = MAX (1, (page->allocation.height - ythickness -
5841 2 * (notebook->tab_vborder + focus_width)));
5845 padding = tab_curvature + focus_width + notebook->tab_vborder;
5848 child_allocation.y = ythickness + padding;
5849 child_allocation.height = MAX (1, (page->allocation.height -
5850 2 * child_allocation.y));
5851 child_allocation.y += page->allocation.y;
5855 child_allocation.y = page->allocation.y +
5856 (page->allocation.height - tab_requisition.height) / 2;
5858 child_allocation.height = tab_requisition.height;
5861 child_allocation.x = notebook->tab_hborder + focus_width + page->allocation.x;
5863 if (tab_pos == GTK_POS_LEFT)
5864 child_allocation.x += xthickness;
5866 child_allocation.width = MAX (1, (page->allocation.width - xthickness -
5867 2 * (notebook->tab_hborder + focus_width)));
5871 tab_allocation_changed = (child_allocation.x != page->tab_label->allocation.x ||
5872 child_allocation.y != page->tab_label->allocation.y ||
5873 child_allocation.width != page->tab_label->allocation.width ||
5874 child_allocation.height != page->tab_label->allocation.height);
5876 gtk_widget_size_allocate (page->tab_label, &child_allocation);
5880 page->tab_allocated_visible = TRUE;
5881 tab_allocation_changed = TRUE;
5884 return tab_allocation_changed;
5888 gtk_notebook_calc_tabs (GtkNotebook *notebook,
5894 GtkNotebookPage *page = NULL;
5896 GList *last_list = NULL;
5897 GList *last_calculated_child = NULL;
5899 gint tab_pos = get_effective_tab_pos (notebook);
5900 guint real_direction;
5906 pack = GTK_NOTEBOOK_PAGE (start)->pack;
5907 if (pack == GTK_PACK_END)
5908 real_direction = (direction == STEP_PREV) ? STEP_NEXT : STEP_PREV;
5910 real_direction = direction;
5917 case GTK_POS_BOTTOM:
5920 page = children->data;
5921 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) &&
5922 gtk_widget_get_visible (page->child))
5924 if (page->pack == pack)
5926 *tab_space -= page->requisition.width;
5927 if (*tab_space < 0 || children == *end)
5931 *tab_space = - (*tab_space +
5932 page->requisition.width);
5934 if (*tab_space == 0 && direction == STEP_PREV)
5935 children = last_calculated_child;
5942 last_calculated_child = children;
5944 last_list = children;
5946 if (real_direction == STEP_NEXT)
5947 children = children->next;
5949 children = children->prev;
5956 page = children->data;
5957 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) &&
5958 gtk_widget_get_visible (page->child))
5960 if (page->pack == pack)
5962 *tab_space -= page->requisition.height;
5963 if (*tab_space < 0 || children == *end)
5967 *tab_space = - (*tab_space +
5968 page->requisition.height);
5970 if (*tab_space == 0 && direction == STEP_PREV)
5971 children = last_calculated_child;
5978 last_calculated_child = children;
5980 last_list = children;
5982 if (real_direction == STEP_NEXT)
5983 children = children->next;
5985 children = children->prev;
5989 if (real_direction == STEP_PREV)
5991 pack = (pack == GTK_PACK_END) ? GTK_PACK_START : GTK_PACK_END;
5992 real_direction = STEP_PREV;
5993 children = last_list;
5998 gtk_notebook_update_tab_states (GtkNotebook *notebook)
6002 for (list = notebook->children; list != NULL; list = list->next)
6004 GtkNotebookPage *page = list->data;
6006 if (page->tab_label)
6008 if (page == notebook->cur_page)
6009 gtk_widget_set_state (page->tab_label, GTK_STATE_NORMAL);
6011 gtk_widget_set_state (page->tab_label, GTK_STATE_ACTIVE);
6016 /* Private GtkNotebook Page Switch Methods:
6018 * gtk_notebook_real_switch_page
6021 gtk_notebook_real_switch_page (GtkNotebook *notebook,
6022 GtkNotebookPage* child,
6025 GList *list = gtk_notebook_find_child (notebook, GTK_WIDGET (child), NULL);
6026 GtkNotebookPage *page = GTK_NOTEBOOK_PAGE (list);
6027 gboolean child_has_focus;
6029 if (notebook->cur_page == page || !gtk_widget_get_visible (GTK_WIDGET (child)))
6032 /* save the value here, changing visibility changes focus */
6033 child_has_focus = notebook->child_has_focus;
6035 if (notebook->cur_page)
6036 gtk_widget_set_child_visible (notebook->cur_page->child, FALSE);
6038 notebook->cur_page = page;
6040 if (!notebook->focus_tab ||
6041 notebook->focus_tab->data != (gpointer) notebook->cur_page)
6042 notebook->focus_tab =
6043 g_list_find (notebook->children, notebook->cur_page);
6045 gtk_widget_set_child_visible (notebook->cur_page->child, TRUE);
6047 /* If the focus was on the previous page, move it to the first
6048 * element on the new page, if possible, or if not, to the
6051 if (child_has_focus)
6053 if (notebook->cur_page->last_focus_child &&
6054 gtk_widget_is_ancestor (notebook->cur_page->last_focus_child, notebook->cur_page->child))
6055 gtk_widget_grab_focus (notebook->cur_page->last_focus_child);
6057 if (!gtk_widget_child_focus (notebook->cur_page->child, GTK_DIR_TAB_FORWARD))
6058 gtk_widget_grab_focus (GTK_WIDGET (notebook));
6061 gtk_notebook_update_tab_states (notebook);
6062 gtk_widget_queue_resize (GTK_WIDGET (notebook));
6063 g_object_notify (G_OBJECT (notebook), "page");
6066 /* Private GtkNotebook Page Switch Functions:
6068 * gtk_notebook_switch_page
6069 * gtk_notebook_page_select
6070 * gtk_notebook_switch_focus_tab
6071 * gtk_notebook_menu_switch_page
6074 gtk_notebook_switch_page (GtkNotebook *notebook,
6075 GtkNotebookPage *page)
6079 if (notebook->cur_page == page)
6082 page_num = g_list_index (notebook->children, page);
6084 g_signal_emit (notebook,
6085 notebook_signals[SWITCH_PAGE],
6092 gtk_notebook_page_select (GtkNotebook *notebook,
6093 gboolean move_focus)
6095 GtkNotebookPage *page;
6096 GtkDirectionType dir = GTK_DIR_DOWN; /* Quiet GCC */
6097 gint tab_pos = get_effective_tab_pos (notebook);
6099 if (!notebook->focus_tab)
6102 page = notebook->focus_tab->data;
6103 gtk_notebook_switch_page (notebook, page);
6112 case GTK_POS_BOTTOM:
6116 dir = GTK_DIR_RIGHT;
6123 if (gtk_widget_child_focus (page->child, dir))
6130 gtk_notebook_switch_focus_tab (GtkNotebook *notebook,
6134 GtkNotebookPage *page;
6136 if (notebook->focus_tab == new_child)
6139 old_child = notebook->focus_tab;
6140 notebook->focus_tab = new_child;
6142 if (notebook->scrollable)
6143 gtk_notebook_redraw_arrows (notebook);
6145 if (!notebook->show_tabs || !notebook->focus_tab)
6148 page = notebook->focus_tab->data;
6149 if (gtk_widget_get_mapped (page->tab_label))
6150 gtk_notebook_redraw_tabs (notebook);
6152 gtk_notebook_pages_allocate (notebook);
6154 gtk_notebook_switch_page (notebook, page);
6158 gtk_notebook_menu_switch_page (GtkWidget *widget,
6159 GtkNotebookPage *page)
6161 GtkNotebook *notebook;
6165 notebook = GTK_NOTEBOOK (gtk_menu_get_attach_widget
6166 (GTK_MENU (widget->parent)));
6168 if (notebook->cur_page == page)
6172 children = notebook->children;
6173 while (children && children->data != page)
6175 children = children->next;
6179 g_signal_emit (notebook,
6180 notebook_signals[SWITCH_PAGE],
6186 /* Private GtkNotebook Menu Functions:
6188 * gtk_notebook_menu_item_create
6189 * gtk_notebook_menu_label_unparent
6190 * gtk_notebook_menu_detacher
6193 gtk_notebook_menu_item_create (GtkNotebook *notebook,
6196 GtkNotebookPage *page;
6197 GtkWidget *menu_item;
6200 if (page->default_menu)
6202 if (GTK_IS_LABEL (page->tab_label))
6203 page->menu_label = gtk_label_new (gtk_label_get_label (GTK_LABEL (page->tab_label)));
6205 page->menu_label = gtk_label_new ("");
6206 gtk_misc_set_alignment (GTK_MISC (page->menu_label), 0.0, 0.5);
6209 gtk_widget_show (page->menu_label);
6210 menu_item = gtk_menu_item_new ();
6211 gtk_container_add (GTK_CONTAINER (menu_item), page->menu_label);
6212 gtk_menu_shell_insert (GTK_MENU_SHELL (notebook->menu), menu_item,
6213 gtk_notebook_real_page_position (notebook, list));
6214 g_signal_connect (menu_item, "activate",
6215 G_CALLBACK (gtk_notebook_menu_switch_page), page);
6216 if (gtk_widget_get_visible (page->child))
6217 gtk_widget_show (menu_item);
6221 gtk_notebook_menu_label_unparent (GtkWidget *widget,
6224 gtk_widget_unparent (GTK_BIN (widget)->child);
6225 GTK_BIN (widget)->child = NULL;
6229 gtk_notebook_menu_detacher (GtkWidget *widget,
6232 GtkNotebook *notebook;
6234 notebook = GTK_NOTEBOOK (widget);
6235 g_return_if_fail (notebook->menu == (GtkWidget*) menu);
6237 notebook->menu = NULL;
6240 /* Public GtkNotebook Page Insert/Remove Methods :
6242 * gtk_notebook_append_page
6243 * gtk_notebook_append_page_menu
6244 * gtk_notebook_prepend_page
6245 * gtk_notebook_prepend_page_menu
6246 * gtk_notebook_insert_page
6247 * gtk_notebook_insert_page_menu
6248 * gtk_notebook_remove_page
6251 * gtk_notebook_append_page:
6252 * @notebook: a #GtkNotebook
6253 * @child: the #GtkWidget to use as the contents of the page.
6254 * @tab_label: (allow-none): the #GtkWidget to be used as the label for the page,
6255 * or %NULL to use the default label, 'page N'.
6257 * Appends a page to @notebook.
6259 * Return value: the index (starting from 0) of the appended
6260 * page in the notebook, or -1 if function fails
6263 gtk_notebook_append_page (GtkNotebook *notebook,
6265 GtkWidget *tab_label)
6267 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6268 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6269 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6271 return gtk_notebook_insert_page_menu (notebook, child, tab_label, NULL, -1);
6275 * gtk_notebook_append_page_menu:
6276 * @notebook: a #GtkNotebook
6277 * @child: the #GtkWidget to use as the contents of the page.
6278 * @tab_label: (allow-none): the #GtkWidget to be used as the label for the page,
6279 * or %NULL to use the default label, 'page N'.
6280 * @menu_label: (allow-none): the widget to use as a label for the page-switch
6281 * menu, if that is enabled. If %NULL, and @tab_label
6282 * is a #GtkLabel or %NULL, then the menu label will be
6283 * a newly created label with the same text as @tab_label;
6284 * If @tab_label is not a #GtkLabel, @menu_label must be
6285 * specified if the page-switch menu is to be used.
6287 * Appends a page to @notebook, specifying the widget to use as the
6288 * label in the popup menu.
6290 * Return value: the index (starting from 0) of the appended
6291 * page in the notebook, or -1 if function fails
6294 gtk_notebook_append_page_menu (GtkNotebook *notebook,
6296 GtkWidget *tab_label,
6297 GtkWidget *menu_label)
6299 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6300 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6301 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6302 g_return_val_if_fail (menu_label == NULL || GTK_IS_WIDGET (menu_label), -1);
6304 return gtk_notebook_insert_page_menu (notebook, child, tab_label, menu_label, -1);
6308 * gtk_notebook_prepend_page:
6309 * @notebook: a #GtkNotebook
6310 * @child: the #GtkWidget to use as the contents of the page.
6311 * @tab_label: (allow-none): the #GtkWidget to be used as the label for the page,
6312 * or %NULL to use the default label, 'page N'.
6314 * Prepends a page to @notebook.
6316 * Return value: the index (starting from 0) of the prepended
6317 * page in the notebook, or -1 if function fails
6320 gtk_notebook_prepend_page (GtkNotebook *notebook,
6322 GtkWidget *tab_label)
6324 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6325 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6326 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6328 return gtk_notebook_insert_page_menu (notebook, child, tab_label, NULL, 0);
6332 * gtk_notebook_prepend_page_menu:
6333 * @notebook: a #GtkNotebook
6334 * @child: the #GtkWidget to use as the contents of the page.
6335 * @tab_label: (allow-none): the #GtkWidget to be used as the label for the page,
6336 * or %NULL to use the default label, 'page N'.
6337 * @menu_label: (allow-none): the widget to use as a label for the page-switch
6338 * menu, if that is enabled. If %NULL, and @tab_label
6339 * is a #GtkLabel or %NULL, then the menu label will be
6340 * a newly created label with the same text as @tab_label;
6341 * If @tab_label is not a #GtkLabel, @menu_label must be
6342 * specified if the page-switch menu is to be used.
6344 * Prepends a page to @notebook, specifying the widget to use as the
6345 * label in the popup menu.
6347 * Return value: the index (starting from 0) of the prepended
6348 * page in the notebook, or -1 if function fails
6351 gtk_notebook_prepend_page_menu (GtkNotebook *notebook,
6353 GtkWidget *tab_label,
6354 GtkWidget *menu_label)
6356 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6357 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6358 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6359 g_return_val_if_fail (menu_label == NULL || GTK_IS_WIDGET (menu_label), -1);
6361 return gtk_notebook_insert_page_menu (notebook, child, tab_label, menu_label, 0);
6365 * gtk_notebook_insert_page:
6366 * @notebook: a #GtkNotebook
6367 * @child: the #GtkWidget to use as the contents of the page.
6368 * @tab_label: (allow-none): the #GtkWidget to be used as the label for the page,
6369 * or %NULL to use the default label, 'page N'.
6370 * @position: the index (starting at 0) at which to insert the page,
6371 * or -1 to append the page after all other pages.
6373 * Insert a page into @notebook at the given position.
6375 * Return value: the index (starting from 0) of the inserted
6376 * page in the notebook, or -1 if function fails
6379 gtk_notebook_insert_page (GtkNotebook *notebook,
6381 GtkWidget *tab_label,
6384 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6385 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6386 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6388 return gtk_notebook_insert_page_menu (notebook, child, tab_label, NULL, position);
6393 gtk_notebook_page_compare_tab (gconstpointer a,
6396 return (((GtkNotebookPage *) a)->tab_label != b);
6400 gtk_notebook_mnemonic_activate_switch_page (GtkWidget *child,
6404 GtkNotebook *notebook = GTK_NOTEBOOK (data);
6407 list = g_list_find_custom (notebook->children, child,
6408 gtk_notebook_page_compare_tab);
6411 GtkNotebookPage *page = list->data;
6413 gtk_widget_grab_focus (GTK_WIDGET (notebook)); /* Do this first to avoid focusing new page */
6414 gtk_notebook_switch_page (notebook, page);
6415 focus_tabs_in (notebook);
6422 * gtk_notebook_insert_page_menu:
6423 * @notebook: a #GtkNotebook
6424 * @child: the #GtkWidget to use as the contents of the page.
6425 * @tab_label: (allow-none): the #GtkWidget to be used as the label for the page,
6426 * or %NULL to use the default label, 'page N'.
6427 * @menu_label: (allow-none): the widget to use as a label for the page-switch
6428 * menu, if that is enabled. If %NULL, and @tab_label
6429 * is a #GtkLabel or %NULL, then the menu label will be
6430 * a newly created label with the same text as @tab_label;
6431 * If @tab_label is not a #GtkLabel, @menu_label must be
6432 * specified if the page-switch menu is to be used.
6433 * @position: the index (starting at 0) at which to insert the page,
6434 * or -1 to append the page after all other pages.
6436 * Insert a page into @notebook at the given position, specifying
6437 * the widget to use as the label in the popup menu.
6439 * Return value: the index (starting from 0) of the inserted
6440 * page in the notebook
6443 gtk_notebook_insert_page_menu (GtkNotebook *notebook,
6445 GtkWidget *tab_label,
6446 GtkWidget *menu_label,
6449 GtkNotebookClass *class;
6451 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6452 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6453 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6454 g_return_val_if_fail (menu_label == NULL || GTK_IS_WIDGET (menu_label), -1);
6456 class = GTK_NOTEBOOK_GET_CLASS (notebook);
6458 return (class->insert_page) (notebook, child, tab_label, menu_label, position);
6462 * gtk_notebook_remove_page:
6463 * @notebook: a #GtkNotebook.
6464 * @page_num: the index of a notebook page, starting
6465 * from 0. If -1, the last page will
6468 * Removes a page from the notebook given its index
6472 gtk_notebook_remove_page (GtkNotebook *notebook,
6477 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6480 list = g_list_nth (notebook->children, page_num);
6482 list = g_list_last (notebook->children);
6485 gtk_container_remove (GTK_CONTAINER (notebook),
6486 ((GtkNotebookPage *) list->data)->child);
6489 /* Public GtkNotebook Page Switch Methods :
6490 * gtk_notebook_get_current_page
6491 * gtk_notebook_page_num
6492 * gtk_notebook_set_current_page
6493 * gtk_notebook_next_page
6494 * gtk_notebook_prev_page
6497 * gtk_notebook_get_current_page:
6498 * @notebook: a #GtkNotebook
6500 * Returns the page number of the current page.
6502 * Return value: the index (starting from 0) of the current
6503 * page in the notebook. If the notebook has no pages, then
6504 * -1 will be returned.
6507 gtk_notebook_get_current_page (GtkNotebook *notebook)
6509 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6511 if (!notebook->cur_page)
6514 return g_list_index (notebook->children, notebook->cur_page);
6518 * gtk_notebook_get_nth_page:
6519 * @notebook: a #GtkNotebook
6520 * @page_num: the index of a page in the notebook, or -1
6521 * to get the last page.
6523 * Returns the child widget contained in page number @page_num.
6525 * Return value: (transfer none): the child widget, or %NULL if @page_num is
6529 gtk_notebook_get_nth_page (GtkNotebook *notebook,
6532 GtkNotebookPage *page;
6535 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
6538 list = g_list_nth (notebook->children, page_num);
6540 list = g_list_last (notebook->children);
6552 * gtk_notebook_get_n_pages:
6553 * @notebook: a #GtkNotebook
6555 * Gets the number of pages in a notebook.
6557 * Return value: the number of pages in the notebook.
6562 gtk_notebook_get_n_pages (GtkNotebook *notebook)
6564 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), 0);
6566 return g_list_length (notebook->children);
6570 * gtk_notebook_page_num:
6571 * @notebook: a #GtkNotebook
6572 * @child: a #GtkWidget
6574 * Finds the index of the page which contains the given child
6577 * Return value: the index of the page containing @child, or
6578 * -1 if @child is not in the notebook.
6581 gtk_notebook_page_num (GtkNotebook *notebook,
6587 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6590 children = notebook->children;
6593 GtkNotebookPage *page = children->data;
6595 if (page->child == child)
6598 children = children->next;
6606 * gtk_notebook_set_current_page:
6607 * @notebook: a #GtkNotebook
6608 * @page_num: index of the page to switch to, starting from 0.
6609 * If negative, the last page will be used. If greater
6610 * than the number of pages in the notebook, nothing
6613 * Switches to the page number @page_num.
6615 * Note that due to historical reasons, GtkNotebook refuses
6616 * to switch to a page unless the child widget is visible.
6617 * Therefore, it is recommended to show child widgets before
6618 * adding them to a notebook.
6621 gtk_notebook_set_current_page (GtkNotebook *notebook,
6626 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6629 page_num = g_list_length (notebook->children) - 1;
6631 list = g_list_nth (notebook->children, page_num);
6633 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (list));
6637 * gtk_notebook_next_page:
6638 * @notebook: a #GtkNotebook
6640 * Switches to the next page. Nothing happens if the current page is
6644 gtk_notebook_next_page (GtkNotebook *notebook)
6648 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6650 list = g_list_find (notebook->children, notebook->cur_page);
6654 list = gtk_notebook_search_page (notebook, list, STEP_NEXT, TRUE);
6658 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (list));
6662 * gtk_notebook_prev_page:
6663 * @notebook: a #GtkNotebook
6665 * Switches to the previous page. Nothing happens if the current page
6666 * is the first page.
6669 gtk_notebook_prev_page (GtkNotebook *notebook)
6673 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6675 list = g_list_find (notebook->children, notebook->cur_page);
6679 list = gtk_notebook_search_page (notebook, list, STEP_PREV, TRUE);
6683 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (list));
6686 /* Public GtkNotebook/Tab Style Functions
6688 * gtk_notebook_set_show_border
6689 * gtk_notebook_set_show_tabs
6690 * gtk_notebook_set_tab_pos
6691 * gtk_notebook_set_homogeneous_tabs
6692 * gtk_notebook_set_tab_border
6693 * gtk_notebook_set_tab_hborder
6694 * gtk_notebook_set_tab_vborder
6695 * gtk_notebook_set_scrollable
6698 * gtk_notebook_set_show_border:
6699 * @notebook: a #GtkNotebook
6700 * @show_border: %TRUE if a bevel should be drawn around the notebook.
6702 * Sets whether a bevel will be drawn around the notebook pages.
6703 * This only has a visual effect when the tabs are not shown.
6704 * See gtk_notebook_set_show_tabs().
6707 gtk_notebook_set_show_border (GtkNotebook *notebook,
6708 gboolean show_border)
6710 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6712 if (notebook->show_border != show_border)
6714 notebook->show_border = show_border;
6716 if (gtk_widget_get_visible (GTK_WIDGET (notebook)))
6717 gtk_widget_queue_resize (GTK_WIDGET (notebook));
6719 g_object_notify (G_OBJECT (notebook), "show-border");
6724 * gtk_notebook_get_show_border:
6725 * @notebook: a #GtkNotebook
6727 * Returns whether a bevel will be drawn around the notebook pages. See
6728 * gtk_notebook_set_show_border().
6730 * Return value: %TRUE if the bevel is drawn
6733 gtk_notebook_get_show_border (GtkNotebook *notebook)
6735 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
6737 return notebook->show_border;
6741 * gtk_notebook_set_show_tabs:
6742 * @notebook: a #GtkNotebook
6743 * @show_tabs: %TRUE if the tabs should be shown.
6745 * Sets whether to show the tabs for the notebook or not.
6748 gtk_notebook_set_show_tabs (GtkNotebook *notebook,
6751 GtkNotebookPrivate *priv;
6752 GtkNotebookPage *page;
6756 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6758 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
6760 show_tabs = show_tabs != FALSE;
6762 if (notebook->show_tabs == show_tabs)
6765 notebook->show_tabs = show_tabs;
6766 children = notebook->children;
6770 gtk_widget_set_can_focus (GTK_WIDGET (notebook), FALSE);
6774 page = children->data;
6775 children = children->next;
6776 if (page->default_tab)
6778 gtk_widget_destroy (page->tab_label);
6779 page->tab_label = NULL;
6782 gtk_widget_hide (page->tab_label);
6787 gtk_widget_set_can_focus (GTK_WIDGET (notebook), TRUE);
6788 gtk_notebook_update_labels (notebook);
6791 for (i = 0; i < N_ACTION_WIDGETS; i++)
6793 if (priv->action_widget[i])
6794 gtk_widget_set_child_visible (priv->action_widget[i], show_tabs);
6797 gtk_widget_queue_resize (GTK_WIDGET (notebook));
6799 g_object_notify (G_OBJECT (notebook), "show-tabs");
6803 * gtk_notebook_get_show_tabs:
6804 * @notebook: a #GtkNotebook
6806 * Returns whether the tabs of the notebook are shown. See
6807 * gtk_notebook_set_show_tabs().
6809 * Return value: %TRUE if the tabs are shown
6812 gtk_notebook_get_show_tabs (GtkNotebook *notebook)
6814 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
6816 return notebook->show_tabs;
6820 * gtk_notebook_set_tab_pos:
6821 * @notebook: a #GtkNotebook.
6822 * @pos: the edge to draw the tabs at.
6824 * Sets the edge at which the tabs for switching pages in the
6825 * notebook are drawn.
6828 gtk_notebook_set_tab_pos (GtkNotebook *notebook,
6829 GtkPositionType pos)
6831 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6833 if (notebook->tab_pos != pos)
6835 notebook->tab_pos = pos;
6836 if (gtk_widget_get_visible (GTK_WIDGET (notebook)))
6837 gtk_widget_queue_resize (GTK_WIDGET (notebook));
6840 g_object_notify (G_OBJECT (notebook), "tab-pos");
6844 * gtk_notebook_get_tab_pos:
6845 * @notebook: a #GtkNotebook
6847 * Gets the edge at which the tabs for switching pages in the
6848 * notebook are drawn.
6850 * Return value: the edge at which the tabs are drawn
6853 gtk_notebook_get_tab_pos (GtkNotebook *notebook)
6855 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), GTK_POS_TOP);
6857 return notebook->tab_pos;
6861 * gtk_notebook_set_scrollable:
6862 * @notebook: a #GtkNotebook
6863 * @scrollable: %TRUE if scroll arrows should be added
6865 * Sets whether the tab label area will have arrows for scrolling if
6866 * there are too many tabs to fit in the area.
6869 gtk_notebook_set_scrollable (GtkNotebook *notebook,
6870 gboolean scrollable)
6872 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6874 scrollable = (scrollable != FALSE);
6876 if (scrollable != notebook->scrollable)
6878 notebook->scrollable = scrollable;
6880 if (gtk_widget_get_visible (GTK_WIDGET (notebook)))
6881 gtk_widget_queue_resize (GTK_WIDGET (notebook));
6883 g_object_notify (G_OBJECT (notebook), "scrollable");
6888 * gtk_notebook_get_scrollable:
6889 * @notebook: a #GtkNotebook
6891 * Returns whether the tab label area has arrows for scrolling. See
6892 * gtk_notebook_set_scrollable().
6894 * Return value: %TRUE if arrows for scrolling are present
6897 gtk_notebook_get_scrollable (GtkNotebook *notebook)
6899 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
6901 return notebook->scrollable;
6904 /* Public GtkNotebook Popup Menu Methods:
6906 * gtk_notebook_popup_enable
6907 * gtk_notebook_popup_disable
6912 * gtk_notebook_popup_enable:
6913 * @notebook: a #GtkNotebook
6915 * Enables the popup menu: if the user clicks with the right mouse button on
6916 * the tab labels, a menu with all the pages will be popped up.
6919 gtk_notebook_popup_enable (GtkNotebook *notebook)
6923 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6928 notebook->menu = gtk_menu_new ();
6929 for (list = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, FALSE);
6931 list = gtk_notebook_search_page (notebook, list, STEP_NEXT, FALSE))
6932 gtk_notebook_menu_item_create (notebook, list);
6934 gtk_notebook_update_labels (notebook);
6935 gtk_menu_attach_to_widget (GTK_MENU (notebook->menu),
6936 GTK_WIDGET (notebook),
6937 gtk_notebook_menu_detacher);
6939 g_object_notify (G_OBJECT (notebook), "enable-popup");
6943 * gtk_notebook_popup_disable:
6944 * @notebook: a #GtkNotebook
6946 * Disables the popup menu.
6949 gtk_notebook_popup_disable (GtkNotebook *notebook)
6951 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6953 if (!notebook->menu)
6956 gtk_container_foreach (GTK_CONTAINER (notebook->menu),
6957 (GtkCallback) gtk_notebook_menu_label_unparent, NULL);
6958 gtk_widget_destroy (notebook->menu);
6960 g_object_notify (G_OBJECT (notebook), "enable-popup");
6963 /* Public GtkNotebook Page Properties Functions:
6965 * gtk_notebook_get_tab_label
6966 * gtk_notebook_set_tab_label
6967 * gtk_notebook_set_tab_label_text
6968 * gtk_notebook_get_menu_label
6969 * gtk_notebook_set_menu_label
6970 * gtk_notebook_set_menu_label_text
6971 * gtk_notebook_set_tab_label_packing
6972 * gtk_notebook_query_tab_label_packing
6973 * gtk_notebook_get_tab_reorderable
6974 * gtk_notebook_set_tab_reorderable
6975 * gtk_notebook_get_tab_detachable
6976 * gtk_notebook_set_tab_detachable
6980 * gtk_notebook_get_tab_label:
6981 * @notebook: a #GtkNotebook
6984 * Returns the tab label widget for the page @child. %NULL is returned
6985 * if @child is not in @notebook or if no tab label has specifically
6986 * been set for @child.
6988 * Return value: (transfer none): the tab label
6991 gtk_notebook_get_tab_label (GtkNotebook *notebook,
6996 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
6997 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
6999 list = CHECK_FIND_CHILD (notebook, child);
7003 if (GTK_NOTEBOOK_PAGE (list)->default_tab)
7006 return GTK_NOTEBOOK_PAGE (list)->tab_label;
7010 * gtk_notebook_set_tab_label:
7011 * @notebook: a #GtkNotebook
7013 * @tab_label: (allow-none): the tab label widget to use, or %NULL for default tab
7016 * Changes the tab label for @child. If %NULL is specified
7017 * for @tab_label, then the page will have the label 'page N'.
7020 gtk_notebook_set_tab_label (GtkNotebook *notebook,
7022 GtkWidget *tab_label)
7024 GtkNotebookPage *page;
7027 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7028 g_return_if_fail (GTK_IS_WIDGET (child));
7030 list = CHECK_FIND_CHILD (notebook, child);
7034 /* a NULL pointer indicates a default_tab setting, otherwise
7035 * we need to set the associated label
7039 if (page->tab_label == tab_label)
7043 gtk_notebook_remove_tab_label (notebook, page);
7047 page->default_tab = FALSE;
7048 page->tab_label = tab_label;
7049 gtk_widget_set_parent (page->tab_label, GTK_WIDGET (notebook));
7053 page->default_tab = TRUE;
7054 page->tab_label = NULL;
7056 if (notebook->show_tabs)
7060 g_snprintf (string, sizeof(string), _("Page %u"),
7061 gtk_notebook_real_page_position (notebook, list));
7062 page->tab_label = gtk_label_new (string);
7063 gtk_widget_set_parent (page->tab_label, GTK_WIDGET (notebook));
7067 if (page->tab_label)
7068 page->mnemonic_activate_signal =
7069 g_signal_connect (page->tab_label,
7070 "mnemonic-activate",
7071 G_CALLBACK (gtk_notebook_mnemonic_activate_switch_page),
7074 if (notebook->show_tabs && gtk_widget_get_visible (child))
7076 gtk_widget_show (page->tab_label);
7077 gtk_widget_queue_resize (GTK_WIDGET (notebook));
7080 gtk_notebook_update_tab_states (notebook);
7081 gtk_widget_child_notify (child, "tab-label");
7085 * gtk_notebook_set_tab_label_text:
7086 * @notebook: a #GtkNotebook
7088 * @tab_text: the label text
7090 * Creates a new label and sets it as the tab label for the page
7091 * containing @child.
7094 gtk_notebook_set_tab_label_text (GtkNotebook *notebook,
7096 const gchar *tab_text)
7098 GtkWidget *tab_label = NULL;
7100 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7103 tab_label = gtk_label_new (tab_text);
7104 gtk_notebook_set_tab_label (notebook, child, tab_label);
7105 gtk_widget_child_notify (child, "tab-label");
7109 * gtk_notebook_get_tab_label_text:
7110 * @notebook: a #GtkNotebook
7111 * @child: a widget contained in a page of @notebook
7113 * Retrieves the text of the tab label for the page containing
7116 * Return value: the text of the tab label, or %NULL if the
7117 * tab label widget is not a #GtkLabel. The
7118 * string is owned by the widget and must not
7121 G_CONST_RETURN gchar *
7122 gtk_notebook_get_tab_label_text (GtkNotebook *notebook,
7125 GtkWidget *tab_label;
7127 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
7128 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
7130 tab_label = gtk_notebook_get_tab_label (notebook, child);
7132 if (GTK_IS_LABEL (tab_label))
7133 return gtk_label_get_text (GTK_LABEL (tab_label));
7139 * gtk_notebook_get_menu_label:
7140 * @notebook: a #GtkNotebook
7141 * @child: a widget contained in a page of @notebook
7143 * Retrieves the menu label widget of the page containing @child.
7145 * Return value: the menu label, or %NULL if the
7146 * notebook page does not have a menu label other
7147 * than the default (the tab label).
7150 gtk_notebook_get_menu_label (GtkNotebook *notebook,
7155 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
7156 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
7158 list = CHECK_FIND_CHILD (notebook, child);
7162 if (GTK_NOTEBOOK_PAGE (list)->default_menu)
7165 return GTK_NOTEBOOK_PAGE (list)->menu_label;
7169 * gtk_notebook_set_menu_label:
7170 * @notebook: a #GtkNotebook
7171 * @child: the child widget
7172 * @menu_label: (allow-none): the menu label, or NULL for default
7174 * Changes the menu label for the page containing @child.
7177 gtk_notebook_set_menu_label (GtkNotebook *notebook,
7179 GtkWidget *menu_label)
7181 GtkNotebookPage *page;
7184 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7185 g_return_if_fail (GTK_IS_WIDGET (child));
7187 list = CHECK_FIND_CHILD (notebook, child);
7192 if (page->menu_label)
7195 gtk_container_remove (GTK_CONTAINER (notebook->menu),
7196 page->menu_label->parent);
7198 if (!page->default_menu)
7199 g_object_unref (page->menu_label);
7204 page->menu_label = menu_label;
7205 g_object_ref_sink (page->menu_label);
7206 page->default_menu = FALSE;
7209 page->default_menu = TRUE;
7212 gtk_notebook_menu_item_create (notebook, list);
7213 gtk_widget_child_notify (child, "menu-label");
7217 * gtk_notebook_set_menu_label_text:
7218 * @notebook: a #GtkNotebook
7219 * @child: the child widget
7220 * @menu_text: the label text
7222 * Creates a new label and sets it as the menu label of @child.
7225 gtk_notebook_set_menu_label_text (GtkNotebook *notebook,
7227 const gchar *menu_text)
7229 GtkWidget *menu_label = NULL;
7231 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7235 menu_label = gtk_label_new (menu_text);
7236 gtk_misc_set_alignment (GTK_MISC (menu_label), 0.0, 0.5);
7238 gtk_notebook_set_menu_label (notebook, child, menu_label);
7239 gtk_widget_child_notify (child, "menu-label");
7243 * gtk_notebook_get_menu_label_text:
7244 * @notebook: a #GtkNotebook
7245 * @child: the child widget of a page of the notebook.
7247 * Retrieves the text of the menu label for the page containing
7250 * Return value: the text of the tab label, or %NULL if the
7251 * widget does not have a menu label other than
7252 * the default menu label, or the menu label widget
7253 * is not a #GtkLabel. The string is owned by
7254 * the widget and must not be freed.
7256 G_CONST_RETURN gchar *
7257 gtk_notebook_get_menu_label_text (GtkNotebook *notebook,
7260 GtkWidget *menu_label;
7262 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
7263 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
7265 menu_label = gtk_notebook_get_menu_label (notebook, child);
7267 if (GTK_IS_LABEL (menu_label))
7268 return gtk_label_get_text (GTK_LABEL (menu_label));
7273 /* Helper function called when pages are reordered
7276 gtk_notebook_child_reordered (GtkNotebook *notebook,
7277 GtkNotebookPage *page)
7281 GtkWidget *menu_item;
7283 menu_item = page->menu_label->parent;
7284 gtk_container_remove (GTK_CONTAINER (menu_item), page->menu_label);
7285 gtk_container_remove (GTK_CONTAINER (notebook->menu), menu_item);
7286 gtk_notebook_menu_item_create (notebook, g_list_find (notebook->children, page));
7289 gtk_notebook_update_tab_states (notebook);
7290 gtk_notebook_update_labels (notebook);
7294 gtk_notebook_set_tab_label_packing (GtkNotebook *notebook,
7298 GtkPackType pack_type)
7300 GtkNotebookPage *page;
7303 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7304 g_return_if_fail (GTK_IS_WIDGET (child));
7306 list = CHECK_FIND_CHILD (notebook, child);
7311 expand = expand != FALSE;
7312 fill = fill != FALSE;
7313 if (page->pack == pack_type && page->expand == expand && page->fill == fill)
7316 gtk_widget_freeze_child_notify (child);
7317 page->expand = expand;
7318 gtk_widget_child_notify (child, "tab-expand");
7320 gtk_widget_child_notify (child, "tab-fill");
7321 if (page->pack != pack_type)
7323 page->pack = pack_type;
7324 gtk_notebook_child_reordered (notebook, page);
7326 gtk_widget_child_notify (child, "tab-pack");
7327 gtk_widget_child_notify (child, "position");
7328 if (notebook->show_tabs)
7329 gtk_notebook_pages_allocate (notebook);
7330 gtk_widget_thaw_child_notify (child);
7334 gtk_notebook_query_tab_label_packing (GtkNotebook *notebook,
7338 GtkPackType *pack_type)
7342 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7343 g_return_if_fail (GTK_IS_WIDGET (child));
7345 list = CHECK_FIND_CHILD (notebook, child);
7350 *expand = GTK_NOTEBOOK_PAGE (list)->expand;
7352 *fill = GTK_NOTEBOOK_PAGE (list)->fill;
7354 *pack_type = GTK_NOTEBOOK_PAGE (list)->pack;
7358 * gtk_notebook_reorder_child:
7359 * @notebook: a #GtkNotebook
7360 * @child: the child to move
7361 * @position: the new position, or -1 to move to the end
7363 * Reorders the page containing @child, so that it appears in position
7364 * @position. If @position is greater than or equal to the number of
7365 * children in the list or negative, @child will be moved to the end
7369 gtk_notebook_reorder_child (GtkNotebook *notebook,
7373 GList *list, *new_list;
7374 GtkNotebookPage *page;
7378 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7379 g_return_if_fail (GTK_IS_WIDGET (child));
7381 list = CHECK_FIND_CHILD (notebook, child);
7385 max_pos = g_list_length (notebook->children) - 1;
7386 if (position < 0 || position > max_pos)
7389 old_pos = g_list_position (notebook->children, list);
7391 if (old_pos == position)
7395 notebook->children = g_list_delete_link (notebook->children, list);
7397 notebook->children = g_list_insert (notebook->children, page, position);
7398 new_list = g_list_nth (notebook->children, position);
7400 /* Fix up GList references in GtkNotebook structure */
7401 if (notebook->first_tab == list)
7402 notebook->first_tab = new_list;
7403 if (notebook->focus_tab == list)
7404 notebook->focus_tab = new_list;
7406 gtk_widget_freeze_child_notify (child);
7408 /* Move around the menu items if necessary */
7409 gtk_notebook_child_reordered (notebook, page);
7410 gtk_widget_child_notify (child, "tab-pack");
7411 gtk_widget_child_notify (child, "position");
7413 if (notebook->show_tabs)
7414 gtk_notebook_pages_allocate (notebook);
7416 gtk_widget_thaw_child_notify (child);
7418 g_signal_emit (notebook,
7419 notebook_signals[PAGE_REORDERED],
7426 * gtk_notebook_set_window_creation_hook:
7427 * @func: (allow-none): the #GtkNotebookWindowCreationFunc, or %NULL
7428 * @data: user data for @func
7429 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
7431 * Installs a global function used to create a window
7432 * when a detached tab is dropped in an empty area.
7437 gtk_notebook_set_window_creation_hook (GtkNotebookWindowCreationFunc func,
7439 GDestroyNotify destroy)
7441 if (window_creation_hook_destroy)
7442 window_creation_hook_destroy (window_creation_hook_data);
7444 window_creation_hook = func;
7445 window_creation_hook_data = data;
7446 window_creation_hook_destroy = destroy;
7450 * gtk_notebook_set_group:
7451 * @notebook: a #GtkNotebook
7452 * @group: (allow-none): a pointer to identify the notebook group, or %NULL to unset it
7454 * Sets a group identificator pointer for @notebook, notebooks sharing
7455 * the same group identificator pointer will be able to exchange tabs
7456 * via drag and drop. A notebook with a %NULL group identificator will
7457 * not be able to exchange tabs with any other notebook.
7462 gtk_notebook_set_group (GtkNotebook *notebook,
7465 GtkNotebookPrivate *priv;
7467 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7469 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
7471 if (priv->group != group)
7473 priv->group = group;
7474 g_object_notify (G_OBJECT (notebook), "group");
7479 * gtk_notebook_get_group:
7480 * @notebook: a #GtkNotebook
7482 * Gets the current group identificator pointer for @notebook.
7484 * Return Value: the group identificator, or %NULL if none is set.
7489 gtk_notebook_get_group (GtkNotebook *notebook)
7491 GtkNotebookPrivate *priv;
7493 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
7495 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
7500 * gtk_notebook_get_tab_reorderable:
7501 * @notebook: a #GtkNotebook
7502 * @child: a child #GtkWidget
7504 * Gets whether the tab can be reordered via drag and drop or not.
7506 * Return Value: %TRUE if the tab is reorderable.
7511 gtk_notebook_get_tab_reorderable (GtkNotebook *notebook,
7516 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
7517 g_return_val_if_fail (GTK_IS_WIDGET (child), FALSE);
7519 list = CHECK_FIND_CHILD (notebook, child);
7523 return GTK_NOTEBOOK_PAGE (list)->reorderable;
7527 * gtk_notebook_set_tab_reorderable:
7528 * @notebook: a #GtkNotebook
7529 * @child: a child #GtkWidget
7530 * @reorderable: whether the tab is reorderable or not.
7532 * Sets whether the notebook tab can be reordered
7533 * via drag and drop or not.
7538 gtk_notebook_set_tab_reorderable (GtkNotebook *notebook,
7540 gboolean reorderable)
7544 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7545 g_return_if_fail (GTK_IS_WIDGET (child));
7547 list = CHECK_FIND_CHILD (notebook, child);
7551 if (GTK_NOTEBOOK_PAGE (list)->reorderable != reorderable)
7553 GTK_NOTEBOOK_PAGE (list)->reorderable = (reorderable == TRUE);
7554 gtk_widget_child_notify (child, "reorderable");
7559 * gtk_notebook_get_tab_detachable:
7560 * @notebook: a #GtkNotebook
7561 * @child: a child #GtkWidget
7563 * Returns whether the tab contents can be detached from @notebook.
7565 * Return Value: TRUE if the tab is detachable.
7570 gtk_notebook_get_tab_detachable (GtkNotebook *notebook,
7575 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
7576 g_return_val_if_fail (GTK_IS_WIDGET (child), FALSE);
7578 list = CHECK_FIND_CHILD (notebook, child);
7582 return GTK_NOTEBOOK_PAGE (list)->detachable;
7586 * gtk_notebook_set_tab_detachable:
7587 * @notebook: a #GtkNotebook
7588 * @child: a child #GtkWidget
7589 * @detachable: whether the tab is detachable or not
7591 * Sets whether the tab can be detached from @notebook to another
7592 * notebook or widget.
7594 * Note that 2 notebooks must share a common group identificator
7595 * (see gtk_notebook_set_group_id ()) to allow automatic tabs
7596 * interchange between them.
7598 * If you want a widget to interact with a notebook through DnD
7599 * (i.e.: accept dragged tabs from it) it must be set as a drop
7600 * destination and accept the target "GTK_NOTEBOOK_TAB". The notebook
7601 * will fill the selection with a GtkWidget** pointing to the child
7602 * widget that corresponds to the dropped tab.
7605 * on_drop_zone_drag_data_received (GtkWidget *widget,
7606 * GdkDragContext *context,
7609 * GtkSelectionData *selection_data,
7612 * gpointer user_data)
7614 * GtkWidget *notebook;
7615 * GtkWidget **child;
7617 * notebook = gtk_drag_get_source_widget (context);
7618 * child = (void*) selection_data->data;
7620 * process_widget (*child);
7621 * gtk_container_remove (GTK_CONTAINER (notebook), *child);
7625 * If you want a notebook to accept drags from other widgets,
7626 * you will have to set your own DnD code to do it.
7631 gtk_notebook_set_tab_detachable (GtkNotebook *notebook,
7633 gboolean detachable)
7637 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7638 g_return_if_fail (GTK_IS_WIDGET (child));
7640 list = CHECK_FIND_CHILD (notebook, child);
7644 if (GTK_NOTEBOOK_PAGE (list)->detachable != detachable)
7646 GTK_NOTEBOOK_PAGE (list)->detachable = (detachable == TRUE);
7647 gtk_widget_child_notify (child, "detachable");
7652 * gtk_notebook_get_action_widget:
7653 * @notebook: a #GtkNotebook
7654 * @pack_type: pack type of the action widget to receive
7656 * Gets one of the action widgets. See gtk_notebook_set_action_widget().
7658 * Returns: The action widget with the given @pack_type or
7659 * %NULL when this action widget has not been set
7664 gtk_notebook_get_action_widget (GtkNotebook *notebook,
7665 GtkPackType pack_type)
7667 GtkNotebookPrivate *priv;
7669 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
7671 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
7672 return priv->action_widget[pack_type];
7676 * gtk_notebook_set_action_widget:
7677 * @notebook: a #GtkNotebook
7678 * @widget: a #GtkWidget
7679 * @pack_type: pack type of the action widget
7681 * Sets @widget as one of the action widgets. Depending on the pack type
7682 * the widget will be placed before or after the tabs. You can use
7683 * a #GtkBox if you need to pack more than one widget on the same side.
7685 * Note that action widgets are "internal" children of the notebook and thus
7686 * not included in the list returned from gtk_container_foreach().
7691 gtk_notebook_set_action_widget (GtkNotebook *notebook,
7693 GtkPackType pack_type)
7695 GtkNotebookPrivate *priv;
7697 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7698 g_return_if_fail (!widget || GTK_IS_WIDGET (widget));
7699 g_return_if_fail (!widget || widget->parent == NULL);
7701 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
7703 if (priv->action_widget[pack_type])
7704 gtk_widget_unparent (priv->action_widget[pack_type]);
7706 priv->action_widget[pack_type] = widget;
7710 gtk_widget_set_child_visible (widget, notebook->show_tabs);
7711 gtk_widget_set_parent (widget, GTK_WIDGET (notebook));
7714 gtk_widget_queue_resize (GTK_WIDGET (notebook));