]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/settings.cpp
Use wxSP_WRAP for generic wxTimePicker spin button.
[wxWidgets.git] / src / gtk / settings.cpp
index 26951dcfd9d9909fb2ee5e101a1f4ecfb5d859ab..0712e10fe77737d737ef7b38908e66e29b18b56b 100644 (file)
 #include "wx/settings.h"
 
 #ifndef WX_PRECOMP
-    #include "wx/cmndata.h"
     #include "wx/toplevel.h"
 #endif
 
 #include "wx/fontutil.h"
+#include "wx/fontenum.h"
 
 #include <gtk/gtk.h>
+#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);
 
@@ -59,7 +61,7 @@ static const GtkStyle* ButtonStyle()
         gtk_widget_ensure_style(s_widget);
         g_signal_connect(s_widget, "style_set", G_CALLBACK(style_set), NULL);
     }
-    return s_widget->style;
+    return gtk_widget_get_style(s_widget);
 }
 
 static const GtkStyle* ListStyle()
@@ -72,7 +74,7 @@ static const GtkStyle* ListStyle()
         gtk_container_add(ContainerWidget(), s_widget);
         gtk_widget_ensure_style(s_widget);
     }
-    return s_widget->style;
+    return gtk_widget_get_style(s_widget);
 }
 
 static const GtkStyle* TextCtrlStyle()
@@ -84,7 +86,7 @@ static const GtkStyle* TextCtrlStyle()
         gtk_container_add(ContainerWidget(), s_widget);
         gtk_widget_ensure_style(s_widget);
     }
-    return s_widget->style;
+    return gtk_widget_get_style(s_widget);
 }
 
 static const GtkStyle* MenuItemStyle()
@@ -96,7 +98,7 @@ static const GtkStyle* MenuItemStyle()
         gtk_container_add(ContainerWidget(), s_widget);
         gtk_widget_ensure_style(s_widget);
     }
-    return s_widget->style;
+    return gtk_widget_get_style(s_widget);
 }
 
 static const GtkStyle* MenuBarStyle()
@@ -108,7 +110,7 @@ static const GtkStyle* MenuBarStyle()
         gtk_container_add(ContainerWidget(), s_widget);
         gtk_widget_ensure_style(s_widget);
     }
-    return s_widget->style;
+    return gtk_widget_get_style(s_widget);
 }
 
 static const GtkStyle* ToolTipStyle()
@@ -123,7 +125,7 @@ static const GtkStyle* ToolTipStyle()
         gtk_widget_set_name(s_widget, name);
         gtk_widget_ensure_style(s_widget);
     }
-    return s_widget->style;
+    return gtk_widget_get_style(s_widget);
 }
 
 wxColour wxSystemSettingsNative::GetColour( wxSystemColour index )
@@ -184,6 +186,16 @@ wxColour wxSystemSettingsNative::GetColour( wxSystemColour index )
             color = wxColor(ListStyle()->base[GTK_STATE_NORMAL]);
             break;
 
+        case wxSYS_COLOUR_LISTBOXTEXT:
+            color = wxColor(ListStyle()->text[GTK_STATE_NORMAL]);
+            break;
+
+        case wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT:
+            // This is for the text in a list control (or tree) when the
+            // item is selected, but not focused
+            color = wxColor(ListStyle()->text[GTK_STATE_ACTIVE]);
+            break;
+
         case wxSYS_COLOUR_MENUTEXT:
         case wxSYS_COLOUR_WINDOWTEXT:
         case wxSYS_COLOUR_CAPTIONTEXT:
@@ -222,11 +234,12 @@ wxColour wxSystemSettingsNative::GetColour( wxSystemColour index )
 
         case wxSYS_COLOUR_MAX:
         default:
-            wxFAIL_MSG( _T("unknown system colour index") );
+            wxFAIL_MSG( wxT("unknown system colour index") );
             color = *wxWHITE;
             break;
     }
 
+    wxASSERT(color.IsOk());
     return color;
 }
 
@@ -245,11 +258,20 @@ wxFont wxSystemSettingsNative::GetFont( wxSystemFont index )
         case wxSYS_SYSTEM_FONT:
         case wxSYS_DEVICE_DEFAULT_FONT:
         case wxSYS_DEFAULT_GUI_FONT:
-            if (!gs_fontSystem.Ok())
+            if (!gs_fontSystem.IsOk())
             {
                 wxNativeFontInfo info;
                 info.description = ButtonStyle()->font_desc;
                 gs_fontSystem = wxFont(info);
+
+#if wxUSE_FONTENUM
+                // (try to) heal the default font (on some common systems e.g. Ubuntu
+                // it's "Sans Serif" but the real font is called "Sans"):
+                if (!wxFontEnumerator::IsValidFacename(gs_fontSystem.GetFaceName()) &&
+                    gs_fontSystem.GetFaceName() == "Sans Serif")
+                    gs_fontSystem.SetFaceName("Sans");
+#endif // wxUSE_FONTENUM
+
                 info.description = NULL;
             }
             font = gs_fontSystem;
@@ -258,6 +280,9 @@ wxFont wxSystemSettingsNative::GetFont( wxSystemFont index )
         default:
             break;
     }
+
+    wxASSERT( font.IsOk() );
+
     return font;
 }
 
@@ -269,11 +294,31 @@ static GtkSettings *GetSettingsForWindowScreen(GdkWindow *window)
                   : gtk_settings_get_default();
 }
 
+static int GetBorderWidth(wxSystemMetric index, wxWindow* win)
+{
+    if (win->m_wxwindow)
+    {
+        wxPizza* pizza = WX_PIZZA(win->m_wxwindow);
+        int x, y;
+        pizza->get_border_widths(x, y);
+        switch (index)
+        {
+            case wxSYS_BORDER_X:
+            case wxSYS_EDGE_X:
+            case wxSYS_FRAMESIZE_X:
+                return x;
+            default:
+                return y;
+        }
+    }
+    return -1;
+}
+
 int wxSystemSettingsNative::GetMetric( wxSystemMetric index, wxWindow* win )
 {
     GdkWindow *window = NULL;
-    if(win && GTK_WIDGET_REALIZED(win->GetHandle()))
-        window = win->GetHandle()->window;
+    if (win)
+        window = gtk_widget_get_window(win->GetHandle());
 
     switch (index)
     {
@@ -283,14 +328,12 @@ int wxSystemSettingsNative::GetMetric( wxSystemMetric index, wxWindow* win )
         case wxSYS_EDGE_Y:
         case wxSYS_FRAMESIZE_X:
         case wxSYS_FRAMESIZE_Y:
-            // If a window is specified/realized, and it is a toplevel window, we can query from wm.
-            // The returned border thickness is outside the client area in that case.
-            if (window)
+            if (win)
             {
                 wxTopLevelWindow *tlw = wxDynamicCast(win, wxTopLevelWindow);
                 if (!tlw)
-                    return -1; // not a tlw, not sure how to approach
-                else
+                    return GetBorderWidth(index, win);
+                else if (window)
                 {
                     // Get the frame extents from the windowmanager.
                     // In most cases the top extent is the titlebar, so we use the bottom extent