From e2acb9ae1c69c1e37cbe0e46933929f5b1b021ba Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sun, 22 Aug 1999 14:10:50 +0000 Subject: [PATCH] Added wxCountingStream for measuring the size of streamed data Added wxBitmapObject for putting it on the clipboard git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3439 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/dataobj.h | 215 ++++++++++++------------ include/wx/gtk1/dataobj.h | 215 ++++++++++++------------ include/wx/stream.h | 22 +++ samples/dnd/Makefile.in | 2 + samples/dnd/dnd.cpp | 308 ++++++++++++++++++++++++++--------- samples/dnd/julian.png | Bin 0 -> 5439 bytes src/common/stream.cpp | 47 ++++++ src/gtk/clipbrd.cpp | 23 ++- src/gtk/dataobj.cpp | 71 ++++++-- src/gtk1/clipbrd.cpp | 23 ++- src/gtk1/dataobj.cpp | 71 ++++++-- utils/wxMMedia2/lib/cdbase.h | 2 + 12 files changed, 683 insertions(+), 316 deletions(-) create mode 100644 samples/dnd/julian.png diff --git a/include/wx/gtk/dataobj.h b/include/wx/gtk/dataobj.h index e8d598e3dd..d79e1b63c8 100644 --- a/include/wx/gtk/dataobj.h +++ b/include/wx/gtk/dataobj.h @@ -37,8 +37,6 @@ class wxFileDataObject; class wxDataFormat : public wxObject { - DECLARE_CLASS( wxDataFormat ) - public: wxDataFormat(); wxDataFormat( wxDataFormatId type ); @@ -73,6 +71,11 @@ private: wxString m_id; bool m_hasAtom; GdkAtom m_atom; + + void PrepareFormats(); + +private: + DECLARE_CLASS( wxDataFormat ) }; //------------------------------------------------------------------------- @@ -81,44 +84,41 @@ private: class wxDataBroker : public wxObject { - DECLARE_CLASS( wxDataBroker ) - public: + /* constructor */ + wxDataBroker(); - /* constructor */ - wxDataBroker(); - - /* add data object */ - void Add( wxDataObject *dataObject, bool preferred = FALSE ); + /* add data object */ + void Add( wxDataObject *dataObject, bool preferred = FALSE ); private: + /* OLE implementation, the methods don't need to be overridden */ - /* 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; + /* get number of supported formats */ + virtual size_t GetFormatCount() const; - /* return preferrd/best supported format */ - virtual wxDataFormatId GetPreferredFormat() const; + /* return nth supported format */ + virtual wxDataFormat &GetNthFormat( size_t nth ) const; - /* search through m_dataObjects, return TRUE if found */ - virtual bool IsSupportedFormat( wxDataFormat &format ) const; + /* return preferrd/best supported format */ + virtual wxDataFormatId GetPreferredFormat() const; - /* search through m_dataObjects and call child's GetSize() */ - virtual size_t GetSize( wxDataFormat& format ) const; + /* search through m_dataObjects, return TRUE if found */ + virtual bool IsSupportedFormat( wxDataFormat &format ) const; - /* search through m_dataObjects and call child's WriteData(dest) */ - virtual void WriteData( wxDataFormat& format, void *dest ) const; + /* search through m_dataObjects and call child's GetSize() */ + virtual size_t GetSize( wxDataFormat& format ) const; - /* implementation */ + /* search through m_dataObjects and call child's WriteData(dest) */ + virtual void WriteData( wxDataFormat& format, void *dest ) const; public: - - wxList m_dataObjects; - size_t m_preferred; + /* implementation */ + wxList m_dataObjects; + size_t m_preferred; + +private: + DECLARE_CLASS( wxDataBroker ) }; //---------------------------------------------------------------------------- @@ -127,31 +127,31 @@ public: class wxDataObject : public wxObject { - DECLARE_DYNAMIC_CLASS( wxDataObject ) - public: + /* constructor */ + wxDataObject(); - /* constructor */ - wxDataObject(); - - /* destructor */ - ~wxDataObject(); + /* destructor */ + ~wxDataObject(); - /* write data to dest */ - virtual void WriteData( void *dest ) const = 0; + /* write data to dest */ + virtual void WriteData( void *dest ) const = 0; - /* get size of data */ - virtual size_t GetSize() const = 0; + /* get size of data */ + virtual size_t GetSize() const = 0; - /* implementation */ - - wxDataFormat &GetFormat(); +public: + /* implementation */ + wxDataFormat m_format; + + wxDataFormat &GetFormat(); - wxDataFormatId GetFormatType() const; - wxString GetFormatId() const; - GdkAtom GetFormatAtom() const; + wxDataFormatId GetFormatType() const; + wxString GetFormatId() const; + GdkAtom GetFormatAtom() const; - wxDataFormat m_format; +private: + DECLARE_DYNAMIC_CLASS( wxDataObject ) }; //---------------------------------------------------------------------------- @@ -160,37 +160,37 @@ public: class wxTextDataObject : public wxDataObject { - DECLARE_DYNAMIC_CLASS( wxTextDataObject ) - public: + /* default constructor. call SetText() later or override + WriteData() and GetSize() for working on-demand */ + wxTextDataObject(); - /* default constructor. call SetText() later or override - WriteData() and GetSize() for working on-demand */ - wxTextDataObject(); + /* constructor */ + wxTextDataObject( const wxString& data ); - /* constructor */ - wxTextDataObject( const wxString& data ); + /* set current text data */ + void SetText( const wxString& data ); - /* set current text data */ - void SetText( const wxString& data ); + /* get current text data */ + wxString GetText() const; - /* get current text data */ - wxString GetText() const; + /* 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 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; - /* 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; - /* write string to dest */ - void WriteString( const wxString &str, void *dest ) const; - - /* implementation */ +public: + /* implementation */ + wxString m_data; - wxString m_data; +private: + DECLARE_DYNAMIC_CLASS( wxTextDataObject ) }; //---------------------------------------------------------------------------- @@ -199,29 +199,29 @@ public: class wxFileDataObject : public wxDataObject { - DECLARE_DYNAMIC_CLASS( wxFileDataObject ) - public: + /* default constructor */ + wxFileDataObject(); - /* default constructor */ - wxFileDataObject(); - - /* add file name to list */ - void AddFile( const wxString &file ); + /* 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; + /* 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; + /* write list of filenames */ + virtual void WriteData( void *dest ) const; - /* return length of list of filenames */ - virtual size_t GetSize() const; + /* return length of list of filenames */ + virtual size_t GetSize() const; - /* implementation */ - - wxString m_files; +public: + /* implementation */ + wxString m_files; + +private: + DECLARE_DYNAMIC_CLASS( wxFileDataObject ) }; //---------------------------------------------------------------------------- @@ -230,27 +230,32 @@ public: class wxBitmapDataObject : public wxDataObject { - DECLARE_DYNAMIC_CLASS( wxBitmapDataObject ) - public: - - /* see wxTextDataObject for explanation */ - - wxBitmapDataObject(); - wxBitmapDataObject( const wxBitmap& bitmap ); - - void SetBitmap( const wxBitmap &bitmap ); - wxBitmap GetBitmap() const; - - virtual void WriteData( void *dest ) const; - virtual size_t GetSize() const; - - void WriteBitmap( const wxBitmap &bitmap, void *dest ) const; - - // implementation - - wxBitmap m_bitmap; - + /* see wxTextDataObject for explanation */ + wxBitmapDataObject(); + wxBitmapDataObject( const wxBitmap& bitmap ); + ~wxBitmapDataObject(); + + void SetBitmap( const wxBitmap &bitmap ); + wxBitmap GetBitmap() const; + + virtual void WriteData( void *dest ) const; + virtual size_t GetSize() const; + void *GetData() const { return (void*)m_pngData; } + + void WriteBitmap( const wxBitmap &bitmap, void *dest ) const; + + void SetPngData( const char *pngData, size_t pngSize ); + +private: + wxBitmap m_bitmap; + size_t m_pngSize; + char *m_pngData; + + void DoConvertToPng(); + +private: + DECLARE_DYNAMIC_CLASS( wxBitmapDataObject ); }; #endif diff --git a/include/wx/gtk1/dataobj.h b/include/wx/gtk1/dataobj.h index e8d598e3dd..d79e1b63c8 100644 --- a/include/wx/gtk1/dataobj.h +++ b/include/wx/gtk1/dataobj.h @@ -37,8 +37,6 @@ class wxFileDataObject; class wxDataFormat : public wxObject { - DECLARE_CLASS( wxDataFormat ) - public: wxDataFormat(); wxDataFormat( wxDataFormatId type ); @@ -73,6 +71,11 @@ private: wxString m_id; bool m_hasAtom; GdkAtom m_atom; + + void PrepareFormats(); + +private: + DECLARE_CLASS( wxDataFormat ) }; //------------------------------------------------------------------------- @@ -81,44 +84,41 @@ private: class wxDataBroker : public wxObject { - DECLARE_CLASS( wxDataBroker ) - public: + /* constructor */ + wxDataBroker(); - /* constructor */ - wxDataBroker(); - - /* add data object */ - void Add( wxDataObject *dataObject, bool preferred = FALSE ); + /* add data object */ + void Add( wxDataObject *dataObject, bool preferred = FALSE ); private: + /* OLE implementation, the methods don't need to be overridden */ - /* 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; + /* get number of supported formats */ + virtual size_t GetFormatCount() const; - /* return preferrd/best supported format */ - virtual wxDataFormatId GetPreferredFormat() const; + /* return nth supported format */ + virtual wxDataFormat &GetNthFormat( size_t nth ) const; - /* search through m_dataObjects, return TRUE if found */ - virtual bool IsSupportedFormat( wxDataFormat &format ) const; + /* return preferrd/best supported format */ + virtual wxDataFormatId GetPreferredFormat() const; - /* search through m_dataObjects and call child's GetSize() */ - virtual size_t GetSize( wxDataFormat& format ) const; + /* search through m_dataObjects, return TRUE if found */ + virtual bool IsSupportedFormat( wxDataFormat &format ) const; - /* search through m_dataObjects and call child's WriteData(dest) */ - virtual void WriteData( wxDataFormat& format, void *dest ) const; + /* search through m_dataObjects and call child's GetSize() */ + virtual size_t GetSize( wxDataFormat& format ) const; - /* implementation */ + /* search through m_dataObjects and call child's WriteData(dest) */ + virtual void WriteData( wxDataFormat& format, void *dest ) const; public: - - wxList m_dataObjects; - size_t m_preferred; + /* implementation */ + wxList m_dataObjects; + size_t m_preferred; + +private: + DECLARE_CLASS( wxDataBroker ) }; //---------------------------------------------------------------------------- @@ -127,31 +127,31 @@ public: class wxDataObject : public wxObject { - DECLARE_DYNAMIC_CLASS( wxDataObject ) - public: + /* constructor */ + wxDataObject(); - /* constructor */ - wxDataObject(); - - /* destructor */ - ~wxDataObject(); + /* destructor */ + ~wxDataObject(); - /* write data to dest */ - virtual void WriteData( void *dest ) const = 0; + /* write data to dest */ + virtual void WriteData( void *dest ) const = 0; - /* get size of data */ - virtual size_t GetSize() const = 0; + /* get size of data */ + virtual size_t GetSize() const = 0; - /* implementation */ - - wxDataFormat &GetFormat(); +public: + /* implementation */ + wxDataFormat m_format; + + wxDataFormat &GetFormat(); - wxDataFormatId GetFormatType() const; - wxString GetFormatId() const; - GdkAtom GetFormatAtom() const; + wxDataFormatId GetFormatType() const; + wxString GetFormatId() const; + GdkAtom GetFormatAtom() const; - wxDataFormat m_format; +private: + DECLARE_DYNAMIC_CLASS( wxDataObject ) }; //---------------------------------------------------------------------------- @@ -160,37 +160,37 @@ public: class wxTextDataObject : public wxDataObject { - DECLARE_DYNAMIC_CLASS( wxTextDataObject ) - public: + /* default constructor. call SetText() later or override + WriteData() and GetSize() for working on-demand */ + wxTextDataObject(); - /* default constructor. call SetText() later or override - WriteData() and GetSize() for working on-demand */ - wxTextDataObject(); + /* constructor */ + wxTextDataObject( const wxString& data ); - /* constructor */ - wxTextDataObject( const wxString& data ); + /* set current text data */ + void SetText( const wxString& data ); - /* set current text data */ - void SetText( const wxString& data ); + /* get current text data */ + wxString GetText() const; - /* get current text data */ - wxString GetText() const; + /* 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 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; - /* 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; - /* write string to dest */ - void WriteString( const wxString &str, void *dest ) const; - - /* implementation */ +public: + /* implementation */ + wxString m_data; - wxString m_data; +private: + DECLARE_DYNAMIC_CLASS( wxTextDataObject ) }; //---------------------------------------------------------------------------- @@ -199,29 +199,29 @@ public: class wxFileDataObject : public wxDataObject { - DECLARE_DYNAMIC_CLASS( wxFileDataObject ) - public: + /* default constructor */ + wxFileDataObject(); - /* default constructor */ - wxFileDataObject(); - - /* add file name to list */ - void AddFile( const wxString &file ); + /* 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; + /* 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; + /* write list of filenames */ + virtual void WriteData( void *dest ) const; - /* return length of list of filenames */ - virtual size_t GetSize() const; + /* return length of list of filenames */ + virtual size_t GetSize() const; - /* implementation */ - - wxString m_files; +public: + /* implementation */ + wxString m_files; + +private: + DECLARE_DYNAMIC_CLASS( wxFileDataObject ) }; //---------------------------------------------------------------------------- @@ -230,27 +230,32 @@ public: class wxBitmapDataObject : public wxDataObject { - DECLARE_DYNAMIC_CLASS( wxBitmapDataObject ) - public: - - /* see wxTextDataObject for explanation */ - - wxBitmapDataObject(); - wxBitmapDataObject( const wxBitmap& bitmap ); - - void SetBitmap( const wxBitmap &bitmap ); - wxBitmap GetBitmap() const; - - virtual void WriteData( void *dest ) const; - virtual size_t GetSize() const; - - void WriteBitmap( const wxBitmap &bitmap, void *dest ) const; - - // implementation - - wxBitmap m_bitmap; - + /* see wxTextDataObject for explanation */ + wxBitmapDataObject(); + wxBitmapDataObject( const wxBitmap& bitmap ); + ~wxBitmapDataObject(); + + void SetBitmap( const wxBitmap &bitmap ); + wxBitmap GetBitmap() const; + + virtual void WriteData( void *dest ) const; + virtual size_t GetSize() const; + void *GetData() const { return (void*)m_pngData; } + + void WriteBitmap( const wxBitmap &bitmap, void *dest ) const; + + void SetPngData( const char *pngData, size_t pngSize ); + +private: + wxBitmap m_bitmap; + size_t m_pngSize; + char *m_pngData; + + void DoConvertToPng(); + +private: + DECLARE_DYNAMIC_CLASS( wxBitmapDataObject ); }; #endif diff --git a/include/wx/stream.h b/include/wx/stream.h index d9fe1b89c0..44660c9e90 100644 --- a/include/wx/stream.h +++ b/include/wx/stream.h @@ -136,6 +136,28 @@ class WXDLLEXPORT wxOutputStream: public wxStreamBase { wxOutputStream& operator<<( __wxOutputManip func) { return func(*this); } }; +// --------------------------------------------------------------------------- +// A stream for measuring streamed output +// --------------------------------------------------------------------------- + +class wxCountingOutputStream: public wxOutputStream { + public: + wxCountingOutputStream(); + + size_t GetSize() const; + bool Ok() const { return TRUE; } + + protected: + + size_t OnSysWrite(const void *buffer, size_t size); + off_t OnSysSeek(off_t pos, wxSeekMode mode); + off_t OnSysTell() const; + + protected: + size_t m_currentPos; +}; + + // --------------------------------------------------------------------------- // "Filter" streams // --------------------------------------------------------------------------- diff --git a/samples/dnd/Makefile.in b/samples/dnd/Makefile.in index 7c88bd2be8..1afad34b83 100644 --- a/samples/dnd/Makefile.in +++ b/samples/dnd/Makefile.in @@ -13,6 +13,8 @@ top_srcdir = @top_srcdir@ top_builddir = ../.. program_dir = samples/dnd +DATAFILES=julian.png + PROGRAM=dnd OBJECTS=$(PROGRAM).o diff --git a/samples/dnd/dnd.cpp b/samples/dnd/dnd.cpp index 046f943199..b8cc40a8c3 100644 --- a/samples/dnd/dnd.cpp +++ b/samples/dnd/dnd.cpp @@ -19,22 +19,23 @@ #include "wx/wx.h" #endif +#ifdef __WXMOTIF__ + #error Sorry, drag and drop is not yet implemented on wxMotif. +#endif + #include "wx/intl.h" #include "wx/log.h" #include "wx/dnd.h" #include "wx/dirdlg.h" - -#ifdef __WXMOTIF__ - #error Sorry, drag and drop is not yet implemented on wxMotif. -#endif +#include "wx/filedlg.h" +#include "wx/image.h" +#include "wx/clipbrd.h" #if defined(__WXGTK__) || defined(__WXMOTIF__) #include "mondrian.xpm" #endif -#include "wx/clipbrd.h" - // ---------------------------------------------------------------------------- // Derive two simple classes which just put in the listbox the strings (text or // file names) we drop on them @@ -95,6 +96,10 @@ public: void OnLogClear(wxCommandEvent& event); void OnCopy(wxCommandEvent& event); void OnPaste(wxCommandEvent& event); + void OnCopyBitmap(wxCommandEvent& event); + void OnPasteBitmap(wxCommandEvent& event); + void OnClipboardHasText(wxCommandEvent& event); + void OnClipboardHasBitmap(wxCommandEvent& event); void OnLeftDown(wxMouseEvent& event); void OnRightDown(wxMouseEvent& event); @@ -102,13 +107,14 @@ public: DECLARE_EVENT_TABLE() private: - wxListBox *m_ctrlFile, - *m_ctrlText; - wxTextCtrl *m_ctrlLog; + wxListBox *m_ctrlFile, + *m_ctrlText; + wxTextCtrl *m_ctrlLog; - wxLog *m_pLog, *m_pLogPrev; + wxLog *m_pLog, *m_pLogPrev; - wxString m_strText; + wxString m_strText; + wxBitmap m_bitmap; }; // ---------------------------------------------------------------------------- @@ -123,26 +129,38 @@ enum Menu_Help, Menu_Clear, Menu_Copy, - Menu_Paste + Menu_Paste, + Menu_CopyBitmap, + Menu_PasteBitmap, + Menu_HasText, + Menu_HasBitmap }; BEGIN_EVENT_TABLE(DnDFrame, wxFrame) - EVT_MENU(Menu_Quit, DnDFrame::OnQuit) - EVT_MENU(Menu_About, DnDFrame::OnAbout) - EVT_MENU(Menu_Drag, DnDFrame::OnDrag) - EVT_MENU(Menu_Help, DnDFrame::OnHelp) - EVT_MENU(Menu_Clear, DnDFrame::OnLogClear) - EVT_MENU(Menu_Copy, DnDFrame::OnCopy) - EVT_MENU(Menu_Paste, DnDFrame::OnPaste) - - EVT_LEFT_DOWN( DnDFrame::OnLeftDown) - EVT_RIGHT_DOWN( DnDFrame::OnRightDown) - EVT_PAINT( DnDFrame::OnPaint) + EVT_MENU(Menu_Quit, DnDFrame::OnQuit) + EVT_MENU(Menu_About, DnDFrame::OnAbout) + EVT_MENU(Menu_Drag, DnDFrame::OnDrag) + EVT_MENU(Menu_Help, DnDFrame::OnHelp) + EVT_MENU(Menu_Clear, DnDFrame::OnLogClear) + EVT_MENU(Menu_Copy, DnDFrame::OnCopy) + EVT_MENU(Menu_Paste, DnDFrame::OnPaste) + EVT_MENU(Menu_CopyBitmap, DnDFrame::OnCopyBitmap) + EVT_MENU(Menu_PasteBitmap,DnDFrame::OnPasteBitmap) + EVT_MENU(Menu_HasText, DnDFrame::OnClipboardHasText) + EVT_MENU(Menu_HasBitmap, DnDFrame::OnClipboardHasBitmap) + + EVT_LEFT_DOWN( DnDFrame::OnLeftDown) + EVT_RIGHT_DOWN( DnDFrame::OnRightDown) + EVT_PAINT( DnDFrame::OnPaint) END_EVENT_TABLE() // `Main program' equivalent, creating windows and returning main app frame bool DnDApp::OnInit() { +#if wxUSE_LIBPNG + wxImage::AddHandler( new wxPNGHandler ); +#endif + // create the main frame window DnDFrame *frame = new DnDFrame((wxFrame *) NULL, "Drag-and-Drop/Clipboard wxWindows Sample", @@ -181,9 +199,15 @@ DnDFrame::DnDFrame(wxFrame *frame, char *title, int x, int y, int w, int h) help_menu->Append(Menu_About, "&About"); wxMenu *clip_menu = new wxMenu; - clip_menu->Append(Menu_Copy, "&Copy\tCtrl+C"); - clip_menu->Append(Menu_Paste, "&Paste\tCtrl+V"); - + clip_menu->Append(Menu_Copy, "&Copy text\tCtrl+C"); + clip_menu->Append(Menu_Paste, "&Paste text\tCtrl+V"); + clip_menu->AppendSeparator(); + clip_menu->Append(Menu_CopyBitmap, "&Copy bitmap"); + clip_menu->Append(Menu_PasteBitmap, "&Paste bitmap"); + clip_menu->AppendSeparator(); + clip_menu->Append(Menu_HasText, "Clipboard has &text\tCtrl+T"); + clip_menu->Append(Menu_HasBitmap, "Clipboard has a &bitmap\tCtrl+B"); + wxMenuBar *menu_bar = new wxMenuBar; menu_bar->Append(file_menu, "&File"); menu_bar->Append(log_menu, "&Log"); @@ -198,58 +222,55 @@ DnDFrame::DnDFrame(wxFrame *frame, char *title, int x, int y, int w, int h) wxString strFile("Drop files here!"), strText("Drop text on me"); - m_ctrlFile = new wxListBox(this, -1, pos, size, 1, &strFile, wxLB_HSCROLL); - m_ctrlText = new wxListBox(this, -1, pos, size, 1, &strText, wxLB_HSCROLL); + m_ctrlFile = new wxListBox(this, -1, pos, size, 1, &strFile, wxLB_HSCROLL | wxLB_ALWAYS_SB ); + m_ctrlText = new wxListBox(this, -1, pos, size, 1, &strText, wxLB_HSCROLL | wxLB_ALWAYS_SB ); m_ctrlLog = new wxTextCtrl(this, -1, "", pos, size, wxTE_MULTILINE | wxTE_READONLY | wxSUNKEN_BORDER ); - -#if wxUSE_STD_IOSTREAM -// redirect log messages to the text window (don't forget to delete it!) - m_pLog = new wxLogTextCtrl(m_ctrlLog); - m_pLogPrev = wxLog::SetActiveTarget(m_pLog); -#endif - - // associate drop targets with 2 text controls - m_ctrlFile->SetDropTarget(new DnDFile(m_ctrlFile)); - m_ctrlText->SetDropTarget(new DnDText(m_ctrlText)); - - wxLayoutConstraints *c; - - // Top-left listbox - c = new wxLayoutConstraints; - c->left.SameAs(this, wxLeft); - c->top.SameAs(this, wxTop); - c->right.PercentOf(this, wxRight, 50); - c->height.PercentOf(this, wxHeight, 40); - m_ctrlFile->SetConstraints(c); - - // Top-right listbox - c = new wxLayoutConstraints; - c->left.SameAs (m_ctrlFile, wxRight); - c->top.SameAs (this, wxTop); - c->right.SameAs (this, wxRight); - c->height.PercentOf(this, wxHeight, 40); - m_ctrlText->SetConstraints(c); - - // Lower text control - c = new wxLayoutConstraints; - c->left.SameAs (this, wxLeft); - c->right.SameAs (this, wxRight); - c->height.PercentOf(this, wxHeight, 40); - c->top.SameAs(m_ctrlText, wxBottom); - m_ctrlLog->SetConstraints(c); - - SetAutoLayout(TRUE); + // redirect log messages to the text window (don't forget to delete it!) + m_pLog = new wxLogTextCtrl(m_ctrlLog); + m_pLogPrev = wxLog::SetActiveTarget(m_pLog); + + // associate drop targets with 2 text controls + m_ctrlFile->SetDropTarget(new DnDFile(m_ctrlFile)); + m_ctrlText->SetDropTarget(new DnDText(m_ctrlText)); + + wxLayoutConstraints *c; + + // Top-left listbox + c = new wxLayoutConstraints; + c->left.SameAs(this, wxLeft); + c->top.SameAs(this, wxTop); + c->right.PercentOf(this, wxRight, 50); + c->height.PercentOf(this, wxHeight, 30); + m_ctrlFile->SetConstraints(c); + + // Top-right listbox + c = new wxLayoutConstraints; + c->left.SameAs (m_ctrlFile, wxRight); + c->top.SameAs (this, wxTop); + c->right.SameAs (this, wxRight); + c->height.PercentOf(this, wxHeight, 30); + m_ctrlText->SetConstraints(c); + + // Lower text control + c = new wxLayoutConstraints; + c->left.SameAs (this, wxLeft); + c->right.SameAs (this, wxRight); + c->height.PercentOf(this, wxHeight, 30); + c->top.SameAs(m_ctrlText, wxBottom); + m_ctrlLog->SetConstraints(c); + + SetAutoLayout(TRUE); } -void DnDFrame::OnQuit(wxCommandEvent& /* event */) +void DnDFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) { Close(TRUE); } -void DnDFrame::OnPaint(wxPaintEvent& /*event*/) +void DnDFrame::OnPaint(wxPaintEvent& WXUNUSED(event)) { int w = 0; int h = 0; @@ -257,10 +278,55 @@ void DnDFrame::OnPaint(wxPaintEvent& /*event*/) wxPaintDC dc(this); dc.SetFont( wxFont( 24, wxDECORATIVE, wxNORMAL, wxNORMAL, FALSE, "charter" ) ); - dc.DrawText( "Drag text from here!", 20, h-35 ); + dc.DrawText( "Drag text from here!", 20, h-50 ); + + if (m_bitmap.Ok()) + dc.DrawBitmap( m_bitmap, 280, h-120, TRUE ); } -void DnDFrame::OnDrag(wxCommandEvent& /* event */) +void DnDFrame::OnClipboardHasText(wxCommandEvent& WXUNUSED(event)) +{ + if ( !wxTheClipboard->Open() ) + { + wxLogError( _T("Can't open clipboard.") ); + + return; + } + + if ( !wxTheClipboard->IsSupported( wxDF_TEXT ) ) + { + wxLogMessage( _T("No text is on the clipboard") ); + } + else + { + wxLogMessage( _T("There is text is on the clipboard") ); + } + + wxTheClipboard->Close(); +} + +void DnDFrame::OnClipboardHasBitmap(wxCommandEvent& WXUNUSED(event)) +{ + if ( !wxTheClipboard->Open() ) + { + wxLogError( _T("Can't open clipboard.") ); + + return; + } + + if ( !wxTheClipboard->IsSupported( wxDF_BITMAP ) ) + { + wxLogMessage( _T("No bitmap is on the clipboard") ); + } + else + { + wxLogMessage( _T("A bitmap is on the clipboard") ); + } + + wxTheClipboard->Close(); +} + +void DnDFrame::OnDrag(wxCommandEvent& WXUNUSED(event)) { wxString strText = wxGetTextFromUser ( @@ -274,7 +340,7 @@ void DnDFrame::OnDrag(wxCommandEvent& /* event */) m_strText = strText; } -void DnDFrame::OnAbout(wxCommandEvent& /* event */) +void DnDFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) { wxMessageBox("Drag-&-Drop Demo\n" "Please see \"Help|Help...\" for details\n" @@ -357,16 +423,108 @@ void DnDFrame::OnRightDown(wxMouseEvent &event ) DnDFrame::~DnDFrame() { -#if wxUSE_STD_IOSTREAM if ( m_pLog != NULL ) { if ( wxLog::SetActiveTarget(m_pLogPrev) == m_pLog ) delete m_pLog; } -#endif } // --------------------------------------------------------------------------- -// clipboard +// bitmap clipboard +// --------------------------------------------------------------------------- + +void DnDFrame::OnCopyBitmap(wxCommandEvent& WXUNUSED(event)) +{ + wxFileDialog dialog(this, "Open a PNG file", "", "", "PNG files (*.png)|*.png", 0); + + if (dialog.ShowModal() != wxID_OK) + { + wxLogMessage( _T("Aborted file open") ); + return; + } + + if (dialog.GetPath().IsEmpty()) + { + wxLogMessage( _T("Returned empty string.") ); + return; + } + + if (!wxFileExists(dialog.GetPath())) + { + wxLogMessage( _T("File doesn't exist.") ); + return; + } + + wxImage image; + image.LoadFile( dialog.GetPath(), wxBITMAP_TYPE_PNG ); + if (!image.Ok()) + { + wxLogMessage( _T("Invalid image file...") ); + return; + } + + wxLogMessage( _T("Decoding image file...") ); + wxYield(); + + wxBitmap bitmap( image.ConvertToBitmap() ); + + if ( !wxTheClipboard->Open() ) + { + wxLogError(_T("Can't open clipboard.")); + + return; + } + + wxLogMessage( _T("Creating wxBitmapDataObject...") ); + wxYield(); + + if ( !wxTheClipboard->AddData(new wxBitmapDataObject(bitmap)) ) + { + wxLogError(_T("Can't copy image to the clipboard.")); + } + else + { + wxLogMessage(_T("Image has been put on the clipboard.") ); + wxLogMessage(_T("You can paste it now and look at it.") ); + } + + wxTheClipboard->Close(); +} + +void DnDFrame::OnPasteBitmap(wxCommandEvent& WXUNUSED(event)) +{ + if ( !wxTheClipboard->Open() ) + { + wxLogError(_T("Can't open clipboard.")); + + return; + } + + if ( !wxTheClipboard->IsSupported(wxDF_BITMAP) ) + { + wxLogWarning(_T("No bitmap on clipboard")); + + wxTheClipboard->Close(); + return; + } + + wxBitmapDataObject data; + if ( !wxTheClipboard->GetData(&data) ) + { + wxLogError(_T("Can't paste bitmap from the clipboard")); + } + else + { + wxLogMessage(_T("Bitmap pasted from the clipboard") ); + m_bitmap = data.GetBitmap(); + Refresh(); + } + + wxTheClipboard->Close(); +} + +// --------------------------------------------------------------------------- +// text clipboard // --------------------------------------------------------------------------- void DnDFrame::OnCopy(wxCommandEvent& WXUNUSED(event)) @@ -403,6 +561,7 @@ void DnDFrame::OnPaste(wxCommandEvent& WXUNUSED(event)) { wxLogWarning(_T("No text data on clipboard")); + wxTheClipboard->Close(); return; } @@ -423,6 +582,7 @@ void DnDFrame::OnPaste(wxCommandEvent& WXUNUSED(event)) // ---------------------------------------------------------------------------- // Notifications called by the base class // ---------------------------------------------------------------------------- + bool DnDText::OnDropText( wxDropPointCoord, wxDropPointCoord, const wxChar *psz ) { m_pOwner->Append(psz); diff --git a/samples/dnd/julian.png b/samples/dnd/julian.png new file mode 100644 index 0000000000000000000000000000000000000000..9e875e0a1fa2a4584b3cf7e9ad98648880029852 GIT binary patch literal 5439 zcmX9?c{o(<{~k;BWfEEQB5M>S%vdtE3|U6Rgc!ZWSYjlcP!3+1Bu?2zwy|Y|43R-H zs7%?*7P8COx2SmKH}CIzuIrrh$8&#{`@TQtdd~Gc#MoI1@=5W*U@$=|wE1P$+lO@r z@Nlr6D6BgV48{S&*f?46@bHjGBr=&yrBdm1I)lNOnwnxVnHw7$hlhs{kw}6dGKoZ` zQ0O!oiAdaF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jQ@O63)kqlmIma^AiHc|Lm#SKqCfra?eCD5SwvL6{QmnWU^_b$b#6Dg>cb*p#lj!Ti>IcW%0&IXnADd6zp;hJ0xj+k^m#3fg-RYv>RrGF#oI?7}R&p=StUyuk{24uDJ)sUxo|6Z^lFx&h`^O z-p~~m?znidCyz}4Tlw1gtA{7I|F_YRU&Uds_FA-3W}|k$iQnuC;bxbb3&@b4ajiqb zOkPLKiguk){xZ|G;X9Rs)ZhKHD@E13hROh5lw4EY2)*Tm8XUZ1+h%W9(V3&=KII`&x7G_3Pd%!!Co5Z-YO&5BR|b zFo}y|T<2#3sjn4c%(HDe+dJD&mbM0VYJPJqzv3^QzO!ntd95OsyJuD}>ax4%!J3}l zC-Jbg488R$;y-{3eoY(L(BVAH8OZkMl{OQ{?h^3U{JPEQHSt*Ur=>&ifPFzRzq z;CRcurX=>4Q40}P{CRAh4zsXC&Mvvd4Z_sBbWJ_KI(4@NXHAc<6Rwq&M#1%^1G&8| zduw}-Co`*VO*A+CZmU1Nb{D1uDJc5h1pwsUzs;Wpr4)P8E9*j9Mkihj3^Yws20f!g zx4#4h2K;&Z=I#Nzh-hW%44jv3d+YX8N#w8}RW7K<)3Cm|?x40ZuV4Jn#_t{f{E3F@ ztM@mztZ(NgrUpV`&)yl}6`XSX4Ge`$2E+;b)B?ci3*cC^a^ zXHf#G@1eS;M+3FmVT^`p{?!!nm$85L#l79`!(a0|_MVM9+bxG1?VI_RjUUSv7HPiu zwOAFsvy*Or-{tqt(5|r#)v_qR{!PTR@!|Itq0@&<%STUyjiY`F=ih7I?CkxslRq52 ze>E;8Xes1HbmZPf_H(`N=zsTSBL^ovUg&Q39dczywq1O)c m_lastcount) m_lastcount = m_currentPos; + return m_currentPos; +} + +off_t wxCountingOutputStream::OnSysSeek(off_t pos, wxSeekMode mode) +{ + if (mode == wxFromStart) + { + m_currentPos = pos; + } + if (mode == wxFromEnd) + { + m_currentPos = m_lastcount + pos; + } + else + { + m_currentPos += pos; + } + if (m_currentPos > m_lastcount) m_lastcount = m_currentPos; + + return m_currentPos; // ? +} + +off_t wxCountingOutputStream::OnSysTell() const +{ + return m_currentPos; // ? +} + // ---------------------------------------------------------------------------- // wxFilterInputStream // ---------------------------------------------------------------------------- + wxFilterInputStream::wxFilterInputStream() : wxInputStream() { diff --git a/src/gtk/clipbrd.cpp b/src/gtk/clipbrd.cpp index 827e86ea22..d3cd53bc4e 100644 --- a/src/gtk/clipbrd.cpp +++ b/src/gtk/clipbrd.cpp @@ -153,7 +153,7 @@ selection_received( GtkWidget *WXUNUSED(widget), clipboard->m_waiting = FALSE; return; } - + /* make sure we got the data in the correct form (selection type). if so, copy data to target object */ @@ -178,12 +178,16 @@ selection_received( GtkWidget *WXUNUSED(widget), case wxDF_BITMAP: { - if (selection_data->type != GDK_SELECTION_TYPE_BITMAP) + if (selection_data->type != GDK_SELECTION_TYPE_STRING) { clipboard->m_waiting = FALSE; return; } + wxBitmapDataObject *bitmap_object = (wxBitmapDataObject *) data_object; + + bitmap_object->SetPngData( (const char*) selection_data->data, (size_t) selection_data->length ); + break; } @@ -268,7 +272,7 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data while (node) { wxDataObject *data_object = (wxDataObject *)node->Data(); - + if (data_object->GetFormat().GetAtom() != selection_data->target) { node = node->Next(); @@ -303,10 +307,17 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data case wxDF_BITMAP: { - // wxBitmapDataObject *private_object = (wxBitmapDataObject*) data_object; + wxBitmapDataObject *bitmap_object = (wxBitmapDataObject*) data_object; - // how do we do that ? - + if (bitmap_object->GetSize() == 0) return; + + gtk_selection_data_set( + selection_data, + GDK_SELECTION_TYPE_STRING, + 8*sizeof(gchar), + (unsigned char*) bitmap_object->GetData(), + (int) bitmap_object->GetSize() ); + break; } diff --git a/src/gtk/dataobj.cpp b/src/gtk/dataobj.cpp index bb9e817c05..1e87427cd7 100644 --- a/src/gtk/dataobj.cpp +++ b/src/gtk/dataobj.cpp @@ -14,6 +14,8 @@ #include "wx/dataobj.h" #include "wx/app.h" #include "wx/debug.h" +#include "wx/mstream.h" +#include "wx/image.h" #include "gdk/gdk.h" @@ -23,6 +25,7 @@ //------------------------------------------------------------------------- GdkAtom g_textAtom = 0; +GdkAtom g_pngAtom = 0; //------------------------------------------------------------------------- // wxDataFormat @@ -32,7 +35,7 @@ IMPLEMENT_CLASS(wxDataFormat, wxObject) wxDataFormat::wxDataFormat() { - if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); + PrepareFormats(); m_type = wxDF_INVALID; m_hasAtom = FALSE; m_atom = (GdkAtom) 0; @@ -40,25 +43,25 @@ wxDataFormat::wxDataFormat() wxDataFormat::wxDataFormat( wxDataFormatId type ) { - if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); + PrepareFormats(); SetType( type ); } wxDataFormat::wxDataFormat( const wxChar *id ) { - if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); + PrepareFormats(); SetId( id ); } wxDataFormat::wxDataFormat( const wxString &id ) { - if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); + PrepareFormats(); SetId( id ); } wxDataFormat::wxDataFormat( const wxDataFormat &format ) { - if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); + PrepareFormats(); m_type = format.GetType(); m_id = format.GetId(); m_hasAtom = TRUE; @@ -67,7 +70,7 @@ wxDataFormat::wxDataFormat( const wxDataFormat &format ) wxDataFormat::wxDataFormat( const GdkAtom atom ) { - if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); + PrepareFormats(); m_hasAtom = TRUE; m_atom = atom; @@ -102,7 +105,7 @@ void wxDataFormat::SetType( wxDataFormatId type ) else if (m_type == wxDF_BITMAP) { - m_id = _T("BITMAP"); + m_id = _T("image/png"); } else if (m_type == wxDF_FILENAME) @@ -169,6 +172,12 @@ GdkAtom wxDataFormat::GetAtom() return m_atom; } +void wxDataFormat::PrepareFormats() +{ + if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); + if (!g_pngAtom) g_pngAtom = gdk_atom_intern( "image/png", FALSE ); +} + //------------------------------------------------------------------------- // wxDataBroker //------------------------------------------------------------------------- @@ -385,18 +394,28 @@ IMPLEMENT_DYNAMIC_CLASS( wxBitmapDataObject, wxDataObject ) wxBitmapDataObject::wxBitmapDataObject() { m_format.SetType( wxDF_BITMAP ); + m_pngData = (char*)NULL; + m_pngSize = 0; } wxBitmapDataObject::wxBitmapDataObject( const wxBitmap& bitmap ) { m_format.SetType( wxDF_BITMAP ); - + m_pngData = (char*)NULL; + m_pngSize = 0; m_bitmap = bitmap; + DoConvertToPng(); +} + +wxBitmapDataObject::~wxBitmapDataObject() +{ + if (m_pngData) delete[] m_pngData; } void wxBitmapDataObject::SetBitmap( const wxBitmap &bitmap ) { m_bitmap = bitmap; + DoConvertToPng(); } wxBitmap wxBitmapDataObject::GetBitmap() const @@ -411,12 +430,44 @@ void wxBitmapDataObject::WriteData( void *dest ) const size_t wxBitmapDataObject::GetSize() const { - return 0; + return m_pngSize; } void wxBitmapDataObject::WriteBitmap( const wxBitmap &bitmap, void *dest ) const { - memcpy( dest, m_bitmap.GetPixmap(), GetSize() ); +// if (m_bitmap == bitmap) + memcpy( dest, m_pngData, m_pngSize ); +} + +void wxBitmapDataObject::SetPngData( const char *pngData, size_t pngSize ) +{ + if (m_pngData) delete[] m_pngData; + m_pngData = (char*) NULL; + m_pngSize = pngSize; + m_pngData = new char[m_pngSize]; + memcpy( m_pngData, pngData, m_pngSize ); + + wxMemoryInputStream mstream( pngData, pngSize ); + wxImage image; + wxPNGHandler handler; + handler.LoadFile( &image, mstream ); + m_bitmap = image.ConvertToBitmap(); +} + +void wxBitmapDataObject::DoConvertToPng() +{ + if (m_pngData) delete[] m_pngData; + + wxImage image( m_bitmap ); + wxPNGHandler handler; + + wxCountingOutputStream count; + handler.SaveFile( &image, count ); + m_pngSize = count.GetSize() + 100; // sometimes the size seems to vary ??? + m_pngData = new char[m_pngSize]; + + wxMemoryOutputStream mstream( m_pngData, m_pngSize ); + handler.SaveFile( &image, mstream ); } // ---------------------------------------------------------------------------- diff --git a/src/gtk1/clipbrd.cpp b/src/gtk1/clipbrd.cpp index 827e86ea22..d3cd53bc4e 100644 --- a/src/gtk1/clipbrd.cpp +++ b/src/gtk1/clipbrd.cpp @@ -153,7 +153,7 @@ selection_received( GtkWidget *WXUNUSED(widget), clipboard->m_waiting = FALSE; return; } - + /* make sure we got the data in the correct form (selection type). if so, copy data to target object */ @@ -178,12 +178,16 @@ selection_received( GtkWidget *WXUNUSED(widget), case wxDF_BITMAP: { - if (selection_data->type != GDK_SELECTION_TYPE_BITMAP) + if (selection_data->type != GDK_SELECTION_TYPE_STRING) { clipboard->m_waiting = FALSE; return; } + wxBitmapDataObject *bitmap_object = (wxBitmapDataObject *) data_object; + + bitmap_object->SetPngData( (const char*) selection_data->data, (size_t) selection_data->length ); + break; } @@ -268,7 +272,7 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data while (node) { wxDataObject *data_object = (wxDataObject *)node->Data(); - + if (data_object->GetFormat().GetAtom() != selection_data->target) { node = node->Next(); @@ -303,10 +307,17 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data case wxDF_BITMAP: { - // wxBitmapDataObject *private_object = (wxBitmapDataObject*) data_object; + wxBitmapDataObject *bitmap_object = (wxBitmapDataObject*) data_object; - // how do we do that ? - + if (bitmap_object->GetSize() == 0) return; + + gtk_selection_data_set( + selection_data, + GDK_SELECTION_TYPE_STRING, + 8*sizeof(gchar), + (unsigned char*) bitmap_object->GetData(), + (int) bitmap_object->GetSize() ); + break; } diff --git a/src/gtk1/dataobj.cpp b/src/gtk1/dataobj.cpp index bb9e817c05..1e87427cd7 100644 --- a/src/gtk1/dataobj.cpp +++ b/src/gtk1/dataobj.cpp @@ -14,6 +14,8 @@ #include "wx/dataobj.h" #include "wx/app.h" #include "wx/debug.h" +#include "wx/mstream.h" +#include "wx/image.h" #include "gdk/gdk.h" @@ -23,6 +25,7 @@ //------------------------------------------------------------------------- GdkAtom g_textAtom = 0; +GdkAtom g_pngAtom = 0; //------------------------------------------------------------------------- // wxDataFormat @@ -32,7 +35,7 @@ IMPLEMENT_CLASS(wxDataFormat, wxObject) wxDataFormat::wxDataFormat() { - if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); + PrepareFormats(); m_type = wxDF_INVALID; m_hasAtom = FALSE; m_atom = (GdkAtom) 0; @@ -40,25 +43,25 @@ wxDataFormat::wxDataFormat() wxDataFormat::wxDataFormat( wxDataFormatId type ) { - if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); + PrepareFormats(); SetType( type ); } wxDataFormat::wxDataFormat( const wxChar *id ) { - if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); + PrepareFormats(); SetId( id ); } wxDataFormat::wxDataFormat( const wxString &id ) { - if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); + PrepareFormats(); SetId( id ); } wxDataFormat::wxDataFormat( const wxDataFormat &format ) { - if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); + PrepareFormats(); m_type = format.GetType(); m_id = format.GetId(); m_hasAtom = TRUE; @@ -67,7 +70,7 @@ wxDataFormat::wxDataFormat( const wxDataFormat &format ) wxDataFormat::wxDataFormat( const GdkAtom atom ) { - if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); + PrepareFormats(); m_hasAtom = TRUE; m_atom = atom; @@ -102,7 +105,7 @@ void wxDataFormat::SetType( wxDataFormatId type ) else if (m_type == wxDF_BITMAP) { - m_id = _T("BITMAP"); + m_id = _T("image/png"); } else if (m_type == wxDF_FILENAME) @@ -169,6 +172,12 @@ GdkAtom wxDataFormat::GetAtom() return m_atom; } +void wxDataFormat::PrepareFormats() +{ + if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); + if (!g_pngAtom) g_pngAtom = gdk_atom_intern( "image/png", FALSE ); +} + //------------------------------------------------------------------------- // wxDataBroker //------------------------------------------------------------------------- @@ -385,18 +394,28 @@ IMPLEMENT_DYNAMIC_CLASS( wxBitmapDataObject, wxDataObject ) wxBitmapDataObject::wxBitmapDataObject() { m_format.SetType( wxDF_BITMAP ); + m_pngData = (char*)NULL; + m_pngSize = 0; } wxBitmapDataObject::wxBitmapDataObject( const wxBitmap& bitmap ) { m_format.SetType( wxDF_BITMAP ); - + m_pngData = (char*)NULL; + m_pngSize = 0; m_bitmap = bitmap; + DoConvertToPng(); +} + +wxBitmapDataObject::~wxBitmapDataObject() +{ + if (m_pngData) delete[] m_pngData; } void wxBitmapDataObject::SetBitmap( const wxBitmap &bitmap ) { m_bitmap = bitmap; + DoConvertToPng(); } wxBitmap wxBitmapDataObject::GetBitmap() const @@ -411,12 +430,44 @@ void wxBitmapDataObject::WriteData( void *dest ) const size_t wxBitmapDataObject::GetSize() const { - return 0; + return m_pngSize; } void wxBitmapDataObject::WriteBitmap( const wxBitmap &bitmap, void *dest ) const { - memcpy( dest, m_bitmap.GetPixmap(), GetSize() ); +// if (m_bitmap == bitmap) + memcpy( dest, m_pngData, m_pngSize ); +} + +void wxBitmapDataObject::SetPngData( const char *pngData, size_t pngSize ) +{ + if (m_pngData) delete[] m_pngData; + m_pngData = (char*) NULL; + m_pngSize = pngSize; + m_pngData = new char[m_pngSize]; + memcpy( m_pngData, pngData, m_pngSize ); + + wxMemoryInputStream mstream( pngData, pngSize ); + wxImage image; + wxPNGHandler handler; + handler.LoadFile( &image, mstream ); + m_bitmap = image.ConvertToBitmap(); +} + +void wxBitmapDataObject::DoConvertToPng() +{ + if (m_pngData) delete[] m_pngData; + + wxImage image( m_bitmap ); + wxPNGHandler handler; + + wxCountingOutputStream count; + handler.SaveFile( &image, count ); + m_pngSize = count.GetSize() + 100; // sometimes the size seems to vary ??? + m_pngData = new char[m_pngSize]; + + wxMemoryOutputStream mstream( m_pngData, m_pngSize ); + handler.SaveFile( &image, mstream ); } // ---------------------------------------------------------------------------- diff --git a/utils/wxMMedia2/lib/cdbase.h b/utils/wxMMedia2/lib/cdbase.h index a46821b38c..427f62cafc 100644 --- a/utils/wxMMedia2/lib/cdbase.h +++ b/utils/wxMMedia2/lib/cdbase.h @@ -17,6 +17,8 @@ #include "wx/wxprec.h" +#include "wx/object.h" + typedef struct wxCDtime { wxUint8 track; wxUint8 hour, min, sec; -- 2.45.2