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