More DnD.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4100 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling 1999-10-21 13:09:06 +00:00
parent 79ec2ce20e
commit 97c79de27c
9 changed files with 206 additions and 54 deletions

View File

@ -73,15 +73,6 @@ public:
// X11 has two clipboards which get selected by this call. Empty on MSW. // X11 has two clipboards which get selected by this call. Empty on MSW.
virtual void UsePrimarySelection( bool WXUNUSED(primary) = FALSE ) { } 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
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@ -45,8 +45,10 @@ public:
// set the data which is transfered by drag and drop // set the data which is transfered by drag and drop
void SetData(wxDataObject& data) void SetData(wxDataObject& data)
{ if (m_data) delete m_data; { m_data = &data; }
m_data = &data; }
wxDataObject *GetDataObject()
{ return m_data; }
// start drag action, see enum wxDragResult for return value description // start drag action, see enum wxDragResult for return value description
// //

View File

@ -33,7 +33,6 @@ class wxWindow;
class wxDropTarget; class wxDropTarget;
class wxTextDropTarget; class wxTextDropTarget;
class wxFileDropTarget; class wxFileDropTarget;
class wxPrivateDropTarget;
class wxDropSource; class wxDropSource;
@ -70,6 +69,37 @@ public:
void SetDragTime( guint time ) { m_dragTime = time; } void SetDragTime( guint time ) { m_dragTime = time; }
}; };
// ----------------------------------------------------------------------------
// A simple wxDropTarget derived class for text data: you only need to
// override OnDropText() to get something working
// ----------------------------------------------------------------------------
class wxTextDropTarget : public wxDropTarget
{
public:
wxTextDropTarget();
virtual bool OnDropText(wxCoord x, wxCoord y, const wxString& text) = 0;
virtual bool OnData(wxCoord x, wxCoord y);
};
// ----------------------------------------------------------------------------
// A drop target which accepts files (dragged from File Manager or Explorer)
// ----------------------------------------------------------------------------
class wxFileDropTarget : public wxDropTarget
{
public:
wxFileDropTarget();
// parameters are the number of files and the array of file names
virtual bool OnDropFiles(wxCoord x, wxCoord y,
const wxArrayString& filenames) = 0;
virtual bool OnData(wxCoord x, wxCoord y);
};
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// wxDropSource // wxDropSource
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@ -100,7 +130,6 @@ public:
GtkWidget *m_widget; GtkWidget *m_widget;
wxWindow *m_window; wxWindow *m_window;
wxDragResult m_retValue; wxDragResult m_retValue;
wxDataObject *m_data;
wxCursor m_defaultCursor; wxCursor m_defaultCursor;
wxCursor m_goaheadCursor; wxCursor m_goaheadCursor;

View File

@ -33,7 +33,6 @@ class wxWindow;
class wxDropTarget; class wxDropTarget;
class wxTextDropTarget; class wxTextDropTarget;
class wxFileDropTarget; class wxFileDropTarget;
class wxPrivateDropTarget;
class wxDropSource; class wxDropSource;
@ -70,6 +69,37 @@ public:
void SetDragTime( guint time ) { m_dragTime = time; } void SetDragTime( guint time ) { m_dragTime = time; }
}; };
// ----------------------------------------------------------------------------
// A simple wxDropTarget derived class for text data: you only need to
// override OnDropText() to get something working
// ----------------------------------------------------------------------------
class wxTextDropTarget : public wxDropTarget
{
public:
wxTextDropTarget();
virtual bool OnDropText(wxCoord x, wxCoord y, const wxString& text) = 0;
virtual bool OnData(wxCoord x, wxCoord y);
};
// ----------------------------------------------------------------------------
// A drop target which accepts files (dragged from File Manager or Explorer)
// ----------------------------------------------------------------------------
class wxFileDropTarget : public wxDropTarget
{
public:
wxFileDropTarget();
// parameters are the number of files and the array of file names
virtual bool OnDropFiles(wxCoord x, wxCoord y,
const wxArrayString& filenames) = 0;
virtual bool OnData(wxCoord x, wxCoord y);
};
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// wxDropSource // wxDropSource
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@ -100,7 +130,6 @@ public:
GtkWidget *m_widget; GtkWidget *m_widget;
wxWindow *m_window; wxWindow *m_window;
wxDragResult m_retValue; wxDragResult m_retValue;
wxDataObject *m_data;
wxCursor m_defaultCursor; wxCursor m_defaultCursor;
wxCursor m_goaheadCursor; wxCursor m_goaheadCursor;

View File

@ -479,7 +479,10 @@
* Use Apple Ieee-double converter * Use Apple Ieee-double converter
*/ */
#define wxUSE_APPLE_IEEE 0 #define wxUSE_APPLE_IEEE 0
/*
* Compatibility with 2.0 API.
*/
#define WXWIN_COMPATIBILITY_2 1
/* /*
* Enables debugging: memory tracing, assert, etc., contains debug level * Enables debugging: memory tracing, assert, etc., contains debug level
*/ */

View File

@ -33,17 +33,6 @@
#endif #endif
#include "wx/thread.h" #include "wx/thread.h"
#include "wx/clipbrd.h"
// ===========================================================================
// implementation
// ===========================================================================
// ----------------------------------------------------------------------------
// some global data defined here
// ----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxClipboardModule, wxModule)
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// wxAppBase // wxAppBase

View File

@ -42,12 +42,13 @@ wxClipboardBase::wxClipboardBase()
// wxClipboardModule: module responsible for initializing the global clipboard // wxClipboardModule: module responsible for initializing the global clipboard
// object // object
// //
// NB: IMPLEMENT_DYNAMIC_CLASS() for it is in common/appcmn.cpp
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class wxClipboardModule : public wxModule class wxClipboardModule : public wxModule
{ {
public: public:
wxClipboardModule() { }
bool OnInit() bool OnInit()
{ wxTheClipboard = new wxClipboard; return TRUE; } { wxTheClipboard = new wxClipboard; return TRUE; }
void OnExit() void OnExit()
@ -57,3 +58,5 @@ private:
DECLARE_DYNAMIC_CLASS(wxClipboardModule) DECLARE_DYNAMIC_CLASS(wxClipboardModule)
}; };
IMPLEMENT_DYNAMIC_CLASS(wxClipboardModule,wxModule)

View File

@ -256,6 +256,8 @@ static gboolean target_drag_drop( GtkWidget *widget,
if (!ret) if (!ret)
{ {
wxLogDebug( wxT( "Drop target: OnDrop returned TRUE") );
/* cancel the whole thing */ /* cancel the whole thing */
gtk_drag_finish( context, gtk_drag_finish( context,
FALSE, /* no success */ FALSE, /* no success */
@ -264,6 +266,8 @@ static gboolean target_drag_drop( GtkWidget *widget,
} }
else else
{ {
wxLogDebug( wxT( "Drop target: OnDrop returned TRUE") );
#if wxUSE_THREADS #if wxUSE_THREADS
/* disable GUI threads */ /* disable GUI threads */
wxapp_uninstall_thread_wakeup(); wxapp_uninstall_thread_wakeup();
@ -324,7 +328,7 @@ static void target_drag_data_received( GtkWidget *WXUNUSED(widget),
return; return;
} }
wxLogDebug( wxT( "Drop target: data received") ); wxLogDebug( wxT( "Drop target: data received event") );
/* inform the wxDropTarget about the current GtkSelectionData. /* inform the wxDropTarget about the current GtkSelectionData.
this is only valid for the duration of this call */ this is only valid for the duration of this call */
@ -332,11 +336,15 @@ static void target_drag_data_received( GtkWidget *WXUNUSED(widget),
if (drop_target->OnData( x, y )) if (drop_target->OnData( x, y ))
{ {
wxLogDebug( wxT( "Drop target: OnData returned TRUE") );
/* tell GTK that data transfer was successfull */ /* tell GTK that data transfer was successfull */
gtk_drag_finish( context, TRUE, FALSE, time ); gtk_drag_finish( context, TRUE, FALSE, time );
} }
else else
{ {
wxLogDebug( wxT( "Drop target: OnData returned FALSE") );
/* tell GTK that data transfer was not successfull */ /* tell GTK that data transfer was not successfull */
gtk_drag_finish( context, FALSE, FALSE, time ); gtk_drag_finish( context, FALSE, FALSE, time );
} }
@ -448,7 +456,9 @@ bool wxDropTarget::GetData()
return TRUE; return TRUE;
} }
return FALSE; m_dataObject->SetData( dragFormat, (size_t)m_dragData->length, (const void*)m_dragData->data );
return TRUE;
} }
void wxDropTarget::UnregisterWidget( GtkWidget *widget ) void wxDropTarget::UnregisterWidget( GtkWidget *widget )
@ -503,6 +513,41 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget )
GTK_SIGNAL_FUNC(target_drag_data_received), (gpointer) this ); GTK_SIGNAL_FUNC(target_drag_data_received), (gpointer) this );
} }
// ----------------------------------------------------------------------------
// wxTextDropTarget
// ----------------------------------------------------------------------------
wxTextDropTarget::wxTextDropTarget()
: wxDropTarget(new wxTextDataObject)
{
}
bool wxTextDropTarget::OnData(wxCoord x, wxCoord y)
{
if ( !GetData() )
return FALSE;
return OnDropText(x, y, ((wxTextDataObject *)m_dataObject)->GetText());
}
// ----------------------------------------------------------------------------
// wxFileDropTarget
// ----------------------------------------------------------------------------
wxFileDropTarget::wxFileDropTarget()
: wxDropTarget(new wxFileDataObject)
{
}
bool wxFileDropTarget::OnData(wxCoord x, wxCoord y)
{
if ( !GetData() )
return FALSE;
return OnDropFiles(x, y,
((wxFileDataObject *)m_dataObject)->GetFilenames());
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// "drag_data_get" // "drag_data_get"
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -517,33 +562,41 @@ source_drag_data_get (GtkWidget *WXUNUSED(widget),
{ {
if (g_isIdle) wxapp_install_idle_handler(); if (g_isIdle) wxapp_install_idle_handler();
#ifdef __WXDEBUG__ wxDataFormat format( selection_data->target );
char *name = gdk_atom_name( selection_data->target );
if (name) wxLogDebug( wxT("Drop source: format requested: %s"), name ); wxLogDebug( wxT("Drop source: format requested: %s"), format.GetId().c_str() );
#endif
drop_source->m_retValue = wxDragCancel; drop_source->m_retValue = wxDragCancel;
wxDataObject *data = drop_source->m_data; wxDataObject *data = drop_source->GetDataObject();
if (!data) if (!data)
{
wxLogDebug( wxT("Drop source: no data object") );
return; return;
}
if (!data->IsSupportedFormat(selection_data->target)) if (!data->IsSupportedFormat(format))
{
wxLogDebug( wxT("Drop source: unsupported format") );
return; return;
}
if (data->GetDataSize(selection_data->target) == 0) if (data->GetDataSize(format) == 0)
{
wxLogDebug( wxT("Drop source: empty data") );
return; return;
}
size_t size = data->GetDataSize(selection_data->target); size_t size = data->GetDataSize(format);
// printf( "data size: %d.\n", (int)data_size ); // printf( "data size: %d.\n", (int)data_size );
guchar *d = new guchar[size]; guchar *d = new guchar[size];
if (!data->GetDataHere( selection_data->target, (void*)d )) if (!data->GetDataHere( format, (void*)d ))
{ {
free( d ); delete[] d;
return; return;
} }
@ -563,7 +616,7 @@ source_drag_data_get (GtkWidget *WXUNUSED(widget),
wxapp_install_thread_wakeup(); wxapp_install_thread_wakeup();
#endif #endif
free( d ); delete[] d;
/* so far only copy, no moves. TODO. */ /* so far only copy, no moves. TODO. */
drop_source->m_retValue = wxDragCopy; drop_source->m_retValue = wxDragCopy;

View File

@ -256,6 +256,8 @@ static gboolean target_drag_drop( GtkWidget *widget,
if (!ret) if (!ret)
{ {
wxLogDebug( wxT( "Drop target: OnDrop returned TRUE") );
/* cancel the whole thing */ /* cancel the whole thing */
gtk_drag_finish( context, gtk_drag_finish( context,
FALSE, /* no success */ FALSE, /* no success */
@ -264,6 +266,8 @@ static gboolean target_drag_drop( GtkWidget *widget,
} }
else else
{ {
wxLogDebug( wxT( "Drop target: OnDrop returned TRUE") );
#if wxUSE_THREADS #if wxUSE_THREADS
/* disable GUI threads */ /* disable GUI threads */
wxapp_uninstall_thread_wakeup(); wxapp_uninstall_thread_wakeup();
@ -324,7 +328,7 @@ static void target_drag_data_received( GtkWidget *WXUNUSED(widget),
return; return;
} }
wxLogDebug( wxT( "Drop target: data received") ); wxLogDebug( wxT( "Drop target: data received event") );
/* inform the wxDropTarget about the current GtkSelectionData. /* inform the wxDropTarget about the current GtkSelectionData.
this is only valid for the duration of this call */ this is only valid for the duration of this call */
@ -332,11 +336,15 @@ static void target_drag_data_received( GtkWidget *WXUNUSED(widget),
if (drop_target->OnData( x, y )) if (drop_target->OnData( x, y ))
{ {
wxLogDebug( wxT( "Drop target: OnData returned TRUE") );
/* tell GTK that data transfer was successfull */ /* tell GTK that data transfer was successfull */
gtk_drag_finish( context, TRUE, FALSE, time ); gtk_drag_finish( context, TRUE, FALSE, time );
} }
else else
{ {
wxLogDebug( wxT( "Drop target: OnData returned FALSE") );
/* tell GTK that data transfer was not successfull */ /* tell GTK that data transfer was not successfull */
gtk_drag_finish( context, FALSE, FALSE, time ); gtk_drag_finish( context, FALSE, FALSE, time );
} }
@ -448,7 +456,9 @@ bool wxDropTarget::GetData()
return TRUE; return TRUE;
} }
return FALSE; m_dataObject->SetData( dragFormat, (size_t)m_dragData->length, (const void*)m_dragData->data );
return TRUE;
} }
void wxDropTarget::UnregisterWidget( GtkWidget *widget ) void wxDropTarget::UnregisterWidget( GtkWidget *widget )
@ -503,6 +513,41 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget )
GTK_SIGNAL_FUNC(target_drag_data_received), (gpointer) this ); GTK_SIGNAL_FUNC(target_drag_data_received), (gpointer) this );
} }
// ----------------------------------------------------------------------------
// wxTextDropTarget
// ----------------------------------------------------------------------------
wxTextDropTarget::wxTextDropTarget()
: wxDropTarget(new wxTextDataObject)
{
}
bool wxTextDropTarget::OnData(wxCoord x, wxCoord y)
{
if ( !GetData() )
return FALSE;
return OnDropText(x, y, ((wxTextDataObject *)m_dataObject)->GetText());
}
// ----------------------------------------------------------------------------
// wxFileDropTarget
// ----------------------------------------------------------------------------
wxFileDropTarget::wxFileDropTarget()
: wxDropTarget(new wxFileDataObject)
{
}
bool wxFileDropTarget::OnData(wxCoord x, wxCoord y)
{
if ( !GetData() )
return FALSE;
return OnDropFiles(x, y,
((wxFileDataObject *)m_dataObject)->GetFilenames());
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// "drag_data_get" // "drag_data_get"
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -517,33 +562,41 @@ source_drag_data_get (GtkWidget *WXUNUSED(widget),
{ {
if (g_isIdle) wxapp_install_idle_handler(); if (g_isIdle) wxapp_install_idle_handler();
#ifdef __WXDEBUG__ wxDataFormat format( selection_data->target );
char *name = gdk_atom_name( selection_data->target );
if (name) wxLogDebug( wxT("Drop source: format requested: %s"), name ); wxLogDebug( wxT("Drop source: format requested: %s"), format.GetId().c_str() );
#endif
drop_source->m_retValue = wxDragCancel; drop_source->m_retValue = wxDragCancel;
wxDataObject *data = drop_source->m_data; wxDataObject *data = drop_source->GetDataObject();
if (!data) if (!data)
{
wxLogDebug( wxT("Drop source: no data object") );
return; return;
}
if (!data->IsSupportedFormat(selection_data->target)) if (!data->IsSupportedFormat(format))
{
wxLogDebug( wxT("Drop source: unsupported format") );
return; return;
}
if (data->GetDataSize(selection_data->target) == 0) if (data->GetDataSize(format) == 0)
{
wxLogDebug( wxT("Drop source: empty data") );
return; return;
}
size_t size = data->GetDataSize(selection_data->target); size_t size = data->GetDataSize(format);
// printf( "data size: %d.\n", (int)data_size ); // printf( "data size: %d.\n", (int)data_size );
guchar *d = new guchar[size]; guchar *d = new guchar[size];
if (!data->GetDataHere( selection_data->target, (void*)d )) if (!data->GetDataHere( format, (void*)d ))
{ {
free( d ); delete[] d;
return; return;
} }
@ -563,7 +616,7 @@ source_drag_data_get (GtkWidget *WXUNUSED(widget),
wxapp_install_thread_wakeup(); wxapp_install_thread_wakeup();
#endif #endif
free( d ); delete[] d;
/* so far only copy, no moves. TODO. */ /* so far only copy, no moves. TODO. */
drop_source->m_retValue = wxDragCopy; drop_source->m_retValue = wxDragCopy;