]>
Commit | Line | Data |
---|---|---|
ffecfa5a | 1 | ///////////////////////////////////////////////////////////////////////////// |
e2731512 | 2 | // Name: src/palmos/button.cpp |
ffecfa5a | 3 | // Purpose: wxButton |
e2731512 | 4 | // Author: William Osborne - minimal working wxPalmOS port |
db101bd3 | 5 | // Modified by: Wlodzimierz ABX Skiba - native wxButton implementation |
ffecfa5a | 6 | // Created: 10/13/04 |
e2731512 | 7 | // RCS-ID: $Id$ |
db101bd3 | 8 | // Copyright: (c) William Osborne, Wlodzimierz Skiba |
ffecfa5a JS |
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" | |
808e3bce WS |
41 | #include "wx/frame.h" |
42 | #include "wx/dialog.h" | |
43 | #include "wx/stockitem.h" | |
ffecfa5a JS |
44 | #endif |
45 | ||
ffecfa5a JS |
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) | |
4055ed82 | 63 | |
ffecfa5a JS |
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 | { | |
808e3bce WS |
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->GetSize()); | |
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 = 1; | |
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 = 5; | |
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); | |
172 | ||
173 | wxControl::PalmCreateControl(buttonCtl, parent, id, palmLabel, palmPos, palmSize); | |
db101bd3 | 174 | return true; |
ffecfa5a JS |
175 | } |
176 | ||
177 | wxButton::~wxButton() | |
178 | { | |
179 | } | |
180 | ||
ffecfa5a JS |
181 | // ---------------------------------------------------------------------------- |
182 | // size management including autosizing | |
183 | // ---------------------------------------------------------------------------- | |
184 | ||
185 | wxSize wxButton::DoGetBestSize() const | |
186 | { | |
808e3bce | 187 | return wxSize(36,12); |
ffecfa5a JS |
188 | } |
189 | ||
190 | /* static */ | |
191 | wxSize wxButtonBase::GetDefaultSize() | |
192 | { | |
808e3bce | 193 | return wxSize(36,12); |
ffecfa5a JS |
194 | } |
195 | ||
196 | void wxButton::SetDefault() | |
197 | { | |
ba889513 WS |
198 | FormType* form = GetParentForm(); |
199 | if(form==NULL) | |
200 | return; | |
201 | FrmSetDefaultButtonID(form,GetId()); | |
ffecfa5a JS |
202 | } |
203 | ||
204 | void wxButton::SetTmpDefault() | |
205 | { | |
206 | } | |
207 | ||
208 | void wxButton::UnsetTmpDefault() | |
209 | { | |
210 | } | |
211 | ||
212 | /* static */ | |
213 | void | |
214 | wxButton::SetDefaultStyle(wxButton *btn, bool on) | |
215 | { | |
216 | } | |
217 | ||
218 | // ---------------------------------------------------------------------------- | |
219 | // helpers | |
220 | // ---------------------------------------------------------------------------- | |
221 | ||
222 | bool wxButton::SendClickEvent() | |
223 | { | |
224 | return false; | |
225 | } | |
226 | ||
808e3bce | 227 | void wxButton::Command(wxCommandEvent &event) |
ffecfa5a JS |
228 | { |
229 | } | |
230 | ||
ffecfa5a JS |
231 | #endif // wxUSE_BUTTON |
232 |