]> git.saurik.com Git - wxWidgets.git/blame - src/palmos/toplevel.cpp
Fix STL compilation (note: this is not the correct fix, but since
[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
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
JS
62
63// ============================================================================
64// wxTopLevelWindowPalm implementation
65// ============================================================================
66
67BEGIN_EVENT_TABLE(wxTopLevelWindowPalm, wxTopLevelWindowBase)
68 EVT_ACTIVATE(wxTopLevelWindowPalm::OnActivate)
69END_EVENT_TABLE()
70
71// ----------------------------------------------------------------------------
72// wxTopLevelWindowPalm creation
73// ----------------------------------------------------------------------------
74
75void wxTopLevelWindowPalm::Init()
76{
77}
78
79WXDWORD wxTopLevelWindowPalm::PalmGetStyle(long style, WXDWORD *exflags) const
80{
81 return 0;
82}
83
ffecfa5a 84bool wxTopLevelWindowPalm::Create(wxWindow *parent,
e9c52a40
WS
85 wxWindowID id,
86 const wxString& title,
87 const wxPoint& pos,
88 const wxSize& size,
89 long style,
90 const wxString& name)
ffecfa5a 91{
db101bd3
WS
92 // this is a check for limitation mentioned before FrameFormHandleEvent() code
93 if(wxTopLevelWindows.GetCount()>0)
ffecfa5a
JS
94 return false;
95
db101bd3 96 ActiveParentFrame=NULL;
ffecfa5a 97
ffecfa5a
JS
98 wxTopLevelWindows.Append(this);
99
100 if ( parent )
101 parent->AddChild(this);
102
ba889513 103 SetId( id == wxID_ANY ? NewControlId() : id );
ffecfa5a 104
db101bd3
WS
105 WinConstraintsType constraints;
106 memset(&constraints, 0, sizeof(WinConstraintsType));
ba889513 107 // position
db101bd3
WS
108 constraints.x_pos = ( pos.x == wxDefaultCoord ) ? winUndefConstraint : pos.x;
109 constraints.y_pos = ( pos.y == wxDefaultCoord ) ? winUndefConstraint : pos.y;
ba889513 110 // size
db101bd3
WS
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(
ba889513 119 GetId(),
db101bd3
WS
120 title.c_str(),
121 winFlagBackBuffer,
122 &constraints,
123 0,
124 NULL,
125 0,
126 NULL,
127 0
128 );
129
130 if(FrameForm==NULL)
ffecfa5a
JS
131 return false;
132
133 FrmSetEventHandler(FrameForm,FrameFormHandleEvent);
e9c52a40 134
ffecfa5a 135 FrmSetActiveForm(FrameForm);
e9c52a40 136
db101bd3 137 ActiveParentFrame=this;
e9c52a40 138
ffecfa5a
JS
139 return true;
140}
141
142wxTopLevelWindowPalm::~wxTopLevelWindowPalm()
143{
144}
145
324eeecb
WS
146// ---------------------------------------------------------------------------
147// implementation
148// ---------------------------------------------------------------------------
149
150WXWINHANDLE wxTopLevelWindowPalm::GetWinHandle() const
151{
152 FormType *form = GetForm();
153 if(form)
154 return FrmGetWindowHandle(form);
155 return 0;
156}
157
ffecfa5a
JS
158// ----------------------------------------------------------------------------
159// wxTopLevelWindowPalm showing
160// ----------------------------------------------------------------------------
161
162void wxTopLevelWindowPalm::DoShowWindow(int nShowCmd)
163{
164}
165
166bool wxTopLevelWindowPalm::Show(bool show)
167{
168 FrmDrawForm(FrameForm);
e9c52a40 169
ffecfa5a
JS
170 wxPaintEvent event(m_windowId);
171 event.SetEventObject(this);
e9c52a40
WS
172 GetEventHandler()->ProcessEvent(event);
173
ffecfa5a
JS
174 return true;
175}
176
177// ----------------------------------------------------------------------------
178// wxTopLevelWindowPalm maximize/minimize
179// ----------------------------------------------------------------------------
180
181void wxTopLevelWindowPalm::Maximize(bool maximize)
182{
183}
184
185bool wxTopLevelWindowPalm::IsMaximized() const
186{
187 return false;
188}
189
190void wxTopLevelWindowPalm::Iconize(bool iconize)
191{
192}
193
194bool wxTopLevelWindowPalm::IsIconized() const
195{
196 return false;
197}
198
199void wxTopLevelWindowPalm::Restore()
200{
201}
202
808e3bce
WS
203void 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
ffecfa5a
JS
213// ----------------------------------------------------------------------------
214// wxTopLevelWindowPalm fullscreen
215// ----------------------------------------------------------------------------
216
217bool wxTopLevelWindowPalm::ShowFullScreen(bool show, long style)
218{
219 return false;
220}
221
222// ----------------------------------------------------------------------------
223// wxTopLevelWindowPalm misc
224// ----------------------------------------------------------------------------
225
226void wxTopLevelWindowPalm::SetIcon(const wxIcon& icon)
227{
228}
229
230void wxTopLevelWindowPalm::SetIcons(const wxIconBundle& icons)
231{
232}
233
234bool wxTopLevelWindowPalm::EnableCloseButton(bool enable)
235{
236 return false;
237}
238
808e3bce 239FormType *wxTopLevelWindowPalm::GetForm() const
bdb54365 240{
808e3bce 241 return FrmGetActiveForm();
bdb54365
WS
242}
243
ffecfa5a
JS
244bool wxTopLevelWindowPalm::SetShape(const wxRegion& region)
245{
246 return false;
247}
248
ffecfa5a 249// ----------------------------------------------------------------------------
721a9626 250// wxTopLevelWindow native event handling
ffecfa5a
JS
251// ----------------------------------------------------------------------------
252
a152561c
WS
253bool wxTopLevelWindowPalm::HandleControlSelect(EventType* event)
254{
255 int id = event->data.ctlSelect.controlID;
721a9626 256
a152561c
WS
257 wxWindow* win = FindWindowById(id,this);
258 if(win==NULL)
259 return false;
260
6a27c749 261#if wxUSE_BUTTON
a152561c
WS
262 wxButton* button = wxDynamicCast(win,wxButton);
263 if(button)
264 return button->SendClickEvent();
6a27c749 265#endif // wxUSE_BUTTON
a152561c 266
6a27c749 267#if wxUSE_CHECKBOX
a152561c
WS
268 wxCheckBox* checkbox = wxDynamicCast(win,wxCheckBox);
269 if(checkbox)
270 return checkbox->SendClickEvent();
6a27c749 271#endif // wxUSE_CHECKBOX
a152561c 272
6a27c749 273#if wxUSE_TOGGLEBTN
a152561c
WS
274 wxToggleButton* toggle = wxDynamicCast(win,wxToggleButton);
275 if(toggle)
276 return toggle->SendClickEvent();
6a27c749 277#endif // wxUSE_TOGGLEBTN
a152561c 278
6a27c749 279#if wxUSE_RADIOBTN
a152561c
WS
280 wxRadioButton* radio = wxDynamicCast(win,wxRadioButton);
281 if(radio)
282 return radio->SendClickEvent();
6a27c749 283#endif // wxUSE_RADIOBTN
a152561c 284
6a27c749
WS
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
9a727a3b
WS
292 wxSlider* slider = wxDynamicCast(win,wxSlider);
293 if(slider)
294 return slider->SendUpdatedEvent();
6a27c749 295#endif // wxUSE_SLIDER
9a727a3b 296
a152561c
WS
297 return false;
298}
299
721a9626
WS
300bool 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
6a27c749 308#if wxUSE_SLIDER
721a9626
WS
309 wxSlider* slider = wxDynamicCast(win,wxSlider);
310 if(slider)
311 return slider->SendScrollEvent(event);
6a27c749 312#endif // wxUSE_SLIDER
721a9626
WS
313
314 return false;
315}
316
317bool 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
ffecfa5a
JS
326void wxTopLevelWindowPalm::OnActivate(wxActivateEvent& event)
327{
328}
329
330/* Palm OS Event handler for the window
e9c52a40
WS
331 *
332 * This function *must* be located outside of the wxTopLevelWindow class because
e2731512
WS
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
ffecfa5a 336 * its first parameter).
e2731512
WS
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
ffecfa5a
JS
342 * wbo@freeshell.org
343 */
a152561c 344static Boolean FrameFormHandleEvent(EventType* event)
ffecfa5a 345{
721a9626
WS
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;
a152561c 350 Boolean handled = false;
e2731512 351
a152561c 352 switch (event->eType) {
ffecfa5a 353 case ctlSelectEvent:
721a9626
WS
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);
ffecfa5a
JS
361 break;
362#if wxUSE_MENUS_NATIVE
363 case menuOpenEvent:
a152561c 364 handled = frame->HandleMenuOpen();
e2731512 365 break;
ffecfa5a 366 case menuEvent:
a152561c 367 handled = frame->HandleMenuSelect(event);
ffecfa5a
JS
368 break;
369#endif
370 default:
371 break;
372 }
e2731512 373
a152561c 374 return handled;
ffecfa5a 375}