From 76fcf0f239c37fbcfe8dcc12f0c59387de96be2a Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sun, 19 Aug 2001 21:36:25 +0000 Subject: [PATCH] Various changes for simplification of focus event 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 | 31 +++++---- include/wx/gtk1/window.h | 31 +++++---- samples/controls/controls.cpp | 1 + src/gtk/combobox.cpp | 2 + src/gtk/statbmp.cpp | 8 ++- src/gtk/textctrl.cpp | 124 ++-------------------------------- src/gtk/window.cpp | 92 +++++++++---------------- src/gtk1/combobox.cpp | 2 + src/gtk1/statbmp.cpp | 8 ++- src/gtk1/textctrl.cpp | 124 ++-------------------------------- src/gtk1/window.cpp | 92 +++++++++---------------- 11 files changed, 127 insertions(+), 388 deletions(-) diff --git a/include/wx/gtk/window.h b/include/wx/gtk/window.h index e648eb9815..cfb1e5af1b 100644 --- a/include/wx/gtk/window.h +++ b/include/wx/gtk/window.h @@ -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 diff --git a/include/wx/gtk1/window.h b/include/wx/gtk1/window.h index e648eb9815..cfb1e5af1b 100644 --- a/include/wx/gtk1/window.h +++ b/include/wx/gtk1/window.h @@ -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 diff --git a/samples/controls/controls.cpp b/samples/controls/controls.cpp index 4c23313cd1..0673cb6bbb 100644 --- a/samples/controls/controls.cpp +++ b/samples/controls/controls.cpp @@ -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); diff --git a/src/gtk/combobox.cpp b/src/gtk/combobox.cpp index 26e78469de..c138c48a42 100644 --- a/src/gtk/combobox.cpp +++ b/src/gtk/combobox.cpp @@ -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(); diff --git a/src/gtk/statbmp.cpp b/src/gtk/statbmp.cpp index 392fa2fa4c..91b5df6215 100644 --- a/src/gtk/statbmp.cpp +++ b/src/gtk/statbmp.cpp @@ -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(); } diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 468f7262a2..35de57809a 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -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()) diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 8a1f5c0cb9..8f73c4e2db 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -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(); diff --git a/src/gtk1/combobox.cpp b/src/gtk1/combobox.cpp index 26e78469de..c138c48a42 100644 --- a/src/gtk1/combobox.cpp +++ b/src/gtk1/combobox.cpp @@ -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(); diff --git a/src/gtk1/statbmp.cpp b/src/gtk1/statbmp.cpp index 392fa2fa4c..91b5df6215 100644 --- a/src/gtk1/statbmp.cpp +++ b/src/gtk1/statbmp.cpp @@ -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(); } diff --git a/src/gtk1/textctrl.cpp b/src/gtk1/textctrl.cpp index 468f7262a2..35de57809a 100644 --- a/src/gtk1/textctrl.cpp +++ b/src/gtk1/textctrl.cpp @@ -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()) diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index 8a1f5c0cb9..8f73c4e2db 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -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(); -- 2.45.2