Added Greg's wxBitmapButton patch, take 2.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9892 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -144,19 +144,11 @@ bool wxBitmapButton::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi
|
|||||||
if (m_bitmap.Ok())
|
if (m_bitmap.Ok())
|
||||||
{
|
{
|
||||||
wxSize newSize = size;
|
wxSize newSize = size;
|
||||||
|
int border = (style & wxNO_BORDER) ? 4 : 10;
|
||||||
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;
|
|
||||||
if (newSize.x == -1) newSize.x = m_bitmap.GetWidth()+border;
|
if (newSize.x == -1) newSize.x = m_bitmap.GetWidth()+border;
|
||||||
if (newSize.y == -1) newSize.y = m_bitmap.GetHeight()+border;
|
if (newSize.y == -1) newSize.y = m_bitmap.GetHeight()+border;
|
||||||
SetSize( newSize.x, newSize.y );
|
SetSize( newSize.x, newSize.y );
|
||||||
|
SetBitmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
|
gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
|
||||||
@@ -206,6 +198,9 @@ wxString wxBitmapButton::GetLabel() const
|
|||||||
|
|
||||||
void wxBitmapButton::ApplyWidgetStyle()
|
void wxBitmapButton::ApplyWidgetStyle()
|
||||||
{
|
{
|
||||||
|
if (GTK_BUTTON(m_widget)->child == NULL) return;
|
||||||
|
|
||||||
|
wxButton::ApplyWidgetStyle();
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxBitmapButton::SetBitmap()
|
void wxBitmapButton::SetBitmap()
|
||||||
@@ -213,41 +208,38 @@ void wxBitmapButton::SetBitmap()
|
|||||||
wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
|
wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
|
||||||
|
|
||||||
wxBitmap the_one;
|
wxBitmap the_one;
|
||||||
|
|
||||||
if (!m_isEnabled)
|
if (!m_isEnabled)
|
||||||
the_one = m_disabled;
|
the_one = m_disabled;
|
||||||
else
|
else if (m_isSelected)
|
||||||
{
|
|
||||||
if (m_isSelected)
|
|
||||||
{
|
|
||||||
the_one = m_selected;
|
the_one = m_selected;
|
||||||
}
|
else if (m_hasFocus)
|
||||||
else
|
|
||||||
{
|
|
||||||
if (m_hasFocus)
|
|
||||||
the_one = m_focus;
|
the_one = m_focus;
|
||||||
else
|
else
|
||||||
the_one = m_bitmap;
|
the_one = m_bitmap;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!the_one.Ok()) the_one = m_bitmap;
|
if (!the_one.Ok()) the_one = m_bitmap;
|
||||||
if (!the_one.Ok()) return;
|
if (!the_one.Ok()) return;
|
||||||
|
|
||||||
GtkButton *bin = GTK_BUTTON( m_widget );
|
|
||||||
GtkPixmap *g_pixmap = GTK_PIXMAP( bin->child );
|
|
||||||
|
|
||||||
GdkBitmap *mask = (GdkBitmap *) NULL;
|
GdkBitmap *mask = (GdkBitmap *) NULL;
|
||||||
if (the_one.GetMask()) mask = the_one.GetMask()->GetBitmap();
|
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 )
|
void wxBitmapButton::SetBitmapDisabled( const wxBitmap& bitmap )
|
||||||
{
|
{
|
||||||
wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
|
if (!bitmap.Ok()) return;
|
||||||
|
|
||||||
if ( ! m_disabled.Ok() ) return;
|
|
||||||
m_disabled = bitmap;
|
m_disabled = bitmap;
|
||||||
|
|
||||||
SetBitmap();
|
SetBitmap();
|
||||||
@@ -255,9 +247,7 @@ void wxBitmapButton::SetBitmapDisabled( const wxBitmap& bitmap )
|
|||||||
|
|
||||||
void wxBitmapButton::SetBitmapFocus( const wxBitmap& bitmap )
|
void wxBitmapButton::SetBitmapFocus( const wxBitmap& bitmap )
|
||||||
{
|
{
|
||||||
wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
|
if (!bitmap.Ok()) return;
|
||||||
|
|
||||||
if ( ! m_focus.Ok() ) return;
|
|
||||||
m_focus = bitmap;
|
m_focus = bitmap;
|
||||||
|
|
||||||
SetBitmap();
|
SetBitmap();
|
||||||
@@ -265,9 +255,7 @@ void wxBitmapButton::SetBitmapFocus( const wxBitmap& bitmap )
|
|||||||
|
|
||||||
void wxBitmapButton::SetBitmapLabel( const wxBitmap& bitmap )
|
void wxBitmapButton::SetBitmapLabel( const wxBitmap& bitmap )
|
||||||
{
|
{
|
||||||
wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
|
if (!bitmap.Ok()) return;
|
||||||
|
|
||||||
if (!m_bitmap.Ok()) return;
|
|
||||||
m_bitmap = bitmap;
|
m_bitmap = bitmap;
|
||||||
|
|
||||||
SetBitmap();
|
SetBitmap();
|
||||||
@@ -275,9 +263,7 @@ void wxBitmapButton::SetBitmapLabel( const wxBitmap& bitmap )
|
|||||||
|
|
||||||
void wxBitmapButton::SetBitmapSelected( const wxBitmap& bitmap )
|
void wxBitmapButton::SetBitmapSelected( const wxBitmap& bitmap )
|
||||||
{
|
{
|
||||||
wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
|
if (!bitmap.Ok()) return;
|
||||||
|
|
||||||
if ( ! m_selected.Ok() ) return;
|
|
||||||
m_selected = bitmap;
|
m_selected = bitmap;
|
||||||
|
|
||||||
SetBitmap();
|
SetBitmap();
|
||||||
|
@@ -144,19 +144,11 @@ bool wxBitmapButton::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi
|
|||||||
if (m_bitmap.Ok())
|
if (m_bitmap.Ok())
|
||||||
{
|
{
|
||||||
wxSize newSize = size;
|
wxSize newSize = size;
|
||||||
|
int border = (style & wxNO_BORDER) ? 4 : 10;
|
||||||
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;
|
|
||||||
if (newSize.x == -1) newSize.x = m_bitmap.GetWidth()+border;
|
if (newSize.x == -1) newSize.x = m_bitmap.GetWidth()+border;
|
||||||
if (newSize.y == -1) newSize.y = m_bitmap.GetHeight()+border;
|
if (newSize.y == -1) newSize.y = m_bitmap.GetHeight()+border;
|
||||||
SetSize( newSize.x, newSize.y );
|
SetSize( newSize.x, newSize.y );
|
||||||
|
SetBitmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
|
gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
|
||||||
@@ -206,6 +198,9 @@ wxString wxBitmapButton::GetLabel() const
|
|||||||
|
|
||||||
void wxBitmapButton::ApplyWidgetStyle()
|
void wxBitmapButton::ApplyWidgetStyle()
|
||||||
{
|
{
|
||||||
|
if (GTK_BUTTON(m_widget)->child == NULL) return;
|
||||||
|
|
||||||
|
wxButton::ApplyWidgetStyle();
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxBitmapButton::SetBitmap()
|
void wxBitmapButton::SetBitmap()
|
||||||
@@ -213,41 +208,38 @@ void wxBitmapButton::SetBitmap()
|
|||||||
wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
|
wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
|
||||||
|
|
||||||
wxBitmap the_one;
|
wxBitmap the_one;
|
||||||
|
|
||||||
if (!m_isEnabled)
|
if (!m_isEnabled)
|
||||||
the_one = m_disabled;
|
the_one = m_disabled;
|
||||||
else
|
else if (m_isSelected)
|
||||||
{
|
|
||||||
if (m_isSelected)
|
|
||||||
{
|
|
||||||
the_one = m_selected;
|
the_one = m_selected;
|
||||||
}
|
else if (m_hasFocus)
|
||||||
else
|
|
||||||
{
|
|
||||||
if (m_hasFocus)
|
|
||||||
the_one = m_focus;
|
the_one = m_focus;
|
||||||
else
|
else
|
||||||
the_one = m_bitmap;
|
the_one = m_bitmap;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!the_one.Ok()) the_one = m_bitmap;
|
if (!the_one.Ok()) the_one = m_bitmap;
|
||||||
if (!the_one.Ok()) return;
|
if (!the_one.Ok()) return;
|
||||||
|
|
||||||
GtkButton *bin = GTK_BUTTON( m_widget );
|
|
||||||
GtkPixmap *g_pixmap = GTK_PIXMAP( bin->child );
|
|
||||||
|
|
||||||
GdkBitmap *mask = (GdkBitmap *) NULL;
|
GdkBitmap *mask = (GdkBitmap *) NULL;
|
||||||
if (the_one.GetMask()) mask = the_one.GetMask()->GetBitmap();
|
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 )
|
void wxBitmapButton::SetBitmapDisabled( const wxBitmap& bitmap )
|
||||||
{
|
{
|
||||||
wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
|
if (!bitmap.Ok()) return;
|
||||||
|
|
||||||
if ( ! m_disabled.Ok() ) return;
|
|
||||||
m_disabled = bitmap;
|
m_disabled = bitmap;
|
||||||
|
|
||||||
SetBitmap();
|
SetBitmap();
|
||||||
@@ -255,9 +247,7 @@ void wxBitmapButton::SetBitmapDisabled( const wxBitmap& bitmap )
|
|||||||
|
|
||||||
void wxBitmapButton::SetBitmapFocus( const wxBitmap& bitmap )
|
void wxBitmapButton::SetBitmapFocus( const wxBitmap& bitmap )
|
||||||
{
|
{
|
||||||
wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
|
if (!bitmap.Ok()) return;
|
||||||
|
|
||||||
if ( ! m_focus.Ok() ) return;
|
|
||||||
m_focus = bitmap;
|
m_focus = bitmap;
|
||||||
|
|
||||||
SetBitmap();
|
SetBitmap();
|
||||||
@@ -265,9 +255,7 @@ void wxBitmapButton::SetBitmapFocus( const wxBitmap& bitmap )
|
|||||||
|
|
||||||
void wxBitmapButton::SetBitmapLabel( const wxBitmap& bitmap )
|
void wxBitmapButton::SetBitmapLabel( const wxBitmap& bitmap )
|
||||||
{
|
{
|
||||||
wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
|
if (!bitmap.Ok()) return;
|
||||||
|
|
||||||
if (!m_bitmap.Ok()) return;
|
|
||||||
m_bitmap = bitmap;
|
m_bitmap = bitmap;
|
||||||
|
|
||||||
SetBitmap();
|
SetBitmap();
|
||||||
@@ -275,9 +263,7 @@ void wxBitmapButton::SetBitmapLabel( const wxBitmap& bitmap )
|
|||||||
|
|
||||||
void wxBitmapButton::SetBitmapSelected( const wxBitmap& bitmap )
|
void wxBitmapButton::SetBitmapSelected( const wxBitmap& bitmap )
|
||||||
{
|
{
|
||||||
wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
|
if (!bitmap.Ok()) return;
|
||||||
|
|
||||||
if ( ! m_selected.Ok() ) return;
|
|
||||||
m_selected = bitmap;
|
m_selected = bitmap;
|
||||||
|
|
||||||
SetBitmap();
|
SetBitmap();
|
||||||
|
Reference in New Issue
Block a user