New DnD and Clipboard code

Rearranged wxApp to do the same in the
    same order upon program start-up on
    wxGTK and wxMSW
  ODBC tweaks
  exchanged wxDataFormat for wxIPCFormat


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1427 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
1999-01-19 16:33:16 +00:00
parent c75e66953f
commit 0d2a2b601b
30 changed files with 2042 additions and 940 deletions

View File

@@ -61,15 +61,16 @@ class wxApp: public wxEvtHandler
static void SetInitializerFunction(wxAppInitializerFunction fn) { m_appInitFn = fn; }
static wxAppInitializerFunction GetInitializerFunction() { return m_appInitFn; }
/* this may have to be overwritten when special, non-default visuals have
to be set. it is also platform dependent as only X knows about displays
and visuals. */
virtual bool InitVisual();
virtual bool OnInit();
/* override for altering the way wxGTK intializes the GUI (palette/visual/colorcube).
* under wxMSW, OnInitGui() does nothing by default. when overriding this method,
* the code in it is likely to be platform dependent, otherwise use OnInit(). */
virtual bool OnInitGui();
virtual int OnRun();
virtual int OnExit();
/* override to create top level frame, display splash screen etc. */
virtual bool OnInit() { return FALSE; }
virtual int OnRun() { return MainLoop(); }
virtual int OnExit() { return 0; }
wxWindow *GetTopWindow();
void SetTopWindow( wxWindow *win );
@@ -105,14 +106,15 @@ class wxApp: public wxEvtHandler
void SetPrintMode(int WXUNUSED(mode) ) {};
int GetPrintMode() const { return wxPRINT_POSTSCRIPT; };
// override this function to create default log target of arbitrary
// user-defined classv (default implementation creates a wxLogGui object)
/* override this function to create default log target of arbitrary
* user-defined classv (default implementation creates a wxLogGui object) */
virtual wxLog *CreateLogTarget();
// GTK implementation
/* GTK implementation */
static void CommonInit();
static void CommonCleanUp();
static bool Initialize();
static bool InitialzeVisual();
static void CleanUp();
bool ProcessIdle();
void DeletePendingObjects();

View File

@@ -51,35 +51,29 @@ public:
wxClipboard();
~wxClipboard();
// open the clipboard before SetData() and GetData()
/* open the clipboard before SetData() and GetData() */
virtual bool Open();
// close the clipboard after SetData() and GetData()
/* close the clipboard after SetData() and GetData() */
virtual void Close();
// can be called several times
virtual bool SetData( wxDataObject *data );
/* set the clipboard data. the clipboard will delete the broker later */
virtual bool SetData( wxDataBroker *data );
// format available on the clipboard ?
// supply ID if private format, the same as wxPrivateDataObject::SetId()
virtual bool IsSupportedFormat( wxDataFormat format, const wxString &id = "" );
// fill data with data on the clipboard (if available)
/* fill data with data on the clipboard (if available) */
virtual bool GetData( wxDataObject *data );
// clears wxTheClipboard and the system's clipboard if possible
/* clears wxTheClipboard and the system's clipboard if possible */
virtual void Clear();
// implementation
GdkAtom GetTargetAtom( wxDataFormat format, const wxString &id = "" );
/* implementation */
bool m_open;
bool m_ownsClipboard;
bool m_ownsPrimarySelection;
wxList m_dataObjects;
wxDataBroker *m_dataBroker;
GtkWidget *m_clipboardWidget;
bool m_formatSupported;

View File

@@ -23,6 +23,8 @@
// classes
//-------------------------------------------------------------------------
class wxDataFormat;
class wxDataBroker;
class wxDataObject;
class wxTextDataObject;
class wxBitmapDataObject;
@@ -30,28 +32,133 @@ class wxPrivateDataObject;
class wxFileDataObject;
//-------------------------------------------------------------------------
// wxDataObject
// wxDataFormat
//-------------------------------------------------------------------------
class wxDataObject: public wxObject
enum wxDataType
{
DECLARE_ABSTRACT_CLASS( wxDataObject )
wxDF_INVALID = 0,
wxDF_TEXT = 1, /* CF_TEXT */
wxDF_BITMAP = 2, /* CF_BITMAP */
wxDF_METAFILE = 3, /* CF_METAFILEPICT */
wxDF_SYLK = 4,
wxDF_DIF = 5,
wxDF_TIFF = 6,
wxDF_OEMTEXT = 7, /* CF_OEMTEXT */
wxDF_DIB = 8, /* CF_DIB */
wxDF_PALETTE = 9,
wxDF_PENDATA = 10,
wxDF_RIFF = 11,
wxDF_WAVE = 12,
wxDF_UNICODETEXT = 13,
wxDF_ENHMETAFILE = 14,
wxDF_FILENAME = 15, /* CF_HDROP */
wxDF_LOCALE = 16,
wxDF_PRIVATE = 20
};
class wxDataFormat : public wxObject
{
DECLARE_CLASS( wxDataFormat )
public:
wxDataFormat( wxDataType type );
wxDataFormat( const wxString &id );
wxDataFormat( wxDataFormat &format );
wxDataFormat( const GdkAtom atom );
int GetType() const;
wxString GetId() const;
void SetId( const wxString &id );
GdkAtom GetAtom();
private:
int m_type;
wxString m_id;
bool m_hasAtom;
GdkAtom m_atom;
};
//-------------------------------------------------------------------------
// wxDataBroker handles data and ormat negotiation for clipboard and DnD
//-------------------------------------------------------------------------
class wxDataBroker : public wxObject
{
DECLARE_CLASS( wxDataBroker )
public:
wxDataObject() {}
~wxDataObject() {}
/* constructor */
wxDataBroker();
/* add data object */
void Add( wxDataObject *dataObject, bool preferred = FALSE );
private:
/* OLE implementation, the methods don't need to be overridden */
/* get number of supported formats */
virtual size_t GetFormatCount() const;
/* return nth supported format */
virtual wxDataFormat &GetNthFormat( size_t nth ) const;
/* return preferrd/best supported format */
virtual wxDataFormat &GetPreferredFormat() const;
/* search through m_dataObjects, return TRUE if found */
virtual bool IsSupportedFormat( wxDataFormat &format ) const;
/* search through m_dataObjects and call child's GetSize() */
virtual size_t GetSize( wxDataFormat& format ) const;
/* search through m_dataObjects and call child's WriteData(dest) */
virtual void WriteData( wxDataFormat& format, void *dest ) const;
/* implementation */
virtual wxDataFormat GetFormat() const = 0;
public:
// implementation
GdkAtom m_formatAtom;
wxList m_dataObjects;
size_t m_preferred;
};
// ----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// wxDataObject to be placed in wxDataBroker
//----------------------------------------------------------------------------
class wxDataObject : public wxObject
{
DECLARE_DYNAMIC_CLASS( wxDataObject )
public:
/* constructor */
wxDataObject();
/* destructor */
~wxDataObject();
/* write data to dest */
virtual void WriteData( void *dest ) const = 0;
/* get size of data */
virtual size_t GetSize() const = 0;
/* implementation */
virtual wxDataFormat &GetFormat() const;
wxDataFormat *m_format;
};
//----------------------------------------------------------------------------
// wxTextDataObject is a specialization of wxDataObject for text data
// ----------------------------------------------------------------------------
//----------------------------------------------------------------------------
class wxTextDataObject : public wxDataObject
{
@@ -59,27 +166,38 @@ class wxTextDataObject : public wxDataObject
public:
wxTextDataObject() {}
wxTextDataObject( const wxString& strText )
: m_strText(strText) { }
/* default constructor. call SetText() later or override
WriteData() and GetSize() for working on-demand */
wxTextDataObject();
virtual wxDataFormat GetFormat() const
{ return wxDF_TEXT; }
/* constructor */
wxTextDataObject( const wxString& data );
/* set current text data */
void SetText( const wxString& data );
void SetText( const wxString& strText)
{ m_strText = strText; }
wxString GetText() const
{ return m_strText; }
/* get current text data */
wxString GetText() const;
private:
wxString m_strText;
/* by default calls WriteString() with string set by constructor or
by SetText(). can be overridden for working on-demand */
virtual void WriteData( void *dest ) const;
/* by default, returns length of string as set by constructor or
by SetText(). can be overridden for working on-demand */
virtual size_t GetSize() const;
/* write string to dest */
void WriteString( const wxString &str, void *dest ) const;
/* implementation */
wxString m_data;
};
// ----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// wxFileDataObject is a specialization of wxDataObject for file names
// ----------------------------------------------------------------------------
//----------------------------------------------------------------------------
class wxFileDataObject : public wxDataObject
{
@@ -87,25 +205,30 @@ class wxFileDataObject : public wxDataObject
public:
wxFileDataObject(void) {}
/* default constructor */
wxFileDataObject();
/* add file name to list */
void AddFile( const wxString &file );
/* get all filename as one string. each file name is 0 terminated,
the list is double zero terminated */
wxString GetFiles() const;
/* write list of filenames */
virtual void WriteData( void *dest ) const;
/* return length of list of filenames */
virtual size_t GetSize() const;
virtual wxDataFormat GetFormat() const
{ return wxDF_FILENAME; }
void AddFile( const wxString &file )
{ m_files += file; m_files += (char)0; }
wxString GetFiles() const
{ return m_files; }
private:
/* implementation */
wxString m_files;
};
// ----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// wxBitmapDataObject is a specialization of wxDataObject for bitmaps
// ----------------------------------------------------------------------------
//----------------------------------------------------------------------------
class wxBitmapDataObject : public wxDataObject
{
@@ -113,26 +236,28 @@ class wxBitmapDataObject : public wxDataObject
public:
wxBitmapDataObject(void) {}
/* see wxTextDataObject for explanation */
wxBitmapDataObject();
wxBitmapDataObject( const wxBitmap& bitmap );
wxBitmapDataObject( const wxBitmap& bitmap ) { m_bitmap = bitmap; }
void SetBitmap( const wxBitmap &bitmap );
wxBitmap GetBitmap() const;
virtual wxDataFormat GetFormat() const
{ return wxDF_BITMAP; }
virtual void WriteData( void *dest ) const;
virtual size_t GetSize() const;
void WriteBitmap( const wxBitmap &bitmap, void *dest ) const;
void SetBitmap( const wxBitmap &bitmap )
{ m_bitmap = bitmap; }
wxBitmap GetBitmap() const
{ return m_bitmap; }
private:
// implementation
wxBitmap m_bitmap;
};
// ----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// wxPrivateDataObject is a specialization of wxDataObject for app specific data
// ----------------------------------------------------------------------------
//----------------------------------------------------------------------------
class wxPrivateDataObject : public wxDataObject
{
@@ -140,33 +265,35 @@ class wxPrivateDataObject : public wxDataObject
public:
/* see wxTextDataObject for explanation of functions */
wxPrivateDataObject();
~wxPrivateDataObject();
virtual wxDataFormat GetFormat() const
{ return wxDF_PRIVATE; }
/* 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", an
* image manipulation program would put a wxBitmapDataObject and a
* wxPrivateDataObject to the clipboard - the latter with "image/png". */
// the string ID identifies the format of clipboard or DnD data. a word
// processor would e.g. add a wxTextDataObject and a wxPrivateDataObject
// to the clipboard - the latter with the Id "WXWORD_FORMAT".
void SetId( const wxString& id );
void SetId( const wxString& id )
{ m_id = id; }
wxString GetId() const
{ return m_id; }
/* get id */
wxString GetId() const;
// will make internal copy
/* set data. will make internal copy. */
void SetData( const char *data, size_t size );
size_t GetDataSize() const
{ return m_size; }
/* returns pointer to data */
char* GetData() const;
virtual void WriteData( void *dest ) const;
virtual size_t GetSize() const;
void WriteData( const char *data, void *dest ) const;
char* GetData() const
{ return m_data; }
private:
// implementation
size_t m_size;
char* m_data;
wxString m_id;

View File

@@ -65,12 +65,14 @@ class wxDropTarget: public wxObject
// Override these to indicate what kind of data you support:
virtual size_t GetFormatCount() const = 0;
virtual wxDataFormat GetFormat(size_t n) const = 0;
virtual wxDataFormat &GetFormat(size_t n) const;
// implementation
void RegisterWidget( GtkWidget *widget );
void UnregisterWidget( GtkWidget *widget );
wxDataFormat *m_format;
};
//-------------------------------------------------------------------------
@@ -81,14 +83,13 @@ class wxTextDropTarget: public wxDropTarget
{
public:
wxTextDropTarget() {};
wxTextDropTarget();
virtual bool OnDrop( long x, long y, const void *data, size_t size );
virtual bool OnDropText( long x, long y, const char *psz );
protected:
virtual size_t GetFormatCount() const;
virtual wxDataFormat GetFormat(size_t n) const;
};
//-------------------------------------------------------------------------
@@ -105,10 +106,10 @@ public:
// the string ID identifies the format of clipboard or DnD data. a word
// processor would e.g. add a wxTextDataObject and a wxPrivateDataObject
// to the clipboard - the latter with the Id "WXWORD_FORMAT".
// to the clipboard - the latter with the Id "application/wxword" or
// "image/png".
void SetId( const wxString& id )
{ m_id = id; }
void SetId( const wxString& id );
wxString GetId()
{ return m_id; }
@@ -116,20 +117,19 @@ public:
private:
virtual size_t GetFormatCount() const;
virtual wxDataFormat GetFormat(size_t n) const;
wxString m_id;
};
// ----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// A drop target which accepts files (dragged from File Manager or Explorer)
// ----------------------------------------------------------------------------
//----------------------------------------------------------------------------
class wxFileDropTarget: public wxDropTarget
{
public:
wxFileDropTarget() {};
wxFileDropTarget();
virtual bool OnDrop( long x, long y, const void *data, size_t size );
virtual bool OnDropFiles( long x, long y,
@@ -138,7 +138,6 @@ class wxFileDropTarget: public wxDropTarget
protected:
virtual size_t GetFormatCount() const;
virtual wxDataFormat GetFormat(size_t n) const;
};
//-------------------------------------------------------------------------
@@ -150,7 +149,7 @@ 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
wxDragMove, // the data was successfully moved (MSW only)
wxDragCancel // the operation was cancelled by user (not an error)
};
@@ -158,17 +157,30 @@ class wxDropSource: public wxObject
{
public:
/* constructor. set data later with SetData() */
wxDropSource( wxWindow *win );
wxDropSource( wxDataObject &data, wxWindow *win );
/* constructor for setting one data object */
wxDropSource( wxDataObject *data, wxWindow *win );
/* constructor for setting several data objects via wxDataBroker */
wxDropSource( wxDataBroker *data, wxWindow *win );
~wxDropSource(void);
void SetData( wxDataObject &data );
/* set one dataobject */
void SetData( wxDataBroker *data );
/* set severa dataobjects via wxDataBroker */
void SetData( wxDataObject *data );
/* start drag action */
wxDragResult DoDragDrop( bool bAllowMove = FALSE );
virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; };
/* override to give feedback */
virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; }
// implementation
/* GTK implementation */
void RegisterWindow(void);
void UnregisterWindow(void);
@@ -176,7 +188,7 @@ class wxDropSource: public wxObject
GtkWidget *m_widget;
wxWindow *m_window;
wxDragResult m_retValue;
wxDataObject *m_data;
wxDataBroker *m_data;
wxCursor m_defaultCursor;
wxCursor m_goaheadCursor;