From: Vadim Zeitlin Date: Sun, 30 Dec 2001 22:34:36 +0000 (+0000) Subject: 1. wxSystemSettings class API face lift: better names for its methods X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/7516ed26c9749018135c24afdd0576e4366c92e6 1. wxSystemSettings class API face lift: better names for its methods 2. wxSystemSettings under wxUniv uses the wxTheme and wxColourScheme git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13254 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/distrib/msw/tmake/filelist.txt b/distrib/msw/tmake/filelist.txt index 9e19b64118..529d67da1a 100644 --- a/distrib/msw/tmake/filelist.txt +++ b/distrib/msw/tmake/filelist.txt @@ -1200,7 +1200,6 @@ regconf.h MSWH region.h MSWH registry.h MSWH scrolbar.h MSWH -settings.h MSWH setup0.h MSWH slider95.h MSWH slidrmsw.h MSWH diff --git a/include/wx/msw/settings.h b/include/wx/msw/settings.h deleted file mode 100644 index bf24eb5bc6..0000000000 --- a/include/wx/msw/settings.h +++ /dev/null @@ -1,41 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/msw/settings.h -// Purpose: wxSystemSettings class -// Author: Julian Smart -// Modified by: -// Created: 01/02/97 -// RCS-ID: $Id$ -// Copyright: (c) Julian Smart -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_SETTINGS_H_ -#define _WX_SETTINGS_H_ - -#ifdef __GNUG__ -#pragma interface "settings.h" -#endif - -#include "wx/colour.h" -#include "wx/font.h" - -class WXDLLEXPORT wxSystemSettings : public wxObject -{ -public: - wxSystemSettings() { } - - // Get a system colour - static wxColour GetSystemColour(int index); - - // Get a system font - static wxFont GetSystemFont(int index); - - // Get a system metric, e.g. scrollbar size - static int GetSystemMetric(int index); - - // Return true if the port has certain feature - static bool GetCapability(int index); -}; - -#endif - // _WX_SETTINGS_H_ diff --git a/include/wx/settings.h b/include/wx/settings.h index 1a52f5d711..46dac734b5 100644 --- a/include/wx/settings.h +++ b/include/wx/settings.h @@ -1,12 +1,12 @@ ///////////////////////////////////////////////////////////////////////////// // Name: wx/settings.h -// Purpose: wxSystemSettingsBase class +// Purpose: wxSystemSettings class // Author: Julian Smart // Modified by: // Created: 01/02/97 // RCS-ID: $Id$ // Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifndef _WX_SETTINGS_H_BASE_ @@ -73,6 +73,9 @@ enum wxSystemColour }; // possible values for wxSystemSettings::GetMetric() parameter +// +// NB: update the conversion table in msw/settings.cpp if you change the values +// of the elements of this enum enum wxSystemMetric { wxSYS_MOUSE_BUTTONS = 1, @@ -122,7 +125,7 @@ enum wxSystemFeature }; // ---------------------------------------------------------------------------- -// wxSystemSettingsBase: defines the API for wxSystemSettings class +// wxSystemSettingsNative: defines the API for wxSystemSettings class // ---------------------------------------------------------------------------- // this is a namespace rather than a class: it has only non virtual static @@ -132,8 +135,7 @@ enum wxSystemFeature // files (i.e. this is not a real base class as we can't override its virtual // functions because it doesn't have any) -#if 0 -class WXDLLEXPORT wxSystemSettingsBase +class WXDLLEXPORT wxSystemSettingsNative { public: // get a standard system colour @@ -157,17 +159,14 @@ public: { return GetFont((wxSystemFont)index); } static int GetSystemMetric(int index) { return GetMetric((wxSystemMetric)index); } - static bool GetCapability(int index) - { return HasFeature((wxSystemFeature)index); } }; -#endif // ---------------------------------------------------------------------------- // include the declaration of the real platform-dependent class // ---------------------------------------------------------------------------- #if defined(__WXMSW__) - #include "wx/msw/settings.h" + #define wxHAS_SS_NATIVE #elif defined(__WXMOTIF__) #include "wx/motif/settings.h" #elif defined(__WXGTK__) @@ -180,6 +179,22 @@ public: #include "wx/os2/settings.h" #endif +// TODO: this should go away once all ports are updated to use wxSSNative +#ifdef wxHAS_SS_NATIVE + +class wxSystemSettings : public wxSystemSettingsNative +{ +public: +#ifdef __WXUNIVERSAL__ + // in wxUniversal we want to use the theme standard colours instead of the + // system ones, otherwuse wxSystemSettings is just the same as + // wxSystemSettingsNative + static wxColour GetColour(wxSystemColour index); +#endif // __WXUNIVERSAL__ +}; + +#endif // wxHAS_SS_NATIVE + #endif // _WX_SETTINGS_H_BASE_ diff --git a/src/generic/calctrl.cpp b/src/generic/calctrl.cpp index 79943136ec..14c60e5267 100644 --- a/src/generic/calctrl.cpp +++ b/src/generic/calctrl.cpp @@ -169,9 +169,8 @@ void wxCalendarCtrl::Init() m_attrs[n] = NULL; } - wxSystemSettings ss; - m_colHighlightFg = ss.GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT); - m_colHighlightBg = ss.GetSystemColour(wxSYS_COLOUR_HIGHLIGHT); + m_colHighlightFg = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT); + m_colHighlightBg = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT); m_colHolidayFg = *wxRED; // don't set m_colHolidayBg - by default, same as our bg colour diff --git a/src/generic/tbarsmpl.cpp b/src/generic/tbarsmpl.cpp index 10f4cf1103..dd79b926b4 100644 --- a/src/generic/tbarsmpl.cpp +++ b/src/generic/tbarsmpl.cpp @@ -234,8 +234,7 @@ bool wxToolBarSimple::Create(wxWindow *parent, return FALSE; // Set it to grey (or other 3D face colour) - wxSystemSettings settings; - SetBackgroundColour(settings.GetSystemColour(wxSYS_COLOUR_3DFACE)); + SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); if ( GetWindowStyleFlag() & wxTB_VERTICAL ) { diff --git a/src/msw/listbox.cpp b/src/msw/listbox.cpp index e0ed9ed803..b024c65b07 100644 --- a/src/msw/listbox.cpp +++ b/src/msw/listbox.cpp @@ -145,8 +145,7 @@ bool wxListBox::Create(wxWindow *parent, if (parent) parent->AddChild(this); - wxSystemSettings settings; - SetBackgroundColour(settings.GetSystemColour(wxSYS_COLOUR_WINDOW)); + SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); SetForegroundColour(parent->GetForegroundColour()); m_windowId = ( id == -1 ) ? (int)NewControlId() : id; diff --git a/src/msw/settings.cpp b/src/msw/settings.cpp index 7255aad988..3f6107f4f8 100644 --- a/src/msw/settings.cpp +++ b/src/msw/settings.cpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // Name: msw/settings.cpp -// Purpose: wxSystemSettings +// Purpose: wxSystemSettingsNative implementation for MSW // Author: Julian Smart // Modified by: // Created: 04/01/98 @@ -17,28 +17,21 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ - #pragma implementation "settings.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif #ifndef WX_PRECOMP - #include - #include "wx/defs.h" - #include "wx/pen.h" - #include "wx/brush.h" #include "wx/gdicmn.h" #endif #include "wx/settings.h" -#include "wx/window.h" + #include "wx/msw/private.h" + #include "wx/module.h" #include "wx/fontutil.h" @@ -46,11 +39,10 @@ // private classes // ---------------------------------------------------------------------------- -// the module which is used to clean up wxSystemSettings data (this is a +// the module which is used to clean up wxSystemSettingsNative data (this is a // singleton class so it can't be done in the dtor) class wxSystemSettingsModule : public wxModule { - friend class wxSystemSettings; public: virtual bool OnInit(); virtual void OnExit(); @@ -63,12 +55,21 @@ private: // global data // ---------------------------------------------------------------------------- +// the font returned by GetFont(wxSYS_DEFAULT_GUI_FONT): it is created when +// GetFont() is called for the first time and deleted by wxSystemSettingsModule static wxFont *gs_fontDefault = NULL; // ============================================================================ // implementation // ============================================================================ +// TODO: see ::SystemParametersInfo for all sorts of Windows settings. +// Different args are required depending on the id. How does this differ +// from GetSystemMetric, and should it? Perhaps call it GetSystemParameter +// and pass an optional void* arg to get further info. +// Should also have SetSystemParameter. +// Also implement WM_WININICHANGE (NT) / WM_SETTINGCHANGE (Win95) + // ---------------------------------------------------------------------------- // wxSystemSettingsModule // ---------------------------------------------------------------------------- @@ -87,30 +88,24 @@ void wxSystemSettingsModule::OnExit() } // ---------------------------------------------------------------------------- -// wxSystemSettings +// wxSystemSettingsNative // ---------------------------------------------------------------------------- -// TODO: see ::SystemParametersInfo for all sorts of Windows settings. -// Different args are required depending on the id. How does this differ -// from GetSystemMetric, and should it? Perhaps call it GetSystemParameter -// and pass an optional void* arg to get further info. -// Should also have SetSystemParameter. -// Also implement WM_WININICHANGE (NT) / WM_SETTINGCHANGE (Win95) +// ---------------------------------------------------------------------------- +// colours +// ---------------------------------------------------------------------------- -wxColour wxSystemSettings::GetSystemColour(int index) +wxColour wxSystemSettingsNative::GetColour(wxSystemColour index) { - switch (index) - { - case wxSYS_COLOUR_LISTBOX: - return *wxWHITE; - - default: - COLORREF ref = ::GetSysColor(index); - wxColour col(GetRValue(ref), GetGValue(ref), GetBValue(ref)); - return col; - } + wxColour col; + wxRGBToColour(col, ::GetSysColor(index)); + return col; } +// ---------------------------------------------------------------------------- +// fonts +// ---------------------------------------------------------------------------- + wxFont wxCreateFontFromStockObject(int index) { wxFont font; @@ -141,10 +136,11 @@ wxFont wxCreateFontFromStockObject(int index) { wxFAIL_MSG( _T("stock font not found") ); } + return font; } -wxFont wxSystemSettings::GetSystemFont(int index) +wxFont wxSystemSettingsNative::GetFont(wxSystemFont index) { // wxWindow ctor calls GetSystemFont(wxSYS_DEFAULT_GUI_FONT) so we're // called fairly often - this is why we cache this particular font @@ -165,116 +161,118 @@ wxFont wxSystemSettings::GetSystemFont(int index) return font; } -// Get a system metric, e.g. scrollbar size -int wxSystemSettings::GetSystemMetric(int index) +// ---------------------------------------------------------------------------- +// 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[] = { -#ifdef __WXMICROWIN__ - // TODO: probably use wxUniv themes functionality - return 0; -#else - switch ( index) - { #ifdef __WIN32__ - case wxSYS_MOUSE_BUTTONS: - return ::GetSystemMetrics(SM_CMOUSEBUTTONS); + SM_CMOUSEBUTTONS, +#else + -1, #endif - case wxSYS_BORDER_X: - return ::GetSystemMetrics(SM_CXBORDER); - case wxSYS_BORDER_Y: - return ::GetSystemMetrics(SM_CYBORDER); - case wxSYS_CURSOR_X: - return ::GetSystemMetrics(SM_CXCURSOR); - case wxSYS_CURSOR_Y: - return ::GetSystemMetrics(SM_CYCURSOR); - case wxSYS_DCLICK_X: - return ::GetSystemMetrics(SM_CXDOUBLECLK); - case wxSYS_DCLICK_Y: - return ::GetSystemMetrics(SM_CYDOUBLECLK); + SM_CXBORDER, + SM_CYBORDER, + SM_CXCURSOR, + SM_CYCURSOR, + SM_CXDOUBLECLK, + SM_CYDOUBLECLK, #if defined(__WIN32__) && defined(SM_CXDRAG) - case wxSYS_DRAG_X: - return ::GetSystemMetrics(SM_CXDRAG); - case wxSYS_DRAG_Y: - return ::GetSystemMetrics(SM_CYDRAG); - case wxSYS_EDGE_X: - return ::GetSystemMetrics(SM_CXEDGE); - case wxSYS_EDGE_Y: - return ::GetSystemMetrics(SM_CYEDGE); + SM_CXDRAG, + SM_CYDRAG, + SM_CXEDGE, + SM_CYEDGE, +#else + -1, -1, -1, -1 #endif - case wxSYS_HSCROLL_ARROW_X: - return ::GetSystemMetrics(SM_CXHSCROLL); - case wxSYS_HSCROLL_ARROW_Y: - return ::GetSystemMetrics(SM_CYHSCROLL); - case wxSYS_HTHUMB_X: - return ::GetSystemMetrics(SM_CXHTHUMB); - case wxSYS_ICON_X: - return ::GetSystemMetrics(SM_CXICON); - case wxSYS_ICON_Y: - return ::GetSystemMetrics(SM_CYICON); - case wxSYS_ICONSPACING_X: - return ::GetSystemMetrics(SM_CXICONSPACING); - case wxSYS_ICONSPACING_Y: - return ::GetSystemMetrics(SM_CYICONSPACING); - case wxSYS_WINDOWMIN_X: - return ::GetSystemMetrics(SM_CXMIN); - case wxSYS_WINDOWMIN_Y: - return ::GetSystemMetrics(SM_CYMIN); - case wxSYS_SCREEN_X: - return ::GetSystemMetrics(SM_CXSCREEN); - case wxSYS_SCREEN_Y: - return ::GetSystemMetrics(SM_CYSCREEN); + SM_CXHSCROLL, + SM_CYHSCROLL, + SM_CXHTHUMB, + SM_CXICON, + SM_CYICON, + SM_CXICONSPACING, + SM_CYICONSPACING, + SM_CXMIN, + SM_CYMIN, + SM_CXSCREEN, + SM_CYSCREEN, #if defined(__WIN32__) && defined(SM_CXSIZEFRAME) - case wxSYS_FRAMESIZE_X: - return ::GetSystemMetrics(SM_CXSIZEFRAME); - case wxSYS_FRAMESIZE_Y: - return ::GetSystemMetrics(SM_CYSIZEFRAME); - case wxSYS_SMALLICON_X: - return ::GetSystemMetrics(SM_CXSMICON); - case wxSYS_SMALLICON_Y: - return ::GetSystemMetrics(SM_CYSMICON); + SM_CXSIZEFRAME, + SM_CYSIZEFRAME, + SM_CXSMICON, + SM_CYSMICON, +#else + -1, -1, -1, -1 #endif - case wxSYS_HSCROLL_Y: - return ::GetSystemMetrics(SM_CYHSCROLL); - case wxSYS_VSCROLL_X: - return ::GetSystemMetrics(SM_CXVSCROLL); - case wxSYS_VSCROLL_ARROW_X: - return ::GetSystemMetrics(SM_CXVSCROLL); - case wxSYS_VSCROLL_ARROW_Y: - return ::GetSystemMetrics(SM_CYVSCROLL); - case wxSYS_VTHUMB_Y: - return ::GetSystemMetrics(SM_CYVTHUMB); - case wxSYS_CAPTION_Y: - return ::GetSystemMetrics(SM_CYCAPTION); - case wxSYS_MENU_Y: - return ::GetSystemMetrics(SM_CYMENU); + SM_CYHSCROLL, + SM_CXVSCROLL, + SM_CXVSCROLL, + SM_CYVSCROLL, + SM_CYVTHUMB, + SM_CYCAPTION, + SM_CYMENU, #if defined(__WIN32__) && defined(SM_NETWORK) - case wxSYS_NETWORK_PRESENT: - return ::GetSystemMetrics(SM_NETWORK) & 0x0001; + SM_NETWORK, +#else + -1, #endif - case wxSYS_PENWINDOWS_PRESENT: - return ::GetSystemMetrics(SM_PENWINDOWS); + SM_PENWINDOWS, #if defined(__WIN32__) && defined(SM_SHOWSOUNDS) - case wxSYS_SHOW_SOUNDS: - return ::GetSystemMetrics(SM_SHOWSOUNDS); + SM_SHOWSOUNDS, +#else + -1, #endif - case wxSYS_SWAP_BUTTONS: - return ::GetSystemMetrics(SM_SWAPBUTTON); - default: - return 0; + SM_SWAPBUTTON, +}; + +// Get a system metric, e.g. scrollbar size +int wxSystemSettingsNative::GetMetric(wxSystemMetric index) +{ +#ifdef __WXMICROWIN__ + // TODO: probably use wxUniv themes functionality + return 0; +#else // !__WXMICROWIN__ + wxCHECK_MSG( index < WXSIZEOF(gs_metricsMap), 0, _T("invalid metric") ); + + int indexMSW = gs_metricsMap[index]; + if ( indexMSW == -1 ) + { + // not supported under current system + return 0; } -#endif - // __WXMICROWIN__ + + int rc = ::GetSystemMetrics(indexMSW); + if ( index == wxSYS_NETWORK_PRESENT ) + { + // only the last bit is significant according to the MSDN + rc &= 1; + } + + return rc; +#endif // __WXMICROWIN__/!__WXMICROWIN__ } -bool wxSystemSettings::GetCapability(int index) +bool wxSystemSettingsNative::HasFeature(wxSystemFeature index) { - switch (index) + switch ( index ) { - case wxSYS_CAN_ICONIZE_FRAME: + case wxSYS_CAN_ICONIZE_FRAME: case wxSYS_CAN_DRAW_FRAME_DECORATIONS: return TRUE; + default: + wxFAIL_MSG( _T("unknown system feature") ); + return FALSE; } } diff --git a/src/univ/colschem.cpp b/src/univ/colschem.cpp index a99b6bfe68..608fd3ea2d 100644 --- a/src/univ/colschem.cpp +++ b/src/univ/colschem.cpp @@ -31,12 +31,73 @@ #ifndef WX_PRECOMP #endif // WX_PRECOMP +#include "wx/settings.h" + #include "wx/univ/colschem.h" // ============================================================================ // implementation // ============================================================================ +// ---------------------------------------------------------------------------- +// wxColourScheme +// ---------------------------------------------------------------------------- + wxColourScheme::~wxColourScheme() { } + +#ifdef wxHAS_SS_NATIVE + +// ---------------------------------------------------------------------------- +// wxSystemSettings +// ---------------------------------------------------------------------------- + +wxColour wxSystemSettings::GetColour(wxSystemColour index) +{ + // the elements of this enum must be kept in sync with wxSystemColour + static const wxColourScheme::StdColour s_mapSysToThemeCol[] = + { + wxColourScheme::SCROLLBAR /* wxSYS_COLOUR_SCROLLBAR */, + wxColourScheme::WINDOW /* wxSYS_COLOUR_BACKGROUND */, + wxColourScheme::TITLEBAR_ACTIVE_TEXT /* wxSYS_COLOUR_ACTIVECAPTION */, + wxColourScheme::TITLEBAR_TEXT /* wxSYS_COLOUR_INACTIVECAPTION */, + wxColourScheme::MAX /* wxSYS_COLOUR_MENU */, + wxColourScheme::MAX /* wxSYS_COLOUR_WINDOW */, + wxColourScheme::MAX /* wxSYS_COLOUR_WINDOWFRAME */, + wxColourScheme::CONTROL_TEXT /* wxSYS_COLOUR_MENUTEXT */, + wxColourScheme::CONTROL_TEXT /* wxSYS_COLOUR_WINDOWTEXT */, + wxColourScheme::CONTROL_TEXT /* wxSYS_COLOUR_CAPTIONTEXT */, + wxColourScheme::MAX /* wxSYS_COLOUR_ACTIVEBORDER */, + wxColourScheme::MAX /* wxSYS_COLOUR_INACTIVEBORDER */, + wxColourScheme::MAX /* wxSYS_COLOUR_APPWORKSPACE */, + wxColourScheme::HIGHLIGHT /* wxSYS_COLOUR_HIGHLIGHT */, + wxColourScheme::HIGHLIGHT_TEXT /* wxSYS_COLOUR_HIGHLIGHTTEXT */, + wxColourScheme::SCROLLBAR /* wxSYS_COLOUR_BTNFACE */, + wxColourScheme::SHADOW_DARK /* wxSYS_COLOUR_BTNSHADOW */, + wxColourScheme::CONTROL_TEXT_DISABLED /* wxSYS_COLOUR_GRAYTEXT */, + wxColourScheme::CONTROL_TEXT /* wxSYS_COLOUR_BTNTEXT */, + wxColourScheme::MAX /* wxSYS_COLOUR_INACTIVECAPTIONTEXT */, + wxColourScheme::SHADOW_HIGHLIGHT /* wxSYS_COLOUR_BTNHIGHLIGHT */, + wxColourScheme::SHADOW_IN /* wxSYS_COLOUR_3DDKSHADOW */, + wxColourScheme::SHADOW_OUT /* wxSYS_COLOUR_3DLIGHT */, + wxColourScheme::MAX /* wxSYS_COLOUR_INFOTEXT */, + wxColourScheme::MAX /* wxSYS_COLOUR_INFOBK */, + wxColourScheme::CONTROL /* wxSYS_COLOUR_LISTBOX */, + }; + + wxCHECK_MSG( index < WXSIZEOF(s_mapSysToThemeCol), wxNullColour, + _T("invalid wxSystemColour") ); + + wxColourScheme::StdColour col = s_mapSysToThemeCol[index]; + if ( col == wxColourScheme::MAX ) + { + // we don't have theme-equivalent for this colour + return wxSystemSettingsNative::GetColour(index); + } + + return wxTheme::Get()->GetColourScheme()->Get(col); +} + +#endif // wxHAS_SS_NATIVE + diff --git a/src/univ/topluniv.cpp b/src/univ/topluniv.cpp index f9bfbeaa86..6dceed79d7 100644 --- a/src/univ/topluniv.cpp +++ b/src/univ/topluniv.cpp @@ -79,7 +79,7 @@ bool wxTopLevelWindow::Create(wxWindow *parent, if ( ms_drawDecorations == -1 ) { ms_drawDecorations = - !wxSystemSettings::GetCapability(wxSYS_CAN_DRAW_FRAME_DECORATIONS) + !wxSystemSettings::HasFeature(wxSYS_CAN_DRAW_FRAME_DECORATIONS) || wxGetEnv(wxT("WXDECOR"), NULL); // FIXME -- wxUniv should provide a way to force non-native decorations! // $WXDECOR is just a hack in absence of better wxUniv solution @@ -87,7 +87,7 @@ bool wxTopLevelWindow::Create(wxWindow *parent, if ( ms_canIconize == -1 ) { - ms_canIconize = wxSystemSettings::GetCapability(wxSYS_CAN_ICONIZE_FRAME); + ms_canIconize = wxSystemSettings::HasFeature(wxSYS_CAN_ICONIZE_FRAME); } if ( ms_drawDecorations )