+#include "wx/gtk/private/win_gtk.h"
+#include "wx/gtk/private/gtk2-compat.h"
+
+bool wxGetFrameExtents(GdkWindow* window, int* left, int* right, int* top, int* bottom);
+
+// ----------------------------------------------------------------------------
+// wxSystemSettings implementation
+// ----------------------------------------------------------------------------
+
+static wxFont gs_fontSystem;
+
+static GtkContainer* ContainerWidget()
+{
+ static GtkContainer* s_widget;
+ if (s_widget == NULL)
+ {
+ s_widget = GTK_CONTAINER(gtk_fixed_new());
+ GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(s_widget));
+ }
+ return s_widget;
+}
+
+extern "C" {
+#ifdef __WXGTK3__
+static void style_updated(GtkWidget*, void*)
+#else
+static void style_set(GtkWidget*, GtkStyle*, void*)
+#endif
+{
+ gs_fontSystem = wxNullFont;
+}
+}
+
+static GtkWidget* ButtonWidget()
+{
+ static GtkWidget* s_widget;
+ if (s_widget == NULL)
+ {
+ s_widget = gtk_button_new();
+ gtk_container_add(ContainerWidget(), s_widget);
+#ifdef __WXGTK3__
+ g_signal_connect(s_widget, "style_updated", G_CALLBACK(style_updated), NULL);
+#else
+ gtk_widget_ensure_style(s_widget);
+ g_signal_connect(s_widget, "style_set", G_CALLBACK(style_set), NULL);
+#endif
+ }
+ return s_widget;
+}
+
+static GtkWidget* ListWidget()
+{
+ static GtkWidget* s_widget;
+ if (s_widget == NULL)
+ {
+ s_widget = gtk_tree_view_new_with_model(
+ GTK_TREE_MODEL(gtk_list_store_new(1, G_TYPE_INT)));
+ gtk_container_add(ContainerWidget(), s_widget);
+#ifndef __WXGTK3__
+ gtk_widget_ensure_style(s_widget);
+#endif
+ }
+ return s_widget;
+}
+
+static GtkWidget* TextCtrlWidget()
+{
+ static GtkWidget* s_widget;
+ if (s_widget == NULL)
+ {
+ s_widget = gtk_text_view_new();
+ gtk_container_add(ContainerWidget(), s_widget);
+#ifndef __WXGTK3__
+ gtk_widget_ensure_style(s_widget);
+#endif
+ }
+ return s_widget;
+}
+
+static GtkWidget* MenuItemWidget()
+{
+ static GtkWidget* s_widget;
+ if (s_widget == NULL)
+ {
+ s_widget = gtk_menu_item_new();
+ gtk_container_add(ContainerWidget(), s_widget);
+#ifndef __WXGTK3__
+ gtk_widget_ensure_style(s_widget);
+#endif
+ }
+ return s_widget;
+}
+
+static GtkWidget* MenuBarWidget()
+{
+ static GtkWidget* s_widget;
+ if (s_widget == NULL)
+ {
+ s_widget = gtk_menu_bar_new();
+ gtk_container_add(ContainerWidget(), s_widget);
+#ifndef __WXGTK3__
+ gtk_widget_ensure_style(s_widget);
+#endif
+ }
+ return s_widget;
+}
+
+static GtkWidget* ToolTipWidget()
+{
+ static GtkWidget* s_widget;
+ if (s_widget == NULL)
+ {
+ s_widget = gtk_window_new(GTK_WINDOW_POPUP);
+ const char* name = "gtk-tooltip";
+#ifndef __WXGTK3__
+ if (gtk_check_version(2, 11, 0))
+ name = "gtk-tooltips";
+#endif
+ gtk_widget_set_name(s_widget, name);
+#ifndef __WXGTK3__
+ gtk_widget_ensure_style(s_widget);
+#endif
+ }
+ return s_widget;
+}
+
+#ifdef __WXGTK3__
+static void bg(GtkWidget* widget, GtkStateFlags state, GdkRGBA& gdkRGBA)
+{
+ GtkStyleContext* sc = gtk_widget_get_style_context(widget);
+ gtk_style_context_get_background_color(sc, state, &gdkRGBA);
+}
+static void fg(GtkWidget* widget, GtkStateFlags state, GdkRGBA& gdkRGBA)
+{
+ GtkStyleContext* sc = gtk_widget_get_style_context(widget);
+ gtk_style_context_get_color(sc, state, &gdkRGBA);
+}
+static void border(GtkWidget* widget, GtkStateFlags state, GdkRGBA& gdkRGBA)
+{
+ GtkStyleContext* sc = gtk_widget_get_style_context(widget);
+ gtk_style_context_get_border_color(sc, state, &gdkRGBA);
+}
+
+wxColour wxSystemSettingsNative::GetColour(wxSystemColour index)
+{
+ GdkRGBA gdkRGBA = { 0, 0, 0, 1 };
+ switch (index)
+ {
+ case wxSYS_COLOUR_3DLIGHT:
+ case wxSYS_COLOUR_ACTIVEBORDER:
+ case wxSYS_COLOUR_BTNFACE:
+ case wxSYS_COLOUR_DESKTOP:
+ case wxSYS_COLOUR_INACTIVEBORDER:
+ case wxSYS_COLOUR_INACTIVECAPTION:
+ case wxSYS_COLOUR_SCROLLBAR:
+ case wxSYS_COLOUR_WINDOWFRAME:
+ bg(ButtonWidget(), GTK_STATE_FLAG_NORMAL, gdkRGBA);
+ break;
+ case wxSYS_COLOUR_BTNHIGHLIGHT:
+ case wxSYS_COLOUR_HIGHLIGHT:
+ bg(ButtonWidget(), GTK_STATE_FLAG_SELECTED, gdkRGBA);
+ break;
+ case wxSYS_COLOUR_BTNSHADOW:
+ border(ButtonWidget(), GTK_STATE_FLAG_NORMAL, gdkRGBA);
+ break;
+ case wxSYS_COLOUR_BTNTEXT:
+ case wxSYS_COLOUR_WINDOWTEXT:
+ fg(ButtonWidget(), GTK_STATE_FLAG_NORMAL, gdkRGBA);
+ break;
+ case wxSYS_COLOUR_GRAYTEXT:
+ case wxSYS_COLOUR_INACTIVECAPTIONTEXT:
+ fg(ButtonWidget(), GTK_STATE_FLAG_INSENSITIVE, gdkRGBA);
+ break;
+ case wxSYS_COLOUR_HIGHLIGHTTEXT:
+ fg(ButtonWidget(), GTK_STATE_FLAG_SELECTED, gdkRGBA);
+ break;
+ case wxSYS_COLOUR_HOTLIGHT:
+ {
+ static GtkWidget* s_widget;
+ if (s_widget == NULL)
+ {
+ s_widget = gtk_link_button_new("");
+ gtk_container_add(ContainerWidget(), s_widget);
+ }
+ fg(s_widget, GTK_STATE_FLAG_NORMAL, gdkRGBA);
+ }
+ break;
+ case wxSYS_COLOUR_INFOBK:
+ bg(ToolTipWidget(), GTK_STATE_FLAG_NORMAL, gdkRGBA);
+ break;
+ case wxSYS_COLOUR_INFOTEXT:
+ fg(ToolTipWidget(), GTK_STATE_FLAG_NORMAL, gdkRGBA);
+ break;
+ case wxSYS_COLOUR_LISTBOX:
+ bg(ListWidget(), GTK_STATE_FLAG_NORMAL, gdkRGBA);
+ break;
+ case wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT:
+ fg(ListWidget(), GTK_STATE_FLAG_SELECTED, gdkRGBA);
+ break;
+ case wxSYS_COLOUR_LISTBOXTEXT:
+ fg(ListWidget(), GTK_STATE_FLAG_NORMAL, gdkRGBA);
+ break;
+ case wxSYS_COLOUR_MENU:
+ bg(MenuItemWidget(), GTK_STATE_FLAG_NORMAL, gdkRGBA);
+ break;
+ case wxSYS_COLOUR_MENUBAR:
+ bg(MenuBarWidget(), GTK_STATE_FLAG_NORMAL, gdkRGBA);
+ break;
+ case wxSYS_COLOUR_ACTIVECAPTION:
+ case wxSYS_COLOUR_MENUHILIGHT:
+ bg(MenuItemWidget(), GTK_STATE_FLAG_SELECTED, gdkRGBA);
+ break;
+ case wxSYS_COLOUR_MENUTEXT:
+ fg(MenuItemWidget(), GTK_STATE_FLAG_NORMAL, gdkRGBA);
+ break;
+ case wxSYS_COLOUR_APPWORKSPACE:
+ case wxSYS_COLOUR_WINDOW:
+ bg(TextCtrlWidget(), GTK_STATE_FLAG_NORMAL, gdkRGBA);
+ break;
+ case wxSYS_COLOUR_CAPTIONTEXT:
+ {
+ GdkRGBA c = { 1, 1, 1, 1 };
+ gdkRGBA = c;
+ }
+ break;
+ default:
+ wxFAIL_MSG("unknown system colour index");
+ // fallthrough
+ case wxSYS_COLOUR_3DDKSHADOW:
+ case wxSYS_COLOUR_GRADIENTACTIVECAPTION:
+ case wxSYS_COLOUR_GRADIENTINACTIVECAPTION:
+ // black
+ break;
+ }
+ return wxColour(gdkRGBA);
+}
+#else
+static const GtkStyle* ButtonStyle()
+{
+ return gtk_widget_get_style(ButtonWidget());
+}
+
+static const GtkStyle* ListStyle()
+{
+ return gtk_widget_get_style(ListWidget());
+}