Added wxPrivateDropTarget

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1402 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
1999-01-14 00:24:03 +00:00
parent bba6f3bd3c
commit ab8884aca6
9 changed files with 440 additions and 231 deletions

View File

@@ -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; }

View File

@@ -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)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -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; }

View File

@@ -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)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -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;

View File

@@ -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;

View File

@@ -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,15 +530,28 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget )
switch (df) switch (df)
{ {
case wxDF_TEXT: case wxDF_TEXT:
{
if (i > 0) formats += ";"; if (i > 0) formats += ";";
formats += "text/plain"; formats += "text/plain";
valid++; valid++;
break; break;
}
case wxDF_FILENAME: case wxDF_FILENAME:
{
if (i > 0) formats += ";"; if (i > 0) formats += ";";
formats += "file:ALL"; formats += "file:ALL";
valid++; valid++;
break; break;
}
case wxDF_PRIVATE:
{
if (i > 0) formats += ";";
wxPrivateDropTarget *pdt = (wxPrivateDropTarget *)this;
formats += "applications/";
formats += pdt->GetId();
valid++;
break;
}
default: default:
break; break;
} }
@@ -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;
@@ -817,11 +871,6 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
gdk_dnd_display_drag_cursor( x, y, FALSE, TRUE ); gdk_dnd_display_drag_cursor( x, y, FALSE, TRUE );
/*
shape_motion( drag_icon, (GdkEventMotion *)NULL );
shape_motion( drop_icon, (GdkEventMotion *)NULL );
*/
while (gdk_dnd.drag_really || gdk_dnd.drag_perhaps) wxYield(); while (gdk_dnd.drag_really || gdk_dnd.drag_perhaps) wxYield();
UnregisterWindow(); UnregisterWindow();
@@ -842,11 +891,22 @@ void wxDropSource::RegisterWindow(void)
switch (df) switch (df)
{ {
case wxDF_TEXT: case wxDF_TEXT:
{
formats += "text/plain"; formats += "text/plain";
break; break;
}
case wxDF_FILENAME: case wxDF_FILENAME:
{
formats += "file:ALL"; formats += "file:ALL";
break; break;
}
case wxDF_PRIVATE:
{
wxPrivateDataObject* pdo = (wxPrivateDataObject*) m_data;
formats += "applications/";
formats += pdo->GetId();
break;
}
default: default:
break; break;
} }

View File

@@ -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;

View File

@@ -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,15 +530,28 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget )
switch (df) switch (df)
{ {
case wxDF_TEXT: case wxDF_TEXT:
{
if (i > 0) formats += ";"; if (i > 0) formats += ";";
formats += "text/plain"; formats += "text/plain";
valid++; valid++;
break; break;
}
case wxDF_FILENAME: case wxDF_FILENAME:
{
if (i > 0) formats += ";"; if (i > 0) formats += ";";
formats += "file:ALL"; formats += "file:ALL";
valid++; valid++;
break; break;
}
case wxDF_PRIVATE:
{
if (i > 0) formats += ";";
wxPrivateDropTarget *pdt = (wxPrivateDropTarget *)this;
formats += "applications/";
formats += pdt->GetId();
valid++;
break;
}
default: default:
break; break;
} }
@@ -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;
@@ -817,11 +871,6 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
gdk_dnd_display_drag_cursor( x, y, FALSE, TRUE ); gdk_dnd_display_drag_cursor( x, y, FALSE, TRUE );
/*
shape_motion( drag_icon, (GdkEventMotion *)NULL );
shape_motion( drop_icon, (GdkEventMotion *)NULL );
*/
while (gdk_dnd.drag_really || gdk_dnd.drag_perhaps) wxYield(); while (gdk_dnd.drag_really || gdk_dnd.drag_perhaps) wxYield();
UnregisterWindow(); UnregisterWindow();
@@ -842,11 +891,22 @@ void wxDropSource::RegisterWindow(void)
switch (df) switch (df)
{ {
case wxDF_TEXT: case wxDF_TEXT:
{
formats += "text/plain"; formats += "text/plain";
break; break;
}
case wxDF_FILENAME: case wxDF_FILENAME:
{
formats += "file:ALL"; formats += "file:ALL";
break; break;
}
case wxDF_PRIVATE:
{
wxPrivateDataObject* pdo = (wxPrivateDataObject*) m_data;
formats += "applications/";
formats += pdo->GetId();
break;
}
default: default:
break; break;
} }