1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 #include "gtknotebook.h"
28 #include "gtksignal.h"
31 #include "gtkmenuitem.h"
33 #include <gdk/gdkkeysyms.h>
36 #include "gtkmarshalers.h"
37 #include "gtkbindings.h"
41 #define TAB_CURVATURE 1
43 #define ARROW_SPACING 0
44 #define NOTEBOOK_INIT_SCROLL_DELAY (200)
45 #define NOTEBOOK_SCROLL_DELAY (100)
79 CHILD_PROP_MENU_LABEL,
81 CHILD_PROP_TAB_EXPAND,
86 #define GTK_NOTEBOOK_PAGE(_glist_) ((GtkNotebookPage *)((GList *)(_glist_))->data)
88 struct _GtkNotebookPage
92 GtkWidget *menu_label;
93 GtkWidget *last_focus_child; /* Last descendant of the page that had focus */
95 guint default_menu : 1; /* If true, we create the menu label ourself */
96 guint default_tab : 1; /* If true, we create the tab label ourself */
101 GtkRequisition requisition;
102 GtkAllocation allocation;
104 guint mnemonic_activate_signal;
107 #ifdef G_DISABLE_CHECKS
108 #define CHECK_FIND_CHILD(notebook, child) \
109 gtk_notebook_find_child (notebook, child, G_STRLOC)
111 #define CHECK_FIND_CHILD(notebook, child) \
112 gtk_notebook_find_child (notebook, child, NULL)
115 /*** GtkNotebook Methods ***/
116 static void gtk_notebook_class_init (GtkNotebookClass *klass);
117 static void gtk_notebook_init (GtkNotebook *notebook);
119 static gboolean gtk_notebook_select_page (GtkNotebook *notebook,
120 gboolean move_focus);
121 static gboolean gtk_notebook_focus_tab (GtkNotebook *notebook,
122 GtkNotebookTab type);
123 static void gtk_notebook_change_current_page (GtkNotebook *notebook,
125 static void gtk_notebook_move_focus_out (GtkNotebook *notebook,
126 GtkDirectionType direction_type);
128 /*** GtkObject Methods ***/
129 static void gtk_notebook_destroy (GtkObject *object);
130 static void gtk_notebook_set_property (GObject *object,
134 static void gtk_notebook_get_property (GObject *object,
139 /*** GtkWidget Methods ***/
140 static void gtk_notebook_map (GtkWidget *widget);
141 static void gtk_notebook_unmap (GtkWidget *widget);
142 static void gtk_notebook_realize (GtkWidget *widget);
143 static void gtk_notebook_unrealize (GtkWidget *widget);
144 static void gtk_notebook_size_request (GtkWidget *widget,
145 GtkRequisition *requisition);
146 static void gtk_notebook_size_allocate (GtkWidget *widget,
147 GtkAllocation *allocation);
148 static gint gtk_notebook_expose (GtkWidget *widget,
149 GdkEventExpose *event);
150 static gint gtk_notebook_button_press (GtkWidget *widget,
151 GdkEventButton *event);
152 static gint gtk_notebook_button_release (GtkWidget *widget,
153 GdkEventButton *event);
154 static gint gtk_notebook_enter_notify (GtkWidget *widget,
155 GdkEventCrossing *event);
156 static gint gtk_notebook_leave_notify (GtkWidget *widget,
157 GdkEventCrossing *event);
158 static gint gtk_notebook_motion_notify (GtkWidget *widget,
159 GdkEventMotion *event);
160 static gint gtk_notebook_focus_in (GtkWidget *widget,
161 GdkEventFocus *event);
162 static void gtk_notebook_draw_focus (GtkWidget *widget);
163 static gint gtk_notebook_focus (GtkWidget *widget,
164 GtkDirectionType direction);
166 /*** GtkContainer Methods ***/
167 static void gtk_notebook_set_child_property (GtkContainer *container,
172 static void gtk_notebook_get_child_property (GtkContainer *container,
177 static void gtk_notebook_add (GtkContainer *container,
179 static void gtk_notebook_remove (GtkContainer *container,
181 static void gtk_notebook_set_focus_child (GtkContainer *container,
183 static GtkType gtk_notebook_child_type (GtkContainer *container);
184 static void gtk_notebook_forall (GtkContainer *container,
185 gboolean include_internals,
186 GtkCallback callback,
187 gpointer callback_data);
189 /*** GtkNotebook Private Functions ***/
190 static void gtk_notebook_redraw_tabs (GtkNotebook *notebook);
191 static void gtk_notebook_redraw_arrows (GtkNotebook *notebook);
192 static void gtk_notebook_focus_changed (GtkNotebook *notebook,
193 GtkNotebookPage *old_page);
194 static void gtk_notebook_real_remove (GtkNotebook *notebook,
196 static void gtk_notebook_update_labels (GtkNotebook *notebook);
197 static gint gtk_notebook_timer (GtkNotebook *notebook);
198 static gint gtk_notebook_page_compare (gconstpointer a,
200 static GList* gtk_notebook_find_child (GtkNotebook *notebook,
202 const gchar *function);
203 static gint gtk_notebook_real_page_position (GtkNotebook *notebook,
205 static GList * gtk_notebook_search_page (GtkNotebook *notebook,
208 gboolean find_visible);
210 /*** GtkNotebook Drawing Functions ***/
211 static void gtk_notebook_paint (GtkWidget *widget,
213 static void gtk_notebook_draw_tab (GtkNotebook *notebook,
214 GtkNotebookPage *page,
216 static void gtk_notebook_draw_arrow (GtkNotebook *notebook,
219 /*** GtkNotebook Size Allocate Functions ***/
220 static void gtk_notebook_pages_allocate (GtkNotebook *notebook);
221 static void gtk_notebook_page_allocate (GtkNotebook *notebook,
222 GtkNotebookPage *page,
223 GtkAllocation *allocation);
224 static void gtk_notebook_calc_tabs (GtkNotebook *notebook,
230 /*** GtkNotebook Page Switch Methods ***/
231 static void gtk_notebook_real_switch_page (GtkNotebook *notebook,
232 GtkNotebookPage *page,
235 /*** GtkNotebook Page Switch Functions ***/
236 static void gtk_notebook_switch_page (GtkNotebook *notebook,
237 GtkNotebookPage *page,
239 static gint gtk_notebook_page_select (GtkNotebook *notebook,
240 gboolean move_focus);
241 static void gtk_notebook_switch_focus_tab (GtkNotebook *notebook,
243 static void gtk_notebook_menu_switch_page (GtkWidget *widget,
244 GtkNotebookPage *page);
246 /*** GtkNotebook Menu Functions ***/
247 static void gtk_notebook_menu_item_create (GtkNotebook *notebook,
249 static void gtk_notebook_menu_label_unparent (GtkWidget *widget,
251 static void gtk_notebook_menu_detacher (GtkWidget *widget,
254 static gboolean focus_tabs_in (GtkNotebook *notebook);
255 static gboolean focus_child_in (GtkNotebook *notebook,
256 GtkDirectionType direction);
258 static GtkContainerClass *parent_class = NULL;
259 static guint notebook_signals[LAST_SIGNAL] = { 0 };
262 gtk_notebook_get_type (void)
264 static GtkType notebook_type = 0;
268 static const GtkTypeInfo notebook_info =
271 sizeof (GtkNotebook),
272 sizeof (GtkNotebookClass),
273 (GtkClassInitFunc) gtk_notebook_class_init,
274 (GtkObjectInitFunc) gtk_notebook_init,
275 /* reserved_1 */ NULL,
276 /* reserved_2 */ NULL,
277 (GtkClassInitFunc) NULL,
280 notebook_type = gtk_type_unique (gtk_container_get_type (), ¬ebook_info);
283 return notebook_type;
287 add_tab_bindings (GtkBindingSet *binding_set,
288 GdkModifierType modifiers,
289 GtkDirectionType direction)
291 gtk_binding_entry_add_signal (binding_set, GDK_Tab, modifiers,
293 GTK_TYPE_DIRECTION_TYPE, direction);
294 gtk_binding_entry_add_signal (binding_set, GDK_KP_Tab, modifiers,
296 GTK_TYPE_DIRECTION_TYPE, direction);
300 add_arrow_bindings (GtkBindingSet *binding_set,
302 GtkDirectionType direction)
304 guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
306 gtk_binding_entry_add_signal (binding_set, keysym, GDK_CONTROL_MASK,
308 GTK_TYPE_DIRECTION_TYPE, direction);
309 gtk_binding_entry_add_signal (binding_set, keypad_keysym, GDK_CONTROL_MASK,
311 GTK_TYPE_DIRECTION_TYPE, direction);
315 gtk_notebook_class_init (GtkNotebookClass *class)
317 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
318 GtkObjectClass *object_class = GTK_OBJECT_CLASS (class);
319 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
320 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
321 GtkBindingSet *binding_set;
323 parent_class = g_type_class_peek_parent (class);
325 gobject_class->set_property = gtk_notebook_set_property;
326 gobject_class->get_property = gtk_notebook_get_property;
327 object_class->destroy = gtk_notebook_destroy;
329 widget_class->map = gtk_notebook_map;
330 widget_class->unmap = gtk_notebook_unmap;
331 widget_class->realize = gtk_notebook_realize;
332 widget_class->unrealize = gtk_notebook_unrealize;
333 widget_class->size_request = gtk_notebook_size_request;
334 widget_class->size_allocate = gtk_notebook_size_allocate;
335 widget_class->expose_event = gtk_notebook_expose;
336 widget_class->button_press_event = gtk_notebook_button_press;
337 widget_class->button_release_event = gtk_notebook_button_release;
338 widget_class->enter_notify_event = gtk_notebook_enter_notify;
339 widget_class->leave_notify_event = gtk_notebook_leave_notify;
340 widget_class->motion_notify_event = gtk_notebook_motion_notify;
341 widget_class->focus_in_event = gtk_notebook_focus_in;
342 widget_class->focus = gtk_notebook_focus;
344 container_class->add = gtk_notebook_add;
345 container_class->remove = gtk_notebook_remove;
346 container_class->forall = gtk_notebook_forall;
347 container_class->set_focus_child = gtk_notebook_set_focus_child;
348 container_class->get_child_property = gtk_notebook_get_child_property;
349 container_class->set_child_property = gtk_notebook_set_child_property;
350 container_class->child_type = gtk_notebook_child_type;
352 class->switch_page = gtk_notebook_real_switch_page;
354 class->focus_tab = gtk_notebook_focus_tab;
355 class->select_page = gtk_notebook_select_page;
356 class->change_current_page = gtk_notebook_change_current_page;
357 class->move_focus_out = gtk_notebook_move_focus_out;
359 g_object_class_install_property (gobject_class,
361 g_param_spec_int ("page",
363 _("The index of the current page"),
368 g_object_class_install_property (gobject_class,
370 g_param_spec_enum ("tab_pos",
372 _("Which side of the notebook holds the tabs"),
373 GTK_TYPE_POSITION_TYPE,
376 g_object_class_install_property (gobject_class,
378 g_param_spec_uint ("tab_border",
380 _("Width of the border around the tab labels"),
385 g_object_class_install_property (gobject_class,
387 g_param_spec_uint ("tab_hborder",
388 _("Horizontal Tab Border"),
389 _("Width of the horizontal border of tab labels"),
394 g_object_class_install_property (gobject_class,
396 g_param_spec_uint ("tab_vborder",
397 _("Vertical Tab Border"),
398 _("Width of the vertical border of tab labels"),
403 g_object_class_install_property (gobject_class,
405 g_param_spec_boolean ("show_tabs",
407 _("Whether tabs should be shown or not"),
410 g_object_class_install_property (gobject_class,
412 g_param_spec_boolean ("show_border",
414 _("Whether the border should be shown or not"),
417 g_object_class_install_property (gobject_class,
419 g_param_spec_boolean ("scrollable",
421 _("If TRUE, scroll arrows are added if there are to many tabs to fit"),
424 g_object_class_install_property (gobject_class,
426 g_param_spec_boolean ("enable_popup",
428 _("If TRUE, pressing the right mouse button on the notebook pops up a menu that you can use to go to a page"),
431 g_object_class_install_property (gobject_class,
433 g_param_spec_boolean ("homogeneous",
435 _("Whether tabs should have homogeneous sizes"),
439 gtk_container_class_install_child_property (container_class,
440 CHILD_PROP_TAB_LABEL,
441 g_param_spec_string ("tab_label", NULL, NULL,
444 gtk_container_class_install_child_property (container_class,
445 CHILD_PROP_MENU_LABEL,
446 g_param_spec_string ("menu_label", NULL, NULL,
449 gtk_container_class_install_child_property (container_class,
451 g_param_spec_int ("position", NULL, NULL,
454 gtk_container_class_install_child_property (container_class,
455 CHILD_PROP_TAB_EXPAND,
456 g_param_spec_boolean ("tab_expand", NULL, NULL,
459 gtk_container_class_install_child_property (container_class,
461 g_param_spec_boolean ("tab_fill", NULL, NULL,
464 gtk_container_class_install_child_property (container_class,
466 g_param_spec_enum ("tab_pack", NULL, NULL,
467 GTK_TYPE_PACK_TYPE, GTK_PACK_START,
470 notebook_signals[SWITCH_PAGE] =
471 gtk_signal_new ("switch_page",
473 GTK_CLASS_TYPE (object_class),
474 GTK_SIGNAL_OFFSET (GtkNotebookClass, switch_page),
475 _gtk_marshal_VOID__POINTER_UINT,
479 notebook_signals[FOCUS_TAB] =
480 g_signal_new ("focus_tab",
481 G_TYPE_FROM_CLASS (object_class),
482 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
483 G_STRUCT_OFFSET (GtkNotebookClass, focus_tab),
485 _gtk_marshal_BOOLEAN__ENUM,
487 GTK_TYPE_NOTEBOOK_TAB);
488 notebook_signals[SELECT_PAGE] =
489 g_signal_new ("select_page",
490 G_TYPE_FROM_CLASS (object_class),
491 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
492 G_STRUCT_OFFSET (GtkNotebookClass, select_page),
494 _gtk_marshal_BOOLEAN__BOOLEAN,
497 notebook_signals[CHANGE_CURRENT_PAGE] =
498 g_signal_new ("change_current_page",
499 G_TYPE_FROM_CLASS (object_class),
500 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
501 G_STRUCT_OFFSET (GtkNotebookClass, change_current_page),
503 _gtk_marshal_VOID__INT,
506 notebook_signals[MOVE_FOCUS_OUT] =
507 g_signal_new ("move_focus_out",
508 G_TYPE_FROM_CLASS (object_class),
509 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
510 G_STRUCT_OFFSET (GtkNotebookClass, move_focus_out),
512 _gtk_marshal_VOID__ENUM,
514 GTK_TYPE_DIRECTION_TYPE);
517 binding_set = gtk_binding_set_by_class (object_class);
518 gtk_binding_entry_add_signal (binding_set,
521 G_TYPE_BOOLEAN, FALSE);
522 gtk_binding_entry_add_signal (binding_set,
525 G_TYPE_BOOLEAN, FALSE);
527 gtk_binding_entry_add_signal (binding_set,
530 GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_FIRST);
531 gtk_binding_entry_add_signal (binding_set,
534 GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_FIRST);
535 gtk_binding_entry_add_signal (binding_set,
538 GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_LAST);
539 gtk_binding_entry_add_signal (binding_set,
542 GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_LAST);
544 gtk_binding_entry_add_signal (binding_set,
545 GDK_Page_Up, GDK_CONTROL_MASK,
546 "change_current_page", 1,
548 gtk_binding_entry_add_signal (binding_set,
549 GDK_Page_Down, GDK_CONTROL_MASK,
550 "change_current_page", 1,
553 add_arrow_bindings (binding_set, GDK_Up, GTK_DIR_UP);
554 add_arrow_bindings (binding_set, GDK_Down, GTK_DIR_DOWN);
555 add_arrow_bindings (binding_set, GDK_Left, GTK_DIR_LEFT);
556 add_arrow_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT);
558 add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
559 add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
563 gtk_notebook_init (GtkNotebook *notebook)
565 GTK_WIDGET_SET_FLAGS (notebook, GTK_CAN_FOCUS | GTK_RECEIVES_DEFAULT);
566 GTK_WIDGET_SET_FLAGS (notebook, GTK_NO_WINDOW);
568 notebook->cur_page = NULL;
569 notebook->children = NULL;
570 notebook->first_tab = NULL;
571 notebook->focus_tab = NULL;
572 notebook->event_window = NULL;
573 notebook->menu = NULL;
575 notebook->tab_hborder = 2;
576 notebook->tab_vborder = 2;
578 notebook->show_tabs = TRUE;
579 notebook->show_border = TRUE;
580 notebook->tab_pos = GTK_POS_TOP;
581 notebook->scrollable = FALSE;
582 notebook->in_child = 0;
583 notebook->click_child = 0;
584 notebook->button = 0;
585 notebook->need_timer = 0;
586 notebook->child_has_focus = FALSE;
587 notebook->have_visible_child = FALSE;
588 notebook->focus_out = FALSE;
592 gtk_notebook_select_page (GtkNotebook *notebook,
595 if (gtk_widget_is_focus (GTK_WIDGET (notebook)))
597 gtk_notebook_page_select (notebook, move_focus);
605 gtk_notebook_focus_tab (GtkNotebook *notebook,
610 if (gtk_widget_is_focus (GTK_WIDGET (notebook)))
614 case GTK_NOTEBOOK_TAB_FIRST:
615 list = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, TRUE);
617 gtk_notebook_switch_focus_tab (notebook, list);
619 case GTK_NOTEBOOK_TAB_LAST:
620 list = gtk_notebook_search_page (notebook, NULL, STEP_PREV, TRUE);
622 gtk_notebook_switch_focus_tab (notebook, list);
633 gtk_notebook_change_current_page (GtkNotebook *notebook,
636 GList *current = NULL;
638 if (notebook->cur_page)
639 current = g_list_find (notebook->children, notebook->cur_page);
643 current = gtk_notebook_search_page (notebook, current, offset < 0 ? STEP_PREV : STEP_NEXT, TRUE);
644 offset += offset < 0 ? 1 : -1;
648 gtk_notebook_switch_page (notebook, current->data, -1);
653 static GtkDirectionType
654 get_effective_direction (GtkNotebook *notebook,
655 GtkDirectionType direction)
657 /* Remap the directions into the effective direction it would be for a
658 * GTK_POS_TOP notebook
660 #define D(rest) GTK_DIR_##rest
662 static const GtkDirectionType translate_direction[4][6] = {
663 /* LEFT */ { D(TAB_FORWARD), D(TAB_BACKWARD), D(LEFT), D(RIGHT), D(UP), D(DOWN) },
664 /* RIGHT */ { D(TAB_BACKWARD), D(TAB_FORWARD), D(LEFT), D(RIGHT), D(DOWN), D(UP) },
665 /* TOP */ { D(TAB_FORWARD), D(TAB_BACKWARD), D(UP), D(DOWN), D(LEFT), D(RIGHT) },
666 /* BOTTOM */ { D(TAB_BACKWARD), D(TAB_FORWARD), D(DOWN), D(UP), D(LEFT), D(RIGHT) },
671 return translate_direction[notebook->tab_pos][direction];
675 gtk_notebook_move_focus_out (GtkNotebook *notebook,
676 GtkDirectionType direction_type)
678 GtkDirectionType effective_direction = get_effective_direction (notebook, direction_type);
681 if (GTK_CONTAINER (notebook)->focus_child && effective_direction == GTK_DIR_UP)
682 if (focus_tabs_in (notebook))
685 if (gtk_widget_is_focus (GTK_WIDGET (notebook)) && effective_direction == GTK_DIR_DOWN)
686 if (focus_child_in (notebook, GTK_DIR_TAB_FORWARD))
689 /* At this point, we know we should be focusing out of the notebook entirely. We
690 * do this by setting a flag, then propagating the focus motion to the notebook.
692 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (notebook));
693 if (!GTK_WIDGET_TOPLEVEL (toplevel))
696 g_object_ref (notebook);
698 notebook->focus_out = TRUE;
699 g_signal_emit_by_name (G_OBJECT (toplevel), "move_focus", direction_type);
700 notebook->focus_out = FALSE;
702 g_object_unref (notebook);
709 * Creates a new #GtkNotebook widget with no pages.
711 * Return value: the newly created #GtkNotebook
714 gtk_notebook_new (void)
716 return GTK_WIDGET (gtk_type_new (gtk_notebook_get_type ()));
719 /* Private GtkObject Methods :
721 * gtk_notebook_destroy
722 * gtk_notebook_set_arg
723 * gtk_notebook_get_arg
726 gtk_notebook_destroy (GtkObject *object)
728 GtkNotebook *notebook = GTK_NOTEBOOK (object);
731 gtk_notebook_popup_disable (notebook);
733 GTK_OBJECT_CLASS (parent_class)->destroy (object);
737 gtk_notebook_set_property (GObject *object,
742 GtkNotebook *notebook;
744 notebook = GTK_NOTEBOOK (object);
749 gtk_notebook_set_show_tabs (notebook, g_value_get_boolean (value));
751 case PROP_SHOW_BORDER:
752 gtk_notebook_set_show_border (notebook, g_value_get_boolean (value));
754 case PROP_SCROLLABLE:
755 gtk_notebook_set_scrollable (notebook, g_value_get_boolean (value));
757 case PROP_ENABLE_POPUP:
758 if (g_value_get_boolean (value))
759 gtk_notebook_popup_enable (notebook);
761 gtk_notebook_popup_disable (notebook);
763 case PROP_HOMOGENEOUS:
764 gtk_notebook_set_homogeneous_tabs (notebook, g_value_get_boolean (value));
767 gtk_notebook_set_current_page (notebook, g_value_get_int (value));
770 gtk_notebook_set_tab_pos (notebook, g_value_get_enum (value));
772 case PROP_TAB_BORDER:
773 gtk_notebook_set_tab_border (notebook, g_value_get_uint (value));
775 case PROP_TAB_HBORDER:
776 gtk_notebook_set_tab_hborder (notebook, g_value_get_uint (value));
778 case PROP_TAB_VBORDER:
779 gtk_notebook_set_tab_vborder (notebook, g_value_get_uint (value));
787 gtk_notebook_get_property (GObject *object,
792 GtkNotebook *notebook;
794 notebook = GTK_NOTEBOOK (object);
799 g_value_set_boolean (value, notebook->show_tabs);
801 case PROP_SHOW_BORDER:
802 g_value_set_boolean (value, notebook->show_border);
804 case PROP_SCROLLABLE:
805 g_value_set_boolean (value, notebook->scrollable);
807 case PROP_ENABLE_POPUP:
808 g_value_set_boolean (value, notebook->menu != NULL);
810 case PROP_HOMOGENEOUS:
811 g_value_set_boolean (value, notebook->homogeneous);
814 g_value_set_int (value, gtk_notebook_get_current_page (notebook));
817 g_value_set_enum (value, notebook->tab_pos);
819 case PROP_TAB_HBORDER:
820 g_value_set_uint (value, notebook->tab_hborder);
822 case PROP_TAB_VBORDER:
823 g_value_set_uint (value, notebook->tab_vborder);
826 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
831 /* Private GtkWidget Methods :
835 * gtk_notebook_realize
836 * gtk_notebook_size_request
837 * gtk_notebook_size_allocate
838 * gtk_notebook_expose
839 * gtk_notebook_button_press
840 * gtk_notebook_button_release
841 * gtk_notebook_enter_notify
842 * gtk_notebook_leave_notify
843 * gtk_notebook_motion_notify
844 * gtk_notebook_focus_in
845 * gtk_notebook_focus_out
846 * gtk_notebook_draw_focus
847 * gtk_notebook_style_set
850 gtk_notebook_get_event_window_position (GtkNotebook *notebook,
851 GdkRectangle *rectangle)
853 GtkWidget *widget = GTK_WIDGET (notebook);
854 gint border_width = GTK_CONTAINER (notebook)->border_width;
856 if (notebook->show_tabs && notebook->children)
860 GtkNotebookPage *page = notebook->children->data;
862 rectangle->x = widget->allocation.x + border_width;
863 rectangle->y = widget->allocation.y + border_width;
865 switch (notebook->tab_pos)
869 rectangle->width = widget->allocation.width - 2 * border_width;
870 rectangle->height = page->requisition.height;
871 if (notebook->tab_pos == GTK_POS_BOTTOM)
872 rectangle->y += widget->allocation.height - 2 * border_width - rectangle->height;
876 rectangle->width = page->requisition.width;
877 rectangle->height = widget->allocation.height - 2 * border_width;
878 if (notebook->tab_pos == GTK_POS_RIGHT)
879 rectangle->x += widget->allocation.width - 2 * border_width - rectangle->width;
890 rectangle->x = rectangle->y = 0;
891 rectangle->width = rectangle->height = 10;
899 gtk_notebook_map (GtkWidget *widget)
901 GtkNotebook *notebook;
902 GtkNotebookPage *page;
905 g_return_if_fail (GTK_IS_NOTEBOOK (widget));
907 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
909 notebook = GTK_NOTEBOOK (widget);
911 if (notebook->cur_page &&
912 GTK_WIDGET_VISIBLE (notebook->cur_page->child) &&
913 !GTK_WIDGET_MAPPED (notebook->cur_page->child))
914 gtk_widget_map (notebook->cur_page->child);
916 if (notebook->scrollable)
917 gtk_notebook_pages_allocate (notebook);
920 children = notebook->children;
924 page = children->data;
925 children = children->next;
927 if (page->tab_label &&
928 GTK_WIDGET_VISIBLE (page->tab_label) &&
929 !GTK_WIDGET_MAPPED (page->tab_label))
930 gtk_widget_map (page->tab_label);
934 if (gtk_notebook_get_event_window_position (notebook, NULL))
935 gdk_window_show_unraised (notebook->event_window);
939 gtk_notebook_unmap (GtkWidget *widget)
941 g_return_if_fail (GTK_IS_NOTEBOOK (widget));
943 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
945 gdk_window_hide (GTK_NOTEBOOK (widget)->event_window);
947 GTK_WIDGET_CLASS (parent_class)->unmap (widget);
951 gtk_notebook_realize (GtkWidget *widget)
953 GtkNotebook *notebook;
954 GdkWindowAttr attributes;
955 gint attributes_mask;
956 GdkRectangle event_window_pos;
958 g_return_if_fail (GTK_IS_NOTEBOOK (widget));
960 notebook = GTK_NOTEBOOK (widget);
961 GTK_WIDGET_SET_FLAGS (notebook, GTK_REALIZED);
963 gtk_notebook_get_event_window_position (notebook, &event_window_pos);
965 widget->window = gtk_widget_get_parent_window (widget);
966 gdk_window_ref (widget->window);
968 attributes.window_type = GDK_WINDOW_CHILD;
969 attributes.x = event_window_pos.x;
970 attributes.y = event_window_pos.y;
971 attributes.width = event_window_pos.width;
972 attributes.height = event_window_pos.height;
973 attributes.wclass = GDK_INPUT_ONLY;
974 attributes.event_mask = gtk_widget_get_events (widget);
975 attributes.event_mask |= (GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK |
976 GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK);
978 attributes_mask = GDK_WA_X | GDK_WA_Y;
980 notebook->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
981 &attributes, attributes_mask);
982 gdk_window_set_user_data (notebook->event_window, notebook);
984 widget->style = gtk_style_attach (widget->style, widget->window);
988 gtk_notebook_unrealize (GtkWidget *widget)
990 GtkNotebook *notebook;
992 g_return_if_fail (GTK_IS_NOTEBOOK (widget));
994 notebook = GTK_NOTEBOOK (widget);
996 gdk_window_set_user_data (notebook->event_window, NULL);
997 gdk_window_destroy (notebook->event_window);
998 notebook->event_window = NULL;
1000 if (GTK_WIDGET_CLASS (parent_class)->unrealize)
1001 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
1005 gtk_notebook_size_request (GtkWidget *widget,
1006 GtkRequisition *requisition)
1008 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
1009 GtkNotebookPage *page;
1011 GtkRequisition child_requisition;
1012 gboolean switch_page = FALSE;
1016 gtk_widget_style_get (widget, "focus-line-width", &focus_width, NULL);
1018 widget->requisition.width = 0;
1019 widget->requisition.height = 0;
1021 for (children = notebook->children, vis_pages = 0; children;
1022 children = children->next)
1024 page = children->data;
1026 if (GTK_WIDGET_VISIBLE (page->child))
1029 gtk_widget_size_request (page->child, &child_requisition);
1031 widget->requisition.width = MAX (widget->requisition.width,
1032 child_requisition.width);
1033 widget->requisition.height = MAX (widget->requisition.height,
1034 child_requisition.height);
1036 if (notebook->menu && page->menu_label->parent &&
1037 !GTK_WIDGET_VISIBLE (page->menu_label->parent))
1038 gtk_widget_show (page->menu_label->parent);
1042 if (page == notebook->cur_page)
1044 if (notebook->menu && page->menu_label->parent &&
1045 GTK_WIDGET_VISIBLE (page->menu_label->parent))
1046 gtk_widget_hide (page->menu_label->parent);
1050 if (notebook->show_border || notebook->show_tabs)
1052 widget->requisition.width += widget->style->xthickness * 2;
1053 widget->requisition.height += widget->style->ythickness * 2;
1055 if (notebook->show_tabs)
1058 gint tab_height = 0;
1062 for (children = notebook->children; children;
1063 children = children->next)
1065 page = children->data;
1067 if (GTK_WIDGET_VISIBLE (page->child))
1069 if (!GTK_WIDGET_VISIBLE (page->tab_label))
1070 gtk_widget_show (page->tab_label);
1072 gtk_widget_size_request (page->tab_label,
1073 &child_requisition);
1075 page->requisition.width =
1076 child_requisition.width +
1077 2 * widget->style->xthickness;
1078 page->requisition.height =
1079 child_requisition.height +
1080 2 * widget->style->ythickness;
1082 switch (notebook->tab_pos)
1085 case GTK_POS_BOTTOM:
1086 page->requisition.height += 2 * (notebook->tab_vborder +
1088 tab_height = MAX (tab_height, page->requisition.height);
1089 tab_max = MAX (tab_max, page->requisition.width);
1093 page->requisition.width += 2 * (notebook->tab_hborder +
1095 tab_width = MAX (tab_width, page->requisition.width);
1096 tab_max = MAX (tab_max, page->requisition.height);
1100 else if (GTK_WIDGET_VISIBLE (page->tab_label))
1101 gtk_widget_hide (page->tab_label);
1104 children = notebook->children;
1108 switch (notebook->tab_pos)
1111 case GTK_POS_BOTTOM:
1112 if (tab_height == 0)
1115 if (notebook->scrollable && vis_pages > 1 &&
1116 widget->requisition.width < tab_width)
1117 tab_height = MAX (tab_height, ARROW_SIZE);
1119 padding = 2 * (TAB_CURVATURE + focus_width +
1120 notebook->tab_hborder) - TAB_OVERLAP;
1124 page = children->data;
1125 children = children->next;
1127 if (!GTK_WIDGET_VISIBLE (page->child))
1130 if (notebook->homogeneous)
1131 page->requisition.width = tab_max;
1133 page->requisition.width += padding;
1135 tab_width += page->requisition.width;
1136 page->requisition.height = tab_height;
1139 if (notebook->scrollable && vis_pages > 1 &&
1140 widget->requisition.width < tab_width)
1141 tab_width = tab_max + 2 * (ARROW_SIZE + ARROW_SPACING);
1143 if (notebook->homogeneous && !notebook->scrollable)
1144 widget->requisition.width = MAX (widget->requisition.width,
1145 vis_pages * tab_max +
1148 widget->requisition.width = MAX (widget->requisition.width,
1149 tab_width + TAB_OVERLAP);
1151 widget->requisition.height += tab_height;
1158 if (notebook->scrollable && vis_pages > 1 &&
1159 widget->requisition.height < tab_height)
1160 tab_width = MAX (tab_width, ARROW_SPACING +2 * ARROW_SIZE);
1162 padding = 2 * (TAB_CURVATURE + focus_width +
1163 notebook->tab_vborder) - TAB_OVERLAP;
1168 page = children->data;
1169 children = children->next;
1171 if (!GTK_WIDGET_VISIBLE (page->child))
1174 page->requisition.width = tab_width;
1176 if (notebook->homogeneous)
1177 page->requisition.height = tab_max;
1179 page->requisition.height += padding;
1181 tab_height += page->requisition.height;
1184 if (notebook->scrollable && vis_pages > 1 &&
1185 widget->requisition.height < tab_height)
1186 tab_height = tab_max + ARROW_SIZE + ARROW_SPACING;
1188 widget->requisition.width += tab_width;
1190 if (notebook->homogeneous && !notebook->scrollable)
1191 widget->requisition.height =
1192 MAX (widget->requisition.height,
1193 vis_pages * tab_max + TAB_OVERLAP);
1195 widget->requisition.height =
1196 MAX (widget->requisition.height,
1197 tab_height + TAB_OVERLAP);
1199 if (!notebook->homogeneous || notebook->scrollable)
1201 widget->requisition.height = MAX (widget->requisition.height,
1202 vis_pages * tab_max +
1210 for (children = notebook->children; children;
1211 children = children->next)
1213 page = children->data;
1215 if (page->tab_label && GTK_WIDGET_VISIBLE (page->tab_label))
1216 gtk_widget_hide (page->tab_label);
1221 widget->requisition.width += GTK_CONTAINER (widget)->border_width * 2;
1222 widget->requisition.height += GTK_CONTAINER (widget)->border_width * 2;
1228 for (children = notebook->children; children;
1229 children = children->next)
1231 page = children->data;
1232 if (GTK_WIDGET_VISIBLE (page->child))
1234 gtk_notebook_switch_page (notebook, page, -1);
1239 else if (GTK_WIDGET_VISIBLE (widget))
1241 widget->requisition.width = GTK_CONTAINER (widget)->border_width * 2;
1242 widget->requisition.height= GTK_CONTAINER (widget)->border_width * 2;
1245 if (vis_pages && !notebook->cur_page)
1247 children = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, TRUE);
1250 notebook->first_tab = children;
1251 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (children),-1);
1257 gtk_notebook_size_allocate (GtkWidget *widget,
1258 GtkAllocation *allocation)
1260 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
1263 widget->allocation = *allocation;
1264 if (GTK_WIDGET_REALIZED (widget))
1266 GdkRectangle position;
1268 if (gtk_notebook_get_event_window_position (notebook, &position))
1269 gdk_window_move_resize (notebook->event_window,
1270 position.x, position.y,
1271 position.width, position.height);
1274 if (notebook->children)
1276 gint border_width = GTK_CONTAINER (widget)->border_width;
1277 GtkNotebookPage *page;
1278 GtkAllocation child_allocation;
1281 child_allocation.x = widget->allocation.x + border_width;
1282 child_allocation.y = widget->allocation.y + border_width;
1283 child_allocation.width = MAX (1, allocation->width - border_width * 2);
1284 child_allocation.height = MAX (1, allocation->height - border_width * 2);
1286 if (notebook->show_tabs || notebook->show_border)
1288 child_allocation.x += widget->style->xthickness;
1289 child_allocation.y += widget->style->ythickness;
1290 child_allocation.width = MAX (1, child_allocation.width -
1291 widget->style->xthickness * 2);
1292 child_allocation.height = MAX (1, child_allocation.height -
1293 widget->style->ythickness * 2);
1295 if (notebook->show_tabs && notebook->children && notebook->cur_page)
1297 switch (notebook->tab_pos)
1300 child_allocation.y += notebook->cur_page->requisition.height;
1301 case GTK_POS_BOTTOM:
1302 child_allocation.height =
1303 MAX (1, child_allocation.height -
1304 notebook->cur_page->requisition.height);
1307 child_allocation.x += notebook->cur_page->requisition.width;
1309 child_allocation.width =
1310 MAX (1, child_allocation.width -
1311 notebook->cur_page->requisition.width);
1317 children = notebook->children;
1320 page = children->data;
1321 children = children->next;
1323 if (GTK_WIDGET_VISIBLE (page->child))
1325 gtk_widget_size_allocate (page->child, &child_allocation);
1330 gtk_notebook_pages_allocate (notebook);
1333 if ((vis_pages != 0) != notebook->have_visible_child)
1335 notebook->have_visible_child = (vis_pages != 0);
1336 if (notebook->show_tabs)
1337 gtk_widget_queue_draw (widget);
1342 gtk_notebook_expose (GtkWidget *widget,
1343 GdkEventExpose *event)
1345 GtkNotebook *notebook;
1346 GdkRectangle child_area;
1348 g_return_val_if_fail (GTK_IS_NOTEBOOK (widget), FALSE);
1349 g_return_val_if_fail (event != NULL, FALSE);
1351 if (GTK_WIDGET_DRAWABLE (widget))
1353 notebook = GTK_NOTEBOOK (widget);
1355 gtk_notebook_paint (widget, &event->area);
1356 if (notebook->show_tabs)
1358 if (notebook->cur_page &&
1359 gtk_widget_intersect (notebook->cur_page->tab_label,
1360 &event->area, &child_area))
1361 gtk_notebook_draw_focus (widget);
1365 if (notebook->cur_page)
1366 gtk_container_propagate_expose (GTK_CONTAINER (notebook),
1367 notebook->cur_page->child,
1375 gtk_notebook_show_arrows (GtkNotebook *notebook)
1377 gboolean show_arrow = FALSE;
1380 if (!notebook->scrollable)
1383 children = notebook->children;
1386 GtkNotebookPage *page = children->data;
1388 if (page->tab_label && !gtk_widget_get_child_visible (page->tab_label))
1391 children = children->next;
1398 gtk_notebook_get_arrow_rect (GtkNotebook *notebook,
1399 GdkRectangle *rectangle)
1401 GdkRectangle event_window_pos;
1403 if (gtk_notebook_get_event_window_position (notebook, &event_window_pos))
1405 rectangle->width = 2 * ARROW_SIZE + ARROW_SPACING;
1406 rectangle->height = ARROW_SIZE;
1408 switch (notebook->tab_pos)
1412 rectangle->x = event_window_pos.x + (event_window_pos.width - rectangle->width) / 2;
1413 rectangle->y = event_window_pos.y + event_window_pos.height - rectangle->height;
1416 case GTK_POS_BOTTOM:
1417 rectangle->x = event_window_pos.x + event_window_pos.width - rectangle->width;
1418 rectangle->y = event_window_pos.y + (event_window_pos.height - rectangle->height) / 2;
1425 gtk_notebook_get_arrow (GtkNotebook *notebook,
1429 GdkRectangle arrow_rect;
1430 GdkRectangle event_window_pos;
1432 if (gtk_notebook_show_arrows (notebook))
1434 gtk_notebook_get_event_window_position (notebook, &event_window_pos);
1435 gtk_notebook_get_arrow_rect (notebook, &arrow_rect);
1440 if (y >= 0 && y < arrow_rect.height)
1442 if (x >= 0 && x < ARROW_SIZE + ARROW_SPACING / 2)
1443 return GTK_ARROW_LEFT;
1444 else if (x >= ARROW_SIZE + ARROW_SPACING / 2 && x < arrow_rect.width)
1445 return GTK_ARROW_RIGHT;
1453 gtk_notebook_arrow_button_press (GtkNotebook *notebook,
1455 GdkEventButton *event)
1457 GtkWidget *widget = GTK_WIDGET (notebook);
1459 if (!GTK_WIDGET_HAS_FOCUS (widget))
1460 gtk_widget_grab_focus (widget);
1462 notebook->button = event->button;
1463 notebook->click_child = arrow;
1465 if (event->button == 1)
1467 GtkDirectionType dir;
1468 if (!notebook->focus_tab ||
1469 gtk_notebook_search_page (notebook, notebook->focus_tab,
1470 arrow == GTK_ARROW_LEFT ? STEP_PREV : STEP_NEXT,
1473 if (notebook->tab_pos == GTK_POS_LEFT ||
1474 notebook->tab_pos == GTK_POS_RIGHT)
1475 dir = (arrow == GTK_ARROW_LEFT) ? GTK_DIR_UP : GTK_DIR_DOWN;
1477 dir = (arrow == GTK_ARROW_LEFT) ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
1478 gtk_widget_child_focus (widget, dir);
1481 if (!notebook->timer)
1483 notebook->timer = gtk_timeout_add
1484 (NOTEBOOK_INIT_SCROLL_DELAY,
1485 (GtkFunction) gtk_notebook_timer, (gpointer) notebook);
1486 notebook->need_timer = TRUE;
1489 else if (event->button == 2)
1490 gtk_notebook_page_select (notebook, TRUE);
1491 else if (event->button == 3)
1492 gtk_notebook_switch_focus_tab (notebook,
1493 gtk_notebook_search_page (notebook,
1495 arrow == GTK_ARROW_LEFT ? STEP_NEXT : STEP_PREV,
1497 gtk_notebook_redraw_arrows (notebook);
1503 get_widget_coordinates (GtkWidget *widget,
1508 GdkWindow *window = ((GdkEventAny *)event)->window;
1511 if (!gdk_event_get_coords (event, &tx, &ty))
1514 while (window && window != widget->window)
1516 gint window_x, window_y;
1518 gdk_window_get_position (window, &window_x, &window_y);
1522 window = gdk_window_get_parent (window);
1537 gtk_notebook_button_press (GtkWidget *widget,
1538 GdkEventButton *event)
1540 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
1541 GtkNotebookPage *page;
1547 if (event->type != GDK_BUTTON_PRESS || !notebook->children ||
1551 if (!get_widget_coordinates (widget, (GdkEvent *)event, &x, &y))
1554 arrow = gtk_notebook_get_arrow (notebook, x, y);
1556 return gtk_notebook_arrow_button_press (notebook, arrow, event);
1558 if (event->button == 3 && notebook->menu)
1560 gtk_menu_popup (GTK_MENU (notebook->menu), NULL, NULL,
1561 NULL, NULL, 3, event->time);
1566 children = notebook->children;
1569 page = children->data;
1571 if (GTK_WIDGET_VISIBLE (page->child) &&
1572 page->tab_label && GTK_WIDGET_MAPPED (page->tab_label) &&
1573 (x >= page->allocation.x) &&
1574 (y >= page->allocation.y) &&
1575 (x <= (page->allocation.x + page->allocation.width)) &&
1576 (y <= (page->allocation.y + page->allocation.height)))
1578 if (page == notebook->cur_page && notebook->focus_tab &&
1579 notebook->focus_tab != children &&
1580 GTK_WIDGET_HAS_FOCUS (notebook))
1582 GtkNotebookPage *old_page;
1584 notebook->child_has_focus = FALSE;
1585 old_page = (GtkNotebookPage *)
1586 (notebook->focus_tab->data);
1587 gtk_notebook_switch_focus_tab (notebook, children);
1588 gtk_notebook_focus_changed (notebook, old_page);
1592 gtk_notebook_switch_focus_tab (notebook, children);
1593 gtk_widget_grab_focus (widget);
1594 gtk_notebook_switch_page (notebook, page, num);
1598 children = children->next;
1601 if (!children && !GTK_WIDGET_HAS_FOCUS (widget))
1602 gtk_widget_grab_focus (widget);
1608 gtk_notebook_button_release (GtkWidget *widget,
1609 GdkEventButton *event)
1611 GtkNotebook *notebook;
1613 g_return_val_if_fail (GTK_IS_NOTEBOOK (widget), FALSE);
1614 g_return_val_if_fail (event != NULL, FALSE);
1616 if (event->type != GDK_BUTTON_RELEASE)
1619 notebook = GTK_NOTEBOOK (widget);
1621 if (event->button == notebook->button)
1625 if (notebook->timer)
1627 gtk_timeout_remove (notebook->timer);
1628 notebook->timer = 0;
1629 notebook->need_timer = FALSE;
1631 click_child = notebook->click_child;
1632 notebook->click_child = 0;
1633 notebook->button = 0;
1634 gtk_notebook_redraw_arrows (notebook);
1643 gtk_notebook_enter_notify (GtkWidget *widget,
1644 GdkEventCrossing *event)
1646 GtkNotebook *notebook;
1650 g_return_val_if_fail (GTK_IS_NOTEBOOK (widget), FALSE);
1651 g_return_val_if_fail (event != NULL, FALSE);
1653 notebook = GTK_NOTEBOOK (widget);
1655 if (!get_widget_coordinates (widget, (GdkEvent *)event, &x, &y))
1658 arrow = gtk_notebook_get_arrow (notebook, x, y);
1660 if (arrow != notebook->in_child)
1662 notebook->in_child = arrow;
1663 gtk_notebook_redraw_arrows (notebook);
1672 gtk_notebook_leave_notify (GtkWidget *widget,
1673 GdkEventCrossing *event)
1675 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
1679 if (!get_widget_coordinates (widget, (GdkEvent *)event, &x, &y))
1682 arrow = gtk_notebook_get_arrow (notebook, x, y);
1684 if (notebook->in_child)
1686 notebook->in_child = 0;
1687 gtk_notebook_redraw_arrows (notebook);
1694 gtk_notebook_motion_notify (GtkWidget *widget,
1695 GdkEventMotion *event)
1697 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
1701 if (notebook->button)
1704 if (!get_widget_coordinates (widget, (GdkEvent *)event, &x, &y))
1707 arrow = gtk_notebook_get_arrow (notebook, x, y);
1709 if (arrow != notebook->in_child)
1711 notebook->in_child = arrow;
1712 gtk_notebook_redraw_arrows (notebook);
1719 gtk_notebook_focus_in (GtkWidget *widget,
1720 GdkEventFocus *event)
1722 GTK_NOTEBOOK (widget)->child_has_focus = FALSE;
1724 return (* GTK_WIDGET_CLASS (parent_class)->focus_in_event) (widget, event);
1728 gtk_notebook_draw_focus (GtkWidget *widget)
1730 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
1732 if (GTK_WIDGET_DRAWABLE (widget) && notebook->show_tabs &&
1733 notebook->focus_tab)
1735 GtkNotebookPage *page;
1739 gtk_widget_style_get (widget, "focus-line-width", &focus_width, NULL);
1741 page = notebook->focus_tab->data;
1743 area.x = page->tab_label->allocation.x - focus_width;
1744 area.y = page->tab_label->allocation.y - focus_width;
1745 area.width = page->tab_label->allocation.width + 2 * focus_width;
1746 area.height = page->tab_label->allocation.height + 2 * focus_width;
1748 gtk_notebook_draw_tab (GTK_NOTEBOOK (widget), page, &area);
1752 /* Private GtkContainer Methods :
1754 * gtk_notebook_set_child_arg
1755 * gtk_notebook_get_child_arg
1757 * gtk_notebook_remove
1758 * gtk_notebook_focus
1759 * gtk_notebook_set_focus_child
1760 * gtk_notebook_child_type
1761 * gtk_notebook_forall
1764 gtk_notebook_set_child_property (GtkContainer *container,
1767 const GValue *value,
1772 GtkPackType pack_type;
1774 /* not finding child's page is valid for menus or labels */
1775 if (!gtk_notebook_find_child (GTK_NOTEBOOK (container), child, NULL))
1778 switch (property_id)
1780 case CHILD_PROP_TAB_LABEL:
1781 /* a NULL pointer indicates a default_tab setting, otherwise
1782 * we need to set the associated label
1784 gtk_notebook_set_tab_label_text (GTK_NOTEBOOK (container), child,
1785 g_value_get_string (value));
1787 case CHILD_PROP_MENU_LABEL:
1788 gtk_notebook_set_menu_label_text (GTK_NOTEBOOK (container), child,
1789 g_value_get_string (value));
1791 case CHILD_PROP_POSITION:
1792 gtk_notebook_reorder_child (GTK_NOTEBOOK (container), child,
1793 g_value_get_int (value));
1795 case CHILD_PROP_TAB_EXPAND:
1796 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
1797 &expand, &fill, &pack_type);
1798 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (container), child,
1799 g_value_get_boolean (value),
1802 case CHILD_PROP_TAB_FILL:
1803 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
1804 &expand, &fill, &pack_type);
1805 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (container), child,
1807 g_value_get_boolean (value),
1810 case CHILD_PROP_TAB_PACK:
1811 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
1812 &expand, &fill, &pack_type);
1813 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (container), child,
1815 g_value_get_enum (value));
1818 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
1824 gtk_notebook_get_child_property (GtkContainer *container,
1831 GtkNotebook *notebook;
1835 GtkPackType pack_type;
1837 notebook = GTK_NOTEBOOK (container);
1839 /* not finding child's page is valid for menus or labels */
1840 list = gtk_notebook_find_child (notebook, child, NULL);
1843 /* nothing to set on labels or menus */
1844 g_param_value_set_default (pspec, value);
1848 switch (property_id)
1850 case CHILD_PROP_TAB_LABEL:
1851 label = gtk_notebook_get_tab_label (notebook, child);
1853 if (label && GTK_IS_LABEL (label))
1854 g_value_set_string (value, GTK_LABEL (label)->label);
1856 g_value_set_string (value, NULL);
1858 case CHILD_PROP_MENU_LABEL:
1859 label = gtk_notebook_get_menu_label (notebook, child);
1861 if (label && GTK_IS_LABEL (label))
1862 g_value_set_string (value, GTK_LABEL (label)->label);
1864 g_value_set_string (value, NULL);
1866 case CHILD_PROP_POSITION:
1867 g_value_set_int (value, g_list_position (notebook->children, list));
1869 case CHILD_PROP_TAB_EXPAND:
1870 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
1871 &expand, NULL, NULL);
1872 g_value_set_boolean (value, expand);
1874 case CHILD_PROP_TAB_FILL:
1875 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
1877 g_value_set_boolean (value, fill);
1879 case CHILD_PROP_TAB_PACK:
1880 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
1881 NULL, NULL, &pack_type);
1882 g_value_set_enum (value, pack_type);
1885 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
1891 gtk_notebook_add (GtkContainer *container,
1894 g_return_if_fail (GTK_IS_NOTEBOOK (container));
1896 gtk_notebook_insert_page_menu (GTK_NOTEBOOK (container), widget,
1901 gtk_notebook_remove (GtkContainer *container,
1904 GtkNotebook *notebook;
1905 GtkNotebookPage *page;
1909 g_return_if_fail (GTK_IS_NOTEBOOK (container));
1910 g_return_if_fail (widget != NULL);
1912 notebook = GTK_NOTEBOOK (container);
1914 children = notebook->children;
1918 page = children->data;
1919 if (page->child == widget)
1921 gtk_notebook_real_remove (notebook, children);
1925 children = children->next;
1930 focus_tabs_in (GtkNotebook *notebook)
1932 if (notebook->show_tabs && notebook->cur_page)
1934 gtk_widget_grab_focus (GTK_WIDGET (notebook));
1936 gtk_notebook_switch_focus_tab (notebook,
1937 g_list_find (notebook->children,
1938 notebook->cur_page));
1947 focus_tabs_move (GtkNotebook *notebook,
1948 GtkDirectionType direction,
1949 gint search_direction)
1953 new_page = gtk_notebook_search_page (notebook, notebook->focus_tab,
1954 search_direction, TRUE);
1956 gtk_notebook_switch_focus_tab (notebook, new_page);
1964 focus_child_in (GtkNotebook *notebook,
1965 GtkDirectionType direction)
1967 if (notebook->cur_page)
1968 return gtk_widget_child_focus (notebook->cur_page->child, direction);
1973 /* Focus in the notebook can either be on the pages, or on
1977 gtk_notebook_focus (GtkWidget *widget,
1978 GtkDirectionType direction)
1980 GtkWidget *old_focus_child;
1981 GtkNotebook *notebook;
1982 GtkDirectionType effective_direction;
1984 gboolean widget_is_focus;
1985 GtkContainer *container;
1987 g_return_val_if_fail (GTK_IS_NOTEBOOK (widget), FALSE);
1989 container = GTK_CONTAINER (widget);
1990 notebook = GTK_NOTEBOOK (container);
1992 if (notebook->focus_out)
1994 notebook->focus_out = FALSE; /* Clear this to catch the wrap-around case */
1998 widget_is_focus = gtk_widget_is_focus (widget);
1999 old_focus_child = container->focus_child;
2001 effective_direction = get_effective_direction (notebook, direction);
2003 if (old_focus_child) /* Focus on page child */
2005 if (gtk_widget_child_focus (old_focus_child, direction))
2008 switch (effective_direction)
2010 case GTK_DIR_TAB_BACKWARD:
2012 /* Focus onto the tabs */
2013 return focus_tabs_in (notebook);
2015 case GTK_DIR_TAB_FORWARD:
2021 else if (widget_is_focus) /* Focus was on tabs */
2023 switch (effective_direction)
2025 case GTK_DIR_TAB_BACKWARD:
2028 case GTK_DIR_TAB_FORWARD:
2030 /* We use TAB_FORWARD rather than direction so that we focus a more
2031 * predictable widget for the user; users may be using arrow focusing
2032 * in this situation even if they don't usually use arrow focusing.
2034 return focus_child_in (notebook, GTK_DIR_TAB_FORWARD);
2036 return focus_tabs_move (notebook, direction, STEP_PREV);
2038 return focus_tabs_move (notebook, direction, STEP_NEXT);
2041 else /* Focus was not on widget */
2043 switch (effective_direction)
2045 case GTK_DIR_TAB_FORWARD:
2047 if (focus_tabs_in (notebook))
2049 if (focus_child_in (notebook, direction))
2052 case GTK_DIR_TAB_BACKWARD:
2054 if (focus_child_in (notebook, direction))
2056 if (focus_tabs_in (notebook))
2061 return focus_child_in (notebook, direction);
2065 g_assert_not_reached ();
2070 gtk_notebook_set_focus_child (GtkContainer *container,
2073 GtkNotebook *notebook = GTK_NOTEBOOK (container);
2074 GtkWidget *page_child;
2075 GtkWidget *toplevel;
2077 /* If the old focus widget was within a page of the notebook,
2078 * (child may either be NULL or not in this case), record it
2079 * for future use if we switch to the page with a mnemonic.
2082 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (container));
2083 if (toplevel && GTK_WIDGET_TOPLEVEL (toplevel))
2085 page_child = GTK_WINDOW (toplevel)->focus_widget;
2088 if (page_child->parent == GTK_WIDGET (container))
2090 GList *list = gtk_notebook_find_child (notebook, page_child, NULL);
2093 GtkNotebookPage *page = list->data;
2095 if (page->last_focus_child)
2096 g_object_remove_weak_pointer (G_OBJECT (page->last_focus_child), (gpointer *)&page->last_focus_child);
2098 page->last_focus_child = GTK_WINDOW (toplevel)->focus_widget;
2099 g_object_add_weak_pointer (G_OBJECT (page->last_focus_child), (gpointer *)&page->last_focus_child);
2105 page_child = page_child->parent;
2111 g_return_if_fail (GTK_IS_WIDGET (child));
2113 notebook->child_has_focus = TRUE;
2114 if (!notebook->focus_tab)
2117 GtkNotebookPage *page;
2119 children = notebook->children;
2122 page = children->data;
2123 if (page->child == child || page->tab_label == child)
2124 gtk_notebook_switch_focus_tab (notebook, children);
2125 children = children->next;
2130 parent_class->set_focus_child (container, child);
2134 gtk_notebook_forall (GtkContainer *container,
2135 gboolean include_internals,
2136 GtkCallback callback,
2137 gpointer callback_data)
2139 GtkNotebook *notebook;
2142 g_return_if_fail (GTK_IS_NOTEBOOK (container));
2143 g_return_if_fail (callback != NULL);
2145 notebook = GTK_NOTEBOOK (container);
2147 children = notebook->children;
2150 GtkNotebookPage *page;
2152 page = children->data;
2153 children = children->next;
2154 (* callback) (page->child, callback_data);
2155 if (include_internals)
2157 if (page->tab_label)
2158 (* callback) (page->tab_label, callback_data);
2159 if (page->menu_label)
2160 (* callback) (page->menu_label, callback_data);
2166 gtk_notebook_child_type (GtkContainer *container)
2168 return GTK_TYPE_WIDGET;
2171 /* Private GtkNotebook Functions:
2173 * gtk_notebook_redraw_tabs
2174 * gtk_notebook_focus_changed
2175 * gtk_notebook_real_remove
2176 * gtk_notebook_update_labels
2177 * gtk_notebook_timer
2178 * gtk_notebook_page_compare
2179 * gtk_notebook_real_page_position
2180 * gtk_notebook_search_page
2183 gtk_notebook_redraw_tabs (GtkNotebook *notebook)
2186 GtkNotebookPage *page;
2187 GdkRectangle redraw_rect;
2190 widget = GTK_WIDGET (notebook);
2191 border = GTK_CONTAINER (notebook)->border_width;
2193 if (!GTK_WIDGET_MAPPED (notebook) || !notebook->first_tab)
2196 page = notebook->first_tab->data;
2198 redraw_rect.x = border;
2199 redraw_rect.y = border;
2201 switch (notebook->tab_pos)
2203 case GTK_POS_BOTTOM:
2204 redraw_rect.y = (widget->allocation.height - border -
2205 page->allocation.height -
2206 widget->style->ythickness);
2207 if (page != notebook->cur_page)
2208 redraw_rect.y -= widget->style->ythickness;
2211 redraw_rect.width = widget->allocation.width - 2 * border;
2212 redraw_rect.height = (page->allocation.height +
2213 widget->style->ythickness);
2214 if (page != notebook->cur_page)
2215 redraw_rect.height += widget->style->ythickness;
2218 redraw_rect.x = (widget->allocation.width - border -
2219 page->allocation.width -
2220 widget->style->xthickness);
2221 if (page != notebook->cur_page)
2222 redraw_rect.x -= widget->style->xthickness;
2225 redraw_rect.width = (page->allocation.width +
2226 widget->style->xthickness);
2227 redraw_rect.height = widget->allocation.height - 2 * border;
2228 if (page != notebook->cur_page)
2229 redraw_rect.width += widget->style->xthickness;
2233 redraw_rect.x += widget->allocation.x;
2234 redraw_rect.y += widget->allocation.y;
2236 gdk_window_invalidate_rect (widget->window, &redraw_rect, TRUE);
2240 gtk_notebook_redraw_arrows (GtkNotebook *notebook)
2242 if (GTK_WIDGET_MAPPED (notebook) && gtk_notebook_show_arrows (notebook))
2246 gtk_notebook_get_arrow_rect (notebook, &rect);
2247 gdk_window_invalidate_rect (GTK_WIDGET (notebook)->window, &rect, FALSE);
2252 gtk_notebook_focus_changed (GtkNotebook *notebook,
2253 GtkNotebookPage *old_page)
2255 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
2257 if (GTK_WIDGET_DRAWABLE (notebook) && notebook->show_tabs)
2262 gtk_widget_style_get (GTK_WIDGET (notebook), "focus-line-width", &focus_width, NULL);
2264 if (notebook->focus_tab)
2266 GtkNotebookPage *page;
2268 page = notebook->focus_tab->data;
2270 area.x = page->tab_label->allocation.x - focus_width;
2271 area.y = page->tab_label->allocation.y - focus_width;
2272 area.width = page->tab_label->allocation.width + 2 * focus_width;
2273 area.height = page->tab_label->allocation.height + 2 * focus_width;
2275 gtk_notebook_draw_tab (notebook, page, &area);
2280 area.x = old_page->tab_label->allocation.x - focus_width;
2281 area.y = old_page->tab_label->allocation.y - focus_width;
2282 area.width = old_page->tab_label->allocation.width + 2 * focus_width;
2283 area.height = old_page->tab_label->allocation.height + 2 * focus_width;
2285 gtk_notebook_draw_tab (notebook, old_page, &area);
2291 gtk_notebook_timer (GtkNotebook *notebook)
2293 gboolean retval = FALSE;
2295 GDK_THREADS_ENTER ();
2297 if (notebook->timer)
2299 if (notebook->click_child == GTK_ARROW_LEFT)
2301 if (!notebook->focus_tab ||
2302 gtk_notebook_search_page (notebook, notebook->focus_tab,
2304 gtk_widget_child_focus (GTK_WIDGET (notebook), GTK_DIR_LEFT);
2306 else if (notebook->click_child == GTK_ARROW_RIGHT)
2308 if (!notebook->focus_tab ||
2309 gtk_notebook_search_page (notebook, notebook->focus_tab,
2311 gtk_widget_child_focus (GTK_WIDGET (notebook), GTK_DIR_RIGHT);
2313 if (notebook->need_timer)
2315 notebook->need_timer = FALSE;
2316 notebook->timer = gtk_timeout_add (NOTEBOOK_SCROLL_DELAY,
2317 (GtkFunction) gtk_notebook_timer,
2318 (gpointer) notebook);
2324 GDK_THREADS_LEAVE ();
2330 gtk_notebook_page_compare (gconstpointer a,
2333 return (((GtkNotebookPage *) a)->child != b);
2337 gtk_notebook_find_child (GtkNotebook *notebook,
2339 const gchar *function)
2341 GList *list = g_list_find_custom (notebook->children, child,
2342 gtk_notebook_page_compare);
2344 #ifndef G_DISABLE_CHECKS
2345 if (!list && function)
2346 g_warning ("%s: unable to find child %p in notebook %p",
2347 function, child, notebook);
2354 gtk_notebook_remove_tab_label (GtkNotebook *notebook,
2355 GtkNotebookPage *page)
2357 if (page->tab_label)
2359 if (page->mnemonic_activate_signal)
2360 gtk_signal_disconnect (page->tab_label,
2361 page->mnemonic_activate_signal);
2362 page->mnemonic_activate_signal = 0;
2364 gtk_widget_unparent (page->tab_label);
2369 gtk_notebook_real_remove (GtkNotebook *notebook,
2372 GtkNotebookPage *page;
2374 gint need_resize = FALSE;
2376 next_list = gtk_notebook_search_page (notebook, list, STEP_PREV, TRUE);
2378 next_list = gtk_notebook_search_page (notebook, list, STEP_NEXT, TRUE);
2380 if (notebook->cur_page == list->data)
2382 notebook->cur_page = NULL;
2384 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (next_list), -1);
2387 if (list == notebook->first_tab)
2388 notebook->first_tab = next_list;
2389 if (list == notebook->focus_tab)
2390 gtk_notebook_switch_focus_tab (notebook, next_list);
2394 if (page->last_focus_child)
2395 g_object_remove_weak_pointer (G_OBJECT (page->last_focus_child), (gpointer *)&page->last_focus_child);
2397 if (GTK_WIDGET_VISIBLE (page->child) && GTK_WIDGET_VISIBLE (notebook))
2400 gtk_widget_unparent (page->child);
2402 gtk_notebook_remove_tab_label (notebook, page);
2406 gtk_container_remove (GTK_CONTAINER (notebook->menu),
2407 page->menu_label->parent);
2408 gtk_widget_queue_resize (notebook->menu);
2410 if (!page->default_menu)
2411 gtk_widget_unref (page->menu_label);
2413 notebook->children = g_list_remove_link (notebook->children, list);
2417 if (!notebook->children && notebook->show_tabs &&
2418 GTK_WIDGET_MAPPED (notebook))
2419 gdk_window_hide (notebook->event_window);
2421 gtk_notebook_update_labels (notebook);
2423 gtk_widget_queue_resize (GTK_WIDGET (notebook));
2427 gtk_notebook_update_labels (GtkNotebook *notebook)
2429 GtkNotebookPage *page;
2434 for (list = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, FALSE);
2436 list = gtk_notebook_search_page (notebook, list, STEP_NEXT, FALSE))
2439 g_snprintf (string, sizeof(string), _("Page %u"), page_num++);
2440 if (notebook->show_tabs)
2442 if (page->default_tab)
2444 if (!page->tab_label)
2446 page->tab_label = gtk_label_new (string);
2447 gtk_widget_set_parent (page->tab_label,
2448 GTK_WIDGET (notebook));
2451 gtk_label_set_text (GTK_LABEL (page->tab_label), string);
2454 if (GTK_WIDGET_VISIBLE (page->child) &&
2455 !GTK_WIDGET_VISIBLE (page->tab_label))
2456 gtk_widget_show (page->tab_label);
2457 else if (!GTK_WIDGET_VISIBLE (page->child) &&
2458 GTK_WIDGET_VISIBLE (page->tab_label))
2459 gtk_widget_hide (page->tab_label);
2461 if (notebook->menu && page->default_menu)
2463 if (page->tab_label && GTK_IS_LABEL (page->tab_label))
2464 gtk_label_set_text (GTK_LABEL (page->menu_label),
2465 GTK_LABEL (page->tab_label)->label);
2467 gtk_label_set_text (GTK_LABEL (page->menu_label), string);
2473 gtk_notebook_real_page_position (GtkNotebook *notebook,
2479 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
2480 g_return_val_if_fail (list != NULL, -1);
2482 for (work = notebook->children, count_start = 0;
2483 work && work != list; work = work->next)
2484 if (GTK_NOTEBOOK_PAGE (work)->pack == GTK_PACK_START)
2490 if (GTK_NOTEBOOK_PAGE (list)->pack == GTK_PACK_START)
2493 return (count_start + g_list_length (list) - 1);
2497 gtk_notebook_search_page (GtkNotebook *notebook,
2500 gboolean find_visible)
2502 GtkNotebookPage *page = NULL;
2503 GList *old_list = NULL;
2506 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
2511 flag = GTK_PACK_END;
2515 flag = GTK_PACK_START;
2522 if (!page || page->pack == flag)
2530 list = notebook->children;
2535 if (page->pack == flag &&
2536 (!find_visible || GTK_WIDGET_VISIBLE (page->child)))
2551 if (page->pack != flag &&
2552 (!find_visible || GTK_WIDGET_VISIBLE (page->child)))
2560 /* Private GtkNotebook Drawing Functions:
2562 * gtk_notebook_paint
2563 * gtk_notebook_draw_tab
2564 * gtk_notebook_draw_arrow
2567 gtk_notebook_paint (GtkWidget *widget,
2570 GtkNotebook *notebook;
2571 GtkNotebookPage *page;
2576 gint border_width = GTK_CONTAINER (widget)->border_width;
2577 gint gap_x = 0, gap_width = 0;
2579 g_return_if_fail (GTK_IS_NOTEBOOK (widget));
2580 g_return_if_fail (area != NULL);
2582 if (!GTK_WIDGET_DRAWABLE (widget))
2585 notebook = GTK_NOTEBOOK (widget);
2587 if ((!notebook->show_tabs && !notebook->show_border) ||
2588 !notebook->cur_page || !GTK_WIDGET_VISIBLE (notebook->cur_page->child))
2591 x = widget->allocation.x + border_width;
2592 y = widget->allocation.y + border_width;
2593 width = widget->allocation.width - border_width * 2;
2594 height = widget->allocation.height - border_width * 2;
2596 if (notebook->show_border && (!notebook->show_tabs || !notebook->children))
2598 gtk_paint_box (widget->style, widget->window,
2599 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
2600 area, widget, "notebook",
2601 x, y, width, height);
2606 if (!GTK_WIDGET_MAPPED (notebook->cur_page->tab_label))
2608 page = notebook->first_tab->data;
2610 switch (notebook->tab_pos)
2613 y += page->allocation.height + widget->style->ythickness;
2614 case GTK_POS_BOTTOM:
2615 height -= page->allocation.height + widget->style->ythickness;
2618 x += page->allocation.width + widget->style->xthickness;
2620 width -= page->allocation.width + widget->style->xthickness;
2623 gtk_paint_box (widget->style, widget->window,
2624 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
2625 area, widget, "notebook",
2626 x, y, width, height);
2630 switch (notebook->tab_pos)
2633 y += notebook->cur_page->allocation.height;
2634 case GTK_POS_BOTTOM:
2635 height -= notebook->cur_page->allocation.height;
2638 x += notebook->cur_page->allocation.width;
2640 width -= notebook->cur_page->allocation.width;
2644 switch (notebook->tab_pos)
2647 case GTK_POS_BOTTOM:
2648 gap_x = (notebook->cur_page->allocation.x - widget->allocation.x - border_width);
2649 gap_width = notebook->cur_page->allocation.width;
2653 gap_x = (notebook->cur_page->allocation.y - widget->allocation.y - border_width);
2654 gap_width = notebook->cur_page->allocation.height;
2657 gtk_paint_box_gap(widget->style, widget->window,
2658 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
2659 area, widget, "notebook",
2660 x, y, width, height,
2661 notebook->tab_pos, gap_x, gap_width);
2665 children = gtk_notebook_search_page (notebook, NULL, STEP_PREV, TRUE);
2668 page = children->data;
2669 children = gtk_notebook_search_page (notebook, children,
2671 if (!GTK_WIDGET_VISIBLE (page->child))
2673 if (!GTK_WIDGET_MAPPED (page->tab_label))
2675 else if (page != notebook->cur_page)
2676 gtk_notebook_draw_tab (notebook, page, area);
2679 if (showarrow && notebook->scrollable)
2681 gtk_notebook_draw_arrow (notebook, GTK_ARROW_LEFT);
2682 gtk_notebook_draw_arrow (notebook, GTK_ARROW_RIGHT);
2684 gtk_notebook_draw_tab (notebook, notebook->cur_page, area);
2688 gtk_notebook_draw_tab (GtkNotebook *notebook,
2689 GtkNotebookPage *page,
2692 GdkRectangle child_area;
2693 GdkRectangle page_area;
2694 GtkStateType state_type;
2695 GtkPositionType gap_side;
2697 g_return_if_fail (notebook != NULL);
2698 g_return_if_fail (page != NULL);
2699 g_return_if_fail (area != NULL);
2701 if (!GTK_WIDGET_MAPPED (page->tab_label) ||
2702 (page->allocation.width == 0) || (page->allocation.height == 0))
2705 page_area.x = page->allocation.x;
2706 page_area.y = page->allocation.y;
2707 page_area.width = page->allocation.width;
2708 page_area.height = page->allocation.height;
2710 if (gdk_rectangle_intersect (&page_area, area, &child_area))
2714 widget = GTK_WIDGET (notebook);
2716 switch (notebook->tab_pos)
2719 gap_side = GTK_POS_BOTTOM;
2721 case GTK_POS_BOTTOM:
2722 gap_side = GTK_POS_TOP;
2725 gap_side = GTK_POS_RIGHT;
2728 gap_side = GTK_POS_LEFT;
2732 if (notebook->cur_page == page)
2733 state_type = GTK_STATE_NORMAL;
2735 state_type = GTK_STATE_ACTIVE;
2736 gtk_paint_extension(widget->style, widget->window,
2737 state_type, GTK_SHADOW_OUT,
2738 area, widget, "tab",
2739 page_area.x, page_area.y,
2740 page_area.width, page_area.height,
2742 if ((GTK_WIDGET_HAS_FOCUS (widget)) &&
2743 notebook->focus_tab && (notebook->focus_tab->data == page))
2747 gtk_widget_style_get (widget, "focus-line-width", &focus_width, NULL);
2749 gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget),
2750 area, widget, "tab",
2751 page->tab_label->allocation.x - focus_width,
2752 page->tab_label->allocation.y - focus_width,
2753 page->tab_label->allocation.width + 2 * focus_width,
2754 page->tab_label->allocation.height + 2 * focus_width);
2756 if (gtk_widget_intersect (page->tab_label, area, &child_area) &&
2757 GTK_WIDGET_DRAWABLE (page->tab_label))
2759 GdkEventExpose expose_event;
2761 /* This is a lame hack since all this code needs rewriting anyhow */
2763 expose_event.window = page->tab_label->window;
2764 expose_event.area = child_area;
2765 expose_event.region = gdk_region_rectangle (&child_area);
2766 expose_event.send_event = TRUE;
2767 expose_event.type = GDK_EXPOSE;
2768 expose_event.count = 0;
2770 gtk_container_propagate_expose (GTK_CONTAINER (notebook), page->tab_label, &expose_event);
2772 gdk_region_destroy (expose_event.region);
2778 gtk_notebook_draw_arrow (GtkNotebook *notebook,
2781 GtkStateType state_type;
2782 GtkShadowType shadow_type;
2784 GdkRectangle arrow_rect;
2786 gtk_notebook_get_arrow_rect (notebook, &arrow_rect);
2788 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
2790 widget = GTK_WIDGET(notebook);
2792 if (GTK_WIDGET_DRAWABLE (notebook))
2794 if (notebook->in_child == arrow)
2796 if (notebook->click_child == arrow)
2797 state_type = GTK_STATE_ACTIVE;
2799 state_type = GTK_STATE_PRELIGHT;
2802 state_type = GTK_STATE_NORMAL;
2804 if (notebook->click_child == arrow)
2805 shadow_type = GTK_SHADOW_IN;
2807 shadow_type = GTK_SHADOW_OUT;
2809 if (arrow == GTK_ARROW_LEFT)
2811 if (notebook->focus_tab &&
2812 !gtk_notebook_search_page (notebook, notebook->focus_tab,
2815 shadow_type = GTK_SHADOW_ETCHED_IN;
2816 state_type = GTK_STATE_INSENSITIVE;
2819 if (notebook->tab_pos == GTK_POS_LEFT ||
2820 notebook->tab_pos == GTK_POS_RIGHT)
2821 arrow = GTK_ARROW_UP;
2823 gtk_paint_arrow (widget->style, widget->window, state_type,
2824 shadow_type, NULL, GTK_WIDGET(notebook), "notebook",
2826 arrow_rect.x, arrow_rect.y, ARROW_SIZE, ARROW_SIZE);
2830 if (notebook->focus_tab &&
2831 !gtk_notebook_search_page (notebook, notebook->focus_tab,
2834 shadow_type = GTK_SHADOW_ETCHED_IN;
2835 state_type = GTK_STATE_INSENSITIVE;
2838 if (notebook->tab_pos == GTK_POS_LEFT ||
2839 notebook->tab_pos == GTK_POS_RIGHT)
2840 arrow = GTK_ARROW_DOWN;
2842 gtk_paint_arrow (widget->style, widget->window, state_type,
2843 shadow_type, NULL, GTK_WIDGET(notebook), "notebook",
2844 arrow, TRUE, arrow_rect.x + ARROW_SIZE + ARROW_SPACING,
2845 arrow_rect.y, ARROW_SIZE, ARROW_SIZE);
2850 /* Private GtkNotebook Size Allocate Functions:
2852 * gtk_notebook_pages_allocate
2853 * gtk_notebook_page_allocate
2854 * gtk_notebook_calc_tabs
2857 gtk_notebook_pages_allocate (GtkNotebook *notebook)
2859 GtkWidget *widget = GTK_WIDGET (notebook);
2860 GtkContainer *container = GTK_CONTAINER (notebook);
2861 GtkNotebookPage *page = NULL;
2862 GtkAllocation *allocation = &widget->allocation;
2863 GtkAllocation child_allocation;
2864 GList *children = NULL;
2865 GList *last_child = NULL;
2866 gboolean showarrow = FALSE;
2876 if (!notebook->show_tabs || !notebook->children || !notebook->cur_page)
2879 child_allocation.x = widget->allocation.x + container->border_width;
2880 child_allocation.y = widget->allocation.y + container->border_width;
2882 switch (notebook->tab_pos)
2884 case GTK_POS_BOTTOM:
2885 child_allocation.y = (widget->allocation.y +
2886 allocation->height -
2887 notebook->cur_page->requisition.height -
2888 container->border_width);
2891 child_allocation.height = notebook->cur_page->requisition.height;
2895 child_allocation.x = (widget->allocation.x +
2897 notebook->cur_page->requisition.width -
2898 container->border_width);
2901 child_allocation.width = notebook->cur_page->requisition.width;
2905 if (notebook->scrollable)
2909 children = notebook->children;
2911 if (notebook->focus_tab)
2912 focus_tab = notebook->focus_tab;
2913 else if (notebook->first_tab)
2914 focus_tab = notebook->first_tab;
2916 focus_tab = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, TRUE);
2918 switch (notebook->tab_pos)
2921 case GTK_POS_BOTTOM:
2924 page = children->data;
2925 children = children->next;
2927 if (GTK_WIDGET_VISIBLE (page->child))
2928 tab_space += page->requisition.width;
2931 allocation->width - 2 * container->border_width - TAB_OVERLAP)
2934 page = focus_tab->data;
2936 tab_space = (allocation->width - TAB_OVERLAP -
2937 page->requisition.width -
2938 2 * (container->border_width + ARROW_SPACING +
2940 x = (allocation->width - 2 * ARROW_SIZE - ARROW_SPACING -
2941 container->border_width);
2943 page = notebook->children->data;
2944 if (notebook->tab_pos == GTK_POS_TOP)
2945 y = (container->border_width +
2946 (page->requisition.height - ARROW_SIZE) / 2);
2948 y = (allocation->height - container->border_width -
2949 ARROW_SIZE - (page->requisition.height - ARROW_SIZE) / 2);
2956 page = children->data;
2957 children = children->next;
2959 if (GTK_WIDGET_VISIBLE (page->child))
2960 tab_space += page->requisition.height;
2963 (allocation->height - 2 * container->border_width - TAB_OVERLAP))
2966 page = focus_tab->data;
2967 tab_space = (allocation->height -
2968 ARROW_SIZE - ARROW_SPACING - TAB_OVERLAP -
2969 2 * container->border_width -
2970 page->requisition.height);
2971 y = allocation->height - container->border_width - ARROW_SIZE;
2973 page = notebook->children->data;
2974 if (notebook->tab_pos == GTK_POS_LEFT)
2975 x = (container->border_width +
2976 (page->requisition.width -
2977 (2 * ARROW_SIZE - ARROW_SPACING)) / 2);
2979 x = (allocation->width - container->border_width -
2980 (2 * ARROW_SIZE - ARROW_SPACING) -
2981 (page->requisition.width -
2982 (2 * ARROW_SIZE - ARROW_SPACING)) / 2);
2986 if (showarrow) /* first_tab <- focus_tab */
2990 notebook->first_tab = focus_tab;
2991 last_child = gtk_notebook_search_page (notebook, focus_tab,
2997 if (notebook->first_tab && notebook->first_tab != focus_tab)
2999 /* Is first_tab really predecessor of focus_tab ? */
3000 page = notebook->first_tab->data;
3001 if (GTK_WIDGET_VISIBLE (page->child))
3002 for (children = focus_tab;
3003 children && children != notebook->first_tab;
3004 children = gtk_notebook_search_page (notebook,
3010 notebook->first_tab = focus_tab;
3012 gtk_notebook_calc_tabs (notebook,
3013 gtk_notebook_search_page (notebook,
3017 &(notebook->first_tab), &tab_space,
3022 notebook->first_tab =
3023 gtk_notebook_search_page (notebook, notebook->first_tab,
3025 if (!notebook->first_tab)
3026 notebook->first_tab = focus_tab;
3027 last_child = gtk_notebook_search_page (notebook, focus_tab,
3030 else /* focus_tab -> end */
3032 if (!notebook->first_tab)
3033 notebook->first_tab = gtk_notebook_search_page (notebook,
3038 gtk_notebook_calc_tabs (notebook,
3039 gtk_notebook_search_page (notebook,
3043 &children, &tab_space, STEP_NEXT);
3046 last_child = children;
3047 else /* start <- first_tab */
3051 gtk_notebook_calc_tabs
3053 gtk_notebook_search_page (notebook,
3054 notebook->first_tab,
3057 &children, &tab_space, STEP_PREV);
3058 notebook->first_tab = gtk_notebook_search_page(notebook,
3068 tab_space = -tab_space;
3070 for (children = notebook->first_tab;
3071 children && children != last_child;
3072 children = gtk_notebook_search_page (notebook, children,
3079 /*unmap all non-visible tabs*/
3080 for (children = gtk_notebook_search_page (notebook, NULL,
3082 children && children != notebook->first_tab;
3083 children = gtk_notebook_search_page (notebook, children,
3086 page = children->data;
3087 if (page->tab_label)
3088 gtk_widget_set_child_visible (page->tab_label, FALSE);
3090 for (children = last_child; children;
3091 children = gtk_notebook_search_page (notebook, children,
3094 page = children->data;
3095 if (page->tab_label)
3096 gtk_widget_set_child_visible (page->tab_label, FALSE);
3099 else /* !showarrow */
3101 notebook->first_tab = gtk_notebook_search_page (notebook, NULL,
3112 children = notebook->children;
3113 switch (notebook->tab_pos)
3116 case GTK_POS_BOTTOM:
3119 page = children->data;
3120 children = children->next;
3122 if (GTK_WIDGET_VISIBLE (page->child))
3125 tab_space += page->requisition.width;
3130 tab_space -= allocation->width;
3136 page = children->data;
3137 children = children->next;
3139 if (GTK_WIDGET_VISIBLE (page->child))
3142 tab_space += page->requisition.height;
3147 tab_space -= allocation->height;
3149 tab_space += 2 * container->border_width + TAB_OVERLAP;
3151 notebook->first_tab = gtk_notebook_search_page (notebook, NULL,
3153 if (notebook->homogeneous && n)
3157 children = notebook->first_tab;
3161 if (children == last_child)
3163 /* FIXME double check */
3167 page = children->data;
3168 if (!showarrow && page->pack != GTK_PACK_START)
3170 children = gtk_notebook_search_page (notebook, children, STEP_NEXT,TRUE);
3173 if (n && (showarrow || page->expand || notebook->homogeneous))
3175 new_fill = (tab_space * i++) / n;
3176 delta = new_fill - old_fill;
3177 old_fill = new_fill;
3180 switch (notebook->tab_pos)
3183 case GTK_POS_BOTTOM:
3184 child_allocation.width = (page->requisition.width +
3185 TAB_OVERLAP + delta);
3189 child_allocation.height = (page->requisition.height +
3190 TAB_OVERLAP + delta);
3194 gtk_notebook_page_allocate (notebook, page, &child_allocation);
3196 switch (notebook->tab_pos)
3199 case GTK_POS_BOTTOM:
3200 child_allocation.x += child_allocation.width - TAB_OVERLAP;
3204 child_allocation.y += child_allocation.height - TAB_OVERLAP;
3208 if (page->tab_label)
3209 gtk_widget_set_child_visible (page->tab_label, TRUE);
3214 children = notebook->children;
3215 switch (notebook->tab_pos)
3218 case GTK_POS_BOTTOM:
3219 child_allocation.x = (allocation->x + allocation->width -
3220 container->border_width);
3224 child_allocation.y = (allocation->y + allocation->height -
3225 container->border_width);
3229 while (children != last_child)
3231 page = children->data;
3232 children = children->next;
3234 if (page->pack != GTK_PACK_END || !GTK_WIDGET_VISIBLE (page->child))
3238 if (n && (page->expand || notebook->homogeneous))
3240 new_fill = (tab_space * i++) / n;
3241 delta = new_fill - old_fill;
3242 old_fill = new_fill;
3245 switch (notebook->tab_pos)
3248 case GTK_POS_BOTTOM:
3249 child_allocation.width = (page->requisition.width +
3250 TAB_OVERLAP + delta);
3251 child_allocation.x -= child_allocation.width;
3255 child_allocation.height = (page->requisition.height +
3256 TAB_OVERLAP + delta);
3257 child_allocation.y -= child_allocation.height;
3261 gtk_notebook_page_allocate (notebook, page, &child_allocation);
3263 switch (notebook->tab_pos)
3266 case GTK_POS_BOTTOM:
3267 child_allocation.x += TAB_OVERLAP;
3271 child_allocation.y += TAB_OVERLAP;
3275 if (page->tab_label)
3276 gtk_widget_set_child_visible (page->tab_label, TRUE);
3281 gtk_notebook_redraw_tabs (notebook);
3285 gtk_notebook_page_allocate (GtkNotebook *notebook,
3286 GtkNotebookPage *page,
3287 GtkAllocation *allocation)
3289 GtkWidget *widget = GTK_WIDGET (notebook);
3290 GtkAllocation child_allocation;
3291 GtkRequisition tab_requisition;
3297 gtk_widget_style_get (widget, "focus-line-width", &focus_width, NULL);
3299 xthickness = widget->style->xthickness;
3300 ythickness = widget->style->ythickness;
3302 /* If the size of the notebook tabs change, we need to queue
3303 * a redraw on the tab area
3305 if ((allocation->width != page->allocation.width) ||
3306 (allocation->height != page->allocation.height))
3308 gint x, y, width, height, border_width;
3310 border_width = GTK_CONTAINER (notebook)->border_width;
3312 switch (notebook->tab_pos)
3315 width = widget->allocation.width;
3316 height = MAX (page->allocation.height, allocation->height) + ythickness;
3321 case GTK_POS_BOTTOM:
3322 width = widget->allocation.width + xthickness;
3323 height = MAX (page->allocation.height, allocation->height) + ythickness;
3325 y = widget->allocation.height - height - border_width;
3329 width = MAX (page->allocation.width, allocation->width) + xthickness;
3330 height = widget->allocation.height;
3336 default: /* quiet gcc */
3337 width = MAX (page->allocation.width, allocation->width) + xthickness;
3338 height = widget->allocation.height;
3339 x = widget->allocation.width - width - border_width;
3344 gtk_widget_queue_clear_area (widget, x, y, width, height);
3347 page->allocation = *allocation;
3348 gtk_widget_get_child_requisition (page->tab_label, &tab_requisition);
3350 if (notebook->cur_page != page)
3352 switch (notebook->tab_pos)
3355 page->allocation.y += ythickness;
3356 case GTK_POS_BOTTOM:
3357 if (page->allocation.height > ythickness)
3358 page->allocation.height -= ythickness;
3361 page->allocation.x += xthickness;
3363 if (page->allocation.width > xthickness)
3364 page->allocation.width -= xthickness;
3369 switch (notebook->tab_pos)
3372 case GTK_POS_BOTTOM:
3373 padding = TAB_CURVATURE + focus_width + notebook->tab_hborder;
3376 child_allocation.x = (xthickness + focus_width +
3377 notebook->tab_hborder);
3378 child_allocation.width = MAX (1, (page->allocation.width -
3379 2 * child_allocation.x));
3380 child_allocation.x += page->allocation.x;
3384 child_allocation.x = (page->allocation.x +
3385 (page->allocation.width -
3386 tab_requisition.width) / 2);
3387 child_allocation.width = tab_requisition.width;
3389 child_allocation.y = (notebook->tab_vborder + focus_width +
3390 page->allocation.y);
3391 if (notebook->tab_pos == GTK_POS_TOP)
3392 child_allocation.y += ythickness;
3393 child_allocation.height = MAX (1, (((gint) page->allocation.height) - ythickness -
3394 2 * (notebook->tab_vborder + focus_width)));
3398 padding = TAB_CURVATURE + focus_width + notebook->tab_vborder;
3401 child_allocation.y = ythickness + padding;
3402 child_allocation.height = MAX (1, (page->allocation.height -
3403 2 * child_allocation.y));
3404 child_allocation.y += page->allocation.y;
3408 child_allocation.y = (page->allocation.y + (page->allocation.height -
3409 tab_requisition.height) / 2);
3410 child_allocation.height = tab_requisition.height;
3412 child_allocation.x = page->allocation.x + notebook->tab_hborder + focus_width;
3413 if (notebook->tab_pos == GTK_POS_LEFT)
3414 child_allocation.x += xthickness;
3415 child_allocation.width = MAX (1, (((gint) page->allocation.width) - xthickness -
3416 2 * (notebook->tab_hborder + focus_width)));
3420 if (page->tab_label)
3421 gtk_widget_size_allocate (page->tab_label, &child_allocation);
3425 gtk_notebook_calc_tabs (GtkNotebook *notebook,
3431 GtkNotebookPage *page = NULL;
3433 GList *last_list = NULL;
3440 pack = GTK_NOTEBOOK_PAGE (start)->pack;
3441 if (pack == GTK_PACK_END)
3442 direction = (direction == STEP_PREV) ? STEP_NEXT : STEP_PREV;
3446 switch (notebook->tab_pos)
3449 case GTK_POS_BOTTOM:
3452 page = children->data;
3453 if (GTK_WIDGET_VISIBLE (page->child))
3455 if (page->pack == pack)
3457 *tab_space -= page->requisition.width;
3458 if (*tab_space < 0 || children == *end)
3462 *tab_space = - (*tab_space +
3463 page->requisition.width);
3469 last_list = children;
3471 if (direction == STEP_NEXT)
3472 children = children->next;
3474 children = children->prev;
3481 page = children->data;
3482 if (GTK_WIDGET_VISIBLE (page->child))
3484 if (page->pack == pack)
3486 *tab_space -= page->requisition.height;
3487 if (*tab_space < 0 || children == *end)
3491 *tab_space = - (*tab_space +
3492 page->requisition.height);
3498 last_list = children;
3500 if (direction == STEP_NEXT)
3501 children = children->next;
3503 children = children->prev;
3507 if (direction == STEP_PREV)
3509 pack = (pack == GTK_PACK_END) ? GTK_PACK_START : GTK_PACK_END;
3510 direction = STEP_PREV;
3511 children = last_list;
3515 /* Private GtkNotebook Page Switch Methods:
3517 * gtk_notebook_real_switch_page
3520 gtk_notebook_real_switch_page (GtkNotebook *notebook,
3521 GtkNotebookPage *page,
3524 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
3525 g_return_if_fail (page != NULL);
3527 if (notebook->cur_page == page || !GTK_WIDGET_VISIBLE (page->child))
3530 if (notebook->cur_page)
3531 gtk_widget_set_child_visible (notebook->cur_page->child, FALSE);
3533 notebook->cur_page = page;
3535 if (!notebook->focus_tab ||
3536 notebook->focus_tab->data != (gpointer) notebook->cur_page)
3537 notebook->focus_tab =
3538 g_list_find (notebook->children, notebook->cur_page);
3540 gtk_widget_set_child_visible (notebook->cur_page->child, TRUE);
3542 /* If the focus was on the previous page, move it to the first
3543 * element on the new page, if possible, or if not, to the
3546 if (notebook->child_has_focus)
3548 if (notebook->cur_page->last_focus_child &&
3549 gtk_widget_is_ancestor (notebook->cur_page->last_focus_child, notebook->cur_page->child))
3550 gtk_widget_grab_focus (notebook->cur_page->last_focus_child);
3552 if (!gtk_widget_child_focus (notebook->cur_page->child, GTK_DIR_TAB_FORWARD))
3553 gtk_widget_grab_focus (GTK_WIDGET (notebook));
3556 gtk_widget_queue_resize (GTK_WIDGET (notebook));
3557 g_object_notify (G_OBJECT (notebook), "page");
3560 /* Private GtkNotebook Page Switch Functions:
3562 * gtk_notebook_switch_page
3563 * gtk_notebook_page_select
3564 * gtk_notebook_switch_focus_tab
3565 * gtk_notebook_menu_switch_page
3568 gtk_notebook_switch_page (GtkNotebook *notebook,
3569 GtkNotebookPage *page,
3572 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
3573 g_return_if_fail (page != NULL);
3575 if (notebook->cur_page == page)
3579 page_num = g_list_index (notebook->children, page);
3581 gtk_signal_emit (GTK_OBJECT (notebook),
3582 notebook_signals[SWITCH_PAGE],
3588 gtk_notebook_page_select (GtkNotebook *notebook,
3589 gboolean move_focus)
3591 GtkNotebookPage *page;
3592 GtkDirectionType dir = GTK_DIR_DOWN; /* Quiet GCC */
3594 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
3596 if (!notebook->focus_tab)
3599 page = notebook->focus_tab->data;
3600 gtk_notebook_switch_page (notebook, page, -1);
3604 switch (notebook->tab_pos)
3609 case GTK_POS_BOTTOM:
3613 dir = GTK_DIR_RIGHT;
3620 if (gtk_widget_child_focus (page->child, dir))
3627 gtk_notebook_switch_focus_tab (GtkNotebook *notebook,
3631 GtkNotebookPage *old_page = NULL;
3632 GtkNotebookPage *page;
3634 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
3636 if (notebook->focus_tab == new_child)
3639 old_child = notebook->focus_tab;
3640 notebook->focus_tab = new_child;
3642 if (notebook->scrollable)
3643 gtk_notebook_redraw_arrows (notebook);
3645 if (!notebook->show_tabs || !notebook->focus_tab)
3649 old_page = old_child->data;
3651 page = notebook->focus_tab->data;
3652 if (GTK_WIDGET_MAPPED (page->tab_label))
3653 gtk_notebook_focus_changed (notebook, old_page);
3655 gtk_notebook_pages_allocate (notebook);
3659 gtk_notebook_menu_switch_page (GtkWidget *widget,
3660 GtkNotebookPage *page)
3662 GtkNotebook *notebook;
3666 g_return_if_fail (widget != NULL);
3667 g_return_if_fail (page != NULL);
3669 notebook = GTK_NOTEBOOK (gtk_menu_get_attach_widget
3670 (GTK_MENU (widget->parent)));
3672 if (notebook->cur_page == page)
3676 children = notebook->children;
3677 while (children && children->data != page)
3679 children = children->next;
3683 gtk_signal_emit (GTK_OBJECT (notebook),
3684 notebook_signals[SWITCH_PAGE],
3689 /* Private GtkNotebook Menu Functions:
3691 * gtk_notebook_menu_item_create
3692 * gtk_notebook_menu_label_unparent
3693 * gtk_notebook_menu_detacher
3696 gtk_notebook_menu_item_create (GtkNotebook *notebook,
3699 GtkNotebookPage *page;
3700 GtkWidget *menu_item;
3703 if (page->default_menu)
3705 if (page->tab_label && GTK_IS_LABEL (page->tab_label))
3706 page->menu_label = gtk_label_new (GTK_LABEL (page->tab_label)->label);
3708 page->menu_label = gtk_label_new ("");
3709 gtk_misc_set_alignment (GTK_MISC (page->menu_label), 0.0, 0.5);
3712 gtk_widget_show (page->menu_label);
3713 menu_item = gtk_menu_item_new ();
3714 gtk_container_add (GTK_CONTAINER (menu_item), page->menu_label);
3715 gtk_menu_shell_insert (GTK_MENU_SHELL (notebook->menu), menu_item,
3716 gtk_notebook_real_page_position (notebook, list));
3717 gtk_signal_connect (GTK_OBJECT (menu_item), "activate",
3718 GTK_SIGNAL_FUNC (gtk_notebook_menu_switch_page), page);
3719 if (GTK_WIDGET_VISIBLE (page->child))
3720 gtk_widget_show (menu_item);
3724 gtk_notebook_menu_label_unparent (GtkWidget *widget,
3727 gtk_widget_unparent (GTK_BIN(widget)->child);
3728 GTK_BIN(widget)->child = NULL;
3732 gtk_notebook_menu_detacher (GtkWidget *widget,
3735 GtkNotebook *notebook;
3737 g_return_if_fail (GTK_IS_NOTEBOOK (widget));
3739 notebook = GTK_NOTEBOOK (widget);
3740 g_return_if_fail (notebook->menu == (GtkWidget*) menu);
3742 notebook->menu = NULL;
3745 /* Public GtkNotebook Page Insert/Remove Methods :
3747 * gtk_notebook_append_page
3748 * gtk_notebook_append_page_menu
3749 * gtk_notebook_prepend_page
3750 * gtk_notebook_prepend_page_menu
3751 * gtk_notebook_insert_page
3752 * gtk_notebook_insert_page_menu
3753 * gtk_notebook_remove_page
3756 * gtk_notebook_append_page:
3757 * @notebook: a #GtkNotebook
3758 * @child: the #GtkWidget to use as the contents of the page.
3759 * @tab_label: the #GtkWidget to be used as the label for the page,
3760 * or %NULL to use the default label, 'page N'.
3762 * Appends a page to @notebook.
3765 gtk_notebook_append_page (GtkNotebook *notebook,
3767 GtkWidget *tab_label)
3769 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
3770 g_return_if_fail (GTK_IS_WIDGET (child));
3771 g_return_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label));
3773 gtk_notebook_insert_page_menu (notebook, child, tab_label, NULL, -1);
3777 * gtk_notebook_append_page_menu:
3778 * @notebook: a #GtkNotebook
3779 * @child: the #GtkWidget to use as the contents of the page.
3780 * @tab_label: the #GtkWidget to be used as the label for the page,
3781 * or %NULL to use the default label, 'page N'.
3782 * @menu_label: the widget to use as a label for the page-switch
3783 * menu, if that is enabled. If %NULL, and @tab_label
3784 * is a #GtkLabel or %NULL, then the menu label will be
3785 * a newly created label with the same text as @tab_label;
3786 * If @tab_label is not a #GtkLabel, @menu_label must be
3787 * specified if the page-switch menu is to be used.
3789 * Appends a page to @notebook, specifying the widget to use as the
3790 * label in the popup menu.
3793 gtk_notebook_append_page_menu (GtkNotebook *notebook,
3795 GtkWidget *tab_label,
3796 GtkWidget *menu_label)
3798 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
3799 g_return_if_fail (GTK_IS_WIDGET (child));
3800 g_return_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label));
3801 g_return_if_fail (menu_label == NULL || GTK_IS_WIDGET (menu_label));
3803 gtk_notebook_insert_page_menu (notebook, child, tab_label, menu_label, -1);
3807 * gtk_notebook_prepend_page:
3808 * @notebook: a #GtkNotebook
3809 * @child: the #GtkWidget to use as the contents of the page.
3810 * @tab_label: the #GtkWidget to be used as the label for the page,
3811 * or %NULL to use the default label, 'page N'.
3813 * Prepends a page to @notebook.
3816 gtk_notebook_prepend_page (GtkNotebook *notebook,
3818 GtkWidget *tab_label)
3820 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
3821 g_return_if_fail (GTK_IS_WIDGET (child));
3822 g_return_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label));
3824 gtk_notebook_insert_page_menu (notebook, child, tab_label, NULL, 0);
3828 * gtk_notebook_prepend_page_menu:
3829 * @notebook: a #GtkNotebook
3830 * @child: the #GtkWidget to use as the contents of the page.
3831 * @tab_label: the #GtkWidget to be used as the label for the page,
3832 * or %NULL to use the default label, 'page N'.
3833 * @menu_label: the widget to use as a label for the page-switch
3834 * menu, if that is enabled. If %NULL, and @tab_label
3835 * is a #GtkLabel or %NULL, then the menu label will be
3836 * a newly created label with the same text as @tab_label;
3837 * If @tab_label is not a #GtkLabel, @menu_label must be
3838 * specified if the page-switch menu is to be used.
3840 * Prepends a page to @notebook, specifying the widget to use as the
3841 * label in the popup menu.
3844 gtk_notebook_prepend_page_menu (GtkNotebook *notebook,
3846 GtkWidget *tab_label,
3847 GtkWidget *menu_label)
3849 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
3850 g_return_if_fail (GTK_IS_WIDGET (child));
3851 g_return_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label));
3852 g_return_if_fail (menu_label == NULL || GTK_IS_WIDGET (menu_label));
3854 gtk_notebook_insert_page_menu (notebook, child, tab_label, menu_label, 0);
3858 * gtk_notebook_insert_page:
3859 * @notebook: a #GtkNotebook
3860 * @child: the #GtkWidget to use as the contents of the page.
3861 * @tab_label: the #GtkWidget to be used as the label for the page,
3862 * or %NULL to use the default label, 'page N'.
3863 * @position: the index (starting at 0) at which to insert the page,
3864 * or -1 to append the page after all other pages.
3866 * Insert a page into @notebook at the given position
3869 gtk_notebook_insert_page (GtkNotebook *notebook,
3871 GtkWidget *tab_label,
3874 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
3875 g_return_if_fail (GTK_IS_WIDGET (child));
3876 g_return_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label));
3878 gtk_notebook_insert_page_menu (notebook, child, tab_label, NULL, position);
3883 gtk_notebook_page_compare_tab (gconstpointer a,
3886 return (((GtkNotebookPage *) a)->tab_label != b);
3890 gtk_notebook_mnemonic_activate_switch_page (GtkWidget *child,
3894 GtkNotebook *notebook = GTK_NOTEBOOK (data);
3897 list = g_list_find_custom (notebook->children, child,
3898 gtk_notebook_page_compare_tab);
3901 GtkNotebookPage *page = list->data;
3903 gtk_widget_grab_focus (GTK_WIDGET (notebook)); /* Do this first to avoid focusing new page */
3904 gtk_notebook_switch_page (notebook, page, -1);
3905 focus_tabs_in (notebook);
3912 * gtk_notebook_insert_page_menu:
3913 * @notebook: a #GtkNotebook
3914 * @child: the #GtkWidget to use as the contents of the page.
3915 * @tab_label: the #GtkWidget to be used as the label for the page,
3916 * or %NULL to use the default label, 'page N'.
3917 * @menu_label: the widget to use as a label for the page-switch
3918 * menu, if that is enabled. If %NULL, and @tab_label
3919 * is a #GtkLabel or %NULL, then the menu label will be
3920 * a newly created label with the same text as @tab_label;
3921 * If @tab_label is not a #GtkLabel, @menu_label must be
3922 * specified if the page-switch menu is to be used.
3923 * @position: the index (starting at 0) at which to insert the page,
3924 * or -1 to append the page after all other pages.
3926 * Insert a page into @notebook at the given position, specifying
3927 * the widget to use as the label in the popup menu.
3930 gtk_notebook_insert_page_menu (GtkNotebook *notebook,
3932 GtkWidget *tab_label,
3933 GtkWidget *menu_label,
3936 GtkNotebookPage *page;
3939 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
3940 g_return_if_fail (GTK_IS_WIDGET (child));
3941 g_return_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label));
3942 g_return_if_fail (menu_label == NULL || GTK_IS_WIDGET (menu_label));
3944 gtk_widget_freeze_child_notify (child);
3946 page = g_new (GtkNotebookPage, 1);
3947 page->child = child;
3948 page->last_focus_child = NULL;
3949 page->requisition.width = 0;
3950 page->requisition.height = 0;
3951 page->allocation.x = 0;
3952 page->allocation.y = 0;
3953 page->allocation.width = 0;
3954 page->allocation.height = 0;
3955 page->default_menu = FALSE;
3956 page->default_tab = FALSE;
3957 page->mnemonic_activate_signal = 0;
3959 nchildren = g_list_length (notebook->children);
3960 if ((position < 0) || (position > nchildren))
3961 position = nchildren;
3963 notebook->children = g_list_insert (notebook->children, page, position);
3967 page->default_tab = TRUE;
3968 if (notebook->show_tabs)
3969 tab_label = gtk_label_new ("");
3971 page->tab_label = tab_label;
3972 page->menu_label = menu_label;
3973 page->expand = FALSE;
3975 page->pack = GTK_PACK_START;
3978 page->default_menu = TRUE;
3981 gtk_widget_ref (page->menu_label);
3982 gtk_object_sink (GTK_OBJECT (page->menu_label));
3986 gtk_notebook_menu_item_create (notebook,
3987 g_list_find (notebook->children, page));
3989 gtk_widget_set_parent (child, GTK_WIDGET (notebook));
3991 gtk_widget_set_parent (tab_label, GTK_WIDGET (notebook));
3993 gtk_notebook_update_labels (notebook);
3995 if (!notebook->first_tab)
3996 notebook->first_tab = notebook->children;
3998 if (!notebook->cur_page)
3999 gtk_widget_set_child_visible (child, TRUE);
4001 gtk_widget_set_child_visible (child, FALSE);
4005 if (notebook->show_tabs && GTK_WIDGET_VISIBLE (child))
4006 gtk_widget_show (tab_label);
4008 gtk_widget_hide (tab_label);
4011 if (!notebook->cur_page)
4013 gtk_notebook_switch_page (notebook, page, 0);
4014 gtk_notebook_switch_focus_tab (notebook, NULL);
4018 page->mnemonic_activate_signal =
4019 gtk_signal_connect (GTK_OBJECT (tab_label),
4020 "mnemonic_activate",
4021 (GtkSignalFunc) gtk_notebook_mnemonic_activate_switch_page,
4024 if (notebook->show_tabs && GTK_WIDGET_MAPPED (notebook))
4025 gdk_window_show_unraised (notebook->event_window);
4027 gtk_widget_child_notify (child, "tab_expand");
4028 gtk_widget_child_notify (child, "tab_fill");
4029 gtk_widget_child_notify (child, "tab_pack");
4030 gtk_widget_child_notify (child, "tab_label");
4031 gtk_widget_child_notify (child, "menu_label");
4032 gtk_widget_child_notify (child, "position");
4033 gtk_widget_thaw_child_notify (child);
4037 * gtk_notebook_remove_page:
4038 * @notebook: a #GtkNotebook.
4039 * @page_num: the index of a notebook page, starting
4040 * from 0. If -1, the last page will
4043 * Removes a page from the notebook given its index
4047 gtk_notebook_remove_page (GtkNotebook *notebook,
4052 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4056 list = g_list_nth (notebook->children, page_num);
4058 gtk_notebook_real_remove (notebook, list);
4062 list = g_list_last (notebook->children);
4064 gtk_notebook_real_remove (notebook, list);
4068 /* Public GtkNotebook Page Switch Methods :
4069 * gtk_notebook_get_current_page
4070 * gtk_notebook_page_num
4071 * gtk_notebook_set_current_page
4072 * gtk_notebook_next_page
4073 * gtk_notebook_prev_page
4076 * gtk_notebook_get_current_page:
4077 * @notebook: a #GtkNotebook
4079 * Returns the page number of the current page.
4081 * Return value: the index (starting from 0) of the current
4082 * page in the notebook. If the notebook has no pages, then
4083 * -1 will be returned.
4086 gtk_notebook_get_current_page (GtkNotebook *notebook)
4088 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
4090 if (!notebook->cur_page)
4093 return g_list_index (notebook->children, notebook->cur_page);
4097 * gtk_notebook_get_nth_page:
4098 * @notebook: a #GtkNotebook
4099 * @page_num: the index of a page in the noteobok
4101 * Returns the child widget contained in page number @page_num.
4103 * Return value: the child widget, or %NULL if @page_num is
4107 gtk_notebook_get_nth_page (GtkNotebook *notebook,
4110 GtkNotebookPage *page;
4112 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
4114 page = g_list_nth_data (notebook->children, page_num);
4123 * gtk_notebook_page_num:
4124 * @notebook: a #GtkNotebook
4125 * @child: a #GtkWidget
4127 * Finds the index of the page which contains the given child
4130 * Return value: the index of the page containing @child, or
4131 * -1 if @child is not in the notebook.
4134 gtk_notebook_page_num (GtkNotebook *notebook,
4140 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
4143 children = notebook->children;
4146 GtkNotebookPage *page = children->data;
4148 if (page->child == child)
4151 children = children->next;
4159 * gtk_notebook_set_current_page:
4160 * @notebook: a #GtkNotebook
4161 * @page_num: index of the page to switch to, starting from 0.
4162 * If negative, or greater than the number of pages
4163 * in the notebook the last page will be used.
4165 * Switches to the page number @page_num.
4168 gtk_notebook_set_current_page (GtkNotebook *notebook,
4173 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4176 list = g_list_nth (notebook->children, page_num);
4178 list = g_list_last (notebook->children);
4180 page_num = g_list_index (notebook->children, list);
4183 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (list), page_num);
4187 * gtk_notebook_next_page:
4188 * @notebook: a #GtkNotebook
4190 * Switches to the next page. Nothing happens if the current page is
4194 gtk_notebook_next_page (GtkNotebook *notebook)
4198 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4200 list = g_list_find (notebook->children, notebook->cur_page);
4204 list = gtk_notebook_search_page (notebook, list, STEP_NEXT, TRUE);
4208 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (list), -1);
4212 * gtk_notebook_prev_page:
4213 * @notebook: a #GtkNotebook
4215 * Switches to the previous page. Nothing happens if the current page
4216 * is the first page.
4219 gtk_notebook_prev_page (GtkNotebook *notebook)
4223 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4225 list = g_list_find (notebook->children, notebook->cur_page);
4229 list = gtk_notebook_search_page (notebook, list, STEP_PREV, TRUE);
4233 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (list), -1);
4236 /* Public GtkNotebook/Tab Style Functions
4238 * gtk_notebook_set_show_border
4239 * gtk_notebook_set_show_tabs
4240 * gtk_notebook_set_tab_pos
4241 * gtk_notebook_set_homogeneous_tabs
4242 * gtk_notebook_set_tab_border
4243 * gtk_notebook_set_tab_hborder
4244 * gtk_notebook_set_tab_vborder
4245 * gtk_notebook_set_scrollable
4248 * gtk_notebook_set_show_border:
4249 * @notebook: a #GtkNotebook
4250 * @show_border: %TRUE if a bevel should be drawn around the notebook.
4252 * Sets whether a bevel will be drawn around the notebook pages.
4253 * This is only has an effect when the tabs are not shown.
4254 * See gtk_notebook_set_show_tabs().
4257 gtk_notebook_set_show_border (GtkNotebook *notebook,
4258 gboolean show_border)
4260 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4262 if (notebook->show_border != show_border)
4264 notebook->show_border = show_border;
4266 if (GTK_WIDGET_VISIBLE (notebook))
4267 gtk_widget_queue_resize (GTK_WIDGET (notebook));
4269 g_object_notify (G_OBJECT (notebook), "show_border");
4274 * gtk_notebook_get_show_border:
4275 * @notebook: a #GtkNotebook
4277 * Returns whether a bevel will be drawn around the notebook pages. See
4278 * gtk_notebook_set_show_border().
4280 * Return value: %TRUE if the bevel is drawn
4283 gtk_notebook_get_show_border (GtkNotebook *notebook)
4285 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
4287 return notebook->show_border;
4291 * gtk_notebook_set_show_tabs:
4292 * @notebook: a #GtkNotebook
4293 * @show_tabs: %TRUE if the tabs should be shown.
4295 * Sets whether to show the tabs for the notebook or not.
4298 gtk_notebook_set_show_tabs (GtkNotebook *notebook,
4301 GtkNotebookPage *page;
4304 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4306 show_tabs = show_tabs != FALSE;
4308 if (notebook->show_tabs == show_tabs)
4311 notebook->show_tabs = show_tabs;
4312 children = notebook->children;
4316 GTK_WIDGET_UNSET_FLAGS (notebook, GTK_CAN_FOCUS);
4320 page = children->data;
4321 children = children->next;
4322 if (page->default_tab)
4324 gtk_widget_destroy (page->tab_label);
4325 page->tab_label = NULL;
4328 gtk_widget_hide (page->tab_label);
4333 GTK_WIDGET_SET_FLAGS (notebook, GTK_CAN_FOCUS);
4334 gtk_notebook_update_labels (notebook);
4336 gtk_widget_queue_resize (GTK_WIDGET (notebook));
4338 g_object_notify (G_OBJECT (notebook), "show_tabs");
4342 * gtk_notebook_get_show_tabs:
4343 * @notebook: a #GtkNotebook
4345 * Returns whether the tabs of the notebook are shown. See
4346 * gtk_notebook_set_show_tabs().
4348 * Return value: %TRUE if the tabs are shown
4351 gtk_notebook_get_show_tabs (GtkNotebook *notebook)
4353 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
4355 return notebook->show_tabs;
4359 * gtk_notebook_set_tab_pos:
4360 * @notebook: a #GtkNotebook.
4361 * @pos: the edge to draw the tabs at.
4363 * Sets the edge at which the tabs for switching pages in the
4364 * notebook are drawn.
4367 gtk_notebook_set_tab_pos (GtkNotebook *notebook,
4368 GtkPositionType pos)
4370 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4372 if (notebook->tab_pos != pos)
4374 notebook->tab_pos = pos;
4375 if (GTK_WIDGET_VISIBLE (notebook))
4376 gtk_widget_queue_resize (GTK_WIDGET (notebook));
4379 g_object_notify (G_OBJECT (notebook), "tab_pos");
4383 * gtk_notebook_get_tab_pos:
4384 * @notebook: a #GtkNotebook
4386 * Gets the edge at which the tabs for switching pages in the
4387 * notebook are drawn.
4389 * Return value: the edge at which the tabs are drawn
4392 gtk_notebook_get_tab_pos (GtkNotebook *notebook)
4394 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), GTK_POS_TOP);
4396 return notebook->tab_pos;
4400 * gtk_notebook_set_homogeneous_tabs:
4401 * @notebook: a #GtkNotebook
4402 * @homogeneous: %TRUE if all tabs should be the same size.
4404 * Sets whether the tabs must have all the same size or not.
4407 gtk_notebook_set_homogeneous_tabs (GtkNotebook *notebook,
4408 gboolean homogeneous)
4410 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4412 if (homogeneous == notebook->homogeneous)
4415 notebook->homogeneous = homogeneous;
4416 gtk_widget_queue_resize (GTK_WIDGET (notebook));
4418 g_object_notify (G_OBJECT (notebook), "homogeneous");
4422 * gtk_notebook_set_tab_border:
4423 * @notebook: a #GtkNotebook
4424 * @border_width: width of the border around the tab labels.
4426 * Sets the width the border around the tab labels
4427 * in a notebook. This is equivalent to calling
4428 * gtk_notebook_set_tab_hborder (@notebook, @border_width) followed
4429 * by gtk_notebook_set_tab_vborder (@notebook, @border_width).
4432 gtk_notebook_set_tab_border (GtkNotebook *notebook,
4435 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4437 notebook->tab_hborder = border_width;
4438 notebook->tab_vborder = border_width;
4440 if (GTK_WIDGET_VISIBLE (notebook) && notebook->show_tabs)
4441 gtk_widget_queue_resize (GTK_WIDGET (notebook));
4443 g_object_freeze_notify (G_OBJECT (notebook));
4444 g_object_notify (G_OBJECT (notebook), "tab_hborder");
4445 g_object_notify (G_OBJECT (notebook), "tab_vborder");
4446 g_object_thaw_notify (G_OBJECT (notebook));
4451 * gtk_notebook_set_tab_hborder:
4452 * @notebook: a #GtkNotebook
4453 * @tab_hborder: width of the horizontal border of tab labels.
4455 * Sets the width of the horizontal border of tab labels.
4458 gtk_notebook_set_tab_hborder (GtkNotebook *notebook,
4461 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4463 if (notebook->tab_hborder == tab_hborder)
4466 notebook->tab_hborder = tab_hborder;
4468 if (GTK_WIDGET_VISIBLE (notebook) && notebook->show_tabs)
4469 gtk_widget_queue_resize (GTK_WIDGET (notebook));
4471 g_object_notify (G_OBJECT (notebook), "tab_hborder");
4475 * gtk_notebook_set_tab_vborder:
4476 * @notebook: a #GtkNotebook
4477 * @tab_vborder: width of the vertical border of tab labels.
4479 * Sets the width of the vertical border of tab labels.
4482 gtk_notebook_set_tab_vborder (GtkNotebook *notebook,
4485 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4487 if (notebook->tab_vborder == tab_vborder)
4490 notebook->tab_vborder = tab_vborder;
4492 if (GTK_WIDGET_VISIBLE (notebook) && notebook->show_tabs)
4493 gtk_widget_queue_resize (GTK_WIDGET (notebook));
4495 g_object_notify (G_OBJECT (notebook), "tab_vborder");
4499 * gtk_notebook_set_scrollable:
4500 * @notebook: a #GtkNotebook
4501 * @scrollable: %TRUE if scroll arrows should be added
4503 * Sets whether the tab label area will have arrows for scrolling if
4504 * there are too many tabs to fit in the area.
4507 gtk_notebook_set_scrollable (GtkNotebook *notebook,
4508 gboolean scrollable)
4510 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4512 scrollable = (scrollable != FALSE);
4514 if (scrollable != notebook->scrollable)
4516 notebook->scrollable = scrollable;
4518 if (GTK_WIDGET_VISIBLE (notebook))
4519 gtk_widget_queue_resize (GTK_WIDGET (notebook));
4521 g_object_notify (G_OBJECT (notebook), "scrollable");
4526 * gtk_notebook_get_scrollable:
4527 * @notebook: a #GtkNotebook
4529 * Returns whether the tab label area has arrows for scrolling. See
4530 * gtk_notebook_set_scrollable().
4532 * Return value: %TRUE if arrows for scrolling are present
4535 gtk_notebook_get_scrollable (GtkNotebook *notebook)
4537 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
4539 return notebook->scrollable;
4542 /* Public GtkNotebook Popup Menu Methods:
4544 * gtk_notebook_popup_enable
4545 * gtk_notebook_popup_disable
4550 * gtk_notebook_popup_enable:
4551 * @notebook: a #GtkNotebook
4553 * Enables the popup menu: if the user clicks with the right mouse button on
4554 * the bookmarks, a menu with all the pages will be popped up.
4557 gtk_notebook_popup_enable (GtkNotebook *notebook)
4561 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4566 notebook->menu = gtk_menu_new ();
4567 for (list = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, FALSE);
4569 list = gtk_notebook_search_page (notebook, list, STEP_NEXT, FALSE))
4570 gtk_notebook_menu_item_create (notebook, list);
4572 gtk_notebook_update_labels (notebook);
4573 gtk_menu_attach_to_widget (GTK_MENU (notebook->menu),
4574 GTK_WIDGET (notebook),
4575 gtk_notebook_menu_detacher);
4577 g_object_notify (G_OBJECT (notebook), "enable_popup");
4581 * gtk_notebook_popup_disable:
4582 * @notebook: a #GtkNotebook
4584 * Disables the popup menu.
4587 gtk_notebook_popup_disable (GtkNotebook *notebook)
4589 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4591 if (!notebook->menu)
4594 gtk_container_foreach (GTK_CONTAINER (notebook->menu),
4595 (GtkCallback) gtk_notebook_menu_label_unparent, NULL);
4596 gtk_widget_destroy (notebook->menu);
4598 g_object_notify (G_OBJECT (notebook), "enable_popup");
4601 /* Public GtkNotebook Page Properties Functions:
4603 * gtk_notebook_get_tab_label
4604 * gtk_notebook_set_tab_label
4605 * gtk_notebook_set_tab_label_text
4606 * gtk_notebook_get_menu_label
4607 * gtk_notebook_set_menu_label
4608 * gtk_notebook_set_menu_label_text
4609 * gtk_notebook_set_tab_label_packing
4610 * gtk_notebook_query_tab_label_packing
4614 * gtk_notebook_get_tab_label:
4615 * @notebook: a #GtkNotebook
4618 * Returns the tab label widget for the page @child. %NULL is returned
4619 * if @child is not in @notebook or if no tab label has specifically
4620 * been set for @child.
4622 * Return value: the tab label
4625 gtk_notebook_get_tab_label (GtkNotebook *notebook,
4630 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
4631 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
4633 list = CHECK_FIND_CHILD (notebook, child);
4637 if (GTK_NOTEBOOK_PAGE (list)->default_tab)
4640 return GTK_NOTEBOOK_PAGE (list)->tab_label;
4644 * gtk_notebook_set_tab_label:
4645 * @notebook: a #GtkNotebook
4647 * @tab_label: the tab label widget to use, or %NULL for default tab
4650 * Changes the tab label for @child. If %NULL is specified
4651 * for @tab_label, then the page will have the label 'page N'.
4654 gtk_notebook_set_tab_label (GtkNotebook *notebook,
4656 GtkWidget *tab_label)
4658 GtkNotebookPage *page;
4661 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4662 g_return_if_fail (GTK_IS_WIDGET (child));
4664 list = CHECK_FIND_CHILD (notebook, child);
4668 /* a NULL pointer indicates a default_tab setting, otherwise
4669 * we need to set the associated label
4673 if (page->tab_label == tab_label)
4677 gtk_notebook_remove_tab_label (notebook, page);
4681 page->default_tab = FALSE;
4682 page->tab_label = tab_label;
4683 gtk_widget_set_parent (page->tab_label, GTK_WIDGET (notebook));
4687 page->default_tab = TRUE;
4688 page->tab_label = NULL;
4690 if (notebook->show_tabs)
4694 g_snprintf (string, sizeof(string), _("Page %u"),
4695 gtk_notebook_real_page_position (notebook, list));
4696 page->tab_label = gtk_label_new (string);
4697 gtk_widget_set_parent (page->tab_label, GTK_WIDGET (notebook));
4701 if (page->tab_label)
4702 page->mnemonic_activate_signal =
4703 gtk_signal_connect (GTK_OBJECT (page->tab_label),
4704 "mnemonic_activate",
4705 (GtkSignalFunc) gtk_notebook_mnemonic_activate_switch_page,
4708 if (notebook->show_tabs && GTK_WIDGET_VISIBLE (child))
4710 gtk_widget_show (page->tab_label);
4711 gtk_widget_queue_resize (GTK_WIDGET (notebook));
4713 gtk_widget_child_notify (child, "tab_label");
4717 * gtk_notebook_set_tab_label_text:
4718 * @notebook: a #GtkNotebook
4720 * @tab_text: the label text
4722 * Creates a new label and sets it as the tab label for the page
4723 * containing @child.
4726 gtk_notebook_set_tab_label_text (GtkNotebook *notebook,
4728 const gchar *tab_text)
4730 GtkWidget *tab_label = NULL;
4732 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4735 tab_label = gtk_label_new (tab_text);
4736 gtk_notebook_set_tab_label (notebook, child, tab_label);
4737 gtk_widget_child_notify (child, "tab_label");
4741 * gtk_notebook_get_tab_label_text:
4742 * @notebook: a #GtkNotebook
4743 * @child: a widget contained in a page of @notebook
4745 * Retrieves the text of the tab label for the page containing
4748 * Returns value: the text of the tab label, or %NULL if the
4749 * tab label widget is not a #GtkLabel. The
4750 * string is owned by the widget and must not
4753 G_CONST_RETURN gchar *
4754 gtk_notebook_get_tab_label_text (GtkNotebook *notebook,
4757 GtkWidget *tab_label;
4759 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
4760 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
4762 tab_label = gtk_notebook_get_tab_label (notebook, child);
4764 if (tab_label && GTK_IS_LABEL (tab_label))
4765 return gtk_label_get_text (GTK_LABEL (tab_label));
4771 * gtk_notebook_get_menu_label:
4772 * @notebook: a #GtkNotebook
4773 * @child: a widget contained in a page of @notebook
4775 * Retrieves the menu label widget of the page containing @child.
4777 * Return value: the menu label, or %NULL if the
4778 * notebook page does not have a menu label other
4779 * than the default (the tab label).
4782 gtk_notebook_get_menu_label (GtkNotebook *notebook,
4787 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
4788 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
4790 list = CHECK_FIND_CHILD (notebook, child);
4794 if (GTK_NOTEBOOK_PAGE (list)->default_menu)
4797 return GTK_NOTEBOOK_PAGE (list)->menu_label;
4801 * gtk_notebook_set_menu_label:
4802 * @notebook: a #GtkNotebook
4803 * @child: the child widget
4804 * @menu_label: the menu label, or NULL for default
4806 * Changes the menu label for the page containing @child.
4809 gtk_notebook_set_menu_label (GtkNotebook *notebook,
4811 GtkWidget *menu_label)
4813 GtkNotebookPage *page;
4816 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4817 g_return_if_fail (GTK_IS_WIDGET (child));
4819 list = CHECK_FIND_CHILD (notebook, child);
4824 if (page->menu_label)
4827 gtk_container_remove (GTK_CONTAINER (notebook->menu),
4828 page->menu_label->parent);
4830 if (!page->default_menu)
4831 gtk_widget_unref (page->menu_label);
4836 page->menu_label = menu_label;
4837 gtk_widget_ref (page->menu_label);
4838 gtk_object_sink (GTK_OBJECT(page->menu_label));
4839 page->default_menu = FALSE;
4842 page->default_menu = TRUE;
4845 gtk_notebook_menu_item_create (notebook, list);
4846 gtk_widget_child_notify (child, "menu_label");
4850 * gtk_notebook_set_menu_label_text:
4851 * @notebook: a #GtkNotebook
4852 * @child: the child widget
4853 * @menu_text: the label text
4855 * Creates a new label and sets it as the menu label of @child.
4858 gtk_notebook_set_menu_label_text (GtkNotebook *notebook,
4860 const gchar *menu_text)
4862 GtkWidget *menu_label = NULL;
4864 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4867 menu_label = gtk_label_new (menu_text);
4868 gtk_notebook_set_menu_label (notebook, child, menu_label);
4869 gtk_widget_child_notify (child, "menu_label");
4873 * gtk_notebook_get_menu_label_text:
4874 * @notebook: a #GtkNotebook
4875 * @child: the child widget of a page of the notebook.
4877 * Retrieves the text of the menu label for the page containing
4880 * Returns value: the text of the tab label, or %NULL if the
4881 * widget does not have a menu label other than
4882 * the default menu label, or the menu label widget
4883 * is not a #GtkLabel. The string is owned by
4884 * the widget and must not be freed.
4886 G_CONST_RETURN gchar *
4887 gtk_notebook_get_menu_label_text (GtkNotebook *notebook,
4890 GtkWidget *menu_label;
4892 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
4893 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
4895 menu_label = gtk_notebook_get_menu_label (notebook, child);
4897 if (menu_label && GTK_IS_LABEL (menu_label))
4898 return gtk_label_get_text (GTK_LABEL (menu_label));
4903 /* Helper function called when pages are reordered
4906 gtk_notebook_child_reordered (GtkNotebook *notebook,
4907 GtkNotebookPage *page)
4911 GtkWidget *menu_item;
4913 menu_item = page->menu_label->parent;
4914 gtk_container_remove (GTK_CONTAINER (menu_item), page->menu_label);
4915 gtk_container_remove (GTK_CONTAINER (notebook->menu), menu_item);
4916 gtk_notebook_menu_item_create (notebook, g_list_find (notebook->children, page));
4919 gtk_notebook_update_labels (notebook);
4923 * gtk_notebook_set_tab_label_packing:
4924 * @notebook: a #GtkNotebook
4925 * @child: the child widget
4926 * @expand: whether to expand the bookmark or not
4927 * @fill: whether the bookmark should fill the allocated area or not
4928 * @pack_type: the position of the bookmark
4930 * Sets the packing parameters for the tab label of the page
4931 * containing @child. See gtk_box_pack_start() for the exact meaning
4932 * of the parameters.
4935 gtk_notebook_set_tab_label_packing (GtkNotebook *notebook,
4939 GtkPackType pack_type)
4941 GtkNotebookPage *page;
4944 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4945 g_return_if_fail (GTK_IS_WIDGET (child));
4947 list = CHECK_FIND_CHILD (notebook, child);
4952 expand = expand != FALSE;
4953 fill = fill != FALSE;
4954 if (page->pack == pack_type && page->expand == expand && page->fill == fill)
4957 gtk_widget_freeze_child_notify (child);
4958 page->expand = expand;
4959 gtk_widget_child_notify (child, "tab_expand");
4961 gtk_widget_child_notify (child, "tab_fill");
4962 if (page->pack != pack_type)
4964 page->pack = pack_type;
4965 gtk_notebook_child_reordered (notebook, page);
4967 gtk_widget_child_notify (child, "tab_pack");
4968 gtk_widget_child_notify (child, "position");
4969 if (notebook->show_tabs)
4970 gtk_notebook_pages_allocate (notebook);
4971 gtk_widget_thaw_child_notify (child);
4975 * gtk_notebook_query_tab_label_packing:
4976 * @notebook: a #GtkNotebook
4978 * @expand: location to store the expand value (or NULL)
4979 * @fill: location to store the fill value (or NULL)
4980 * @pack_type: location to store the pack_type (or NULL)
4982 * Query the packing attributes for the tab label of the page
4983 * containing @child.
4986 gtk_notebook_query_tab_label_packing (GtkNotebook *notebook,
4990 GtkPackType *pack_type)
4994 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4995 g_return_if_fail (GTK_IS_WIDGET (child));
4997 list = CHECK_FIND_CHILD (notebook, child);
5002 *expand = GTK_NOTEBOOK_PAGE (list)->expand;
5004 *fill = GTK_NOTEBOOK_PAGE (list)->fill;
5006 *pack_type = GTK_NOTEBOOK_PAGE (list)->pack;
5010 * gtk_notebook_reorder_child:
5011 * @notebook: a #GtkNotebook
5012 * @child: the child to move
5013 * @position: the new position
5015 * Reorders the page containing @child, so that it appears in position
5016 * @position. Out of bounds @position will be clamped.
5019 gtk_notebook_reorder_child (GtkNotebook *notebook,
5023 GList *list, *new_list;
5024 GtkNotebookPage *page;
5027 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
5028 g_return_if_fail (GTK_IS_WIDGET (child));
5030 list = CHECK_FIND_CHILD (notebook, child);
5034 old_pos = g_list_position (notebook->children, list);
5036 if (old_pos == position)
5040 notebook->children = g_list_delete_link (notebook->children, list);
5042 position = CLAMP (position, 0, g_list_length (notebook->children));
5044 notebook->children = g_list_insert (notebook->children, page, position);
5045 new_list = g_list_nth (notebook->children, position);
5047 /* Fix up GList references in GtkNotebook structure */
5048 if (notebook->first_tab == list)
5049 notebook->first_tab = new_list;
5050 if (notebook->focus_tab == list)
5051 notebook->focus_tab = new_list;
5053 gtk_widget_freeze_child_notify (child);
5055 /* Move around the menu items if necesary */
5056 gtk_notebook_child_reordered (notebook, page);
5057 gtk_widget_child_notify (child, "tab_pack");
5058 gtk_widget_child_notify (child, "position");
5060 if (notebook->show_tabs)
5061 gtk_notebook_pages_allocate (notebook);
5063 gtk_widget_thaw_child_notify (child);