Added wxPrivateDropTarget
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1402 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -138,11 +138,9 @@ class wxPrivateDataObject : public wxDataObject
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
wxPrivateDataObject()
|
wxPrivateDataObject();
|
||||||
{ m_size = 0; m_data = (char*) NULL; }
|
|
||||||
|
|
||||||
~wxPrivateDataObject()
|
~wxPrivateDataObject();
|
||||||
{ if (m_data) delete[] m_data; }
|
|
||||||
|
|
||||||
virtual wxDataFormat GetFormat() const
|
virtual wxDataFormat GetFormat() const
|
||||||
{ return wxDF_PRIVATE; }
|
{ return wxDF_PRIVATE; }
|
||||||
|
@@ -43,6 +43,7 @@ class wxWindow;
|
|||||||
class wxDropTarget;
|
class wxDropTarget;
|
||||||
class wxTextDropTarget;
|
class wxTextDropTarget;
|
||||||
class wxFileDropTarget;
|
class wxFileDropTarget;
|
||||||
|
class wxPrivateDropTarget;
|
||||||
|
|
||||||
class wxDropSource;
|
class wxDropSource;
|
||||||
|
|
||||||
@@ -90,6 +91,36 @@ class wxTextDropTarget: public wxDropTarget
|
|||||||
virtual wxDataFormat GetFormat(size_t n) const;
|
virtual wxDataFormat GetFormat(size_t n) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
// wxPrivateDropTarget
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class wxPrivateDropTarget: public wxDropTarget
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
wxPrivateDropTarget();
|
||||||
|
|
||||||
|
// you have to override OnDrop to get at the data
|
||||||
|
|
||||||
|
// 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 "WXWORD_FORMAT".
|
||||||
|
|
||||||
|
void SetId( const wxString& id )
|
||||||
|
{ m_id = id; }
|
||||||
|
|
||||||
|
wxString GetId()
|
||||||
|
{ return m_id; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
virtual size_t GetFormatCount() const;
|
||||||
|
virtual wxDataFormat GetFormat(size_t n) const;
|
||||||
|
|
||||||
|
wxString m_id;
|
||||||
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// A drop target which accepts files (dragged from File Manager or Explorer)
|
// A drop target which accepts files (dragged from File Manager or Explorer)
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -138,11 +138,9 @@ class wxPrivateDataObject : public wxDataObject
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
wxPrivateDataObject()
|
wxPrivateDataObject();
|
||||||
{ m_size = 0; m_data = (char*) NULL; }
|
|
||||||
|
|
||||||
~wxPrivateDataObject()
|
~wxPrivateDataObject();
|
||||||
{ if (m_data) delete[] m_data; }
|
|
||||||
|
|
||||||
virtual wxDataFormat GetFormat() const
|
virtual wxDataFormat GetFormat() const
|
||||||
{ return wxDF_PRIVATE; }
|
{ return wxDF_PRIVATE; }
|
||||||
|
@@ -43,6 +43,7 @@ class wxWindow;
|
|||||||
class wxDropTarget;
|
class wxDropTarget;
|
||||||
class wxTextDropTarget;
|
class wxTextDropTarget;
|
||||||
class wxFileDropTarget;
|
class wxFileDropTarget;
|
||||||
|
class wxPrivateDropTarget;
|
||||||
|
|
||||||
class wxDropSource;
|
class wxDropSource;
|
||||||
|
|
||||||
@@ -90,6 +91,36 @@ class wxTextDropTarget: public wxDropTarget
|
|||||||
virtual wxDataFormat GetFormat(size_t n) const;
|
virtual wxDataFormat GetFormat(size_t n) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
// wxPrivateDropTarget
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class wxPrivateDropTarget: public wxDropTarget
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
wxPrivateDropTarget();
|
||||||
|
|
||||||
|
// you have to override OnDrop to get at the data
|
||||||
|
|
||||||
|
// 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 "WXWORD_FORMAT".
|
||||||
|
|
||||||
|
void SetId( const wxString& id )
|
||||||
|
{ m_id = id; }
|
||||||
|
|
||||||
|
wxString GetId()
|
||||||
|
{ return m_id; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
virtual size_t GetFormatCount() const;
|
||||||
|
virtual wxDataFormat GetFormat(size_t n) const;
|
||||||
|
|
||||||
|
wxString m_id;
|
||||||
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// A drop target which accepts files (dragged from File Manager or Explorer)
|
// A drop target which accepts files (dragged from File Manager or Explorer)
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -32,12 +32,13 @@
|
|||||||
// Derive two simple classes which just put in the listbox the strings (text or
|
// Derive two simple classes which just put in the listbox the strings (text or
|
||||||
// file names) we drop on them
|
// file names) we drop on them
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
class DnDText : public wxTextDropTarget
|
class DnDText : public wxTextDropTarget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DnDText(wxListBox *pOwner) { m_pOwner = pOwner; }
|
DnDText(wxListBox *pOwner) { m_pOwner = pOwner; }
|
||||||
|
|
||||||
virtual bool OnDropText(long x, long y, const char *psz);
|
virtual bool OnDropText(long x, long y, const char *psz );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxListBox *m_pOwner;
|
wxListBox *m_pOwner;
|
||||||
@@ -49,7 +50,7 @@ public:
|
|||||||
DnDFile(wxListBox *pOwner) { m_pOwner = pOwner; }
|
DnDFile(wxListBox *pOwner) { m_pOwner = pOwner; }
|
||||||
|
|
||||||
virtual bool OnDropFiles(long x, long y,
|
virtual bool OnDropFiles(long x, long y,
|
||||||
size_t nFiles, const char * const aszFiles[]);
|
size_t nFiles, const char * const aszFiles[] );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxListBox *m_pOwner;
|
wxListBox *m_pOwner;
|
||||||
@@ -58,6 +59,7 @@ private:
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Define a new application type
|
// Define a new application type
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
class DnDApp : public wxApp
|
class DnDApp : public wxApp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -102,6 +104,7 @@ private:
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// IDs for the menu commands
|
// IDs for the menu commands
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
Menu_Quit = 1,
|
Menu_Quit = 1,
|
||||||
@@ -190,7 +193,7 @@ DnDFrame::DnDFrame(wxFrame *frame, char *title, int x, int y, int w, int h)
|
|||||||
|
|
||||||
// associate drop targets with 2 text controls
|
// associate drop targets with 2 text controls
|
||||||
m_ctrlFile->SetDropTarget(new DnDFile(m_ctrlFile));
|
m_ctrlFile->SetDropTarget(new DnDFile(m_ctrlFile));
|
||||||
m_ctrlText->SetDropTarget(new DnDText(m_ctrlText));
|
m_ctrlText->SetDropTarget( new DnDText(m_ctrlText) );
|
||||||
|
|
||||||
wxLayoutConstraints *c;
|
wxLayoutConstraints *c;
|
||||||
|
|
||||||
@@ -302,14 +305,16 @@ bool DnDFrame::OnClose()
|
|||||||
|
|
||||||
void DnDFrame::OnLeftDown(wxMouseEvent &WXUNUSED(event) )
|
void DnDFrame::OnLeftDown(wxMouseEvent &WXUNUSED(event) )
|
||||||
{
|
{
|
||||||
if ( !m_strText.IsEmpty() ) {
|
if ( !m_strText.IsEmpty() )
|
||||||
|
{
|
||||||
// start drag operation
|
// start drag operation
|
||||||
|
|
||||||
wxTextDataObject data(m_strText);
|
wxTextDataObject data(m_strText);
|
||||||
wxDropSource dragSource(data, this);
|
wxDropSource dragSource(data, this);
|
||||||
const char *pc;
|
const char *pc;
|
||||||
|
|
||||||
switch ( dragSource.DoDragDrop(TRUE) ) {
|
switch ( dragSource.DoDragDrop(TRUE) )
|
||||||
|
{
|
||||||
case wxDragError: pc = "Error!"; break;
|
case wxDragError: pc = "Error!"; break;
|
||||||
case wxDragNone: pc = "Nothing"; break;
|
case wxDragNone: pc = "Nothing"; break;
|
||||||
case wxDragCopy: pc = "Copied"; break;
|
case wxDragCopy: pc = "Copied"; break;
|
||||||
|
@@ -12,6 +12,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/dataobj.h"
|
#include "wx/dataobj.h"
|
||||||
|
#include "wx/app.h"
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
// wxDataObject
|
// wxDataObject
|
||||||
@@ -43,6 +44,18 @@ IMPLEMENT_DYNAMIC_CLASS( wxBitmapDataObject, wxDataObject )
|
|||||||
|
|
||||||
IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject, wxDataObject )
|
IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject, wxDataObject )
|
||||||
|
|
||||||
|
wxPrivateDataObject::wxPrivateDataObject()
|
||||||
|
{
|
||||||
|
m_size = 0;
|
||||||
|
m_data = (char*) NULL;
|
||||||
|
m_id = wxTheApp->GetAppName();
|
||||||
|
}
|
||||||
|
|
||||||
|
wxPrivateDataObject::~wxPrivateDataObject()
|
||||||
|
{
|
||||||
|
if (m_data) delete[] m_data;
|
||||||
|
}
|
||||||
|
|
||||||
void wxPrivateDataObject::SetData( const char *data, size_t size )
|
void wxPrivateDataObject::SetData( const char *data, size_t size )
|
||||||
{
|
{
|
||||||
m_size = size;
|
m_size = size;
|
||||||
|
278
src/gtk/dnd.cpp
278
src/gtk/dnd.cpp
@@ -102,10 +102,10 @@ static void target_drag_data_received( GtkWidget *WXUNUSED(widget),
|
|||||||
|
|
||||||
if ((data->length >= 0) && (data->format == 8))
|
if ((data->length >= 0) && (data->format == 8))
|
||||||
{
|
{
|
||||||
wxString str = (const char*)data->data;
|
wxString str = (const char*)data->data;
|
||||||
printf( "Received %s\n.", WXSTRINGCAST str );
|
printf( "Received %s\n.", WXSTRINGCAST str );
|
||||||
gtk_drag_finish( context, TRUE, FALSE, time );
|
gtk_drag_finish( context, TRUE, FALSE, time );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_drag_finish (context, FALSE, FALSE, time);
|
gtk_drag_finish (context, FALSE, FALSE, time);
|
||||||
@@ -153,6 +153,7 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget )
|
|||||||
GtkTargetEntry format;
|
GtkTargetEntry format;
|
||||||
format.info = 0;
|
format.info = 0;
|
||||||
format.flags = 0;
|
format.flags = 0;
|
||||||
|
char buf[100];
|
||||||
|
|
||||||
int valid = 0;
|
int valid = 0;
|
||||||
for ( size_t i = 0; i < GetFormatCount(); i++ )
|
for ( size_t i = 0; i < GetFormatCount(); i++ )
|
||||||
@@ -168,6 +169,12 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget )
|
|||||||
format.target = "file:ALL";
|
format.target = "file:ALL";
|
||||||
valid++;
|
valid++;
|
||||||
break;
|
break;
|
||||||
|
case wxDF_PRIVATE:
|
||||||
|
wxPrivateDropTarget *pdt = (wxPrivateDropTarget *)this;
|
||||||
|
strcpy( buf, "applications/" );
|
||||||
|
strcat( buf, WXSTRINGCAST pdt->GetID() );
|
||||||
|
format.target = buf;
|
||||||
|
valid++;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -478,9 +485,9 @@ static void gtk_target_callback( GtkWidget *widget,
|
|||||||
int x = 0;
|
int x = 0;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
gdk_window_get_pointer( widget->window, &x, &y, (GdkModifierType *) NULL );
|
gdk_window_get_pointer( widget->window, &x, &y, (GdkModifierType *) NULL );
|
||||||
|
/*
|
||||||
// printf( "Drop data is of type %s.\n", event->data_type );
|
printf( "Drop data is of type %s.\n", event->data_type );
|
||||||
|
*/
|
||||||
target->OnDrop( x, y, (const void*)event->data, (size_t)event->data_numbytes );
|
target->OnDrop( x, y, (const void*)event->data, (size_t)event->data_numbytes );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -523,22 +530,35 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget )
|
|||||||
switch (df)
|
switch (df)
|
||||||
{
|
{
|
||||||
case wxDF_TEXT:
|
case wxDF_TEXT:
|
||||||
if (i > 0) formats += ";";
|
{
|
||||||
formats += "text/plain";
|
if (i > 0) formats += ";";
|
||||||
valid++;
|
formats += "text/plain";
|
||||||
break;
|
valid++;
|
||||||
case wxDF_FILENAME:
|
break;
|
||||||
if (i > 0) formats += ";";
|
}
|
||||||
formats += "file:ALL";
|
case wxDF_FILENAME:
|
||||||
valid++;
|
{
|
||||||
break;
|
if (i > 0) formats += ";";
|
||||||
default:
|
formats += "file:ALL";
|
||||||
|
valid++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case wxDF_PRIVATE:
|
||||||
|
{
|
||||||
|
if (i > 0) formats += ";";
|
||||||
|
wxPrivateDropTarget *pdt = (wxPrivateDropTarget *)this;
|
||||||
|
formats += "applications/";
|
||||||
|
formats += pdt->GetId();
|
||||||
|
valid++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *str = WXSTRINGCAST formats;
|
char *str = WXSTRINGCAST formats;
|
||||||
|
|
||||||
gtk_widget_dnd_drop_set( widget, TRUE, &str, valid, FALSE );
|
gtk_widget_dnd_drop_set( widget, TRUE, &str, valid, FALSE );
|
||||||
|
|
||||||
gtk_signal_connect( GTK_OBJECT(widget), "drop_data_available_event",
|
gtk_signal_connect( GTK_OBJECT(widget), "drop_data_available_event",
|
||||||
@@ -557,8 +577,10 @@ bool wxTextDropTarget::OnDrop( long x, long y, const void *data, size_t WXUNUSED
|
|||||||
|
|
||||||
bool wxTextDropTarget::OnDropText( long x, long y, const char *psz )
|
bool wxTextDropTarget::OnDropText( long x, long y, const char *psz )
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
printf( "Got dropped text: %s.\n", psz );
|
printf( "Got dropped text: %s.\n", psz );
|
||||||
printf( "At x: %d, y: %d.\n", (int)x, (int)y );
|
printf( "At x: %d, y: %d.\n", (int)x, (int)y );
|
||||||
|
*/
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -572,6 +594,25 @@ wxDataFormat wxTextDropTarget::GetFormat(size_t WXUNUSED(n)) const
|
|||||||
return wxDF_TEXT;
|
return wxDF_TEXT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxPrivateDropTarget
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wxPrivateDropTarget::wxPrivateDropTarget()
|
||||||
|
{
|
||||||
|
m_id = wxTheApp->GetAppName();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t wxPrivateDropTarget::GetFormatCount() const
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxDataFormat wxPrivateDropTarget::GetFormat(size_t WXUNUSED(n)) const
|
||||||
|
{
|
||||||
|
return wxDF_PRIVATE;
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxFileDropTarget
|
// wxFileDropTarget
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -580,11 +621,13 @@ bool wxFileDropTarget::OnDropFiles( long x, long y, size_t nFiles, const char *
|
|||||||
{
|
{
|
||||||
printf( "Got %d dropped files.\n", (int)nFiles );
|
printf( "Got %d dropped files.\n", (int)nFiles );
|
||||||
printf( "At x: %d, y: %d.\n", (int)x, (int)y );
|
printf( "At x: %d, y: %d.\n", (int)x, (int)y );
|
||||||
|
|
||||||
for (size_t i = 0; i < nFiles; i++)
|
for (size_t i = 0; i < nFiles; i++)
|
||||||
{
|
{
|
||||||
printf( aszFiles[i] );
|
printf( aszFiles[i] );
|
||||||
printf( "\n" );
|
printf( "\n" );
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -641,6 +684,17 @@ void gtk_drag_callback( GtkWidget *widget, GdkEvent *event, wxDropSource *source
|
|||||||
|
|
||||||
switch (data->GetFormat())
|
switch (data->GetFormat())
|
||||||
{
|
{
|
||||||
|
case wxDF_PRIVATE:
|
||||||
|
{
|
||||||
|
wxPrivateDataObject *pdo = (wxPrivateDataObject*) data;
|
||||||
|
|
||||||
|
gtk_widget_dnd_data_set( widget,
|
||||||
|
event,
|
||||||
|
(unsigned char*) pdo->GetData(),
|
||||||
|
(int) pdo->GetDataSize() );
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
case wxDF_TEXT:
|
case wxDF_TEXT:
|
||||||
{
|
{
|
||||||
wxTextDataObject *text_object = (wxTextDataObject*) data;
|
wxTextDataObject *text_object = (wxTextDataObject*) data;
|
||||||
@@ -684,62 +738,62 @@ void gtk_drag_callback( GtkWidget *widget, GdkEvent *event, wxDropSource *source
|
|||||||
|
|
||||||
wxDropSource::wxDropSource( wxWindow *win )
|
wxDropSource::wxDropSource( wxWindow *win )
|
||||||
{
|
{
|
||||||
g_blockEventsOnDrag = TRUE;
|
g_blockEventsOnDrag = TRUE;
|
||||||
|
|
||||||
m_window = win;
|
m_window = win;
|
||||||
m_widget = win->m_widget;
|
m_widget = win->m_widget;
|
||||||
if (win->m_wxwindow) m_widget = win->m_wxwindow;
|
if (win->m_wxwindow) m_widget = win->m_wxwindow;
|
||||||
|
|
||||||
m_data = (wxDataObject *) NULL;
|
m_data = (wxDataObject *) NULL;
|
||||||
m_retValue = wxDragCancel;
|
m_retValue = wxDragCancel;
|
||||||
|
|
||||||
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
|
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
|
||||||
m_goaheadCursor = wxCursor( wxCURSOR_HAND );
|
m_goaheadCursor = wxCursor( wxCURSOR_HAND );
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDropSource::wxDropSource( wxDataObject &data, wxWindow *win )
|
wxDropSource::wxDropSource( wxDataObject &data, wxWindow *win )
|
||||||
{
|
{
|
||||||
g_blockEventsOnDrag = TRUE;
|
g_blockEventsOnDrag = TRUE;
|
||||||
|
|
||||||
m_window = win;
|
m_window = win;
|
||||||
m_widget = win->m_widget;
|
m_widget = win->m_widget;
|
||||||
if (win->m_wxwindow) m_widget = win->m_wxwindow;
|
if (win->m_wxwindow) m_widget = win->m_wxwindow;
|
||||||
m_retValue = wxDragCancel;
|
m_retValue = wxDragCancel;
|
||||||
|
|
||||||
m_data = &data;
|
m_data = &data;
|
||||||
|
|
||||||
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
|
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
|
||||||
m_goaheadCursor = wxCursor( wxCURSOR_HAND );
|
m_goaheadCursor = wxCursor( wxCURSOR_HAND );
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxDropSource::SetData( wxDataObject &data )
|
void wxDropSource::SetData( wxDataObject &data )
|
||||||
{
|
{
|
||||||
m_data = &data;
|
m_data = &data;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDropSource::~wxDropSource(void)
|
wxDropSource::~wxDropSource(void)
|
||||||
{
|
{
|
||||||
// if (m_data) delete m_data;
|
// if (m_data) delete m_data;
|
||||||
|
|
||||||
g_blockEventsOnDrag = FALSE;
|
g_blockEventsOnDrag = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
|
wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
|
||||||
{
|
{
|
||||||
if (gdk_dnd.dnd_grabbed) return (wxDragResult) wxDragNone;
|
if (gdk_dnd.dnd_grabbed) return (wxDragResult) wxDragNone;
|
||||||
if (gdk_dnd.drag_really) return (wxDragResult) wxDragNone;
|
if (gdk_dnd.drag_really) return (wxDragResult) wxDragNone;
|
||||||
|
|
||||||
wxASSERT_MSG( m_data, "wxDragSource: no data" );
|
wxASSERT_MSG( m_data, "wxDragSource: no data" );
|
||||||
|
|
||||||
if (!m_data) return (wxDragResult) wxDragNone;
|
if (!m_data) return (wxDragResult) wxDragNone;
|
||||||
|
|
||||||
static GtkWidget *drag_icon = (GtkWidget*) NULL;
|
static GtkWidget *drag_icon = (GtkWidget*) NULL;
|
||||||
static GtkWidget *drop_icon = (GtkWidget*) NULL;
|
static GtkWidget *drop_icon = (GtkWidget*) NULL;
|
||||||
|
|
||||||
GdkPoint hotspot_1 = {0,-5 };
|
GdkPoint hotspot_1 = {0,-5 };
|
||||||
|
|
||||||
if (!drag_icon)
|
if (!drag_icon)
|
||||||
{
|
{
|
||||||
drag_icon = shape_create_icon ( gv_xpm,
|
drag_icon = shape_create_icon ( gv_xpm,
|
||||||
440, 140, 0,0, GTK_WINDOW_POPUP);
|
440, 140, 0,0, GTK_WINDOW_POPUP);
|
||||||
|
|
||||||
@@ -748,12 +802,12 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
|
|||||||
&drag_icon);
|
&drag_icon);
|
||||||
|
|
||||||
gtk_widget_hide (drag_icon);
|
gtk_widget_hide (drag_icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
GdkPoint hotspot_2 = {-5,-5};
|
GdkPoint hotspot_2 = {-5,-5};
|
||||||
|
|
||||||
if (!drop_icon)
|
if (!drop_icon)
|
||||||
{
|
{
|
||||||
drop_icon = shape_create_icon ( page_xpm,
|
drop_icon = shape_create_icon ( page_xpm,
|
||||||
440, 140, 0,0, GTK_WINDOW_POPUP);
|
440, 140, 0,0, GTK_WINDOW_POPUP);
|
||||||
|
|
||||||
@@ -762,7 +816,7 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
|
|||||||
&drop_icon);
|
&drop_icon);
|
||||||
|
|
||||||
gtk_widget_hide (drop_icon);
|
gtk_widget_hide (drop_icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
gdk_dnd_set_drag_shape( drag_icon->window,
|
gdk_dnd_set_drag_shape( drag_icon->window,
|
||||||
@@ -771,101 +825,107 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
|
|||||||
&hotspot_2);
|
&hotspot_2);
|
||||||
|
|
||||||
|
|
||||||
GdkWindowPrivate *wp = (GdkWindowPrivate*) m_widget->window;
|
GdkWindowPrivate *wp = (GdkWindowPrivate*) m_widget->window;
|
||||||
|
|
||||||
RegisterWindow();
|
RegisterWindow();
|
||||||
|
|
||||||
gdk_dnd.drag_perhaps = TRUE;
|
gdk_dnd.drag_perhaps = TRUE;
|
||||||
|
|
||||||
gdk_dnd.dnd_drag_start.x = 5;
|
gdk_dnd.dnd_drag_start.x = 5;
|
||||||
gdk_dnd.dnd_drag_start.y = 5;
|
gdk_dnd.dnd_drag_start.y = 5;
|
||||||
gdk_dnd.real_sw = wp;
|
gdk_dnd.real_sw = wp;
|
||||||
|
|
||||||
if (gdk_dnd.drag_startwindows)
|
if (gdk_dnd.drag_startwindows)
|
||||||
{
|
{
|
||||||
g_free( gdk_dnd.drag_startwindows );
|
g_free( gdk_dnd.drag_startwindows );
|
||||||
gdk_dnd.drag_startwindows = (GdkWindow **) NULL;
|
gdk_dnd.drag_startwindows = (GdkWindow **) NULL;
|
||||||
}
|
}
|
||||||
gdk_dnd.drag_numwindows = gdk_dnd.drag_really = 0;
|
gdk_dnd.drag_numwindows = gdk_dnd.drag_really = 0;
|
||||||
|
|
||||||
XWindowAttributes dnd_winattr;
|
XWindowAttributes dnd_winattr;
|
||||||
XGetWindowAttributes( gdk_display, wp->xwindow, &dnd_winattr );
|
XGetWindowAttributes( gdk_display, wp->xwindow, &dnd_winattr );
|
||||||
wp->dnd_drag_savedeventmask = dnd_winattr.your_event_mask;
|
wp->dnd_drag_savedeventmask = dnd_winattr.your_event_mask;
|
||||||
|
|
||||||
gdk_dnd_drag_addwindow( m_widget->window );
|
gdk_dnd_drag_addwindow( m_widget->window );
|
||||||
|
|
||||||
GdkEventDragBegin ev;
|
GdkEventDragBegin ev;
|
||||||
ev.type = GDK_DRAG_BEGIN;
|
ev.type = GDK_DRAG_BEGIN;
|
||||||
ev.window = m_widget->window;
|
ev.window = m_widget->window;
|
||||||
ev.u.allflags = 0;
|
ev.u.allflags = 0;
|
||||||
ev.u.flags.protocol_version = DND_PROTOCOL_VERSION;
|
ev.u.flags.protocol_version = DND_PROTOCOL_VERSION;
|
||||||
|
|
||||||
gdk_event_put( (GdkEvent*)&ev );
|
gdk_event_put( (GdkEvent*)&ev );
|
||||||
|
|
||||||
XGrabPointer( gdk_display, wp->xwindow, False,
|
XGrabPointer( gdk_display, wp->xwindow, False,
|
||||||
ButtonMotionMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
|
ButtonMotionMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
|
||||||
GrabModeAsync, GrabModeAsync, gdk_root_window, None, CurrentTime );
|
GrabModeAsync, GrabModeAsync, gdk_root_window, None, CurrentTime );
|
||||||
|
|
||||||
gdk_dnd_set_drag_cursors( m_defaultCursor.GetCursor(), m_goaheadCursor.GetCursor() );
|
gdk_dnd_set_drag_cursors( m_defaultCursor.GetCursor(), m_goaheadCursor.GetCursor() );
|
||||||
|
|
||||||
gdk_dnd.dnd_grabbed = TRUE;
|
gdk_dnd.dnd_grabbed = TRUE;
|
||||||
gdk_dnd.drag_really = 1;
|
gdk_dnd.drag_really = 1;
|
||||||
|
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
wxGetMousePosition( &x, &y );
|
wxGetMousePosition( &x, &y );
|
||||||
|
|
||||||
gdk_dnd_display_drag_cursor( x, y, FALSE, TRUE );
|
gdk_dnd_display_drag_cursor( x, y, FALSE, TRUE );
|
||||||
|
|
||||||
/*
|
while (gdk_dnd.drag_really || gdk_dnd.drag_perhaps) wxYield();
|
||||||
shape_motion( drag_icon, (GdkEventMotion *)NULL );
|
|
||||||
shape_motion( drop_icon, (GdkEventMotion *)NULL );
|
|
||||||
*/
|
|
||||||
|
|
||||||
while (gdk_dnd.drag_really || gdk_dnd.drag_perhaps) wxYield();
|
|
||||||
|
|
||||||
UnregisterWindow();
|
UnregisterWindow();
|
||||||
|
|
||||||
g_blockEventsOnDrag = FALSE;
|
g_blockEventsOnDrag = FALSE;
|
||||||
|
|
||||||
return m_retValue;
|
return m_retValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxDropSource::RegisterWindow(void)
|
void wxDropSource::RegisterWindow(void)
|
||||||
{
|
{
|
||||||
if (!m_data) return;
|
if (!m_data) return;
|
||||||
|
|
||||||
wxString formats;
|
wxString formats;
|
||||||
|
|
||||||
wxDataFormat df = m_data->GetFormat();
|
wxDataFormat df = m_data->GetFormat();
|
||||||
|
|
||||||
switch (df)
|
switch (df)
|
||||||
{
|
{
|
||||||
case wxDF_TEXT:
|
case wxDF_TEXT:
|
||||||
formats += "text/plain";
|
{
|
||||||
break;
|
formats += "text/plain";
|
||||||
case wxDF_FILENAME:
|
break;
|
||||||
formats += "file:ALL";
|
}
|
||||||
break;
|
case wxDF_FILENAME:
|
||||||
default:
|
{
|
||||||
break;
|
formats += "file:ALL";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case wxDF_PRIVATE:
|
||||||
|
{
|
||||||
|
wxPrivateDataObject* pdo = (wxPrivateDataObject*) m_data;
|
||||||
|
formats += "applications/";
|
||||||
|
formats += pdo->GetId();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *str = WXSTRINGCAST formats;
|
char *str = WXSTRINGCAST formats;
|
||||||
|
|
||||||
gtk_widget_dnd_drag_set( m_widget, TRUE, &str, 1 );
|
gtk_widget_dnd_drag_set( m_widget, TRUE, &str, 1 );
|
||||||
|
|
||||||
gtk_signal_connect( GTK_OBJECT(m_widget), "drag_request_event",
|
gtk_signal_connect( GTK_OBJECT(m_widget), "drag_request_event",
|
||||||
GTK_SIGNAL_FUNC(gtk_drag_callback), (gpointer)this );
|
GTK_SIGNAL_FUNC(gtk_drag_callback), (gpointer)this );
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxDropSource::UnregisterWindow(void)
|
void wxDropSource::UnregisterWindow(void)
|
||||||
{
|
{
|
||||||
if (!m_widget) return;
|
if (!m_widget) return;
|
||||||
|
|
||||||
gtk_widget_dnd_drag_set( m_widget, FALSE, (gchar **) NULL, 0 );
|
gtk_widget_dnd_drag_set( m_widget, FALSE, (gchar **) NULL, 0 );
|
||||||
|
|
||||||
gtk_signal_disconnect_by_data( GTK_OBJECT(m_widget), (gpointer)this );
|
gtk_signal_disconnect_by_data( GTK_OBJECT(m_widget), (gpointer)this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -12,6 +12,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/dataobj.h"
|
#include "wx/dataobj.h"
|
||||||
|
#include "wx/app.h"
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
// wxDataObject
|
// wxDataObject
|
||||||
@@ -43,6 +44,18 @@ IMPLEMENT_DYNAMIC_CLASS( wxBitmapDataObject, wxDataObject )
|
|||||||
|
|
||||||
IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject, wxDataObject )
|
IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject, wxDataObject )
|
||||||
|
|
||||||
|
wxPrivateDataObject::wxPrivateDataObject()
|
||||||
|
{
|
||||||
|
m_size = 0;
|
||||||
|
m_data = (char*) NULL;
|
||||||
|
m_id = wxTheApp->GetAppName();
|
||||||
|
}
|
||||||
|
|
||||||
|
wxPrivateDataObject::~wxPrivateDataObject()
|
||||||
|
{
|
||||||
|
if (m_data) delete[] m_data;
|
||||||
|
}
|
||||||
|
|
||||||
void wxPrivateDataObject::SetData( const char *data, size_t size )
|
void wxPrivateDataObject::SetData( const char *data, size_t size )
|
||||||
{
|
{
|
||||||
m_size = size;
|
m_size = size;
|
||||||
|
278
src/gtk1/dnd.cpp
278
src/gtk1/dnd.cpp
@@ -102,10 +102,10 @@ static void target_drag_data_received( GtkWidget *WXUNUSED(widget),
|
|||||||
|
|
||||||
if ((data->length >= 0) && (data->format == 8))
|
if ((data->length >= 0) && (data->format == 8))
|
||||||
{
|
{
|
||||||
wxString str = (const char*)data->data;
|
wxString str = (const char*)data->data;
|
||||||
printf( "Received %s\n.", WXSTRINGCAST str );
|
printf( "Received %s\n.", WXSTRINGCAST str );
|
||||||
gtk_drag_finish( context, TRUE, FALSE, time );
|
gtk_drag_finish( context, TRUE, FALSE, time );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_drag_finish (context, FALSE, FALSE, time);
|
gtk_drag_finish (context, FALSE, FALSE, time);
|
||||||
@@ -153,6 +153,7 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget )
|
|||||||
GtkTargetEntry format;
|
GtkTargetEntry format;
|
||||||
format.info = 0;
|
format.info = 0;
|
||||||
format.flags = 0;
|
format.flags = 0;
|
||||||
|
char buf[100];
|
||||||
|
|
||||||
int valid = 0;
|
int valid = 0;
|
||||||
for ( size_t i = 0; i < GetFormatCount(); i++ )
|
for ( size_t i = 0; i < GetFormatCount(); i++ )
|
||||||
@@ -168,6 +169,12 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget )
|
|||||||
format.target = "file:ALL";
|
format.target = "file:ALL";
|
||||||
valid++;
|
valid++;
|
||||||
break;
|
break;
|
||||||
|
case wxDF_PRIVATE:
|
||||||
|
wxPrivateDropTarget *pdt = (wxPrivateDropTarget *)this;
|
||||||
|
strcpy( buf, "applications/" );
|
||||||
|
strcat( buf, WXSTRINGCAST pdt->GetID() );
|
||||||
|
format.target = buf;
|
||||||
|
valid++;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -478,9 +485,9 @@ static void gtk_target_callback( GtkWidget *widget,
|
|||||||
int x = 0;
|
int x = 0;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
gdk_window_get_pointer( widget->window, &x, &y, (GdkModifierType *) NULL );
|
gdk_window_get_pointer( widget->window, &x, &y, (GdkModifierType *) NULL );
|
||||||
|
/*
|
||||||
// printf( "Drop data is of type %s.\n", event->data_type );
|
printf( "Drop data is of type %s.\n", event->data_type );
|
||||||
|
*/
|
||||||
target->OnDrop( x, y, (const void*)event->data, (size_t)event->data_numbytes );
|
target->OnDrop( x, y, (const void*)event->data, (size_t)event->data_numbytes );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -523,22 +530,35 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget )
|
|||||||
switch (df)
|
switch (df)
|
||||||
{
|
{
|
||||||
case wxDF_TEXT:
|
case wxDF_TEXT:
|
||||||
if (i > 0) formats += ";";
|
{
|
||||||
formats += "text/plain";
|
if (i > 0) formats += ";";
|
||||||
valid++;
|
formats += "text/plain";
|
||||||
break;
|
valid++;
|
||||||
case wxDF_FILENAME:
|
break;
|
||||||
if (i > 0) formats += ";";
|
}
|
||||||
formats += "file:ALL";
|
case wxDF_FILENAME:
|
||||||
valid++;
|
{
|
||||||
break;
|
if (i > 0) formats += ";";
|
||||||
default:
|
formats += "file:ALL";
|
||||||
|
valid++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case wxDF_PRIVATE:
|
||||||
|
{
|
||||||
|
if (i > 0) formats += ";";
|
||||||
|
wxPrivateDropTarget *pdt = (wxPrivateDropTarget *)this;
|
||||||
|
formats += "applications/";
|
||||||
|
formats += pdt->GetId();
|
||||||
|
valid++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *str = WXSTRINGCAST formats;
|
char *str = WXSTRINGCAST formats;
|
||||||
|
|
||||||
gtk_widget_dnd_drop_set( widget, TRUE, &str, valid, FALSE );
|
gtk_widget_dnd_drop_set( widget, TRUE, &str, valid, FALSE );
|
||||||
|
|
||||||
gtk_signal_connect( GTK_OBJECT(widget), "drop_data_available_event",
|
gtk_signal_connect( GTK_OBJECT(widget), "drop_data_available_event",
|
||||||
@@ -557,8 +577,10 @@ bool wxTextDropTarget::OnDrop( long x, long y, const void *data, size_t WXUNUSED
|
|||||||
|
|
||||||
bool wxTextDropTarget::OnDropText( long x, long y, const char *psz )
|
bool wxTextDropTarget::OnDropText( long x, long y, const char *psz )
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
printf( "Got dropped text: %s.\n", psz );
|
printf( "Got dropped text: %s.\n", psz );
|
||||||
printf( "At x: %d, y: %d.\n", (int)x, (int)y );
|
printf( "At x: %d, y: %d.\n", (int)x, (int)y );
|
||||||
|
*/
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -572,6 +594,25 @@ wxDataFormat wxTextDropTarget::GetFormat(size_t WXUNUSED(n)) const
|
|||||||
return wxDF_TEXT;
|
return wxDF_TEXT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxPrivateDropTarget
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wxPrivateDropTarget::wxPrivateDropTarget()
|
||||||
|
{
|
||||||
|
m_id = wxTheApp->GetAppName();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t wxPrivateDropTarget::GetFormatCount() const
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxDataFormat wxPrivateDropTarget::GetFormat(size_t WXUNUSED(n)) const
|
||||||
|
{
|
||||||
|
return wxDF_PRIVATE;
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxFileDropTarget
|
// wxFileDropTarget
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -580,11 +621,13 @@ bool wxFileDropTarget::OnDropFiles( long x, long y, size_t nFiles, const char *
|
|||||||
{
|
{
|
||||||
printf( "Got %d dropped files.\n", (int)nFiles );
|
printf( "Got %d dropped files.\n", (int)nFiles );
|
||||||
printf( "At x: %d, y: %d.\n", (int)x, (int)y );
|
printf( "At x: %d, y: %d.\n", (int)x, (int)y );
|
||||||
|
|
||||||
for (size_t i = 0; i < nFiles; i++)
|
for (size_t i = 0; i < nFiles; i++)
|
||||||
{
|
{
|
||||||
printf( aszFiles[i] );
|
printf( aszFiles[i] );
|
||||||
printf( "\n" );
|
printf( "\n" );
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -641,6 +684,17 @@ void gtk_drag_callback( GtkWidget *widget, GdkEvent *event, wxDropSource *source
|
|||||||
|
|
||||||
switch (data->GetFormat())
|
switch (data->GetFormat())
|
||||||
{
|
{
|
||||||
|
case wxDF_PRIVATE:
|
||||||
|
{
|
||||||
|
wxPrivateDataObject *pdo = (wxPrivateDataObject*) data;
|
||||||
|
|
||||||
|
gtk_widget_dnd_data_set( widget,
|
||||||
|
event,
|
||||||
|
(unsigned char*) pdo->GetData(),
|
||||||
|
(int) pdo->GetDataSize() );
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
case wxDF_TEXT:
|
case wxDF_TEXT:
|
||||||
{
|
{
|
||||||
wxTextDataObject *text_object = (wxTextDataObject*) data;
|
wxTextDataObject *text_object = (wxTextDataObject*) data;
|
||||||
@@ -684,62 +738,62 @@ void gtk_drag_callback( GtkWidget *widget, GdkEvent *event, wxDropSource *source
|
|||||||
|
|
||||||
wxDropSource::wxDropSource( wxWindow *win )
|
wxDropSource::wxDropSource( wxWindow *win )
|
||||||
{
|
{
|
||||||
g_blockEventsOnDrag = TRUE;
|
g_blockEventsOnDrag = TRUE;
|
||||||
|
|
||||||
m_window = win;
|
m_window = win;
|
||||||
m_widget = win->m_widget;
|
m_widget = win->m_widget;
|
||||||
if (win->m_wxwindow) m_widget = win->m_wxwindow;
|
if (win->m_wxwindow) m_widget = win->m_wxwindow;
|
||||||
|
|
||||||
m_data = (wxDataObject *) NULL;
|
m_data = (wxDataObject *) NULL;
|
||||||
m_retValue = wxDragCancel;
|
m_retValue = wxDragCancel;
|
||||||
|
|
||||||
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
|
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
|
||||||
m_goaheadCursor = wxCursor( wxCURSOR_HAND );
|
m_goaheadCursor = wxCursor( wxCURSOR_HAND );
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDropSource::wxDropSource( wxDataObject &data, wxWindow *win )
|
wxDropSource::wxDropSource( wxDataObject &data, wxWindow *win )
|
||||||
{
|
{
|
||||||
g_blockEventsOnDrag = TRUE;
|
g_blockEventsOnDrag = TRUE;
|
||||||
|
|
||||||
m_window = win;
|
m_window = win;
|
||||||
m_widget = win->m_widget;
|
m_widget = win->m_widget;
|
||||||
if (win->m_wxwindow) m_widget = win->m_wxwindow;
|
if (win->m_wxwindow) m_widget = win->m_wxwindow;
|
||||||
m_retValue = wxDragCancel;
|
m_retValue = wxDragCancel;
|
||||||
|
|
||||||
m_data = &data;
|
m_data = &data;
|
||||||
|
|
||||||
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
|
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
|
||||||
m_goaheadCursor = wxCursor( wxCURSOR_HAND );
|
m_goaheadCursor = wxCursor( wxCURSOR_HAND );
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxDropSource::SetData( wxDataObject &data )
|
void wxDropSource::SetData( wxDataObject &data )
|
||||||
{
|
{
|
||||||
m_data = &data;
|
m_data = &data;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDropSource::~wxDropSource(void)
|
wxDropSource::~wxDropSource(void)
|
||||||
{
|
{
|
||||||
// if (m_data) delete m_data;
|
// if (m_data) delete m_data;
|
||||||
|
|
||||||
g_blockEventsOnDrag = FALSE;
|
g_blockEventsOnDrag = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
|
wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
|
||||||
{
|
{
|
||||||
if (gdk_dnd.dnd_grabbed) return (wxDragResult) wxDragNone;
|
if (gdk_dnd.dnd_grabbed) return (wxDragResult) wxDragNone;
|
||||||
if (gdk_dnd.drag_really) return (wxDragResult) wxDragNone;
|
if (gdk_dnd.drag_really) return (wxDragResult) wxDragNone;
|
||||||
|
|
||||||
wxASSERT_MSG( m_data, "wxDragSource: no data" );
|
wxASSERT_MSG( m_data, "wxDragSource: no data" );
|
||||||
|
|
||||||
if (!m_data) return (wxDragResult) wxDragNone;
|
if (!m_data) return (wxDragResult) wxDragNone;
|
||||||
|
|
||||||
static GtkWidget *drag_icon = (GtkWidget*) NULL;
|
static GtkWidget *drag_icon = (GtkWidget*) NULL;
|
||||||
static GtkWidget *drop_icon = (GtkWidget*) NULL;
|
static GtkWidget *drop_icon = (GtkWidget*) NULL;
|
||||||
|
|
||||||
GdkPoint hotspot_1 = {0,-5 };
|
GdkPoint hotspot_1 = {0,-5 };
|
||||||
|
|
||||||
if (!drag_icon)
|
if (!drag_icon)
|
||||||
{
|
{
|
||||||
drag_icon = shape_create_icon ( gv_xpm,
|
drag_icon = shape_create_icon ( gv_xpm,
|
||||||
440, 140, 0,0, GTK_WINDOW_POPUP);
|
440, 140, 0,0, GTK_WINDOW_POPUP);
|
||||||
|
|
||||||
@@ -748,12 +802,12 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
|
|||||||
&drag_icon);
|
&drag_icon);
|
||||||
|
|
||||||
gtk_widget_hide (drag_icon);
|
gtk_widget_hide (drag_icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
GdkPoint hotspot_2 = {-5,-5};
|
GdkPoint hotspot_2 = {-5,-5};
|
||||||
|
|
||||||
if (!drop_icon)
|
if (!drop_icon)
|
||||||
{
|
{
|
||||||
drop_icon = shape_create_icon ( page_xpm,
|
drop_icon = shape_create_icon ( page_xpm,
|
||||||
440, 140, 0,0, GTK_WINDOW_POPUP);
|
440, 140, 0,0, GTK_WINDOW_POPUP);
|
||||||
|
|
||||||
@@ -762,7 +816,7 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
|
|||||||
&drop_icon);
|
&drop_icon);
|
||||||
|
|
||||||
gtk_widget_hide (drop_icon);
|
gtk_widget_hide (drop_icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
gdk_dnd_set_drag_shape( drag_icon->window,
|
gdk_dnd_set_drag_shape( drag_icon->window,
|
||||||
@@ -771,101 +825,107 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
|
|||||||
&hotspot_2);
|
&hotspot_2);
|
||||||
|
|
||||||
|
|
||||||
GdkWindowPrivate *wp = (GdkWindowPrivate*) m_widget->window;
|
GdkWindowPrivate *wp = (GdkWindowPrivate*) m_widget->window;
|
||||||
|
|
||||||
RegisterWindow();
|
RegisterWindow();
|
||||||
|
|
||||||
gdk_dnd.drag_perhaps = TRUE;
|
gdk_dnd.drag_perhaps = TRUE;
|
||||||
|
|
||||||
gdk_dnd.dnd_drag_start.x = 5;
|
gdk_dnd.dnd_drag_start.x = 5;
|
||||||
gdk_dnd.dnd_drag_start.y = 5;
|
gdk_dnd.dnd_drag_start.y = 5;
|
||||||
gdk_dnd.real_sw = wp;
|
gdk_dnd.real_sw = wp;
|
||||||
|
|
||||||
if (gdk_dnd.drag_startwindows)
|
if (gdk_dnd.drag_startwindows)
|
||||||
{
|
{
|
||||||
g_free( gdk_dnd.drag_startwindows );
|
g_free( gdk_dnd.drag_startwindows );
|
||||||
gdk_dnd.drag_startwindows = (GdkWindow **) NULL;
|
gdk_dnd.drag_startwindows = (GdkWindow **) NULL;
|
||||||
}
|
}
|
||||||
gdk_dnd.drag_numwindows = gdk_dnd.drag_really = 0;
|
gdk_dnd.drag_numwindows = gdk_dnd.drag_really = 0;
|
||||||
|
|
||||||
XWindowAttributes dnd_winattr;
|
XWindowAttributes dnd_winattr;
|
||||||
XGetWindowAttributes( gdk_display, wp->xwindow, &dnd_winattr );
|
XGetWindowAttributes( gdk_display, wp->xwindow, &dnd_winattr );
|
||||||
wp->dnd_drag_savedeventmask = dnd_winattr.your_event_mask;
|
wp->dnd_drag_savedeventmask = dnd_winattr.your_event_mask;
|
||||||
|
|
||||||
gdk_dnd_drag_addwindow( m_widget->window );
|
gdk_dnd_drag_addwindow( m_widget->window );
|
||||||
|
|
||||||
GdkEventDragBegin ev;
|
GdkEventDragBegin ev;
|
||||||
ev.type = GDK_DRAG_BEGIN;
|
ev.type = GDK_DRAG_BEGIN;
|
||||||
ev.window = m_widget->window;
|
ev.window = m_widget->window;
|
||||||
ev.u.allflags = 0;
|
ev.u.allflags = 0;
|
||||||
ev.u.flags.protocol_version = DND_PROTOCOL_VERSION;
|
ev.u.flags.protocol_version = DND_PROTOCOL_VERSION;
|
||||||
|
|
||||||
gdk_event_put( (GdkEvent*)&ev );
|
gdk_event_put( (GdkEvent*)&ev );
|
||||||
|
|
||||||
XGrabPointer( gdk_display, wp->xwindow, False,
|
XGrabPointer( gdk_display, wp->xwindow, False,
|
||||||
ButtonMotionMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
|
ButtonMotionMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
|
||||||
GrabModeAsync, GrabModeAsync, gdk_root_window, None, CurrentTime );
|
GrabModeAsync, GrabModeAsync, gdk_root_window, None, CurrentTime );
|
||||||
|
|
||||||
gdk_dnd_set_drag_cursors( m_defaultCursor.GetCursor(), m_goaheadCursor.GetCursor() );
|
gdk_dnd_set_drag_cursors( m_defaultCursor.GetCursor(), m_goaheadCursor.GetCursor() );
|
||||||
|
|
||||||
gdk_dnd.dnd_grabbed = TRUE;
|
gdk_dnd.dnd_grabbed = TRUE;
|
||||||
gdk_dnd.drag_really = 1;
|
gdk_dnd.drag_really = 1;
|
||||||
|
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
wxGetMousePosition( &x, &y );
|
wxGetMousePosition( &x, &y );
|
||||||
|
|
||||||
gdk_dnd_display_drag_cursor( x, y, FALSE, TRUE );
|
gdk_dnd_display_drag_cursor( x, y, FALSE, TRUE );
|
||||||
|
|
||||||
/*
|
while (gdk_dnd.drag_really || gdk_dnd.drag_perhaps) wxYield();
|
||||||
shape_motion( drag_icon, (GdkEventMotion *)NULL );
|
|
||||||
shape_motion( drop_icon, (GdkEventMotion *)NULL );
|
|
||||||
*/
|
|
||||||
|
|
||||||
while (gdk_dnd.drag_really || gdk_dnd.drag_perhaps) wxYield();
|
|
||||||
|
|
||||||
UnregisterWindow();
|
UnregisterWindow();
|
||||||
|
|
||||||
g_blockEventsOnDrag = FALSE;
|
g_blockEventsOnDrag = FALSE;
|
||||||
|
|
||||||
return m_retValue;
|
return m_retValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxDropSource::RegisterWindow(void)
|
void wxDropSource::RegisterWindow(void)
|
||||||
{
|
{
|
||||||
if (!m_data) return;
|
if (!m_data) return;
|
||||||
|
|
||||||
wxString formats;
|
wxString formats;
|
||||||
|
|
||||||
wxDataFormat df = m_data->GetFormat();
|
wxDataFormat df = m_data->GetFormat();
|
||||||
|
|
||||||
switch (df)
|
switch (df)
|
||||||
{
|
{
|
||||||
case wxDF_TEXT:
|
case wxDF_TEXT:
|
||||||
formats += "text/plain";
|
{
|
||||||
break;
|
formats += "text/plain";
|
||||||
case wxDF_FILENAME:
|
break;
|
||||||
formats += "file:ALL";
|
}
|
||||||
break;
|
case wxDF_FILENAME:
|
||||||
default:
|
{
|
||||||
break;
|
formats += "file:ALL";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case wxDF_PRIVATE:
|
||||||
|
{
|
||||||
|
wxPrivateDataObject* pdo = (wxPrivateDataObject*) m_data;
|
||||||
|
formats += "applications/";
|
||||||
|
formats += pdo->GetId();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *str = WXSTRINGCAST formats;
|
char *str = WXSTRINGCAST formats;
|
||||||
|
|
||||||
gtk_widget_dnd_drag_set( m_widget, TRUE, &str, 1 );
|
gtk_widget_dnd_drag_set( m_widget, TRUE, &str, 1 );
|
||||||
|
|
||||||
gtk_signal_connect( GTK_OBJECT(m_widget), "drag_request_event",
|
gtk_signal_connect( GTK_OBJECT(m_widget), "drag_request_event",
|
||||||
GTK_SIGNAL_FUNC(gtk_drag_callback), (gpointer)this );
|
GTK_SIGNAL_FUNC(gtk_drag_callback), (gpointer)this );
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxDropSource::UnregisterWindow(void)
|
void wxDropSource::UnregisterWindow(void)
|
||||||
{
|
{
|
||||||
if (!m_widget) return;
|
if (!m_widget) return;
|
||||||
|
|
||||||
gtk_widget_dnd_drag_set( m_widget, FALSE, (gchar **) NULL, 0 );
|
gtk_widget_dnd_drag_set( m_widget, FALSE, (gchar **) NULL, 0 );
|
||||||
|
|
||||||
gtk_signal_disconnect_by_data( GTK_OBJECT(m_widget), (gpointer)this );
|
gtk_signal_disconnect_by_data( GTK_OBJECT(m_widget), (gpointer)this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user