X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b5f3d8e93431a2d38dda003400163d431a643b05..04fa04d8067d235ab45b5bc05b65f0679634b541:/src/generic/grideditors.cpp?ds=sidebyside diff --git a/src/generic/grideditors.cpp b/src/generic/grideditors.cpp index 1ece439bf7..ac90aa3310 100644 --- a/src/generic/grideditors.cpp +++ b/src/generic/grideditors.cpp @@ -28,12 +28,12 @@ #include "wx/textctrl.h" #include "wx/checkbox.h" #include "wx/combobox.h" - #include "wx/valtext.h" #include "wx/intl.h" #include "wx/math.h" #include "wx/listbox.h" #endif +#include "wx/valnum.h" #include "wx/textfile.h" #include "wx/spinctrl.h" #include "wx/tokenzr.h" @@ -300,13 +300,13 @@ void wxGridCellEditor::Show(bool show, wxGridCellAttr *attr) else { // restore the standard colours fonts - if ( m_colFgOld.Ok() ) + if ( m_colFgOld.IsOk() ) { m_control->SetForegroundColour(m_colFgOld); m_colFgOld = wxNullColour; } - if ( m_colBgOld.Ok() ) + if ( m_colBgOld.IsOk() ) { m_control->SetBackgroundColour(m_colBgOld); m_colBgOld = wxNullColour; @@ -314,7 +314,7 @@ void wxGridCellEditor::Show(bool show, wxGridCellAttr *attr) // Workaround for GTK+1 font setting problem on some platforms #if !defined(__WXGTK__) || defined(__WXGTK20__) - if ( m_fontOld.Ok() ) + if ( m_fontOld.IsOk() ) { m_control->SetFont(m_fontOld); m_fontOld = wxNullFont; @@ -338,13 +338,15 @@ void wxGridCellEditor::HandleReturn(wxKeyEvent& event) bool wxGridCellEditor::IsAcceptedKey(wxKeyEvent& event) { bool ctrl = event.ControlDown(); - bool alt = event.AltDown(); + bool alt; #ifdef __WXMAC__ // On the Mac the Alt key is more like shift and is used for entry of // valid characters, so check for Ctrl and Meta instead. alt = event.MetaDown(); -#endif +#else // !__WXMAC__ + alt = event.AltDown(); +#endif // __WXMAC__/!__WXMAC__ // Assume it's not a valid char if ctrl or alt is down, but if both are // down then it may be because of an AltGr key combination, so let them @@ -353,14 +355,10 @@ bool wxGridCellEditor::IsAcceptedKey(wxKeyEvent& event) return false; #if wxUSE_UNICODE - // if the unicode key code is not really a unicode character (it may - // be a function key or etc., the platforms appear to always give us a - // small value in this case) then fallback to the ASCII key code but - // don't do anything for function keys or etc. - if ( event.GetUnicodeKey() > 127 && event.GetKeyCode() > 127 ) + if ( static_cast(event.GetUnicodeKey()) == WXK_NONE ) return false; #else - if ( event.GetKeyCode() > 255 ) + if ( event.GetKeyCode() > WXK_START ) return false; #endif @@ -399,7 +397,10 @@ void wxGridCellTextEditor::DoCreate(wxWindow* parent, wxEvtHandler* evtHandler, long style) { - style |= wxTE_PROCESS_ENTER | wxTE_PROCESS_TAB | wxNO_BORDER; + // Use of wxTE_RICH2 is a strange hack to work around the bug #11681: a + // plain text control seems to lose its caret somehow when we hide it and + // show it again for a different cell. + style |= wxTE_PROCESS_ENTER | wxTE_PROCESS_TAB | wxNO_BORDER | wxTE_RICH2; m_control = new wxTextCtrl(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, @@ -485,7 +486,10 @@ void wxGridCellTextEditor::DoBeginEdit(const wxString& startValue) Text()->SetFocus(); } -bool wxGridCellTextEditor::EndEdit(const wxString& WXUNUSED(oldval), +bool wxGridCellTextEditor::EndEdit(int WXUNUSED(row), + int WXUNUSED(col), + const wxGrid* WXUNUSED(grid), + const wxString& WXUNUSED(oldval), wxString *newval) { wxCHECK_MSG( m_control, false, @@ -524,7 +528,15 @@ void wxGridCellTextEditor::DoReset(const wxString& startValue) bool wxGridCellTextEditor::IsAcceptedKey(wxKeyEvent& event) { - return wxGridCellEditor::IsAcceptedKey(event); + switch ( event.GetKeyCode() ) + { + case WXK_DELETE: + case WXK_BACK: + return true; + + default: + return wxGridCellEditor::IsAcceptedKey(event); + } } void wxGridCellTextEditor::StartingKey(wxKeyEvent& event) @@ -535,35 +547,39 @@ void wxGridCellTextEditor::StartingKey(wxKeyEvent& event) // a valid character, so not a whole lot of testing needs to be done. wxTextCtrl* tc = Text(); - wxChar ch; - long pos; + int ch; + + bool isPrintable; #if wxUSE_UNICODE ch = event.GetUnicodeKey(); - if (ch <= 127) - ch = (wxChar)event.GetKeyCode(); -#else - ch = (wxChar)event.GetKeyCode(); -#endif + if ( ch != WXK_NONE ) + isPrintable = true; + else +#endif // wxUSE_UNICODE + { + ch = event.GetKeyCode(); + isPrintable = ch >= WXK_SPACE && ch < WXK_START; + } switch (ch) { case WXK_DELETE: - // delete the character at the cursor - pos = tc->GetInsertionPoint(); - if (pos < tc->GetLastPosition()) - tc->Remove(pos, pos + 1); + // Delete the initial character when starting to edit with DELETE. + tc->Remove(0, 1); break; case WXK_BACK: - // delete the character before the cursor - pos = tc->GetInsertionPoint(); - if (pos > 0) + // Delete the last character when starting to edit with BACKSPACE. + { + const long pos = tc->GetLastPosition(); tc->Remove(pos - 1, pos); + } break; default: - tc->WriteText(ch); + if ( isPrintable ) + tc->WriteText(static_cast(ch)); break; } } @@ -601,7 +617,7 @@ void wxGridCellTextEditor::SetParameters(const wxString& params) } else { - wxLogDebug( _T("Invalid wxGridCellTextEditor parameter string '%s' ignored"), params.c_str() ); + wxLogDebug( wxT("Invalid wxGridCellTextEditor parameter string '%s' ignored"), params.c_str() ); } } } @@ -644,7 +660,7 @@ void wxGridCellNumberEditor::Create(wxWindow* parent, wxGridCellTextEditor::Create(parent, id, evtHandler); #if wxUSE_VALIDATORS - Text()->SetValidator(wxTextValidator(wxFILTER_NUMERIC)); + Text()->SetValidator(wxIntegerValidator()); #endif } } @@ -663,7 +679,7 @@ void wxGridCellNumberEditor::BeginEdit(int row, int col, wxGrid* grid) wxString sValue = table->GetValue(row, col); if (! sValue.ToLong(&m_value) && ! sValue.empty()) { - wxFAIL_MSG( _T("this cell doesn't have numeric value") ); + wxFAIL_MSG( wxT("this cell doesn't have numeric value") ); return; } } @@ -681,7 +697,10 @@ void wxGridCellNumberEditor::BeginEdit(int row, int col, wxGrid* grid) } } -bool wxGridCellNumberEditor::EndEdit(const wxString& oldval, wxString *newval) +bool wxGridCellNumberEditor::EndEdit(int WXUNUSED(row), + int WXUNUSED(col), + const wxGrid* WXUNUSED(grid), + const wxString& oldval, wxString *newval) { long value = 0; wxString text; @@ -802,11 +821,11 @@ void wxGridCellNumberEditor::SetParameters(const wxString& params) else { long tmp; - if ( params.BeforeFirst(_T(',')).ToLong(&tmp) ) + if ( params.BeforeFirst(wxT(',')).ToLong(&tmp) ) { m_min = (int)tmp; - if ( params.AfterFirst(_T(',')).ToLong(&tmp) ) + if ( params.AfterFirst(wxT(',')).ToLong(&tmp) ) { m_max = (int)tmp; @@ -815,7 +834,7 @@ void wxGridCellNumberEditor::SetParameters(const wxString& params) } } - wxLogDebug(_T("Invalid wxGridCellNumberEditor parameter string '%s' ignored"), params.c_str()); + wxLogDebug(wxT("Invalid wxGridCellNumberEditor parameter string '%s' ignored"), params.c_str()); } } @@ -856,7 +875,7 @@ void wxGridCellFloatEditor::Create(wxWindow* parent, wxGridCellTextEditor::Create(parent, id, evtHandler); #if wxUSE_VALIDATORS - Text()->SetValidator(wxTextValidator(wxFILTER_NUMERIC)); + Text()->SetValidator(wxFloatingPointValidator(m_precision)); #endif } @@ -877,7 +896,7 @@ void wxGridCellFloatEditor::BeginEdit(int row, int col, wxGrid* grid) { if ( !value.ToDouble(&m_value) ) { - wxFAIL_MSG( _T("this cell doesn't have float value") ); + wxFAIL_MSG( wxT("this cell doesn't have float value") ); return; } } @@ -886,7 +905,10 @@ void wxGridCellFloatEditor::BeginEdit(int row, int col, wxGrid* grid) DoBeginEdit(GetString()); } -bool wxGridCellFloatEditor::EndEdit(const wxString& oldval, wxString *newval) +bool wxGridCellFloatEditor::EndEdit(int WXUNUSED(row), + int WXUNUSED(col), + const wxGrid* WXUNUSED(grid), + const wxString& oldval, wxString *newval) { const wxString text(Text()->GetValue()); @@ -944,7 +966,7 @@ void wxGridCellFloatEditor::StartingKey(wxKeyEvent& event) bool is_decimal_point = ( strbuf == wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT, wxLOCALE_CAT_NUMBER) ); #else - bool is_decimal_point = ( strbuf == _T(".") ); + bool is_decimal_point = ( strbuf == wxT(".") ); #endif if ( wxIsdigit(keycode) || keycode == '+' || keycode == '-' @@ -970,11 +992,11 @@ void wxGridCellFloatEditor::SetParameters(const wxString& params) else { long tmp; - if ( params.BeforeFirst(_T(',')).ToLong(&tmp) ) + if ( params.BeforeFirst(wxT(',')).ToLong(&tmp) ) { m_width = (int)tmp; - if ( params.AfterFirst(_T(',')).ToLong(&tmp) ) + if ( params.AfterFirst(wxT(',')).ToLong(&tmp) ) { m_precision = (int)tmp; @@ -983,7 +1005,7 @@ void wxGridCellFloatEditor::SetParameters(const wxString& params) } } - wxLogDebug(_T("Invalid wxGridCellFloatEditor parameter string '%s' ignored"), params.c_str()); + wxLogDebug(wxT("Invalid wxGridCellFloatEditor parameter string '%s' ignored"), params.c_str()); } } @@ -993,21 +1015,21 @@ wxString wxGridCellFloatEditor::GetString() const if ( m_precision == -1 && m_width != -1) { // default precision - fmt.Printf(_T("%%%d.f"), m_width); + fmt.Printf(wxT("%%%d.f"), m_width); } else if ( m_precision != -1 && m_width == -1) { // default width - fmt.Printf(_T("%%.%df"), m_precision); + fmt.Printf(wxT("%%.%df"), m_precision); } else if ( m_precision != -1 && m_width != -1 ) { - fmt.Printf(_T("%%%d.%df"), m_width, m_precision); + fmt.Printf(wxT("%%%d.%df"), m_width, m_precision); } else { // default width/precision - fmt = _T("%f"); + fmt = wxT("%f"); } return wxString::Format(fmt, m_value); @@ -1018,18 +1040,13 @@ bool wxGridCellFloatEditor::IsAcceptedKey(wxKeyEvent& event) if ( wxGridCellEditor::IsAcceptedKey(event) ) { const int keycode = event.GetKeyCode(); - if ( isascii(keycode) ) + if ( wxIsascii(keycode) ) { - char tmpbuf[2]; - tmpbuf[0] = (char) keycode; - tmpbuf[1] = '\0'; - wxString strbuf(tmpbuf, *wxConvCurrent); - #if wxUSE_INTL const wxString decimalPoint = wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT, wxLOCALE_CAT_NUMBER); #else - const wxString decimalPoint(_T('.')); + const wxString decimalPoint(wxT('.')); #endif // accept digits, 'e' as in '1e+6', also '-', '+', and '.' @@ -1056,7 +1073,7 @@ bool wxGridCellFloatEditor::IsAcceptedKey(wxKeyEvent& event) // ---------------------------------------------------------------------------- // the default values for GetValue() -wxString wxGridCellBoolEditor::ms_stringValues[2] = { _T(""), _T("1") }; +wxString wxGridCellBoolEditor::ms_stringValues[2] = { wxT(""), wxT("1") }; void wxGridCellBoolEditor::Create(wxWindow* parent, wxWindowID id, @@ -1174,7 +1191,7 @@ void wxGridCellBoolEditor::BeginEdit(int row, int col, wxGrid* grid) // because we'll still overwrite it with something different and // this risks to be very surprising for the user code, let them // know about it - wxFAIL_MSG( _T("invalid value for a cell with bool editor!") ); + wxFAIL_MSG( wxT("invalid value for a cell with bool editor!") ); } } @@ -1182,7 +1199,10 @@ void wxGridCellBoolEditor::BeginEdit(int row, int col, wxGrid* grid) CBox()->SetFocus(); } -bool wxGridCellBoolEditor::EndEdit(const wxString& WXUNUSED(oldval), +bool wxGridCellBoolEditor::EndEdit(int WXUNUSED(row), + int WXUNUSED(col), + const wxGrid* WXUNUSED(grid), + const wxString& WXUNUSED(oldval), wxString *newval) { bool value = CBox()->GetValue(); @@ -1370,7 +1390,10 @@ void wxGridCellChoiceEditor::BeginEdit(int row, int col, wxGrid* grid) } } -bool wxGridCellChoiceEditor::EndEdit(const wxString& WXUNUSED(oldval), +bool wxGridCellChoiceEditor::EndEdit(int WXUNUSED(row), + int WXUNUSED(col), + const wxGrid* WXUNUSED(grid), + const wxString& WXUNUSED(oldval), wxString *newval) { const wxString value = Combo()->GetValue(); @@ -1417,7 +1440,7 @@ void wxGridCellChoiceEditor::SetParameters(const wxString& params) m_choices.Empty(); - wxStringTokenizer tk(params, _T(',')); + wxStringTokenizer tk(params, wxT(',')); while ( tk.HasMoreTokens() ) { m_choices.Add(tk.GetNextToken()); @@ -1483,12 +1506,14 @@ void wxGridCellEnumEditor::BeginEdit(int row, int col, wxGrid* grid) } Combo()->SetSelection(m_index); - Combo()->SetInsertionPointEnd(); Combo()->SetFocus(); } -bool wxGridCellEnumEditor::EndEdit(const wxString& WXUNUSED(oldval), +bool wxGridCellEnumEditor::EndEdit(int WXUNUSED(row), + int WXUNUSED(col), + const wxGrid* WXUNUSED(grid), + const wxString& WXUNUSED(oldval), wxString *newval) { long idx = Combo()->GetSelection();