1. wxKeyEvent::GetKeyCode() and HasModifiers() added and documented

2. wxGridCellEditor::IsAcceptedKey() added and implemented
3. no changes in other files (but cvs wants to commit them)


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7626 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2000-06-21 09:15:59 +00:00
parent 3ffdc4cfeb
commit 7669ba3c67
6 changed files with 241 additions and 70 deletions

View File

@@ -93,6 +93,14 @@ Returns TRUE if the Alt key was down at the time of the key event.
Returns TRUE if the control key was down at the time of the key event. Returns TRUE if the control key was down at the time of the key event.
\membersection{wxKeyEvent::GetKeyCode}
\constfunc{int}{GetKeyCode}{\void}
Returns the virtual key code. ASCII events return normal ASCII values,
while non-ASCII events return values such as {\bf WXK\_LEFT} for the
left cursor key. See \helpref{Keycodes}{keycodes} for a full list of the virtual key codes.
\membersection{wxKeyEvent::GetX} \membersection{wxKeyEvent::GetX}
\constfunc{long}{GetX}{\void} \constfunc{long}{GetX}{\void}
@@ -105,14 +113,6 @@ Returns the X position of the event.
Returns the Y position of the event. Returns the Y position of the event.
\membersection{wxKeyEvent::KeyCode}
\constfunc{long}{KeyCode}{\void}
Returns the virtual key code. ASCII events return normal ASCII values,
while non-ASCII events return values such as {\bf WXK\_LEFT} for the
left cursor key. See \helpref{Keycodes}{keycodes} for a full list of the virtual key codes.
\membersection{wxKeyEvent::MetaDown} \membersection{wxKeyEvent::MetaDown}
\constfunc{bool}{MetaDown}{\void} \constfunc{bool}{MetaDown}{\void}
@@ -127,6 +127,14 @@ Returns TRUE if the Meta key was down at the time of the key event.
Obtains the position at which the key was pressed. Obtains the position at which the key was pressed.
\membersection{wxKeyEvent::HasModifiers}
\constfunc{bool}{HasModifiers}{\void}
Returns TRUE if either of {\sc Ctrl}, {\sc Alt} or {\sc Meta} keys was down
at the time of the key event. Note that this function does not take into
account the {\sc Shift} key state.
\membersection{wxKeyEvent::ShiftDown} \membersection{wxKeyEvent::ShiftDown}
\constfunc{bool}{ShiftDown}{\void} \constfunc{bool}{ShiftDown}{\void}

View File

@@ -768,7 +768,11 @@ public:
bool MetaDown() const { return m_metaDown; } bool MetaDown() const { return m_metaDown; }
bool AltDown() const { return m_altDown; } bool AltDown() const { return m_altDown; }
bool ShiftDown() const { return m_shiftDown; } bool ShiftDown() const { return m_shiftDown; }
long KeyCode() const { return m_keyCode; }
bool HasModifiers() const { return ControlDown() || AltDown() || MetaDown(); }
// get the key code: an ASCII7 char or an element of wxKeyCode enum
int GetKeyCode() const { return (int)m_keyCode; }
// Find the position of the event // Find the position of the event
void GetPosition(wxCoord *xpos, wxCoord *ypos) const void GetPosition(wxCoord *xpos, wxCoord *ypos) const
@@ -796,6 +800,9 @@ public:
void CopyObject(wxObject& obj) const; void CopyObject(wxObject& obj) const;
// deprecated
long KeyCode() const { return m_keyCode; }
public: public:
wxCoord m_x, m_y; wxCoord m_x, m_y;

View File

@@ -328,9 +328,18 @@ public:
// Reset the value in the control back to its starting value // Reset the value in the control back to its starting value
virtual void Reset() = 0; virtual void Reset() = 0;
// If the editor is enabled by pressing keys on the grid, // return TRUE to allow the given key to start editing: the base class
// this will be called to let the editor do something about // version only checks that the event has no modifiers. The derived
// that first key if desired. // classes are supposed to do "if ( base::IsAcceptedKey() && ... )" in
// their IsAcceptedKey() implementation, although, of course, it is not a
// mandatory requirment.
//
// NB: if the key is F2 (special), editing will always start and this
// method will not be called at all (but StartingKey() will)
virtual bool IsAcceptedKey(wxKeyEvent& event);
// If the editor is enabled by pressing keys on the grid, this will be
// called to let the editor do something about that first key if desired
virtual void StartingKey(wxKeyEvent& event); virtual void StartingKey(wxKeyEvent& event);
// if the editor is enabled by clicking on the cell, this method will be // if the editor is enabled by clicking on the cell, this method will be
@@ -379,6 +388,7 @@ public:
virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr); virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
virtual bool IsAcceptedKey(wxKeyEvent& event);
virtual void BeginEdit(int row, int col, wxGrid* grid); virtual void BeginEdit(int row, int col, wxGrid* grid);
virtual bool EndEdit(int row, int col, wxGrid* grid); virtual bool EndEdit(int row, int col, wxGrid* grid);
@@ -416,6 +426,7 @@ public:
wxWindowID id, wxWindowID id,
wxEvtHandler* evtHandler); wxEvtHandler* evtHandler);
virtual bool IsAcceptedKey(wxKeyEvent& event);
virtual void BeginEdit(int row, int col, wxGrid* grid); virtual void BeginEdit(int row, int col, wxGrid* grid);
virtual bool EndEdit(int row, int col, wxGrid* grid); virtual bool EndEdit(int row, int col, wxGrid* grid);
@@ -455,6 +466,7 @@ public:
wxWindowID id, wxWindowID id,
wxEvtHandler* evtHandler); wxEvtHandler* evtHandler);
virtual bool IsAcceptedKey(wxKeyEvent& event);
virtual void BeginEdit(int row, int col, wxGrid* grid); virtual void BeginEdit(int row, int col, wxGrid* grid);
virtual bool EndEdit(int row, int col, wxGrid* grid); virtual bool EndEdit(int row, int col, wxGrid* grid);
@@ -488,6 +500,7 @@ public:
virtual void SetSize(const wxRect& rect); virtual void SetSize(const wxRect& rect);
virtual void Show(bool show, wxGridCellAttr *attr = (wxGridCellAttr *)NULL); virtual void Show(bool show, wxGridCellAttr *attr = (wxGridCellAttr *)NULL);
virtual bool IsAcceptedKey(wxKeyEvent& event);
virtual void BeginEdit(int row, int col, wxGrid* grid); virtual void BeginEdit(int row, int col, wxGrid* grid);
virtual bool EndEdit(int row, int col, wxGrid* grid); virtual bool EndEdit(int row, int col, wxGrid* grid);

View File

@@ -37,7 +37,7 @@
//#define TEST_ARRAYS //#define TEST_ARRAYS
//#define TEST_CMDLINE //#define TEST_CMDLINE
//#define TEST_DATETIME #define TEST_DATETIME
//#define TEST_DIR //#define TEST_DIR
//#define TEST_DLLLOADER //#define TEST_DLLLOADER
//#define TEST_EXECUTE //#define TEST_EXECUTE
@@ -55,7 +55,7 @@
//#define TEST_TIMER //#define TEST_TIMER
//#define TEST_VCARD //#define TEST_VCARD
//#define TEST_WCHAR //#define TEST_WCHAR
#define TEST_ZIP //#define TEST_ZIP
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// test class for container objects // test class for container objects
@@ -2263,6 +2263,7 @@ static void TestTimeFormat()
{ CompareBoth, "Date is %x, time is %X" }, { CompareBoth, "Date is %x, time is %X" },
{ CompareTime, "Time is %H:%M:%S or %I:%M:%S %p" }, { CompareTime, "Time is %H:%M:%S or %I:%M:%S %p" },
{ CompareNone, "The day of year: %j, the week of year: %W" }, { CompareNone, "The day of year: %j, the week of year: %W" },
{ CompareDate, "ISO date without separators: %4Y%2m%2d" },
}; };
static const Date formatTestDates[] = static const Date formatTestDates[] =
@@ -3462,13 +3463,13 @@ int main(int argc, char **argv)
TestTimeWDays(); TestTimeWDays();
TestTimeWNumber(); TestTimeWNumber();
TestTimeParse(); TestTimeParse();
TestTimeFormat();
TestTimeArithmetics(); TestTimeArithmetics();
TestTimeHolidays(); TestTimeHolidays();
TestTimeZoneBug(); TestTimeZoneBug();
} }
if ( 1 ) TestTimeFormat();
if ( 0 )
TestInteractive(); TestInteractive();
#endif // TEST_DATETIME #endif // TEST_DATETIME

View File

@@ -109,6 +109,7 @@ bool wxBMPHandler::SaveFile(wxImage *image,
if (// VS: looks ugly but compilers tend to do ugly things with structs, if (// VS: looks ugly but compilers tend to do ugly things with structs,
// like aligning hdr.filesize's ofset to dword :( // like aligning hdr.filesize's ofset to dword :(
// VZ: we should add padding then...
!stream.Write(&hdr.magic, 2) || !stream.Write(&hdr.magic, 2) ||
!stream.Write(&hdr.filesize, 4) || !stream.Write(&hdr.filesize, 4) ||
!stream.Write(&hdr.reserved, 4) || !stream.Write(&hdr.reserved, 4) ||

View File

@@ -471,6 +471,11 @@ void wxGridCellEditor::HandleReturn(wxKeyEvent& event)
event.Skip(); event.Skip();
} }
bool wxGridCellEditor::IsAcceptedKey(wxKeyEvent& event)
{
// accept the simple key presses, not anything with Ctrl/Alt/Meta
return !event.HasModifiers();
}
void wxGridCellEditor::StartingKey(wxKeyEvent& event) void wxGridCellEditor::StartingKey(wxKeyEvent& event)
{ {
@@ -599,13 +604,51 @@ void wxGridCellTextEditor::DoReset(const wxString& startValue)
Text()->SetInsertionPointEnd(); Text()->SetInsertionPointEnd();
} }
bool wxGridCellTextEditor::IsAcceptedKey(wxKeyEvent& event)
{
if ( wxGridCellEditor::IsAcceptedKey(event) )
{
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:
case WXK_MULTIPLY:
case WXK_NUMPAD_MULTIPLY:
case WXK_ADD:
case WXK_NUMPAD_ADD:
case WXK_SUBTRACT:
case WXK_NUMPAD_SUBTRACT:
case WXK_DECIMAL:
case WXK_NUMPAD_DECIMAL:
case WXK_DIVIDE:
case WXK_NUMPAD_DIVIDE:
return TRUE;
default:
if ( isprint(keycode) )
return TRUE;
}
}
return FALSE;
}
void wxGridCellTextEditor::StartingKey(wxKeyEvent& event) void wxGridCellTextEditor::StartingKey(wxKeyEvent& event)
{ {
if ( !event.AltDown() && !event.MetaDown() && !event.ControlDown() ) // we don't check for !HasModifiers() because IsAcceptedKey() did it
{
// insert the key in the control // insert the key in the control
wxChar ch; wxChar ch;
int keycode = (int)event.KeyCode(); int keycode = event.GetKeyCode();
switch ( keycode ) switch ( keycode )
{ {
case WXK_NUMPAD0: case WXK_NUMPAD0:
@@ -666,13 +709,11 @@ void wxGridCellTextEditor::StartingKey(wxKeyEvent& event)
if ( ch ) if ( ch )
{ {
Text()->AppendText(ch); Text()->AppendText(ch);
// skip event.Skip() below
return;
} }
} else
{
event.Skip(); event.Skip();
}
} }
void wxGridCellTextEditor::HandleReturn( wxKeyEvent& void wxGridCellTextEditor::HandleReturn( wxKeyEvent&
@@ -816,6 +857,40 @@ void wxGridCellNumberEditor::Reset()
} }
} }
bool wxGridCellNumberEditor::IsAcceptedKey(wxKeyEvent& event)
{
if ( wxGridCellEditor::IsAcceptedKey(event) )
{
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:
case WXK_ADD:
case WXK_NUMPAD_ADD:
case WXK_SUBTRACT:
case WXK_NUMPAD_SUBTRACT:
case WXK_UP:
case WXK_DOWN:
return TRUE;
default:
if ( isdigit(keycode) )
return TRUE;
}
}
return FALSE;
}
void wxGridCellNumberEditor::StartingKey(wxKeyEvent& event) void wxGridCellNumberEditor::StartingKey(wxKeyEvent& event)
{ {
if ( !HasRange() ) if ( !HasRange() )
@@ -991,6 +1066,41 @@ wxString wxGridCellFloatEditor::GetString() const
return wxString::Format(fmt, m_valueOld); return wxString::Format(fmt, m_valueOld);
} }
bool wxGridCellFloatEditor::IsAcceptedKey(wxKeyEvent& event)
{
if ( wxGridCellEditor::IsAcceptedKey(event) )
{
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:
case WXK_ADD:
case WXK_NUMPAD_ADD:
case WXK_SUBTRACT:
case WXK_NUMPAD_SUBTRACT:
case WXK_DECIMAL:
case WXK_NUMPAD_DECIMAL:
return TRUE;
default:
// additionally accept 'e' as in '1e+6'
if ( isdigit(keycode) || tolower(keycode) == 'e' )
return TRUE;
}
}
return FALSE;
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxGridCellBoolEditor // wxGridCellBoolEditor
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -1109,6 +1219,29 @@ void wxGridCellBoolEditor::StartingClick()
CBox()->SetValue(!CBox()->GetValue()); CBox()->SetValue(!CBox()->GetValue());
} }
bool wxGridCellBoolEditor::IsAcceptedKey(wxKeyEvent& event)
{
if ( wxGridCellEditor::IsAcceptedKey(event) )
{
int keycode = event.GetKeyCode();
switch ( keycode )
{
case WXK_MULTIPLY:
case WXK_NUMPAD_MULTIPLY:
case WXK_ADD:
case WXK_NUMPAD_ADD:
case WXK_SUBTRACT:
case WXK_NUMPAD_SUBTRACT:
case WXK_SPACE:
case '+':
case '-':
return TRUE;
}
}
return FALSE;
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxGridCellChoiceEditor // wxGridCellChoiceEditor
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -5365,20 +5498,28 @@ void wxGrid::OnKeyDown( wxKeyEvent& event )
// Otherwise fall through to default // Otherwise fall through to default
default: default:
// alphanumeric keys or F2 (special key just for this) enable // is it possible to edit the current cell at all?
// the cell edit control if ( !IsCellEditControlEnabled() && CanEnableCellControl() )
if ( !(event.AltDown() ||
event.MetaDown() ||
event.ControlDown()) &&
!IsCellEditControlEnabled() &&
CanEnableCellControl() )
{ {
EnableCellEditControl(); // yes, now check whether the cells editor accepts the key
int row = m_currentCellCoords.GetRow(); int row = m_currentCellCoords.GetRow();
int col = m_currentCellCoords.GetCol(); int col = m_currentCellCoords.GetCol();
wxGridCellAttr* attr = GetCellAttr(row, col); wxGridCellAttr* attr = GetCellAttr(row, col);
wxGridCellEditor *editor = attr->GetEditor(this, row, col); wxGridCellEditor *editor = attr->GetEditor(this, row, col);
// <F2> is special and will always start editing, for
// other keys - ask the editor itself
if ( (event.KeyCode() == WXK_F2 && !event.HasModifiers())
|| editor->IsAcceptedKey(event) )
{
EnableCellEditControl();
editor->StartingKey(event); editor->StartingKey(event);
}
else
{
event.Skip();
}
editor->DecRef(); editor->DecRef();
attr->DecRef(); attr->DecRef();
} }