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
This commit is contained in:
Julian Smart
1998-07-31 13:01:34 +00:00
parent bd0df01f3f
commit 57a7b7c148
16 changed files with 103 additions and 23 deletions

View File

@@ -858,6 +858,7 @@ typedef unsigned long WXHBRUSH;
typedef unsigned long WXHPALETTE; typedef unsigned long WXHPALETTE;
typedef unsigned long WXHCURSOR; typedef unsigned long WXHCURSOR;
typedef unsigned long WXHRGN; typedef unsigned long WXHRGN;
typedef unsigned long WXHACCEL;
typedef unsigned long WXHINSTANCE; typedef unsigned long WXHINSTANCE;
typedef unsigned long WXHBITMAP; typedef unsigned long WXHBITMAP;
typedef unsigned long WXHIMAGELIST; typedef unsigned long WXHIMAGELIST;

View File

@@ -18,6 +18,7 @@
#include "wx/window.h" #include "wx/window.h"
#include "wx/toolbar.h" #include "wx/toolbar.h"
#include "wx/msw/accel.h"
WXDLLEXPORT_DATA(extern const char*) wxFrameNameStr; WXDLLEXPORT_DATA(extern const char*) wxFrameNameStr;
WXDLLEXPORT_DATA(extern const char*) wxToolBarNameStr; WXDLLEXPORT_DATA(extern const char*) wxToolBarNameStr;
@@ -126,7 +127,9 @@ public:
inline bool Iconized(void) const { return IsIconized(); } inline bool Iconized(void) const { return IsIconized(); }
virtual void Maximize(bool maximize); 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 // Responds to colour changes
void OnSysColourChanged(wxSysColourChangedEvent& event); void OnSysColourChanged(wxSysColourChangedEvent& event);
@@ -148,6 +151,7 @@ public:
bool MSWOnClose(void); bool MSWOnClose(void);
void MSWOnMenuHighlight(WXWORD item, WXWORD flags, WXHMENU sysmenu); void MSWOnMenuHighlight(WXWORD item, WXWORD flags, WXHMENU sysmenu);
bool MSWProcessMessage(WXMSG *msg); bool MSWProcessMessage(WXMSG *msg);
bool MSWTranslateMessage(WXMSG *msg);
void MSWCreate(int id, wxWindow *parent, const char *WXUNUSED(wclass), wxWindow *wx_win, const char *title, 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); int x, int y, int width, int height, long style);
@@ -159,6 +163,7 @@ protected:
WXHICON m_defaultIcon; WXHICON m_defaultIcon;
static bool m_useNativeStatusBar; static bool m_useNativeStatusBar;
wxToolBar * m_frameToolBar ; wxToolBar * m_frameToolBar ;
wxAcceleratorTable m_acceleratorTable;
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };

View File

@@ -94,6 +94,7 @@ class WXDLLEXPORT wxMDIParentFrame: public wxFrame
bool MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control); bool MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control);
void MSWOnMenuHighlight(WXWORD item, WXWORD flags, WXHMENU sysmenu); void MSWOnMenuHighlight(WXWORD item, WXWORD flags, WXHMENU sysmenu);
bool MSWProcessMessage(WXMSG *msg); bool MSWProcessMessage(WXMSG *msg);
bool MSWTranslateMessage(WXMSG *msg);
void MSWOnCreate(WXLPCREATESTRUCT cs); void MSWOnCreate(WXLPCREATESTRUCT cs);
long MSWDefWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam); long MSWDefWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
bool MSWOnEraseBkgnd(WXHDC pDC); bool MSWOnEraseBkgnd(WXHDC pDC);
@@ -161,6 +162,7 @@ class WXDLLEXPORT wxMDIChildFrame: public wxFrame
bool MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control); bool MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control);
long MSWDefWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam); long MSWDefWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
bool MSWProcessMessage(WXMSG *msg); bool MSWProcessMessage(WXMSG *msg);
bool MSWTranslateMessage(WXMSG *msg);
void MSWDestroyWindow(void); void MSWDestroyWindow(void);
// Implementation // Implementation

View File

@@ -555,6 +555,7 @@ public:
// Calls an appropriate default window procedure // Calls an appropriate default window procedure
virtual long MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); virtual long MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
virtual bool MSWProcessMessage(WXMSG* pMsg); virtual bool MSWProcessMessage(WXMSG* pMsg);
virtual bool MSWTranslateMessage(WXMSG* pMsg);
virtual void MSWDestroyWindow(void); virtual void MSWDestroyWindow(void);
// Detach "Window" menu from menu bar so it doesn't get deleted // Detach "Window" menu from menu bar so it doesn't get deleted
@@ -665,7 +666,7 @@ public:
#endif #endif
*/ */
WXHANDLE m_acceleratorTable; // WXHANDLE m_acceleratorTable;
WXHMENU m_hMenu; // Menu, if any WXHMENU m_hMenu; // Menu, if any
wxList * m_children; // Window's children wxList * m_children; // Window's children
int m_returnCode; int m_returnCode;

View File

@@ -100,6 +100,16 @@ MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, c
CreateToolBar(wxNO_BORDER|wxTB_FLAT|wxTB_HORIZONTAL); CreateToolBar(wxNO_BORDER|wxTB_FLAT|wxTB_HORIZONTAL);
InitToolBar(GetToolBar()); 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) ) void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )

View File

@@ -1,3 +1,6 @@
mondrian ICON "mondrian.ico" mondrian ICON "mondrian.ico"
#include "wx/msw/wx.rc" #include "wx/msw/wx.rc"
#define MINIMAL_QUIT 1
#define MINIMAL_ABOUT 102

View File

@@ -757,7 +757,19 @@ bool wxApp::ProcessMessage(WXMSG *Msg)
HWND hWnd; 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->MSWTranslateMessage(Msg))
return TRUE;
}
}
// Anyone for a non-translation message? Try youngest descendants first.
for (hWnd = msg->hwnd; hWnd != NULL; hWnd = ::GetParent(hWnd)) for (hWnd = msg->hwnd; hWnd != NULL; hWnd = ::GetParent(hWnd))
{ {
wxWindow *wnd = wxFindWinFromHandle((WXHWND) hWnd); wxWindow *wnd = wxFindWinFromHandle((WXHWND) hWnd);
@@ -765,18 +777,9 @@ bool wxApp::ProcessMessage(WXMSG *Msg)
{ {
if (wnd->MSWProcessMessage(Msg)) if (wnd->MSWProcessMessage(Msg))
return TRUE; return TRUE;
// STOP if we've reached the top of the hierarchy!
// if (m_topWindow && (wnd == m_topWindow))
// return FALSE;
} }
} }
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;
} }
void wxApp::OnIdle(wxIdleEvent& event) void wxApp::OnIdle(wxIdleEvent& event)

View File

@@ -99,6 +99,7 @@ wxCursor *wxHOURGLASS_CURSOR = NULL;
wxCursor *wxCROSS_CURSOR = NULL; wxCursor *wxCROSS_CURSOR = NULL;
// 'Null' objects // 'Null' objects
wxAcceleratorTable wxNullAcceleratorTable;
wxBitmap wxNullBitmap; wxBitmap wxNullBitmap;
wxIcon wxNullIcon; wxIcon wxNullIcon;
wxCursor wxNullCursor; wxCursor wxNullCursor;

View File

@@ -348,6 +348,11 @@ void wxFrame::SetIcon(const wxIcon& icon)
#endif #endif
} }
void wxFrame::SetAcceleratorTable(const wxAcceleratorTable& accel)
{
m_acceleratorTable = accel;
}
wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id, wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id,
const wxString& name) const wxString& name)
{ {
@@ -479,6 +484,7 @@ void wxFrame::SetMenuBar(wxMenuBar *menu_bar)
menu_bar->m_menuBarFrame = this; menu_bar->m_menuBarFrame = this;
} }
#if 0
bool wxFrame::LoadAccelerators(const wxString& table) bool wxFrame::LoadAccelerators(const wxString& table)
{ {
m_acceleratorTable = (WXHANDLE) m_acceleratorTable = (WXHANDLE)
@@ -498,6 +504,7 @@ bool wxFrame::LoadAccelerators(const wxString& table)
return (m_acceleratorTable != (WXHANDLE) NULL); return (m_acceleratorTable != (WXHANDLE) NULL);
} }
#endif
void wxFrame::Fit(void) void wxFrame::Fit(void)
{ {
@@ -758,8 +765,13 @@ void wxFrame::MSWOnMenuHighlight(WXWORD nItem, WXWORD nFlags, WXHMENU hSysMenu)
bool wxFrame::MSWProcessMessage(WXMSG* pMsg) bool wxFrame::MSWProcessMessage(WXMSG* pMsg)
{ {
if (m_acceleratorTable != 0 && return FALSE;
::TranslateAccelerator((HWND) GetHWND(), (HACCEL) m_acceleratorTable, (MSG *)pMsg)) }
bool wxFrame::MSWTranslateMessage(WXMSG* pMsg)
{
if (m_acceleratorTable.Ok() &&
::TranslateAccelerator((HWND) GetHWND(), (HACCEL) m_acceleratorTable.GetHACCEL(), (MSG *)pMsg))
return TRUE; return TRUE;
return FALSE; return FALSE;

View File

@@ -118,6 +118,7 @@ COMMONOBJS = \
# $(MSWDIR)\matrix.obj \ # $(MSWDIR)\matrix.obj \
MSWOBJS = \ MSWOBJS = \
$(MSWDIR)\accel.obj \
$(MSWDIR)\app.obj \ $(MSWDIR)\app.obj \
$(MSWDIR)\bitmap.obj \ $(MSWDIR)\bitmap.obj \
$(MSWDIR)\bmpbuttn.obj \ $(MSWDIR)\bmpbuttn.obj \
@@ -234,6 +235,8 @@ $(COMMDIR)\lex_yy.c: $(COMMDIR)\doslex.c
#$(OBJECTS): $(WXDIR)\include\wx\setup.h #$(OBJECTS): $(WXDIR)\include\wx\setup.h
$(MSWDIR)\accel.obj: $(MSWDIR)\accel.$(SRCSUFF)
$(MSWDIR)\app.obj: $(MSWDIR)\app.$(SRCSUFF) $(MSWDIR)\app.obj: $(MSWDIR)\app.$(SRCSUFF)
$(MSWDIR)\bitmap.obj: $(MSWDIR)\bitmap.$(SRCSUFF) $(MSWDIR)\bitmap.obj: $(MSWDIR)\bitmap.$(SRCSUFF)

View File

@@ -119,6 +119,7 @@ COMMONOBJS = \
# $(COMMDIR)\fileconf.obj # Doens't compile (nested classes) # $(COMMDIR)\fileconf.obj # Doens't compile (nested classes)
MSWOBJS = \ MSWOBJS = \
$(MSWDIR)\accel.obj \
$(MSWDIR)\app.obj \ $(MSWDIR)\app.obj \
$(MSWDIR)\bitmap.obj \ $(MSWDIR)\bitmap.obj \
$(MSWDIR)\bmpbuttn.obj \ $(MSWDIR)\bmpbuttn.obj \
@@ -258,6 +259,11 @@ dummydll.obj: dummydll.$(SRCSUFF) $(WXDIR)\include\wx\wx.h
$(CPPFLAGS) /YcWX/WXPREC.H /c /Tp $*.$(SRCSUFF) $(CPPFLAGS) /YcWX/WXPREC.H /c /Tp $*.$(SRCSUFF)
<< <<
$(MSWDIR)/accel.obj: $*.$(SRCSUFF)
cl @<<
$(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF)
<<
$(MSWDIR)/app.obj: $*.$(SRCSUFF) $(MSWDIR)/app.obj: $*.$(SRCSUFF)
cl @<< cl @<<
$(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF) $(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF)

View File

@@ -122,6 +122,7 @@ COMMONOBJS = \
$(COMMDIR)/wincmn.$(OBJSUFF) $(COMMDIR)/wincmn.$(OBJSUFF)
MSWOBJS = \ MSWOBJS = \
accel.$(OBJSUFF) \
app.$(OBJSUFF) \ app.$(OBJSUFF) \
bitmap.$(OBJSUFF) \ bitmap.$(OBJSUFF) \
bmpbuttn.$(OBJSUFF) \ bmpbuttn.$(OBJSUFF) \

View File

@@ -122,6 +122,7 @@ COMMONOBJS = \
MSWOBJS = \ MSWOBJS = \
$(MSWDIR)\accel.obj \
$(MSWDIR)\app.obj \ $(MSWDIR)\app.obj \
$(MSWDIR)\bitmap.obj \ $(MSWDIR)\bitmap.obj \
$(MSWDIR)\bmpbuttn.obj \ $(MSWDIR)\bmpbuttn.obj \
@@ -278,6 +279,11 @@ dummydll.obj: dummydll.$(SRCSUFF) $(WXDIR)\include\wx\wx.h
$(CPPFLAGS) $(MAKEPRECOMP) /c /Tp $*.$(SRCSUFF) $(CPPFLAGS) $(MAKEPRECOMP) /c /Tp $*.$(SRCSUFF)
<< <<
$(MSWDIR)/accel.obj: $*.$(SRCSUFF)
cl @<<
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@
<<
$(MSWDIR)/app.obj: $*.$(SRCSUFF) $(MSWDIR)/app.obj: $*.$(SRCSUFF)
cl @<< cl @<<
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@ $(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@

View File

@@ -479,7 +479,7 @@ bool wxMDIParentFrame::MSWOnActivate(int state, bool minimized, WXHWND activate)
bool wxMDIParentFrame::MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control) 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. // In case it's e.g. a toolbar.
wxWindow *win = wxFindWinFromHandle(control); 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)) if ((m_currentChild != (wxWindow *)NULL) && (m_currentChild->GetHWND() != (WXHWND) NULL) && m_currentChild->MSWProcessMessage(msg))
return TRUE; return TRUE;
if (m_acceleratorTable != (WXHANDLE) NULL && return FALSE;
::TranslateAccelerator((HWND) GetHWND(), (HACCEL) m_acceleratorTable, pMsg)) }
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; return TRUE;
if (pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN) if (pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN)
@@ -612,6 +622,7 @@ bool wxMDIParentFrame::MSWProcessMessage(WXMSG* msg)
return FALSE; return FALSE;
} }
bool wxMDIParentFrame::MSWOnEraseBkgnd(WXHDC WXUNUSED(pDC)) bool wxMDIParentFrame::MSWOnEraseBkgnd(WXHDC WXUNUSED(pDC))
{ {
return TRUE; return TRUE;
@@ -918,7 +929,8 @@ bool wxMDIChildFrame::MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control)
#if WXDEBUG > 1 #if WXDEBUG > 1
wxDebugMsg("wxMDIChildFrame::MSWOnCommand %d\n", GetHWND()); wxDebugMsg("wxMDIChildFrame::MSWOnCommand %d\n", GetHWND());
#endif #endif
if ((cmd == 0) && GetHWND()) // if ((cmd == 0) && GetHWND())
if (GetHWND())
{ {
// In case it's e.g. a toolbar. // In case it's e.g. a toolbar.
wxWindow *win = wxFindWinFromHandle(control); wxWindow *win = wxFindWinFromHandle(control);
@@ -946,14 +958,20 @@ long wxMDIChildFrame::MSWDefWindowProc(WXUINT message, WXUINT wParam, WXLPARAM l
} }
bool wxMDIChildFrame::MSWProcessMessage(WXMSG *msg) bool wxMDIChildFrame::MSWProcessMessage(WXMSG *msg)
{
return FALSE;
}
bool wxMDIChildFrame::MSWTranslateMessage(WXMSG* msg)
{ {
MSG *pMsg = (MSG *)msg; MSG *pMsg = (MSG *)msg;
if (m_acceleratorTable && GetHWND()) if (m_acceleratorTable.Ok())
{ {
wxFrame *parent = (wxFrame *)GetParent(); wxFrame *parent = (wxFrame *)GetParent();
HWND parent_hwnd = (HWND) parent->GetHWND(); 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; return FALSE;
} }

View File

@@ -33,8 +33,11 @@
#include "wx/log.h" #include "wx/log.h"
// Windows headers // Windows headers
/*
#define STRICT #define STRICT
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
*/
#include <windows.h> #include <windows.h>
// other std headers // other std headers

View File

@@ -252,7 +252,7 @@ wxWindow::wxWindow(void)
m_lastMsg = 0; m_lastMsg = 0;
m_lastWParam = 0; m_lastWParam = 0;
m_lastLParam = 0; m_lastLParam = 0;
m_acceleratorTable = 0; // m_acceleratorTable = 0;
m_hMenu = 0; m_hMenu = 0;
m_xThumbSize = 0; m_xThumbSize = 0;
@@ -434,7 +434,7 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID id,
m_lastMsg = 0; m_lastMsg = 0;
m_lastWParam = 0; m_lastWParam = 0;
m_lastLParam = 0; m_lastLParam = 0;
m_acceleratorTable = 0; // m_acceleratorTable = 0;
m_hMenu = 0; m_hMenu = 0;
m_xThumbSize = 0; m_xThumbSize = 0;
@@ -2012,6 +2012,11 @@ bool wxWindow::MSWProcessMessage(WXMSG* pMsg)
return FALSE; return FALSE;
} }
bool wxWindow::MSWTranslateMessage(WXMSG* WXUNUSED(pMsg))
{
return FALSE;
}
long wxWindow::MSWOnMDIActivate(long WXUNUSED(flag), WXHWND WXUNUSED(activate), WXHWND WXUNUSED(deactivate)) long wxWindow::MSWOnMDIActivate(long WXUNUSED(flag), WXHWND WXUNUSED(activate), WXHWND WXUNUSED(deactivate))
{ {
#if WXDEBUG > 1 #if WXDEBUG > 1