From e1ee679c2e3f48bc4f2607e35033ed5505ed6665 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 21 Oct 1999 00:25:42 +0000 Subject: [PATCH] wxDataObejct and related changes (won't compile right now) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4089 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/clipbrd.h | 125 +++++++++- include/wx/dataobj.h | 435 +++++++++++++++++++++++++++++----- include/wx/defs.h | 1 + include/wx/dnd.h | 135 ++++++++++- include/wx/gtk/clipbrd.h | 57 +---- include/wx/gtk/dataform.h | 60 +++++ include/wx/gtk/dataobj.h | 251 +------------------- include/wx/gtk1/clipbrd.h | 57 +---- include/wx/gtk1/dataform.h | 60 +++++ include/wx/gtk1/dataobj.h | 251 +------------------- include/wx/motif/clipbrd.h | 136 ++--------- include/wx/motif/dataform.h | 54 +++++ include/wx/msw/clipbrd.h | 26 +- include/wx/msw/ole/dataform.h | 68 ++++++ include/wx/msw/ole/dataobj.h | 61 +---- include/wx/msw/ole/dropsrc.h | 60 ++--- include/wx/msw/ole/droptgt.h | 54 ++--- src/common/appcmn.cpp | 6 + src/gtk/clipbrd.cpp | 25 +- src/gtk/dataobj.cpp | 168 ++++--------- src/gtk1/clipbrd.cpp | 25 +- src/gtk1/dataobj.cpp | 168 ++++--------- src/motif/clipbrd.cpp | 20 -- src/msw/clipbrd.cpp | 19 -- src/msw/ole/dropsrc.cpp | 5 - 25 files changed, 1093 insertions(+), 1234 deletions(-) create mode 100644 include/wx/gtk/dataform.h create mode 100644 include/wx/gtk1/dataform.h create mode 100644 include/wx/motif/dataform.h create mode 100644 include/wx/msw/ole/dataform.h diff --git a/include/wx/clipbrd.h b/include/wx/clipbrd.h index 36a95b0638..6ce90e1982 100644 --- a/include/wx/clipbrd.h +++ b/include/wx/clipbrd.h @@ -1,21 +1,128 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wx/clipbrd.h +// Purpose: wxClipboad class and clipboard functions +// Author: Vadim Zeitlin +// Modified by: +// Created: 19.10.99 +// RCS-ID: $Id$ +// Copyright: (c) wxWindows Team +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + #ifndef _WX_CLIPBRD_H_BASE_ #define _WX_CLIPBRD_H_BASE_ +#include "wx/defs.h" + +#if wxUSE_CLIPBOARD + +#include "wx/object.h" +#include "wx/wxchar.h" + +class WXDLLEXPORT wxDataFormat; +class WXDLLEXPORT wxDataObject; + +// ---------------------------------------------------------------------------- +// wxClipboard represents the system clipboard. Normally, you should use +// wxTheClipboard which is a global pointer to the (unique) clipboard. +// +// Clipboard can be used to copy data to/paste data from. It works together +// with wxDataObject. +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxClipboardBase : public wxObject +{ +public: + // open the clipboard before Add/SetData() and GetData() + virtual bool Open(); + + // close the clipboard after Add/SetData() and GetData() + virtual void Close(); + + // add to the clipboard data + // + // NB: the clipboard owns the pointer and will delete it, so data must be + // allocated on the heap + virtual bool AddData( wxDataObject *data ); + + // set the clipboard data, this is the same as Clear() followed by + // AddData() + virtual bool SetData( wxDataObject *data ); + + // ask if data in correct format is available + virtual bool IsSupported( const wxDataFormat& format ); + + // 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(); + + // flushes the clipboard: this means that the data which is currently on + // clipboard will stay available even after the application exits (possibly + // eating memory), otherwise the clipboard will be emptied on exit + virtual bool Flush() { return FALSE; } + + // X11 has two clipboards which get selected by this call. Empty on MSW. + virtual void UsePrimarySelection( bool WXUNUSED(primary) = FALSE ) { } + +#ifdef WXWIN_COMPATIBILITY_2 + // deprecated version + bool GetData(wxDataObject *data) + { + wxCHECK_MSG(data, FALSE, wxT("NULL pointer in wxClipboard")); + + return GetData(*data); + } +#endif // WXWIN_COMPATIBILITY_2 +}; + +// ---------------------------------------------------------------------------- +// include platform-specific class declaration +// ---------------------------------------------------------------------------- + #if defined(__WXMSW__) -#include "wx/msw/clipbrd.h" + #include "wx/msw/clipbrd.h" #elif defined(__WXMOTIF__) -#include "wx/motif/clipbrd.h" + #include "wx/motif/clipbrd.h" #elif defined(__WXGTK__) -#include "wx/gtk/clipbrd.h" + #include "wx/gtk/clipbrd.h" #elif defined(__WXQT__) -#include "wx/gtk/clipbrd.h" + #include "wx/gtk/clipbrd.h" #elif defined(__WXMAC__) -#include "wx/mac/clipbrd.h" + #include "wx/mac/clipbrd.h" #elif defined(__WXPM__) -#include "wx/os2/clipbrd.h" + #include "wx/os2/clipbrd.h" #elif defined(__WXSTUBS__) -#include "wx/stubs/clipbrd.h" + #include "wx/stubs/clipbrd.h" #endif -#endif - // _WX_CLIPBRD_H_BASE_ +// ---------------------------------------------------------------------------- +// globals +// ---------------------------------------------------------------------------- + +// The global clipboard object +WXDLLEXPORT_DATA(extern wxClipboard *) wxTheClipboard; + +// ---------------------------------------------------------------------------- +// wxClipboardModule: module responsible for initializing the global clipboard +// object +// +// NB: IMPLEMENT_DYNAMIC_CLASS() for it is in common/appcmn.cpp +// ---------------------------------------------------------------------------- + +class wxClipboardModule : public wxModule +{ +public: + bool OnInit() + { wxTheClipboard = new wxClipboard; } + void OnExit() + { delete wxTheClipboard; wxTheClipboard = (wxClipboard *)NULL; } + +private: + DECLARE_DYNAMIC_CLASS(wxClipboardModule) +}; + +#endif // wxUSE_CLIPBOARD + +#endif // _WX_CLIPBRD_H_BASE_ diff --git a/include/wx/dataobj.h b/include/wx/dataobj.h index c17f2f8341..9ef5f2bc7f 100644 --- a/include/wx/dataobj.h +++ b/include/wx/dataobj.h @@ -1,7 +1,7 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: dataobj.h +// Name: wx/dataobj.h // Purpose: common data object classes -// Author: Robert Roebling, Vadim Zeitlin +// Author: Vadim Zeitlin, Robert Roebling // Modified by: // Created: 26.05.99 // RCS-ID: $Id$ @@ -12,6 +12,135 @@ #ifndef _WX_DATAOBJ_H_BASE_ #define _WX_DATAOBJ_H_BASE_ +#ifdef __GNUG__ + #pragma interface "dataobjbase.h" +#endif + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#include "wx/defs.h" +#include "wx/string.h" +#include "wx/bitmap.h" +#include "wx/list.h" + +// ============================================================================ +/* + Generic data transfer related classes. The class hierarchy is as follows: + + - wxDataObject- + / \ + / \ + wxDataObjectSimple wxDataObjectComposite + / | \ + / | \ + wxTextDataObject | wxBitmapDataObject + | + wxCustomDataObject + +*/ +// ============================================================================ + +// ---------------------------------------------------------------------------- +// wxDataFormat class is declared in platform-specific headers: it represents +// a format for data which may be either one of the standard ones (text, +// bitmap, ...) or a custom one which is then identified by a unique string. +// ---------------------------------------------------------------------------- + +/* the class interface looks like this (pseudo code): + +class wxDataFormat +{ +public: + typedef NativeFormat; + + wxDataFormat(NativeFormat format = wxDF_INVALID); + wxDataFormat(const wxChar *format); + + wxDataFormat& operator=(NativeFormat format); + wxDataFormat& operator=(const wxDataFormat& format); + + bool operator==(NativeFormat format) const; + bool operator!=(NativeFormat format) const; + + void SetType(NativeFormat format); + NativeFormat GetType() const; + + wxString GetId() const; + void SetId(const wxChar *format); +}; + +*/ + +#if defined(__WXMSW__) + #include "wx/msw/ole/dataform.h" +#elif defined(__WXMOTIF__) + #include "wx/motif/dataform.h" +#elif defined(__WXGTK__) + #include "wx/gtk/dataform.h" +#endif + +// ---------------------------------------------------------------------------- +// wxDataObject represents a piece of data which knows which formats it +// supports and knows how to render itself in each of them - GetDataHere(), +// and how to restore data from the buffer (SetData()). +// +// Although this class may be used directly (i.e. custom classes may be +// derived from it), in many cases it might be simpler to use either +// wxDataObjectSimple or wxDataObjectComposite classes. +// +// A data object may be "read only", i.e. support only GetData() functions or +// "read-write", i.e. support both GetData() and SetData() (in principle, it +// might be "write only" too, but this is rare). Moreover, it doesn't have to +// support the same formats in Get() and Set() directions: for example, a data +// object containing JPEG image might accept BMPs in GetData() because JPEG +// image may be easily transformed into BMP but not in SetData(). Accordingly, +// all methods dealing with formats take an additional "direction" argument +// which is either SET or GET and which tells the function if the format needs +// to be supported by SetData() or GetDataHere(). +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxDataObjectBase +{ +public: + enum Direction + { + Get = 0x01, // format is supported by GetDataHere() + Set = 0x02, // format is supported by SetData() + Both = 0x03 // format is supported by both (unused currently) + }; + + // this class is polymorphic, hence it needs a virtual dtor + virtual ~wxDataObjectBase(); + + // get the best suited format for rendering our data + virtual wxDataFormat GetPreferredFormat(Direction dir = Get) const = 0; + + // get the number of formats we support + virtual size_t GetFormatCount(Direction dir = Get) const = 0; + + // return all formats in the provided array (of size GetFormatCount()) + virtual void GetAllFormats(wxDataFormat *formats, + Direction dir = Get) const = 0; + + // 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 the provided buffer, return + // TRUE if data copied successfully, FALSE otherwise + virtual bool GetDataHere(const wxDataFormat& format, void *buf) const = 0; + + // get data from the buffer of specified length (in the given format), + // return TRUE if the data was read successfully, FALSE otherwise + virtual bool SetData(const wxDataFormat& format, + size_t len, const void *buf) = 0; +}; + +// ---------------------------------------------------------------------------- +// include the platform-specific declarations of wxDataObject +// ---------------------------------------------------------------------------- + #if defined(__WXMSW__) #include "wx/msw/ole/dataobj.h" #elif defined(__WXMOTIF__) @@ -28,71 +157,267 @@ #include "wx/stubs/dnd.h" #endif -// --------------------------------------------------------------------------- -// wxPrivateDataObject is a specialization of wxDataObject for app specific -// data (of some given kind, derive directly from wxDataObject if you wish to -// efficiently support multiple formats) -// --------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- +// wxDataObjectSimple is a wxDataObject which only supports one format (in +// both Get and Set directions, but you may return FALSE from GetDataHere() or +// SetData() if one of them is not supported). This is the simplest possible +// wxDataObject implementation. +// +// This is still an "abstract base class" (although it doesn't have any pure +// virtual functions), to use it you should derive from it and implement +// GetDataSize(), GetDataHere() and SetData() functions because the base class +// versions don't do anything - they just return "not implemented". +// +// This class should be used when you provide data in only one format (no +// conversion to/from other formats), either a standard or a custom one. +// Otherwise, you should use wxDataObjectComposite or wxDataObject directly. +// ---------------------------------------------------------------------------- -class WXDLLEXPORT wxPrivateDataObject : public wxDataObject +class WXDLLEXPORT wxDataObjectSimple : public wxDataObject { -#if defined(__WXGTK__) || defined(__WXMOTIF__) - DECLARE_CLASS( wxPrivateDataObject ) -#endif - public: - wxPrivateDataObject(); - virtual ~wxPrivateDataObject() { Free(); } + // ctor takes the format we support, but it can also be set later with + // SetFormat() + wxDataObjectSimple(const wxDataFormat& format = wxDF_INVALID) + : m_format(format) + { + } - // get the format object - it is used to decide whether we support the - // given output format or not - wxDataFormat& GetFormat() { return m_format; } + // get/set the format we support + const wxDataFormat& GetFormat() const { return m_format; } + void SetFormat(const wxDataFormat& format) { m_format = format; } - // set data. will make copy of the data - void SetData( const void *data, size_t size ); + // virtual functions to override in derived class (the base class versions + // just return "not implemented") + // ----------------------------------------------------------------------- - // returns pointer to data - void *GetData() const { return m_data; } - - // get the size of the data - virtual size_t GetSize() const; - - // copy data to the given buffer - virtual void WriteData( void *dest ) const; - - // these functions are provided for wxGTK compatibility, their usage is - // deprecated - use GetFormat().SetId() instead - void SetId( const wxString& id ) { m_format.SetId(id); } - wxString GetId() const { return m_format.GetId(); } - - // implement the base class pure virtuals - virtual wxDataFormat GetPreferredFormat() const - { return m_format; } - virtual bool IsSupportedFormat(wxDataFormat format) const - { return m_format == format; } + // get the size of our data virtual size_t GetDataSize() const - { return m_size; } - virtual void GetDataHere(void *dest) const - { WriteData(dest); } + { return 0; } - // the function which really copies the data - called by WriteData() above - // and uses GetSize() to get the size of the data - void WriteData( const void *data, void *dest ) const; + // copy our data to the buffer + virtual bool GetDataHere(void *WXUNUSED(buf)) const + { return FALSE; } + + // copy data from buffer to our data + virtual bool SetData(size_t len, const void *WXUNUSED(buf)) + { return FALSE; } + + // implement base class pure virtuals + // ---------------------------------- + virtual wxDataFormat GetPreferredFormat(Direction WXUNUSED(dir) = Get) const + { return m_format; } + virtual size_t GetFormatCount(Direction WXUNUSED(dir) = Get) const + { return 1; } + virtual void GetAllFormats(wxDataFormat *formats, + Direction WXUNUSED(dir) = Get) const + { *formats = m_format; } + virtual size_t GetDataSize(const wxDataFormat& WXUNUSED(format)) const + { return GetDataSize(); } + virtual bool GetDataHere(const wxDataFormat& WXUNUSED(format), + void *buf) const + { return GetDataHere(buf); } + virtual bool SetData(const wxDataFormat& WXUNUSED(format), + size_t len, const void *buf) + { return SetData(len, buf); } private: - // free the data - void Free(); - - // the data - size_t m_size; - void *m_data; - -#if !defined(__WXMOTIF__) - // the data format + // the one and only format we support wxDataFormat m_format; -#endif }; +// ---------------------------------------------------------------------------- +// wxDataObjectComposite is the simplest way to implement wxDataObject +// supporting multiple formats. It contains several wxDataObjectSimple and +// supports all formats supported by any of them. +// +// This class shouldn't be (normally) derived from, but may be used directly. +// If you need more flexibility than what it provides, you should probably use +// wxDataObject directly. +// ---------------------------------------------------------------------------- +WX_DECLARE_LIST(wxDataObjectSimple, wxSimpleDataObjectList); + +class WXDLLEXPORT wxDataObjectComposite : public wxDataObject +{ +public: + // ctor + wxDataObjectComposite() { m_preferred = 0; } + + // add data object (it will be deleted by wxDataObjectComposite, hence it + // must be allocated on the heap) whose format will become the preferred + // one if preferred == TRUE + void Add(wxDataObjectSimple *dataObject, bool preferred = FALSE); + + // implement base class pure virtuals + // ---------------------------------- + virtual wxDataFormat GetPreferredFormat(Direction dir = Get) const; + virtual size_t GetFormatCount(Direction dir = Get) const; + virtual void GetAllFormats(wxDataFormat *formats, Direction dir = Get) const; + virtual size_t GetDataSize(const wxDataFormat& format) const; + virtual bool GetDataHere(const wxDataFormat& format, void *buf) const; + virtual bool SetData(const wxDataFormat& format, size_t len, const void *buf); + +protected: + // returns the pointer to the object which supports this format or NULL + wxDataObjectSimple *GetObject(const wxDataFormat& format) const; + +private: + // the list of all (simple) data objects whose formats we support + wxSimpleDataObjectList m_dataObjects; + + // the index of the preferred one (0 initially, so by default the first + // one is the preferred) + size_t m_preferred; +}; + +// ============================================================================ +// Standard implementations of wxDataObjectSimple which can be used directly +// (i.e. without having to derive from them) for standard data type transfers. +// +// Note that although all of them can work with provided data, you can also +// override their virtual GetXXX() functions to only provide data on demand. +// ============================================================================ + +// ---------------------------------------------------------------------------- +// wxTextDataObject contains text data +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxTextDataObject : public wxDataObjectSimple +{ +public: + // ctor: you can specify the text here or in SetText(), or override + // GetText() + wxTextDataObject(const wxString& text = wxEmptyString) + : wxDataObjectSimple(wxDF_TEXT), m_text(text) + { + } + + // virtual functions which you may override if you want to provide text on + // demand only - otherwise, the trivial default versions will be used + virtual size_t GetTextLength() const { return m_text.Len() + 1; } + virtual wxString GetText() const { return m_text; } + virtual void SetText(const wxString& text) { m_text = text; } + + // implement base class pure virtuals + // ---------------------------------- + virtual size_t GetDataSize() const; + virtual bool GetDataHere(void *buf) const; + virtual bool SetData(size_t len, const void *buf); + +private: + wxString m_text; +}; + +// ---------------------------------------------------------------------------- +// wxBitmapDataObject contains a bitmap +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxBitmapDataObjectBase : public wxDataObjectSimple +{ +public: + // ctor: you can specify the bitmap here or in SetBitmap(), or override + // GetBitmap() + wxBitmapDataObjectBase(const wxBitmap& bitmap = wxNullBitmap) + : wxDataObjectSimple(wxDF_BITMAP), m_bitmap(bitmap) + { + } + + // virtual functions which you may override if you want to provide data on + // demand only - otherwise, the trivial default versions will be used + virtual wxBitmap GetBitmap() const { return m_bitmap; } + virtual void SetBitmap(const wxBitmap& bitmap) { m_bitmap = bitmap; } + +private: + wxBitmap m_bitmap; +}; + +// ---------------------------------------------------------------------------- +// wxFileDataObject contains a list of filenames +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxFileDataObjectBase : public wxDataObjectSimple +{ +public: + // ctor: you can specify the bitmap here or in SetBitmap(), or override + // GetBitmap() + wxFileDataObjectBase() : wxDataObjectSimple(wxDF_FILENAME) { } + + // get a reference to our array - you may modify it (i.e. add/remove + // filenames to it then) + wxArrayString& GetFilenames() { return m_filenames; } + + // a helper function + void AddFile(const wxString& filename) { m_filenames.Add(filename); } + + // virtual functions which you may override if you want to provide data on + // demand only - otherwise, the trivial default versions will be used. + // + // they work with a NUL-separated string of filenames, the base class + // versions concatenate/extract filenames from this string + virtual wxString GetFilenames() const; + virtual void SetFilenames(const wxChar* filenames); + +private: + wxArrayString m_filenames; +}; + +// ---------------------------------------------------------------------------- +// wxCustomDataObject contains arbitrary untyped user data. +// +// It is understood that this data can be copied bitwise. +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxCustomDataObject : public wxDataObjectSimple +{ +public: + // if you don't specify the format in the ctor, you can still use + // SetFormat() later + wxCustomDataObject(const wxDataFormat& format = wxDF_INVALID); + + // the dtor calls Free() + virtual ~wxCustomDataObject(); + + // you can call SetData() to set m_data: it will make a copy of the data + // you pass - or you can use TakeData() which won't copy anything, but + // will take ownership of data (i.e. will call Free() on it later) + void TakeData(size_t size, void *data); + + // this function is called to allocate "size" bytes of memory from + // SetData(). The default version uses operator new[]. + virtual void *Alloc(size_t size); + + // this function is called when the data is freed, you may override it to + // anything you want (or may be nothing at all). The default version calls + // operator delete[] on m_data + virtual void Free(); + + // get data: you may override these functions if you wish to provide data + // only when it's requested + virtual size_t GetSize() const { return m_size; } + virtual void *GetData() const { return m_data; } + + // implement base class pure virtuals + // ---------------------------------- + virtual size_t GetDataSize() const; + virtual bool GetDataHere(void *buf) const; + virtual bool SetData(size_t size, const void *buf); + +private: + size_t m_size; + void *m_data; +}; + +// ---------------------------------------------------------------------------- +// include platform-specific declarations of wxXXXBase classes +// ---------------------------------------------------------------------------- + +#if defined(__WXMSW__) + #include "wx/msw/ole/dataobj2.h" +#elif defined(__WXMOTIF__) + #include "wx/motif/dataobj2.h" +#elif defined(__WXGTK__) + #include "wx/gtk/dataobj2.h" #endif - // _WX_DATAOBJ_H_BASE_ + +#endif // _WX_DATAOBJ_H_BASE_ diff --git a/include/wx/defs.h b/include/wx/defs.h index fac7781467..0eb6c98144 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -1244,6 +1244,7 @@ typedef enum #define wxTOOL_RIGHT 4 +// tyhe ids of standard data formats enum wxDataFormatId { wxDF_INVALID = 0, diff --git a/include/wx/dnd.h b/include/wx/dnd.h index f6ddf89255..c201cf9992 100644 --- a/include/wx/dnd.h +++ b/include/wx/dnd.h @@ -1,23 +1,136 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: wx/dnd.h +// Purpose: Drag and drop classes declarations +// Author: Vadim Zeitlin, Robert Roebling +// Modified by: +// Created: 26.05.99 +// RCS-ID: $Id$ +// Copyright: (c) wxWindows Team +// Licence: wxWindows license +/////////////////////////////////////////////////////////////////////////////// + #ifndef _WX_DND_H_BASE_ #define _WX_DND_H_BASE_ -#if defined(__WXMSW__) +#include "wx/defs.h" + +#if wxUSE_DRAG_AND_DROP + #include "wx/dataobj.h" -#include "wx/msw/ole/dropsrc.h" -#include "wx/msw/ole/droptgt.h" + +// ---------------------------------------------------------------------------- +// constants +// ---------------------------------------------------------------------------- + +// result of wxDropSource::DoDragDrop() call +enum wxDragResult +{ + wxDragError, // error prevented the d&d operation from completing + wxDragNone, // drag target didn't accept the data + wxDragCopy, // the data was successfully copied + wxDragMove, // the data was successfully moved (MSW only) + wxDragCancel // the operation was cancelled by user (not an error) +}; + +// ---------------------------------------------------------------------------- +// wxDropSource is the object you need to create (and call DoDragDrop on it) +// to initiate a drag-and-drop operation +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxDropSourceBase +{ +public: + wxDropSourceBase() { m_data = (wxDataObject *)NULL; } + virtual ~wxDropSourceBase() { } + + // set the data which is transfered by drag and drop + void SetData(wxDataObject& data) { delete m_data; m_data = &data; } + + // start drag action, see enum wxDragResult for return value description + // + // if bAllowMove is TRUE, data can be moved, if not - only copied + virtual wxDragResult DoDragDrop( bool bAllowMove = FALSE ); + + // override to give feedback depending on the current operation result + // "effect" + virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), + bool WXUNUSED(bScrolling) ) + { + return TRUE; + } + +protected: + wxDataObject *m_data; +}; + +// ---------------------------------------------------------------------------- +// wxDropTarget should be associated with a window if it wants to be able to +// receive data via drag and drop +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxDropTargetBase +{ +public: + // ctor takes a pointer to heap-allocated wxDataObject which will be owned + // by wxDropTarget and deleted by it automatically. If you don't give it + // here, you can use SetDataObject() later. + wxDropTargetBase(wxDataObject *dataObject = NULL) + { m_dataObject = dataObject; } + // dtor deletes our data object + virtual ~wxDropTargetBase() + { delete m_dataObject; } + + // get/set the associated wxDataObject + wxDataObject *GetDataObject() const + { return m_dataObject; } + void SetDataObject(wxDataObject *dataObject) + { delete m_dataObject; m_dataObject = dataObject; } + + // called when mouse enters/leaves the window: might be used to give + // some visual feedback to the user + virtual void OnEnter() { } + virtual void OnLeave() { } + + // this function is called when data is dropped at position (x, y) - if it + // returns TRUE, OnData() will be called immediately afterwards which will + // allow to retrieve the data dropped. + virtual bool OnDrop(wxCoord x, wxCoord y) = 0; + + // called after OnDrop() returns TRUE: you will usually just call + // GetData() from here and, probably, also refresh something to update the + // new data + virtual bool OnData() = 0; + + // may be called *only* from inside OnData() and will fill m_dataObject + // with the data from the drop source if it returns TRUE + virtual bool GetData() = 0; + +protected: + wxDataObject *m_dataObject; +}; + +// ---------------------------------------------------------------------------- +// include platform dependent class declarations +// ---------------------------------------------------------------------------- + +#if defined(__WXMSW__) + #include "wx/dataobj.h" + #include "wx/msw/ole/dropsrc.h" + #include "wx/msw/ole/droptgt.h" #elif defined(__WXMOTIF__) -#include "wx/motif/dnd.h" + #include "wx/motif/dnd.h" #elif defined(__WXGTK__) -#include "wx/gtk/dnd.h" + #include "wx/gtk/dnd.h" #elif defined(__WXQT__) -#include "wx/qt/dnd.h" + #include "wx/qt/dnd.h" #elif defined(__WXMAC__) -#include "wx/mac/dnd.h" + #include "wx/mac/dnd.h" #elif defined(__WXPM__) -#include "wx/os2/dnd.h" + #include "wx/os2/dnd.h" #elif defined(__WXSTUBS__) -#include "wx/stubs/dnd.h" + #include "wx/stubs/dnd.h" #endif -#endif - // _WX_DND_H_BASE_ +#endif // wxUSE_DRAG_AND_DROP + +#endif // _WX_DND_H_BASE_ diff --git a/include/wx/gtk/clipbrd.h b/include/wx/gtk/clipbrd.h index 188ea58fcf..b6d2583e84 100644 --- a/include/wx/gtk/clipbrd.h +++ b/include/wx/gtk/clipbrd.h @@ -15,8 +15,6 @@ #pragma interface #endif -#include "wx/defs.h" - #if wxUSE_CLIPBOARD #include "wx/object.h" @@ -25,24 +23,11 @@ #include "wx/control.h" #include "wx/module.h" -//----------------------------------------------------------------------------- -// classes -//----------------------------------------------------------------------------- - -class wxClipboard; -class wxClipboardModule; - -//----------------------------------------------------------------------------- -// global data -//----------------------------------------------------------------------------- - -extern wxClipboard* wxTheClipboard; - -//----------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- // wxClipboard -//----------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- -class wxClipboard : public wxObject +class wxClipboard : public wxClipboardBase { public: wxClipboard(); @@ -61,22 +46,20 @@ public: virtual bool AddData( wxDataObject *data ); // ask if data in correct format is available - virtual bool IsSupported( wxDataFormat format ); + virtual bool IsSupported( const wxDataFormat& format ); // fill data with data on the clipboard (if available) - virtual bool GetData( wxDataObject *data ); + virtual bool GetData( wxDataObject& data ); // clears wxTheClipboard and the system's clipboard if possible virtual void Clear(); - // flushes the clipboard: not available under GTK - virtual bool Flush() { return FALSE; } + // If primary == TRUE, use primary selection in all further ops, + // primary == FALSE resets it. + virtual void UsePrimarySelection(bool primary = TRUE) + { m_usePrimary = primary; } - /// If primary == TRUE, use primary selection in all further ops, - /// primary=FALSE resets it. - inline void UsePrimarySelection(bool primary = TRUE) { m_usePrimary = primary; } - - // implementation + // implementation from now on bool m_open; bool m_ownsClipboard; bool m_ownsPrimarySelection; @@ -89,29 +72,13 @@ public: bool m_formatSupported; GdkAtom m_targetRequested; bool m_usePrimary; - wxDataObject *m_receivedData; - + wxDataObject *m_receivedData; + private: DECLARE_DYNAMIC_CLASS(wxClipboard) }; -//----------------------------------------------------------------------------- -// wxClipboardModule -//----------------------------------------------------------------------------- - -class wxClipboardModule: public wxModule -{ -public: - wxClipboardModule() {} - bool OnInit(); - void OnExit(); - -private: - DECLARE_DYNAMIC_CLASS(wxClipboardModule) -}; - #endif - // wxUSE_CLIPBOARD #endif diff --git a/include/wx/gtk/dataform.h b/include/wx/gtk/dataform.h new file mode 100644 index 0000000000..a0618e01af --- /dev/null +++ b/include/wx/gtk/dataform.h @@ -0,0 +1,60 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: gtk/dataform.h +// Purpose: declaration of the wxDataFormat class +// Author: Vadim Zeitlin +// Modified by: +// Created: 19.10.99 (extracted from gtk/dataobj.h) +// RCS-ID: $Id$ +// Copyright: (c) 1998 Vadim Zeitlin +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_GTK_DATAFORM_H +#define _WX_GTK_DATAFORM_H + +class wxDataFormat +{ +public: + // the clipboard formats under GDK are GdkAtoms + typedef GdkAtom NativeFormat; + + wxDataFormat(); + wxDataFormat( wxDataFormatId type ); + wxDataFormat( const wxString &id ); + wxDataFormat( const wxChar *id ); + wxDataFormat( NativeFormat format ); + + wxDataFormat& operator=(NativeFormat format) + { SetId(format); return *this; } + + // comparison (must have both versions) + bool operator==(NativeFormat format) const + { return m_format == (NativeFormat)format; } + bool operator!=(NativeFormat format) const + { return m_format != (NativeFormat)format; } + + // 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; } + + void SetId( NativeFormat format ); + + // string ids are used for custom types - this SetId() must be used for + // application-specific formats + wxString GetId() const; + void SetId( const wxChar *id ); + + // implementation + wxDataFormatId GetType() const; + +private: + wxDataFormatId m_type; + NativeFormat m_format; + + void PrepareFormats(); + void SetType( wxDataFormatId type ); +}; + +#endif // _WX_GTK_DATAFORM_H diff --git a/include/wx/gtk/dataobj.h b/include/wx/gtk/dataobj.h index 237674e3c6..79430ddce6 100644 --- a/include/wx/gtk/dataobj.h +++ b/include/wx/gtk/dataobj.h @@ -1,255 +1,26 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: dataobj.h -// Purpose: declaration of the wxDataObject class +// Name: gtk/dataobj.h +// Purpose: declaration of the wxDataObject // Author: Robert Roebling // RCS-ID: $Id$ -// Copyright: (c) 1998 Vadim Zeitlin, Robert Roebling +// Copyright: (c) 1998, 1999 Vadim Zeitlin, Robert Roebling // Licence: wxWindows license /////////////////////////////////////////////////////////////////////////////// -#ifndef __GTKDATAOBJECTH__ -#define __GTKDATAOBJECTH__ +#ifndef _WX_GTK_DATAOBJ_H_ +#define _WX_GTK_DATAOBJ_H_ #ifdef __GNUG__ -#pragma interface + #pragma interface "dataobj.h" #endif -#include "wx/defs.h" -#include "wx/object.h" -#include "wx/string.h" -#include "wx/bitmap.h" +// ---------------------------------------------------------------------------- +// wxDataObject is the same as wxDataObjectBase under wxGTK +// ---------------------------------------------------------------------------- -//------------------------------------------------------------------------- -// classes -//------------------------------------------------------------------------- - -class wxDataFormat; -class wxDataBroker; -class wxDataObject; -class wxTextDataObject; -class wxBitmapDataObject; -class wxPrivateDataObject; -class wxFileDataObject; - -//------------------------------------------------------------------------- -// wxDataFormat -//------------------------------------------------------------------------- - -class wxDataFormat +class wxDataObject : public wxDataObjectBase { -public: - // the clipboard formats under GDK are GdkAtoms - typedef GdkAtom NativeFormat; - - wxDataFormat(); - wxDataFormat( wxDataFormatId type ); - wxDataFormat( const wxString &id ); - wxDataFormat( const wxChar *id ); - wxDataFormat( NativeFormat format ); - - wxDataFormat& operator=(NativeFormat format) - { SetId(format); return *this; } - wxDataFormat& operator=(const wxDataFormat& format) - { SetId(format); return *this; } - - // comparison (must have both versions) - bool operator==(wxDataFormatId type) const - { return m_type == (wxDataFormatId)type; } - bool operator!=(wxDataFormatId type) const - { return m_type != (wxDataFormatId)type; } - bool operator==(NativeFormat format) const - { return m_format == (NativeFormat)format; } - bool operator!=(NativeFormat format) const - { return m_format != (NativeFormat)format; } - bool operator==(const wxDataFormat& format) const - { return m_format == format.m_format; } - bool operator!=(const wxDataFormat& format) const - { return m_format != format.m_format; } - - // 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; } - - // this only works with standard ids - void SetId( wxDataFormatId type ); - - // this only works with standard ids - void SetId( NativeFormat format ); - - // string ids are used for custom types - this SetId() must be used for - // application-specific formats - wxString GetId() const; - void SetId( const wxChar *id ); - - // implementation - wxDataFormatId GetType() const; - -private: - wxDataFormatId m_type; - NativeFormat m_format; - - void PrepareFormats(); - void SetType( wxDataFormatId type ); }; -//---------------------------------------------------------------------------- -// wxDataObject -//---------------------------------------------------------------------------- - -class wxDataObject : public wxObject -{ -public: - wxDataObject(); - ~wxDataObject(); - - virtual wxDataFormat GetPreferredFormat() const = 0; - - // get the number of formats we support: it is understood that if we - // can accept data in some format, then we can render data in this - // format as well, but the contrary is not necessarily true. For the - // default value of the argument, all formats we support should be - // returned, but if outputOnlyToo == FALSE, then we should only return - // the formats which our SetData() understands - virtual size_t GetFormatCount(bool outputOnlyToo = TRUE) const - { return 1; } - - // return all formats in the provided array (of size GetFormatCount()) - virtual void GetAllFormats(wxDataFormat *formats, - bool outputOnlyToo = TRUE) 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 bool GetDataHere(const wxDataFormat& format, void *buf) const = 0; - - // get data from the buffer (in the given format) - virtual bool SetData(const wxDataFormat& format, const void *buf) = 0; - - // a simpler name which makes more sense for data objects supporting - // only one format - wxDataFormat GetFormat() const { return GetPreferredFormat(); } - - // 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; - -private: - DECLARE_DYNAMIC_CLASS( wxDataObject ) -}; - -//---------------------------------------------------------------------------- -// wxTextDataObject is a specialization of wxDataObject for text data -//---------------------------------------------------------------------------- - -class wxTextDataObject : public wxDataObject -{ -public: - // ctors - wxTextDataObject(); - wxTextDataObject(const wxString& strText); - void Init(const wxString& strText) { m_strText = strText; } - - virtual wxDataFormat GetPreferredFormat() const - { return wxDF_TEXT; } - virtual bool IsSupportedFormat(const wxDataFormat& format) const - { return format == wxDF_TEXT; } - - virtual size_t GetDataSize(const wxDataFormat& format) const; - virtual bool GetDataHere(const wxDataFormat& format, void *buf) const; - virtual bool SetData(const wxDataFormat& format, const void *buf); - - // additional helpers - void SetText(const wxString& strText) { m_strText = strText; } - wxString GetText() const { return m_strText; } - -private: - wxString m_strText; - -private: - DECLARE_DYNAMIC_CLASS( wxTextDataObject ) -}; - -//---------------------------------------------------------------------------- -// wxFileDataObject is a specialization of wxDataObject for file names -//---------------------------------------------------------------------------- - -class wxFileDataObject : public wxDataObject -{ -public: - wxFileDataObject(); - - void AddFile( const wxString &file ); - void SetFiles( const wxString &files ) - { m_files = files; } - wxString GetFiles() const; - - virtual wxDataFormat GetPreferredFormat() const - { return wxDF_FILENAME; } - virtual bool IsSupportedFormat(const wxDataFormat& format) const - { return format == wxDF_FILENAME; } - - virtual size_t GetDataSize(const wxDataFormat& format) const; - virtual bool GetDataHere(const wxDataFormat& format, void *buf) const; - virtual bool SetData(const wxDataFormat& format, const void *buf); - -public: - wxString m_files; - -private: - DECLARE_DYNAMIC_CLASS( wxFileDataObject ) -}; - -//---------------------------------------------------------------------------- -// wxBitmapDataObject is a specialization of wxDataObject for bitmaps -//---------------------------------------------------------------------------- - -class wxBitmapDataObject : public wxDataObject -{ -public: - // ctors - wxBitmapDataObject(); - wxBitmapDataObject(const wxBitmap& bitmap); - - // destr - ~wxBitmapDataObject(); - - // set/get our bitmap - void SetBitmap(const wxBitmap& bitmap); - const wxBitmap GetBitmap() const { return m_bitmap; } - - 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 bool GetDataHere(const wxDataFormat& format, void *buf) const; - - // sets PNG data - virtual bool SetData(const wxDataFormat& format, const void *buf); - - // sets PNG data - virtual void SetPngData(const void *buf, size_t size); - - void *GetData() - { return m_pngData; } - -private: - wxBitmap m_bitmap; - size_t m_pngSize; - void *m_pngData; - - void DoConvertToPng(); - -private: - DECLARE_DYNAMIC_CLASS( wxBitmapDataObject ); -}; - -#endif - //__GTKDNDH__ +#endif // _WX_GTK_DATAOBJ_H_ diff --git a/include/wx/gtk1/clipbrd.h b/include/wx/gtk1/clipbrd.h index 188ea58fcf..b6d2583e84 100644 --- a/include/wx/gtk1/clipbrd.h +++ b/include/wx/gtk1/clipbrd.h @@ -15,8 +15,6 @@ #pragma interface #endif -#include "wx/defs.h" - #if wxUSE_CLIPBOARD #include "wx/object.h" @@ -25,24 +23,11 @@ #include "wx/control.h" #include "wx/module.h" -//----------------------------------------------------------------------------- -// classes -//----------------------------------------------------------------------------- - -class wxClipboard; -class wxClipboardModule; - -//----------------------------------------------------------------------------- -// global data -//----------------------------------------------------------------------------- - -extern wxClipboard* wxTheClipboard; - -//----------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- // wxClipboard -//----------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- -class wxClipboard : public wxObject +class wxClipboard : public wxClipboardBase { public: wxClipboard(); @@ -61,22 +46,20 @@ public: virtual bool AddData( wxDataObject *data ); // ask if data in correct format is available - virtual bool IsSupported( wxDataFormat format ); + virtual bool IsSupported( const wxDataFormat& format ); // fill data with data on the clipboard (if available) - virtual bool GetData( wxDataObject *data ); + virtual bool GetData( wxDataObject& data ); // clears wxTheClipboard and the system's clipboard if possible virtual void Clear(); - // flushes the clipboard: not available under GTK - virtual bool Flush() { return FALSE; } + // If primary == TRUE, use primary selection in all further ops, + // primary == FALSE resets it. + virtual void UsePrimarySelection(bool primary = TRUE) + { m_usePrimary = primary; } - /// If primary == TRUE, use primary selection in all further ops, - /// primary=FALSE resets it. - inline void UsePrimarySelection(bool primary = TRUE) { m_usePrimary = primary; } - - // implementation + // implementation from now on bool m_open; bool m_ownsClipboard; bool m_ownsPrimarySelection; @@ -89,29 +72,13 @@ public: bool m_formatSupported; GdkAtom m_targetRequested; bool m_usePrimary; - wxDataObject *m_receivedData; - + wxDataObject *m_receivedData; + private: DECLARE_DYNAMIC_CLASS(wxClipboard) }; -//----------------------------------------------------------------------------- -// wxClipboardModule -//----------------------------------------------------------------------------- - -class wxClipboardModule: public wxModule -{ -public: - wxClipboardModule() {} - bool OnInit(); - void OnExit(); - -private: - DECLARE_DYNAMIC_CLASS(wxClipboardModule) -}; - #endif - // wxUSE_CLIPBOARD #endif diff --git a/include/wx/gtk1/dataform.h b/include/wx/gtk1/dataform.h new file mode 100644 index 0000000000..a0618e01af --- /dev/null +++ b/include/wx/gtk1/dataform.h @@ -0,0 +1,60 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: gtk/dataform.h +// Purpose: declaration of the wxDataFormat class +// Author: Vadim Zeitlin +// Modified by: +// Created: 19.10.99 (extracted from gtk/dataobj.h) +// RCS-ID: $Id$ +// Copyright: (c) 1998 Vadim Zeitlin +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_GTK_DATAFORM_H +#define _WX_GTK_DATAFORM_H + +class wxDataFormat +{ +public: + // the clipboard formats under GDK are GdkAtoms + typedef GdkAtom NativeFormat; + + wxDataFormat(); + wxDataFormat( wxDataFormatId type ); + wxDataFormat( const wxString &id ); + wxDataFormat( const wxChar *id ); + wxDataFormat( NativeFormat format ); + + wxDataFormat& operator=(NativeFormat format) + { SetId(format); return *this; } + + // comparison (must have both versions) + bool operator==(NativeFormat format) const + { return m_format == (NativeFormat)format; } + bool operator!=(NativeFormat format) const + { return m_format != (NativeFormat)format; } + + // 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; } + + void SetId( NativeFormat format ); + + // string ids are used for custom types - this SetId() must be used for + // application-specific formats + wxString GetId() const; + void SetId( const wxChar *id ); + + // implementation + wxDataFormatId GetType() const; + +private: + wxDataFormatId m_type; + NativeFormat m_format; + + void PrepareFormats(); + void SetType( wxDataFormatId type ); +}; + +#endif // _WX_GTK_DATAFORM_H diff --git a/include/wx/gtk1/dataobj.h b/include/wx/gtk1/dataobj.h index 237674e3c6..79430ddce6 100644 --- a/include/wx/gtk1/dataobj.h +++ b/include/wx/gtk1/dataobj.h @@ -1,255 +1,26 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: dataobj.h -// Purpose: declaration of the wxDataObject class +// Name: gtk/dataobj.h +// Purpose: declaration of the wxDataObject // Author: Robert Roebling // RCS-ID: $Id$ -// Copyright: (c) 1998 Vadim Zeitlin, Robert Roebling +// Copyright: (c) 1998, 1999 Vadim Zeitlin, Robert Roebling // Licence: wxWindows license /////////////////////////////////////////////////////////////////////////////// -#ifndef __GTKDATAOBJECTH__ -#define __GTKDATAOBJECTH__ +#ifndef _WX_GTK_DATAOBJ_H_ +#define _WX_GTK_DATAOBJ_H_ #ifdef __GNUG__ -#pragma interface + #pragma interface "dataobj.h" #endif -#include "wx/defs.h" -#include "wx/object.h" -#include "wx/string.h" -#include "wx/bitmap.h" +// ---------------------------------------------------------------------------- +// wxDataObject is the same as wxDataObjectBase under wxGTK +// ---------------------------------------------------------------------------- -//------------------------------------------------------------------------- -// classes -//------------------------------------------------------------------------- - -class wxDataFormat; -class wxDataBroker; -class wxDataObject; -class wxTextDataObject; -class wxBitmapDataObject; -class wxPrivateDataObject; -class wxFileDataObject; - -//------------------------------------------------------------------------- -// wxDataFormat -//------------------------------------------------------------------------- - -class wxDataFormat +class wxDataObject : public wxDataObjectBase { -public: - // the clipboard formats under GDK are GdkAtoms - typedef GdkAtom NativeFormat; - - wxDataFormat(); - wxDataFormat( wxDataFormatId type ); - wxDataFormat( const wxString &id ); - wxDataFormat( const wxChar *id ); - wxDataFormat( NativeFormat format ); - - wxDataFormat& operator=(NativeFormat format) - { SetId(format); return *this; } - wxDataFormat& operator=(const wxDataFormat& format) - { SetId(format); return *this; } - - // comparison (must have both versions) - bool operator==(wxDataFormatId type) const - { return m_type == (wxDataFormatId)type; } - bool operator!=(wxDataFormatId type) const - { return m_type != (wxDataFormatId)type; } - bool operator==(NativeFormat format) const - { return m_format == (NativeFormat)format; } - bool operator!=(NativeFormat format) const - { return m_format != (NativeFormat)format; } - bool operator==(const wxDataFormat& format) const - { return m_format == format.m_format; } - bool operator!=(const wxDataFormat& format) const - { return m_format != format.m_format; } - - // 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; } - - // this only works with standard ids - void SetId( wxDataFormatId type ); - - // this only works with standard ids - void SetId( NativeFormat format ); - - // string ids are used for custom types - this SetId() must be used for - // application-specific formats - wxString GetId() const; - void SetId( const wxChar *id ); - - // implementation - wxDataFormatId GetType() const; - -private: - wxDataFormatId m_type; - NativeFormat m_format; - - void PrepareFormats(); - void SetType( wxDataFormatId type ); }; -//---------------------------------------------------------------------------- -// wxDataObject -//---------------------------------------------------------------------------- - -class wxDataObject : public wxObject -{ -public: - wxDataObject(); - ~wxDataObject(); - - virtual wxDataFormat GetPreferredFormat() const = 0; - - // get the number of formats we support: it is understood that if we - // can accept data in some format, then we can render data in this - // format as well, but the contrary is not necessarily true. For the - // default value of the argument, all formats we support should be - // returned, but if outputOnlyToo == FALSE, then we should only return - // the formats which our SetData() understands - virtual size_t GetFormatCount(bool outputOnlyToo = TRUE) const - { return 1; } - - // return all formats in the provided array (of size GetFormatCount()) - virtual void GetAllFormats(wxDataFormat *formats, - bool outputOnlyToo = TRUE) 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 bool GetDataHere(const wxDataFormat& format, void *buf) const = 0; - - // get data from the buffer (in the given format) - virtual bool SetData(const wxDataFormat& format, const void *buf) = 0; - - // a simpler name which makes more sense for data objects supporting - // only one format - wxDataFormat GetFormat() const { return GetPreferredFormat(); } - - // 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; - -private: - DECLARE_DYNAMIC_CLASS( wxDataObject ) -}; - -//---------------------------------------------------------------------------- -// wxTextDataObject is a specialization of wxDataObject for text data -//---------------------------------------------------------------------------- - -class wxTextDataObject : public wxDataObject -{ -public: - // ctors - wxTextDataObject(); - wxTextDataObject(const wxString& strText); - void Init(const wxString& strText) { m_strText = strText; } - - virtual wxDataFormat GetPreferredFormat() const - { return wxDF_TEXT; } - virtual bool IsSupportedFormat(const wxDataFormat& format) const - { return format == wxDF_TEXT; } - - virtual size_t GetDataSize(const wxDataFormat& format) const; - virtual bool GetDataHere(const wxDataFormat& format, void *buf) const; - virtual bool SetData(const wxDataFormat& format, const void *buf); - - // additional helpers - void SetText(const wxString& strText) { m_strText = strText; } - wxString GetText() const { return m_strText; } - -private: - wxString m_strText; - -private: - DECLARE_DYNAMIC_CLASS( wxTextDataObject ) -}; - -//---------------------------------------------------------------------------- -// wxFileDataObject is a specialization of wxDataObject for file names -//---------------------------------------------------------------------------- - -class wxFileDataObject : public wxDataObject -{ -public: - wxFileDataObject(); - - void AddFile( const wxString &file ); - void SetFiles( const wxString &files ) - { m_files = files; } - wxString GetFiles() const; - - virtual wxDataFormat GetPreferredFormat() const - { return wxDF_FILENAME; } - virtual bool IsSupportedFormat(const wxDataFormat& format) const - { return format == wxDF_FILENAME; } - - virtual size_t GetDataSize(const wxDataFormat& format) const; - virtual bool GetDataHere(const wxDataFormat& format, void *buf) const; - virtual bool SetData(const wxDataFormat& format, const void *buf); - -public: - wxString m_files; - -private: - DECLARE_DYNAMIC_CLASS( wxFileDataObject ) -}; - -//---------------------------------------------------------------------------- -// wxBitmapDataObject is a specialization of wxDataObject for bitmaps -//---------------------------------------------------------------------------- - -class wxBitmapDataObject : public wxDataObject -{ -public: - // ctors - wxBitmapDataObject(); - wxBitmapDataObject(const wxBitmap& bitmap); - - // destr - ~wxBitmapDataObject(); - - // set/get our bitmap - void SetBitmap(const wxBitmap& bitmap); - const wxBitmap GetBitmap() const { return m_bitmap; } - - 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 bool GetDataHere(const wxDataFormat& format, void *buf) const; - - // sets PNG data - virtual bool SetData(const wxDataFormat& format, const void *buf); - - // sets PNG data - virtual void SetPngData(const void *buf, size_t size); - - void *GetData() - { return m_pngData; } - -private: - wxBitmap m_bitmap; - size_t m_pngSize; - void *m_pngData; - - void DoConvertToPng(); - -private: - DECLARE_DYNAMIC_CLASS( wxBitmapDataObject ); -}; - -#endif - //__GTKDNDH__ +#endif // _WX_GTK_DATAOBJ_H_ diff --git a/include/wx/motif/clipbrd.h b/include/wx/motif/clipbrd.h index 781a9a0b94..6b675bc645 100644 --- a/include/wx/motif/clipbrd.h +++ b/include/wx/motif/clipbrd.h @@ -19,8 +19,6 @@ #pragma interface "clipbrd.h" #endif -#include "wx/defs.h" - #if wxUSE_CLIPBOARD #include "wx/dataobj.h" @@ -42,134 +40,44 @@ bool WXDLLEXPORT wxGetClipboardFormatName(wxDataFormat dataFormat, char *formatN // wxClipboard //----------------------------------------------------------------------------- -class WXDLLEXPORT wxDataObject; -class WXDLLEXPORT wxClipboard: public wxObject +class wxClipboard : public wxClipboardBase { - DECLARE_DYNAMIC_CLASS(wxClipboard) - public: + wxClipboard(); + ~wxClipboard(); - wxClipboard(); - ~wxClipboard(); + // open the clipboard before SetData() and GetData() + virtual bool Open(); - // open the clipboard before SetData() and GetData() - virtual bool Open(); + // close the clipboard after SetData() and GetData() + virtual void Close(); - // close the clipboard after SetData() and GetData() - virtual void Close(); + // can be called several times + virtual bool SetData( wxDataObject *data ); - // can be called several times - virtual bool SetData( wxDataObject *data ); + // format available on the clipboard ? + // supply ID if private format, the same as wxPrivateDataObject::SetId() + virtual bool IsSupported( wxDataFormat format ); - // format available on the clipboard ? - // supply ID if private format, the same as wxPrivateDataObject::SetId() - virtual bool IsSupported( wxDataFormat format ); + // fill data with data on the clipboard (if available) + virtual bool GetData( wxDataObject *data ); - // 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(); - // clears wxTheClipboard and the system's clipboard if possible - virtual void Clear(); + // implementation from now on - /// If primary == TRUE, use primary selection in all further ops, - /// primary=FALSE resets it. - inline void UsePrimarySelection(bool primary = TRUE) { m_usePrimary = primary; } + bool m_open; + wxList m_data; + bool m_usePrimary; - // implementation - - bool m_open; - wxList m_data; - bool m_usePrimary; +private: + DECLARE_DYNAMIC_CLASS(wxClipboard) }; /* The clipboard */ WXDLLEXPORT_DATA(extern wxClipboard*) wxTheClipboard; -//----------------------------------------------------------------------------- -// wxClipboardModule -//----------------------------------------------------------------------------- - -class wxClipboardModule: public wxModule -{ - DECLARE_DYNAMIC_CLASS(wxClipboardModule) - -public: - wxClipboardModule() {} - bool OnInit(); - void OnExit(); -}; - -// This is the old, 1.68 implementation -#if 0 - -/* 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() = 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 -{ - DECLARE_DYNAMIC_CLASS(wxClipboard) - - public: - wxClipboardClient *clipOwner; - char *cbString, *sentString, *receivedString; - void *receivedTargets; - long receivedLength; - - wxClipboard(); - ~wxClipboard(); - - /* Set the clipboard data owner. "time" comes from the event record. */ - void SetClipboardClient(wxClipboardClient *, long time); - - /* Set the clipboard string; does not require a client. */ - void SetClipboardString(char *, long time); - - /* 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(); -}; - -/* Initialize wxTheClipboard. Can be called repeatedly */ -void WXDLLEXPORT wxInitClipboard(); - -/* The clipboard */ -WXDLLEXPORT_DATA(extern wxClipboard*) wxTheClipboard; - -#endif - // Old clipboard class - #endif // wxUSE_CLIPBOARD #endif diff --git a/include/wx/motif/dataform.h b/include/wx/motif/dataform.h new file mode 100644 index 0000000000..cab0b9d678 --- /dev/null +++ b/include/wx/motif/dataform.h @@ -0,0 +1,54 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: motif/dataform.h +// Purpose: declaration of the wxDataFormat class +// Author: Vadim Zeitlin +// Modified by: +// Created: 19.10.99 (extracted from motif/dataobj.h) +// RCS-ID: $Id$ +// Copyright: (c) 1998 Vadim Zeitlin +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_MOTIF_DATAFORM_H +#define _WX_MOTIF_DATAFORM_H + +class wxDataFormat +{ +public: + wxDataFormat(); + wxDataFormat( wxDataFormatId type ); + wxDataFormat( const wxString &id ); + wxDataFormat( const wxChar *id ); + wxDataFormat( const wxDataFormat &format ); + wxDataFormat( const Atom atom ); + + void SetType( wxDataFormatId type ); + wxDataFormatId GetType() const; + + /* the string Id identifies the format of clipboard or DnD data. a word + * processor would e.g. add a wxTextDataObject and a wxPrivateDataObject + * to the clipboard - the latter with the Id "application/wxword", an + * image manipulation program would put a wxBitmapDataObject and a + * wxPrivateDataObject to the clipboard - the latter with "image/png". */ + + wxString GetId() const; + void SetId( const wxChar *id ); + + Atom GetAtom(); + void SetAtom(Atom atom) { m_hasAtom = TRUE; m_atom = atom; } + + // implicit conversion to wxDataFormatId + operator wxDataFormatId() const { return m_type; } + + bool operator==(wxDataFormatId type) const { return m_type == type; } + bool operator!=(wxDataFormatId type) const { return m_type != type; } + +private: + wxDataFormatId m_type; + wxString m_id; + bool m_hasAtom; + Atom m_atom; +}; + +#endif // _WX_MOTIF_DATAFORM_H + diff --git a/include/wx/msw/clipbrd.h b/include/wx/msw/clipbrd.h index a7d010e60d..05c8cef304 100644 --- a/include/wx/msw/clipbrd.h +++ b/include/wx/msw/clipbrd.h @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: clipbrd.h -// Purpose: Clipboard functionality +// Name: wx/msw/clipbrd.h +// Purpose: wxClipboad class and clipboard functions for MSW // Author: Julian Smart // Modified by: // Created: 01/02/97 @@ -16,9 +16,6 @@ #pragma interface "clipbrd.h" #endif -#include "wx/defs.h" -#include "wx/setup.h" - #if wxUSE_CLIPBOARD #include "wx/list.h" @@ -96,25 +93,6 @@ private: bool m_clearOnExit; }; -// The global clipboard object -WXDLLEXPORT_DATA(extern wxClipboard*) wxTheClipboard; - -//----------------------------------------------------------------------------- -// wxClipboardModule: module responsible for initializing the global clipboard -// object -//----------------------------------------------------------------------------- - -class wxClipboardModule : public wxModule -{ - DECLARE_DYNAMIC_CLASS(wxClipboardModule) - -public: - wxClipboardModule() { } - - bool OnInit(); - void OnExit(); -}; - #endif // wxUSE_CLIPBOARD #endif // _WX_CLIPBRD_H_ diff --git a/include/wx/msw/ole/dataform.h b/include/wx/msw/ole/dataform.h new file mode 100644 index 0000000000..020d4aec75 --- /dev/null +++ b/include/wx/msw/ole/dataform.h @@ -0,0 +1,68 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: msw/ole/dataform.h +// Purpose: declaration of the wxDataFormat class +// Author: Vadim Zeitlin +// Modified by: +// Created: 19.10.99 (extracted from msw/ole/dataobj.h) +// RCS-ID: $Id$ +// Copyright: (c) 1998 Vadim Zeitlin +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_MSW_OLE_DATAFORM_H +#define _WX_MSW_OLE_DATAFORM_H + +// ---------------------------------------------------------------------------- +// wxDataFormat identifies the single format of data +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxDataFormat +{ +public: + // the clipboard formats under Win32 are UINTs + typedef unsigned int NativeFormat; + + wxDataFormat(NativeFormat format = wxDF_INVALID) { m_format = format; } + wxDataFormat(const wxChar *format) { SetId(format); } + + wxDataFormat& operator=(NativeFormat format) + { m_format = format; return *this; } + wxDataFormat& operator=(const wxDataFormat& format) + { m_format = format.m_format; return *this; } + + // default copy ctor/assignment operators ok + + // comparison (must have both versions) + bool operator==(wxDataFormatId format) const + { return m_format == (NativeFormat)format; } + bool operator!=(wxDataFormatId format) const + { return m_format != (NativeFormat)format; } + bool operator==(const wxDataFormat& format) const + { return m_format == format.m_format; } + bool operator!=(const wxDataFormat& format) const + { return m_format != format.m_format; } + + // 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; } + + // this only works with standard ids + void SetType(wxDataFormatId format) { m_format = format; } + wxDataFormatId GetType() const { return m_format; } + + // string ids are used for custom types - this SetId() must be used for + // application-specific formats + wxString GetId() const; + void SetId(const wxChar *format); + +private: + // returns TRUE if the format is one of those defined in wxDataFormatId + bool IsStandard() const { return m_format > 0 && m_format < wxDF_MAX; } + + NativeFormat m_format; +}; + +#endif // _WX_MSW_OLE_DATAFORM_H + diff --git a/include/wx/msw/ole/dataobj.h b/include/wx/msw/ole/dataobj.h index ab800e3e07..09dff76e96 100644 --- a/include/wx/msw/ole/dataobj.h +++ b/include/wx/msw/ole/dataobj.h @@ -1,67 +1,16 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: ole/dataobj.h +// Name: msw/ole/dataobj.h // Purpose: declaration of the wxDataObject class // Author: Vadim Zeitlin -// Modified by: +// Modified by: // Created: 10.05.98 // RCS-ID: $Id$ // Copyright: (c) 1998 Vadim Zeitlin // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// -#ifndef _WX_OLEDATAOBJ_H -#define _WX_OLEDATAOBJ_H - -// ---------------------------------------------------------------------------- -// wxDataFormat identifies the single format of data -// ---------------------------------------------------------------------------- - -class WXDLLEXPORT wxDataFormat -{ -public: - // the clipboard formats under Win32 are UINTs - typedef unsigned int NativeFormat; - - wxDataFormat(NativeFormat format = wxDF_INVALID) { m_format = format; } - wxDataFormat(const wxChar *format) { SetId(format); } - - wxDataFormat& operator=(NativeFormat format) - { m_format = format; return *this; } - wxDataFormat& operator=(const wxDataFormat& format) - { m_format = format.m_format; return *this; } - - // defautl copy ctor/assignment operators ok - - // comparison (must have both versions) - bool operator==(wxDataFormatId format) const - { return m_format == (NativeFormat)format; } - bool operator!=(wxDataFormatId format) const - { return m_format != (NativeFormat)format; } - bool operator==(const wxDataFormat& format) const - { return m_format == format.m_format; } - bool operator!=(const wxDataFormat& format) const - { return m_format != format.m_format; } - - // 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; } - - // this only works with standard ids - void SetId(wxDataFormatId format) { m_format = format; } - - // string ids are used for custom types - this SetId() must be used for - // application-specific formats - wxString GetId() const; - void SetId(const wxChar *format); - -private: - // returns TRUE if the format is one of those defined in wxDataFormatId - bool IsStandard() const { return m_format > 0 && m_format < wxDF_MAX; } - - NativeFormat m_format; -}; +#ifndef _WX_MSW_OLE_DATAOBJ_H +#define _WX_MSW_OLE_DATAOBJ_H // ---------------------------------------------------------------------------- // forward declarations @@ -198,5 +147,5 @@ private: // TODO: wxFileDataObject. -#endif //_WX_OLEDATAOBJ_H +#endif //_WX_MSW_OLE_DATAOBJ_H diff --git a/include/wx/msw/ole/dropsrc.h b/include/wx/msw/ole/dropsrc.h index dbfe018d66..aa9283f65c 100644 --- a/include/wx/msw/ole/dropsrc.h +++ b/include/wx/msw/ole/dropsrc.h @@ -2,7 +2,7 @@ // Name: ole/dropsrc.h // Purpose: declaration of the wxDropSource class // Author: Vadim Zeitlin -// Modified by: +// Modified by: // Created: 06.03.98 // RCS-ID: $Id$ // Copyright: (c) 1998 Vadim Zeitlin @@ -28,19 +28,6 @@ class wxIDropSource; class WXDLLEXPORT wxDataObject; class WXDLLEXPORT wxWindow; -// ---------------------------------------------------------------------------- -// constants -// ---------------------------------------------------------------------------- - -enum wxDragResult -{ - wxDragError, // error prevented the d&d operation from completing - wxDragNone, // drag target didn't accept the data - wxDragCopy, // the data was successfully copied - wxDragMove, // the data was successfully moved - wxDragCancel // the operation was cancelled by user (not an error) -}; - // ---------------------------------------------------------------------------- // wxDropSource is used to start the drag-&-drop operation on associated // wxDataObject object. It's responsible for giving UI feedback while dragging. @@ -49,37 +36,34 @@ enum wxDragResult class WXDLLEXPORT wxDropSource { public: - // ctors: if you use default ctor you must call SetData() later! - // NB: the "wxWindow *win" parameter is unused and is here only for wxGTK - // compatibility, as well as both icon parameters - wxDropSource(wxWindow *win = NULL, - const wxIcon &go = wxNullIcon, - const wxIcon &stop = wxNullIcon ); - wxDropSource(wxDataObject& data, - wxWindow *win = NULL, - const wxIcon &go = wxNullIcon, - const wxIcon &stop = wxNullIcon ); + // ctors: if you use default ctor you must call SetData() later! + // + // NB: the "wxWindow *win" parameter is unused and is here only for wxGTK + // compatibility, as well as both icon parameters + wxDropSource(wxWindow *win = NULL, + const wxIcon &go = wxNullIcon, + const wxIcon &stop = wxNullIcon ); + wxDropSource(wxDataObject& data, + wxWindow *win = NULL, + const wxIcon &go = wxNullIcon, + const wxIcon &stop = wxNullIcon ); - void SetData(wxDataObject& data); + virtual ~wxDropSource(); - virtual ~wxDropSource(); + // do it (call this in response to a mouse button press, for example) + // params: if bAllowMove is false, data can be only copied + virtual wxDragResult DoDragDrop(bool bAllowMove = FALSE); - // do it (call this in response to a mouse button press, for example) - // params: if bAllowMove is false, data can be only copied - wxDragResult DoDragDrop(bool bAllowMove = FALSE); - - // overridable: you may give some custom UI feedback during d&d operation - // in this function (it's called on each mouse move, so it shouldn't be too - // slow). Just return false if you want default feedback. - virtual bool GiveFeedback(wxDragResult effect, bool bScrolling); + // overridable: you may give some custom UI feedback during d&d operation + // in this function (it's called on each mouse move, so it shouldn't be + // too slow). Just return false if you want default feedback. + virtual bool GiveFeedback(wxDragResult effect, bool bScrolling); protected: - void Init(); - - wxDataObject *m_pData; // pointer to associated data object + void Init(); private: - wxIDropSource *m_pIDropSource; // the pointer to COM interface + wxIDropSource *m_pIDropSource; // the pointer to COM interface }; #endif //_WX_OLEDROPSRC_H diff --git a/include/wx/msw/ole/droptgt.h b/include/wx/msw/ole/droptgt.h index d623116b31..1a7716f2a5 100644 --- a/include/wx/msw/ole/droptgt.h +++ b/include/wx/msw/ole/droptgt.h @@ -2,7 +2,7 @@ // Name: ole/droptgt.h // Purpose: declaration of the wxDropTarget class // Author: Vadim Zeitlin -// Modified by: +// Modified by: // Created: 06.03.98 // RCS-ID: $Id$ // Copyright: (c) 1998 Vadim Zeitlin @@ -33,7 +33,7 @@ struct IDataObject; // An instance of the class wxDropTarget may be associated with any wxWindow // derived object via SetDropTarget() function. If this is done, the virtual // methods of wxDropTarget are called when something is dropped on the window. -// +// // Note that wxDropTarget is an abstract base class (ABC) and you should derive // your own class from it implementing pure virtual function in order to use it // (all of them, including protected ones which are called by the class itself) @@ -41,38 +41,38 @@ struct IDataObject; class WXDLLEXPORT wxDropTarget { public: - // ctor & dtor - wxDropTarget(); - virtual ~wxDropTarget(); + // ctor & dtor + wxDropTarget(); + virtual ~wxDropTarget(); - // normally called by wxWindow on window creation/destruction, but might be - // called `manually' as well. Register() returns true on success. - bool Register(WXHWND hwnd); - void Revoke(WXHWND hwnd); + // normally called by wxWindow on window creation/destruction, but might be + // called `manually' as well. Register() returns true on success. + bool Register(WXHWND hwnd); + void Revoke(WXHWND hwnd); - // do we accept this kind of data? - virtual bool IsAcceptedData(IDataObject *pIDataSource) const; + // do we accept this kind of data? + virtual bool IsAcceptedData(IDataObject *pIDataSource) const; - // called when mouse enters/leaves the window: might be used to give - // some visual feedback to the user - virtual void OnEnter() { } - virtual void OnLeave() { } + // called when mouse enters/leaves the window: might be used to give + // some visual feedback to the user + virtual void OnEnter() { } + virtual void OnLeave() { } - // this function is called when data is dropped. - // (x, y) are the coordinates of the drop - virtual bool OnDrop(long x, long y, const void *pData) = 0; + // this function is called when data is dropped. + // (x, y) are the coordinates of the drop + virtual bool OnDrop(long x, long y, const void *pData) = 0; protected: - // Override these to indicate what kind of data you support: the first - // format to which data can be converted is used. The classes below show - // how it can be done in the simplest cases. - // how many different (clipboard) formats do you support? - virtual size_t GetFormatCount() const = 0; - // return the n-th supported format - virtual wxDataFormat GetFormat(size_t n) const = 0; + // Override these to indicate what kind of data you support: the first + // format to which data can be converted is used. The classes below show + // how it can be done in the simplest cases. + // how many different (clipboard) formats do you support? + virtual size_t GetFormatCount() const = 0; + // return the n-th supported format + virtual wxDataFormat GetFormat(size_t n) const = 0; private: - wxIDropTarget *m_pIDropTarget; // the pointer to COM interface + wxIDropTarget *m_pIDropTarget; // the pointer to COM interface }; // ---------------------------------------------------------------------------- @@ -99,7 +99,7 @@ public: virtual bool OnDrop(long x, long y, const void *pData); // params: the number of files and the array of file names - virtual bool OnDropFiles(long x, long y, + virtual bool OnDropFiles(long x, long y, size_t nFiles, const wxChar * const aszFiles[]) = 0; protected: diff --git a/src/common/appcmn.cpp b/src/common/appcmn.cpp index 357f388c08..33d0cc1956 100644 --- a/src/common/appcmn.cpp +++ b/src/common/appcmn.cpp @@ -38,6 +38,12 @@ // implementation // =========================================================================== +// ---------------------------------------------------------------------------- +// some global data defined here +// ---------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS(wxClipboardModule, wxModule) + // --------------------------------------------------------------------------- // wxAppBase // ---------------------------------------------------------------------------- diff --git a/src/gtk/clipbrd.cpp b/src/gtk/clipbrd.cpp index 9a9e38ee22..79e3bc58bb 100644 --- a/src/gtk/clipbrd.cpp +++ b/src/gtk/clipbrd.cpp @@ -15,6 +15,7 @@ #if wxUSE_CLIPBOARD +#include "wx/dataobj.h" #include "wx/utils.h" #include "glib.h" @@ -548,7 +549,7 @@ void wxClipboard::Close() m_open = FALSE; } -bool wxClipboard::IsSupported( wxDataFormat format ) +bool wxClipboard::IsSupported( const wxDataFormat& format ) { /* store requested format to be asked for by callbacks */ @@ -580,7 +581,7 @@ bool wxClipboard::IsSupported( wxDataFormat format ) return TRUE; } -bool wxClipboard::GetData( wxDataObject *data ) +bool wxClipboard::GetData( wxDataObject& data ) { wxCHECK_MSG( m_open, FALSE, wxT("clipboard not open") ); @@ -627,26 +628,6 @@ bool wxClipboard::GetData( wxDataObject *data ) return TRUE; } -//----------------------------------------------------------------------------- -// wxClipboardModule -//----------------------------------------------------------------------------- - -IMPLEMENT_DYNAMIC_CLASS(wxClipboardModule,wxModule) - -bool wxClipboardModule::OnInit() -{ - wxTheClipboard = new wxClipboard(); - - return TRUE; -} - -void wxClipboardModule::OnExit() -{ - if (wxTheClipboard) delete wxTheClipboard; - wxTheClipboard = (wxClipboard*) NULL; -} - #endif - // wxUSE_CLIPBOARD diff --git a/src/gtk/dataobj.cpp b/src/gtk/dataobj.cpp index 401dca0db0..dc7effd747 100644 --- a/src/gtk/dataobj.cpp +++ b/src/gtk/dataobj.cpp @@ -19,7 +19,6 @@ #include "gdk/gdk.h" - //------------------------------------------------------------------------- // global data //------------------------------------------------------------------------- @@ -117,11 +116,11 @@ void wxDataFormat::SetId( const wxChar *id ) void wxDataFormat::PrepareFormats() { - if (!g_textAtom) + if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); - if (!g_pngAtom) + if (!g_pngAtom) g_pngAtom = gdk_atom_intern( "image/png", FALSE ); - if (!g_fileAtom) + if (!g_fileAtom) g_fileAtom = gdk_atom_intern( "file:ALL", FALSE ); } @@ -162,85 +161,27 @@ bool wxDataObject::IsSupportedFormat(const wxDataFormat& format) const } } - -// ---------------------------------------------------------------------------- -// wxTextDataObject -// ---------------------------------------------------------------------------- - -IMPLEMENT_DYNAMIC_CLASS( wxTextDataObject, wxDataObject ) - -wxTextDataObject::wxTextDataObject() -{ -} - -wxTextDataObject::wxTextDataObject(const wxString& strText) - : m_strText(strText) -{ -} - -size_t wxTextDataObject::GetDataSize(const wxDataFormat& format) const -{ - return m_strText.Len() + 1; // +1 for trailing '\0'of course -} - -bool wxTextDataObject::GetDataHere(const wxDataFormat& format, void *buf) const -{ - memcpy(buf, m_strText.c_str(), GetDataSize(format)); - return TRUE; -} - -bool wxTextDataObject::SetData(const wxDataFormat& format, const void *buf) -{ - m_strText = (const wxChar *)buf; - return TRUE; -} - // ---------------------------------------------------------------------------- // wxFileDataObject // ---------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS( wxFileDataObject, wxDataObject ) - -wxFileDataObject::wxFileDataObject() +bool wxFileDataObject::GetDataHere(void *buf) const { + const wxString& filenames = GetFilenames(); + memcpy( buf, filenames.mbc_str(), filenames.Len() + 1 ); + + return TRUE; } -void wxFileDataObject::AddFile( const wxString &file ) +size_t wxFileDataObject::GetDataSize() const { - m_files += file; - m_files += (wxChar)0; + return GetFilenames().Len() + 1; } -wxString wxFileDataObject::GetFiles() const +bool wxFileDataObject::SetData(const void *buf) { - return m_files; -} + SetFilenames((const wxChar *)buf); -bool wxFileDataObject::GetDataHere(const wxDataFormat& format, void *buf) const -{ - if (format == wxDF_FILENAME) - { - memcpy( buf, m_files.mbc_str(), m_files.Len() + 1 ); - return TRUE; - } - - return FALSE; -} - -size_t wxFileDataObject::GetDataSize(const wxDataFormat& format) const -{ - if (format != wxDF_FILENAME) return 0; - - return m_files.Len() + 1; -} - -bool wxFileDataObject::SetData(const wxDataFormat& format, const void *buf) -{ - if (format != wxDF_FILENAME) - return FALSE; - - m_files = (char*)(buf); // this is so ugly, I cannot look at it - return TRUE; } @@ -248,96 +189,81 @@ bool wxFileDataObject::SetData(const wxDataFormat& format, const void *buf) // wxBitmapDataObject // ---------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS( wxBitmapDataObject, wxDataObject ) - wxBitmapDataObject::wxBitmapDataObject() { - m_pngData = (void*)NULL; - m_pngSize = 0; + Init(); } wxBitmapDataObject::wxBitmapDataObject( const wxBitmap& bitmap ) + : wxBitmapDataObjectBase(bitmap) { - m_pngData = (void*)NULL; - m_pngSize = 0; - m_bitmap = bitmap; + Init(); + DoConvertToPng(); } wxBitmapDataObject::~wxBitmapDataObject() { - if (m_pngData) - delete[] m_pngData; + Clear(); } void wxBitmapDataObject::SetBitmap( const wxBitmap &bitmap ) { - if (m_pngData) - delete[] m_pngData; - m_pngData = (void*)NULL; - m_pngSize = 0; - - m_bitmap = bitmap; + ClearAll(); + + wxBitmapDataObjectBase::SetBitmap(bitmap); + DoConvertToPng(); } -size_t wxBitmapDataObject::GetDataSize(const wxDataFormat& format) const +bool wxBitmapDataObject::GetDataHere(void *buf) const { - if (format != wxDF_BITMAP) return 0; - - return m_pngSize; -} - -bool wxBitmapDataObject::GetDataHere(const wxDataFormat& format, void *buf) const -{ - if (format != wxDF_BITMAP) return FALSE; - - if (m_pngSize > 0) + if ( !m_pngSize ) { - memcpy(buf, m_pngData, m_pngSize); - return TRUE; + wxFAIL_MSG( wxT("attempt to copy empty bitmap failed") ); + + return FALSE; } - - return FALSE; + + memcpy(buf, m_pngData, m_pngSize); + + return TRUE; } -bool wxBitmapDataObject::SetData(const wxDataFormat& format, const void *buf) +bool wxBitmapDataObject::SetData(size_t size, const void *buf) { - if (m_pngData) delete[] m_pngData; - m_pngData = (void*) NULL; - m_pngSize = 0; - m_bitmap = wxNullBitmap; - - return FALSE; -} + Clear(); -void wxBitmapDataObject::SetPngData(const void *buf, size_t size) -{ - if (m_pngData) delete[] m_pngData; m_pngSize = size; - m_pngData = (void*) new char[m_pngSize]; - + m_pngData = malloc(m_pngSize); + memcpy( m_pngData, buf, m_pngSize ); - + wxMemoryInputStream mstream( (char*) m_pngData, m_pngSize ); wxImage image; wxPNGHandler handler; - handler.LoadFile( &image, mstream ); + if ( !handler.LoadFile( &image, mstream ) ) + { + return FALSE; + } + m_bitmap = image.ConvertToBitmap(); } void wxBitmapDataObject::DoConvertToPng() { - if (!m_bitmap.Ok()) return; - + if (!m_bitmap.Ok()) + return; + wxImage image( m_bitmap ); wxPNGHandler handler; - + wxCountingOutputStream count; handler.SaveFile( &image, count ); + m_pngSize = count.GetSize() + 100; // sometimes the size seems to vary ??? - m_pngData = (void*) new char[m_pngSize]; - + m_pngData = malloc(m_pngSize); + wxMemoryOutputStream mstream( (char*) m_pngData, m_pngSize ); handler.SaveFile( &image, mstream ); } diff --git a/src/gtk1/clipbrd.cpp b/src/gtk1/clipbrd.cpp index 9a9e38ee22..79e3bc58bb 100644 --- a/src/gtk1/clipbrd.cpp +++ b/src/gtk1/clipbrd.cpp @@ -15,6 +15,7 @@ #if wxUSE_CLIPBOARD +#include "wx/dataobj.h" #include "wx/utils.h" #include "glib.h" @@ -548,7 +549,7 @@ void wxClipboard::Close() m_open = FALSE; } -bool wxClipboard::IsSupported( wxDataFormat format ) +bool wxClipboard::IsSupported( const wxDataFormat& format ) { /* store requested format to be asked for by callbacks */ @@ -580,7 +581,7 @@ bool wxClipboard::IsSupported( wxDataFormat format ) return TRUE; } -bool wxClipboard::GetData( wxDataObject *data ) +bool wxClipboard::GetData( wxDataObject& data ) { wxCHECK_MSG( m_open, FALSE, wxT("clipboard not open") ); @@ -627,26 +628,6 @@ bool wxClipboard::GetData( wxDataObject *data ) return TRUE; } -//----------------------------------------------------------------------------- -// wxClipboardModule -//----------------------------------------------------------------------------- - -IMPLEMENT_DYNAMIC_CLASS(wxClipboardModule,wxModule) - -bool wxClipboardModule::OnInit() -{ - wxTheClipboard = new wxClipboard(); - - return TRUE; -} - -void wxClipboardModule::OnExit() -{ - if (wxTheClipboard) delete wxTheClipboard; - wxTheClipboard = (wxClipboard*) NULL; -} - #endif - // wxUSE_CLIPBOARD diff --git a/src/gtk1/dataobj.cpp b/src/gtk1/dataobj.cpp index 401dca0db0..dc7effd747 100644 --- a/src/gtk1/dataobj.cpp +++ b/src/gtk1/dataobj.cpp @@ -19,7 +19,6 @@ #include "gdk/gdk.h" - //------------------------------------------------------------------------- // global data //------------------------------------------------------------------------- @@ -117,11 +116,11 @@ void wxDataFormat::SetId( const wxChar *id ) void wxDataFormat::PrepareFormats() { - if (!g_textAtom) + if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); - if (!g_pngAtom) + if (!g_pngAtom) g_pngAtom = gdk_atom_intern( "image/png", FALSE ); - if (!g_fileAtom) + if (!g_fileAtom) g_fileAtom = gdk_atom_intern( "file:ALL", FALSE ); } @@ -162,85 +161,27 @@ bool wxDataObject::IsSupportedFormat(const wxDataFormat& format) const } } - -// ---------------------------------------------------------------------------- -// wxTextDataObject -// ---------------------------------------------------------------------------- - -IMPLEMENT_DYNAMIC_CLASS( wxTextDataObject, wxDataObject ) - -wxTextDataObject::wxTextDataObject() -{ -} - -wxTextDataObject::wxTextDataObject(const wxString& strText) - : m_strText(strText) -{ -} - -size_t wxTextDataObject::GetDataSize(const wxDataFormat& format) const -{ - return m_strText.Len() + 1; // +1 for trailing '\0'of course -} - -bool wxTextDataObject::GetDataHere(const wxDataFormat& format, void *buf) const -{ - memcpy(buf, m_strText.c_str(), GetDataSize(format)); - return TRUE; -} - -bool wxTextDataObject::SetData(const wxDataFormat& format, const void *buf) -{ - m_strText = (const wxChar *)buf; - return TRUE; -} - // ---------------------------------------------------------------------------- // wxFileDataObject // ---------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS( wxFileDataObject, wxDataObject ) - -wxFileDataObject::wxFileDataObject() +bool wxFileDataObject::GetDataHere(void *buf) const { + const wxString& filenames = GetFilenames(); + memcpy( buf, filenames.mbc_str(), filenames.Len() + 1 ); + + return TRUE; } -void wxFileDataObject::AddFile( const wxString &file ) +size_t wxFileDataObject::GetDataSize() const { - m_files += file; - m_files += (wxChar)0; + return GetFilenames().Len() + 1; } -wxString wxFileDataObject::GetFiles() const +bool wxFileDataObject::SetData(const void *buf) { - return m_files; -} + SetFilenames((const wxChar *)buf); -bool wxFileDataObject::GetDataHere(const wxDataFormat& format, void *buf) const -{ - if (format == wxDF_FILENAME) - { - memcpy( buf, m_files.mbc_str(), m_files.Len() + 1 ); - return TRUE; - } - - return FALSE; -} - -size_t wxFileDataObject::GetDataSize(const wxDataFormat& format) const -{ - if (format != wxDF_FILENAME) return 0; - - return m_files.Len() + 1; -} - -bool wxFileDataObject::SetData(const wxDataFormat& format, const void *buf) -{ - if (format != wxDF_FILENAME) - return FALSE; - - m_files = (char*)(buf); // this is so ugly, I cannot look at it - return TRUE; } @@ -248,96 +189,81 @@ bool wxFileDataObject::SetData(const wxDataFormat& format, const void *buf) // wxBitmapDataObject // ---------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS( wxBitmapDataObject, wxDataObject ) - wxBitmapDataObject::wxBitmapDataObject() { - m_pngData = (void*)NULL; - m_pngSize = 0; + Init(); } wxBitmapDataObject::wxBitmapDataObject( const wxBitmap& bitmap ) + : wxBitmapDataObjectBase(bitmap) { - m_pngData = (void*)NULL; - m_pngSize = 0; - m_bitmap = bitmap; + Init(); + DoConvertToPng(); } wxBitmapDataObject::~wxBitmapDataObject() { - if (m_pngData) - delete[] m_pngData; + Clear(); } void wxBitmapDataObject::SetBitmap( const wxBitmap &bitmap ) { - if (m_pngData) - delete[] m_pngData; - m_pngData = (void*)NULL; - m_pngSize = 0; - - m_bitmap = bitmap; + ClearAll(); + + wxBitmapDataObjectBase::SetBitmap(bitmap); + DoConvertToPng(); } -size_t wxBitmapDataObject::GetDataSize(const wxDataFormat& format) const +bool wxBitmapDataObject::GetDataHere(void *buf) const { - if (format != wxDF_BITMAP) return 0; - - return m_pngSize; -} - -bool wxBitmapDataObject::GetDataHere(const wxDataFormat& format, void *buf) const -{ - if (format != wxDF_BITMAP) return FALSE; - - if (m_pngSize > 0) + if ( !m_pngSize ) { - memcpy(buf, m_pngData, m_pngSize); - return TRUE; + wxFAIL_MSG( wxT("attempt to copy empty bitmap failed") ); + + return FALSE; } - - return FALSE; + + memcpy(buf, m_pngData, m_pngSize); + + return TRUE; } -bool wxBitmapDataObject::SetData(const wxDataFormat& format, const void *buf) +bool wxBitmapDataObject::SetData(size_t size, const void *buf) { - if (m_pngData) delete[] m_pngData; - m_pngData = (void*) NULL; - m_pngSize = 0; - m_bitmap = wxNullBitmap; - - return FALSE; -} + Clear(); -void wxBitmapDataObject::SetPngData(const void *buf, size_t size) -{ - if (m_pngData) delete[] m_pngData; m_pngSize = size; - m_pngData = (void*) new char[m_pngSize]; - + m_pngData = malloc(m_pngSize); + memcpy( m_pngData, buf, m_pngSize ); - + wxMemoryInputStream mstream( (char*) m_pngData, m_pngSize ); wxImage image; wxPNGHandler handler; - handler.LoadFile( &image, mstream ); + if ( !handler.LoadFile( &image, mstream ) ) + { + return FALSE; + } + m_bitmap = image.ConvertToBitmap(); } void wxBitmapDataObject::DoConvertToPng() { - if (!m_bitmap.Ok()) return; - + if (!m_bitmap.Ok()) + return; + wxImage image( m_bitmap ); wxPNGHandler handler; - + wxCountingOutputStream count; handler.SaveFile( &image, count ); + m_pngSize = count.GetSize() + 100; // sometimes the size seems to vary ??? - m_pngData = (void*) new char[m_pngSize]; - + m_pngData = malloc(m_pngSize); + wxMemoryOutputStream mstream( (char*) m_pngData, m_pngSize ); handler.SaveFile( &image, mstream ); } diff --git a/src/motif/clipbrd.cpp b/src/motif/clipbrd.cpp index 0cc48a40f0..93c36445be 100644 --- a/src/motif/clipbrd.cpp +++ b/src/motif/clipbrd.cpp @@ -363,26 +363,6 @@ bool wxClipboard::GetData( wxDataObject *data ) return FALSE; } -//----------------------------------------------------------------------------- -// wxClipboardModule -//----------------------------------------------------------------------------- - -IMPLEMENT_DYNAMIC_CLASS(wxClipboardModule,wxModule) - -bool wxClipboardModule::OnInit() -{ - wxTheClipboard = new wxClipboard(); - - return TRUE; -} - -void wxClipboardModule::OnExit() -{ - if (wxTheClipboard) delete wxTheClipboard; - wxTheClipboard = (wxClipboard*) NULL; -} - - #if 0 /* diff --git a/src/msw/clipbrd.cpp b/src/msw/clipbrd.cpp index 043d879ae2..a24d4c3c58 100644 --- a/src/msw/clipbrd.cpp +++ b/src/msw/clipbrd.cpp @@ -778,25 +778,6 @@ bool wxClipboard::GetData( wxDataObject *data ) #endif // wxUSE_DATAOBJ/!wxUSE_DATAOBJ } -//----------------------------------------------------------------------------- -// wxClipboardModule -//----------------------------------------------------------------------------- - -IMPLEMENT_DYNAMIC_CLASS(wxClipboardModule,wxModule) - -bool wxClipboardModule::OnInit() -{ - wxTheClipboard = new wxClipboard(); - - return TRUE; -} - -void wxClipboardModule::OnExit() -{ - if (wxTheClipboard) delete wxTheClipboard; - wxTheClipboard = (wxClipboard*) NULL; -} - #else #error "Please turn wxUSE_CLIPBOARD on to compile this file." #endif // wxUSE_CLIPBOARD diff --git a/src/msw/ole/dropsrc.cpp b/src/msw/ole/dropsrc.cpp index 3384ac0057..bd296c8abb 100644 --- a/src/msw/ole/dropsrc.cpp +++ b/src/msw/ole/dropsrc.cpp @@ -177,11 +177,6 @@ wxDropSource::wxDropSource(wxDataObject& data, SetData(data); } -void wxDropSource::SetData(wxDataObject& data) -{ - m_pData = &data; -} - wxDropSource::~wxDropSource() { m_pIDropSource->Release();