]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins/src/skin_main.cpp
* modules/gui/wxwindows/*, include/vlc_interface.h: new generic "open file" dialog.
[vlc] / modules / gui / skins / src / skin_main.cpp
index 2fe3d96376315697097378056cb774d0da03202d..0ed57c2923ecc06e826076e4909a0d3d0bda9453 100644 (file)
@@ -2,7 +2,7 @@
  * skin-main.cpp: skins plugin for VLC
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: skin_main.cpp,v 1.2 2003/03/19 03:11:14 karibu Exp $
+ * $Id: skin_main.cpp,v 1.47 2003/07/20 10:38:49 gbazin Exp $
  *
  * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
  *          Emmanuel Puig    <karibu@via.ecp.fr>
  * USA.
  *****************************************************************************/
 
-
 //--- VLC -------------------------------------------------------------------
 #include <vlc/vlc.h>
 #include <vlc/intf.h>
 #include <vlc/aout.h>
 
 //--- SKIN ------------------------------------------------------------------
-#include "os_api.h"
+#include "../os_api.h"
 #include "event.h"
-#include "dialog.h"
-#include "os_dialog.h"
 #include "banks.h"
 #include "window.h"
 #include "theme.h"
-#include "os_theme.h"
+#include "../os_theme.h"
 #include "themeloader.h"
 #include "vlcproc.h"
 #include "skin_common.h"
+#include "dialogs.h"
 
+#ifdef X11_SKINS
+#include <X11/Xlib.h>
+#include <Imlib2.h>
+#endif
 
 //---------------------------------------------------------------------------
 // Interface thread
@@ -53,8 +55,10 @@ intf_thread_t *g_pIntf;
 //---------------------------------------------------------------------------
 // Exported interface functions.
 //---------------------------------------------------------------------------
+#ifdef WIN32
 extern "C" __declspec( dllexport )
     int __VLC_SYMBOL( vlc_entry ) ( module_t *p_module );
+#endif
 
 //---------------------------------------------------------------------------
 // Local prototypes.
@@ -84,24 +88,95 @@ static int Open ( vlc_object_t *p_this )
 
     p_intf->pf_run = Run;
 
-
     // Suscribe to messages bank
     p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
 
     // Set no new theme when opening file
     p_intf->p_sys->p_new_theme_file = NULL;
 
-    // Initialize Win32 thread
+    // Initialize info on playlist
     p_intf->p_sys->i_index        = -1;
     p_intf->p_sys->i_size         = 0;
 
-
     p_intf->p_sys->i_close_status = VLC_NOTHING;
 
     p_intf->p_sys->p_input = NULL;
     p_intf->p_sys->p_playlist = (playlist_t *)vlc_object_find( p_intf,
         VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
 
+#if defined X11_SKINS
+    // Initialize X11
+    Display *display = XOpenDisplay( NULL );
+    p_intf->p_sys->display = display;
+    vlc_mutex_init( p_intf, &p_intf->p_sys->xlock );
+    // Fake window to receive broadcast events
+    Window root = DefaultRootWindow( display );
+    p_intf->p_sys->mainWin = XCreateSimpleWindow( display, root, 0, 0, 
+                                                  1, 1, 0, 0, 0 );
+    XStoreName( display, p_intf->p_sys->mainWin, "VLC Media Player" );
+
+    // Load the vlc icon
+    int screen = DefaultScreen( display );
+    Screen *screenptr = DefaultScreenOfDisplay( display );
+    Visual *visual = DefaultVisualOfScreen( screenptr );
+    imlib_context_set_display( display );
+    imlib_context_set_visual( visual );
+    imlib_context_set_drawable( root );
+    imlib_context_set_colormap( DefaultColormap( display, screen ) );
+    imlib_context_set_dither( 1 );
+    imlib_context_set_blend( 1 );
+    Imlib_Image img = imlib_load_image_immediately( DATA_PATH"/vlc32x32.png" );
+    if( img == NULL )
+    {
+        // for developers ;)
+        img = imlib_load_image_immediately( "./share/vlc32x32.png" );
+    }
+    if( img == NULL )
+    {
+        msg_Err( p_intf, "loading vlc icon failed" );
+        p_intf->p_sys->iconPixmap = None;
+        p_intf->p_sys->iconMask = None;
+    }
+    else
+    {
+        imlib_context_set_image( img );
+        imlib_render_pixmaps_for_whole_image( &p_intf->p_sys->iconPixmap,
+                                              &p_intf->p_sys->iconMask );
+        imlib_free_image();
+    }
+
+
+#elif defined WIN32
+    // Interface thread id used to post broadcast messages
+    p_intf->p_sys->dwThreadId = GetCurrentThreadId();
+
+    // We dynamically load msimg32.dll to get a pointer to TransparentBlt()
+    p_intf->p_sys->h_msimg32_dll = LoadLibrary("msimg32.dll");
+    if( !p_intf->p_sys->h_msimg32_dll ||
+        !( p_intf->p_sys->TransparentBlt =
+           (BOOL (WINAPI*)(HDC,int,int,int,int,HDC,
+                           int,int,int,int,unsigned int))
+           GetProcAddress( p_intf->p_sys->h_msimg32_dll, "TransparentBlt" ) ) )
+    {
+        p_intf->p_sys->TransparentBlt = NULL;
+        msg_Dbg( p_intf, "Couldn't find TransparentBlt(), "
+                 "falling back to BitBlt()" );
+    }
+
+    // idem for user32.dll and SetLayeredWindowAttributes()
+    p_intf->p_sys->h_user32_dll = LoadLibrary("user32.dll");
+    if( !p_intf->p_sys->h_user32_dll ||
+        !( p_intf->p_sys->SetLayeredWindowAttributes =
+           (BOOL (WINAPI *)(HWND,COLORREF,BYTE,DWORD))
+           GetProcAddress( p_intf->p_sys->h_user32_dll,
+                           "SetLayeredWindowAttributes" ) ) )
+    {
+        p_intf->p_sys->SetLayeredWindowAttributes = NULL;
+        msg_Dbg( p_intf, "Couldn't find SetLayeredWindowAttributes()" );
+    }
+
+#endif
+
     p_intf->p_sys->p_theme = (Theme *)new OSTheme( p_intf );
 
     return( 0 );
@@ -114,7 +189,6 @@ static void Close ( vlc_object_t *p_this )
 {
     intf_thread_t *p_intf = (intf_thread_t *)p_this;
 
-
     if( p_intf->p_sys->p_input )
     {
         vlc_object_release( p_intf->p_sys->p_input );
@@ -128,10 +202,23 @@ static void Close ( vlc_object_t *p_this )
     // Delete theme, it's important to do it correctly
     delete (OSTheme *)p_intf->p_sys->p_theme;
 
+#if defined X11_SKINS
+    XDestroyWindow( p_intf->p_sys->display, p_intf->p_sys->mainWin );
+    XCloseDisplay( p_intf->p_sys->display );
+#endif
+
     // Unsuscribe to messages bank
     msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
 
-
+#ifdef WIN32
+    // Unload msimg32.dll and user32.dll
+    if( p_intf->p_sys->h_msimg32_dll )
+        FreeLibrary( p_intf->p_sys->h_msimg32_dll );
+    if( p_intf->p_sys->h_user32_dll )
+        FreeLibrary( p_intf->p_sys->h_user32_dll );
+#elif defined X11_SKINS
+    vlc_mutex_destroy( &p_intf->p_sys->xlock );
+#endif
 
     // Destroy structure
     free( p_intf->p_sys );
@@ -143,8 +230,13 @@ static void Close ( vlc_object_t *p_this )
 //---------------------------------------------------------------------------
 static void Run( intf_thread_t *p_intf )
 {
+
     int a = OSAPI_GetTime();
 
+    // Initialize the dialog boxes
+    p_intf->p_sys->p_dialogs = new Dialogs( p_intf );
+    if( !p_intf->p_sys->p_dialogs ) return;
+
     // Load a theme
     char *skin_last = config_GetPsz( p_intf, "skin_last" );
     ThemeLoader *Loader = new ThemeLoader( p_intf );
@@ -152,38 +244,41 @@ static void Run( intf_thread_t *p_intf )
     if( skin_last == NULL || ! Loader->Load( skin_last ) )
     {
         // Too bad, it failed. Let's try with the default theme
-        if( ! Loader->Load( DEFAULT_SKIN_FILE ) )
+//        if( ! Loader->Load( DEFAULT_SKIN_FILE ) )
+#ifdef WIN32
+        string default_dir = (string)p_intf->p_libvlc->psz_vlcpath +
+                             DIRECTORY_SEPARATOR + "skins" +
+                             DIRECTORY_SEPARATOR + "default" +
+                             DIRECTORY_SEPARATOR + "theme.xml";
+        if( ! Loader->Load( default_dir ) )
         {
             // Last chance: the user can  select a new theme file
+#else
+        string user_skin = (string)p_intf->p_vlc->psz_homedir +
+                              DIRECTORY_SEPARATOR + CONFIG_DIR +
+                              DIRECTORY_SEPARATOR + "skins" +
+                              DIRECTORY_SEPARATOR + "default" +
+                              DIRECTORY_SEPARATOR + "theme.xml";
+
+        string default_skin = (string)DATA_PATH +
+                              DIRECTORY_SEPARATOR + "skins" +
+                              DIRECTORY_SEPARATOR + "default" +
+                              DIRECTORY_SEPARATOR + "theme.xml";
+        if( !Loader->Load( user_skin ) && !Loader->Load( default_skin ) )
+        {
+#endif
+            p_intf->p_sys->p_dialogs->ShowOpenSkin( 1 /* block */ );
 
-            // Initialize file structure
-            OpenFileDialog *OpenFile;
-            OpenFile = (OpenFileDialog *)new OSOpenFileDialog( _("Open skin"),
-                false );
-            OpenFile->AddFilter( _("Skin files"), "*.vlt" );
-            OpenFile->AddFilter( _("Skin files"), "*.xml" );
-            OpenFile->AddFilter( _("All files"), "*.*" );
-
-            // Open dialog box
-            if( OpenFile->Open() )
-            {
-                // try to load selected file
-                if( ! Loader->Load( OpenFile->FileList.front() ) )
-                {
-                    // He, he, what the hell is he doing ?
-                    delete OpenFile;
-                    delete Loader;
-                    return;
-                }
-            }
-            else
+            // try to load selected file
+            if( !p_intf->p_sys->p_new_theme_file ||
+                !Loader->Load( (string)p_intf->p_sys->p_new_theme_file ) )
             {
-                delete OpenFile;
+                // He, he, what the hell is he doing ?
                 delete Loader;
+                delete p_intf->p_sys->p_dialogs;
+                if( skin_last ) free( skin_last );
                 return;
             }
-
-            delete OpenFile;
         }
     }
 
@@ -191,15 +286,17 @@ static void Run( intf_thread_t *p_intf )
     p_intf->p_sys->p_theme->InitTheme();
     p_intf->p_sys->p_theme->ShowTheme();
 
+    if( skin_last ) free( skin_last );
     delete Loader;
 
-    msg_Err( p_intf, "Load theme time : %i ms", OSAPI_GetTime() - a );
+    msg_Dbg( p_intf, "Load theme time : %i ms", OSAPI_GetTime() - a );
 
-    // Refresh the whole interface
     OSAPI_PostMessage( NULL, VLC_INTF_REFRESH, 0, (int)true );
 
-    // Run interface message loop
     OSRun( p_intf );
+
+    // clean up the dialog boxes
+    delete p_intf->p_sys->p_dialogs;
 }
 
 //---------------------------------------------------------------------------
@@ -223,10 +320,10 @@ vlc_module_begin();
               VLC_FALSE );
     add_bool( "show_in_taskbar", VLC_TRUE, NULL, SKIN_TASKBAR,
               SKIN_TASKBAR_LONG, VLC_FALSE );
-    set_description( _("Skinnable Interface Module") );
+    set_description( _("Skinnable Interface") );
     set_capability( "interface", 30 );
     set_callbacks( Open, Close );
-    add_shortcut( "skins" );
+    set_program( "svlc" );
 vlc_module_end();
 
 
@@ -249,11 +346,6 @@ int SkinManage( intf_thread_t *p_intf )
         p_intf->p_sys->p_input = NULL;
     }
 
-    OSAPI_PostMessage( NULL, VLC_INTF_REFRESH, 0, (long)false );
-
-    // Update the log window
-    //p_intf->p_sys->p_theme->UpdateLog( p_intf->p_sys->p_sub );
-
     //-------------------------------------------------------------------------
     if( p_intf->p_sys->p_input != NULL && !p_intf->p_sys->p_input->b_die )
     {
@@ -273,10 +365,10 @@ int SkinManage( intf_thread_t *p_intf )
             p_intf->p_sys->p_theme->EvtBank->Get( "volume_refresh" ),
             (long)( volume * SLIDER_RANGE / AOUT_VOLUME_MAX ) );
 
-
         // Refresh slider
-        //if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
-        //{
+        // if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
+        if( p_input->stream.b_seekable )
+        {
 #define p_area p_input->stream.p_selected_area
 
             // Set value of sliders
@@ -312,12 +404,11 @@ int SkinManage( intf_thread_t *p_intf )
             delete[] text;
 
 #undef p_area
-        //}
+        }
         vlc_mutex_unlock( &p_input->stream.stream_lock );
     }
     //-------------------------------------------------------------------------
     vlc_mutex_unlock( &p_intf->change_lock );
 
-    return( TRUE );
+    return( VLC_TRUE );
 }
-//---------------------------------------------------------------------------