Changing datatransfer implementation from CFPasteboard to NSPasteboard API (#1264)
* changing datatransfer from CFPasteboard to NSPasteboard API * factoring and cleaning up * Switching back naming * missed file * getting wxCFStringRef to be independent of system headers * add unichar include * using wxCFStringRef in header * moving to private headers, change method name * adapting to lesser content in cfstring.h * Removing malloc/free usage * use wxScopedArray throughout * using wxMemoryBuffer instead of char[] * fixing nonprecomp headers * missing forward decl in non-precomp builds
This commit is contained in:
@@ -12,8 +12,6 @@
|
||||
#ifndef __WX_CFSTRINGHOLDER_H__
|
||||
#define __WX_CFSTRINGHOLDER_H__
|
||||
|
||||
#include <CoreFoundation/CFString.h>
|
||||
|
||||
#include "wx/dlimpexp.h"
|
||||
#include "wx/fontenc.h"
|
||||
#include "wx/osx/core/cfref.h"
|
||||
@@ -44,7 +42,7 @@ public:
|
||||
wxFontEncoding encoding = wxFONTENCODING_DEFAULT) ;
|
||||
|
||||
#ifdef __WXMAC__
|
||||
wxCFStringRef(NSString* ref)
|
||||
wxCFStringRef(WX_NSString ref)
|
||||
: wxCFRef< CFStringRef >((CFStringRef) ref)
|
||||
{
|
||||
}
|
||||
@@ -69,29 +67,12 @@ public:
|
||||
static wxString AsString( CFStringRef ref, wxFontEncoding encoding = wxFONTENCODING_DEFAULT ) ;
|
||||
static wxString AsStringWithNormalizationFormC( CFStringRef ref, wxFontEncoding encoding = wxFONTENCODING_DEFAULT ) ;
|
||||
#ifdef __WXMAC__
|
||||
static wxString AsString( NSString* ref, wxFontEncoding encoding = wxFONTENCODING_DEFAULT ) ;
|
||||
static wxString AsStringWithNormalizationFormC( NSString* ref, wxFontEncoding encoding = wxFONTENCODING_DEFAULT ) ;
|
||||
static wxString AsString( WX_NSString ref, wxFontEncoding encoding = wxFONTENCODING_DEFAULT ) ;
|
||||
static wxString AsStringWithNormalizationFormC( WX_NSString ref, wxFontEncoding encoding = wxFONTENCODING_DEFAULT ) ;
|
||||
|
||||
NSString* AsNSString() const { return (NSString*)(CFStringRef) *this; }
|
||||
WX_NSString AsNSString() const { return (WX_NSString)(CFStringRef) *this; }
|
||||
#endif
|
||||
private:
|
||||
} ;
|
||||
|
||||
// corresponding class for holding UniChars (native unicode characters)
|
||||
|
||||
class WXDLLIMPEXP_BASE wxMacUniCharBuffer
|
||||
{
|
||||
public :
|
||||
wxMacUniCharBuffer( const wxString &str ) ;
|
||||
|
||||
~wxMacUniCharBuffer() ;
|
||||
|
||||
UniCharPtr GetBuffer() ;
|
||||
|
||||
UniCharCount GetChars() ;
|
||||
|
||||
private :
|
||||
UniCharPtr m_ubuf ;
|
||||
UniCharCount m_chars ;
|
||||
};
|
||||
#endif //__WXCFSTRINGHOLDER_H__
|
||||
|
@@ -51,6 +51,7 @@ wxString WXDLLIMPEXP_CORE wxMacMakeStringFromPascal( const unsigned char * from
|
||||
WXDLLIMPEXP_BASE wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathComponent = NULL );
|
||||
WXDLLIMPEXP_BASE OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef );
|
||||
WXDLLIMPEXP_BASE wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname );
|
||||
WXDLLIMPEXP_BASE CFURLRef wxOSXCreateURLFromFileSystemPath( const wxString& path);
|
||||
|
||||
// keycode utils from app.cpp
|
||||
|
||||
|
@@ -13,6 +13,7 @@
|
||||
|
||||
#include <CoreFoundation/CFString.h>
|
||||
#include <CoreFoundation/CFStringEncodingExt.h>
|
||||
#include "wx/fontmap.h"
|
||||
|
||||
// ============================================================================
|
||||
// CoreFoundation conversion classes
|
||||
@@ -335,3 +336,20 @@ private:
|
||||
CFStringEncoding m_encoding ;
|
||||
};
|
||||
|
||||
// corresponding class for holding UniChars (native unicode characters)
|
||||
|
||||
class WXDLLIMPEXP_BASE wxMacUniCharBuffer
|
||||
{
|
||||
public :
|
||||
wxMacUniCharBuffer( const wxString &str ) ;
|
||||
|
||||
~wxMacUniCharBuffer() ;
|
||||
|
||||
UniCharPtr GetBuffer() ;
|
||||
|
||||
UniCharCount GetChars() ;
|
||||
|
||||
private :
|
||||
UniCharPtr m_ubuf ;
|
||||
UniCharCount m_chars ;
|
||||
};
|
||||
|
@@ -11,10 +11,12 @@
|
||||
#ifndef _WX_MAC_DATAFORM_H
|
||||
#define _WX_MAC_DATAFORM_H
|
||||
|
||||
#include "wx/osx/core/cfstring.h"
|
||||
|
||||
class WXDLLIMPEXP_CORE wxDataFormat
|
||||
{
|
||||
public:
|
||||
typedef unsigned long NativeFormat;
|
||||
typedef CFStringRef NativeFormat;
|
||||
|
||||
wxDataFormat();
|
||||
wxDataFormat(wxDataFormatId vType);
|
||||
@@ -41,11 +43,11 @@ public:
|
||||
// explicit and implicit conversions to NativeFormat which is one of
|
||||
// standard data types (implicit conversion is useful for preserving the
|
||||
// compatibility with old code)
|
||||
NativeFormat GetFormatId() const { return m_format; }
|
||||
operator NativeFormat() const { return m_format; }
|
||||
const NativeFormat GetFormatId() const { return m_format; }
|
||||
operator const NativeFormat() const { return m_format; }
|
||||
|
||||
void SetId(NativeFormat format);
|
||||
|
||||
|
||||
// string ids are used for custom types - this SetId() must be used for
|
||||
// application-specific formats
|
||||
wxString GetId() const;
|
||||
@@ -54,15 +56,18 @@ public:
|
||||
// implementation
|
||||
wxDataFormatId GetType() const { return m_type; }
|
||||
void SetType( wxDataFormatId type );
|
||||
static NativeFormat GetFormatForType(wxDataFormatId type);
|
||||
|
||||
// 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;
|
||||
private:
|
||||
wxDataFormatId m_type;
|
||||
NativeFormat m_format;
|
||||
// indicates the type in case of wxDF_PRIVATE :
|
||||
wxString m_id ;
|
||||
void ClearNativeFormat();
|
||||
|
||||
wxDataFormatId m_type;
|
||||
wxCFStringRef m_format;
|
||||
};
|
||||
|
||||
#endif // _WX_MAC_DATAFORM_H
|
||||
|
@@ -11,28 +11,24 @@
|
||||
#ifndef _WX_MAC_DATAOBJ_H_
|
||||
#define _WX_MAC_DATAOBJ_H_
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDataObject is the same as wxDataObjectBase under wxGTK
|
||||
// ----------------------------------------------------------------------------
|
||||
class WXDLLIMPEXP_CORE wxOSXDataSink;
|
||||
class WXDLLIMPEXP_CORE wxOSXDataSource;
|
||||
|
||||
class WXDLLIMPEXP_CORE wxDataObject : public wxDataObjectBase
|
||||
{
|
||||
public:
|
||||
wxDataObject();
|
||||
#ifdef __DARWIN__
|
||||
virtual ~wxDataObject() { }
|
||||
#endif
|
||||
|
||||
virtual bool IsSupportedFormat( const wxDataFormat& format, Direction dir = Get ) const;
|
||||
void AddToPasteboard( void * pasteboardRef , wxIntPtr itemID );
|
||||
// returns true if the passed in format is present in the pasteboard
|
||||
static bool IsFormatInPasteboard( void * pasteboardRef, const wxDataFormat &dataFormat );
|
||||
// returns true if any of the accepted formats of this dataobj is in the pasteboard
|
||||
bool HasDataInPasteboard( void * pasteboardRef );
|
||||
bool GetFromPasteboard( void * pasteboardRef );
|
||||
|
||||
void WriteToSink(wxOSXDataSink *sink) const;
|
||||
bool ReadFromSource(wxOSXDataSource *source);
|
||||
bool CanReadFromSource(wxOSXDataSource *source) const;
|
||||
|
||||
#if wxOSX_USE_COCOA
|
||||
virtual void AddSupportedTypes( void* cfarray);
|
||||
// adds all the native formats (in descending order of preference) this data object supports
|
||||
virtual void AddSupportedTypes( CFMutableArrayRef cfarray) const;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@@ -30,6 +30,8 @@ class WXDLLIMPEXP_FWD_CORE wxFileDropTarget;
|
||||
|
||||
class WXDLLIMPEXP_FWD_CORE wxDropSource;
|
||||
|
||||
class WXDLLIMPEXP_FWD_CORE wxOSXDataSource;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// macros
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -58,9 +60,10 @@ class WXDLLIMPEXP_CORE wxDropTarget: public wxDropTargetBase
|
||||
virtual wxDataFormat GetMatchingPair();
|
||||
|
||||
bool CurrentDragHasSupportedFormat() ;
|
||||
void SetCurrentDragPasteboard( void* dragpasteboard ) { m_currentDragPasteboard = dragpasteboard ; }
|
||||
|
||||
void SetCurrentDragSource( wxOSXDataSource* dragpasteboard ) { m_currentDragPasteboard = dragpasteboard ; }
|
||||
protected :
|
||||
void* m_currentDragPasteboard ;
|
||||
wxOSXDataSource* m_currentDragPasteboard ;
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#define _WX_PRIVATE_OSX_H_
|
||||
|
||||
#include "wx/osx/core/private.h"
|
||||
#include "wx/osx/private/datatransfer.h"
|
||||
|
||||
#if wxOSX_USE_IPHONE
|
||||
#include "wx/osx/iphone/private.h"
|
||||
|
113
include/wx/osx/private/datatransfer.h
Normal file
113
include/wx/osx/private/datatransfer.h
Normal file
@@ -0,0 +1,113 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/osx/private/datatransfer.h
|
||||
// Purpose: OS X specific data transfer implementation
|
||||
// Author: Stefan Csomor
|
||||
// Created: 2019-03-29
|
||||
// Copyright: (c) 2019 Stefan Csomor <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_OSX_PRIVATE_DATATRANSFER_H_
|
||||
#define _WX_OSX_PRIVATE_DATATRANSFER_H_
|
||||
|
||||
#include "wx/osx/private.h"
|
||||
#include "wx/osx/dataform.h"
|
||||
|
||||
class WXDLLIMPEXP_FWD_CORE wxDataObject;
|
||||
|
||||
class WXDLLIMPEXP_CORE wxOSXDataSourceItem
|
||||
{
|
||||
public:
|
||||
virtual ~wxOSXDataSourceItem();
|
||||
|
||||
virtual wxDataFormat::NativeFormat AvailableType(CFArrayRef types) const = 0;
|
||||
|
||||
virtual bool GetData( const wxDataFormat& dataFormat, wxMemoryBuffer& target) = 0;
|
||||
|
||||
virtual bool GetData( wxDataFormat::NativeFormat type, wxMemoryBuffer& target) = 0;
|
||||
|
||||
virtual CFDataRef DoGetData(wxDataFormat::NativeFormat type) const = 0;
|
||||
};
|
||||
|
||||
class WXDLLIMPEXP_CORE wxOSXDataSource
|
||||
{
|
||||
public:
|
||||
// the number of source items
|
||||
virtual size_t GetItemCount() const = 0;
|
||||
|
||||
// get source item by index, needs to be deleted after use
|
||||
virtual const wxOSXDataSourceItem* GetItem(size_t pos) const = 0;
|
||||
|
||||
// returns true if there is any data in this source conforming to dataFormat
|
||||
virtual bool IsSupported(const wxDataFormat &dataFormat);
|
||||
|
||||
// returns true if there is any data in this source supported by dataobj
|
||||
virtual bool IsSupported(const wxDataObject &dataobj);
|
||||
|
||||
// returns true if there is any data in this source of types
|
||||
virtual bool HasData(CFArrayRef types) const = 0;
|
||||
|
||||
};
|
||||
|
||||
class WXDLLIMPEXP_CORE wxOSXDataSinkItem
|
||||
{
|
||||
public:
|
||||
virtual ~wxOSXDataSinkItem();
|
||||
|
||||
virtual void SetFilename(const wxString& filename);
|
||||
|
||||
// translating from wx into native representation
|
||||
virtual void SetData(const wxDataFormat& format, const void *buf, size_t size) = 0;
|
||||
|
||||
// translating from wx into native representation
|
||||
virtual void SetData(wxDataFormat::NativeFormat format, const void *buf, size_t size) = 0;
|
||||
|
||||
// native implementation for setting data
|
||||
virtual void DoSetData(wxDataFormat::NativeFormat format, CFDataRef data) = 0;
|
||||
};
|
||||
|
||||
|
||||
class WXDLLIMPEXP_CORE wxOSXDataSink
|
||||
{
|
||||
public:
|
||||
// delete all created sink items
|
||||
virtual void Clear() = 0;
|
||||
|
||||
// create a new sink item
|
||||
virtual wxOSXDataSinkItem* CreateItem() = 0;
|
||||
|
||||
// flush the created sink items into the system sink representation
|
||||
virtual void Flush() = 0 ;
|
||||
};
|
||||
|
||||
class WXDLLIMPEXP_CORE wxOSXPasteboard : public wxOSXDataSink, public wxOSXDataSource
|
||||
{
|
||||
public:
|
||||
wxOSXPasteboard(OSXPasteboard native);
|
||||
~wxOSXPasteboard();
|
||||
|
||||
// sink methods
|
||||
|
||||
virtual wxOSXDataSinkItem* CreateItem() wxOVERRIDE;
|
||||
|
||||
void Clear() wxOVERRIDE;
|
||||
|
||||
void Flush() wxOVERRIDE;
|
||||
|
||||
// source methods
|
||||
|
||||
virtual size_t GetItemCount() const wxOVERRIDE;
|
||||
|
||||
virtual const wxOSXDataSourceItem* GetItem(size_t pos) const wxOVERRIDE;
|
||||
|
||||
virtual bool HasData(CFArrayRef types) const wxOVERRIDE;
|
||||
|
||||
static wxOSXPasteboard* GetGeneralClipboard();
|
||||
private:
|
||||
void DeleteSinkItems();
|
||||
|
||||
OSXPasteboard m_pasteboard;
|
||||
wxVector<wxOSXDataSinkItem*> m_sinkItems;
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user