1 /*****************************************************************************
2 * skin-main.cpp: skins plugin for VLC
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: skin_main.cpp,v 1.44 2003/07/13 14:55:17 gbazin 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 ---------------------------------------------------------------
32 #if !defined(MODULE_NAME_IS_basic_skins)
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"
54 #if !defined(MODULE_NAME_IS_basic_skins)
55 #include "../../wxwindows/wxwindows.h"
63 //---------------------------------------------------------------------------
65 // It is a global variable because we have C code for the parser, and we
66 // need to access C++ objects from there
67 //---------------------------------------------------------------------------
68 intf_thread_t *g_pIntf;
70 //---------------------------------------------------------------------------
71 // Exported interface functions.
72 //---------------------------------------------------------------------------
74 extern "C" __declspec( dllexport )
75 int __VLC_SYMBOL( vlc_entry ) ( module_t *p_module );
78 //---------------------------------------------------------------------------
80 //---------------------------------------------------------------------------
81 static int Open ( vlc_object_t * );
82 static void Close ( vlc_object_t * );
83 static void Run ( intf_thread_t * );
85 int SkinManage( intf_thread_t *p_intf );
86 void OSRun( intf_thread_t *p_intf );
88 //---------------------------------------------------------------------------
89 // Open: initialize interface
90 //---------------------------------------------------------------------------
91 static int Open ( vlc_object_t *p_this )
93 intf_thread_t *p_intf = (intf_thread_t *)p_this;
96 // Allocate instance and initialize some members
97 p_intf->p_sys = (intf_sys_t *) malloc( sizeof( intf_sys_t ) );
98 if( p_intf->p_sys == NULL )
100 msg_Err( p_intf, "out of memory" );
104 p_intf->pf_run = Run;
107 // Suscribe to messages bank
108 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
110 // Set no new theme when opening file
111 p_intf->p_sys->p_new_theme_file = NULL;
113 // Initialize info on playlist
114 p_intf->p_sys->i_index = -1;
115 p_intf->p_sys->i_size = 0;
117 p_intf->p_sys->i_close_status = VLC_NOTHING;
119 p_intf->p_sys->p_input = NULL;
120 p_intf->p_sys->p_playlist = (playlist_t *)vlc_object_find( p_intf,
121 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
123 #if defined X11_SKINS
125 Display *display = XOpenDisplay( NULL );
126 p_intf->p_sys->display = display;
127 vlc_mutex_init( p_intf, &p_intf->p_sys->xlock );
128 // Fake window to receive broadcast events
129 Window root = DefaultRootWindow( display );
130 p_intf->p_sys->mainWin = XCreateSimpleWindow( display, root, 0, 0,
132 XStoreName( display, p_intf->p_sys->mainWin, "VLC Media Player" );
135 int screen = DefaultScreen( display );
136 Screen *screenptr = DefaultScreenOfDisplay( display );
137 Visual *visual = DefaultVisualOfScreen( screenptr );
138 imlib_context_set_display( display );
139 imlib_context_set_visual( visual );
140 imlib_context_set_drawable( root );
141 imlib_context_set_colormap( DefaultColormap( display, screen ) );
142 imlib_context_set_dither( 1 );
143 imlib_context_set_blend( 1 );
144 Imlib_Image img = imlib_load_image_immediately( DATA_PATH"/vlc32x32.png" );
148 img = imlib_load_image_immediately( "./share/vlc32x32.png" );
152 msg_Err( p_intf, "loading vlc icon failed" );
153 p_intf->p_sys->iconPixmap = None;
154 p_intf->p_sys->iconMask = None;
158 imlib_context_set_image( img );
159 imlib_render_pixmaps_for_whole_image( &p_intf->p_sys->iconPixmap,
160 &p_intf->p_sys->iconMask );
166 // Interface thread id used to post broadcast messages
167 p_intf->p_sys->dwThreadId = GetCurrentThreadId();
169 // We dynamically load msimg32.dll to get a pointer to TransparentBlt()
170 p_intf->p_sys->h_msimg32_dll = LoadLibrary("msimg32.dll");
171 if( !p_intf->p_sys->h_msimg32_dll ||
172 !( p_intf->p_sys->TransparentBlt =
173 (BOOL (WINAPI*)(HDC,int,int,int,int,HDC,
174 int,int,int,int,unsigned int))
175 GetProcAddress( p_intf->p_sys->h_msimg32_dll, "TransparentBlt" ) ) )
177 p_intf->p_sys->TransparentBlt = NULL;
178 msg_Dbg( p_intf, "Couldn't find TransparentBlt(), "
179 "falling back to BitBlt()" );
182 // idem for user32.dll and SetLayeredWindowAttributes()
183 p_intf->p_sys->h_user32_dll = LoadLibrary("user32.dll");
184 if( !p_intf->p_sys->h_user32_dll ||
185 !( p_intf->p_sys->SetLayeredWindowAttributes =
186 (BOOL (WINAPI *)(HWND,COLORREF,BYTE,DWORD))
187 GetProcAddress( p_intf->p_sys->h_user32_dll,
188 "SetLayeredWindowAttributes" ) ) )
190 p_intf->p_sys->SetLayeredWindowAttributes = NULL;
191 msg_Dbg( p_intf, "Couldn't find SetLayeredWindowAttributes()" );
196 p_intf->p_sys->p_theme = (Theme *)new OSTheme( p_intf );
201 //---------------------------------------------------------------------------
202 // Close: destroy interface
203 //---------------------------------------------------------------------------
204 static void Close ( vlc_object_t *p_this )
206 intf_thread_t *p_intf = (intf_thread_t *)p_this;
208 if( p_intf->p_sys->p_input )
210 vlc_object_release( p_intf->p_sys->p_input );
213 if( p_intf->p_sys->p_playlist )
215 vlc_object_release( p_intf->p_sys->p_playlist );
218 // Delete theme, it's important to do it correctly
219 delete (OSTheme *)p_intf->p_sys->p_theme;
221 #if defined X11_SKINS
222 XDestroyWindow( p_intf->p_sys->display, p_intf->p_sys->mainWin );
223 XCloseDisplay( p_intf->p_sys->display );
226 // Unsuscribe to messages bank
227 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
230 // Unload msimg32.dll and user32.dll
231 if( p_intf->p_sys->h_msimg32_dll )
232 FreeLibrary( p_intf->p_sys->h_msimg32_dll );
233 if( p_intf->p_sys->h_user32_dll )
234 FreeLibrary( p_intf->p_sys->h_user32_dll );
235 #elif defined X11_SKINS
236 vlc_mutex_destroy( &p_intf->p_sys->xlock );
240 free( p_intf->p_sys );
244 //---------------------------------------------------------------------------
246 //---------------------------------------------------------------------------
247 static void Run( intf_thread_t *p_intf )
250 int a = OSAPI_GetTime();
252 #if !defined(MODULE_NAME_IS_basic_skins)
253 // Initialize the dialog boxes
254 p_intf->p_sys->p_dialogs = new Dialogs( p_intf );
255 if( !p_intf->p_sys->p_dialogs ||
256 !p_intf->p_sys->p_dialogs->OpenDlg ) return;
260 char *skin_last = config_GetPsz( p_intf, "skin_last" );
261 ThemeLoader *Loader = new ThemeLoader( p_intf );
263 if( skin_last == NULL || ! Loader->Load( skin_last ) )
265 // Too bad, it failed. Let's try with the default theme
266 // if( ! Loader->Load( DEFAULT_SKIN_FILE ) )
268 string default_dir = (string)p_intf->p_libvlc->psz_vlcpath +
269 DIRECTORY_SEPARATOR + "skins" +
270 DIRECTORY_SEPARATOR + "default" +
271 DIRECTORY_SEPARATOR + "theme.xml";
272 if( ! Loader->Load( default_dir ) )
274 // Last chance: the user can select a new theme file
276 string user_skin = (string)p_intf->p_vlc->psz_homedir +
277 DIRECTORY_SEPARATOR + CONFIG_DIR +
278 DIRECTORY_SEPARATOR + "skins" +
279 DIRECTORY_SEPARATOR + "default" +
280 DIRECTORY_SEPARATOR + "theme.xml";
282 string default_skin = (string)DATA_PATH +
283 DIRECTORY_SEPARATOR + "skins" +
284 DIRECTORY_SEPARATOR + "default" +
285 DIRECTORY_SEPARATOR + "theme.xml";
286 if( !Loader->Load( user_skin ) && !Loader->Load( default_skin ) )
289 #if !defined(MODULE_NAME_IS_basic_skins)
291 wxFileDialog dialog( NULL,
292 wxU(_("Open a skin file")), wxT(""), wxT(""),
293 wxT("Skin files (*.vlt)|*.vlt|Skin files (*.xml)|*.xml|"
294 "All files|*.*"), wxOPEN );
296 if( dialog.ShowModal() == wxID_OK )
298 // try to load selected file
299 if( ! Loader->Load( (string)dialog.GetPath().mb_str() ) )
301 // He, he, what the hell is he doing ?
312 #if !defined(MODULE_NAME_IS_basic_skins)
321 p_intf->p_sys->p_theme->InitTheme();
322 p_intf->p_sys->p_theme->ShowTheme();
326 msg_Dbg( p_intf, "Load theme time : %i ms", OSAPI_GetTime() - a );
328 OSAPI_PostMessage( NULL, VLC_INTF_REFRESH, 0, (int)true );
332 #if !defined(MODULE_NAME_IS_basic_skins)
333 // clean up the dialog boxes
334 delete p_intf->p_sys->p_dialogs;
338 //---------------------------------------------------------------------------
340 //---------------------------------------------------------------------------
341 #define DEFAULT_SKIN N_("Last skin actually used")
342 #define DEFAULT_SKIN_LONG N_("Last skin actually used")
343 #define SKIN_CONFIG N_("Config of last used skin")
344 #define SKIN_CONFIG_LONG N_("Config of last used skin")
345 #define SKIN_TRAY N_("Show application in system tray")
346 #define SKIN_TRAY_LONG N_("Show application in system tray")
347 #define SKIN_TASKBAR N_("Show application in taskbar")
348 #define SKIN_TASKBAR_LONG N_("Show application in taskbar")
351 add_string( "skin_last", "", NULL, DEFAULT_SKIN, DEFAULT_SKIN_LONG,
353 add_string( "skin_config", "", NULL, SKIN_CONFIG, SKIN_CONFIG_LONG,
355 add_bool( "show_in_tray", VLC_FALSE, NULL, SKIN_TRAY, SKIN_TRAY_LONG,
357 add_bool( "show_in_taskbar", VLC_TRUE, NULL, SKIN_TASKBAR,
358 SKIN_TASKBAR_LONG, VLC_FALSE );
359 set_description( _("Skinnable Interface") );
360 set_capability( "interface", 30 );
361 set_callbacks( Open, Close );
362 #if !defined(WIN32) && !defined(MODULE_NAME_IS_basic_skins)
363 linked_with_a_crap_library_which_uses_atexit();
368 //---------------------------------------------------------------------------
370 //---------------------------------------------------------------------------
371 int SkinManage( intf_thread_t *p_intf )
373 vlc_mutex_lock( &p_intf->change_lock );
376 if( p_intf->p_sys->p_input == NULL )
378 p_intf->p_sys->p_input = (input_thread_t *)
379 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
381 else if( p_intf->p_sys->p_input->b_dead )
383 vlc_object_release( p_intf->p_sys->p_input );
384 p_intf->p_sys->p_input = NULL;
387 #if !defined(MODULE_NAME_IS_basic_skins) //FIXME
388 // Update the log window
389 p_intf->p_sys->p_dialogs->MessagesDlg->UpdateLog();
391 // Update the file info window
392 p_intf->p_sys->p_dialogs->FileInfoDlg->UpdateFileInfo();
395 //-------------------------------------------------------------------------
396 if( p_intf->p_sys->p_input != NULL && !p_intf->p_sys->p_input->b_die )
398 input_thread_t * p_input = p_intf->p_sys->p_input;
400 vlc_mutex_lock( &p_input->stream.stream_lock );
402 // Refresh sound volume
403 audio_volume_t volume;
405 // Get sound volume from VLC
406 aout_VolumeGet( p_intf, &volume);
409 OSAPI_PostMessage( NULL, CTRL_SET_SLIDER,
411 p_intf->p_sys->p_theme->EvtBank->Get( "volume_refresh" ),
412 (long)( volume * SLIDER_RANGE / AOUT_VOLUME_MAX ) );
415 // if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
416 if( p_input->stream.b_seekable )
418 #define p_area p_input->stream.p_selected_area
420 // Set value of sliders
421 long Value = SLIDER_RANGE *
422 p_input->stream.p_selected_area->i_tell /
423 p_input->stream.p_selected_area->i_size;
426 OSAPI_PostMessage( NULL, CTRL_SET_SLIDER, (unsigned int)
427 p_intf->p_sys->p_theme->EvtBank->Get( "time" ), (long)Value );
429 // Text char * for updating text controls
430 char *text = new char[OFFSETTOTIME_MAX_SIZE];
432 // Create end time text
433 input_OffsetToTime( p_intf->p_sys->p_input, &text[1],
434 p_area->i_size - p_area->i_tell );
436 p_intf->p_sys->p_theme->EvtBank->Get( "left_time" )
437 ->PostTextMessage( text );
439 // Create time text and update
440 input_OffsetToTime( p_intf->p_sys->p_input, text, p_area->i_tell );
441 p_intf->p_sys->p_theme->EvtBank->Get( "time" )
442 ->PostTextMessage( text );
444 // Create total time text
445 input_OffsetToTime( p_intf->p_sys->p_input, text, p_area->i_size );
446 p_intf->p_sys->p_theme->EvtBank->Get( "total_time" )
447 ->PostTextMessage( text );
454 vlc_mutex_unlock( &p_input->stream.stream_lock );
456 //-------------------------------------------------------------------------
457 vlc_mutex_unlock( &p_intf->change_lock );