X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6ed98c6a3b7f2be77ea16b5d26467796c1be9f4d..0598e263cecc205aff9a6735cf41803205fabbcb:/src/os2/toplevel.cpp?ds=sidebyside diff --git a/src/os2/toplevel.cpp b/src/os2/toplevel.cpp index 4e74fa9343..a7a66c4f1e 100644 --- a/src/os2/toplevel.cpp +++ b/src/os2/toplevel.cpp @@ -59,6 +59,14 @@ extern void wxAssociateWinWithHandle( HWND hWnd bool wxTopLevelWindowOS2::m_sbInitialized = FALSE; wxWindow* wxTopLevelWindowOS2::m_spHiddenParent = NULL; +// ============================================================================ +// wxTopLevelWindowOS2 implementation +// ============================================================================ + +BEGIN_EVENT_TABLE(wxTopLevelWindowOS2, wxTopLevelWindowBase) + EVT_ACTIVATE(wxTopLevelWindowOS2::OnActivate) +END_EVENT_TABLE() + // ============================================================================ // wxTopLevelWindowMSW implementation // ============================================================================ @@ -70,21 +78,21 @@ MRESULT EXPENTRY wxDlgProc( HWND WXUNUSED(hWnd) ,MPARAM WXUNUSED(lParam) ) { - if (uMessage == WM_INITDLG) - { - // - // For this message, returning TRUE tells system to set focus to the - // first control in the dialog box. - // - return (MRESULT)TRUE; - } - else + switch(uMessage) { - // - // For all the other ones, FALSE means that we didn't process the - // message - // - return (MRESULT)FALSE; + case WM_INITDLG: + // + // For this message, returning TRUE tells system to set focus to + // the first control in the dialog box, but we set the focus + // ourselves, however in OS/2 we must return true to enable the dialog + // + return (MRESULT)TRUE; + default: + // + // For all the other ones, FALSE means that we didn't process the + // message + // + return (MRESULT)FALSE; } } // end of wxDlgProc @@ -111,8 +119,65 @@ void wxTopLevelWindowOS2::Init() m_hFrame = NULLHANDLE; memset(&m_vSwp, 0, sizeof(SWP)); memset(&m_vSwpClient, 0, sizeof(SWP)); + m_pWinLastFocused = (wxWindow *)NULL; } // end of wxTopLevelWindowIOS2::Init +void wxTopLevelWindowOS2::OnActivate( + wxActivateEvent& rEvent +) +{ + if (rEvent.GetActive()) + { + // + // Restore focus to the child which was last focused + // + wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), m_hWnd); + + wxWindow* pParent = m_pWinLastFocused ? m_pWinLastFocused->GetParent() + : NULL; + if (!pParent) + { + pParent = this; + } + + wxSetFocusToChild( pParent + ,&m_pWinLastFocused + ); + } + else // deactivating + { + // + // Remember the last focused child if it is our child + // + m_pWinLastFocused = FindFocus(); + + // + // So we NULL it out if it's a child from some other frame + // + wxWindow* pWin = m_pWinLastFocused; + + while (pWin) + { + if (pWin->IsTopLevel()) + { + if (pWin != this) + { + m_pWinLastFocused = NULL; + } + break; + } + pWin = pWin->GetParent(); + } + + wxLogTrace(_T("focus"), + _T("wxTLW %08x deactivated, last focused: %08x."), + m_hWnd, + m_pWinLastFocused ? GetHwndOf(m_pWinLastFocused) + : NULL); + rEvent.Skip(); + } +} // end of wxTopLevelWindowOS2::OnActivate + WXDWORD wxTopLevelWindowOS2::OS2GetStyle( long lStyle , WXDWORD* pdwExflags @@ -332,7 +397,7 @@ bool wxTopLevelWindowOS2::CreateDialog( ,nY ,nWidth ,nHeight - ,SWP_MOVE | SWP_SIZE | SWP_ZORDER | SWP_SHOW + ,SWP_MOVE | SWP_SIZE | SWP_ZORDER | SWP_SHOW | SWP_ACTIVATE ); ::WinQueryWindowPos(GetHwnd(), GetSwp()); m_hFrame = m_hWnd;