1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
30 // Be sure things are destroyed in the right order (XXX check)
42 void Theme::loadConfig()
44 msg_Dbg( getIntf(), "loading theme configuration");
46 // Get config from vlcrc file
47 char *save = config_GetPsz( getIntf(), "skins2-config" );
50 // Is there an existing config?
51 if( !strcmp( save, "" ) )
54 m_windowManager.showAll( true );
59 map<string, TopWindowPtr>::const_iterator it;
61 int x, y, visible, scan;
63 // Get config for each window
64 for( it = m_windows.begin(); it != m_windows.end(); it++ )
66 TopWindow *pWin = (*it).second.get();
68 scan = sscanf( &save[i * 13], "(%4d,%4d,%1d)", &x, &y, &visible );
70 // If config has the correct number of arguments
73 m_windowManager.startMove( *pWin );
74 m_windowManager.move( *pWin, x, y );
75 m_windowManager.stopMove();
78 m_windowManager.show( *pWin );
89 void Theme::saveConfig()
91 msg_Dbg( getIntf(), "saving theme configuration");
93 // Initialize char where config is stored
94 char *save = new char[400];
95 map<string, TopWindowPtr>::const_iterator it;
99 // Save config of every window
100 for( it = m_windows.begin(); it != m_windows.end(); it++ )
102 TopWindow *pWin = (*it).second.get();
106 sprintf( &save[i * 13], "(%4d,%4d,%1d)", x, y,
107 pWin->getVisibleVar().get() );
111 // Save config to file
112 config_PutPsz( getIntf(), "skins2-config", save );
120 #define FIND_OBJECT( mapData, mapName ) \
121 map<string, mapData>::const_iterator it; \
122 it = mapName.find( id ); \
123 if( it == mapName.end() ) \
127 return (*it).second.get();
129 // This macro takes an ID of the form "id1;id2;id3", and returns the object
130 // corresponding to the first valid ID. If no ID is valid, it returns NULL.
131 // XXX: should we use a template method instead?
132 #define FIND_FIRST_OBJECT( mapDataPtr, mapName ) \
133 string rightPart = id; \
134 string::size_type pos; \
137 pos = rightPart.find( ";" ); \
138 string leftPart = rightPart.substr( 0, pos ); \
139 map<string, mapDataPtr>::const_iterator it = mapName.find( leftPart ); \
140 if( it != mapName.end() ) \
142 return (*it).second.get(); \
146 if( pos != string::npos ) \
148 rightPart = rightPart.substr( pos, rightPart.size() ); \
150 rightPart.substr( rightPart.find_first_not_of( " \t;" ), \
151 rightPart.size() ); \
154 while( pos != string::npos ); \
157 GenericBitmap *Theme::getBitmapById( const string &id )
159 FIND_FIRST_OBJECT( GenericBitmapPtr, m_bitmaps );
162 GenericFont *Theme::getFontById( const string &id )
164 FIND_FIRST_OBJECT( GenericFontPtr, m_fonts );
167 Popup *Theme::getPopupById( const string &id )
169 FIND_OBJECT( PopupPtr, m_popups );
172 TopWindow *Theme::getWindowById( const string &id )
174 FIND_OBJECT( TopWindowPtr, m_windows );
177 GenericLayout *Theme::getLayoutById( const string &id )
179 FIND_OBJECT( GenericLayoutPtr, m_layouts );
182 CtrlGeneric *Theme::getControlById( const string &id )
184 FIND_OBJECT( CtrlGenericPtr, m_controls );