added wxTextCtrl::EmulateKeyPress
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15005 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -143,6 +143,7 @@ All (GUI):
|
|||||||
- added wxImage::FloodFill and implemented wxWindowDC::DoFloodFill method
|
- added wxImage::FloodFill and implemented wxWindowDC::DoFloodFill method
|
||||||
for GTK+, Mac, MGL, X11, Motif ports (Chris Elliott)
|
for GTK+, Mac, MGL, X11, Motif ports (Chris Elliott)
|
||||||
- added (platform-dependent) scan code to wxKeyEvent (Bryce Denney)
|
- added (platform-dependent) scan code to wxKeyEvent (Bryce Denney)
|
||||||
|
- added wxTextCtrl::EmulateKeyPress()
|
||||||
|
|
||||||
wxMSW:
|
wxMSW:
|
||||||
|
|
||||||
|
@@ -395,6 +395,20 @@ Copies the selected text to the clipboard and removes the selection.
|
|||||||
|
|
||||||
Resets the internal `modified' flag as if the current edits had been saved.
|
Resets the internal `modified' flag as if the current edits had been saved.
|
||||||
|
|
||||||
|
\membersection{wxTextCtrl::EmulateKeyPress}
|
||||||
|
|
||||||
|
\func{bool}{EmulateKeyPress}{\param{const wxKeyEvent\& }{event}}
|
||||||
|
|
||||||
|
This functions inserts into the control the character which would have been
|
||||||
|
inserted if the given key event had occured in the text control. The
|
||||||
|
{\it event} object should be the same as the one passed to {\tt EVT\_KEY\_DOWN}
|
||||||
|
handler previously by wxWindows.
|
||||||
|
|
||||||
|
\wxheading{Return value}
|
||||||
|
|
||||||
|
{\tt TRUE} if the event resulted in a change to the control, {\tt FALSE}
|
||||||
|
otherwise.
|
||||||
|
|
||||||
\membersection{wxTextCtrl::GetDefaultStyle}\label{wxtextctrlgetdefaultstyle}
|
\membersection{wxTextCtrl::GetDefaultStyle}\label{wxtextctrlgetdefaultstyle}
|
||||||
|
|
||||||
\constfunc{const wxTextAttr\& }{GetDefaultStyle}{\void}
|
\constfunc{const wxTextAttr\& }{GetDefaultStyle}{\void}
|
||||||
|
@@ -82,6 +82,10 @@ public:
|
|||||||
virtual void WriteText(const wxString& text);
|
virtual void WriteText(const wxString& text);
|
||||||
virtual void AppendText(const wxString& text);
|
virtual void AppendText(const wxString& text);
|
||||||
|
|
||||||
|
#ifdef __WIN32__
|
||||||
|
virtual bool EmulateKeyPress(const wxKeyEvent& event);
|
||||||
|
#endif // __WIN32__
|
||||||
|
|
||||||
#if wxUSE_RICHEDIT
|
#if wxUSE_RICHEDIT
|
||||||
// apply text attribute to the range of text (only works with richedit
|
// apply text attribute to the range of text (only works with richedit
|
||||||
// controls)
|
// controls)
|
||||||
|
@@ -203,6 +203,10 @@ public:
|
|||||||
virtual void WriteText(const wxString& text) = 0;
|
virtual void WriteText(const wxString& text) = 0;
|
||||||
virtual void AppendText(const wxString& text) = 0;
|
virtual void AppendText(const wxString& text) = 0;
|
||||||
|
|
||||||
|
// insert the character which would have resulted from this key event,
|
||||||
|
// return TRUE if anything has been inserted
|
||||||
|
virtual bool EmulateKeyPress(const wxKeyEvent& event);
|
||||||
|
|
||||||
// text control under some platforms supports the text styles: these
|
// text control under some platforms supports the text styles: these
|
||||||
// methods allow to apply the given text style to the given selection or to
|
// methods allow to apply the given text style to the given selection or to
|
||||||
// set/get the style which will be used for all appended text
|
// set/get the style which will be used for all appended text
|
||||||
|
@@ -277,6 +277,84 @@ bool wxTextCtrlBase::CanPaste() const
|
|||||||
return IsEditable();
|
return IsEditable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// emulating key presses
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool wxTextCtrlBase::EmulateKeyPress(const wxKeyEvent& event)
|
||||||
|
{
|
||||||
|
// the generic version is unused in wxMSW
|
||||||
|
#ifndef __WIN32__
|
||||||
|
wxChar ch;
|
||||||
|
int keycode = event.GetKeyCode();
|
||||||
|
switch ( keycode )
|
||||||
|
{
|
||||||
|
case WXK_NUMPAD0:
|
||||||
|
case WXK_NUMPAD1:
|
||||||
|
case WXK_NUMPAD2:
|
||||||
|
case WXK_NUMPAD3:
|
||||||
|
case WXK_NUMPAD4:
|
||||||
|
case WXK_NUMPAD5:
|
||||||
|
case WXK_NUMPAD6:
|
||||||
|
case WXK_NUMPAD7:
|
||||||
|
case WXK_NUMPAD8:
|
||||||
|
case WXK_NUMPAD9:
|
||||||
|
ch = _T('0') + keycode - WXK_NUMPAD0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WXK_MULTIPLY:
|
||||||
|
case WXK_NUMPAD_MULTIPLY:
|
||||||
|
ch = _T('*');
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WXK_ADD:
|
||||||
|
case WXK_NUMPAD_ADD:
|
||||||
|
ch = _T('+');
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WXK_SUBTRACT:
|
||||||
|
case WXK_NUMPAD_SUBTRACT:
|
||||||
|
ch = _T('-');
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WXK_DECIMAL:
|
||||||
|
case WXK_NUMPAD_DECIMAL:
|
||||||
|
ch = _T('.');
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WXK_DIVIDE:
|
||||||
|
case WXK_NUMPAD_DIVIDE:
|
||||||
|
ch = _T('/');
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
if ( keycode < 256 && keycode >= 0 && isprint(keycode) )
|
||||||
|
{
|
||||||
|
// FIXME this is not going to work for non letters...
|
||||||
|
if ( !event.ShiftDown() )
|
||||||
|
{
|
||||||
|
keycode = tolower(keycode);
|
||||||
|
}
|
||||||
|
|
||||||
|
ch = (wxChar)keycode;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ch = _T('\0');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ch )
|
||||||
|
{
|
||||||
|
WriteText(ch);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
#endif // !__WIN32__
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// selection and ranges
|
// selection and ranges
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -708,73 +708,7 @@ bool wxGridCellTextEditor::IsAcceptedKey(wxKeyEvent& event)
|
|||||||
|
|
||||||
void wxGridCellTextEditor::StartingKey(wxKeyEvent& event)
|
void wxGridCellTextEditor::StartingKey(wxKeyEvent& event)
|
||||||
{
|
{
|
||||||
// we don't check for !HasModifiers() because IsAcceptedKey() did it
|
if ( !Text()->EmulateKeyPress(event) )
|
||||||
|
|
||||||
// insert the key in the control
|
|
||||||
wxChar ch;
|
|
||||||
int keycode = event.GetKeyCode();
|
|
||||||
switch ( keycode )
|
|
||||||
{
|
|
||||||
case WXK_NUMPAD0:
|
|
||||||
case WXK_NUMPAD1:
|
|
||||||
case WXK_NUMPAD2:
|
|
||||||
case WXK_NUMPAD3:
|
|
||||||
case WXK_NUMPAD4:
|
|
||||||
case WXK_NUMPAD5:
|
|
||||||
case WXK_NUMPAD6:
|
|
||||||
case WXK_NUMPAD7:
|
|
||||||
case WXK_NUMPAD8:
|
|
||||||
case WXK_NUMPAD9:
|
|
||||||
ch = _T('0') + keycode - WXK_NUMPAD0;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WXK_MULTIPLY:
|
|
||||||
case WXK_NUMPAD_MULTIPLY:
|
|
||||||
ch = _T('*');
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WXK_ADD:
|
|
||||||
case WXK_NUMPAD_ADD:
|
|
||||||
ch = _T('+');
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WXK_SUBTRACT:
|
|
||||||
case WXK_NUMPAD_SUBTRACT:
|
|
||||||
ch = _T('-');
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WXK_DECIMAL:
|
|
||||||
case WXK_NUMPAD_DECIMAL:
|
|
||||||
ch = _T('.');
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WXK_DIVIDE:
|
|
||||||
case WXK_NUMPAD_DIVIDE:
|
|
||||||
ch = _T('/');
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
if ( keycode < 256 && keycode >= 0 && isprint(keycode) )
|
|
||||||
{
|
|
||||||
// FIXME this is not going to work for non letters...
|
|
||||||
if ( !event.ShiftDown() )
|
|
||||||
{
|
|
||||||
keycode = tolower(keycode);
|
|
||||||
}
|
|
||||||
|
|
||||||
ch = (wxChar)keycode;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ch = _T('\0');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ch )
|
|
||||||
{
|
|
||||||
Text()->AppendText(ch);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
event.Skip();
|
event.Skip();
|
||||||
}
|
}
|
||||||
|
@@ -692,6 +692,25 @@ void wxTextCtrl::Clear()
|
|||||||
::SetWindowText(GetHwnd(), wxT(""));
|
::SetWindowText(GetHwnd(), wxT(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __WIN32__
|
||||||
|
|
||||||
|
bool wxTextCtrl::EmulateKeyPress(const wxKeyEvent& event)
|
||||||
|
{
|
||||||
|
SetFocus();
|
||||||
|
|
||||||
|
size_t lenOld = GetValue().length();
|
||||||
|
|
||||||
|
wxUint32 code = event.GetRawKeyCode();
|
||||||
|
::keybd_event(code, 0, 0 /* key press */, NULL);
|
||||||
|
::keybd_event(code, 0, KEYEVENTF_KEYUP, NULL);
|
||||||
|
|
||||||
|
// assume that any alphanumeric key changes the total number of characters
|
||||||
|
// in the control - this should work in 99% of cases
|
||||||
|
return GetValue().length() != lenOld;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // __WIN32__
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Clipboard operations
|
// Clipboard operations
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user