1 /*****************************************************************************
2 * skin_parser.cpp
3 *****************************************************************************
4 * Copyright (C) 2004 the VideoLAN team
5 * $Id: 6cf725f118f896fce091d680362a019043177fda $
6 *
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 *
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.
13 *
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.
18 *
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 *****************************************************************************/
23
24 #include "skin_parser.hpp"
25 #include "../src/os_factory.hpp"
26 #include "interpreter.hpp"
27 #include <math.h>
28
SkinParser(intf_thread_t * pIntf,const std::string & rFileName,const std::string & rPath,BuilderData * pData)29 SkinParser::SkinParser( intf_thread_t *pIntf, const std::string &rFileName,
30 const std::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 )
33 {
34 // Make sure the data is allocated
35 if( m_pData == NULL )
36 {
37 m_pData = new BuilderData();
38 }
39
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" );
44 }
45
46
~SkinParser()47 SkinParser::~SkinParser()
48 {
49 if( m_ownData )
50 {
51 delete m_pData;
52 }
53 }
54
MissingAttr(AttrList_t & attr,const std::string & name,const char * a)55 inline bool SkinParser::MissingAttr( AttrList_t &attr, const std::string &name,
56 const char *a )
57 {
58 if( attr.find(a) == attr.end() )
59 {
60 msg_Err( getIntf(), "bad theme (element: %s, missing attribute: %s)",
61 name.c_str(), a );
62 m_errors = true; return true;
63 }
64 return false;
65 }
66
handleBeginElement(const std::string & rName,AttrList_t & attr)67 void SkinParser::handleBeginElement( const std::string &rName, AttrList_t &attr )
68 {
69 #define RequireAttr( attr, name, a ) \
70 if( MissingAttr( attr, name, a ) ) return;
71
72 if( rName == "Include" )
73 {
74 RequireAttr( attr, rName, "file" );
75
76 OSFactory *pFactory = OSFactory::instance( getIntf() );
77 std::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 );
80 subParser.parse();
81 }
82
83 else if( rName == "IniFile" )
84 {
85 RequireAttr( attr, rName, "id" );
86 RequireAttr( attr, rName, "file" );
87
88 const BuilderData::IniFile iniFile( uniqueId( attr["id"] ),
89 attr["file"] );
90 m_pData->m_listIniFile.push_back( iniFile );
91 }
92
93 else if( rName == "Anchor" )
94 {
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" );
101
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 );
111 }
112
113 else if( rName == "Bitmap" )
114 {
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" );
121
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 );
128 }
129
130 else if( rName == "SubBitmap" )
131 {
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" );
140
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 );
147 }
148
149 else if( rName == "BitmapFont" )
150 {
151 RequireAttr( attr, rName, "id" );
152 RequireAttr( attr, rName, "file" );
153 DefaultAttr( attr, "type", "digits" );
154
155 const BuilderData::BitmapFont font( uniqueId( attr["id"] ),
156 attr["file"], attr["type"] );
157 m_pData->m_listBitmapFont.push_back( font );
158 }
159
160 else if( rName == "PopupMenu" )
161 {
162 RequireAttr( attr, rName, "id" );
163
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 );
168 }
169
170 else if( rName == "MenuItem" )
171 {
172 RequireAttr( attr, rName, "label" );
173 DefaultAttr( attr, "action", "none" );
174
175 const BuilderData::MenuItem item( attr["label"], attr["action"],
176 m_popupPosList.back(),
177 m_curPopupId );
178 m_pData->m_listMenuItem.push_back( item );
179 m_popupPosList.back()++;
180 }
181
182 else if( rName == "MenuSeparator" )
183 {
184 const BuilderData::MenuSeparator sep( m_popupPosList.back(),
185 m_curPopupId );
186 m_pData->m_listMenuSeparator.push_back( sep );
187 m_popupPosList.back()++;
188 }
189
190 else if( rName == "Button" )
191 {
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", "" );
206
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() );
219 m_curLayer++;
220 m_pData->m_listButton.push_back( button );
221 }
222
223 else if( rName == "Checkbox" )
224 {
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", "" );
245
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() );
260 m_curLayer++;
261 m_pData->m_listCheckbox.push_back( checkbox );
262 }
263
264 else if( rName == "Font" )
265 {
266 RequireAttr( attr, rName, "id" );
267 RequireAttr( attr, rName, "file" );
268 DefaultAttr( attr, "size", "12" );
269
270 const BuilderData::Font fontData( uniqueId( attr["id"] ),
271 attr["file"], atoi( attr["size"] ) );
272 m_pData->m_listFont.push_back( fontData );
273 }
274
275 else if( rName == "Group" )
276 {
277 DefaultAttr( attr, "x", "0" );
278 DefaultAttr( attr, "y", "0" );
279
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"] ) );
284 }
285
286 else if( rName == "Image" )
287 {
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" );
304
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() );
320 m_curLayer++;
321 m_pData->m_listImage.push_back( imageData );
322 }
323
324 else if( rName == "Layout" )
325 {
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" );
333
334 int refWidth, refHeight;
335 getRefDimensions( refWidth, refHeight, true );
336 int width = getDimension( attr["width"], refWidth );
337 int height = getDimension( attr["height"], refHeight );
338
339 m_curLayoutId = uniqueId( attr["id"] );
340 const BuilderData::Layout layout( m_curLayoutId,
341 width, height,
342 getDimension( attr["minwidth"], refWidth ),
343 getDimension( attr["maxwidth"], refWidth ),
344 getDimension( attr["minheight"], refHeight ),
345 getDimension( attr["maxheight"], refHeight ),
346 m_curWindowId );
347
348 updateWindowPos( width, height );
349 m_pData->m_listLayout.push_back( layout );
350 m_curLayer = 0;
351 }
352
353 else if( rName == "Panel" )
354 {
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" );
368
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 );
379
380 std::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"] ),
386 width, height,
387 m_curLayer, m_curWindowId, m_curLayoutId, m_panelStack.back() );
388 m_curLayer++;
389 m_pData->m_listPanel.push_back( panel );
390 // Add the panel to the stack
391 m_panelStack.push_back( panelId );
392 }
393
394 else if( rName == "Playlist" )
395 {
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", "" );
423
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 );
434
435 m_curTreeId = uniqueId( attr["id"] );
436 const BuilderData::Tree treeData( m_curTreeId,
437 x + m_xOffset, y + m_yOffset, attr["visible"],
438 attr["flat"],
439 width, height,
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"],
446 attr["fgcolor"],
447 attr["playcolor"],
448 attr["bgcolor1"],
449 attr["bgcolor2"],
450 attr["selcolor"], attr["help"],
451 m_curLayer, m_curWindowId, m_curLayoutId, m_panelStack.back() );
452 m_curLayer++;
453 m_pData->m_listTree.push_back( treeData );
454 }
455 else if( rName == "Playtree" )
456 {
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", "" );
484
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 );
495
496 m_curTreeId = uniqueId( attr["id"] );
497 const BuilderData::Tree treeData( m_curTreeId,
498 x + m_xOffset, y + m_yOffset, attr["visible"],
499 attr["flat"],
500 width, height,
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() );
511 m_curLayer++;
512 m_pData->m_listTree.push_back( treeData );
513 }
514
515 else if( rName == "RadialSlider" )
516 {
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", "" );
532
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"] ),
538 attr["visible"],
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() );
547 m_curLayer++;
548 m_pData->m_listRadialSlider.push_back( radial );
549 }
550
551 else if( rName == "Slider" )
552 {
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", "" );
571
572 std::string newValue = attr["value"];
573 if( m_curTreeId != "" )
574 {
575 // Slider associated to a tree
576 newValue = "playtree.slider";
577 }
578
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() );
594 m_curLayer++;
595 m_pData->m_listSlider.push_back( slider );
596 }
597
598 else if( rName == "SliderBackground" )
599 {
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" );
605
606 // Retrieve the current slider data
607 BuilderData::Slider &slider = m_pData->m_listSlider.back();
608
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"] );
614 }
615
616 else if( rName == "Text" )
617 {
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", "" );
634
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 );
640
641 const BuilderData::Text textData( uniqueId( attr["id"] ),
642 x + m_xOffset, y + m_yOffset,
643 attr["visible"], attr["font"],
644 attr["text"],
645 width,
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() );
654 m_curLayer++;
655 m_pData->m_listText.push_back( textData );
656 }
657
658 else if( rName == "Theme" )
659 {
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" );
665
666 // Check the version
667 if( strcmp( attr["version"], SKINS_DTD_VERSION ) )
668 {
669 msg_Err( getIntf(), "bad theme version : %s (you need version %s)",
670 attr["version"], SKINS_DTD_VERSION );
671 m_errors = true;
672 return;
673 }
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 );
679 }
680
681 else if( rName == "ThemeInfo" )
682 {
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"],
688 attr["author"] );
689 }
690
691 else if( rName == "Video" )
692 {
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", "true" );
709 DefaultAttr( attr, "help", "" );
710
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 );
721
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() );
730 m_curLayer++;
731 m_pData->m_listVideo.push_back( videoData );
732 }
733
734 else if( rName == "Window" )
735 {
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" );
747
748 m_curWindowId = uniqueId( attr["id"] );
749
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,
756 attr["position"],
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 );
763 }
764 #undef RequireAttr
765 }
766
767
handleEndElement(const std::string & rName)768 void SkinParser::handleEndElement( const std::string &rName )
769 {
770 if( rName == "Group" )
771 {
772 m_xOffset -= m_xOffsetList.back();
773 m_yOffset -= m_yOffsetList.back();
774 m_xOffsetList.pop_back();
775 m_yOffsetList.pop_back();
776 }
777 else if( rName == "Playtree" || rName == "Playlist" )
778 {
779 m_curTreeId = "";
780 }
781 else if( rName == "Popup" )
782 {
783 m_curPopupId = "";
784 m_popupPosList.pop_back();
785 }
786 else if( rName == "Panel" )
787 {
788 m_panelStack.pop_back();
789 }
790 }
791
792
convertBoolean(const char * value) const793 bool SkinParser::convertBoolean( const char *value ) const
794 {
795 return strcmp( value, "true" ) == 0;
796 }
797
798
convertColor(const char * transcolor)799 int SkinParser::convertColor( const char *transcolor )
800 {
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 );
806 }
807
808
convertInRange(const char * value,int minValue,int maxValue,const std::string & rAttribute) const809 int SkinParser::convertInRange( const char *value, int minValue, int maxValue,
810 const std::string &rAttribute ) const
811 {
812 int intValue = atoi( value );
813
814 if( intValue < minValue )
815 {
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 );
819 return minValue;
820 }
821 else if( intValue > maxValue )
822 {
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 );
826 return maxValue;
827 }
828 else
829 {
830 return intValue;
831 }
832 }
833
834
generateId() const835 const std::string SkinParser::generateId() const
836 {
837 static int i = 1;
838
839 char genId[5];
840 snprintf( genId, 4, "%i", i++ );
841
842 std::string base = "_ReservedId_" + (std::string)genId;
843
844 return base;
845 }
846
847
uniqueId(const std::string & id)848 const std::string SkinParser::uniqueId( const std::string &id )
849 {
850 std::string newId;
851
852 if( m_idSet.find( id ) != m_idSet.end() )
853 {
854 // The id was already used
855 if( id != "none" )
856 {
857 msg_Warn( getIntf(), "non-unique id: %s", id.c_str() );
858 }
859 newId = generateId();
860 }
861 else
862 {
863 // OK, this is a new id
864 newId = id;
865 }
866
867 // Add the id to the set
868 m_idSet.insert( newId );
869
870 return newId;
871 }
872
getRefDimensions(int & rWidth,int & rHeight,bool toScreen)873 void SkinParser::getRefDimensions( int &rWidth, int &rHeight, bool toScreen )
874 {
875 if( toScreen )
876 {
877 OSFactory *pOsFactory = OSFactory::instance( getIntf() );
878 rWidth = pOsFactory->getScreenWidth();
879 rHeight = pOsFactory->getScreenHeight();
880 return;
881 }
882
883 std::string panelId = m_panelStack.back();
884 if( panelId != "none" )
885 {
886 std::list<BuilderData::Panel>::const_iterator it;
887 for( it = m_pData->m_listPanel.begin();
888 it != m_pData->m_listPanel.end(); ++it )
889 {
890 if( it->m_id == panelId )
891 {
892 rWidth = it->m_width;
893 rHeight = it->m_height;
894 return;
895 }
896 }
897 }
898 else
899 {
900 const BuilderData::Layout layout = m_pData->m_listLayout.back();
901 rWidth = layout.m_width;
902 rHeight = layout.m_height;
903 return;
904 }
905 msg_Err( getIntf(), "failure to retrieve parent panel or layout" );
906 }
907
908
getDimension(std::string value,int refDimension)909 int SkinParser::getDimension( std::string value, int refDimension )
910 {
911 std::string::size_type leftPos;
912
913 leftPos = value.find( "%" );
914 if( leftPos != std::string::npos )
915 {
916 int val = atoi( value.substr( 0, leftPos ).c_str() );
917 return val * refDimension / 100;
918 }
919
920 leftPos = value.find( "px" );
921 if( leftPos != std::string::npos )
922 {
923 int val = atoi( value.substr( 0, leftPos ).c_str() );
924 return val;
925 }
926
927 return atoi( value.c_str() );
928 }
929
930
getPosition(std::string position)931 int SkinParser::getPosition( std::string position )
932 {
933 if( position == "-1" )
934 return POS_UNDEF;
935 else if( position == "Center" )
936 return POS_CENTER;
937 else if( position == "North" )
938 return POS_TOP;
939 else if( position == "South" )
940 return POS_BOTTOM;
941 else if( position == "West" )
942 return POS_LEFT;
943 else if( position == "East" )
944 return POS_RIGHT;
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;
953
954 msg_Err( getIntf(), "unknown value '%s' for position",
955 position.c_str() );
956 return POS_UNDEF;
957 }
958
959
convertPosition(std::string position,std::string xOffset,std::string yOffset,std::string xMargin,std::string yMargin,int width,int height,int refWidth,int refHeight,int * p_x,int * p_y)960 void SkinParser::convertPosition( std::string position, std::string xOffset,
961 std::string yOffset, std::string xMargin,
962 std::string yMargin, int width, int height,
963 int refWidth, int refHeight, int* p_x, int* p_y )
964 {
965 int iPosition = getPosition( position );
966 if( iPosition != POS_UNDEF )
967 {
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 );
974
975 // compute *p_x
976 if( iPosition & POS_LEFT )
977 *p_x = i_xMargin;
978 else if( iPosition & POS_RIGHT )
979 *p_x = refWidth - width - i_xMargin;
980 else
981 *p_x = ( refWidth - width ) / 2;
982
983 // compute *p_y
984 if( iPosition & POS_TOP )
985 *p_y = i_yMargin;
986 else if( iPosition & POS_BOTTOM )
987 *p_y = refHeight - height - i_yMargin;
988 else
989 *p_y = ( refHeight - height ) / 2;
990
991 // add offset
992 *p_x += i_xOffset;
993 *p_y += i_yOffset;
994 }
995 else
996 {
997 // compute offset against the current object size
998 int i_xOffset = getDimension( xOffset, width );
999 int i_yOffset = getDimension( yOffset, height );
1000
1001 // add offset
1002 *p_x += i_xOffset;
1003 *p_y += i_yOffset;
1004 }
1005 }
1006
1007
updateWindowPos(int width,int height)1008 void SkinParser::updateWindowPos( int width, int height )
1009 {
1010 BuilderData::Window win = m_pData->m_listWindow.back();
1011 m_pData->m_listWindow.pop_back();
1012
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 );
1020
1021 m_pData->m_listWindow.push_back( win );
1022 }
1023