1 /***********************************************************************
2     created:    Mon Jun 13 2005
3     author:     Paul D Turner <paul@cegui.org.uk>
4 *************************************************************************/
5 /***************************************************************************
6  *   Copyright (C) 2004 - 2010 Paul D Turner & The CEGUI Development Team
7  *
8  *   Permission is hereby granted, free of charge, to any person obtaining
9  *   a copy of this software and associated documentation files (the
10  *   "Software"), to deal in the Software without restriction, including
11  *   without limitation the rights to use, copy, modify, merge, publish,
12  *   distribute, sublicense, and/or sell copies of the Software, and to
13  *   permit persons to whom the Software is furnished to do so, subject to
14  *   the following conditions:
15  *
16  *   The above copyright notice and this permission notice shall be
17  *   included in all copies or substantial portions of the Software.
18  *
19  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  *   OTHER DEALINGS IN THE SOFTWARE.
26  ***************************************************************************/
27 #include "CEGUI/falagard/WidgetLookFeel.h"
28 #include "CEGUI/falagard/WidgetLookManager.h"
29 #include "CEGUI/falagard/XMLHandler.h"
30 #include "CEGUI/Exceptions.h"
31 #include "CEGUI/Logger.h"
32 #include "CEGUI/WindowManager.h"
33 #include "CEGUI/AnimationManager.h"
34 #include "CEGUI/AnimationInstance.h"
35 #include <iostream>
36 #include <algorithm>
37 
38 // Start of CEGUI namespace section
39 namespace CEGUI
40 {
41 //---------------------------------------------------------------------------//
WidgetLookFeel(const String & name,const String & inherits)42 WidgetLookFeel::WidgetLookFeel(const String& name, const String& inherits) :
43     d_lookName(name),
44     d_inheritedLookName(inherits)
45 {
46 }
47 
48 //---------------------------------------------------------------------------//
WidgetLookFeel(const WidgetLookFeel & other)49 WidgetLookFeel::WidgetLookFeel(const WidgetLookFeel& other) :
50     d_lookName(other.d_lookName),
51     d_inheritedLookName(other.d_inheritedLookName),
52     d_imagerySections(other.d_imagerySections),
53     d_childWidgets(other.d_childWidgets),
54     d_stateImagery(other.d_stateImagery),
55     d_properties(other.d_properties),
56     d_namedAreas(other.d_namedAreas),
57     d_animations(other.d_animations),
58     d_animationInstances(other.d_animationInstances),
59     d_eventLinkDefinitions(other.d_eventLinkDefinitions)
60 {
61     for (PropertyDefinitionList::iterator i = other.d_propertyDefinitions.begin();
62         i < other.d_propertyDefinitions.end();
63         ++i)
64     {
65         d_propertyDefinitions.push_back(
66             dynamic_cast<PropertyDefinitionBase*>(
67                 dynamic_cast<Property*>(*i)->clone()));
68     }
69 
70     for (PropertyLinkDefinitionList::iterator i = other.d_propertyLinkDefinitions.begin();
71         i < other.d_propertyLinkDefinitions.end();
72         ++i)
73     {
74         d_propertyLinkDefinitions.push_back(
75             dynamic_cast<PropertyDefinitionBase*>(
76                 dynamic_cast<Property*>(*i)->clone()));
77     }
78 }
79 
80 //---------------------------------------------------------------------------//
operator =(const WidgetLookFeel & other)81 WidgetLookFeel& WidgetLookFeel::operator=(const WidgetLookFeel& other)
82 {
83     WidgetLookFeel tmp(other);
84     swap(tmp);
85     return *this;
86 }
87 
88 //---------------------------------------------------------------------------//
swap(WidgetLookFeel & other)89 void WidgetLookFeel::swap(WidgetLookFeel& other)
90 {
91     std::swap(d_lookName, other.d_lookName);
92     std::swap(d_inheritedLookName, other.d_inheritedLookName);
93     std::swap(d_imagerySections, other.d_imagerySections);
94     std::swap(d_childWidgets, other.d_childWidgets);
95     std::swap(d_stateImagery, other.d_stateImagery);
96     std::swap(d_properties, other.d_properties);
97     std::swap(d_namedAreas, other.d_namedAreas);
98     std::swap(d_propertyDefinitions, other.d_propertyDefinitions);
99     std::swap(d_propertyLinkDefinitions, other.d_propertyLinkDefinitions);
100     std::swap(d_animations, other.d_animations);
101     std::swap(d_animationInstances, other.d_animationInstances);
102     std::swap(d_eventLinkDefinitions, other.d_eventLinkDefinitions);
103 }
104 
105 //---------------------------------------------------------------------------//
~WidgetLookFeel()106 WidgetLookFeel::~WidgetLookFeel()
107 {
108     for (PropertyDefinitionList::reverse_iterator it = d_propertyDefinitions.rbegin();
109         it < d_propertyDefinitions.rend(); ++it)
110         CEGUI_DELETE_AO (*it);
111 
112     for (PropertyLinkDefinitionList::reverse_iterator it = d_propertyLinkDefinitions.rbegin();
113         it < d_propertyLinkDefinitions.rend(); ++it)
114         CEGUI_DELETE_AO (*it);
115 }
116 
117 //---------------------------------------------------------------------------//
getStateImagery(const CEGUI::String & state) const118 const StateImagery& WidgetLookFeel::getStateImagery(
119                                         const CEGUI::String& state) const
120 {
121     StateList::const_iterator imagery = d_stateImagery.find(state);
122 
123     if (imagery != d_stateImagery.end())
124         return (*imagery).second;
125 
126     if (d_inheritedLookName.empty())
127         CEGUI_THROW(UnknownObjectException("unknown state '" + state +
128             "' in look '" + d_lookName + "'."));
129 
130     return WidgetLookManager::getSingleton().
131         getWidgetLook(d_inheritedLookName).getStateImagery(state);
132 }
133 
134 //---------------------------------------------------------------------------//
getImagerySection(const CEGUI::String & section) const135 const ImagerySection& WidgetLookFeel::getImagerySection(
136                                         const CEGUI::String& section) const
137 {
138     ImageryList::const_iterator imgSect = d_imagerySections.find(section);
139 
140     if (imgSect != d_imagerySections.end())
141         return (*imgSect).second;
142 
143     if (d_inheritedLookName.empty())
144         CEGUI_THROW(UnknownObjectException("unknown imagery section '" +
145             section +  "' in look '" + d_lookName + "'."));
146 
147     return WidgetLookManager::getSingleton().
148         getWidgetLook(d_inheritedLookName).getImagerySection(section);
149 }
150 
151 //---------------------------------------------------------------------------//
getName() const152 const String& WidgetLookFeel::getName() const
153 {
154     return d_lookName;
155 }
156 
157 //---------------------------------------------------------------------------//
addImagerySection(const ImagerySection & section)158 void WidgetLookFeel::addImagerySection(const ImagerySection& section)
159 {
160     if (d_imagerySections.find(section.getName()) != d_imagerySections.end())
161         Logger::getSingleton().logEvent(
162             "WidgetLookFeel::addImagerySection - Defintion for imagery "
163             "section '" + section.getName() + "' already exists.  "
164             "Replacing previous definition.");
165 
166     d_imagerySections[section.getName()] = section;
167 }
168 //---------------------------------------------------------------------------//
renameImagerySection(const String & oldName,const String & newName)169 void WidgetLookFeel::renameImagerySection(const String& oldName, const String& newName)
170 {
171 	ImageryList::iterator oldsection = d_imagerySections.find(oldName);
172     if (oldsection == d_imagerySections.end())
173         CEGUI_THROW(UnknownObjectException("unknown imagery section: '" +
174             oldName + "' in look '" + d_lookName + "'."));
175 
176     if (d_imagerySections.find(newName) != d_imagerySections.end())
177         CEGUI_THROW(UnknownObjectException("imagery section: '" + newName +
178             "' already exists in look '" + d_lookName + "'."));
179 
180     oldsection->second.setName(newName);
181     d_imagerySections[newName] = d_imagerySections[oldName];
182     d_imagerySections.erase(oldsection);
183 }
184 
185 //---------------------------------------------------------------------------//
addWidgetComponent(const WidgetComponent & widget)186 void WidgetLookFeel::addWidgetComponent(const WidgetComponent& widget)
187 {
188     d_childWidgets.push_back(widget);
189 }
190 
191 //---------------------------------------------------------------------------//
addStateSpecification(const StateImagery & state)192 void WidgetLookFeel::addStateSpecification(const StateImagery& state)
193 {
194     if (d_stateImagery.find(state.getName()) != d_stateImagery.end())
195         Logger::getSingleton().logEvent(
196             "WidgetLookFeel::addStateSpecification - Defintion for state '" +
197             state.getName() + "' already exists.  Replacing previous "
198             "definition.");
199 
200     d_stateImagery[state.getName()] = state;
201 }
202 
203 //---------------------------------------------------------------------------//
addPropertyInitialiser(const PropertyInitialiser & initialiser)204 void WidgetLookFeel::addPropertyInitialiser(
205                         const PropertyInitialiser& initialiser)
206 {
207     d_properties.push_back(initialiser);
208 }
209 
210 //---------------------------------------------------------------------------//
clearImagerySections()211 void WidgetLookFeel::clearImagerySections()
212 {
213     d_imagerySections.clear();
214 }
215 
216 //---------------------------------------------------------------------------//
clearWidgetComponents()217 void WidgetLookFeel::clearWidgetComponents()
218 {
219     d_childWidgets.clear();
220 }
221 
222 //---------------------------------------------------------------------------//
clearStateSpecifications()223 void WidgetLookFeel::clearStateSpecifications()
224 {
225     d_stateImagery.clear();
226 }
227 
228 //---------------------------------------------------------------------------//
clearPropertyInitialisers()229 void WidgetLookFeel::clearPropertyInitialisers()
230 {
231     d_properties.clear();
232 }
233 
234 //---------------------------------------------------------------------------//
initialiseWidget(Window & widget) const235 void WidgetLookFeel::initialiseWidget(Window& widget) const
236 {
237     // add new property definitions
238     PropertyDefinitionCollator pdc;
239     appendPropertyDefinitions(pdc);
240     for (PropertyDefinitionCollator::const_iterator pdi = pdc.begin();
241          pdi != pdc.end();
242          ++pdi)
243     {
244         PropertyDefinitionBase* propDefBase = *pdi;
245         Property* curProperty = dynamic_cast<Property*>(propDefBase);
246         // add the property to the window
247         widget.addProperty(curProperty);
248     }
249 
250     // add required child widgets
251     WidgetComponentCollator wcc;
252     appendChildWidgetComponents(wcc);
253     for (WidgetComponentCollator::const_iterator wci = wcc.begin();
254          wci != wcc.end();
255          ++wci)
256     {
257         (*wci)->create(widget);
258     }
259 
260     // add new property link definitions
261     PropertyLinkDefinitionCollator pldc;
262     appendPropertyLinkDefinitions(pldc);
263     for (PropertyLinkDefinitionCollator::const_iterator pldi = pldc.begin();
264          pldi != pldc.end();
265          ++pldi)
266     {
267         // add the property to the window
268         widget.addProperty(dynamic_cast<Property*>(*pldi));
269     }
270     // apply properties to the parent window
271     PropertyInitialiserCollator pic;
272     appendPropertyInitialisers(pic);
273     for (PropertyInitialiserCollator::const_iterator pi = pic.begin();
274          pi != pic.end();
275          ++pi)
276     {
277         (*pi)->apply(widget);
278     }
279 
280     // setup linked events
281     EventLinkDefinitionCollator eldc;
282     appendEventLinkDefinitions(eldc);
283     for (EventLinkDefinitionCollator::const_iterator eldi = eldc.begin();
284          eldi != eldc.end();
285          ++eldi)
286     {
287         (*eldi)->initialiseWidget(widget);
288     }
289 
290     // create animation instances
291     AnimationNameSet ans;
292     appendAnimationNames(ans);
293     for (AnimationNameSet::const_iterator ani = ans.begin();
294          ani != ans.end();
295          ++ani)
296     {
297         AnimationInstance* instance =
298             AnimationManager::getSingleton().instantiateAnimation(*ani);
299 
300         d_animationInstances.insert(std::make_pair(&widget, instance));
301         instance->setTargetWindow(&widget);
302     }
303 }
304 
305 //---------------------------------------------------------------------------//
cleanUpWidget(Window & widget) const306 void WidgetLookFeel::cleanUpWidget(Window& widget) const
307 {
308     if (widget.getLookNFeel() != getName())
309     {
310         CEGUI_THROW(InvalidRequestException("The window '" +
311             widget.getNamePath() + "' does not have this WidgetLook assigned"));
312     }
313 
314     // remove added child widgets
315     WidgetComponentCollator wcc;
316     appendChildWidgetComponents(wcc);
317     for (WidgetComponentCollator::const_iterator wci = wcc.begin();
318          wci != wcc.end();
319          ++wci)
320     {
321         (*wci)->cleanup(widget);
322     }
323 
324     // delete added named Events
325     EventLinkDefinitionCollator eldc;
326     appendEventLinkDefinitions(eldc);
327     for (EventLinkDefinitionCollator::const_iterator eldi = eldc.begin();
328          eldi != eldc.end();
329          ++eldi)
330     {
331         (*eldi)->cleanUpWidget(widget);
332     }
333 
334     // remove added property definitions
335     PropertyDefinitionCollator pdc;
336     appendPropertyDefinitions(pdc);
337     for (PropertyDefinitionCollator::const_iterator pdi = pdc.begin();
338          pdi != pdc.end();
339          ++pdi)
340     {
341         // remove the property from the window
342         widget.removeProperty((*pdi)->getPropertyName());
343     }
344 
345     // remove added property link definitions
346     PropertyLinkDefinitionCollator pldc;
347     appendPropertyLinkDefinitions(pldc);
348     for (PropertyLinkDefinitionCollator::const_iterator pldi = pldc.begin();
349          pldi != pldc.end();
350          ++pldi)
351     {
352         // remove the property from the window
353         widget.removeProperty((*pldi)->getPropertyName());
354     }
355 
356     // clean up animation instances assoicated wit the window.
357     AnimationInstanceMap::iterator anim;
358     while ((anim = d_animationInstances.find(&widget)) != d_animationInstances.end())
359     {
360         AnimationManager::getSingleton().destroyAnimationInstance(anim->second);
361         d_animationInstances.erase(anim);
362     }
363 }
364 
365 //---------------------------------------------------------------------------//
isStateImageryPresent(const String & state) const366 bool WidgetLookFeel::isStateImageryPresent(const String& state) const
367 {
368     StateList::const_iterator i = d_stateImagery.find(state);
369 
370     if (i != d_stateImagery.end())
371         return true;
372 
373     if (d_inheritedLookName.empty())
374         return false;
375 
376     return WidgetLookManager::getSingleton().
377         getWidgetLook(d_inheritedLookName).isStateImageryPresent(state);
378 }
379 
380 //---------------------------------------------------------------------------//
addNamedArea(const NamedArea & area)381 void WidgetLookFeel::addNamedArea(const NamedArea& area)
382 {
383     if (d_namedAreas.find(area.getName()) != d_namedAreas.end())
384         Logger::getSingleton().logEvent(
385             "WidgetLookFeel::addNamedArea - Defintion for area '" +
386             area.getName() + "' already exists.  Replacing previous "
387             "definition.");
388 
389     d_namedAreas[area.getName()] = area;
390 }
391 
392 
393 //---------------------------------------------------------------------------//
renameNamedArea(const String & oldName,const String & newName)394 void WidgetLookFeel::renameNamedArea(const String& oldName, const String& newName)
395 {
396     NamedAreaList::iterator oldarea = d_namedAreas.find(oldName);
397     NamedAreaList::const_iterator newarea = d_namedAreas.find(newName);
398     if (oldarea == d_namedAreas.end())
399         CEGUI_THROW(UnknownObjectException("unknown named area: '" + oldName +
400             "' in look '" + d_lookName + "'."));
401 
402     if (newarea != d_namedAreas.end())
403         CEGUI_THROW(UnknownObjectException("named area: '" + newName +
404             "' already exists in look '" + d_lookName + "'."));
405 
406     oldarea->second.setName(newName);
407     d_namedAreas[newName] = d_namedAreas[oldName];
408     d_namedAreas.erase(oldarea);
409 }
410 //---------------------------------------------------------------------------//
clearNamedAreas()411 void WidgetLookFeel::clearNamedAreas()
412 {
413     d_namedAreas.clear();
414 }
415 
416 //---------------------------------------------------------------------------//
getNamedArea(const String & name) const417 const NamedArea& WidgetLookFeel::getNamedArea(const String& name) const
418 {
419     NamedAreaList::const_iterator area = d_namedAreas.find(name);
420 
421     if (area != d_namedAreas.end())
422         return (*area).second;
423 
424     if (d_inheritedLookName.empty())
425         CEGUI_THROW(UnknownObjectException("unknown named area: '" + name +
426             "' in look '" + d_lookName + "'."));
427 
428     return WidgetLookManager::getSingleton().
429         getWidgetLook(d_inheritedLookName).getNamedArea(name);
430 }
431 
432 //---------------------------------------------------------------------------//
isNamedAreaDefined(const String & name) const433 bool WidgetLookFeel::isNamedAreaDefined(const String& name) const
434 {
435     NamedAreaList::const_iterator area = d_namedAreas.find(name);
436 
437     if (area != d_namedAreas.end())
438         return true;
439 
440     if (d_inheritedLookName.empty())
441         return false;
442 
443     return WidgetLookManager::getSingleton().
444         getWidgetLook(d_inheritedLookName).isNamedAreaDefined(name);
445 }
446 
447 //---------------------------------------------------------------------------//
layoutChildWidgets(const Window & owner) const448 void WidgetLookFeel::layoutChildWidgets(const Window& owner) const
449 {
450     WidgetComponentCollator wcc;
451     appendChildWidgetComponents(wcc);
452 
453     for (WidgetComponentCollator::const_iterator wci = wcc.begin();
454          wci != wcc.end();
455          ++wci)
456     {
457         (*wci)->layout(owner);
458     }
459 }
460 
461 //---------------------------------------------------------------------------//
addPropertyDefinition(PropertyDefinitionBase * propdef)462 void WidgetLookFeel::addPropertyDefinition(PropertyDefinitionBase* propdef)
463 {
464     d_propertyDefinitions.push_back(propdef);
465 }
466 
467 //---------------------------------------------------------------------------//
clearPropertyDefinitions()468 void WidgetLookFeel::clearPropertyDefinitions()
469 {
470     d_propertyDefinitions.clear();
471 }
472 
473 //---------------------------------------------------------------------------//
addPropertyLinkDefinition(PropertyDefinitionBase * propdef)474 void WidgetLookFeel::addPropertyLinkDefinition(PropertyDefinitionBase* propdef)
475 {
476     d_propertyLinkDefinitions.push_back(propdef);
477 }
478 
479 //---------------------------------------------------------------------------//
clearPropertyLinkDefinitions()480 void WidgetLookFeel::clearPropertyLinkDefinitions()
481 {
482     d_propertyLinkDefinitions.clear();
483 }
484 
485 //---------------------------------------------------------------------------//
getStateNames(bool inherits) const486 WidgetLookFeel::StringSet WidgetLookFeel::getStateNames(bool inherits) const
487 {
488     return getStateImageryNames(inherits);
489 }
490 
491 //---------------------------------------------------------------------------//
getStateImageryNames(bool inherits) const492 WidgetLookFeel::StringSet WidgetLookFeel::getStateImageryNames(bool inherits) const
493 {
494     StringSet result;
495     for(StateList::const_iterator i = d_stateImagery.begin();
496         i != d_stateImagery.end();
497         ++i)
498     {
499         result.insert(i->first);
500     }
501     if (!d_inheritedLookName.empty() && inherits)
502     {
503         StringSet temp = WidgetLookManager::getSingleton().
504                 getWidgetLook(d_inheritedLookName).getStateNames(true);
505         result.insert(temp.begin(),temp.end());
506     }
507     return result;
508 }
509 
510 //---------------------------------------------------------------------------//
511 WidgetLookFeel::StateIterator
getStateIterator(bool inherits) const512 WidgetLookFeel::getStateIterator(bool inherits) const
513 {
514     if(inherits)
515     {
516         StringSet names = getStateNames(true);
517         StateList result;
518         for(StringSet::iterator i = names.begin();i != names.end();++i)
519         {
520             result.insert(std::make_pair(*i, getStateImagery(*i)));
521         }
522         return StateIterator(result.begin(),result.end());
523     }else{
524         return StateIterator(d_stateImagery.begin(),d_stateImagery.end());
525     }
526 }
527 
528 //---------------------------------------------------------------------------//
getImageryNames(bool inherits) const529 WidgetLookFeel::StringSet WidgetLookFeel::getImageryNames(bool inherits) const
530 {
531     return getImagerySectionNames(inherits);
532 }
533 
534 //---------------------------------------------------------------------------//
getImagerySectionNames(bool inherits) const535 WidgetLookFeel::StringSet WidgetLookFeel::getImagerySectionNames(bool inherits) const
536 {
537     StringSet result;
538 
539     for(ImageryList::const_iterator i = d_imagerySections.begin();
540         i != d_imagerySections.end();
541         ++i)
542     {
543         result.insert(i->first);
544     }
545     if (!d_inheritedLookName.empty() && inherits)
546     {
547         StringSet temp = WidgetLookManager::getSingleton().
548                 getWidgetLook(d_inheritedLookName).getImageryNames(true);
549         result.insert(temp.begin(),temp.end());
550     }
551     return result;
552 }
553 
554 //---------------------------------------------------------------------------//
555 WidgetLookFeel::ImageryIterator
getImageryIterator(bool inherits) const556 WidgetLookFeel::getImageryIterator(bool inherits) const
557 {
558     if(inherits)
559     {
560         StringSet names = getImageryNames(true);
561         ImageryList result;
562         for(StringSet::iterator i = names.begin();i != names.end();++i)
563         {
564             result.insert(std::make_pair(*i, getImagerySection(*i)));
565         }
566         return ImageryIterator(result.begin(),result.end());
567     }else{
568         return ImageryIterator(d_imagerySections.begin(),d_imagerySections.end());
569     }
570 }
571 
572 //---------------------------------------------------------------------------//
573 WidgetLookFeel::StringSet
getNamedAreaNames(bool inherits) const574 WidgetLookFeel::getNamedAreaNames(bool inherits) const
575 {
576     StringSet result;
577     for(NamedAreaList::const_iterator i = d_namedAreas.begin();
578         i != d_namedAreas.end();
579         ++i)
580     {
581         result.insert(i->first);
582     }
583     if (!d_inheritedLookName.empty() && inherits)
584     {
585         StringSet temp = WidgetLookManager::getSingleton().
586                 getWidgetLook(d_inheritedLookName).getNamedAreaNames(true);
587         result.insert(temp.begin(),temp.end());
588     }
589     return result;
590 }
591 
592 //---------------------------------------------------------------------------//
593 WidgetLookFeel::NamedAreaIterator
getNamedAreaIterator(bool inherits) const594 WidgetLookFeel::getNamedAreaIterator(bool inherits) const
595 {
596     if(inherits)
597     {
598         StringSet names = getNamedAreaNames(true);
599         NamedAreaList result;
600         for(StringSet::iterator i = names.begin();i != names.end();++i)
601         {
602             result.insert(std::make_pair(*i, getNamedArea(*i)));
603         }
604         return NamedAreaIterator(result.begin(),result.end());
605     }else{
606         return NamedAreaIterator(d_namedAreas.begin(),d_namedAreas.end());
607     }
608 }
609 
610 //---------------------------------------------------------------------------//
getWidgetNames(bool inherits) const611 WidgetLookFeel::StringSet WidgetLookFeel::getWidgetNames(bool inherits) const
612 {
613     return getWidgetComponentNames(inherits);
614 }
615 
616 //---------------------------------------------------------------------------//
getWidgetComponentNames(bool inherits) const617 WidgetLookFeel::StringSet WidgetLookFeel::getWidgetComponentNames(bool inherits) const
618 {
619     StringSet result;
620     for(WidgetList::const_iterator i = d_childWidgets.begin();
621         i != d_childWidgets.end();
622         ++i)
623     {
624         result.insert(i->getWidgetName());
625     }
626     if (!d_inheritedLookName.empty() && inherits)
627     {
628         StringSet temp = WidgetLookManager::getSingleton().
629                 getWidgetLook(d_inheritedLookName).getWidgetNames(true);
630         result.insert(temp.begin(),temp.end());
631     }
632     return result;
633 }
634 
635 //---------------------------------------------------------------------------//
636 WidgetLookFeel::WidgetComponentIterator
getWidgetComponentIterator(bool inherits) const637 WidgetLookFeel::getWidgetComponentIterator(bool inherits) const
638 {
639     WidgetComponentCollator wcc;
640     appendChildWidgetComponents(wcc, inherits);
641 
642     return WidgetComponentIterator(wcc.begin(), wcc.end());
643 }
644 
645 //---------------------------------------------------------------------------//
646 WidgetLookFeel::StringSet
getPropertyDefinitionNames(bool inherits) const647 WidgetLookFeel::getPropertyDefinitionNames(bool inherits) const
648 {
649     StringSet result;
650     for(PropertyDefinitionList::const_iterator i = d_propertyDefinitions.begin();
651         i != d_propertyDefinitions.end();
652         ++i)
653     {
654         result.insert((*i)->getPropertyName());
655     }
656     if (!d_inheritedLookName.empty() && inherits)
657     {
658         StringSet temp = WidgetLookManager::getSingleton().
659                 getWidgetLook(d_inheritedLookName).getPropertyDefinitionNames(true);
660         result.insert(temp.begin(),temp.end());
661     }
662     return result;
663 }
664 
665 //---------------------------------------------------------------------------//
666 WidgetLookFeel::PropertyDefinitionIterator
getPropertyDefinitionIterator(bool inherits) const667 WidgetLookFeel::getPropertyDefinitionIterator(bool inherits) const
668 {
669     PropertyDefinitionCollator pdc;
670     appendPropertyDefinitions(pdc, inherits);
671 
672     return PropertyDefinitionIterator(pdc.begin(), pdc.end());
673 }
674 
675 //---------------------------------------------------------------------------//
676 WidgetLookFeel::StringSet
getPropertyLinkDefinitionNames(bool inherits) const677 WidgetLookFeel::getPropertyLinkDefinitionNames(bool inherits) const
678 {
679     StringSet result;
680     for(PropertyLinkDefinitionList::const_iterator i = d_propertyLinkDefinitions.begin();
681         i != d_propertyLinkDefinitions.end();
682         ++i)
683     {
684         result.insert((*i)->getPropertyName());
685     }
686     if (!d_inheritedLookName.empty() && inherits)
687     {
688         StringSet temp = WidgetLookManager::getSingleton().
689                 getWidgetLook(d_inheritedLookName).getPropertyLinkDefinitionNames(true);
690         result.insert(temp.begin(),temp.end());
691     }
692     return result;
693 }
694 
695 //---------------------------------------------------------------------------//
696 WidgetLookFeel::PropertyLinkDefinitionIterator
getPropertyLinkDefinitionIterator(bool inherits) const697 WidgetLookFeel::getPropertyLinkDefinitionIterator(bool inherits) const
698 {
699     PropertyLinkDefinitionCollator pldc;
700     appendPropertyLinkDefinitions(pldc, inherits);
701 
702     return PropertyLinkDefinitionIterator(pldc.begin(), pldc.end());
703 }
704 
705 //---------------------------------------------------------------------------//
706 WidgetLookFeel::StringSet
getPropertyInitialiserNames(bool inherits) const707 WidgetLookFeel::getPropertyInitialiserNames(bool inherits) const
708 {
709     StringSet result;
710     for(PropertyList::const_iterator i = d_properties.begin();
711         i != d_properties.end();
712         ++i)
713     {
714         result.insert(i->getTargetPropertyName());
715     }
716     if (!d_inheritedLookName.empty() && inherits)
717     {
718         StringSet temp = WidgetLookManager::getSingleton().
719                 getWidgetLook(d_inheritedLookName).getPropertyInitialiserNames(true);
720         result.insert(temp.begin(),temp.end());
721     }
722     return result;
723 }
724 
725 //---------------------------------------------------------------------------//
726 WidgetLookFeel::PropertyInitialiserIterator
getPropertyInitialiserIterator(bool inherits) const727 WidgetLookFeel::getPropertyInitialiserIterator(bool inherits) const
728 {
729     PropertyInitialiserCollator pic;
730     appendPropertyInitialisers(pic, inherits);
731 
732     return PropertyInitialiserIterator(pic.begin(), pic.end());
733 }
734 
735 //---------------------------------------------------------------------------//
736 WidgetLookFeel::StringSet
getEventLinkDefinitionNames(bool inherits) const737 WidgetLookFeel::getEventLinkDefinitionNames(bool inherits) const
738 {
739     StringSet result;
740     for(EventLinkDefinitionList::const_iterator i = d_eventLinkDefinitions.begin();
741         i != d_eventLinkDefinitions.end();
742         ++i)
743     {
744         result.insert(i->getName());
745     }
746     if (!d_inheritedLookName.empty() && inherits)
747     {
748         StringSet temp = WidgetLookManager::getSingleton().
749                 getWidgetLook(d_inheritedLookName).getEventLinkDefinitionNames(true);
750         result.insert(temp.begin(),temp.end());
751     }
752     return result;
753 }
754 
755 //---------------------------------------------------------------------------//
756 WidgetLookFeel::EventLinkDefinitionIterator
getEventLinkDefinitionIterator(bool inherits) const757 WidgetLookFeel::getEventLinkDefinitionIterator(bool inherits) const
758 {
759     EventLinkDefinitionCollator eldc;
760     appendEventLinkDefinitions(eldc, inherits);
761 
762     return EventLinkDefinitionIterator(eldc.begin(), eldc.end());
763 }
764 
765 //---------------------------------------------------------------------------//
766 WidgetLookFeel::StringSet
getAnimationNames(bool inherits) const767 WidgetLookFeel::getAnimationNames(bool inherits) const
768 {
769     AnimationNameSet ans;
770     appendAnimationNames(ans,inherits);
771     return ans;
772 }
773 
774 //---------------------------------------------------------------------------//
775 WidgetLookFeel::AnimationNameIterator
getAnimationNameIterator(bool inherits) const776 WidgetLookFeel::getAnimationNameIterator(bool inherits) const
777 {
778     AnimationNameSet wcl;
779     appendAnimationNames(wcl,inherits);
780 
781     return AnimationNameIterator(wcl.begin(),wcl.end());
782 }
783 
784 //---------------------------------------------------------------------------//
writeXMLToStream(XMLSerializer & xml_stream) const785 void WidgetLookFeel::writeXMLToStream(XMLSerializer& xml_stream) const
786 {
787     xml_stream.openTag(Falagard_xmlHandler::WidgetLookElement);
788 
789     xml_stream.attribute(Falagard_xmlHandler::NameAttribute, d_lookName);
790 
791     if(!d_inheritedLookName.empty())
792         xml_stream.attribute(Falagard_xmlHandler::InheritsAttribute, d_inheritedLookName);
793 
794     // These sub-scopes of the loops avoid the "'curr'-already-initialized"
795     // compile error on VC6++
796     {
797         // output property definitions
798         for (PropertyDefinitionList::const_iterator curr = d_propertyDefinitions.begin();
799              curr != d_propertyDefinitions.end();
800              ++curr)
801         {
802             (*curr)->writeDefinitionXMLToStream(xml_stream);
803         }
804     }
805 
806     {
807         // output property link definitions
808         for (PropertyLinkDefinitionList::const_iterator curr = d_propertyLinkDefinitions.begin();
809              curr != d_propertyLinkDefinitions.end();
810              ++curr)
811         {
812             (*curr)->writeDefinitionXMLToStream(xml_stream);
813         }
814     }
815 
816     {
817         // output property initialisers.
818         for (PropertyList::const_iterator curr = d_properties.begin();
819              curr != d_properties.end();
820              ++curr)
821         {
822             (*curr).writeXMLToStream(xml_stream);
823         }
824     }
825 
826     {
827         // output named areas
828         for (NamedAreaList::const_iterator curr = d_namedAreas.begin();
829              curr != d_namedAreas.end();
830              ++curr)
831         {
832             (*curr).second.writeXMLToStream(xml_stream);
833         }
834     }
835 
836     {
837         // output child widgets
838         for (WidgetList::const_iterator curr = d_childWidgets.begin();
839              curr != d_childWidgets.end();
840              ++curr)
841         {
842             (*curr).writeXMLToStream(xml_stream);
843         }
844     }
845 
846     {
847         // output imagery sections
848         for (ImageryList::const_iterator curr = d_imagerySections.begin();
849              curr != d_imagerySections.end();
850              ++curr)
851         {
852             (*curr).second.writeXMLToStream(xml_stream);
853         }
854     }
855 
856     {
857         // output states
858         for (StateList::const_iterator curr = d_stateImagery.begin();
859              curr != d_stateImagery.end();
860              ++curr)
861         {
862             (*curr).second.writeXMLToStream(xml_stream);
863         }
864     }
865 
866     xml_stream.closeTag();
867 }
868 
869 //---------------------------------------------------------------------------//
findPropertyInitialiser(const String & propertyName) const870 const PropertyInitialiser* WidgetLookFeel::findPropertyInitialiser(const String& propertyName) const
871 {
872     PropertyInitialiserCollator pic;
873     appendPropertyInitialisers(pic);
874 
875     PropertyInitialiserCollator::const_iterator i = pic.find(propertyName);
876 
877     if (i == pic.end())
878         return 0;
879 
880     return *i;
881 }
882 
883 //---------------------------------------------------------------------------//
findWidgetComponent(const String & name) const884 const WidgetComponent* WidgetLookFeel::findWidgetComponent(const String& name) const
885 {
886     WidgetComponentCollator wcc;
887     appendChildWidgetComponents(wcc);
888 
889     WidgetComponentCollator::const_iterator wci = wcc.find(name);
890 
891     if (wci == wcc.end())
892         return 0;
893 
894     return *wci;
895 }
896 
897 //---------------------------------------------------------------------------//
retrieveWidgetComponentFromList(const String & name,bool includeInheritedElements)898 WidgetComponent* WidgetLookFeel::retrieveWidgetComponentFromList(const String& name, bool includeInheritedElements)
899 {
900     WidgetList::iterator iter = d_childWidgets.begin();
901     WidgetList::iterator iterEnd = d_childWidgets.end();
902 
903     while(iter != iterEnd)
904     {
905         if(iter->getWidgetName().compare(name) == 0)
906             return &(*iter);
907 
908         ++iter;
909     }
910 
911     if(includeInheritedElements)
912     {
913         WidgetLookFeel* inheritedWidgetLook = getInheritedWidgetLookFeel();
914         if(inheritedWidgetLook != 0)
915             return inheritedWidgetLook->retrieveWidgetComponentFromList(name, true);
916     }
917 
918     return 0;
919 }
920 
921 //---------------------------------------------------------------------------//
retrievePropertyInitialiserFromList(const String & name,bool includeInheritedElements)922 PropertyInitialiser* WidgetLookFeel::retrievePropertyInitialiserFromList(const String& name, bool includeInheritedElements)
923 {
924     PropertyList::iterator iter = d_properties.begin();
925     PropertyList::iterator iterEnd = d_properties.end();
926 
927     while(iter != iterEnd)
928     {
929         PropertyInitialiser& propInit = *iter;
930         if(propInit.getTargetPropertyName().compare(name) == 0)
931             return &propInit;
932 
933         ++iter;
934     }
935 
936     if(includeInheritedElements)
937     {
938         WidgetLookFeel* inheritedWidgetLook = getInheritedWidgetLookFeel();
939         if(inheritedWidgetLook != 0)
940             return inheritedWidgetLook->retrievePropertyInitialiserFromList(name, true);
941     }
942 
943     return 0;
944 }
945 
946 //---------------------------------------------------------------------------//
retrievePropertyDefinitionFromList(const String & name,bool includeInheritedElements)947 PropertyDefinitionBase* WidgetLookFeel::retrievePropertyDefinitionFromList(const String& name, bool includeInheritedElements)
948 {
949     PropertyDefinitionList::iterator iter = d_propertyDefinitions.begin();
950     PropertyDefinitionList::iterator iterEnd = d_propertyDefinitions.end();
951 
952     while(iter != iterEnd)
953     {
954         PropertyDefinitionBase* propDefBase = *iter;
955         if(propDefBase->getPropertyName().compare(name) == 0)
956             return propDefBase;
957 
958         ++iter;
959     }
960 
961 
962     if(includeInheritedElements)
963     {
964         WidgetLookFeel* inheritedWidgetLook = getInheritedWidgetLookFeel();
965         if(inheritedWidgetLook != 0)
966             return inheritedWidgetLook->retrievePropertyDefinitionFromList(name, true);
967     }
968 
969     return 0;
970 }
971 
972 
973 //---------------------------------------------------------------------------//
retrievePropertyLinkDefinitionFromList(const String & name,bool includeInheritedElements)974 PropertyDefinitionBase* WidgetLookFeel::retrievePropertyLinkDefinitionFromList(const String& name, bool includeInheritedElements)
975 {
976     PropertyLinkDefinitionList::iterator iter = d_propertyLinkDefinitions.begin();
977     PropertyLinkDefinitionList::iterator iterEnd = d_propertyLinkDefinitions.end();
978 
979     while(iter != iterEnd)
980     {
981         PropertyDefinitionBase* propDefBase = *iter;
982         if(propDefBase->getPropertyName().compare(name) == 0)
983             return propDefBase;
984 
985         ++iter;
986     }
987 
988     if(includeInheritedElements)
989     {
990         WidgetLookFeel* inheritedWidgetLook = getInheritedWidgetLookFeel();
991         if(inheritedWidgetLook != 0)
992             return inheritedWidgetLook->retrievePropertyLinkDefinitionFromList(name, true);
993     }
994 
995     return 0;
996 }
997 
998 //---------------------------------------------------------------------------//
retrieveEventLinkDefinitionFromList(const String & name,bool includeInheritedElements)999 EventLinkDefinition* WidgetLookFeel::retrieveEventLinkDefinitionFromList(const String& name, bool includeInheritedElements)
1000 {
1001     EventLinkDefinitionList::iterator iter = d_eventLinkDefinitions.begin();
1002     EventLinkDefinitionList::iterator iterEnd = d_eventLinkDefinitions.end();
1003 
1004     while(iter != iterEnd)
1005     {
1006         EventLinkDefinition& eventLinkDef = *iter;
1007         if(eventLinkDef.getName().compare(name) == 0)
1008             return &eventLinkDef;
1009 
1010         ++iter;
1011     }
1012 
1013     if(includeInheritedElements)
1014     {
1015         WidgetLookFeel* inheritedWidgetLook = getInheritedWidgetLookFeel();
1016         if(inheritedWidgetLook != 0)
1017             return inheritedWidgetLook->retrieveEventLinkDefinitionFromList(name, true);
1018     }
1019 
1020     return 0;
1021 }
1022 
1023 
1024 //---------------------------------------------------------------------------//
addAnimationName(const String & anim_name)1025 void WidgetLookFeel::addAnimationName(const String& anim_name)
1026 {
1027     AnimationList::iterator it = std::find(d_animations.begin(),
1028                                            d_animations.end(),
1029                                            anim_name);
1030 
1031     if (it == d_animations.end())
1032         d_animations.push_back(anim_name);
1033 }
1034 
1035 //---------------------------------------------------------------------------//
addEventLinkDefinition(const EventLinkDefinition & evtdef)1036 void WidgetLookFeel::addEventLinkDefinition(const EventLinkDefinition& evtdef)
1037 {
1038     d_eventLinkDefinitions.push_back(evtdef);
1039 }
1040 
1041 //---------------------------------------------------------------------------//
clearEventLinkDefinitions()1042 void WidgetLookFeel::clearEventLinkDefinitions()
1043 {
1044     d_eventLinkDefinitions.clear();
1045 }
1046 
1047 //---------------------------------------------------------------------------//
appendChildWidgetComponents(WidgetComponentCollator & col,bool inherits) const1048 void WidgetLookFeel::appendChildWidgetComponents(WidgetComponentCollator& col,
1049                                                  bool inherits) const
1050 {
1051     if (!d_inheritedLookName.empty() && inherits)
1052         WidgetLookManager::getSingleton().
1053             getWidgetLook(d_inheritedLookName).appendChildWidgetComponents(col);
1054 
1055     for (WidgetList::const_iterator i = d_childWidgets.begin();
1056          i != d_childWidgets.end();
1057          ++i)
1058     {
1059         col.set(i->getWidgetName(), &*i);
1060     }
1061 
1062 }
1063 
1064 //---------------------------------------------------------------------------//
appendPropertyDefinitions(PropertyDefinitionCollator & col,bool inherits) const1065 void WidgetLookFeel::appendPropertyDefinitions(PropertyDefinitionCollator& col,
1066                                                bool inherits) const
1067 {
1068     if (!d_inheritedLookName.empty() && inherits)
1069         WidgetLookManager::getSingleton().
1070             getWidgetLook(d_inheritedLookName).appendPropertyDefinitions(col);
1071 
1072     for (PropertyDefinitionList::iterator i = d_propertyDefinitions.begin();
1073          i != d_propertyDefinitions.end();
1074          ++i)
1075     {
1076         col.set((*i)->getPropertyName(), *i);
1077     }
1078 
1079 }
1080 
1081 //---------------------------------------------------------------------------//
appendPropertyLinkDefinitions(PropertyLinkDefinitionCollator & col,bool inherits) const1082 void WidgetLookFeel::appendPropertyLinkDefinitions(
1083         PropertyLinkDefinitionCollator& col, bool inherits) const
1084 {
1085     if (!d_inheritedLookName.empty() && inherits)
1086         WidgetLookManager::getSingleton().
1087             getWidgetLook(d_inheritedLookName).appendPropertyLinkDefinitions(col);
1088 
1089     for (PropertyLinkDefinitionList::iterator i = d_propertyLinkDefinitions.begin();
1090          i != d_propertyLinkDefinitions.end();
1091          ++i)
1092     {
1093         col.set((*i)->getPropertyName(), *i);
1094     }
1095 }
1096 
1097 //---------------------------------------------------------------------------//
appendPropertyInitialisers(PropertyInitialiserCollator & col,bool inherits) const1098 void WidgetLookFeel::appendPropertyInitialisers(
1099         PropertyInitialiserCollator& col, bool inherits) const
1100 {
1101     if (!d_inheritedLookName.empty() && inherits)
1102         WidgetLookManager::getSingleton().
1103             getWidgetLook(d_inheritedLookName).appendPropertyInitialisers(col);
1104 
1105     for (PropertyList::const_iterator i = d_properties.begin();
1106          i != d_properties.end();
1107          ++i)
1108     {
1109         col.set(i->getTargetPropertyName(), &*i);
1110     }
1111 }
1112 
1113 //---------------------------------------------------------------------------//
appendEventLinkDefinitions(EventLinkDefinitionCollator & col,bool inherits) const1114 void WidgetLookFeel::appendEventLinkDefinitions(
1115         EventLinkDefinitionCollator& col, bool inherits) const
1116 {
1117     if (!d_inheritedLookName.empty() && inherits)
1118         WidgetLookManager::getSingleton().
1119             getWidgetLook(d_inheritedLookName).appendEventLinkDefinitions(col);
1120 
1121     for (EventLinkDefinitionList::const_iterator i = d_eventLinkDefinitions.begin();
1122          i != d_eventLinkDefinitions.end();
1123          ++i)
1124     {
1125         col.set(i->getName(), &*i);
1126     }
1127 }
1128 
1129 //---------------------------------------------------------------------------//
appendAnimationNames(AnimationNameSet & set,bool inherits) const1130 void WidgetLookFeel::appendAnimationNames(AnimationNameSet& set,
1131                                           bool inherits) const
1132 {
1133     set.insert(d_animations.begin(),d_animations.end());
1134 
1135     if (!d_inheritedLookName.empty() && inherits)
1136         WidgetLookManager::getSingleton().
1137             getWidgetLook(d_inheritedLookName).appendAnimationNames(set);
1138 }
1139 
1140 //---------------------------------------------------------------------------//
handleFontRenderSizeChange(Window & window,const Font * font) const1141 bool WidgetLookFeel::handleFontRenderSizeChange(Window& window,
1142                                                 const Font* font) const
1143 {
1144     bool result = false;
1145 
1146     for(ImageryList::const_iterator i = d_imagerySections.begin();
1147         i != d_imagerySections.end();
1148         ++i)
1149     {
1150         result |= i->second.handleFontRenderSizeChange(window, font);
1151     }
1152 
1153     for(WidgetList::const_iterator i = d_childWidgets.begin();
1154         i != d_childWidgets.end();
1155         ++i)
1156     {
1157         result |= i->handleFontRenderSizeChange(window, font);
1158     }
1159 
1160     if (!d_inheritedLookName.empty())
1161         result |= WidgetLookManager::getSingleton().
1162             getWidgetLook(d_inheritedLookName).
1163                 handleFontRenderSizeChange(window, font);
1164 
1165     return result;
1166 }
1167 
1168 //---------------------------------------------------------------------------//
getStateImageryMap(bool includeInheritedElements)1169 WidgetLookFeel::StateImageryPointerMap WidgetLookFeel::getStateImageryMap(bool includeInheritedElements)
1170 {
1171     StateImageryPointerMap pointerMap;
1172     StringSet nameSet = getStateNames(includeInheritedElements);
1173 
1174     StringSet::iterator iter = nameSet.begin();
1175     StringSet::iterator iterEnd = nameSet.end();
1176     while(iter != iterEnd)
1177     {
1178         const CEGUI::String& currentElementName = *iter;
1179         StateList::iterator stateImageryIter = d_stateImagery.find(currentElementName);
1180 
1181         if(stateImageryIter == d_stateImagery.end())
1182         {
1183             CEGUI_THROW(UnknownObjectException("Error: StateImagery with name: \"" + currentElementName
1184                 + "\" exists in the list of names but a StateImagery with this name"
1185                 + "could not be found in the map"));
1186         }
1187         else
1188         {
1189             StateImagery* stateImagery = &stateImageryIter->second;
1190             pointerMap.insert(std::make_pair(currentElementName, stateImagery));
1191         }
1192 
1193         ++iter;
1194     }
1195 
1196     return pointerMap;
1197 }
1198 
1199 //---------------------------------------------------------------------------//
getImagerySectionMap(bool includeInheritedElements)1200 WidgetLookFeel::ImagerySectionPointerMap WidgetLookFeel::getImagerySectionMap(bool includeInheritedElements)
1201 {
1202     ImagerySectionPointerMap pointerMap;
1203     StringSet nameSet = getImageryNames(includeInheritedElements);
1204 
1205     StringSet::iterator iter = nameSet.begin();
1206     StringSet::iterator iterEnd = nameSet.end();
1207     while(iter != iterEnd)
1208     {
1209         const CEGUI::String& currentElementName = *iter;
1210         ImageryList::iterator imagerySectionIter = d_imagerySections.find(currentElementName);
1211 
1212         if(imagerySectionIter == d_imagerySections.end())
1213         {
1214             CEGUI_THROW(UnknownObjectException("Error: ImagerySection with name: \"" + currentElementName
1215                                                + "\" exists in the list of names but a ImagerySection with this name"
1216                                                + "could not be found in the map"));
1217         }
1218         else
1219         {
1220             ImagerySection* imagerySection = &imagerySectionIter->second;
1221             pointerMap.insert(std::make_pair(currentElementName, imagerySection));
1222         }
1223 
1224         ++iter;
1225     }
1226 
1227     return pointerMap;
1228 }
1229 
1230 //---------------------------------------------------------------------------//
getNamedAreaMap(bool includeInheritedElements)1231 WidgetLookFeel::NamedAreaPointerMap WidgetLookFeel::getNamedAreaMap(bool includeInheritedElements)
1232 {
1233     NamedAreaPointerMap pointerMap;
1234     StringSet nameSet = getNamedAreaNames(includeInheritedElements);
1235 
1236     StringSet::iterator iter = nameSet.begin();
1237     StringSet::iterator iterEnd = nameSet.end();
1238     while(iter != iterEnd)
1239     {
1240         const CEGUI::String& currentElementName = *iter;
1241         NamedAreaList::iterator namedAreaIter = d_namedAreas.find(currentElementName);
1242 
1243         if(namedAreaIter == d_namedAreas.end())
1244         {
1245             CEGUI_THROW(UnknownObjectException("Error: NamedArea with name: \"" + currentElementName
1246                 + "\" exists in the list of names but a NamedArea with this name"
1247                 + "could not be found in the map"));
1248         }
1249         else
1250         {
1251             NamedArea* namedArea = &namedAreaIter->second;
1252             pointerMap.insert(std::make_pair(currentElementName, namedArea));
1253         }
1254 
1255         ++iter;
1256     }
1257 
1258     return pointerMap;
1259 }
1260 
1261 //---------------------------------------------------------------------------//
getWidgetComponentMap(bool includeInheritedElements)1262 WidgetLookFeel::WidgetComponentPointerMap WidgetLookFeel::getWidgetComponentMap(bool includeInheritedElements)
1263 {
1264     WidgetComponentPointerMap pointerMap;
1265     StringSet nameSet = getWidgetNames(includeInheritedElements);
1266 
1267     StringSet::iterator iter = nameSet.begin();
1268     StringSet::iterator iterEnd = nameSet.end();
1269     while(iter != iterEnd)
1270     {
1271         const CEGUI::String& currentElementName = *iter;
1272         // This is deprecated in the next version, instead we will directly access the WidgetComponent map, which will be added.
1273         WidgetComponent* widgetComponent = retrieveWidgetComponentFromList(currentElementName, includeInheritedElements);
1274 
1275         if(widgetComponent == 0)
1276         {
1277             CEGUI_THROW(UnknownObjectException("Error: WidgetComponent with name: \"" + currentElementName
1278                 + "\" exists in the list of names but a WidgetComponent with this name"
1279                 + "could not be found in the map"));
1280         }
1281         else
1282         {
1283             pointerMap.insert(std::make_pair(currentElementName, widgetComponent));
1284         }
1285 
1286         ++iter;
1287     }
1288 
1289     return pointerMap;
1290 }
1291 
1292 //---------------------------------------------------------------------------//
getPropertyInitialiserMap(bool includeInheritedElements)1293 WidgetLookFeel::PropertyInitialiserPointerMap WidgetLookFeel::getPropertyInitialiserMap(bool includeInheritedElements)
1294 {
1295     PropertyInitialiserPointerMap pointerMap;
1296     StringSet nameSet = getPropertyInitialiserNames(includeInheritedElements);
1297 
1298     StringSet::iterator iter = nameSet.begin();
1299     StringSet::iterator iterEnd = nameSet.end();
1300     while(iter != iterEnd)
1301     {
1302         const CEGUI::String& currentElementName = *iter;
1303         // This is deprecated in the next version, instead we will directly access the PropertyInitialiser map, which will be added.
1304         PropertyInitialiser* propertyInitialiser = retrievePropertyInitialiserFromList(currentElementName, includeInheritedElements);
1305 
1306         if(propertyInitialiser == 0)
1307         {
1308             CEGUI_THROW(UnknownObjectException("Error: PropertyInitialiser with name: \"" + currentElementName
1309                 + "\" exists in the list of names but a PropertyInitialiser with this name"
1310                 + "could not be found in the map"));
1311         }
1312         else
1313         {
1314             pointerMap.insert(std::make_pair(currentElementName, propertyInitialiser));
1315         }
1316 
1317         ++iter;
1318     }
1319 
1320     return pointerMap;
1321 }
1322 
1323 
1324 //---------------------------------------------------------------------------//
getPropertyDefinitionMap(bool includeInheritedElements)1325 WidgetLookFeel::PropertyDefinitionBasePointerMap WidgetLookFeel::getPropertyDefinitionMap(bool includeInheritedElements)
1326 {
1327     PropertyDefinitionBasePointerMap pointerMap;
1328     StringSet nameSet = getPropertyDefinitionNames(includeInheritedElements);
1329 
1330     StringSet::iterator iter = nameSet.begin();
1331     StringSet::iterator iterEnd = nameSet.end();
1332     while(iter != iterEnd)
1333     {
1334         const CEGUI::String& currentElementName = *iter;
1335         // This is deprecated in the next version, instead we will directly access the PropertyDefinition map, which will be added.
1336         PropertyDefinitionBase* propertyDefinition = retrievePropertyDefinitionFromList(currentElementName, includeInheritedElements);
1337 
1338         if(propertyDefinition == 0)
1339         {
1340             CEGUI_THROW(UnknownObjectException("Error: PropertyDefinition with name: \"" + currentElementName
1341                 + "\" exists in the list of names but a PropertyDefinition with this name"
1342                 + "could not be found in the map"));
1343         }
1344         else
1345         {
1346             pointerMap.insert(std::make_pair(currentElementName, propertyDefinition));
1347         }
1348 
1349         ++iter;
1350     }
1351 
1352     return pointerMap;
1353 }
1354 
1355 //---------------------------------------------------------------------------//
getPropertyLinkDefinitionMap(bool includeInheritedElements)1356 WidgetLookFeel::PropertyDefinitionBasePointerMap WidgetLookFeel::getPropertyLinkDefinitionMap(bool includeInheritedElements)
1357 {
1358     PropertyDefinitionBasePointerMap pointerMap;
1359     StringSet nameSet = getPropertyLinkDefinitionNames(includeInheritedElements);
1360 
1361     StringSet::iterator iter = nameSet.begin();
1362     StringSet::iterator iterEnd = nameSet.end();
1363     while(iter != iterEnd)
1364     {
1365         const CEGUI::String& currentElementName = *iter;
1366         // This is deprecated in the next version, instead we will directly access the PropertyLinkDefinition map, which will be added.
1367         PropertyDefinitionBase* propertyLinkDefinition = retrievePropertyLinkDefinitionFromList(currentElementName, includeInheritedElements);
1368 
1369         if(propertyLinkDefinition == 0)
1370         {
1371             CEGUI_THROW(UnknownObjectException("Error: PropertyLinkDefinition with name: \"" + currentElementName
1372                 + "\" exists in the list of names but a PropertyLinkDefinition with this name"
1373                 + "could not be found in the map"));
1374         }
1375         else
1376         {
1377             pointerMap.insert(std::make_pair(currentElementName, propertyLinkDefinition));
1378         }
1379 
1380         ++iter;
1381     }
1382 
1383     return pointerMap;
1384 }
1385 
1386 
1387 //---------------------------------------------------------------------------//
getEventLinkDefinitionMap(bool includeInheritedElements)1388 WidgetLookFeel::EventLinkDefinitionPointerMap WidgetLookFeel::getEventLinkDefinitionMap(bool includeInheritedElements)
1389 {
1390     EventLinkDefinitionPointerMap pointerMap;
1391     StringSet nameSet = getEventLinkDefinitionNames(includeInheritedElements);
1392 
1393     StringSet::iterator iter = nameSet.begin();
1394     StringSet::iterator iterEnd = nameSet.end();
1395     while(iter != iterEnd)
1396     {
1397         const CEGUI::String& currentElementName = *iter;
1398         // This is deprecated in the next version, instead we will directly access the EventLinkDefinition map, which will be added.
1399         EventLinkDefinition* eventLinkDef = retrieveEventLinkDefinitionFromList(currentElementName, includeInheritedElements);
1400 
1401         if(eventLinkDef == 0)
1402         {
1403             CEGUI_THROW(UnknownObjectException("Error: EventLinkDefinition with name: \"" + currentElementName
1404                 + "\" exists in the list of names but a EventLinkDefinition with this name"
1405                 + "could not be found in the map"));
1406         }
1407         else
1408         {
1409             pointerMap.insert(std::make_pair(currentElementName, eventLinkDef));
1410         }
1411 
1412         ++iter;
1413     }
1414 
1415     return pointerMap;
1416 }
1417 
1418 
1419 //---------------------------------------------------------------------------//
getInheritedWidgetLookName() const1420 const CEGUI::String& WidgetLookFeel::getInheritedWidgetLookName() const
1421 {
1422     return d_inheritedLookName;
1423 }
1424 
1425 //---------------------------------------------------------------------------//
getInheritedWidgetLookFeel()1426 WidgetLookFeel* WidgetLookFeel::getInheritedWidgetLookFeel()
1427 {
1428     if(d_inheritedLookName.empty())
1429         return 0;
1430 
1431     WidgetLookManager::WidgetLookPointerMap pointerMap = WidgetLookManager::getSingleton().getWidgetLookPointerMap();
1432     WidgetLookManager::WidgetLookPointerMap::iterator foundIter = pointerMap.find(d_inheritedLookName);
1433 
1434     if(foundIter == pointerMap.end())
1435         CEGUI_THROW(UnknownObjectException("Error: Inherited WidgetLook with name: \"" + d_inheritedLookName
1436                                            + "\" cannot be found in the WidgetLookManager's map"));
1437 
1438     return foundIter->second;
1439 }
1440 
1441 //---------------------------------------------------------------------------//
1442 
1443 } // End of  CEGUI namespace section
1444 
1445