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