1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/dfb/window.cpp
4 // Author: Vaclav Slavik
5 // (based on GTK, MSW, MGL implementations)
8 // Copyright: (c) 2006 REA Elektronik GmbH
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/window.h"
30 #include "wx/dcclient.h"
31 #include "wx/nonownedwnd.h"
35 #include "wx/dynarray.h"
37 #include "wx/dfb/private.h"
38 #include "wx/private/overlay.h"
40 #define TRACE_EVENTS "events"
41 #define TRACE_PAINT "paint"
43 // ===========================================================================
45 // ===========================================================================
47 // ---------------------------------------------------------------------------
49 // ---------------------------------------------------------------------------
51 // the window that has keyboard focus:
52 static wxWindowDFB
*gs_focusedWindow
= NULL
;
53 // the window that is about to be focused after currently focused
55 static wxWindow
*gs_toBeFocusedWindow
= NULL
;
56 // the window that has mouse capture
57 static wxWindowDFB
*gs_mouseCapture
= NULL
;
59 // ---------------------------------------------------------------------------
61 // ---------------------------------------------------------------------------
63 WX_DEFINE_ARRAY_PTR(wxOverlayImpl
*, wxDfbOverlaysList
);
65 // ---------------------------------------------------------------------------
67 // ---------------------------------------------------------------------------
69 // in wxUniv this class is abstract because it doesn't have DoPopupMenu()
70 IMPLEMENT_ABSTRACT_CLASS(wxWindowDFB
, wxWindowBase
)
72 BEGIN_EVENT_TABLE(wxWindowDFB
, wxWindowBase
)
75 // ----------------------------------------------------------------------------
76 // constructors and such
77 // ----------------------------------------------------------------------------
79 void wxWindowDFB::Init()
88 wxWindowDFB::~wxWindowDFB()
92 m_isBeingDeleted
= true;
94 if ( gs_mouseCapture
== this )
97 if ( gs_focusedWindow
== this )
103 // real construction (Init() must have been called before!)
104 bool wxWindowDFB::Create(wxWindow
*parent
,
109 const wxString
& name
)
111 if ( !m_tlw
&& parent
)
112 m_tlw
= parent
->GetTLW();
114 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
118 parent
->AddChild(this);
120 // set the size to something bogus initially, in case some code tries to
121 // create wxWindowDC before SetSize() is called below:
122 m_rect
.width
= m_rect
.height
= 1;
125 x
= pos
.x
, y
= pos
.y
;
126 if ( x
== -1 ) x
= 0;
127 if ( y
== -1 ) y
= 0;
128 w
= WidthDefault(size
.x
);
129 h
= HeightDefault(size
.y
);
135 // ---------------------------------------------------------------------------
137 // ---------------------------------------------------------------------------
139 wxIDirectFBSurfacePtr
wxWindowDFB::ObtainDfbSurface() const
141 wxCHECK_MSG( m_parent
, NULL
, "parentless window?" );
143 wxIDirectFBSurfacePtr
parentSurface(m_parent
->GetDfbSurface());
144 wxCHECK_MSG( parentSurface
, NULL
, "invalid parent surface" );
147 AdjustForParentClientOrigin(r
.x
, r
.y
, 0);
148 DFBRectangle rect
= { r
.x
, r
.y
, r
.width
, r
.height
};
150 return parentSurface
->GetSubSurface(&rect
);
153 wxIDirectFBSurfacePtr
wxWindowDFB::GetDfbSurface()
157 m_surface
= ObtainDfbSurface();
158 wxASSERT_MSG( m_surface
, "invalid DirectFB surface" );
164 void wxWindowDFB::InvalidateDfbSurface()
168 // surfaces of the children are subsurfaces of this window's surface,
169 // so they must be invalidated as well:
170 wxWindowList
& children
= GetChildren();
171 for ( wxWindowList::iterator i
= children
.begin(); i
!= children
.end(); ++i
)
173 (*i
)->InvalidateDfbSurface();
177 // ---------------------------------------------------------------------------
179 // ---------------------------------------------------------------------------
181 void wxWindowDFB::SetFocus()
183 if ( gs_focusedWindow
== this )
184 return; // nothing to do, focused already
186 wxWindowDFB
*oldFocusedWindow
= gs_focusedWindow
;
188 if ( gs_focusedWindow
)
190 gs_toBeFocusedWindow
= (wxWindow
*)this;
191 gs_focusedWindow
->DFBKillFocus();
192 gs_toBeFocusedWindow
= NULL
;
195 gs_focusedWindow
= this;
197 if ( IsShownOnScreen() &&
198 (!oldFocusedWindow
|| oldFocusedWindow
->GetTLW() != m_tlw
) )
200 m_tlw
->SetDfbFocus();
202 // else: do nothing, because DirectFB windows cannot have focus if they
203 // are hidden; when the TLW becomes visible, it will set the focus
204 // to use from wxTLW::Show()
206 // notify the parent keeping track of focus for the kbd navigation
207 // purposes that we got it
208 wxChildFocusEvent
eventFocus((wxWindow
*)this);
209 GetEventHandler()->ProcessEvent(eventFocus
);
211 wxFocusEvent
event(wxEVT_SET_FOCUS
, GetId());
212 event
.SetEventObject(this);
213 event
.SetWindow((wxWindow
*)oldFocusedWindow
);
214 GetEventHandler()->ProcessEvent(event
);
217 // caret needs to be informed about focus change
218 wxCaret
*caret
= GetCaret();
221 #endif // wxUSE_CARET
224 void wxWindowDFB::DFBKillFocus()
226 wxCHECK_RET( gs_focusedWindow
== this,
227 "killing focus on window that doesn't have it" );
229 gs_focusedWindow
= NULL
;
231 if ( m_isBeingDeleted
)
232 return; // don't send any events from dtor
235 // caret needs to be informed about focus change
236 wxCaret
*caret
= GetCaret();
238 caret
->OnKillFocus();
239 #endif // wxUSE_CARET
241 wxFocusEvent
event(wxEVT_KILL_FOCUS
, GetId());
242 event
.SetEventObject(this);
243 event
.SetWindow(gs_toBeFocusedWindow
);
244 GetEventHandler()->ProcessEvent(event
);
247 // ----------------------------------------------------------------------------
248 // this wxWindowBase function is implemented here (in platform-specific file)
249 // because it is static and so couldn't be made virtual
250 // ----------------------------------------------------------------------------
251 wxWindow
*wxWindowBase::DoFindFocus()
253 return (wxWindow
*)gs_focusedWindow
;
256 bool wxWindowDFB::Show(bool show
)
258 if ( !wxWindowBase::Show(show
) )
261 // Unlike Refresh(), DoRefreshWindow() doesn't check visibility, so
262 // call it to force refresh of either this window (if showing) or its
263 // parent area at the place of this window (if hiding):
269 // Raise the window to the top of the Z order
270 void wxWindowDFB::Raise()
272 wxFAIL_MSG( "Raise() not implemented" );
275 // Lower the window to the bottom of the Z order
276 void wxWindowDFB::Lower()
278 wxFAIL_MSG( "Lower() not implemented" );
281 void wxWindowDFB::DoCaptureMouse()
283 #warning "implement this"
285 if ( gs_mouseCapture
)
286 DFB_wmUncaptureEvents(gs_mouseCapture
->m_wnd
, wxDFB_CAPTURE_MOUSE
);
288 gs_mouseCapture
= this;
290 DFB_wmCaptureEvents(m_wnd
, EVT_MOUSEEVT
, wxDFB_CAPTURE_MOUSE
);
294 void wxWindowDFB::DoReleaseMouse()
296 wxASSERT_MSG( gs_mouseCapture
== this, wxT("attempt to release mouse, but this window hasn't captured it") );
298 #warning "implement this"
300 DFB_wmUncaptureEvents(m_wnd
, wxDFB_CAPTURE_MOUSE
);
302 gs_mouseCapture
= NULL
;
305 /* static */ wxWindow
*wxWindowBase::GetCapture()
307 return (wxWindow
*)gs_mouseCapture
;
310 bool wxWindowDFB::SetCursor(const wxCursor
& cursor
)
312 if ( !wxWindowBase::SetCursor(cursor
) )
318 #warning "implement this"
321 DFB_wmSetWindowCursor(m_wnd
, *m_cursor
.GetDFBCursor());
323 DFB_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetDFBCursor());
329 void wxWindowDFB::WarpPointer(int x
, int y
)
332 wxDisplaySize(&w
, &h
);
334 ClientToScreen(&x
, &y
);
337 if ( x
>= w
) x
= w
-1;
338 if ( y
>= h
) y
= h
-1;
340 wxIDirectFBDisplayLayerPtr
layer(wxIDirectFB::Get()->GetDisplayLayer());
341 wxCHECK_RET( layer
, "no display layer" );
343 layer
->WarpCursor(x
, y
);
346 // Set this window to be the child of 'parent'.
347 bool wxWindowDFB::Reparent(wxWindowBase
*parent
)
349 if ( !wxWindowBase::Reparent(parent
) )
352 #warning "implement this"
353 wxFAIL_MSG( "reparenting not yet implemented" );
358 // ---------------------------------------------------------------------------
359 // moving and resizing
360 // ---------------------------------------------------------------------------
363 void wxWindowDFB::DoGetSize(int *x
, int *y
) const
365 if (x
) *x
= m_rect
.width
;
366 if (y
) *y
= m_rect
.height
;
369 void wxWindowDFB::DoGetPosition(int *x
, int *y
) const
371 if (x
) *x
= m_rect
.x
;
372 if (y
) *y
= m_rect
.y
;
375 static wxPoint
GetScreenPosOfClientOrigin(const wxWindowDFB
*win
)
377 wxCHECK_MSG( win
, wxPoint(0, 0), "no window provided" );
379 wxPoint
pt(win
->GetPosition() + win
->GetClientAreaOrigin());
381 if ( !win
->IsTopLevel() )
382 pt
+= GetScreenPosOfClientOrigin(win
->GetParent());
387 void wxWindowDFB::DoScreenToClient(int *x
, int *y
) const
389 wxPoint o
= GetScreenPosOfClientOrigin(this);
395 void wxWindowDFB::DoClientToScreen(int *x
, int *y
) const
397 wxPoint o
= GetScreenPosOfClientOrigin(this);
403 // Get size *available for subwindows* i.e. excluding menu bar etc.
404 void wxWindowDFB::DoGetClientSize(int *x
, int *y
) const
409 void wxWindowDFB::DoMoveWindow(int x
, int y
, int width
, int height
)
411 // NB: [x,y] arguments are in (parent's) window coordinates, while
412 // m_rect.{x,y} are in (parent's) client coordinates. That's why we
413 // offset by parentOrigin in some places below
415 wxPoint
parentOrigin(0, 0);
416 AdjustForParentClientOrigin(parentOrigin
.x
, parentOrigin
.y
);
418 wxRect
oldpos(m_rect
);
419 oldpos
.Offset(parentOrigin
);
421 wxRect
newpos(x
, y
, width
, height
);
423 // input [x,y] is in window coords, but we store client coords in m_rect:
425 m_rect
.Offset(-parentOrigin
);
427 // window's position+size changed and so did the subsurface that covers it
428 InvalidateDfbSurface();
432 // queue both former and new position of the window for repainting:
433 wxWindow
*parent
= GetParent();
435 // only refresh the visible parts:
436 if ( !CanBeOutsideClientArea() )
438 wxRect
parentClient(parent
->GetClientSize());
439 oldpos
.Intersect(parentClient
);
440 newpos
.Intersect(parentClient
);
443 parent
->RefreshRect(oldpos
);
444 parent
->RefreshRect(newpos
);
448 // set the size of the window: if the dimensions are positive, just use them,
449 // but if any of them is equal to -1, it means that we must find the value for
450 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
451 // which case -1 is a valid value for x and y)
453 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
454 // the width/height to best suit our contents, otherwise we reuse the current
456 void wxWindowDFB::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
458 // get the current size and position...
459 int currentX
, currentY
;
460 GetPosition(¤tX
, ¤tY
);
461 int currentW
,currentH
;
462 GetSize(¤tW
, ¤tH
);
464 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
466 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
469 // ... and don't do anything (avoiding flicker) if it's already ok
470 if ( x
== currentX
&& y
== currentY
&&
471 width
== currentW
&& height
== currentH
)
479 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
481 size
= DoGetBestSize();
486 // just take the current one
493 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
497 size
= DoGetBestSize();
499 //else: already called DoGetBestSize() above
505 // just take the current one
510 int maxWidth
= GetMaxWidth(),
511 minWidth
= GetMinWidth(),
512 maxHeight
= GetMaxHeight(),
513 minHeight
= GetMinHeight();
515 if ( minWidth
!= -1 && width
< minWidth
) width
= minWidth
;
516 if ( maxWidth
!= -1 && width
> maxWidth
) width
= maxWidth
;
517 if ( minHeight
!= -1 && height
< minHeight
) height
= minHeight
;
518 if ( maxHeight
!= -1 && height
> maxHeight
) height
= maxHeight
;
520 if ( m_rect
.x
!= x
|| m_rect
.y
!= y
||
521 m_rect
.width
!= width
|| m_rect
.height
!= height
)
523 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
524 DoMoveWindow(x
, y
, width
, height
);
526 wxSize
newSize(width
, height
);
527 wxSizeEvent
event(newSize
, GetId());
528 event
.SetEventObject(this);
529 GetEventHandler()->ProcessEvent(event
);
533 void wxWindowDFB::DoSetClientSize(int width
, int height
)
535 SetSize(width
, height
);
538 // ---------------------------------------------------------------------------
540 // ---------------------------------------------------------------------------
542 int wxWindowDFB::GetCharHeight() const
544 wxWindowDC
dc((wxWindow
*)this);
545 return dc
.GetCharHeight();
548 int wxWindowDFB::GetCharWidth() const
550 wxWindowDC
dc((wxWindow
*)this);
551 return dc
.GetCharWidth();
554 void wxWindowDFB::GetTextExtent(const wxString
& string
,
556 int *descent
, int *externalLeading
,
557 const wxFont
*theFont
) const
559 wxWindowDC
dc((wxWindow
*)this);
560 dc
.GetTextExtent(string
, x
, y
, descent
, externalLeading
, (wxFont
*)theFont
);
564 // ---------------------------------------------------------------------------
566 // ---------------------------------------------------------------------------
568 void wxWindowDFB::Clear()
570 wxClientDC
dc((wxWindow
*)this);
571 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
572 dc
.SetBackground(brush
);
576 void wxWindowDFB::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
578 if ( !IsShown() || IsFrozen() )
581 // NB[1]: We intentionally ignore the eraseBack argument here. This is
582 // because of the way wxDFB's painting is implemented: the refresh
583 // request is propagated up to wxTLW, which is then painted in
584 // top-down order. This means that this window's area is first
585 // painted by its parent and this window is then painted over it, so
586 // it's not safe to not paint this window's background even if
588 // NB[2]: wxWindow::Refresh() takes the rectangle in client coords, but
589 // wxUniv translates it to window coords before passing it to
590 // wxWindowDFB::Refresh(), so we can directly pass the rect to
591 // DoRefreshRect (which takes window, not client, coords) here.
593 DoRefreshRect(*rect
);
598 void wxWindowDFB::RefreshWindowRect(const wxRect
& rect
)
600 if ( !IsShown() || IsFrozen() )
606 void wxWindowDFB::DoRefreshWindow()
608 // NB: DoRefreshRect() takes window coords, not client, so this is correct
609 DoRefreshRect(wxRect(GetSize()));
612 void wxWindowDFB::DoRefreshRect(const wxRect
& rect
)
614 wxWindow
*parent
= GetParent();
615 wxCHECK_RET( parent
, "no parent" );
617 // don't overlap outside of the window (NB: 'rect' is in window coords):
619 r
.Intersect(wxRect(GetSize()));
623 wxLogTrace(TRACE_PAINT
,
624 "%p ('%s'): refresh rect [%i,%i,%i,%i]",
625 this, GetName().c_str(),
626 rect
.x
, rect
.y
, rect
.GetRight(), rect
.GetBottom());
628 // convert the refresh rectangle to parent's coordinates and
629 // recursively refresh the parent:
630 r
.Offset(GetPosition());
631 r
.Offset(parent
->GetClientAreaOrigin());
633 // normal windows cannot extend out of its parent's client area, so don't
634 // refresh any hidden parts:
635 if ( !CanBeOutsideClientArea() )
636 r
.Intersect(parent
->GetClientRect());
638 parent
->DoRefreshRect(r
);
641 void wxWindowDFB::Update()
643 if ( !IsShown() || IsFrozen() )
646 GetParent()->Update();
649 void wxWindowDFB::Freeze()
654 void wxWindowDFB::Thaw()
656 wxASSERT_MSG( IsFrozen(), "Thaw() without matching Freeze()" );
658 if ( --m_frozenness
== 0 )
665 void wxWindowDFB::PaintWindow(const wxRect
& rect
)
667 wxCHECK_RET( !IsFrozen() && IsShown(), "shouldn't be called" );
669 wxLogTrace(TRACE_PAINT
,
670 "%p ('%s'): painting region [%i,%i,%i,%i]",
671 this, GetName().c_str(),
672 rect
.x
, rect
.y
, rect
.GetRight(), rect
.GetBottom());
674 m_updateRegion
= rect
;
676 // FIXME_DFB: don't waste time rendering the area if it's fully covered
677 // by some children, go directly to rendering the children
678 // (unless some child has HasTransparentBackground()=true!)
680 // NB: unconditionally send wxEraseEvent, because our implementation of
681 // wxWindow::Refresh() ignores the eraseBack argument
682 wxWindowDC
dc((wxWindow
*)this);
683 wxEraseEvent
eventEr(m_windowId
, &dc
);
684 eventEr
.SetEventObject(this);
685 GetEventHandler()->ProcessEvent(eventEr
);
687 wxRect
clientRect(GetClientRect());
689 // only send wxNcPaintEvent if drawing at least part of nonclient area:
690 if ( !clientRect
.Contains(rect
) )
692 wxNcPaintEvent
eventNc(GetId());
693 eventNc
.SetEventObject(this);
694 GetEventHandler()->ProcessEvent(eventNc
);
698 wxLogTrace(TRACE_PAINT
, "%p ('%s'): not sending wxNcPaintEvent",
699 this, GetName().c_str());
702 // only send wxPaintEvent if drawing at least part of client area:
703 if ( rect
.Intersects(clientRect
) )
705 wxPaintEvent
eventPt(GetId());
706 eventPt
.SetEventObject(this);
707 GetEventHandler()->ProcessEvent(eventPt
);
711 wxLogTrace(TRACE_PAINT
, "%p ('%s'): not sending wxPaintEvent",
712 this, GetName().c_str());
715 // draw window's overlays on top of the painted window, if we have any:
718 m_updateRegion
.Clear();
720 // client area portion of 'rect':
721 wxRect
rectClientOnly(rect
);
722 rectClientOnly
.Intersect(clientRect
);
724 // paint the children:
725 wxPoint origin
= GetClientAreaOrigin();
726 wxWindowList
& children
= GetChildren();
727 for ( wxWindowList::iterator i
= children
.begin();
728 i
!= children
.end(); ++i
)
730 wxWindow
*child
= *i
;
732 if ( child
->IsFrozen() || !child
->IsShown() )
733 continue; // don't paint anything if the window is frozen or hidden
735 // compute child's area to repaint
736 wxRect
childrect(child
->GetRect());
737 childrect
.Offset(origin
);
739 if ( child
->CanBeOutsideClientArea() )
740 childrect
.Intersect(rect
);
742 childrect
.Intersect(rectClientOnly
);
744 if ( childrect
.IsEmpty() )
748 childrect
.Offset(-child
->GetPosition());
749 childrect
.Offset(-origin
);
750 child
->PaintWindow(childrect
);
754 void wxWindowDFB::PaintOverlays(const wxRect
& rect
)
759 for ( wxDfbOverlaysList::const_iterator i
= m_overlays
->begin();
760 i
!= m_overlays
->end(); ++i
)
762 // FIXME: the cast is necessary for STL build where the iterator
763 // (incorrectly) returns void* and not wxOverlayImpl*
764 wxOverlayImpl
*overlay
= (wxOverlayImpl
*) *i
;
766 wxRect
orectOrig(overlay
->GetRect());
767 wxRect
orect(orectOrig
);
768 orect
.Intersect(rect
);
769 if ( orect
.IsEmpty() )
772 if ( overlay
->IsEmpty() )
773 continue; // nothing to paint
775 DFBRectangle dfbRect
= { orect
.x
- orectOrig
.x
, orect
.y
- orectOrig
.y
,
776 orect
.width
, orect
.height
};
777 GetDfbSurface()->Blit
779 overlay
->GetDirectFBSurface(),
786 void wxWindowDFB::AddOverlay(wxOverlayImpl
*overlay
)
789 m_overlays
= new wxDfbOverlaysList
;
791 m_overlays
->Add(overlay
);
794 void wxWindowDFB::RemoveOverlay(wxOverlayImpl
*overlay
)
796 wxCHECK_RET( m_overlays
, "no overlays to remove" );
798 m_overlays
->Remove(overlay
);
800 if ( m_overlays
->empty() )
802 wxDELETE(m_overlays
);
805 if ( !m_isBeingDeleted
)
806 RefreshWindowRect(overlay
->GetRect());
810 // ---------------------------------------------------------------------------
812 // ---------------------------------------------------------------------------
814 #define KEY(dfb, wx) \
816 wxLogTrace(TRACE_EVENTS, \
817 _T("key " #dfb " mapped to " #wx)); \
820 // returns translated keycode, i.e. the one for KEYUP/KEYDOWN where 'a'..'z' is
821 // translated to 'A'..'Z'
822 static long GetTranslatedKeyCode(DFBInputDeviceKeyIdentifier key_id
)
826 KEY(DIKI_UNKNOWN
, 0);
866 KEY(DIKI_F1
, WXK_F1
);
867 KEY(DIKI_F2
, WXK_F2
);
868 KEY(DIKI_F3
, WXK_F3
);
869 KEY(DIKI_F4
, WXK_F4
);
870 KEY(DIKI_F5
, WXK_F5
);
871 KEY(DIKI_F6
, WXK_F6
);
872 KEY(DIKI_F7
, WXK_F7
);
873 KEY(DIKI_F8
, WXK_F8
);
874 KEY(DIKI_F9
, WXK_F9
);
875 KEY(DIKI_F10
, WXK_F10
);
876 KEY(DIKI_F11
, WXK_F11
);
877 KEY(DIKI_F12
, WXK_F12
);
879 KEY(DIKI_SHIFT_L
, WXK_SHIFT
);
880 KEY(DIKI_SHIFT_R
, WXK_SHIFT
);
881 KEY(DIKI_CONTROL_L
, WXK_CONTROL
);
882 KEY(DIKI_CONTROL_R
, WXK_CONTROL
);
883 KEY(DIKI_ALT_L
, WXK_ALT
);
884 KEY(DIKI_ALT_R
, WXK_ALT
);
885 // this key was removed in 0.9.25 but include it for previous versions
886 // just to avoid gcc warnings about unhandled enum value in switch
887 #if !wxCHECK_DFB_VERSION(0, 9, 24)
892 KEY(DIKI_SUPER_L
, 0);
893 KEY(DIKI_SUPER_R
, 0);
894 KEY(DIKI_HYPER_L
, 0);
895 KEY(DIKI_HYPER_R
, 0);
897 KEY(DIKI_CAPS_LOCK
, 0);
898 KEY(DIKI_NUM_LOCK
, WXK_NUMLOCK
);
899 KEY(DIKI_SCROLL_LOCK
, 0);
901 KEY(DIKI_ESCAPE
, WXK_ESCAPE
);
902 KEY(DIKI_LEFT
, WXK_LEFT
);
903 KEY(DIKI_RIGHT
, WXK_RIGHT
);
904 KEY(DIKI_UP
, WXK_UP
);
905 KEY(DIKI_DOWN
, WXK_DOWN
);
906 KEY(DIKI_TAB
, WXK_TAB
);
907 KEY(DIKI_ENTER
, WXK_RETURN
);
908 KEY(DIKI_SPACE
, WXK_SPACE
);
909 KEY(DIKI_BACKSPACE
, WXK_BACK
);
910 KEY(DIKI_INSERT
, WXK_INSERT
);
911 KEY(DIKI_DELETE
, WXK_DELETE
);
912 KEY(DIKI_HOME
, WXK_HOME
);
913 KEY(DIKI_END
, WXK_END
);
914 KEY(DIKI_PAGE_UP
, WXK_PAGEUP
);
915 KEY(DIKI_PAGE_DOWN
, WXK_PAGEDOWN
);
916 KEY(DIKI_PRINT
, WXK_PRINT
);
917 KEY(DIKI_PAUSE
, WXK_PAUSE
);
919 KEY(DIKI_QUOTE_LEFT
, '`');
920 KEY(DIKI_MINUS_SIGN
, '-');
921 KEY(DIKI_EQUALS_SIGN
, '=');
922 KEY(DIKI_BRACKET_LEFT
, '[');
923 KEY(DIKI_BRACKET_RIGHT
, ']');
924 KEY(DIKI_BACKSLASH
, '\\');
925 KEY(DIKI_SEMICOLON
, ';');
926 KEY(DIKI_QUOTE_RIGHT
, '\'');
927 KEY(DIKI_COMMA
, ',');
928 KEY(DIKI_PERIOD
, '.');
929 KEY(DIKI_SLASH
, '/');
931 KEY(DIKI_LESS_SIGN
, '<');
933 KEY(DIKI_KP_DIV
, WXK_NUMPAD_DIVIDE
);
934 KEY(DIKI_KP_MULT
, WXK_NUMPAD_MULTIPLY
);
935 KEY(DIKI_KP_MINUS
, WXK_NUMPAD_SUBTRACT
);
936 KEY(DIKI_KP_PLUS
, WXK_NUMPAD_ADD
);
937 KEY(DIKI_KP_ENTER
, WXK_NUMPAD_ENTER
);
938 KEY(DIKI_KP_SPACE
, WXK_NUMPAD_SPACE
);
939 KEY(DIKI_KP_TAB
, WXK_NUMPAD_TAB
);
940 KEY(DIKI_KP_F1
, WXK_NUMPAD_F1
);
941 KEY(DIKI_KP_F2
, WXK_NUMPAD_F2
);
942 KEY(DIKI_KP_F3
, WXK_NUMPAD_F3
);
943 KEY(DIKI_KP_F4
, WXK_NUMPAD_F4
);
944 KEY(DIKI_KP_EQUAL
, WXK_NUMPAD_EQUAL
);
945 KEY(DIKI_KP_SEPARATOR
, WXK_NUMPAD_SEPARATOR
);
947 KEY(DIKI_KP_DECIMAL
, WXK_NUMPAD_DECIMAL
);
948 KEY(DIKI_KP_0
, WXK_NUMPAD0
);
949 KEY(DIKI_KP_1
, WXK_NUMPAD1
);
950 KEY(DIKI_KP_2
, WXK_NUMPAD2
);
951 KEY(DIKI_KP_3
, WXK_NUMPAD3
);
952 KEY(DIKI_KP_4
, WXK_NUMPAD4
);
953 KEY(DIKI_KP_5
, WXK_NUMPAD5
);
954 KEY(DIKI_KP_6
, WXK_NUMPAD6
);
955 KEY(DIKI_KP_7
, WXK_NUMPAD7
);
956 KEY(DIKI_KP_8
, WXK_NUMPAD8
);
957 KEY(DIKI_KP_9
, WXK_NUMPAD9
);
959 case DIKI_KEYDEF_END
:
960 case DIKI_NUMBER_OF_KEYS
:
961 wxFAIL_MSG( "invalid key_id value" );
965 return 0; // silence compiler warnings
968 // returns untranslated keycode, i.e. for EVT_CHAR, where characters are left in
969 // the form they were entered (lowercase, diacritics etc.)
970 static long GetUntraslatedKeyCode(DFBInputDeviceKeyIdentifier key_id
,
971 DFBInputDeviceKeySymbol key_symbol
)
973 switch ( DFB_KEY_TYPE(key_symbol
) )
979 if ( key_symbol
< 128 )
984 wchar_t chr
= key_symbol
;
985 wxCharBuffer
buf(wxConvUI
->cWC2MB(&chr
, 1, NULL
));
987 return *buf
; // may be 0 if failed
989 #endif // wxUSE_WCHAR_T
995 return GetTranslatedKeyCode(key_id
);
1001 void wxWindowDFB::HandleKeyEvent(const wxDFBWindowEvent
& event_
)
1006 const DFBWindowEvent
& e
= event_
;
1008 wxLogTrace(TRACE_EVENTS
,
1009 "handling key %s event for window %p ('%s')",
1010 e
.type
== DWET_KEYUP
? "up" : "down",
1011 this, GetName().c_str());
1013 // fill in wxKeyEvent fields:
1015 event
.SetEventObject(this);
1016 event
.SetTimestamp(wxDFB_EVENT_TIMESTAMP(e
));
1017 event
.m_rawCode
= e
.key_code
;
1018 event
.m_keyCode
= GetTranslatedKeyCode(e
.key_id
);
1019 event
.m_scanCode
= 0; // not used by wx at all
1021 event
.m_uniChar
= e
.key_symbol
;
1023 event
.m_shiftDown
= ( e
.modifiers
& DIMM_SHIFT
) != 0;
1024 event
.m_controlDown
= ( e
.modifiers
& DIMM_CONTROL
) != 0;
1025 event
.m_altDown
= ( e
.modifiers
& DIMM_ALT
) != 0;
1026 event
.m_metaDown
= ( e
.modifiers
& DIMM_META
) != 0;
1028 // translate coordinates from TLW-relative to this window-relative:
1031 GetTLW()->ClientToScreen(&event
.m_x
, &event
.m_y
);
1032 this->ScreenToClient(&event
.m_x
, &event
.m_y
);
1034 if ( e
.type
== DWET_KEYUP
)
1036 event
.SetEventType(wxEVT_KEY_UP
);
1037 GetEventHandler()->ProcessEvent(event
);
1041 bool isTab
= (event
.m_keyCode
== WXK_TAB
);
1043 event
.SetEventType(wxEVT_KEY_DOWN
);
1045 if ( GetEventHandler()->ProcessEvent(event
) )
1048 // only send wxEVT_CHAR event if not processed yet:
1049 event
.m_keyCode
= GetUntraslatedKeyCode(e
.key_id
, e
.key_symbol
);
1050 if ( event
.m_keyCode
!= 0 )
1052 event
.SetEventType(wxEVT_CHAR
);
1053 if ( GetEventHandler()->ProcessEvent(event
) )
1057 // Synthetize navigation key event, but do it only if the TAB key
1058 // wasn't handled yet:
1059 if ( isTab
&& GetParent() && GetParent()->HasFlag(wxTAB_TRAVERSAL
) )
1061 wxNavigationKeyEvent navEvent
;
1062 navEvent
.SetEventObject(GetParent());
1063 // Shift-TAB goes in reverse direction:
1064 navEvent
.SetDirection(!event
.m_shiftDown
);
1065 // Ctrl-TAB changes the (parent) window, i.e. switch notebook page:
1066 navEvent
.SetWindowChange(event
.m_controlDown
);
1067 navEvent
.SetCurrentFocus(wxStaticCast(this, wxWindow
));
1068 GetParent()->GetEventHandler()->ProcessEvent(navEvent
);
1073 // ---------------------------------------------------------------------------
1074 // idle events processing
1075 // ---------------------------------------------------------------------------
1077 void wxWindowDFB::OnInternalIdle()
1079 if (wxUpdateUIEvent::CanUpdate(this) && IsShown())
1080 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1084 // Find the wxWindow at the current mouse position, returning the mouse
1086 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1088 return wxFindWindowAtPoint(pt
= wxGetMousePosition());
1091 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
1093 wxFAIL_MSG( "wxFindWindowAtPoint not implemented" );