]> git.saurik.com Git - wxWidgets.git/blame - include/wx/univ/button.h
correcting a source for double event delivery
[wxWidgets.git] / include / wx / univ / button.h
CommitLineData
1e6feb95
VZ
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$
442b35b5 8// Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
65571936 9// Licence: wxWindows licence
1e6feb95
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_UNIV_BUTTON_H_
13#define _WX_UNIV_BUTTON_H_
14
12028905 15#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
a3870b2f 16 #pragma interface "univbutton.h"
1e6feb95
VZ
17#endif
18
19class WXDLLEXPORT wxInputHandler;
20
21#include "wx/bitmap.h"
22
23// ----------------------------------------------------------------------------
24// the actions supported by this control
25// ----------------------------------------------------------------------------
26
27#define wxACTION_BUTTON_TOGGLE _T("toggle") // press/release the button
28#define wxACTION_BUTTON_PRESS _T("press") // press the button
29#define wxACTION_BUTTON_RELEASE _T("release") // release the button
30#define wxACTION_BUTTON_CLICK _T("click") // generate button click event
31
32// ----------------------------------------------------------------------------
33// wxButton: a push button
34// ----------------------------------------------------------------------------
35
36class WXDLLEXPORT wxButton : public wxButtonBase
37{
38public:
6463b9f5 39 wxButton() { Init(); }
1e6feb95
VZ
40 wxButton(wxWindow *parent,
41 wxWindowID id,
42 const wxBitmap& bitmap,
43 const wxString& label,
44 const wxPoint& pos = wxDefaultPosition,
45 const wxSize& size = wxDefaultSize,
46 long style = 0,
47 const wxValidator& validator = wxDefaultValidator,
6463b9f5
JS
48 const wxString& name = wxButtonNameStr)
49 {
50 Init();
51
52 Create(parent, id, bitmap, label, pos, size, style, validator, name);
53 }
401e3b6e
VS
54
55 wxButton(wxWindow *parent, wxWindowID id, wxStockItemID stock,
56 const wxString& descriptiveLabel = wxEmptyString,
57 const wxPoint& pos = wxDefaultPosition,
58 long style = 0,
59 const wxValidator& validator = wxDefaultValidator,
60 const wxString& name = wxButtonNameStr)
61 {
62 Init();
63
64 Create(parent, id, stock, descriptiveLabel, pos, style, validator, name);
65 }
1e6feb95
VZ
66
67 wxButton(wxWindow *parent,
68 wxWindowID id,
69 const wxString& label,
70 const wxPoint& pos = wxDefaultPosition,
71 const wxSize& size = wxDefaultSize,
72 long style = 0,
73 const wxValidator& validator = wxDefaultValidator,
6463b9f5
JS
74 const wxString& name = wxButtonNameStr)
75 {
76 Init();
77
78 Create(parent, id, label, pos, size, style, validator, name);
79 }
1e6feb95
VZ
80
81 bool Create(wxWindow *parent,
82 wxWindowID id,
83 const wxString& label,
84 const wxPoint& pos = wxDefaultPosition,
85 const wxSize& size = wxDefaultSize,
86 long style = 0,
87 const wxValidator& validator = wxDefaultValidator,
88 const wxString& name = wxButtonNameStr)
89 {
90 return Create(parent, id, wxNullBitmap, label,
91 pos, size, style, validator, name);
92 }
401e3b6e
VS
93
94 bool Create(wxWindow *parent, wxWindowID id, wxStockItemID stock,
95 const wxString& descriptiveLabel = wxEmptyString,
96 const wxPoint& pos = wxDefaultPosition,
97 long style = 0,
98 const wxValidator& validator = wxDefaultValidator,
99 const wxString& name = wxButtonNameStr)
100 {
101 return CreateStock(parent, id, stock, descriptiveLabel,
102 pos, style, validator, name);
103 }
1e6feb95
VZ
104
105 bool Create(wxWindow *parent,
106 wxWindowID id,
107 const wxBitmap& bitmap,
108 const wxString& label,
109 const wxPoint& pos = wxDefaultPosition,
110 const wxSize& size = wxDefaultSize,
111 long style = 0,
112 const wxValidator& validator = wxDefaultValidator,
113 const wxString& name = wxButtonNameStr);
114
115 virtual ~wxButton();
116
117 virtual void SetImageLabel(const wxBitmap& bitmap);
118 virtual void SetImageMargins(wxCoord x, wxCoord y);
119 virtual void SetDefault();
120
121 virtual bool IsPressed() const { return m_isPressed; }
122 virtual bool IsDefault() const { return m_isDefault; }
123
124 // wxButton actions
125 void Toggle();
126 virtual void Press();
127 virtual void Release();
128 virtual void Click();
129
130protected:
131 virtual bool PerformAction(const wxControlAction& action,
132 long numArg = -1,
133 const wxString& strArg = wxEmptyString);
134 virtual wxSize DoGetBestClientSize() const;
193e19cf
RR
135
136 virtual bool DoDrawBackground(wxDC& dc);
1e6feb95
VZ
137 virtual void DoDraw(wxControlRenderer *renderer);
138
a290fa5a 139 virtual bool CanBeHighlighted() const { return true; }
1e6feb95
VZ
140
141 // common part of all ctors
142 void Init();
143
144 // current state
145 bool m_isPressed,
146 m_isDefault;
147
148 // the (optional) image to show and the margins around it
149 wxBitmap m_bitmap;
150 wxCoord m_marginBmpX,
151 m_marginBmpY;
152
153private:
154 DECLARE_DYNAMIC_CLASS(wxButton)
155};
156
157// ----------------------------------------------------------------------------
158// wxStdButtonInputHandler: translates SPACE and ENTER keys and the left mouse
159// click into button press/release actions
160// ----------------------------------------------------------------------------
161
162class WXDLLEXPORT wxStdButtonInputHandler : public wxStdInputHandler
163{
164public:
165 wxStdButtonInputHandler(wxInputHandler *inphand);
166
23645bfa 167 virtual bool HandleKey(wxInputConsumer *consumer,
1e6feb95
VZ
168 const wxKeyEvent& event,
169 bool pressed);
23645bfa 170 virtual bool HandleMouse(wxInputConsumer *consumer,
1e6feb95 171 const wxMouseEvent& event);
23645bfa
VS
172 virtual bool HandleMouseMove(wxInputConsumer *consumer, const wxMouseEvent& event);
173 virtual bool HandleFocus(wxInputConsumer *consumer, const wxFocusEvent& event);
174 virtual bool HandleActivation(wxInputConsumer *consumer, bool activated);
1e6feb95
VZ
175
176private:
177 // the window (button) which has capture or NULL and the flag telling if
178 // the mouse is inside the button which captured it or not
179 wxWindow *m_winCapture;
180 bool m_winHasMouse;
181};
182
183#endif // _WX_UNIV_BUTTON_H_
184