* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
-#include <config.h>
-#include "gtkalias.h"
+#include "config.h"
#include "gtkviewport.h"
#include "gtkintl.h"
#include "gtkmarshalers.h"
+#include "gtkprivate.h"
+#include "gtkalias.h"
enum {
PROP_0,
};
-static void gtk_viewport_class_init (GtkViewportClass *klass);
-static void gtk_viewport_init (GtkViewport *viewport);
static void gtk_viewport_finalize (GObject *object);
static void gtk_viewport_destroy (GtkObject *object);
static void gtk_viewport_set_property (GObject *object,
static void gtk_viewport_style_set (GtkWidget *widget,
GtkStyle *previous_style);
-static GtkBinClass *parent_class;
-
-GType
-gtk_viewport_get_type (void)
-{
- static GType viewport_type = 0;
-
- if (!viewport_type)
- {
- static const GTypeInfo viewport_info =
- {
- sizeof (GtkViewportClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) gtk_viewport_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (GtkViewport),
- 0, /* n_preallocs */
- (GInstanceInitFunc) gtk_viewport_init,
- };
-
- viewport_type = g_type_register_static (GTK_TYPE_BIN, "GtkViewport",
- &viewport_info, 0);
- }
-
- return viewport_type;
-}
+G_DEFINE_TYPE (GtkViewport, gtk_viewport, GTK_TYPE_BIN)
static void
gtk_viewport_class_init (GtkViewportClass *class)
widget_class = (GtkWidgetClass*) class;
container_class = (GtkContainerClass*) class;
- parent_class = g_type_class_peek_parent (class);
-
gobject_class->finalize = gtk_viewport_finalize;
gobject_class->set_property = gtk_viewport_set_property;
gobject_class->get_property = gtk_viewport_get_property;
P_("Horizontal adjustment"),
P_("The GtkAdjustment that determines the values of the horizontal position for this viewport"),
GTK_TYPE_ADJUSTMENT,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (gobject_class,
PROP_VADJUSTMENT,
P_("Vertical adjustment"),
P_("The GtkAdjustment that determines the values of the vertical position for this viewport"),
GTK_TYPE_ADJUSTMENT,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (gobject_class,
PROP_SHADOW_TYPE,
- g_param_spec_enum ("shadow_type",
+ g_param_spec_enum ("shadow-type",
P_("Shadow type"),
P_("Determines how the shadowed box around the viewport is drawn"),
GTK_TYPE_SHADOW_TYPE,
GTK_SHADOW_IN,
- G_PARAM_READWRITE));
-
+ GTK_PARAM_READWRITE));
+
+ /**
+ * GtkViewport::set-scroll-adjustments
+ * @horizontal: the horizontal #GtkAdjustment
+ * @vertical: the vertical #GtkAdjustment
+ *
+ * Set the scroll adjustments for the viewport. Usually scrolled containers
+ * like #GtkScrolledWindow will emit this signal to connect two instances
+ * of #GtkScrollbar to the scroll directions of the #GtkViewport.
+ */
widget_class->set_scroll_adjustments_signal =
- g_signal_new ("set_scroll_adjustments",
+ g_signal_new (I_("set-scroll-adjustments"),
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkViewportClass, set_scroll_adjustments),
{
GtkWidget *viewport;
- viewport = gtk_widget_new (GTK_TYPE_VIEWPORT,
+ viewport = g_object_new (GTK_TYPE_VIEWPORT,
"hadjustment", hadjustment,
"vadjustment", vadjustment,
NULL);
viewport_disconnect_adjustment (viewport, GTK_ORIENTATION_HORIZONTAL);
viewport_disconnect_adjustment (viewport, GTK_ORIENTATION_VERTICAL);
- G_OBJECT_CLASS (parent_class)->finalize (object);
+ G_OBJECT_CLASS (gtk_viewport_parent_class)->finalize (object);
}
static void
viewport_disconnect_adjustment (viewport, GTK_ORIENTATION_HORIZONTAL);
viewport_disconnect_adjustment (viewport, GTK_ORIENTATION_VERTICAL);
- GTK_OBJECT_CLASS (parent_class)->destroy (object);
+ GTK_OBJECT_CLASS (gtk_viewport_parent_class)->destroy (object);
}
/**
if (!adjustment)
adjustment = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0,
0.0, 0.0, 0.0));
- if (*adjustmentp)
- g_object_unref (*adjustmentp);
+ viewport_disconnect_adjustment (viewport, orientation);
*adjustmentp = adjustment;
- g_object_ref (adjustment);
- gtk_object_sink (GTK_OBJECT (adjustment));
+ g_object_ref_sink (adjustment);
if (orientation == GTK_ORIENTATION_HORIZONTAL)
viewport_set_hadjustment_values (viewport, &value_changed);
else
viewport_set_vadjustment_values (viewport, &value_changed);
- g_signal_connect (adjustment, "value_changed",
+ g_signal_connect (adjustment, "value-changed",
G_CALLBACK (gtk_viewport_adjustment_value_changed),
viewport);
/**
* gtk_viewport_set_hadjustment:
* @viewport: a #GtkViewport.
- * @adjustment: a #GtkAdjustment.
- *
+ * @adjustment: (allow-none): a #GtkAdjustment.
+ *
* Sets the horizontal adjustment of the viewport.
**/
void
/**
* gtk_viewport_set_vadjustment:
* @viewport: a #GtkViewport.
- * @adjustment: a #GtkAdjustment.
- *
+ * @adjustment: (allow-none): a #GtkAdjustment.
+ *
* Sets the vertical adjustment of the viewport.
**/
void
gtk_widget_queue_draw (GTK_WIDGET (viewport));
}
- g_object_notify (G_OBJECT (viewport), "shadow_type");
+ g_object_notify (G_OBJECT (viewport), "shadow-type");
}
}
return viewport->shadow_type;
}
+/**
+ * gtk_viewport_get_bin_window:
+ * @viewport: a #GtkViewport
+ *
+ * Gets the bin window of the #GtkViewport.
+ *
+ * Return value: a #GdkWindow
+ *
+ * Since: 2.20
+ **/
+GdkWindow*
+gtk_viewport_get_bin_window (GtkViewport *viewport)
+{
+ g_return_val_if_fail (GTK_IS_VIEWPORT (viewport), NULL);
+
+ return viewport->bin_window;
+}
+
static void
gtk_viewport_realize (GtkWidget *widget)
{
gdk_window_destroy (viewport->bin_window);
viewport->bin_window = NULL;
- if (GTK_WIDGET_CLASS (parent_class)->unrealize)
- (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
+ GTK_WIDGET_CLASS (gtk_viewport_parent_class)->unrealize (widget);
}
static void
gtk_viewport_paint (GtkWidget *widget,
GdkRectangle *area)
{
- GtkViewport *viewport;
-
- g_return_if_fail (GTK_IS_VIEWPORT (widget));
- g_return_if_fail (area != NULL);
-
if (GTK_WIDGET_DRAWABLE (widget))
{
- viewport = GTK_VIEWPORT (widget);
+ GtkViewport *viewport = GTK_VIEWPORT (widget);
gtk_paint_shadow (widget->style, widget->window,
GTK_STATE_NORMAL, viewport->shadow_type,
- NULL, widget, "viewport",
+ area, widget, "viewport",
0, 0, -1, -1);
}
}
GdkEventExpose *event)
{
GtkViewport *viewport;
- GtkBin *bin;
if (GTK_WIDGET_DRAWABLE (widget))
{
viewport = GTK_VIEWPORT (widget);
- bin = GTK_BIN (widget);
if (event->window == widget->window)
gtk_viewport_paint (widget, &event->area);
GTK_STATE_NORMAL, GTK_SHADOW_NONE,
&event->area, widget, "viewportbin",
0, 0, -1, -1);
-
- (* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event);
+
+ GTK_WIDGET_CLASS (gtk_viewport_parent_class)->expose_event (widget, event);
}
}
gtk_viewport_add (GtkContainer *container,
GtkWidget *child)
{
- GtkBin *bin;
-
- g_return_if_fail (GTK_IS_WIDGET (child));
+ GtkBin *bin = GTK_BIN (container);
- bin = GTK_BIN (container);
g_return_if_fail (bin->child == NULL);
gtk_widget_set_parent_window (child, GTK_VIEWPORT (bin)->bin_window);
- GTK_CONTAINER_CLASS (parent_class)->add (container, child);
+ GTK_CONTAINER_CLASS (gtk_viewport_parent_class)->add (container, child);
}
static void
gtk_viewport_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
- GtkViewport *viewport;
- GtkBin *bin;
+ GtkBin *bin = GTK_BIN (widget);
GtkRequisition child_requisition;
- viewport = GTK_VIEWPORT (widget);
- bin = GTK_BIN (widget);
+ requisition->width = GTK_CONTAINER (widget)->border_width;
- requisition->width = (GTK_CONTAINER (widget)->border_width +
- GTK_WIDGET (widget)->style->xthickness) * 2;
+ requisition->height = GTK_CONTAINER (widget)->border_width;
- requisition->height = (GTK_CONTAINER (widget)->border_width * 2 +
- GTK_WIDGET (widget)->style->ythickness) * 2;
+ if (GTK_VIEWPORT (widget)->shadow_type != GTK_SHADOW_NONE)
+ {
+ requisition->width += 2 * widget->style->xthickness;
+ requisition->height += 2 * widget->style->ythickness;
+ }
if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
{
GtkBin *bin = GTK_BIN (widget);
gint border_width = GTK_CONTAINER (widget)->border_width;
gboolean hadjustment_value_changed, vadjustment_value_changed;
-
GtkAdjustment *hadjustment = gtk_viewport_get_hadjustment (viewport);
GtkAdjustment *vadjustment = gtk_viewport_get_vadjustment (viewport);
+ GtkAllocation child_allocation;
/* If our size changed, and we have a shadow, queue a redraw on widget->window to
* redraw the shadow correctly.
gdk_window_invalidate_rect (widget->window, NULL, FALSE);
widget->allocation = *allocation;
-
+
viewport_set_hadjustment_values (viewport, &hadjustment_value_changed);
viewport_set_vadjustment_values (viewport, &vadjustment_value_changed);
-
+
+ child_allocation.x = 0;
+ child_allocation.y = 0;
+ child_allocation.width = hadjustment->upper;
+ child_allocation.height = vadjustment->upper;
if (GTK_WIDGET_REALIZED (widget))
{
GtkAllocation view_allocation;
-
- viewport_get_view_allocation (viewport, &view_allocation);
-
gdk_window_move_resize (widget->window,
allocation->x + border_width,
allocation->y + border_width,
allocation->width - border_width * 2,
allocation->height - border_width * 2);
-
+
+ viewport_get_view_allocation (viewport, &view_allocation);
gdk_window_move_resize (viewport->view_window,
view_allocation.x,
view_allocation.y,
view_allocation.width,
view_allocation.height);
+ gdk_window_move_resize (viewport->bin_window,
+ - hadjustment->value,
+ - vadjustment->value,
+ child_allocation.width,
+ child_allocation.height);
}
-
if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
- {
- GtkAllocation child_allocation;
-
- child_allocation.x = 0;
- child_allocation.y = 0;
- child_allocation.width = hadjustment->upper;
- child_allocation.height = vadjustment->upper;
-
- if (GTK_WIDGET_REALIZED (widget))
- gdk_window_move_resize (viewport->bin_window,
- - hadjustment->value,
- - vadjustment->value,
- child_allocation.width,
- child_allocation.height);
-
- gtk_widget_size_allocate (bin->child, &child_allocation);
- }
+ gtk_widget_size_allocate (bin->child, &child_allocation);
gtk_adjustment_changed (hadjustment);
gtk_adjustment_changed (vadjustment);
gtk_viewport_adjustment_value_changed (GtkAdjustment *adjustment,
gpointer data)
{
- GtkViewport *viewport;
- GtkBin *bin;
-
- g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
- g_return_if_fail (GTK_IS_VIEWPORT (data));
-
- viewport = GTK_VIEWPORT (data);
- bin = GTK_BIN (data);
+ GtkViewport *viewport = GTK_VIEWPORT (data);
+ GtkBin *bin = GTK_BIN (data);
if (bin->child && GTK_WIDGET_VISIBLE (bin->child) &&
GTK_WIDGET_REALIZED (viewport))
gtk_viewport_style_set (GtkWidget *widget,
GtkStyle *previous_style)
{
- GtkViewport *viewport;
-
if (GTK_WIDGET_REALIZED (widget) &&
- !GTK_WIDGET_NO_WINDOW (widget))
+ gtk_widget_get_has_window (widget))
{
- viewport = GTK_VIEWPORT (widget);
-
+ GtkViewport *viewport = GTK_VIEWPORT (widget);
+
gtk_style_set_background (widget->style, viewport->bin_window, GTK_STATE_NORMAL);
gtk_style_set_background (widget->style, widget->window, widget->state);
}
}
+
+#define __GTK_VIEWPORT_C__
+#include "gtkaliasdef.c"