]> 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 2b150dfad115f14a8f89a0c03b373b8f73780243..0ed57c2923ecc06e826076e4909a0d3d0bda9453 100644 (file)
@@ -2,7 +2,7 @@
  * skin-main.cpp: skins plugin for VLC
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: skin_main.cpp,v 1.19 2003/04/28 00:18:27 ipkiss 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>
@@ -23,9 +23,6 @@
  * USA.
  *****************************************************************************/
 
-//--- GENERAL ---------------------------------------------------------------
-#include <wx/wx.h>
-
 //--- VLC -------------------------------------------------------------------
 #include <vlc/vlc.h>
 #include <vlc/intf.h>
 #include "themeloader.h"
 #include "vlcproc.h"
 #include "skin_common.h"
-#include "wxdialogs.h"
+#include "dialogs.h"
 
+#ifdef X11_SKINS
+#include <X11/Xlib.h>
+#include <Imlib2.h>
+#endif
 
 //---------------------------------------------------------------------------
 // Interface thread
@@ -87,36 +88,94 @@ 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 WIN32
-    // Initialize GDK
-    int    i_args   = 3;
-    char  *p_args[] = { "", "", "--sync", NULL };
-    char **pp_args  = p_args;
+#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();
+    }
 
-    gdk_init( &i_args, &pp_args );
-#endif
 
-    // Initialize conditions and mutexes
-    vlc_mutex_init( p_intf, &p_intf->p_sys->init_lock );
-    vlc_cond_init( p_intf, &p_intf->p_sys->init_cond );
+#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 );
 
@@ -130,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 );
@@ -144,12 +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 );
 
-    // Destroy conditions and mutexes
-    vlc_cond_destroy( &p_intf->p_sys->init_cond );
-    vlc_mutex_destroy( &p_intf->p_sys->init_lock );
+#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 );
@@ -164,6 +233,10 @@ 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 );
@@ -171,42 +244,39 @@ 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 0
-        if( ! Loader->Load( DEFAULT_SKIN_FILE ) )
-#else
+//        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";
-#else
-// FIXME: find VLC directory 
-        string default_dir = (string)"./share" +
-                             DIRECTORY_SEPARATOR + "skins" +
-                             DIRECTORY_SEPARATOR + "default" +
-                             DIRECTORY_SEPARATOR + "theme.xml";
-#endif
         if( ! Loader->Load( default_dir ) )
-#endif
         {
             // Last chance: the user can  select a new theme file
-            wxFileDialog dialog( NULL, _("Open a skin file"), "", "",
-                "Skin files (*.vlt)|*.vlt|Skin files (*.xml)|*.xml|"
-                    "All files|*.*", wxOPEN );
+#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 */ );
 
-            if( dialog.ShowModal() == wxID_OK )
-            {
-                // try to load selected file
-                if( ! Loader->Load( dialog.GetPath().c_str() ) )
-                {
-                    // He, he, what the hell is he doing ?
-                    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 ) )
             {
+                // He, he, what the hell is he doing ?
                 delete Loader;
+                delete p_intf->p_sys->p_dialogs;
+                if( skin_last ) free( skin_last );
                 return;
             }
         }
@@ -216,14 +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 );
 
     OSRun( p_intf );
+
+    // clean up the dialog boxes
+    delete p_intf->p_sys->p_dialogs;
 }
 
 //---------------------------------------------------------------------------
@@ -250,7 +323,7 @@ vlc_module_begin();
     set_description( _("Skinnable Interface") );
     set_capability( "interface", 30 );
     set_callbacks( Open, Close );
-    add_shortcut( "skins" );
+    set_program( "svlc" );
 vlc_module_end();
 
 
@@ -273,14 +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->MessagesDlg->UpdateLog();
-
-    // Update the file info window
-    p_intf->p_sys->InfoDlg->UpdateFileInfo();
-
     //-------------------------------------------------------------------------
     if( p_intf->p_sys->p_input != NULL && !p_intf->p_sys->p_input->b_die )
     {
@@ -300,7 +365,6 @@ 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 )