Simplify GTK+ 2 version checks with a helper function

Use wx_is_at_least_gtk2(minor) instead of gtk_check_version(2, minor)
because it is more clear and also works as expected (i.e. returns true)
when using GTK+ 3 instead of creating difficult to notice bugs in the
code by failing the version check in this case.

See #18004.
This commit is contained in:
Vadim Zeitlin
2017-11-22 23:59:21 +01:00
parent a8671869e5
commit d6af0236c5
31 changed files with 101 additions and 148 deletions

View File

@@ -99,7 +99,7 @@ static void wxgtk_window_set_urgency_hint (GtkWindow *win,
gboolean setting)
{
#if GTK_CHECK_VERSION(2,7,0)
if (gtk_check_version(2,7,0) == NULL)
if (wx_is_at_least_gtk2(7))
gtk_window_set_urgency_hint(win, setting);
else
#endif
@@ -1582,28 +1582,29 @@ bool wxTopLevelWindowGTK::SetTransparent(wxByte alpha)
{
if (m_widget == NULL)
return false;
#if GTK_CHECK_VERSION(2,12,0)
#ifndef __WXGTK3__
if (gtk_check_version(2,12,0) == NULL)
#endif
{
#ifdef __WXGTK3__
#if GTK_CHECK_VERSION(3,8,0)
if(gtk_check_version(3,8,0) == NULL)
{
gtk_widget_set_opacity(m_widget, alpha / 255.0);
}
else
#endif
{
// Can't avoid using this deprecated function with older GTK+.
wxGCC_WARNING_SUPPRESS(deprecated-declarations);
gtk_window_set_opacity(GTK_WINDOW(m_widget), alpha / 255.0);
wxGCC_WARNING_RESTORE();
}
if(gtk_check_version(3,8,0) == NULL)
{
gtk_widget_set_opacity(m_widget, alpha / 255.0);
}
else
#endif // GTK+ 3.8+
{
gtk_window_set_opacity(GTK_WINDOW(m_widget), alpha / 255.0);
}
return true;
#else // !__WXGTK3__
#if GTK_CHECK_VERSION(2,12,0)
if (wx_is_at_least_gtk2(12))
{
gtk_window_set_opacity(GTK_WINDOW(m_widget), alpha / 255.0);
return true;
}
#endif // GTK_CHECK_VERSION(2,12,0)
#ifndef __WXGTK3__
#ifdef GDK_WINDOWING_X11
GdkWindow* window = gtk_widget_get_window(m_widget);
if (window == NULL)
@@ -1626,7 +1627,7 @@ bool wxTopLevelWindowGTK::SetTransparent(wxByte alpha)
#else // !GDK_WINDOWING_X11
return false;
#endif // GDK_WINDOWING_X11 / !GDK_WINDOWING_X11
#endif // !__WXGTK3__
#endif // __WXGTK3__/!__WXGTK3__
}
bool wxTopLevelWindowGTK::CanSetTransparent()
@@ -1638,11 +1639,8 @@ bool wxTopLevelWindowGTK::CanSetTransparent()
return wxSystemOptions::GetOptionInt(SYSOPT_TRANSPARENT) != 0;
}
#ifdef __WXGTK3__
return gtk_widget_is_composited(m_widget) != 0;
#else
#if GTK_CHECK_VERSION(2,10,0)
if (!gtk_check_version(2,10,0))
if (wx_is_at_least_gtk2(10))
{
return gtk_widget_is_composited(m_widget) != 0;
}
@@ -1651,7 +1649,6 @@ bool wxTopLevelWindowGTK::CanSetTransparent()
{
return false;
}
#endif // !__WXGTK3__
#if 0 // Don't be optimistic here for the sake of wxAUI
int opcode, event, error;