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