]> git.sesse.net Git - vlc/blob - modules/gui/skins2/parser/skin_parser.cpp
f3ea0c2f748ae811101d2b58512143d8778cbe22
[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
295     else if( rName == "Playlist" )
296     {
297         RequireDefault( "id" );
298         RequireDefault( "font" );
299         CheckDefault( "visible", "true" );
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( "fgcolor", "#000000" );
308         CheckDefault( "playcolor", "#FF0000" );
309         CheckDefault( "bgcolor1", "#FFFFFF" );
310         CheckDefault( "bgcolor2", "#FFFFFF" );
311         CheckDefault( "selcolor", "#0000FF" );
312         CheckDefault( "help", "" );
313
314         m_curListId = uniqueId( attr["id"] );
315         const BuilderData::List listData( m_curListId, atoi( attr["x"] ) +
316                 m_xOffset, atoi( attr["y"] ) + m_yOffset, attr["visible"],
317                 atoi( attr["width"]), atoi( attr["height"] ),
318                 attr["lefttop"], attr["rightbottom"], attr["font"],
319                 "playlist", attr["bgimage"], attr["fgcolor"],
320                 attr["playcolor"], attr["bgcolor1"], attr["bgcolor2"],
321                 attr["selcolor"], attr["help"],
322                 m_curLayer, m_curWindowId, m_curLayoutId );
323         m_curLayer++;
324         m_pData->m_listList.push_back( listData );
325     }
326
327     else if( rName == "Playtree" )
328     {
329         RequireDefault( "id" );
330         RequireDefault( "font" );
331         CheckDefault( "visible", "true" );
332         CheckDefault( "flat", "false" );
333         CheckDefault( "x", "0" );
334         CheckDefault( "y", "0" );
335         CheckDefault( "width", "0" );
336         CheckDefault( "height", "0" );
337         CheckDefault( "lefttop", "lefttop" );
338         CheckDefault( "rightbottom", "lefttop" );
339         CheckDefault( "bgimage", "none" );
340         CheckDefault( "itemimage", "none" );
341         CheckDefault( "openimage", "none" );
342         CheckDefault( "closedimage", "none" );
343         CheckDefault( "fgcolor", "#000000" );
344         CheckDefault( "playcolor", "#FF0000" );
345         CheckDefault( "bgcolor1", "#FFFFFF" );
346         CheckDefault( "bgcolor2", "#FFFFFF" );
347         CheckDefault( "selcolor", "#0000FF" );
348         CheckDefault( "help", "" );
349
350         m_curTreeId = uniqueId( attr["id"] );
351         const BuilderData::Tree treeData( m_curTreeId, atoi( attr["x"] ) +
352                 m_xOffset, atoi( attr["y"] ) + m_yOffset, attr["visible"],
353                 attr["flat"],
354                 atoi( attr["width"]), atoi( attr["height"] ),
355                 attr["lefttop"], attr["rightbottom"],
356                 attr["font"], "playtree",
357                 attr["bgimage"], attr["itemimage"],
358                 attr["openimage"], attr["closedimage"],
359                 attr["fgcolor"], attr["playcolor"],
360                 attr["bgcolor1"], attr["bgcolor2"],
361                 attr["selcolor"], attr["help"],
362                 m_curLayer, m_curWindowId, m_curLayoutId );
363         m_curLayer++;
364         m_pData->m_listTree.push_back( treeData );
365     }
366
367     else if( rName == "RadialSlider" )
368     {
369         RequireDefault( "sequence" );
370         RequireDefault( "nbimages" );
371         CheckDefault( "id", "none" );
372         CheckDefault( "visible", "true" );
373         CheckDefault( "x", "0" );
374         CheckDefault( "y", "0" );
375         CheckDefault( "lefttop", "lefttop" );
376         CheckDefault( "rightbottom", "lefttop" );
377         CheckDefault( "minangle", "0" );
378         CheckDefault( "maxangle", "360" );
379         CheckDefault( "value", "none" );
380         CheckDefault( "tooltiptext", "" );
381         CheckDefault( "help", "" );
382
383         const BuilderData::RadialSlider radial( uniqueId( attr["id"] ),
384                 attr["visible"],
385                 atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
386                 attr["lefttop"], attr["rightbottom"], attr["sequence"],
387                 atoi( attr["nbImages"] ), atof( attr["minAngle"] ) * M_PI /180,
388                 atof( attr["maxAngle"] ) * M_PI / 180, attr["value"],
389                 attr["tooltiptext"], attr["help"], m_curLayer, m_curWindowId,
390                 m_curLayoutId );
391         m_curLayer++;
392         m_pData->m_listRadialSlider.push_back( radial );
393     }
394
395     else if( rName == "Slider" )
396     {
397         RequireDefault( "up" );
398         RequireDefault( "points" );
399         CheckDefault( "id", "none" );
400         CheckDefault( "visible", "true" );
401         CheckDefault( "x", "0" );
402         CheckDefault( "y", "0" );
403         CheckDefault( "width", "0" );
404         CheckDefault( "height", "0" );
405         CheckDefault( "lefttop", "lefttop" );
406         CheckDefault( "rightbottom", "lefttop" );
407         CheckDefault( "down", "none" );
408         CheckDefault( "over", "none" );
409         CheckDefault( "thickness", "10" );
410         CheckDefault( "value", "none" );
411         CheckDefault( "tooltiptext", "" );
412         CheckDefault( "help", "" );
413
414         string newValue = attr["value"];
415         if( m_curListId != "" )
416         {
417             // Slider associated to a list
418             newValue = "playlist.slider";
419         }
420         else if( m_curTreeId != "" )
421         {
422             // Slider associated to a tree
423             newValue = "playtree.slider";
424         }
425         const BuilderData::Slider slider( uniqueId( attr["id"] ),
426                 attr["visible"], atoi( attr["x"] ) + m_xOffset,
427                 atoi( attr["y"] ) + m_yOffset, attr["lefttop"],
428                 attr["rightbottom"], attr["up"], attr["down"],
429                 attr["over"], attr["points"], atoi( attr["thickness"] ),
430                 newValue, "none", 0, 0, 0, 0, attr["tooltiptext"],
431                 attr["help"], m_curLayer, m_curWindowId, m_curLayoutId );
432         m_curLayer++;
433         m_pData->m_listSlider.push_back( slider );
434     }
435
436     else if( rName == "SliderBackground" )
437     {
438         RequireDefault( "image" );
439         CheckDefault( "nbhoriz", "1" );
440         CheckDefault( "nbvert", "1" );
441         CheckDefault( "padhoriz", "0" );
442         CheckDefault( "padvert", "0" );
443
444         // Retrieve the current slider data
445         BuilderData::Slider &slider = m_pData->m_listSlider.back();
446
447         slider.m_imageId = attr["image"];
448         slider.m_nbHoriz = atoi( attr["nbhoriz"] );
449         slider.m_nbVert = atoi( attr["nbvert"] );
450         slider.m_padHoriz = atoi( attr["padhoriz"] );
451         slider.m_padVert = atoi( attr["padvert"] );
452     }
453
454     else if( rName == "Text" )
455     {
456         RequireDefault( "font" );
457         CheckDefault( "id", "none" );
458         CheckDefault( "visible", "true" );
459         CheckDefault( "x", "0" );
460         CheckDefault( "y", "0" );
461         CheckDefault( "text", "" );
462         CheckDefault( "color", "#000000" );
463         CheckDefault( "scrolling", "auto" );
464         CheckDefault( "alignment", "left" );
465         CheckDefault( "width", "0" );
466         CheckDefault( "lefttop", "lefttop" );
467         CheckDefault( "rightbottom", "lefttop" );
468         CheckDefault( "help", "" );
469
470         const BuilderData::Text textData( uniqueId( attr["id"] ),
471                 atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
472                 attr["visible"], attr["font"],
473                 attr["text"], atoi( attr["width"] ),
474                 attr["lefttop"], attr["rightbottom"],
475                 convertColor( attr["color"] ),
476                 attr["scrolling"], attr["alignment"],
477                 attr["help"], m_curLayer, m_curWindowId, m_curLayoutId );
478         m_curLayer++;
479         m_pData->m_listText.push_back( textData );
480     }
481
482     else if( rName == "Theme" )
483     {
484         RequireDefault( "version" );
485         CheckDefault( "tooltipfont", "defaultfont" );
486         CheckDefault( "magnet", "15" );
487         CheckDefault( "alpha", "255" );
488         CheckDefault( "movealpha", "255" );
489
490         // Check the version
491         if( strcmp( attr["version"], SKINS_DTD_VERSION ) )
492         {
493             msg_Err( getIntf(), "bad theme version : %s (you need version %s)",
494                      attr["version"], SKINS_DTD_VERSION );
495             m_errors = true;
496             return;
497         }
498         const BuilderData::Theme theme( attr["tooltipfont"],
499                 atoi( attr["magnet"] ),
500                 convertInRange( attr["alpha"], 1, 255, "alpha" ),
501                 convertInRange( attr["movealpha"], 1, 255, "movealpha" ) );
502         m_pData->m_listTheme.push_back( theme );
503     }
504
505     else if( rName == "ThemeInfo" )
506     {
507         msg_Info( getIntf(), "skin: %s  author: %s", attr["name"],
508                   attr["author"] );
509     }
510
511     else if( rName == "Video" )
512     {
513         CheckDefault( "id", "none" );
514         CheckDefault( "visible", "true" );
515         CheckDefault( "x", "0" );
516         CheckDefault( "y", "0" );
517         CheckDefault( "width", "0" );
518         CheckDefault( "height", "0" );
519         CheckDefault( "lefttop", "lefttop" );
520         CheckDefault( "rightbottom", "lefttop" );
521         CheckDefault( "autoresize", "false" );
522         CheckDefault( "help", "" );
523
524         const BuilderData::Video videoData( uniqueId( attr["id"] ),
525                 atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
526                 atoi( attr["width"] ), atoi( attr["height" ]),
527                 attr["lefttop"], attr["rightbottom"],
528                 attr["visible"], convertBoolean( attr["autoresize"] ),
529                 attr["help"], m_curLayer, m_curWindowId, m_curLayoutId );
530         m_curLayer++;
531         m_pData->m_listVideo.push_back( videoData );
532     }
533
534     else if( rName == "Window" )
535     {
536         CheckDefault( "id", "none" );
537         CheckDefault( "visible", "true" );
538         CheckDefault( "x", "0" );
539         CheckDefault( "y", "0" );
540         CheckDefault( "dragdrop", "true" );
541         CheckDefault( "playondrop", "true" );
542
543         m_curWindowId = uniqueId( attr["id"] );
544         const BuilderData::Window window( m_curWindowId,
545                 atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
546                 convertBoolean( attr["visible"] ),
547                 convertBoolean( attr["dragdrop"] ),
548                 convertBoolean( attr["playondrop"] ) );
549         m_pData->m_listWindow.push_back( window );
550     }
551 }
552
553
554 void SkinParser::handleEndElement( const string &rName )
555 {
556     if( rName == "Group" )
557     {
558         m_xOffset -= m_xOffsetList.back();
559         m_yOffset -= m_yOffsetList.back();
560         m_xOffsetList.pop_back();
561         m_yOffsetList.pop_back();
562     }
563     else if( rName == "Playlist" )
564     {
565         m_curListId = "";
566     }
567     else if( rName == "Playtree" )
568     {
569         m_curTreeId = "";
570     }
571     else if( rName == "Popup" )
572     {
573         m_curPopupId = "";
574         m_popupPosList.pop_back();
575     }
576 }
577
578
579 bool SkinParser::convertBoolean( const char *value ) const
580 {
581     return strcmp( value, "true" ) == 0;
582 }
583
584
585 int SkinParser::convertColor( const char *transcolor )
586 {
587     // TODO: move to the builder
588     unsigned long iRed, iGreen, iBlue;
589     iRed = iGreen = iBlue = 0;
590     sscanf( transcolor, "#%2lX%2lX%2lX", &iRed, &iGreen, &iBlue );
591     return ( iRed << 16 | iGreen << 8 | iBlue );
592 }
593
594
595 int SkinParser::convertInRange( const char *value, int minValue, int maxValue,
596                                 const string &rAttribute ) const
597 {
598     int intValue = atoi( value );
599
600     if( intValue < minValue )
601     {
602         msg_Warn( getIntf(), "value of \"%s\" attribute (%i) is out of the "
603                   "expected range [%i, %i], using %i instead",
604                   rAttribute.c_str(), intValue, minValue, maxValue, minValue );
605         return minValue;
606     }
607     else if( intValue > maxValue )
608     {
609         msg_Warn( getIntf(), "value of \"%s\" attribute (%i) is out of the "
610                   "expected range [%i, %i], using %i instead",
611                   rAttribute.c_str(), intValue, minValue, maxValue, maxValue );
612         return maxValue;
613     }
614     else
615     {
616         return intValue;
617     }
618 }
619
620
621 const string SkinParser::generateId() const
622 {
623     static int i = 1;
624
625     char genId[5];
626     snprintf( genId, 4, "%i", i++ );
627
628     string base = "_ReservedId_" + (string)genId;
629
630     return base;
631 }
632
633
634 const string SkinParser::uniqueId( const string &id )
635 {
636     string newId;
637
638     if( m_idSet.find( id ) != m_idSet.end() )
639     {
640         // The id was already used
641         if( id != "none" )
642         {
643             msg_Warn( getIntf(), "non-unique id: %s", id.c_str() );
644         }
645         newId = generateId();
646     }
647     else
648     {
649         // OK, this is a new id
650         newId = id;
651     }
652
653     // Add the id to the set
654     m_idSet.insert( newId );
655
656     return newId;
657 }