1 /*****************************************************************************
2  * skin_parser.hpp
3  *****************************************************************************
4  * Copyright (C) 2004 the VideoLAN team
5  * $Id: a284b35d58a096760feeb10c8d51a449b5b6aac0 $
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 along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23 
24 #ifndef SKIN_PARSER_HPP
25 #define SKIN_PARSER_HPP
26 
27 #include "xmlparser.hpp"
28 #include "builder_data.hpp"
29 #include <set>
30 
31 
32 /// Parser for the skin DTD
33 class SkinParser: public XMLParser
34 {
35 public:
36 
37     enum {
38         POS_UNDEF  = 0,
39         POS_CENTER = 1,
40         POS_LEFT   = 2,
41         POS_RIGHT  = 4,
42         POS_TOP    = 8,
43         POS_BOTTOM = 16,
44     };
45 
46     SkinParser( intf_thread_t *pIntf, const std::string &rFileName,
47                 const std::string &rPath, BuilderData *pData = NULL );
48     virtual ~SkinParser();
49 
getData() const50     const BuilderData &getData() const { return *m_pData; }
51 
52     static int convertColor( const char *transcolor );
53 
54 private:
55     /// Path of the theme
56     const std::string m_path;
57     /// Container for mapping data from the XML
58     BuilderData *m_pData;
59     /// Indicate whether the class owns the data
60     bool m_ownData;
61     /// Current IDs
62     std::string m_curBitmapId;
63     std::string m_curWindowId;
64     std::string m_curLayoutId;
65     std::string m_curPopupId;
66     std::string m_curListId;
67     std::string m_curTreeId;
68     /// Current position of menu items in the popups
69     std::list<int> m_popupPosList;
70     /// Current offset of the controls
71     int m_xOffset, m_yOffset;
72     std::list<int> m_xOffsetList, m_yOffsetList;
73     /// Stack of panel ids
74     std::list<std::string> m_panelStack;
75     /// Layer of the current control in the layout
76     int m_curLayer;
77     /// Set of used id
78     std::set<std::string> m_idSet;
79 
80     /// Callbacks
81     virtual void handleBeginElement( const std::string &rName,
82                                      AttrList_t &attr );
83     virtual void handleEndElement( const std::string &rName );
84 
85     /// Helper functions
86     //@{
87     bool convertBoolean( const char *value ) const;
88     /// Transform to int, and check that it is in the given range (if not,
89     /// the closest range boundary will be used)
90     int convertInRange( const char *value, int minValue, int maxValue,
91                         const std::string &rAttribute ) const;
92     //@}
93 
94     /// Generate a new id
95     const std::string generateId() const;
96 
97     /// Check if the id is unique, and if not generate a new one
98     const std::string uniqueId( const std::string &id );
99 
100     /// Management of relative positions
101     void getRefDimensions( int &rWidth, int &rHeight, bool toScreen );
102     int getDimension( std::string value, int refDimension );
103     int getPosition( std::string value );
104     void updateWindowPos( int width, int height );
105 
106     void convertPosition( std::string position,
107                           std::string xOffset, std::string yOffset,
108                           std::string xMargin, std::string yMargin,
109                           int width, int height, int refWidth, int refHeight,
110                           int* p_x, int* p_y );
111 
112     /// Helper for handleBeginElement: Provide default attribute if missing.
DefaultAttr(AttrList_t & attr,const char * a,const char * b)113     static void DefaultAttr( AttrList_t &attr, const char *a, const char *b )
114     {
115         if( attr.find(a) == attr.end() ) attr[strdup(a)] = strdup(b);
116     }
117     /// Helper for handleBeginElement: Complain if a named attribute is missing.
118     bool MissingAttr( AttrList_t &attr, const std::string &name, const char *a );
119 
120 };
121 
122 #endif
123