]> git.saurik.com Git - wxWidgets.git/blame - src/palmos/toplevel.cpp
Rebake after recguard.h added to bakefiles
[wxWidgets.git] / src / palmos / toplevel.cpp
CommitLineData
ffecfa5a 1///////////////////////////////////////////////////////////////////////////////
e9c52a40 2// Name: src/palmos/toplevel.cpp
ffecfa5a 3// Purpose: implements wxTopLevelWindow for Palm OS
e9c52a40
WS
4// Author: William Osborne - minimal working wxPalmOS port
5// Modified by: Wlodzimierz ABX Skiba - more than minimal functionality
ffecfa5a 6// Created: 10/13/04
e9c52a40
WS
7// RCS-ID: $Id$
8// Copyright: (c) William Osborne <wbo@freeshell.org>, Wlodzimierz Skiba
ffecfa5a
JS
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"
ffecfa5a
JS
43#include "wx/display.h"
44
a152561c
WS
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"
9a727a3b 50#include "wx/slider.h"
6a27c749 51#include "wx/datectrl.h"
a152561c 52
20bc5ad8
WS
53#include <Window.h>
54#include <Form.h>
55
ffecfa5a
JS
56// ----------------------------------------------------------------------------
57// globals
58// ----------------------------------------------------------------------------
59
60// the name of the default wxWidgets class
61extern const wxChar *wxCanvasClassName;
62
63// Pointer to the currently active frame for the form event handler.
db101bd3 64wxTopLevelWindowPalm* ActiveParentFrame;
ffecfa5a 65
20bc5ad8
WS
66static Boolean FrameFormHandleEvent(EventType *event);
67
ffecfa5a
JS
68// ============================================================================
69// wxTopLevelWindowPalm implementation
70// ============================================================================
71
72BEGIN_EVENT_TABLE(wxTopLevelWindowPalm, wxTopLevelWindowBase)
73 EVT_ACTIVATE(wxTopLevelWindowPalm::OnActivate)
74END_EVENT_TABLE()
75
76// ----------------------------------------------------------------------------
77// wxTopLevelWindowPalm creation
78// ----------------------------------------------------------------------------
79
80void wxTopLevelWindowPalm::Init()
81{
82}
83
84WXDWORD wxTopLevelWindowPalm::PalmGetStyle(long style, WXDWORD *exflags) const
85{
86 return 0;
87}
88
ffecfa5a 89bool wxTopLevelWindowPalm::Create(wxWindow *parent,
e9c52a40
WS
90 wxWindowID id,
91 const wxString& title,
92 const wxPoint& pos,
93 const wxSize& size,
94 long style,
95 const wxString& name)
ffecfa5a 96{
db101bd3
WS
97 // this is a check for limitation mentioned before FrameFormHandleEvent() code
98 if(wxTopLevelWindows.GetCount()>0)
ffecfa5a
JS
99 return false;
100
db101bd3 101 ActiveParentFrame=NULL;
ffecfa5a 102
ffecfa5a
JS
103 wxTopLevelWindows.Append(this);
104
105 if ( parent )
106 parent->AddChild(this);
107
ba889513 108 SetId( id == wxID_ANY ? NewControlId() : id );
ffecfa5a 109
db101bd3
WS
110 WinConstraintsType constraints;
111 memset(&constraints, 0, sizeof(WinConstraintsType));
ba889513 112 // position
db101bd3
WS
113 constraints.x_pos = ( pos.x == wxDefaultCoord ) ? winUndefConstraint : pos.x;
114 constraints.y_pos = ( pos.y == wxDefaultCoord ) ? winUndefConstraint : pos.y;
ba889513 115 // size
db101bd3
WS
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(
ba889513 124 GetId(),
db101bd3
WS
125 title.c_str(),
126 winFlagBackBuffer,
127 &constraints,
128 0,
129 NULL,
130 0,
131 NULL,
132 0
133 );
134
135 if(FrameForm==NULL)
ffecfa5a
JS
136 return false;
137
20bc5ad8 138 FrmSetEventHandler((FormType *)FrameForm,FrameFormHandleEvent);
e9c52a40 139
20bc5ad8 140 FrmSetActiveForm((FormType *)FrameForm);
e9c52a40 141
db101bd3 142 ActiveParentFrame=this;
e9c52a40 143
ffecfa5a
JS
144 return true;
145}
146
147wxTopLevelWindowPalm::~wxTopLevelWindowPalm()
148{
149}
150
324eeecb
WS
151// ---------------------------------------------------------------------------
152// implementation
153// ---------------------------------------------------------------------------
154
155WXWINHANDLE wxTopLevelWindowPalm::GetWinHandle() const
156{
20bc5ad8 157 FormType *form = (FormType *)GetForm();
324eeecb
WS
158 if(form)
159 return FrmGetWindowHandle(form);
20bc5ad8 160 return NULL;
324eeecb
WS
161}
162
ffecfa5a
JS
163// ----------------------------------------------------------------------------
164// wxTopLevelWindowPalm showing
165// ----------------------------------------------------------------------------
166
167void wxTopLevelWindowPalm::DoShowWindow(int nShowCmd)
168{
169}
170
171bool wxTopLevelWindowPalm::Show(bool show)
172{
20bc5ad8 173 FrmDrawForm((FormType *)FrameForm);
e9c52a40 174
ffecfa5a
JS
175 wxPaintEvent event(m_windowId);
176 event.SetEventObject(this);
e9c52a40
WS
177 GetEventHandler()->ProcessEvent(event);
178
ffecfa5a
JS
179 return true;
180}
181
182// ----------------------------------------------------------------------------
183// wxTopLevelWindowPalm maximize/minimize
184// ----------------------------------------------------------------------------
185
186void wxTopLevelWindowPalm::Maximize(bool maximize)
187{
188}
189
190bool wxTopLevelWindowPalm::IsMaximized() const
191{
192 return false;
193}
194
195void wxTopLevelWindowPalm::Iconize(bool iconize)
196{
197}
198
199bool wxTopLevelWindowPalm::IsIconized() const
200{
201 return false;
202}
203
204void wxTopLevelWindowPalm::Restore()
205{
206}
207
808e3bce
WS
208void wxTopLevelWindowPalm::DoGetSize( int *width, int *height ) const
209{
210 RectangleType rect;
20bc5ad8 211 FrmGetFormBounds( (FormType *)GetForm() , &rect );
808e3bce
WS
212 if(width)
213 *width = rect.extent.x;
214 if(height)
215 *height = rect.extent.y;
216}
217
ffecfa5a
JS
218// ----------------------------------------------------------------------------
219// wxTopLevelWindowPalm fullscreen
220// ----------------------------------------------------------------------------
221
222bool wxTopLevelWindowPalm::ShowFullScreen(bool show, long style)
223{
224 return false;
225}
226
227// ----------------------------------------------------------------------------
228// wxTopLevelWindowPalm misc
229// ----------------------------------------------------------------------------
230
231void wxTopLevelWindowPalm::SetIcon(const wxIcon& icon)
232{
233}
234
235void wxTopLevelWindowPalm::SetIcons(const wxIconBundle& icons)
236{
237}
238
239bool wxTopLevelWindowPalm::EnableCloseButton(bool enable)
240{
241 return false;
242}
243
20bc5ad8 244WXFORMPTR wxTopLevelWindowPalm::GetForm() const
bdb54365 245{
808e3bce 246 return FrmGetActiveForm();
bdb54365
WS
247}
248
ffecfa5a
JS
249bool wxTopLevelWindowPalm::SetShape(const wxRegion& region)
250{
251 return false;
252}
253
ffecfa5a 254// ----------------------------------------------------------------------------
721a9626 255// wxTopLevelWindow native event handling
ffecfa5a
JS
256// ----------------------------------------------------------------------------
257
20bc5ad8 258bool wxTopLevelWindowPalm::HandleControlSelect(WXEVENTPTR event)
a152561c 259{
20bc5ad8
WS
260 const EventType *palmEvent = (EventType *)event;
261 const int id = palmEvent->data.ctlSelect.controlID;
721a9626 262
a152561c
WS
263 wxWindow* win = FindWindowById(id,this);
264 if(win==NULL)
265 return false;
266
6a27c749 267#if wxUSE_BUTTON
a152561c
WS
268 wxButton* button = wxDynamicCast(win,wxButton);
269 if(button)
270 return button->SendClickEvent();
6a27c749 271#endif // wxUSE_BUTTON
a152561c 272
6a27c749 273#if wxUSE_CHECKBOX
a152561c
WS
274 wxCheckBox* checkbox = wxDynamicCast(win,wxCheckBox);
275 if(checkbox)
276 return checkbox->SendClickEvent();
6a27c749 277#endif // wxUSE_CHECKBOX
a152561c 278
6a27c749 279#if wxUSE_TOGGLEBTN
a152561c
WS
280 wxToggleButton* toggle = wxDynamicCast(win,wxToggleButton);
281 if(toggle)
282 return toggle->SendClickEvent();
6a27c749 283#endif // wxUSE_TOGGLEBTN
a152561c 284
6a27c749 285#if wxUSE_RADIOBTN
a152561c
WS
286 wxRadioButton* radio = wxDynamicCast(win,wxRadioButton);
287 if(radio)
288 return radio->SendClickEvent();
6a27c749 289#endif // wxUSE_RADIOBTN
a152561c 290
6a27c749
WS
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
9a727a3b
WS
298 wxSlider* slider = wxDynamicCast(win,wxSlider);
299 if(slider)
300 return slider->SendUpdatedEvent();
6a27c749 301#endif // wxUSE_SLIDER
9a727a3b 302
a152561c
WS
303 return false;
304}
305
20bc5ad8 306bool wxTopLevelWindowPalm::HandleControlRepeat(WXEVENTPTR event)
721a9626 307{
20bc5ad8
WS
308 const EventType *palmEvent = (EventType *)event;
309 const int id = palmEvent->data.ctlRepeat.controlID;
721a9626 310
20bc5ad8 311 wxWindow* win = FindWindowById(id, this);
721a9626
WS
312 if(win==NULL)
313 return false;
314
6a27c749 315#if wxUSE_SLIDER
721a9626
WS
316 wxSlider* slider = wxDynamicCast(win,wxSlider);
317 if(slider)
318 return slider->SendScrollEvent(event);
6a27c749 319#endif // wxUSE_SLIDER
721a9626
WS
320
321 return false;
322}
323
20bc5ad8 324bool wxTopLevelWindowPalm::HandleSize(WXEVENTPTR event)
721a9626 325{
20bc5ad8
WS
326 const EventType *palmEvent = (EventType *)event;
327 wxSize newSize(palmEvent->data.winResized.newBounds.extent.x,
328 palmEvent->data.winResized.newBounds.extent.y);
721a9626
WS
329 wxSizeEvent eventWx(newSize,GetId());
330 eventWx.SetEventObject(this);
331 return GetEventHandler()->ProcessEvent(eventWx);
332}
333
ffecfa5a
JS
334void wxTopLevelWindowPalm::OnActivate(wxActivateEvent& event)
335{
336}
337
338/* Palm OS Event handler for the window
e9c52a40
WS
339 *
340 * This function *must* be located outside of the wxTopLevelWindow class because
e2731512
WS
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
ffecfa5a 344 * its first parameter).
e2731512
WS
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
ffecfa5a
JS
350 * wbo@freeshell.org
351 */
20bc5ad8 352static Boolean FrameFormHandleEvent(EventType *event)
ffecfa5a 353{
721a9626
WS
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;
a152561c 358 Boolean handled = false;
e2731512 359
a152561c 360 switch (event->eType) {
ffecfa5a 361 case ctlSelectEvent:
721a9626
WS
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);
ffecfa5a
JS
369 break;
370#if wxUSE_MENUS_NATIVE
371 case menuOpenEvent:
a152561c 372 handled = frame->HandleMenuOpen();
e2731512 373 break;
ffecfa5a 374 case menuEvent:
a152561c 375 handled = frame->HandleMenuSelect(event);
ffecfa5a
JS
376 break;
377#endif
378 default:
379 break;
380 }
e2731512 381
a152561c 382 return handled;
ffecfa5a 383}