X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a1b806b98241ab649c169aaa1f134df85e80fb8b..bc9d3d911cfb51f612a699d7fb00f57eb5b2097c:/src/generic/grideditors.cpp diff --git a/src/generic/grideditors.cpp b/src/generic/grideditors.cpp index ac90aa3310..fabd2b9227 100644 --- a/src/generic/grideditors.cpp +++ b/src/generic/grideditors.cpp @@ -56,6 +56,10 @@ #define WXUNUSED_GTK(identifier) identifier #endif +#ifdef __WXOSX__ +#include "wx/osx/private.h" +#endif + // Required for wxIs... functions #include @@ -406,6 +410,10 @@ void wxGridCellTextEditor::DoCreate(wxWindow* parent, wxDefaultPosition, wxDefaultSize, style); +#ifdef __WXOSX__ + wxWidgetImpl* impl = m_control->GetPeer(); + impl->SetNeedsFocusRect(false); +#endif // set max length allowed in the textctrl, if the parameter was set if ( m_maxChars != 0 ) { @@ -451,6 +459,12 @@ void wxGridCellTextEditor::SetSize(const wxRect& rectOrig) rect.width -= 2; rect.height -= 2; +#elif defined(__WXOSX__) + rect.x += 1; + rect.y += 1; + + rect.width -= 1; + rect.height -= 1; #else int extra_x = ( rect.x > 2 ) ? 2 : 1; int extra_y = ( rect.y > 2 ) ? 2 : 1; @@ -862,10 +876,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, @@ -988,51 +1005,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_precision = (int)tmp; + m_width = (int)width; + } + else + { + 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 ) + if ( !m_format ) { - fmt.Printf(wxT("%%%d.%df"), m_width, m_precision); - } - else - { - // 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) @@ -1349,6 +1428,29 @@ void wxGridCellChoiceEditor::Create(wxWindow* parent, wxGridCellEditor::Create(parent, id, evtHandler); } +void wxGridCellChoiceEditor::SetSize(const wxRect& rect) +{ + wxASSERT_MSG(m_control, + wxT("The wxGridCellChoiceEditor must be created first!")); + + // Check that the height is not too small to fit the combobox. + wxRect rectTallEnough = rect; + const wxSize bestSize = m_control->GetBestSize(); + const wxCoord diffY = bestSize.GetHeight() - rectTallEnough.GetHeight(); + if ( diffY > 0 ) + { + // Do make it tall enough. + rectTallEnough.height += diffY; + + // Also centre the effective rectangle vertically with respect to the + // original one. + rectTallEnough.y -= diffY/2; + } + //else: The rectangle provided is already tall enough. + + wxGridCellEditor::SetSize(rectTallEnough); +} + void wxGridCellChoiceEditor::PaintBackground(const wxRect& rectCell, wxGridCellAttr * attr) { @@ -1380,6 +1482,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 @@ -1486,6 +1596,14 @@ void wxGridCellEnumEditor::BeginEdit(int row, int col, wxGrid* grid) wxASSERT_MSG(m_control, wxT("The wxGridCellEnumEditor must be Created first!")); + wxGridCellEditorEvtHandler* evtHandler = NULL; + if (m_control) + evtHandler = wxDynamicCast(m_control->GetEventHandler(), wxGridCellEditorEvtHandler); + + // Don't immediately end if we get a kill focus event within BeginEdit + if (evtHandler) + evtHandler->SetInSetFocus(true); + wxGridTableBase *table = grid->GetTable(); if ( table->CanGetValueAs(row, col, wxGRID_VALUE_NUMBER) ) @@ -1508,6 +1626,22 @@ void wxGridCellEnumEditor::BeginEdit(int row, int col, wxGrid* grid) Combo()->SetSelection(m_index); 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 + // happens after this point, so we can't reset the flag yet. +#if !defined(__WXGTK20__) + evtHandler->SetInSetFocus(false); +#endif + } } bool wxGridCellEnumEditor::EndEdit(int WXUNUSED(row),