diff --git a/include/wx/osx/dataform.h b/include/wx/osx/dataform.h index 8f31948df6..e43593e5d8 100644 --- a/include/wx/osx/dataform.h +++ b/include/wx/osx/dataform.h @@ -61,9 +61,14 @@ public: // returns true if the format is one of those defined in wxDataFormatId bool IsStandard() const { return m_type > 0 && m_type < wxDF_PRIVATE; } - // adds all the native formats for this format to an array - void AddSupportedTypes(CFMutableArrayRef types) const; + // adds all the native formats for this format when calling a GetData + void AddSupportedTypesForGetting(CFMutableArrayRef types) const; + + // adds all the native formats for this format when calling a SetData + void AddSupportedTypesForSetting(CFMutableArrayRef types) const; private: + void DoAddSupportedTypes(CFMutableArrayRef types, bool forSetting) const; + void ClearNativeFormat(); wxDataFormatId m_type; diff --git a/include/wx/osx/dataobj.h b/include/wx/osx/dataobj.h index fa3af42980..0ad2b4d73d 100644 --- a/include/wx/osx/dataobj.h +++ b/include/wx/osx/dataobj.h @@ -33,7 +33,7 @@ public: #if wxOSX_USE_COCOA // adds all the native formats (in descending order of preference) this data object supports - virtual void AddSupportedTypes( CFMutableArrayRef cfarray) const; + virtual void AddSupportedTypes( CFMutableArrayRef cfarray, Direction dir ) const; #endif }; diff --git a/src/osx/carbon/dataobj.cpp b/src/osx/carbon/dataobj.cpp index 35582cb88d..261816b095 100644 --- a/src/osx/carbon/dataobj.cpp +++ b/src/osx/carbon/dataobj.cpp @@ -93,7 +93,13 @@ wxDataFormat::NativeFormat wxDataFormat::GetFormatForType(wxDataFormatId type) break; case wxDF_UNICODETEXT: +#ifdef wxNEEDS_UTF8_FOR_TEXT_DATAOBJ + f = kUTTypeUTF8PlainText; +#elif defined(wxNEEDS_UTF16_FOR_TEXT_DATAOBJ) f = kUTTypeUTF16PlainText; +#else +#error "one of wxNEEDS_UTF{8,16}_FOR_TEXT_DATAOBJ must be defined" +#endif break; case wxDF_HTML: @@ -125,7 +131,17 @@ void wxDataFormat::SetType( wxDataFormatId dataType ) m_format = GetFormatForType(dataType); } -void wxDataFormat::AddSupportedTypes(CFMutableArrayRef cfarray) const +void wxDataFormat::AddSupportedTypesForSetting(CFMutableArrayRef types) const +{ + DoAddSupportedTypes(types, true); +} + +void wxDataFormat::AddSupportedTypesForGetting(CFMutableArrayRef types) const +{ + DoAddSupportedTypes(types, false); +} + +void wxDataFormat::DoAddSupportedTypes(CFMutableArrayRef cfarray, bool forSetting) const { if ( GetType() == wxDF_PRIVATE ) { @@ -134,20 +150,18 @@ void wxDataFormat::AddSupportedTypes(CFMutableArrayRef cfarray) const else { CFArrayAppendValue(cfarray, GetFormatForType(m_type)); - // add additional accepted types - switch (GetType()) + if ( forSetting ) { - case wxDF_UNICODETEXT: - CFArrayAppendValue(cfarray, kUTTypeUTF8PlainText); - break; - case wxDF_FILENAME: - CFArrayAppendValue(cfarray, kPasteboardTypeFileURLPromise); - break; - case wxDF_BITMAP: - CFArrayAppendValue(cfarray, kUTTypePICT); - break; - default: - break; + // add additional accepted types which we are ready to accept and can + // convert to our internal formats + switch (GetType()) + { + case wxDF_FILENAME: + CFArrayAppendValue(cfarray, kPasteboardTypeFileURLPromise); + break; + default: + break; + } } } } @@ -377,7 +391,7 @@ bool wxDataObject::ReadFromSource(wxOSXDataSource * source) if (source->IsSupported(dataFormat)) { wxCFMutableArrayRef typesarray; - dataFormat.AddSupportedTypes(typesarray); + dataFormat.AddSupportedTypesForSetting(typesarray); size_t itemCount = source->GetItemCount(); for ( size_t itemIndex = 0; itemIndex < itemCount && !transferred; ++itemIndex) @@ -522,15 +536,19 @@ bool wxDataObject::CanReadFromSource( wxDataObject * source ) const return GetSupportedFormatInSource(source) != wxDF_INVALID; } -void wxDataObject::AddSupportedTypes( CFMutableArrayRef cfarray) const +void wxDataObject::AddSupportedTypes( CFMutableArrayRef cfarray, Direction dir) const { size_t nFormats = GetFormatCount(wxDataObject::Set); wxScopedArray array(GetFormatCount()); GetAllFormats(array.get(), wxDataObject::Set); for (size_t i = 0; i < nFormats; i++) - array[i].AddSupportedTypes(cfarray); - + { + if ( dir == Direction::Get) + array[i].AddSupportedTypesForGetting(cfarray); + else + array[i].AddSupportedTypesForSetting(cfarray); + } } // ---------------------------------------------------------------------------- diff --git a/src/osx/cocoa/dnd.mm b/src/osx/cocoa/dnd.mm index 7e1df4fabb..31d3a2cd5b 100644 --- a/src/osx/cocoa/dnd.mm +++ b/src/osx/cocoa/dnd.mm @@ -50,14 +50,14 @@ wxOSXDataSourceItem::~wxOSXDataSourceItem() bool wxOSXDataSource::IsSupported(const wxDataFormat &dataFormat) { wxCFMutableArrayRef typesarray; - dataFormat.AddSupportedTypes(typesarray); + dataFormat.AddSupportedTypesForSetting(typesarray); return HasData(typesarray); } bool wxOSXDataSource::IsSupported(const wxDataObject &dataobj) { wxCFMutableArrayRef typesarray; - dataobj.AddSupportedTypes(typesarray); + dataobj.AddSupportedTypes(typesarray, wxDataObjectBase::Direction::Get); return HasData(typesarray); } @@ -431,6 +431,10 @@ wxDropSource* wxDropSource::GetCurrentDropSource() return gCurrentSource; } +#if __MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_13 +typedef NSString* NSPasteboardType; +#endif + @interface wxPasteBoardWriter : NSObject { wxDataObject* m_data; @@ -447,10 +451,6 @@ wxDropSource* wxDropSource::GetCurrentDropSource() return self; } -#if __MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_13 -typedef NSString* NSPasteboardType; -#endif - - (nullable id)pasteboardPropertyListForType:(nonnull NSPasteboardType)type { wxDataFormat format((wxDataFormat::NativeFormat) type); @@ -464,7 +464,7 @@ typedef NSString* NSPasteboardType; - (nonnull NSArray *)writableTypesForPasteboard:(nonnull NSPasteboard *)pasteboard { wxCFMutableArrayRef typesarray; - m_data->AddSupportedTypes(typesarray); + m_data->AddSupportedTypes(typesarray, wxDataObjectBase::Direction::Get); return (NSArray*) typesarray.autorelease(); } diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index fc525f7a43..2fd1559bae 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -3215,7 +3215,7 @@ void wxWidgetCocoaImpl::SetDropTarget(wxDropTarget* target) if (dobj) { wxCFMutableArrayRef typesarray; - dobj->AddSupportedTypes(typesarray); + dobj->AddSupportedTypes(typesarray, wxDataObjectBase::Direction::Get); NSView* targetView = m_osxView; if ([m_osxView isKindOfClass:[NSScrollView class]]) targetView = [(NSScrollView*)m_osxView documentView];