]> git.sesse.net Git - vlc/blob - modules/gui/skins2/parser/skin_parser.cpp
Merge back branch 0.8.6-playlist-vlm to trunk.
[vlc] / modules / gui / skins2 / parser / skin_parser.cpp
1 /*****************************************************************************
2  * skin_parser.cpp
3  *****************************************************************************
4  * Copyright (C) 2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #include "skin_parser.hpp"
25 #include "../src/os_factory.hpp"
26 #include "interpreter.hpp"
27 #include <math.h>
28
29 SkinParser::SkinParser( intf_thread_t *pIntf, const string &rFileName,
30                         const string &rPath, bool useDTD, BuilderData *pData ):
31     XMLParser( pIntf, rFileName, useDTD ), m_path( rPath), m_pData(pData),
32     m_ownData(pData == NULL), m_xOffset( 0 ), m_yOffset( 0 )
33 {
34     // Make sure the data is allocated
35     if( m_pData == NULL )
36     {
37         m_pData = new BuilderData();
38     }
39 }
40
41
42 SkinParser::~SkinParser()
43 {
44     if( m_ownData )
45     {
46         delete m_pData;
47     }
48 }
49
50
51 void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
52 {
53 #define CheckDefault( a, b ) \
54     if( attr.find(a) == attr.end() ) attr[strdup(a)] = strdup(b);
55 #define RequireDefault( a ) \
56     if( attr.find(a) == attr.end() ) \
57     { \
58         msg_Err( getIntf(), "bad theme (element: %s, missing attribute: %s)", \
59                  rName.c_str(), a ); \
60         m_errors = true; return; \
61     }
62
63     if( rName == "Include" )
64     {
65         RequireDefault( "file" );
66
67         OSFactory *pFactory = OSFactory::instance( getIntf() );
68         string fullPath = m_path + pFactory->getDirSeparator() + attr["file"];
69         msg_Dbg( getIntf(), "opening included XML file: %s", fullPath.c_str() );
70         // FIXME: We do not use the DTD to validate the included XML file,
71         // as the parser seems to dislike it otherwise...
72         SkinParser subParser( getIntf(), fullPath.c_str(), false, m_pData );
73         subParser.parse();
74     }
75
76     else if( rName == "IniFile" )
77     {
78         RequireDefault( "id" );
79         RequireDefault( "file" );
80
81         const BuilderData::IniFile iniFile( attr["id"],
82                 attr["file"] );
83         m_pData->m_listIniFile.push_back( iniFile );
84     }
85
86     else if( rName == "Anchor" )
87     {
88         RequireDefault( "priority" );
89         CheckDefault( "x", "0" );
90         CheckDefault( "y", "0" );
91         CheckDefault( "points", "(0,0)" );
92         CheckDefault( "range", "10" );
93
94         const BuilderData::Anchor anchor( atoi( attr["x"] ) + m_xOffset,
95                 atoi( attr["y"] ) + m_yOffset, atoi( attr["range"] ),
96                 atoi( attr["priority"] ), attr["points"], m_curLayoutId );
97         m_pData->m_listAnchor.push_back( anchor );
98     }
99
100     else if( rName == "Bitmap" )
101     {
102         RequireDefault( "id" );
103         RequireDefault( "file" );
104         RequireDefault( "alphacolor" );
105         CheckDefault( "nbframes", "1" );
106         CheckDefault( "fps", "4" );
107
108         m_curBitmapId = uniqueId( attr["id"] );
109         const BuilderData::Bitmap bitmap( m_curBitmapId,
110                 attr["file"], convertColor( attr["alphacolor"] ),
111                 atoi( attr["nbframes"] ), atoi( attr["fps"] ) );
112         m_pData->m_listBitmap.push_back( bitmap );
113     }
114
115     else if( rName == "SubBitmap" )
116     {
117         RequireDefault( "id" );
118         RequireDefault( "x" );
119         RequireDefault( "y" );
120         RequireDefault( "width" );
121         RequireDefault( "height" );
122         CheckDefault( "nbframes", "1" );
123         CheckDefault( "fps", "4" );
124
125         const BuilderData::SubBitmap bitmap( attr["id"],
126                 m_curBitmapId, atoi( attr["x"] ), atoi( attr["y"] ),
127                 atoi( attr["width"] ), atoi( attr["height"] ),
128                 atoi( attr["nbframes"] ), atoi( attr["fps"] ) );
129         m_pData->m_listSubBitmap.push_back( bitmap );
130     }
131
132     else if( rName == "BitmapFont" )
133     {
134         RequireDefault( "id" );
135         RequireDefault( "file" );
136         CheckDefault( "type", "digits" );
137
138         const BuilderData::BitmapFont font( attr["id"],
139                 attr["file"], attr["type"] );
140         m_pData->m_listBitmapFont.push_back( font );
141     }
142
143     else if( rName == "PopupMenu" )
144     {
145         RequireDefault( "id" );
146
147         m_popupPosList.push_back(0);
148         m_curPopupId = uniqueId( attr["id"] );
149         const BuilderData::PopupMenu popup( m_curPopupId );
150         m_pData->m_listPopupMenu.push_back( popup );
151     }
152
153     else if( rName == "MenuItem" )
154     {
155         RequireDefault( "label" );
156         CheckDefault( "action", "none" );
157
158         const BuilderData::MenuItem item( attr["label"], attr["action"],
159                                           m_popupPosList.back(),
160                                           m_curPopupId );
161         m_pData->m_listMenuItem.push_back( item );
162         m_popupPosList.back()++;
163     }
164
165     else if( rName == "MenuSeparator" )
166     {
167         const BuilderData::MenuSeparator sep( m_popupPosList.back(),
168                                               m_curPopupId );
169         m_pData->m_listMenuSeparator.push_back( sep );
170         m_popupPosList.back()++;
171     }
172
173     else if( rName == "Button" )
174     {
175         RequireDefault( "up" );
176         CheckDefault( "id", "none" );
177         CheckDefault( "visible", "true" );
178         CheckDefault( "x", "0" );
179         CheckDefault( "y", "0" );
180         CheckDefault( "lefttop", "lefttop" );
181         CheckDefault( "rightbottom", "lefttop" );
182         CheckDefault( "down", "none" );
183         CheckDefault( "over", "none" );
184         CheckDefault( "action", "none" );
185         CheckDefault( "tooltiptext", "" );
186         CheckDefault( "help", "" );
187
188         const BuilderData::Button button( uniqueId( attr["id"] ),
189                 atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
190                 attr["lefttop"], attr["rightbottom"], attr["visible"],
191                 attr["up"], attr["down"], attr["over"], attr["action"],
192                 attr["tooltiptext"], attr["help"],
193                 m_curLayer, m_curWindowId, m_curLayoutId );
194         m_curLayer++;
195         m_pData->m_listButton.push_back( button );
196     }
197
198     else if( rName == "Checkbox" )
199     {
200         RequireDefault( "up1" );
201         RequireDefault( "up2" );
202         RequireDefault( "state" );
203         CheckDefault( "id", "none" );
204         CheckDefault( "visible", "true" );
205         CheckDefault( "x", "0" );
206         CheckDefault( "y", "0" );
207         CheckDefault( "lefttop", "lefttop" );
208         CheckDefault( "rightbottom", "lefttop" );
209         CheckDefault( "down1", "none" );
210         CheckDefault( "over1", "none" );
211         CheckDefault( "down2", "none" );
212         CheckDefault( "over2", "none" );
213         CheckDefault( "action1", "none" );
214         CheckDefault( "action2", "none" );
215         CheckDefault( "tooltiptext1", "" );
216         CheckDefault( "tooltiptext2", "" );
217         CheckDefault( "help", "" );
218
219         const BuilderData::Checkbox checkbox( uniqueId( attr["id"] ),
220                 atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
221                 attr["lefttop"], attr["rightbottom"], attr["visible"],
222                 attr["up1"], attr["down1"], attr["over1"],
223                 attr["up2"], attr["down2"], attr["over2"], attr["state"],
224                 attr["action1"], attr["action2"], attr["tooltiptext1"],
225                 attr["tooltiptext2"], attr["help"], m_curLayer, m_curWindowId,
226                 m_curLayoutId );
227         m_curLayer++;
228         m_pData->m_listCheckbox.push_back( checkbox );
229     }
230
231     else if( rName == "Font" )
232     {
233         RequireDefault( "id" );
234         RequireDefault( "file" );
235         CheckDefault( "size", "12" );
236
237         const BuilderData::Font fontData( uniqueId( attr["id"] ),
238                 attr["file"], atoi( attr["size"] ) );
239         m_pData->m_listFont.push_back( fontData );
240     }
241
242     else if( rName == "Group" )
243     {
244         CheckDefault( "x", "0" );
245         CheckDefault( "y", "0" );
246
247         m_xOffset += atoi( attr["x"] );
248         m_yOffset += atoi( attr["y"] );
249         m_xOffsetList.push_back( atoi( attr["x"] ) );
250         m_yOffsetList.push_back( atoi( attr["y"] ) );
251     }
252
253     else if( rName == "Image" )
254     {
255         RequireDefault( "image" );
256         CheckDefault( "id", "none" );
257         CheckDefault( "visible", "true" );
258         CheckDefault( "x", "0" );
259         CheckDefault( "y", "0" );
260         CheckDefault( "lefttop", "lefttop" );
261         CheckDefault( "rightbottom", "lefttop" );
262         CheckDefault( "action", "none" );
263         CheckDefault( "action2", "none" );
264         CheckDefault( "resize", "mosaic" );
265         CheckDefault( "help", "" );
266
267         const BuilderData::Image imageData( uniqueId( attr["id"] ),
268                 atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
269                 attr["lefttop"], attr["rightbottom"], attr["visible"],
270                 attr["image"], attr["action"], attr["action2"], attr["resize"],
271                 attr["help"], m_curLayer, m_curWindowId, m_curLayoutId );
272         m_curLayer++;
273         m_pData->m_listImage.push_back( imageData );
274     }
275
276     else if( rName == "Layout" )
277     {
278         RequireDefault( "width" );
279         RequireDefault( "height" );
280         CheckDefault( "id", "none" );
281         CheckDefault( "minwidth", "-1" );
282         CheckDefault( "maxwidth", "-1" );
283         CheckDefault( "minheight", "-1" );
284         CheckDefault( "maxheight", "-1" );
285
286         m_curLayoutId = uniqueId( attr["id"] );
287         const BuilderData::Layout layout( m_curLayoutId, atoi( attr["width"] ),
288                 atoi( attr["height"] ), atoi( attr["minwidth"] ),
289                 atoi( attr["maxwidth"] ), atoi( attr["minheight"] ),
290                 atoi( attr["maxheight"] ), m_curWindowId );
291         m_pData->m_listLayout.push_back( layout );
292         m_curLayer = 0;
293     }
294     else if( rName == "Playlist" )
295     {
296         RequireDefault( "id" );
297         RequireDefault( "font" );
298         CheckDefault( "visible", "true" );
299         CheckDefault( "flat", "true" ); // Only difference here
300         CheckDefault( "x", "0" );
301         CheckDefault( "y", "0" );
302         CheckDefault( "width", "0" );
303         CheckDefault( "height", "0" );
304         CheckDefault( "lefttop", "lefttop" );
305         CheckDefault( "rightbottom", "lefttop" );
306         CheckDefault( "bgimage", "none" );
307         CheckDefault( "itemimage", "none" );
308         CheckDefault( "openimage", "none" );
309         CheckDefault( "closedimage", "none" );
310         CheckDefault( "fgcolor", "#000000" );
311         CheckDefault( "playcolor", "#FF0000" );
312         CheckDefault( "bgcolor1", "#FFFFFF" );
313         CheckDefault( "bgcolor2", "#FFFFFF" );
314         CheckDefault( "selcolor", "#0000FF" );
315         CheckDefault( "help", "" );
316         m_curTreeId = uniqueId( attr["id"] );
317         const BuilderData::Tree treeData( m_curTreeId, atoi( attr["x"] ) +
318                 m_xOffset, atoi( attr["y"] ) + m_yOffset, attr["visible"],
319                 attr["flat"],
320                 atoi( attr["width"]), atoi( attr["height"] ),
321                 attr["lefttop"], attr["rightbottom"],
322                 attr["font"], "playtree",
323                 attr["bgimage"], attr["itemimage"],
324                 attr["openimage"], attr["closedimage"],
325                 attr["fgcolor"],
326                 attr["playcolor"],
327                 attr["bgcolor1"],
328                 attr["bgcolor2"],
329                 attr["selcolor"], attr["help"],
330                 m_curLayer, m_curWindowId, m_curLayoutId );
331         m_curLayer++;
332         m_pData->m_listTree.push_back( treeData );
333     }
334     else if( rName == "Playtree" )
335     {
336         RequireDefault( "id" );
337         RequireDefault( "font" );
338         CheckDefault( "visible", "true" );
339         CheckDefault( "flat", "false" );
340         CheckDefault( "x", "0" );
341         CheckDefault( "y", "0" );
342         CheckDefault( "width", "0" );
343         CheckDefault( "height", "0" );
344         CheckDefault( "lefttop", "lefttop" );
345         CheckDefault( "rightbottom", "lefttop" );
346         CheckDefault( "bgimage", "none" );
347         CheckDefault( "itemimage", "none" );
348         CheckDefault( "openimage", "none" );
349         CheckDefault( "closedimage", "none" );
350         CheckDefault( "fgcolor", "#000000" );
351         CheckDefault( "playcolor", "#FF0000" );
352         CheckDefault( "bgcolor1", "#FFFFFF" );
353         CheckDefault( "bgcolor2", "#FFFFFF" );
354         CheckDefault( "selcolor", "#0000FF" );
355         CheckDefault( "help", "" );
356
357         m_curTreeId = uniqueId( attr["id"] );
358         const BuilderData::Tree treeData( m_curTreeId, atoi( attr["x"] ) +
359                 m_xOffset, atoi( attr["y"] ) + m_yOffset, attr["visible"],
360                 attr["flat"],
361                 atoi( attr["width"]), atoi( attr["height"] ),
362                 attr["lefttop"], attr["rightbottom"],
363                 attr["font"], "playtree",
364                 attr["bgimage"], attr["itemimage"],
365                 attr["openimage"], attr["closedimage"],
366                 attr["fgcolor"], attr["playcolor"],
367                 attr["bgcolor1"], attr["bgcolor2"],
368                 attr["selcolor"], attr["help"],
369                 m_curLayer, m_curWindowId, m_curLayoutId );
370         m_curLayer++;
371         m_pData->m_listTree.push_back( treeData );
372     }
373
374     else if( rName == "RadialSlider" )
375     {
376         RequireDefault( "sequence" );
377         RequireDefault( "nbimages" );
378         CheckDefault( "id", "none" );
379         CheckDefault( "visible", "true" );
380         CheckDefault( "x", "0" );
381         CheckDefault( "y", "0" );
382         CheckDefault( "lefttop", "lefttop" );
383         CheckDefault( "rightbottom", "lefttop" );
384         CheckDefault( "minangle", "0" );
385         CheckDefault( "maxangle", "360" );
386         CheckDefault( "value", "none" );
387         CheckDefault( "tooltiptext", "" );
388         CheckDefault( "help", "" );
389
390         const BuilderData::RadialSlider radial( uniqueId( attr["id"] ),
391                 attr["visible"],
392                 atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
393                 attr["lefttop"], attr["rightbottom"], attr["sequence"],
394                 atoi( attr["nbImages"] ), atof( attr["minAngle"] ) * M_PI /180,
395                 atof( attr["maxAngle"] ) * M_PI / 180, attr["value"],
396                 attr["tooltiptext"], attr["help"], m_curLayer, m_curWindowId,
397                 m_curLayoutId );
398         m_curLayer++;
399         m_pData->m_listRadialSlider.push_back( radial );
400     }
401
402     else if( rName == "Slider" )
403     {
404         RequireDefault( "up" );
405         RequireDefault( "points" );
406         CheckDefault( "id", "none" );
407         CheckDefault( "visible", "true" );
408         CheckDefault( "x", "0" );
409         CheckDefault( "y", "0" );
410         CheckDefault( "width", "0" );
411         CheckDefault( "height", "0" );
412         CheckDefault( "lefttop", "lefttop" );
413         CheckDefault( "rightbottom", "lefttop" );
414         CheckDefault( "down", "none" );
415         CheckDefault( "over", "none" );
416         CheckDefault( "thickness", "10" );
417         CheckDefault( "value", "none" );
418         CheckDefault( "tooltiptext", "" );
419         CheckDefault( "help", "" );
420
421         string newValue = attr["value"];
422         if( m_curTreeId != "" )
423         {
424             // Slider associated to a tree
425             newValue = "playtree.slider";
426         }
427         const BuilderData::Slider slider( uniqueId( attr["id"] ),
428                 attr["visible"], atoi( attr["x"] ) + m_xOffset,
429                 atoi( attr["y"] ) + m_yOffset, attr["lefttop"],
430                 attr["rightbottom"], attr["up"], attr["down"],
431                 attr["over"], attr["points"], atoi( attr["thickness"] ),
432                 newValue, "none", 0, 0, 0, 0, attr["tooltiptext"],
433                 attr["help"], m_curLayer, m_curWindowId, m_curLayoutId );
434         m_curLayer++;
435         m_pData->m_listSlider.push_back( slider );
436     }
437
438     else if( rName == "SliderBackground" )
439     {
440         RequireDefault( "image" );
441         CheckDefault( "nbhoriz", "1" );
442         CheckDefault( "nbvert", "1" );
443         CheckDefault( "padhoriz", "0" );
444         CheckDefault( "padvert", "0" );
445
446         // Retrieve the current slider data
447         BuilderData::Slider &slider = m_pData->m_listSlider.back();
448
449         slider.m_imageId = attr["image"];
450         slider.m_nbHoriz = atoi( attr["nbhoriz"] );
451         slider.m_nbVert = atoi( attr["nbvert"] );
452         slider.m_padHoriz = atoi( attr["padhoriz"] );
453         slider.m_padVert = atoi( attr["padvert"] );
454     }
455
456     else if( rName == "Text" )
457     {
458         RequireDefault( "font" );
459         CheckDefault( "id", "none" );
460         CheckDefault( "visible", "true" );
461         CheckDefault( "x", "0" );
462         CheckDefault( "y", "0" );
463         CheckDefault( "text", "" );
464         CheckDefault( "color", "#000000" );
465         CheckDefault( "scrolling", "auto" );
466         CheckDefault( "alignment", "left" );
467         CheckDefault( "width", "0" );
468         CheckDefault( "lefttop", "lefttop" );
469         CheckDefault( "rightbottom", "lefttop" );
470         CheckDefault( "help", "" );
471
472         const BuilderData::Text textData( uniqueId( attr["id"] ),
473                 atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
474                 attr["visible"], attr["font"],
475                 attr["text"], atoi( attr["width"] ),
476                 attr["lefttop"], attr["rightbottom"],
477                 convertColor( attr["color"] ),
478                 attr["scrolling"], attr["alignment"],
479                 attr["help"], m_curLayer, m_curWindowId, m_curLayoutId );
480         m_curLayer++;
481         m_pData->m_listText.push_back( textData );
482     }
483
484     else if( rName == "Theme" )
485     {
486         RequireDefault( "version" );
487         CheckDefault( "tooltipfont", "defaultfont" );
488         CheckDefault( "magnet", "15" );
489         CheckDefault( "alpha", "255" );
490         CheckDefault( "movealpha", "255" );
491
492         // Check the version
493         if( strcmp( attr["version"], SKINS_DTD_VERSION ) )
494         {
495             msg_Err( getIntf(), "bad theme version : %s (you need version %s)",
496                      attr["version"], SKINS_DTD_VERSION );
497             m_errors = true;
498             return;
499         }
500         const BuilderData::Theme theme( attr["tooltipfont"],
501                 atoi( attr["magnet"] ),
502                 convertInRange( attr["alpha"], 1, 255, "alpha" ),
503                 convertInRange( attr["movealpha"], 1, 255, "movealpha" ) );
504         m_pData->m_listTheme.push_back( theme );
505     }
506
507     else if( rName == "ThemeInfo" )
508     {
509         msg_Info( getIntf(), "skin: %s  author: %s", attr["name"],
510                   attr["author"] );
511     }
512
513     else if( rName == "Video" )
514     {
515         CheckDefault( "id", "none" );
516         CheckDefault( "visible", "true" );
517         CheckDefault( "x", "0" );
518         CheckDefault( "y", "0" );
519         CheckDefault( "width", "0" );
520         CheckDefault( "height", "0" );
521         CheckDefault( "lefttop", "lefttop" );
522         CheckDefault( "rightbottom", "lefttop" );
523         CheckDefault( "autoresize", "false" );
524         CheckDefault( "help", "" );
525
526         const BuilderData::Video videoData( uniqueId( attr["id"] ),
527                 atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
528                 atoi( attr["width"] ), atoi( attr["height" ]),
529                 attr["lefttop"], attr["rightbottom"],
530                 attr["visible"], convertBoolean( attr["autoresize"] ),
531                 attr["help"], m_curLayer, m_curWindowId, m_curLayoutId );
532         m_curLayer++;
533         m_pData->m_listVideo.push_back( videoData );
534     }
535
536     else if( rName == "Window" )
537     {
538         CheckDefault( "id", "none" );
539         CheckDefault( "visible", "true" );
540         CheckDefault( "x", "0" );
541         CheckDefault( "y", "0" );
542         CheckDefault( "dragdrop", "true" );
543         CheckDefault( "playondrop", "true" );
544
545         m_curWindowId = uniqueId( attr["id"] );
546         const BuilderData::Window window( m_curWindowId,
547                 atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
548                 convertBoolean( attr["visible"] ),
549                 convertBoolean( attr["dragdrop"] ),
550                 convertBoolean( attr["playondrop"] ) );
551         m_pData->m_listWindow.push_back( window );
552     }
553 }
554
555
556 void SkinParser::handleEndElement( const string &rName )
557 {
558     if( rName == "Group" )
559     {
560         m_xOffset -= m_xOffsetList.back();
561         m_yOffset -= m_yOffsetList.back();
562         m_xOffsetList.pop_back();
563         m_yOffsetList.pop_back();
564     }
565     else if( rName == "Playtree" || rName == "Playlist" )
566     {
567         m_curTreeId = "";
568     }
569     else if( rName == "Popup" )
570     {
571         m_curPopupId = "";
572         m_popupPosList.pop_back();
573     }
574 }
575
576
577 bool SkinParser::convertBoolean( const char *value ) const
578 {
579     return strcmp( value, "true" ) == 0;
580 }
581
582
583 int SkinParser::convertColor( const char *transcolor )
584 {
585     // TODO: move to the builder
586     unsigned long iRed, iGreen, iBlue;
587     iRed = iGreen = iBlue = 0;
588     sscanf( transcolor, "#%2lX%2lX%2lX", &iRed, &iGreen, &iBlue );
589     return ( iRed << 16 | iGreen << 8 | iBlue );
590 }
591
592
593 int SkinParser::convertInRange( const char *value, int minValue, int maxValue,
594                                 const string &rAttribute ) const
595 {
596     int intValue = atoi( value );
597
598     if( intValue < minValue )
599     {
600         msg_Warn( getIntf(), "value of \"%s\" attribute (%i) is out of the "
601                   "expected range [%i, %i], using %i instead",
602                   rAttribute.c_str(), intValue, minValue, maxValue, minValue );
603         return minValue;
604     }
605     else if( intValue > maxValue )
606     {
607         msg_Warn( getIntf(), "value of \"%s\" attribute (%i) is out of the "
608                   "expected range [%i, %i], using %i instead",
609                   rAttribute.c_str(), intValue, minValue, maxValue, maxValue );
610         return maxValue;
611     }
612     else
613     {
614         return intValue;
615     }
616 }
617
618
619 const string SkinParser::generateId() const
620 {
621     static int i = 1;
622
623     char genId[5];
624     snprintf( genId, 4, "%i", i++ );
625
626     string base = "_ReservedId_" + (string)genId;
627
628     return base;
629 }
630
631
632 const string SkinParser::uniqueId( const string &id )
633 {
634     string newId;
635
636     if( m_idSet.find( id ) != m_idSet.end() )
637     {
638         // The id was already used
639         if( id != "none" )
640         {
641             msg_Warn( getIntf(), "non-unique id: %s", id.c_str() );
642         }
643         newId = generateId();
644     }
645     else
646     {
647         // OK, this is a new id
648         newId = id;
649     }
650
651     // Add the id to the set
652     m_idSet.insert( newId );
653
654     return newId;
655 }