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"
44 #include "wx/display.h"
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 // the name of the default wxWidgets class
51 extern const wxChar
*wxCanvasClassName
;
53 // Pointer to the currently active frame for the form event handler.
54 wxTopLevelWindowPalm
* ActiveParentFrame
;
56 // ============================================================================
57 // wxTopLevelWindowPalm implementation
58 // ============================================================================
60 BEGIN_EVENT_TABLE(wxTopLevelWindowPalm
, wxTopLevelWindowBase
)
61 EVT_ACTIVATE(wxTopLevelWindowPalm::OnActivate
)
64 // ----------------------------------------------------------------------------
65 // wxTopLevelWindowPalm creation
66 // ----------------------------------------------------------------------------
68 void wxTopLevelWindowPalm::Init()
72 WXDWORD
wxTopLevelWindowPalm::PalmGetStyle(long style
, WXDWORD
*exflags
) const
77 WXHWND
wxTopLevelWindowPalm::PalmGetParent() const
82 bool wxTopLevelWindowPalm::Create(wxWindow
*parent
,
84 const wxString
& title
,
90 // this is a check for limitation mentioned before FrameFormHandleEvent() code
91 if(wxTopLevelWindows
.GetCount()>0)
94 ActiveParentFrame
=NULL
;
96 wxTopLevelWindows
.Append(this);
99 parent
->AddChild(this);
101 SetId( id
== wxID_ANY
? NewControlId() : id
);
103 WinConstraintsType constraints
;
104 memset(&constraints
, 0, sizeof(WinConstraintsType
));
106 constraints
.x_pos
= ( pos
.x
== wxDefaultCoord
) ? winUndefConstraint
: pos
.x
;
107 constraints
.y_pos
= ( pos
.y
== wxDefaultCoord
) ? winUndefConstraint
: pos
.y
;
109 constraints
.x_min
= winUndefConstraint
;
110 constraints
.x_max
= winMaxConstraint
;
111 constraints
.x_pref
= ( size
.x
== wxDefaultCoord
) ? winUndefConstraint
: size
.x
;
112 constraints
.y_min
= winUndefConstraint
;
113 constraints
.y_max
= winMaxConstraint
;
114 constraints
.y_pref
= ( size
.y
== wxDefaultCoord
) ? winUndefConstraint
: size
.y
;
116 FrameForm
= FrmNewFormWithConstraints(
131 FrmSetEventHandler(FrameForm
,FrameFormHandleEvent
);
133 FrmSetActiveForm(FrameForm
);
135 ActiveParentFrame
=this;
140 wxTopLevelWindowPalm::~wxTopLevelWindowPalm()
144 // ----------------------------------------------------------------------------
145 // wxTopLevelWindowPalm showing
146 // ----------------------------------------------------------------------------
148 void wxTopLevelWindowPalm::DoShowWindow(int nShowCmd
)
152 bool wxTopLevelWindowPalm::Show(bool show
)
154 FrmDrawForm(FrameForm
);
156 wxPaintEvent
event(m_windowId
);
157 event
.SetEventObject(this);
158 GetEventHandler()->ProcessEvent(event
);
163 // ----------------------------------------------------------------------------
164 // wxTopLevelWindowPalm maximize/minimize
165 // ----------------------------------------------------------------------------
167 void wxTopLevelWindowPalm::Maximize(bool maximize
)
171 bool wxTopLevelWindowPalm::IsMaximized() const
176 void wxTopLevelWindowPalm::Iconize(bool iconize
)
180 bool wxTopLevelWindowPalm::IsIconized() const
185 void wxTopLevelWindowPalm::Restore()
189 void wxTopLevelWindowPalm::DoGetSize( int *width
, int *height
) const
192 FrmGetFormBounds( GetForm() , &rect
);
194 *width
= rect
.extent
.x
;
196 *height
= rect
.extent
.y
;
199 // ----------------------------------------------------------------------------
200 // wxTopLevelWindowPalm fullscreen
201 // ----------------------------------------------------------------------------
203 bool wxTopLevelWindowPalm::ShowFullScreen(bool show
, long style
)
208 // ----------------------------------------------------------------------------
209 // wxTopLevelWindowPalm misc
210 // ----------------------------------------------------------------------------
212 void wxTopLevelWindowPalm::SetIcon(const wxIcon
& icon
)
216 void wxTopLevelWindowPalm::SetIcons(const wxIconBundle
& icons
)
220 bool wxTopLevelWindowPalm::EnableCloseButton(bool enable
)
225 FormType
*wxTopLevelWindowPalm::GetForm() const
227 return FrmGetActiveForm();
232 bool wxTopLevelWindowPalm::SetShape(const wxRegion
& region
)
237 #endif // !__WXWINCE__
239 // ----------------------------------------------------------------------------
240 // wxTopLevelWindow event handling
241 // ----------------------------------------------------------------------------
243 void wxTopLevelWindowPalm::OnActivate(wxActivateEvent
& event
)
247 /* Palm OS Event handler for the window
249 * This function *must* be located outside of the wxTopLevelWindow class because
250 * the Palm OS API expects a standalone C function as a callback. You cannot
251 * pass a pointer to a member function of a C++ class as a callback because the
252 * prototypes don't match. (A member function has a hidden "this" pointer as
253 * its first parameter).
255 * This event handler uses a global pointer to the current wxFrame to process
256 * the events generated by the Palm OS form API. I know this is ugly, but right
257 * now I can't think of any other way to deal with this problem. If someone
258 * finds a better solution, please let me know. My email address is
261 static Boolean
FrameFormHandleEvent(EventType
* pEvent
)
263 wxFrame
* frame
= wxDynamicCast(ActiveParentFrame
,wxFrame
);
264 Boolean fHandled
= false;
269 switch (pEvent
->eType
) {
272 #if wxUSE_MENUS_NATIVE
274 fHandled
= frame
->HandleMenuOpen();
277 ItemID
= pEvent
->data
.menu
.itemID
;
278 fHandled
= frame
->HandleMenuSelect(ItemID
);