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"
29 #include "wx/toplevel.h"
30 #include "wx/dialog.h"
31 #include "wx/string.h"
35 #include "wx/containr.h" // wxSetFocusToChild()
38 #include "wx/module.h"
39 #include "wx/display.h"
41 // controls for sending select event
42 #include "wx/button.h"
43 #include "wx/checkbox.h"
44 #include "wx/radiobut.h"
45 #include "wx/tglbtn.h"
46 #include "wx/slider.h"
47 #include "wx/datectrl.h"
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
56 // the name of the default wxWidgets class
57 extern const wxChar
*wxCanvasClassName
;
59 // Pointer to the currently active frame for the form event handler.
60 wxTopLevelWindowPalm
* ActiveParentFrame
;
62 static Boolean
FrameFormHandleEvent(EventType
*event
);
64 // ============================================================================
65 // wxTopLevelWindowPalm implementation
66 // ============================================================================
68 BEGIN_EVENT_TABLE(wxTopLevelWindowPalm
, wxTopLevelWindowBase
)
69 EVT_ACTIVATE(wxTopLevelWindowPalm::OnActivate
)
72 // ----------------------------------------------------------------------------
73 // wxTopLevelWindowPalm creation
74 // ----------------------------------------------------------------------------
76 void wxTopLevelWindowPalm::Init()
80 WXDWORD
wxTopLevelWindowPalm::PalmGetStyle(long style
, WXDWORD
*exflags
) const
85 bool wxTopLevelWindowPalm::Create(wxWindow
*parent
,
87 const wxString
& title
,
93 // this is a check for limitation mentioned before FrameFormHandleEvent() code
94 if(wxTopLevelWindows
.GetCount()>0)
97 ActiveParentFrame
=NULL
;
99 wxTopLevelWindows
.Append(this);
102 parent
->AddChild(this);
104 SetId( id
== wxID_ANY
? NewControlId() : id
);
106 WinConstraintsType constraints
;
107 memset(&constraints
, 0, sizeof(WinConstraintsType
));
109 constraints
.x_pos
= ( pos
.x
== wxDefaultCoord
) ? winUndefConstraint
: pos
.x
;
110 constraints
.y_pos
= ( pos
.y
== wxDefaultCoord
) ? winUndefConstraint
: pos
.y
;
112 constraints
.x_min
= winUndefConstraint
;
113 constraints
.x_max
= winMaxConstraint
;
114 constraints
.x_pref
= ( size
.x
== wxDefaultCoord
) ? winUndefConstraint
: size
.x
;
115 constraints
.y_min
= winUndefConstraint
;
116 constraints
.y_max
= winMaxConstraint
;
117 constraints
.y_pref
= ( size
.y
== wxDefaultCoord
) ? winUndefConstraint
: size
.y
;
119 FrameForm
= FrmNewFormWithConstraints(
134 FrmSetEventHandler((FormType
*)FrameForm
,FrameFormHandleEvent
);
136 FrmSetActiveForm((FormType
*)FrameForm
);
138 ActiveParentFrame
=this;
143 wxTopLevelWindowPalm::~wxTopLevelWindowPalm()
147 // ---------------------------------------------------------------------------
149 // ---------------------------------------------------------------------------
151 WXWINHANDLE
wxTopLevelWindowPalm::GetWinHandle() const
153 FormType
*form
= (FormType
*)GetForm();
155 return FrmGetWindowHandle(form
);
159 // ----------------------------------------------------------------------------
160 // wxTopLevelWindowPalm showing
161 // ----------------------------------------------------------------------------
163 void wxTopLevelWindowPalm::DoShowWindow(int nShowCmd
)
167 bool wxTopLevelWindowPalm::Show(bool show
)
169 FrmDrawForm((FormType
*)FrameForm
);
171 wxPaintEvent
event(m_windowId
);
172 event
.SetEventObject(this);
173 GetEventHandler()->ProcessEvent(event
);
178 // ----------------------------------------------------------------------------
179 // wxTopLevelWindowPalm maximize/minimize
180 // ----------------------------------------------------------------------------
182 void wxTopLevelWindowPalm::Maximize(bool maximize
)
186 bool wxTopLevelWindowPalm::IsMaximized() const
191 void wxTopLevelWindowPalm::Iconize(bool iconize
)
195 bool wxTopLevelWindowPalm::IsIconized() const
200 void wxTopLevelWindowPalm::Restore()
204 void wxTopLevelWindowPalm::DoGetSize( int *width
, int *height
) const
207 FrmGetFormBounds( (FormType
*)GetForm() , &rect
);
209 *width
= rect
.extent
.x
;
211 *height
= rect
.extent
.y
;
214 // ----------------------------------------------------------------------------
215 // wxTopLevelWindowPalm fullscreen
216 // ----------------------------------------------------------------------------
218 bool wxTopLevelWindowPalm::ShowFullScreen(bool show
, long style
)
223 // ----------------------------------------------------------------------------
224 // wxTopLevelWindowPalm misc
225 // ----------------------------------------------------------------------------
227 void wxTopLevelWindowPalm::SetIcon(const wxIcon
& icon
)
231 void wxTopLevelWindowPalm::SetIcons(const wxIconBundle
& icons
)
235 bool wxTopLevelWindowPalm::EnableCloseButton(bool enable
)
240 WXFORMPTR
wxTopLevelWindowPalm::GetForm() const
242 return FrmGetActiveForm();
245 bool wxTopLevelWindowPalm::SetShape(const wxRegion
& region
)
250 // ----------------------------------------------------------------------------
251 // wxTopLevelWindow native event handling
252 // ----------------------------------------------------------------------------
254 bool wxTopLevelWindowPalm::HandleControlSelect(WXEVENTPTR event
)
256 const EventType
*palmEvent
= (EventType
*)event
;
257 const int id
= palmEvent
->data
.ctlSelect
.controlID
;
259 wxWindow
* win
= FindWindowById(id
,this);
264 wxButton
* button
= wxDynamicCast(win
,wxButton
);
266 return button
->SendClickEvent();
267 #endif // wxUSE_BUTTON
270 wxCheckBox
* checkbox
= wxDynamicCast(win
,wxCheckBox
);
272 return checkbox
->SendClickEvent();
273 #endif // wxUSE_CHECKBOX
276 wxToggleButton
* toggle
= wxDynamicCast(win
,wxToggleButton
);
278 return toggle
->SendClickEvent();
279 #endif // wxUSE_TOGGLEBTN
282 wxRadioButton
* radio
= wxDynamicCast(win
,wxRadioButton
);
284 return radio
->SendClickEvent();
285 #endif // wxUSE_RADIOBTN
287 #if wxUSE_DATEPICKCTRL
288 wxDatePickerCtrl
* datepicker
= wxDynamicCast(win
,wxDatePickerCtrl
);
290 return datepicker
->SendClickEvent();
291 #endif // wxUSE_DATEPICKCTRL
294 wxSlider
* slider
= wxDynamicCast(win
,wxSlider
);
296 return slider
->SendUpdatedEvent();
297 #endif // wxUSE_SLIDER
302 bool wxTopLevelWindowPalm::HandleControlRepeat(WXEVENTPTR event
)
304 const EventType
*palmEvent
= (EventType
*)event
;
305 const int id
= palmEvent
->data
.ctlRepeat
.controlID
;
307 wxWindow
* win
= FindWindowById(id
, this);
312 wxSlider
* slider
= wxDynamicCast(win
,wxSlider
);
314 return slider
->SendScrollEvent(event
);
315 #endif // wxUSE_SLIDER
320 bool wxTopLevelWindowPalm::HandleSize(WXEVENTPTR event
)
322 const EventType
*palmEvent
= (EventType
*)event
;
323 wxSize
newSize(palmEvent
->data
.winResized
.newBounds
.extent
.x
,
324 palmEvent
->data
.winResized
.newBounds
.extent
.y
);
325 wxSizeEvent
eventWx(newSize
,GetId());
326 eventWx
.SetEventObject(this);
327 return GetEventHandler()->ProcessEvent(eventWx
);
330 void wxTopLevelWindowPalm::OnActivate(wxActivateEvent
& event
)
334 /* Palm OS Event handler for the window
336 * This function *must* be located outside of the wxTopLevelWindow class because
337 * the Palm OS API expects a standalone C function as a callback. You cannot
338 * pass a pointer to a member function of a C++ class as a callback because the
339 * prototypes don't match. (A member function has a hidden "this" pointer as
340 * its first parameter).
342 * This event handler uses a global pointer to the current wxFrame to process
343 * the events generated by the Palm OS form API. I know this is ugly, but right
344 * now I can't think of any other way to deal with this problem. If someone
345 * finds a better solution, please let me know. My email address is
348 static Boolean
FrameFormHandleEvent(EventType
*event
)
350 // frame and tlw point to the same object but they are for convenience
351 // of calling proper structure withiout later dynamic typcasting
352 wxFrame
* frame
= wxDynamicCast(ActiveParentFrame
,wxFrame
);
353 wxTopLevelWindowPalm
* tlw
= ActiveParentFrame
;
354 Boolean handled
= false;
356 switch (event
->eType
) {
358 handled
= tlw
->HandleControlSelect(event
);
361 handled
= tlw
->HandleControlRepeat(event
);
363 case winResizedEvent
:
364 handled
= tlw
->HandleSize(event
);
366 #if wxUSE_MENUS_NATIVE
368 handled
= frame
->HandleMenuOpen();
371 handled
= frame
->HandleMenuSelect(event
);