From: Vadim Zeitlin Date: Mon, 2 Jul 2012 14:36:56 +0000 (+0000) Subject: Fix wxDataViewChoiceRenderer behaviour in wxOSX/Cocoa. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/119e862ca9898d238c8d040718fc0f062dd43a16 Fix wxDataViewChoiceRenderer behaviour in wxOSX/Cocoa. Changing the value of a "choice" cell in wxDataViewCtrl didn't work correctly in wxOSX/Cocoa because wxDataViewChoiceRenderer used the base class version of OSXOnCellChanged() which passed the integer index we received from NSOutlineView to the model instead of the expected string. Fix this by overriding OSXOnCellChanged() in wxDataViewChoiceRenderer itself and using its argument as an integer index of the selection because this is what it is, at least under OS X 10.7. Closes #14373. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71939 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/osx/dvrenderers.h b/include/wx/osx/dvrenderers.h index 1916a77ed7..5d3e506981 100644 --- a/include/wx/osx/dvrenderers.h +++ b/include/wx/osx/dvrenderers.h @@ -103,6 +103,12 @@ public: wxString GetChoice(size_t index) const { return m_choices[index]; } const wxArrayString& GetChoices() const { return m_choices; } +#if wxOSX_USE_COCOA + virtual void OSXOnCellChanged(NSObject *value, + const wxDataViewItem& item, + unsigned col); +#endif // Cocoa + private: wxArrayString m_choices; diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index 9d2fabdc42..26fd4eee1a 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -2620,12 +2620,11 @@ wxDataViewRenderer::OSXOnCellChanged(NSObject *object, const wxDataViewItem& item, unsigned col) { - // TODO: we probably should get rid of this code entirely and make this - // function pure virtual, but currently we still have some native - // renderers (wxDataViewChoiceRenderer) which don't override it and - // there is also wxDataViewCustomRenderer for which it's not obvious - // how it should be implemented so keep this "auto-deduction" of - // variant type from NSObject for now + // TODO: This code should really be removed and this function be made pure + // virtual. We just need to decide what to do with custom renderers + // (i.e. wxDataViewCustomRenderer), currently OS X "in place" editing + // which doesn't really create an editor control is not compatible + // with the in place editing under other platforms. wxVariant value; if ( [object isKindOfClass:[NSString class]] ) @@ -2856,6 +2855,17 @@ wxDataViewChoiceRenderer::wxDataViewChoiceRenderer(const wxArrayString& choices, [cell release]; } +void +wxDataViewChoiceRenderer::OSXOnCellChanged(NSObject *value, + const wxDataViewItem& item, + unsigned col) +{ + // At least under OS X 10.7 we get the index of the item selected and not + // its string. + wxDataViewModel *model = GetOwner()->GetOwner()->GetModel(); + model->ChangeValue(GetChoice(ObjectToLong(value)), item, col); +} + bool wxDataViewChoiceRenderer::MacRender() { if (GetValue().GetType() == GetVariantType())