From dc86cb34c3a8f141686339f1285cf259dec5faaa Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Mon, 2 Nov 1998 14:12:29 +0000 Subject: [PATCH] DnD fixes Image fixes Clipboard API git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@952 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/clipbrd.h | 71 ++++++++++++++++++++++++++++ include/wx/gtk/dnd.h | 97 +++++++++++++-------------------------- include/wx/gtk1/clipbrd.h | 71 ++++++++++++++++++++++++++++ include/wx/gtk1/dnd.h | 97 +++++++++++++-------------------------- samples/image/image.cpp | 12 +++++ src/common/image.cpp | 8 ++++ src/gtk.inc | 1 + src/gtk/bitmap.cpp | 11 ++++- src/gtk/clipbrd.cpp | 86 ++++++++++++++++++++++++++++++++++ src/gtk/dnd.cpp | 22 +++------ src/gtk/menu.cpp | 6 ++- src/gtk/window.cpp | 12 +++-- src/gtk1/bitmap.cpp | 11 ++++- src/gtk1/clipbrd.cpp | 86 ++++++++++++++++++++++++++++++++++ src/gtk1/dnd.cpp | 22 +++------ src/gtk1/menu.cpp | 6 ++- src/gtk1/window.cpp | 12 +++-- 17 files changed, 455 insertions(+), 176 deletions(-) create mode 100644 include/wx/gtk/clipbrd.h create mode 100644 include/wx/gtk1/clipbrd.h create mode 100644 src/gtk/clipbrd.cpp create mode 100644 src/gtk1/clipbrd.cpp diff --git a/include/wx/gtk/clipbrd.h b/include/wx/gtk/clipbrd.h new file mode 100644 index 0000000000..aa46abbb00 --- /dev/null +++ b/include/wx/gtk/clipbrd.h @@ -0,0 +1,71 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: clipboard.h +// Purpose: +// Author: Robert Roebling +// Id: $Id$ +// Copyright: (c) 1998 Robert Roebling +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + + +#ifndef __GTKCLIPBOARDH__ +#define __GTKCLIPBOARDH__ + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "wx/defs.h" +#include "wx/object.h" +#include "wx/list.h" +#include "wx/control.h" +#include "wx/dnd.h" // for wxDataObject + +//----------------------------------------------------------------------------- +// classes +//----------------------------------------------------------------------------- + +class wxClipboard; + +//----------------------------------------------------------------------------- +// global functions +//----------------------------------------------------------------------------- + +void wxInitClipboard(); +void wxDoneClipboard(); + +//----------------------------------------------------------------------------- +// global data +//----------------------------------------------------------------------------- + +extern wxClipboard* wxTheClipboard; + +//----------------------------------------------------------------------------- +// wxClipboard +//----------------------------------------------------------------------------- + +class wxClipboard: public wxObject +{ + DECLARE_DYNAMIC_CLASS(wxClipboard) + +public: + + wxClipboard(); + ~wxClipboard(); + + virtual void SetData( wxDataObject *data ); + virtual void *GetData( wxDataFormat format, size_t *length ); + virtual bool IsAvailable( wxDataFormat format ); + + // implementation + + wxDataObject *m_data; + char *m_sentString, + *m_receivedString; + void *m_receivedTargets; + size_t m_receivedLength; + GtkWidget *m_clipboardWidget; +}; + +#endif + // __GTKCLIPBOARDH__ diff --git a/include/wx/gtk/dnd.h b/include/wx/gtk/dnd.h index 34f15b2b40..e10c9e7c76 100644 --- a/include/wx/gtk/dnd.h +++ b/include/wx/gtk/dnd.h @@ -43,46 +43,14 @@ class wxDropSource; class wxDataObject: public wxObject { public: - // all data formats (values are the same as in windows.h, do not change!) - enum StdFormat - { - Invalid, - Text, - Bitmap, - MetafilePict, - Sylk, - Dif, - Tiff, - OemText, - Dib, - Palette, - Pendata, - Riff, - Wave, - UnicodeText, - EnhMetafile, - Hdrop, - Locale, - Max - }; - - // function to return symbolic name of clipboard format (debug messages) - static const char *GetFormatName(wxDataFormat format); - - // ctor & dtor + wxDataObject() {}; ~wxDataObject() {}; - // pure virtuals to override - // get the best suited format for our data virtual wxDataFormat GetPreferredFormat() const = 0; - // decide if we support this format (should be one of values of - // StdFormat enumerations or a user-defined format) - virtual bool IsSupportedFormat(wxDataFormat format) const = 0; - // get the (total) size of data + virtual bool IsSupportedFormat( wxDataFormat format ) const = 0; virtual size_t GetDataSize() const = 0; - // copy raw data to provided pointer - virtual void GetDataHere(void *pBuf) const = 0; + virtual void GetDataHere( void *data ) const = 0; }; @@ -93,20 +61,22 @@ public: class wxTextDataObject : public wxDataObject { public: - // ctors + wxTextDataObject() { } wxTextDataObject(const wxString& strText) : m_strText(strText) { } void Init(const wxString& strText) { m_strText = strText; } - // implement base class pure virtuals virtual wxDataFormat GetPreferredFormat() const { return wxDF_TEXT; } + virtual bool IsSupportedFormat(wxDataFormat format) const { return format == wxDF_TEXT; } + virtual size_t GetDataSize() const - { return m_strText.Len() + 1; } // +1 for trailing '\0'of course - virtual void GetDataHere(void *pBuf) const - { memcpy(pBuf, m_strText.c_str(), GetDataSize()); } + { return m_strText.Len() + 1; } // +1 for trailing '\0' + + virtual void GetDataHere( void *data ) const + { memcpy(data, m_strText.c_str(), GetDataSize()); } private: wxString m_strText; @@ -125,15 +95,17 @@ public: void AddFile( const wxString &file ) { m_files += file; m_files += '\0'; } - // implement base class pure virtuals virtual wxDataFormat GetPreferredFormat() const { return wxDF_FILENAME; } - virtual bool IsSupportedFormat(wxDataFormat format) const + + virtual bool IsSupportedFormat( wxDataFormat format ) const { return format == wxDF_FILENAME; } + virtual size_t GetDataSize() const { return m_files.Len(); } // no trailing '\0' - virtual void GetDataHere(void *pBuf) const - { memcpy(pBuf, m_files.c_str(), GetDataSize()); } + + virtual void GetDataHere( void *data ) const + { memcpy(data, m_files.c_str(), GetDataSize()); } private: wxString m_files; @@ -152,18 +124,15 @@ class wxDropTarget: public wxObject virtual void OnEnter() { } virtual void OnLeave() { } - virtual bool OnDrop( long x, long y, const void *pData ) = 0; + virtual bool OnDrop( long x, long y, const void *data, size_t size ) = 0; - // implementation - - int m_size; - // Override these to indicate what kind of data you support: virtual size_t GetFormatCount() const = 0; virtual wxDataFormat GetFormat(size_t n) const = 0; - void Drop( GdkEventDropDataAvailable *event, int x, int y ); + // implementation + void RegisterWidget( GtkWidget *widget ); void UnregisterWidget( GtkWidget *widget ); }; @@ -177,7 +146,7 @@ class wxTextDropTarget: public wxDropTarget public: wxTextDropTarget() {}; - virtual bool OnDrop( long x, long y, const void *pData ); + virtual bool OnDrop( long x, long y, const void *data, size_t size ); virtual bool OnDropText( long x, long y, const char *psz ); protected: @@ -196,9 +165,9 @@ class wxFileDropTarget: public wxDropTarget wxFileDropTarget() {}; - virtual bool OnDrop(long x, long y, const void *pData); + virtual bool OnDrop( long x, long y, const void *data, size_t size ); virtual bool OnDropFiles( long x, long y, - size_t nFiles, const char * const aszFiles[]); + size_t nFiles, const char * const aszFiles[] ); protected: @@ -210,14 +179,14 @@ class wxFileDropTarget: public wxDropTarget // wxDropSource //------------------------------------------------------------------------- - enum wxDragResult - { - wxDragError, // error prevented the d&d operation from completing - wxDragNone, // drag target didn't accept the data - wxDragCopy, // the data was successfully copied - wxDragMove, // the data was successfully moved - wxDragCancel // the operation was cancelled by user (not an error) - }; +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 + wxDragCancel // the operation was cancelled by user (not an error) +}; class wxDropSource: public wxObject { @@ -232,11 +201,9 @@ class wxDropSource: public wxObject wxDragResult DoDragDrop( bool bAllowMove = FALSE ); virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; }; - - protected: - - friend void gtk_drag_callback( GtkWidget *widget, GdkEvent *event, wxDropSource *source ); + // implementation + void RegisterWindow(void); void UnregisterWindow(void); diff --git a/include/wx/gtk1/clipbrd.h b/include/wx/gtk1/clipbrd.h new file mode 100644 index 0000000000..aa46abbb00 --- /dev/null +++ b/include/wx/gtk1/clipbrd.h @@ -0,0 +1,71 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: clipboard.h +// Purpose: +// Author: Robert Roebling +// Id: $Id$ +// Copyright: (c) 1998 Robert Roebling +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + + +#ifndef __GTKCLIPBOARDH__ +#define __GTKCLIPBOARDH__ + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "wx/defs.h" +#include "wx/object.h" +#include "wx/list.h" +#include "wx/control.h" +#include "wx/dnd.h" // for wxDataObject + +//----------------------------------------------------------------------------- +// classes +//----------------------------------------------------------------------------- + +class wxClipboard; + +//----------------------------------------------------------------------------- +// global functions +//----------------------------------------------------------------------------- + +void wxInitClipboard(); +void wxDoneClipboard(); + +//----------------------------------------------------------------------------- +// global data +//----------------------------------------------------------------------------- + +extern wxClipboard* wxTheClipboard; + +//----------------------------------------------------------------------------- +// wxClipboard +//----------------------------------------------------------------------------- + +class wxClipboard: public wxObject +{ + DECLARE_DYNAMIC_CLASS(wxClipboard) + +public: + + wxClipboard(); + ~wxClipboard(); + + virtual void SetData( wxDataObject *data ); + virtual void *GetData( wxDataFormat format, size_t *length ); + virtual bool IsAvailable( wxDataFormat format ); + + // implementation + + wxDataObject *m_data; + char *m_sentString, + *m_receivedString; + void *m_receivedTargets; + size_t m_receivedLength; + GtkWidget *m_clipboardWidget; +}; + +#endif + // __GTKCLIPBOARDH__ diff --git a/include/wx/gtk1/dnd.h b/include/wx/gtk1/dnd.h index 34f15b2b40..e10c9e7c76 100644 --- a/include/wx/gtk1/dnd.h +++ b/include/wx/gtk1/dnd.h @@ -43,46 +43,14 @@ class wxDropSource; class wxDataObject: public wxObject { public: - // all data formats (values are the same as in windows.h, do not change!) - enum StdFormat - { - Invalid, - Text, - Bitmap, - MetafilePict, - Sylk, - Dif, - Tiff, - OemText, - Dib, - Palette, - Pendata, - Riff, - Wave, - UnicodeText, - EnhMetafile, - Hdrop, - Locale, - Max - }; - - // function to return symbolic name of clipboard format (debug messages) - static const char *GetFormatName(wxDataFormat format); - - // ctor & dtor + wxDataObject() {}; ~wxDataObject() {}; - // pure virtuals to override - // get the best suited format for our data virtual wxDataFormat GetPreferredFormat() const = 0; - // decide if we support this format (should be one of values of - // StdFormat enumerations or a user-defined format) - virtual bool IsSupportedFormat(wxDataFormat format) const = 0; - // get the (total) size of data + virtual bool IsSupportedFormat( wxDataFormat format ) const = 0; virtual size_t GetDataSize() const = 0; - // copy raw data to provided pointer - virtual void GetDataHere(void *pBuf) const = 0; + virtual void GetDataHere( void *data ) const = 0; }; @@ -93,20 +61,22 @@ public: class wxTextDataObject : public wxDataObject { public: - // ctors + wxTextDataObject() { } wxTextDataObject(const wxString& strText) : m_strText(strText) { } void Init(const wxString& strText) { m_strText = strText; } - // implement base class pure virtuals virtual wxDataFormat GetPreferredFormat() const { return wxDF_TEXT; } + virtual bool IsSupportedFormat(wxDataFormat format) const { return format == wxDF_TEXT; } + virtual size_t GetDataSize() const - { return m_strText.Len() + 1; } // +1 for trailing '\0'of course - virtual void GetDataHere(void *pBuf) const - { memcpy(pBuf, m_strText.c_str(), GetDataSize()); } + { return m_strText.Len() + 1; } // +1 for trailing '\0' + + virtual void GetDataHere( void *data ) const + { memcpy(data, m_strText.c_str(), GetDataSize()); } private: wxString m_strText; @@ -125,15 +95,17 @@ public: void AddFile( const wxString &file ) { m_files += file; m_files += '\0'; } - // implement base class pure virtuals virtual wxDataFormat GetPreferredFormat() const { return wxDF_FILENAME; } - virtual bool IsSupportedFormat(wxDataFormat format) const + + virtual bool IsSupportedFormat( wxDataFormat format ) const { return format == wxDF_FILENAME; } + virtual size_t GetDataSize() const { return m_files.Len(); } // no trailing '\0' - virtual void GetDataHere(void *pBuf) const - { memcpy(pBuf, m_files.c_str(), GetDataSize()); } + + virtual void GetDataHere( void *data ) const + { memcpy(data, m_files.c_str(), GetDataSize()); } private: wxString m_files; @@ -152,18 +124,15 @@ class wxDropTarget: public wxObject virtual void OnEnter() { } virtual void OnLeave() { } - virtual bool OnDrop( long x, long y, const void *pData ) = 0; + virtual bool OnDrop( long x, long y, const void *data, size_t size ) = 0; - // implementation - - int m_size; - // Override these to indicate what kind of data you support: virtual size_t GetFormatCount() const = 0; virtual wxDataFormat GetFormat(size_t n) const = 0; - void Drop( GdkEventDropDataAvailable *event, int x, int y ); + // implementation + void RegisterWidget( GtkWidget *widget ); void UnregisterWidget( GtkWidget *widget ); }; @@ -177,7 +146,7 @@ class wxTextDropTarget: public wxDropTarget public: wxTextDropTarget() {}; - virtual bool OnDrop( long x, long y, const void *pData ); + virtual bool OnDrop( long x, long y, const void *data, size_t size ); virtual bool OnDropText( long x, long y, const char *psz ); protected: @@ -196,9 +165,9 @@ class wxFileDropTarget: public wxDropTarget wxFileDropTarget() {}; - virtual bool OnDrop(long x, long y, const void *pData); + virtual bool OnDrop( long x, long y, const void *data, size_t size ); virtual bool OnDropFiles( long x, long y, - size_t nFiles, const char * const aszFiles[]); + size_t nFiles, const char * const aszFiles[] ); protected: @@ -210,14 +179,14 @@ class wxFileDropTarget: public wxDropTarget // wxDropSource //------------------------------------------------------------------------- - enum wxDragResult - { - wxDragError, // error prevented the d&d operation from completing - wxDragNone, // drag target didn't accept the data - wxDragCopy, // the data was successfully copied - wxDragMove, // the data was successfully moved - wxDragCancel // the operation was cancelled by user (not an error) - }; +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 + wxDragCancel // the operation was cancelled by user (not an error) +}; class wxDropSource: public wxObject { @@ -232,11 +201,9 @@ class wxDropSource: public wxObject wxDragResult DoDragDrop( bool bAllowMove = FALSE ); virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; }; - - protected: - - friend void gtk_drag_callback( GtkWidget *widget, GdkEvent *event, wxDropSource *source ); + // implementation + void RegisterWindow(void); void UnregisterWindow(void); diff --git a/samples/image/image.cpp b/samples/image/image.cpp index 997b1f9484..248c837a3c 100644 --- a/samples/image/image.cpp +++ b/samples/image/image.cpp @@ -79,6 +79,18 @@ MyCanvas::MyCanvas( wxWindow *parent, const wxWindowID id, const wxPoint &pos, c wxImage image; image.LoadFile( "../horse.png", wxBITMAP_TYPE_PNG ); my_horse = new wxBitmap( image ); + + wxBitmap bitmap( 100, 100 ); + + wxMemoryDC dc; + dc.SelectObject( bitmap ); + dc.SetBrush( wxRED_BRUSH ); + dc.SetPen( wxWHITE_PEN ); + dc.DrawRectangle( 0, 0, 100, 100 ); + dc.SelectObject( wxNullBitmap ); + + image = bitmap.ConvertToImage(); + image.SaveFile( "../test.png", wxBITMAP_TYPE_PNG ); } MyCanvas::~MyCanvas(void) diff --git a/src/common/image.cpp b/src/common/image.cpp index 1414471eca..5dac31e477 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -22,6 +22,7 @@ #include "wx/debug.h" #include "wx/log.h" #include "../png/png.h" +#include "wx/filefn.h" //----------------------------------------------------------------------------- // wxImage @@ -191,6 +192,13 @@ int wxImage::GetHeight() const bool wxImage::LoadFile( const wxString& filename, long type ) { UnRef(); + + if (!wxFileExists(filename)) + { + wxLogWarning( "Image file does not exist." ); + + return FALSE; + } m_refData = new wxImageRefData; diff --git a/src/gtk.inc b/src/gtk.inc index 43a72e8839..89877aee97 100644 --- a/src/gtk.inc +++ b/src/gtk.inc @@ -74,6 +74,7 @@ LIB_CPP_SRC=\ gtk/button.cpp \ gtk/checkbox.cpp \ gtk/choice.cpp \ + gtk/clipbrd.cpp \ gtk/colour.cpp \ gtk/control.cpp \ gtk/combobox.cpp \ diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp index acd2e490fa..50d6763dcf 100644 --- a/src/gtk/bitmap.cpp +++ b/src/gtk/bitmap.cpp @@ -513,8 +513,12 @@ wxImage wxBitmap::ConvertToImage() const image.Create( M_BMPDATA->m_width, M_BMPDATA->m_height ); char unsigned *data = image.GetData(); + + + GdkVisual *visual = gdk_window_get_visual( M_BMPDATA->m_pixmap ); + if (visual == NULL) visual = gdk_window_get_visual( (GdkWindow*) &gdk_root_parent ); + int bpp = visual->depth; - int bpp = gdk_image->bpp; GdkColormap *cmap = gtk_widget_get_default_colormap(); long pos = 0; @@ -525,6 +529,11 @@ wxImage wxBitmap::ConvertToImage() const int pixel = gdk_image_get_pixel( gdk_image, i, j ); if (bpp <= 8) { +/* + int r = cmap->colors[pixel].red; // debug code + int g = cmap->colors[pixel].green; + int b = cmap->colors[pixel].blue; +*/ data[pos] = cmap->colors[pixel].red >> 8; data[pos+1] = cmap->colors[pixel].green >> 8; data[pos+2] = cmap->colors[pixel].blue >> 8; diff --git a/src/gtk/clipbrd.cpp b/src/gtk/clipbrd.cpp new file mode 100644 index 0000000000..48cd4598f4 --- /dev/null +++ b/src/gtk/clipbrd.cpp @@ -0,0 +1,86 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: clipbrd.cpp +// Purpose: +// Author: Robert Roebling +// Id: $Id$ +// Copyright: (c) 1998 Robert Roebling +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma implementation "clipbrd.h" +#endif + +#include "wx/clipbrd.h" + +//----------------------------------------------------------------------------- +// data +//----------------------------------------------------------------------------- + +wxClipboard *wxTheClipboard = (wxClipboard*) NULL; + +//----------------------------------------------------------------------------- +// functions +//----------------------------------------------------------------------------- + +void wxInitClipboard() +{ + if (wxTheClipboard) delete wxTheClipboard; + wxTheClipboard = new wxClipboard(); +} + +void wxDoneClipboard() +{ + if (wxTheClipboard) delete wxTheClipboard; + wxTheClipboard = (wxClipboard*) NULL; +} + +//----------------------------------------------------------------------------- +// "selection_received" +//----------------------------------------------------------------------------- + +/* +static void selection_received( GtkWidget *widget, GtkSelectionData *selection_data, gpointer data ) +{ +} +*/ + +//----------------------------------------------------------------------------- +// wxClipboard +//----------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS(wxClipboard,wxObject) + +wxClipboard::wxClipboard() +{ + m_data = (wxDataObject*)NULL; + m_clipboardWidget = gtk_window_new( GTK_WINDOW_POPUP ); + gtk_widget_realize( m_clipboardWidget ); +} + +wxClipboard::~wxClipboard() +{ + if (m_data) delete m_data; + if (m_clipboardWidget) gtk_widget_destroy( m_clipboardWidget ); +} + +void wxClipboard::SetData( wxDataObject *data ) +{ + if (m_data) delete m_data; + m_data = data; +} + +void *wxClipboard::GetData( wxDataFormat format, size_t *length ) +{ + if (!IsAvailable(format)) + { + if (length) *length = 0; + return NULL; + } + return NULL; +} + +bool wxClipboard::IsAvailable( wxDataFormat WXUNUSED(format) ) +{ + return FALSE; +} diff --git a/src/gtk/dnd.cpp b/src/gtk/dnd.cpp index b55ca705f1..39af3c4349 100644 --- a/src/gtk/dnd.cpp +++ b/src/gtk/dnd.cpp @@ -33,20 +33,12 @@ extern bool g_blockEventsOnDrag; wxDropTarget::wxDropTarget() { - m_size = 0; } wxDropTarget::~wxDropTarget() { } -void wxDropTarget::Drop( GdkEventDropDataAvailable *event, int x, int y ) -{ - printf( "Drop data is of type %s.\n", event->data_type ); - - OnDrop( x, y, (char *)event->data); -} - void wxDropTarget::UnregisterWidget( GtkWidget *widget ) { if (!widget) return; @@ -88,9 +80,9 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget ) // wxTextDropTarget // ---------------------------------------------------------------------------- -bool wxTextDropTarget::OnDrop( long x, long y, const void *pData ) +bool wxTextDropTarget::OnDrop( long x, long y, const void *data, size_t WXUNUSED(size) ) { - OnDropText( x, y, (const char*)pData ); + OnDropText( x, y, (const char*)data ); return TRUE; } @@ -127,18 +119,18 @@ bool wxFileDropTarget::OnDropFiles( long x, long y, size_t nFiles, const char * return TRUE; } -bool wxFileDropTarget::OnDrop(long x, long y, const void *pData ) +bool wxFileDropTarget::OnDrop(long x, long y, const void *data, size_t size ) { size_t number = 0; - char *text = (char*) pData; - for (int i = 0; i < m_size; i++) + char *text = (char*) data; + for (size_t i = 0; i < size; i++) if (text[i] == 0) number++; if (number == 0) return TRUE; char **files = new char*[number]; - text = (char*) pData; + text = (char*) data; for (size_t i = 0; i < number; i++) { files[i] = text; @@ -146,7 +138,7 @@ bool wxFileDropTarget::OnDrop(long x, long y, const void *pData ) text += len+1; } - bool ret = OnDropFiles(x, y, 1, files ); + bool ret = OnDropFiles( x, y, 1, files ); free( files ); diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index 974d8ae066..b6d4de7986 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -443,8 +443,10 @@ wxMenuItem *wxMenu::FindItem(int id) const node = node->Next(); } - wxLogDebug( "wxMenu::FindItem: item %d not found.", id); - + // Not finding anything here can be correct + // when search the entire menu system for + // an entry -> no error message. + return (wxMenuItem *) NULL; } diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 995e34d9fb..eaba8b03e1 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -850,8 +850,10 @@ static void gtk_window_drop_callback( GtkWidget *widget, GdkEventDropDataAvailab int x = 0; int y = 0; gdk_window_get_pointer( widget->window, &x, &y, (GdkModifierType *) NULL ); - win->GetDropTarget()->m_size = event->data_numbytes; - win->GetDropTarget()->Drop( event, x, y ); + + printf( "Drop data is of type %s.\n", event->data_type ); + + win->GetDropTarget()->OnDrop( x, y, (const void*)event->data, (size_t)event->data_numbytes ); } /* @@ -1688,8 +1690,8 @@ void wxWindow::AddChild( wxWindow *child ) // wxFrame and wxDialog as children aren't placed into the parents - if (( IS_KIND_OF(child,wxFrame) || IS_KIND_OF(child,wxDialog) ) && - (!IS_KIND_OF(child,wxMDIChildFrame))) + if (( IS_KIND_OF(child,wxFrame) || IS_KIND_OF(child,wxDialog) ) /*&& + (!IS_KIND_OF(child,wxMDIChildFrame))*/) { m_children.Append( child ); @@ -1714,7 +1716,7 @@ void wxWindow::AddChild( wxWindow *child ) } } } - + // wxNotebook is very special, so it has a private AddChild() if (IS_KIND_OF(this,wxNotebook)) diff --git a/src/gtk1/bitmap.cpp b/src/gtk1/bitmap.cpp index acd2e490fa..50d6763dcf 100644 --- a/src/gtk1/bitmap.cpp +++ b/src/gtk1/bitmap.cpp @@ -513,8 +513,12 @@ wxImage wxBitmap::ConvertToImage() const image.Create( M_BMPDATA->m_width, M_BMPDATA->m_height ); char unsigned *data = image.GetData(); + + + GdkVisual *visual = gdk_window_get_visual( M_BMPDATA->m_pixmap ); + if (visual == NULL) visual = gdk_window_get_visual( (GdkWindow*) &gdk_root_parent ); + int bpp = visual->depth; - int bpp = gdk_image->bpp; GdkColormap *cmap = gtk_widget_get_default_colormap(); long pos = 0; @@ -525,6 +529,11 @@ wxImage wxBitmap::ConvertToImage() const int pixel = gdk_image_get_pixel( gdk_image, i, j ); if (bpp <= 8) { +/* + int r = cmap->colors[pixel].red; // debug code + int g = cmap->colors[pixel].green; + int b = cmap->colors[pixel].blue; +*/ data[pos] = cmap->colors[pixel].red >> 8; data[pos+1] = cmap->colors[pixel].green >> 8; data[pos+2] = cmap->colors[pixel].blue >> 8; diff --git a/src/gtk1/clipbrd.cpp b/src/gtk1/clipbrd.cpp new file mode 100644 index 0000000000..48cd4598f4 --- /dev/null +++ b/src/gtk1/clipbrd.cpp @@ -0,0 +1,86 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: clipbrd.cpp +// Purpose: +// Author: Robert Roebling +// Id: $Id$ +// Copyright: (c) 1998 Robert Roebling +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma implementation "clipbrd.h" +#endif + +#include "wx/clipbrd.h" + +//----------------------------------------------------------------------------- +// data +//----------------------------------------------------------------------------- + +wxClipboard *wxTheClipboard = (wxClipboard*) NULL; + +//----------------------------------------------------------------------------- +// functions +//----------------------------------------------------------------------------- + +void wxInitClipboard() +{ + if (wxTheClipboard) delete wxTheClipboard; + wxTheClipboard = new wxClipboard(); +} + +void wxDoneClipboard() +{ + if (wxTheClipboard) delete wxTheClipboard; + wxTheClipboard = (wxClipboard*) NULL; +} + +//----------------------------------------------------------------------------- +// "selection_received" +//----------------------------------------------------------------------------- + +/* +static void selection_received( GtkWidget *widget, GtkSelectionData *selection_data, gpointer data ) +{ +} +*/ + +//----------------------------------------------------------------------------- +// wxClipboard +//----------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS(wxClipboard,wxObject) + +wxClipboard::wxClipboard() +{ + m_data = (wxDataObject*)NULL; + m_clipboardWidget = gtk_window_new( GTK_WINDOW_POPUP ); + gtk_widget_realize( m_clipboardWidget ); +} + +wxClipboard::~wxClipboard() +{ + if (m_data) delete m_data; + if (m_clipboardWidget) gtk_widget_destroy( m_clipboardWidget ); +} + +void wxClipboard::SetData( wxDataObject *data ) +{ + if (m_data) delete m_data; + m_data = data; +} + +void *wxClipboard::GetData( wxDataFormat format, size_t *length ) +{ + if (!IsAvailable(format)) + { + if (length) *length = 0; + return NULL; + } + return NULL; +} + +bool wxClipboard::IsAvailable( wxDataFormat WXUNUSED(format) ) +{ + return FALSE; +} diff --git a/src/gtk1/dnd.cpp b/src/gtk1/dnd.cpp index b55ca705f1..39af3c4349 100644 --- a/src/gtk1/dnd.cpp +++ b/src/gtk1/dnd.cpp @@ -33,20 +33,12 @@ extern bool g_blockEventsOnDrag; wxDropTarget::wxDropTarget() { - m_size = 0; } wxDropTarget::~wxDropTarget() { } -void wxDropTarget::Drop( GdkEventDropDataAvailable *event, int x, int y ) -{ - printf( "Drop data is of type %s.\n", event->data_type ); - - OnDrop( x, y, (char *)event->data); -} - void wxDropTarget::UnregisterWidget( GtkWidget *widget ) { if (!widget) return; @@ -88,9 +80,9 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget ) // wxTextDropTarget // ---------------------------------------------------------------------------- -bool wxTextDropTarget::OnDrop( long x, long y, const void *pData ) +bool wxTextDropTarget::OnDrop( long x, long y, const void *data, size_t WXUNUSED(size) ) { - OnDropText( x, y, (const char*)pData ); + OnDropText( x, y, (const char*)data ); return TRUE; } @@ -127,18 +119,18 @@ bool wxFileDropTarget::OnDropFiles( long x, long y, size_t nFiles, const char * return TRUE; } -bool wxFileDropTarget::OnDrop(long x, long y, const void *pData ) +bool wxFileDropTarget::OnDrop(long x, long y, const void *data, size_t size ) { size_t number = 0; - char *text = (char*) pData; - for (int i = 0; i < m_size; i++) + char *text = (char*) data; + for (size_t i = 0; i < size; i++) if (text[i] == 0) number++; if (number == 0) return TRUE; char **files = new char*[number]; - text = (char*) pData; + text = (char*) data; for (size_t i = 0; i < number; i++) { files[i] = text; @@ -146,7 +138,7 @@ bool wxFileDropTarget::OnDrop(long x, long y, const void *pData ) text += len+1; } - bool ret = OnDropFiles(x, y, 1, files ); + bool ret = OnDropFiles( x, y, 1, files ); free( files ); diff --git a/src/gtk1/menu.cpp b/src/gtk1/menu.cpp index 974d8ae066..b6d4de7986 100644 --- a/src/gtk1/menu.cpp +++ b/src/gtk1/menu.cpp @@ -443,8 +443,10 @@ wxMenuItem *wxMenu::FindItem(int id) const node = node->Next(); } - wxLogDebug( "wxMenu::FindItem: item %d not found.", id); - + // Not finding anything here can be correct + // when search the entire menu system for + // an entry -> no error message. + return (wxMenuItem *) NULL; } diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index 995e34d9fb..eaba8b03e1 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -850,8 +850,10 @@ static void gtk_window_drop_callback( GtkWidget *widget, GdkEventDropDataAvailab int x = 0; int y = 0; gdk_window_get_pointer( widget->window, &x, &y, (GdkModifierType *) NULL ); - win->GetDropTarget()->m_size = event->data_numbytes; - win->GetDropTarget()->Drop( event, x, y ); + + printf( "Drop data is of type %s.\n", event->data_type ); + + win->GetDropTarget()->OnDrop( x, y, (const void*)event->data, (size_t)event->data_numbytes ); } /* @@ -1688,8 +1690,8 @@ void wxWindow::AddChild( wxWindow *child ) // wxFrame and wxDialog as children aren't placed into the parents - if (( IS_KIND_OF(child,wxFrame) || IS_KIND_OF(child,wxDialog) ) && - (!IS_KIND_OF(child,wxMDIChildFrame))) + if (( IS_KIND_OF(child,wxFrame) || IS_KIND_OF(child,wxDialog) ) /*&& + (!IS_KIND_OF(child,wxMDIChildFrame))*/) { m_children.Append( child ); @@ -1714,7 +1716,7 @@ void wxWindow::AddChild( wxWindow *child ) } } } - + // wxNotebook is very special, so it has a private AddChild() if (IS_KIND_OF(this,wxNotebook)) -- 2.45.2