From 4a99d5975088e9c3cf05b3d4d9889bd9b70ea75d Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Wed, 19 Oct 2011 16:20:10 +0000 Subject: [PATCH] Move InitMouseEvent() to wx/gtk/private/event.h. It is needed in wxDataViewCtrl now too, in addition to wxWindow. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69472 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/private/event.h | 57 ++++++++++++++++++++++++++++++++++ src/gtk/window.cpp | 39 ++--------------------- 2 files changed, 59 insertions(+), 37 deletions(-) create mode 100644 include/wx/gtk/private/event.h diff --git a/include/wx/gtk/private/event.h b/include/wx/gtk/private/event.h new file mode 100644 index 0000000000..1b23254045 --- /dev/null +++ b/include/wx/gtk/private/event.h @@ -0,0 +1,57 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: wx/gtk/private/event.h +// Purpose: Helper functions for working with GDK and wx events +// Author: Vaclav Slavik +// Created: 2011-10-14 +// RCS-ID: $Id$ +// Copyright: (c) 2011 Vaclav Slavik +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _GTK_PRIVATE_EVENT_H_ +#define _GTK_PRIVATE_EVENT_H_ + +namespace wxGTKImpl +{ + +// init wxMouseEvent with the info from GdkEventXXX struct +template void InitMouseEvent(wxWindowGTK *win, + wxMouseEvent& event, + T *gdk_event) +{ + event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK) != 0; + event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK) != 0; + event.m_altDown = (gdk_event->state & GDK_MOD1_MASK) != 0; + event.m_metaDown = (gdk_event->state & GDK_META_MASK) != 0; + event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK) != 0; + event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK) != 0; + event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK) != 0; + + // In gdk/win32 VK_XBUTTON1 is translated to GDK_BUTTON4_MASK + // and VK_XBUTTON2 to GDK_BUTTON5_MASK. In x11/gdk buttons 4/5 + // are wheel rotation and buttons 8/9 don't change the state. + event.m_aux1Down = (gdk_event->state & GDK_BUTTON4_MASK) != 0; + event.m_aux2Down = (gdk_event->state & GDK_BUTTON5_MASK) != 0; + + wxPoint pt = win->GetClientAreaOrigin(); + event.m_x = (wxCoord)gdk_event->x - pt.x; + event.m_y = (wxCoord)gdk_event->y - pt.y; + + if ((win->m_wxwindow) && (win->GetLayoutDirection() == wxLayout_RightToLeft)) + { + // origin in the upper right corner + GtkAllocation a; + gtk_widget_get_allocation(win->m_wxwindow, &a); + int window_width = a.width; + event.m_x = window_width - event.m_x; + } + + event.SetEventObject( win ); + event.SetId( win->GetId() ); + event.SetTimestamp( gdk_event->time ); +} + +} // namespace wxGTKImpl + +#endif // _GTK_PRIVATE_EVENT_H_ + diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 2c416d0e80..26004164af 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -37,6 +37,8 @@ #include "wx/gtk/private.h" #include "wx/gtk/private/win_gtk.h" +#include "wx/gtk/private/event.h" +using namespace wxGTKImpl; #include @@ -1101,43 +1103,6 @@ gtk_window_key_release_callback( GtkWidget * WXUNUSED(widget), // mouse event processing helpers // ---------------------------------------------------------------------------- -// init wxMouseEvent with the info from GdkEventXXX struct -template void InitMouseEvent(wxWindowGTK *win, - wxMouseEvent& event, - T *gdk_event) -{ - event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK) != 0; - event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK) != 0; - event.m_altDown = (gdk_event->state & GDK_MOD1_MASK) != 0; - event.m_metaDown = (gdk_event->state & GDK_META_MASK) != 0; - event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK) != 0; - event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK) != 0; - event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK) != 0; - - // In gdk/win32 VK_XBUTTON1 is translated to GDK_BUTTON4_MASK - // and VK_XBUTTON2 to GDK_BUTTON5_MASK. In x11/gdk buttons 4/5 - // are wheel rotation and buttons 8/9 don't change the state. - event.m_aux1Down = (gdk_event->state & GDK_BUTTON4_MASK) != 0; - event.m_aux2Down = (gdk_event->state & GDK_BUTTON5_MASK) != 0; - - wxPoint pt = win->GetClientAreaOrigin(); - event.m_x = (wxCoord)gdk_event->x - pt.x; - event.m_y = (wxCoord)gdk_event->y - pt.y; - - if ((win->m_wxwindow) && (win->GetLayoutDirection() == wxLayout_RightToLeft)) - { - // origin in the upper right corner - GtkAllocation a; - gtk_widget_get_allocation(win->m_wxwindow, &a); - int window_width = a.width; - event.m_x = window_width - event.m_x; - } - - event.SetEventObject( win ); - event.SetId( win->GetId() ); - event.SetTimestamp( gdk_event->time ); -} - static void AdjustEventButtonState(wxMouseEvent& event) { // GDK reports the old state of the button for a button press event, but -- 2.45.2