From 57a7b7c1484fda95240972aae876bdbdbbc98344 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Fri, 31 Jul 1998 13:01:34 +0000 Subject: [PATCH] Added wxAcceleratorTable, wxFrame::SetAcceleratorTable and additions to process it under wxMSW. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@406 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/defs.h | 1 + include/wx/msw/frame.h | 7 ++++++- include/wx/msw/mdi.h | 2 ++ include/wx/msw/window.h | 3 ++- samples/mdi/mdi.cpp | 10 ++++++++++ samples/minimal/minimal.rc | 3 +++ src/msw/app.cpp | 25 ++++++++++++++----------- src/msw/data.cpp | 1 + src/msw/frame.cpp | 16 ++++++++++++++-- src/msw/makefile.b32 | 3 +++ src/msw/makefile.dos | 6 ++++++ src/msw/makefile.g95 | 1 + src/msw/makefile.nt | 6 ++++++ src/msw/mdi.cpp | 30 ++++++++++++++++++++++++------ src/msw/registry.cpp | 3 +++ src/msw/window.cpp | 9 +++++++-- 16 files changed, 103 insertions(+), 23 deletions(-) diff --git a/include/wx/defs.h b/include/wx/defs.h index 6734839262..099c48b6ae 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -858,6 +858,7 @@ typedef unsigned long WXHBRUSH; typedef unsigned long WXHPALETTE; typedef unsigned long WXHCURSOR; typedef unsigned long WXHRGN; +typedef unsigned long WXHACCEL; typedef unsigned long WXHINSTANCE; typedef unsigned long WXHBITMAP; typedef unsigned long WXHIMAGELIST; diff --git a/include/wx/msw/frame.h b/include/wx/msw/frame.h index 30184810c2..642962a488 100644 --- a/include/wx/msw/frame.h +++ b/include/wx/msw/frame.h @@ -18,6 +18,7 @@ #include "wx/window.h" #include "wx/toolbar.h" +#include "wx/msw/accel.h" WXDLLEXPORT_DATA(extern const char*) wxFrameNameStr; WXDLLEXPORT_DATA(extern const char*) wxToolBarNameStr; @@ -126,7 +127,9 @@ public: inline bool Iconized(void) const { return IsIconized(); } virtual void Maximize(bool maximize); - virtual bool LoadAccelerators(const wxString& table); +// virtual bool LoadAccelerators(const wxString& table); + + virtual void SetAcceleratorTable(const wxAcceleratorTable& accel); // Responds to colour changes void OnSysColourChanged(wxSysColourChangedEvent& event); @@ -148,6 +151,7 @@ public: bool MSWOnClose(void); void MSWOnMenuHighlight(WXWORD item, WXWORD flags, WXHMENU sysmenu); bool MSWProcessMessage(WXMSG *msg); + bool MSWTranslateMessage(WXMSG *msg); void MSWCreate(int id, wxWindow *parent, const char *WXUNUSED(wclass), wxWindow *wx_win, const char *title, int x, int y, int width, int height, long style); @@ -159,6 +163,7 @@ protected: WXHICON m_defaultIcon; static bool m_useNativeStatusBar; wxToolBar * m_frameToolBar ; + wxAcceleratorTable m_acceleratorTable; DECLARE_EVENT_TABLE() }; diff --git a/include/wx/msw/mdi.h b/include/wx/msw/mdi.h index 0ba4f62034..a07466a196 100644 --- a/include/wx/msw/mdi.h +++ b/include/wx/msw/mdi.h @@ -94,6 +94,7 @@ class WXDLLEXPORT wxMDIParentFrame: public wxFrame bool MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control); void MSWOnMenuHighlight(WXWORD item, WXWORD flags, WXHMENU sysmenu); bool MSWProcessMessage(WXMSG *msg); + bool MSWTranslateMessage(WXMSG *msg); void MSWOnCreate(WXLPCREATESTRUCT cs); long MSWDefWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam); bool MSWOnEraseBkgnd(WXHDC pDC); @@ -161,6 +162,7 @@ class WXDLLEXPORT wxMDIChildFrame: public wxFrame bool MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control); long MSWDefWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam); bool MSWProcessMessage(WXMSG *msg); + bool MSWTranslateMessage(WXMSG *msg); void MSWDestroyWindow(void); // Implementation diff --git a/include/wx/msw/window.h b/include/wx/msw/window.h index 82c7516980..e18eec3a63 100644 --- a/include/wx/msw/window.h +++ b/include/wx/msw/window.h @@ -555,6 +555,7 @@ public: // Calls an appropriate default window procedure virtual long MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); virtual bool MSWProcessMessage(WXMSG* pMsg); + virtual bool MSWTranslateMessage(WXMSG* pMsg); virtual void MSWDestroyWindow(void); // Detach "Window" menu from menu bar so it doesn't get deleted @@ -665,7 +666,7 @@ public: #endif */ - WXHANDLE m_acceleratorTable; +// WXHANDLE m_acceleratorTable; WXHMENU m_hMenu; // Menu, if any wxList * m_children; // Window's children int m_returnCode; diff --git a/samples/mdi/mdi.cpp b/samples/mdi/mdi.cpp index 5aee6a0806..dfcfa0bb4b 100644 --- a/samples/mdi/mdi.cpp +++ b/samples/mdi/mdi.cpp @@ -100,6 +100,16 @@ MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, c CreateToolBar(wxNO_BORDER|wxTB_FLAT|wxTB_HORIZONTAL); InitToolBar(GetToolBar()); + +#ifdef __WXMSW__ + // Accelerators + wxAcceleratorEntry entries[3]; + entries[0].Set(wxACCEL_CTRL, (int) 'N', MDI_NEW_WINDOW); + entries[1].Set(wxACCEL_CTRL, (int) 'X', MDI_QUIT); + entries[2].Set(wxACCEL_CTRL, (int) 'A', MDI_ABOUT); + wxAcceleratorTable accel(3, entries); + SetAcceleratorTable(accel); +#endif } void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) ) diff --git a/samples/minimal/minimal.rc b/samples/minimal/minimal.rc index 7655c62a4c..3bf71d6da0 100644 --- a/samples/minimal/minimal.rc +++ b/samples/minimal/minimal.rc @@ -1,3 +1,6 @@ mondrian ICON "mondrian.ico" #include "wx/msw/wx.rc" +#define MINIMAL_QUIT 1 +#define MINIMAL_ABOUT 102 + diff --git a/src/msw/app.cpp b/src/msw/app.cpp index 47b65da5b4..6a73f6d322 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -757,26 +757,29 @@ bool wxApp::ProcessMessage(WXMSG *Msg) HWND hWnd; - // Anyone for a message? Try youngest descendants first. + // Try translations first; find the youngest window with + // a translation table. for (hWnd = msg->hwnd; hWnd != NULL; hWnd = ::GetParent(hWnd)) { wxWindow *wnd = wxFindWinFromHandle((WXHWND) hWnd); if (wnd) { - if (wnd->MSWProcessMessage(Msg)) + if (wnd->MSWTranslateMessage(Msg)) return TRUE; - - // STOP if we've reached the top of the hierarchy! -// if (m_topWindow && (wnd == m_topWindow)) -// return FALSE; } } - // TODO: Is this now obsolete, given that m_topWindow may not be defined? - // Does it do anything useful anyway? -// if (m_topWindow && m_topWindow->MSWProcessMessage(Msg)) -// return TRUE; - return FALSE; + // Anyone for a non-translation message? Try youngest descendants first. + for (hWnd = msg->hwnd; hWnd != NULL; hWnd = ::GetParent(hWnd)) + { + wxWindow *wnd = wxFindWinFromHandle((WXHWND) hWnd); + if (wnd) + { + if (wnd->MSWProcessMessage(Msg)) + return TRUE; + } + } + return FALSE; } void wxApp::OnIdle(wxIdleEvent& event) diff --git a/src/msw/data.cpp b/src/msw/data.cpp index a692201c45..ea8b75ba3d 100644 --- a/src/msw/data.cpp +++ b/src/msw/data.cpp @@ -99,6 +99,7 @@ wxCursor *wxHOURGLASS_CURSOR = NULL; wxCursor *wxCROSS_CURSOR = NULL; // 'Null' objects +wxAcceleratorTable wxNullAcceleratorTable; wxBitmap wxNullBitmap; wxIcon wxNullIcon; wxCursor wxNullCursor; diff --git a/src/msw/frame.cpp b/src/msw/frame.cpp index a616ad14a1..4684891fc2 100644 --- a/src/msw/frame.cpp +++ b/src/msw/frame.cpp @@ -348,6 +348,11 @@ void wxFrame::SetIcon(const wxIcon& icon) #endif } +void wxFrame::SetAcceleratorTable(const wxAcceleratorTable& accel) +{ + m_acceleratorTable = accel; +} + wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id, const wxString& name) { @@ -479,6 +484,7 @@ void wxFrame::SetMenuBar(wxMenuBar *menu_bar) menu_bar->m_menuBarFrame = this; } +#if 0 bool wxFrame::LoadAccelerators(const wxString& table) { m_acceleratorTable = (WXHANDLE) @@ -498,6 +504,7 @@ bool wxFrame::LoadAccelerators(const wxString& table) return (m_acceleratorTable != (WXHANDLE) NULL); } +#endif void wxFrame::Fit(void) { @@ -758,8 +765,13 @@ void wxFrame::MSWOnMenuHighlight(WXWORD nItem, WXWORD nFlags, WXHMENU hSysMenu) bool wxFrame::MSWProcessMessage(WXMSG* pMsg) { - if (m_acceleratorTable != 0 && - ::TranslateAccelerator((HWND) GetHWND(), (HACCEL) m_acceleratorTable, (MSG *)pMsg)) + return FALSE; +} + +bool wxFrame::MSWTranslateMessage(WXMSG* pMsg) +{ + if (m_acceleratorTable.Ok() && + ::TranslateAccelerator((HWND) GetHWND(), (HACCEL) m_acceleratorTable.GetHACCEL(), (MSG *)pMsg)) return TRUE; return FALSE; diff --git a/src/msw/makefile.b32 b/src/msw/makefile.b32 index 6d765757a1..b44de26681 100644 --- a/src/msw/makefile.b32 +++ b/src/msw/makefile.b32 @@ -118,6 +118,7 @@ COMMONOBJS = \ # $(MSWDIR)\matrix.obj \ MSWOBJS = \ + $(MSWDIR)\accel.obj \ $(MSWDIR)\app.obj \ $(MSWDIR)\bitmap.obj \ $(MSWDIR)\bmpbuttn.obj \ @@ -234,6 +235,8 @@ $(COMMDIR)\lex_yy.c: $(COMMDIR)\doslex.c #$(OBJECTS): $(WXDIR)\include\wx\setup.h +$(MSWDIR)\accel.obj: $(MSWDIR)\accel.$(SRCSUFF) + $(MSWDIR)\app.obj: $(MSWDIR)\app.$(SRCSUFF) $(MSWDIR)\bitmap.obj: $(MSWDIR)\bitmap.$(SRCSUFF) diff --git a/src/msw/makefile.dos b/src/msw/makefile.dos index ee63802731..6d28cd8edb 100644 --- a/src/msw/makefile.dos +++ b/src/msw/makefile.dos @@ -119,6 +119,7 @@ COMMONOBJS = \ # $(COMMDIR)\fileconf.obj # Doens't compile (nested classes) MSWOBJS = \ + $(MSWDIR)\accel.obj \ $(MSWDIR)\app.obj \ $(MSWDIR)\bitmap.obj \ $(MSWDIR)\bmpbuttn.obj \ @@ -258,6 +259,11 @@ dummydll.obj: dummydll.$(SRCSUFF) $(WXDIR)\include\wx\wx.h $(CPPFLAGS) /YcWX/WXPREC.H /c /Tp $*.$(SRCSUFF) << +$(MSWDIR)/accel.obj: $*.$(SRCSUFF) + cl @<< +$(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF) +<< + $(MSWDIR)/app.obj: $*.$(SRCSUFF) cl @<< $(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF) diff --git a/src/msw/makefile.g95 b/src/msw/makefile.g95 index 8e6ac8f024..5db4dfeeb6 100644 --- a/src/msw/makefile.g95 +++ b/src/msw/makefile.g95 @@ -122,6 +122,7 @@ COMMONOBJS = \ $(COMMDIR)/wincmn.$(OBJSUFF) MSWOBJS = \ + accel.$(OBJSUFF) \ app.$(OBJSUFF) \ bitmap.$(OBJSUFF) \ bmpbuttn.$(OBJSUFF) \ diff --git a/src/msw/makefile.nt b/src/msw/makefile.nt index 3174cef27d..695ae309cd 100644 --- a/src/msw/makefile.nt +++ b/src/msw/makefile.nt @@ -122,6 +122,7 @@ COMMONOBJS = \ MSWOBJS = \ + $(MSWDIR)\accel.obj \ $(MSWDIR)\app.obj \ $(MSWDIR)\bitmap.obj \ $(MSWDIR)\bmpbuttn.obj \ @@ -278,6 +279,11 @@ dummydll.obj: dummydll.$(SRCSUFF) $(WXDIR)\include\wx\wx.h $(CPPFLAGS) $(MAKEPRECOMP) /c /Tp $*.$(SRCSUFF) << +$(MSWDIR)/accel.obj: $*.$(SRCSUFF) + cl @<< +$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@ +<< + $(MSWDIR)/app.obj: $*.$(SRCSUFF) cl @<< $(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@ diff --git a/src/msw/mdi.cpp b/src/msw/mdi.cpp index 55998c1240..774b215ca1 100644 --- a/src/msw/mdi.cpp +++ b/src/msw/mdi.cpp @@ -479,7 +479,7 @@ bool wxMDIParentFrame::MSWOnActivate(int state, bool minimized, WXHWND activate) bool wxMDIParentFrame::MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control) { - if (cmd == 0) +// if (cmd == 0) // Why did I do this test? { // In case it's e.g. a toolbar. wxWindow *win = wxFindWinFromHandle(control); @@ -599,8 +599,18 @@ bool wxMDIParentFrame::MSWProcessMessage(WXMSG* msg) if ((m_currentChild != (wxWindow *)NULL) && (m_currentChild->GetHWND() != (WXHWND) NULL) && m_currentChild->MSWProcessMessage(msg)) return TRUE; - if (m_acceleratorTable != (WXHANDLE) NULL && - ::TranslateAccelerator((HWND) GetHWND(), (HACCEL) m_acceleratorTable, pMsg)) + return FALSE; +} + +bool wxMDIParentFrame::MSWTranslateMessage(WXMSG* msg) +{ + MSG *pMsg = (MSG *)msg; + + if ((m_currentChild != (wxWindow *)NULL) && (m_currentChild->GetHWND() != (WXHWND) NULL) && m_currentChild->MSWTranslateMessage(msg)) + return TRUE; + + if (m_acceleratorTable.Ok() && + ::TranslateAccelerator((HWND) GetHWND(), (HACCEL) m_acceleratorTable.GetHACCEL(), pMsg)) return TRUE; if (pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN) @@ -612,6 +622,7 @@ bool wxMDIParentFrame::MSWProcessMessage(WXMSG* msg) return FALSE; } + bool wxMDIParentFrame::MSWOnEraseBkgnd(WXHDC WXUNUSED(pDC)) { return TRUE; @@ -918,7 +929,8 @@ bool wxMDIChildFrame::MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control) #if WXDEBUG > 1 wxDebugMsg("wxMDIChildFrame::MSWOnCommand %d\n", GetHWND()); #endif - if ((cmd == 0) && GetHWND()) +// if ((cmd == 0) && GetHWND()) + if (GetHWND()) { // In case it's e.g. a toolbar. wxWindow *win = wxFindWinFromHandle(control); @@ -946,14 +958,20 @@ long wxMDIChildFrame::MSWDefWindowProc(WXUINT message, WXUINT wParam, WXLPARAM l } bool wxMDIChildFrame::MSWProcessMessage(WXMSG *msg) +{ + return FALSE; +} + +bool wxMDIChildFrame::MSWTranslateMessage(WXMSG* msg) { MSG *pMsg = (MSG *)msg; - if (m_acceleratorTable && GetHWND()) + if (m_acceleratorTable.Ok()) { wxFrame *parent = (wxFrame *)GetParent(); HWND parent_hwnd = (HWND) parent->GetHWND(); - return (::TranslateAccelerator(parent_hwnd, (HACCEL) m_acceleratorTable, pMsg) != 0); + return (::TranslateAccelerator(parent_hwnd, (HACCEL) m_acceleratorTable.GetHACCEL(), pMsg) != 0); } + return FALSE; } diff --git a/src/msw/registry.cpp b/src/msw/registry.cpp index e7d698cbbd..c6d0142dc1 100644 --- a/src/msw/registry.cpp +++ b/src/msw/registry.cpp @@ -33,8 +33,11 @@ #include "wx/log.h" // Windows headers +/* #define STRICT #define WIN32_LEAN_AND_MEAN +*/ + #include // other std headers diff --git a/src/msw/window.cpp b/src/msw/window.cpp index d5e8050619..e594c9b07b 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -252,7 +252,7 @@ wxWindow::wxWindow(void) m_lastMsg = 0; m_lastWParam = 0; m_lastLParam = 0; - m_acceleratorTable = 0; +// m_acceleratorTable = 0; m_hMenu = 0; m_xThumbSize = 0; @@ -434,7 +434,7 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID id, m_lastMsg = 0; m_lastWParam = 0; m_lastLParam = 0; - m_acceleratorTable = 0; +// m_acceleratorTable = 0; m_hMenu = 0; m_xThumbSize = 0; @@ -2012,6 +2012,11 @@ bool wxWindow::MSWProcessMessage(WXMSG* pMsg) return FALSE; } +bool wxWindow::MSWTranslateMessage(WXMSG* WXUNUSED(pMsg)) +{ + return FALSE; +} + long wxWindow::MSWOnMDIActivate(long WXUNUSED(flag), WXHWND WXUNUSED(activate), WXHWND WXUNUSED(deactivate)) { #if WXDEBUG > 1 -- 2.45.2