]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins/src/skin_main.cpp
* modules/gui/wxwindows/*: The wxwindows interface is now a "dialogs provider" module...
[vlc] / modules / gui / skins / src / skin_main.cpp
index 529fb467652b5879a4ec1dbdd9635cfe071fb9a8..b18965b3070ffefd0736a3b1c4118ec46f712f6b 100644 (file)
@@ -2,7 +2,7 @@
  * skin-main.cpp: skins plugin for VLC
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: skin_main.cpp,v 1.10 2003/04/16 21:40:07 ipkiss Exp $
+ * $Id: skin_main.cpp,v 1.45 2003/07/17 17:30:40 gbazin Exp $
  *
  * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
  *          Emmanuel Puig    <karibu@via.ecp.fr>
@@ -23,7 +23,6 @@
  * USA.
  *****************************************************************************/
 
-
 //--- VLC -------------------------------------------------------------------
 #include <vlc/vlc.h>
 #include <vlc/intf.h>
@@ -32,8 +31,6 @@
 //--- SKIN ------------------------------------------------------------------
 #include "../os_api.h"
 #include "event.h"
-#include "dialog.h"
-#include "../os_dialog.h"
 #include "banks.h"
 #include "window.h"
 #include "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
@@ -85,6 +87,7 @@ static int Open ( vlc_object_t *p_this )
     };
 
     p_intf->pf_run = Run;
+    p_intf->p_sys->pf_showdialog = Dialogs::ShowDialog;
 
 
     // Suscribe to messages bank
@@ -93,17 +96,89 @@ static int Open ( vlc_object_t *p_this )
     // 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 );
@@ -116,7 +191,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 );
@@ -130,10 +204,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 );
@@ -146,18 +233,12 @@ static void Close ( vlc_object_t *p_this )
 static void Run( intf_thread_t *p_intf )
 {
 
-#if !defined WIN32
-/* FIXME: should be elsewhere ? */
-    // Initialize GDK
-    int    i_args   = 1;
-    char  *p_args[] = { "", NULL };
-    char **pp_args  = p_args;
-
-    gdk_init( &i_args, &pp_args );
-#endif
-
     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 );
@@ -165,54 +246,61 @@ 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
-
-            // Initialize file structure
-            OpenFileDialog *OpenFile;
-            OpenFile = (OpenFileDialog *)new OSOpenFileDialog( NULL,
-                _("Open skin"), false );
-            OpenFile->AddFilter( _("Skin files"), "*.vlt" );
-            OpenFile->AddFilter( _("Skin files"), "*.xml" );
-            OpenFile->AddFilter( _("All files"), "*.*" );
-
-            // Open dialog box
-            if( OpenFile->Open() )
+#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
+#if 0
+#if !defined(MODULE_NAME_IS_basic_skins)
+            wxMutexGuiEnter();
+            wxFileDialog dialog( NULL,
+                wxU(_("Open a skin file")), wxT(""), wxT(""),
+                wxT("Skin files (*.vlt)|*.vlt|Skin files (*.xml)|*.xml|"
+                    "All files|*.*"), wxOPEN );
+
+            if( dialog.ShowModal() == wxID_OK )
             {
                 // try to load selected file
-                if( ! Loader->Load( OpenFile->FileList.front() ) )
+                if( ! Loader->Load( (string)dialog.GetPath().mb_str() ) )
                 {
                     // He, he, what the hell is he doing ?
-                    delete OpenFile;
                     delete Loader;
+                    wxMutexGuiLeave();
                     return;
                 }
+                wxMutexGuiLeave();
             }
             else
+#endif
+#endif
             {
-                delete OpenFile;
                 delete Loader;
+#if 0
+#if !defined(MODULE_NAME_IS_basic_skins)
+                wxMutexGuiLeave();
+#endif
+#endif
                 return;
             }
-
-            delete OpenFile;
         }
     }
 
@@ -222,13 +310,14 @@ static void Run( intf_thread_t *p_intf )
 
     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;
 }
 
 //---------------------------------------------------------------------------
@@ -255,7 +344,6 @@ vlc_module_begin();
     set_description( _("Skinnable Interface") );
     set_capability( "interface", 30 );
     set_callbacks( Open, Close );
-    add_shortcut( "skins" );
 vlc_module_end();
 
 
@@ -278,11 +366,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 )
     {
@@ -302,10 +385,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
@@ -341,7 +424,7 @@ int SkinManage( intf_thread_t *p_intf )
             delete[] text;
 
 #undef p_area
-        //}
+        }
         vlc_mutex_unlock( &p_input->stream.stream_lock );
     }
     //-------------------------------------------------------------------------
@@ -349,4 +432,3 @@ int SkinManage( intf_thread_t *p_intf )
 
     return( VLC_TRUE );
 }
-//---------------------------------------------------------------------------