]>
Commit | Line | Data |
---|---|---|
ffecfa5a | 1 | /////////////////////////////////////////////////////////////////////////////// |
e9c52a40 | 2 | // Name: src/palmos/toplevel.cpp |
ffecfa5a | 3 | // Purpose: implements wxTopLevelWindow for Palm OS |
e9c52a40 WS |
4 | // Author: William Osborne - minimal working wxPalmOS port |
5 | // Modified by: Wlodzimierz ABX Skiba - more than minimal functionality | |
ffecfa5a | 6 | // Created: 10/13/04 |
e9c52a40 WS |
7 | // RCS-ID: $Id$ |
8 | // Copyright: (c) William Osborne <wbo@freeshell.org>, Wlodzimierz Skiba | |
ffecfa5a JS |
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" | |
ffecfa5a JS |
43 | #include "wx/display.h" |
44 | ||
a152561c WS |
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" | |
9a727a3b | 50 | #include "wx/slider.h" |
a152561c | 51 | |
ffecfa5a JS |
52 | // ---------------------------------------------------------------------------- |
53 | // globals | |
54 | // ---------------------------------------------------------------------------- | |
55 | ||
56 | // the name of the default wxWidgets class | |
57 | extern const wxChar *wxCanvasClassName; | |
58 | ||
59 | // Pointer to the currently active frame for the form event handler. | |
db101bd3 | 60 | wxTopLevelWindowPalm* ActiveParentFrame; |
ffecfa5a JS |
61 | |
62 | // ============================================================================ | |
63 | // wxTopLevelWindowPalm implementation | |
64 | // ============================================================================ | |
65 | ||
66 | BEGIN_EVENT_TABLE(wxTopLevelWindowPalm, wxTopLevelWindowBase) | |
67 | EVT_ACTIVATE(wxTopLevelWindowPalm::OnActivate) | |
68 | END_EVENT_TABLE() | |
69 | ||
70 | // ---------------------------------------------------------------------------- | |
71 | // wxTopLevelWindowPalm creation | |
72 | // ---------------------------------------------------------------------------- | |
73 | ||
74 | void wxTopLevelWindowPalm::Init() | |
75 | { | |
76 | } | |
77 | ||
78 | WXDWORD wxTopLevelWindowPalm::PalmGetStyle(long style, WXDWORD *exflags) const | |
79 | { | |
80 | return 0; | |
81 | } | |
82 | ||
83 | WXHWND wxTopLevelWindowPalm::PalmGetParent() const | |
84 | { | |
85 | return NULL; | |
86 | } | |
87 | ||
ffecfa5a | 88 | bool wxTopLevelWindowPalm::Create(wxWindow *parent, |
e9c52a40 WS |
89 | wxWindowID id, |
90 | const wxString& title, | |
91 | const wxPoint& pos, | |
92 | const wxSize& size, | |
93 | long style, | |
94 | const wxString& name) | |
ffecfa5a | 95 | { |
db101bd3 WS |
96 | // this is a check for limitation mentioned before FrameFormHandleEvent() code |
97 | if(wxTopLevelWindows.GetCount()>0) | |
ffecfa5a JS |
98 | return false; |
99 | ||
db101bd3 | 100 | ActiveParentFrame=NULL; |
ffecfa5a | 101 | |
ffecfa5a JS |
102 | wxTopLevelWindows.Append(this); |
103 | ||
104 | if ( parent ) | |
105 | parent->AddChild(this); | |
106 | ||
ba889513 | 107 | SetId( id == wxID_ANY ? NewControlId() : id ); |
ffecfa5a | 108 | |
db101bd3 WS |
109 | WinConstraintsType constraints; |
110 | memset(&constraints, 0, sizeof(WinConstraintsType)); | |
ba889513 | 111 | // position |
db101bd3 WS |
112 | constraints.x_pos = ( pos.x == wxDefaultCoord ) ? winUndefConstraint : pos.x; |
113 | constraints.y_pos = ( pos.y == wxDefaultCoord ) ? winUndefConstraint : pos.y; | |
ba889513 | 114 | // size |
db101bd3 WS |
115 | constraints.x_min = winUndefConstraint; |
116 | constraints.x_max = winMaxConstraint; | |
117 | constraints.x_pref = ( size.x == wxDefaultCoord ) ? winUndefConstraint : size.x; | |
118 | constraints.y_min = winUndefConstraint; | |
119 | constraints.y_max = winMaxConstraint; | |
120 | constraints.y_pref = ( size.y == wxDefaultCoord ) ? winUndefConstraint : size.y; | |
121 | ||
122 | FrameForm = FrmNewFormWithConstraints( | |
ba889513 | 123 | GetId(), |
db101bd3 WS |
124 | title.c_str(), |
125 | winFlagBackBuffer, | |
126 | &constraints, | |
127 | 0, | |
128 | NULL, | |
129 | 0, | |
130 | NULL, | |
131 | 0 | |
132 | ); | |
133 | ||
134 | if(FrameForm==NULL) | |
ffecfa5a JS |
135 | return false; |
136 | ||
137 | FrmSetEventHandler(FrameForm,FrameFormHandleEvent); | |
e9c52a40 | 138 | |
ffecfa5a | 139 | FrmSetActiveForm(FrameForm); |
e9c52a40 | 140 | |
db101bd3 | 141 | ActiveParentFrame=this; |
e9c52a40 | 142 | |
ffecfa5a JS |
143 | return true; |
144 | } | |
145 | ||
146 | wxTopLevelWindowPalm::~wxTopLevelWindowPalm() | |
147 | { | |
148 | } | |
149 | ||
150 | // ---------------------------------------------------------------------------- | |
151 | // wxTopLevelWindowPalm showing | |
152 | // ---------------------------------------------------------------------------- | |
153 | ||
154 | void wxTopLevelWindowPalm::DoShowWindow(int nShowCmd) | |
155 | { | |
156 | } | |
157 | ||
158 | bool wxTopLevelWindowPalm::Show(bool show) | |
159 | { | |
160 | FrmDrawForm(FrameForm); | |
e9c52a40 | 161 | |
ffecfa5a JS |
162 | wxPaintEvent event(m_windowId); |
163 | event.SetEventObject(this); | |
e9c52a40 WS |
164 | GetEventHandler()->ProcessEvent(event); |
165 | ||
ffecfa5a JS |
166 | return true; |
167 | } | |
168 | ||
169 | // ---------------------------------------------------------------------------- | |
170 | // wxTopLevelWindowPalm maximize/minimize | |
171 | // ---------------------------------------------------------------------------- | |
172 | ||
173 | void wxTopLevelWindowPalm::Maximize(bool maximize) | |
174 | { | |
175 | } | |
176 | ||
177 | bool wxTopLevelWindowPalm::IsMaximized() const | |
178 | { | |
179 | return false; | |
180 | } | |
181 | ||
182 | void wxTopLevelWindowPalm::Iconize(bool iconize) | |
183 | { | |
184 | } | |
185 | ||
186 | bool wxTopLevelWindowPalm::IsIconized() const | |
187 | { | |
188 | return false; | |
189 | } | |
190 | ||
191 | void wxTopLevelWindowPalm::Restore() | |
192 | { | |
193 | } | |
194 | ||
808e3bce WS |
195 | void wxTopLevelWindowPalm::DoGetSize( int *width, int *height ) const |
196 | { | |
197 | RectangleType rect; | |
198 | FrmGetFormBounds( GetForm() , &rect ); | |
199 | if(width) | |
200 | *width = rect.extent.x; | |
201 | if(height) | |
202 | *height = rect.extent.y; | |
203 | } | |
204 | ||
ffecfa5a JS |
205 | // ---------------------------------------------------------------------------- |
206 | // wxTopLevelWindowPalm fullscreen | |
207 | // ---------------------------------------------------------------------------- | |
208 | ||
209 | bool wxTopLevelWindowPalm::ShowFullScreen(bool show, long style) | |
210 | { | |
211 | return false; | |
212 | } | |
213 | ||
214 | // ---------------------------------------------------------------------------- | |
215 | // wxTopLevelWindowPalm misc | |
216 | // ---------------------------------------------------------------------------- | |
217 | ||
218 | void wxTopLevelWindowPalm::SetIcon(const wxIcon& icon) | |
219 | { | |
220 | } | |
221 | ||
222 | void wxTopLevelWindowPalm::SetIcons(const wxIconBundle& icons) | |
223 | { | |
224 | } | |
225 | ||
226 | bool wxTopLevelWindowPalm::EnableCloseButton(bool enable) | |
227 | { | |
228 | return false; | |
229 | } | |
230 | ||
808e3bce | 231 | FormType *wxTopLevelWindowPalm::GetForm() const |
bdb54365 | 232 | { |
808e3bce | 233 | return FrmGetActiveForm(); |
bdb54365 WS |
234 | } |
235 | ||
ffecfa5a JS |
236 | #ifndef __WXWINCE__ |
237 | ||
238 | bool wxTopLevelWindowPalm::SetShape(const wxRegion& region) | |
239 | { | |
240 | return false; | |
241 | } | |
242 | ||
243 | #endif // !__WXWINCE__ | |
244 | ||
245 | // ---------------------------------------------------------------------------- | |
246 | // wxTopLevelWindow event handling | |
247 | // ---------------------------------------------------------------------------- | |
248 | ||
a152561c WS |
249 | bool wxTopLevelWindowPalm::HandleControlSelect(EventType* event) |
250 | { | |
251 | int id = event->data.ctlSelect.controlID; | |
252 | wxWindow* win = FindWindowById(id,this); | |
253 | if(win==NULL) | |
254 | return false; | |
255 | ||
256 | wxButton* button = wxDynamicCast(win,wxButton); | |
257 | if(button) | |
258 | return button->SendClickEvent(); | |
259 | ||
260 | wxCheckBox* checkbox = wxDynamicCast(win,wxCheckBox); | |
261 | if(checkbox) | |
262 | return checkbox->SendClickEvent(); | |
263 | ||
264 | wxToggleButton* toggle = wxDynamicCast(win,wxToggleButton); | |
265 | if(toggle) | |
266 | return toggle->SendClickEvent(); | |
267 | ||
268 | wxRadioButton* radio = wxDynamicCast(win,wxRadioButton); | |
269 | if(radio) | |
270 | return radio->SendClickEvent(); | |
271 | ||
9a727a3b WS |
272 | wxSlider* slider = wxDynamicCast(win,wxSlider); |
273 | if(slider) | |
274 | return slider->SendUpdatedEvent(); | |
275 | ||
a152561c WS |
276 | return false; |
277 | } | |
278 | ||
ffecfa5a JS |
279 | void wxTopLevelWindowPalm::OnActivate(wxActivateEvent& event) |
280 | { | |
281 | } | |
282 | ||
283 | /* Palm OS Event handler for the window | |
e9c52a40 WS |
284 | * |
285 | * This function *must* be located outside of the wxTopLevelWindow class because | |
e2731512 WS |
286 | * the Palm OS API expects a standalone C function as a callback. You cannot |
287 | * pass a pointer to a member function of a C++ class as a callback because the | |
288 | * prototypes don't match. (A member function has a hidden "this" pointer as | |
ffecfa5a | 289 | * its first parameter). |
e2731512 WS |
290 | * |
291 | * This event handler uses a global pointer to the current wxFrame to process | |
292 | * the events generated by the Palm OS form API. I know this is ugly, but right | |
293 | * now I can't think of any other way to deal with this problem. If someone | |
294 | * finds a better solution, please let me know. My email address is | |
ffecfa5a JS |
295 | * wbo@freeshell.org |
296 | */ | |
a152561c | 297 | static Boolean FrameFormHandleEvent(EventType* event) |
ffecfa5a | 298 | { |
db101bd3 | 299 | wxFrame* frame = wxDynamicCast(ActiveParentFrame,wxFrame); |
a152561c | 300 | Boolean handled = false; |
e2731512 | 301 | |
a152561c | 302 | switch (event->eType) { |
ffecfa5a | 303 | case ctlSelectEvent: |
a152561c | 304 | handled = frame->HandleControlSelect(event); |
ffecfa5a JS |
305 | break; |
306 | #if wxUSE_MENUS_NATIVE | |
307 | case menuOpenEvent: | |
a152561c | 308 | handled = frame->HandleMenuOpen(); |
e2731512 | 309 | break; |
ffecfa5a | 310 | case menuEvent: |
a152561c | 311 | handled = frame->HandleMenuSelect(event); |
ffecfa5a JS |
312 | break; |
313 | #endif | |
314 | default: | |
315 | break; | |
316 | } | |
e2731512 | 317 | |
a152561c | 318 | return handled; |
ffecfa5a | 319 | } |