]>
Commit | Line | Data |
---|---|---|
b3c86150 VS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/dfb/window.cpp | |
3 | // Purpose: wxWindow | |
4 | // Author: Vaclav Slavik | |
5 | // (based on GTK, MSW, MGL implementations) | |
6 | // Created: 2006-80-10 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 2006 REA Elektronik GmbH | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // =========================================================================== | |
13 | // declarations | |
14 | // =========================================================================== | |
15 | ||
16 | // --------------------------------------------------------------------------- | |
17 | // headers | |
18 | // --------------------------------------------------------------------------- | |
19 | ||
20 | // For compilers that support precompilation, includes "wx.h". | |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
27 | #include "wx/window.h" | |
28 | ||
29 | #ifndef WX_PRECOMP | |
30 | #include "wx/dcclient.h" | |
31 | #endif | |
32 | ||
33 | #include "wx/caret.h" | |
34 | ||
35 | #include "wx/dfb/private.h" | |
36 | ||
37 | #define TRACE_EVENTS _T("events") | |
38 | #define TRACE_PAINT _T("paint") | |
39 | ||
40 | // =========================================================================== | |
41 | // implementation | |
42 | // =========================================================================== | |
43 | ||
44 | // --------------------------------------------------------------------------- | |
45 | // global variables | |
46 | // --------------------------------------------------------------------------- | |
47 | ||
48 | // the window that has keyboard focus: | |
49 | static wxWindowDFB *gs_focusedWindow = NULL; | |
50 | // the window that is about to be focused after currently focused | |
51 | // one looses focus: | |
52 | static wxWindow *gs_toBeFocusedWindow = NULL; | |
53 | // the window that has mouse capture | |
54 | static wxWindowDFB *gs_mouseCapture = NULL; | |
55 | ||
56 | // --------------------------------------------------------------------------- | |
57 | // event tables | |
58 | // --------------------------------------------------------------------------- | |
59 | ||
60 | // in wxUniv this class is abstract because it doesn't have DoPopupMenu() | |
61 | IMPLEMENT_ABSTRACT_CLASS(wxWindowDFB, wxWindowBase) | |
62 | ||
63 | BEGIN_EVENT_TABLE(wxWindowDFB, wxWindowBase) | |
64 | END_EVENT_TABLE() | |
65 | ||
66 | // ---------------------------------------------------------------------------- | |
67 | // constructors and such | |
68 | // ---------------------------------------------------------------------------- | |
69 | ||
70 | void wxWindowDFB::Init() | |
71 | { | |
72 | m_isShown = true; | |
73 | m_frozenness = 0; | |
74 | m_tlw = NULL; | |
75 | } | |
76 | ||
77 | // Destructor | |
78 | wxWindowDFB::~wxWindowDFB() | |
79 | { | |
80 | SendDestroyEvent(); | |
81 | ||
82 | m_isBeingDeleted = true; | |
83 | ||
84 | if ( gs_mouseCapture == this ) | |
85 | ReleaseMouse(); | |
86 | ||
87 | #warning "FIXME: what to do with gs_activeFrame here and elsewhere?" | |
88 | #if 0 | |
89 | if (gs_activeFrame == this) | |
90 | { | |
91 | gs_activeFrame = NULL; | |
92 | // activate next frame in Z-order: | |
93 | if ( m_wnd->prev ) | |
94 | { | |
95 | wxWindowDFB *win = (wxWindowDFB*)m_wnd->prev->userData; | |
96 | win->SetFocus(); | |
97 | } | |
98 | else if ( m_wnd->next ) | |
99 | { | |
100 | wxWindowDFB *win = (wxWindowDFB*)m_wnd->next->userData; | |
101 | win->SetFocus(); | |
102 | } | |
103 | } | |
104 | #endif | |
105 | ||
106 | if ( gs_focusedWindow == this ) | |
107 | KillFocus(); | |
108 | ||
109 | DestroyChildren(); | |
110 | } | |
111 | ||
112 | // real construction (Init() must have been called before!) | |
113 | bool wxWindowDFB::Create(wxWindow *parent, | |
114 | wxWindowID id, | |
115 | const wxPoint& pos, | |
116 | const wxSize& size, | |
117 | long style, | |
118 | const wxString& name) | |
119 | { | |
120 | if ( !m_tlw && parent ) | |
121 | m_tlw = parent->GetTLW(); | |
122 | ||
123 | if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) ) | |
124 | return false; | |
125 | ||
126 | if ( parent ) | |
127 | parent->AddChild(this); | |
128 | ||
dbbdd346 VS |
129 | // set the size to something bogus initially, in case some code tries to |
130 | // create wxWindowDC before SetSize() is called below: | |
131 | m_rect.width = m_rect.height = 1; | |
132 | ||
b3c86150 VS |
133 | int x, y, w, h; |
134 | x = pos.x, y = pos.y; | |
135 | if ( x == -1 ) x = 0; | |
136 | if ( y == -1 ) y = 0; | |
137 | w = WidthDefault(size.x); | |
138 | h = HeightDefault(size.y); | |
139 | SetSize(x, y, w, h); | |
140 | ||
141 | return true; | |
142 | } | |
143 | ||
144 | // --------------------------------------------------------------------------- | |
145 | // surface access | |
146 | // --------------------------------------------------------------------------- | |
147 | ||
52c8d32a | 148 | wxIDirectFBSurfacePtr wxWindowDFB::ObtainDfbSurface() const |
b3c86150 VS |
149 | { |
150 | wxCHECK_MSG( m_parent, NULL, _T("parentless window?") ); | |
151 | ||
52c8d32a | 152 | wxIDirectFBSurfacePtr parentSurface(m_parent->GetDfbSurface()); |
b3c86150 VS |
153 | wxCHECK_MSG( parentSurface, NULL, _T("invalid parent surface") ); |
154 | ||
155 | wxRect r(GetRect()); | |
156 | AdjustForParentClientOrigin(r.x, r.y, 0); | |
157 | DFBRectangle rect = { r.x, r.y, r.width, r.height }; | |
158 | ||
52c8d32a | 159 | return parentSurface->GetSubSurface(&rect); |
b3c86150 VS |
160 | } |
161 | ||
52c8d32a | 162 | wxIDirectFBSurfacePtr wxWindowDFB::GetDfbSurface() |
b3c86150 VS |
163 | { |
164 | if ( !m_surface ) | |
165 | { | |
166 | m_surface = ObtainDfbSurface(); | |
167 | wxASSERT_MSG( m_surface, _T("invalid DirectFB surface") ); | |
168 | } | |
169 | ||
170 | return m_surface; | |
171 | } | |
172 | ||
173 | void wxWindowDFB::InvalidateDfbSurface() | |
174 | { | |
175 | m_surface = NULL; | |
176 | } | |
177 | ||
178 | // --------------------------------------------------------------------------- | |
179 | // basic operations | |
180 | // --------------------------------------------------------------------------- | |
181 | ||
182 | void wxWindowDFB::SetFocus() | |
183 | { | |
184 | if ( gs_focusedWindow == this ) return; | |
185 | ||
186 | wxWindowDFB *oldFocusedWindow = gs_focusedWindow; | |
187 | ||
188 | if ( gs_focusedWindow ) | |
189 | { | |
190 | gs_toBeFocusedWindow = (wxWindow*)this; | |
191 | gs_focusedWindow->KillFocus(); | |
192 | gs_toBeFocusedWindow = NULL; | |
193 | } | |
194 | ||
195 | #warning "FIXME: implement in terms of DWET_{GOT,LOST}FOCUS" | |
196 | ||
52c8d32a | 197 | wxIDirectFBWindowPtr dfbwin(m_tlw->GetDirectFBWindow()); |
b3c86150 | 198 | #warning "FIXME: RequestFocus() may only be called on visible TLW" |
52c8d32a | 199 | if ( !dfbwin->RequestFocus() ) |
b3c86150 VS |
200 | return; |
201 | ||
202 | gs_focusedWindow = this; | |
203 | ||
204 | #warning "FIXME: keep this or not? not, think multiapp core" | |
205 | #if 0 | |
206 | wxWindowDFB *active = wxGetTopLevelParent((wxWindow*)this); | |
207 | if ( !(m_windowStyle & wxPOPUP_WINDOW) && active != gs_activeFrame ) | |
208 | { | |
209 | if ( gs_activeFrame ) | |
210 | { | |
211 | wxActivateEvent event(wxEVT_ACTIVATE, false, gs_activeFrame->GetId()); | |
212 | event.SetEventObject(gs_activeFrame); | |
213 | gs_activeFrame->GetEventHandler()->ProcessEvent(event); | |
214 | } | |
215 | ||
216 | gs_activeFrame = active; | |
217 | wxActivateEvent event(wxEVT_ACTIVATE, true, gs_activeFrame->GetId()); | |
218 | event.SetEventObject(gs_activeFrame); | |
219 | gs_activeFrame->GetEventHandler()->ProcessEvent(event); | |
220 | } | |
221 | #endif | |
222 | ||
223 | wxFocusEvent event(wxEVT_SET_FOCUS, GetId()); | |
224 | event.SetEventObject(this); | |
225 | event.SetWindow((wxWindow*)oldFocusedWindow); | |
226 | GetEventHandler()->ProcessEvent(event); | |
227 | ||
228 | #if wxUSE_CARET | |
229 | // caret needs to be informed about focus change | |
230 | wxCaret *caret = GetCaret(); | |
231 | if ( caret ) | |
232 | caret->OnSetFocus(); | |
233 | #endif // wxUSE_CARET | |
234 | } | |
235 | ||
236 | void wxWindowDFB::KillFocus() | |
237 | { | |
238 | if ( gs_focusedWindow != this ) return; | |
239 | gs_focusedWindow = NULL; | |
240 | ||
241 | if ( m_isBeingDeleted ) return; | |
242 | ||
243 | #if wxUSE_CARET | |
244 | // caret needs to be informed about focus change | |
245 | wxCaret *caret = GetCaret(); | |
246 | if ( caret ) | |
247 | caret->OnKillFocus(); | |
248 | #endif // wxUSE_CARET | |
249 | ||
250 | wxFocusEvent event(wxEVT_KILL_FOCUS, GetId()); | |
251 | event.SetEventObject(this); | |
252 | event.SetWindow(gs_toBeFocusedWindow); | |
253 | GetEventHandler()->ProcessEvent(event); | |
254 | } | |
255 | ||
256 | // ---------------------------------------------------------------------------- | |
257 | // this wxWindowBase function is implemented here (in platform-specific file) | |
258 | // because it is static and so couldn't be made virtual | |
259 | // ---------------------------------------------------------------------------- | |
260 | wxWindow *wxWindowBase::DoFindFocus() | |
261 | { | |
262 | return (wxWindow*)gs_focusedWindow; | |
263 | } | |
264 | ||
265 | bool wxWindowDFB::Show(bool show) | |
266 | { | |
267 | if ( !wxWindowBase::Show(show) ) | |
268 | return false; | |
269 | ||
270 | // Unlike Refresh(), DoRefreshWindow() doesn't check visibility, so | |
271 | // call it to force refresh of either this window (if showing) or its | |
272 | // parent area at the place of this window (if hiding): | |
273 | DoRefreshWindow(); | |
274 | ||
275 | #warning "FIXME: all of this must be implemented for DFB" | |
276 | #if 0 | |
277 | DFB_wmShowWindow(m_wnd, show); | |
278 | ||
279 | if (!show && gs_activeFrame == this) | |
280 | { | |
281 | // activate next frame in Z-order: | |
282 | if ( m_wnd->prev ) | |
283 | { | |
284 | wxWindowDFB *win = (wxWindowDFB*)m_wnd->prev->userData; | |
285 | win->SetFocus(); | |
286 | } | |
287 | else if ( m_wnd->next ) | |
288 | { | |
289 | wxWindowDFB *win = (wxWindowDFB*)m_wnd->next->userData; | |
290 | win->SetFocus(); | |
291 | } | |
292 | else | |
293 | { | |
294 | gs_activeFrame = NULL; | |
295 | } | |
296 | } | |
297 | #endif | |
298 | ||
299 | return true; | |
300 | } | |
301 | ||
302 | // Raise the window to the top of the Z order | |
303 | void wxWindowDFB::Raise() | |
304 | { | |
305 | wxFAIL_MSG( _T("Raise() not implemented") ); | |
306 | } | |
307 | ||
308 | // Lower the window to the bottom of the Z order | |
309 | void wxWindowDFB::Lower() | |
310 | { | |
311 | wxFAIL_MSG( _T("Lower() not implemented") ); | |
312 | } | |
313 | ||
314 | void wxWindowDFB::DoCaptureMouse() | |
315 | { | |
316 | #warning "implement this" | |
317 | #if 0 | |
318 | if ( gs_mouseCapture ) | |
319 | DFB_wmUncaptureEvents(gs_mouseCapture->m_wnd, wxDFB_CAPTURE_MOUSE); | |
320 | #endif | |
321 | gs_mouseCapture = this; | |
322 | #if 0 | |
323 | DFB_wmCaptureEvents(m_wnd, EVT_MOUSEEVT, wxDFB_CAPTURE_MOUSE); | |
324 | #endif | |
325 | } | |
326 | ||
327 | void wxWindowDFB::DoReleaseMouse() | |
328 | { | |
329 | wxASSERT_MSG( gs_mouseCapture == this, wxT("attempt to release mouse, but this window hasn't captured it") ); | |
330 | ||
331 | #warning "implement this" | |
332 | #if 0 | |
333 | DFB_wmUncaptureEvents(m_wnd, wxDFB_CAPTURE_MOUSE); | |
334 | #endif | |
335 | gs_mouseCapture = NULL; | |
336 | } | |
337 | ||
338 | /* static */ wxWindow *wxWindowBase::GetCapture() | |
339 | { | |
340 | return (wxWindow*)gs_mouseCapture; | |
341 | } | |
342 | ||
343 | bool wxWindowDFB::SetCursor(const wxCursor& cursor) | |
344 | { | |
345 | if ( !wxWindowBase::SetCursor(cursor) ) | |
346 | { | |
347 | // no change | |
348 | return false; | |
349 | } | |
350 | ||
351 | #warning "implement this" | |
352 | #if 0 | |
353 | if ( m_cursor.Ok() ) | |
354 | DFB_wmSetWindowCursor(m_wnd, *m_cursor.GetDFBCursor()); | |
355 | else | |
356 | DFB_wmSetWindowCursor(m_wnd, *wxSTANDARD_CURSOR->GetDFBCursor()); | |
357 | #endif | |
358 | ||
359 | return true; | |
360 | } | |
361 | ||
362 | void wxWindowDFB::WarpPointer(int x, int y) | |
363 | { | |
364 | int w, h; | |
365 | wxDisplaySize(&w, &h); | |
366 | ||
367 | ClientToScreen(&x, &y); | |
368 | if ( x < 0 ) x = 0; | |
369 | if ( y < 0 ) y = 0; | |
370 | if ( x >= w ) x = w-1; | |
371 | if ( y >= h ) y = h-1; | |
372 | ||
a5b31f4e | 373 | wxIDirectFBDisplayLayerPtr layer(wxIDirectFB::Get()->GetDisplayLayer()); |
b3c86150 VS |
374 | wxCHECK_RET( layer, _T("no display layer") ); |
375 | ||
52c8d32a | 376 | layer->WarpCursor(x, y); |
b3c86150 VS |
377 | } |
378 | ||
379 | // Set this window to be the child of 'parent'. | |
380 | bool wxWindowDFB::Reparent(wxWindowBase *parent) | |
381 | { | |
382 | if ( !wxWindowBase::Reparent(parent) ) | |
383 | return false; | |
384 | ||
385 | #warning "implement this" | |
386 | wxFAIL_MSG( _T("reparenting not yet implemented") ); | |
387 | ||
388 | return true; | |
389 | } | |
390 | ||
391 | // --------------------------------------------------------------------------- | |
392 | // moving and resizing | |
393 | // --------------------------------------------------------------------------- | |
394 | ||
395 | // Get total size | |
396 | void wxWindowDFB::DoGetSize(int *x, int *y) const | |
397 | { | |
398 | if (x) *x = m_rect.width; | |
399 | if (y) *y = m_rect.height; | |
400 | } | |
401 | ||
402 | void wxWindowDFB::DoGetPosition(int *x, int *y) const | |
403 | { | |
404 | if (x) *x = m_rect.x; | |
405 | if (y) *y = m_rect.y; | |
406 | } | |
407 | ||
408 | static wxPoint GetScreenPosOfClientOrigin(const wxWindowDFB *win) | |
409 | { | |
410 | wxCHECK_MSG( win, wxPoint(0, 0), _T("no window provided") ); | |
411 | ||
412 | wxPoint pt(win->GetPosition() + win->GetClientAreaOrigin()); | |
413 | ||
414 | if ( !win->IsTopLevel() ) | |
415 | pt += GetScreenPosOfClientOrigin(win->GetParent()); | |
416 | ||
417 | return pt; | |
418 | } | |
419 | ||
420 | void wxWindowDFB::DoScreenToClient(int *x, int *y) const | |
421 | { | |
422 | wxPoint o = GetScreenPosOfClientOrigin(this); | |
423 | ||
424 | if (x) *x -= o.x; | |
425 | if (y) *y -= o.y; | |
426 | } | |
427 | ||
428 | void wxWindowDFB::DoClientToScreen(int *x, int *y) const | |
429 | { | |
430 | wxPoint o = GetScreenPosOfClientOrigin(this); | |
431 | ||
432 | if (x) *x += o.x; | |
433 | if (y) *y += o.y; | |
434 | } | |
435 | ||
436 | // Get size *available for subwindows* i.e. excluding menu bar etc. | |
437 | void wxWindowDFB::DoGetClientSize(int *x, int *y) const | |
438 | { | |
439 | DoGetSize(x, y); | |
440 | } | |
441 | ||
442 | void wxWindowDFB::DoMoveWindow(int x, int y, int width, int height) | |
443 | { | |
444 | wxRect oldpos(m_rect); | |
445 | wxRect newpos(x, y, width, height); | |
446 | ||
447 | m_rect = newpos; | |
448 | ||
449 | // window's position+size changed and so did the subsurface that covers it | |
450 | InvalidateDfbSurface(); | |
451 | ||
452 | if ( IsShown() ) | |
453 | { | |
454 | // queue both former and new position of the window for repainting: | |
455 | wxWindow *parent = GetParent(); | |
456 | wxPoint origin(parent->GetClientAreaOrigin()); | |
457 | oldpos.Offset(origin); | |
458 | newpos.Offset(origin); | |
459 | parent->RefreshRect(oldpos); | |
460 | parent->RefreshRect(newpos); | |
461 | } | |
462 | } | |
463 | ||
464 | // set the size of the window: if the dimensions are positive, just use them, | |
465 | // but if any of them is equal to -1, it means that we must find the value for | |
466 | // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in | |
467 | // which case -1 is a valid value for x and y) | |
468 | // | |
469 | // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate | |
470 | // the width/height to best suit our contents, otherwise we reuse the current | |
471 | // width/height | |
472 | void wxWindowDFB::DoSetSize(int x, int y, int width, int height, int sizeFlags) | |
473 | { | |
474 | // get the current size and position... | |
475 | int currentX, currentY; | |
476 | GetPosition(¤tX, ¤tY); | |
477 | int currentW,currentH; | |
478 | GetSize(¤tW, ¤tH); | |
479 | ||
480 | if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) | |
481 | x = currentX; | |
482 | if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) | |
483 | y = currentY; | |
484 | ||
485 | // ... and don't do anything (avoiding flicker) if it's already ok | |
486 | if ( x == currentX && y == currentY && | |
487 | width == currentW && height == currentH ) | |
488 | { | |
489 | return; | |
490 | } | |
491 | ||
492 | AdjustForParentClientOrigin(x, y, sizeFlags); | |
493 | ||
494 | wxSize size(-1, -1); | |
495 | if ( width == -1 ) | |
496 | { | |
497 | if ( sizeFlags & wxSIZE_AUTO_WIDTH ) | |
498 | { | |
499 | size = DoGetBestSize(); | |
500 | width = size.x; | |
501 | } | |
502 | else | |
503 | { | |
504 | // just take the current one | |
505 | width = currentW; | |
506 | } | |
507 | } | |
508 | ||
509 | if ( height == -1 ) | |
510 | { | |
511 | if ( sizeFlags & wxSIZE_AUTO_HEIGHT ) | |
512 | { | |
513 | if ( size.x == -1 ) | |
514 | { | |
515 | size = DoGetBestSize(); | |
516 | } | |
517 | //else: already called DoGetBestSize() above | |
518 | ||
519 | height = size.y; | |
520 | } | |
521 | else | |
522 | { | |
523 | // just take the current one | |
524 | height = currentH; | |
525 | } | |
526 | } | |
527 | ||
528 | int maxWidth = GetMaxWidth(), | |
529 | minWidth = GetMinWidth(), | |
530 | maxHeight = GetMaxHeight(), | |
531 | minHeight = GetMinHeight(); | |
532 | ||
533 | if ( minWidth != -1 && width < minWidth ) width = minWidth; | |
534 | if ( maxWidth != -1 && width > maxWidth ) width = maxWidth; | |
535 | if ( minHeight != -1 && height < minHeight ) height = minHeight; | |
536 | if ( maxHeight != -1 && height > maxHeight ) height = maxHeight; | |
537 | ||
538 | if ( m_rect.x != x || m_rect.y != y || | |
539 | m_rect.width != width || m_rect.height != height ) | |
540 | { | |
541 | DoMoveWindow(x, y, width, height); | |
542 | ||
543 | wxSize newSize(width, height); | |
544 | wxSizeEvent event(newSize, GetId()); | |
545 | event.SetEventObject(this); | |
546 | GetEventHandler()->ProcessEvent(event); | |
547 | } | |
548 | } | |
549 | ||
550 | void wxWindowDFB::DoSetClientSize(int width, int height) | |
551 | { | |
552 | SetSize(width, height); | |
553 | } | |
554 | ||
555 | // --------------------------------------------------------------------------- | |
556 | // text metrics | |
557 | // --------------------------------------------------------------------------- | |
558 | ||
559 | int wxWindowDFB::GetCharHeight() const | |
560 | { | |
561 | wxWindowDC dc((wxWindow*)this); | |
562 | return dc.GetCharHeight(); | |
563 | } | |
564 | ||
565 | int wxWindowDFB::GetCharWidth() const | |
566 | { | |
567 | wxWindowDC dc((wxWindow*)this); | |
568 | return dc.GetCharWidth(); | |
569 | } | |
570 | ||
571 | void wxWindowDFB::GetTextExtent(const wxString& string, | |
572 | int *x, int *y, | |
573 | int *descent, int *externalLeading, | |
574 | const wxFont *theFont) const | |
575 | { | |
576 | wxWindowDC dc((wxWindow*)this); | |
577 | dc.GetTextExtent(string, x, y, descent, externalLeading, (wxFont*)theFont); | |
578 | } | |
579 | ||
580 | ||
581 | // --------------------------------------------------------------------------- | |
582 | // painting | |
583 | // --------------------------------------------------------------------------- | |
584 | ||
585 | void wxWindowDFB::Clear() | |
586 | { | |
587 | wxClientDC dc((wxWindow *)this); | |
588 | wxBrush brush(GetBackgroundColour(), wxSOLID); | |
589 | dc.SetBackground(brush); | |
590 | dc.Clear(); | |
591 | } | |
592 | ||
593 | void wxWindowDFB::Refresh(bool eraseBack, const wxRect *rect) | |
594 | { | |
595 | if ( !IsShown() || IsFrozen() ) | |
596 | return; | |
597 | ||
598 | if ( rect ) | |
599 | DoRefreshRect(*rect, eraseBack); | |
600 | else | |
601 | DoRefreshWindow(eraseBack); | |
602 | } | |
603 | ||
604 | void wxWindowDFB::DoRefreshWindow(bool eraseBack) | |
605 | { | |
606 | DoRefreshRect(wxRect(wxPoint(0, 0), GetSize()), eraseBack); | |
607 | } | |
608 | ||
609 | void wxWindowDFB::DoRefreshRect(const wxRect& rect, bool eraseBack) | |
610 | { | |
611 | wxWindow *parent = GetParent(); | |
612 | wxCHECK_RET( parent, _T("no parent") ); | |
613 | ||
614 | // convert the refresh rectangle to parent's coordinates and | |
615 | // recursively refresh the parent: | |
616 | wxRect r(rect); | |
617 | r.Offset(GetPosition()); | |
618 | r.Offset(parent->GetClientAreaOrigin()); | |
619 | ||
620 | parent->DoRefreshRect(r, eraseBack); | |
621 | } | |
622 | ||
623 | void wxWindowDFB::Update() | |
624 | { | |
625 | if ( !IsShown() || IsFrozen() ) | |
626 | return; | |
627 | ||
628 | GetParent()->Update(); | |
629 | } | |
630 | ||
631 | void wxWindowDFB::Freeze() | |
632 | { | |
633 | m_frozenness++; | |
634 | } | |
635 | ||
636 | void wxWindowDFB::Thaw() | |
637 | { | |
638 | wxASSERT_MSG( IsFrozen(), _T("Thaw() without matching Freeze()") ); | |
639 | ||
640 | if ( --m_frozenness == 0 ) | |
641 | { | |
642 | if ( IsShown() ) | |
643 | Refresh(); | |
644 | } | |
645 | } | |
646 | ||
647 | void wxWindowDFB::PaintWindow(const wxRect& rect, bool eraseBackground) | |
648 | { | |
14ac4e3a | 649 | wxCHECK_RET( !IsFrozen() && IsShown(), _T("shouldn't be called") ); |
b3c86150 VS |
650 | |
651 | wxLogTrace(TRACE_PAINT, | |
14ac4e3a | 652 | _T("%p ('%s'): painting region [x=%i,y=%i,w=%i,h=%i]"), |
b3c86150 VS |
653 | this, GetName().c_str(), |
654 | rect.x, rect.y, rect.width, rect.height); | |
655 | ||
656 | m_updateRegion = rect; | |
657 | ||
658 | // FIXME_DFB: don't waste time rendering the area if it's fully covered | |
659 | // by some children, go directly to rendering the children | |
660 | ||
661 | #if wxUSE_CARET | |
662 | // must hide caret temporarily, otherwise we'd get rendering artifacts | |
663 | wxCaret *caret = GetCaret(); | |
664 | if ( caret ) | |
665 | caret->Hide(); | |
666 | #endif // wxUSE_CARET | |
667 | ||
668 | if ( eraseBackground ) | |
669 | { | |
670 | wxWindowDC dc((wxWindow*)this); | |
671 | wxEraseEvent eventEr(m_windowId, &dc); | |
672 | eventEr.SetEventObject(this); | |
673 | GetEventHandler()->ProcessEvent(eventEr); | |
674 | } | |
675 | ||
676 | wxNcPaintEvent eventNc(GetId()); | |
677 | eventNc.SetEventObject(this); | |
678 | GetEventHandler()->ProcessEvent(eventNc); | |
679 | ||
680 | wxPaintEvent eventPt(GetId()); | |
681 | eventPt.SetEventObject(this); | |
682 | GetEventHandler()->ProcessEvent(eventPt); | |
683 | ||
684 | #if wxUSE_CARET | |
685 | if ( caret ) | |
686 | caret->Show(); | |
687 | #endif // wxUSE_CARET | |
688 | ||
689 | wxPoint origin = GetClientAreaOrigin(); | |
690 | wxWindowList& children = GetChildren(); | |
691 | for ( wxWindowList::iterator i = children.begin(); | |
692 | i != children.end(); ++i ) | |
693 | { | |
694 | wxWindow *child = *i; | |
695 | ||
14ac4e3a VS |
696 | if ( child->IsFrozen() || !child->IsShown() ) |
697 | continue; // don't paint anything if the window is frozen or hidden | |
698 | ||
b3c86150 VS |
699 | // compute child's area to repaint |
700 | wxRect childrect(child->GetRect()); | |
701 | childrect.Offset(origin); | |
702 | childrect.Intersect(rect); | |
703 | if ( childrect.IsEmpty() ) | |
704 | continue; | |
705 | ||
706 | // and repaint it: | |
707 | wxPoint childpos(child->GetPosition()); | |
708 | childrect.Offset(-childpos.x, -childpos.y); | |
709 | childrect.Offset(-origin.x, -origin.y); | |
710 | child->PaintWindow(childrect, eraseBackground); | |
711 | } | |
712 | ||
713 | m_updateRegion.Clear(); | |
714 | } | |
715 | ||
716 | ||
717 | // --------------------------------------------------------------------------- | |
718 | // events handling | |
719 | // --------------------------------------------------------------------------- | |
720 | ||
721 | #define KEY(dfb, wx) \ | |
722 | case dfb: \ | |
723 | wxLogTrace(TRACE_EVENTS, \ | |
724 | _T("key " #dfb " mapped to " #wx)); \ | |
725 | return wx | |
726 | ||
727 | // returns translated keycode, i.e. the one for KEYUP/KEYDOWN where 'a'..'z' is | |
728 | // translated to 'A'..'Z' | |
729 | static long GetTranslatedKeyCode(DFBInputDeviceKeyIdentifier key_id) | |
730 | { | |
731 | switch ( key_id ) | |
732 | { | |
733 | KEY(DIKI_UNKNOWN, 0); | |
734 | ||
735 | KEY(DIKI_A, 'A'); | |
736 | KEY(DIKI_B, 'B'); | |
737 | KEY(DIKI_C, 'C'); | |
738 | KEY(DIKI_D, 'D'); | |
739 | KEY(DIKI_E, 'E'); | |
740 | KEY(DIKI_F, 'F'); | |
741 | KEY(DIKI_G, 'G'); | |
742 | KEY(DIKI_H, 'H'); | |
743 | KEY(DIKI_I, 'I'); | |
744 | KEY(DIKI_J, 'J'); | |
745 | KEY(DIKI_K, 'K'); | |
746 | KEY(DIKI_L, 'L'); | |
747 | KEY(DIKI_M, 'M'); | |
748 | KEY(DIKI_N, 'N'); | |
749 | KEY(DIKI_O, 'O'); | |
750 | KEY(DIKI_P, 'P'); | |
751 | KEY(DIKI_Q, 'Q'); | |
752 | KEY(DIKI_R, 'R'); | |
753 | KEY(DIKI_S, 'S'); | |
754 | KEY(DIKI_T, 'T'); | |
755 | KEY(DIKI_U, 'U'); | |
756 | KEY(DIKI_V, 'V'); | |
757 | KEY(DIKI_W, 'W'); | |
758 | KEY(DIKI_X, 'X'); | |
759 | KEY(DIKI_Y, 'Y'); | |
760 | KEY(DIKI_Z, 'Z'); | |
761 | ||
762 | KEY(DIKI_0, '0'); | |
763 | KEY(DIKI_1, '1'); | |
764 | KEY(DIKI_2, '2'); | |
765 | KEY(DIKI_3, '3'); | |
766 | KEY(DIKI_4, '4'); | |
767 | KEY(DIKI_5, '5'); | |
768 | KEY(DIKI_6, '6'); | |
769 | KEY(DIKI_7, '7'); | |
770 | KEY(DIKI_8, '8'); | |
771 | KEY(DIKI_9, '9'); | |
772 | ||
773 | KEY(DIKI_F1, WXK_F1); | |
774 | KEY(DIKI_F2, WXK_F2); | |
775 | KEY(DIKI_F3, WXK_F3); | |
776 | KEY(DIKI_F4, WXK_F4); | |
777 | KEY(DIKI_F5, WXK_F5); | |
778 | KEY(DIKI_F6, WXK_F6); | |
779 | KEY(DIKI_F7, WXK_F7); | |
780 | KEY(DIKI_F8, WXK_F8); | |
781 | KEY(DIKI_F9, WXK_F9); | |
782 | KEY(DIKI_F10, WXK_F10); | |
783 | KEY(DIKI_F11, WXK_F11); | |
784 | KEY(DIKI_F12, WXK_F12); | |
785 | ||
786 | KEY(DIKI_SHIFT_L, WXK_SHIFT); | |
787 | KEY(DIKI_SHIFT_R, WXK_SHIFT); | |
788 | KEY(DIKI_CONTROL_L, WXK_CONTROL); | |
789 | KEY(DIKI_CONTROL_R, WXK_CONTROL); | |
790 | KEY(DIKI_ALT_L, WXK_ALT); | |
791 | KEY(DIKI_ALT_R, WXK_ALT); | |
792 | KEY(DIKI_META_L, 0); | |
793 | KEY(DIKI_META_R, 0); | |
794 | KEY(DIKI_SUPER_L, 0); | |
795 | KEY(DIKI_SUPER_R, 0); | |
796 | KEY(DIKI_HYPER_L, 0); | |
797 | KEY(DIKI_HYPER_R, 0); | |
798 | ||
799 | KEY(DIKI_CAPS_LOCK, 0); | |
800 | KEY(DIKI_NUM_LOCK, WXK_NUMLOCK); | |
801 | KEY(DIKI_SCROLL_LOCK, 0); | |
802 | ||
803 | KEY(DIKI_ESCAPE, WXK_ESCAPE); | |
804 | KEY(DIKI_LEFT, WXK_LEFT); | |
805 | KEY(DIKI_RIGHT, WXK_RIGHT); | |
806 | KEY(DIKI_UP, WXK_UP); | |
807 | KEY(DIKI_DOWN, WXK_DOWN); | |
808 | KEY(DIKI_TAB, WXK_TAB); | |
809 | KEY(DIKI_ENTER, WXK_RETURN); | |
810 | KEY(DIKI_SPACE, WXK_SPACE); | |
811 | KEY(DIKI_BACKSPACE, WXK_BACK); | |
812 | KEY(DIKI_INSERT, WXK_INSERT); | |
813 | KEY(DIKI_DELETE, WXK_DELETE); | |
814 | KEY(DIKI_HOME, WXK_HOME); | |
815 | KEY(DIKI_END, WXK_END); | |
816 | KEY(DIKI_PAGE_UP, WXK_PAGEUP); | |
817 | KEY(DIKI_PAGE_DOWN, WXK_PAGEDOWN); | |
818 | KEY(DIKI_PRINT, WXK_PRINT); | |
819 | KEY(DIKI_PAUSE, WXK_PAUSE); | |
820 | ||
821 | KEY(DIKI_QUOTE_LEFT, '`'); | |
822 | KEY(DIKI_MINUS_SIGN, '-'); | |
823 | KEY(DIKI_EQUALS_SIGN, '='); | |
824 | KEY(DIKI_BRACKET_LEFT, '['); | |
825 | KEY(DIKI_BRACKET_RIGHT, ']'); | |
826 | KEY(DIKI_BACKSLASH, '\\'); | |
827 | KEY(DIKI_SEMICOLON, ';'); | |
828 | KEY(DIKI_QUOTE_RIGHT, '\''); | |
829 | KEY(DIKI_COMMA, ','); | |
830 | KEY(DIKI_PERIOD, '.'); | |
831 | KEY(DIKI_SLASH, '/'); | |
832 | ||
833 | KEY(DIKI_LESS_SIGN, '<'); | |
834 | ||
835 | KEY(DIKI_KP_DIV, WXK_NUMPAD_DIVIDE); | |
836 | KEY(DIKI_KP_MULT, WXK_NUMPAD_MULTIPLY); | |
837 | KEY(DIKI_KP_MINUS, WXK_NUMPAD_SUBTRACT); | |
838 | KEY(DIKI_KP_PLUS, WXK_NUMPAD_ADD); | |
839 | KEY(DIKI_KP_ENTER, WXK_NUMPAD_ENTER); | |
840 | KEY(DIKI_KP_SPACE, WXK_NUMPAD_SPACE); | |
841 | KEY(DIKI_KP_TAB, WXK_NUMPAD_TAB); | |
842 | KEY(DIKI_KP_F1, WXK_NUMPAD_F1); | |
843 | KEY(DIKI_KP_F2, WXK_NUMPAD_F2); | |
844 | KEY(DIKI_KP_F3, WXK_NUMPAD_F3); | |
845 | KEY(DIKI_KP_F4, WXK_NUMPAD_F4); | |
846 | KEY(DIKI_KP_EQUAL, WXK_NUMPAD_EQUAL); | |
847 | KEY(DIKI_KP_SEPARATOR, WXK_NUMPAD_SEPARATOR); | |
848 | ||
849 | KEY(DIKI_KP_DECIMAL, WXK_NUMPAD_DECIMAL); | |
850 | KEY(DIKI_KP_0, WXK_NUMPAD0); | |
851 | KEY(DIKI_KP_1, WXK_NUMPAD1); | |
852 | KEY(DIKI_KP_2, WXK_NUMPAD2); | |
853 | KEY(DIKI_KP_3, WXK_NUMPAD3); | |
854 | KEY(DIKI_KP_4, WXK_NUMPAD4); | |
855 | KEY(DIKI_KP_5, WXK_NUMPAD5); | |
856 | KEY(DIKI_KP_6, WXK_NUMPAD6); | |
857 | KEY(DIKI_KP_7, WXK_NUMPAD7); | |
858 | KEY(DIKI_KP_8, WXK_NUMPAD8); | |
859 | KEY(DIKI_KP_9, WXK_NUMPAD9); | |
860 | ||
861 | case DIKI_KEYDEF_END: | |
862 | case DIKI_NUMBER_OF_KEYS: | |
863 | wxFAIL_MSG( _T("invalid key_id value") ); | |
864 | return 0; | |
865 | } | |
866 | ||
867 | return 0; // silence compiler warnings | |
868 | } | |
869 | ||
870 | // returns untranslated keycode, i.e. for EVT_CHAR, where characters are left in | |
871 | // the form they were entered (lowercase, diacritics etc.) | |
872 | static long GetUntraslatedKeyCode(DFBInputDeviceKeyIdentifier key_id, | |
873 | DFBInputDeviceKeySymbol key_symbol) | |
874 | { | |
875 | switch ( DFB_KEY_TYPE(key_symbol) ) | |
876 | { | |
877 | case DIKT_UNICODE: | |
878 | #if wxUSE_UNICODE | |
879 | return key_symbol; | |
880 | #else | |
881 | if ( key_symbol < 128 ) | |
882 | return key_symbol; | |
883 | else | |
884 | { | |
885 | #if wxUSE_WCHAR_T | |
886 | wchar_t chr = key_symbol; | |
887 | wxCharBuffer buf(wxConvUI->cWC2MB(&chr, 1, NULL)); | |
888 | if ( buf ) | |
889 | return *buf; // may be 0 if failed | |
890 | else | |
891 | #endif // wxUSE_WCHAR_T | |
892 | return 0; | |
893 | } | |
894 | #endif | |
895 | ||
896 | default: | |
897 | return GetTranslatedKeyCode(key_id); | |
898 | } | |
899 | } | |
900 | ||
901 | #undef KEY | |
902 | ||
903 | void wxWindowDFB::HandleKeyEvent(const wxDFBWindowEvent& event_) | |
904 | { | |
905 | if ( !IsEnabled() ) | |
906 | return; | |
907 | ||
908 | const DFBWindowEvent& e = event_; | |
909 | ||
910 | wxLogTrace(TRACE_EVENTS, | |
911 | _T("handling key %s event for window %p ('%s')"), | |
912 | e.type == DWET_KEYUP ? _T("up") : _T("down"), | |
913 | this, GetName().c_str()); | |
914 | ||
915 | // fill in wxKeyEvent fields: | |
916 | wxKeyEvent event; | |
917 | event.SetEventObject(this); | |
918 | event.SetTimestamp(wxDFB_EVENT_TIMESTAMP(e)); | |
919 | event.m_rawCode = e.key_code; | |
920 | event.m_keyCode = GetTranslatedKeyCode(e.key_id); | |
921 | event.m_scanCode = 0; // not used by wx at all | |
922 | #if wxUSE_UNICODE | |
923 | event.m_uniChar = e.key_symbol; | |
924 | #endif | |
925 | event.m_shiftDown = ( e.modifiers & DIMM_SHIFT ) != 0; | |
926 | event.m_controlDown = ( e.modifiers & DIMM_CONTROL ) != 0; | |
927 | event.m_altDown = ( e.modifiers & DIMM_ALT ) != 0; | |
928 | event.m_metaDown = ( e.modifiers & DIMM_META ) != 0; | |
929 | ||
930 | // translate coordinates from TLW-relative to this window-relative: | |
931 | event.m_x = e.x; | |
932 | event.m_y = e.y; | |
933 | GetTLW()->ClientToScreen(&event.m_x, &event.m_y); | |
934 | this->ScreenToClient(&event.m_x, &event.m_y); | |
935 | ||
936 | if ( e.type == DWET_KEYUP ) | |
937 | { | |
938 | event.SetEventType(wxEVT_KEY_UP); | |
939 | GetEventHandler()->ProcessEvent(event); | |
940 | } | |
941 | else | |
942 | { | |
943 | bool isTab = (event.m_keyCode == WXK_TAB); | |
944 | ||
945 | event.SetEventType(wxEVT_KEY_DOWN); | |
946 | ||
947 | if ( GetEventHandler()->ProcessEvent(event) ) | |
948 | return; | |
949 | ||
950 | // only send wxEVT_CHAR event if not processed yet: | |
951 | event.m_keyCode = GetUntraslatedKeyCode(e.key_id, e.key_symbol); | |
952 | if ( event.m_keyCode != 0 ) | |
953 | { | |
954 | event.SetEventType(wxEVT_CHAR); | |
955 | if ( GetEventHandler()->ProcessEvent(event) ) | |
956 | return; | |
957 | } | |
958 | ||
959 | // Synthetize navigation key event, but do it only if the TAB key | |
960 | // wasn't handled yet: | |
961 | if ( isTab && GetParent() && GetParent()->HasFlag(wxTAB_TRAVERSAL) ) | |
962 | { | |
963 | wxNavigationKeyEvent navEvent; | |
964 | navEvent.SetEventObject(GetParent()); | |
965 | // Shift-TAB goes in reverse direction: | |
966 | navEvent.SetDirection(!event.m_shiftDown); | |
967 | // Ctrl-TAB changes the (parent) window, i.e. switch notebook page: | |
968 | navEvent.SetWindowChange(event.m_controlDown); | |
969 | navEvent.SetCurrentFocus(wxStaticCast(this, wxWindow)); | |
970 | GetParent()->GetEventHandler()->ProcessEvent(navEvent); | |
971 | } | |
972 | } | |
973 | } | |
974 | ||
975 | // --------------------------------------------------------------------------- | |
976 | // idle events processing | |
977 | // --------------------------------------------------------------------------- | |
978 | ||
979 | void wxWindowDFB::OnInternalIdle() | |
980 | { | |
981 | if (wxUpdateUIEvent::CanUpdate(this)) | |
982 | UpdateWindowUI(wxUPDATE_UI_FROMIDLE); | |
983 | } | |
984 | ||
985 | ||
986 | // Find the wxWindow at the current mouse position, returning the mouse | |
987 | // position. | |
988 | wxWindow* wxFindWindowAtPointer(wxPoint& pt) | |
989 | { | |
990 | return wxFindWindowAtPoint(pt = wxGetMousePosition()); | |
991 | } | |
992 | ||
993 | wxWindow* wxFindWindowAtPoint(const wxPoint& pt) | |
994 | { | |
995 | wxFAIL_MSG( _T("wxFindWindowAtPoint not implemented") ); | |
996 | return NULL; | |
997 | } |