gtk2/gtk/gtkscrolledwindow.c

673 lines
22 KiB
C
Raw Normal View History

1997-11-24 22:37:52 +00:00
/* GTK - The GIMP Toolkit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
1997-11-24 22:37:52 +00:00
*/
#include "gtkscrolledwindow.h"
#include "gtksignal.h"
#define SCROLLBAR_SPACING(w) (GTK_SCROLLED_WINDOW_CLASS (GTK_OBJECT (w)->klass)->scrollbar_spacing)
1997-11-24 22:37:52 +00:00
enum {
ARG_0,
ARG_VIEWPORT,
ARG_HSCROLLBAR_POLICY,
ARG_VSCROLLBAR_POLICY
};
1997-11-24 22:37:52 +00:00
static void gtk_scrolled_window_class_init (GtkScrolledWindowClass *klass);
static void gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window);
static void gtk_scrolled_window_set_arg (GtkObject *object,
GtkArg *arg,
guint arg_id);
static void gtk_scrolled_window_get_arg (GtkObject *object,
GtkArg *arg,
guint arg_id);
1997-11-24 22:37:52 +00:00
static void gtk_scrolled_window_destroy (GtkObject *object);
static void gtk_scrolled_window_finalize (GtkObject *object);
1997-11-24 22:37:52 +00:00
static void gtk_scrolled_window_map (GtkWidget *widget);
static void gtk_scrolled_window_unmap (GtkWidget *widget);
static void gtk_scrolled_window_draw (GtkWidget *widget,
GdkRectangle *area);
static void gtk_scrolled_window_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void gtk_scrolled_window_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static void gtk_scrolled_window_add (GtkContainer *container,
GtkWidget *widget);
static void gtk_scrolled_window_remove (GtkContainer *container,
GtkWidget *widget);
static void gtk_scrolled_window_foreach (GtkContainer *container,
GtkCallback callback,
gpointer callback_data);
static void gtk_scrolled_window_viewport_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static void gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
gpointer data);
static GtkContainerClass *parent_class = NULL;
GtkType
configure.in acheader.h gdk/gdkwindow.c Check for Shape extension both on Sun May 3 13:38:22 1998 Owen Taylor <otaylor@gtk.org> * configure.in acheader.h gdk/gdkwindow.c Check for Shape extension both on the client and server side. (And, more importantly, check for the shape extension so we may include -lXext even when compiling with --disable-xshm) Don't set override_redirect on all shaped windows. It isn't necessary. * gdk/gdkwindow.c: Set ->colormap to NULL for root and foreign windows. Use this to check if we need to get the colormap from X. Fri May 1 22:32:47 1998 Owen Taylor <otaylor@gtk.org> * gtk/gtkbutton.c (gtk_button_paint): Draw the areas between the default and the button always in GTK_STATE_NORMAL. * gtk/gtkrange.c (gtk_range_style_set): Added a style_set callback. Fri May 1 16:40:57 1998 Owen Taylor <otaylor@gtk.org> * gdk/gdkpixmap.c (gdk_pixmap_colormap_create_from_xpmp[_d]): Fix a buffer overflow on pixmaps that claim to have more than 31 characters per pixel. (gdk_pixmap_read_string): Don't wrap around strings longer than half of address space ;-) * gtk/gtk[vh]ruler.c gtk/gtkinputdialog.c: Expand some buffers that were used for printing integers. * */* (almost): Style: All int foo () { ... } changed to int foo (void) { ... } ^^^^^^^ This is why some many files changed Even where there were proper prototypes elsewhere. * gdk/gxid.c (handle_claim_device): Some extra checks. It isn't safe against being fed bad X id's, but at least it should be safe against deleting all your files.
1998-05-03 22:41:32 +00:00
gtk_scrolled_window_get_type (void)
1997-11-24 22:37:52 +00:00
{
static GtkType scrolled_window_type = 0;
1997-11-24 22:37:52 +00:00
if (!scrolled_window_type)
{
GtkTypeInfo scrolled_window_info =
{
"GtkScrolledWindow",
sizeof (GtkScrolledWindow),
sizeof (GtkScrolledWindowClass),
(GtkClassInitFunc) gtk_scrolled_window_class_init,
(GtkObjectInitFunc) gtk_scrolled_window_init,
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
call the base class init fucntions from all parent types upon class Sun Jun 28 04:29:10 1998 Tim Janik <timj@gtk.org> * gtk/gtktypeutils.c (gtk_type_class_init): call the base class init fucntions from all parent types upon class initialization. * gtk/gtkcontainer.c: (gtk_container_get_type): announce gtk_container_base_class_init to the type system. (gtk_container_base_class_init): new function to feature base class initialization. (gtk_container_get_child_arg): (gtk_container_set_child_arg): call the GtkContainerClass get_child_arg and set_child_arg methods of the class indicated through the argument name. * gtk/gtkobject.c: (gtk_object_base_class_init): new function to feature base class initialization. (gtk_object_init_type): announce gtk_object_base_class_init to the type system. (gtk_object_class_init): setup the get_arg and set_arg pointers for GtkObjectClass. (gtk_object_setv): (gtk_object_getv): call the GtkObjectClass get_arg and set_arg methods, instead of bothering the type system with this. * gtk/gtkaccellabel.c: * gtk/gtkbutton.c: * gtk/gtkradiobutton.c: * gtk/gtktable.c: * gtk/gtktogglebutton.c: * gtk/gtktipsquery.c: * gtk/gtkbox.c: * gtk/gtkpacker.c: * gtk/gtkwidget.c: * gtk/gtkwindow.c: * gtk/gtkframe.c: * gtk/gtkmisc.c: * gtk/gtklabel.c: set the object_class->{g|s}et_arg pointers to the corresponding gtk_*_{g|s]et_arg functions and updated the gtk_*_get_type functions wrt GtkTypeInfo initialization. changed a lot of the set/get arg functions to take a GtkObject argument. gtk/gtkadjustment.c: gtk/gtkalignment.c: gtk/gtkarrow.c: gtk/gtkaspectframe.c: gtk/gtkbbox.c: gtk/gtkbin.c: gtk/gtkcheckbutton.c: gtk/gtkcheckmenuitem.c: gtk/gtkclist.c: gtk/gtkcolorsel.c: gtk/gtkcombo.c: gtk/gtkctree.c: gtk/gtkcurve.c: gtk/gtkdata.c: gtk/gtkdialog.c: gtk/gtkdrawingarea.c: gtk/gtkeditable.c: gtk/gtkentry.c: gtk/gtkeventbox.c: gtk/gtkfilesel.c: gtk/gtkfixed.c: gtk/gtkfontsel.c: gtk/gtkgamma.c: gtk/gtkhandlebox.c: gtk/gtkhbbox.c: gtk/gtkhbox.c: gtk/gtkhpaned.c: gtk/gtkhruler.c: gtk/gtkhscale.c: gtk/gtkhscrollbar.c: gtk/gtkhseparator.c: gtk/gtkimage.c: gtk/gtkinputdialog.c: gtk/gtkitem.c: gtk/gtkitemfactory.c: gtk/gtklist.c: gtk/gtklistitem.c: gtk/gtkmenu.c: gtk/gtkmenubar.c: gtk/gtkmenuitem.c: gtk/gtkmenushell.c: gtk/gtknotebook.c: gtk/gtkoptionmenu.c: gtk/gtkpaned.c: gtk/gtkpixmap.c: gtk/gtkpreview.c: gtk/gtkprogressbar.c: gtk/gtkradiomenuitem.c: gtk/gtkrange.c: gtk/gtkruler.c: gtk/gtkscale.c: gtk/gtkscrollbar.c: gtk/gtkscrolledwindow.c: gtk/gtkseparator.c: gtk/gtkspinbutton.c: gtk/gtkstatusbar.c: gtk/gtktext.c: gtk/gtktoolbar.c: gtk/gtktooltips.c: gtk/gtktree.c: gtk/gtktreeitem.c: gtk/gtkvbbox.c: gtk/gtkvbox.c: gtk/gtkviewport.c: gtk/gtkvpaned.c: gtk/gtkvruler.c: gtk/gtkvscale.c: gtk/gtkvscrollbar.c: gtk/gtkvseparator.c: updated the GtkTypeInfo initialization code to match the modified GtkTypeInfo structure.
1998-06-28 07:46:10 +00:00
(GtkClassInitFunc) NULL,
1997-11-24 22:37:52 +00:00
};
scrolled_window_type = gtk_type_unique (GTK_TYPE_CONTAINER, &scrolled_window_info);
1997-11-24 22:37:52 +00:00
}
return scrolled_window_type;
}
static void
gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
{
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
GtkContainerClass *container_class;
object_class = (GtkObjectClass*) class;
widget_class = (GtkWidgetClass*) class;
container_class = (GtkContainerClass*) class;
parent_class = gtk_type_class (GTK_TYPE_CONTAINER);
gtk_object_add_arg_type ("GtkScrolledWindow::viewport",
GTK_TYPE_VIEWPORT,
GTK_ARG_READWRITE | GTK_ARG_CONSTRUCT,
ARG_VIEWPORT);
gtk_object_add_arg_type ("GtkScrolledWindow::hscrollbar_policy",
GTK_TYPE_POLICY_TYPE,
GTK_ARG_READWRITE,
ARG_HSCROLLBAR_POLICY);
gtk_object_add_arg_type ("GtkScrolledWindow::vscrollbar_policy",
GTK_TYPE_POLICY_TYPE,
GTK_ARG_READWRITE,
ARG_VSCROLLBAR_POLICY);
object_class->set_arg = gtk_scrolled_window_set_arg;
object_class->get_arg = gtk_scrolled_window_get_arg;
1997-11-24 22:37:52 +00:00
object_class->destroy = gtk_scrolled_window_destroy;
object_class->finalize = gtk_scrolled_window_finalize;
1997-11-24 22:37:52 +00:00
widget_class->map = gtk_scrolled_window_map;
widget_class->unmap = gtk_scrolled_window_unmap;
widget_class->draw = gtk_scrolled_window_draw;
widget_class->size_request = gtk_scrolled_window_size_request;
widget_class->size_allocate = gtk_scrolled_window_size_allocate;
container_class->add = gtk_scrolled_window_add;
container_class->remove = gtk_scrolled_window_remove;
container_class->foreach = gtk_scrolled_window_foreach;
class->scrollbar_spacing = 5;
1997-11-24 22:37:52 +00:00
}
static void
gtk_scrolled_window_set_arg (GtkObject *object,
GtkArg *arg,
guint arg_id)
{
GtkScrolledWindow *scrolled_window;
scrolled_window = GTK_SCROLLED_WINDOW (object);
switch (arg_id)
{
GtkWidget *viewport;
case ARG_VIEWPORT:
g_return_if_fail (scrolled_window->viewport == NULL);
viewport = GTK_VALUE_POINTER (*arg);
if (!viewport)
viewport = gtk_viewport_new (NULL, NULL);
scrolled_window->viewport = viewport;
gtk_scrolled_window_construct (scrolled_window, NULL, NULL);
case ARG_HSCROLLBAR_POLICY:
gtk_scrolled_window_set_policy (scrolled_window,
GTK_VALUE_ENUM (*arg),
scrolled_window->vscrollbar_policy);
break;
case ARG_VSCROLLBAR_POLICY:
gtk_scrolled_window_set_policy (scrolled_window,
scrolled_window->hscrollbar_policy,
GTK_VALUE_ENUM (*arg));
break;
default:
break;
}
}
static void
gtk_scrolled_window_get_arg (GtkObject *object,
GtkArg *arg,
guint arg_id)
{
GtkScrolledWindow *scrolled_window;
scrolled_window = GTK_SCROLLED_WINDOW (object);
switch (arg_id)
{
case ARG_VIEWPORT:
GTK_VALUE_POINTER (*arg) = scrolled_window->viewport;
break;
case ARG_HSCROLLBAR_POLICY:
GTK_VALUE_ENUM (*arg) = scrolled_window->hscrollbar_policy;
break;
case ARG_VSCROLLBAR_POLICY:
GTK_VALUE_ENUM (*arg) = scrolled_window->vscrollbar_policy;
break;
default:
arg->type = GTK_TYPE_INVALID;
break;
}
}
1997-11-24 22:37:52 +00:00
static void
gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window)
{
GTK_WIDGET_SET_FLAGS (scrolled_window, GTK_NO_WINDOW);
added a frame with radio buttons to select the resize_mode for the Wed Jun 24 07:47:29 1998 Tim Janik <timj@gtk.org> * gtk/testgtk.c (create_idle_test): added a frame with radio buttons to select the resize_mode for the idle-labels container. * gtk/gtkframe.h: * gtk/gtkframe.c: GtkType and macro corrections. * gtk/gtkradiobutton.c (gtk_radio_button_set_arg): new function to support radio grouping. Tue Jun 23 08:01:09 1998 Tim Janik <timj@gtk.org> * gtk/gtkcontainer.c (gtk_container_set_resize_mode): queue a resize unconditionally if resize_mode has changed. * gtk/gtkscrolledwindow.c (gtk_scrolled_window_init): set GTK_RESIZE_QUEUE on the scrolled window. (gtk_scrolled_window_construct): set GTK_RESIZE_PARENT for the vieport. Tue Jun 23 04:20:30 1998 Tim Janik <timj@gtk.org> * gtk/gtkcontainer.h: * gtk/gtkcontainer.c: (GTK_IS_RESIZE_CONTAINER): new macro to find out if a given gtkobject is a container with resize_mode==GTK_RESIZE_PARENT. (gtk_container_queue_resize): new function to queue a container for a *size* reallocation (doesn't affect its position, and thus its parent is left untouched usually). (gtk_container_get_resize_container): new function to retrive the next most resize container which is not itself queued for a resize. (gtk_container_idle_sizer): new function to carefully process the container_resize_queue since it can change during invokation of gtk_container_check_resize(). (gtk_container_resize_children): total rework of this function to properly handle resize containers. makes a lot of assumptions whitch are stated in the comments. * gtk/gtkcontainer.c: (gtk_container_real_check_resize): only requeue ourselves if we are not a resize container. (gtk_container_clear_resize_widgets): care for automatic deletion of our resize_widgets list on size_allocate through a handler connection. * gtk/gtkwindow.c (gtk_window_shutdown): new functionm to reset the focus and default widget of a window, so to take the burden from gtk_widget_unparent. * gtk/gtkviewport.c: removed gtk_viewport_check_resize, which tried to be clever, but actually messed up the resize_children logic and caused unneccessary allocations on its whole branch. besides this, it messed up the display by not invoking a redraw after the allocation. * gtk/gtktable.c (gtk_table_set_child_arg): reverted recent change, so that it is the child again that is queued for a resize. (gtk_table_attach): likewise. (gtk_table_remove): likewise.
1998-06-24 06:25:14 +00:00
gtk_container_set_resize_mode (GTK_CONTAINER (scrolled_window), GTK_RESIZE_QUEUE);
1997-11-24 22:37:52 +00:00
scrolled_window->hscrollbar = NULL;
scrolled_window->vscrollbar = NULL;
scrolled_window->hscrollbar_policy = GTK_POLICY_ALWAYS;
scrolled_window->vscrollbar_policy = GTK_POLICY_ALWAYS;
}
GtkWidget*
gtk_scrolled_window_new (GtkAdjustment *hadjustment,
GtkAdjustment *vadjustment)
{
GtkWidget *scrolled_window;
1997-11-24 22:37:52 +00:00
scrolled_window = gtk_type_new (GTK_TYPE_SCROLLED_WINDOW);
1997-11-24 22:37:52 +00:00
gtk_scrolled_window_construct (GTK_SCROLLED_WINDOW (scrolled_window), hadjustment, vadjustment);
return scrolled_window;
}
void
gtk_scrolled_window_construct (GtkScrolledWindow *scrolled_window,
GtkAdjustment *hadjustment,
GtkAdjustment *vadjustment)
{
g_return_if_fail (scrolled_window != NULL);
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
g_return_if_fail (scrolled_window->hscrollbar == NULL);
g_return_if_fail (scrolled_window->vscrollbar == NULL);
if (scrolled_window->viewport)
g_return_if_fail (hadjustment == NULL && vadjustment == NULL);
else
scrolled_window->viewport = gtk_viewport_new (hadjustment, vadjustment);
1997-11-24 22:37:52 +00:00
hadjustment = gtk_viewport_get_hadjustment (GTK_VIEWPORT (scrolled_window->viewport));
vadjustment = gtk_viewport_get_vadjustment (GTK_VIEWPORT (scrolled_window->viewport));
added a frame with radio buttons to select the resize_mode for the Wed Jun 24 07:47:29 1998 Tim Janik <timj@gtk.org> * gtk/testgtk.c (create_idle_test): added a frame with radio buttons to select the resize_mode for the idle-labels container. * gtk/gtkframe.h: * gtk/gtkframe.c: GtkType and macro corrections. * gtk/gtkradiobutton.c (gtk_radio_button_set_arg): new function to support radio grouping. Tue Jun 23 08:01:09 1998 Tim Janik <timj@gtk.org> * gtk/gtkcontainer.c (gtk_container_set_resize_mode): queue a resize unconditionally if resize_mode has changed. * gtk/gtkscrolledwindow.c (gtk_scrolled_window_init): set GTK_RESIZE_QUEUE on the scrolled window. (gtk_scrolled_window_construct): set GTK_RESIZE_PARENT for the vieport. Tue Jun 23 04:20:30 1998 Tim Janik <timj@gtk.org> * gtk/gtkcontainer.h: * gtk/gtkcontainer.c: (GTK_IS_RESIZE_CONTAINER): new macro to find out if a given gtkobject is a container with resize_mode==GTK_RESIZE_PARENT. (gtk_container_queue_resize): new function to queue a container for a *size* reallocation (doesn't affect its position, and thus its parent is left untouched usually). (gtk_container_get_resize_container): new function to retrive the next most resize container which is not itself queued for a resize. (gtk_container_idle_sizer): new function to carefully process the container_resize_queue since it can change during invokation of gtk_container_check_resize(). (gtk_container_resize_children): total rework of this function to properly handle resize containers. makes a lot of assumptions whitch are stated in the comments. * gtk/gtkcontainer.c: (gtk_container_real_check_resize): only requeue ourselves if we are not a resize container. (gtk_container_clear_resize_widgets): care for automatic deletion of our resize_widgets list on size_allocate through a handler connection. * gtk/gtkwindow.c (gtk_window_shutdown): new functionm to reset the focus and default widget of a window, so to take the burden from gtk_widget_unparent. * gtk/gtkviewport.c: removed gtk_viewport_check_resize, which tried to be clever, but actually messed up the resize_children logic and caused unneccessary allocations on its whole branch. besides this, it messed up the display by not invoking a redraw after the allocation. * gtk/gtktable.c (gtk_table_set_child_arg): reverted recent change, so that it is the child again that is queued for a resize. (gtk_table_attach): likewise. (gtk_table_remove): likewise.
1998-06-24 06:25:14 +00:00
gtk_container_set_resize_mode (GTK_CONTAINER (scrolled_window->viewport), GTK_RESIZE_PARENT);
1997-11-24 22:37:52 +00:00
gtk_signal_connect (GTK_OBJECT (hadjustment), "changed",
(GtkSignalFunc) gtk_scrolled_window_adjustment_changed,
(gpointer) scrolled_window);
gtk_signal_connect (GTK_OBJECT (vadjustment), "changed",
(GtkSignalFunc) gtk_scrolled_window_adjustment_changed,
(gpointer) scrolled_window);
scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
scrolled_window->vscrollbar = gtk_vscrollbar_new (vadjustment);
gtk_widget_set_parent (scrolled_window->viewport, GTK_WIDGET (scrolled_window));
gtk_widget_set_parent (scrolled_window->hscrollbar, GTK_WIDGET (scrolled_window));
gtk_widget_set_parent (scrolled_window->vscrollbar, GTK_WIDGET (scrolled_window));
gtk_widget_show (scrolled_window->viewport);
gtk_widget_show (scrolled_window->hscrollbar);
gtk_widget_show (scrolled_window->vscrollbar);
gtk_widget_ref (scrolled_window->viewport);
gtk_widget_ref (scrolled_window->hscrollbar);
gtk_widget_ref (scrolled_window->vscrollbar);
1997-11-24 22:37:52 +00:00
}
GtkAdjustment*
gtk_scrolled_window_get_hadjustment (GtkScrolledWindow *scrolled_window)
{
g_return_val_if_fail (scrolled_window != NULL, NULL);
g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
return gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar));
}
GtkAdjustment*
gtk_scrolled_window_get_vadjustment (GtkScrolledWindow *scrolled_window)
{
g_return_val_if_fail (scrolled_window != NULL, NULL);
g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
return gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar));
}
void
gtk_scrolled_window_set_policy (GtkScrolledWindow *scrolled_window,
GtkPolicyType hscrollbar_policy,
GtkPolicyType vscrollbar_policy)
{
g_return_if_fail (scrolled_window != NULL);
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
if ((scrolled_window->hscrollbar_policy != hscrollbar_policy) ||
(scrolled_window->vscrollbar_policy != vscrollbar_policy))
{
scrolled_window->hscrollbar_policy = hscrollbar_policy;
scrolled_window->vscrollbar_policy = vscrollbar_policy;
if (GTK_WIDGET (scrolled_window)->parent)
gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
}
}
static void
gtk_scrolled_window_destroy (GtkObject *object)
{
GtkScrolledWindow *scrolled_window;
g_return_if_fail (object != NULL);
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (object));
scrolled_window = GTK_SCROLLED_WINDOW (object);
gtk_widget_destroy (scrolled_window->viewport);
gtk_widget_destroy (scrolled_window->hscrollbar);
gtk_widget_destroy (scrolled_window->vscrollbar);
if (GTK_OBJECT_CLASS (parent_class)->destroy)
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}
static void
gtk_scrolled_window_finalize (GtkObject *object)
{
GtkScrolledWindow *scrolled_window;
scrolled_window = GTK_SCROLLED_WINDOW (object);
gtk_widget_unref (scrolled_window->viewport);
gtk_widget_unref (scrolled_window->hscrollbar);
gtk_widget_unref (scrolled_window->vscrollbar);
GTK_OBJECT_CLASS (parent_class)->finalize (object);
}
1997-11-24 22:37:52 +00:00
static void
gtk_scrolled_window_map (GtkWidget *widget)
{
GtkScrolledWindow *scrolled_window;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (widget));
if (!GTK_WIDGET_MAPPED (widget))
{
GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
scrolled_window = GTK_SCROLLED_WINDOW (widget);
if (GTK_WIDGET_VISIBLE (scrolled_window->viewport) &&
!GTK_WIDGET_MAPPED (scrolled_window->viewport))
gtk_widget_map (scrolled_window->viewport);
if (GTK_WIDGET_VISIBLE (scrolled_window->hscrollbar) &&
!GTK_WIDGET_MAPPED (scrolled_window->hscrollbar))
gtk_widget_map (scrolled_window->hscrollbar);
if (GTK_WIDGET_VISIBLE (scrolled_window->vscrollbar) &&
!GTK_WIDGET_MAPPED (scrolled_window->vscrollbar))
gtk_widget_map (scrolled_window->vscrollbar);
}
}
static void
gtk_scrolled_window_unmap (GtkWidget *widget)
{
GtkScrolledWindow *scrolled_window;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (widget));
if (GTK_WIDGET_MAPPED (widget))
{
GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
scrolled_window = GTK_SCROLLED_WINDOW (widget);
if (GTK_WIDGET_MAPPED (scrolled_window->viewport))
gtk_widget_unmap (scrolled_window->viewport);
if (GTK_WIDGET_MAPPED (scrolled_window->hscrollbar))
gtk_widget_unmap (scrolled_window->hscrollbar);
if (GTK_WIDGET_MAPPED (scrolled_window->vscrollbar))
gtk_widget_unmap (scrolled_window->vscrollbar);
}
}
static void
gtk_scrolled_window_draw (GtkWidget *widget,
GdkRectangle *area)
{
GtkScrolledWindow *scrolled_window;
GdkRectangle child_area;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (widget));
g_return_if_fail (area != NULL);
if (GTK_WIDGET_DRAWABLE (widget))
{
scrolled_window = GTK_SCROLLED_WINDOW (widget);
if (gtk_widget_intersect (scrolled_window->viewport, area, &child_area))
gtk_widget_draw (scrolled_window->viewport, &child_area);
if (gtk_widget_intersect (scrolled_window->hscrollbar, area, &child_area))
gtk_widget_draw (scrolled_window->hscrollbar, &child_area);
if (gtk_widget_intersect (scrolled_window->vscrollbar, area, &child_area))
gtk_widget_draw (scrolled_window->vscrollbar, &child_area);
}
}
static void
gtk_scrolled_window_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
GtkScrolledWindow *scrolled_window;
gint extra_height;
gint extra_width;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (widget));
g_return_if_fail (requisition != NULL);
scrolled_window = GTK_SCROLLED_WINDOW (widget);
requisition->width = 0;
requisition->height = 0;
if (GTK_WIDGET_VISIBLE (scrolled_window->viewport))
{
gtk_widget_size_request (scrolled_window->viewport, &scrolled_window->viewport->requisition);
requisition->width += scrolled_window->viewport->requisition.width;
requisition->height += scrolled_window->viewport->requisition.height;
}
extra_width = 0;
extra_height = 0;
if ((scrolled_window->hscrollbar_policy == GTK_POLICY_AUTOMATIC) ||
GTK_WIDGET_VISIBLE (scrolled_window->hscrollbar))
{
gtk_widget_size_request (scrolled_window->hscrollbar,
&scrolled_window->hscrollbar->requisition);
requisition->width = MAX (requisition->width, scrolled_window->hscrollbar->requisition.width);
extra_height = SCROLLBAR_SPACING (scrolled_window) + scrolled_window->hscrollbar->requisition.height;
1997-11-24 22:37:52 +00:00
}
if ((scrolled_window->vscrollbar_policy == GTK_POLICY_AUTOMATIC) ||
GTK_WIDGET_VISIBLE (scrolled_window->vscrollbar))
{
gtk_widget_size_request (scrolled_window->vscrollbar,
&scrolled_window->vscrollbar->requisition);
requisition->height = MAX (requisition->height, scrolled_window->vscrollbar->requisition.height);
extra_width = SCROLLBAR_SPACING (scrolled_window) + scrolled_window->vscrollbar->requisition.width;
1997-11-24 22:37:52 +00:00
}
requisition->width += GTK_CONTAINER (widget)->border_width * 2 + extra_width;
requisition->height += GTK_CONTAINER (widget)->border_width * 2 + extra_height;
}
static void
gtk_scrolled_window_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
GtkScrolledWindow *scrolled_window;
GtkAllocation viewport_allocation;
GtkAllocation child_allocation;
guint previous_hvis;
guint previous_vvis;
gint count;
1997-11-24 22:37:52 +00:00
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (widget));
g_return_if_fail (allocation != NULL);
scrolled_window = GTK_SCROLLED_WINDOW (widget);
widget->allocation = *allocation;
if (scrolled_window->hscrollbar_policy == GTK_POLICY_ALWAYS)
scrolled_window->hscrollbar_visible = TRUE;
if (scrolled_window->vscrollbar_policy == GTK_POLICY_ALWAYS)
scrolled_window->vscrollbar_visible = TRUE;
1997-11-24 22:37:52 +00:00
if (GTK_WIDGET_VISIBLE (scrolled_window->viewport))
{
count = 0;
1997-11-24 22:37:52 +00:00
do {
gtk_scrolled_window_viewport_allocate (widget, &viewport_allocation);
child_allocation.x = viewport_allocation.x + allocation->x;
child_allocation.y = viewport_allocation.y + allocation->y;
child_allocation.width = viewport_allocation.width;
child_allocation.height = viewport_allocation.height;
previous_hvis = scrolled_window->hscrollbar_visible;
previous_vvis = scrolled_window->vscrollbar_visible;
1997-11-24 22:37:52 +00:00
gtk_widget_size_allocate (scrolled_window->viewport, &child_allocation);
/* If, after the first iteration, the hscrollbar and the
* vscrollbar flip visiblity, then we need both.
*/
if ((count++) &&
(previous_hvis != scrolled_window->hscrollbar_visible) &&
(previous_vvis != scrolled_window->vscrollbar_visible))
{
scrolled_window->hscrollbar_visible = TRUE;
scrolled_window->vscrollbar_visible = TRUE;
break;
}
count++;
} while ((previous_hvis != scrolled_window->hscrollbar_visible) ||
(previous_vvis != scrolled_window->vscrollbar_visible));
1997-11-24 22:37:52 +00:00
}
if (scrolled_window->hscrollbar_visible)
1997-11-24 22:37:52 +00:00
{
if (!GTK_WIDGET_VISIBLE (scrolled_window->hscrollbar))
gtk_widget_show (scrolled_window->hscrollbar);
1997-11-24 22:37:52 +00:00
child_allocation.x = viewport_allocation.x;
child_allocation.y = viewport_allocation.y + viewport_allocation.height + SCROLLBAR_SPACING (scrolled_window);
1997-11-24 22:37:52 +00:00
child_allocation.width = viewport_allocation.width;
child_allocation.height = scrolled_window->hscrollbar->requisition.height;
child_allocation.x += allocation->x;
child_allocation.y += allocation->y;
gtk_widget_size_allocate (scrolled_window->hscrollbar, &child_allocation);
}
else
{
if (GTK_WIDGET_VISIBLE (scrolled_window->hscrollbar))
gtk_widget_hide (scrolled_window->hscrollbar);
}
1997-11-24 22:37:52 +00:00
if (scrolled_window->vscrollbar_visible)
1997-11-24 22:37:52 +00:00
{
if (!GTK_WIDGET_VISIBLE (scrolled_window->vscrollbar))
gtk_widget_show (scrolled_window->vscrollbar);
child_allocation.x = viewport_allocation.x + viewport_allocation.width + SCROLLBAR_SPACING (scrolled_window);
1997-11-24 22:37:52 +00:00
child_allocation.y = viewport_allocation.y;
child_allocation.width = scrolled_window->vscrollbar->requisition.width;
child_allocation.height = viewport_allocation.height;
child_allocation.x += allocation->x;
child_allocation.y += allocation->y;
gtk_widget_size_allocate (scrolled_window->vscrollbar, &child_allocation);
}
else
{
if (GTK_WIDGET_VISIBLE (scrolled_window->vscrollbar))
gtk_widget_hide (scrolled_window->vscrollbar);
}
1997-11-24 22:37:52 +00:00
}
static void
gtk_scrolled_window_add (GtkContainer *container,
GtkWidget *widget)
{
GtkScrolledWindow *scrolled_window;
g_return_if_fail (container != NULL);
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container));
g_return_if_fail (widget != NULL);
scrolled_window = GTK_SCROLLED_WINDOW (container);
gtk_container_add (GTK_CONTAINER (scrolled_window->viewport), widget);
}
static void
gtk_scrolled_window_remove (GtkContainer *container,
GtkWidget *widget)
{
GtkScrolledWindow *scrolled_window;
g_return_if_fail (container != NULL);
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container));
g_return_if_fail (widget != NULL);
scrolled_window = GTK_SCROLLED_WINDOW (container);
if (scrolled_window->viewport == widget ||
scrolled_window->hscrollbar == widget ||
scrolled_window->vscrollbar == widget)
{
/* this happens during destroy */
gtk_widget_unparent (widget);
}
else
gtk_container_remove (GTK_CONTAINER (scrolled_window->viewport), widget);
1997-11-24 22:37:52 +00:00
}
static void
gtk_scrolled_window_foreach (GtkContainer *container,
GtkCallback callback,
gpointer callback_data)
{
GtkScrolledWindow *scrolled_window;
g_return_if_fail (container != NULL);
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container));
g_return_if_fail (callback != NULL);
scrolled_window = GTK_SCROLLED_WINDOW (container);
if (scrolled_window->viewport)
(* callback) (scrolled_window->viewport, callback_data);
(* callback) (scrolled_window->vscrollbar, callback_data);
(* callback) (scrolled_window->hscrollbar, callback_data);
1997-11-24 22:37:52 +00:00
}
static void
gtk_scrolled_window_viewport_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
GtkScrolledWindow *scrolled_window;
g_return_if_fail (widget != NULL);
g_return_if_fail (allocation != NULL);
scrolled_window = GTK_SCROLLED_WINDOW (widget);
allocation->x = GTK_CONTAINER (widget)->border_width;
allocation->y = GTK_CONTAINER (widget)->border_width;
allocation->width = MAX (1, widget->allocation.width - allocation->x * 2);
allocation->height = MAX (1, widget->allocation.height - allocation->y * 2);
1997-11-24 22:37:52 +00:00
if (scrolled_window->vscrollbar_visible)
allocation->width = MAX (1,
allocation->width - (scrolled_window->vscrollbar->requisition.width + SCROLLBAR_SPACING (scrolled_window)));
if (scrolled_window->hscrollbar_visible)
allocation->height = MAX (1,
allocation->height - (scrolled_window->hscrollbar->requisition.height + SCROLLBAR_SPACING (scrolled_window)));
1997-11-24 22:37:52 +00:00
}
static void
gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
gpointer data)
{
GtkScrolledWindow *scrolled_win;
g_return_if_fail (adjustment != NULL);
g_return_if_fail (data != NULL);
scrolled_win = GTK_SCROLLED_WINDOW (data);
if (adjustment == gtk_range_get_adjustment (GTK_RANGE (scrolled_win->hscrollbar)))
{
if (scrolled_win->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
{
scrolled_win->hscrollbar_visible =
((adjustment->upper - adjustment->lower) > adjustment->page_size);
}
1997-11-24 22:37:52 +00:00
}
else if (adjustment == gtk_range_get_adjustment (GTK_RANGE (scrolled_win->vscrollbar)))
{
if (scrolled_win->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
{
scrolled_win->vscrollbar_visible =
((adjustment->upper - adjustment->lower) > adjustment->page_size);
}
1997-11-24 22:37:52 +00:00
}
else
{
g_warning ("could not determine which adjustment scrollbar received change signal for");
return;
}
}