[gcalctool/gcalctool-newui2: 1/3] Handle '^' better



commit c0bc4390646d708bc783da9fd21fa1b739772dd5
Author: Robert Ancell <robert ancell gmail com>
Date:   Fri Sep 18 11:05:36 2009 +1000

    Handle '^' better

 src/gtk.c |   26 ++++++++++++++++++++++++--
 1 files changed, 24 insertions(+), 2 deletions(-)
---
diff --git a/src/gtk.c b/src/gtk.c
index 120bb16..ec0d457 100644
--- a/src/gtk.c
+++ b/src/gtk.c
@@ -175,7 +175,10 @@ typedef struct {
     
     GdkAtom clipboard_atom;
     GdkAtom primary_atom;  
-    char *shelf;                       /* PUT selection shelf contents. */   
+    char *shelf;                       /* PUT selection shelf contents. */
+    
+    /* Last text entered */
+    char *last_text;
 } GtkUI;
 static GtkUI X;
 
@@ -366,7 +369,20 @@ do_button(int function, int arg)
         cursor_end = cursor_start;
     }
 
-    do_expression(function, arg, cursor_start, cursor_end);
+    /* Some keyboards don't have a '^' button so convert two multiplies to one '^' */
+    if (cursor_start == cursor_end &&
+        function == FN_TEXT && X.last_text != NULL &&
+        strcmp((char *)arg, "Ã?") == 0 && strcmp(X.last_text, "Ã?") == 0) {
+        do_button(FN_BACKSPACE, 0);
+        do_button(FN_TEXT, (int)"^"); // FIXME: Not 64 bit safe
+    }
+    else {
+        do_expression(function, arg, cursor_start, cursor_end);
+        if (function == FN_TEXT)
+            X.last_text = (char *)arg;
+        else
+            X.last_text = NULL;
+    }
 }
 
 
@@ -1092,6 +1108,12 @@ main_window_key_press_cb(GtkWidget *widget, GdkEventKey *event)
         do_text(v->radix);
         return TRUE;
     }
+    
+    /* Some keyboards use this keyval for '^' (e.g. German) */
+    if (event->keyval == GDK_dead_circumflex) {
+        do_text("^");
+        return TRUE;
+    }
 
     switch(*event->string)
     {



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