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
This commit is contained in:
Vadim Zeitlin
2012-07-02 14:36:56 +00:00
parent 87762892be
commit 119e862ca9
2 changed files with 22 additions and 6 deletions

View File

@@ -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;

View File

@@ -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())