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