00001 /************************************************************************ 00002 filename: CEGUIFalWidgetLookFeel.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/CEGUIFalWidgetLookFeel.h" 00025 #include "CEGUIExceptions.h" 00026 #include "CEGUILogger.h" 00027 #include <iostream> 00028 00029 // Start of CEGUI namespace section 00030 namespace CEGUI 00031 { 00032 WidgetLookFeel::WidgetLookFeel(const String& name) : 00033 d_lookName(name) 00034 {} 00035 00036 const StateImagery& WidgetLookFeel::getStateImagery(const CEGUI::String& state) const 00037 { 00038 StateList::const_iterator imagery = d_stateImagery.find(state); 00039 00040 if (imagery == d_stateImagery.end()) 00041 { 00042 throw UnknownObjectException("WidgetLookFeel::getStateImagery - unknown state '" + state + "' in look '" + d_lookName + "'."); 00043 } 00044 00045 return (*imagery).second; 00046 } 00047 00048 00049 const ImagerySection& WidgetLookFeel::getImagerySection(const CEGUI::String& section) const 00050 { 00051 ImageryList::const_iterator imgSect = d_imagerySections.find(section); 00052 00053 if (imgSect == d_imagerySections.end()) 00054 { 00055 throw UnknownObjectException("WidgetLookFeel::getImagerySection - unknown imagery section '" + section + "' in look '" + d_lookName + "'."); 00056 } 00057 00058 return (*imgSect).second; 00059 } 00060 00061 00062 const String& WidgetLookFeel::getName() const 00063 { 00064 return d_lookName; 00065 } 00066 00067 void WidgetLookFeel::addImagerySection(const ImagerySection& section) 00068 { 00069 if (d_imagerySections.find(section.getName()) != d_imagerySections.end()) 00070 { 00071 Logger::getSingleton().logEvent( 00072 "WidgetLookFeel::addImagerySection - Defintion for imagery section '" + section.getName() + "' already exists. Replacing previous definition."); 00073 } 00074 00075 d_imagerySections[section.getName()] = section; 00076 } 00077 00078 void WidgetLookFeel::addWidgetComponent(const WidgetComponent& widget) 00079 { 00080 d_childWidgets.push_back(widget); 00081 } 00082 00083 void WidgetLookFeel::addStateSpecification(const StateImagery& state) 00084 { 00085 if (d_stateImagery.find(state.getName()) != d_stateImagery.end()) 00086 { 00087 Logger::getSingleton().logEvent( 00088 "WidgetLookFeel::addStateSpecification - Defintion for state '" + state.getName() + "' already exists. Replacing previous definition."); 00089 } 00090 00091 d_stateImagery[state.getName()] = state; 00092 } 00093 00094 void WidgetLookFeel::addPropertyInitialiser(const PropertyInitialiser& initialiser) 00095 { 00096 d_properties.push_back(initialiser); 00097 } 00098 00099 void WidgetLookFeel::clearImagerySections() 00100 { 00101 d_imagerySections.clear(); 00102 } 00103 00104 void WidgetLookFeel::clearWidgetComponents() 00105 { 00106 d_childWidgets.clear(); 00107 } 00108 00109 void WidgetLookFeel::clearStateSpecifications() 00110 { 00111 d_stateImagery.clear(); 00112 } 00113 00114 void WidgetLookFeel::clearPropertyInitialisers() 00115 { 00116 d_properties.clear(); 00117 } 00118 00119 void WidgetLookFeel::initialiseWidget(Window& widget) const 00120 { 00121 // add new property definitions first 00122 for(PropertyDefinitionList::iterator propdef = d_propertyDefinitions.begin(); propdef != d_propertyDefinitions.end(); ++propdef) 00123 { 00124 // add the property to the window 00125 widget.addProperty(&(*propdef)); 00126 // write default value to get things set up properly 00127 widget.setProperty((*propdef).getName(), (*propdef).getDefault(&widget)); 00128 } 00129 00130 // apply properties to the parent window 00131 for(PropertyList::const_iterator prop = d_properties.begin(); prop != d_properties.end(); ++prop) 00132 { 00133 (*prop).apply(widget); 00134 } 00135 00136 // add required child widgets 00137 for(WidgetList::const_iterator curr = d_childWidgets.begin(); curr != d_childWidgets.end(); ++curr) 00138 { 00139 (*curr).create(widget); 00140 } 00141 } 00142 00143 bool WidgetLookFeel::isStateImageryPresent(const String& state) const 00144 { 00145 return d_stateImagery.find(state) != d_stateImagery.end(); 00146 } 00147 00148 void WidgetLookFeel::addNamedArea(const NamedArea& area) 00149 { 00150 if (d_namedAreas.find(area.getName()) != d_namedAreas.end()) 00151 { 00152 Logger::getSingleton().logEvent( 00153 "WidgetLookFeel::addNamedArea - Defintion for area '" + area.getName() + "' already exists. Replacing previous definition."); 00154 } 00155 00156 d_namedAreas[area.getName()] = area; 00157 } 00158 00159 void WidgetLookFeel::clearNamedAreas() 00160 { 00161 d_namedAreas.clear(); 00162 } 00163 00164 const NamedArea& WidgetLookFeel::getNamedArea(const String& name) const 00165 { 00166 NamedAreaList::const_iterator area = d_namedAreas.find(name); 00167 00168 if (area == d_namedAreas.end()) 00169 { 00170 throw UnknownObjectException("WidgetLookFeel::getNamedArea - unknown named area: '" + name + "' in look '" + d_lookName + "'."); 00171 } 00172 00173 return (*area).second; 00174 } 00175 00176 bool WidgetLookFeel::isNamedAreaDefined(const String& name) const 00177 { 00178 return d_namedAreas.find(name) != d_namedAreas.end(); 00179 } 00180 00181 void WidgetLookFeel::layoutChildWidgets(const Window& owner) const 00182 { 00183 // apply properties to the parent window 00184 for(WidgetList::const_iterator wdgt = d_childWidgets.begin(); wdgt != d_childWidgets.end(); ++wdgt) 00185 { 00186 (*wdgt).layout(owner); 00187 } 00188 } 00189 00190 void WidgetLookFeel::addPropertyDefinition(const PropertyDefinition& propdef) 00191 { 00192 d_propertyDefinitions.push_back(propdef); 00193 } 00194 00195 void WidgetLookFeel::clearPropertyDefinitions() 00196 { 00197 d_propertyDefinitions.clear(); 00198 } 00199 00200 void WidgetLookFeel::writeXMLToStream(OutStream& out_stream) const 00201 { 00202 out_stream << "<WidgetLook name=\"" << d_lookName << "\">" << std::endl; 00203 00204 // These sub-scobes of the loops avoid the "'curr'-already-initialized" compile error on VC6++ 00205 { 00206 // output property definitions 00207 for (PropertyDefinitionList::const_iterator curr = d_propertyDefinitions.begin(); curr != d_propertyDefinitions.end(); ++curr) 00208 (*curr).writeXMLToStream(out_stream); 00209 } 00210 00211 { 00212 // output property initialisers. 00213 for (PropertyList::const_iterator curr = d_properties.begin(); curr != d_properties.end(); ++curr) 00214 (*curr).writeXMLToStream(out_stream); 00215 } 00216 00217 { 00218 // output named areas 00219 for (NamedAreaList::const_iterator curr = d_namedAreas.begin(); curr != d_namedAreas.end(); ++curr) 00220 (*curr).second.writeXMLToStream(out_stream); 00221 } 00222 00223 { 00224 // output child widgets 00225 for (WidgetList::const_iterator curr = d_childWidgets.begin(); curr != d_childWidgets.end(); ++curr) 00226 (*curr).writeXMLToStream(out_stream); 00227 } 00228 00229 { 00230 // output imagery sections 00231 for (ImageryList::const_iterator curr = d_imagerySections.begin(); curr != d_imagerySections.end(); ++curr) 00232 (*curr).second.writeXMLToStream(out_stream); 00233 } 00234 00235 { 00236 // output states 00237 for (StateList::const_iterator curr = d_stateImagery.begin(); curr != d_stateImagery.end(); ++curr) 00238 (*curr).second.writeXMLToStream(out_stream); 00239 } 00240 00241 out_stream << "</WidgetLook>" << std::endl; 00242 } 00243 00244 } // End of CEGUI namespace section