]> git.saurik.com Git - wxWidgets.git/blame - include/wx/bmpbuttn.h
support SDK < 10.6, fixes #14902
[wxWidgets.git] / include / wx / bmpbuttn.h
CommitLineData
1e6feb95 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: wx/bmpbuttn.h
1e6feb95
VZ
3// Purpose: wxBitmapButton class interface
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 25.08.00
7// RCS-ID: $Id$
8// Copyright: (c) 2000 Vadim Zeitlin
65571936 9// Licence: wxWindows licence
1e6feb95
VZ
10/////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _WX_BMPBUTTON_H_BASE_
13#define _WX_BMPBUTTON_H_BASE_
c801d85f 14
997176a3
VZ
15#include "wx/defs.h"
16
1e6feb95
VZ
17#if wxUSE_BMPBUTTON
18
1e6feb95
VZ
19#include "wx/button.h"
20
b38dc31f 21// FIXME: right now only wxMSW, wxGTK and wxOSX implement bitmap support in wxButton
a6fd73d3
VZ
22// itself, this shouldn't be used for the other platforms neither
23// when all of them do it
b38dc31f 24#if (defined(__WXMSW__) || defined(__WXGTK20__) || defined(__WXOSX__)) && !defined(__WXUNIVERSAL__)
a6fd73d3
VZ
25 #define wxHAS_BUTTON_BITMAP
26#endif
1e6feb95 27
be7a086c
VZ
28class WXDLLIMPEXP_FWD_CORE wxBitmapButton;
29
1e6feb95
VZ
30// ----------------------------------------------------------------------------
31// wxBitmapButton: a button which shows bitmaps instead of the usual string.
32// It has different bitmaps for different states (focused/disabled/pressed)
33// ----------------------------------------------------------------------------
34
53a2db12 35class WXDLLIMPEXP_CORE wxBitmapButtonBase : public wxButton
1e6feb95
VZ
36{
37public:
6463b9f5 38 wxBitmapButtonBase()
6b5a2b6f 39 {
a6fd73d3 40#ifndef wxHAS_BUTTON_BITMAP
6b5a2b6f
VZ
41 m_marginX =
42 m_marginY = 0;
a6fd73d3 43#endif // wxHAS_BUTTON_BITMAP
6b5a2b6f 44 }
1e6feb95 45
8e4c2912
VZ
46 bool Create(wxWindow *parent,
47 wxWindowID winid,
8e4c2912
VZ
48 const wxPoint& pos,
49 const wxSize& size,
50 long style,
51 const wxValidator& validator,
52 const wxString& name)
53 {
54 // We use wxBU_NOTEXT to let the base class Create() know that we are
55 // not going to show the label: this is a hack needed for wxGTK where
56 // we can show both label and bitmap only with GTK 2.6+ but we always
57 // can show just one of them and this style allows us to choose which
58 // one we need.
59 //
60 // And we also use wxBU_EXACTFIT to avoid being resized up to the
61 // standard button size as this doesn't make sense for bitmap buttons
62 // which are not standard anyhow and should fit their bitmap size.
78eecde0
VZ
63 return wxButton::Create(parent, winid, "",
64 pos, size,
8e4c2912
VZ
65 style | wxBU_NOTEXT | wxBU_EXACTFIT,
66 validator, name);
67 }
68
be7a086c
VZ
69 // Special creation function for a standard "Close" bitmap. It allows to
70 // simply create a close button with the image appropriate for the common
71 // platform.
72 static wxBitmapButton* NewCloseButton(wxWindow* parent, wxWindowID winid);
73
74
1e6feb95 75 // set/get the margins around the button
a6fd73d3
VZ
76 virtual void SetMargins(int x, int y)
77 {
78 DoSetBitmapMargins(x, y);
79 }
80
81 int GetMarginX() const { return DoGetBitmapMargins().x; }
82 int GetMarginY() const { return DoGetBitmapMargins().y; }
1e6feb95 83
6b5a2b6f
VZ
84 // deprecated synonym for SetBitmapLabel()
85#if WXWIN_COMPATIBILITY_2_6
eebe696e
VZ
86 wxDEPRECATED_INLINE( void SetLabel(const wxBitmap& bitmap),
87 SetBitmapLabel(bitmap); )
6b5a2b6f
VZ
88
89 // prevent virtual function hiding
90 virtual void SetLabel(const wxString& label)
faa49bfd 91 { wxWindow::SetLabel(label); }
6b5a2b6f
VZ
92#endif // WXWIN_COMPATIBILITY_2_6
93
1e6feb95 94protected:
a6fd73d3 95#ifndef wxHAS_BUTTON_BITMAP
1e6feb95 96 // function called when any of the bitmaps changes
c46b98da 97 virtual void OnSetBitmap() { InvalidateBestSize(); Refresh(); }
1e6feb95 98
2352862a
VZ
99 virtual wxBitmap DoGetBitmap(State which) const { return m_bitmaps[which]; }
100 virtual void DoSetBitmap(const wxBitmap& bitmap, State which)
101 { m_bitmaps[which] = bitmap; OnSetBitmap(); }
102
a6fd73d3
VZ
103 virtual wxSize DoGetBitmapMargins() const
104 {
105 return wxSize(m_marginX, m_marginY);
106 }
107
108 virtual void DoSetBitmapMargins(int x, int y)
109 {
110 m_marginX = x;
111 m_marginY = y;
112 }
113
1e6feb95 114 // the bitmaps for various states
2352862a 115 wxBitmap m_bitmaps[State_Max];
1e6feb95
VZ
116
117 // the margins around the bitmap
118 int m_marginX,
119 m_marginY;
a6fd73d3 120#endif // !wxHAS_BUTTON_BITMAP
fc7a2a60 121
c0c133e1 122 wxDECLARE_NO_COPY_CLASS(wxBitmapButtonBase);
1e6feb95
VZ
123};
124
125#if defined(__WXUNIVERSAL__)
126 #include "wx/univ/bmpbuttn.h"
127#elif defined(__WXMSW__)
128 #include "wx/msw/bmpbuttn.h"
2049ba38 129#elif defined(__WXMOTIF__)
1e6feb95 130 #include "wx/motif/bmpbuttn.h"
1be7a35c 131#elif defined(__WXGTK20__)
1e6feb95 132 #include "wx/gtk/bmpbuttn.h"
1be7a35c
MR
133#elif defined(__WXGTK__)
134 #include "wx/gtk1/bmpbuttn.h"
34138703 135#elif defined(__WXMAC__)
ef0e9220 136 #include "wx/osx/bmpbuttn.h"
e64df9bc
DE
137#elif defined(__WXCOCOA__)
138 #include "wx/cocoa/bmpbuttn.h"
1777b9bb 139#elif defined(__WXPM__)
1e6feb95 140 #include "wx/os2/bmpbuttn.h"
c801d85f
KB
141#endif
142
1e6feb95
VZ
143#endif // wxUSE_BMPBUTTON
144
145#endif // _WX_BMPBUTTON_H_BASE_