From 219f895a273cdf12ded3f79dbbcd1e076fe83901 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sun, 12 Jul 1998 20:06:59 +0000 Subject: [PATCH] stream compile fixes bitmap, icon, imaglist work (broken) notebook client resize fixed (ugly) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@237 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/generic/imaglist.h | 4 +- include/wx/gtk/bitmap.h | 6 ++ include/wx/gtk/frame.h | 4 +- include/wx/gtk/icon.h | 5 +- include/wx/gtk/notebook.h | 5 +- include/wx/gtk1/bitmap.h | 6 ++ include/wx/gtk1/frame.h | 4 +- include/wx/gtk1/icon.h | 5 +- include/wx/gtk1/notebook.h | 5 +- include/wx/mstream.h | 3 +- include/wx/stream.h | 6 +- samples/controls/controls.cpp | 5 ++ src/common/datstrm.cpp | 24 +++---- src/common/mstream.cpp | 8 +-- src/common/stream.cpp | 16 ++++- src/generic/imaglist.cpp | 37 +++++++++-- src/gtk/bitmap.cpp | 113 ++++++++++++++++++++++++++------ src/gtk/frame.cpp | 7 +- src/gtk/icon.cpp | 5 ++ src/gtk/notebook.cpp | 117 +++++++++++++++++++--------------- src/gtk1/bitmap.cpp | 113 ++++++++++++++++++++++++++------ src/gtk1/frame.cpp | 7 +- src/gtk1/icon.cpp | 5 ++ src/gtk1/notebook.cpp | 117 +++++++++++++++++++--------------- user/wxLayout/wxllist.h | 2 +- 25 files changed, 435 insertions(+), 194 deletions(-) diff --git a/include/wx/generic/imaglist.h b/include/wx/generic/imaglist.h index 6bf2ed7455..2a0893a3ac 100644 --- a/include/wx/generic/imaglist.h +++ b/include/wx/generic/imaglist.h @@ -47,7 +47,7 @@ class wxImageList: public wxObject public: wxImageList::wxImageList() { } - wxImageList(int width, int height, bool mask = TRUE, int initialCount = 1); + wxImageList( int width, int height, bool mask = TRUE, int initialCount = 1 ); ~wxImageList(); bool Create(); int GetImageCount() const; @@ -62,6 +62,8 @@ class wxImageList: public wxObject private: wxList m_images; + int m_width; + int m_height; }; #endif // __IMAGELISTH_G__ diff --git a/include/wx/gtk/bitmap.h b/include/wx/gtk/bitmap.h index 876eba2249..94795def8e 100644 --- a/include/wx/gtk/bitmap.h +++ b/include/wx/gtk/bitmap.h @@ -102,6 +102,8 @@ class wxBitmap: public wxObject wxMask *GetMask(void) const; void SetMask( wxMask *mask ); + void Resize( int height, int width ); + bool SaveFile( const wxString &name, int type, wxPalette *palette = NULL ); bool LoadFile( const wxString &name, int type ); @@ -121,6 +123,10 @@ class wxBitmap: public wxObject GdkPixmap *GetPixmap(void) const; GdkBitmap *GetBitmap(void) const; + void DestroyImage(void); + void RecreateImage(void); + void Render(void); + // no data :-) }; diff --git a/include/wx/gtk/frame.h b/include/wx/gtk/frame.h index 42b6adb9a9..517edc9506 100644 --- a/include/wx/gtk/frame.h +++ b/include/wx/gtk/frame.h @@ -70,7 +70,9 @@ class wxFrame: public wxWindow wxString GetTitle(void) const; void OnActivate( wxActivateEvent &WXUNUSED(event) ) {}; - void GtkOnSize( int width, int height ); + //private: + + void GtkOnSize( int x, int y, int width, int height ); private: diff --git a/include/wx/gtk/icon.h b/include/wx/gtk/icon.h index 2d9ee37522..a79e4906ef 100644 --- a/include/wx/gtk/icon.h +++ b/include/wx/gtk/icon.h @@ -40,11 +40,8 @@ public: inline wxIcon(const wxIcon& icon) { Ref(icon); } inline wxIcon(const wxIcon* icon) { if (icon) Ref(*icon); } + wxIcon( char **bits, int width=-1, int height=-1 ); - // Don't change this. Robert. - wxIcon( char **bits, int WXUNUSED(width), int WXUNUSED(height) ) : - wxBitmap( bits ) {}; - inline wxIcon& operator = (const wxIcon& icon) { if (*this == icon) return (*this); Ref(icon); return *this; } inline bool operator == (const wxIcon& icon) { return m_refData == icon.m_refData; } inline bool operator != (const wxIcon& icon) { return m_refData != icon.m_refData; } diff --git a/include/wx/gtk/notebook.h b/include/wx/gtk/notebook.h index bea1b55ffa..51b228aee0 100644 --- a/include/wx/gtk/notebook.h +++ b/include/wx/gtk/notebook.h @@ -31,6 +31,7 @@ class wxNotebookPage; // ---------------------------------------------------------------------------- // notebook events // ---------------------------------------------------------------------------- + class wxNotebookEvent : public wxCommandEvent { public: @@ -139,10 +140,6 @@ public: // base class virtuals virtual void AddChild(wxWindow *child); -protected: - // wxWin callbacks - void OnSize(wxSizeEvent& event); - private: // common part of all ctors void Init(); diff --git a/include/wx/gtk1/bitmap.h b/include/wx/gtk1/bitmap.h index 876eba2249..94795def8e 100644 --- a/include/wx/gtk1/bitmap.h +++ b/include/wx/gtk1/bitmap.h @@ -102,6 +102,8 @@ class wxBitmap: public wxObject wxMask *GetMask(void) const; void SetMask( wxMask *mask ); + void Resize( int height, int width ); + bool SaveFile( const wxString &name, int type, wxPalette *palette = NULL ); bool LoadFile( const wxString &name, int type ); @@ -121,6 +123,10 @@ class wxBitmap: public wxObject GdkPixmap *GetPixmap(void) const; GdkBitmap *GetBitmap(void) const; + void DestroyImage(void); + void RecreateImage(void); + void Render(void); + // no data :-) }; diff --git a/include/wx/gtk1/frame.h b/include/wx/gtk1/frame.h index 42b6adb9a9..517edc9506 100644 --- a/include/wx/gtk1/frame.h +++ b/include/wx/gtk1/frame.h @@ -70,7 +70,9 @@ class wxFrame: public wxWindow wxString GetTitle(void) const; void OnActivate( wxActivateEvent &WXUNUSED(event) ) {}; - void GtkOnSize( int width, int height ); + //private: + + void GtkOnSize( int x, int y, int width, int height ); private: diff --git a/include/wx/gtk1/icon.h b/include/wx/gtk1/icon.h index 2d9ee37522..a79e4906ef 100644 --- a/include/wx/gtk1/icon.h +++ b/include/wx/gtk1/icon.h @@ -40,11 +40,8 @@ public: inline wxIcon(const wxIcon& icon) { Ref(icon); } inline wxIcon(const wxIcon* icon) { if (icon) Ref(*icon); } + wxIcon( char **bits, int width=-1, int height=-1 ); - // Don't change this. Robert. - wxIcon( char **bits, int WXUNUSED(width), int WXUNUSED(height) ) : - wxBitmap( bits ) {}; - inline wxIcon& operator = (const wxIcon& icon) { if (*this == icon) return (*this); Ref(icon); return *this; } inline bool operator == (const wxIcon& icon) { return m_refData == icon.m_refData; } inline bool operator != (const wxIcon& icon) { return m_refData != icon.m_refData; } diff --git a/include/wx/gtk1/notebook.h b/include/wx/gtk1/notebook.h index bea1b55ffa..51b228aee0 100644 --- a/include/wx/gtk1/notebook.h +++ b/include/wx/gtk1/notebook.h @@ -31,6 +31,7 @@ class wxNotebookPage; // ---------------------------------------------------------------------------- // notebook events // ---------------------------------------------------------------------------- + class wxNotebookEvent : public wxCommandEvent { public: @@ -139,10 +140,6 @@ public: // base class virtuals virtual void AddChild(wxWindow *child); -protected: - // wxWin callbacks - void OnSize(wxSizeEvent& event); - private: // common part of all ctors void Init(); diff --git a/include/wx/mstream.h b/include/wx/mstream.h index 9cc7aab26a..716c809967 100644 --- a/include/wx/mstream.h +++ b/include/wx/mstream.h @@ -11,7 +11,8 @@ #ifndef __WXMMSTREAM_H__ #define __WXMMSTREAM_H__ -#include +#include "wx/object.h" +#include "wx/stream.h" class wxMemoryStreamBase: public wxStream { DECLARE_CLASS(wxMemoryStreamBase) diff --git a/include/wx/stream.h b/include/wx/stream.h index a0800e1368..8ee9d1b8df 100644 --- a/include/wx/stream.h +++ b/include/wx/stream.h @@ -91,7 +91,7 @@ class wxFilterInputStream: public wxInputStream { wxInputStream *m_parent_i_stream; }; -class wxFilterOuputStream: pubilc wxOutputStream { +class wxFilterOutputStream: public wxOutputStream { DECLARE_CLASS(wxFilterOutputStream) public: wxFilterOutputStream(wxOutputStream& stream); @@ -102,8 +102,8 @@ class wxFilterOuputStream: pubilc wxOutputStream { virtual size_t SeekO(int pos, wxWhenceType whence = wxBeginPosition) { return m_parent_o_stream->SeekO(pos, whence); } - virtual bool Eof() const { return m_parent_o_sream->Eof(); } - virtual size_t LastRead() const { return m_parent_o_stream->LastRead(); } + virtual bool Bad() const { return m_parent_o_stream->Bad(); } + virtual size_t LastWrite() const { return m_parent_o_stream->LastWrite(); } protected: wxOutputStream *m_parent_o_stream; diff --git a/samples/controls/controls.cpp b/samples/controls/controls.cpp index 004eff2b84..7db58c8219 100644 --- a/samples/controls/controls.cpp +++ b/samples/controls/controls.cpp @@ -133,6 +133,8 @@ const ID_CHOICE_APPEND = 124; const ID_COMBO = 140; +const ID_TEXT = 150; + BEGIN_EVENT_TABLE(MyPanel, wxPanel) EVT_SIZE ( MyPanel::OnSize) EVT_LISTBOX (ID_LISTBOX, MyPanel::OnListBox) @@ -177,6 +179,9 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) : panel = new wxPanel(m_notebook); m_combo = new wxComboBox( panel, ID_COMBO, "This", wxPoint(10,10), wxSize(120,-1), 9, choices ); m_notebook->AddPage(panel, "wxComboBox"); + + wxTextCtrl *text = new wxTextCtrl( m_notebook, ID_TEXT, "Write text here.", wxPoint(0,20), wxSize(120,100), wxTE_MULTILINE ); + m_notebook->AddPage( text, "wxTextCtrl" ); } void MyPanel::OnSize( wxSizeEvent& WXUNUSED(event) ) diff --git a/src/common/datstrm.cpp b/src/common/datstrm.cpp index f4ccc714a4..15a5ef78a8 100644 --- a/src/common/datstrm.cpp +++ b/src/common/datstrm.cpp @@ -44,7 +44,7 @@ unsigned long wxDataInputStream::Read32() { char buf[4]; - if (!m_istream) + if (!m_parent_i_stream) return 0; Read(buf, 4); @@ -59,7 +59,7 @@ unsigned short wxDataInputStream::Read16() { char buf[2]; - if (!m_istream) + if (!m_parent_i_stream) return 0; Read(buf, 2); @@ -72,7 +72,7 @@ unsigned char wxDataInputStream::Read8() { char buf; - if (!m_istream) + if (!m_parent_i_stream) return 0; Read(&buf, 1); @@ -87,7 +87,7 @@ double wxDataInputStream::ReadDouble() #if USE_APPLE_IEEE char buf[10]; - if (!m_istream) + if (!m_parent_i_stream) return 0.0; Read(buf, 10); @@ -101,7 +101,7 @@ wxString wxDataInputStream::ReadLine() { char i_strg[255]; - if (!m_istream) + if (!m_parent_i_stream) return ""; // TODO: Implement ReadLine @@ -114,7 +114,7 @@ wxString wxDataInputStream::ReadString() char *string; unsigned long len; - if (!m_istream) + if (!m_parent_i_stream) return ""; len = Read32(); @@ -138,7 +138,7 @@ void wxDataOutputStream::Write32(unsigned long i) { char buf[4]; - if (!m_ostream) + if (!m_parent_o_stream) return; buf[0] = i & 0xff; @@ -152,7 +152,7 @@ void wxDataOutputStream::Write16(unsigned short i) { char buf[2]; - if (!m_ostream) + if (!m_parent_o_stream) return; buf[0] = i & 0xff; @@ -162,7 +162,7 @@ void wxDataOutputStream::Write16(unsigned short i) void wxDataOutputStream::Write8(unsigned char i) { - if (!m_ostream) + if (!m_parent_o_stream) return; Write(&i, 1); @@ -176,7 +176,7 @@ void wxDataOutputStream::WriteLine(const wxString& line) wxString tmp_string = line + '\n'; #endif - if (!m_ostream) + if (!m_parent_o_stream) return; Write((const char *) tmp_string, tmp_string.Length()); @@ -184,7 +184,7 @@ void wxDataOutputStream::WriteLine(const wxString& line) void wxDataOutputStream::WriteString(const wxString& string) { - if (!m_ostream) + if (!m_parent_o_stream) return; Write32(string.Length()); @@ -198,7 +198,7 @@ void wxDataOutputStream::WriteDouble(double d) { char buf[10]; - if (!m_ostream) + if (!m_parent_o_stream) return; #if USE_APPLE_IEEE diff --git a/src/common/mstream.cpp b/src/common/mstream.cpp index 7bed3cbf11..2bfa364e1e 100644 --- a/src/common/mstream.cpp +++ b/src/common/mstream.cpp @@ -14,14 +14,14 @@ #endif #include -#include -#include +#include "wx/stream.h" +#include "wx/mstream.h" #if !USE_SHARED_LIBRARY IMPLEMENT_CLASS(wxMemoryStreamBase, wxStream) IMPLEMENT_CLASS(wxMemoryInputStream, wxMemoryStreamBase) -IMPLEMENT_DYNAMIC_CLASS(wxMemoryOutputStream, wxMemoryStreamBase) -IMPLEMENT_DYNAMIC_CLASS(wxMemoryStream, wxMemoryStreamBase) +//IMPLEMENT_DYNAMIC_CLASS(wxMemoryOutputStream, wxMemoryStreamBase) +//IMPLEMENT_DYNAMIC_CLASS(wxMemoryStream, wxMemoryStreamBase) #endif wxMemoryStreamBase::wxMemoryStreamBase(char *data, size_t length, int iolimit) diff --git a/src/common/stream.cpp b/src/common/stream.cpp index fc7bcc8b9a..b438c2b386 100644 --- a/src/common/stream.cpp +++ b/src/common/stream.cpp @@ -13,8 +13,8 @@ #pragma implementation "stream.h" #endif -#include -#include "stream.h" +#include "wx/object.h" +#include "wx/stream.h" #if !USE_SHARED_LIBRARY IMPLEMENT_ABSTRACT_CLASS(wxInputStream, wxObject) @@ -65,9 +65,19 @@ wxOutputStream& wxOutputStream::Write(wxInputStream& stream_in) wxFilterInputStream::wxFilterInputStream(wxInputStream& stream) : wxInputStream() { - m_parent_stream = &stream; + m_parent_i_stream = &stream; } wxFilterInputStream::~wxFilterInputStream() { } + +wxFilterOutputStream::wxFilterOutputStream(wxOutputStream& stream) + : wxOutputStream() +{ + m_parent_o_stream = &stream; +} + +wxFilterOutputStream::~wxFilterOutputStream() +{ +} diff --git a/src/generic/imaglist.cpp b/src/generic/imaglist.cpp index 103d86d9e5..61819c387a 100644 --- a/src/generic/imaglist.cpp +++ b/src/generic/imaglist.cpp @@ -20,8 +20,10 @@ IMPLEMENT_DYNAMIC_CLASS(wxImageList, wxObject) -wxImageList::wxImageList(int width, int height, bool mask, int initialCount) +wxImageList::wxImageList( int width, int height, bool WXUNUSED(mask), int WXUNUSED(initialCount) ) { + m_width = width; + m_height = height; Create(); }; @@ -81,6 +83,15 @@ bool wxImageList::RemoveAll() bool wxImageList::GetSize( int index, int &width, int &height ) const { +#ifdef __WXGTK__ + + width = m_width; + height = m_height; + + return (m_images.Nth( index ) != NULL); + +#else + wxNode *node = m_images.Nth( index ); if (node) { @@ -95,17 +106,33 @@ bool wxImageList::GetSize( int index, int &width, int &height ) const height = 0; return FALSE; }; + +#endif }; -bool wxImageList::Draw( int index, wxDC &dc, - int x, int y, - int WXUNUSED(flags), bool WXUNUSED(solidBackground) ) +bool wxImageList::Draw( int index, wxDC &dc, int x, int y, + int flags, bool WXUNUSED(solidBackground) ) { wxNode *node = m_images.Nth( index ); if (!node) return FALSE; wxBitmap *bm = (wxBitmap*)node->Data(); + +#ifdef __WXGTK__ + + // As X doesn't have a standard size for icons, we resize here. + // Otherwise we'd simply have to forbid different bitmap sizes. + + if ((m_width != bm->GetWidth()) || + (m_height != bm->GetHeight())) + { + bm->Resize( m_width, m_height ); + }; + +#endif + wxIcon *icon = (wxIcon*)bm; - dc.DrawIcon( *icon, x, y ); + dc.DrawIcon( *icon, x, y, (flags & wxIMAGELIST_DRAW_TRANSPARENT) > 0 ); + return TRUE; }; diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp index eb09743ab8..05c3136acc 100644 --- a/src/gtk/bitmap.cpp +++ b/src/gtk/bitmap.cpp @@ -74,6 +74,9 @@ class wxBitmapRefData: public wxObjectRefData int m_width; int m_height; int m_bpp; +#ifdef USE_GDK_IMLIB + GdkImlibImage *m_image; +#endif wxPalette *m_palette; }; @@ -92,10 +95,11 @@ wxBitmapRefData::~wxBitmapRefData(void) { #ifdef USE_GDK_IMLIB if (m_pixmap) gdk_imlib_free_pixmap( m_pixmap ); + if (m_image) gdk_imlib_destroy_image( m_image ); #else if (m_pixmap) gdk_pixmap_unref( m_pixmap ); - if (m_bitmap) gdk_bitmap_unref( m_bitmap ); #endif + if (m_bitmap) gdk_bitmap_unref( m_bitmap ); if (m_mask) delete m_mask; if (m_palette) delete m_palette; }; @@ -126,22 +130,26 @@ wxBitmap::wxBitmap( int width, int height, int depth ) wxBitmap::wxBitmap( char **bits ) { m_refData = new wxBitmapRefData(); - - GdkBitmap *mask = NULL; #ifndef USE_GDK_IMLIB + + GdkBitmap *mask = NULL; + M_BMPDATA->m_pixmap = gdk_pixmap_create_from_xpm_d( (GdkWindow*) &gdk_root_parent, &mask, NULL, (gchar **) bits ); -#else - M_BMPDATA->m_pixmap = NULL; - int res = gdk_imlib_data_to_pixmap( bits, &M_BMPDATA->m_pixmap, &mask ); -#endif - + if (mask) { M_BMPDATA->m_mask = new wxMask(); M_BMPDATA->m_mask->m_bitmap = mask; }; + +#else + + M_BMPDATA->m_image = gdk_imlib_create_image_from_xpm_data( bits ); + Render(); + +#endif gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) ); M_BMPDATA->m_bpp = 24; // ? @@ -248,19 +256,57 @@ void wxBitmap::SetDepth( int depth ) wxMask *wxBitmap::GetMask(void) const { if (!Ok()) return NULL; + return M_BMPDATA->m_mask; }; void wxBitmap::SetMask( wxMask *mask ) { if (!Ok()) return; + if (M_BMPDATA->m_mask) delete M_BMPDATA->m_mask; M_BMPDATA->m_mask = mask; }; -bool wxBitmap::SaveFile( const wxString &WXUNUSED(name), int WXUNUSED(type), +void wxBitmap::Resize( int height, int width ) +{ + if (!Ok()) return; + + return; + +#ifdef USE_GDK_IMLIB + + if (M_BMPDATA->m_bitmap) return; // not supported for bitmaps + + if (!M_BMPDATA->m_image) RecreateImage(); + + if (M_BMPDATA->m_pixmap) gdk_imlib_free_pixmap( M_BMPDATA->m_pixmap ); + if (M_BMPDATA->m_mask) delete M_BMPDATA->m_mask; + + GdkImlibImage* image = gdk_imlib_clone_scaled_image( M_BMPDATA->m_image, height, width ); + gdk_imlib_destroy_image( M_BMPDATA->m_image ); + M_BMPDATA->m_image = image; + M_BMPDATA->m_height = height; + M_BMPDATA->m_width = width; + + Render(); + +#endif +}; + +bool wxBitmap::SaveFile( const wxString &name, int WXUNUSED(type), wxPalette *WXUNUSED(palette) ) { +#ifdef USE_GDK_IMLIB + + if (!Ok()) return FALSE; + + if (!M_BMPDATA->m_image) RecreateImage(); + + return gdk_imlib_save_image( M_BMPDATA->m_image, WXSTRINGCAST name, NULL ); + +#endif + return FALSE; }; @@ -270,23 +316,16 @@ bool wxBitmap::LoadFile( const wxString &name, int WXUNUSED(type) ) UnRef(); m_refData = new wxBitmapRefData(); - M_BMPDATA->m_mask = NULL; - - GdkBitmap *mask = NULL; - int res = gdk_imlib_load_file_to_pixmap( WXSTRINGCAST name, &M_BMPDATA->m_pixmap, &mask ); + M_BMPDATA->m_image = gdk_imlib_load_image( WXSTRINGCAST name ); - if (res != 1) + if (!M_BMPDATA->m_image) { UnRef(); return FALSE; }; - if (mask) - { - M_BMPDATA->m_mask = new wxMask(); - M_BMPDATA->m_mask->m_bitmap = mask; - } + Render(); gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) ); M_BMPDATA->m_bpp = 24; // ? @@ -312,6 +351,42 @@ GdkPixmap *wxBitmap::GetPixmap(void) const GdkBitmap *wxBitmap::GetBitmap(void) const { if (!Ok()) return NULL; + return M_BMPDATA->m_bitmap; }; +void wxBitmap::DestroyImage(void) +{ + if (!Ok()) return; + + if (M_BMPDATA->m_image) + { + gdk_imlib_destroy_image( M_BMPDATA->m_image ); + M_BMPDATA->m_image = NULL; + }; +}; + +void wxBitmap::RecreateImage(void) +{ +}; + +void wxBitmap::Render(void) +{ + if (!Ok()) return; + +#ifdef USE_GDK_IMLIB + + gdk_imlib_render( M_BMPDATA->m_image, M_BMPDATA->m_image->rgb_width, M_BMPDATA->m_image->rgb_height ); + + M_BMPDATA->m_pixmap = gdk_imlib_move_image( M_BMPDATA->m_image ); + GdkBitmap *mask = gdk_imlib_move_mask( M_BMPDATA->m_image ); + if (mask) + { + M_BMPDATA->m_mask = new wxMask(); + M_BMPDATA->m_mask->m_bitmap = mask; + }; + +#endif +}; + + diff --git a/src/gtk/frame.cpp b/src/gtk/frame.cpp index e78e9679b6..075ed1e7f6 100644 --- a/src/gtk/frame.cpp +++ b/src/gtk/frame.cpp @@ -42,7 +42,7 @@ void gtk_frame_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, printf( ".\n" ); */ - win->GtkOnSize( alloc->width, alloc->height ); + win->GtkOnSize( alloc->x, alloc->y, alloc->width, alloc->height ); }; //----------------------------------------------------------------------------- @@ -194,8 +194,11 @@ void wxFrame::GetClientSize( int *width, int *height ) const }; }; -void wxFrame::GtkOnSize( int width, int height ) +void wxFrame::GtkOnSize( int x, int y, int width, int height ) { + m_x = x; + m_y = y; + if ((m_height == height) && (m_width == width) && (m_sizeSet)) return; if (!m_mainWindow) return; diff --git a/src/gtk/icon.cpp b/src/gtk/icon.cpp index a65627746c..7ab4484537 100644 --- a/src/gtk/icon.cpp +++ b/src/gtk/icon.cpp @@ -20,3 +20,8 @@ IMPLEMENT_DYNAMIC_CLASS(wxIcon,wxBitmap) +wxIcon::wxIcon( char **bits, int WXUNUSED(width), int WXUNUSED(height) ) : + wxBitmap( bits ) +{ +}; + diff --git a/src/gtk/notebook.cpp b/src/gtk/notebook.cpp index eb1ac6d1b5..4021fcaf49 100644 --- a/src/gtk/notebook.cpp +++ b/src/gtk/notebook.cpp @@ -19,13 +19,40 @@ #include "wx/intl.h" #include "wx/log.h" +//----------------------------------------------------------------------------- +// wxNotebookPage +//----------------------------------------------------------------------------- + +class wxNotebookPage: public wxObject +{ +public: + wxNotebookPage() + { + m_id = -1; + m_text = ""; + m_image = -1; + m_page = NULL; + m_client = NULL; + m_parent = NULL; + }; + +//private: + int m_id; + wxString m_text; + int m_image; + GtkNotebookPage *m_page; + GtkLabel *m_label; + wxWindow *m_client; + GtkNotebook *m_parent; +}; + //----------------------------------------------------------------------------- // GTK callbacks //----------------------------------------------------------------------------- // page change callback -static void gtk_notebook_page_change_callback(GtkNotebook *widget, - GtkNotebookPage *page, +static void gtk_notebook_page_change_callback(GtkNotebook *WXUNUSED(widget), + GtkNotebookPage *WXUNUSED(page), gint nPage, gpointer data) { @@ -42,29 +69,24 @@ static void gtk_notebook_page_change_callback(GtkNotebook *widget, notebook->ProcessEvent(event); } -//----------------------------------------------------------------------------- -// wxNotebookPage -//----------------------------------------------------------------------------- - -class wxNotebookPage: public wxObject +static void gtk_notebook_client_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, + wxNotebookPage *page ) { -public: - wxNotebookPage() - { - m_id = -1; - m_text = ""; - m_image = -1; - m_page = NULL; - m_clientPanel = NULL; - }; - -//private: - int m_id; - wxString m_text; - int m_image; - GtkNotebookPage *m_page; - GtkLabel *m_label; - wxWindow *m_clientPanel; + if (!page->m_client->HasVMT()) return; + +/* + printf( "OnResize from " ); + if (page->m_client->GetClassInfo() && page->m_client->GetClassInfo()->GetClassName()) + printf( page->m_client->GetClassInfo()->GetClassName() ); + printf( ".\n" ); + + printf( " New: X: %d Y: %d ", alloc->x, alloc->y ); + printf( " W: %d H: %d ", alloc->width, alloc->height ); + printf( " .\n" ); +*/ + + page->m_client->SetSize( alloc->x, alloc->y+26, + alloc->width, alloc->height ); }; //----------------------------------------------------------------------------- @@ -195,7 +217,7 @@ wxNotebookPage* wxNotebook::GetNotebookPage(int page) const node = node->Next(); }; - wxLogDebug("Notebook page %d not found!", page); + wxLogDebug( "Notebook page %d not found!", page ); return NULL; }; @@ -305,7 +327,7 @@ bool wxNotebook::DeletePage( int page ) wxASSERT( child ); - delete nb_page->m_clientPanel; + delete nb_page->m_client; // Amazingly, this is not necessary // gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget), page_num ); @@ -328,7 +350,7 @@ bool wxNotebook::AddPage(wxWindow* win, const wxString& text, while (node) { page = (wxNotebookPage*)node->Data(); - if ( page->m_clientPanel == win ) + if ( page->m_client == win ) break; // found node = node->Next(); }; @@ -356,29 +378,36 @@ wxWindow *wxNotebook::GetPage( int page ) const if (!nb_page) return NULL; else - return nb_page->m_clientPanel; + return nb_page->m_client; }; void wxNotebook::AddChild( wxWindow *win ) { // @@@ normally done in wxWindow::AddChild but for some reason wxNotebook // case is special there (Robert?) + // Robert: Don't you think the code below looks different from the one + // in wxWindow::AddChild :-) + m_children.Append(win); + wxNotebookPage *page = new wxNotebookPage(); page->m_id = GetPageCount(); - page->m_label = (GtkLabel *)gtk_label_new("no caption"); - page->m_clientPanel = win; - gtk_notebook_append_page(GTK_NOTEBOOK(m_widget), win->m_widget, - (GtkWidget *)page->m_label); + page->m_label = (GtkLabel *)gtk_label_new("Handle"); + page->m_client = win; + gtk_notebook_append_page( GTK_NOTEBOOK(m_widget), win->m_widget, + (GtkWidget *)page->m_label); gtk_misc_set_alignment(GTK_MISC(page->m_label), 0.0, 0.5); - page->m_page = (GtkNotebookPage*) - ( - g_list_last(GTK_NOTEBOOK(m_widget)->children)->data - ); + page->m_page = + (GtkNotebookPage*) (g_list_last(GTK_NOTEBOOK(m_widget)->children)->data); + + page->m_parent = GTK_NOTEBOOK(m_widget); + gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", + GTK_SIGNAL_FUNC(gtk_notebook_client_size_callback), (gpointer)page ); + if (!page->m_page) { wxLogFatalError( "Notebook page creation error" ); @@ -388,22 +417,6 @@ void wxNotebook::AddChild( wxWindow *win ) m_pages.Append( page ); }; -void wxNotebook::OnSize(wxSizeEvent& event) -{ - // forward this event to all pages - wxNode *node = m_pages.First(); - while (node) - { - wxNotebookPage *page = (wxNotebookPage*)node->Data(); - // @@@@ This -50 is completely wrong - instead, we should substract - // the height of the tabs - page->m_clientPanel->SetSize(event.GetSize().GetX(), - event.GetSize().GetY() - 50); - - node = node->Next(); - }; -} - //----------------------------------------------------------------------------- // wxNotebookEvent //----------------------------------------------------------------------------- diff --git a/src/gtk1/bitmap.cpp b/src/gtk1/bitmap.cpp index eb09743ab8..05c3136acc 100644 --- a/src/gtk1/bitmap.cpp +++ b/src/gtk1/bitmap.cpp @@ -74,6 +74,9 @@ class wxBitmapRefData: public wxObjectRefData int m_width; int m_height; int m_bpp; +#ifdef USE_GDK_IMLIB + GdkImlibImage *m_image; +#endif wxPalette *m_palette; }; @@ -92,10 +95,11 @@ wxBitmapRefData::~wxBitmapRefData(void) { #ifdef USE_GDK_IMLIB if (m_pixmap) gdk_imlib_free_pixmap( m_pixmap ); + if (m_image) gdk_imlib_destroy_image( m_image ); #else if (m_pixmap) gdk_pixmap_unref( m_pixmap ); - if (m_bitmap) gdk_bitmap_unref( m_bitmap ); #endif + if (m_bitmap) gdk_bitmap_unref( m_bitmap ); if (m_mask) delete m_mask; if (m_palette) delete m_palette; }; @@ -126,22 +130,26 @@ wxBitmap::wxBitmap( int width, int height, int depth ) wxBitmap::wxBitmap( char **bits ) { m_refData = new wxBitmapRefData(); - - GdkBitmap *mask = NULL; #ifndef USE_GDK_IMLIB + + GdkBitmap *mask = NULL; + M_BMPDATA->m_pixmap = gdk_pixmap_create_from_xpm_d( (GdkWindow*) &gdk_root_parent, &mask, NULL, (gchar **) bits ); -#else - M_BMPDATA->m_pixmap = NULL; - int res = gdk_imlib_data_to_pixmap( bits, &M_BMPDATA->m_pixmap, &mask ); -#endif - + if (mask) { M_BMPDATA->m_mask = new wxMask(); M_BMPDATA->m_mask->m_bitmap = mask; }; + +#else + + M_BMPDATA->m_image = gdk_imlib_create_image_from_xpm_data( bits ); + Render(); + +#endif gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) ); M_BMPDATA->m_bpp = 24; // ? @@ -248,19 +256,57 @@ void wxBitmap::SetDepth( int depth ) wxMask *wxBitmap::GetMask(void) const { if (!Ok()) return NULL; + return M_BMPDATA->m_mask; }; void wxBitmap::SetMask( wxMask *mask ) { if (!Ok()) return; + if (M_BMPDATA->m_mask) delete M_BMPDATA->m_mask; M_BMPDATA->m_mask = mask; }; -bool wxBitmap::SaveFile( const wxString &WXUNUSED(name), int WXUNUSED(type), +void wxBitmap::Resize( int height, int width ) +{ + if (!Ok()) return; + + return; + +#ifdef USE_GDK_IMLIB + + if (M_BMPDATA->m_bitmap) return; // not supported for bitmaps + + if (!M_BMPDATA->m_image) RecreateImage(); + + if (M_BMPDATA->m_pixmap) gdk_imlib_free_pixmap( M_BMPDATA->m_pixmap ); + if (M_BMPDATA->m_mask) delete M_BMPDATA->m_mask; + + GdkImlibImage* image = gdk_imlib_clone_scaled_image( M_BMPDATA->m_image, height, width ); + gdk_imlib_destroy_image( M_BMPDATA->m_image ); + M_BMPDATA->m_image = image; + M_BMPDATA->m_height = height; + M_BMPDATA->m_width = width; + + Render(); + +#endif +}; + +bool wxBitmap::SaveFile( const wxString &name, int WXUNUSED(type), wxPalette *WXUNUSED(palette) ) { +#ifdef USE_GDK_IMLIB + + if (!Ok()) return FALSE; + + if (!M_BMPDATA->m_image) RecreateImage(); + + return gdk_imlib_save_image( M_BMPDATA->m_image, WXSTRINGCAST name, NULL ); + +#endif + return FALSE; }; @@ -270,23 +316,16 @@ bool wxBitmap::LoadFile( const wxString &name, int WXUNUSED(type) ) UnRef(); m_refData = new wxBitmapRefData(); - M_BMPDATA->m_mask = NULL; - - GdkBitmap *mask = NULL; - int res = gdk_imlib_load_file_to_pixmap( WXSTRINGCAST name, &M_BMPDATA->m_pixmap, &mask ); + M_BMPDATA->m_image = gdk_imlib_load_image( WXSTRINGCAST name ); - if (res != 1) + if (!M_BMPDATA->m_image) { UnRef(); return FALSE; }; - if (mask) - { - M_BMPDATA->m_mask = new wxMask(); - M_BMPDATA->m_mask->m_bitmap = mask; - } + Render(); gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) ); M_BMPDATA->m_bpp = 24; // ? @@ -312,6 +351,42 @@ GdkPixmap *wxBitmap::GetPixmap(void) const GdkBitmap *wxBitmap::GetBitmap(void) const { if (!Ok()) return NULL; + return M_BMPDATA->m_bitmap; }; +void wxBitmap::DestroyImage(void) +{ + if (!Ok()) return; + + if (M_BMPDATA->m_image) + { + gdk_imlib_destroy_image( M_BMPDATA->m_image ); + M_BMPDATA->m_image = NULL; + }; +}; + +void wxBitmap::RecreateImage(void) +{ +}; + +void wxBitmap::Render(void) +{ + if (!Ok()) return; + +#ifdef USE_GDK_IMLIB + + gdk_imlib_render( M_BMPDATA->m_image, M_BMPDATA->m_image->rgb_width, M_BMPDATA->m_image->rgb_height ); + + M_BMPDATA->m_pixmap = gdk_imlib_move_image( M_BMPDATA->m_image ); + GdkBitmap *mask = gdk_imlib_move_mask( M_BMPDATA->m_image ); + if (mask) + { + M_BMPDATA->m_mask = new wxMask(); + M_BMPDATA->m_mask->m_bitmap = mask; + }; + +#endif +}; + + diff --git a/src/gtk1/frame.cpp b/src/gtk1/frame.cpp index e78e9679b6..075ed1e7f6 100644 --- a/src/gtk1/frame.cpp +++ b/src/gtk1/frame.cpp @@ -42,7 +42,7 @@ void gtk_frame_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, printf( ".\n" ); */ - win->GtkOnSize( alloc->width, alloc->height ); + win->GtkOnSize( alloc->x, alloc->y, alloc->width, alloc->height ); }; //----------------------------------------------------------------------------- @@ -194,8 +194,11 @@ void wxFrame::GetClientSize( int *width, int *height ) const }; }; -void wxFrame::GtkOnSize( int width, int height ) +void wxFrame::GtkOnSize( int x, int y, int width, int height ) { + m_x = x; + m_y = y; + if ((m_height == height) && (m_width == width) && (m_sizeSet)) return; if (!m_mainWindow) return; diff --git a/src/gtk1/icon.cpp b/src/gtk1/icon.cpp index a65627746c..7ab4484537 100644 --- a/src/gtk1/icon.cpp +++ b/src/gtk1/icon.cpp @@ -20,3 +20,8 @@ IMPLEMENT_DYNAMIC_CLASS(wxIcon,wxBitmap) +wxIcon::wxIcon( char **bits, int WXUNUSED(width), int WXUNUSED(height) ) : + wxBitmap( bits ) +{ +}; + diff --git a/src/gtk1/notebook.cpp b/src/gtk1/notebook.cpp index eb1ac6d1b5..4021fcaf49 100644 --- a/src/gtk1/notebook.cpp +++ b/src/gtk1/notebook.cpp @@ -19,13 +19,40 @@ #include "wx/intl.h" #include "wx/log.h" +//----------------------------------------------------------------------------- +// wxNotebookPage +//----------------------------------------------------------------------------- + +class wxNotebookPage: public wxObject +{ +public: + wxNotebookPage() + { + m_id = -1; + m_text = ""; + m_image = -1; + m_page = NULL; + m_client = NULL; + m_parent = NULL; + }; + +//private: + int m_id; + wxString m_text; + int m_image; + GtkNotebookPage *m_page; + GtkLabel *m_label; + wxWindow *m_client; + GtkNotebook *m_parent; +}; + //----------------------------------------------------------------------------- // GTK callbacks //----------------------------------------------------------------------------- // page change callback -static void gtk_notebook_page_change_callback(GtkNotebook *widget, - GtkNotebookPage *page, +static void gtk_notebook_page_change_callback(GtkNotebook *WXUNUSED(widget), + GtkNotebookPage *WXUNUSED(page), gint nPage, gpointer data) { @@ -42,29 +69,24 @@ static void gtk_notebook_page_change_callback(GtkNotebook *widget, notebook->ProcessEvent(event); } -//----------------------------------------------------------------------------- -// wxNotebookPage -//----------------------------------------------------------------------------- - -class wxNotebookPage: public wxObject +static void gtk_notebook_client_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, + wxNotebookPage *page ) { -public: - wxNotebookPage() - { - m_id = -1; - m_text = ""; - m_image = -1; - m_page = NULL; - m_clientPanel = NULL; - }; - -//private: - int m_id; - wxString m_text; - int m_image; - GtkNotebookPage *m_page; - GtkLabel *m_label; - wxWindow *m_clientPanel; + if (!page->m_client->HasVMT()) return; + +/* + printf( "OnResize from " ); + if (page->m_client->GetClassInfo() && page->m_client->GetClassInfo()->GetClassName()) + printf( page->m_client->GetClassInfo()->GetClassName() ); + printf( ".\n" ); + + printf( " New: X: %d Y: %d ", alloc->x, alloc->y ); + printf( " W: %d H: %d ", alloc->width, alloc->height ); + printf( " .\n" ); +*/ + + page->m_client->SetSize( alloc->x, alloc->y+26, + alloc->width, alloc->height ); }; //----------------------------------------------------------------------------- @@ -195,7 +217,7 @@ wxNotebookPage* wxNotebook::GetNotebookPage(int page) const node = node->Next(); }; - wxLogDebug("Notebook page %d not found!", page); + wxLogDebug( "Notebook page %d not found!", page ); return NULL; }; @@ -305,7 +327,7 @@ bool wxNotebook::DeletePage( int page ) wxASSERT( child ); - delete nb_page->m_clientPanel; + delete nb_page->m_client; // Amazingly, this is not necessary // gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget), page_num ); @@ -328,7 +350,7 @@ bool wxNotebook::AddPage(wxWindow* win, const wxString& text, while (node) { page = (wxNotebookPage*)node->Data(); - if ( page->m_clientPanel == win ) + if ( page->m_client == win ) break; // found node = node->Next(); }; @@ -356,29 +378,36 @@ wxWindow *wxNotebook::GetPage( int page ) const if (!nb_page) return NULL; else - return nb_page->m_clientPanel; + return nb_page->m_client; }; void wxNotebook::AddChild( wxWindow *win ) { // @@@ normally done in wxWindow::AddChild but for some reason wxNotebook // case is special there (Robert?) + // Robert: Don't you think the code below looks different from the one + // in wxWindow::AddChild :-) + m_children.Append(win); + wxNotebookPage *page = new wxNotebookPage(); page->m_id = GetPageCount(); - page->m_label = (GtkLabel *)gtk_label_new("no caption"); - page->m_clientPanel = win; - gtk_notebook_append_page(GTK_NOTEBOOK(m_widget), win->m_widget, - (GtkWidget *)page->m_label); + page->m_label = (GtkLabel *)gtk_label_new("Handle"); + page->m_client = win; + gtk_notebook_append_page( GTK_NOTEBOOK(m_widget), win->m_widget, + (GtkWidget *)page->m_label); gtk_misc_set_alignment(GTK_MISC(page->m_label), 0.0, 0.5); - page->m_page = (GtkNotebookPage*) - ( - g_list_last(GTK_NOTEBOOK(m_widget)->children)->data - ); + page->m_page = + (GtkNotebookPage*) (g_list_last(GTK_NOTEBOOK(m_widget)->children)->data); + + page->m_parent = GTK_NOTEBOOK(m_widget); + gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", + GTK_SIGNAL_FUNC(gtk_notebook_client_size_callback), (gpointer)page ); + if (!page->m_page) { wxLogFatalError( "Notebook page creation error" ); @@ -388,22 +417,6 @@ void wxNotebook::AddChild( wxWindow *win ) m_pages.Append( page ); }; -void wxNotebook::OnSize(wxSizeEvent& event) -{ - // forward this event to all pages - wxNode *node = m_pages.First(); - while (node) - { - wxNotebookPage *page = (wxNotebookPage*)node->Data(); - // @@@@ This -50 is completely wrong - instead, we should substract - // the height of the tabs - page->m_clientPanel->SetSize(event.GetSize().GetX(), - event.GetSize().GetY() - 50); - - node = node->Next(); - }; -} - //----------------------------------------------------------------------------- // wxNotebookEvent //----------------------------------------------------------------------------- diff --git a/user/wxLayout/wxllist.h b/user/wxLayout/wxllist.h index d7d5d4b497..37e1e04cad 100644 --- a/user/wxLayout/wxllist.h +++ b/user/wxLayout/wxllist.h @@ -20,7 +20,7 @@ #ifndef MCONFIG_H // for testing only: # define WXLAYOUT_DEBUG -# cdefine USE_STD_STRING +# define USE_STD_STRING #endif #ifdef USE_STD_STRING -- 2.45.2