wxMSW wxClipboard implementation
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1396 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -729,18 +729,25 @@ typedef enum
|
||||
// Don't do parent client adjustments (for implementation only)
|
||||
#define wxSIZE_NO_ADJUSTMENTS 0x0008
|
||||
|
||||
|
||||
/* Data format for drag & drop and clipboard operations
|
||||
* numbers as per winuser.h */
|
||||
|
||||
enum wxDataFormat
|
||||
{
|
||||
wxDF_INVALID = 0,
|
||||
wxDF_TEXT = 1, /* CF_TEXT */
|
||||
wxDF_BITMAP = 2, /* CF_BITMAP */
|
||||
wxDF_METAFILE = 3, /* CF_METAFILEPICT */
|
||||
wxDF_DIB = 8, /* CF_DIB */
|
||||
wxDF_SYLK = 4,
|
||||
wxDF_DIF = 5,
|
||||
wxDF_TIFF = 6,
|
||||
wxDF_OEMTEXT = 7, /* CF_OEMTEXT */
|
||||
wxDF_DIB = 8, /* CF_DIB */
|
||||
wxDF_PALETTE = 9,
|
||||
wxDF_PENDATA = 10,
|
||||
wxDF_RIFF = 11,
|
||||
wxDF_WAVE = 12,
|
||||
wxDF_UNICODETEXT = 13,
|
||||
wxDF_ENHMETAFILE = 14,
|
||||
wxDF_FILENAME = 15, /* CF_HDROP */
|
||||
wxDF_LOCALE = 16,
|
||||
wxDF_PRIVATE = 20
|
||||
};
|
||||
|
||||
|
@@ -69,7 +69,7 @@ public:
|
||||
void SetText( const wxString& strText)
|
||||
{ m_strText = strText; }
|
||||
|
||||
wxString GetText()
|
||||
wxString GetText() const
|
||||
{ return m_strText; }
|
||||
|
||||
private:
|
||||
@@ -95,7 +95,7 @@ public:
|
||||
void AddFile( const wxString &file )
|
||||
{ m_files += file; m_files += (char)0; }
|
||||
|
||||
wxString GetFiles()
|
||||
wxString GetFiles() const
|
||||
{ return m_files; }
|
||||
|
||||
private:
|
||||
@@ -121,7 +121,7 @@ public:
|
||||
void SetBitmap( const wxBitmap &bitmap )
|
||||
{ m_bitmap = bitmap; }
|
||||
|
||||
wxBitmap GetBitmap()
|
||||
wxBitmap GetBitmap() const
|
||||
{ return m_bitmap; }
|
||||
|
||||
private:
|
||||
@@ -154,16 +154,16 @@ public:
|
||||
void SetId( const wxString& id )
|
||||
{ m_id = id; }
|
||||
|
||||
wxString GetId()
|
||||
wxString GetId() const
|
||||
{ return m_id; }
|
||||
|
||||
// will make internal copy
|
||||
void SetData( const char *data, size_t size );
|
||||
|
||||
size_t GetDataSize()
|
||||
size_t GetDataSize() const
|
||||
{ return m_size; }
|
||||
|
||||
char* GetData()
|
||||
char* GetData() const
|
||||
{ return m_data; }
|
||||
|
||||
private:
|
||||
|
@@ -69,7 +69,7 @@ public:
|
||||
void SetText( const wxString& strText)
|
||||
{ m_strText = strText; }
|
||||
|
||||
wxString GetText()
|
||||
wxString GetText() const
|
||||
{ return m_strText; }
|
||||
|
||||
private:
|
||||
@@ -95,7 +95,7 @@ public:
|
||||
void AddFile( const wxString &file )
|
||||
{ m_files += file; m_files += (char)0; }
|
||||
|
||||
wxString GetFiles()
|
||||
wxString GetFiles() const
|
||||
{ return m_files; }
|
||||
|
||||
private:
|
||||
@@ -121,7 +121,7 @@ public:
|
||||
void SetBitmap( const wxBitmap &bitmap )
|
||||
{ m_bitmap = bitmap; }
|
||||
|
||||
wxBitmap GetBitmap()
|
||||
wxBitmap GetBitmap() const
|
||||
{ return m_bitmap; }
|
||||
|
||||
private:
|
||||
@@ -154,16 +154,16 @@ public:
|
||||
void SetId( const wxString& id )
|
||||
{ m_id = id; }
|
||||
|
||||
wxString GetId()
|
||||
wxString GetId() const
|
||||
{ return m_id; }
|
||||
|
||||
// will make internal copy
|
||||
void SetData( const char *data, size_t size );
|
||||
|
||||
size_t GetDataSize()
|
||||
size_t GetDataSize() const
|
||||
{ return m_size; }
|
||||
|
||||
char* GetData()
|
||||
char* GetData() const
|
||||
{ return m_data; }
|
||||
|
||||
private:
|
||||
|
@@ -23,88 +23,59 @@
|
||||
|
||||
#include "wx/list.h"
|
||||
|
||||
// These functions superceded by wxClipboard, but retained in order to implement
|
||||
// wxClipboard, and for compatibility.
|
||||
WXDLLEXPORT bool wxOpenClipboard(void);
|
||||
WXDLLEXPORT bool wxClipboardOpen(void);
|
||||
WXDLLEXPORT bool wxCloseClipboard(void);
|
||||
WXDLLEXPORT bool wxEmptyClipboard(void);
|
||||
WXDLLEXPORT bool wxIsClipboardFormatAvailable(int dataFormat);
|
||||
WXDLLEXPORT bool wxSetClipboardData(int dataFormat, wxObject *obj, int width = 0, int height = 0);
|
||||
WXDLLEXPORT wxObject* wxGetClipboardData(int dataFormat, long *len = NULL);
|
||||
WXDLLEXPORT int wxEnumClipboardFormats(int dataFormat);
|
||||
WXDLLEXPORT bool wxIsClipboardFormatAvailable(wxDataFormat dataFormat);
|
||||
WXDLLEXPORT bool wxSetClipboardData(wxDataFormat dataFormat, wxObject *obj, int width = 0, int height = 0);
|
||||
WXDLLEXPORT wxObject* wxGetClipboardData(wxDataFormat dataFormat, long *len = NULL);
|
||||
WXDLLEXPORT wxDataFormat wxEnumClipboardFormats(wxDataFormat dataFormat);
|
||||
WXDLLEXPORT int wxRegisterClipboardFormat(char *formatName);
|
||||
WXDLLEXPORT bool wxGetClipboardFormatName(int dataFormat, char *formatName, int maxCount);
|
||||
WXDLLEXPORT bool wxGetClipboardFormatName(wxDataFormat dataFormat, char *formatName, int maxCount);
|
||||
|
||||
/* The following is Matthew Flatt's implementation of the MSW
|
||||
* side of generic clipboard functionality.
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxClipboard
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/* A clipboard client holds data belonging to the clipboard.
|
||||
For plain text, a client is not necessary. */
|
||||
class WXDLLEXPORT wxClipboardClient : public wxObject
|
||||
{
|
||||
DECLARE_ABSTRACT_CLASS(wxClipboardClient)
|
||||
|
||||
public:
|
||||
/* This list should be filled in with strings indicating the formats
|
||||
this client can provide. Almost all clients will provide "TEXT".
|
||||
Format names should be 4 characters long, so things will work
|
||||
out on the Macintosh */
|
||||
wxStringList formats;
|
||||
|
||||
/* This method is called when the client is losing the selection. */
|
||||
virtual void BeingReplaced(void) = 0;
|
||||
|
||||
/* This method is called when someone wants the data this client is
|
||||
supplying to the clipboard. "format" is a string indicating the
|
||||
format of the data - one of the strings from the "formats"
|
||||
list. "*size" should be filled with the size of the resulting
|
||||
data. In the case of text, "*size" does not count the
|
||||
NULL terminator. */
|
||||
virtual char *GetData(char *format, long *size) = 0;
|
||||
};
|
||||
|
||||
/* ONE instance of this class: */
|
||||
class WXDLLEXPORT wxClipboard : public wxObject
|
||||
class WXDLLEXPORT wxDataObject;
|
||||
class WXDLLEXPORT wxClipboard: public wxObject
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS(wxClipboard)
|
||||
|
||||
public:
|
||||
wxClipboardClient *clipOwner;
|
||||
char *cbString, *sentString, *receivedString;
|
||||
void *receivedTargets;
|
||||
long receivedLength;
|
||||
#ifdef __XVIEW__
|
||||
long sel_owner;
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
||||
wxClipboard();
|
||||
~wxClipboard();
|
||||
|
||||
/* Set the clipboard data owner. "time" comes from the event record. */
|
||||
void SetClipboardClient(wxClipboardClient *, long time);
|
||||
// open the clipboard before SetData() and GetData()
|
||||
virtual bool Open();
|
||||
|
||||
// close the clipboard after SetData() and GetData()
|
||||
virtual void Close();
|
||||
|
||||
// can be called several times
|
||||
virtual bool SetData( wxDataObject *data );
|
||||
|
||||
/* Set the clipboard string; does not require a client. */
|
||||
void SetClipboardString(char *, long time);
|
||||
// format available on the clipboard ?
|
||||
// supply ID if private format, the same as wxPrivateDataObject::SetId()
|
||||
virtual bool IsSupportedFormat( wxDataFormat format, const wxString &id = wxEmptyString );
|
||||
|
||||
// fill data with data on the clipboard (if available)
|
||||
virtual bool GetData( wxDataObject *data );
|
||||
|
||||
// clears wxTheClipboard and the system's clipboard if possible
|
||||
virtual void Clear();
|
||||
|
||||
/* Get data from the clipboard in the format "TEXT". */
|
||||
char *GetClipboardString(long time);
|
||||
|
||||
/* Get data from the clipboard */
|
||||
char *GetClipboardData(char *format, long *length, long time);
|
||||
|
||||
/* Get the clipboard client directly. Will be NULL if clipboard data
|
||||
is a string, or if some other application owns the clipboard.
|
||||
This can be useful for shortcutting data translation, if the
|
||||
clipboard user can check for a specific client. (This is used
|
||||
by the wxMediaEdit class.) */
|
||||
wxClipboardClient *GetClipboardClient(void);
|
||||
// implementation
|
||||
|
||||
bool m_open;
|
||||
};
|
||||
|
||||
/* Initialize wxTheClipboard. Can be called repeatedly */
|
||||
WXDLLEXPORT void wxInitClipboard(void);
|
||||
|
||||
/* The clipboard */
|
||||
WXDLLEXPORT_DATA(extern wxClipboard*) wxTheClipboard;
|
||||
// WXDLLEXPORT_DATA(extern wxClipboard*) wxTheClipboard;
|
||||
|
||||
#endif // wxUSE_CLIPBOARD
|
||||
#endif
|
||||
|
@@ -21,69 +21,99 @@
|
||||
|
||||
#if wxUSE_METAFILE
|
||||
#include "wx/dc.h"
|
||||
#include "wx/gdiobj.h"
|
||||
|
||||
#if wxUSE_DRAG_AND_DROP
|
||||
#include "wx/dataobj.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Metafile and metafile device context classes - work in Windows 3.1 only
|
||||
* Metafile and metafile device context classes
|
||||
*
|
||||
*/
|
||||
|
||||
class WXDLLEXPORT wxDC;
|
||||
class WXDLLEXPORT wxMetaFile: public wxObject
|
||||
#define wxMetaFile wxMetafile
|
||||
#define wxMetaFileDC wxMetafileDC
|
||||
|
||||
class WXDLLEXPORT wxMetafile;
|
||||
|
||||
class WXDLLEXPORT wxMetafileRefData: public wxGDIRefData
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS(wxMetaFile)
|
||||
friend class WXDLLEXPORT wxMetafile;
|
||||
public:
|
||||
wxMetafileRefData(void);
|
||||
~wxMetafileRefData(void);
|
||||
|
||||
public:
|
||||
WXHANDLE m_metafile;
|
||||
int m_windowsMappingMode;
|
||||
};
|
||||
|
||||
#define M_METAFILEDATA ((wxMetafileRefData *)m_refData)
|
||||
|
||||
class WXDLLEXPORT wxMetafile: public wxGDIObject
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS(wxMetafile)
|
||||
public:
|
||||
wxMetaFile(const wxString& file = "");
|
||||
~wxMetaFile(void);
|
||||
// Copy constructor
|
||||
inline wxMetafile(const wxMetafile& metafile)
|
||||
{ Ref(metafile); }
|
||||
|
||||
wxMetafile(const wxString& file = "");
|
||||
~wxMetafile(void);
|
||||
|
||||
// After this is called, the metafile cannot be used for anything
|
||||
// since it is now owned by the clipboard.
|
||||
virtual bool SetClipboard(int width = 0, int height = 0);
|
||||
|
||||
virtual bool Play(wxDC *dc);
|
||||
inline bool Ok(void) { return m_metaFile != 0; };
|
||||
inline bool Ok(void) const { return (M_METAFILEDATA && (M_METAFILEDATA->m_metafile != 0)); };
|
||||
|
||||
// Implementation
|
||||
inline WXHANDLE GetHMETAFILE(void) { return m_metaFile; }
|
||||
inline void SetHMETAFILE(WXHANDLE mf) { m_metaFile = mf; }
|
||||
inline int GetWindowsMappingMode(void) { return m_windowsMappingMode; }
|
||||
inline void SetWindowsMappingMode(int mm) { m_windowsMappingMode = mm; }
|
||||
inline WXHANDLE GetHMETAFILE(void) { return M_METAFILEDATA->m_metafile; }
|
||||
void SetHMETAFILE(WXHANDLE mf) ;
|
||||
inline int GetWindowsMappingMode(void) { return M_METAFILEDATA->m_windowsMappingMode; }
|
||||
void SetWindowsMappingMode(int mm);
|
||||
|
||||
// Operators
|
||||
inline wxMetafile& operator = (const wxMetafile& metafile) { if (*this == metafile) return (*this); Ref(metafile); return *this; }
|
||||
inline bool operator == (const wxMetafile& metafile) { return m_refData == metafile.m_refData; }
|
||||
inline bool operator != (const wxMetafile& metafile) { return m_refData != metafile.m_refData; }
|
||||
|
||||
protected:
|
||||
WXHANDLE m_metaFile;
|
||||
int m_windowsMappingMode;
|
||||
};
|
||||
|
||||
class WXDLLEXPORT wxMetaFileDC: public wxDC
|
||||
class WXDLLEXPORT wxMetafileDC: public wxDC
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS(wxMetaFileDC)
|
||||
DECLARE_DYNAMIC_CLASS(wxMetafileDC)
|
||||
|
||||
public:
|
||||
// Don't supply origin and extent
|
||||
// Supply them to wxMakeMetaFilePlaceable instead.
|
||||
wxMetaFileDC(const wxString& file = "");
|
||||
wxMetafileDC(const wxString& file = "");
|
||||
|
||||
// Supply origin and extent (recommended).
|
||||
// Then don't need to supply them to wxMakeMetaFilePlaceable.
|
||||
wxMetaFileDC(const wxString& file, int xext, int yext, int xorg, int yorg);
|
||||
wxMetafileDC(const wxString& file, int xext, int yext, int xorg, int yorg);
|
||||
|
||||
~wxMetaFileDC(void);
|
||||
~wxMetafileDC(void);
|
||||
|
||||
// Should be called at end of drawing
|
||||
virtual wxMetaFile *Close(void);
|
||||
virtual wxMetafile *Close(void);
|
||||
virtual void SetMapMode(int mode);
|
||||
virtual void GetTextExtent(const wxString& string, long *x, long *y,
|
||||
long *descent = NULL, long *externalLeading = NULL,
|
||||
wxFont *theFont = NULL, bool use16bit = FALSE) const;
|
||||
|
||||
// Implementation
|
||||
inline wxMetaFile *GetMetaFile(void) { return m_metaFile; }
|
||||
inline void SetMetaFile(wxMetaFile *mf) { m_metaFile = mf; }
|
||||
inline int GetWindowsMappingMode(void) { return m_windowsMappingMode; }
|
||||
inline wxMetafile *GetMetaFile(void) const { return m_metaFile; }
|
||||
inline void SetMetaFile(wxMetafile *mf) { m_metaFile = mf; }
|
||||
inline int GetWindowsMappingMode(void) const { return m_windowsMappingMode; }
|
||||
inline void SetWindowsMappingMode(int mm) { m_windowsMappingMode = mm; }
|
||||
|
||||
protected:
|
||||
int m_windowsMappingMode;
|
||||
wxMetaFile *m_metaFile;
|
||||
int m_windowsMappingMode;
|
||||
wxMetafile* m_metaFile;
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -94,11 +124,55 @@ protected:
|
||||
*/
|
||||
|
||||
// No origin or extent
|
||||
bool WXDLLEXPORT wxMakeMetaFilePlaceable(const wxString& filename, float scale = 1.0);
|
||||
#define wxMakeMetaFilePlaceable wxMakeMetafilePlaceable
|
||||
bool WXDLLEXPORT wxMakeMetafilePlaceable(const wxString& filename, float scale = 1.0);
|
||||
|
||||
// Optional origin and extent
|
||||
bool WXDLLEXPORT wxMakeMetaFilePlaceable(const wxString& filename, int x1, int y1, int x2, int y2, float scale = 1.0, bool useOriginAndExtent = TRUE);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxMetafileDataObject is a specialization of wxDataObject for metafile data
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// TODO: implement OLE side of things. At present, it's just for clipboard
|
||||
// use.
|
||||
|
||||
#if wxUSE_DRAG_AND_DROP
|
||||
class WXDLLEXPORT wxMetafileDataObject : public wxDataObject
|
||||
{
|
||||
public:
|
||||
// ctors
|
||||
wxMetafileDataObject() { m_width = 0; m_height = 0; };
|
||||
wxMetafileDataObject(const wxMetafile& metafile, int width = 0, int height = 0):
|
||||
m_metafile(metafile), m_width(width), m_height(height) { }
|
||||
|
||||
void SetMetafile(const wxMetafile& metafile, int w = 0, int h = 0)
|
||||
{ m_metafile = metafile; m_width = w; m_height = h; }
|
||||
wxMetafile GetMetafile() const { return m_metafile; }
|
||||
int GetWidth() const { return m_width; }
|
||||
int GetHeight() const { return m_height; }
|
||||
|
||||
virtual wxDataFormat GetFormat() const { return wxDF_METAFILE; }
|
||||
|
||||
/* ??
|
||||
// implement base class pure virtuals
|
||||
virtual wxDataFormat GetPreferredFormat() const
|
||||
{ return (wxDataFormat) wxDataObject::Text; }
|
||||
virtual bool IsSupportedFormat(wxDataFormat format) const
|
||||
{ return format == wxDataObject::Text || format == wxDataObject::Locale; }
|
||||
virtual size_t GetDataSize() const
|
||||
{ return m_strText.Len() + 1; } // +1 for trailing '\0'of course
|
||||
virtual void GetDataHere(void *pBuf) const
|
||||
{ memcpy(pBuf, m_strText.c_str(), GetDataSize()); }
|
||||
*/
|
||||
|
||||
private:
|
||||
wxMetafile m_metafile;
|
||||
int m_width;
|
||||
int m_height;
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif // wxUSE_METAFILE
|
||||
#endif
|
||||
// _WX_METAFIILE_H_
|
||||
|
@@ -73,6 +73,9 @@ public:
|
||||
// retrieve IDataObject interface (for other OLE related classes)
|
||||
IDataObject *GetInterface() const { return m_pIDataObject; }
|
||||
|
||||
////// wxGTK compatibility: hopefully to become the preferred API.
|
||||
virtual wxDataFormat GetFormat() const { return GetPreferredFormat(); }
|
||||
|
||||
private:
|
||||
IDataObject *m_pIDataObject; // pointer to the COM interface
|
||||
};
|
||||
@@ -98,6 +101,11 @@ public:
|
||||
virtual void GetDataHere(void *pBuf) const
|
||||
{ memcpy(pBuf, m_strText.c_str(), GetDataSize()); }
|
||||
|
||||
////// wxGTK compatibility: hopefully to become the preferred API.
|
||||
void SetText(const wxString& strText) { m_strText = strText; }
|
||||
wxString GetText() const { return m_strText; }
|
||||
virtual wxDataFormat GetFormat() const { return wxDF_TEXT; }
|
||||
|
||||
private:
|
||||
wxString m_strText;
|
||||
};
|
||||
@@ -106,4 +114,42 @@ private:
|
||||
// @@@ TODO: wx{Bitmap|Metafile|...}DataObject
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxBitmapDataObject is a specialization of wxDataObject for bitmap data
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// TODO: implement OLE side of things. At present, it's just for clipboard
|
||||
// use.
|
||||
class WXDLLEXPORT wxBitmapDataObject : public wxDataObject
|
||||
{
|
||||
public:
|
||||
// ctors
|
||||
wxBitmapDataObject() {};
|
||||
wxBitmapDataObject(const wxBitmap& bitmap): m_bitmap(bitmap) {}
|
||||
void SetBitmap(const wxBitmap& bitmap) { m_bitmap = bitmap; }
|
||||
wxBitmap GetBitmap() const { return m_bitmap; }
|
||||
|
||||
virtual wxDataFormat GetFormat() const { return wxDF_BITMAP; }
|
||||
|
||||
/* ??
|
||||
// implement base class pure virtuals
|
||||
virtual wxDataFormat GetPreferredFormat() const
|
||||
{ return (wxDataFormat) wxDataObject::Text; }
|
||||
virtual bool IsSupportedFormat(wxDataFormat format) const
|
||||
{ return format == wxDataObject::Text || format == wxDataObject::Locale; }
|
||||
virtual size_t GetDataSize() const
|
||||
{ return m_strText.Len() + 1; } // +1 for trailing '\0'of course
|
||||
virtual void GetDataHere(void *pBuf) const
|
||||
{ memcpy(pBuf, m_strText.c_str(), GetDataSize()); }
|
||||
*/
|
||||
|
||||
private:
|
||||
wxBitmap m_bitmap;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxMetaFileDataObject: see metafile.h is a specialization of wxDataObject for bitmap data
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#endif //_WX_OLEDATAOBJ_H
|
||||
|
||||
|
Reference in New Issue
Block a user