]> git.saurik.com Git - wxWidgets.git/blob - include/wx/univ/button.h
renamed BLOCK_SIZE which conflicts with a #define in a std Linux (and maybe not only...
[wxWidgets.git] / include / wx / univ / button.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/univ/button.h
3 // Purpose: wxButton for wxUniversal
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 15.08.00
7 // RCS-ID: $Id$
8 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_UNIV_BUTTON_H_
13 #define _WX_UNIV_BUTTON_H_
14
15 class WXDLLEXPORT wxInputHandler;
16
17 #include "wx/bitmap.h"
18
19 // ----------------------------------------------------------------------------
20 // the actions supported by this control
21 // ----------------------------------------------------------------------------
22
23 #define wxACTION_BUTTON_TOGGLE _T("toggle") // press/release the button
24 #define wxACTION_BUTTON_PRESS _T("press") // press the button
25 #define wxACTION_BUTTON_RELEASE _T("release") // release the button
26 #define wxACTION_BUTTON_CLICK _T("click") // generate button click event
27
28 // ----------------------------------------------------------------------------
29 // wxButton: a push button
30 // ----------------------------------------------------------------------------
31
32 class WXDLLEXPORT wxButton : public wxButtonBase
33 {
34 public:
35 wxButton() { Init(); }
36 wxButton(wxWindow *parent,
37 wxWindowID id,
38 const wxBitmap& bitmap,
39 const wxString& label = wxEmptyString,
40 const wxPoint& pos = wxDefaultPosition,
41 const wxSize& size = wxDefaultSize,
42 long style = 0,
43 const wxValidator& validator = wxDefaultValidator,
44 const wxString& name = wxButtonNameStr)
45 {
46 Init();
47
48 Create(parent, id, bitmap, label, pos, size, style, validator, name);
49 }
50
51 wxButton(wxWindow *parent,
52 wxWindowID id,
53 const wxString& label = wxEmptyString,
54 const wxPoint& pos = wxDefaultPosition,
55 const wxSize& size = wxDefaultSize,
56 long style = 0,
57 const wxValidator& validator = wxDefaultValidator,
58 const wxString& name = wxButtonNameStr)
59 {
60 Init();
61
62 Create(parent, id, label, pos, size, style, validator, name);
63 }
64
65 bool Create(wxWindow *parent,
66 wxWindowID id,
67 const wxString& label = wxEmptyString,
68 const wxPoint& pos = wxDefaultPosition,
69 const wxSize& size = wxDefaultSize,
70 long style = 0,
71 const wxValidator& validator = wxDefaultValidator,
72 const wxString& name = wxButtonNameStr)
73 {
74 return Create(parent, id, wxNullBitmap, label,
75 pos, size, style, validator, name);
76 }
77
78 bool Create(wxWindow *parent,
79 wxWindowID id,
80 const wxBitmap& bitmap,
81 const wxString& label = wxEmptyString,
82 const wxPoint& pos = wxDefaultPosition,
83 const wxSize& size = wxDefaultSize,
84 long style = 0,
85 const wxValidator& validator = wxDefaultValidator,
86 const wxString& name = wxButtonNameStr);
87
88 virtual ~wxButton();
89
90 virtual void SetImageLabel(const wxBitmap& bitmap);
91 virtual void SetImageMargins(wxCoord x, wxCoord y);
92 virtual void SetDefault();
93
94 virtual bool IsPressed() const { return m_isPressed; }
95 virtual bool IsDefault() const { return m_isDefault; }
96
97 // wxButton actions
98 void Toggle();
99 virtual void Press();
100 virtual void Release();
101 virtual void Click();
102
103 protected:
104 virtual bool PerformAction(const wxControlAction& action,
105 long numArg = -1,
106 const wxString& strArg = wxEmptyString);
107 virtual wxSize DoGetBestClientSize() const;
108
109 virtual bool DoDrawBackground(wxDC& dc);
110 virtual void DoDraw(wxControlRenderer *renderer);
111
112 virtual bool CanBeHighlighted() const { return true; }
113
114 // common part of all ctors
115 void Init();
116
117 // current state
118 bool m_isPressed,
119 m_isDefault;
120
121 // the (optional) image to show and the margins around it
122 wxBitmap m_bitmap;
123 wxCoord m_marginBmpX,
124 m_marginBmpY;
125
126 private:
127 DECLARE_DYNAMIC_CLASS(wxButton)
128 };
129
130 // ----------------------------------------------------------------------------
131 // wxStdButtonInputHandler: translates SPACE and ENTER keys and the left mouse
132 // click into button press/release actions
133 // ----------------------------------------------------------------------------
134
135 class WXDLLEXPORT wxStdButtonInputHandler : public wxStdInputHandler
136 {
137 public:
138 wxStdButtonInputHandler(wxInputHandler *inphand);
139
140 virtual bool HandleKey(wxInputConsumer *consumer,
141 const wxKeyEvent& event,
142 bool pressed);
143 virtual bool HandleMouse(wxInputConsumer *consumer,
144 const wxMouseEvent& event);
145 virtual bool HandleMouseMove(wxInputConsumer *consumer, const wxMouseEvent& event);
146 virtual bool HandleFocus(wxInputConsumer *consumer, const wxFocusEvent& event);
147 virtual bool HandleActivation(wxInputConsumer *consumer, bool activated);
148
149 private:
150 // the window (button) which has capture or NULL and the flag telling if
151 // the mouse is inside the button which captured it or not
152 wxWindow *m_winCapture;
153 bool m_winHasMouse;
154 };
155
156 #endif // _WX_UNIV_BUTTON_H_
157