]> git.saurik.com Git - wxWidgets.git/blame - src/palmos/toplevel.cpp
supress warning about in custom build steps with VC7+ (temporary workaround until...
[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
ffecfa5a
JS
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
1832043f
WS
27#include "wx/toplevel.h"
28
ffecfa5a
JS
29#ifndef WX_PRECOMP
30 #include "wx/app.h"
ffecfa5a
JS
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()
f1e01716 37 #include "wx/button.h"
ab1ce969 38 #include "wx/checkbox.h"
b0b5881a 39 #include "wx/radiobut.h"
f4da9a94 40 #include "wx/slider.h"
02761f6c 41 #include "wx/module.h"
ffecfa5a
JS
42#endif //WX_PRECOMP
43
ffecfa5a
JS
44#include "wx/display.h"
45
a152561c 46// controls for sending select event
a152561c 47#include "wx/tglbtn.h"
6a27c749 48#include "wx/datectrl.h"
a152561c 49
20bc5ad8
WS
50#include <Window.h>
51#include <Form.h>
52
ffecfa5a
JS
53// ----------------------------------------------------------------------------
54// globals
55// ----------------------------------------------------------------------------
56
57// the name of the default wxWidgets class
58extern const wxChar *wxCanvasClassName;
59
60// Pointer to the currently active frame for the form event handler.
db101bd3 61wxTopLevelWindowPalm* ActiveParentFrame;
ffecfa5a 62
20bc5ad8
WS
63static Boolean FrameFormHandleEvent(EventType *event);
64
ffecfa5a
JS
65// ============================================================================
66// wxTopLevelWindowPalm implementation
67// ============================================================================
68
69BEGIN_EVENT_TABLE(wxTopLevelWindowPalm, wxTopLevelWindowBase)
70 EVT_ACTIVATE(wxTopLevelWindowPalm::OnActivate)
71END_EVENT_TABLE()
72
73// ----------------------------------------------------------------------------
74// wxTopLevelWindowPalm creation
75// ----------------------------------------------------------------------------
76
77void wxTopLevelWindowPalm::Init()
78{
79}
80
81WXDWORD wxTopLevelWindowPalm::PalmGetStyle(long style, WXDWORD *exflags) const
82{
83 return 0;
84}
85
ffecfa5a 86bool wxTopLevelWindowPalm::Create(wxWindow *parent,
e9c52a40
WS
87 wxWindowID id,
88 const wxString& title,
89 const wxPoint& pos,
90 const wxSize& size,
91 long style,
92 const wxString& name)
ffecfa5a 93{
db101bd3
WS
94 // this is a check for limitation mentioned before FrameFormHandleEvent() code
95 if(wxTopLevelWindows.GetCount()>0)
ffecfa5a
JS
96 return false;
97
db101bd3 98 ActiveParentFrame=NULL;
ffecfa5a 99
ffecfa5a
JS
100 wxTopLevelWindows.Append(this);
101
102 if ( parent )
103 parent->AddChild(this);
104
ba889513 105 SetId( id == wxID_ANY ? NewControlId() : id );
ffecfa5a 106
db101bd3
WS
107 WinConstraintsType constraints;
108 memset(&constraints, 0, sizeof(WinConstraintsType));
ba889513 109 // position
db101bd3
WS
110 constraints.x_pos = ( pos.x == wxDefaultCoord ) ? winUndefConstraint : pos.x;
111 constraints.y_pos = ( pos.y == wxDefaultCoord ) ? winUndefConstraint : pos.y;
ba889513 112 // size
db101bd3
WS
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(
ba889513 121 GetId(),
db101bd3
WS
122 title.c_str(),
123 winFlagBackBuffer,
124 &constraints,
125 0,
126 NULL,
127 0,
128 NULL,
129 0
130 );
131
132 if(FrameForm==NULL)
ffecfa5a
JS
133 return false;
134
20bc5ad8 135 FrmSetEventHandler((FormType *)FrameForm,FrameFormHandleEvent);
e9c52a40 136
20bc5ad8 137 FrmSetActiveForm((FormType *)FrameForm);
e9c52a40 138
db101bd3 139 ActiveParentFrame=this;
e9c52a40 140
ffecfa5a
JS
141 return true;
142}
143
144wxTopLevelWindowPalm::~wxTopLevelWindowPalm()
145{
146}
147
324eeecb
WS
148// ---------------------------------------------------------------------------
149// implementation
150// ---------------------------------------------------------------------------
151
152WXWINHANDLE wxTopLevelWindowPalm::GetWinHandle() const
153{
20bc5ad8 154 FormType *form = (FormType *)GetForm();
324eeecb
WS
155 if(form)
156 return FrmGetWindowHandle(form);
20bc5ad8 157 return NULL;
324eeecb
WS
158}
159
ffecfa5a
JS
160// ----------------------------------------------------------------------------
161// wxTopLevelWindowPalm showing
162// ----------------------------------------------------------------------------
163
164void wxTopLevelWindowPalm::DoShowWindow(int nShowCmd)
165{
166}
167
168bool wxTopLevelWindowPalm::Show(bool show)
169{
e2fc40b4
VZ
170 if (true != show) {
171 return true;
172 }
20bc5ad8 173 FrmDrawForm((FormType *)FrameForm);
e9c52a40 174
ffecfa5a
JS
175 wxPaintEvent event(m_windowId);
176 event.SetEventObject(this);
937013e0 177 HandleWindowEvent(event);
e9c52a40 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
0ab48d64
WS
231void wxTopLevelWindowPalm::SetTitle( const wxString& WXUNUSED(title))
232{
233}
234
235wxString wxTopLevelWindowPalm::GetTitle() const
236{
237 return wxEmptyString;
238}
239
ffecfa5a
JS
240void wxTopLevelWindowPalm::SetIcons(const wxIconBundle& icons)
241{
242}
243
244bool wxTopLevelWindowPalm::EnableCloseButton(bool enable)
245{
246 return false;
247}
248
20bc5ad8 249WXFORMPTR wxTopLevelWindowPalm::GetForm() const
bdb54365 250{
808e3bce 251 return FrmGetActiveForm();
bdb54365
WS
252}
253
ffecfa5a
JS
254bool wxTopLevelWindowPalm::SetShape(const wxRegion& region)
255{
256 return false;
257}
258
ffecfa5a 259// ----------------------------------------------------------------------------
721a9626 260// wxTopLevelWindow native event handling
ffecfa5a
JS
261// ----------------------------------------------------------------------------
262
20bc5ad8 263bool wxTopLevelWindowPalm::HandleControlSelect(WXEVENTPTR event)
a152561c 264{
20bc5ad8
WS
265 const EventType *palmEvent = (EventType *)event;
266 const int id = palmEvent->data.ctlSelect.controlID;
721a9626 267
a152561c
WS
268 wxWindow* win = FindWindowById(id,this);
269 if(win==NULL)
270 return false;
271
6a27c749 272#if wxUSE_BUTTON
a152561c
WS
273 wxButton* button = wxDynamicCast(win,wxButton);
274 if(button)
275 return button->SendClickEvent();
6a27c749 276#endif // wxUSE_BUTTON
a152561c 277
6a27c749 278#if wxUSE_CHECKBOX
a152561c
WS
279 wxCheckBox* checkbox = wxDynamicCast(win,wxCheckBox);
280 if(checkbox)
281 return checkbox->SendClickEvent();
6a27c749 282#endif // wxUSE_CHECKBOX
a152561c 283
6a27c749 284#if wxUSE_TOGGLEBTN
a152561c
WS
285 wxToggleButton* toggle = wxDynamicCast(win,wxToggleButton);
286 if(toggle)
287 return toggle->SendClickEvent();
6a27c749 288#endif // wxUSE_TOGGLEBTN
a152561c 289
6a27c749 290#if wxUSE_RADIOBTN
a152561c
WS
291 wxRadioButton* radio = wxDynamicCast(win,wxRadioButton);
292 if(radio)
293 return radio->SendClickEvent();
6a27c749 294#endif // wxUSE_RADIOBTN
a152561c 295
6a27c749
WS
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
9a727a3b
WS
303 wxSlider* slider = wxDynamicCast(win,wxSlider);
304 if(slider)
305 return slider->SendUpdatedEvent();
6a27c749 306#endif // wxUSE_SLIDER
9a727a3b 307
a152561c
WS
308 return false;
309}
310
20bc5ad8 311bool wxTopLevelWindowPalm::HandleControlRepeat(WXEVENTPTR event)
721a9626 312{
20bc5ad8
WS
313 const EventType *palmEvent = (EventType *)event;
314 const int id = palmEvent->data.ctlRepeat.controlID;
721a9626 315
20bc5ad8 316 wxWindow* win = FindWindowById(id, this);
721a9626
WS
317 if(win==NULL)
318 return false;
319
6a27c749 320#if wxUSE_SLIDER
721a9626
WS
321 wxSlider* slider = wxDynamicCast(win,wxSlider);
322 if(slider)
323 return slider->SendScrollEvent(event);
6a27c749 324#endif // wxUSE_SLIDER
721a9626
WS
325
326 return false;
327}
328
20bc5ad8 329bool wxTopLevelWindowPalm::HandleSize(WXEVENTPTR event)
721a9626 330{
20bc5ad8
WS
331 const EventType *palmEvent = (EventType *)event;
332 wxSize newSize(palmEvent->data.winResized.newBounds.extent.x,
333 palmEvent->data.winResized.newBounds.extent.y);
721a9626
WS
334 wxSizeEvent eventWx(newSize,GetId());
335 eventWx.SetEventObject(this);
937013e0 336 return HandleWindowEvent(eventWx);
721a9626
WS
337}
338
ffecfa5a
JS
339void wxTopLevelWindowPalm::OnActivate(wxActivateEvent& event)
340{
341}
342
343/* Palm OS Event handler for the window
e9c52a40
WS
344 *
345 * This function *must* be located outside of the wxTopLevelWindow class because
e2731512
WS
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
ffecfa5a 349 * its first parameter).
e2731512
WS
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
ffecfa5a
JS
355 * wbo@freeshell.org
356 */
20bc5ad8 357static Boolean FrameFormHandleEvent(EventType *event)
ffecfa5a 358{
721a9626
WS
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;
a152561c 363 Boolean handled = false;
e2731512 364
a152561c 365 switch (event->eType) {
ffecfa5a 366 case ctlSelectEvent:
721a9626
WS
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);
ffecfa5a
JS
374 break;
375#if wxUSE_MENUS_NATIVE
376 case menuOpenEvent:
a152561c 377 handled = frame->HandleMenuOpen();
e2731512 378 break;
ffecfa5a 379 case menuEvent:
a152561c 380 handled = frame->HandleMenuSelect(event);
ffecfa5a
JS
381 break;
382#endif
383 default:
384 break;
385 }
e2731512 386
a152561c 387 return handled;
ffecfa5a 388}