From 67a6726a2c83c6cb6e046311c23cca75c37fbbee Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Thu, 26 Apr 2001 18:58:09 +0000 Subject: [PATCH] Added Greg's wxBitmapButton patch, take 2. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9892 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/bmpbuttn.cpp | 70 +++++++++++++++++-------------------------- src/gtk1/bmpbuttn.cpp | 70 +++++++++++++++++-------------------------- 2 files changed, 56 insertions(+), 84 deletions(-) diff --git a/src/gtk/bmpbuttn.cpp b/src/gtk/bmpbuttn.cpp index b056ecbcbd..8fb62fc085 100644 --- a/src/gtk/bmpbuttn.cpp +++ b/src/gtk/bmpbuttn.cpp @@ -144,19 +144,11 @@ bool wxBitmapButton::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi if (m_bitmap.Ok()) { wxSize newSize = size; - - GdkBitmap *mask = (GdkBitmap *) NULL; - if (m_bitmap.GetMask()) mask = m_bitmap.GetMask()->GetBitmap(); - GtkWidget *pixmap = gtk_pixmap_new( m_bitmap.GetPixmap(), mask ); - - gtk_widget_show( pixmap ); - gtk_container_add( GTK_CONTAINER(m_widget), pixmap ); - - int border = 10; - if (style & wxNO_BORDER) border = 4; + int border = (style & wxNO_BORDER) ? 4 : 10; if (newSize.x == -1) newSize.x = m_bitmap.GetWidth()+border; if (newSize.y == -1) newSize.y = m_bitmap.GetHeight()+border; SetSize( newSize.x, newSize.y ); + SetBitmap(); } gtk_signal_connect( GTK_OBJECT(m_widget), "clicked", @@ -206,6 +198,9 @@ wxString wxBitmapButton::GetLabel() const void wxBitmapButton::ApplyWidgetStyle() { + if (GTK_BUTTON(m_widget)->child == NULL) return; + + wxButton::ApplyWidgetStyle(); } void wxBitmapButton::SetBitmap() @@ -213,51 +208,46 @@ void wxBitmapButton::SetBitmap() wxCHECK_RET( m_widget != NULL, wxT("invalid button") ); wxBitmap the_one; - if (!m_isEnabled) the_one = m_disabled; + else if (m_isSelected) + the_one = m_selected; + else if (m_hasFocus) + the_one = m_focus; else - { - if (m_isSelected) - { - the_one = m_selected; - } - else - { - if (m_hasFocus) - the_one = m_focus; - else - the_one = m_bitmap; - } - } + the_one = m_bitmap; if (!the_one.Ok()) the_one = m_bitmap; if (!the_one.Ok()) return; - GtkButton *bin = GTK_BUTTON( m_widget ); - GtkPixmap *g_pixmap = GTK_PIXMAP( bin->child ); - GdkBitmap *mask = (GdkBitmap *) NULL; if (the_one.GetMask()) mask = the_one.GetMask()->GetBitmap(); - gtk_pixmap_set( g_pixmap, the_one.GetPixmap(), mask ); + GtkButton *bin = GTK_BUTTON(m_widget); + if (bin->child == NULL) + { // initial bitmap + GtkWidget *pixmap = gtk_pixmap_new(the_one.GetPixmap(), mask); + gtk_widget_show(pixmap); + gtk_container_add(GTK_CONTAINER(m_widget), pixmap); + } + else + { // subsequent bitmaps + GtkPixmap *g_pixmap = GTK_PIXMAP(bin->child); + gtk_pixmap_set(g_pixmap, the_one.GetPixmap(), mask); + } } void wxBitmapButton::SetBitmapDisabled( const wxBitmap& bitmap ) { - wxCHECK_RET( m_widget != NULL, wxT("invalid button") ); - - if ( ! m_disabled.Ok() ) return; - m_disabled = bitmap; + if (!bitmap.Ok()) return; + m_disabled = bitmap; - SetBitmap(); + SetBitmap(); } void wxBitmapButton::SetBitmapFocus( const wxBitmap& bitmap ) { - wxCHECK_RET( m_widget != NULL, wxT("invalid button") ); - - if ( ! m_focus.Ok() ) return; + if (!bitmap.Ok()) return; m_focus = bitmap; SetBitmap(); @@ -265,9 +255,7 @@ void wxBitmapButton::SetBitmapFocus( const wxBitmap& bitmap ) void wxBitmapButton::SetBitmapLabel( const wxBitmap& bitmap ) { - wxCHECK_RET( m_widget != NULL, wxT("invalid button") ); - - if (!m_bitmap.Ok()) return; + if (!bitmap.Ok()) return; m_bitmap = bitmap; SetBitmap(); @@ -275,9 +263,7 @@ void wxBitmapButton::SetBitmapLabel( const wxBitmap& bitmap ) void wxBitmapButton::SetBitmapSelected( const wxBitmap& bitmap ) { - wxCHECK_RET( m_widget != NULL, wxT("invalid button") ); - - if ( ! m_selected.Ok() ) return; + if (!bitmap.Ok()) return; m_selected = bitmap; SetBitmap(); diff --git a/src/gtk1/bmpbuttn.cpp b/src/gtk1/bmpbuttn.cpp index b056ecbcbd..8fb62fc085 100644 --- a/src/gtk1/bmpbuttn.cpp +++ b/src/gtk1/bmpbuttn.cpp @@ -144,19 +144,11 @@ bool wxBitmapButton::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi if (m_bitmap.Ok()) { wxSize newSize = size; - - GdkBitmap *mask = (GdkBitmap *) NULL; - if (m_bitmap.GetMask()) mask = m_bitmap.GetMask()->GetBitmap(); - GtkWidget *pixmap = gtk_pixmap_new( m_bitmap.GetPixmap(), mask ); - - gtk_widget_show( pixmap ); - gtk_container_add( GTK_CONTAINER(m_widget), pixmap ); - - int border = 10; - if (style & wxNO_BORDER) border = 4; + int border = (style & wxNO_BORDER) ? 4 : 10; if (newSize.x == -1) newSize.x = m_bitmap.GetWidth()+border; if (newSize.y == -1) newSize.y = m_bitmap.GetHeight()+border; SetSize( newSize.x, newSize.y ); + SetBitmap(); } gtk_signal_connect( GTK_OBJECT(m_widget), "clicked", @@ -206,6 +198,9 @@ wxString wxBitmapButton::GetLabel() const void wxBitmapButton::ApplyWidgetStyle() { + if (GTK_BUTTON(m_widget)->child == NULL) return; + + wxButton::ApplyWidgetStyle(); } void wxBitmapButton::SetBitmap() @@ -213,51 +208,46 @@ void wxBitmapButton::SetBitmap() wxCHECK_RET( m_widget != NULL, wxT("invalid button") ); wxBitmap the_one; - if (!m_isEnabled) the_one = m_disabled; + else if (m_isSelected) + the_one = m_selected; + else if (m_hasFocus) + the_one = m_focus; else - { - if (m_isSelected) - { - the_one = m_selected; - } - else - { - if (m_hasFocus) - the_one = m_focus; - else - the_one = m_bitmap; - } - } + the_one = m_bitmap; if (!the_one.Ok()) the_one = m_bitmap; if (!the_one.Ok()) return; - GtkButton *bin = GTK_BUTTON( m_widget ); - GtkPixmap *g_pixmap = GTK_PIXMAP( bin->child ); - GdkBitmap *mask = (GdkBitmap *) NULL; if (the_one.GetMask()) mask = the_one.GetMask()->GetBitmap(); - gtk_pixmap_set( g_pixmap, the_one.GetPixmap(), mask ); + GtkButton *bin = GTK_BUTTON(m_widget); + if (bin->child == NULL) + { // initial bitmap + GtkWidget *pixmap = gtk_pixmap_new(the_one.GetPixmap(), mask); + gtk_widget_show(pixmap); + gtk_container_add(GTK_CONTAINER(m_widget), pixmap); + } + else + { // subsequent bitmaps + GtkPixmap *g_pixmap = GTK_PIXMAP(bin->child); + gtk_pixmap_set(g_pixmap, the_one.GetPixmap(), mask); + } } void wxBitmapButton::SetBitmapDisabled( const wxBitmap& bitmap ) { - wxCHECK_RET( m_widget != NULL, wxT("invalid button") ); - - if ( ! m_disabled.Ok() ) return; - m_disabled = bitmap; + if (!bitmap.Ok()) return; + m_disabled = bitmap; - SetBitmap(); + SetBitmap(); } void wxBitmapButton::SetBitmapFocus( const wxBitmap& bitmap ) { - wxCHECK_RET( m_widget != NULL, wxT("invalid button") ); - - if ( ! m_focus.Ok() ) return; + if (!bitmap.Ok()) return; m_focus = bitmap; SetBitmap(); @@ -265,9 +255,7 @@ void wxBitmapButton::SetBitmapFocus( const wxBitmap& bitmap ) void wxBitmapButton::SetBitmapLabel( const wxBitmap& bitmap ) { - wxCHECK_RET( m_widget != NULL, wxT("invalid button") ); - - if (!m_bitmap.Ok()) return; + if (!bitmap.Ok()) return; m_bitmap = bitmap; SetBitmap(); @@ -275,9 +263,7 @@ void wxBitmapButton::SetBitmapLabel( const wxBitmap& bitmap ) void wxBitmapButton::SetBitmapSelected( const wxBitmap& bitmap ) { - wxCHECK_RET( m_widget != NULL, wxT("invalid button") ); - - if ( ! m_selected.Ok() ) return; + if (!bitmap.Ok()) return; m_selected = bitmap; SetBitmap(); -- 2.45.2