Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CEGUIFalWidgetLookManager.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002     filename:   CEGUIFalWidgetLookManager.cpp
00003     created:    Mon Jun 13 2005
00004     author:     Paul D Turner <paul@cegui.org.uk>
00005 *************************************************************************/
00006 /*************************************************************************
00007     Crazy Eddie's GUI System (http://www.cegui.org.uk)
00008     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
00009  
00010     This library is free software; you can redistribute it and/or
00011     modify it under the terms of the GNU Lesser General Public
00012     License as published by the Free Software Foundation; either
00013     version 2.1 of the License, or (at your option) any later version.
00014  
00015     This library is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018     Lesser General Public License for more details.
00019  
00020     You should have received a copy of the GNU Lesser General Public
00021     License along with this library; if not, write to the Free Software
00022     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 *************************************************************************/
00024 #include "falagard/CEGUIFalWidgetLookManager.h"
00025 #include "falagard/CEGUIFalagard_xmlHandler.h"
00026 #include "CEGUIResourceProvider.h"
00027 #include "CEGUIXMLParser.h"
00028 #include "CEGUIExceptions.h"
00029 #include "CEGUILogger.h"
00030 
00031 // Start of CEGUI namespace section
00032 namespace CEGUI
00033 {
00035     // Static data definitions.
00036     template<> WidgetLookManager* Singleton<WidgetLookManager>::ms_Singleton = 0;
00037     const String WidgetLookManager::FalagardSchemaName("Falagard.xsd");
00039 
00040     WidgetLookManager::WidgetLookManager()
00041     {
00042         Logger::getSingleton().logEvent("CEGUI::WidgetLookManager singleton created.");
00043     }
00044 
00045     WidgetLookManager::~ WidgetLookManager()
00046     {
00047         Logger::getSingleton().logEvent("CEGUI::WidgetLookManager singleton destroyed.");
00048     }
00049 
00050     /*************************************************************************
00051                 Return singleton object
00052           *************************************************************************/
00053           WidgetLookManager&    WidgetLookManager::getSingleton(void)
00054           {
00055                   return Singleton<WidgetLookManager>::getSingleton();
00056           }
00057 
00058           /*************************************************************************
00059                   Return singleton pointer
00060           *************************************************************************/
00061           WidgetLookManager*    WidgetLookManager::getSingletonPtr(void)
00062           {
00063                   return Singleton<WidgetLookManager>::getSingletonPtr();
00064         }
00065 
00066     void WidgetLookManager::parseLookNFeelSpecification(const String& filename, const String& resourceGroup)
00067     {
00068         // valid filenames are required!
00069         if (filename.empty())
00070         {
00071             throw InvalidRequestException("WidgetLookManager::parseLookNFeelSpecification - Filename supplied for look & feel file must be valid");
00072         }
00073 
00074         // create handler object
00075         Falagard_xmlHandler handler(this);
00076 
00077         // perform parse of XML data
00078         try
00079         {
00080             System::getSingleton().getXMLParser()->parseXMLFile(handler, filename, FalagardSchemaName, resourceGroup);
00081         }
00082         catch(...)
00083         {
00084             Logger::getSingleton().logEvent("WidgetLookManager::parseLookNFeelSpecification - loading of look and feel data from file '" + filename +"' has failed.", Errors);
00085             throw;
00086         }
00087     }
00088 
00089     bool WidgetLookManager::isWidgetLookAvailable(const String& widget) const
00090     {
00091         return d_widgetLooks.find(widget) != d_widgetLooks.end();
00092     }
00093 
00094     const WidgetLookFeel& WidgetLookManager::getWidgetLook(const String& widget) const
00095     {
00096         WidgetLookList::const_iterator wlf = d_widgetLooks.find(widget);
00097 
00098         if (wlf != d_widgetLooks.end())
00099         {
00100             return (*wlf).second;
00101         }
00102 
00103         throw UnknownObjectException("WidgetLookManager::getWidgetLook - Widget look and feel '" + widget + "' does not exist.");
00104     }
00105 
00106     void WidgetLookManager::eraseWidgetLook(const String& widget)
00107     {
00108         WidgetLookList::iterator wlf = d_widgetLooks.find(widget);
00109         if (wlf != d_widgetLooks.end())
00110         {
00111             d_widgetLooks.erase(wlf);
00112         }
00113         else
00114         {
00115             Logger::getSingleton().logEvent(
00116                 "WidgetLookManager::eraseWidgetLook - Widget look and feel '" + widget + "' did not exist.");
00117         }
00118     }
00119 
00120     void WidgetLookManager::addWidgetLook(const WidgetLookFeel& look)
00121     {
00122         if (isWidgetLookAvailable(look.getName()))
00123         {
00124             Logger::getSingleton().logEvent(
00125                 "WidgetLookManager::addWidgetLook - Widget look and feel '" + look.getName() + "' already exists.  Replacing previous definition.");
00126         }
00127 
00128         d_widgetLooks[look.getName()] = look;
00129     }
00130 
00131     void WidgetLookManager::writeFalagardXMLHeadToStream(OutStream& out_stream) const
00132     {
00133         // output xml header
00134         out_stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
00135         // output root element
00136         out_stream << "<Falagard>" << std::endl;
00137     }
00138 
00139     void WidgetLookManager::writeFalagardXMLTailToStream(OutStream& out_stream) const
00140     {
00141         // close root element
00142         out_stream << "</Falagard>" << std::endl;
00143     }
00144 
00145     void WidgetLookManager::writeWidgetLookToStream(const String& name, OutStream& out_stream) const
00146     {
00147         // start of file
00148         writeFalagardXMLHeadToStream(out_stream);
00149 
00150         try
00151         {
00152             // output the desired widget look data
00153             getWidgetLook(name).writeXMLToStream(out_stream);
00154         }
00155         catch (UnknownObjectException)
00156         {
00157             Logger::getSingleton().logEvent("WidgetLookManager::writeWidgetLookToStream - Failed to write widget look XML data to stream.", Errors);
00158         }
00159 
00160         // close the root tags to terminate the file
00161         writeFalagardXMLTailToStream(out_stream);
00162     }
00163 
00164     void WidgetLookManager::writeWidgetLookSeriesToStream(const String& prefix, OutStream& out_stream) const
00165     {
00166         // start of file
00167         writeFalagardXMLHeadToStream(out_stream);
00168 
00169         for (WidgetLookList::const_iterator curr = d_widgetLooks.begin(); curr != d_widgetLooks.end(); ++curr)
00170         {
00171             if ((*curr).first.compare(0, prefix.length(), prefix) == 0)
00172                 (*curr).second.writeXMLToStream(out_stream);
00173         }
00174 
00175         // close the root tags to terminate the file
00176         writeFalagardXMLTailToStream(out_stream);
00177     }
00178 
00179 } // End of  CEGUI namespace section

Generated on Wed Sep 7 09:56:31 2005 for Crazy Eddies GUI System by  doxygen 1.4.3