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, BuilderData *pData ):
31 XMLParser( pIntf, rFileName ), 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 SkinParser subParser( getIntf(), fullPath.c_str(), m_path, m_pData );
83 else if( rName == "IniFile" )
85 RequireAttr( attr, rName, "id" );
86 RequireAttr( attr, rName, "file" );
88 const BuilderData::IniFile iniFile( uniqueId( attr["id"] ),
90 m_pData->m_listIniFile.push_back( iniFile );
93 else if( rName == "Anchor" )
95 RequireAttr( attr, rName, "priority" );
96 DefaultAttr( attr, "x", "0" );
97 DefaultAttr( attr, "y", "0" );
98 DefaultAttr( attr, "lefttop", "lefttop" );
99 DefaultAttr( attr, "points", "(0,0)" );
100 DefaultAttr( attr, "range", "10" );
102 int refWidth = getRefWidth( false );
103 int refHeight = getRefHeight( false );
104 int x = getDimension( attr["x"], refWidth );
105 int y = getDimension( attr["y"], refHeight );
106 const BuilderData::Anchor anchor( x + m_xOffset,
107 y + m_yOffset, attr["lefttop"],
108 atoi( attr["range"] ), atoi( attr["priority"] ),
109 attr["points"], m_curLayoutId );
110 m_pData->m_listAnchor.push_back( anchor );
113 else if( rName == "Bitmap" )
115 RequireAttr( attr, rName, "id" );
116 RequireAttr( attr, rName, "file" );
117 RequireAttr( attr, rName, "alphacolor" );
118 DefaultAttr( attr, "nbframes", "1" );
119 DefaultAttr( attr, "fps", "4" );
120 DefaultAttr( attr, "loop", "0" );
122 m_curBitmapId = uniqueId( attr["id"] );
123 const BuilderData::Bitmap bitmap( m_curBitmapId,
124 attr["file"], convertColor( attr["alphacolor"] ),
125 atoi( attr["nbframes"] ), atoi( attr["fps"] ),
126 atoi( attr["loop"] ) );
127 m_pData->m_listBitmap.push_back( bitmap );
130 else if( rName == "SubBitmap" )
132 RequireAttr( attr, rName, "id" );
133 RequireAttr( attr, rName, "x" );
134 RequireAttr( attr, rName, "y" );
135 RequireAttr( attr, rName, "width" );
136 RequireAttr( attr, rName, "height" );
137 DefaultAttr( attr, "nbframes", "1" );
138 DefaultAttr( attr, "fps", "4" );
139 DefaultAttr( attr, "loop", "0" );
141 const BuilderData::SubBitmap bitmap( uniqueId( attr["id"] ),
142 m_curBitmapId, atoi( attr["x"] ), atoi( attr["y"] ),
143 atoi( attr["width"] ), atoi( attr["height"] ),
144 atoi( attr["nbframes"] ), atoi( attr["fps"] ),
145 atoi( attr["loop"] ) );
146 m_pData->m_listSubBitmap.push_back( bitmap );
149 else if( rName == "BitmapFont" )
151 RequireAttr( attr, rName, "id" );
152 RequireAttr( attr, rName, "file" );
153 DefaultAttr( attr, "type", "digits" );
155 const BuilderData::BitmapFont font( uniqueId( attr["id"] ),
156 attr["file"], attr["type"] );
157 m_pData->m_listBitmapFont.push_back( font );
160 else if( rName == "PopupMenu" )
162 RequireAttr( attr, rName, "id" );
164 m_popupPosList.push_back(0);
165 m_curPopupId = uniqueId( attr["id"] );
166 const BuilderData::PopupMenu popup( m_curPopupId );
167 m_pData->m_listPopupMenu.push_back( popup );
170 else if( rName == "MenuItem" )
172 RequireAttr( attr, rName, "label" );
173 DefaultAttr( attr, "action", "none" );
175 const BuilderData::MenuItem item( attr["label"], attr["action"],
176 m_popupPosList.back(),
178 m_pData->m_listMenuItem.push_back( item );
179 m_popupPosList.back()++;
182 else if( rName == "MenuSeparator" )
184 const BuilderData::MenuSeparator sep( m_popupPosList.back(),
186 m_pData->m_listMenuSeparator.push_back( sep );
187 m_popupPosList.back()++;
190 else if( rName == "Button" )
192 RequireAttr( attr, rName, "up" );
193 DefaultAttr( attr, "id", "none" );
194 DefaultAttr( attr, "visible", "true" );
195 DefaultAttr( attr, "x", "0" );
196 DefaultAttr( attr, "y", "0" );
197 DefaultAttr( attr, "lefttop", "lefttop" );
198 DefaultAttr( attr, "rightbottom", "lefttop" );
199 DefaultAttr( attr, "xkeepratio", "false" );
200 DefaultAttr( attr, "ykeepratio", "false" );
201 DefaultAttr( attr, "down", "none" );
202 DefaultAttr( attr, "over", "none" );
203 DefaultAttr( attr, "action", "none" );
204 DefaultAttr( attr, "tooltiptext", "" );
205 DefaultAttr( attr, "help", "" );
207 int refWidth = getRefWidth( false );
208 int refHeight = getRefHeight( false );
209 int x = getDimension( attr["x"], refWidth );
210 int y = getDimension( attr["y"], refHeight );
211 const BuilderData::Button button( uniqueId( attr["id"] ),
212 x + m_xOffset, y + m_yOffset,
213 attr["lefttop"], attr["rightbottom"],
214 convertBoolean( attr["xkeepratio"] ),
215 convertBoolean( attr["ykeepratio"] ), attr["visible"],
216 attr["up"], attr["down"], attr["over"], attr["action"],
217 attr["tooltiptext"], attr["help"],
218 m_curLayer, m_curWindowId, m_curLayoutId, m_panelStack.back() );
220 m_pData->m_listButton.push_back( button );
223 else if( rName == "Checkbox" )
225 RequireAttr( attr, rName, "up1" );
226 RequireAttr( attr, rName, "up2" );
227 RequireAttr( attr, rName, "state" );
228 DefaultAttr( attr, "id", "none" );
229 DefaultAttr( attr, "visible", "true" );
230 DefaultAttr( attr, "x", "0" );
231 DefaultAttr( attr, "y", "0" );
232 DefaultAttr( attr, "lefttop", "lefttop" );
233 DefaultAttr( attr, "rightbottom", "lefttop" );
234 DefaultAttr( attr, "xkeepratio", "false" );
235 DefaultAttr( attr, "ykeepratio", "false" );
236 DefaultAttr( attr, "down1", "none" );
237 DefaultAttr( attr, "over1", "none" );
238 DefaultAttr( attr, "down2", "none" );
239 DefaultAttr( attr, "over2", "none" );
240 DefaultAttr( attr, "action1", "none" );
241 DefaultAttr( attr, "action2", "none" );
242 DefaultAttr( attr, "tooltiptext1", "" );
243 DefaultAttr( attr, "tooltiptext2", "" );
244 DefaultAttr( attr, "help", "" );
246 int refWidth = getRefWidth( false );
247 int refHeight = getRefHeight( false );
248 int x = getDimension( attr["x"], refWidth );
249 int y = getDimension( attr["y"], refHeight );
250 const BuilderData::Checkbox checkbox( uniqueId( attr["id"] ),
251 x + m_xOffset, y + m_yOffset,
252 attr["lefttop"], attr["rightbottom"],
253 convertBoolean( attr["xkeepratio"] ),
254 convertBoolean( attr["ykeepratio"] ), attr["visible"],
255 attr["up1"], attr["down1"], attr["over1"],
256 attr["up2"], attr["down2"], attr["over2"], attr["state"],
257 attr["action1"], attr["action2"], attr["tooltiptext1"],
258 attr["tooltiptext2"], attr["help"], m_curLayer, m_curWindowId,
259 m_curLayoutId, m_panelStack.back() );
261 m_pData->m_listCheckbox.push_back( checkbox );
264 else if( rName == "Font" )
266 RequireAttr( attr, rName, "id" );
267 RequireAttr( attr, rName, "file" );
268 DefaultAttr( attr, "size", "12" );
270 const BuilderData::Font fontData( uniqueId( attr["id"] ),
271 attr["file"], atoi( attr["size"] ) );
272 m_pData->m_listFont.push_back( fontData );
275 else if( rName == "Group" )
277 DefaultAttr( attr, "x", "0" );
278 DefaultAttr( attr, "y", "0" );
280 m_xOffset += atoi( attr["x"] );
281 m_yOffset += atoi( attr["y"] );
282 m_xOffsetList.push_back( atoi( attr["x"] ) );
283 m_yOffsetList.push_back( atoi( attr["y"] ) );
286 else if( rName == "Image" )
288 RequireAttr( attr, rName, "image" );
289 DefaultAttr( attr, "id", "none" );
290 DefaultAttr( attr, "visible", "true" );
291 DefaultAttr( attr, "x", "0" );
292 DefaultAttr( attr, "y", "0" );
293 DefaultAttr( attr, "width", "-1" );
294 DefaultAttr( attr, "height", "-1" );
295 DefaultAttr( attr, "lefttop", "lefttop" );
296 DefaultAttr( attr, "rightbottom", "lefttop" );
297 DefaultAttr( attr, "xkeepratio", "false" );
298 DefaultAttr( attr, "ykeepratio", "false" );
299 DefaultAttr( attr, "action", "none" );
300 DefaultAttr( attr, "action2", "none" );
301 DefaultAttr( attr, "resize", "mosaic" );
302 DefaultAttr( attr, "help", "" );
303 DefaultAttr( attr, "art", "false" );
305 int refWidth = getRefWidth( false );
306 int refHeight = getRefHeight( false );
307 int x = getDimension( attr["x"], refWidth );
308 int y = getDimension( attr["y"], refHeight );
309 int width = getDimension( attr["width"], refWidth );
310 int height = getDimension( attr["height"], refHeight );
311 const BuilderData::Image imageData( uniqueId( attr["id"] ),
312 x + m_xOffset, y + m_yOffset, width, height,
313 attr["lefttop"], attr["rightbottom"],
314 convertBoolean( attr["xkeepratio"] ),
315 convertBoolean( attr["ykeepratio"] ), attr["visible"],
316 attr["image"], attr["action"], attr["action2"], attr["resize"],
317 attr["help"], convertBoolean( attr["art"] ),
318 m_curLayer, m_curWindowId, m_curLayoutId,
319 m_panelStack.back() );
321 m_pData->m_listImage.push_back( imageData );
324 else if( rName == "Layout" )
326 RequireAttr( attr, rName, "width" );
327 RequireAttr( attr, rName, "height" );
328 DefaultAttr( attr, "id", "none" );
329 DefaultAttr( attr, "minwidth", "-1" );
330 DefaultAttr( attr, "maxwidth", "-1" );
331 DefaultAttr( attr, "minheight", "-1" );
332 DefaultAttr( attr, "maxheight", "-1" );
334 int refWidth = getRefWidth( true );
335 int refHeight = getRefHeight( true );
336 int width = getDimension( attr["width"], refWidth );
337 int height = getDimension( attr["height"], refHeight );
339 m_curLayoutId = uniqueId( attr["id"] );
340 const BuilderData::Layout layout( m_curLayoutId,
342 getDimension( attr["minwidth"], refWidth ),
343 getDimension( attr["maxwidth"], refWidth ),
344 getDimension( attr["minheight"], refHeight ),
345 getDimension( attr["maxheight"], refHeight ),
348 updateWindowPos( width, height );
349 m_pData->m_listLayout.push_back( layout );
353 else if( rName == "Panel" )
355 DefaultAttr( attr, "x", "0" );
356 DefaultAttr( attr, "y", "0" );
357 DefaultAttr( attr, "lefttop", "lefttop" );
358 DefaultAttr( attr, "rightbottom", "lefttop" );
359 DefaultAttr( attr, "xkeepratio", "false" );
360 DefaultAttr( attr, "ykeepratio", "false" );
361 RequireAttr( attr, rName, "width" );
362 RequireAttr( attr, rName, "height" );
363 DefaultAttr( attr, "position", "-1" );
364 DefaultAttr( attr, "xoffset", "0" );
365 DefaultAttr( attr, "yoffset", "0" );
366 DefaultAttr( attr, "xmargin", "0" );
367 DefaultAttr( attr, "ymargin", "0" );
369 int refWidth = getRefWidth( false );
370 int refHeight = getRefHeight( false );
372 int x = getDimension( attr["x"], refWidth );
373 int y = getDimension( attr["y"], refHeight );
374 int width = getDimension( attr["width"], refWidth );
375 int height = getDimension( attr["height"], refHeight );
376 convertPosition( attr["position"],
377 attr["xoffset"], attr["yoffset"],
378 attr["xmargin"], attr["ymargin"],
379 width, height, refWidth, refHeight, &x, &y );
381 string panelId = uniqueId( "none" );
382 const BuilderData::Panel panel( panelId,
383 x + m_xOffset, y + m_yOffset,
384 attr["lefttop"], attr["rightbottom"],
385 convertBoolean( attr["xkeepratio"] ),
386 convertBoolean( attr["ykeepratio"] ),
388 m_curLayer, m_curWindowId, m_curLayoutId, m_panelStack.back() );
390 m_pData->m_listPanel.push_back( panel );
391 // Add the panel to the stack
392 m_panelStack.push_back( panelId );
395 else if( rName == "Playlist" )
397 RequireAttr( attr, rName, "id" );
398 RequireAttr( attr, rName, "font" );
399 DefaultAttr( attr, "visible", "true" );
400 DefaultAttr( attr, "flat", "true" ); // Only difference here
401 DefaultAttr( attr, "x", "0" );
402 DefaultAttr( attr, "y", "0" );
403 DefaultAttr( attr, "width", "0" );
404 DefaultAttr( attr, "height", "0" );
405 DefaultAttr( attr, "position", "-1" );
406 DefaultAttr( attr, "xoffset", "0" );
407 DefaultAttr( attr, "yoffset", "0" );
408 DefaultAttr( attr, "xmargin", "0" );
409 DefaultAttr( attr, "ymargin", "0" );
410 DefaultAttr( attr, "lefttop", "lefttop" );
411 DefaultAttr( attr, "rightbottom", "lefttop" );
412 DefaultAttr( attr, "xkeepratio", "false" );
413 DefaultAttr( attr, "ykeepratio", "false" );
414 DefaultAttr( attr, "bgimage", "none" );
415 DefaultAttr( attr, "itemimage", "none" );
416 DefaultAttr( attr, "openimage", "none" );
417 DefaultAttr( attr, "closedimage", "none" );
418 DefaultAttr( attr, "fgcolor", "#000000" );
419 DefaultAttr( attr, "playcolor", "#FF0000" );
420 DefaultAttr( attr, "bgcolor1", "#FFFFFF" );
421 DefaultAttr( attr, "bgcolor2", "#FFFFFF" );
422 DefaultAttr( attr, "selcolor", "#0000FF" );
423 DefaultAttr( attr, "help", "" );
425 int refWidth = getRefWidth( false );
426 int refHeight = getRefHeight( false );
428 int x = getDimension( attr["x"], refWidth );
429 int y = getDimension( attr["y"], refHeight );
430 int width = getDimension( attr["width"], refWidth );
431 int height = getDimension( attr["height"], refHeight );
432 convertPosition( attr["position"],
433 attr["xoffset"], attr["yoffset"],
434 attr["xmargin"], attr["ymargin"],
435 width, height, refWidth, refHeight, &x, &y );
437 m_curTreeId = uniqueId( attr["id"] );
438 const BuilderData::Tree treeData( m_curTreeId,
439 x + m_xOffset, y + m_yOffset, attr["visible"],
442 attr["lefttop"], attr["rightbottom"],
443 convertBoolean( attr["xkeepratio"] ),
444 convertBoolean( attr["ykeepratio"] ),
445 attr["font"], "playtree",
446 attr["bgimage"], attr["itemimage"],
447 attr["openimage"], attr["closedimage"],
452 attr["selcolor"], attr["help"],
453 m_curLayer, m_curWindowId, m_curLayoutId, m_panelStack.back() );
455 m_pData->m_listTree.push_back( treeData );
457 else if( rName == "Playtree" )
459 RequireAttr( attr, rName, "id" );
460 RequireAttr( attr, rName, "font" );
461 DefaultAttr( attr, "visible", "true" );
462 DefaultAttr( attr, "flat", "false" );
463 DefaultAttr( attr, "x", "0" );
464 DefaultAttr( attr, "y", "0" );
465 DefaultAttr( attr, "width", "0" );
466 DefaultAttr( attr, "height", "0" );
467 DefaultAttr( attr, "position", "-1" );
468 DefaultAttr( attr, "xoffset", "0" );
469 DefaultAttr( attr, "yoffset", "0" );
470 DefaultAttr( attr, "xmargin", "0" );
471 DefaultAttr( attr, "ymargin", "0" );
472 DefaultAttr( attr, "lefttop", "lefttop" );
473 DefaultAttr( attr, "rightbottom", "lefttop" );
474 DefaultAttr( attr, "xkeepratio", "false" );
475 DefaultAttr( attr, "ykeepratio", "false" );
476 DefaultAttr( attr, "bgimage", "none" );
477 DefaultAttr( attr, "itemimage", "none" );
478 DefaultAttr( attr, "openimage", "none" );
479 DefaultAttr( attr, "closedimage", "none" );
480 DefaultAttr( attr, "fgcolor", "#000000" );
481 DefaultAttr( attr, "playcolor", "#FF0000" );
482 DefaultAttr( attr, "bgcolor1", "#FFFFFF" );
483 DefaultAttr( attr, "bgcolor2", "#FFFFFF" );
484 DefaultAttr( attr, "selcolor", "#0000FF" );
485 DefaultAttr( attr, "help", "" );
487 int refWidth = getRefWidth( false );
488 int refHeight = getRefHeight( false );
490 int x = getDimension( attr["x"], refWidth );
491 int y = getDimension( attr["y"], refHeight );
492 int width = getDimension( attr["width"], refWidth );
493 int height = getDimension( attr["height"], refHeight );
494 convertPosition( attr["position"],
495 attr["xoffset"], attr["yoffset"],
496 attr["xmargin"], attr["ymargin"],
497 width, height, refWidth, refHeight, &x, &y );
499 m_curTreeId = uniqueId( attr["id"] );
500 const BuilderData::Tree treeData( m_curTreeId,
501 x + m_xOffset, y + m_yOffset, attr["visible"],
504 attr["lefttop"], attr["rightbottom"],
505 convertBoolean( attr["xkeepratio"] ),
506 convertBoolean( attr["ykeepratio"] ),
507 attr["font"], "playtree",
508 attr["bgimage"], attr["itemimage"],
509 attr["openimage"], attr["closedimage"],
510 attr["fgcolor"], attr["playcolor"],
511 attr["bgcolor1"], attr["bgcolor2"],
512 attr["selcolor"], attr["help"],
513 m_curLayer, m_curWindowId, m_curLayoutId, m_panelStack.back() );
515 m_pData->m_listTree.push_back( treeData );
518 else if( rName == "RadialSlider" )
520 RequireAttr( attr, rName, "sequence" );
521 RequireAttr( attr, rName, "nbimages" );
522 DefaultAttr( attr, "id", "none" );
523 DefaultAttr( attr, "visible", "true" );
524 DefaultAttr( attr, "x", "0" );
525 DefaultAttr( attr, "y", "0" );
526 DefaultAttr( attr, "lefttop", "lefttop" );
527 DefaultAttr( attr, "rightbottom", "lefttop" );
528 DefaultAttr( attr, "xkeepratio", "false" );
529 DefaultAttr( attr, "ykeepratio", "false" );
530 DefaultAttr( attr, "minangle", "0" );
531 DefaultAttr( attr, "maxangle", "360" );
532 DefaultAttr( attr, "value", "none" );
533 DefaultAttr( attr, "tooltiptext", "" );
534 DefaultAttr( attr, "help", "" );
536 int refWidth = getRefWidth( false );
537 int refHeight = getRefHeight( false );
538 int x = getDimension( attr["x"], refWidth );
539 int y = getDimension( attr["y"], refHeight );
540 const BuilderData::RadialSlider radial( uniqueId( attr["id"] ),
542 x + m_xOffset, y + m_yOffset,
543 attr["lefttop"], attr["rightbottom"],
544 convertBoolean( attr["xkeepratio"] ),
545 convertBoolean( attr["ykeepratio"] ), attr["sequence"],
546 atoi( attr["nbimages"] ), atof( attr["minangle"] ) * M_PI /180,
547 atof( attr["maxangle"] ) * M_PI / 180, attr["value"],
548 attr["tooltiptext"], attr["help"], m_curLayer, m_curWindowId,
549 m_curLayoutId, m_panelStack.back() );
551 m_pData->m_listRadialSlider.push_back( radial );
554 else if( rName == "Slider" )
556 RequireAttr( attr, rName, "up" );
557 RequireAttr( attr, rName, "points" );
558 DefaultAttr( attr, "id", "none" );
559 DefaultAttr( attr, "visible", "true" );
560 DefaultAttr( attr, "x", "0" );
561 DefaultAttr( attr, "y", "0" );
562 DefaultAttr( attr, "lefttop", "lefttop" );
563 DefaultAttr( attr, "rightbottom", "lefttop" );
564 DefaultAttr( attr, "xkeepratio", "false" );
565 DefaultAttr( attr, "ykeepratio", "false" );
566 DefaultAttr( attr, "down", "none" );
567 DefaultAttr( attr, "over", "none" );
568 DefaultAttr( attr, "thickness", "10" );
569 DefaultAttr( attr, "value", "none" );
570 DefaultAttr( attr, "tooltiptext", "" );
571 DefaultAttr( attr, "help", "" );
573 string newValue = attr["value"];
574 if( m_curTreeId != "" )
576 // Slider associated to a tree
577 newValue = "playtree.slider";
580 int refWidth = getRefWidth( false );
581 int refHeight = getRefHeight( false );
582 int x = getDimension( attr["x"], refWidth );
583 int y = getDimension( attr["y"], refHeight );
584 const BuilderData::Slider slider( uniqueId( attr["id"] ),
585 attr["visible"], x + m_xOffset,
586 y + m_yOffset, attr["lefttop"],
587 attr["rightbottom"], convertBoolean( attr["xkeepratio"] ),
588 convertBoolean( attr["ykeepratio"] ), attr["up"], attr["down"],
589 attr["over"], attr["points"], atoi( attr["thickness"] ),
590 newValue, "none", 0, 0, 0, 0, attr["tooltiptext"],
591 attr["help"], m_curLayer, m_curWindowId, m_curLayoutId,
592 m_panelStack.back() );
594 m_pData->m_listSlider.push_back( slider );
597 else if( rName == "SliderBackground" )
599 RequireAttr( attr, rName, "image" );
600 DefaultAttr( attr, "nbhoriz", "1" );
601 DefaultAttr( attr, "nbvert", "1" );
602 DefaultAttr( attr, "padhoriz", "0" );
603 DefaultAttr( attr, "padvert", "0" );
605 // Retrieve the current slider data
606 BuilderData::Slider &slider = m_pData->m_listSlider.back();
608 slider.m_imageId = attr["image"];
609 slider.m_nbHoriz = atoi( attr["nbhoriz"] );
610 slider.m_nbVert = atoi( attr["nbvert"] );
611 slider.m_padHoriz = atoi( attr["padhoriz"] );
612 slider.m_padVert = atoi( attr["padvert"] );
615 else if( rName == "Text" )
617 RequireAttr( attr, rName, "font" );
618 DefaultAttr( attr, "id", "none" );
619 DefaultAttr( attr, "visible", "true" );
620 DefaultAttr( attr, "x", "0" );
621 DefaultAttr( attr, "y", "0" );
622 DefaultAttr( attr, "text", "" );
623 DefaultAttr( attr, "color", "#000000" );
624 DefaultAttr( attr, "scrolling", "auto" );
625 DefaultAttr( attr, "alignment", "left" );
626 DefaultAttr( attr, "focus", "true" );
627 DefaultAttr( attr, "width", "0" );
628 DefaultAttr( attr, "lefttop", "lefttop" );
629 DefaultAttr( attr, "rightbottom", "lefttop" );
630 DefaultAttr( attr, "xkeepratio", "false" );
631 DefaultAttr( attr, "ykeepratio", "false" );
632 DefaultAttr( attr, "help", "" );
634 int refWidth = getRefWidth( false );
635 int refHeight = getRefHeight( false );
637 int x = getDimension( attr["x"], refWidth );
638 int y = getDimension( attr["y"], refHeight );
639 int width = getDimension( attr["width"], refWidth );
641 const BuilderData::Text textData( uniqueId( attr["id"] ),
642 x + m_xOffset, y + m_yOffset,
643 attr["visible"], attr["font"],
646 attr["lefttop"], attr["rightbottom"],
647 convertBoolean( attr["xkeepratio"] ),
648 convertBoolean( attr["ykeepratio"] ),
649 convertColor( attr["color"] ),
650 attr["scrolling"], attr["alignment"],
651 attr["focus"], attr["help"],
652 m_curLayer, m_curWindowId, m_curLayoutId,
653 m_panelStack.back() );
655 m_pData->m_listText.push_back( textData );
658 else if( rName == "Theme" )
660 RequireAttr( attr, rName, "version" );
661 DefaultAttr( attr, "tooltipfont", "defaultfont" );
662 DefaultAttr( attr, "magnet", "15" );
663 DefaultAttr( attr, "alpha", "255" );
664 DefaultAttr( attr, "movealpha", "255" );
667 if( strcmp( attr["version"], SKINS_DTD_VERSION ) )
669 msg_Err( getIntf(), "bad theme version : %s (you need version %s)",
670 attr["version"], SKINS_DTD_VERSION );
674 const BuilderData::Theme theme( attr["tooltipfont"],
675 atoi( attr["magnet"] ),
676 convertInRange( attr["alpha"], 1, 255, "alpha" ),
677 convertInRange( attr["movealpha"], 1, 255, "movealpha" ) );
678 m_pData->m_listTheme.push_back( theme );
681 else if( rName == "ThemeInfo" )
683 DefaultAttr( attr, "name", "" );
684 DefaultAttr( attr, "author", "" );
685 DefaultAttr( attr, "email", "" );
686 DefaultAttr( attr, "website", "" );
687 msg_Info( getIntf(), "skin: %s author: %s", attr["name"],
691 else if( rName == "Video" )
693 DefaultAttr( attr, "id", "none" );
694 DefaultAttr( attr, "visible", "true" );
695 DefaultAttr( attr, "x", "0" );
696 DefaultAttr( attr, "y", "0" );
697 DefaultAttr( attr, "width", "0" );
698 DefaultAttr( attr, "height", "0" );
699 DefaultAttr( attr, "position", "-1" );
700 DefaultAttr( attr, "xoffset", "0" );
701 DefaultAttr( attr, "yoffset", "0" );
702 DefaultAttr( attr, "xmargin", "0" );
703 DefaultAttr( attr, "ymargin", "0" );
704 DefaultAttr( attr, "lefttop", "lefttop" );
705 DefaultAttr( attr, "rightbottom", "lefttop" );
706 DefaultAttr( attr, "xkeepratio", "false" );
707 DefaultAttr( attr, "ykeepratio", "false" );
708 DefaultAttr( attr, "autoresize", "false" );
709 DefaultAttr( attr, "help", "" );
711 int refWidth = getRefWidth( false );
712 int refHeight = getRefHeight( false );
714 int x = getDimension( attr["x"], refWidth );
715 int y = getDimension( attr["y"], refHeight );
716 int width = getDimension( attr["width"], refWidth );
717 int height = getDimension( attr["height"], refHeight );
718 convertPosition( attr["position"],
719 attr["xoffset"], attr["yoffset"],
720 attr["xmargin"], attr["ymargin"],
721 width, height, refWidth, refHeight, &x, &y );
723 const BuilderData::Video videoData( uniqueId( attr["id"] ),
724 x + m_xOffset, y + m_yOffset, width, height,
725 attr["lefttop"], attr["rightbottom"],
726 convertBoolean( attr["xkeepratio"] ),
727 convertBoolean( attr["ykeepratio"] ),
728 attr["visible"], convertBoolean( attr["autoresize"] ),
729 attr["help"], m_curLayer, m_curWindowId, m_curLayoutId,
730 m_panelStack.back() );
732 m_pData->m_listVideo.push_back( videoData );
735 else if( rName == "Window" )
737 DefaultAttr( attr, "id", "none" );
738 DefaultAttr( attr, "visible", "true" );
739 DefaultAttr( attr, "x", "0" );
740 DefaultAttr( attr, "y", "0" );
741 DefaultAttr( attr, "position", "-1" );
742 DefaultAttr( attr, "xoffset", "0" );
743 DefaultAttr( attr, "yoffset", "0" );
744 DefaultAttr( attr, "xmargin", "0" );
745 DefaultAttr( attr, "ymargin", "0" );
746 DefaultAttr( attr, "dragdrop", "true" );
747 DefaultAttr( attr, "playondrop", "true" );
749 m_curWindowId = uniqueId( attr["id"] );
751 int refWidth = getRefWidth( true );
752 int refHeight = getRefHeight( true );
753 int x = getDimension( attr["x"], refWidth );
754 int y = getDimension( attr["y"], refHeight );
755 const BuilderData::Window window( m_curWindowId,
756 x + m_xOffset, y + m_yOffset,
758 attr["xoffset"], attr["yoffset"],
759 attr["xmargin"], attr["ymargin"],
760 convertBoolean( attr["visible"] ),
761 convertBoolean( attr["dragdrop"] ),
762 convertBoolean( attr["playondrop"] ) );
763 m_pData->m_listWindow.push_back( window );
769 void SkinParser::handleEndElement( const string &rName )
771 if( rName == "Group" )
773 m_xOffset -= m_xOffsetList.back();
774 m_yOffset -= m_yOffsetList.back();
775 m_xOffsetList.pop_back();
776 m_yOffsetList.pop_back();
778 else if( rName == "Playtree" || rName == "Playlist" )
782 else if( rName == "Popup" )
785 m_popupPosList.pop_back();
787 else if( rName == "Panel" )
789 m_panelStack.pop_back();
794 bool SkinParser::convertBoolean( const char *value ) const
796 return strcmp( value, "true" ) == 0;
800 int SkinParser::convertColor( const char *transcolor )
802 // TODO: move to the builder
803 unsigned long iRed, iGreen, iBlue;
804 iRed = iGreen = iBlue = 0;
805 sscanf( transcolor, "#%2lX%2lX%2lX", &iRed, &iGreen, &iBlue );
806 return ( iRed << 16 | iGreen << 8 | iBlue );
810 int SkinParser::convertInRange( const char *value, int minValue, int maxValue,
811 const string &rAttribute ) const
813 int intValue = atoi( value );
815 if( intValue < minValue )
817 msg_Warn( getIntf(), "value of \"%s\" attribute (%i) is out of the "
818 "expected range [%i, %i], using %i instead",
819 rAttribute.c_str(), intValue, minValue, maxValue, minValue );
822 else if( intValue > maxValue )
824 msg_Warn( getIntf(), "value of \"%s\" attribute (%i) is out of the "
825 "expected range [%i, %i], using %i instead",
826 rAttribute.c_str(), intValue, minValue, maxValue, maxValue );
836 const string SkinParser::generateId() const
841 snprintf( genId, 4, "%i", i++ );
843 string base = "_ReservedId_" + (string)genId;
849 const string SkinParser::uniqueId( const string &id )
853 if( m_idSet.find( id ) != m_idSet.end() )
855 // The id was already used
858 msg_Warn( getIntf(), "non-unique id: %s", id.c_str() );
860 newId = generateId();
864 // OK, this is a new id
868 // Add the id to the set
869 m_idSet.insert( newId );
874 int SkinParser::getRefWidth( bool toScreen )
878 OSFactory *pOsFactory = OSFactory::instance( getIntf() );
879 return pOsFactory->getScreenWidth();
882 string panelId = m_panelStack.back();
883 if( panelId != "none" )
885 const BuilderData::Panel panel = m_pData->m_listPanel.back();
886 return panel.m_width;
890 const BuilderData::Layout layout = m_pData->m_listLayout.back();
891 return layout.m_width;
895 int SkinParser::getRefHeight( bool toScreen )
899 OSFactory *pOsFactory = OSFactory::instance( getIntf() );
900 return pOsFactory->getScreenHeight();
903 string panelId = m_panelStack.back();
904 if( panelId != "none" )
906 const BuilderData::Panel panel = m_pData->m_listPanel.back();
907 return panel.m_height;
911 const BuilderData::Layout layout = m_pData->m_listLayout.back();
912 return layout.m_height;
917 int SkinParser::getDimension( string value, int refDimension )
919 string::size_type leftPos;
921 leftPos = value.find( "%" );
922 if( leftPos != string::npos )
924 int val = atoi( value.substr( 0, leftPos ).c_str() );
925 return val * refDimension / 100;
928 leftPos = value.find( "px" );
929 if( leftPos != string::npos )
931 int val = atoi( value.substr( 0, leftPos ).c_str() );
935 return atoi( value.c_str() );
939 int SkinParser::getPosition( string position )
941 if( position == "-1" )
943 else if( position == "Center" )
945 else if( position == "North" )
947 else if( position == "South" )
949 else if( position == "West" )
951 else if( position == "East" )
953 else if( position == "NorthWest" )
954 return POS_TOP | POS_LEFT;
955 else if( position == "NorthEast" )
956 return POS_TOP | POS_RIGHT;
957 else if( position == "SouthWest" )
958 return POS_BOTTOM | POS_LEFT;
959 else if( position == "SouthEast" )
960 return POS_BOTTOM | POS_RIGHT;
962 msg_Err( getIntf(), "unknown value '%s' for position",
968 void SkinParser::convertPosition( string position, string xOffset,
969 string yOffset, string xMargin,
970 string yMargin, int width, int height,
971 int refWidth, int refHeight, int* p_x, int* p_y )
973 int iPosition = getPosition( position );
974 if( iPosition == POS_UNDEF )
977 int i_xOffset = getDimension( xOffset, refWidth );
978 int i_yOffset = getDimension( yOffset, refHeight );
979 int i_xMargin = getDimension( xMargin, refWidth );
980 int i_yMargin = getDimension( yMargin, refHeight );
983 if( iPosition & POS_LEFT )
985 else if( iPosition & POS_RIGHT )
986 *p_x = refWidth - width - i_xMargin;
988 *p_x = ( refWidth - width ) / 2;
991 if( iPosition & POS_TOP )
993 else if( iPosition & POS_BOTTOM )
994 *p_y = refHeight - height - i_yMargin;
996 *p_y = ( refHeight - height ) / 2;
1004 void SkinParser::updateWindowPos( int width, int height )
1006 BuilderData::Window win = m_pData->m_listWindow.back();
1007 m_pData->m_listWindow.pop_back();
1009 int refWidth = getRefWidth( true );
1010 int refHeight = getRefHeight( true );
1011 convertPosition( win.m_position,
1012 win.m_xOffset, win.m_yOffset,
1013 win.m_xMargin, win.m_yMargin,
1014 width, height, refWidth, refHeight,
1015 &win.m_xPos, &win.m_yPos );
1017 m_pData->m_listWindow.push_back( win );