More accelerator work

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7469 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
David Webster
2000-05-23 21:00:52 +00:00
parent d30143f3cb
commit a61421124a
6 changed files with 61 additions and 23 deletions

View File

@@ -53,28 +53,32 @@ class WXDLLEXPORT wxAcceleratorTable: public wxObject
DECLARE_DYNAMIC_CLASS(wxAcceleratorTable) DECLARE_DYNAMIC_CLASS(wxAcceleratorTable)
public: public:
wxAcceleratorTable(); wxAcceleratorTable();
wxAcceleratorTable(const wxString& resource); // Load from .rc resource wxAcceleratorTable(const wxString& rsResource); // Load from .rc resource
wxAcceleratorTable(int n, wxAcceleratorEntry entries[]); // Load from array wxAcceleratorTable( int n
,wxAcceleratorEntry vaEntries[]
); // Load from array
// Copy constructors // Copy constructors
inline wxAcceleratorTable(const wxAcceleratorTable& accel) { Ref(accel); } inline wxAcceleratorTable(const wxAcceleratorTable& rAccel) { Ref(rAccel); }
inline wxAcceleratorTable(const wxAcceleratorTable* accel) { if (accel) Ref(*accel); } inline wxAcceleratorTable(const wxAcceleratorTable* pAccel) { if (pAccel) Ref(*pAccel); }
~wxAcceleratorTable(); ~wxAcceleratorTable();
inline wxAcceleratorTable& operator = (const wxAcceleratorTable& accel) inline wxAcceleratorTable& operator = (const wxAcceleratorTable& rAccel)
{ if (*this == accel) return (*this); Ref(accel); return *this; }; { if (*this == rAccel) return (*this); Ref(rAccel); return *this; };
inline bool operator == (const wxAcceleratorTable& accel) inline bool operator == (const wxAcceleratorTable& rAccel)
{ return m_refData == accel.m_refData; }; { return m_refData == rAccel.m_refData; };
inline bool operator != (const wxAcceleratorTable& accel) inline bool operator != (const wxAcceleratorTable& rAccel)
{ return m_refData != accel.m_refData; }; { return m_refData != rAccel.m_refData; };
bool Ok() const; bool Ok() const;
void SetHACCEL(WXHACCEL hAccel); void SetHACCEL(WXHACCEL hAccel);
WXHACCEL GetHACCEL() const; WXHACCEL GetHACCEL(void) const;
// translate the accelerator, return TRUE if done // 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; WXDLLEXPORT_DATA(extern wxAcceleratorTable) wxNullAcceleratorTable;

View File

@@ -79,6 +79,18 @@ wxAcceleratorTable::wxAcceleratorTable(
,NULL // resources always in .exe ,NULL // resources always in .exe
,(ULONG)ulId ,(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_hAccel = hAccel;
M_ACCELDATA->m_ok = (hAccel != 0); M_ACCELDATA->m_ok = (hAccel != 0);
} }
@@ -117,7 +129,7 @@ wxAcceleratorTable::wxAcceleratorTable(
,&bIsVirtual ,&bIsVirtual
); );
if (bIsVirtual) if (bIsVirtual)
uVirt |= AF_VIRTUALKEY; uVirt = AF_CHAR | AF_VIRTUALKEY;
USHORT uCmd = vaEntries[i].GetCommand(); USHORT uCmd = vaEntries[i].GetCommand();
@@ -130,6 +142,19 @@ wxAcceleratorTable::wxAcceleratorTable(
M_ACCELDATA->m_hAccel = ::WinCreateAccelTable( vHabmain M_ACCELDATA->m_hAccel = ::WinCreateAccelTable( vHabmain
,pArr ,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; delete[] pArr;
M_ACCELDATA->m_ok = (M_ACCELDATA->m_hAccel != 0); M_ACCELDATA->m_ok = (M_ACCELDATA->m_hAccel != 0);
} // end of wxAcceleratorTable::wxAcceleratorTable } // end of wxAcceleratorTable::wxAcceleratorTable
@@ -155,14 +180,14 @@ WXHACCEL wxAcceleratorTable::GetHACCEL() const
} }
bool wxAcceleratorTable::Translate( bool wxAcceleratorTable::Translate(
wxWindow* pWindow WXHWND hWnd
, WXMSG* pWxmsg , WXMSG* pWxmsg
) const ) const
{ {
PQMSG pMsg = (PQMSG)pWxmsg; PQMSG pMsg = (PQMSG)pWxmsg;
return Ok() && ::WinTranslateAccel( vHabmain return Ok() && ::WinTranslateAccel( vHabmain
,GetHwndOf(pWindow) ,(HWND)hWnd
,GetHaccel() ,GetHaccel()
,pMsg ,pMsg
); );

View File

@@ -698,8 +698,8 @@ bool wxApp::ProcessMessage(
WXMSG* pWxmsg WXMSG* pWxmsg
) )
{ {
QMSG* vMsg = (PQMSG)pWxmsg; QMSG* pMsg = (PQMSG)pWxmsg;
HWND hWnd = vMsg->hwnd; HWND hWnd = pMsg->hwnd;
wxWindow* pWndThis = wxFindWinFromHandle((WXHWND)hWnd); wxWindow* pWndThis = wxFindWinFromHandle((WXHWND)hWnd);
wxWindow* pWnd; wxWindow* pWnd;
@@ -708,7 +708,7 @@ bool wxApp::ProcessMessage(
// We must relay WM_MOUSEMOVE events to the tooltip ctrl if we want it to // We must relay WM_MOUSEMOVE events to the tooltip ctrl if we want it to
// popup the tooltip bubbles // popup the tooltip bubbles
// //
if (pWndThis && (vMsg->msg == WM_MOUSEMOVE)) if (pWndThis && (pMsg->msg == WM_MOUSEMOVE))
{ {
wxToolTip* pToolTip = pWndThis->GetToolTip(); wxToolTip* pToolTip = pWndThis->GetToolTip();
if (pToolTip) if (pToolTip)
@@ -729,6 +729,17 @@ bool wxApp::ProcessMessage(
pWndThis = wxFindWinFromHandle((WXHWND)hWnd); 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. // Anyone for a non-translation message? Try youngest descendants first.
// //

View File

@@ -1147,8 +1147,6 @@ bool wxFrame::OS2TranslateMessage(
WXMSG* pMsg WXMSG* pMsg
) )
{ {
if (wxWindow::OS2TranslateMessage(pMsg))
return TRUE;
// //
// try the menu bar accels // try the menu bar accels
// //
@@ -1158,7 +1156,7 @@ bool wxFrame::OS2TranslateMessage(
return FALSE; return FALSE;
const wxAcceleratorTable& rAcceleratorTable = pMenuBar->GetAccelTable(); const wxAcceleratorTable& rAcceleratorTable = pMenuBar->GetAccelTable();
return rAcceleratorTable.Translate(this, pMsg); return rAcceleratorTable.Translate(m_hFrame, pMsg);
} // end of wxFrame::OS2TranslateMessage } // end of wxFrame::OS2TranslateMessage
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@@ -996,7 +996,7 @@ MRESULT wxMDIChildFrame::OS2DefWindowProc(WXUINT message, WXWPARAM wParam, WXLPA
bool wxMDIChildFrame::OS2TranslateMessage(WXMSG* msg) bool wxMDIChildFrame::OS2TranslateMessage(WXMSG* msg)
{ {
return m_acceleratorTable.Translate(GetParent(), msg); return m_acceleratorTable.Translate(GetParent()->GetHWND(), msg);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@@ -1699,7 +1699,7 @@ bool wxWindow::OS2TranslateMessage(
WXMSG* pMsg WXMSG* pMsg
) )
{ {
return m_acceleratorTable.Translate(this, pMsg); return m_acceleratorTable.Translate(m_hWnd, pMsg);
} // end of wxWindow::OS2TranslateMessage } // end of wxWindow::OS2TranslateMessage
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------