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 _T("events")
41 #define TRACE_PAINT _T("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 #warning "FIXME: what to do with gs_activeFrame here and elsewhere?"
99 if (gs_activeFrame
== this)
101 gs_activeFrame
= NULL
;
102 // activate next frame in Z-order:
105 wxWindowDFB
*win
= (wxWindowDFB
*)m_wnd
->prev
->userData
;
108 else if ( m_wnd
->next
)
110 wxWindowDFB
*win
= (wxWindowDFB
*)m_wnd
->next
->userData
;
116 if ( gs_focusedWindow
== this )
122 // real construction (Init() must have been called before!)
123 bool wxWindowDFB::Create(wxWindow
*parent
,
128 const wxString
& name
)
130 if ( !m_tlw
&& parent
)
131 m_tlw
= parent
->GetTLW();
133 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
137 parent
->AddChild(this);
139 // set the size to something bogus initially, in case some code tries to
140 // create wxWindowDC before SetSize() is called below:
141 m_rect
.width
= m_rect
.height
= 1;
144 x
= pos
.x
, y
= pos
.y
;
145 if ( x
== -1 ) x
= 0;
146 if ( y
== -1 ) y
= 0;
147 w
= WidthDefault(size
.x
);
148 h
= HeightDefault(size
.y
);
154 // ---------------------------------------------------------------------------
156 // ---------------------------------------------------------------------------
158 wxIDirectFBSurfacePtr
wxWindowDFB::ObtainDfbSurface() const
160 wxCHECK_MSG( m_parent
, NULL
, _T("parentless window?") );
162 wxIDirectFBSurfacePtr
parentSurface(m_parent
->GetDfbSurface());
163 wxCHECK_MSG( parentSurface
, NULL
, _T("invalid parent surface") );
166 AdjustForParentClientOrigin(r
.x
, r
.y
, 0);
167 DFBRectangle rect
= { r
.x
, r
.y
, r
.width
, r
.height
};
169 return parentSurface
->GetSubSurface(&rect
);
172 wxIDirectFBSurfacePtr
wxWindowDFB::GetDfbSurface()
176 m_surface
= ObtainDfbSurface();
177 wxASSERT_MSG( m_surface
, _T("invalid DirectFB surface") );
183 void wxWindowDFB::InvalidateDfbSurface()
187 // surfaces of the children are subsurfaces of this window's surface,
188 // so they must be invalidated as well:
189 wxWindowList
& children
= GetChildren();
190 for ( wxWindowList::iterator i
= children
.begin(); i
!= children
.end(); ++i
)
192 (*i
)->InvalidateDfbSurface();
196 // ---------------------------------------------------------------------------
198 // ---------------------------------------------------------------------------
200 void wxWindowDFB::SetFocus()
202 if ( gs_focusedWindow
== this )
203 return; // nothing to do, focused already
205 wxWindowDFB
*oldFocusedWindow
= gs_focusedWindow
;
207 if ( gs_focusedWindow
)
209 gs_toBeFocusedWindow
= (wxWindow
*)this;
210 gs_focusedWindow
->DFBKillFocus();
211 gs_toBeFocusedWindow
= NULL
;
214 gs_focusedWindow
= this;
216 if ( IsShownOnScreen() )
218 m_tlw
->SetDfbFocus();
220 // else: do nothing, because DirectFB windows cannot have focus if they
221 // are hidden; when the TLW becomes visible, it will set the focus
222 // to use from wxTLW::Show()
224 #warning "FIXME: implement in terms of DWET_{GOT,LOST}FOCUS"
225 #warning "FIXME: keep this or not? not, think multiapp core"
227 wxWindowDFB
*active
= wxGetTopLevelParent((wxWindow
*)this);
228 if ( !(m_windowStyle
& wxPOPUP_WINDOW
) && active
!= gs_activeFrame
)
230 if ( gs_activeFrame
)
232 wxActivateEvent
event(wxEVT_ACTIVATE
, false, gs_activeFrame
->GetId());
233 event
.SetEventObject(gs_activeFrame
);
234 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
237 gs_activeFrame
= active
;
238 wxActivateEvent
event(wxEVT_ACTIVATE
, true, gs_activeFrame
->GetId());
239 event
.SetEventObject(gs_activeFrame
);
240 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
244 // notify the parent keeping track of focus for the kbd navigation
245 // purposes that we got it
246 wxChildFocusEvent
eventFocus((wxWindow
*)this);
247 GetEventHandler()->ProcessEvent(eventFocus
);
249 wxFocusEvent
event(wxEVT_SET_FOCUS
, GetId());
250 event
.SetEventObject(this);
251 event
.SetWindow((wxWindow
*)oldFocusedWindow
);
252 GetEventHandler()->ProcessEvent(event
);
255 // caret needs to be informed about focus change
256 wxCaret
*caret
= GetCaret();
259 #endif // wxUSE_CARET
262 void wxWindowDFB::DFBKillFocus()
264 wxCHECK_RET( gs_focusedWindow
== this,
265 _T("killing focus on window that doesn't have it") );
267 gs_focusedWindow
= NULL
;
269 if ( m_isBeingDeleted
)
270 return; // don't send any events from dtor
273 // caret needs to be informed about focus change
274 wxCaret
*caret
= GetCaret();
276 caret
->OnKillFocus();
277 #endif // wxUSE_CARET
279 wxFocusEvent
event(wxEVT_KILL_FOCUS
, GetId());
280 event
.SetEventObject(this);
281 event
.SetWindow(gs_toBeFocusedWindow
);
282 GetEventHandler()->ProcessEvent(event
);
285 // ----------------------------------------------------------------------------
286 // this wxWindowBase function is implemented here (in platform-specific file)
287 // because it is static and so couldn't be made virtual
288 // ----------------------------------------------------------------------------
289 wxWindow
*wxWindowBase::DoFindFocus()
291 return (wxWindow
*)gs_focusedWindow
;
294 bool wxWindowDFB::Show(bool show
)
296 if ( !wxWindowBase::Show(show
) )
299 // Unlike Refresh(), DoRefreshWindow() doesn't check visibility, so
300 // call it to force refresh of either this window (if showing) or its
301 // parent area at the place of this window (if hiding):
304 #warning "FIXME: all of this must be implemented for DFB"
306 DFB_wmShowWindow(m_wnd
, show
);
308 if (!show
&& gs_activeFrame
== this)
310 // activate next frame in Z-order:
313 wxWindowDFB
*win
= (wxWindowDFB
*)m_wnd
->prev
->userData
;
316 else if ( m_wnd
->next
)
318 wxWindowDFB
*win
= (wxWindowDFB
*)m_wnd
->next
->userData
;
323 gs_activeFrame
= NULL
;
331 // Raise the window to the top of the Z order
332 void wxWindowDFB::Raise()
334 wxFAIL_MSG( _T("Raise() not implemented") );
337 // Lower the window to the bottom of the Z order
338 void wxWindowDFB::Lower()
340 wxFAIL_MSG( _T("Lower() not implemented") );
343 void wxWindowDFB::DoCaptureMouse()
345 #warning "implement this"
347 if ( gs_mouseCapture
)
348 DFB_wmUncaptureEvents(gs_mouseCapture
->m_wnd
, wxDFB_CAPTURE_MOUSE
);
350 gs_mouseCapture
= this;
352 DFB_wmCaptureEvents(m_wnd
, EVT_MOUSEEVT
, wxDFB_CAPTURE_MOUSE
);
356 void wxWindowDFB::DoReleaseMouse()
358 wxASSERT_MSG( gs_mouseCapture
== this, wxT("attempt to release mouse, but this window hasn't captured it") );
360 #warning "implement this"
362 DFB_wmUncaptureEvents(m_wnd
, wxDFB_CAPTURE_MOUSE
);
364 gs_mouseCapture
= NULL
;
367 /* static */ wxWindow
*wxWindowBase::GetCapture()
369 return (wxWindow
*)gs_mouseCapture
;
372 bool wxWindowDFB::SetCursor(const wxCursor
& cursor
)
374 if ( !wxWindowBase::SetCursor(cursor
) )
380 #warning "implement this"
383 DFB_wmSetWindowCursor(m_wnd
, *m_cursor
.GetDFBCursor());
385 DFB_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetDFBCursor());
391 void wxWindowDFB::WarpPointer(int x
, int y
)
394 wxDisplaySize(&w
, &h
);
396 ClientToScreen(&x
, &y
);
399 if ( x
>= w
) x
= w
-1;
400 if ( y
>= h
) y
= h
-1;
402 wxIDirectFBDisplayLayerPtr
layer(wxIDirectFB::Get()->GetDisplayLayer());
403 wxCHECK_RET( layer
, _T("no display layer") );
405 layer
->WarpCursor(x
, y
);
408 // Set this window to be the child of 'parent'.
409 bool wxWindowDFB::Reparent(wxWindowBase
*parent
)
411 if ( !wxWindowBase::Reparent(parent
) )
414 #warning "implement this"
415 wxFAIL_MSG( _T("reparenting not yet implemented") );
420 // ---------------------------------------------------------------------------
421 // moving and resizing
422 // ---------------------------------------------------------------------------
425 void wxWindowDFB::DoGetSize(int *x
, int *y
) const
427 if (x
) *x
= m_rect
.width
;
428 if (y
) *y
= m_rect
.height
;
431 void wxWindowDFB::DoGetPosition(int *x
, int *y
) const
433 if (x
) *x
= m_rect
.x
;
434 if (y
) *y
= m_rect
.y
;
437 static wxPoint
GetScreenPosOfClientOrigin(const wxWindowDFB
*win
)
439 wxCHECK_MSG( win
, wxPoint(0, 0), _T("no window provided") );
441 wxPoint
pt(win
->GetPosition() + win
->GetClientAreaOrigin());
443 if ( !win
->IsTopLevel() )
444 pt
+= GetScreenPosOfClientOrigin(win
->GetParent());
449 void wxWindowDFB::DoScreenToClient(int *x
, int *y
) const
451 wxPoint o
= GetScreenPosOfClientOrigin(this);
457 void wxWindowDFB::DoClientToScreen(int *x
, int *y
) const
459 wxPoint o
= GetScreenPosOfClientOrigin(this);
465 // Get size *available for subwindows* i.e. excluding menu bar etc.
466 void wxWindowDFB::DoGetClientSize(int *x
, int *y
) const
471 void wxWindowDFB::DoMoveWindow(int x
, int y
, int width
, int height
)
473 // NB: [x,y] arguments are in (parent's) window coordinates, while
474 // m_rect.{x,y} are in (parent's) client coordinates. That's why we
475 // offset by parentOrigin in some places below
477 wxPoint
parentOrigin(0, 0);
478 AdjustForParentClientOrigin(parentOrigin
.x
, parentOrigin
.y
);
480 wxRect
oldpos(m_rect
);
481 oldpos
.Offset(parentOrigin
);
483 wxRect
newpos(x
, y
, width
, height
);
485 // input [x,y] is in window coords, but we store client coords in m_rect:
487 m_rect
.Offset(-parentOrigin
);
489 // window's position+size changed and so did the subsurface that covers it
490 InvalidateDfbSurface();
494 // queue both former and new position of the window for repainting:
495 wxWindow
*parent
= GetParent();
497 // only refresh the visible parts:
498 if ( !CanBeOutsideClientArea() )
500 wxRect
parentClient(parent
->GetClientSize());
501 oldpos
.Intersect(parentClient
);
502 newpos
.Intersect(parentClient
);
505 parent
->RefreshRect(oldpos
);
506 parent
->RefreshRect(newpos
);
510 // set the size of the window: if the dimensions are positive, just use them,
511 // but if any of them is equal to -1, it means that we must find the value for
512 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
513 // which case -1 is a valid value for x and y)
515 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
516 // the width/height to best suit our contents, otherwise we reuse the current
518 void wxWindowDFB::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
520 // get the current size and position...
521 int currentX
, currentY
;
522 GetPosition(¤tX
, ¤tY
);
523 int currentW
,currentH
;
524 GetSize(¤tW
, ¤tH
);
526 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
528 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
531 // ... and don't do anything (avoiding flicker) if it's already ok
532 if ( x
== currentX
&& y
== currentY
&&
533 width
== currentW
&& height
== currentH
)
541 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
543 size
= DoGetBestSize();
548 // just take the current one
555 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
559 size
= DoGetBestSize();
561 //else: already called DoGetBestSize() above
567 // just take the current one
572 int maxWidth
= GetMaxWidth(),
573 minWidth
= GetMinWidth(),
574 maxHeight
= GetMaxHeight(),
575 minHeight
= GetMinHeight();
577 if ( minWidth
!= -1 && width
< minWidth
) width
= minWidth
;
578 if ( maxWidth
!= -1 && width
> maxWidth
) width
= maxWidth
;
579 if ( minHeight
!= -1 && height
< minHeight
) height
= minHeight
;
580 if ( maxHeight
!= -1 && height
> maxHeight
) height
= maxHeight
;
582 if ( m_rect
.x
!= x
|| m_rect
.y
!= y
||
583 m_rect
.width
!= width
|| m_rect
.height
!= height
)
585 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
586 DoMoveWindow(x
, y
, width
, height
);
588 wxSize
newSize(width
, height
);
589 wxSizeEvent
event(newSize
, GetId());
590 event
.SetEventObject(this);
591 GetEventHandler()->ProcessEvent(event
);
595 void wxWindowDFB::DoSetClientSize(int width
, int height
)
597 SetSize(width
, height
);
600 // ---------------------------------------------------------------------------
602 // ---------------------------------------------------------------------------
604 int wxWindowDFB::GetCharHeight() const
606 wxWindowDC
dc((wxWindow
*)this);
607 return dc
.GetCharHeight();
610 int wxWindowDFB::GetCharWidth() const
612 wxWindowDC
dc((wxWindow
*)this);
613 return dc
.GetCharWidth();
616 void wxWindowDFB::GetTextExtent(const wxString
& string
,
618 int *descent
, int *externalLeading
,
619 const wxFont
*theFont
) const
621 wxWindowDC
dc((wxWindow
*)this);
622 dc
.GetTextExtent(string
, x
, y
, descent
, externalLeading
, (wxFont
*)theFont
);
626 // ---------------------------------------------------------------------------
628 // ---------------------------------------------------------------------------
630 void wxWindowDFB::Clear()
632 wxClientDC
dc((wxWindow
*)this);
633 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
634 dc
.SetBackground(brush
);
638 void wxWindowDFB::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
640 if ( !IsShown() || IsFrozen() )
643 // NB[1]: We intentionally ignore the eraseBack argument here. This is
644 // because of the way wxDFB's painting is implemented: the refresh
645 // request is propagated up to wxTLW, which is then painted in
646 // top-down order. This means that this window's area is first
647 // painted by its parent and this window is then painted over it, so
648 // it's not safe to not paint this window's background even if
650 // NB[2]: wxWindow::Refresh() takes the rectangle in client coords, but
651 // wxUniv translates it to window coords before passing it to
652 // wxWindowDFB::Refresh(), so we can directly pass the rect to
653 // DoRefreshRect (which takes window, not client, coords) here.
655 DoRefreshRect(*rect
);
660 void wxWindowDFB::RefreshWindowRect(const wxRect
& rect
)
662 if ( !IsShown() || IsFrozen() )
668 void wxWindowDFB::DoRefreshWindow()
670 // NB: DoRefreshRect() takes window coords, not client, so this is correct
671 DoRefreshRect(wxRect(GetSize()));
674 void wxWindowDFB::DoRefreshRect(const wxRect
& rect
)
676 wxWindow
*parent
= GetParent();
677 wxCHECK_RET( parent
, _T("no parent") );
679 // don't overlap outside of the window (NB: 'rect' is in window coords):
681 r
.Intersect(wxRect(GetSize()));
685 wxLogTrace(TRACE_PAINT
,
686 _T("%p ('%s'): refresh rect [%i,%i,%i,%i]"),
687 this, GetName().c_str(),
688 rect
.x
, rect
.y
, rect
.GetRight(), rect
.GetBottom());
690 // convert the refresh rectangle to parent's coordinates and
691 // recursively refresh the parent:
692 r
.Offset(GetPosition());
693 r
.Offset(parent
->GetClientAreaOrigin());
695 // normal windows cannot extend out of its parent's client area, so don't
696 // refresh any hidden parts:
697 if ( !CanBeOutsideClientArea() )
698 r
.Intersect(parent
->GetClientRect());
700 parent
->DoRefreshRect(r
);
703 void wxWindowDFB::Update()
705 if ( !IsShown() || IsFrozen() )
708 GetParent()->Update();
711 void wxWindowDFB::Freeze()
716 void wxWindowDFB::Thaw()
718 wxASSERT_MSG( IsFrozen(), _T("Thaw() without matching Freeze()") );
720 if ( --m_frozenness
== 0 )
727 void wxWindowDFB::PaintWindow(const wxRect
& rect
)
729 wxCHECK_RET( !IsFrozen() && IsShown(), _T("shouldn't be called") );
731 wxLogTrace(TRACE_PAINT
,
732 _T("%p ('%s'): painting region [%i,%i,%i,%i]"),
733 this, GetName().c_str(),
734 rect
.x
, rect
.y
, rect
.GetRight(), rect
.GetBottom());
736 m_updateRegion
= rect
;
738 // FIXME_DFB: don't waste time rendering the area if it's fully covered
739 // by some children, go directly to rendering the children
741 // NB: unconditionally send wxEraseEvent, because our implementation of
742 // wxWindow::Refresh() ignores the eraseBack argument
743 wxWindowDC
dc((wxWindow
*)this);
744 wxEraseEvent
eventEr(m_windowId
, &dc
);
745 eventEr
.SetEventObject(this);
746 GetEventHandler()->ProcessEvent(eventEr
);
748 wxRect
clientRect(GetClientRect());
750 // only send wxNcPaintEvent if drawing at least part of nonclient area:
751 if ( !clientRect
.Contains(rect
) )
753 wxNcPaintEvent
eventNc(GetId());
754 eventNc
.SetEventObject(this);
755 GetEventHandler()->ProcessEvent(eventNc
);
759 wxLogTrace(TRACE_PAINT
, _T("%p ('%s'): not sending wxNcPaintEvent"),
760 this, GetName().c_str());
763 // only send wxPaintEvent if drawing at least part of client area:
764 if ( rect
.Intersects(clientRect
) )
766 wxPaintEvent
eventPt(GetId());
767 eventPt
.SetEventObject(this);
768 GetEventHandler()->ProcessEvent(eventPt
);
772 wxLogTrace(TRACE_PAINT
, _T("%p ('%s'): not sending wxPaintEvent"),
773 this, GetName().c_str());
776 // draw window's overlays on top of the painted window, if we have any:
779 m_updateRegion
.Clear();
781 // client area portion of 'rect':
782 wxRect
rectClientOnly(rect
);
783 rectClientOnly
.Intersect(clientRect
);
785 // paint the children:
786 wxPoint origin
= GetClientAreaOrigin();
787 wxWindowList
& children
= GetChildren();
788 for ( wxWindowList::iterator i
= children
.begin();
789 i
!= children
.end(); ++i
)
791 wxWindow
*child
= *i
;
793 if ( child
->IsFrozen() || !child
->IsShown() )
794 continue; // don't paint anything if the window is frozen or hidden
796 // compute child's area to repaint
797 wxRect
childrect(child
->GetRect());
798 childrect
.Offset(origin
);
800 if ( child
->CanBeOutsideClientArea() )
801 childrect
.Intersect(rect
);
803 childrect
.Intersect(rectClientOnly
);
805 if ( childrect
.IsEmpty() )
809 childrect
.Offset(-child
->GetPosition());
810 childrect
.Offset(-origin
);
811 child
->PaintWindow(childrect
);
815 void wxWindowDFB::PaintOverlays(const wxRect
& rect
)
820 for ( wxDfbOverlaysList::const_iterator i
= m_overlays
->begin();
821 i
!= m_overlays
->end(); ++i
)
823 wxOverlayImpl
*overlay
= *i
;
825 wxRect
orectOrig(overlay
->GetRect());
826 wxRect
orect(orectOrig
);
827 orect
.Intersect(rect
);
828 if ( orect
.IsEmpty() )
831 if ( overlay
->IsEmpty() )
832 continue; // nothing to paint
834 DFBRectangle dfbRect
= { orect
.x
- orectOrig
.x
, orect
.y
- orectOrig
.y
,
835 orect
.width
, orect
.height
};
836 GetDfbSurface()->Blit
838 overlay
->GetDirectFBSurface(),
845 void wxWindowDFB::AddOverlay(wxOverlayImpl
*overlay
)
848 m_overlays
= new wxDfbOverlaysList
;
850 m_overlays
->Add(overlay
);
853 void wxWindowDFB::RemoveOverlay(wxOverlayImpl
*overlay
)
855 wxCHECK_RET( m_overlays
, _T("no overlays to remove") );
857 m_overlays
->Remove(overlay
);
859 if ( m_overlays
->empty() )
861 wxDELETE(m_overlays
);
864 if ( !m_isBeingDeleted
)
865 RefreshWindowRect(overlay
->GetRect());
869 // ---------------------------------------------------------------------------
871 // ---------------------------------------------------------------------------
873 #define KEY(dfb, wx) \
875 wxLogTrace(TRACE_EVENTS, \
876 _T("key " #dfb " mapped to " #wx)); \
879 // returns translated keycode, i.e. the one for KEYUP/KEYDOWN where 'a'..'z' is
880 // translated to 'A'..'Z'
881 static long GetTranslatedKeyCode(DFBInputDeviceKeyIdentifier key_id
)
885 KEY(DIKI_UNKNOWN
, 0);
925 KEY(DIKI_F1
, WXK_F1
);
926 KEY(DIKI_F2
, WXK_F2
);
927 KEY(DIKI_F3
, WXK_F3
);
928 KEY(DIKI_F4
, WXK_F4
);
929 KEY(DIKI_F5
, WXK_F5
);
930 KEY(DIKI_F6
, WXK_F6
);
931 KEY(DIKI_F7
, WXK_F7
);
932 KEY(DIKI_F8
, WXK_F8
);
933 KEY(DIKI_F9
, WXK_F9
);
934 KEY(DIKI_F10
, WXK_F10
);
935 KEY(DIKI_F11
, WXK_F11
);
936 KEY(DIKI_F12
, WXK_F12
);
938 KEY(DIKI_SHIFT_L
, WXK_SHIFT
);
939 KEY(DIKI_SHIFT_R
, WXK_SHIFT
);
940 KEY(DIKI_CONTROL_L
, WXK_CONTROL
);
941 KEY(DIKI_CONTROL_R
, WXK_CONTROL
);
942 KEY(DIKI_ALT_L
, WXK_ALT
);
943 KEY(DIKI_ALT_R
, WXK_ALT
);
944 // this key was removed in 0.9.25 but include it for previous versions
945 // just to avoid gcc warnings about unhandled enum value in switch
946 #if !wxCHECK_DFB_VERSION(0, 9, 24)
951 KEY(DIKI_SUPER_L
, 0);
952 KEY(DIKI_SUPER_R
, 0);
953 KEY(DIKI_HYPER_L
, 0);
954 KEY(DIKI_HYPER_R
, 0);
956 KEY(DIKI_CAPS_LOCK
, 0);
957 KEY(DIKI_NUM_LOCK
, WXK_NUMLOCK
);
958 KEY(DIKI_SCROLL_LOCK
, 0);
960 KEY(DIKI_ESCAPE
, WXK_ESCAPE
);
961 KEY(DIKI_LEFT
, WXK_LEFT
);
962 KEY(DIKI_RIGHT
, WXK_RIGHT
);
963 KEY(DIKI_UP
, WXK_UP
);
964 KEY(DIKI_DOWN
, WXK_DOWN
);
965 KEY(DIKI_TAB
, WXK_TAB
);
966 KEY(DIKI_ENTER
, WXK_RETURN
);
967 KEY(DIKI_SPACE
, WXK_SPACE
);
968 KEY(DIKI_BACKSPACE
, WXK_BACK
);
969 KEY(DIKI_INSERT
, WXK_INSERT
);
970 KEY(DIKI_DELETE
, WXK_DELETE
);
971 KEY(DIKI_HOME
, WXK_HOME
);
972 KEY(DIKI_END
, WXK_END
);
973 KEY(DIKI_PAGE_UP
, WXK_PAGEUP
);
974 KEY(DIKI_PAGE_DOWN
, WXK_PAGEDOWN
);
975 KEY(DIKI_PRINT
, WXK_PRINT
);
976 KEY(DIKI_PAUSE
, WXK_PAUSE
);
978 KEY(DIKI_QUOTE_LEFT
, '`');
979 KEY(DIKI_MINUS_SIGN
, '-');
980 KEY(DIKI_EQUALS_SIGN
, '=');
981 KEY(DIKI_BRACKET_LEFT
, '[');
982 KEY(DIKI_BRACKET_RIGHT
, ']');
983 KEY(DIKI_BACKSLASH
, '\\');
984 KEY(DIKI_SEMICOLON
, ';');
985 KEY(DIKI_QUOTE_RIGHT
, '\'');
986 KEY(DIKI_COMMA
, ',');
987 KEY(DIKI_PERIOD
, '.');
988 KEY(DIKI_SLASH
, '/');
990 KEY(DIKI_LESS_SIGN
, '<');
992 KEY(DIKI_KP_DIV
, WXK_NUMPAD_DIVIDE
);
993 KEY(DIKI_KP_MULT
, WXK_NUMPAD_MULTIPLY
);
994 KEY(DIKI_KP_MINUS
, WXK_NUMPAD_SUBTRACT
);
995 KEY(DIKI_KP_PLUS
, WXK_NUMPAD_ADD
);
996 KEY(DIKI_KP_ENTER
, WXK_NUMPAD_ENTER
);
997 KEY(DIKI_KP_SPACE
, WXK_NUMPAD_SPACE
);
998 KEY(DIKI_KP_TAB
, WXK_NUMPAD_TAB
);
999 KEY(DIKI_KP_F1
, WXK_NUMPAD_F1
);
1000 KEY(DIKI_KP_F2
, WXK_NUMPAD_F2
);
1001 KEY(DIKI_KP_F3
, WXK_NUMPAD_F3
);
1002 KEY(DIKI_KP_F4
, WXK_NUMPAD_F4
);
1003 KEY(DIKI_KP_EQUAL
, WXK_NUMPAD_EQUAL
);
1004 KEY(DIKI_KP_SEPARATOR
, WXK_NUMPAD_SEPARATOR
);
1006 KEY(DIKI_KP_DECIMAL
, WXK_NUMPAD_DECIMAL
);
1007 KEY(DIKI_KP_0
, WXK_NUMPAD0
);
1008 KEY(DIKI_KP_1
, WXK_NUMPAD1
);
1009 KEY(DIKI_KP_2
, WXK_NUMPAD2
);
1010 KEY(DIKI_KP_3
, WXK_NUMPAD3
);
1011 KEY(DIKI_KP_4
, WXK_NUMPAD4
);
1012 KEY(DIKI_KP_5
, WXK_NUMPAD5
);
1013 KEY(DIKI_KP_6
, WXK_NUMPAD6
);
1014 KEY(DIKI_KP_7
, WXK_NUMPAD7
);
1015 KEY(DIKI_KP_8
, WXK_NUMPAD8
);
1016 KEY(DIKI_KP_9
, WXK_NUMPAD9
);
1018 case DIKI_KEYDEF_END
:
1019 case DIKI_NUMBER_OF_KEYS
:
1020 wxFAIL_MSG( _T("invalid key_id value") );
1024 return 0; // silence compiler warnings
1027 // returns untranslated keycode, i.e. for EVT_CHAR, where characters are left in
1028 // the form they were entered (lowercase, diacritics etc.)
1029 static long GetUntraslatedKeyCode(DFBInputDeviceKeyIdentifier key_id
,
1030 DFBInputDeviceKeySymbol key_symbol
)
1032 switch ( DFB_KEY_TYPE(key_symbol
) )
1038 if ( key_symbol
< 128 )
1043 wchar_t chr
= key_symbol
;
1044 wxCharBuffer
buf(wxConvUI
->cWC2MB(&chr
, 1, NULL
));
1046 return *buf
; // may be 0 if failed
1048 #endif // wxUSE_WCHAR_T
1054 return GetTranslatedKeyCode(key_id
);
1060 void wxWindowDFB::HandleKeyEvent(const wxDFBWindowEvent
& event_
)
1065 const DFBWindowEvent
& e
= event_
;
1067 wxLogTrace(TRACE_EVENTS
,
1068 _T("handling key %s event for window %p ('%s')"),
1069 e
.type
== DWET_KEYUP
? _T("up") : _T("down"),
1070 this, GetName().c_str());
1072 // fill in wxKeyEvent fields:
1074 event
.SetEventObject(this);
1075 event
.SetTimestamp(wxDFB_EVENT_TIMESTAMP(e
));
1076 event
.m_rawCode
= e
.key_code
;
1077 event
.m_keyCode
= GetTranslatedKeyCode(e
.key_id
);
1078 event
.m_scanCode
= 0; // not used by wx at all
1080 event
.m_uniChar
= e
.key_symbol
;
1082 event
.m_shiftDown
= ( e
.modifiers
& DIMM_SHIFT
) != 0;
1083 event
.m_controlDown
= ( e
.modifiers
& DIMM_CONTROL
) != 0;
1084 event
.m_altDown
= ( e
.modifiers
& DIMM_ALT
) != 0;
1085 event
.m_metaDown
= ( e
.modifiers
& DIMM_META
) != 0;
1087 // translate coordinates from TLW-relative to this window-relative:
1090 GetTLW()->ClientToScreen(&event
.m_x
, &event
.m_y
);
1091 this->ScreenToClient(&event
.m_x
, &event
.m_y
);
1093 if ( e
.type
== DWET_KEYUP
)
1095 event
.SetEventType(wxEVT_KEY_UP
);
1096 GetEventHandler()->ProcessEvent(event
);
1100 bool isTab
= (event
.m_keyCode
== WXK_TAB
);
1102 event
.SetEventType(wxEVT_KEY_DOWN
);
1104 if ( GetEventHandler()->ProcessEvent(event
) )
1107 // only send wxEVT_CHAR event if not processed yet:
1108 event
.m_keyCode
= GetUntraslatedKeyCode(e
.key_id
, e
.key_symbol
);
1109 if ( event
.m_keyCode
!= 0 )
1111 event
.SetEventType(wxEVT_CHAR
);
1112 if ( GetEventHandler()->ProcessEvent(event
) )
1116 // Synthetize navigation key event, but do it only if the TAB key
1117 // wasn't handled yet:
1118 if ( isTab
&& GetParent() && GetParent()->HasFlag(wxTAB_TRAVERSAL
) )
1120 wxNavigationKeyEvent navEvent
;
1121 navEvent
.SetEventObject(GetParent());
1122 // Shift-TAB goes in reverse direction:
1123 navEvent
.SetDirection(!event
.m_shiftDown
);
1124 // Ctrl-TAB changes the (parent) window, i.e. switch notebook page:
1125 navEvent
.SetWindowChange(event
.m_controlDown
);
1126 navEvent
.SetCurrentFocus(wxStaticCast(this, wxWindow
));
1127 GetParent()->GetEventHandler()->ProcessEvent(navEvent
);
1132 // ---------------------------------------------------------------------------
1133 // idle events processing
1134 // ---------------------------------------------------------------------------
1136 void wxWindowDFB::OnInternalIdle()
1138 if (wxUpdateUIEvent::CanUpdate(this))
1139 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1143 // Find the wxWindow at the current mouse position, returning the mouse
1145 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1147 return wxFindWindowAtPoint(pt
= wxGetMousePosition());
1150 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
1152 wxFAIL_MSG( _T("wxFindWindowAtPoint not implemented") );