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/.
30 #include "gtknotebook.h"
35 #include <gdk/gdkkeysyms.h>
39 #include "gtkmenuitem.h"
41 #include "gtksizerequest.h"
43 #include "gtkmarshalers.h"
44 #include "gtkbindings.h"
45 #include "gtkprivate.h"
47 #include "gtkbuildable.h"
49 #define SCROLL_DELAY_FACTOR 5
50 #define SCROLL_THRESHOLD 12
51 #define DND_THRESHOLD_MULTIPLIER 4
52 #define FRAMES_PER_SECOND 45
53 #define MSECS_BETWEEN_UPDATES (1000 / FRAMES_PER_SECOND)
55 typedef struct _GtkNotebookPage GtkNotebookPage;
60 DRAG_OPERATION_REORDER,
62 } GtkNotebookDragOperation;
70 struct _GtkNotebookPrivate
72 GtkNotebookDragOperation operation;
73 GtkNotebookPage *cur_page;
74 GtkNotebookPage *detached_tab;
75 GtkTargetList *source_targets;
76 GtkWidget *action_widget[N_ACTION_WIDGETS];
77 GtkWidget *dnd_window;
80 GdkWindow *drag_window;
81 GdkWindow *event_window;
84 GList *first_tab; /* The first tab visible (for scrolling notebooks) */
100 guint switch_tab_timer;
109 guint child_has_focus : 1;
110 guint click_child : 3;
111 guint during_detach : 1;
112 guint during_reorder : 1;
113 guint focus_out : 1; /* Flag used by ::move-focus-out implementation */
114 guint has_scrolled : 1;
115 guint have_visible_child : 1;
116 guint homogeneous : 1;
118 guint need_timer : 1;
119 guint show_border : 1;
121 guint scrollable : 1;
124 guint has_before_previous : 1;
125 guint has_before_next : 1;
126 guint has_after_previous : 1;
127 guint has_after_next : 1;
163 } GtkNotebookPointerPosition;
165 #define ARROW_IS_LEFT(arrow) ((arrow) == ARROW_LEFT_BEFORE || (arrow) == ARROW_LEFT_AFTER)
166 #define ARROW_IS_BEFORE(arrow) ((arrow) == ARROW_LEFT_BEFORE || (arrow) == ARROW_RIGHT_BEFORE)
181 CHILD_PROP_TAB_LABEL,
182 CHILD_PROP_MENU_LABEL,
184 CHILD_PROP_TAB_EXPAND,
187 CHILD_PROP_REORDERABLE,
188 CHILD_PROP_DETACHABLE
191 #define GTK_NOTEBOOK_PAGE(_glist_) ((GtkNotebookPage *)((GList *)(_glist_))->data)
193 /* some useful defines for calculating coords */
194 #define PAGE_LEFT_X(_page_) (((GtkNotebookPage *) (_page_))->allocation.x)
195 #define PAGE_RIGHT_X(_page_) (((GtkNotebookPage *) (_page_))->allocation.x + ((GtkNotebookPage *) (_page_))->allocation.width)
196 #define PAGE_MIDDLE_X(_page_) (((GtkNotebookPage *) (_page_))->allocation.x + ((GtkNotebookPage *) (_page_))->allocation.width / 2)
197 #define PAGE_TOP_Y(_page_) (((GtkNotebookPage *) (_page_))->allocation.y)
198 #define PAGE_BOTTOM_Y(_page_) (((GtkNotebookPage *) (_page_))->allocation.y + ((GtkNotebookPage *) (_page_))->allocation.height)
199 #define PAGE_MIDDLE_Y(_page_) (((GtkNotebookPage *) (_page_))->allocation.y + ((GtkNotebookPage *) (_page_))->allocation.height / 2)
200 #define NOTEBOOK_IS_TAB_LABEL_PARENT(_notebook_,_page_) (gtk_widget_get_parent (((GtkNotebookPage *) (_page_))->tab_label) == ((GtkWidget *) (_notebook_)))
202 struct _GtkNotebookPage
205 GtkWidget *tab_label;
206 GtkWidget *menu_label;
207 GtkWidget *last_focus_child; /* Last descendant of the page that had focus */
209 guint default_menu : 1; /* If true, we create the menu label ourself */
210 guint default_tab : 1; /* If true, we create the tab label ourself */
214 guint reorderable : 1;
215 guint detachable : 1;
217 /* if true, the tab label was visible on last allocation; we track this so
218 * that we know to redraw the tab area if a tab label was hidden then shown
219 * without changing position */
220 guint tab_allocated_visible : 1;
222 GtkRequisition requisition;
223 GtkAllocation allocation;
225 gulong mnemonic_activate_signal;
226 gulong notify_visible_handler;
229 static const GtkTargetEntry notebook_targets [] = {
230 { "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, 0 },
233 #ifdef G_DISABLE_CHECKS
234 #define CHECK_FIND_CHILD(notebook, child) \
235 gtk_notebook_find_child (notebook, child, G_STRLOC)
237 #define CHECK_FIND_CHILD(notebook, child) \
238 gtk_notebook_find_child (notebook, child, NULL)
241 /*** GtkNotebook Methods ***/
242 static gboolean gtk_notebook_select_page (GtkNotebook *notebook,
243 gboolean move_focus);
244 static gboolean gtk_notebook_focus_tab (GtkNotebook *notebook,
245 GtkNotebookTab type);
246 static gboolean gtk_notebook_change_current_page (GtkNotebook *notebook,
248 static void gtk_notebook_move_focus_out (GtkNotebook *notebook,
249 GtkDirectionType direction_type);
250 static gboolean gtk_notebook_reorder_tab (GtkNotebook *notebook,
251 GtkDirectionType direction_type,
252 gboolean move_to_last);
253 static void gtk_notebook_remove_tab_label (GtkNotebook *notebook,
254 GtkNotebookPage *page);
255 static void gtk_notebook_set_tab_label_packing (GtkNotebook *notebook,
259 GtkPackType pack_type);
260 static void gtk_notebook_query_tab_label_packing (GtkNotebook *notebook,
264 GtkPackType *pack_type);
266 /*** GtkObject Methods ***/
267 static void gtk_notebook_destroy (GtkObject *object);
268 static void gtk_notebook_set_property (GObject *object,
272 static void gtk_notebook_get_property (GObject *object,
277 /*** GtkWidget Methods ***/
278 static void gtk_notebook_map (GtkWidget *widget);
279 static void gtk_notebook_unmap (GtkWidget *widget);
280 static void gtk_notebook_realize (GtkWidget *widget);
281 static void gtk_notebook_unrealize (GtkWidget *widget);
282 static void gtk_notebook_size_request (GtkWidget *widget,
283 GtkRequisition *requisition);
284 static void gtk_notebook_size_allocate (GtkWidget *widget,
285 GtkAllocation *allocation);
286 static gint gtk_notebook_expose (GtkWidget *widget,
287 GdkEventExpose *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 guint notebook_signals[LAST_SIGNAL] = { 0 };
472 G_DEFINE_TYPE_WITH_CODE (GtkNotebook, gtk_notebook, GTK_TYPE_CONTAINER,
473 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
474 gtk_notebook_buildable_init))
477 add_tab_bindings (GtkBindingSet *binding_set,
478 GdkModifierType modifiers,
479 GtkDirectionType direction)
481 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, modifiers,
483 GTK_TYPE_DIRECTION_TYPE, direction);
484 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, modifiers,
486 GTK_TYPE_DIRECTION_TYPE, direction);
490 add_arrow_bindings (GtkBindingSet *binding_set,
492 GtkDirectionType direction)
494 guint keypad_keysym = keysym - GDK_KEY_Left + GDK_KEY_KP_Left;
496 gtk_binding_entry_add_signal (binding_set, keysym, GDK_CONTROL_MASK,
498 GTK_TYPE_DIRECTION_TYPE, direction);
499 gtk_binding_entry_add_signal (binding_set, keypad_keysym, GDK_CONTROL_MASK,
501 GTK_TYPE_DIRECTION_TYPE, direction);
505 add_reorder_bindings (GtkBindingSet *binding_set,
507 GtkDirectionType direction,
508 gboolean move_to_last)
510 guint keypad_keysym = keysym - GDK_KEY_Left + GDK_KEY_KP_Left;
512 gtk_binding_entry_add_signal (binding_set, keysym, GDK_MOD1_MASK,
514 GTK_TYPE_DIRECTION_TYPE, direction,
515 G_TYPE_BOOLEAN, move_to_last);
516 gtk_binding_entry_add_signal (binding_set, keypad_keysym, GDK_MOD1_MASK,
518 GTK_TYPE_DIRECTION_TYPE, direction,
519 G_TYPE_BOOLEAN, move_to_last);
523 gtk_object_handled_accumulator (GSignalInvocationHint *ihint,
525 const GValue *handler_return,
528 gboolean continue_emission;
531 object = g_value_get_object (handler_return);
532 g_value_set_object (return_accu, object);
533 continue_emission = !object;
535 return continue_emission;
539 gtk_notebook_class_init (GtkNotebookClass *class)
541 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
542 GtkObjectClass *object_class = GTK_OBJECT_CLASS (class);
543 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
544 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
545 GtkBindingSet *binding_set;
547 gobject_class->set_property = gtk_notebook_set_property;
548 gobject_class->get_property = gtk_notebook_get_property;
549 object_class->destroy = gtk_notebook_destroy;
551 widget_class->map = gtk_notebook_map;
552 widget_class->unmap = gtk_notebook_unmap;
553 widget_class->realize = gtk_notebook_realize;
554 widget_class->unrealize = gtk_notebook_unrealize;
555 widget_class->size_request = gtk_notebook_size_request;
556 widget_class->size_allocate = gtk_notebook_size_allocate;
557 widget_class->expose_event = gtk_notebook_expose;
558 widget_class->button_press_event = gtk_notebook_button_press;
559 widget_class->button_release_event = gtk_notebook_button_release;
560 widget_class->popup_menu = gtk_notebook_popup_menu;
561 widget_class->leave_notify_event = gtk_notebook_leave_notify;
562 widget_class->motion_notify_event = gtk_notebook_motion_notify;
563 widget_class->grab_notify = gtk_notebook_grab_notify;
564 widget_class->state_changed = gtk_notebook_state_changed;
565 widget_class->focus_in_event = gtk_notebook_focus_in;
566 widget_class->focus_out_event = gtk_notebook_focus_out;
567 widget_class->focus = gtk_notebook_focus;
568 widget_class->style_set = gtk_notebook_style_set;
569 widget_class->drag_begin = gtk_notebook_drag_begin;
570 widget_class->drag_end = gtk_notebook_drag_end;
571 widget_class->drag_motion = gtk_notebook_drag_motion;
572 widget_class->drag_leave = gtk_notebook_drag_leave;
573 widget_class->drag_drop = gtk_notebook_drag_drop;
574 widget_class->drag_data_get = gtk_notebook_drag_data_get;
575 widget_class->drag_data_received = gtk_notebook_drag_data_received;
577 container_class->add = gtk_notebook_add;
578 container_class->remove = gtk_notebook_remove;
579 container_class->forall = gtk_notebook_forall;
580 container_class->set_focus_child = gtk_notebook_set_focus_child;
581 container_class->get_child_property = gtk_notebook_get_child_property;
582 container_class->set_child_property = gtk_notebook_set_child_property;
583 container_class->child_type = gtk_notebook_child_type;
585 class->switch_page = gtk_notebook_real_switch_page;
586 class->insert_page = gtk_notebook_real_insert_page;
588 class->focus_tab = gtk_notebook_focus_tab;
589 class->select_page = gtk_notebook_select_page;
590 class->change_current_page = gtk_notebook_change_current_page;
591 class->move_focus_out = gtk_notebook_move_focus_out;
592 class->reorder_tab = gtk_notebook_reorder_tab;
593 class->create_window = gtk_notebook_create_window;
595 g_object_class_install_property (gobject_class,
597 g_param_spec_int ("page",
599 P_("The index of the current page"),
603 GTK_PARAM_READWRITE));
604 g_object_class_install_property (gobject_class,
606 g_param_spec_enum ("tab-pos",
608 P_("Which side of the notebook holds the tabs"),
609 GTK_TYPE_POSITION_TYPE,
611 GTK_PARAM_READWRITE));
612 g_object_class_install_property (gobject_class,
614 g_param_spec_boolean ("show-tabs",
616 P_("Whether tabs should be shown"),
618 GTK_PARAM_READWRITE));
619 g_object_class_install_property (gobject_class,
621 g_param_spec_boolean ("show-border",
623 P_("Whether the border should be shown"),
625 GTK_PARAM_READWRITE));
626 g_object_class_install_property (gobject_class,
628 g_param_spec_boolean ("scrollable",
630 P_("If TRUE, scroll arrows are added if there are too many tabs to fit"),
632 GTK_PARAM_READWRITE));
633 g_object_class_install_property (gobject_class,
635 g_param_spec_boolean ("enable-popup",
637 P_("If TRUE, pressing the right mouse button on the notebook pops up a menu that you can use to go to a page"),
639 GTK_PARAM_READWRITE));
642 * GtkNotebook:group-name:
644 * Group name for tab drag and drop.
648 g_object_class_install_property (gobject_class,
650 g_param_spec_string ("group-name",
652 P_("Group name for tab drag and drop"),
654 GTK_PARAM_READWRITE));
656 gtk_container_class_install_child_property (container_class,
657 CHILD_PROP_TAB_LABEL,
658 g_param_spec_string ("tab-label",
660 P_("The string displayed on the child's tab label"),
662 GTK_PARAM_READWRITE));
663 gtk_container_class_install_child_property (container_class,
664 CHILD_PROP_MENU_LABEL,
665 g_param_spec_string ("menu-label",
667 P_("The string displayed in the child's menu entry"),
669 GTK_PARAM_READWRITE));
670 gtk_container_class_install_child_property (container_class,
672 g_param_spec_int ("position",
674 P_("The index of the child in the parent"),
676 GTK_PARAM_READWRITE));
677 gtk_container_class_install_child_property (container_class,
678 CHILD_PROP_TAB_EXPAND,
679 g_param_spec_boolean ("tab-expand",
681 P_("Whether to expand the child's tab"),
683 GTK_PARAM_READWRITE));
684 gtk_container_class_install_child_property (container_class,
686 g_param_spec_boolean ("tab-fill",
688 P_("Whether the child's tab should fill the allocated area"),
690 GTK_PARAM_READWRITE));
691 gtk_container_class_install_child_property (container_class,
693 g_param_spec_enum ("tab-pack",
695 P_("A GtkPackType indicating whether the child is packed with reference to the start or end of the parent"),
696 GTK_TYPE_PACK_TYPE, GTK_PACK_START,
697 GTK_PARAM_READWRITE));
698 gtk_container_class_install_child_property (container_class,
699 CHILD_PROP_REORDERABLE,
700 g_param_spec_boolean ("reorderable",
701 P_("Tab reorderable"),
702 P_("Whether the tab is reorderable by user action"),
704 GTK_PARAM_READWRITE));
705 gtk_container_class_install_child_property (container_class,
706 CHILD_PROP_DETACHABLE,
707 g_param_spec_boolean ("detachable",
708 P_("Tab detachable"),
709 P_("Whether the tab is detachable"),
711 GTK_PARAM_READWRITE));
714 * GtkNotebook:has-secondary-backward-stepper:
716 * The "has-secondary-backward-stepper" property determines whether
717 * a second backward arrow button is displayed on the opposite end
722 gtk_widget_class_install_style_property (widget_class,
723 g_param_spec_boolean ("has-secondary-backward-stepper",
724 P_("Secondary backward stepper"),
725 P_("Display a second backward arrow button on the opposite end of the tab area"),
727 GTK_PARAM_READABLE));
730 * GtkNotebook:has-secondary-forward-stepper:
732 * The "has-secondary-forward-stepper" property determines whether
733 * a second forward arrow button is displayed on the opposite end
738 gtk_widget_class_install_style_property (widget_class,
739 g_param_spec_boolean ("has-secondary-forward-stepper",
740 P_("Secondary forward stepper"),
741 P_("Display a second forward arrow button on the opposite end of the tab area"),
743 GTK_PARAM_READABLE));
746 * GtkNotebook:has-backward-stepper:
748 * The "has-backward-stepper" property determines whether
749 * the standard backward arrow button is displayed.
753 gtk_widget_class_install_style_property (widget_class,
754 g_param_spec_boolean ("has-backward-stepper",
755 P_("Backward stepper"),
756 P_("Display the standard backward arrow button"),
758 GTK_PARAM_READABLE));
761 * GtkNotebook:has-forward-stepper:
763 * The "has-forward-stepper" property determines whether
764 * the standard forward arrow button is displayed.
768 gtk_widget_class_install_style_property (widget_class,
769 g_param_spec_boolean ("has-forward-stepper",
770 P_("Forward stepper"),
771 P_("Display the standard forward arrow button"),
773 GTK_PARAM_READABLE));
776 * GtkNotebook:tab-overlap:
778 * The "tab-overlap" property defines size of tab overlap
783 gtk_widget_class_install_style_property (widget_class,
784 g_param_spec_int ("tab-overlap",
786 P_("Size of tab overlap area"),
790 GTK_PARAM_READABLE));
793 * GtkNotebook:tab-curvature:
795 * The "tab-curvature" property defines size of tab curvature.
799 gtk_widget_class_install_style_property (widget_class,
800 g_param_spec_int ("tab-curvature",
802 P_("Size of tab curvature"),
806 GTK_PARAM_READABLE));
809 * GtkNotebook:arrow-spacing:
811 * The "arrow-spacing" property defines the spacing between the scroll
812 * arrows and the tabs.
816 gtk_widget_class_install_style_property (widget_class,
817 g_param_spec_int ("arrow-spacing",
819 P_("Scroll arrow spacing"),
823 GTK_PARAM_READABLE));
825 notebook_signals[SWITCH_PAGE] =
826 g_signal_new (I_("switch-page"),
827 G_TYPE_FROM_CLASS (gobject_class),
829 G_STRUCT_OFFSET (GtkNotebookClass, switch_page),
831 _gtk_marshal_VOID__OBJECT_UINT,
835 notebook_signals[FOCUS_TAB] =
836 g_signal_new (I_("focus-tab"),
837 G_TYPE_FROM_CLASS (gobject_class),
838 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
839 G_STRUCT_OFFSET (GtkNotebookClass, focus_tab),
841 _gtk_marshal_BOOLEAN__ENUM,
843 GTK_TYPE_NOTEBOOK_TAB);
844 notebook_signals[SELECT_PAGE] =
845 g_signal_new (I_("select-page"),
846 G_TYPE_FROM_CLASS (gobject_class),
847 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
848 G_STRUCT_OFFSET (GtkNotebookClass, select_page),
850 _gtk_marshal_BOOLEAN__BOOLEAN,
853 notebook_signals[CHANGE_CURRENT_PAGE] =
854 g_signal_new (I_("change-current-page"),
855 G_TYPE_FROM_CLASS (gobject_class),
856 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
857 G_STRUCT_OFFSET (GtkNotebookClass, change_current_page),
859 _gtk_marshal_BOOLEAN__INT,
862 notebook_signals[MOVE_FOCUS_OUT] =
863 g_signal_new (I_("move-focus-out"),
864 G_TYPE_FROM_CLASS (gobject_class),
865 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
866 G_STRUCT_OFFSET (GtkNotebookClass, move_focus_out),
868 _gtk_marshal_VOID__ENUM,
870 GTK_TYPE_DIRECTION_TYPE);
871 notebook_signals[REORDER_TAB] =
872 g_signal_new (I_("reorder-tab"),
873 G_TYPE_FROM_CLASS (gobject_class),
874 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
875 G_STRUCT_OFFSET (GtkNotebookClass, reorder_tab),
877 _gtk_marshal_BOOLEAN__ENUM_BOOLEAN,
879 GTK_TYPE_DIRECTION_TYPE,
882 * GtkNotebook::page-reordered:
883 * @notebook: the #GtkNotebook
884 * @child: the child #GtkWidget affected
885 * @page_num: the new page number for @child
887 * the ::page-reordered signal is emitted in the notebook
888 * right after a page has been reordered.
892 notebook_signals[PAGE_REORDERED] =
893 g_signal_new (I_("page-reordered"),
894 G_TYPE_FROM_CLASS (gobject_class),
897 _gtk_marshal_VOID__OBJECT_UINT,
902 * GtkNotebook::page-removed:
903 * @notebook: the #GtkNotebook
904 * @child: the child #GtkWidget affected
905 * @page_num: the @child page number
907 * the ::page-removed signal is emitted in the notebook
908 * right after a page is removed from the notebook.
912 notebook_signals[PAGE_REMOVED] =
913 g_signal_new (I_("page-removed"),
914 G_TYPE_FROM_CLASS (gobject_class),
917 _gtk_marshal_VOID__OBJECT_UINT,
922 * GtkNotebook::page-added:
923 * @notebook: the #GtkNotebook
924 * @child: the child #GtkWidget affected
925 * @page_num: the new page number for @child
927 * the ::page-added signal is emitted in the notebook
928 * right after a page is added to the notebook.
932 notebook_signals[PAGE_ADDED] =
933 g_signal_new (I_("page-added"),
934 G_TYPE_FROM_CLASS (gobject_class),
937 _gtk_marshal_VOID__OBJECT_UINT,
943 * GtkNotebook::create-window:
944 * @notebook: the #GtkNotebook emitting the signal
945 * @page: the tab of @notebook that is being detached
946 * @x: the X coordinate where the drop happens
947 * @y: the Y coordinate where the drop happens
949 * The ::create-window signal is emitted when a detachable
950 * tab is dropped on the root window.
952 * A handler for this signal can create a window containing
953 * a notebook where the tab will be attached. It is also
954 * responsible for moving/resizing the window and adding the
955 * necessary properties to the notebook (e.g. the
956 * #GtkNotebook:group ).
958 * Returns: a #GtkNotebook that @page should be added to, or %NULL.
962 notebook_signals[CREATE_WINDOW] =
963 g_signal_new (I_("create-window"),
964 G_TYPE_FROM_CLASS (gobject_class),
966 G_STRUCT_OFFSET (GtkNotebookClass, create_window),
967 gtk_object_handled_accumulator, NULL,
968 _gtk_marshal_OBJECT__OBJECT_INT_INT,
969 GTK_TYPE_NOTEBOOK, 3,
970 GTK_TYPE_WIDGET, G_TYPE_INT, G_TYPE_INT);
972 binding_set = gtk_binding_set_by_class (class);
973 gtk_binding_entry_add_signal (binding_set,
976 G_TYPE_BOOLEAN, FALSE);
977 gtk_binding_entry_add_signal (binding_set,
980 G_TYPE_BOOLEAN, FALSE);
982 gtk_binding_entry_add_signal (binding_set,
985 GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_FIRST);
986 gtk_binding_entry_add_signal (binding_set,
989 GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_FIRST);
990 gtk_binding_entry_add_signal (binding_set,
993 GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_LAST);
994 gtk_binding_entry_add_signal (binding_set,
997 GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_LAST);
999 gtk_binding_entry_add_signal (binding_set,
1000 GDK_KEY_Page_Up, GDK_CONTROL_MASK,
1001 "change-current-page", 1,
1003 gtk_binding_entry_add_signal (binding_set,
1004 GDK_KEY_Page_Down, GDK_CONTROL_MASK,
1005 "change-current-page", 1,
1008 gtk_binding_entry_add_signal (binding_set,
1009 GDK_KEY_Page_Up, GDK_CONTROL_MASK | GDK_MOD1_MASK,
1010 "change-current-page", 1,
1012 gtk_binding_entry_add_signal (binding_set,
1013 GDK_KEY_Page_Down, GDK_CONTROL_MASK | GDK_MOD1_MASK,
1014 "change-current-page", 1,
1017 add_arrow_bindings (binding_set, GDK_KEY_Up, GTK_DIR_UP);
1018 add_arrow_bindings (binding_set, GDK_KEY_Down, GTK_DIR_DOWN);
1019 add_arrow_bindings (binding_set, GDK_KEY_Left, GTK_DIR_LEFT);
1020 add_arrow_bindings (binding_set, GDK_KEY_Right, GTK_DIR_RIGHT);
1022 add_reorder_bindings (binding_set, GDK_KEY_Up, GTK_DIR_UP, FALSE);
1023 add_reorder_bindings (binding_set, GDK_KEY_Down, GTK_DIR_DOWN, FALSE);
1024 add_reorder_bindings (binding_set, GDK_KEY_Left, GTK_DIR_LEFT, FALSE);
1025 add_reorder_bindings (binding_set, GDK_KEY_Right, GTK_DIR_RIGHT, FALSE);
1026 add_reorder_bindings (binding_set, GDK_KEY_Home, GTK_DIR_LEFT, TRUE);
1027 add_reorder_bindings (binding_set, GDK_KEY_Home, GTK_DIR_UP, TRUE);
1028 add_reorder_bindings (binding_set, GDK_KEY_End, GTK_DIR_RIGHT, TRUE);
1029 add_reorder_bindings (binding_set, GDK_KEY_End, GTK_DIR_DOWN, TRUE);
1031 add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
1032 add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
1034 g_type_class_add_private (class, sizeof (GtkNotebookPrivate));
1038 gtk_notebook_init (GtkNotebook *notebook)
1040 GtkNotebookPrivate *priv;
1042 gtk_widget_set_can_focus (GTK_WIDGET (notebook), TRUE);
1043 gtk_widget_set_has_window (GTK_WIDGET (notebook), FALSE);
1045 notebook->priv = G_TYPE_INSTANCE_GET_PRIVATE (notebook,
1047 GtkNotebookPrivate);
1048 priv = notebook->priv;
1050 priv->cur_page = NULL;
1051 priv->children = NULL;
1052 priv->first_tab = NULL;
1053 priv->focus_tab = NULL;
1054 priv->event_window = NULL;
1057 priv->tab_hborder = 2;
1058 priv->tab_vborder = 2;
1060 priv->show_tabs = TRUE;
1061 priv->show_border = TRUE;
1062 priv->tab_pos = GTK_POS_TOP;
1063 priv->scrollable = FALSE;
1065 priv->click_child = 0;
1067 priv->need_timer = 0;
1068 priv->child_has_focus = FALSE;
1069 priv->have_visible_child = FALSE;
1070 priv->focus_out = FALSE;
1072 priv->has_before_previous = 1;
1073 priv->has_before_next = 0;
1074 priv->has_after_previous = 0;
1075 priv->has_after_next = 1;
1078 priv->pressed_button = -1;
1079 priv->dnd_timer = 0;
1080 priv->switch_tab_timer = 0;
1081 priv->source_targets = gtk_target_list_new (notebook_targets,
1082 G_N_ELEMENTS (notebook_targets));
1083 priv->operation = DRAG_OPERATION_NONE;
1084 priv->detached_tab = NULL;
1085 priv->during_detach = FALSE;
1086 priv->has_scrolled = FALSE;
1088 gtk_drag_dest_set (GTK_WIDGET (notebook), 0,
1089 notebook_targets, G_N_ELEMENTS (notebook_targets),
1092 g_signal_connect (G_OBJECT (notebook), "drag-failed",
1093 G_CALLBACK (gtk_notebook_drag_failed), NULL);
1095 gtk_drag_dest_set_track_motion (GTK_WIDGET (notebook), TRUE);
1099 gtk_notebook_buildable_init (GtkBuildableIface *iface)
1101 iface->add_child = gtk_notebook_buildable_add_child;
1105 gtk_notebook_buildable_add_child (GtkBuildable *buildable,
1106 GtkBuilder *builder,
1110 GtkNotebook *notebook = GTK_NOTEBOOK (buildable);
1112 if (type && strcmp (type, "tab") == 0)
1116 page = gtk_notebook_get_nth_page (notebook, -1);
1117 /* To set the tab label widget, we must have already a child
1118 * inside the tab container. */
1119 g_assert (page != NULL);
1120 gtk_notebook_set_tab_label (notebook, page, GTK_WIDGET (child));
1122 else if (type && strcmp (type, "action-start") == 0)
1124 gtk_notebook_set_action_widget (notebook, GTK_WIDGET (child), GTK_PACK_START);
1126 else if (type && strcmp (type, "action-end") == 0)
1128 gtk_notebook_set_action_widget (notebook, GTK_WIDGET (child), GTK_PACK_END);
1131 gtk_notebook_append_page (notebook, GTK_WIDGET (child), NULL);
1133 GTK_BUILDER_WARN_INVALID_CHILD_TYPE (notebook, type);
1137 gtk_notebook_select_page (GtkNotebook *notebook,
1138 gboolean move_focus)
1140 GtkNotebookPrivate *priv = notebook->priv;
1142 if (gtk_widget_is_focus (GTK_WIDGET (notebook)) && priv->show_tabs)
1144 gtk_notebook_page_select (notebook, move_focus);
1152 gtk_notebook_focus_tab (GtkNotebook *notebook,
1153 GtkNotebookTab type)
1155 GtkNotebookPrivate *priv = notebook->priv;
1158 if (gtk_widget_is_focus (GTK_WIDGET (notebook)) && priv->show_tabs)
1162 case GTK_NOTEBOOK_TAB_FIRST:
1163 list = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, TRUE);
1165 gtk_notebook_switch_focus_tab (notebook, list);
1167 case GTK_NOTEBOOK_TAB_LAST:
1168 list = gtk_notebook_search_page (notebook, NULL, STEP_PREV, TRUE);
1170 gtk_notebook_switch_focus_tab (notebook, list);
1181 gtk_notebook_change_current_page (GtkNotebook *notebook,
1184 GtkNotebookPrivate *priv = notebook->priv;
1185 GList *current = NULL;
1187 if (!priv->show_tabs)
1191 current = g_list_find (priv->children, priv->cur_page);
1195 current = gtk_notebook_search_page (notebook, current,
1196 offset < 0 ? STEP_PREV : STEP_NEXT,
1201 gboolean wrap_around;
1203 g_object_get (gtk_widget_get_settings (GTK_WIDGET (notebook)),
1204 "gtk-keynav-wrap-around", &wrap_around,
1208 current = gtk_notebook_search_page (notebook, NULL,
1209 offset < 0 ? STEP_PREV : STEP_NEXT,
1215 offset += offset < 0 ? 1 : -1;
1219 gtk_notebook_switch_page (notebook, current->data);
1221 gtk_widget_error_bell (GTK_WIDGET (notebook));
1226 static GtkDirectionType
1227 get_effective_direction (GtkNotebook *notebook,
1228 GtkDirectionType direction)
1230 GtkNotebookPrivate *priv = notebook->priv;
1232 /* Remap the directions into the effective direction it would be for a
1233 * GTK_POS_TOP notebook
1236 #define D(rest) GTK_DIR_##rest
1238 static const GtkDirectionType translate_direction[2][4][6] = {
1239 /* LEFT */ {{ D(TAB_FORWARD), D(TAB_BACKWARD), D(LEFT), D(RIGHT), D(UP), D(DOWN) },
1240 /* RIGHT */ { D(TAB_BACKWARD), D(TAB_FORWARD), D(LEFT), D(RIGHT), D(DOWN), D(UP) },
1241 /* TOP */ { D(TAB_FORWARD), D(TAB_BACKWARD), D(UP), D(DOWN), D(LEFT), D(RIGHT) },
1242 /* BOTTOM */ { D(TAB_BACKWARD), D(TAB_FORWARD), D(DOWN), D(UP), D(LEFT), D(RIGHT) }},
1243 /* LEFT */ {{ D(TAB_BACKWARD), D(TAB_FORWARD), D(LEFT), D(RIGHT), D(DOWN), D(UP) },
1244 /* RIGHT */ { D(TAB_FORWARD), D(TAB_BACKWARD), D(LEFT), D(RIGHT), D(UP), D(DOWN) },
1245 /* TOP */ { D(TAB_FORWARD), D(TAB_BACKWARD), D(UP), D(DOWN), D(RIGHT), D(LEFT) },
1246 /* BOTTOM */ { D(TAB_BACKWARD), D(TAB_FORWARD), D(DOWN), D(UP), D(RIGHT), D(LEFT) }},
1251 int text_dir = gtk_widget_get_direction (GTK_WIDGET (notebook)) == GTK_TEXT_DIR_RTL ? 1 : 0;
1253 return translate_direction[text_dir][priv->tab_pos][direction];
1257 get_effective_tab_pos (GtkNotebook *notebook)
1259 GtkNotebookPrivate *priv = notebook->priv;
1261 if (gtk_widget_get_direction (GTK_WIDGET (notebook)) == GTK_TEXT_DIR_RTL)
1263 switch (priv->tab_pos)
1266 return GTK_POS_RIGHT;
1268 return GTK_POS_LEFT;
1273 return priv->tab_pos;
1277 get_tab_gap_pos (GtkNotebook *notebook)
1279 gint tab_pos = get_effective_tab_pos (notebook);
1280 gint gap_side = GTK_POS_BOTTOM;
1285 gap_side = GTK_POS_BOTTOM;
1287 case GTK_POS_BOTTOM:
1288 gap_side = GTK_POS_TOP;
1291 gap_side = GTK_POS_RIGHT;
1294 gap_side = GTK_POS_LEFT;
1302 gtk_notebook_move_focus_out (GtkNotebook *notebook,
1303 GtkDirectionType direction_type)
1305 GtkNotebookPrivate *priv = notebook->priv;
1306 GtkDirectionType effective_direction = get_effective_direction (notebook, direction_type);
1307 GtkWidget *toplevel;
1309 if (gtk_container_get_focus_child (GTK_CONTAINER (notebook)) && effective_direction == GTK_DIR_UP)
1310 if (focus_tabs_in (notebook))
1312 if (gtk_widget_is_focus (GTK_WIDGET (notebook)) && effective_direction == GTK_DIR_DOWN)
1313 if (focus_child_in (notebook, GTK_DIR_TAB_FORWARD))
1316 /* At this point, we know we should be focusing out of the notebook entirely. We
1317 * do this by setting a flag, then propagating the focus motion to the notebook.
1319 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (notebook));
1320 if (!gtk_widget_is_toplevel (toplevel))
1323 g_object_ref (notebook);
1325 priv->focus_out = TRUE;
1326 g_signal_emit_by_name (toplevel, "move-focus", direction_type);
1327 priv->focus_out = FALSE;
1329 g_object_unref (notebook);
1333 reorder_tab (GtkNotebook *notebook, GList *position, GList *tab)
1335 GtkNotebookPrivate *priv = notebook->priv;
1338 if (position == tab)
1339 return g_list_position (priv->children, tab);
1341 /* check that we aren't inserting the tab in the
1342 * same relative position, taking packing into account */
1343 elem = (position) ? position->prev : g_list_last (priv->children);
1345 while (elem && elem != tab && GTK_NOTEBOOK_PAGE (elem)->pack != GTK_NOTEBOOK_PAGE (tab)->pack)
1349 return g_list_position (priv->children, tab);
1351 /* now actually reorder the tab */
1352 if (priv->first_tab == tab)
1353 priv->first_tab = gtk_notebook_search_page (notebook, priv->first_tab,
1356 priv->children = g_list_remove_link (priv->children, tab);
1359 elem = g_list_last (priv->children);
1362 elem = position->prev;
1363 position->prev = tab;
1369 priv->children = tab;
1372 tab->next = position;
1374 return g_list_position (priv->children, tab);
1378 gtk_notebook_reorder_tab (GtkNotebook *notebook,
1379 GtkDirectionType direction_type,
1380 gboolean move_to_last)
1382 GtkNotebookPrivate *priv = notebook->priv;
1383 GtkDirectionType effective_direction = get_effective_direction (notebook, direction_type);
1384 GtkNotebookPage *page;
1385 GList *last, *child;
1388 if (!gtk_widget_is_focus (GTK_WIDGET (notebook)) || !priv->show_tabs)
1391 if (!priv->cur_page ||
1392 !priv->cur_page->reorderable)
1395 if (effective_direction != GTK_DIR_LEFT &&
1396 effective_direction != GTK_DIR_RIGHT)
1401 child = priv->focus_tab;
1406 child = gtk_notebook_search_page (notebook, last,
1407 (effective_direction == GTK_DIR_RIGHT) ? STEP_NEXT : STEP_PREV,
1410 while (child && GTK_NOTEBOOK_PAGE (last)->pack == GTK_NOTEBOOK_PAGE (child)->pack);
1415 child = gtk_notebook_search_page (notebook, priv->focus_tab,
1416 (effective_direction == GTK_DIR_RIGHT) ? STEP_NEXT : STEP_PREV,
1419 if (!child || child->data == priv->cur_page)
1424 if (page->pack == priv->cur_page->pack)
1426 if (effective_direction == GTK_DIR_RIGHT)
1427 page_num = reorder_tab (notebook, (page->pack == GTK_PACK_START) ? child->next : child, priv->focus_tab);
1429 page_num = reorder_tab (notebook, (page->pack == GTK_PACK_START) ? child : child->next, priv->focus_tab);
1431 gtk_notebook_pages_allocate (notebook);
1433 g_signal_emit (notebook,
1434 notebook_signals[PAGE_REORDERED],
1436 ((GtkNotebookPage *) priv->focus_tab->data)->child,
1448 * Creates a new #GtkNotebook widget with no pages.
1450 * Return value: the newly created #GtkNotebook
1453 gtk_notebook_new (void)
1455 return g_object_new (GTK_TYPE_NOTEBOOK, NULL);
1458 /* Private GtkObject Methods :
1460 * gtk_notebook_destroy
1461 * gtk_notebook_set_arg
1462 * gtk_notebook_get_arg
1465 gtk_notebook_destroy (GtkObject *object)
1467 GtkNotebook *notebook = GTK_NOTEBOOK (object);
1468 GtkNotebookPrivate *priv = notebook->priv;
1471 gtk_notebook_popup_disable (notebook);
1473 if (priv->source_targets)
1475 gtk_target_list_unref (priv->source_targets);
1476 priv->source_targets = NULL;
1479 if (priv->switch_tab_timer)
1481 g_source_remove (priv->switch_tab_timer);
1482 priv->switch_tab_timer = 0;
1485 GTK_OBJECT_CLASS (gtk_notebook_parent_class)->destroy (object);
1489 gtk_notebook_set_property (GObject *object,
1491 const GValue *value,
1494 GtkNotebook *notebook;
1496 notebook = GTK_NOTEBOOK (object);
1500 case PROP_SHOW_TABS:
1501 gtk_notebook_set_show_tabs (notebook, g_value_get_boolean (value));
1503 case PROP_SHOW_BORDER:
1504 gtk_notebook_set_show_border (notebook, g_value_get_boolean (value));
1506 case PROP_SCROLLABLE:
1507 gtk_notebook_set_scrollable (notebook, g_value_get_boolean (value));
1509 case PROP_ENABLE_POPUP:
1510 if (g_value_get_boolean (value))
1511 gtk_notebook_popup_enable (notebook);
1513 gtk_notebook_popup_disable (notebook);
1516 gtk_notebook_set_current_page (notebook, g_value_get_int (value));
1519 gtk_notebook_set_tab_pos (notebook, g_value_get_enum (value));
1521 case PROP_GROUP_NAME:
1522 gtk_notebook_set_group_name (notebook, g_value_get_string (value));
1525 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1531 gtk_notebook_get_property (GObject *object,
1536 GtkNotebook *notebook = GTK_NOTEBOOK (object);
1537 GtkNotebookPrivate *priv = notebook->priv;
1541 case PROP_SHOW_TABS:
1542 g_value_set_boolean (value, priv->show_tabs);
1544 case PROP_SHOW_BORDER:
1545 g_value_set_boolean (value, priv->show_border);
1547 case PROP_SCROLLABLE:
1548 g_value_set_boolean (value, priv->scrollable);
1550 case PROP_ENABLE_POPUP:
1551 g_value_set_boolean (value, priv->menu != NULL);
1554 g_value_set_int (value, gtk_notebook_get_current_page (notebook));
1557 g_value_set_enum (value, priv->tab_pos);
1559 case PROP_GROUP_NAME:
1560 g_value_set_string (value, gtk_notebook_get_group_name (notebook));
1563 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1568 /* Private GtkWidget Methods :
1571 * gtk_notebook_unmap
1572 * gtk_notebook_realize
1573 * gtk_notebook_size_request
1574 * gtk_notebook_size_allocate
1575 * gtk_notebook_expose
1576 * gtk_notebook_scroll
1577 * gtk_notebook_button_press
1578 * gtk_notebook_button_release
1579 * gtk_notebook_popup_menu
1580 * gtk_notebook_leave_notify
1581 * gtk_notebook_motion_notify
1582 * gtk_notebook_focus_in
1583 * gtk_notebook_focus_out
1584 * gtk_notebook_draw_focus
1585 * gtk_notebook_style_set
1586 * gtk_notebook_drag_begin
1587 * gtk_notebook_drag_end
1588 * gtk_notebook_drag_failed
1589 * gtk_notebook_drag_motion
1590 * gtk_notebook_drag_drop
1591 * gtk_notebook_drag_data_get
1592 * gtk_notebook_drag_data_received
1595 gtk_notebook_get_event_window_position (GtkNotebook *notebook,
1596 GdkRectangle *rectangle)
1598 GtkNotebookPrivate *priv = notebook->priv;
1599 GtkAllocation allocation, action_allocation;
1600 GtkWidget *widget = GTK_WIDGET (notebook);
1601 guint border_width = gtk_container_get_border_width (GTK_CONTAINER (notebook));
1602 GtkNotebookPage *visible_page = NULL;
1604 gint tab_pos = get_effective_tab_pos (notebook);
1608 for (tmp_list = priv->children; tmp_list; tmp_list = tmp_list->next)
1610 GtkNotebookPage *page = tmp_list->data;
1611 if (gtk_widget_get_visible (page->child))
1613 visible_page = page;
1618 if (priv->show_tabs && visible_page)
1622 gtk_widget_get_allocation (widget, &allocation);
1624 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
1625 rectangle->x = allocation.x + border_width;
1626 rectangle->y = allocation.y + border_width;
1631 case GTK_POS_BOTTOM:
1632 rectangle->width = allocation.width - 2 * border_width;
1633 rectangle->height = visible_page->requisition.height;
1634 if (tab_pos == GTK_POS_BOTTOM)
1635 rectangle->y += allocation.height - 2 * border_width - rectangle->height;
1637 for (i = 0; i < N_ACTION_WIDGETS; i++)
1639 if (priv->action_widget[i] &&
1640 gtk_widget_get_visible (priv->action_widget[i]))
1642 gtk_widget_get_allocation (priv->action_widget[i], &action_allocation);
1644 rectangle->width -= action_allocation.width;
1645 if ((!is_rtl && i == ACTION_WIDGET_START) ||
1646 (is_rtl && i == ACTION_WIDGET_END))
1647 rectangle->x += action_allocation.width;
1653 rectangle->width = visible_page->requisition.width;
1654 rectangle->height = allocation.height - 2 * border_width;
1655 if (tab_pos == GTK_POS_RIGHT)
1656 rectangle->x += allocation.width - 2 * border_width - rectangle->width;
1658 for (i = 0; i < N_ACTION_WIDGETS; i++)
1660 if (priv->action_widget[i] &&
1661 gtk_widget_get_visible (priv->action_widget[i]))
1663 gtk_widget_get_allocation (priv->action_widget[i], &action_allocation);
1665 rectangle->height -= action_allocation.height;
1667 if (i == ACTION_WIDGET_START)
1668 rectangle->y += action_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 GtkNotebookPrivate *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 GtkNotebookPrivate *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 GtkNotebookPrivate *priv = notebook->priv;
1757 GdkWindowAttr attributes;
1758 gint attributes_mask;
1759 GdkRectangle event_window_pos;
1761 gtk_widget_set_realized (widget, TRUE);
1763 gtk_notebook_get_event_window_position (notebook, &event_window_pos);
1765 window = gtk_widget_get_parent_window (widget);
1766 gtk_widget_set_window (widget, window);
1767 g_object_ref (window);
1769 attributes.window_type = GDK_WINDOW_CHILD;
1770 attributes.x = event_window_pos.x;
1771 attributes.y = event_window_pos.y;
1772 attributes.width = event_window_pos.width;
1773 attributes.height = event_window_pos.height;
1774 attributes.wclass = GDK_INPUT_ONLY;
1775 attributes.event_mask = gtk_widget_get_events (widget);
1776 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
1777 GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK |
1778 GDK_POINTER_MOTION_MASK | GDK_LEAVE_NOTIFY_MASK);
1779 attributes_mask = GDK_WA_X | GDK_WA_Y;
1781 priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
1782 &attributes, attributes_mask);
1783 gdk_window_set_user_data (priv->event_window, notebook);
1785 gtk_widget_style_attach (widget);
1789 gtk_notebook_unrealize (GtkWidget *widget)
1791 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
1792 GtkNotebookPrivate *priv = notebook->priv;
1794 gdk_window_set_user_data (priv->event_window, NULL);
1795 gdk_window_destroy (priv->event_window);
1796 priv->event_window = NULL;
1798 if (priv->drag_window)
1800 gdk_window_set_user_data (priv->drag_window, NULL);
1801 gdk_window_destroy (priv->drag_window);
1802 priv->drag_window = NULL;
1805 GTK_WIDGET_CLASS (gtk_notebook_parent_class)->unrealize (widget);
1809 gtk_notebook_size_request (GtkWidget *widget,
1810 GtkRequisition *requisition)
1812 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
1813 GtkNotebookPrivate *priv = notebook->priv;
1814 GtkNotebookPage *page;
1816 GtkRequisition child_requisition;
1817 GtkRequisition action_widget_requisition[2] = { { 0 }, { 0 } };
1818 gboolean switch_page = FALSE;
1824 gint scroll_arrow_hlength;
1825 gint scroll_arrow_vlength;
1828 gtk_widget_style_get (widget,
1829 "focus-line-width", &focus_width,
1830 "tab-overlap", &tab_overlap,
1831 "tab-curvature", &tab_curvature,
1832 "arrow-spacing", &arrow_spacing,
1833 "scroll-arrow-hlength", &scroll_arrow_hlength,
1834 "scroll-arrow-vlength", &scroll_arrow_vlength,
1837 requisition->width = 0;
1838 requisition->height = 0;
1840 for (children = priv->children, vis_pages = 0; children;
1841 children = children->next)
1844 page = children->data;
1846 if (gtk_widget_get_visible (page->child))
1849 gtk_size_request_get_size (GTK_SIZE_REQUEST (page->child),
1850 &child_requisition, NULL);
1852 requisition->width = MAX (requisition->width,
1853 child_requisition.width);
1854 requisition->height = MAX (requisition->height,
1855 child_requisition.height);
1857 if (priv->menu && page->menu_label)
1859 parent = gtk_widget_get_parent (page->menu_label);
1860 if (parent && !gtk_widget_get_visible (parent))
1861 gtk_widget_show (parent);
1866 if (page == priv->cur_page)
1869 if (priv->menu && page->menu_label)
1871 parent = gtk_widget_get_parent (page->menu_label);
1872 if (parent && gtk_widget_get_visible (parent))
1873 gtk_widget_hide (parent);
1878 if (priv->show_border || priv->show_tabs)
1882 style = gtk_widget_get_style (widget);
1884 requisition->width += style->xthickness * 2;
1885 requisition->height += style->ythickness * 2;
1887 if (priv->show_tabs)
1890 gint tab_height = 0;
1894 gint action_width = 0;
1895 gint action_height = 0;
1897 for (children = priv->children; children;
1898 children = children->next)
1900 page = children->data;
1902 if (gtk_widget_get_visible (page->child))
1904 if (!gtk_widget_get_visible (page->tab_label))
1905 gtk_widget_show (page->tab_label);
1907 gtk_size_request_get_size (GTK_SIZE_REQUEST (page->tab_label),
1908 &child_requisition, NULL);
1910 page->requisition.width = child_requisition.width + 2 * style->xthickness;
1911 page->requisition.height = child_requisition.height + 2 * style->ythickness;
1913 switch (priv->tab_pos)
1916 case GTK_POS_BOTTOM:
1917 page->requisition.height += 2 * (priv->tab_vborder +
1919 tab_height = MAX (tab_height, page->requisition.height);
1920 tab_max = MAX (tab_max, page->requisition.width);
1924 page->requisition.width += 2 * (priv->tab_hborder +
1926 tab_width = MAX (tab_width, page->requisition.width);
1927 tab_max = MAX (tab_max, page->requisition.height);
1931 else if (gtk_widget_get_visible (page->tab_label))
1932 gtk_widget_hide (page->tab_label);
1935 children = priv->children;
1939 for (i = 0; i < N_ACTION_WIDGETS; i++)
1941 if (priv->action_widget[i])
1943 gtk_size_request_get_size (GTK_SIZE_REQUEST (priv->action_widget[i]),
1944 &action_widget_requisition[i], NULL);
1945 action_widget_requisition[i].width += style->xthickness;
1946 action_widget_requisition[i].height += style->ythickness;
1950 switch (priv->tab_pos)
1953 case GTK_POS_BOTTOM:
1954 if (tab_height == 0)
1957 if (priv->scrollable && vis_pages > 1 &&
1958 requisition->width < tab_width)
1959 tab_height = MAX (tab_height, scroll_arrow_hlength);
1961 tab_height = MAX (tab_height, action_widget_requisition[ACTION_WIDGET_START].height);
1962 tab_height = MAX (tab_height, action_widget_requisition[ACTION_WIDGET_END].height);
1964 padding = 2 * (tab_curvature + focus_width +
1965 priv->tab_hborder) - tab_overlap;
1969 page = children->data;
1970 children = children->next;
1972 if (!gtk_widget_get_visible (page->child))
1975 if (priv->homogeneous)
1976 page->requisition.width = tab_max;
1978 page->requisition.width += padding;
1980 tab_width += page->requisition.width;
1981 page->requisition.height = tab_height;
1984 if (priv->scrollable && vis_pages > 1 &&
1985 requisition->width < tab_width)
1986 tab_width = tab_max + 2 * (scroll_arrow_hlength + arrow_spacing);
1988 action_width += action_widget_requisition[ACTION_WIDGET_START].width;
1989 action_width += action_widget_requisition[ACTION_WIDGET_END].width;
1990 if (priv->homogeneous && !priv->scrollable)
1991 requisition->width = MAX (requisition->width,
1992 vis_pages * tab_max +
1993 tab_overlap + action_width);
1995 requisition->width = MAX (requisition->width,
1996 tab_width + tab_overlap + action_width);
1998 requisition->height += tab_height;
2005 if (priv->scrollable && vis_pages > 1 &&
2006 requisition->height < tab_height)
2007 tab_width = MAX (tab_width,
2008 arrow_spacing + 2 * scroll_arrow_vlength);
2010 tab_width = MAX (tab_width, action_widget_requisition[ACTION_WIDGET_START].width);
2011 tab_width = MAX (tab_width, action_widget_requisition[ACTION_WIDGET_END].width);
2013 padding = 2 * (tab_curvature + focus_width +
2014 priv->tab_vborder) - tab_overlap;
2019 page = children->data;
2020 children = children->next;
2022 if (!gtk_widget_get_visible (page->child))
2025 page->requisition.width = tab_width;
2027 if (priv->homogeneous)
2028 page->requisition.height = tab_max;
2030 page->requisition.height += padding;
2032 tab_height += page->requisition.height;
2035 if (priv->scrollable && vis_pages > 1 &&
2036 requisition->height < tab_height)
2037 tab_height = tab_max + (2 * scroll_arrow_vlength + arrow_spacing);
2038 action_height += action_widget_requisition[ACTION_WIDGET_START].height;
2039 action_height += action_widget_requisition[ACTION_WIDGET_END].height;
2041 if (priv->homogeneous && !priv->scrollable)
2042 requisition->height =
2043 MAX (requisition->height,
2044 vis_pages * tab_max + tab_overlap + action_height);
2046 requisition->height =
2047 MAX (requisition->height,
2048 tab_height + tab_overlap + action_height);
2050 if (!priv->homogeneous || priv->scrollable)
2052 requisition->height = MAX (requisition->height,
2053 vis_pages * tab_max +
2056 requisition->width += tab_width;
2063 for (children = priv->children; children;
2064 children = children->next)
2066 page = children->data;
2068 if (page->tab_label && gtk_widget_get_visible (page->tab_label))
2069 gtk_widget_hide (page->tab_label);
2074 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
2076 requisition->width += border_width * 2;
2077 requisition->height += border_width * 2;
2083 for (children = priv->children; children;
2084 children = children->next)
2086 page = children->data;
2087 if (gtk_widget_get_visible (page->child))
2089 gtk_notebook_switch_page (notebook, page);
2094 else if (gtk_widget_get_visible (widget))
2096 requisition->width = border_width * 2;
2097 requisition->height = border_width * 2;
2100 if (vis_pages && !priv->cur_page)
2102 children = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, TRUE);
2105 priv->first_tab = children;
2106 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (children));
2112 gtk_notebook_size_allocate (GtkWidget *widget,
2113 GtkAllocation *allocation)
2115 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2116 GtkNotebookPrivate *priv = notebook->priv;
2118 gint tab_pos = get_effective_tab_pos (notebook);
2122 style = gtk_widget_get_style (widget);
2124 gtk_widget_style_get (widget, "focus-line-width", &focus_width, NULL);
2126 gtk_widget_set_allocation (widget, allocation);
2128 if (gtk_widget_get_realized (widget))
2130 GdkRectangle position;
2132 if (gtk_notebook_get_event_window_position (notebook, &position))
2134 gdk_window_move_resize (priv->event_window,
2135 position.x, position.y,
2136 position.width, position.height);
2137 if (gtk_widget_get_mapped (GTK_WIDGET (notebook)))
2138 gdk_window_show_unraised (priv->event_window);
2141 gdk_window_hide (priv->event_window);
2146 guint border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
2147 GtkNotebookPage *page;
2148 GtkAllocation child_allocation;
2152 child_allocation.x = allocation->x + border_width;
2153 child_allocation.y = allocation->y + border_width;
2154 child_allocation.width = MAX (1, allocation->width - border_width * 2);
2155 child_allocation.height = MAX (1, allocation->height - border_width * 2);
2157 if (priv->show_tabs || priv->show_border)
2159 child_allocation.x += style->xthickness;
2160 child_allocation.y += style->ythickness;
2161 child_allocation.width = MAX (1, child_allocation.width - style->xthickness * 2);
2162 child_allocation.height = MAX (1, child_allocation.height - style->ythickness * 2);
2164 if (priv->show_tabs && priv->children && priv->cur_page)
2169 child_allocation.y += priv->cur_page->requisition.height;
2170 case GTK_POS_BOTTOM:
2171 child_allocation.height =
2172 MAX (1, child_allocation.height -
2173 priv->cur_page->requisition.height);
2176 child_allocation.x += priv->cur_page->requisition.width;
2178 child_allocation.width =
2179 MAX (1, child_allocation.width -
2180 priv->cur_page->requisition.width);
2184 for (i = 0; i < N_ACTION_WIDGETS; i++)
2186 GtkAllocation widget_allocation;
2187 GtkRequisition requisition;
2189 if (!priv->action_widget[i])
2192 widget_allocation.x = allocation->x + border_width;
2193 widget_allocation.y = allocation->y + border_width;
2194 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2196 gtk_size_request_get_size (GTK_SIZE_REQUEST (priv->action_widget[i]),
2197 &requisition, NULL);
2201 case GTK_POS_BOTTOM:
2202 widget_allocation.y += allocation->height - 2 * border_width - priv->cur_page->requisition.height;
2205 widget_allocation.width = requisition.width;
2206 widget_allocation.height = priv->cur_page->requisition.height - style->ythickness;
2208 if ((i == ACTION_WIDGET_START && is_rtl) ||
2209 (i == ACTION_WIDGET_END && !is_rtl))
2210 widget_allocation.x += allocation->width - 2 * border_width - requisition.width;
2211 if (tab_pos == GTK_POS_TOP) /* no fall through */
2212 widget_allocation.y += 2 * focus_width;
2215 widget_allocation.x += allocation->width - 2 * border_width - priv->cur_page->requisition.width;
2218 widget_allocation.height = requisition.height;
2219 widget_allocation.width = priv->cur_page->requisition.width - style->xthickness;
2221 if (i == ACTION_WIDGET_END)
2222 widget_allocation.y += allocation->height - 2 * border_width - requisition.height;
2223 if (tab_pos == GTK_POS_LEFT) /* no fall through */
2224 widget_allocation.x += 2 * focus_width;
2228 gtk_widget_size_allocate (priv->action_widget[i], &widget_allocation);
2233 children = priv->children;
2236 page = children->data;
2237 children = children->next;
2239 if (gtk_widget_get_visible (page->child))
2240 gtk_widget_size_allocate (page->child, &child_allocation);
2243 gtk_notebook_pages_allocate (notebook);
2248 gtk_notebook_expose (GtkWidget *widget,
2249 GdkEventExpose *event)
2251 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2252 GtkNotebookPrivate *priv = notebook->priv;
2255 if (event->window == priv->drag_window)
2257 GdkRectangle area = { 0, };
2260 /* FIXME: This is a workaround to make tabs reordering work better
2261 * with engines with rounded tabs. If the drag window background
2262 * isn't set, the rounded corners would be black.
2264 * Ideally, these corners should be made transparent, Either by using
2265 * ARGB visuals or shape windows.
2267 cr = gdk_cairo_create (priv->drag_window);
2268 gdk_cairo_set_source_color (cr, >k_widget_get_style(widget)->bg [GTK_STATE_NORMAL]);
2272 gdk_drawable_get_size (priv->drag_window,
2273 &area.width, &area.height);
2274 gtk_notebook_draw_tab (notebook,
2277 gtk_notebook_draw_focus (widget, event);
2278 gtk_container_propagate_expose (GTK_CONTAINER (notebook),
2279 priv->cur_page->tab_label, event);
2281 else if (gtk_widget_is_drawable (widget))
2283 gtk_notebook_paint (widget, &event->area);
2284 if (priv->show_tabs)
2286 GtkNotebookPage *page;
2289 gtk_notebook_draw_focus (widget, event);
2290 pages = priv->children;
2294 page = GTK_NOTEBOOK_PAGE (pages);
2295 pages = pages->next;
2297 if (gtk_widget_get_window (page->tab_label) == event->window &&
2298 gtk_widget_is_drawable (page->tab_label))
2299 gtk_container_propagate_expose (GTK_CONTAINER (notebook),
2300 page->tab_label, event);
2305 gtk_container_propagate_expose (GTK_CONTAINER (notebook),
2306 priv->cur_page->child,
2308 if (priv->show_tabs)
2310 for (i = 0; i < N_ACTION_WIDGETS; i++)
2312 if (priv->action_widget[i] &&
2313 gtk_widget_is_drawable (priv->action_widget[i]))
2314 gtk_container_propagate_expose (GTK_CONTAINER (notebook),
2315 priv->action_widget[i], event);
2324 gtk_notebook_show_arrows (GtkNotebook *notebook)
2326 GtkNotebookPrivate *priv = notebook->priv;
2327 gboolean show_arrow = FALSE;
2330 if (!priv->scrollable)
2333 children = priv->children;
2336 GtkNotebookPage *page = children->data;
2338 if (page->tab_label && !gtk_widget_get_child_visible (page->tab_label))
2341 children = children->next;
2348 gtk_notebook_get_arrow_rect (GtkNotebook *notebook,
2349 GdkRectangle *rectangle,
2350 GtkNotebookArrow arrow)
2352 GtkNotebookPrivate *priv = notebook->priv;
2353 GdkRectangle event_window_pos;
2354 gboolean before = ARROW_IS_BEFORE (arrow);
2355 gboolean left = ARROW_IS_LEFT (arrow);
2357 if (gtk_notebook_get_event_window_position (notebook, &event_window_pos))
2359 gint scroll_arrow_hlength;
2360 gint scroll_arrow_vlength;
2362 gtk_widget_style_get (GTK_WIDGET (notebook),
2363 "scroll-arrow-hlength", &scroll_arrow_hlength,
2364 "scroll-arrow-vlength", &scroll_arrow_vlength,
2367 switch (priv->tab_pos)
2371 rectangle->width = scroll_arrow_vlength;
2372 rectangle->height = scroll_arrow_vlength;
2374 if ((before && (priv->has_before_previous != priv->has_before_next)) ||
2375 (!before && (priv->has_after_previous != priv->has_after_next)))
2376 rectangle->x = event_window_pos.x + (event_window_pos.width - rectangle->width) / 2;
2378 rectangle->x = event_window_pos.x + event_window_pos.width / 2 - rectangle->width;
2380 rectangle->x = event_window_pos.x + event_window_pos.width / 2;
2381 rectangle->y = event_window_pos.y;
2383 rectangle->y += event_window_pos.height - rectangle->height;
2387 case GTK_POS_BOTTOM:
2388 rectangle->width = scroll_arrow_hlength;
2389 rectangle->height = scroll_arrow_hlength;
2393 if (left || !priv->has_before_previous)
2394 rectangle->x = event_window_pos.x;
2396 rectangle->x = event_window_pos.x + rectangle->width;
2400 if (!left || !priv->has_after_next)
2401 rectangle->x = event_window_pos.x + event_window_pos.width - rectangle->width;
2403 rectangle->x = event_window_pos.x + event_window_pos.width - 2 * rectangle->width;
2405 rectangle->y = event_window_pos.y + (event_window_pos.height - rectangle->height) / 2;
2411 static GtkNotebookArrow
2412 gtk_notebook_get_arrow (GtkNotebook *notebook,
2416 GtkNotebookPrivate *priv = notebook->priv;
2417 GdkRectangle arrow_rect;
2418 GdkRectangle event_window_pos;
2421 GtkNotebookArrow arrow[4];
2423 arrow[0] = priv->has_before_previous ? ARROW_LEFT_BEFORE : ARROW_NONE;
2424 arrow[1] = priv->has_before_next ? ARROW_RIGHT_BEFORE : ARROW_NONE;
2425 arrow[2] = priv->has_after_previous ? ARROW_LEFT_AFTER : ARROW_NONE;
2426 arrow[3] = priv->has_after_next ? ARROW_RIGHT_AFTER : ARROW_NONE;
2428 if (gtk_notebook_show_arrows (notebook))
2430 gtk_notebook_get_event_window_position (notebook, &event_window_pos);
2431 for (i = 0; i < 4; i++)
2433 if (arrow[i] == ARROW_NONE)
2436 gtk_notebook_get_arrow_rect (notebook, &arrow_rect, arrow[i]);
2438 x0 = x - arrow_rect.x;
2439 y0 = y - arrow_rect.y;
2441 if (y0 >= 0 && y0 < arrow_rect.height &&
2442 x0 >= 0 && x0 < arrow_rect.width)
2451 gtk_notebook_do_arrow (GtkNotebook *notebook,
2452 GtkNotebookArrow arrow)
2454 GtkNotebookPrivate *priv = notebook->priv;
2455 GtkWidget *widget = GTK_WIDGET (notebook);
2456 gboolean is_rtl, left;
2458 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2459 left = (ARROW_IS_LEFT (arrow) && !is_rtl) ||
2460 (!ARROW_IS_LEFT (arrow) && is_rtl);
2462 if (!priv->focus_tab ||
2463 gtk_notebook_search_page (notebook, priv->focus_tab,
2464 left ? STEP_PREV : STEP_NEXT,
2467 gtk_notebook_change_current_page (notebook, left ? -1 : 1);
2468 gtk_widget_grab_focus (widget);
2473 gtk_notebook_arrow_button_press (GtkNotebook *notebook,
2474 GtkNotebookArrow arrow,
2477 GtkNotebookPrivate *priv = notebook->priv;
2478 GtkWidget *widget = GTK_WIDGET (notebook);
2479 gboolean is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2480 gboolean left = (ARROW_IS_LEFT (arrow) && !is_rtl) ||
2481 (!ARROW_IS_LEFT (arrow) && is_rtl);
2483 if (!gtk_widget_has_focus (widget))
2484 gtk_widget_grab_focus (widget);
2486 priv->button = button;
2487 priv->click_child = arrow;
2491 gtk_notebook_do_arrow (notebook, arrow);
2492 gtk_notebook_set_scroll_timer (notebook);
2494 else if (button == 2)
2495 gtk_notebook_page_select (notebook, TRUE);
2496 else if (button == 3)
2497 gtk_notebook_switch_focus_tab (notebook,
2498 gtk_notebook_search_page (notebook,
2500 left ? STEP_NEXT : STEP_PREV,
2502 gtk_notebook_redraw_arrows (notebook);
2508 get_widget_coordinates (GtkWidget *widget,
2513 GdkWindow *window = ((GdkEventAny *)event)->window;
2516 if (!gdk_event_get_coords (event, &tx, &ty))
2519 while (window && window != gtk_widget_get_window (widget))
2521 gint window_x, window_y;
2523 gdk_window_get_position (window, &window_x, &window_y);
2527 window = gdk_window_get_parent (window);
2542 get_tab_at_pos (GtkNotebook *notebook, gint x, gint y)
2544 GtkNotebookPrivate *priv = notebook->priv;
2545 GtkNotebookPage *page;
2548 children = priv->children;
2551 page = children->data;
2553 if (gtk_widget_get_visible (page->child) &&
2554 page->tab_label && gtk_widget_get_mapped (page->tab_label) &&
2555 (x >= page->allocation.x) &&
2556 (y >= page->allocation.y) &&
2557 (x <= (page->allocation.x + page->allocation.width)) &&
2558 (y <= (page->allocation.y + page->allocation.height)))
2561 children = children->next;
2568 gtk_notebook_button_press (GtkWidget *widget,
2569 GdkEventButton *event)
2571 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2572 GtkNotebookPrivate *priv = notebook->priv;
2573 GtkNotebookPage *page;
2575 GtkNotebookArrow arrow;
2578 if (event->type != GDK_BUTTON_PRESS || !priv->children ||
2582 if (!get_widget_coordinates (widget, (GdkEvent *)event, &x, &y))
2585 arrow = gtk_notebook_get_arrow (notebook, x, y);
2587 return gtk_notebook_arrow_button_press (notebook, arrow, event->button);
2589 if (event->button == 3 && priv->menu)
2591 gtk_menu_popup (GTK_MENU (priv->menu), NULL, NULL,
2592 NULL, NULL, 3, event->time);
2596 if (event->button != 1)
2599 priv->button = event->button;
2601 if ((tab = get_tab_at_pos (notebook, x, y)) != NULL)
2603 gboolean page_changed, was_focus;
2606 page_changed = page != priv->cur_page;
2607 was_focus = gtk_widget_is_focus (widget);
2609 gtk_notebook_switch_focus_tab (notebook, tab);
2610 gtk_widget_grab_focus (widget);
2612 if (page_changed && !was_focus)
2613 gtk_widget_child_focus (page->child, GTK_DIR_TAB_FORWARD);
2615 /* save press to possibly begin a drag */
2616 if (page->reorderable || page->detachable)
2618 priv->during_detach = FALSE;
2619 priv->during_reorder = FALSE;
2620 priv->pressed_button = event->button;
2625 priv->drag_begin_x = priv->mouse_x;
2626 priv->drag_begin_y = priv->mouse_y;
2627 priv->drag_offset_x = priv->drag_begin_x - page->allocation.x;
2628 priv->drag_offset_y = priv->drag_begin_y - page->allocation.y;
2636 popup_position_func (GtkMenu *menu,
2642 GtkNotebook *notebook = data;
2643 GtkNotebookPrivate *priv = notebook->priv;
2644 GtkAllocation allocation;
2646 GtkRequisition requisition;
2648 if (priv->focus_tab)
2650 GtkNotebookPage *page;
2652 page = priv->focus_tab->data;
2653 w = page->tab_label;
2657 w = GTK_WIDGET (notebook);
2660 gdk_window_get_origin (gtk_widget_get_window (w), x, y);
2662 gtk_widget_get_allocation (w, &allocation);
2663 gtk_size_request_get_size (GTK_SIZE_REQUEST (menu),
2664 &requisition, NULL);
2666 if (gtk_widget_get_direction (w) == GTK_TEXT_DIR_RTL)
2667 *x += allocation.x + allocation.width - requisition.width;
2671 *y += allocation.y + allocation.height;
2677 gtk_notebook_popup_menu (GtkWidget *widget)
2679 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2680 GtkNotebookPrivate *priv = notebook->priv;
2684 gtk_menu_popup (GTK_MENU (priv->menu), NULL, NULL,
2685 popup_position_func, notebook,
2686 0, gtk_get_current_event_time ());
2687 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menu), FALSE);
2695 stop_scrolling (GtkNotebook *notebook)
2697 GtkNotebookPrivate *priv = notebook->priv;
2701 g_source_remove (priv->timer);
2703 priv->need_timer = FALSE;
2705 priv->click_child = 0;
2707 gtk_notebook_redraw_arrows (notebook);
2711 get_drop_position (GtkNotebook *notebook,
2714 GtkNotebookPrivate *priv = notebook->priv;
2715 GList *children, *last_child;
2716 GtkNotebookPage *page;
2723 is_rtl = gtk_widget_get_direction ((GtkWidget *) notebook) == GTK_TEXT_DIR_RTL;
2724 children = priv->children;
2729 page = children->data;
2731 if ((priv->operation != DRAG_OPERATION_REORDER || page != priv->cur_page) &&
2732 gtk_widget_get_visible (page->child) &&
2734 gtk_widget_get_mapped (page->tab_label) &&
2737 switch (priv->tab_pos)
2740 case GTK_POS_BOTTOM:
2743 if ((page->pack == GTK_PACK_START && PAGE_MIDDLE_X (page) > x) ||
2744 (page->pack == GTK_PACK_END && PAGE_MIDDLE_X (page) < x))
2749 if ((page->pack == GTK_PACK_START && PAGE_MIDDLE_X (page) < x) ||
2750 (page->pack == GTK_PACK_END && PAGE_MIDDLE_X (page) > x))
2757 if ((page->pack == GTK_PACK_START && PAGE_MIDDLE_Y (page) > y) ||
2758 (page->pack == GTK_PACK_END && PAGE_MIDDLE_Y (page) < y))
2764 last_child = children->next;
2767 children = children->next;
2774 show_drag_window (GtkNotebook *notebook,
2775 GtkNotebookPrivate *priv,
2776 GtkNotebookPage *page,
2779 GtkWidget *widget = GTK_WIDGET (notebook);
2781 if (!priv->drag_window)
2783 GdkWindowAttr attributes;
2784 guint attributes_mask;
2786 attributes.x = page->allocation.x;
2787 attributes.y = page->allocation.y;
2788 attributes.width = page->allocation.width;
2789 attributes.height = page->allocation.height;
2790 attributes.window_type = GDK_WINDOW_CHILD;
2791 attributes.wclass = GDK_INPUT_OUTPUT;
2792 attributes.visual = gtk_widget_get_visual (widget);
2793 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
2794 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
2796 priv->drag_window = gdk_window_new (gtk_widget_get_parent_window (widget),
2799 gdk_window_set_user_data (priv->drag_window, widget);
2802 g_object_ref (page->tab_label);
2803 gtk_widget_unparent (page->tab_label);
2804 gtk_widget_set_parent_window (page->tab_label, priv->drag_window);
2805 gtk_widget_set_parent (page->tab_label, widget);
2806 g_object_unref (page->tab_label);
2808 gdk_window_show (priv->drag_window);
2810 /* the grab will dissapear when the window is hidden */
2811 gdk_device_grab (device, priv->drag_window,
2812 GDK_OWNERSHIP_WINDOW, FALSE,
2813 GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK,
2814 NULL, GDK_CURRENT_TIME);
2817 /* This function undoes the reparenting that happens both when drag_window
2818 * is shown for reordering and when the DnD icon is shown for detaching
2821 hide_drag_window (GtkNotebook *notebook,
2822 GtkNotebookPrivate *priv,
2823 GtkNotebookPage *page)
2825 GtkWidget *widget = GTK_WIDGET (notebook);
2826 GtkWidget *parent = gtk_widget_get_parent (page->tab_label);
2828 if (gtk_widget_get_window (page->tab_label) != gtk_widget_get_window (widget) ||
2829 !NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page))
2831 g_object_ref (page->tab_label);
2833 if (GTK_IS_WINDOW (parent))
2835 /* parent widget is the drag window */
2836 gtk_container_remove (GTK_CONTAINER (parent), page->tab_label);
2839 gtk_widget_unparent (page->tab_label);
2841 gtk_widget_set_parent (page->tab_label, widget);
2842 g_object_unref (page->tab_label);
2845 if (priv->drag_window &&
2846 gdk_window_is_visible (priv->drag_window))
2847 gdk_window_hide (priv->drag_window);
2851 gtk_notebook_stop_reorder (GtkNotebook *notebook)
2853 GtkNotebookPrivate *priv = notebook->priv;
2854 GtkNotebookPage *page;
2856 if (priv->operation == DRAG_OPERATION_DETACH)
2857 page = priv->detached_tab;
2859 page = priv->cur_page;
2861 if (!page || !page->tab_label)
2864 priv->pressed_button = -1;
2866 if (page->reorderable || page->detachable)
2868 if (priv->during_reorder)
2870 gint old_page_num, page_num;
2873 element = get_drop_position (notebook, page->pack);
2874 old_page_num = g_list_position (priv->children, priv->focus_tab);
2875 page_num = reorder_tab (notebook, element, priv->focus_tab);
2876 gtk_notebook_child_reordered (notebook, page);
2878 if (priv->has_scrolled || old_page_num != page_num)
2879 g_signal_emit (notebook,
2880 notebook_signals[PAGE_REORDERED], 0,
2881 page->child, page_num);
2883 priv->has_scrolled = FALSE;
2884 priv->during_reorder = FALSE;
2887 hide_drag_window (notebook, priv, page);
2889 priv->operation = DRAG_OPERATION_NONE;
2890 gtk_notebook_pages_allocate (notebook);
2892 if (priv->dnd_timer)
2894 g_source_remove (priv->dnd_timer);
2895 priv->dnd_timer = 0;
2901 gtk_notebook_button_release (GtkWidget *widget,
2902 GdkEventButton *event)
2904 GtkNotebook *notebook;
2905 GtkNotebookPrivate *priv;
2906 GtkNotebookPage *page;
2908 if (event->type != GDK_BUTTON_RELEASE)
2911 notebook = GTK_NOTEBOOK (widget);
2912 priv = notebook->priv;
2914 page = priv->cur_page;
2916 if (!priv->during_detach &&
2917 page->reorderable &&
2918 event->button == priv->pressed_button)
2919 gtk_notebook_stop_reorder (notebook);
2921 if (event->button == priv->button)
2923 stop_scrolling (notebook);
2931 gtk_notebook_leave_notify (GtkWidget *widget,
2932 GdkEventCrossing *event)
2934 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2935 GtkNotebookPrivate *priv = notebook->priv;
2938 if (!get_widget_coordinates (widget, (GdkEvent *)event, &x, &y))
2944 gtk_notebook_redraw_arrows (notebook);
2950 static GtkNotebookPointerPosition
2951 get_pointer_position (GtkNotebook *notebook)
2953 GtkNotebookPrivate *priv = notebook->priv;
2954 GtkWidget *widget = GTK_WIDGET (notebook);
2955 gint wx, wy, width, height;
2958 if (!priv->scrollable)
2959 return POINTER_BETWEEN;
2961 gdk_window_get_position (priv->event_window, &wx, &wy);
2962 gdk_drawable_get_size (GDK_DRAWABLE (priv->event_window), &width, &height);
2964 if (priv->tab_pos == GTK_POS_TOP ||
2965 priv->tab_pos == GTK_POS_BOTTOM)
2969 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2970 x = priv->mouse_x - wx;
2972 if (x > width - SCROLL_THRESHOLD)
2973 return (is_rtl) ? POINTER_BEFORE : POINTER_AFTER;
2974 else if (x < SCROLL_THRESHOLD)
2975 return (is_rtl) ? POINTER_AFTER : POINTER_BEFORE;
2977 return POINTER_BETWEEN;
2983 y = priv->mouse_y - wy;
2984 if (y > height - SCROLL_THRESHOLD)
2985 return POINTER_AFTER;
2986 else if (y < SCROLL_THRESHOLD)
2987 return POINTER_BEFORE;
2989 return POINTER_BETWEEN;
2994 scroll_notebook_timer (gpointer data)
2996 GtkNotebook *notebook = GTK_NOTEBOOK (data);
2997 GtkNotebookPrivate *priv = notebook->priv;
2998 GtkNotebookPointerPosition pointer_position;
2999 GList *element, *first_tab;
3001 pointer_position = get_pointer_position (notebook);
3003 element = get_drop_position (notebook, priv->cur_page->pack);
3004 reorder_tab (notebook, element, priv->focus_tab);
3005 first_tab = gtk_notebook_search_page (notebook, priv->first_tab,
3006 (pointer_position == POINTER_BEFORE) ? STEP_PREV : STEP_NEXT,
3010 priv->first_tab = first_tab;
3011 gtk_notebook_pages_allocate (notebook);
3013 gdk_window_move_resize (priv->drag_window,
3014 priv->drag_window_x,
3015 priv->drag_window_y,
3016 priv->cur_page->allocation.width,
3017 priv->cur_page->allocation.height);
3018 gdk_window_raise (priv->drag_window);
3025 check_threshold (GtkNotebook *notebook,
3029 GtkNotebookPrivate *priv = notebook->priv;
3032 GdkRectangle rectangle = { 0, }; /* shut up gcc */
3033 GtkSettings *settings;
3035 widget = GTK_WIDGET (notebook);
3036 settings = gtk_widget_get_settings (GTK_WIDGET (notebook));
3037 g_object_get (G_OBJECT (settings), "gtk-dnd-drag-threshold", &dnd_threshold, NULL);
3039 /* we want a large threshold */
3040 dnd_threshold *= DND_THRESHOLD_MULTIPLIER;
3042 gdk_window_get_position (priv->event_window, &rectangle.x, &rectangle.y);
3043 gdk_drawable_get_size (GDK_DRAWABLE (priv->event_window), &rectangle.width, &rectangle.height);
3045 rectangle.x -= dnd_threshold;
3046 rectangle.width += 2 * dnd_threshold;
3047 rectangle.y -= dnd_threshold;
3048 rectangle.height += 2 * dnd_threshold;
3050 return (current_x < rectangle.x ||
3051 current_x > rectangle.x + rectangle.width ||
3052 current_y < rectangle.y ||
3053 current_y > rectangle.y + rectangle.height);
3057 gtk_notebook_motion_notify (GtkWidget *widget,
3058 GdkEventMotion *event)
3060 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
3061 GtkNotebookPrivate *priv = notebook->priv;
3062 GtkNotebookPage *page;
3063 GtkNotebookArrow arrow;
3064 GtkNotebookPointerPosition pointer_position;
3065 GtkSettings *settings;
3069 page = priv->cur_page;
3074 if (!(event->state & GDK_BUTTON1_MASK) &&
3075 priv->pressed_button != -1)
3077 gtk_notebook_stop_reorder (notebook);
3078 stop_scrolling (notebook);
3081 if (event->time < priv->timestamp + MSECS_BETWEEN_UPDATES)
3084 priv->timestamp = event->time;
3086 /* While animating the move, event->x is relative to the flying tab
3087 * (priv->drag_window has a pointer grab), but we need coordinates relative to
3088 * the notebook widget.
3090 gdk_window_get_origin (gtk_widget_get_window (widget), &x_win, &y_win);
3091 priv->mouse_x = event->x_root - x_win;
3092 priv->mouse_y = event->y_root - y_win;
3094 arrow = gtk_notebook_get_arrow (notebook, priv->mouse_x, priv->mouse_y);
3095 if (arrow != priv->in_child)
3097 priv->in_child = arrow;
3098 gtk_notebook_redraw_arrows (notebook);
3101 if (priv->pressed_button == -1)
3104 if (page->detachable &&
3105 check_threshold (notebook, priv->mouse_x, priv->mouse_y))
3107 priv->detached_tab = priv->cur_page;
3108 priv->during_detach = TRUE;
3110 gtk_drag_begin (widget, priv->source_targets, GDK_ACTION_MOVE,
3111 priv->pressed_button, (GdkEvent*) event);
3115 if (page->reorderable &&
3116 (priv->during_reorder ||
3117 gtk_drag_check_threshold (widget, priv->drag_begin_x, priv->drag_begin_y, priv->mouse_x, priv->mouse_y)))
3119 priv->during_reorder = TRUE;
3120 pointer_position = get_pointer_position (notebook);
3122 if (event->window == priv->drag_window &&
3123 pointer_position != POINTER_BETWEEN &&
3124 gtk_notebook_show_arrows (notebook))
3127 if (!priv->dnd_timer)
3129 priv->has_scrolled = TRUE;
3130 settings = gtk_widget_get_settings (GTK_WIDGET (notebook));
3131 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
3133 priv->dnd_timer = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
3134 scroll_notebook_timer,
3135 (gpointer) notebook);
3140 if (priv->dnd_timer)
3142 g_source_remove (priv->dnd_timer);
3143 priv->dnd_timer = 0;
3147 if (event->window == priv->drag_window ||
3148 priv->operation != DRAG_OPERATION_REORDER)
3150 /* the drag operation is beginning, create the window */
3151 if (priv->operation != DRAG_OPERATION_REORDER)
3153 priv->operation = DRAG_OPERATION_REORDER;
3154 show_drag_window (notebook, priv, page, event->device);
3157 gtk_notebook_pages_allocate (notebook);
3158 gdk_window_move_resize (priv->drag_window,
3159 priv->drag_window_x,
3160 priv->drag_window_y,
3161 page->allocation.width,
3162 page->allocation.height);
3170 gtk_notebook_grab_notify (GtkWidget *widget,
3171 gboolean was_grabbed)
3173 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
3177 gtk_notebook_stop_reorder (notebook);
3178 stop_scrolling (notebook);
3183 gtk_notebook_state_changed (GtkWidget *widget,
3184 GtkStateType previous_state)
3186 if (!gtk_widget_is_sensitive (widget))
3187 stop_scrolling (GTK_NOTEBOOK (widget));
3191 gtk_notebook_focus_in (GtkWidget *widget,
3192 GdkEventFocus *event)
3194 gtk_notebook_redraw_tabs (GTK_NOTEBOOK (widget));
3200 gtk_notebook_focus_out (GtkWidget *widget,
3201 GdkEventFocus *event)
3203 gtk_notebook_redraw_tabs (GTK_NOTEBOOK (widget));
3209 gtk_notebook_draw_focus (GtkWidget *widget,
3210 GdkEventExpose *event)
3212 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
3213 GtkNotebookPrivate *priv = notebook->priv;
3215 if (gtk_widget_has_focus (widget) && gtk_widget_is_drawable (widget) &&
3216 priv->show_tabs && priv->cur_page &&
3217 gtk_widget_get_window (priv->cur_page->tab_label) == event->window)
3219 GtkNotebookPage *page;
3221 page = priv->cur_page;
3223 if (gtk_widget_intersect (page->tab_label, &event->area, NULL))
3225 GtkAllocation tab_allocation;
3229 gtk_widget_style_get (widget, "focus-line-width", &focus_width, NULL);
3231 gtk_widget_get_allocation (page->tab_label, &tab_allocation);
3232 area.x = tab_allocation.x - focus_width;
3233 area.y = tab_allocation.y - focus_width;
3234 area.width = tab_allocation.width + 2 * focus_width;
3235 area.height = tab_allocation.height + 2 * focus_width;
3237 gtk_paint_focus (gtk_widget_get_style (widget), event->window,
3238 gtk_widget_get_state (widget), NULL, widget, "tab",
3239 area.x, area.y, area.width, area.height);
3245 gtk_notebook_style_set (GtkWidget *widget,
3248 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
3249 GtkNotebookPrivate *priv = notebook->priv;
3251 gboolean has_before_previous;
3252 gboolean has_before_next;
3253 gboolean has_after_previous;
3254 gboolean has_after_next;
3256 gtk_widget_style_get (widget,
3257 "has-backward-stepper", &has_before_previous,
3258 "has-secondary-forward-stepper", &has_before_next,
3259 "has-secondary-backward-stepper", &has_after_previous,
3260 "has-forward-stepper", &has_after_next,
3263 priv->has_before_previous = has_before_previous;
3264 priv->has_before_next = has_before_next;
3265 priv->has_after_previous = has_after_previous;
3266 priv->has_after_next = has_after_next;
3268 GTK_WIDGET_CLASS (gtk_notebook_parent_class)->style_set (widget, previous);
3272 on_drag_icon_expose (GtkWidget *widget,
3273 GdkEventExpose *event,
3276 GtkWidget *notebook, *child;
3277 GtkRequisition requisition;
3280 notebook = GTK_WIDGET (data);
3281 child = gtk_bin_get_child (GTK_BIN (widget));
3283 gtk_size_request_get_size (GTK_SIZE_REQUEST (widget),
3284 &requisition, NULL);
3285 gap_pos = get_tab_gap_pos (GTK_NOTEBOOK (notebook));
3287 gtk_paint_extension (gtk_widget_get_style (notebook),
3288 gtk_widget_get_window (widget),
3289 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
3290 NULL, widget, "tab",
3292 requisition.width, requisition.height,
3295 gtk_container_propagate_expose (GTK_CONTAINER (widget), child, event);
3301 gtk_notebook_drag_begin (GtkWidget *widget,
3302 GdkDragContext *context)
3304 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
3305 GtkNotebookPrivate *priv = notebook->priv;
3306 GtkWidget *tab_label;
3308 if (priv->dnd_timer)
3310 g_source_remove (priv->dnd_timer);
3311 priv->dnd_timer = 0;
3314 priv->operation = DRAG_OPERATION_DETACH;
3315 gtk_notebook_pages_allocate (notebook);
3317 tab_label = priv->detached_tab->tab_label;
3319 hide_drag_window (notebook, priv, priv->cur_page);
3320 g_object_ref (tab_label);
3321 gtk_widget_unparent (tab_label);
3323 priv->dnd_window = gtk_window_new (GTK_WINDOW_POPUP);
3324 gtk_window_set_screen (GTK_WINDOW (priv->dnd_window),
3325 gtk_widget_get_screen (widget));
3326 gtk_container_add (GTK_CONTAINER (priv->dnd_window), tab_label);
3327 gtk_widget_set_size_request (priv->dnd_window,
3328 priv->detached_tab->allocation.width,
3329 priv->detached_tab->allocation.height);
3330 g_object_unref (tab_label);
3332 g_signal_connect (G_OBJECT (priv->dnd_window), "expose-event",
3333 G_CALLBACK (on_drag_icon_expose), notebook);
3335 gtk_drag_set_icon_widget (context, priv->dnd_window, -2, -2);
3339 gtk_notebook_drag_end (GtkWidget *widget,
3340 GdkDragContext *context)
3342 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
3343 GtkNotebookPrivate *priv = notebook->priv;
3345 gtk_notebook_stop_reorder (notebook);
3347 if (priv->detached_tab)
3348 gtk_notebook_switch_page (notebook, priv->detached_tab);
3350 _gtk_bin_set_child (GTK_BIN (priv->dnd_window), NULL);
3351 gtk_widget_destroy (priv->dnd_window);
3352 priv->dnd_window = NULL;
3354 priv->operation = DRAG_OPERATION_NONE;
3357 static GtkNotebook *
3358 gtk_notebook_create_window (GtkNotebook *notebook,
3367 gtk_notebook_drag_failed (GtkWidget *widget,
3368 GdkDragContext *context,
3369 GtkDragResult result,
3372 if (result == GTK_DRAG_RESULT_NO_TARGET)
3374 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
3375 GtkNotebookPrivate *priv = notebook->priv;
3376 GtkNotebook *dest_notebook = NULL;
3377 GdkDisplay *display;
3380 display = gtk_widget_get_display (widget);
3381 gdk_display_get_pointer (display, NULL, &x, &y, NULL);
3383 g_signal_emit (notebook, notebook_signals[CREATE_WINDOW], 0,
3384 priv->detached_tab->child, x, y, &dest_notebook);
3387 do_detach_tab (notebook, dest_notebook, priv->detached_tab->child, 0, 0);
3396 gtk_notebook_switch_tab_timeout (gpointer data)
3398 GtkNotebook *notebook = GTK_NOTEBOOK (data);
3399 GtkNotebookPrivate *priv = notebook->priv;
3403 priv->switch_tab_timer = 0;
3407 if ((tab = get_tab_at_pos (notebook, x, y)) != NULL)
3409 /* FIXME: hack, we don't want the
3410 * focus to move fom the source widget
3412 priv->child_has_focus = FALSE;
3413 gtk_notebook_switch_focus_tab (notebook, tab);
3420 gtk_notebook_drag_motion (GtkWidget *widget,
3421 GdkDragContext *context,
3426 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
3427 GtkNotebookPrivate *priv = notebook->priv;
3428 GtkAllocation allocation;
3429 GdkRectangle position;
3430 GtkSettings *settings;
3431 GtkNotebookArrow arrow;
3433 GdkAtom target, tab_target;
3435 gtk_widget_get_allocation (widget, &allocation);
3437 arrow = gtk_notebook_get_arrow (notebook,
3442 priv->click_child = arrow;
3443 gtk_notebook_set_scroll_timer (notebook);
3444 gdk_drag_status (context, 0, time);
3448 stop_scrolling (notebook);
3449 target = gtk_drag_dest_find_target (widget, context, NULL);
3450 tab_target = gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB");
3452 if (target == tab_target)
3454 GQuark group, source_group;
3455 GtkNotebook *source;
3456 GtkWidget *source_child;
3458 source = GTK_NOTEBOOK (gtk_drag_get_source_widget (context));
3459 source_child = source->priv->cur_page->child;
3461 group = notebook->priv->group;
3462 source_group = source->priv->group;
3464 if (group != 0 && group == source_group &&
3465 !(widget == source_child ||
3466 gtk_widget_is_ancestor (widget, source_child)))
3468 gdk_drag_status (context, GDK_ACTION_MOVE, time);
3473 /* it's a tab, but doesn't share
3474 * ID with this notebook */
3475 gdk_drag_status (context, 0, time);
3482 if (gtk_notebook_get_event_window_position (notebook, &position) &&
3483 x >= position.x && x <= position.x + position.width &&
3484 y >= position.y && y <= position.y + position.height)
3489 if (!priv->switch_tab_timer)
3491 settings = gtk_widget_get_settings (widget);
3493 g_object_get (settings, "gtk-timeout-expand", &timeout, NULL);
3494 priv->switch_tab_timer = gdk_threads_add_timeout (timeout,
3495 gtk_notebook_switch_tab_timeout,
3501 if (priv->switch_tab_timer)
3503 g_source_remove (priv->switch_tab_timer);
3504 priv->switch_tab_timer = 0;
3508 return (target == tab_target) ? TRUE : FALSE;
3512 gtk_notebook_drag_leave (GtkWidget *widget,
3513 GdkDragContext *context,
3516 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
3517 GtkNotebookPrivate *priv = notebook->priv;
3519 if (priv->switch_tab_timer)
3521 g_source_remove (priv->switch_tab_timer);
3522 priv->switch_tab_timer = 0;
3525 stop_scrolling (GTK_NOTEBOOK (widget));
3529 gtk_notebook_drag_drop (GtkWidget *widget,
3530 GdkDragContext *context,
3535 GdkAtom target, tab_target;
3537 target = gtk_drag_dest_find_target (widget, context, NULL);
3538 tab_target = gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB");
3540 if (target == tab_target)
3542 gtk_drag_get_data (widget, context, target, time);
3550 do_detach_tab (GtkNotebook *from,
3556 GtkNotebookPrivate *to_priv = to->priv;
3557 GtkAllocation to_allocation;
3558 GtkWidget *tab_label, *menu_label;
3559 gboolean tab_expand, tab_fill, reorderable, detachable;
3564 menu_label = gtk_notebook_get_menu_label (from, child);
3567 g_object_ref (menu_label);
3569 tab_label = gtk_notebook_get_tab_label (from, child);
3572 g_object_ref (tab_label);
3574 g_object_ref (child);
3576 gtk_container_child_get (GTK_CONTAINER (from),
3578 "tab-expand", &tab_expand,
3579 "tab-fill", &tab_fill,
3580 "tab-pack", &tab_pack,
3581 "reorderable", &reorderable,
3582 "detachable", &detachable,
3585 gtk_container_remove (GTK_CONTAINER (from), child);
3587 gtk_widget_get_allocation (GTK_WIDGET (to), &to_allocation);
3588 to_priv->mouse_x = x + to_allocation.x;
3589 to_priv->mouse_y = y + to_allocation.y;
3591 element = get_drop_position (to, tab_pack);
3592 page_num = g_list_position (to_priv->children, element);
3593 gtk_notebook_insert_page_menu (to, child, tab_label, menu_label, page_num);
3595 gtk_container_child_set (GTK_CONTAINER (to), child,
3596 "tab-pack", tab_pack,
3597 "tab-expand", tab_expand,
3598 "tab-fill", tab_fill,
3599 "reorderable", reorderable,
3600 "detachable", detachable,
3603 g_object_unref (child);
3606 g_object_unref (tab_label);
3609 g_object_unref (menu_label);
3611 gtk_notebook_set_current_page (to, page_num);
3615 gtk_notebook_drag_data_get (GtkWidget *widget,
3616 GdkDragContext *context,
3617 GtkSelectionData *data,
3621 if (data->target == gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB"))
3623 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
3624 GtkNotebookPrivate *priv = notebook->priv;
3626 gtk_selection_data_set (data,
3629 (void*) &priv->detached_tab->child,
3635 gtk_notebook_drag_data_received (GtkWidget *widget,
3636 GdkDragContext *context,
3639 GtkSelectionData *data,
3643 GtkNotebook *notebook;
3644 GtkWidget *source_widget;
3647 notebook = GTK_NOTEBOOK (widget);
3648 source_widget = gtk_drag_get_source_widget (context);
3650 if (source_widget &&
3651 data->target == gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB"))
3653 child = (void*) data->data;
3655 do_detach_tab (GTK_NOTEBOOK (source_widget), notebook, *child, x, y);
3656 gtk_drag_finish (context, TRUE, FALSE, time);
3659 gtk_drag_finish (context, FALSE, FALSE, time);
3662 /* Private GtkContainer Methods :
3664 * gtk_notebook_set_child_arg
3665 * gtk_notebook_get_child_arg
3667 * gtk_notebook_remove
3668 * gtk_notebook_focus
3669 * gtk_notebook_set_focus_child
3670 * gtk_notebook_child_type
3671 * gtk_notebook_forall
3674 gtk_notebook_set_child_property (GtkContainer *container,
3677 const GValue *value,
3682 GtkPackType pack_type;
3684 /* not finding child's page is valid for menus or labels */
3685 if (!gtk_notebook_find_child (GTK_NOTEBOOK (container), child, NULL))
3688 switch (property_id)
3690 case CHILD_PROP_TAB_LABEL:
3691 /* a NULL pointer indicates a default_tab setting, otherwise
3692 * we need to set the associated label
3694 gtk_notebook_set_tab_label_text (GTK_NOTEBOOK (container), child,
3695 g_value_get_string (value));
3697 case CHILD_PROP_MENU_LABEL:
3698 gtk_notebook_set_menu_label_text (GTK_NOTEBOOK (container), child,
3699 g_value_get_string (value));
3701 case CHILD_PROP_POSITION:
3702 gtk_notebook_reorder_child (GTK_NOTEBOOK (container), child,
3703 g_value_get_int (value));
3705 case CHILD_PROP_TAB_EXPAND:
3706 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3707 &expand, &fill, &pack_type);
3708 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (container), child,
3709 g_value_get_boolean (value),
3712 case CHILD_PROP_TAB_FILL:
3713 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3714 &expand, &fill, &pack_type);
3715 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (container), child,
3717 g_value_get_boolean (value),
3720 case CHILD_PROP_TAB_PACK:
3721 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3722 &expand, &fill, &pack_type);
3723 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (container), child,
3725 g_value_get_enum (value));
3727 case CHILD_PROP_REORDERABLE:
3728 gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (container), child,
3729 g_value_get_boolean (value));
3731 case CHILD_PROP_DETACHABLE:
3732 gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (container), child,
3733 g_value_get_boolean (value));
3736 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
3742 gtk_notebook_get_child_property (GtkContainer *container,
3748 GtkNotebook *notebook = GTK_NOTEBOOK (container);
3749 GtkNotebookPrivate *priv = notebook->priv;
3754 GtkPackType pack_type;
3756 /* not finding child's page is valid for menus or labels */
3757 list = gtk_notebook_find_child (notebook, child, NULL);
3760 /* nothing to set on labels or menus */
3761 g_param_value_set_default (pspec, value);
3765 switch (property_id)
3767 case CHILD_PROP_TAB_LABEL:
3768 label = gtk_notebook_get_tab_label (notebook, child);
3770 if (GTK_IS_LABEL (label))
3771 g_value_set_string (value, gtk_label_get_label (GTK_LABEL (label)));
3773 g_value_set_string (value, NULL);
3775 case CHILD_PROP_MENU_LABEL:
3776 label = gtk_notebook_get_menu_label (notebook, child);
3778 if (GTK_IS_LABEL (label))
3779 g_value_set_string (value, gtk_label_get_label (GTK_LABEL (label)));
3781 g_value_set_string (value, NULL);
3783 case CHILD_PROP_POSITION:
3784 g_value_set_int (value, g_list_position (priv->children, list));
3786 case CHILD_PROP_TAB_EXPAND:
3787 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3788 &expand, NULL, NULL);
3789 g_value_set_boolean (value, expand);
3791 case CHILD_PROP_TAB_FILL:
3792 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3794 g_value_set_boolean (value, fill);
3796 case CHILD_PROP_TAB_PACK:
3797 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3798 NULL, NULL, &pack_type);
3799 g_value_set_enum (value, pack_type);
3801 case CHILD_PROP_REORDERABLE:
3802 g_value_set_boolean (value,
3803 gtk_notebook_get_tab_reorderable (GTK_NOTEBOOK (container), child));
3805 case CHILD_PROP_DETACHABLE:
3806 g_value_set_boolean (value,
3807 gtk_notebook_get_tab_detachable (GTK_NOTEBOOK (container), child));
3810 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
3816 gtk_notebook_add (GtkContainer *container,
3819 gtk_notebook_insert_page_menu (GTK_NOTEBOOK (container), widget,
3824 gtk_notebook_remove (GtkContainer *container,
3827 GtkNotebook *notebook = GTK_NOTEBOOK (container);
3828 GtkNotebookPrivate *priv = notebook->priv;
3829 GtkNotebookPage *page;
3833 children = priv->children;
3836 page = children->data;
3838 if (page->child == widget)
3842 children = children->next;
3845 if (children == NULL)
3848 g_object_ref (widget);
3850 gtk_notebook_real_remove (notebook, children);
3852 g_signal_emit (notebook,
3853 notebook_signals[PAGE_REMOVED],
3858 g_object_unref (widget);
3862 focus_tabs_in (GtkNotebook *notebook)
3864 GtkNotebookPrivate *priv = notebook->priv;
3866 if (priv->show_tabs && priv->cur_page)
3868 gtk_widget_grab_focus (GTK_WIDGET (notebook));
3870 gtk_notebook_switch_focus_tab (notebook,
3871 g_list_find (priv->children,
3881 focus_tabs_move (GtkNotebook *notebook,
3882 GtkDirectionType direction,
3883 gint search_direction)
3885 GtkNotebookPrivate *priv = notebook->priv;
3888 new_page = gtk_notebook_search_page (notebook, priv->focus_tab,
3889 search_direction, TRUE);
3892 gboolean wrap_around;
3894 g_object_get (gtk_widget_get_settings (GTK_WIDGET (notebook)),
3895 "gtk-keynav-wrap-around", &wrap_around,
3899 new_page = gtk_notebook_search_page (notebook, NULL,
3900 search_direction, TRUE);
3904 gtk_notebook_switch_focus_tab (notebook, new_page);
3906 gtk_widget_error_bell (GTK_WIDGET (notebook));
3912 focus_child_in (GtkNotebook *notebook,
3913 GtkDirectionType direction)
3915 GtkNotebookPrivate *priv = notebook->priv;
3918 return gtk_widget_child_focus (priv->cur_page->child, direction);
3924 focus_action_in (GtkNotebook *notebook,
3926 GtkDirectionType direction)
3928 GtkNotebookPrivate *priv = notebook->priv;
3930 if (priv->action_widget[action] &&
3931 gtk_widget_get_visible (priv->action_widget[action]))
3932 return gtk_widget_child_focus (priv->action_widget[action], direction);
3937 /* Focus in the notebook can either be on the pages, or on
3938 * the tabs or on the action_widgets.
3941 gtk_notebook_focus (GtkWidget *widget,
3942 GtkDirectionType direction)
3944 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
3945 GtkNotebookPrivate *priv = notebook->priv;
3946 GtkWidget *old_focus_child;
3947 GtkDirectionType effective_direction;
3951 gboolean widget_is_focus;
3952 GtkContainer *container;
3954 container = GTK_CONTAINER (widget);
3956 if (priv->tab_pos == GTK_POS_TOP ||
3957 priv->tab_pos == GTK_POS_LEFT)
3959 first_action = ACTION_WIDGET_START;
3960 last_action = ACTION_WIDGET_END;
3964 first_action = ACTION_WIDGET_END;
3965 last_action = ACTION_WIDGET_START;
3968 if (priv->focus_out)
3970 priv->focus_out = FALSE; /* Clear this to catch the wrap-around case */
3974 widget_is_focus = gtk_widget_is_focus (widget);
3975 old_focus_child = gtk_container_get_focus_child (container);
3977 effective_direction = get_effective_direction (notebook, direction);
3979 if (old_focus_child) /* Focus on page child or action widget */
3981 if (gtk_widget_child_focus (old_focus_child, direction))
3984 if (old_focus_child == priv->action_widget[ACTION_WIDGET_START])
3986 switch (effective_direction)
3989 return focus_child_in (notebook, GTK_DIR_TAB_FORWARD);
3991 return focus_tabs_in (notebook);
3999 case GTK_DIR_TAB_FORWARD:
4000 if ((priv->tab_pos == GTK_POS_RIGHT || priv->tab_pos == GTK_POS_BOTTOM) &&
4001 focus_child_in (notebook, direction))
4003 return focus_tabs_in (notebook);
4004 case GTK_DIR_TAB_BACKWARD:
4007 g_assert_not_reached ();
4011 else if (old_focus_child == priv->action_widget[ACTION_WIDGET_END])
4013 switch (effective_direction)
4016 return focus_child_in (notebook, GTK_DIR_TAB_FORWARD);
4020 return focus_tabs_in (notebook);
4026 case GTK_DIR_TAB_FORWARD:
4028 case GTK_DIR_TAB_BACKWARD:
4029 if ((priv->tab_pos == GTK_POS_TOP || priv->tab_pos == GTK_POS_LEFT) &&
4030 focus_child_in (notebook, direction))
4032 return focus_tabs_in (notebook);
4034 g_assert_not_reached ();
4040 switch (effective_direction)
4042 case GTK_DIR_TAB_BACKWARD:
4044 /* Focus onto the tabs */
4045 return focus_tabs_in (notebook);
4050 case GTK_DIR_TAB_FORWARD:
4051 return focus_action_in (notebook, last_action, direction);
4055 else if (widget_is_focus) /* Focus was on tabs */
4057 switch (effective_direction)
4059 case GTK_DIR_TAB_BACKWARD:
4060 return focus_action_in (notebook, first_action, direction);
4063 case GTK_DIR_TAB_FORWARD:
4064 if (focus_child_in (notebook, GTK_DIR_TAB_FORWARD))
4066 return focus_action_in (notebook, last_action, direction);
4068 /* We use TAB_FORWARD rather than direction so that we focus a more
4069 * predictable widget for the user; users may be using arrow focusing
4070 * in this situation even if they don't usually use arrow focusing.
4072 return focus_child_in (notebook, GTK_DIR_TAB_FORWARD);
4074 return focus_tabs_move (notebook, direction, STEP_PREV);
4076 return focus_tabs_move (notebook, direction, STEP_NEXT);
4079 else /* Focus was not on widget */
4081 switch (effective_direction)
4083 case GTK_DIR_TAB_FORWARD:
4085 if (focus_action_in (notebook, first_action, direction))
4087 if (focus_tabs_in (notebook))
4089 if (focus_action_in (notebook, last_action, direction))
4091 if (focus_child_in (notebook, direction))
4094 case GTK_DIR_TAB_BACKWARD:
4095 if (focus_action_in (notebook, last_action, direction))
4097 if (focus_child_in (notebook, direction))
4099 if (focus_tabs_in (notebook))
4101 if (focus_action_in (notebook, first_action, direction))
4106 return focus_child_in (notebook, direction);
4110 g_assert_not_reached ();
4115 gtk_notebook_set_focus_child (GtkContainer *container,
4118 GtkNotebook *notebook = GTK_NOTEBOOK (container);
4119 GtkNotebookPrivate *priv = notebook->priv;
4120 GtkWidget *page_child;
4121 GtkWidget *toplevel;
4123 /* If the old focus widget was within a page of the notebook,
4124 * (child may either be NULL or not in this case), record it
4125 * for future use if we switch to the page with a mnemonic.
4128 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (container));
4129 if (toplevel && gtk_widget_is_toplevel (toplevel))
4131 page_child = gtk_window_get_focus (GTK_WINDOW (toplevel));
4134 if (gtk_widget_get_parent (page_child) == GTK_WIDGET (container))
4136 GList *list = gtk_notebook_find_child (notebook, page_child, NULL);
4139 GtkNotebookPage *page = list->data;
4141 if (page->last_focus_child)
4142 g_object_remove_weak_pointer (G_OBJECT (page->last_focus_child), (gpointer *)&page->last_focus_child);
4144 page->last_focus_child = gtk_window_get_focus (GTK_WINDOW (toplevel));
4145 g_object_add_weak_pointer (G_OBJECT (page->last_focus_child), (gpointer *)&page->last_focus_child);
4151 page_child = gtk_widget_get_parent (page_child);
4157 g_return_if_fail (GTK_IS_WIDGET (child));
4159 priv->child_has_focus = TRUE;
4160 if (!priv->focus_tab)
4163 GtkNotebookPage *page;
4165 children = priv->children;
4168 page = children->data;
4169 if (page->child == child || page->tab_label == child)
4170 gtk_notebook_switch_focus_tab (notebook, children);
4171 children = children->next;
4176 priv->child_has_focus = FALSE;
4178 GTK_CONTAINER_CLASS (gtk_notebook_parent_class)->set_focus_child (container, child);
4182 gtk_notebook_forall (GtkContainer *container,
4183 gboolean include_internals,
4184 GtkCallback callback,
4185 gpointer callback_data)
4187 GtkNotebook *notebook = GTK_NOTEBOOK (container);
4188 GtkNotebookPrivate *priv = notebook->priv;
4192 children = priv->children;
4195 GtkNotebookPage *page;
4197 page = children->data;
4198 children = children->next;
4199 (* callback) (page->child, callback_data);
4201 if (include_internals)
4203 if (page->tab_label)
4204 (* callback) (page->tab_label, callback_data);
4208 if (include_internals) {
4209 for (i = 0; i < N_ACTION_WIDGETS; i++)
4211 if (priv->action_widget[i])
4212 (* callback) (priv->action_widget[i], callback_data);
4218 gtk_notebook_child_type (GtkContainer *container)
4220 return GTK_TYPE_WIDGET;
4223 /* Private GtkNotebook Methods:
4225 * gtk_notebook_real_insert_page
4228 page_visible_cb (GtkWidget *page,
4232 GtkNotebook *notebook = GTK_NOTEBOOK (data);
4233 GtkNotebookPrivate *priv = notebook->priv;
4237 if (priv->cur_page &&
4238 priv->cur_page->child == page &&
4239 !gtk_widget_get_visible (page))
4241 list = g_list_find (priv->children, priv->cur_page);
4244 next = gtk_notebook_search_page (notebook, list, STEP_NEXT, TRUE);
4246 next = gtk_notebook_search_page (notebook, list, STEP_PREV, TRUE);
4250 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (next));
4255 gtk_notebook_real_insert_page (GtkNotebook *notebook,
4257 GtkWidget *tab_label,
4258 GtkWidget *menu_label,
4261 GtkNotebookPrivate *priv = notebook->priv;
4262 GtkNotebookPage *page;
4265 gtk_widget_freeze_child_notify (child);
4267 page = g_slice_new0 (GtkNotebookPage);
4268 page->child = child;
4270 nchildren = g_list_length (priv->children);
4271 if ((position < 0) || (position > nchildren))
4272 position = nchildren;
4274 priv->children = g_list_insert (priv->children, page, position);
4278 page->default_tab = TRUE;
4279 if (priv->show_tabs)
4280 tab_label = gtk_label_new (NULL);
4282 page->tab_label = tab_label;
4283 page->menu_label = menu_label;
4284 page->expand = FALSE;
4286 page->pack = GTK_PACK_START;
4289 page->default_menu = TRUE;
4291 g_object_ref_sink (page->menu_label);
4294 gtk_notebook_menu_item_create (notebook,
4295 g_list_find (priv->children, page));
4297 gtk_widget_set_parent (child, GTK_WIDGET (notebook));
4299 gtk_widget_set_parent (tab_label, GTK_WIDGET (notebook));
4301 gtk_notebook_update_labels (notebook);
4303 if (!priv->first_tab)
4304 priv->first_tab = priv->children;
4306 /* child visible will be turned on by switch_page below */
4307 if (priv->cur_page != page)
4308 gtk_widget_set_child_visible (child, FALSE);
4312 if (priv->show_tabs && gtk_widget_get_visible (child))
4313 gtk_widget_show (tab_label);
4315 gtk_widget_hide (tab_label);
4317 page->mnemonic_activate_signal =
4318 g_signal_connect (tab_label,
4319 "mnemonic-activate",
4320 G_CALLBACK (gtk_notebook_mnemonic_activate_switch_page),
4324 page->notify_visible_handler = g_signal_connect (child, "notify::visible",
4325 G_CALLBACK (page_visible_cb), notebook);
4327 g_signal_emit (notebook,
4328 notebook_signals[PAGE_ADDED],
4333 if (!priv->cur_page)
4335 gtk_notebook_switch_page (notebook, page);
4336 /* focus_tab is set in the switch_page method */
4337 gtk_notebook_switch_focus_tab (notebook, priv->focus_tab);
4340 gtk_notebook_update_tab_states (notebook);
4342 if (priv->scrollable)
4343 gtk_notebook_redraw_arrows (notebook);
4345 gtk_widget_child_notify (child, "tab-expand");
4346 gtk_widget_child_notify (child, "tab-fill");
4347 gtk_widget_child_notify (child, "tab-pack");
4348 gtk_widget_child_notify (child, "tab-label");
4349 gtk_widget_child_notify (child, "menu-label");
4350 gtk_widget_child_notify (child, "position");
4351 gtk_widget_thaw_child_notify (child);
4353 /* The page-added handler might have reordered the pages, re-get the position */
4354 return gtk_notebook_page_num (notebook, child);
4357 /* Private GtkNotebook Functions:
4359 * gtk_notebook_redraw_tabs
4360 * gtk_notebook_real_remove
4361 * gtk_notebook_update_labels
4362 * gtk_notebook_timer
4363 * gtk_notebook_set_scroll_timer
4364 * gtk_notebook_page_compare
4365 * gtk_notebook_real_page_position
4366 * gtk_notebook_search_page
4369 gtk_notebook_redraw_tabs (GtkNotebook *notebook)
4371 GtkNotebookPrivate *priv = notebook->priv;
4372 GtkAllocation allocation;
4374 GtkNotebookPage *page;
4376 GdkRectangle redraw_rect;
4378 gint tab_pos = get_effective_tab_pos (notebook);
4380 widget = GTK_WIDGET (notebook);
4381 border = gtk_container_get_border_width (GTK_CONTAINER (notebook));
4383 if (!gtk_widget_get_mapped (widget) || !priv->first_tab)
4386 page = priv->first_tab->data;
4388 redraw_rect.x = border;
4389 redraw_rect.y = border;
4391 style = gtk_widget_get_style (widget);
4392 gtk_widget_get_allocation (widget, &allocation);
4396 case GTK_POS_BOTTOM:
4397 redraw_rect.y = allocation.height - border -
4398 page->allocation.height - style->ythickness;
4400 if (page != priv->cur_page)
4401 redraw_rect.y -= style->ythickness;
4404 redraw_rect.width = allocation.width - 2 * border;
4405 redraw_rect.height = page->allocation.height + style->ythickness;
4407 if (page != priv->cur_page)
4408 redraw_rect.height += style->ythickness;
4411 redraw_rect.x = allocation.width - border -
4412 page->allocation.width - style->xthickness;
4414 if (page != priv->cur_page)
4415 redraw_rect.x -= style->xthickness;
4418 redraw_rect.width = page->allocation.width + style->xthickness;
4419 redraw_rect.height = allocation.height - 2 * border;
4421 if (page != priv->cur_page)
4422 redraw_rect.width += style->xthickness;
4426 redraw_rect.x += allocation.x;
4427 redraw_rect.y += allocation.y;
4429 gdk_window_invalidate_rect (gtk_widget_get_window (widget),
4430 &redraw_rect, TRUE);
4434 gtk_notebook_redraw_arrows (GtkNotebook *notebook)
4436 GtkNotebookPrivate *priv = notebook->priv;
4438 if (gtk_widget_get_mapped (GTK_WIDGET (notebook)) &&
4439 gtk_notebook_show_arrows (notebook))
4443 GtkNotebookArrow arrow[4];
4445 arrow[0] = priv->has_before_previous ? ARROW_LEFT_BEFORE : ARROW_NONE;
4446 arrow[1] = priv->has_before_next ? ARROW_RIGHT_BEFORE : ARROW_NONE;
4447 arrow[2] = priv->has_after_previous ? ARROW_LEFT_AFTER : ARROW_NONE;
4448 arrow[3] = priv->has_after_next ? ARROW_RIGHT_AFTER : ARROW_NONE;
4450 for (i = 0; i < 4; i++)
4452 if (arrow[i] == ARROW_NONE)
4455 gtk_notebook_get_arrow_rect (notebook, &rect, arrow[i]);
4456 gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET (notebook)),
4463 gtk_notebook_timer (GtkNotebook *notebook)
4465 GtkNotebookPrivate *priv = notebook->priv;
4466 gboolean retval = FALSE;
4470 gtk_notebook_do_arrow (notebook, priv->click_child);
4472 if (priv->need_timer)
4474 GtkSettings *settings;
4477 settings = gtk_widget_get_settings (GTK_WIDGET (notebook));
4478 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
4480 priv->need_timer = FALSE;
4481 priv->timer = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
4482 (GSourceFunc) gtk_notebook_timer,
4483 (gpointer) notebook);
4493 gtk_notebook_set_scroll_timer (GtkNotebook *notebook)
4495 GtkNotebookPrivate *priv = notebook->priv;
4496 GtkWidget *widget = GTK_WIDGET (notebook);
4500 GtkSettings *settings = gtk_widget_get_settings (widget);
4503 g_object_get (settings, "gtk-timeout-initial", &timeout, NULL);
4505 priv->timer = gdk_threads_add_timeout (timeout,
4506 (GSourceFunc) gtk_notebook_timer,
4507 (gpointer) notebook);
4508 priv->need_timer = TRUE;
4513 gtk_notebook_page_compare (gconstpointer a,
4516 return (((GtkNotebookPage *) a)->child != b);
4520 gtk_notebook_find_child (GtkNotebook *notebook,
4522 const gchar *function)
4524 GtkNotebookPrivate *priv = notebook->priv;
4525 GList *list = g_list_find_custom (priv->children, child,
4526 gtk_notebook_page_compare);
4528 #ifndef G_DISABLE_CHECKS
4529 if (!list && function)
4530 g_warning ("%s: unable to find child %p in notebook %p",
4531 function, child, notebook);
4538 gtk_notebook_remove_tab_label (GtkNotebook *notebook,
4539 GtkNotebookPage *page)
4541 if (page->tab_label)
4543 if (page->mnemonic_activate_signal)
4544 g_signal_handler_disconnect (page->tab_label,
4545 page->mnemonic_activate_signal);
4546 page->mnemonic_activate_signal = 0;
4548 gtk_widget_set_state (page->tab_label, GTK_STATE_NORMAL);
4549 gtk_widget_unparent (page->tab_label);
4550 page->tab_label = NULL;
4555 gtk_notebook_real_remove (GtkNotebook *notebook,
4558 GtkNotebookPrivate *priv = notebook->priv;
4559 GtkNotebookPage *page;
4561 gint need_resize = FALSE;
4562 GtkWidget *tab_label;
4564 gboolean destroying;
4566 destroying = GTK_OBJECT_FLAGS (notebook) & GTK_IN_DESTRUCTION;
4568 next_list = gtk_notebook_search_page (notebook, list, STEP_NEXT, TRUE);
4570 next_list = gtk_notebook_search_page (notebook, list, STEP_PREV, TRUE);
4572 priv->children = g_list_remove_link (priv->children, list);
4574 if (priv->cur_page == list->data)
4576 priv->cur_page = NULL;
4577 if (next_list && !destroying)
4578 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (next_list));
4581 if (priv->detached_tab == list->data)
4582 priv->detached_tab = NULL;
4584 if (list == priv->first_tab)
4585 priv->first_tab = next_list;
4586 if (list == priv->focus_tab && !destroying)
4587 gtk_notebook_switch_focus_tab (notebook, next_list);
4591 g_signal_handler_disconnect (page->child, page->notify_visible_handler);
4593 if (gtk_widget_get_visible (page->child) &&
4594 gtk_widget_get_visible (GTK_WIDGET (notebook)))
4597 gtk_widget_unparent (page->child);
4599 tab_label = page->tab_label;
4602 g_object_ref (tab_label);
4603 gtk_notebook_remove_tab_label (notebook, page);
4605 gtk_widget_destroy (tab_label);
4606 g_object_unref (tab_label);
4611 GtkWidget *parent = gtk_widget_get_parent (page->menu_label);
4613 gtk_notebook_menu_label_unparent (parent, NULL);
4614 gtk_container_remove (GTK_CONTAINER (priv->menu), parent);
4616 gtk_widget_queue_resize (priv->menu);
4618 if (!page->default_menu)
4619 g_object_unref (page->menu_label);
4623 if (page->last_focus_child)
4625 g_object_remove_weak_pointer (G_OBJECT (page->last_focus_child), (gpointer *)&page->last_focus_child);
4626 page->last_focus_child = NULL;
4629 g_slice_free (GtkNotebookPage, page);
4631 gtk_notebook_update_labels (notebook);
4633 gtk_widget_queue_resize (GTK_WIDGET (notebook));
4637 gtk_notebook_update_labels (GtkNotebook *notebook)
4639 GtkNotebookPrivate *priv = notebook->priv;
4640 GtkNotebookPage *page;
4645 if (!priv->show_tabs && !priv->menu)
4648 for (list = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, FALSE);
4650 list = gtk_notebook_search_page (notebook, list, STEP_NEXT, FALSE))
4653 g_snprintf (string, sizeof(string), _("Page %u"), page_num++);
4654 if (priv->show_tabs)
4656 if (page->default_tab)
4658 if (!page->tab_label)
4660 page->tab_label = gtk_label_new (string);
4661 gtk_widget_set_parent (page->tab_label,
4662 GTK_WIDGET (notebook));
4665 gtk_label_set_text (GTK_LABEL (page->tab_label), string);
4668 if (gtk_widget_get_visible (page->child) &&
4669 !gtk_widget_get_visible (page->tab_label))
4670 gtk_widget_show (page->tab_label);
4671 else if (!gtk_widget_get_visible (page->child) &&
4672 gtk_widget_get_visible (page->tab_label))
4673 gtk_widget_hide (page->tab_label);
4675 if (priv->menu && page->default_menu)
4677 if (GTK_IS_LABEL (page->tab_label))
4678 gtk_label_set_text (GTK_LABEL (page->menu_label),
4679 gtk_label_get_label (GTK_LABEL (page->tab_label)));
4681 gtk_label_set_text (GTK_LABEL (page->menu_label), string);
4687 gtk_notebook_real_page_position (GtkNotebook *notebook,
4690 GtkNotebookPrivate *priv = notebook->priv;
4694 for (work = priv->children, count_start = 0;
4695 work && work != list; work = work->next)
4696 if (GTK_NOTEBOOK_PAGE (work)->pack == GTK_PACK_START)
4702 if (GTK_NOTEBOOK_PAGE (list)->pack == GTK_PACK_START)
4705 return (count_start + g_list_length (list) - 1);
4709 gtk_notebook_search_page (GtkNotebook *notebook,
4712 gboolean find_visible)
4714 GtkNotebookPrivate *priv = notebook->priv;
4715 GtkNotebookPage *page = NULL;
4716 GList *old_list = NULL;
4722 flag = GTK_PACK_END;
4726 flag = GTK_PACK_START;
4733 if (!page || page->pack == flag)
4741 list = priv->children;
4746 if (page->pack == flag &&
4748 (gtk_widget_get_visible (page->child) &&
4749 (!page->tab_label || NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page)))))
4764 if (page->pack != flag &&
4766 (gtk_widget_get_visible (page->child) &&
4767 (!page->tab_label || NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page)))))
4775 /* Private GtkNotebook Drawing Functions:
4777 * gtk_notebook_paint
4778 * gtk_notebook_draw_tab
4779 * gtk_notebook_draw_arrow
4782 gtk_notebook_paint (GtkWidget *widget,
4785 GtkNotebook *notebook;
4786 GtkNotebookPrivate *priv;
4787 GtkNotebookPage *page;
4788 GtkAllocation allocation;
4793 guint border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
4794 gint gap_x = 0, gap_width = 0, step = STEP_PREV;
4798 if (!gtk_widget_is_drawable (widget))
4801 notebook = GTK_NOTEBOOK (widget);
4802 priv = notebook->priv;
4803 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
4804 tab_pos = get_effective_tab_pos (notebook);
4806 if ((!priv->show_tabs && !priv->show_border) ||
4807 !priv->cur_page || !gtk_widget_get_visible (priv->cur_page->child))
4810 gtk_widget_get_allocation (widget, &allocation);
4812 x = allocation.x + border_width;
4813 y = allocation.y + border_width;
4814 width = allocation.width - border_width * 2;
4815 height = allocation.height - border_width * 2;
4817 if (priv->show_border && (!priv->show_tabs || !priv->children))
4819 gtk_paint_box (gtk_widget_get_style (widget),
4820 gtk_widget_get_window (widget),
4821 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
4822 area, widget, "notebook",
4823 x, y, width, height);
4827 if (!priv->first_tab)
4828 priv->first_tab = priv->children;
4830 if (!gtk_widget_get_mapped (priv->cur_page->tab_label))
4831 page = GTK_NOTEBOOK_PAGE (priv->first_tab);
4833 page = priv->cur_page;
4838 y += page->allocation.height;
4840 case GTK_POS_BOTTOM:
4841 height -= page->allocation.height;
4844 x += page->allocation.width;
4847 width -= page->allocation.width;
4851 if (!NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, priv->cur_page) ||
4852 !gtk_widget_get_mapped (priv->cur_page->tab_label))
4862 case GTK_POS_BOTTOM:
4863 if (priv->operation == DRAG_OPERATION_REORDER)
4864 gap_x = priv->drag_window_x - allocation.x - border_width;
4866 gap_x = priv->cur_page->allocation.x - allocation.x - border_width;
4868 gap_width = priv->cur_page->allocation.width;
4869 step = is_rtl ? STEP_NEXT : STEP_PREV;
4873 if (priv->operation == DRAG_OPERATION_REORDER)
4874 gap_x = priv->drag_window_y - border_width - allocation.y;
4876 gap_x = priv->cur_page->allocation.y - allocation.y - border_width;
4878 gap_width = priv->cur_page->allocation.height;
4883 gtk_paint_box_gap (gtk_widget_get_style (widget),
4884 gtk_widget_get_window (widget),
4885 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
4886 area, widget, "notebook",
4887 x, y, width, height,
4888 tab_pos, gap_x, gap_width);
4891 children = gtk_notebook_search_page (notebook, NULL, step, TRUE);
4894 page = children->data;
4895 children = gtk_notebook_search_page (notebook, children,
4897 if (!gtk_widget_get_visible (page->child))
4899 if (!gtk_widget_get_mapped (page->tab_label))
4901 else if (page != priv->cur_page)
4902 gtk_notebook_draw_tab (notebook, page, area);
4905 if (showarrow && priv->scrollable)
4907 if (priv->has_before_previous)
4908 gtk_notebook_draw_arrow (notebook, ARROW_LEFT_BEFORE);
4909 if (priv->has_before_next)
4910 gtk_notebook_draw_arrow (notebook, ARROW_RIGHT_BEFORE);
4911 if (priv->has_after_previous)
4912 gtk_notebook_draw_arrow (notebook, ARROW_LEFT_AFTER);
4913 if (priv->has_after_next)
4914 gtk_notebook_draw_arrow (notebook, ARROW_RIGHT_AFTER);
4916 gtk_notebook_draw_tab (notebook, priv->cur_page, area);
4920 gtk_notebook_draw_tab (GtkNotebook *notebook,
4921 GtkNotebookPage *page,
4924 GtkNotebookPrivate *priv;
4925 GdkRectangle child_area;
4926 GdkRectangle page_area;
4927 GtkStateType state_type;
4928 GtkPositionType gap_side;
4932 if (!NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) ||
4933 !gtk_widget_get_mapped (page->tab_label) ||
4934 (page->allocation.width == 0) || (page->allocation.height == 0))
4937 widget = GTK_WIDGET (notebook);
4938 priv = notebook->priv;
4940 if (priv->operation == DRAG_OPERATION_REORDER && page == priv->cur_page)
4941 window = priv->drag_window;
4943 window = gtk_widget_get_window (widget);
4945 page_area.x = page->allocation.x;
4946 page_area.y = page->allocation.y;
4947 page_area.width = page->allocation.width;
4948 page_area.height = page->allocation.height;
4950 if (gdk_rectangle_intersect (&page_area, area, &child_area))
4952 gap_side = get_tab_gap_pos (notebook);
4954 if (priv->cur_page == page)
4955 state_type = GTK_STATE_NORMAL;
4957 state_type = GTK_STATE_ACTIVE;
4959 gtk_paint_extension (gtk_widget_get_style (widget), window,
4960 state_type, GTK_SHADOW_OUT,
4961 area, widget, "tab",
4962 page_area.x, page_area.y,
4963 page_area.width, page_area.height,
4969 gtk_notebook_draw_arrow (GtkNotebook *notebook,
4970 GtkNotebookArrow nbarrow)
4972 GtkNotebookPrivate *priv = notebook->priv;
4973 GtkStateType state_type;
4974 GtkShadowType shadow_type;
4976 GdkRectangle arrow_rect;
4978 gboolean is_rtl, left;
4980 widget = GTK_WIDGET (notebook);
4982 if (gtk_widget_is_drawable (widget))
4984 gint scroll_arrow_hlength;
4985 gint scroll_arrow_vlength;
4988 gtk_notebook_get_arrow_rect (notebook, &arrow_rect, nbarrow);
4990 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
4991 left = (ARROW_IS_LEFT (nbarrow) && !is_rtl) ||
4992 (!ARROW_IS_LEFT (nbarrow) && is_rtl);
4994 gtk_widget_style_get (widget,
4995 "scroll-arrow-hlength", &scroll_arrow_hlength,
4996 "scroll-arrow-vlength", &scroll_arrow_vlength,
4999 if (priv->in_child == nbarrow)
5001 if (priv->click_child == nbarrow)
5002 state_type = GTK_STATE_ACTIVE;
5004 state_type = GTK_STATE_PRELIGHT;
5007 state_type = gtk_widget_get_state (widget);
5009 if (priv->click_child == nbarrow)
5010 shadow_type = GTK_SHADOW_IN;
5012 shadow_type = GTK_SHADOW_OUT;
5014 if (priv->focus_tab &&
5015 !gtk_notebook_search_page (notebook, priv->focus_tab,
5016 left ? STEP_PREV : STEP_NEXT, TRUE))
5018 shadow_type = GTK_SHADOW_ETCHED_IN;
5019 state_type = GTK_STATE_INSENSITIVE;
5022 if (priv->tab_pos == GTK_POS_LEFT ||
5023 priv->tab_pos == GTK_POS_RIGHT)
5025 arrow = (ARROW_IS_LEFT (nbarrow) ? GTK_ARROW_UP : GTK_ARROW_DOWN);
5026 arrow_size = scroll_arrow_vlength;
5030 arrow = (ARROW_IS_LEFT (nbarrow) ? GTK_ARROW_LEFT : GTK_ARROW_RIGHT);
5031 arrow_size = scroll_arrow_hlength;
5034 gtk_paint_arrow (gtk_widget_get_style (widget),
5035 gtk_widget_get_window (widget), state_type,
5036 shadow_type, NULL, widget, "notebook",
5037 arrow, TRUE, arrow_rect.x, arrow_rect.y,
5038 arrow_size, arrow_size);
5042 /* Private GtkNotebook Size Allocate Functions:
5044 * gtk_notebook_tab_space
5045 * gtk_notebook_calculate_shown_tabs
5046 * gtk_notebook_calculate_tabs_allocation
5047 * gtk_notebook_pages_allocate
5048 * gtk_notebook_page_allocate
5049 * gtk_notebook_calc_tabs
5052 gtk_notebook_tab_space (GtkNotebook *notebook,
5053 gboolean *show_arrows,
5058 GtkNotebookPrivate *priv = notebook->priv;
5059 GtkAllocation allocation, action_allocation;
5063 gint tab_pos = get_effective_tab_pos (notebook);
5066 gint scroll_arrow_hlength;
5067 gint scroll_arrow_vlength;
5072 widget = GTK_WIDGET (notebook);
5073 children = priv->children;
5074 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
5076 style = gtk_widget_get_style (widget);
5078 gtk_widget_style_get (GTK_WIDGET (notebook),
5079 "arrow-spacing", &arrow_spacing,
5080 "scroll-arrow-hlength", &scroll_arrow_hlength,
5081 "scroll-arrow-vlength", &scroll_arrow_vlength,
5084 border_width = gtk_container_get_border_width (GTK_CONTAINER (notebook));
5086 gtk_widget_get_allocation (widget, &allocation);
5091 case GTK_POS_BOTTOM:
5092 *min = allocation.x + border_width;
5093 *max = allocation.x + allocation.width - border_width;
5095 for (i = 0; i < N_ACTION_WIDGETS; i++)
5097 if (priv->action_widget[i])
5099 gtk_widget_get_allocation (priv->action_widget[i], &action_allocation);
5101 if ((i == ACTION_WIDGET_START && !is_rtl) ||
5102 (i == ACTION_WIDGET_END && is_rtl))
5103 *min += action_allocation.width + style->xthickness;
5105 *max -= action_allocation.width + style->xthickness;
5111 GtkNotebookPage *page;
5113 page = children->data;
5114 children = children->next;
5116 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) &&
5117 gtk_widget_get_visible (page->child))
5118 *tab_space += page->requisition.width;
5123 *min = allocation.y + border_width;
5124 *max = allocation.y + allocation.height - border_width;
5126 for (i = 0; i < N_ACTION_WIDGETS; i++)
5128 if (priv->action_widget[i])
5130 gtk_widget_get_allocation (priv->action_widget[i], &action_allocation);
5132 if (i == ACTION_WIDGET_START)
5133 *min += action_allocation.height + style->ythickness;
5135 *max -= action_allocation.height + style->ythickness;
5141 GtkNotebookPage *page;
5143 page = children->data;
5144 children = children->next;
5146 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) &&
5147 gtk_widget_get_visible (page->child))
5148 *tab_space += page->requisition.height;
5153 if (!priv->scrollable)
5154 *show_arrows = FALSE;
5157 gtk_widget_style_get (widget, "tab-overlap", &tab_overlap, NULL);
5162 case GTK_POS_BOTTOM:
5163 if (*tab_space > *max - *min - tab_overlap)
5165 *show_arrows = TRUE;
5167 /* take arrows into account */
5168 *tab_space = *max - *min - tab_overlap;
5170 if (priv->has_after_previous)
5172 *tab_space -= arrow_spacing + scroll_arrow_hlength;
5173 *max -= arrow_spacing + scroll_arrow_hlength;
5176 if (priv->has_after_next)
5178 *tab_space -= arrow_spacing + scroll_arrow_hlength;
5179 *max -= arrow_spacing + scroll_arrow_hlength;
5182 if (priv->has_before_previous)
5184 *tab_space -= arrow_spacing + scroll_arrow_hlength;
5185 *min += arrow_spacing + scroll_arrow_hlength;
5188 if (priv->has_before_next)
5190 *tab_space -= arrow_spacing + scroll_arrow_hlength;
5191 *min += arrow_spacing + scroll_arrow_hlength;
5197 if (*tab_space > *max - *min - tab_overlap)
5199 *show_arrows = TRUE;
5201 /* take arrows into account */
5202 *tab_space = *max - *min - tab_overlap;
5204 if (priv->has_after_previous || priv->has_after_next)
5206 *tab_space -= arrow_spacing + scroll_arrow_vlength;
5207 *max -= arrow_spacing + scroll_arrow_vlength;
5210 if (priv->has_before_previous || priv->has_before_next)
5212 *tab_space -= arrow_spacing + scroll_arrow_vlength;
5213 *min += arrow_spacing + scroll_arrow_vlength;
5222 gtk_notebook_calculate_shown_tabs (GtkNotebook *notebook,
5223 gboolean show_arrows,
5229 gint *remaining_space)
5231 GtkNotebookPrivate *priv = notebook->priv;
5233 GtkContainer *container;
5235 GtkNotebookPage *page;
5236 gint tab_pos, tab_overlap;
5238 widget = GTK_WIDGET (notebook);
5239 container = GTK_CONTAINER (notebook);
5240 gtk_widget_style_get (widget, "tab-overlap", &tab_overlap, NULL);
5241 tab_pos = get_effective_tab_pos (notebook);
5243 if (show_arrows) /* first_tab <- focus_tab */
5245 *remaining_space = tab_space;
5247 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, priv->cur_page) &&
5248 gtk_widget_get_visible (priv->cur_page->child))
5250 gtk_notebook_calc_tabs (notebook,
5253 remaining_space, STEP_NEXT);
5256 if (tab_space <= 0 || *remaining_space <= 0)
5259 priv->first_tab = priv->focus_tab;
5260 *last_child = gtk_notebook_search_page (notebook, priv->focus_tab,
5262 page = priv->first_tab->data;
5263 *remaining_space = tab_space - page->requisition.width;
5270 if (priv->first_tab && priv->first_tab != priv->focus_tab)
5272 /* Is first_tab really predecessor of focus_tab? */
5273 page = priv->first_tab->data;
5274 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) &&
5275 gtk_widget_get_visible (page->child))
5276 for (children = priv->focus_tab;
5277 children && children != priv->first_tab;
5278 children = gtk_notebook_search_page (notebook,
5286 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, priv->cur_page))
5287 priv->first_tab = priv->focus_tab;
5289 priv->first_tab = gtk_notebook_search_page (notebook, priv->focus_tab,
5293 /* calculate shown tabs counting backwards from the focus tab */
5294 gtk_notebook_calc_tabs (notebook,
5295 gtk_notebook_search_page (notebook,
5299 &(priv->first_tab), remaining_space,
5302 if (*remaining_space < 0)
5305 gtk_notebook_search_page (notebook, priv->first_tab,
5307 if (!priv->first_tab)
5308 priv->first_tab = priv->focus_tab;
5310 *last_child = gtk_notebook_search_page (notebook, priv->focus_tab,
5313 else /* focus_tab -> end */
5315 if (!priv->first_tab)
5316 priv->first_tab = gtk_notebook_search_page (notebook,
5321 gtk_notebook_calc_tabs (notebook,
5322 gtk_notebook_search_page (notebook,
5326 &children, remaining_space, STEP_NEXT);
5328 if (*remaining_space <= 0)
5329 *last_child = children;
5330 else /* start <- first_tab */
5335 gtk_notebook_calc_tabs (notebook,
5336 gtk_notebook_search_page (notebook,
5340 &children, remaining_space, STEP_PREV);
5342 if (*remaining_space == 0)
5343 priv->first_tab = children;
5345 priv->first_tab = gtk_notebook_search_page(notebook,
5352 if (*remaining_space < 0)
5354 /* calculate number of tabs */
5355 *remaining_space = - (*remaining_space);
5358 for (children = priv->first_tab;
5359 children && children != *last_child;
5360 children = gtk_notebook_search_page (notebook, children,
5365 *remaining_space = 0;
5368 /* unmap all non-visible tabs */
5369 for (children = gtk_notebook_search_page (notebook, NULL,
5371 children && children != priv->first_tab;
5372 children = gtk_notebook_search_page (notebook, children,
5375 page = children->data;
5377 if (page->tab_label &&
5378 NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page))
5379 gtk_widget_set_child_visible (page->tab_label, FALSE);
5382 for (children = *last_child; children;
5383 children = gtk_notebook_search_page (notebook, children,
5386 page = children->data;
5388 if (page->tab_label &&
5389 NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page))
5390 gtk_widget_set_child_visible (page->tab_label, FALSE);
5393 else /* !show_arrows */
5398 *remaining_space = max - min - tab_overlap - tab_space;
5399 children = priv->children;
5400 priv->first_tab = gtk_notebook_search_page (notebook, NULL,
5404 page = children->data;
5405 children = children->next;
5407 if (!NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) ||
5408 !gtk_widget_get_visible (page->child))
5417 /* if notebook is homogeneous, all tabs are expanded */
5418 if (priv->homogeneous && *n)
5424 get_allocate_at_bottom (GtkWidget *widget,
5425 gint search_direction)
5427 gboolean is_rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
5428 gboolean tab_pos = get_effective_tab_pos (GTK_NOTEBOOK (widget));
5433 case GTK_POS_BOTTOM:
5435 return (search_direction == STEP_PREV);
5437 return (search_direction == STEP_NEXT);
5442 return (search_direction == STEP_PREV);
5450 gtk_notebook_calculate_tabs_allocation (GtkNotebook *notebook,
5455 gint *remaining_space,
5456 gint *expanded_tabs,
5460 GtkNotebookPrivate *priv = notebook->priv;
5461 GtkAllocation allocation;
5463 GtkContainer *container;
5464 GtkNotebookPage *page;
5466 gboolean allocate_at_bottom;
5467 gint tab_overlap, tab_pos, tab_extra_space;
5468 gint left_x, right_x, top_y, bottom_y, anchor;
5469 gint xthickness, ythickness;
5471 gboolean gap_left, packing_changed;
5472 GtkAllocation child_allocation = { 0, };
5474 widget = GTK_WIDGET (notebook);
5475 container = GTK_CONTAINER (notebook);
5476 gtk_widget_style_get (widget, "tab-overlap", &tab_overlap, NULL);
5477 tab_pos = get_effective_tab_pos (notebook);
5478 allocate_at_bottom = get_allocate_at_bottom (widget, direction);
5481 gtk_widget_get_allocation (widget, &allocation);
5483 border_width = gtk_container_get_border_width (container);
5484 child_allocation.x = allocation.x + border_width;
5485 child_allocation.y = allocation.y + border_width;
5487 style = gtk_widget_get_style (widget);
5488 xthickness = style->xthickness;
5489 ythickness = style->ythickness;
5493 case GTK_POS_BOTTOM:
5494 child_allocation.y = allocation.y + allocation.height -
5495 priv->cur_page->requisition.height - border_width;
5498 child_allocation.x = (allocate_at_bottom) ? max : min;
5499 child_allocation.height = priv->cur_page->requisition.height;
5500 anchor = child_allocation.x;
5504 child_allocation.x = allocation.x + allocation.width -
5505 priv->cur_page->requisition.width - border_width;
5508 child_allocation.y = (allocate_at_bottom) ? max : min;
5509 child_allocation.width = priv->cur_page->requisition.width;
5510 anchor = child_allocation.y;
5514 left_x = CLAMP (priv->mouse_x - priv->drag_offset_x,
5515 min, max - priv->cur_page->allocation.width);
5516 top_y = CLAMP (priv->mouse_y - priv->drag_offset_y,
5517 min, max - priv->cur_page->allocation.height);
5518 right_x = left_x + priv->cur_page->allocation.width;
5519 bottom_y = top_y + priv->cur_page->allocation.height;
5520 gap_left = packing_changed = FALSE;
5522 while (*children && *children != last_child)
5524 page = (*children)->data;
5526 if (direction == STEP_NEXT && page->pack != GTK_PACK_START)
5530 else if (priv->operation == DRAG_OPERATION_REORDER)
5531 packing_changed = TRUE;
5534 if (direction == STEP_NEXT)
5535 *children = gtk_notebook_search_page (notebook, *children, direction, TRUE);
5538 *children = (*children)->next;
5540 if (page->pack != GTK_PACK_END || !gtk_widget_get_visible (page->child))
5544 if (!NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page))
5547 tab_extra_space = 0;
5548 if (*expanded_tabs && (showarrow || page->expand || priv->homogeneous))
5550 tab_extra_space = *remaining_space / *expanded_tabs;
5551 *remaining_space -= tab_extra_space;
5558 case GTK_POS_BOTTOM:
5559 child_allocation.width = page->requisition.width + tab_overlap + tab_extra_space;
5561 /* make sure that the reordered tab doesn't go past the last position */
5562 if (priv->operation == DRAG_OPERATION_REORDER &&
5563 !gap_left && packing_changed)
5565 if (!allocate_at_bottom)
5567 if ((priv->cur_page->pack == GTK_PACK_START && left_x >= anchor) ||
5568 (priv->cur_page->pack == GTK_PACK_END && left_x < anchor))
5570 left_x = priv->drag_window_x = anchor;
5571 anchor += priv->cur_page->allocation.width - tab_overlap;
5576 if ((priv->cur_page->pack == GTK_PACK_START && right_x <= anchor) ||
5577 (priv->cur_page->pack == GTK_PACK_END && right_x > anchor))
5579 anchor -= priv->cur_page->allocation.width;
5580 left_x = priv->drag_window_x = anchor;
5581 anchor += tab_overlap;
5588 if (priv->operation == DRAG_OPERATION_REORDER && page == priv->cur_page)
5590 priv->drag_window_x = left_x;
5591 priv->drag_window_y = child_allocation.y;
5595 if (allocate_at_bottom)
5596 anchor -= child_allocation.width;
5598 if (priv->operation == DRAG_OPERATION_REORDER && page->pack == priv->cur_page->pack)
5600 if (!allocate_at_bottom &&
5602 left_x <= anchor + child_allocation.width / 2)
5603 anchor += priv->cur_page->allocation.width - tab_overlap;
5604 else if (allocate_at_bottom &&
5605 right_x >= anchor + child_allocation.width / 2 &&
5606 right_x <= anchor + child_allocation.width)
5607 anchor -= priv->cur_page->allocation.width - tab_overlap;
5610 child_allocation.x = anchor;
5616 child_allocation.height = page->requisition.height + tab_overlap + tab_extra_space;
5618 /* make sure that the reordered tab doesn't go past the last position */
5619 if (priv->operation == DRAG_OPERATION_REORDER &&
5620 !gap_left && packing_changed)
5622 if (!allocate_at_bottom &&
5623 ((priv->cur_page->pack == GTK_PACK_START && top_y >= anchor) ||
5624 (priv->cur_page->pack == GTK_PACK_END && top_y < anchor)))
5626 top_y = priv->drag_window_y = anchor;
5627 anchor += priv->cur_page->allocation.height - tab_overlap;
5633 if (priv->operation == DRAG_OPERATION_REORDER && page == priv->cur_page)
5635 priv->drag_window_x = child_allocation.x;
5636 priv->drag_window_y = top_y;
5640 if (allocate_at_bottom)
5641 anchor -= child_allocation.height;
5643 if (priv->operation == DRAG_OPERATION_REORDER && page->pack == priv->cur_page->pack)
5645 if (!allocate_at_bottom &&
5647 top_y <= anchor + child_allocation.height / 2)
5648 anchor += priv->cur_page->allocation.height - tab_overlap;
5649 else if (allocate_at_bottom &&
5650 bottom_y >= anchor + child_allocation.height / 2 &&
5651 bottom_y <= anchor + child_allocation.height)
5652 anchor -= priv->cur_page->allocation.height - tab_overlap;
5655 child_allocation.y = anchor;
5661 page->allocation = child_allocation;
5663 if ((page == priv->detached_tab && priv->operation == DRAG_OPERATION_DETACH) ||
5664 (page == priv->cur_page && priv->operation == DRAG_OPERATION_REORDER))
5666 /* needs to be allocated at 0,0
5667 * to be shown in the drag window */
5668 page->allocation.x = 0;
5669 page->allocation.y = 0;
5672 if (page != priv->cur_page)
5677 page->allocation.y += ythickness;
5679 case GTK_POS_BOTTOM:
5680 page->allocation.height = MAX (1, page->allocation.height - ythickness);
5683 page->allocation.x += xthickness;
5686 page->allocation.width = MAX (1, page->allocation.width - xthickness);
5691 /* calculate whether to leave a gap based on reorder operation or not */
5695 case GTK_POS_BOTTOM:
5696 if (priv->operation != DRAG_OPERATION_REORDER ||
5697 (priv->operation == DRAG_OPERATION_REORDER && page != priv->cur_page))
5699 if (priv->operation == DRAG_OPERATION_REORDER)
5701 if (page->pack == priv->cur_page->pack &&
5702 !allocate_at_bottom &&
5703 left_x > anchor + child_allocation.width / 2 &&
5704 left_x <= anchor + child_allocation.width)
5705 anchor += priv->cur_page->allocation.width - tab_overlap;
5706 else if (page->pack == priv->cur_page->pack &&
5707 allocate_at_bottom &&
5708 right_x >= anchor &&
5709 right_x <= anchor + child_allocation.width / 2)
5710 anchor -= priv->cur_page->allocation.width - tab_overlap;
5713 if (!allocate_at_bottom)
5714 anchor += child_allocation.width - tab_overlap;
5716 anchor += tab_overlap;
5722 if (priv->operation != DRAG_OPERATION_REORDER ||
5723 (priv->operation == DRAG_OPERATION_REORDER && page != priv->cur_page))
5725 if (priv->operation == DRAG_OPERATION_REORDER)
5727 if (page->pack == priv->cur_page->pack &&
5728 !allocate_at_bottom &&
5729 top_y >= anchor + child_allocation.height / 2 &&
5730 top_y <= anchor + child_allocation.height)
5731 anchor += priv->cur_page->allocation.height - tab_overlap;
5732 else if (page->pack == priv->cur_page->pack &&
5733 allocate_at_bottom &&
5734 bottom_y >= anchor &&
5735 bottom_y <= anchor + child_allocation.height / 2)
5736 anchor -= priv->cur_page->allocation.height - tab_overlap;
5739 if (!allocate_at_bottom)
5740 anchor += child_allocation.height - tab_overlap;
5742 anchor += tab_overlap;
5748 /* set child visible */
5749 if (page->tab_label)
5750 gtk_widget_set_child_visible (page->tab_label, TRUE);
5753 /* Don't move the current tab past the last position during tabs reordering */
5755 priv->operation == DRAG_OPERATION_REORDER &&
5756 ((direction == STEP_NEXT && priv->cur_page->pack == GTK_PACK_START) ||
5757 ((direction == STEP_PREV || packing_changed) && priv->cur_page->pack == GTK_PACK_END)))
5762 case GTK_POS_BOTTOM:
5763 if (allocate_at_bottom)
5764 anchor -= priv->cur_page->allocation.width;
5766 if ((!allocate_at_bottom && priv->drag_window_x > anchor) ||
5767 (allocate_at_bottom && priv->drag_window_x < anchor))
5768 priv->drag_window_x = anchor;
5772 if (allocate_at_bottom)
5773 anchor -= priv->cur_page->allocation.height;
5775 if ((!allocate_at_bottom && priv->drag_window_y > anchor) ||
5776 (allocate_at_bottom && priv->drag_window_y < anchor))
5777 priv->drag_window_y = anchor;
5784 gtk_notebook_pages_allocate (GtkNotebook *notebook)
5786 GtkNotebookPrivate *priv = notebook->priv;
5787 GList *children = NULL;
5788 GList *last_child = NULL;
5789 gboolean showarrow = FALSE;
5790 gint tab_space, min, max, remaining_space;
5792 gboolean tab_allocations_changed = FALSE;
5794 if (!priv->show_tabs || !priv->children || !priv->cur_page)
5797 min = max = tab_space = remaining_space = 0;
5800 gtk_notebook_tab_space (notebook, &showarrow,
5801 &min, &max, &tab_space);
5803 gtk_notebook_calculate_shown_tabs (notebook, showarrow,
5804 min, max, tab_space, &last_child,
5805 &expanded_tabs, &remaining_space);
5807 children = priv->first_tab;
5808 gtk_notebook_calculate_tabs_allocation (notebook, &children, last_child,
5809 showarrow, STEP_NEXT,
5810 &remaining_space, &expanded_tabs, min, max);
5811 if (children && children != last_child)
5813 children = priv->children;
5814 gtk_notebook_calculate_tabs_allocation (notebook, &children, last_child,
5815 showarrow, STEP_PREV,
5816 &remaining_space, &expanded_tabs, min, max);
5819 children = priv->children;
5823 if (gtk_notebook_page_allocate (notebook, GTK_NOTEBOOK_PAGE (children)))
5824 tab_allocations_changed = TRUE;
5825 children = children->next;
5828 if (!priv->first_tab)
5829 priv->first_tab = priv->children;
5831 if (tab_allocations_changed)
5832 gtk_notebook_redraw_tabs (notebook);
5836 gtk_notebook_page_allocate (GtkNotebook *notebook,
5837 GtkNotebookPage *page)
5839 GtkWidget *widget = GTK_WIDGET (notebook);
5840 GtkNotebookPrivate *priv = notebook->priv;
5841 GtkAllocation child_allocation, label_allocation;
5842 GtkRequisition tab_requisition;
5849 gint tab_pos = get_effective_tab_pos (notebook);
5850 gboolean tab_allocation_changed;
5851 gboolean was_visible = page->tab_allocated_visible;
5853 if (!page->tab_label ||
5854 !gtk_widget_get_visible (page->tab_label) ||
5855 !gtk_widget_get_child_visible (page->tab_label))
5857 page->tab_allocated_visible = FALSE;
5861 style = gtk_widget_get_style (widget);
5862 xthickness = style->xthickness;
5863 ythickness = style->ythickness;
5865 gtk_size_request_get_size (GTK_SIZE_REQUEST (page->tab_label),
5866 &tab_requisition, NULL);
5867 gtk_widget_style_get (widget,
5868 "focus-line-width", &focus_width,
5869 "tab-curvature", &tab_curvature,
5874 case GTK_POS_BOTTOM:
5875 padding = tab_curvature + focus_width + priv->tab_hborder;
5878 child_allocation.x = xthickness + focus_width + priv->tab_hborder;
5879 child_allocation.width = MAX (1, page->allocation.width - 2 * child_allocation.x);
5880 child_allocation.x += page->allocation.x;
5884 child_allocation.x = page->allocation.x +
5885 (page->allocation.width - tab_requisition.width) / 2;
5887 child_allocation.width = tab_requisition.width;
5890 child_allocation.y = priv->tab_vborder + focus_width + page->allocation.y;
5892 if (tab_pos == GTK_POS_TOP)
5893 child_allocation.y += ythickness;
5895 child_allocation.height = MAX (1, (page->allocation.height - ythickness -
5896 2 * (priv->tab_vborder + focus_width)));
5900 padding = tab_curvature + focus_width + priv->tab_vborder;
5903 child_allocation.y = ythickness + padding;
5904 child_allocation.height = MAX (1, (page->allocation.height -
5905 2 * child_allocation.y));
5906 child_allocation.y += page->allocation.y;
5910 child_allocation.y = page->allocation.y +
5911 (page->allocation.height - tab_requisition.height) / 2;
5913 child_allocation.height = tab_requisition.height;
5916 child_allocation.x = priv->tab_hborder + focus_width + page->allocation.x;
5918 if (tab_pos == GTK_POS_LEFT)
5919 child_allocation.x += xthickness;
5921 child_allocation.width = MAX (1, (page->allocation.width - xthickness -
5922 2 * (priv->tab_hborder + focus_width)));
5926 gtk_widget_get_allocation (page->tab_label, &label_allocation);
5927 tab_allocation_changed = (child_allocation.x != label_allocation.x ||
5928 child_allocation.y != label_allocation.y ||
5929 child_allocation.width != label_allocation.width ||
5930 child_allocation.height != label_allocation.height);
5932 gtk_widget_size_allocate (page->tab_label, &child_allocation);
5936 page->tab_allocated_visible = TRUE;
5937 tab_allocation_changed = TRUE;
5940 return tab_allocation_changed;
5944 gtk_notebook_calc_tabs (GtkNotebook *notebook,
5950 GtkNotebookPage *page = NULL;
5952 GList *last_list = NULL;
5953 GList *last_calculated_child = NULL;
5955 gint tab_pos = get_effective_tab_pos (notebook);
5956 guint real_direction;
5962 pack = GTK_NOTEBOOK_PAGE (start)->pack;
5963 if (pack == GTK_PACK_END)
5964 real_direction = (direction == STEP_PREV) ? STEP_NEXT : STEP_PREV;
5966 real_direction = direction;
5973 case GTK_POS_BOTTOM:
5976 page = children->data;
5977 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) &&
5978 gtk_widget_get_visible (page->child))
5980 if (page->pack == pack)
5982 *tab_space -= page->requisition.width;
5983 if (*tab_space < 0 || children == *end)
5987 *tab_space = - (*tab_space +
5988 page->requisition.width);
5990 if (*tab_space == 0 && direction == STEP_PREV)
5991 children = last_calculated_child;
5998 last_calculated_child = children;
6000 last_list = children;
6002 if (real_direction == STEP_NEXT)
6003 children = children->next;
6005 children = children->prev;
6012 page = children->data;
6013 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) &&
6014 gtk_widget_get_visible (page->child))
6016 if (page->pack == pack)
6018 *tab_space -= page->requisition.height;
6019 if (*tab_space < 0 || children == *end)
6023 *tab_space = - (*tab_space +
6024 page->requisition.height);
6026 if (*tab_space == 0 && direction == STEP_PREV)
6027 children = last_calculated_child;
6034 last_calculated_child = children;
6036 last_list = children;
6038 if (real_direction == STEP_NEXT)
6039 children = children->next;
6041 children = children->prev;
6045 if (real_direction == STEP_PREV)
6047 pack = (pack == GTK_PACK_END) ? GTK_PACK_START : GTK_PACK_END;
6048 real_direction = STEP_PREV;
6049 children = last_list;
6054 gtk_notebook_update_tab_states (GtkNotebook *notebook)
6056 GtkNotebookPrivate *priv = notebook->priv;
6059 for (list = priv->children; list != NULL; list = list->next)
6061 GtkNotebookPage *page = list->data;
6063 if (page->tab_label)
6065 if (page == priv->cur_page)
6066 gtk_widget_set_state (page->tab_label, GTK_STATE_NORMAL);
6068 gtk_widget_set_state (page->tab_label, GTK_STATE_ACTIVE);
6073 /* Private GtkNotebook Page Switch Methods:
6075 * gtk_notebook_real_switch_page
6078 gtk_notebook_real_switch_page (GtkNotebook *notebook,
6082 GtkNotebookPrivate *priv = notebook->priv;
6083 GList *list = gtk_notebook_find_child (notebook, GTK_WIDGET (child), NULL);
6084 GtkNotebookPage *page = GTK_NOTEBOOK_PAGE (list);
6085 gboolean child_has_focus;
6087 if (priv->cur_page == page || !gtk_widget_get_visible (GTK_WIDGET (child)))
6090 /* save the value here, changing visibility changes focus */
6091 child_has_focus = priv->child_has_focus;
6094 gtk_widget_set_child_visible (priv->cur_page->child, FALSE);
6096 priv->cur_page = page;
6098 if (!priv->focus_tab ||
6099 priv->focus_tab->data != (gpointer) priv->cur_page)
6101 g_list_find (priv->children, priv->cur_page);
6103 gtk_widget_set_child_visible (priv->cur_page->child, TRUE);
6105 /* If the focus was on the previous page, move it to the first
6106 * element on the new page, if possible, or if not, to the
6109 if (child_has_focus)
6111 if (priv->cur_page->last_focus_child &&
6112 gtk_widget_is_ancestor (priv->cur_page->last_focus_child, priv->cur_page->child))
6113 gtk_widget_grab_focus (priv->cur_page->last_focus_child);
6115 if (!gtk_widget_child_focus (priv->cur_page->child, GTK_DIR_TAB_FORWARD))
6116 gtk_widget_grab_focus (GTK_WIDGET (notebook));
6119 gtk_notebook_update_tab_states (notebook);
6120 gtk_widget_queue_resize (GTK_WIDGET (notebook));
6121 g_object_notify (G_OBJECT (notebook), "page");
6124 /* Private GtkNotebook Page Switch Functions:
6126 * gtk_notebook_switch_page
6127 * gtk_notebook_page_select
6128 * gtk_notebook_switch_focus_tab
6129 * gtk_notebook_menu_switch_page
6132 gtk_notebook_switch_page (GtkNotebook *notebook,
6133 GtkNotebookPage *page)
6135 GtkNotebookPrivate *priv = notebook->priv;
6138 if (priv->cur_page == page)
6141 page_num = g_list_index (priv->children, page);
6143 g_signal_emit (notebook,
6144 notebook_signals[SWITCH_PAGE],
6151 gtk_notebook_page_select (GtkNotebook *notebook,
6152 gboolean move_focus)
6154 GtkNotebookPrivate *priv = notebook->priv;
6155 GtkNotebookPage *page;
6156 GtkDirectionType dir = GTK_DIR_DOWN; /* Quiet GCC */
6157 gint tab_pos = get_effective_tab_pos (notebook);
6159 if (!priv->focus_tab)
6162 page = priv->focus_tab->data;
6163 gtk_notebook_switch_page (notebook, page);
6172 case GTK_POS_BOTTOM:
6176 dir = GTK_DIR_RIGHT;
6183 if (gtk_widget_child_focus (page->child, dir))
6190 gtk_notebook_switch_focus_tab (GtkNotebook *notebook,
6193 GtkNotebookPrivate *priv = notebook->priv;
6195 GtkNotebookPage *page;
6197 if (priv->focus_tab == new_child)
6200 old_child = priv->focus_tab;
6201 priv->focus_tab = new_child;
6203 if (priv->scrollable)
6204 gtk_notebook_redraw_arrows (notebook);
6206 if (!priv->show_tabs || !priv->focus_tab)
6209 page = priv->focus_tab->data;
6210 if (gtk_widget_get_mapped (page->tab_label))
6211 gtk_notebook_redraw_tabs (notebook);
6213 gtk_notebook_pages_allocate (notebook);
6215 gtk_notebook_switch_page (notebook, page);
6219 gtk_notebook_menu_switch_page (GtkWidget *widget,
6220 GtkNotebookPage *page)
6222 GtkNotebookPrivate *priv;
6223 GtkNotebook *notebook;
6228 parent = gtk_widget_get_parent (widget);
6229 notebook = GTK_NOTEBOOK (gtk_menu_get_attach_widget (GTK_MENU (parent)));
6230 priv = notebook->priv;
6232 if (priv->cur_page == page)
6236 children = priv->children;
6237 while (children && children->data != page)
6239 children = children->next;
6243 g_signal_emit (notebook,
6244 notebook_signals[SWITCH_PAGE],
6250 /* Private GtkNotebook Menu Functions:
6252 * gtk_notebook_menu_item_create
6253 * gtk_notebook_menu_label_unparent
6254 * gtk_notebook_menu_detacher
6257 gtk_notebook_menu_item_create (GtkNotebook *notebook,
6260 GtkNotebookPrivate *priv = notebook->priv;
6261 GtkNotebookPage *page;
6262 GtkWidget *menu_item;
6265 if (page->default_menu)
6267 if (GTK_IS_LABEL (page->tab_label))
6268 page->menu_label = gtk_label_new (gtk_label_get_label (GTK_LABEL (page->tab_label)));
6270 page->menu_label = gtk_label_new ("");
6271 gtk_misc_set_alignment (GTK_MISC (page->menu_label), 0.0, 0.5);
6274 gtk_widget_show (page->menu_label);
6275 menu_item = gtk_menu_item_new ();
6276 gtk_container_add (GTK_CONTAINER (menu_item), page->menu_label);
6277 gtk_menu_shell_insert (GTK_MENU_SHELL (priv->menu), menu_item,
6278 gtk_notebook_real_page_position (notebook, list));
6279 g_signal_connect (menu_item, "activate",
6280 G_CALLBACK (gtk_notebook_menu_switch_page), page);
6281 if (gtk_widget_get_visible (page->child))
6282 gtk_widget_show (menu_item);
6286 gtk_notebook_menu_label_unparent (GtkWidget *widget,
6289 gtk_widget_unparent (gtk_bin_get_child (GTK_BIN (widget)));
6290 _gtk_bin_set_child (GTK_BIN (widget), NULL);
6294 gtk_notebook_menu_detacher (GtkWidget *widget,
6297 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
6298 GtkNotebookPrivate *priv = notebook->priv;
6300 g_return_if_fail (priv->menu == (GtkWidget*) menu);
6305 /* Public GtkNotebook Page Insert/Remove Methods :
6307 * gtk_notebook_append_page
6308 * gtk_notebook_append_page_menu
6309 * gtk_notebook_prepend_page
6310 * gtk_notebook_prepend_page_menu
6311 * gtk_notebook_insert_page
6312 * gtk_notebook_insert_page_menu
6313 * gtk_notebook_remove_page
6316 * gtk_notebook_append_page:
6317 * @notebook: a #GtkNotebook
6318 * @child: the #GtkWidget to use as the contents of the page.
6319 * @tab_label: (allow-none): the #GtkWidget to be used as the label for the page,
6320 * or %NULL to use the default label, 'page N'.
6322 * Appends a page to @notebook.
6324 * Return value: the index (starting from 0) of the appended
6325 * page in the notebook, or -1 if function fails
6328 gtk_notebook_append_page (GtkNotebook *notebook,
6330 GtkWidget *tab_label)
6332 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6333 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6334 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6336 return gtk_notebook_insert_page_menu (notebook, child, tab_label, NULL, -1);
6340 * gtk_notebook_append_page_menu:
6341 * @notebook: a #GtkNotebook
6342 * @child: the #GtkWidget to use as the contents of the page.
6343 * @tab_label: (allow-none): the #GtkWidget to be used as the label for the page,
6344 * or %NULL to use the default label, 'page N'.
6345 * @menu_label: (allow-none): the widget to use as a label for the page-switch
6346 * menu, if that is enabled. If %NULL, and @tab_label
6347 * is a #GtkLabel or %NULL, then the menu label will be
6348 * a newly created label with the same text as @tab_label;
6349 * If @tab_label is not a #GtkLabel, @menu_label must be
6350 * specified if the page-switch menu is to be used.
6352 * Appends a page to @notebook, specifying the widget to use as the
6353 * label in the popup menu.
6355 * Return value: the index (starting from 0) of the appended
6356 * page in the notebook, or -1 if function fails
6359 gtk_notebook_append_page_menu (GtkNotebook *notebook,
6361 GtkWidget *tab_label,
6362 GtkWidget *menu_label)
6364 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6365 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6366 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6367 g_return_val_if_fail (menu_label == NULL || GTK_IS_WIDGET (menu_label), -1);
6369 return gtk_notebook_insert_page_menu (notebook, child, tab_label, menu_label, -1);
6373 * gtk_notebook_prepend_page:
6374 * @notebook: a #GtkNotebook
6375 * @child: the #GtkWidget to use as the contents of the page.
6376 * @tab_label: (allow-none): the #GtkWidget to be used as the label for the page,
6377 * or %NULL to use the default label, 'page N'.
6379 * Prepends a page to @notebook.
6381 * Return value: the index (starting from 0) of the prepended
6382 * page in the notebook, or -1 if function fails
6385 gtk_notebook_prepend_page (GtkNotebook *notebook,
6387 GtkWidget *tab_label)
6389 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6390 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6391 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6393 return gtk_notebook_insert_page_menu (notebook, child, tab_label, NULL, 0);
6397 * gtk_notebook_prepend_page_menu:
6398 * @notebook: a #GtkNotebook
6399 * @child: the #GtkWidget to use as the contents of the page.
6400 * @tab_label: (allow-none): the #GtkWidget to be used as the label for the page,
6401 * or %NULL to use the default label, 'page N'.
6402 * @menu_label: (allow-none): the widget to use as a label for the page-switch
6403 * menu, if that is enabled. If %NULL, and @tab_label
6404 * is a #GtkLabel or %NULL, then the menu label will be
6405 * a newly created label with the same text as @tab_label;
6406 * If @tab_label is not a #GtkLabel, @menu_label must be
6407 * specified if the page-switch menu is to be used.
6409 * Prepends a page to @notebook, specifying the widget to use as the
6410 * label in the popup menu.
6412 * Return value: the index (starting from 0) of the prepended
6413 * page in the notebook, or -1 if function fails
6416 gtk_notebook_prepend_page_menu (GtkNotebook *notebook,
6418 GtkWidget *tab_label,
6419 GtkWidget *menu_label)
6421 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6422 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6423 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6424 g_return_val_if_fail (menu_label == NULL || GTK_IS_WIDGET (menu_label), -1);
6426 return gtk_notebook_insert_page_menu (notebook, child, tab_label, menu_label, 0);
6430 * gtk_notebook_insert_page:
6431 * @notebook: a #GtkNotebook
6432 * @child: the #GtkWidget to use as the contents of the page.
6433 * @tab_label: (allow-none): the #GtkWidget to be used as the label for the page,
6434 * or %NULL to use the default label, 'page N'.
6435 * @position: the index (starting at 0) at which to insert the page,
6436 * or -1 to append the page after all other pages.
6438 * Insert a page into @notebook at the given position.
6440 * Return value: the index (starting from 0) of the inserted
6441 * page in the notebook, or -1 if function fails
6444 gtk_notebook_insert_page (GtkNotebook *notebook,
6446 GtkWidget *tab_label,
6449 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6450 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6451 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6453 return gtk_notebook_insert_page_menu (notebook, child, tab_label, NULL, position);
6458 gtk_notebook_page_compare_tab (gconstpointer a,
6461 return (((GtkNotebookPage *) a)->tab_label != b);
6465 gtk_notebook_mnemonic_activate_switch_page (GtkWidget *child,
6469 GtkNotebook *notebook = GTK_NOTEBOOK (data);
6470 GtkNotebookPrivate *priv = notebook->priv;
6473 list = g_list_find_custom (priv->children, child,
6474 gtk_notebook_page_compare_tab);
6477 GtkNotebookPage *page = list->data;
6479 gtk_widget_grab_focus (GTK_WIDGET (notebook)); /* Do this first to avoid focusing new page */
6480 gtk_notebook_switch_page (notebook, page);
6481 focus_tabs_in (notebook);
6488 * gtk_notebook_insert_page_menu:
6489 * @notebook: a #GtkNotebook
6490 * @child: the #GtkWidget to use as the contents of the page.
6491 * @tab_label: (allow-none): the #GtkWidget to be used as the label for the page,
6492 * or %NULL to use the default label, 'page N'.
6493 * @menu_label: (allow-none): the widget to use as a label for the page-switch
6494 * menu, if that is enabled. If %NULL, and @tab_label
6495 * is a #GtkLabel or %NULL, then the menu label will be
6496 * a newly created label with the same text as @tab_label;
6497 * If @tab_label is not a #GtkLabel, @menu_label must be
6498 * specified if the page-switch menu is to be used.
6499 * @position: the index (starting at 0) at which to insert the page,
6500 * or -1 to append the page after all other pages.
6502 * Insert a page into @notebook at the given position, specifying
6503 * the widget to use as the label in the popup menu.
6505 * Return value: the index (starting from 0) of the inserted
6506 * page in the notebook
6509 gtk_notebook_insert_page_menu (GtkNotebook *notebook,
6511 GtkWidget *tab_label,
6512 GtkWidget *menu_label,
6515 GtkNotebookClass *class;
6517 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6518 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6519 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6520 g_return_val_if_fail (menu_label == NULL || GTK_IS_WIDGET (menu_label), -1);
6522 class = GTK_NOTEBOOK_GET_CLASS (notebook);
6524 return (class->insert_page) (notebook, child, tab_label, menu_label, position);
6528 * gtk_notebook_remove_page:
6529 * @notebook: a #GtkNotebook.
6530 * @page_num: the index of a notebook page, starting
6531 * from 0. If -1, the last page will
6534 * Removes a page from the notebook given its index
6538 gtk_notebook_remove_page (GtkNotebook *notebook,
6541 GtkNotebookPrivate *priv;
6544 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6546 priv = notebook->priv;
6549 list = g_list_nth (priv->children, page_num);
6551 list = g_list_last (priv->children);
6554 gtk_container_remove (GTK_CONTAINER (notebook),
6555 ((GtkNotebookPage *) list->data)->child);
6558 /* Public GtkNotebook Page Switch Methods :
6559 * gtk_notebook_get_current_page
6560 * gtk_notebook_page_num
6561 * gtk_notebook_set_current_page
6562 * gtk_notebook_next_page
6563 * gtk_notebook_prev_page
6566 * gtk_notebook_get_current_page:
6567 * @notebook: a #GtkNotebook
6569 * Returns the page number of the current page.
6571 * Return value: the index (starting from 0) of the current
6572 * page in the notebook. If the notebook has no pages, then
6573 * -1 will be returned.
6576 gtk_notebook_get_current_page (GtkNotebook *notebook)
6578 GtkNotebookPrivate *priv;
6580 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6582 priv = notebook->priv;
6584 if (!priv->cur_page)
6587 return g_list_index (priv->children, priv->cur_page);
6591 * gtk_notebook_get_nth_page:
6592 * @notebook: a #GtkNotebook
6593 * @page_num: the index of a page in the notebook, or -1
6594 * to get the last page.
6596 * Returns the child widget contained in page number @page_num.
6598 * Return value: (transfer none): the child widget, or %NULL if @page_num is
6602 gtk_notebook_get_nth_page (GtkNotebook *notebook,
6605 GtkNotebookPrivate *priv;
6606 GtkNotebookPage *page;
6609 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
6611 priv = notebook->priv;
6614 list = g_list_nth (priv->children, page_num);
6616 list = g_list_last (priv->children);
6628 * gtk_notebook_get_n_pages:
6629 * @notebook: a #GtkNotebook
6631 * Gets the number of pages in a notebook.
6633 * Return value: the number of pages in the notebook.
6638 gtk_notebook_get_n_pages (GtkNotebook *notebook)
6640 GtkNotebookPrivate *priv;
6642 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), 0);
6644 priv = notebook->priv;
6646 return g_list_length (priv->children);
6650 * gtk_notebook_page_num:
6651 * @notebook: a #GtkNotebook
6652 * @child: a #GtkWidget
6654 * Finds the index of the page which contains the given child
6657 * Return value: the index of the page containing @child, or
6658 * -1 if @child is not in the notebook.
6661 gtk_notebook_page_num (GtkNotebook *notebook,
6664 GtkNotebookPrivate *priv;
6668 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6670 priv = notebook->priv;
6673 children = priv->children;
6676 GtkNotebookPage *page = children->data;
6678 if (page->child == child)
6681 children = children->next;
6689 * gtk_notebook_set_current_page:
6690 * @notebook: a #GtkNotebook
6691 * @page_num: index of the page to switch to, starting from 0.
6692 * If negative, the last page will be used. If greater
6693 * than the number of pages in the notebook, nothing
6696 * Switches to the page number @page_num.
6698 * Note that due to historical reasons, GtkNotebook refuses
6699 * to switch to a page unless the child widget is visible.
6700 * Therefore, it is recommended to show child widgets before
6701 * adding them to a notebook.
6704 gtk_notebook_set_current_page (GtkNotebook *notebook,
6707 GtkNotebookPrivate *priv;
6710 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6712 priv = notebook->priv;
6715 page_num = g_list_length (priv->children) - 1;
6717 list = g_list_nth (priv->children, page_num);
6719 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (list));
6723 * gtk_notebook_next_page:
6724 * @notebook: a #GtkNotebook
6726 * Switches to the next page. Nothing happens if the current page is
6730 gtk_notebook_next_page (GtkNotebook *notebook)
6732 GtkNotebookPrivate *priv;
6735 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6737 priv = notebook->priv;
6739 list = g_list_find (priv->children, priv->cur_page);
6743 list = gtk_notebook_search_page (notebook, list, STEP_NEXT, TRUE);
6747 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (list));
6751 * gtk_notebook_prev_page:
6752 * @notebook: a #GtkNotebook
6754 * Switches to the previous page. Nothing happens if the current page
6755 * is the first page.
6758 gtk_notebook_prev_page (GtkNotebook *notebook)
6760 GtkNotebookPrivate *priv;
6763 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6765 priv = notebook->priv;
6767 list = g_list_find (priv->children, priv->cur_page);
6771 list = gtk_notebook_search_page (notebook, list, STEP_PREV, TRUE);
6775 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (list));
6778 /* Public GtkNotebook/Tab Style Functions
6780 * gtk_notebook_set_show_border
6781 * gtk_notebook_get_show_border
6782 * gtk_notebook_set_show_tabs
6783 * gtk_notebook_get_show_tabs
6784 * gtk_notebook_set_tab_pos
6785 * gtk_notebook_get_tab_pos
6786 * gtk_notebook_set_scrollable
6787 * gtk_notebook_get_scrollable
6788 * gtk_notebook_get_tab_hborder
6789 * gtk_notebook_get_tab_vborder
6792 * gtk_notebook_set_show_border:
6793 * @notebook: a #GtkNotebook
6794 * @show_border: %TRUE if a bevel should be drawn around the notebook.
6796 * Sets whether a bevel will be drawn around the notebook pages.
6797 * This only has a visual effect when the tabs are not shown.
6798 * See gtk_notebook_set_show_tabs().
6801 gtk_notebook_set_show_border (GtkNotebook *notebook,
6802 gboolean show_border)
6804 GtkNotebookPrivate *priv;
6806 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6808 priv = notebook->priv;
6810 if (priv->show_border != show_border)
6812 priv->show_border = show_border;
6814 if (gtk_widget_get_visible (GTK_WIDGET (notebook)))
6815 gtk_widget_queue_resize (GTK_WIDGET (notebook));
6817 g_object_notify (G_OBJECT (notebook), "show-border");
6822 * gtk_notebook_get_show_border:
6823 * @notebook: a #GtkNotebook
6825 * Returns whether a bevel will be drawn around the notebook pages. See
6826 * gtk_notebook_set_show_border().
6828 * Return value: %TRUE if the bevel is drawn
6831 gtk_notebook_get_show_border (GtkNotebook *notebook)
6833 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
6835 return notebook->priv->show_border;
6839 * gtk_notebook_set_show_tabs:
6840 * @notebook: a #GtkNotebook
6841 * @show_tabs: %TRUE if the tabs should be shown.
6843 * Sets whether to show the tabs for the notebook or not.
6846 gtk_notebook_set_show_tabs (GtkNotebook *notebook,
6849 GtkNotebookPrivate *priv;
6850 GtkNotebookPage *page;
6854 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6856 priv = notebook->priv;
6858 show_tabs = show_tabs != FALSE;
6860 if (priv->show_tabs == show_tabs)
6863 priv->show_tabs = show_tabs;
6864 children = priv->children;
6868 gtk_widget_set_can_focus (GTK_WIDGET (notebook), FALSE);
6872 page = children->data;
6873 children = children->next;
6874 if (page->default_tab)
6876 gtk_widget_destroy (page->tab_label);
6877 page->tab_label = NULL;
6880 gtk_widget_hide (page->tab_label);
6885 gtk_widget_set_can_focus (GTK_WIDGET (notebook), TRUE);
6886 gtk_notebook_update_labels (notebook);
6889 for (i = 0; i < N_ACTION_WIDGETS; i++)
6891 if (priv->action_widget[i])
6892 gtk_widget_set_child_visible (priv->action_widget[i], show_tabs);
6895 gtk_widget_queue_resize (GTK_WIDGET (notebook));
6897 g_object_notify (G_OBJECT (notebook), "show-tabs");
6901 * gtk_notebook_get_show_tabs:
6902 * @notebook: a #GtkNotebook
6904 * Returns whether the tabs of the notebook are shown. See
6905 * gtk_notebook_set_show_tabs().
6907 * Return value: %TRUE if the tabs are shown
6910 gtk_notebook_get_show_tabs (GtkNotebook *notebook)
6912 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
6914 return notebook->priv->show_tabs;
6918 * gtk_notebook_set_tab_pos:
6919 * @notebook: a #GtkNotebook.
6920 * @pos: the edge to draw the tabs at.
6922 * Sets the edge at which the tabs for switching pages in the
6923 * notebook are drawn.
6926 gtk_notebook_set_tab_pos (GtkNotebook *notebook,
6927 GtkPositionType pos)
6929 GtkNotebookPrivate *priv;
6931 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6933 priv = notebook->priv;
6935 if (priv->tab_pos != pos)
6937 priv->tab_pos = pos;
6938 if (gtk_widget_get_visible (GTK_WIDGET (notebook)))
6939 gtk_widget_queue_resize (GTK_WIDGET (notebook));
6942 g_object_notify (G_OBJECT (notebook), "tab-pos");
6946 * gtk_notebook_get_tab_pos:
6947 * @notebook: a #GtkNotebook
6949 * Gets the edge at which the tabs for switching pages in the
6950 * notebook are drawn.
6952 * Return value: the edge at which the tabs are drawn
6955 gtk_notebook_get_tab_pos (GtkNotebook *notebook)
6957 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), GTK_POS_TOP);
6959 return notebook->priv->tab_pos;
6963 * gtk_notebook_set_scrollable:
6964 * @notebook: a #GtkNotebook
6965 * @scrollable: %TRUE if scroll arrows should be added
6967 * Sets whether the tab label area will have arrows for scrolling if
6968 * there are too many tabs to fit in the area.
6971 gtk_notebook_set_scrollable (GtkNotebook *notebook,
6972 gboolean scrollable)
6974 GtkNotebookPrivate *priv;
6976 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6978 priv = notebook->priv;
6980 scrollable = (scrollable != FALSE);
6982 if (scrollable != priv->scrollable)
6984 priv->scrollable = scrollable;
6986 if (gtk_widget_get_visible (GTK_WIDGET (notebook)))
6987 gtk_widget_queue_resize (GTK_WIDGET (notebook));
6989 g_object_notify (G_OBJECT (notebook), "scrollable");
6994 * gtk_notebook_get_scrollable:
6995 * @notebook: a #GtkNotebook
6997 * Returns whether the tab label area has arrows for scrolling. See
6998 * gtk_notebook_set_scrollable().
7000 * Return value: %TRUE if arrows for scrolling are present
7003 gtk_notebook_get_scrollable (GtkNotebook *notebook)
7005 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
7007 return notebook->priv->scrollable;
7011 * gtk_notebook_get_tab_hborder:
7012 * @notebook: a #GtkNotebook
7014 * Returns the horizontal width of a tab border.
7016 * Return value: horizontal width of a tab border
7021 gtk_notebook_get_tab_hborder (GtkNotebook *notebook)
7023 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
7025 return notebook->priv->tab_hborder;
7029 * gtk_notebook_get_tab_vborder:
7030 * @notebook: a #GtkNotebook
7032 * Returns the vertical width of a tab border.
7034 * Return value: vertical width of a tab border
7039 gtk_notebook_get_tab_vborder (GtkNotebook *notebook)
7041 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
7043 return notebook->priv->tab_vborder;
7047 /* Public GtkNotebook Popup Menu Methods:
7049 * gtk_notebook_popup_enable
7050 * gtk_notebook_popup_disable
7055 * gtk_notebook_popup_enable:
7056 * @notebook: a #GtkNotebook
7058 * Enables the popup menu: if the user clicks with the right mouse button on
7059 * the tab labels, a menu with all the pages will be popped up.
7062 gtk_notebook_popup_enable (GtkNotebook *notebook)
7064 GtkNotebookPrivate *priv;
7067 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7069 priv = notebook->priv;
7074 priv->menu = gtk_menu_new ();
7075 for (list = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, FALSE);
7077 list = gtk_notebook_search_page (notebook, list, STEP_NEXT, FALSE))
7078 gtk_notebook_menu_item_create (notebook, list);
7080 gtk_notebook_update_labels (notebook);
7081 gtk_menu_attach_to_widget (GTK_MENU (priv->menu),
7082 GTK_WIDGET (notebook),
7083 gtk_notebook_menu_detacher);
7085 g_object_notify (G_OBJECT (notebook), "enable-popup");
7089 * gtk_notebook_popup_disable:
7090 * @notebook: a #GtkNotebook
7092 * Disables the popup menu.
7095 gtk_notebook_popup_disable (GtkNotebook *notebook)
7097 GtkNotebookPrivate *priv;
7099 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7101 priv = notebook->priv;
7106 gtk_container_foreach (GTK_CONTAINER (priv->menu),
7107 (GtkCallback) gtk_notebook_menu_label_unparent, NULL);
7108 gtk_widget_destroy (priv->menu);
7110 g_object_notify (G_OBJECT (notebook), "enable-popup");
7113 /* Public GtkNotebook Page Properties Functions:
7115 * gtk_notebook_get_tab_label
7116 * gtk_notebook_set_tab_label
7117 * gtk_notebook_set_tab_label_text
7118 * gtk_notebook_get_menu_label
7119 * gtk_notebook_set_menu_label
7120 * gtk_notebook_set_menu_label_text
7121 * gtk_notebook_get_tab_reorderable
7122 * gtk_notebook_set_tab_reorderable
7123 * gtk_notebook_get_tab_detachable
7124 * gtk_notebook_set_tab_detachable
7128 * gtk_notebook_get_tab_label:
7129 * @notebook: a #GtkNotebook
7132 * Returns the tab label widget for the page @child. %NULL is returned
7133 * if @child is not in @notebook or if no tab label has specifically
7134 * been set for @child.
7136 * Return value: (transfer none): the tab label
7139 gtk_notebook_get_tab_label (GtkNotebook *notebook,
7144 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
7145 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
7147 list = CHECK_FIND_CHILD (notebook, child);
7151 if (GTK_NOTEBOOK_PAGE (list)->default_tab)
7154 return GTK_NOTEBOOK_PAGE (list)->tab_label;
7158 * gtk_notebook_set_tab_label:
7159 * @notebook: a #GtkNotebook
7161 * @tab_label: (allow-none): the tab label widget to use, or %NULL for default tab
7164 * Changes the tab label for @child. If %NULL is specified
7165 * for @tab_label, then the page will have the label 'page N'.
7168 gtk_notebook_set_tab_label (GtkNotebook *notebook,
7170 GtkWidget *tab_label)
7172 GtkNotebookPrivate *priv;
7173 GtkNotebookPage *page;
7176 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7177 g_return_if_fail (GTK_IS_WIDGET (child));
7179 priv = notebook->priv;
7181 list = CHECK_FIND_CHILD (notebook, child);
7185 /* a NULL pointer indicates a default_tab setting, otherwise
7186 * we need to set the associated label
7190 if (page->tab_label == tab_label)
7194 gtk_notebook_remove_tab_label (notebook, page);
7198 page->default_tab = FALSE;
7199 page->tab_label = tab_label;
7200 gtk_widget_set_parent (page->tab_label, GTK_WIDGET (notebook));
7204 page->default_tab = TRUE;
7205 page->tab_label = NULL;
7207 if (priv->show_tabs)
7211 g_snprintf (string, sizeof(string), _("Page %u"),
7212 gtk_notebook_real_page_position (notebook, list));
7213 page->tab_label = gtk_label_new (string);
7214 gtk_widget_set_parent (page->tab_label, GTK_WIDGET (notebook));
7218 if (page->tab_label)
7219 page->mnemonic_activate_signal =
7220 g_signal_connect (page->tab_label,
7221 "mnemonic-activate",
7222 G_CALLBACK (gtk_notebook_mnemonic_activate_switch_page),
7225 if (priv->show_tabs && gtk_widget_get_visible (child))
7227 gtk_widget_show (page->tab_label);
7228 gtk_widget_queue_resize (GTK_WIDGET (notebook));
7231 gtk_notebook_update_tab_states (notebook);
7232 gtk_widget_child_notify (child, "tab-label");
7236 * gtk_notebook_set_tab_label_text:
7237 * @notebook: a #GtkNotebook
7239 * @tab_text: the label text
7241 * Creates a new label and sets it as the tab label for the page
7242 * containing @child.
7245 gtk_notebook_set_tab_label_text (GtkNotebook *notebook,
7247 const gchar *tab_text)
7249 GtkWidget *tab_label = NULL;
7251 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7254 tab_label = gtk_label_new (tab_text);
7255 gtk_notebook_set_tab_label (notebook, child, tab_label);
7256 gtk_widget_child_notify (child, "tab-label");
7260 * gtk_notebook_get_tab_label_text:
7261 * @notebook: a #GtkNotebook
7262 * @child: a widget contained in a page of @notebook
7264 * Retrieves the text of the tab label for the page containing
7267 * Return value: the text of the tab label, or %NULL if the
7268 * tab label widget is not a #GtkLabel. The
7269 * string is owned by the widget and must not
7272 G_CONST_RETURN gchar *
7273 gtk_notebook_get_tab_label_text (GtkNotebook *notebook,
7276 GtkWidget *tab_label;
7278 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
7279 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
7281 tab_label = gtk_notebook_get_tab_label (notebook, child);
7283 if (GTK_IS_LABEL (tab_label))
7284 return gtk_label_get_text (GTK_LABEL (tab_label));
7290 * gtk_notebook_get_menu_label:
7291 * @notebook: a #GtkNotebook
7292 * @child: a widget contained in a page of @notebook
7294 * Retrieves the menu label widget of the page containing @child.
7296 * Return value: (transfer none): the menu label, or %NULL if the
7297 * notebook page does not have a menu label other than the
7298 * default (the tab label).
7301 gtk_notebook_get_menu_label (GtkNotebook *notebook,
7306 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
7307 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
7309 list = CHECK_FIND_CHILD (notebook, child);
7313 if (GTK_NOTEBOOK_PAGE (list)->default_menu)
7316 return GTK_NOTEBOOK_PAGE (list)->menu_label;
7320 * gtk_notebook_set_menu_label:
7321 * @notebook: a #GtkNotebook
7322 * @child: the child widget
7323 * @menu_label: (allow-none): the menu label, or NULL for default
7325 * Changes the menu label for the page containing @child.
7328 gtk_notebook_set_menu_label (GtkNotebook *notebook,
7330 GtkWidget *menu_label)
7332 GtkNotebookPrivate *priv;
7333 GtkNotebookPage *page;
7336 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7337 g_return_if_fail (GTK_IS_WIDGET (child));
7339 priv = notebook->priv;
7341 list = CHECK_FIND_CHILD (notebook, child);
7346 if (page->menu_label)
7349 gtk_container_remove (GTK_CONTAINER (priv->menu),
7350 gtk_widget_get_parent (page->menu_label));
7352 if (!page->default_menu)
7353 g_object_unref (page->menu_label);
7358 page->menu_label = menu_label;
7359 g_object_ref_sink (page->menu_label);
7360 page->default_menu = FALSE;
7363 page->default_menu = TRUE;
7366 gtk_notebook_menu_item_create (notebook, list);
7367 gtk_widget_child_notify (child, "menu-label");
7371 * gtk_notebook_set_menu_label_text:
7372 * @notebook: a #GtkNotebook
7373 * @child: the child widget
7374 * @menu_text: the label text
7376 * Creates a new label and sets it as the menu label of @child.
7379 gtk_notebook_set_menu_label_text (GtkNotebook *notebook,
7381 const gchar *menu_text)
7383 GtkWidget *menu_label = NULL;
7385 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7389 menu_label = gtk_label_new (menu_text);
7390 gtk_misc_set_alignment (GTK_MISC (menu_label), 0.0, 0.5);
7392 gtk_notebook_set_menu_label (notebook, child, menu_label);
7393 gtk_widget_child_notify (child, "menu-label");
7397 * gtk_notebook_get_menu_label_text:
7398 * @notebook: a #GtkNotebook
7399 * @child: the child widget of a page of the notebook.
7401 * Retrieves the text of the menu label for the page containing
7404 * Return value: the text of the tab label, or %NULL if the
7405 * widget does not have a menu label other than
7406 * the default menu label, or the menu label widget
7407 * is not a #GtkLabel. The string is owned by
7408 * the widget and must not be freed.
7410 G_CONST_RETURN gchar *
7411 gtk_notebook_get_menu_label_text (GtkNotebook *notebook,
7414 GtkWidget *menu_label;
7416 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
7417 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
7419 menu_label = gtk_notebook_get_menu_label (notebook, child);
7421 if (GTK_IS_LABEL (menu_label))
7422 return gtk_label_get_text (GTK_LABEL (menu_label));
7427 /* Helper function called when pages are reordered
7430 gtk_notebook_child_reordered (GtkNotebook *notebook,
7431 GtkNotebookPage *page)
7433 GtkNotebookPrivate *priv = notebook->priv;
7437 GtkWidget *menu_item;
7439 menu_item = gtk_widget_get_parent (page->menu_label);
7440 gtk_container_remove (GTK_CONTAINER (menu_item), page->menu_label);
7441 gtk_container_remove (GTK_CONTAINER (priv->menu), menu_item);
7442 gtk_notebook_menu_item_create (notebook, g_list_find (priv->children, page));
7445 gtk_notebook_update_tab_states (notebook);
7446 gtk_notebook_update_labels (notebook);
7450 gtk_notebook_set_tab_label_packing (GtkNotebook *notebook,
7454 GtkPackType pack_type)
7456 GtkNotebookPrivate *priv;
7457 GtkNotebookPage *page;
7460 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7461 g_return_if_fail (GTK_IS_WIDGET (child));
7463 priv = notebook->priv;
7465 list = CHECK_FIND_CHILD (notebook, child);
7470 expand = expand != FALSE;
7471 fill = fill != FALSE;
7472 if (page->pack == pack_type && page->expand == expand && page->fill == fill)
7475 gtk_widget_freeze_child_notify (child);
7476 page->expand = expand;
7477 gtk_widget_child_notify (child, "tab-expand");
7479 gtk_widget_child_notify (child, "tab-fill");
7480 if (page->pack != pack_type)
7482 page->pack = pack_type;
7483 gtk_notebook_child_reordered (notebook, page);
7485 gtk_widget_child_notify (child, "tab-pack");
7486 gtk_widget_child_notify (child, "position");
7487 if (priv->show_tabs)
7488 gtk_notebook_pages_allocate (notebook);
7489 gtk_widget_thaw_child_notify (child);
7493 gtk_notebook_query_tab_label_packing (GtkNotebook *notebook,
7497 GtkPackType *pack_type)
7501 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7502 g_return_if_fail (GTK_IS_WIDGET (child));
7504 list = CHECK_FIND_CHILD (notebook, child);
7509 *expand = GTK_NOTEBOOK_PAGE (list)->expand;
7511 *fill = GTK_NOTEBOOK_PAGE (list)->fill;
7513 *pack_type = GTK_NOTEBOOK_PAGE (list)->pack;
7517 * gtk_notebook_reorder_child:
7518 * @notebook: a #GtkNotebook
7519 * @child: the child to move
7520 * @position: the new position, or -1 to move to the end
7522 * Reorders the page containing @child, so that it appears in position
7523 * @position. If @position is greater than or equal to the number of
7524 * children in the list or negative, @child will be moved to the end
7528 gtk_notebook_reorder_child (GtkNotebook *notebook,
7532 GtkNotebookPrivate *priv;
7533 GList *list, *new_list;
7534 GtkNotebookPage *page;
7538 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7539 g_return_if_fail (GTK_IS_WIDGET (child));
7541 priv = notebook->priv;
7543 list = CHECK_FIND_CHILD (notebook, child);
7547 max_pos = g_list_length (priv->children) - 1;
7548 if (position < 0 || position > max_pos)
7551 old_pos = g_list_position (priv->children, list);
7553 if (old_pos == position)
7557 priv->children = g_list_delete_link (priv->children, list);
7559 priv->children = g_list_insert (priv->children, page, position);
7560 new_list = g_list_nth (priv->children, position);
7562 /* Fix up GList references in GtkNotebook structure */
7563 if (priv->first_tab == list)
7564 priv->first_tab = new_list;
7565 if (priv->focus_tab == list)
7566 priv->focus_tab = new_list;
7568 gtk_widget_freeze_child_notify (child);
7570 /* Move around the menu items if necessary */
7571 gtk_notebook_child_reordered (notebook, page);
7572 gtk_widget_child_notify (child, "tab-pack");
7573 gtk_widget_child_notify (child, "position");
7575 if (priv->show_tabs)
7576 gtk_notebook_pages_allocate (notebook);
7578 gtk_widget_thaw_child_notify (child);
7580 g_signal_emit (notebook,
7581 notebook_signals[PAGE_REORDERED],
7588 * gtk_notebook_set_group_name:
7589 * @notebook: a #GtkNotebook
7590 * @name: (allow-none): the name of the notebook group, or %NULL to unset it
7592 * Sets a group name for @notebook.
7594 * Notebooks with the same name will be able to exchange tabs
7595 * via drag and drop. A notebook with a %NULL group name will
7596 * not be able to exchange tabs with any other notebook.
7601 gtk_notebook_set_group_name (GtkNotebook *notebook,
7602 const gchar *group_name)
7604 GtkNotebookPrivate *priv;
7607 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7609 priv = notebook->priv;
7611 group = g_quark_from_string (group_name);
7613 if (priv->group != group)
7615 priv->group = group;
7616 g_object_notify (G_OBJECT (notebook), "group-name");
7621 * gtk_notebook_get_group_name:
7622 * @notebook: a #GtkNotebook
7624 * Gets the current group name for @notebook.
7626 * Return Value: (transfer none): the group name,
7627 * or %NULL if none is set.
7632 gtk_notebook_get_group_name (GtkNotebook *notebook)
7634 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
7636 return g_quark_to_string (notebook->priv->group);
7640 * gtk_notebook_get_tab_reorderable:
7641 * @notebook: a #GtkNotebook
7642 * @child: a child #GtkWidget
7644 * Gets whether the tab can be reordered via drag and drop or not.
7646 * Return Value: %TRUE if the tab is reorderable.
7651 gtk_notebook_get_tab_reorderable (GtkNotebook *notebook,
7656 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
7657 g_return_val_if_fail (GTK_IS_WIDGET (child), FALSE);
7659 list = CHECK_FIND_CHILD (notebook, child);
7663 return GTK_NOTEBOOK_PAGE (list)->reorderable;
7667 * gtk_notebook_set_tab_reorderable:
7668 * @notebook: a #GtkNotebook
7669 * @child: a child #GtkWidget
7670 * @reorderable: whether the tab is reorderable or not.
7672 * Sets whether the notebook tab can be reordered
7673 * via drag and drop or not.
7678 gtk_notebook_set_tab_reorderable (GtkNotebook *notebook,
7680 gboolean reorderable)
7684 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7685 g_return_if_fail (GTK_IS_WIDGET (child));
7687 list = CHECK_FIND_CHILD (notebook, child);
7691 if (GTK_NOTEBOOK_PAGE (list)->reorderable != reorderable)
7693 GTK_NOTEBOOK_PAGE (list)->reorderable = (reorderable == TRUE);
7694 gtk_widget_child_notify (child, "reorderable");
7699 * gtk_notebook_get_tab_detachable:
7700 * @notebook: a #GtkNotebook
7701 * @child: a child #GtkWidget
7703 * Returns whether the tab contents can be detached from @notebook.
7705 * Return Value: TRUE if the tab is detachable.
7710 gtk_notebook_get_tab_detachable (GtkNotebook *notebook,
7715 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
7716 g_return_val_if_fail (GTK_IS_WIDGET (child), FALSE);
7718 list = CHECK_FIND_CHILD (notebook, child);
7722 return GTK_NOTEBOOK_PAGE (list)->detachable;
7726 * gtk_notebook_set_tab_detachable:
7727 * @notebook: a #GtkNotebook
7728 * @child: a child #GtkWidget
7729 * @detachable: whether the tab is detachable or not
7731 * Sets whether the tab can be detached from @notebook to another
7732 * notebook or widget.
7734 * Note that 2 notebooks must share a common group identificator
7735 * (see gtk_notebook_set_group()) to allow automatic tabs
7736 * interchange between them.
7738 * If you want a widget to interact with a notebook through DnD
7739 * (i.e.: accept dragged tabs from it) it must be set as a drop
7740 * destination and accept the target "GTK_NOTEBOOK_TAB". The notebook
7741 * will fill the selection with a GtkWidget** pointing to the child
7742 * widget that corresponds to the dropped tab.
7745 * on_drop_zone_drag_data_received (GtkWidget *widget,
7746 * GdkDragContext *context,
7749 * GtkSelectionData *selection_data,
7752 * gpointer user_data)
7754 * GtkWidget *notebook;
7755 * GtkWidget **child;
7757 * notebook = gtk_drag_get_source_widget (context);
7758 * child = (void*) selection_data->data;
7760 * process_widget (*child);
7761 * gtk_container_remove (GTK_CONTAINER (notebook), *child);
7765 * If you want a notebook to accept drags from other widgets,
7766 * you will have to set your own DnD code to do it.
7771 gtk_notebook_set_tab_detachable (GtkNotebook *notebook,
7773 gboolean detachable)
7777 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7778 g_return_if_fail (GTK_IS_WIDGET (child));
7780 list = CHECK_FIND_CHILD (notebook, child);
7784 if (GTK_NOTEBOOK_PAGE (list)->detachable != detachable)
7786 GTK_NOTEBOOK_PAGE (list)->detachable = (detachable == TRUE);
7787 gtk_widget_child_notify (child, "detachable");
7792 * gtk_notebook_get_action_widget:
7793 * @notebook: a #GtkNotebook
7794 * @pack_type: pack type of the action widget to receive
7796 * Gets one of the action widgets. See gtk_notebook_set_action_widget().
7798 * Returns: (transfer none): The action widget with the given @pack_type
7799 * or %NULL when this action widget has not been set
7804 gtk_notebook_get_action_widget (GtkNotebook *notebook,
7805 GtkPackType pack_type)
7807 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
7809 return notebook->priv->action_widget[pack_type];
7813 * gtk_notebook_set_action_widget:
7814 * @notebook: a #GtkNotebook
7815 * @widget: a #GtkWidget
7816 * @pack_type: pack type of the action widget
7818 * Sets @widget as one of the action widgets. Depending on the pack type
7819 * the widget will be placed before or after the tabs. You can use
7820 * a #GtkBox if you need to pack more than one widget on the same side.
7822 * Note that action widgets are "internal" children of the notebook and thus
7823 * not included in the list returned from gtk_container_foreach().
7828 gtk_notebook_set_action_widget (GtkNotebook *notebook,
7830 GtkPackType pack_type)
7832 GtkNotebookPrivate *priv;
7834 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7835 g_return_if_fail (!widget || GTK_IS_WIDGET (widget));
7836 g_return_if_fail (!widget || gtk_widget_get_parent (widget) == NULL);
7838 priv = notebook->priv;
7840 if (priv->action_widget[pack_type])
7841 gtk_widget_unparent (priv->action_widget[pack_type]);
7843 priv->action_widget[pack_type] = widget;
7847 gtk_widget_set_child_visible (widget, priv->show_tabs);
7848 gtk_widget_set_parent (widget, GTK_WIDGET (notebook));
7851 gtk_widget_queue_resize (GTK_WIDGET (notebook));