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"
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 // ============================================================================
63 // wxTopLevelWindowPalm implementation
64 // ============================================================================
66 BEGIN_EVENT_TABLE(wxTopLevelWindowPalm
, wxTopLevelWindowBase
)
67 EVT_ACTIVATE(wxTopLevelWindowPalm::OnActivate
)
70 // ----------------------------------------------------------------------------
71 // wxTopLevelWindowPalm creation
72 // ----------------------------------------------------------------------------
74 void wxTopLevelWindowPalm::Init()
78 WXDWORD
wxTopLevelWindowPalm::PalmGetStyle(long style
, WXDWORD
*exflags
) const
83 WXHWND
wxTopLevelWindowPalm::PalmGetParent() const
88 bool wxTopLevelWindowPalm::Create(wxWindow
*parent
,
90 const wxString
& title
,
96 // this is a check for limitation mentioned before FrameFormHandleEvent() code
97 if(wxTopLevelWindows
.GetCount()>0)
100 ActiveParentFrame
=NULL
;
102 wxTopLevelWindows
.Append(this);
105 parent
->AddChild(this);
107 SetId( id
== wxID_ANY
? NewControlId() : id
);
109 WinConstraintsType constraints
;
110 memset(&constraints
, 0, sizeof(WinConstraintsType
));
112 constraints
.x_pos
= ( pos
.x
== wxDefaultCoord
) ? winUndefConstraint
: pos
.x
;
113 constraints
.y_pos
= ( pos
.y
== wxDefaultCoord
) ? winUndefConstraint
: pos
.y
;
115 constraints
.x_min
= winUndefConstraint
;
116 constraints
.x_max
= winMaxConstraint
;
117 constraints
.x_pref
= ( size
.x
== wxDefaultCoord
) ? winUndefConstraint
: size
.x
;
118 constraints
.y_min
= winUndefConstraint
;
119 constraints
.y_max
= winMaxConstraint
;
120 constraints
.y_pref
= ( size
.y
== wxDefaultCoord
) ? winUndefConstraint
: size
.y
;
122 FrameForm
= FrmNewFormWithConstraints(
137 FrmSetEventHandler(FrameForm
,FrameFormHandleEvent
);
139 FrmSetActiveForm(FrameForm
);
141 ActiveParentFrame
=this;
146 wxTopLevelWindowPalm::~wxTopLevelWindowPalm()
150 // ----------------------------------------------------------------------------
151 // wxTopLevelWindowPalm showing
152 // ----------------------------------------------------------------------------
154 void wxTopLevelWindowPalm::DoShowWindow(int nShowCmd
)
158 bool wxTopLevelWindowPalm::Show(bool show
)
160 FrmDrawForm(FrameForm
);
162 wxPaintEvent
event(m_windowId
);
163 event
.SetEventObject(this);
164 GetEventHandler()->ProcessEvent(event
);
169 // ----------------------------------------------------------------------------
170 // wxTopLevelWindowPalm maximize/minimize
171 // ----------------------------------------------------------------------------
173 void wxTopLevelWindowPalm::Maximize(bool maximize
)
177 bool wxTopLevelWindowPalm::IsMaximized() const
182 void wxTopLevelWindowPalm::Iconize(bool iconize
)
186 bool wxTopLevelWindowPalm::IsIconized() const
191 void wxTopLevelWindowPalm::Restore()
195 void wxTopLevelWindowPalm::DoGetSize( int *width
, int *height
) const
198 FrmGetFormBounds( GetForm() , &rect
);
200 *width
= rect
.extent
.x
;
202 *height
= rect
.extent
.y
;
205 // ----------------------------------------------------------------------------
206 // wxTopLevelWindowPalm fullscreen
207 // ----------------------------------------------------------------------------
209 bool wxTopLevelWindowPalm::ShowFullScreen(bool show
, long style
)
214 // ----------------------------------------------------------------------------
215 // wxTopLevelWindowPalm misc
216 // ----------------------------------------------------------------------------
218 void wxTopLevelWindowPalm::SetIcon(const wxIcon
& icon
)
222 void wxTopLevelWindowPalm::SetIcons(const wxIconBundle
& icons
)
226 bool wxTopLevelWindowPalm::EnableCloseButton(bool enable
)
231 FormType
*wxTopLevelWindowPalm::GetForm() const
233 return FrmGetActiveForm();
238 bool wxTopLevelWindowPalm::SetShape(const wxRegion
& region
)
243 #endif // !__WXWINCE__
245 // ----------------------------------------------------------------------------
246 // wxTopLevelWindow native event handling
247 // ----------------------------------------------------------------------------
249 bool wxTopLevelWindowPalm::HandleControlSelect(EventType
* event
)
251 int id
= event
->data
.ctlSelect
.controlID
;
253 wxWindow
* win
= FindWindowById(id
,this);
257 wxButton
* button
= wxDynamicCast(win
,wxButton
);
259 return button
->SendClickEvent();
261 wxCheckBox
* checkbox
= wxDynamicCast(win
,wxCheckBox
);
263 return checkbox
->SendClickEvent();
265 wxToggleButton
* toggle
= wxDynamicCast(win
,wxToggleButton
);
267 return toggle
->SendClickEvent();
269 wxRadioButton
* radio
= wxDynamicCast(win
,wxRadioButton
);
271 return radio
->SendClickEvent();
273 wxSlider
* slider
= wxDynamicCast(win
,wxSlider
);
275 return slider
->SendUpdatedEvent();
280 bool wxTopLevelWindowPalm::HandleControlRepeat(EventType
* event
)
282 int id
= event
->data
.ctlRepeat
.controlID
;
284 wxWindow
* win
= FindWindowById(id
,this);
288 wxSlider
* slider
= wxDynamicCast(win
,wxSlider
);
290 return slider
->SendScrollEvent(event
);
295 bool wxTopLevelWindowPalm::HandleSize(EventType
* event
)
297 wxSize
newSize(event
->data
.winResized
.newBounds
.extent
.x
,
298 event
->data
.winResized
.newBounds
.extent
.y
);
299 wxSizeEvent
eventWx(newSize
,GetId());
300 eventWx
.SetEventObject(this);
301 return GetEventHandler()->ProcessEvent(eventWx
);
304 void wxTopLevelWindowPalm::OnActivate(wxActivateEvent
& event
)
308 /* Palm OS Event handler for the window
310 * This function *must* be located outside of the wxTopLevelWindow class because
311 * the Palm OS API expects a standalone C function as a callback. You cannot
312 * pass a pointer to a member function of a C++ class as a callback because the
313 * prototypes don't match. (A member function has a hidden "this" pointer as
314 * its first parameter).
316 * This event handler uses a global pointer to the current wxFrame to process
317 * the events generated by the Palm OS form API. I know this is ugly, but right
318 * now I can't think of any other way to deal with this problem. If someone
319 * finds a better solution, please let me know. My email address is
322 static Boolean
FrameFormHandleEvent(EventType
* event
)
324 // frame and tlw point to the same object but they are for convenience
325 // of calling proper structure withiout later dynamic typcasting
326 wxFrame
* frame
= wxDynamicCast(ActiveParentFrame
,wxFrame
);
327 wxTopLevelWindowPalm
* tlw
= ActiveParentFrame
;
328 Boolean handled
= false;
330 switch (event
->eType
) {
332 handled
= tlw
->HandleControlSelect(event
);
335 handled
= tlw
->HandleControlRepeat(event
);
337 case winResizedEvent
:
338 handled
= tlw
->HandleSize(event
);
340 #if wxUSE_MENUS_NATIVE
342 handled
= frame
->HandleMenuOpen();
345 handled
= frame
->HandleMenuSelect(event
);