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 #include "gtknotebook.h"
38 #include "gtkmenuitem.h"
41 #include "gtkmarshalers.h"
42 #include "gtkbindings.h"
43 #include "gtkprivate.h"
45 #include "gtkbuildable.h"
47 #define SCROLL_DELAY_FACTOR 5
48 #define SCROLL_THRESHOLD 12
49 #define DND_THRESHOLD_MULTIPLIER 4
50 #define FRAMES_PER_SECOND 45
51 #define MSECS_BETWEEN_UPDATES (1000 / FRAMES_PER_SECOND)
53 typedef struct _GtkNotebookPage GtkNotebookPage;
58 DRAG_OPERATION_REORDER,
60 } GtkNotebookDragOperation;
68 struct _GtkNotebookPriv
70 GtkNotebookDragOperation operation;
71 GtkNotebookPage *cur_page;
72 GtkNotebookPage *detached_tab;
73 GtkTargetList *source_targets;
74 GtkWidget *action_widget[N_ACTION_WIDGETS];
75 GtkWidget *dnd_window;
78 GdkWindow *drag_window;
79 GdkWindow *event_window;
82 GList *first_tab; /* The first tab visible (for scrolling notebooks) */
98 guint switch_tab_timer;
107 guint child_has_focus : 1;
108 guint click_child : 3;
109 guint during_detach : 1;
110 guint during_reorder : 1;
111 guint focus_out : 1; /* Flag used by ::move-focus-out implementation */
112 guint has_scrolled : 1;
113 guint have_visible_child : 1;
114 guint homogeneous : 1;
116 guint need_timer : 1;
117 guint show_border : 1;
119 guint scrollable : 1;
122 guint has_before_previous : 1;
123 guint has_before_next : 1;
124 guint has_after_previous : 1;
125 guint has_after_next : 1;
161 } GtkNotebookPointerPosition;
163 #define ARROW_IS_LEFT(arrow) ((arrow) == ARROW_LEFT_BEFORE || (arrow) == ARROW_LEFT_AFTER)
164 #define ARROW_IS_BEFORE(arrow) ((arrow) == ARROW_LEFT_BEFORE || (arrow) == ARROW_RIGHT_BEFORE)
179 CHILD_PROP_TAB_LABEL,
180 CHILD_PROP_MENU_LABEL,
182 CHILD_PROP_TAB_EXPAND,
185 CHILD_PROP_REORDERABLE,
186 CHILD_PROP_DETACHABLE
189 #define GTK_NOTEBOOK_PAGE(_glist_) ((GtkNotebookPage *)((GList *)(_glist_))->data)
191 /* some useful defines for calculating coords */
192 #define PAGE_LEFT_X(_page_) (((GtkNotebookPage *) (_page_))->allocation.x)
193 #define PAGE_RIGHT_X(_page_) (((GtkNotebookPage *) (_page_))->allocation.x + ((GtkNotebookPage *) (_page_))->allocation.width)
194 #define PAGE_MIDDLE_X(_page_) (((GtkNotebookPage *) (_page_))->allocation.x + ((GtkNotebookPage *) (_page_))->allocation.width / 2)
195 #define PAGE_TOP_Y(_page_) (((GtkNotebookPage *) (_page_))->allocation.y)
196 #define PAGE_BOTTOM_Y(_page_) (((GtkNotebookPage *) (_page_))->allocation.y + ((GtkNotebookPage *) (_page_))->allocation.height)
197 #define PAGE_MIDDLE_Y(_page_) (((GtkNotebookPage *) (_page_))->allocation.y + ((GtkNotebookPage *) (_page_))->allocation.height / 2)
198 #define NOTEBOOK_IS_TAB_LABEL_PARENT(_notebook_,_page_) (((GtkNotebookPage *) (_page_))->tab_label->parent == ((GtkWidget *) (_notebook_)))
200 struct _GtkNotebookPage
203 GtkWidget *tab_label;
204 GtkWidget *menu_label;
205 GtkWidget *last_focus_child; /* Last descendant of the page that had focus */
207 guint default_menu : 1; /* If true, we create the menu label ourself */
208 guint default_tab : 1; /* If true, we create the tab label ourself */
212 guint reorderable : 1;
213 guint detachable : 1;
215 /* if true, the tab label was visible on last allocation; we track this so
216 * that we know to redraw the tab area if a tab label was hidden then shown
217 * without changing position */
218 guint tab_allocated_visible : 1;
220 GtkRequisition requisition;
221 GtkAllocation allocation;
223 gulong mnemonic_activate_signal;
224 gulong notify_visible_handler;
227 static const GtkTargetEntry notebook_targets [] = {
228 { "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, 0 },
231 #ifdef G_DISABLE_CHECKS
232 #define CHECK_FIND_CHILD(notebook, child) \
233 gtk_notebook_find_child (notebook, child, G_STRLOC)
235 #define CHECK_FIND_CHILD(notebook, child) \
236 gtk_notebook_find_child (notebook, child, NULL)
239 /*** GtkNotebook Methods ***/
240 static gboolean gtk_notebook_select_page (GtkNotebook *notebook,
241 gboolean move_focus);
242 static gboolean gtk_notebook_focus_tab (GtkNotebook *notebook,
243 GtkNotebookTab type);
244 static gboolean gtk_notebook_change_current_page (GtkNotebook *notebook,
246 static void gtk_notebook_move_focus_out (GtkNotebook *notebook,
247 GtkDirectionType direction_type);
248 static gboolean gtk_notebook_reorder_tab (GtkNotebook *notebook,
249 GtkDirectionType direction_type,
250 gboolean move_to_last);
251 static void gtk_notebook_remove_tab_label (GtkNotebook *notebook,
252 GtkNotebookPage *page);
253 static void gtk_notebook_set_tab_label_packing (GtkNotebook *notebook,
257 GtkPackType pack_type);
258 static void gtk_notebook_query_tab_label_packing (GtkNotebook *notebook,
262 GtkPackType *pack_type);
264 /*** GtkObject Methods ***/
265 static void gtk_notebook_destroy (GtkObject *object);
266 static void gtk_notebook_set_property (GObject *object,
270 static void gtk_notebook_get_property (GObject *object,
275 /*** GtkWidget Methods ***/
276 static void gtk_notebook_map (GtkWidget *widget);
277 static void gtk_notebook_unmap (GtkWidget *widget);
278 static void gtk_notebook_realize (GtkWidget *widget);
279 static void gtk_notebook_unrealize (GtkWidget *widget);
280 static void gtk_notebook_size_request (GtkWidget *widget,
281 GtkRequisition *requisition);
282 static void gtk_notebook_size_allocate (GtkWidget *widget,
283 GtkAllocation *allocation);
284 static gint gtk_notebook_expose (GtkWidget *widget,
285 GdkEventExpose *event);
286 static gboolean gtk_notebook_scroll (GtkWidget *widget,
287 GdkEventScroll *event);
288 static gint gtk_notebook_button_press (GtkWidget *widget,
289 GdkEventButton *event);
290 static gint gtk_notebook_button_release (GtkWidget *widget,
291 GdkEventButton *event);
292 static gboolean gtk_notebook_popup_menu (GtkWidget *widget);
293 static gint gtk_notebook_leave_notify (GtkWidget *widget,
294 GdkEventCrossing *event);
295 static gint gtk_notebook_motion_notify (GtkWidget *widget,
296 GdkEventMotion *event);
297 static gint gtk_notebook_focus_in (GtkWidget *widget,
298 GdkEventFocus *event);
299 static gint gtk_notebook_focus_out (GtkWidget *widget,
300 GdkEventFocus *event);
301 static void gtk_notebook_grab_notify (GtkWidget *widget,
302 gboolean was_grabbed);
303 static void gtk_notebook_state_changed (GtkWidget *widget,
304 GtkStateType previous_state);
305 static void gtk_notebook_draw_focus (GtkWidget *widget,
306 GdkEventExpose *event);
307 static gint gtk_notebook_focus (GtkWidget *widget,
308 GtkDirectionType direction);
309 static void gtk_notebook_style_set (GtkWidget *widget,
312 /*** Drag and drop Methods ***/
313 static void gtk_notebook_drag_begin (GtkWidget *widget,
314 GdkDragContext *context);
315 static void gtk_notebook_drag_end (GtkWidget *widget,
316 GdkDragContext *context);
317 static gboolean gtk_notebook_drag_failed (GtkWidget *widget,
318 GdkDragContext *context,
319 GtkDragResult result,
321 static gboolean gtk_notebook_drag_motion (GtkWidget *widget,
322 GdkDragContext *context,
326 static void gtk_notebook_drag_leave (GtkWidget *widget,
327 GdkDragContext *context,
329 static gboolean gtk_notebook_drag_drop (GtkWidget *widget,
330 GdkDragContext *context,
334 static void gtk_notebook_drag_data_get (GtkWidget *widget,
335 GdkDragContext *context,
336 GtkSelectionData *data,
339 static void gtk_notebook_drag_data_received (GtkWidget *widget,
340 GdkDragContext *context,
343 GtkSelectionData *data,
347 /*** GtkContainer Methods ***/
348 static void gtk_notebook_set_child_property (GtkContainer *container,
353 static void gtk_notebook_get_child_property (GtkContainer *container,
358 static void gtk_notebook_add (GtkContainer *container,
360 static void gtk_notebook_remove (GtkContainer *container,
362 static void gtk_notebook_set_focus_child (GtkContainer *container,
364 static GType gtk_notebook_child_type (GtkContainer *container);
365 static void gtk_notebook_forall (GtkContainer *container,
366 gboolean include_internals,
367 GtkCallback callback,
368 gpointer callback_data);
370 /*** GtkNotebook Methods ***/
371 static gint gtk_notebook_real_insert_page (GtkNotebook *notebook,
373 GtkWidget *tab_label,
374 GtkWidget *menu_label,
377 static GtkNotebook *gtk_notebook_create_window (GtkNotebook *notebook,
382 /*** GtkNotebook Private Functions ***/
383 static void gtk_notebook_redraw_tabs (GtkNotebook *notebook);
384 static void gtk_notebook_redraw_arrows (GtkNotebook *notebook);
385 static void gtk_notebook_real_remove (GtkNotebook *notebook,
387 static void gtk_notebook_update_labels (GtkNotebook *notebook);
388 static gint gtk_notebook_timer (GtkNotebook *notebook);
389 static void gtk_notebook_set_scroll_timer (GtkNotebook *notebook);
390 static gint gtk_notebook_page_compare (gconstpointer a,
392 static GList* gtk_notebook_find_child (GtkNotebook *notebook,
394 const gchar *function);
395 static gint gtk_notebook_real_page_position (GtkNotebook *notebook,
397 static GList * gtk_notebook_search_page (GtkNotebook *notebook,
400 gboolean find_visible);
401 static void gtk_notebook_child_reordered (GtkNotebook *notebook,
402 GtkNotebookPage *page);
404 /*** GtkNotebook Drawing Functions ***/
405 static void gtk_notebook_paint (GtkWidget *widget,
407 static void gtk_notebook_draw_tab (GtkNotebook *notebook,
408 GtkNotebookPage *page,
410 static void gtk_notebook_draw_arrow (GtkNotebook *notebook,
411 GtkNotebookArrow arrow);
413 /*** GtkNotebook Size Allocate Functions ***/
414 static void gtk_notebook_pages_allocate (GtkNotebook *notebook);
415 static gboolean gtk_notebook_page_allocate (GtkNotebook *notebook,
416 GtkNotebookPage *page);
417 static void gtk_notebook_calc_tabs (GtkNotebook *notebook,
423 /*** GtkNotebook Page Switch Methods ***/
424 static void gtk_notebook_real_switch_page (GtkNotebook *notebook,
428 /*** GtkNotebook Page Switch Functions ***/
429 static void gtk_notebook_switch_page (GtkNotebook *notebook,
430 GtkNotebookPage *page);
431 static gint gtk_notebook_page_select (GtkNotebook *notebook,
432 gboolean move_focus);
433 static void gtk_notebook_switch_focus_tab (GtkNotebook *notebook,
435 static void gtk_notebook_menu_switch_page (GtkWidget *widget,
436 GtkNotebookPage *page);
438 /*** GtkNotebook Menu Functions ***/
439 static void gtk_notebook_menu_item_create (GtkNotebook *notebook,
441 static void gtk_notebook_menu_label_unparent (GtkWidget *widget,
443 static void gtk_notebook_menu_detacher (GtkWidget *widget,
446 /*** GtkNotebook Private Setters ***/
447 static void gtk_notebook_update_tab_states (GtkNotebook *notebook);
448 static gboolean gtk_notebook_mnemonic_activate_switch_page (GtkWidget *child,
452 static gboolean focus_tabs_in (GtkNotebook *notebook);
453 static gboolean focus_child_in (GtkNotebook *notebook,
454 GtkDirectionType direction);
456 static void stop_scrolling (GtkNotebook *notebook);
457 static void do_detach_tab (GtkNotebook *from,
464 static void gtk_notebook_buildable_init (GtkBuildableIface *iface);
465 static void gtk_notebook_buildable_add_child (GtkBuildable *buildable,
470 static GtkNotebookWindowCreationFunc window_creation_hook = NULL;
471 static gpointer window_creation_hook_data;
472 static GDestroyNotify window_creation_hook_destroy = NULL;
474 static guint notebook_signals[LAST_SIGNAL] = { 0 };
476 G_DEFINE_TYPE_WITH_CODE (GtkNotebook, gtk_notebook, GTK_TYPE_CONTAINER,
477 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
478 gtk_notebook_buildable_init))
481 add_tab_bindings (GtkBindingSet *binding_set,
482 GdkModifierType modifiers,
483 GtkDirectionType direction)
485 gtk_binding_entry_add_signal (binding_set, GDK_Tab, modifiers,
487 GTK_TYPE_DIRECTION_TYPE, direction);
488 gtk_binding_entry_add_signal (binding_set, GDK_KP_Tab, modifiers,
490 GTK_TYPE_DIRECTION_TYPE, direction);
494 add_arrow_bindings (GtkBindingSet *binding_set,
496 GtkDirectionType direction)
498 guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
500 gtk_binding_entry_add_signal (binding_set, keysym, GDK_CONTROL_MASK,
502 GTK_TYPE_DIRECTION_TYPE, direction);
503 gtk_binding_entry_add_signal (binding_set, keypad_keysym, GDK_CONTROL_MASK,
505 GTK_TYPE_DIRECTION_TYPE, direction);
509 add_reorder_bindings (GtkBindingSet *binding_set,
511 GtkDirectionType direction,
512 gboolean move_to_last)
514 guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
516 gtk_binding_entry_add_signal (binding_set, keysym, GDK_MOD1_MASK,
518 GTK_TYPE_DIRECTION_TYPE, direction,
519 G_TYPE_BOOLEAN, move_to_last);
520 gtk_binding_entry_add_signal (binding_set, keypad_keysym, GDK_MOD1_MASK,
522 GTK_TYPE_DIRECTION_TYPE, direction,
523 G_TYPE_BOOLEAN, move_to_last);
527 gtk_object_handled_accumulator (GSignalInvocationHint *ihint,
529 const GValue *handler_return,
532 gboolean continue_emission;
535 object = g_value_get_object (handler_return);
536 g_value_set_object (return_accu, object);
537 continue_emission = !object;
539 return continue_emission;
543 gtk_notebook_class_init (GtkNotebookClass *class)
545 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
546 GtkObjectClass *object_class = GTK_OBJECT_CLASS (class);
547 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
548 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
549 GtkBindingSet *binding_set;
551 gobject_class->set_property = gtk_notebook_set_property;
552 gobject_class->get_property = gtk_notebook_get_property;
553 object_class->destroy = gtk_notebook_destroy;
555 widget_class->map = gtk_notebook_map;
556 widget_class->unmap = gtk_notebook_unmap;
557 widget_class->realize = gtk_notebook_realize;
558 widget_class->unrealize = gtk_notebook_unrealize;
559 widget_class->size_request = gtk_notebook_size_request;
560 widget_class->size_allocate = gtk_notebook_size_allocate;
561 widget_class->expose_event = gtk_notebook_expose;
562 widget_class->scroll_event = gtk_notebook_scroll;
563 widget_class->button_press_event = gtk_notebook_button_press;
564 widget_class->button_release_event = gtk_notebook_button_release;
565 widget_class->popup_menu = gtk_notebook_popup_menu;
566 widget_class->leave_notify_event = gtk_notebook_leave_notify;
567 widget_class->motion_notify_event = gtk_notebook_motion_notify;
568 widget_class->grab_notify = gtk_notebook_grab_notify;
569 widget_class->state_changed = gtk_notebook_state_changed;
570 widget_class->focus_in_event = gtk_notebook_focus_in;
571 widget_class->focus_out_event = gtk_notebook_focus_out;
572 widget_class->focus = gtk_notebook_focus;
573 widget_class->style_set = gtk_notebook_style_set;
574 widget_class->drag_begin = gtk_notebook_drag_begin;
575 widget_class->drag_end = gtk_notebook_drag_end;
576 widget_class->drag_motion = gtk_notebook_drag_motion;
577 widget_class->drag_leave = gtk_notebook_drag_leave;
578 widget_class->drag_drop = gtk_notebook_drag_drop;
579 widget_class->drag_data_get = gtk_notebook_drag_data_get;
580 widget_class->drag_data_received = gtk_notebook_drag_data_received;
582 container_class->add = gtk_notebook_add;
583 container_class->remove = gtk_notebook_remove;
584 container_class->forall = gtk_notebook_forall;
585 container_class->set_focus_child = gtk_notebook_set_focus_child;
586 container_class->get_child_property = gtk_notebook_get_child_property;
587 container_class->set_child_property = gtk_notebook_set_child_property;
588 container_class->child_type = gtk_notebook_child_type;
590 class->switch_page = gtk_notebook_real_switch_page;
591 class->insert_page = gtk_notebook_real_insert_page;
593 class->focus_tab = gtk_notebook_focus_tab;
594 class->select_page = gtk_notebook_select_page;
595 class->change_current_page = gtk_notebook_change_current_page;
596 class->move_focus_out = gtk_notebook_move_focus_out;
597 class->reorder_tab = gtk_notebook_reorder_tab;
598 class->create_window = gtk_notebook_create_window;
600 g_object_class_install_property (gobject_class,
602 g_param_spec_int ("page",
604 P_("The index of the current page"),
608 GTK_PARAM_READWRITE));
609 g_object_class_install_property (gobject_class,
611 g_param_spec_enum ("tab-pos",
613 P_("Which side of the notebook holds the tabs"),
614 GTK_TYPE_POSITION_TYPE,
616 GTK_PARAM_READWRITE));
617 g_object_class_install_property (gobject_class,
619 g_param_spec_boolean ("show-tabs",
621 P_("Whether tabs should be shown or not"),
623 GTK_PARAM_READWRITE));
624 g_object_class_install_property (gobject_class,
626 g_param_spec_boolean ("show-border",
628 P_("Whether the border should be shown or not"),
630 GTK_PARAM_READWRITE));
631 g_object_class_install_property (gobject_class,
633 g_param_spec_boolean ("scrollable",
635 P_("If TRUE, scroll arrows are added if there are too many tabs to fit"),
637 GTK_PARAM_READWRITE));
638 g_object_class_install_property (gobject_class,
640 g_param_spec_boolean ("enable-popup",
642 P_("If TRUE, pressing the right mouse button on the notebook pops up a menu that you can use to go to a page"),
644 GTK_PARAM_READWRITE));
649 * Group for tabs drag and drop.
653 g_object_class_install_property (gobject_class,
655 g_param_spec_pointer ("group",
657 P_("Group for tabs drag and drop"),
658 GTK_PARAM_READWRITE));
660 gtk_container_class_install_child_property (container_class,
661 CHILD_PROP_TAB_LABEL,
662 g_param_spec_string ("tab-label",
664 P_("The string displayed on the child's tab label"),
666 GTK_PARAM_READWRITE));
667 gtk_container_class_install_child_property (container_class,
668 CHILD_PROP_MENU_LABEL,
669 g_param_spec_string ("menu-label",
671 P_("The string displayed in the child's menu entry"),
673 GTK_PARAM_READWRITE));
674 gtk_container_class_install_child_property (container_class,
676 g_param_spec_int ("position",
678 P_("The index of the child in the parent"),
680 GTK_PARAM_READWRITE));
681 gtk_container_class_install_child_property (container_class,
682 CHILD_PROP_TAB_EXPAND,
683 g_param_spec_boolean ("tab-expand",
685 P_("Whether to expand the child's tab or not"),
687 GTK_PARAM_READWRITE));
688 gtk_container_class_install_child_property (container_class,
690 g_param_spec_boolean ("tab-fill",
692 P_("Whether the child's tab should fill the allocated area or not"),
694 GTK_PARAM_READWRITE));
695 gtk_container_class_install_child_property (container_class,
697 g_param_spec_enum ("tab-pack",
699 P_("A GtkPackType indicating whether the child is packed with reference to the start or end of the parent"),
700 GTK_TYPE_PACK_TYPE, GTK_PACK_START,
701 GTK_PARAM_READWRITE));
702 gtk_container_class_install_child_property (container_class,
703 CHILD_PROP_REORDERABLE,
704 g_param_spec_boolean ("reorderable",
705 P_("Tab reorderable"),
706 P_("Whether the tab is reorderable by user action or not"),
708 GTK_PARAM_READWRITE));
709 gtk_container_class_install_child_property (container_class,
710 CHILD_PROP_DETACHABLE,
711 g_param_spec_boolean ("detachable",
712 P_("Tab detachable"),
713 P_("Whether the tab is detachable"),
715 GTK_PARAM_READWRITE));
718 * GtkNotebook:has-secondary-backward-stepper:
720 * The "has-secondary-backward-stepper" property determines whether
721 * a second backward arrow button is displayed on the opposite end
726 gtk_widget_class_install_style_property (widget_class,
727 g_param_spec_boolean ("has-secondary-backward-stepper",
728 P_("Secondary backward stepper"),
729 P_("Display a second backward arrow button on the opposite end of the tab area"),
731 GTK_PARAM_READABLE));
734 * GtkNotebook:has-secondary-forward-stepper:
736 * The "has-secondary-forward-stepper" property determines whether
737 * a second forward arrow button is displayed on the opposite end
742 gtk_widget_class_install_style_property (widget_class,
743 g_param_spec_boolean ("has-secondary-forward-stepper",
744 P_("Secondary forward stepper"),
745 P_("Display a second forward arrow button on the opposite end of the tab area"),
747 GTK_PARAM_READABLE));
750 * GtkNotebook:has-backward-stepper:
752 * The "has-backward-stepper" property determines whether
753 * the standard backward arrow button is displayed.
757 gtk_widget_class_install_style_property (widget_class,
758 g_param_spec_boolean ("has-backward-stepper",
759 P_("Backward stepper"),
760 P_("Display the standard backward arrow button"),
762 GTK_PARAM_READABLE));
765 * GtkNotebook:has-forward-stepper:
767 * The "has-forward-stepper" property determines whether
768 * the standard forward arrow button is displayed.
772 gtk_widget_class_install_style_property (widget_class,
773 g_param_spec_boolean ("has-forward-stepper",
774 P_("Forward stepper"),
775 P_("Display the standard forward arrow button"),
777 GTK_PARAM_READABLE));
780 * GtkNotebook:tab-overlap:
782 * The "tab-overlap" property defines size of tab overlap
787 gtk_widget_class_install_style_property (widget_class,
788 g_param_spec_int ("tab-overlap",
790 P_("Size of tab overlap area"),
794 GTK_PARAM_READABLE));
797 * GtkNotebook:tab-curvature:
799 * The "tab-curvature" property defines size of tab curvature.
803 gtk_widget_class_install_style_property (widget_class,
804 g_param_spec_int ("tab-curvature",
806 P_("Size of tab curvature"),
810 GTK_PARAM_READABLE));
813 * GtkNotebook:arrow-spacing:
815 * The "arrow-spacing" property defines the spacing between the scroll
816 * arrows and the tabs.
820 gtk_widget_class_install_style_property (widget_class,
821 g_param_spec_int ("arrow-spacing",
823 P_("Scroll arrow spacing"),
827 GTK_PARAM_READABLE));
829 notebook_signals[SWITCH_PAGE] =
830 g_signal_new (I_("switch-page"),
831 G_TYPE_FROM_CLASS (gobject_class),
833 G_STRUCT_OFFSET (GtkNotebookClass, switch_page),
835 _gtk_marshal_VOID__POINTER_UINT,
839 notebook_signals[FOCUS_TAB] =
840 g_signal_new (I_("focus-tab"),
841 G_TYPE_FROM_CLASS (gobject_class),
842 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
843 G_STRUCT_OFFSET (GtkNotebookClass, focus_tab),
845 _gtk_marshal_BOOLEAN__ENUM,
847 GTK_TYPE_NOTEBOOK_TAB);
848 notebook_signals[SELECT_PAGE] =
849 g_signal_new (I_("select-page"),
850 G_TYPE_FROM_CLASS (gobject_class),
851 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
852 G_STRUCT_OFFSET (GtkNotebookClass, select_page),
854 _gtk_marshal_BOOLEAN__BOOLEAN,
857 notebook_signals[CHANGE_CURRENT_PAGE] =
858 g_signal_new (I_("change-current-page"),
859 G_TYPE_FROM_CLASS (gobject_class),
860 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
861 G_STRUCT_OFFSET (GtkNotebookClass, change_current_page),
863 _gtk_marshal_BOOLEAN__INT,
866 notebook_signals[MOVE_FOCUS_OUT] =
867 g_signal_new (I_("move-focus-out"),
868 G_TYPE_FROM_CLASS (gobject_class),
869 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
870 G_STRUCT_OFFSET (GtkNotebookClass, move_focus_out),
872 _gtk_marshal_VOID__ENUM,
874 GTK_TYPE_DIRECTION_TYPE);
875 notebook_signals[REORDER_TAB] =
876 g_signal_new (I_("reorder-tab"),
877 G_TYPE_FROM_CLASS (gobject_class),
878 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
879 G_STRUCT_OFFSET (GtkNotebookClass, reorder_tab),
881 _gtk_marshal_BOOLEAN__ENUM_BOOLEAN,
883 GTK_TYPE_DIRECTION_TYPE,
886 * GtkNotebook::page-reordered:
887 * @notebook: the #GtkNotebook
888 * @child: the child #GtkWidget affected
889 * @page_num: the new page number for @child
891 * the ::page-reordered signal is emitted in the notebook
892 * right after a page has been reordered.
896 notebook_signals[PAGE_REORDERED] =
897 g_signal_new (I_("page-reordered"),
898 G_TYPE_FROM_CLASS (gobject_class),
901 _gtk_marshal_VOID__OBJECT_UINT,
906 * GtkNotebook::page-removed:
907 * @notebook: the #GtkNotebook
908 * @child: the child #GtkWidget affected
909 * @page_num: the @child page number
911 * the ::page-removed signal is emitted in the notebook
912 * right after a page is removed from the notebook.
916 notebook_signals[PAGE_REMOVED] =
917 g_signal_new (I_("page-removed"),
918 G_TYPE_FROM_CLASS (gobject_class),
921 _gtk_marshal_VOID__OBJECT_UINT,
926 * GtkNotebook::page-added:
927 * @notebook: the #GtkNotebook
928 * @child: the child #GtkWidget affected
929 * @page_num: the new page number for @child
931 * the ::page-added signal is emitted in the notebook
932 * right after a page is added to the notebook.
936 notebook_signals[PAGE_ADDED] =
937 g_signal_new (I_("page-added"),
938 G_TYPE_FROM_CLASS (gobject_class),
941 _gtk_marshal_VOID__OBJECT_UINT,
947 * GtkNotebook::create-window:
948 * @notebook: the #GtkNotebook emitting the signal
949 * @page: the tab of @notebook that is being detached
950 * @x: the X coordinate where the drop happens
951 * @y: the Y coordinate where the drop happens
953 * The ::create-window signal is emitted when a detachable
954 * tab is dropped on the root window.
956 * A handler for this signal can create a window containing
957 * a notebook where the tab will be attached. It is also
958 * responsible for moving/resizing the window and adding the
959 * necessary properties to the notebook (e.g. the
960 * #GtkNotebook:group ).
962 * The default handler uses the global window creation hook,
963 * if one has been set with gtk_notebook_set_window_creation_hook().
965 * Returns: a #GtkNotebook that @page should be added to, or %NULL.
969 notebook_signals[CREATE_WINDOW] =
970 g_signal_new (I_("create-window"),
971 G_TYPE_FROM_CLASS (gobject_class),
973 G_STRUCT_OFFSET (GtkNotebookClass, create_window),
974 gtk_object_handled_accumulator, NULL,
975 _gtk_marshal_OBJECT__OBJECT_INT_INT,
976 GTK_TYPE_NOTEBOOK, 3,
977 GTK_TYPE_WIDGET, G_TYPE_INT, G_TYPE_INT);
979 binding_set = gtk_binding_set_by_class (class);
980 gtk_binding_entry_add_signal (binding_set,
983 G_TYPE_BOOLEAN, FALSE);
984 gtk_binding_entry_add_signal (binding_set,
987 G_TYPE_BOOLEAN, FALSE);
989 gtk_binding_entry_add_signal (binding_set,
992 GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_FIRST);
993 gtk_binding_entry_add_signal (binding_set,
996 GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_FIRST);
997 gtk_binding_entry_add_signal (binding_set,
1000 GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_LAST);
1001 gtk_binding_entry_add_signal (binding_set,
1004 GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_LAST);
1006 gtk_binding_entry_add_signal (binding_set,
1007 GDK_Page_Up, GDK_CONTROL_MASK,
1008 "change-current-page", 1,
1010 gtk_binding_entry_add_signal (binding_set,
1011 GDK_Page_Down, GDK_CONTROL_MASK,
1012 "change-current-page", 1,
1015 gtk_binding_entry_add_signal (binding_set,
1016 GDK_Page_Up, GDK_CONTROL_MASK | GDK_MOD1_MASK,
1017 "change-current-page", 1,
1019 gtk_binding_entry_add_signal (binding_set,
1020 GDK_Page_Down, GDK_CONTROL_MASK | GDK_MOD1_MASK,
1021 "change-current-page", 1,
1024 add_arrow_bindings (binding_set, GDK_Up, GTK_DIR_UP);
1025 add_arrow_bindings (binding_set, GDK_Down, GTK_DIR_DOWN);
1026 add_arrow_bindings (binding_set, GDK_Left, GTK_DIR_LEFT);
1027 add_arrow_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT);
1029 add_reorder_bindings (binding_set, GDK_Up, GTK_DIR_UP, FALSE);
1030 add_reorder_bindings (binding_set, GDK_Down, GTK_DIR_DOWN, FALSE);
1031 add_reorder_bindings (binding_set, GDK_Left, GTK_DIR_LEFT, FALSE);
1032 add_reorder_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT, FALSE);
1033 add_reorder_bindings (binding_set, GDK_Home, GTK_DIR_LEFT, TRUE);
1034 add_reorder_bindings (binding_set, GDK_Home, GTK_DIR_UP, TRUE);
1035 add_reorder_bindings (binding_set, GDK_End, GTK_DIR_RIGHT, TRUE);
1036 add_reorder_bindings (binding_set, GDK_End, GTK_DIR_DOWN, TRUE);
1038 add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
1039 add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
1041 g_type_class_add_private (class, sizeof (GtkNotebookPriv));
1045 gtk_notebook_init (GtkNotebook *notebook)
1047 GtkNotebookPriv *priv;
1049 gtk_widget_set_can_focus (GTK_WIDGET (notebook), TRUE);
1050 gtk_widget_set_has_window (GTK_WIDGET (notebook), FALSE);
1052 notebook->priv = G_TYPE_INSTANCE_GET_PRIVATE (notebook,
1055 priv = notebook->priv;
1057 priv->cur_page = NULL;
1058 priv->children = NULL;
1059 priv->first_tab = NULL;
1060 priv->focus_tab = NULL;
1061 priv->event_window = NULL;
1064 priv->tab_hborder = 2;
1065 priv->tab_vborder = 2;
1067 priv->show_tabs = TRUE;
1068 priv->show_border = TRUE;
1069 priv->tab_pos = GTK_POS_TOP;
1070 priv->scrollable = FALSE;
1072 priv->click_child = 0;
1074 priv->need_timer = 0;
1075 priv->child_has_focus = FALSE;
1076 priv->have_visible_child = FALSE;
1077 priv->focus_out = FALSE;
1079 priv->has_before_previous = 1;
1080 priv->has_before_next = 0;
1081 priv->has_after_previous = 0;
1082 priv->has_after_next = 1;
1085 priv->pressed_button = -1;
1086 priv->dnd_timer = 0;
1087 priv->switch_tab_timer = 0;
1088 priv->source_targets = gtk_target_list_new (notebook_targets,
1089 G_N_ELEMENTS (notebook_targets));
1090 priv->operation = DRAG_OPERATION_NONE;
1091 priv->detached_tab = NULL;
1092 priv->during_detach = FALSE;
1093 priv->has_scrolled = FALSE;
1095 gtk_drag_dest_set (GTK_WIDGET (notebook), 0,
1096 notebook_targets, G_N_ELEMENTS (notebook_targets),
1099 g_signal_connect (G_OBJECT (notebook), "drag-failed",
1100 G_CALLBACK (gtk_notebook_drag_failed), NULL);
1102 gtk_drag_dest_set_track_motion (GTK_WIDGET (notebook), TRUE);
1106 gtk_notebook_buildable_init (GtkBuildableIface *iface)
1108 iface->add_child = gtk_notebook_buildable_add_child;
1112 gtk_notebook_buildable_add_child (GtkBuildable *buildable,
1113 GtkBuilder *builder,
1117 GtkNotebook *notebook = GTK_NOTEBOOK (buildable);
1119 if (type && strcmp (type, "tab") == 0)
1123 page = gtk_notebook_get_nth_page (notebook, -1);
1124 /* To set the tab label widget, we must have already a child
1125 * inside the tab container. */
1126 g_assert (page != NULL);
1127 gtk_notebook_set_tab_label (notebook, page, GTK_WIDGET (child));
1129 else if (type && strcmp (type, "action-start") == 0)
1131 gtk_notebook_set_action_widget (notebook, GTK_WIDGET (child), GTK_PACK_START);
1133 else if (type && strcmp (type, "action-end") == 0)
1135 gtk_notebook_set_action_widget (notebook, GTK_WIDGET (child), GTK_PACK_END);
1138 gtk_notebook_append_page (notebook, GTK_WIDGET (child), NULL);
1140 GTK_BUILDER_WARN_INVALID_CHILD_TYPE (notebook, type);
1144 gtk_notebook_select_page (GtkNotebook *notebook,
1145 gboolean move_focus)
1147 GtkNotebookPriv *priv = notebook->priv;
1149 if (gtk_widget_is_focus (GTK_WIDGET (notebook)) && priv->show_tabs)
1151 gtk_notebook_page_select (notebook, move_focus);
1159 gtk_notebook_focus_tab (GtkNotebook *notebook,
1160 GtkNotebookTab type)
1162 GtkNotebookPriv *priv = notebook->priv;
1165 if (gtk_widget_is_focus (GTK_WIDGET (notebook)) && priv->show_tabs)
1169 case GTK_NOTEBOOK_TAB_FIRST:
1170 list = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, TRUE);
1172 gtk_notebook_switch_focus_tab (notebook, list);
1174 case GTK_NOTEBOOK_TAB_LAST:
1175 list = gtk_notebook_search_page (notebook, NULL, STEP_PREV, TRUE);
1177 gtk_notebook_switch_focus_tab (notebook, list);
1188 gtk_notebook_change_current_page (GtkNotebook *notebook,
1191 GtkNotebookPriv *priv = notebook->priv;
1192 GList *current = NULL;
1194 if (!priv->show_tabs)
1198 current = g_list_find (priv->children, priv->cur_page);
1202 current = gtk_notebook_search_page (notebook, current,
1203 offset < 0 ? STEP_PREV : STEP_NEXT,
1208 gboolean wrap_around;
1210 g_object_get (gtk_widget_get_settings (GTK_WIDGET (notebook)),
1211 "gtk-keynav-wrap-around", &wrap_around,
1215 current = gtk_notebook_search_page (notebook, NULL,
1216 offset < 0 ? STEP_PREV : STEP_NEXT,
1222 offset += offset < 0 ? 1 : -1;
1226 gtk_notebook_switch_page (notebook, current->data);
1228 gtk_widget_error_bell (GTK_WIDGET (notebook));
1233 static GtkDirectionType
1234 get_effective_direction (GtkNotebook *notebook,
1235 GtkDirectionType direction)
1237 GtkNotebookPriv *priv = notebook->priv;
1239 /* Remap the directions into the effective direction it would be for a
1240 * GTK_POS_TOP notebook
1243 #define D(rest) GTK_DIR_##rest
1245 static const GtkDirectionType translate_direction[2][4][6] = {
1246 /* LEFT */ {{ D(TAB_FORWARD), D(TAB_BACKWARD), D(LEFT), D(RIGHT), D(UP), D(DOWN) },
1247 /* RIGHT */ { D(TAB_BACKWARD), D(TAB_FORWARD), D(LEFT), D(RIGHT), D(DOWN), D(UP) },
1248 /* TOP */ { D(TAB_FORWARD), D(TAB_BACKWARD), D(UP), D(DOWN), D(LEFT), D(RIGHT) },
1249 /* BOTTOM */ { D(TAB_BACKWARD), D(TAB_FORWARD), D(DOWN), D(UP), D(LEFT), D(RIGHT) }},
1250 /* LEFT */ {{ D(TAB_BACKWARD), D(TAB_FORWARD), D(LEFT), D(RIGHT), D(DOWN), D(UP) },
1251 /* RIGHT */ { D(TAB_FORWARD), D(TAB_BACKWARD), D(LEFT), D(RIGHT), D(UP), D(DOWN) },
1252 /* TOP */ { D(TAB_FORWARD), D(TAB_BACKWARD), D(UP), D(DOWN), D(RIGHT), D(LEFT) },
1253 /* BOTTOM */ { D(TAB_BACKWARD), D(TAB_FORWARD), D(DOWN), D(UP), D(RIGHT), D(LEFT) }},
1258 int text_dir = gtk_widget_get_direction (GTK_WIDGET (notebook)) == GTK_TEXT_DIR_RTL ? 1 : 0;
1260 return translate_direction[text_dir][priv->tab_pos][direction];
1264 get_effective_tab_pos (GtkNotebook *notebook)
1266 GtkNotebookPriv *priv = notebook->priv;
1268 if (gtk_widget_get_direction (GTK_WIDGET (notebook)) == GTK_TEXT_DIR_RTL)
1270 switch (priv->tab_pos)
1273 return GTK_POS_RIGHT;
1275 return GTK_POS_LEFT;
1280 return priv->tab_pos;
1284 get_tab_gap_pos (GtkNotebook *notebook)
1286 gint tab_pos = get_effective_tab_pos (notebook);
1287 gint gap_side = GTK_POS_BOTTOM;
1292 gap_side = GTK_POS_BOTTOM;
1294 case GTK_POS_BOTTOM:
1295 gap_side = GTK_POS_TOP;
1298 gap_side = GTK_POS_RIGHT;
1301 gap_side = GTK_POS_LEFT;
1309 gtk_notebook_move_focus_out (GtkNotebook *notebook,
1310 GtkDirectionType direction_type)
1312 GtkNotebookPriv *priv = notebook->priv;
1313 GtkDirectionType effective_direction = get_effective_direction (notebook, direction_type);
1314 GtkWidget *toplevel;
1316 if (gtk_container_get_focus_child (GTK_CONTAINER (notebook)) && effective_direction == GTK_DIR_UP)
1317 if (focus_tabs_in (notebook))
1319 if (gtk_widget_is_focus (GTK_WIDGET (notebook)) && effective_direction == GTK_DIR_DOWN)
1320 if (focus_child_in (notebook, GTK_DIR_TAB_FORWARD))
1323 /* At this point, we know we should be focusing out of the notebook entirely. We
1324 * do this by setting a flag, then propagating the focus motion to the notebook.
1326 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (notebook));
1327 if (!gtk_widget_is_toplevel (toplevel))
1330 g_object_ref (notebook);
1332 priv->focus_out = TRUE;
1333 g_signal_emit_by_name (toplevel, "move-focus", direction_type);
1334 priv->focus_out = FALSE;
1336 g_object_unref (notebook);
1340 reorder_tab (GtkNotebook *notebook, GList *position, GList *tab)
1342 GtkNotebookPriv *priv = notebook->priv;
1345 if (position == tab)
1346 return g_list_position (priv->children, tab);
1348 /* check that we aren't inserting the tab in the
1349 * same relative position, taking packing into account */
1350 elem = (position) ? position->prev : g_list_last (priv->children);
1352 while (elem && elem != tab && GTK_NOTEBOOK_PAGE (elem)->pack != GTK_NOTEBOOK_PAGE (tab)->pack)
1356 return g_list_position (priv->children, tab);
1358 /* now actually reorder the tab */
1359 if (priv->first_tab == tab)
1360 priv->first_tab = gtk_notebook_search_page (notebook, priv->first_tab,
1363 priv->children = g_list_remove_link (priv->children, tab);
1366 elem = g_list_last (priv->children);
1369 elem = position->prev;
1370 position->prev = tab;
1376 priv->children = tab;
1379 tab->next = position;
1381 return g_list_position (priv->children, tab);
1385 gtk_notebook_reorder_tab (GtkNotebook *notebook,
1386 GtkDirectionType direction_type,
1387 gboolean move_to_last)
1389 GtkNotebookPriv *priv = notebook->priv;
1390 GtkDirectionType effective_direction = get_effective_direction (notebook, direction_type);
1391 GtkNotebookPage *page;
1392 GList *last, *child;
1395 if (!gtk_widget_is_focus (GTK_WIDGET (notebook)) || !priv->show_tabs)
1398 if (!priv->cur_page ||
1399 !priv->cur_page->reorderable)
1402 if (effective_direction != GTK_DIR_LEFT &&
1403 effective_direction != GTK_DIR_RIGHT)
1408 child = priv->focus_tab;
1413 child = gtk_notebook_search_page (notebook, last,
1414 (effective_direction == GTK_DIR_RIGHT) ? STEP_NEXT : STEP_PREV,
1417 while (child && GTK_NOTEBOOK_PAGE (last)->pack == GTK_NOTEBOOK_PAGE (child)->pack);
1422 child = gtk_notebook_search_page (notebook, priv->focus_tab,
1423 (effective_direction == GTK_DIR_RIGHT) ? STEP_NEXT : STEP_PREV,
1426 if (!child || child->data == priv->cur_page)
1431 if (page->pack == priv->cur_page->pack)
1433 if (effective_direction == GTK_DIR_RIGHT)
1434 page_num = reorder_tab (notebook, (page->pack == GTK_PACK_START) ? child->next : child, priv->focus_tab);
1436 page_num = reorder_tab (notebook, (page->pack == GTK_PACK_START) ? child : child->next, priv->focus_tab);
1438 gtk_notebook_pages_allocate (notebook);
1440 g_signal_emit (notebook,
1441 notebook_signals[PAGE_REORDERED],
1443 ((GtkNotebookPage *) priv->focus_tab->data)->child,
1455 * Creates a new #GtkNotebook widget with no pages.
1457 * Return value: the newly created #GtkNotebook
1460 gtk_notebook_new (void)
1462 return g_object_new (GTK_TYPE_NOTEBOOK, NULL);
1465 /* Private GtkObject Methods :
1467 * gtk_notebook_destroy
1468 * gtk_notebook_set_arg
1469 * gtk_notebook_get_arg
1472 gtk_notebook_destroy (GtkObject *object)
1474 GtkNotebook *notebook = GTK_NOTEBOOK (object);
1475 GtkNotebookPriv *priv = notebook->priv;
1478 gtk_notebook_popup_disable (notebook);
1480 if (priv->source_targets)
1482 gtk_target_list_unref (priv->source_targets);
1483 priv->source_targets = NULL;
1486 if (priv->switch_tab_timer)
1488 g_source_remove (priv->switch_tab_timer);
1489 priv->switch_tab_timer = 0;
1492 GTK_OBJECT_CLASS (gtk_notebook_parent_class)->destroy (object);
1496 gtk_notebook_set_property (GObject *object,
1498 const GValue *value,
1501 GtkNotebook *notebook;
1503 notebook = GTK_NOTEBOOK (object);
1507 case PROP_SHOW_TABS:
1508 gtk_notebook_set_show_tabs (notebook, g_value_get_boolean (value));
1510 case PROP_SHOW_BORDER:
1511 gtk_notebook_set_show_border (notebook, g_value_get_boolean (value));
1513 case PROP_SCROLLABLE:
1514 gtk_notebook_set_scrollable (notebook, g_value_get_boolean (value));
1516 case PROP_ENABLE_POPUP:
1517 if (g_value_get_boolean (value))
1518 gtk_notebook_popup_enable (notebook);
1520 gtk_notebook_popup_disable (notebook);
1523 gtk_notebook_set_current_page (notebook, g_value_get_int (value));
1526 gtk_notebook_set_tab_pos (notebook, g_value_get_enum (value));
1529 gtk_notebook_set_group (notebook, g_value_get_pointer (value));
1532 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1538 gtk_notebook_get_property (GObject *object,
1543 GtkNotebook *notebook = GTK_NOTEBOOK (object);
1544 GtkNotebookPriv *priv = notebook->priv;
1548 case PROP_SHOW_TABS:
1549 g_value_set_boolean (value, priv->show_tabs);
1551 case PROP_SHOW_BORDER:
1552 g_value_set_boolean (value, priv->show_border);
1554 case PROP_SCROLLABLE:
1555 g_value_set_boolean (value, priv->scrollable);
1557 case PROP_ENABLE_POPUP:
1558 g_value_set_boolean (value, priv->menu != NULL);
1561 g_value_set_int (value, gtk_notebook_get_current_page (notebook));
1564 g_value_set_enum (value, priv->tab_pos);
1567 g_value_set_pointer (value, priv->group);
1570 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1575 /* Private GtkWidget Methods :
1578 * gtk_notebook_unmap
1579 * gtk_notebook_realize
1580 * gtk_notebook_size_request
1581 * gtk_notebook_size_allocate
1582 * gtk_notebook_expose
1583 * gtk_notebook_scroll
1584 * gtk_notebook_button_press
1585 * gtk_notebook_button_release
1586 * gtk_notebook_popup_menu
1587 * gtk_notebook_leave_notify
1588 * gtk_notebook_motion_notify
1589 * gtk_notebook_focus_in
1590 * gtk_notebook_focus_out
1591 * gtk_notebook_draw_focus
1592 * gtk_notebook_style_set
1593 * gtk_notebook_drag_begin
1594 * gtk_notebook_drag_end
1595 * gtk_notebook_drag_failed
1596 * gtk_notebook_drag_motion
1597 * gtk_notebook_drag_drop
1598 * gtk_notebook_drag_data_get
1599 * gtk_notebook_drag_data_received
1602 gtk_notebook_get_event_window_position (GtkNotebook *notebook,
1603 GdkRectangle *rectangle)
1605 GtkNotebookPriv *priv = notebook->priv;
1606 GtkWidget *widget = GTK_WIDGET (notebook);
1607 guint border_width = gtk_container_get_border_width (GTK_CONTAINER (notebook));
1608 GtkNotebookPage *visible_page = NULL;
1610 gint tab_pos = get_effective_tab_pos (notebook);
1614 for (tmp_list = priv->children; tmp_list; tmp_list = tmp_list->next)
1616 GtkNotebookPage *page = tmp_list->data;
1617 if (gtk_widget_get_visible (page->child))
1619 visible_page = page;
1624 if (priv->show_tabs && visible_page)
1628 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
1629 rectangle->x = widget->allocation.x + border_width;
1630 rectangle->y = widget->allocation.y + border_width;
1635 case GTK_POS_BOTTOM:
1636 rectangle->width = widget->allocation.width - 2 * border_width;
1637 rectangle->height = visible_page->requisition.height;
1638 if (tab_pos == GTK_POS_BOTTOM)
1639 rectangle->y += widget->allocation.height - 2 * border_width - rectangle->height;
1641 for (i = 0; i < N_ACTION_WIDGETS; i++)
1643 if (priv->action_widget[i] &&
1644 gtk_widget_get_visible (priv->action_widget[i]))
1646 rectangle->width -= priv->action_widget[i]->allocation.width;
1647 if ((!is_rtl && i == ACTION_WIDGET_START) ||
1648 (is_rtl && i == ACTION_WIDGET_END))
1649 rectangle->x += priv->action_widget[i]->allocation.width;
1655 rectangle->width = visible_page->requisition.width;
1656 rectangle->height = widget->allocation.height - 2 * border_width;
1657 if (tab_pos == GTK_POS_RIGHT)
1658 rectangle->x += widget->allocation.width - 2 * border_width - rectangle->width;
1660 for (i = 0; i < N_ACTION_WIDGETS; i++)
1662 if (priv->action_widget[i] &&
1663 gtk_widget_get_visible (priv->action_widget[i]))
1665 rectangle->height -= priv->action_widget[i]->allocation.height;
1667 if (i == ACTION_WIDGET_START)
1668 rectangle->y += priv->action_widget[i]->allocation.height;
1681 rectangle->x = rectangle->y = 0;
1682 rectangle->width = rectangle->height = 10;
1690 gtk_notebook_map (GtkWidget *widget)
1692 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
1693 GtkNotebookPriv *priv = notebook->priv;
1694 GtkNotebookPage *page;
1698 gtk_widget_set_mapped (widget, TRUE);
1700 if (priv->cur_page &&
1701 gtk_widget_get_visible (priv->cur_page->child) &&
1702 !gtk_widget_get_mapped (priv->cur_page->child))
1703 gtk_widget_map (priv->cur_page->child);
1705 for (i = 0; i < N_ACTION_WIDGETS; i++)
1707 if (priv->action_widget[i] &&
1708 gtk_widget_get_visible (priv->action_widget[i]) &&
1709 GTK_WIDGET_CHILD_VISIBLE (priv->action_widget[i]) &&
1710 !gtk_widget_get_mapped (priv->action_widget[i]))
1711 gtk_widget_map (priv->action_widget[i]);
1714 if (priv->scrollable)
1715 gtk_notebook_pages_allocate (notebook);
1718 children = priv->children;
1722 page = children->data;
1723 children = children->next;
1725 if (page->tab_label &&
1726 gtk_widget_get_visible (page->tab_label) &&
1727 !gtk_widget_get_mapped (page->tab_label))
1728 gtk_widget_map (page->tab_label);
1732 if (gtk_notebook_get_event_window_position (notebook, NULL))
1733 gdk_window_show_unraised (priv->event_window);
1737 gtk_notebook_unmap (GtkWidget *widget)
1739 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
1740 GtkNotebookPriv *priv = notebook->priv;
1742 stop_scrolling (notebook);
1744 gtk_widget_set_mapped (widget, FALSE);
1746 gdk_window_hide (priv->event_window);
1748 GTK_WIDGET_CLASS (gtk_notebook_parent_class)->unmap (widget);
1752 gtk_notebook_realize (GtkWidget *widget)
1754 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
1755 GtkNotebookPriv *priv = notebook->priv;
1756 GdkWindowAttr attributes;
1757 gint attributes_mask;
1758 GdkRectangle event_window_pos;
1760 gtk_widget_set_realized (widget, TRUE);
1762 gtk_notebook_get_event_window_position (notebook, &event_window_pos);
1764 widget->window = gtk_widget_get_parent_window (widget);
1765 g_object_ref (widget->window);
1767 attributes.window_type = GDK_WINDOW_CHILD;
1768 attributes.x = event_window_pos.x;
1769 attributes.y = event_window_pos.y;
1770 attributes.width = event_window_pos.width;
1771 attributes.height = event_window_pos.height;
1772 attributes.wclass = GDK_INPUT_ONLY;
1773 attributes.event_mask = gtk_widget_get_events (widget);
1774 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
1775 GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK |
1776 GDK_POINTER_MOTION_MASK | GDK_LEAVE_NOTIFY_MASK |
1778 attributes_mask = GDK_WA_X | GDK_WA_Y;
1780 priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
1781 &attributes, attributes_mask);
1782 gdk_window_set_user_data (priv->event_window, notebook);
1784 widget->style = gtk_style_attach (widget->style, widget->window);
1788 gtk_notebook_unrealize (GtkWidget *widget)
1790 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
1791 GtkNotebookPriv *priv = notebook->priv;
1793 gdk_window_set_user_data (priv->event_window, NULL);
1794 gdk_window_destroy (priv->event_window);
1795 priv->event_window = NULL;
1797 if (priv->drag_window)
1799 gdk_window_set_user_data (priv->drag_window, NULL);
1800 gdk_window_destroy (priv->drag_window);
1801 priv->drag_window = NULL;
1804 GTK_WIDGET_CLASS (gtk_notebook_parent_class)->unrealize (widget);
1808 gtk_notebook_size_request (GtkWidget *widget,
1809 GtkRequisition *requisition)
1811 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
1812 GtkNotebookPriv *priv = notebook->priv;
1813 GtkNotebookPage *page;
1815 GtkRequisition child_requisition;
1816 GtkRequisition action_widget_requisition[2] = { { 0 }, { 0 } };
1817 gboolean switch_page = FALSE;
1823 gint scroll_arrow_hlength;
1824 gint scroll_arrow_vlength;
1827 gtk_widget_style_get (widget,
1828 "focus-line-width", &focus_width,
1829 "tab-overlap", &tab_overlap,
1830 "tab-curvature", &tab_curvature,
1831 "arrow-spacing", &arrow_spacing,
1832 "scroll-arrow-hlength", &scroll_arrow_hlength,
1833 "scroll-arrow-vlength", &scroll_arrow_vlength,
1836 widget->requisition.width = 0;
1837 widget->requisition.height = 0;
1839 for (children = priv->children, vis_pages = 0; children;
1840 children = children->next)
1842 page = children->data;
1844 if (gtk_widget_get_visible (page->child))
1847 gtk_widget_size_request (page->child, &child_requisition);
1849 widget->requisition.width = MAX (widget->requisition.width,
1850 child_requisition.width);
1851 widget->requisition.height = MAX (widget->requisition.height,
1852 child_requisition.height);
1854 if (priv->menu && page->menu_label->parent &&
1855 !gtk_widget_get_visible (page->menu_label->parent))
1856 gtk_widget_show (page->menu_label->parent);
1860 if (page == priv->cur_page)
1862 if (priv->menu && page->menu_label->parent &&
1863 gtk_widget_get_visible (page->menu_label->parent))
1864 gtk_widget_hide (page->menu_label->parent);
1868 if (priv->show_border || priv->show_tabs)
1870 widget->requisition.width += widget->style->xthickness * 2;
1871 widget->requisition.height += widget->style->ythickness * 2;
1873 if (priv->show_tabs)
1876 gint tab_height = 0;
1880 gint action_width = 0;
1881 gint action_height = 0;
1883 for (children = priv->children; children;
1884 children = children->next)
1886 page = children->data;
1888 if (gtk_widget_get_visible (page->child))
1890 if (!gtk_widget_get_visible (page->tab_label))
1891 gtk_widget_show (page->tab_label);
1893 gtk_widget_size_request (page->tab_label,
1894 &child_requisition);
1896 page->requisition.width =
1897 child_requisition.width +
1898 2 * widget->style->xthickness;
1899 page->requisition.height =
1900 child_requisition.height +
1901 2 * widget->style->ythickness;
1903 switch (priv->tab_pos)
1906 case GTK_POS_BOTTOM:
1907 page->requisition.height += 2 * (priv->tab_vborder +
1909 tab_height = MAX (tab_height, page->requisition.height);
1910 tab_max = MAX (tab_max, page->requisition.width);
1914 page->requisition.width += 2 * (priv->tab_hborder +
1916 tab_width = MAX (tab_width, page->requisition.width);
1917 tab_max = MAX (tab_max, page->requisition.height);
1921 else if (gtk_widget_get_visible (page->tab_label))
1922 gtk_widget_hide (page->tab_label);
1925 children = priv->children;
1929 for (i = 0; i < N_ACTION_WIDGETS; i++)
1931 if (priv->action_widget[i])
1933 gtk_widget_size_request (priv->action_widget[i], &action_widget_requisition[i]);
1934 action_widget_requisition[i].width += widget->style->xthickness;
1935 action_widget_requisition[i].height += widget->style->ythickness;
1939 switch (priv->tab_pos)
1942 case GTK_POS_BOTTOM:
1943 if (tab_height == 0)
1946 if (priv->scrollable && vis_pages > 1 &&
1947 widget->requisition.width < tab_width)
1948 tab_height = MAX (tab_height, scroll_arrow_hlength);
1950 tab_height = MAX (tab_height, action_widget_requisition[ACTION_WIDGET_START].height);
1951 tab_height = MAX (tab_height, action_widget_requisition[ACTION_WIDGET_END].height);
1953 padding = 2 * (tab_curvature + focus_width +
1954 priv->tab_hborder) - tab_overlap;
1958 page = children->data;
1959 children = children->next;
1961 if (!gtk_widget_get_visible (page->child))
1964 if (priv->homogeneous)
1965 page->requisition.width = tab_max;
1967 page->requisition.width += padding;
1969 tab_width += page->requisition.width;
1970 page->requisition.height = tab_height;
1973 if (priv->scrollable && vis_pages > 1 &&
1974 widget->requisition.width < tab_width)
1975 tab_width = tab_max + 2 * (scroll_arrow_hlength + arrow_spacing);
1977 action_width += action_widget_requisition[ACTION_WIDGET_START].width;
1978 action_width += action_widget_requisition[ACTION_WIDGET_END].width;
1979 if (priv->homogeneous && !priv->scrollable)
1980 widget->requisition.width = MAX (widget->requisition.width,
1981 vis_pages * tab_max +
1982 tab_overlap + action_width);
1984 widget->requisition.width = MAX (widget->requisition.width,
1985 tab_width + tab_overlap + action_width);
1987 widget->requisition.height += tab_height;
1994 if (priv->scrollable && vis_pages > 1 &&
1995 widget->requisition.height < tab_height)
1996 tab_width = MAX (tab_width,
1997 arrow_spacing + 2 * scroll_arrow_vlength);
1999 tab_width = MAX (tab_width, action_widget_requisition[ACTION_WIDGET_START].width);
2000 tab_width = MAX (tab_width, action_widget_requisition[ACTION_WIDGET_END].width);
2002 padding = 2 * (tab_curvature + focus_width +
2003 priv->tab_vborder) - tab_overlap;
2008 page = children->data;
2009 children = children->next;
2011 if (!gtk_widget_get_visible (page->child))
2014 page->requisition.width = tab_width;
2016 if (priv->homogeneous)
2017 page->requisition.height = tab_max;
2019 page->requisition.height += padding;
2021 tab_height += page->requisition.height;
2024 if (priv->scrollable && vis_pages > 1 &&
2025 widget->requisition.height < tab_height)
2026 tab_height = tab_max + (2 * scroll_arrow_vlength + arrow_spacing);
2027 action_height += action_widget_requisition[ACTION_WIDGET_START].height;
2028 action_height += action_widget_requisition[ACTION_WIDGET_END].height;
2030 if (priv->homogeneous && !priv->scrollable)
2031 widget->requisition.height =
2032 MAX (widget->requisition.height,
2033 vis_pages * tab_max + tab_overlap + action_height);
2035 widget->requisition.height =
2036 MAX (widget->requisition.height,
2037 tab_height + tab_overlap + action_height);
2039 if (!priv->homogeneous || priv->scrollable)
2041 widget->requisition.height = MAX (widget->requisition.height,
2042 vis_pages * tab_max +
2045 widget->requisition.width += tab_width;
2052 for (children = priv->children; children;
2053 children = children->next)
2055 page = children->data;
2057 if (page->tab_label && gtk_widget_get_visible (page->tab_label))
2058 gtk_widget_hide (page->tab_label);
2063 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
2065 widget->requisition.width += border_width * 2;
2066 widget->requisition.height += border_width * 2;
2072 for (children = priv->children; children;
2073 children = children->next)
2075 page = children->data;
2076 if (gtk_widget_get_visible (page->child))
2078 gtk_notebook_switch_page (notebook, page);
2083 else if (gtk_widget_get_visible (widget))
2085 widget->requisition.width = border_width * 2;
2086 widget->requisition.height= border_width * 2;
2089 if (vis_pages && !priv->cur_page)
2091 children = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, TRUE);
2094 priv->first_tab = children;
2095 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (children));
2101 gtk_notebook_size_allocate (GtkWidget *widget,
2102 GtkAllocation *allocation)
2104 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2105 GtkNotebookPriv *priv = notebook->priv;
2106 gint tab_pos = get_effective_tab_pos (notebook);
2110 gtk_widget_style_get (widget, "focus-line-width", &focus_width, NULL);
2112 widget->allocation = *allocation;
2113 if (gtk_widget_get_realized (widget))
2115 GdkRectangle position;
2117 if (gtk_notebook_get_event_window_position (notebook, &position))
2119 gdk_window_move_resize (priv->event_window,
2120 position.x, position.y,
2121 position.width, position.height);
2122 if (gtk_widget_get_mapped (GTK_WIDGET (notebook)))
2123 gdk_window_show_unraised (priv->event_window);
2126 gdk_window_hide (priv->event_window);
2131 guint border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
2132 GtkNotebookPage *page;
2133 GtkAllocation child_allocation;
2137 child_allocation.x = widget->allocation.x + border_width;
2138 child_allocation.y = widget->allocation.y + border_width;
2139 child_allocation.width = MAX (1, allocation->width - border_width * 2);
2140 child_allocation.height = MAX (1, allocation->height - border_width * 2);
2142 if (priv->show_tabs || priv->show_border)
2144 child_allocation.x += widget->style->xthickness;
2145 child_allocation.y += widget->style->ythickness;
2146 child_allocation.width = MAX (1, child_allocation.width -
2147 widget->style->xthickness * 2);
2148 child_allocation.height = MAX (1, child_allocation.height -
2149 widget->style->ythickness * 2);
2151 if (priv->show_tabs && priv->children && priv->cur_page)
2156 child_allocation.y += priv->cur_page->requisition.height;
2157 case GTK_POS_BOTTOM:
2158 child_allocation.height =
2159 MAX (1, child_allocation.height -
2160 priv->cur_page->requisition.height);
2163 child_allocation.x += priv->cur_page->requisition.width;
2165 child_allocation.width =
2166 MAX (1, child_allocation.width -
2167 priv->cur_page->requisition.width);
2171 for (i = 0; i < N_ACTION_WIDGETS; i++)
2173 GtkAllocation widget_allocation;
2175 if (!priv->action_widget[i])
2178 widget_allocation.x = widget->allocation.x + border_width;
2179 widget_allocation.y = widget->allocation.y + border_width;
2180 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2184 case GTK_POS_BOTTOM:
2185 widget_allocation.y +=
2186 widget->allocation.height - 2 * border_width - priv->cur_page->requisition.height;
2189 widget_allocation.width = priv->action_widget[i]->requisition.width;
2190 widget_allocation.height = priv->cur_page->requisition.height - widget->style->ythickness;
2192 if ((i == ACTION_WIDGET_START && is_rtl) ||
2193 (i == ACTION_WIDGET_END && !is_rtl))
2194 widget_allocation.x +=
2195 widget->allocation.width - 2 * border_width -
2196 priv->action_widget[i]->requisition.width;
2197 if (tab_pos == GTK_POS_TOP) /* no fall through */
2198 widget_allocation.y += 2 * focus_width;
2201 widget_allocation.x +=
2202 widget->allocation.width - 2 * border_width - priv->cur_page->requisition.width;
2205 widget_allocation.height = priv->action_widget[i]->requisition.height;
2206 widget_allocation.width = priv->cur_page->requisition.width - widget->style->xthickness;
2208 if (i == ACTION_WIDGET_END)
2209 widget_allocation.y +=
2210 widget->allocation.height - 2 * border_width -
2211 priv->action_widget[i]->requisition.height;
2212 if (tab_pos == GTK_POS_LEFT) /* no fall through */
2213 widget_allocation.x += 2 * focus_width;
2217 gtk_widget_size_allocate (priv->action_widget[i], &widget_allocation);
2222 children = priv->children;
2225 page = children->data;
2226 children = children->next;
2228 if (gtk_widget_get_visible (page->child))
2229 gtk_widget_size_allocate (page->child, &child_allocation);
2232 gtk_notebook_pages_allocate (notebook);
2237 gtk_notebook_expose (GtkWidget *widget,
2238 GdkEventExpose *event)
2240 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2241 GtkNotebookPriv *priv = notebook->priv;
2244 if (event->window == priv->drag_window)
2246 GdkRectangle area = { 0, };
2249 /* FIXME: This is a workaround to make tabs reordering work better
2250 * with engines with rounded tabs. If the drag window background
2251 * isn't set, the rounded corners would be black.
2253 * Ideally, these corners should be made transparent, Either by using
2254 * ARGB visuals or shape windows.
2256 cr = gdk_cairo_create (priv->drag_window);
2257 gdk_cairo_set_source_color (cr, &widget->style->bg [GTK_STATE_NORMAL]);
2261 gdk_drawable_get_size (priv->drag_window,
2262 &area.width, &area.height);
2263 gtk_notebook_draw_tab (notebook,
2266 gtk_notebook_draw_focus (widget, event);
2267 gtk_container_propagate_expose (GTK_CONTAINER (notebook),
2268 priv->cur_page->tab_label, event);
2270 else if (gtk_widget_is_drawable (widget))
2272 gtk_notebook_paint (widget, &event->area);
2273 if (priv->show_tabs)
2275 GtkNotebookPage *page;
2278 gtk_notebook_draw_focus (widget, event);
2279 pages = priv->children;
2283 page = GTK_NOTEBOOK_PAGE (pages);
2284 pages = pages->next;
2286 if (page->tab_label->window == event->window &&
2287 gtk_widget_is_drawable (page->tab_label))
2288 gtk_container_propagate_expose (GTK_CONTAINER (notebook),
2289 page->tab_label, event);
2294 gtk_container_propagate_expose (GTK_CONTAINER (notebook),
2295 priv->cur_page->child,
2297 if (priv->show_tabs)
2299 for (i = 0; i < N_ACTION_WIDGETS; i++)
2301 if (priv->action_widget[i] &&
2302 gtk_widget_is_drawable (priv->action_widget[i]))
2303 gtk_container_propagate_expose (GTK_CONTAINER (notebook),
2304 priv->action_widget[i], event);
2313 gtk_notebook_show_arrows (GtkNotebook *notebook)
2315 GtkNotebookPriv *priv = notebook->priv;
2316 gboolean show_arrow = FALSE;
2319 if (!priv->scrollable)
2322 children = priv->children;
2325 GtkNotebookPage *page = children->data;
2327 if (page->tab_label && !gtk_widget_get_child_visible (page->tab_label))
2330 children = children->next;
2337 gtk_notebook_get_arrow_rect (GtkNotebook *notebook,
2338 GdkRectangle *rectangle,
2339 GtkNotebookArrow arrow)
2341 GtkNotebookPriv *priv = notebook->priv;
2342 GdkRectangle event_window_pos;
2343 gboolean before = ARROW_IS_BEFORE (arrow);
2344 gboolean left = ARROW_IS_LEFT (arrow);
2346 if (gtk_notebook_get_event_window_position (notebook, &event_window_pos))
2348 gint scroll_arrow_hlength;
2349 gint scroll_arrow_vlength;
2351 gtk_widget_style_get (GTK_WIDGET (notebook),
2352 "scroll-arrow-hlength", &scroll_arrow_hlength,
2353 "scroll-arrow-vlength", &scroll_arrow_vlength,
2356 switch (priv->tab_pos)
2360 rectangle->width = scroll_arrow_vlength;
2361 rectangle->height = scroll_arrow_vlength;
2363 if ((before && (priv->has_before_previous != priv->has_before_next)) ||
2364 (!before && (priv->has_after_previous != priv->has_after_next)))
2365 rectangle->x = event_window_pos.x + (event_window_pos.width - rectangle->width) / 2;
2367 rectangle->x = event_window_pos.x + event_window_pos.width / 2 - rectangle->width;
2369 rectangle->x = event_window_pos.x + event_window_pos.width / 2;
2370 rectangle->y = event_window_pos.y;
2372 rectangle->y += event_window_pos.height - rectangle->height;
2376 case GTK_POS_BOTTOM:
2377 rectangle->width = scroll_arrow_hlength;
2378 rectangle->height = scroll_arrow_hlength;
2382 if (left || !priv->has_before_previous)
2383 rectangle->x = event_window_pos.x;
2385 rectangle->x = event_window_pos.x + rectangle->width;
2389 if (!left || !priv->has_after_next)
2390 rectangle->x = event_window_pos.x + event_window_pos.width - rectangle->width;
2392 rectangle->x = event_window_pos.x + event_window_pos.width - 2 * rectangle->width;
2394 rectangle->y = event_window_pos.y + (event_window_pos.height - rectangle->height) / 2;
2400 static GtkNotebookArrow
2401 gtk_notebook_get_arrow (GtkNotebook *notebook,
2405 GtkNotebookPriv *priv = notebook->priv;
2406 GdkRectangle arrow_rect;
2407 GdkRectangle event_window_pos;
2410 GtkNotebookArrow arrow[4];
2412 arrow[0] = priv->has_before_previous ? ARROW_LEFT_BEFORE : ARROW_NONE;
2413 arrow[1] = priv->has_before_next ? ARROW_RIGHT_BEFORE : ARROW_NONE;
2414 arrow[2] = priv->has_after_previous ? ARROW_LEFT_AFTER : ARROW_NONE;
2415 arrow[3] = priv->has_after_next ? ARROW_RIGHT_AFTER : ARROW_NONE;
2417 if (gtk_notebook_show_arrows (notebook))
2419 gtk_notebook_get_event_window_position (notebook, &event_window_pos);
2420 for (i = 0; i < 4; i++)
2422 if (arrow[i] == ARROW_NONE)
2425 gtk_notebook_get_arrow_rect (notebook, &arrow_rect, arrow[i]);
2427 x0 = x - arrow_rect.x;
2428 y0 = y - arrow_rect.y;
2430 if (y0 >= 0 && y0 < arrow_rect.height &&
2431 x0 >= 0 && x0 < arrow_rect.width)
2440 gtk_notebook_do_arrow (GtkNotebook *notebook,
2441 GtkNotebookArrow arrow)
2443 GtkNotebookPriv *priv = notebook->priv;
2444 GtkWidget *widget = GTK_WIDGET (notebook);
2445 gboolean is_rtl, left;
2447 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2448 left = (ARROW_IS_LEFT (arrow) && !is_rtl) ||
2449 (!ARROW_IS_LEFT (arrow) && is_rtl);
2451 if (!priv->focus_tab ||
2452 gtk_notebook_search_page (notebook, priv->focus_tab,
2453 left ? STEP_PREV : STEP_NEXT,
2456 gtk_notebook_change_current_page (notebook, left ? -1 : 1);
2457 gtk_widget_grab_focus (widget);
2462 gtk_notebook_arrow_button_press (GtkNotebook *notebook,
2463 GtkNotebookArrow arrow,
2466 GtkNotebookPriv *priv = notebook->priv;
2467 GtkWidget *widget = GTK_WIDGET (notebook);
2468 gboolean is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2469 gboolean left = (ARROW_IS_LEFT (arrow) && !is_rtl) ||
2470 (!ARROW_IS_LEFT (arrow) && is_rtl);
2472 if (!gtk_widget_has_focus (widget))
2473 gtk_widget_grab_focus (widget);
2475 priv->button = button;
2476 priv->click_child = arrow;
2480 gtk_notebook_do_arrow (notebook, arrow);
2481 gtk_notebook_set_scroll_timer (notebook);
2483 else if (button == 2)
2484 gtk_notebook_page_select (notebook, TRUE);
2485 else if (button == 3)
2486 gtk_notebook_switch_focus_tab (notebook,
2487 gtk_notebook_search_page (notebook,
2489 left ? STEP_NEXT : STEP_PREV,
2491 gtk_notebook_redraw_arrows (notebook);
2497 get_widget_coordinates (GtkWidget *widget,
2502 GdkWindow *window = ((GdkEventAny *)event)->window;
2505 if (!gdk_event_get_coords (event, &tx, &ty))
2508 while (window && window != widget->window)
2510 gint window_x, window_y;
2512 gdk_window_get_position (window, &window_x, &window_y);
2516 window = gdk_window_get_parent (window);
2531 gtk_notebook_scroll (GtkWidget *widget,
2532 GdkEventScroll *event)
2534 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2535 GtkNotebookPriv *priv = notebook->priv;
2536 GtkWidget *child, *event_widget;
2539 if (!priv->cur_page)
2542 child = priv->cur_page->child;
2543 event_widget = gtk_get_event_widget ((GdkEvent *)event);
2545 /* ignore scroll events from the content of the page */
2546 if (!event_widget || gtk_widget_is_ancestor (event_widget, child) || event_widget == child)
2549 /* nor from the action area */
2550 for (i = 0; i < 2; i++)
2552 if (event_widget == priv->action_widget[i] ||
2553 gtk_widget_is_ancestor (event_widget, priv->action_widget[i]))
2557 switch (event->direction)
2559 case GDK_SCROLL_RIGHT:
2560 case GDK_SCROLL_DOWN:
2561 gtk_notebook_next_page (notebook);
2563 case GDK_SCROLL_LEFT:
2565 gtk_notebook_prev_page (notebook);
2573 get_tab_at_pos (GtkNotebook *notebook, gint x, gint y)
2575 GtkNotebookPriv *priv = notebook->priv;
2576 GtkNotebookPage *page;
2579 children = priv->children;
2582 page = children->data;
2584 if (gtk_widget_get_visible (page->child) &&
2585 page->tab_label && gtk_widget_get_mapped (page->tab_label) &&
2586 (x >= page->allocation.x) &&
2587 (y >= page->allocation.y) &&
2588 (x <= (page->allocation.x + page->allocation.width)) &&
2589 (y <= (page->allocation.y + page->allocation.height)))
2592 children = children->next;
2599 gtk_notebook_button_press (GtkWidget *widget,
2600 GdkEventButton *event)
2602 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2603 GtkNotebookPriv *priv = notebook->priv;
2604 GtkNotebookPage *page;
2606 GtkNotebookArrow arrow;
2609 if (event->type != GDK_BUTTON_PRESS || !priv->children ||
2613 if (!get_widget_coordinates (widget, (GdkEvent *)event, &x, &y))
2616 arrow = gtk_notebook_get_arrow (notebook, x, y);
2618 return gtk_notebook_arrow_button_press (notebook, arrow, event->button);
2620 if (event->button == 3 && priv->menu)
2622 gtk_menu_popup (GTK_MENU (priv->menu), NULL, NULL,
2623 NULL, NULL, 3, event->time);
2627 if (event->button != 1)
2630 priv->button = event->button;
2632 if ((tab = get_tab_at_pos (notebook, x, y)) != NULL)
2634 gboolean page_changed, was_focus;
2637 page_changed = page != priv->cur_page;
2638 was_focus = gtk_widget_is_focus (widget);
2640 gtk_notebook_switch_focus_tab (notebook, tab);
2641 gtk_widget_grab_focus (widget);
2643 if (page_changed && !was_focus)
2644 gtk_widget_child_focus (page->child, GTK_DIR_TAB_FORWARD);
2646 /* save press to possibly begin a drag */
2647 if (page->reorderable || page->detachable)
2649 priv->during_detach = FALSE;
2650 priv->during_reorder = FALSE;
2651 priv->pressed_button = event->button;
2656 priv->drag_begin_x = priv->mouse_x;
2657 priv->drag_begin_y = priv->mouse_y;
2658 priv->drag_offset_x = priv->drag_begin_x - page->allocation.x;
2659 priv->drag_offset_y = priv->drag_begin_y - page->allocation.y;
2667 popup_position_func (GtkMenu *menu,
2673 GtkNotebook *notebook = data;
2674 GtkNotebookPriv *priv = notebook->priv;
2676 GtkRequisition requisition;
2678 if (priv->focus_tab)
2680 GtkNotebookPage *page;
2682 page = priv->focus_tab->data;
2683 w = page->tab_label;
2687 w = GTK_WIDGET (notebook);
2690 gdk_window_get_origin (w->window, x, y);
2691 gtk_widget_size_request (GTK_WIDGET (menu), &requisition);
2693 if (gtk_widget_get_direction (w) == GTK_TEXT_DIR_RTL)
2694 *x += w->allocation.x + w->allocation.width - requisition.width;
2696 *x += w->allocation.x;
2698 *y += w->allocation.y + w->allocation.height;
2704 gtk_notebook_popup_menu (GtkWidget *widget)
2706 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2707 GtkNotebookPriv *priv = notebook->priv;
2711 gtk_menu_popup (GTK_MENU (priv->menu), NULL, NULL,
2712 popup_position_func, notebook,
2713 0, gtk_get_current_event_time ());
2714 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menu), FALSE);
2722 stop_scrolling (GtkNotebook *notebook)
2724 GtkNotebookPriv *priv = notebook->priv;
2728 g_source_remove (priv->timer);
2730 priv->need_timer = FALSE;
2732 priv->click_child = 0;
2734 gtk_notebook_redraw_arrows (notebook);
2738 get_drop_position (GtkNotebook *notebook,
2741 GtkNotebookPriv *priv = notebook->priv;
2742 GList *children, *last_child;
2743 GtkNotebookPage *page;
2750 is_rtl = gtk_widget_get_direction ((GtkWidget *) notebook) == GTK_TEXT_DIR_RTL;
2751 children = priv->children;
2756 page = children->data;
2758 if ((priv->operation != DRAG_OPERATION_REORDER || page != priv->cur_page) &&
2759 gtk_widget_get_visible (page->child) &&
2761 gtk_widget_get_mapped (page->tab_label) &&
2764 switch (priv->tab_pos)
2767 case GTK_POS_BOTTOM:
2770 if ((page->pack == GTK_PACK_START && PAGE_MIDDLE_X (page) > x) ||
2771 (page->pack == GTK_PACK_END && PAGE_MIDDLE_X (page) < x))
2776 if ((page->pack == GTK_PACK_START && PAGE_MIDDLE_X (page) < x) ||
2777 (page->pack == GTK_PACK_END && PAGE_MIDDLE_X (page) > x))
2784 if ((page->pack == GTK_PACK_START && PAGE_MIDDLE_Y (page) > y) ||
2785 (page->pack == GTK_PACK_END && PAGE_MIDDLE_Y (page) < y))
2791 last_child = children->next;
2794 children = children->next;
2801 show_drag_window (GtkNotebook *notebook,
2802 GtkNotebookPriv *priv,
2803 GtkNotebookPage *page,
2806 GtkWidget *widget = GTK_WIDGET (notebook);
2808 if (!priv->drag_window)
2810 GdkWindowAttr attributes;
2811 guint attributes_mask;
2813 attributes.x = page->allocation.x;
2814 attributes.y = page->allocation.y;
2815 attributes.width = page->allocation.width;
2816 attributes.height = page->allocation.height;
2817 attributes.window_type = GDK_WINDOW_CHILD;
2818 attributes.wclass = GDK_INPUT_OUTPUT;
2819 attributes.visual = gtk_widget_get_visual (widget);
2820 attributes.colormap = gtk_widget_get_colormap (widget);
2821 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
2822 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2824 priv->drag_window = gdk_window_new (gtk_widget_get_parent_window (widget),
2827 gdk_window_set_user_data (priv->drag_window, widget);
2830 g_object_ref (page->tab_label);
2831 gtk_widget_unparent (page->tab_label);
2832 gtk_widget_set_parent_window (page->tab_label, priv->drag_window);
2833 gtk_widget_set_parent (page->tab_label, widget);
2834 g_object_unref (page->tab_label);
2836 gdk_window_show (priv->drag_window);
2838 /* the grab will dissapear when the window is hidden */
2839 gdk_device_grab (device, priv->drag_window,
2840 GDK_OWNERSHIP_WINDOW, FALSE,
2841 GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK,
2842 NULL, GDK_CURRENT_TIME);
2845 /* This function undoes the reparenting that happens both when drag_window
2846 * is shown for reordering and when the DnD icon is shown for detaching
2849 hide_drag_window (GtkNotebook *notebook,
2850 GtkNotebookPriv *priv,
2851 GtkNotebookPage *page)
2853 GtkWidget *widget = GTK_WIDGET (notebook);
2854 GtkWidget *parent = page->tab_label->parent;
2856 if (page->tab_label->window != widget->window ||
2857 !NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page))
2859 g_object_ref (page->tab_label);
2861 if (GTK_IS_WINDOW (parent))
2863 /* parent widget is the drag window */
2864 gtk_container_remove (GTK_CONTAINER (parent), page->tab_label);
2867 gtk_widget_unparent (page->tab_label);
2869 gtk_widget_set_parent (page->tab_label, widget);
2870 g_object_unref (page->tab_label);
2873 if (priv->drag_window &&
2874 gdk_window_is_visible (priv->drag_window))
2875 gdk_window_hide (priv->drag_window);
2879 gtk_notebook_stop_reorder (GtkNotebook *notebook)
2881 GtkNotebookPriv *priv = notebook->priv;
2882 GtkNotebookPage *page;
2884 if (priv->operation == DRAG_OPERATION_DETACH)
2885 page = priv->detached_tab;
2887 page = priv->cur_page;
2889 if (!page || !page->tab_label)
2892 priv->pressed_button = -1;
2894 if (page->reorderable || page->detachable)
2896 if (priv->during_reorder)
2898 gint old_page_num, page_num;
2901 element = get_drop_position (notebook, page->pack);
2902 old_page_num = g_list_position (priv->children, priv->focus_tab);
2903 page_num = reorder_tab (notebook, element, priv->focus_tab);
2904 gtk_notebook_child_reordered (notebook, page);
2906 if (priv->has_scrolled || old_page_num != page_num)
2907 g_signal_emit (notebook,
2908 notebook_signals[PAGE_REORDERED], 0,
2909 page->child, page_num);
2911 priv->has_scrolled = FALSE;
2912 priv->during_reorder = FALSE;
2915 hide_drag_window (notebook, priv, page);
2917 priv->operation = DRAG_OPERATION_NONE;
2918 gtk_notebook_pages_allocate (notebook);
2920 if (priv->dnd_timer)
2922 g_source_remove (priv->dnd_timer);
2923 priv->dnd_timer = 0;
2929 gtk_notebook_button_release (GtkWidget *widget,
2930 GdkEventButton *event)
2932 GtkNotebook *notebook;
2933 GtkNotebookPriv *priv;
2934 GtkNotebookPage *page;
2936 if (event->type != GDK_BUTTON_RELEASE)
2939 notebook = GTK_NOTEBOOK (widget);
2940 priv = notebook->priv;
2942 page = priv->cur_page;
2944 if (!priv->during_detach &&
2945 page->reorderable &&
2946 event->button == priv->pressed_button)
2947 gtk_notebook_stop_reorder (notebook);
2949 if (event->button == priv->button)
2951 stop_scrolling (notebook);
2959 gtk_notebook_leave_notify (GtkWidget *widget,
2960 GdkEventCrossing *event)
2962 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2963 GtkNotebookPriv *priv = notebook->priv;
2966 if (!get_widget_coordinates (widget, (GdkEvent *)event, &x, &y))
2972 gtk_notebook_redraw_arrows (notebook);
2978 static GtkNotebookPointerPosition
2979 get_pointer_position (GtkNotebook *notebook)
2981 GtkNotebookPriv *priv = notebook->priv;
2982 GtkWidget *widget = GTK_WIDGET (notebook);
2983 gint wx, wy, width, height;
2986 if (!priv->scrollable)
2987 return POINTER_BETWEEN;
2989 gdk_window_get_position (priv->event_window, &wx, &wy);
2990 gdk_drawable_get_size (GDK_DRAWABLE (priv->event_window), &width, &height);
2992 if (priv->tab_pos == GTK_POS_TOP ||
2993 priv->tab_pos == GTK_POS_BOTTOM)
2997 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2998 x = priv->mouse_x - wx;
3000 if (x > width - SCROLL_THRESHOLD)
3001 return (is_rtl) ? POINTER_BEFORE : POINTER_AFTER;
3002 else if (x < SCROLL_THRESHOLD)
3003 return (is_rtl) ? POINTER_AFTER : POINTER_BEFORE;
3005 return POINTER_BETWEEN;
3011 y = priv->mouse_y - wy;
3012 if (y > height - SCROLL_THRESHOLD)
3013 return POINTER_AFTER;
3014 else if (y < SCROLL_THRESHOLD)
3015 return POINTER_BEFORE;
3017 return POINTER_BETWEEN;
3022 scroll_notebook_timer (gpointer data)
3024 GtkNotebook *notebook = GTK_NOTEBOOK (data);
3025 GtkNotebookPriv *priv = notebook->priv;
3026 GtkNotebookPointerPosition pointer_position;
3027 GList *element, *first_tab;
3029 pointer_position = get_pointer_position (notebook);
3031 element = get_drop_position (notebook, priv->cur_page->pack);
3032 reorder_tab (notebook, element, priv->focus_tab);
3033 first_tab = gtk_notebook_search_page (notebook, priv->first_tab,
3034 (pointer_position == POINTER_BEFORE) ? STEP_PREV : STEP_NEXT,
3038 priv->first_tab = first_tab;
3039 gtk_notebook_pages_allocate (notebook);
3041 gdk_window_move_resize (priv->drag_window,
3042 priv->drag_window_x,
3043 priv->drag_window_y,
3044 priv->cur_page->allocation.width,
3045 priv->cur_page->allocation.height);
3046 gdk_window_raise (priv->drag_window);
3053 check_threshold (GtkNotebook *notebook,
3057 GtkNotebookPriv *priv = notebook->priv;
3060 GdkRectangle rectangle = { 0, }; /* shut up gcc */
3061 GtkSettings *settings;
3063 widget = GTK_WIDGET (notebook);
3064 settings = gtk_widget_get_settings (GTK_WIDGET (notebook));
3065 g_object_get (G_OBJECT (settings), "gtk-dnd-drag-threshold", &dnd_threshold, NULL);
3067 /* we want a large threshold */
3068 dnd_threshold *= DND_THRESHOLD_MULTIPLIER;
3070 gdk_window_get_position (priv->event_window, &rectangle.x, &rectangle.y);
3071 gdk_drawable_get_size (GDK_DRAWABLE (priv->event_window), &rectangle.width, &rectangle.height);
3073 rectangle.x -= dnd_threshold;
3074 rectangle.width += 2 * dnd_threshold;
3075 rectangle.y -= dnd_threshold;
3076 rectangle.height += 2 * dnd_threshold;
3078 return (current_x < rectangle.x ||
3079 current_x > rectangle.x + rectangle.width ||
3080 current_y < rectangle.y ||
3081 current_y > rectangle.y + rectangle.height);
3085 gtk_notebook_motion_notify (GtkWidget *widget,
3086 GdkEventMotion *event)
3088 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
3089 GtkNotebookPriv *priv = notebook->priv;
3090 GtkNotebookPage *page;
3091 GtkNotebookArrow arrow;
3092 GtkNotebookPointerPosition pointer_position;
3093 GtkSettings *settings;
3097 page = priv->cur_page;
3102 if (!(event->state & GDK_BUTTON1_MASK) &&
3103 priv->pressed_button != -1)
3105 gtk_notebook_stop_reorder (notebook);
3106 stop_scrolling (notebook);
3109 if (event->time < priv->timestamp + MSECS_BETWEEN_UPDATES)
3112 priv->timestamp = event->time;
3114 /* While animating the move, event->x is relative to the flying tab
3115 * (priv->drag_window has a pointer grab), but we need coordinates relative to
3116 * the notebook widget.
3118 gdk_window_get_origin (widget->window, &x_win, &y_win);
3119 priv->mouse_x = event->x_root - x_win;
3120 priv->mouse_y = event->y_root - y_win;
3122 arrow = gtk_notebook_get_arrow (notebook, priv->mouse_x, priv->mouse_y);
3123 if (arrow != priv->in_child)
3125 priv->in_child = arrow;
3126 gtk_notebook_redraw_arrows (notebook);
3129 if (priv->pressed_button == -1)
3132 if (page->detachable &&
3133 check_threshold (notebook, priv->mouse_x, priv->mouse_y))
3135 priv->detached_tab = priv->cur_page;
3136 priv->during_detach = TRUE;
3138 gtk_drag_begin (widget, priv->source_targets, GDK_ACTION_MOVE,
3139 priv->pressed_button, (GdkEvent*) event);
3143 if (page->reorderable &&
3144 (priv->during_reorder ||
3145 gtk_drag_check_threshold (widget, priv->drag_begin_x, priv->drag_begin_y, priv->mouse_x, priv->mouse_y)))
3147 priv->during_reorder = TRUE;
3148 pointer_position = get_pointer_position (notebook);
3150 if (event->window == priv->drag_window &&
3151 pointer_position != POINTER_BETWEEN &&
3152 gtk_notebook_show_arrows (notebook))
3155 if (!priv->dnd_timer)
3157 priv->has_scrolled = TRUE;
3158 settings = gtk_widget_get_settings (GTK_WIDGET (notebook));
3159 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
3161 priv->dnd_timer = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
3162 scroll_notebook_timer,
3163 (gpointer) notebook);
3168 if (priv->dnd_timer)
3170 g_source_remove (priv->dnd_timer);
3171 priv->dnd_timer = 0;
3175 if (event->window == priv->drag_window ||
3176 priv->operation != DRAG_OPERATION_REORDER)
3178 /* the drag operation is beginning, create the window */
3179 if (priv->operation != DRAG_OPERATION_REORDER)
3181 priv->operation = DRAG_OPERATION_REORDER;
3182 show_drag_window (notebook, priv, page, event->device);
3185 gtk_notebook_pages_allocate (notebook);
3186 gdk_window_move_resize (priv->drag_window,
3187 priv->drag_window_x,
3188 priv->drag_window_y,
3189 page->allocation.width,
3190 page->allocation.height);
3198 gtk_notebook_grab_notify (GtkWidget *widget,
3199 gboolean was_grabbed)
3201 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
3205 gtk_notebook_stop_reorder (notebook);
3206 stop_scrolling (notebook);
3211 gtk_notebook_state_changed (GtkWidget *widget,
3212 GtkStateType previous_state)
3214 if (!gtk_widget_is_sensitive (widget))
3215 stop_scrolling (GTK_NOTEBOOK (widget));
3219 gtk_notebook_focus_in (GtkWidget *widget,
3220 GdkEventFocus *event)
3222 gtk_notebook_redraw_tabs (GTK_NOTEBOOK (widget));
3228 gtk_notebook_focus_out (GtkWidget *widget,
3229 GdkEventFocus *event)
3231 gtk_notebook_redraw_tabs (GTK_NOTEBOOK (widget));
3237 gtk_notebook_draw_focus (GtkWidget *widget,
3238 GdkEventExpose *event)
3240 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
3241 GtkNotebookPriv *priv = notebook->priv;
3243 if (gtk_widget_has_focus (widget) && gtk_widget_is_drawable (widget) &&
3244 priv->show_tabs && priv->cur_page &&
3245 priv->cur_page->tab_label->window == event->window)
3247 GtkNotebookPage *page;
3249 page = priv->cur_page;
3251 if (gtk_widget_intersect (page->tab_label, &event->area, NULL))
3256 gtk_widget_style_get (widget, "focus-line-width", &focus_width, NULL);
3258 area.x = page->tab_label->allocation.x - focus_width;
3259 area.y = page->tab_label->allocation.y - focus_width;
3260 area.width = page->tab_label->allocation.width + 2 * focus_width;
3261 area.height = page->tab_label->allocation.height + 2 * focus_width;
3263 gtk_paint_focus (widget->style, event->window,
3264 gtk_widget_get_state (widget), NULL, widget, "tab",
3265 area.x, area.y, area.width, area.height);
3271 gtk_notebook_style_set (GtkWidget *widget,
3274 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
3275 GtkNotebookPriv *priv = notebook->priv;
3277 gboolean has_before_previous;
3278 gboolean has_before_next;
3279 gboolean has_after_previous;
3280 gboolean has_after_next;
3282 gtk_widget_style_get (widget,
3283 "has-backward-stepper", &has_before_previous,
3284 "has-secondary-forward-stepper", &has_before_next,
3285 "has-secondary-backward-stepper", &has_after_previous,
3286 "has-forward-stepper", &has_after_next,
3289 priv->has_before_previous = has_before_previous;
3290 priv->has_before_next = has_before_next;
3291 priv->has_after_previous = has_after_previous;
3292 priv->has_after_next = has_after_next;
3294 GTK_WIDGET_CLASS (gtk_notebook_parent_class)->style_set (widget, previous);
3298 on_drag_icon_expose (GtkWidget *widget,
3299 GdkEventExpose *event,
3302 GtkWidget *notebook, *child;
3303 GtkRequisition requisition;
3306 notebook = GTK_WIDGET (data);
3307 child = gtk_bin_get_child (GTK_BIN (widget));
3309 gtk_widget_size_request (widget, &requisition);
3310 gap_pos = get_tab_gap_pos (GTK_NOTEBOOK (notebook));
3312 gtk_paint_extension (gtk_widget_get_style (notebook),
3313 gtk_widget_get_window (widget),
3314 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
3315 NULL, widget, "tab",
3317 requisition.width, requisition.height,
3320 gtk_container_propagate_expose (GTK_CONTAINER (widget), child, event);
3326 gtk_notebook_drag_begin (GtkWidget *widget,
3327 GdkDragContext *context)
3329 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
3330 GtkNotebookPriv *priv = notebook->priv;
3331 GtkWidget *tab_label;
3333 if (priv->dnd_timer)
3335 g_source_remove (priv->dnd_timer);
3336 priv->dnd_timer = 0;
3339 priv->operation = DRAG_OPERATION_DETACH;
3340 gtk_notebook_pages_allocate (notebook);
3342 tab_label = priv->detached_tab->tab_label;
3344 hide_drag_window (notebook, priv, priv->cur_page);
3345 g_object_ref (tab_label);
3346 gtk_widget_unparent (tab_label);
3348 priv->dnd_window = gtk_window_new (GTK_WINDOW_POPUP);
3349 gtk_window_set_screen (GTK_WINDOW (priv->dnd_window),
3350 gtk_widget_get_screen (widget));
3351 gtk_container_add (GTK_CONTAINER (priv->dnd_window), tab_label);
3352 gtk_widget_set_size_request (priv->dnd_window,
3353 priv->detached_tab->allocation.width,
3354 priv->detached_tab->allocation.height);
3355 g_object_unref (tab_label);
3357 g_signal_connect (G_OBJECT (priv->dnd_window), "expose-event",
3358 G_CALLBACK (on_drag_icon_expose), notebook);
3360 gtk_drag_set_icon_widget (context, priv->dnd_window, -2, -2);
3364 gtk_notebook_drag_end (GtkWidget *widget,
3365 GdkDragContext *context)
3367 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
3368 GtkNotebookPriv *priv = notebook->priv;
3370 gtk_notebook_stop_reorder (notebook);
3372 if (priv->detached_tab)
3373 gtk_notebook_switch_page (notebook, priv->detached_tab);
3375 _gtk_bin_set_child (GTK_BIN (priv->dnd_window), NULL);
3376 gtk_widget_destroy (priv->dnd_window);
3377 priv->dnd_window = NULL;
3379 priv->operation = DRAG_OPERATION_NONE;
3382 static GtkNotebook *
3383 gtk_notebook_create_window (GtkNotebook *notebook,
3388 if (window_creation_hook)
3389 return (* window_creation_hook) (notebook, page, x, y, window_creation_hook_data);
3395 gtk_notebook_drag_failed (GtkWidget *widget,
3396 GdkDragContext *context,
3397 GtkDragResult result,
3400 if (result == GTK_DRAG_RESULT_NO_TARGET)
3402 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
3403 GtkNotebookPriv *priv = notebook->priv;
3404 GtkNotebook *dest_notebook = NULL;
3405 GdkDisplay *display;
3408 display = gtk_widget_get_display (widget);
3409 gdk_display_get_pointer (display, NULL, &x, &y, NULL);
3411 g_signal_emit (notebook, notebook_signals[CREATE_WINDOW], 0,
3412 priv->detached_tab->child, x, y, &dest_notebook);
3415 do_detach_tab (notebook, dest_notebook, priv->detached_tab->child, 0, 0);
3424 gtk_notebook_switch_tab_timeout (gpointer data)
3426 GtkNotebook *notebook = GTK_NOTEBOOK (data);
3427 GtkNotebookPriv *priv = notebook->priv;
3431 priv->switch_tab_timer = 0;
3435 if ((tab = get_tab_at_pos (notebook, x, y)) != NULL)
3437 /* FIXME: hack, we don't want the
3438 * focus to move fom the source widget
3440 priv->child_has_focus = FALSE;
3441 gtk_notebook_switch_focus_tab (notebook, tab);
3448 gtk_notebook_drag_motion (GtkWidget *widget,
3449 GdkDragContext *context,
3454 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
3455 GtkNotebookPriv *priv = notebook->priv;
3456 GdkRectangle position;
3457 GtkSettings *settings;
3458 GtkNotebookArrow arrow;
3460 GdkAtom target, tab_target;
3462 arrow = gtk_notebook_get_arrow (notebook,
3463 x + widget->allocation.x,
3464 y + widget->allocation.y);
3467 priv->click_child = arrow;
3468 gtk_notebook_set_scroll_timer (notebook);
3469 gdk_drag_status (context, 0, time);
3473 stop_scrolling (notebook);
3474 target = gtk_drag_dest_find_target (widget, context, NULL);
3475 tab_target = gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB");
3477 if (target == tab_target)
3479 gpointer widget_group, source_widget_group;
3480 GtkWidget *source_widget;
3482 source_widget = gtk_drag_get_source_widget (context);
3483 g_assert (source_widget);
3485 widget_group = gtk_notebook_get_group (notebook);
3486 source_widget_group = gtk_notebook_get_group (GTK_NOTEBOOK (source_widget));
3488 if (widget_group && source_widget_group &&
3489 widget_group == source_widget_group &&
3490 !(widget == GTK_NOTEBOOK (source_widget)->priv->cur_page->child ||
3491 gtk_widget_is_ancestor (widget, GTK_NOTEBOOK (source_widget)->priv->cur_page->child)))
3493 gdk_drag_status (context, GDK_ACTION_MOVE, time);
3498 /* it's a tab, but doesn't share
3499 * ID with this notebook */
3500 gdk_drag_status (context, 0, time);
3504 x += widget->allocation.x;
3505 y += widget->allocation.y;
3507 if (gtk_notebook_get_event_window_position (notebook, &position) &&
3508 x >= position.x && x <= position.x + position.width &&
3509 y >= position.y && y <= position.y + position.height)
3514 if (!priv->switch_tab_timer)
3516 settings = gtk_widget_get_settings (widget);
3518 g_object_get (settings, "gtk-timeout-expand", &timeout, NULL);
3519 priv->switch_tab_timer = gdk_threads_add_timeout (timeout,
3520 gtk_notebook_switch_tab_timeout,
3526 if (priv->switch_tab_timer)
3528 g_source_remove (priv->switch_tab_timer);
3529 priv->switch_tab_timer = 0;
3533 return (target == tab_target) ? TRUE : FALSE;
3537 gtk_notebook_drag_leave (GtkWidget *widget,
3538 GdkDragContext *context,
3541 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
3542 GtkNotebookPriv *priv = notebook->priv;
3544 if (priv->switch_tab_timer)
3546 g_source_remove (priv->switch_tab_timer);
3547 priv->switch_tab_timer = 0;
3550 stop_scrolling (GTK_NOTEBOOK (widget));
3554 gtk_notebook_drag_drop (GtkWidget *widget,
3555 GdkDragContext *context,
3560 GdkAtom target, tab_target;
3562 target = gtk_drag_dest_find_target (widget, context, NULL);
3563 tab_target = gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB");
3565 if (target == tab_target)
3567 gtk_drag_get_data (widget, context, target, time);
3575 do_detach_tab (GtkNotebook *from,
3581 GtkNotebookPriv *to_priv = to->priv;
3582 GtkWidget *tab_label, *menu_label;
3583 gboolean tab_expand, tab_fill, reorderable, detachable;
3588 menu_label = gtk_notebook_get_menu_label (from, child);
3591 g_object_ref (menu_label);
3593 tab_label = gtk_notebook_get_tab_label (from, child);
3596 g_object_ref (tab_label);
3598 g_object_ref (child);
3600 gtk_container_child_get (GTK_CONTAINER (from),
3602 "tab-expand", &tab_expand,
3603 "tab-fill", &tab_fill,
3604 "tab-pack", &tab_pack,
3605 "reorderable", &reorderable,
3606 "detachable", &detachable,
3609 gtk_container_remove (GTK_CONTAINER (from), child);
3611 to_priv->mouse_x = x + GTK_WIDGET (to)->allocation.x;
3612 to_priv->mouse_y = y + GTK_WIDGET (to)->allocation.y;
3614 element = get_drop_position (to, tab_pack);
3615 page_num = g_list_position (to_priv->children, element);
3616 gtk_notebook_insert_page_menu (to, child, tab_label, menu_label, page_num);
3618 gtk_container_child_set (GTK_CONTAINER (to), child,
3619 "tab-pack", tab_pack,
3620 "tab-expand", tab_expand,
3621 "tab-fill", tab_fill,
3622 "reorderable", reorderable,
3623 "detachable", detachable,
3626 g_object_unref (child);
3629 g_object_unref (tab_label);
3632 g_object_unref (menu_label);
3634 gtk_notebook_set_current_page (to, page_num);
3638 gtk_notebook_drag_data_get (GtkWidget *widget,
3639 GdkDragContext *context,
3640 GtkSelectionData *data,
3644 if (data->target == gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB"))
3646 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
3647 GtkNotebookPriv *priv = notebook->priv;
3649 gtk_selection_data_set (data,
3652 (void*) &priv->detached_tab->child,
3658 gtk_notebook_drag_data_received (GtkWidget *widget,
3659 GdkDragContext *context,
3662 GtkSelectionData *data,
3666 GtkNotebook *notebook;
3667 GtkWidget *source_widget;
3670 notebook = GTK_NOTEBOOK (widget);
3671 source_widget = gtk_drag_get_source_widget (context);
3673 if (source_widget &&
3674 data->target == gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB"))
3676 child = (void*) data->data;
3678 do_detach_tab (GTK_NOTEBOOK (source_widget), notebook, *child, x, y);
3679 gtk_drag_finish (context, TRUE, FALSE, time);
3682 gtk_drag_finish (context, FALSE, FALSE, time);
3685 /* Private GtkContainer Methods :
3687 * gtk_notebook_set_child_arg
3688 * gtk_notebook_get_child_arg
3690 * gtk_notebook_remove
3691 * gtk_notebook_focus
3692 * gtk_notebook_set_focus_child
3693 * gtk_notebook_child_type
3694 * gtk_notebook_forall
3697 gtk_notebook_set_child_property (GtkContainer *container,
3700 const GValue *value,
3705 GtkPackType pack_type;
3707 /* not finding child's page is valid for menus or labels */
3708 if (!gtk_notebook_find_child (GTK_NOTEBOOK (container), child, NULL))
3711 switch (property_id)
3713 case CHILD_PROP_TAB_LABEL:
3714 /* a NULL pointer indicates a default_tab setting, otherwise
3715 * we need to set the associated label
3717 gtk_notebook_set_tab_label_text (GTK_NOTEBOOK (container), child,
3718 g_value_get_string (value));
3720 case CHILD_PROP_MENU_LABEL:
3721 gtk_notebook_set_menu_label_text (GTK_NOTEBOOK (container), child,
3722 g_value_get_string (value));
3724 case CHILD_PROP_POSITION:
3725 gtk_notebook_reorder_child (GTK_NOTEBOOK (container), child,
3726 g_value_get_int (value));
3728 case CHILD_PROP_TAB_EXPAND:
3729 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3730 &expand, &fill, &pack_type);
3731 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (container), child,
3732 g_value_get_boolean (value),
3735 case CHILD_PROP_TAB_FILL:
3736 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3737 &expand, &fill, &pack_type);
3738 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (container), child,
3740 g_value_get_boolean (value),
3743 case CHILD_PROP_TAB_PACK:
3744 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3745 &expand, &fill, &pack_type);
3746 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (container), child,
3748 g_value_get_enum (value));
3750 case CHILD_PROP_REORDERABLE:
3751 gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (container), child,
3752 g_value_get_boolean (value));
3754 case CHILD_PROP_DETACHABLE:
3755 gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (container), child,
3756 g_value_get_boolean (value));
3759 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
3765 gtk_notebook_get_child_property (GtkContainer *container,
3771 GtkNotebook *notebook = GTK_NOTEBOOK (container);
3772 GtkNotebookPriv *priv = notebook->priv;
3777 GtkPackType pack_type;
3779 /* not finding child's page is valid for menus or labels */
3780 list = gtk_notebook_find_child (notebook, child, NULL);
3783 /* nothing to set on labels or menus */
3784 g_param_value_set_default (pspec, value);
3788 switch (property_id)
3790 case CHILD_PROP_TAB_LABEL:
3791 label = gtk_notebook_get_tab_label (notebook, child);
3793 if (GTK_IS_LABEL (label))
3794 g_value_set_string (value, gtk_label_get_label (GTK_LABEL (label)));
3796 g_value_set_string (value, NULL);
3798 case CHILD_PROP_MENU_LABEL:
3799 label = gtk_notebook_get_menu_label (notebook, child);
3801 if (GTK_IS_LABEL (label))
3802 g_value_set_string (value, gtk_label_get_label (GTK_LABEL (label)));
3804 g_value_set_string (value, NULL);
3806 case CHILD_PROP_POSITION:
3807 g_value_set_int (value, g_list_position (priv->children, list));
3809 case CHILD_PROP_TAB_EXPAND:
3810 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3811 &expand, NULL, NULL);
3812 g_value_set_boolean (value, expand);
3814 case CHILD_PROP_TAB_FILL:
3815 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3817 g_value_set_boolean (value, fill);
3819 case CHILD_PROP_TAB_PACK:
3820 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3821 NULL, NULL, &pack_type);
3822 g_value_set_enum (value, pack_type);
3824 case CHILD_PROP_REORDERABLE:
3825 g_value_set_boolean (value,
3826 gtk_notebook_get_tab_reorderable (GTK_NOTEBOOK (container), child));
3828 case CHILD_PROP_DETACHABLE:
3829 g_value_set_boolean (value,
3830 gtk_notebook_get_tab_detachable (GTK_NOTEBOOK (container), child));
3833 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
3839 gtk_notebook_add (GtkContainer *container,
3842 gtk_notebook_insert_page_menu (GTK_NOTEBOOK (container), widget,
3847 gtk_notebook_remove (GtkContainer *container,
3850 GtkNotebook *notebook = GTK_NOTEBOOK (container);
3851 GtkNotebookPriv *priv = notebook->priv;
3852 GtkNotebookPage *page;
3856 children = priv->children;
3859 page = children->data;
3861 if (page->child == widget)
3865 children = children->next;
3868 if (children == NULL)
3871 g_object_ref (widget);
3873 gtk_notebook_real_remove (notebook, children);
3875 g_signal_emit (notebook,
3876 notebook_signals[PAGE_REMOVED],
3881 g_object_unref (widget);
3885 focus_tabs_in (GtkNotebook *notebook)
3887 GtkNotebookPriv *priv = notebook->priv;
3889 if (priv->show_tabs && priv->cur_page)
3891 gtk_widget_grab_focus (GTK_WIDGET (notebook));
3893 gtk_notebook_switch_focus_tab (notebook,
3894 g_list_find (priv->children,
3904 focus_tabs_move (GtkNotebook *notebook,
3905 GtkDirectionType direction,
3906 gint search_direction)
3908 GtkNotebookPriv *priv = notebook->priv;
3911 new_page = gtk_notebook_search_page (notebook, priv->focus_tab,
3912 search_direction, TRUE);
3915 gboolean wrap_around;
3917 g_object_get (gtk_widget_get_settings (GTK_WIDGET (notebook)),
3918 "gtk-keynav-wrap-around", &wrap_around,
3922 new_page = gtk_notebook_search_page (notebook, NULL,
3923 search_direction, TRUE);
3927 gtk_notebook_switch_focus_tab (notebook, new_page);
3929 gtk_widget_error_bell (GTK_WIDGET (notebook));
3935 focus_child_in (GtkNotebook *notebook,
3936 GtkDirectionType direction)
3938 GtkNotebookPriv *priv = notebook->priv;
3941 return gtk_widget_child_focus (priv->cur_page->child, direction);
3947 focus_action_in (GtkNotebook *notebook,
3949 GtkDirectionType direction)
3951 GtkNotebookPriv *priv = notebook->priv;
3953 if (priv->action_widget[action] &&
3954 gtk_widget_get_visible (priv->action_widget[action]))
3955 return gtk_widget_child_focus (priv->action_widget[action], direction);
3960 /* Focus in the notebook can either be on the pages, or on
3961 * the tabs or on the action_widgets.
3964 gtk_notebook_focus (GtkWidget *widget,
3965 GtkDirectionType direction)
3967 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
3968 GtkNotebookPriv *priv = notebook->priv;
3969 GtkWidget *old_focus_child;
3970 GtkDirectionType effective_direction;
3974 gboolean widget_is_focus;
3975 GtkContainer *container;
3977 container = GTK_CONTAINER (widget);
3979 if (priv->tab_pos == GTK_POS_TOP ||
3980 priv->tab_pos == GTK_POS_LEFT)
3982 first_action = ACTION_WIDGET_START;
3983 last_action = ACTION_WIDGET_END;
3987 first_action = ACTION_WIDGET_END;
3988 last_action = ACTION_WIDGET_START;
3991 if (priv->focus_out)
3993 priv->focus_out = FALSE; /* Clear this to catch the wrap-around case */
3997 widget_is_focus = gtk_widget_is_focus (widget);
3998 old_focus_child = gtk_container_get_focus_child (container);
4000 effective_direction = get_effective_direction (notebook, direction);
4002 if (old_focus_child) /* Focus on page child or action widget */
4004 if (gtk_widget_child_focus (old_focus_child, direction))
4007 if (old_focus_child == priv->action_widget[ACTION_WIDGET_START])
4009 switch (effective_direction)
4012 return focus_child_in (notebook, GTK_DIR_TAB_FORWARD);
4014 return focus_tabs_in (notebook);
4022 case GTK_DIR_TAB_FORWARD:
4023 if ((priv->tab_pos == GTK_POS_RIGHT || priv->tab_pos == GTK_POS_BOTTOM) &&
4024 focus_child_in (notebook, direction))
4026 return focus_tabs_in (notebook);
4027 case GTK_DIR_TAB_BACKWARD:
4030 g_assert_not_reached ();
4034 else if (old_focus_child == priv->action_widget[ACTION_WIDGET_END])
4036 switch (effective_direction)
4039 return focus_child_in (notebook, GTK_DIR_TAB_FORWARD);
4043 return focus_tabs_in (notebook);
4049 case GTK_DIR_TAB_FORWARD:
4051 case GTK_DIR_TAB_BACKWARD:
4052 if ((priv->tab_pos == GTK_POS_TOP || priv->tab_pos == GTK_POS_LEFT) &&
4053 focus_child_in (notebook, direction))
4055 return focus_tabs_in (notebook);
4057 g_assert_not_reached ();
4063 switch (effective_direction)
4065 case GTK_DIR_TAB_BACKWARD:
4067 /* Focus onto the tabs */
4068 return focus_tabs_in (notebook);
4073 case GTK_DIR_TAB_FORWARD:
4074 return focus_action_in (notebook, last_action, direction);
4078 else if (widget_is_focus) /* Focus was on tabs */
4080 switch (effective_direction)
4082 case GTK_DIR_TAB_BACKWARD:
4083 return focus_action_in (notebook, first_action, direction);
4086 case GTK_DIR_TAB_FORWARD:
4087 if (focus_child_in (notebook, GTK_DIR_TAB_FORWARD))
4089 return focus_action_in (notebook, last_action, direction);
4091 /* We use TAB_FORWARD rather than direction so that we focus a more
4092 * predictable widget for the user; users may be using arrow focusing
4093 * in this situation even if they don't usually use arrow focusing.
4095 return focus_child_in (notebook, GTK_DIR_TAB_FORWARD);
4097 return focus_tabs_move (notebook, direction, STEP_PREV);
4099 return focus_tabs_move (notebook, direction, STEP_NEXT);
4102 else /* Focus was not on widget */
4104 switch (effective_direction)
4106 case GTK_DIR_TAB_FORWARD:
4108 if (focus_action_in (notebook, first_action, direction))
4110 if (focus_tabs_in (notebook))
4112 if (focus_action_in (notebook, last_action, direction))
4114 if (focus_child_in (notebook, direction))
4117 case GTK_DIR_TAB_BACKWARD:
4118 if (focus_action_in (notebook, last_action, direction))
4120 if (focus_child_in (notebook, direction))
4122 if (focus_tabs_in (notebook))
4124 if (focus_action_in (notebook, first_action, direction))
4129 return focus_child_in (notebook, direction);
4133 g_assert_not_reached ();
4138 gtk_notebook_set_focus_child (GtkContainer *container,
4141 GtkNotebook *notebook = GTK_NOTEBOOK (container);
4142 GtkNotebookPriv *priv = notebook->priv;
4143 GtkWidget *page_child;
4144 GtkWidget *toplevel;
4146 /* If the old focus widget was within a page of the notebook,
4147 * (child may either be NULL or not in this case), record it
4148 * for future use if we switch to the page with a mnemonic.
4151 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (container));
4152 if (toplevel && gtk_widget_is_toplevel (toplevel))
4154 page_child = GTK_WINDOW (toplevel)->focus_widget;
4157 if (page_child->parent == GTK_WIDGET (container))
4159 GList *list = gtk_notebook_find_child (notebook, page_child, NULL);
4162 GtkNotebookPage *page = list->data;
4164 if (page->last_focus_child)
4165 g_object_remove_weak_pointer (G_OBJECT (page->last_focus_child), (gpointer *)&page->last_focus_child);
4167 page->last_focus_child = GTK_WINDOW (toplevel)->focus_widget;
4168 g_object_add_weak_pointer (G_OBJECT (page->last_focus_child), (gpointer *)&page->last_focus_child);
4174 page_child = page_child->parent;
4180 g_return_if_fail (GTK_IS_WIDGET (child));
4182 priv->child_has_focus = TRUE;
4183 if (!priv->focus_tab)
4186 GtkNotebookPage *page;
4188 children = priv->children;
4191 page = children->data;
4192 if (page->child == child || page->tab_label == child)
4193 gtk_notebook_switch_focus_tab (notebook, children);
4194 children = children->next;
4199 priv->child_has_focus = FALSE;
4201 GTK_CONTAINER_CLASS (gtk_notebook_parent_class)->set_focus_child (container, child);
4205 gtk_notebook_forall (GtkContainer *container,
4206 gboolean include_internals,
4207 GtkCallback callback,
4208 gpointer callback_data)
4210 GtkNotebook *notebook = GTK_NOTEBOOK (container);
4211 GtkNotebookPriv *priv = notebook->priv;
4215 children = priv->children;
4218 GtkNotebookPage *page;
4220 page = children->data;
4221 children = children->next;
4222 (* callback) (page->child, callback_data);
4224 if (include_internals)
4226 if (page->tab_label)
4227 (* callback) (page->tab_label, callback_data);
4231 if (include_internals) {
4232 for (i = 0; i < N_ACTION_WIDGETS; i++)
4234 if (priv->action_widget[i])
4235 (* callback) (priv->action_widget[i], callback_data);
4241 gtk_notebook_child_type (GtkContainer *container)
4243 return GTK_TYPE_WIDGET;
4246 /* Private GtkNotebook Methods:
4248 * gtk_notebook_real_insert_page
4251 page_visible_cb (GtkWidget *page,
4255 GtkNotebook *notebook = GTK_NOTEBOOK (data);
4256 GtkNotebookPriv *priv = notebook->priv;
4260 if (priv->cur_page &&
4261 priv->cur_page->child == page &&
4262 !gtk_widget_get_visible (page))
4264 list = g_list_find (priv->children, priv->cur_page);
4267 next = gtk_notebook_search_page (notebook, list, STEP_NEXT, TRUE);
4269 next = gtk_notebook_search_page (notebook, list, STEP_PREV, TRUE);
4273 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (next));
4278 gtk_notebook_real_insert_page (GtkNotebook *notebook,
4280 GtkWidget *tab_label,
4281 GtkWidget *menu_label,
4284 GtkNotebookPriv *priv = notebook->priv;
4285 GtkNotebookPage *page;
4288 gtk_widget_freeze_child_notify (child);
4290 page = g_slice_new0 (GtkNotebookPage);
4291 page->child = child;
4293 nchildren = g_list_length (priv->children);
4294 if ((position < 0) || (position > nchildren))
4295 position = nchildren;
4297 priv->children = g_list_insert (priv->children, page, position);
4301 page->default_tab = TRUE;
4302 if (priv->show_tabs)
4303 tab_label = gtk_label_new (NULL);
4305 page->tab_label = tab_label;
4306 page->menu_label = menu_label;
4307 page->expand = FALSE;
4309 page->pack = GTK_PACK_START;
4312 page->default_menu = TRUE;
4314 g_object_ref_sink (page->menu_label);
4317 gtk_notebook_menu_item_create (notebook,
4318 g_list_find (priv->children, page));
4320 gtk_widget_set_parent (child, GTK_WIDGET (notebook));
4322 gtk_widget_set_parent (tab_label, GTK_WIDGET (notebook));
4324 gtk_notebook_update_labels (notebook);
4326 if (!priv->first_tab)
4327 priv->first_tab = priv->children;
4329 /* child visible will be turned on by switch_page below */
4330 if (priv->cur_page != page)
4331 gtk_widget_set_child_visible (child, FALSE);
4335 if (priv->show_tabs && gtk_widget_get_visible (child))
4336 gtk_widget_show (tab_label);
4338 gtk_widget_hide (tab_label);
4340 page->mnemonic_activate_signal =
4341 g_signal_connect (tab_label,
4342 "mnemonic-activate",
4343 G_CALLBACK (gtk_notebook_mnemonic_activate_switch_page),
4347 page->notify_visible_handler = g_signal_connect (child, "notify::visible",
4348 G_CALLBACK (page_visible_cb), notebook);
4350 g_signal_emit (notebook,
4351 notebook_signals[PAGE_ADDED],
4356 if (!priv->cur_page)
4358 gtk_notebook_switch_page (notebook, page);
4359 /* focus_tab is set in the switch_page method */
4360 gtk_notebook_switch_focus_tab (notebook, priv->focus_tab);
4363 gtk_notebook_update_tab_states (notebook);
4365 if (priv->scrollable)
4366 gtk_notebook_redraw_arrows (notebook);
4368 gtk_widget_child_notify (child, "tab-expand");
4369 gtk_widget_child_notify (child, "tab-fill");
4370 gtk_widget_child_notify (child, "tab-pack");
4371 gtk_widget_child_notify (child, "tab-label");
4372 gtk_widget_child_notify (child, "menu-label");
4373 gtk_widget_child_notify (child, "position");
4374 gtk_widget_thaw_child_notify (child);
4376 /* The page-added handler might have reordered the pages, re-get the position */
4377 return gtk_notebook_page_num (notebook, child);
4380 /* Private GtkNotebook Functions:
4382 * gtk_notebook_redraw_tabs
4383 * gtk_notebook_real_remove
4384 * gtk_notebook_update_labels
4385 * gtk_notebook_timer
4386 * gtk_notebook_set_scroll_timer
4387 * gtk_notebook_page_compare
4388 * gtk_notebook_real_page_position
4389 * gtk_notebook_search_page
4392 gtk_notebook_redraw_tabs (GtkNotebook *notebook)
4394 GtkNotebookPriv *priv = notebook->priv;
4396 GtkNotebookPage *page;
4397 GdkRectangle redraw_rect;
4399 gint tab_pos = get_effective_tab_pos (notebook);
4401 widget = GTK_WIDGET (notebook);
4402 border = gtk_container_get_border_width (GTK_CONTAINER (notebook));
4404 if (!gtk_widget_get_mapped (widget) || !priv->first_tab)
4407 page = priv->first_tab->data;
4409 redraw_rect.x = border;
4410 redraw_rect.y = border;
4414 case GTK_POS_BOTTOM:
4415 redraw_rect.y = widget->allocation.height - border -
4416 page->allocation.height - widget->style->ythickness;
4418 if (page != priv->cur_page)
4419 redraw_rect.y -= widget->style->ythickness;
4422 redraw_rect.width = widget->allocation.width - 2 * border;
4423 redraw_rect.height = page->allocation.height + widget->style->ythickness;
4425 if (page != priv->cur_page)
4426 redraw_rect.height += widget->style->ythickness;
4429 redraw_rect.x = widget->allocation.width - border -
4430 page->allocation.width - widget->style->xthickness;
4432 if (page != priv->cur_page)
4433 redraw_rect.x -= widget->style->xthickness;
4436 redraw_rect.width = page->allocation.width + widget->style->xthickness;
4437 redraw_rect.height = widget->allocation.height - 2 * border;
4439 if (page != priv->cur_page)
4440 redraw_rect.width += widget->style->xthickness;
4444 redraw_rect.x += widget->allocation.x;
4445 redraw_rect.y += widget->allocation.y;
4447 gdk_window_invalidate_rect (widget->window, &redraw_rect, TRUE);
4451 gtk_notebook_redraw_arrows (GtkNotebook *notebook)
4453 GtkNotebookPriv *priv = notebook->priv;
4455 if (gtk_widget_get_mapped (GTK_WIDGET (notebook)) &&
4456 gtk_notebook_show_arrows (notebook))
4460 GtkNotebookArrow arrow[4];
4462 arrow[0] = priv->has_before_previous ? ARROW_LEFT_BEFORE : ARROW_NONE;
4463 arrow[1] = priv->has_before_next ? ARROW_RIGHT_BEFORE : ARROW_NONE;
4464 arrow[2] = priv->has_after_previous ? ARROW_LEFT_AFTER : ARROW_NONE;
4465 arrow[3] = priv->has_after_next ? ARROW_RIGHT_AFTER : ARROW_NONE;
4467 for (i = 0; i < 4; i++)
4469 if (arrow[i] == ARROW_NONE)
4472 gtk_notebook_get_arrow_rect (notebook, &rect, arrow[i]);
4473 gdk_window_invalidate_rect (GTK_WIDGET (notebook)->window,
4480 gtk_notebook_timer (GtkNotebook *notebook)
4482 GtkNotebookPriv *priv = notebook->priv;
4483 gboolean retval = FALSE;
4487 gtk_notebook_do_arrow (notebook, priv->click_child);
4489 if (priv->need_timer)
4491 GtkSettings *settings;
4494 settings = gtk_widget_get_settings (GTK_WIDGET (notebook));
4495 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
4497 priv->need_timer = FALSE;
4498 priv->timer = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
4499 (GSourceFunc) gtk_notebook_timer,
4500 (gpointer) notebook);
4510 gtk_notebook_set_scroll_timer (GtkNotebook *notebook)
4512 GtkNotebookPriv *priv = notebook->priv;
4513 GtkWidget *widget = GTK_WIDGET (notebook);
4517 GtkSettings *settings = gtk_widget_get_settings (widget);
4520 g_object_get (settings, "gtk-timeout-initial", &timeout, NULL);
4522 priv->timer = gdk_threads_add_timeout (timeout,
4523 (GSourceFunc) gtk_notebook_timer,
4524 (gpointer) notebook);
4525 priv->need_timer = TRUE;
4530 gtk_notebook_page_compare (gconstpointer a,
4533 return (((GtkNotebookPage *) a)->child != b);
4537 gtk_notebook_find_child (GtkNotebook *notebook,
4539 const gchar *function)
4541 GtkNotebookPriv *priv = notebook->priv;
4542 GList *list = g_list_find_custom (priv->children, child,
4543 gtk_notebook_page_compare);
4545 #ifndef G_DISABLE_CHECKS
4546 if (!list && function)
4547 g_warning ("%s: unable to find child %p in notebook %p",
4548 function, child, notebook);
4555 gtk_notebook_remove_tab_label (GtkNotebook *notebook,
4556 GtkNotebookPage *page)
4558 if (page->tab_label)
4560 if (page->mnemonic_activate_signal)
4561 g_signal_handler_disconnect (page->tab_label,
4562 page->mnemonic_activate_signal);
4563 page->mnemonic_activate_signal = 0;
4565 gtk_widget_set_state (page->tab_label, GTK_STATE_NORMAL);
4566 gtk_widget_unparent (page->tab_label);
4567 page->tab_label = NULL;
4572 gtk_notebook_real_remove (GtkNotebook *notebook,
4575 GtkNotebookPriv *priv = notebook->priv;
4576 GtkNotebookPage *page;
4578 gint need_resize = FALSE;
4579 GtkWidget *tab_label;
4581 gboolean destroying;
4583 destroying = GTK_OBJECT_FLAGS (notebook) & GTK_IN_DESTRUCTION;
4585 next_list = gtk_notebook_search_page (notebook, list, STEP_NEXT, TRUE);
4587 next_list = gtk_notebook_search_page (notebook, list, STEP_PREV, TRUE);
4589 priv->children = g_list_remove_link (priv->children, list);
4591 if (priv->cur_page == list->data)
4593 priv->cur_page = NULL;
4594 if (next_list && !destroying)
4595 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (next_list));
4598 if (priv->detached_tab == list->data)
4599 priv->detached_tab = NULL;
4601 if (list == priv->first_tab)
4602 priv->first_tab = next_list;
4603 if (list == priv->focus_tab && !destroying)
4604 gtk_notebook_switch_focus_tab (notebook, next_list);
4608 g_signal_handler_disconnect (page->child, page->notify_visible_handler);
4610 if (gtk_widget_get_visible (page->child) &&
4611 gtk_widget_get_visible (GTK_WIDGET (notebook)))
4614 gtk_widget_unparent (page->child);
4616 tab_label = page->tab_label;
4619 g_object_ref (tab_label);
4620 gtk_notebook_remove_tab_label (notebook, page);
4622 gtk_widget_destroy (tab_label);
4623 g_object_unref (tab_label);
4628 GtkWidget *parent = page->menu_label->parent;
4630 gtk_notebook_menu_label_unparent (parent, NULL);
4631 gtk_container_remove (GTK_CONTAINER (priv->menu), parent);
4633 gtk_widget_queue_resize (priv->menu);
4635 if (!page->default_menu)
4636 g_object_unref (page->menu_label);
4640 if (page->last_focus_child)
4642 g_object_remove_weak_pointer (G_OBJECT (page->last_focus_child), (gpointer *)&page->last_focus_child);
4643 page->last_focus_child = NULL;
4646 g_slice_free (GtkNotebookPage, page);
4648 gtk_notebook_update_labels (notebook);
4650 gtk_widget_queue_resize (GTK_WIDGET (notebook));
4654 gtk_notebook_update_labels (GtkNotebook *notebook)
4656 GtkNotebookPriv *priv = notebook->priv;
4657 GtkNotebookPage *page;
4662 if (!priv->show_tabs && !priv->menu)
4665 for (list = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, FALSE);
4667 list = gtk_notebook_search_page (notebook, list, STEP_NEXT, FALSE))
4670 g_snprintf (string, sizeof(string), _("Page %u"), page_num++);
4671 if (priv->show_tabs)
4673 if (page->default_tab)
4675 if (!page->tab_label)
4677 page->tab_label = gtk_label_new (string);
4678 gtk_widget_set_parent (page->tab_label,
4679 GTK_WIDGET (notebook));
4682 gtk_label_set_text (GTK_LABEL (page->tab_label), string);
4685 if (gtk_widget_get_visible (page->child) &&
4686 !gtk_widget_get_visible (page->tab_label))
4687 gtk_widget_show (page->tab_label);
4688 else if (!gtk_widget_get_visible (page->child) &&
4689 gtk_widget_get_visible (page->tab_label))
4690 gtk_widget_hide (page->tab_label);
4692 if (priv->menu && page->default_menu)
4694 if (GTK_IS_LABEL (page->tab_label))
4695 gtk_label_set_text (GTK_LABEL (page->menu_label),
4696 gtk_label_get_label (GTK_LABEL (page->tab_label)));
4698 gtk_label_set_text (GTK_LABEL (page->menu_label), string);
4704 gtk_notebook_real_page_position (GtkNotebook *notebook,
4707 GtkNotebookPriv *priv = notebook->priv;
4711 for (work = priv->children, count_start = 0;
4712 work && work != list; work = work->next)
4713 if (GTK_NOTEBOOK_PAGE (work)->pack == GTK_PACK_START)
4719 if (GTK_NOTEBOOK_PAGE (list)->pack == GTK_PACK_START)
4722 return (count_start + g_list_length (list) - 1);
4726 gtk_notebook_search_page (GtkNotebook *notebook,
4729 gboolean find_visible)
4731 GtkNotebookPriv *priv = notebook->priv;
4732 GtkNotebookPage *page = NULL;
4733 GList *old_list = NULL;
4739 flag = GTK_PACK_END;
4743 flag = GTK_PACK_START;
4750 if (!page || page->pack == flag)
4758 list = priv->children;
4763 if (page->pack == flag &&
4765 (gtk_widget_get_visible (page->child) &&
4766 (!page->tab_label || NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page)))))
4781 if (page->pack != flag &&
4783 (gtk_widget_get_visible (page->child) &&
4784 (!page->tab_label || NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page)))))
4792 /* Private GtkNotebook Drawing Functions:
4794 * gtk_notebook_paint
4795 * gtk_notebook_draw_tab
4796 * gtk_notebook_draw_arrow
4799 gtk_notebook_paint (GtkWidget *widget,
4802 GtkNotebook *notebook;
4803 GtkNotebookPriv *priv;
4804 GtkNotebookPage *page;
4809 guint border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
4810 gint gap_x = 0, gap_width = 0, step = STEP_PREV;
4814 if (!gtk_widget_is_drawable (widget))
4817 notebook = GTK_NOTEBOOK (widget);
4818 priv = notebook->priv;
4819 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
4820 tab_pos = get_effective_tab_pos (notebook);
4822 if ((!priv->show_tabs && !priv->show_border) ||
4823 !priv->cur_page || !gtk_widget_get_visible (priv->cur_page->child))
4826 x = widget->allocation.x + border_width;
4827 y = widget->allocation.y + border_width;
4828 width = widget->allocation.width - border_width * 2;
4829 height = widget->allocation.height - border_width * 2;
4831 if (priv->show_border && (!priv->show_tabs || !priv->children))
4833 gtk_paint_box (widget->style, widget->window,
4834 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
4835 area, widget, "notebook",
4836 x, y, width, height);
4840 if (!priv->first_tab)
4841 priv->first_tab = priv->children;
4843 if (!gtk_widget_get_mapped (priv->cur_page->tab_label))
4844 page = GTK_NOTEBOOK_PAGE (priv->first_tab);
4846 page = priv->cur_page;
4851 y += page->allocation.height;
4853 case GTK_POS_BOTTOM:
4854 height -= page->allocation.height;
4857 x += page->allocation.width;
4860 width -= page->allocation.width;
4864 if (!NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, priv->cur_page) ||
4865 !gtk_widget_get_mapped (priv->cur_page->tab_label))
4875 case GTK_POS_BOTTOM:
4876 if (priv->operation == DRAG_OPERATION_REORDER)
4877 gap_x = priv->drag_window_x - widget->allocation.x - border_width;
4879 gap_x = priv->cur_page->allocation.x - widget->allocation.x - border_width;
4881 gap_width = priv->cur_page->allocation.width;
4882 step = is_rtl ? STEP_NEXT : STEP_PREV;
4886 if (priv->operation == DRAG_OPERATION_REORDER)
4887 gap_x = priv->drag_window_y - border_width - widget->allocation.y;
4889 gap_x = priv->cur_page->allocation.y - widget->allocation.y - border_width;
4891 gap_width = priv->cur_page->allocation.height;
4896 gtk_paint_box_gap (widget->style, widget->window,
4897 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
4898 area, widget, "notebook",
4899 x, y, width, height,
4900 tab_pos, gap_x, gap_width);
4903 children = gtk_notebook_search_page (notebook, NULL, step, TRUE);
4906 page = children->data;
4907 children = gtk_notebook_search_page (notebook, children,
4909 if (!gtk_widget_get_visible (page->child))
4911 if (!gtk_widget_get_mapped (page->tab_label))
4913 else if (page != priv->cur_page)
4914 gtk_notebook_draw_tab (notebook, page, area);
4917 if (showarrow && priv->scrollable)
4919 if (priv->has_before_previous)
4920 gtk_notebook_draw_arrow (notebook, ARROW_LEFT_BEFORE);
4921 if (priv->has_before_next)
4922 gtk_notebook_draw_arrow (notebook, ARROW_RIGHT_BEFORE);
4923 if (priv->has_after_previous)
4924 gtk_notebook_draw_arrow (notebook, ARROW_LEFT_AFTER);
4925 if (priv->has_after_next)
4926 gtk_notebook_draw_arrow (notebook, ARROW_RIGHT_AFTER);
4928 gtk_notebook_draw_tab (notebook, priv->cur_page, area);
4932 gtk_notebook_draw_tab (GtkNotebook *notebook,
4933 GtkNotebookPage *page,
4936 GtkNotebookPriv *priv;
4937 GdkRectangle child_area;
4938 GdkRectangle page_area;
4939 GtkStateType state_type;
4940 GtkPositionType gap_side;
4944 if (!NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) ||
4945 !gtk_widget_get_mapped (page->tab_label) ||
4946 (page->allocation.width == 0) || (page->allocation.height == 0))
4949 widget = GTK_WIDGET (notebook);
4950 priv = notebook->priv;
4952 if (priv->operation == DRAG_OPERATION_REORDER && page == priv->cur_page)
4953 window = priv->drag_window;
4955 window = widget->window;
4957 page_area.x = page->allocation.x;
4958 page_area.y = page->allocation.y;
4959 page_area.width = page->allocation.width;
4960 page_area.height = page->allocation.height;
4962 if (gdk_rectangle_intersect (&page_area, area, &child_area))
4964 gap_side = get_tab_gap_pos (notebook);
4966 if (priv->cur_page == page)
4967 state_type = GTK_STATE_NORMAL;
4969 state_type = GTK_STATE_ACTIVE;
4971 gtk_paint_extension (widget->style, window,
4972 state_type, GTK_SHADOW_OUT,
4973 area, widget, "tab",
4974 page_area.x, page_area.y,
4975 page_area.width, page_area.height,
4981 gtk_notebook_draw_arrow (GtkNotebook *notebook,
4982 GtkNotebookArrow nbarrow)
4984 GtkNotebookPriv *priv = notebook->priv;
4985 GtkStateType state_type;
4986 GtkShadowType shadow_type;
4988 GdkRectangle arrow_rect;
4990 gboolean is_rtl, left;
4992 widget = GTK_WIDGET (notebook);
4994 if (gtk_widget_is_drawable (widget))
4996 gint scroll_arrow_hlength;
4997 gint scroll_arrow_vlength;
5000 gtk_notebook_get_arrow_rect (notebook, &arrow_rect, nbarrow);
5002 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
5003 left = (ARROW_IS_LEFT (nbarrow) && !is_rtl) ||
5004 (!ARROW_IS_LEFT (nbarrow) && is_rtl);
5006 gtk_widget_style_get (widget,
5007 "scroll-arrow-hlength", &scroll_arrow_hlength,
5008 "scroll-arrow-vlength", &scroll_arrow_vlength,
5011 if (priv->in_child == nbarrow)
5013 if (priv->click_child == nbarrow)
5014 state_type = GTK_STATE_ACTIVE;
5016 state_type = GTK_STATE_PRELIGHT;
5019 state_type = gtk_widget_get_state (widget);
5021 if (priv->click_child == nbarrow)
5022 shadow_type = GTK_SHADOW_IN;
5024 shadow_type = GTK_SHADOW_OUT;
5026 if (priv->focus_tab &&
5027 !gtk_notebook_search_page (notebook, priv->focus_tab,
5028 left ? STEP_PREV : STEP_NEXT, TRUE))
5030 shadow_type = GTK_SHADOW_ETCHED_IN;
5031 state_type = GTK_STATE_INSENSITIVE;
5034 if (priv->tab_pos == GTK_POS_LEFT ||
5035 priv->tab_pos == GTK_POS_RIGHT)
5037 arrow = (ARROW_IS_LEFT (nbarrow) ? GTK_ARROW_UP : GTK_ARROW_DOWN);
5038 arrow_size = scroll_arrow_vlength;
5042 arrow = (ARROW_IS_LEFT (nbarrow) ? GTK_ARROW_LEFT : GTK_ARROW_RIGHT);
5043 arrow_size = scroll_arrow_hlength;
5046 gtk_paint_arrow (widget->style, widget->window, state_type,
5047 shadow_type, NULL, widget, "notebook",
5048 arrow, TRUE, arrow_rect.x, arrow_rect.y,
5049 arrow_size, arrow_size);
5053 /* Private GtkNotebook Size Allocate Functions:
5055 * gtk_notebook_tab_space
5056 * gtk_notebook_calculate_shown_tabs
5057 * gtk_notebook_calculate_tabs_allocation
5058 * gtk_notebook_pages_allocate
5059 * gtk_notebook_page_allocate
5060 * gtk_notebook_calc_tabs
5063 gtk_notebook_tab_space (GtkNotebook *notebook,
5064 gboolean *show_arrows,
5069 GtkNotebookPriv *priv = notebook->priv;
5072 gint tab_pos = get_effective_tab_pos (notebook);
5075 gint scroll_arrow_hlength;
5076 gint scroll_arrow_vlength;
5081 widget = GTK_WIDGET (notebook);
5082 children = priv->children;
5083 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
5085 gtk_widget_style_get (GTK_WIDGET (notebook),
5086 "arrow-spacing", &arrow_spacing,
5087 "scroll-arrow-hlength", &scroll_arrow_hlength,
5088 "scroll-arrow-vlength", &scroll_arrow_vlength,
5091 border_width = gtk_container_get_border_width (GTK_CONTAINER (notebook));
5096 case GTK_POS_BOTTOM:
5097 *min = widget->allocation.x + border_width;
5098 *max = widget->allocation.x + widget->allocation.width - border_width;
5100 for (i = 0; i < N_ACTION_WIDGETS; i++)
5102 if (priv->action_widget[i])
5104 if ((i == ACTION_WIDGET_START && !is_rtl) ||
5105 (i == ACTION_WIDGET_END && is_rtl))
5106 *min += priv->action_widget[i]->allocation.width + widget->style->xthickness;
5108 *max -= priv->action_widget[i]->allocation.width + widget->style->xthickness;
5114 GtkNotebookPage *page;
5116 page = children->data;
5117 children = children->next;
5119 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) &&
5120 gtk_widget_get_visible (page->child))
5121 *tab_space += page->requisition.width;
5126 *min = widget->allocation.y + border_width;
5127 *max = widget->allocation.y + widget->allocation.height - border_width;
5129 for (i = 0; i < N_ACTION_WIDGETS; i++)
5131 if (priv->action_widget[i])
5133 if (i == ACTION_WIDGET_START)
5134 *min += priv->action_widget[i]->allocation.height + widget->style->ythickness;
5136 *max -= priv->action_widget[i]->allocation.height + widget->style->ythickness;
5142 GtkNotebookPage *page;
5144 page = children->data;
5145 children = children->next;
5147 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) &&
5148 gtk_widget_get_visible (page->child))
5149 *tab_space += page->requisition.height;
5154 if (!priv->scrollable)
5155 *show_arrows = FALSE;
5158 gtk_widget_style_get (widget, "tab-overlap", &tab_overlap, NULL);
5163 case GTK_POS_BOTTOM:
5164 if (*tab_space > *max - *min - tab_overlap)
5166 *show_arrows = TRUE;
5168 /* take arrows into account */
5169 *tab_space = *max - *min - tab_overlap;
5171 if (priv->has_after_previous)
5173 *tab_space -= arrow_spacing + scroll_arrow_hlength;
5174 *max -= arrow_spacing + scroll_arrow_hlength;
5177 if (priv->has_after_next)
5179 *tab_space -= arrow_spacing + scroll_arrow_hlength;
5180 *max -= arrow_spacing + scroll_arrow_hlength;
5183 if (priv->has_before_previous)
5185 *tab_space -= arrow_spacing + scroll_arrow_hlength;
5186 *min += arrow_spacing + scroll_arrow_hlength;
5189 if (priv->has_before_next)
5191 *tab_space -= arrow_spacing + scroll_arrow_hlength;
5192 *min += arrow_spacing + scroll_arrow_hlength;
5198 if (*tab_space > *max - *min - tab_overlap)
5200 *show_arrows = TRUE;
5202 /* take arrows into account */
5203 *tab_space = *max - *min - tab_overlap;
5205 if (priv->has_after_previous || priv->has_after_next)
5207 *tab_space -= arrow_spacing + scroll_arrow_vlength;
5208 *max -= arrow_spacing + scroll_arrow_vlength;
5211 if (priv->has_before_previous || priv->has_before_next)
5213 *tab_space -= arrow_spacing + scroll_arrow_vlength;
5214 *min += arrow_spacing + scroll_arrow_vlength;
5223 gtk_notebook_calculate_shown_tabs (GtkNotebook *notebook,
5224 gboolean show_arrows,
5230 gint *remaining_space)
5232 GtkNotebookPriv *priv = notebook->priv;
5234 GtkContainer *container;
5236 GtkNotebookPage *page;
5237 gint tab_pos, tab_overlap;
5239 widget = GTK_WIDGET (notebook);
5240 container = GTK_CONTAINER (notebook);
5241 gtk_widget_style_get (widget, "tab-overlap", &tab_overlap, NULL);
5242 tab_pos = get_effective_tab_pos (notebook);
5244 if (show_arrows) /* first_tab <- focus_tab */
5246 *remaining_space = tab_space;
5248 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, priv->cur_page) &&
5249 gtk_widget_get_visible (priv->cur_page->child))
5251 gtk_notebook_calc_tabs (notebook,
5254 remaining_space, STEP_NEXT);
5257 if (tab_space <= 0 || *remaining_space <= 0)
5260 priv->first_tab = priv->focus_tab;
5261 *last_child = gtk_notebook_search_page (notebook, priv->focus_tab,
5263 page = priv->first_tab->data;
5264 *remaining_space = tab_space - page->requisition.width;
5271 if (priv->first_tab && priv->first_tab != priv->focus_tab)
5273 /* Is first_tab really predecessor of focus_tab? */
5274 page = priv->first_tab->data;
5275 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) &&
5276 gtk_widget_get_visible (page->child))
5277 for (children = priv->focus_tab;
5278 children && children != priv->first_tab;
5279 children = gtk_notebook_search_page (notebook,
5287 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, priv->cur_page))
5288 priv->first_tab = priv->focus_tab;
5290 priv->first_tab = gtk_notebook_search_page (notebook, priv->focus_tab,
5294 /* calculate shown tabs counting backwards from the focus tab */
5295 gtk_notebook_calc_tabs (notebook,
5296 gtk_notebook_search_page (notebook,
5300 &(priv->first_tab), remaining_space,
5303 if (*remaining_space < 0)
5306 gtk_notebook_search_page (notebook, priv->first_tab,
5308 if (!priv->first_tab)
5309 priv->first_tab = priv->focus_tab;
5311 *last_child = gtk_notebook_search_page (notebook, priv->focus_tab,
5314 else /* focus_tab -> end */
5316 if (!priv->first_tab)
5317 priv->first_tab = gtk_notebook_search_page (notebook,
5322 gtk_notebook_calc_tabs (notebook,
5323 gtk_notebook_search_page (notebook,
5327 &children, remaining_space, STEP_NEXT);
5329 if (*remaining_space <= 0)
5330 *last_child = children;
5331 else /* start <- first_tab */
5336 gtk_notebook_calc_tabs (notebook,
5337 gtk_notebook_search_page (notebook,
5341 &children, remaining_space, STEP_PREV);
5343 if (*remaining_space == 0)
5344 priv->first_tab = children;
5346 priv->first_tab = gtk_notebook_search_page(notebook,
5353 if (*remaining_space < 0)
5355 /* calculate number of tabs */
5356 *remaining_space = - (*remaining_space);
5359 for (children = priv->first_tab;
5360 children && children != *last_child;
5361 children = gtk_notebook_search_page (notebook, children,
5366 *remaining_space = 0;
5369 /* unmap all non-visible tabs */
5370 for (children = gtk_notebook_search_page (notebook, NULL,
5372 children && children != priv->first_tab;
5373 children = gtk_notebook_search_page (notebook, children,
5376 page = children->data;
5378 if (page->tab_label &&
5379 NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page))
5380 gtk_widget_set_child_visible (page->tab_label, FALSE);
5383 for (children = *last_child; children;
5384 children = gtk_notebook_search_page (notebook, children,
5387 page = children->data;
5389 if (page->tab_label &&
5390 NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page))
5391 gtk_widget_set_child_visible (page->tab_label, FALSE);
5394 else /* !show_arrows */
5399 *remaining_space = max - min - tab_overlap - tab_space;
5400 children = priv->children;
5401 priv->first_tab = gtk_notebook_search_page (notebook, NULL,
5405 page = children->data;
5406 children = children->next;
5408 if (!NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) ||
5409 !gtk_widget_get_visible (page->child))
5418 /* if notebook is homogeneous, all tabs are expanded */
5419 if (priv->homogeneous && *n)
5425 get_allocate_at_bottom (GtkWidget *widget,
5426 gint search_direction)
5428 gboolean is_rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
5429 gboolean tab_pos = get_effective_tab_pos (GTK_NOTEBOOK (widget));
5434 case GTK_POS_BOTTOM:
5436 return (search_direction == STEP_PREV);
5438 return (search_direction == STEP_NEXT);
5443 return (search_direction == STEP_PREV);
5451 gtk_notebook_calculate_tabs_allocation (GtkNotebook *notebook,
5456 gint *remaining_space,
5457 gint *expanded_tabs,
5461 GtkNotebookPriv *priv = notebook->priv;
5463 GtkContainer *container;
5464 GtkNotebookPage *page;
5465 gboolean allocate_at_bottom;
5466 gint tab_overlap, tab_pos, tab_extra_space;
5467 gint left_x, right_x, top_y, bottom_y, anchor;
5468 gint xthickness, ythickness;
5470 gboolean gap_left, packing_changed;
5471 GtkAllocation child_allocation = { 0, };
5473 widget = GTK_WIDGET (notebook);
5474 container = GTK_CONTAINER (notebook);
5475 gtk_widget_style_get (widget, "tab-overlap", &tab_overlap, NULL);
5476 tab_pos = get_effective_tab_pos (notebook);
5477 allocate_at_bottom = get_allocate_at_bottom (widget, direction);
5480 border_width = gtk_container_get_border_width (container);
5481 child_allocation.x = widget->allocation.x + border_width;
5482 child_allocation.y = widget->allocation.y + border_width;
5484 xthickness = widget->style->xthickness;
5485 ythickness = widget->style->ythickness;
5489 case GTK_POS_BOTTOM:
5490 child_allocation.y = widget->allocation.y + widget->allocation.height -
5491 priv->cur_page->requisition.height - border_width;
5494 child_allocation.x = (allocate_at_bottom) ? max : min;
5495 child_allocation.height = priv->cur_page->requisition.height;
5496 anchor = child_allocation.x;
5500 child_allocation.x = widget->allocation.x + widget->allocation.width -
5501 priv->cur_page->requisition.width - border_width;
5504 child_allocation.y = (allocate_at_bottom) ? max : min;
5505 child_allocation.width = priv->cur_page->requisition.width;
5506 anchor = child_allocation.y;
5510 left_x = CLAMP (priv->mouse_x - priv->drag_offset_x,
5511 min, max - priv->cur_page->allocation.width);
5512 top_y = CLAMP (priv->mouse_y - priv->drag_offset_y,
5513 min, max - priv->cur_page->allocation.height);
5514 right_x = left_x + priv->cur_page->allocation.width;
5515 bottom_y = top_y + priv->cur_page->allocation.height;
5516 gap_left = packing_changed = FALSE;
5518 while (*children && *children != last_child)
5520 page = (*children)->data;
5522 if (direction == STEP_NEXT && page->pack != GTK_PACK_START)
5526 else if (priv->operation == DRAG_OPERATION_REORDER)
5527 packing_changed = TRUE;
5530 if (direction == STEP_NEXT)
5531 *children = gtk_notebook_search_page (notebook, *children, direction, TRUE);
5534 *children = (*children)->next;
5536 if (page->pack != GTK_PACK_END || !gtk_widget_get_visible (page->child))
5540 if (!NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page))
5543 tab_extra_space = 0;
5544 if (*expanded_tabs && (showarrow || page->expand || priv->homogeneous))
5546 tab_extra_space = *remaining_space / *expanded_tabs;
5547 *remaining_space -= tab_extra_space;
5554 case GTK_POS_BOTTOM:
5555 child_allocation.width = page->requisition.width + tab_overlap + tab_extra_space;
5557 /* make sure that the reordered tab doesn't go past the last position */
5558 if (priv->operation == DRAG_OPERATION_REORDER &&
5559 !gap_left && packing_changed)
5561 if (!allocate_at_bottom)
5563 if ((priv->cur_page->pack == GTK_PACK_START && left_x >= anchor) ||
5564 (priv->cur_page->pack == GTK_PACK_END && left_x < anchor))
5566 left_x = priv->drag_window_x = anchor;
5567 anchor += priv->cur_page->allocation.width - tab_overlap;
5572 if ((priv->cur_page->pack == GTK_PACK_START && right_x <= anchor) ||
5573 (priv->cur_page->pack == GTK_PACK_END && right_x > anchor))
5575 anchor -= priv->cur_page->allocation.width;
5576 left_x = priv->drag_window_x = anchor;
5577 anchor += tab_overlap;
5584 if (priv->operation == DRAG_OPERATION_REORDER && page == priv->cur_page)
5586 priv->drag_window_x = left_x;
5587 priv->drag_window_y = child_allocation.y;
5591 if (allocate_at_bottom)
5592 anchor -= child_allocation.width;
5594 if (priv->operation == DRAG_OPERATION_REORDER && page->pack == priv->cur_page->pack)
5596 if (!allocate_at_bottom &&
5598 left_x <= anchor + child_allocation.width / 2)
5599 anchor += priv->cur_page->allocation.width - tab_overlap;
5600 else if (allocate_at_bottom &&
5601 right_x >= anchor + child_allocation.width / 2 &&
5602 right_x <= anchor + child_allocation.width)
5603 anchor -= priv->cur_page->allocation.width - tab_overlap;
5606 child_allocation.x = anchor;
5612 child_allocation.height = page->requisition.height + tab_overlap + tab_extra_space;
5614 /* make sure that the reordered tab doesn't go past the last position */
5615 if (priv->operation == DRAG_OPERATION_REORDER &&
5616 !gap_left && packing_changed)
5618 if (!allocate_at_bottom &&
5619 ((priv->cur_page->pack == GTK_PACK_START && top_y >= anchor) ||
5620 (priv->cur_page->pack == GTK_PACK_END && top_y < anchor)))
5622 top_y = priv->drag_window_y = anchor;
5623 anchor += priv->cur_page->allocation.height - tab_overlap;
5629 if (priv->operation == DRAG_OPERATION_REORDER && page == priv->cur_page)
5631 priv->drag_window_x = child_allocation.x;
5632 priv->drag_window_y = top_y;
5636 if (allocate_at_bottom)
5637 anchor -= child_allocation.height;
5639 if (priv->operation == DRAG_OPERATION_REORDER && page->pack == priv->cur_page->pack)
5641 if (!allocate_at_bottom &&
5643 top_y <= anchor + child_allocation.height / 2)
5644 anchor += priv->cur_page->allocation.height - tab_overlap;
5645 else if (allocate_at_bottom &&
5646 bottom_y >= anchor + child_allocation.height / 2 &&
5647 bottom_y <= anchor + child_allocation.height)
5648 anchor -= priv->cur_page->allocation.height - tab_overlap;
5651 child_allocation.y = anchor;
5657 page->allocation = child_allocation;
5659 if ((page == priv->detached_tab && priv->operation == DRAG_OPERATION_DETACH) ||
5660 (page == priv->cur_page && priv->operation == DRAG_OPERATION_REORDER))
5662 /* needs to be allocated at 0,0
5663 * to be shown in the drag window */
5664 page->allocation.x = 0;
5665 page->allocation.y = 0;
5668 if (page != priv->cur_page)
5673 page->allocation.y += ythickness;
5675 case GTK_POS_BOTTOM:
5676 page->allocation.height = MAX (1, page->allocation.height - ythickness);
5679 page->allocation.x += xthickness;
5682 page->allocation.width = MAX (1, page->allocation.width - xthickness);
5687 /* calculate whether to leave a gap based on reorder operation or not */
5691 case GTK_POS_BOTTOM:
5692 if (priv->operation != DRAG_OPERATION_REORDER ||
5693 (priv->operation == DRAG_OPERATION_REORDER && page != priv->cur_page))
5695 if (priv->operation == DRAG_OPERATION_REORDER)
5697 if (page->pack == priv->cur_page->pack &&
5698 !allocate_at_bottom &&
5699 left_x > anchor + child_allocation.width / 2 &&
5700 left_x <= anchor + child_allocation.width)
5701 anchor += priv->cur_page->allocation.width - tab_overlap;
5702 else if (page->pack == priv->cur_page->pack &&
5703 allocate_at_bottom &&
5704 right_x >= anchor &&
5705 right_x <= anchor + child_allocation.width / 2)
5706 anchor -= priv->cur_page->allocation.width - tab_overlap;
5709 if (!allocate_at_bottom)
5710 anchor += child_allocation.width - tab_overlap;
5712 anchor += tab_overlap;
5718 if (priv->operation != DRAG_OPERATION_REORDER ||
5719 (priv->operation == DRAG_OPERATION_REORDER && page != priv->cur_page))
5721 if (priv->operation == DRAG_OPERATION_REORDER)
5723 if (page->pack == priv->cur_page->pack &&
5724 !allocate_at_bottom &&
5725 top_y >= anchor + child_allocation.height / 2 &&
5726 top_y <= anchor + child_allocation.height)
5727 anchor += priv->cur_page->allocation.height - tab_overlap;
5728 else if (page->pack == priv->cur_page->pack &&
5729 allocate_at_bottom &&
5730 bottom_y >= anchor &&
5731 bottom_y <= anchor + child_allocation.height / 2)
5732 anchor -= priv->cur_page->allocation.height - tab_overlap;
5735 if (!allocate_at_bottom)
5736 anchor += child_allocation.height - tab_overlap;
5738 anchor += tab_overlap;
5744 /* set child visible */
5745 if (page->tab_label)
5746 gtk_widget_set_child_visible (page->tab_label, TRUE);
5749 /* Don't move the current tab past the last position during tabs reordering */
5751 priv->operation == DRAG_OPERATION_REORDER &&
5752 ((direction == STEP_NEXT && priv->cur_page->pack == GTK_PACK_START) ||
5753 ((direction == STEP_PREV || packing_changed) && priv->cur_page->pack == GTK_PACK_END)))
5758 case GTK_POS_BOTTOM:
5759 if (allocate_at_bottom)
5760 anchor -= priv->cur_page->allocation.width;
5762 if ((!allocate_at_bottom && priv->drag_window_x > anchor) ||
5763 (allocate_at_bottom && priv->drag_window_x < anchor))
5764 priv->drag_window_x = anchor;
5768 if (allocate_at_bottom)
5769 anchor -= priv->cur_page->allocation.height;
5771 if ((!allocate_at_bottom && priv->drag_window_y > anchor) ||
5772 (allocate_at_bottom && priv->drag_window_y < anchor))
5773 priv->drag_window_y = anchor;
5780 gtk_notebook_pages_allocate (GtkNotebook *notebook)
5782 GtkNotebookPriv *priv = notebook->priv;
5783 GList *children = NULL;
5784 GList *last_child = NULL;
5785 gboolean showarrow = FALSE;
5786 gint tab_space, min, max, remaining_space;
5788 gboolean tab_allocations_changed = FALSE;
5790 if (!priv->show_tabs || !priv->children || !priv->cur_page)
5793 min = max = tab_space = remaining_space = 0;
5796 gtk_notebook_tab_space (notebook, &showarrow,
5797 &min, &max, &tab_space);
5799 gtk_notebook_calculate_shown_tabs (notebook, showarrow,
5800 min, max, tab_space, &last_child,
5801 &expanded_tabs, &remaining_space);
5803 children = priv->first_tab;
5804 gtk_notebook_calculate_tabs_allocation (notebook, &children, last_child,
5805 showarrow, STEP_NEXT,
5806 &remaining_space, &expanded_tabs, min, max);
5807 if (children && children != last_child)
5809 children = priv->children;
5810 gtk_notebook_calculate_tabs_allocation (notebook, &children, last_child,
5811 showarrow, STEP_PREV,
5812 &remaining_space, &expanded_tabs, min, max);
5815 children = priv->children;
5819 if (gtk_notebook_page_allocate (notebook, GTK_NOTEBOOK_PAGE (children)))
5820 tab_allocations_changed = TRUE;
5821 children = children->next;
5824 if (!priv->first_tab)
5825 priv->first_tab = priv->children;
5827 if (tab_allocations_changed)
5828 gtk_notebook_redraw_tabs (notebook);
5832 gtk_notebook_page_allocate (GtkNotebook *notebook,
5833 GtkNotebookPage *page)
5835 GtkWidget *widget = GTK_WIDGET (notebook);
5836 GtkNotebookPriv *priv = notebook->priv;
5837 GtkAllocation child_allocation;
5838 GtkRequisition tab_requisition;
5844 gint tab_pos = get_effective_tab_pos (notebook);
5845 gboolean tab_allocation_changed;
5846 gboolean was_visible = page->tab_allocated_visible;
5848 if (!page->tab_label ||
5849 !gtk_widget_get_visible (page->tab_label) ||
5850 !gtk_widget_get_child_visible (page->tab_label))
5852 page->tab_allocated_visible = FALSE;
5856 xthickness = widget->style->xthickness;
5857 ythickness = widget->style->ythickness;
5859 gtk_widget_get_child_requisition (page->tab_label, &tab_requisition);
5860 gtk_widget_style_get (widget,
5861 "focus-line-width", &focus_width,
5862 "tab-curvature", &tab_curvature,
5867 case GTK_POS_BOTTOM:
5868 padding = tab_curvature + focus_width + priv->tab_hborder;
5871 child_allocation.x = xthickness + focus_width + priv->tab_hborder;
5872 child_allocation.width = MAX (1, page->allocation.width - 2 * child_allocation.x);
5873 child_allocation.x += page->allocation.x;
5877 child_allocation.x = page->allocation.x +
5878 (page->allocation.width - tab_requisition.width) / 2;
5880 child_allocation.width = tab_requisition.width;
5883 child_allocation.y = priv->tab_vborder + focus_width + page->allocation.y;
5885 if (tab_pos == GTK_POS_TOP)
5886 child_allocation.y += ythickness;
5888 child_allocation.height = MAX (1, (page->allocation.height - ythickness -
5889 2 * (priv->tab_vborder + focus_width)));
5893 padding = tab_curvature + focus_width + priv->tab_vborder;
5896 child_allocation.y = ythickness + padding;
5897 child_allocation.height = MAX (1, (page->allocation.height -
5898 2 * child_allocation.y));
5899 child_allocation.y += page->allocation.y;
5903 child_allocation.y = page->allocation.y +
5904 (page->allocation.height - tab_requisition.height) / 2;
5906 child_allocation.height = tab_requisition.height;
5909 child_allocation.x = priv->tab_hborder + focus_width + page->allocation.x;
5911 if (tab_pos == GTK_POS_LEFT)
5912 child_allocation.x += xthickness;
5914 child_allocation.width = MAX (1, (page->allocation.width - xthickness -
5915 2 * (priv->tab_hborder + focus_width)));
5919 tab_allocation_changed = (child_allocation.x != page->tab_label->allocation.x ||
5920 child_allocation.y != page->tab_label->allocation.y ||
5921 child_allocation.width != page->tab_label->allocation.width ||
5922 child_allocation.height != page->tab_label->allocation.height);
5924 gtk_widget_size_allocate (page->tab_label, &child_allocation);
5928 page->tab_allocated_visible = TRUE;
5929 tab_allocation_changed = TRUE;
5932 return tab_allocation_changed;
5936 gtk_notebook_calc_tabs (GtkNotebook *notebook,
5942 GtkNotebookPage *page = NULL;
5944 GList *last_list = NULL;
5945 GList *last_calculated_child = NULL;
5947 gint tab_pos = get_effective_tab_pos (notebook);
5948 guint real_direction;
5954 pack = GTK_NOTEBOOK_PAGE (start)->pack;
5955 if (pack == GTK_PACK_END)
5956 real_direction = (direction == STEP_PREV) ? STEP_NEXT : STEP_PREV;
5958 real_direction = direction;
5965 case GTK_POS_BOTTOM:
5968 page = children->data;
5969 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) &&
5970 gtk_widget_get_visible (page->child))
5972 if (page->pack == pack)
5974 *tab_space -= page->requisition.width;
5975 if (*tab_space < 0 || children == *end)
5979 *tab_space = - (*tab_space +
5980 page->requisition.width);
5982 if (*tab_space == 0 && direction == STEP_PREV)
5983 children = last_calculated_child;
5990 last_calculated_child = children;
5992 last_list = children;
5994 if (real_direction == STEP_NEXT)
5995 children = children->next;
5997 children = children->prev;
6004 page = children->data;
6005 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) &&
6006 gtk_widget_get_visible (page->child))
6008 if (page->pack == pack)
6010 *tab_space -= page->requisition.height;
6011 if (*tab_space < 0 || children == *end)
6015 *tab_space = - (*tab_space +
6016 page->requisition.height);
6018 if (*tab_space == 0 && direction == STEP_PREV)
6019 children = last_calculated_child;
6026 last_calculated_child = children;
6028 last_list = children;
6030 if (real_direction == STEP_NEXT)
6031 children = children->next;
6033 children = children->prev;
6037 if (real_direction == STEP_PREV)
6039 pack = (pack == GTK_PACK_END) ? GTK_PACK_START : GTK_PACK_END;
6040 real_direction = STEP_PREV;
6041 children = last_list;
6046 gtk_notebook_update_tab_states (GtkNotebook *notebook)
6048 GtkNotebookPriv *priv = notebook->priv;
6051 for (list = priv->children; list != NULL; list = list->next)
6053 GtkNotebookPage *page = list->data;
6055 if (page->tab_label)
6057 if (page == priv->cur_page)
6058 gtk_widget_set_state (page->tab_label, GTK_STATE_NORMAL);
6060 gtk_widget_set_state (page->tab_label, GTK_STATE_ACTIVE);
6065 /* Private GtkNotebook Page Switch Methods:
6067 * gtk_notebook_real_switch_page
6070 gtk_notebook_real_switch_page (GtkNotebook *notebook,
6074 GtkNotebookPriv *priv = notebook->priv;
6075 GList *list = gtk_notebook_find_child (notebook, GTK_WIDGET (child), NULL);
6076 GtkNotebookPage *page = GTK_NOTEBOOK_PAGE (list);
6077 gboolean child_has_focus;
6079 if (priv->cur_page == page || !gtk_widget_get_visible (GTK_WIDGET (child)))
6082 /* save the value here, changing visibility changes focus */
6083 child_has_focus = priv->child_has_focus;
6086 gtk_widget_set_child_visible (priv->cur_page->child, FALSE);
6088 priv->cur_page = page;
6090 if (!priv->focus_tab ||
6091 priv->focus_tab->data != (gpointer) priv->cur_page)
6093 g_list_find (priv->children, priv->cur_page);
6095 gtk_widget_set_child_visible (priv->cur_page->child, TRUE);
6097 /* If the focus was on the previous page, move it to the first
6098 * element on the new page, if possible, or if not, to the
6101 if (child_has_focus)
6103 if (priv->cur_page->last_focus_child &&
6104 gtk_widget_is_ancestor (priv->cur_page->last_focus_child, priv->cur_page->child))
6105 gtk_widget_grab_focus (priv->cur_page->last_focus_child);
6107 if (!gtk_widget_child_focus (priv->cur_page->child, GTK_DIR_TAB_FORWARD))
6108 gtk_widget_grab_focus (GTK_WIDGET (notebook));
6111 gtk_notebook_update_tab_states (notebook);
6112 gtk_widget_queue_resize (GTK_WIDGET (notebook));
6113 g_object_notify (G_OBJECT (notebook), "page");
6116 /* Private GtkNotebook Page Switch Functions:
6118 * gtk_notebook_switch_page
6119 * gtk_notebook_page_select
6120 * gtk_notebook_switch_focus_tab
6121 * gtk_notebook_menu_switch_page
6124 gtk_notebook_switch_page (GtkNotebook *notebook,
6125 GtkNotebookPage *page)
6127 GtkNotebookPriv *priv = notebook->priv;
6130 if (priv->cur_page == page)
6133 page_num = g_list_index (priv->children, page);
6135 g_signal_emit (notebook,
6136 notebook_signals[SWITCH_PAGE],
6143 gtk_notebook_page_select (GtkNotebook *notebook,
6144 gboolean move_focus)
6146 GtkNotebookPriv *priv = notebook->priv;
6147 GtkNotebookPage *page;
6148 GtkDirectionType dir = GTK_DIR_DOWN; /* Quiet GCC */
6149 gint tab_pos = get_effective_tab_pos (notebook);
6151 if (!priv->focus_tab)
6154 page = priv->focus_tab->data;
6155 gtk_notebook_switch_page (notebook, page);
6164 case GTK_POS_BOTTOM:
6168 dir = GTK_DIR_RIGHT;
6175 if (gtk_widget_child_focus (page->child, dir))
6182 gtk_notebook_switch_focus_tab (GtkNotebook *notebook,
6185 GtkNotebookPriv *priv = notebook->priv;
6187 GtkNotebookPage *page;
6189 if (priv->focus_tab == new_child)
6192 old_child = priv->focus_tab;
6193 priv->focus_tab = new_child;
6195 if (priv->scrollable)
6196 gtk_notebook_redraw_arrows (notebook);
6198 if (!priv->show_tabs || !priv->focus_tab)
6201 page = priv->focus_tab->data;
6202 if (gtk_widget_get_mapped (page->tab_label))
6203 gtk_notebook_redraw_tabs (notebook);
6205 gtk_notebook_pages_allocate (notebook);
6207 gtk_notebook_switch_page (notebook, page);
6211 gtk_notebook_menu_switch_page (GtkWidget *widget,
6212 GtkNotebookPage *page)
6214 GtkNotebookPriv *priv;
6215 GtkNotebook *notebook;
6219 notebook = GTK_NOTEBOOK (gtk_menu_get_attach_widget
6220 (GTK_MENU (widget->parent)));
6221 priv = notebook->priv;
6223 if (priv->cur_page == page)
6227 children = priv->children;
6228 while (children && children->data != page)
6230 children = children->next;
6234 g_signal_emit (notebook,
6235 notebook_signals[SWITCH_PAGE],
6241 /* Private GtkNotebook Menu Functions:
6243 * gtk_notebook_menu_item_create
6244 * gtk_notebook_menu_label_unparent
6245 * gtk_notebook_menu_detacher
6248 gtk_notebook_menu_item_create (GtkNotebook *notebook,
6251 GtkNotebookPriv *priv = notebook->priv;
6252 GtkNotebookPage *page;
6253 GtkWidget *menu_item;
6256 if (page->default_menu)
6258 if (GTK_IS_LABEL (page->tab_label))
6259 page->menu_label = gtk_label_new (gtk_label_get_label (GTK_LABEL (page->tab_label)));
6261 page->menu_label = gtk_label_new ("");
6262 gtk_misc_set_alignment (GTK_MISC (page->menu_label), 0.0, 0.5);
6265 gtk_widget_show (page->menu_label);
6266 menu_item = gtk_menu_item_new ();
6267 gtk_container_add (GTK_CONTAINER (menu_item), page->menu_label);
6268 gtk_menu_shell_insert (GTK_MENU_SHELL (priv->menu), menu_item,
6269 gtk_notebook_real_page_position (notebook, list));
6270 g_signal_connect (menu_item, "activate",
6271 G_CALLBACK (gtk_notebook_menu_switch_page), page);
6272 if (gtk_widget_get_visible (page->child))
6273 gtk_widget_show (menu_item);
6277 gtk_notebook_menu_label_unparent (GtkWidget *widget,
6280 gtk_widget_unparent (gtk_bin_get_child (GTK_BIN (widget)));
6281 _gtk_bin_set_child (GTK_BIN (widget), NULL);
6285 gtk_notebook_menu_detacher (GtkWidget *widget,
6288 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
6289 GtkNotebookPriv *priv = notebook->priv;
6291 g_return_if_fail (priv->menu == (GtkWidget*) menu);
6296 /* Public GtkNotebook Page Insert/Remove Methods :
6298 * gtk_notebook_append_page
6299 * gtk_notebook_append_page_menu
6300 * gtk_notebook_prepend_page
6301 * gtk_notebook_prepend_page_menu
6302 * gtk_notebook_insert_page
6303 * gtk_notebook_insert_page_menu
6304 * gtk_notebook_remove_page
6307 * gtk_notebook_append_page:
6308 * @notebook: a #GtkNotebook
6309 * @child: the #GtkWidget to use as the contents of the page.
6310 * @tab_label: (allow-none): the #GtkWidget to be used as the label for the page,
6311 * or %NULL to use the default label, 'page N'.
6313 * Appends a page to @notebook.
6315 * Return value: the index (starting from 0) of the appended
6316 * page in the notebook, or -1 if function fails
6319 gtk_notebook_append_page (GtkNotebook *notebook,
6321 GtkWidget *tab_label)
6323 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6324 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6325 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6327 return gtk_notebook_insert_page_menu (notebook, child, tab_label, NULL, -1);
6331 * gtk_notebook_append_page_menu:
6332 * @notebook: a #GtkNotebook
6333 * @child: the #GtkWidget to use as the contents of the page.
6334 * @tab_label: (allow-none): the #GtkWidget to be used as the label for the page,
6335 * or %NULL to use the default label, 'page N'.
6336 * @menu_label: (allow-none): the widget to use as a label for the page-switch
6337 * menu, if that is enabled. If %NULL, and @tab_label
6338 * is a #GtkLabel or %NULL, then the menu label will be
6339 * a newly created label with the same text as @tab_label;
6340 * If @tab_label is not a #GtkLabel, @menu_label must be
6341 * specified if the page-switch menu is to be used.
6343 * Appends a page to @notebook, specifying the widget to use as the
6344 * label in the popup menu.
6346 * Return value: the index (starting from 0) of the appended
6347 * page in the notebook, or -1 if function fails
6350 gtk_notebook_append_page_menu (GtkNotebook *notebook,
6352 GtkWidget *tab_label,
6353 GtkWidget *menu_label)
6355 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6356 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6357 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6358 g_return_val_if_fail (menu_label == NULL || GTK_IS_WIDGET (menu_label), -1);
6360 return gtk_notebook_insert_page_menu (notebook, child, tab_label, menu_label, -1);
6364 * gtk_notebook_prepend_page:
6365 * @notebook: a #GtkNotebook
6366 * @child: the #GtkWidget to use as the contents of the page.
6367 * @tab_label: (allow-none): the #GtkWidget to be used as the label for the page,
6368 * or %NULL to use the default label, 'page N'.
6370 * Prepends a page to @notebook.
6372 * Return value: the index (starting from 0) of the prepended
6373 * page in the notebook, or -1 if function fails
6376 gtk_notebook_prepend_page (GtkNotebook *notebook,
6378 GtkWidget *tab_label)
6380 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6381 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6382 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6384 return gtk_notebook_insert_page_menu (notebook, child, tab_label, NULL, 0);
6388 * gtk_notebook_prepend_page_menu:
6389 * @notebook: a #GtkNotebook
6390 * @child: the #GtkWidget to use as the contents of the page.
6391 * @tab_label: (allow-none): the #GtkWidget to be used as the label for the page,
6392 * or %NULL to use the default label, 'page N'.
6393 * @menu_label: (allow-none): the widget to use as a label for the page-switch
6394 * menu, if that is enabled. If %NULL, and @tab_label
6395 * is a #GtkLabel or %NULL, then the menu label will be
6396 * a newly created label with the same text as @tab_label;
6397 * If @tab_label is not a #GtkLabel, @menu_label must be
6398 * specified if the page-switch menu is to be used.
6400 * Prepends a page to @notebook, specifying the widget to use as the
6401 * label in the popup menu.
6403 * Return value: the index (starting from 0) of the prepended
6404 * page in the notebook, or -1 if function fails
6407 gtk_notebook_prepend_page_menu (GtkNotebook *notebook,
6409 GtkWidget *tab_label,
6410 GtkWidget *menu_label)
6412 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6413 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6414 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6415 g_return_val_if_fail (menu_label == NULL || GTK_IS_WIDGET (menu_label), -1);
6417 return gtk_notebook_insert_page_menu (notebook, child, tab_label, menu_label, 0);
6421 * gtk_notebook_insert_page:
6422 * @notebook: a #GtkNotebook
6423 * @child: the #GtkWidget to use as the contents of the page.
6424 * @tab_label: (allow-none): the #GtkWidget to be used as the label for the page,
6425 * or %NULL to use the default label, 'page N'.
6426 * @position: the index (starting at 0) at which to insert the page,
6427 * or -1 to append the page after all other pages.
6429 * Insert a page into @notebook at the given position.
6431 * Return value: the index (starting from 0) of the inserted
6432 * page in the notebook, or -1 if function fails
6435 gtk_notebook_insert_page (GtkNotebook *notebook,
6437 GtkWidget *tab_label,
6440 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6441 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6442 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6444 return gtk_notebook_insert_page_menu (notebook, child, tab_label, NULL, position);
6449 gtk_notebook_page_compare_tab (gconstpointer a,
6452 return (((GtkNotebookPage *) a)->tab_label != b);
6456 gtk_notebook_mnemonic_activate_switch_page (GtkWidget *child,
6460 GtkNotebook *notebook = GTK_NOTEBOOK (data);
6461 GtkNotebookPriv *priv = notebook->priv;
6464 list = g_list_find_custom (priv->children, child,
6465 gtk_notebook_page_compare_tab);
6468 GtkNotebookPage *page = list->data;
6470 gtk_widget_grab_focus (GTK_WIDGET (notebook)); /* Do this first to avoid focusing new page */
6471 gtk_notebook_switch_page (notebook, page);
6472 focus_tabs_in (notebook);
6479 * gtk_notebook_insert_page_menu:
6480 * @notebook: a #GtkNotebook
6481 * @child: the #GtkWidget to use as the contents of the page.
6482 * @tab_label: (allow-none): the #GtkWidget to be used as the label for the page,
6483 * or %NULL to use the default label, 'page N'.
6484 * @menu_label: (allow-none): the widget to use as a label for the page-switch
6485 * menu, if that is enabled. If %NULL, and @tab_label
6486 * is a #GtkLabel or %NULL, then the menu label will be
6487 * a newly created label with the same text as @tab_label;
6488 * If @tab_label is not a #GtkLabel, @menu_label must be
6489 * specified if the page-switch menu is to be used.
6490 * @position: the index (starting at 0) at which to insert the page,
6491 * or -1 to append the page after all other pages.
6493 * Insert a page into @notebook at the given position, specifying
6494 * the widget to use as the label in the popup menu.
6496 * Return value: the index (starting from 0) of the inserted
6497 * page in the notebook
6500 gtk_notebook_insert_page_menu (GtkNotebook *notebook,
6502 GtkWidget *tab_label,
6503 GtkWidget *menu_label,
6506 GtkNotebookClass *class;
6508 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6509 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6510 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6511 g_return_val_if_fail (menu_label == NULL || GTK_IS_WIDGET (menu_label), -1);
6513 class = GTK_NOTEBOOK_GET_CLASS (notebook);
6515 return (class->insert_page) (notebook, child, tab_label, menu_label, position);
6519 * gtk_notebook_remove_page:
6520 * @notebook: a #GtkNotebook.
6521 * @page_num: the index of a notebook page, starting
6522 * from 0. If -1, the last page will
6525 * Removes a page from the notebook given its index
6529 gtk_notebook_remove_page (GtkNotebook *notebook,
6532 GtkNotebookPriv *priv;
6535 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6537 priv = notebook->priv;
6540 list = g_list_nth (priv->children, page_num);
6542 list = g_list_last (priv->children);
6545 gtk_container_remove (GTK_CONTAINER (notebook),
6546 ((GtkNotebookPage *) list->data)->child);
6549 /* Public GtkNotebook Page Switch Methods :
6550 * gtk_notebook_get_current_page
6551 * gtk_notebook_page_num
6552 * gtk_notebook_set_current_page
6553 * gtk_notebook_next_page
6554 * gtk_notebook_prev_page
6557 * gtk_notebook_get_current_page:
6558 * @notebook: a #GtkNotebook
6560 * Returns the page number of the current page.
6562 * Return value: the index (starting from 0) of the current
6563 * page in the notebook. If the notebook has no pages, then
6564 * -1 will be returned.
6567 gtk_notebook_get_current_page (GtkNotebook *notebook)
6569 GtkNotebookPriv *priv;
6571 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6573 priv = notebook->priv;
6575 if (!priv->cur_page)
6578 return g_list_index (priv->children, priv->cur_page);
6582 * gtk_notebook_get_nth_page:
6583 * @notebook: a #GtkNotebook
6584 * @page_num: the index of a page in the notebook, or -1
6585 * to get the last page.
6587 * Returns the child widget contained in page number @page_num.
6589 * Return value: (transfer none): the child widget, or %NULL if @page_num is
6593 gtk_notebook_get_nth_page (GtkNotebook *notebook,
6596 GtkNotebookPriv *priv;
6597 GtkNotebookPage *page;
6600 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
6602 priv = notebook->priv;
6605 list = g_list_nth (priv->children, page_num);
6607 list = g_list_last (priv->children);
6619 * gtk_notebook_get_n_pages:
6620 * @notebook: a #GtkNotebook
6622 * Gets the number of pages in a notebook.
6624 * Return value: the number of pages in the notebook.
6629 gtk_notebook_get_n_pages (GtkNotebook *notebook)
6631 GtkNotebookPriv *priv;
6633 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), 0);
6635 priv = notebook->priv;
6637 return g_list_length (priv->children);
6641 * gtk_notebook_page_num:
6642 * @notebook: a #GtkNotebook
6643 * @child: a #GtkWidget
6645 * Finds the index of the page which contains the given child
6648 * Return value: the index of the page containing @child, or
6649 * -1 if @child is not in the notebook.
6652 gtk_notebook_page_num (GtkNotebook *notebook,
6655 GtkNotebookPriv *priv;
6659 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6661 priv = notebook->priv;
6664 children = priv->children;
6667 GtkNotebookPage *page = children->data;
6669 if (page->child == child)
6672 children = children->next;
6680 * gtk_notebook_set_current_page:
6681 * @notebook: a #GtkNotebook
6682 * @page_num: index of the page to switch to, starting from 0.
6683 * If negative, the last page will be used. If greater
6684 * than the number of pages in the notebook, nothing
6687 * Switches to the page number @page_num.
6689 * Note that due to historical reasons, GtkNotebook refuses
6690 * to switch to a page unless the child widget is visible.
6691 * Therefore, it is recommended to show child widgets before
6692 * adding them to a notebook.
6695 gtk_notebook_set_current_page (GtkNotebook *notebook,
6698 GtkNotebookPriv *priv;
6701 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6703 priv = notebook->priv;
6706 page_num = g_list_length (priv->children) - 1;
6708 list = g_list_nth (priv->children, page_num);
6710 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (list));
6714 * gtk_notebook_next_page:
6715 * @notebook: a #GtkNotebook
6717 * Switches to the next page. Nothing happens if the current page is
6721 gtk_notebook_next_page (GtkNotebook *notebook)
6723 GtkNotebookPriv *priv;
6726 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6728 priv = notebook->priv;
6730 list = g_list_find (priv->children, priv->cur_page);
6734 list = gtk_notebook_search_page (notebook, list, STEP_NEXT, TRUE);
6738 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (list));
6742 * gtk_notebook_prev_page:
6743 * @notebook: a #GtkNotebook
6745 * Switches to the previous page. Nothing happens if the current page
6746 * is the first page.
6749 gtk_notebook_prev_page (GtkNotebook *notebook)
6751 GtkNotebookPriv *priv;
6754 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6756 priv = notebook->priv;
6758 list = g_list_find (priv->children, priv->cur_page);
6762 list = gtk_notebook_search_page (notebook, list, STEP_PREV, TRUE);
6766 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (list));
6769 /* Public GtkNotebook/Tab Style Functions
6771 * gtk_notebook_set_show_border
6772 * gtk_notebook_set_show_tabs
6773 * gtk_notebook_set_tab_pos
6774 * gtk_notebook_set_homogeneous_tabs
6775 * gtk_notebook_set_tab_border
6776 * gtk_notebook_set_tab_hborder
6777 * gtk_notebook_set_tab_vborder
6778 * gtk_notebook_set_scrollable
6781 * gtk_notebook_set_show_border:
6782 * @notebook: a #GtkNotebook
6783 * @show_border: %TRUE if a bevel should be drawn around the notebook.
6785 * Sets whether a bevel will be drawn around the notebook pages.
6786 * This only has a visual effect when the tabs are not shown.
6787 * See gtk_notebook_set_show_tabs().
6790 gtk_notebook_set_show_border (GtkNotebook *notebook,
6791 gboolean show_border)
6793 GtkNotebookPriv *priv;
6795 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6797 priv = notebook->priv;
6799 if (priv->show_border != show_border)
6801 priv->show_border = show_border;
6803 if (gtk_widget_get_visible (GTK_WIDGET (notebook)))
6804 gtk_widget_queue_resize (GTK_WIDGET (notebook));
6806 g_object_notify (G_OBJECT (notebook), "show-border");
6811 * gtk_notebook_get_show_border:
6812 * @notebook: a #GtkNotebook
6814 * Returns whether a bevel will be drawn around the notebook pages. See
6815 * gtk_notebook_set_show_border().
6817 * Return value: %TRUE if the bevel is drawn
6820 gtk_notebook_get_show_border (GtkNotebook *notebook)
6822 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
6824 return notebook->priv->show_border;
6828 * gtk_notebook_set_show_tabs:
6829 * @notebook: a #GtkNotebook
6830 * @show_tabs: %TRUE if the tabs should be shown.
6832 * Sets whether to show the tabs for the notebook or not.
6835 gtk_notebook_set_show_tabs (GtkNotebook *notebook,
6838 GtkNotebookPriv *priv;
6839 GtkNotebookPage *page;
6843 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6845 priv = notebook->priv;
6847 show_tabs = show_tabs != FALSE;
6849 if (priv->show_tabs == show_tabs)
6852 priv->show_tabs = show_tabs;
6853 children = priv->children;
6857 gtk_widget_set_can_focus (GTK_WIDGET (notebook), FALSE);
6861 page = children->data;
6862 children = children->next;
6863 if (page->default_tab)
6865 gtk_widget_destroy (page->tab_label);
6866 page->tab_label = NULL;
6869 gtk_widget_hide (page->tab_label);
6874 gtk_widget_set_can_focus (GTK_WIDGET (notebook), TRUE);
6875 gtk_notebook_update_labels (notebook);
6878 for (i = 0; i < N_ACTION_WIDGETS; i++)
6880 if (priv->action_widget[i])
6881 gtk_widget_set_child_visible (priv->action_widget[i], show_tabs);
6884 gtk_widget_queue_resize (GTK_WIDGET (notebook));
6886 g_object_notify (G_OBJECT (notebook), "show-tabs");
6890 * gtk_notebook_get_show_tabs:
6891 * @notebook: a #GtkNotebook
6893 * Returns whether the tabs of the notebook are shown. See
6894 * gtk_notebook_set_show_tabs().
6896 * Return value: %TRUE if the tabs are shown
6899 gtk_notebook_get_show_tabs (GtkNotebook *notebook)
6901 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
6903 return notebook->priv->show_tabs;
6907 * gtk_notebook_set_tab_pos:
6908 * @notebook: a #GtkNotebook.
6909 * @pos: the edge to draw the tabs at.
6911 * Sets the edge at which the tabs for switching pages in the
6912 * notebook are drawn.
6915 gtk_notebook_set_tab_pos (GtkNotebook *notebook,
6916 GtkPositionType pos)
6918 GtkNotebookPriv *priv;
6920 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6922 priv = notebook->priv;
6924 if (priv->tab_pos != pos)
6926 priv->tab_pos = pos;
6927 if (gtk_widget_get_visible (GTK_WIDGET (notebook)))
6928 gtk_widget_queue_resize (GTK_WIDGET (notebook));
6931 g_object_notify (G_OBJECT (notebook), "tab-pos");
6935 * gtk_notebook_get_tab_pos:
6936 * @notebook: a #GtkNotebook
6938 * Gets the edge at which the tabs for switching pages in the
6939 * notebook are drawn.
6941 * Return value: the edge at which the tabs are drawn
6944 gtk_notebook_get_tab_pos (GtkNotebook *notebook)
6946 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), GTK_POS_TOP);
6948 return notebook->priv->tab_pos;
6952 * gtk_notebook_set_scrollable:
6953 * @notebook: a #GtkNotebook
6954 * @scrollable: %TRUE if scroll arrows should be added
6956 * Sets whether the tab label area will have arrows for scrolling if
6957 * there are too many tabs to fit in the area.
6960 gtk_notebook_set_scrollable (GtkNotebook *notebook,
6961 gboolean scrollable)
6963 GtkNotebookPriv *priv;
6965 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6967 priv = notebook->priv;
6969 scrollable = (scrollable != FALSE);
6971 if (scrollable != priv->scrollable)
6973 priv->scrollable = scrollable;
6975 if (gtk_widget_get_visible (GTK_WIDGET (notebook)))
6976 gtk_widget_queue_resize (GTK_WIDGET (notebook));
6978 g_object_notify (G_OBJECT (notebook), "scrollable");
6983 * gtk_notebook_get_scrollable:
6984 * @notebook: a #GtkNotebook
6986 * Returns whether the tab label area has arrows for scrolling. See
6987 * gtk_notebook_set_scrollable().
6989 * Return value: %TRUE if arrows for scrolling are present
6992 gtk_notebook_get_scrollable (GtkNotebook *notebook)
6994 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
6996 return notebook->priv->scrollable;
6999 /* Public GtkNotebook Popup Menu Methods:
7001 * gtk_notebook_popup_enable
7002 * gtk_notebook_popup_disable
7007 * gtk_notebook_popup_enable:
7008 * @notebook: a #GtkNotebook
7010 * Enables the popup menu: if the user clicks with the right mouse button on
7011 * the tab labels, a menu with all the pages will be popped up.
7014 gtk_notebook_popup_enable (GtkNotebook *notebook)
7016 GtkNotebookPriv *priv;
7019 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7021 priv = notebook->priv;
7026 priv->menu = gtk_menu_new ();
7027 for (list = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, FALSE);
7029 list = gtk_notebook_search_page (notebook, list, STEP_NEXT, FALSE))
7030 gtk_notebook_menu_item_create (notebook, list);
7032 gtk_notebook_update_labels (notebook);
7033 gtk_menu_attach_to_widget (GTK_MENU (priv->menu),
7034 GTK_WIDGET (notebook),
7035 gtk_notebook_menu_detacher);
7037 g_object_notify (G_OBJECT (notebook), "enable-popup");
7041 * gtk_notebook_popup_disable:
7042 * @notebook: a #GtkNotebook
7044 * Disables the popup menu.
7047 gtk_notebook_popup_disable (GtkNotebook *notebook)
7049 GtkNotebookPriv *priv;
7051 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7053 priv = notebook->priv;
7058 gtk_container_foreach (GTK_CONTAINER (priv->menu),
7059 (GtkCallback) gtk_notebook_menu_label_unparent, NULL);
7060 gtk_widget_destroy (priv->menu);
7062 g_object_notify (G_OBJECT (notebook), "enable-popup");
7065 /* Public GtkNotebook Page Properties Functions:
7067 * gtk_notebook_get_tab_label
7068 * gtk_notebook_set_tab_label
7069 * gtk_notebook_set_tab_label_text
7070 * gtk_notebook_get_menu_label
7071 * gtk_notebook_set_menu_label
7072 * gtk_notebook_set_menu_label_text
7073 * gtk_notebook_set_tab_label_packing
7074 * gtk_notebook_query_tab_label_packing
7075 * gtk_notebook_get_tab_reorderable
7076 * gtk_notebook_set_tab_reorderable
7077 * gtk_notebook_get_tab_detachable
7078 * gtk_notebook_set_tab_detachable
7082 * gtk_notebook_get_tab_label:
7083 * @notebook: a #GtkNotebook
7086 * Returns the tab label widget for the page @child. %NULL is returned
7087 * if @child is not in @notebook or if no tab label has specifically
7088 * been set for @child.
7090 * Return value: (transfer none): the tab label
7093 gtk_notebook_get_tab_label (GtkNotebook *notebook,
7098 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
7099 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
7101 list = CHECK_FIND_CHILD (notebook, child);
7105 if (GTK_NOTEBOOK_PAGE (list)->default_tab)
7108 return GTK_NOTEBOOK_PAGE (list)->tab_label;
7112 * gtk_notebook_set_tab_label:
7113 * @notebook: a #GtkNotebook
7115 * @tab_label: (allow-none): the tab label widget to use, or %NULL for default tab
7118 * Changes the tab label for @child. If %NULL is specified
7119 * for @tab_label, then the page will have the label 'page N'.
7122 gtk_notebook_set_tab_label (GtkNotebook *notebook,
7124 GtkWidget *tab_label)
7126 GtkNotebookPriv *priv;
7127 GtkNotebookPage *page;
7130 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7131 g_return_if_fail (GTK_IS_WIDGET (child));
7133 priv = notebook->priv;
7135 list = CHECK_FIND_CHILD (notebook, child);
7139 /* a NULL pointer indicates a default_tab setting, otherwise
7140 * we need to set the associated label
7144 if (page->tab_label == tab_label)
7148 gtk_notebook_remove_tab_label (notebook, page);
7152 page->default_tab = FALSE;
7153 page->tab_label = tab_label;
7154 gtk_widget_set_parent (page->tab_label, GTK_WIDGET (notebook));
7158 page->default_tab = TRUE;
7159 page->tab_label = NULL;
7161 if (priv->show_tabs)
7165 g_snprintf (string, sizeof(string), _("Page %u"),
7166 gtk_notebook_real_page_position (notebook, list));
7167 page->tab_label = gtk_label_new (string);
7168 gtk_widget_set_parent (page->tab_label, GTK_WIDGET (notebook));
7172 if (page->tab_label)
7173 page->mnemonic_activate_signal =
7174 g_signal_connect (page->tab_label,
7175 "mnemonic-activate",
7176 G_CALLBACK (gtk_notebook_mnemonic_activate_switch_page),
7179 if (priv->show_tabs && gtk_widget_get_visible (child))
7181 gtk_widget_show (page->tab_label);
7182 gtk_widget_queue_resize (GTK_WIDGET (notebook));
7185 gtk_notebook_update_tab_states (notebook);
7186 gtk_widget_child_notify (child, "tab-label");
7190 * gtk_notebook_set_tab_label_text:
7191 * @notebook: a #GtkNotebook
7193 * @tab_text: the label text
7195 * Creates a new label and sets it as the tab label for the page
7196 * containing @child.
7199 gtk_notebook_set_tab_label_text (GtkNotebook *notebook,
7201 const gchar *tab_text)
7203 GtkWidget *tab_label = NULL;
7205 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7208 tab_label = gtk_label_new (tab_text);
7209 gtk_notebook_set_tab_label (notebook, child, tab_label);
7210 gtk_widget_child_notify (child, "tab-label");
7214 * gtk_notebook_get_tab_label_text:
7215 * @notebook: a #GtkNotebook
7216 * @child: a widget contained in a page of @notebook
7218 * Retrieves the text of the tab label for the page containing
7221 * Return value: the text of the tab label, or %NULL if the
7222 * tab label widget is not a #GtkLabel. The
7223 * string is owned by the widget and must not
7226 G_CONST_RETURN gchar *
7227 gtk_notebook_get_tab_label_text (GtkNotebook *notebook,
7230 GtkWidget *tab_label;
7232 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
7233 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
7235 tab_label = gtk_notebook_get_tab_label (notebook, child);
7237 if (GTK_IS_LABEL (tab_label))
7238 return gtk_label_get_text (GTK_LABEL (tab_label));
7244 * gtk_notebook_get_menu_label:
7245 * @notebook: a #GtkNotebook
7246 * @child: a widget contained in a page of @notebook
7248 * Retrieves the menu label widget of the page containing @child.
7250 * Return value: the menu label, or %NULL if the
7251 * notebook page does not have a menu label other
7252 * than the default (the tab label).
7255 gtk_notebook_get_menu_label (GtkNotebook *notebook,
7260 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
7261 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
7263 list = CHECK_FIND_CHILD (notebook, child);
7267 if (GTK_NOTEBOOK_PAGE (list)->default_menu)
7270 return GTK_NOTEBOOK_PAGE (list)->menu_label;
7274 * gtk_notebook_set_menu_label:
7275 * @notebook: a #GtkNotebook
7276 * @child: the child widget
7277 * @menu_label: (allow-none): the menu label, or NULL for default
7279 * Changes the menu label for the page containing @child.
7282 gtk_notebook_set_menu_label (GtkNotebook *notebook,
7284 GtkWidget *menu_label)
7286 GtkNotebookPriv *priv;
7287 GtkNotebookPage *page;
7290 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7291 g_return_if_fail (GTK_IS_WIDGET (child));
7293 priv = notebook->priv;
7295 list = CHECK_FIND_CHILD (notebook, child);
7300 if (page->menu_label)
7303 gtk_container_remove (GTK_CONTAINER (priv->menu),
7304 page->menu_label->parent);
7306 if (!page->default_menu)
7307 g_object_unref (page->menu_label);
7312 page->menu_label = menu_label;
7313 g_object_ref_sink (page->menu_label);
7314 page->default_menu = FALSE;
7317 page->default_menu = TRUE;
7320 gtk_notebook_menu_item_create (notebook, list);
7321 gtk_widget_child_notify (child, "menu-label");
7325 * gtk_notebook_set_menu_label_text:
7326 * @notebook: a #GtkNotebook
7327 * @child: the child widget
7328 * @menu_text: the label text
7330 * Creates a new label and sets it as the menu label of @child.
7333 gtk_notebook_set_menu_label_text (GtkNotebook *notebook,
7335 const gchar *menu_text)
7337 GtkWidget *menu_label = NULL;
7339 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7343 menu_label = gtk_label_new (menu_text);
7344 gtk_misc_set_alignment (GTK_MISC (menu_label), 0.0, 0.5);
7346 gtk_notebook_set_menu_label (notebook, child, menu_label);
7347 gtk_widget_child_notify (child, "menu-label");
7351 * gtk_notebook_get_menu_label_text:
7352 * @notebook: a #GtkNotebook
7353 * @child: the child widget of a page of the notebook.
7355 * Retrieves the text of the menu label for the page containing
7358 * Return value: the text of the tab label, or %NULL if the
7359 * widget does not have a menu label other than
7360 * the default menu label, or the menu label widget
7361 * is not a #GtkLabel. The string is owned by
7362 * the widget and must not be freed.
7364 G_CONST_RETURN gchar *
7365 gtk_notebook_get_menu_label_text (GtkNotebook *notebook,
7368 GtkWidget *menu_label;
7370 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
7371 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
7373 menu_label = gtk_notebook_get_menu_label (notebook, child);
7375 if (GTK_IS_LABEL (menu_label))
7376 return gtk_label_get_text (GTK_LABEL (menu_label));
7381 /* Helper function called when pages are reordered
7384 gtk_notebook_child_reordered (GtkNotebook *notebook,
7385 GtkNotebookPage *page)
7387 GtkNotebookPriv *priv = notebook->priv;
7391 GtkWidget *menu_item;
7393 menu_item = page->menu_label->parent;
7394 gtk_container_remove (GTK_CONTAINER (menu_item), page->menu_label);
7395 gtk_container_remove (GTK_CONTAINER (priv->menu), menu_item);
7396 gtk_notebook_menu_item_create (notebook, g_list_find (priv->children, page));
7399 gtk_notebook_update_tab_states (notebook);
7400 gtk_notebook_update_labels (notebook);
7404 gtk_notebook_set_tab_label_packing (GtkNotebook *notebook,
7408 GtkPackType pack_type)
7410 GtkNotebookPriv *priv;
7411 GtkNotebookPage *page;
7414 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7415 g_return_if_fail (GTK_IS_WIDGET (child));
7417 priv = notebook->priv;
7419 list = CHECK_FIND_CHILD (notebook, child);
7424 expand = expand != FALSE;
7425 fill = fill != FALSE;
7426 if (page->pack == pack_type && page->expand == expand && page->fill == fill)
7429 gtk_widget_freeze_child_notify (child);
7430 page->expand = expand;
7431 gtk_widget_child_notify (child, "tab-expand");
7433 gtk_widget_child_notify (child, "tab-fill");
7434 if (page->pack != pack_type)
7436 page->pack = pack_type;
7437 gtk_notebook_child_reordered (notebook, page);
7439 gtk_widget_child_notify (child, "tab-pack");
7440 gtk_widget_child_notify (child, "position");
7441 if (priv->show_tabs)
7442 gtk_notebook_pages_allocate (notebook);
7443 gtk_widget_thaw_child_notify (child);
7447 gtk_notebook_query_tab_label_packing (GtkNotebook *notebook,
7451 GtkPackType *pack_type)
7455 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7456 g_return_if_fail (GTK_IS_WIDGET (child));
7458 list = CHECK_FIND_CHILD (notebook, child);
7463 *expand = GTK_NOTEBOOK_PAGE (list)->expand;
7465 *fill = GTK_NOTEBOOK_PAGE (list)->fill;
7467 *pack_type = GTK_NOTEBOOK_PAGE (list)->pack;
7471 * gtk_notebook_reorder_child:
7472 * @notebook: a #GtkNotebook
7473 * @child: the child to move
7474 * @position: the new position, or -1 to move to the end
7476 * Reorders the page containing @child, so that it appears in position
7477 * @position. If @position is greater than or equal to the number of
7478 * children in the list or negative, @child will be moved to the end
7482 gtk_notebook_reorder_child (GtkNotebook *notebook,
7486 GtkNotebookPriv *priv;
7487 GList *list, *new_list;
7488 GtkNotebookPage *page;
7492 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7493 g_return_if_fail (GTK_IS_WIDGET (child));
7495 priv = notebook->priv;
7497 list = CHECK_FIND_CHILD (notebook, child);
7501 max_pos = g_list_length (priv->children) - 1;
7502 if (position < 0 || position > max_pos)
7505 old_pos = g_list_position (priv->children, list);
7507 if (old_pos == position)
7511 priv->children = g_list_delete_link (priv->children, list);
7513 priv->children = g_list_insert (priv->children, page, position);
7514 new_list = g_list_nth (priv->children, position);
7516 /* Fix up GList references in GtkNotebook structure */
7517 if (priv->first_tab == list)
7518 priv->first_tab = new_list;
7519 if (priv->focus_tab == list)
7520 priv->focus_tab = new_list;
7522 gtk_widget_freeze_child_notify (child);
7524 /* Move around the menu items if necessary */
7525 gtk_notebook_child_reordered (notebook, page);
7526 gtk_widget_child_notify (child, "tab-pack");
7527 gtk_widget_child_notify (child, "position");
7529 if (priv->show_tabs)
7530 gtk_notebook_pages_allocate (notebook);
7532 gtk_widget_thaw_child_notify (child);
7534 g_signal_emit (notebook,
7535 notebook_signals[PAGE_REORDERED],
7542 * gtk_notebook_set_window_creation_hook:
7543 * @func: (allow-none): the #GtkNotebookWindowCreationFunc, or %NULL
7544 * @data: user data for @func
7545 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
7547 * Installs a global function used to create a window
7548 * when a detached tab is dropped in an empty area.
7553 gtk_notebook_set_window_creation_hook (GtkNotebookWindowCreationFunc func,
7555 GDestroyNotify destroy)
7557 if (window_creation_hook_destroy)
7558 window_creation_hook_destroy (window_creation_hook_data);
7560 window_creation_hook = func;
7561 window_creation_hook_data = data;
7562 window_creation_hook_destroy = destroy;
7566 * gtk_notebook_set_group:
7567 * @notebook: a #GtkNotebook
7568 * @group: (allow-none): a pointer to identify the notebook group, or %NULL to unset it
7570 * Sets a group identificator pointer for @notebook, notebooks sharing
7571 * the same group identificator pointer will be able to exchange tabs
7572 * via drag and drop. A notebook with a %NULL group identificator will
7573 * not be able to exchange tabs with any other notebook.
7578 gtk_notebook_set_group (GtkNotebook *notebook,
7581 GtkNotebookPriv *priv;
7583 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7585 priv = notebook->priv;
7587 if (priv->group != group)
7589 priv->group = group;
7590 g_object_notify (G_OBJECT (notebook), "group");
7595 * gtk_notebook_get_group:
7596 * @notebook: a #GtkNotebook
7598 * Gets the current group identificator pointer for @notebook.
7600 * Return Value: the group identificator, or %NULL if none is set.
7605 gtk_notebook_get_group (GtkNotebook *notebook)
7607 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
7609 return notebook->priv->group;
7613 * gtk_notebook_get_tab_reorderable:
7614 * @notebook: a #GtkNotebook
7615 * @child: a child #GtkWidget
7617 * Gets whether the tab can be reordered via drag and drop or not.
7619 * Return Value: %TRUE if the tab is reorderable.
7624 gtk_notebook_get_tab_reorderable (GtkNotebook *notebook,
7629 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
7630 g_return_val_if_fail (GTK_IS_WIDGET (child), FALSE);
7632 list = CHECK_FIND_CHILD (notebook, child);
7636 return GTK_NOTEBOOK_PAGE (list)->reorderable;
7640 * gtk_notebook_set_tab_reorderable:
7641 * @notebook: a #GtkNotebook
7642 * @child: a child #GtkWidget
7643 * @reorderable: whether the tab is reorderable or not.
7645 * Sets whether the notebook tab can be reordered
7646 * via drag and drop or not.
7651 gtk_notebook_set_tab_reorderable (GtkNotebook *notebook,
7653 gboolean reorderable)
7657 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7658 g_return_if_fail (GTK_IS_WIDGET (child));
7660 list = CHECK_FIND_CHILD (notebook, child);
7664 if (GTK_NOTEBOOK_PAGE (list)->reorderable != reorderable)
7666 GTK_NOTEBOOK_PAGE (list)->reorderable = (reorderable == TRUE);
7667 gtk_widget_child_notify (child, "reorderable");
7672 * gtk_notebook_get_tab_detachable:
7673 * @notebook: a #GtkNotebook
7674 * @child: a child #GtkWidget
7676 * Returns whether the tab contents can be detached from @notebook.
7678 * Return Value: TRUE if the tab is detachable.
7683 gtk_notebook_get_tab_detachable (GtkNotebook *notebook,
7688 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
7689 g_return_val_if_fail (GTK_IS_WIDGET (child), FALSE);
7691 list = CHECK_FIND_CHILD (notebook, child);
7695 return GTK_NOTEBOOK_PAGE (list)->detachable;
7699 * gtk_notebook_set_tab_detachable:
7700 * @notebook: a #GtkNotebook
7701 * @child: a child #GtkWidget
7702 * @detachable: whether the tab is detachable or not
7704 * Sets whether the tab can be detached from @notebook to another
7705 * notebook or widget.
7707 * Note that 2 notebooks must share a common group identificator
7708 * (see gtk_notebook_set_group_id ()) to allow automatic tabs
7709 * interchange between them.
7711 * If you want a widget to interact with a notebook through DnD
7712 * (i.e.: accept dragged tabs from it) it must be set as a drop
7713 * destination and accept the target "GTK_NOTEBOOK_TAB". The notebook
7714 * will fill the selection with a GtkWidget** pointing to the child
7715 * widget that corresponds to the dropped tab.
7718 * on_drop_zone_drag_data_received (GtkWidget *widget,
7719 * GdkDragContext *context,
7722 * GtkSelectionData *selection_data,
7725 * gpointer user_data)
7727 * GtkWidget *notebook;
7728 * GtkWidget **child;
7730 * notebook = gtk_drag_get_source_widget (context);
7731 * child = (void*) selection_data->data;
7733 * process_widget (*child);
7734 * gtk_container_remove (GTK_CONTAINER (notebook), *child);
7738 * If you want a notebook to accept drags from other widgets,
7739 * you will have to set your own DnD code to do it.
7744 gtk_notebook_set_tab_detachable (GtkNotebook *notebook,
7746 gboolean detachable)
7750 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7751 g_return_if_fail (GTK_IS_WIDGET (child));
7753 list = CHECK_FIND_CHILD (notebook, child);
7757 if (GTK_NOTEBOOK_PAGE (list)->detachable != detachable)
7759 GTK_NOTEBOOK_PAGE (list)->detachable = (detachable == TRUE);
7760 gtk_widget_child_notify (child, "detachable");
7765 * gtk_notebook_get_action_widget:
7766 * @notebook: a #GtkNotebook
7767 * @pack_type: pack type of the action widget to receive
7769 * Gets one of the action widgets. See gtk_notebook_set_action_widget().
7771 * Returns: The action widget with the given @pack_type or
7772 * %NULL when this action widget has not been set
7777 gtk_notebook_get_action_widget (GtkNotebook *notebook,
7778 GtkPackType pack_type)
7780 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
7782 return notebook->priv->action_widget[pack_type];
7786 * gtk_notebook_set_action_widget:
7787 * @notebook: a #GtkNotebook
7788 * @widget: a #GtkWidget
7789 * @pack_type: pack type of the action widget
7791 * Sets @widget as one of the action widgets. Depending on the pack type
7792 * the widget will be placed before or after the tabs. You can use
7793 * a #GtkBox if you need to pack more than one widget on the same side.
7795 * Note that action widgets are "internal" children of the notebook and thus
7796 * not included in the list returned from gtk_container_foreach().
7801 gtk_notebook_set_action_widget (GtkNotebook *notebook,
7803 GtkPackType pack_type)
7805 GtkNotebookPriv *priv;
7807 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7808 g_return_if_fail (!widget || GTK_IS_WIDGET (widget));
7809 g_return_if_fail (!widget || widget->parent == NULL);
7811 priv = notebook->priv;
7813 if (priv->action_widget[pack_type])
7814 gtk_widget_unparent (priv->action_widget[pack_type]);
7816 priv->action_widget[pack_type] = widget;
7820 gtk_widget_set_child_visible (widget, priv->show_tabs);
7821 gtk_widget_set_parent (widget, GTK_WIDGET (notebook));
7824 gtk_widget_queue_resize (GTK_WIDGET (notebook));