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