Changed clipboard text format id from "STRING" to "TEXT"

DnD might now actually compile (but nothing else)


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2055 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
1999-04-06 17:24:14 +00:00
parent ca8b28f2ef
commit d6086ea663
9 changed files with 657 additions and 555 deletions

View File

@@ -17,14 +17,6 @@
#include "wx/defs.h" #include "wx/defs.h"
//-------------------------------------------------------------------------
// conditional compilation
//-------------------------------------------------------------------------
#if (GTK_MINOR_VERSION > 0)
#define NEW_GTK_DND_CODE
#endif
#if wxUSE_DRAG_AND_DROP #if wxUSE_DRAG_AND_DROP
#include "wx/object.h" #include "wx/object.h"
@@ -47,6 +39,172 @@ class wxPrivateDropTarget;
class wxDropSource; class wxDropSource;
//-------------------------------------------------------------------------
// wxDropSource
//-------------------------------------------------------------------------
enum wxDragResult
{
wxDragError, // error prevented the d&d operation from completing
wxDragNone, // drag target didn't accept the data
wxDragCopy, // the data was successfully copied
wxDragMove, // the data was successfully moved (MSW only)
wxDragCancel // the operation was cancelled by user (not an error)
};
class wxDropSource: public wxObject
{
public:
/* constructor. set data later with SetData() */
wxDropSource( wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon );
/* constructor for setting one data object */
wxDropSource( wxDataObject *data, wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon );
/* constructor for setting several data objects via wxDataBroker */
wxDropSource( wxDataBroker *data, wxWindow *win );
~wxDropSource();
/* set several dataobjects via wxDataBroker */
void SetData( wxDataBroker *data );
/* set one dataobject */
void SetData( wxDataObject *data );
/* start drag action */
wxDragResult DoDragDrop( bool bAllowMove = FALSE );
/* override to give feedback */
virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; }
/* GTK implementation */
void RegisterWindow();
void UnregisterWindow();
GtkWidget *m_widget;
wxWindow *m_window;
wxDragResult m_retValue;
wxDataBroker *m_data;
wxCursor m_defaultCursor;
wxCursor m_goaheadCursor;
wxIcon m_goIcon;
wxIcon m_stopIcon;
};
#include "gtk/gtk.h"
#if (GTK_MINOR_VERSION > 0)
//-------------------------------------------------------------------------
// wxDropTarget
//-------------------------------------------------------------------------
class wxDropTarget: public wxObject
{
public:
wxDropTarget();
~wxDropTarget();
/* may be overridden to react to events */
virtual void OnEnter();
virtual void OnLeave();
virtual bool OnMove( int x, int y );
/* has te be overridden to get data */
virtual bool OnDrop( int x, int y );
/* called to query formats available */
bool IsSupported( wxDataFormat format );
/* fill data with data on the clipboard (if available) */
bool GetData( wxDataObject *data );
// implementation
void RegisterWidget( GtkWidget *widget );
void UnregisterWidget( GtkWidget *widget );
GdkDragContext *m_dragContext;
void SetDragContext( GdkDragContext *dc ) { m_dragContext = dc; }
GdkDragContext *GetDragContext() { return m_dragContext; }
};
//-------------------------------------------------------------------------
// wxTextDropTarget
//-------------------------------------------------------------------------
class wxTextDropTarget: public wxDropTarget
{
public:
wxTextDropTarget() {}
virtual bool OnMove( int x, int y );
virtual bool OnDrop( int x, int y );
/* you have to override OnDropData to get at the text */
virtual bool OnDropText( int x, int y, const char *text ) = 0;
};
//-------------------------------------------------------------------------
// wxPrivateDropTarget
//-------------------------------------------------------------------------
class wxPrivateDropTarget: public wxDropTarget
{
public:
/* sets id to "application/myprogram" where "myprogram" is the
same as wxApp->GetAppName() */
wxPrivateDropTarget();
/* see SetId() below for explanation */
wxPrivateDropTarget( const wxString &id );
virtual bool OnMove( int x, int y );
virtual bool OnDrop( int x, int y );
/* you have to override OnDropData to get at the data */
virtual bool OnDropData( int x, int y, void *data, size_t size ) = 0;
/* 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 "application/wxword" or
"image/png". */
void SetId( const wxString& id ) { m_id = id; }
wxString GetId() { return m_id; }
private:
wxString m_id;
};
//----------------------------------------------------------------------------
// A drop target which accepts files (dragged from File Manager or Explorer)
//----------------------------------------------------------------------------
class wxFileDropTarget: public wxDropTarget
{
public:
wxFileDropTarget() {}
virtual bool OnMove( int x, int y );
virtual bool OnDrop( int x, int y );
/* you have to override OnDropFiles to get at the file names */
virtual bool OnDropFiles( int x, int y, size_t nFiles, const char * const aszFiles[] ) = 0;
};
#else
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// wxDropTarget // wxDropTarget
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@@ -141,62 +299,8 @@ class wxFileDropTarget: public wxDropTarget
virtual size_t GetFormatCount() const; virtual size_t GetFormatCount() const;
}; };
//------------------------------------------------------------------------- #endif
// wxDropSource
//-------------------------------------------------------------------------
enum wxDragResult
{
wxDragError, // error prevented the d&d operation from completing
wxDragNone, // drag target didn't accept the data
wxDragCopy, // the data was successfully copied
wxDragMove, // the data was successfully moved (MSW only)
wxDragCancel // the operation was cancelled by user (not an error)
};
class wxDropSource: public wxObject
{
public:
/* constructor. set data later with SetData() */
wxDropSource( wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon );
/* constructor for setting one data object */
wxDropSource( wxDataObject *data, wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon );
/* constructor for setting several data objects via wxDataBroker */
wxDropSource( wxDataBroker *data, wxWindow *win );
~wxDropSource(void);
/* set one dataobject */
void SetData( wxDataBroker *data );
/* set severa dataobjects via wxDataBroker */
void SetData( wxDataObject *data );
/* start drag action */
wxDragResult DoDragDrop( bool bAllowMove = FALSE );
/* override to give feedback */
virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; }
/* GTK implementation */
void RegisterWindow(void);
void UnregisterWindow(void);
GtkWidget *m_widget;
wxWindow *m_window;
wxDragResult m_retValue;
wxDataBroker *m_data;
wxCursor m_defaultCursor;
wxCursor m_goaheadCursor;
wxIcon m_goIcon;
wxIcon m_stopIcon;
};
#endif #endif

View File

@@ -17,14 +17,6 @@
#include "wx/defs.h" #include "wx/defs.h"
//-------------------------------------------------------------------------
// conditional compilation
//-------------------------------------------------------------------------
#if (GTK_MINOR_VERSION > 0)
#define NEW_GTK_DND_CODE
#endif
#if wxUSE_DRAG_AND_DROP #if wxUSE_DRAG_AND_DROP
#include "wx/object.h" #include "wx/object.h"
@@ -47,6 +39,172 @@ class wxPrivateDropTarget;
class wxDropSource; class wxDropSource;
//-------------------------------------------------------------------------
// wxDropSource
//-------------------------------------------------------------------------
enum wxDragResult
{
wxDragError, // error prevented the d&d operation from completing
wxDragNone, // drag target didn't accept the data
wxDragCopy, // the data was successfully copied
wxDragMove, // the data was successfully moved (MSW only)
wxDragCancel // the operation was cancelled by user (not an error)
};
class wxDropSource: public wxObject
{
public:
/* constructor. set data later with SetData() */
wxDropSource( wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon );
/* constructor for setting one data object */
wxDropSource( wxDataObject *data, wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon );
/* constructor for setting several data objects via wxDataBroker */
wxDropSource( wxDataBroker *data, wxWindow *win );
~wxDropSource();
/* set several dataobjects via wxDataBroker */
void SetData( wxDataBroker *data );
/* set one dataobject */
void SetData( wxDataObject *data );
/* start drag action */
wxDragResult DoDragDrop( bool bAllowMove = FALSE );
/* override to give feedback */
virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; }
/* GTK implementation */
void RegisterWindow();
void UnregisterWindow();
GtkWidget *m_widget;
wxWindow *m_window;
wxDragResult m_retValue;
wxDataBroker *m_data;
wxCursor m_defaultCursor;
wxCursor m_goaheadCursor;
wxIcon m_goIcon;
wxIcon m_stopIcon;
};
#include "gtk/gtk.h"
#if (GTK_MINOR_VERSION > 0)
//-------------------------------------------------------------------------
// wxDropTarget
//-------------------------------------------------------------------------
class wxDropTarget: public wxObject
{
public:
wxDropTarget();
~wxDropTarget();
/* may be overridden to react to events */
virtual void OnEnter();
virtual void OnLeave();
virtual bool OnMove( int x, int y );
/* has te be overridden to get data */
virtual bool OnDrop( int x, int y );
/* called to query formats available */
bool IsSupported( wxDataFormat format );
/* fill data with data on the clipboard (if available) */
bool GetData( wxDataObject *data );
// implementation
void RegisterWidget( GtkWidget *widget );
void UnregisterWidget( GtkWidget *widget );
GdkDragContext *m_dragContext;
void SetDragContext( GdkDragContext *dc ) { m_dragContext = dc; }
GdkDragContext *GetDragContext() { return m_dragContext; }
};
//-------------------------------------------------------------------------
// wxTextDropTarget
//-------------------------------------------------------------------------
class wxTextDropTarget: public wxDropTarget
{
public:
wxTextDropTarget() {}
virtual bool OnMove( int x, int y );
virtual bool OnDrop( int x, int y );
/* you have to override OnDropData to get at the text */
virtual bool OnDropText( int x, int y, const char *text ) = 0;
};
//-------------------------------------------------------------------------
// wxPrivateDropTarget
//-------------------------------------------------------------------------
class wxPrivateDropTarget: public wxDropTarget
{
public:
/* sets id to "application/myprogram" where "myprogram" is the
same as wxApp->GetAppName() */
wxPrivateDropTarget();
/* see SetId() below for explanation */
wxPrivateDropTarget( const wxString &id );
virtual bool OnMove( int x, int y );
virtual bool OnDrop( int x, int y );
/* you have to override OnDropData to get at the data */
virtual bool OnDropData( int x, int y, void *data, size_t size ) = 0;
/* 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 "application/wxword" or
"image/png". */
void SetId( const wxString& id ) { m_id = id; }
wxString GetId() { return m_id; }
private:
wxString m_id;
};
//----------------------------------------------------------------------------
// A drop target which accepts files (dragged from File Manager or Explorer)
//----------------------------------------------------------------------------
class wxFileDropTarget: public wxDropTarget
{
public:
wxFileDropTarget() {}
virtual bool OnMove( int x, int y );
virtual bool OnDrop( int x, int y );
/* you have to override OnDropFiles to get at the file names */
virtual bool OnDropFiles( int x, int y, size_t nFiles, const char * const aszFiles[] ) = 0;
};
#else
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// wxDropTarget // wxDropTarget
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@@ -141,62 +299,8 @@ class wxFileDropTarget: public wxDropTarget
virtual size_t GetFormatCount() const; virtual size_t GetFormatCount() const;
}; };
//------------------------------------------------------------------------- #endif
// wxDropSource
//-------------------------------------------------------------------------
enum wxDragResult
{
wxDragError, // error prevented the d&d operation from completing
wxDragNone, // drag target didn't accept the data
wxDragCopy, // the data was successfully copied
wxDragMove, // the data was successfully moved (MSW only)
wxDragCancel // the operation was cancelled by user (not an error)
};
class wxDropSource: public wxObject
{
public:
/* constructor. set data later with SetData() */
wxDropSource( wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon );
/* constructor for setting one data object */
wxDropSource( wxDataObject *data, wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon );
/* constructor for setting several data objects via wxDataBroker */
wxDropSource( wxDataBroker *data, wxWindow *win );
~wxDropSource(void);
/* set one dataobject */
void SetData( wxDataBroker *data );
/* set severa dataobjects via wxDataBroker */
void SetData( wxDataObject *data );
/* start drag action */
wxDragResult DoDragDrop( bool bAllowMove = FALSE );
/* override to give feedback */
virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; }
/* GTK implementation */
void RegisterWindow(void);
void UnregisterWindow(void);
GtkWidget *m_widget;
wxWindow *m_window;
wxDragResult m_retValue;
wxDataBroker *m_data;
wxCursor m_defaultCursor;
wxCursor m_goaheadCursor;
wxIcon m_goIcon;
wxIcon m_stopIcon;
};
#endif #endif

View File

@@ -25,7 +25,6 @@
wxClipboard *wxTheClipboard = (wxClipboard*) NULL; wxClipboard *wxTheClipboard = (wxClipboard*) NULL;
GdkAtom g_textAtom = 0;
GdkAtom g_clipboardAtom = 0; GdkAtom g_clipboardAtom = 0;
GdkAtom g_targetsAtom = 0; GdkAtom g_targetsAtom = 0;
@@ -295,7 +294,6 @@ wxClipboard::wxClipboard()
(gpointer) NULL ); (gpointer) NULL );
if (!g_clipboardAtom) g_clipboardAtom = gdk_atom_intern( "CLIPBOARD", FALSE ); if (!g_clipboardAtom) g_clipboardAtom = gdk_atom_intern( "CLIPBOARD", FALSE );
if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE );
if (!g_targetsAtom) g_targetsAtom = gdk_atom_intern ("TARGETS", FALSE); if (!g_targetsAtom) g_targetsAtom = gdk_atom_intern ("TARGETS", FALSE);
m_formatSupported = FALSE; m_formatSupported = FALSE;

View File

@@ -17,6 +17,13 @@
#include "gdk/gdk.h" #include "gdk/gdk.h"
//-------------------------------------------------------------------------
// global data
//-------------------------------------------------------------------------
GdkAtom g_textAtom = 0;
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// wxDataFormat // wxDataFormat
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@@ -25,6 +32,7 @@ IMPLEMENT_CLASS(wxDataFormat, wxObject)
wxDataFormat::wxDataFormat() wxDataFormat::wxDataFormat()
{ {
if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE );
m_type = wxDF_INVALID; m_type = wxDF_INVALID;
m_hasAtom = FALSE; m_hasAtom = FALSE;
m_atom = (GdkAtom) 0; m_atom = (GdkAtom) 0;
@@ -32,16 +40,19 @@ wxDataFormat::wxDataFormat()
wxDataFormat::wxDataFormat( wxDataType type ) wxDataFormat::wxDataFormat( wxDataType type )
{ {
if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE );
SetType( type ); SetType( type );
} }
wxDataFormat::wxDataFormat( const wxString &id ) wxDataFormat::wxDataFormat( const wxString &id )
{ {
if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE );
SetId( id ); SetId( id );
} }
wxDataFormat::wxDataFormat( wxDataFormat &format ) wxDataFormat::wxDataFormat( wxDataFormat &format )
{ {
if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE );
m_type = format.GetType(); m_type = format.GetType();
m_id = format.GetId(); m_id = format.GetId();
m_hasAtom = TRUE; m_hasAtom = TRUE;
@@ -50,11 +61,12 @@ wxDataFormat::wxDataFormat( wxDataFormat &format )
wxDataFormat::wxDataFormat( const GdkAtom atom ) wxDataFormat::wxDataFormat( const GdkAtom atom )
{ {
if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE );
m_hasAtom = TRUE; m_hasAtom = TRUE;
m_atom = atom; m_atom = atom;
if (m_atom == GDK_TARGET_STRING) if (m_atom == g_textAtom)
{ {
m_type = wxDF_TEXT; m_type = wxDF_TEXT;
} else } else
@@ -79,7 +91,7 @@ void wxDataFormat::SetType( wxDataType type )
if (m_type == wxDF_TEXT) if (m_type == wxDF_TEXT)
{ {
m_id = "STRING"; m_id = "TEXT";
} }
else else
if (m_type == wxDF_BITMAP) if (m_type == wxDF_BITMAP)
@@ -124,7 +136,7 @@ GdkAtom wxDataFormat::GetAtom()
if (m_type == wxDF_TEXT) if (m_type == wxDF_TEXT)
{ {
m_atom = GDK_TARGET_STRING; m_atom = g_textAtom;
} }
else else
if (m_type == wxDF_BITMAP) if (m_type == wxDF_BITMAP)

View File

@@ -33,7 +33,7 @@
extern bool g_blockEventsOnDrag; extern bool g_blockEventsOnDrag;
#ifdef NEW_GTK_DND_CODE #if (GTK_MINOR_VERSION > 0)
#include "gtk/gtkdnd.h" #include "gtk/gtkdnd.h"
#include "gtk/gtkselection.h" #include "gtk/gtkselection.h"
@@ -43,10 +43,13 @@ extern bool g_blockEventsOnDrag;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
static void target_drag_leave( GtkWidget *WXUNUSED(widget), static void target_drag_leave( GtkWidget *WXUNUSED(widget),
GdkDragContext *WXUNUSED(context), GdkDragContext *context,
guint WXUNUSED(time) ) guint WXUNUSED(time),
wxDropTarget *dt )
{ {
printf( "leave.\n" ); dt->SetDragContext( context );
dt->OnLeave();
dt->SetDragContext( (GdkDragContext*) NULL );
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -55,12 +58,23 @@ static void target_drag_leave( GtkWidget *WXUNUSED(widget),
static gboolean target_drag_motion( GtkWidget *WXUNUSED(widget), static gboolean target_drag_motion( GtkWidget *WXUNUSED(widget),
GdkDragContext *context, GdkDragContext *context,
gint WXUNUSED(x), gint x,
gint WXUNUSED(y), gint y,
guint time ) guint time,
wxDropTarget *dt )
{ {
printf( "motion.\n" ); dt->SetDragContext( context );
if (dt->OnMove( x, y ))
{
gdk_drag_status( context, context->suggested_action, time ); gdk_drag_status( context, context->suggested_action, time );
}
else
{
gdk_drag_status( context, (GdkDragAction)0, time );
}
dt->SetDragContext( (GdkDragContext*) NULL );
return TRUE; return TRUE;
} }
@@ -123,6 +137,36 @@ wxDropTarget::~wxDropTarget()
{ {
} }
void wxDropTarget::OnEnter()
{
}
void wxDropTarget::OnLeave()
{
}
bool wxDropTarget::OnMove( int x, int y )
{
printf( "mouse move %d %d.\n", x, y );
return TRUE;
}
bool wxDropTarget::OnDrop( int x, int y )
{
printf( "mouse move %d %d.\n", x, y );
return TRUE;
}
bool wxDropTarget::IsSupported( wxDataFormat format )
{
return TRUE;
}
bool wxDropTarget::GetData( wxDataObject *data )
{
return FALSE;
}
void wxDropTarget::UnregisterWidget( GtkWidget *widget ) void wxDropTarget::UnregisterWidget( GtkWidget *widget )
{ {
wxCHECK_RET( widget != NULL, "unregister widget is NULL" ); wxCHECK_RET( widget != NULL, "unregister widget is NULL" );
@@ -154,32 +198,7 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget )
format.info = 0; format.info = 0;
format.flags = 0; format.flags = 0;
char buf[100]; char buf[100];
strcpy( buf, "text/plain" );
int valid = 0;
for ( size_t i = 0; i < GetFormatCount(); i++ )
{
wxDataFormat df = GetFormat( i );
switch (df)
{
case wxDF_TEXT:
format.target = "text/plain";
valid++;
break;
case wxDF_FILENAME:
format.target = "file:ALL";
valid++;
break;
case wxDF_PRIVATE:
wxPrivateDropTarget *pdt = (wxPrivateDropTarget *)this;
strcpy( buf, WXSTRINGCAST pdt->GetID() );
format.target = buf;
valid++;
default:
break;
}
}
wxASSERT_MSG( valid != 0, "No valid DnD format supported." );
gtk_drag_dest_set( widget, gtk_drag_dest_set( widget,
GTK_DEST_DEFAULT_ALL, GTK_DEST_DEFAULT_ALL,
@@ -200,62 +219,83 @@ 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
// ---------------------------------------------------------------------------- //-------------------------------------------------------------------------
bool wxTextDropTarget::OnDrop( long x, long y, const void *data, size_t WXUNUSED(size) ) bool wxTextDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) )
{ {
OnDropText( x, y, (const char*)data ); return IsSupported( wxDF_TEXT ); // same as "TEXT"
return TRUE;
} }
bool wxTextDropTarget::OnDropText( long x, long y, const char *psz ) bool wxTextDropTarget::OnDrop( int x, int y )
{ {
printf( "Got dropped text: %s.\n", psz ); if (!IsSupported( wxDF_TEXT )) return FALSE;
printf( "At x: %d, y: %d.\n", (int)x, (int)y );
return TRUE; wxTextDataObject data;
if (!GetData( &data )) return FALSE;
return OnDropText( x, y, data.GetText() );
} }
size_t wxTextDropTarget::GetFormatCount() const //-------------------------------------------------------------------------
// wxPrivateDropTarget
//-------------------------------------------------------------------------
wxPrivateDropTarget::wxPrivateDropTarget()
{ {
return 1; m_id = wxTheApp->GetAppName();
} }
wxDataFormat wxTextDropTarget::GetFormat(size_t WXUNUSED(n)) const wxPrivateDropTarget::wxPrivateDropTarget( const wxString &id )
{ {
return wxDF_TEXT; m_id = id;
} }
// ---------------------------------------------------------------------------- bool wxPrivateDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) )
// wxFileDropTarget
// ----------------------------------------------------------------------------
bool wxFileDropTarget::OnDropFiles( long x, long y, size_t nFiles, const char * const aszFiles[] )
{ {
printf( "Got %d dropped files.\n", (int)nFiles ); return IsSupported( m_id );
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;
} }
bool wxFileDropTarget::OnDrop(long x, long y, const void *data, size_t size ) bool wxPrivateDropTarget::OnDrop( int x, int y )
{ {
if (!IsSupported( m_id )) return FALSE;
wxPrivateDataObject data;
if (!GetData( &data )) return FALSE;
return OnDropData( x, y, data.GetData(), data.GetSize() );
}
//----------------------------------------------------------------------------
// A drop target which accepts files (dragged from File Manager or Explorer)
//----------------------------------------------------------------------------
bool wxFileDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) )
{
return IsSupported( wxDF_FILENAME ); // same as "file:ALL"
}
bool wxFileDropTarget::OnDrop( int x, int y )
{
if (!IsSupported( wxDF_FILENAME )) return FALSE;
wxFileDataObject data;
if (!GetData( &data )) return FALSE;
/* get number of substrings /root/mytext.txt/0/root/myothertext.txt/0/0 */
size_t number = 0; size_t number = 0;
size_t i; size_t i;
char *text = (char*) data; size_t size = data.GetFiles().Length();
for (i = 0; i < size; i++) char *text = WXSTRINGCAST data.GetFiles();
for ( i = 0; i < size; i++)
if (text[i] == 0) number++; if (text[i] == 0) number++;
if (number == 0) return TRUE; if (number == 0) return TRUE;
char **files = new char*[number]; char **files = new char*[number];
text = (char*) data; text = WXSTRINGCAST data.GetFiles();
for (i = 0; i < number; i++) for (i = 0; i < number; i++)
{ {
files[i] = text; files[i] = text;
@@ -263,120 +303,17 @@ bool wxFileDropTarget::OnDrop(long x, long y, const void *data, size_t size )
text += len+1; text += len+1;
} }
bool ret = OnDropFiles( x, y, 1, files ); bool ret = OnDropFiles( x, y, number, files );
free( files ); free( files );
return ret; return ret;
} }
size_t wxFileDropTarget::GetFormatCount() const
{
return 1;
}
wxDataFormat wxFileDropTarget::GetFormat(size_t WXUNUSED(n)) const
{
return wxDF_FILENAME;
}
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// wxDropSource // wxDropSource
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
wxDropSource::wxDropSource( wxWindow *win )
{
g_blockEventsOnDrag = TRUE;
m_window = win;
m_widget = win->m_widget;
if (win->m_wxwindow) m_widget = win->m_wxwindow;
m_data = (wxDataObject *) NULL;
m_retValue = wxDragCancel;
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
m_goaheadCursor = wxCursor( wxCURSOR_HAND );
}
wxDropSource::wxDropSource( wxDataObject &data, wxWindow *win )
{
g_blockEventsOnDrag = TRUE;
m_window = win;
m_widget = win->m_widget;
if (win->m_wxwindow) m_widget = win->m_wxwindow;
m_retValue = wxDragCancel;
m_data = &data;
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
m_goaheadCursor = wxCursor( wxCURSOR_HAND );
}
void wxDropSource::SetData( wxDataObject &data )
{
m_data = &data;
}
wxDropSource::~wxDropSource(void)
{
// if (m_data) delete m_data;
g_blockEventsOnDrag = FALSE;
}
wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
{
wxASSERT_MSG( m_data, "wxDragSource: no data" );
if (!m_data) return (wxDragResult) wxDragNone;
if (m_data->GetDataSize() == 0) return (wxDragResult) wxDragNone;
RegisterWindow();
// TODO
UnregisterWindow();
g_blockEventsOnDrag = FALSE;
return m_retValue;
}
void wxDropSource::RegisterWindow(void)
{
if (!m_data) return;
wxString formats;
wxDataFormat df = m_data->GetPreferredFormat();
switch (df)
{
case wxDF_TEXT:
formats += "text/plain";
break;
case wxDF_FILENAME:
formats += "file:ALL";
break;
default:
break;
}
char *str = WXSTRINGCAST formats;
// TODO
}
void wxDropSource::UnregisterWindow(void)
{
if (!m_widget) return;
// TODO
}
#else // NEW_CODE #else // NEW_CODE
GtkWidget *shape_create_icon ( const wxIcon &shape, GtkWidget *shape_create_icon ( const wxIcon &shape,

View File

@@ -25,7 +25,6 @@
wxClipboard *wxTheClipboard = (wxClipboard*) NULL; wxClipboard *wxTheClipboard = (wxClipboard*) NULL;
GdkAtom g_textAtom = 0;
GdkAtom g_clipboardAtom = 0; GdkAtom g_clipboardAtom = 0;
GdkAtom g_targetsAtom = 0; GdkAtom g_targetsAtom = 0;
@@ -295,7 +294,6 @@ wxClipboard::wxClipboard()
(gpointer) NULL ); (gpointer) NULL );
if (!g_clipboardAtom) g_clipboardAtom = gdk_atom_intern( "CLIPBOARD", FALSE ); if (!g_clipboardAtom) g_clipboardAtom = gdk_atom_intern( "CLIPBOARD", FALSE );
if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE );
if (!g_targetsAtom) g_targetsAtom = gdk_atom_intern ("TARGETS", FALSE); if (!g_targetsAtom) g_targetsAtom = gdk_atom_intern ("TARGETS", FALSE);
m_formatSupported = FALSE; m_formatSupported = FALSE;

View File

@@ -17,6 +17,13 @@
#include "gdk/gdk.h" #include "gdk/gdk.h"
//-------------------------------------------------------------------------
// global data
//-------------------------------------------------------------------------
GdkAtom g_textAtom = 0;
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// wxDataFormat // wxDataFormat
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@@ -25,6 +32,7 @@ IMPLEMENT_CLASS(wxDataFormat, wxObject)
wxDataFormat::wxDataFormat() wxDataFormat::wxDataFormat()
{ {
if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE );
m_type = wxDF_INVALID; m_type = wxDF_INVALID;
m_hasAtom = FALSE; m_hasAtom = FALSE;
m_atom = (GdkAtom) 0; m_atom = (GdkAtom) 0;
@@ -32,16 +40,19 @@ wxDataFormat::wxDataFormat()
wxDataFormat::wxDataFormat( wxDataType type ) wxDataFormat::wxDataFormat( wxDataType type )
{ {
if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE );
SetType( type ); SetType( type );
} }
wxDataFormat::wxDataFormat( const wxString &id ) wxDataFormat::wxDataFormat( const wxString &id )
{ {
if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE );
SetId( id ); SetId( id );
} }
wxDataFormat::wxDataFormat( wxDataFormat &format ) wxDataFormat::wxDataFormat( wxDataFormat &format )
{ {
if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE );
m_type = format.GetType(); m_type = format.GetType();
m_id = format.GetId(); m_id = format.GetId();
m_hasAtom = TRUE; m_hasAtom = TRUE;
@@ -50,11 +61,12 @@ wxDataFormat::wxDataFormat( wxDataFormat &format )
wxDataFormat::wxDataFormat( const GdkAtom atom ) wxDataFormat::wxDataFormat( const GdkAtom atom )
{ {
if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE );
m_hasAtom = TRUE; m_hasAtom = TRUE;
m_atom = atom; m_atom = atom;
if (m_atom == GDK_TARGET_STRING) if (m_atom == g_textAtom)
{ {
m_type = wxDF_TEXT; m_type = wxDF_TEXT;
} else } else
@@ -79,7 +91,7 @@ void wxDataFormat::SetType( wxDataType type )
if (m_type == wxDF_TEXT) if (m_type == wxDF_TEXT)
{ {
m_id = "STRING"; m_id = "TEXT";
} }
else else
if (m_type == wxDF_BITMAP) if (m_type == wxDF_BITMAP)
@@ -124,7 +136,7 @@ GdkAtom wxDataFormat::GetAtom()
if (m_type == wxDF_TEXT) if (m_type == wxDF_TEXT)
{ {
m_atom = GDK_TARGET_STRING; m_atom = g_textAtom;
} }
else else
if (m_type == wxDF_BITMAP) if (m_type == wxDF_BITMAP)

View File

@@ -33,7 +33,7 @@
extern bool g_blockEventsOnDrag; extern bool g_blockEventsOnDrag;
#ifdef NEW_GTK_DND_CODE #if (GTK_MINOR_VERSION > 0)
#include "gtk/gtkdnd.h" #include "gtk/gtkdnd.h"
#include "gtk/gtkselection.h" #include "gtk/gtkselection.h"
@@ -43,10 +43,13 @@ extern bool g_blockEventsOnDrag;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
static void target_drag_leave( GtkWidget *WXUNUSED(widget), static void target_drag_leave( GtkWidget *WXUNUSED(widget),
GdkDragContext *WXUNUSED(context), GdkDragContext *context,
guint WXUNUSED(time) ) guint WXUNUSED(time),
wxDropTarget *dt )
{ {
printf( "leave.\n" ); dt->SetDragContext( context );
dt->OnLeave();
dt->SetDragContext( (GdkDragContext*) NULL );
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -55,12 +58,23 @@ static void target_drag_leave( GtkWidget *WXUNUSED(widget),
static gboolean target_drag_motion( GtkWidget *WXUNUSED(widget), static gboolean target_drag_motion( GtkWidget *WXUNUSED(widget),
GdkDragContext *context, GdkDragContext *context,
gint WXUNUSED(x), gint x,
gint WXUNUSED(y), gint y,
guint time ) guint time,
wxDropTarget *dt )
{ {
printf( "motion.\n" ); dt->SetDragContext( context );
if (dt->OnMove( x, y ))
{
gdk_drag_status( context, context->suggested_action, time ); gdk_drag_status( context, context->suggested_action, time );
}
else
{
gdk_drag_status( context, (GdkDragAction)0, time );
}
dt->SetDragContext( (GdkDragContext*) NULL );
return TRUE; return TRUE;
} }
@@ -123,6 +137,36 @@ wxDropTarget::~wxDropTarget()
{ {
} }
void wxDropTarget::OnEnter()
{
}
void wxDropTarget::OnLeave()
{
}
bool wxDropTarget::OnMove( int x, int y )
{
printf( "mouse move %d %d.\n", x, y );
return TRUE;
}
bool wxDropTarget::OnDrop( int x, int y )
{
printf( "mouse move %d %d.\n", x, y );
return TRUE;
}
bool wxDropTarget::IsSupported( wxDataFormat format )
{
return TRUE;
}
bool wxDropTarget::GetData( wxDataObject *data )
{
return FALSE;
}
void wxDropTarget::UnregisterWidget( GtkWidget *widget ) void wxDropTarget::UnregisterWidget( GtkWidget *widget )
{ {
wxCHECK_RET( widget != NULL, "unregister widget is NULL" ); wxCHECK_RET( widget != NULL, "unregister widget is NULL" );
@@ -154,32 +198,7 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget )
format.info = 0; format.info = 0;
format.flags = 0; format.flags = 0;
char buf[100]; char buf[100];
strcpy( buf, "text/plain" );
int valid = 0;
for ( size_t i = 0; i < GetFormatCount(); i++ )
{
wxDataFormat df = GetFormat( i );
switch (df)
{
case wxDF_TEXT:
format.target = "text/plain";
valid++;
break;
case wxDF_FILENAME:
format.target = "file:ALL";
valid++;
break;
case wxDF_PRIVATE:
wxPrivateDropTarget *pdt = (wxPrivateDropTarget *)this;
strcpy( buf, WXSTRINGCAST pdt->GetID() );
format.target = buf;
valid++;
default:
break;
}
}
wxASSERT_MSG( valid != 0, "No valid DnD format supported." );
gtk_drag_dest_set( widget, gtk_drag_dest_set( widget,
GTK_DEST_DEFAULT_ALL, GTK_DEST_DEFAULT_ALL,
@@ -200,62 +219,83 @@ 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
// ---------------------------------------------------------------------------- //-------------------------------------------------------------------------
bool wxTextDropTarget::OnDrop( long x, long y, const void *data, size_t WXUNUSED(size) ) bool wxTextDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) )
{ {
OnDropText( x, y, (const char*)data ); return IsSupported( wxDF_TEXT ); // same as "TEXT"
return TRUE;
} }
bool wxTextDropTarget::OnDropText( long x, long y, const char *psz ) bool wxTextDropTarget::OnDrop( int x, int y )
{ {
printf( "Got dropped text: %s.\n", psz ); if (!IsSupported( wxDF_TEXT )) return FALSE;
printf( "At x: %d, y: %d.\n", (int)x, (int)y );
return TRUE; wxTextDataObject data;
if (!GetData( &data )) return FALSE;
return OnDropText( x, y, data.GetText() );
} }
size_t wxTextDropTarget::GetFormatCount() const //-------------------------------------------------------------------------
// wxPrivateDropTarget
//-------------------------------------------------------------------------
wxPrivateDropTarget::wxPrivateDropTarget()
{ {
return 1; m_id = wxTheApp->GetAppName();
} }
wxDataFormat wxTextDropTarget::GetFormat(size_t WXUNUSED(n)) const wxPrivateDropTarget::wxPrivateDropTarget( const wxString &id )
{ {
return wxDF_TEXT; m_id = id;
} }
// ---------------------------------------------------------------------------- bool wxPrivateDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) )
// wxFileDropTarget
// ----------------------------------------------------------------------------
bool wxFileDropTarget::OnDropFiles( long x, long y, size_t nFiles, const char * const aszFiles[] )
{ {
printf( "Got %d dropped files.\n", (int)nFiles ); return IsSupported( m_id );
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;
} }
bool wxFileDropTarget::OnDrop(long x, long y, const void *data, size_t size ) bool wxPrivateDropTarget::OnDrop( int x, int y )
{ {
if (!IsSupported( m_id )) return FALSE;
wxPrivateDataObject data;
if (!GetData( &data )) return FALSE;
return OnDropData( x, y, data.GetData(), data.GetSize() );
}
//----------------------------------------------------------------------------
// A drop target which accepts files (dragged from File Manager or Explorer)
//----------------------------------------------------------------------------
bool wxFileDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) )
{
return IsSupported( wxDF_FILENAME ); // same as "file:ALL"
}
bool wxFileDropTarget::OnDrop( int x, int y )
{
if (!IsSupported( wxDF_FILENAME )) return FALSE;
wxFileDataObject data;
if (!GetData( &data )) return FALSE;
/* get number of substrings /root/mytext.txt/0/root/myothertext.txt/0/0 */
size_t number = 0; size_t number = 0;
size_t i; size_t i;
char *text = (char*) data; size_t size = data.GetFiles().Length();
for (i = 0; i < size; i++) char *text = WXSTRINGCAST data.GetFiles();
for ( i = 0; i < size; i++)
if (text[i] == 0) number++; if (text[i] == 0) number++;
if (number == 0) return TRUE; if (number == 0) return TRUE;
char **files = new char*[number]; char **files = new char*[number];
text = (char*) data; text = WXSTRINGCAST data.GetFiles();
for (i = 0; i < number; i++) for (i = 0; i < number; i++)
{ {
files[i] = text; files[i] = text;
@@ -263,120 +303,17 @@ bool wxFileDropTarget::OnDrop(long x, long y, const void *data, size_t size )
text += len+1; text += len+1;
} }
bool ret = OnDropFiles( x, y, 1, files ); bool ret = OnDropFiles( x, y, number, files );
free( files ); free( files );
return ret; return ret;
} }
size_t wxFileDropTarget::GetFormatCount() const
{
return 1;
}
wxDataFormat wxFileDropTarget::GetFormat(size_t WXUNUSED(n)) const
{
return wxDF_FILENAME;
}
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// wxDropSource // wxDropSource
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
wxDropSource::wxDropSource( wxWindow *win )
{
g_blockEventsOnDrag = TRUE;
m_window = win;
m_widget = win->m_widget;
if (win->m_wxwindow) m_widget = win->m_wxwindow;
m_data = (wxDataObject *) NULL;
m_retValue = wxDragCancel;
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
m_goaheadCursor = wxCursor( wxCURSOR_HAND );
}
wxDropSource::wxDropSource( wxDataObject &data, wxWindow *win )
{
g_blockEventsOnDrag = TRUE;
m_window = win;
m_widget = win->m_widget;
if (win->m_wxwindow) m_widget = win->m_wxwindow;
m_retValue = wxDragCancel;
m_data = &data;
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
m_goaheadCursor = wxCursor( wxCURSOR_HAND );
}
void wxDropSource::SetData( wxDataObject &data )
{
m_data = &data;
}
wxDropSource::~wxDropSource(void)
{
// if (m_data) delete m_data;
g_blockEventsOnDrag = FALSE;
}
wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
{
wxASSERT_MSG( m_data, "wxDragSource: no data" );
if (!m_data) return (wxDragResult) wxDragNone;
if (m_data->GetDataSize() == 0) return (wxDragResult) wxDragNone;
RegisterWindow();
// TODO
UnregisterWindow();
g_blockEventsOnDrag = FALSE;
return m_retValue;
}
void wxDropSource::RegisterWindow(void)
{
if (!m_data) return;
wxString formats;
wxDataFormat df = m_data->GetPreferredFormat();
switch (df)
{
case wxDF_TEXT:
formats += "text/plain";
break;
case wxDF_FILENAME:
formats += "file:ALL";
break;
default:
break;
}
char *str = WXSTRINGCAST formats;
// TODO
}
void wxDropSource::UnregisterWindow(void)
{
if (!m_widget) return;
// TODO
}
#else // NEW_CODE #else // NEW_CODE
GtkWidget *shape_create_icon ( const wxIcon &shape, GtkWidget *shape_create_icon ( const wxIcon &shape,

View File

@@ -265,7 +265,7 @@ long wxExecute( char **argv, bool sync, wxProcess *process )
// These three lines close the open file descriptors to to avoid any // These three lines close the open file descriptors to to avoid any
// input/output which might block the process or irritate the user. If // input/output which might block the process or irritate the user. If
// one wants proper IO for the subprocess, the "right thing to do is // one wants proper IO for the subprocess, the right thing to do is
// to start an xterm executing it. // to start an xterm executing it.
if (sync == 0) if (sync == 0)
{ {