+// ----------------------------------------------------------------------------
+// wxSystemSettingsNative
+// ----------------------------------------------------------------------------
+
+// ----------------------------------------------------------------------------
+// colours
+// ----------------------------------------------------------------------------
+
+wxColour wxSystemSettingsNative::GetColour(wxSystemColour index)
+{
+ // we use 0 as the default value just to avoid compiler warnings, as there
+ // is no invalid colour value we use hasCol as the real indicator of
+ // whether colSys was initialized or not
+ COLORREF colSys = 0;
+ bool hasCol = false;
+
+ // the default colours for the entries after BTNHIGHLIGHT
+ static const COLORREF s_defaultSysColors[] =
+ {
+ 0x000000, // 3DDKSHADOW
+ 0xdfdfdf, // 3DLIGHT
+ 0x000000, // INFOTEXT
+ 0xe1ffff, // INFOBK
+
+ 0, // filler - no std colour with this index
+
+ // TODO: please fill in the standard values of those, I don't have them
+ 0, // HOTLIGHT
+ 0, // GRADIENTACTIVECAPTION
+ 0, // GRADIENTINACTIVECAPTION
+ 0, // MENU
+ 0, // MENUBAR (unused)
+ };
+
+ if ( index == wxSYS_COLOUR_LISTBOXTEXT)
+ {
+ // there is no standard colour with this index, map to another one
+ index = wxSYS_COLOUR_WINDOWTEXT;
+ }
+ else if ( index == wxSYS_COLOUR_LISTBOX )
+ {
+ // there is no standard colour with this index, map to another one
+ index = wxSYS_COLOUR_WINDOW;
+ }
+ else if ( index > wxSYS_COLOUR_BTNHIGHLIGHT )
+ {
+ // the indices before BTNHIGHLIGHT are understood by GetSysColor() in
+ // all Windows version, for the other ones we have to check
+ bool useDefault;
+
+ int verMaj, verMin;
+ wxGetOsVersion(&verMaj, &verMin);
+ if ( verMaj < 4 )
+ {
+ // NT 3.5
+ useDefault = true;
+ }
+ else if ( verMaj == 4 )
+ {
+ // Win95/NT 4.0
+ useDefault = index > wxSYS_COLOUR_INFOBK;
+ }
+ else if ( verMaj == 5 && verMin == 0 )
+ {
+ // Win98/Win2K
+ useDefault = index > wxSYS_COLOUR_GRADIENTINACTIVECAPTION;
+ }
+ else // >= 5.1
+ {
+ // 5.1 is Windows XP
+ useDefault = false;
+ // Determine if we are using flat menus, only then allow wxSYS_COLOUR_MENUBAR
+ if ( index == wxSYS_COLOUR_MENUBAR )
+ {
+ BOOL isFlat ;
+ if ( SystemParametersInfo( SPI_GETFLATMENU , 0 ,&isFlat, 0 ) )
+ {
+ if ( !isFlat )
+ index = wxSYS_COLOUR_MENU ;
+ }
+ }
+ }
+
+ if ( useDefault )
+ {
+ // special handling for MENUBAR colour: we use this in wxToolBar
+ // and wxStatusBar to have correct bg colour under Windows XP
+ // (which uses COLOR_MENUBAR for them) but they should still look
+ // correctly under previous Windows versions as well
+ if ( index == wxSYS_COLOUR_MENUBAR )
+ {
+ index = wxSYS_COLOUR_3DFACE;
+ }
+ else // replace with default colour
+ {
+ unsigned int n = index - wxSYS_COLOUR_BTNHIGHLIGHT;
+
+ wxASSERT_MSG( n < WXSIZEOF(s_defaultSysColors),
+ wxT("forgot tp update the default colours array") );
+
+ colSys = s_defaultSysColors[n];
+ hasCol = true;
+ }
+ }
+ }
+
+ if ( !hasCol )
+ {
+#ifdef __WXWINCE__
+ colSys = ::GetSysColor(index|SYS_COLOR_INDEX_FLAG);
+#else
+ colSys = ::GetSysColor(index);
+#endif
+ }
+
+ wxColour ret = wxRGBToColour(colSys);
+ wxASSERT(ret.IsOk());
+ return ret;
+}
+
+// ----------------------------------------------------------------------------
+// fonts
+// ----------------------------------------------------------------------------
+
+wxFont wxCreateFontFromStockObject(int index)
+{
+ wxFont font;
+
+ HFONT hFont = (HFONT) ::GetStockObject(index);
+ if ( hFont )
+ {
+ LOGFONT lf;
+ if ( ::GetObject(hFont, sizeof(LOGFONT), &lf) != 0 )
+ {
+ wxNativeFontInfo info;
+ info.lf = lf;
+ // Under MicroWindows we pass the HFONT as well
+ // because it's hard to convert HFONT -> LOGFONT -> HFONT
+ // It's OK to delete stock objects, the delete will be ignored.
+#ifdef __WXMICROWIN__
+ font.Create(info, (WXHFONT) hFont);
+#else
+ font.Create(info);
+#endif
+ }
+ else
+ {
+ wxFAIL_MSG( wxT("failed to get LOGFONT") );
+ }
+ }
+ else // GetStockObject() failed
+ {
+ wxFAIL_MSG( wxT("stock font not found") );
+ }
+
+ return font;
+}
+
+wxFont wxSystemSettingsNative::GetFont(wxSystemFont index)
+{
+#ifdef __WXWINCE__
+ // under CE only a single SYSTEM_FONT exists
+ index;
+
+ if ( !gs_fontDefault )
+ {
+ gs_fontDefault = new wxFont(wxCreateFontFromStockObject(SYSTEM_FONT));
+ }
+
+ wxASSERT(gs_fontDefault->IsOk() &&
+ wxFontEnumerator::IsValidFacename(gs_fontDefault->GetFaceName()));
+ return *gs_fontDefault;
+#else // !__WXWINCE__
+ // wxWindow ctor calls GetFont(wxSYS_DEFAULT_GUI_FONT) so we're
+ // called fairly often -- this is why we cache this particular font
+ if ( index == wxSYS_DEFAULT_GUI_FONT )
+ {
+ if ( !gs_fontDefault )
+ {
+ // http://blogs.msdn.com/oldnewthing/archive/2005/07/07/436435.aspx
+ // explains why neither SYSTEM_FONT nor DEFAULT_GUI_FONT should be
+ // used here
+ //
+ // the message box font seems to be the one which should be used
+ // for most (simple) controls, e.g. buttons and such but other
+ // controls may prefer to use lfStatusFont or lfCaptionFont if it
+ // is more appropriate for them
+ wxNativeFontInfo info;
+ info.lf = wxMSWImpl::GetNonClientMetrics().lfMessageFont;
+ gs_fontDefault = new wxFont(info);
+ }
+
+ return *gs_fontDefault;
+ }
+
+ wxFont font = wxCreateFontFromStockObject(index);
+
+ wxASSERT(font.IsOk());
+
+#if wxUSE_FONTENUM
+ wxASSERT(wxFontEnumerator::IsValidFacename(font.GetFaceName()));
+#endif // wxUSE_FONTENUM
+
+ return font;
+#endif // __WXWINCE__/!__WXWINCE__
+}
+
+// ----------------------------------------------------------------------------
+// system metrics/features
+// ----------------------------------------------------------------------------
+
+// TODO: some of the "metrics" clearly should be features now that we have
+// HasFeature()!
+
+// the conversion table from wxSystemMetric enum to GetSystemMetrics() param
+//
+// if the constant is not defined, put -1 in the table to indicate that it is
+// unknown
+static const int gs_metricsMap[] =