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, "lefttop", "lefttop" );
560 DefaultAttr( attr, "rightbottom", "lefttop" );
561 DefaultAttr( attr, "xkeepratio", "false" );
562 DefaultAttr( attr, "ykeepratio", "false" );
563 DefaultAttr( attr, "down", "none" );
564 DefaultAttr( attr, "over", "none" );
565 DefaultAttr( attr, "thickness", "10" );
566 DefaultAttr( attr, "value", "none" );
567 DefaultAttr( attr, "tooltiptext", "" );
568 DefaultAttr( attr, "help", "" );
570 string newValue = attr["value"];
571 if( m_curTreeId != "" )
573 // Slider associated to a tree
574 newValue = "playtree.slider";
577 int refWidth, refHeight;
578 getRefDimensions( refWidth, refHeight, false );
579 int x = getDimension( attr["x"], refWidth );
580 int y = getDimension( attr["y"], refHeight );
581 const BuilderData::Slider slider( uniqueId( attr["id"] ),
582 attr["visible"], x + m_xOffset,
583 y + m_yOffset, attr["lefttop"],
584 attr["rightbottom"], convertBoolean( attr["xkeepratio"] ),
585 convertBoolean( attr["ykeepratio"] ), attr["up"], attr["down"],
586 attr["over"], attr["points"], atoi( attr["thickness"] ),
587 newValue, "none", 0, 0, 0, 0, attr["tooltiptext"],
588 attr["help"], m_curLayer, m_curWindowId, m_curLayoutId,
589 m_panelStack.back() );
591 m_pData->m_listSlider.push_back( slider );
594 else if( rName == "SliderBackground" )
596 RequireAttr( attr, rName, "image" );
597 DefaultAttr( attr, "nbhoriz", "1" );
598 DefaultAttr( attr, "nbvert", "1" );
599 DefaultAttr( attr, "padhoriz", "0" );
600 DefaultAttr( attr, "padvert", "0" );
602 // Retrieve the current slider data
603 BuilderData::Slider &slider = m_pData->m_listSlider.back();
605 slider.m_imageId = attr["image"];
606 slider.m_nbHoriz = atoi( attr["nbhoriz"] );
607 slider.m_nbVert = atoi( attr["nbvert"] );
608 slider.m_padHoriz = atoi( attr["padhoriz"] );
609 slider.m_padVert = atoi( attr["padvert"] );
612 else if( rName == "Text" )
614 RequireAttr( attr, rName, "font" );
615 DefaultAttr( attr, "id", "none" );
616 DefaultAttr( attr, "visible", "true" );
617 DefaultAttr( attr, "x", "0" );
618 DefaultAttr( attr, "y", "0" );
619 DefaultAttr( attr, "text", "" );
620 DefaultAttr( attr, "color", "#000000" );
621 DefaultAttr( attr, "scrolling", "auto" );
622 DefaultAttr( attr, "alignment", "left" );
623 DefaultAttr( attr, "focus", "true" );
624 DefaultAttr( attr, "width", "0" );
625 DefaultAttr( attr, "lefttop", "lefttop" );
626 DefaultAttr( attr, "rightbottom", "lefttop" );
627 DefaultAttr( attr, "xkeepratio", "false" );
628 DefaultAttr( attr, "ykeepratio", "false" );
629 DefaultAttr( attr, "help", "" );
631 int refWidth, refHeight;
632 getRefDimensions( refWidth, refHeight, false );
633 int x = getDimension( attr["x"], refWidth );
634 int y = getDimension( attr["y"], refHeight );
635 int width = getDimension( attr["width"], refWidth );
637 const BuilderData::Text textData( uniqueId( attr["id"] ),
638 x + m_xOffset, y + m_yOffset,
639 attr["visible"], attr["font"],
642 attr["lefttop"], attr["rightbottom"],
643 convertBoolean( attr["xkeepratio"] ),
644 convertBoolean( attr["ykeepratio"] ),
645 convertColor( attr["color"] ),
646 attr["scrolling"], attr["alignment"],
647 attr["focus"], attr["help"],
648 m_curLayer, m_curWindowId, m_curLayoutId,
649 m_panelStack.back() );
651 m_pData->m_listText.push_back( textData );
654 else if( rName == "Theme" )
656 RequireAttr( attr, rName, "version" );
657 DefaultAttr( attr, "tooltipfont", "defaultfont" );
658 DefaultAttr( attr, "magnet", "15" );
659 DefaultAttr( attr, "alpha", "255" );
660 DefaultAttr( attr, "movealpha", "255" );
663 if( strcmp( attr["version"], SKINS_DTD_VERSION ) )
665 msg_Err( getIntf(), "bad theme version : %s (you need version %s)",
666 attr["version"], SKINS_DTD_VERSION );
670 const BuilderData::Theme theme( attr["tooltipfont"],
671 atoi( attr["magnet"] ),
672 convertInRange( attr["alpha"], 1, 255, "alpha" ),
673 convertInRange( attr["movealpha"], 1, 255, "movealpha" ) );
674 m_pData->m_listTheme.push_back( theme );
677 else if( rName == "ThemeInfo" )
679 DefaultAttr( attr, "name", "" );
680 DefaultAttr( attr, "author", "" );
681 DefaultAttr( attr, "email", "" );
682 DefaultAttr( attr, "website", "" );
683 msg_Info( getIntf(), "skin: %s author: %s", attr["name"],
687 else if( rName == "Video" )
689 DefaultAttr( attr, "id", "none" );
690 DefaultAttr( attr, "visible", "true" );
691 DefaultAttr( attr, "x", "0" );
692 DefaultAttr( attr, "y", "0" );
693 DefaultAttr( attr, "width", "0" );
694 DefaultAttr( attr, "height", "0" );
695 DefaultAttr( attr, "position", "-1" );
696 DefaultAttr( attr, "xoffset", "0" );
697 DefaultAttr( attr, "yoffset", "0" );
698 DefaultAttr( attr, "xmargin", "0" );
699 DefaultAttr( attr, "ymargin", "0" );
700 DefaultAttr( attr, "lefttop", "lefttop" );
701 DefaultAttr( attr, "rightbottom", "lefttop" );
702 DefaultAttr( attr, "xkeepratio", "false" );
703 DefaultAttr( attr, "ykeepratio", "false" );
704 DefaultAttr( attr, "autoresize", "false" );
705 DefaultAttr( attr, "help", "" );
707 int refWidth, refHeight;
708 getRefDimensions( refWidth, refHeight, false );
709 int x = getDimension( attr["x"], refWidth );
710 int y = getDimension( attr["y"], refHeight );
711 int width = getDimension( attr["width"], refWidth );
712 int height = getDimension( attr["height"], refHeight );
713 convertPosition( attr["position"],
714 attr["xoffset"], attr["yoffset"],
715 attr["xmargin"], attr["ymargin"],
716 width, height, refWidth, refHeight, &x, &y );
718 const BuilderData::Video videoData( uniqueId( attr["id"] ),
719 x + m_xOffset, y + m_yOffset, width, height,
720 attr["lefttop"], attr["rightbottom"],
721 convertBoolean( attr["xkeepratio"] ),
722 convertBoolean( attr["ykeepratio"] ),
723 attr["visible"], convertBoolean( attr["autoresize"] ),
724 attr["help"], m_curLayer, m_curWindowId, m_curLayoutId,
725 m_panelStack.back() );
727 m_pData->m_listVideo.push_back( videoData );
730 else if( rName == "Window" )
732 DefaultAttr( attr, "id", "none" );
733 DefaultAttr( attr, "visible", "true" );
734 DefaultAttr( attr, "x", "0" );
735 DefaultAttr( attr, "y", "0" );
736 DefaultAttr( attr, "position", "-1" );
737 DefaultAttr( attr, "xoffset", "0" );
738 DefaultAttr( attr, "yoffset", "0" );
739 DefaultAttr( attr, "xmargin", "0" );
740 DefaultAttr( attr, "ymargin", "0" );
741 DefaultAttr( attr, "dragdrop", "true" );
742 DefaultAttr( attr, "playondrop", "true" );
744 m_curWindowId = uniqueId( attr["id"] );
746 int refWidth, refHeight;
747 getRefDimensions( refWidth, refHeight, true );
748 int x = getDimension( attr["x"], refWidth );
749 int y = getDimension( attr["y"], refHeight );
750 const BuilderData::Window window( m_curWindowId,
751 x + m_xOffset, y + m_yOffset,
753 attr["xoffset"], attr["yoffset"],
754 attr["xmargin"], attr["ymargin"],
755 convertBoolean( attr["visible"] ),
756 convertBoolean( attr["dragdrop"] ),
757 convertBoolean( attr["playondrop"] ) );
758 m_pData->m_listWindow.push_back( window );
764 void SkinParser::handleEndElement( const string &rName )
766 if( rName == "Group" )
768 m_xOffset -= m_xOffsetList.back();
769 m_yOffset -= m_yOffsetList.back();
770 m_xOffsetList.pop_back();
771 m_yOffsetList.pop_back();
773 else if( rName == "Playtree" || rName == "Playlist" )
777 else if( rName == "Popup" )
780 m_popupPosList.pop_back();
782 else if( rName == "Panel" )
784 m_panelStack.pop_back();
789 bool SkinParser::convertBoolean( const char *value ) const
791 return strcmp( value, "true" ) == 0;
795 int SkinParser::convertColor( const char *transcolor )
797 // TODO: move to the builder
798 unsigned long iRed, iGreen, iBlue;
799 iRed = iGreen = iBlue = 0;
800 sscanf( transcolor, "#%2lX%2lX%2lX", &iRed, &iGreen, &iBlue );
801 return ( iRed << 16 | iGreen << 8 | iBlue );
805 int SkinParser::convertInRange( const char *value, int minValue, int maxValue,
806 const string &rAttribute ) const
808 int intValue = atoi( value );
810 if( intValue < minValue )
812 msg_Warn( getIntf(), "value of \"%s\" attribute (%i) is out of the "
813 "expected range [%i, %i], using %i instead",
814 rAttribute.c_str(), intValue, minValue, maxValue, minValue );
817 else if( intValue > maxValue )
819 msg_Warn( getIntf(), "value of \"%s\" attribute (%i) is out of the "
820 "expected range [%i, %i], using %i instead",
821 rAttribute.c_str(), intValue, minValue, maxValue, maxValue );
831 const string SkinParser::generateId() const
836 snprintf( genId, 4, "%i", i++ );
838 string base = "_ReservedId_" + (string)genId;
844 const string SkinParser::uniqueId( const string &id )
848 if( m_idSet.find( id ) != m_idSet.end() )
850 // The id was already used
853 msg_Warn( getIntf(), "non-unique id: %s", id.c_str() );
855 newId = generateId();
859 // OK, this is a new id
863 // Add the id to the set
864 m_idSet.insert( newId );
869 void SkinParser::getRefDimensions( int &rWidth, int &rHeight, bool toScreen )
873 OSFactory *pOsFactory = OSFactory::instance( getIntf() );
874 rWidth = pOsFactory->getScreenWidth();
875 rHeight = pOsFactory->getScreenHeight();
879 string panelId = m_panelStack.back();
880 if( panelId != "none" )
882 list<BuilderData::Panel>::const_iterator it;
883 for( it = m_pData->m_listPanel.begin();
884 it != m_pData->m_listPanel.end(); ++it )
886 if( it->m_id == panelId )
888 rWidth = it->m_width;
889 rHeight = it->m_height;
896 const BuilderData::Layout layout = m_pData->m_listLayout.back();
897 rWidth = layout.m_width;
898 rHeight = layout.m_height;
901 msg_Err( getIntf(), "failure to retrieve parent panel or layout" );
905 int SkinParser::getDimension( string value, int refDimension )
907 string::size_type leftPos;
909 leftPos = value.find( "%" );
910 if( leftPos != string::npos )
912 int val = atoi( value.substr( 0, leftPos ).c_str() );
913 return val * refDimension / 100;
916 leftPos = value.find( "px" );
917 if( leftPos != string::npos )
919 int val = atoi( value.substr( 0, leftPos ).c_str() );
923 return atoi( value.c_str() );
927 int SkinParser::getPosition( string position )
929 if( position == "-1" )
931 else if( position == "Center" )
933 else if( position == "North" )
935 else if( position == "South" )
937 else if( position == "West" )
939 else if( position == "East" )
941 else if( position == "NorthWest" )
942 return POS_TOP | POS_LEFT;
943 else if( position == "NorthEast" )
944 return POS_TOP | POS_RIGHT;
945 else if( position == "SouthWest" )
946 return POS_BOTTOM | POS_LEFT;
947 else if( position == "SouthEast" )
948 return POS_BOTTOM | POS_RIGHT;
950 msg_Err( getIntf(), "unknown value '%s' for position",
956 void SkinParser::convertPosition( string position, string xOffset,
957 string yOffset, string xMargin,
958 string yMargin, int width, int height,
959 int refWidth, int refHeight, int* p_x, int* p_y )
961 int iPosition = getPosition( position );
962 if( iPosition != POS_UNDEF )
964 // compute offset against the parent object size
965 // for backward compatibility
966 int i_xOffset = getDimension( xOffset, refWidth );
967 int i_yOffset = getDimension( yOffset, refHeight );
968 int i_xMargin = getDimension( xMargin, refWidth );
969 int i_yMargin = getDimension( yMargin, refHeight );
972 if( iPosition & POS_LEFT )
974 else if( iPosition & POS_RIGHT )
975 *p_x = refWidth - width - i_xMargin;
977 *p_x = ( refWidth - width ) / 2;
980 if( iPosition & POS_TOP )
982 else if( iPosition & POS_BOTTOM )
983 *p_y = refHeight - height - i_yMargin;
985 *p_y = ( refHeight - height ) / 2;
993 // compute offset against the current object size
994 int i_xOffset = getDimension( xOffset, width );
995 int i_yOffset = getDimension( yOffset, height );
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, refHeight;
1010 getRefDimensions( refWidth, refHeight, 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 );