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

CEGUIScheme_xmlHandler.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002 filename:       CEGUIScheme_xmlHandler.cpp
00003 created:        21/2/2004
00004 author:         Paul D Turner
00005 
00006 purpose:        Implements GUI Scheme class
00007 *************************************************************************/
00008 /*************************************************************************
00009 Crazy Eddie's GUI System (http://www.cegui.org.uk)
00010 Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
00011 
00012 This library is free software; you can redistribute it and/or
00013 modify it under the terms of the GNU Lesser General Public
00014 License as published by the Free Software Foundation; either
00015 version 2.1 of the License, or (at your option) any later version.
00016 
00017 This library is distributed in the hope that it will be useful,
00018 but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020 Lesser General Public License for more details.
00021 
00022 You should have received a copy of the GNU Lesser General Public
00023 License along with this library; if not, write to the Free Software
00024 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 *************************************************************************/
00026 #include "CEGUIScheme_xmlHandler.h"
00027 
00028 #include "CEGUIExceptions.h"
00029 #include "CEGUIImageset.h"
00030 #include "CEGUILogger.h"
00031 #include "CEGUIXMLAttributes.h"
00032 #include "falagard/CEGUIFalWidgetLookManager.h"
00033 
00034 // Start of CEGUI namespace section
00035 namespace CEGUI
00036 {
00037 
00038 /*************************************************************************
00039 Static Data definitions
00040 *************************************************************************/
00041 
00042 // xml file elements and attributes
00043 const String Scheme_xmlHandler::GUISchemeElement( "GUIScheme" );
00044 const String Scheme_xmlHandler::ImagesetElement( "Imageset" );
00045 const String Scheme_xmlHandler::ImagesetFromImageElement( "ImagesetFromImage" );
00046 const String Scheme_xmlHandler::FontElement( "Font" );
00047 const String Scheme_xmlHandler::WindowSetElement( "WindowSet" );
00048 const String Scheme_xmlHandler::WindowFactoryElement( "WindowFactory" );
00049 const String Scheme_xmlHandler::WindowAliasElement( "WindowAlias" );
00050 const String Scheme_xmlHandler::FalagardMappingElement( "FalagardMapping" );
00051 const String Scheme_xmlHandler::LookNFeelElement( "LookNFeel" );
00052 const String Scheme_xmlHandler::NameAttribute( "Name" );
00053 const String Scheme_xmlHandler::FilenameAttribute( "Filename" );
00054 const String Scheme_xmlHandler::AliasAttribute( "Alias" );
00055 const String Scheme_xmlHandler::TargetAttribute( "Target" );
00056 const String Scheme_xmlHandler::ResourceGroupAttribute( "ResourceGroup" );
00057 const String Scheme_xmlHandler::WindowTypeAttribute( "WindowType" );
00058 const String Scheme_xmlHandler::TargetTypeAttribute( "TargetType" );
00059 const String Scheme_xmlHandler::LookNFeelAttribute( "LookNFeel" );
00060 
00061 /*************************************************************************
00062 Handler methods
00063 *************************************************************************/
00064 void Scheme_xmlHandler::elementStart(const String& element, const XMLAttributes& attributes)
00065 {
00066         // handle alias element
00067         if (element == WindowAliasElement)
00068         {
00069                 Scheme::AliasMapping    alias;
00070 
00071                 alias.aliasName  = attributes.getValueAsString(AliasAttribute);
00072         alias.targetName = attributes.getValueAsString(TargetAttribute);
00073                 d_scheme->d_aliasMappings.push_back(alias);
00074         }
00075         // handle an Imageset element
00076         else if (element == ImagesetElement)
00077         {
00078                 Scheme::LoadableUIElement       imageset;
00079 
00080         imageset.name = attributes.getValueAsString(NameAttribute);
00081         imageset.filename = attributes.getValueAsString(FilenameAttribute);
00082         imageset.resourceGroup = attributes.getValueAsString(ResourceGroupAttribute);
00083 
00084                 d_scheme->d_imagesets.push_back(imageset);
00085         }
00086     // handle an ImagesetFromImage element
00087     else if (element == ImagesetFromImageElement)
00088     {
00089         Scheme::LoadableUIElement       imageset;
00090 
00091         imageset.name = attributes.getValueAsString(NameAttribute);
00092         imageset.filename = attributes.getValueAsString(FilenameAttribute);
00093         imageset.resourceGroup = attributes.getValueAsString(ResourceGroupAttribute);
00094 
00095         d_scheme->d_imagesetsFromImages.push_back(imageset);
00096     }
00097         // handle a font element
00098         else if (element == FontElement)
00099         {
00100                 Scheme::LoadableUIElement       font;
00101 
00102         font.name = attributes.getValueAsString(NameAttribute);
00103         font.filename = attributes.getValueAsString(FilenameAttribute);
00104         font.resourceGroup = attributes.getValueAsString(ResourceGroupAttribute);
00105 
00106                 d_scheme->d_fonts.push_back(font);
00107         }
00108         // handle a WindowSet element
00109         else if (element == WindowSetElement)
00110         {
00111                 Scheme::UIModule        module;
00112         module.name             = attributes.getValueAsString(FilenameAttribute);
00113                 module.module   = NULL;
00114 
00115                 module.factories.clear();
00116                 d_scheme->d_widgetModules.push_back(module);
00117         }
00118         // handle a WindowFactory element
00119         else if (element == WindowFactoryElement)
00120         {
00121                 Scheme::UIElementFactory factory;
00122 
00123         factory.name = attributes.getValueAsString(NameAttribute);
00124 
00125                 d_scheme->d_widgetModules[d_scheme->d_widgetModules.size() - 1].factories.push_back(factory);
00126         }
00127         // handle root Scheme element
00128         else if (element == GUISchemeElement)
00129         {
00130                 // get name of scheme we are creating
00131         d_scheme->d_name = attributes.getValueAsString(NameAttribute);
00132 
00133                 Logger::getSingleton().logEvent("Started creation of Scheme '" + d_scheme->d_name + "' via XML file.", Informative);
00134 
00135                 if (SchemeManager::getSingleton().isSchemePresent(d_scheme->d_name))
00136                 {
00137                         throw   AlreadyExistsException((utf8*)"A GUI Scheme named '" + d_scheme->d_name + "' is already present in the system.");
00138                 }
00139 
00140         }
00141     else if (element == FalagardMappingElement)
00142     {
00143         Scheme::FalagardMapping fmap;
00144         fmap.windowName = attributes.getValueAsString(WindowTypeAttribute);
00145         fmap.targetName = attributes.getValueAsString(TargetTypeAttribute);
00146         fmap.lookName   = attributes.getValueAsString(LookNFeelAttribute);
00147 
00148         d_scheme->d_falagardMappings.push_back(fmap);
00149     }
00150     else if (element == LookNFeelElement)
00151     {
00152         Scheme::LoadableUIElement lnf;
00153         lnf.filename      = attributes.getValueAsString(FilenameAttribute);
00154         lnf.resourceGroup = attributes.getValueAsString(ResourceGroupAttribute);
00155 
00156         d_scheme->d_looknfeels.push_back(lnf);
00157     }
00158         // anything else is an error which *should* have already been caught by XML validation
00159         else
00160         {
00161                 throw FileIOException("Scheme::xmlHandler::startElement - Unexpected data was found while parsing the Scheme file: '" + element + "' is unknown.");
00162         }
00163 
00164 }
00165 
00166 void Scheme_xmlHandler::elementEnd(const String& element)
00167 {
00168         if (element == GUISchemeElement)
00169         {
00170                 Logger::getSingleton().logEvent("Finished creation of Scheme '" + d_scheme->d_name + "' via XML file.", Informative);
00171         }
00172 
00173 }
00174 
00175 } // End of  CEGUI namespace section

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