Remove all lines containing cvs/svn "$Id$" keyword.
[wxWidgets.git] / include / wx / gtk / private / event.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/private/event.h
3 // Purpose: Helper functions for working with GDK and wx events
4 // Author: Vaclav Slavik
5 // Created: 2011-10-14
6 // Copyright: (c) 2011 Vaclav Slavik
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #ifndef _GTK_PRIVATE_EVENT_H_
11 #define _GTK_PRIVATE_EVENT_H_
12
13 #if !GTK_CHECK_VERSION(2,10,0)
14 // GTK+ can reliably detect Meta key state only since 2.10 when
15 // GDK_META_MASK was introduced -- there wasn't any way to detect it
16 // in older versions. wxGTK used GDK_MOD2_MASK for this purpose, but
17 // GDK_MOD2_MASK is documented as:
18 //
19 // the fifth modifier key (it depends on the modifier mapping of the X
20 // server which key is interpreted as this modifier)
21 //
22 // In other words, it isn't guaranteed to map to Meta. This is a real
23 // problem: it is common to map NumLock to it (in fact, it's an exception
24 // if the X server _doesn't_ use it for NumLock). So the old code caused
25 // wxKeyEvent::MetaDown() to always return true as long as NumLock was on
26 // on many systems, which broke all applications using
27 // wxKeyEvent::GetModifiers() to check modifiers state (see e.g. here:
28 // http://tinyurl.com/56lsk2).
29 //
30 // Because of this, it's better to not detect Meta key state at all than
31 // to detect it incorrectly. Hence the following #define, which causes
32 // m_metaDown to be always set to false.
33 #define GDK_META_MASK 0
34 #endif
35
36 namespace wxGTKImpl
37 {
38
39 // init wxMouseEvent with the info from GdkEventXXX struct
40 template<typename T> void InitMouseEvent(wxWindowGTK *win,
41 wxMouseEvent& event,
42 T *gdk_event)
43 {
44 event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK) != 0;
45 event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK) != 0;
46 event.m_altDown = (gdk_event->state & GDK_MOD1_MASK) != 0;
47 event.m_metaDown = (gdk_event->state & GDK_META_MASK) != 0;
48 event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK) != 0;
49 event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK) != 0;
50 event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK) != 0;
51
52 // In gdk/win32 VK_XBUTTON1 is translated to GDK_BUTTON4_MASK
53 // and VK_XBUTTON2 to GDK_BUTTON5_MASK. In x11/gdk buttons 4/5
54 // are wheel rotation and buttons 8/9 don't change the state.
55 event.m_aux1Down = (gdk_event->state & GDK_BUTTON4_MASK) != 0;
56 event.m_aux2Down = (gdk_event->state & GDK_BUTTON5_MASK) != 0;
57
58 wxPoint pt = win->GetClientAreaOrigin();
59 event.m_x = (wxCoord)gdk_event->x - pt.x;
60 event.m_y = (wxCoord)gdk_event->y - pt.y;
61
62 if ((win->m_wxwindow) && (win->GetLayoutDirection() == wxLayout_RightToLeft))
63 {
64 // origin in the upper right corner
65 GtkAllocation a;
66 gtk_widget_get_allocation(win->m_wxwindow, &a);
67 int window_width = a.width;
68 event.m_x = window_width - event.m_x;
69 }
70
71 event.SetEventObject( win );
72 event.SetId( win->GetId() );
73 event.SetTimestamp( gdk_event->time );
74 }
75
76 } // namespace wxGTKImpl
77
78 #endif // _GTK_PRIVATE_EVENT_H_
79