From fc54776e31f04962739980d6cdcc894bb87a9c53 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Wed, 21 Oct 1998 22:21:09 +0000 Subject: [PATCH] SetBackground for ListBox and others Removed the old and famous wxSplitter bug git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@896 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/combobox.h | 1 + include/wx/gtk/dcclient.h | 2 +- include/wx/gtk/window.h | 7 +-- include/wx/gtk1/combobox.h | 1 + include/wx/gtk1/dcclient.h | 2 +- include/wx/gtk1/window.h | 7 +-- samples/controls/controls.cpp | 22 +++++-- src/gtk/combobox.cpp | 21 +++++++ src/gtk/dcclient.cpp | 44 +++++++------- src/gtk/dcmemory.cpp | 2 +- src/gtk/listbox.cpp | 104 +++++++++++++++++++++++++++++++--- src/gtk/textctrl.cpp | 9 ++- src/gtk/window.cpp | 22 +++---- src/gtk1/combobox.cpp | 21 +++++++ src/gtk1/dcclient.cpp | 44 +++++++------- src/gtk1/dcmemory.cpp | 2 +- src/gtk1/listbox.cpp | 104 +++++++++++++++++++++++++++++++--- src/gtk1/textctrl.cpp | 9 ++- src/gtk1/window.cpp | 22 +++---- 19 files changed, 334 insertions(+), 112 deletions(-) diff --git a/include/wx/gtk/combobox.h b/include/wx/gtk/combobox.h index c7d7b7064b..12c632e480 100644 --- a/include/wx/gtk/combobox.h +++ b/include/wx/gtk/combobox.h @@ -95,6 +95,7 @@ class wxComboBox: public wxControl void SetFont( const wxFont &font ); void OnSize( wxSizeEvent &event ); + void SetBackgroundColour( const wxColour &colour ); // implementation diff --git a/include/wx/gtk/dcclient.h b/include/wx/gtk/dcclient.h index d9c316aa34..be532ec577 100644 --- a/include/wx/gtk/dcclient.h +++ b/include/wx/gtk/dcclient.h @@ -100,7 +100,7 @@ class wxPaintDC: public wxDC GdkGC *m_textGC; GdkGC *m_bgGC; GdkColormap *m_cmap; - bool m_isDrawable; + bool m_isMemDC; void SetUpDC(void); GdkWindow *GetWindow(void); diff --git a/include/wx/gtk/window.h b/include/wx/gtk/window.h index e7438063b8..50556991dc 100644 --- a/include/wx/gtk/window.h +++ b/include/wx/gtk/window.h @@ -236,6 +236,8 @@ public: void ConnectWidget( GtkWidget *widget ); void ConnectDnDWidget( GtkWidget *widget ); void DisconnectDnDWidget( GtkWidget *widget ); + + void SetBackgroundColourHelper( GdkWindow *window ); void PreCreation( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style, const wxString &name ); @@ -315,11 +317,6 @@ public: virtual void GetClientSizeConstraint(int *w, int *h) const ; virtual void GetPositionConstraint(int *x, int *y) const ; -protected: - // set background colour for arbitrary window (useful because some windows - // don't work with m_wxwindow, e.g. wxTextCtrl) - void SetBackgroundColourHelper( const wxColour &colour, GdkWindow *window ); - private: DECLARE_EVENT_TABLE() }; diff --git a/include/wx/gtk1/combobox.h b/include/wx/gtk1/combobox.h index c7d7b7064b..12c632e480 100644 --- a/include/wx/gtk1/combobox.h +++ b/include/wx/gtk1/combobox.h @@ -95,6 +95,7 @@ class wxComboBox: public wxControl void SetFont( const wxFont &font ); void OnSize( wxSizeEvent &event ); + void SetBackgroundColour( const wxColour &colour ); // implementation diff --git a/include/wx/gtk1/dcclient.h b/include/wx/gtk1/dcclient.h index d9c316aa34..be532ec577 100644 --- a/include/wx/gtk1/dcclient.h +++ b/include/wx/gtk1/dcclient.h @@ -100,7 +100,7 @@ class wxPaintDC: public wxDC GdkGC *m_textGC; GdkGC *m_bgGC; GdkColormap *m_cmap; - bool m_isDrawable; + bool m_isMemDC; void SetUpDC(void); GdkWindow *GetWindow(void); diff --git a/include/wx/gtk1/window.h b/include/wx/gtk1/window.h index e7438063b8..50556991dc 100644 --- a/include/wx/gtk1/window.h +++ b/include/wx/gtk1/window.h @@ -236,6 +236,8 @@ public: void ConnectWidget( GtkWidget *widget ); void ConnectDnDWidget( GtkWidget *widget ); void DisconnectDnDWidget( GtkWidget *widget ); + + void SetBackgroundColourHelper( GdkWindow *window ); void PreCreation( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style, const wxString &name ); @@ -315,11 +317,6 @@ public: virtual void GetClientSizeConstraint(int *w, int *h) const ; virtual void GetPositionConstraint(int *x, int *y) const ; -protected: - // set background colour for arbitrary window (useful because some windows - // don't work with m_wxwindow, e.g. wxTextCtrl) - void SetBackgroundColourHelper( const wxColour &colour, GdkWindow *window ); - private: DECLARE_EVENT_TABLE() }; diff --git a/samples/controls/controls.cpp b/samples/controls/controls.cpp index c08ec582d9..82d5215fcd 100644 --- a/samples/controls/controls.cpp +++ b/samples/controls/controls.cpp @@ -28,6 +28,11 @@ #ifdef __WXGTK__ #include "mondrian.xpm" +#include "icons/choice.xpm" +#include "icons/combo.xpm" +#include "icons/list.xpm" +#include "icons/radio.xpm" +#include "icons/text.xpm" #endif //---------------------------------------------------------------------- @@ -227,6 +232,8 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) : Image_List, Image_Choice, Image_Combo, Image_Text, Image_Radio, Image_Max }; + // fill the image list +#ifdef __WXMSW__ const char *aIconNames[] = { "list.xpm", "choice.xpm", "combo.xpm", "text.xpm", "radio.xpm" @@ -234,15 +241,22 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) : wxASSERT( WXSIZEOF(aIconNames) == Image_Max ); // keep in sync - // TODO should find the dir from path to program - wxString strIconDir = "icons/"; - - // fill the image list + wxString strIconDir = "icons/"; + wxImageList *imagelist = new wxImageList(32, 32); for ( size_t n = 0; n < Image_Max; n++ ) { imagelist->Add(wxBitmap(strIconDir + aIconNames[n])); } +#else + wxImageList *imagelist = new wxImageList(32, 32); + + imagelist-> Add( wxBitmap( list_xpm )); + imagelist-> Add( wxBitmap( choice_xpm )); + imagelist-> Add( wxBitmap( combo_xpm )); + imagelist-> Add( wxBitmap( text_xpm )); + imagelist-> Add( wxBitmap( radio_xpm )); +#endif m_notebook->SetImageList(imagelist); diff --git a/src/gtk/combobox.cpp b/src/gtk/combobox.cpp index 9db6be50b8..efe78a6f3f 100644 --- a/src/gtk/combobox.cpp +++ b/src/gtk/combobox.cpp @@ -130,6 +130,12 @@ void wxComboBox::Append( const wxString &item, char *clientData ) gtk_widget_get_style( m_widget ) ) ); } + if (m_backgroundColour != wxNullColour) + { + GtkBin *bin = GTK_BIN( list_item ); + SetBackgroundColourHelper( bin->child->window ); + } + gtk_signal_connect( GTK_OBJECT(list_item), "select", GTK_SIGNAL_FUNC(gtk_combo_clicked_callback), (gpointer)this ); @@ -426,3 +432,18 @@ bool wxComboBox::IsOwnGtkWindow( GdkWindow *window ) (window == GTK_COMBO(m_widget)->button->window ) ); } +void wxComboBox::SetBackgroundColour( const wxColour &colour ) +{ + wxWindow::SetBackgroundColour( colour ); + + GtkWidget *list = GTK_COMBO(m_widget)->list; + + GList *child = GTK_LIST(list)->children; + while (child) + { + GtkBin *bin = (GtkBin*) child->data; + SetBackgroundColourHelper( bin->child->window ); + child = child->next; + } +} + diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index 84d0cebf07..17cd007433 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/dcclient.cpp @@ -92,6 +92,7 @@ wxPaintDC::wxPaintDC(void) m_textGC = (GdkGC *) NULL; m_bgGC = (GdkGC *) NULL; m_cmap = (GdkColormap *) NULL; + m_isMemDC = FALSE; } wxPaintDC::wxPaintDC( wxWindow *window ) @@ -112,7 +113,7 @@ wxPaintDC::wxPaintDC( wxWindow *window ) else m_cmap = gtk_widget_get_colormap( window->m_widget ); - m_isDrawable = TRUE; + m_isMemDC = FALSE; SetUpDC(); } @@ -137,9 +138,7 @@ void wxPaintDC::DrawLine( long x1, long y1, long x2, long y2 ) { if (!Ok()) return; - // FIXME: is this right? Causes a segfault on my system and doesn't - // seem right: wxPaintDC does not inherit from wxMemoryDC - // if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); if (m_pen.GetStyle() != wxTRANSPARENT) { @@ -152,9 +151,7 @@ void wxPaintDC::CrossHair( long x, long y ) { if (!Ok()) return; - // FIXME: is this right? Causes a segfault on my system and doesn't - // seem right: wxPaintDC does not inherit from wxMemoryDC - // if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); if (m_pen.GetStyle() != wxTRANSPARENT) { @@ -174,7 +171,7 @@ void wxPaintDC::DrawArc( long x1, long y1, long x2, long y2, double xc, double y { if (!Ok()) return; - if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); long xx1 = XLOG2DEV(x1); long yy1 = YLOG2DEV(y1); @@ -224,7 +221,7 @@ void wxPaintDC::DrawEllipticArc( long x, long y, long width, long height, double { if (!Ok()) return; - if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); long xx = XLOG2DEV(x); long yy = YLOG2DEV(y); @@ -248,7 +245,7 @@ void wxPaintDC::DrawPoint( long x, long y ) { if (!Ok()) return; - if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); if (m_pen.GetStyle() != wxTRANSPARENT) gdk_draw_point( m_window, m_penGC, XLOG2DEV(x), YLOG2DEV(y) ); @@ -258,7 +255,7 @@ void wxPaintDC::DrawLines( int n, wxPoint points[], long xoffset, long yoffset ) { if (!Ok()) return; - if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); if (m_pen.GetStyle() == wxTRANSPARENT) return; @@ -276,7 +273,7 @@ void wxPaintDC::DrawLines( wxList *points, long xoffset, long yoffset ) { if (!Ok()) return; - if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); if (m_pen.GetStyle() == wxTRANSPARENT) return; @@ -298,7 +295,7 @@ void wxPaintDC::DrawPolygon( int n, wxPoint points[], long xoffset, long yoffset { if (!Ok()) return; - if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); if (!n) return; // Nothing to draw GdkPoint *gdkpoints = new GdkPoint[n+1]; @@ -325,7 +322,7 @@ void wxPaintDC::DrawPolygon( wxList *lines, long xoffset, long yoffset, int WXUN { if (!Ok()) return; - if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); int n = lines->Number(); GdkPoint *gdkpoints = new GdkPoint[n]; @@ -359,7 +356,7 @@ void wxPaintDC::DrawRectangle( long x, long y, long width, long height ) { if (!Ok()) return; - if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); long xx = XLOG2DEV(x); long yy = YLOG2DEV(y); @@ -384,7 +381,7 @@ void wxPaintDC::DrawRoundedRectangle( long x, long y, long width, long height, d { if (!Ok()) return; - if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); if (radius < 0.0) radius = - radius * ((width < height) ? width : height); @@ -451,7 +448,7 @@ void wxPaintDC::DrawEllipse( long x, long y, long width, long height ) { if (!Ok()) return; - if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); long xx = XLOG2DEV(x); long yy = YLOG2DEV(y); @@ -480,7 +477,7 @@ void wxPaintDC::DrawIcon( const wxIcon &icon, long x, long y, bool useMask ) if (!icon.Ok()) return; - if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); int xx = XLOG2DEV(x); int yy = YLOG2DEV(y); @@ -509,10 +506,9 @@ bool wxPaintDC::Blit( long xdest, long ydest, long width, long height, { if (!Ok()) return FALSE; - if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); - // CMB 20/5/98: add blitting of bitmaps - if (source->IsKindOf(CLASSINFO(wxMemoryDC))) + if (m_isMemDC) { wxMemoryDC* srcDC = (wxMemoryDC*)source; GdkBitmap* bmap = srcDC->m_selected.GetBitmap(); @@ -551,7 +547,7 @@ void wxPaintDC::DrawText( const wxString &text, long x, long y, bool WXUNUSED(us { if (!Ok()) return; - if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); GdkFont *font = m_font.GetInternalFont( m_scaleY ); @@ -622,9 +618,9 @@ void wxPaintDC::Clear(void) { if (!Ok()) return; - if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); - if (m_isDrawable) + if (!m_isMemDC) { gdk_window_clear( m_window ); } diff --git a/src/gtk/dcmemory.cpp b/src/gtk/dcmemory.cpp index 84a6e144e7..aa8ab7a269 100644 --- a/src/gtk/dcmemory.cpp +++ b/src/gtk/dcmemory.cpp @@ -66,7 +66,7 @@ void wxMemoryDC::SelectObject( const wxBitmap& bitmap ) SetUpDC(); - m_isDrawable = FALSE; + m_isMemDC = TRUE; } else { diff --git a/src/gtk/listbox.cpp b/src/gtk/listbox.cpp index b8c301884b..7742d96c55 100644 --- a/src/gtk/listbox.cpp +++ b/src/gtk/listbox.cpp @@ -136,6 +136,8 @@ void wxListBox::Append( const wxString &item ) void wxListBox::Append( const wxString &item, char *clientData ) { + wxCHECK_RET( m_list != NULL, "invalid list ctrl" ); + GtkWidget *list_item = gtk_list_item_new_with_label( item ); if (m_hasOwnStyle) @@ -143,9 +145,13 @@ void wxListBox::Append( const wxString &item, char *clientData ) GtkBin *bin = GTK_BIN( list_item ); gtk_widget_set_style( bin->child, gtk_style_ref( - gtk_widget_get_style( m_widget ) ) ); + gtk_widget_get_style( GTK_WIDGET(m_list) ) ) ); + + gtk_widget_set_style( GTK_WIDGET(bin), + gtk_style_ref( + gtk_widget_get_style( GTK_WIDGET(m_list) ) ) ); } - + gtk_signal_connect( GTK_OBJECT(list_item), "select", GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this ); @@ -162,11 +168,12 @@ void wxListBox::Append( const wxString &item, char *clientData ) ConnectWidget( list_item ); ConnectDnDWidget( list_item ); - } void wxListBox::Clear(void) { + wxCHECK_RET( m_list != NULL, "invalid list ctrl" ); + gtk_list_clear_items( m_list, 0, Number() ); m_clientData.Clear(); @@ -174,6 +181,8 @@ void wxListBox::Clear(void) void wxListBox::Delete( int n ) { + wxCHECK_RET( m_list != NULL, "invalid list ctrl" ); + GList *child = g_list_nth( m_list->children, n ); if (!child) @@ -197,11 +206,15 @@ void wxListBox::Delete( int n ) void wxListBox::Deselect( int n ) { + wxCHECK_RET( m_list != NULL, "invalid list ctrl" ); + gtk_list_unselect_item( m_list, n ); } int wxListBox::FindString( const wxString &item ) const { + wxCHECK_MSG( m_list != NULL, -1, "invalid list ctrl" ); + GList *child = m_list->children; int count = 0; while (child) @@ -222,6 +235,8 @@ int wxListBox::FindString( const wxString &item ) const char *wxListBox::GetClientData( int n ) const { + wxCHECK_MSG( m_list != NULL, (char*) NULL, "invalid list ctrl" ); + wxNode *node = m_clientData.Nth( n ); if (node) return ((char*)node->Data()); @@ -231,6 +246,8 @@ char *wxListBox::GetClientData( int n ) const int wxListBox::GetSelection(void) const { + wxCHECK_MSG( m_list != NULL, -1, "invalid list ctrl" ); + GList *child = m_list->children; int count = 0; while (child) @@ -244,6 +261,8 @@ int wxListBox::GetSelection(void) const int wxListBox::GetSelections(wxArrayInt& aSelections) const { + wxCHECK_MSG( m_list != NULL, -1, "invalid list ctrl" ); + // get the number of selected items first GList *child = m_list->children; int count = 0; @@ -271,6 +290,8 @@ int wxListBox::GetSelections(wxArrayInt& aSelections) const wxString wxListBox::GetString( int n ) const { + wxCHECK_MSG( m_list != NULL, "", "invalid list ctrl" ); + GList *child = g_list_nth( m_list->children, n ); if (child) { @@ -284,6 +305,8 @@ wxString wxListBox::GetString( int n ) const wxString wxListBox::GetStringSelection(void) const { + wxCHECK_MSG( m_list != NULL, "", "invalid list ctrl" ); + GList *selection = m_list->selection; if (selection) { @@ -297,6 +320,8 @@ wxString wxListBox::GetStringSelection(void) const int wxListBox::Number(void) { + wxCHECK_MSG( m_list != NULL, -1, "invalid list ctrl" ); + GList *child = m_list->children; int count = 0; while (child) { count++; child = child->next; } @@ -305,6 +330,8 @@ int wxListBox::Number(void) bool wxListBox::Selected( int n ) { + wxCHECK_MSG( m_list != NULL, FALSE, "invalid list ctrl" ); + GList *target = g_list_nth( m_list->children, n ); if (target) { @@ -326,6 +353,8 @@ void wxListBox::Set( int WXUNUSED(n), const wxString *WXUNUSED(choices) ) void wxListBox::SetClientData( int n, char *clientData ) { + wxCHECK_RET( m_list != NULL, "invalid list ctrl" ); + wxNode *node = m_clientData.Nth( n ); if (node) { @@ -349,6 +378,8 @@ void wxListBox::SetFirstItem( const wxString &WXUNUSED(item) ) void wxListBox::SetSelection( int n, bool select ) { + wxCHECK_RET( m_list != NULL, "invalid list ctrl" ); + if (select) gtk_list_select_item( m_list, n ); else @@ -357,6 +388,8 @@ void wxListBox::SetSelection( int n, bool select ) void wxListBox::SetString( int n, const wxString &string ) { + wxCHECK_RET( m_list != NULL, "invalid list ctrl" ); + GList *child = g_list_nth( m_list->children, n ); if (child) { @@ -372,6 +405,8 @@ void wxListBox::SetString( int n, const wxString &string ) void wxListBox::SetStringSelection( const wxString &string, bool select ) { + wxCHECK_RET( m_list != NULL, "invalid list ctrl" ); + SetSelection( FindString(string), select ); } @@ -393,6 +428,8 @@ int wxListBox::GetIndex( GtkWidget *item ) const void wxListBox::SetDropTarget( wxDropTarget *dropTarget ) { + wxCHECK_RET( m_list != NULL, "invalid list ctrl" ); + GList *child = m_list->children; while (child) { @@ -417,7 +454,29 @@ GtkWidget *wxListBox::GetConnectWidget(void) void wxListBox::SetFont( const wxFont &font ) { - wxWindow::SetFont( font ); + wxCHECK_RET( m_list != NULL, "invalid list ctrl" ); + + if (((wxFont*)&font)->Ok()) + m_font = font; + else + m_font = *wxSWISS_FONT; + + GtkStyle *style = (GtkStyle*) NULL; + if (!m_hasOwnStyle) + { + m_hasOwnStyle = TRUE; + style = gtk_style_copy( gtk_widget_get_style( GTK_WIDGET(m_list) ) ); + } + else + { + style = gtk_widget_get_style( GTK_WIDGET(m_list) ); + } + + gdk_font_unref( style->font ); + style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) ); + + gtk_widget_set_style( GTK_WIDGET(m_list), style ); + GList *child = m_list->children; while (child) @@ -425,7 +484,7 @@ void wxListBox::SetFont( const wxFont &font ) GtkBin *bin = (GtkBin*) child->data; gtk_widget_set_style( bin->child, gtk_style_ref( - gtk_widget_get_style( m_widget ) ) ); + gtk_widget_get_style( GTK_WIDGET(m_list) ) ) ); child = child->next; } } @@ -437,7 +496,7 @@ bool wxListBox::IsOwnGtkWindow( GdkWindow *window ) GList *child = m_list->children; while (child) { - GtkBin *bin = (GtkBin*) child->data; + GtkBin *bin = GTK_BIN( child->data ); if (bin->child->window == window) return TRUE; child = child->next; } @@ -445,10 +504,39 @@ bool wxListBox::IsOwnGtkWindow( GdkWindow *window ) return FALSE; } -void wxListBox::SetBackgroundColour(const wxColour &colour) +void wxListBox::SetBackgroundColour( const wxColour &colour ) { wxCHECK_RET( m_list != NULL, "invalid list ctrl" ); - SetBackgroundColourHelper( colour, GTK_WIDGET(m_list)->window ); + m_backgroundColour = colour; + if (!m_backgroundColour.Ok()) return; + + SetBackgroundColourHelper( GTK_WIDGET(m_list)->window ); + + GtkStyle *style = (GtkStyle*) NULL; + if (!m_hasOwnStyle) + { + m_hasOwnStyle = TRUE; + style = gtk_style_copy( gtk_widget_get_style( GTK_WIDGET(m_list) ) ); + } + else + { + style = gtk_widget_get_style( GTK_WIDGET(m_list) ); + } + + style->base[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor(); + style->bg[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor(); + + gtk_widget_set_style( GTK_WIDGET(m_list), style ); + + GList *child = m_list->children; + while (child) + { + GtkWidget *item = GTK_WIDGET(child->data); + gtk_widget_set_style( item, + gtk_style_ref( + gtk_widget_get_style( GTK_WIDGET(m_list) ) ) ); + child = child->next; + } } diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index ed3763b079..08c6712364 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -464,12 +464,11 @@ void wxTextCtrl::SetFont( const wxFont &font ) gtk_widget_set_style( m_text, style ); } -// as our GTK widget is m_text and not m_widget, we have to override -// SetBackgroundColour() to make it work void wxTextCtrl::SetBackgroundColour( const wxColour &colour ) { wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); - - // NB: the GtkEntry and GtkText classes have text_area at the same offset - SetBackgroundColourHelper( colour, GTK_TEXT(m_text)->text_area ); + + m_backgroundColour = colour; + + SetBackgroundColourHelper( GTK_TEXT(m_text)->text_area ); } diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 54f342377a..1e6c3b6b92 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -1096,7 +1096,7 @@ void wxWindow::PreCreation( wxWindow *parent, wxWindowID id, if (m_cursor == NULL) m_cursor = new wxCursor( wxCURSOR_ARROW ); m_font = *wxSWISS_FONT; - m_backgroundColour = wxWHITE; +// m_backgroundColour = wxWHITE; m_foregroundColour = wxBLACK; m_windowStyle = style; m_windowName = name; @@ -1939,7 +1939,7 @@ bool wxWindow::IsExposed( const wxRect& rect ) const void wxWindow::Clear() { - wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + wxCHECK_RET( m_widget != NULL, "invalid window" ); if (m_wxwindow && m_wxwindow->window) gdk_window_clear( m_wxwindow->window ); } @@ -1949,21 +1949,23 @@ wxColour wxWindow::GetBackgroundColour() const return m_backgroundColour; } -void wxWindow::SetBackgroundColourHelper(const wxColour& colour, - GdkWindow *window) +void wxWindow::SetBackgroundColourHelper( GdkWindow *window ) { - m_backgroundColour = colour; - m_backgroundColour.CalcPixel( gdk_window_get_colormap(window) ); + if (!m_backgroundColour.Ok()) return; + + m_backgroundColour.CalcPixel( gdk_window_get_colormap( window ) ); gdk_window_set_background( window, m_backgroundColour.GetColor() ); gdk_window_clear( window ); } void wxWindow::SetBackgroundColour( const wxColour &colour ) { - wxASSERT_MSG( m_widget != NULL, "invalid window" ); + wxCHECK_RET( m_widget != NULL, "invalid window" ); + m_backgroundColour = colour; + GtkWidget *widget = m_wxwindow == NULL ? m_widget : m_wxwindow; - SetBackgroundColourHelper( colour, widget->window ); + SetBackgroundColourHelper( widget->window ); } wxColour wxWindow::GetForegroundColour() const @@ -1978,7 +1980,7 @@ void wxWindow::SetForegroundColour( const wxColour &colour ) bool wxWindow::Validate() { - wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + wxCHECK_MSG( m_widget != NULL, FALSE, "invalid window" ); wxNode *node = GetChildren()->First(); while (node) @@ -1993,7 +1995,7 @@ bool wxWindow::Validate() bool wxWindow::TransferDataToWindow() { - wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + wxCHECK_MSG( m_widget != NULL, FALSE, "invalid window" ); wxNode *node = GetChildren()->First(); while (node) diff --git a/src/gtk1/combobox.cpp b/src/gtk1/combobox.cpp index 9db6be50b8..efe78a6f3f 100644 --- a/src/gtk1/combobox.cpp +++ b/src/gtk1/combobox.cpp @@ -130,6 +130,12 @@ void wxComboBox::Append( const wxString &item, char *clientData ) gtk_widget_get_style( m_widget ) ) ); } + if (m_backgroundColour != wxNullColour) + { + GtkBin *bin = GTK_BIN( list_item ); + SetBackgroundColourHelper( bin->child->window ); + } + gtk_signal_connect( GTK_OBJECT(list_item), "select", GTK_SIGNAL_FUNC(gtk_combo_clicked_callback), (gpointer)this ); @@ -426,3 +432,18 @@ bool wxComboBox::IsOwnGtkWindow( GdkWindow *window ) (window == GTK_COMBO(m_widget)->button->window ) ); } +void wxComboBox::SetBackgroundColour( const wxColour &colour ) +{ + wxWindow::SetBackgroundColour( colour ); + + GtkWidget *list = GTK_COMBO(m_widget)->list; + + GList *child = GTK_LIST(list)->children; + while (child) + { + GtkBin *bin = (GtkBin*) child->data; + SetBackgroundColourHelper( bin->child->window ); + child = child->next; + } +} + diff --git a/src/gtk1/dcclient.cpp b/src/gtk1/dcclient.cpp index 84d0cebf07..17cd007433 100644 --- a/src/gtk1/dcclient.cpp +++ b/src/gtk1/dcclient.cpp @@ -92,6 +92,7 @@ wxPaintDC::wxPaintDC(void) m_textGC = (GdkGC *) NULL; m_bgGC = (GdkGC *) NULL; m_cmap = (GdkColormap *) NULL; + m_isMemDC = FALSE; } wxPaintDC::wxPaintDC( wxWindow *window ) @@ -112,7 +113,7 @@ wxPaintDC::wxPaintDC( wxWindow *window ) else m_cmap = gtk_widget_get_colormap( window->m_widget ); - m_isDrawable = TRUE; + m_isMemDC = FALSE; SetUpDC(); } @@ -137,9 +138,7 @@ void wxPaintDC::DrawLine( long x1, long y1, long x2, long y2 ) { if (!Ok()) return; - // FIXME: is this right? Causes a segfault on my system and doesn't - // seem right: wxPaintDC does not inherit from wxMemoryDC - // if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); if (m_pen.GetStyle() != wxTRANSPARENT) { @@ -152,9 +151,7 @@ void wxPaintDC::CrossHair( long x, long y ) { if (!Ok()) return; - // FIXME: is this right? Causes a segfault on my system and doesn't - // seem right: wxPaintDC does not inherit from wxMemoryDC - // if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); if (m_pen.GetStyle() != wxTRANSPARENT) { @@ -174,7 +171,7 @@ void wxPaintDC::DrawArc( long x1, long y1, long x2, long y2, double xc, double y { if (!Ok()) return; - if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); long xx1 = XLOG2DEV(x1); long yy1 = YLOG2DEV(y1); @@ -224,7 +221,7 @@ void wxPaintDC::DrawEllipticArc( long x, long y, long width, long height, double { if (!Ok()) return; - if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); long xx = XLOG2DEV(x); long yy = YLOG2DEV(y); @@ -248,7 +245,7 @@ void wxPaintDC::DrawPoint( long x, long y ) { if (!Ok()) return; - if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); if (m_pen.GetStyle() != wxTRANSPARENT) gdk_draw_point( m_window, m_penGC, XLOG2DEV(x), YLOG2DEV(y) ); @@ -258,7 +255,7 @@ void wxPaintDC::DrawLines( int n, wxPoint points[], long xoffset, long yoffset ) { if (!Ok()) return; - if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); if (m_pen.GetStyle() == wxTRANSPARENT) return; @@ -276,7 +273,7 @@ void wxPaintDC::DrawLines( wxList *points, long xoffset, long yoffset ) { if (!Ok()) return; - if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); if (m_pen.GetStyle() == wxTRANSPARENT) return; @@ -298,7 +295,7 @@ void wxPaintDC::DrawPolygon( int n, wxPoint points[], long xoffset, long yoffset { if (!Ok()) return; - if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); if (!n) return; // Nothing to draw GdkPoint *gdkpoints = new GdkPoint[n+1]; @@ -325,7 +322,7 @@ void wxPaintDC::DrawPolygon( wxList *lines, long xoffset, long yoffset, int WXUN { if (!Ok()) return; - if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); int n = lines->Number(); GdkPoint *gdkpoints = new GdkPoint[n]; @@ -359,7 +356,7 @@ void wxPaintDC::DrawRectangle( long x, long y, long width, long height ) { if (!Ok()) return; - if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); long xx = XLOG2DEV(x); long yy = YLOG2DEV(y); @@ -384,7 +381,7 @@ void wxPaintDC::DrawRoundedRectangle( long x, long y, long width, long height, d { if (!Ok()) return; - if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); if (radius < 0.0) radius = - radius * ((width < height) ? width : height); @@ -451,7 +448,7 @@ void wxPaintDC::DrawEllipse( long x, long y, long width, long height ) { if (!Ok()) return; - if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); long xx = XLOG2DEV(x); long yy = YLOG2DEV(y); @@ -480,7 +477,7 @@ void wxPaintDC::DrawIcon( const wxIcon &icon, long x, long y, bool useMask ) if (!icon.Ok()) return; - if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); int xx = XLOG2DEV(x); int yy = YLOG2DEV(y); @@ -509,10 +506,9 @@ bool wxPaintDC::Blit( long xdest, long ydest, long width, long height, { if (!Ok()) return FALSE; - if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); - // CMB 20/5/98: add blitting of bitmaps - if (source->IsKindOf(CLASSINFO(wxMemoryDC))) + if (m_isMemDC) { wxMemoryDC* srcDC = (wxMemoryDC*)source; GdkBitmap* bmap = srcDC->m_selected.GetBitmap(); @@ -551,7 +547,7 @@ void wxPaintDC::DrawText( const wxString &text, long x, long y, bool WXUNUSED(us { if (!Ok()) return; - if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); GdkFont *font = m_font.GetInternalFont( m_scaleY ); @@ -622,9 +618,9 @@ void wxPaintDC::Clear(void) { if (!Ok()) return; - if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage(); + if (m_isMemDC) ((wxMemoryDC*)this)->m_selected.DestroyImage(); - if (m_isDrawable) + if (!m_isMemDC) { gdk_window_clear( m_window ); } diff --git a/src/gtk1/dcmemory.cpp b/src/gtk1/dcmemory.cpp index 84a6e144e7..aa8ab7a269 100644 --- a/src/gtk1/dcmemory.cpp +++ b/src/gtk1/dcmemory.cpp @@ -66,7 +66,7 @@ void wxMemoryDC::SelectObject( const wxBitmap& bitmap ) SetUpDC(); - m_isDrawable = FALSE; + m_isMemDC = TRUE; } else { diff --git a/src/gtk1/listbox.cpp b/src/gtk1/listbox.cpp index b8c301884b..7742d96c55 100644 --- a/src/gtk1/listbox.cpp +++ b/src/gtk1/listbox.cpp @@ -136,6 +136,8 @@ void wxListBox::Append( const wxString &item ) void wxListBox::Append( const wxString &item, char *clientData ) { + wxCHECK_RET( m_list != NULL, "invalid list ctrl" ); + GtkWidget *list_item = gtk_list_item_new_with_label( item ); if (m_hasOwnStyle) @@ -143,9 +145,13 @@ void wxListBox::Append( const wxString &item, char *clientData ) GtkBin *bin = GTK_BIN( list_item ); gtk_widget_set_style( bin->child, gtk_style_ref( - gtk_widget_get_style( m_widget ) ) ); + gtk_widget_get_style( GTK_WIDGET(m_list) ) ) ); + + gtk_widget_set_style( GTK_WIDGET(bin), + gtk_style_ref( + gtk_widget_get_style( GTK_WIDGET(m_list) ) ) ); } - + gtk_signal_connect( GTK_OBJECT(list_item), "select", GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this ); @@ -162,11 +168,12 @@ void wxListBox::Append( const wxString &item, char *clientData ) ConnectWidget( list_item ); ConnectDnDWidget( list_item ); - } void wxListBox::Clear(void) { + wxCHECK_RET( m_list != NULL, "invalid list ctrl" ); + gtk_list_clear_items( m_list, 0, Number() ); m_clientData.Clear(); @@ -174,6 +181,8 @@ void wxListBox::Clear(void) void wxListBox::Delete( int n ) { + wxCHECK_RET( m_list != NULL, "invalid list ctrl" ); + GList *child = g_list_nth( m_list->children, n ); if (!child) @@ -197,11 +206,15 @@ void wxListBox::Delete( int n ) void wxListBox::Deselect( int n ) { + wxCHECK_RET( m_list != NULL, "invalid list ctrl" ); + gtk_list_unselect_item( m_list, n ); } int wxListBox::FindString( const wxString &item ) const { + wxCHECK_MSG( m_list != NULL, -1, "invalid list ctrl" ); + GList *child = m_list->children; int count = 0; while (child) @@ -222,6 +235,8 @@ int wxListBox::FindString( const wxString &item ) const char *wxListBox::GetClientData( int n ) const { + wxCHECK_MSG( m_list != NULL, (char*) NULL, "invalid list ctrl" ); + wxNode *node = m_clientData.Nth( n ); if (node) return ((char*)node->Data()); @@ -231,6 +246,8 @@ char *wxListBox::GetClientData( int n ) const int wxListBox::GetSelection(void) const { + wxCHECK_MSG( m_list != NULL, -1, "invalid list ctrl" ); + GList *child = m_list->children; int count = 0; while (child) @@ -244,6 +261,8 @@ int wxListBox::GetSelection(void) const int wxListBox::GetSelections(wxArrayInt& aSelections) const { + wxCHECK_MSG( m_list != NULL, -1, "invalid list ctrl" ); + // get the number of selected items first GList *child = m_list->children; int count = 0; @@ -271,6 +290,8 @@ int wxListBox::GetSelections(wxArrayInt& aSelections) const wxString wxListBox::GetString( int n ) const { + wxCHECK_MSG( m_list != NULL, "", "invalid list ctrl" ); + GList *child = g_list_nth( m_list->children, n ); if (child) { @@ -284,6 +305,8 @@ wxString wxListBox::GetString( int n ) const wxString wxListBox::GetStringSelection(void) const { + wxCHECK_MSG( m_list != NULL, "", "invalid list ctrl" ); + GList *selection = m_list->selection; if (selection) { @@ -297,6 +320,8 @@ wxString wxListBox::GetStringSelection(void) const int wxListBox::Number(void) { + wxCHECK_MSG( m_list != NULL, -1, "invalid list ctrl" ); + GList *child = m_list->children; int count = 0; while (child) { count++; child = child->next; } @@ -305,6 +330,8 @@ int wxListBox::Number(void) bool wxListBox::Selected( int n ) { + wxCHECK_MSG( m_list != NULL, FALSE, "invalid list ctrl" ); + GList *target = g_list_nth( m_list->children, n ); if (target) { @@ -326,6 +353,8 @@ void wxListBox::Set( int WXUNUSED(n), const wxString *WXUNUSED(choices) ) void wxListBox::SetClientData( int n, char *clientData ) { + wxCHECK_RET( m_list != NULL, "invalid list ctrl" ); + wxNode *node = m_clientData.Nth( n ); if (node) { @@ -349,6 +378,8 @@ void wxListBox::SetFirstItem( const wxString &WXUNUSED(item) ) void wxListBox::SetSelection( int n, bool select ) { + wxCHECK_RET( m_list != NULL, "invalid list ctrl" ); + if (select) gtk_list_select_item( m_list, n ); else @@ -357,6 +388,8 @@ void wxListBox::SetSelection( int n, bool select ) void wxListBox::SetString( int n, const wxString &string ) { + wxCHECK_RET( m_list != NULL, "invalid list ctrl" ); + GList *child = g_list_nth( m_list->children, n ); if (child) { @@ -372,6 +405,8 @@ void wxListBox::SetString( int n, const wxString &string ) void wxListBox::SetStringSelection( const wxString &string, bool select ) { + wxCHECK_RET( m_list != NULL, "invalid list ctrl" ); + SetSelection( FindString(string), select ); } @@ -393,6 +428,8 @@ int wxListBox::GetIndex( GtkWidget *item ) const void wxListBox::SetDropTarget( wxDropTarget *dropTarget ) { + wxCHECK_RET( m_list != NULL, "invalid list ctrl" ); + GList *child = m_list->children; while (child) { @@ -417,7 +454,29 @@ GtkWidget *wxListBox::GetConnectWidget(void) void wxListBox::SetFont( const wxFont &font ) { - wxWindow::SetFont( font ); + wxCHECK_RET( m_list != NULL, "invalid list ctrl" ); + + if (((wxFont*)&font)->Ok()) + m_font = font; + else + m_font = *wxSWISS_FONT; + + GtkStyle *style = (GtkStyle*) NULL; + if (!m_hasOwnStyle) + { + m_hasOwnStyle = TRUE; + style = gtk_style_copy( gtk_widget_get_style( GTK_WIDGET(m_list) ) ); + } + else + { + style = gtk_widget_get_style( GTK_WIDGET(m_list) ); + } + + gdk_font_unref( style->font ); + style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) ); + + gtk_widget_set_style( GTK_WIDGET(m_list), style ); + GList *child = m_list->children; while (child) @@ -425,7 +484,7 @@ void wxListBox::SetFont( const wxFont &font ) GtkBin *bin = (GtkBin*) child->data; gtk_widget_set_style( bin->child, gtk_style_ref( - gtk_widget_get_style( m_widget ) ) ); + gtk_widget_get_style( GTK_WIDGET(m_list) ) ) ); child = child->next; } } @@ -437,7 +496,7 @@ bool wxListBox::IsOwnGtkWindow( GdkWindow *window ) GList *child = m_list->children; while (child) { - GtkBin *bin = (GtkBin*) child->data; + GtkBin *bin = GTK_BIN( child->data ); if (bin->child->window == window) return TRUE; child = child->next; } @@ -445,10 +504,39 @@ bool wxListBox::IsOwnGtkWindow( GdkWindow *window ) return FALSE; } -void wxListBox::SetBackgroundColour(const wxColour &colour) +void wxListBox::SetBackgroundColour( const wxColour &colour ) { wxCHECK_RET( m_list != NULL, "invalid list ctrl" ); - SetBackgroundColourHelper( colour, GTK_WIDGET(m_list)->window ); + m_backgroundColour = colour; + if (!m_backgroundColour.Ok()) return; + + SetBackgroundColourHelper( GTK_WIDGET(m_list)->window ); + + GtkStyle *style = (GtkStyle*) NULL; + if (!m_hasOwnStyle) + { + m_hasOwnStyle = TRUE; + style = gtk_style_copy( gtk_widget_get_style( GTK_WIDGET(m_list) ) ); + } + else + { + style = gtk_widget_get_style( GTK_WIDGET(m_list) ); + } + + style->base[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor(); + style->bg[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor(); + + gtk_widget_set_style( GTK_WIDGET(m_list), style ); + + GList *child = m_list->children; + while (child) + { + GtkWidget *item = GTK_WIDGET(child->data); + gtk_widget_set_style( item, + gtk_style_ref( + gtk_widget_get_style( GTK_WIDGET(m_list) ) ) ); + child = child->next; + } } diff --git a/src/gtk1/textctrl.cpp b/src/gtk1/textctrl.cpp index ed3763b079..08c6712364 100644 --- a/src/gtk1/textctrl.cpp +++ b/src/gtk1/textctrl.cpp @@ -464,12 +464,11 @@ void wxTextCtrl::SetFont( const wxFont &font ) gtk_widget_set_style( m_text, style ); } -// as our GTK widget is m_text and not m_widget, we have to override -// SetBackgroundColour() to make it work void wxTextCtrl::SetBackgroundColour( const wxColour &colour ) { wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); - - // NB: the GtkEntry and GtkText classes have text_area at the same offset - SetBackgroundColourHelper( colour, GTK_TEXT(m_text)->text_area ); + + m_backgroundColour = colour; + + SetBackgroundColourHelper( GTK_TEXT(m_text)->text_area ); } diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index 54f342377a..1e6c3b6b92 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -1096,7 +1096,7 @@ void wxWindow::PreCreation( wxWindow *parent, wxWindowID id, if (m_cursor == NULL) m_cursor = new wxCursor( wxCURSOR_ARROW ); m_font = *wxSWISS_FONT; - m_backgroundColour = wxWHITE; +// m_backgroundColour = wxWHITE; m_foregroundColour = wxBLACK; m_windowStyle = style; m_windowName = name; @@ -1939,7 +1939,7 @@ bool wxWindow::IsExposed( const wxRect& rect ) const void wxWindow::Clear() { - wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + wxCHECK_RET( m_widget != NULL, "invalid window" ); if (m_wxwindow && m_wxwindow->window) gdk_window_clear( m_wxwindow->window ); } @@ -1949,21 +1949,23 @@ wxColour wxWindow::GetBackgroundColour() const return m_backgroundColour; } -void wxWindow::SetBackgroundColourHelper(const wxColour& colour, - GdkWindow *window) +void wxWindow::SetBackgroundColourHelper( GdkWindow *window ) { - m_backgroundColour = colour; - m_backgroundColour.CalcPixel( gdk_window_get_colormap(window) ); + if (!m_backgroundColour.Ok()) return; + + m_backgroundColour.CalcPixel( gdk_window_get_colormap( window ) ); gdk_window_set_background( window, m_backgroundColour.GetColor() ); gdk_window_clear( window ); } void wxWindow::SetBackgroundColour( const wxColour &colour ) { - wxASSERT_MSG( m_widget != NULL, "invalid window" ); + wxCHECK_RET( m_widget != NULL, "invalid window" ); + m_backgroundColour = colour; + GtkWidget *widget = m_wxwindow == NULL ? m_widget : m_wxwindow; - SetBackgroundColourHelper( colour, widget->window ); + SetBackgroundColourHelper( widget->window ); } wxColour wxWindow::GetForegroundColour() const @@ -1978,7 +1980,7 @@ void wxWindow::SetForegroundColour( const wxColour &colour ) bool wxWindow::Validate() { - wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + wxCHECK_MSG( m_widget != NULL, FALSE, "invalid window" ); wxNode *node = GetChildren()->First(); while (node) @@ -1993,7 +1995,7 @@ bool wxWindow::Validate() bool wxWindow::TransferDataToWindow() { - wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + wxCHECK_MSG( m_widget != NULL, FALSE, "invalid window" ); wxNode *node = GetChildren()->First(); while (node) -- 2.45.2