1 /*****************************************************************************
2 * theme.cpp: Theme class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: theme.cpp,v 1.6 2003/04/13 17:46:23 asmax Exp $
7 * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
8 * Emmanuel Puig <karibu@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,
24 *****************************************************************************/
27 //--- VLC -------------------------------------------------------------------
30 //--- SKIN ------------------------------------------------------------------
33 #include "os_window.h"
35 #include "os_dialog.h"
43 #include "skin_common.h"
47 //---------------------------------------------------------------------------
49 //---------------------------------------------------------------------------
50 Theme::Theme( intf_thread_t *_p_intf )
53 BmpBank = new BitmapBank( p_intf );
54 FntBank = new FontBank( p_intf );
55 EvtBank = new EventBank( p_intf );
56 OffBank = new OffSetBank( p_intf );
58 ConstructPlaylist = false;
61 ShowInTaskbar = false;
64 //---------------------------------------------------------------------------
68 list<Window *>::const_iterator win;
69 for( win = WindowList.begin(); win != WindowList.end(); win++ )
71 delete (OSWindow *)(*win);
73 delete (OSLogWindow *)Log;
79 //---------------------------------------------------------------------------
80 void Theme::ShowTheme()
82 // Get parameters form vlcrc config file
83 if( ShowInTray != (bool)config_GetInt( p_intf, "show_in_tray" ) )
86 if( ShowInTaskbar != (bool)config_GetInt( p_intf, "show_in_taskbar" ) )
89 list<Window *>::const_iterator win;
93 // Synchronize control to visible aspect
94 for( win = WindowList.begin(); win != WindowList.end(); win++ )
96 // Synchronize windows visibility
97 if( (*win)->OnStartThemeVisible )
99 evt1 = (Event *)new OSEvent( p_intf, (*win), WINDOW_OPEN, 1, 0 );
100 evt2 = (Event *)new OSEvent( p_intf, (*win), WINDOW_CLOSE, 0, 0 );
104 evt1 = (Event *)new OSEvent( p_intf, (*win), WINDOW_OPEN, 0, 0 );
105 evt2 = (Event *)new OSEvent( p_intf, (*win), WINDOW_CLOSE, 1, 0 );
107 evt1->PostSynchroMessage( true );
108 evt2->PostSynchroMessage( true );
111 // Initialize magnetism
115 OSAPI_PostMessage( NULL, VLC_SHOW, 0, 0 );
117 //---------------------------------------------------------------------------
118 void Theme::CreateSystemMenu()
120 AddSystemMenu( "Open file...", EvtBank->Get( "open" ) );
121 AddSystemMenu( "Change skin...", EvtBank->Get( "load_skin" ) );
122 AddSystemMenu( "Preferences...", NULL );
123 AddSystemMenu( "SEPARATOR", 0 );
124 AddSystemMenu( "Exit", EvtBank->Get( "quit" ) );
126 //---------------------------------------------------------------------------
127 void Theme::LoadConfig()
129 // Get config from vlcrc file
130 char *save = config_GetPsz( p_intf, "skin_config" );
135 list<Window *>::const_iterator win;
139 // Get config for each window
140 for( win = WindowList.begin(); win != WindowList.end(); win++ )
143 scan = sscanf( &save[i * 13], "(%4d,%4d,%1d)", &x, &y, &v );
145 // If config has the correct number of arguments
148 (*win)->Move( x, y );
149 (*win)->OnStartThemeVisible = (bool)v;
156 //---------------------------------------------------------------------------
157 void Theme::SaveConfig()
159 // Initialize char where config is stored
160 char *save = new char[400];
161 list<Window *>::const_iterator win;
165 // Save config of every window
166 for( win = WindowList.begin(); win != WindowList.end(); win++ )
169 (*win)->GetPos( x, y );
170 sprintf( &save[i * 13], "(%4d,%4d,%1d)", x, y,
171 (*win)->OnStartThemeVisible );
175 // Save config to file
176 config_PutPsz( p_intf, "skin_config", save );
177 config_PutInt( p_intf, "show_in_tray", (int)ShowInTray );
178 config_PutInt( p_intf, "show_in_taskbar", (int)ShowInTaskbar );
179 config_SaveConfigFile( p_intf, "skins" );
185 //---------------------------------------------------------------------------
186 void Theme::StartTheme( bool log, int magnet )
191 Log = (LogWindow *)new OSLogWindow( p_intf );
194 //---------------------------------------------------------------------------
195 void Theme::InitTheme()
197 // Initialize the events
199 fprintf(stderr, "FIXME in theme.cpp !\n");
202 // Initialize the controls
205 // Initialize the windows
208 //---------------------------------------------------------------------------
209 void Theme::InitWindows()
211 for( list<Window *>::const_iterator win = WindowList.begin();
212 win != WindowList.end(); win++ )
217 //---------------------------------------------------------------------------
218 void Theme::InitControls()
220 for( list<Window *>::const_iterator win = WindowList.begin();
221 win != WindowList.end(); win++ )
223 for( unsigned int i = 0; i < (*win)->ControlList.size(); i++ )
225 (*win)->ControlList[i]->Init();
229 //---------------------------------------------------------------------------
230 Window * Theme::GetWindow( string name )
232 for( list<Window *>::const_iterator win = WindowList.begin();
233 win != WindowList.end(); win++ )
235 if( name == OSAPI_GetWindowTitle( *win ) )
242 //---------------------------------------------------------------------------
243 void Theme::MoveSkin( Window *wnd, int left, int top )
245 int x, y, oldx, oldy;
247 list<Anchor *>::const_iterator anc;
248 list<Anchor *>::const_iterator hang;
249 wnd->GetPos( oldx, oldy );
251 // Move child windows recursively
252 for( anc = wnd->AnchorList.begin(); anc != wnd->AnchorList.end(); anc++ )
254 for( hang = (*anc)->HangList.begin(); hang != (*anc)->HangList.end();
257 win = (*hang)->GetParent();
259 MoveSkin( win, left, top );
263 // Move window only if has not been moved yet
267 wnd->Move( oldx + left, oldy + top );
270 //---------------------------------------------------------------------------
271 bool Theme::MoveSkinMagnet( Window *wnd, int left, int top )
274 // If magnetism not activate
277 wnd->Move( left, top );
281 // Screen bounds initialization
285 OSAPI_GetScreenSize( Sx, Sy );
287 wnd->GetSize( width, height );
288 wnd->GetPos( Wx, Wy );
290 // Magnetism with screen bounds
291 if( left < Magnet && left > -Magnet)
293 else if( left + width > Sx - Magnet && left + width < Sx + Magnet )
294 NewLeft = Sx - width;
295 if( top < Magnet && top > -Magnet )
297 else if( top + height > Sy - Magnet && top + height < Sy + Magnet )
298 NewTop = Sy - height;
301 HangToAnchors( wnd, NewLeft, NewTop );
303 // All windows can be moved
304 list<Window *>::const_iterator win;
305 for( win = WindowList.begin(); win != WindowList.end(); win++ )
306 (*win)->Moved = false;
309 MoveSkin( wnd, NewLeft - Wx, NewTop - Wy );
313 //---------------------------------------------------------------------------
314 void Theme::HangToAnchors( Window *wnd, int &x, int &y, bool init )
316 // Magnetism initialization
317 int win_x, win_y, win_anchor_x, win_anchor_y, wnd_anchor_x, wnd_anchor_y;
318 list<Window *>::const_iterator win;
319 list<Anchor *>::const_iterator win_anchor, wnd_anchor;
321 // Parse list of windows
322 for( win = WindowList.begin(); win != WindowList.end(); win++ )
324 // If window is moved window
326 continue; // Check next window
328 // If window is hidden
331 if( (*win)->IsHidden() )
332 continue; // Check next window
336 if( !(*win)->OnStartThemeVisible )
337 continue; // Check next window
340 // Parse anchor lists
341 for( wnd_anchor = wnd->AnchorList.begin();
342 wnd_anchor != wnd->AnchorList.end(); wnd_anchor++ )
344 for( win_anchor = (*win)->AnchorList.begin();
345 win_anchor != (*win)->AnchorList.end(); win_anchor++ )
347 if( (*wnd_anchor)->GetPriority() <
348 (*win_anchor)->GetPriority() )
350 // Parent anchor is win and child is wnd !!!
353 if( !(*win_anchor)->Hang( (*wnd_anchor), x, y ) )
355 // If child is in parent list and parent doesn't hang ch
356 if( (*win_anchor)->IsInList( (*wnd_anchor) ) )
357 (*win_anchor)->Remove( (*wnd_anchor) );
361 // If parent hang child and child is not still in list
362 if( !(*win_anchor)->IsInList( (*wnd_anchor) ) )
364 (*win_anchor)->Add( (*wnd_anchor) );
367 // Move window to stick anchor
368 (*wnd_anchor)->GetPos( wnd_anchor_x, wnd_anchor_y );
369 (*win_anchor)->GetPos( win_anchor_x, win_anchor_y );
370 (*win)->GetPos( win_x, win_y );
372 x = win_x + win_anchor_x - wnd_anchor_x;
373 y = win_y + win_anchor_y - wnd_anchor_y;
379 else if( (*win_anchor)->Hang( (*wnd_anchor), x, y ) )
381 // Move window to stick anchor
382 (*wnd_anchor)->GetPos( wnd_anchor_x, wnd_anchor_y );
383 (*win_anchor)->GetPos( win_anchor_x, win_anchor_y );
384 (*win)->GetPos( win_x, win_y );
386 x = win_x + win_anchor_x - wnd_anchor_x;
387 y = win_y + win_anchor_y - wnd_anchor_y;
395 //---------------------------------------------------------------------------
396 void Theme::CheckAnchors()
398 list<Window *>::const_iterator win;
401 for( win = WindowList.begin(); win != WindowList.end(); win++ )
403 (*win)->GetPos( x, y );
404 HangToAnchors( (*win), x, y, true );
405 (*win)->Move( x, y );
408 //---------------------------------------------------------------------------
409 void Theme::UpdateLog( msg_subscription_t *Sub )
414 //---------------------------------------------------------------------------
415 void Theme::ShowLog( int show )
430 if( Log->IsVisible() )
436 //---------------------------------------------------------------------------
437 void Theme::ClearLog()
442 //---------------------------------------------------------------------------