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