implement support for button bitmaps (normal state only for now) for wxGTK
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61075 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
23d8a71f51
commit
7be740a3fd
@ -1,6 +1,6 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: wx/gtk/button.h
|
// Name: wx/gtk/button.h
|
||||||
// Purpose:
|
// Purpose: wxGTK wxButton class declaration
|
||||||
// Author: Robert Roebling
|
// Author: Robert Roebling
|
||||||
// Id: $Id$
|
// Id: $Id$
|
||||||
// Copyright: (c) 1998 Robert Roebling
|
// Copyright: (c) 1998 Robert Roebling
|
||||||
@ -14,10 +14,10 @@
|
|||||||
// wxButton
|
// wxButton
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
class WXDLLIMPEXP_CORE wxButton: public wxButtonBase
|
class WXDLLIMPEXP_CORE wxButton : public wxButtonBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxButton();
|
wxButton() { }
|
||||||
wxButton(wxWindow *parent, wxWindowID id,
|
wxButton(wxWindow *parent, wxWindowID id,
|
||||||
const wxString& label = wxEmptyString,
|
const wxString& label = wxEmptyString,
|
||||||
const wxPoint& pos = wxDefaultPosition,
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
@ -28,8 +28,6 @@ public:
|
|||||||
Create(parent, id, label, pos, size, style, validator, name);
|
Create(parent, id, label, pos, size, style, validator, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~wxButton();
|
|
||||||
|
|
||||||
bool Create(wxWindow *parent, wxWindowID id,
|
bool Create(wxWindow *parent, wxWindowID id,
|
||||||
const wxString& label = wxEmptyString,
|
const wxString& label = wxEmptyString,
|
||||||
const wxPoint& pos = wxDefaultPosition,
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
@ -39,7 +37,7 @@ public:
|
|||||||
|
|
||||||
virtual wxWindow *SetDefault();
|
virtual wxWindow *SetDefault();
|
||||||
virtual void SetLabel( const wxString &label );
|
virtual void SetLabel( const wxString &label );
|
||||||
virtual bool Enable( bool enable = TRUE );
|
virtual bool Enable( bool enable = true );
|
||||||
|
|
||||||
// implementation
|
// implementation
|
||||||
// --------------
|
// --------------
|
||||||
@ -56,7 +54,13 @@ protected:
|
|||||||
|
|
||||||
virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const;
|
virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const;
|
||||||
|
|
||||||
|
virtual wxBitmap DoGetBitmap(State which) const;
|
||||||
|
virtual void DoSetBitmap(const wxBitmap& bitmap, State which);
|
||||||
|
virtual void DoSetBitmapPosition(wxDirection dir);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
wxBitmap m_bitmaps[State_Max];
|
||||||
|
|
||||||
DECLARE_DYNAMIC_CLASS(wxButton)
|
DECLARE_DYNAMIC_CLASS(wxButton)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -75,14 +75,6 @@ gtk_button_style_set_callback(GtkWidget* widget, GtkStyle*, wxButton* win)
|
|||||||
|
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxButton,wxControl)
|
IMPLEMENT_DYNAMIC_CLASS(wxButton,wxControl)
|
||||||
|
|
||||||
wxButton::wxButton()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
wxButton::~wxButton()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxButton::Create(wxWindow *parent,
|
bool wxButton::Create(wxWindow *parent,
|
||||||
wxWindowID id,
|
wxWindowID id,
|
||||||
const wxString &label,
|
const wxString &label,
|
||||||
@ -262,7 +254,7 @@ wxSize wxButton::DoGetBestSize() const
|
|||||||
{
|
{
|
||||||
// the default button in wxGTK is bigger than the other ones because of an
|
// the default button in wxGTK is bigger than the other ones because of an
|
||||||
// extra border around it, but we don't want to take it into account in
|
// extra border around it, but we don't want to take it into account in
|
||||||
// our size calculations (otherwsie the result is visually ugly), so
|
// our size calculations (otherwise the result is visually ugly), so
|
||||||
// always return the size of non default button from here
|
// always return the size of non default button from here
|
||||||
const bool isDefault = GTK_WIDGET_HAS_DEFAULT(m_widget);
|
const bool isDefault = GTK_WIDGET_HAS_DEFAULT(m_widget);
|
||||||
if ( isDefault )
|
if ( isDefault )
|
||||||
@ -282,8 +274,10 @@ wxSize wxButton::DoGetBestSize() const
|
|||||||
if (!HasFlag(wxBU_EXACTFIT))
|
if (!HasFlag(wxBU_EXACTFIT))
|
||||||
{
|
{
|
||||||
wxSize defaultSize = GetDefaultSize();
|
wxSize defaultSize = GetDefaultSize();
|
||||||
if (ret.x < defaultSize.x) ret.x = defaultSize.x;
|
if (ret.x < defaultSize.x)
|
||||||
if (ret.y < defaultSize.y) ret.y = defaultSize.y;
|
ret.x = defaultSize.x;
|
||||||
|
if (ret.y < defaultSize.y)
|
||||||
|
ret.y = defaultSize.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
CacheBestSize(ret);
|
CacheBestSize(ret);
|
||||||
@ -297,4 +291,81 @@ wxButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
|||||||
return GetDefaultAttributesFromGTKWidget(gtk_button_new);
|
return GetDefaultAttributesFromGTKWidget(gtk_button_new);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// bitmaps support
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wxBitmap wxButton::DoGetBitmap(State which) const
|
||||||
|
{
|
||||||
|
return m_bitmaps[which];
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxButton::DoSetBitmap(const wxBitmap& bitmap, State which)
|
||||||
|
{
|
||||||
|
#ifdef __WXGTK26__
|
||||||
|
// normal image is special: setting it enables images for the button and
|
||||||
|
// resetting it to nothing disables all of them
|
||||||
|
if ( which == State_Normal )
|
||||||
|
{
|
||||||
|
if ( !gtk_check_version(2,6,0) )
|
||||||
|
{
|
||||||
|
GtkWidget *image = gtk_button_get_image(GTK_BUTTON(m_widget));
|
||||||
|
if ( image && !bitmap.IsOk() )
|
||||||
|
{
|
||||||
|
gtk_container_remove(GTK_CONTAINER(m_widget), image);
|
||||||
|
InvalidateBestSize();
|
||||||
|
}
|
||||||
|
else if ( !image && bitmap.IsOk() )
|
||||||
|
{
|
||||||
|
image = gtk_image_new();
|
||||||
|
gtk_button_set_image(GTK_BUTTON(m_widget), image);
|
||||||
|
InvalidateBestSize();
|
||||||
|
}
|
||||||
|
//else: image presence or absence didn't change
|
||||||
|
|
||||||
|
if ( bitmap.IsOk() )
|
||||||
|
{
|
||||||
|
gtk_image_set_from_pixbuf(GTK_IMAGE(image), bitmap.GetPixbuf());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif // GTK+ 2.6+
|
||||||
|
|
||||||
|
m_bitmaps[which] = bitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxButton::DoSetBitmapPosition(wxDirection dir)
|
||||||
|
{
|
||||||
|
#ifdef __WXGTK210__
|
||||||
|
if ( !gtk_check_version(2,10,0) )
|
||||||
|
{
|
||||||
|
GtkPositionType gtkpos;
|
||||||
|
switch ( dir )
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
wxFAIL_MSG( "invalid position" );
|
||||||
|
// fall through
|
||||||
|
|
||||||
|
case wxLEFT:
|
||||||
|
gtkpos = GTK_POS_LEFT;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case wxRIGHT:
|
||||||
|
gtkpos = GTK_POS_RIGHT;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case wxTOP:
|
||||||
|
gtkpos = GTK_POS_TOP;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case wxBOTTOM:
|
||||||
|
gtkpos = GTK_POS_BOTTOM;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk_button_set_image_position(GTK_BUTTON(m_widget), gtkpos);
|
||||||
|
}
|
||||||
|
#endif // GTK+ 2.10+
|
||||||
|
}
|
||||||
|
|
||||||
#endif // wxUSE_BUTTON
|
#endif // wxUSE_BUTTON
|
||||||
|
Loading…
Reference in New Issue
Block a user