]> git.saurik.com Git - wxWidgets.git/blob - src/palmos/toplevel.cpp
getting rid of redundant redraws
[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 #include "wx/display.h"
44
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
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.
60 wxTopLevelWindowPalm* ActiveParentFrame;
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 bool wxTopLevelWindowPalm::Create(wxWindow *parent,
84 wxWindowID id,
85 const wxString& title,
86 const wxPoint& pos,
87 const wxSize& size,
88 long style,
89 const wxString& name)
90 {
91 // this is a check for limitation mentioned before FrameFormHandleEvent() code
92 if(wxTopLevelWindows.GetCount()>0)
93 return false;
94
95 ActiveParentFrame=NULL;
96
97 wxTopLevelWindows.Append(this);
98
99 if ( parent )
100 parent->AddChild(this);
101
102 SetId( id == wxID_ANY ? NewControlId() : id );
103
104 WinConstraintsType constraints;
105 memset(&constraints, 0, sizeof(WinConstraintsType));
106 // position
107 constraints.x_pos = ( pos.x == wxDefaultCoord ) ? winUndefConstraint : pos.x;
108 constraints.y_pos = ( pos.y == wxDefaultCoord ) ? winUndefConstraint : pos.y;
109 // size
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;
116
117 FrameForm = FrmNewFormWithConstraints(
118 GetId(),
119 title.c_str(),
120 winFlagBackBuffer,
121 &constraints,
122 0,
123 NULL,
124 0,
125 NULL,
126 0
127 );
128
129 if(FrameForm==NULL)
130 return false;
131
132 FrmSetEventHandler(FrameForm,FrameFormHandleEvent);
133
134 FrmSetActiveForm(FrameForm);
135
136 ActiveParentFrame=this;
137
138 return true;
139 }
140
141 wxTopLevelWindowPalm::~wxTopLevelWindowPalm()
142 {
143 }
144
145 // ---------------------------------------------------------------------------
146 // implementation
147 // ---------------------------------------------------------------------------
148
149 WXWINHANDLE wxTopLevelWindowPalm::GetWinHandle() const
150 {
151 FormType *form = GetForm();
152 if(form)
153 return FrmGetWindowHandle(form);
154 return 0;
155 }
156
157 // ----------------------------------------------------------------------------
158 // wxTopLevelWindowPalm showing
159 // ----------------------------------------------------------------------------
160
161 void wxTopLevelWindowPalm::DoShowWindow(int nShowCmd)
162 {
163 }
164
165 bool wxTopLevelWindowPalm::Show(bool show)
166 {
167 FrmDrawForm(FrameForm);
168
169 wxPaintEvent event(m_windowId);
170 event.SetEventObject(this);
171 GetEventHandler()->ProcessEvent(event);
172
173 return true;
174 }
175
176 // ----------------------------------------------------------------------------
177 // wxTopLevelWindowPalm maximize/minimize
178 // ----------------------------------------------------------------------------
179
180 void wxTopLevelWindowPalm::Maximize(bool maximize)
181 {
182 }
183
184 bool wxTopLevelWindowPalm::IsMaximized() const
185 {
186 return false;
187 }
188
189 void wxTopLevelWindowPalm::Iconize(bool iconize)
190 {
191 }
192
193 bool wxTopLevelWindowPalm::IsIconized() const
194 {
195 return false;
196 }
197
198 void wxTopLevelWindowPalm::Restore()
199 {
200 }
201
202 void wxTopLevelWindowPalm::DoGetSize( int *width, int *height ) const
203 {
204 RectangleType rect;
205 FrmGetFormBounds( GetForm() , &rect );
206 if(width)
207 *width = rect.extent.x;
208 if(height)
209 *height = rect.extent.y;
210 }
211
212 // ----------------------------------------------------------------------------
213 // wxTopLevelWindowPalm fullscreen
214 // ----------------------------------------------------------------------------
215
216 bool wxTopLevelWindowPalm::ShowFullScreen(bool show, long style)
217 {
218 return false;
219 }
220
221 // ----------------------------------------------------------------------------
222 // wxTopLevelWindowPalm misc
223 // ----------------------------------------------------------------------------
224
225 void wxTopLevelWindowPalm::SetIcon(const wxIcon& icon)
226 {
227 }
228
229 void wxTopLevelWindowPalm::SetIcons(const wxIconBundle& icons)
230 {
231 }
232
233 bool wxTopLevelWindowPalm::EnableCloseButton(bool enable)
234 {
235 return false;
236 }
237
238 FormType *wxTopLevelWindowPalm::GetForm() const
239 {
240 return FrmGetActiveForm();
241 }
242
243 bool wxTopLevelWindowPalm::SetShape(const wxRegion& region)
244 {
245 return false;
246 }
247
248 // ----------------------------------------------------------------------------
249 // wxTopLevelWindow native event handling
250 // ----------------------------------------------------------------------------
251
252 bool wxTopLevelWindowPalm::HandleControlSelect(EventType* event)
253 {
254 int id = event->data.ctlSelect.controlID;
255
256 wxWindow* win = FindWindowById(id,this);
257 if(win==NULL)
258 return false;
259
260 wxButton* button = wxDynamicCast(win,wxButton);
261 if(button)
262 return button->SendClickEvent();
263
264 wxCheckBox* checkbox = wxDynamicCast(win,wxCheckBox);
265 if(checkbox)
266 return checkbox->SendClickEvent();
267
268 wxToggleButton* toggle = wxDynamicCast(win,wxToggleButton);
269 if(toggle)
270 return toggle->SendClickEvent();
271
272 wxRadioButton* radio = wxDynamicCast(win,wxRadioButton);
273 if(radio)
274 return radio->SendClickEvent();
275
276 wxSlider* slider = wxDynamicCast(win,wxSlider);
277 if(slider)
278 return slider->SendUpdatedEvent();
279
280 return false;
281 }
282
283 bool wxTopLevelWindowPalm::HandleControlRepeat(EventType* event)
284 {
285 int id = event->data.ctlRepeat.controlID;
286
287 wxWindow* win = FindWindowById(id,this);
288 if(win==NULL)
289 return false;
290
291 wxSlider* slider = wxDynamicCast(win,wxSlider);
292 if(slider)
293 return slider->SendScrollEvent(event);
294
295 return false;
296 }
297
298 bool wxTopLevelWindowPalm::HandleSize(EventType* event)
299 {
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);
305 }
306
307 void wxTopLevelWindowPalm::OnActivate(wxActivateEvent& event)
308 {
309 }
310
311 /* Palm OS Event handler for the window
312 *
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).
318 *
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
323 * wbo@freeshell.org
324 */
325 static Boolean FrameFormHandleEvent(EventType* event)
326 {
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;
332
333 switch (event->eType) {
334 case ctlSelectEvent:
335 handled = tlw->HandleControlSelect(event);
336 break;
337 case ctlRepeatEvent:
338 handled = tlw->HandleControlRepeat(event);
339 break;
340 case winResizedEvent:
341 handled = tlw->HandleSize(event);
342 break;
343 #if wxUSE_MENUS_NATIVE
344 case menuOpenEvent:
345 handled = frame->HandleMenuOpen();
346 break;
347 case menuEvent:
348 handled = frame->HandleMenuSelect(event);
349 break;
350 #endif
351 default:
352 break;
353 }
354
355 return handled;
356 }