summaryrefslogtreecommitdiff
path: root/gtk/gtkscrolledwindow.c
diff options
context:
space:
mode:
authorTim Janik <timj@gtk.org>1998-11-23 01:54:45 +0000
committerTim Janik <timj@src.gnome.org>1998-11-23 01:54:45 +0000
commit98e22a43ab25649842fde09ac0bc0e764c9a9dca (patch)
treec17939c89cd902660a1fa677d5b7177a45d4d336 /gtk/gtkscrolledwindow.c
parent12f7825907f9398ba09c90650afea0305d6dd629 (diff)
downloadgtk+-98e22a43ab25649842fde09ac0bc0e764c9a9dca.tar.gz
added args ::show_text, ::text_xalign, ::text_yalign, ::activity_mode.
Sun Nov 22 16:21:28 1998 Tim Janik <timj@gtk.org> * gtk/gtkprogress.c: added args ::show_text, ::text_xalign, ::text_yalign, ::activity_mode. * gtk/gtkprogressbar.c: added construct arg ::adjustment. added args ::bar_style, ::orientation, ::discrete_blocks, ::activity_step, ::activity_blocks. (gtk_progress_bar_new): (gtk_progress_bar_new_with_adjustment): use gtk_widget_new(). (gtk_progress_bar_construct): deprecated. * gtk/gtkvscrollbar.c: (gtk_vscrollbar_draw_step_back): (gtk_vscrollbar_draw_step_forw): use "vscrollbar" as detail for gtk_paint_arrow, to be consistent with hscrollbar. * gtk/gtktext.c added construct args ::hadjustment, ::vadjustment. added args ::line_wrap, ::word_wrap. (gtk_text_class_init): added scroll_adjustments signal. (gtk_text_new): use gtk_widget_new. (gtk_text_disconnect): remove adjustement with gtk_text_set_adjustments, so we don't screw the reference counts and don't leave signals connected. (gtk_text_destroy): disconnect adjustments signals. (gtk_text_finalize): unref adjustments. * gtk/gtkctree.c: added construct args ::n_columns and ::tree_column. added args ::indent, ::spacing, ::show_stub, ::reorderable, ::use_drag_icons, ::line_style and ::expander_style. (gtk_ctree_set_show_stub): renamed from gtk_ctree_show_stub, which is deprecated now. * gtk/gtkclist.h: remove GTK_CLIST_CONSTRUCT flag. * gtk/gtkclist.c: removed ::vadjustment and ::hadjustment args, introduced ::scroll_adjustments signal. added ::shadow_type, ::selection_mode and ::row_height args. added n_columns construct arg. (gtk_clist_construct): call gtk_object_constructed(). (gtk_clist_set_row_height): if height is passed as 0, revert to automatic height calculation. (gtk_clist_destroy): before unrefing the adjustments, disconnect our signal handlers. Fri Nov 21 22:34:58 1998 Tim Janik <timj@gtk.org> * gtk/gtkwidget.c (gtk_widget_new): call gtk_object_default_construct like gtk_object_new. (gtk_widget_destroy): assert that we only destroy constructed widgets. * gtk/gtkobject.h (enum GtkArgFlags): new flag GTK_ARG_CONSTRUCT_ONLY to identify args that may only be used for construction. GTK_ARG_CONSTRUCT maybe used as normal arguments besides construction time. * gtk/gtkobject.c (gtk_object_new): invoke gtk_object_default_construct at the end if the object is not fully constructed. (gtk_object_newv): likewise. (gtk_object_destroy): assert that we only destroy constructed objects. (gtk_object_init): setup GTK_CONSTRUCTED from the objects real klass. (gtk_object_default_construct): new function to complete default construction of an object by applying missing construtor args with default values of 0, 0.0 or NULL. (gtk_object_constructed): new function to mark an object as being constructed (used from within constructors). * gtk/gtkarg.c (gtk_arg_type_new_static): return the args info pointer so it is immediatedly available for the caller. * gtk/gtktypeutils.c (gtk_type_new): pass an object's real class to the object initilizer (GtkObjectInitFunc takes a second arg now, the real klass), and asure that object initializers may temporarily alter the class pointer. Fri Nov 20 08:00:30 1998 Tim Janik <timj@gtk.org> * gtk/testgtk.c: change all occourances of gtk_container_add ( scrolled_window, widget) to gtk_scrolled_window_add_with_viewport (...) for widget!=(clist, ctree, text, viewport). * gtk/gtkcombo.c: (gtk_combo_init): use gtk_scrolled_window_add_with_viewport() to add children to the scrolled window. * gtk/gtkscrolledwindow.h: * gtk/gtkscrolledwindow.c: changed scrolled_window->viewport to scrolled_window->child, and use gtk_widget_scroll_adjustements() to set the scroll adjustments for the widget, we do not create an additional viewport anymore. added ::hadjustment and ::vadjustment constructor args. (gtk_scrolled_window_new): use gtk_widget_new() to create the widget. (gtk_scrolled_window_set_hadjustment): (gtk_scrolled_window_set_vadjustment): new functions that superceed gtk_scrolled_window_construct. (gtk_scrolled_window_construct): deprecated this function. * gtk/gtkhscrollbar.c: * gtk/gtkvscrollbar.c: * gtk/gtkhscale.c: * gtk/gtkvscale.c: support a constructor arg "::adjustment", and use gtk_widget_new() for the widget creation. * gtk/gtkrange.c: added ::update_policy arg. (gtk_range_set_adjustment): if adjustment is passed in as NULL, create a default adjustment so this function can be used for derived widgets that depend on the adjustment's existance. (gtk_range_destroy): disconnect the adjustment signal, so we don't get called after we got destroyed, we don't destroy the adjustment in here, because it might have been provided from another widget. * gtk/gtkviewport.c: introduced ::scroll_adjustments signal. (gtk_viewport_destroy): same as gtk_range_destroy. * gtk/gtkprogress.c (gtk_progress_destroy): same as gtk_range_destroy. * gtk/gtkwidget.h: * gtk/gtkwidget.c: changed gtk_widget_activate() to return a gboolean, indicating whether this widget supports activation. added gtk_widget_scroll_adjustements() to set the scrolling adjustments of a widget. Wed Nov 19 01:22:42 1998 Tim Janik <timj@gtk.org> * gtk/gtkoptionmenu.c: (gtk_option_menu_remove_contents): (gtk_option_menu_update_contents): removed gtk_container_[un]block_resize() pairs. * gtk/gtknotebook.h: * gtk/gtknotebook.c: removed the tab_border field, since it shouldn't be used outside of gtknotebook.c anyways. made ARG_TAB_BORDER a wrtie-only argument. * *.c: made deprecated functions issue a message: gtk_clist_set_border, gtk_container_block_resize, gtk_container_unblock_resize, gtk_container_need_resize, gtk_object_class_add_user_signal, gtk_spin_button_construct, gtk_scrolled_window_construct. removed non-functional functions: gtk_container_disable_resize, gtk_container_enable_resize, gtk_clist_set_policy. Wed Nov 18 22:54:36 1998 Tim Janik <timj@gtk.org> * gtk/gtkbox.c (gtk_box_init): * gtk/gtkdrawingarea.c (gtk_drawing_area_init): * gtk/gtkeventbox.c (gtk_event_box_init): * gtk/gtkfixed.c (gtk_fixed_init): * gtk/gtkframe.c (gtk_frame_init): * gtk/gtkhandlebox.c (gtk_handle_box_init): * gtk/gtkpacker.c (gtk_packer_init): * gtk/gtkmisc.c (gtk_misc_init): * gtk/gtkpreview.c (gtk_preview_init): * gtk/gtkprogress.c (gtk_progress_init): * gtk/gtkprogressbar.c (gtk_progress_bar_init): * gtk/gtkseparator.c (gtk_separator_init): * gtk/gtktable.c (gtk_table_init): * gtk/gtkviewport.c (gtk_viewport_init): * gtk/gtkalignment.c (gtk_alignment_init): removed setting of the GTK_BASIC flag. * gtk/gtkwidget.h: * gtk/gtkwidget.c: removed GTK_BASIC, GTK_WIDGET_BASIC and gtk_widget_basic. * miscellaneous GtkType and macro fixups.
Diffstat (limited to 'gtk/gtkscrolledwindow.c')
-rw-r--r--gtk/gtkscrolledwindow.c653
1 files changed, 367 insertions, 286 deletions
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index ce2964dc9c..d68960b924 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -24,7 +24,8 @@
enum {
ARG_0,
- ARG_VIEWPORT,
+ ARG_HADJUSTMENT,
+ ARG_VADJUSTMENT,
ARG_HSCROLLBAR_POLICY,
ARG_VSCROLLBAR_POLICY,
ARG_WINDOW_PLACEMENT
@@ -57,7 +58,7 @@ static void gtk_scrolled_window_forall (GtkContainer *cont
gboolean include_internals,
GtkCallback callback,
gpointer callback_data);
-static void gtk_scrolled_window_viewport_allocate (GtkWidget *widget,
+static void gtk_scrolled_window_relative_allocation(GtkWidget *widget,
GtkAllocation *allocation);
static void gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
gpointer data);
@@ -103,10 +104,14 @@ gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
container_class = (GtkContainerClass*) class;
parent_class = gtk_type_class (GTK_TYPE_CONTAINER);
- gtk_object_add_arg_type ("GtkScrolledWindow::viewport",
- GTK_TYPE_VIEWPORT,
+ gtk_object_add_arg_type ("GtkScrolledWindow::hadjustment",
+ GTK_TYPE_ADJUSTMENT,
GTK_ARG_READWRITE | GTK_ARG_CONSTRUCT,
- ARG_VIEWPORT);
+ ARG_HADJUSTMENT);
+ gtk_object_add_arg_type ("GtkScrolledWindow::vadjustment",
+ GTK_TYPE_ADJUSTMENT,
+ GTK_ARG_READWRITE | GTK_ARG_CONSTRUCT,
+ ARG_VADJUSTMENT);
gtk_object_add_arg_type ("GtkScrolledWindow::hscrollbar_policy",
GTK_TYPE_POLICY_TYPE,
GTK_ARG_READWRITE,
@@ -149,11 +154,12 @@ gtk_scrolled_window_set_arg (GtkObject *object,
switch (arg_id)
{
- GtkWidget *viewport;
-
- case ARG_VIEWPORT:
- viewport = GTK_VALUE_POINTER (*arg);
- gtk_container_add (GTK_CONTAINER (scrolled_window), viewport);
+ case ARG_HADJUSTMENT:
+ gtk_scrolled_window_set_hadjustment (scrolled_window, GTK_VALUE_POINTER (*arg));
+ break;
+ case ARG_VADJUSTMENT:
+ gtk_scrolled_window_set_vadjustment (scrolled_window, GTK_VALUE_POINTER (*arg));
+ break;
case ARG_HSCROLLBAR_POLICY:
gtk_scrolled_window_set_policy (scrolled_window,
GTK_VALUE_ENUM (*arg),
@@ -184,8 +190,11 @@ gtk_scrolled_window_get_arg (GtkObject *object,
switch (arg_id)
{
- case ARG_VIEWPORT:
- GTK_VALUE_POINTER (*arg) = scrolled_window->viewport;
+ case ARG_HADJUSTMENT:
+ GTK_VALUE_POINTER (*arg) = gtk_scrolled_window_get_hadjustment (scrolled_window);
+ break;
+ case ARG_VADJUSTMENT:
+ GTK_VALUE_POINTER (*arg) = gtk_scrolled_window_get_vadjustment (scrolled_window);
break;
case ARG_HSCROLLBAR_POLICY:
GTK_VALUE_ENUM (*arg) = scrolled_window->hscrollbar_policy;
@@ -209,12 +218,14 @@ gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window)
gtk_container_set_resize_mode (GTK_CONTAINER (scrolled_window), GTK_RESIZE_QUEUE);
+ scrolled_window->child = NULL;
scrolled_window->hscrollbar = NULL;
scrolled_window->vscrollbar = NULL;
scrolled_window->hscrollbar_policy = GTK_POLICY_ALWAYS;
scrolled_window->vscrollbar_policy = GTK_POLICY_ALWAYS;
+ scrolled_window->hscrollbar_visible = FALSE;
+ scrolled_window->vscrollbar_visible = FALSE;
scrolled_window->window_placement = GTK_CORNER_TOP_LEFT;
- scrolled_window->autogenerated_viewport = FALSE;
}
GtkWidget*
@@ -223,9 +234,16 @@ gtk_scrolled_window_new (GtkAdjustment *hadjustment,
{
GtkWidget *scrolled_window;
- scrolled_window = gtk_type_new (GTK_TYPE_SCROLLED_WINDOW);
+ if (hadjustment)
+ g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), NULL);
+
+ if (vadjustment)
+ g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), NULL);
- gtk_scrolled_window_construct (GTK_SCROLLED_WINDOW (scrolled_window), hadjustment, vadjustment);
+ scrolled_window = gtk_widget_new (GTK_TYPE_SCROLLED_WINDOW,
+ "hadjustment", hadjustment,
+ "vadjustment", vadjustment,
+ NULL);
return scrolled_window;
}
@@ -235,34 +253,106 @@ gtk_scrolled_window_construct (GtkScrolledWindow *scrolled_window,
GtkAdjustment *hadjustment,
GtkAdjustment *vadjustment)
{
+ g_message ("gtk_scrolled_window_construct() is deprecated");
+ gtk_scrolled_window_set_hadjustment (scrolled_window, hadjustment);
+ gtk_scrolled_window_set_vadjustment (scrolled_window, vadjustment);
+ gtk_object_default_construct (GTK_OBJECT (scrolled_window));
+}
+
+void
+gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window,
+ GtkAdjustment *hadjustment)
+{
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 (hadjustment)
+ g_return_if_fail (GTK_IS_ADJUSTMENT (hadjustment));
+ else
+ hadjustment = (GtkAdjustment*) gtk_object_new (GTK_TYPE_ADJUSTMENT, NULL);
- scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
- scrolled_window->vscrollbar = gtk_vscrollbar_new (vadjustment);
+ if (!scrolled_window->hscrollbar)
+ {
+ gtk_widget_push_composite_child ();
+ scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
+ gtk_widget_pop_composite_child ();
- hadjustment =
- gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar));
- vadjustment =
- gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar));
+ gtk_widget_set_parent (scrolled_window->hscrollbar, GTK_WIDGET (scrolled_window));
+ gtk_widget_ref (scrolled_window->hscrollbar);
+ gtk_widget_show (scrolled_window->hscrollbar);
+ }
+ else
+ {
+ GtkAdjustment *old_adjustment;
+
+ old_adjustment = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar));
+ if (old_adjustment == hadjustment)
+ return;
+
+ gtk_signal_disconnect_by_func (GTK_OBJECT (old_adjustment),
+ GTK_SIGNAL_FUNC (gtk_scrolled_window_adjustment_changed),
+ scrolled_window);
+ gtk_range_set_adjustment (GTK_RANGE (scrolled_window->hscrollbar),
+ hadjustment);
+ }
+ hadjustment = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar));
+ gtk_signal_connect (GTK_OBJECT (hadjustment),
+ "changed",
+ GTK_SIGNAL_FUNC (gtk_scrolled_window_adjustment_changed),
+ scrolled_window);
+ gtk_scrolled_window_adjustment_changed (hadjustment, scrolled_window);
+
+ if (scrolled_window->child)
+ gtk_widget_scroll_adjustements (scrolled_window->child,
+ gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar)),
+ gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar)));
+}
- 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);
+void
+gtk_scrolled_window_set_vadjustment (GtkScrolledWindow *scrolled_window,
+ GtkAdjustment *vadjustment)
+{
+ g_return_if_fail (scrolled_window != NULL);
+ g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
+ if (vadjustment)
+ g_return_if_fail (GTK_IS_ADJUSTMENT (vadjustment));
+ else
+ vadjustment = (GtkAdjustment*) gtk_object_new (GTK_TYPE_ADJUSTMENT, NULL);
- gtk_widget_set_parent (scrolled_window->hscrollbar, GTK_WIDGET (scrolled_window));
- gtk_widget_set_parent (scrolled_window->vscrollbar, GTK_WIDGET (scrolled_window));
+ if (!scrolled_window->vscrollbar)
+ {
+ gtk_widget_push_composite_child ();
+ scrolled_window->vscrollbar = gtk_vscrollbar_new (vadjustment);
+ gtk_widget_pop_composite_child ();
- gtk_widget_show (scrolled_window->hscrollbar);
- gtk_widget_show (scrolled_window->vscrollbar);
-
- gtk_widget_ref (scrolled_window->hscrollbar);
- gtk_widget_ref (scrolled_window->vscrollbar);
+ gtk_widget_set_parent (scrolled_window->vscrollbar, GTK_WIDGET (scrolled_window));
+ gtk_widget_ref (scrolled_window->vscrollbar);
+ gtk_widget_show (scrolled_window->vscrollbar);
+ }
+ else
+ {
+ GtkAdjustment *old_adjustment;
+
+ old_adjustment = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar));
+ if (old_adjustment == vadjustment)
+ return;
+
+ gtk_signal_disconnect_by_func (GTK_OBJECT (old_adjustment),
+ GTK_SIGNAL_FUNC (gtk_scrolled_window_adjustment_changed),
+ scrolled_window);
+ gtk_range_set_adjustment (GTK_RANGE (scrolled_window->vscrollbar),
+ vadjustment);
+ }
+ vadjustment = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar));
+ gtk_signal_connect (GTK_OBJECT (vadjustment),
+ "changed",
+ GTK_SIGNAL_FUNC (gtk_scrolled_window_adjustment_changed),
+ scrolled_window);
+ gtk_scrolled_window_adjustment_changed (vadjustment, scrolled_window);
+
+ if (scrolled_window->child)
+ gtk_widget_scroll_adjustements (scrolled_window->child,
+ gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar)),
+ gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar)));
}
GtkAdjustment*
@@ -271,7 +361,9 @@ 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));
+ return (scrolled_window->hscrollbar ?
+ gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar)) :
+ NULL);
}
GtkAdjustment*
@@ -280,7 +372,9 @@ 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));
+ return (scrolled_window->vscrollbar ?
+ gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar)) :
+ NULL);
}
void
@@ -297,8 +391,7 @@ gtk_scrolled_window_set_policy (GtkScrolledWindow *scrolled_window,
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));
+ gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
}
}
@@ -313,8 +406,7 @@ gtk_scrolled_window_set_placement (GtkScrolledWindow *scrolled_window,
{
scrolled_window->window_placement = window_placement;
- if (GTK_WIDGET (scrolled_window)->parent)
- gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
+ gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
}
}
@@ -328,7 +420,8 @@ gtk_scrolled_window_destroy (GtkObject *object)
scrolled_window = GTK_SCROLLED_WINDOW (object);
- gtk_widget_destroy (scrolled_window->viewport);
+ gtk_widget_unparent (scrolled_window->hscrollbar);
+ gtk_widget_unparent (scrolled_window->vscrollbar);
gtk_widget_destroy (scrolled_window->hscrollbar);
gtk_widget_destroy (scrolled_window->vscrollbar);
@@ -342,7 +435,7 @@ 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);
@@ -352,20 +445,20 @@ gtk_scrolled_window_finalize (GtkObject *object)
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);
+ GtkScrolledWindow *scrolled_window;
+
scrolled_window = GTK_SCROLLED_WINDOW (widget);
+ GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
- if (scrolled_window->viewport &&
- GTK_WIDGET_VISIBLE (scrolled_window->viewport) &&
- !GTK_WIDGET_MAPPED (scrolled_window->viewport))
- gtk_widget_map (scrolled_window->viewport);
+ if (scrolled_window->child &&
+ GTK_WIDGET_VISIBLE (scrolled_window->child) &&
+ !GTK_WIDGET_MAPPED (scrolled_window->child))
+ gtk_widget_map (scrolled_window->child);
if (GTK_WIDGET_VISIBLE (scrolled_window->hscrollbar) &&
!GTK_WIDGET_MAPPED (scrolled_window->hscrollbar))
@@ -374,31 +467,36 @@ gtk_scrolled_window_map (GtkWidget *widget)
if (GTK_WIDGET_VISIBLE (scrolled_window->vscrollbar) &&
!GTK_WIDGET_MAPPED (scrolled_window->vscrollbar))
gtk_widget_map (scrolled_window->vscrollbar);
+
+ gtk_widget_queue_draw (widget);
}
}
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);
+ GtkScrolledWindow *scrolled_window;
+
scrolled_window = GTK_SCROLLED_WINDOW (widget);
+ GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
- if (scrolled_window->viewport &&
- GTK_WIDGET_MAPPED (scrolled_window->viewport))
- gtk_widget_unmap (scrolled_window->viewport);
+ if (scrolled_window->child &&
+ GTK_WIDGET_VISIBLE (scrolled_window->child) &&
+ GTK_WIDGET_MAPPED (scrolled_window->child))
+ gtk_widget_unmap (scrolled_window->child);
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);
+
+ gtk_widget_queue_clear (widget);
}
}
@@ -406,30 +504,55 @@ 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))
{
+ GtkScrolledWindow *scrolled_window;
+ GdkRectangle child_area;
+
scrolled_window = GTK_SCROLLED_WINDOW (widget);
+
+ if (scrolled_window->child && GTK_WIDGET_VISIBLE (scrolled_window->child) &&
+ gtk_widget_intersect (scrolled_window->child, area, &child_area))
+ gtk_widget_draw (scrolled_window->child, &child_area);
- if (scrolled_window->viewport &&
- 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))
+ if (GTK_WIDGET_VISIBLE (scrolled_window->hscrollbar) &&
+ 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))
+ if (GTK_WIDGET_VISIBLE (scrolled_window->vscrollbar) &&
+ gtk_widget_intersect (scrolled_window->vscrollbar, area, &child_area))
gtk_widget_draw (scrolled_window->vscrollbar, &child_area);
}
}
static void
+gtk_scrolled_window_forall (GtkContainer *container,
+ gboolean include_internals,
+ 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->child)
+ callback (scrolled_window->child, callback_data);
+ if (include_internals)
+ {
+ callback (scrolled_window->vscrollbar, callback_data);
+ callback (scrolled_window->hscrollbar, callback_data);
+ }
+}
+
+static void
gtk_scrolled_window_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
@@ -446,13 +569,12 @@ gtk_scrolled_window_size_request (GtkWidget *widget,
requisition->width = 0;
requisition->height = 0;
- if (scrolled_window->viewport &&
- GTK_WIDGET_VISIBLE (scrolled_window->viewport))
+ if (scrolled_window->child && GTK_WIDGET_VISIBLE (scrolled_window->child))
{
- gtk_widget_size_request (scrolled_window->viewport, &scrolled_window->viewport->requisition);
+ gtk_widget_size_request (scrolled_window->child, &scrolled_window->child->requisition);
- requisition->width += scrolled_window->viewport->requisition.width;
- requisition->height += scrolled_window->viewport->requisition.height;
+ requisition->width += scrolled_window->child->requisition.width;
+ requisition->height += scrolled_window->child->requisition.height;
}
extra_width = 0;
@@ -483,15 +605,52 @@ gtk_scrolled_window_size_request (GtkWidget *widget,
}
static void
+gtk_scrolled_window_relative_allocation (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);
+
+ if (scrolled_window->vscrollbar_visible)
+ {
+ if (scrolled_window->window_placement == GTK_CORNER_TOP_RIGHT ||
+ scrolled_window->window_placement == GTK_CORNER_BOTTOM_RIGHT)
+ allocation->x += (scrolled_window->vscrollbar->requisition.width +
+ SCROLLBAR_SPACING (scrolled_window));
+
+ allocation->width = MAX (1, allocation->width -
+ (scrolled_window->vscrollbar->requisition.width +
+ SCROLLBAR_SPACING (scrolled_window)));
+ }
+ if (scrolled_window->hscrollbar_visible)
+ {
+ if (scrolled_window->window_placement == GTK_CORNER_BOTTOM_LEFT ||
+ scrolled_window->window_placement == GTK_CORNER_BOTTOM_RIGHT)
+ allocation->y += (scrolled_window->hscrollbar->requisition.height +
+ SCROLLBAR_SPACING (scrolled_window));
+
+ allocation->height = MAX (1, allocation->height -
+ (scrolled_window->hscrollbar->requisition.height +
+ SCROLLBAR_SPACING (scrolled_window)));
+ }
+}
+
+static void
gtk_scrolled_window_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
GtkScrolledWindow *scrolled_window;
- GtkAllocation viewport_allocation;
+ GtkAllocation relative_allocation;
GtkAllocation child_allocation;
- guint previous_hvis;
- guint previous_vvis;
- gint count;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (widget));
@@ -505,55 +664,65 @@ gtk_scrolled_window_size_allocate (GtkWidget *widget,
if (scrolled_window->vscrollbar_policy == GTK_POLICY_ALWAYS)
scrolled_window->vscrollbar_visible = TRUE;
- if (scrolled_window->viewport &&
- GTK_WIDGET_VISIBLE (scrolled_window->viewport))
+ if (scrolled_window->child && GTK_WIDGET_VISIBLE (scrolled_window->child))
{
- count = 0;
-
- 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;
-
- 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));
+ gboolean previous_hvis;
+ gboolean previous_vvis;
+ guint count = 0;
+
+ do
+ {
+ gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
+
+ child_allocation.x = relative_allocation.x + allocation->x;
+ child_allocation.y = relative_allocation.y + allocation->y;
+ child_allocation.width = relative_allocation.width;
+ child_allocation.height = relative_allocation.height;
+
+ previous_hvis = scrolled_window->hscrollbar_visible;
+ previous_vvis = scrolled_window->vscrollbar_visible;
+
+ gtk_widget_size_allocate (scrolled_window->child, &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;
+
+ /* a new resize is already queued at this point,
+ * so we will immediatedly get reinvoked
+ */
+ return;
+ }
+
+ count++;
+ }
+ while (previous_hvis != scrolled_window->hscrollbar_visible ||
+ previous_vvis != scrolled_window->vscrollbar_visible);
}
-
+ else
+ gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
+
if (scrolled_window->hscrollbar_visible)
{
if (!GTK_WIDGET_VISIBLE (scrolled_window->hscrollbar))
gtk_widget_show (scrolled_window->hscrollbar);
- child_allocation.x = viewport_allocation.x;
+ child_allocation.x = relative_allocation.x;
if (scrolled_window->window_placement == GTK_CORNER_TOP_LEFT ||
scrolled_window->window_placement == GTK_CORNER_TOP_RIGHT)
- child_allocation.y = (viewport_allocation.y +
- viewport_allocation.height +
+ child_allocation.y = (relative_allocation.y +
+ relative_allocation.height +
SCROLLBAR_SPACING (scrolled_window));
else
child_allocation.y = GTK_CONTAINER (scrolled_window)->border_width;
- child_allocation.width = viewport_allocation.width;
+ child_allocation.width = relative_allocation.width;
child_allocation.height = scrolled_window->hscrollbar->requisition.height;
child_allocation.x += allocation->x;
child_allocation.y += allocation->y;
@@ -570,15 +739,15 @@ gtk_scrolled_window_size_allocate (GtkWidget *widget,
if (scrolled_window->window_placement == GTK_CORNER_TOP_LEFT ||
scrolled_window->window_placement == GTK_CORNER_BOTTOM_LEFT)
- child_allocation.x = (viewport_allocation.x +
- viewport_allocation.width +
+ child_allocation.x = (relative_allocation.x +
+ relative_allocation.width +
SCROLLBAR_SPACING (scrolled_window));
else
child_allocation.x = GTK_CONTAINER (scrolled_window)->border_width;
- child_allocation.y = viewport_allocation.y;
+ child_allocation.y = relative_allocation.y;
child_allocation.width = scrolled_window->vscrollbar->requisition.width;
- child_allocation.height = viewport_allocation.height;
+ child_allocation.height = relative_allocation.height;
child_allocation.x += allocation->x;
child_allocation.y += allocation->y;
@@ -588,209 +757,121 @@ gtk_scrolled_window_size_allocate (GtkWidget *widget,
gtk_widget_hide (scrolled_window->vscrollbar);
}
+
static void
-gtk_scrolled_window_add (GtkContainer *container,
- GtkWidget *widget)
+gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
+ gpointer data)
{
- GtkScrolledWindow *scrolled_window;
- GtkArgInfo *info_hadj;
- GtkArgInfo *info_vadj;
- gchar *error;
-
- g_return_if_fail (container != NULL);
- g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container));
- g_return_if_fail (widget != NULL);
+ GtkScrolledWindow *scrolled_win;
- scrolled_window = GTK_SCROLLED_WINDOW (container);
+ g_return_if_fail (adjustment != NULL);
+ g_return_if_fail (data != NULL);
- if (scrolled_window->viewport)
- gtk_container_remove (container, scrolled_window->viewport);
+ scrolled_win = GTK_SCROLLED_WINDOW (data);
- error = gtk_object_arg_get_info (GTK_OBJECT_TYPE (widget),
- "hadjustment", &info_hadj);
- if (!error)
+ if (adjustment == gtk_range_get_adjustment (GTK_RANGE (scrolled_win->hscrollbar)))
{
- error = gtk_object_arg_get_info (GTK_OBJECT_TYPE (widget),
- "vadjustment", &info_vadj);
-
- if (!error)
+ if (scrolled_win->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
{
- gtk_object_set (GTK_OBJECT (widget),
- "hadjustment",
- gtk_scrolled_window_get_hadjustment
- (scrolled_window),
- "vadjustment",
- gtk_scrolled_window_get_vadjustment
- (scrolled_window),
- NULL);
- scrolled_window->viewport = widget;
- gtk_widget_set_parent (widget, GTK_WIDGET (scrolled_window));
- gtk_widget_ref (widget);
- scrolled_window->autogenerated_viewport = FALSE;
+ gboolean visible;
+
+ visible = scrolled_win->hscrollbar_visible;
+ scrolled_win->hscrollbar_visible = (adjustment->upper - adjustment->lower >
+ adjustment->page_size);
+ if (scrolled_win->hscrollbar_visible != visible)
+ gtk_widget_queue_resize (GTK_WIDGET (scrolled_win));
}
}
-
- if (error)
- {
- g_free (error);
-
- scrolled_window->viewport = gtk_viewport_new
- (gtk_scrolled_window_get_hadjustment (scrolled_window),
- gtk_scrolled_window_get_vadjustment (scrolled_window));
- gtk_widget_set_parent (scrolled_window->viewport,
- GTK_WIDGET (scrolled_window));
- gtk_widget_ref (scrolled_window->viewport);
- gtk_widget_show (scrolled_window->viewport);
- scrolled_window->autogenerated_viewport = FALSE;
-
- gtk_container_add (GTK_CONTAINER (scrolled_window->viewport), widget);
-
- widget = scrolled_window->viewport;
- }
-
- if (GTK_WIDGET_VISIBLE (scrolled_window))
+ else if (adjustment == gtk_range_get_adjustment (GTK_RANGE (scrolled_win->vscrollbar)))
{
- if (GTK_WIDGET_REALIZED (scrolled_window) &&
- !GTK_WIDGET_REALIZED (widget))
- gtk_widget_realize (widget);
+ if (scrolled_win->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
+ {
+ gboolean visible;
- if (GTK_WIDGET_MAPPED (scrolled_window) &&
- !GTK_WIDGET_MAPPED (widget))
- gtk_widget_map (widget);
+ visible = scrolled_win->vscrollbar_visible;
+ scrolled_win->vscrollbar_visible = (adjustment->upper - adjustment->lower >
+ adjustment->page_size);
+ if (scrolled_win->vscrollbar_visible != visible)
+ gtk_widget_queue_resize (GTK_WIDGET (scrolled_win));
+ }
}
-
- if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (scrolled_window))
- gtk_widget_queue_resize (widget);
}
static void
-gtk_scrolled_window_remove (GtkContainer *container,
- GtkWidget *widget)
+gtk_scrolled_window_add (GtkContainer *container,
+ GtkWidget *child)
{
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 */
+ g_return_if_fail (scrolled_window->child == NULL);
+
+ gtk_widget_set_parent (child, GTK_WIDGET (container));
+ scrolled_window->child = child;
- if (scrolled_window->viewport == widget)
- scrolled_window->autogenerated_viewport = FALSE;
+ /* this is a temporary message */
+ if (!gtk_widget_scroll_adjustements (child,
+ gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar)),
+ gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar))))
+ g_message ("gtk_scrolled_window_add(): cannot add non scrollable widget "
+ "use gtk_scrolled_window_add_with_viewport() instead");
+
+ if (GTK_WIDGET_VISIBLE (scrolled_window))
+ {
+ if (GTK_WIDGET_REALIZED (scrolled_window) &&
+ !GTK_WIDGET_REALIZED (child))
+ gtk_widget_realize (child);
- gtk_widget_unparent (widget);
+ if (GTK_WIDGET_MAPPED (scrolled_window) &&
+ !GTK_WIDGET_MAPPED (child))
+ gtk_widget_map (child);
}
- else if (scrolled_window->autogenerated_viewport)
- gtk_container_remove (GTK_CONTAINER (scrolled_window->viewport), widget);
+
+ if (GTK_WIDGET_VISIBLE (child) && GTK_WIDGET_VISIBLE (scrolled_window))
+ gtk_widget_queue_resize (child);
}
static void
-gtk_scrolled_window_forall (GtkContainer *container,
- gboolean include_internals,
- GtkCallback callback,
- gpointer callback_data)
+gtk_scrolled_window_remove (GtkContainer *container,
+ GtkWidget *child)
{
GtkScrolledWindow *scrolled_window;
-
+ gboolean widget_was_visible;
+
g_return_if_fail (container != NULL);
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container));
- g_return_if_fail (callback != NULL);
+ g_return_if_fail (child != NULL);
scrolled_window = GTK_SCROLLED_WINDOW (container);
-
- if (scrolled_window->viewport)
- (* callback) (scrolled_window->viewport, callback_data);
- if (include_internals)
- {
- (* callback) (scrolled_window->vscrollbar, callback_data);
- (* callback) (scrolled_window->hscrollbar, callback_data);
- }
-}
-
-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);
-
- if (scrolled_window->vscrollbar_visible)
- {
- if (scrolled_window->window_placement == GTK_CORNER_TOP_RIGHT ||
- scrolled_window->window_placement == GTK_CORNER_BOTTOM_RIGHT)
- allocation->x += (scrolled_window->vscrollbar->requisition.width +
- SCROLLBAR_SPACING (scrolled_window));
-
- allocation->width =
- MAX (1, allocation->width -
- (scrolled_window->vscrollbar->requisition.width +
- SCROLLBAR_SPACING (scrolled_window)));
- }
- if (scrolled_window->hscrollbar_visible)
- {
- if (scrolled_window->window_placement == GTK_CORNER_BOTTOM_LEFT ||
- scrolled_window->window_placement == GTK_CORNER_BOTTOM_RIGHT)
- allocation->y += (scrolled_window->hscrollbar->requisition.height +
- SCROLLBAR_SPACING (scrolled_window));
-
- allocation->height =
- MAX (1, allocation->height -
- (scrolled_window->hscrollbar->requisition.height +
- SCROLLBAR_SPACING (scrolled_window)));
- }
+ g_return_if_fail (scrolled_window->child == child);
+
+ widget_was_visible = GTK_WIDGET_VISIBLE (child);
+
+ gtk_widget_scroll_adjustements (child, NULL, NULL);
+ gtk_widget_unparent (child);
+ scrolled_window->child = NULL;
+
+ if (widget_was_visible)
+ gtk_widget_queue_resize (GTK_WIDGET (container));
}
-static void
-gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
- gpointer data)
+void
+gtk_scrolled_window_add_with_viewport (GtkScrolledWindow *scrolled_window,
+ GtkWidget *child)
{
- GtkScrolledWindow *scrolled_win;
- gboolean visible;
-
- g_return_if_fail (adjustment != NULL);
- g_return_if_fail (data != NULL);
+ GtkWidget *viewport;
- 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)
- {
- visible = scrolled_win->hscrollbar_visible;
- scrolled_win->hscrollbar_visible =
- ((adjustment->upper - adjustment->lower) > adjustment->page_size);
- if (scrolled_win->hscrollbar_visible != visible)
- gtk_widget_queue_resize (GTK_WIDGET (scrolled_win));
- }
- }
- else if (adjustment == gtk_range_get_adjustment (GTK_RANGE (scrolled_win->vscrollbar)))
- {
- if (scrolled_win->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
- {
- visible = scrolled_win->vscrollbar_visible;
- scrolled_win->vscrollbar_visible =
- ((adjustment->upper - adjustment->lower) > adjustment->page_size);
- if (scrolled_win->vscrollbar_visible != visible)
- gtk_widget_queue_resize (GTK_WIDGET (scrolled_win));
- }
- }
- else
- {
- g_warning ("could not determine which adjustment scrollbar received change signal for");
- return;
- }
+ g_return_if_fail (scrolled_window != NULL);
+ g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
+ g_return_if_fail (child != NULL);
+ g_return_if_fail (GTK_IS_WIDGET (child));
+ g_return_if_fail (scrolled_window->child == NULL);
+ g_return_if_fail (child->parent == NULL);
+
+ viewport =
+ gtk_viewport_new (gtk_scrolled_window_get_hadjustment (scrolled_window),
+ gtk_scrolled_window_get_vadjustment (scrolled_window));
+ gtk_widget_show (viewport);
+ gtk_container_add (GTK_CONTAINER (viewport), child);
+ gtk_container_add (GTK_CONTAINER (scrolled_window), viewport);
}