#include "wx/gtk/private.h"
#include "wx/gtk/private/win_gtk.h"
+#include "wx/gtk/private/event.h"
+using namespace wxGTKImpl;
#include <gdk/gdkx.h>
// the trace mask used for the focus debugging messages
#define TRACE_FOCUS wxT("focus")
-//-----------------------------------------------------------------------------
-// missing gdk functions
-//-----------------------------------------------------------------------------
-
-void
-gdk_window_warp_pointer (GdkWindow *window,
- gint x,
- gint y)
-{
- if (!window)
- window = gdk_get_default_root_window();
-
- if (!GDK_WINDOW_DESTROYED(window))
- {
- XWarpPointer (GDK_WINDOW_XDISPLAY(window),
- None, /* not source window -> move from anywhere */
- GDK_WINDOW_XID(window), /* dest window */
- 0, 0, 0, 0, /* not source window -> move from anywhere */
- x, y );
- }
-}
-
-
//-----------------------------------------------------------------------------
// "size_request" of m_widget
//-----------------------------------------------------------------------------
wxWindowGTK *win,
GdkEventKey *gdk_event)
{
- int x = 0;
- int y = 0;
- GdkModifierType state;
- if (gdk_event->window)
- gdk_window_get_pointer(gdk_event->window, &x, &y, &state);
-
event.SetTimestamp( gdk_event->time );
event.SetId(win->GetId());
event.m_rawCode = (wxUint32) gdk_event->keyval;
event.m_rawFlags = gdk_event->hardware_keycode;
- wxGetMousePosition( &x, &y );
- win->ScreenToClient( &x, &y );
- event.m_x = x;
- event.m_y = y;
+ wxGetMousePosition(&event.m_x, &event.m_y);
+ win->ScreenToClient(&event.m_x, &event.m_y);
event.SetEventObject( win );
}
// mouse event processing helpers
// ----------------------------------------------------------------------------
-// init wxMouseEvent with the info from GdkEventXXX struct
-template<typename T> void InitMouseEvent(wxWindowGTK *win,
- wxMouseEvent& event,
- T *gdk_event)
-{
- event.SetTimestamp( gdk_event->time );
- 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
//-----------------------------------------------------------------------------
static void
-gtk_window_realized_callback(GtkWidget* widget, wxWindow* win)
+gtk_window_realized_callback(GtkWidget* WXUNUSED(widget), wxWindow* win)
{
- if (win->m_imData)
+ win->GTKHandleRealized();
+}
+
+void wxWindowGTK::GTKHandleRealized()
+{
+ if (m_imData)
{
- gtk_im_context_set_client_window( win->m_imData->context,
- win->m_wxwindow ? win->GTKGetDrawingWindow() : gtk_widget_get_window(widget));
+ gtk_im_context_set_client_window
+ (
+ m_imData->context,
+ m_wxwindow ? GTKGetDrawingWindow()
+ : gtk_widget_get_window(m_widget)
+ );
}
// We cannot set colours and fonts before the widget
// been realized, so we do this directly after realization
// or otherwise in idle time
- if (win->m_needsStyleChange)
+ if (m_needsStyleChange)
{
- win->SetBackgroundStyle(win->GetBackgroundStyle());
- win->m_needsStyleChange = false;
+ SetBackgroundStyle(GetBackgroundStyle());
+ m_needsStyleChange = false;
}
- wxWindowCreateEvent event( win );
- event.SetEventObject( win );
- win->GTKProcessEvent( event );
+ wxWindowCreateEvent event( this );
+ event.SetEventObject( this );
+ GTKProcessEvent( event );
- win->GTKUpdateCursor(true, false);
+ GTKUpdateCursor(true, false);
}
//-----------------------------------------------------------------------------
ConnectWidget( connect_widget );
- /* We cannot set colours, fonts and cursors before the widget has
- been realized, so we do this directly after realization */
- g_signal_connect (connect_widget, "realize",
- G_CALLBACK (gtk_window_realized_callback), this);
+ // We cannot set colours, fonts and cursors before the widget has been
+ // realized, so we do this directly after realization -- unless the widget
+ // was in fact realized already.
+ if ( gtk_widget_get_realized(connect_widget) )
+ {
+ gtk_window_realized_callback(connect_widget, this);
+ }
+ else
+ {
+ g_signal_connect (connect_widget, "realize",
+ G_CALLBACK (gtk_window_realized_callback), this);
+ }
if (!IsTopLevel())
{
gtk_widget_show( m_widget );
}
-gulong wxWindowGTK::GTKConnectWidget(const char *signal, void (*callback)())
+unsigned long wxWindowGTK::GTKConnectWidget(const char *signal, void (*callback)())
{
return g_signal_connect(m_widget, signal, callback, this);
}
wxFocusEvent event( wxEVT_KILL_FOCUS, GetId() );
event.SetEventObject( this );
+ event.SetWindow( FindFocus() );
GTKProcessEvent( event );
}
{
wxCHECK_RET( (m_widget != NULL), wxT("invalid window") );
- // We provide this function ourselves as it is
- // missing in GDK (top of this file).
-
- GdkWindow *window = NULL;
- if (m_wxwindow)
- window = gtk_widget_get_window(m_wxwindow);
- else
- window = gtk_widget_get_window(GetConnectWidget());
-
- if (window)
- gdk_window_warp_pointer( window, x, y );
+ ClientToScreen(&x, &y);
+ GdkDisplay* display = gtk_widget_get_display(m_widget);
+ GdkScreen* screen = gtk_widget_get_screen(m_widget);
+#ifdef __WXGTK30__
+ GdkDeviceManager* manager = gdk_display_get_device_manager(display);
+ gdk_device_warp(gdk_device_manager_get_client_pointer(manager), screen, x, y);
+#else
+ XWarpPointer(GDK_DISPLAY_XDISPLAY(display),
+ None,
+ GDK_WINDOW_XID(gdk_screen_get_root_window(screen)),
+ 0, 0, 0, 0, x, y);
+#endif
}
wxWindowGTK::ScrollDir wxWindowGTK::ScrollDirFromRange(GtkRange *range) const