]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/private/event.h
add gdk_window_get_height/width
[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 namespace wxGTKImpl
15 {
16
17 // init wxMouseEvent with the info from GdkEventXXX struct
18 template<typename T> void InitMouseEvent(wxWindowGTK *win,
19 wxMouseEvent& event,
20 T *gdk_event)
21 {
22 event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK) != 0;
23 event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK) != 0;
24 event.m_altDown = (gdk_event->state & GDK_MOD1_MASK) != 0;
25 event.m_metaDown = (gdk_event->state & GDK_META_MASK) != 0;
26 event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK) != 0;
27 event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK) != 0;
28 event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK) != 0;
29
30 // In gdk/win32 VK_XBUTTON1 is translated to GDK_BUTTON4_MASK
31 // and VK_XBUTTON2 to GDK_BUTTON5_MASK. In x11/gdk buttons 4/5
32 // are wheel rotation and buttons 8/9 don't change the state.
33 event.m_aux1Down = (gdk_event->state & GDK_BUTTON4_MASK) != 0;
34 event.m_aux2Down = (gdk_event->state & GDK_BUTTON5_MASK) != 0;
35
36 wxPoint pt = win->GetClientAreaOrigin();
37 event.m_x = (wxCoord)gdk_event->x - pt.x;
38 event.m_y = (wxCoord)gdk_event->y - pt.y;
39
40 if ((win->m_wxwindow) && (win->GetLayoutDirection() == wxLayout_RightToLeft))
41 {
42 // origin in the upper right corner
43 GtkAllocation a;
44 gtk_widget_get_allocation(win->m_wxwindow, &a);
45 int window_width = a.width;
46 event.m_x = window_width - event.m_x;
47 }
48
49 event.SetEventObject( win );
50 event.SetId( win->GetId() );
51 event.SetTimestamp( gdk_event->time );
52 }
53
54 } // namespace wxGTKImpl
55
56 #endif // _GTK_PRIVATE_EVENT_H_
57