]> git.saurik.com Git - wxWidgets.git/blame - src/palmos/toplevel.cpp
Move wxColourData and wxFontData into separate files.
[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 94 // this is a check for limitation mentioned before FrameFormHandleEvent() code
6afc1b46 95 if(wxTopLevelWindows.GetCount() > 0) {
ffecfa5a 96 return false;
6afc1b46 97 }
ffecfa5a 98
db101bd3 99 ActiveParentFrame=NULL;
ffecfa5a 100
ffecfa5a
JS
101 wxTopLevelWindows.Append(this);
102
6afc1b46 103 if ( parent ) {
ffecfa5a 104 parent->AddChild(this);
6afc1b46 105 }
ffecfa5a 106
ba889513 107 SetId( id == wxID_ANY ? NewControlId() : id );
ffecfa5a 108
6afc1b46 109#ifdef __WXPALMOS6__
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;
db101bd3 122 FrameForm = FrmNewFormWithConstraints(
ba889513 123 GetId(),
db101bd3
WS
124 title.c_str(),
125 winFlagBackBuffer,
126 &constraints,
127 0,
128 NULL,
129 0,
130 NULL,
131 0
132 );
6afc1b46
VZ
133#else // __WXPALMOS5__
134#define winUndefConstraint 0xFFFF
135#define winMaxConstraint 288
136 // FormType *FrmNewForm (UInt16 formID, const Char *titleStrP, Coord x, Coord y, Coord width, Coord height,
137 // Boolean modal, UInt16 defaultButton, UInt16 helpRscID, UInt16 menuRscID);
138 FrameForm = FrmNewForm (GetId(), title.c_str(),
139 (( pos.x == wxDefaultCoord ) ? winUndefConstraint : pos.x),
140 (( pos.y == wxDefaultCoord ) ? winUndefConstraint : pos.y),
141 winMaxConstraint, winMaxConstraint,
142 false, 0, 0, 0);
143#endif
144 if(NULL == FrameForm) {
ffecfa5a 145 return false;
6afc1b46 146 }
ffecfa5a 147
6afc1b46 148 FrmSetEventHandler((FormType *)FrameForm, FrameFormHandleEvent);
e9c52a40 149
20bc5ad8 150 FrmSetActiveForm((FormType *)FrameForm);
e9c52a40 151
db101bd3 152 ActiveParentFrame=this;
e9c52a40 153
ffecfa5a
JS
154 return true;
155}
156
157wxTopLevelWindowPalm::~wxTopLevelWindowPalm()
158{
159}
160
324eeecb
WS
161// ---------------------------------------------------------------------------
162// implementation
163// ---------------------------------------------------------------------------
164
165WXWINHANDLE wxTopLevelWindowPalm::GetWinHandle() const
166{
20bc5ad8 167 FormType *form = (FormType *)GetForm();
324eeecb
WS
168 if(form)
169 return FrmGetWindowHandle(form);
20bc5ad8 170 return NULL;
324eeecb
WS
171}
172
ffecfa5a
JS
173// ----------------------------------------------------------------------------
174// wxTopLevelWindowPalm showing
175// ----------------------------------------------------------------------------
176
177void wxTopLevelWindowPalm::DoShowWindow(int nShowCmd)
178{
179}
180
181bool wxTopLevelWindowPalm::Show(bool show)
182{
e2fc40b4 183 if (true != show) {
6afc1b46 184 return true;
e2fc40b4 185 }
20bc5ad8 186 FrmDrawForm((FormType *)FrameForm);
e9c52a40 187
ffecfa5a
JS
188 wxPaintEvent event(m_windowId);
189 event.SetEventObject(this);
937013e0 190 HandleWindowEvent(event);
e9c52a40 191
ffecfa5a
JS
192 return true;
193}
194
195// ----------------------------------------------------------------------------
196// wxTopLevelWindowPalm maximize/minimize
197// ----------------------------------------------------------------------------
198
199void wxTopLevelWindowPalm::Maximize(bool maximize)
200{
201}
202
203bool wxTopLevelWindowPalm::IsMaximized() const
204{
205 return false;
206}
207
208void wxTopLevelWindowPalm::Iconize(bool iconize)
209{
210}
211
212bool wxTopLevelWindowPalm::IsIconized() const
213{
214 return false;
215}
216
217void wxTopLevelWindowPalm::Restore()
218{
219}
220
808e3bce
WS
221void wxTopLevelWindowPalm::DoGetSize( int *width, int *height ) const
222{
223 RectangleType rect;
20bc5ad8 224 FrmGetFormBounds( (FormType *)GetForm() , &rect );
808e3bce
WS
225 if(width)
226 *width = rect.extent.x;
227 if(height)
228 *height = rect.extent.y;
229}
230
ffecfa5a
JS
231// ----------------------------------------------------------------------------
232// wxTopLevelWindowPalm fullscreen
233// ----------------------------------------------------------------------------
234
235bool wxTopLevelWindowPalm::ShowFullScreen(bool show, long style)
236{
237 return false;
238}
239
240// ----------------------------------------------------------------------------
241// wxTopLevelWindowPalm misc
242// ----------------------------------------------------------------------------
243
0ab48d64
WS
244void wxTopLevelWindowPalm::SetTitle( const wxString& WXUNUSED(title))
245{
246}
247
248wxString wxTopLevelWindowPalm::GetTitle() const
249{
250 return wxEmptyString;
251}
252
ffecfa5a
JS
253void wxTopLevelWindowPalm::SetIcons(const wxIconBundle& icons)
254{
255}
256
257bool wxTopLevelWindowPalm::EnableCloseButton(bool enable)
258{
259 return false;
260}
261
20bc5ad8 262WXFORMPTR wxTopLevelWindowPalm::GetForm() const
bdb54365 263{
808e3bce 264 return FrmGetActiveForm();
bdb54365
WS
265}
266
ffecfa5a
JS
267bool wxTopLevelWindowPalm::SetShape(const wxRegion& region)
268{
269 return false;
270}
271
ffecfa5a 272// ----------------------------------------------------------------------------
721a9626 273// wxTopLevelWindow native event handling
ffecfa5a
JS
274// ----------------------------------------------------------------------------
275
20bc5ad8 276bool wxTopLevelWindowPalm::HandleControlSelect(WXEVENTPTR event)
a152561c 277{
20bc5ad8
WS
278 const EventType *palmEvent = (EventType *)event;
279 const int id = palmEvent->data.ctlSelect.controlID;
721a9626 280
a152561c
WS
281 wxWindow* win = FindWindowById(id,this);
282 if(win==NULL)
283 return false;
284
6a27c749 285#if wxUSE_BUTTON
a152561c
WS
286 wxButton* button = wxDynamicCast(win,wxButton);
287 if(button)
288 return button->SendClickEvent();
6a27c749 289#endif // wxUSE_BUTTON
a152561c 290
6a27c749 291#if wxUSE_CHECKBOX
a152561c
WS
292 wxCheckBox* checkbox = wxDynamicCast(win,wxCheckBox);
293 if(checkbox)
294 return checkbox->SendClickEvent();
6a27c749 295#endif // wxUSE_CHECKBOX
a152561c 296
6a27c749 297#if wxUSE_TOGGLEBTN
a152561c
WS
298 wxToggleButton* toggle = wxDynamicCast(win,wxToggleButton);
299 if(toggle)
300 return toggle->SendClickEvent();
6a27c749 301#endif // wxUSE_TOGGLEBTN
a152561c 302
6a27c749 303#if wxUSE_RADIOBTN
a152561c
WS
304 wxRadioButton* radio = wxDynamicCast(win,wxRadioButton);
305 if(radio)
306 return radio->SendClickEvent();
6a27c749 307#endif // wxUSE_RADIOBTN
a152561c 308
6a27c749
WS
309#if wxUSE_DATEPICKCTRL
310 wxDatePickerCtrl* datepicker = wxDynamicCast(win,wxDatePickerCtrl);
311 if(datepicker)
312 return datepicker->SendClickEvent();
313#endif // wxUSE_DATEPICKCTRL
314
315#if wxUSE_SLIDER
9a727a3b
WS
316 wxSlider* slider = wxDynamicCast(win,wxSlider);
317 if(slider)
318 return slider->SendUpdatedEvent();
6a27c749 319#endif // wxUSE_SLIDER
9a727a3b 320
a152561c
WS
321 return false;
322}
323
20bc5ad8 324bool wxTopLevelWindowPalm::HandleControlRepeat(WXEVENTPTR event)
721a9626 325{
20bc5ad8
WS
326 const EventType *palmEvent = (EventType *)event;
327 const int id = palmEvent->data.ctlRepeat.controlID;
721a9626 328
20bc5ad8 329 wxWindow* win = FindWindowById(id, this);
721a9626
WS
330 if(win==NULL)
331 return false;
332
6a27c749 333#if wxUSE_SLIDER
721a9626
WS
334 wxSlider* slider = wxDynamicCast(win,wxSlider);
335 if(slider)
336 return slider->SendScrollEvent(event);
6a27c749 337#endif // wxUSE_SLIDER
721a9626
WS
338
339 return false;
340}
341
20bc5ad8 342bool wxTopLevelWindowPalm::HandleSize(WXEVENTPTR event)
721a9626 343{
6afc1b46 344#ifdef __WXPALMOS6__
20bc5ad8
WS
345 const EventType *palmEvent = (EventType *)event;
346 wxSize newSize(palmEvent->data.winResized.newBounds.extent.x,
347 palmEvent->data.winResized.newBounds.extent.y);
721a9626
WS
348 wxSizeEvent eventWx(newSize,GetId());
349 eventWx.SetEventObject(this);
937013e0 350 return HandleWindowEvent(eventWx);
6afc1b46
VZ
351#else // __WXPALMOS5__
352 return false;
353#endif
354
721a9626
WS
355}
356
ffecfa5a
JS
357void wxTopLevelWindowPalm::OnActivate(wxActivateEvent& event)
358{
359}
360
361/* Palm OS Event handler for the window
e9c52a40
WS
362 *
363 * This function *must* be located outside of the wxTopLevelWindow class because
e2731512
WS
364 * the Palm OS API expects a standalone C function as a callback. You cannot
365 * pass a pointer to a member function of a C++ class as a callback because the
366 * prototypes don't match. (A member function has a hidden "this" pointer as
ffecfa5a 367 * its first parameter).
e2731512
WS
368 *
369 * This event handler uses a global pointer to the current wxFrame to process
370 * the events generated by the Palm OS form API. I know this is ugly, but right
371 * now I can't think of any other way to deal with this problem. If someone
372 * finds a better solution, please let me know. My email address is
ffecfa5a
JS
373 * wbo@freeshell.org
374 */
20bc5ad8 375static Boolean FrameFormHandleEvent(EventType *event)
ffecfa5a 376{
721a9626
WS
377 // frame and tlw point to the same object but they are for convenience
378 // of calling proper structure withiout later dynamic typcasting
379 wxFrame* frame = wxDynamicCast(ActiveParentFrame,wxFrame);
380 wxTopLevelWindowPalm* tlw = ActiveParentFrame;
a152561c 381 Boolean handled = false;
e2731512 382
a152561c 383 switch (event->eType) {
ffecfa5a 384 case ctlSelectEvent:
721a9626
WS
385 handled = tlw->HandleControlSelect(event);
386 break;
387 case ctlRepeatEvent:
388 handled = tlw->HandleControlRepeat(event);
389 break;
6afc1b46 390#ifdef __WXPALMOS6__
721a9626
WS
391 case winResizedEvent:
392 handled = tlw->HandleSize(event);
ffecfa5a 393 break;
6afc1b46 394#endif // __WXPALMOS6__
ffecfa5a
JS
395#if wxUSE_MENUS_NATIVE
396 case menuOpenEvent:
a152561c 397 handled = frame->HandleMenuOpen();
e2731512 398 break;
ffecfa5a 399 case menuEvent:
a152561c 400 handled = frame->HandleMenuSelect(event);
ffecfa5a
JS
401 break;
402#endif
403 default:
404 break;
405 }
e2731512 406
a152561c 407 return handled;
ffecfa5a 408}