theme_set.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:7k
- /*
- * ===========================================================================
- * PRODUCTION $Log: theme_set.cpp,v $
- * PRODUCTION Revision 1000.1 2004/06/01 20:43:27 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: theme_set.cpp,v 1000.1 2004/06/01 20:43:27 gouriano Exp $
- * ===========================================================================
- *
- * PUBLIC DOMAIN NOTICE
- * National Center for Biotechnology Information
- *
- * This software/database is a "United States Government Work" under the
- * terms of the United States Copyright Act. It was written as part of
- * the author's official duties as a United States Government employee and
- * thus cannot be copyrighted. This software/database is freely available
- * to the public for use. The National Library of Medicine and the U.S.
- * Government have not placed any restriction on its use or reproduction.
- *
- * Although all reasonable efforts have been taken to ensure the accuracy
- * and reliability of the software and data, the NLM and the U.S.
- * Government do not and cannot warrant the performance or results that
- * may be obtained by using this software or data. The NLM and the U.S.
- * Government disclaim all warranties, express or implied, including
- * warranties of performance, merchantability or fitness for any particular
- * purpose.
- *
- * Please cite the author in any work or product based on this material.
- *
- * ===========================================================================
- *
- * Author: Robert G. Smith
- *
- * File Description:
- * CSettingsSet is an adapter of the PluginConfigCache. It is meant to be
- * used as a base class for individual plugins' configuration classes, and
- * provides an interface to the PluginConfigCache for plugins.
- * It constrains our access to the PluginConfigCache to a particular type.
- *
- */
- #include <ncbi_pch.hpp>
- #include <gui/config/theme_set.hpp>
- BEGIN_NCBI_SCOPE
- /// Dummy class, since CThemeSet doesn't need a Factory Default Settings.
- class NCBI_GUICONFIG_EXPORT CThemeDefaultSettings
- : public IFactoryDefaultSettings
- {
- public:
- CThemeDefaultSettings() {}
- virtual ~CThemeDefaultSettings() {}
- string Get(const string& key) const { return kEmptyStr; }
- };
- CThemeSet::CThemeSet(objects::CPluginConfigCache* config_cache,
- const string& type,
- const string& typedesc,
- const string& delim
- )
- : CSettingsSet( config_cache, type, new CThemeDefaultSettings, typedesc, delim)
- {
- }
- CThemeSet::~CThemeSet()
- {
- }
- /// convert between current settings and the PluginConfigCache.
- bool CThemeSet::LoadCurrentSettings(ELoadValueSource src)
- {
- NON_CONST_ITERATE(TSettingsReg, set_it, m_Settings) {
- CSettingsSet& thisSet = **set_it;
- string this_style;
- if (src == eLoad_Current) {
- string this_type = thisSet.GetType();
- try {
- this_style = SetCurrentSavedSet().GetStyleByType(this_type);
- }
- catch (const CSerialException&) {
- // either CInvalidChoiceSelection because my current PCV is not an Include PCV.
- // or CUnassignedMember because this_type doesn't exist in my current PCV.
- this_style = sm_StartupStyleName;
- }
- } else {
- // Factory default is the default style.
- this_style = sm_StartupStyleName;
- }
- thisSet.SetCurrentStyleName(this_style);
- thisSet.LoadCurrentSettings(src);
- }
- return true;
- }
- bool CThemeSet::SaveCurrentSettings(void)
- {
- NON_CONST_ITERATE(TSettingsReg, set_it, m_Settings) {
- CSettingsSet& thisSet = **set_it;
- thisSet.SaveCurrentSettings();
-
- string this_type = thisSet.GetType();
- string this_style = thisSet.GetCurrentStyleName();
- SetCurrentSavedSet().AddPCId(this_type, this_style);
- }
-
- return true;
- }
- void CThemeSet::AddSettingsSet(CSettingsSet& new_set)
- {
- m_Settings.push_back( CRef<CSettingsSet>(&new_set ));
- }
- vector<string> CThemeSet::GetTypes() const
- {
- vector<string> my_types;
- ITERATE(TSettingsReg, set_it, m_Settings) {
- const string& this_type = (*set_it)->GetType();
- my_types.push_back(this_type);
- }
- return my_types;
- }
- vector<string> CThemeSet::GetTypeDescriptions() const
- {
- vector<string> my_descs;
- ITERATE(TSettingsReg, set_it, m_Settings) {
- const string& this_desc = (*set_it)->GetTypeDescription();
- my_descs.push_back(this_desc);
- }
- return my_descs;
- }
- list<string> CThemeSet::GetSetsStyles(const string& type) const
- {
- return x_GetSettings(type).GetStyleNames();
- }
- const string& CThemeSet::GetSetsCurrentStyleName(const string& type) const
- {
- return x_GetSettings(type).GetCurrentStyleName();
- }
- void CThemeSet::SetSetsCurrentStyleName(const string& type, const string& new_style)
- {
- CSettingsSet& this_set = x_SetSettings(type);
- this_set.SetCurrentStyleName(new_style);
- this_set.LoadCurrentSettings(eLoad_Current);
- }
- const string& CThemeSet::GetSetsDescription(const string& type) const
- {
- return x_GetSettings(type).GetTypeDescription();
- }
- const CSettingsSet& CThemeSet::x_GetSettings(const string& type) const
- {
- ITERATE(TSettingsReg, set_it, m_Settings) {
- if ((*set_it)->GetType() == type) {
- return **set_it;
- }
- }
- NCBI_THROW(CConfigException, eThemeUnknownSet, type);
- }
- CSettingsSet& CThemeSet::x_SetSettings(const string& type)
- {
- NON_CONST_ITERATE(TSettingsReg, set_it, m_Settings) {
- if ((*set_it)->GetType() == type) {
- return **set_it;
- }
- }
- NCBI_THROW(CConfigException, eThemeUnknownSet, type);
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- *
- * $Log: theme_set.cpp,v $
- * Revision 1000.1 2004/06/01 20:43:27 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6
- *
- * Revision 1.6 2004/05/21 22:27:40 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.5 2004/02/04 16:20:49 rsmith
- * store managed settings in a vector, not a map so we have control over their order.
- *
- * Revision 1.4 2004/02/02 18:44:18 rsmith
- * add description to CSettingsSet, constructor and descendants.
- *
- * Revision 1.3 2004/01/20 13:55:43 rsmith
- * Load settings after changing the style name in a sub-set.
- *
- * Revision 1.2 2003/12/30 15:01:21 dicuccio
- * Fixed compiler warnings on MSVC
- *
- * Revision 1.1 2003/12/29 14:41:39 rsmith
- * initial checkin
- *
- *
- * ===========================================================================
- */