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