]> git.sesse.net Git - vlc/blob - modules/gui/skins2/parser/skin_parser.hpp
skins2: fix nested panels wrongly positioned if not the first child
[vlc] / modules / gui / skins2 / parser / skin_parser.hpp
1 /*****************************************************************************
2  * skin_parser.hpp
3  *****************************************************************************
4  * Copyright (C) 2004 the VideoLAN team
5  * $Id$
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 string &rFileName,
47                 const string &rPath, BuilderData *pData = NULL );
48     virtual ~SkinParser();
49
50     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 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     string m_curBitmapId;
63     string m_curWindowId;
64     string m_curLayoutId;
65     string m_curPopupId;
66     string m_curListId;
67     string m_curTreeId;
68     /// Current position of menu items in the popups
69     list<int> m_popupPosList;
70     /// Current offset of the controls
71     int m_xOffset, m_yOffset;
72     list<int> m_xOffsetList, m_yOffsetList;
73     /// Stack of panel ids
74     list<string> m_panelStack;
75     /// Layer of the current control in the layout
76     int m_curLayer;
77     /// Set of used id
78     set<string> m_idSet;
79
80     /// Callbacks
81     virtual void handleBeginElement( const string &rName,
82                                      AttrList_t &attr );
83     virtual void handleEndElement( const 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 string &rAttribute ) const;
92     //@}
93
94     /// Generate a new id
95     const string generateId() const;
96
97     /// Check if the id is unique, and if not generate a new one
98     const string uniqueId( const string &id );
99
100     /// Management of relative positions
101     void getRefDimensions( int &rWidth, int &rHeight, bool toScreen );
102     int getDimension( string value, int refDimension );
103     int getPosition( string value );
104     void updateWindowPos( int width, int height );
105
106     void convertPosition( string position,
107                           string xOffset, string yOffset,
108                           string xMargin, 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.
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 string &name, const char *a );
119
120 };
121
122 #endif