TLW default item changes have changed Enter key processing: it was now handled as TAB even for controls such as wxTree/ListCtrl which need it themselves; fix this by checking for VK_RETURN in these classes MSWShouldPreProcessMessage() implementation; also removed specific test for wxTextCtrl in wxWindowMSW::MSWProcessMessage() and simplified its code

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40405 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2006-07-31 22:06:24 +00:00
parent 955e46d25d
commit 90c6edd706
6 changed files with 66 additions and 53 deletions

View File

@@ -346,6 +346,7 @@ public:
// IMPLEMENTATION
virtual bool MSWCommand(WXUINT param, WXWORD id);
virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
virtual bool MSWShouldPreProcessMessage(WXMSG* msg);
// bring the control in sync with current m_windowStyle value
void UpdateStyle();

View File

@@ -224,6 +224,7 @@ public:
virtual WXLRESULT MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
virtual bool MSWCommand(WXUINT param, WXWORD id);
virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
virtual bool MSWShouldPreProcessMessage(WXMSG* msg);
// override some base class virtuals
virtual bool SetBackgroundColour(const wxColour &colour);

View File

@@ -1763,6 +1763,20 @@ bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data)
// message processing
// ----------------------------------------------------------------------------
bool wxListCtrl::MSWShouldPreProcessMessage(WXMSG* msg)
{
if ( msg->message == WM_KEYDOWN )
{
if ( msg->wParam == VK_RETURN )
{
// we need VK_RETURN to generate wxEVT_COMMAND_LIST_ITEM_ACTIVATED
return false;
}
}
return wxControl::MSWShouldPreProcessMessage(msg);
}
bool wxListCtrl::MSWCommand(WXUINT cmd, WXWORD id)
{
if (cmd == EN_UPDATE)

View File

@@ -1784,18 +1784,17 @@ void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event)
// kbd input processing
// ----------------------------------------------------------------------------
bool wxTextCtrl::MSWShouldPreProcessMessage(WXMSG* pMsg)
bool wxTextCtrl::MSWShouldPreProcessMessage(WXMSG* msg)
{
MSG *msg = (MSG *)pMsg;
// check for our special keys here: if we don't do it and the parent frame
// uses them as accelerators, they wouldn't work at all, so we disable
// usual preprocessing for them
if ( msg->message == WM_KEYDOWN )
{
WORD vkey = (WORD) msg->wParam;
if ( (HIWORD(msg->lParam) & KF_ALTDOWN) == KF_ALTDOWN )
const WPARAM vkey = msg->wParam;
if ( HIWORD(msg->lParam) & KF_ALTDOWN )
{
// Alt-Backspace is accelerator for "Undo"
if ( vkey == VK_BACK )
return false;
}
@@ -1813,6 +1812,9 @@ bool wxTextCtrl::MSWShouldPreProcessMessage(WXMSG* pMsg)
// fall through
case 0:
if ( vkey == VK_RETURN )
return false;
// fall through
case 2:
break;
@@ -1841,7 +1843,7 @@ bool wxTextCtrl::MSWShouldPreProcessMessage(WXMSG* pMsg)
}
}
return wxControl::MSWShouldPreProcessMessage(pMsg);
return wxControl::MSWShouldPreProcessMessage(msg);
}
void wxTextCtrl::OnChar(wxKeyEvent& event)

View File

@@ -1985,6 +1985,20 @@ void wxTreeCtrl::SortChildren(const wxTreeItemId& item)
// implementation
// ----------------------------------------------------------------------------
bool wxTreeCtrl::MSWShouldPreProcessMessage(WXMSG* msg)
{
if ( msg->message == WM_KEYDOWN )
{
if ( msg->wParam == VK_RETURN )
{
// we need VK_RETURN to generate wxEVT_COMMAND_TREE_ITEM_ACTIVATED
return false;
}
}
return wxTreeCtrlBase::MSWShouldPreProcessMessage(msg);
}
bool wxTreeCtrl::MSWCommand(WXUINT cmd, WXWORD id)
{
if ( cmd == EN_UPDATE )

View File

@@ -2119,13 +2119,15 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
if ( (lDlgCode & DLGC_WANTMESSAGE) && !bCtrlDown )
{
// control wants to process Enter itself, don't
// call IsDialogMessage() which would interpret
// it
// call IsDialogMessage() which would consume it
return false;
}
#if wxUSE_BUTTON
// currently active button should get enter press even
// if there is a default button elsewhere
// if there is a default button elsewhere so check if
// this window is a button first
wxWindow *btn = NULL;
if ( lDlgCode & DLGC_DEFPUSHBUTTON )
{
// let IsDialogMessage() handle this for all
@@ -2135,59 +2137,38 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
if ( (style & BS_OWNERDRAW) == BS_OWNERDRAW )
{
// emulate the button click
wxWindow *
btn = wxFindWinFromHandle((WXHWND)msg->hwnd);
if ( btn )
btn->MSWCommand(BN_CLICKED, 0 /* unused */);
btn = wxFindWinFromHandle((WXHWND)msg->hwnd);
}
bProcess = false;
}
else // not a button itself
else // not a button itself, do we have default button?
{
#if wxUSE_BUTTON
wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
wxTopLevelWindow *
tlw = wxDynamicCast(wxGetTopLevelParent(this),
wxTopLevelWindow);
if ( tlw )
{
wxButton *btn = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
if ( btn && btn->IsEnabled() )
{
// if we do have a default button, do press it
btn->MSWCommand(BN_CLICKED, 0 /* unused */);
return true;
}
}
else // no default button
#endif // wxUSE_BUTTON
{
#ifdef __WXWINCE__
wxJoystickEvent event(wxEVT_JOY_BUTTON_DOWN);
event.SetEventObject(this);
if(GetEventHandler()->ProcessEvent(event))
return true;
#endif
// this is a quick and dirty test for a text
// control
if ( !(lDlgCode & DLGC_HASSETSEL) )
{
// don't process Enter, the control might
// need it for itself and don't let
// ::IsDialogMessage() have it as it can
// eat the Enter events sometimes
return false;
}
else if (!IsTopLevel())
{
// if not a top level window, let parent
// handle it
return false;
}
//else: treat Enter as TAB: pass to the next
// control as this is the best thing to do
// if the text doesn't handle Enter itself
btn = wxDynamicCast(tlw->GetDefaultItem(),
wxButton);
}
}
if ( btn && btn->IsEnabled() )
{
btn->MSWCommand(BN_CLICKED, 0 /* unused */);
return true;
}
#endif // wxUSE_BUTTON
#ifdef __WXWINCE__
// map Enter presses into button presses on PDAs
wxJoystickEvent event(wxEVT_JOY_BUTTON_DOWN);
event.SetEventObject(this);
if ( GetEventHandler()->ProcessEvent(event) )
return true;
#endif // __WXWINCE__
}
break;