]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtktoolpalette.c
Added initial revision of GtkWrapBox container widget and test case.
[~andy/gtk] / gtk / gtktoolpalette.c
index ac5a5a777311f6f5a06177dd5178161588fa3ff6..15ecf3eba8429cc6e4c7ab4186cd38f3bf671345 100644 (file)
@@ -29,7 +29,6 @@
 
 #include "gtkprivate.h"
 #include "gtkintl.h"
-#include "gtkalias.h"
 
 #define DEFAULT_ICON_SIZE       GTK_ICON_SIZE_SMALL_TOOLBAR
 #define DEFAULT_ORIENTATION     GTK_ORIENTATION_VERTICAL
@@ -349,11 +348,13 @@ static void
 gtk_tool_palette_size_request (GtkWidget      *widget,
                                GtkRequisition *requisition)
 {
-  const gint border_width = GTK_CONTAINER (widget)->border_width;
   GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
   GtkRequisition child_requisition;
+  guint border_width;
   guint i;
 
+  border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
+
   requisition->width = 0;
   requisition->height = 0;
 
@@ -386,7 +387,6 @@ static void
 gtk_tool_palette_size_allocate (GtkWidget     *widget,
                                 GtkAllocation *allocation)
 {
-  const gint border_width = GTK_CONTAINER (widget)->border_width;
   GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
   GtkAdjustment *adjustment = NULL;
   GtkAllocation child_allocation;
@@ -398,6 +398,7 @@ gtk_tool_palette_size_allocate (GtkWidget     *widget,
   gint page_start, page_size = 0;
   gint offset = 0;
   guint i;
+  guint border_width;
 
   gint min_offset = -1, max_offset = -1;
 
@@ -405,6 +406,7 @@ gtk_tool_palette_size_allocate (GtkWidget     *widget,
 
   gint *group_sizes = g_newa (gint, palette->priv->groups->len);
 
+  border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
   GtkTextDirection direction = gtk_widget_get_direction (widget);
 
   GTK_WIDGET_CLASS (gtk_tool_palette_parent_class)->size_allocate (widget, allocation);
@@ -618,15 +620,18 @@ gtk_tool_palette_expose_event (GtkWidget      *widget,
 {
   GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
   GdkDisplay *display;
+  GdkWindow *window;
   cairo_t *cr;
   guint i;
 
-  display = gdk_drawable_get_display (widget->window);
+  window = gtk_widget_get_window (widget);
+
+  display = gdk_drawable_get_display (window);
 
   if (!gdk_display_supports_composite (display))
     return FALSE;
 
-  cr = gdk_cairo_create (widget->window);
+  cr = gdk_cairo_create (window);
   gdk_cairo_region (cr, event->region);
   cairo_clip (cr);
 
@@ -650,33 +655,43 @@ gtk_tool_palette_expose_event (GtkWidget      *widget,
 static void
 gtk_tool_palette_realize (GtkWidget *widget)
 {
-  const gint border_width = GTK_CONTAINER (widget)->border_width;
-  gint attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+  GtkAllocation allocation;
+  GdkWindow *window;
   GdkWindowAttr attributes;
+  gint attributes_mask;
+  guint border_width;
+
+  gtk_widget_set_realized (widget, TRUE);
+
+  border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
+
+  gtk_widget_get_allocation (widget, &allocation);
 
   attributes.window_type = GDK_WINDOW_CHILD;
-  attributes.x = widget->allocation.x + border_width;
-  attributes.y = widget->allocation.y + border_width;
-  attributes.width = widget->allocation.width - border_width * 2;
-  attributes.height = widget->allocation.height - border_width * 2;
+  attributes.x = allocation.x + border_width;
+  attributes.y = allocation.y + border_width;
+  attributes.width = allocation.width - border_width * 2;
+  attributes.height = allocation.height - border_width * 2;
   attributes.wclass = GDK_INPUT_OUTPUT;
   attributes.visual = gtk_widget_get_visual (widget);
   attributes.colormap = gtk_widget_get_colormap (widget);
-  attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK
-                        | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
-                        | GDK_BUTTON_MOTION_MASK;
+  attributes.event_mask = gtk_widget_get_events (widget)
+                         | GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK
+                         | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
+                         | GDK_BUTTON_MOTION_MASK;
+  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
 
-  widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
-                                   &attributes, attributes_mask);
+  window = gdk_window_new (gtk_widget_get_parent_window (widget),
+                           &attributes, attributes_mask);
+  gdk_window_set_user_data (window, widget);
 
-  gdk_window_set_user_data (widget->window, widget);
-  widget->style = gtk_style_attach (widget->style, widget->window);
-  gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
-  GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
+  gtk_widget_style_attach (widget);
+  gtk_style_set_background (gtk_widget_get_style (widget),
+                            window, GTK_STATE_NORMAL);
 
   gtk_container_forall (GTK_CONTAINER (widget),
                         (GtkCallback) gtk_widget_set_parent_window,
-                        widget->window);
+                        window);
 
   gtk_widget_queue_resize_no_redraw (widget);
 }
@@ -685,8 +700,11 @@ static void
 gtk_tool_palette_adjustment_value_changed (GtkAdjustment *adjustment,
                                            gpointer       data)
 {
+  GtkAllocation allocation;
   GtkWidget *widget = GTK_WIDGET (data);
-  gtk_tool_palette_size_allocate (widget, &widget->allocation);
+
+  gtk_widget_get_allocation (widget, &allocation);
+  gtk_tool_palette_size_allocate (widget, &allocation);
 }
 
 static void
@@ -798,11 +816,13 @@ gtk_tool_palette_set_child_property (GtkContainer *container,
   switch (prop_id)
     {
       case CHILD_PROP_EXCLUSIVE:
-        gtk_tool_palette_set_exclusive (palette, child, g_value_get_boolean (value));
+        gtk_tool_palette_set_exclusive (palette, GTK_TOOL_ITEM_GROUP (child), 
+          g_value_get_boolean (value));
         break;
 
       case CHILD_PROP_EXPAND:
-        gtk_tool_palette_set_expand (palette, child, g_value_get_boolean (value));
+        gtk_tool_palette_set_expand (palette, GTK_TOOL_ITEM_GROUP (child), 
+          g_value_get_boolean (value));
         break;
 
       default:
@@ -823,11 +843,13 @@ gtk_tool_palette_get_child_property (GtkContainer *container,
   switch (prop_id)
     {
       case CHILD_PROP_EXCLUSIVE:
-        g_value_set_boolean (value, gtk_tool_palette_get_exclusive (palette, child));
+        g_value_set_boolean (value, 
+          gtk_tool_palette_get_exclusive (palette, GTK_TOOL_ITEM_GROUP (child)));
         break;
 
       case CHILD_PROP_EXPAND:
-        g_value_set_boolean (value, gtk_tool_palette_get_expand (palette, child));
+        g_value_set_boolean (value, 
+          gtk_tool_palette_get_expand (palette, GTK_TOOL_ITEM_GROUP (child)));
         break;
 
       default:
@@ -1294,9 +1316,9 @@ _gtk_tool_palette_compare_groups (gconstpointer a,
  * Since: 2.20
  */
 void
-gtk_tool_palette_set_group_position (GtkToolPalette *palette,
-                                     GtkWidget      *group,
-                                     gint            position)
+gtk_tool_palette_set_group_position (GtkToolPalette   *palette,
+                                     GtkToolItemGroup *group,
+                                     gint             position)
 {
   GtkToolItemGroupInfo *group_new;
   GtkToolItemGroupInfo *group_old;
@@ -1362,9 +1384,9 @@ gtk_tool_palette_group_notify_collapsed (GtkToolItemGroup *group,
  * Since: 2.20
  */
 void
-gtk_tool_palette_set_exclusive (GtkToolPalette *palette,
-                                GtkWidget      *group,
-                                gboolean        exclusive)
+gtk_tool_palette_set_exclusive (GtkToolPalette   *palette,
+                                GtkToolItemGroup *group,
+                                gboolean          exclusive)
 {
   GtkToolItemGroupInfo *group_info;
   gint position;
@@ -1399,7 +1421,7 @@ gtk_tool_palette_set_exclusive (GtkToolPalette *palette,
     }
 
   gtk_tool_palette_group_notify_collapsed (group_info->widget, NULL, palette);
-  gtk_widget_child_notify (group, "exclusive");
+  gtk_widget_child_notify (GTK_WIDGET (group), "exclusive");
 }
 
 /**
@@ -1413,8 +1435,8 @@ gtk_tool_palette_set_exclusive (GtkToolPalette *palette,
  * Since: 2.20
  */
 void
-gtk_tool_palette_set_expand (GtkToolPalette *palette,
-                             GtkWidget      *group,
+gtk_tool_palette_set_expand (GtkToolPalette   *palette,
+                             GtkToolItemGroup *group,
                              gboolean        expand)
 {
   GtkToolItemGroupInfo *group_info;
@@ -1432,7 +1454,7 @@ gtk_tool_palette_set_expand (GtkToolPalette *palette,
     {
       group_info->expand = expand;
       gtk_widget_queue_resize (GTK_WIDGET (palette));
-      gtk_widget_child_notify (group, "expand");
+      gtk_widget_child_notify (GTK_WIDGET (group), "expand");
     }
 }
 
@@ -1449,8 +1471,8 @@ gtk_tool_palette_set_expand (GtkToolPalette *palette,
  * Since: 2.20
  */
 gint
-gtk_tool_palette_get_group_position (GtkToolPalette *palette,
-                                     GtkWidget      *group)
+gtk_tool_palette_get_group_position (GtkToolPalette   *palette,
+                                     GtkToolItemGroup *group)
 {
   guint i;
 
@@ -1480,8 +1502,8 @@ gtk_tool_palette_get_group_position (GtkToolPalette *palette,
  * Since: 2.20
  */
 gboolean
-gtk_tool_palette_get_exclusive (GtkToolPalette *palette,
-                                GtkWidget      *group)
+gtk_tool_palette_get_exclusive (GtkToolPalette   *palette,
+                                GtkToolItemGroup *group)
 {
   gint position;
   GtkToolItemGroupInfo *info;
@@ -1510,8 +1532,8 @@ gtk_tool_palette_get_exclusive (GtkToolPalette *palette,
  * Since: 2.20
  */
 gboolean
-gtk_tool_palette_get_expand (GtkToolPalette *palette,
-                             GtkWidget      *group)
+gtk_tool_palette_get_expand (GtkToolPalette   *palette,
+                             GtkToolItemGroup *group)
 {
   gint position;
   GtkToolItemGroupInfo *info;
@@ -1545,12 +1567,17 @@ gtk_tool_palette_get_drop_item (GtkToolPalette *palette,
                                 gint            x,
                                 gint            y)
 {
-  GtkWidget *group = gtk_tool_palette_get_drop_group (palette, x, y);
+  GtkAllocation allocation;
+  GtkToolItemGroup *group = gtk_tool_palette_get_drop_group (palette, x, y);
+  GtkWidget *widget = GTK_WIDGET (group);
 
   if (group)
-    return gtk_tool_item_group_get_drop_item (GTK_TOOL_ITEM_GROUP (group),
-                                              x - group->allocation.x,
-                                              y - group->allocation.y);
+    {
+      gtk_widget_get_allocation (widget, &allocation);
+      return gtk_tool_item_group_get_drop_item (group,
+                                                x - allocation.x,
+                                                y - allocation.y);
+    }
 
   return NULL;
 }
@@ -1568,20 +1595,20 @@ gtk_tool_palette_get_drop_item (GtkToolPalette *palette,
  *
  * Since: 2.20
  */
-GtkWidget*
+GtkToolItemGroup*
 gtk_tool_palette_get_drop_group (GtkToolPalette *palette,
                                  gint            x,
                                  gint            y)
 {
-  GtkAllocation *allocation;
+  GtkAllocation allocation;
   guint i;
 
   g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
 
-  allocation = &GTK_WIDGET (palette)->allocation;
+  gtk_widget_get_allocation (GTK_WIDGET (palette), &allocation);
 
-  g_return_val_if_fail (x >= 0 && x < allocation->width, NULL);
-  g_return_val_if_fail (y >= 0 && y < allocation->height, NULL);
+  g_return_val_if_fail (x >= 0 && x < allocation.width, NULL);
+  g_return_val_if_fail (y >= 0 && y < allocation.height, NULL);
 
   for (i = 0; i < palette->priv->groups->len; ++i)
     {
@@ -1593,13 +1620,14 @@ gtk_tool_palette_get_drop_group (GtkToolPalette *palette,
         continue;
 
       widget = GTK_WIDGET (group->widget);
+      gtk_widget_get_allocation (widget, &allocation);
 
-      x0 = x - widget->allocation.x;
-      y0 = y - widget->allocation.y;
+      x0 = x - allocation.x;
+      y0 = y - allocation.y;
 
-      if (x0 >= 0 && x0 < widget->allocation.width &&
-          y0 >= 0 && y0 < widget->allocation.height)
-        return widget;
+      if (x0 >= 0 && x0 < allocation.width &&
+          y0 >= 0 && y0 < allocation.height)
+        return GTK_TOOL_ITEM_GROUP (widget);
     }
 
   return NULL;
@@ -1919,7 +1947,3 @@ _gtk_tool_palette_get_size_group (GtkToolPalette *palette)
 
   return palette->priv->text_size_group;
 }
-
-
-#define __GTK_TOOL_PALETTE_C__
-#include "gtkaliasdef.c"