1. wxPostEvent added and documented

2. Made it possible to have wxDataObjects which support multiple formats
   painlessly
3. Extensively modified dnd sample to show a "real life" wxDataObject


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4028 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1999-10-17 01:18:49 +00:00
parent 6d693bb4fc
commit 8e193f384f
24 changed files with 1359 additions and 637 deletions

View File

@@ -307,6 +307,15 @@ extern void WXDLLEXPORT wxExit();
// Yield to other apps/messages
extern bool WXDLLEXPORT wxYield();
// Post a message to the given eventhandler which will be processed during the
// next event loop iteration
inline void WXDLLEXPORT wxPostEvent(wxEvtHandler *dest, wxEvent& event)
{
wxCHECK_RET( dest, wxT("need an object to post event to in wxPostEvent") );
dest->AddPendingEvent(event);
}
#endif // wxUSE_GUI
// console applications may avoid using DECLARE_APP and IMPLEMENT_APP macros

View File

@@ -1281,6 +1281,10 @@ protected:
wxEVT_COMPARE_ITEM
*/
// ============================================================================
// event handler and related classes
// ============================================================================
typedef void (wxObject::*wxObjectEventFunction)(wxEvent&);
struct WXDLLEXPORT wxEventTableEntry
@@ -1314,9 +1318,45 @@ public:
void SetNextHandler(wxEvtHandler *handler) { m_nextHandler = handler; }
void SetPreviousHandler(wxEvtHandler *handler) { m_previousHandler = handler; }
void SetEvtHandlerEnabled(bool en) { m_enabled = en; }
void SetEvtHandlerEnabled(bool enabled) { m_enabled = enabled; }
bool GetEvtHandlerEnabled() const { return m_enabled; }
// process an event right now
virtual bool ProcessEvent(wxEvent& event);
// add an event to be processed later
void AddPendingEvent(wxEvent& event);
// process all pending events
void ProcessPendingEvents();
// add a
#if wxUSE_THREADS
bool ProcessThreadEvent(wxEvent& event);
#endif
// Dynamic association of a member function handler with the event handler,
// id and event type
void Connect( int id, int lastId, wxEventType eventType,
wxObjectEventFunction func,
wxObject *userData = (wxObject *) NULL );
// Convenience function: take just one id
void Connect( int id, wxEventType eventType,
wxObjectEventFunction func,
wxObject *userData = (wxObject *) NULL )
{ Connect(id, -1, eventType, func, userData); }
// implementation from now on
virtual bool SearchEventTable(wxEventTable& table, wxEvent& event);
bool SearchDynamicEventTable( wxEvent& event );
#if wxUSE_THREADS
void ClearEventLocker() { delete m_eventsLocker; m_eventsLocker = NULL; };
#endif
// old stuff
#if WXWIN_COMPATIBILITY_2
virtual void OnCommand(wxWindow& WXUNUSED(win),
wxCommandEvent& WXUNUSED(event))
@@ -1333,33 +1373,8 @@ public:
virtual bool OnClose();
#endif
#if wxUSE_THREADS
bool ProcessThreadEvent(wxEvent& event);
void ProcessPendingEvents();
#endif
virtual bool ProcessEvent(wxEvent& event);
virtual bool SearchEventTable(wxEventTable& table, wxEvent& event);
// Dynamic association of a member function handler with the event handler,
// id and event type
void Connect( int id, int lastId, wxEventType eventType,
wxObjectEventFunction func,
wxObject *userData = (wxObject *) NULL );
// Convenience function: take just one id
void Connect( int id, wxEventType eventType,
wxObjectEventFunction func,
wxObject *userData = (wxObject *) NULL )
{ Connect(id, -1, eventType, func, userData); }
bool SearchDynamicEventTable( wxEvent& event );
#if wxUSE_THREADS
void ClearEventLocker() { delete m_eventsLocker; m_eventsLocker = NULL; };
#endif
private:
static const wxEventTableEntry sm_eventTableEntries[];
static const wxEventTableEntry sm_eventTableEntries[];
protected:
static const wxEventTable sm_eventTable;
@@ -1369,7 +1384,6 @@ protected:
protected:
wxEvtHandler* m_nextHandler;
wxEvtHandler* m_previousHandler;
bool m_enabled; // Is event handler enabled?
wxList* m_dynamicEvents;
wxList* m_pendingEvents;
#if wxUSE_THREADS
@@ -1379,6 +1393,9 @@ protected:
// optimization: instead of using costly IsKindOf() to decide whether we're
// a window (which is true in 99% of cases), use this flag
bool m_isWindow;
// Is event handler enabled?
bool m_enabled;
};
typedef void (wxEvtHandler::*wxEventFunction)(wxEvent&);
@@ -1614,6 +1631,17 @@ const wxEventTableEntry theClass::sm_eventTableEntries[] = { \
#define EVT_UPDATE_UI(id, func) \
{ wxEVT_UPDATE_UI, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxUpdateUIEventFunction) & func, (wxObject *) NULL },\
// ----------------------------------------------------------------------------
// Global data
// ----------------------------------------------------------------------------
// for pending event processing - notice that there is intentionally no
// WXDLLEXPORT here
extern wxList *wxPendingEvents;
#if wxUSE_THREADS
extern wxCriticalSection *wxPendingEventsLocker;
#endif
// ----------------------------------------------------------------------------
// Helper functions
// ----------------------------------------------------------------------------

View File

@@ -49,22 +49,22 @@ public:
wxDropTarget();
~wxDropTarget();
/* may be overridden to react to events */
virtual void OnEnter();
virtual void OnLeave();
/* may be overridden to reject certain formats or drops
on certain areas. always returns TRUE by default
indicating that you'd accept the data from the drag. */
virtual bool OnMove( long x, long y );
/* has to be overridden to accept a drop event. call
/* has to be overridden to accept a drop event. call
IsSupported() to ask which formats are available
and then call RequestData() to indicate the format
and then call RequestData() to indicate the format
you request. */
virtual bool OnDrop( long x, long y );
/* this gets called once the data has actually arrived. get
it with GetData(). this has to be overridden. */
virtual bool OnData( long x, long y );
@@ -75,21 +75,21 @@ public:
/* called to query what formats are available */
bool IsSupported( wxDataFormat format );
/* fill data with data from the dragging source */
bool GetData( wxDataObject *data );
// implementation
void RegisterWidget( GtkWidget *widget );
void UnregisterWidget( GtkWidget *widget );
GdkDragContext *m_dragContext;
GtkWidget *m_dragWidget;
GtkSelectionData *m_dragData;
guint m_dragTime;
bool m_firstMotion; /* gdk has no "gdk_drag_enter" event */
void SetDragContext( GdkDragContext *dc ) { m_dragContext = dc; }
void SetDragWidget( GtkWidget *w ) { m_dragWidget = w; }
void SetDragData( GtkSelectionData *sd ) { m_dragData = sd; }
@@ -109,10 +109,10 @@ public:
virtual bool OnMove( long x, long y );
virtual bool OnDrop( long x, long y );
virtual bool OnData( long x, long y );
/* you have to override OnDropData to get at the text */
virtual bool OnDropText( long x, long y, const wxChar *text ) = 0;
};
//-------------------------------------------------------------------------
@@ -128,21 +128,21 @@ public:
wxPrivateDropTarget();
/* see SetId() below for explanation */
wxPrivateDropTarget( const wxString &id );
virtual bool OnMove( long x, long y );
virtual bool OnDrop( long x, long y );
virtual bool OnData( long x, long y );
/* you have to override OnDropData to get at the data */
virtual bool OnDropData( long x, long y, void *data, size_t size ) = 0;
/* 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" or
"image/png". */
void SetId( const wxString& id ) { m_id = id; }
wxString GetId() { return m_id; }
private:
wxString m_id;
@@ -155,13 +155,13 @@ private:
class wxFileDropTarget: public wxDropTarget
{
public:
wxFileDropTarget() {}
virtual bool OnMove( long x, long y );
virtual bool OnDrop( long x, long y );
virtual bool OnData( long x, long y );
/* you have to override OnDropFiles to get at the file names */
virtual bool OnDropFiles( long x, long y, size_t nFiles, const wxChar * const aszFiles[] ) = 0;
@@ -186,43 +186,46 @@ public:
/* constructor. set data later with SetData() */
wxDropSource( wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon );
/* constructor for setting one data object */
wxDropSource( wxDataObject *data, wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon );
wxDropSource( wxDataObject& data, wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon );
/* constructor for setting several data objects via wxDataBroker */
wxDropSource( wxDataBroker *data, wxWindow *win );
~wxDropSource();
/* set several dataobjects via wxDataBroker */
void SetData( wxDataBroker *data );
/* set one dataobject */
void SetData( wxDataObject& data );
// this one isn't portable to wxMSW -- deprecated
void SetData( wxDataObject *data );
/* start drag action */
wxDragResult DoDragDrop( bool bAllowMove = FALSE );
/* override to give feedback */
virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; }
/* GTK implementation */
void RegisterWindow();
void UnregisterWindow();
GtkWidget *m_widget;
wxWindow *m_window;
wxDragResult m_retValue;
wxDataBroker *m_data;
wxCursor m_defaultCursor;
wxCursor m_goaheadCursor;
wxIcon m_goIcon;
wxIcon m_stopIcon;
bool m_waiting;
};
@@ -230,6 +233,6 @@ public:
// wxUSE_DRAG_AND_DROP
#endif
#endif
//__GTKDNDH__

View File

@@ -49,22 +49,22 @@ public:
wxDropTarget();
~wxDropTarget();
/* may be overridden to react to events */
virtual void OnEnter();
virtual void OnLeave();
/* may be overridden to reject certain formats or drops
on certain areas. always returns TRUE by default
indicating that you'd accept the data from the drag. */
virtual bool OnMove( long x, long y );
/* has to be overridden to accept a drop event. call
/* has to be overridden to accept a drop event. call
IsSupported() to ask which formats are available
and then call RequestData() to indicate the format
and then call RequestData() to indicate the format
you request. */
virtual bool OnDrop( long x, long y );
/* this gets called once the data has actually arrived. get
it with GetData(). this has to be overridden. */
virtual bool OnData( long x, long y );
@@ -75,21 +75,21 @@ public:
/* called to query what formats are available */
bool IsSupported( wxDataFormat format );
/* fill data with data from the dragging source */
bool GetData( wxDataObject *data );
// implementation
void RegisterWidget( GtkWidget *widget );
void UnregisterWidget( GtkWidget *widget );
GdkDragContext *m_dragContext;
GtkWidget *m_dragWidget;
GtkSelectionData *m_dragData;
guint m_dragTime;
bool m_firstMotion; /* gdk has no "gdk_drag_enter" event */
void SetDragContext( GdkDragContext *dc ) { m_dragContext = dc; }
void SetDragWidget( GtkWidget *w ) { m_dragWidget = w; }
void SetDragData( GtkSelectionData *sd ) { m_dragData = sd; }
@@ -109,10 +109,10 @@ public:
virtual bool OnMove( long x, long y );
virtual bool OnDrop( long x, long y );
virtual bool OnData( long x, long y );
/* you have to override OnDropData to get at the text */
virtual bool OnDropText( long x, long y, const wxChar *text ) = 0;
};
//-------------------------------------------------------------------------
@@ -128,21 +128,21 @@ public:
wxPrivateDropTarget();
/* see SetId() below for explanation */
wxPrivateDropTarget( const wxString &id );
virtual bool OnMove( long x, long y );
virtual bool OnDrop( long x, long y );
virtual bool OnData( long x, long y );
/* you have to override OnDropData to get at the data */
virtual bool OnDropData( long x, long y, void *data, size_t size ) = 0;
/* 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" or
"image/png". */
void SetId( const wxString& id ) { m_id = id; }
wxString GetId() { return m_id; }
private:
wxString m_id;
@@ -155,13 +155,13 @@ private:
class wxFileDropTarget: public wxDropTarget
{
public:
wxFileDropTarget() {}
virtual bool OnMove( long x, long y );
virtual bool OnDrop( long x, long y );
virtual bool OnData( long x, long y );
/* you have to override OnDropFiles to get at the file names */
virtual bool OnDropFiles( long x, long y, size_t nFiles, const wxChar * const aszFiles[] ) = 0;
@@ -186,43 +186,46 @@ public:
/* constructor. set data later with SetData() */
wxDropSource( wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon );
/* constructor for setting one data object */
wxDropSource( wxDataObject *data, wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon );
wxDropSource( wxDataObject& data, wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon );
/* constructor for setting several data objects via wxDataBroker */
wxDropSource( wxDataBroker *data, wxWindow *win );
~wxDropSource();
/* set several dataobjects via wxDataBroker */
void SetData( wxDataBroker *data );
/* set one dataobject */
void SetData( wxDataObject& data );
// this one isn't portable to wxMSW -- deprecated
void SetData( wxDataObject *data );
/* start drag action */
wxDragResult DoDragDrop( bool bAllowMove = FALSE );
/* override to give feedback */
virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; }
/* GTK implementation */
void RegisterWindow();
void UnregisterWindow();
GtkWidget *m_widget;
wxWindow *m_window;
wxDragResult m_retValue;
wxDataBroker *m_data;
wxCursor m_defaultCursor;
wxCursor m_goaheadCursor;
wxIcon m_goIcon;
wxIcon m_stopIcon;
bool m_waiting;
};
@@ -230,6 +233,6 @@ public:
// wxUSE_DRAG_AND_DROP
#endif
#endif
//__GTKDNDH__

View File

@@ -83,9 +83,7 @@ public:
virtual bool ProcessMessage(WXMSG* pMsg);
void DeletePendingObjects();
bool ProcessIdle();
#if wxUSE_THREADS
void ProcessPendingEvents();
#endif
int GetComCtl32Version() const;
public:

View File

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

View File

@@ -13,9 +13,9 @@
#define _WX_OLEDROPSRC_H
#ifdef __GNUG__
#pragma interface
#pragma interface
#endif
#include "wx/window.h"
#if !wxUSE_DRAG_AND_DROP
#error "You should #define wxUSE_DRAG_AND_DROP to 1 to compile this file!"
#endif //WX_DRAG_DROP
@@ -23,30 +23,42 @@
// ----------------------------------------------------------------------------
// forward declarations
// ----------------------------------------------------------------------------
class wxIDropSource;
class wxDataObject;
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.
// ----------------------------------------------------------------------------
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
wxDropSource(wxWindow *win = NULL);
wxDropSource(wxDataObject& data, wxWindow *win = NULL);
// 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);