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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "toplevel.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/toplevel.h"
34 #include "wx/dialog.h"
35 #include "wx/string.h"
39 #include "wx/containr.h" // wxSetFocusToChild()
42 #include "wx/module.h"
43 #include "wx/display.h"
45 // controls for sending select event
46 #include "wx/button.h"
47 #include "wx/checkbox.h"
48 #include "wx/radiobut.h"
49 #include "wx/tglbtn.h"
50 #include "wx/slider.h"
51 #include "wx/datectrl.h"
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 // the name of the default wxWidgets class
61 extern const wxChar
*wxCanvasClassName
;
63 // Pointer to the currently active frame for the form event handler.
64 wxTopLevelWindowPalm
* ActiveParentFrame
;
66 static Boolean
FrameFormHandleEvent(EventType
*event
);
68 // ============================================================================
69 // wxTopLevelWindowPalm implementation
70 // ============================================================================
72 BEGIN_EVENT_TABLE(wxTopLevelWindowPalm
, wxTopLevelWindowBase
)
73 EVT_ACTIVATE(wxTopLevelWindowPalm::OnActivate
)
76 // ----------------------------------------------------------------------------
77 // wxTopLevelWindowPalm creation
78 // ----------------------------------------------------------------------------
80 void wxTopLevelWindowPalm::Init()
84 WXDWORD
wxTopLevelWindowPalm::PalmGetStyle(long style
, WXDWORD
*exflags
) const
89 bool wxTopLevelWindowPalm::Create(wxWindow
*parent
,
91 const wxString
& title
,
97 // this is a check for limitation mentioned before FrameFormHandleEvent() code
98 if(wxTopLevelWindows
.GetCount()>0)
101 ActiveParentFrame
=NULL
;
103 wxTopLevelWindows
.Append(this);
106 parent
->AddChild(this);
108 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
;
123 FrameForm
= FrmNewFormWithConstraints(
138 FrmSetEventHandler((FormType
*)FrameForm
,FrameFormHandleEvent
);
140 FrmSetActiveForm((FormType
*)FrameForm
);
142 ActiveParentFrame
=this;
147 wxTopLevelWindowPalm::~wxTopLevelWindowPalm()
151 // ---------------------------------------------------------------------------
153 // ---------------------------------------------------------------------------
155 WXWINHANDLE
wxTopLevelWindowPalm::GetWinHandle() const
157 FormType
*form
= (FormType
*)GetForm();
159 return FrmGetWindowHandle(form
);
163 // ----------------------------------------------------------------------------
164 // wxTopLevelWindowPalm showing
165 // ----------------------------------------------------------------------------
167 void wxTopLevelWindowPalm::DoShowWindow(int nShowCmd
)
171 bool wxTopLevelWindowPalm::Show(bool show
)
173 FrmDrawForm((FormType
*)FrameForm
);
175 wxPaintEvent
event(m_windowId
);
176 event
.SetEventObject(this);
177 GetEventHandler()->ProcessEvent(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::SetIcon(const wxIcon
& icon
)
235 void wxTopLevelWindowPalm::SetIcons(const wxIconBundle
& icons
)
239 bool wxTopLevelWindowPalm::EnableCloseButton(bool enable
)
244 WXFORMPTR
wxTopLevelWindowPalm::GetForm() const
246 return FrmGetActiveForm();
249 bool wxTopLevelWindowPalm::SetShape(const wxRegion
& region
)
254 // ----------------------------------------------------------------------------
255 // wxTopLevelWindow native event handling
256 // ----------------------------------------------------------------------------
258 bool wxTopLevelWindowPalm::HandleControlSelect(WXEVENTPTR event
)
260 const EventType
*palmEvent
= (EventType
*)event
;
261 const int id
= palmEvent
->data
.ctlSelect
.controlID
;
263 wxWindow
* win
= FindWindowById(id
,this);
268 wxButton
* button
= wxDynamicCast(win
,wxButton
);
270 return button
->SendClickEvent();
271 #endif // wxUSE_BUTTON
274 wxCheckBox
* checkbox
= wxDynamicCast(win
,wxCheckBox
);
276 return checkbox
->SendClickEvent();
277 #endif // wxUSE_CHECKBOX
280 wxToggleButton
* toggle
= wxDynamicCast(win
,wxToggleButton
);
282 return toggle
->SendClickEvent();
283 #endif // wxUSE_TOGGLEBTN
286 wxRadioButton
* radio
= wxDynamicCast(win
,wxRadioButton
);
288 return radio
->SendClickEvent();
289 #endif // wxUSE_RADIOBTN
291 #if wxUSE_DATEPICKCTRL
292 wxDatePickerCtrl
* datepicker
= wxDynamicCast(win
,wxDatePickerCtrl
);
294 return datepicker
->SendClickEvent();
295 #endif // wxUSE_DATEPICKCTRL
298 wxSlider
* slider
= wxDynamicCast(win
,wxSlider
);
300 return slider
->SendUpdatedEvent();
301 #endif // wxUSE_SLIDER
306 bool wxTopLevelWindowPalm::HandleControlRepeat(WXEVENTPTR event
)
308 const EventType
*palmEvent
= (EventType
*)event
;
309 const int id
= palmEvent
->data
.ctlRepeat
.controlID
;
311 wxWindow
* win
= FindWindowById(id
, this);
316 wxSlider
* slider
= wxDynamicCast(win
,wxSlider
);
318 return slider
->SendScrollEvent(event
);
319 #endif // wxUSE_SLIDER
324 bool wxTopLevelWindowPalm::HandleSize(WXEVENTPTR event
)
326 const EventType
*palmEvent
= (EventType
*)event
;
327 wxSize
newSize(palmEvent
->data
.winResized
.newBounds
.extent
.x
,
328 palmEvent
->data
.winResized
.newBounds
.extent
.y
);
329 wxSizeEvent
eventWx(newSize
,GetId());
330 eventWx
.SetEventObject(this);
331 return GetEventHandler()->ProcessEvent(eventWx
);
334 void wxTopLevelWindowPalm::OnActivate(wxActivateEvent
& event
)
338 /* Palm OS Event handler for the window
340 * This function *must* be located outside of the wxTopLevelWindow class because
341 * the Palm OS API expects a standalone C function as a callback. You cannot
342 * pass a pointer to a member function of a C++ class as a callback because the
343 * prototypes don't match. (A member function has a hidden "this" pointer as
344 * its first parameter).
346 * This event handler uses a global pointer to the current wxFrame to process
347 * the events generated by the Palm OS form API. I know this is ugly, but right
348 * now I can't think of any other way to deal with this problem. If someone
349 * finds a better solution, please let me know. My email address is
352 static Boolean
FrameFormHandleEvent(EventType
*event
)
354 // frame and tlw point to the same object but they are for convenience
355 // of calling proper structure withiout later dynamic typcasting
356 wxFrame
* frame
= wxDynamicCast(ActiveParentFrame
,wxFrame
);
357 wxTopLevelWindowPalm
* tlw
= ActiveParentFrame
;
358 Boolean handled
= false;
360 switch (event
->eType
) {
362 handled
= tlw
->HandleControlSelect(event
);
365 handled
= tlw
->HandleControlRepeat(event
);
367 case winResizedEvent
:
368 handled
= tlw
->HandleSize(event
);
370 #if wxUSE_MENUS_NATIVE
372 handled
= frame
->HandleMenuOpen();
375 handled
= frame
->HandleMenuSelect(event
);