1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2004 the VideoLAN team
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
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.
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.
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 *****************************************************************************/
24 #include "skin_parser.hpp"
25 #include "../src/os_factory.hpp"
26 #include "interpreter.hpp"
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 )
34 // Make sure the data is allocated
37 m_pData
= new BuilderData();
40 // Special id, we don't want any control to have the same one
41 m_idSet
.insert( "none" );
42 // At the beginning, there is no Panel
43 m_panelStack
.push_back( "none" );
47 SkinParser::~SkinParser()
55 inline bool SkinParser::MissingAttr( AttrList_t
&attr
, const string
&name
,
58 if( attr
.find(a
) == attr
.end() )
60 msg_Err( getIntf(), "bad theme (element: %s, missing attribute: %s)",
62 m_errors
= true; return true;
67 void SkinParser::handleBeginElement( const string
&rName
, AttrList_t
&attr
)
69 #define RequireAttr( attr, name, a ) \
70 if( MissingAttr( attr, name, a ) ) return;
72 if( rName
== "Include" )
74 RequireAttr( attr
, rName
, "file" );
76 OSFactory
*pFactory
= OSFactory::instance( getIntf() );
77 string fullPath
= m_path
+ pFactory
->getDirSeparator() + attr
["file"];
78 msg_Dbg( getIntf(), "opening included XML file: %s", fullPath
.c_str() );
79 // FIXME: We do not use the DTD to validate the included XML file,
80 // as the parser seems to dislike it otherwise...
81 SkinParser
subParser( getIntf(), fullPath
.c_str(), false, m_pData
);
85 else if( rName
== "IniFile" )
87 RequireAttr( attr
, rName
, "id" );
88 RequireAttr( attr
, rName
, "file" );
90 const BuilderData::IniFile
iniFile( uniqueId( attr
["id"] ),
92 m_pData
->m_listIniFile
.push_back( iniFile
);
95 else if( rName
== "Anchor" )
97 RequireAttr( attr
, rName
, "priority" );
98 DefaultAttr( attr
, "x", "0" );
99 DefaultAttr( attr
, "y", "0" );
100 DefaultAttr( attr
, "lefttop", "lefttop" );
101 DefaultAttr( attr
, "points", "(0,0)" );
102 DefaultAttr( attr
, "range", "10" );
104 const BuilderData::Anchor
anchor( atoi( attr
["x"] ) + m_xOffset
,
105 atoi( attr
["y"] ) + m_yOffset
, attr
["lefttop"],
106 atoi( attr
["range"] ), atoi( attr
["priority"] ),
107 attr
["points"], m_curLayoutId
);
108 m_pData
->m_listAnchor
.push_back( anchor
);
111 else if( rName
== "Bitmap" )
113 RequireAttr( attr
, rName
, "id" );
114 RequireAttr( attr
, rName
, "file" );
115 RequireAttr( attr
, rName
, "alphacolor" );
116 DefaultAttr( attr
, "nbframes", "1" );
117 DefaultAttr( attr
, "fps", "4" );
118 DefaultAttr( attr
, "loop", "0" );
120 m_curBitmapId
= uniqueId( attr
["id"] );
121 const BuilderData::Bitmap
bitmap( m_curBitmapId
,
122 attr
["file"], convertColor( attr
["alphacolor"] ),
123 atoi( attr
["nbframes"] ), atoi( attr
["fps"] ),
124 atoi( attr
["loop"] ) );
125 m_pData
->m_listBitmap
.push_back( bitmap
);
128 else if( rName
== "SubBitmap" )
130 RequireAttr( attr
, rName
, "id" );
131 RequireAttr( attr
, rName
, "x" );
132 RequireAttr( attr
, rName
, "y" );
133 RequireAttr( attr
, rName
, "width" );
134 RequireAttr( attr
, rName
, "height" );
135 DefaultAttr( attr
, "nbframes", "1" );
136 DefaultAttr( attr
, "fps", "4" );
137 DefaultAttr( attr
, "loop", "0" );
139 const BuilderData::SubBitmap
bitmap( uniqueId( attr
["id"] ),
140 m_curBitmapId
, atoi( attr
["x"] ), atoi( attr
["y"] ),
141 atoi( attr
["width"] ), atoi( attr
["height"] ),
142 atoi( attr
["nbframes"] ), atoi( attr
["fps"] ),
143 atoi( attr
["loop"] ) );
144 m_pData
->m_listSubBitmap
.push_back( bitmap
);
147 else if( rName
== "BitmapFont" )
149 RequireAttr( attr
, rName
, "id" );
150 RequireAttr( attr
, rName
, "file" );
151 DefaultAttr( attr
, "type", "digits" );
153 const BuilderData::BitmapFont
font( uniqueId( attr
["id"] ),
154 attr
["file"], attr
["type"] );
155 m_pData
->m_listBitmapFont
.push_back( font
);
158 else if( rName
== "PopupMenu" )
160 RequireAttr( attr
, rName
, "id" );
162 m_popupPosList
.push_back(0);
163 m_curPopupId
= uniqueId( attr
["id"] );
164 const BuilderData::PopupMenu
popup( m_curPopupId
);
165 m_pData
->m_listPopupMenu
.push_back( popup
);
168 else if( rName
== "MenuItem" )
170 RequireAttr( attr
, rName
, "label" );
171 DefaultAttr( attr
, "action", "none" );
173 const BuilderData::MenuItem
item( attr
["label"], attr
["action"],
174 m_popupPosList
.back(),
176 m_pData
->m_listMenuItem
.push_back( item
);
177 m_popupPosList
.back()++;
180 else if( rName
== "MenuSeparator" )
182 const BuilderData::MenuSeparator
sep( m_popupPosList
.back(),
184 m_pData
->m_listMenuSeparator
.push_back( sep
);
185 m_popupPosList
.back()++;
188 else if( rName
== "Button" )
190 RequireAttr( attr
, rName
, "up" );
191 DefaultAttr( attr
, "id", "none" );
192 DefaultAttr( attr
, "visible", "true" );
193 DefaultAttr( attr
, "x", "0" );
194 DefaultAttr( attr
, "y", "0" );
195 DefaultAttr( attr
, "lefttop", "lefttop" );
196 DefaultAttr( attr
, "rightbottom", "lefttop" );
197 DefaultAttr( attr
, "xkeepratio", "false" );
198 DefaultAttr( attr
, "ykeepratio", "false" );
199 DefaultAttr( attr
, "down", "none" );
200 DefaultAttr( attr
, "over", "none" );
201 DefaultAttr( attr
, "action", "none" );
202 DefaultAttr( attr
, "tooltiptext", "" );
203 DefaultAttr( attr
, "help", "" );
205 const BuilderData::Button
button( uniqueId( attr
["id"] ),
206 atoi( attr
["x"] ) + m_xOffset
, atoi( attr
["y"] ) + m_yOffset
,
207 attr
["lefttop"], attr
["rightbottom"],
208 convertBoolean( attr
["xkeepratio"] ),
209 convertBoolean( attr
["ykeepratio"] ), attr
["visible"],
210 attr
["up"], attr
["down"], attr
["over"], attr
["action"],
211 attr
["tooltiptext"], attr
["help"],
212 m_curLayer
, m_curWindowId
, m_curLayoutId
, m_panelStack
.back() );
214 m_pData
->m_listButton
.push_back( button
);
217 else if( rName
== "Checkbox" )
219 RequireAttr( attr
, rName
, "up1" );
220 RequireAttr( attr
, rName
, "up2" );
221 RequireAttr( attr
, rName
, "state" );
222 DefaultAttr( attr
, "id", "none" );
223 DefaultAttr( attr
, "visible", "true" );
224 DefaultAttr( attr
, "x", "0" );
225 DefaultAttr( attr
, "y", "0" );
226 DefaultAttr( attr
, "lefttop", "lefttop" );
227 DefaultAttr( attr
, "rightbottom", "lefttop" );
228 DefaultAttr( attr
, "xkeepratio", "false" );
229 DefaultAttr( attr
, "ykeepratio", "false" );
230 DefaultAttr( attr
, "down1", "none" );
231 DefaultAttr( attr
, "over1", "none" );
232 DefaultAttr( attr
, "down2", "none" );
233 DefaultAttr( attr
, "over2", "none" );
234 DefaultAttr( attr
, "action1", "none" );
235 DefaultAttr( attr
, "action2", "none" );
236 DefaultAttr( attr
, "tooltiptext1", "" );
237 DefaultAttr( attr
, "tooltiptext2", "" );
238 DefaultAttr( attr
, "help", "" );
240 const BuilderData::Checkbox
checkbox( uniqueId( attr
["id"] ),
241 atoi( attr
["x"] ) + m_xOffset
, atoi( attr
["y"] ) + m_yOffset
,
242 attr
["lefttop"], attr
["rightbottom"],
243 convertBoolean( attr
["xkeepratio"] ),
244 convertBoolean( attr
["ykeepratio"] ), attr
["visible"],
245 attr
["up1"], attr
["down1"], attr
["over1"],
246 attr
["up2"], attr
["down2"], attr
["over2"], attr
["state"],
247 attr
["action1"], attr
["action2"], attr
["tooltiptext1"],
248 attr
["tooltiptext2"], attr
["help"], m_curLayer
, m_curWindowId
,
249 m_curLayoutId
, m_panelStack
.back() );
251 m_pData
->m_listCheckbox
.push_back( checkbox
);
254 else if( rName
== "Font" )
256 RequireAttr( attr
, rName
, "id" );
257 RequireAttr( attr
, rName
, "file" );
258 DefaultAttr( attr
, "size", "12" );
260 const BuilderData::Font
fontData( uniqueId( attr
["id"] ),
261 attr
["file"], atoi( attr
["size"] ) );
262 m_pData
->m_listFont
.push_back( fontData
);
265 else if( rName
== "Group" )
267 DefaultAttr( attr
, "x", "0" );
268 DefaultAttr( attr
, "y", "0" );
270 m_xOffset
+= atoi( attr
["x"] );
271 m_yOffset
+= atoi( attr
["y"] );
272 m_xOffsetList
.push_back( atoi( attr
["x"] ) );
273 m_yOffsetList
.push_back( atoi( attr
["y"] ) );
276 else if( rName
== "Image" )
278 RequireAttr( attr
, rName
, "image" );
279 DefaultAttr( attr
, "id", "none" );
280 DefaultAttr( attr
, "visible", "true" );
281 DefaultAttr( attr
, "x", "0" );
282 DefaultAttr( attr
, "y", "0" );
283 DefaultAttr( attr
, "lefttop", "lefttop" );
284 DefaultAttr( attr
, "rightbottom", "lefttop" );
285 DefaultAttr( attr
, "xkeepratio", "false" );
286 DefaultAttr( attr
, "ykeepratio", "false" );
287 DefaultAttr( attr
, "action", "none" );
288 DefaultAttr( attr
, "action2", "none" );
289 DefaultAttr( attr
, "resize", "mosaic" );
290 DefaultAttr( attr
, "help", "" );
291 DefaultAttr( attr
, "art", "false" );
293 const BuilderData::Image
imageData( uniqueId( attr
["id"] ),
294 atoi( attr
["x"] ) + m_xOffset
, atoi( attr
["y"] ) + m_yOffset
,
295 attr
["lefttop"], attr
["rightbottom"],
296 convertBoolean( attr
["xkeepratio"] ),
297 convertBoolean( attr
["ykeepratio"] ), attr
["visible"],
298 attr
["image"], attr
["action"], attr
["action2"], attr
["resize"],
299 attr
["help"], convertBoolean( attr
["art"] ),
300 m_curLayer
, m_curWindowId
, m_curLayoutId
,
301 m_panelStack
.back() );
303 m_pData
->m_listImage
.push_back( imageData
);
306 else if( rName
== "Layout" )
308 RequireAttr( attr
, rName
, "width" );
309 RequireAttr( attr
, rName
, "height" );
310 DefaultAttr( attr
, "id", "none" );
311 DefaultAttr( attr
, "minwidth", "-1" );
312 DefaultAttr( attr
, "maxwidth", "-1" );
313 DefaultAttr( attr
, "minheight", "-1" );
314 DefaultAttr( attr
, "maxheight", "-1" );
316 m_curLayoutId
= uniqueId( attr
["id"] );
317 const BuilderData::Layout
layout( m_curLayoutId
, atoi( attr
["width"] ),
318 atoi( attr
["height"] ), atoi( attr
["minwidth"] ),
319 atoi( attr
["maxwidth"] ), atoi( attr
["minheight"] ),
320 atoi( attr
["maxheight"] ), m_curWindowId
);
321 m_pData
->m_listLayout
.push_back( layout
);
325 else if( rName
== "Panel" )
327 DefaultAttr( attr
, "x", "0" );
328 DefaultAttr( attr
, "y", "0" );
329 DefaultAttr( attr
, "lefttop", "lefttop" );
330 DefaultAttr( attr
, "rightbottom", "lefttop" );
331 DefaultAttr( attr
, "xkeepratio", "false" );
332 DefaultAttr( attr
, "ykeepratio", "false" );
333 RequireAttr( attr
, rName
, "width" );
334 RequireAttr( attr
, rName
, "height" );
336 string panelId
= uniqueId( "none" );
337 const BuilderData::Panel
panel( panelId
,
338 atoi( attr
["x"] ) + m_xOffset
, atoi( attr
["y"] ) + m_yOffset
,
339 attr
["lefttop"], attr
["rightbottom"],
340 convertBoolean( attr
["xkeepratio"] ),
341 convertBoolean( attr
["ykeepratio"] ),
342 atoi( attr
["width"] ), atoi( attr
["height" ] ),
343 m_curLayer
, m_curWindowId
, m_curLayoutId
, m_panelStack
.back() );
345 m_pData
->m_listPanel
.push_back( panel
);
346 // Add the panel to the stack
347 m_panelStack
.push_back( panelId
);
350 else if( rName
== "Playlist" )
352 RequireAttr( attr
, rName
, "id" );
353 RequireAttr( attr
, rName
, "font" );
354 DefaultAttr( attr
, "visible", "true" );
355 DefaultAttr( attr
, "flat", "true" ); // Only difference here
356 DefaultAttr( attr
, "x", "0" );
357 DefaultAttr( attr
, "y", "0" );
358 DefaultAttr( attr
, "width", "0" );
359 DefaultAttr( attr
, "height", "0" );
360 DefaultAttr( attr
, "lefttop", "lefttop" );
361 DefaultAttr( attr
, "rightbottom", "lefttop" );
362 DefaultAttr( attr
, "xkeepratio", "false" );
363 DefaultAttr( attr
, "ykeepratio", "false" );
364 DefaultAttr( attr
, "bgimage", "none" );
365 DefaultAttr( attr
, "itemimage", "none" );
366 DefaultAttr( attr
, "openimage", "none" );
367 DefaultAttr( attr
, "closedimage", "none" );
368 DefaultAttr( attr
, "fgcolor", "#000000" );
369 DefaultAttr( attr
, "playcolor", "#FF0000" );
370 DefaultAttr( attr
, "bgcolor1", "#FFFFFF" );
371 DefaultAttr( attr
, "bgcolor2", "#FFFFFF" );
372 DefaultAttr( attr
, "selcolor", "#0000FF" );
373 DefaultAttr( attr
, "help", "" );
375 m_curTreeId
= uniqueId( attr
["id"] );
376 const BuilderData::Tree
treeData( m_curTreeId
, atoi( attr
["x"] ) +
377 m_xOffset
, atoi( attr
["y"] ) + m_yOffset
, attr
["visible"],
379 atoi( attr
["width"]), atoi( attr
["height"] ),
380 attr
["lefttop"], attr
["rightbottom"],
381 convertBoolean( attr
["xkeepratio"] ),
382 convertBoolean( attr
["ykeepratio"] ),
383 attr
["font"], "playtree",
384 attr
["bgimage"], attr
["itemimage"],
385 attr
["openimage"], attr
["closedimage"],
390 attr
["selcolor"], attr
["help"],
391 m_curLayer
, m_curWindowId
, m_curLayoutId
, m_panelStack
.back() );
393 m_pData
->m_listTree
.push_back( treeData
);
395 else if( rName
== "Playtree" )
397 RequireAttr( attr
, rName
, "id" );
398 RequireAttr( attr
, rName
, "font" );
399 DefaultAttr( attr
, "visible", "true" );
400 DefaultAttr( attr
, "flat", "false" );
401 DefaultAttr( attr
, "x", "0" );
402 DefaultAttr( attr
, "y", "0" );
403 DefaultAttr( attr
, "width", "0" );
404 DefaultAttr( attr
, "height", "0" );
405 DefaultAttr( attr
, "lefttop", "lefttop" );
406 DefaultAttr( attr
, "rightbottom", "lefttop" );
407 DefaultAttr( attr
, "xkeepratio", "false" );
408 DefaultAttr( attr
, "ykeepratio", "false" );
409 DefaultAttr( attr
, "bgimage", "none" );
410 DefaultAttr( attr
, "itemimage", "none" );
411 DefaultAttr( attr
, "openimage", "none" );
412 DefaultAttr( attr
, "closedimage", "none" );
413 DefaultAttr( attr
, "fgcolor", "#000000" );
414 DefaultAttr( attr
, "playcolor", "#FF0000" );
415 DefaultAttr( attr
, "bgcolor1", "#FFFFFF" );
416 DefaultAttr( attr
, "bgcolor2", "#FFFFFF" );
417 DefaultAttr( attr
, "selcolor", "#0000FF" );
418 DefaultAttr( attr
, "help", "" );
420 m_curTreeId
= uniqueId( attr
["id"] );
421 const BuilderData::Tree
treeData( m_curTreeId
, atoi( attr
["x"] ) +
422 m_xOffset
, atoi( attr
["y"] ) + m_yOffset
, attr
["visible"],
424 atoi( attr
["width"]), atoi( attr
["height"] ),
425 attr
["lefttop"], attr
["rightbottom"],
426 convertBoolean( attr
["xkeepratio"] ),
427 convertBoolean( attr
["ykeepratio"] ),
428 attr
["font"], "playtree",
429 attr
["bgimage"], attr
["itemimage"],
430 attr
["openimage"], attr
["closedimage"],
431 attr
["fgcolor"], attr
["playcolor"],
432 attr
["bgcolor1"], attr
["bgcolor2"],
433 attr
["selcolor"], attr
["help"],
434 m_curLayer
, m_curWindowId
, m_curLayoutId
, m_panelStack
.back() );
436 m_pData
->m_listTree
.push_back( treeData
);
439 else if( rName
== "RadialSlider" )
441 RequireAttr( attr
, rName
, "sequence" );
442 RequireAttr( attr
, rName
, "nbimages" );
443 DefaultAttr( attr
, "id", "none" );
444 DefaultAttr( attr
, "visible", "true" );
445 DefaultAttr( attr
, "x", "0" );
446 DefaultAttr( attr
, "y", "0" );
447 DefaultAttr( attr
, "lefttop", "lefttop" );
448 DefaultAttr( attr
, "rightbottom", "lefttop" );
449 DefaultAttr( attr
, "xkeepratio", "false" );
450 DefaultAttr( attr
, "ykeepratio", "false" );
451 DefaultAttr( attr
, "minangle", "0" );
452 DefaultAttr( attr
, "maxangle", "360" );
453 DefaultAttr( attr
, "value", "none" );
454 DefaultAttr( attr
, "tooltiptext", "" );
455 DefaultAttr( attr
, "help", "" );
457 const BuilderData::RadialSlider
radial( uniqueId( attr
["id"] ),
459 atoi( attr
["x"] ) + m_xOffset
, atoi( attr
["y"] ) + m_yOffset
,
460 attr
["lefttop"], attr
["rightbottom"],
461 convertBoolean( attr
["xkeepratio"] ),
462 convertBoolean( attr
["ykeepratio"] ), attr
["sequence"],
463 atoi( attr
["nbimages"] ), atof( attr
["minangle"] ) * M_PI
/180,
464 atof( attr
["maxangle"] ) * M_PI
/ 180, attr
["value"],
465 attr
["tooltiptext"], attr
["help"], m_curLayer
, m_curWindowId
,
466 m_curLayoutId
, m_panelStack
.back() );
468 m_pData
->m_listRadialSlider
.push_back( radial
);
471 else if( rName
== "Slider" )
473 RequireAttr( attr
, rName
, "up" );
474 RequireAttr( attr
, rName
, "points" );
475 DefaultAttr( attr
, "id", "none" );
476 DefaultAttr( attr
, "visible", "true" );
477 DefaultAttr( attr
, "x", "0" );
478 DefaultAttr( attr
, "y", "0" );
479 DefaultAttr( attr
, "lefttop", "lefttop" );
480 DefaultAttr( attr
, "rightbottom", "lefttop" );
481 DefaultAttr( attr
, "xkeepratio", "false" );
482 DefaultAttr( attr
, "ykeepratio", "false" );
483 DefaultAttr( attr
, "down", "none" );
484 DefaultAttr( attr
, "over", "none" );
485 DefaultAttr( attr
, "thickness", "10" );
486 DefaultAttr( attr
, "value", "none" );
487 DefaultAttr( attr
, "tooltiptext", "" );
488 DefaultAttr( attr
, "help", "" );
490 string newValue
= attr
["value"];
491 if( m_curTreeId
!= "" )
493 // Slider associated to a tree
494 newValue
= "playtree.slider";
496 const BuilderData::Slider
slider( uniqueId( attr
["id"] ),
497 attr
["visible"], atoi( attr
["x"] ) + m_xOffset
,
498 atoi( attr
["y"] ) + m_yOffset
, attr
["lefttop"],
499 attr
["rightbottom"], convertBoolean( attr
["xkeepratio"] ),
500 convertBoolean( attr
["ykeepratio"] ), attr
["up"], attr
["down"],
501 attr
["over"], attr
["points"], atoi( attr
["thickness"] ),
502 newValue
, "none", 0, 0, 0, 0, attr
["tooltiptext"],
503 attr
["help"], m_curLayer
, m_curWindowId
, m_curLayoutId
,
504 m_panelStack
.back() );
506 m_pData
->m_listSlider
.push_back( slider
);
509 else if( rName
== "SliderBackground" )
511 RequireAttr( attr
, rName
, "image" );
512 DefaultAttr( attr
, "nbhoriz", "1" );
513 DefaultAttr( attr
, "nbvert", "1" );
514 DefaultAttr( attr
, "padhoriz", "0" );
515 DefaultAttr( attr
, "padvert", "0" );
517 // Retrieve the current slider data
518 BuilderData::Slider
&slider
= m_pData
->m_listSlider
.back();
520 slider
.m_imageId
= attr
["image"];
521 slider
.m_nbHoriz
= atoi( attr
["nbhoriz"] );
522 slider
.m_nbVert
= atoi( attr
["nbvert"] );
523 slider
.m_padHoriz
= atoi( attr
["padhoriz"] );
524 slider
.m_padVert
= atoi( attr
["padvert"] );
527 else if( rName
== "Text" )
529 RequireAttr( attr
, rName
, "font" );
530 DefaultAttr( attr
, "id", "none" );
531 DefaultAttr( attr
, "visible", "true" );
532 DefaultAttr( attr
, "x", "0" );
533 DefaultAttr( attr
, "y", "0" );
534 DefaultAttr( attr
, "text", "" );
535 DefaultAttr( attr
, "color", "#000000" );
536 DefaultAttr( attr
, "scrolling", "auto" );
537 DefaultAttr( attr
, "alignment", "left" );
538 DefaultAttr( attr
, "width", "0" );
539 DefaultAttr( attr
, "lefttop", "lefttop" );
540 DefaultAttr( attr
, "rightbottom", "lefttop" );
541 DefaultAttr( attr
, "xkeepratio", "false" );
542 DefaultAttr( attr
, "ykeepratio", "false" );
543 DefaultAttr( attr
, "help", "" );
545 const BuilderData::Text
textData( uniqueId( attr
["id"] ),
546 atoi( attr
["x"] ) + m_xOffset
, atoi( attr
["y"] ) + m_yOffset
,
547 attr
["visible"], attr
["font"],
548 attr
["text"], atoi( attr
["width"] ),
549 attr
["lefttop"], attr
["rightbottom"],
550 convertBoolean( attr
["xkeepratio"] ),
551 convertBoolean( attr
["ykeepratio"] ),
552 convertColor( attr
["color"] ),
553 attr
["scrolling"], attr
["alignment"],
554 attr
["help"], m_curLayer
, m_curWindowId
, m_curLayoutId
,
555 m_panelStack
.back() );
557 m_pData
->m_listText
.push_back( textData
);
560 else if( rName
== "Theme" )
562 RequireAttr( attr
, rName
, "version" );
563 DefaultAttr( attr
, "tooltipfont", "defaultfont" );
564 DefaultAttr( attr
, "magnet", "15" );
565 DefaultAttr( attr
, "alpha", "255" );
566 DefaultAttr( attr
, "movealpha", "255" );
569 if( strcmp( attr
["version"], SKINS_DTD_VERSION
) )
571 msg_Err( getIntf(), "bad theme version : %s (you need version %s)",
572 attr
["version"], SKINS_DTD_VERSION
);
576 const BuilderData::Theme
theme( attr
["tooltipfont"],
577 atoi( attr
["magnet"] ),
578 convertInRange( attr
["alpha"], 1, 255, "alpha" ),
579 convertInRange( attr
["movealpha"], 1, 255, "movealpha" ) );
580 m_pData
->m_listTheme
.push_back( theme
);
583 else if( rName
== "ThemeInfo" )
585 DefaultAttr( attr
, "name", "" );
586 DefaultAttr( attr
, "author", "" );
587 DefaultAttr( attr
, "email", "" );
588 DefaultAttr( attr
, "website", "" );
589 msg_Info( getIntf(), "skin: %s author: %s", attr
["name"],
593 else if( rName
== "Video" )
595 DefaultAttr( attr
, "id", "none" );
596 DefaultAttr( attr
, "visible", "true" );
597 DefaultAttr( attr
, "x", "0" );
598 DefaultAttr( attr
, "y", "0" );
599 DefaultAttr( attr
, "width", "0" );
600 DefaultAttr( attr
, "height", "0" );
601 DefaultAttr( attr
, "lefttop", "lefttop" );
602 DefaultAttr( attr
, "rightbottom", "lefttop" );
603 DefaultAttr( attr
, "xkeepratio", "false" );
604 DefaultAttr( attr
, "ykeepratio", "false" );
605 DefaultAttr( attr
, "autoresize", "false" );
606 DefaultAttr( attr
, "help", "" );
608 const BuilderData::Video
videoData( uniqueId( attr
["id"] ),
609 atoi( attr
["x"] ) + m_xOffset
, atoi( attr
["y"] ) + m_yOffset
,
610 atoi( attr
["width"] ), atoi( attr
["height" ]),
611 attr
["lefttop"], attr
["rightbottom"],
612 convertBoolean( attr
["xkeepratio"] ),
613 convertBoolean( attr
["ykeepratio"] ),
614 attr
["visible"], convertBoolean( attr
["autoresize"] ),
615 attr
["help"], m_curLayer
, m_curWindowId
, m_curLayoutId
,
616 m_panelStack
.back() );
618 m_pData
->m_listVideo
.push_back( videoData
);
621 else if( rName
== "Window" )
623 DefaultAttr( attr
, "id", "none" );
624 DefaultAttr( attr
, "visible", "true" );
625 DefaultAttr( attr
, "x", "0" );
626 DefaultAttr( attr
, "y", "0" );
627 DefaultAttr( attr
, "dragdrop", "true" );
628 DefaultAttr( attr
, "playondrop", "true" );
630 m_curWindowId
= uniqueId( attr
["id"] );
631 const BuilderData::Window
window( m_curWindowId
,
632 atoi( attr
["x"] ) + m_xOffset
, atoi( attr
["y"] ) + m_yOffset
,
633 convertBoolean( attr
["visible"] ),
634 convertBoolean( attr
["dragdrop"] ),
635 convertBoolean( attr
["playondrop"] ) );
636 m_pData
->m_listWindow
.push_back( window
);
642 void SkinParser::handleEndElement( const string
&rName
)
644 if( rName
== "Group" )
646 m_xOffset
-= m_xOffsetList
.back();
647 m_yOffset
-= m_yOffsetList
.back();
648 m_xOffsetList
.pop_back();
649 m_yOffsetList
.pop_back();
651 else if( rName
== "Playtree" || rName
== "Playlist" )
655 else if( rName
== "Popup" )
658 m_popupPosList
.pop_back();
660 else if( rName
== "Panel" )
662 m_panelStack
.pop_back();
667 bool SkinParser::convertBoolean( const char *value
) const
669 return strcmp( value
, "true" ) == 0;
673 int SkinParser::convertColor( const char *transcolor
)
675 // TODO: move to the builder
676 unsigned long iRed
, iGreen
, iBlue
;
677 iRed
= iGreen
= iBlue
= 0;
678 sscanf( transcolor
, "#%2lX%2lX%2lX", &iRed
, &iGreen
, &iBlue
);
679 return ( iRed
<< 16 | iGreen
<< 8 | iBlue
);
683 int SkinParser::convertInRange( const char *value
, int minValue
, int maxValue
,
684 const string
&rAttribute
) const
686 int intValue
= atoi( value
);
688 if( intValue
< minValue
)
690 msg_Warn( getIntf(), "value of \"%s\" attribute (%i) is out of the "
691 "expected range [%i, %i], using %i instead",
692 rAttribute
.c_str(), intValue
, minValue
, maxValue
, minValue
);
695 else if( intValue
> maxValue
)
697 msg_Warn( getIntf(), "value of \"%s\" attribute (%i) is out of the "
698 "expected range [%i, %i], using %i instead",
699 rAttribute
.c_str(), intValue
, minValue
, maxValue
, maxValue
);
709 const string
SkinParser::generateId() const
714 snprintf( genId
, 4, "%i", i
++ );
716 string base
= "_ReservedId_" + (string
)genId
;
722 const string
SkinParser::uniqueId( const string
&id
)
726 if( m_idSet
.find( id
) != m_idSet
.end() )
728 // The id was already used
731 msg_Warn( getIntf(), "non-unique id: %s", id
.c_str() );
733 newId
= generateId();
737 // OK, this is a new id
741 // Add the id to the set
742 m_idSet
.insert( newId
);