]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/window.cpp
fix missing mouse-up events (eg when track control was called, which is consuming...
[wxWidgets.git] / src / gtk / window.cpp
index 66d9e909d48f252336fde90f62091dd8d8c8adb8..cd98009b09baaeaaed996112553255f903309317 100644 (file)
@@ -1097,6 +1097,17 @@ static gint gtk_window_key_press_callback( GtkWidget *widget,
     if (g_blockEventsOnDrag)
         return FALSE;
 
+#ifdef __WXGTK20__
+    if (win->m_imContext)
+    {
+        // In GTK 2.0, we need to hand over the key event to an input method
+        // and the IM will emit a "commit" event containing the actual utf8
+        // character.  In that case the EVT_CHAR events will be sent from
+        // there.
+        if ( gtk_im_context_filter_keypress(win->m_imContext, gdk_event) )
+            return TRUE;
+    }
+#endif
 
     wxKeyEvent event( wxEVT_KEY_DOWN );
     if ( !wxTranslateGTKKeyEventToWx(event, win, gdk_event) )
@@ -1134,56 +1145,41 @@ static gint gtk_window_key_press_callback( GtkWidget *widget,
     {
         long key_code;
         KeySym keysym = gdk_event->keyval;
-#ifdef __WXGTK20__
-        // In GTK 2.0, we need to hand over the key event to an input method
-        // and the IM will emit a "commit" event containing the actual utf8
-        // character.  In that case the EVT_CHAR events will be sent from
-        // there.  But only do it this way for non-KeySym keys.
-        key_code = wxTranslateKeySymToWXKey(gdk_event->keyval, FALSE /* isChar */);
-        if ( !key_code && win->m_imContext )
+        // Find key code for EVT_CHAR and EVT_CHAR_HOOK events
+        key_code = wxTranslateKeySymToWXKey(keysym, TRUE /* isChar */);
+        if ( !key_code )
         {
-            gtk_im_context_filter_keypress ( (GtkIMContext*) win->m_imContext, gdk_event );
-            ret = TRUE;
-        }
-        else
-#endif
-        {
-            // Find key code for EVT_CHAR and EVT_CHAR_HOOK events
-            key_code = wxTranslateKeySymToWXKey(keysym, TRUE /* isChar */);
-            if ( !key_code )
+            if ( gdk_event->length == 1 )
             {
-                if ( gdk_event->length == 1 )
-                {
-                    key_code = (unsigned char)gdk_event->string[0];
-                }
-                else if ( wxIsAsciiKeysym(keysym) )
-                {
-                    // ASCII key
-                    key_code = (unsigned char)keysym;
-                }
+                key_code = (unsigned char)gdk_event->string[0];
             }
-
-            if ( key_code )
+            else if ( wxIsAsciiKeysym(keysym) )
             {
-                wxLogTrace(TRACE_KEYS, _T("Char event: %ld"), key_code);
+                // ASCII key
+                key_code = (unsigned char)keysym;
+            }
+        }
 
-                event.m_keyCode = key_code;
+        if ( key_code )
+        {
+            wxLogTrace(TRACE_KEYS, _T("Char event: %ld"), key_code);
 
-                // Implement OnCharHook by checking ancesteror top level windows
-                wxWindow *parent = win;
-                while (parent && !parent->IsTopLevel())
-                    parent = parent->GetParent();
-                if (parent)
-                {
-                    event.SetEventType( wxEVT_CHAR_HOOK );
-                    ret = parent->GetEventHandler()->ProcessEvent( event );
-                }
+            event.m_keyCode = key_code;
 
-                if (!ret)
-                {
-                    event.SetEventType(wxEVT_CHAR);
-                    ret = win->GetEventHandler()->ProcessEvent( event );
-                }
+            // Implement OnCharHook by checking ancesteror top level windows
+            wxWindow *parent = win;
+            while (parent && !parent->IsTopLevel())
+                parent = parent->GetParent();
+            if (parent)
+            {
+                event.SetEventType( wxEVT_CHAR_HOOK );
+                ret = parent->GetEventHandler()->ProcessEvent( event );
+            }
+
+            if (!ret)
+            {
+                event.SetEventType(wxEVT_CHAR);
+                ret = win->GetEventHandler()->ProcessEvent( event );
             }
         }
     }
@@ -1274,11 +1270,15 @@ static void gtk_wxwindow_commit_cb (GtkIMContext *context,
     if (event.m_uniChar < 256)
         event.m_keyCode = event.m_uniChar;
 #else
-    gunichar uniChar = g_utf8_get_char( str );
-    // We cannot handle Unicode in non-Unicode mode
-    if (uniChar > 255) return;
-
-    event.m_keyCode = uniChar;
+    wchar_t unistr[2];
+    unistr[0] = g_utf8_get_char(str);
+    unistr[1] = 0;
+    wxCharBuffer ansistr(wxConvLocal.cWC2MB(unistr));
+    // We cannot handle characters that cannot be represented in 
+    // current locale's charset in non-Unicode mode:
+    if (ansistr.data() == NULL) return;
+
+    event.m_keyCode = ansistr[0u];
 #endif
 
 
@@ -1534,8 +1534,8 @@ static gint gtk_window_button_press_callback( GtkWidget *widget,
 
     wxEventType event_type = wxEVT_NULL;
 
-    // GdkDisplay is a GTK+ 2.1.0 thing
-#if defined(__WXGTK20__) && GTK_CHECK_VERSION(2, 1, 0)
+    // GdkDisplay is a GTK+ 2.2.0 thing
+#if defined(__WXGTK20__) && GTK_CHECK_VERSION(2, 2, 0)
     if ( gdk_event->type == GDK_2BUTTON_PRESS &&
             gdk_event->button >= 1 && gdk_event->button <= 3 )
     {
@@ -1900,6 +1900,11 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget,
     if (g_isIdle)
         wxapp_install_idle_handler();
 
+#ifdef __WXGTK20__
+    if (win->m_imContext)
+        gtk_im_context_focus_in(win->m_imContext);
+#endif
+
     if (!win->m_hasVMT) return FALSE;
     if (g_blockEventsOnDrag) return FALSE;
 
@@ -1988,6 +1993,11 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEventFocus *gdk
     if (g_isIdle)
         wxapp_install_idle_handler();
 
+#ifdef __WXGTK20__
+    if (win->m_imContext)
+        gtk_im_context_focus_out(win->m_imContext);
+#endif
+
     if (!win->m_hasVMT) return FALSE;
     if (g_blockEventsOnDrag) return FALSE;
 
@@ -2311,7 +2321,7 @@ gtk_window_realized_callback( GtkWidget *m_widget, wxWindow *win )
     if (win->m_imContext)
     {
         GtkPizza *pizza = GTK_PIZZA( m_widget );
-        gtk_im_context_set_client_window( (GtkIMContext*) win->m_imContext, pizza->bin_window );
+        gtk_im_context_set_client_window( win->m_imContext, pizza->bin_window );
     }
 #endif
 
@@ -2695,17 +2705,6 @@ bool wxWindowGTK::Create( wxWindow *parent,
     gtk_signal_connect( GTK_OBJECT(m_vAdjust), "value_changed",
           (GtkSignalFunc) gtk_window_vscroll_callback, (gpointer) this );
 
-#ifdef __WXGTK20__
-    // Create input method handler
-    m_imContext = (GtkIMMulticontext*) gtk_im_multicontext_new ();
-
-    // Cannot handle drawing preedited text yet
-    gtk_im_context_set_use_preedit( (GtkIMContext*) m_imContext, FALSE );
-
-    g_signal_connect (G_OBJECT (m_imContext), "commit",
-        G_CALLBACK (gtk_wxwindow_commit_cb), this);
-#endif
-
     gtk_widget_show( m_wxwindow );
 
     if (m_parent)
@@ -2801,18 +2800,18 @@ void wxWindowGTK::PostCreation()
 #else
             // gtk_widget_set_redraw_on_allocate( GTK_WIDGET(m_wxwindow), !HasFlag( wxFULL_REPAINT_ON_RESIZE ) );
 #endif
+        }
 
 #ifdef __WXGTK20__
         // Create input method handler
-        m_imContext = (GtkIMMulticontext*) gtk_im_multicontext_new ();
+        m_imContext = gtk_im_multicontext_new();
 
         // Cannot handle drawing preedited text yet
-        gtk_im_context_set_use_preedit( (GtkIMContext*) m_imContext, FALSE );
+        gtk_im_context_set_use_preedit( m_imContext, FALSE );
 
         g_signal_connect (G_OBJECT (m_imContext), "commit",
-            G_CALLBACK (gtk_wxwindow_commit_cb), this);
+                          G_CALLBACK (gtk_wxwindow_commit_cb), this);
 #endif
-        }
 
         // these are called when the "sunken" or "raised" borders are drawn
         gtk_signal_connect( GTK_OBJECT(m_widget), "expose_event",