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"
30 #include "gtkmenuitem.h"
32 #include <gdk/gdkkeysyms.h>
35 #include "gtkmarshalers.h"
36 #include "gtkbindings.h"
40 #define TAB_CURVATURE 1
42 #define ARROW_SPACING 0
43 #define NOTEBOOK_INIT_SCROLL_DELAY (200)
44 #define NOTEBOOK_SCROLL_DELAY (100)
78 CHILD_PROP_MENU_LABEL,
80 CHILD_PROP_TAB_EXPAND,
85 #define GTK_NOTEBOOK_PAGE(_glist_) ((GtkNotebookPage *)((GList *)(_glist_))->data)
87 struct _GtkNotebookPage
91 GtkWidget *menu_label;
92 GtkWidget *last_focus_child; /* Last descendant of the page that had focus */
94 guint default_menu : 1; /* If true, we create the menu label ourself */
95 guint default_tab : 1; /* If true, we create the tab label ourself */
100 GtkRequisition requisition;
101 GtkAllocation allocation;
103 guint mnemonic_activate_signal;
106 #ifdef G_DISABLE_CHECKS
107 #define CHECK_FIND_CHILD(notebook, child) \
108 gtk_notebook_find_child (notebook, child, G_STRLOC)
110 #define CHECK_FIND_CHILD(notebook, child) \
111 gtk_notebook_find_child (notebook, child, NULL)
114 /*** GtkNotebook Methods ***/
115 static void gtk_notebook_class_init (GtkNotebookClass *klass);
116 static void gtk_notebook_init (GtkNotebook *notebook);
118 static gboolean gtk_notebook_select_page (GtkNotebook *notebook,
119 gboolean move_focus);
120 static gboolean gtk_notebook_focus_tab (GtkNotebook *notebook,
121 GtkNotebookTab type);
122 static void gtk_notebook_change_current_page (GtkNotebook *notebook,
124 static void gtk_notebook_move_focus_out (GtkNotebook *notebook,
125 GtkDirectionType direction_type);
127 /*** GtkObject Methods ***/
128 static void gtk_notebook_destroy (GtkObject *object);
129 static void gtk_notebook_set_property (GObject *object,
133 static void gtk_notebook_get_property (GObject *object,
138 /*** GtkWidget Methods ***/
139 static void gtk_notebook_map (GtkWidget *widget);
140 static void gtk_notebook_unmap (GtkWidget *widget);
141 static void gtk_notebook_realize (GtkWidget *widget);
142 static void gtk_notebook_unrealize (GtkWidget *widget);
143 static void gtk_notebook_size_request (GtkWidget *widget,
144 GtkRequisition *requisition);
145 static void gtk_notebook_size_allocate (GtkWidget *widget,
146 GtkAllocation *allocation);
147 static gint gtk_notebook_expose (GtkWidget *widget,
148 GdkEventExpose *event);
149 static gint gtk_notebook_button_press (GtkWidget *widget,
150 GdkEventButton *event);
151 static gint gtk_notebook_button_release (GtkWidget *widget,
152 GdkEventButton *event);
153 static gint gtk_notebook_enter_notify (GtkWidget *widget,
154 GdkEventCrossing *event);
155 static gint gtk_notebook_leave_notify (GtkWidget *widget,
156 GdkEventCrossing *event);
157 static gint gtk_notebook_motion_notify (GtkWidget *widget,
158 GdkEventMotion *event);
159 static gint gtk_notebook_focus_in (GtkWidget *widget,
160 GdkEventFocus *event);
161 static void gtk_notebook_draw_focus (GtkWidget *widget);
162 static gint gtk_notebook_focus (GtkWidget *widget,
163 GtkDirectionType direction);
165 /*** GtkContainer Methods ***/
166 static void gtk_notebook_set_child_property (GtkContainer *container,
171 static void gtk_notebook_get_child_property (GtkContainer *container,
176 static void gtk_notebook_add (GtkContainer *container,
178 static void gtk_notebook_remove (GtkContainer *container,
180 static void gtk_notebook_set_focus_child (GtkContainer *container,
182 static GType gtk_notebook_child_type (GtkContainer *container);
183 static void gtk_notebook_forall (GtkContainer *container,
184 gboolean include_internals,
185 GtkCallback callback,
186 gpointer callback_data);
188 /*** GtkNotebook Private Functions ***/
189 static void gtk_notebook_redraw_tabs (GtkNotebook *notebook);
190 static void gtk_notebook_redraw_arrows (GtkNotebook *notebook);
191 static void gtk_notebook_focus_changed (GtkNotebook *notebook,
192 GtkNotebookPage *old_page);
193 static void gtk_notebook_real_remove (GtkNotebook *notebook,
195 static void gtk_notebook_update_labels (GtkNotebook *notebook);
196 static gint gtk_notebook_timer (GtkNotebook *notebook);
197 static gint gtk_notebook_page_compare (gconstpointer a,
199 static GList* gtk_notebook_find_child (GtkNotebook *notebook,
201 const gchar *function);
202 static gint gtk_notebook_real_page_position (GtkNotebook *notebook,
204 static GList * gtk_notebook_search_page (GtkNotebook *notebook,
207 gboolean find_visible);
209 /*** GtkNotebook Drawing Functions ***/
210 static void gtk_notebook_paint (GtkWidget *widget,
212 static void gtk_notebook_draw_tab (GtkNotebook *notebook,
213 GtkNotebookPage *page,
215 static void gtk_notebook_draw_arrow (GtkNotebook *notebook,
218 /*** GtkNotebook Size Allocate Functions ***/
219 static void gtk_notebook_pages_allocate (GtkNotebook *notebook);
220 static void gtk_notebook_page_allocate (GtkNotebook *notebook,
221 GtkNotebookPage *page,
222 GtkAllocation *allocation);
223 static void gtk_notebook_calc_tabs (GtkNotebook *notebook,
229 /*** GtkNotebook Page Switch Methods ***/
230 static void gtk_notebook_real_switch_page (GtkNotebook *notebook,
231 GtkNotebookPage *page,
234 /*** GtkNotebook Page Switch Functions ***/
235 static void gtk_notebook_switch_page (GtkNotebook *notebook,
236 GtkNotebookPage *page,
238 static gint gtk_notebook_page_select (GtkNotebook *notebook,
239 gboolean move_focus);
240 static void gtk_notebook_switch_focus_tab (GtkNotebook *notebook,
242 static void gtk_notebook_menu_switch_page (GtkWidget *widget,
243 GtkNotebookPage *page);
245 /*** GtkNotebook Menu Functions ***/
246 static void gtk_notebook_menu_item_create (GtkNotebook *notebook,
248 static void gtk_notebook_menu_label_unparent (GtkWidget *widget,
250 static void gtk_notebook_menu_detacher (GtkWidget *widget,
253 static gboolean focus_tabs_in (GtkNotebook *notebook);
254 static gboolean focus_child_in (GtkNotebook *notebook,
255 GtkDirectionType direction);
257 static GtkContainerClass *parent_class = NULL;
258 static guint notebook_signals[LAST_SIGNAL] = { 0 };
261 gtk_notebook_get_type (void)
263 static GType notebook_type = 0;
267 static const GTypeInfo notebook_info =
269 sizeof (GtkNotebookClass),
270 NULL, /* base_init */
271 NULL, /* base_finalize */
272 (GClassInitFunc) gtk_notebook_class_init,
273 NULL, /* class_finalize */
274 NULL, /* class_data */
275 sizeof (GtkNotebook),
277 (GInstanceInitFunc) gtk_notebook_init,
280 notebook_type = g_type_register_static (GTK_TYPE_CONTAINER, "GtkNotebook",
284 return notebook_type;
288 add_tab_bindings (GtkBindingSet *binding_set,
289 GdkModifierType modifiers,
290 GtkDirectionType direction)
292 gtk_binding_entry_add_signal (binding_set, GDK_Tab, modifiers,
294 GTK_TYPE_DIRECTION_TYPE, direction);
295 gtk_binding_entry_add_signal (binding_set, GDK_KP_Tab, modifiers,
297 GTK_TYPE_DIRECTION_TYPE, direction);
301 add_arrow_bindings (GtkBindingSet *binding_set,
303 GtkDirectionType direction)
305 guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
307 gtk_binding_entry_add_signal (binding_set, keysym, GDK_CONTROL_MASK,
309 GTK_TYPE_DIRECTION_TYPE, direction);
310 gtk_binding_entry_add_signal (binding_set, keypad_keysym, GDK_CONTROL_MASK,
312 GTK_TYPE_DIRECTION_TYPE, direction);
316 gtk_notebook_class_init (GtkNotebookClass *class)
318 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
319 GtkObjectClass *object_class = GTK_OBJECT_CLASS (class);
320 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
321 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
322 GtkBindingSet *binding_set;
324 parent_class = g_type_class_peek_parent (class);
326 gobject_class->set_property = gtk_notebook_set_property;
327 gobject_class->get_property = gtk_notebook_get_property;
328 object_class->destroy = gtk_notebook_destroy;
330 widget_class->map = gtk_notebook_map;
331 widget_class->unmap = gtk_notebook_unmap;
332 widget_class->realize = gtk_notebook_realize;
333 widget_class->unrealize = gtk_notebook_unrealize;
334 widget_class->size_request = gtk_notebook_size_request;
335 widget_class->size_allocate = gtk_notebook_size_allocate;
336 widget_class->expose_event = gtk_notebook_expose;
337 widget_class->button_press_event = gtk_notebook_button_press;
338 widget_class->button_release_event = gtk_notebook_button_release;
339 widget_class->enter_notify_event = gtk_notebook_enter_notify;
340 widget_class->leave_notify_event = gtk_notebook_leave_notify;
341 widget_class->motion_notify_event = gtk_notebook_motion_notify;
342 widget_class->focus_in_event = gtk_notebook_focus_in;
343 widget_class->focus = gtk_notebook_focus;
345 container_class->add = gtk_notebook_add;
346 container_class->remove = gtk_notebook_remove;
347 container_class->forall = gtk_notebook_forall;
348 container_class->set_focus_child = gtk_notebook_set_focus_child;
349 container_class->get_child_property = gtk_notebook_get_child_property;
350 container_class->set_child_property = gtk_notebook_set_child_property;
351 container_class->child_type = gtk_notebook_child_type;
353 class->switch_page = gtk_notebook_real_switch_page;
355 class->focus_tab = gtk_notebook_focus_tab;
356 class->select_page = gtk_notebook_select_page;
357 class->change_current_page = gtk_notebook_change_current_page;
358 class->move_focus_out = gtk_notebook_move_focus_out;
360 g_object_class_install_property (gobject_class,
362 g_param_spec_int ("page",
364 _("The index of the current page"),
369 g_object_class_install_property (gobject_class,
371 g_param_spec_enum ("tab_pos",
373 _("Which side of the notebook holds the tabs"),
374 GTK_TYPE_POSITION_TYPE,
377 g_object_class_install_property (gobject_class,
379 g_param_spec_uint ("tab_border",
381 _("Width of the border around the tab labels"),
386 g_object_class_install_property (gobject_class,
388 g_param_spec_uint ("tab_hborder",
389 _("Horizontal Tab Border"),
390 _("Width of the horizontal border of tab labels"),
395 g_object_class_install_property (gobject_class,
397 g_param_spec_uint ("tab_vborder",
398 _("Vertical Tab Border"),
399 _("Width of the vertical border of tab labels"),
404 g_object_class_install_property (gobject_class,
406 g_param_spec_boolean ("show_tabs",
408 _("Whether tabs should be shown or not"),
411 g_object_class_install_property (gobject_class,
413 g_param_spec_boolean ("show_border",
415 _("Whether the border should be shown or not"),
418 g_object_class_install_property (gobject_class,
420 g_param_spec_boolean ("scrollable",
422 _("If TRUE, scroll arrows are added if there are too many tabs to fit"),
425 g_object_class_install_property (gobject_class,
427 g_param_spec_boolean ("enable_popup",
429 _("If TRUE, pressing the right mouse button on the notebook pops up a menu that you can use to go to a page"),
432 g_object_class_install_property (gobject_class,
434 g_param_spec_boolean ("homogeneous",
436 _("Whether tabs should have homogeneous sizes"),
440 gtk_container_class_install_child_property (container_class,
441 CHILD_PROP_TAB_LABEL,
442 g_param_spec_string ("tab_label",
444 _("The string displayed on the childs tab label"),
447 gtk_container_class_install_child_property (container_class,
448 CHILD_PROP_MENU_LABEL,
449 g_param_spec_string ("menu_label",
451 _("The string displayed in the childs menu entry"),
454 gtk_container_class_install_child_property (container_class,
456 g_param_spec_int ("position",
458 _("The index of the child in the parent"),
461 gtk_container_class_install_child_property (container_class,
462 CHILD_PROP_TAB_EXPAND,
463 g_param_spec_boolean ("tab_expand",
465 _("Whether to expand the childs tab or not"),
468 gtk_container_class_install_child_property (container_class,
470 g_param_spec_boolean ("tab_fill",
472 _("Wheather the childs tab should fill the allocated area or not"),
475 gtk_container_class_install_child_property (container_class,
477 g_param_spec_enum ("tab_pack",
479 _("A GtkPackType indicating whether the child is packed with reference to the start or end of the parent"),
480 GTK_TYPE_PACK_TYPE, GTK_PACK_START,
483 notebook_signals[SWITCH_PAGE] =
484 g_signal_new ("switch_page",
485 G_TYPE_FROM_CLASS (gobject_class),
487 G_STRUCT_OFFSET (GtkNotebookClass, switch_page),
489 _gtk_marshal_VOID__POINTER_UINT,
493 notebook_signals[FOCUS_TAB] =
494 g_signal_new ("focus_tab",
495 G_TYPE_FROM_CLASS (gobject_class),
496 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
497 G_STRUCT_OFFSET (GtkNotebookClass, focus_tab),
499 _gtk_marshal_BOOLEAN__ENUM,
501 GTK_TYPE_NOTEBOOK_TAB);
502 notebook_signals[SELECT_PAGE] =
503 g_signal_new ("select_page",
504 G_TYPE_FROM_CLASS (gobject_class),
505 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
506 G_STRUCT_OFFSET (GtkNotebookClass, select_page),
508 _gtk_marshal_BOOLEAN__BOOLEAN,
511 notebook_signals[CHANGE_CURRENT_PAGE] =
512 g_signal_new ("change_current_page",
513 G_TYPE_FROM_CLASS (gobject_class),
514 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
515 G_STRUCT_OFFSET (GtkNotebookClass, change_current_page),
517 _gtk_marshal_VOID__INT,
520 notebook_signals[MOVE_FOCUS_OUT] =
521 g_signal_new ("move_focus_out",
522 G_TYPE_FROM_CLASS (gobject_class),
523 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
524 G_STRUCT_OFFSET (GtkNotebookClass, move_focus_out),
526 _gtk_marshal_VOID__ENUM,
528 GTK_TYPE_DIRECTION_TYPE);
531 binding_set = gtk_binding_set_by_class (class);
532 gtk_binding_entry_add_signal (binding_set,
535 G_TYPE_BOOLEAN, FALSE);
536 gtk_binding_entry_add_signal (binding_set,
539 G_TYPE_BOOLEAN, FALSE);
541 gtk_binding_entry_add_signal (binding_set,
544 GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_FIRST);
545 gtk_binding_entry_add_signal (binding_set,
548 GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_FIRST);
549 gtk_binding_entry_add_signal (binding_set,
552 GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_LAST);
553 gtk_binding_entry_add_signal (binding_set,
556 GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_LAST);
558 gtk_binding_entry_add_signal (binding_set,
559 GDK_Page_Up, GDK_CONTROL_MASK,
560 "change_current_page", 1,
562 gtk_binding_entry_add_signal (binding_set,
563 GDK_Page_Down, GDK_CONTROL_MASK,
564 "change_current_page", 1,
567 add_arrow_bindings (binding_set, GDK_Up, GTK_DIR_UP);
568 add_arrow_bindings (binding_set, GDK_Down, GTK_DIR_DOWN);
569 add_arrow_bindings (binding_set, GDK_Left, GTK_DIR_LEFT);
570 add_arrow_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT);
572 add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
573 add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
577 gtk_notebook_init (GtkNotebook *notebook)
579 GTK_WIDGET_SET_FLAGS (notebook, GTK_CAN_FOCUS | GTK_RECEIVES_DEFAULT);
580 GTK_WIDGET_SET_FLAGS (notebook, GTK_NO_WINDOW);
582 notebook->cur_page = NULL;
583 notebook->children = NULL;
584 notebook->first_tab = NULL;
585 notebook->focus_tab = NULL;
586 notebook->event_window = NULL;
587 notebook->menu = NULL;
589 notebook->tab_hborder = 2;
590 notebook->tab_vborder = 2;
592 notebook->show_tabs = TRUE;
593 notebook->show_border = TRUE;
594 notebook->tab_pos = GTK_POS_TOP;
595 notebook->scrollable = FALSE;
596 notebook->in_child = 0;
597 notebook->click_child = 0;
598 notebook->button = 0;
599 notebook->need_timer = 0;
600 notebook->child_has_focus = FALSE;
601 notebook->have_visible_child = FALSE;
602 notebook->focus_out = FALSE;
606 gtk_notebook_select_page (GtkNotebook *notebook,
609 if (gtk_widget_is_focus (GTK_WIDGET (notebook)))
611 gtk_notebook_page_select (notebook, move_focus);
619 gtk_notebook_focus_tab (GtkNotebook *notebook,
624 if (gtk_widget_is_focus (GTK_WIDGET (notebook)))
628 case GTK_NOTEBOOK_TAB_FIRST:
629 list = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, TRUE);
631 gtk_notebook_switch_focus_tab (notebook, list);
633 case GTK_NOTEBOOK_TAB_LAST:
634 list = gtk_notebook_search_page (notebook, NULL, STEP_PREV, TRUE);
636 gtk_notebook_switch_focus_tab (notebook, list);
647 gtk_notebook_change_current_page (GtkNotebook *notebook,
650 GList *current = NULL;
652 if (notebook->cur_page)
653 current = g_list_find (notebook->children, notebook->cur_page);
657 current = gtk_notebook_search_page (notebook, current, offset < 0 ? STEP_PREV : STEP_NEXT, TRUE);
658 offset += offset < 0 ? 1 : -1;
662 gtk_notebook_switch_page (notebook, current->data, -1);
664 gdk_display_beep (gtk_widget_get_display (GTK_WIDGET (notebook)));
667 static GtkDirectionType
668 get_effective_direction (GtkNotebook *notebook,
669 GtkDirectionType direction)
671 /* Remap the directions into the effective direction it would be for a
672 * GTK_POS_TOP notebook
674 #define D(rest) GTK_DIR_##rest
676 static const GtkDirectionType translate_direction[4][6] = {
677 /* LEFT */ { D(TAB_FORWARD), D(TAB_BACKWARD), D(LEFT), D(RIGHT), D(UP), D(DOWN) },
678 /* RIGHT */ { D(TAB_BACKWARD), D(TAB_FORWARD), D(LEFT), D(RIGHT), D(DOWN), D(UP) },
679 /* TOP */ { D(TAB_FORWARD), D(TAB_BACKWARD), D(UP), D(DOWN), D(LEFT), D(RIGHT) },
680 /* BOTTOM */ { D(TAB_BACKWARD), D(TAB_FORWARD), D(DOWN), D(UP), D(LEFT), D(RIGHT) },
685 return translate_direction[notebook->tab_pos][direction];
689 gtk_notebook_move_focus_out (GtkNotebook *notebook,
690 GtkDirectionType direction_type)
692 GtkDirectionType effective_direction = get_effective_direction (notebook, direction_type);
695 if (GTK_CONTAINER (notebook)->focus_child && effective_direction == GTK_DIR_UP)
696 if (focus_tabs_in (notebook))
699 if (gtk_widget_is_focus (GTK_WIDGET (notebook)) && effective_direction == GTK_DIR_DOWN)
700 if (focus_child_in (notebook, GTK_DIR_TAB_FORWARD))
703 /* At this point, we know we should be focusing out of the notebook entirely. We
704 * do this by setting a flag, then propagating the focus motion to the notebook.
706 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (notebook));
707 if (!GTK_WIDGET_TOPLEVEL (toplevel))
710 g_object_ref (notebook);
712 notebook->focus_out = TRUE;
713 g_signal_emit_by_name (toplevel, "move_focus", direction_type);
714 notebook->focus_out = FALSE;
716 g_object_unref (notebook);
723 * Creates a new #GtkNotebook widget with no pages.
725 * Return value: the newly created #GtkNotebook
728 gtk_notebook_new (void)
730 return g_object_new (GTK_TYPE_NOTEBOOK, NULL);
733 /* Private GtkObject Methods :
735 * gtk_notebook_destroy
736 * gtk_notebook_set_arg
737 * gtk_notebook_get_arg
740 gtk_notebook_destroy (GtkObject *object)
742 GtkNotebook *notebook = GTK_NOTEBOOK (object);
745 gtk_notebook_popup_disable (notebook);
747 GTK_OBJECT_CLASS (parent_class)->destroy (object);
751 gtk_notebook_set_property (GObject *object,
756 GtkNotebook *notebook;
758 notebook = GTK_NOTEBOOK (object);
763 gtk_notebook_set_show_tabs (notebook, g_value_get_boolean (value));
765 case PROP_SHOW_BORDER:
766 gtk_notebook_set_show_border (notebook, g_value_get_boolean (value));
768 case PROP_SCROLLABLE:
769 gtk_notebook_set_scrollable (notebook, g_value_get_boolean (value));
771 case PROP_ENABLE_POPUP:
772 if (g_value_get_boolean (value))
773 gtk_notebook_popup_enable (notebook);
775 gtk_notebook_popup_disable (notebook);
777 case PROP_HOMOGENEOUS:
778 gtk_notebook_set_homogeneous_tabs (notebook, g_value_get_boolean (value));
781 gtk_notebook_set_current_page (notebook, g_value_get_int (value));
784 gtk_notebook_set_tab_pos (notebook, g_value_get_enum (value));
786 case PROP_TAB_BORDER:
787 gtk_notebook_set_tab_border (notebook, g_value_get_uint (value));
789 case PROP_TAB_HBORDER:
790 gtk_notebook_set_tab_hborder (notebook, g_value_get_uint (value));
792 case PROP_TAB_VBORDER:
793 gtk_notebook_set_tab_vborder (notebook, g_value_get_uint (value));
801 gtk_notebook_get_property (GObject *object,
806 GtkNotebook *notebook;
808 notebook = GTK_NOTEBOOK (object);
813 g_value_set_boolean (value, notebook->show_tabs);
815 case PROP_SHOW_BORDER:
816 g_value_set_boolean (value, notebook->show_border);
818 case PROP_SCROLLABLE:
819 g_value_set_boolean (value, notebook->scrollable);
821 case PROP_ENABLE_POPUP:
822 g_value_set_boolean (value, notebook->menu != NULL);
824 case PROP_HOMOGENEOUS:
825 g_value_set_boolean (value, notebook->homogeneous);
828 g_value_set_int (value, gtk_notebook_get_current_page (notebook));
831 g_value_set_enum (value, notebook->tab_pos);
833 case PROP_TAB_HBORDER:
834 g_value_set_uint (value, notebook->tab_hborder);
836 case PROP_TAB_VBORDER:
837 g_value_set_uint (value, notebook->tab_vborder);
840 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
845 /* Private GtkWidget Methods :
849 * gtk_notebook_realize
850 * gtk_notebook_size_request
851 * gtk_notebook_size_allocate
852 * gtk_notebook_expose
853 * gtk_notebook_button_press
854 * gtk_notebook_button_release
855 * gtk_notebook_enter_notify
856 * gtk_notebook_leave_notify
857 * gtk_notebook_motion_notify
858 * gtk_notebook_focus_in
859 * gtk_notebook_focus_out
860 * gtk_notebook_draw_focus
861 * gtk_notebook_style_set
864 gtk_notebook_get_event_window_position (GtkNotebook *notebook,
865 GdkRectangle *rectangle)
867 GtkWidget *widget = GTK_WIDGET (notebook);
868 gint border_width = GTK_CONTAINER (notebook)->border_width;
869 GtkNotebookPage *visible_page = NULL;
872 for (tmp_list = notebook->children; tmp_list; tmp_list = tmp_list->next)
874 GtkNotebookPage *page = tmp_list->data;
875 if (GTK_WIDGET_VISIBLE (page->child))
882 if (notebook->show_tabs && visible_page)
886 rectangle->x = widget->allocation.x + border_width;
887 rectangle->y = widget->allocation.y + border_width;
889 switch (notebook->tab_pos)
893 rectangle->width = widget->allocation.width - 2 * border_width;
894 rectangle->height = visible_page->requisition.height;
895 if (notebook->tab_pos == GTK_POS_BOTTOM)
896 rectangle->y += widget->allocation.height - 2 * border_width - rectangle->height;
900 rectangle->width = visible_page->requisition.width;
901 rectangle->height = widget->allocation.height - 2 * border_width;
902 if (notebook->tab_pos == GTK_POS_RIGHT)
903 rectangle->x += widget->allocation.width - 2 * border_width - rectangle->width;
914 rectangle->x = rectangle->y = 0;
915 rectangle->width = rectangle->height = 10;
923 gtk_notebook_map (GtkWidget *widget)
925 GtkNotebook *notebook;
926 GtkNotebookPage *page;
929 g_return_if_fail (GTK_IS_NOTEBOOK (widget));
931 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
933 notebook = GTK_NOTEBOOK (widget);
935 if (notebook->cur_page &&
936 GTK_WIDGET_VISIBLE (notebook->cur_page->child) &&
937 !GTK_WIDGET_MAPPED (notebook->cur_page->child))
938 gtk_widget_map (notebook->cur_page->child);
940 if (notebook->scrollable)
941 gtk_notebook_pages_allocate (notebook);
944 children = notebook->children;
948 page = children->data;
949 children = children->next;
951 if (page->tab_label &&
952 GTK_WIDGET_VISIBLE (page->tab_label) &&
953 !GTK_WIDGET_MAPPED (page->tab_label))
954 gtk_widget_map (page->tab_label);
958 if (gtk_notebook_get_event_window_position (notebook, NULL))
959 gdk_window_show_unraised (notebook->event_window);
963 gtk_notebook_unmap (GtkWidget *widget)
965 g_return_if_fail (GTK_IS_NOTEBOOK (widget));
967 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
969 gdk_window_hide (GTK_NOTEBOOK (widget)->event_window);
971 GTK_WIDGET_CLASS (parent_class)->unmap (widget);
975 gtk_notebook_realize (GtkWidget *widget)
977 GtkNotebook *notebook;
978 GdkWindowAttr attributes;
979 gint attributes_mask;
980 GdkRectangle event_window_pos;
982 g_return_if_fail (GTK_IS_NOTEBOOK (widget));
984 notebook = GTK_NOTEBOOK (widget);
985 GTK_WIDGET_SET_FLAGS (notebook, GTK_REALIZED);
987 gtk_notebook_get_event_window_position (notebook, &event_window_pos);
989 widget->window = gtk_widget_get_parent_window (widget);
990 g_object_ref (widget->window);
992 attributes.window_type = GDK_WINDOW_CHILD;
993 attributes.x = event_window_pos.x;
994 attributes.y = event_window_pos.y;
995 attributes.width = event_window_pos.width;
996 attributes.height = event_window_pos.height;
997 attributes.wclass = GDK_INPUT_ONLY;
998 attributes.event_mask = gtk_widget_get_events (widget);
999 attributes.event_mask |= (GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK |
1000 GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK);
1002 attributes_mask = GDK_WA_X | GDK_WA_Y;
1004 notebook->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
1005 &attributes, attributes_mask);
1006 gdk_window_set_user_data (notebook->event_window, notebook);
1008 widget->style = gtk_style_attach (widget->style, widget->window);
1012 gtk_notebook_unrealize (GtkWidget *widget)
1014 GtkNotebook *notebook;
1016 g_return_if_fail (GTK_IS_NOTEBOOK (widget));
1018 notebook = GTK_NOTEBOOK (widget);
1020 gdk_window_set_user_data (notebook->event_window, NULL);
1021 gdk_window_destroy (notebook->event_window);
1022 notebook->event_window = NULL;
1024 if (GTK_WIDGET_CLASS (parent_class)->unrealize)
1025 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
1029 gtk_notebook_size_request (GtkWidget *widget,
1030 GtkRequisition *requisition)
1032 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
1033 GtkNotebookPage *page;
1035 GtkRequisition child_requisition;
1036 gboolean switch_page = FALSE;
1040 gtk_widget_style_get (widget, "focus-line-width", &focus_width, NULL);
1042 widget->requisition.width = 0;
1043 widget->requisition.height = 0;
1045 for (children = notebook->children, vis_pages = 0; children;
1046 children = children->next)
1048 page = children->data;
1050 if (GTK_WIDGET_VISIBLE (page->child))
1053 gtk_widget_size_request (page->child, &child_requisition);
1055 widget->requisition.width = MAX (widget->requisition.width,
1056 child_requisition.width);
1057 widget->requisition.height = MAX (widget->requisition.height,
1058 child_requisition.height);
1060 if (notebook->menu && page->menu_label->parent &&
1061 !GTK_WIDGET_VISIBLE (page->menu_label->parent))
1062 gtk_widget_show (page->menu_label->parent);
1066 if (page == notebook->cur_page)
1068 if (notebook->menu && page->menu_label->parent &&
1069 GTK_WIDGET_VISIBLE (page->menu_label->parent))
1070 gtk_widget_hide (page->menu_label->parent);
1074 if (notebook->show_border || notebook->show_tabs)
1076 widget->requisition.width += widget->style->xthickness * 2;
1077 widget->requisition.height += widget->style->ythickness * 2;
1079 if (notebook->show_tabs)
1082 gint tab_height = 0;
1086 for (children = notebook->children; children;
1087 children = children->next)
1089 page = children->data;
1091 if (GTK_WIDGET_VISIBLE (page->child))
1093 if (!GTK_WIDGET_VISIBLE (page->tab_label))
1094 gtk_widget_show (page->tab_label);
1096 gtk_widget_size_request (page->tab_label,
1097 &child_requisition);
1099 page->requisition.width =
1100 child_requisition.width +
1101 2 * widget->style->xthickness;
1102 page->requisition.height =
1103 child_requisition.height +
1104 2 * widget->style->ythickness;
1106 switch (notebook->tab_pos)
1109 case GTK_POS_BOTTOM:
1110 page->requisition.height += 2 * (notebook->tab_vborder +
1112 tab_height = MAX (tab_height, page->requisition.height);
1113 tab_max = MAX (tab_max, page->requisition.width);
1117 page->requisition.width += 2 * (notebook->tab_hborder +
1119 tab_width = MAX (tab_width, page->requisition.width);
1120 tab_max = MAX (tab_max, page->requisition.height);
1124 else if (GTK_WIDGET_VISIBLE (page->tab_label))
1125 gtk_widget_hide (page->tab_label);
1128 children = notebook->children;
1132 switch (notebook->tab_pos)
1135 case GTK_POS_BOTTOM:
1136 if (tab_height == 0)
1139 if (notebook->scrollable && vis_pages > 1 &&
1140 widget->requisition.width < tab_width)
1141 tab_height = MAX (tab_height, ARROW_SIZE);
1143 padding = 2 * (TAB_CURVATURE + focus_width +
1144 notebook->tab_hborder) - TAB_OVERLAP;
1148 page = children->data;
1149 children = children->next;
1151 if (!GTK_WIDGET_VISIBLE (page->child))
1154 if (notebook->homogeneous)
1155 page->requisition.width = tab_max;
1157 page->requisition.width += padding;
1159 tab_width += page->requisition.width;
1160 page->requisition.height = tab_height;
1163 if (notebook->scrollable && vis_pages > 1 &&
1164 widget->requisition.width < tab_width)
1165 tab_width = tab_max + 2 * (ARROW_SIZE + ARROW_SPACING);
1167 if (notebook->homogeneous && !notebook->scrollable)
1168 widget->requisition.width = MAX (widget->requisition.width,
1169 vis_pages * tab_max +
1172 widget->requisition.width = MAX (widget->requisition.width,
1173 tab_width + TAB_OVERLAP);
1175 widget->requisition.height += tab_height;
1182 if (notebook->scrollable && vis_pages > 1 &&
1183 widget->requisition.height < tab_height)
1184 tab_width = MAX (tab_width, ARROW_SPACING +2 * ARROW_SIZE);
1186 padding = 2 * (TAB_CURVATURE + focus_width +
1187 notebook->tab_vborder) - TAB_OVERLAP;
1192 page = children->data;
1193 children = children->next;
1195 if (!GTK_WIDGET_VISIBLE (page->child))
1198 page->requisition.width = tab_width;
1200 if (notebook->homogeneous)
1201 page->requisition.height = tab_max;
1203 page->requisition.height += padding;
1205 tab_height += page->requisition.height;
1208 if (notebook->scrollable && vis_pages > 1 &&
1209 widget->requisition.height < tab_height)
1210 tab_height = tab_max + ARROW_SIZE + ARROW_SPACING;
1212 widget->requisition.width += tab_width;
1214 if (notebook->homogeneous && !notebook->scrollable)
1215 widget->requisition.height =
1216 MAX (widget->requisition.height,
1217 vis_pages * tab_max + TAB_OVERLAP);
1219 widget->requisition.height =
1220 MAX (widget->requisition.height,
1221 tab_height + TAB_OVERLAP);
1223 if (!notebook->homogeneous || notebook->scrollable)
1225 widget->requisition.height = MAX (widget->requisition.height,
1226 vis_pages * tab_max +
1234 for (children = notebook->children; children;
1235 children = children->next)
1237 page = children->data;
1239 if (page->tab_label && GTK_WIDGET_VISIBLE (page->tab_label))
1240 gtk_widget_hide (page->tab_label);
1245 widget->requisition.width += GTK_CONTAINER (widget)->border_width * 2;
1246 widget->requisition.height += GTK_CONTAINER (widget)->border_width * 2;
1252 for (children = notebook->children; children;
1253 children = children->next)
1255 page = children->data;
1256 if (GTK_WIDGET_VISIBLE (page->child))
1258 gtk_notebook_switch_page (notebook, page, -1);
1263 else if (GTK_WIDGET_VISIBLE (widget))
1265 widget->requisition.width = GTK_CONTAINER (widget)->border_width * 2;
1266 widget->requisition.height= GTK_CONTAINER (widget)->border_width * 2;
1269 if (vis_pages && !notebook->cur_page)
1271 children = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, TRUE);
1274 notebook->first_tab = children;
1275 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (children),-1);
1281 gtk_notebook_size_allocate (GtkWidget *widget,
1282 GtkAllocation *allocation)
1284 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
1287 widget->allocation = *allocation;
1288 if (GTK_WIDGET_REALIZED (widget))
1290 GdkRectangle position;
1292 if (gtk_notebook_get_event_window_position (notebook, &position))
1293 gdk_window_move_resize (notebook->event_window,
1294 position.x, position.y,
1295 position.width, position.height);
1298 if (notebook->children)
1300 gint border_width = GTK_CONTAINER (widget)->border_width;
1301 GtkNotebookPage *page;
1302 GtkAllocation child_allocation;
1305 child_allocation.x = widget->allocation.x + border_width;
1306 child_allocation.y = widget->allocation.y + border_width;
1307 child_allocation.width = MAX (1, allocation->width - border_width * 2);
1308 child_allocation.height = MAX (1, allocation->height - border_width * 2);
1310 if (notebook->show_tabs || notebook->show_border)
1312 child_allocation.x += widget->style->xthickness;
1313 child_allocation.y += widget->style->ythickness;
1314 child_allocation.width = MAX (1, child_allocation.width -
1315 widget->style->xthickness * 2);
1316 child_allocation.height = MAX (1, child_allocation.height -
1317 widget->style->ythickness * 2);
1319 if (notebook->show_tabs && notebook->children && notebook->cur_page)
1321 switch (notebook->tab_pos)
1324 child_allocation.y += notebook->cur_page->requisition.height;
1325 case GTK_POS_BOTTOM:
1326 child_allocation.height =
1327 MAX (1, child_allocation.height -
1328 notebook->cur_page->requisition.height);
1331 child_allocation.x += notebook->cur_page->requisition.width;
1333 child_allocation.width =
1334 MAX (1, child_allocation.width -
1335 notebook->cur_page->requisition.width);
1341 children = notebook->children;
1344 page = children->data;
1345 children = children->next;
1347 if (GTK_WIDGET_VISIBLE (page->child))
1349 gtk_widget_size_allocate (page->child, &child_allocation);
1354 gtk_notebook_pages_allocate (notebook);
1357 if ((vis_pages != 0) != notebook->have_visible_child)
1359 notebook->have_visible_child = (vis_pages != 0);
1360 if (notebook->show_tabs)
1361 gtk_widget_queue_draw (widget);
1366 gtk_notebook_expose (GtkWidget *widget,
1367 GdkEventExpose *event)
1369 GtkNotebook *notebook;
1370 GdkRectangle child_area;
1372 g_return_val_if_fail (GTK_IS_NOTEBOOK (widget), FALSE);
1373 g_return_val_if_fail (event != NULL, FALSE);
1375 if (GTK_WIDGET_DRAWABLE (widget))
1377 notebook = GTK_NOTEBOOK (widget);
1379 gtk_notebook_paint (widget, &event->area);
1380 if (notebook->show_tabs)
1382 if (notebook->cur_page &&
1383 gtk_widget_intersect (notebook->cur_page->tab_label,
1384 &event->area, &child_area))
1385 gtk_notebook_draw_focus (widget);
1389 if (notebook->cur_page)
1390 gtk_container_propagate_expose (GTK_CONTAINER (notebook),
1391 notebook->cur_page->child,
1399 gtk_notebook_show_arrows (GtkNotebook *notebook)
1401 gboolean show_arrow = FALSE;
1404 if (!notebook->scrollable)
1407 children = notebook->children;
1410 GtkNotebookPage *page = children->data;
1412 if (page->tab_label && !gtk_widget_get_child_visible (page->tab_label))
1415 children = children->next;
1422 gtk_notebook_get_arrow_rect (GtkNotebook *notebook,
1423 GdkRectangle *rectangle)
1425 GdkRectangle event_window_pos;
1427 if (gtk_notebook_get_event_window_position (notebook, &event_window_pos))
1429 rectangle->width = 2 * ARROW_SIZE + ARROW_SPACING;
1430 rectangle->height = ARROW_SIZE;
1432 switch (notebook->tab_pos)
1436 rectangle->x = event_window_pos.x + (event_window_pos.width - rectangle->width) / 2;
1437 rectangle->y = event_window_pos.y + event_window_pos.height - rectangle->height;
1440 case GTK_POS_BOTTOM:
1441 rectangle->x = event_window_pos.x + event_window_pos.width - rectangle->width;
1442 rectangle->y = event_window_pos.y + (event_window_pos.height - rectangle->height) / 2;
1449 gtk_notebook_get_arrow (GtkNotebook *notebook,
1453 GdkRectangle arrow_rect;
1454 GdkRectangle event_window_pos;
1456 if (gtk_notebook_show_arrows (notebook))
1458 gtk_notebook_get_event_window_position (notebook, &event_window_pos);
1459 gtk_notebook_get_arrow_rect (notebook, &arrow_rect);
1464 if (y >= 0 && y < arrow_rect.height)
1466 if (x >= 0 && x < ARROW_SIZE + ARROW_SPACING / 2)
1467 return GTK_ARROW_LEFT;
1468 else if (x >= ARROW_SIZE + ARROW_SPACING / 2 && x < arrow_rect.width)
1469 return GTK_ARROW_RIGHT;
1477 gtk_notebook_do_arrow (GtkNotebook *notebook,
1480 GtkWidget *widget = GTK_WIDGET (notebook);
1481 GtkDirectionType dir;
1483 if (!notebook->focus_tab ||
1484 gtk_notebook_search_page (notebook, notebook->focus_tab,
1485 arrow == GTK_ARROW_LEFT ? STEP_PREV : STEP_NEXT,
1488 if (notebook->tab_pos == GTK_POS_LEFT ||
1489 notebook->tab_pos == GTK_POS_RIGHT)
1490 dir = (arrow == GTK_ARROW_LEFT) ? GTK_DIR_UP : GTK_DIR_DOWN;
1492 dir = (arrow == GTK_ARROW_LEFT) ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
1493 gtk_widget_child_focus (widget, dir);
1498 gtk_notebook_arrow_button_press (GtkNotebook *notebook,
1500 GdkEventButton *event)
1502 GtkWidget *widget = GTK_WIDGET (notebook);
1504 if (!GTK_WIDGET_HAS_FOCUS (widget))
1505 gtk_widget_grab_focus (widget);
1507 notebook->button = event->button;
1508 notebook->click_child = arrow;
1510 if (event->button == 1)
1512 gtk_notebook_do_arrow (notebook, arrow);
1514 if (!notebook->timer)
1516 notebook->timer = gtk_timeout_add
1517 (NOTEBOOK_INIT_SCROLL_DELAY,
1518 (GtkFunction) gtk_notebook_timer, (gpointer) notebook);
1519 notebook->need_timer = TRUE;
1522 else if (event->button == 2)
1523 gtk_notebook_page_select (notebook, TRUE);
1524 else if (event->button == 3)
1525 gtk_notebook_switch_focus_tab (notebook,
1526 gtk_notebook_search_page (notebook,
1528 arrow == GTK_ARROW_LEFT ? STEP_NEXT : STEP_PREV,
1530 gtk_notebook_redraw_arrows (notebook);
1536 get_widget_coordinates (GtkWidget *widget,
1541 GdkWindow *window = ((GdkEventAny *)event)->window;
1544 if (!gdk_event_get_coords (event, &tx, &ty))
1547 while (window && window != widget->window)
1549 gint window_x, window_y;
1551 gdk_window_get_position (window, &window_x, &window_y);
1555 window = gdk_window_get_parent (window);
1570 gtk_notebook_button_press (GtkWidget *widget,
1571 GdkEventButton *event)
1573 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
1574 GtkNotebookPage *page;
1580 if (event->type != GDK_BUTTON_PRESS || !notebook->children ||
1584 if (!get_widget_coordinates (widget, (GdkEvent *)event, &x, &y))
1587 arrow = gtk_notebook_get_arrow (notebook, x, y);
1589 return gtk_notebook_arrow_button_press (notebook, arrow, event);
1591 if (event->button == 3 && notebook->menu)
1593 gtk_menu_popup (GTK_MENU (notebook->menu), NULL, NULL,
1594 NULL, NULL, 3, event->time);
1599 children = notebook->children;
1602 page = children->data;
1604 if (GTK_WIDGET_VISIBLE (page->child) &&
1605 page->tab_label && GTK_WIDGET_MAPPED (page->tab_label) &&
1606 (x >= page->allocation.x) &&
1607 (y >= page->allocation.y) &&
1608 (x <= (page->allocation.x + page->allocation.width)) &&
1609 (y <= (page->allocation.y + page->allocation.height)))
1611 if (page == notebook->cur_page && notebook->focus_tab &&
1612 notebook->focus_tab != children &&
1613 GTK_WIDGET_HAS_FOCUS (notebook))
1615 GtkNotebookPage *old_page;
1617 notebook->child_has_focus = FALSE;
1618 old_page = (GtkNotebookPage *)
1619 (notebook->focus_tab->data);
1620 gtk_notebook_switch_focus_tab (notebook, children);
1621 gtk_notebook_focus_changed (notebook, old_page);
1625 gtk_notebook_switch_focus_tab (notebook, children);
1626 gtk_widget_grab_focus (widget);
1627 gtk_notebook_switch_page (notebook, page, num);
1631 children = children->next;
1634 if (!children && !GTK_WIDGET_HAS_FOCUS (widget))
1635 gtk_widget_grab_focus (widget);
1641 gtk_notebook_button_release (GtkWidget *widget,
1642 GdkEventButton *event)
1644 GtkNotebook *notebook;
1646 g_return_val_if_fail (GTK_IS_NOTEBOOK (widget), FALSE);
1647 g_return_val_if_fail (event != NULL, FALSE);
1649 if (event->type != GDK_BUTTON_RELEASE)
1652 notebook = GTK_NOTEBOOK (widget);
1654 if (event->button == notebook->button)
1658 if (notebook->timer)
1660 gtk_timeout_remove (notebook->timer);
1661 notebook->timer = 0;
1662 notebook->need_timer = FALSE;
1664 click_child = notebook->click_child;
1665 notebook->click_child = 0;
1666 notebook->button = 0;
1667 gtk_notebook_redraw_arrows (notebook);
1676 gtk_notebook_enter_notify (GtkWidget *widget,
1677 GdkEventCrossing *event)
1679 GtkNotebook *notebook;
1683 g_return_val_if_fail (GTK_IS_NOTEBOOK (widget), FALSE);
1684 g_return_val_if_fail (event != NULL, FALSE);
1686 notebook = GTK_NOTEBOOK (widget);
1688 if (!get_widget_coordinates (widget, (GdkEvent *)event, &x, &y))
1691 arrow = gtk_notebook_get_arrow (notebook, x, y);
1693 if (arrow != notebook->in_child)
1695 notebook->in_child = arrow;
1696 gtk_notebook_redraw_arrows (notebook);
1705 gtk_notebook_leave_notify (GtkWidget *widget,
1706 GdkEventCrossing *event)
1708 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
1712 if (!get_widget_coordinates (widget, (GdkEvent *)event, &x, &y))
1715 arrow = gtk_notebook_get_arrow (notebook, x, y);
1717 if (notebook->in_child)
1719 notebook->in_child = 0;
1720 gtk_notebook_redraw_arrows (notebook);
1727 gtk_notebook_motion_notify (GtkWidget *widget,
1728 GdkEventMotion *event)
1730 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
1734 if (notebook->button)
1737 if (!get_widget_coordinates (widget, (GdkEvent *)event, &x, &y))
1740 arrow = gtk_notebook_get_arrow (notebook, x, y);
1742 if (arrow != notebook->in_child)
1744 notebook->in_child = arrow;
1745 gtk_notebook_redraw_arrows (notebook);
1752 gtk_notebook_focus_in (GtkWidget *widget,
1753 GdkEventFocus *event)
1755 GTK_NOTEBOOK (widget)->child_has_focus = FALSE;
1757 return (* GTK_WIDGET_CLASS (parent_class)->focus_in_event) (widget, event);
1761 gtk_notebook_draw_focus (GtkWidget *widget)
1763 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
1765 if (GTK_WIDGET_DRAWABLE (widget) && notebook->show_tabs &&
1766 notebook->focus_tab)
1768 GtkNotebookPage *page;
1772 gtk_widget_style_get (widget, "focus-line-width", &focus_width, NULL);
1774 page = notebook->focus_tab->data;
1776 area.x = page->tab_label->allocation.x - focus_width;
1777 area.y = page->tab_label->allocation.y - focus_width;
1778 area.width = page->tab_label->allocation.width + 2 * focus_width;
1779 area.height = page->tab_label->allocation.height + 2 * focus_width;
1781 gtk_notebook_draw_tab (GTK_NOTEBOOK (widget), page, &area);
1785 /* Private GtkContainer Methods :
1787 * gtk_notebook_set_child_arg
1788 * gtk_notebook_get_child_arg
1790 * gtk_notebook_remove
1791 * gtk_notebook_focus
1792 * gtk_notebook_set_focus_child
1793 * gtk_notebook_child_type
1794 * gtk_notebook_forall
1797 gtk_notebook_set_child_property (GtkContainer *container,
1800 const GValue *value,
1805 GtkPackType pack_type;
1807 /* not finding child's page is valid for menus or labels */
1808 if (!gtk_notebook_find_child (GTK_NOTEBOOK (container), child, NULL))
1811 switch (property_id)
1813 case CHILD_PROP_TAB_LABEL:
1814 /* a NULL pointer indicates a default_tab setting, otherwise
1815 * we need to set the associated label
1817 gtk_notebook_set_tab_label_text (GTK_NOTEBOOK (container), child,
1818 g_value_get_string (value));
1820 case CHILD_PROP_MENU_LABEL:
1821 gtk_notebook_set_menu_label_text (GTK_NOTEBOOK (container), child,
1822 g_value_get_string (value));
1824 case CHILD_PROP_POSITION:
1825 gtk_notebook_reorder_child (GTK_NOTEBOOK (container), child,
1826 g_value_get_int (value));
1828 case CHILD_PROP_TAB_EXPAND:
1829 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
1830 &expand, &fill, &pack_type);
1831 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (container), child,
1832 g_value_get_boolean (value),
1835 case CHILD_PROP_TAB_FILL:
1836 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
1837 &expand, &fill, &pack_type);
1838 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (container), child,
1840 g_value_get_boolean (value),
1843 case CHILD_PROP_TAB_PACK:
1844 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
1845 &expand, &fill, &pack_type);
1846 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (container), child,
1848 g_value_get_enum (value));
1851 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
1857 gtk_notebook_get_child_property (GtkContainer *container,
1864 GtkNotebook *notebook;
1868 GtkPackType pack_type;
1870 notebook = GTK_NOTEBOOK (container);
1872 /* not finding child's page is valid for menus or labels */
1873 list = gtk_notebook_find_child (notebook, child, NULL);
1876 /* nothing to set on labels or menus */
1877 g_param_value_set_default (pspec, value);
1881 switch (property_id)
1883 case CHILD_PROP_TAB_LABEL:
1884 label = gtk_notebook_get_tab_label (notebook, child);
1886 if (label && GTK_IS_LABEL (label))
1887 g_value_set_string (value, GTK_LABEL (label)->label);
1889 g_value_set_string (value, NULL);
1891 case CHILD_PROP_MENU_LABEL:
1892 label = gtk_notebook_get_menu_label (notebook, child);
1894 if (label && GTK_IS_LABEL (label))
1895 g_value_set_string (value, GTK_LABEL (label)->label);
1897 g_value_set_string (value, NULL);
1899 case CHILD_PROP_POSITION:
1900 g_value_set_int (value, g_list_position (notebook->children, list));
1902 case CHILD_PROP_TAB_EXPAND:
1903 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
1904 &expand, NULL, NULL);
1905 g_value_set_boolean (value, expand);
1907 case CHILD_PROP_TAB_FILL:
1908 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
1910 g_value_set_boolean (value, fill);
1912 case CHILD_PROP_TAB_PACK:
1913 gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child,
1914 NULL, NULL, &pack_type);
1915 g_value_set_enum (value, pack_type);
1918 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
1924 gtk_notebook_add (GtkContainer *container,
1927 g_return_if_fail (GTK_IS_NOTEBOOK (container));
1929 gtk_notebook_insert_page_menu (GTK_NOTEBOOK (container), widget,
1934 gtk_notebook_remove (GtkContainer *container,
1937 GtkNotebook *notebook;
1938 GtkNotebookPage *page;
1942 g_return_if_fail (GTK_IS_NOTEBOOK (container));
1943 g_return_if_fail (widget != NULL);
1945 notebook = GTK_NOTEBOOK (container);
1947 children = notebook->children;
1951 page = children->data;
1952 if (page->child == widget)
1954 gtk_notebook_real_remove (notebook, children);
1958 children = children->next;
1963 focus_tabs_in (GtkNotebook *notebook)
1965 if (notebook->show_tabs && notebook->cur_page)
1967 gtk_widget_grab_focus (GTK_WIDGET (notebook));
1969 gtk_notebook_switch_focus_tab (notebook,
1970 g_list_find (notebook->children,
1971 notebook->cur_page));
1980 focus_tabs_move (GtkNotebook *notebook,
1981 GtkDirectionType direction,
1982 gint search_direction)
1986 new_page = gtk_notebook_search_page (notebook, notebook->focus_tab,
1987 search_direction, TRUE);
1989 gtk_notebook_switch_focus_tab (notebook, new_page);
1991 gdk_display_beep (gtk_widget_get_display (GTK_WIDGET (notebook)));
1997 focus_child_in (GtkNotebook *notebook,
1998 GtkDirectionType direction)
2000 if (notebook->cur_page)
2001 return gtk_widget_child_focus (notebook->cur_page->child, direction);
2006 /* Focus in the notebook can either be on the pages, or on
2010 gtk_notebook_focus (GtkWidget *widget,
2011 GtkDirectionType direction)
2013 GtkWidget *old_focus_child;
2014 GtkNotebook *notebook;
2015 GtkDirectionType effective_direction;
2017 gboolean widget_is_focus;
2018 GtkContainer *container;
2020 g_return_val_if_fail (GTK_IS_NOTEBOOK (widget), FALSE);
2022 container = GTK_CONTAINER (widget);
2023 notebook = GTK_NOTEBOOK (container);
2025 if (notebook->focus_out)
2027 notebook->focus_out = FALSE; /* Clear this to catch the wrap-around case */
2031 widget_is_focus = gtk_widget_is_focus (widget);
2032 old_focus_child = container->focus_child;
2034 effective_direction = get_effective_direction (notebook, direction);
2036 if (old_focus_child) /* Focus on page child */
2038 if (gtk_widget_child_focus (old_focus_child, direction))
2041 switch (effective_direction)
2043 case GTK_DIR_TAB_BACKWARD:
2045 /* Focus onto the tabs */
2046 return focus_tabs_in (notebook);
2048 case GTK_DIR_TAB_FORWARD:
2054 else if (widget_is_focus) /* Focus was on tabs */
2056 switch (effective_direction)
2058 case GTK_DIR_TAB_BACKWARD:
2061 case GTK_DIR_TAB_FORWARD:
2063 /* We use TAB_FORWARD rather than direction so that we focus a more
2064 * predictable widget for the user; users may be using arrow focusing
2065 * in this situation even if they don't usually use arrow focusing.
2067 return focus_child_in (notebook, GTK_DIR_TAB_FORWARD);
2069 return focus_tabs_move (notebook, direction, STEP_PREV);
2071 return focus_tabs_move (notebook, direction, STEP_NEXT);
2074 else /* Focus was not on widget */
2076 switch (effective_direction)
2078 case GTK_DIR_TAB_FORWARD:
2080 if (focus_tabs_in (notebook))
2082 if (focus_child_in (notebook, direction))
2085 case GTK_DIR_TAB_BACKWARD:
2087 if (focus_child_in (notebook, direction))
2089 if (focus_tabs_in (notebook))
2094 return focus_child_in (notebook, direction);
2098 g_assert_not_reached ();
2103 gtk_notebook_set_focus_child (GtkContainer *container,
2106 GtkNotebook *notebook = GTK_NOTEBOOK (container);
2107 GtkWidget *page_child;
2108 GtkWidget *toplevel;
2110 /* If the old focus widget was within a page of the notebook,
2111 * (child may either be NULL or not in this case), record it
2112 * for future use if we switch to the page with a mnemonic.
2115 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (container));
2116 if (toplevel && GTK_WIDGET_TOPLEVEL (toplevel))
2118 page_child = GTK_WINDOW (toplevel)->focus_widget;
2121 if (page_child->parent == GTK_WIDGET (container))
2123 GList *list = gtk_notebook_find_child (notebook, page_child, NULL);
2126 GtkNotebookPage *page = list->data;
2128 if (page->last_focus_child)
2129 g_object_remove_weak_pointer (G_OBJECT (page->last_focus_child), (gpointer *)&page->last_focus_child);
2131 page->last_focus_child = GTK_WINDOW (toplevel)->focus_widget;
2132 g_object_add_weak_pointer (G_OBJECT (page->last_focus_child), (gpointer *)&page->last_focus_child);
2138 page_child = page_child->parent;
2144 g_return_if_fail (GTK_IS_WIDGET (child));
2146 notebook->child_has_focus = TRUE;
2147 if (!notebook->focus_tab)
2150 GtkNotebookPage *page;
2152 children = notebook->children;
2155 page = children->data;
2156 if (page->child == child || page->tab_label == child)
2157 gtk_notebook_switch_focus_tab (notebook, children);
2158 children = children->next;
2163 parent_class->set_focus_child (container, child);
2167 gtk_notebook_forall (GtkContainer *container,
2168 gboolean include_internals,
2169 GtkCallback callback,
2170 gpointer callback_data)
2172 GtkNotebook *notebook;
2175 g_return_if_fail (GTK_IS_NOTEBOOK (container));
2176 g_return_if_fail (callback != NULL);
2178 notebook = GTK_NOTEBOOK (container);
2180 children = notebook->children;
2183 GtkNotebookPage *page;
2185 page = children->data;
2186 children = children->next;
2187 (* callback) (page->child, callback_data);
2188 if (include_internals)
2190 if (page->tab_label)
2191 (* callback) (page->tab_label, callback_data);
2192 if (page->menu_label)
2193 (* callback) (page->menu_label, callback_data);
2199 gtk_notebook_child_type (GtkContainer *container)
2201 return GTK_TYPE_WIDGET;
2204 /* Private GtkNotebook Functions:
2206 * gtk_notebook_redraw_tabs
2207 * gtk_notebook_focus_changed
2208 * gtk_notebook_real_remove
2209 * gtk_notebook_update_labels
2210 * gtk_notebook_timer
2211 * gtk_notebook_page_compare
2212 * gtk_notebook_real_page_position
2213 * gtk_notebook_search_page
2216 gtk_notebook_redraw_tabs (GtkNotebook *notebook)
2219 GtkNotebookPage *page;
2220 GdkRectangle redraw_rect;
2223 widget = GTK_WIDGET (notebook);
2224 border = GTK_CONTAINER (notebook)->border_width;
2226 if (!GTK_WIDGET_MAPPED (notebook) || !notebook->first_tab)
2229 page = notebook->first_tab->data;
2231 redraw_rect.x = border;
2232 redraw_rect.y = border;
2234 switch (notebook->tab_pos)
2236 case GTK_POS_BOTTOM:
2237 redraw_rect.y = (widget->allocation.height - border -
2238 page->allocation.height -
2239 widget->style->ythickness);
2240 if (page != notebook->cur_page)
2241 redraw_rect.y -= widget->style->ythickness;
2244 redraw_rect.width = widget->allocation.width - 2 * border;
2245 redraw_rect.height = (page->allocation.height +
2246 widget->style->ythickness);
2247 if (page != notebook->cur_page)
2248 redraw_rect.height += widget->style->ythickness;
2251 redraw_rect.x = (widget->allocation.width - border -
2252 page->allocation.width -
2253 widget->style->xthickness);
2254 if (page != notebook->cur_page)
2255 redraw_rect.x -= widget->style->xthickness;
2258 redraw_rect.width = (page->allocation.width +
2259 widget->style->xthickness);
2260 redraw_rect.height = widget->allocation.height - 2 * border;
2261 if (page != notebook->cur_page)
2262 redraw_rect.width += widget->style->xthickness;
2266 redraw_rect.x += widget->allocation.x;
2267 redraw_rect.y += widget->allocation.y;
2269 gdk_window_invalidate_rect (widget->window, &redraw_rect, TRUE);
2273 gtk_notebook_redraw_arrows (GtkNotebook *notebook)
2275 if (GTK_WIDGET_MAPPED (notebook) && gtk_notebook_show_arrows (notebook))
2279 gtk_notebook_get_arrow_rect (notebook, &rect);
2280 gdk_window_invalidate_rect (GTK_WIDGET (notebook)->window, &rect, FALSE);
2285 gtk_notebook_focus_changed (GtkNotebook *notebook,
2286 GtkNotebookPage *old_page)
2288 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
2290 if (GTK_WIDGET_DRAWABLE (notebook) && notebook->show_tabs)
2295 gtk_widget_style_get (GTK_WIDGET (notebook), "focus-line-width", &focus_width, NULL);
2297 if (notebook->focus_tab)
2299 GtkNotebookPage *page;
2301 page = notebook->focus_tab->data;
2303 area.x = page->tab_label->allocation.x - focus_width;
2304 area.y = page->tab_label->allocation.y - focus_width;
2305 area.width = page->tab_label->allocation.width + 2 * focus_width;
2306 area.height = page->tab_label->allocation.height + 2 * focus_width;
2308 gtk_notebook_draw_tab (notebook, page, &area);
2313 area.x = old_page->tab_label->allocation.x - focus_width;
2314 area.y = old_page->tab_label->allocation.y - focus_width;
2315 area.width = old_page->tab_label->allocation.width + 2 * focus_width;
2316 area.height = old_page->tab_label->allocation.height + 2 * focus_width;
2318 gtk_notebook_draw_tab (notebook, old_page, &area);
2324 gtk_notebook_timer (GtkNotebook *notebook)
2326 gboolean retval = FALSE;
2328 GDK_THREADS_ENTER ();
2330 if (notebook->timer)
2332 gtk_notebook_do_arrow (notebook, notebook->click_child);
2334 if (notebook->need_timer)
2336 notebook->need_timer = FALSE;
2337 notebook->timer = gtk_timeout_add (NOTEBOOK_SCROLL_DELAY,
2338 (GtkFunction) gtk_notebook_timer,
2339 (gpointer) notebook);
2345 GDK_THREADS_LEAVE ();
2351 gtk_notebook_page_compare (gconstpointer a,
2354 return (((GtkNotebookPage *) a)->child != b);
2358 gtk_notebook_find_child (GtkNotebook *notebook,
2360 const gchar *function)
2362 GList *list = g_list_find_custom (notebook->children, child,
2363 gtk_notebook_page_compare);
2365 #ifndef G_DISABLE_CHECKS
2366 if (!list && function)
2367 g_warning ("%s: unable to find child %p in notebook %p",
2368 function, child, notebook);
2375 gtk_notebook_remove_tab_label (GtkNotebook *notebook,
2376 GtkNotebookPage *page)
2378 if (page->tab_label)
2380 if (page->mnemonic_activate_signal)
2381 g_signal_handler_disconnect (page->tab_label,
2382 page->mnemonic_activate_signal);
2383 page->mnemonic_activate_signal = 0;
2385 gtk_widget_unparent (page->tab_label);
2390 gtk_notebook_real_remove (GtkNotebook *notebook,
2393 GtkNotebookPage *page;
2395 gint need_resize = FALSE;
2397 next_list = gtk_notebook_search_page (notebook, list, STEP_PREV, TRUE);
2399 next_list = gtk_notebook_search_page (notebook, list, STEP_NEXT, TRUE);
2401 if (notebook->cur_page == list->data)
2403 notebook->cur_page = NULL;
2405 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (next_list), -1);
2408 if (list == notebook->first_tab)
2409 notebook->first_tab = next_list;
2410 if (list == notebook->focus_tab)
2411 gtk_notebook_switch_focus_tab (notebook, next_list);
2415 if (GTK_WIDGET_VISIBLE (page->child) && GTK_WIDGET_VISIBLE (notebook))
2418 gtk_widget_unparent (page->child);
2420 gtk_notebook_remove_tab_label (notebook, page);
2424 gtk_container_remove (GTK_CONTAINER (notebook->menu),
2425 page->menu_label->parent);
2426 gtk_widget_queue_resize (notebook->menu);
2428 if (!page->default_menu)
2429 g_object_unref (page->menu_label);
2431 notebook->children = g_list_remove_link (notebook->children, list);
2434 if (page->last_focus_child)
2436 g_object_remove_weak_pointer (G_OBJECT (page->last_focus_child), (gpointer *)&page->last_focus_child);
2437 page->last_focus_child = NULL;
2442 if (!notebook->children && notebook->show_tabs &&
2443 GTK_WIDGET_MAPPED (notebook))
2444 gdk_window_hide (notebook->event_window);
2446 gtk_notebook_update_labels (notebook);
2448 gtk_widget_queue_resize (GTK_WIDGET (notebook));
2452 gtk_notebook_update_labels (GtkNotebook *notebook)
2454 GtkNotebookPage *page;
2459 for (list = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, FALSE);
2461 list = gtk_notebook_search_page (notebook, list, STEP_NEXT, FALSE))
2464 g_snprintf (string, sizeof(string), _("Page %u"), page_num++);
2465 if (notebook->show_tabs)
2467 if (page->default_tab)
2469 if (!page->tab_label)
2471 page->tab_label = gtk_label_new (string);
2472 gtk_widget_set_parent (page->tab_label,
2473 GTK_WIDGET (notebook));
2476 gtk_label_set_text (GTK_LABEL (page->tab_label), string);
2479 if (GTK_WIDGET_VISIBLE (page->child) &&
2480 !GTK_WIDGET_VISIBLE (page->tab_label))
2481 gtk_widget_show (page->tab_label);
2482 else if (!GTK_WIDGET_VISIBLE (page->child) &&
2483 GTK_WIDGET_VISIBLE (page->tab_label))
2484 gtk_widget_hide (page->tab_label);
2486 if (notebook->menu && page->default_menu)
2488 if (page->tab_label && GTK_IS_LABEL (page->tab_label))
2489 gtk_label_set_text (GTK_LABEL (page->menu_label),
2490 GTK_LABEL (page->tab_label)->label);
2492 gtk_label_set_text (GTK_LABEL (page->menu_label), string);
2498 gtk_notebook_real_page_position (GtkNotebook *notebook,
2504 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
2505 g_return_val_if_fail (list != NULL, -1);
2507 for (work = notebook->children, count_start = 0;
2508 work && work != list; work = work->next)
2509 if (GTK_NOTEBOOK_PAGE (work)->pack == GTK_PACK_START)
2515 if (GTK_NOTEBOOK_PAGE (list)->pack == GTK_PACK_START)
2518 return (count_start + g_list_length (list) - 1);
2522 gtk_notebook_search_page (GtkNotebook *notebook,
2525 gboolean find_visible)
2527 GtkNotebookPage *page = NULL;
2528 GList *old_list = NULL;
2531 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
2536 flag = GTK_PACK_END;
2540 flag = GTK_PACK_START;
2547 if (!page || page->pack == flag)
2555 list = notebook->children;
2560 if (page->pack == flag &&
2561 (!find_visible || GTK_WIDGET_VISIBLE (page->child)))
2576 if (page->pack != flag &&
2577 (!find_visible || GTK_WIDGET_VISIBLE (page->child)))
2585 /* Private GtkNotebook Drawing Functions:
2587 * gtk_notebook_paint
2588 * gtk_notebook_draw_tab
2589 * gtk_notebook_draw_arrow
2592 gtk_notebook_paint (GtkWidget *widget,
2595 GtkNotebook *notebook;
2596 GtkNotebookPage *page;
2601 gint border_width = GTK_CONTAINER (widget)->border_width;
2602 gint gap_x = 0, gap_width = 0;
2604 g_return_if_fail (GTK_IS_NOTEBOOK (widget));
2605 g_return_if_fail (area != NULL);
2607 if (!GTK_WIDGET_DRAWABLE (widget))
2610 notebook = GTK_NOTEBOOK (widget);
2612 if ((!notebook->show_tabs && !notebook->show_border) ||
2613 !notebook->cur_page || !GTK_WIDGET_VISIBLE (notebook->cur_page->child))
2616 x = widget->allocation.x + border_width;
2617 y = widget->allocation.y + border_width;
2618 width = widget->allocation.width - border_width * 2;
2619 height = widget->allocation.height - border_width * 2;
2621 if (notebook->show_border && (!notebook->show_tabs || !notebook->children))
2623 gtk_paint_box (widget->style, widget->window,
2624 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
2625 area, widget, "notebook",
2626 x, y, width, height);
2631 if (!GTK_WIDGET_MAPPED (notebook->cur_page->tab_label))
2633 page = notebook->first_tab->data;
2635 switch (notebook->tab_pos)
2638 y += page->allocation.height + widget->style->ythickness;
2639 case GTK_POS_BOTTOM:
2640 height -= page->allocation.height + widget->style->ythickness;
2643 x += page->allocation.width + widget->style->xthickness;
2645 width -= page->allocation.width + widget->style->xthickness;
2648 gtk_paint_box (widget->style, widget->window,
2649 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
2650 area, widget, "notebook",
2651 x, y, width, height);
2655 switch (notebook->tab_pos)
2658 y += notebook->cur_page->allocation.height;
2659 case GTK_POS_BOTTOM:
2660 height -= notebook->cur_page->allocation.height;
2663 x += notebook->cur_page->allocation.width;
2665 width -= notebook->cur_page->allocation.width;
2669 switch (notebook->tab_pos)
2672 case GTK_POS_BOTTOM:
2673 gap_x = (notebook->cur_page->allocation.x - widget->allocation.x - border_width);
2674 gap_width = notebook->cur_page->allocation.width;
2678 gap_x = (notebook->cur_page->allocation.y - widget->allocation.y - border_width);
2679 gap_width = notebook->cur_page->allocation.height;
2682 gtk_paint_box_gap(widget->style, widget->window,
2683 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
2684 area, widget, "notebook",
2685 x, y, width, height,
2686 notebook->tab_pos, gap_x, gap_width);
2690 children = gtk_notebook_search_page (notebook, NULL, STEP_PREV, TRUE);
2693 page = children->data;
2694 children = gtk_notebook_search_page (notebook, children,
2696 if (!GTK_WIDGET_VISIBLE (page->child))
2698 if (!GTK_WIDGET_MAPPED (page->tab_label))
2700 else if (page != notebook->cur_page)
2701 gtk_notebook_draw_tab (notebook, page, area);
2704 if (showarrow && notebook->scrollable)
2706 gtk_notebook_draw_arrow (notebook, GTK_ARROW_LEFT);
2707 gtk_notebook_draw_arrow (notebook, GTK_ARROW_RIGHT);
2709 gtk_notebook_draw_tab (notebook, notebook->cur_page, area);
2713 gtk_notebook_draw_tab (GtkNotebook *notebook,
2714 GtkNotebookPage *page,
2717 GdkRectangle child_area;
2718 GdkRectangle page_area;
2719 GtkStateType state_type;
2720 GtkPositionType gap_side;
2722 g_return_if_fail (notebook != NULL);
2723 g_return_if_fail (page != NULL);
2724 g_return_if_fail (area != NULL);
2726 if (!GTK_WIDGET_MAPPED (page->tab_label) ||
2727 (page->allocation.width == 0) || (page->allocation.height == 0))
2730 page_area.x = page->allocation.x;
2731 page_area.y = page->allocation.y;
2732 page_area.width = page->allocation.width;
2733 page_area.height = page->allocation.height;
2735 if (gdk_rectangle_intersect (&page_area, area, &child_area))
2739 widget = GTK_WIDGET (notebook);
2741 switch (notebook->tab_pos)
2744 gap_side = GTK_POS_BOTTOM;
2746 case GTK_POS_BOTTOM:
2747 gap_side = GTK_POS_TOP;
2750 gap_side = GTK_POS_RIGHT;
2753 gap_side = GTK_POS_LEFT;
2757 if (notebook->cur_page == page)
2758 state_type = GTK_STATE_NORMAL;
2760 state_type = GTK_STATE_ACTIVE;
2761 gtk_paint_extension(widget->style, widget->window,
2762 state_type, GTK_SHADOW_OUT,
2763 area, widget, "tab",
2764 page_area.x, page_area.y,
2765 page_area.width, page_area.height,
2767 if ((GTK_WIDGET_HAS_FOCUS (widget)) &&
2768 notebook->focus_tab && (notebook->focus_tab->data == page))
2772 gtk_widget_style_get (widget, "focus-line-width", &focus_width, NULL);
2774 gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget),
2775 area, widget, "tab",
2776 page->tab_label->allocation.x - focus_width,
2777 page->tab_label->allocation.y - focus_width,
2778 page->tab_label->allocation.width + 2 * focus_width,
2779 page->tab_label->allocation.height + 2 * focus_width);
2781 if (gtk_widget_intersect (page->tab_label, area, &child_area) &&
2782 GTK_WIDGET_DRAWABLE (page->tab_label))
2784 GdkEvent *expose_event = gdk_event_new (GDK_EXPOSE);
2786 /* This is a lame hack since all this code needs rewriting anyhow */
2788 expose_event->expose.window = g_object_ref (page->tab_label->window);
2789 expose_event->expose.area = child_area;
2790 expose_event->expose.region = gdk_region_rectangle (&child_area);
2791 expose_event->expose.send_event = TRUE;
2792 expose_event->expose.count = 0;
2794 gtk_container_propagate_expose (GTK_CONTAINER (notebook), page->tab_label, (GdkEventExpose *)expose_event);
2796 gdk_event_free (expose_event);
2802 gtk_notebook_draw_arrow (GtkNotebook *notebook,
2805 GtkStateType state_type;
2806 GtkShadowType shadow_type;
2808 GdkRectangle arrow_rect;
2810 gtk_notebook_get_arrow_rect (notebook, &arrow_rect);
2812 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
2814 widget = GTK_WIDGET(notebook);
2816 if (GTK_WIDGET_DRAWABLE (notebook))
2818 if (notebook->in_child == arrow)
2820 if (notebook->click_child == arrow)
2821 state_type = GTK_STATE_ACTIVE;
2823 state_type = GTK_STATE_PRELIGHT;
2826 state_type = GTK_STATE_NORMAL;
2828 if (notebook->click_child == arrow)
2829 shadow_type = GTK_SHADOW_IN;
2831 shadow_type = GTK_SHADOW_OUT;
2833 if (arrow == GTK_ARROW_LEFT)
2835 if (notebook->focus_tab &&
2836 !gtk_notebook_search_page (notebook, notebook->focus_tab,
2839 shadow_type = GTK_SHADOW_ETCHED_IN;
2840 state_type = GTK_STATE_INSENSITIVE;
2843 if (notebook->tab_pos == GTK_POS_LEFT ||
2844 notebook->tab_pos == GTK_POS_RIGHT)
2845 arrow = GTK_ARROW_UP;
2847 gtk_paint_arrow (widget->style, widget->window, state_type,
2848 shadow_type, NULL, GTK_WIDGET(notebook), "notebook",
2850 arrow_rect.x, arrow_rect.y, ARROW_SIZE, ARROW_SIZE);
2854 if (notebook->focus_tab &&
2855 !gtk_notebook_search_page (notebook, notebook->focus_tab,
2858 shadow_type = GTK_SHADOW_ETCHED_IN;
2859 state_type = GTK_STATE_INSENSITIVE;
2862 if (notebook->tab_pos == GTK_POS_LEFT ||
2863 notebook->tab_pos == GTK_POS_RIGHT)
2864 arrow = GTK_ARROW_DOWN;
2866 gtk_paint_arrow (widget->style, widget->window, state_type,
2867 shadow_type, NULL, GTK_WIDGET(notebook), "notebook",
2868 arrow, TRUE, arrow_rect.x + ARROW_SIZE + ARROW_SPACING,
2869 arrow_rect.y, ARROW_SIZE, ARROW_SIZE);
2874 /* Private GtkNotebook Size Allocate Functions:
2876 * gtk_notebook_pages_allocate
2877 * gtk_notebook_page_allocate
2878 * gtk_notebook_calc_tabs
2881 gtk_notebook_pages_allocate (GtkNotebook *notebook)
2883 GtkWidget *widget = GTK_WIDGET (notebook);
2884 GtkContainer *container = GTK_CONTAINER (notebook);
2885 GtkNotebookPage *page = NULL;
2886 GtkAllocation *allocation = &widget->allocation;
2887 GtkAllocation child_allocation;
2888 GList *children = NULL;
2889 GList *last_child = NULL;
2890 gboolean showarrow = FALSE;
2900 if (!notebook->show_tabs || !notebook->children || !notebook->cur_page)
2903 child_allocation.x = widget->allocation.x + container->border_width;
2904 child_allocation.y = widget->allocation.y + container->border_width;
2906 switch (notebook->tab_pos)
2908 case GTK_POS_BOTTOM:
2909 child_allocation.y = (widget->allocation.y +
2910 allocation->height -
2911 notebook->cur_page->requisition.height -
2912 container->border_width);
2915 child_allocation.height = notebook->cur_page->requisition.height;
2919 child_allocation.x = (widget->allocation.x +
2921 notebook->cur_page->requisition.width -
2922 container->border_width);
2925 child_allocation.width = notebook->cur_page->requisition.width;
2929 if (notebook->scrollable)
2933 children = notebook->children;
2935 if (notebook->focus_tab)
2936 focus_tab = notebook->focus_tab;
2937 else if (notebook->first_tab)
2938 focus_tab = notebook->first_tab;
2940 focus_tab = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, TRUE);
2942 switch (notebook->tab_pos)
2945 case GTK_POS_BOTTOM:
2948 page = children->data;
2949 children = children->next;
2951 if (GTK_WIDGET_VISIBLE (page->child))
2952 tab_space += page->requisition.width;
2955 allocation->width - 2 * container->border_width - TAB_OVERLAP)
2958 page = focus_tab->data;
2960 tab_space = (allocation->width - TAB_OVERLAP -
2961 page->requisition.width -
2962 2 * (container->border_width + ARROW_SPACING +
2964 x = (allocation->width - 2 * ARROW_SIZE - ARROW_SPACING -
2965 container->border_width);
2967 page = notebook->children->data;
2968 if (notebook->tab_pos == GTK_POS_TOP)
2969 y = (container->border_width +
2970 (page->requisition.height - ARROW_SIZE) / 2);
2972 y = (allocation->height - container->border_width -
2973 ARROW_SIZE - (page->requisition.height - ARROW_SIZE) / 2);
2980 page = children->data;
2981 children = children->next;
2983 if (GTK_WIDGET_VISIBLE (page->child))
2984 tab_space += page->requisition.height;
2987 (allocation->height - 2 * container->border_width - TAB_OVERLAP))
2990 page = focus_tab->data;
2991 tab_space = (allocation->height -
2992 ARROW_SIZE - ARROW_SPACING - TAB_OVERLAP -
2993 2 * container->border_width -
2994 page->requisition.height);
2995 y = allocation->height - container->border_width - ARROW_SIZE;
2997 page = notebook->children->data;
2998 if (notebook->tab_pos == GTK_POS_LEFT)
2999 x = (container->border_width +
3000 (page->requisition.width -
3001 (2 * ARROW_SIZE - ARROW_SPACING)) / 2);
3003 x = (allocation->width - container->border_width -
3004 (2 * ARROW_SIZE - ARROW_SPACING) -
3005 (page->requisition.width -
3006 (2 * ARROW_SIZE - ARROW_SPACING)) / 2);
3010 if (showarrow) /* first_tab <- focus_tab */
3014 notebook->first_tab = focus_tab;
3015 last_child = gtk_notebook_search_page (notebook, focus_tab,
3021 if (notebook->first_tab && notebook->first_tab != focus_tab)
3023 /* Is first_tab really predecessor of focus_tab ? */
3024 page = notebook->first_tab->data;
3025 if (GTK_WIDGET_VISIBLE (page->child))
3026 for (children = focus_tab;
3027 children && children != notebook->first_tab;
3028 children = gtk_notebook_search_page (notebook,
3034 notebook->first_tab = focus_tab;
3036 gtk_notebook_calc_tabs (notebook,
3037 gtk_notebook_search_page (notebook,
3041 &(notebook->first_tab), &tab_space,
3046 notebook->first_tab =
3047 gtk_notebook_search_page (notebook, notebook->first_tab,
3049 if (!notebook->first_tab)
3050 notebook->first_tab = focus_tab;
3051 last_child = gtk_notebook_search_page (notebook, focus_tab,
3054 else /* focus_tab -> end */
3056 if (!notebook->first_tab)
3057 notebook->first_tab = gtk_notebook_search_page (notebook,
3062 gtk_notebook_calc_tabs (notebook,
3063 gtk_notebook_search_page (notebook,
3067 &children, &tab_space, STEP_NEXT);
3070 last_child = children;
3071 else /* start <- first_tab */
3075 gtk_notebook_calc_tabs
3077 gtk_notebook_search_page (notebook,
3078 notebook->first_tab,
3081 &children, &tab_space, STEP_PREV);
3082 notebook->first_tab = gtk_notebook_search_page(notebook,
3092 tab_space = -tab_space;
3094 for (children = notebook->first_tab;
3095 children && children != last_child;
3096 children = gtk_notebook_search_page (notebook, children,
3103 /*unmap all non-visible tabs*/
3104 for (children = gtk_notebook_search_page (notebook, NULL,
3106 children && children != notebook->first_tab;
3107 children = gtk_notebook_search_page (notebook, children,
3110 page = children->data;
3111 if (page->tab_label)
3112 gtk_widget_set_child_visible (page->tab_label, FALSE);
3114 for (children = last_child; children;
3115 children = gtk_notebook_search_page (notebook, children,
3118 page = children->data;
3119 if (page->tab_label)
3120 gtk_widget_set_child_visible (page->tab_label, FALSE);
3123 else /* !showarrow */
3125 notebook->first_tab = gtk_notebook_search_page (notebook, NULL,
3136 children = notebook->children;
3137 switch (notebook->tab_pos)
3140 case GTK_POS_BOTTOM:
3143 page = children->data;
3144 children = children->next;
3146 if (GTK_WIDGET_VISIBLE (page->child))
3149 tab_space += page->requisition.width;
3154 tab_space -= allocation->width;
3160 page = children->data;
3161 children = children->next;
3163 if (GTK_WIDGET_VISIBLE (page->child))
3166 tab_space += page->requisition.height;
3171 tab_space -= allocation->height;
3173 tab_space += 2 * container->border_width + TAB_OVERLAP;
3175 notebook->first_tab = gtk_notebook_search_page (notebook, NULL,
3177 if (notebook->homogeneous && n)
3181 children = notebook->first_tab;
3185 if (children == last_child)
3187 /* FIXME double check */
3191 page = children->data;
3192 if (!showarrow && page->pack != GTK_PACK_START)
3194 children = gtk_notebook_search_page (notebook, children, STEP_NEXT,TRUE);
3197 if (n && (showarrow || page->expand || notebook->homogeneous))
3199 new_fill = (tab_space * i++) / n;
3200 delta = new_fill - old_fill;
3201 old_fill = new_fill;
3204 switch (notebook->tab_pos)
3207 case GTK_POS_BOTTOM:
3208 child_allocation.width = (page->requisition.width +
3209 TAB_OVERLAP + delta);
3213 child_allocation.height = (page->requisition.height +
3214 TAB_OVERLAP + delta);
3218 gtk_notebook_page_allocate (notebook, page, &child_allocation);
3220 switch (notebook->tab_pos)
3223 case GTK_POS_BOTTOM:
3224 child_allocation.x += child_allocation.width - TAB_OVERLAP;
3228 child_allocation.y += child_allocation.height - TAB_OVERLAP;
3232 if (page->tab_label)
3233 gtk_widget_set_child_visible (page->tab_label, TRUE);
3238 children = notebook->children;
3239 switch (notebook->tab_pos)
3242 case GTK_POS_BOTTOM:
3243 child_allocation.x = (allocation->x + allocation->width -
3244 container->border_width);
3248 child_allocation.y = (allocation->y + allocation->height -
3249 container->border_width);
3253 while (children != last_child)
3255 page = children->data;
3256 children = children->next;
3258 if (page->pack != GTK_PACK_END || !GTK_WIDGET_VISIBLE (page->child))
3262 if (n && (page->expand || notebook->homogeneous))
3264 new_fill = (tab_space * i++) / n;
3265 delta = new_fill - old_fill;
3266 old_fill = new_fill;
3269 switch (notebook->tab_pos)
3272 case GTK_POS_BOTTOM:
3273 child_allocation.width = (page->requisition.width +
3274 TAB_OVERLAP + delta);
3275 child_allocation.x -= child_allocation.width;
3279 child_allocation.height = (page->requisition.height +
3280 TAB_OVERLAP + delta);
3281 child_allocation.y -= child_allocation.height;
3285 gtk_notebook_page_allocate (notebook, page, &child_allocation);
3287 switch (notebook->tab_pos)
3290 case GTK_POS_BOTTOM:
3291 child_allocation.x += TAB_OVERLAP;
3295 child_allocation.y += TAB_OVERLAP;
3299 if (page->tab_label)
3300 gtk_widget_set_child_visible (page->tab_label, TRUE);
3305 gtk_notebook_redraw_tabs (notebook);
3309 gtk_notebook_page_allocate (GtkNotebook *notebook,
3310 GtkNotebookPage *page,
3311 GtkAllocation *allocation)
3313 GtkWidget *widget = GTK_WIDGET (notebook);
3314 GtkAllocation child_allocation;
3315 GtkRequisition tab_requisition;
3321 gtk_widget_style_get (widget, "focus-line-width", &focus_width, NULL);
3323 xthickness = widget->style->xthickness;
3324 ythickness = widget->style->ythickness;
3326 /* If the size of the notebook tabs change, we need to queue
3327 * a redraw on the tab area
3329 if ((allocation->width != page->allocation.width) ||
3330 (allocation->height != page->allocation.height))
3332 gint x, y, width, height, border_width;
3334 border_width = GTK_CONTAINER (notebook)->border_width;
3336 switch (notebook->tab_pos)
3339 width = widget->allocation.width;
3340 height = MAX (page->allocation.height, allocation->height) + ythickness;
3345 case GTK_POS_BOTTOM:
3346 width = widget->allocation.width + xthickness;
3347 height = MAX (page->allocation.height, allocation->height) + ythickness;
3349 y = widget->allocation.height - height - border_width;
3353 width = MAX (page->allocation.width, allocation->width) + xthickness;
3354 height = widget->allocation.height;
3360 default: /* quiet gcc */
3361 width = MAX (page->allocation.width, allocation->width) + xthickness;
3362 height = widget->allocation.height;
3363 x = widget->allocation.width - width - border_width;
3368 gtk_widget_queue_draw_area (widget, x, y, width, height);
3371 page->allocation = *allocation;
3372 gtk_widget_get_child_requisition (page->tab_label, &tab_requisition);
3374 if (notebook->cur_page != page)
3376 switch (notebook->tab_pos)
3379 page->allocation.y += ythickness;
3380 case GTK_POS_BOTTOM:
3381 if (page->allocation.height > ythickness)
3382 page->allocation.height -= ythickness;
3385 page->allocation.x += xthickness;
3387 if (page->allocation.width > xthickness)
3388 page->allocation.width -= xthickness;
3393 switch (notebook->tab_pos)
3396 case GTK_POS_BOTTOM:
3397 padding = TAB_CURVATURE + focus_width + notebook->tab_hborder;
3400 child_allocation.x = (xthickness + focus_width +
3401 notebook->tab_hborder);
3402 child_allocation.width = MAX (1, (page->allocation.width -
3403 2 * child_allocation.x));
3404 child_allocation.x += page->allocation.x;
3408 child_allocation.x = (page->allocation.x +
3409 (page->allocation.width -
3410 tab_requisition.width) / 2);
3411 child_allocation.width = tab_requisition.width;
3413 child_allocation.y = (notebook->tab_vborder + focus_width +
3414 page->allocation.y);
3415 if (notebook->tab_pos == GTK_POS_TOP)
3416 child_allocation.y += ythickness;
3417 child_allocation.height = MAX (1, (((gint) page->allocation.height) - ythickness -
3418 2 * (notebook->tab_vborder + focus_width)));
3422 padding = TAB_CURVATURE + focus_width + notebook->tab_vborder;
3425 child_allocation.y = ythickness + padding;
3426 child_allocation.height = MAX (1, (page->allocation.height -
3427 2 * child_allocation.y));
3428 child_allocation.y += page->allocation.y;
3432 child_allocation.y = (page->allocation.y + (page->allocation.height -
3433 tab_requisition.height) / 2);
3434 child_allocation.height = tab_requisition.height;
3436 child_allocation.x = page->allocation.x + notebook->tab_hborder + focus_width;
3437 if (notebook->tab_pos == GTK_POS_LEFT)
3438 child_allocation.x += xthickness;
3439 child_allocation.width = MAX (1, (((gint) page->allocation.width) - xthickness -
3440 2 * (notebook->tab_hborder + focus_width)));
3444 if (page->tab_label)
3445 gtk_widget_size_allocate (page->tab_label, &child_allocation);
3449 gtk_notebook_calc_tabs (GtkNotebook *notebook,
3455 GtkNotebookPage *page = NULL;
3457 GList *last_list = NULL;
3464 pack = GTK_NOTEBOOK_PAGE (start)->pack;
3465 if (pack == GTK_PACK_END)
3466 direction = (direction == STEP_PREV) ? STEP_NEXT : STEP_PREV;
3470 switch (notebook->tab_pos)
3473 case GTK_POS_BOTTOM:
3476 page = children->data;
3477 if (GTK_WIDGET_VISIBLE (page->child))
3479 if (page->pack == pack)
3481 *tab_space -= page->requisition.width;
3482 if (*tab_space < 0 || children == *end)
3486 *tab_space = - (*tab_space +
3487 page->requisition.width);
3493 last_list = children;
3495 if (direction == STEP_NEXT)
3496 children = children->next;
3498 children = children->prev;
3505 page = children->data;
3506 if (GTK_WIDGET_VISIBLE (page->child))
3508 if (page->pack == pack)
3510 *tab_space -= page->requisition.height;
3511 if (*tab_space < 0 || children == *end)
3515 *tab_space = - (*tab_space +
3516 page->requisition.height);
3522 last_list = children;
3524 if (direction == STEP_NEXT)
3525 children = children->next;
3527 children = children->prev;
3531 if (direction == STEP_PREV)
3533 pack = (pack == GTK_PACK_END) ? GTK_PACK_START : GTK_PACK_END;
3534 direction = STEP_PREV;
3535 children = last_list;
3539 /* Private GtkNotebook Page Switch Methods:
3541 * gtk_notebook_real_switch_page
3544 gtk_notebook_real_switch_page (GtkNotebook *notebook,
3545 GtkNotebookPage *page,
3548 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
3549 g_return_if_fail (page != NULL);
3551 if (notebook->cur_page == page || !GTK_WIDGET_VISIBLE (page->child))
3554 if (notebook->cur_page)
3555 gtk_widget_set_child_visible (notebook->cur_page->child, FALSE);
3557 notebook->cur_page = page;
3559 if (!notebook->focus_tab ||
3560 notebook->focus_tab->data != (gpointer) notebook->cur_page)
3561 notebook->focus_tab =
3562 g_list_find (notebook->children, notebook->cur_page);
3564 gtk_widget_set_child_visible (notebook->cur_page->child, TRUE);
3566 /* If the focus was on the previous page, move it to the first
3567 * element on the new page, if possible, or if not, to the
3570 if (notebook->child_has_focus)
3572 if (notebook->cur_page->last_focus_child &&
3573 gtk_widget_is_ancestor (notebook->cur_page->last_focus_child, notebook->cur_page->child))
3574 gtk_widget_grab_focus (notebook->cur_page->last_focus_child);
3576 if (!gtk_widget_child_focus (notebook->cur_page->child, GTK_DIR_TAB_FORWARD))
3577 gtk_widget_grab_focus (GTK_WIDGET (notebook));
3580 gtk_widget_queue_resize (GTK_WIDGET (notebook));
3581 g_object_notify (G_OBJECT (notebook), "page");
3584 /* Private GtkNotebook Page Switch Functions:
3586 * gtk_notebook_switch_page
3587 * gtk_notebook_page_select
3588 * gtk_notebook_switch_focus_tab
3589 * gtk_notebook_menu_switch_page
3592 gtk_notebook_switch_page (GtkNotebook *notebook,
3593 GtkNotebookPage *page,
3596 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
3597 g_return_if_fail (page != NULL);
3599 if (notebook->cur_page == page)
3603 page_num = g_list_index (notebook->children, page);
3605 g_signal_emit (notebook,
3606 notebook_signals[SWITCH_PAGE],
3613 gtk_notebook_page_select (GtkNotebook *notebook,
3614 gboolean move_focus)
3616 GtkNotebookPage *page;
3617 GtkDirectionType dir = GTK_DIR_DOWN; /* Quiet GCC */
3619 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
3621 if (!notebook->focus_tab)
3624 page = notebook->focus_tab->data;
3625 gtk_notebook_switch_page (notebook, page, -1);
3629 switch (notebook->tab_pos)
3634 case GTK_POS_BOTTOM:
3638 dir = GTK_DIR_RIGHT;
3645 if (gtk_widget_child_focus (page->child, dir))
3652 gtk_notebook_switch_focus_tab (GtkNotebook *notebook,
3656 GtkNotebookPage *old_page = NULL;
3657 GtkNotebookPage *page;
3659 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
3661 if (notebook->focus_tab == new_child)
3664 old_child = notebook->focus_tab;
3665 notebook->focus_tab = new_child;
3667 if (notebook->scrollable)
3668 gtk_notebook_redraw_arrows (notebook);
3670 if (!notebook->show_tabs || !notebook->focus_tab)
3674 old_page = old_child->data;
3676 page = notebook->focus_tab->data;
3677 if (GTK_WIDGET_MAPPED (page->tab_label))
3678 gtk_notebook_focus_changed (notebook, old_page);
3680 gtk_notebook_pages_allocate (notebook);
3684 gtk_notebook_menu_switch_page (GtkWidget *widget,
3685 GtkNotebookPage *page)
3687 GtkNotebook *notebook;
3691 g_return_if_fail (widget != NULL);
3692 g_return_if_fail (page != NULL);
3694 notebook = GTK_NOTEBOOK (gtk_menu_get_attach_widget
3695 (GTK_MENU (widget->parent)));
3697 if (notebook->cur_page == page)
3701 children = notebook->children;
3702 while (children && children->data != page)
3704 children = children->next;
3708 g_signal_emit (notebook,
3709 notebook_signals[SWITCH_PAGE],
3715 /* Private GtkNotebook Menu Functions:
3717 * gtk_notebook_menu_item_create
3718 * gtk_notebook_menu_label_unparent
3719 * gtk_notebook_menu_detacher
3722 gtk_notebook_menu_item_create (GtkNotebook *notebook,
3725 GtkNotebookPage *page;
3726 GtkWidget *menu_item;
3729 if (page->default_menu)
3731 if (page->tab_label && GTK_IS_LABEL (page->tab_label))
3732 page->menu_label = gtk_label_new (GTK_LABEL (page->tab_label)->label);
3734 page->menu_label = gtk_label_new ("");
3735 gtk_misc_set_alignment (GTK_MISC (page->menu_label), 0.0, 0.5);
3738 gtk_widget_show (page->menu_label);
3739 menu_item = gtk_menu_item_new ();
3740 gtk_container_add (GTK_CONTAINER (menu_item), page->menu_label);
3741 gtk_menu_shell_insert (GTK_MENU_SHELL (notebook->menu), menu_item,
3742 gtk_notebook_real_page_position (notebook, list));
3743 g_signal_connect (menu_item, "activate",
3744 G_CALLBACK (gtk_notebook_menu_switch_page), page);
3745 if (GTK_WIDGET_VISIBLE (page->child))
3746 gtk_widget_show (menu_item);
3750 gtk_notebook_menu_label_unparent (GtkWidget *widget,
3753 gtk_widget_unparent (GTK_BIN(widget)->child);
3754 GTK_BIN(widget)->child = NULL;
3758 gtk_notebook_menu_detacher (GtkWidget *widget,
3761 GtkNotebook *notebook;
3763 g_return_if_fail (GTK_IS_NOTEBOOK (widget));
3765 notebook = GTK_NOTEBOOK (widget);
3766 g_return_if_fail (notebook->menu == (GtkWidget*) menu);
3768 notebook->menu = NULL;
3771 /* Public GtkNotebook Page Insert/Remove Methods :
3773 * gtk_notebook_append_page
3774 * gtk_notebook_append_page_menu
3775 * gtk_notebook_prepend_page
3776 * gtk_notebook_prepend_page_menu
3777 * gtk_notebook_insert_page
3778 * gtk_notebook_insert_page_menu
3779 * gtk_notebook_remove_page
3782 * gtk_notebook_append_page:
3783 * @notebook: a #GtkNotebook
3784 * @child: the #GtkWidget to use as the contents of the page.
3785 * @tab_label: the #GtkWidget to be used as the label for the page,
3786 * or %NULL to use the default label, 'page N'.
3788 * Appends a page to @notebook.
3791 gtk_notebook_append_page (GtkNotebook *notebook,
3793 GtkWidget *tab_label)
3795 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
3796 g_return_if_fail (GTK_IS_WIDGET (child));
3797 g_return_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label));
3799 gtk_notebook_insert_page_menu (notebook, child, tab_label, NULL, -1);
3803 * gtk_notebook_append_page_menu:
3804 * @notebook: a #GtkNotebook
3805 * @child: the #GtkWidget to use as the contents of the page.
3806 * @tab_label: the #GtkWidget to be used as the label for the page,
3807 * or %NULL to use the default label, 'page N'.
3808 * @menu_label: the widget to use as a label for the page-switch
3809 * menu, if that is enabled. If %NULL, and @tab_label
3810 * is a #GtkLabel or %NULL, then the menu label will be
3811 * a newly created label with the same text as @tab_label;
3812 * If @tab_label is not a #GtkLabel, @menu_label must be
3813 * specified if the page-switch menu is to be used.
3815 * Appends a page to @notebook, specifying the widget to use as the
3816 * label in the popup menu.
3819 gtk_notebook_append_page_menu (GtkNotebook *notebook,
3821 GtkWidget *tab_label,
3822 GtkWidget *menu_label)
3824 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
3825 g_return_if_fail (GTK_IS_WIDGET (child));
3826 g_return_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label));
3827 g_return_if_fail (menu_label == NULL || GTK_IS_WIDGET (menu_label));
3829 gtk_notebook_insert_page_menu (notebook, child, tab_label, menu_label, -1);
3833 * gtk_notebook_prepend_page:
3834 * @notebook: a #GtkNotebook
3835 * @child: the #GtkWidget to use as the contents of the page.
3836 * @tab_label: the #GtkWidget to be used as the label for the page,
3837 * or %NULL to use the default label, 'page N'.
3839 * Prepends a page to @notebook.
3842 gtk_notebook_prepend_page (GtkNotebook *notebook,
3844 GtkWidget *tab_label)
3846 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
3847 g_return_if_fail (GTK_IS_WIDGET (child));
3848 g_return_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label));
3850 gtk_notebook_insert_page_menu (notebook, child, tab_label, NULL, 0);
3854 * gtk_notebook_prepend_page_menu:
3855 * @notebook: a #GtkNotebook
3856 * @child: the #GtkWidget to use as the contents of the page.
3857 * @tab_label: the #GtkWidget to be used as the label for the page,
3858 * or %NULL to use the default label, 'page N'.
3859 * @menu_label: the widget to use as a label for the page-switch
3860 * menu, if that is enabled. If %NULL, and @tab_label
3861 * is a #GtkLabel or %NULL, then the menu label will be
3862 * a newly created label with the same text as @tab_label;
3863 * If @tab_label is not a #GtkLabel, @menu_label must be
3864 * specified if the page-switch menu is to be used.
3866 * Prepends a page to @notebook, specifying the widget to use as the
3867 * label in the popup menu.
3870 gtk_notebook_prepend_page_menu (GtkNotebook *notebook,
3872 GtkWidget *tab_label,
3873 GtkWidget *menu_label)
3875 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
3876 g_return_if_fail (GTK_IS_WIDGET (child));
3877 g_return_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label));
3878 g_return_if_fail (menu_label == NULL || GTK_IS_WIDGET (menu_label));
3880 gtk_notebook_insert_page_menu (notebook, child, tab_label, menu_label, 0);
3884 * gtk_notebook_insert_page:
3885 * @notebook: a #GtkNotebook
3886 * @child: the #GtkWidget to use as the contents of the page.
3887 * @tab_label: the #GtkWidget to be used as the label for the page,
3888 * or %NULL to use the default label, 'page N'.
3889 * @position: the index (starting at 0) at which to insert the page,
3890 * or -1 to append the page after all other pages.
3892 * Insert a page into @notebook at the given position
3895 gtk_notebook_insert_page (GtkNotebook *notebook,
3897 GtkWidget *tab_label,
3900 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
3901 g_return_if_fail (GTK_IS_WIDGET (child));
3902 g_return_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label));
3904 gtk_notebook_insert_page_menu (notebook, child, tab_label, NULL, position);
3909 gtk_notebook_page_compare_tab (gconstpointer a,
3912 return (((GtkNotebookPage *) a)->tab_label != b);
3916 gtk_notebook_mnemonic_activate_switch_page (GtkWidget *child,
3920 GtkNotebook *notebook = GTK_NOTEBOOK (data);
3923 list = g_list_find_custom (notebook->children, child,
3924 gtk_notebook_page_compare_tab);
3927 GtkNotebookPage *page = list->data;
3929 gtk_widget_grab_focus (GTK_WIDGET (notebook)); /* Do this first to avoid focusing new page */
3930 gtk_notebook_switch_page (notebook, page, -1);
3931 focus_tabs_in (notebook);
3938 * gtk_notebook_insert_page_menu:
3939 * @notebook: a #GtkNotebook
3940 * @child: the #GtkWidget to use as the contents of the page.
3941 * @tab_label: the #GtkWidget to be used as the label for the page,
3942 * or %NULL to use the default label, 'page N'.
3943 * @menu_label: the widget to use as a label for the page-switch
3944 * menu, if that is enabled. If %NULL, and @tab_label
3945 * is a #GtkLabel or %NULL, then the menu label will be
3946 * a newly created label with the same text as @tab_label;
3947 * If @tab_label is not a #GtkLabel, @menu_label must be
3948 * specified if the page-switch menu is to be used.
3949 * @position: the index (starting at 0) at which to insert the page,
3950 * or -1 to append the page after all other pages.
3952 * Insert a page into @notebook at the given position, specifying
3953 * the widget to use as the label in the popup menu.
3956 gtk_notebook_insert_page_menu (GtkNotebook *notebook,
3958 GtkWidget *tab_label,
3959 GtkWidget *menu_label,
3962 GtkNotebookPage *page;
3965 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
3966 g_return_if_fail (GTK_IS_WIDGET (child));
3967 g_return_if_fail (tab_label == NULL || GTK_IS_WIDGET (tab_label));
3968 g_return_if_fail (menu_label == NULL || GTK_IS_WIDGET (menu_label));
3970 gtk_widget_freeze_child_notify (child);
3972 page = g_new (GtkNotebookPage, 1);
3973 page->child = child;
3974 page->last_focus_child = NULL;
3975 page->requisition.width = 0;
3976 page->requisition.height = 0;
3977 page->allocation.x = 0;
3978 page->allocation.y = 0;
3979 page->allocation.width = 0;
3980 page->allocation.height = 0;
3981 page->default_menu = FALSE;
3982 page->default_tab = FALSE;
3983 page->mnemonic_activate_signal = 0;
3985 nchildren = g_list_length (notebook->children);
3986 if ((position < 0) || (position > nchildren))
3987 position = nchildren;
3989 notebook->children = g_list_insert (notebook->children, page, position);
3993 page->default_tab = TRUE;
3994 if (notebook->show_tabs)
3995 tab_label = gtk_label_new ("");
3997 page->tab_label = tab_label;
3998 page->menu_label = menu_label;
3999 page->expand = FALSE;
4001 page->pack = GTK_PACK_START;
4004 page->default_menu = TRUE;
4007 g_object_ref (page->menu_label);
4008 gtk_object_sink (GTK_OBJECT (page->menu_label));
4012 gtk_notebook_menu_item_create (notebook,
4013 g_list_find (notebook->children, page));
4015 gtk_widget_set_parent (child, GTK_WIDGET (notebook));
4017 gtk_widget_set_parent (tab_label, GTK_WIDGET (notebook));
4019 gtk_notebook_update_labels (notebook);
4021 if (!notebook->first_tab)
4022 notebook->first_tab = notebook->children;
4024 if (!notebook->cur_page)
4025 gtk_widget_set_child_visible (child, TRUE);
4027 gtk_widget_set_child_visible (child, FALSE);
4031 if (notebook->show_tabs && GTK_WIDGET_VISIBLE (child))
4032 gtk_widget_show (tab_label);
4034 gtk_widget_hide (tab_label);
4037 if (!notebook->cur_page)
4039 gtk_notebook_switch_page (notebook, page, 0);
4040 gtk_notebook_switch_focus_tab (notebook, NULL);
4044 page->mnemonic_activate_signal =
4045 g_signal_connect (tab_label,
4046 "mnemonic_activate",
4047 G_CALLBACK (gtk_notebook_mnemonic_activate_switch_page),
4050 if (notebook->show_tabs && GTK_WIDGET_MAPPED (notebook))
4051 gdk_window_show_unraised (notebook->event_window);
4053 gtk_widget_child_notify (child, "tab_expand");
4054 gtk_widget_child_notify (child, "tab_fill");
4055 gtk_widget_child_notify (child, "tab_pack");
4056 gtk_widget_child_notify (child, "tab_label");
4057 gtk_widget_child_notify (child, "menu_label");
4058 gtk_widget_child_notify (child, "position");
4059 gtk_widget_thaw_child_notify (child);
4063 * gtk_notebook_remove_page:
4064 * @notebook: a #GtkNotebook.
4065 * @page_num: the index of a notebook page, starting
4066 * from 0. If -1, the last page will
4069 * Removes a page from the notebook given its index
4073 gtk_notebook_remove_page (GtkNotebook *notebook,
4078 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4082 list = g_list_nth (notebook->children, page_num);
4084 gtk_notebook_real_remove (notebook, list);
4088 list = g_list_last (notebook->children);
4090 gtk_notebook_real_remove (notebook, list);
4094 /* Public GtkNotebook Page Switch Methods :
4095 * gtk_notebook_get_current_page
4096 * gtk_notebook_page_num
4097 * gtk_notebook_set_current_page
4098 * gtk_notebook_next_page
4099 * gtk_notebook_prev_page
4102 * gtk_notebook_get_current_page:
4103 * @notebook: a #GtkNotebook
4105 * Returns the page number of the current page.
4107 * Return value: the index (starting from 0) of the current
4108 * page in the notebook. If the notebook has no pages, then
4109 * -1 will be returned.
4112 gtk_notebook_get_current_page (GtkNotebook *notebook)
4114 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
4116 if (!notebook->cur_page)
4119 return g_list_index (notebook->children, notebook->cur_page);
4123 * gtk_notebook_get_nth_page:
4124 * @notebook: a #GtkNotebook
4125 * @page_num: the index of a page in the noteobok, or -1
4126 * to get the last page.
4128 * Returns the child widget contained in page number @page_num.
4130 * Return value: the child widget, or %NULL if @page_num is
4134 gtk_notebook_get_nth_page (GtkNotebook *notebook,
4137 GtkNotebookPage *page;
4140 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
4143 list = g_list_nth (notebook->children, page_num);
4145 list = g_list_last (notebook->children);
4157 * gtk_notebook_get_nth_page:
4158 * @notebook: a #GtkNotebook
4160 * Gets the number of pages in a notebook.
4162 * Return value: the number of pages in the notebook.
4165 gtk_notebook_get_n_pages (GtkNotebook *notebook)
4167 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), 0);
4169 return g_list_length (notebook->children);
4173 * gtk_notebook_page_num:
4174 * @notebook: a #GtkNotebook
4175 * @child: a #GtkWidget
4177 * Finds the index of the page which contains the given child
4180 * Return value: the index of the page containing @child, or
4181 * -1 if @child is not in the notebook.
4184 gtk_notebook_page_num (GtkNotebook *notebook,
4190 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
4193 children = notebook->children;
4196 GtkNotebookPage *page = children->data;
4198 if (page->child == child)
4201 children = children->next;
4209 * gtk_notebook_set_current_page:
4210 * @notebook: a #GtkNotebook
4211 * @page_num: index of the page to switch to, starting from 0.
4212 * If negative, the last page will be used. If greater
4213 * than the number of pages in the notebook, nothing
4216 * Switches to the page number @page_num.
4219 gtk_notebook_set_current_page (GtkNotebook *notebook,
4224 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4227 list = g_list_nth (notebook->children, page_num);
4229 list = g_list_last (notebook->children);
4231 page_num = g_list_index (notebook->children, list);
4234 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (list), page_num);
4238 * gtk_notebook_next_page:
4239 * @notebook: a #GtkNotebook
4241 * Switches to the next page. Nothing happens if the current page is
4245 gtk_notebook_next_page (GtkNotebook *notebook)
4249 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4251 list = g_list_find (notebook->children, notebook->cur_page);
4255 list = gtk_notebook_search_page (notebook, list, STEP_NEXT, TRUE);
4259 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (list), -1);
4263 * gtk_notebook_prev_page:
4264 * @notebook: a #GtkNotebook
4266 * Switches to the previous page. Nothing happens if the current page
4267 * is the first page.
4270 gtk_notebook_prev_page (GtkNotebook *notebook)
4274 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4276 list = g_list_find (notebook->children, notebook->cur_page);
4280 list = gtk_notebook_search_page (notebook, list, STEP_PREV, TRUE);
4284 gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (list), -1);
4287 /* Public GtkNotebook/Tab Style Functions
4289 * gtk_notebook_set_show_border
4290 * gtk_notebook_set_show_tabs
4291 * gtk_notebook_set_tab_pos
4292 * gtk_notebook_set_homogeneous_tabs
4293 * gtk_notebook_set_tab_border
4294 * gtk_notebook_set_tab_hborder
4295 * gtk_notebook_set_tab_vborder
4296 * gtk_notebook_set_scrollable
4299 * gtk_notebook_set_show_border:
4300 * @notebook: a #GtkNotebook
4301 * @show_border: %TRUE if a bevel should be drawn around the notebook.
4303 * Sets whether a bevel will be drawn around the notebook pages.
4304 * This only has a visual effect when the tabs are not shown.
4305 * See gtk_notebook_set_show_tabs().
4308 gtk_notebook_set_show_border (GtkNotebook *notebook,
4309 gboolean show_border)
4311 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4313 if (notebook->show_border != show_border)
4315 notebook->show_border = show_border;
4317 if (GTK_WIDGET_VISIBLE (notebook))
4318 gtk_widget_queue_resize (GTK_WIDGET (notebook));
4320 g_object_notify (G_OBJECT (notebook), "show_border");
4325 * gtk_notebook_get_show_border:
4326 * @notebook: a #GtkNotebook
4328 * Returns whether a bevel will be drawn around the notebook pages. See
4329 * gtk_notebook_set_show_border().
4331 * Return value: %TRUE if the bevel is drawn
4334 gtk_notebook_get_show_border (GtkNotebook *notebook)
4336 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
4338 return notebook->show_border;
4342 * gtk_notebook_set_show_tabs:
4343 * @notebook: a #GtkNotebook
4344 * @show_tabs: %TRUE if the tabs should be shown.
4346 * Sets whether to show the tabs for the notebook or not.
4349 gtk_notebook_set_show_tabs (GtkNotebook *notebook,
4352 GtkNotebookPage *page;
4355 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4357 show_tabs = show_tabs != FALSE;
4359 if (notebook->show_tabs == show_tabs)
4362 notebook->show_tabs = show_tabs;
4363 children = notebook->children;
4367 GTK_WIDGET_UNSET_FLAGS (notebook, GTK_CAN_FOCUS);
4371 page = children->data;
4372 children = children->next;
4373 if (page->default_tab)
4375 gtk_widget_destroy (page->tab_label);
4376 page->tab_label = NULL;
4379 gtk_widget_hide (page->tab_label);
4384 GTK_WIDGET_SET_FLAGS (notebook, GTK_CAN_FOCUS);
4385 gtk_notebook_update_labels (notebook);
4387 gtk_widget_queue_resize (GTK_WIDGET (notebook));
4389 g_object_notify (G_OBJECT (notebook), "show_tabs");
4393 * gtk_notebook_get_show_tabs:
4394 * @notebook: a #GtkNotebook
4396 * Returns whether the tabs of the notebook are shown. See
4397 * gtk_notebook_set_show_tabs().
4399 * Return value: %TRUE if the tabs are shown
4402 gtk_notebook_get_show_tabs (GtkNotebook *notebook)
4404 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
4406 return notebook->show_tabs;
4410 * gtk_notebook_set_tab_pos:
4411 * @notebook: a #GtkNotebook.
4412 * @pos: the edge to draw the tabs at.
4414 * Sets the edge at which the tabs for switching pages in the
4415 * notebook are drawn.
4418 gtk_notebook_set_tab_pos (GtkNotebook *notebook,
4419 GtkPositionType pos)
4421 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4423 if (notebook->tab_pos != pos)
4425 notebook->tab_pos = pos;
4426 if (GTK_WIDGET_VISIBLE (notebook))
4427 gtk_widget_queue_resize (GTK_WIDGET (notebook));
4430 g_object_notify (G_OBJECT (notebook), "tab_pos");
4434 * gtk_notebook_get_tab_pos:
4435 * @notebook: a #GtkNotebook
4437 * Gets the edge at which the tabs for switching pages in the
4438 * notebook are drawn.
4440 * Return value: the edge at which the tabs are drawn
4443 gtk_notebook_get_tab_pos (GtkNotebook *notebook)
4445 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), GTK_POS_TOP);
4447 return notebook->tab_pos;
4451 * gtk_notebook_set_homogeneous_tabs:
4452 * @notebook: a #GtkNotebook
4453 * @homogeneous: %TRUE if all tabs should be the same size.
4455 * Sets whether the tabs must have all the same size or not.
4458 gtk_notebook_set_homogeneous_tabs (GtkNotebook *notebook,
4459 gboolean homogeneous)
4461 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4463 if (homogeneous == notebook->homogeneous)
4466 notebook->homogeneous = homogeneous;
4467 gtk_widget_queue_resize (GTK_WIDGET (notebook));
4469 g_object_notify (G_OBJECT (notebook), "homogeneous");
4473 * gtk_notebook_set_tab_border:
4474 * @notebook: a #GtkNotebook
4475 * @border_width: width of the border around the tab labels.
4477 * Sets the width the border around the tab labels
4478 * in a notebook. This is equivalent to calling
4479 * gtk_notebook_set_tab_hborder (@notebook, @border_width) followed
4480 * by gtk_notebook_set_tab_vborder (@notebook, @border_width).
4483 gtk_notebook_set_tab_border (GtkNotebook *notebook,
4486 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4488 notebook->tab_hborder = border_width;
4489 notebook->tab_vborder = border_width;
4491 if (GTK_WIDGET_VISIBLE (notebook) && notebook->show_tabs)
4492 gtk_widget_queue_resize (GTK_WIDGET (notebook));
4494 g_object_freeze_notify (G_OBJECT (notebook));
4495 g_object_notify (G_OBJECT (notebook), "tab_hborder");
4496 g_object_notify (G_OBJECT (notebook), "tab_vborder");
4497 g_object_thaw_notify (G_OBJECT (notebook));
4502 * gtk_notebook_set_tab_hborder:
4503 * @notebook: a #GtkNotebook
4504 * @tab_hborder: width of the horizontal border of tab labels.
4506 * Sets the width of the horizontal border of tab labels.
4509 gtk_notebook_set_tab_hborder (GtkNotebook *notebook,
4512 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4514 if (notebook->tab_hborder == tab_hborder)
4517 notebook->tab_hborder = tab_hborder;
4519 if (GTK_WIDGET_VISIBLE (notebook) && notebook->show_tabs)
4520 gtk_widget_queue_resize (GTK_WIDGET (notebook));
4522 g_object_notify (G_OBJECT (notebook), "tab_hborder");
4526 * gtk_notebook_set_tab_vborder:
4527 * @notebook: a #GtkNotebook
4528 * @tab_vborder: width of the vertical border of tab labels.
4530 * Sets the width of the vertical border of tab labels.
4533 gtk_notebook_set_tab_vborder (GtkNotebook *notebook,
4536 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4538 if (notebook->tab_vborder == tab_vborder)
4541 notebook->tab_vborder = tab_vborder;
4543 if (GTK_WIDGET_VISIBLE (notebook) && notebook->show_tabs)
4544 gtk_widget_queue_resize (GTK_WIDGET (notebook));
4546 g_object_notify (G_OBJECT (notebook), "tab_vborder");
4550 * gtk_notebook_set_scrollable:
4551 * @notebook: a #GtkNotebook
4552 * @scrollable: %TRUE if scroll arrows should be added
4554 * Sets whether the tab label area will have arrows for scrolling if
4555 * there are too many tabs to fit in the area.
4558 gtk_notebook_set_scrollable (GtkNotebook *notebook,
4559 gboolean scrollable)
4561 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4563 scrollable = (scrollable != FALSE);
4565 if (scrollable != notebook->scrollable)
4567 notebook->scrollable = scrollable;
4569 if (GTK_WIDGET_VISIBLE (notebook))
4570 gtk_widget_queue_resize (GTK_WIDGET (notebook));
4572 g_object_notify (G_OBJECT (notebook), "scrollable");
4577 * gtk_notebook_get_scrollable:
4578 * @notebook: a #GtkNotebook
4580 * Returns whether the tab label area has arrows for scrolling. See
4581 * gtk_notebook_set_scrollable().
4583 * Return value: %TRUE if arrows for scrolling are present
4586 gtk_notebook_get_scrollable (GtkNotebook *notebook)
4588 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
4590 return notebook->scrollable;
4593 /* Public GtkNotebook Popup Menu Methods:
4595 * gtk_notebook_popup_enable
4596 * gtk_notebook_popup_disable
4601 * gtk_notebook_popup_enable:
4602 * @notebook: a #GtkNotebook
4604 * Enables the popup menu: if the user clicks with the right mouse button on
4605 * the bookmarks, a menu with all the pages will be popped up.
4608 gtk_notebook_popup_enable (GtkNotebook *notebook)
4612 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4617 notebook->menu = gtk_menu_new ();
4618 for (list = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, FALSE);
4620 list = gtk_notebook_search_page (notebook, list, STEP_NEXT, FALSE))
4621 gtk_notebook_menu_item_create (notebook, list);
4623 gtk_notebook_update_labels (notebook);
4624 gtk_menu_attach_to_widget (GTK_MENU (notebook->menu),
4625 GTK_WIDGET (notebook),
4626 gtk_notebook_menu_detacher);
4628 g_object_notify (G_OBJECT (notebook), "enable_popup");
4632 * gtk_notebook_popup_disable:
4633 * @notebook: a #GtkNotebook
4635 * Disables the popup menu.
4638 gtk_notebook_popup_disable (GtkNotebook *notebook)
4640 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4642 if (!notebook->menu)
4645 gtk_container_foreach (GTK_CONTAINER (notebook->menu),
4646 (GtkCallback) gtk_notebook_menu_label_unparent, NULL);
4647 gtk_widget_destroy (notebook->menu);
4649 g_object_notify (G_OBJECT (notebook), "enable_popup");
4652 /* Public GtkNotebook Page Properties Functions:
4654 * gtk_notebook_get_tab_label
4655 * gtk_notebook_set_tab_label
4656 * gtk_notebook_set_tab_label_text
4657 * gtk_notebook_get_menu_label
4658 * gtk_notebook_set_menu_label
4659 * gtk_notebook_set_menu_label_text
4660 * gtk_notebook_set_tab_label_packing
4661 * gtk_notebook_query_tab_label_packing
4665 * gtk_notebook_get_tab_label:
4666 * @notebook: a #GtkNotebook
4669 * Returns the tab label widget for the page @child. %NULL is returned
4670 * if @child is not in @notebook or if no tab label has specifically
4671 * been set for @child.
4673 * Return value: the tab label
4676 gtk_notebook_get_tab_label (GtkNotebook *notebook,
4681 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
4682 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
4684 list = CHECK_FIND_CHILD (notebook, child);
4688 if (GTK_NOTEBOOK_PAGE (list)->default_tab)
4691 return GTK_NOTEBOOK_PAGE (list)->tab_label;
4695 * gtk_notebook_set_tab_label:
4696 * @notebook: a #GtkNotebook
4698 * @tab_label: the tab label widget to use, or %NULL for default tab
4701 * Changes the tab label for @child. If %NULL is specified
4702 * for @tab_label, then the page will have the label 'page N'.
4705 gtk_notebook_set_tab_label (GtkNotebook *notebook,
4707 GtkWidget *tab_label)
4709 GtkNotebookPage *page;
4712 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4713 g_return_if_fail (GTK_IS_WIDGET (child));
4715 list = CHECK_FIND_CHILD (notebook, child);
4719 /* a NULL pointer indicates a default_tab setting, otherwise
4720 * we need to set the associated label
4724 if (page->tab_label == tab_label)
4728 gtk_notebook_remove_tab_label (notebook, page);
4732 page->default_tab = FALSE;
4733 page->tab_label = tab_label;
4734 gtk_widget_set_parent (page->tab_label, GTK_WIDGET (notebook));
4738 page->default_tab = TRUE;
4739 page->tab_label = NULL;
4741 if (notebook->show_tabs)
4745 g_snprintf (string, sizeof(string), _("Page %u"),
4746 gtk_notebook_real_page_position (notebook, list));
4747 page->tab_label = gtk_label_new (string);
4748 gtk_widget_set_parent (page->tab_label, GTK_WIDGET (notebook));
4752 if (page->tab_label)
4753 page->mnemonic_activate_signal =
4754 g_signal_connect (page->tab_label,
4755 "mnemonic_activate",
4756 G_CALLBACK (gtk_notebook_mnemonic_activate_switch_page),
4759 if (notebook->show_tabs && GTK_WIDGET_VISIBLE (child))
4761 gtk_widget_show (page->tab_label);
4762 gtk_widget_queue_resize (GTK_WIDGET (notebook));
4764 gtk_widget_child_notify (child, "tab_label");
4768 * gtk_notebook_set_tab_label_text:
4769 * @notebook: a #GtkNotebook
4771 * @tab_text: the label text
4773 * Creates a new label and sets it as the tab label for the page
4774 * containing @child.
4777 gtk_notebook_set_tab_label_text (GtkNotebook *notebook,
4779 const gchar *tab_text)
4781 GtkWidget *tab_label = NULL;
4783 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4786 tab_label = gtk_label_new (tab_text);
4787 gtk_notebook_set_tab_label (notebook, child, tab_label);
4788 gtk_widget_child_notify (child, "tab_label");
4792 * gtk_notebook_get_tab_label_text:
4793 * @notebook: a #GtkNotebook
4794 * @child: a widget contained in a page of @notebook
4796 * Retrieves the text of the tab label for the page containing
4799 * Returns value: the text of the tab label, or %NULL if the
4800 * tab label widget is not a #GtkLabel. The
4801 * string is owned by the widget and must not
4804 G_CONST_RETURN gchar *
4805 gtk_notebook_get_tab_label_text (GtkNotebook *notebook,
4808 GtkWidget *tab_label;
4810 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
4811 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
4813 tab_label = gtk_notebook_get_tab_label (notebook, child);
4815 if (tab_label && GTK_IS_LABEL (tab_label))
4816 return gtk_label_get_text (GTK_LABEL (tab_label));
4822 * gtk_notebook_get_menu_label:
4823 * @notebook: a #GtkNotebook
4824 * @child: a widget contained in a page of @notebook
4826 * Retrieves the menu label widget of the page containing @child.
4828 * Return value: the menu label, or %NULL if the
4829 * notebook page does not have a menu label other
4830 * than the default (the tab label).
4833 gtk_notebook_get_menu_label (GtkNotebook *notebook,
4838 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
4839 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
4841 list = CHECK_FIND_CHILD (notebook, child);
4845 if (GTK_NOTEBOOK_PAGE (list)->default_menu)
4848 return GTK_NOTEBOOK_PAGE (list)->menu_label;
4852 * gtk_notebook_set_menu_label:
4853 * @notebook: a #GtkNotebook
4854 * @child: the child widget
4855 * @menu_label: the menu label, or NULL for default
4857 * Changes the menu label for the page containing @child.
4860 gtk_notebook_set_menu_label (GtkNotebook *notebook,
4862 GtkWidget *menu_label)
4864 GtkNotebookPage *page;
4867 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4868 g_return_if_fail (GTK_IS_WIDGET (child));
4870 list = CHECK_FIND_CHILD (notebook, child);
4875 if (page->menu_label)
4878 gtk_container_remove (GTK_CONTAINER (notebook->menu),
4879 page->menu_label->parent);
4881 if (!page->default_menu)
4882 g_object_unref (page->menu_label);
4887 page->menu_label = menu_label;
4888 g_object_ref (page->menu_label);
4889 gtk_object_sink (GTK_OBJECT(page->menu_label));
4890 page->default_menu = FALSE;
4893 page->default_menu = TRUE;
4896 gtk_notebook_menu_item_create (notebook, list);
4897 gtk_widget_child_notify (child, "menu_label");
4901 * gtk_notebook_set_menu_label_text:
4902 * @notebook: a #GtkNotebook
4903 * @child: the child widget
4904 * @menu_text: the label text
4906 * Creates a new label and sets it as the menu label of @child.
4909 gtk_notebook_set_menu_label_text (GtkNotebook *notebook,
4911 const gchar *menu_text)
4913 GtkWidget *menu_label = NULL;
4915 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4918 menu_label = gtk_label_new (menu_text);
4919 gtk_notebook_set_menu_label (notebook, child, menu_label);
4920 gtk_widget_child_notify (child, "menu_label");
4924 * gtk_notebook_get_menu_label_text:
4925 * @notebook: a #GtkNotebook
4926 * @child: the child widget of a page of the notebook.
4928 * Retrieves the text of the menu label for the page containing
4931 * Returns value: the text of the tab label, or %NULL if the
4932 * widget does not have a menu label other than
4933 * the default menu label, or the menu label widget
4934 * is not a #GtkLabel. The string is owned by
4935 * the widget and must not be freed.
4937 G_CONST_RETURN gchar *
4938 gtk_notebook_get_menu_label_text (GtkNotebook *notebook,
4941 GtkWidget *menu_label;
4943 g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
4944 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
4946 menu_label = gtk_notebook_get_menu_label (notebook, child);
4948 if (menu_label && GTK_IS_LABEL (menu_label))
4949 return gtk_label_get_text (GTK_LABEL (menu_label));
4954 /* Helper function called when pages are reordered
4957 gtk_notebook_child_reordered (GtkNotebook *notebook,
4958 GtkNotebookPage *page)
4962 GtkWidget *menu_item;
4964 menu_item = page->menu_label->parent;
4965 gtk_container_remove (GTK_CONTAINER (menu_item), page->menu_label);
4966 gtk_container_remove (GTK_CONTAINER (notebook->menu), menu_item);
4967 gtk_notebook_menu_item_create (notebook, g_list_find (notebook->children, page));
4970 gtk_notebook_update_labels (notebook);
4974 * gtk_notebook_set_tab_label_packing:
4975 * @notebook: a #GtkNotebook
4976 * @child: the child widget
4977 * @expand: whether to expand the bookmark or not
4978 * @fill: whether the bookmark should fill the allocated area or not
4979 * @pack_type: the position of the bookmark
4981 * Sets the packing parameters for the tab label of the page
4982 * containing @child. See gtk_box_pack_start() for the exact meaning
4983 * of the parameters.
4986 gtk_notebook_set_tab_label_packing (GtkNotebook *notebook,
4990 GtkPackType pack_type)
4992 GtkNotebookPage *page;
4995 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
4996 g_return_if_fail (GTK_IS_WIDGET (child));
4998 list = CHECK_FIND_CHILD (notebook, child);
5003 expand = expand != FALSE;
5004 fill = fill != FALSE;
5005 if (page->pack == pack_type && page->expand == expand && page->fill == fill)
5008 gtk_widget_freeze_child_notify (child);
5009 page->expand = expand;
5010 gtk_widget_child_notify (child, "tab_expand");
5012 gtk_widget_child_notify (child, "tab_fill");
5013 if (page->pack != pack_type)
5015 page->pack = pack_type;
5016 gtk_notebook_child_reordered (notebook, page);
5018 gtk_widget_child_notify (child, "tab_pack");
5019 gtk_widget_child_notify (child, "position");
5020 if (notebook->show_tabs)
5021 gtk_notebook_pages_allocate (notebook);
5022 gtk_widget_thaw_child_notify (child);
5026 * gtk_notebook_query_tab_label_packing:
5027 * @notebook: a #GtkNotebook
5029 * @expand: location to store the expand value (or NULL)
5030 * @fill: location to store the fill value (or NULL)
5031 * @pack_type: location to store the pack_type (or NULL)
5033 * Query the packing attributes for the tab label of the page
5034 * containing @child.
5037 gtk_notebook_query_tab_label_packing (GtkNotebook *notebook,
5041 GtkPackType *pack_type)
5045 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
5046 g_return_if_fail (GTK_IS_WIDGET (child));
5048 list = CHECK_FIND_CHILD (notebook, child);
5053 *expand = GTK_NOTEBOOK_PAGE (list)->expand;
5055 *fill = GTK_NOTEBOOK_PAGE (list)->fill;
5057 *pack_type = GTK_NOTEBOOK_PAGE (list)->pack;
5061 * gtk_notebook_reorder_child:
5062 * @notebook: a #GtkNotebook
5063 * @child: the child to move
5064 * @position: the new position, or -1 to move to the end
5066 * Reorders the page containing @child, so that it appears in position
5067 * @position. If @position is greater than or equal to the number of
5068 * children in the list or negative, @child will be moved to the end
5072 gtk_notebook_reorder_child (GtkNotebook *notebook,
5076 GList *list, *new_list;
5077 GtkNotebookPage *page;
5081 g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
5082 g_return_if_fail (GTK_IS_WIDGET (child));
5084 list = CHECK_FIND_CHILD (notebook, child);
5088 max_pos = g_list_length (notebook->children) - 1;
5089 if (position < 0 || position > max_pos)
5092 old_pos = g_list_position (notebook->children, list);
5094 if (old_pos == position)
5098 notebook->children = g_list_delete_link (notebook->children, list);
5100 notebook->children = g_list_insert (notebook->children, page, position);
5101 new_list = g_list_nth (notebook->children, position);
5103 /* Fix up GList references in GtkNotebook structure */
5104 if (notebook->first_tab == list)
5105 notebook->first_tab = new_list;
5106 if (notebook->focus_tab == list)
5107 notebook->focus_tab = new_list;
5109 gtk_widget_freeze_child_notify (child);
5111 /* Move around the menu items if necesary */
5112 gtk_notebook_child_reordered (notebook, page);
5113 gtk_widget_child_notify (child, "tab_pack");
5114 gtk_widget_child_notify (child, "position");
5116 if (notebook->show_tabs)
5117 gtk_notebook_pages_allocate (notebook);
5119 gtk_widget_thaw_child_notify (child);