1
/* GTK - The GIMP Toolkit
2
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Library General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Library General Public License for more details.
14
* You should have received a copy of the GNU Library General Public
15
* License along with this library; if not, write to the
16
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
* Boston, MA 02111-1307, USA.
21
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
22
* file for a list of people on the GTK+ Team. See the ChangeLog
23
* files for a list of changes. These files are distributed with
24
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
28
#include <gtk/gtkhscrollbar.h>
29
#include <gtk/gtkvscrollbar.h>
30
#include <gtk/gtksignal.h>
31
#include <gtk/gtkviewport.h>
32
#include "gtkscrollframe.h"
35
/* scrolled window policy and size requisition handling:
37
* gtk size requisition works as follows:
38
* a widget upon size-request reports the width and height that it finds
39
* to be best suited to display its contents, including children.
40
* the width and/or height reported from a widget upon size requisition
41
* may be overidden by the user by specifying a width and/or height
42
* other than 0 through gtk_widget_set_usize().
44
* a scrolled window needs (for imlementing all three policy types) to
45
* request its width and height based on two different rationales.
46
* 1) the user wants the scrolled window to just fit into the space
47
* that it gets allocated for a specifc dimension.
48
* 1.1) this does not apply if the user specified a concrete value
49
* value for that specific dimension by either specifying usize for the
50
* scrolled window or for its child.
51
* 2) the user wants the scrolled window to take as much space up as
52
* is desired by the child for a specifc dimension (i.e. POLICY_NEVER).
54
* also, kinda obvious:
55
* 3) a user would certainly not have choosen a scrolled window as a container
56
* for the child, if the resulting allocation takes up more space than the
57
* child would have allocated without the scrolled window.
60
* A) from 1) follows: the scrolled window shouldn't request more space for a
61
* specifc dimension than is required at minimum.
62
* B) from 1.1) follows: the requisition may be overidden by usize of the scrolled
63
* window (done automatically) or by usize of the child (needs to be checked).
64
* C) from 2) follows: for POLICY_NEVER, the scrolled window simply reports the
66
* D) from 3) follows: the scrolled window child's minimum width and minimum height
67
* under A) at least correspond to the space taken up by its scrollbars.
70
/* Object argument IDs */
75
ARG_HSCROLLBAR_POLICY,
76
ARG_VSCROLLBAR_POLICY,
82
/* Private part of the GtkScrollFrame structure */
84
/* Horizontal and vertical scrollbars */
88
/* Space between scrollbars and frame */
91
/* Allocation for frame */
97
/* Scrollbar policy */
101
/* Whether scrollbars are visible */
102
guint hsb_visible : 1;
103
guint vsb_visible : 1;
105
/* Placement of frame wrt scrollbars */
106
guint frame_placement : 2;
108
/* Shadow type for frame */
109
guint shadow_type : 3;
110
} ScrollFramePrivate;
113
static void gtk_scroll_frame_class_init (GtkScrollFrameClass *class);
114
static void gtk_scroll_frame_init (GtkScrollFrame *sf);
115
static void gtk_scroll_frame_set_arg (GtkObject *object, GtkArg *arg, guint arg_id);
116
static void gtk_scroll_frame_get_arg (GtkObject *object, GtkArg *arg, guint arg_id);
117
static void gtk_scroll_frame_destroy (GtkObject *object);
118
static void gtk_scroll_frame_finalize (GtkObject *object);
120
static void gtk_scroll_frame_map (GtkWidget *widget);
121
static void gtk_scroll_frame_unmap (GtkWidget *widget);
122
static void gtk_scroll_frame_draw (GtkWidget *widget, GdkRectangle *area);
123
static void gtk_scroll_frame_size_request (GtkWidget *widget, GtkRequisition *requisition);
124
static void gtk_scroll_frame_size_allocate (GtkWidget *widget, GtkAllocation *allocation);
125
static gint gtk_scroll_frame_expose (GtkWidget *widget, GdkEventExpose *event);
126
static gint gtk_scroll_frame_button_press (GtkWidget *widget, GdkEventButton *event);
128
static void gtk_scroll_frame_add (GtkContainer *container, GtkWidget *widget);
129
static void gtk_scroll_frame_remove (GtkContainer *container, GtkWidget *widget);
130
static void gtk_scroll_frame_forall (GtkContainer *container, gboolean include_internals,
131
GtkCallback callback, gpointer callback_data);
133
static GtkBinClass *parent_class;
137
* gtk_scroll_frame_get_type:
140
* Registers the #GtkScrollFrame class if necessary, and returns the type ID
143
* Return value: The type ID of the #GtkScrollFrame class.
146
gtk_scroll_frame_get_type (void)
148
static GtkType scroll_frame_type = 0;
150
if (!scroll_frame_type) {
151
static const GtkTypeInfo scroll_frame_info = {
153
sizeof (GtkScrollFrame),
154
sizeof (GtkScrollFrameClass),
155
(GtkClassInitFunc) gtk_scroll_frame_class_init,
156
(GtkObjectInitFunc) gtk_scroll_frame_init,
157
NULL, /* reserved_1 */
158
NULL, /* reserved_2 */
159
(GtkClassInitFunc) NULL
162
scroll_frame_type = gtk_type_unique (GTK_TYPE_BIN, &scroll_frame_info);
165
return scroll_frame_type;
168
/* Class initialization function for the scroll frame widget */
170
gtk_scroll_frame_class_init (GtkScrollFrameClass *class)
172
GtkObjectClass *object_class;
173
GtkWidgetClass *widget_class;
174
GtkContainerClass *container_class;
176
object_class = (GtkObjectClass *) class;
177
widget_class = (GtkWidgetClass *) class;
178
container_class = (GtkContainerClass *) class;
180
parent_class = gtk_type_class (GTK_TYPE_BIN);
182
gtk_object_add_arg_type ("GtkScrollFrame::hadjustment",
184
GTK_ARG_READWRITE | GTK_ARG_CONSTRUCT,
186
gtk_object_add_arg_type ("GtkScrollFrame::vadjustment",
188
GTK_ARG_READWRITE | GTK_ARG_CONSTRUCT,
190
gtk_object_add_arg_type ("GtkScrollFrame::hscrollbar_policy",
191
GTK_TYPE_POLICY_TYPE,
193
ARG_HSCROLLBAR_POLICY);
194
gtk_object_add_arg_type ("GtkScrollFrame::vscrollbar_policy",
195
GTK_TYPE_POLICY_TYPE,
197
ARG_VSCROLLBAR_POLICY);
198
gtk_object_add_arg_type ("GtkScrollFrame::frame_placement",
199
GTK_TYPE_CORNER_TYPE,
201
ARG_FRAME_PLACEMENT);
202
gtk_object_add_arg_type ("GtkScrollFrame::shadow_type",
203
GTK_TYPE_SHADOW_TYPE,
206
gtk_object_add_arg_type ("GtkScrollFrame::scrollbar_spacing",
209
ARG_SCROLLBAR_SPACING);
211
object_class->set_arg = gtk_scroll_frame_set_arg;
212
object_class->get_arg = gtk_scroll_frame_get_arg;
213
object_class->destroy = gtk_scroll_frame_destroy;
214
object_class->finalize = gtk_scroll_frame_finalize;
216
widget_class->map = gtk_scroll_frame_map;
217
widget_class->unmap = gtk_scroll_frame_unmap;
218
widget_class->draw = gtk_scroll_frame_draw;
219
widget_class->size_request = gtk_scroll_frame_size_request;
220
widget_class->size_allocate = gtk_scroll_frame_size_allocate;
221
widget_class->expose_event = gtk_scroll_frame_expose;
222
widget_class->button_press_event = gtk_scroll_frame_button_press;
224
container_class->add = gtk_scroll_frame_add;
225
container_class->remove = gtk_scroll_frame_remove;
226
container_class->forall = gtk_scroll_frame_forall;
229
/* Object initialization function for the scroll frame widget */
231
gtk_scroll_frame_init (GtkScrollFrame *sf)
233
ScrollFramePrivate *priv;
235
priv = g_new0 (ScrollFramePrivate, 1);
238
GTK_WIDGET_SET_FLAGS (sf, GTK_NO_WINDOW);
240
gtk_container_set_resize_mode (GTK_CONTAINER (sf), GTK_RESIZE_QUEUE);
242
priv->sb_spacing = 3;
243
priv->hsb_policy = GTK_POLICY_ALWAYS;
244
priv->vsb_policy = GTK_POLICY_ALWAYS;
245
priv->frame_placement = GTK_CORNER_TOP_LEFT;
246
priv->shadow_type = GTK_SHADOW_NONE;
249
/* Set_arg handler for the scroll frame widget */
251
gtk_scroll_frame_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
254
ScrollFramePrivate *priv;
256
sf = GTK_SCROLL_FRAME (object);
260
case ARG_HADJUSTMENT:
261
gtk_scroll_frame_set_hadjustment (sf, GTK_VALUE_POINTER (*arg));
264
case ARG_VADJUSTMENT:
265
gtk_scroll_frame_set_vadjustment (sf, GTK_VALUE_POINTER (*arg));
268
case ARG_HSCROLLBAR_POLICY:
269
gtk_scroll_frame_set_policy (sf, GTK_VALUE_ENUM (*arg), priv->vsb_policy);
272
case ARG_VSCROLLBAR_POLICY:
273
gtk_scroll_frame_set_policy (sf, priv->hsb_policy, GTK_VALUE_ENUM (*arg));
276
case ARG_FRAME_PLACEMENT:
277
gtk_scroll_frame_set_placement (sf, GTK_VALUE_ENUM (*arg));
280
case ARG_SHADOW_TYPE:
281
gtk_scroll_frame_set_shadow_type (sf, GTK_VALUE_ENUM (*arg));
284
case ARG_SCROLLBAR_SPACING:
285
gtk_scroll_frame_set_scrollbar_spacing (sf, GTK_VALUE_UINT (*arg));
293
/* Get_arg handler for the scroll frame widget */
295
gtk_scroll_frame_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
298
ScrollFramePrivate *priv;
300
sf = GTK_SCROLL_FRAME (object);
304
case ARG_HADJUSTMENT:
305
GTK_VALUE_POINTER (*arg) = gtk_scroll_frame_get_hadjustment (sf);
308
case ARG_VADJUSTMENT:
309
GTK_VALUE_POINTER (*arg) = gtk_scroll_frame_get_vadjustment (sf);
312
case ARG_HSCROLLBAR_POLICY:
313
GTK_VALUE_ENUM (*arg) = priv->hsb_policy;
316
case ARG_VSCROLLBAR_POLICY:
317
GTK_VALUE_ENUM (*arg) = priv->vsb_policy;
320
case ARG_FRAME_PLACEMENT:
321
GTK_VALUE_ENUM (*arg) = priv->frame_placement;
324
case ARG_SHADOW_TYPE:
325
GTK_VALUE_ENUM (*arg) = priv->shadow_type;
328
case ARG_SCROLLBAR_SPACING:
329
GTK_VALUE_UINT (*arg) = priv->sb_spacing;
333
arg->type = GTK_TYPE_INVALID;
338
/* Destroy handler for the scroll frame widget */
340
gtk_scroll_frame_destroy (GtkObject *object)
343
ScrollFramePrivate *priv;
345
g_return_if_fail (object != NULL);
346
g_return_if_fail (GTK_IS_SCROLL_FRAME (object));
348
sf = GTK_SCROLL_FRAME (object);
351
gtk_widget_unparent (priv->hsb);
352
gtk_widget_unparent (priv->vsb);
353
gtk_widget_destroy (priv->hsb);
354
gtk_widget_destroy (priv->vsb);
356
if (GTK_OBJECT_CLASS (parent_class)->destroy)
357
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
360
/* Finalize handler for the scroll frame widget */
362
gtk_scroll_frame_finalize (GtkObject *object)
365
ScrollFramePrivate *priv;
367
sf = GTK_SCROLL_FRAME (object);
370
gtk_widget_unref (priv->hsb);
371
gtk_widget_unref (priv->vsb);
375
if (GTK_OBJECT_CLASS (parent_class)->finalize)
376
(* GTK_OBJECT_CLASS (parent_class)->finalize) (object);
379
/* Map handler for the scroll frame widget */
381
gtk_scroll_frame_map (GtkWidget *widget)
384
ScrollFramePrivate *priv;
386
g_return_if_fail (widget != NULL);
387
g_return_if_fail (GTK_IS_SCROLL_FRAME (widget));
389
sf = GTK_SCROLL_FRAME (widget);
392
/* chain parent class handler to map self and child */
393
if (GTK_WIDGET_CLASS (parent_class)->map)
394
(* GTK_WIDGET_CLASS (parent_class)->map) (widget);
396
if (GTK_WIDGET_VISIBLE (priv->hsb) && !GTK_WIDGET_MAPPED (priv->hsb))
397
gtk_widget_map (priv->hsb);
399
if (GTK_WIDGET_VISIBLE (priv->vsb) && !GTK_WIDGET_MAPPED (priv->vsb))
400
gtk_widget_map (priv->vsb);
403
/* Unmap handler for the scroll frame widget */
405
gtk_scroll_frame_unmap (GtkWidget *widget)
408
ScrollFramePrivate *priv;
410
g_return_if_fail (widget != NULL);
411
g_return_if_fail (GTK_IS_SCROLL_FRAME (widget));
413
sf = GTK_SCROLL_FRAME (widget);
416
/* chain parent class handler to unmap self and child */
417
if (GTK_WIDGET_CLASS (parent_class)->unmap)
418
(* GTK_WIDGET_CLASS (parent_class)->unmap) (widget);
420
if (GTK_WIDGET_MAPPED (priv->hsb))
421
gtk_widget_unmap (priv->hsb);
423
if (GTK_WIDGET_MAPPED (priv->vsb))
424
gtk_widget_unmap (priv->vsb);
427
/* Draws the shadow of a scroll frame widget */
429
draw_shadow (GtkScrollFrame *sf, GdkRectangle *area)
431
ScrollFramePrivate *priv;
433
g_assert (area != NULL);
437
gtk_paint_shadow (GTK_WIDGET (sf)->style,
438
GTK_WIDGET (sf)->window,
439
GTK_STATE_NORMAL, priv->shadow_type,
440
area, GTK_WIDGET (sf),
442
priv->frame_x, priv->frame_y,
443
priv->frame_w, priv->frame_h);
446
/* Draw handler for the scroll frame widget */
448
gtk_scroll_frame_draw (GtkWidget *widget, GdkRectangle *area)
451
ScrollFramePrivate *priv;
453
GdkRectangle child_area;
455
g_return_if_fail (widget != NULL);
456
g_return_if_fail (GTK_IS_SCROLL_FRAME (widget));
457
g_return_if_fail (area != NULL);
459
sf = GTK_SCROLL_FRAME (widget);
461
bin = GTK_BIN (widget);
463
if (GTK_WIDGET_DRAWABLE (widget))
464
draw_shadow (sf, area);
466
if (bin->child && GTK_WIDGET_VISIBLE (bin->child)
467
&& gtk_widget_intersect (bin->child, area, &child_area))
468
gtk_widget_draw (bin->child, &child_area);
470
if (GTK_WIDGET_VISIBLE (priv->hsb)
471
&& gtk_widget_intersect (priv->hsb, area, &child_area))
472
gtk_widget_draw (priv->hsb, &child_area);
474
if (GTK_WIDGET_VISIBLE (priv->vsb)
475
&& gtk_widget_intersect (priv->vsb, area, &child_area))
476
gtk_widget_draw (priv->vsb, &child_area);
479
/* Forall handler for the scroll frame widget */
481
gtk_scroll_frame_forall (GtkContainer *container, gboolean include_internals,
482
GtkCallback callback, gpointer callback_data)
485
ScrollFramePrivate *priv;
487
g_return_if_fail (container != NULL);
488
g_return_if_fail (GTK_IS_SCROLL_FRAME (container));
489
g_return_if_fail (callback != NULL);
491
sf = GTK_SCROLL_FRAME (container);
494
if (GTK_CONTAINER_CLASS (parent_class)->forall)
495
(* GTK_CONTAINER_CLASS (parent_class)->forall) (
496
container, include_internals,
497
callback, callback_data);
499
if (include_internals) {
501
(* callback) (priv->vsb, callback_data);
504
(* callback) (priv->hsb, callback_data);
508
/* Size_request handler for the scroll frame widget */
510
gtk_scroll_frame_size_request (GtkWidget *widget, GtkRequisition *requisition)
513
ScrollFramePrivate *priv;
517
GtkRequisition hsb_requisition;
518
GtkRequisition vsb_requisition;
519
GtkRequisition child_requisition;
521
g_return_if_fail (widget != NULL);
522
g_return_if_fail (GTK_IS_SCROLL_FRAME (widget));
523
g_return_if_fail (requisition != NULL);
525
sf = GTK_SCROLL_FRAME (widget);
527
bin = GTK_BIN (widget);
532
requisition->width = GTK_CONTAINER (widget)->border_width * 2;
533
requisition->height = GTK_CONTAINER (widget)->border_width * 2;
535
if (priv->shadow_type != GTK_SHADOW_NONE) {
536
requisition->width += 2 * widget->style->klass->xthickness;
537
requisition->height += 2 * widget->style->klass->ythickness;
540
gtk_widget_size_request (priv->hsb, &hsb_requisition);
541
gtk_widget_size_request (priv->vsb, &vsb_requisition);
543
if (bin->child && GTK_WIDGET_VISIBLE (bin->child)) {
544
static guint quark_aux_info;
547
quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
549
gtk_widget_size_request (bin->child, &child_requisition);
551
if (priv->hsb_policy == GTK_POLICY_NEVER)
552
requisition->width += child_requisition.width;
554
GtkWidgetAuxInfo *aux_info;
556
aux_info = gtk_object_get_data_by_id (GTK_OBJECT (bin->child),
558
if (aux_info && aux_info->width > 0) {
559
requisition->width += aux_info->width;
562
requisition->width += vsb_requisition.width;
565
if (priv->vsb_policy == GTK_POLICY_NEVER)
566
requisition->height += child_requisition.height;
568
GtkWidgetAuxInfo *aux_info;
570
aux_info = gtk_object_get_data_by_id (GTK_OBJECT (bin->child),
572
if (aux_info && aux_info->height > 0) {
573
requisition->height += aux_info->height;
576
requisition->height += hsb_requisition.height;
580
if (priv->hsb_policy == GTK_POLICY_AUTOMATIC || GTK_WIDGET_VISIBLE (priv->hsb)) {
581
requisition->width = MAX (requisition->width, hsb_requisition.width);
582
if (!extra_height || GTK_WIDGET_VISIBLE (priv->hsb))
583
extra_height = priv->sb_spacing + hsb_requisition.height;
586
if (priv->vsb_policy == GTK_POLICY_AUTOMATIC || GTK_WIDGET_VISIBLE (priv->vsb)) {
587
requisition->height = MAX (requisition->height, vsb_requisition.height);
588
if (!extra_width || GTK_WIDGET_VISIBLE (priv->vsb))
589
extra_width = priv->sb_spacing + vsb_requisition.width;
592
requisition->width += MAX (0, extra_width);
593
requisition->height += MAX (0, extra_height);
596
/* Computes the relative allocation for the scroll frame widget */
598
compute_relative_allocation (GtkWidget *widget, GtkAllocation *allocation)
601
ScrollFramePrivate *priv;
603
g_assert (widget != NULL);
604
g_assert (GTK_IS_SCROLL_FRAME (widget));
605
g_assert (allocation != NULL);
607
sf = GTK_SCROLL_FRAME (widget);
610
allocation->x = GTK_CONTAINER (widget)->border_width;
611
allocation->y = GTK_CONTAINER (widget)->border_width;
612
allocation->width = MAX (1, (int) widget->allocation.width - (int) allocation->x * 2);
613
allocation->height = MAX (1, (int) widget->allocation.height - (int) allocation->y * 2);
615
if (priv->vsb_visible) {
616
GtkRequisition vsb_requisition;
618
gtk_widget_get_child_requisition (priv->vsb, &vsb_requisition);
620
if (priv->frame_placement == GTK_CORNER_TOP_RIGHT
621
|| priv->frame_placement == GTK_CORNER_BOTTOM_RIGHT)
622
allocation->x += vsb_requisition.width + priv->sb_spacing;
624
allocation->width = MAX (1,
625
((int) allocation->width
626
- (int) (vsb_requisition.width + priv->sb_spacing)));
629
if (priv->hsb_visible) {
630
GtkRequisition hsb_requisition;
632
gtk_widget_get_child_requisition (priv->hsb, &hsb_requisition);
634
if (priv->frame_placement == GTK_CORNER_BOTTOM_LEFT
635
|| priv->frame_placement == GTK_CORNER_BOTTOM_RIGHT)
636
allocation->y += hsb_requisition.height + priv->sb_spacing;
638
allocation->height = MAX (1,
639
((int) allocation->height
640
- (int) (hsb_requisition.height + priv->sb_spacing)));
644
/* Size_allocate handler for the scroll frame widget */
646
gtk_scroll_frame_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
649
ScrollFramePrivate *priv;
651
GtkAllocation relative_allocation;
652
GtkAllocation child_allocation;
653
int xthickness, ythickness;
655
g_return_if_fail (widget != NULL);
656
g_return_if_fail (GTK_IS_SCROLL_FRAME (widget));
657
g_return_if_fail (allocation != NULL);
659
sf = GTK_SCROLL_FRAME (widget);
661
bin = GTK_BIN (widget);
663
widget->allocation = *allocation;
665
if (priv->hsb_policy == GTK_POLICY_ALWAYS)
666
priv->hsb_visible = TRUE;
667
else if (priv->hsb_policy == GTK_POLICY_NEVER)
668
priv->hsb_visible = FALSE;
670
if (priv->vsb_policy == GTK_POLICY_ALWAYS)
671
priv->vsb_visible = TRUE;
672
else if (priv->vsb_policy == GTK_POLICY_NEVER)
673
priv->vsb_visible = FALSE;
675
if (priv->shadow_type == GTK_SHADOW_NONE) {
679
xthickness = widget->style->klass->xthickness;
680
ythickness = widget->style->klass->ythickness;
683
if (bin->child && GTK_WIDGET_VISIBLE (bin->child)) {
684
gboolean previous_hvis;
685
gboolean previous_vvis;
689
compute_relative_allocation (widget, &relative_allocation);
691
priv->frame_x = relative_allocation.x + allocation->x;
692
priv->frame_y = relative_allocation.y + allocation->y;
693
priv->frame_w = relative_allocation.width;
694
priv->frame_h = relative_allocation.height;
696
child_allocation.x = priv->frame_x + xthickness;
697
child_allocation.y = priv->frame_y + ythickness;
698
child_allocation.width = MAX ((int) priv->frame_w - 2 * xthickness, 0);
699
child_allocation.height = MAX ((int) priv->frame_h - 2 * ythickness, 0);
701
previous_hvis = priv->hsb_visible;
702
previous_vvis = priv->vsb_visible;
704
gtk_widget_size_allocate (bin->child, &child_allocation);
706
/* If, after the first iteration, the hscrollbar and the
707
* vscrollbar flip visiblity, then we need both.
710
&& previous_hvis != priv->hsb_visible
711
&& previous_vvis != priv->vsb_visible) {
712
priv->hsb_visible = TRUE;
713
priv->vsb_visible = TRUE;
715
/* a new resize is already queued at this point,
716
* so we will immediatedly get reinvoked
722
} while (previous_hvis != priv->hsb_visible
723
|| previous_vvis != priv->vsb_visible);
725
compute_relative_allocation (widget, &relative_allocation);
727
if (priv->hsb_visible) {
728
GtkRequisition hscrollbar_requisition;
730
gtk_widget_get_child_requisition (priv->hsb, &hscrollbar_requisition);
732
if (!GTK_WIDGET_VISIBLE (priv->hsb))
733
gtk_widget_show (priv->hsb);
735
child_allocation.x = relative_allocation.x;
736
if (priv->frame_placement == GTK_CORNER_TOP_LEFT
737
|| priv->frame_placement == GTK_CORNER_TOP_RIGHT)
738
child_allocation.y = (relative_allocation.y
739
+ relative_allocation.height
742
child_allocation.y = GTK_CONTAINER (sf)->border_width;
744
child_allocation.width = relative_allocation.width;
745
child_allocation.height = hscrollbar_requisition.height;
746
child_allocation.x += allocation->x;
747
child_allocation.y += allocation->y;
749
gtk_widget_size_allocate (priv->hsb, &child_allocation);
750
} else if (GTK_WIDGET_VISIBLE (priv->hsb))
751
gtk_widget_hide (priv->hsb);
753
if (priv->vsb_visible) {
754
GtkRequisition vscrollbar_requisition;
756
if (!GTK_WIDGET_VISIBLE (priv->vsb))
757
gtk_widget_show (priv->vsb);
759
gtk_widget_get_child_requisition (priv->vsb, &vscrollbar_requisition);
761
if (priv->frame_placement == GTK_CORNER_TOP_LEFT
762
|| priv->frame_placement == GTK_CORNER_BOTTOM_LEFT)
763
child_allocation.x = (relative_allocation.x
764
+ relative_allocation.width
767
child_allocation.x = GTK_CONTAINER (sf)->border_width;
769
child_allocation.y = relative_allocation.y;
770
child_allocation.width = vscrollbar_requisition.width;
771
child_allocation.height = relative_allocation.height;
772
child_allocation.x += allocation->x;
773
child_allocation.y += allocation->y;
775
gtk_widget_size_allocate (priv->vsb, &child_allocation);
776
} else if (GTK_WIDGET_VISIBLE (priv->vsb))
777
gtk_widget_hide (priv->vsb);
780
/* Button press handler for the scroll framw diget */
782
gtk_scroll_frame_button_press (GtkWidget *widget, GdkEventButton *event)
784
g_return_val_if_fail (widget != NULL, FALSE);
785
g_return_val_if_fail (GTK_IS_SCROLL_FRAME (widget), FALSE);
786
g_return_val_if_fail (event != NULL, FALSE);
788
/* This is to handle mouse wheel scrolling */
789
if (event->button == 4 || event->button == 5) {
793
gtk_object_get (GTK_OBJECT (widget),
794
(event->state & GDK_CONTROL_MASK) ?
795
"hadjustment" : "vadjustment",
799
new_value = adj->value + ((event->button == 4) ?
800
-adj->page_increment / 2:
801
adj->page_increment / 2);
802
new_value = CLAMP (new_value, adj->lower, adj->upper - adj->page_size);
803
gtk_adjustment_set_value (adj, new_value);
811
/* Expose handler for the scroll frame widget */
813
gtk_scroll_frame_expose (GtkWidget *widget, GdkEventExpose *event)
817
g_return_val_if_fail (widget != NULL, FALSE);
818
g_return_val_if_fail (GTK_IS_SCROLL_FRAME (widget), FALSE);
819
g_return_val_if_fail (event != NULL, FALSE);
821
sf = GTK_SCROLL_FRAME (widget);
823
if (GTK_WIDGET_DRAWABLE (widget))
824
draw_shadow (sf, &event->area);
826
if (GTK_WIDGET_CLASS (parent_class)->expose_event)
827
(* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event);
832
/* Add handler for the scroll frame widget */
834
gtk_scroll_frame_add (GtkContainer *container, GtkWidget *child)
837
ScrollFramePrivate *priv;
840
sf = GTK_SCROLL_FRAME (container);
842
bin = GTK_BIN (container);
843
g_return_if_fail (bin->child == NULL);
846
gtk_widget_set_parent (child, GTK_WIDGET (bin));
848
/* this is a temporary message */
849
if (!gtk_widget_set_scroll_adjustments (child,
850
gtk_range_get_adjustment (GTK_RANGE (priv->hsb)),
851
gtk_range_get_adjustment (GTK_RANGE (priv->vsb))))
852
g_warning ("gtk_scroll_frame_add(): cannot add non scrollable widget "
853
"use gtk_scroll_frame_add_with_viewport() instead");
855
if (GTK_WIDGET_REALIZED (child->parent))
856
gtk_widget_realize (child);
858
if (GTK_WIDGET_VISIBLE (child->parent) && GTK_WIDGET_VISIBLE (child)) {
859
if (GTK_WIDGET_MAPPED (child->parent))
860
gtk_widget_map (child);
862
gtk_widget_queue_resize (child);
866
/* Remove method for the scroll frame widget */
868
gtk_scroll_frame_remove (GtkContainer *container, GtkWidget *child)
870
g_return_if_fail (container != NULL);
871
g_return_if_fail (GTK_IS_SCROLL_FRAME (container));
872
g_return_if_fail (child != NULL);
873
g_return_if_fail (GTK_BIN (container)->child == child);
875
gtk_widget_set_scroll_adjustments (child, NULL, NULL);
877
/* chain parent class handler to remove child */
878
if (GTK_CONTAINER_CLASS (parent_class)->remove)
879
(* GTK_CONTAINER_CLASS (parent_class)->remove) (container, child);
883
* gtk_scroll_frame_new:
884
* @hadj: If non-NULL, the adjustment to use for horizontal scrolling.
885
* @vadj: If non-NULL, the adjustment to use for vertical scrolling.
887
* Creates a new scroll frame widget.
889
* Return value: The newly-created scroll frame widget.
892
gtk_scroll_frame_new (GtkAdjustment *hadj, GtkAdjustment *vadj)
895
g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadj), NULL);
898
g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadj), NULL);
900
return gtk_widget_new (GTK_TYPE_SCROLL_FRAME,
906
/* Callback used when one of the scroll frame widget's adjustments changes */
908
adjustment_changed (GtkAdjustment *adj, gpointer data)
911
ScrollFramePrivate *priv;
913
g_return_if_fail (adj != NULL);
914
g_return_if_fail (GTK_IS_ADJUSTMENT (adj));
915
g_return_if_fail (data != NULL);
917
sf = GTK_SCROLL_FRAME (data);
920
if (adj == gtk_range_get_adjustment (GTK_RANGE (priv->hsb))) {
921
if (priv->hsb_policy == GTK_POLICY_AUTOMATIC) {
924
visible = priv->hsb_visible;
925
priv->hsb_visible = (adj->upper - adj->lower > adj->page_size);
926
if (priv->hsb_visible != visible)
927
gtk_widget_queue_resize (GTK_WIDGET (sf));
929
} else if (adj == gtk_range_get_adjustment (GTK_RANGE (priv->vsb))) {
930
if (priv->vsb_policy == GTK_POLICY_AUTOMATIC) {
933
visible = priv->vsb_visible;
934
priv->vsb_visible = (adj->upper - adj->lower > adj->page_size);
935
if (priv->vsb_visible != visible)
936
gtk_widget_queue_resize (GTK_WIDGET (sf));
942
* gtk_scroll_frame_set_hadjustment:
943
* @sf: A scroll frame widget.
944
* @adj: An adjustment.
946
* Sets the adjustment to be used for horizontal scrolling in a scroll frame
950
gtk_scroll_frame_set_hadjustment (GtkScrollFrame *sf, GtkAdjustment *adj)
952
ScrollFramePrivate *priv;
954
g_return_if_fail (sf != NULL);
955
g_return_if_fail (GTK_IS_SCROLL_FRAME (sf));
960
g_return_if_fail (GTK_IS_ADJUSTMENT (adj));
962
adj = GTK_ADJUSTMENT (gtk_object_new (GTK_TYPE_ADJUSTMENT, NULL));
965
gtk_widget_push_composite_child ();
966
priv->hsb = gtk_hscrollbar_new (adj);
967
gtk_widget_set_composite_name (priv->hsb, "hscrollbar");
968
gtk_widget_pop_composite_child ();
970
gtk_widget_set_parent (priv->hsb, GTK_WIDGET (sf));
971
gtk_widget_ref (priv->hsb);
972
gtk_widget_show (priv->hsb);
974
GtkAdjustment *old_adj;
976
old_adj = gtk_range_get_adjustment (GTK_RANGE (priv->hsb));
980
gtk_signal_disconnect_by_func (GTK_OBJECT (old_adj),
981
GTK_SIGNAL_FUNC (adjustment_changed),
983
gtk_range_set_adjustment (GTK_RANGE (priv->hsb), adj);
986
adj = gtk_range_get_adjustment (GTK_RANGE (priv->hsb));
987
gtk_signal_connect (GTK_OBJECT (adj),
989
GTK_SIGNAL_FUNC (adjustment_changed),
991
adjustment_changed (adj, sf);
993
if (GTK_BIN (sf)->child)
994
gtk_widget_set_scroll_adjustments (
996
gtk_range_get_adjustment (GTK_RANGE (priv->hsb)),
997
gtk_range_get_adjustment (GTK_RANGE (priv->vsb)));
1001
* gtk_scroll_frame_set_vadjustment:
1002
* @sf: A scroll frame widget.
1003
* @adj: An adjustment.
1005
* Sets the adjustment to be used for vertical scrolling in a scroll frame
1009
gtk_scroll_frame_set_vadjustment (GtkScrollFrame *sf, GtkAdjustment *adj)
1011
ScrollFramePrivate *priv;
1013
g_return_if_fail (sf != NULL);
1014
g_return_if_fail (GTK_IS_SCROLL_FRAME (sf));
1019
g_return_if_fail (GTK_IS_ADJUSTMENT (adj));
1021
adj = GTK_ADJUSTMENT (gtk_object_new (GTK_TYPE_ADJUSTMENT, NULL));
1024
gtk_widget_push_composite_child ();
1025
priv->vsb = gtk_vscrollbar_new (adj);
1026
gtk_widget_set_composite_name (priv->vsb, "vscrollbar");
1027
gtk_widget_pop_composite_child ();
1029
gtk_widget_set_parent (priv->vsb, GTK_WIDGET (sf));
1030
gtk_widget_ref (priv->vsb);
1031
gtk_widget_show (priv->vsb);
1033
GtkAdjustment *old_adj;
1035
old_adj = gtk_range_get_adjustment (GTK_RANGE (priv->vsb));
1039
gtk_signal_disconnect_by_func (GTK_OBJECT (old_adj),
1040
GTK_SIGNAL_FUNC (adjustment_changed),
1042
gtk_range_set_adjustment (GTK_RANGE (priv->vsb), adj);
1045
adj = gtk_range_get_adjustment (GTK_RANGE (priv->vsb));
1046
gtk_signal_connect (GTK_OBJECT (adj),
1048
GTK_SIGNAL_FUNC (adjustment_changed),
1050
adjustment_changed (adj, sf);
1052
if (GTK_BIN (sf)->child)
1053
gtk_widget_set_scroll_adjustments (
1054
GTK_BIN (sf)->child,
1055
gtk_range_get_adjustment (GTK_RANGE (priv->hsb)),
1056
gtk_range_get_adjustment (GTK_RANGE (priv->vsb)));
1060
* gtk_scroll_frame_get_hadjustment:
1061
* @sf: A scroll frame widget.
1063
* Queries the horizontal adjustment of a scroll frame widget.
1065
* Return value: The horizontal adjustment of the scroll frame, or NULL if none.
1068
gtk_scroll_frame_get_hadjustment (GtkScrollFrame *sf)
1070
ScrollFramePrivate *priv;
1072
g_return_val_if_fail (sf != NULL, NULL);
1073
g_return_val_if_fail (GTK_IS_SCROLL_FRAME (sf), NULL);
1077
return priv->hsb ? gtk_range_get_adjustment (GTK_RANGE (priv->hsb)) : NULL;
1081
* gtk_scroll_frame_get_vadjustment:
1082
* @sf: A scroll frame widget.
1084
* Queries the vertical adjustment of a scroll frame widget.
1086
* Return value: The vertical adjustment of the scroll frame, or NULL if none.
1089
gtk_scroll_frame_get_vadjustment (GtkScrollFrame *sf)
1091
ScrollFramePrivate *priv;
1093
g_return_val_if_fail (sf != NULL, NULL);
1094
g_return_val_if_fail (GTK_IS_SCROLL_FRAME (sf), NULL);
1098
return priv->vsb ? gtk_range_get_adjustment (GTK_RANGE (priv->vsb)) : NULL;
1102
* gtk_scroll_frame_set_policy:
1103
* @sf: A scroll frame widget.
1104
* @hsb_policy: Policy for the horizontal scrollbar.
1105
* @vsb_policy: Policy for the vertical scrollbar.
1107
* Sets the scrollbar policies of a scroll frame widget. These determine when
1108
* the scrollbars are to be shown or hidden.
1111
gtk_scroll_frame_set_policy (GtkScrollFrame *sf,
1112
GtkPolicyType hsb_policy,
1113
GtkPolicyType vsb_policy)
1115
ScrollFramePrivate *priv;
1117
g_return_if_fail (sf != NULL);
1118
g_return_if_fail (GTK_IS_SCROLL_FRAME (sf));
1122
if (priv->hsb_policy == hsb_policy && priv->vsb_policy == vsb_policy)
1125
priv->hsb_policy = hsb_policy;
1126
priv->vsb_policy = vsb_policy;
1128
gtk_widget_queue_resize (GTK_WIDGET (sf));
1132
* gtk_scroll_frame_get_policy:
1133
* @sf: A scroll frame widget.
1134
* @hsb_policy: Return value for the horizontal scrollbar's policy.
1135
* @vsb_policy: Return value for the vertical scrollbar's policy.
1137
* Queries the scrollbar policies of a scroll frame widget.
1140
gtk_scroll_frame_get_policy (GtkScrollFrame *sf,
1141
GtkPolicyType *hsb_policy,
1142
GtkPolicyType *vsb_policy)
1144
ScrollFramePrivate *priv;
1146
g_return_if_fail (sf != NULL);
1147
g_return_if_fail (GTK_IS_SCROLL_FRAME (sf));
1152
*hsb_policy = priv->hsb_policy;
1155
*vsb_policy = priv->vsb_policy;
1159
* gtk_scroll_frame_set_placement:
1160
* @sf: A scroll frame widget.
1161
* @frame_placement: Placement for the frame.
1163
* Sets the placement of a scroll frame widget's frame with respect to its
1167
gtk_scroll_frame_set_placement (GtkScrollFrame *sf, GtkCornerType frame_placement)
1169
ScrollFramePrivate *priv;
1171
g_return_if_fail (sf != NULL);
1172
g_return_if_fail (GTK_IS_SCROLL_FRAME (sf));
1176
if (priv->frame_placement == frame_placement)
1179
priv->frame_placement = frame_placement;
1180
gtk_widget_queue_resize (GTK_WIDGET (sf));
1184
* gtk_scroll_frame_set_shadow_type:
1185
* @sf: A scroll frame widget.
1186
* @shadow_type: A shadow type.
1188
* Sets the shadow type of a scroll frame widget. You can use this when you
1189
* insert a child that does not paint a frame on its own.
1192
gtk_scroll_frame_set_shadow_type (GtkScrollFrame *sf, GtkShadowType shadow_type)
1194
ScrollFramePrivate *priv;
1196
g_return_if_fail (sf != NULL);
1197
g_return_if_fail (GTK_IS_SCROLL_FRAME (sf));
1198
g_return_if_fail (shadow_type >= GTK_SHADOW_NONE && shadow_type <= GTK_SHADOW_ETCHED_OUT);
1202
if (priv->shadow_type == shadow_type)
1205
priv->shadow_type = shadow_type;
1206
gtk_widget_queue_resize (GTK_WIDGET (sf));
1210
* gtk_scroll_frame_get_shadow_type:
1211
* @sf: A scroll frame widget.
1213
* Queries the shadow type of a scroll frame widget.
1215
* Return value: Shadow type.
1218
gtk_scroll_frame_get_shadow_type (GtkScrollFrame *sf)
1220
ScrollFramePrivate *priv;
1222
g_return_val_if_fail (sf != NULL, GTK_SHADOW_NONE);
1223
g_return_val_if_fail (GTK_IS_SCROLL_FRAME (sf), GTK_SHADOW_NONE);
1227
return priv->shadow_type;
1231
* gtk_scroll_frame_set_scrollbar_spacing:
1232
* @sf: A scroll frame widget.
1233
* @spacing: Desired spacing in pixels.
1235
* Sets the spacing between the frame and the scrollbars of a scroll frame
1239
gtk_scroll_frame_set_scrollbar_spacing (GtkScrollFrame *sf, guint spacing)
1241
ScrollFramePrivate *priv;
1243
g_return_if_fail (sf != NULL);
1244
g_return_if_fail (GTK_IS_SCROLL_FRAME (sf));
1248
if (priv->sb_spacing == spacing)
1251
priv->sb_spacing = spacing;
1252
gtk_widget_queue_resize (GTK_WIDGET (sf));
1256
* gtk_scroll_frame_add_with_viewport:
1257
* @sf: A scroll frame widget.
1260
* Creates a #GtkViewport and puts the specified child inside it, thus allowing
1261
* the viewport to be scrolled by the scroll frame widget. This is meant to be
1262
* used only when a child does not support the scrolling interface.
1265
gtk_scroll_frame_add_with_viewport (GtkScrollFrame *sf, GtkWidget *child)
1267
ScrollFramePrivate *priv;
1269
GtkWidget *viewport;
1271
g_return_if_fail (sf != NULL);
1272
g_return_if_fail (GTK_IS_SCROLL_FRAME (sf));
1273
g_return_if_fail (child != NULL);
1274
g_return_if_fail (GTK_IS_WIDGET (child));
1275
g_return_if_fail (child->parent == NULL);
1280
if (bin->child != NULL) {
1281
g_return_if_fail (GTK_IS_VIEWPORT (bin->child));
1282
g_return_if_fail (GTK_BIN (bin->child)->child == NULL);
1284
viewport = bin->child;
1286
viewport = gtk_viewport_new (gtk_scroll_frame_get_hadjustment (sf),
1287
gtk_scroll_frame_get_vadjustment (sf));
1288
gtk_container_add (GTK_CONTAINER (sf), viewport);
1291
gtk_widget_show (viewport);
1292
gtk_container_add (GTK_CONTAINER (viewport), child);