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)
98 ActiveParentFrame
=NULL
;
100 wxTopLevelWindows
.Append(this);
103 parent
->AddChild(this);
105 SetId( id
== wxID_ANY
? NewControlId() : id
);
107 WinConstraintsType constraints
;
108 memset(&constraints
, 0, sizeof(WinConstraintsType
));
110 constraints
.x_pos
= ( pos
.x
== wxDefaultCoord
) ? winUndefConstraint
: pos
.x
;
111 constraints
.y_pos
= ( pos
.y
== wxDefaultCoord
) ? winUndefConstraint
: pos
.y
;
113 constraints
.x_min
= winUndefConstraint
;
114 constraints
.x_max
= winMaxConstraint
;
115 constraints
.x_pref
= ( size
.x
== wxDefaultCoord
) ? winUndefConstraint
: size
.x
;
116 constraints
.y_min
= winUndefConstraint
;
117 constraints
.y_max
= winMaxConstraint
;
118 constraints
.y_pref
= ( size
.y
== wxDefaultCoord
) ? winUndefConstraint
: size
.y
;
120 FrameForm
= FrmNewFormWithConstraints(
135 FrmSetEventHandler((FormType
*)FrameForm
,FrameFormHandleEvent
);
137 FrmSetActiveForm((FormType
*)FrameForm
);
139 ActiveParentFrame
=this;
144 wxTopLevelWindowPalm::~wxTopLevelWindowPalm()
148 // ---------------------------------------------------------------------------
150 // ---------------------------------------------------------------------------
152 WXWINHANDLE
wxTopLevelWindowPalm::GetWinHandle() const
154 FormType
*form
= (FormType
*)GetForm();
156 return FrmGetWindowHandle(form
);
160 // ----------------------------------------------------------------------------
161 // wxTopLevelWindowPalm showing
162 // ----------------------------------------------------------------------------
164 void wxTopLevelWindowPalm::DoShowWindow(int nShowCmd
)
168 bool wxTopLevelWindowPalm::Show(bool show
)
173 FrmDrawForm((FormType
*)FrameForm
);
175 wxPaintEvent
event(m_windowId
);
176 event
.SetEventObject(this);
177 HandleWindowEvent(event
);
182 // ----------------------------------------------------------------------------
183 // wxTopLevelWindowPalm maximize/minimize
184 // ----------------------------------------------------------------------------
186 void wxTopLevelWindowPalm::Maximize(bool maximize
)
190 bool wxTopLevelWindowPalm::IsMaximized() const
195 void wxTopLevelWindowPalm::Iconize(bool iconize
)
199 bool wxTopLevelWindowPalm::IsIconized() const
204 void wxTopLevelWindowPalm::Restore()
208 void wxTopLevelWindowPalm::DoGetSize( int *width
, int *height
) const
211 FrmGetFormBounds( (FormType
*)GetForm() , &rect
);
213 *width
= rect
.extent
.x
;
215 *height
= rect
.extent
.y
;
218 // ----------------------------------------------------------------------------
219 // wxTopLevelWindowPalm fullscreen
220 // ----------------------------------------------------------------------------
222 bool wxTopLevelWindowPalm::ShowFullScreen(bool show
, long style
)
227 // ----------------------------------------------------------------------------
228 // wxTopLevelWindowPalm misc
229 // ----------------------------------------------------------------------------
231 void wxTopLevelWindowPalm::SetTitle( const wxString
& WXUNUSED(title
))
235 wxString
wxTopLevelWindowPalm::GetTitle() const
237 return wxEmptyString
;
240 void wxTopLevelWindowPalm::SetIcons(const wxIconBundle
& icons
)
244 bool wxTopLevelWindowPalm::EnableCloseButton(bool enable
)
249 WXFORMPTR
wxTopLevelWindowPalm::GetForm() const
251 return FrmGetActiveForm();
254 bool wxTopLevelWindowPalm::SetShape(const wxRegion
& region
)
259 // ----------------------------------------------------------------------------
260 // wxTopLevelWindow native event handling
261 // ----------------------------------------------------------------------------
263 bool wxTopLevelWindowPalm::HandleControlSelect(WXEVENTPTR event
)
265 const EventType
*palmEvent
= (EventType
*)event
;
266 const int id
= palmEvent
->data
.ctlSelect
.controlID
;
268 wxWindow
* win
= FindWindowById(id
,this);
273 wxButton
* button
= wxDynamicCast(win
,wxButton
);
275 return button
->SendClickEvent();
276 #endif // wxUSE_BUTTON
279 wxCheckBox
* checkbox
= wxDynamicCast(win
,wxCheckBox
);
281 return checkbox
->SendClickEvent();
282 #endif // wxUSE_CHECKBOX
285 wxToggleButton
* toggle
= wxDynamicCast(win
,wxToggleButton
);
287 return toggle
->SendClickEvent();
288 #endif // wxUSE_TOGGLEBTN
291 wxRadioButton
* radio
= wxDynamicCast(win
,wxRadioButton
);
293 return radio
->SendClickEvent();
294 #endif // wxUSE_RADIOBTN
296 #if wxUSE_DATEPICKCTRL
297 wxDatePickerCtrl
* datepicker
= wxDynamicCast(win
,wxDatePickerCtrl
);
299 return datepicker
->SendClickEvent();
300 #endif // wxUSE_DATEPICKCTRL
303 wxSlider
* slider
= wxDynamicCast(win
,wxSlider
);
305 return slider
->SendUpdatedEvent();
306 #endif // wxUSE_SLIDER
311 bool wxTopLevelWindowPalm::HandleControlRepeat(WXEVENTPTR event
)
313 const EventType
*palmEvent
= (EventType
*)event
;
314 const int id
= palmEvent
->data
.ctlRepeat
.controlID
;
316 wxWindow
* win
= FindWindowById(id
, this);
321 wxSlider
* slider
= wxDynamicCast(win
,wxSlider
);
323 return slider
->SendScrollEvent(event
);
324 #endif // wxUSE_SLIDER
329 bool wxTopLevelWindowPalm::HandleSize(WXEVENTPTR event
)
331 const EventType
*palmEvent
= (EventType
*)event
;
332 wxSize
newSize(palmEvent
->data
.winResized
.newBounds
.extent
.x
,
333 palmEvent
->data
.winResized
.newBounds
.extent
.y
);
334 wxSizeEvent
eventWx(newSize
,GetId());
335 eventWx
.SetEventObject(this);
336 return HandleWindowEvent(eventWx
);
339 void wxTopLevelWindowPalm::OnActivate(wxActivateEvent
& event
)
343 /* Palm OS Event handler for the window
345 * This function *must* be located outside of the wxTopLevelWindow class because
346 * the Palm OS API expects a standalone C function as a callback. You cannot
347 * pass a pointer to a member function of a C++ class as a callback because the
348 * prototypes don't match. (A member function has a hidden "this" pointer as
349 * its first parameter).
351 * This event handler uses a global pointer to the current wxFrame to process
352 * the events generated by the Palm OS form API. I know this is ugly, but right
353 * now I can't think of any other way to deal with this problem. If someone
354 * finds a better solution, please let me know. My email address is
357 static Boolean
FrameFormHandleEvent(EventType
*event
)
359 // frame and tlw point to the same object but they are for convenience
360 // of calling proper structure withiout later dynamic typcasting
361 wxFrame
* frame
= wxDynamicCast(ActiveParentFrame
,wxFrame
);
362 wxTopLevelWindowPalm
* tlw
= ActiveParentFrame
;
363 Boolean handled
= false;
365 switch (event
->eType
) {
367 handled
= tlw
->HandleControlSelect(event
);
370 handled
= tlw
->HandleControlRepeat(event
);
372 case winResizedEvent
:
373 handled
= tlw
->HandleSize(event
);
375 #if wxUSE_MENUS_NATIVE
377 handled
= frame
->HandleMenuOpen();
380 handled
= frame
->HandleMenuSelect(event
);