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