]>
git.saurik.com Git - wxWidgets.git/blob - 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
7 // Copyright: (c) 2011 Vaclav Slavik
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _GTK_PRIVATE_EVENT_H_
12 #define _GTK_PRIVATE_EVENT_H_
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:
20 // the fifth modifier key (it depends on the modifier mapping of the X
21 // server which key is interpreted as this modifier)
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).
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
40 // init wxMouseEvent with the info from GdkEventXXX struct
41 template<typename T
> void InitMouseEvent(wxWindowGTK
*win
,
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;
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;
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
;
63 if ((win
->m_wxwindow
) && (win
->GetLayoutDirection() == wxLayout_RightToLeft
))
65 // origin in the upper right corner
67 gtk_widget_get_allocation(win
->m_wxwindow
, &a
);
68 int window_width
= a
.width
;
69 event
.m_x
= window_width
- event
.m_x
;
72 event
.SetEventObject( win
);
73 event
.SetId( win
->GetId() );
74 event
.SetTimestamp( gdk_event
->time
);
77 } // namespace wxGTKImpl
79 #endif // _GTK_PRIVATE_EVENT_H_