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", "" );
292 const BuilderData::Image imageData( uniqueId( attr["id"] ),
293 atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
294 attr["lefttop"], attr["rightbottom"],
295 convertBoolean( attr["xkeepratio"] ),
296 convertBoolean( attr["ykeepratio"] ), attr["visible"],
297 attr["image"], attr["action"], attr["action2"], attr["resize"],
298 attr["help"], m_curLayer, m_curWindowId, m_curLayoutId,
299 m_panelStack.back() );
301 m_pData->m_listImage.push_back( imageData );
304 else if( rName == "Layout" )
306 RequireAttr( attr, rName, "width" );
307 RequireAttr( attr, rName, "height" );
308 DefaultAttr( attr, "id", "none" );
309 DefaultAttr( attr, "minwidth", "-1" );
310 DefaultAttr( attr, "maxwidth", "-1" );
311 DefaultAttr( attr, "minheight", "-1" );
312 DefaultAttr( attr, "maxheight", "-1" );
314 m_curLayoutId = uniqueId( attr["id"] );
315 const BuilderData::Layout layout( m_curLayoutId, atoi( attr["width"] ),
316 atoi( attr["height"] ), atoi( attr["minwidth"] ),
317 atoi( attr["maxwidth"] ), atoi( attr["minheight"] ),
318 atoi( attr["maxheight"] ), m_curWindowId );
319 m_pData->m_listLayout.push_back( layout );
323 else if( rName == "Panel" )
325 DefaultAttr( attr, "x", "0" );
326 DefaultAttr( attr, "y", "0" );
327 DefaultAttr( attr, "lefttop", "lefttop" );
328 DefaultAttr( attr, "rightbottom", "lefttop" );
329 DefaultAttr( attr, "xkeepratio", "false" );
330 DefaultAttr( attr, "ykeepratio", "false" );
331 RequireAttr( attr, rName, "width" );
332 RequireAttr( attr, rName, "height" );
334 string panelId = uniqueId( "none" );
335 const BuilderData::Panel panel( panelId,
336 atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
337 attr["lefttop"], attr["rightbottom"],
338 convertBoolean( attr["xkeepratio"] ),
339 convertBoolean( attr["ykeepratio"] ),
340 atoi( attr["width"] ), atoi( attr["height" ] ),
341 m_curLayer, m_curWindowId, m_curLayoutId, m_panelStack.back() );
343 m_pData->m_listPanel.push_back( panel );
344 // Add the panel to the stack
345 m_panelStack.push_back( panelId );
348 else if( rName == "Playlist" )
350 RequireAttr( attr, rName, "id" );
351 RequireAttr( attr, rName, "font" );
352 DefaultAttr( attr, "visible", "true" );
353 DefaultAttr( attr, "flat", "true" ); // Only difference here
354 DefaultAttr( attr, "x", "0" );
355 DefaultAttr( attr, "y", "0" );
356 DefaultAttr( attr, "width", "0" );
357 DefaultAttr( attr, "height", "0" );
358 DefaultAttr( attr, "lefttop", "lefttop" );
359 DefaultAttr( attr, "rightbottom", "lefttop" );
360 DefaultAttr( attr, "xkeepratio", "false" );
361 DefaultAttr( attr, "ykeepratio", "false" );
362 DefaultAttr( attr, "bgimage", "none" );
363 DefaultAttr( attr, "itemimage", "none" );
364 DefaultAttr( attr, "openimage", "none" );
365 DefaultAttr( attr, "closedimage", "none" );
366 DefaultAttr( attr, "fgcolor", "#000000" );
367 DefaultAttr( attr, "playcolor", "#FF0000" );
368 DefaultAttr( attr, "bgcolor1", "#FFFFFF" );
369 DefaultAttr( attr, "bgcolor2", "#FFFFFF" );
370 DefaultAttr( attr, "selcolor", "#0000FF" );
371 DefaultAttr( attr, "help", "" );
373 m_curTreeId = uniqueId( attr["id"] );
374 const BuilderData::Tree treeData( m_curTreeId, atoi( attr["x"] ) +
375 m_xOffset, atoi( attr["y"] ) + m_yOffset, attr["visible"],
377 atoi( attr["width"]), atoi( attr["height"] ),
378 attr["lefttop"], attr["rightbottom"],
379 convertBoolean( attr["xkeepratio"] ),
380 convertBoolean( attr["ykeepratio"] ),
381 attr["font"], "playtree",
382 attr["bgimage"], attr["itemimage"],
383 attr["openimage"], attr["closedimage"],
388 attr["selcolor"], attr["help"],
389 m_curLayer, m_curWindowId, m_curLayoutId, m_panelStack.back() );
391 m_pData->m_listTree.push_back( treeData );
393 else if( rName == "Playtree" )
395 RequireAttr( attr, rName, "id" );
396 RequireAttr( attr, rName, "font" );
397 DefaultAttr( attr, "visible", "true" );
398 DefaultAttr( attr, "flat", "false" );
399 DefaultAttr( attr, "x", "0" );
400 DefaultAttr( attr, "y", "0" );
401 DefaultAttr( attr, "width", "0" );
402 DefaultAttr( attr, "height", "0" );
403 DefaultAttr( attr, "lefttop", "lefttop" );
404 DefaultAttr( attr, "rightbottom", "lefttop" );
405 DefaultAttr( attr, "xkeepratio", "false" );
406 DefaultAttr( attr, "ykeepratio", "false" );
407 DefaultAttr( attr, "bgimage", "none" );
408 DefaultAttr( attr, "itemimage", "none" );
409 DefaultAttr( attr, "openimage", "none" );
410 DefaultAttr( attr, "closedimage", "none" );
411 DefaultAttr( attr, "fgcolor", "#000000" );
412 DefaultAttr( attr, "playcolor", "#FF0000" );
413 DefaultAttr( attr, "bgcolor1", "#FFFFFF" );
414 DefaultAttr( attr, "bgcolor2", "#FFFFFF" );
415 DefaultAttr( attr, "selcolor", "#0000FF" );
416 DefaultAttr( attr, "help", "" );
418 m_curTreeId = uniqueId( attr["id"] );
419 const BuilderData::Tree treeData( m_curTreeId, atoi( attr["x"] ) +
420 m_xOffset, atoi( attr["y"] ) + m_yOffset, attr["visible"],
422 atoi( attr["width"]), atoi( attr["height"] ),
423 attr["lefttop"], attr["rightbottom"],
424 convertBoolean( attr["xkeepratio"] ),
425 convertBoolean( attr["ykeepratio"] ),
426 attr["font"], "playtree",
427 attr["bgimage"], attr["itemimage"],
428 attr["openimage"], attr["closedimage"],
429 attr["fgcolor"], attr["playcolor"],
430 attr["bgcolor1"], attr["bgcolor2"],
431 attr["selcolor"], attr["help"],
432 m_curLayer, m_curWindowId, m_curLayoutId, m_panelStack.back() );
434 m_pData->m_listTree.push_back( treeData );
437 else if( rName == "RadialSlider" )
439 RequireAttr( attr, rName, "sequence" );
440 RequireAttr( attr, rName, "nbimages" );
441 DefaultAttr( attr, "id", "none" );
442 DefaultAttr( attr, "visible", "true" );
443 DefaultAttr( attr, "x", "0" );
444 DefaultAttr( attr, "y", "0" );
445 DefaultAttr( attr, "lefttop", "lefttop" );
446 DefaultAttr( attr, "rightbottom", "lefttop" );
447 DefaultAttr( attr, "xkeepratio", "false" );
448 DefaultAttr( attr, "ykeepratio", "false" );
449 DefaultAttr( attr, "minangle", "0" );
450 DefaultAttr( attr, "maxangle", "360" );
451 DefaultAttr( attr, "value", "none" );
452 DefaultAttr( attr, "tooltiptext", "" );
453 DefaultAttr( attr, "help", "" );
455 const BuilderData::RadialSlider radial( uniqueId( attr["id"] ),
457 atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
458 attr["lefttop"], attr["rightbottom"],
459 convertBoolean( attr["xkeepratio"] ),
460 convertBoolean( attr["ykeepratio"] ), attr["sequence"],
461 atoi( attr["nbImages"] ), atof( attr["minAngle"] ) * M_PI /180,
462 atof( attr["maxAngle"] ) * M_PI / 180, attr["value"],
463 attr["tooltiptext"], attr["help"], m_curLayer, m_curWindowId,
464 m_curLayoutId, m_panelStack.back() );
466 m_pData->m_listRadialSlider.push_back( radial );
469 else if( rName == "Slider" )
471 RequireAttr( attr, rName, "up" );
472 RequireAttr( attr, rName, "points" );
473 DefaultAttr( attr, "id", "none" );
474 DefaultAttr( attr, "visible", "true" );
475 DefaultAttr( attr, "x", "0" );
476 DefaultAttr( attr, "y", "0" );
477 DefaultAttr( attr, "lefttop", "lefttop" );
478 DefaultAttr( attr, "rightbottom", "lefttop" );
479 DefaultAttr( attr, "xkeepratio", "false" );
480 DefaultAttr( attr, "ykeepratio", "false" );
481 DefaultAttr( attr, "down", "none" );
482 DefaultAttr( attr, "over", "none" );
483 DefaultAttr( attr, "thickness", "10" );
484 DefaultAttr( attr, "value", "none" );
485 DefaultAttr( attr, "tooltiptext", "" );
486 DefaultAttr( attr, "help", "" );
488 string newValue = attr["value"];
489 if( m_curTreeId != "" )
491 // Slider associated to a tree
492 newValue = "playtree.slider";
494 const BuilderData::Slider slider( uniqueId( attr["id"] ),
495 attr["visible"], atoi( attr["x"] ) + m_xOffset,
496 atoi( attr["y"] ) + m_yOffset, attr["lefttop"],
497 attr["rightbottom"], convertBoolean( attr["xkeepratio"] ),
498 convertBoolean( attr["ykeepratio"] ), attr["up"], attr["down"],
499 attr["over"], attr["points"], atoi( attr["thickness"] ),
500 newValue, "none", 0, 0, 0, 0, attr["tooltiptext"],
501 attr["help"], m_curLayer, m_curWindowId, m_curLayoutId,
502 m_panelStack.back() );
504 m_pData->m_listSlider.push_back( slider );
507 else if( rName == "SliderBackground" )
509 RequireAttr( attr, rName, "image" );
510 DefaultAttr( attr, "nbhoriz", "1" );
511 DefaultAttr( attr, "nbvert", "1" );
512 DefaultAttr( attr, "padhoriz", "0" );
513 DefaultAttr( attr, "padvert", "0" );
515 // Retrieve the current slider data
516 BuilderData::Slider &slider = m_pData->m_listSlider.back();
518 slider.m_imageId = attr["image"];
519 slider.m_nbHoriz = atoi( attr["nbhoriz"] );
520 slider.m_nbVert = atoi( attr["nbvert"] );
521 slider.m_padHoriz = atoi( attr["padhoriz"] );
522 slider.m_padVert = atoi( attr["padvert"] );
525 else if( rName == "Text" )
527 RequireAttr( attr, rName, "font" );
528 DefaultAttr( attr, "id", "none" );
529 DefaultAttr( attr, "visible", "true" );
530 DefaultAttr( attr, "x", "0" );
531 DefaultAttr( attr, "y", "0" );
532 DefaultAttr( attr, "text", "" );
533 DefaultAttr( attr, "color", "#000000" );
534 DefaultAttr( attr, "scrolling", "auto" );
535 DefaultAttr( attr, "alignment", "left" );
536 DefaultAttr( attr, "width", "0" );
537 DefaultAttr( attr, "lefttop", "lefttop" );
538 DefaultAttr( attr, "rightbottom", "lefttop" );
539 DefaultAttr( attr, "xkeepratio", "false" );
540 DefaultAttr( attr, "ykeepratio", "false" );
541 DefaultAttr( attr, "help", "" );
543 const BuilderData::Text textData( uniqueId( attr["id"] ),
544 atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
545 attr["visible"], attr["font"],
546 attr["text"], atoi( attr["width"] ),
547 attr["lefttop"], attr["rightbottom"],
548 convertBoolean( attr["xkeepratio"] ),
549 convertBoolean( attr["ykeepratio"] ),
550 convertColor( attr["color"] ),
551 attr["scrolling"], attr["alignment"],
552 attr["help"], m_curLayer, m_curWindowId, m_curLayoutId,
553 m_panelStack.back() );
555 m_pData->m_listText.push_back( textData );
558 else if( rName == "Theme" )
560 RequireAttr( attr, rName, "version" );
561 DefaultAttr( attr, "tooltipfont", "defaultfont" );
562 DefaultAttr( attr, "magnet", "15" );
563 DefaultAttr( attr, "alpha", "255" );
564 DefaultAttr( attr, "movealpha", "255" );
567 if( strcmp( attr["version"], SKINS_DTD_VERSION ) )
569 msg_Err( getIntf(), "bad theme version : %s (you need version %s)",
570 attr["version"], SKINS_DTD_VERSION );
574 const BuilderData::Theme theme( attr["tooltipfont"],
575 atoi( attr["magnet"] ),
576 convertInRange( attr["alpha"], 1, 255, "alpha" ),
577 convertInRange( attr["movealpha"], 1, 255, "movealpha" ) );
578 m_pData->m_listTheme.push_back( theme );
581 else if( rName == "ThemeInfo" )
583 DefaultAttr( attr, "name", "" );
584 DefaultAttr( attr, "author", "" );
585 DefaultAttr( attr, "email", "" );
586 DefaultAttr( attr, "website", "" );
587 msg_Info( getIntf(), "skin: %s author: %s", attr["name"],
591 else if( rName == "Video" )
593 DefaultAttr( attr, "id", "none" );
594 DefaultAttr( attr, "visible", "true" );
595 DefaultAttr( attr, "x", "0" );
596 DefaultAttr( attr, "y", "0" );
597 DefaultAttr( attr, "width", "0" );
598 DefaultAttr( attr, "height", "0" );
599 DefaultAttr( attr, "lefttop", "lefttop" );
600 DefaultAttr( attr, "rightbottom", "lefttop" );
601 DefaultAttr( attr, "xkeepratio", "false" );
602 DefaultAttr( attr, "ykeepratio", "false" );
603 DefaultAttr( attr, "autoresize", "false" );
604 DefaultAttr( attr, "help", "" );
606 const BuilderData::Video videoData( uniqueId( attr["id"] ),
607 atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
608 atoi( attr["width"] ), atoi( attr["height" ]),
609 attr["lefttop"], attr["rightbottom"],
610 convertBoolean( attr["xkeepratio"] ),
611 convertBoolean( attr["ykeepratio"] ),
612 attr["visible"], convertBoolean( attr["autoresize"] ),
613 attr["help"], m_curLayer, m_curWindowId, m_curLayoutId,
614 m_panelStack.back() );
616 m_pData->m_listVideo.push_back( videoData );
619 else if( rName == "Window" )
621 DefaultAttr( attr, "id", "none" );
622 DefaultAttr( attr, "visible", "true" );
623 DefaultAttr( attr, "x", "0" );
624 DefaultAttr( attr, "y", "0" );
625 DefaultAttr( attr, "dragdrop", "true" );
626 DefaultAttr( attr, "playondrop", "true" );
628 m_curWindowId = uniqueId( attr["id"] );
629 const BuilderData::Window window( m_curWindowId,
630 atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
631 convertBoolean( attr["visible"] ),
632 convertBoolean( attr["dragdrop"] ),
633 convertBoolean( attr["playondrop"] ) );
634 m_pData->m_listWindow.push_back( window );
640 void SkinParser::handleEndElement( const string &rName )
642 if( rName == "Group" )
644 m_xOffset -= m_xOffsetList.back();
645 m_yOffset -= m_yOffsetList.back();
646 m_xOffsetList.pop_back();
647 m_yOffsetList.pop_back();
649 else if( rName == "Playtree" || rName == "Playlist" )
653 else if( rName == "Popup" )
656 m_popupPosList.pop_back();
658 else if( rName == "Panel" )
660 m_panelStack.pop_back();
665 bool SkinParser::convertBoolean( const char *value ) const
667 return strcmp( value, "true" ) == 0;
671 int SkinParser::convertColor( const char *transcolor )
673 // TODO: move to the builder
674 unsigned long iRed, iGreen, iBlue;
675 iRed = iGreen = iBlue = 0;
676 sscanf( transcolor, "#%2lX%2lX%2lX", &iRed, &iGreen, &iBlue );
677 return ( iRed << 16 | iGreen << 8 | iBlue );
681 int SkinParser::convertInRange( const char *value, int minValue, int maxValue,
682 const string &rAttribute ) const
684 int intValue = atoi( value );
686 if( intValue < minValue )
688 msg_Warn( getIntf(), "value of \"%s\" attribute (%i) is out of the "
689 "expected range [%i, %i], using %i instead",
690 rAttribute.c_str(), intValue, minValue, maxValue, minValue );
693 else if( intValue > maxValue )
695 msg_Warn( getIntf(), "value of \"%s\" attribute (%i) is out of the "
696 "expected range [%i, %i], using %i instead",
697 rAttribute.c_str(), intValue, minValue, maxValue, maxValue );
707 const string SkinParser::generateId() const
712 snprintf( genId, 4, "%i", i++ );
714 string base = "_ReservedId_" + (string)genId;
720 const string SkinParser::uniqueId( const string &id )
724 if( m_idSet.find( id ) != m_idSet.end() )
726 // The id was already used
729 msg_Warn( getIntf(), "non-unique id: %s", id.c_str() );
731 newId = generateId();
735 // OK, this is a new id
739 // Add the id to the set
740 m_idSet.insert( newId );