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
8 // Copyright: (c) William Osborne <wbo@freeshell.org>, Wlodzimierz Skiba
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/toplevel.h"
31 #include "wx/dialog.h"
32 #include "wx/string.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"
44 #include "wx/display.h"
46 // controls for sending select event
47 #include "wx/tglbtn.h"
48 #include "wx/datectrl.h"
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
57 // the name of the default wxWidgets class
58 extern const wxChar
*wxCanvasClassName
;
60 // Pointer to the currently active frame for the form event handler.
61 wxTopLevelWindowPalm
* ActiveParentFrame
;
63 static Boolean
FrameFormHandleEvent(EventType
*event
);
65 // ============================================================================
66 // wxTopLevelWindowPalm implementation
67 // ============================================================================
69 BEGIN_EVENT_TABLE(wxTopLevelWindowPalm
, wxTopLevelWindowBase
)
70 EVT_ACTIVATE(wxTopLevelWindowPalm::OnActivate
)
73 // ----------------------------------------------------------------------------
74 // wxTopLevelWindowPalm creation
75 // ----------------------------------------------------------------------------
77 void wxTopLevelWindowPalm::Init()
81 WXDWORD
wxTopLevelWindowPalm::PalmGetStyle(long style
, WXDWORD
*exflags
) const
86 bool wxTopLevelWindowPalm::Create(wxWindow
*parent
,
88 const wxString
& title
,
94 // this is a check for limitation mentioned before FrameFormHandleEvent() code
95 if(wxTopLevelWindows
.GetCount() > 0) {
99 ActiveParentFrame
=NULL
;
101 wxTopLevelWindows
.Append(this);
104 parent
->AddChild(this);
107 SetId( id
== wxID_ANY
? NewControlId() : id
);
110 WinConstraintsType constraints
;
111 memset(&constraints
, 0, sizeof(WinConstraintsType
));
113 constraints
.x_pos
= ( pos
.x
== wxDefaultCoord
) ? winUndefConstraint
: pos
.x
;
114 constraints
.y_pos
= ( pos
.y
== wxDefaultCoord
) ? winUndefConstraint
: pos
.y
;
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(
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
,
144 if(NULL
== FrameForm
) {
148 FrmSetEventHandler((FormType
*)FrameForm
, FrameFormHandleEvent
);
150 FrmSetActiveForm((FormType
*)FrameForm
);
152 ActiveParentFrame
=this;
157 wxTopLevelWindowPalm::~wxTopLevelWindowPalm()
161 // ---------------------------------------------------------------------------
163 // ---------------------------------------------------------------------------
165 WXWINHANDLE
wxTopLevelWindowPalm::GetWinHandle() const
167 FormType
*form
= (FormType
*)GetForm();
169 return FrmGetWindowHandle(form
);
173 // ----------------------------------------------------------------------------
174 // wxTopLevelWindowPalm showing
175 // ----------------------------------------------------------------------------
177 void wxTopLevelWindowPalm::DoShowWindow(int nShowCmd
)
181 bool wxTopLevelWindowPalm::Show(bool show
)
186 FrmDrawForm((FormType
*)FrameForm
);
188 wxPaintEvent
event(m_windowId
);
189 event
.SetEventObject(this);
190 HandleWindowEvent(event
);
195 // ----------------------------------------------------------------------------
196 // wxTopLevelWindowPalm maximize/minimize
197 // ----------------------------------------------------------------------------
199 void wxTopLevelWindowPalm::Maximize(bool maximize
)
203 bool wxTopLevelWindowPalm::IsMaximized() const
208 void wxTopLevelWindowPalm::Iconize(bool iconize
)
212 bool wxTopLevelWindowPalm::IsIconized() const
217 void wxTopLevelWindowPalm::Restore()
221 void wxTopLevelWindowPalm::DoGetSize( int *width
, int *height
) const
224 FrmGetFormBounds( (FormType
*)GetForm() , &rect
);
226 *width
= rect
.extent
.x
;
228 *height
= rect
.extent
.y
;
231 // ----------------------------------------------------------------------------
232 // wxTopLevelWindowPalm fullscreen
233 // ----------------------------------------------------------------------------
235 bool wxTopLevelWindowPalm::ShowFullScreen(bool show
, long style
)
240 // ----------------------------------------------------------------------------
241 // wxTopLevelWindowPalm misc
242 // ----------------------------------------------------------------------------
244 void wxTopLevelWindowPalm::SetTitle( const wxString
& WXUNUSED(title
))
248 wxString
wxTopLevelWindowPalm::GetTitle() const
250 return wxEmptyString
;
253 void wxTopLevelWindowPalm::SetIcons(const wxIconBundle
& icons
)
257 bool wxTopLevelWindowPalm::EnableCloseButton(bool enable
)
262 WXFORMPTR
wxTopLevelWindowPalm::GetForm() const
264 return FrmGetActiveForm();
267 bool wxTopLevelWindowPalm::SetShape(const wxRegion
& region
)
272 // ----------------------------------------------------------------------------
273 // wxTopLevelWindow native event handling
274 // ----------------------------------------------------------------------------
276 bool wxTopLevelWindowPalm::HandleControlSelect(WXEVENTPTR event
)
278 const EventType
*palmEvent
= (EventType
*)event
;
279 const int id
= palmEvent
->data
.ctlSelect
.controlID
;
281 wxWindow
* win
= FindWindowById(id
,this);
286 wxButton
* button
= wxDynamicCast(win
,wxButton
);
288 return button
->SendClickEvent();
289 #endif // wxUSE_BUTTON
292 wxCheckBox
* checkbox
= wxDynamicCast(win
,wxCheckBox
);
294 return checkbox
->SendClickEvent();
295 #endif // wxUSE_CHECKBOX
298 wxToggleButton
* toggle
= wxDynamicCast(win
,wxToggleButton
);
300 return toggle
->SendClickEvent();
301 #endif // wxUSE_TOGGLEBTN
304 wxRadioButton
* radio
= wxDynamicCast(win
,wxRadioButton
);
306 return radio
->SendClickEvent();
307 #endif // wxUSE_RADIOBTN
309 #if wxUSE_DATEPICKCTRL
310 wxDatePickerCtrl
* datepicker
= wxDynamicCast(win
,wxDatePickerCtrl
);
312 return datepicker
->SendClickEvent();
313 #endif // wxUSE_DATEPICKCTRL
316 wxSlider
* slider
= wxDynamicCast(win
,wxSlider
);
318 return slider
->SendUpdatedEvent();
319 #endif // wxUSE_SLIDER
324 bool wxTopLevelWindowPalm::HandleControlRepeat(WXEVENTPTR event
)
326 const EventType
*palmEvent
= (EventType
*)event
;
327 const int id
= palmEvent
->data
.ctlRepeat
.controlID
;
329 wxWindow
* win
= FindWindowById(id
, this);
334 wxSlider
* slider
= wxDynamicCast(win
,wxSlider
);
336 return slider
->SendScrollEvent(event
);
337 #endif // wxUSE_SLIDER
342 bool wxTopLevelWindowPalm::HandleSize(WXEVENTPTR event
)
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__
357 void wxTopLevelWindowPalm::OnActivate(wxActivateEvent
& event
)
361 /* Palm OS Event handler for the window
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).
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
375 static Boolean
FrameFormHandleEvent(EventType
*event
)
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;
383 switch (event
->eType
) {
385 handled
= tlw
->HandleControlSelect(event
);
388 handled
= tlw
->HandleControlRepeat(event
);
391 case winResizedEvent
:
392 handled
= tlw
->HandleSize(event
);
394 #endif // __WXPALMOS6__
395 #if wxUSE_MENUS_NATIVE
397 handled
= frame
->HandleMenuOpen();
400 handled
= frame
->HandleMenuSelect(event
);