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"
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 // the name of the default wxWidgets class
56 extern const wxChar
*wxCanvasClassName
;
58 // Pointer to the currently active frame for the form event handler.
59 wxTopLevelWindowPalm
* ActiveParentFrame
;
61 // ============================================================================
62 // wxTopLevelWindowPalm implementation
63 // ============================================================================
65 BEGIN_EVENT_TABLE(wxTopLevelWindowPalm
, wxTopLevelWindowBase
)
66 EVT_ACTIVATE(wxTopLevelWindowPalm::OnActivate
)
69 // ----------------------------------------------------------------------------
70 // wxTopLevelWindowPalm creation
71 // ----------------------------------------------------------------------------
73 void wxTopLevelWindowPalm::Init()
77 WXDWORD
wxTopLevelWindowPalm::PalmGetStyle(long style
, WXDWORD
*exflags
) const
82 WXHWND
wxTopLevelWindowPalm::PalmGetParent() const
87 bool wxTopLevelWindowPalm::Create(wxWindow
*parent
,
89 const wxString
& title
,
95 // this is a check for limitation mentioned before FrameFormHandleEvent() code
96 if(wxTopLevelWindows
.GetCount()>0)
99 ActiveParentFrame
=NULL
;
101 wxTopLevelWindows
.Append(this);
104 parent
->AddChild(this);
106 SetId( id
== wxID_ANY
? NewControlId() : id
);
108 WinConstraintsType constraints
;
109 memset(&constraints
, 0, sizeof(WinConstraintsType
));
111 constraints
.x_pos
= ( pos
.x
== wxDefaultCoord
) ? winUndefConstraint
: pos
.x
;
112 constraints
.y_pos
= ( pos
.y
== wxDefaultCoord
) ? winUndefConstraint
: pos
.y
;
114 constraints
.x_min
= winUndefConstraint
;
115 constraints
.x_max
= winMaxConstraint
;
116 constraints
.x_pref
= ( size
.x
== wxDefaultCoord
) ? winUndefConstraint
: size
.x
;
117 constraints
.y_min
= winUndefConstraint
;
118 constraints
.y_max
= winMaxConstraint
;
119 constraints
.y_pref
= ( size
.y
== wxDefaultCoord
) ? winUndefConstraint
: size
.y
;
121 FrameForm
= FrmNewFormWithConstraints(
136 FrmSetEventHandler(FrameForm
,FrameFormHandleEvent
);
138 FrmSetActiveForm(FrameForm
);
140 ActiveParentFrame
=this;
145 wxTopLevelWindowPalm::~wxTopLevelWindowPalm()
149 // ----------------------------------------------------------------------------
150 // wxTopLevelWindowPalm showing
151 // ----------------------------------------------------------------------------
153 void wxTopLevelWindowPalm::DoShowWindow(int nShowCmd
)
157 bool wxTopLevelWindowPalm::Show(bool show
)
159 FrmDrawForm(FrameForm
);
161 wxPaintEvent
event(m_windowId
);
162 event
.SetEventObject(this);
163 GetEventHandler()->ProcessEvent(event
);
168 // ----------------------------------------------------------------------------
169 // wxTopLevelWindowPalm maximize/minimize
170 // ----------------------------------------------------------------------------
172 void wxTopLevelWindowPalm::Maximize(bool maximize
)
176 bool wxTopLevelWindowPalm::IsMaximized() const
181 void wxTopLevelWindowPalm::Iconize(bool iconize
)
185 bool wxTopLevelWindowPalm::IsIconized() const
190 void wxTopLevelWindowPalm::Restore()
194 void wxTopLevelWindowPalm::DoGetSize( int *width
, int *height
) const
197 FrmGetFormBounds( GetForm() , &rect
);
199 *width
= rect
.extent
.x
;
201 *height
= rect
.extent
.y
;
204 // ----------------------------------------------------------------------------
205 // wxTopLevelWindowPalm fullscreen
206 // ----------------------------------------------------------------------------
208 bool wxTopLevelWindowPalm::ShowFullScreen(bool show
, long style
)
213 // ----------------------------------------------------------------------------
214 // wxTopLevelWindowPalm misc
215 // ----------------------------------------------------------------------------
217 void wxTopLevelWindowPalm::SetIcon(const wxIcon
& icon
)
221 void wxTopLevelWindowPalm::SetIcons(const wxIconBundle
& icons
)
225 bool wxTopLevelWindowPalm::EnableCloseButton(bool enable
)
230 FormType
*wxTopLevelWindowPalm::GetForm() const
232 return FrmGetActiveForm();
237 bool wxTopLevelWindowPalm::SetShape(const wxRegion
& region
)
242 #endif // !__WXWINCE__
244 // ----------------------------------------------------------------------------
245 // wxTopLevelWindow event handling
246 // ----------------------------------------------------------------------------
248 bool wxTopLevelWindowPalm::HandleControlSelect(EventType
* event
)
250 int id
= event
->data
.ctlSelect
.controlID
;
251 wxWindow
* win
= FindWindowById(id
,this);
255 wxButton
* button
= wxDynamicCast(win
,wxButton
);
257 return button
->SendClickEvent();
259 wxCheckBox
* checkbox
= wxDynamicCast(win
,wxCheckBox
);
261 return checkbox
->SendClickEvent();
263 wxToggleButton
* toggle
= wxDynamicCast(win
,wxToggleButton
);
265 return toggle
->SendClickEvent();
267 wxRadioButton
* radio
= wxDynamicCast(win
,wxRadioButton
);
269 return radio
->SendClickEvent();
274 void wxTopLevelWindowPalm::OnActivate(wxActivateEvent
& event
)
278 /* Palm OS Event handler for the window
280 * This function *must* be located outside of the wxTopLevelWindow class because
281 * the Palm OS API expects a standalone C function as a callback. You cannot
282 * pass a pointer to a member function of a C++ class as a callback because the
283 * prototypes don't match. (A member function has a hidden "this" pointer as
284 * its first parameter).
286 * This event handler uses a global pointer to the current wxFrame to process
287 * the events generated by the Palm OS form API. I know this is ugly, but right
288 * now I can't think of any other way to deal with this problem. If someone
289 * finds a better solution, please let me know. My email address is
292 static Boolean
FrameFormHandleEvent(EventType
* event
)
294 wxFrame
* frame
= wxDynamicCast(ActiveParentFrame
,wxFrame
);
295 Boolean handled
= false;
297 switch (event
->eType
) {
299 handled
= frame
->HandleControlSelect(event
);
301 #if wxUSE_MENUS_NATIVE
303 handled
= frame
->HandleMenuOpen();
306 handled
= frame
->HandleMenuSelect(event
);