// 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
};
// ----------------------------------------------------------------------------
// set the data which is transfered by drag and drop
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
//
class wxDropTarget;
class wxTextDropTarget;
class wxFileDropTarget;
-class wxPrivateDropTarget;
class wxDropSource;
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
//-------------------------------------------------------------------------
GtkWidget *m_widget;
wxWindow *m_window;
wxDragResult m_retValue;
- wxDataObject *m_data;
wxCursor m_defaultCursor;
wxCursor m_goaheadCursor;
class wxDropTarget;
class wxTextDropTarget;
class wxFileDropTarget;
-class wxPrivateDropTarget;
class wxDropSource;
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
//-------------------------------------------------------------------------
GtkWidget *m_widget;
wxWindow *m_window;
wxDragResult m_retValue;
- wxDataObject *m_data;
wxCursor m_defaultCursor;
wxCursor m_goaheadCursor;
* Use Apple Ieee-double converter
*/
#define wxUSE_APPLE_IEEE 0
-
+/*
+ * Compatibility with 2.0 API.
+ */
+#define WXWIN_COMPATIBILITY_2 1
/*
* Enables debugging: memory tracing, assert, etc., contains debug level
*/
#endif
#include "wx/thread.h"
-#include "wx/clipbrd.h"
-
-// ===========================================================================
-// implementation
-// ===========================================================================
-
-// ----------------------------------------------------------------------------
-// some global data defined here
-// ----------------------------------------------------------------------------
-
-IMPLEMENT_DYNAMIC_CLASS(wxClipboardModule, wxModule)
// ---------------------------------------------------------------------------
// wxAppBase
// 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:
+ wxClipboardModule() { }
+
bool OnInit()
{ wxTheClipboard = new wxClipboard; return TRUE; }
void OnExit()
DECLARE_DYNAMIC_CLASS(wxClipboardModule)
};
+IMPLEMENT_DYNAMIC_CLASS(wxClipboardModule,wxModule)
+
if (!ret)
{
+ wxLogDebug( wxT( "Drop target: OnDrop returned TRUE") );
+
/* cancel the whole thing */
gtk_drag_finish( context,
FALSE, /* no success */
}
else
{
+ wxLogDebug( wxT( "Drop target: OnDrop returned TRUE") );
+
#if wxUSE_THREADS
/* disable GUI threads */
wxapp_uninstall_thread_wakeup();
return;
}
- wxLogDebug( wxT( "Drop target: data received") );
+ wxLogDebug( wxT( "Drop target: data received event") );
/* inform the wxDropTarget about the current GtkSelectionData.
this is only valid for the duration of this call */
if (drop_target->OnData( x, y ))
{
+ wxLogDebug( wxT( "Drop target: OnData returned TRUE") );
+
/* tell GTK that data transfer was successfull */
gtk_drag_finish( context, TRUE, FALSE, time );
}
else
{
+ wxLogDebug( wxT( "Drop target: OnData returned FALSE") );
+
/* tell GTK that data transfer was not successfull */
gtk_drag_finish( context, FALSE, FALSE, time );
}
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 )
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"
//----------------------------------------------------------------------------
{
if (g_isIdle) wxapp_install_idle_handler();
-#ifdef __WXDEBUG__
- char *name = gdk_atom_name( selection_data->target );
- if (name) wxLogDebug( wxT("Drop source: format requested: %s"), name );
-#endif
+ wxDataFormat format( selection_data->target );
+
+ wxLogDebug( wxT("Drop source: format requested: %s"), format.GetId().c_str() );
drop_source->m_retValue = wxDragCancel;
- wxDataObject *data = drop_source->m_data;
+ wxDataObject *data = drop_source->GetDataObject();
if (!data)
+ {
+ wxLogDebug( wxT("Drop source: no data object") );
return;
+ }
- if (!data->IsSupportedFormat(selection_data->target))
+ if (!data->IsSupportedFormat(format))
+ {
+ wxLogDebug( wxT("Drop source: unsupported format") );
return;
+ }
- if (data->GetDataSize(selection_data->target) == 0)
+ if (data->GetDataSize(format) == 0)
+ {
+ wxLogDebug( wxT("Drop source: empty data") );
return;
+ }
- size_t size = data->GetDataSize(selection_data->target);
+ size_t size = data->GetDataSize(format);
// printf( "data size: %d.\n", (int)data_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;
}
wxapp_install_thread_wakeup();
#endif
- free( d );
+ delete[] d;
/* so far only copy, no moves. TODO. */
drop_source->m_retValue = wxDragCopy;
if (!ret)
{
+ wxLogDebug( wxT( "Drop target: OnDrop returned TRUE") );
+
/* cancel the whole thing */
gtk_drag_finish( context,
FALSE, /* no success */
}
else
{
+ wxLogDebug( wxT( "Drop target: OnDrop returned TRUE") );
+
#if wxUSE_THREADS
/* disable GUI threads */
wxapp_uninstall_thread_wakeup();
return;
}
- wxLogDebug( wxT( "Drop target: data received") );
+ wxLogDebug( wxT( "Drop target: data received event") );
/* inform the wxDropTarget about the current GtkSelectionData.
this is only valid for the duration of this call */
if (drop_target->OnData( x, y ))
{
+ wxLogDebug( wxT( "Drop target: OnData returned TRUE") );
+
/* tell GTK that data transfer was successfull */
gtk_drag_finish( context, TRUE, FALSE, time );
}
else
{
+ wxLogDebug( wxT( "Drop target: OnData returned FALSE") );
+
/* tell GTK that data transfer was not successfull */
gtk_drag_finish( context, FALSE, FALSE, time );
}
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 )
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"
//----------------------------------------------------------------------------
{
if (g_isIdle) wxapp_install_idle_handler();
-#ifdef __WXDEBUG__
- char *name = gdk_atom_name( selection_data->target );
- if (name) wxLogDebug( wxT("Drop source: format requested: %s"), name );
-#endif
+ wxDataFormat format( selection_data->target );
+
+ wxLogDebug( wxT("Drop source: format requested: %s"), format.GetId().c_str() );
drop_source->m_retValue = wxDragCancel;
- wxDataObject *data = drop_source->m_data;
+ wxDataObject *data = drop_source->GetDataObject();
if (!data)
+ {
+ wxLogDebug( wxT("Drop source: no data object") );
return;
+ }
- if (!data->IsSupportedFormat(selection_data->target))
+ if (!data->IsSupportedFormat(format))
+ {
+ wxLogDebug( wxT("Drop source: unsupported format") );
return;
+ }
- if (data->GetDataSize(selection_data->target) == 0)
+ if (data->GetDataSize(format) == 0)
+ {
+ wxLogDebug( wxT("Drop source: empty data") );
return;
+ }
- size_t size = data->GetDataSize(selection_data->target);
+ size_t size = data->GetDataSize(format);
// printf( "data size: %d.\n", (int)data_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;
}
wxapp_install_thread_wakeup();
#endif
- free( d );
+ delete[] d;
/* so far only copy, no moves. TODO. */
drop_source->m_retValue = wxDragCopy;