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