X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ed88f3ab346b6df9525bb9d7cbde34eba6223e63..64ea838d8f4d1853b7d850db93ee565e901d099a:/src/univ/theme.cpp?ds=inline diff --git a/src/univ/theme.cpp b/src/univ/theme.cpp index f9e384c683..9aef4355b9 100644 --- a/src/univ/theme.cpp +++ b/src/univ/theme.cpp @@ -1,12 +1,12 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: univ/theme.cpp +// Name: src/univ/theme.cpp // Purpose: implementation of wxTheme // Author: Vadim Zeitlin // Modified by: // Created: 06.08.00 // RCS-ID: $Id$ // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com) -// Licence: wxWindows license +// Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// // =========================================================================== @@ -17,10 +17,6 @@ // headers // --------------------------------------------------------------------------- -#ifdef __GNUG__ - #pragma implementation "theme.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -33,6 +29,8 @@ #include "wx/log.h" #endif // WX_PRECOMP +#include "wx/artprov.h" + #include "wx/univ/renderer.h" #include "wx/univ/inphand.h" #include "wx/univ/theme.h" @@ -41,16 +39,16 @@ // implementation // ============================================================================ -wxThemeInfo *wxTheme::ms_allThemes = (wxThemeInfo *)NULL; -wxTheme *wxTheme::ms_theme = (wxTheme *)NULL; +wxThemeInfo *wxTheme::ms_allThemes = NULL; +wxTheme *wxTheme::ms_theme = NULL; // ---------------------------------------------------------------------------- // "dynamic" theme creation // ---------------------------------------------------------------------------- wxThemeInfo::wxThemeInfo(Constructor c, - const wxChar *n, - const wxChar *d) + const wxString& n, + const wxString& d) : name(n), desc(d), ctor(c) { // insert us (in the head of) the linked list @@ -64,7 +62,7 @@ wxThemeInfo::wxThemeInfo(Constructor c, wxThemeInfo *info = ms_allThemes; while ( info ) { - if ( name == info->name ) + if ( name.CmpNoCase(info->name) == 0 ) { return info->ctor(); } @@ -72,7 +70,7 @@ wxThemeInfo::wxThemeInfo(Constructor c, info = info->next; } - return (wxTheme *)NULL; + return NULL; } // ---------------------------------------------------------------------------- @@ -84,51 +82,60 @@ wxThemeInfo::wxThemeInfo(Constructor c, if ( ms_theme ) { // we already have a theme - return TRUE; + return true; } wxString nameDefTheme; // use the environment variable first - const wxChar *p = wxGetenv(_T("WXTHEME")); + const wxChar *p = wxGetenv(wxT("WXTHEME")); if ( p ) { nameDefTheme = p; } +#ifdef wxUNIV_DEFAULT_THEME else // use native theme by default { - #if defined(__WXMSW__) - nameDefTheme = _T("win32"); - #elif defined(__WXGTK__) - nameDefTheme = _T("gtk"); - #elif defined(__WXMGL__) - nameDefTheme = _T("win32"); - #endif + nameDefTheme = wxSTRINGIZE_T(wxUNIV_DEFAULT_THEME); } +#endif // wxUNIV_DEFAULT_THEME - ms_theme = Create(nameDefTheme); + wxTheme *theme = Create(nameDefTheme); // fallback to the first one in the list - if ( !ms_theme && ms_allThemes ) + if ( !theme && ms_allThemes ) { - ms_theme = ms_allThemes->ctor(); + theme = ms_allThemes->ctor(); } // abort if still nothing - if ( !ms_theme ) + if ( !theme ) { wxLogError(_("Failed to initialize GUI: no built-in themes found.")); - return FALSE; + return false; } - return TRUE; + // Set the theme as current. + wxTheme::Set(theme); + + return true; } /* static */ wxTheme *wxTheme::Set(wxTheme *theme) { wxTheme *themeOld = ms_theme; ms_theme = theme; + + if ( ms_theme ) + { + // automatically start using the art provider of the new theme if it + // has one + wxArtProvider *art = ms_theme->GetArtProvider(); + if ( art ) + wxArtProvider::Push(art); + } + return themeOld; } @@ -140,3 +147,58 @@ wxTheme::~wxTheme() { } + +// ---------------------------------------------------------------------------- +// wxDelegateTheme +// ---------------------------------------------------------------------------- + +wxDelegateTheme::wxDelegateTheme(const wxString& theme) +{ + m_themeName = theme; + m_theme = NULL; +} + +wxDelegateTheme::~wxDelegateTheme() +{ + delete m_theme; +} + +bool wxDelegateTheme::GetOrCreateTheme() +{ + if ( !m_theme ) + m_theme = wxTheme::Create(m_themeName); + return m_theme != NULL; +} + +wxRenderer *wxDelegateTheme::GetRenderer() +{ + if ( !GetOrCreateTheme() ) + return NULL; + + return m_theme->GetRenderer(); +} + +wxArtProvider *wxDelegateTheme::GetArtProvider() +{ + if ( !GetOrCreateTheme() ) + return NULL; + + return m_theme->GetArtProvider(); +} + +wxInputHandler *wxDelegateTheme::GetInputHandler(const wxString& control, + wxInputConsumer *consumer) +{ + if ( !GetOrCreateTheme() ) + return NULL; + + return m_theme->GetInputHandler(control, consumer); +} + +wxColourScheme *wxDelegateTheme::GetColourScheme() +{ + if ( !GetOrCreateTheme() ) + return NULL; + + return m_theme->GetColourScheme(); +}