[giv] Fixed text in caliper on Windows and made gtk insensitive to clicks when not in focus.



commit 39891ed7cba9300c55ab06cf4df5d3fc019259e2
Author: Dov Grobgeld <dov grobgeld gmail com>
Date:   Fri Jun 8 16:44:12 2012 +0300

    Fixed text in caliper on Windows and made gtk insensitive to clicks when not in focus.
    
    * The text was broken in the caliper on Windows. Hopefully it is fixed now.
    * When studying users I noticed that some of them were surprised that giv zoom when they clicked in the window to focus it. To solve this I made giv not zoom during 200ms after it received focus.

 src/giv-win.gob                         |    6 ++--
 src/gtkimageviewer/gtk-image-viewer.gob |   40 +++++++++++++++++++++++++++++-
 2 files changed, 41 insertions(+), 5 deletions(-)
---
diff --git a/src/giv-win.gob b/src/giv-win.gob
index 6083d96..984ed2b 100644
--- a/src/giv-win.gob
+++ b/src/giv-win.gob
@@ -3923,8 +3923,8 @@ draw_caliper(GivWin *self,
     if (lasso_context == DOVTK_LASSO_CONTEXT_LABEL)
         return;
 
-#if _WIN32
-    // This is stil broken!
+#if 0 && _WIN32
+    // This is stil broken, but fortunately the "normal" pango backend works.
 
     // As I can't get pango cairo to work under Windows, I use the specific windows
     // backend which fortunately works.
@@ -3963,7 +3963,7 @@ draw_caliper(GivWin *self,
 #else
     // Draw the distance in the middle
 #ifdef _WIN32
-    PangoFontDescription *font_descr = pango_font_description_from_string("TimesNewRoman 15");
+    PangoFontDescription *font_descr = pango_font_description_from_string("Arial 15");
 #else
     PangoFontDescription *font_descr = pango_font_description_from_string("Sans 15");
 #endif
diff --git a/src/gtkimageviewer/gtk-image-viewer.gob b/src/gtkimageviewer/gtk-image-viewer.gob
index 20ff632..b0a8d9a 100644
--- a/src/gtkimageviewer/gtk-image-viewer.gob
+++ b/src/gtkimageviewer/gtk-image-viewer.gob
@@ -90,6 +90,8 @@ static void vadjustment_value_changed (GtkAdjustment *vadjustment,
 static void hadjustment_value_changed (GtkAdjustment *hadjustment,
                                        gpointer       data);
 
+static gboolean turn_off_insensitive(GtkWidget *widget);
+
 %}
 
 
@@ -138,6 +140,8 @@ class Gtk:Image:Viewer from Gtk:Widget
   private gdouble cache_width = -1;
   private gdouble cache_height = -1;
   private gboolean frozen = FALSE;
+  private gboolean is_insensitive = FALSE;
+  private gint timeout_id = 0;
   
   init(self)
   {
@@ -227,6 +231,7 @@ class Gtk:Image:Viewer from Gtk:Widget
       GDK_POINTER_MOTION_MASK |
       GDK_POINTER_MOTION_HINT_MASK | 
       GDK_KEY_PRESS_MASK |
+      GDK_FOCUS_CHANGE_MASK |
       GDK_LEAVE_NOTIFY_MASK |
       GDK_ENTER_NOTIFY_MASK;
     attributes.visual = gtk_widget_get_visual (widget);
@@ -414,7 +419,11 @@ class Gtk:Image:Viewer from Gtk:Widget
   enter_notify_event(GtkWidget *widget,
                      GdkEventCrossing *event)
   {
-    // printf("Enter notify\n");
+    GtkImageViewer *self = GTK_IMAGE_VIEWER(widget);
+    selfp->is_insensitive = TRUE;
+    if (selfp->timeout_id)
+        g_source_remove(selfp->timeout_id);
+    selfp->timeout_id = g_timeout_add(200, (GSourceFunc) turn_off_insensitive, self);
     if (!GTK_WIDGET_HAS_FOCUS (widget))
       gtk_widget_grab_focus (widget);
     
@@ -426,9 +435,13 @@ class Gtk:Image:Viewer from Gtk:Widget
   leave_notify_event(GtkWidget *widget,
                      GdkEventCrossing *event)
   {
+    GtkImageViewer *self = GTK_IMAGE_VIEWER(widget);
     // printf("Leave notify\n");
     if (!GTK_WIDGET_HAS_FOCUS (widget))
       gtk_widget_grab_focus (widget);
+    if (selfp->timeout_id)
+        g_source_remove(selfp->timeout_id);
+    selfp->is_insensitive = TRUE;
     
     return TRUE;
   }
@@ -491,7 +504,10 @@ class Gtk:Image:Viewer from Gtk:Widget
     int button = event->button;
     double x = event->x;
     double y = event->y;
-  
+
+    if (selfp->is_insensitive)
+        return TRUE;
+
     if (button == 1)
         gtk_image_viewer_zoom_in(self, (int)x, (int)y, 2);
     else if (button == 2)
@@ -2256,4 +2272,24 @@ fix_gdk_pixbuf_scale_nn(const GdkPixbuf *src,
     }
     g_free(dest_addr);
 }
+
+static gboolean turn_off_insensitive(GtkWidget *data)
+{
+  GtkImageViewer *self = GTK_IMAGE_VIEWER (data);
+
+  // Recursively get top level window and check if it has focus
+  GtkWidget *w = GTK_WIDGET(data);
+  while(!GTK_IS_WINDOW(w))
+      w = gtk_widget_get_parent(w);
+  
+  if (!gtk_window_has_toplevel_focus(GTK_WINDOW(w)))
+      return TRUE;
+
+  selfp->is_insensitive = FALSE;
+  // Invalidate the timeout id
+  selfp->timeout_id = 0;
+
+  return FALSE;
+}
+
 %}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]