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"
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
57 // the name of the default wxWidgets class
58 extern const wxChar
*wxCanvasClassName
;
60 // Pointer to the currently active frame for the form event handler.
61 wxTopLevelWindowPalm
* ActiveParentFrame
;
63 // ============================================================================
64 // wxTopLevelWindowPalm implementation
65 // ============================================================================
67 BEGIN_EVENT_TABLE(wxTopLevelWindowPalm
, wxTopLevelWindowBase
)
68 EVT_ACTIVATE(wxTopLevelWindowPalm::OnActivate
)
71 // ----------------------------------------------------------------------------
72 // wxTopLevelWindowPalm creation
73 // ----------------------------------------------------------------------------
75 void wxTopLevelWindowPalm::Init()
79 WXDWORD
wxTopLevelWindowPalm::PalmGetStyle(long style
, WXDWORD
*exflags
) const
84 bool wxTopLevelWindowPalm::Create(wxWindow
*parent
,
86 const wxString
& title
,
92 // this is a check for limitation mentioned before FrameFormHandleEvent() code
93 if(wxTopLevelWindows
.GetCount()>0)
96 ActiveParentFrame
=NULL
;
98 wxTopLevelWindows
.Append(this);
101 parent
->AddChild(this);
103 SetId( id
== wxID_ANY
? NewControlId() : id
);
105 WinConstraintsType constraints
;
106 memset(&constraints
, 0, sizeof(WinConstraintsType
));
108 constraints
.x_pos
= ( pos
.x
== wxDefaultCoord
) ? winUndefConstraint
: pos
.x
;
109 constraints
.y_pos
= ( pos
.y
== wxDefaultCoord
) ? winUndefConstraint
: pos
.y
;
111 constraints
.x_min
= winUndefConstraint
;
112 constraints
.x_max
= winMaxConstraint
;
113 constraints
.x_pref
= ( size
.x
== wxDefaultCoord
) ? winUndefConstraint
: size
.x
;
114 constraints
.y_min
= winUndefConstraint
;
115 constraints
.y_max
= winMaxConstraint
;
116 constraints
.y_pref
= ( size
.y
== wxDefaultCoord
) ? winUndefConstraint
: size
.y
;
118 FrameForm
= FrmNewFormWithConstraints(
133 FrmSetEventHandler(FrameForm
,FrameFormHandleEvent
);
135 FrmSetActiveForm(FrameForm
);
137 ActiveParentFrame
=this;
142 wxTopLevelWindowPalm::~wxTopLevelWindowPalm()
146 // ---------------------------------------------------------------------------
148 // ---------------------------------------------------------------------------
150 WXWINHANDLE
wxTopLevelWindowPalm::GetWinHandle() const
152 FormType
*form
= GetForm();
154 return FrmGetWindowHandle(form
);
158 // ----------------------------------------------------------------------------
159 // wxTopLevelWindowPalm showing
160 // ----------------------------------------------------------------------------
162 void wxTopLevelWindowPalm::DoShowWindow(int nShowCmd
)
166 bool wxTopLevelWindowPalm::Show(bool show
)
168 FrmDrawForm(FrameForm
);
170 wxPaintEvent
event(m_windowId
);
171 event
.SetEventObject(this);
172 GetEventHandler()->ProcessEvent(event
);
177 // ----------------------------------------------------------------------------
178 // wxTopLevelWindowPalm maximize/minimize
179 // ----------------------------------------------------------------------------
181 void wxTopLevelWindowPalm::Maximize(bool maximize
)
185 bool wxTopLevelWindowPalm::IsMaximized() const
190 void wxTopLevelWindowPalm::Iconize(bool iconize
)
194 bool wxTopLevelWindowPalm::IsIconized() const
199 void wxTopLevelWindowPalm::Restore()
203 void wxTopLevelWindowPalm::DoGetSize( int *width
, int *height
) const
206 FrmGetFormBounds( GetForm() , &rect
);
208 *width
= rect
.extent
.x
;
210 *height
= rect
.extent
.y
;
213 // ----------------------------------------------------------------------------
214 // wxTopLevelWindowPalm fullscreen
215 // ----------------------------------------------------------------------------
217 bool wxTopLevelWindowPalm::ShowFullScreen(bool show
, long style
)
222 // ----------------------------------------------------------------------------
223 // wxTopLevelWindowPalm misc
224 // ----------------------------------------------------------------------------
226 void wxTopLevelWindowPalm::SetIcon(const wxIcon
& icon
)
230 void wxTopLevelWindowPalm::SetIcons(const wxIconBundle
& icons
)
234 bool wxTopLevelWindowPalm::EnableCloseButton(bool enable
)
239 FormType
*wxTopLevelWindowPalm::GetForm() const
241 return FrmGetActiveForm();
244 bool wxTopLevelWindowPalm::SetShape(const wxRegion
& region
)
249 // ----------------------------------------------------------------------------
250 // wxTopLevelWindow native event handling
251 // ----------------------------------------------------------------------------
253 bool wxTopLevelWindowPalm::HandleControlSelect(EventType
* event
)
255 int id
= event
->data
.ctlSelect
.controlID
;
257 wxWindow
* win
= FindWindowById(id
,this);
262 wxButton
* button
= wxDynamicCast(win
,wxButton
);
264 return button
->SendClickEvent();
265 #endif // wxUSE_BUTTON
268 wxCheckBox
* checkbox
= wxDynamicCast(win
,wxCheckBox
);
270 return checkbox
->SendClickEvent();
271 #endif // wxUSE_CHECKBOX
274 wxToggleButton
* toggle
= wxDynamicCast(win
,wxToggleButton
);
276 return toggle
->SendClickEvent();
277 #endif // wxUSE_TOGGLEBTN
280 wxRadioButton
* radio
= wxDynamicCast(win
,wxRadioButton
);
282 return radio
->SendClickEvent();
283 #endif // wxUSE_RADIOBTN
285 #if wxUSE_DATEPICKCTRL
286 wxDatePickerCtrl
* datepicker
= wxDynamicCast(win
,wxDatePickerCtrl
);
288 return datepicker
->SendClickEvent();
289 #endif // wxUSE_DATEPICKCTRL
292 wxSlider
* slider
= wxDynamicCast(win
,wxSlider
);
294 return slider
->SendUpdatedEvent();
295 #endif // wxUSE_SLIDER
300 bool wxTopLevelWindowPalm::HandleControlRepeat(EventType
* event
)
302 int id
= event
->data
.ctlRepeat
.controlID
;
304 wxWindow
* win
= FindWindowById(id
,this);
309 wxSlider
* slider
= wxDynamicCast(win
,wxSlider
);
311 return slider
->SendScrollEvent(event
);
312 #endif // wxUSE_SLIDER
317 bool wxTopLevelWindowPalm::HandleSize(EventType
* event
)
319 wxSize
newSize(event
->data
.winResized
.newBounds
.extent
.x
,
320 event
->data
.winResized
.newBounds
.extent
.y
);
321 wxSizeEvent
eventWx(newSize
,GetId());
322 eventWx
.SetEventObject(this);
323 return GetEventHandler()->ProcessEvent(eventWx
);
326 void wxTopLevelWindowPalm::OnActivate(wxActivateEvent
& event
)
330 /* Palm OS Event handler for the window
332 * This function *must* be located outside of the wxTopLevelWindow class because
333 * the Palm OS API expects a standalone C function as a callback. You cannot
334 * pass a pointer to a member function of a C++ class as a callback because the
335 * prototypes don't match. (A member function has a hidden "this" pointer as
336 * its first parameter).
338 * This event handler uses a global pointer to the current wxFrame to process
339 * the events generated by the Palm OS form API. I know this is ugly, but right
340 * now I can't think of any other way to deal with this problem. If someone
341 * finds a better solution, please let me know. My email address is
344 static Boolean
FrameFormHandleEvent(EventType
* event
)
346 // frame and tlw point to the same object but they are for convenience
347 // of calling proper structure withiout later dynamic typcasting
348 wxFrame
* frame
= wxDynamicCast(ActiveParentFrame
,wxFrame
);
349 wxTopLevelWindowPalm
* tlw
= ActiveParentFrame
;
350 Boolean handled
= false;
352 switch (event
->eType
) {
354 handled
= tlw
->HandleControlSelect(event
);
357 handled
= tlw
->HandleControlRepeat(event
);
359 case winResizedEvent
:
360 handled
= tlw
->HandleSize(event
);
362 #if wxUSE_MENUS_NATIVE
364 handled
= frame
->HandleMenuOpen();
367 handled
= frame
->HandleMenuSelect(event
);