]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkviewport.c
Merges from gtk-1-2
[~andy/gtk] / gtk / gtkviewport.c
index 80e7e6383d4552d038a5ceaabf92779feb285419..afffdf01ad5580e4c04824f63c33db81f4f1c2e7 100644 (file)
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
  */
+
+/*
+ * Modified by the GTK+ Team and others 1997-1999.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
+ */
+
 #include "gtksignal.h"
 #include "gtkviewport.h"
 
@@ -382,12 +390,12 @@ gtk_viewport_map (GtkWidget *widget)
   GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
   bin = GTK_BIN (widget);
 
-  gdk_window_show (widget->window);
-
   if (bin->child &&
       GTK_WIDGET_VISIBLE (bin->child) &&
       !GTK_WIDGET_MAPPED (bin->child))
     gtk_widget_map (bin->child);
+
+  gdk_window_show (widget->window);
 }
 
 static void
@@ -430,7 +438,9 @@ gtk_viewport_realize (GtkWidget *widget)
   attributes.colormap = gtk_widget_get_colormap (widget);
 
   event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
-  attributes.event_mask = event_mask;
+  /* We select on button_press_mask so that button 4-5 scrolls are trapped.
+   */
+  attributes.event_mask = event_mask | GDK_BUTTON_PRESS_MASK;
 
   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
 
@@ -449,8 +459,8 @@ gtk_viewport_realize (GtkWidget *widget)
       attributes.y = 0;
     }
 
-  attributes.width = MAX (1, widget->allocation.width - attributes.x * 2 - border_width * 2);
-  attributes.height = MAX (1, widget->allocation.height - attributes.y * 2 - border_width * 2);
+  attributes.width = MAX (1, (gint)widget->allocation.width - attributes.x * 2 - border_width * 2);
+  attributes.height = MAX (1, (gint)widget->allocation.height - attributes.y * 2 - border_width * 2);
   attributes.event_mask = 0;
 
   viewport->view_window = gdk_window_new (widget->window, &attributes, attributes_mask);
@@ -555,11 +565,16 @@ gtk_viewport_draw (GtkWidget    *widget,
       
       gtk_viewport_paint (widget, &tmp_area);
 
+      tmp_area.x += viewport->hadjustment->value - widget->style->klass->xthickness;
+      tmp_area.y += viewport->vadjustment->value - widget->style->klass->ythickness;
+      
+      gtk_paint_flat_box(widget->style, viewport->bin_window, 
+                        GTK_STATE_NORMAL, GTK_SHADOW_NONE,
+                        &tmp_area, widget, "viewportbin",
+                        0, 0, -1, -1);
+
       if (bin->child)
        {
-         tmp_area.x += viewport->hadjustment->value - widget->style->klass->xthickness;
-         tmp_area.y += viewport->vadjustment->value - widget->style->klass->ythickness;
-
          if (gtk_widget_intersect (bin->child, &tmp_area, &child_area))
            gtk_widget_draw (bin->child, &child_area);
        }
@@ -585,13 +600,22 @@ gtk_viewport_expose (GtkWidget      *widget,
 
       if (event->window == widget->window)
        gtk_viewport_paint (widget, &event->area);
+      else if (event->window == viewport->bin_window)
+       {
+         child_event = *event;
+
+         gtk_paint_flat_box(widget->style, viewport->bin_window, 
+                            GTK_STATE_NORMAL, GTK_SHADOW_NONE,
+                            &event->area, widget, "viewportbin",
+                            0, 0, -1, -1);
+         
+         if ((bin->child != NULL) &&
+             GTK_WIDGET_NO_WINDOW (bin->child) &&
+             gtk_widget_intersect (bin->child, &event->area, &child_event.area))
+           gtk_widget_event (bin->child, (GdkEvent*) &child_event);
+       }
+       
 
-      child_event = *event;
-      if ((event->window == viewport->bin_window) &&
-         (bin->child != NULL) &&
-         GTK_WIDGET_NO_WINDOW (bin->child) &&
-         gtk_widget_intersect (bin->child, &event->area, &child_event.area))
-       gtk_widget_event (bin->child, (GdkEvent*) &child_event);
     }
 
   return FALSE;
@@ -621,6 +645,7 @@ gtk_viewport_size_request (GtkWidget      *widget,
 {
   GtkViewport *viewport;
   GtkBin *bin;
+  GtkRequisition child_requisition;
 
   g_return_if_fail (widget != NULL);
   g_return_if_fail (GTK_IS_VIEWPORT (widget));
@@ -637,9 +662,9 @@ gtk_viewport_size_request (GtkWidget      *widget,
 
   if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
     {
-      gtk_widget_size_request (bin->child, &bin->child->requisition);
-      requisition->width += bin->child->requisition.width;
-      requisition->height += bin->child->requisition.height;
+      gtk_widget_size_request (bin->child, &child_requisition);
+      requisition->width += child_requisition.width;
+      requisition->height += child_requisition.height;
     }
 }
 
@@ -688,10 +713,6 @@ gtk_viewport_size_allocate (GtkWidget     *widget,
                              child_allocation.y,
                              child_allocation.width,
                              child_allocation.height);
-       gtk_paint_flat_box(widget->style, viewport->bin_window, GTK_STATE_NORMAL,
-                         GTK_SHADOW_NONE,
-                         NULL, widget, "viewportbin",
-                         0, 0, -1, -1);
     }
 
   viewport->hadjustment->page_size = child_allocation.width;
@@ -707,8 +728,11 @@ gtk_viewport_size_allocate (GtkWidget     *widget,
 
   if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
     {
+      GtkRequisition child_requisition;
+      gtk_widget_get_child_requisition (bin->child, &child_requisition);
+      
       viewport->hadjustment->lower = 0;
-      viewport->hadjustment->upper = MAX (bin->child->requisition.width,
+      viewport->hadjustment->upper = MAX (child_requisition.width,
                                          child_allocation.width);
 
       hval = CLAMP (hval, 0,
@@ -716,7 +740,7 @@ gtk_viewport_size_allocate (GtkWidget     *widget,
                    viewport->hadjustment->page_size);
 
       viewport->vadjustment->lower = 0;
-      viewport->vadjustment->upper = MAX (bin->child->requisition.height,
+      viewport->vadjustment->upper = MAX (child_requisition.height,
                                          child_allocation.height);
 
       vval = CLAMP (vval, 0,
@@ -732,12 +756,10 @@ gtk_viewport_size_allocate (GtkWidget     *widget,
       child_allocation.width = viewport->hadjustment->upper;
       child_allocation.height = viewport->vadjustment->upper;
 
-      if (!GTK_WIDGET_REALIZED (widget))
-        gtk_widget_realize (widget);
-
-      gdk_window_resize (viewport->bin_window,
-                        child_allocation.width,
-                        child_allocation.height);
+      if (GTK_WIDGET_REALIZED (widget))
+       gdk_window_resize (viewport->bin_window,
+                          child_allocation.width,
+                          child_allocation.height);
 
       child_allocation.x = 0;
       child_allocation.y = 0;
@@ -778,7 +800,6 @@ gtk_viewport_adjustment_value_changed (GtkAdjustment *adjustment,
   GtkViewport *viewport;
   GtkBin *bin;
   GtkAllocation child_allocation;
-  gint width, height;
 
   g_return_if_fail (adjustment != NULL);
   g_return_if_fail (data != NULL);
@@ -789,8 +810,6 @@ gtk_viewport_adjustment_value_changed (GtkAdjustment *adjustment,
 
   if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
     {
-      gdk_window_get_size (viewport->view_window, &width, &height);
-
       child_allocation.x = 0;
       child_allocation.y = 0;
 
@@ -822,14 +841,5 @@ gtk_viewport_style_set (GtkWidget *widget,
        
        gtk_style_set_background (widget->style, viewport->bin_window, GTK_STATE_NORMAL);
        gtk_style_set_background (widget->style, widget->window, widget->state);
-       gtk_paint_flat_box(widget->style, viewport->bin_window, GTK_STATE_NORMAL,
-                          GTK_SHADOW_NONE,
-                          NULL, widget, "viewportbin",
-                          0, 0, -1, -1);
-       if (GTK_WIDGET_DRAWABLE (widget))
-         {
-            gdk_window_clear (widget->window);
-            gdk_window_clear (viewport->bin_window);
-         }
      }
 }