]>
Commit | Line | Data |
---|---|---|
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 | // For compilers that support precompilation, includes "wx.h". | |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
27 | #include "wx/toplevel.h" | |
28 | ||
29 | #ifndef WX_PRECOMP | |
30 | #include "wx/app.h" | |
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() | |
37 | #include "wx/button.h" | |
38 | #include "wx/checkbox.h" | |
39 | #include "wx/radiobut.h" | |
40 | #include "wx/slider.h" | |
41 | #include "wx/module.h" | |
42 | #endif //WX_PRECOMP | |
43 | ||
44 | #include "wx/display.h" | |
45 | ||
46 | // controls for sending select event | |
47 | #include "wx/tglbtn.h" | |
48 | #include "wx/datectrl.h" | |
49 | ||
50 | #include <Window.h> | |
51 | #include <Form.h> | |
52 | ||
53 | // ---------------------------------------------------------------------------- | |
54 | // globals | |
55 | // ---------------------------------------------------------------------------- | |
56 | ||
57 | // the name of the default wxWidgets class | |
58 | extern const wxChar *wxCanvasClassName; | |
59 | ||
60 | // Pointer to the currently active frame for the form event handler. | |
61 | wxTopLevelWindowPalm* ActiveParentFrame; | |
62 | ||
63 | static Boolean FrameFormHandleEvent(EventType *event); | |
64 | ||
65 | // ============================================================================ | |
66 | // wxTopLevelWindowPalm implementation | |
67 | // ============================================================================ | |
68 | ||
69 | BEGIN_EVENT_TABLE(wxTopLevelWindowPalm, wxTopLevelWindowBase) | |
70 | EVT_ACTIVATE(wxTopLevelWindowPalm::OnActivate) | |
71 | END_EVENT_TABLE() | |
72 | ||
73 | // ---------------------------------------------------------------------------- | |
74 | // wxTopLevelWindowPalm creation | |
75 | // ---------------------------------------------------------------------------- | |
76 | ||
77 | void wxTopLevelWindowPalm::Init() | |
78 | { | |
79 | } | |
80 | ||
81 | WXDWORD wxTopLevelWindowPalm::PalmGetStyle(long style, WXDWORD *exflags) const | |
82 | { | |
83 | return 0; | |
84 | } | |
85 | ||
86 | bool wxTopLevelWindowPalm::Create(wxWindow *parent, | |
87 | wxWindowID id, | |
88 | const wxString& title, | |
89 | const wxPoint& pos, | |
90 | const wxSize& size, | |
91 | long style, | |
92 | const wxString& name) | |
93 | { | |
94 | // this is a check for limitation mentioned before FrameFormHandleEvent() code | |
95 | if(wxTopLevelWindows.GetCount() > 0) { | |
96 | return false; | |
97 | } | |
98 | ||
99 | ActiveParentFrame=NULL; | |
100 | ||
101 | wxTopLevelWindows.Append(this); | |
102 | ||
103 | if ( parent ) { | |
104 | parent->AddChild(this); | |
105 | } | |
106 | ||
107 | SetId( id == wxID_ANY ? NewControlId() : id ); | |
108 | ||
109 | #ifdef __WXPALMOS6__ | |
110 | WinConstraintsType constraints; | |
111 | memset(&constraints, 0, sizeof(WinConstraintsType)); | |
112 | // position | |
113 | constraints.x_pos = ( pos.x == wxDefaultCoord ) ? winUndefConstraint : pos.x; | |
114 | constraints.y_pos = ( pos.y == wxDefaultCoord ) ? winUndefConstraint : pos.y; | |
115 | // size | |
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; | |
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 | #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) { | |
145 | return false; | |
146 | } | |
147 | ||
148 | FrmSetEventHandler((FormType *)FrameForm, FrameFormHandleEvent); | |
149 | ||
150 | FrmSetActiveForm((FormType *)FrameForm); | |
151 | ||
152 | ActiveParentFrame=this; | |
153 | ||
154 | return true; | |
155 | } | |
156 | ||
157 | wxTopLevelWindowPalm::~wxTopLevelWindowPalm() | |
158 | { | |
159 | } | |
160 | ||
161 | // --------------------------------------------------------------------------- | |
162 | // implementation | |
163 | // --------------------------------------------------------------------------- | |
164 | ||
165 | WXWINHANDLE wxTopLevelWindowPalm::GetWinHandle() const | |
166 | { | |
167 | FormType *form = (FormType *)GetForm(); | |
168 | if(form) | |
169 | return FrmGetWindowHandle(form); | |
170 | return NULL; | |
171 | } | |
172 | ||
173 | // ---------------------------------------------------------------------------- | |
174 | // wxTopLevelWindowPalm showing | |
175 | // ---------------------------------------------------------------------------- | |
176 | ||
177 | void wxTopLevelWindowPalm::DoShowWindow(int nShowCmd) | |
178 | { | |
179 | } | |
180 | ||
181 | bool wxTopLevelWindowPalm::Show(bool show) | |
182 | { | |
183 | if (true != show) { | |
184 | return true; | |
185 | } | |
186 | FrmDrawForm((FormType *)FrameForm); | |
187 | ||
188 | wxPaintEvent event(m_windowId); | |
189 | event.SetEventObject(this); | |
190 | HandleWindowEvent(event); | |
191 | ||
192 | return true; | |
193 | } | |
194 | ||
195 | // ---------------------------------------------------------------------------- | |
196 | // wxTopLevelWindowPalm maximize/minimize | |
197 | // ---------------------------------------------------------------------------- | |
198 | ||
199 | void wxTopLevelWindowPalm::Maximize(bool maximize) | |
200 | { | |
201 | } | |
202 | ||
203 | bool wxTopLevelWindowPalm::IsMaximized() const | |
204 | { | |
205 | return false; | |
206 | } | |
207 | ||
208 | void wxTopLevelWindowPalm::Iconize(bool iconize) | |
209 | { | |
210 | } | |
211 | ||
212 | bool wxTopLevelWindowPalm::IsIconized() const | |
213 | { | |
214 | return false; | |
215 | } | |
216 | ||
217 | void wxTopLevelWindowPalm::Restore() | |
218 | { | |
219 | } | |
220 | ||
221 | void wxTopLevelWindowPalm::DoGetSize( int *width, int *height ) const | |
222 | { | |
223 | RectangleType rect; | |
224 | FrmGetFormBounds( (FormType *)GetForm() , &rect ); | |
225 | if(width) | |
226 | *width = rect.extent.x; | |
227 | if(height) | |
228 | *height = rect.extent.y; | |
229 | } | |
230 | ||
231 | // ---------------------------------------------------------------------------- | |
232 | // wxTopLevelWindowPalm fullscreen | |
233 | // ---------------------------------------------------------------------------- | |
234 | ||
235 | bool wxTopLevelWindowPalm::ShowFullScreen(bool show, long style) | |
236 | { | |
237 | return false; | |
238 | } | |
239 | ||
240 | // ---------------------------------------------------------------------------- | |
241 | // wxTopLevelWindowPalm misc | |
242 | // ---------------------------------------------------------------------------- | |
243 | ||
244 | void wxTopLevelWindowPalm::SetTitle( const wxString& WXUNUSED(title)) | |
245 | { | |
246 | } | |
247 | ||
248 | wxString wxTopLevelWindowPalm::GetTitle() const | |
249 | { | |
250 | return wxEmptyString; | |
251 | } | |
252 | ||
253 | void wxTopLevelWindowPalm::SetIcons(const wxIconBundle& icons) | |
254 | { | |
255 | } | |
256 | ||
257 | bool wxTopLevelWindowPalm::EnableCloseButton(bool enable) | |
258 | { | |
259 | return false; | |
260 | } | |
261 | ||
262 | WXFORMPTR wxTopLevelWindowPalm::GetForm() const | |
263 | { | |
264 | return FrmGetActiveForm(); | |
265 | } | |
266 | ||
267 | bool wxTopLevelWindowPalm::SetShape(const wxRegion& region) | |
268 | { | |
269 | return false; | |
270 | } | |
271 | ||
272 | // ---------------------------------------------------------------------------- | |
273 | // wxTopLevelWindow native event handling | |
274 | // ---------------------------------------------------------------------------- | |
275 | ||
276 | bool wxTopLevelWindowPalm::HandleControlSelect(WXEVENTPTR event) | |
277 | { | |
278 | const EventType *palmEvent = (EventType *)event; | |
279 | const int id = palmEvent->data.ctlSelect.controlID; | |
280 | ||
281 | wxWindow* win = FindWindowById(id,this); | |
282 | if(win==NULL) | |
283 | return false; | |
284 | ||
285 | #if wxUSE_BUTTON | |
286 | wxButton* button = wxDynamicCast(win,wxButton); | |
287 | if(button) | |
288 | return button->SendClickEvent(); | |
289 | #endif // wxUSE_BUTTON | |
290 | ||
291 | #if wxUSE_CHECKBOX | |
292 | wxCheckBox* checkbox = wxDynamicCast(win,wxCheckBox); | |
293 | if(checkbox) | |
294 | return checkbox->SendClickEvent(); | |
295 | #endif // wxUSE_CHECKBOX | |
296 | ||
297 | #if wxUSE_TOGGLEBTN | |
298 | wxToggleButton* toggle = wxDynamicCast(win,wxToggleButton); | |
299 | if(toggle) | |
300 | return toggle->SendClickEvent(); | |
301 | #endif // wxUSE_TOGGLEBTN | |
302 | ||
303 | #if wxUSE_RADIOBTN | |
304 | wxRadioButton* radio = wxDynamicCast(win,wxRadioButton); | |
305 | if(radio) | |
306 | return radio->SendClickEvent(); | |
307 | #endif // wxUSE_RADIOBTN | |
308 | ||
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 | |
316 | wxSlider* slider = wxDynamicCast(win,wxSlider); | |
317 | if(slider) | |
318 | return slider->SendUpdatedEvent(); | |
319 | #endif // wxUSE_SLIDER | |
320 | ||
321 | return false; | |
322 | } | |
323 | ||
324 | bool wxTopLevelWindowPalm::HandleControlRepeat(WXEVENTPTR event) | |
325 | { | |
326 | const EventType *palmEvent = (EventType *)event; | |
327 | const int id = palmEvent->data.ctlRepeat.controlID; | |
328 | ||
329 | wxWindow* win = FindWindowById(id, this); | |
330 | if(win==NULL) | |
331 | return false; | |
332 | ||
333 | #if wxUSE_SLIDER | |
334 | wxSlider* slider = wxDynamicCast(win,wxSlider); | |
335 | if(slider) | |
336 | return slider->SendScrollEvent(event); | |
337 | #endif // wxUSE_SLIDER | |
338 | ||
339 | return false; | |
340 | } | |
341 | ||
342 | bool wxTopLevelWindowPalm::HandleSize(WXEVENTPTR event) | |
343 | { | |
344 | #ifdef __WXPALMOS6__ | |
345 | const EventType *palmEvent = (EventType *)event; | |
346 | wxSize newSize(palmEvent->data.winResized.newBounds.extent.x, | |
347 | palmEvent->data.winResized.newBounds.extent.y); | |
348 | wxSizeEvent eventWx(newSize,GetId()); | |
349 | eventWx.SetEventObject(this); | |
350 | return HandleWindowEvent(eventWx); | |
351 | #else // __WXPALMOS5__ | |
352 | return false; | |
353 | #endif | |
354 | ||
355 | } | |
356 | ||
357 | void wxTopLevelWindowPalm::OnActivate(wxActivateEvent& event) | |
358 | { | |
359 | } | |
360 | ||
361 | /* Palm OS Event handler for the window | |
362 | * | |
363 | * This function *must* be located outside of the wxTopLevelWindow class because | |
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 | |
367 | * its first parameter). | |
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 | |
373 | * wbo@freeshell.org | |
374 | */ | |
375 | static Boolean FrameFormHandleEvent(EventType *event) | |
376 | { | |
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; | |
381 | Boolean handled = false; | |
382 | ||
383 | switch (event->eType) { | |
384 | case ctlSelectEvent: | |
385 | handled = tlw->HandleControlSelect(event); | |
386 | break; | |
387 | case ctlRepeatEvent: | |
388 | handled = tlw->HandleControlRepeat(event); | |
389 | break; | |
390 | #ifdef __WXPALMOS6__ | |
391 | case winResizedEvent: | |
392 | handled = tlw->HandleSize(event); | |
393 | break; | |
394 | #endif // __WXPALMOS6__ | |
395 | #if wxUSE_MENUS_NATIVE | |
396 | case menuOpenEvent: | |
397 | handled = frame->HandleMenuOpen(); | |
398 | break; | |
399 | case menuEvent: | |
400 | handled = frame->HandleMenuSelect(event); | |
401 | break; | |
402 | #endif | |
403 | default: | |
404 | break; | |
405 | } | |
406 | ||
407 | return handled; | |
408 | } |