]> git.saurik.com Git - wxWidgets.git/blob - src/palmos/toplevel.cpp
Global platform header (<PalmOS.h>) removed from public wx-headers (but included...
[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 #include "wx/slider.h"
51 #include "wx/datectrl.h"
52
53 #include <Window.h>
54 #include <Form.h>
55
56 // ----------------------------------------------------------------------------
57 // globals
58 // ----------------------------------------------------------------------------
59
60 // the name of the default wxWidgets class
61 extern const wxChar *wxCanvasClassName;
62
63 // Pointer to the currently active frame for the form event handler.
64 wxTopLevelWindowPalm* ActiveParentFrame;
65
66 static Boolean FrameFormHandleEvent(EventType *event);
67
68 // ============================================================================
69 // wxTopLevelWindowPalm implementation
70 // ============================================================================
71
72 BEGIN_EVENT_TABLE(wxTopLevelWindowPalm, wxTopLevelWindowBase)
73 EVT_ACTIVATE(wxTopLevelWindowPalm::OnActivate)
74 END_EVENT_TABLE()
75
76 // ----------------------------------------------------------------------------
77 // wxTopLevelWindowPalm creation
78 // ----------------------------------------------------------------------------
79
80 void wxTopLevelWindowPalm::Init()
81 {
82 }
83
84 WXDWORD wxTopLevelWindowPalm::PalmGetStyle(long style, WXDWORD *exflags) const
85 {
86 return 0;
87 }
88
89 bool wxTopLevelWindowPalm::Create(wxWindow *parent,
90 wxWindowID id,
91 const wxString& title,
92 const wxPoint& pos,
93 const wxSize& size,
94 long style,
95 const wxString& name)
96 {
97 // this is a check for limitation mentioned before FrameFormHandleEvent() code
98 if(wxTopLevelWindows.GetCount()>0)
99 return false;
100
101 ActiveParentFrame=NULL;
102
103 wxTopLevelWindows.Append(this);
104
105 if ( parent )
106 parent->AddChild(this);
107
108 SetId( id == wxID_ANY ? NewControlId() : id );
109
110 WinConstraintsType constraints;
111 memset(&constraints, 0, sizeof(WinConstraintsType));
112 // position
113 constraints.x_pos = ( pos.x == wxDefaultCoord ) ? winUndefConstraint : pos.x;
114 constraints.y_pos = ( pos.y == wxDefaultCoord ) ? winUndefConstraint : pos.y;
115 // size
116 constraints.x_min = winUndefConstraint;
117 constraints.x_max = winMaxConstraint;
118 constraints.x_pref = ( size.x == wxDefaultCoord ) ? winUndefConstraint : size.x;
119 constraints.y_min = winUndefConstraint;
120 constraints.y_max = winMaxConstraint;
121 constraints.y_pref = ( size.y == wxDefaultCoord ) ? winUndefConstraint : size.y;
122
123 FrameForm = FrmNewFormWithConstraints(
124 GetId(),
125 title.c_str(),
126 winFlagBackBuffer,
127 &constraints,
128 0,
129 NULL,
130 0,
131 NULL,
132 0
133 );
134
135 if(FrameForm==NULL)
136 return false;
137
138 FrmSetEventHandler((FormType *)FrameForm,FrameFormHandleEvent);
139
140 FrmSetActiveForm((FormType *)FrameForm);
141
142 ActiveParentFrame=this;
143
144 return true;
145 }
146
147 wxTopLevelWindowPalm::~wxTopLevelWindowPalm()
148 {
149 }
150
151 // ---------------------------------------------------------------------------
152 // implementation
153 // ---------------------------------------------------------------------------
154
155 WXWINHANDLE wxTopLevelWindowPalm::GetWinHandle() const
156 {
157 FormType *form = (FormType *)GetForm();
158 if(form)
159 return FrmGetWindowHandle(form);
160 return NULL;
161 }
162
163 // ----------------------------------------------------------------------------
164 // wxTopLevelWindowPalm showing
165 // ----------------------------------------------------------------------------
166
167 void wxTopLevelWindowPalm::DoShowWindow(int nShowCmd)
168 {
169 }
170
171 bool wxTopLevelWindowPalm::Show(bool show)
172 {
173 FrmDrawForm((FormType *)FrameForm);
174
175 wxPaintEvent event(m_windowId);
176 event.SetEventObject(this);
177 GetEventHandler()->ProcessEvent(event);
178
179 return true;
180 }
181
182 // ----------------------------------------------------------------------------
183 // wxTopLevelWindowPalm maximize/minimize
184 // ----------------------------------------------------------------------------
185
186 void wxTopLevelWindowPalm::Maximize(bool maximize)
187 {
188 }
189
190 bool wxTopLevelWindowPalm::IsMaximized() const
191 {
192 return false;
193 }
194
195 void wxTopLevelWindowPalm::Iconize(bool iconize)
196 {
197 }
198
199 bool wxTopLevelWindowPalm::IsIconized() const
200 {
201 return false;
202 }
203
204 void wxTopLevelWindowPalm::Restore()
205 {
206 }
207
208 void wxTopLevelWindowPalm::DoGetSize( int *width, int *height ) const
209 {
210 RectangleType rect;
211 FrmGetFormBounds( (FormType *)GetForm() , &rect );
212 if(width)
213 *width = rect.extent.x;
214 if(height)
215 *height = rect.extent.y;
216 }
217
218 // ----------------------------------------------------------------------------
219 // wxTopLevelWindowPalm fullscreen
220 // ----------------------------------------------------------------------------
221
222 bool wxTopLevelWindowPalm::ShowFullScreen(bool show, long style)
223 {
224 return false;
225 }
226
227 // ----------------------------------------------------------------------------
228 // wxTopLevelWindowPalm misc
229 // ----------------------------------------------------------------------------
230
231 void wxTopLevelWindowPalm::SetIcon(const wxIcon& icon)
232 {
233 }
234
235 void wxTopLevelWindowPalm::SetIcons(const wxIconBundle& icons)
236 {
237 }
238
239 bool wxTopLevelWindowPalm::EnableCloseButton(bool enable)
240 {
241 return false;
242 }
243
244 WXFORMPTR wxTopLevelWindowPalm::GetForm() const
245 {
246 return FrmGetActiveForm();
247 }
248
249 bool wxTopLevelWindowPalm::SetShape(const wxRegion& region)
250 {
251 return false;
252 }
253
254 // ----------------------------------------------------------------------------
255 // wxTopLevelWindow native event handling
256 // ----------------------------------------------------------------------------
257
258 bool wxTopLevelWindowPalm::HandleControlSelect(WXEVENTPTR event)
259 {
260 const EventType *palmEvent = (EventType *)event;
261 const int id = palmEvent->data.ctlSelect.controlID;
262
263 wxWindow* win = FindWindowById(id,this);
264 if(win==NULL)
265 return false;
266
267 #if wxUSE_BUTTON
268 wxButton* button = wxDynamicCast(win,wxButton);
269 if(button)
270 return button->SendClickEvent();
271 #endif // wxUSE_BUTTON
272
273 #if wxUSE_CHECKBOX
274 wxCheckBox* checkbox = wxDynamicCast(win,wxCheckBox);
275 if(checkbox)
276 return checkbox->SendClickEvent();
277 #endif // wxUSE_CHECKBOX
278
279 #if wxUSE_TOGGLEBTN
280 wxToggleButton* toggle = wxDynamicCast(win,wxToggleButton);
281 if(toggle)
282 return toggle->SendClickEvent();
283 #endif // wxUSE_TOGGLEBTN
284
285 #if wxUSE_RADIOBTN
286 wxRadioButton* radio = wxDynamicCast(win,wxRadioButton);
287 if(radio)
288 return radio->SendClickEvent();
289 #endif // wxUSE_RADIOBTN
290
291 #if wxUSE_DATEPICKCTRL
292 wxDatePickerCtrl* datepicker = wxDynamicCast(win,wxDatePickerCtrl);
293 if(datepicker)
294 return datepicker->SendClickEvent();
295 #endif // wxUSE_DATEPICKCTRL
296
297 #if wxUSE_SLIDER
298 wxSlider* slider = wxDynamicCast(win,wxSlider);
299 if(slider)
300 return slider->SendUpdatedEvent();
301 #endif // wxUSE_SLIDER
302
303 return false;
304 }
305
306 bool wxTopLevelWindowPalm::HandleControlRepeat(WXEVENTPTR event)
307 {
308 const EventType *palmEvent = (EventType *)event;
309 const int id = palmEvent->data.ctlRepeat.controlID;
310
311 wxWindow* win = FindWindowById(id, this);
312 if(win==NULL)
313 return false;
314
315 #if wxUSE_SLIDER
316 wxSlider* slider = wxDynamicCast(win,wxSlider);
317 if(slider)
318 return slider->SendScrollEvent(event);
319 #endif // wxUSE_SLIDER
320
321 return false;
322 }
323
324 bool wxTopLevelWindowPalm::HandleSize(WXEVENTPTR event)
325 {
326 const EventType *palmEvent = (EventType *)event;
327 wxSize newSize(palmEvent->data.winResized.newBounds.extent.x,
328 palmEvent->data.winResized.newBounds.extent.y);
329 wxSizeEvent eventWx(newSize,GetId());
330 eventWx.SetEventObject(this);
331 return GetEventHandler()->ProcessEvent(eventWx);
332 }
333
334 void wxTopLevelWindowPalm::OnActivate(wxActivateEvent& event)
335 {
336 }
337
338 /* Palm OS Event handler for the window
339 *
340 * This function *must* be located outside of the wxTopLevelWindow class because
341 * the Palm OS API expects a standalone C function as a callback. You cannot
342 * pass a pointer to a member function of a C++ class as a callback because the
343 * prototypes don't match. (A member function has a hidden "this" pointer as
344 * its first parameter).
345 *
346 * This event handler uses a global pointer to the current wxFrame to process
347 * the events generated by the Palm OS form API. I know this is ugly, but right
348 * now I can't think of any other way to deal with this problem. If someone
349 * finds a better solution, please let me know. My email address is
350 * wbo@freeshell.org
351 */
352 static Boolean FrameFormHandleEvent(EventType *event)
353 {
354 // frame and tlw point to the same object but they are for convenience
355 // of calling proper structure withiout later dynamic typcasting
356 wxFrame* frame = wxDynamicCast(ActiveParentFrame,wxFrame);
357 wxTopLevelWindowPalm* tlw = ActiveParentFrame;
358 Boolean handled = false;
359
360 switch (event->eType) {
361 case ctlSelectEvent:
362 handled = tlw->HandleControlSelect(event);
363 break;
364 case ctlRepeatEvent:
365 handled = tlw->HandleControlRepeat(event);
366 break;
367 case winResizedEvent:
368 handled = tlw->HandleSize(event);
369 break;
370 #if wxUSE_MENUS_NATIVE
371 case menuOpenEvent:
372 handled = frame->HandleMenuOpen();
373 break;
374 case menuEvent:
375 handled = frame->HandleMenuSelect(event);
376 break;
377 #endif
378 default:
379 break;
380 }
381
382 return handled;
383 }