]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkviewport.c
Deprecate flag macros for toplevel, state, no window and composite child
[~andy/gtk] / gtk / gtkviewport.c
index 3d18da0c2c0088fa01f7df24d9bbee317ea9271a..d650a4029e3864247015577a2e2c6df81d8cdd38 100644 (file)
@@ -24,7 +24,7 @@
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
-#include <config.h>
+#include "config.h"
 #include "gtkviewport.h"
 #include "gtkintl.h"
 #include "gtkmarshalers.h"
@@ -125,8 +125,17 @@ gtk_viewport_class_init (GtkViewportClass *class)
                                                      GTK_SHADOW_IN,
                                                      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 (I_("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),
@@ -221,7 +230,7 @@ gtk_viewport_new (GtkAdjustment *hadjustment,
 {
   GtkWidget *viewport;
 
-  viewport = gtk_widget_new (GTK_TYPE_VIEWPORT,
+  viewport = g_object_new (GTK_TYPE_VIEWPORT,
                             "hadjustment", hadjustment,
                             "vadjustment", vadjustment,
                             NULL);
@@ -442,7 +451,7 @@ viewport_set_adjustment (GtkViewport    *viewport,
   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);
 
@@ -457,8 +466,8 @@ viewport_set_adjustment (GtkViewport    *viewport,
 /**
  * gtk_viewport_set_hadjustment:
  * @viewport: a #GtkViewport.
- * @adjustment: a #GtkAdjustment.
- * 
+ * @adjustment: (allow-none): a #GtkAdjustment.
+ *
  * Sets the horizontal adjustment of the viewport.
  **/
 void
@@ -477,8 +486,8 @@ gtk_viewport_set_hadjustment (GtkViewport   *viewport,
 /**
  * gtk_viewport_set_vadjustment:
  * @viewport: a #GtkViewport.
- * @adjustment: a #GtkAdjustment.
- * 
+ * @adjustment: (allow-none): a #GtkAdjustment.
+ *
  * Sets the vertical adjustment of the viewport.
  **/
 void
@@ -547,6 +556,24 @@ gtk_viewport_get_shadow_type (GtkViewport *viewport)
   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)
 {
@@ -637,26 +664,20 @@ gtk_viewport_unrealize (GtkWidget *widget)
   gdk_window_destroy (viewport->bin_window);
   viewport->bin_window = NULL;
 
-  if (GTK_WIDGET_CLASS (gtk_viewport_parent_class)->unrealize)
-    (* GTK_WIDGET_CLASS (gtk_viewport_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);
     }
 }
@@ -679,8 +700,8 @@ gtk_viewport_expose (GtkWidget      *widget,
                             GTK_STATE_NORMAL, GTK_SHADOW_NONE,
                             &event->area, widget, "viewportbin",
                             0, 0, -1, -1);
-         
-         (* GTK_WIDGET_CLASS (gtk_viewport_parent_class)->expose_event) (widget, event);
+
+         GTK_WIDGET_CLASS (gtk_viewport_parent_class)->expose_event (widget, event);
        }
     }
 
@@ -691,11 +712,8 @@ static void
 gtk_viewport_add (GtkContainer *container,
                  GtkWidget    *child)
 {
-  GtkBin *bin;
+  GtkBin *bin = GTK_BIN (container);
 
-  g_return_if_fail (GTK_IS_WIDGET (child));
-
-  bin = GTK_BIN (container);
   g_return_if_fail (bin->child == NULL);
 
   gtk_widget_set_parent_window (child, GTK_VIEWPORT (bin)->bin_window);
@@ -707,16 +725,18 @@ static void
 gtk_viewport_size_request (GtkWidget      *widget,
                           GtkRequisition *requisition)
 {
-  GtkBin *bin;
+  GtkBin *bin = GTK_BIN (widget);
   GtkRequisition child_requisition;
 
-  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))
     {
@@ -734,9 +754,9 @@ gtk_viewport_size_allocate (GtkWidget     *widget,
   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.
@@ -748,47 +768,37 @@ gtk_viewport_size_allocate (GtkWidget     *widget,
     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);
@@ -802,14 +812,8 @@ static void
 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))
@@ -835,13 +839,11 @@ static void
 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);
      }