00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00032 namespace CEGUI
00033 {
00035
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
00052
00053 WidgetLookManager& WidgetLookManager::getSingleton(void)
00054 {
00055 return Singleton<WidgetLookManager>::getSingleton();
00056 }
00057
00058
00059
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
00069 if (filename.empty())
00070 {
00071 throw InvalidRequestException("WidgetLookManager::parseLookNFeelSpecification - Filename supplied for look & feel file must be valid");
00072 }
00073
00074
00075 Falagard_xmlHandler handler(this);
00076
00077
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
00134 out_stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
00135
00136 out_stream << "<Falagard>" << std::endl;
00137 }
00138
00139 void WidgetLookManager::writeFalagardXMLTailToStream(OutStream& out_stream) const
00140 {
00141
00142 out_stream << "</Falagard>" << std::endl;
00143 }
00144
00145 void WidgetLookManager::writeWidgetLookToStream(const String& name, OutStream& out_stream) const
00146 {
00147
00148 writeFalagardXMLHeadToStream(out_stream);
00149
00150 try
00151 {
00152
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
00161 writeFalagardXMLTailToStream(out_stream);
00162 }
00163
00164 void WidgetLookManager::writeWidgetLookSeriesToStream(const String& prefix, OutStream& out_stream) const
00165 {
00166
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
00176 writeFalagardXMLTailToStream(out_stream);
00177 }
00178
00179 }