Made wxGTK compile and link again. Broke wxMSW a little.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4098 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling 1999-10-21 10:23:30 +00:00
parent 1be7f92adb
commit b068c4e8a1
18 changed files with 398 additions and 598 deletions

View File

@ -1,5 +1,5 @@
# #
# This file was automatically generated by tmake at 04:13, 1999/10/21 # This file was automatically generated by tmake at 11:02, 1999/10/21
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE UNX.T! # DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE UNX.T!
# #
@ -685,6 +685,7 @@ GTK_COMMONOBJS = \
parser.o \ parser.o \
appcmn.o \ appcmn.o \
choiccmn.o \ choiccmn.o \
clipcmn.o \
cmndata.o \ cmndata.o \
config.o \ config.o \
ctrlcmn.o \ ctrlcmn.o \
@ -776,6 +777,7 @@ GTK_COMMONDEPS = \
parser.d \ parser.d \
appcmn.d \ appcmn.d \
choiccmn.d \ choiccmn.d \
clipcmn.d \
cmndata.d \ cmndata.d \
config.d \ config.d \
ctrlcmn.d \ ctrlcmn.d \
@ -1061,6 +1063,7 @@ MOTIF_COMMONOBJS = \
parser.o \ parser.o \
appcmn.o \ appcmn.o \
choiccmn.o \ choiccmn.o \
clipcmn.o \
cmndata.o \ cmndata.o \
config.o \ config.o \
ctrlcmn.o \ ctrlcmn.o \
@ -1153,6 +1156,7 @@ MOTIF_COMMONDEPS = \
parser.d \ parser.d \
appcmn.d \ appcmn.d \
choiccmn.d \ choiccmn.d \
clipcmn.d \
cmndata.d \ cmndata.d \
config.d \ config.d \
ctrlcmn.d \ ctrlcmn.d \
@ -1401,6 +1405,7 @@ MSW_COMMONOBJS = \
parser.o \ parser.o \
appcmn.o \ appcmn.o \
choiccmn.o \ choiccmn.o \
clipcmn.o \
cmndata.o \ cmndata.o \
config.o \ config.o \
ctrlcmn.o \ ctrlcmn.o \
@ -1493,6 +1498,7 @@ MSW_COMMONDEPS = \
parser.d \ parser.d \
appcmn.d \ appcmn.d \
choiccmn.d \ choiccmn.d \
clipcmn.d \
cmndata.d \ cmndata.d \
config.d \ config.d \
ctrlcmn.d \ ctrlcmn.d \

View File

@ -94,6 +94,7 @@ wizard.cpp G
appcmn.cpp C B appcmn.cpp C B
choiccmn.cpp C choiccmn.cpp C
cmndata.cpp C cmndata.cpp C
clipcmn.cpp C
config.cpp C B config.cpp C B
ctrlcmn.cpp C ctrlcmn.cpp C
date.cpp C B date.cpp C B

View File

@ -12,10 +12,15 @@
#ifndef _WX_CLIPBRD_H_BASE_ #ifndef _WX_CLIPBRD_H_BASE_
#define _WX_CLIPBRD_H_BASE_ #define _WX_CLIPBRD_H_BASE_
#ifdef __GNUG__
#pragma interface "clipboardbase.h"
#endif
#include "wx/defs.h" #include "wx/defs.h"
#if wxUSE_CLIPBOARD #if wxUSE_CLIPBOARD
#include "wx/object.h" #include "wx/object.h"
#include "wx/wxchar.h" #include "wx/wxchar.h"
@ -33,30 +38,32 @@ class WXDLLEXPORT wxDataObject;
class WXDLLEXPORT wxClipboardBase : public wxObject class WXDLLEXPORT wxClipboardBase : public wxObject
{ {
public: public:
wxClipboardBase();
// open the clipboard before Add/SetData() and GetData() // open the clipboard before Add/SetData() and GetData()
virtual bool Open(); virtual bool Open() = 0;
// close the clipboard after Add/SetData() and GetData() // close the clipboard after Add/SetData() and GetData()
virtual void Close(); virtual void Close() = 0;
// add to the clipboard data // add to the clipboard data
// //
// NB: the clipboard owns the pointer and will delete it, so data must be // NB: the clipboard owns the pointer and will delete it, so data must be
// allocated on the heap // allocated on the heap
virtual bool AddData( wxDataObject *data ); virtual bool AddData( wxDataObject *data ) = 0;
// set the clipboard data, this is the same as Clear() followed by // set the clipboard data, this is the same as Clear() followed by
// AddData() // AddData()
virtual bool SetData( wxDataObject *data ); virtual bool SetData( wxDataObject *data ) = 0;
// ask if data in correct format is available // ask if data in correct format is available
virtual bool IsSupported( const wxDataFormat& format ); virtual bool IsSupported( const wxDataFormat& format ) = 0;
// fill data with data on the clipboard (if available) // fill data with data on the clipboard (if available)
virtual bool GetData( wxDataObject& data ); virtual bool GetData( wxDataObject& data ) = 0;
// clears wxTheClipboard and the system's clipboard if possible // clears wxTheClipboard and the system's clipboard if possible
virtual void Clear(); virtual void Clear() = 0;
// flushes the clipboard: this means that the data which is currently on // flushes the clipboard: this means that the data which is currently on
// clipboard will stay available even after the application exits (possibly // clipboard will stay available even after the application exits (possibly
@ -104,25 +111,6 @@ public:
// The global clipboard object // The global clipboard object
WXDLLEXPORT_DATA(extern wxClipboard *) wxTheClipboard; WXDLLEXPORT_DATA(extern wxClipboard *) wxTheClipboard;
// ----------------------------------------------------------------------------
// wxClipboardModule: module responsible for initializing the global clipboard
// object
//
// NB: IMPLEMENT_DYNAMIC_CLASS() for it is in common/appcmn.cpp
// ----------------------------------------------------------------------------
class wxClipboardModule : public wxModule
{
public:
bool OnInit()
{ wxTheClipboard = new wxClipboard; return TRUE; }
void OnExit()
{ delete wxTheClipboard; wxTheClipboard = (wxClipboard *)NULL; }
private:
DECLARE_DYNAMIC_CLASS(wxClipboardModule)
};
#endif // wxUSE_CLIPBOARD #endif // wxUSE_CLIPBOARD
#endif // _WX_CLIPBRD_H_BASE_ #endif // _WX_CLIPBRD_H_BASE_

View File

@ -331,7 +331,7 @@ public:
virtual wxBitmap GetBitmap() const { return m_bitmap; } virtual wxBitmap GetBitmap() const { return m_bitmap; }
virtual void SetBitmap(const wxBitmap& bitmap) { m_bitmap = bitmap; } virtual void SetBitmap(const wxBitmap& bitmap) { m_bitmap = bitmap; }
private: protected:
wxBitmap m_bitmap; wxBitmap m_bitmap;
}; };
@ -349,7 +349,7 @@ public:
wxFileDataObjectBase() : wxDataObjectSimple(wxDF_FILENAME) { } wxFileDataObjectBase() : wxDataObjectSimple(wxDF_FILENAME) { }
// get a reference to our array // get a reference to our array
const wxArrayString& GetFilenames() { return m_filenames; } const wxArrayString& GetFilenames() const { return m_filenames; }
// the Get() functions do nothing for us // the Get() functions do nothing for us
virtual size_t GetDataSize() const { return 0; } virtual size_t GetDataSize() const { return 0; }

View File

@ -44,7 +44,9 @@ public:
virtual ~wxDropSourceBase() { } virtual ~wxDropSourceBase() { }
// set the data which is transfered by drag and drop // set the data which is transfered by drag and drop
void SetData(wxDataObject& data) { delete m_data; m_data = &data; } void SetData(wxDataObject& data)
{ if (m_data) delete m_data;
m_data = &data; }
// start drag action, see enum wxDragResult for return value description // start drag action, see enum wxDragResult for return value description
// //
@ -80,7 +82,7 @@ public:
// ctor takes a pointer to heap-allocated wxDataObject which will be owned // ctor takes a pointer to heap-allocated wxDataObject which will be owned
// by wxDropTarget and deleted by it automatically. If you don't give it // by wxDropTarget and deleted by it automatically. If you don't give it
// here, you can use SetDataObject() later. // here, you can use SetDataObject() later.
wxDropTargetBase(wxDataObject *dataObject = NULL) wxDropTargetBase(wxDataObject *dataObject = (wxDataObject*)NULL)
{ m_dataObject = dataObject; } { m_dataObject = dataObject; }
// dtor deletes our data object // dtor deletes our data object
virtual ~wxDropTargetBase() virtual ~wxDropTargetBase()
@ -90,13 +92,23 @@ public:
wxDataObject *GetDataObject() const wxDataObject *GetDataObject() const
{ return m_dataObject; } { return m_dataObject; }
void SetDataObject(wxDataObject *dataObject) void SetDataObject(wxDataObject *dataObject)
{ delete m_dataObject; m_dataObject = dataObject; } { if (m_dataObject) delete m_dataObject;
m_dataObject = dataObject; }
// called when mouse enters/leaves the window: might be used to give // called when mouse enters/leaves the window: might be used to give
// some visual feedback to the user // some visual feedback to the user
virtual void OnEnter() { }
virtual void OnLeave() { } virtual void OnLeave() { }
// this function is called when data enters over position (x, y) - if it
// returns TRUE, the dragging icon can indicate that the window would
// accept a drop here
virtual bool OnEnter(wxCoord x, wxCoord y) = 0;
// this function is called when data is move over position (x, y) - if it
// returns TRUE, the dragging icon can indicate that the window would
// accept a drop here
virtual bool OnMove(wxCoord x, wxCoord y) = 0;
// this function is called when data is dropped at position (x, y) - if it // this function is called when data is dropped at position (x, y) - if it
// returns TRUE, OnData() will be called immediately afterwards which will // returns TRUE, OnData() will be called immediately afterwards which will
// allow to retrieve the data dropped. // allow to retrieve the data dropped.

View File

@ -20,6 +20,10 @@
class wxDataObject : public wxDataObjectBase class wxDataObject : public wxDataObjectBase
{ {
public:
wxDataObject();
virtual bool IsSupportedFormat( const wxDataFormat& format, Direction dir = Get ) const;
}; };
#endif // _WX_GTK_DATAOBJ_H_ #endif // _WX_GTK_DATAOBJ_H_

View File

@ -46,7 +46,6 @@ protected:
void Clear() { free(m_pngData); } void Clear() { free(m_pngData); }
void ClearAll() { Clear(); Init(); } void ClearAll() { Clear(); Init(); }
private:
size_t m_pngSize; size_t m_pngSize;
void *m_pngData; void *m_pngData;
@ -63,6 +62,8 @@ public:
// implement base class pure virtuals // implement base class pure virtuals
// ---------------------------------- // ----------------------------------
void AddFile( const wxString &filename );
virtual size_t GetDataSize() const; virtual size_t GetDataSize() const;
virtual bool GetDataHere(void *buf) const; virtual bool GetDataHere(void *buf) const;
virtual bool SetData(size_t len, const void *buf); virtual bool SetData(size_t len, const void *buf);

View File

@ -41,135 +41,40 @@ class wxDropSource;
// wxDropTarget // wxDropTarget
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
class wxDropTarget: public wxObject class wxDropTarget: public wxDropTargetBase
{ {
public: public:
wxDropTarget(wxDataObject *dataObject = (wxDataObject*) NULL );
virtual bool OnEnter(wxCoord x, wxCoord y) ;
virtual bool OnMove(wxCoord x, wxCoord y);
virtual bool OnDrop(wxCoord x, wxCoord y);
virtual bool OnData(wxCoord x, wxCoord y);
virtual bool GetData();
wxDropTarget(); // implementation
~wxDropTarget();
/* may be overridden to react to events */ GdkAtom GetMatchingPair();
virtual void OnEnter(); void RegisterWidget( GtkWidget *widget );
virtual void OnLeave(); void UnregisterWidget( GtkWidget *widget );
/* may be overridden to reject certain formats or drops GdkDragContext *m_dragContext;
on certain areas. always returns TRUE by default GtkWidget *m_dragWidget;
indicating that you'd accept the data from the drag. */ GtkSelectionData *m_dragData;
virtual bool OnMove( long x, long y ); guint m_dragTime;
bool m_firstMotion; /* gdk has no "gdk_drag_enter" event */
/* has to be overridden to accept a drop event. call void SetDragContext( GdkDragContext *dc ) { m_dragContext = dc; }
IsSupported() to ask which formats are available void SetDragWidget( GtkWidget *w ) { m_dragWidget = w; }
and then call RequestData() to indicate the format void SetDragData( GtkSelectionData *sd ) { m_dragData = sd; }
you request. */ void SetDragTime( guint time ) { m_dragTime = time; }
virtual bool OnDrop( long x, long y );
/* this gets called once the data has actually arrived. get
it with GetData(). this has to be overridden. */
virtual bool OnData( long x, long y );
/* called from within OnDrop() to request a certain format
from the drop event. */
bool RequestData( wxDataFormat format );
/* called to query what formats are available */
bool IsSupported( wxDataFormat format );
/* fill data with data from the dragging source */
bool GetData( wxDataObject *data );
virtual size_t GetFormatCount() const = 0;
virtual wxDataFormat GetFormat(size_t n) const = 0;
// implementation
void RegisterWidget( GtkWidget *widget );
void UnregisterWidget( GtkWidget *widget );
GdkDragContext *m_dragContext;
GtkWidget *m_dragWidget;
GtkSelectionData *m_dragData;
guint m_dragTime;
bool m_firstMotion; /* gdk has no "gdk_drag_enter" event */
void SetDragContext( GdkDragContext *dc ) { m_dragContext = dc; }
void SetDragWidget( GtkWidget *w ) { m_dragWidget = w; }
void SetDragData( GtkSelectionData *sd ) { m_dragData = sd; }
void SetDragTime( guint time ) { m_dragTime = time; }
};
//-------------------------------------------------------------------------
// wxTextDropTarget
//-------------------------------------------------------------------------
class wxTextDropTarget: public wxDropTarget
{
public:
wxTextDropTarget() {}
virtual bool OnData( long x, long y );
/* you have to override OnDropData to get at the text */
virtual bool OnDropText( long x, long y, const wxChar *text ) = 0;
virtual size_t GetFormatCount() const
{ return 1; }
virtual wxDataFormat GetFormat(size_t n) const
{ return wxDF_TEXT; }
};
//-------------------------------------------------------------------------
// wxPrivateDropTarget
//-------------------------------------------------------------------------
/*
class wxPrivateDropTarget: public wxDropTarget
{
public:
wxPrivateDropTarget();
wxPrivateDropTarget( const wxString &id );
virtual bool OnMove( long x, long y );
virtual bool OnDrop( long x, long y );
virtual bool OnData( long x, long y );
virtual bool OnDropData( long x, long y, void *data, size_t size ) = 0;
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 OnData( long x, long y );
virtual bool OnDropFiles( long x, long y, size_t nFiles, const wxChar * const aszFiles[] ) = 0;
virtual size_t GetFormatCount() const
{ return 1; }
virtual wxDataFormat GetFormat(size_t n) const
{ return wxDF_FILENAME; }
}; };
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// wxDropSource // wxDropSource
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
class wxDropSource: public wxObject class wxDropSource: public wxDropSourceBase
{ {
public: public:
/* constructor. set data later with SetData() */ /* constructor. set data later with SetData() */

View File

@ -20,6 +20,10 @@
class wxDataObject : public wxDataObjectBase class wxDataObject : public wxDataObjectBase
{ {
public:
wxDataObject();
virtual bool IsSupportedFormat( const wxDataFormat& format, Direction dir = Get ) const;
}; };
#endif // _WX_GTK_DATAOBJ_H_ #endif // _WX_GTK_DATAOBJ_H_

View File

@ -46,7 +46,6 @@ protected:
void Clear() { free(m_pngData); } void Clear() { free(m_pngData); }
void ClearAll() { Clear(); Init(); } void ClearAll() { Clear(); Init(); }
private:
size_t m_pngSize; size_t m_pngSize;
void *m_pngData; void *m_pngData;
@ -63,6 +62,8 @@ public:
// implement base class pure virtuals // implement base class pure virtuals
// ---------------------------------- // ----------------------------------
void AddFile( const wxString &filename );
virtual size_t GetDataSize() const; virtual size_t GetDataSize() const;
virtual bool GetDataHere(void *buf) const; virtual bool GetDataHere(void *buf) const;
virtual bool SetData(size_t len, const void *buf); virtual bool SetData(size_t len, const void *buf);

View File

@ -41,135 +41,40 @@ class wxDropSource;
// wxDropTarget // wxDropTarget
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
class wxDropTarget: public wxObject class wxDropTarget: public wxDropTargetBase
{ {
public: public:
wxDropTarget(wxDataObject *dataObject = (wxDataObject*) NULL );
virtual bool OnEnter(wxCoord x, wxCoord y) ;
virtual bool OnMove(wxCoord x, wxCoord y);
virtual bool OnDrop(wxCoord x, wxCoord y);
virtual bool OnData(wxCoord x, wxCoord y);
virtual bool GetData();
wxDropTarget(); // implementation
~wxDropTarget();
/* may be overridden to react to events */ GdkAtom GetMatchingPair();
virtual void OnEnter(); void RegisterWidget( GtkWidget *widget );
virtual void OnLeave(); void UnregisterWidget( GtkWidget *widget );
/* may be overridden to reject certain formats or drops GdkDragContext *m_dragContext;
on certain areas. always returns TRUE by default GtkWidget *m_dragWidget;
indicating that you'd accept the data from the drag. */ GtkSelectionData *m_dragData;
virtual bool OnMove( long x, long y ); guint m_dragTime;
bool m_firstMotion; /* gdk has no "gdk_drag_enter" event */
/* has to be overridden to accept a drop event. call void SetDragContext( GdkDragContext *dc ) { m_dragContext = dc; }
IsSupported() to ask which formats are available void SetDragWidget( GtkWidget *w ) { m_dragWidget = w; }
and then call RequestData() to indicate the format void SetDragData( GtkSelectionData *sd ) { m_dragData = sd; }
you request. */ void SetDragTime( guint time ) { m_dragTime = time; }
virtual bool OnDrop( long x, long y );
/* this gets called once the data has actually arrived. get
it with GetData(). this has to be overridden. */
virtual bool OnData( long x, long y );
/* called from within OnDrop() to request a certain format
from the drop event. */
bool RequestData( wxDataFormat format );
/* called to query what formats are available */
bool IsSupported( wxDataFormat format );
/* fill data with data from the dragging source */
bool GetData( wxDataObject *data );
virtual size_t GetFormatCount() const = 0;
virtual wxDataFormat GetFormat(size_t n) const = 0;
// implementation
void RegisterWidget( GtkWidget *widget );
void UnregisterWidget( GtkWidget *widget );
GdkDragContext *m_dragContext;
GtkWidget *m_dragWidget;
GtkSelectionData *m_dragData;
guint m_dragTime;
bool m_firstMotion; /* gdk has no "gdk_drag_enter" event */
void SetDragContext( GdkDragContext *dc ) { m_dragContext = dc; }
void SetDragWidget( GtkWidget *w ) { m_dragWidget = w; }
void SetDragData( GtkSelectionData *sd ) { m_dragData = sd; }
void SetDragTime( guint time ) { m_dragTime = time; }
};
//-------------------------------------------------------------------------
// wxTextDropTarget
//-------------------------------------------------------------------------
class wxTextDropTarget: public wxDropTarget
{
public:
wxTextDropTarget() {}
virtual bool OnData( long x, long y );
/* you have to override OnDropData to get at the text */
virtual bool OnDropText( long x, long y, const wxChar *text ) = 0;
virtual size_t GetFormatCount() const
{ return 1; }
virtual wxDataFormat GetFormat(size_t n) const
{ return wxDF_TEXT; }
};
//-------------------------------------------------------------------------
// wxPrivateDropTarget
//-------------------------------------------------------------------------
/*
class wxPrivateDropTarget: public wxDropTarget
{
public:
wxPrivateDropTarget();
wxPrivateDropTarget( const wxString &id );
virtual bool OnMove( long x, long y );
virtual bool OnDrop( long x, long y );
virtual bool OnData( long x, long y );
virtual bool OnDropData( long x, long y, void *data, size_t size ) = 0;
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 OnData( long x, long y );
virtual bool OnDropFiles( long x, long y, size_t nFiles, const wxChar * const aszFiles[] ) = 0;
virtual size_t GetFormatCount() const
{ return 1; }
virtual wxDataFormat GetFormat(size_t n) const
{ return wxDF_FILENAME; }
}; };
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// wxDropSource // wxDropSource
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
class wxDropSource: public wxObject class wxDropSource: public wxDropSourceBase
{ {
public: public:
/* constructor. set data later with SetData() */ /* constructor. set data later with SetData() */

59
src/common/clipcmn.cpp Normal file
View File

@ -0,0 +1,59 @@
/////////////////////////////////////////////////////////////////////////////
// Name: common/clipcmn.cpp
// Purpose: common (to all ports) wxClipboard functions
// Author: Robert Roebling
// Modified by:
// Created: 28.06.99
// RCS-ID: $Id$
// Copyright: (c) Robert Roebling
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifdef __GNUG__
#pragma implementation "clipboardbase.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/clipbrd.h"
//--------------------------------------------------------------------------
// wxClipboardBase
//--------------------------------------------------------------------------
wxClipboardBase::wxClipboardBase()
{
}
// ----------------------------------------------------------------------------
// wxClipboardModule: module responsible for initializing the global clipboard
// object
//
// NB: IMPLEMENT_DYNAMIC_CLASS() for it is in common/appcmn.cpp
// ----------------------------------------------------------------------------
class wxClipboardModule : public wxModule
{
public:
bool OnInit()
{ wxTheClipboard = new wxClipboard; return TRUE; }
void OnExit()
{ delete wxTheClipboard; wxTheClipboard = (wxClipboard *)NULL; }
private:
DECLARE_DYNAMIC_CLASS(wxClipboardModule)
};

View File

@ -17,6 +17,7 @@
#include "wx/dataobj.h" #include "wx/dataobj.h"
#include "wx/utils.h" #include "wx/utils.h"
#include "wx/log.h"
#include "glib.h" #include "glib.h"
#include "gdk/gdk.h" #include "gdk/gdk.h"
@ -148,9 +149,11 @@ selection_received( GtkWidget *WXUNUSED(widget),
clipboard->m_waiting = FALSE; clipboard->m_waiting = FALSE;
return; return;
} }
wxDataFormat format( selection_data->target );
/* make sure we got the data in the correct format */ /* make sure we got the data in the correct format */
if (data_object->GetFormat() != selection_data->target) if (!data_object->IsSupportedFormat( format ) )
{ {
clipboard->m_waiting = FALSE; clipboard->m_waiting = FALSE;
return; return;
@ -159,7 +162,7 @@ selection_received( GtkWidget *WXUNUSED(widget),
/* make sure we got the data in the correct form (selection type). /* make sure we got the data in the correct form (selection type).
if so, copy data to target object */ if so, copy data to target object */
switch (data_object->GetFormat().GetType()) switch (format.GetType())
{ {
case wxDF_TEXT: case wxDF_TEXT:
{ {
@ -188,7 +191,7 @@ selection_received( GtkWidget *WXUNUSED(widget),
wxBitmapDataObject *bitmap_object = (wxBitmapDataObject *) data_object; wxBitmapDataObject *bitmap_object = (wxBitmapDataObject *) data_object;
bitmap_object->SetPngData( (const void*) selection_data->data, (size_t) selection_data->length ); bitmap_object->SetData( (size_t) selection_data->length, (const void*) selection_data->data );
break; break;
} }
@ -201,9 +204,7 @@ selection_received( GtkWidget *WXUNUSED(widget),
return; return;
} }
wxPrivateDataObject *private_object = (wxPrivateDataObject *) data_object; data_object->SetData( format, (size_t) selection_data->length, (const char*) selection_data->data );
private_object->SetData( (const char*) selection_data->data, (size_t) selection_data->length );
break; break;
} }
@ -271,9 +272,11 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data
wxDataObject *data = wxTheClipboard->m_data; wxDataObject *data = wxTheClipboard->m_data;
if (!data->IsSupportedFormat( selection_data->target )) return; wxDataFormat format( selection_data->target );
if (!data->IsSupportedFormat( format )) return;
if (data->GetFormat().GetType() == wxDF_TEXT) if (format.GetType() == wxDF_TEXT)
{ {
wxTextDataObject *text_object = (wxTextDataObject*) data; wxTextDataObject *text_object = (wxTextDataObject*) data;
wxString text( text_object->GetText() ); wxString text( text_object->GetText() );
@ -295,23 +298,23 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data
return; return;
} }
if (data->GetFormat().GetType() == wxDF_BITMAP) if (format.GetType() == wxDF_BITMAP)
{ {
wxBitmapDataObject *bitmap_object = (wxBitmapDataObject*) data; wxBitmapDataObject *bitmap_object = (wxBitmapDataObject*) data;
if (bitmap_object->GetDataSize(wxDF_BITMAP) == 0) return; if (bitmap_object->GetDataSize() == 0) return;
gtk_selection_data_set( gtk_selection_data_set(
selection_data, selection_data,
GDK_SELECTION_TYPE_STRING, GDK_SELECTION_TYPE_STRING,
8*sizeof(gchar), 8*sizeof(gchar),
(unsigned char*) bitmap_object->GetData(), (unsigned char*) bitmap_object->GetPngData(),
(int) bitmap_object->GetDataSize(wxDF_BITMAP) ); (int) bitmap_object->GetDataSize() );
return; return;
} }
int size = data->GetDataSize( selection_data->target ); int size = data->GetDataSize( format );
if (size == 0) return; if (size == 0) return;
@ -456,54 +459,46 @@ bool wxClipboard::AddData( wxDataObject *data )
wxCHECK_MSG( data, FALSE, wxT("data is invalid") ); wxCHECK_MSG( data, FALSE, wxT("data is invalid") );
// we can only store one wxDataObject /* we can only store one wxDataObject */
Clear(); Clear();
m_data = data; m_data = data;
/* get native format id of new data object */
GdkAtom format = data->GetFormat();
wxCHECK_MSG( format, FALSE, wxT("data has invalid format") );
/* This should happen automatically, but to be on the safe side */ /* This should happen automatically, but to be on the safe side */
m_ownsClipboard = FALSE; m_ownsClipboard = FALSE;
m_ownsPrimarySelection = FALSE; m_ownsPrimarySelection = FALSE;
/* Add handlers if someone requests data */ /* get formats from wxDataObjects */
wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ];
m_data->GetAllFormats( array );
for (size_t i = 0; i < m_data->GetFormatCount(); i++)
{
GdkAtom atom = array[i];
wxLogDebug( wxT("Clipboard Supported atom %s"), gdk_atom_name( atom ) );
#if (GTK_MINOR_VERSION > 0) /* Add handlers if someone requests data. We currently always
offer data to the clipboard and the primary selection. Maybe
gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget), we should make that depend on the usePrimary flag */
gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget),
GDK_SELECTION_PRIMARY, GDK_SELECTION_PRIMARY,
format, atom,
0 ); /* what is info ? */ 0 ); /* what is info ? */
gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget), gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget),
g_clipboardAtom, g_clipboardAtom,
format, atom,
0 ); /* what is info ? */ 0 ); /* what is info ? */
}
delete[] array;
gtk_signal_connect( GTK_OBJECT(m_clipboardWidget), gtk_signal_connect( GTK_OBJECT(m_clipboardWidget),
"selection_get", "selection_get",
GTK_SIGNAL_FUNC(selection_handler), GTK_SIGNAL_FUNC(selection_handler),
(gpointer) NULL ); (gpointer) NULL );
#else
gtk_selection_add_handler( m_clipboardWidget,
g_clipboardAtom,
format,
selection_handler,
(gpointer) NULL );
gtk_selection_add_handler( m_clipboardWidget,
GDK_SELECTION_PRIMARY,
format,
selection_handler,
(gpointer) NULL );
#endif
#if wxUSE_THREADS #if wxUSE_THREADS
/* disable GUI threads */ /* disable GUI threads */
wxapp_uninstall_thread_wakeup(); wxapp_uninstall_thread_wakeup();
@ -585,47 +580,56 @@ bool wxClipboard::GetData( wxDataObject& data )
{ {
wxCHECK_MSG( m_open, FALSE, wxT("clipboard not open") ); wxCHECK_MSG( m_open, FALSE, wxT("clipboard not open") );
/* is data supported by clipboard ? */ /* get formats from wxDataObjects */
wxDataFormat *array = new wxDataFormat[ data.GetFormatCount() ];
data.GetAllFormats( array );
if (!IsSupported( data->GetFormat() )) return FALSE; for (size_t i = 0; i < data.GetFormatCount(); i++)
{
/* is data supported by clipboard ? */
if (!IsSupported( array[i] ))
continue;
/* store pointer to data object to be filled up by callbacks */ /* store pointer to data object to be filled up by callbacks */
m_receivedData = &data;
m_receivedData = data; /* store requested format to be asked for by callbacks */
m_targetRequested = array[i];
/* store requested format to be asked for by callbacks */
m_targetRequested = data->GetFormat();
wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") ); wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") );
/* start query */ /* start query */
m_formatSupported = FALSE;
m_formatSupported = FALSE;
/* ask for clipboard contents. this will set /* ask for clipboard contents. this will set
m_formatSupported to TRUE if m_targetRequested m_formatSupported to TRUE if m_targetRequested
is supported. is supported.
also, we have to wait for the "answer" from the also, we have to wait for the "answer" from the
clipboard owner which is an asynchronous process. clipboard owner which is an asynchronous process.
therefore we set m_waiting = TRUE here and wait therefore we set m_waiting = TRUE here and wait
until the callback "targets_selection_received" until the callback "targets_selection_received"
sets it to FALSE */ sets it to FALSE */
m_waiting = TRUE; m_waiting = TRUE;
gtk_selection_convert( m_clipboardWidget, gtk_selection_convert( m_clipboardWidget,
m_usePrimary ? GDK_SELECTION_PRIMARY : g_clipboardAtom, m_usePrimary ? GDK_SELECTION_PRIMARY : g_clipboardAtom,
m_targetRequested, m_targetRequested,
GDK_CURRENT_TIME ); GDK_CURRENT_TIME );
while (m_waiting) gtk_main_iteration(); while (m_waiting) gtk_main_iteration();
/* this is a true error as we checked for the presence of such data before */ /* this is a true error as we checked for the presence of such data before */
wxCHECK_MSG( m_formatSupported, FALSE, wxT("error retrieving data from clipboard") );
wxCHECK_MSG( m_formatSupported, FALSE, wxT("error retrieving data from clipboard") );
/* return success */
delete[] array;
return TRUE;
}
return TRUE; /* return failure */
delete[] array;
return FALSE;
} }
#endif #endif

View File

@ -128,25 +128,19 @@ void wxDataFormat::PrepareFormats()
// wxDataObject // wxDataObject
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
IMPLEMENT_ABSTRACT_CLASS( wxDataObject, wxObject )
wxDataObject::wxDataObject() wxDataObject::wxDataObject()
{ {
} }
wxDataObject::~wxDataObject() bool wxDataObject::IsSupportedFormat(const wxDataFormat& format, Direction dir) const
{ {
} size_t nFormatCount = GetFormatCount(dir);
bool wxDataObject::IsSupportedFormat(const wxDataFormat& format) const
{
size_t nFormatCount = GetFormatCount();
if ( nFormatCount == 1 ) { if ( nFormatCount == 1 ) {
return format == GetPreferredFormat(); return format == GetPreferredFormat();
} }
else { else {
wxDataFormat *formats = new wxDataFormat[nFormatCount]; wxDataFormat *formats = new wxDataFormat[nFormatCount];
GetAllFormats(formats); GetAllFormats(formats,dir);
size_t n; size_t n;
for ( n = 0; n < nFormatCount; n++ ) { for ( n = 0; n < nFormatCount; n++ ) {
@ -167,7 +161,14 @@ bool wxDataObject::IsSupportedFormat(const wxDataFormat& format) const
bool wxFileDataObject::GetDataHere(void *buf) const bool wxFileDataObject::GetDataHere(void *buf) const
{ {
const wxString& filenames = GetFilenames(); wxString filenames;
for (size_t i = 0; i < m_filenames.GetCount(); i++)
{
filenames += m_filenames[i];
filenames += (wxChar) 0;
}
memcpy( buf, filenames.mbc_str(), filenames.Len() + 1 ); memcpy( buf, filenames.mbc_str(), filenames.Len() + 1 );
return TRUE; return TRUE;
@ -175,16 +176,33 @@ bool wxFileDataObject::GetDataHere(void *buf) const
size_t wxFileDataObject::GetDataSize() const size_t wxFileDataObject::GetDataSize() const
{ {
return GetFilenames().Len() + 1; size_t res = 0;
for (size_t i = 0; i < m_filenames.GetCount(); i++)
{
res += m_filenames[i].Len();
res += 1;
}
return res + 1;
} }
bool wxFileDataObject::SetData(const void *buf) bool wxFileDataObject::SetData(size_t WXUNUSED(size), const void *buf)
{ {
SetFilenames((const wxChar *)buf); /* TODO */
wxString file( (const char *)buf ); /* char, not wxChar */
AddFile( file );
return TRUE; return TRUE;
} }
void wxFileDataObject::AddFile( const wxString &filename )
{
m_filenames.Add( filename );
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxBitmapDataObject // wxBitmapDataObject
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -248,6 +266,8 @@ bool wxBitmapDataObject::SetData(size_t size, const void *buf)
} }
m_bitmap = image.ConvertToBitmap(); m_bitmap = image.ConvertToBitmap();
return m_bitmap.Ok();
} }
void wxBitmapDataObject::DoConvertToPng() void wxBitmapDataObject::DoConvertToPng()
@ -268,51 +288,4 @@ void wxBitmapDataObject::DoConvertToPng()
handler.SaveFile( &image, mstream ); handler.SaveFile( &image, mstream );
} }
// ----------------------------------------------------------------------------
// wxPrivateDataObject
// ----------------------------------------------------------------------------
IMPLEMENT_CLASS( wxPrivateDataObject, wxDataObject )
void wxPrivateDataObject::Free()
{
if ( m_data )
free(m_data);
}
wxPrivateDataObject::wxPrivateDataObject()
{
wxString id = wxT("application/");
id += wxTheApp->GetAppName();
m_format.SetId( id );
m_size = 0;
m_data = (void *)NULL;
}
void wxPrivateDataObject::SetData( const void *data, size_t size )
{
Free();
m_size = size;
m_data = malloc(size);
memcpy( m_data, data, size );
}
void wxPrivateDataObject::WriteData( void *dest ) const
{
WriteData( m_data, dest );
}
size_t wxPrivateDataObject::GetSize() const
{
return m_size;
}
void wxPrivateDataObject::WriteData( const void *data, void *dest ) const
{
memcpy( dest, data, GetSize() );
}

View File

@ -349,35 +349,27 @@ static void target_drag_data_received( GtkWidget *WXUNUSED(widget),
// wxDropTarget // wxDropTarget
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
wxDropTarget::wxDropTarget( wxDataObject *data ) wxDropTarget::wxDropTarget( wxDataObject *data )
: wxDropTargetBase( data )
{ {
m_firstMotion = TRUE; m_firstMotion = TRUE;
m_dragContext = (GdkDragContext*) NULL; m_dragContext = (GdkDragContext*) NULL;
m_dragWidget = (GtkWidget*) NULL; m_dragWidget = (GtkWidget*) NULL;
m_dragData = (GtkSelectionData*) NULL; m_dragData = (GtkSelectionData*) NULL;
m_dragTime = 0; m_dragTime = 0;
m_data = data;
}
wxDropTarget::~wxDropTarget()
{
} }
bool wxDropTarget::OnEnter( int WXUNUSED(x), int WXUNUSED(y) ) bool wxDropTarget::OnEnter( int WXUNUSED(x), int WXUNUSED(y) )
{ {
if (!m_data) if (!m_dataObject)
return FALSE; return FALSE;
return (GetMatchingPair() != (GdkAtom) 0); return (GetMatchingPair() != (GdkAtom) 0);
} }
void wxDropTarget::OnLeave()
{
}
bool wxDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) ) bool wxDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) )
{ {
if (!m_data) if (!m_dataObject)
return FALSE; return FALSE;
return (GetMatchingPair() != (GdkAtom) 0); return (GetMatchingPair() != (GdkAtom) 0);
@ -385,7 +377,7 @@ bool wxDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) )
bool wxDropTarget::OnDrop( int WXUNUSED(x), int WXUNUSED(y) ) bool wxDropTarget::OnDrop( int WXUNUSED(x), int WXUNUSED(y) )
{ {
if (!m_data) if (!m_dataObject)
return FALSE; return FALSE;
return (GetMatchingPair() != (GdkAtom) 0); return (GetMatchingPair() != (GdkAtom) 0);
@ -393,7 +385,7 @@ bool wxDropTarget::OnDrop( int WXUNUSED(x), int WXUNUSED(y) )
bool wxDropTarget::OnData( int WXUNUSED(x), int WXUNUSED(y) ) bool wxDropTarget::OnData( int WXUNUSED(x), int WXUNUSED(y) )
{ {
if (!m_data) if (!m_dataObject)
return FALSE; return FALSE;
if (GetMatchingPair() == (GdkAtom) 0) if (GetMatchingPair() == (GdkAtom) 0)
@ -404,7 +396,7 @@ bool wxDropTarget::OnData( int WXUNUSED(x), int WXUNUSED(y) )
GdkAtom wxDropTarget::GetMatchingPair() GdkAtom wxDropTarget::GetMatchingPair()
{ {
if (!m_data) if (!m_dataObject)
return (GdkAtom) 0; return (GdkAtom) 0;
if (!m_dragContext) if (!m_dragContext)
@ -420,7 +412,7 @@ GdkAtom wxDropTarget::GetMatchingPair()
char *name = gdk_atom_name( formatAtom ); char *name = gdk_atom_name( formatAtom );
if (name) wxLogDebug( "Drop target: drag has format: %s", name ); if (name) wxLogDebug( "Drop target: drag has format: %s", name );
#endif #endif
if (m_data->IsSupportedFormat( format )) if (m_dataObject->IsSupportedFormat( format ))
return formatAtom; return formatAtom;
child = child->next; child = child->next;
@ -434,25 +426,25 @@ bool wxDropTarget::GetData()
if (!m_dragData) if (!m_dragData)
return FALSE; return FALSE;
if (!m_data) if (!m_dataObject)
return FALSE; return FALSE;
wxDataFormat dragFormat( m_dragData->target ); wxDataFormat dragFormat( m_dragData->target );
if (!m_data->IsSupportedFormat( dragFormat )) if (!m_dataObject->IsSupportedFormat( dragFormat ))
return FALSE; return FALSE;
if (dragFormat.GetType() == wxDF_TEXT) if (dragFormat.GetType() == wxDF_TEXT)
{ {
wxTextDataObject *text_object = (wxTextDataObject*)m_data; wxTextDataObject *text_object = (wxTextDataObject*)m_dataObject;
text_object->SetText( (const char*)m_dragData->data ); text_object->SetText( (const char*)m_dragData->data );
return TRUE; return TRUE;
} }
if (dragFormat.GetType() == wxDF_FILENAME) if (dragFormat.GetType() == wxDF_FILENAME)
{ {
wxFileDataObject *file_object = (wxFileDataObject*)m_data; wxFileDataObject *file_object = (wxFileDataObject*)m_dataObject;
file_object->SetFiles( (const char*)m_dragData->data ); file_object->SetData( 0, (const char*)m_dragData->data );
return TRUE; return TRUE;
} }
@ -633,7 +625,6 @@ wxDropSource::wxDropSource( wxWindow *win, const wxIcon &go, const wxIcon &stop
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_retValue = wxDragCancel; m_retValue = wxDragCancel;
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY ); m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
@ -649,14 +640,14 @@ wxDropSource::wxDropSource( wxDataObject& data, wxWindow *win,
const wxIcon &go, const wxIcon &stop ) const wxIcon &go, const wxIcon &stop )
{ {
m_waiting = TRUE; m_waiting = TRUE;
SetData( data );
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_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY ); m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
m_goaheadCursor = wxCursor( wxCURSOR_HAND ); m_goaheadCursor = wxCursor( wxCURSOR_HAND );
@ -666,19 +657,8 @@ wxDropSource::wxDropSource( wxDataObject& data, wxWindow *win,
if (wxNullIcon == stop) m_stopIcon = wxIcon( gv_xpm ); if (wxNullIcon == stop) m_stopIcon = wxIcon( gv_xpm );
} }
void wxDropSource::SetData( wxDataObject& data )
{
if (m_data)
delete m_data;
m_data = &data;
}
wxDropSource::~wxDropSource() wxDropSource::~wxDropSource()
{ {
if (m_data)
// delete m_data;
g_blockEventsOnDrag = FALSE; g_blockEventsOnDrag = FALSE;
} }
@ -701,7 +681,7 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
GtkTargetList *target_list = gtk_target_list_new( (GtkTargetEntry*) NULL, 0 ); GtkTargetList *target_list = gtk_target_list_new( (GtkTargetEntry*) NULL, 0 );
wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ]; wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ];
m_data->GetAllFormats( array, TRUE ); m_data->GetAllFormats( array );
for (size_t i = 0; i < m_data->GetFormatCount(); i++) for (size_t i = 0; i < m_data->GetFormatCount(); i++)
{ {
GdkAtom atom = array[i]; GdkAtom atom = array[i];

View File

@ -17,6 +17,7 @@
#include "wx/dataobj.h" #include "wx/dataobj.h"
#include "wx/utils.h" #include "wx/utils.h"
#include "wx/log.h"
#include "glib.h" #include "glib.h"
#include "gdk/gdk.h" #include "gdk/gdk.h"
@ -148,9 +149,11 @@ selection_received( GtkWidget *WXUNUSED(widget),
clipboard->m_waiting = FALSE; clipboard->m_waiting = FALSE;
return; return;
} }
wxDataFormat format( selection_data->target );
/* make sure we got the data in the correct format */ /* make sure we got the data in the correct format */
if (data_object->GetFormat() != selection_data->target) if (!data_object->IsSupportedFormat( format ) )
{ {
clipboard->m_waiting = FALSE; clipboard->m_waiting = FALSE;
return; return;
@ -159,7 +162,7 @@ selection_received( GtkWidget *WXUNUSED(widget),
/* make sure we got the data in the correct form (selection type). /* make sure we got the data in the correct form (selection type).
if so, copy data to target object */ if so, copy data to target object */
switch (data_object->GetFormat().GetType()) switch (format.GetType())
{ {
case wxDF_TEXT: case wxDF_TEXT:
{ {
@ -188,7 +191,7 @@ selection_received( GtkWidget *WXUNUSED(widget),
wxBitmapDataObject *bitmap_object = (wxBitmapDataObject *) data_object; wxBitmapDataObject *bitmap_object = (wxBitmapDataObject *) data_object;
bitmap_object->SetPngData( (const void*) selection_data->data, (size_t) selection_data->length ); bitmap_object->SetData( (size_t) selection_data->length, (const void*) selection_data->data );
break; break;
} }
@ -201,9 +204,7 @@ selection_received( GtkWidget *WXUNUSED(widget),
return; return;
} }
wxPrivateDataObject *private_object = (wxPrivateDataObject *) data_object; data_object->SetData( format, (size_t) selection_data->length, (const char*) selection_data->data );
private_object->SetData( (const char*) selection_data->data, (size_t) selection_data->length );
break; break;
} }
@ -271,9 +272,11 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data
wxDataObject *data = wxTheClipboard->m_data; wxDataObject *data = wxTheClipboard->m_data;
if (!data->IsSupportedFormat( selection_data->target )) return; wxDataFormat format( selection_data->target );
if (!data->IsSupportedFormat( format )) return;
if (data->GetFormat().GetType() == wxDF_TEXT) if (format.GetType() == wxDF_TEXT)
{ {
wxTextDataObject *text_object = (wxTextDataObject*) data; wxTextDataObject *text_object = (wxTextDataObject*) data;
wxString text( text_object->GetText() ); wxString text( text_object->GetText() );
@ -295,23 +298,23 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data
return; return;
} }
if (data->GetFormat().GetType() == wxDF_BITMAP) if (format.GetType() == wxDF_BITMAP)
{ {
wxBitmapDataObject *bitmap_object = (wxBitmapDataObject*) data; wxBitmapDataObject *bitmap_object = (wxBitmapDataObject*) data;
if (bitmap_object->GetDataSize(wxDF_BITMAP) == 0) return; if (bitmap_object->GetDataSize() == 0) return;
gtk_selection_data_set( gtk_selection_data_set(
selection_data, selection_data,
GDK_SELECTION_TYPE_STRING, GDK_SELECTION_TYPE_STRING,
8*sizeof(gchar), 8*sizeof(gchar),
(unsigned char*) bitmap_object->GetData(), (unsigned char*) bitmap_object->GetPngData(),
(int) bitmap_object->GetDataSize(wxDF_BITMAP) ); (int) bitmap_object->GetDataSize() );
return; return;
} }
int size = data->GetDataSize( selection_data->target ); int size = data->GetDataSize( format );
if (size == 0) return; if (size == 0) return;
@ -456,54 +459,46 @@ bool wxClipboard::AddData( wxDataObject *data )
wxCHECK_MSG( data, FALSE, wxT("data is invalid") ); wxCHECK_MSG( data, FALSE, wxT("data is invalid") );
// we can only store one wxDataObject /* we can only store one wxDataObject */
Clear(); Clear();
m_data = data; m_data = data;
/* get native format id of new data object */
GdkAtom format = data->GetFormat();
wxCHECK_MSG( format, FALSE, wxT("data has invalid format") );
/* This should happen automatically, but to be on the safe side */ /* This should happen automatically, but to be on the safe side */
m_ownsClipboard = FALSE; m_ownsClipboard = FALSE;
m_ownsPrimarySelection = FALSE; m_ownsPrimarySelection = FALSE;
/* Add handlers if someone requests data */ /* get formats from wxDataObjects */
wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ];
m_data->GetAllFormats( array );
for (size_t i = 0; i < m_data->GetFormatCount(); i++)
{
GdkAtom atom = array[i];
wxLogDebug( wxT("Clipboard Supported atom %s"), gdk_atom_name( atom ) );
#if (GTK_MINOR_VERSION > 0) /* Add handlers if someone requests data. We currently always
offer data to the clipboard and the primary selection. Maybe
gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget), we should make that depend on the usePrimary flag */
gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget),
GDK_SELECTION_PRIMARY, GDK_SELECTION_PRIMARY,
format, atom,
0 ); /* what is info ? */ 0 ); /* what is info ? */
gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget), gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget),
g_clipboardAtom, g_clipboardAtom,
format, atom,
0 ); /* what is info ? */ 0 ); /* what is info ? */
}
delete[] array;
gtk_signal_connect( GTK_OBJECT(m_clipboardWidget), gtk_signal_connect( GTK_OBJECT(m_clipboardWidget),
"selection_get", "selection_get",
GTK_SIGNAL_FUNC(selection_handler), GTK_SIGNAL_FUNC(selection_handler),
(gpointer) NULL ); (gpointer) NULL );
#else
gtk_selection_add_handler( m_clipboardWidget,
g_clipboardAtom,
format,
selection_handler,
(gpointer) NULL );
gtk_selection_add_handler( m_clipboardWidget,
GDK_SELECTION_PRIMARY,
format,
selection_handler,
(gpointer) NULL );
#endif
#if wxUSE_THREADS #if wxUSE_THREADS
/* disable GUI threads */ /* disable GUI threads */
wxapp_uninstall_thread_wakeup(); wxapp_uninstall_thread_wakeup();
@ -585,47 +580,56 @@ bool wxClipboard::GetData( wxDataObject& data )
{ {
wxCHECK_MSG( m_open, FALSE, wxT("clipboard not open") ); wxCHECK_MSG( m_open, FALSE, wxT("clipboard not open") );
/* is data supported by clipboard ? */ /* get formats from wxDataObjects */
wxDataFormat *array = new wxDataFormat[ data.GetFormatCount() ];
data.GetAllFormats( array );
if (!IsSupported( data->GetFormat() )) return FALSE; for (size_t i = 0; i < data.GetFormatCount(); i++)
{
/* is data supported by clipboard ? */
if (!IsSupported( array[i] ))
continue;
/* store pointer to data object to be filled up by callbacks */ /* store pointer to data object to be filled up by callbacks */
m_receivedData = &data;
m_receivedData = data; /* store requested format to be asked for by callbacks */
m_targetRequested = array[i];
/* store requested format to be asked for by callbacks */
m_targetRequested = data->GetFormat();
wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") ); wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") );
/* start query */ /* start query */
m_formatSupported = FALSE;
m_formatSupported = FALSE;
/* ask for clipboard contents. this will set /* ask for clipboard contents. this will set
m_formatSupported to TRUE if m_targetRequested m_formatSupported to TRUE if m_targetRequested
is supported. is supported.
also, we have to wait for the "answer" from the also, we have to wait for the "answer" from the
clipboard owner which is an asynchronous process. clipboard owner which is an asynchronous process.
therefore we set m_waiting = TRUE here and wait therefore we set m_waiting = TRUE here and wait
until the callback "targets_selection_received" until the callback "targets_selection_received"
sets it to FALSE */ sets it to FALSE */
m_waiting = TRUE; m_waiting = TRUE;
gtk_selection_convert( m_clipboardWidget, gtk_selection_convert( m_clipboardWidget,
m_usePrimary ? GDK_SELECTION_PRIMARY : g_clipboardAtom, m_usePrimary ? GDK_SELECTION_PRIMARY : g_clipboardAtom,
m_targetRequested, m_targetRequested,
GDK_CURRENT_TIME ); GDK_CURRENT_TIME );
while (m_waiting) gtk_main_iteration(); while (m_waiting) gtk_main_iteration();
/* this is a true error as we checked for the presence of such data before */ /* this is a true error as we checked for the presence of such data before */
wxCHECK_MSG( m_formatSupported, FALSE, wxT("error retrieving data from clipboard") );
wxCHECK_MSG( m_formatSupported, FALSE, wxT("error retrieving data from clipboard") );
/* return success */
delete[] array;
return TRUE;
}
return TRUE; /* return failure */
delete[] array;
return FALSE;
} }
#endif #endif

View File

@ -128,25 +128,19 @@ void wxDataFormat::PrepareFormats()
// wxDataObject // wxDataObject
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
IMPLEMENT_ABSTRACT_CLASS( wxDataObject, wxObject )
wxDataObject::wxDataObject() wxDataObject::wxDataObject()
{ {
} }
wxDataObject::~wxDataObject() bool wxDataObject::IsSupportedFormat(const wxDataFormat& format, Direction dir) const
{ {
} size_t nFormatCount = GetFormatCount(dir);
bool wxDataObject::IsSupportedFormat(const wxDataFormat& format) const
{
size_t nFormatCount = GetFormatCount();
if ( nFormatCount == 1 ) { if ( nFormatCount == 1 ) {
return format == GetPreferredFormat(); return format == GetPreferredFormat();
} }
else { else {
wxDataFormat *formats = new wxDataFormat[nFormatCount]; wxDataFormat *formats = new wxDataFormat[nFormatCount];
GetAllFormats(formats); GetAllFormats(formats,dir);
size_t n; size_t n;
for ( n = 0; n < nFormatCount; n++ ) { for ( n = 0; n < nFormatCount; n++ ) {
@ -167,7 +161,14 @@ bool wxDataObject::IsSupportedFormat(const wxDataFormat& format) const
bool wxFileDataObject::GetDataHere(void *buf) const bool wxFileDataObject::GetDataHere(void *buf) const
{ {
const wxString& filenames = GetFilenames(); wxString filenames;
for (size_t i = 0; i < m_filenames.GetCount(); i++)
{
filenames += m_filenames[i];
filenames += (wxChar) 0;
}
memcpy( buf, filenames.mbc_str(), filenames.Len() + 1 ); memcpy( buf, filenames.mbc_str(), filenames.Len() + 1 );
return TRUE; return TRUE;
@ -175,16 +176,33 @@ bool wxFileDataObject::GetDataHere(void *buf) const
size_t wxFileDataObject::GetDataSize() const size_t wxFileDataObject::GetDataSize() const
{ {
return GetFilenames().Len() + 1; size_t res = 0;
for (size_t i = 0; i < m_filenames.GetCount(); i++)
{
res += m_filenames[i].Len();
res += 1;
}
return res + 1;
} }
bool wxFileDataObject::SetData(const void *buf) bool wxFileDataObject::SetData(size_t WXUNUSED(size), const void *buf)
{ {
SetFilenames((const wxChar *)buf); /* TODO */
wxString file( (const char *)buf ); /* char, not wxChar */
AddFile( file );
return TRUE; return TRUE;
} }
void wxFileDataObject::AddFile( const wxString &filename )
{
m_filenames.Add( filename );
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxBitmapDataObject // wxBitmapDataObject
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -248,6 +266,8 @@ bool wxBitmapDataObject::SetData(size_t size, const void *buf)
} }
m_bitmap = image.ConvertToBitmap(); m_bitmap = image.ConvertToBitmap();
return m_bitmap.Ok();
} }
void wxBitmapDataObject::DoConvertToPng() void wxBitmapDataObject::DoConvertToPng()
@ -268,51 +288,4 @@ void wxBitmapDataObject::DoConvertToPng()
handler.SaveFile( &image, mstream ); handler.SaveFile( &image, mstream );
} }
// ----------------------------------------------------------------------------
// wxPrivateDataObject
// ----------------------------------------------------------------------------
IMPLEMENT_CLASS( wxPrivateDataObject, wxDataObject )
void wxPrivateDataObject::Free()
{
if ( m_data )
free(m_data);
}
wxPrivateDataObject::wxPrivateDataObject()
{
wxString id = wxT("application/");
id += wxTheApp->GetAppName();
m_format.SetId( id );
m_size = 0;
m_data = (void *)NULL;
}
void wxPrivateDataObject::SetData( const void *data, size_t size )
{
Free();
m_size = size;
m_data = malloc(size);
memcpy( m_data, data, size );
}
void wxPrivateDataObject::WriteData( void *dest ) const
{
WriteData( m_data, dest );
}
size_t wxPrivateDataObject::GetSize() const
{
return m_size;
}
void wxPrivateDataObject::WriteData( const void *data, void *dest ) const
{
memcpy( dest, data, GetSize() );
}

View File

@ -349,35 +349,27 @@ static void target_drag_data_received( GtkWidget *WXUNUSED(widget),
// wxDropTarget // wxDropTarget
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
wxDropTarget::wxDropTarget( wxDataObject *data ) wxDropTarget::wxDropTarget( wxDataObject *data )
: wxDropTargetBase( data )
{ {
m_firstMotion = TRUE; m_firstMotion = TRUE;
m_dragContext = (GdkDragContext*) NULL; m_dragContext = (GdkDragContext*) NULL;
m_dragWidget = (GtkWidget*) NULL; m_dragWidget = (GtkWidget*) NULL;
m_dragData = (GtkSelectionData*) NULL; m_dragData = (GtkSelectionData*) NULL;
m_dragTime = 0; m_dragTime = 0;
m_data = data;
}
wxDropTarget::~wxDropTarget()
{
} }
bool wxDropTarget::OnEnter( int WXUNUSED(x), int WXUNUSED(y) ) bool wxDropTarget::OnEnter( int WXUNUSED(x), int WXUNUSED(y) )
{ {
if (!m_data) if (!m_dataObject)
return FALSE; return FALSE;
return (GetMatchingPair() != (GdkAtom) 0); return (GetMatchingPair() != (GdkAtom) 0);
} }
void wxDropTarget::OnLeave()
{
}
bool wxDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) ) bool wxDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) )
{ {
if (!m_data) if (!m_dataObject)
return FALSE; return FALSE;
return (GetMatchingPair() != (GdkAtom) 0); return (GetMatchingPair() != (GdkAtom) 0);
@ -385,7 +377,7 @@ bool wxDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) )
bool wxDropTarget::OnDrop( int WXUNUSED(x), int WXUNUSED(y) ) bool wxDropTarget::OnDrop( int WXUNUSED(x), int WXUNUSED(y) )
{ {
if (!m_data) if (!m_dataObject)
return FALSE; return FALSE;
return (GetMatchingPair() != (GdkAtom) 0); return (GetMatchingPair() != (GdkAtom) 0);
@ -393,7 +385,7 @@ bool wxDropTarget::OnDrop( int WXUNUSED(x), int WXUNUSED(y) )
bool wxDropTarget::OnData( int WXUNUSED(x), int WXUNUSED(y) ) bool wxDropTarget::OnData( int WXUNUSED(x), int WXUNUSED(y) )
{ {
if (!m_data) if (!m_dataObject)
return FALSE; return FALSE;
if (GetMatchingPair() == (GdkAtom) 0) if (GetMatchingPair() == (GdkAtom) 0)
@ -404,7 +396,7 @@ bool wxDropTarget::OnData( int WXUNUSED(x), int WXUNUSED(y) )
GdkAtom wxDropTarget::GetMatchingPair() GdkAtom wxDropTarget::GetMatchingPair()
{ {
if (!m_data) if (!m_dataObject)
return (GdkAtom) 0; return (GdkAtom) 0;
if (!m_dragContext) if (!m_dragContext)
@ -420,7 +412,7 @@ GdkAtom wxDropTarget::GetMatchingPair()
char *name = gdk_atom_name( formatAtom ); char *name = gdk_atom_name( formatAtom );
if (name) wxLogDebug( "Drop target: drag has format: %s", name ); if (name) wxLogDebug( "Drop target: drag has format: %s", name );
#endif #endif
if (m_data->IsSupportedFormat( format )) if (m_dataObject->IsSupportedFormat( format ))
return formatAtom; return formatAtom;
child = child->next; child = child->next;
@ -434,25 +426,25 @@ bool wxDropTarget::GetData()
if (!m_dragData) if (!m_dragData)
return FALSE; return FALSE;
if (!m_data) if (!m_dataObject)
return FALSE; return FALSE;
wxDataFormat dragFormat( m_dragData->target ); wxDataFormat dragFormat( m_dragData->target );
if (!m_data->IsSupportedFormat( dragFormat )) if (!m_dataObject->IsSupportedFormat( dragFormat ))
return FALSE; return FALSE;
if (dragFormat.GetType() == wxDF_TEXT) if (dragFormat.GetType() == wxDF_TEXT)
{ {
wxTextDataObject *text_object = (wxTextDataObject*)m_data; wxTextDataObject *text_object = (wxTextDataObject*)m_dataObject;
text_object->SetText( (const char*)m_dragData->data ); text_object->SetText( (const char*)m_dragData->data );
return TRUE; return TRUE;
} }
if (dragFormat.GetType() == wxDF_FILENAME) if (dragFormat.GetType() == wxDF_FILENAME)
{ {
wxFileDataObject *file_object = (wxFileDataObject*)m_data; wxFileDataObject *file_object = (wxFileDataObject*)m_dataObject;
file_object->SetFiles( (const char*)m_dragData->data ); file_object->SetData( 0, (const char*)m_dragData->data );
return TRUE; return TRUE;
} }
@ -633,7 +625,6 @@ wxDropSource::wxDropSource( wxWindow *win, const wxIcon &go, const wxIcon &stop
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_retValue = wxDragCancel; m_retValue = wxDragCancel;
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY ); m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
@ -649,14 +640,14 @@ wxDropSource::wxDropSource( wxDataObject& data, wxWindow *win,
const wxIcon &go, const wxIcon &stop ) const wxIcon &go, const wxIcon &stop )
{ {
m_waiting = TRUE; m_waiting = TRUE;
SetData( data );
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_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY ); m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
m_goaheadCursor = wxCursor( wxCURSOR_HAND ); m_goaheadCursor = wxCursor( wxCURSOR_HAND );
@ -666,19 +657,8 @@ wxDropSource::wxDropSource( wxDataObject& data, wxWindow *win,
if (wxNullIcon == stop) m_stopIcon = wxIcon( gv_xpm ); if (wxNullIcon == stop) m_stopIcon = wxIcon( gv_xpm );
} }
void wxDropSource::SetData( wxDataObject& data )
{
if (m_data)
delete m_data;
m_data = &data;
}
wxDropSource::~wxDropSource() wxDropSource::~wxDropSource()
{ {
if (m_data)
// delete m_data;
g_blockEventsOnDrag = FALSE; g_blockEventsOnDrag = FALSE;
} }
@ -701,7 +681,7 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
GtkTargetList *target_list = gtk_target_list_new( (GtkTargetEntry*) NULL, 0 ); GtkTargetList *target_list = gtk_target_list_new( (GtkTargetEntry*) NULL, 0 );
wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ]; wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ];
m_data->GetAllFormats( array, TRUE ); m_data->GetAllFormats( array );
for (size_t i = 0; i < m_data->GetFormatCount(); i++) for (size_t i = 0; i < m_data->GetFormatCount(); i++)
{ {
GdkAtom atom = array[i]; GdkAtom atom = array[i];