changeset 2860:2e081c64a529

transform UiSkinnedTextbox into windowless widget
author Tomasz Mon <desowin@gmail.com>
date Sun, 03 Aug 2008 15:28:02 +0200
parents 312ba23cbb87
children 1439cc16d954
files src/skins/ui_skinned_button.c src/skins/ui_skinned_textbox.c src/skins/ui_skinned_textbox.h
diffstat 3 files changed, 62 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/skins/ui_skinned_button.c	Sun Aug 03 14:11:02 2008 +0200
+++ b/src/skins/ui_skinned_button.c	Sun Aug 03 15:28:02 2008 +0200
@@ -188,7 +188,8 @@
     attributes.y = widget->allocation.y;
     attributes.width = widget->allocation.width;
     attributes.height = widget->allocation.height;
-    attributes.window_type = GDK_INPUT_ONLY;
+    attributes.wclass = GDK_INPUT_ONLY;
+    attributes.window_type = GDK_WINDOW_CHILD;
     attributes.event_mask = gtk_widget_get_events(widget);
     attributes.event_mask |= GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK;
 
--- a/src/skins/ui_skinned_textbox.c	Sun Aug 03 14:11:02 2008 +0200
+++ b/src/skins/ui_skinned_textbox.c	Sun Aug 03 15:28:02 2008 +0200
@@ -69,6 +69,9 @@
 static void ui_skinned_textbox_init               (UiSkinnedTextbox *textbox);
 static void ui_skinned_textbox_destroy            (GtkObject *object);
 static void ui_skinned_textbox_realize            (GtkWidget *widget);
+static void ui_skinned_textbox_unrealize          (GtkWidget *widget);
+static void ui_skinned_textbox_map                (GtkWidget *widget);
+static void ui_skinned_textbox_unmap              (GtkWidget *widget);
 static void ui_skinned_textbox_size_request       (GtkWidget *widget, GtkRequisition *requisition);
 static void ui_skinned_textbox_size_allocate      (GtkWidget *widget, GtkAllocation *allocation);
 static gboolean ui_skinned_textbox_expose         (GtkWidget *widget, GdkEventExpose *event);
@@ -118,6 +121,9 @@
     object_class->destroy = ui_skinned_textbox_destroy;
 
     widget_class->realize = ui_skinned_textbox_realize;
+    widget_class->unrealize = ui_skinned_textbox_unrealize;
+    widget_class->map = ui_skinned_textbox_map;
+    widget_class->unmap = ui_skinned_textbox_unmap;
     widget_class->expose_event = ui_skinned_textbox_expose;
     widget_class->size_request = ui_skinned_textbox_size_request;
     widget_class->size_allocate = ui_skinned_textbox_size_allocate;
@@ -157,6 +163,9 @@
     UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox);
     priv->move_x = 0;
     priv->move_y = 0;
+
+    textbox->event_window = NULL;
+    GTK_WIDGET_SET_FLAGS (textbox, GTK_NO_WINDOW);
 }
 
 GtkWidget* ui_skinned_textbox_new(GtkWidget *fixed, gint x, gint y, gint w, gboolean allow_scroll, SkinPixmapId si) {
@@ -210,28 +219,64 @@
     g_return_if_fail (widget != NULL);
     g_return_if_fail (UI_SKINNED_IS_TEXTBOX(widget));
 
-    GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
+    if (GTK_WIDGET_CLASS (parent_class)->realize)
+        (* GTK_WIDGET_CLASS (parent_class)->realize) (widget);
+
     textbox = UI_SKINNED_TEXTBOX(widget);
 
     attributes.x = widget->allocation.x;
     attributes.y = widget->allocation.y;
     attributes.width = widget->allocation.width;
     attributes.height = widget->allocation.height;
-    attributes.wclass = GDK_INPUT_OUTPUT;
+    attributes.wclass = GDK_INPUT_ONLY;
     attributes.window_type = GDK_WINDOW_CHILD;
     attributes.event_mask = gtk_widget_get_events(widget);
-    attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | 
+    attributes.event_mask |= GDK_BUTTON_PRESS_MASK |
                              GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK |
                              GDK_POINTER_MOTION_HINT_MASK;
-    attributes.visual = gtk_widget_get_visual(widget);
-    attributes.colormap = gtk_widget_get_colormap(widget);
 
-    attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
-    widget->window = gdk_window_new(widget->parent->window, &attributes, attributes_mask);
+    attributes_mask = GDK_WA_X | GDK_WA_Y;
+    textbox->event_window = gdk_window_new (widget->window, &attributes, attributes_mask);
 
     widget->style = gtk_style_attach(widget->style, widget->window);
 
-    gdk_window_set_user_data(widget->window, widget);
+    gdk_window_set_user_data(textbox->event_window, widget);
+}
+
+static void ui_skinned_textbox_unrealize(GtkWidget *widget) {
+    UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX(widget);
+
+    if ( textbox->event_window != NULL )
+    {
+      gdk_window_set_user_data( textbox->event_window , NULL );
+      gdk_window_destroy( textbox->event_window );
+      textbox->event_window = NULL;
+    }
+
+    if (GTK_WIDGET_CLASS (parent_class)->unrealize)
+        (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
+}
+
+static void ui_skinned_textbox_map (GtkWidget *widget)
+{
+    UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX (widget);
+
+    if (textbox->event_window != NULL)
+      gdk_window_show (textbox->event_window);
+
+    if (GTK_WIDGET_CLASS (parent_class)->map)
+      (* GTK_WIDGET_CLASS (parent_class)->map) (widget);
+}
+
+static void ui_skinned_textbox_unmap (GtkWidget *widget)
+{
+    UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX (widget);
+
+    if (textbox->event_window != NULL)
+      gdk_window_hide (textbox->event_window);
+
+    if (GTK_WIDGET_CLASS (parent_class)->unmap)
+      (* GTK_WIDGET_CLASS (parent_class)->unmap) (widget);
 }
 
 static void ui_skinned_textbox_size_request(GtkWidget *widget, GtkRequisition *requisition) {
@@ -250,7 +295,8 @@
     widget->allocation.x *= (priv->scaled ? config.scale_factor : 1);
     widget->allocation.y *= (priv->scaled ? config.scale_factor : 1);
     if (GTK_WIDGET_REALIZED (widget))
-        gdk_window_move_resize(widget->window, widget->allocation.x, widget->allocation.y, allocation->width, allocation->height);
+        if (textbox->event_window)
+            gdk_window_move_resize(textbox->event_window, widget->allocation.x, widget->allocation.y, allocation->width, allocation->height);
 
     if (textbox->x + priv->move_x - widget->allocation.x/(priv->scaled ? config.scale_factor : 1) <3);
         priv->move_x = 0;
@@ -317,7 +363,10 @@
             }
         }
 
-        ui_skinned_widget_draw(widget, obj, textbox->width, textbox->height, priv->scaled);
+        ui_skinned_widget_draw_with_coordinates(widget, obj, textbox->width, textbox->height,
+                                                widget->allocation.x,
+                                                widget->allocation.y,
+                                                priv->scaled);
 
         g_object_unref(obj);
     }
--- a/src/skins/ui_skinned_textbox.h	Sun Aug 03 14:11:02 2008 +0200
+++ b/src/skins/ui_skinned_textbox.h	Sun Aug 03 15:28:02 2008 +0200
@@ -44,6 +44,7 @@
 struct _UiSkinnedTextbox {
     GtkWidget        widget;
 
+    GdkWindow        *event_window;
     gint             x, y, width, height;
     gchar            *text;
 };