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:
wxPrivateDataObject()
{ m_size = 0; m_data = (char*) NULL; }
wxPrivateDataObject();
~wxPrivateDataObject()
{ if (m_data) delete[] m_data; }
~wxPrivateDataObject();
virtual wxDataFormat GetFormat() const
{ return wxDF_PRIVATE; }

View File

@ -43,6 +43,7 @@ class wxWindow;
class wxDropTarget;
class wxTextDropTarget;
class wxFileDropTarget;
class wxPrivateDropTarget;
class wxDropSource;
@ -90,6 +91,36 @@ class wxTextDropTarget: public wxDropTarget
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)
// ----------------------------------------------------------------------------

View File

@ -138,11 +138,9 @@ class wxPrivateDataObject : public wxDataObject
public:
wxPrivateDataObject()
{ m_size = 0; m_data = (char*) NULL; }
wxPrivateDataObject();
~wxPrivateDataObject()
{ if (m_data) delete[] m_data; }
~wxPrivateDataObject();
virtual wxDataFormat GetFormat() const
{ return wxDF_PRIVATE; }

View File

@ -43,6 +43,7 @@ class wxWindow;
class wxDropTarget;
class wxTextDropTarget;
class wxFileDropTarget;
class wxPrivateDropTarget;
class wxDropSource;
@ -90,6 +91,36 @@ class wxTextDropTarget: public wxDropTarget
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)
// ----------------------------------------------------------------------------

View File

@ -32,6 +32,7 @@
// Derive two simple classes which just put in the listbox the strings (text or
// file names) we drop on them
// ----------------------------------------------------------------------------
class DnDText : public wxTextDropTarget
{
public:
@ -58,6 +59,7 @@ private:
// ----------------------------------------------------------------------------
// Define a new application type
// ----------------------------------------------------------------------------
class DnDApp : public wxApp
{
public:
@ -102,6 +104,7 @@ private:
// ----------------------------------------------------------------------------
// IDs for the menu commands
// ----------------------------------------------------------------------------
enum
{
Menu_Quit = 1,
@ -302,14 +305,16 @@ bool DnDFrame::OnClose()
void DnDFrame::OnLeftDown(wxMouseEvent &WXUNUSED(event) )
{
if ( !m_strText.IsEmpty() ) {
if ( !m_strText.IsEmpty() )
{
// start drag operation
wxTextDataObject data(m_strText);
wxDropSource dragSource(data, this);
const char *pc;
switch ( dragSource.DoDragDrop(TRUE) ) {
switch ( dragSource.DoDragDrop(TRUE) )
{
case wxDragError: pc = "Error!"; break;
case wxDragNone: pc = "Nothing"; break;
case wxDragCopy: pc = "Copied"; break;

View File

@ -12,6 +12,7 @@
#endif
#include "wx/dataobj.h"
#include "wx/app.h"
//-------------------------------------------------------------------------
// wxDataObject
@ -43,6 +44,18 @@ IMPLEMENT_DYNAMIC_CLASS( wxBitmapDataObject, 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 )
{
m_size = size;

View File

@ -153,6 +153,7 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget )
GtkTargetEntry format;
format.info = 0;
format.flags = 0;
char buf[100];
int valid = 0;
for ( size_t i = 0; i < GetFormatCount(); i++ )
@ -168,6 +169,12 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget )
format.target = "file:ALL";
valid++;
break;
case wxDF_PRIVATE:
wxPrivateDropTarget *pdt = (wxPrivateDropTarget *)this;
strcpy( buf, "applications/" );
strcat( buf, WXSTRINGCAST pdt->GetID() );
format.target = buf;
valid++;
default:
break;
}
@ -478,9 +485,9 @@ static void gtk_target_callback( GtkWidget *widget,
int x = 0;
int y = 0;
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 );
}
@ -523,15 +530,28 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget )
switch (df)
{
case wxDF_TEXT:
{
if (i > 0) formats += ";";
formats += "text/plain";
valid++;
break;
}
case wxDF_FILENAME:
{
if (i > 0) formats += ";";
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;
}
@ -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 )
{
/*
printf( "Got dropped text: %s.\n", psz );
printf( "At x: %d, y: %d.\n", (int)x, (int)y );
*/
return TRUE;
}
@ -572,6 +594,25 @@ wxDataFormat wxTextDropTarget::GetFormat(size_t WXUNUSED(n)) const
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
// ----------------------------------------------------------------------------
@ -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( "At x: %d, y: %d.\n", (int)x, (int)y );
for (size_t i = 0; i < nFiles; i++)
{
printf( aszFiles[i] );
printf( "\n" );
}
return TRUE;
}
@ -641,6 +684,17 @@ void gtk_drag_callback( GtkWidget *widget, GdkEvent *event, wxDropSource *source
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:
{
wxTextDataObject *text_object = (wxTextDataObject*) data;
@ -817,11 +871,6 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
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();
UnregisterWindow();
@ -842,11 +891,22 @@ void wxDropSource::RegisterWindow(void)
switch (df)
{
case wxDF_TEXT:
{
formats += "text/plain";
break;
}
case wxDF_FILENAME:
{
formats += "file:ALL";
break;
}
case wxDF_PRIVATE:
{
wxPrivateDataObject* pdo = (wxPrivateDataObject*) m_data;
formats += "applications/";
formats += pdo->GetId();
break;
}
default:
break;
}

View File

@ -12,6 +12,7 @@
#endif
#include "wx/dataobj.h"
#include "wx/app.h"
//-------------------------------------------------------------------------
// wxDataObject
@ -43,6 +44,18 @@ IMPLEMENT_DYNAMIC_CLASS( wxBitmapDataObject, 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 )
{
m_size = size;

View File

@ -153,6 +153,7 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget )
GtkTargetEntry format;
format.info = 0;
format.flags = 0;
char buf[100];
int valid = 0;
for ( size_t i = 0; i < GetFormatCount(); i++ )
@ -168,6 +169,12 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget )
format.target = "file:ALL";
valid++;
break;
case wxDF_PRIVATE:
wxPrivateDropTarget *pdt = (wxPrivateDropTarget *)this;
strcpy( buf, "applications/" );
strcat( buf, WXSTRINGCAST pdt->GetID() );
format.target = buf;
valid++;
default:
break;
}
@ -478,9 +485,9 @@ static void gtk_target_callback( GtkWidget *widget,
int x = 0;
int y = 0;
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 );
}
@ -523,15 +530,28 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget )
switch (df)
{
case wxDF_TEXT:
{
if (i > 0) formats += ";";
formats += "text/plain";
valid++;
break;
}
case wxDF_FILENAME:
{
if (i > 0) formats += ";";
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;
}
@ -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 )
{
/*
printf( "Got dropped text: %s.\n", psz );
printf( "At x: %d, y: %d.\n", (int)x, (int)y );
*/
return TRUE;
}
@ -572,6 +594,25 @@ wxDataFormat wxTextDropTarget::GetFormat(size_t WXUNUSED(n)) const
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
// ----------------------------------------------------------------------------
@ -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( "At x: %d, y: %d.\n", (int)x, (int)y );
for (size_t i = 0; i < nFiles; i++)
{
printf( aszFiles[i] );
printf( "\n" );
}
return TRUE;
}
@ -641,6 +684,17 @@ void gtk_drag_callback( GtkWidget *widget, GdkEvent *event, wxDropSource *source
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:
{
wxTextDataObject *text_object = (wxTextDataObject*) data;
@ -817,11 +871,6 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
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();
UnregisterWindow();
@ -842,11 +891,22 @@ void wxDropSource::RegisterWindow(void)
switch (df)
{
case wxDF_TEXT:
{
formats += "text/plain";
break;
}
case wxDF_FILENAME:
{
formats += "file:ALL";
break;
}
case wxDF_PRIVATE:
{
wxPrivateDataObject* pdo = (wxPrivateDataObject*) m_data;
formats += "applications/";
formats += pdo->GetId();
break;
}
default:
break;
}