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, refHeight;
103 getRefDimensions( refWidth, refHeight, 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, refHeight;
208 getRefDimensions( refWidth, refHeight, 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, refHeight;
247 getRefDimensions( refWidth, refHeight, 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, refHeight;
306 getRefDimensions( refWidth, refHeight, 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, refHeight;
335 getRefDimensions( refWidth, refHeight, 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, refHeight;
370 getRefDimensions( refWidth, refHeight, false );
371 int x = getDimension( attr["x"], refWidth );
372 int y = getDimension( attr["y"], refHeight );
373 int width = getDimension( attr["width"], refWidth );
374 int height = getDimension( attr["height"], refHeight );
375 convertPosition( attr["position"],
376 attr["xoffset"], attr["yoffset"],
377 attr["xmargin"], attr["ymargin"],
378 width, height, refWidth, refHeight, &x, &y );
380 string panelId = uniqueId( "none" );
381 const BuilderData::Panel panel( panelId,
382 x + m_xOffset, y + m_yOffset,
383 attr["lefttop"], attr["rightbottom"],
384 convertBoolean( attr["xkeepratio"] ),
385 convertBoolean( attr["ykeepratio"] ),
387 m_curLayer, m_curWindowId, m_curLayoutId, m_panelStack.back() );
389 m_pData->m_listPanel.push_back( panel );
390 // Add the panel to the stack
391 m_panelStack.push_back( panelId );
394 else if( rName == "Playlist" )
396 RequireAttr( attr, rName, "id" );
397 RequireAttr( attr, rName, "font" );
398 DefaultAttr( attr, "visible", "true" );
399 DefaultAttr( attr, "flat", "true" ); // Only difference here
400 DefaultAttr( attr, "x", "0" );
401 DefaultAttr( attr, "y", "0" );
402 DefaultAttr( attr, "width", "0" );
403 DefaultAttr( attr, "height", "0" );
404 DefaultAttr( attr, "position", "-1" );
405 DefaultAttr( attr, "xoffset", "0" );
406 DefaultAttr( attr, "yoffset", "0" );
407 DefaultAttr( attr, "xmargin", "0" );
408 DefaultAttr( attr, "ymargin", "0" );
409 DefaultAttr( attr, "lefttop", "lefttop" );
410 DefaultAttr( attr, "rightbottom", "lefttop" );
411 DefaultAttr( attr, "xkeepratio", "false" );
412 DefaultAttr( attr, "ykeepratio", "false" );
413 DefaultAttr( attr, "bgimage", "none" );
414 DefaultAttr( attr, "itemimage", "none" );
415 DefaultAttr( attr, "openimage", "none" );
416 DefaultAttr( attr, "closedimage", "none" );
417 DefaultAttr( attr, "fgcolor", "#000000" );
418 DefaultAttr( attr, "playcolor", "#FF0000" );
419 DefaultAttr( attr, "bgcolor1", "#FFFFFF" );
420 DefaultAttr( attr, "bgcolor2", "#FFFFFF" );
421 DefaultAttr( attr, "selcolor", "#0000FF" );
422 DefaultAttr( attr, "help", "" );
424 int refWidth, refHeight;
425 getRefDimensions( refWidth, refHeight, false );
426 int x = getDimension( attr["x"], refWidth );
427 int y = getDimension( attr["y"], refHeight );
428 int width = getDimension( attr["width"], refWidth );
429 int height = getDimension( attr["height"], refHeight );
430 convertPosition( attr["position"],
431 attr["xoffset"], attr["yoffset"],
432 attr["xmargin"], attr["ymargin"],
433 width, height, refWidth, refHeight, &x, &y );
435 m_curTreeId = uniqueId( attr["id"] );
436 const BuilderData::Tree treeData( m_curTreeId,
437 x + m_xOffset, y + m_yOffset, attr["visible"],
440 attr["lefttop"], attr["rightbottom"],
441 convertBoolean( attr["xkeepratio"] ),
442 convertBoolean( attr["ykeepratio"] ),
443 attr["font"], "playtree",
444 attr["bgimage"], attr["itemimage"],
445 attr["openimage"], attr["closedimage"],
450 attr["selcolor"], attr["help"],
451 m_curLayer, m_curWindowId, m_curLayoutId, m_panelStack.back() );
453 m_pData->m_listTree.push_back( treeData );
455 else if( rName == "Playtree" )
457 RequireAttr( attr, rName, "id" );
458 RequireAttr( attr, rName, "font" );
459 DefaultAttr( attr, "visible", "true" );
460 DefaultAttr( attr, "flat", "false" );
461 DefaultAttr( attr, "x", "0" );
462 DefaultAttr( attr, "y", "0" );
463 DefaultAttr( attr, "width", "0" );
464 DefaultAttr( attr, "height", "0" );
465 DefaultAttr( attr, "position", "-1" );
466 DefaultAttr( attr, "xoffset", "0" );
467 DefaultAttr( attr, "yoffset", "0" );
468 DefaultAttr( attr, "xmargin", "0" );
469 DefaultAttr( attr, "ymargin", "0" );
470 DefaultAttr( attr, "lefttop", "lefttop" );
471 DefaultAttr( attr, "rightbottom", "lefttop" );
472 DefaultAttr( attr, "xkeepratio", "false" );
473 DefaultAttr( attr, "ykeepratio", "false" );
474 DefaultAttr( attr, "bgimage", "none" );
475 DefaultAttr( attr, "itemimage", "none" );
476 DefaultAttr( attr, "openimage", "none" );
477 DefaultAttr( attr, "closedimage", "none" );
478 DefaultAttr( attr, "fgcolor", "#000000" );
479 DefaultAttr( attr, "playcolor", "#FF0000" );
480 DefaultAttr( attr, "bgcolor1", "#FFFFFF" );
481 DefaultAttr( attr, "bgcolor2", "#FFFFFF" );
482 DefaultAttr( attr, "selcolor", "#0000FF" );
483 DefaultAttr( attr, "help", "" );
485 int refWidth, refHeight;
486 getRefDimensions( refWidth, refHeight, false );
487 int x = getDimension( attr["x"], refWidth );
488 int y = getDimension( attr["y"], refHeight );
489 int width = getDimension( attr["width"], refWidth );
490 int height = getDimension( attr["height"], refHeight );
491 convertPosition( attr["position"],
492 attr["xoffset"], attr["yoffset"],
493 attr["xmargin"], attr["ymargin"],
494 width, height, refWidth, refHeight, &x, &y );
496 m_curTreeId = uniqueId( attr["id"] );
497 const BuilderData::Tree treeData( m_curTreeId,
498 x + m_xOffset, y + m_yOffset, attr["visible"],
501 attr["lefttop"], attr["rightbottom"],
502 convertBoolean( attr["xkeepratio"] ),
503 convertBoolean( attr["ykeepratio"] ),
504 attr["font"], "playtree",
505 attr["bgimage"], attr["itemimage"],
506 attr["openimage"], attr["closedimage"],
507 attr["fgcolor"], attr["playcolor"],
508 attr["bgcolor1"], attr["bgcolor2"],
509 attr["selcolor"], attr["help"],
510 m_curLayer, m_curWindowId, m_curLayoutId, m_panelStack.back() );
512 m_pData->m_listTree.push_back( treeData );
515 else if( rName == "RadialSlider" )
517 RequireAttr( attr, rName, "sequence" );
518 RequireAttr( attr, rName, "nbimages" );
519 DefaultAttr( attr, "id", "none" );
520 DefaultAttr( attr, "visible", "true" );
521 DefaultAttr( attr, "x", "0" );
522 DefaultAttr( attr, "y", "0" );
523 DefaultAttr( attr, "lefttop", "lefttop" );
524 DefaultAttr( attr, "rightbottom", "lefttop" );
525 DefaultAttr( attr, "xkeepratio", "false" );
526 DefaultAttr( attr, "ykeepratio", "false" );
527 DefaultAttr( attr, "minangle", "0" );
528 DefaultAttr( attr, "maxangle", "360" );
529 DefaultAttr( attr, "value", "none" );
530 DefaultAttr( attr, "tooltiptext", "" );
531 DefaultAttr( attr, "help", "" );
533 int refWidth, refHeight;
534 getRefDimensions( refWidth, refHeight, false );
535 int x = getDimension( attr["x"], refWidth );
536 int y = getDimension( attr["y"], refHeight );
537 const BuilderData::RadialSlider radial( uniqueId( attr["id"] ),
539 x + m_xOffset, y + m_yOffset,
540 attr["lefttop"], attr["rightbottom"],
541 convertBoolean( attr["xkeepratio"] ),
542 convertBoolean( attr["ykeepratio"] ), attr["sequence"],
543 atoi( attr["nbimages"] ), atof( attr["minangle"] ) * M_PI /180,
544 atof( attr["maxangle"] ) * M_PI / 180, attr["value"],
545 attr["tooltiptext"], attr["help"], m_curLayer, m_curWindowId,
546 m_curLayoutId, m_panelStack.back() );
548 m_pData->m_listRadialSlider.push_back( radial );
551 else if( rName == "Slider" )
553 RequireAttr( attr, rName, "up" );
554 RequireAttr( attr, rName, "points" );
555 DefaultAttr( attr, "id", "none" );
556 DefaultAttr( attr, "visible", "true" );
557 DefaultAttr( attr, "x", "0" );
558 DefaultAttr( attr, "y", "0" );
559 DefaultAttr( attr, "width", "-1" );
560 DefaultAttr( attr, "height", "-1" );
561 DefaultAttr( attr, "lefttop", "lefttop" );
562 DefaultAttr( attr, "rightbottom", "lefttop" );
563 DefaultAttr( attr, "xkeepratio", "false" );
564 DefaultAttr( attr, "ykeepratio", "false" );
565 DefaultAttr( attr, "down", "none" );
566 DefaultAttr( attr, "over", "none" );
567 DefaultAttr( attr, "thickness", "10" );
568 DefaultAttr( attr, "value", "none" );
569 DefaultAttr( attr, "tooltiptext", "" );
570 DefaultAttr( attr, "help", "" );
572 string newValue = attr["value"];
573 if( m_curTreeId != "" )
575 // Slider associated to a tree
576 newValue = "playtree.slider";
579 int refWidth, refHeight;
580 getRefDimensions( refWidth, refHeight, false );
581 int x = getDimension( attr["x"], refWidth );
582 int y = getDimension( attr["y"], refHeight );
583 int width = getDimension( attr["width"], refWidth );
584 int height = getDimension( attr["height"], refHeight );
585 const BuilderData::Slider slider( uniqueId( attr["id"] ),
586 attr["visible"], x + m_xOffset, y + m_yOffset,
587 width, height, attr["lefttop"],
588 attr["rightbottom"], convertBoolean( attr["xkeepratio"] ),
589 convertBoolean( attr["ykeepratio"] ), attr["up"], attr["down"],
590 attr["over"], attr["points"], atoi( attr["thickness"] ),
591 newValue, "none", 0, 0, 0, 0, attr["tooltiptext"],
592 attr["help"], m_curLayer, m_curWindowId, m_curLayoutId,
593 m_panelStack.back() );
595 m_pData->m_listSlider.push_back( slider );
598 else if( rName == "SliderBackground" )
600 RequireAttr( attr, rName, "image" );
601 DefaultAttr( attr, "nbhoriz", "1" );
602 DefaultAttr( attr, "nbvert", "1" );
603 DefaultAttr( attr, "padhoriz", "0" );
604 DefaultAttr( attr, "padvert", "0" );
606 // Retrieve the current slider data
607 BuilderData::Slider &slider = m_pData->m_listSlider.back();
609 slider.m_imageId = attr["image"];
610 slider.m_nbHoriz = atoi( attr["nbhoriz"] );
611 slider.m_nbVert = atoi( attr["nbvert"] );
612 slider.m_padHoriz = atoi( attr["padhoriz"] );
613 slider.m_padVert = atoi( attr["padvert"] );
616 else if( rName == "Text" )
618 RequireAttr( attr, rName, "font" );
619 DefaultAttr( attr, "id", "none" );
620 DefaultAttr( attr, "visible", "true" );
621 DefaultAttr( attr, "x", "0" );
622 DefaultAttr( attr, "y", "0" );
623 DefaultAttr( attr, "text", "" );
624 DefaultAttr( attr, "color", "#000000" );
625 DefaultAttr( attr, "scrolling", "auto" );
626 DefaultAttr( attr, "alignment", "left" );
627 DefaultAttr( attr, "focus", "true" );
628 DefaultAttr( attr, "width", "0" );
629 DefaultAttr( attr, "lefttop", "lefttop" );
630 DefaultAttr( attr, "rightbottom", "lefttop" );
631 DefaultAttr( attr, "xkeepratio", "false" );
632 DefaultAttr( attr, "ykeepratio", "false" );
633 DefaultAttr( attr, "help", "" );
635 int refWidth, refHeight;
636 getRefDimensions( refWidth, refHeight, 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, refHeight;
712 getRefDimensions( refWidth, refHeight, false );
713 int x = getDimension( attr["x"], refWidth );
714 int y = getDimension( attr["y"], refHeight );
715 int width = getDimension( attr["width"], refWidth );
716 int height = getDimension( attr["height"], refHeight );
717 convertPosition( attr["position"],
718 attr["xoffset"], attr["yoffset"],
719 attr["xmargin"], attr["ymargin"],
720 width, height, refWidth, refHeight, &x, &y );
722 const BuilderData::Video videoData( uniqueId( attr["id"] ),
723 x + m_xOffset, y + m_yOffset, width, height,
724 attr["lefttop"], attr["rightbottom"],
725 convertBoolean( attr["xkeepratio"] ),
726 convertBoolean( attr["ykeepratio"] ),
727 attr["visible"], convertBoolean( attr["autoresize"] ),
728 attr["help"], m_curLayer, m_curWindowId, m_curLayoutId,
729 m_panelStack.back() );
731 m_pData->m_listVideo.push_back( videoData );
734 else if( rName == "Window" )
736 DefaultAttr( attr, "id", "none" );
737 DefaultAttr( attr, "visible", "true" );
738 DefaultAttr( attr, "x", "0" );
739 DefaultAttr( attr, "y", "0" );
740 DefaultAttr( attr, "position", "-1" );
741 DefaultAttr( attr, "xoffset", "0" );
742 DefaultAttr( attr, "yoffset", "0" );
743 DefaultAttr( attr, "xmargin", "0" );
744 DefaultAttr( attr, "ymargin", "0" );
745 DefaultAttr( attr, "dragdrop", "true" );
746 DefaultAttr( attr, "playondrop", "true" );
748 m_curWindowId = uniqueId( attr["id"] );
750 int refWidth, refHeight;
751 getRefDimensions( refWidth, refHeight, true );
752 int x = getDimension( attr["x"], refWidth );
753 int y = getDimension( attr["y"], refHeight );
754 const BuilderData::Window window( m_curWindowId,
755 x + m_xOffset, y + m_yOffset,
757 attr["xoffset"], attr["yoffset"],
758 attr["xmargin"], attr["ymargin"],
759 convertBoolean( attr["visible"] ),
760 convertBoolean( attr["dragdrop"] ),
761 convertBoolean( attr["playondrop"] ) );
762 m_pData->m_listWindow.push_back( window );
768 void SkinParser::handleEndElement( const string &rName )
770 if( rName == "Group" )
772 m_xOffset -= m_xOffsetList.back();
773 m_yOffset -= m_yOffsetList.back();
774 m_xOffsetList.pop_back();
775 m_yOffsetList.pop_back();
777 else if( rName == "Playtree" || rName == "Playlist" )
781 else if( rName == "Popup" )
784 m_popupPosList.pop_back();
786 else if( rName == "Panel" )
788 m_panelStack.pop_back();
793 bool SkinParser::convertBoolean( const char *value ) const
795 return strcmp( value, "true" ) == 0;
799 int SkinParser::convertColor( const char *transcolor )
801 // TODO: move to the builder
802 unsigned long iRed, iGreen, iBlue;
803 iRed = iGreen = iBlue = 0;
804 sscanf( transcolor, "#%2lX%2lX%2lX", &iRed, &iGreen, &iBlue );
805 return ( iRed << 16 | iGreen << 8 | iBlue );
809 int SkinParser::convertInRange( const char *value, int minValue, int maxValue,
810 const string &rAttribute ) const
812 int intValue = atoi( value );
814 if( intValue < minValue )
816 msg_Warn( getIntf(), "value of \"%s\" attribute (%i) is out of the "
817 "expected range [%i, %i], using %i instead",
818 rAttribute.c_str(), intValue, minValue, maxValue, minValue );
821 else if( intValue > maxValue )
823 msg_Warn( getIntf(), "value of \"%s\" attribute (%i) is out of the "
824 "expected range [%i, %i], using %i instead",
825 rAttribute.c_str(), intValue, minValue, maxValue, maxValue );
835 const string SkinParser::generateId() const
840 snprintf( genId, 4, "%i", i++ );
842 string base = "_ReservedId_" + (string)genId;
848 const string SkinParser::uniqueId( const string &id )
852 if( m_idSet.find( id ) != m_idSet.end() )
854 // The id was already used
857 msg_Warn( getIntf(), "non-unique id: %s", id.c_str() );
859 newId = generateId();
863 // OK, this is a new id
867 // Add the id to the set
868 m_idSet.insert( newId );
873 void SkinParser::getRefDimensions( int &rWidth, int &rHeight, bool toScreen )
877 OSFactory *pOsFactory = OSFactory::instance( getIntf() );
878 rWidth = pOsFactory->getScreenWidth();
879 rHeight = pOsFactory->getScreenHeight();
883 string panelId = m_panelStack.back();
884 if( panelId != "none" )
886 list<BuilderData::Panel>::const_iterator it;
887 for( it = m_pData->m_listPanel.begin();
888 it != m_pData->m_listPanel.end(); ++it )
890 if( it->m_id == panelId )
892 rWidth = it->m_width;
893 rHeight = it->m_height;
900 const BuilderData::Layout layout = m_pData->m_listLayout.back();
901 rWidth = layout.m_width;
902 rHeight = layout.m_height;
905 msg_Err( getIntf(), "failure to retrieve parent panel or layout" );
909 int SkinParser::getDimension( string value, int refDimension )
911 string::size_type leftPos;
913 leftPos = value.find( "%" );
914 if( leftPos != string::npos )
916 int val = atoi( value.substr( 0, leftPos ).c_str() );
917 return val * refDimension / 100;
920 leftPos = value.find( "px" );
921 if( leftPos != string::npos )
923 int val = atoi( value.substr( 0, leftPos ).c_str() );
927 return atoi( value.c_str() );
931 int SkinParser::getPosition( string position )
933 if( position == "-1" )
935 else if( position == "Center" )
937 else if( position == "North" )
939 else if( position == "South" )
941 else if( position == "West" )
943 else if( position == "East" )
945 else if( position == "NorthWest" )
946 return POS_TOP | POS_LEFT;
947 else if( position == "NorthEast" )
948 return POS_TOP | POS_RIGHT;
949 else if( position == "SouthWest" )
950 return POS_BOTTOM | POS_LEFT;
951 else if( position == "SouthEast" )
952 return POS_BOTTOM | POS_RIGHT;
954 msg_Err( getIntf(), "unknown value '%s' for position",
960 void SkinParser::convertPosition( string position, string xOffset,
961 string yOffset, string xMargin,
962 string yMargin, int width, int height,
963 int refWidth, int refHeight, int* p_x, int* p_y )
965 int iPosition = getPosition( position );
966 if( iPosition != POS_UNDEF )
968 // compute offset against the parent object size
969 // for backward compatibility
970 int i_xOffset = getDimension( xOffset, refWidth );
971 int i_yOffset = getDimension( yOffset, refHeight );
972 int i_xMargin = getDimension( xMargin, refWidth );
973 int i_yMargin = getDimension( yMargin, refHeight );
976 if( iPosition & POS_LEFT )
978 else if( iPosition & POS_RIGHT )
979 *p_x = refWidth - width - i_xMargin;
981 *p_x = ( refWidth - width ) / 2;
984 if( iPosition & POS_TOP )
986 else if( iPosition & POS_BOTTOM )
987 *p_y = refHeight - height - i_yMargin;
989 *p_y = ( refHeight - height ) / 2;
997 // compute offset against the current object size
998 int i_xOffset = getDimension( xOffset, width );
999 int i_yOffset = getDimension( yOffset, height );
1008 void SkinParser::updateWindowPos( int width, int height )
1010 BuilderData::Window win = m_pData->m_listWindow.back();
1011 m_pData->m_listWindow.pop_back();
1013 int refWidth, refHeight;
1014 getRefDimensions( refWidth, refHeight, true );
1015 convertPosition( win.m_position,
1016 win.m_xOffset, win.m_yOffset,
1017 win.m_xMargin, win.m_yMargin,
1018 width, height, refWidth, refHeight,
1019 &win.m_xPos, &win.m_yPos );
1021 m_pData->m_listWindow.push_back( win );