1998-05-20 10:01:55 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: dnd.h
|
|
|
|
// Purpose: declaration of the wxDropTarget class
|
|
|
|
// Author: Robert Roebling
|
1998-10-29 13:03:18 -05:00
|
|
|
// RCS-ID: $Id$
|
1998-05-20 10:01:55 -04:00
|
|
|
// Copyright: (c) 1998 Vadim Zeitlin, Robert Roebling
|
|
|
|
// Licence: wxWindows license
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __GTKDNDH__
|
|
|
|
#define __GTKDNDH__
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
1999-01-06 16:09:17 -05:00
|
|
|
#if wxUSE_DRAG_AND_DROP
|
1999-01-04 08:52:06 -05:00
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
#include "wx/object.h"
|
|
|
|
#include "wx/string.h"
|
1998-12-14 11:13:49 -05:00
|
|
|
#include "wx/dataobj.h"
|
1998-05-20 10:01:55 -04:00
|
|
|
#include "wx/cursor.h"
|
1999-02-09 03:18:14 -05:00
|
|
|
#include "wx/icon.h"
|
|
|
|
#include "wx/gdicmn.h"
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// classes
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class wxWindow;
|
|
|
|
|
|
|
|
class wxDropTarget;
|
|
|
|
class wxTextDropTarget;
|
1998-07-27 16:50:48 -04:00
|
|
|
class wxFileDropTarget;
|
1999-01-13 19:24:03 -05:00
|
|
|
class wxPrivateDropTarget;
|
1998-07-27 16:50:48 -04:00
|
|
|
|
|
|
|
class wxDropSource;
|
|
|
|
|
1999-04-06 13:24:14 -04:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// wxDropTarget
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class wxDropTarget: public wxObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
1999-10-20 21:58:57 -04:00
|
|
|
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
|
|
|
|
IsSupported() to ask which formats are available
|
|
|
|
and then call RequestData() to indicate the format
|
|
|
|
you request. */
|
|
|
|
virtual bool OnDrop( long x, long y );
|
1999-10-16 21:18:49 -04:00
|
|
|
|
1999-10-20 21:58:57 -04:00
|
|
|
/* 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 );
|
1999-10-16 21:18:49 -04:00
|
|
|
|
1999-10-20 21:58:57 -04:00
|
|
|
/* called from within OnDrop() to request a certain format
|
|
|
|
from the drop event. */
|
|
|
|
bool RequestData( wxDataFormat format );
|
1999-10-16 21:18:49 -04:00
|
|
|
|
1999-10-20 21:58:57 -04:00
|
|
|
/* called to query what formats are available */
|
|
|
|
bool IsSupported( wxDataFormat format );
|
1999-04-06 13:24:14 -04:00
|
|
|
|
1999-10-20 21:58:57 -04:00
|
|
|
/* fill data with data from the dragging source */
|
|
|
|
bool GetData( wxDataObject *data );
|
1999-04-06 13:24:14 -04:00
|
|
|
|
1999-10-20 21:58:57 -04:00
|
|
|
virtual size_t GetFormatCount() const = 0;
|
|
|
|
virtual wxDataFormat GetFormat(size_t n) const = 0;
|
|
|
|
|
1999-10-19 18:13:33 -04:00
|
|
|
// implementation
|
1999-04-06 13:24:14 -04:00
|
|
|
|
1999-10-20 21:58:57 -04:00
|
|
|
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; }
|
|
|
|
void SetDragTime( guint time ) { m_dragTime = time; }
|
|
|
|
};
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// wxTextDropTarget
|
|
|
|
//-------------------------------------------------------------------------
|
1999-10-16 21:18:49 -04:00
|
|
|
|
1999-10-20 21:58:57 -04:00
|
|
|
class wxTextDropTarget: public wxDropTarget
|
|
|
|
{
|
|
|
|
public:
|
1999-10-16 21:18:49 -04:00
|
|
|
|
1999-10-20 21:58:57 -04:00
|
|
|
wxTextDropTarget() {}
|
1999-10-16 21:18:49 -04:00
|
|
|
|
1999-10-20 21:58:57 -04:00
|
|
|
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;
|
|
|
|
|
|
|
|
virtual size_t GetFormatCount() const
|
|
|
|
{ return 1; }
|
|
|
|
virtual wxDataFormat GetFormat(size_t n) const
|
|
|
|
{ return wxDF_TEXT; }
|
1999-04-06 13:24:14 -04:00
|
|
|
};
|
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
//-------------------------------------------------------------------------
|
1999-10-20 21:58:57 -04:00
|
|
|
// wxPrivateDropTarget
|
1998-05-20 10:01:55 -04:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
1999-10-20 21:58:57 -04:00
|
|
|
/*
|
|
|
|
class wxPrivateDropTarget: public wxDropTarget
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
1999-10-20 21:58:57 -04:00
|
|
|
public:
|
|
|
|
|
|
|
|
wxPrivateDropTarget();
|
|
|
|
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 );
|
|
|
|
|
|
|
|
virtual bool OnDropData( long x, long y, void *data, size_t size ) = 0;
|
|
|
|
|
|
|
|
void SetId( const wxString& id ) { m_id = id; }
|
|
|
|
wxString GetId() { return m_id; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
wxString m_id;
|
1998-05-20 10:01:55 -04:00
|
|
|
};
|
1999-10-20 21:58:57 -04:00
|
|
|
*/
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-10-20 21:58:57 -04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// A drop target which accepts files (dragged from File Manager or Explorer)
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class wxFileDropTarget: public wxDropTarget
|
1999-01-13 19:24:03 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
1999-10-20 21:58:57 -04:00
|
|
|
wxFileDropTarget() {}
|
|
|
|
|
|
|
|
virtual bool OnData( long x, long y );
|
1999-10-16 21:18:49 -04:00
|
|
|
|
1999-10-20 21:58:57 -04:00
|
|
|
virtual bool OnDropFiles( long x, long y, size_t nFiles, const wxChar * const aszFiles[] ) = 0;
|
|
|
|
|
|
|
|
virtual size_t GetFormatCount() const
|
|
|
|
{ return 1; }
|
|
|
|
virtual wxDataFormat GetFormat(size_t n) const
|
|
|
|
{ return wxDF_FILENAME; }
|
|
|
|
};
|
1999-10-16 21:18:49 -04:00
|
|
|
|
1999-10-20 21:58:57 -04:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// wxDropSource
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class wxDropSource: public wxObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/* constructor. set data later with SetData() */
|
|
|
|
wxDropSource( wxWindow *win,
|
|
|
|
const wxIcon &go = wxNullIcon,
|
|
|
|
const wxIcon &stop = wxNullIcon );
|
1999-10-16 21:18:49 -04:00
|
|
|
|
1999-10-20 21:58:57 -04:00
|
|
|
/* constructor for setting one data object */
|
|
|
|
wxDropSource( wxDataObject& data,
|
|
|
|
wxWindow *win,
|
|
|
|
const wxIcon &go = wxNullIcon,
|
|
|
|
const wxIcon &stop = wxNullIcon );
|
1999-10-16 21:18:49 -04:00
|
|
|
|
1999-10-20 21:58:57 -04:00
|
|
|
~wxDropSource();
|
1999-10-16 21:18:49 -04:00
|
|
|
|
1999-10-20 21:58:57 -04:00
|
|
|
/* start drag action */
|
|
|
|
virtual wxDragResult DoDragDrop( bool bAllowMove = FALSE );
|
1999-10-16 21:18:49 -04:00
|
|
|
|
1999-10-20 21:58:57 -04:00
|
|
|
/* GTK implementation */
|
|
|
|
void RegisterWindow();
|
|
|
|
void UnregisterWindow();
|
1999-10-16 21:18:49 -04:00
|
|
|
|
1999-04-20 06:09:15 -04:00
|
|
|
GtkWidget *m_widget;
|
|
|
|
wxWindow *m_window;
|
|
|
|
wxDragResult m_retValue;
|
1999-10-18 18:22:56 -04:00
|
|
|
wxDataObject *m_data;
|
1999-10-16 21:18:49 -04:00
|
|
|
|
1999-04-20 06:09:15 -04:00
|
|
|
wxCursor m_defaultCursor;
|
|
|
|
wxCursor m_goaheadCursor;
|
1999-10-16 21:18:49 -04:00
|
|
|
|
1999-04-20 06:09:15 -04:00
|
|
|
wxIcon m_goIcon;
|
|
|
|
wxIcon m_stopIcon;
|
1999-10-16 21:18:49 -04:00
|
|
|
|
1999-04-20 06:09:15 -04:00
|
|
|
bool m_waiting;
|
1998-05-20 10:01:55 -04:00
|
|
|
};
|
|
|
|
|
1999-01-04 08:52:06 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// wxUSE_DRAG_AND_DROP
|
|
|
|
|
1999-10-16 21:18:49 -04:00
|
|
|
#endif
|
1998-05-20 10:01:55 -04:00
|
|
|
//__GTKDNDH__
|
|
|
|
|