]> git.saurik.com Git - wxWidgets.git/blob - src/palmos/toplevel.cpp
wxButton, wxCheckBox, wxSlider, wxToggleButton native implementations for PalmOS.
[wxWidgets.git] / src / palmos / toplevel.cpp
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
6 // Created: 10/13/04
7 // RCS-ID: $Id$
8 // Copyright: (c) William Osborne <wbo@freeshell.org>, Wlodzimierz Skiba
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "toplevel.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/app.h"
33 #include "wx/toplevel.h"
34 #include "wx/dialog.h"
35 #include "wx/string.h"
36 #include "wx/log.h"
37 #include "wx/intl.h"
38 #include "wx/frame.h"
39 #include "wx/containr.h" // wxSetFocusToChild()
40 #endif //WX_PRECOMP
41
42 #include "wx/module.h"
43
44 #include "wx/display.h"
45
46 // ----------------------------------------------------------------------------
47 // globals
48 // ----------------------------------------------------------------------------
49
50 // the name of the default wxWidgets class
51 extern const wxChar *wxCanvasClassName;
52
53 // Pointer to the currently active frame for the form event handler.
54 wxTopLevelWindowPalm* ActiveParentFrame;
55
56 // ============================================================================
57 // wxTopLevelWindowPalm implementation
58 // ============================================================================
59
60 BEGIN_EVENT_TABLE(wxTopLevelWindowPalm, wxTopLevelWindowBase)
61 EVT_ACTIVATE(wxTopLevelWindowPalm::OnActivate)
62 END_EVENT_TABLE()
63
64 // ----------------------------------------------------------------------------
65 // wxTopLevelWindowPalm creation
66 // ----------------------------------------------------------------------------
67
68 void wxTopLevelWindowPalm::Init()
69 {
70 }
71
72 WXDWORD wxTopLevelWindowPalm::PalmGetStyle(long style, WXDWORD *exflags) const
73 {
74 return 0;
75 }
76
77 WXHWND wxTopLevelWindowPalm::PalmGetParent() const
78 {
79 return NULL;
80 }
81
82 bool wxTopLevelWindowPalm::Create(wxWindow *parent,
83 wxWindowID id,
84 const wxString& title,
85 const wxPoint& pos,
86 const wxSize& size,
87 long style,
88 const wxString& name)
89 {
90 // this is a check for limitation mentioned before FrameFormHandleEvent() code
91 if(wxTopLevelWindows.GetCount()>0)
92 return false;
93
94 ActiveParentFrame=NULL;
95
96 wxTopLevelWindows.Append(this);
97
98 if ( parent )
99 parent->AddChild(this);
100
101 m_windowId = id == wxID_ANY ? NewControlId() : id;
102
103 WinConstraintsType constraints;
104 memset(&constraints, 0, sizeof(WinConstraintsType));
105 constraints.x_pos = ( pos.x == wxDefaultCoord ) ? winUndefConstraint : pos.x;
106 constraints.y_pos = ( pos.y == wxDefaultCoord ) ? winUndefConstraint : pos.y;
107 constraints.x_min = winUndefConstraint;
108 constraints.x_max = winMaxConstraint;
109 constraints.x_pref = ( size.x == wxDefaultCoord ) ? winUndefConstraint : size.x;
110 constraints.y_min = winUndefConstraint;
111 constraints.y_max = winMaxConstraint;
112 constraints.y_pref = ( size.y == wxDefaultCoord ) ? winUndefConstraint : size.y;
113
114 FrameForm = FrmNewFormWithConstraints(
115 m_windowId,
116 title.c_str(),
117 winFlagBackBuffer,
118 &constraints,
119 0,
120 NULL,
121 0,
122 NULL,
123 0
124 );
125
126 if(FrameForm==NULL)
127 return false;
128
129 FrmSetEventHandler(FrameForm,FrameFormHandleEvent);
130
131 FrmSetActiveForm(FrameForm);
132
133 ActiveParentFrame=this;
134
135 return true;
136 }
137
138 wxTopLevelWindowPalm::~wxTopLevelWindowPalm()
139 {
140 }
141
142 // ----------------------------------------------------------------------------
143 // wxTopLevelWindowPalm showing
144 // ----------------------------------------------------------------------------
145
146 void wxTopLevelWindowPalm::DoShowWindow(int nShowCmd)
147 {
148 }
149
150 bool wxTopLevelWindowPalm::Show(bool show)
151 {
152 FrmDrawForm(FrameForm);
153
154 wxPaintEvent event(m_windowId);
155 event.SetEventObject(this);
156 GetEventHandler()->ProcessEvent(event);
157
158 return true;
159 }
160
161 // ----------------------------------------------------------------------------
162 // wxTopLevelWindowPalm maximize/minimize
163 // ----------------------------------------------------------------------------
164
165 void wxTopLevelWindowPalm::Maximize(bool maximize)
166 {
167 }
168
169 bool wxTopLevelWindowPalm::IsMaximized() const
170 {
171 return false;
172 }
173
174 void wxTopLevelWindowPalm::Iconize(bool iconize)
175 {
176 }
177
178 bool wxTopLevelWindowPalm::IsIconized() const
179 {
180 return false;
181 }
182
183 void wxTopLevelWindowPalm::Restore()
184 {
185 }
186
187 // ----------------------------------------------------------------------------
188 // wxTopLevelWindowPalm fullscreen
189 // ----------------------------------------------------------------------------
190
191 bool wxTopLevelWindowPalm::ShowFullScreen(bool show, long style)
192 {
193 return false;
194 }
195
196 // ----------------------------------------------------------------------------
197 // wxTopLevelWindowPalm misc
198 // ----------------------------------------------------------------------------
199
200 void wxTopLevelWindowPalm::SetIcon(const wxIcon& icon)
201 {
202 }
203
204 void wxTopLevelWindowPalm::SetIcons(const wxIconBundle& icons)
205 {
206 }
207
208 bool wxTopLevelWindowPalm::EnableCloseButton(bool enable)
209 {
210 return false;
211 }
212
213 FormType *wxTopLevelWindowPalm::GetForm()
214 {
215 return FrmGetActiveForm ();
216 }
217
218 #ifndef __WXWINCE__
219
220 bool wxTopLevelWindowPalm::SetShape(const wxRegion& region)
221 {
222 return false;
223 }
224
225 #endif // !__WXWINCE__
226
227 // ----------------------------------------------------------------------------
228 // wxTopLevelWindow event handling
229 // ----------------------------------------------------------------------------
230
231 void wxTopLevelWindowPalm::OnActivate(wxActivateEvent& event)
232 {
233 }
234
235 /* Palm OS Event handler for the window
236 *
237 * This function *must* be located outside of the wxTopLevelWindow class because
238 * the Palm OS API expects a standalone C function as a callback. You cannot
239 * pass a pointer to a member function of a C++ class as a callback because the
240 * prototypes don't match. (A member function has a hidden "this" pointer as
241 * its first parameter).
242 *
243 * This event handler uses a global pointer to the current wxFrame to process
244 * the events generated by the Palm OS form API. I know this is ugly, but right
245 * now I can't think of any other way to deal with this problem. If someone
246 * finds a better solution, please let me know. My email address is
247 * wbo@freeshell.org
248 */
249 static Boolean FrameFormHandleEvent(EventType* pEvent)
250 {
251 wxFrame* frame = wxDynamicCast(ActiveParentFrame,wxFrame);
252 Boolean fHandled = false;
253 FormType* pForm;
254 WinHandle hWindow;
255 int ItemID=0;
256
257 switch (pEvent->eType) {
258 case ctlSelectEvent:
259 break;
260 #if wxUSE_MENUS_NATIVE
261 case menuOpenEvent:
262 fHandled = frame->HandleMenuOpen();
263 break;
264 case menuEvent:
265 ItemID = pEvent->data.menu.itemID;
266 fHandled = frame->HandleMenuSelect(ItemID);
267 break;
268 #endif
269 default:
270 break;
271 }
272
273 return fHandled;
274 }