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"
35 #include "wx/dfb/private.h"
37 #define TRACE_EVENTS _T("events")
38 #define TRACE_PAINT _T("paint")
40 // ===========================================================================
42 // ===========================================================================
44 // ---------------------------------------------------------------------------
46 // ---------------------------------------------------------------------------
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
52 static wxWindow
*gs_toBeFocusedWindow
= NULL
;
53 // the window that has mouse capture
54 static wxWindowDFB
*gs_mouseCapture
= NULL
;
56 // ---------------------------------------------------------------------------
58 // ---------------------------------------------------------------------------
60 // in wxUniv this class is abstract because it doesn't have DoPopupMenu()
61 IMPLEMENT_ABSTRACT_CLASS(wxWindowDFB
, wxWindowBase
)
63 BEGIN_EVENT_TABLE(wxWindowDFB
, wxWindowBase
)
66 // ----------------------------------------------------------------------------
67 // constructors and such
68 // ----------------------------------------------------------------------------
70 void wxWindowDFB::Init()
78 wxWindowDFB::~wxWindowDFB()
82 m_isBeingDeleted
= true;
84 if ( gs_mouseCapture
== this )
87 #warning "FIXME: what to do with gs_activeFrame here and elsewhere?"
89 if (gs_activeFrame
== this)
91 gs_activeFrame
= NULL
;
92 // activate next frame in Z-order:
95 wxWindowDFB
*win
= (wxWindowDFB
*)m_wnd
->prev
->userData
;
98 else if ( m_wnd
->next
)
100 wxWindowDFB
*win
= (wxWindowDFB
*)m_wnd
->next
->userData
;
106 if ( gs_focusedWindow
== this )
112 // real construction (Init() must have been called before!)
113 bool wxWindowDFB::Create(wxWindow
*parent
,
118 const wxString
& name
)
120 if ( !m_tlw
&& parent
)
121 m_tlw
= parent
->GetTLW();
123 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
127 parent
->AddChild(this);
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;
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
);
144 // ---------------------------------------------------------------------------
146 // ---------------------------------------------------------------------------
148 wxIDirectFBSurfacePtr
wxWindowDFB::ObtainDfbSurface() const
150 wxCHECK_MSG( m_parent
, NULL
, _T("parentless window?") );
152 wxIDirectFBSurfacePtr
parentSurface(m_parent
->GetDfbSurface());
153 wxCHECK_MSG( parentSurface
, NULL
, _T("invalid parent surface") );
156 AdjustForParentClientOrigin(r
.x
, r
.y
, 0);
157 DFBRectangle rect
= { r
.x
, r
.y
, r
.width
, r
.height
};
159 return parentSurface
->GetSubSurface(&rect
);
162 wxIDirectFBSurfacePtr
wxWindowDFB::GetDfbSurface()
166 m_surface
= ObtainDfbSurface();
167 wxASSERT_MSG( m_surface
, _T("invalid DirectFB surface") );
173 void wxWindowDFB::InvalidateDfbSurface()
178 // ---------------------------------------------------------------------------
180 // ---------------------------------------------------------------------------
182 void wxWindowDFB::SetFocus()
184 if ( gs_focusedWindow
== this ) return;
186 wxWindowDFB
*oldFocusedWindow
= gs_focusedWindow
;
188 if ( gs_focusedWindow
)
190 gs_toBeFocusedWindow
= (wxWindow
*)this;
191 gs_focusedWindow
->KillFocus();
192 gs_toBeFocusedWindow
= NULL
;
195 #warning "FIXME: implement in terms of DWET_{GOT,LOST}FOCUS"
197 wxIDirectFBWindowPtr
dfbwin(m_tlw
->GetDirectFBWindow());
198 #warning "FIXME: RequestFocus() may only be called on visible TLW"
199 if ( !dfbwin
->RequestFocus() )
202 gs_focusedWindow
= this;
204 #warning "FIXME: keep this or not? not, think multiapp core"
206 wxWindowDFB
*active
= wxGetTopLevelParent((wxWindow
*)this);
207 if ( !(m_windowStyle
& wxPOPUP_WINDOW
) && active
!= gs_activeFrame
)
209 if ( gs_activeFrame
)
211 wxActivateEvent
event(wxEVT_ACTIVATE
, false, gs_activeFrame
->GetId());
212 event
.SetEventObject(gs_activeFrame
);
213 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
216 gs_activeFrame
= active
;
217 wxActivateEvent
event(wxEVT_ACTIVATE
, true, gs_activeFrame
->GetId());
218 event
.SetEventObject(gs_activeFrame
);
219 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
223 wxFocusEvent
event(wxEVT_SET_FOCUS
, GetId());
224 event
.SetEventObject(this);
225 event
.SetWindow((wxWindow
*)oldFocusedWindow
);
226 GetEventHandler()->ProcessEvent(event
);
229 // caret needs to be informed about focus change
230 wxCaret
*caret
= GetCaret();
233 #endif // wxUSE_CARET
236 void wxWindowDFB::KillFocus()
238 if ( gs_focusedWindow
!= this ) return;
239 gs_focusedWindow
= NULL
;
241 if ( m_isBeingDeleted
) return;
244 // caret needs to be informed about focus change
245 wxCaret
*caret
= GetCaret();
247 caret
->OnKillFocus();
248 #endif // wxUSE_CARET
250 wxFocusEvent
event(wxEVT_KILL_FOCUS
, GetId());
251 event
.SetEventObject(this);
252 event
.SetWindow(gs_toBeFocusedWindow
);
253 GetEventHandler()->ProcessEvent(event
);
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()
262 return (wxWindow
*)gs_focusedWindow
;
265 bool wxWindowDFB::Show(bool show
)
267 if ( !wxWindowBase::Show(show
) )
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):
275 #warning "FIXME: all of this must be implemented for DFB"
277 DFB_wmShowWindow(m_wnd
, show
);
279 if (!show
&& gs_activeFrame
== this)
281 // activate next frame in Z-order:
284 wxWindowDFB
*win
= (wxWindowDFB
*)m_wnd
->prev
->userData
;
287 else if ( m_wnd
->next
)
289 wxWindowDFB
*win
= (wxWindowDFB
*)m_wnd
->next
->userData
;
294 gs_activeFrame
= NULL
;
302 // Raise the window to the top of the Z order
303 void wxWindowDFB::Raise()
305 wxFAIL_MSG( _T("Raise() not implemented") );
308 // Lower the window to the bottom of the Z order
309 void wxWindowDFB::Lower()
311 wxFAIL_MSG( _T("Lower() not implemented") );
314 void wxWindowDFB::DoCaptureMouse()
316 #warning "implement this"
318 if ( gs_mouseCapture
)
319 DFB_wmUncaptureEvents(gs_mouseCapture
->m_wnd
, wxDFB_CAPTURE_MOUSE
);
321 gs_mouseCapture
= this;
323 DFB_wmCaptureEvents(m_wnd
, EVT_MOUSEEVT
, wxDFB_CAPTURE_MOUSE
);
327 void wxWindowDFB::DoReleaseMouse()
329 wxASSERT_MSG( gs_mouseCapture
== this, wxT("attempt to release mouse, but this window hasn't captured it") );
331 #warning "implement this"
333 DFB_wmUncaptureEvents(m_wnd
, wxDFB_CAPTURE_MOUSE
);
335 gs_mouseCapture
= NULL
;
338 /* static */ wxWindow
*wxWindowBase::GetCapture()
340 return (wxWindow
*)gs_mouseCapture
;
343 bool wxWindowDFB::SetCursor(const wxCursor
& cursor
)
345 if ( !wxWindowBase::SetCursor(cursor
) )
351 #warning "implement this"
354 DFB_wmSetWindowCursor(m_wnd
, *m_cursor
.GetDFBCursor());
356 DFB_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetDFBCursor());
362 void wxWindowDFB::WarpPointer(int x
, int y
)
365 wxDisplaySize(&w
, &h
);
367 ClientToScreen(&x
, &y
);
370 if ( x
>= w
) x
= w
-1;
371 if ( y
>= h
) y
= h
-1;
373 wxIDirectFBDisplayLayerPtr
layer(wxIDirectFB::Get()->GetDisplayLayer());
374 wxCHECK_RET( layer
, _T("no display layer") );
376 layer
->WarpCursor(x
, y
);
379 // Set this window to be the child of 'parent'.
380 bool wxWindowDFB::Reparent(wxWindowBase
*parent
)
382 if ( !wxWindowBase::Reparent(parent
) )
385 #warning "implement this"
386 wxFAIL_MSG( _T("reparenting not yet implemented") );
391 // ---------------------------------------------------------------------------
392 // moving and resizing
393 // ---------------------------------------------------------------------------
396 void wxWindowDFB::DoGetSize(int *x
, int *y
) const
398 if (x
) *x
= m_rect
.width
;
399 if (y
) *y
= m_rect
.height
;
402 void wxWindowDFB::DoGetPosition(int *x
, int *y
) const
404 if (x
) *x
= m_rect
.x
;
405 if (y
) *y
= m_rect
.y
;
408 static wxPoint
GetScreenPosOfClientOrigin(const wxWindowDFB
*win
)
410 wxCHECK_MSG( win
, wxPoint(0, 0), _T("no window provided") );
412 wxPoint
pt(win
->GetPosition() + win
->GetClientAreaOrigin());
414 if ( !win
->IsTopLevel() )
415 pt
+= GetScreenPosOfClientOrigin(win
->GetParent());
420 void wxWindowDFB::DoScreenToClient(int *x
, int *y
) const
422 wxPoint o
= GetScreenPosOfClientOrigin(this);
428 void wxWindowDFB::DoClientToScreen(int *x
, int *y
) const
430 wxPoint o
= GetScreenPosOfClientOrigin(this);
436 // Get size *available for subwindows* i.e. excluding menu bar etc.
437 void wxWindowDFB::DoGetClientSize(int *x
, int *y
) const
442 void wxWindowDFB::DoMoveWindow(int x
, int y
, int width
, int height
)
444 wxRect
oldpos(m_rect
);
445 wxRect
newpos(x
, y
, width
, height
);
449 // window's position+size changed and so did the subsurface that covers it
450 InvalidateDfbSurface();
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
);
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)
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
472 void wxWindowDFB::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
474 // get the current size and position...
475 int currentX
, currentY
;
476 GetPosition(¤tX
, ¤tY
);
477 int currentW
,currentH
;
478 GetSize(¤tW
, ¤tH
);
480 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
482 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
485 // ... and don't do anything (avoiding flicker) if it's already ok
486 if ( x
== currentX
&& y
== currentY
&&
487 width
== currentW
&& height
== currentH
)
492 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
497 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
499 size
= DoGetBestSize();
504 // just take the current one
511 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
515 size
= DoGetBestSize();
517 //else: already called DoGetBestSize() above
523 // just take the current one
528 int maxWidth
= GetMaxWidth(),
529 minWidth
= GetMinWidth(),
530 maxHeight
= GetMaxHeight(),
531 minHeight
= GetMinHeight();
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
;
538 if ( m_rect
.x
!= x
|| m_rect
.y
!= y
||
539 m_rect
.width
!= width
|| m_rect
.height
!= height
)
541 DoMoveWindow(x
, y
, width
, height
);
543 wxSize
newSize(width
, height
);
544 wxSizeEvent
event(newSize
, GetId());
545 event
.SetEventObject(this);
546 GetEventHandler()->ProcessEvent(event
);
550 void wxWindowDFB::DoSetClientSize(int width
, int height
)
552 SetSize(width
, height
);
555 // ---------------------------------------------------------------------------
557 // ---------------------------------------------------------------------------
559 int wxWindowDFB::GetCharHeight() const
561 wxWindowDC
dc((wxWindow
*)this);
562 return dc
.GetCharHeight();
565 int wxWindowDFB::GetCharWidth() const
567 wxWindowDC
dc((wxWindow
*)this);
568 return dc
.GetCharWidth();
571 void wxWindowDFB::GetTextExtent(const wxString
& string
,
573 int *descent
, int *externalLeading
,
574 const wxFont
*theFont
) const
576 wxWindowDC
dc((wxWindow
*)this);
577 dc
.GetTextExtent(string
, x
, y
, descent
, externalLeading
, (wxFont
*)theFont
);
581 // ---------------------------------------------------------------------------
583 // ---------------------------------------------------------------------------
585 void wxWindowDFB::Clear()
587 wxClientDC
dc((wxWindow
*)this);
588 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
589 dc
.SetBackground(brush
);
593 void wxWindowDFB::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
595 if ( !IsShown() || IsFrozen() )
598 // NB[1]: We intentionally ignore the eraseBack argument here. This is
599 // because of the way wxDFB's painting is implemented: the refresh
600 // request is probagated up to wxTLW, which is then painted in
601 // top-down order. This means that this window's area is first
602 // painted by its parent and this window is then painted over it, so
603 // it's not safe to not paint this window's background even if
605 // NB[2]: wxWindow::Refresh() takes the rectangle in client coords, but
606 // wxUniv translates it to window coords before passing it to
607 // wxWindowDFB::Refresh(), so we can directly pass the rect to
608 // DoRefreshRect (which takes window, not client, coords) here.
610 DoRefreshRect(*rect
);
615 void wxWindowDFB::DoRefreshWindow()
617 // NB: DoRefreshRect() takes window coords, not client, so this is correct
618 DoRefreshRect(wxRect(GetSize()));
621 void wxWindowDFB::DoRefreshRect(const wxRect
& rect
)
623 wxWindow
*parent
= GetParent();
624 wxCHECK_RET( parent
, _T("no parent") );
626 // don't overlap outside of the window (NB: 'rect' is in window coords):
628 r
.Intersect(wxRect(GetSize()));
632 wxLogTrace(TRACE_PAINT
,
633 _T("%p ('%s'): refresh rect [%i,%i,%i,%i]"),
634 this, GetName().c_str(),
635 rect
.x
, rect
.y
, rect
.GetRight(), rect
.GetBottom());
637 // convert the refresh rectangle to parent's coordinates and
638 // recursively refresh the parent:
639 r
.Offset(GetPosition());
640 r
.Offset(parent
->GetClientAreaOrigin());
642 parent
->DoRefreshRect(r
);
645 void wxWindowDFB::Update()
647 if ( !IsShown() || IsFrozen() )
650 GetParent()->Update();
653 void wxWindowDFB::Freeze()
658 void wxWindowDFB::Thaw()
660 wxASSERT_MSG( IsFrozen(), _T("Thaw() without matching Freeze()") );
662 if ( --m_frozenness
== 0 )
669 void wxWindowDFB::PaintWindow(const wxRect
& rect
)
671 wxCHECK_RET( !IsFrozen() && IsShown(), _T("shouldn't be called") );
673 wxLogTrace(TRACE_PAINT
,
674 _T("%p ('%s'): painting region [%i,%i,%i,%i]"),
675 this, GetName().c_str(),
676 rect
.x
, rect
.y
, rect
.GetRight(), rect
.GetBottom());
678 m_updateRegion
= rect
;
681 // must hide caret temporarily, otherwise we'd get rendering artifacts
682 wxCaret
*caret
= GetCaret();
685 #endif // wxUSE_CARET
687 // FIXME_DFB: don't waste time rendering the area if it's fully covered
688 // by some children, go directly to rendering the children
690 // NB: unconditionally send wxEraseEvent, because our implementation of
691 // wxWindow::Refresh() ignores the eraseBack argument
692 wxWindowDC
dc((wxWindow
*)this);
693 wxEraseEvent
eventEr(m_windowId
, &dc
);
694 eventEr
.SetEventObject(this);
695 GetEventHandler()->ProcessEvent(eventEr
);
697 wxRect
clientRect(GetClientRect());
699 // only send wxNcPaintEvent if drawing at least part of nonclient area:
700 if ( !clientRect
.Contains(rect
) )
702 wxNcPaintEvent
eventNc(GetId());
703 eventNc
.SetEventObject(this);
704 GetEventHandler()->ProcessEvent(eventNc
);
708 wxLogTrace(TRACE_PAINT
, _T("%p ('%s'): not sending wxNcPaintEvent"),
709 this, GetName().c_str());
712 // only send wxPaintEvent if drawing at least part of client area:
713 if ( rect
.Intersects(clientRect
) )
715 wxPaintEvent
eventPt(GetId());
716 eventPt
.SetEventObject(this);
717 GetEventHandler()->ProcessEvent(eventPt
);
721 wxLogTrace(TRACE_PAINT
, _T("%p ('%s'): not sending wxPaintEvent"),
722 this, GetName().c_str());
728 #endif // wxUSE_CARET
730 m_updateRegion
.Clear();
732 // paint the children:
733 wxPoint origin
= GetClientAreaOrigin();
734 wxWindowList
& children
= GetChildren();
735 for ( wxWindowList::iterator i
= children
.begin();
736 i
!= children
.end(); ++i
)
738 wxWindow
*child
= *i
;
740 if ( child
->IsFrozen() || !child
->IsShown() )
741 continue; // don't paint anything if the window is frozen or hidden
743 // compute child's area to repaint
744 wxRect
childrect(child
->GetRect());
745 childrect
.Offset(origin
);
746 childrect
.Intersect(rect
);
747 if ( childrect
.IsEmpty() )
751 childrect
.Offset(-child
->GetPosition());
752 childrect
.Offset(-origin
);
753 child
->PaintWindow(childrect
);
758 // ---------------------------------------------------------------------------
760 // ---------------------------------------------------------------------------
762 #define KEY(dfb, wx) \
764 wxLogTrace(TRACE_EVENTS, \
765 _T("key " #dfb " mapped to " #wx)); \
768 // returns translated keycode, i.e. the one for KEYUP/KEYDOWN where 'a'..'z' is
769 // translated to 'A'..'Z'
770 static long GetTranslatedKeyCode(DFBInputDeviceKeyIdentifier key_id
)
774 KEY(DIKI_UNKNOWN
, 0);
814 KEY(DIKI_F1
, WXK_F1
);
815 KEY(DIKI_F2
, WXK_F2
);
816 KEY(DIKI_F3
, WXK_F3
);
817 KEY(DIKI_F4
, WXK_F4
);
818 KEY(DIKI_F5
, WXK_F5
);
819 KEY(DIKI_F6
, WXK_F6
);
820 KEY(DIKI_F7
, WXK_F7
);
821 KEY(DIKI_F8
, WXK_F8
);
822 KEY(DIKI_F9
, WXK_F9
);
823 KEY(DIKI_F10
, WXK_F10
);
824 KEY(DIKI_F11
, WXK_F11
);
825 KEY(DIKI_F12
, WXK_F12
);
827 KEY(DIKI_SHIFT_L
, WXK_SHIFT
);
828 KEY(DIKI_SHIFT_R
, WXK_SHIFT
);
829 KEY(DIKI_CONTROL_L
, WXK_CONTROL
);
830 KEY(DIKI_CONTROL_R
, WXK_CONTROL
);
831 KEY(DIKI_ALT_L
, WXK_ALT
);
832 KEY(DIKI_ALT_R
, WXK_ALT
);
835 KEY(DIKI_SUPER_L
, 0);
836 KEY(DIKI_SUPER_R
, 0);
837 KEY(DIKI_HYPER_L
, 0);
838 KEY(DIKI_HYPER_R
, 0);
840 KEY(DIKI_CAPS_LOCK
, 0);
841 KEY(DIKI_NUM_LOCK
, WXK_NUMLOCK
);
842 KEY(DIKI_SCROLL_LOCK
, 0);
844 KEY(DIKI_ESCAPE
, WXK_ESCAPE
);
845 KEY(DIKI_LEFT
, WXK_LEFT
);
846 KEY(DIKI_RIGHT
, WXK_RIGHT
);
847 KEY(DIKI_UP
, WXK_UP
);
848 KEY(DIKI_DOWN
, WXK_DOWN
);
849 KEY(DIKI_TAB
, WXK_TAB
);
850 KEY(DIKI_ENTER
, WXK_RETURN
);
851 KEY(DIKI_SPACE
, WXK_SPACE
);
852 KEY(DIKI_BACKSPACE
, WXK_BACK
);
853 KEY(DIKI_INSERT
, WXK_INSERT
);
854 KEY(DIKI_DELETE
, WXK_DELETE
);
855 KEY(DIKI_HOME
, WXK_HOME
);
856 KEY(DIKI_END
, WXK_END
);
857 KEY(DIKI_PAGE_UP
, WXK_PAGEUP
);
858 KEY(DIKI_PAGE_DOWN
, WXK_PAGEDOWN
);
859 KEY(DIKI_PRINT
, WXK_PRINT
);
860 KEY(DIKI_PAUSE
, WXK_PAUSE
);
862 KEY(DIKI_QUOTE_LEFT
, '`');
863 KEY(DIKI_MINUS_SIGN
, '-');
864 KEY(DIKI_EQUALS_SIGN
, '=');
865 KEY(DIKI_BRACKET_LEFT
, '[');
866 KEY(DIKI_BRACKET_RIGHT
, ']');
867 KEY(DIKI_BACKSLASH
, '\\');
868 KEY(DIKI_SEMICOLON
, ';');
869 KEY(DIKI_QUOTE_RIGHT
, '\'');
870 KEY(DIKI_COMMA
, ',');
871 KEY(DIKI_PERIOD
, '.');
872 KEY(DIKI_SLASH
, '/');
874 KEY(DIKI_LESS_SIGN
, '<');
876 KEY(DIKI_KP_DIV
, WXK_NUMPAD_DIVIDE
);
877 KEY(DIKI_KP_MULT
, WXK_NUMPAD_MULTIPLY
);
878 KEY(DIKI_KP_MINUS
, WXK_NUMPAD_SUBTRACT
);
879 KEY(DIKI_KP_PLUS
, WXK_NUMPAD_ADD
);
880 KEY(DIKI_KP_ENTER
, WXK_NUMPAD_ENTER
);
881 KEY(DIKI_KP_SPACE
, WXK_NUMPAD_SPACE
);
882 KEY(DIKI_KP_TAB
, WXK_NUMPAD_TAB
);
883 KEY(DIKI_KP_F1
, WXK_NUMPAD_F1
);
884 KEY(DIKI_KP_F2
, WXK_NUMPAD_F2
);
885 KEY(DIKI_KP_F3
, WXK_NUMPAD_F3
);
886 KEY(DIKI_KP_F4
, WXK_NUMPAD_F4
);
887 KEY(DIKI_KP_EQUAL
, WXK_NUMPAD_EQUAL
);
888 KEY(DIKI_KP_SEPARATOR
, WXK_NUMPAD_SEPARATOR
);
890 KEY(DIKI_KP_DECIMAL
, WXK_NUMPAD_DECIMAL
);
891 KEY(DIKI_KP_0
, WXK_NUMPAD0
);
892 KEY(DIKI_KP_1
, WXK_NUMPAD1
);
893 KEY(DIKI_KP_2
, WXK_NUMPAD2
);
894 KEY(DIKI_KP_3
, WXK_NUMPAD3
);
895 KEY(DIKI_KP_4
, WXK_NUMPAD4
);
896 KEY(DIKI_KP_5
, WXK_NUMPAD5
);
897 KEY(DIKI_KP_6
, WXK_NUMPAD6
);
898 KEY(DIKI_KP_7
, WXK_NUMPAD7
);
899 KEY(DIKI_KP_8
, WXK_NUMPAD8
);
900 KEY(DIKI_KP_9
, WXK_NUMPAD9
);
902 case DIKI_KEYDEF_END
:
903 case DIKI_NUMBER_OF_KEYS
:
904 wxFAIL_MSG( _T("invalid key_id value") );
908 return 0; // silence compiler warnings
911 // returns untranslated keycode, i.e. for EVT_CHAR, where characters are left in
912 // the form they were entered (lowercase, diacritics etc.)
913 static long GetUntraslatedKeyCode(DFBInputDeviceKeyIdentifier key_id
,
914 DFBInputDeviceKeySymbol key_symbol
)
916 switch ( DFB_KEY_TYPE(key_symbol
) )
922 if ( key_symbol
< 128 )
927 wchar_t chr
= key_symbol
;
928 wxCharBuffer
buf(wxConvUI
->cWC2MB(&chr
, 1, NULL
));
930 return *buf
; // may be 0 if failed
932 #endif // wxUSE_WCHAR_T
938 return GetTranslatedKeyCode(key_id
);
944 void wxWindowDFB::HandleKeyEvent(const wxDFBWindowEvent
& event_
)
949 const DFBWindowEvent
& e
= event_
;
951 wxLogTrace(TRACE_EVENTS
,
952 _T("handling key %s event for window %p ('%s')"),
953 e
.type
== DWET_KEYUP
? _T("up") : _T("down"),
954 this, GetName().c_str());
956 // fill in wxKeyEvent fields:
958 event
.SetEventObject(this);
959 event
.SetTimestamp(wxDFB_EVENT_TIMESTAMP(e
));
960 event
.m_rawCode
= e
.key_code
;
961 event
.m_keyCode
= GetTranslatedKeyCode(e
.key_id
);
962 event
.m_scanCode
= 0; // not used by wx at all
964 event
.m_uniChar
= e
.key_symbol
;
966 event
.m_shiftDown
= ( e
.modifiers
& DIMM_SHIFT
) != 0;
967 event
.m_controlDown
= ( e
.modifiers
& DIMM_CONTROL
) != 0;
968 event
.m_altDown
= ( e
.modifiers
& DIMM_ALT
) != 0;
969 event
.m_metaDown
= ( e
.modifiers
& DIMM_META
) != 0;
971 // translate coordinates from TLW-relative to this window-relative:
974 GetTLW()->ClientToScreen(&event
.m_x
, &event
.m_y
);
975 this->ScreenToClient(&event
.m_x
, &event
.m_y
);
977 if ( e
.type
== DWET_KEYUP
)
979 event
.SetEventType(wxEVT_KEY_UP
);
980 GetEventHandler()->ProcessEvent(event
);
984 bool isTab
= (event
.m_keyCode
== WXK_TAB
);
986 event
.SetEventType(wxEVT_KEY_DOWN
);
988 if ( GetEventHandler()->ProcessEvent(event
) )
991 // only send wxEVT_CHAR event if not processed yet:
992 event
.m_keyCode
= GetUntraslatedKeyCode(e
.key_id
, e
.key_symbol
);
993 if ( event
.m_keyCode
!= 0 )
995 event
.SetEventType(wxEVT_CHAR
);
996 if ( GetEventHandler()->ProcessEvent(event
) )
1000 // Synthetize navigation key event, but do it only if the TAB key
1001 // wasn't handled yet:
1002 if ( isTab
&& GetParent() && GetParent()->HasFlag(wxTAB_TRAVERSAL
) )
1004 wxNavigationKeyEvent navEvent
;
1005 navEvent
.SetEventObject(GetParent());
1006 // Shift-TAB goes in reverse direction:
1007 navEvent
.SetDirection(!event
.m_shiftDown
);
1008 // Ctrl-TAB changes the (parent) window, i.e. switch notebook page:
1009 navEvent
.SetWindowChange(event
.m_controlDown
);
1010 navEvent
.SetCurrentFocus(wxStaticCast(this, wxWindow
));
1011 GetParent()->GetEventHandler()->ProcessEvent(navEvent
);
1016 // ---------------------------------------------------------------------------
1017 // idle events processing
1018 // ---------------------------------------------------------------------------
1020 void wxWindowDFB::OnInternalIdle()
1022 if (wxUpdateUIEvent::CanUpdate(this))
1023 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1027 // Find the wxWindow at the current mouse position, returning the mouse
1029 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1031 return wxFindWindowAtPoint(pt
= wxGetMousePosition());
1034 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
1036 wxFAIL_MSG( _T("wxFindWindowAtPoint not implemented") );