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 // For compilers that support precompilation, includes "wx.h". 
  21 #include "wx/wxprec.h" 
  27 #include "wx/toplevel.h" 
  31     #include "wx/dialog.h" 
  32     #include "wx/string.h" 
  36     #include "wx/containr.h"        // wxSetFocusToChild() 
  37     #include "wx/button.h" 
  38     #include "wx/checkbox.h" 
  39     #include "wx/radiobut.h" 
  40     #include "wx/slider.h" 
  41     #include "wx/module.h" 
  44 #include "wx/display.h" 
  46 // controls for sending select event 
  47 #include "wx/tglbtn.h" 
  48 #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 static Boolean 
FrameFormHandleEvent(EventType 
*event
); 
  65 // ============================================================================ 
  66 // wxTopLevelWindowPalm implementation 
  67 // ============================================================================ 
  69 BEGIN_EVENT_TABLE(wxTopLevelWindowPalm
, wxTopLevelWindowBase
) 
  70     EVT_ACTIVATE(wxTopLevelWindowPalm::OnActivate
) 
  73 // ---------------------------------------------------------------------------- 
  74 // wxTopLevelWindowPalm creation 
  75 // ---------------------------------------------------------------------------- 
  77 void wxTopLevelWindowPalm::Init() 
  81 WXDWORD 
wxTopLevelWindowPalm::PalmGetStyle(long style
, WXDWORD 
*exflags
) const 
  86 bool wxTopLevelWindowPalm::Create(wxWindow 
*parent
, 
  88                                   const wxString
& title
, 
  94     // this is a check for limitation mentioned before FrameFormHandleEvent() code 
  95     if(wxTopLevelWindows
.GetCount()>0) 
  98     ActiveParentFrame
=NULL
; 
 100     wxTopLevelWindows
.Append(this); 
 103         parent
->AddChild(this); 
 105     SetId( id 
== wxID_ANY 
? NewControlId() : id 
); 
 107     WinConstraintsType constraints
; 
 108     memset(&constraints
, 0, sizeof(WinConstraintsType
)); 
 110     constraints
.x_pos 
= ( pos
.x 
== wxDefaultCoord 
) ? winUndefConstraint 
: pos
.x
; 
 111     constraints
.y_pos 
= ( pos
.y 
== wxDefaultCoord 
) ? winUndefConstraint 
: pos
.y
; 
 113     constraints
.x_min 
= winUndefConstraint
; 
 114     constraints
.x_max 
= winMaxConstraint
; 
 115     constraints
.x_pref 
= ( size
.x 
== wxDefaultCoord 
) ? winUndefConstraint 
: size
.x
; 
 116     constraints
.y_min 
= winUndefConstraint
; 
 117     constraints
.y_max 
= winMaxConstraint
; 
 118     constraints
.y_pref 
= ( size
.y 
== wxDefaultCoord 
) ? winUndefConstraint 
: size
.y
; 
 120     FrameForm 
= FrmNewFormWithConstraints( 
 135     FrmSetEventHandler((FormType 
*)FrameForm
,FrameFormHandleEvent
); 
 137     FrmSetActiveForm((FormType 
*)FrameForm
); 
 139     ActiveParentFrame
=this; 
 144 wxTopLevelWindowPalm::~wxTopLevelWindowPalm() 
 148 // --------------------------------------------------------------------------- 
 150 // --------------------------------------------------------------------------- 
 152 WXWINHANDLE 
wxTopLevelWindowPalm::GetWinHandle() const 
 154     FormType 
*form 
= (FormType 
*)GetForm(); 
 156         return FrmGetWindowHandle(form
); 
 160 // ---------------------------------------------------------------------------- 
 161 // wxTopLevelWindowPalm showing 
 162 // ---------------------------------------------------------------------------- 
 164 void wxTopLevelWindowPalm::DoShowWindow(int nShowCmd
) 
 168 bool wxTopLevelWindowPalm::Show(bool show
) 
 170     FrmDrawForm((FormType 
*)FrameForm
); 
 172     wxPaintEvent 
event(m_windowId
); 
 173     event
.SetEventObject(this); 
 174     GetEventHandler()->ProcessEvent(event
); 
 179 // ---------------------------------------------------------------------------- 
 180 // wxTopLevelWindowPalm maximize/minimize 
 181 // ---------------------------------------------------------------------------- 
 183 void wxTopLevelWindowPalm::Maximize(bool maximize
) 
 187 bool wxTopLevelWindowPalm::IsMaximized() const 
 192 void wxTopLevelWindowPalm::Iconize(bool iconize
) 
 196 bool wxTopLevelWindowPalm::IsIconized() const 
 201 void wxTopLevelWindowPalm::Restore() 
 205 void wxTopLevelWindowPalm::DoGetSize( int *width
, int *height 
) const 
 208     FrmGetFormBounds( (FormType 
*)GetForm() , &rect 
); 
 210         *width 
= rect
.extent
.x
; 
 212         *height 
= rect
.extent
.y
; 
 215 // ---------------------------------------------------------------------------- 
 216 // wxTopLevelWindowPalm fullscreen 
 217 // ---------------------------------------------------------------------------- 
 219 bool wxTopLevelWindowPalm::ShowFullScreen(bool show
, long style
) 
 224 // ---------------------------------------------------------------------------- 
 225 // wxTopLevelWindowPalm misc 
 226 // ---------------------------------------------------------------------------- 
 228 void wxTopLevelWindowPalm::SetTitle( const wxString
& WXUNUSED(title
)) 
 232 wxString 
wxTopLevelWindowPalm::GetTitle() const 
 234     return wxEmptyString
; 
 237 void wxTopLevelWindowPalm::SetIcon(const wxIcon
& icon
) 
 241 void wxTopLevelWindowPalm::SetIcons(const wxIconBundle
& icons
) 
 245 bool wxTopLevelWindowPalm::EnableCloseButton(bool enable
) 
 250 WXFORMPTR 
wxTopLevelWindowPalm::GetForm() const 
 252     return FrmGetActiveForm(); 
 255 bool wxTopLevelWindowPalm::SetShape(const wxRegion
& region
) 
 260 // ---------------------------------------------------------------------------- 
 261 // wxTopLevelWindow native event handling 
 262 // ---------------------------------------------------------------------------- 
 264 bool wxTopLevelWindowPalm::HandleControlSelect(WXEVENTPTR event
) 
 266     const EventType 
*palmEvent 
= (EventType 
*)event
; 
 267     const int id 
= palmEvent
->data
.ctlSelect
.controlID
; 
 269     wxWindow
* win 
= FindWindowById(id
,this); 
 274     wxButton
* button 
= wxDynamicCast(win
,wxButton
); 
 276         return button
->SendClickEvent(); 
 277 #endif // wxUSE_BUTTON 
 280     wxCheckBox
* checkbox 
= wxDynamicCast(win
,wxCheckBox
); 
 282         return checkbox
->SendClickEvent(); 
 283 #endif // wxUSE_CHECKBOX 
 286     wxToggleButton
* toggle 
= wxDynamicCast(win
,wxToggleButton
); 
 288         return toggle
->SendClickEvent(); 
 289 #endif // wxUSE_TOGGLEBTN 
 292     wxRadioButton
* radio 
= wxDynamicCast(win
,wxRadioButton
); 
 294         return radio
->SendClickEvent(); 
 295 #endif // wxUSE_RADIOBTN 
 297 #if wxUSE_DATEPICKCTRL 
 298     wxDatePickerCtrl
* datepicker 
= wxDynamicCast(win
,wxDatePickerCtrl
); 
 300         return datepicker
->SendClickEvent(); 
 301 #endif // wxUSE_DATEPICKCTRL 
 304     wxSlider
* slider 
= wxDynamicCast(win
,wxSlider
); 
 306         return slider
->SendUpdatedEvent(); 
 307 #endif // wxUSE_SLIDER 
 312 bool wxTopLevelWindowPalm::HandleControlRepeat(WXEVENTPTR event
) 
 314     const EventType 
*palmEvent 
= (EventType 
*)event
; 
 315     const int id 
= palmEvent
->data
.ctlRepeat
.controlID
; 
 317     wxWindow
* win 
= FindWindowById(id
, this); 
 322     wxSlider
* slider 
= wxDynamicCast(win
,wxSlider
); 
 324         return slider
->SendScrollEvent(event
); 
 325 #endif // wxUSE_SLIDER 
 330 bool wxTopLevelWindowPalm::HandleSize(WXEVENTPTR event
) 
 332     const EventType 
*palmEvent 
= (EventType 
*)event
; 
 333     wxSize 
newSize(palmEvent
->data
.winResized
.newBounds
.extent
.x
, 
 334                    palmEvent
->data
.winResized
.newBounds
.extent
.y
); 
 335     wxSizeEvent 
eventWx(newSize
,GetId()); 
 336     eventWx
.SetEventObject(this); 
 337     return GetEventHandler()->ProcessEvent(eventWx
); 
 340 void wxTopLevelWindowPalm::OnActivate(wxActivateEvent
& event
) 
 344 /* Palm OS Event handler for the window 
 346  * This function *must* be located outside of the wxTopLevelWindow class because 
 347  * the Palm OS API expects a standalone C function as a callback.  You cannot 
 348  * pass a pointer to a member function of a C++ class as a callback because the 
 349  * prototypes don't match.  (A member function has a hidden "this" pointer as 
 350  * its first parameter). 
 352  * This event handler uses a global pointer to the current wxFrame to process 
 353  * the events generated by the Palm OS form API.  I know this is ugly, but right 
 354  * now I can't think of any other way to deal with this problem.  If someone 
 355  * finds a better solution, please let me know.  My email address is 
 358 static Boolean 
FrameFormHandleEvent(EventType 
*event
) 
 360     // frame and tlw point to the same object but they are for convenience 
 361     // of calling proper structure withiout later dynamic typcasting 
 362     wxFrame
* frame 
= wxDynamicCast(ActiveParentFrame
,wxFrame
); 
 363     wxTopLevelWindowPalm
* tlw 
= ActiveParentFrame
; 
 364     Boolean     handled 
= false; 
 366     switch (event
->eType
) { 
 368             handled 
= tlw
->HandleControlSelect(event
); 
 371             handled 
= tlw
->HandleControlRepeat(event
); 
 373         case winResizedEvent
: 
 374             handled 
= tlw
->HandleSize(event
); 
 376 #if wxUSE_MENUS_NATIVE 
 378             handled 
= frame
->HandleMenuOpen(); 
 381             handled 
= frame
->HandleMenuSelect(event
);