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:
@@ -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.
|
||||
|
||||
\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}
|
||||
|
||||
\constfunc{long}{GetX}{\void}
|
||||
@@ -105,14 +113,6 @@ Returns the X 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}
|
||||
|
||||
\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.
|
||||
|
||||
\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}
|
||||
|
||||
\constfunc{bool}{ShiftDown}{\void}
|
||||
|
@@ -768,7 +768,11 @@ public:
|
||||
bool MetaDown() const { return m_metaDown; }
|
||||
bool AltDown() const { return m_altDown; }
|
||||
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
|
||||
void GetPosition(wxCoord *xpos, wxCoord *ypos) const
|
||||
@@ -796,6 +800,9 @@ public:
|
||||
|
||||
void CopyObject(wxObject& obj) const;
|
||||
|
||||
// deprecated
|
||||
long KeyCode() const { return m_keyCode; }
|
||||
|
||||
public:
|
||||
wxCoord m_x, m_y;
|
||||
|
||||
|
@@ -328,9 +328,18 @@ public:
|
||||
// Reset the value in the control back to its starting value
|
||||
virtual void Reset() = 0;
|
||||
|
||||
// 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.
|
||||
// return TRUE to allow the given key to start editing: the base class
|
||||
// version only checks that the event has no modifiers. The derived
|
||||
// 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);
|
||||
|
||||
// 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 bool IsAcceptedKey(wxKeyEvent& event);
|
||||
virtual void BeginEdit(int row, int col, wxGrid* grid);
|
||||
virtual bool EndEdit(int row, int col, wxGrid* grid);
|
||||
|
||||
@@ -416,6 +426,7 @@ public:
|
||||
wxWindowID id,
|
||||
wxEvtHandler* evtHandler);
|
||||
|
||||
virtual bool IsAcceptedKey(wxKeyEvent& event);
|
||||
virtual void BeginEdit(int row, int col, wxGrid* grid);
|
||||
virtual bool EndEdit(int row, int col, wxGrid* grid);
|
||||
|
||||
@@ -455,6 +466,7 @@ public:
|
||||
wxWindowID id,
|
||||
wxEvtHandler* evtHandler);
|
||||
|
||||
virtual bool IsAcceptedKey(wxKeyEvent& event);
|
||||
virtual void BeginEdit(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 Show(bool show, wxGridCellAttr *attr = (wxGridCellAttr *)NULL);
|
||||
|
||||
virtual bool IsAcceptedKey(wxKeyEvent& event);
|
||||
virtual void BeginEdit(int row, int col, wxGrid* grid);
|
||||
virtual bool EndEdit(int row, int col, wxGrid* grid);
|
||||
|
||||
|
@@ -37,7 +37,7 @@
|
||||
|
||||
//#define TEST_ARRAYS
|
||||
//#define TEST_CMDLINE
|
||||
//#define TEST_DATETIME
|
||||
#define TEST_DATETIME
|
||||
//#define TEST_DIR
|
||||
//#define TEST_DLLLOADER
|
||||
//#define TEST_EXECUTE
|
||||
@@ -55,7 +55,7 @@
|
||||
//#define TEST_TIMER
|
||||
//#define TEST_VCARD
|
||||
//#define TEST_WCHAR
|
||||
#define TEST_ZIP
|
||||
//#define TEST_ZIP
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test class for container objects
|
||||
@@ -2263,6 +2263,7 @@ static void TestTimeFormat()
|
||||
{ CompareBoth, "Date is %x, time is %X" },
|
||||
{ CompareTime, "Time is %H:%M:%S or %I:%M:%S %p" },
|
||||
{ CompareNone, "The day of year: %j, the week of year: %W" },
|
||||
{ CompareDate, "ISO date without separators: %4Y%2m%2d" },
|
||||
};
|
||||
|
||||
static const Date formatTestDates[] =
|
||||
@@ -3462,13 +3463,13 @@ int main(int argc, char **argv)
|
||||
TestTimeWDays();
|
||||
TestTimeWNumber();
|
||||
TestTimeParse();
|
||||
TestTimeFormat();
|
||||
TestTimeArithmetics();
|
||||
TestTimeHolidays();
|
||||
|
||||
TestTimeZoneBug();
|
||||
}
|
||||
if ( 1 )
|
||||
TestTimeFormat();
|
||||
if ( 0 )
|
||||
TestInteractive();
|
||||
#endif // TEST_DATETIME
|
||||
|
||||
|
@@ -109,6 +109,7 @@ bool wxBMPHandler::SaveFile(wxImage *image,
|
||||
|
||||
if (// VS: looks ugly but compilers tend to do ugly things with structs,
|
||||
// like aligning hdr.filesize's ofset to dword :(
|
||||
// VZ: we should add padding then...
|
||||
!stream.Write(&hdr.magic, 2) ||
|
||||
!stream.Write(&hdr.filesize, 4) ||
|
||||
!stream.Write(&hdr.reserved, 4) ||
|
||||
|
@@ -471,6 +471,11 @@ void wxGridCellEditor::HandleReturn(wxKeyEvent& event)
|
||||
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)
|
||||
{
|
||||
@@ -599,13 +604,51 @@ void wxGridCellTextEditor::DoReset(const wxString& startValue)
|
||||
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)
|
||||
{
|
||||
if ( !event.AltDown() && !event.MetaDown() && !event.ControlDown() )
|
||||
{
|
||||
// we don't check for !HasModifiers() because IsAcceptedKey() did it
|
||||
|
||||
// insert the key in the control
|
||||
wxChar ch;
|
||||
int keycode = (int)event.KeyCode();
|
||||
int keycode = event.GetKeyCode();
|
||||
switch ( keycode )
|
||||
{
|
||||
case WXK_NUMPAD0:
|
||||
@@ -666,13 +709,11 @@ void wxGridCellTextEditor::StartingKey(wxKeyEvent& event)
|
||||
if ( ch )
|
||||
{
|
||||
Text()->AppendText(ch);
|
||||
|
||||
// skip event.Skip() below
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
event.Skip();
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if ( !HasRange() )
|
||||
@@ -991,6 +1066,41 @@ wxString wxGridCellFloatEditor::GetString() const
|
||||
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
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -1109,6 +1219,29 @@ void wxGridCellBoolEditor::StartingClick()
|
||||
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
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -5365,20 +5498,28 @@ void wxGrid::OnKeyDown( wxKeyEvent& event )
|
||||
// Otherwise fall through to default
|
||||
|
||||
default:
|
||||
// alphanumeric keys or F2 (special key just for this) enable
|
||||
// the cell edit control
|
||||
if ( !(event.AltDown() ||
|
||||
event.MetaDown() ||
|
||||
event.ControlDown()) &&
|
||||
!IsCellEditControlEnabled() &&
|
||||
CanEnableCellControl() )
|
||||
// is it possible to edit the current cell at all?
|
||||
if ( !IsCellEditControlEnabled() && CanEnableCellControl() )
|
||||
{
|
||||
EnableCellEditControl();
|
||||
// yes, now check whether the cells editor accepts the key
|
||||
int row = m_currentCellCoords.GetRow();
|
||||
int col = m_currentCellCoords.GetCol();
|
||||
wxGridCellAttr* attr = GetCellAttr(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);
|
||||
}
|
||||
else
|
||||
{
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
editor->DecRef();
|
||||
attr->DecRef();
|
||||
}
|
||||
|
Reference in New Issue
Block a user