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
)
170 FrmDrawForm((FormType
*)FrameForm
);
172 wxPaintEvent
event(m_windowId
);
173 event
.SetEventObject(this);
174 HandleWindowEvent(event
);
179 // ----------------------------------------------------------------------------
180 // wxTopLevelWindowPalm maximize/minimize
181 // ----------------------------------------------------------------------------
183 void wxTopLevelWindowPalm::Maximize(bool maximize
)
187 bool wxTopLevelWindowPalm::IsMaximized() const
192 void wxTopLevelWindowPalm::Iconize(bool iconize
)
196 bool wxTopLevelWindowPalm::IsIconized() const
201 void wxTopLevelWindowPalm::Restore()
205 void wxTopLevelWindowPalm::DoGetSize( int *width
, int *height
) const
208 FrmGetFormBounds( (FormType
*)GetForm() , &rect
);
210 *width
= rect
.extent
.x
;
212 *height
= rect
.extent
.y
;
215 // ----------------------------------------------------------------------------
216 // wxTopLevelWindowPalm fullscreen
217 // ----------------------------------------------------------------------------
219 bool wxTopLevelWindowPalm::ShowFullScreen(bool show
, long style
)
224 // ----------------------------------------------------------------------------
225 // wxTopLevelWindowPalm misc
226 // ----------------------------------------------------------------------------
228 void wxTopLevelWindowPalm::SetTitle( const wxString
& WXUNUSED(title
))
232 wxString
wxTopLevelWindowPalm::GetTitle() const
234 return wxEmptyString
;
237 void wxTopLevelWindowPalm::SetIcons(const wxIconBundle
& icons
)
241 bool wxTopLevelWindowPalm::EnableCloseButton(bool enable
)
246 WXFORMPTR
wxTopLevelWindowPalm::GetForm() const
248 return FrmGetActiveForm();
251 bool wxTopLevelWindowPalm::SetShape(const wxRegion
& region
)
256 // ----------------------------------------------------------------------------
257 // wxTopLevelWindow native event handling
258 // ----------------------------------------------------------------------------
260 bool wxTopLevelWindowPalm::HandleControlSelect(WXEVENTPTR event
)
262 const EventType
*palmEvent
= (EventType
*)event
;
263 const int id
= palmEvent
->data
.ctlSelect
.controlID
;
265 wxWindow
* win
= FindWindowById(id
,this);
270 wxButton
* button
= wxDynamicCast(win
,wxButton
);
272 return button
->SendClickEvent();
273 #endif // wxUSE_BUTTON
276 wxCheckBox
* checkbox
= wxDynamicCast(win
,wxCheckBox
);
278 return checkbox
->SendClickEvent();
279 #endif // wxUSE_CHECKBOX
282 wxToggleButton
* toggle
= wxDynamicCast(win
,wxToggleButton
);
284 return toggle
->SendClickEvent();
285 #endif // wxUSE_TOGGLEBTN
288 wxRadioButton
* radio
= wxDynamicCast(win
,wxRadioButton
);
290 return radio
->SendClickEvent();
291 #endif // wxUSE_RADIOBTN
293 #if wxUSE_DATEPICKCTRL
294 wxDatePickerCtrl
* datepicker
= wxDynamicCast(win
,wxDatePickerCtrl
);
296 return datepicker
->SendClickEvent();
297 #endif // wxUSE_DATEPICKCTRL
300 wxSlider
* slider
= wxDynamicCast(win
,wxSlider
);
302 return slider
->SendUpdatedEvent();
303 #endif // wxUSE_SLIDER
308 bool wxTopLevelWindowPalm::HandleControlRepeat(WXEVENTPTR event
)
310 const EventType
*palmEvent
= (EventType
*)event
;
311 const int id
= palmEvent
->data
.ctlRepeat
.controlID
;
313 wxWindow
* win
= FindWindowById(id
, this);
318 wxSlider
* slider
= wxDynamicCast(win
,wxSlider
);
320 return slider
->SendScrollEvent(event
);
321 #endif // wxUSE_SLIDER
326 bool wxTopLevelWindowPalm::HandleSize(WXEVENTPTR event
)
328 const EventType
*palmEvent
= (EventType
*)event
;
329 wxSize
newSize(palmEvent
->data
.winResized
.newBounds
.extent
.x
,
330 palmEvent
->data
.winResized
.newBounds
.extent
.y
);
331 wxSizeEvent
eventWx(newSize
,GetId());
332 eventWx
.SetEventObject(this);
333 return HandleWindowEvent(eventWx
);
336 void wxTopLevelWindowPalm::OnActivate(wxActivateEvent
& event
)
340 /* Palm OS Event handler for the window
342 * This function *must* be located outside of the wxTopLevelWindow class because
343 * the Palm OS API expects a standalone C function as a callback. You cannot
344 * pass a pointer to a member function of a C++ class as a callback because the
345 * prototypes don't match. (A member function has a hidden "this" pointer as
346 * its first parameter).
348 * This event handler uses a global pointer to the current wxFrame to process
349 * the events generated by the Palm OS form API. I know this is ugly, but right
350 * now I can't think of any other way to deal with this problem. If someone
351 * finds a better solution, please let me know. My email address is
354 static Boolean
FrameFormHandleEvent(EventType
*event
)
356 // frame and tlw point to the same object but they are for convenience
357 // of calling proper structure withiout later dynamic typcasting
358 wxFrame
* frame
= wxDynamicCast(ActiveParentFrame
,wxFrame
);
359 wxTopLevelWindowPalm
* tlw
= ActiveParentFrame
;
360 Boolean handled
= false;
362 switch (event
->eType
) {
364 handled
= tlw
->HandleControlSelect(event
);
367 handled
= tlw
->HandleControlRepeat(event
);
369 case winResizedEvent
:
370 handled
= tlw
->HandleSize(event
);
372 #if wxUSE_MENUS_NATIVE
374 handled
= frame
->HandleMenuOpen();
377 handled
= frame
->HandleMenuSelect(event
);