Improve wxTE_PROCESS_ENTER handling in wxUniv
This commit is contained in:
@@ -36,6 +36,7 @@ class WXDLLIMPEXP_FWD_CORE wxTextCtrlCommandProcessor;
|
|||||||
#define wxACTION_TEXT_WORD_RIGHT wxT("wordright")
|
#define wxACTION_TEXT_WORD_RIGHT wxT("wordright")
|
||||||
#define wxACTION_TEXT_PAGE_UP wxT("pageup")
|
#define wxACTION_TEXT_PAGE_UP wxT("pageup")
|
||||||
#define wxACTION_TEXT_PAGE_DOWN wxT("pagedown")
|
#define wxACTION_TEXT_PAGE_DOWN wxT("pagedown")
|
||||||
|
#define wxACTION_TEXT_RETURN wxT("return")
|
||||||
|
|
||||||
// clipboard operations
|
// clipboard operations
|
||||||
#define wxACTION_TEXT_COPY wxT("copy")
|
#define wxACTION_TEXT_COPY wxT("copy")
|
||||||
@@ -451,6 +452,8 @@ protected:
|
|||||||
bool DoCut();
|
bool DoCut();
|
||||||
bool DoPaste();
|
bool DoPaste();
|
||||||
|
|
||||||
|
bool ClickDefaultButtonIfPossible();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// all these methods are for multiline text controls only
|
// all these methods are for multiline text controls only
|
||||||
|
|
||||||
|
@@ -96,8 +96,12 @@ void wxDialog::OnOK(wxCommandEvent &WXUNUSED(event))
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SetReturnCode(wxID_OK);
|
// don't change return code from event char if it was set earlier
|
||||||
Show(false);
|
if (GetReturnCode() == 0)
|
||||||
|
{
|
||||||
|
SetReturnCode(wxID_OK);
|
||||||
|
Show(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4676,6 +4676,15 @@ bool wxTextCtrl::PerformAction(const wxControlAction& actionOrig,
|
|||||||
if ( CanRedo() )
|
if ( CanRedo() )
|
||||||
Redo();
|
Redo();
|
||||||
}
|
}
|
||||||
|
else if ( action == wxACTION_TEXT_RETURN )
|
||||||
|
{
|
||||||
|
// activate default button
|
||||||
|
if ( !HasFlag(wxTE_PROCESS_ENTER) && !HasFlag(wxTE_MULTILINE) )
|
||||||
|
{
|
||||||
|
return ClickDefaultButtonIfPossible();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return wxControl::PerformAction(action, numArg, strArg);
|
return wxControl::PerformAction(action, numArg, strArg);
|
||||||
@@ -4768,13 +4777,18 @@ void wxTextCtrl::OnChar(wxKeyEvent& event)
|
|||||||
#endif
|
#endif
|
||||||
if ( keycode == WXK_RETURN )
|
if ( keycode == WXK_RETURN )
|
||||||
{
|
{
|
||||||
if ( IsSingleLine() || (GetWindowStyle() & wxTE_PROCESS_ENTER) )
|
if ( (GetWindowStyle() & wxTE_PROCESS_ENTER) )
|
||||||
{
|
{
|
||||||
wxCommandEvent event(wxEVT_TEXT_ENTER, GetId());
|
wxCommandEvent event(wxEVT_TEXT_ENTER, GetId());
|
||||||
InitCommandEvent(event);
|
InitCommandEvent(event);
|
||||||
event.SetString(GetValue());
|
event.SetString(GetValue());
|
||||||
GetEventHandler()->ProcessEvent(event);
|
GetEventHandler()->ProcessEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( IsSingleLine() )
|
||||||
|
{
|
||||||
|
ClickDefaultButtonIfPossible();
|
||||||
|
}
|
||||||
else // interpret <Enter> normally: insert new line
|
else // interpret <Enter> normally: insert new line
|
||||||
{
|
{
|
||||||
PerformAction(wxACTION_TEXT_INSERT, -1, wxT('\n'));
|
PerformAction(wxACTION_TEXT_INSERT, -1, wxT('\n'));
|
||||||
@@ -4805,6 +4819,23 @@ void wxTextCtrl::OnChar(wxKeyEvent& event)
|
|||||||
event.Skip();
|
event.Skip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxTextCtrl::ClickDefaultButtonIfPossible()
|
||||||
|
{
|
||||||
|
wxTopLevelWindow* tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
|
||||||
|
if ( tlw )
|
||||||
|
{
|
||||||
|
wxButton* btn = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
|
||||||
|
if ( btn )
|
||||||
|
{
|
||||||
|
wxCommandEvent evt(wxEVT_BUTTON, btn->GetId());
|
||||||
|
evt.SetEventObject(btn);
|
||||||
|
btn->Command(evt);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
wxInputHandler *wxTextCtrl::GetStdInputHandler(wxInputHandler *handlerDef)
|
wxInputHandler *wxTextCtrl::GetStdInputHandler(wxInputHandler *handlerDef)
|
||||||
{
|
{
|
||||||
@@ -4922,6 +4953,9 @@ bool wxStdTextCtrlInputHandler::HandleKey(wxInputConsumer *consumer,
|
|||||||
action << wxACTION_TEXT_PREFIX_DEL << wxACTION_TEXT_LEFT;
|
action << wxACTION_TEXT_PREFIX_DEL << wxACTION_TEXT_LEFT;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case WXK_RETURN:
|
||||||
|
action << wxACTION_TEXT_RETURN;
|
||||||
|
break;
|
||||||
// something else
|
// something else
|
||||||
default:
|
default:
|
||||||
// reset the action as it could be already set to one of the
|
// reset the action as it could be already set to one of the
|
||||||
@@ -4957,7 +4991,11 @@ bool wxStdTextCtrlInputHandler::HandleKey(wxInputConsumer *consumer,
|
|||||||
|
|
||||||
if ( (action != wxACTION_NONE) && (action != wxACTION_TEXT_PREFIX_SEL) )
|
if ( (action != wxACTION_NONE) && (action != wxACTION_TEXT_PREFIX_SEL) )
|
||||||
{
|
{
|
||||||
consumer->PerformAction(action, -1, str);
|
bool result = consumer->PerformAction(action, -1, str);
|
||||||
|
if ( !result && action == wxACTION_TEXT_RETURN )
|
||||||
|
{
|
||||||
|
return wxStdInputHandler::HandleKey(consumer, event, pressed);
|
||||||
|
}
|
||||||
|
|
||||||
// the key down of WXK_UP/DOWN and WXK_PAGEUP/DOWN
|
// the key down of WXK_UP/DOWN and WXK_PAGEUP/DOWN
|
||||||
// must generate a wxEVT_TEXT event. For the controls
|
// must generate a wxEVT_TEXT event. For the controls
|
||||||
|
Reference in New Issue
Block a user