X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fc29e86ef781c56b4cfbd07bc17ac1611d211884..3bf5a59b5e058bebffcf9d87f03550b4ecf93e73:/src/msw/settings.cpp diff --git a/src/msw/settings.cpp b/src/msw/settings.cpp index 3e55d24dfe..9ba29bc069 100644 --- a/src/msw/settings.cpp +++ b/src/msw/settings.cpp @@ -5,8 +5,8 @@ // Modified by: // Created: 04/01/98 // RCS-ID: $Id$ -// Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows license +// Copyright: (c) Julian Smart +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -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,112 @@ 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 ) + { +#ifdef __WXWINCE__ + colSys = ::GetSysColor(index|SYS_COLOR_INDEX_FLAG); +#else + colSys = ::GetSysColor(index); +#endif + } + + return wxRGBToColour(colSys); } // ---------------------------------------------------------------------------- @@ -175,7 +283,7 @@ wxFont wxSystemSettingsNative::GetFont(wxSystemFont index) static const int gs_metricsMap[] = { -1, // wxSystemMetric enums start at 1, so give a dummy value for pos 0. -#ifdef __WIN32__ +#if defined(__WIN32__) && !defined(__WXWINCE__) SM_CMOUSEBUTTONS, #else -1, @@ -193,17 +301,25 @@ static const int gs_metricsMap[] = SM_CXEDGE, SM_CYEDGE, #else - -1, -1, -1, -1 + -1, -1, -1, -1, #endif SM_CXHSCROLL, SM_CYHSCROLL, +#ifdef SM_CXHTHUMB SM_CXHTHUMB, +#else + -1, +#endif SM_CXICON, SM_CYICON, SM_CXICONSPACING, SM_CYICONSPACING, +#ifdef SM_CXHTHUMB SM_CXMIN, SM_CYMIN, +#else + -1, -1, +#endif SM_CXSCREEN, SM_CYSCREEN, @@ -213,13 +329,17 @@ static const int gs_metricsMap[] = SM_CXSMICON, SM_CYSMICON, #else - -1, -1, -1, -1 + -1, -1, -1, -1, #endif SM_CYHSCROLL, SM_CXVSCROLL, SM_CXVSCROLL, SM_CYVSCROLL, +#ifdef SM_CYVTHUMB SM_CYVTHUMB, +#else + -1, +#endif SM_CYCAPTION, SM_CYMENU, #if defined(__WIN32__) && defined(SM_NETWORK) @@ -227,13 +347,21 @@ static const int gs_metricsMap[] = #else -1, #endif +#ifdef SM_PENWINDOWS SM_PENWINDOWS, +#else + -1, +#endif #if defined(__WIN32__) && defined(SM_SHOWSOUNDS) SM_SHOWSOUNDS, #else -1, #endif +#ifdef SM_SWAPBUTTON SM_SWAPBUTTON, +#else + -1 +#endif }; // Get a system metric, e.g. scrollbar size @@ -243,7 +371,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 )