X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7516ed26c9749018135c24afdd0576e4366c92e6..647b8e379ed0f470f0f643fe816ba872be41541d:/src/msw/settings.cpp diff --git a/src/msw/settings.cpp b/src/msw/settings.cpp index 3f6107f4f8..a621cc73e2 100644 --- a/src/msw/settings.cpp +++ b/src/msw/settings.cpp @@ -25,6 +25,7 @@ #endif #ifndef WX_PRECOMP + #include "wx/utils.h" #include "wx/gdicmn.h" #endif @@ -32,6 +33,10 @@ #include "wx/msw/private.h" +#ifndef SPI_GETFLATMENU +#define SPI_GETFLATMENU 0x1022 +#endif + #include "wx/module.h" #include "wx/fontutil.h" @@ -97,9 +102,108 @@ void wxSystemSettingsModule::OnExit() wxColour wxSystemSettingsNative::GetColour(wxSystemColour index) { - wxColour col; - wxRGBToColour(col, ::GetSysColor(index)); - return col; + // 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_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; + + // none of the is supported under Win16 anyhow +#ifdef __WIN32__ + 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 ; + } + } + } +#else + useDefault = TRUE; +#endif // __WIN32__ + + 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), + _T("forgot tp update the default colours array") ); + + colSys = s_defaultSysColors[n]; + hasCol = TRUE; + } + } + } + + if ( !hasCol ) + { + colSys = ::GetSysColor(index); + } + + return wxRGBToColour(colSys); } // ---------------------------------------------------------------------------- @@ -174,6 +278,7 @@ wxFont wxSystemSettingsNative::GetFont(wxSystemFont index) // unknown static const int gs_metricsMap[] = { + -1, // wxSystemMetric enums start at 1, so give a dummy value for pos 0. #ifdef __WIN32__ SM_CMOUSEBUTTONS, #else @@ -242,7 +347,8 @@ int wxSystemSettingsNative::GetMetric(wxSystemMetric index) // TODO: probably use wxUniv themes functionality return 0; #else // !__WXMICROWIN__ - wxCHECK_MSG( index < WXSIZEOF(gs_metricsMap), 0, _T("invalid metric") ); + wxCHECK_MSG( index > 0 && (size_t)index < WXSIZEOF(gs_metricsMap), 0, + _T("invalid metric") ); int indexMSW = gs_metricsMap[index]; if ( indexMSW == -1 )