summaryrefslogtreecommitdiff
path: root/gtk/gtknotebook.c
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2001-11-15 21:04:51 +0000
committerOwen Taylor <otaylor@src.gnome.org>2001-11-15 21:04:51 +0000
commitb27345fe2cf7277bb3483d06651c8bb6820003ec (patch)
tree5d692b7598d24fb038d1c02b9304cb9b68e4a236 /gtk/gtknotebook.c
parent41f14d359739ba21d0725d7025885da880100f33 (diff)
downloadgtk+-b27345fe2cf7277bb3483d06651c8bb6820003ec.tar.gz
Cal gdk_window_invalidate_maybe_recurse() for recursion. (Soeren Sandmann)
Thu Nov 15 14:19:34 2001 Owen Taylor <otaylor@redhat.com> * gdk/gdkwindow.c (gdk_window_invalidate_maybe_recurse): Cal gdk_window_invalidate_maybe_recurse() for recursion. (Soeren Sandmann) * gtk/gtkviewport.c: Make !redraw_on_allocate. (Soeren Sandmann) * gtk/gtkcontainer.c (gtk_container_expose): Call gtk_container_forall() not _foreach() to propagate, since we need to propagate exposes to internal children as well. * gtk/gtkwidget.c (gtk_widget_set_events, gtk_widget_add_events): Remove the restriction of only being able to call these on window widgets, since we have lots of NO_WINDOW widgets with windows now; for add events, recurse over the children of widget->window to find one owned by the widget. * gtk/gtkbutton.[ch]: Make a NO_WINDOW widget, using an input-only window to catch events. * gtk/gtktogglebutton.[ch]: Remove the code for switching between NO_WINDOW and WINDOW widgets based on the mode. * gtk/gtkcheckbutton.c gtk/gtkoptionmenu.c gtk/gtkclist.c gtk/gtktreeview.c: Adopt to NO_WINDOW change for GtkButton. * gtk/gtkrange.[ch]: Make into a NO_WINDOW widget. * gtk/gtkhscale.c, gtk/gtkvscale.c: Adopt to NO_WINDOW change for range. * gtk/gtknotebook.[ch]: Make into a NO_WINDOW widget. * docs/Changes-2.0.txt: Add a note about the NO_WINDOW changes.
Diffstat (limited to 'gtk/gtknotebook.c')
-rw-r--r--gtk/gtknotebook.c680
1 files changed, 299 insertions, 381 deletions
diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c
index 87f114138d..bac4ff9ee2 100644
--- a/gtk/gtknotebook.c
+++ b/gtk/gtknotebook.c
@@ -180,7 +180,6 @@ static void gtk_notebook_forall (GtkContainer *container,
gpointer callback_data);
/*** GtkNotebook Private Functions ***/
-static void gtk_notebook_panel_realize (GtkNotebook *notebook);
static void gtk_notebook_redraw_tabs (GtkNotebook *notebook);
static void gtk_notebook_redraw_arrows (GtkNotebook *notebook);
static void gtk_notebook_focus_changed (GtkNotebook *notebook,
@@ -209,7 +208,6 @@ static void gtk_notebook_draw_tab (GtkNotebook *notebook,
GdkRectangle *area);
static void gtk_notebook_draw_arrow (GtkNotebook *notebook,
guint arrow);
-static void gtk_notebook_set_shape (GtkNotebook *notebook);
/*** GtkNotebook Size Allocate Functions ***/
static void gtk_notebook_pages_allocate (GtkNotebook *notebook);
@@ -497,13 +495,13 @@ static void
gtk_notebook_init (GtkNotebook *notebook)
{
GTK_WIDGET_SET_FLAGS (notebook, GTK_CAN_FOCUS | GTK_RECEIVES_DEFAULT);
- GTK_WIDGET_UNSET_FLAGS (notebook, GTK_NO_WINDOW);
+ GTK_WIDGET_SET_FLAGS (notebook, GTK_NO_WINDOW);
notebook->cur_page = NULL;
notebook->children = NULL;
notebook->first_tab = NULL;
notebook->focus_tab = NULL;
- notebook->panel = NULL;
+ notebook->event_window = NULL;
notebook->menu = NULL;
notebook->tab_hborder = 2;
@@ -696,6 +694,54 @@ gtk_notebook_get_property (GObject *object,
* gtk_notebook_draw_focus
* gtk_notebook_style_set
*/
+static gboolean
+gtk_notebook_get_event_window_position (GtkNotebook *notebook,
+ GdkRectangle *rectangle)
+{
+ GtkWidget *widget = GTK_WIDGET (notebook);
+
+ if (notebook->show_tabs && notebook->children)
+ {
+ if (rectangle)
+ {
+ GtkNotebookPage *page = notebook->children->data;
+
+ rectangle->x = widget->allocation.x;
+ rectangle->y = widget->allocation.y;
+
+ switch (notebook->tab_pos)
+ {
+ case GTK_POS_TOP:
+ case GTK_POS_BOTTOM:
+ rectangle->width = widget->allocation.width;
+ rectangle->height = page->requisition.height;
+ if (notebook->tab_pos == GTK_POS_BOTTOM)
+ rectangle->y += widget->allocation.height - rectangle->height;
+ break;
+ case GTK_POS_LEFT:
+ case GTK_POS_RIGHT:
+ rectangle->width = page->requisition.width;
+ rectangle->height = widget->allocation.height;
+ if (notebook->tab_pos == GTK_POS_RIGHT)
+ rectangle->x += widget->allocation.width - rectangle->width;
+ break;
+ }
+ }
+
+ return TRUE;
+ }
+ else
+ {
+ if (rectangle)
+ {
+ rectangle->x = rectangle->y = 0;
+ rectangle->width = rectangle->height = 10;
+ }
+ }
+
+ return FALSE;
+}
+
static void
gtk_notebook_map (GtkWidget *widget)
{
@@ -732,10 +778,8 @@ gtk_notebook_map (GtkWidget *widget)
}
}
- if (notebook->scrollable)
- gdk_window_show (notebook->panel);
-
- gdk_window_show (widget->window);
+ if (gtk_notebook_get_event_window_position (notebook, NULL))
+ gdk_window_show (notebook->event_window);
}
static void
@@ -744,9 +788,8 @@ gtk_notebook_unmap (GtkWidget *widget)
g_return_if_fail (GTK_IS_NOTEBOOK (widget));
GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
- gdk_window_hide (widget->window);
- if (GTK_NOTEBOOK (widget)->panel)
- gdk_window_hide (GTK_NOTEBOOK (widget)->panel);
+
+ gdk_window_hide (GTK_NOTEBOOK (widget)->event_window);
}
static void
@@ -755,35 +798,35 @@ gtk_notebook_realize (GtkWidget *widget)
GtkNotebook *notebook;
GdkWindowAttr attributes;
gint attributes_mask;
+ GdkRectangle event_window_pos;
g_return_if_fail (GTK_IS_NOTEBOOK (widget));
notebook = GTK_NOTEBOOK (widget);
GTK_WIDGET_SET_FLAGS (notebook, GTK_REALIZED);
+ gtk_notebook_get_event_window_position (notebook, &event_window_pos);
+
+ widget->window = gtk_widget_get_parent_window (widget);
+ gdk_window_ref (widget->window);
+
attributes.window_type = GDK_WINDOW_CHILD;
- attributes.x = widget->allocation.x;
- attributes.y = widget->allocation.y;
- attributes.width = widget->allocation.width;
- attributes.height = widget->allocation.height;
- attributes.wclass = GDK_INPUT_OUTPUT;
- attributes.visual = gtk_widget_get_visual (widget);
- attributes.colormap = gtk_widget_get_colormap (widget);
+ attributes.x = event_window_pos.x;
+ attributes.y = event_window_pos.y;
+ attributes.width = event_window_pos.width;
+ attributes.height = event_window_pos.height;
+ attributes.wclass = GDK_INPUT_ONLY;
attributes.event_mask = gtk_widget_get_events (widget);
attributes.event_mask |= (GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK);
- attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+ attributes_mask = GDK_WA_X | GDK_WA_Y;
- widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
- gdk_window_set_user_data (widget->window, notebook);
+ notebook->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
+ &attributes, attributes_mask);
+ gdk_window_set_user_data (notebook->event_window, notebook);
widget->style = gtk_style_attach (widget->style, widget->window);
- gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
-
- gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
- if (notebook->scrollable)
- gtk_notebook_panel_realize (notebook);
}
static void
@@ -795,12 +838,9 @@ gtk_notebook_unrealize (GtkWidget *widget)
notebook = GTK_NOTEBOOK (widget);
- if (notebook->panel)
- {
- gdk_window_set_user_data (notebook->panel, NULL);
- gdk_window_destroy (notebook->panel);
- notebook->panel = NULL;
- }
+ gdk_window_set_user_data (notebook->event_window, NULL);
+ gdk_window_destroy (notebook->event_window);
+ notebook->event_window = NULL;
if (GTK_WIDGET_CLASS (parent_class)->unrealize)
(* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
@@ -1071,28 +1111,34 @@ gtk_notebook_size_allocate (GtkWidget *widget,
g_return_if_fail (GTK_IS_NOTEBOOK (widget));
g_return_if_fail (allocation != NULL);
+ notebook = GTK_NOTEBOOK (widget);
+
widget->allocation = *allocation;
if (GTK_WIDGET_REALIZED (widget))
- gdk_window_move_resize (widget->window,
- allocation->x, allocation->y,
- allocation->width, allocation->height);
+ {
+ GdkRectangle position;
+
+ if (gtk_notebook_get_event_window_position (notebook, &position))
+ gdk_window_move_resize (notebook->event_window,
+ position.x, position.y,
+ position.width, position.height);
+ }
- notebook = GTK_NOTEBOOK (widget);
if (notebook->children)
{
child_allocation.x = GTK_CONTAINER (widget)->border_width;
child_allocation.y = GTK_CONTAINER (widget)->border_width;
- child_allocation.width = MAX (1, (gint)allocation->width - child_allocation.x * 2);
- child_allocation.height = MAX (1, (gint)allocation->height - child_allocation.y * 2);
+ child_allocation.width = MAX (1, allocation->width - child_allocation.x * 2);
+ child_allocation.height = MAX (1, allocation->height - child_allocation.y * 2);
if (notebook->show_tabs || notebook->show_border)
{
child_allocation.x += widget->style->xthickness;
child_allocation.y += widget->style->ythickness;
- child_allocation.width = MAX (1, (gint)child_allocation.width -
- (gint) widget->style->xthickness * 2);
- child_allocation.height = MAX (1, (gint)child_allocation.height -
- (gint) widget->style->ythickness * 2);
+ child_allocation.width = MAX (1, child_allocation.width -
+ widget->style->xthickness * 2);
+ child_allocation.height = MAX (1, child_allocation.height -
+ widget->style->ythickness * 2);
if (notebook->show_tabs && notebook->children && notebook->cur_page)
{
@@ -1102,15 +1148,15 @@ gtk_notebook_size_allocate (GtkWidget *widget,
child_allocation.y += notebook->cur_page->requisition.height;
case GTK_POS_BOTTOM:
child_allocation.height =
- MAX (1, (gint)child_allocation.height -
- (gint)notebook->cur_page->requisition.height);
+ MAX (1, child_allocation.height -
+ notebook->cur_page->requisition.height);
break;
case GTK_POS_LEFT:
child_allocation.x += notebook->cur_page->requisition.width;
case GTK_POS_RIGHT:
child_allocation.width =
- MAX (1, (gint)child_allocation.width -
- (gint)notebook->cur_page->requisition.width);
+ MAX (1, child_allocation.width -
+ notebook->cur_page->requisition.width);
break;
}
}
@@ -1128,7 +1174,6 @@ gtk_notebook_size_allocate (GtkWidget *widget,
gtk_notebook_pages_allocate (notebook);
}
- gtk_notebook_set_shape (notebook);
}
static gint
@@ -1165,13 +1210,104 @@ gtk_notebook_expose (GtkWidget *widget,
}
static gboolean
+gtk_notebook_show_arrows (GtkNotebook *notebook)
+{
+ gboolean show_arrow = FALSE;
+ GList *children;
+
+ if (!notebook->scrollable)
+ return FALSE;
+
+ children = notebook->children;
+ while (children)
+ {
+ GtkNotebookPage *page = children->data;
+
+ if (page->tab_label && !gtk_widget_get_child_visible (page->tab_label))
+ show_arrow = TRUE;
+
+ children = children->next;
+ }
+
+ return show_arrow;
+}
+
+static void
+gtk_notebook_get_arrow_rect (GtkNotebook *notebook,
+ GdkRectangle *rectangle)
+{
+ GdkRectangle event_window_pos;
+
+ if (gtk_notebook_get_event_window_position (notebook, &event_window_pos))
+ {
+ rectangle->width = 2 * ARROW_SIZE + ARROW_SPACING;
+ rectangle->height = ARROW_SIZE;
+
+ switch (notebook->tab_pos)
+ {
+ case GTK_POS_LEFT:
+ rectangle->x = event_window_pos.x + (event_window_pos.width - rectangle->width) / 2;
+ break;
+ case GTK_POS_RIGHT:
+ rectangle->x = event_window_pos.x + event_window_pos.width - (event_window_pos.width - rectangle->width) / 2;
+ break;
+ case GTK_POS_TOP:
+ case GTK_POS_BOTTOM:
+ rectangle->x = event_window_pos.x + event_window_pos.width - rectangle->width;
+ break;
+ }
+
+ switch (notebook->tab_pos)
+ {
+ case GTK_POS_LEFT:
+ case GTK_POS_RIGHT:
+ rectangle->y = event_window_pos.y + event_window_pos.height - rectangle->height;
+ break;
+ case GTK_POS_TOP:
+ rectangle->y = event_window_pos.y + (event_window_pos.height - rectangle->height) / 2;
+ break;
+ case GTK_POS_BOTTOM:
+ rectangle->y = event_window_pos.y + event_window_pos.height - (event_window_pos.height - rectangle->height) / 2;
+ break;
+ }
+ }
+}
+
+static GtkArrowType
+gtk_notebook_get_arrow (GtkNotebook *notebook,
+ gint x,
+ gint y)
+{
+ GdkRectangle arrow_rect;
+ GdkRectangle event_window_pos;
+
+ if (gtk_notebook_show_arrows (notebook))
+ {
+ gtk_notebook_get_event_window_position (notebook, &event_window_pos);
+ gtk_notebook_get_arrow_rect (notebook, &arrow_rect);
+
+ x -= arrow_rect.x - event_window_pos.x;
+ y -= arrow_rect.y - event_window_pos.y;
+
+ if (y >= 0 && y < arrow_rect.height)
+ {
+ if (x >= 0 && x < ARROW_SIZE + ARROW_SPACING / 2)
+ return GTK_ARROW_LEFT;
+ else if (x >= ARROW_SIZE + ARROW_SPACING / 2 && x < arrow_rect.width)
+ return GTK_ARROW_RIGHT;
+ }
+ }
+
+ return 0;
+}
+
+static gboolean
gtk_notebook_arrow_button_press (GtkNotebook *notebook,
+ GtkArrowType arrow,
GdkEventButton *event)
{
GtkWidget *widget = GTK_WIDGET (notebook);
- GtkArrowType arrow = event->x <= ARROW_SIZE + ARROW_SPACING / 2 ? GTK_ARROW_LEFT : GTK_ARROW_RIGHT;
-
if (!GTK_WIDGET_HAS_FOCUS (widget))
gtk_widget_grab_focus (widget);
@@ -1219,75 +1355,75 @@ static gboolean
gtk_notebook_button_press (GtkWidget *widget,
GdkEventButton *event)
{
- GtkNotebook *notebook;
+ GtkNotebook *notebook = GTK_NOTEBOOK (widget);
GtkNotebookPage *page;
GList *children;
+ GtkArrowType arrow;
+ GdkRectangle event_window_pos;
gint num;
-
- g_return_val_if_fail (GTK_IS_NOTEBOOK (widget), FALSE);
- g_return_val_if_fail (event != NULL, FALSE);
-
- notebook = GTK_NOTEBOOK (widget);
+ gint x, y;
if (event->type != GDK_BUTTON_PRESS || !notebook->children ||
notebook->button)
return FALSE;
- if (event->window == notebook->panel)
+ arrow = gtk_notebook_get_arrow (notebook, event->x, event->y);
+ if (arrow)
+ return gtk_notebook_arrow_button_press (notebook, arrow, event);
+
+ if (event->button == 3 && notebook->menu)
{
- return gtk_notebook_arrow_button_press (notebook, event);
+ gtk_menu_popup (GTK_MENU (notebook->menu), NULL, NULL,
+ NULL, NULL, 3, event->time);
+ return TRUE;
}
- else if (event->window == widget->window)
- {
- if (event->button == 3 && notebook->menu)
- {
- gtk_menu_popup (GTK_MENU (notebook->menu), NULL, NULL,
- NULL, NULL, 3, event->time);
- return TRUE;
- }
- num = 0;
- children = notebook->children;
- while (children)
+ /* Translate coordinates from event_window to widget->window
+ */
+ gtk_notebook_get_event_window_position (notebook, &event_window_pos);
+ x = event->x + event_window_pos.x;
+ y = event->y + event_window_pos.y;
+
+ num = 0;
+ children = notebook->children;
+ while (children)
+ {
+ page = children->data;
+
+ if (GTK_WIDGET_VISIBLE (page->child) &&
+ page->tab_label && GTK_WIDGET_MAPPED (page->tab_label) &&
+ (x >= page->allocation.x) &&
+ (y >= page->allocation.y) &&
+ (x <= (page->allocation.x + page->allocation.width)) &&
+ (y <= (page->allocation.y + page->allocation.height)))
{
- page = children->data;
-
- if (GTK_WIDGET_VISIBLE (page->child) &&
- page->tab_label && GTK_WIDGET_MAPPED (page->tab_label) &&
- (event->x >= page->allocation.x) &&
- (event->y >= page->allocation.y) &&
- (event->x <= (page->allocation.x + page->allocation.width)) &&
- (event->y <= (page->allocation.y + page->allocation.height)))
+ if (page == notebook->cur_page && notebook->focus_tab &&
+ notebook->focus_tab != children &&
+ GTK_WIDGET_HAS_FOCUS (notebook))
{
- if (page == notebook->cur_page && notebook->focus_tab &&
- notebook->focus_tab != children &&
- GTK_WIDGET_HAS_FOCUS (notebook))
- {
- GtkNotebookPage *old_page;
-
- notebook->child_has_focus = FALSE;
- old_page = (GtkNotebookPage *)
- (notebook->focus_tab->data);
- gtk_notebook_switch_focus_tab (notebook, children);
- gtk_notebook_focus_changed (notebook, old_page);
- }
- else
- {
- gtk_notebook_switch_focus_tab (notebook, children);
- gtk_widget_grab_focus (widget);
- gtk_notebook_switch_page (notebook, page, num);
- }
- break;
+ GtkNotebookPage *old_page;
+
+ notebook->child_has_focus = FALSE;
+ old_page = (GtkNotebookPage *)
+ (notebook->focus_tab->data);
+ gtk_notebook_switch_focus_tab (notebook, children);
+ gtk_notebook_focus_changed (notebook, old_page);
}
- children = children->next;
- num++;
+ else
+ {
+ gtk_notebook_switch_focus_tab (notebook, children);
+ gtk_widget_grab_focus (widget);
+ gtk_notebook_switch_page (notebook, page, num);
+ }
+ break;
}
- if (!children && !GTK_WIDGET_HAS_FOCUS (widget))
- gtk_widget_grab_focus (widget);
- return TRUE;
+ children = children->next;
+ num++;
}
-
- return FALSE;
+ if (!children && !GTK_WIDGET_HAS_FOCUS (widget))
+ gtk_widget_grab_focus (widget);
+
+ return TRUE;
}
static gint
@@ -1330,89 +1466,69 @@ gtk_notebook_enter_notify (GtkWidget *widget,
GdkEventCrossing *event)
{
GtkNotebook *notebook;
+ GtkArrowType arrow;
g_return_val_if_fail (GTK_IS_NOTEBOOK (widget), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
notebook = GTK_NOTEBOOK (widget);
- if (event->window == notebook->panel)
- {
- gint x;
- gint y;
-
- gdk_window_get_pointer (notebook->panel, &x, &y, NULL);
-
- if (x <= ARROW_SIZE + ARROW_SPACING / 2)
- notebook->in_child = GTK_ARROW_LEFT;
- else
- notebook->in_child = GTK_ARROW_RIGHT;
+ arrow = gtk_notebook_get_arrow (notebook, event->x, event->y);
+ if (arrow != notebook->in_child)
+ {
+ notebook->in_child = arrow;
gtk_notebook_redraw_arrows (notebook);
+
+ return TRUE;
}
- return FALSE;
+ return TRUE;
}
static gint
gtk_notebook_leave_notify (GtkWidget *widget,
GdkEventCrossing *event)
{
- GtkNotebook *notebook;
+ GtkNotebook *notebook = GTK_NOTEBOOK (widget);
+ GtkArrowType arrow;
- g_return_val_if_fail (GTK_IS_NOTEBOOK (widget), FALSE);
- g_return_val_if_fail (event != NULL, FALSE);
-
- notebook = GTK_NOTEBOOK (widget);
+ arrow = gtk_notebook_get_arrow (notebook, event->x, event->y);
- if (event->window == notebook->panel)
- gtk_notebook_redraw_arrows (notebook);
+ if (notebook->in_child)
+ {
+ notebook->in_child = 0;
+ gtk_notebook_redraw_arrows (notebook);
+ }
- return FALSE;
+ return TRUE;
}
static gint
gtk_notebook_motion_notify (GtkWidget *widget,
GdkEventMotion *event)
{
- GtkNotebook *notebook;
+ GtkNotebook *notebook = GTK_NOTEBOOK (widget);
+ GtkArrowType arrow;
- g_return_val_if_fail (GTK_IS_NOTEBOOK (widget), FALSE);
- g_return_val_if_fail (event != NULL, FALSE);
-
- notebook = GTK_NOTEBOOK (widget);
-
if (notebook->button)
return FALSE;
- if (event->window == notebook->panel)
- {
- gint x;
- GtkArrowType old_child = notebook->in_child;
-
- x = event->x;
- if (event->is_hint)
- gdk_window_get_pointer (notebook->panel, &x, NULL, NULL);
-
- if (x <= ARROW_SIZE + ARROW_SPACING / 2)
- notebook->in_child = GTK_ARROW_LEFT;
- else
- notebook->in_child = GTK_ARROW_RIGHT;
+ arrow = gtk_notebook_get_arrow (notebook, event->x, event->y);
- if (old_child != notebook->in_child)
- gtk_notebook_redraw_arrows (notebook);
+ if (arrow != notebook->in_child)
+ {
+ notebook->in_child = arrow;
+ gtk_notebook_redraw_arrows (notebook);
}
- return FALSE;
+ return TRUE;
}
static gint
gtk_notebook_focus_in (GtkWidget *widget,
GdkEventFocus *event)
{
- g_return_val_if_fail (GTK_IS_NOTEBOOK (widget), FALSE);
- g_return_val_if_fail (event != NULL, FALSE);
-
GTK_NOTEBOOK (widget)->child_has_focus = FALSE;
return (* GTK_WIDGET_CLASS (parent_class)->focus_in_event) (widget, event);
@@ -1421,11 +1537,7 @@ gtk_notebook_focus_in (GtkWidget *widget,
static void
gtk_notebook_draw_focus (GtkWidget *widget)
{
- GtkNotebook *notebook;
-
- g_return_if_fail (GTK_IS_NOTEBOOK (widget));
-
- notebook = GTK_NOTEBOOK (widget);
+ GtkNotebook *notebook = GTK_NOTEBOOK (widget);
if (GTK_WIDGET_DRAWABLE (widget) && notebook->show_tabs &&
notebook->focus_tab)
@@ -1840,7 +1952,6 @@ gtk_notebook_child_type (GtkContainer *container)
/* Private GtkNotebook Functions:
*
- * gtk_notebook_panel_realize
* gtk_notebook_redraw_tabs
* gtk_notebook_focus_changed
* gtk_notebook_real_remove
@@ -1851,49 +1962,6 @@ gtk_notebook_child_type (GtkContainer *container)
* gtk_notebook_search_page
*/
static void
-gtk_notebook_panel_realize (GtkNotebook *notebook)
-{
- GtkWidget *widget;
- GdkWindowAttr attributes;
- gint attributes_mask;
-
- g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
-
- widget = GTK_WIDGET (notebook);
-
- attributes.window_type = GDK_WINDOW_CHILD;
- attributes.wclass = GDK_INPUT_OUTPUT;
- attributes.visual = gtk_widget_get_visual (widget);
- attributes.colormap = gtk_widget_get_colormap (widget);
- attributes.event_mask = gtk_widget_get_events (widget);
- attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK
- | GDK_BUTTON_RELEASE_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_ENTER_NOTIFY_MASK
- | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK;
-
- attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
-
- attributes.width = 2 * ARROW_SIZE + ARROW_SPACING;
- attributes.height = ARROW_SIZE;
-
- attributes.x = (widget->allocation.width - attributes.width -
- GTK_CONTAINER (notebook)->border_width);
- attributes.y = (widget->allocation.height - ARROW_SIZE -
- GTK_CONTAINER (notebook)->border_width);
- if (notebook->tab_pos == GTK_POS_TOP)
- attributes.y = GTK_CONTAINER (notebook)->border_width;
- else if (notebook->tab_pos == GTK_POS_LEFT)
- attributes.x = (widget->allocation.x +
- GTK_CONTAINER (notebook)->border_width);
-
- notebook->panel = gdk_window_new (widget->window, &attributes,
- attributes_mask);
- gtk_style_set_background (widget->style, notebook->panel,
- GTK_STATE_NORMAL);
- gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
- gdk_window_set_user_data (notebook->panel, widget);
-}
-
-static void
gtk_notebook_redraw_tabs (GtkNotebook *notebook)
{
GtkWidget *widget;
@@ -1950,8 +2018,13 @@ gtk_notebook_redraw_tabs (GtkNotebook *notebook)
static void
gtk_notebook_redraw_arrows (GtkNotebook *notebook)
{
- if (GTK_WIDGET_MAPPED (notebook) && notebook->panel)
- gdk_window_invalidate_rect (notebook->panel, NULL, FALSE);
+ if (GTK_WIDGET_MAPPED (notebook) && gtk_notebook_show_arrows (notebook))
+ {
+ GdkRectangle rect;
+
+ gtk_notebook_get_arrow_rect (notebook, &rect);
+ gdk_window_invalidate_rect (GTK_WIDGET (notebook)->window, &rect, FALSE);
+ }
}
static void
@@ -2113,6 +2186,10 @@ gtk_notebook_real_remove (GtkNotebook *notebook,
g_list_free (list);
g_free (page);
+ if (!notebook->children && notebook->show_tabs &&
+ GTK_WIDGET_MAPPED (notebook))
+ gdk_window_hide (notebook->event_window);
+
gtk_notebook_update_labels (notebook);
if (need_resize)
gtk_widget_queue_resize (GTK_WIDGET (notebook));
@@ -2257,7 +2334,6 @@ gtk_notebook_search_page (GtkNotebook *notebook,
* gtk_notebook_paint
* gtk_notebook_draw_tab
* gtk_notebook_draw_arrow
- * gtk_notebook_set_shape
*/
static void
gtk_notebook_paint (GtkWidget *widget,
@@ -2269,6 +2345,7 @@ gtk_notebook_paint (GtkWidget *widget,
gboolean showarrow;
gint width, height;
gint x, y;
+ gint border_width = GTK_CONTAINER (widget)->border_width;
gint gap_x = 0, gap_width = 0;
g_return_if_fail (GTK_IS_NOTEBOOK (widget));
@@ -2281,15 +2358,10 @@ gtk_notebook_paint (GtkWidget *widget,
if ((!notebook->show_tabs && !notebook->show_border) ||
!notebook->cur_page || !GTK_WIDGET_VISIBLE (notebook->cur_page->child))
- {
- gdk_window_clear_area (widget->window,
- area->x, area->y,
- area->width, area->height);
- return;
- }
+ return;
- x = GTK_CONTAINER (widget)->border_width;
- y = GTK_CONTAINER (widget)->border_width;
+ x = widget->allocation.x + border_width;
+ y = widget->allocation.y + border_width;
width = widget->allocation.width - x * 2;
height = widget->allocation.height - y * 2;
@@ -2344,23 +2416,19 @@ gtk_notebook_paint (GtkWidget *widget,
switch (notebook->tab_pos)
{
case GTK_POS_TOP:
- gap_x = (notebook->cur_page->allocation.x -
- GTK_CONTAINER(notebook)->border_width);
+ gap_x = (notebook->cur_page->allocation.x - border_width);
gap_width = notebook->cur_page->allocation.width;
break;
case GTK_POS_BOTTOM:
- gap_x = (notebook->cur_page->allocation.x -
- GTK_CONTAINER(notebook)->border_width);
+ gap_x = (notebook->cur_page->allocation.x - border_width);
gap_width = notebook->cur_page->allocation.width;
break;
case GTK_POS_LEFT:
- gap_x = (notebook->cur_page->allocation.y -
- GTK_CONTAINER(notebook)->border_width);
+ gap_x = (notebook->cur_page->allocation.y - border_width);
gap_width = notebook->cur_page->allocation.height;
break;
case GTK_POS_RIGHT:
- gap_x = (notebook->cur_page->allocation.y -
- GTK_CONTAINER(notebook)->border_width);
+ gap_x = (notebook->cur_page->allocation.y - border_width);
gap_width = notebook->cur_page->allocation.height;
break;
}
@@ -2487,6 +2555,9 @@ gtk_notebook_draw_arrow (GtkNotebook *notebook,
GtkStateType state_type;
GtkShadowType shadow_type;
GtkWidget *widget;
+ GdkRectangle arrow_rect;
+
+ gtk_notebook_get_arrow_rect (notebook, &arrow_rect);
g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
@@ -2523,11 +2594,10 @@ gtk_notebook_draw_arrow (GtkNotebook *notebook,
notebook->tab_pos == GTK_POS_RIGHT)
arrow = GTK_ARROW_UP;
- gdk_window_clear_area (notebook->panel, 0, 0, ARROW_SIZE, ARROW_SIZE);
- gtk_paint_arrow (widget->style, notebook->panel, state_type,
+ gtk_paint_arrow (widget->style, widget->window, state_type,
shadow_type, NULL, GTK_WIDGET(notebook), "notebook",
arrow, TRUE,
- 0, 0, ARROW_SIZE, ARROW_SIZE);
+ arrow_rect.x, arrow_rect.y, ARROW_SIZE, ARROW_SIZE);
}
else
{
@@ -2543,141 +2613,14 @@ gtk_notebook_draw_arrow (GtkNotebook *notebook,
notebook->tab_pos == GTK_POS_RIGHT)
arrow = GTK_ARROW_DOWN;
- gdk_window_clear_area(notebook->panel, ARROW_SIZE + ARROW_SPACING,
- 0, ARROW_SIZE, ARROW_SIZE);
- gtk_paint_arrow (widget->style, notebook->panel, state_type,
+ gtk_paint_arrow (widget->style, widget->window, state_type,
shadow_type, NULL, GTK_WIDGET(notebook), "notebook",
- arrow, TRUE, ARROW_SIZE + ARROW_SPACING,
- 0, ARROW_SIZE, ARROW_SIZE);
+ arrow, TRUE, arrow_rect.x + ARROW_SIZE + ARROW_SPACING,
+ arrow_rect.y, ARROW_SIZE, ARROW_SIZE);
}
}
}
-static void
-gtk_notebook_set_shape (GtkNotebook *notebook)
-{
- GtkWidget *widget = NULL;
- GdkPixmap *pm = NULL;
- GdkGC *pmgc = NULL;
- GdkColor col;
- gint x, y, width, height, w, h, depth;
- GtkNotebookPage *page;
- GList *children;
-
- if (!GTK_WIDGET(notebook)->window)
- return;
-
- widget = GTK_WIDGET(notebook);
-
- w = widget->allocation.width;
- h = widget->allocation.height;
-
- pm = gdk_pixmap_new (widget->window, w, h, 1);
- pmgc = gdk_gc_new (pm);
-
- /* clear the shape mask */
- col.pixel = 0;
- gdk_gc_set_foreground(pmgc, &col);
- gdk_draw_rectangle(pm, pmgc, TRUE, 0, 0, w, h);
-
- col.pixel = 1;
- gdk_gc_set_foreground(pmgc, &col);
-
- /* draw the shape for the notebook page itself */
- x = GTK_CONTAINER(notebook)->border_width;
- y = GTK_CONTAINER(notebook)->border_width;
- width = widget->allocation.width - x * 2;
- height = widget->allocation.height - y * 2;
-
- if (notebook->show_tabs && notebook->children)
- {
- if (!(notebook->show_tabs))
- {
- page = notebook->first_tab->data;
- switch (notebook->tab_pos)
- {
- case GTK_POS_TOP:
- y += page->allocation.height +
- widget->style->ythickness;
- case GTK_POS_BOTTOM:
- height -= page->allocation.height +
- widget->style->ythickness;
- break;
- case GTK_POS_LEFT:
- x += page->allocation.width +
- widget->style->xthickness;
- case GTK_POS_RIGHT:
- width -= page->allocation.width +
- widget->style->xthickness;
- break;
- }
- }
- else
- {
- if (notebook->cur_page)
- page = notebook->cur_page;
- else
- page = notebook->children->data;
-
- if (!GTK_WIDGET_MAPPED (page->tab_label))
- {
- if (notebook->tab_pos == GTK_POS_LEFT)
- {
- x -= widget->style->xthickness * 2;
- width += widget->style->xthickness * 2;
- }
- else if (notebook->tab_pos == GTK_POS_RIGHT)
- width += widget->style->xthickness * 2;
- }
- switch (notebook->tab_pos)
- {
- case GTK_POS_TOP:
- y += page->allocation.height;
- case GTK_POS_BOTTOM:
- height -= page->allocation.height;
- break;
- case GTK_POS_LEFT:
- x += page->allocation.width;
- case GTK_POS_RIGHT:
- width -= page->allocation.width;
- break;
- }
- }
- }
- gdk_draw_rectangle(pm, pmgc, TRUE, x, y, width, height);
-
- /* if theres an area for scrolling arrows draw the shape for them */
- if (notebook->panel && gdk_window_is_visible (notebook->panel))
- {
- gdk_window_get_geometry(notebook->panel, &x, &y, &width, &height, &depth);
- gdk_draw_rectangle(pm, pmgc, TRUE, x, y, width, height);
- }
-
- /* draw the shapes of all the children */
- if (notebook->show_tabs)
- {
- children = notebook->children;
- while (children)
- {
- page = children->data;
- if (gtk_widget_get_child_visible (page->tab_label))
- {
- x = page->allocation.x;
- y = page->allocation.y;
- width = page->allocation.width;
- height = page->allocation.height;
- gdk_draw_rectangle(pm, pmgc, TRUE, x, y, width, height);
- }
- children = children->next;
- }
- }
-
- /* set the mask */
- gdk_window_shape_combine_mask(widget->window, pm, 0, 0);
- gdk_pixmap_unref(pm);
- gdk_gc_destroy(pmgc);
-}
-
/* Private GtkNotebook Size Allocate Functions:
*
* gtk_notebook_pages_allocate
@@ -2892,12 +2835,6 @@ gtk_notebook_pages_allocate (GtkNotebook *notebook)
}
}
- if (GTK_WIDGET_REALIZED (notebook))
- {
- gdk_window_move (notebook->panel, x, y);
- gdk_window_show (notebook->panel);
- }
-
if (tab_space < 0)
{
tab_space = -tab_space;
@@ -2936,8 +2873,6 @@ gtk_notebook_pages_allocate (GtkNotebook *notebook)
notebook->first_tab = gtk_notebook_search_page (notebook, NULL,
STEP_NEXT, TRUE);
tab_space = 0;
- if (GTK_WIDGET_REALIZED (notebook))
- gdk_window_hide (notebook->panel);
}
}
@@ -3115,7 +3050,6 @@ gtk_notebook_pages_allocate (GtkNotebook *notebook)
}
done:
- gtk_notebook_set_shape (notebook);
gtk_notebook_redraw_tabs (notebook);
}
@@ -3216,7 +3150,7 @@ gtk_notebook_page_allocate (GtkNotebook *notebook,
{
child_allocation.x = (xthickness + FOCUS_WIDTH +
notebook->tab_hborder);
- child_allocation.width = MAX (1, (((gint) page->allocation.width) -
+ child_allocation.width = MAX (1, (page->allocation.width -
2 * child_allocation.x));
child_allocation.x += page->allocation.x;
}
@@ -3231,7 +3165,7 @@ gtk_notebook_page_allocate (GtkNotebook *notebook,
page->allocation.y);
if (notebook->tab_pos == GTK_POS_TOP)
child_allocation.y += ythickness;
- child_allocation.height = MAX (1, (((gint) page->allocation.height) - ythickness -
+ child_allocation.height = MAX (1, (page->allocation.height - ythickness -
2 * (notebook->tab_vborder + FOCUS_WIDTH)));
break;
case GTK_POS_LEFT:
@@ -3240,7 +3174,7 @@ gtk_notebook_page_allocate (GtkNotebook *notebook,
if (page->fill)
{
child_allocation.y = ythickness + padding;
- child_allocation.height = MAX (1, (((gint) page->allocation.height) -
+ child_allocation.height = MAX (1, (page->allocation.height -
2 * child_allocation.y));
child_allocation.y += page->allocation.y;
}
@@ -3253,7 +3187,7 @@ gtk_notebook_page_allocate (GtkNotebook *notebook,
child_allocation.x = page->allocation.x + notebook->tab_hborder + FOCUS_WIDTH;
if (notebook->tab_pos == GTK_POS_LEFT)
child_allocation.x += xthickness;
- child_allocation.width = MAX (1, (((gint) page->allocation.width) - xthickness -
+ child_allocation.width = MAX (1, (page->allocation.width - xthickness -
2 * (notebook->tab_hborder + FOCUS_WIDTH)));
break;
}
@@ -3466,7 +3400,7 @@ gtk_notebook_switch_focus_tab (GtkNotebook *notebook,
old_child = notebook->focus_tab;
notebook->focus_tab = new_child;
- if (notebook->scrollable && GTK_WIDGET_DRAWABLE (notebook))
+ if (notebook->scrollable)
gtk_notebook_redraw_arrows (notebook);
if (!notebook->show_tabs || !notebook->focus_tab)
@@ -3480,8 +3414,6 @@ gtk_notebook_switch_focus_tab (GtkNotebook *notebook,
gtk_notebook_focus_changed (notebook, old_page);
else
gtk_notebook_pages_allocate (notebook);
-
- gtk_notebook_set_shape (notebook);
}
static void
@@ -3847,6 +3779,9 @@ gtk_notebook_insert_page_menu (GtkNotebook *notebook,
(GtkSignalFunc) gtk_notebook_mnemonic_activate_switch_page,
notebook);
+ if (notebook->show_tabs && GTK_WIDGET_MAPPED (notebook))
+ gdk_window_show (notebook->event_window);
+
gtk_widget_child_notify (child, "tab_expand");
gtk_widget_child_notify (child, "tab_fill");
gtk_widget_child_notify (child, "tab_pack");
@@ -4150,9 +4085,6 @@ gtk_notebook_set_show_tabs (GtkNotebook *notebook,
else
gtk_widget_hide (page->tab_label);
}
-
- if (notebook->panel)
- gdk_window_hide (notebook->panel);
}
else
{
@@ -4335,20 +4267,6 @@ gtk_notebook_set_scrollable (GtkNotebook *notebook,
{
notebook->scrollable = scrollable;
- if (GTK_WIDGET_REALIZED (notebook))
- {
- if (scrollable)
- {
- gtk_notebook_panel_realize (notebook);
- }
- else if (notebook->panel)
- {
- gdk_window_set_user_data (notebook->panel, NULL);
- gdk_window_destroy (notebook->panel);
- notebook->panel = NULL;
- }
- }
-
if (GTK_WIDGET_VISIBLE (notebook))
gtk_widget_queue_resize (GTK_WIDGET (notebook));