#include "wx/tooltip.h"
#include "wx/caret.h"
#include "wx/fontutil.h"
-#include "wx/scopeguard.h"
#include "wx/sysopt.h"
#include <ctype.h>
#include "wx/gtk/private/event.h"
using namespace wxGTKImpl;
+#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>
+#include "wx/x11/private/wrapxkb.h"
+#else
+typedef guint KeySym;
+#endif
#include <gdk/gdkkeysyms.h>
#if GTK_CHECK_VERSION(3,0,0)
// the trace mask used for the focus debugging messages
#define TRACE_FOCUS wxT("focus")
-//-----------------------------------------------------------------------------
-// "size_request" of m_widget
-//-----------------------------------------------------------------------------
-
-extern "C" {
-static void
-wxgtk_window_size_request_callback(GtkWidget * WXUNUSED(widget),
- GtkRequisition *requisition,
- wxWindow * win)
-{
- int w, h;
- win->GetSize( &w, &h );
- if (w < 2)
- w = 2;
- if (h < 2)
- h = 2;
-
- requisition->height = h;
- requisition->width = w;
-}
-}
-
//-----------------------------------------------------------------------------
// "expose_event" of m_wxwindow
//-----------------------------------------------------------------------------
keysym = (KeySym)gdk_event->string[0];
}
+#ifdef GDK_WINDOWING_X11
// we want to always get the same key code when the same key is
// pressed regardless of the state of the modifiers, i.e. on a
// standard US keyboard pressing '5' or '%' ('5' key with
wxLogTrace(TRACE_KEYS, wxT("\t-> keycode %d"), keycode);
+#ifdef HAVE_X11_XKBLIB_H
+ KeySym keysymNormalized = XkbKeycodeToKeysym(dpy, keycode, 0, 0);
+#else
KeySym keysymNormalized = XKeycodeToKeysym(dpy, keycode, 0);
+#endif
// use the normalized, i.e. lower register, keysym if we've
// got one
key_code = keysymNormalized ? keysymNormalized : keysym;
+#else
+ key_code = keysym;
+#endif
// as explained above, we want to have lower register key codes
// normally but for the letter keys we want to have the upper ones
} // anonymous namespace
+// If a widget does not handle a key or mouse event, GTK+ sends it up the
+// parent chain until it is handled. These events are not supposed to propagate
+// in wxWidgets, so this code avoids handling them in any parent wxWindow,
+// while still allowing the event to propagate so things like native keyboard
+// navigation will work.
+#define wxPROCESS_EVENT_ONCE(EventType, event) \
+ static EventType eventPrev; \
+ if (memcmp(&eventPrev, event, sizeof(EventType)) == 0) \
+ return false; \
+ eventPrev = *event
+
extern "C" {
static gboolean
gtk_window_key_press_callback( GtkWidget *WXUNUSED(widget),
if (g_blockEventsOnDrag)
return FALSE;
+ wxPROCESS_EVENT_ONCE(GdkEventKey, gdk_event);
+
wxKeyEvent event( wxEVT_KEY_DOWN );
bool ret = false;
bool return_after_IM = false;
// We should let GTK+ IM filter key event first. According to GTK+ 2.0 API
// docs, if IM filter returns true, no further processing should be done.
// we should send the key_down event anyway.
- bool intercepted_by_IM = gtk_im_context_filter_keypress(win->m_imData->context, gdk_event);
+ bool intercepted_by_IM =
+ gtk_im_context_filter_keypress(win->m_imData->context, gdk_event) != 0;
win->m_imData->lastKeyEvent = NULL;
if (intercepted_by_IM)
{
if (g_blockEventsOnDrag)
return FALSE;
+ wxPROCESS_EVENT_ONCE(GdkEventKey, gdk_event);
+
wxKeyEvent event( wxEVT_KEY_UP );
if ( !wxTranslateGTKKeyEventToWx(event, win, gdk_event) )
{
}
}
-//-----------------------------------------------------------------------------
-// key and mouse events, after, from m_widget
-//-----------------------------------------------------------------------------
-
-extern "C" {
-static gboolean key_and_mouse_event_after(GtkWidget* widget, GdkEventKey*, wxWindow*)
-{
- // If a widget does not handle a key or mouse event, GTK+ sends it up the
- // parent chain until it is handled. These events are not supposed to
- // propagate in wxWidgets, so prevent it unless widget is in a native
- // container.
- return WX_IS_PIZZA(gtk_widget_get_parent(widget));
-}
-}
-
// ============================================================================
// the mouse events
// ============================================================================
}
}
-// find the window to send the mouse event too
+// find the window to send the mouse event to
static
wxWindowGTK *FindWindowForMouseEvent(wxWindowGTK *win, wxCoord& x, wxCoord& y)
{
wxWindowList::compatibility_iterator node = win->GetChildren().GetFirst();
while (node)
{
- wxWindowGTK *child = node->GetData();
+ wxWindow* child = static_cast<wxWindow*>(node->GetData());
node = node->GetNext();
if (!child->IsShown())
else
{
if ((child->m_wxwindow == NULL) &&
+ win->IsClientAreaChild(child) &&
(child->m_x <= xx) &&
(child->m_y <= yy) &&
(child->m_x+child->m_width >= xx) &&
GdkEventButton *gdk_event,
wxWindowGTK *win )
{
+ wxPROCESS_EVENT_ONCE(GdkEventButton, gdk_event);
+
wxCOMMON_CALLBACK_PROLOGUE(gdk_event, win);
g_lastButtonNumber = gdk_event->button;
GdkEventButton *gdk_event,
wxWindowGTK *win )
{
+ wxPROCESS_EVENT_ONCE(GdkEventButton, gdk_event);
+
wxCOMMON_CALLBACK_PROLOGUE(gdk_event, win);
g_lastButtonNumber = 0;
GdkEventMotion *gdk_event,
wxWindowGTK *win )
{
+ wxPROCESS_EVENT_ONCE(GdkEventMotion, gdk_event);
+
wxCOMMON_CALLBACK_PROLOGUE(gdk_event, win);
if (gdk_event->is_hint)
static gboolean
window_scroll_event(GtkWidget*, GdkEventScroll* gdk_event, wxWindow* win)
{
- if (gdk_event->direction != GDK_SCROLL_UP &&
- gdk_event->direction != GDK_SCROLL_DOWN)
- {
- return false;
- }
-
wxMouseEvent event(wxEVT_MOUSEWHEEL);
InitMouseEvent(win, event, gdk_event);
// FIXME: Get these values from GTK or GDK
event.m_linesPerAction = 3;
event.m_wheelDelta = 120;
- if (gdk_event->direction == GDK_SCROLL_UP)
- event.m_wheelRotation = 120;
- else
- event.m_wheelRotation = -120;
+
+ // Determine the scroll direction.
+ switch (gdk_event->direction)
+ {
+ case GDK_SCROLL_UP:
+ case GDK_SCROLL_RIGHT:
+ event.m_wheelRotation = 120;
+ break;
+
+ case GDK_SCROLL_DOWN:
+ case GDK_SCROLL_LEFT:
+ event.m_wheelRotation = -120;
+ break;
+
+ default:
+ return false; // Unknown/unhandled direction
+ }
+
+ // And the scroll axis.
+ switch (gdk_event->direction)
+ {
+ case GDK_SCROLL_UP:
+ case GDK_SCROLL_DOWN:
+ event.m_wheelAxis = wxMOUSE_WHEEL_VERTICAL;
+ break;
+
+ case GDK_SCROLL_LEFT:
+ case GDK_SCROLL_RIGHT:
+ event.m_wheelAxis = wxMOUSE_WHEEL_HORIZONTAL;
+ break;
+ }
if (win->GTKProcessEvent(event))
return TRUE;
wxWindow *wxWindowBase::DoFindFocus()
{
+ // For compatibility with wxMSW, pretend that showing a popup menu doesn't
+ // change the focus and that it remains on the window showing it, even
+ // though the real focus does change in GTK.
+ extern wxMenu *wxCurrentPopupMenu;
+ if ( wxCurrentPopupMenu )
+ return wxCurrentPopupMenu->GetInvokingWindow();
+
wxWindowGTK *focus = gs_pendingFocus ? gs_pendingFocus : gs_currentFocus;
// the cast is necessary when we compile in wxUniversal mode
return static_cast<wxWindow*>(focus);
child->m_x += pizza->m_scroll_x;
child->m_y += pizza->m_scroll_y;
- gtk_widget_set_size_request(
- child->m_widget, child->m_width, child->m_height);
- pizza->put(child->m_widget, child->m_x, child->m_y);
+ pizza->put(child->m_widget,
+ child->m_x, child->m_y, child->m_width, child->m_height);
}
//-----------------------------------------------------------------------------
m_width = WidthDefault(size.x) ;
m_height = HeightDefault(size.y);
- m_x = (int)pos.x;
- m_y = (int)pos.y;
+ if (pos != wxDefaultPosition)
+ {
+ m_x = pos.x;
+ m_y = pos.y;
+ }
return true;
}
ConnectWidget( connect_widget );
- // connect handler to prevent events from propagating up parent chain
- g_signal_connect_after(m_widget,
- "key_press_event", G_CALLBACK(key_and_mouse_event_after), this);
- g_signal_connect_after(m_widget,
- "key_release_event", G_CALLBACK(key_and_mouse_event_after), this);
- g_signal_connect_after(m_widget,
- "button_press_event", G_CALLBACK(key_and_mouse_event_after), this);
- g_signal_connect_after(m_widget,
- "button_release_event", G_CALLBACK(key_and_mouse_event_after), this);
- g_signal_connect_after(m_widget,
- "motion_notify_event", G_CALLBACK(key_and_mouse_event_after), 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.
}
#endif // GTK+ >= 2.8
- if ( GTKShouldConnectSizeRequest() )
- {
- // This is needed if we want to add our windows into native
- // GTK controls, such as the toolbar. With this callback, the
- // toolbar gets to know the correct size (the one set by the
- // programmer). Sadly, it misbehaves for wxComboBox.
- g_signal_connect (m_widget, "size_request",
- G_CALLBACK (wxgtk_window_size_request_callback),
- this);
- }
+ if (!WX_IS_PIZZA(gtk_widget_get_parent(m_widget)) && !GTK_IS_WINDOW(m_widget))
+ gtk_widget_set_size_request(m_widget, m_width, m_height);
InheritAttributes();
return wxWindowBase::Destroy();
}
+static GSList* gs_queueResizeList;
+
+extern "C" {
+static gboolean queue_resize(void*)
+{
+ gdk_threads_enter();
+ for (GSList* p = gs_queueResizeList; p; p = p->next)
+ {
+ if (p->data)
+ {
+ gtk_widget_queue_resize(GTK_WIDGET(p->data));
+ g_object_remove_weak_pointer(G_OBJECT(p->data), &p->data);
+ }
+ }
+ g_slist_free(gs_queueResizeList);
+ gs_queueResizeList = NULL;
+ gdk_threads_leave();
+ return false;
+}
+}
+
void wxWindowGTK::DoMoveWindow(int x, int y, int width, int height)
{
gtk_widget_set_size_request(m_widget, width, height);
+ GtkWidget* parent = gtk_widget_get_parent(m_widget);
+ if (WX_IS_PIZZA(parent))
+ WX_PIZZA(parent)->move(m_widget, x, y, width, height);
- // inform the parent to perform the move
- wxASSERT_MSG(m_parent && m_parent->m_wxwindow,
- "the parent window has no client area?");
- WX_PIZZA(m_parent->m_wxwindow)->move(m_widget, x, y);
+ // With GTK3, gtk_widget_queue_resize() is ignored while a size-allocate
+ // is in progress. This situation is common in wxWidgets, since
+ // size-allocate can generate wxSizeEvent and size event handlers often
+ // call SetSize(), directly or indirectly. Work around this by deferring
+ // the queue-resize until after size-allocate processing is finished.
+ if (g_slist_find(gs_queueResizeList, m_widget) == NULL)
+ {
+ if (gs_queueResizeList == NULL)
+ g_idle_add_full(GTK_PRIORITY_RESIZE, queue_resize, NULL, NULL);
+ gs_queueResizeList = g_slist_prepend(gs_queueResizeList, m_widget);
+ g_object_add_weak_pointer(G_OBJECT(m_widget), &gs_queueResizeList->data);
+ }
}
void wxWindowGTK::ConstrainSize()
void wxWindowGTK::DoSetSize( int x, int y, int width, int height, int sizeFlags )
{
- wxASSERT_MSG( (m_widget != NULL), wxT("invalid window") );
- wxASSERT_MSG( (m_parent != NULL), wxT("wxWindowGTK::SetSize requires parent.\n") );
+ wxCHECK_RET(m_widget, "invalid window");
- if ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0 && (x == -1 || y == -1))
+ int scrollX = 0, scrollY = 0;
+ GtkWidget* parent = gtk_widget_get_parent(m_widget);
+ if (WX_IS_PIZZA(parent))
{
- int currentX, currentY;
- GetPosition(¤tX, ¤tY);
- if (x == -1)
- x = currentX;
- if (y == -1)
- y = currentY;
+ wxPizza* pizza = WX_PIZZA(parent);
+ scrollX = pizza->m_scroll_x;
+ scrollY = pizza->m_scroll_y;
}
- AdjustForParentClientOrigin(x, y, sizeFlags);
+ if (x != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
+ x += scrollX;
+ else
+ x = m_x;
+ if (y != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
+ y += scrollY;
+ else
+ y = m_y;
// calculate the best size if we should auto size the window
if ( ((sizeFlags & wxSIZE_AUTO_WIDTH) && width == -1) ||
height = sizeBest.y;
}
- const wxSize oldSize(m_width, m_height);
- if (width != -1)
- m_width = width;
- if (height != -1)
- m_height = height;
+ if (width == -1)
+ width = m_width;
+ if (height == -1)
+ height = m_height;
- if (m_parent->m_wxwindow)
+ const bool sizeChange = m_width != width || m_height != height;
+ if (sizeChange || m_x != x || m_y != y)
{
- wxPizza* pizza = WX_PIZZA(m_parent->m_wxwindow);
- m_x = x + pizza->m_scroll_x;
- m_y = y + pizza->m_scroll_y;
-
- int left_border = 0;
- int right_border = 0;
- int top_border = 0;
- int bottom_border = 0;
+ m_x = x;
+ m_y = y;
+ m_width = width;
+ m_height = height;
/* the default button has a border around it */
if (gtk_widget_get_can_default(m_widget))
gtk_widget_style_get( m_widget, "default_border", &default_border, NULL );
if (default_border)
{
- left_border += default_border->left;
- right_border += default_border->right;
- top_border += default_border->top;
- bottom_border += default_border->bottom;
+ x -= default_border->left;
+ y -= default_border->top;
+ width += default_border->left + default_border->right;
+ height += default_border->top + default_border->bottom;
gtk_border_free( default_border );
}
}
- DoMoveWindow( m_x - left_border,
- m_y - top_border,
- m_width+left_border+right_border,
- m_height+top_border+bottom_border );
+ DoMoveWindow(x, y, width, height);
}
- if (m_width != oldSize.x || m_height != oldSize.y)
+ if ((sizeChange && !m_nativeSizeEvent) || (sizeFlags & wxSIZE_FORCE_EVENT))
{
// update these variables to keep size_allocate handler
// from sending another size event for this change
GetClientSize( &m_oldClientWidth, &m_oldClientHeight );
- gtk_widget_queue_resize(m_widget);
- if (!m_nativeSizeEvent)
- {
- wxSizeEvent event( wxSize(m_width,m_height), GetId() );
- event.SetEventObject( this );
- HandleWindowEvent( event );
- }
- } else
- if (sizeFlags & wxSIZE_FORCE_EVENT)
- {
wxSizeEvent event( wxSize(m_width,m_height), GetId() );
event.SetEventObject( this );
HandleWindowEvent( event );
void wxWindowGTK::DoGetSize( int *width, int *height ) const
{
- wxCHECK_RET( (m_widget != NULL), wxT("invalid window") );
-
if (width) (*width) = m_width;
if (height) (*height) = m_height;
}
void wxWindowGTK::DoGetPosition( int *x, int *y ) const
{
- wxCHECK_RET( (m_widget != NULL), wxT("invalid window") );
-
int dx = 0;
int dy = 0;
- if (!IsTopLevel() && m_parent && m_parent->m_wxwindow)
+ GtkWidget* parent = NULL;
+ if (m_widget)
+ parent = gtk_widget_get_parent(m_widget);
+ if (WX_IS_PIZZA(parent))
{
- wxPizza* pizza = WX_PIZZA(m_parent->m_wxwindow);
+ wxPizza* pizza = WX_PIZZA(parent);
dx = pizza->m_scroll_x;
dy = pizza->m_scroll_y;
}
-
- if (m_x == -1 && m_y == -1)
- {
- GdkWindow *source = NULL;
- if (m_wxwindow)
- source = gtk_widget_get_window(m_wxwindow);
- else
- source = gtk_widget_get_window(m_widget);
-
- if (source)
- {
- int org_x = 0;
- int org_y = 0;
- gdk_window_get_origin( source, &org_x, &org_y );
-
- if (m_parent)
- m_parent->ScreenToClient(&org_x, &org_y);
-
- const_cast<wxWindowGTK*>(this)->m_x = org_x;
- const_cast<wxWindowGTK*>(this)->m_y = org_y;
- }
- }
-
if (x) (*x) = m_x - dx;
if (y) (*y) = m_y - dy;
}
gboolean rc;
g_signal_emit_by_name(parent->m_widget, "focus", dir, &rc);
- return rc == TRUE;
+ return rc != 0;
}
}
GdkDeviceManager* manager = gdk_display_get_device_manager(display);
gdk_device_warp(gdk_device_manager_get_client_pointer(manager), screen, x, y);
#else
+#ifdef GDK_WINDOWING_X11
XWarpPointer(GDK_DISPLAY_XDISPLAY(display),
None,
GDK_WINDOW_XID(gdk_screen_get_root_window(screen)),
0, 0, 0, 0, x, y);
#endif
+#endif
}
wxWindowGTK::ScrollDir wxWindowGTK::ScrollDirFromRange(GtkRange *range) const
bool wxWindowGTK::IsDoubleBuffered() const
{
- return gtk_widget_get_double_buffered( m_wxwindow );
+ return gtk_widget_get_double_buffered( m_wxwindow ) != 0;
}
void wxWindowGTK::ClearBackground()
{
// Make sure GDK/X11 doesn't refresh the window
// automatically.
- gdk_window_set_back_pixmap( window, None, False );
+ gdk_window_set_back_pixmap( window, NULL, FALSE );
m_needsStyleChange = false;
}
else // window not realized yet
*reason = _("This program was compiled with a too old version of GTK+, "
"please rebuild with GTK+ 2.12 or newer.");
}
-#endif // wxGTK_HAS_COMPOSITING_SUPPORT/!wxGTK_HAS_COMPOSITING_SUPPORT
return false;
+#endif // wxGTK_HAS_COMPOSITING_SUPPORT/!wxGTK_HAS_COMPOSITING_SUPPORT
}
// ----------------------------------------------------------------------------
{
wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") );
- // For compatibility with other ports, pretend that the window showing the
- // menu has focus while the menu is shown. This is needed because the popup
- // menu actually steals the focus from the window it's associated it in
- // wxGTK unlike, say, wxMSW.
- wxWindowGTK* const oldPendingFocus = gs_pendingFocus;
- gs_pendingFocus = this;
- wxON_BLOCK_EXIT_SET( gs_pendingFocus, oldPendingFocus );
-
menu->UpdateUI();
wxPoint pos;