diff --git a/docs/changes.txt b/docs/changes.txt index a7fb5917f5..c2edd51abd 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -82,6 +82,7 @@ wxOSX: - Remove extra borders around wxFilePickerCtrl (John Roberts). - Set up extensions filter correctly in wxFileDialog (nick863). - Turn off automatic quotes substitutions in wxTextCtrl (Xlord2). +- Implement wxDataViewChoiceByIndexRenderer (wanup). Unix: diff --git a/include/wx/osx/dvrenderers.h b/include/wx/osx/dvrenderers.h index 2e43251261..bb41f3d5b8 100644 --- a/include/wx/osx/dvrenderers.h +++ b/include/wx/osx/dvrenderers.h @@ -116,6 +116,25 @@ private: wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewChoiceRenderer); }; +// ---------------------------------------------------------------------------- +// wxDataViewChoiceByIndexRenderer +// ---------------------------------------------------------------------------- + +class WXDLLIMPEXP_ADV wxDataViewChoiceByIndexRenderer: public wxDataViewChoiceRenderer +{ +public: + wxDataViewChoiceByIndexRenderer(const wxArrayString& choices, + wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE, + int alignment = wxDVR_DEFAULT_ALIGNMENT); + + virtual bool SetValue(const wxVariant& value) wxOVERRIDE; + virtual bool GetValue(wxVariant& value) const wxOVERRIDE; + + virtual void OSXOnCellChanged(NSObject *value, + const wxDataViewItem& item, + unsigned col) wxOVERRIDE; +}; + #endif // wxOSX_USE_COCOA // --------------------------------------------------------- diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index c4240a3435..022fc779d4 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -2836,6 +2836,49 @@ bool wxDataViewChoiceRenderer::MacRender() wxIMPLEMENT_CLASS(wxDataViewChoiceRenderer, wxDataViewRenderer); +// ---------------------------------------------------------------------------- +// wxDataViewChoiceByIndexRenderer +// ---------------------------------------------------------------------------- + +wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer(const wxArrayString& choices, + wxDataViewCellMode mode, + int alignment) + : wxDataViewChoiceRenderer(choices, mode, alignment) +{ + m_variantType = wxS("long"); +} + +void +wxDataViewChoiceByIndexRenderer::OSXOnCellChanged(NSObject *value, + const wxDataViewItem& item, + unsigned col) +{ + wxVariant valueLong(ObjectToLong(value)); + if ( !Validate(valueLong) ) + return; + + wxDataViewModel *model = GetOwner()->GetOwner()->GetModel(); + model->ChangeValue(valueLong, item, col); +} + +bool +wxDataViewChoiceByIndexRenderer::SetValue(const wxVariant& value) +{ + const wxVariant valueStr = GetChoice(value.GetLong()); + return wxDataViewChoiceRenderer::SetValue(valueStr); +} + +bool +wxDataViewChoiceByIndexRenderer::GetValue(wxVariant& value) const +{ + wxVariant valueStr; + if ( !wxDataViewChoiceRenderer::GetValue(valueStr) ) + return false; + + value = (long) GetChoices().Index(valueStr.GetString()); + return true; +} + // --------------------------------------------------------- // wxDataViewDateRenderer // ---------------------------------------------------------