event.m_keyCode = key_code;
#if wxUSE_UNICODE
- event.m_uniChar = gdk_keyval_to_unicode(key_code ? key_code : keysym);
+ event.m_uniChar = gdk_keyval_to_unicode(key_code);
if ( !event.m_uniChar && event.m_keyCode <= WXK_DELETE )
{
// Set Unicode key code to the ASCII equivalent for compatibility. E.g.
{
int x = 0;
int y = 0;
- GdkModifierType state;
- gdk_window_get_pointer(gdk_event->window, &x, &y, &state);
+#ifdef __WXGTK3__
+ gdk_window_get_device_position(gdk_event->window, gdk_event->device, &x, &y, NULL);
+#else
+ gdk_window_get_pointer(gdk_event->window, &x, &y, NULL);
+#endif
gdk_event->x = x;
gdk_event->y = y;
}
if ( g_captureWindow )
{
// synthesise a mouse enter or leave event if needed
- GdkWindow *winUnderMouse = gdk_window_at_pointer(NULL, NULL);
+ GdkWindow* winUnderMouse =
+#ifdef __WXGTK3__
+ gdk_device_get_window_at_position(gdk_event->device, NULL, NULL);
+#else
+ gdk_window_at_pointer(NULL, NULL);
+#endif
// This seems to be necessary and actually been added to
// GDK itself in version 2.0.X
gdk_flush();
case GDK_SCROLL_LEFT:
event.m_wheelRotation = -120;
break;
-
+#if GTK_CHECK_VERSION(3,4,0)
+ case GDK_SCROLL_SMOOTH:
+ // TODO
+#endif
default:
return false; // Unknown/unhandled direction
}
case GDK_SCROLL_RIGHT:
event.m_wheelAxis = wxMOUSE_WHEEL_HORIZONTAL;
break;
+#if GTK_CHECK_VERSION(3,4,0)
+ case GDK_SCROLL_SMOOTH:
+ // TODO
+ break;
+#endif
}
if (win->GTKProcessEvent(event))
//-----------------------------------------------------------------------------
static gboolean
-gtk_window_enter_callback( GtkWidget *widget,
+gtk_window_enter_callback( GtkWidget*,
GdkEventCrossing *gdk_event,
wxWindowGTK *win )
{
// Event was emitted after a grab
if (gdk_event->mode != GDK_CROSSING_NORMAL) return FALSE;
- int x = 0;
- int y = 0;
- GdkModifierType state = (GdkModifierType)0;
-
- gdk_window_get_pointer(gtk_widget_get_window(widget), &x, &y, &state);
-
wxMouseEvent event( wxEVT_ENTER_WINDOW );
InitMouseEvent(win, event, gdk_event);
- wxPoint pt = win->GetClientAreaOrigin();
- event.m_x = x + pt.x;
- event.m_y = y + pt.y;
if ( !g_captureWindow )
{
//-----------------------------------------------------------------------------
static gboolean
-gtk_window_leave_callback( GtkWidget *widget,
+gtk_window_leave_callback( GtkWidget*,
GdkEventCrossing *gdk_event,
wxWindowGTK *win )
{
if (gdk_event->mode != GDK_CROSSING_NORMAL) return FALSE;
wxMouseEvent event( wxEVT_LEAVE_WINDOW );
-
- int x = 0;
- int y = 0;
- GdkModifierType state = (GdkModifierType)0;
-
- gdk_window_get_pointer(gtk_widget_get_window(widget), &x, &y, &state);
-
InitMouseEvent(win, event, gdk_event);
return win->GTKProcessEvent(event);
if (w < 0) w = 0;
if (h < 0) h = 0;
}
- if (win->m_oldClientWidth != w || win->m_oldClientHeight != h)
+ win->m_useCachedClientSize = true;
+ if (win->m_clientWidth != w || win->m_clientHeight != h)
{
- win->m_oldClientWidth = w;
- win->m_oldClientHeight = h;
+ win->m_clientWidth = w;
+ win->m_clientHeight = h;
// this callback can be connected to m_wxwindow,
// so always get size from m_widget->allocation
GtkAllocation a;
static void style_updated(GtkWidget*, GtkStyle*, wxWindow* win)
#endif
{
- if (win->IsTopLevel())
- {
- wxSysColourChangedEvent event;
- event.SetEventObject(win);
- win->GTKProcessEvent(event);
- }
- else
- {
- // Border width could change, which will change client size.
- // Make sure size event occurs for this
- win->m_oldClientWidth = 0;
- }
+ wxSysColourChangedEvent event;
+ event.SetEventObject(win);
+ win->GTKProcessEvent(event);
}
//-----------------------------------------------------------------------------
if (IsFrozen())
DoFreeze();
+ GdkWindow* const window = GTKGetDrawingWindow();
+
if (m_imData)
{
gtk_im_context_set_client_window
(
m_imData->context,
- m_wxwindow ? GTKGetDrawingWindow()
+ window ? window
: gtk_widget_get_window(m_widget)
);
}
#if wxGTK_HAS_COMPOSITING_SUPPORT
if (IsTransparentBackgroundSupported())
{
- GdkWindow* const window = GTKGetDrawingWindow();
if (window)
gdk_window_set_composited(window, true);
}
}
}
-
- // We cannot set colours and fonts before the widget
- // been realized, so we do this directly after realization
- // or otherwise in idle time
-
- if (m_needsStyleChange)
+#ifndef __WXGTK3__
+ if (window && (
+ m_backgroundStyle == wxBG_STYLE_PAINT ||
+ m_backgroundStyle == wxBG_STYLE_TRANSPARENT))
{
- SetBackgroundStyle(GetBackgroundStyle());
- m_needsStyleChange = false;
+ gdk_window_set_back_pixmap(window, NULL, false);
}
+#endif
wxWindowCreateEvent event(static_cast<wxWindow*>(this));
event.SetEventObject( this );
GTKUpdateCursor(true, false);
- if (m_wxwindow &&
- (IsTopLevel() || HasFlag(wxBORDER_RAISED | wxBORDER_SUNKEN | wxBORDER_THEME)))
+ if (m_wxwindow && IsTopLevel())
{
// attaching to style changed signal after realization avoids initial
// changes we don't care about
if (m_imData)
gtk_im_context_set_client_window(m_imData->context, NULL);
- g_signal_handlers_disconnect_by_func(
- m_wxwindow, (void*)style_updated, this);
+ if (IsTopLevel())
+ {
+ g_signal_handlers_disconnect_by_func(
+ m_wxwindow, (void*)style_updated, this);
+ }
}
}
}
#endif // __WINDOWS__
-static void GetMouseState(int& x, int& y, GdkModifierType& mask)
+static GdkDisplay* GetDisplay()
{
wxWindow* tlw = NULL;
if (!wxTopLevelWindows.empty())
display = gtk_widget_get_display(tlw->m_widget);
else
display = gdk_display_get_default();
- gdk_display_get_pointer(display, NULL, &x, &y, &mask);
+ return display;
}
wxMouseState wxGetMouseState()
gint y;
GdkModifierType mask;
- GetMouseState(x, y, mask);
+ GdkDisplay* display = GetDisplay();
+#ifdef __WXGTK3__
+ GdkDeviceManager* manager = gdk_display_get_device_manager(display);
+ GdkDevice* device = gdk_device_manager_get_client_pointer(manager);
+ GdkScreen* screen;
+ gdk_device_get_position(device, &screen, &x, &y);
+ GdkWindow* window = gdk_screen_get_root_window(screen);
+ gdk_device_get_state(device, window, NULL, &mask);
+#else
+ gdk_display_get_pointer(display, NULL, &x, &y, &mask);
+#endif
ms.SetX(x);
ms.SetY(y);
m_nativeSizeEvent = false;
#ifdef __WXGTK3__
m_paintContext = NULL;
+ m_styleProvider = NULL;
#endif
m_isScrolling = false;
m_scrollPos[dir] = 0;
}
- m_oldClientWidth =
- m_oldClientHeight = 0;
+ m_clientWidth =
+ m_clientHeight = 0;
+ m_useCachedClientSize = false;
m_clipPaintRegion = false;
- m_needsStyleChange = false;
-
m_cursor = *wxSTANDARD_CURSOR;
m_imData = NULL;
}
}
- if (HasFlag(wxALWAYS_SHOW_SB))
- {
- gtk_scrolled_window_set_policy( scrolledWindow, GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS );
- }
- else
- {
- gtk_scrolled_window_set_policy( scrolledWindow, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
- }
+ // If wx[HV]SCROLL is not given, the corresponding scrollbar is not shown
+ // at all. Otherwise it may be shown only on demand (default) or always, if
+ // the wxALWAYS_SHOW_SB is specified.
+ GtkPolicyType horzPolicy = HasFlag(wxHSCROLL)
+ ? HasFlag(wxALWAYS_SHOW_SB)
+ ? GTK_POLICY_ALWAYS
+ : GTK_POLICY_AUTOMATIC
+ : GTK_POLICY_NEVER;
+ GtkPolicyType vertPolicy = HasFlag(wxVSCROLL)
+ ? HasFlag(wxALWAYS_SHOW_SB)
+ ? GTK_POLICY_ALWAYS
+ : GTK_POLICY_AUTOMATIC
+ : GTK_POLICY_NEVER;
+ gtk_scrolled_window_set_policy( scrolledWindow, horzPolicy, vertPolicy );
m_scrollBar[ScrollDir_Horz] = GTK_RANGE(gtk_scrolled_window_get_hscrollbar(scrolledWindow));
m_scrollBar[ScrollDir_Vert] = GTK_RANGE(gtk_scrolled_window_get_vscrollbar(scrolledWindow));
if ( gs_deferredFocusOut == this )
gs_deferredFocusOut = NULL;
- if (m_widget)
- GTKDisconnect(m_widget);
- if (m_wxwindow && m_wxwindow != m_widget)
+ // Unlike the above cases, which can happen in normal circumstances, a
+ // window shouldn't be destroyed while it still has capture, so even though
+ // we still reset the global pointer to avoid leaving it dangling and
+ // crashing afterwards, also complain about it.
+ if ( g_captureWindow == this )
+ {
+ wxFAIL_MSG( wxS("Destroying window with mouse capture") );
+ g_captureWindow = NULL;
+ }
+
+ if (m_wxwindow)
+ {
GTKDisconnect(m_wxwindow);
+ GtkWidget* parent = gtk_widget_get_parent(m_wxwindow);
+ if (parent)
+ GTKDisconnect(parent);
+ }
+ if (m_widget && m_widget != m_wxwindow)
+ GTKDisconnect(m_widget);
// destroy children before destroying this window itself
DestroyChildren();
while (IsFrozen())
Thaw();
+#ifdef __WXGTK3__
+ if (m_styleProvider)
+ g_object_unref(m_styleProvider);
+#endif
+
if (m_widget)
{
// Note that gtk_widget_destroy() does not destroy the widget, it just
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);
+ // apply any font or color changes made before creation
+ GTKApplyWidgetStyle();
+
InheritAttributes();
SetLayoutDirection(wxLayout_Default);
height = m_height;
const bool sizeChange = m_width != width || m_height != height;
+
+ if (sizeChange)
+ m_useCachedClientSize = false;
+
if (sizeChange || m_x != x || m_y != y)
{
m_x = x;
{
// update these variables to keep size_allocate handler
// from sending another size event for this change
- GetClientSize( &m_oldClientWidth, &m_oldClientHeight );
+ DoGetClientSize(&m_clientWidth, &m_clientHeight);
wxSizeEvent event( wxSize(m_width,m_height), GetId() );
event.SetEventObject( this );
{
wxCHECK_RET( (m_widget != NULL), wxT("invalid window") );
+ if (m_useCachedClientSize)
+ {
+ if (width) *width = m_clientWidth;
+ if (height) *height = m_clientHeight;
+ return;
+ }
+
int w = m_width;
int h = m_height;
gtk_scrolled_window_get_policy(GTK_SCROLLED_WINDOW(m_widget),
&policy[ScrollDir_Horz],
&policy[ScrollDir_Vert]);
- const int scrollbar_spacing =
+
+ // get scrollbar spacing the same way the GTK-private function
+ // _gtk_scrolled_window_get_scrollbar_spacing() does it
+ int scrollbar_spacing =
GTK_SCROLLED_WINDOW_GET_CLASS(m_widget)->scrollbar_spacing;
+ if (scrollbar_spacing < 0)
+ {
+ gtk_widget_style_get(
+ m_widget, "scrollbar-spacing", &scrollbar_spacing, NULL);
+ }
for ( int i = 0; i < ScrollDir_Max; i++ )
{
bool wxWindowGTK::SetBackgroundColour( const wxColour &colour )
{
- wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") );
-
if (!wxWindowBase::SetBackgroundColour(colour))
return false;
-#ifndef __WXGTK3__
- if (colour.IsOk())
+ if (m_widget)
{
- // We need the pixel value e.g. for background clearing.
- m_backgroundColour.CalcPixel(gtk_widget_get_colormap(m_widget));
- }
+#ifndef __WXGTK3__
+ if (colour.IsOk())
+ {
+ // We need the pixel value e.g. for background clearing.
+ m_backgroundColour.CalcPixel(gtk_widget_get_colormap(m_widget));
+ }
#endif
- // apply style change (forceStyle=true so that new style is applied
- // even if the bg colour changed from valid to wxNullColour)
- GTKApplyWidgetStyle(true);
+ // apply style change (forceStyle=true so that new style is applied
+ // even if the bg colour changed from valid to wxNullColour)
+ GTKApplyWidgetStyle(true);
+ }
return true;
}
bool wxWindowGTK::SetForegroundColour( const wxColour &colour )
{
- wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") );
-
if (!wxWindowBase::SetForegroundColour(colour))
- {
return false;
- }
-#ifndef __WXGTK3__
- if (colour.IsOk())
+ if (m_widget)
{
- // We need the pixel value e.g. for background clearing.
- m_foregroundColour.CalcPixel(gtk_widget_get_colormap(m_widget));
- }
+#ifndef __WXGTK3__
+ if (colour.IsOk())
+ {
+ // We need the pixel value e.g. for background clearing.
+ m_foregroundColour.CalcPixel(gtk_widget_get_colormap(m_widget));
+ }
#endif
- // apply style change (forceStyle=true so that new style is applied
- // even if the bg colour changed from valid to wxNullColour):
- GTKApplyWidgetStyle(true);
+ // apply style change (forceStyle=true so that new style is applied
+ // even if the bg colour changed from valid to wxNullColour):
+ GTKApplyWidgetStyle(true);
+ }
return true;
}
}
#ifndef __WXGTK3__
-GtkRcStyle *wxWindowGTK::GTKCreateWidgetStyle(bool forceStyle)
+GtkRcStyle* wxWindowGTK::GTKCreateWidgetStyle()
{
- // do we need to apply any changes at all?
- if ( !forceStyle &&
- !m_font.IsOk() &&
- !m_foregroundColour.IsOk() && !m_backgroundColour.IsOk() )
- {
- return NULL;
- }
-
GtkRcStyle *style = gtk_rc_style_new();
if ( m_font.IsOk() )
}
#endif // !__WXGTK3__
-void wxWindowGTK::GTKApplyWidgetStyle(bool WXUNUSED_IN_GTK3(forceStyle))
+void wxWindowGTK::GTKApplyWidgetStyle(bool forceStyle)
{
+ if (forceStyle || m_font.IsOk() ||
+ m_foregroundColour.IsOk() || m_backgroundColour.IsOk())
+ {
#ifdef __WXGTK3__
- DoApplyWidgetStyle(NULL);
+ if (m_backgroundColour.IsOk())
+ {
+ // create a GtkStyleProvider to override "background-image"
+ if (m_styleProvider == NULL)
+ m_styleProvider = GTK_STYLE_PROVIDER(gtk_css_provider_new());
+ const char css[] =
+ "*{background-image:-gtk-gradient(linear,0 0,0 1,"
+ "from(rgba(%u,%u,%u,%g)),to(rgba(%u,%u,%u,%g)))}";
+ char buf[sizeof(css) + 20];
+ const unsigned r = m_backgroundColour.Red();
+ const unsigned g = m_backgroundColour.Green();
+ const unsigned b = m_backgroundColour.Blue();
+ const double a = m_backgroundColour.Alpha() / 255.0;
+ g_snprintf(buf, sizeof(buf), css, r, g, b, a, r, g, b, a);
+ gtk_css_provider_load_from_data(GTK_CSS_PROVIDER(m_styleProvider), buf, -1, NULL);
+ }
+ DoApplyWidgetStyle(NULL);
#else
- GtkRcStyle *style = GTKCreateWidgetStyle(forceStyle);
- if ( style )
- {
+ GtkRcStyle* style = GTKCreateWidgetStyle();
DoApplyWidgetStyle(style);
g_object_unref(style);
- }
#endif
+ }
// Style change may affect GTK+'s size calculation:
InvalidateBestSize();
gtk_widget_override_font(widget, pfd);
gtk_widget_override_color(widget, GTK_STATE_FLAG_NORMAL, m_foregroundColour);
gtk_widget_override_background_color(widget, GTK_STATE_FLAG_NORMAL, m_backgroundColour);
+
+ // setting background color has no effect with some themes when the widget style
+ // has a "background-image" property, so we need to override that as well
+
+ GtkStyleContext* context = gtk_widget_get_style_context(widget);
+ if (m_styleProvider)
+ gtk_style_context_remove_provider(context, m_styleProvider);
+ cairo_pattern_t* pattern = NULL;
+ if (m_backgroundColour.IsOk())
+ {
+ gtk_style_context_get(context,
+ GTK_STATE_FLAG_NORMAL, "background-image", &pattern, NULL);
+ }
+ if (pattern)
+ {
+ cairo_pattern_destroy(pattern);
+ gtk_style_context_add_provider(context,
+ m_styleProvider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ }
#else
gtk_widget_modify_style(widget, style);
#endif
#ifndef __WXGTK3__
GdkWindow *window;
- if ( m_wxwindow )
- {
- window = GTKGetDrawingWindow();
- }
- else
- {
- GtkWidget * const w = GetConnectWidget();
- window = w ? gtk_widget_get_window(w) : NULL;
- }
-
- bool wantNoBackPixmap = style == wxBG_STYLE_PAINT || style == wxBG_STYLE_TRANSPARENT;
-
- if ( wantNoBackPixmap )
+ if ((style == wxBG_STYLE_PAINT || style == wxBG_STYLE_TRANSPARENT) &&
+ (window = GTKGetDrawingWindow()))
{
- if (window)
- {
- // Make sure GDK/X11 doesn't refresh the window
- // automatically.
- gdk_window_set_back_pixmap( window, NULL, FALSE );
- m_needsStyleChange = false;
- }
- else // window not realized yet
- {
- // Do when window is realized
- m_needsStyleChange = true;
- }
-
- // Don't apply widget style, or we get a grey background
- }
- else
- {
- // apply style change (forceStyle=true so that new style is applied
- // even if the bg colour changed from valid to wxNullColour):
- GTKApplyWidgetStyle(true);
+ gdk_window_set_back_pixmap(window, NULL, false);
}
#endif // !__WXGTK3__
{
// ensure that the menu appears entirely on screen
GtkRequisition req;
+#ifdef __WXGTK3__
+ gtk_widget_get_preferred_size(GTK_WIDGET(menu), &req, NULL);
+#else
gtk_widget_get_child_requisition(GTK_WIDGET(menu), &req);
+#endif
wxSize sizeScreen = wxGetDisplaySize();
wxPoint *pos = (wxPoint*)user_data;
bool wxWindowGTK::SetFont( const wxFont &font )
{
- wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") );
-
if (!wxWindowBase::SetFont(font))
return false;
- // apply style change (forceStyle=true so that new style is applied
- // even if the font changed from valid to wxNullFont):
- GTKApplyWidgetStyle(true);
+ if (m_widget)
+ {
+ // apply style change (forceStyle=true so that new style is applied
+ // even if the font changed from valid to wxNullFont):
+ GTKApplyWidgetStyle(true);
+ }
return true;
}
if (!cursor->IsOk())
cursor = wxSTANDARD_CURSOR;
+ const GdkEventMask mask = GdkEventMask(
+ GDK_BUTTON_PRESS_MASK |
+ GDK_BUTTON_RELEASE_MASK |
+ GDK_POINTER_MOTION_HINT_MASK |
+ GDK_POINTER_MOTION_MASK);
+#ifdef __WXGTK3__
+ GdkDisplay* display = gdk_window_get_display(window);
+ GdkDeviceManager* manager = gdk_display_get_device_manager(display);
+ GdkDevice* device = gdk_device_manager_get_client_pointer(manager);
+ gdk_device_grab(
+ device, window, GDK_OWNERSHIP_NONE, false, mask,
+ cursor->GetCursor(), unsigned(GDK_CURRENT_TIME));
+#else
gdk_pointer_grab( window, FALSE,
- (GdkEventMask)
- (GDK_BUTTON_PRESS_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_POINTER_MOTION_HINT_MASK |
- GDK_POINTER_MOTION_MASK),
+ mask,
NULL,
cursor->GetCursor(),
(guint32)GDK_CURRENT_TIME );
+#endif
g_captureWindow = this;
g_captureWindowHasMouse = true;
}
if (!window)
return;
+#ifdef __WXGTK3__
+ GdkDisplay* display = gdk_window_get_display(window);
+ GdkDeviceManager* manager = gdk_display_get_device_manager(display);
+ GdkDevice* device = gdk_device_manager_get_client_pointer(manager);
+ gdk_device_ungrab(device, unsigned(GDK_CURRENT_TIME));
+#else
gdk_pointer_ungrab ( (guint32)GDK_CURRENT_TIME );
+#endif
}
void wxWindowGTK::GTKReleaseMouseAndNotify()
}
// Get the current mouse position.
+void wxGetMousePosition(int* x, int* y)
+{
+ GdkDisplay* display = GetDisplay();
+#ifdef __WXGTK3__
+ GdkDeviceManager* manager = gdk_display_get_device_manager(display);
+ GdkDevice* device = gdk_device_manager_get_client_pointer(manager);
+ gdk_device_get_position(device, NULL, x, y);
+#else
+ gdk_display_get_pointer(display, NULL, x, y, NULL);
+#endif
+}
+
wxPoint wxGetMousePosition()
{
- int x, y;
- GdkModifierType unused;
- GetMouseState(x, y, unused);
- return wxPoint(x, y);
+ wxPoint pt;
+ wxGetMousePosition(&pt.x, &pt.y);
+ return pt;
}
GdkWindow* wxWindowGTK::GTKGetDrawingWindow() const