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()
87 wxWindowDFB::~wxWindowDFB()
91 m_isBeingDeleted
= true;
93 if ( gs_mouseCapture
== this )
96 if ( gs_focusedWindow
== this )
102 // real construction (Init() must have been called before!)
103 bool wxWindowDFB::Create(wxWindow
*parent
,
108 const wxString
& name
)
110 if ( !m_tlw
&& parent
)
111 m_tlw
= parent
->GetTLW();
113 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
117 parent
->AddChild(this);
119 // set the size to something bogus initially, in case some code tries to
120 // create wxWindowDC before SetSize() is called below:
121 m_rect
.width
= m_rect
.height
= 1;
124 x
= pos
.x
, y
= pos
.y
;
125 if ( x
== -1 ) x
= 0;
126 if ( y
== -1 ) y
= 0;
127 w
= WidthDefault(size
.x
);
128 h
= HeightDefault(size
.y
);
134 // ---------------------------------------------------------------------------
136 // ---------------------------------------------------------------------------
138 wxIDirectFBSurfacePtr
wxWindowDFB::ObtainDfbSurface() const
140 wxCHECK_MSG( m_parent
, NULL
, "parentless window?" );
142 wxIDirectFBSurfacePtr
parentSurface(m_parent
->GetDfbSurface());
143 wxCHECK_MSG( parentSurface
, NULL
, "invalid parent surface" );
146 AdjustForParentClientOrigin(r
.x
, r
.y
, 0);
147 DFBRectangle rect
= { r
.x
, r
.y
, r
.width
, r
.height
};
149 return parentSurface
->GetSubSurface(&rect
);
152 wxIDirectFBSurfacePtr
wxWindowDFB::GetDfbSurface()
156 m_surface
= ObtainDfbSurface();
157 wxASSERT_MSG( m_surface
, "invalid DirectFB surface" );
163 void wxWindowDFB::InvalidateDfbSurface()
167 // surfaces of the children are subsurfaces of this window's surface,
168 // so they must be invalidated as well:
169 wxWindowList
& children
= GetChildren();
170 for ( wxWindowList::iterator i
= children
.begin(); i
!= children
.end(); ++i
)
172 (*i
)->InvalidateDfbSurface();
176 // ---------------------------------------------------------------------------
178 // ---------------------------------------------------------------------------
180 void wxWindowDFB::SetFocus()
182 if ( gs_focusedWindow
== this )
183 return; // nothing to do, focused already
185 wxWindowDFB
*oldFocusedWindow
= gs_focusedWindow
;
187 if ( gs_focusedWindow
)
189 gs_toBeFocusedWindow
= (wxWindow
*)this;
190 gs_focusedWindow
->DFBKillFocus();
191 gs_toBeFocusedWindow
= NULL
;
194 gs_focusedWindow
= this;
196 if ( IsShownOnScreen() &&
197 (!oldFocusedWindow
|| oldFocusedWindow
->GetTLW() != m_tlw
) )
199 m_tlw
->SetDfbFocus();
201 // else: do nothing, because DirectFB windows cannot have focus if they
202 // are hidden; when the TLW becomes visible, it will set the focus
203 // to use from wxTLW::Show()
205 // notify the parent keeping track of focus for the kbd navigation
206 // purposes that we got it
207 wxChildFocusEvent
eventFocus((wxWindow
*)this);
208 HandleWindowEvent(eventFocus
);
210 wxFocusEvent
event(wxEVT_SET_FOCUS
, GetId());
211 event
.SetEventObject(this);
212 event
.SetWindow((wxWindow
*)oldFocusedWindow
);
213 HandleWindowEvent(event
);
216 // caret needs to be informed about focus change
217 wxCaret
*caret
= GetCaret();
220 #endif // wxUSE_CARET
223 void wxWindowDFB::DFBKillFocus()
225 wxCHECK_RET( gs_focusedWindow
== this,
226 "killing focus on window that doesn't have it" );
228 gs_focusedWindow
= NULL
;
230 if ( m_isBeingDeleted
)
231 return; // don't send any events from dtor
234 // caret needs to be informed about focus change
235 wxCaret
*caret
= GetCaret();
237 caret
->OnKillFocus();
238 #endif // wxUSE_CARET
240 wxFocusEvent
event(wxEVT_KILL_FOCUS
, GetId());
241 event
.SetEventObject(this);
242 event
.SetWindow(gs_toBeFocusedWindow
);
243 HandleWindowEvent(event
);
246 // ----------------------------------------------------------------------------
247 // this wxWindowBase function is implemented here (in platform-specific file)
248 // because it is static and so couldn't be made virtual
249 // ----------------------------------------------------------------------------
250 wxWindow
*wxWindowBase::DoFindFocus()
252 return (wxWindow
*)gs_focusedWindow
;
255 bool wxWindowDFB::Show(bool show
)
257 if ( !wxWindowBase::Show(show
) )
260 // Unlike Refresh(), DoRefreshWindow() doesn't check visibility, so
261 // call it to force refresh of either this window (if showing) or its
262 // parent area at the place of this window (if hiding):
268 // Raise the window to the top of the Z order
269 void wxWindowDFB::Raise()
271 wxFAIL_MSG( "Raise() not implemented" );
274 // Lower the window to the bottom of the Z order
275 void wxWindowDFB::Lower()
277 wxFAIL_MSG( "Lower() not implemented" );
280 void wxWindowDFB::DoCaptureMouse()
282 #warning "implement this"
284 if ( gs_mouseCapture
)
285 DFB_wmUncaptureEvents(gs_mouseCapture
->m_wnd
, wxDFB_CAPTURE_MOUSE
);
287 gs_mouseCapture
= this;
289 DFB_wmCaptureEvents(m_wnd
, EVT_MOUSEEVT
, wxDFB_CAPTURE_MOUSE
);
293 void wxWindowDFB::DoReleaseMouse()
295 wxASSERT_MSG( gs_mouseCapture
== this, wxT("attempt to release mouse, but this window hasn't captured it") );
297 #warning "implement this"
299 DFB_wmUncaptureEvents(m_wnd
, wxDFB_CAPTURE_MOUSE
);
301 gs_mouseCapture
= NULL
;
304 /* static */ wxWindow
*wxWindowBase::GetCapture()
306 return (wxWindow
*)gs_mouseCapture
;
309 bool wxWindowDFB::SetCursor(const wxCursor
& cursor
)
311 if ( !wxWindowBase::SetCursor(cursor
) )
317 #warning "implement this"
320 DFB_wmSetWindowCursor(m_wnd
, *m_cursor
.GetDFBCursor());
322 DFB_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetDFBCursor());
328 void wxWindowDFB::WarpPointer(int x
, int y
)
331 wxDisplaySize(&w
, &h
);
333 ClientToScreen(&x
, &y
);
336 if ( x
>= w
) x
= w
-1;
337 if ( y
>= h
) y
= h
-1;
339 wxIDirectFBDisplayLayerPtr
layer(wxIDirectFB::Get()->GetDisplayLayer());
340 wxCHECK_RET( layer
, "no display layer" );
342 layer
->WarpCursor(x
, y
);
345 // Set this window to be the child of 'parent'.
346 bool wxWindowDFB::Reparent(wxWindowBase
*parent
)
348 if ( !wxWindowBase::Reparent(parent
) )
351 #warning "implement this"
352 wxFAIL_MSG( "reparenting not yet implemented" );
357 // ---------------------------------------------------------------------------
358 // moving and resizing
359 // ---------------------------------------------------------------------------
362 void wxWindowDFB::DoGetSize(int *x
, int *y
) const
364 if (x
) *x
= m_rect
.width
;
365 if (y
) *y
= m_rect
.height
;
368 void wxWindowDFB::DoGetPosition(int *x
, int *y
) const
370 if (x
) *x
= m_rect
.x
;
371 if (y
) *y
= m_rect
.y
;
374 static wxPoint
GetScreenPosOfClientOrigin(const wxWindowDFB
*win
)
376 wxCHECK_MSG( win
, wxPoint(0, 0), "no window provided" );
378 wxPoint
pt(win
->GetPosition() + win
->GetClientAreaOrigin());
380 if ( !win
->IsTopLevel() )
381 pt
+= GetScreenPosOfClientOrigin(win
->GetParent());
386 void wxWindowDFB::DoScreenToClient(int *x
, int *y
) const
388 wxPoint o
= GetScreenPosOfClientOrigin(this);
394 void wxWindowDFB::DoClientToScreen(int *x
, int *y
) const
396 wxPoint o
= GetScreenPosOfClientOrigin(this);
402 // Get size *available for subwindows* i.e. excluding menu bar etc.
403 void wxWindowDFB::DoGetClientSize(int *x
, int *y
) const
408 void wxWindowDFB::DoMoveWindow(int x
, int y
, int width
, int height
)
410 // NB: [x,y] arguments are in (parent's) window coordinates, while
411 // m_rect.{x,y} are in (parent's) client coordinates. That's why we
412 // offset by parentOrigin in some places below
414 wxPoint
parentOrigin(0, 0);
415 AdjustForParentClientOrigin(parentOrigin
.x
, parentOrigin
.y
);
417 wxRect
oldpos(m_rect
);
418 oldpos
.Offset(parentOrigin
);
420 wxRect
newpos(x
, y
, width
, height
);
422 // input [x,y] is in window coords, but we store client coords in m_rect:
424 m_rect
.Offset(-parentOrigin
);
426 // window's position+size changed and so did the subsurface that covers it
427 InvalidateDfbSurface();
431 // queue both former and new position of the window for repainting:
432 wxWindow
*parent
= GetParent();
434 // only refresh the visible parts:
435 if ( !CanBeOutsideClientArea() )
437 wxRect
parentClient(parent
->GetClientSize());
438 oldpos
.Intersect(parentClient
);
439 newpos
.Intersect(parentClient
);
442 parent
->RefreshRect(oldpos
);
443 parent
->RefreshRect(newpos
);
447 // set the size of the window: if the dimensions are positive, just use them,
448 // but if any of them is equal to -1, it means that we must find the value for
449 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
450 // which case -1 is a valid value for x and y)
452 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
453 // the width/height to best suit our contents, otherwise we reuse the current
455 void wxWindowDFB::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
457 // get the current size and position...
458 int currentX
, currentY
;
459 GetPosition(¤tX
, ¤tY
);
460 int currentW
,currentH
;
461 GetSize(¤tW
, ¤tH
);
463 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
465 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
468 // ... and don't do anything (avoiding flicker) if it's already ok
469 if ( x
== currentX
&& y
== currentY
&&
470 width
== currentW
&& height
== currentH
)
478 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
480 size
= DoGetBestSize();
485 // just take the current one
492 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
496 size
= DoGetBestSize();
498 //else: already called DoGetBestSize() above
504 // just take the current one
509 int maxWidth
= GetMaxWidth(),
510 minWidth
= GetMinWidth(),
511 maxHeight
= GetMaxHeight(),
512 minHeight
= GetMinHeight();
514 if ( minWidth
!= -1 && width
< minWidth
) width
= minWidth
;
515 if ( maxWidth
!= -1 && width
> maxWidth
) width
= maxWidth
;
516 if ( minHeight
!= -1 && height
< minHeight
) height
= minHeight
;
517 if ( maxHeight
!= -1 && height
> maxHeight
) height
= maxHeight
;
519 if ( m_rect
.x
!= x
|| m_rect
.y
!= y
||
520 m_rect
.width
!= width
|| m_rect
.height
!= height
)
522 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
523 DoMoveWindow(x
, y
, width
, height
);
525 wxSize
newSize(width
, height
);
526 wxSizeEvent
event(newSize
, GetId());
527 event
.SetEventObject(this);
528 HandleWindowEvent(event
);
532 void wxWindowDFB::DoSetClientSize(int width
, int height
)
534 SetSize(width
, height
);
537 // ---------------------------------------------------------------------------
539 // ---------------------------------------------------------------------------
541 int wxWindowDFB::GetCharHeight() const
543 wxWindowDC
dc((wxWindow
*)this);
544 return dc
.GetCharHeight();
547 int wxWindowDFB::GetCharWidth() const
549 wxWindowDC
dc((wxWindow
*)this);
550 return dc
.GetCharWidth();
553 void wxWindowDFB::GetTextExtent(const wxString
& string
,
555 int *descent
, int *externalLeading
,
556 const wxFont
*theFont
) const
558 wxWindowDC
dc((wxWindow
*)this);
559 dc
.GetTextExtent(string
, x
, y
, descent
, externalLeading
, (wxFont
*)theFont
);
563 // ---------------------------------------------------------------------------
565 // ---------------------------------------------------------------------------
567 void wxWindowDFB::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
569 if ( !IsShown() || IsFrozen() )
572 // NB[1]: We intentionally ignore the eraseBack argument here. This is
573 // because of the way wxDFB's painting is implemented: the refresh
574 // request is propagated up to wxTLW, which is then painted in
575 // top-down order. This means that this window's area is first
576 // painted by its parent and this window is then painted over it, so
577 // it's not safe to not paint this window's background even if
579 // NB[2]: wxWindow::Refresh() takes the rectangle in client coords, but
580 // wxUniv translates it to window coords before passing it to
581 // wxWindowDFB::Refresh(), so we can directly pass the rect to
582 // DoRefreshRect (which takes window, not client, coords) here.
584 DoRefreshRect(*rect
);
589 void wxWindowDFB::RefreshWindowRect(const wxRect
& rect
)
591 if ( !IsShown() || IsFrozen() )
597 void wxWindowDFB::DoRefreshWindow()
599 // NB: DoRefreshRect() takes window coords, not client, so this is correct
600 DoRefreshRect(wxRect(GetSize()));
603 void wxWindowDFB::DoRefreshRect(const wxRect
& rect
)
605 wxWindow
*parent
= GetParent();
606 wxCHECK_RET( parent
, "no parent" );
608 // don't overlap outside of the window (NB: 'rect' is in window coords):
610 r
.Intersect(wxRect(GetSize()));
614 wxLogTrace(TRACE_PAINT
,
615 "%p ('%s'): refresh rect [%i,%i,%i,%i]",
616 this, GetName().c_str(),
617 rect
.x
, rect
.y
, rect
.GetRight(), rect
.GetBottom());
619 // convert the refresh rectangle to parent's coordinates and
620 // recursively refresh the parent:
621 r
.Offset(GetPosition());
622 r
.Offset(parent
->GetClientAreaOrigin());
624 // normal windows cannot extend out of its parent's client area, so don't
625 // refresh any hidden parts:
626 if ( !CanBeOutsideClientArea() )
627 r
.Intersect(parent
->GetClientRect());
629 parent
->DoRefreshRect(r
);
632 void wxWindowDFB::Update()
634 if ( !IsShown() || IsFrozen() )
637 GetParent()->Update();
640 void wxWindowDFB::DoThaw()
646 void wxWindowDFB::PaintWindow(const wxRect
& rect
)
648 wxCHECK_RET( !IsFrozen() && IsShown(), "shouldn't be called" );
650 wxLogTrace(TRACE_PAINT
,
651 "%p ('%s'): painting region [%i,%i,%i,%i]",
652 this, GetName().c_str(),
653 rect
.x
, rect
.y
, rect
.GetRight(), rect
.GetBottom());
655 m_updateRegion
= rect
;
657 // FIXME_DFB: don't waste time rendering the area if it's fully covered
658 // by some children, go directly to rendering the children
659 // (unless some child has HasTransparentBackground()=true!)
661 // NB: unconditionally send wxEraseEvent, because our implementation of
662 // wxWindow::Refresh() ignores the eraseBack argument
663 wxWindowDC
dc((wxWindow
*)this);
664 wxEraseEvent
eventEr(m_windowId
, &dc
);
665 eventEr
.SetEventObject(this);
666 HandleWindowEvent(eventEr
);
668 wxRect
clientRect(GetClientRect());
670 // only send wxNcPaintEvent if drawing at least part of nonclient area:
671 if ( !clientRect
.Contains(rect
) )
673 wxNcPaintEvent
eventNc(GetId());
674 eventNc
.SetEventObject(this);
675 HandleWindowEvent(eventNc
);
679 wxLogTrace(TRACE_PAINT
, "%p ('%s'): not sending wxNcPaintEvent",
680 this, GetName().c_str());
683 // only send wxPaintEvent if drawing at least part of client area:
684 if ( rect
.Intersects(clientRect
) )
686 wxPaintEvent
eventPt(GetId());
687 eventPt
.SetEventObject(this);
688 HandleWindowEvent(eventPt
);
692 wxLogTrace(TRACE_PAINT
, "%p ('%s'): not sending wxPaintEvent",
693 this, GetName().c_str());
696 // draw window's overlays on top of the painted window, if we have any:
699 m_updateRegion
.Clear();
701 // client area portion of 'rect':
702 wxRect
rectClientOnly(rect
);
703 rectClientOnly
.Intersect(clientRect
);
705 // paint the children:
706 wxPoint origin
= GetClientAreaOrigin();
707 wxWindowList
& children
= GetChildren();
708 for ( wxWindowList::iterator i
= children
.begin();
709 i
!= children
.end(); ++i
)
711 wxWindow
*child
= *i
;
713 if ( child
->IsFrozen() || !child
->IsShown() )
714 continue; // don't paint anything if the window is frozen or hidden
716 // compute child's area to repaint
717 wxRect
childrect(child
->GetRect());
718 childrect
.Offset(origin
);
720 if ( child
->CanBeOutsideClientArea() )
721 childrect
.Intersect(rect
);
723 childrect
.Intersect(rectClientOnly
);
725 if ( childrect
.IsEmpty() )
729 childrect
.Offset(-child
->GetPosition());
730 childrect
.Offset(-origin
);
731 child
->PaintWindow(childrect
);
735 void wxWindowDFB::PaintOverlays(const wxRect
& rect
)
740 for ( wxDfbOverlaysList::const_iterator i
= m_overlays
->begin();
741 i
!= m_overlays
->end(); ++i
)
743 // FIXME: the cast is necessary for STL build where the iterator
744 // (incorrectly) returns void* and not wxOverlayImpl*
745 wxOverlayImpl
*overlay
= (wxOverlayImpl
*) *i
;
747 wxRect
orectOrig(overlay
->GetRect());
748 wxRect
orect(orectOrig
);
749 orect
.Intersect(rect
);
750 if ( orect
.IsEmpty() )
753 if ( overlay
->IsEmpty() )
754 continue; // nothing to paint
756 DFBRectangle dfbRect
= { orect
.x
- orectOrig
.x
, orect
.y
- orectOrig
.y
,
757 orect
.width
, orect
.height
};
758 GetDfbSurface()->Blit
760 overlay
->GetDirectFBSurface(),
767 void wxWindowDFB::AddOverlay(wxOverlayImpl
*overlay
)
770 m_overlays
= new wxDfbOverlaysList
;
772 m_overlays
->Add(overlay
);
775 void wxWindowDFB::RemoveOverlay(wxOverlayImpl
*overlay
)
777 wxCHECK_RET( m_overlays
, "no overlays to remove" );
779 m_overlays
->Remove(overlay
);
781 if ( m_overlays
->empty() )
783 wxDELETE(m_overlays
);
786 if ( !m_isBeingDeleted
)
787 RefreshWindowRect(overlay
->GetRect());
791 // ---------------------------------------------------------------------------
793 // ---------------------------------------------------------------------------
795 #define KEY(dfb, wx) \
797 wxLogTrace(TRACE_EVENTS, \
798 _T("key " #dfb " mapped to " #wx)); \
801 // returns translated keycode, i.e. the one for KEYUP/KEYDOWN where 'a'..'z' is
802 // translated to 'A'..'Z'
803 static long GetTranslatedKeyCode(DFBInputDeviceKeyIdentifier key_id
)
807 KEY(DIKI_UNKNOWN
, 0);
847 KEY(DIKI_F1
, WXK_F1
);
848 KEY(DIKI_F2
, WXK_F2
);
849 KEY(DIKI_F3
, WXK_F3
);
850 KEY(DIKI_F4
, WXK_F4
);
851 KEY(DIKI_F5
, WXK_F5
);
852 KEY(DIKI_F6
, WXK_F6
);
853 KEY(DIKI_F7
, WXK_F7
);
854 KEY(DIKI_F8
, WXK_F8
);
855 KEY(DIKI_F9
, WXK_F9
);
856 KEY(DIKI_F10
, WXK_F10
);
857 KEY(DIKI_F11
, WXK_F11
);
858 KEY(DIKI_F12
, WXK_F12
);
860 KEY(DIKI_SHIFT_L
, WXK_SHIFT
);
861 KEY(DIKI_SHIFT_R
, WXK_SHIFT
);
862 KEY(DIKI_CONTROL_L
, WXK_CONTROL
);
863 KEY(DIKI_CONTROL_R
, WXK_CONTROL
);
864 KEY(DIKI_ALT_L
, WXK_ALT
);
865 KEY(DIKI_ALT_R
, WXK_ALT
);
866 // this key was removed in 0.9.25 but include it for previous versions
867 // just to avoid gcc warnings about unhandled enum value in switch
868 #if !wxCHECK_DFB_VERSION(0, 9, 24)
873 KEY(DIKI_SUPER_L
, 0);
874 KEY(DIKI_SUPER_R
, 0);
875 KEY(DIKI_HYPER_L
, 0);
876 KEY(DIKI_HYPER_R
, 0);
878 KEY(DIKI_CAPS_LOCK
, 0);
879 KEY(DIKI_NUM_LOCK
, WXK_NUMLOCK
);
880 KEY(DIKI_SCROLL_LOCK
, 0);
882 KEY(DIKI_ESCAPE
, WXK_ESCAPE
);
883 KEY(DIKI_LEFT
, WXK_LEFT
);
884 KEY(DIKI_RIGHT
, WXK_RIGHT
);
885 KEY(DIKI_UP
, WXK_UP
);
886 KEY(DIKI_DOWN
, WXK_DOWN
);
887 KEY(DIKI_TAB
, WXK_TAB
);
888 KEY(DIKI_ENTER
, WXK_RETURN
);
889 KEY(DIKI_SPACE
, WXK_SPACE
);
890 KEY(DIKI_BACKSPACE
, WXK_BACK
);
891 KEY(DIKI_INSERT
, WXK_INSERT
);
892 KEY(DIKI_DELETE
, WXK_DELETE
);
893 KEY(DIKI_HOME
, WXK_HOME
);
894 KEY(DIKI_END
, WXK_END
);
895 KEY(DIKI_PAGE_UP
, WXK_PAGEUP
);
896 KEY(DIKI_PAGE_DOWN
, WXK_PAGEDOWN
);
897 KEY(DIKI_PRINT
, WXK_PRINT
);
898 KEY(DIKI_PAUSE
, WXK_PAUSE
);
900 KEY(DIKI_QUOTE_LEFT
, '`');
901 KEY(DIKI_MINUS_SIGN
, '-');
902 KEY(DIKI_EQUALS_SIGN
, '=');
903 KEY(DIKI_BRACKET_LEFT
, '[');
904 KEY(DIKI_BRACKET_RIGHT
, ']');
905 KEY(DIKI_BACKSLASH
, '\\');
906 KEY(DIKI_SEMICOLON
, ';');
907 KEY(DIKI_QUOTE_RIGHT
, '\'');
908 KEY(DIKI_COMMA
, ',');
909 KEY(DIKI_PERIOD
, '.');
910 KEY(DIKI_SLASH
, '/');
912 KEY(DIKI_LESS_SIGN
, '<');
914 KEY(DIKI_KP_DIV
, WXK_NUMPAD_DIVIDE
);
915 KEY(DIKI_KP_MULT
, WXK_NUMPAD_MULTIPLY
);
916 KEY(DIKI_KP_MINUS
, WXK_NUMPAD_SUBTRACT
);
917 KEY(DIKI_KP_PLUS
, WXK_NUMPAD_ADD
);
918 KEY(DIKI_KP_ENTER
, WXK_NUMPAD_ENTER
);
919 KEY(DIKI_KP_SPACE
, WXK_NUMPAD_SPACE
);
920 KEY(DIKI_KP_TAB
, WXK_NUMPAD_TAB
);
921 KEY(DIKI_KP_F1
, WXK_NUMPAD_F1
);
922 KEY(DIKI_KP_F2
, WXK_NUMPAD_F2
);
923 KEY(DIKI_KP_F3
, WXK_NUMPAD_F3
);
924 KEY(DIKI_KP_F4
, WXK_NUMPAD_F4
);
925 KEY(DIKI_KP_EQUAL
, WXK_NUMPAD_EQUAL
);
926 KEY(DIKI_KP_SEPARATOR
, WXK_NUMPAD_SEPARATOR
);
928 KEY(DIKI_KP_DECIMAL
, WXK_NUMPAD_DECIMAL
);
929 KEY(DIKI_KP_0
, WXK_NUMPAD0
);
930 KEY(DIKI_KP_1
, WXK_NUMPAD1
);
931 KEY(DIKI_KP_2
, WXK_NUMPAD2
);
932 KEY(DIKI_KP_3
, WXK_NUMPAD3
);
933 KEY(DIKI_KP_4
, WXK_NUMPAD4
);
934 KEY(DIKI_KP_5
, WXK_NUMPAD5
);
935 KEY(DIKI_KP_6
, WXK_NUMPAD6
);
936 KEY(DIKI_KP_7
, WXK_NUMPAD7
);
937 KEY(DIKI_KP_8
, WXK_NUMPAD8
);
938 KEY(DIKI_KP_9
, WXK_NUMPAD9
);
940 case DIKI_KEYDEF_END
:
941 case DIKI_NUMBER_OF_KEYS
:
942 wxFAIL_MSG( "invalid key_id value" );
946 return 0; // silence compiler warnings
949 // returns untranslated keycode, i.e. for EVT_CHAR, where characters are left in
950 // the form they were entered (lowercase, diacritics etc.)
951 static long GetUntraslatedKeyCode(DFBInputDeviceKeyIdentifier key_id
,
952 DFBInputDeviceKeySymbol key_symbol
)
954 switch ( DFB_KEY_TYPE(key_symbol
) )
960 if ( key_symbol
< 128 )
965 wchar_t chr
= key_symbol
;
966 wxCharBuffer
buf(wxConvUI
->cWC2MB(&chr
, 1, NULL
));
968 return *buf
; // may be 0 if failed
970 #endif // wxUSE_WCHAR_T
976 return GetTranslatedKeyCode(key_id
);
982 void wxWindowDFB::HandleKeyEvent(const wxDFBWindowEvent
& event_
)
987 const DFBWindowEvent
& e
= event_
;
989 wxLogTrace(TRACE_EVENTS
,
990 "handling key %s event for window %p ('%s')",
991 e
.type
== DWET_KEYUP
? "up" : "down",
992 this, GetName().c_str());
994 // fill in wxKeyEvent fields:
996 event
.SetEventObject(this);
997 event
.SetTimestamp(wxDFB_EVENT_TIMESTAMP(e
));
998 event
.m_rawCode
= e
.key_code
;
999 event
.m_keyCode
= GetTranslatedKeyCode(e
.key_id
);
1000 event
.m_scanCode
= 0; // not used by wx at all
1002 event
.m_uniChar
= e
.key_symbol
;
1004 event
.m_shiftDown
= ( e
.modifiers
& DIMM_SHIFT
) != 0;
1005 event
.m_controlDown
= ( e
.modifiers
& DIMM_CONTROL
) != 0;
1006 event
.m_altDown
= ( e
.modifiers
& DIMM_ALT
) != 0;
1007 event
.m_metaDown
= ( e
.modifiers
& DIMM_META
) != 0;
1009 // translate coordinates from TLW-relative to this window-relative:
1012 GetTLW()->ClientToScreen(&event
.m_x
, &event
.m_y
);
1013 this->ScreenToClient(&event
.m_x
, &event
.m_y
);
1015 if ( e
.type
== DWET_KEYUP
)
1017 event
.SetEventType(wxEVT_KEY_UP
);
1018 HandleWindowEvent(event
);
1022 bool isTab
= (event
.m_keyCode
== WXK_TAB
);
1024 event
.SetEventType(wxEVT_KEY_DOWN
);
1026 if ( HandleWindowEvent(event
) )
1029 // only send wxEVT_CHAR event if not processed yet:
1030 event
.m_keyCode
= GetUntraslatedKeyCode(e
.key_id
, e
.key_symbol
);
1031 if ( event
.m_keyCode
!= 0 )
1033 event
.SetEventType(wxEVT_CHAR
);
1034 if ( HandleWindowEvent(event
) )
1038 // Synthetize navigation key event, but do it only if the TAB key
1039 // wasn't handled yet:
1040 if ( isTab
&& GetParent() && GetParent()->HasFlag(wxTAB_TRAVERSAL
) )
1042 wxNavigationKeyEvent navEvent
;
1043 navEvent
.SetEventObject(GetParent());
1044 // Shift-TAB goes in reverse direction:
1045 navEvent
.SetDirection(!event
.m_shiftDown
);
1046 // Ctrl-TAB changes the (parent) window, i.e. switch notebook page:
1047 navEvent
.SetWindowChange(event
.m_controlDown
);
1048 navEvent
.SetCurrentFocus(wxStaticCast(this, wxWindow
));
1049 GetParent()->HandleWindowEvent(navEvent
);
1054 // ---------------------------------------------------------------------------
1055 // idle events processing
1056 // ---------------------------------------------------------------------------
1058 void wxWindowDFB::OnInternalIdle()
1060 if (wxUpdateUIEvent::CanUpdate(this) && IsShown())
1061 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1065 // Find the wxWindow at the current mouse position, returning the mouse
1067 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1069 return wxFindWindowAtPoint(pt
= wxGetMousePosition());
1072 wxWindow
* wxFindWindowAtPoint(const wxPoint
& WXUNUSED(pt
))
1074 wxFAIL_MSG( "wxFindWindowAtPoint not implemented" );