]> git.saurik.com Git - wxWidgets.git/blob - src/palmos/button.cpp
Cygwin compile fix
[wxWidgets.git] / src / palmos / button.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/button.cpp
3 // Purpose: wxButton
4 // Author: William Osborne - minimal working wxPalmOS port
5 // Modified by: Wlodzimierz ABX Skiba - native wxButton implementation
6 // Created: 10/13/04
7 // RCS-ID: $Id$
8 // Copyright: (c) William Osborne, Wlodzimierz Skiba
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "button.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #if wxUSE_BUTTON
32
33 #ifndef WX_PRECOMP
34 #include "wx/app.h"
35 #include "wx/button.h"
36 #include "wx/brush.h"
37 #include "wx/panel.h"
38 #include "wx/bmpbuttn.h"
39 #include "wx/settings.h"
40 #include "wx/dcscreen.h"
41 #include "wx/frame.h"
42 #include "wx/dialog.h"
43 #endif
44
45 #include "wx/stockitem.h"
46
47 #include <Control.h>
48 #include <Form.h>
49
50 // ----------------------------------------------------------------------------
51 // macros
52 // ----------------------------------------------------------------------------
53
54 #if wxUSE_EXTENDED_RTTI
55
56 WX_DEFINE_FLAGS( wxButtonStyle )
57
58 wxBEGIN_FLAGS( wxButtonStyle )
59 // new style border flags, we put them first to
60 // use them for streaming out
61 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
62 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
63 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
64 wxFLAGS_MEMBER(wxBORDER_RAISED)
65 wxFLAGS_MEMBER(wxBORDER_STATIC)
66 wxFLAGS_MEMBER(wxBORDER_NONE)
67
68 // old style border flags
69 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
70 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
71 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
72 wxFLAGS_MEMBER(wxRAISED_BORDER)
73 wxFLAGS_MEMBER(wxSTATIC_BORDER)
74 wxFLAGS_MEMBER(wxBORDER)
75
76 // standard window styles
77 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
78 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
79 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
80 wxFLAGS_MEMBER(wxWANTS_CHARS)
81 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
82 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
83 wxFLAGS_MEMBER(wxVSCROLL)
84 wxFLAGS_MEMBER(wxHSCROLL)
85
86 wxFLAGS_MEMBER(wxBU_LEFT)
87 wxFLAGS_MEMBER(wxBU_RIGHT)
88 wxFLAGS_MEMBER(wxBU_TOP)
89 wxFLAGS_MEMBER(wxBU_BOTTOM)
90 wxFLAGS_MEMBER(wxBU_EXACTFIT)
91 wxEND_FLAGS( wxButtonStyle )
92
93 IMPLEMENT_DYNAMIC_CLASS_XTI(wxButton, wxControl,"wx/button.h")
94
95 wxBEGIN_PROPERTIES_TABLE(wxButton)
96 wxEVENT_PROPERTY( Click , wxEVT_COMMAND_BUTTON_CLICKED , wxCommandEvent)
97
98 wxPROPERTY( Font , wxFont , SetFont , GetFont , EMPTY_MACROVALUE, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
99 wxPROPERTY( Label, wxString , SetLabel, GetLabel, wxString(), 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
100
101 wxPROPERTY_FLAGS( WindowStyle , wxButtonStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
102
103 wxEND_PROPERTIES_TABLE()
104
105 wxBEGIN_HANDLERS_TABLE(wxButton)
106 wxEND_HANDLERS_TABLE()
107
108 wxCONSTRUCTOR_6( wxButton , wxWindow* , Parent , wxWindowID , Id , wxString , Label , wxPoint , Position , wxSize , Size , long , WindowStyle )
109
110
111 #else
112 IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
113 #endif
114
115 // this macro tries to adjust the default button height to a reasonable value
116 // using the char height as the base
117 #define BUTTON_HEIGHT_FROM_CHAR_HEIGHT(cy) (11*EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)/10)
118
119 // ============================================================================
120 // implementation
121 // ============================================================================
122
123 // ----------------------------------------------------------------------------
124 // creation/destruction
125 // ----------------------------------------------------------------------------
126
127 bool wxButton::Create(wxWindow *parent,
128 wxWindowID id,
129 const wxString& label,
130 const wxPoint& pos,
131 const wxSize& size,
132 long style,
133 const wxValidator& validator,
134 const wxString& name)
135 {
136 // Default coordinates based on the knowledgebase recipe "Buttons"
137 wxSize palmSize(size.x==wxDefaultCoord?36:size.x,
138 size.y==wxDefaultCoord?12:size.y);
139
140 // Default placement depends on dialog vs. frame type of parent
141 wxPoint palmPos(pos);
142 if((palmPos.x==wxDefaultCoord)||(palmPos.y==wxDefaultCoord))
143 {
144 wxSize parentSize(parent->GetClientSize());
145 wxWindow* parentTLW = parent;
146 while ( parentTLW && !parentTLW->IsTopLevel() )
147 {
148 parentTLW = parentTLW->GetParent();
149 }
150
151 if(wxDynamicCast(parentTLW, wxFrame)!=NULL)
152 {
153 if(palmPos.x==wxDefaultCoord)
154 palmPos.x = 0;
155 if(palmPos.y==wxDefaultCoord)
156 palmPos.y = parentSize.y-palmSize.y;
157 }
158 else if(wxDynamicCast(parentTLW, wxDialog)!=NULL)
159 {
160 if(palmPos.x==wxDefaultCoord)
161 palmPos.x = 4;
162 if(palmPos.y==wxDefaultCoord)
163 palmPos.y = parentSize.y-palmSize.y-5;
164 }
165 else
166 {
167 // something seriously broken
168 return false;
169 }
170 }
171
172 // take the stock label
173 wxString palmLabel = label;
174 if( palmLabel.empty() && wxIsStockID(id) )
175 palmLabel = wxGetStockLabel(id, false);
176
177 if(!wxControl::Create(parent, id, palmPos, palmSize, style, validator, name))
178 return false;
179
180 return wxControl::PalmCreateControl(buttonCtl, palmLabel, palmPos, palmSize);
181 }
182
183 wxButton::~wxButton()
184 {
185 }
186
187 // ----------------------------------------------------------------------------
188 // size management including autosizing
189 // ----------------------------------------------------------------------------
190
191 wxSize wxButton::DoGetBestSize() const
192 {
193 return wxSize(36,12);
194 }
195
196 /* static */
197 wxSize wxButtonBase::GetDefaultSize()
198 {
199 return wxSize(36,12);
200 }
201
202 void wxButton::SetDefault()
203 {
204 FormType* form = (FormType* )GetParentForm();
205 if(form==NULL)
206 return;
207 FrmSetDefaultButtonID(form,GetId());
208 }
209
210 void wxButton::SetTmpDefault()
211 {
212 }
213
214 void wxButton::UnsetTmpDefault()
215 {
216 }
217
218 /* static */
219 void
220 wxButton::SetDefaultStyle(wxButton *btn, bool on)
221 {
222 }
223
224 // ----------------------------------------------------------------------------
225 // helpers
226 // ----------------------------------------------------------------------------
227
228 bool wxButton::SendClickEvent()
229 {
230 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
231 event.SetEventObject(this);
232 return ProcessCommand(event);
233 }
234
235 void wxButton::Command(wxCommandEvent &event)
236 {
237 ProcessCommand(event);
238 }
239
240 #endif // wxUSE_BUTTON
241