1. wxPostEvent added and documented
2. Made it possible to have wxDataObjects which support multiple formats painlessly 3. Extensively modified dnd sample to show a "real life" wxDataObject git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4028 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -12,7 +12,6 @@
|
||||
#ifndef _WX_OLEDATAOBJ_H
|
||||
#define _WX_OLEDATAOBJ_H
|
||||
|
||||
#include "wx/bitmap.h"
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDataFormat identifies the single format of data
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -68,75 +67,85 @@ struct IDataObject;
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDataObject is a "smart" and polymorphic piece of data.
|
||||
//
|
||||
// TODO it's currently "read-only" from COM point of view, i.e. we don't support
|
||||
// SetData. We don't support all advise functions neither (but it's easy to
|
||||
// do if we really want them)
|
||||
// TODO it's currently "read-only" from COM point of view, i.e. we don't
|
||||
// support SetData. We don't support all advise functions neither (but
|
||||
// it's easy to do if we really want them)
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class WXDLLEXPORT wxDataObject
|
||||
{
|
||||
public:
|
||||
// function to return symbolic name of clipboard format (debug messages)
|
||||
static const char *GetFormatName(wxDataFormat format);
|
||||
// ctor & dtor
|
||||
wxDataObject();
|
||||
virtual ~wxDataObject();
|
||||
|
||||
// ctor & dtor
|
||||
wxDataObject();
|
||||
virtual ~wxDataObject();
|
||||
// pure virtuals to override
|
||||
// get the best suited format for our data
|
||||
virtual wxDataFormat GetPreferredFormat() const = 0;
|
||||
// get the number of formats we support
|
||||
virtual size_t GetFormatCount() const
|
||||
{ return 1; }
|
||||
// return all formats in the provided array (of size GetFormatCount())
|
||||
virtual void GetAllFormats(wxDataFormat *formats) const
|
||||
{ formats[0] = GetPreferredFormat(); }
|
||||
// get the (total) size of data for the given format
|
||||
virtual size_t GetDataSize(const wxDataFormat& format) const = 0;
|
||||
// copy raw data (in the specified format) to provided pointer
|
||||
virtual void GetDataHere(const wxDataFormat& format, void *pBuf) const = 0;
|
||||
|
||||
// pure virtuals to override
|
||||
// get the best suited format for our data
|
||||
virtual wxDataFormat GetPreferredFormat() const = 0;
|
||||
// decide if we support this format (should be one of values of
|
||||
// wxDataFormatId enumerations or a user-defined format)
|
||||
virtual bool IsSupportedFormat(wxDataFormat format) const = 0;
|
||||
// get the (total) size of data
|
||||
virtual size_t GetDataSize() const = 0;
|
||||
// copy raw data to provided pointer
|
||||
virtual void GetDataHere(void *pBuf) const = 0;
|
||||
// accessors
|
||||
// retrieve IDataObject interface (for other OLE related classes)
|
||||
IDataObject *GetInterface() const { return m_pIDataObject; }
|
||||
// a simpler name which makes more sense for data objects supporting
|
||||
// only one format
|
||||
wxDataFormat GetFormat() const { return GetPreferredFormat(); }
|
||||
|
||||
// accessors
|
||||
// retrieve IDataObject interface (for other OLE related classes)
|
||||
IDataObject *GetInterface() const { return m_pIDataObject; }
|
||||
// old interface
|
||||
// decide if we support this format (can be either standard or custom
|
||||
// format) -- now uses GetAllFormats()
|
||||
virtual bool IsSupportedFormat(const wxDataFormat& format) const;
|
||||
|
||||
////// wxGTK compatibility: hopefully to become the preferred API.
|
||||
virtual wxDataFormat GetFormat() const { return GetPreferredFormat(); }
|
||||
#ifdef __WXDEBUG__
|
||||
// function to return symbolic name of clipboard format (for debug messages)
|
||||
static const char *GetFormatName(wxDataFormat format);
|
||||
#endif // Debug
|
||||
|
||||
private:
|
||||
IDataObject *m_pIDataObject; // pointer to the COM interface
|
||||
IDataObject *m_pIDataObject; // pointer to the COM interface
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxTextDataObject is a specialization of wxDataObject for text data
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class WXDLLEXPORT wxTextDataObject : public wxDataObject
|
||||
{
|
||||
public:
|
||||
// ctors
|
||||
wxTextDataObject() { }
|
||||
wxTextDataObject(const wxString& strText) : m_strText(strText) { }
|
||||
void Init(const wxString& strText) { m_strText = strText; }
|
||||
// ctors
|
||||
wxTextDataObject() { }
|
||||
wxTextDataObject(const wxString& strText) : m_strText(strText) { }
|
||||
void Init(const wxString& strText) { m_strText = strText; }
|
||||
|
||||
// implement base class pure virtuals
|
||||
virtual wxDataFormat GetPreferredFormat() const
|
||||
{ return wxDF_TEXT; }
|
||||
virtual bool IsSupportedFormat(wxDataFormat format) const
|
||||
{ return format == wxDF_TEXT || format == wxDF_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()); }
|
||||
// implement base class pure virtuals
|
||||
virtual wxDataFormat GetPreferredFormat() const
|
||||
{ return wxDF_TEXT; }
|
||||
virtual bool IsSupportedFormat(const wxDataFormat& format) const
|
||||
{ return format == wxDF_TEXT || format == wxDF_LOCALE; }
|
||||
virtual size_t GetDataSize(const wxDataFormat& format) const
|
||||
{ return m_strText.Len() + 1; } // +1 for trailing '\0'of course
|
||||
virtual void GetDataHere(const wxDataFormat& format, void *pBuf) const
|
||||
{ memcpy(pBuf, m_strText.c_str(), GetDataSize(format)); }
|
||||
|
||||
////// 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; }
|
||||
// additional helpers
|
||||
void SetText(const wxString& strText) { m_strText = strText; }
|
||||
wxString GetText() const { return m_strText; }
|
||||
|
||||
private:
|
||||
wxString m_strText;
|
||||
wxString m_strText;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// @@@ TODO: wx{Bitmap|Metafile|...}DataObject
|
||||
// TODO: wx{Bitmap|Metafile|...}DataObject
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -145,29 +154,29 @@ private:
|
||||
|
||||
// TODO: implement OLE side of things. At present, it's just for clipboard
|
||||
// use.
|
||||
#include "wx/bitmap.h"
|
||||
|
||||
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; }
|
||||
// ctors
|
||||
wxBitmapDataObject() { }
|
||||
wxBitmapDataObject(const wxBitmap& bitmap): m_bitmap(bitmap) { }
|
||||
|
||||
virtual wxDataFormat GetFormat() const { return wxDF_BITMAP; }
|
||||
// set/get our bitmap
|
||||
void SetBitmap(const wxBitmap& bitmap) { m_bitmap = bitmap; }
|
||||
const wxBitmap GetBitmap() const { return m_bitmap; }
|
||||
|
||||
// implement base class pure virtuals
|
||||
virtual wxDataFormat GetPreferredFormat() const
|
||||
{ return wxDF_BITMAP; }
|
||||
virtual bool IsSupportedFormat(wxDataFormat format) const
|
||||
{ return format == wxDF_BITMAP; }
|
||||
virtual size_t GetDataSize() const
|
||||
{ wxASSERT(FALSE); return 0; } // BEMIMP
|
||||
virtual void GetDataHere(void *pBuf) const
|
||||
{ wxASSERT(FALSE); } // BEMIMP
|
||||
// implement base class pure virtuals
|
||||
virtual wxDataFormat GetPreferredFormat() const
|
||||
{ return wxDF_BITMAP; }
|
||||
virtual bool IsSupportedFormat(const wxDataFormat& format) const
|
||||
{ return format == wxDF_BITMAP; }
|
||||
virtual size_t GetDataSize(const wxDataFormat& format) const;
|
||||
virtual void GetDataHere(const wxDataFormat& format, void *pBuf) const;
|
||||
|
||||
private:
|
||||
wxBitmap m_bitmap;
|
||||
wxBitmap m_bitmap;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user