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