[Tomoe-cvs 902] CVS update: libtomoe-gtk/src

Back to archive index

Hiroyuki Ikezoe ikezo****@users*****
2006年 11月 23日 (木) 10:09:55 JST


Index: libtomoe-gtk/src/tomoe-canvas.c
diff -u libtomoe-gtk/src/tomoe-canvas.c:1.18 libtomoe-gtk/src/tomoe-canvas.c:1.19
--- libtomoe-gtk/src/tomoe-canvas.c:1.18	Wed Nov 22 21:05:29 2006
+++ libtomoe-gtk/src/tomoe-canvas.c	Thu Nov 23 10:09:55 2006
@@ -43,6 +43,8 @@
 struct _TomoeCanvasPriv
 {
     guint            size;
+    gint             width;
+    gint             height;
     GdkGC           *handwrite_line_gc;
     GdkGC           *adjust_line_gc;
     GdkGC           *annotate_gc;
@@ -63,8 +65,9 @@
 static void   tomoe_canvas_class_init           (TomoeCanvasClass  *klass);
 static void   tomoe_canvas_init                 (TomoeCanvas       *object);
 static void   tomoe_canvas_dispose              (GObject           *object);
-static gint   tomoe_canvas_configure_event      (GtkWidget         *widget,
-                                                 GdkEventConfigure *event);
+static void   tomoe_canvas_realize              (GtkWidget         *widget);
+static void   tomoe_canvas_size_allocate        (GtkWidget         *widget,
+					         GtkAllocation     *allocation);
 static gint   tomoe_canvas_expose_event         (GtkWidget         *widget,
                                                  GdkEventExpose    *event);
 static gint   tomoe_canvas_button_press_event   (GtkWidget         *widget,
@@ -118,9 +121,6 @@
                                                  guint              inde,
                                                  GdkColor          *color);
 #endif
-static void   on_size_allocate                  (GtkWidget         *widget,
-                                                 GtkAllocation     *allocation,
-                                                 gpointer           user_data);
 
 static GList*               instance_list = NULL;
 static guint                canvas_signals[LAST_SIGNAL] = { 0 };
@@ -179,7 +179,8 @@
   		  G_TYPE_NONE, 0);
 
     gobject_class->dispose             = tomoe_canvas_dispose;
-    widget_class->configure_event      = tomoe_canvas_configure_event;
+    widget_class->realize              = tomoe_canvas_realize;
+    widget_class->size_allocate        = tomoe_canvas_size_allocate;
     widget_class->expose_event         = tomoe_canvas_expose_event;
     widget_class->button_press_event   = tomoe_canvas_button_press_event;
     widget_class->button_release_event = tomoe_canvas_button_release_event;
@@ -197,26 +198,8 @@
 static void
 tomoe_canvas_init (TomoeCanvas *canvas)
 {
-    GtkWidget *widget = GTK_WIDGET (canvas);
     TomoeCanvasPriv *priv = TOMOE_CANVAS_GET_PRIVATE (canvas);
-    PangoFontDescription *font_desc;
-    gint width, height;
-
-    gtk_widget_set_events (widget,
-                           GDK_EXPOSURE_MASK |
-                           GDK_LEAVE_NOTIFY_MASK |
-                           GDK_BUTTON_PRESS_MASK |
-                           GDK_BUTTON_RELEASE_MASK |
-                           GDK_POINTER_MOTION_MASK |
-                           GDK_POINTER_MOTION_HINT_MASK);
-
-    font_desc = pango_font_description_from_string ("Sans 12");
-    gtk_widget_modify_font (widget, font_desc);
-
-    g_signal_connect (G_OBJECT (widget), "size-allocate",
-                      G_CALLBACK (on_size_allocate),
-                      (gpointer) NULL);
-
+    
     priv->size              = TOMOE_CANVAS_DEFAULT_SIZE;
     priv->handwrite_line_gc = NULL;
     priv->adjust_line_gc    = NULL;
@@ -229,15 +212,6 @@
     priv->writing           = tomoe_writing_new ();
     priv->locked            = FALSE;
 
-    gtk_widget_get_size_request (GTK_WIDGET (canvas), &width, &height);
-    if (width == -1)
-        priv->size = TOMOE_CANVAS_DEFAULT_SIZE;
-    else
-        priv->size = width;
-/*    tomoe_canvas_set_size (canvas, 300);*/
-
-    gtk_widget_set_size_request (GTK_WIDGET (canvas), priv->size, priv->size);
-
     instance_list = g_list_append (instance_list, (gpointer) canvas);
 }
 
@@ -300,28 +274,66 @@
                                     NULL));
 }
 
-static gint
-tomoe_canvas_configure_event (GtkWidget *widget, GdkEventConfigure *event)
+static void
+tomoe_canvas_realize (GtkWidget *widget)
 {
-    TomoeCanvas *canvas = TOMOE_CANVAS (widget);
-    TomoeCanvasPriv *priv = TOMOE_CANVAS_GET_PRIVATE (canvas);
-    gboolean retval = FALSE;
+    PangoFontDescription *font_desc;
+    GdkWindowAttr attributes;
 
-    if (GTK_WIDGET_CLASS(tomoe_canvas_parent_class)->configure_event)
-        retval = GTK_WIDGET_CLASS(tomoe_canvas_parent_class)->configure_event (widget,
-                                                                               event);
-
-    if (priv->pixmap)
-        g_object_unref(priv->pixmap);
-
-    priv->pixmap = gdk_pixmap_new(widget->window,
-                                  widget->allocation.width,
-                                  widget->allocation.height,
-                                  -1);
+    GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
 
-    tomoe_canvas_real_clear (TOMOE_CANVAS (canvas));
+    attributes.window_type = GDK_WINDOW_CHILD;
+    attributes.wclass = GDK_INPUT_OUTPUT;
+    attributes.visual = gtk_widget_get_visual (widget);
+    attributes.colormap = gtk_widget_get_colormap (widget);
+
+    attributes.x = widget->allocation.x;
+    attributes.y = widget->allocation.y;
+    attributes.width = widget->allocation.width;
+    attributes.height = widget->allocation.height;
+    attributes.event_mask = GDK_EXPOSURE_MASK |
+	    GDK_BUTTON_PRESS_MASK |
+	    GDK_BUTTON_RELEASE_MASK |
+	    GDK_POINTER_MOTION_MASK |
+	    GDK_POINTER_MOTION_HINT_MASK |
+	    GDK_ENTER_NOTIFY_MASK |
+	    GDK_LEAVE_NOTIFY_MASK;
+
+    widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
+		    &attributes,
+		    GDK_WA_X | GDK_WA_Y |
+		    GDK_WA_COLORMAP |
+		    GDK_WA_VISUAL);
+    gdk_window_set_user_data (widget->window, widget);
+    widget->style = gtk_style_attach (widget->style, widget->window);
 
-    return retval;
+    gdk_window_set_background (widget->window, &widget->style->bg [GTK_STATE_NORMAL]);
+
+    font_desc = pango_font_description_from_string ("Sans 12");
+    gtk_widget_modify_font (widget, font_desc);
+}
+
+static void
+tomoe_canvas_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
+{
+    TomoeCanvasPriv *priv = TOMOE_CANVAS_GET_PRIVATE (widget);
+
+    priv->width = allocation->width;
+    priv->height = allocation->height;
+    priv->size = allocation->width;
+
+    if (GTK_WIDGET_REALIZED (widget)) {
+        if (priv->pixmap)
+            g_object_unref(priv->pixmap);
+
+        priv->pixmap = gdk_pixmap_new(widget->window,
+                                      allocation->width,
+                                      allocation->height,
+                                      -1);
+    	tomoe_canvas_refresh (TOMOE_CANVAS (widget));
+    }
+    if (GTK_WIDGET_CLASS (tomoe_canvas_parent_class)->size_allocate)
+        GTK_WIDGET_CLASS (tomoe_canvas_parent_class)->size_allocate (widget, allocation);
 }
 
 static gint
@@ -380,7 +392,7 @@
     TomoeCanvas *canvas = TOMOE_CANVAS (widget);
     TomoeCanvasPriv *priv = TOMOE_CANVAS_GET_PRIVATE (canvas);
     gboolean retval = FALSE;
-    //GdkColor color = { 0, 0x8000, 0x0000, 0x0000};
+    GdkColor color = { 0, 0x8000, 0x0000, 0x0000};
 
     if (priv->locked) return retval;
 
@@ -390,6 +402,7 @@
     tomoe_writing_line_to (priv->writing);
     draw_annotate (canvas, tomoe_writing_get_number_of_strokes (priv->writing) + 1, &color);
 #endif
+
     g_signal_emit (G_OBJECT (widget), canvas_signals[STROKE_ADDED_SIGNAL], 0);
 
     if (priv->auto_find_id) {
@@ -550,15 +563,15 @@
 tomoe_canvas_get_writing (TomoeCanvas *canvas)
 {
     TomoeCanvasPriv *priv;
-    TomoeWriting *g;
+    TomoeWriting *writing;
 
     g_return_val_if_fail (TOMOE_IS_CANVAS (canvas), NULL);
 
     priv = TOMOE_CANVAS_GET_PRIVATE (canvas);
 
-    g = create_sparse_writing (canvas);
+    writing = create_sparse_writing (canvas);
 
-    return g;
+    return writing;
 }
 
 void
@@ -574,7 +587,7 @@
         g_object_unref (priv->writing);
     priv->writing = writing;
 
-    if (priv->writing)
+    if (GTK_WIDGET_REALIZED (GTK_WIDGET (canvas)))
     	tomoe_canvas_refresh (canvas);
 }
 
@@ -585,15 +598,6 @@
     priv->locked = lock;
 }
 
-typedef struct _CharSize CharSize;
-struct _CharSize
-{
-    gint x0;
-    gint y0;
-    gint x1;
-    gint y1;
-};
-
 static void
 get_rectangle_for_stroke (GList *points, GdkRectangle *rect)
 {
@@ -858,7 +862,13 @@
     g_return_if_fail (TOMOE_IS_CANVAS (canvas));
 
     priv = TOMOE_CANVAS_GET_PRIVATE (canvas);
-    priv->size = size;
+    priv->width = size;
+    priv->height = size;
+
+    gtk_widget_set_size_request (GTK_WIDGET (canvas), size, size);
+    gtk_widget_queue_resize (GTK_WIDGET (canvas));
+    if (GTK_WIDGET_REALIZED (GTK_WIDGET (canvas)))
+        tomoe_canvas_refresh (canvas);
 }
 
 static void
@@ -956,6 +966,7 @@
     priv->context = context;
 }
 
+#if 0
 static void
 tomoe_canvas_append_point (TomoeCanvas *canvas, gint x, gint y)
 {
@@ -968,6 +979,7 @@
     _init_gc (canvas);
     /* tomoe_canvas_draw_line (canvas, pp, p, &color); */
 }
+#endif
 
 static void
 tomoe_canvas_draw_line (TomoeCanvas *canvas,
@@ -1286,15 +1298,6 @@
     g_object_unref (layout);
 }
 #endif
-static void
-on_size_allocate (GtkWidget *widget, GtkAllocation *allocation, gpointer user_data)
-{
-    TomoeCanvasPriv *priv = TOMOE_CANVAS_GET_PRIVATE (TOMOE_CANVAS (widget));
-    priv->size = allocation->width;
-
-    if (widget->window)
-        tomoe_canvas_refresh (TOMOE_CANVAS (widget));
-}
 /*
  * vi:ts=4:nowrap:ai:expandtab
  */
Index: libtomoe-gtk/src/tomoe-details.c
diff -u libtomoe-gtk/src/tomoe-details.c:1.17 libtomoe-gtk/src/tomoe-details.c:1.18
--- libtomoe-gtk/src/tomoe-details.c:1.17	Wed Nov 22 21:05:29 2006
+++ libtomoe-gtk/src/tomoe-details.c	Thu Nov 23 10:09:55 2006
@@ -134,22 +134,18 @@
 
     GObject *object;
     GObjectClass *klass = G_OBJECT_CLASS (tomoe_details_parent_class);
-
-    object = klass->constructor (type, n_props, props);
-
-    return object;
-}
-
-static void
-tomoe_details_init (TomoeDetails *window)
-{
     GtkWidget *hbox, *main_vbox, *vbox, *alignment, *button;
     GtkWidget *label, *canvas, *meta, *frame, *tree_view;
     GtkListStore *list_store;
     GtkTreeViewColumn *column;
     GtkTreeIter iter;
+    TomoeDetails *window;
     GtkCellRenderer *renderer;
-    TomoeDetailsPrivate *priv = TOMOE_DETAILS_GET_PRIVATE (window);
+
+    object = klass->constructor (type, n_props, props);
+
+    window = TOMOE_DETAILS (object);
+    TomoeDetailsPrivate *priv = TOMOE_DETAILS_GET_PRIVATE (object);
 
     gtk_window_set_title (GTK_WINDOW (window),
                           _("Character Details"));
@@ -222,9 +218,9 @@
 
     canvas = tomoe_canvas_new ();
     priv->canvas = canvas;
-    gtk_widget_set_size_request (canvas, 100, 100);
     tomoe_canvas_lock (TOMOE_CANVAS (canvas), TRUE);
     gtk_container_add (GTK_CONTAINER (frame), canvas);
+    gtk_widget_set_size_request (canvas, 100, 100);
     /*
     g_signal_connect (G_OBJECT (canvas), "stroke-added",
                       G_CALLBACK (on_canvas_stroke_added), (gpointer) page);
@@ -319,6 +315,16 @@
                                                        NULL);
     gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
 #endif
+
+    _show_details (TOMOE_DETAILS (object));
+    _update_sensitive (TOMOE_DETAILS (object));
+
+    return object;
+}
+
+static void
+tomoe_details_init (TomoeDetails *window)
+{
 }
 
 static void
@@ -389,8 +395,6 @@
                                             "tomoe-char", chr,
                                             "tomoe-dict", dict,
                                             NULL));
-    _show_details (TOMOE_DETAILS (w));
-    _update_sensitive (TOMOE_DETAILS (w));
     return w;
 }
 
@@ -489,11 +493,8 @@
 
     result = gtk_dialog_run (GTK_DIALOG (wnd));
     gtk_widget_destroy (wnd);
-#warning FIXME!
-#if 0
     if (result)
-#endif
-    _show_details (dialog);
+        _show_details (dialog);
 }
 
 static void
Index: libtomoe-gtk/src/tomoe-stroke-search.c
diff -u libtomoe-gtk/src/tomoe-stroke-search.c:1.7 libtomoe-gtk/src/tomoe-stroke-search.c:1.8
--- libtomoe-gtk/src/tomoe-stroke-search.c:1.7	Wed Nov 22 20:28:35 2006
+++ libtomoe-gtk/src/tomoe-stroke-search.c	Thu Nov 23 10:09:55 2006
@@ -106,6 +106,7 @@
 
     canvas = tomoe_canvas_new ();
     priv->canvas = canvas;
+    gtk_widget_set_size_request (canvas, 300, 300);
     gtk_container_add (GTK_CONTAINER (frame), canvas);
     g_signal_connect (G_OBJECT (canvas), "stroke-added",
                       G_CALLBACK (on_canvas_stroke_added),


tomoe-cvs メーリングリストの案内
Back to archive index