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