]> git.saurik.com Git - wxWidgets.git/commitdiff
Various changes for simplification of focus event
authorRobert Roebling <robert@roebling.de>
Sun, 19 Aug 2001 21:36:25 +0000 (21:36 +0000)
committerRobert Roebling <robert@roebling.de>
Sun, 19 Aug 2001 21:36:25 +0000 (21:36 +0000)
    code in wxGTK. It will also work for wxComboBox
    now, but not for GTK's other composite controls
    such as wxListBox and wxChoice.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11414 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/gtk/window.h
include/wx/gtk1/window.h
samples/controls/controls.cpp
src/gtk/combobox.cpp
src/gtk/statbmp.cpp
src/gtk/textctrl.cpp
src/gtk/window.cpp
src/gtk1/combobox.cpp
src/gtk1/statbmp.cpp
src/gtk1/textctrl.cpp
src/gtk1/window.cpp

index e648eb9815cd2b1cc7d0e8817f5f4292178c8b6f..cfb1e5af1b190a5314df88a0e6e642666651819a 100644 (file)
@@ -165,36 +165,39 @@ public:
     int                  m_width, m_height;
     int                  m_oldClientWidth,m_oldClientHeight;
 
-    /* see the docs in src/gtk/window.cpp */
-    GtkWidget           *m_widget;
-    GtkWidget           *m_wxwindow;
+    // see the docs in src/gtk/window.cpp
+    GtkWidget           *m_widget;          // mostly the widget seen by the rest of GTK
+    GtkWidget           *m_wxwindow;        // mostly the client area as per wxWindows
+    
+    // this widget will be queried for GTK's focus events
+    GtkWidget           *m_focusWidget;
 
 #if HAVE_XIM
-    /* XIM support for wxWindows */
+    // XIM support for wxWindows
     GdkIC               *m_ic;
     GdkICAttr           *m_icattr;
 #endif
 
-    /* scrolling stuff */
+    // scrolling stuff
     GtkAdjustment       *m_hAdjust,*m_vAdjust;
     float                m_oldHorizontalPos;
     float                m_oldVerticalPos;
 
     // extra (wxGTK-specific) flags
-    bool                 m_needParent:1;        /* ! wxFrame, wxDialog, wxNotebookPage ?  */
-    bool                 m_noExpose:1;          /* wxGLCanvas has its own redrawing */
-    bool                 m_nativeSizeEvent:1;   /* wxGLCanvas sends wxSizeEvent upon "alloc_size" */
+    bool                 m_needParent:1;        // ! wxFrame, wxDialog, wxNotebookPage ?
+    bool                 m_noExpose:1;          // wxGLCanvas has its own redrawing
+    bool                 m_nativeSizeEvent:1;   // wxGLCanvas sends wxSizeEvent upon "alloc_size"
     bool                 m_hasScrolling:1;
     bool                 m_hasVMT:1;
     bool                 m_sizeSet:1;
     bool                 m_resizing:1;
-    bool                 m_isStaticBox:1;    /* faster than IS_KIND_OF */
-    bool                 m_isRadioButton:1;  /* faster than IS_KIND_OF */
-    bool                 m_isFrame:1;        /* faster than IS_KIND_OF */
-    bool                 m_acceptsFocus:1;   /* not wxStaticBox, not wxStaticBitmap etc.  */
+    bool                 m_isStaticBox:1;       // faster than IS_KIND_OF
+    bool                 m_isRadioButton:1;     // faster than IS_KIND_OF
+    bool                 m_isFrame:1;           // faster than IS_KIND_OF
+    bool                 m_acceptsFocus:1;      // not wxStaticBox, not wxStaticBitmap etc.
     bool                 m_isScrolling;
-    bool                 m_clipPaintRegion;  /* TRUE after ScrollWindow() */
-    bool                 m_queuedFullRedraw; /* TRUE after DoMoveWindow */
+    bool                 m_clipPaintRegion;     // TRUE after ScrollWindow()
+    bool                 m_queuedFullRedraw;    // TRUE after DoMoveWindow
 
     // these are true if the style were set before the widget was realized
     // (typcally in the constructor) but the actual GTK style must not be set
index e648eb9815cd2b1cc7d0e8817f5f4292178c8b6f..cfb1e5af1b190a5314df88a0e6e642666651819a 100644 (file)
@@ -165,36 +165,39 @@ public:
     int                  m_width, m_height;
     int                  m_oldClientWidth,m_oldClientHeight;
 
-    /* see the docs in src/gtk/window.cpp */
-    GtkWidget           *m_widget;
-    GtkWidget           *m_wxwindow;
+    // see the docs in src/gtk/window.cpp
+    GtkWidget           *m_widget;          // mostly the widget seen by the rest of GTK
+    GtkWidget           *m_wxwindow;        // mostly the client area as per wxWindows
+    
+    // this widget will be queried for GTK's focus events
+    GtkWidget           *m_focusWidget;
 
 #if HAVE_XIM
-    /* XIM support for wxWindows */
+    // XIM support for wxWindows
     GdkIC               *m_ic;
     GdkICAttr           *m_icattr;
 #endif
 
-    /* scrolling stuff */
+    // scrolling stuff
     GtkAdjustment       *m_hAdjust,*m_vAdjust;
     float                m_oldHorizontalPos;
     float                m_oldVerticalPos;
 
     // extra (wxGTK-specific) flags
-    bool                 m_needParent:1;        /* ! wxFrame, wxDialog, wxNotebookPage ?  */
-    bool                 m_noExpose:1;          /* wxGLCanvas has its own redrawing */
-    bool                 m_nativeSizeEvent:1;   /* wxGLCanvas sends wxSizeEvent upon "alloc_size" */
+    bool                 m_needParent:1;        // ! wxFrame, wxDialog, wxNotebookPage ?
+    bool                 m_noExpose:1;          // wxGLCanvas has its own redrawing
+    bool                 m_nativeSizeEvent:1;   // wxGLCanvas sends wxSizeEvent upon "alloc_size"
     bool                 m_hasScrolling:1;
     bool                 m_hasVMT:1;
     bool                 m_sizeSet:1;
     bool                 m_resizing:1;
-    bool                 m_isStaticBox:1;    /* faster than IS_KIND_OF */
-    bool                 m_isRadioButton:1;  /* faster than IS_KIND_OF */
-    bool                 m_isFrame:1;        /* faster than IS_KIND_OF */
-    bool                 m_acceptsFocus:1;   /* not wxStaticBox, not wxStaticBitmap etc.  */
+    bool                 m_isStaticBox:1;       // faster than IS_KIND_OF
+    bool                 m_isRadioButton:1;     // faster than IS_KIND_OF
+    bool                 m_isFrame:1;           // faster than IS_KIND_OF
+    bool                 m_acceptsFocus:1;      // not wxStaticBox, not wxStaticBitmap etc.
     bool                 m_isScrolling;
-    bool                 m_clipPaintRegion;  /* TRUE after ScrollWindow() */
-    bool                 m_queuedFullRedraw; /* TRUE after DoMoveWindow */
+    bool                 m_clipPaintRegion;     // TRUE after ScrollWindow()
+    bool                 m_queuedFullRedraw;    // TRUE after DoMoveWindow
 
     // these are true if the style were set before the widget was realized
     // (typcally in the constructor) but the actual GTK style must not be set
index 4c23313cd19e14aa2ab7158793f6348e42487b5d..0673cb6bbbb544d673e79af3b12146cfc010f21a 100644 (file)
@@ -787,6 +787,7 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
                                   bmp1,
                                   wxPoint(30, 70)
                                  );
+
     bmpBtn->SetBitmapSelected(bmp2);
     bmpBtn->SetBitmapFocus(bmp3);
 
index 26e78469decc7383c5e9610d9ffca09023ca8002..c138c48a42f01adad90ac78719a5474f177f2bb0 100644 (file)
@@ -154,6 +154,8 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value,
     }
 
     m_parent->DoAddChild( this );
+    
+    m_focusWidget = GTK_COMBO(m_widget)->entry;
 
     PostCreation();
 
index 392fa2fa4c6e39422112d0cd5b4fe7b15b6f1a0b..91b5df62155b3956d524e49638ea3a6b6ba9e729 100644 (file)
@@ -46,11 +46,13 @@ void wxStaticBitmap::CreatePixmapWidget()
         mask = m_bitmap.GetMask()->GetBitmap();
     m_widget = gtk_pixmap_new( m_bitmap.GetPixmap(), mask );
 
-    /* insert GTK representation */
+    // insert GTK representation
     (*m_parent->m_insertCallback)(m_parent, this);
 
     gtk_widget_show( m_widget );
 
+    m_focusWidget = m_widget;
+
     PostCreation();
 }
 
@@ -64,7 +66,7 @@ bool wxStaticBitmap::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi
         !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
     {
         wxFAIL_MSG( wxT("wxXX creation failed") );
-       return FALSE;
+    return FALSE;
     }
 
     m_bitmap = bitmap;
@@ -81,6 +83,8 @@ bool wxStaticBitmap::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi
     else
     {
         m_widget = gtk_label_new( "Bitmap" );
+        
+        m_focusWidget = m_widget;
 
         PostCreation();
     }
index 468f7262a25feef63c6a98a5ae4c32aefacf86f5..35de57809a7bc4356f3516b039bcc9ad03596a7f 100644 (file)
@@ -52,6 +52,9 @@ gtk_insert_text_callback(GtkEditable *editable,
                          gint *position,
                          wxTextCtrl *win)
 {
+    if (g_isIdle)
+        wxapp_install_idle_handler();
+
     // we should only be called if we have a max len limit at all
     GtkEntry *entry = GTK_ENTRY (editable);
 
@@ -117,111 +120,6 @@ gtk_scrollbar_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win )
     win->CalculateScrollbar();
 }
 
-//-----------------------------------------------------------------------------
-// "focus_in_event"
-//-----------------------------------------------------------------------------
-
-extern wxWindow  *g_focusWindow;
-extern bool       g_blockEventsOnDrag;
-// extern bool g_isIdle;
-
-static gint gtk_text_focus_in_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxWindow *win )
-{
-    // Necessary?
-#if 0
-    if (g_isIdle)
-        wxapp_install_idle_handler();
-#endif
-    if (!win->m_hasVMT) return FALSE;
-    if (g_blockEventsOnDrag) return FALSE;
-
-    g_focusWindow = win;
-
-    // notify the parent that we got the focus
-    wxChildFocusEvent eventFocus(win);
-    (void)win->GetEventHandler()->ProcessEvent(eventFocus);
-
-#ifdef HAVE_XIM
-    if (win->m_ic)
-        gdk_im_begin(win->m_ic, win->m_wxwindow->window);
-#endif
-
-#if 0
-#ifdef wxUSE_CARET
-    // caret needs to be informed about focus change
-    wxCaret *caret = win->GetCaret();
-    if ( caret )
-    {
-        caret->OnSetFocus();
-    }
-#endif // wxUSE_CARET
-#endif
-
-    wxFocusEvent event( wxEVT_SET_FOCUS, win->GetId() );
-    event.SetEventObject( win );
-
-    if (win->GetEventHandler()->ProcessEvent( event ))
-    {
-        return TRUE;
-    }
-
-    return FALSE;
-}
-
-//-----------------------------------------------------------------------------
-// "focus_out_event"
-//-----------------------------------------------------------------------------
-
-static gint gtk_text_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxWindow *win )
-{
-#if 0
-    if (g_isIdle)
-        wxapp_install_idle_handler();
-#endif
-
-    if (!win->m_hasVMT) return FALSE;
-    if (g_blockEventsOnDrag) return FALSE;
-
-#if 0
-    // if the focus goes out of our app alltogether, OnIdle() will send
-    // wxActivateEvent, otherwise gtk_window_focus_in_callback() will reset
-    // g_sendActivateEvent to -1
-    g_sendActivateEvent = 0;
-#endif
-
-    wxWindow *winFocus = wxFindFocusedChild(win);
-    if ( winFocus )
-        win = winFocus;
-
-    g_focusWindow = (wxWindow *)NULL;
-
-#ifdef HAVE_XIM
-    if (win->m_ic)
-        gdk_im_end();
-#endif
-
-#if 0
-#ifdef wxUSE_CARET
-    // caret needs to be informed about focus change
-    wxCaret *caret = win->GetCaret();
-    if ( caret )
-    {
-        caret->OnKillFocus();
-    }
-#endif // wxUSE_CARET
-#endif
-
-    wxFocusEvent event( wxEVT_KILL_FOCUS, win->GetId() );
-    event.SetEventObject( win );
-
-    if (win->GetEventHandler()->ProcessEvent( event ))
-    {
-        return TRUE;
-    }
-
-    return FALSE;
-}
-
 //-----------------------------------------------------------------------------
 //  wxTextCtrl
 //-----------------------------------------------------------------------------
@@ -347,6 +245,8 @@ bool wxTextCtrl::Create( wxWindow *parent,
     }
 
     m_parent->DoAddChild( this );
+    
+    m_focusWidget = m_text;
 
     PostCreation();
 
@@ -368,20 +268,6 @@ bool wxTextCtrl::Create( wxWindow *parent,
     {
         gtk_signal_connect(GTK_OBJECT(GTK_TEXT(m_text)->vadj), "changed",
           (GtkSignalFunc) gtk_scrollbar_changed_callback, (gpointer) this );
-
-        gtk_signal_connect( GTK_OBJECT(GTK_TEXT(m_text)), "focus_in_event",
-              GTK_SIGNAL_FUNC(gtk_text_focus_in_callback), (gpointer)this );
-
-        gtk_signal_connect( GTK_OBJECT(GTK_TEXT(m_text)), "focus_out_event",
-                           GTK_SIGNAL_FUNC(gtk_text_focus_out_callback), (gpointer)this );
-    }
-    else
-    {
-        gtk_signal_connect( GTK_OBJECT(m_text), "focus_in_event",
-              GTK_SIGNAL_FUNC(gtk_text_focus_in_callback), (gpointer)this );
-
-        gtk_signal_connect( GTK_OBJECT(m_text), "focus_out_event",
-                           GTK_SIGNAL_FUNC(gtk_text_focus_out_callback), (gpointer)this );
     }
 
     if (!value.IsEmpty())
index 8a1f5c0cb9ea0ff3410ed7b92ca48054ff6b1264..8f73c4e2db7ad7f02f261df34e9a02daa05a5a54 100644 (file)
@@ -1669,7 +1669,7 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget,
     switch ( g_sendActivateEvent )
     {
         case -1:
-            // we've got focus from outside, synthtize wxActivateEvent
+            // we've got focus from outside, synthetize wxActivateEvent
             g_sendActivateEvent = 1;
             break;
 
@@ -1683,14 +1683,12 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget,
     g_focusWindowLast =
     g_focusWindow = win;
 
-/*
-    printf( "OnSetFocus from " );
+#if 0
+    wxPrintf( "OnSetFocus from " );
     if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
-        printf( win->GetClassInfo()->GetClassName() );
-    printf( "   " );
-    printf( WXSTRINGCAST win->GetLabel() );
-    printf( ".\n" );
-*/
+        wxPrintf( win->GetClassInfo()->GetClassName() );
+    wxPrintf( ".\n" );
+#endif
 
     // notify the parent keeping track of focus for the kbd navigation
     // purposes that we got it
@@ -1711,16 +1709,6 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget,
     }
 #endif // wxUSE_CARET
 
-#if wxUSE_TEXTCTRL
-    // If it's a wxTextCtrl don't send the event as it will be done
-    // after the control gets to process it.
-    wxTextCtrl *ctrl = wxDynamicCast(win, wxTextCtrl);
-    if ( ctrl )
-    {
-        return FALSE;
-    }
-#endif
-
     if (win->IsTopLevel())
     {
         wxActivateEvent event( wxEVT_ACTIVATE, TRUE, win->GetId() );
@@ -1768,12 +1756,12 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED
 
     g_focusWindow = (wxWindowGTK *)NULL;
 
-/*
-    printf( "OnKillFocus from " );
+#if 0
+    wxPrintf( "OnKillFocus from " );
     if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
-        printf( win->GetClassInfo()->GetClassName() );
-    printf( ".\n" );
-*/
+        wxPrintf( win->GetClassInfo()->GetClassName() );
+    wxPrintf( ".\n" );
+#endif
 
 #ifdef HAVE_XIM
     if (win->m_ic)
@@ -1789,16 +1777,6 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED
     }
 #endif // wxUSE_CARET
 
-#if wxUSE_TEXTCTRL
-    // If it's a wxTextCtrl don't send the event as it will be done
-    // after the control gets to process it.
-    wxTextCtrl *ctrl = wxDynamicCast(win, wxTextCtrl);
-    if ( ctrl )
-    {
-        return FALSE;
-    }
-#endif
-
     if (win->IsTopLevel())
     {
         wxActivateEvent event( wxEVT_ACTIVATE, FALSE, win->GetId() );
@@ -1837,9 +1815,7 @@ static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_
     if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE;
 
     wxMouseEvent event( wxEVT_ENTER_WINDOW );
-#if (GTK_MINOR_VERSION > 0)
     event.SetTimestamp( gdk_event->time );
-#endif
     event.SetEventObject( win );
 
     int x = 0;
@@ -1879,9 +1855,7 @@ static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_
     if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE;
 
     wxMouseEvent event( wxEVT_LEAVE_WINDOW );
-#if (GTK_MINOR_VERSION > 0)
     event.SetTimestamp( gdk_event->time );
-#endif
     event.SetEventObject( win );
 
     int x = 0;
@@ -2299,6 +2273,7 @@ void wxWindowGTK::Init()
     // GTK specific
     m_widget = (GtkWidget *) NULL;
     m_wxwindow = (GtkWidget *) NULL;
+    m_focusWidget = (GtkWidget *) NULL;
 
     // position/size
     m_x = 0;
@@ -2313,7 +2288,7 @@ void wxWindowGTK::Init()
 
     m_noExpose = FALSE;
     m_nativeSizeEvent = FALSE;
-
+    
     m_hasScrolling = FALSE;
     m_isScrolling = FALSE;
 
@@ -2487,6 +2462,8 @@ bool wxWindowGTK::Create( wxWindow *parent,
 
     if (m_parent)
         m_parent->DoAddChild( this );
+        
+    m_focusWidget = m_wxwindow;
 
     PostCreation();
 
@@ -2576,12 +2553,12 @@ bool wxWindowGTK::PreCreation( wxWindowGTK *parent, const wxPoint &pos,  const w
 void wxWindowGTK::PostCreation()
 {
     wxASSERT_MSG( (m_widget != NULL), wxT("invalid window") );
-
+    
     if (m_wxwindow)
     {
         if (!m_noExpose)
         {
-            /* these get reported to wxWindows -> wxPaintEvent */
+            // these get reported to wxWindows -> wxPaintEvent
 
             gtk_pizza_set_external( GTK_PIZZA(m_wxwindow), TRUE );
 
@@ -2598,35 +2575,32 @@ void wxWindowGTK::PostCreation()
             }
         }
 
-#if (GTK_MINOR_VERSION > 0)
-        /* these are called when the "sunken" or "raised" borders are drawn */
+        // these are called when the "sunken" or "raised" borders are drawn */
         gtk_signal_connect( GTK_OBJECT(m_widget), "expose_event",
           GTK_SIGNAL_FUNC(gtk_window_own_expose_callback), (gpointer)this );
 
         gtk_signal_connect( GTK_OBJECT(m_widget), "draw",
           GTK_SIGNAL_FUNC(gtk_window_own_draw_callback), (gpointer)this );
-#endif
     }
 
-    if (m_wxwindow && m_needParent)
-    {
-        gtk_signal_connect( GTK_OBJECT(m_wxwindow), "focus_in_event",
-            GTK_SIGNAL_FUNC(gtk_window_focus_in_callback), (gpointer)this );
+    // focus handling
 
-        gtk_signal_connect( GTK_OBJECT(m_wxwindow), "focus_out_event",
-            GTK_SIGNAL_FUNC(gtk_window_focus_out_callback), (gpointer)this );
-    }
-    else
-    {
-        // For dialogs and frames, we are interested mainly in
-        // m_widget's focus.
+    if (m_focusWidget == NULL)
+        m_focusWidget = m_widget;
 
-        gtk_signal_connect( GTK_OBJECT(m_widget), "focus_in_event",
-            GTK_SIGNAL_FUNC(gtk_window_focus_in_callback), (gpointer)this );
+#if 0
+    if (GetClassInfo() && GetClassInfo()->GetClassName())
+        wxPrintf( GetClassInfo()->GetClassName() );
+    wxPrintf( ".\n" );
+#endif
 
-        gtk_signal_connect( GTK_OBJECT(m_widget), "focus_out_event",
-            GTK_SIGNAL_FUNC(gtk_window_focus_out_callback), (gpointer)this );
-    }
+    gtk_signal_connect( GTK_OBJECT(m_focusWidget), "focus_in_event",
+        GTK_SIGNAL_FUNC(gtk_window_focus_in_callback), (gpointer)this );
+
+    gtk_signal_connect( GTK_OBJECT(m_focusWidget), "focus_out_event",
+         GTK_SIGNAL_FUNC(gtk_window_focus_out_callback), (gpointer)this );
+
+    // connect to the various key and mouse handlers
 
     GtkWidget *connect_widget = GetConnectWidget();
 
index 26e78469decc7383c5e9610d9ffca09023ca8002..c138c48a42f01adad90ac78719a5474f177f2bb0 100644 (file)
@@ -154,6 +154,8 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value,
     }
 
     m_parent->DoAddChild( this );
+    
+    m_focusWidget = GTK_COMBO(m_widget)->entry;
 
     PostCreation();
 
index 392fa2fa4c6e39422112d0cd5b4fe7b15b6f1a0b..91b5df62155b3956d524e49638ea3a6b6ba9e729 100644 (file)
@@ -46,11 +46,13 @@ void wxStaticBitmap::CreatePixmapWidget()
         mask = m_bitmap.GetMask()->GetBitmap();
     m_widget = gtk_pixmap_new( m_bitmap.GetPixmap(), mask );
 
-    /* insert GTK representation */
+    // insert GTK representation
     (*m_parent->m_insertCallback)(m_parent, this);
 
     gtk_widget_show( m_widget );
 
+    m_focusWidget = m_widget;
+
     PostCreation();
 }
 
@@ -64,7 +66,7 @@ bool wxStaticBitmap::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi
         !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
     {
         wxFAIL_MSG( wxT("wxXX creation failed") );
-       return FALSE;
+    return FALSE;
     }
 
     m_bitmap = bitmap;
@@ -81,6 +83,8 @@ bool wxStaticBitmap::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi
     else
     {
         m_widget = gtk_label_new( "Bitmap" );
+        
+        m_focusWidget = m_widget;
 
         PostCreation();
     }
index 468f7262a25feef63c6a98a5ae4c32aefacf86f5..35de57809a7bc4356f3516b039bcc9ad03596a7f 100644 (file)
@@ -52,6 +52,9 @@ gtk_insert_text_callback(GtkEditable *editable,
                          gint *position,
                          wxTextCtrl *win)
 {
+    if (g_isIdle)
+        wxapp_install_idle_handler();
+
     // we should only be called if we have a max len limit at all
     GtkEntry *entry = GTK_ENTRY (editable);
 
@@ -117,111 +120,6 @@ gtk_scrollbar_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win )
     win->CalculateScrollbar();
 }
 
-//-----------------------------------------------------------------------------
-// "focus_in_event"
-//-----------------------------------------------------------------------------
-
-extern wxWindow  *g_focusWindow;
-extern bool       g_blockEventsOnDrag;
-// extern bool g_isIdle;
-
-static gint gtk_text_focus_in_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxWindow *win )
-{
-    // Necessary?
-#if 0
-    if (g_isIdle)
-        wxapp_install_idle_handler();
-#endif
-    if (!win->m_hasVMT) return FALSE;
-    if (g_blockEventsOnDrag) return FALSE;
-
-    g_focusWindow = win;
-
-    // notify the parent that we got the focus
-    wxChildFocusEvent eventFocus(win);
-    (void)win->GetEventHandler()->ProcessEvent(eventFocus);
-
-#ifdef HAVE_XIM
-    if (win->m_ic)
-        gdk_im_begin(win->m_ic, win->m_wxwindow->window);
-#endif
-
-#if 0
-#ifdef wxUSE_CARET
-    // caret needs to be informed about focus change
-    wxCaret *caret = win->GetCaret();
-    if ( caret )
-    {
-        caret->OnSetFocus();
-    }
-#endif // wxUSE_CARET
-#endif
-
-    wxFocusEvent event( wxEVT_SET_FOCUS, win->GetId() );
-    event.SetEventObject( win );
-
-    if (win->GetEventHandler()->ProcessEvent( event ))
-    {
-        return TRUE;
-    }
-
-    return FALSE;
-}
-
-//-----------------------------------------------------------------------------
-// "focus_out_event"
-//-----------------------------------------------------------------------------
-
-static gint gtk_text_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxWindow *win )
-{
-#if 0
-    if (g_isIdle)
-        wxapp_install_idle_handler();
-#endif
-
-    if (!win->m_hasVMT) return FALSE;
-    if (g_blockEventsOnDrag) return FALSE;
-
-#if 0
-    // if the focus goes out of our app alltogether, OnIdle() will send
-    // wxActivateEvent, otherwise gtk_window_focus_in_callback() will reset
-    // g_sendActivateEvent to -1
-    g_sendActivateEvent = 0;
-#endif
-
-    wxWindow *winFocus = wxFindFocusedChild(win);
-    if ( winFocus )
-        win = winFocus;
-
-    g_focusWindow = (wxWindow *)NULL;
-
-#ifdef HAVE_XIM
-    if (win->m_ic)
-        gdk_im_end();
-#endif
-
-#if 0
-#ifdef wxUSE_CARET
-    // caret needs to be informed about focus change
-    wxCaret *caret = win->GetCaret();
-    if ( caret )
-    {
-        caret->OnKillFocus();
-    }
-#endif // wxUSE_CARET
-#endif
-
-    wxFocusEvent event( wxEVT_KILL_FOCUS, win->GetId() );
-    event.SetEventObject( win );
-
-    if (win->GetEventHandler()->ProcessEvent( event ))
-    {
-        return TRUE;
-    }
-
-    return FALSE;
-}
-
 //-----------------------------------------------------------------------------
 //  wxTextCtrl
 //-----------------------------------------------------------------------------
@@ -347,6 +245,8 @@ bool wxTextCtrl::Create( wxWindow *parent,
     }
 
     m_parent->DoAddChild( this );
+    
+    m_focusWidget = m_text;
 
     PostCreation();
 
@@ -368,20 +268,6 @@ bool wxTextCtrl::Create( wxWindow *parent,
     {
         gtk_signal_connect(GTK_OBJECT(GTK_TEXT(m_text)->vadj), "changed",
           (GtkSignalFunc) gtk_scrollbar_changed_callback, (gpointer) this );
-
-        gtk_signal_connect( GTK_OBJECT(GTK_TEXT(m_text)), "focus_in_event",
-              GTK_SIGNAL_FUNC(gtk_text_focus_in_callback), (gpointer)this );
-
-        gtk_signal_connect( GTK_OBJECT(GTK_TEXT(m_text)), "focus_out_event",
-                           GTK_SIGNAL_FUNC(gtk_text_focus_out_callback), (gpointer)this );
-    }
-    else
-    {
-        gtk_signal_connect( GTK_OBJECT(m_text), "focus_in_event",
-              GTK_SIGNAL_FUNC(gtk_text_focus_in_callback), (gpointer)this );
-
-        gtk_signal_connect( GTK_OBJECT(m_text), "focus_out_event",
-                           GTK_SIGNAL_FUNC(gtk_text_focus_out_callback), (gpointer)this );
     }
 
     if (!value.IsEmpty())
index 8a1f5c0cb9ea0ff3410ed7b92ca48054ff6b1264..8f73c4e2db7ad7f02f261df34e9a02daa05a5a54 100644 (file)
@@ -1669,7 +1669,7 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget,
     switch ( g_sendActivateEvent )
     {
         case -1:
-            // we've got focus from outside, synthtize wxActivateEvent
+            // we've got focus from outside, synthetize wxActivateEvent
             g_sendActivateEvent = 1;
             break;
 
@@ -1683,14 +1683,12 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget,
     g_focusWindowLast =
     g_focusWindow = win;
 
-/*
-    printf( "OnSetFocus from " );
+#if 0
+    wxPrintf( "OnSetFocus from " );
     if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
-        printf( win->GetClassInfo()->GetClassName() );
-    printf( "   " );
-    printf( WXSTRINGCAST win->GetLabel() );
-    printf( ".\n" );
-*/
+        wxPrintf( win->GetClassInfo()->GetClassName() );
+    wxPrintf( ".\n" );
+#endif
 
     // notify the parent keeping track of focus for the kbd navigation
     // purposes that we got it
@@ -1711,16 +1709,6 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget,
     }
 #endif // wxUSE_CARET
 
-#if wxUSE_TEXTCTRL
-    // If it's a wxTextCtrl don't send the event as it will be done
-    // after the control gets to process it.
-    wxTextCtrl *ctrl = wxDynamicCast(win, wxTextCtrl);
-    if ( ctrl )
-    {
-        return FALSE;
-    }
-#endif
-
     if (win->IsTopLevel())
     {
         wxActivateEvent event( wxEVT_ACTIVATE, TRUE, win->GetId() );
@@ -1768,12 +1756,12 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED
 
     g_focusWindow = (wxWindowGTK *)NULL;
 
-/*
-    printf( "OnKillFocus from " );
+#if 0
+    wxPrintf( "OnKillFocus from " );
     if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
-        printf( win->GetClassInfo()->GetClassName() );
-    printf( ".\n" );
-*/
+        wxPrintf( win->GetClassInfo()->GetClassName() );
+    wxPrintf( ".\n" );
+#endif
 
 #ifdef HAVE_XIM
     if (win->m_ic)
@@ -1789,16 +1777,6 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED
     }
 #endif // wxUSE_CARET
 
-#if wxUSE_TEXTCTRL
-    // If it's a wxTextCtrl don't send the event as it will be done
-    // after the control gets to process it.
-    wxTextCtrl *ctrl = wxDynamicCast(win, wxTextCtrl);
-    if ( ctrl )
-    {
-        return FALSE;
-    }
-#endif
-
     if (win->IsTopLevel())
     {
         wxActivateEvent event( wxEVT_ACTIVATE, FALSE, win->GetId() );
@@ -1837,9 +1815,7 @@ static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_
     if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE;
 
     wxMouseEvent event( wxEVT_ENTER_WINDOW );
-#if (GTK_MINOR_VERSION > 0)
     event.SetTimestamp( gdk_event->time );
-#endif
     event.SetEventObject( win );
 
     int x = 0;
@@ -1879,9 +1855,7 @@ static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_
     if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE;
 
     wxMouseEvent event( wxEVT_LEAVE_WINDOW );
-#if (GTK_MINOR_VERSION > 0)
     event.SetTimestamp( gdk_event->time );
-#endif
     event.SetEventObject( win );
 
     int x = 0;
@@ -2299,6 +2273,7 @@ void wxWindowGTK::Init()
     // GTK specific
     m_widget = (GtkWidget *) NULL;
     m_wxwindow = (GtkWidget *) NULL;
+    m_focusWidget = (GtkWidget *) NULL;
 
     // position/size
     m_x = 0;
@@ -2313,7 +2288,7 @@ void wxWindowGTK::Init()
 
     m_noExpose = FALSE;
     m_nativeSizeEvent = FALSE;
-
+    
     m_hasScrolling = FALSE;
     m_isScrolling = FALSE;
 
@@ -2487,6 +2462,8 @@ bool wxWindowGTK::Create( wxWindow *parent,
 
     if (m_parent)
         m_parent->DoAddChild( this );
+        
+    m_focusWidget = m_wxwindow;
 
     PostCreation();
 
@@ -2576,12 +2553,12 @@ bool wxWindowGTK::PreCreation( wxWindowGTK *parent, const wxPoint &pos,  const w
 void wxWindowGTK::PostCreation()
 {
     wxASSERT_MSG( (m_widget != NULL), wxT("invalid window") );
-
+    
     if (m_wxwindow)
     {
         if (!m_noExpose)
         {
-            /* these get reported to wxWindows -> wxPaintEvent */
+            // these get reported to wxWindows -> wxPaintEvent
 
             gtk_pizza_set_external( GTK_PIZZA(m_wxwindow), TRUE );
 
@@ -2598,35 +2575,32 @@ void wxWindowGTK::PostCreation()
             }
         }
 
-#if (GTK_MINOR_VERSION > 0)
-        /* these are called when the "sunken" or "raised" borders are drawn */
+        // these are called when the "sunken" or "raised" borders are drawn */
         gtk_signal_connect( GTK_OBJECT(m_widget), "expose_event",
           GTK_SIGNAL_FUNC(gtk_window_own_expose_callback), (gpointer)this );
 
         gtk_signal_connect( GTK_OBJECT(m_widget), "draw",
           GTK_SIGNAL_FUNC(gtk_window_own_draw_callback), (gpointer)this );
-#endif
     }
 
-    if (m_wxwindow && m_needParent)
-    {
-        gtk_signal_connect( GTK_OBJECT(m_wxwindow), "focus_in_event",
-            GTK_SIGNAL_FUNC(gtk_window_focus_in_callback), (gpointer)this );
+    // focus handling
 
-        gtk_signal_connect( GTK_OBJECT(m_wxwindow), "focus_out_event",
-            GTK_SIGNAL_FUNC(gtk_window_focus_out_callback), (gpointer)this );
-    }
-    else
-    {
-        // For dialogs and frames, we are interested mainly in
-        // m_widget's focus.
+    if (m_focusWidget == NULL)
+        m_focusWidget = m_widget;
 
-        gtk_signal_connect( GTK_OBJECT(m_widget), "focus_in_event",
-            GTK_SIGNAL_FUNC(gtk_window_focus_in_callback), (gpointer)this );
+#if 0
+    if (GetClassInfo() && GetClassInfo()->GetClassName())
+        wxPrintf( GetClassInfo()->GetClassName() );
+    wxPrintf( ".\n" );
+#endif
 
-        gtk_signal_connect( GTK_OBJECT(m_widget), "focus_out_event",
-            GTK_SIGNAL_FUNC(gtk_window_focus_out_callback), (gpointer)this );
-    }
+    gtk_signal_connect( GTK_OBJECT(m_focusWidget), "focus_in_event",
+        GTK_SIGNAL_FUNC(gtk_window_focus_in_callback), (gpointer)this );
+
+    gtk_signal_connect( GTK_OBJECT(m_focusWidget), "focus_out_event",
+         GTK_SIGNAL_FUNC(gtk_window_focus_out_callback), (gpointer)this );
+
+    // connect to the various key and mouse handlers
 
     GtkWidget *connect_widget = GetConnectWidget();