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 bool wxTopLevelWindowPalm::Create(wxWindow
*parent
,
85 const wxString
& title
,
91 // this is a check for limitation mentioned before FrameFormHandleEvent() code
92 if(wxTopLevelWindows
.GetCount()>0)
95 ActiveParentFrame
=NULL
;
97 wxTopLevelWindows
.Append(this);
100 parent
->AddChild(this);
102 SetId( id
== wxID_ANY
? NewControlId() : id
);
104 WinConstraintsType constraints
;
105 memset(&constraints
, 0, sizeof(WinConstraintsType
));
107 constraints
.x_pos
= ( pos
.x
== wxDefaultCoord
) ? winUndefConstraint
: pos
.x
;
108 constraints
.y_pos
= ( pos
.y
== wxDefaultCoord
) ? winUndefConstraint
: pos
.y
;
110 constraints
.x_min
= winUndefConstraint
;
111 constraints
.x_max
= winMaxConstraint
;
112 constraints
.x_pref
= ( size
.x
== wxDefaultCoord
) ? winUndefConstraint
: size
.x
;
113 constraints
.y_min
= winUndefConstraint
;
114 constraints
.y_max
= winMaxConstraint
;
115 constraints
.y_pref
= ( size
.y
== wxDefaultCoord
) ? winUndefConstraint
: size
.y
;
117 FrameForm
= FrmNewFormWithConstraints(
132 FrmSetEventHandler(FrameForm
,FrameFormHandleEvent
);
134 FrmSetActiveForm(FrameForm
);
136 ActiveParentFrame
=this;
141 wxTopLevelWindowPalm::~wxTopLevelWindowPalm()
145 // ---------------------------------------------------------------------------
147 // ---------------------------------------------------------------------------
149 WXWINHANDLE
wxTopLevelWindowPalm::GetWinHandle() const
151 FormType
*form
= GetForm();
153 return FrmGetWindowHandle(form
);
157 // ----------------------------------------------------------------------------
158 // wxTopLevelWindowPalm showing
159 // ----------------------------------------------------------------------------
161 void wxTopLevelWindowPalm::DoShowWindow(int nShowCmd
)
165 bool wxTopLevelWindowPalm::Show(bool show
)
167 FrmDrawForm(FrameForm
);
169 wxPaintEvent
event(m_windowId
);
170 event
.SetEventObject(this);
171 GetEventHandler()->ProcessEvent(event
);
176 // ----------------------------------------------------------------------------
177 // wxTopLevelWindowPalm maximize/minimize
178 // ----------------------------------------------------------------------------
180 void wxTopLevelWindowPalm::Maximize(bool maximize
)
184 bool wxTopLevelWindowPalm::IsMaximized() const
189 void wxTopLevelWindowPalm::Iconize(bool iconize
)
193 bool wxTopLevelWindowPalm::IsIconized() const
198 void wxTopLevelWindowPalm::Restore()
202 void wxTopLevelWindowPalm::DoGetSize( int *width
, int *height
) const
205 FrmGetFormBounds( GetForm() , &rect
);
207 *width
= rect
.extent
.x
;
209 *height
= rect
.extent
.y
;
212 // ----------------------------------------------------------------------------
213 // wxTopLevelWindowPalm fullscreen
214 // ----------------------------------------------------------------------------
216 bool wxTopLevelWindowPalm::ShowFullScreen(bool show
, long style
)
221 // ----------------------------------------------------------------------------
222 // wxTopLevelWindowPalm misc
223 // ----------------------------------------------------------------------------
225 void wxTopLevelWindowPalm::SetIcon(const wxIcon
& icon
)
229 void wxTopLevelWindowPalm::SetIcons(const wxIconBundle
& icons
)
233 bool wxTopLevelWindowPalm::EnableCloseButton(bool enable
)
238 FormType
*wxTopLevelWindowPalm::GetForm() const
240 return FrmGetActiveForm();
243 bool wxTopLevelWindowPalm::SetShape(const wxRegion
& region
)
248 // ----------------------------------------------------------------------------
249 // wxTopLevelWindow native event handling
250 // ----------------------------------------------------------------------------
252 bool wxTopLevelWindowPalm::HandleControlSelect(EventType
* event
)
254 int id
= event
->data
.ctlSelect
.controlID
;
256 wxWindow
* win
= FindWindowById(id
,this);
260 wxButton
* button
= wxDynamicCast(win
,wxButton
);
262 return button
->SendClickEvent();
264 wxCheckBox
* checkbox
= wxDynamicCast(win
,wxCheckBox
);
266 return checkbox
->SendClickEvent();
268 wxToggleButton
* toggle
= wxDynamicCast(win
,wxToggleButton
);
270 return toggle
->SendClickEvent();
272 wxRadioButton
* radio
= wxDynamicCast(win
,wxRadioButton
);
274 return radio
->SendClickEvent();
276 wxSlider
* slider
= wxDynamicCast(win
,wxSlider
);
278 return slider
->SendUpdatedEvent();
283 bool wxTopLevelWindowPalm::HandleControlRepeat(EventType
* event
)
285 int id
= event
->data
.ctlRepeat
.controlID
;
287 wxWindow
* win
= FindWindowById(id
,this);
291 wxSlider
* slider
= wxDynamicCast(win
,wxSlider
);
293 return slider
->SendScrollEvent(event
);
298 bool wxTopLevelWindowPalm::HandleSize(EventType
* event
)
300 wxSize
newSize(event
->data
.winResized
.newBounds
.extent
.x
,
301 event
->data
.winResized
.newBounds
.extent
.y
);
302 wxSizeEvent
eventWx(newSize
,GetId());
303 eventWx
.SetEventObject(this);
304 return GetEventHandler()->ProcessEvent(eventWx
);
307 void wxTopLevelWindowPalm::OnActivate(wxActivateEvent
& event
)
311 /* Palm OS Event handler for the window
313 * This function *must* be located outside of the wxTopLevelWindow class because
314 * the Palm OS API expects a standalone C function as a callback. You cannot
315 * pass a pointer to a member function of a C++ class as a callback because the
316 * prototypes don't match. (A member function has a hidden "this" pointer as
317 * its first parameter).
319 * This event handler uses a global pointer to the current wxFrame to process
320 * the events generated by the Palm OS form API. I know this is ugly, but right
321 * now I can't think of any other way to deal with this problem. If someone
322 * finds a better solution, please let me know. My email address is
325 static Boolean
FrameFormHandleEvent(EventType
* event
)
327 // frame and tlw point to the same object but they are for convenience
328 // of calling proper structure withiout later dynamic typcasting
329 wxFrame
* frame
= wxDynamicCast(ActiveParentFrame
,wxFrame
);
330 wxTopLevelWindowPalm
* tlw
= ActiveParentFrame
;
331 Boolean handled
= false;
333 switch (event
->eType
) {
335 handled
= tlw
->HandleControlSelect(event
);
338 handled
= tlw
->HandleControlRepeat(event
);
340 case winResizedEvent
:
341 handled
= tlw
->HandleSize(event
);
343 #if wxUSE_MENUS_NATIVE
345 handled
= frame
->HandleMenuOpen();
348 handled
= frame
->HandleMenuSelect(event
);