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 #ifndef _CEGUIFalWidgetLookManager_h_
28 #define _CEGUIFalWidgetLookManager_h_
29 
30 #include "../Singleton.h"
31 #include "../String.h"
32 #include "../Exceptions.h"
33 #include "./WidgetLookFeel.h"
34 #include <map>
35 
36 #if defined(_MSC_VER)
37 #	pragma warning(push)
38 #	pragma warning(disable : 4251)
39 #	pragma warning(disable : 4275)
40 #endif
41 
42 // Start of CEGUI namespace section
43 namespace CEGUI
44 {
45     /*!
46     \brief
47         Manager class that gives top-level access to widget data based "look and feel" specifications loaded into the system.
48     */
49     class CEGUIEXPORT WidgetLookManager :
50         public Singleton<WidgetLookManager>,
51         public AllocatedObject<WidgetLookManager>
52     {
53     public:
54         /*!
55         \brief
56             Constructor.
57         */
58         WidgetLookManager();
59 
60         /*!
61         \brief
62             Destructor
63         */
64         ~WidgetLookManager();
65 
66        	/*!
67 	      \brief
68 		        Return singleton WidgetLookManager object
69 
70 	      \return
71 		        Singleton WidgetLookManager object
72 	      */
73 	      static	WidgetLookManager&	getSingleton(void);
74 
75 
76 	      /*!
77 	      \brief
78 		        Return pointer to singleton WidgetLookManager object
79 
80 	      \return
81 		        Pointer to singleton WidgetLookManager object
82 	      */
83 	      static	WidgetLookManager*	getSingletonPtr(void);
84 
85 
86         /** Typedef for a set of WidgetLookFeel names. */
87         typedef std::set<String, StringFastLessCompare CEGUI_SET_ALLOC(String)> WidgetLookNameSet;
88 
89         //! Typedef for a map of Strings to WidgetLookFeel objects
90         typedef std::map<String, WidgetLookFeel*, StringFastLessCompare CEGUI_MAP_ALLOC(String, WidgetLookFeel*)> WidgetLookPointerMap;
91 
92         /*!
93         \brief
94             Parses a file containing window look & feel specifications (in the form of XML).
95 
96         \note
97             If the new file contains specifications for widget types that are already specified, it is not an error;
98             the previous definitions are overwritten by the new data.  An entry will appear in the log each time any
99             look & feel component is overwritten.
100 
101         \param source
102             RawDataContainer containing the source code that will be parsed
103 
104         \param resourceGroup
105             Resource group identifier to pass to the resource provider when loading the file.
106 
107         \return
108             Nothing.
109 
110         \exception FileIOException             thrown if there was some problem accessing or parsing the file \a filename
111         \exception InvalidRequestException     thrown if an invalid filename was provided.
112         */
113         void parseLookNFeelSpecificationFromContainer(const RawDataContainer& source);
114 
115         /*!
116         \see WidgetLookManager::parseLookNFeelSpecificationFromContainer
117         */
118         void parseLookNFeelSpecificationFromFile(const String& filename, const String& resourceGroup = "");
119 
120         /*!
121         \see WidgetLookManager::parseLookNFeelSpecificationFromContainer
122         */
123         void parseLookNFeelSpecificationFromString(const String& source);
124 
125         /*!
126         \brief
127             Return whether a WidgetLookFeel has been created with the specified name.
128 
129         \param widget
130             String object holding the name of a widget look to test for.
131 
132         \return
133             - true if a WidgetLookFeel named \a widget is available.
134             - false if so such WidgetLookFeel is currently available.
135         */
136         bool isWidgetLookAvailable(const String& widget) const;
137 
138 
139         /*!
140         \brief
141             Return a const reference to a WidgetLookFeel object which has the specified name.
142 
143         \param widget
144             String object holding the name of a widget look that is to be returned.
145 
146         \return
147             const reference to the requested WidgetLookFeel object.
148 
149         \exception UnknownObjectException   thrown if no WidgetLookFeel is available with the requested name.
150         */
151         const WidgetLookFeel& getWidgetLook(const String& widget) const;
152 
153 
154         /*!
155         \brief
156             Erase the WidgetLookFeel that has the specified name.
157 
158         \param widget
159             String object holding the name of a widget look to be erased.  If no such WidgetLookFeel exists, nothing
160             happens.
161 
162         \return
163             Nothing.
164         */
165         void eraseWidgetLook(const String& widget);
166 
167         //! erase all defined WidgetLookFeel.
168         void eraseAllWidgetLooks();
169 
170         /*!
171         \brief
172             Add the given WidgetLookFeel.
173 
174         \note
175             If the WidgetLookFeel specification uses a name that already exists within the system, it is not an error;
176             the previous definition is overwritten by the new data.  An entry will appear in the log each time any
177             look & feel component is overwritten.
178 
179         \param look
180             WidgetLookFeel object to be added to the system.  NB: The WidgetLookFeel is copied, no change of ownership of the
181             input object occurrs.
182 
183         \return
184             Nothing.
185         */
186         void addWidgetLook(const WidgetLookFeel& look);
187 
188 
189         /*!
190         \brief
191             Writes a complete WidgetLookFeel to a stream. Note that XML file header and
192             Falagard opening/closing tags will also be written.
193 
194         \param name
195             String holding the name of the WidgetLookFeel to be output to the stream.
196 
197         \param out_stream
198             OutStream where XML data should be sent.
199         */
200         void writeWidgetLookToStream(const String& widgetLookName, OutStream& out_stream) const;
201 
202         /*!
203         \brief
204             Writes a complete WidgetLookFeel to a string. Note that XML file header and
205             Falagard opening/closing tags will also be written.
206 
207         \param name
208             String holding the name of the WidgetLookFeel to be output to the string.
209 
210         \return
211             String containing the WidgetLook parsed to XML.
212         */
213         String getWidgetLookAsString(const String& widgetLookName) const;
214 
215         /*!
216         \brief
217             Writes a set WidgetLookFeels to a string. Note that XML file header and
218             Falagard opening/closing tags will also be written.
219 
220         \param widgetLookNameSet
221             Set of strings containing the WidgetLookFeel names to be output to the string.
222 
223         \return
224             String containing the set of WidgetLookFeels parsed to XML.
225         */
226         String getWidgetLookSetAsString(const WidgetLookNameSet& widgetLookNameSet) const;
227 
228         /*!
229         \brief
230             Writes a series of complete WidgetLook objects to a stream. Note that XML file header and
231             Falagard opening/closing tags will also be written.
232 
233             The \a prefix specifies a name prefix common to all widget looks to be written, you could
234             specify this as "TaharezLook/" and then any defined widget look starting with that prefix, such
235             as "TaharezLook/Button" and "TaharezLook/Listbox" will be written to the stream.
236 
237         \param prefix
238             String holding the widget look name prefix, which will be used when searching for the widget looks
239             to be output to the stream.
240 
241         \param out_stream
242             OutStream where XML data should be sent.
243         */
244         void writeWidgetLookSeriesToStream(const String& prefix, OutStream& out_stream) const;
245 
246         /*!
247         \brief
248             Writes a series of complete WidgetLook objects to a stream. Note that XML file header and
249             Falagard opening/closing tags will also be written.
250 
251             The \a widgetLookSet specifies a set of strings containing the names of the WidgetLookFeels
252             to be written to the stream.
253 
254         \param widgetLookNameSet
255             Set of strings containing the WidgetLookFeel names to be added to be written to the stream.
256 
257         \param out_stream
258             OutStream where XML data should be sent.
259         */
260         void writeWidgetLookSetToStream(const WidgetLookNameSet& widgetLookNameSet, OutStream& out_stream) const;
261 
262         /*!
263         \brief
264             Returns the default resource group currently set for LookNFeels.
265 
266         \return
267             String describing the default resource group identifier that will be
268             used when loading LookNFeel data.
269         */
getDefaultResourceGroup()270         static const String& getDefaultResourceGroup()
271             { return d_defaultResourceGroup; }
272 
273         /*!
274         \brief
275             Sets the default resource group to be used when loading LookNFeel data
276 
277         \param resourceGroup
278             String describing the default resource group identifier to be used.
279 
280         \return
281             Nothing.
282         */
setDefaultResourceGroup(const String & resourceGroup)283         static void setDefaultResourceGroup(const String& resourceGroup)
284             { d_defaultResourceGroup = resourceGroup; }
285 
286         /*!
287         \brief
288             Returns a map containing Strings to WidgetLookFeel pointers. The map contains pointers to the WidgetLookFeels
289             that were added to this Manager.
290 
291         \return
292             A map of Strings to WidgetLookFeel pointers.
293         */
294         WidgetLookPointerMap getWidgetLookPointerMap();
295 
296     private:
297         //! Name of schema file used for XML validation.
298         static const String FalagardSchemaName;
299         //! holds default resource group
300         static String d_defaultResourceGroup;
301 
302 
303         //! Typedef for a map of Strings to WidgetLookFeel objects
304         // \deprecated  Will use the correct allocator in the next version and will
305         // be renamed to "WidgetLookMap"
306         typedef std::map<String, WidgetLookFeel, StringFastLessCompare> WidgetLookList;
307 
308         //! List of WidgetLookFeels added to this Manager
309         WidgetLookList  d_widgetLooks;
310 
311     public:
312         //! \deprecated Use WidgetLookPointerMap instead, which provides direct access to the added elements.
313         typedef ConstMapIterator<WidgetLookList> WidgetLookIterator;
314         //! \deprecated Use getWidgetLookPointerMap instead, which provides direct access to the added elements. In the next version getWidgetLookMap will be added to replace the const-ness.
315         WidgetLookIterator getWidgetLookIterator() const;
316     };
317 
318 } // End of  CEGUI namespace section
319 
320 
321 #if defined(_MSC_VER)
322 #	pragma warning(pop)
323 #endif
324 
325 #endif  // end of guard _CEGUIFalWidgetLookManager_h_
326