event.h 3.2 KB

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