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 WXHCURSOR;
typedef unsigned long WXHRGN;
typedef unsigned long WXHACCEL;
typedef unsigned long WXHINSTANCE;
typedef unsigned long WXHBITMAP;
typedef unsigned long WXHIMAGELIST;

View File

@ -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()
};

View File

@ -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

View File

@ -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;

View File

@ -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) )

View File

@ -1,3 +1,6 @@
mondrian ICON "mondrian.ico"
#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;
// 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))
{
wxWindow *wnd = wxFindWinFromHandle((WXHWND) hWnd);
@ -765,18 +777,9 @@ bool wxApp::ProcessMessage(WXMSG *Msg)
{
if (wnd->MSWProcessMessage(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;
return FALSE;
}
void wxApp::OnIdle(wxIdleEvent& event)

View File

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

View File

@ -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;

View File

@ -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)

View File

@ -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)

View File

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

View File

@ -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$@

View File

@ -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;
}

View File

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

View File

@ -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