1 /* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
2 /* GTK - The GIMP Toolkit
3 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
23 * file for a list of people on the GTK+ Team. See the ChangeLog
24 * files for a list of changes. These files are distributed with
25 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
33 #include <gdk/gdkkeysyms.h>
35 #undef GTK_DISABLE_DEPRECATED
37 #include "gtknotebook.h"
40 #include "gtkmenuitem.h"
43 #include "gtkmarshalers.h"
44 #include "gtkbindings.h"
45 #include "gtkprivate.h"
47 #include "gtkbuildable.h"
51 #define SCROLL_DELAY_FACTOR 5
52 #define SCROLL_THRESHOLD 12
53 #define DND_THRESHOLD_MULTIPLIER 4
54 #define FRAMES_PER_SECOND 45
55 #define MSECS_BETWEEN_UPDATES (1000 / FRAMES_PER_SECOND)
90 } GtkNotebookPointerPosition;
95 DRAG_OPERATION_REORDER,
97 } GtkNotebookDragOperation;
99 #define ARROW_IS_LEFT(arrow) ((arrow) == ARROW_LEFT_BEFORE || (arrow) == ARROW_LEFT_AFTER)
100 #define ARROW_IS_BEFORE(arrow) ((arrow) == ARROW_LEFT_BEFORE || (arrow) == ARROW_RIGHT_BEFORE)
120 CHILD_PROP_TAB_LABEL,
121 CHILD_PROP_MENU_LABEL,
123 CHILD_PROP_TAB_EXPAND,
126 CHILD_PROP_REORDERABLE,
127 CHILD_PROP_DETACHABLE
130 #define GTK_NOTEBOOK_PAGE(_glist_) ((GtkNotebookPage *)((GList *)(_glist_))->data)
132 /* some useful defines for calculating coords */
133 #define PAGE_LEFT_X(_page_) (((GtkNotebookPage *) (_page_))->allocation.x)
134 #define PAGE_RIGHT_X(_page_) (((GtkNotebookPage *) (_page_))->allocation.x + ((GtkNotebookPage *) (_page_))->allocation.width)
135 #define PAGE_MIDDLE_X(_page_) (((GtkNotebookPage *) (_page_))->allocation.x + ((GtkNotebookPage *) (_page_))->allocation.width / 2)
136 #define PAGE_TOP_Y(_page_) (((GtkNotebookPage *) (_page_))->allocation.y)
137 #define PAGE_BOTTOM_Y(_page_) (((GtkNotebookPage *) (_page_))->allocation.y + ((GtkNotebookPage *) (_page_))->allocation.height)
138 #define PAGE_MIDDLE_Y(_page_) (((GtkNotebookPage *) (_page_))->allocation.y + ((GtkNotebookPage *) (_page_))->allocation.height / 2)
139 #define NOTEBOOK_IS_TAB_LABEL_PARENT(_notebook_,_page_) (((GtkNotebookPage *) (_page_))->tab_label->parent == ((GtkWidget *) (_notebook_)))
141 struct _GtkNotebookPage
144 GtkWidget *tab_label;
145 GtkWidget *menu_label;
146 GtkWidget *last_focus_child; /* Last descendant of the page that had focus */
148 guint default_menu : 1; /* If true, we create the menu label ourself */
149 guint default_tab : 1; /* If true, we create the tab label ourself */
153 guint reorderable : 1;
154 guint detachable : 1;
156 GtkRequisition requisition;
157 GtkAllocation allocation;
159 gulong mnemonic_activate_signal;
160 gulong notify_visible_handler;
163 #define GTK_NOTEBOOK_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_NOTEBOOK, GtkNotebookPrivate))
165 typedef struct _GtkNotebookPrivate GtkNotebookPrivate;
167 struct _GtkNotebookPrivate
174 guint switch_tab_timer;
182 GtkWidget *dnd_window;
183 GtkTargetList *source_targets;
184 GtkNotebookDragOperation operation;
185 GdkWindow *drag_window;
188 GtkNotebookPage *detached_tab;
192 guint during_reorder : 1;
193 guint during_detach : 1;
194 guint has_scrolled : 1;
197 static const GtkTargetEntry notebook_targets [] = {
198 { "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, 0 },
201 #ifdef G_DISABLE_CHECKS
202 #define CHECK_FIND_CHILD(notebook, child) \
203 gtk_notebook_find_child (notebook, child, G_STRLOC)
205 #define CHECK_FIND_CHILD(notebook, child) \
206 gtk_notebook_find_child (notebook, child, NULL)
209 /*** GtkNotebook Methods ***/
210 static gboolean gtk_notebook_select_page (GtkNotebook *notebook,
211 gboolean move_focus);
212 static gboolean gtk_notebook_focus_tab (GtkNotebook *notebook,
213 GtkNotebookTab type);
214 static gboolean gtk_notebook_change_current_page (GtkNotebook *notebook,
216 static void gtk_notebook_move_focus_out (GtkNotebook *notebook,
217 GtkDirectionType direction_type);
218 static gboolean gtk_notebook_reorder_tab (GtkNotebook *notebook,
219 GtkDirectionType direction_type,
220 gboolean move_to_last);
221 static void gtk_notebook_remove_tab_label (GtkNotebook *notebook,
222 GtkNotebookPage *page);
224 /*** GtkObject Methods ***/
225 static void gtk_notebook_destroy (GtkObject *object);
226 static void gtk_notebook_set_property (GObject *object,
230 static void gtk_notebook_get_property (GObject *object,
235 /*** GtkWidget Methods ***/
236 static void gtk_notebook_map (GtkWidget *widget);
237 static void gtk_notebook_unmap (GtkWidget *widget);
238 static void gtk_notebook_realize (GtkWidget *widget);
239 static void gtk_notebook_unrealize (GtkWidget *widget);
240 static void gtk_notebook_size_request (GtkWidget *widget,
241 GtkRequisition *requisition);
242 static void gtk_notebook_size_allocate (GtkWidget *widget,
243 GtkAllocation *allocation);
244 static gint gtk_notebook_expose (GtkWidget *widget,
245 GdkEventExpose *event);
246 static gboolean gtk_notebook_scroll (GtkWidget *widget,
247 GdkEventScroll *event);
248 static gint gtk_notebook_button_press (GtkWidget *widget,
249 GdkEventButton *event);
250 static gint gtk_notebook_button_release (GtkWidget *widget,
251 GdkEventButton *event);
252 static gboolean gtk_notebook_popup_menu (GtkWidget *widget);
253 static gint gtk_notebook_leave_notify (GtkWidget *widget,
254 GdkEventCrossing *event);
255 static gint gtk_notebook_motion_notify (GtkWidget *widget,
256 GdkEventMotion *event);
257 static gint gtk_notebook_focus_in (GtkWidget *widget,
258 GdkEventFocus *event);
259 static gint gtk_notebook_focus_out (GtkWidget *widget,
260 GdkEventFocus *event);
261 static void gtk_notebook_grab_notify (GtkWidget *widget,
262 gboolean was_grabbed);
263 static void gtk_notebook_state_changed (GtkWidget *widget,
264 GtkStateType previous_state);
265 static void gtk_notebook_draw_focus (GtkWidget *widget,
266 GdkEventExpose *event);
267 static gint gtk_notebook_focus (GtkWidget *widget,
268 GtkDirectionType direction);
269 static void gtk_notebook_style_set (GtkWidget *widget,
272 /*** Drag and drop Methods ***/
273 static void gtk_notebook_drag_begin (GtkWidget *widget,
274 GdkDragContext *context);
275 static void gtk_notebook_drag_end (GtkWidget *widget,
276 GdkDragContext *context);
277 static gboolean gtk_notebook_drag_failed (GtkWidget *widget,
278 GdkDragContext *context,
279 GtkDragResult result,
281 static gboolean gtk_notebook_drag_motion (GtkWidget *widget,
282 GdkDragContext *context,
286 static void gtk_notebook_drag_leave (GtkWidget *widget,
287 GdkDragContext *context,
289 static gboolean gtk_notebook_drag_drop (GtkWidget *widget,
290 GdkDragContext *context,
294 static void gtk_notebook_drag_data_get (GtkWidget *widget,
295 GdkDragContext *context,
296 GtkSelectionData *data,
299 static void gtk_notebook_drag_data_received (GtkWidget *widget,
300 GdkDragContext *context,
303 GtkSelectionData *data,
307 /*** GtkContainer Methods ***/
308 static void gtk_notebook_set_child_property (GtkContainer *container,
313 static void gtk_notebook_get_child_property (GtkContainer *container,
318 static void gtk_notebook_add (GtkContainer *container,
320 static void gtk_notebook_remove (GtkContainer *container,
322 static void gtk_notebook_set_focus_child (GtkContainer *container,
324 static GType gtk_notebook_child_type (GtkContainer *container);
325 static void gtk_notebook_forall (GtkContainer *container,
326 gboolean include_internals,
327 GtkCallback callback,
328 gpointer callback_data);
330 /*** GtkNotebook Methods ***/
331 static gint gtk_notebook_real_insert_page (GtkNotebook *notebook,
333 GtkWidget *tab_label,
334 GtkWidget *menu_label,
337 static GtkNotebook *gtk_notebook_create_window (GtkNotebook *notebook,
342 /*** GtkNotebook Private Functions ***/
343 static void gtk_notebook_redraw_tabs (GtkNotebook *notebook);
344 static void gtk_notebook_redraw_arrows (GtkNotebook *notebook);
345 static void gtk_notebook_real_remove (GtkNotebook *notebook,
347 static void gtk_notebook_update_labels (GtkNotebook *notebook);
348 static gint gtk_notebook_timer (GtkNotebook *notebook);
349 static void gtk_notebook_set_scroll_timer (GtkNotebook *notebook);
350 static gint gtk_notebook_page_compare (gconstpointer a,
352 static GList* gtk_notebook_find_child (GtkNotebook *notebook,
354 const gchar *function);
355 static gint gtk_notebook_real_page_position (GtkNotebook *notebook,
357 static GList * gtk_notebook_search_page (GtkNotebook *notebook,
360 gboolean find_visible);
361 static void gtk_notebook_child_reordered (GtkNotebook *notebook,
362 GtkNotebookPage *page);
364 /*** GtkNotebook Drawing Functions ***/
365 static void gtk_notebook_paint (GtkWidget *widget,
367 static void gtk_notebook_draw_tab (GtkNotebook *notebook,
368 GtkNotebookPage *page,
370 static void gtk_notebook_draw_arrow (GtkNotebook *notebook,
371 GtkNotebookArrow arrow);
373 /*** GtkNotebook Size Allocate Functions ***/
374 static void gtk_notebook_pages_allocate (GtkNotebook *notebook);
375 static gboolean gtk_notebook_page_allocate (GtkNotebook *notebook,
376 GtkNotebookPage *page);
377 static void gtk_notebook_calc_tabs (GtkNotebook *notebook,
383 /*** GtkNotebook Page Switch Methods ***/
384 static void gtk_notebook_real_switch_page (GtkNotebook *notebook,
385 GtkNotebookPage *page,
388 /*** GtkNotebook Page Switch Functions ***/
389 static void gtk_notebook_switch_page (GtkNotebook *notebook,
390 GtkNotebookPage *page);
391 static gint gtk_notebook_page_select (GtkNotebook *notebook,
392 gboolean move_focus);
393 static void gtk_notebook_switch_focus_tab (GtkNotebook *notebook,
395 static void gtk_notebook_menu_switch_page (GtkWidget *widget,
396 GtkNotebookPage *page);
398 /*** GtkNotebook Menu Functions ***/
399 static void gtk_notebook_menu_item_create (GtkNotebook *notebook,
401 static void gtk_notebook_menu_label_unparent (GtkWidget *widget,
403 static void gtk_notebook_menu_detacher (GtkWidget *widget,
406 /*** GtkNotebook Private Setters ***/
407 static void gtk_notebook_set_homogeneous_tabs_internal (GtkNotebook *notebook,
408 gboolean homogeneous);
409 static void gtk_notebook_set_tab_border_internal (GtkNotebook *notebook,
411 static void gtk_notebook_set_tab_hborder_internal (GtkNotebook *notebook,
413 static void gtk_notebook_set_tab_vborder_internal (GtkNotebook *notebook,
416 static void gtk_notebook_update_tab_states (GtkNotebook *notebook);
417 static gboolean gtk_notebook_mnemonic_activate_switch_page (GtkWidget *child,
421 static gboolean focus_tabs_in (GtkNotebook *notebook);
422 static gboolean focus_child_in (GtkNotebook *notebook,
423 GtkDirectionType direction);
425 static void stop_scrolling (GtkNotebook *notebook);
426 static void do_detach_tab (GtkNotebook *from,
433 static void gtk_notebook_buildable_init (GtkBuildableIface *iface);
434 static void gtk_notebook_buildable_add_child (GtkBuildable *buildable,
439 static GtkNotebookWindowCreationFunc window_creation_hook = NULL;
440 static gpointer window_creation_hook_data;
441 static GDestroyNotify window_creation_hook_destroy = NULL;
443 static guint notebook_signals[LAST_SIGNAL] = { 0 };
445 G_DEFINE_TYPE_WITH_CODE (GtkNotebook, gtk_notebook, GTK_TYPE_CONTAINER,
446 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
447 gtk_notebook_buildable_init))
450 add_tab_bindings (GtkBindingSet *binding_set,
451 GdkModifierType modifiers,
452 GtkDirectionType direction)
454 gtk_binding_entry_add_signal (binding_set, GDK_Tab, modifiers,
456 GTK_TYPE_DIRECTION_TYPE, direction);
457 gtk_binding_entry_add_signal (binding_set, GDK_KP_Tab, modifiers,
459 GTK_TYPE_DIRECTION_TYPE, direction);
463 add_arrow_bindings (GtkBindingSet *binding_set,
465 GtkDirectionType direction)
467 guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
469 gtk_binding_entry_add_signal (binding_set, keysym, GDK_CONTROL_MASK,
471 GTK_TYPE_DIRECTION_TYPE, direction);
472 gtk_binding_entry_add_signal (binding_set, keypad_keysym, GDK_CONTROL_MASK,
474 GTK_TYPE_DIRECTION_TYPE, direction);
478 add_reorder_bindings (GtkBindingSet *binding_set,
480 GtkDirectionType direction,
481 gboolean move_to_last)
483 guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
485 gtk_binding_entry_add_signal (binding_set, keysym, GDK_MOD1_MASK,
487 GTK_TYPE_DIRECTION_TYPE, direction,
488 G_TYPE_BOOLEAN, move_to_last);
489 gtk_binding_entry_add_signal (binding_set, keypad_keysym, GDK_MOD1_MASK,
491 GTK_TYPE_DIRECTION_TYPE, direction,
492 G_TYPE_BOOLEAN, move_to_last);
496 gtk_object_handled_accumulator (GSignalInvocationHint *ihint,
498 const GValue *handler_return,
501 gboolean continue_emission;
504 object = g_value_get_object (handler_return);
505 g_value_set_object (return_accu, object);
506 continue_emission = !object;
508 return continue_emission;
512 gtk_notebook_class_init (GtkNotebookClass *class)
514 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
515 GtkObjectClass *object_class = GTK_OBJECT_CLASS (class);
516 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
517 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
518 GtkBindingSet *binding_set;
520 gobject_class->set_property = gtk_notebook_set_property;
521 gobject_class->get_property = gtk_notebook_get_property;
522 object_class->destroy = gtk_notebook_destroy;
524 widget_class->map = gtk_notebook_map;
525 widget_class->unmap = gtk_notebook_unmap;
526 widget_class->realize = gtk_notebook_realize;
527 widget_class->unrealize = gtk_notebook_unrealize;
528 widget_class->size_request = gtk_notebook_size_request;
529 widget_class->size_allocate = gtk_notebook_size_allocate;
530 widget_class->expose_event = gtk_notebook_expose;
531 widget_class->scroll_event = gtk_notebook_scroll;
532 widget_class->button_press_event = gtk_notebook_button_press;
533 widget_class->button_release_event = gtk_notebook_button_release;
534 widget_class->popup_menu = gtk_notebook_popup_menu;
535 widget_class->leave_notify_event = gtk_notebook_leave_notify;
536 widget_class->motion_notify_event = gtk_notebook_motion_notify;
537 widget_class->grab_notify = gtk_notebook_grab_notify;
538 widget_class->state_changed = gtk_notebook_state_changed;
539 widget_class->focus_in_event = gtk_notebook_focus_in;
540 widget_class->focus_out_event = gtk_notebook_focus_out;
541 widget_class->focus = gtk_notebook_focus;
542 widget_class->style_set = gtk_notebook_style_set;
543 widget_class->drag_begin = gtk_notebook_drag_begin;
544 widget_class->drag_end = gtk_notebook_drag_end;
545 widget_class->drag_motion = gtk_notebook_drag_motion;
546 widget_class->drag_leave = gtk_notebook_drag_leave;
547 widget_class->drag_drop = gtk_notebook_drag_drop;
548 widget_class->drag_data_get = gtk_notebook_drag_data_get;
549 widget_class->drag_data_received = gtk_notebook_drag_data_received;
551 container_class->add = gtk_notebook_add;
552 container_class->remove = gtk_notebook_remove;
553 container_class->forall = gtk_notebook_forall;
554 container_class->set_focus_child = gtk_notebook_set_focus_child;
555 container_class->get_child_property = gtk_notebook_get_child_property;
556 container_class->set_child_property = gtk_notebook_set_child_property;
557 container_class->child_type = gtk_notebook_child_type;
559 class->switch_page = gtk_notebook_real_switch_page;
560 class->insert_page = gtk_notebook_real_insert_page;
562 class->focus_tab = gtk_notebook_focus_tab;
563 class->select_page = gtk_notebook_select_page;
564 class->change_current_page = gtk_notebook_change_current_page;
565 class->move_focus_out = gtk_notebook_move_focus_out;
566 class->reorder_tab = gtk_notebook_reorder_tab;
567 class->create_window = gtk_notebook_create_window;
569 g_object_class_install_property (gobject_class,
571 g_param_spec_int ("page",
573 P_("The index of the current page"),
577 GTK_PARAM_READWRITE));
578 g_object_class_install_property (gobject_class,
580 g_param_spec_enum ("tab-pos",
582 P_("Which side of the notebook holds the tabs"),
583 GTK_TYPE_POSITION_TYPE,
585 GTK_PARAM_READWRITE));
586 g_object_class_install_property (gobject_class,
588 g_param_spec_uint ("tab-border",
590 P_("Width of the border around the tab labels"),
594 GTK_PARAM_WRITABLE));
595 g_object_class_install_property (gobject_class,
597 g_param_spec_uint ("tab-hborder",
598 P_("Horizontal Tab Border"),
599 P_("Width of the horizontal border of tab labels"),
603 GTK_PARAM_READWRITE));
604 g_object_class_install_property (gobject_class,
606 g_param_spec_uint ("tab-vborder",
607 P_("Vertical Tab Border"),
608 P_("Width of the vertical border of tab labels"),
612 GTK_PARAM_READWRITE));
613 g_object_class_install_property (gobject_class,
615 g_param_spec_boolean ("show-tabs",
617 P_("Whether tabs should be shown or not"),
619 GTK_PARAM_READWRITE));
620 g_object_class_install_property (gobject_class,
622 g_param_spec_boolean ("show-border",
624 P_("Whether the border should be shown or not"),
626 GTK_PARAM_READWRITE));
627 g_object_class_install_property (gobject_class,
629 g_param_spec_boolean ("scrollable",
631 P_("If TRUE, scroll arrows are added if there are too many tabs to fit"),
633 GTK_PARAM_READWRITE));
634 g_object_class_install_property (gobject_class,
636 g_param_spec_boolean ("enable-popup",
638 P_("If TRUE, pressing the right mouse button on the notebook pops up a menu that you can use to go to a page"),
640 GTK_PARAM_READWRITE));
641 g_object_class_install_property (gobject_class,
643 g_param_spec_boolean ("homogeneous",
645 P_("Whether tabs should have homogeneous sizes"),
647 GTK_PARAM_READWRITE));
648 g_object_class_install_property (gobject_class,
650 g_param_spec_int ("group-id",
652 P_("Group ID for tabs drag and drop"),
656 GTK_PARAM_READWRITE));
661 * Group for tabs drag and drop.
665 g_object_class_install_property (gobject_class,
667 g_param_spec_pointer ("group",
669 P_("Group for tabs drag and drop"),
670 GTK_PARAM_READWRITE));
672 gtk_container_class_install_child_property (container_class,
673 CHILD_PROP_TAB_LABEL,
674 g_param_spec_string ("tab-label",
676 P_("The string displayed on the child's tab label"),
678 GTK_PARAM_READWRITE));
679 gtk_container_class_install_child_property (container_class,
680 CHILD_PROP_MENU_LABEL,
681 g_param_spec_string ("menu-label",
683 P_("The string displayed in the child's menu entry"),
685 GTK_PARAM_READWRITE));
686 gtk_container_class_install_child_property (container_class,
688 g_param_spec_int ("position",
690 P_("The index of the child in the parent"),
692 GTK_PARAM_READWRITE));
693 gtk_container_class_install_child_property (container_class,
694 CHILD_PROP_TAB_EXPAND,
695 g_param_spec_boolean ("tab-expand",
697 P_("Whether to expand the child's tab or not"),
699 GTK_PARAM_READWRITE));
700 gtk_container_class_install_child_property (container_class,
702 g_param_spec_boolean ("tab-fill",
704 P_("Whether the child's tab should fill the allocated area or not"),
706 GTK_PARAM_READWRITE));
707 gtk_container_class_install_child_property (container_class,
709 g_param_spec_enum ("tab-pack",
711 P_("A GtkPackType indicating whether the child is packed with reference to the start or end of the parent"),
712 GTK_TYPE_PACK_TYPE, GTK_PACK_START,
713 GTK_PARAM_READWRITE));
714 gtk_container_class_install_child_property (container_class,
715 CHILD_PROP_REORDERABLE,
716 g_param_spec_boolean ("reorderable",
717 P_("Tab reorderable"),
718 P_("Whether the tab is reorderable by user action or not"),
720 GTK_PARAM_READWRITE));
721 gtk_container_class_install_child_property (container_class,
722 CHILD_PROP_DETACHABLE,
723 g_param_spec_boolean ("detachable",
724 P_("Tab detachable"),
725 P_("Whether the tab is detachable"),
727 GTK_PARAM_READWRITE));
730 * GtkNotebook:has-secondary-backward-stepper:
732 * The "has-secondary-backward-stepper" property determines whether
733 * a second backward arrow button is displayed on the opposite end
738 gtk_widget_class_install_style_property (widget_class,
739 g_param_spec_boolean ("has-secondary-backward-stepper",
740 P_("Secondary backward stepper"),
741 P_("Display a second backward arrow button on the opposite end of the tab area"),
743 GTK_PARAM_READABLE));
746 * GtkNotebook:has-secondary-forward-stepper:
748 * The "has-secondary-forward-stepper" property determines whether
749 * a second forward arrow button is displayed on the opposite end
754 gtk_widget_class_install_style_property (widget_class,
755 g_param_spec_boolean ("has-secondary-forward-stepper",
756 P_("Secondary forward stepper"),
757 P_("Display a second forward arrow button on the opposite end of the tab area"),
759 GTK_PARAM_READABLE));
762 * GtkNotebook:has-backward-stepper:
764 * The "has-backward-stepper" property determines whether
765 * the standard backward arrow button is displayed.
769 gtk_widget_class_install_style_property (widget_class,
770 g_param_spec_boolean ("has-backward-stepper",
771 P_("Backward stepper"),
772 P_("Display the standard backward arrow button"),
774 GTK_PARAM_READABLE));
777 * GtkNotebook:has-forward-stepper:
779 * The "has-forward-stepper" property determines whether
780 * the standard forward arrow button is displayed.
784 gtk_widget_class_install_style_property (widget_class,
785 g_param_spec_boolean ("has-forward-stepper",
786 P_("Forward stepper"),
787 P_("Display the standard forward arrow button"),
789 GTK_PARAM_READABLE));
792 * GtkNotebook:tab-overlap:
794 * The "tab-overlap" property defines size of tab overlap
799 gtk_widget_class_install_style_property (widget_class,
800 g_param_spec_int ("tab-overlap",
802 P_("Size of tab overlap area"),
806 GTK_PARAM_READABLE));
809 * GtkNotebook:tab-curvature:
811 * The "tab-curvature" property defines size of tab curvature.
815 gtk_widget_class_install_style_property (widget_class,
816 g_param_spec_int ("tab-curvature",
818 P_("Size of tab curvature"),
822 GTK_PARAM_READABLE));
825 * GtkNotebook:arrow-spacing:
827 * The "arrow-spacing" property defines the spacing between the scroll
828 * arrows and the tabs.
832 gtk_widget_class_install_style_property (widget_class,
833 g_param_spec_int ("arrow-spacing",
835 P_("Scroll arrow spacing"),
839 GTK_PARAM_READABLE));
841 notebook_signals[SWITCH_PAGE] =
842 g_signal_new (I_("switch-page"),
843 G_TYPE_FROM_CLASS (gobject_class),
845 G_STRUCT_OFFSET (GtkNotebookClass, switch_page),
847 _gtk_marshal_VOID__POINTER_UINT,
851 notebook_signals[FOCUS_TAB] =
852 g_signal_new (I_("focus-tab"),
853 G_TYPE_FROM_CLASS (gobject_class),
854 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
855 G_STRUCT_OFFSET (GtkNotebookClass, focus_tab),
857 _gtk_marshal_BOOLEAN__ENUM,
859 GTK_TYPE_NOTEBOOK_TAB);
860 notebook_signals[SELECT_PAGE] =
861 g_signal_new (I_("select-page"),
862 G_TYPE_FROM_CLASS (gobject_class),
863 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
864 G_STRUCT_OFFSET (GtkNotebookClass, select_page),
866 _gtk_marshal_BOOLEAN__BOOLEAN,
869 notebook_signals[CHANGE_CURRENT_PAGE] =
870 g_signal_new (I_("change-current-page"),
871 G_TYPE_FROM_CLASS (gobject_class),
872 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
873 G_STRUCT_OFFSET (GtkNotebookClass, change_current_page),
875 _gtk_marshal_BOOLEAN__INT,
878 notebook_signals[MOVE_FOCUS_OUT] =
879 g_signal_new (I_("move-focus-out"),
880 G_TYPE_FROM_CLASS (gobject_class),
881 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
882 G_STRUCT_OFFSET (GtkNotebookClass, move_focus_out),
884 _gtk_marshal_VOID__ENUM,
886 GTK_TYPE_DIRECTION_TYPE);
887 notebook_signals[REORDER_TAB] =
888 g_signal_new (I_("reorder-tab"),
889 G_TYPE_FROM_CLASS (gobject_class),
890 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
891 G_STRUCT_OFFSET (GtkNotebookClass, reorder_tab),
893 _gtk_marshal_BOOLEAN__ENUM_BOOLEAN,
895 GTK_TYPE_DIRECTION_TYPE,
898 * GtkNotebook::page-reordered:
899 * @notebook: the #GtkNotebook
900 * @child: the child #GtkWidget affected
901 * @page_num: the new page number for @child
903 * the ::page-reordered signal is emitted in the notebook
904 * right after a page has been reordered.
908 notebook_signals[PAGE_REORDERED] =
909 g_signal_new (I_("page-reordered"),
910 G_TYPE_FROM_CLASS (gobject_class),
913 _gtk_marshal_VOID__OBJECT_UINT,
918 * GtkNotebook::page-removed:
919 * @notebook: the #GtkNotebook
920 * @child: the child #GtkWidget affected
921 * @page_num: the @child page number
923 * the ::page-removed signal is emitted in the notebook
924 * right after a page is removed from the notebook.
928 notebook_signals[PAGE_REMOVED] =
929 g_signal_new (I_("page-removed"),
930 G_TYPE_FROM_CLASS (gobject_class),
933 _gtk_marshal_VOID__OBJECT_UINT,
938 * GtkNotebook::page-added:
939 * @notebook: the #GtkNotebook
940 * @child: the child #GtkWidget affected
941 * @page_num: the new page number for @child
943 * the ::page-added signal is emitted in the notebook
944 * right after a page is added to the notebook.
948 notebook_signals[PAGE_ADDED] =
949 g_signal_new (I_("page-added"),
950 G_TYPE_FROM_CLASS (gobject_class),
953 _gtk_marshal_VOID__OBJECT_UINT,
959 * GtkNotebook::create-window:
960 * @notebook: the #GtkNotebook emitting the signal
961 * @page: the tab of @notebook that is being detached
962 * @x: the X coordinate where the drop happens
963 * @y: the Y coordinate where the drop happens
965 * The ::create-window signal is emitted when a detachable
966 * tab is dropped on the root window.
968 * A handler for this signal can create a window containing
969 * a notebook where the tab will be attached. It is also
970 * responsible for moving/resizing the window and adding the
971 * necessary properties to the notebook (e.g. the
972 * #GtkNotebook:group-id ).
974 * The default handler uses the global window creation hook,
975 * if one has been set with gtk_notebook_set_window_creation_hook().
977 * Returns: a #GtkNotebook that @page should be added to, or %NULL.
981 notebook_signals[CREATE_WINDOW] =
982 g_signal_new (I_("create-window"),
983 G_TYPE_FROM_CLASS (gobject_class),
985 G_STRUCT_OFFSET (GtkNotebookClass, create_window),
986 gtk_object_handled_accumulator, NULL,
987 _gtk_marshal_OBJECT__OBJECT_INT_INT,
988 GTK_TYPE_NOTEBOOK, 3,
989 GTK_TYPE_WIDGET, G_TYPE_INT, G_TYPE_INT);
991 binding_set = gtk_binding_set_by_class (class);
992 gtk_binding_entry_add_signal (binding_set,
995 G_TYPE_BOOLEAN, FALSE);
996 gtk_binding_entry_add_signal (binding_set,
999 G_TYPE_BOOLEAN, FALSE);
1001 gtk_binding_entry_add_signal (binding_set,
1004 GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_FIRST);
1005 gtk_binding_entry_add_signal (binding_set,
1008 GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_FIRST);
1009 gtk_binding_entry_add_signal (binding_set,
1012 GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_LAST);
1013 gtk_binding_entry_add_signal (binding_set,
1016 GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_LAST);
1018 gtk_binding_entry_add_signal (binding_set,
1019 GDK_Page_Up, GDK_CONTROL_MASK,
1020 "change-current-page", 1,
1022 gtk_binding_entry_add_signal (binding_set,
1023 GDK_Page_Down, GDK_CONTROL_MASK,
1024 "change-current-page", 1,
1027 gtk_binding_entry_add_signal (binding_set,
1028 GDK_Page_Up, GDK_CONTROL_MASK | GDK_MOD1_MASK,
1029 "change-current-page", 1,
1031 gtk_binding_entry_add_signal (binding_set,
1032 GDK_Page_Down, GDK_CONTROL_MASK | GDK_MOD1_MASK,
1033 "change-current-page", 1,
1036 add_arrow_bindings (binding_set, GDK_Up, GTK_DIR_UP);
1037 add_arrow_bindings (binding_set, GDK_Down, GTK_DIR_DOWN);
1038 add_arrow_bindings (binding_set, GDK_Left, GTK_DIR_LEFT);
1039 add_arrow_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT);
1041 add_reorder_bindings (binding_set, GDK_Up, GTK_DIR_UP, FALSE);
1042 add_reorder_bindings (binding_set, GDK_Down, GTK_DIR_DOWN, FALSE);
1043 add_reorder_bindings (binding_set, GDK_Left, GTK_DIR_LEFT, FALSE);
1044 add_reorder_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT, FALSE);
1045 add_reorder_bindings (binding_set, GDK_Home, GTK_DIR_LEFT, TRUE);
1046 add_reorder_bindings (binding_set, GDK_Home, GTK_DIR_UP, TRUE);
1047 add_reorder_bindings (binding_set, GDK_End, GTK_DIR_RIGHT, TRUE);
1048 add_reorder_bindings (binding_set, GDK_End, GTK_DIR_DOWN, TRUE);
1050 add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
1051 add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
1053 g_type_class_add_private (class, sizeof (GtkNotebookPrivate));
1057 gtk_notebook_init (GtkNotebook *notebook)
1059 GtkNotebookPrivate *priv;
1061 GTK_WIDGET_SET_FLAGS (notebook, GTK_CAN_FOCUS);
1062 GTK_WIDGET_SET_FLAGS (notebook, GTK_NO_WINDOW);
1064 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
1066 notebook->cur_page = NULL;
1067 notebook->children = NULL;
1068 notebook->first_tab = NULL;
1069 notebook->focus_tab = NULL;
1070 notebook->event_window = NULL;
1071 notebook->menu = NULL;
1073 notebook->tab_hborder = 2;
1074 notebook->tab_vborder = 2;
1076 notebook->show_tabs = TRUE;
1077 notebook->show_border = TRUE;
1078 notebook->tab_pos = GTK_POS_TOP;
1079 notebook->scrollable = FALSE;
1080 notebook->in_child = 0;
1081 notebook->click_child = 0;
1082 notebook->button = 0;
1083 notebook->need_timer = 0;
1084 notebook->child_has_focus = FALSE;
1085 notebook->have_visible_child = FALSE;
1086 notebook->focus_out = FALSE;
1088 notebook->has_before_previous = 1;
1089 notebook->has_before_next = 0;
1090 notebook->has_after_previous = 0;
1091 notebook->has_after_next = 1;
1094 priv->pressed_button = -1;
1095 priv->dnd_timer = 0;
1096 priv->switch_tab_timer = 0;
1097 priv->source_targets = gtk_target_list_new (notebook_targets,
1098 G_N_ELEMENTS (notebook_targets));
1099 priv->operation = DRAG_OPERATION_NONE;
1100 priv->detached_tab = NULL;
1101 priv->during_detach = FALSE;
1102 priv->has_scrolled = FALSE;
1104 gtk_drag_dest_set (GTK_WIDGET (notebook), 0,
1105 notebook_targets, G_N_ELEMENTS (notebook_targets),
1108 g_signal_connect (G_OBJECT (notebook), "drag-failed",
1109 G_CALLBACK (gtk_notebook_drag_failed), NULL);
1111 gtk_drag_dest_set_track_motion (GTK_WIDGET (notebook), TRUE);
1115 gtk_notebook_buildable_init (GtkBuildableIface *iface)
1117 iface->add_child = gtk_notebook_buildable_add_child;
1121 gtk_notebook_buildable_add_child (GtkBuildable *buildable,
1122 GtkBuilder *builder,
1126 GtkNotebook *notebook = GTK_NOTEBOOK (buildable);
1128 if (type && strcmp (type, "tab") == 0)
1132 page = gtk_notebook_get_nth_page (notebook, -1);
1133 /* To set the tab label widget, we must have already a child
1134 * inside the tab container. */
1135 g_assert (page != NULL);
1136 gtk_notebook_set_tab_label (notebook, page, GTK_WIDGET (child));
1139 gtk_notebook_append_page (notebook, GTK_WIDGET (child), NULL);
1141 GTK_BUILDER_WARN_INVALID_CHILD_TYPE (notebook, type);
1145 gtk_notebook_select_page (GtkNotebook *notebook,
1146 gboolean move_focus)
1148 if (gtk_widget_is_focus (GTK_WIDGET (notebook)) && notebook->show_tabs)
1150 gtk_notebook_page_select (notebook, move_focus);
1158 gtk_notebook_focus_tab (GtkNotebook *notebook,
1159 GtkNotebookTab type)
1163 if (gtk_widget_is_focus (GTK_WIDGET (notebook)) && notebook->show_tabs)
1167 case GTK_NOTEBOOK_TAB_FIRST:
1168 list = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, TRUE);
1170 gtk_notebook_switch_focus_tab (notebook, list);
1172 case GTK_NOTEBOOK_TAB_LAST:
1173 list = gtk_notebook_search_page (notebook, NULL, STEP_PREV, TRUE);
1175 gtk_notebook_switch_focus_tab (notebook, list);
1186 gtk_notebook_change_current_page (GtkNotebook *notebook,
1189 GList *current = NULL;
1191 if (!notebook->show_tabs)
1194 if (notebook->cur_page)
1195 current = g_list_find (notebook->children, notebook->cur_page);
1199 current = gtk_notebook_search_page (notebook, current,
1200 offset < 0 ? STEP_PREV : STEP_NEXT,
1205 gboolean wrap_around;
1207 g_object_get (gtk_widget_get_settings (GTK_WIDGET (notebook)),
1208 "gtk-keynav-wrap-around", &wrap_around,
1212 current = gtk_notebook_search_page (notebook, NULL,
1213 offset < 0 ? STEP_PREV : STEP_NEXT,
1219 offset += offset < 0 ? 1 : -1;
1223 gtk_notebook_switch_page (notebook, current->data);
1225 gtk_widget_error_bell (GTK_WIDGET (notebook));
1230 static GtkDirectionType
1231 get_effective_direction (GtkNotebook *notebook,
1232 GtkDirectionType direction)
1234 /* Remap the directions into the effective direction it would be for a
1235 * GTK_POS_TOP notebook
1238 #define D(rest) GTK_DIR_##rest
1240 static const GtkDirectionType translate_direction[2][4][6] = {
1241 /* LEFT */ {{ D(TAB_FORWARD), D(TAB_BACKWARD), D(LEFT), D(RIGHT), D(UP), D(DOWN) },
1242 /* RIGHT */ { D(TAB_BACKWARD), D(TAB_FORWARD), D(LEFT), D(RIGHT), D(DOWN), D(UP) },
1243 /* TOP */ { D(TAB_FORWARD), D(TAB_BACKWARD), D(UP), D(DOWN), D(LEFT), D(RIGHT) },
1244 /* BOTTOM */ { D(TAB_BACKWARD), D(TAB_FORWARD), D(DOWN), D(UP), D(LEFT), D(RIGHT) }},
1245 /* LEFT */ {{ D(TAB_BACKWARD), D(TAB_FORWARD), D(LEFT), D(RIGHT), D(DOWN), D(UP) },
1246 /* RIGHT */ { D(TAB_FORWARD), D(TAB_BACKWARD), D(LEFT), D(RIGHT), D(UP), D(DOWN) },
1247 /* TOP */ { D(TAB_FORWARD), D(TAB_BACKWARD), D(UP), D(DOWN), D(RIGHT), D(LEFT) },
1248 /* BOTTOM */ { D(TAB_BACKWARD), D(TAB_FORWARD), D(DOWN), D(UP), D(RIGHT), D(LEFT) }},
1253 int text_dir = gtk_widget_get_direction (GTK_WIDGET (notebook)) == GTK_TEXT_DIR_RTL ? 1 : 0;
1255 return translate_direction[text_dir][notebook->tab_pos][direction];
1259 get_effective_tab_pos (GtkNotebook *notebook)
1261 if (gtk_widget_get_direction (GTK_WIDGET (notebook)) == GTK_TEXT_DIR_RTL)
1263 switch (notebook->tab_pos)
1266 return GTK_POS_RIGHT;
1268 return GTK_POS_LEFT;
1273 return notebook->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 GtkDirectionType effective_direction = get_effective_direction (notebook, direction_type);
1306 GtkWidget *toplevel;
1308 if (GTK_CONTAINER (notebook)->focus_child && effective_direction == GTK_DIR_UP)
1309 if (focus_tabs_in (notebook))
1311 if (gtk_widget_is_focus (GTK_WIDGET (notebook)) && effective_direction == GTK_DIR_DOWN)
1312 if (focus_child_in (notebook, GTK_DIR_TAB_FORWARD))
1315 /* At this point, we know we should be focusing out of the notebook entirely. We
1316 * do this by setting a flag, then propagating the focus motion to the notebook.
1318 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (notebook));
1319 if (!GTK_WIDGET_TOPLEVEL (toplevel))
1322 g_object_ref (notebook);
1324 notebook->focus_out = TRUE;
1325 g_signal_emit_by_name (toplevel, "move-focus", direction_type);
1326 notebook->focus_out = FALSE;
1328 g_object_unref (notebook);
1332 reorder_tab (GtkNotebook *notebook, GList *position, GList *tab)
1336 if (position == tab)
1337 return g_list_position (notebook->children, tab);
1339 /* check that we aren't inserting the tab in the
1340 * same relative position, taking packing into account */
1341 elem = (position) ? position->prev : g_list_last (notebook->children);
1343 while (elem && elem != tab && GTK_NOTEBOOK_PAGE (elem)->pack != GTK_NOTEBOOK_PAGE (tab)->pack)
1347 return g_list_position (notebook->children, tab);
1349 /* now actually reorder the tab */
1350 if (notebook->first_tab == tab)
1351 notebook->first_tab = gtk_notebook_search_page (notebook, notebook->first_tab,
1354 notebook->children = g_list_remove_link (notebook->children, tab);
1357 elem = g_list_last (notebook->children);
1360 elem = position->prev;
1361 position->prev = tab;
1367 notebook->children = tab;
1370 tab->next = position;
1372 return g_list_position (notebook->children, tab);
1376 gtk_notebook_reorder_tab (GtkNotebook *notebook,
1377 GtkDirectionType direction_type,
1378 gboolean move_to_last)
1380 GtkDirectionType effective_direction = get_effective_direction (notebook, direction_type);
1381 GtkNotebookPage *page;
1382 GList *last, *child;
1385 if (!gtk_widget_is_focus (GTK_WIDGET (notebook)) || !notebook->show_tabs)
1388 if (!notebook->cur_page ||
1389 !notebook->cur_page->reorderable)
1392 if (effective_direction != GTK_DIR_LEFT &&
1393 effective_direction != GTK_DIR_RIGHT)
1398 child = notebook->focus_tab;
1403 child = gtk_notebook_search_page (notebook, last,
1404 (effective_direction == GTK_DIR_RIGHT) ? STEP_NEXT : STEP_PREV,
1407 while (child && GTK_NOTEBOOK_PAGE (last)->pack == GTK_NOTEBOOK_PAGE (child)->pack);
1412 child = gtk_notebook_search_page (notebook, notebook->focus_tab,
1413 (effective_direction == GTK_DIR_RIGHT) ? STEP_NEXT : STEP_PREV,
1416 if (!child || child->data == notebook->cur_page)
1421 if (page->pack == notebook->cur_page->pack)
1423 if (effective_direction == GTK_DIR_RIGHT)
1424 page_num = reorder_tab (notebook, (page->pack == GTK_PACK_START) ? child->next : child, notebook->focus_tab);
1426 page_num = reorder_tab (notebook, (page->pack == GTK_PACK_START) ? child : child->next, notebook->focus_tab);
1428 gtk_notebook_pages_allocate (notebook);
1430 g_signal_emit (notebook,
1431 notebook_signals[PAGE_REORDERED],
1433 ((GtkNotebookPage *) notebook->focus_tab->data)->child,
1445 * Creates a new #GtkNotebook widget with no pages.
1447 * Return value: the newly created #GtkNotebook
1450 gtk_notebook_new (void)
1452 return g_object_new (GTK_TYPE_NOTEBOOK, NULL);
1455 /* Private GtkObject Methods :
1457 * gtk_notebook_destroy
1458 * gtk_notebook_set_arg
1459 * gtk_notebook_get_arg
1462 gtk_notebook_destroy (GtkObject *object)
1464 GtkNotebook *notebook = GTK_NOTEBOOK (object);
1465 GtkNotebookPrivate *priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
1468 gtk_notebook_popup_disable (notebook);
1470 if (priv->source_targets)
1472 gtk_target_list_unref (priv->source_targets);
1473 priv->source_targets = NULL;
1476 if (priv->switch_tab_timer)
1478 g_source_remove (priv->switch_tab_timer);
1479 priv->switch_tab_timer = 0;
1482 GTK_OBJECT_CLASS (gtk_notebook_parent_class)->destroy (object);
1486 gtk_notebook_set_property (GObject *object,
1488 const GValue *value,
1491 GtkNotebook *notebook;
1493 notebook = GTK_NOTEBOOK (object);
1497 case PROP_SHOW_TABS:
1498 gtk_notebook_set_show_tabs (notebook, g_value_get_boolean (value));
1500 case PROP_SHOW_BORDER:
1501 gtk_notebook_set_show_border (notebook, g_value_get_boolean (value));
1503 case PROP_SCROLLABLE:
1504 gtk_notebook_set_scrollable (notebook, g_value_get_boolean (value));
1506 case PROP_ENABLE_POPUP:
1507 if (g_value_get_boolean (value))
1508 gtk_notebook_popup_enable (notebook);
1510 gtk_notebook_popup_disable (notebook);
1512 case PROP_HOMOGENEOUS:
1513 gtk_notebook_set_homogeneous_tabs_internal (notebook, g_value_get_boolean (value));
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_TAB_BORDER:
1522 gtk_notebook_set_tab_border_internal (notebook, g_value_get_uint (value));
1524 case PROP_TAB_HBORDER:
1525 gtk_notebook_set_tab_hborder_internal (notebook, g_value_get_uint (value));
1527 case PROP_TAB_VBORDER:
1528 gtk_notebook_set_tab_vborder_internal (notebook, g_value_get_uint (value));
1531 gtk_notebook_set_group_id (notebook, g_value_get_int (value));
1534 gtk_notebook_set_group (notebook, g_value_get_pointer (value));
1537 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1543 gtk_notebook_get_property (GObject *object,
1548 GtkNotebook *notebook;
1549 GtkNotebookPrivate *priv;
1551 notebook = GTK_NOTEBOOK (object);
1552 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
1556 case PROP_SHOW_TABS:
1557 g_value_set_boolean (value, notebook->show_tabs);
1559 case PROP_SHOW_BORDER:
1560 g_value_set_boolean (value, notebook->show_border);
1562 case PROP_SCROLLABLE:
1563 g_value_set_boolean (value, notebook->scrollable);
1565 case PROP_ENABLE_POPUP:
1566 g_value_set_boolean (value, notebook->menu != NULL);
1568 case PROP_HOMOGENEOUS:
1569 g_value_set_boolean (value, notebook->homogeneous);
1572 g_value_set_int (value, gtk_notebook_get_current_page (notebook));
1575 g_value_set_enum (value, notebook->tab_pos);
1577 case PROP_TAB_HBORDER:
1578 g_value_set_uint (value, notebook->tab_hborder);
1580 case PROP_TAB_VBORDER:
1581 g_value_set_uint (value, notebook->tab_vborder);
1584 g_value_set_int (value, gtk_notebook_get_group_id (notebook));
1587 g_value_set_pointer (value, priv->group);
1590 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1595 /* Private GtkWidget Methods :
1598 * gtk_notebook_unmap
1599 * gtk_notebook_realize
1600 * gtk_notebook_size_request
1601 * gtk_notebook_size_allocate
1602 * gtk_notebook_expose
1603 * gtk_notebook_scroll
1604 * gtk_notebook_button_press
1605 * gtk_notebook_button_release
1606 * gtk_notebook_popup_menu
1607 * gtk_notebook_leave_notify
1608 * gtk_notebook_motion_notify
1609 * gtk_notebook_focus_in
1610 * gtk_notebook_focus_out
1611 * gtk_notebook_draw_focus
1612 * gtk_notebook_style_set
1613 * gtk_notebook_drag_begin
1614 * gtk_notebook_drag_end
1615 * gtk_notebook_drag_failed
1616 * gtk_notebook_drag_motion
1617 * gtk_notebook_drag_drop
1618 * gtk_notebook_drag_data_get
1619 * gtk_notebook_drag_data_received
1622 gtk_notebook_get_event_window_position (GtkNotebook *notebook,
1623 GdkRectangle *rectangle)
1625 GtkWidget *widget = GTK_WIDGET (notebook);
1626 gint border_width = GTK_CONTAINER (notebook)->border_width;
1627 GtkNotebookPage *visible_page = NULL;
1629 gint tab_pos = get_effective_tab_pos (notebook);
1631 for (tmp_list = notebook->children; tmp_list; tmp_list = tmp_list->next)
1633 GtkNotebookPage *page = tmp_list->data;
1634 if (GTK_WIDGET_VISIBLE (page->child))
1636 visible_page = page;
1641 if (notebook->show_tabs && visible_page)
1645 rectangle->x = widget->allocation.x + border_width;
1646 rectangle->y = widget->allocation.y + border_width;
1651 case GTK_POS_BOTTOM:
1652 rectangle->width = widget->allocation.width - 2 * border_width;
1653 rectangle->height = visible_page->requisition.height;
1654 if (tab_pos == GTK_POS_BOTTOM)
1655 rectangle->y += widget->allocation.height - 2 * border_width - rectangle->height;
1659 rectangle->width = visible_page->requisition.width;
1660 rectangle->height = widget->allocation.height - 2 * border_width;
1661 if (tab_pos == GTK_POS_RIGHT)
1662 rectangle->x += widget->allocation.width - 2 * border_width - rectangle->width;
1673 rectangle->x = rectangle->y = 0;
1674 rectangle->width = rectangle->height = 10;
1682 gtk_notebook_map (GtkWidget *widget)
1684 GtkNotebook *notebook;
1685 GtkNotebookPage *page;
1688 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
1690 notebook = GTK_NOTEBOOK (widget);
1692 if (notebook->cur_page &&
1693 GTK_WIDGET_VISIBLE (notebook->cur_page->child) &&
1694 !GTK_WIDGET_MAPPED (notebook->cur_page->child))
1695 gtk_widget_map (notebook->cur_page->child);
1697 if (notebook->scrollable)
1698 gtk_notebook_pages_allocate (notebook);
1701 children = notebook->children;
1705 page = children->data;
1706 children = children->next;
1708 if (page->tab_label &&
1709 GTK_WIDGET_VISIBLE (page->tab_label) &&
1710 !GTK_WIDGET_MAPPED (page->tab_label))
1711 gtk_widget_map (page->tab_label);
1715 if (gtk_notebook_get_event_window_position (notebook, NULL))
1716 gdk_window_show_unraised (notebook->event_window);
1720 gtk_notebook_unmap (GtkWidget *widget)
1722 stop_scrolling (GTK_NOTEBOOK (widget));
1724 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
1726 gdk_window_hide (GTK_NOTEBOOK (widget)->event_window);
1728 GTK_WIDGET_CLASS (gtk_notebook_parent_class)->unmap (widget);
1732 gtk_notebook_realize (GtkWidget *widget)
1734 GtkNotebook *notebook;
1735 GdkWindowAttr attributes;
1736 gint attributes_mask;
1737 GdkRectangle event_window_pos;
1739 notebook = GTK_NOTEBOOK (widget);
1740 GTK_WIDGET_SET_FLAGS (notebook, GTK_REALIZED);
1742 gtk_notebook_get_event_window_position (notebook, &event_window_pos);
1744 widget->window = gtk_widget_get_parent_window (widget);
1745 g_object_ref (widget->window);
1747 attributes.window_type = GDK_WINDOW_CHILD;
1748 attributes.x = event_window_pos.x;
1749 attributes.y = event_window_pos.y;
1750 attributes.width = event_window_pos.width;
1751 attributes.height = event_window_pos.height;
1752 attributes.wclass = GDK_INPUT_ONLY;
1753 attributes.event_mask = gtk_widget_get_events (widget);
1754 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
1755 GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK |
1756 GDK_POINTER_MOTION_MASK | GDK_LEAVE_NOTIFY_MASK |
1758 attributes_mask = GDK_WA_X | GDK_WA_Y;
1760 notebook->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
1761 &attributes, attributes_mask);
1762 gdk_window_set_user_data (notebook->event_window, notebook);
1764 widget->style = gtk_style_attach (widget->style, widget->window);
1768 gtk_notebook_unrealize (GtkWidget *widget)
1770 GtkNotebook *notebook;
1771 GtkNotebookPrivate *priv;
1773 notebook = GTK_NOTEBOOK (widget);
1774 priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
1776 gdk_window_set_user_data (notebook->event_window, NULL);
1777 gdk_window_destroy (notebook->event_window);
1778 notebook->event_window = NULL;
1780 if (priv->drag_window)
1782 gdk_window_set_user_data (priv->drag_window, NULL);
1783 gdk_window_destroy (priv->drag_window);
1784 priv->drag_window = NULL;
1787 GTK_WIDGET_CLASS (gtk_notebook_parent_class)->unrealize (widget);
1791 gtk_notebook_size_request (GtkWidget *widget,
1792 GtkRequisition *requisition)
1794 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
1795 GtkNotebookPage *page;
1797 GtkRequisition child_requisition;
1798 gboolean switch_page = FALSE;
1804 gint scroll_arrow_hlength;
1805 gint scroll_arrow_vlength;
1807 gtk_widget_style_get (widget,
1808 "focus-line-width", &focus_width,
1809 "tab-overlap", &tab_overlap,
1810 "tab-curvature", &tab_curvature,
1811 "arrow-spacing", &arrow_spacing,
1812 "scroll-arrow-hlength", &scroll_arrow_hlength,
1813 "scroll-arrow-vlength", &scroll_arrow_vlength,
1816 widget->requisition.width = 0;
1817 widget->requisition.height = 0;
1819 for (children = notebook->children, vis_pages = 0; children;
1820 children = children->next)
1822 page = children->data;
1824 if (GTK_WIDGET_VISIBLE (page->child))
1827 gtk_widget_size_request (page->child, &child_requisition);
1829 widget->requisition.width = MAX (widget->requisition.width,
1830 child_requisition.width);
1831 widget->requisition.height = MAX (widget->requisition.height,
1832 child_requisition.height);
1834 if (notebook->menu && page->menu_label->parent &&
1835 !GTK_WIDGET_VISIBLE (page->menu_label->parent))
1836 gtk_widget_show (page->menu_label->parent);
1840 if (page == notebook->cur_page)
1842 if (notebook->menu && page->menu_label->parent &&
1843 GTK_WIDGET_VISIBLE (page->menu_label->parent))
1844 gtk_widget_hide (page->menu_label->parent);
1848 if (notebook->show_border || notebook->show_tabs)
1850 widget->requisition.width += widget->style->xthickness * 2;
1851 widget->requisition.height += widget->style->ythickness * 2;
1853 if (notebook->show_tabs)
1856 gint tab_height = 0;
1860 for (children = notebook->children; children;
1861 children = children->next)
1863 page = children->data;
1865 if (GTK_WIDGET_VISIBLE (page->child))
1867 if (!GTK_WIDGET_VISIBLE (page->tab_label))
1868 gtk_widget_show (page->tab_label);
1870 gtk_widget_size_request (page->tab_label,
1871 &child_requisition);
1873 page->requisition.width =
1874 child_requisition.width +
1875 2 * widget->style->xthickness;
1876 page->requisition.height =
1877 child_requisition.height +
1878 2 * widget->style->ythickness;
1880 switch (notebook->tab_pos)
1883 case GTK_POS_BOTTOM:
1884 page->requisition.height += 2 * (notebook->tab_vborder +
1886 tab_height = MAX (tab_height, page->requisition.height);
1887 tab_max = MAX (tab_max, page->requisition.width);
1891 page->requisition.width += 2 * (notebook->tab_hborder +
1893 tab_width = MAX (tab_width, page->requisition.width);
1894 tab_max = MAX (tab_max, page->requisition.height);
1898 else if (GTK_WIDGET_VISIBLE (page->tab_label))
1899 gtk_widget_hide (page->tab_label);
1902 children = notebook->children;
1906 switch (notebook->tab_pos)
1909 case GTK_POS_BOTTOM:
1910 if (tab_height == 0)
1913 if (notebook->scrollable && vis_pages > 1 &&
1914 widget->requisition.width < tab_width)
1915 tab_height = MAX (tab_height, scroll_arrow_hlength);
1917 padding = 2 * (tab_curvature + focus_width +
1918 notebook->tab_hborder) - tab_overlap;
1922 page = children->data;
1923 children = children->next;
1925 if (!GTK_WIDGET_VISIBLE (page->child))
1928 if (notebook->homogeneous)
1929 page->requisition.width = tab_max;
1931 page->requisition.width += padding;
1933 tab_width += page->requisition.width;
1934 page->requisition.height = tab_height;
1937 if (notebook->scrollable && vis_pages > 1 &&
1938 widget->requisition.width < tab_width)
1939 tab_width = tab_max + 2 * (scroll_arrow_hlength + arrow_spacing);
1941 if (notebook->homogeneous && !notebook->scrollable)
1942 widget->requisition.width = MAX (widget->requisition.width,
1943 vis_pages * tab_max +
1946 widget->requisition.width = MAX (widget->requisition.width,
1947 tab_width + tab_overlap);
1949 widget->requisition.height += tab_height;
1956 if (notebook->scrollable && vis_pages > 1 &&
1957 widget->requisition.height < tab_height)
1958 tab_width = MAX (tab_width,
1959 arrow_spacing + 2 * scroll_arrow_vlength);
1961 padding = 2 * (tab_curvature + focus_width +
1962 notebook->tab_vborder) - tab_overlap;
1967 page = children->data;
1968 children = children->next;
1970 if (!GTK_WIDGET_VISIBLE (page->child))
1973 page->requisition.width = tab_width;
1975 if (notebook->homogeneous)
1976 page->requisition.height = tab_max;
1978 page->requisition.height += padding;
1980 tab_height += page->requisition.height;
1983 if (notebook->scrollable && vis_pages > 1 &&
1984 widget->requisition.height < tab_height)
1985 tab_height = tab_max + (2 * scroll_arrow_vlength + arrow_spacing);
1987 widget->requisition.width += tab_width;
1989 if (notebook->homogeneous && !notebook->scrollable)
1990 widget->requisition.height =
1991 MAX (widget->requisition.height,
1992 vis_pages * tab_max + tab_overlap);
1994 widget->requisition.height =
1995 MAX (widget->requisition.height,
1996 tab_height + tab_overlap);
1998 if (!notebook->homogeneous || notebook->scrollable)
2000 widget->requisition.height = MAX (widget->requisition.height,
2001 vis_pages * tab_max +
2009 for (children = notebook->children; children;
2010 children = children->next)
2012 page = children->data;
2014 if (page->tab_label && GTK_WIDGET_VISIBLE (page->tab_label))
2015 gtk_widget_hide (page->tab_label);
2020 widget->requisition.width += GTK_CONTAINER (widget)->border_width * 2;
2021 widget->requisition.height += GTK_CONTAINER (widget)->border_width * 2;
2027 for (children = notebook->children; children;
2028 children = children->next)
2030 page = children->data;
2031 if (GTK_WIDGET_VISIBLE (page->child))
2033 gtk_notebook_switch_page (notebook, page);
2038 else if (GTK_WIDGET_VISIBLE (widget))
2040 widget->requisition.width = GTK_CONTAINER (widget)->border_width * 2;
2041 widget->requisition.height= GTK_CONTAINER (widget)->border_width * 2;
2044 if (vis_pages && !notebook->cur_page)
2046 children = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, TRUE);
2049 notebook->first_tab = children;
2050 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (children));
2056 gtk_notebook_size_allocate (GtkWidget *widget,
2057 GtkAllocation *allocation)
2059 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2060 gint tab_pos = get_effective_tab_pos (notebook);
2062 widget->allocation = *allocation;
2063 if (GTK_WIDGET_REALIZED (widget))
2065 GdkRectangle position;
2067 if (gtk_notebook_get_event_window_position (notebook, &position))
2069 gdk_window_move_resize (notebook->event_window,
2070 position.x, position.y,
2071 position.width, position.height);
2072 if (GTK_WIDGET_MAPPED (notebook))
2073 gdk_window_show_unraised (notebook->event_window);
2076 gdk_window_hide (notebook->event_window);
2079 if (notebook->children)
2081 gint border_width = GTK_CONTAINER (widget)->border_width;
2082 GtkNotebookPage *page;
2083 GtkAllocation child_allocation;
2086 child_allocation.x = widget->allocation.x + border_width;
2087 child_allocation.y = widget->allocation.y + border_width;
2088 child_allocation.width = MAX (1, allocation->width - border_width * 2);
2089 child_allocation.height = MAX (1, allocation->height - border_width * 2);
2091 if (notebook->show_tabs || notebook->show_border)
2093 child_allocation.x += widget->style->xthickness;
2094 child_allocation.y += widget->style->ythickness;
2095 child_allocation.width = MAX (1, child_allocation.width -
2096 widget->style->xthickness * 2);
2097 child_allocation.height = MAX (1, child_allocation.height -
2098 widget->style->ythickness * 2);
2100 if (notebook->show_tabs && notebook->children && notebook->cur_page)
2105 child_allocation.y += notebook->cur_page->requisition.height;
2106 case GTK_POS_BOTTOM:
2107 child_allocation.height =
2108 MAX (1, child_allocation.height -
2109 notebook->cur_page->requisition.height);
2112 child_allocation.x += notebook->cur_page->requisition.width;
2114 child_allocation.width =
2115 MAX (1, child_allocation.width -
2116 notebook->cur_page->requisition.width);
2122 children = notebook->children;
2125 page = children->data;
2126 children = children->next;
2128 if (GTK_WIDGET_VISIBLE (page->child))
2129 gtk_widget_size_allocate (page->child, &child_allocation);
2132 gtk_notebook_pages_allocate (notebook);
2137 gtk_notebook_expose (GtkWidget *widget,
2138 GdkEventExpose *event)
2140 GtkNotebook *notebook;
2141 GtkNotebookPrivate *priv;
2143 notebook = GTK_NOTEBOOK (widget);
2144 priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
2146 if (event->window == priv->drag_window)
2148 GdkRectangle area = { 0, };
2151 /* FIXME: This is a workaround to make tabs reordering work better
2152 * with engines with rounded tabs. If the drag window background
2153 * isn't set, the rounded corners would be black.
2155 * Ideally, these corners should be made transparent, Either by using
2156 * ARGB visuals or shape windows.
2158 cr = gdk_cairo_create (priv->drag_window);
2159 gdk_cairo_set_source_color (cr, &widget->style->bg [GTK_STATE_NORMAL]);
2163 gdk_drawable_get_size (priv->drag_window,
2164 &area.width, &area.height);
2165 gtk_notebook_draw_tab (notebook,
2168 gtk_notebook_draw_focus (widget, event);
2169 gtk_container_propagate_expose (GTK_CONTAINER (notebook),
2170 notebook->cur_page->tab_label, event);
2172 else if (GTK_WIDGET_DRAWABLE (widget))
2174 gtk_notebook_paint (widget, &event->area);
2175 if (notebook->show_tabs)
2177 GtkNotebookPage *page;
2180 gtk_notebook_draw_focus (widget, event);
2181 pages = notebook->children;
2185 page = GTK_NOTEBOOK_PAGE (pages);
2186 pages = pages->next;
2188 if (page->tab_label->window == event->window &&
2189 GTK_WIDGET_DRAWABLE (page->tab_label))
2190 gtk_container_propagate_expose (GTK_CONTAINER (notebook),
2191 page->tab_label, event);
2195 if (notebook->cur_page)
2196 gtk_container_propagate_expose (GTK_CONTAINER (notebook),
2197 notebook->cur_page->child,
2205 gtk_notebook_show_arrows (GtkNotebook *notebook)
2207 gboolean show_arrow = FALSE;
2210 if (!notebook->scrollable)
2213 children = notebook->children;
2216 GtkNotebookPage *page = children->data;
2218 if (page->tab_label && !gtk_widget_get_child_visible (page->tab_label))
2221 children = children->next;
2228 gtk_notebook_get_arrow_rect (GtkNotebook *notebook,
2229 GdkRectangle *rectangle,
2230 GtkNotebookArrow arrow)
2232 GdkRectangle event_window_pos;
2233 gboolean before = ARROW_IS_BEFORE (arrow);
2234 gboolean left = ARROW_IS_LEFT (arrow);
2236 if (gtk_notebook_get_event_window_position (notebook, &event_window_pos))
2238 gint scroll_arrow_hlength;
2239 gint scroll_arrow_vlength;
2241 gtk_widget_style_get (GTK_WIDGET (notebook),
2242 "scroll-arrow-hlength", &scroll_arrow_hlength,
2243 "scroll-arrow-vlength", &scroll_arrow_vlength,
2246 switch (notebook->tab_pos)
2250 rectangle->width = scroll_arrow_vlength;
2251 rectangle->height = scroll_arrow_vlength;
2253 if ((before && (notebook->has_before_previous != notebook->has_before_next)) ||
2254 (!before && (notebook->has_after_previous != notebook->has_after_next)))
2255 rectangle->x = event_window_pos.x + (event_window_pos.width - rectangle->width) / 2;
2257 rectangle->x = event_window_pos.x + event_window_pos.width / 2 - rectangle->width;
2259 rectangle->x = event_window_pos.x + event_window_pos.width / 2;
2260 rectangle->y = event_window_pos.y;
2262 rectangle->y += event_window_pos.height - rectangle->height;
2266 case GTK_POS_BOTTOM:
2267 rectangle->width = scroll_arrow_hlength;
2268 rectangle->height = scroll_arrow_hlength;
2272 if (left || !notebook->has_before_previous)
2273 rectangle->x = event_window_pos.x;
2275 rectangle->x = event_window_pos.x + rectangle->width;
2279 if (!left || !notebook->has_after_next)
2280 rectangle->x = event_window_pos.x + event_window_pos.width - rectangle->width;
2282 rectangle->x = event_window_pos.x + event_window_pos.width - 2 * rectangle->width;
2284 rectangle->y = event_window_pos.y + (event_window_pos.height - rectangle->height) / 2;
2290 static GtkNotebookArrow
2291 gtk_notebook_get_arrow (GtkNotebook *notebook,
2295 GdkRectangle arrow_rect;
2296 GdkRectangle event_window_pos;
2299 GtkNotebookArrow arrow[4];
2301 arrow[0] = notebook->has_before_previous ? ARROW_LEFT_BEFORE : ARROW_NONE;
2302 arrow[1] = notebook->has_before_next ? ARROW_RIGHT_BEFORE : ARROW_NONE;
2303 arrow[2] = notebook->has_after_previous ? ARROW_LEFT_AFTER : ARROW_NONE;
2304 arrow[3] = notebook->has_after_next ? ARROW_RIGHT_AFTER : ARROW_NONE;
2306 if (gtk_notebook_show_arrows (notebook))
2308 gtk_notebook_get_event_window_position (notebook, &event_window_pos);
2309 for (i = 0; i < 4; i++)
2311 if (arrow[i] == ARROW_NONE)
2314 gtk_notebook_get_arrow_rect (notebook, &arrow_rect, arrow[i]);
2316 x0 = x - arrow_rect.x;
2317 y0 = y - arrow_rect.y;
2319 if (y0 >= 0 && y0 < arrow_rect.height &&
2320 x0 >= 0 && x0 < arrow_rect.width)
2329 gtk_notebook_do_arrow (GtkNotebook *notebook,
2330 GtkNotebookArrow arrow)
2332 GtkWidget *widget = GTK_WIDGET (notebook);
2333 gboolean is_rtl, left;
2335 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2336 left = (ARROW_IS_LEFT (arrow) && !is_rtl) ||
2337 (!ARROW_IS_LEFT (arrow) && is_rtl);
2339 if (!notebook->focus_tab ||
2340 gtk_notebook_search_page (notebook, notebook->focus_tab,
2341 left ? STEP_PREV : STEP_NEXT,
2344 gtk_notebook_change_current_page (notebook, left ? -1 : 1);
2345 gtk_widget_grab_focus (widget);
2350 gtk_notebook_arrow_button_press (GtkNotebook *notebook,
2351 GtkNotebookArrow arrow,
2354 GtkWidget *widget = GTK_WIDGET (notebook);
2355 gboolean is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2356 gboolean left = (ARROW_IS_LEFT (arrow) && !is_rtl) ||
2357 (!ARROW_IS_LEFT (arrow) && is_rtl);
2359 if (!GTK_WIDGET_HAS_FOCUS (widget))
2360 gtk_widget_grab_focus (widget);
2362 notebook->button = button;
2363 notebook->click_child = arrow;
2367 gtk_notebook_do_arrow (notebook, arrow);
2368 gtk_notebook_set_scroll_timer (notebook);
2370 else if (button == 2)
2371 gtk_notebook_page_select (notebook, TRUE);
2372 else if (button == 3)
2373 gtk_notebook_switch_focus_tab (notebook,
2374 gtk_notebook_search_page (notebook,
2376 left ? STEP_NEXT : STEP_PREV,
2378 gtk_notebook_redraw_arrows (notebook);
2384 get_widget_coordinates (GtkWidget *widget,
2389 GdkWindow *window = ((GdkEventAny *)event)->window;
2392 if (!gdk_event_get_coords (event, &tx, &ty))
2395 while (window && window != widget->window)
2397 gint window_x, window_y;
2399 gdk_window_get_position (window, &window_x, &window_y);
2403 window = gdk_window_get_parent (window);
2418 gtk_notebook_scroll (GtkWidget *widget,
2419 GdkEventScroll *event)
2421 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2424 GtkWidget* originator;
2426 if (!notebook->cur_page)
2429 child = notebook->cur_page->child;
2430 originator = gtk_get_event_widget ((GdkEvent *)event);
2432 /* ignore scroll events from the content of the page */
2433 if (!originator || gtk_widget_is_ancestor (originator, child) || originator == child)
2436 switch (event->direction)
2438 case GDK_SCROLL_RIGHT:
2439 case GDK_SCROLL_DOWN:
2440 gtk_notebook_next_page (notebook);
2442 case GDK_SCROLL_LEFT:
2444 gtk_notebook_prev_page (notebook);
2452 get_tab_at_pos (GtkNotebook *notebook, gint x, gint y)
2454 GtkNotebookPage *page;
2455 GList *children = notebook->children;
2459 page = children->data;
2461 if (GTK_WIDGET_VISIBLE (page->child) &&
2462 page->tab_label && GTK_WIDGET_MAPPED (page->tab_label) &&
2463 (x >= page->allocation.x) &&
2464 (y >= page->allocation.y) &&
2465 (x <= (page->allocation.x + page->allocation.width)) &&
2466 (y <= (page->allocation.y + page->allocation.height)))
2469 children = children->next;
2476 gtk_notebook_button_press (GtkWidget *widget,
2477 GdkEventButton *event)
2479 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2480 GtkNotebookPrivate *priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
2481 GtkNotebookPage *page;
2483 GtkNotebookArrow arrow;
2486 if (event->type != GDK_BUTTON_PRESS || !notebook->children ||
2490 if (!get_widget_coordinates (widget, (GdkEvent *)event, &x, &y))
2493 arrow = gtk_notebook_get_arrow (notebook, x, y);
2495 return gtk_notebook_arrow_button_press (notebook, arrow, event->button);
2497 if (event->button == 3 && notebook->menu)
2499 gtk_menu_popup (GTK_MENU (notebook->menu), NULL, NULL,
2500 NULL, NULL, 3, event->time);
2504 if (event->button != 1)
2507 notebook->button = event->button;
2509 if ((tab = get_tab_at_pos (notebook, x, y)) != NULL)
2511 gboolean page_changed, was_focus;
2514 page_changed = page != notebook->cur_page;
2515 was_focus = gtk_widget_is_focus (widget);
2517 gtk_notebook_switch_focus_tab (notebook, tab);
2518 gtk_widget_grab_focus (widget);
2520 if (page_changed && !was_focus)
2521 gtk_widget_child_focus (page->child, GTK_DIR_TAB_FORWARD);
2523 /* save press to possibly begin a drag */
2524 if (page->reorderable || page->detachable)
2526 priv->during_detach = FALSE;
2527 priv->during_reorder = FALSE;
2528 priv->pressed_button = event->button;
2530 gdk_window_get_pointer (widget->window,
2535 priv->drag_begin_x = priv->mouse_x;
2536 priv->drag_begin_y = priv->mouse_y;
2537 priv->drag_offset_x = priv->drag_begin_x - page->allocation.x;
2538 priv->drag_offset_y = priv->drag_begin_y - page->allocation.y;
2546 popup_position_func (GtkMenu *menu,
2552 GtkNotebook *notebook = data;
2554 GtkRequisition requisition;
2556 if (notebook->focus_tab)
2558 GtkNotebookPage *page;
2560 page = notebook->focus_tab->data;
2561 w = page->tab_label;
2565 w = GTK_WIDGET (notebook);
2568 gdk_window_get_origin (w->window, x, y);
2569 gtk_widget_size_request (GTK_WIDGET (menu), &requisition);
2571 if (gtk_widget_get_direction (w) == GTK_TEXT_DIR_RTL)
2572 *x += w->allocation.x + w->allocation.width - requisition.width;
2574 *x += w->allocation.x;
2576 *y += w->allocation.y + w->allocation.height;
2582 gtk_notebook_popup_menu (GtkWidget *widget)
2584 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2588 gtk_menu_popup (GTK_MENU (notebook->menu), NULL, NULL,
2589 popup_position_func, notebook,
2590 0, gtk_get_current_event_time ());
2591 gtk_menu_shell_select_first (GTK_MENU_SHELL (notebook->menu), FALSE);
2599 stop_scrolling (GtkNotebook *notebook)
2601 if (notebook->timer)
2603 g_source_remove (notebook->timer);
2604 notebook->timer = 0;
2605 notebook->need_timer = FALSE;
2607 notebook->click_child = 0;
2608 notebook->button = 0;
2609 gtk_notebook_redraw_arrows (notebook);
2613 get_drop_position (GtkNotebook *notebook,
2616 GtkNotebookPrivate *priv;
2617 GList *children, *last_child;
2618 GtkNotebookPage *page;
2622 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
2626 is_rtl = gtk_widget_get_direction ((GtkWidget *) notebook) == GTK_TEXT_DIR_RTL;
2627 children = notebook->children;
2632 page = children->data;
2634 if ((priv->operation != DRAG_OPERATION_REORDER || page != notebook->cur_page) &&
2635 GTK_WIDGET_VISIBLE (page->child) &&
2637 GTK_WIDGET_MAPPED (page->tab_label) &&
2640 switch (notebook->tab_pos)
2643 case GTK_POS_BOTTOM:
2646 if ((page->pack == GTK_PACK_START && PAGE_MIDDLE_X (page) > x) ||
2647 (page->pack == GTK_PACK_END && PAGE_MIDDLE_X (page) < x))
2652 if ((page->pack == GTK_PACK_START && PAGE_MIDDLE_X (page) < x) ||
2653 (page->pack == GTK_PACK_END && PAGE_MIDDLE_X (page) > x))
2660 if ((page->pack == GTK_PACK_START && PAGE_MIDDLE_Y (page) > y) ||
2661 (page->pack == GTK_PACK_END && PAGE_MIDDLE_Y (page) < y))
2667 last_child = children->next;
2670 children = children->next;
2677 show_drag_window (GtkNotebook *notebook,
2678 GtkNotebookPrivate *priv,
2679 GtkNotebookPage *page)
2681 GtkWidget *widget = GTK_WIDGET (notebook);
2683 if (!priv->drag_window)
2685 GdkWindowAttr attributes;
2686 guint attributes_mask;
2688 attributes.x = page->allocation.x;
2689 attributes.y = page->allocation.y;
2690 attributes.width = page->allocation.width;
2691 attributes.height = page->allocation.height;
2692 attributes.window_type = GDK_WINDOW_CHILD;
2693 attributes.wclass = GDK_INPUT_OUTPUT;
2694 attributes.visual = gtk_widget_get_visual (widget);
2695 attributes.colormap = gtk_widget_get_colormap (widget);
2696 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
2697 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2699 priv->drag_window = gdk_window_new (gtk_widget_get_parent_window (widget),
2702 gdk_window_set_user_data (priv->drag_window, widget);
2705 g_object_ref (page->tab_label);
2706 gtk_widget_unparent (page->tab_label);
2707 gtk_widget_set_parent_window (page->tab_label, priv->drag_window);
2708 gtk_widget_set_parent (page->tab_label, widget);
2709 g_object_unref (page->tab_label);
2711 gdk_window_show (priv->drag_window);
2713 /* the grab will dissapear when the window is hidden */
2714 gdk_pointer_grab (priv->drag_window,
2716 GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK,
2717 NULL, NULL, GDK_CURRENT_TIME);
2720 /* This function undoes the reparenting that happens both when drag_window
2721 * is shown for reordering and when the DnD icon is shown for detaching
2724 hide_drag_window (GtkNotebook *notebook,
2725 GtkNotebookPrivate *priv,
2726 GtkNotebookPage *page)
2728 GtkWidget *widget = GTK_WIDGET (notebook);
2729 GtkWidget *parent = page->tab_label->parent;
2731 if (page->tab_label->window != widget->window ||
2732 !NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page))
2734 g_object_ref (page->tab_label);
2736 if (GTK_IS_WINDOW (parent))
2738 /* parent widget is the drag window */
2739 gtk_container_remove (GTK_CONTAINER (parent), page->tab_label);
2742 gtk_widget_unparent (page->tab_label);
2744 gtk_widget_set_parent (page->tab_label, widget);
2745 g_object_unref (page->tab_label);
2748 if (priv->drag_window &&
2749 gdk_window_is_visible (priv->drag_window))
2750 gdk_window_hide (priv->drag_window);
2754 gtk_notebook_stop_reorder (GtkNotebook *notebook)
2756 GtkNotebookPrivate *priv;
2757 GtkNotebookPage *page;
2759 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
2761 if (priv->operation == DRAG_OPERATION_DETACH)
2762 page = priv->detached_tab;
2764 page = notebook->cur_page;
2766 if (!page || !page->tab_label)
2769 priv->pressed_button = -1;
2771 if (page->reorderable || page->detachable)
2773 if (priv->during_reorder)
2775 gint old_page_num, page_num;
2778 element = get_drop_position (notebook, page->pack);
2779 old_page_num = g_list_position (notebook->children, notebook->focus_tab);
2780 page_num = reorder_tab (notebook, element, notebook->focus_tab);
2781 gtk_notebook_child_reordered (notebook, page);
2783 if (priv->has_scrolled || old_page_num != page_num)
2784 g_signal_emit (notebook,
2785 notebook_signals[PAGE_REORDERED], 0,
2786 page->child, page_num);
2788 priv->has_scrolled = FALSE;
2789 priv->during_reorder = FALSE;
2792 hide_drag_window (notebook, priv, page);
2794 priv->operation = DRAG_OPERATION_NONE;
2795 gtk_notebook_pages_allocate (notebook);
2797 if (priv->dnd_timer)
2799 g_source_remove (priv->dnd_timer);
2800 priv->dnd_timer = 0;
2806 gtk_notebook_button_release (GtkWidget *widget,
2807 GdkEventButton *event)
2809 GtkNotebook *notebook;
2810 GtkNotebookPrivate *priv;
2811 GtkNotebookPage *page;
2813 if (event->type != GDK_BUTTON_RELEASE)
2816 notebook = GTK_NOTEBOOK (widget);
2817 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
2818 page = notebook->cur_page;
2820 if (!priv->during_detach &&
2821 page->reorderable &&
2822 event->button == priv->pressed_button)
2823 gtk_notebook_stop_reorder (notebook);
2825 if (event->button == notebook->button)
2827 stop_scrolling (notebook);
2835 gtk_notebook_leave_notify (GtkWidget *widget,
2836 GdkEventCrossing *event)
2838 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2841 if (!get_widget_coordinates (widget, (GdkEvent *)event, &x, &y))
2844 if (notebook->in_child)
2846 notebook->in_child = 0;
2847 gtk_notebook_redraw_arrows (notebook);
2853 static GtkNotebookPointerPosition
2854 get_pointer_position (GtkNotebook *notebook)
2856 GtkWidget *widget = (GtkWidget *) notebook;
2857 GtkContainer *container = (GtkContainer *) notebook;
2858 GtkNotebookPrivate *priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
2861 if (!notebook->scrollable)
2862 return POINTER_BETWEEN;
2864 if (notebook->tab_pos == GTK_POS_TOP ||
2865 notebook->tab_pos == GTK_POS_BOTTOM)
2869 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2870 x = priv->mouse_x - widget->allocation.x;
2872 if (x > widget->allocation.width - 2 * container->border_width - SCROLL_THRESHOLD)
2873 return (is_rtl) ? POINTER_BEFORE : POINTER_AFTER;
2874 else if (x < SCROLL_THRESHOLD + container->border_width)
2875 return (is_rtl) ? POINTER_AFTER : POINTER_BEFORE;
2877 return POINTER_BETWEEN;
2883 y = priv->mouse_y - widget->allocation.y;
2884 if (y > widget->allocation.height - 2 * container->border_width - SCROLL_THRESHOLD)
2885 return POINTER_AFTER;
2886 else if (y < SCROLL_THRESHOLD + container->border_width)
2887 return POINTER_BEFORE;
2889 return POINTER_BETWEEN;
2894 scroll_notebook_timer (gpointer data)
2896 GtkNotebook *notebook = (GtkNotebook *) data;
2897 GtkNotebookPrivate *priv;
2898 GtkNotebookPointerPosition pointer_position;
2899 GList *element, *first_tab;
2901 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
2902 pointer_position = get_pointer_position (notebook);
2904 element = get_drop_position (notebook, notebook->cur_page->pack);
2905 reorder_tab (notebook, element, notebook->focus_tab);
2906 first_tab = gtk_notebook_search_page (notebook, notebook->first_tab,
2907 (pointer_position == POINTER_BEFORE) ? STEP_PREV : STEP_NEXT,
2911 notebook->first_tab = first_tab;
2912 gtk_notebook_pages_allocate (notebook);
2914 gdk_window_move_resize (priv->drag_window,
2915 priv->drag_window_x,
2916 priv->drag_window_y,
2917 notebook->cur_page->allocation.width,
2918 notebook->cur_page->allocation.height);
2919 gdk_window_raise (priv->drag_window);
2926 check_threshold (GtkNotebook *notebook,
2932 GdkRectangle rectangle = { 0, }; /* shut up gcc */
2933 GtkSettings *settings;
2935 widget = GTK_WIDGET (notebook);
2936 settings = gtk_widget_get_settings (GTK_WIDGET (notebook));
2937 g_object_get (G_OBJECT (settings), "gtk-dnd-drag-threshold", &dnd_threshold, NULL);
2939 /* we want a large threshold */
2940 dnd_threshold *= DND_THRESHOLD_MULTIPLIER;
2942 gdk_window_get_position (notebook->event_window, &rectangle.x, &rectangle.y);
2943 gdk_drawable_get_size (GDK_DRAWABLE (notebook->event_window), &rectangle.width, &rectangle.height);
2945 rectangle.x -= dnd_threshold;
2946 rectangle.width += 2 * dnd_threshold;
2947 rectangle.y -= dnd_threshold;
2948 rectangle.height += 2 * dnd_threshold;
2950 return (current_x < rectangle.x ||
2951 current_x > rectangle.x + rectangle.width ||
2952 current_y < rectangle.y ||
2953 current_y > rectangle.y + rectangle.height);
2957 gtk_notebook_motion_notify (GtkWidget *widget,
2958 GdkEventMotion *event)
2960 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2961 GtkNotebookPrivate *priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
2962 GtkNotebookPage *page;
2963 GtkNotebookArrow arrow;
2964 GtkNotebookPointerPosition pointer_position;
2965 GtkSettings *settings;
2968 page = notebook->cur_page;
2973 if (!(event->state & GDK_BUTTON1_MASK) &&
2974 priv->pressed_button != -1)
2976 gtk_notebook_stop_reorder (notebook);
2977 stop_scrolling (notebook);
2980 if (event->time < priv->timestamp + MSECS_BETWEEN_UPDATES)
2983 priv->timestamp = event->time;
2984 gdk_window_get_pointer (widget->window,
2989 arrow = gtk_notebook_get_arrow (notebook, priv->mouse_x, priv->mouse_y);
2990 if (arrow != notebook->in_child)
2992 notebook->in_child = arrow;
2993 gtk_notebook_redraw_arrows (notebook);
2996 if (priv->pressed_button == -1)
2999 if (page->detachable &&
3000 check_threshold (notebook, priv->mouse_x, priv->mouse_y))
3002 priv->detached_tab = notebook->cur_page;
3003 priv->during_detach = TRUE;
3005 gtk_drag_begin (widget, priv->source_targets, GDK_ACTION_MOVE,
3006 priv->pressed_button, (GdkEvent*) event);
3010 if (page->reorderable &&
3011 (priv->during_reorder ||
3012 gtk_drag_check_threshold (widget, priv->drag_begin_x, priv->drag_begin_y, priv->mouse_x, priv->mouse_y)))
3014 priv->during_reorder = TRUE;
3015 pointer_position = get_pointer_position (notebook);
3017 if (event->window == priv->drag_window &&
3018 pointer_position != POINTER_BETWEEN &&
3019 gtk_notebook_show_arrows (notebook))
3022 if (!priv->dnd_timer)
3024 priv->has_scrolled = TRUE;
3025 settings = gtk_widget_get_settings (GTK_WIDGET (notebook));
3026 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
3028 priv->dnd_timer = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
3029 scroll_notebook_timer,
3030 (gpointer) notebook);
3035 if (priv->dnd_timer)
3037 g_source_remove (priv->dnd_timer);
3038 priv->dnd_timer = 0;
3042 if (event->window == priv->drag_window ||
3043 priv->operation != DRAG_OPERATION_REORDER)
3045 /* the drag operation is beginning, create the window */
3046 if (priv->operation != DRAG_OPERATION_REORDER)
3048 priv->operation = DRAG_OPERATION_REORDER;
3049 show_drag_window (notebook, priv, page);
3052 gtk_notebook_pages_allocate (notebook);
3053 gdk_window_move_resize (priv->drag_window,
3054 priv->drag_window_x,
3055 priv->drag_window_y,
3056 page->allocation.width,
3057 page->allocation.height);
3065 gtk_notebook_grab_notify (GtkWidget *widget,
3066 gboolean was_grabbed)
3068 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
3072 gtk_notebook_stop_reorder (notebook);
3073 stop_scrolling (notebook);
3078 gtk_notebook_state_changed (GtkWidget *widget,
3079 GtkStateType previous_state)
3081 if (!GTK_WIDGET_IS_SENSITIVE (widget))
3082 stop_scrolling (GTK_NOTEBOOK (widget));
3086 gtk_notebook_focus_in (GtkWidget *widget,
3087 GdkEventFocus *event)
3089 GTK_NOTEBOOK (widget)->child_has_focus = FALSE;
3091 gtk_notebook_redraw_tabs (GTK_NOTEBOOK (widget));
3097 gtk_notebook_focus_out (GtkWidget *widget,
3098 GdkEventFocus *event)
3100 gtk_notebook_redraw_tabs (GTK_NOTEBOOK (widget));
3106 gtk_notebook_draw_focus (GtkWidget *widget,
3107 GdkEventExpose *event)
3109 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
3111 if (GTK_WIDGET_HAS_FOCUS (widget) && GTK_WIDGET_DRAWABLE (widget) &&
3112 notebook->show_tabs && notebook->cur_page &&
3113 notebook->cur_page->tab_label->window == event->window)
3115 GtkNotebookPage *page;
3117 page = notebook->cur_page;
3119 if (gtk_widget_intersect (page->tab_label, &event->area, NULL))
3124 gtk_widget_style_get (widget, "focus-line-width", &focus_width, NULL);
3126 area.x = page->tab_label->allocation.x - focus_width;
3127 area.y = page->tab_label->allocation.y - focus_width;
3128 area.width = page->tab_label->allocation.width + 2 * focus_width;
3129 area.height = page->tab_label->allocation.height + 2 * focus_width;
3131 gtk_paint_focus (widget->style, event->window,
3132 GTK_WIDGET_STATE (widget), NULL, widget, "tab",
3133 area.x, area.y, area.width, area.height);
3139 gtk_notebook_style_set (GtkWidget *widget,
3142 GtkNotebook *notebook;
3144 gboolean has_before_previous;
3145 gboolean has_before_next;
3146 gboolean has_after_previous;
3147 gboolean has_after_next;
3149 notebook = GTK_NOTEBOOK (widget);
3151 gtk_widget_style_get (widget,
3152 "has-backward-stepper", &has_before_previous,
3153 "has-secondary-forward-stepper", &has_before_next,
3154 "has-secondary-backward-stepper", &has_after_previous,
3155 "has-forward-stepper", &has_after_next,
3158 notebook->has_before_previous = has_before_previous;
3159 notebook->has_before_next = has_before_next;
3160 notebook->has_after_previous = has_after_previous;
3161 notebook->has_after_next = has_after_next;
3163 GTK_WIDGET_CLASS (gtk_notebook_parent_class)->style_set (widget, previous);
3167 on_drag_icon_expose (GtkWidget *widget,
3168 GdkEventExpose *event,
3171 GtkWidget *notebook, *child = GTK_WIDGET (data);
3172 GtkRequisition requisition;
3175 notebook = GTK_WIDGET (data);
3176 child = GTK_BIN (widget)->child;
3177 gtk_widget_size_request (widget, &requisition);
3178 gap_pos = get_tab_gap_pos (GTK_NOTEBOOK (notebook));
3180 gtk_paint_extension (notebook->style, widget->window,
3181 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
3182 NULL, widget, "tab",
3184 requisition.width, requisition.height,
3187 gtk_container_propagate_expose (GTK_CONTAINER (widget), child, event);
3193 gtk_notebook_drag_begin (GtkWidget *widget,
3194 GdkDragContext *context)
3196 GtkNotebookPrivate *priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
3197 GtkNotebook *notebook = (GtkNotebook*) widget;
3198 GtkWidget *tab_label;
3200 if (priv->dnd_timer)
3202 g_source_remove (priv->dnd_timer);
3203 priv->dnd_timer = 0;
3206 priv->operation = DRAG_OPERATION_DETACH;
3207 gtk_notebook_pages_allocate (notebook);
3209 tab_label = priv->detached_tab->tab_label;
3211 hide_drag_window (notebook, priv, notebook->cur_page);
3212 g_object_ref (tab_label);
3213 gtk_widget_unparent (tab_label);
3215 priv->dnd_window = gtk_window_new (GTK_WINDOW_POPUP);
3216 gtk_container_add (GTK_CONTAINER (priv->dnd_window), tab_label);
3217 gtk_widget_set_size_request (priv->dnd_window,
3218 priv->detached_tab->allocation.width,
3219 priv->detached_tab->allocation.height);
3220 g_object_unref (tab_label);
3222 g_signal_connect (G_OBJECT (priv->dnd_window), "expose-event",
3223 G_CALLBACK (on_drag_icon_expose), notebook);
3225 gtk_drag_set_icon_widget (context, priv->dnd_window, -2, -2);
3229 gtk_notebook_drag_end (GtkWidget *widget,
3230 GdkDragContext *context)
3232 GtkNotebookPrivate *priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
3234 gtk_notebook_stop_reorder (GTK_NOTEBOOK (widget));
3236 if (priv->detached_tab)
3237 gtk_notebook_switch_page (GTK_NOTEBOOK (widget), priv->detached_tab);
3239 GTK_BIN (priv->dnd_window)->child = NULL;
3240 gtk_widget_destroy (priv->dnd_window);
3241 priv->dnd_window = NULL;
3243 priv->operation = DRAG_OPERATION_NONE;
3246 static GtkNotebook *
3247 gtk_notebook_create_window (GtkNotebook *notebook,
3252 if (window_creation_hook)
3253 return (* window_creation_hook) (notebook, page, x, y, window_creation_hook_data);
3259 gtk_notebook_drag_failed (GtkWidget *widget,
3260 GdkDragContext *context,
3261 GtkDragResult result,
3264 if (result == GTK_DRAG_RESULT_NO_TARGET)
3266 GtkNotebookPrivate *priv;
3267 GtkNotebook *notebook, *dest_notebook = NULL;
3268 GdkDisplay *display;
3271 notebook = GTK_NOTEBOOK (widget);
3272 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
3274 display = gtk_widget_get_display (widget);
3275 gdk_display_get_pointer (display, NULL, &x, &y, NULL);
3277 g_signal_emit (notebook, notebook_signals[CREATE_WINDOW], 0,
3278 priv->detached_tab->child, x, y, &dest_notebook);
3281 do_detach_tab (notebook, dest_notebook, priv->detached_tab->child, 0, 0);
3290 gtk_notebook_switch_tab_timeout (gpointer data)
3292 GtkNotebook *notebook;
3293 GtkNotebookPrivate *priv;
3297 notebook = GTK_NOTEBOOK (data);
3298 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
3300 priv->switch_tab_timer = 0;
3304 if ((tab = get_tab_at_pos (notebook, x, y)) != NULL)
3306 /* FIXME: hack, we don't want the
3307 * focus to move fom the source widget
3309 notebook->child_has_focus = FALSE;
3310 gtk_notebook_switch_focus_tab (notebook, tab);
3317 gtk_notebook_drag_motion (GtkWidget *widget,
3318 GdkDragContext *context,
3323 GtkNotebook *notebook;
3324 GtkNotebookPrivate *priv;
3325 GdkRectangle position;
3326 GtkSettings *settings;
3327 GtkNotebookArrow arrow;
3329 GdkAtom target, tab_target;
3331 notebook = GTK_NOTEBOOK (widget);
3332 arrow = gtk_notebook_get_arrow (notebook,
3333 x + widget->allocation.x,
3334 y + widget->allocation.y);
3337 notebook->click_child = arrow;
3338 gtk_notebook_set_scroll_timer (notebook);
3339 gdk_drag_status (context, 0, time);
3343 stop_scrolling (notebook);
3344 target = gtk_drag_dest_find_target (widget, context, NULL);
3345 tab_target = gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB");
3347 if (target == tab_target)
3349 gpointer widget_group, source_widget_group;
3350 GtkWidget *source_widget;
3352 source_widget = gtk_drag_get_source_widget (context);
3353 g_assert (source_widget);
3355 widget_group = gtk_notebook_get_group (notebook);
3356 source_widget_group = gtk_notebook_get_group (GTK_NOTEBOOK (source_widget));
3358 if (widget_group && source_widget_group &&
3359 widget_group == source_widget_group &&
3360 !(widget == GTK_NOTEBOOK (source_widget)->cur_page->child ||
3361 gtk_widget_is_ancestor (widget, GTK_NOTEBOOK (source_widget)->cur_page->child)))
3363 gdk_drag_status (context, GDK_ACTION_MOVE, time);
3368 /* it's a tab, but doesn't share
3369 * ID with this notebook */
3370 gdk_drag_status (context, 0, time);
3374 priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
3375 x += widget->allocation.x;
3376 y += widget->allocation.y;
3378 if (gtk_notebook_get_event_window_position (notebook, &position) &&
3379 x >= position.x && x <= position.x + position.width &&
3380 y >= position.y && y <= position.y + position.height)
3385 if (!priv->switch_tab_timer)
3387 settings = gtk_widget_get_settings (widget);
3389 g_object_get (settings, "gtk-timeout-expand", &timeout, NULL);
3390 priv->switch_tab_timer = gdk_threads_add_timeout (timeout,
3391 gtk_notebook_switch_tab_timeout,
3397 if (priv->switch_tab_timer)
3399 g_source_remove (priv->switch_tab_timer);
3400 priv->switch_tab_timer = 0;
3404 return (target == tab_target) ? TRUE : FALSE;
3408 gtk_notebook_drag_leave (GtkWidget *widget,
3409 GdkDragContext *context,
3412 GtkNotebookPrivate *priv;
3414 priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
3416 if (priv->switch_tab_timer)
3418 g_source_remove (priv->switch_tab_timer);
3419 priv->switch_tab_timer = 0;
3422 stop_scrolling (GTK_NOTEBOOK (widget));
3426 gtk_notebook_drag_drop (GtkWidget *widget,
3427 GdkDragContext *context,
3432 GdkAtom target, tab_target;
3434 target = gtk_drag_dest_find_target (widget, context, NULL);
3435 tab_target = gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB");
3437 if (target == tab_target)
3439 gtk_drag_get_data (widget, context, target, time);
3447 do_detach_tab (GtkNotebook *from,
3453 GtkNotebookPrivate *priv;
3454 GtkWidget *tab_label, *menu_label;
3455 gboolean tab_expand, tab_fill, reorderable, detachable;
3460 menu_label = gtk_notebook_get_menu_label (from, child);
3463 g_object_ref (menu_label);
3465 tab_label = gtk_notebook_get_tab_label (from, child);
3468 g_object_ref (tab_label);
3470 g_object_ref (child);
3472 gtk_container_child_get (GTK_CONTAINER (from),
3474 "tab-expand", &tab_expand,
3475 "tab-fill", &tab_fill,
3476 "tab-pack", &tab_pack,
3477 "reorderable", &reorderable,
3478 "detachable", &detachable,
3481 gtk_container_remove (GTK_CONTAINER (from), child);
3483 priv = GTK_NOTEBOOK_GET_PRIVATE (to);
3484 priv->mouse_x = x + GTK_WIDGET (to)->allocation.x;
3485 priv->mouse_y = y + GTK_WIDGET (to)->allocation.y;
3487 element = get_drop_position (to, tab_pack);
3488 page_num = g_list_position (to->children, element);
3489 gtk_notebook_insert_page_menu (to, child, tab_label, menu_label, page_num);
3491 gtk_container_child_set (GTK_CONTAINER (to), child,
3492 "tab-pack", tab_pack,
3493 "tab-expand", tab_expand,
3494 "tab-fill", tab_fill,
3495 "reorderable", reorderable,
3496 "detachable", detachable,
3499 g_object_unref (child);
3502 g_object_unref (tab_label);
3505 g_object_unref (menu_label);
3507 gtk_notebook_set_current_page (to, page_num);
3511 gtk_notebook_drag_data_get (GtkWidget *widget,
3512 GdkDragContext *context,
3513 GtkSelectionData *data,
3517 GtkNotebookPrivate *priv;
3519 if (data->target == gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB"))
3521 priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
3523 gtk_selection_data_set (data,
3526 (void*) &priv->detached_tab->child,
3532 gtk_notebook_drag_data_received (GtkWidget *widget,
3533 GdkDragContext *context,
3536 GtkSelectionData *data,
3540 GtkNotebook *notebook;
3541 GtkWidget *source_widget;
3544 notebook = GTK_NOTEBOOK (widget);
3545 source_widget = gtk_drag_get_source_widget (context);
3547 if (source_widget &&
3548 data->target == gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB"))
3550 child = (void*) data->data;
3552 do_detach_tab (GTK_NOTEBOOK (source_widget), notebook, *child, x, y);
3553 gtk_drag_finish (context, TRUE, FALSE, time);
3556 gtk_drag_finish (context, FALSE, FALSE, time);
3559 /* Private GtkContainer Methods :
3561 * gtk_notebook_set_child_arg
3562 * gtk_notebook_get_child_arg
3564 * gtk_notebook_remove
3565 * gtk_notebook_focus
3566 * gtk_notebook_set_focus_child
3567 * gtk_notebook_child_type
3568 * gtk_notebook_forall
3571 gtk_notebook_set_child_property (GtkContainer *container,
3574 const GValue *value,
3579 GtkPackType pack_type;
3581 /* not finding child's page is valid for menus or labels */
3582 if (!gtk_notebook_find_child (GTK_NOTEBOOK (container), child, NULL))
3585 switch (property_id)
3587 case CHILD_PROP_TAB_LABEL:
3588 /* a NULL pointer indicates a default_tab setting, otherwise
3589 * we need to set the associated label
3591 gtk_notebook_set_tab_label_text (GTK_NOTEBOOK (container), child,
3592 g_value_get_string (value));
3594 case CHILD_PROP_MENU_LABEL:
3595 gtk_notebook_set_menu_label_text (GTK_NOTEBOOK (container), child,
3596 g_value_get_string (value));
3598 case CHILD_PROP_POSITION:
3599 gtk_notebook_reorder_child (GTK_NOTEBOOK (container), child,
3600 g_value_get_int (value));
3602 case CHILD_PROP_TAB_EXPAND:
3603 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3604 &expand, &fill, &pack_type);
3605 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (container), child,
3606 g_value_get_boolean (value),
3609 case CHILD_PROP_TAB_FILL:
3610 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3611 &expand, &fill, &pack_type);
3612 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (container), child,
3614 g_value_get_boolean (value),
3617 case CHILD_PROP_TAB_PACK:
3618 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3619 &expand, &fill, &pack_type);
3620 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (container), child,
3622 g_value_get_enum (value));
3624 case CHILD_PROP_REORDERABLE:
3625 gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (container), child,
3626 g_value_get_boolean (value));
3628 case CHILD_PROP_DETACHABLE:
3629 gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (container), child,
3630 g_value_get_boolean (value));
3633 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
3639 gtk_notebook_get_child_property (GtkContainer *container,
3646 GtkNotebook *notebook;
3650 GtkPackType pack_type;
3652 notebook = GTK_NOTEBOOK (container);
3654 /* not finding child's page is valid for menus or labels */
3655 list = gtk_notebook_find_child (notebook, child, NULL);
3658 /* nothing to set on labels or menus */
3659 g_param_value_set_default (pspec, value);
3663 switch (property_id)
3665 case CHILD_PROP_TAB_LABEL:
3666 label = gtk_notebook_get_tab_label (notebook, child);
3668 if (GTK_IS_LABEL (label))
3669 g_value_set_string (value, GTK_LABEL (label)->label);
3671 g_value_set_string (value, NULL);
3673 case CHILD_PROP_MENU_LABEL:
3674 label = gtk_notebook_get_menu_label (notebook, child);
3676 if (GTK_IS_LABEL (label))
3677 g_value_set_string (value, GTK_LABEL (label)->label);
3679 g_value_set_string (value, NULL);
3681 case CHILD_PROP_POSITION:
3682 g_value_set_int (value, g_list_position (notebook->children, list));
3684 case CHILD_PROP_TAB_EXPAND:
3685 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3686 &expand, NULL, NULL);
3687 g_value_set_boolean (value, expand);
3689 case CHILD_PROP_TAB_FILL:
3690 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3692 g_value_set_boolean (value, fill);
3694 case CHILD_PROP_TAB_PACK:
3695 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
3696 NULL, NULL, &pack_type);
3697 g_value_set_enum (value, pack_type);
3699 case CHILD_PROP_REORDERABLE:
3700 g_value_set_boolean (value,
3701 gtk_notebook_get_tab_reorderable (GTK_NOTEBOOK (container), child));
3703 case CHILD_PROP_DETACHABLE:
3704 g_value_set_boolean (value,
3705 gtk_notebook_get_tab_detachable (GTK_NOTEBOOK (container), child));
3708 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
3714 gtk_notebook_add (GtkContainer *container,
3717 gtk_notebook_insert_page_menu (GTK_NOTEBOOK (container), widget,
3722 gtk_notebook_remove (GtkContainer *container,
3725 GtkNotebook *notebook;
3726 GtkNotebookPage *page;
3730 notebook = GTK_NOTEBOOK (container);
3732 children = notebook->children;
3735 page = children->data;
3737 if (page->child == widget)
3741 children = children->next;
3744 if (children == NULL)
3747 g_object_ref (widget);
3749 gtk_notebook_real_remove (notebook, children);
3751 g_signal_emit (notebook,
3752 notebook_signals[PAGE_REMOVED],
3757 g_object_unref (widget);
3761 focus_tabs_in (GtkNotebook *notebook)
3763 if (notebook->show_tabs && notebook->cur_page)
3765 gtk_widget_grab_focus (GTK_WIDGET (notebook));
3767 gtk_notebook_switch_focus_tab (notebook,
3768 g_list_find (notebook->children,
3769 notebook->cur_page));
3778 focus_tabs_move (GtkNotebook *notebook,
3779 GtkDirectionType direction,
3780 gint search_direction)
3784 new_page = gtk_notebook_search_page (notebook, notebook->focus_tab,
3785 search_direction, TRUE);
3788 gboolean wrap_around;
3790 g_object_get (gtk_widget_get_settings (GTK_WIDGET (notebook)),
3791 "gtk-keynav-wrap-around", &wrap_around,
3795 new_page = gtk_notebook_search_page (notebook, NULL,
3796 search_direction, TRUE);
3800 gtk_notebook_switch_focus_tab (notebook, new_page);
3802 gtk_widget_error_bell (GTK_WIDGET (notebook));
3808 focus_child_in (GtkNotebook *notebook,
3809 GtkDirectionType direction)
3811 if (notebook->cur_page)
3812 return gtk_widget_child_focus (notebook->cur_page->child, direction);
3817 /* Focus in the notebook can either be on the pages, or on
3821 gtk_notebook_focus (GtkWidget *widget,
3822 GtkDirectionType direction)
3824 GtkWidget *old_focus_child;
3825 GtkNotebook *notebook;
3826 GtkDirectionType effective_direction;
3828 gboolean widget_is_focus;
3829 GtkContainer *container;
3831 container = GTK_CONTAINER (widget);
3832 notebook = GTK_NOTEBOOK (container);
3834 if (notebook->focus_out)
3836 notebook->focus_out = FALSE; /* Clear this to catch the wrap-around case */
3840 widget_is_focus = gtk_widget_is_focus (widget);
3841 old_focus_child = container->focus_child;
3843 effective_direction = get_effective_direction (notebook, direction);
3845 if (old_focus_child) /* Focus on page child */
3847 if (gtk_widget_child_focus (old_focus_child, direction))
3850 switch (effective_direction)
3852 case GTK_DIR_TAB_BACKWARD:
3854 /* Focus onto the tabs */
3855 return focus_tabs_in (notebook);
3857 case GTK_DIR_TAB_FORWARD:
3863 else if (widget_is_focus) /* Focus was on tabs */
3865 switch (effective_direction)
3867 case GTK_DIR_TAB_BACKWARD:
3870 case GTK_DIR_TAB_FORWARD:
3872 /* We use TAB_FORWARD rather than direction so that we focus a more
3873 * predictable widget for the user; users may be using arrow focusing
3874 * in this situation even if they don't usually use arrow focusing.
3876 return focus_child_in (notebook, GTK_DIR_TAB_FORWARD);
3878 return focus_tabs_move (notebook, direction, STEP_PREV);
3880 return focus_tabs_move (notebook, direction, STEP_NEXT);
3883 else /* Focus was not on widget */
3885 switch (effective_direction)
3887 case GTK_DIR_TAB_FORWARD:
3889 if (focus_tabs_in (notebook))
3891 if (focus_child_in (notebook, direction))
3894 case GTK_DIR_TAB_BACKWARD:
3896 if (focus_child_in (notebook, direction))
3898 if (focus_tabs_in (notebook))
3903 return focus_child_in (notebook, direction);
3907 g_assert_not_reached ();
3912 gtk_notebook_set_focus_child (GtkContainer *container,
3915 GtkNotebook *notebook = GTK_NOTEBOOK (container);
3916 GtkWidget *page_child;
3917 GtkWidget *toplevel;
3919 /* If the old focus widget was within a page of the notebook,
3920 * (child may either be NULL or not in this case), record it
3921 * for future use if we switch to the page with a mnemonic.
3924 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (container));
3925 if (toplevel && GTK_WIDGET_TOPLEVEL (toplevel))
3927 page_child = GTK_WINDOW (toplevel)->focus_widget;
3930 if (page_child->parent == GTK_WIDGET (container))
3932 GList *list = gtk_notebook_find_child (notebook, page_child, NULL);
3935 GtkNotebookPage *page = list->data;
3937 if (page->last_focus_child)
3938 g_object_remove_weak_pointer (G_OBJECT (page->last_focus_child), (gpointer *)&page->last_focus_child);
3940 page->last_focus_child = GTK_WINDOW (toplevel)->focus_widget;
3941 g_object_add_weak_pointer (G_OBJECT (page->last_focus_child), (gpointer *)&page->last_focus_child);
3947 page_child = page_child->parent;
3953 g_return_if_fail (GTK_IS_WIDGET (child));
3955 notebook->child_has_focus = TRUE;
3956 if (!notebook->focus_tab)
3959 GtkNotebookPage *page;
3961 children = notebook->children;
3964 page = children->data;
3965 if (page->child == child || page->tab_label == child)
3966 gtk_notebook_switch_focus_tab (notebook, children);
3967 children = children->next;
3972 GTK_CONTAINER_CLASS (gtk_notebook_parent_class)->set_focus_child (container, child);
3976 gtk_notebook_forall (GtkContainer *container,
3977 gboolean include_internals,
3978 GtkCallback callback,
3979 gpointer callback_data)
3981 GtkNotebook *notebook;
3984 notebook = GTK_NOTEBOOK (container);
3986 children = notebook->children;
3989 GtkNotebookPage *page;
3991 page = children->data;
3992 children = children->next;
3993 (* callback) (page->child, callback_data);
3995 if (include_internals)
3997 if (page->tab_label)
3998 (* callback) (page->tab_label, callback_data);
4004 gtk_notebook_child_type (GtkContainer *container)
4006 return GTK_TYPE_WIDGET;
4009 /* Private GtkNotebook Methods:
4011 * gtk_notebook_real_insert_page
4014 page_visible_cb (GtkWidget *page,
4018 GtkNotebook *notebook = (GtkNotebook *) data;
4022 if (notebook->cur_page &&
4023 notebook->cur_page->child == page &&
4024 !GTK_WIDGET_VISIBLE (page))
4026 list = g_list_find (notebook->children, notebook->cur_page);
4029 next = gtk_notebook_search_page (notebook, list, STEP_NEXT, TRUE);
4031 next = gtk_notebook_search_page (notebook, list, STEP_PREV, TRUE);
4035 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (next));
4040 gtk_notebook_real_insert_page (GtkNotebook *notebook,
4042 GtkWidget *tab_label,
4043 GtkWidget *menu_label,
4046 GtkNotebookPage *page;
4049 gtk_widget_freeze_child_notify (child);
4051 page = g_slice_new0 (GtkNotebookPage);
4052 page->child = child;
4054 nchildren = g_list_length (notebook->children);
4055 if ((position < 0) || (position > nchildren))
4056 position = nchildren;
4058 notebook->children = g_list_insert (notebook->children, page, position);
4062 page->default_tab = TRUE;
4063 if (notebook->show_tabs)
4064 tab_label = gtk_label_new (NULL);
4066 page->tab_label = tab_label;
4067 page->menu_label = menu_label;
4068 page->expand = FALSE;
4070 page->pack = GTK_PACK_START;
4073 page->default_menu = TRUE;
4075 g_object_ref_sink (page->menu_label);
4078 gtk_notebook_menu_item_create (notebook,
4079 g_list_find (notebook->children, page));
4081 gtk_widget_set_parent (child, GTK_WIDGET (notebook));
4083 gtk_widget_set_parent (tab_label, GTK_WIDGET (notebook));
4085 gtk_notebook_update_labels (notebook);
4087 if (!notebook->first_tab)
4088 notebook->first_tab = notebook->children;
4090 /* child visible will be turned on by switch_page below */
4091 if (notebook->cur_page != page)
4092 gtk_widget_set_child_visible (child, FALSE);
4096 if (notebook->show_tabs && GTK_WIDGET_VISIBLE (child))
4097 gtk_widget_show (tab_label);
4099 gtk_widget_hide (tab_label);
4101 page->mnemonic_activate_signal =
4102 g_signal_connect (tab_label,
4103 "mnemonic-activate",
4104 G_CALLBACK (gtk_notebook_mnemonic_activate_switch_page),
4108 page->notify_visible_handler = g_signal_connect (child, "notify::visible",
4109 G_CALLBACK (page_visible_cb), notebook);
4111 g_signal_emit (notebook,
4112 notebook_signals[PAGE_ADDED],
4117 if (!notebook->cur_page)
4119 gtk_notebook_switch_page (notebook, page);
4120 /* focus_tab is set in the switch_page method */
4121 gtk_notebook_switch_focus_tab (notebook, notebook->focus_tab);
4124 gtk_notebook_update_tab_states (notebook);
4126 gtk_widget_child_notify (child, "tab-expand");
4127 gtk_widget_child_notify (child, "tab-fill");
4128 gtk_widget_child_notify (child, "tab-pack");
4129 gtk_widget_child_notify (child, "tab-label");
4130 gtk_widget_child_notify (child, "menu-label");
4131 gtk_widget_child_notify (child, "position");
4132 gtk_widget_thaw_child_notify (child);
4134 /* The page-added handler might have reordered the pages, re-get the position */
4135 return gtk_notebook_page_num (notebook, child);
4138 /* Private GtkNotebook Functions:
4140 * gtk_notebook_redraw_tabs
4141 * gtk_notebook_real_remove
4142 * gtk_notebook_update_labels
4143 * gtk_notebook_timer
4144 * gtk_notebook_set_scroll_timer
4145 * gtk_notebook_page_compare
4146 * gtk_notebook_real_page_position
4147 * gtk_notebook_search_page
4150 gtk_notebook_redraw_tabs (GtkNotebook *notebook)
4153 GtkNotebookPage *page;
4154 GdkRectangle redraw_rect;
4156 gint tab_pos = get_effective_tab_pos (notebook);
4158 widget = GTK_WIDGET (notebook);
4159 border = GTK_CONTAINER (notebook)->border_width;
4161 if (!GTK_WIDGET_MAPPED (notebook) || !notebook->first_tab)
4164 page = notebook->first_tab->data;
4166 redraw_rect.x = border;
4167 redraw_rect.y = border;
4171 case GTK_POS_BOTTOM:
4172 redraw_rect.y = widget->allocation.height - border -
4173 page->allocation.height - widget->style->ythickness;
4175 if (page != notebook->cur_page)
4176 redraw_rect.y -= widget->style->ythickness;
4179 redraw_rect.width = widget->allocation.width - 2 * border;
4180 redraw_rect.height = page->allocation.height + widget->style->ythickness;
4182 if (page != notebook->cur_page)
4183 redraw_rect.height += widget->style->ythickness;
4186 redraw_rect.x = widget->allocation.width - border -
4187 page->allocation.width - widget->style->xthickness;
4189 if (page != notebook->cur_page)
4190 redraw_rect.x -= widget->style->xthickness;
4193 redraw_rect.width = page->allocation.width + widget->style->xthickness;
4194 redraw_rect.height = widget->allocation.height - 2 * border;
4196 if (page != notebook->cur_page)
4197 redraw_rect.width += widget->style->xthickness;
4201 redraw_rect.x += widget->allocation.x;
4202 redraw_rect.y += widget->allocation.y;
4204 gdk_window_invalidate_rect (widget->window, &redraw_rect, TRUE);
4208 gtk_notebook_redraw_arrows (GtkNotebook *notebook)
4210 if (GTK_WIDGET_MAPPED (notebook) && gtk_notebook_show_arrows (notebook))
4214 GtkNotebookArrow arrow[4];
4216 arrow[0] = notebook->has_before_previous ? ARROW_LEFT_BEFORE : ARROW_NONE;
4217 arrow[1] = notebook->has_before_next ? ARROW_RIGHT_BEFORE : ARROW_NONE;
4218 arrow[2] = notebook->has_after_previous ? ARROW_LEFT_AFTER : ARROW_NONE;
4219 arrow[3] = notebook->has_after_next ? ARROW_RIGHT_AFTER : ARROW_NONE;
4221 for (i = 0; i < 4; i++)
4223 if (arrow[i] == ARROW_NONE)
4226 gtk_notebook_get_arrow_rect (notebook, &rect, arrow[i]);
4227 gdk_window_invalidate_rect (GTK_WIDGET (notebook)->window,
4234 gtk_notebook_timer (GtkNotebook *notebook)
4236 gboolean retval = FALSE;
4238 if (notebook->timer)
4240 gtk_notebook_do_arrow (notebook, notebook->click_child);
4242 if (notebook->need_timer)
4244 GtkSettings *settings;
4247 settings = gtk_widget_get_settings (GTK_WIDGET (notebook));
4248 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
4250 notebook->need_timer = FALSE;
4251 notebook->timer = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
4252 (GSourceFunc) gtk_notebook_timer,
4253 (gpointer) notebook);
4263 gtk_notebook_set_scroll_timer (GtkNotebook *notebook)
4265 GtkWidget *widget = GTK_WIDGET (notebook);
4267 if (!notebook->timer)
4269 GtkSettings *settings = gtk_widget_get_settings (widget);
4272 g_object_get (settings, "gtk-timeout-initial", &timeout, NULL);
4274 notebook->timer = gdk_threads_add_timeout (timeout,
4275 (GSourceFunc) gtk_notebook_timer,
4276 (gpointer) notebook);
4277 notebook->need_timer = TRUE;
4282 gtk_notebook_page_compare (gconstpointer a,
4285 return (((GtkNotebookPage *) a)->child != b);
4289 gtk_notebook_find_child (GtkNotebook *notebook,
4291 const gchar *function)
4293 GList *list = g_list_find_custom (notebook->children, child,
4294 gtk_notebook_page_compare);
4296 #ifndef G_DISABLE_CHECKS
4297 if (!list && function)
4298 g_warning ("%s: unable to find child %p in notebook %p",
4299 function, child, notebook);
4306 gtk_notebook_remove_tab_label (GtkNotebook *notebook,
4307 GtkNotebookPage *page)
4309 if (page->tab_label)
4311 if (page->mnemonic_activate_signal)
4312 g_signal_handler_disconnect (page->tab_label,
4313 page->mnemonic_activate_signal);
4314 page->mnemonic_activate_signal = 0;
4316 gtk_widget_set_state (page->tab_label, GTK_STATE_NORMAL);
4317 gtk_widget_unparent (page->tab_label);
4318 page->tab_label = NULL;
4323 gtk_notebook_real_remove (GtkNotebook *notebook,
4326 GtkNotebookPrivate *priv;
4327 GtkNotebookPage *page;
4329 gint need_resize = FALSE;
4330 GtkWidget *tab_label;
4332 gboolean destroying;
4334 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
4335 destroying = GTK_OBJECT_FLAGS (notebook) & GTK_IN_DESTRUCTION;
4337 next_list = gtk_notebook_search_page (notebook, list, STEP_NEXT, TRUE);
4339 next_list = gtk_notebook_search_page (notebook, list, STEP_PREV, TRUE);
4341 notebook->children = g_list_remove_link (notebook->children, list);
4343 if (notebook->cur_page == list->data)
4345 notebook->cur_page = NULL;
4346 if (next_list && !destroying)
4347 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (next_list));
4350 if (priv->detached_tab == list->data)
4351 priv->detached_tab = NULL;
4353 if (list == notebook->first_tab)
4354 notebook->first_tab = next_list;
4355 if (list == notebook->focus_tab && !destroying)
4356 gtk_notebook_switch_focus_tab (notebook, next_list);
4360 g_signal_handler_disconnect (page->child, page->notify_visible_handler);
4362 if (GTK_WIDGET_VISIBLE (page->child) && GTK_WIDGET_VISIBLE (notebook))
4365 gtk_widget_unparent (page->child);
4367 tab_label = page->tab_label;
4370 g_object_ref (tab_label);
4371 gtk_notebook_remove_tab_label (notebook, page);
4373 gtk_widget_destroy (tab_label);
4374 g_object_unref (tab_label);
4379 gtk_container_remove (GTK_CONTAINER (notebook->menu),
4380 page->menu_label->parent);
4381 gtk_widget_queue_resize (notebook->menu);
4383 if (!page->default_menu)
4384 g_object_unref (page->menu_label);
4388 if (page->last_focus_child)
4390 g_object_remove_weak_pointer (G_OBJECT (page->last_focus_child), (gpointer *)&page->last_focus_child);
4391 page->last_focus_child = NULL;
4394 g_slice_free (GtkNotebookPage, page);
4396 gtk_notebook_update_labels (notebook);
4398 gtk_widget_queue_resize (GTK_WIDGET (notebook));
4402 gtk_notebook_update_labels (GtkNotebook *notebook)
4404 GtkNotebookPage *page;
4409 if (!notebook->show_tabs && !notebook->menu)
4412 for (list = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, FALSE);
4414 list = gtk_notebook_search_page (notebook, list, STEP_NEXT, FALSE))
4417 g_snprintf (string, sizeof(string), _("Page %u"), page_num++);
4418 if (notebook->show_tabs)
4420 if (page->default_tab)
4422 if (!page->tab_label)
4424 page->tab_label = gtk_label_new (string);
4425 gtk_widget_set_parent (page->tab_label,
4426 GTK_WIDGET (notebook));
4429 gtk_label_set_text (GTK_LABEL (page->tab_label), string);
4432 if (GTK_WIDGET_VISIBLE (page->child) &&
4433 !GTK_WIDGET_VISIBLE (page->tab_label))
4434 gtk_widget_show (page->tab_label);
4435 else if (!GTK_WIDGET_VISIBLE (page->child) &&
4436 GTK_WIDGET_VISIBLE (page->tab_label))
4437 gtk_widget_hide (page->tab_label);
4439 if (notebook->menu && page->default_menu)
4441 if (GTK_IS_LABEL (page->tab_label))
4442 gtk_label_set_text (GTK_LABEL (page->menu_label),
4443 GTK_LABEL (page->tab_label)->label);
4445 gtk_label_set_text (GTK_LABEL (page->menu_label), string);
4451 gtk_notebook_real_page_position (GtkNotebook *notebook,
4457 for (work = notebook->children, count_start = 0;
4458 work && work != list; work = work->next)
4459 if (GTK_NOTEBOOK_PAGE (work)->pack == GTK_PACK_START)
4465 if (GTK_NOTEBOOK_PAGE (list)->pack == GTK_PACK_START)
4468 return (count_start + g_list_length (list) - 1);
4472 gtk_notebook_search_page (GtkNotebook *notebook,
4475 gboolean find_visible)
4477 GtkNotebookPage *page = NULL;
4478 GList *old_list = NULL;
4484 flag = GTK_PACK_END;
4488 flag = GTK_PACK_START;
4495 if (!page || page->pack == flag)
4503 list = notebook->children;
4508 if (page->pack == flag &&
4510 (GTK_WIDGET_VISIBLE (page->child) &&
4511 (!page->tab_label || NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page)))))
4526 if (page->pack != flag &&
4528 (GTK_WIDGET_VISIBLE (page->child) &&
4529 (!page->tab_label || NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page)))))
4537 /* Private GtkNotebook Drawing Functions:
4539 * gtk_notebook_paint
4540 * gtk_notebook_draw_tab
4541 * gtk_notebook_draw_arrow
4544 gtk_notebook_paint (GtkWidget *widget,
4547 GtkNotebook *notebook;
4548 GtkNotebookPrivate *priv;
4549 GtkNotebookPage *page;
4554 gint border_width = GTK_CONTAINER (widget)->border_width;
4555 gint gap_x = 0, gap_width = 0, step = STEP_PREV;
4559 if (!GTK_WIDGET_DRAWABLE (widget))
4562 notebook = GTK_NOTEBOOK (widget);
4563 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
4564 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
4565 tab_pos = get_effective_tab_pos (notebook);
4567 if ((!notebook->show_tabs && !notebook->show_border) ||
4568 !notebook->cur_page || !GTK_WIDGET_VISIBLE (notebook->cur_page->child))
4571 x = widget->allocation.x + border_width;
4572 y = widget->allocation.y + border_width;
4573 width = widget->allocation.width - border_width * 2;
4574 height = widget->allocation.height - border_width * 2;
4576 if (notebook->show_border && (!notebook->show_tabs || !notebook->children))
4578 gtk_paint_box (widget->style, widget->window,
4579 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
4580 area, widget, "notebook",
4581 x, y, width, height);
4585 if (!notebook->first_tab)
4586 notebook->first_tab = notebook->children;
4588 if (!GTK_WIDGET_MAPPED (notebook->cur_page->tab_label))
4589 page = GTK_NOTEBOOK_PAGE (notebook->first_tab);
4591 page = notebook->cur_page;
4596 y += page->allocation.height;
4598 case GTK_POS_BOTTOM:
4599 height -= page->allocation.height;
4602 x += page->allocation.width;
4605 width -= page->allocation.width;
4609 if (!NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, notebook->cur_page) ||
4610 !GTK_WIDGET_MAPPED (notebook->cur_page->tab_label))
4620 case GTK_POS_BOTTOM:
4621 if (priv->operation == DRAG_OPERATION_REORDER)
4622 gap_x = priv->drag_window_x - widget->allocation.x - border_width;
4624 gap_x = notebook->cur_page->allocation.x - widget->allocation.x - border_width;
4626 gap_width = notebook->cur_page->allocation.width;
4627 step = is_rtl ? STEP_NEXT : STEP_PREV;
4631 if (priv->operation == DRAG_OPERATION_REORDER)
4632 gap_x = priv->drag_window_y - border_width - widget->allocation.y;
4634 gap_x = notebook->cur_page->allocation.y - widget->allocation.y - border_width;
4636 gap_width = notebook->cur_page->allocation.height;
4641 gtk_paint_box_gap (widget->style, widget->window,
4642 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
4643 area, widget, "notebook",
4644 x, y, width, height,
4645 tab_pos, gap_x, gap_width);
4648 children = gtk_notebook_search_page (notebook, NULL, step, TRUE);
4651 page = children->data;
4652 children = gtk_notebook_search_page (notebook, children,
4654 if (!GTK_WIDGET_VISIBLE (page->child))
4656 if (!GTK_WIDGET_MAPPED (page->tab_label))
4658 else if (page != notebook->cur_page)
4659 gtk_notebook_draw_tab (notebook, page, area);
4662 if (showarrow && notebook->scrollable)
4664 if (notebook->has_before_previous)
4665 gtk_notebook_draw_arrow (notebook, ARROW_LEFT_BEFORE);
4666 if (notebook->has_before_next)
4667 gtk_notebook_draw_arrow (notebook, ARROW_RIGHT_BEFORE);
4668 if (notebook->has_after_previous)
4669 gtk_notebook_draw_arrow (notebook, ARROW_LEFT_AFTER);
4670 if (notebook->has_after_next)
4671 gtk_notebook_draw_arrow (notebook, ARROW_RIGHT_AFTER);
4673 gtk_notebook_draw_tab (notebook, notebook->cur_page, area);
4677 gtk_notebook_draw_tab (GtkNotebook *notebook,
4678 GtkNotebookPage *page,
4681 GtkNotebookPrivate *priv;
4682 GdkRectangle child_area;
4683 GdkRectangle page_area;
4684 GtkStateType state_type;
4685 GtkPositionType gap_side;
4689 if (!NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) ||
4690 !GTK_WIDGET_MAPPED (page->tab_label) ||
4691 (page->allocation.width == 0) || (page->allocation.height == 0))
4694 widget = GTK_WIDGET (notebook);
4695 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
4697 if (priv->operation == DRAG_OPERATION_REORDER && page == notebook->cur_page)
4698 window = priv->drag_window;
4700 window = widget->window;
4702 page_area.x = page->allocation.x;
4703 page_area.y = page->allocation.y;
4704 page_area.width = page->allocation.width;
4705 page_area.height = page->allocation.height;
4707 if (gdk_rectangle_intersect (&page_area, area, &child_area))
4709 gap_side = get_tab_gap_pos (notebook);
4711 if (notebook->cur_page == page)
4712 state_type = GTK_STATE_NORMAL;
4714 state_type = GTK_STATE_ACTIVE;
4716 gtk_paint_extension (widget->style, window,
4717 state_type, GTK_SHADOW_OUT,
4718 area, widget, "tab",
4719 page_area.x, page_area.y,
4720 page_area.width, page_area.height,
4726 gtk_notebook_draw_arrow (GtkNotebook *notebook,
4727 GtkNotebookArrow nbarrow)
4729 GtkStateType state_type;
4730 GtkShadowType shadow_type;
4732 GdkRectangle arrow_rect;
4734 gboolean is_rtl, left;
4736 if (GTK_WIDGET_DRAWABLE (notebook))
4738 gint scroll_arrow_hlength;
4739 gint scroll_arrow_vlength;
4742 gtk_notebook_get_arrow_rect (notebook, &arrow_rect, nbarrow);
4744 widget = GTK_WIDGET (notebook);
4746 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
4747 left = (ARROW_IS_LEFT (nbarrow) && !is_rtl) ||
4748 (!ARROW_IS_LEFT (nbarrow) && is_rtl);
4750 gtk_widget_style_get (widget,
4751 "scroll-arrow-hlength", &scroll_arrow_hlength,
4752 "scroll-arrow-vlength", &scroll_arrow_vlength,
4755 if (notebook->in_child == nbarrow)
4757 if (notebook->click_child == nbarrow)
4758 state_type = GTK_STATE_ACTIVE;
4760 state_type = GTK_STATE_PRELIGHT;
4763 state_type = GTK_WIDGET_STATE (widget);
4765 if (notebook->click_child == nbarrow)
4766 shadow_type = GTK_SHADOW_IN;
4768 shadow_type = GTK_SHADOW_OUT;
4770 if (notebook->focus_tab &&
4771 !gtk_notebook_search_page (notebook, notebook->focus_tab,
4772 left ? STEP_PREV : STEP_NEXT, TRUE))
4774 shadow_type = GTK_SHADOW_ETCHED_IN;
4775 state_type = GTK_STATE_INSENSITIVE;
4778 if (notebook->tab_pos == GTK_POS_LEFT ||
4779 notebook->tab_pos == GTK_POS_RIGHT)
4781 arrow = (ARROW_IS_LEFT (nbarrow) ? GTK_ARROW_UP : GTK_ARROW_DOWN);
4782 arrow_size = scroll_arrow_vlength;
4786 arrow = (ARROW_IS_LEFT (nbarrow) ? GTK_ARROW_LEFT : GTK_ARROW_RIGHT);
4787 arrow_size = scroll_arrow_hlength;
4790 gtk_paint_arrow (widget->style, widget->window, state_type,
4791 shadow_type, NULL, widget, "notebook",
4792 arrow, TRUE, arrow_rect.x, arrow_rect.y,
4793 arrow_size, arrow_size);
4797 /* Private GtkNotebook Size Allocate Functions:
4799 * gtk_notebook_tab_space
4800 * gtk_notebook_calculate_shown_tabs
4801 * gtk_notebook_calculate_tabs_allocation
4802 * gtk_notebook_pages_allocate
4803 * gtk_notebook_page_allocate
4804 * gtk_notebook_calc_tabs
4807 gtk_notebook_tab_space (GtkNotebook *notebook,
4808 gboolean *show_arrows,
4813 GtkNotebookPrivate *priv;
4816 gint tab_pos = get_effective_tab_pos (notebook);
4819 gint scroll_arrow_hlength;
4820 gint scroll_arrow_vlength;
4822 widget = GTK_WIDGET (notebook);
4823 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
4824 children = notebook->children;
4826 gtk_widget_style_get (GTK_WIDGET (notebook),
4827 "arrow-spacing", &arrow_spacing,
4828 "scroll-arrow-hlength", &scroll_arrow_hlength,
4829 "scroll-arrow-vlength", &scroll_arrow_vlength,
4835 case GTK_POS_BOTTOM:
4836 *min = widget->allocation.x + GTK_CONTAINER (notebook)->border_width;
4837 *max = widget->allocation.x + widget->allocation.width - GTK_CONTAINER (notebook)->border_width;
4841 GtkNotebookPage *page;
4843 page = children->data;
4844 children = children->next;
4846 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) &&
4847 GTK_WIDGET_VISIBLE (page->child))
4848 *tab_space += page->requisition.width;
4853 *min = widget->allocation.y + GTK_CONTAINER (notebook)->border_width;
4854 *max = widget->allocation.y + widget->allocation.height - GTK_CONTAINER (notebook)->border_width;
4858 GtkNotebookPage *page;
4860 page = children->data;
4861 children = children->next;
4863 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) &&
4864 GTK_WIDGET_VISIBLE (page->child))
4865 *tab_space += page->requisition.height;
4870 if (!notebook->scrollable)
4871 *show_arrows = FALSE;
4874 gtk_widget_style_get (widget, "tab-overlap", &tab_overlap, NULL);
4879 case GTK_POS_BOTTOM:
4880 if (*tab_space > *max - *min - tab_overlap)
4882 *show_arrows = TRUE;
4884 /* take arrows into account */
4885 *tab_space = widget->allocation.width - tab_overlap -
4886 2 * GTK_CONTAINER (notebook)->border_width;
4888 if (notebook->has_after_previous)
4890 *tab_space -= arrow_spacing + scroll_arrow_hlength;
4891 *max -= arrow_spacing + scroll_arrow_hlength;
4894 if (notebook->has_after_next)
4896 *tab_space -= arrow_spacing + scroll_arrow_hlength;
4897 *max -= arrow_spacing + scroll_arrow_hlength;
4900 if (notebook->has_before_previous)
4902 *tab_space -= arrow_spacing + scroll_arrow_hlength;
4903 *min += arrow_spacing + scroll_arrow_hlength;
4906 if (notebook->has_before_next)
4908 *tab_space -= arrow_spacing + scroll_arrow_hlength;
4909 *min += arrow_spacing + scroll_arrow_hlength;
4915 if (*tab_space > *max - *min - tab_overlap)
4917 *show_arrows = TRUE;
4919 /* take arrows into account */
4920 *tab_space = widget->allocation.height -
4921 tab_overlap - 2 * GTK_CONTAINER (notebook)->border_width;
4923 if (notebook->has_after_previous || notebook->has_after_next)
4925 *tab_space -= arrow_spacing + scroll_arrow_vlength;
4926 *max -= arrow_spacing + scroll_arrow_vlength;
4929 if (notebook->has_before_previous || notebook->has_before_next)
4931 *tab_space -= arrow_spacing + scroll_arrow_vlength;
4932 *min += arrow_spacing + scroll_arrow_vlength;
4941 gtk_notebook_calculate_shown_tabs (GtkNotebook *notebook,
4942 gboolean show_arrows,
4948 gint *remaining_space)
4951 GtkContainer *container;
4953 GtkNotebookPage *page;
4954 gint tab_pos, tab_overlap;
4956 widget = GTK_WIDGET (notebook);
4957 container = GTK_CONTAINER (notebook);
4958 gtk_widget_style_get (widget, "tab-overlap", &tab_overlap, NULL);
4959 tab_pos = get_effective_tab_pos (notebook);
4961 if (show_arrows) /* first_tab <- focus_tab */
4963 *remaining_space = tab_space;
4965 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, notebook->cur_page) &&
4966 GTK_WIDGET_VISIBLE (notebook->cur_page->child))
4968 gtk_notebook_calc_tabs (notebook,
4969 notebook->focus_tab,
4970 &(notebook->focus_tab),
4971 remaining_space, STEP_NEXT);
4974 if (*remaining_space <= 0)
4977 notebook->first_tab = notebook->focus_tab;
4978 *last_child = gtk_notebook_search_page (notebook, notebook->focus_tab,
4985 if (notebook->first_tab && notebook->first_tab != notebook->focus_tab)
4987 /* Is first_tab really predecessor of focus_tab? */
4988 page = notebook->first_tab->data;
4989 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) &&
4990 GTK_WIDGET_VISIBLE (page->child))
4991 for (children = notebook->focus_tab;
4992 children && children != notebook->first_tab;
4993 children = gtk_notebook_search_page (notebook,
5001 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, notebook->cur_page))
5002 notebook->first_tab = notebook->focus_tab;
5004 notebook->first_tab = gtk_notebook_search_page (notebook, notebook->focus_tab,
5008 /* calculate shown tabs counting backwards from the focus tab */
5009 gtk_notebook_calc_tabs (notebook,
5010 gtk_notebook_search_page (notebook,
5011 notebook->focus_tab,
5014 &(notebook->first_tab), remaining_space,
5017 if (*remaining_space < 0)
5019 notebook->first_tab =
5020 gtk_notebook_search_page (notebook, notebook->first_tab,
5022 if (!notebook->first_tab)
5023 notebook->first_tab = notebook->focus_tab;
5025 *last_child = gtk_notebook_search_page (notebook, notebook->focus_tab,
5028 else /* focus_tab -> end */
5030 if (!notebook->first_tab)
5031 notebook->first_tab = gtk_notebook_search_page (notebook,
5036 gtk_notebook_calc_tabs (notebook,
5037 gtk_notebook_search_page (notebook,
5038 notebook->focus_tab,
5041 &children, remaining_space, STEP_NEXT);
5043 if (*remaining_space <= 0)
5044 *last_child = children;
5045 else /* start <- first_tab */
5050 gtk_notebook_calc_tabs (notebook,
5051 gtk_notebook_search_page (notebook,
5052 notebook->first_tab,
5055 &children, remaining_space, STEP_PREV);
5057 if (*remaining_space == 0)
5058 notebook->first_tab = children;
5060 notebook->first_tab = gtk_notebook_search_page(notebook,
5068 if (*remaining_space < 0)
5070 /* calculate number of tabs */
5071 *remaining_space = - (*remaining_space);
5074 for (children = notebook->first_tab;
5075 children && children != *last_child;
5076 children = gtk_notebook_search_page (notebook, children,
5081 *remaining_space = 0;
5083 /* unmap all non-visible tabs */
5084 for (children = gtk_notebook_search_page (notebook, NULL,
5086 children && children != notebook->first_tab;
5087 children = gtk_notebook_search_page (notebook, children,
5090 page = children->data;
5092 if (page->tab_label &&
5093 NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page))
5094 gtk_widget_set_child_visible (page->tab_label, FALSE);
5097 for (children = *last_child; children;
5098 children = gtk_notebook_search_page (notebook, children,
5101 page = children->data;
5103 if (page->tab_label &&
5104 NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page))
5105 gtk_widget_set_child_visible (page->tab_label, FALSE);
5108 else /* !show_arrows */
5113 *remaining_space = max - min - tab_overlap - tab_space;
5114 children = notebook->children;
5115 notebook->first_tab = gtk_notebook_search_page (notebook, NULL,
5119 page = children->data;
5120 children = children->next;
5122 if (!NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) ||
5123 !GTK_WIDGET_VISIBLE (page->child))
5132 /* if notebook is homogeneous, all tabs are expanded */
5133 if (notebook->homogeneous && *n)
5139 get_allocate_at_bottom (GtkWidget *widget,
5140 gint search_direction)
5142 gboolean is_rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
5143 gboolean tab_pos = get_effective_tab_pos (GTK_NOTEBOOK (widget));
5148 case GTK_POS_BOTTOM:
5150 return (search_direction == STEP_PREV);
5152 return (search_direction == STEP_NEXT);
5157 return (search_direction == STEP_PREV);
5165 gtk_notebook_calculate_tabs_allocation (GtkNotebook *notebook,
5170 gint *remaining_space,
5171 gint *expanded_tabs,
5176 GtkContainer *container;
5177 GtkNotebookPrivate *priv;
5178 GtkNotebookPage *page;
5179 gboolean allocate_at_bottom;
5180 gint tab_overlap, tab_pos, tab_extra_space;
5181 gint left_x, right_x, top_y, bottom_y, anchor;
5182 gint xthickness, ythickness;
5183 gboolean gap_left, packing_changed;
5184 GtkAllocation child_allocation = { 0, };
5186 widget = GTK_WIDGET (notebook);
5187 container = GTK_CONTAINER (notebook);
5188 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
5189 gtk_widget_style_get (widget, "tab-overlap", &tab_overlap, NULL);
5190 tab_pos = get_effective_tab_pos (notebook);
5191 allocate_at_bottom = get_allocate_at_bottom (widget, direction);
5194 child_allocation.x = widget->allocation.x + container->border_width;
5195 child_allocation.y = widget->allocation.y + container->border_width;
5197 xthickness = widget->style->xthickness;
5198 ythickness = widget->style->ythickness;
5202 case GTK_POS_BOTTOM:
5203 child_allocation.y = widget->allocation.y + widget->allocation.height -
5204 notebook->cur_page->requisition.height - container->border_width;
5207 child_allocation.x = (allocate_at_bottom) ? max : min;
5208 child_allocation.height = notebook->cur_page->requisition.height;
5209 anchor = child_allocation.x;
5213 child_allocation.x = widget->allocation.x + widget->allocation.width -
5214 notebook->cur_page->requisition.width - container->border_width;
5217 child_allocation.y = (allocate_at_bottom) ? max : min;
5218 child_allocation.width = notebook->cur_page->requisition.width;
5219 anchor = child_allocation.y;
5223 left_x = CLAMP (priv->mouse_x - priv->drag_offset_x,
5224 min, max - notebook->cur_page->allocation.width);
5225 top_y = CLAMP (priv->mouse_y - priv->drag_offset_y,
5226 min, max - notebook->cur_page->allocation.height);
5227 right_x = left_x + notebook->cur_page->allocation.width;
5228 bottom_y = top_y + notebook->cur_page->allocation.height;
5229 gap_left = packing_changed = FALSE;
5231 while (*children && *children != last_child)
5233 page = (*children)->data;
5235 if (direction == STEP_NEXT && page->pack != GTK_PACK_START)
5239 else if (priv->operation == DRAG_OPERATION_REORDER)
5240 packing_changed = TRUE;
5243 if (direction == STEP_NEXT)
5244 *children = gtk_notebook_search_page (notebook, *children, direction, TRUE);
5247 *children = (*children)->next;
5249 if (page->pack != GTK_PACK_END || !GTK_WIDGET_VISIBLE (page->child))
5253 if (!NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page))
5256 tab_extra_space = 0;
5257 if (*expanded_tabs && (showarrow || page->expand || notebook->homogeneous))
5259 tab_extra_space = *remaining_space / *expanded_tabs;
5260 *remaining_space -= tab_extra_space;
5267 case GTK_POS_BOTTOM:
5268 child_allocation.width = page->requisition.width + tab_overlap + tab_extra_space;
5270 /* make sure that the reordered tab doesn't go past the last position */
5271 if (priv->operation == DRAG_OPERATION_REORDER &&
5272 !gap_left && packing_changed)
5274 if (!allocate_at_bottom)
5276 if ((notebook->cur_page->pack == GTK_PACK_START && left_x >= anchor) ||
5277 (notebook->cur_page->pack == GTK_PACK_END && left_x < anchor))
5279 left_x = priv->drag_window_x = anchor;
5280 anchor += notebook->cur_page->allocation.width - tab_overlap;
5285 if ((notebook->cur_page->pack == GTK_PACK_START && right_x <= anchor) ||
5286 (notebook->cur_page->pack == GTK_PACK_END && right_x > anchor))
5288 anchor -= notebook->cur_page->allocation.width;
5289 left_x = priv->drag_window_x = anchor;
5290 anchor += tab_overlap;
5297 if (priv->operation == DRAG_OPERATION_REORDER && page == notebook->cur_page)
5299 priv->drag_window_x = left_x;
5300 priv->drag_window_y = child_allocation.y;
5304 if (allocate_at_bottom)
5305 anchor -= child_allocation.width;
5307 if (priv->operation == DRAG_OPERATION_REORDER && page->pack == notebook->cur_page->pack)
5309 if (!allocate_at_bottom &&
5311 left_x <= anchor + child_allocation.width / 2)
5312 anchor += notebook->cur_page->allocation.width - tab_overlap;
5313 else if (allocate_at_bottom &&
5314 right_x >= anchor + child_allocation.width / 2 &&
5315 right_x <= anchor + child_allocation.width)
5316 anchor -= notebook->cur_page->allocation.width - tab_overlap;
5319 child_allocation.x = anchor;
5325 child_allocation.height = page->requisition.height + tab_overlap + tab_extra_space;
5327 /* make sure that the reordered tab doesn't go past the last position */
5328 if (priv->operation == DRAG_OPERATION_REORDER &&
5329 !gap_left && packing_changed)
5331 if (!allocate_at_bottom &&
5332 ((notebook->cur_page->pack == GTK_PACK_START && top_y >= anchor) ||
5333 (notebook->cur_page->pack == GTK_PACK_END && top_y < anchor)))
5335 top_y = priv->drag_window_y = anchor;
5336 anchor += notebook->cur_page->allocation.height - tab_overlap;
5342 if (priv->operation == DRAG_OPERATION_REORDER && page == notebook->cur_page)
5344 priv->drag_window_x = child_allocation.x;
5345 priv->drag_window_y = top_y;
5349 if (allocate_at_bottom)
5350 anchor -= child_allocation.height;
5352 if (priv->operation == DRAG_OPERATION_REORDER && page->pack == notebook->cur_page->pack)
5354 if (!allocate_at_bottom &&
5356 top_y <= anchor + child_allocation.height / 2)
5357 anchor += notebook->cur_page->allocation.height - tab_overlap;
5358 else if (allocate_at_bottom &&
5359 bottom_y >= anchor + child_allocation.height / 2 &&
5360 bottom_y <= anchor + child_allocation.height)
5361 anchor -= notebook->cur_page->allocation.height - tab_overlap;
5364 child_allocation.y = anchor;
5370 page->allocation = child_allocation;
5372 if ((page == priv->detached_tab && priv->operation == DRAG_OPERATION_DETACH) ||
5373 (page == notebook->cur_page && priv->operation == DRAG_OPERATION_REORDER))
5375 /* needs to be allocated at 0,0
5376 * to be shown in the drag window */
5377 page->allocation.x = 0;
5378 page->allocation.y = 0;
5381 if (page != notebook->cur_page)
5386 page->allocation.y += ythickness;
5388 case GTK_POS_BOTTOM:
5389 page->allocation.height = MAX (1, page->allocation.height - ythickness);
5392 page->allocation.x += xthickness;
5395 page->allocation.width = MAX (1, page->allocation.width - xthickness);
5400 /* calculate whether to leave a gap based on reorder operation or not */
5404 case GTK_POS_BOTTOM:
5405 if (priv->operation != DRAG_OPERATION_REORDER ||
5406 (priv->operation == DRAG_OPERATION_REORDER && page != notebook->cur_page))
5408 if (priv->operation == DRAG_OPERATION_REORDER)
5410 if (page->pack == notebook->cur_page->pack &&
5411 !allocate_at_bottom &&
5412 left_x > anchor + child_allocation.width / 2 &&
5413 left_x <= anchor + child_allocation.width)
5414 anchor += notebook->cur_page->allocation.width - tab_overlap;
5415 else if (page->pack == notebook->cur_page->pack &&
5416 allocate_at_bottom &&
5417 right_x >= anchor &&
5418 right_x <= anchor + child_allocation.width / 2)
5419 anchor -= notebook->cur_page->allocation.width - tab_overlap;
5422 if (!allocate_at_bottom)
5423 anchor += child_allocation.width - tab_overlap;
5425 anchor += tab_overlap;
5431 if (priv->operation != DRAG_OPERATION_REORDER ||
5432 (priv->operation == DRAG_OPERATION_REORDER && page != notebook->cur_page))
5434 if (priv->operation == DRAG_OPERATION_REORDER)
5436 if (page->pack == notebook->cur_page->pack &&
5437 !allocate_at_bottom &&
5438 top_y >= anchor + child_allocation.height / 2 &&
5439 top_y <= anchor + child_allocation.height)
5440 anchor += notebook->cur_page->allocation.height - tab_overlap;
5441 else if (page->pack == notebook->cur_page->pack &&
5442 allocate_at_bottom &&
5443 bottom_y >= anchor &&
5444 bottom_y <= anchor + child_allocation.height / 2)
5445 anchor -= notebook->cur_page->allocation.height - tab_overlap;
5448 if (!allocate_at_bottom)
5449 anchor += child_allocation.height - tab_overlap;
5451 anchor += tab_overlap;
5457 /* set child visible */
5458 if (page->tab_label)
5459 gtk_widget_set_child_visible (page->tab_label, TRUE);
5462 /* Don't move the current tab past the last position during tabs reordering */
5464 priv->operation == DRAG_OPERATION_REORDER &&
5465 ((direction == STEP_NEXT && notebook->cur_page->pack == GTK_PACK_START) ||
5466 ((direction == STEP_PREV || packing_changed) && notebook->cur_page->pack == GTK_PACK_END)))
5471 case GTK_POS_BOTTOM:
5472 if (allocate_at_bottom)
5473 anchor -= notebook->cur_page->allocation.width;
5475 if ((!allocate_at_bottom && priv->drag_window_x > anchor) ||
5476 (allocate_at_bottom && priv->drag_window_x < anchor))
5477 priv->drag_window_x = anchor;
5481 if (allocate_at_bottom)
5482 anchor -= notebook->cur_page->allocation.height;
5484 if ((!allocate_at_bottom && priv->drag_window_y > anchor) ||
5485 (allocate_at_bottom && priv->drag_window_y < anchor))
5486 priv->drag_window_y = anchor;
5493 gtk_notebook_pages_allocate (GtkNotebook *notebook)
5495 GList *children = NULL;
5496 GList *last_child = NULL;
5497 gboolean showarrow = FALSE;
5498 gint tab_space, min, max, remaining_space;
5499 gint expanded_tabs, operation;
5500 gboolean tab_allocations_changed = FALSE;
5502 if (!notebook->show_tabs || !notebook->children || !notebook->cur_page)
5505 min = max = tab_space = remaining_space = 0;
5508 gtk_notebook_tab_space (notebook, &showarrow,
5509 &min, &max, &tab_space);
5511 gtk_notebook_calculate_shown_tabs (notebook, showarrow,
5512 min, max, tab_space, &last_child,
5513 &expanded_tabs, &remaining_space);
5515 children = notebook->first_tab;
5516 gtk_notebook_calculate_tabs_allocation (notebook, &children, last_child,
5517 showarrow, STEP_NEXT,
5518 &remaining_space, &expanded_tabs, min, max);
5519 if (children && children != last_child)
5521 children = notebook->children;
5522 gtk_notebook_calculate_tabs_allocation (notebook, &children, last_child,
5523 showarrow, STEP_PREV,
5524 &remaining_space, &expanded_tabs, min, max);
5527 children = notebook->children;
5531 if (gtk_notebook_page_allocate (notebook, GTK_NOTEBOOK_PAGE (children)))
5532 tab_allocations_changed = TRUE;
5533 children = children->next;
5536 operation = GTK_NOTEBOOK_GET_PRIVATE (notebook)->operation;
5538 if (!notebook->first_tab)
5539 notebook->first_tab = notebook->children;
5541 if (tab_allocations_changed)
5542 gtk_notebook_redraw_tabs (notebook);
5546 gtk_notebook_page_allocate (GtkNotebook *notebook,
5547 GtkNotebookPage *page)
5549 GtkWidget *widget = GTK_WIDGET (notebook);
5550 GtkAllocation child_allocation;
5551 GtkRequisition tab_requisition;
5557 gint tab_pos = get_effective_tab_pos (notebook);
5558 gboolean tab_allocation_changed;
5560 if (!page->tab_label)
5563 xthickness = widget->style->xthickness;
5564 ythickness = widget->style->ythickness;
5566 gtk_widget_get_child_requisition (page->tab_label, &tab_requisition);
5567 gtk_widget_style_get (widget,
5568 "focus-line-width", &focus_width,
5569 "tab-curvature", &tab_curvature,
5574 case GTK_POS_BOTTOM:
5575 padding = tab_curvature + focus_width + notebook->tab_hborder;
5578 child_allocation.x = xthickness + focus_width + notebook->tab_hborder;
5579 child_allocation.width = MAX (1, page->allocation.width - 2 * child_allocation.x);
5580 child_allocation.x += page->allocation.x;
5584 child_allocation.x = page->allocation.x +
5585 (page->allocation.width - tab_requisition.width) / 2;
5587 child_allocation.width = tab_requisition.width;
5590 child_allocation.y = notebook->tab_vborder + focus_width + page->allocation.y;
5592 if (tab_pos == GTK_POS_TOP)
5593 child_allocation.y += ythickness;
5595 child_allocation.height = MAX (1, (page->allocation.height - ythickness -
5596 2 * (notebook->tab_vborder + focus_width)));
5600 padding = tab_curvature + focus_width + notebook->tab_vborder;
5603 child_allocation.y = ythickness + padding;
5604 child_allocation.height = MAX (1, (page->allocation.height -
5605 2 * child_allocation.y));
5606 child_allocation.y += page->allocation.y;
5610 child_allocation.y = page->allocation.y +
5611 (page->allocation.height - tab_requisition.height) / 2;
5613 child_allocation.height = tab_requisition.height;
5616 child_allocation.x = notebook->tab_hborder + focus_width + page->allocation.x;
5618 if (tab_pos == GTK_POS_LEFT)
5619 child_allocation.x += xthickness;
5621 child_allocation.width = MAX (1, (page->allocation.width - xthickness -
5622 2 * (notebook->tab_hborder + focus_width)));
5626 tab_allocation_changed = (child_allocation.x != page->tab_label->allocation.x ||
5627 child_allocation.y != page->tab_label->allocation.y ||
5628 child_allocation.width != page->tab_label->allocation.width ||
5629 child_allocation.height != page->tab_label->allocation.height);
5631 gtk_widget_size_allocate (page->tab_label, &child_allocation);
5633 return tab_allocation_changed;
5637 gtk_notebook_calc_tabs (GtkNotebook *notebook,
5643 GtkNotebookPage *page = NULL;
5645 GList *last_list = NULL;
5646 GList *last_calculated_child = NULL;
5648 gint tab_pos = get_effective_tab_pos (notebook);
5649 guint real_direction;
5655 pack = GTK_NOTEBOOK_PAGE (start)->pack;
5656 if (pack == GTK_PACK_END)
5657 real_direction = (direction == STEP_PREV) ? STEP_NEXT : STEP_PREV;
5659 real_direction = direction;
5666 case GTK_POS_BOTTOM:
5669 page = children->data;
5670 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) &&
5671 GTK_WIDGET_VISIBLE (page->child))
5673 if (page->pack == pack)
5675 *tab_space -= page->requisition.width;
5676 if (*tab_space < 0 || children == *end)
5680 *tab_space = - (*tab_space +
5681 page->requisition.width);
5683 if (*tab_space == 0 && direction == STEP_PREV)
5684 children = last_calculated_child;
5691 last_calculated_child = children;
5693 last_list = children;
5695 if (real_direction == STEP_NEXT)
5696 children = children->next;
5698 children = children->prev;
5705 page = children->data;
5706 if (NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page) &&
5707 GTK_WIDGET_VISIBLE (page->child))
5709 if (page->pack == pack)
5711 *tab_space -= page->requisition.height;
5712 if (*tab_space < 0 || children == *end)
5716 *tab_space = - (*tab_space +
5717 page->requisition.height);
5719 if (*tab_space == 0 && direction == STEP_PREV)
5720 children = last_calculated_child;
5727 last_calculated_child = children;
5729 last_list = children;
5731 if (real_direction == STEP_NEXT)
5732 children = children->next;
5734 children = children->prev;
5738 if (real_direction == STEP_PREV)
5740 pack = (pack == GTK_PACK_END) ? GTK_PACK_START : GTK_PACK_END;
5741 real_direction = STEP_PREV;
5742 children = last_list;
5747 gtk_notebook_update_tab_states (GtkNotebook *notebook)
5751 for (list = notebook->children; list != NULL; list = list->next)
5753 GtkNotebookPage *page = list->data;
5755 if (page->tab_label)
5757 if (page == notebook->cur_page)
5758 gtk_widget_set_state (page->tab_label, GTK_STATE_NORMAL);
5760 gtk_widget_set_state (page->tab_label, GTK_STATE_ACTIVE);
5765 /* Private GtkNotebook Page Switch Methods:
5767 * gtk_notebook_real_switch_page
5770 gtk_notebook_real_switch_page (GtkNotebook *notebook,
5771 GtkNotebookPage *page,
5774 if (notebook->cur_page == page || !GTK_WIDGET_VISIBLE (page->child))
5777 if (notebook->cur_page)
5778 gtk_widget_set_child_visible (notebook->cur_page->child, FALSE);
5780 notebook->cur_page = page;
5782 if (!notebook->focus_tab ||
5783 notebook->focus_tab->data != (gpointer) notebook->cur_page)
5784 notebook->focus_tab =
5785 g_list_find (notebook->children, notebook->cur_page);
5787 gtk_widget_set_child_visible (notebook->cur_page->child, TRUE);
5789 /* If the focus was on the previous page, move it to the first
5790 * element on the new page, if possible, or if not, to the
5793 if (notebook->child_has_focus)
5795 if (notebook->cur_page->last_focus_child &&
5796 gtk_widget_is_ancestor (notebook->cur_page->last_focus_child, notebook->cur_page->child))
5797 gtk_widget_grab_focus (notebook->cur_page->last_focus_child);
5799 if (!gtk_widget_child_focus (notebook->cur_page->child, GTK_DIR_TAB_FORWARD))
5800 gtk_widget_grab_focus (GTK_WIDGET (notebook));
5803 gtk_notebook_update_tab_states (notebook);
5804 gtk_widget_queue_resize (GTK_WIDGET (notebook));
5805 g_object_notify (G_OBJECT (notebook), "page");
5808 /* Private GtkNotebook Page Switch Functions:
5810 * gtk_notebook_switch_page
5811 * gtk_notebook_page_select
5812 * gtk_notebook_switch_focus_tab
5813 * gtk_notebook_menu_switch_page
5816 gtk_notebook_switch_page (GtkNotebook *notebook,
5817 GtkNotebookPage *page)
5821 if (notebook->cur_page == page)
5824 page_num = g_list_index (notebook->children, page);
5826 g_signal_emit (notebook,
5827 notebook_signals[SWITCH_PAGE],
5834 gtk_notebook_page_select (GtkNotebook *notebook,
5835 gboolean move_focus)
5837 GtkNotebookPage *page;
5838 GtkDirectionType dir = GTK_DIR_DOWN; /* Quiet GCC */
5839 gint tab_pos = get_effective_tab_pos (notebook);
5841 if (!notebook->focus_tab)
5844 page = notebook->focus_tab->data;
5845 gtk_notebook_switch_page (notebook, page);
5854 case GTK_POS_BOTTOM:
5858 dir = GTK_DIR_RIGHT;
5865 if (gtk_widget_child_focus (page->child, dir))
5872 gtk_notebook_switch_focus_tab (GtkNotebook *notebook,
5876 GtkNotebookPage *page;
5878 if (notebook->focus_tab == new_child)
5881 old_child = notebook->focus_tab;
5882 notebook->focus_tab = new_child;
5884 if (notebook->scrollable)
5885 gtk_notebook_redraw_arrows (notebook);
5887 if (!notebook->show_tabs || !notebook->focus_tab)
5890 page = notebook->focus_tab->data;
5891 if (GTK_WIDGET_MAPPED (page->tab_label))
5892 gtk_notebook_redraw_tabs (notebook);
5894 gtk_notebook_pages_allocate (notebook);
5896 gtk_notebook_switch_page (notebook, page);
5900 gtk_notebook_menu_switch_page (GtkWidget *widget,
5901 GtkNotebookPage *page)
5903 GtkNotebook *notebook;
5907 notebook = GTK_NOTEBOOK (gtk_menu_get_attach_widget
5908 (GTK_MENU (widget->parent)));
5910 if (notebook->cur_page == page)
5914 children = notebook->children;
5915 while (children && children->data != page)
5917 children = children->next;
5921 g_signal_emit (notebook,
5922 notebook_signals[SWITCH_PAGE],
5928 /* Private GtkNotebook Menu Functions:
5930 * gtk_notebook_menu_item_create
5931 * gtk_notebook_menu_label_unparent
5932 * gtk_notebook_menu_detacher
5935 gtk_notebook_menu_item_create (GtkNotebook *notebook,
5938 GtkNotebookPage *page;
5939 GtkWidget *menu_item;
5942 if (page->default_menu)
5944 if (GTK_IS_LABEL (page->tab_label))
5945 page->menu_label = gtk_label_new (GTK_LABEL (page->tab_label)->label);
5947 page->menu_label = gtk_label_new ("");
5948 gtk_misc_set_alignment (GTK_MISC (page->menu_label), 0.0, 0.5);
5951 gtk_widget_show (page->menu_label);
5952 menu_item = gtk_menu_item_new ();
5953 gtk_container_add (GTK_CONTAINER (menu_item), page->menu_label);
5954 gtk_menu_shell_insert (GTK_MENU_SHELL (notebook->menu), menu_item,
5955 gtk_notebook_real_page_position (notebook, list));
5956 g_signal_connect (menu_item, "activate",
5957 G_CALLBACK (gtk_notebook_menu_switch_page), page);
5958 if (GTK_WIDGET_VISIBLE (page->child))
5959 gtk_widget_show (menu_item);
5963 gtk_notebook_menu_label_unparent (GtkWidget *widget,
5966 gtk_widget_unparent (GTK_BIN (widget)->child);
5967 GTK_BIN (widget)->child = NULL;
5971 gtk_notebook_menu_detacher (GtkWidget *widget,
5974 GtkNotebook *notebook;
5976 notebook = GTK_NOTEBOOK (widget);
5977 g_return_if_fail (notebook->menu == (GtkWidget*) menu);
5979 notebook->menu = NULL;
5982 /* Private GtkNotebook Setter Functions:
5984 * gtk_notebook_set_homogeneous_tabs_internal
5985 * gtk_notebook_set_tab_border_internal
5986 * gtk_notebook_set_tab_hborder_internal
5987 * gtk_notebook_set_tab_vborder_internal
5990 gtk_notebook_set_homogeneous_tabs_internal (GtkNotebook *notebook,
5991 gboolean homogeneous)
5993 if (homogeneous == notebook->homogeneous)
5996 notebook->homogeneous = homogeneous;
5997 gtk_widget_queue_resize (GTK_WIDGET (notebook));
5999 g_object_notify (G_OBJECT (notebook), "homogeneous");
6003 gtk_notebook_set_tab_border_internal (GtkNotebook *notebook,
6006 notebook->tab_hborder = border_width;
6007 notebook->tab_vborder = border_width;
6009 if (GTK_WIDGET_VISIBLE (notebook) && notebook->show_tabs)
6010 gtk_widget_queue_resize (GTK_WIDGET (notebook));
6012 g_object_freeze_notify (G_OBJECT (notebook));
6013 g_object_notify (G_OBJECT (notebook), "tab-hborder");
6014 g_object_notify (G_OBJECT (notebook), "tab-vborder");
6015 g_object_thaw_notify (G_OBJECT (notebook));
6019 gtk_notebook_set_tab_hborder_internal (GtkNotebook *notebook,
6022 if (notebook->tab_hborder == tab_hborder)
6025 notebook->tab_hborder = tab_hborder;
6027 if (GTK_WIDGET_VISIBLE (notebook) && notebook->show_tabs)
6028 gtk_widget_queue_resize (GTK_WIDGET (notebook));
6030 g_object_notify (G_OBJECT (notebook), "tab-hborder");
6034 gtk_notebook_set_tab_vborder_internal (GtkNotebook *notebook,
6037 if (notebook->tab_vborder == tab_vborder)
6040 notebook->tab_vborder = tab_vborder;
6042 if (GTK_WIDGET_VISIBLE (notebook) && notebook->show_tabs)
6043 gtk_widget_queue_resize (GTK_WIDGET (notebook));
6045 g_object_notify (G_OBJECT (notebook), "tab-vborder");
6048 /* Public GtkNotebook Page Insert/Remove Methods :
6050 * gtk_notebook_append_page
6051 * gtk_notebook_append_page_menu
6052 * gtk_notebook_prepend_page
6053 * gtk_notebook_prepend_page_menu
6054 * gtk_notebook_insert_page
6055 * gtk_notebook_insert_page_menu
6056 * gtk_notebook_remove_page
6059 * gtk_notebook_append_page:
6060 * @notebook: a #GtkNotebook
6061 * @child: the #GtkWidget to use as the contents of the page.
6062 * @tab_label: the #GtkWidget to be used as the label for the page,
6063 * or %NULL to use the default label, 'page N'.
6065 * Appends a page to @notebook.
6067 * Return value: the index (starting from 0) of the appended
6068 * page in the notebook, or -1 if function fails
6071 gtk_notebook_append_page (GtkNotebook *notebook,
6073 GtkWidget *tab_label)
6075 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6076 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6077 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6079 return gtk_notebook_insert_page_menu (notebook, child, tab_label, NULL, -1);
6083 * gtk_notebook_append_page_menu:
6084 * @notebook: a #GtkNotebook
6085 * @child: the #GtkWidget to use as the contents of the page.
6086 * @tab_label: the #GtkWidget to be used as the label for the page,
6087 * or %NULL to use the default label, 'page N'.
6088 * @menu_label: the widget to use as a label for the page-switch
6089 * menu, if that is enabled. If %NULL, and @tab_label
6090 * is a #GtkLabel or %NULL, then the menu label will be
6091 * a newly created label with the same text as @tab_label;
6092 * If @tab_label is not a #GtkLabel, @menu_label must be
6093 * specified if the page-switch menu is to be used.
6095 * Appends a page to @notebook, specifying the widget to use as the
6096 * label in the popup menu.
6098 * Return value: the index (starting from 0) of the appended
6099 * page in the notebook, or -1 if function fails
6102 gtk_notebook_append_page_menu (GtkNotebook *notebook,
6104 GtkWidget *tab_label,
6105 GtkWidget *menu_label)
6107 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6108 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6109 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6110 g_return_val_if_fail (menu_label == NULL || GTK_IS_WIDGET (menu_label), -1);
6112 return gtk_notebook_insert_page_menu (notebook, child, tab_label, menu_label, -1);
6116 * gtk_notebook_prepend_page:
6117 * @notebook: a #GtkNotebook
6118 * @child: the #GtkWidget to use as the contents of the page.
6119 * @tab_label: the #GtkWidget to be used as the label for the page,
6120 * or %NULL to use the default label, 'page N'.
6122 * Prepends a page to @notebook.
6124 * Return value: the index (starting from 0) of the prepended
6125 * page in the notebook, or -1 if function fails
6128 gtk_notebook_prepend_page (GtkNotebook *notebook,
6130 GtkWidget *tab_label)
6132 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6133 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6134 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6136 return gtk_notebook_insert_page_menu (notebook, child, tab_label, NULL, 0);
6140 * gtk_notebook_prepend_page_menu:
6141 * @notebook: a #GtkNotebook
6142 * @child: the #GtkWidget to use as the contents of the page.
6143 * @tab_label: the #GtkWidget to be used as the label for the page,
6144 * or %NULL to use the default label, 'page N'.
6145 * @menu_label: the widget to use as a label for the page-switch
6146 * menu, if that is enabled. If %NULL, and @tab_label
6147 * is a #GtkLabel or %NULL, then the menu label will be
6148 * a newly created label with the same text as @tab_label;
6149 * If @tab_label is not a #GtkLabel, @menu_label must be
6150 * specified if the page-switch menu is to be used.
6152 * Prepends a page to @notebook, specifying the widget to use as the
6153 * label in the popup menu.
6155 * Return value: the index (starting from 0) of the prepended
6156 * page in the notebook, or -1 if function fails
6159 gtk_notebook_prepend_page_menu (GtkNotebook *notebook,
6161 GtkWidget *tab_label,
6162 GtkWidget *menu_label)
6164 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6165 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6166 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6167 g_return_val_if_fail (menu_label == NULL || GTK_IS_WIDGET (menu_label), -1);
6169 return gtk_notebook_insert_page_menu (notebook, child, tab_label, menu_label, 0);
6173 * gtk_notebook_insert_page:
6174 * @notebook: a #GtkNotebook
6175 * @child: the #GtkWidget to use as the contents of the page.
6176 * @tab_label: the #GtkWidget to be used as the label for the page,
6177 * or %NULL to use the default label, 'page N'.
6178 * @position: the index (starting at 0) at which to insert the page,
6179 * or -1 to append the page after all other pages.
6181 * Insert a page into @notebook at the given position.
6183 * Return value: the index (starting from 0) of the inserted
6184 * page in the notebook, or -1 if function fails
6187 gtk_notebook_insert_page (GtkNotebook *notebook,
6189 GtkWidget *tab_label,
6192 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6193 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6194 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6196 return gtk_notebook_insert_page_menu (notebook, child, tab_label, NULL, position);
6201 gtk_notebook_page_compare_tab (gconstpointer a,
6204 return (((GtkNotebookPage *) a)->tab_label != b);
6208 gtk_notebook_mnemonic_activate_switch_page (GtkWidget *child,
6212 GtkNotebook *notebook = GTK_NOTEBOOK (data);
6215 list = g_list_find_custom (notebook->children, child,
6216 gtk_notebook_page_compare_tab);
6219 GtkNotebookPage *page = list->data;
6221 gtk_widget_grab_focus (GTK_WIDGET (notebook)); /* Do this first to avoid focusing new page */
6222 gtk_notebook_switch_page (notebook, page);
6223 focus_tabs_in (notebook);
6230 * gtk_notebook_insert_page_menu:
6231 * @notebook: a #GtkNotebook
6232 * @child: the #GtkWidget to use as the contents of the page.
6233 * @tab_label: the #GtkWidget to be used as the label for the page,
6234 * or %NULL to use the default label, 'page N'.
6235 * @menu_label: the widget to use as a label for the page-switch
6236 * menu, if that is enabled. If %NULL, and @tab_label
6237 * is a #GtkLabel or %NULL, then the menu label will be
6238 * a newly created label with the same text as @tab_label;
6239 * If @tab_label is not a #GtkLabel, @menu_label must be
6240 * specified if the page-switch menu is to be used.
6241 * @position: the index (starting at 0) at which to insert the page,
6242 * or -1 to append the page after all other pages.
6244 * Insert a page into @notebook at the given position, specifying
6245 * the widget to use as the label in the popup menu.
6247 * Return value: the index (starting from 0) of the inserted
6248 * page in the notebook
6251 gtk_notebook_insert_page_menu (GtkNotebook *notebook,
6253 GtkWidget *tab_label,
6254 GtkWidget *menu_label,
6257 GtkNotebookClass *class;
6259 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6260 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
6261 g_return_val_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label), -1);
6262 g_return_val_if_fail (menu_label == NULL || GTK_IS_WIDGET (menu_label), -1);
6264 class = GTK_NOTEBOOK_GET_CLASS (notebook);
6266 return (class->insert_page) (notebook, child, tab_label, menu_label, position);
6270 * gtk_notebook_remove_page:
6271 * @notebook: a #GtkNotebook.
6272 * @page_num: the index of a notebook page, starting
6273 * from 0. If -1, the last page will
6276 * Removes a page from the notebook given its index
6280 gtk_notebook_remove_page (GtkNotebook *notebook,
6285 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6288 list = g_list_nth (notebook->children, page_num);
6290 list = g_list_last (notebook->children);
6293 gtk_container_remove (GTK_CONTAINER (notebook),
6294 ((GtkNotebookPage *) list->data)->child);
6297 /* Public GtkNotebook Page Switch Methods :
6298 * gtk_notebook_get_current_page
6299 * gtk_notebook_page_num
6300 * gtk_notebook_set_current_page
6301 * gtk_notebook_next_page
6302 * gtk_notebook_prev_page
6305 * gtk_notebook_get_current_page:
6306 * @notebook: a #GtkNotebook
6308 * Returns the page number of the current page.
6310 * Return value: the index (starting from 0) of the current
6311 * page in the notebook. If the notebook has no pages, then
6312 * -1 will be returned.
6315 gtk_notebook_get_current_page (GtkNotebook *notebook)
6317 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6319 if (!notebook->cur_page)
6322 return g_list_index (notebook->children, notebook->cur_page);
6326 * gtk_notebook_get_nth_page:
6327 * @notebook: a #GtkNotebook
6328 * @page_num: the index of a page in the notebook, or -1
6329 * to get the last page.
6331 * Returns the child widget contained in page number @page_num.
6333 * Return value: the child widget, or %NULL if @page_num is
6337 gtk_notebook_get_nth_page (GtkNotebook *notebook,
6340 GtkNotebookPage *page;
6343 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
6346 list = g_list_nth (notebook->children, page_num);
6348 list = g_list_last (notebook->children);
6360 * gtk_notebook_get_n_pages:
6361 * @notebook: a #GtkNotebook
6363 * Gets the number of pages in a notebook.
6365 * Return value: the number of pages in the notebook.
6370 gtk_notebook_get_n_pages (GtkNotebook *notebook)
6372 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), 0);
6374 return g_list_length (notebook->children);
6378 * gtk_notebook_page_num:
6379 * @notebook: a #GtkNotebook
6380 * @child: a #GtkWidget
6382 * Finds the index of the page which contains the given child
6385 * Return value: the index of the page containing @child, or
6386 * -1 if @child is not in the notebook.
6389 gtk_notebook_page_num (GtkNotebook *notebook,
6395 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
6398 children = notebook->children;
6401 GtkNotebookPage *page = children->data;
6403 if (page->child == child)
6406 children = children->next;
6414 * gtk_notebook_set_current_page:
6415 * @notebook: a #GtkNotebook
6416 * @page_num: index of the page to switch to, starting from 0.
6417 * If negative, the last page will be used. If greater
6418 * than the number of pages in the notebook, nothing
6421 * Switches to the page number @page_num.
6423 * Note that due to historical reasons, GtkNotebook refuses
6424 * to switch to a page unless the child widget is visible.
6425 * Therefore, it is recommended to show child widgets before
6426 * adding them to a notebook.
6429 gtk_notebook_set_current_page (GtkNotebook *notebook,
6434 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6437 page_num = g_list_length (notebook->children) - 1;
6439 list = g_list_nth (notebook->children, page_num);
6441 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (list));
6445 * gtk_notebook_next_page:
6446 * @notebook: a #GtkNotebook
6448 * Switches to the next page. Nothing happens if the current page is
6452 gtk_notebook_next_page (GtkNotebook *notebook)
6456 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6458 list = g_list_find (notebook->children, notebook->cur_page);
6462 list = gtk_notebook_search_page (notebook, list, STEP_NEXT, TRUE);
6466 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (list));
6470 * gtk_notebook_prev_page:
6471 * @notebook: a #GtkNotebook
6473 * Switches to the previous page. Nothing happens if the current page
6474 * is the first page.
6477 gtk_notebook_prev_page (GtkNotebook *notebook)
6481 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6483 list = g_list_find (notebook->children, notebook->cur_page);
6487 list = gtk_notebook_search_page (notebook, list, STEP_PREV, TRUE);
6491 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (list));
6494 /* Public GtkNotebook/Tab Style Functions
6496 * gtk_notebook_set_show_border
6497 * gtk_notebook_set_show_tabs
6498 * gtk_notebook_set_tab_pos
6499 * gtk_notebook_set_homogeneous_tabs
6500 * gtk_notebook_set_tab_border
6501 * gtk_notebook_set_tab_hborder
6502 * gtk_notebook_set_tab_vborder
6503 * gtk_notebook_set_scrollable
6506 * gtk_notebook_set_show_border:
6507 * @notebook: a #GtkNotebook
6508 * @show_border: %TRUE if a bevel should be drawn around the notebook.
6510 * Sets whether a bevel will be drawn around the notebook pages.
6511 * This only has a visual effect when the tabs are not shown.
6512 * See gtk_notebook_set_show_tabs().
6515 gtk_notebook_set_show_border (GtkNotebook *notebook,
6516 gboolean show_border)
6518 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6520 if (notebook->show_border != show_border)
6522 notebook->show_border = show_border;
6524 if (GTK_WIDGET_VISIBLE (notebook))
6525 gtk_widget_queue_resize (GTK_WIDGET (notebook));
6527 g_object_notify (G_OBJECT (notebook), "show-border");
6532 * gtk_notebook_get_show_border:
6533 * @notebook: a #GtkNotebook
6535 * Returns whether a bevel will be drawn around the notebook pages. See
6536 * gtk_notebook_set_show_border().
6538 * Return value: %TRUE if the bevel is drawn
6541 gtk_notebook_get_show_border (GtkNotebook *notebook)
6543 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
6545 return notebook->show_border;
6549 * gtk_notebook_set_show_tabs:
6550 * @notebook: a #GtkNotebook
6551 * @show_tabs: %TRUE if the tabs should be shown.
6553 * Sets whether to show the tabs for the notebook or not.
6556 gtk_notebook_set_show_tabs (GtkNotebook *notebook,
6559 GtkNotebookPage *page;
6562 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6564 show_tabs = show_tabs != FALSE;
6566 if (notebook->show_tabs == show_tabs)
6569 notebook->show_tabs = show_tabs;
6570 children = notebook->children;
6574 GTK_WIDGET_UNSET_FLAGS (notebook, GTK_CAN_FOCUS);
6578 page = children->data;
6579 children = children->next;
6580 if (page->default_tab)
6582 gtk_widget_destroy (page->tab_label);
6583 page->tab_label = NULL;
6586 gtk_widget_hide (page->tab_label);
6591 GTK_WIDGET_SET_FLAGS (notebook, GTK_CAN_FOCUS);
6592 gtk_notebook_update_labels (notebook);
6594 gtk_widget_queue_resize (GTK_WIDGET (notebook));
6596 g_object_notify (G_OBJECT (notebook), "show-tabs");
6600 * gtk_notebook_get_show_tabs:
6601 * @notebook: a #GtkNotebook
6603 * Returns whether the tabs of the notebook are shown. See
6604 * gtk_notebook_set_show_tabs().
6606 * Return value: %TRUE if the tabs are shown
6609 gtk_notebook_get_show_tabs (GtkNotebook *notebook)
6611 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
6613 return notebook->show_tabs;
6617 * gtk_notebook_set_tab_pos:
6618 * @notebook: a #GtkNotebook.
6619 * @pos: the edge to draw the tabs at.
6621 * Sets the edge at which the tabs for switching pages in the
6622 * notebook are drawn.
6625 gtk_notebook_set_tab_pos (GtkNotebook *notebook,
6626 GtkPositionType pos)
6628 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6630 if (notebook->tab_pos != pos)
6632 notebook->tab_pos = pos;
6633 if (GTK_WIDGET_VISIBLE (notebook))
6634 gtk_widget_queue_resize (GTK_WIDGET (notebook));
6637 g_object_notify (G_OBJECT (notebook), "tab-pos");
6641 * gtk_notebook_get_tab_pos:
6642 * @notebook: a #GtkNotebook
6644 * Gets the edge at which the tabs for switching pages in the
6645 * notebook are drawn.
6647 * Return value: the edge at which the tabs are drawn
6650 gtk_notebook_get_tab_pos (GtkNotebook *notebook)
6652 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), GTK_POS_TOP);
6654 return notebook->tab_pos;
6658 * gtk_notebook_set_homogeneous_tabs:
6659 * @notebook: a #GtkNotebook
6660 * @homogeneous: %TRUE if all tabs should be the same size.
6662 * Sets whether the tabs must have all the same size or not.
6665 gtk_notebook_set_homogeneous_tabs (GtkNotebook *notebook,
6666 gboolean homogeneous)
6668 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6670 gtk_notebook_set_homogeneous_tabs_internal (notebook, homogeneous);
6674 * gtk_notebook_set_tab_border:
6675 * @notebook: a #GtkNotebook
6676 * @border_width: width of the border around the tab labels.
6678 * Sets the width the border around the tab labels
6679 * in a notebook. This is equivalent to calling
6680 * gtk_notebook_set_tab_hborder (@notebook, @border_width) followed
6681 * by gtk_notebook_set_tab_vborder (@notebook, @border_width).
6684 gtk_notebook_set_tab_border (GtkNotebook *notebook,
6687 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6689 gtk_notebook_set_tab_border_internal (notebook, border_width);
6693 * gtk_notebook_set_tab_hborder:
6694 * @notebook: a #GtkNotebook
6695 * @tab_hborder: width of the horizontal border of tab labels.
6697 * Sets the width of the horizontal border of tab labels.
6700 gtk_notebook_set_tab_hborder (GtkNotebook *notebook,
6703 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6705 gtk_notebook_set_tab_hborder_internal (notebook, tab_hborder);
6709 * gtk_notebook_set_tab_vborder:
6710 * @notebook: a #GtkNotebook
6711 * @tab_vborder: width of the vertical border of tab labels.
6713 * Sets the width of the vertical border of tab labels.
6716 gtk_notebook_set_tab_vborder (GtkNotebook *notebook,
6719 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6721 gtk_notebook_set_tab_vborder_internal (notebook, tab_vborder);
6725 * gtk_notebook_set_scrollable:
6726 * @notebook: a #GtkNotebook
6727 * @scrollable: %TRUE if scroll arrows should be added
6729 * Sets whether the tab label area will have arrows for scrolling if
6730 * there are too many tabs to fit in the area.
6733 gtk_notebook_set_scrollable (GtkNotebook *notebook,
6734 gboolean scrollable)
6736 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6738 scrollable = (scrollable != FALSE);
6740 if (scrollable != notebook->scrollable)
6742 notebook->scrollable = scrollable;
6744 if (GTK_WIDGET_VISIBLE (notebook))
6745 gtk_widget_queue_resize (GTK_WIDGET (notebook));
6747 g_object_notify (G_OBJECT (notebook), "scrollable");
6752 * gtk_notebook_get_scrollable:
6753 * @notebook: a #GtkNotebook
6755 * Returns whether the tab label area has arrows for scrolling. See
6756 * gtk_notebook_set_scrollable().
6758 * Return value: %TRUE if arrows for scrolling are present
6761 gtk_notebook_get_scrollable (GtkNotebook *notebook)
6763 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
6765 return notebook->scrollable;
6768 /* Public GtkNotebook Popup Menu Methods:
6770 * gtk_notebook_popup_enable
6771 * gtk_notebook_popup_disable
6776 * gtk_notebook_popup_enable:
6777 * @notebook: a #GtkNotebook
6779 * Enables the popup menu: if the user clicks with the right mouse button on
6780 * the bookmarks, a menu with all the pages will be popped up.
6783 gtk_notebook_popup_enable (GtkNotebook *notebook)
6787 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6792 notebook->menu = gtk_menu_new ();
6793 for (list = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, FALSE);
6795 list = gtk_notebook_search_page (notebook, list, STEP_NEXT, FALSE))
6796 gtk_notebook_menu_item_create (notebook, list);
6798 gtk_notebook_update_labels (notebook);
6799 gtk_menu_attach_to_widget (GTK_MENU (notebook->menu),
6800 GTK_WIDGET (notebook),
6801 gtk_notebook_menu_detacher);
6803 g_object_notify (G_OBJECT (notebook), "enable-popup");
6807 * gtk_notebook_popup_disable:
6808 * @notebook: a #GtkNotebook
6810 * Disables the popup menu.
6813 gtk_notebook_popup_disable (GtkNotebook *notebook)
6815 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6817 if (!notebook->menu)
6820 gtk_container_foreach (GTK_CONTAINER (notebook->menu),
6821 (GtkCallback) gtk_notebook_menu_label_unparent, NULL);
6822 gtk_widget_destroy (notebook->menu);
6824 g_object_notify (G_OBJECT (notebook), "enable-popup");
6827 /* Public GtkNotebook Page Properties Functions:
6829 * gtk_notebook_get_tab_label
6830 * gtk_notebook_set_tab_label
6831 * gtk_notebook_set_tab_label_text
6832 * gtk_notebook_get_menu_label
6833 * gtk_notebook_set_menu_label
6834 * gtk_notebook_set_menu_label_text
6835 * gtk_notebook_set_tab_label_packing
6836 * gtk_notebook_query_tab_label_packing
6837 * gtk_notebook_get_tab_reorderable
6838 * gtk_notebook_set_tab_reorderable
6839 * gtk_notebook_get_tab_detachable
6840 * gtk_notebook_set_tab_detachable
6844 * gtk_notebook_get_tab_label:
6845 * @notebook: a #GtkNotebook
6848 * Returns the tab label widget for the page @child. %NULL is returned
6849 * if @child is not in @notebook or if no tab label has specifically
6850 * been set for @child.
6852 * Return value: the tab label
6855 gtk_notebook_get_tab_label (GtkNotebook *notebook,
6860 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
6861 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
6863 list = CHECK_FIND_CHILD (notebook, child);
6867 if (GTK_NOTEBOOK_PAGE (list)->default_tab)
6870 return GTK_NOTEBOOK_PAGE (list)->tab_label;
6874 * gtk_notebook_set_tab_label:
6875 * @notebook: a #GtkNotebook
6877 * @tab_label: the tab label widget to use, or %NULL for default tab
6880 * Changes the tab label for @child. If %NULL is specified
6881 * for @tab_label, then the page will have the label 'page N'.
6884 gtk_notebook_set_tab_label (GtkNotebook *notebook,
6886 GtkWidget *tab_label)
6888 GtkNotebookPage *page;
6891 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6892 g_return_if_fail (GTK_IS_WIDGET (child));
6894 list = CHECK_FIND_CHILD (notebook, child);
6898 /* a NULL pointer indicates a default_tab setting, otherwise
6899 * we need to set the associated label
6903 if (page->tab_label == tab_label)
6907 gtk_notebook_remove_tab_label (notebook, page);
6911 page->default_tab = FALSE;
6912 page->tab_label = tab_label;
6913 gtk_widget_set_parent (page->tab_label, GTK_WIDGET (notebook));
6917 page->default_tab = TRUE;
6918 page->tab_label = NULL;
6920 if (notebook->show_tabs)
6924 g_snprintf (string, sizeof(string), _("Page %u"),
6925 gtk_notebook_real_page_position (notebook, list));
6926 page->tab_label = gtk_label_new (string);
6927 gtk_widget_set_parent (page->tab_label, GTK_WIDGET (notebook));
6931 if (page->tab_label)
6932 page->mnemonic_activate_signal =
6933 g_signal_connect (page->tab_label,
6934 "mnemonic-activate",
6935 G_CALLBACK (gtk_notebook_mnemonic_activate_switch_page),
6938 if (notebook->show_tabs && GTK_WIDGET_VISIBLE (child))
6940 gtk_widget_show (page->tab_label);
6941 gtk_widget_queue_resize (GTK_WIDGET (notebook));
6944 gtk_notebook_update_tab_states (notebook);
6945 gtk_widget_child_notify (child, "tab-label");
6949 * gtk_notebook_set_tab_label_text:
6950 * @notebook: a #GtkNotebook
6952 * @tab_text: the label text
6954 * Creates a new label and sets it as the tab label for the page
6955 * containing @child.
6958 gtk_notebook_set_tab_label_text (GtkNotebook *notebook,
6960 const gchar *tab_text)
6962 GtkWidget *tab_label = NULL;
6964 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
6967 tab_label = gtk_label_new (tab_text);
6968 gtk_notebook_set_tab_label (notebook, child, tab_label);
6969 gtk_widget_child_notify (child, "tab-label");
6973 * gtk_notebook_get_tab_label_text:
6974 * @notebook: a #GtkNotebook
6975 * @child: a widget contained in a page of @notebook
6977 * Retrieves the text of the tab label for the page containing
6980 * Return value: the text of the tab label, or %NULL if the
6981 * tab label widget is not a #GtkLabel. The
6982 * string is owned by the widget and must not
6985 G_CONST_RETURN gchar *
6986 gtk_notebook_get_tab_label_text (GtkNotebook *notebook,
6989 GtkWidget *tab_label;
6991 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
6992 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
6994 tab_label = gtk_notebook_get_tab_label (notebook, child);
6996 if (GTK_IS_LABEL (tab_label))
6997 return gtk_label_get_text (GTK_LABEL (tab_label));
7003 * gtk_notebook_get_menu_label:
7004 * @notebook: a #GtkNotebook
7005 * @child: a widget contained in a page of @notebook
7007 * Retrieves the menu label widget of the page containing @child.
7009 * Return value: the menu label, or %NULL if the
7010 * notebook page does not have a menu label other
7011 * than the default (the tab label).
7014 gtk_notebook_get_menu_label (GtkNotebook *notebook,
7019 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
7020 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
7022 list = CHECK_FIND_CHILD (notebook, child);
7026 if (GTK_NOTEBOOK_PAGE (list)->default_menu)
7029 return GTK_NOTEBOOK_PAGE (list)->menu_label;
7033 * gtk_notebook_set_menu_label:
7034 * @notebook: a #GtkNotebook
7035 * @child: the child widget
7036 * @menu_label: the menu label, or NULL for default
7038 * Changes the menu label for the page containing @child.
7041 gtk_notebook_set_menu_label (GtkNotebook *notebook,
7043 GtkWidget *menu_label)
7045 GtkNotebookPage *page;
7048 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7049 g_return_if_fail (GTK_IS_WIDGET (child));
7051 list = CHECK_FIND_CHILD (notebook, child);
7056 if (page->menu_label)
7059 gtk_container_remove (GTK_CONTAINER (notebook->menu),
7060 page->menu_label->parent);
7062 if (!page->default_menu)
7063 g_object_unref (page->menu_label);
7068 page->menu_label = menu_label;
7069 g_object_ref_sink (page->menu_label);
7070 page->default_menu = FALSE;
7073 page->default_menu = TRUE;
7076 gtk_notebook_menu_item_create (notebook, list);
7077 gtk_widget_child_notify (child, "menu-label");
7081 * gtk_notebook_set_menu_label_text:
7082 * @notebook: a #GtkNotebook
7083 * @child: the child widget
7084 * @menu_text: the label text
7086 * Creates a new label and sets it as the menu label of @child.
7089 gtk_notebook_set_menu_label_text (GtkNotebook *notebook,
7091 const gchar *menu_text)
7093 GtkWidget *menu_label = NULL;
7095 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7099 menu_label = gtk_label_new (menu_text);
7100 gtk_misc_set_alignment (GTK_MISC (menu_label), 0.0, 0.5);
7102 gtk_notebook_set_menu_label (notebook, child, menu_label);
7103 gtk_widget_child_notify (child, "menu-label");
7107 * gtk_notebook_get_menu_label_text:
7108 * @notebook: a #GtkNotebook
7109 * @child: the child widget of a page of the notebook.
7111 * Retrieves the text of the menu label for the page containing
7114 * Return value: the text of the tab label, or %NULL if the
7115 * widget does not have a menu label other than
7116 * the default menu label, or the menu label widget
7117 * is not a #GtkLabel. The string is owned by
7118 * the widget and must not be freed.
7120 G_CONST_RETURN gchar *
7121 gtk_notebook_get_menu_label_text (GtkNotebook *notebook,
7124 GtkWidget *menu_label;
7126 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
7127 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
7129 menu_label = gtk_notebook_get_menu_label (notebook, child);
7131 if (GTK_IS_LABEL (menu_label))
7132 return gtk_label_get_text (GTK_LABEL (menu_label));
7137 /* Helper function called when pages are reordered
7140 gtk_notebook_child_reordered (GtkNotebook *notebook,
7141 GtkNotebookPage *page)
7145 GtkWidget *menu_item;
7147 menu_item = page->menu_label->parent;
7148 gtk_container_remove (GTK_CONTAINER (menu_item), page->menu_label);
7149 gtk_container_remove (GTK_CONTAINER (notebook->menu), menu_item);
7150 gtk_notebook_menu_item_create (notebook, g_list_find (notebook->children, page));
7153 gtk_notebook_update_tab_states (notebook);
7154 gtk_notebook_update_labels (notebook);
7158 * gtk_notebook_set_tab_label_packing:
7159 * @notebook: a #GtkNotebook
7160 * @child: the child widget
7161 * @expand: whether to expand the bookmark or not
7162 * @fill: whether the bookmark should fill the allocated area or not
7163 * @pack_type: the position of the bookmark
7165 * Sets the packing parameters for the tab label of the page
7166 * containing @child. See gtk_box_pack_start() for the exact meaning
7167 * of the parameters.
7170 gtk_notebook_set_tab_label_packing (GtkNotebook *notebook,
7174 GtkPackType pack_type)
7176 GtkNotebookPage *page;
7179 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7180 g_return_if_fail (GTK_IS_WIDGET (child));
7182 list = CHECK_FIND_CHILD (notebook, child);
7187 expand = expand != FALSE;
7188 fill = fill != FALSE;
7189 if (page->pack == pack_type && page->expand == expand && page->fill == fill)
7192 gtk_widget_freeze_child_notify (child);
7193 page->expand = expand;
7194 gtk_widget_child_notify (child, "tab-expand");
7196 gtk_widget_child_notify (child, "tab-fill");
7197 if (page->pack != pack_type)
7199 page->pack = pack_type;
7200 gtk_notebook_child_reordered (notebook, page);
7202 gtk_widget_child_notify (child, "tab-pack");
7203 gtk_widget_child_notify (child, "position");
7204 if (notebook->show_tabs)
7205 gtk_notebook_pages_allocate (notebook);
7206 gtk_widget_thaw_child_notify (child);
7210 * gtk_notebook_query_tab_label_packing:
7211 * @notebook: a #GtkNotebook
7213 * @expand: location to store the expand value (or NULL)
7214 * @fill: location to store the fill value (or NULL)
7215 * @pack_type: location to store the pack_type (or NULL)
7217 * Query the packing attributes for the tab label of the page
7218 * containing @child.
7221 gtk_notebook_query_tab_label_packing (GtkNotebook *notebook,
7225 GtkPackType *pack_type)
7229 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7230 g_return_if_fail (GTK_IS_WIDGET (child));
7232 list = CHECK_FIND_CHILD (notebook, child);
7237 *expand = GTK_NOTEBOOK_PAGE (list)->expand;
7239 *fill = GTK_NOTEBOOK_PAGE (list)->fill;
7241 *pack_type = GTK_NOTEBOOK_PAGE (list)->pack;
7245 * gtk_notebook_reorder_child:
7246 * @notebook: a #GtkNotebook
7247 * @child: the child to move
7248 * @position: the new position, or -1 to move to the end
7250 * Reorders the page containing @child, so that it appears in position
7251 * @position. If @position is greater than or equal to the number of
7252 * children in the list or negative, @child will be moved to the end
7256 gtk_notebook_reorder_child (GtkNotebook *notebook,
7260 GList *list, *new_list;
7261 GtkNotebookPage *page;
7265 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7266 g_return_if_fail (GTK_IS_WIDGET (child));
7268 list = CHECK_FIND_CHILD (notebook, child);
7272 max_pos = g_list_length (notebook->children) - 1;
7273 if (position < 0 || position > max_pos)
7276 old_pos = g_list_position (notebook->children, list);
7278 if (old_pos == position)
7282 notebook->children = g_list_delete_link (notebook->children, list);
7284 notebook->children = g_list_insert (notebook->children, page, position);
7285 new_list = g_list_nth (notebook->children, position);
7287 /* Fix up GList references in GtkNotebook structure */
7288 if (notebook->first_tab == list)
7289 notebook->first_tab = new_list;
7290 if (notebook->focus_tab == list)
7291 notebook->focus_tab = new_list;
7293 gtk_widget_freeze_child_notify (child);
7295 /* Move around the menu items if necessary */
7296 gtk_notebook_child_reordered (notebook, page);
7297 gtk_widget_child_notify (child, "tab-pack");
7298 gtk_widget_child_notify (child, "position");
7300 if (notebook->show_tabs)
7301 gtk_notebook_pages_allocate (notebook);
7303 gtk_widget_thaw_child_notify (child);
7305 g_signal_emit (notebook,
7306 notebook_signals[PAGE_REORDERED],
7313 * gtk_notebook_set_window_creation_hook:
7314 * @func: the #GtkNotebookWindowCreationFunc, or %NULL
7315 * @data: user data for @func
7316 * @destroy: Destroy notifier for @data, or %NULL
7318 * Installs a global function used to create a window
7319 * when a detached tab is dropped in an empty area.
7324 gtk_notebook_set_window_creation_hook (GtkNotebookWindowCreationFunc func,
7326 GDestroyNotify destroy)
7328 if (window_creation_hook_destroy)
7329 window_creation_hook_destroy (window_creation_hook_data);
7331 window_creation_hook = func;
7332 window_creation_hook_data = data;
7333 window_creation_hook_destroy = destroy;
7337 * gtk_notebook_set_group_id:
7338 * @notebook: a #GtkNotebook
7339 * @group_id: a group identificator, or -1 to unset it
7341 * Sets an group identificator for @notebook, notebooks sharing
7342 * the same group identificator will be able to exchange tabs
7343 * via drag and drop. A notebook with group identificator -1 will
7344 * not be able to exchange tabs with any other notebook.
7347 * Deprecated: 2.12: use gtk_notebook_set_group() instead.
7350 gtk_notebook_set_group_id (GtkNotebook *notebook,
7355 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7357 /* add 1 to get rid of the -1/NULL difference */
7358 group = GINT_TO_POINTER (group_id + 1);
7359 gtk_notebook_set_group (notebook, group);
7363 * gtk_notebook_set_group:
7364 * @notebook: a #GtkNotebook
7365 * @group: a pointer to identify the notebook group, or %NULL to unset it
7367 * Sets a group identificator pointer for @notebook, notebooks sharing
7368 * the same group identificator pointer will be able to exchange tabs
7369 * via drag and drop. A notebook with a %NULL group identificator will
7370 * not be able to exchange tabs with any other notebook.
7375 gtk_notebook_set_group (GtkNotebook *notebook,
7378 GtkNotebookPrivate *priv;
7380 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7382 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
7384 if (priv->group != group)
7386 priv->group = group;
7387 g_object_notify (G_OBJECT (notebook), "group-id");
7388 g_object_notify (G_OBJECT (notebook), "group");
7393 * gtk_notebook_get_group_id:
7394 * @notebook: a #GtkNotebook
7396 * Gets the current group identificator for @notebook.
7398 * Return Value: the group identificator, or -1 if none is set.
7401 * Deprecated: 2.12: use gtk_notebook_get_group() instead.
7404 gtk_notebook_get_group_id (GtkNotebook *notebook)
7406 GtkNotebookPrivate *priv;
7408 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
7410 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
7412 /* substract 1 to get rid of the -1/NULL difference */
7413 return GPOINTER_TO_INT (priv->group) - 1;
7417 * gtk_notebook_get_group:
7418 * @notebook: a #GtkNotebook
7420 * Gets the current group identificator pointer for @notebook.
7422 * Return Value: the group identificator, or %NULL if none is set.
7427 gtk_notebook_get_group (GtkNotebook *notebook)
7429 GtkNotebookPrivate *priv;
7431 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
7433 priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
7438 * gtk_notebook_get_tab_reorderable:
7439 * @notebook: a #GtkNotebook
7440 * @child: a child #GtkWidget
7442 * Gets whether the tab can be reordered via drag and drop or not.
7444 * Return Value: %TRUE if the tab is reorderable.
7449 gtk_notebook_get_tab_reorderable (GtkNotebook *notebook,
7454 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
7455 g_return_val_if_fail (GTK_IS_WIDGET (child), FALSE);
7457 list = CHECK_FIND_CHILD (notebook, child);
7461 return GTK_NOTEBOOK_PAGE (list)->reorderable;
7465 * gtk_notebook_set_tab_reorderable:
7466 * @notebook: a #GtkNotebook
7467 * @child: a child #GtkWidget
7468 * @reorderable: whether the tab is reorderable or not.
7470 * Sets whether the notebook tab can be reordered
7471 * via drag and drop or not.
7476 gtk_notebook_set_tab_reorderable (GtkNotebook *notebook,
7478 gboolean reorderable)
7482 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7483 g_return_if_fail (GTK_IS_WIDGET (child));
7485 list = CHECK_FIND_CHILD (notebook, child);
7489 if (GTK_NOTEBOOK_PAGE (list)->reorderable != reorderable)
7491 GTK_NOTEBOOK_PAGE (list)->reorderable = (reorderable == TRUE);
7492 gtk_widget_child_notify (child, "reorderable");
7497 * gtk_notebook_get_tab_detachable:
7498 * @notebook: a #GtkNotebook
7499 * @child: a child #GtkWidget
7501 * Returns whether the tab contents can be detached from @notebook.
7503 * Return Value: TRUE if the tab is detachable.
7508 gtk_notebook_get_tab_detachable (GtkNotebook *notebook,
7513 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
7514 g_return_val_if_fail (GTK_IS_WIDGET (child), FALSE);
7516 list = CHECK_FIND_CHILD (notebook, child);
7520 return GTK_NOTEBOOK_PAGE (list)->detachable;
7524 * gtk_notebook_set_tab_detachable:
7525 * @notebook: a #GtkNotebook
7526 * @child: a child #GtkWidget
7527 * @detachable: whether the tab is detachable or not
7529 * Sets whether the tab can be detached from @notebook to another
7530 * notebook or widget.
7532 * Note that 2 notebooks must share a common group identificator
7533 * (see gtk_notebook_set_group_id ()) to allow automatic tabs
7534 * interchange between them.
7536 * If you want a widget to interact with a notebook through DnD
7537 * (i.e.: accept dragged tabs from it) it must be set as a drop
7538 * destination and accept the target "GTK_NOTEBOOK_TAB". The notebook
7539 * will fill the selection with a GtkWidget** pointing to the child
7540 * widget that corresponds to the dropped tab.
7543 * on_drop_zone_drag_data_received (GtkWidget *widget,
7544 * GdkDragContext *context,
7547 * GtkSelectionData *selection_data,
7550 * gpointer user_data)
7552 * GtkWidget *notebook;
7553 * GtkWidget **child;
7555 * notebook = gtk_drag_get_source_widget (context);
7556 * child = (void*) selection_data->data;
7558 * process_widget (*child);
7559 * gtk_container_remove (GTK_CONTAINER (notebook), *child);
7563 * If you want a notebook to accept drags from other widgets,
7564 * you will have to set your own DnD code to do it.
7569 gtk_notebook_set_tab_detachable (GtkNotebook *notebook,
7571 gboolean detachable)
7575 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
7576 g_return_if_fail (GTK_IS_WIDGET (child));
7578 list = CHECK_FIND_CHILD (notebook, child);
7582 if (GTK_NOTEBOOK_PAGE (list)->detachable != detachable)
7584 GTK_NOTEBOOK_PAGE (list)->detachable = (detachable == TRUE);
7585 gtk_widget_child_notify (child, "detachable");
7589 #define __GTK_NOTEBOOK_C__
7590 #include "gtkaliasdef.c"