]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/win_gtk.c
Context menu event from keyboard records the mouse position, not -1, -1,
[wxWidgets.git] / src / gtk / win_gtk.c
index 6115bc3a337fcddfcf8be76bc824937639ad8c49..6eb8b4e1e28aac2cda29d0f5b56dcbfcb9769c4a 100644 (file)
 extern "C" {
 #endif /* __cplusplus */
 
-typedef struct _GtkPizzaAdjData  GtkPizzaAdjData;
+typedef struct _GtkPizzaChild GtkPizzaChild;
+typedef struct _GtkPizzaClass GtkPizzaClass;
 
-struct _GtkPizzaAdjData
+struct _GtkPizzaClass
 {
-    gint dx;
-    gint dy;
+  GtkContainerClass parent_class;
+
+  void  (*set_scroll_adjustments)   (GtkPizza     *pizza,
+                                     GtkAdjustment  *hadjustment,
+                                     GtkAdjustment  *vadjustment);
+};
+
+struct _GtkPizzaChild
+{
+    GtkWidget *widget;
+    gint x;
+    gint y;
 };
 
 static void gtk_pizza_class_init    (GtkPizzaClass    *klass);
@@ -40,8 +51,6 @@ static void gtk_pizza_size_request  (GtkWidget        *widget,
                                      GtkRequisition   *requisition);
 static void gtk_pizza_size_allocate (GtkWidget        *widget,
                                      GtkAllocation    *allocation);
-static gint gtk_pizza_expose        (GtkWidget        *widget,
-                                     GdkEventExpose   *event);
 static void gtk_pizza_style_set     (GtkWidget *widget,
                                      GtkStyle  *previous_style);
 static void gtk_pizza_add           (GtkContainer     *container,
@@ -55,8 +64,6 @@ static void gtk_pizza_forall        (GtkContainer     *container,
 
 static void     gtk_pizza_allocate_child     (GtkPizza      *pizza,
                                               GtkPizzaChild *child);
-static void     gtk_pizza_adjust_allocations_recurse (GtkWidget *widget,
-                                                      gpointer   cb_data);
 
 static GtkType gtk_pizza_child_type (GtkContainer     *container);
 
@@ -73,7 +80,7 @@ gtk_pizza_get_type ()
 
     if (!pizza_type)
     {
-        static const GTypeInfo pizza_info =
+        const GTypeInfo pizza_info =
         {
             sizeof (GtkPizzaClass),
             NULL,           /* base_init */
@@ -84,6 +91,7 @@ gtk_pizza_get_type ()
             sizeof (GtkPizza),
             16,             /* n_preallocs */
             (GInstanceInitFunc) gtk_pizza_init,
+            NULL
         };
         pizza_type = g_type_register_static (GTK_TYPE_CONTAINER, "GtkPizza", &pizza_info, (GTypeFlags)0);
     }
@@ -147,7 +155,6 @@ gtk_pizza_class_init (GtkPizzaClass *klass)
     widget_class->unrealize = gtk_pizza_unrealize;
     widget_class->size_request = gtk_pizza_size_request;
     widget_class->size_allocate = gtk_pizza_size_allocate;
-    widget_class->expose_event = gtk_pizza_expose;
     widget_class->style_set = gtk_pizza_style_set;
 
     container_class->add = gtk_pizza_add;
@@ -182,18 +189,15 @@ gtk_pizza_child_type (GtkContainer     *container)
 static void
 gtk_pizza_init (GtkPizza *pizza)
 {
+    GTK_WIDGET_SET_FLAGS (pizza, GTK_CAN_FOCUS);
     GTK_WIDGET_UNSET_FLAGS (pizza, GTK_NO_WINDOW);
 
-    pizza->shadow_type = GTK_MYSHADOW_NONE;
-
     pizza->children = NULL;
 
     pizza->bin_window = NULL;
 
     pizza->m_xoffset = 0;
     pizza->m_yoffset = 0;
-    
-    pizza->m_width = -1;
 }
 
 GtkWidget*
@@ -202,6 +206,20 @@ gtk_pizza_new ()
     GtkPizza *pizza;
 
     pizza = g_object_new (gtk_pizza_get_type (), NULL);
+    
+    pizza->m_noscroll = FALSE;
+
+    return GTK_WIDGET (pizza);
+}
+
+GtkWidget*
+gtk_pizza_new_no_scroll ()
+{
+    GtkPizza *pizza;
+
+    pizza = g_object_new (gtk_pizza_get_type (), NULL);
+
+    pizza->m_noscroll = TRUE;
 
     return GTK_WIDGET (pizza);
 }
@@ -228,7 +246,7 @@ void       gtk_pizza_set_xoffset     (GtkPizza          *pizza, gint xoffset)
     g_return_if_fail (GTK_IS_PIZZA (pizza));
 
     pizza->m_xoffset = xoffset;
-    // do something
+    /* do something */
 }
 
 void       gtk_pizza_set_yoffset     (GtkPizza          *pizza, gint yoffset)
@@ -237,21 +255,21 @@ void       gtk_pizza_set_yoffset     (GtkPizza          *pizza, gint yoffset)
     g_return_if_fail (GTK_IS_PIZZA (pizza));
 
     pizza->m_xoffset = yoffset;
-    // do something
+    /* do something */
 }
 
 gint       gtk_pizza_get_rtl_offset  (GtkPizza          *pizza)
 {
-    gint width;
+    gint border;
 
     g_return_val_if_fail ( (pizza != NULL), 0 );
     g_return_val_if_fail ( (GTK_IS_PIZZA (pizza)), 0 );
-    
+
     if (!pizza->bin_window) return 0;
-    
-    gdk_window_get_geometry( pizza->bin_window, NULL, NULL, &width, NULL, NULL );
-    
-    return width;
+
+    border = pizza->container.border_width;
+
+    return GTK_WIDGET(pizza)->allocation.width - border*2;
 }
 
 
@@ -263,25 +281,6 @@ gtk_pizza_scroll_set_adjustments (GtkPizza     *pizza,
    /* We handle scrolling in the wxScrolledWindow, not here. */
 }
 
-void
-gtk_pizza_set_shadow_type (GtkPizza        *pizza,
-                           GtkMyShadowType  type)
-{
-    g_return_if_fail (pizza != NULL);
-    g_return_if_fail (GTK_IS_PIZZA (pizza));
-
-    if (pizza->shadow_type != type)
-    {
-        pizza->shadow_type = type;
-
-        if (GTK_WIDGET_VISIBLE (pizza))
-        {
-            gtk_widget_size_allocate (GTK_WIDGET (pizza), &(GTK_WIDGET (pizza)->allocation));
-            gtk_widget_queue_draw (GTK_WIDGET (pizza));
-        }
-    }
-}
-
 void
 gtk_pizza_put (GtkPizza   *pizza,
                GtkWidget  *widget,
@@ -296,31 +295,20 @@ gtk_pizza_put (GtkPizza   *pizza,
     g_return_if_fail (GTK_IS_PIZZA (pizza));
     g_return_if_fail (widget != NULL);
 
-    if (gtk_widget_get_direction( GTK_WIDGET(pizza) ) == GTK_TEXT_DIR_RTL)
-    {
-        // reverse horizontal placement
-        x = pizza->m_width - x - width;
-    }
-
     child_info = g_new (GtkPizzaChild, 1);
 
     child_info->widget = widget;
     child_info->x = x;
     child_info->y = y;
-    child_info->width = width;
-    child_info->height = height;
 
-    if (GTK_IS_PIZZA(widget))
-        GTK_PIZZA(widget)->m_width = width;
-                
     pizza->children = g_list_append (pizza->children, child_info);
 
     if (GTK_WIDGET_REALIZED (pizza))
-      gtk_widget_set_parent_window (widget, pizza->bin_window);
+        gtk_widget_set_parent_window (widget, pizza->bin_window);
 
     gtk_widget_set_parent (widget, GTK_WIDGET (pizza));
 
-    gtk_widget_set_size_request (widget, width, height);
+    gtk_widget_set_size_request( widget, width, height );
 }
 
 void
@@ -356,26 +344,13 @@ gtk_pizza_set_size (GtkPizza   *pizza,
 
         if (child->widget == widget)
         {
-            gint new_x = x;
-            if (gtk_widget_get_direction( GTK_WIDGET(pizza) ) == GTK_TEXT_DIR_RTL)
+            if (child->x != x || child->y != y)
             {
-                // reverse horizontal placement
-                new_x = pizza->m_width - new_x - width;
+                child->x = x;
+                child->y = y;
+                gtk_widget_queue_resize(widget);
             }
 
-            if ((child->x == new_x) &&
-                (child->y == y) &&
-                (child->width == width) &&
-                (child->height == height)) return;
-
-            child->x = new_x;
-            child->y = y;
-            child->width = width;
-            child->height = height;
-            
-            if (GTK_IS_PIZZA(widget))
-                GTK_PIZZA(widget)->m_width = width;
-
             gtk_widget_set_size_request (widget, width, height);
 
             return;
@@ -421,6 +396,8 @@ gtk_pizza_realize (GtkWidget *widget)
     gint attributes_mask;
     GtkPizzaChild *child;
     GList *children;
+    int border;
+    int w, h;
 
     g_return_if_fail (widget != NULL);
     g_return_if_fail (GTK_IS_PIZZA (widget));
@@ -435,34 +412,24 @@ gtk_pizza_realize (GtkWidget *widget)
     attributes.width = widget->allocation.width;
     attributes.height = widget->allocation.height;
 
-#ifndef __WXUNIVERSAL__
-    if (pizza->shadow_type == GTK_MYSHADOW_NONE)
-    {
-        /* no border, no changes to sizes */
-    }
-    else if (pizza->shadow_type == GTK_MYSHADOW_THIN)
-    {
-        /* GTK_MYSHADOW_THIN == wxSIMPLE_BORDER */
-        attributes.x += 1;
-        attributes.y += 1;
-        attributes.width -= 2;
-        attributes.height -= 2;
-    }
-    else
-    {
-        /* GTK_MYSHADOW_IN == wxSUNKEN_BORDER */
-        /* GTK_MYSHADOW_OUT == wxRAISED_BORDER */
-        attributes.x += 2;
-        attributes.y += 2;
-        attributes.width -= 4;
-        attributes.height -= 4;
-    }
-#endif /* __WXUNIVERSAL__ */
-
     /* minimal size */
     if (attributes.width < 2) attributes.width = 2;
     if (attributes.height < 2) attributes.height = 2;
 
+    border = pizza->container.border_width;
+    w = attributes.width  - 2 * border;
+    h = attributes.height - 2 * border;
+    if (w < 2) w = 2;
+    if (h < 2) h = 2;
+
+    if (!pizza->m_noscroll)
+    {
+        attributes.x += border;
+        attributes.y += border;
+        attributes.width  = w;
+        attributes.height = h;
+    }
+
     attributes.wclass = GDK_INPUT_OUTPUT;
     attributes.visual = gtk_widget_get_visual (widget);
     attributes.colormap = gtk_widget_get_colormap (widget);
@@ -475,6 +442,13 @@ gtk_pizza_realize (GtkWidget *widget)
 
     attributes.x = 0;
     attributes.y = 0;
+    if (pizza->m_noscroll)
+    {
+        attributes.x = border;
+        attributes.y = border;
+        attributes.width  = w;
+        attributes.height = h;
+    }
 
     attributes.event_mask = gtk_widget_get_events (widget);
     attributes.event_mask |= GDK_EXPOSURE_MASK              |
@@ -577,6 +551,7 @@ gtk_pizza_size_allocate (GtkWidget     *widget,
     gint x,y,w,h;
     GtkPizzaChild *child;
     GList *children;
+    gboolean only_resize;
 
     g_return_if_fail (widget != NULL);
     g_return_if_fail (GTK_IS_PIZZA(widget));
@@ -584,29 +559,42 @@ gtk_pizza_size_allocate (GtkWidget     *widget,
 
     pizza = GTK_PIZZA (widget);
 
+    only_resize = ((widget->allocation.x == allocation->x) &&
+                   (widget->allocation.y == allocation->y));
     widget->allocation = *allocation;
 
-    if (pizza->shadow_type == GTK_MYSHADOW_NONE)
-        border = 0;
-    else
-    if (pizza->shadow_type == GTK_MYSHADOW_THIN)
-        border = 1;
-    else
-        border = 2;
-
-    x = allocation->x + border;
-    y = allocation->y + border;
-    w = allocation->width - border*2;
-    h = allocation->height - border*2;
-    if (w < 0)
-        w = 0;
-    if (h < 0)
-        h = 0;
-
-    if (GTK_WIDGET_REALIZED (widget))
+    if (GTK_WIDGET_REALIZED(widget))
     {
-        gdk_window_move_resize( widget->window, x, y, w, h );
-        gdk_window_move_resize( pizza->bin_window, 0, 0, w, h );
+        border = pizza->container.border_width;
+
+        x = allocation->x + border;
+        y = allocation->y + border;
+        w = allocation->width - border*2;
+        h = allocation->height - border*2;
+        if (w < 0)
+            w = 0;
+        if (h < 0)
+            h = 0;
+
+        if (pizza->m_noscroll)
+        {
+            if (only_resize)
+                gdk_window_resize( widget->window, allocation->width, allocation->height );
+            else
+                gdk_window_move_resize( widget->window, allocation->x, allocation->y, 
+                                                        allocation->width, allocation->height );
+
+            gdk_window_move_resize( pizza->bin_window, border, border, w, h );
+        }
+        else
+        {
+            if (only_resize)
+                gdk_window_resize( widget->window, w, h );
+            else
+                gdk_window_move_resize( widget->window, x, y, w, h );
+
+            gdk_window_resize( pizza->bin_window, w, h );
+        }
     }
 
     children = pizza->children;
@@ -619,26 +607,6 @@ gtk_pizza_size_allocate (GtkWidget     *widget,
     }
 }
 
-static gint
-gtk_pizza_expose (GtkWidget      *widget,
-                  GdkEventExpose *event)
-{
-    GtkPizza *pizza;
-
-    g_return_val_if_fail (widget != NULL, FALSE);
-    g_return_val_if_fail (GTK_IS_PIZZA (widget), FALSE);
-    g_return_val_if_fail (event != NULL, FALSE);
-
-    pizza = (GtkPizza*)widget;
-
-    if (event->window != pizza->bin_window)
-        return FALSE;
-
-    pizza_parent_class->expose_event(widget, event);
-
-    return FALSE;
-}
-
 static void
 gtk_pizza_style_set(GtkWidget *widget, GtkStyle  *previous_style)
 {
@@ -741,66 +709,37 @@ gtk_pizza_allocate_child (GtkPizza      *pizza,
     allocation.width = requisition.width;
     allocation.height = requisition.height;
 
-    gtk_widget_size_allocate (child->widget, &allocation);
-}
-
-static void
-gtk_pizza_adjust_allocations_recurse (GtkWidget *widget,
-                                       gpointer   cb_data)
-{
-    GtkPizzaAdjData *data = cb_data;
-
-    widget->allocation.x += data->dx;
-    widget->allocation.y += data->dy;
-
-    if (GTK_WIDGET_NO_WINDOW (widget) && GTK_IS_CONTAINER (widget))
+    if (gtk_widget_get_direction( GTK_WIDGET(pizza) ) == GTK_TEXT_DIR_RTL)
     {
-        gtk_container_forall (GTK_CONTAINER (widget),
-                          gtk_pizza_adjust_allocations_recurse,
-                          cb_data);
-    }
-}
+        /* reverse horizontal placement */
+        gint offset,border;
 
-static void
-gtk_pizza_adjust_allocations (GtkPizza *pizza,
-                               gint       dx,
-                               gint       dy)
-{
-    GList *tmp_list;
-    GtkPizzaAdjData data;
-
-    data.dx = dx;
-    data.dy = dy;
-
-    tmp_list = pizza->children;
-    while (tmp_list)
-    {
-        GtkPizzaChild *child = tmp_list->data;
-        tmp_list = tmp_list->next;
+        offset = GTK_WIDGET(pizza)->allocation.width;
+        border = pizza->container.border_width;
+        offset -= border*2;
 
-        child->widget->allocation.x += dx;
-        child->widget->allocation.y += dy;
-
-        if (GTK_WIDGET_NO_WINDOW (child->widget) &&
-            GTK_IS_CONTAINER (child->widget))
-        {
-            gtk_container_forall (GTK_CONTAINER (child->widget),
-                                  gtk_pizza_adjust_allocations_recurse,
-                                  &data);
-        }
+        allocation.x = offset - child->x - allocation.width + pizza->m_xoffset;
     }
+
+    gtk_widget_size_allocate (child->widget, &allocation);
 }
 
 void
 gtk_pizza_scroll (GtkPizza *pizza, gint dx, gint dy)
 {
+    GList *tmp_list;
+    
     pizza->m_xoffset += dx;
     pizza->m_yoffset += dy;
 
-    gtk_pizza_adjust_allocations (pizza, -dx, -dy);
-
     if (pizza->bin_window)
         gdk_window_scroll( pizza->bin_window, -dx, -dy );
+
+    for (tmp_list = pizza->children; tmp_list; tmp_list = tmp_list->next)
+    {
+        GtkPizzaChild *child = tmp_list->data;
+        gtk_widget_queue_resize(child->widget);
+    }
 }
 
 #ifdef __cplusplus