From 0fe0275981e662b56d9df1e5847932326f04cf0b Mon Sep 17 00:00:00 2001
From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= <vslavik@fastmail.fm>
Date: Wed, 29 Sep 2004 14:34:28 +0000
Subject: [PATCH] changes to make wxWindow::FindFocus work as expected with
 composite controls

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29540 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 include/wx/window.h        | 10 +++++++++-
 src/cocoa/window.mm        |  2 +-
 src/common/wincmn.cpp      | 10 ++++++++++
 src/generic/listctrl.cpp   |  2 ++
 src/gtk/window.cpp         |  2 +-
 src/gtk1/window.cpp        |  2 +-
 src/mac/carbon/window.cpp  |  2 +-
 src/mac/classic/window.cpp |  2 +-
 src/mgl/window.cpp         |  2 +-
 src/motif/window.cpp       |  2 +-
 src/msw/window.cpp         |  2 +-
 src/os2/window.cpp         |  4 ++--
 src/os2/wx25.def           |  2 +-
 src/x11/window.cpp         |  2 +-
 14 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/include/wx/window.h b/include/wx/window.h
index e43fff75ef..3c9e9a8906 100644
--- a/include/wx/window.h
+++ b/include/wx/window.h
@@ -493,7 +493,9 @@ public:
     virtual void SetFocusFromKbd() { SetFocus(); }
 
         // return the window which currently has the focus or NULL
-    static wxWindow *FindFocus() /* = 0: implement in derived classes */;
+    static wxWindow *FindFocus();
+    
+    static wxWindow *DoFindFocus() /* = 0: implement in derived classes */;
 
         // can this window have focus?
     virtual bool AcceptsFocus() const { return IsShown() && IsEnabled(); }
@@ -1072,6 +1074,12 @@ protected:
     // Send the wxWindowDestroyEvent
     void SendDestroyEvent();
 
+    // returns the main window of composite control; this is the window
+    // that FindFocus returns if the focus is in one of composite control's
+    // windows
+    virtual wxWindow *GetMainWindowOfCompositeControl() 
+        { return (wxWindow*)this; }
+
     // the window id - a number which uniquely identifies a window among
     // its siblings unless it is wxID_ANY
     wxWindowID           m_windowId;
diff --git a/src/cocoa/window.mm b/src/cocoa/window.mm
index b5838d9752..a1e06db23e 100644
--- a/src/cocoa/window.mm
+++ b/src/cocoa/window.mm
@@ -855,7 +855,7 @@ bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y)
 }
 
 // Get the window with the focus
-wxWindow *wxWindowBase::FindFocus()
+wxWindow *wxWindowBase::DoFindFocus()
 {
     // TODO
     return NULL;
diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp
index 74b2b50b6c..44fdda3991 100644
--- a/src/common/wincmn.cpp
+++ b/src/common/wincmn.cpp
@@ -2467,6 +2467,16 @@ void wxWindowBase::DoMoveInTabOrder(wxWindow *win, MoveKind move)
     }
 }
 
+// ----------------------------------------------------------------------------
+// focus handling
+// ----------------------------------------------------------------------------
+
+/*static*/ wxWindow* wxWindowBase::FindFocus()
+{
+    wxWindow *win = DoFindFocus();
+    return win ? win->GetMainWindowOfCompositeControl() : NULL;
+}
+
 // ----------------------------------------------------------------------------
 // global functions
 // ----------------------------------------------------------------------------
diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp
index 573f8c91f6..00e2e002c3 100644
--- a/src/generic/listctrl.cpp
+++ b/src/generic/listctrl.cpp
@@ -517,6 +517,8 @@ public:
                       const wxString &name = _T("listctrlmainwindow") );
 
     virtual ~wxListMainWindow();
+    
+    wxWindow *GetMainWindowOfCompositeControl() { return GetParent(); }
 
     bool HasFlag(int flag) const { return m_parent->HasFlag(flag); }
 
diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp
index 5b78c8b40e..a8d1520741 100644
--- a/src/gtk/window.cpp
+++ b/src/gtk/window.cpp
@@ -2359,7 +2359,7 @@ static gint gtk_scrollbar_button_release_callback( GtkRange *widget,
 // because it is static and so couldn't be made virtual
 // ----------------------------------------------------------------------------
 
-wxWindow *wxWindowBase::FindFocus()
+wxWindow *wxWindowBase::DoFindFocus()
 {
     // the cast is necessary when we compile in wxUniversal mode
     return (wxWindow *)g_focusWindow;
diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp
index 5b78c8b40e..a8d1520741 100644
--- a/src/gtk1/window.cpp
+++ b/src/gtk1/window.cpp
@@ -2359,7 +2359,7 @@ static gint gtk_scrollbar_button_release_callback( GtkRange *widget,
 // because it is static and so couldn't be made virtual
 // ----------------------------------------------------------------------------
 
-wxWindow *wxWindowBase::FindFocus()
+wxWindow *wxWindowBase::DoFindFocus()
 {
     // the cast is necessary when we compile in wxUniversal mode
     return (wxWindow *)g_focusWindow;
diff --git a/src/mac/carbon/window.cpp b/src/mac/carbon/window.cpp
index c84a5c1632..06d75e4611 100644
--- a/src/mac/carbon/window.cpp
+++ b/src/mac/carbon/window.cpp
@@ -2486,7 +2486,7 @@ void wxWindowMac::MacOnScroll(wxScrollEvent &event )
 }
 
 // Get the window with the focus
-wxWindowMac *wxWindowBase::FindFocus()
+wxWindowMac *wxWindowBase::DoFindFocus()
 {
     ControlRef control ;
     GetKeyboardFocus( GetUserFocusWindow() , &control ) ;
diff --git a/src/mac/classic/window.cpp b/src/mac/classic/window.cpp
index db17efd0b3..57b25ec1dc 100644
--- a/src/mac/classic/window.cpp
+++ b/src/mac/classic/window.cpp
@@ -1332,7 +1332,7 @@ void wxWindowMac::MacOnScroll(wxScrollEvent &event )
 }
 
 // Get the window with the focus
-wxWindowMac *wxWindowBase::FindFocus()
+wxWindowMac *wxWindowBase::DoFindFocus()
 {
     return gFocusWindow ;
 }
diff --git a/src/mgl/window.cpp b/src/mgl/window.cpp
index ae6e6e0177..560a55b514 100644
--- a/src/mgl/window.cpp
+++ b/src/mgl/window.cpp
@@ -742,7 +742,7 @@ void wxWindowMGL::KillFocus()
 // this wxWindowBase function is implemented here (in platform-specific file)
 // because it is static and so couldn't be made virtual
 // ----------------------------------------------------------------------------
-wxWindow *wxWindowBase::FindFocus()
+wxWindow *wxWindowBase::DoFindFocus()
 {
     return (wxWindow*)gs_focusedWindow;
 }
diff --git a/src/motif/window.cpp b/src/motif/window.cpp
index 207afc3ed0..c4babdf5db 100644
--- a/src/motif/window.cpp
+++ b/src/motif/window.cpp
@@ -564,7 +564,7 @@ void wxWindow::SetFocus()
 }
 
 // Get the window with the focus
-wxWindow *wxWindowBase::FindFocus()
+wxWindow *wxWindowBase::DoFindFocus()
 {
     // TODO Problems:
     // (1) Can there be multiple focussed widgets in an application?
diff --git a/src/msw/window.cpp b/src/msw/window.cpp
index 2d23c631f1..1daf19b5e9 100644
--- a/src/msw/window.cpp
+++ b/src/msw/window.cpp
@@ -581,7 +581,7 @@ void wxWindowMSW::SetFocusFromKbd()
 }
 
 // Get the window with the focus
-wxWindow *wxWindowBase::FindFocus()
+wxWindow *wxWindowBase::DoFindFocus()
 {
     HWND hWnd = ::GetFocus();
     if ( hWnd )
diff --git a/src/os2/window.cpp b/src/os2/window.cpp
index 022caeb470..6c57b9aa91 100644
--- a/src/os2/window.cpp
+++ b/src/os2/window.cpp
@@ -475,7 +475,7 @@ void wxWindowOS2::SetFocusFromKbd()
     wxWindowBase::SetFocusFromKbd();
 } // end of wxWindowOS2::SetFocus
 
-wxWindow* wxWindowBase::FindFocus()
+wxWindow* wxWindowBase::DoFindFocus()
 {
     HWND                            hWnd = ::WinQueryFocus(HWND_DESKTOP);
 
@@ -484,7 +484,7 @@ wxWindow* wxWindowBase::FindFocus()
         return wxFindWinFromHandle((WXHWND)hWnd);
     }
     return NULL;
-} // wxWindowBase::FindFocus
+} // wxWindowBase::DoFindFocus
 
 bool wxWindowOS2::Enable(
   bool                              bEnable
diff --git a/src/os2/wx25.def b/src/os2/wx25.def
index ea187e4c2a..c2615d9b06 100644
--- a/src/os2/wx25.def
+++ b/src/os2/wx25.def
@@ -14262,7 +14262,7 @@ EXPORTS
       DoMoveWindow__8wxWindowFiN31
       ;wxWindow::DoClientToScreen(int*,int*) const
       DoClientToScreen__8wxWindowCFPiT1
-      ;wxWindowBase::FindFocus()
+      ;wxWindowBase::DoFindFocus()
       FindFocus__12wxWindowBaseFv
       ;wxWindow::OS2OnDrawItem(int,void**)
       OS2OnDrawItem__8wxWindowFiPPv
diff --git a/src/x11/window.cpp b/src/x11/window.cpp
index 666f2d0157..deccc1ef5b 100644
--- a/src/x11/window.cpp
+++ b/src/x11/window.cpp
@@ -394,7 +394,7 @@ void wxWindowX11::SetFocus()
 }
 
 // Get the window with the focus
-wxWindow *wxWindowBase::FindFocus()
+wxWindow *wxWindowBase::DoFindFocus()
 {
     Window xfocus = (Window) 0;
     int revert = 0;
-- 
2.50.0

