X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/97e07b1cd961266a83e257868eff6aae464bed02..c44db939d6fb7975ee95747cdfb158001675e0e1:/src/generic/grideditors.cpp?ds=inline diff --git a/src/generic/grideditors.cpp b/src/generic/grideditors.cpp index 620130e596..835ca10e71 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; @@ -660,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 } } @@ -862,10 +862,13 @@ wxString wxGridCellNumberEditor::GetValue() const // wxGridCellFloatEditor // ---------------------------------------------------------------------------- -wxGridCellFloatEditor::wxGridCellFloatEditor(int width, int precision) +wxGridCellFloatEditor::wxGridCellFloatEditor(int width, + int precision, + int format) { m_width = width; m_precision = precision; + m_style = format; } void wxGridCellFloatEditor::Create(wxWindow* parent, @@ -875,7 +878,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 } @@ -988,51 +991,113 @@ void wxGridCellFloatEditor::SetParameters(const wxString& params) // reset to default m_width = m_precision = -1; + m_style = wxGRID_FLOAT_FORMAT_DEFAULT; + m_format.clear(); } else { - long tmp; - if ( params.BeforeFirst(wxT(',')).ToLong(&tmp) ) + wxString rest; + wxString tmp = params.BeforeFirst(wxT(','), &rest); + if ( !tmp.empty() ) { - m_width = (int)tmp; - - if ( params.AfterFirst(wxT(',')).ToLong(&tmp) ) + long width; + if ( tmp.ToLong(&width) ) + { + m_width = (int)width; + } + else { - m_precision = (int)tmp; + wxLogDebug(wxT("Invalid wxGridCellFloatRenderer width parameter string '%s ignored"), params.c_str()); + } + } - // skip the error message below - return; + tmp = rest.BeforeFirst(wxT(',')); + if ( !tmp.empty() ) + { + long precision; + if ( tmp.ToLong(&precision) ) + { + m_precision = (int)precision; + } + else + { + wxLogDebug(wxT("Invalid wxGridCellFloatRenderer precision parameter string '%s ignored"), params.c_str()); } } - wxLogDebug(wxT("Invalid wxGridCellFloatEditor parameter string '%s' ignored"), params.c_str()); + tmp = rest.AfterFirst(wxT(',')); + if ( !tmp.empty() ) + { + if ( tmp[0] == wxT('f') ) + { + m_style = wxGRID_FLOAT_FORMAT_FIXED; + } + else if ( tmp[0] == wxT('e') ) + { + m_style = wxGRID_FLOAT_FORMAT_SCIENTIFIC; + } + else if ( tmp[0] == wxT('g') ) + { + m_style = wxGRID_FLOAT_FORMAT_COMPACT; + } + else if ( tmp[0] == wxT('E') ) + { + m_style = wxGRID_FLOAT_FORMAT_SCIENTIFIC | + wxGRID_FLOAT_FORMAT_UPPER; + } + else if ( tmp[0] == wxT('F') ) + { + m_style = wxGRID_FLOAT_FORMAT_FIXED | + wxGRID_FLOAT_FORMAT_UPPER; + } + else if ( tmp[0] == wxT('G') ) + { + m_style = wxGRID_FLOAT_FORMAT_COMPACT | + wxGRID_FLOAT_FORMAT_UPPER; + } + else + { + wxLogDebug("Invalid wxGridCellFloatRenderer format " + "parameter string '%s ignored", params); + } + } } } -wxString wxGridCellFloatEditor::GetString() const +wxString wxGridCellFloatEditor::GetString() { - wxString fmt; - if ( m_precision == -1 && m_width != -1) - { - // default precision - fmt.Printf(wxT("%%%d.f"), m_width); - } - else if ( m_precision != -1 && m_width == -1) - { - // default width - fmt.Printf(wxT("%%.%df"), m_precision); - } - else if ( m_precision != -1 && m_width != -1 ) - { - fmt.Printf(wxT("%%%d.%df"), m_width, m_precision); - } - else + if ( !m_format ) { - // default width/precision - fmt = wxT("%f"); + if ( m_precision == -1 && m_width != -1) + { + // default precision + m_format.Printf(wxT("%%%d."), m_width); + } + else if ( m_precision != -1 && m_width == -1) + { + // default width + m_format.Printf(wxT("%%.%d"), m_precision); + } + else if ( m_precision != -1 && m_width != -1 ) + { + m_format.Printf(wxT("%%%d.%d"), m_width, m_precision); + } + else + { + // default width/precision + m_format = wxT("%"); + } + + bool isUpper = (m_style & wxGRID_FLOAT_FORMAT_UPPER) != 0; + if ( m_style & wxGRID_FLOAT_FORMAT_SCIENTIFIC ) + m_format += isUpper ? wxT('E') : wxT('e'); + else if ( m_style & wxGRID_FLOAT_FORMAT_COMPACT ) + m_format += isUpper ? wxT('G') : wxT('g'); + else + m_format += wxT('f'); } - return wxString::Format(fmt, m_value); + return wxString::Format(m_format, m_value); } bool wxGridCellFloatEditor::IsAcceptedKey(wxKeyEvent& event) @@ -1380,6 +1445,14 @@ void wxGridCellChoiceEditor::BeginEdit(int row, int col, wxGrid* grid) Combo()->SetFocus(); +#ifdef __WXOSX_COCOA__ + // This is a work around for the combobox being simply dismissed when a + // choice is made in it under OS X. The bug is almost certainly due to a + // problem in focus events generation logic but it's not obvious to fix and + // for now this at least allows to use wxGrid. + Combo()->Popup(); +#endif + if (evtHandler) { // When dropping down the menu, a kill focus event @@ -1506,7 +1579,6 @@ void wxGridCellEnumEditor::BeginEdit(int row, int col, wxGrid* grid) } Combo()->SetSelection(m_index); - Combo()->SetInsertionPointEnd(); Combo()->SetFocus(); }