From a61421124afc0950d2b3c136472b46eefc0fbd61 Mon Sep 17 00:00:00 2001 From: David Webster Date: Tue, 23 May 2000 21:00:52 +0000 Subject: [PATCH] More accelerator work git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7469 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/os2/accel.h | 28 ++++++++++++++++------------ src/os2/accel.cpp | 31 ++++++++++++++++++++++++++++--- src/os2/app.cpp | 17 ++++++++++++++--- src/os2/frame.cpp | 4 +--- src/os2/mdi.cpp | 2 +- src/os2/window.cpp | 2 +- 6 files changed, 61 insertions(+), 23 deletions(-) diff --git a/include/wx/os2/accel.h b/include/wx/os2/accel.h index 49730d5d9b..226e0320bc 100644 --- a/include/wx/os2/accel.h +++ b/include/wx/os2/accel.h @@ -53,28 +53,32 @@ class WXDLLEXPORT wxAcceleratorTable: public wxObject DECLARE_DYNAMIC_CLASS(wxAcceleratorTable) public: wxAcceleratorTable(); - wxAcceleratorTable(const wxString& resource); // Load from .rc resource - wxAcceleratorTable(int n, wxAcceleratorEntry entries[]); // Load from array + wxAcceleratorTable(const wxString& rsResource); // Load from .rc resource + wxAcceleratorTable( int n + ,wxAcceleratorEntry vaEntries[] + ); // Load from array // Copy constructors - inline wxAcceleratorTable(const wxAcceleratorTable& accel) { Ref(accel); } - inline wxAcceleratorTable(const wxAcceleratorTable* accel) { if (accel) Ref(*accel); } + inline wxAcceleratorTable(const wxAcceleratorTable& rAccel) { Ref(rAccel); } + inline wxAcceleratorTable(const wxAcceleratorTable* pAccel) { if (pAccel) Ref(*pAccel); } ~wxAcceleratorTable(); - inline wxAcceleratorTable& operator = (const wxAcceleratorTable& accel) - { if (*this == accel) return (*this); Ref(accel); return *this; }; - inline bool operator == (const wxAcceleratorTable& accel) - { return m_refData == accel.m_refData; }; - inline bool operator != (const wxAcceleratorTable& accel) - { return m_refData != accel.m_refData; }; + inline wxAcceleratorTable& operator = (const wxAcceleratorTable& rAccel) + { if (*this == rAccel) return (*this); Ref(rAccel); return *this; }; + inline bool operator == (const wxAcceleratorTable& rAccel) + { return m_refData == rAccel.m_refData; }; + inline bool operator != (const wxAcceleratorTable& rAccel) + { return m_refData != rAccel.m_refData; }; bool Ok() const; void SetHACCEL(WXHACCEL hAccel); - WXHACCEL GetHACCEL() const; + WXHACCEL GetHACCEL(void) const; // translate the accelerator, return TRUE if done - bool Translate(wxWindow *window, WXMSG *msg) const; + bool Translate( WXHWND hWnd + ,WXMSG* pMsg + ) const; }; WXDLLEXPORT_DATA(extern wxAcceleratorTable) wxNullAcceleratorTable; diff --git a/src/os2/accel.cpp b/src/os2/accel.cpp index 5cd421d0ff..41feab31bd 100644 --- a/src/os2/accel.cpp +++ b/src/os2/accel.cpp @@ -79,6 +79,18 @@ wxAcceleratorTable::wxAcceleratorTable( ,NULL // resources always in .exe ,(ULONG)ulId ); + if (wxTheApp->GetTopWindow() != NULL) + { + // + // If we have accelerators the top window is the frame + // + wxFrame* pFrame = (wxFrame*)wxTheApp->GetTopWindow(); + + ::WinSetAccelTable( vHabmain + ,(HWND)pFrame->GetFrame() + ,hAccel + ); + } M_ACCELDATA->m_hAccel = hAccel; M_ACCELDATA->m_ok = (hAccel != 0); } @@ -117,7 +129,7 @@ wxAcceleratorTable::wxAcceleratorTable( ,&bIsVirtual ); if (bIsVirtual) - uVirt |= AF_VIRTUALKEY; + uVirt = AF_CHAR | AF_VIRTUALKEY; USHORT uCmd = vaEntries[i].GetCommand(); @@ -130,6 +142,19 @@ wxAcceleratorTable::wxAcceleratorTable( M_ACCELDATA->m_hAccel = ::WinCreateAccelTable( vHabmain ,pArr ); + if (wxTheApp->GetTopWindow() != NULL) + { + // + // If we have accelerators the top window is the frame + // + wxFrame* pFrame = (wxFrame*)wxTheApp->GetTopWindow(); + + ::WinSetAccelTable( vHabmain + ,(HWND)pFrame->GetFrame() + ,M_ACCELDATA->m_hAccel + ); + } + delete[] pArr; M_ACCELDATA->m_ok = (M_ACCELDATA->m_hAccel != 0); } // end of wxAcceleratorTable::wxAcceleratorTable @@ -155,14 +180,14 @@ WXHACCEL wxAcceleratorTable::GetHACCEL() const } bool wxAcceleratorTable::Translate( - wxWindow* pWindow + WXHWND hWnd , WXMSG* pWxmsg ) const { PQMSG pMsg = (PQMSG)pWxmsg; return Ok() && ::WinTranslateAccel( vHabmain - ,GetHwndOf(pWindow) + ,(HWND)hWnd ,GetHaccel() ,pMsg ); diff --git a/src/os2/app.cpp b/src/os2/app.cpp index 94a18e1e2f..d59feeaccf 100644 --- a/src/os2/app.cpp +++ b/src/os2/app.cpp @@ -698,8 +698,8 @@ bool wxApp::ProcessMessage( WXMSG* pWxmsg ) { - QMSG* vMsg = (PQMSG)pWxmsg; - HWND hWnd = vMsg->hwnd; + QMSG* pMsg = (PQMSG)pWxmsg; + HWND hWnd = pMsg->hwnd; wxWindow* pWndThis = wxFindWinFromHandle((WXHWND)hWnd); wxWindow* pWnd; @@ -708,7 +708,7 @@ bool wxApp::ProcessMessage( // We must relay WM_MOUSEMOVE events to the tooltip ctrl if we want it to // popup the tooltip bubbles // - if (pWndThis && (vMsg->msg == WM_MOUSEMOVE)) + if (pWndThis && (pMsg->msg == WM_MOUSEMOVE)) { wxToolTip* pToolTip = pWndThis->GetToolTip(); if (pToolTip) @@ -729,6 +729,17 @@ bool wxApp::ProcessMessage( pWndThis = wxFindWinFromHandle((WXHWND)hWnd); } + // + // Try translations first; find the youngest window with + // a translation table. + // + for (pWnd = pWndThis; pWnd; pWnd = pWnd->GetParent() ) + { + if (pMsg->msg == WM_CHAR) + if (pWnd->OS2TranslateMessage(pWxmsg)) + return TRUE; + } + // // Anyone for a non-translation message? Try youngest descendants first. // diff --git a/src/os2/frame.cpp b/src/os2/frame.cpp index fe19a3d024..0bfe4f7c52 100644 --- a/src/os2/frame.cpp +++ b/src/os2/frame.cpp @@ -1147,8 +1147,6 @@ bool wxFrame::OS2TranslateMessage( WXMSG* pMsg ) { - if (wxWindow::OS2TranslateMessage(pMsg)) - return TRUE; // // try the menu bar accels // @@ -1158,7 +1156,7 @@ bool wxFrame::OS2TranslateMessage( return FALSE; const wxAcceleratorTable& rAcceleratorTable = pMenuBar->GetAccelTable(); - return rAcceleratorTable.Translate(this, pMsg); + return rAcceleratorTable.Translate(m_hFrame, pMsg); } // end of wxFrame::OS2TranslateMessage // --------------------------------------------------------------------------- diff --git a/src/os2/mdi.cpp b/src/os2/mdi.cpp index b0142bab68..2c36bb8c0d 100644 --- a/src/os2/mdi.cpp +++ b/src/os2/mdi.cpp @@ -996,7 +996,7 @@ MRESULT wxMDIChildFrame::OS2DefWindowProc(WXUINT message, WXWPARAM wParam, WXLPA bool wxMDIChildFrame::OS2TranslateMessage(WXMSG* msg) { - return m_acceleratorTable.Translate(GetParent(), msg); + return m_acceleratorTable.Translate(GetParent()->GetHWND(), msg); } // --------------------------------------------------------------------------- diff --git a/src/os2/window.cpp b/src/os2/window.cpp index ef559b7aa9..ef1e7fa285 100644 --- a/src/os2/window.cpp +++ b/src/os2/window.cpp @@ -1699,7 +1699,7 @@ bool wxWindow::OS2TranslateMessage( WXMSG* pMsg ) { - return m_acceleratorTable.Translate(this, pMsg); + return m_acceleratorTable.Translate(m_hWnd, pMsg); } // end of wxWindow::OS2TranslateMessage // ---------------------------------------------------------------------------