1 /*****************************************************************************
2 * skin-main.cpp: skins plugin for VLC
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: skin_main.cpp,v 1.35 2003/06/09 12:33:16 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 *****************************************************************************/
26 //--- VLC -------------------------------------------------------------------
31 //--- GENERAL ---------------------------------------------------------------
33 #ifdef WIN32 /* mingw32 hack */
37 /* Let vlc take care of the i18n stuff */
38 #define WXINTL_NO_GETTEXT_MACRO
42 //--- SKIN ------------------------------------------------------------------
43 #include "../os_api.h"
48 #include "../os_theme.h"
49 #include "themeloader.h"
51 #include "skin_common.h"
55 #include "../../wxwindows/wxwindows.h"
62 //---------------------------------------------------------------------------
64 // It is a global variable because we have C code for the parser, and we
65 // need to access C++ objects from there
66 //---------------------------------------------------------------------------
67 intf_thread_t *g_pIntf;
69 //---------------------------------------------------------------------------
70 // Exported interface functions.
71 //---------------------------------------------------------------------------
73 extern "C" __declspec( dllexport )
74 int __VLC_SYMBOL( vlc_entry ) ( module_t *p_module );
77 //---------------------------------------------------------------------------
79 //---------------------------------------------------------------------------
80 static int Open ( vlc_object_t * );
81 static void Close ( vlc_object_t * );
82 static void Run ( intf_thread_t * );
84 int SkinManage( intf_thread_t *p_intf );
85 void OSRun( intf_thread_t *p_intf );
87 //---------------------------------------------------------------------------
88 // Open: initialize interface
89 //---------------------------------------------------------------------------
90 static int Open ( vlc_object_t *p_this )
92 intf_thread_t *p_intf = (intf_thread_t *)p_this;
95 // Allocate instance and initialize some members
96 p_intf->p_sys = (intf_sys_t *) malloc( sizeof( intf_sys_t ) );
97 if( p_intf->p_sys == NULL )
99 msg_Err( p_intf, "out of memory" );
103 p_intf->pf_run = Run;
106 // Suscribe to messages bank
107 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
109 // Set no new theme when opening file
110 p_intf->p_sys->p_new_theme_file = NULL;
112 // Initialize info on playlist
113 p_intf->p_sys->i_index = -1;
114 p_intf->p_sys->i_size = 0;
116 p_intf->p_sys->i_close_status = VLC_NOTHING;
118 p_intf->p_sys->p_input = NULL;
119 p_intf->p_sys->p_playlist = (playlist_t *)vlc_object_find( p_intf,
120 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
125 char *p_args[] = { "", "", "--sync", NULL };
126 char **pp_args = p_args;
128 gdk_init( &i_args, &pp_args );
130 #elif defined X11_SKINS
132 p_intf->p_sys->display = XOpenDisplay( NULL );
133 vlc_mutex_init( p_intf, &p_intf->p_sys->xlock );
136 // Interface thread id used to post broadcast messages
137 p_intf->p_sys->dwThreadId = GetCurrentThreadId();
139 // We dynamically load msimg32.dll to get a pointer to TransparentBlt()
140 p_intf->p_sys->h_msimg32_dll = LoadLibrary("msimg32.dll");
141 if( !p_intf->p_sys->h_msimg32_dll ||
142 !( p_intf->p_sys->TransparentBlt =
143 (BOOL (WINAPI*)(HDC,int,int,int,int,HDC,
144 int,int,int,int,unsigned int))
145 GetProcAddress( p_intf->p_sys->h_msimg32_dll, "TransparentBlt" ) ) )
147 p_intf->p_sys->TransparentBlt = NULL;
148 msg_Dbg( p_intf, "Couldn't find TransparentBlt(), "
149 "falling back to BitBlt()" );
152 // idem for user32.dll and SetLayeredWindowAttributes()
153 p_intf->p_sys->h_user32_dll = LoadLibrary("user32.dll");
154 if( !p_intf->p_sys->h_user32_dll ||
155 !( p_intf->p_sys->SetLayeredWindowAttributes =
156 (BOOL (WINAPI *)(HWND,COLORREF,BYTE,DWORD))
157 GetProcAddress( p_intf->p_sys->h_user32_dll,
158 "SetLayeredWindowAttributes" ) ) )
160 p_intf->p_sys->SetLayeredWindowAttributes = NULL;
161 msg_Dbg( p_intf, "Couldn't find SetLayeredWindowAttributes()" );
166 p_intf->p_sys->p_theme = (Theme *)new OSTheme( p_intf );
171 //---------------------------------------------------------------------------
172 // Close: destroy interface
173 //---------------------------------------------------------------------------
174 static void Close ( vlc_object_t *p_this )
176 intf_thread_t *p_intf = (intf_thread_t *)p_this;
178 if( p_intf->p_sys->p_input )
180 vlc_object_release( p_intf->p_sys->p_input );
183 if( p_intf->p_sys->p_playlist )
185 vlc_object_release( p_intf->p_sys->p_playlist );
188 // Delete theme, it's important to do it correctly
189 delete (OSTheme *)p_intf->p_sys->p_theme;
191 #if defined X11_SKINS
192 XCloseDisplay( p_intf->p_sys->display );
195 // Unsuscribe to messages bank
196 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
199 // Unload msimg32.dll and user32.dll
200 if( p_intf->p_sys->h_msimg32_dll )
201 FreeLibrary( p_intf->p_sys->h_msimg32_dll );
202 if( p_intf->p_sys->h_user32_dll )
203 FreeLibrary( p_intf->p_sys->h_user32_dll );
204 #elif defined X11_SKINS
205 vlc_mutex_destroy( &p_intf->p_sys->xlock );
209 free( p_intf->p_sys );
213 //---------------------------------------------------------------------------
215 //---------------------------------------------------------------------------
216 static void Run( intf_thread_t *p_intf )
219 int a = OSAPI_GetTime();
222 // Initialize the dialog boxes
223 p_intf->p_sys->p_dialogs = new Dialogs( p_intf );
224 if( !p_intf->p_sys->p_dialogs ||
225 !p_intf->p_sys->p_dialogs->OpenDlg ) return;
229 char *skin_last = config_GetPsz( p_intf, "skin_last" );
230 ThemeLoader *Loader = new ThemeLoader( p_intf );
232 if( skin_last == NULL || ! Loader->Load( skin_last ) )
234 // Too bad, it failed. Let's try with the default theme
236 if( ! Loader->Load( DEFAULT_SKIN_FILE ) )
239 string default_dir = (string)p_intf->p_libvlc->psz_vlcpath +
240 DIRECTORY_SEPARATOR + "skins" +
241 DIRECTORY_SEPARATOR + "default" +
242 DIRECTORY_SEPARATOR + "theme.xml";
244 // FIXME: find VLC directory
245 string default_dir = (string)"./share" +
246 DIRECTORY_SEPARATOR + "skins" +
247 DIRECTORY_SEPARATOR + "default" +
248 DIRECTORY_SEPARATOR + "theme.xml";
250 if( ! Loader->Load( default_dir ) )
253 // Last chance: the user can select a new theme file
256 wxFileDialog dialog( NULL,
257 wxU(_("Open a skin file")), wxT(""), wxT(""),
258 wxT("Skin files (*.vlt)|*.vlt|Skin files (*.xml)|*.xml|"
259 "All files|*.*"), wxOPEN );
261 if( dialog.ShowModal() == wxID_OK )
263 // try to load selected file
264 if( ! Loader->Load( (string)dialog.GetPath().mb_str() ) )
266 // He, he, what the hell is he doing ?
286 p_intf->p_sys->p_theme->InitTheme();
287 p_intf->p_sys->p_theme->ShowTheme();
291 msg_Dbg( p_intf, "Load theme time : %i ms", OSAPI_GetTime() - a );
293 // Refresh the whole interface
294 OSAPI_PostMessage( NULL, VLC_INTF_REFRESH, 0, (int)true );
299 // clean up the dialog boxes
300 delete p_intf->p_sys->p_dialogs;
304 //---------------------------------------------------------------------------
306 //---------------------------------------------------------------------------
307 #define DEFAULT_SKIN N_("Last skin actually used")
308 #define DEFAULT_SKIN_LONG N_("Last skin actually used")
309 #define SKIN_CONFIG N_("Config of last used skin")
310 #define SKIN_CONFIG_LONG N_("Config of last used skin")
311 #define SKIN_TRAY N_("Show application in system tray")
312 #define SKIN_TRAY_LONG N_("Show application in system tray")
313 #define SKIN_TASKBAR N_("Show application in taskbar")
314 #define SKIN_TASKBAR_LONG N_("Show application in taskbar")
317 add_string( "skin_last", "", NULL, DEFAULT_SKIN, DEFAULT_SKIN_LONG,
319 add_string( "skin_config", "", NULL, SKIN_CONFIG, SKIN_CONFIG_LONG,
321 add_bool( "show_in_tray", VLC_FALSE, NULL, SKIN_TRAY, SKIN_TRAY_LONG,
323 add_bool( "show_in_taskbar", VLC_TRUE, NULL, SKIN_TASKBAR,
324 SKIN_TASKBAR_LONG, VLC_FALSE );
325 set_description( _("Skinnable Interface") );
326 set_capability( "interface", 30 );
327 set_callbacks( Open, Close );
331 //---------------------------------------------------------------------------
333 //---------------------------------------------------------------------------
334 int SkinManage( intf_thread_t *p_intf )
336 vlc_mutex_lock( &p_intf->change_lock );
339 if( p_intf->p_sys->p_input == NULL )
341 p_intf->p_sys->p_input = (input_thread_t *)
342 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
344 else if( p_intf->p_sys->p_input->b_dead )
346 vlc_object_release( p_intf->p_sys->p_input );
347 p_intf->p_sys->p_input = NULL;
350 OSAPI_PostMessage( NULL, VLC_INTF_REFRESH, 0, (long)false );
352 #ifndef BASIC_SKINS //FIXME
353 // Update the log window
354 p_intf->p_sys->p_dialogs->MessagesDlg->UpdateLog();
356 // Update the file info window
357 p_intf->p_sys->p_dialogs->FileInfoDlg->UpdateFileInfo();
360 //-------------------------------------------------------------------------
361 if( p_intf->p_sys->p_input != NULL && !p_intf->p_sys->p_input->b_die )
363 input_thread_t * p_input = p_intf->p_sys->p_input;
365 vlc_mutex_lock( &p_input->stream.stream_lock );
367 // Refresh sound volume
368 audio_volume_t volume;
370 // Get sound volume from VLC
371 aout_VolumeGet( p_intf, &volume);
374 OSAPI_PostMessage( NULL, CTRL_SET_SLIDER,
376 p_intf->p_sys->p_theme->EvtBank->Get( "volume_refresh" ),
377 (long)( volume * SLIDER_RANGE / AOUT_VOLUME_MAX ) );
381 // if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
382 if( p_input->stream.b_seekable )
384 #define p_area p_input->stream.p_selected_area
386 // Set value of sliders
387 long Value = SLIDER_RANGE *
388 p_input->stream.p_selected_area->i_tell /
389 p_input->stream.p_selected_area->i_size;
392 OSAPI_PostMessage( NULL, CTRL_SET_SLIDER, (unsigned int)
393 p_intf->p_sys->p_theme->EvtBank->Get( "time" ), (long)Value );
395 // Text char * for updating text controls
396 char *text = new char[OFFSETTOTIME_MAX_SIZE];
398 // Create end time text
399 input_OffsetToTime( p_intf->p_sys->p_input, &text[1],
400 p_area->i_size - p_area->i_tell );
402 p_intf->p_sys->p_theme->EvtBank->Get( "left_time" )
403 ->PostTextMessage( text );
405 // Create time text and update
406 input_OffsetToTime( p_intf->p_sys->p_input, text, p_area->i_tell );
407 p_intf->p_sys->p_theme->EvtBank->Get( "time" )
408 ->PostTextMessage( text );
410 // Create total time text
411 input_OffsetToTime( p_intf->p_sys->p_input, text, p_area->i_size );
412 p_intf->p_sys->p_theme->EvtBank->Get( "total_time" )
413 ->PostTextMessage( text );
420 vlc_mutex_unlock( &p_input->stream.stream_lock );
422 //-------------------------------------------------------------------------
423 vlc_mutex_unlock( &p_intf->change_lock );