1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: wrappers.cpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
27 #include "parser_context.hpp"
29 // Current DTD version
30 #define SKINS_DTD_VERSION "2.0"
33 static bool ConvertBoolean( const char *value );
34 static int ConvertColor( const char *transcolor );
37 #define DATA ((ParserContext*)pContext)->m_data
38 #define WIN_ID ((ParserContext*)pContext)->m_curWindowId
39 #define LAY_ID ((ParserContext*)pContext)->m_curLayoutId
40 #define CUR_LIST ((ParserContext*)pContext)->m_curListId
41 #define X_OFFSET ((ParserContext*)pContext)->m_xOffset
42 #define Y_OFFSET ((ParserContext*)pContext)->m_yOffset
43 #define LAYER ((ParserContext*)pContext)->m_curLayer
46 void AddBitmap( void *pContext, char *name, char *file,
49 const BuilderData::Bitmap bitmap( name, file,
50 ConvertColor( transcolor ) );
51 DATA.m_listBitmap.push_back( bitmap );
55 void AddEvent( void *pContext, char *name, char *event, char *key )
57 // const BuilderData:: Command( name, event, key );
61 void AddFont( void *pContext, char *name, char *font, char *size,
62 char *color, char *italic, char *underline )
64 const BuilderData::Font fontData( name, font, atoi( size ) );
65 DATA.m_listFont.push_back( fontData );
69 void AddThemeInfo( void *pContext, char *name, char *author,
70 char *email, char *webpage )
72 msg_Warn( ((ParserContext*)pContext)->m_pIntf,
73 "skin: %s author: %s", name, author );
77 void StartWindow( void *pContext, char *name, char *x, char *y,
78 char *visible, char *dragdrop, char *playOnDrop )
80 const BuilderData::Window window( name, atoi( x ) + X_OFFSET,
81 atoi( y ) + Y_OFFSET, ConvertBoolean( visible ),
82 ConvertBoolean( dragdrop ), ConvertBoolean( playOnDrop ));
83 DATA.m_listWindow.push_back( window );
88 void EndWindow( void *pContext )
90 // ((Builder*)pContext)->endWindow();
94 void StartLayout( void *pContext, char *id, char *width, char *height,
95 char *minwidth, char *maxwidth, char *minheight,
98 const BuilderData::Layout layout( id, atoi( width ), atoi( height ),
99 atoi( minwidth ), atoi( maxwidth ),
100 atoi( minheight ), atoi( maxheight ),
102 DATA.m_listLayout.push_back( layout );
108 void EndLayout( void *pContext )
110 // ((Builder*)pContext)->endLayout();
114 void StartTheme( void *pContext, char *version, char *magnet,
115 char *alpha, char *movealpha, char *fadetime )
118 if( strcmp( version, SKINS_DTD_VERSION ) )
120 msg_Err( ((ParserContext*)pContext)->m_pIntf, "Bad theme version :"
121 " %s (you need version %s)", version, SKINS_DTD_VERSION );
123 const BuilderData::Theme theme( atoi( magnet ),
124 atoi( alpha ), atoi( movealpha ), atoi( fadetime ) );
125 DATA.m_listTheme.push_back( theme );
129 void EndTheme( void *pContext )
131 // ((Builder*)pContext)->endTheme();
135 void StartGroup( void *pContext, char *x, char *y )
137 X_OFFSET += atoi( x );
138 Y_OFFSET += atoi( y );
139 ((ParserContext*)pContext)->m_xOffsetList.push_back( atoi( x ) );
140 ((ParserContext*)pContext)->m_yOffsetList.push_back( atoi( y ) );
144 void EndGroup( void *pContext )
146 X_OFFSET -= ((ParserContext*)pContext)->m_xOffsetList.back();
147 Y_OFFSET -= ((ParserContext*)pContext)->m_yOffsetList.back();
148 ((ParserContext*)pContext)->m_xOffsetList.pop_back();
149 ((ParserContext*)pContext)->m_yOffsetList.pop_back();
153 void AddAnchor( void *pContext, char *x, char *y, char *len,
156 const BuilderData::Anchor anchor( atoi( x ) + X_OFFSET,
157 atoi( y ) + Y_OFFSET, atoi( len ), atoi( priority ), WIN_ID );
158 DATA.m_listAnchor.push_back( anchor );
162 //---------------------------------------------------------------------------
164 //---------------------------------------------------------------------------
165 void AddImage( void *pContext, char *id, char *visible, char *x,
166 char *y, char *lefttop, char *rightbottom, char *image,
167 char *event, char *help )
169 const BuilderData::Image imageData( id, atoi( x ) + X_OFFSET,
170 atoi( y ) + Y_OFFSET, lefttop, rightbottom, ConvertBoolean( visible ),
171 image, event, help, LAYER, WIN_ID, LAY_ID );
173 DATA.m_listImage.push_back( imageData );
177 void AddRectangle( void *pContext, char *id, char *visible, char *x,
178 char *y, char *w, char *h, char *color, char *event,
181 // msg_Warn( ((Builder*)pContext)->getIntf(), "Do we _really_ need a Rectangle control?" );
185 void AddButton( void *pContext,
187 char *x, char *y, char *lefttop, char *rightbottom,
188 char *up, char *down, char *over,
189 char *action, char *tooltiptext, char *help )
191 const BuilderData::Button button( id, atoi( x ) + X_OFFSET,
192 atoi( y ) + Y_OFFSET, lefttop, rightbottom, up, down, over, action,
193 tooltiptext, help, LAYER, WIN_ID, LAY_ID );
195 DATA.m_listButton.push_back( button );
199 void AddCheckBox( void *pContext, char *id,
200 char *x, char *y, char *lefttop, char *rightbottom,
201 char *up1, char *down1, char *over1, char *up2,
202 char *down2, char *over2, char *state, char *action1,
203 char *action2, char *tooltiptext1, char *tooltiptext2,
206 const BuilderData::Checkbox checkbox( id, atoi( x ) + X_OFFSET,
207 atoi( y ) + Y_OFFSET, lefttop, rightbottom, up1, down1, over1, up2,
208 down2, over2, state, action1, action2, tooltiptext1, tooltiptext2,
209 help, LAYER, WIN_ID, LAY_ID );
211 DATA.m_listCheckbox.push_back( checkbox );
215 void AddSlider( void *pContext, char *id, char *visible, char *x, char *y,
216 char *lefttop, char *rightbottom,
217 char *up, char *down, char *over, char *points,
218 char *thickness, char *value, char *tooltiptext, char *help )
220 string newValue = value;
223 // Slider associated to a list
225 newValue = "playlist.slider";
227 const BuilderData::Slider slider( id, visible, atoi( x ) + X_OFFSET,
228 atoi( y ) + Y_OFFSET, lefttop, rightbottom, up, down, over, points,
229 atoi( thickness ), newValue, tooltiptext, help, LAYER, WIN_ID, LAY_ID );
231 DATA.m_listSlider.push_back( slider );
235 void AddRadialSlider( void *pContext, char *id, char *visible, char *x, char *y,
236 char *lefttop, char *rightbottom, char *sequence,
237 char *nbImages, char *minAngle, char *maxAngle,
238 char *value, char *tooltiptext, char *help )
240 const BuilderData::RadialSlider radial( id, visible, atoi( x ) + X_OFFSET,
241 atoi( y ) + Y_OFFSET, lefttop, rightbottom, sequence, atoi( nbImages ),
242 atof( minAngle ) * M_PI / 180, atof( maxAngle ) * M_PI / 180, value,
243 tooltiptext, help, LAYER, WIN_ID, LAY_ID );
245 DATA.m_listRadialSlider.push_back( radial );
249 void AddPlaylist( void *pContext, char *id, char *visible, char *x,
250 char *y, char *width, char *height, char *lefttop,
251 char *rightbottom, char *font, char *var, char *fgcolor,
252 char *playcolor, char *bgcolor1, char *bgcolor2,
253 char *selcolor, char *help )
255 const BuilderData::List listData( id, atoi( x ) + X_OFFSET,
256 atoi( y ) + Y_OFFSET, atoi( width), atoi( height ), lefttop,
257 rightbottom, font, var, ConvertColor( fgcolor ),
258 ConvertColor( playcolor ), ConvertColor( bgcolor1 ),
259 ConvertColor( bgcolor2 ), ConvertColor( selcolor ), help, LAYER,
263 DATA.m_listList.push_back( listData );
267 void AddPlaylistEnd( void *pContext )
273 void AddText( void *pContext, char *id, char *visible, char *x,
274 char *y, char *text, char *font, char *align, char *width,
275 char *display, char *scroll, char *scrollspace, char *help )
277 const BuilderData::Text textData( id, atoi( x ) + X_OFFSET,
278 atoi( y ) + Y_OFFSET, font, text, atoi( width ), help, LAYER, WIN_ID,
281 DATA.m_listText.push_back( textData );
287 //---------------------------------------------------------------------------
289 //---------------------------------------------------------------------------
291 static bool ConvertBoolean( const char *value )
293 return strcmp( value, "true" ) == 0;
297 static int ConvertColor( const char *transcolor )
299 unsigned long iRed, iGreen, iBlue;
300 iRed = iGreen = iBlue = 0;
301 sscanf( transcolor, "#%2lX%2lX%2lX", &iRed, &iGreen, &iBlue );
302 return ( iRed << 16 | iGreen << 8 | iBlue );