]> git.saurik.com Git - wxWidgets.git/blob - src/palmos/toplevel.cpp
Native wxStaticText. Cleaning of wxRadioBox code before native implementation. Events...
[wxWidgets.git] / src / palmos / toplevel.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/toplevel.cpp
3 // Purpose: implements wxTopLevelWindow for Palm OS
4 // Author: William Osborne - minimal working wxPalmOS port
5 // Modified by: Wlodzimierz ABX Skiba - more than minimal functionality
6 // Created: 10/13/04
7 // RCS-ID: $Id$
8 // Copyright: (c) William Osborne <wbo@freeshell.org>, 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 "toplevel.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 #ifndef WX_PRECOMP
32 #include "wx/app.h"
33 #include "wx/toplevel.h"
34 #include "wx/dialog.h"
35 #include "wx/string.h"
36 #include "wx/log.h"
37 #include "wx/intl.h"
38 #include "wx/frame.h"
39 #include "wx/containr.h" // wxSetFocusToChild()
40 #endif //WX_PRECOMP
41
42 #include "wx/module.h"
43 #include "wx/display.h"
44
45 // controls for sending select event
46 #include "wx/button.h"
47 #include "wx/checkbox.h"
48 #include "wx/radiobut.h"
49 #include "wx/tglbtn.h"
50
51 // ----------------------------------------------------------------------------
52 // globals
53 // ----------------------------------------------------------------------------
54
55 // the name of the default wxWidgets class
56 extern const wxChar *wxCanvasClassName;
57
58 // Pointer to the currently active frame for the form event handler.
59 wxTopLevelWindowPalm* ActiveParentFrame;
60
61 // ============================================================================
62 // wxTopLevelWindowPalm implementation
63 // ============================================================================
64
65 BEGIN_EVENT_TABLE(wxTopLevelWindowPalm, wxTopLevelWindowBase)
66 EVT_ACTIVATE(wxTopLevelWindowPalm::OnActivate)
67 END_EVENT_TABLE()
68
69 // ----------------------------------------------------------------------------
70 // wxTopLevelWindowPalm creation
71 // ----------------------------------------------------------------------------
72
73 void wxTopLevelWindowPalm::Init()
74 {
75 }
76
77 WXDWORD wxTopLevelWindowPalm::PalmGetStyle(long style, WXDWORD *exflags) const
78 {
79 return 0;
80 }
81
82 WXHWND wxTopLevelWindowPalm::PalmGetParent() const
83 {
84 return NULL;
85 }
86
87 bool wxTopLevelWindowPalm::Create(wxWindow *parent,
88 wxWindowID id,
89 const wxString& title,
90 const wxPoint& pos,
91 const wxSize& size,
92 long style,
93 const wxString& name)
94 {
95 // this is a check for limitation mentioned before FrameFormHandleEvent() code
96 if(wxTopLevelWindows.GetCount()>0)
97 return false;
98
99 ActiveParentFrame=NULL;
100
101 wxTopLevelWindows.Append(this);
102
103 if ( parent )
104 parent->AddChild(this);
105
106 SetId( id == wxID_ANY ? NewControlId() : id );
107
108 WinConstraintsType constraints;
109 memset(&constraints, 0, sizeof(WinConstraintsType));
110 // position
111 constraints.x_pos = ( pos.x == wxDefaultCoord ) ? winUndefConstraint : pos.x;
112 constraints.y_pos = ( pos.y == wxDefaultCoord ) ? winUndefConstraint : pos.y;
113 // size
114 constraints.x_min = winUndefConstraint;
115 constraints.x_max = winMaxConstraint;
116 constraints.x_pref = ( size.x == wxDefaultCoord ) ? winUndefConstraint : size.x;
117 constraints.y_min = winUndefConstraint;
118 constraints.y_max = winMaxConstraint;
119 constraints.y_pref = ( size.y == wxDefaultCoord ) ? winUndefConstraint : size.y;
120
121 FrameForm = FrmNewFormWithConstraints(
122 GetId(),
123 title.c_str(),
124 winFlagBackBuffer,
125 &constraints,
126 0,
127 NULL,
128 0,
129 NULL,
130 0
131 );
132
133 if(FrameForm==NULL)
134 return false;
135
136 FrmSetEventHandler(FrameForm,FrameFormHandleEvent);
137
138 FrmSetActiveForm(FrameForm);
139
140 ActiveParentFrame=this;
141
142 return true;
143 }
144
145 wxTopLevelWindowPalm::~wxTopLevelWindowPalm()
146 {
147 }
148
149 // ----------------------------------------------------------------------------
150 // wxTopLevelWindowPalm showing
151 // ----------------------------------------------------------------------------
152
153 void wxTopLevelWindowPalm::DoShowWindow(int nShowCmd)
154 {
155 }
156
157 bool wxTopLevelWindowPalm::Show(bool show)
158 {
159 FrmDrawForm(FrameForm);
160
161 wxPaintEvent event(m_windowId);
162 event.SetEventObject(this);
163 GetEventHandler()->ProcessEvent(event);
164
165 return true;
166 }
167
168 // ----------------------------------------------------------------------------
169 // wxTopLevelWindowPalm maximize/minimize
170 // ----------------------------------------------------------------------------
171
172 void wxTopLevelWindowPalm::Maximize(bool maximize)
173 {
174 }
175
176 bool wxTopLevelWindowPalm::IsMaximized() const
177 {
178 return false;
179 }
180
181 void wxTopLevelWindowPalm::Iconize(bool iconize)
182 {
183 }
184
185 bool wxTopLevelWindowPalm::IsIconized() const
186 {
187 return false;
188 }
189
190 void wxTopLevelWindowPalm::Restore()
191 {
192 }
193
194 void wxTopLevelWindowPalm::DoGetSize( int *width, int *height ) const
195 {
196 RectangleType rect;
197 FrmGetFormBounds( GetForm() , &rect );
198 if(width)
199 *width = rect.extent.x;
200 if(height)
201 *height = rect.extent.y;
202 }
203
204 // ----------------------------------------------------------------------------
205 // wxTopLevelWindowPalm fullscreen
206 // ----------------------------------------------------------------------------
207
208 bool wxTopLevelWindowPalm::ShowFullScreen(bool show, long style)
209 {
210 return false;
211 }
212
213 // ----------------------------------------------------------------------------
214 // wxTopLevelWindowPalm misc
215 // ----------------------------------------------------------------------------
216
217 void wxTopLevelWindowPalm::SetIcon(const wxIcon& icon)
218 {
219 }
220
221 void wxTopLevelWindowPalm::SetIcons(const wxIconBundle& icons)
222 {
223 }
224
225 bool wxTopLevelWindowPalm::EnableCloseButton(bool enable)
226 {
227 return false;
228 }
229
230 FormType *wxTopLevelWindowPalm::GetForm() const
231 {
232 return FrmGetActiveForm();
233 }
234
235 #ifndef __WXWINCE__
236
237 bool wxTopLevelWindowPalm::SetShape(const wxRegion& region)
238 {
239 return false;
240 }
241
242 #endif // !__WXWINCE__
243
244 // ----------------------------------------------------------------------------
245 // wxTopLevelWindow event handling
246 // ----------------------------------------------------------------------------
247
248 bool wxTopLevelWindowPalm::HandleControlSelect(EventType* event)
249 {
250 int id = event->data.ctlSelect.controlID;
251 wxWindow* win = FindWindowById(id,this);
252 if(win==NULL)
253 return false;
254
255 wxButton* button = wxDynamicCast(win,wxButton);
256 if(button)
257 return button->SendClickEvent();
258
259 wxCheckBox* checkbox = wxDynamicCast(win,wxCheckBox);
260 if(checkbox)
261 return checkbox->SendClickEvent();
262
263 wxToggleButton* toggle = wxDynamicCast(win,wxToggleButton);
264 if(toggle)
265 return toggle->SendClickEvent();
266
267 wxRadioButton* radio = wxDynamicCast(win,wxRadioButton);
268 if(radio)
269 return radio->SendClickEvent();
270
271 return false;
272 }
273
274 void wxTopLevelWindowPalm::OnActivate(wxActivateEvent& event)
275 {
276 }
277
278 /* Palm OS Event handler for the window
279 *
280 * This function *must* be located outside of the wxTopLevelWindow class because
281 * the Palm OS API expects a standalone C function as a callback. You cannot
282 * pass a pointer to a member function of a C++ class as a callback because the
283 * prototypes don't match. (A member function has a hidden "this" pointer as
284 * its first parameter).
285 *
286 * This event handler uses a global pointer to the current wxFrame to process
287 * the events generated by the Palm OS form API. I know this is ugly, but right
288 * now I can't think of any other way to deal with this problem. If someone
289 * finds a better solution, please let me know. My email address is
290 * wbo@freeshell.org
291 */
292 static Boolean FrameFormHandleEvent(EventType* event)
293 {
294 wxFrame* frame = wxDynamicCast(ActiveParentFrame,wxFrame);
295 Boolean handled = false;
296
297 switch (event->eType) {
298 case ctlSelectEvent:
299 handled = frame->HandleControlSelect(event);
300 break;
301 #if wxUSE_MENUS_NATIVE
302 case menuOpenEvent:
303 handled = frame->HandleMenuOpen();
304 break;
305 case menuEvent:
306 handled = frame->HandleMenuSelect(event);
307 break;
308 #endif
309 default:
310 break;
311 }
312
313 return handled;
314 }