]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins2/win32/win32_factory.cpp
More libvlc_global presumed abuse
[vlc] / modules / gui / skins2 / win32 / win32_factory.cpp
index b95b33b3d399f64dd1de658992d040058ea044ce..6fbe0e87307494ed5e569114faad2916aa0c3b9e 100644 (file)
 #include "win32_popup.hpp"
 #include "win32_loop.hpp"
 #include "../src/theme.hpp"
+#include "../src/window_manager.hpp"
+#include "../commands/cmd_dialogs.hpp"
+#include "../commands/cmd_minimize.hpp"
+
+// Custom message for the notifications of the system tray
+#define MY_WM_TRAYACTION (WM_APP + 1)
 
 
 LRESULT CALLBACK Win32Proc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
@@ -67,11 +73,26 @@ LRESULT CALLBACK Win32Proc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
             }
             else
             {
-                msg_Err( p_intf, "WM_SYSCOMMAND %i", wParam );
+                msg_Dbg( p_intf, "WM_SYSCOMMAND %i", wParam );
+            }
+        }
+        // Handle systray notifications
+        else if( uMsg == MY_WM_TRAYACTION )
+        {
+            if( (UINT)lParam == WM_LBUTTONDOWN )
+            {
+                p_intf->p_sys->p_theme->getWindowManager().raiseAll();
+            }
+            else if( (UINT)lParam == WM_RBUTTONDOWN )
+            {
+                CmdDlgShowPopupMenu aCmdPopup( p_intf );
+                aCmdPopup.execute();
+            }
+            else if( (UINT)lParam == WM_LBUTTONDBLCLK )
+            {
+                CmdRestore aCmdRestore( p_intf );
+                aCmdRestore.execute();
             }
-//            if( (Event *)wParam != NULL )
-//                ( (Event *)wParam )->SendEvent();
-//            return 0;
         }
     }
 
@@ -120,31 +141,53 @@ bool Win32Factory::init()
         // then fine, otherwise return with an error.
         if( !GetClassInfo( m_hInst, _T("SkinWindowClass"), &wndclass ) )
         {
-            msg_Err( getIntf(), "Cannot register window class" );
+            msg_Err( getIntf(), "cannot register window class" );
             return false;
         }
     }
 
     // Create Window
-    m_hParentWindow = CreateWindowEx( WS_EX_APPWINDOW, _T("SkinWindowClass"),
+    m_hParentWindow = CreateWindowEx( WS_EX_TOOLWINDOW, _T("SkinWindowClass"),
         _T("VLC media player"), WS_SYSMENU|WS_POPUP,
         -200, -200, 0, 0, 0, 0, m_hInst, 0 );
     if( m_hParentWindow == NULL )
     {
-        msg_Err( getIntf(), "Cannot create parent window" );
+        msg_Err( getIntf(), "cannot create parent window" );
         return false;
     }
 
+    // Store with it a pointer to the interface thread
+    SetWindowLongPtr( m_hParentWindow, GWLP_USERDATA, (LONG_PTR)getIntf() );
+
     // We do it this way otherwise CreateWindowEx will fail
     // if WS_EX_LAYERED is not supported
     SetWindowLongPtr( m_hParentWindow, GWL_EXSTYLE,
                       GetWindowLong( m_hParentWindow, GWL_EXSTYLE ) |
                       WS_EX_LAYERED );
 
-    // Store with it a pointer to the interface thread
-    SetWindowLongPtr( m_hParentWindow, GWLP_USERDATA, (LONG_PTR)getIntf() );
     ShowWindow( m_hParentWindow, SW_SHOW );
 
+    // Initialize the systray icon
+    m_trayIcon.cbSize = sizeof( NOTIFYICONDATA );
+    m_trayIcon.hWnd = m_hParentWindow;
+    m_trayIcon.uID = 42;
+    m_trayIcon.uFlags = NIF_ICON|NIF_TIP|NIF_MESSAGE;
+    m_trayIcon.uCallbackMessage = MY_WM_TRAYACTION;
+    m_trayIcon.hIcon = LoadIcon( m_hInst, _T("VLC_ICON") );
+    strcpy( m_trayIcon.szTip, "VLC media player" );
+
+    // Show the systray icon if needed
+    if( config_GetInt( getIntf(), "skins2-systray" ) )
+    {
+        addInTray();
+    }
+
+    // Show the task in the task bar if needed
+    if( config_GetInt( getIntf(), "skins2-taskbar" ) )
+    {
+        addInTaskBar();
+    }
+
     // Initialize the OLE library (for drag & drop)
     OleInitialize( NULL );
 
@@ -157,7 +200,7 @@ bool Win32Factory::init()
             GetProcAddress( m_hMsimg32, _T("TransparentBlt") ) ) )
     {
         TransparentBlt = NULL;
-        msg_Dbg( getIntf(), "Couldn't find TransparentBlt(), "
+        msg_Dbg( getIntf(), "couldn't find TransparentBlt(), "
                  "falling back to BitBlt()" );
     }
     if( !m_hMsimg32 ||
@@ -167,7 +210,7 @@ bool Win32Factory::init()
             GetProcAddress( m_hMsimg32, _T("AlphaBlend") ) ) )
     {
         AlphaBlend = NULL;
-        msg_Dbg( getIntf(), "Couldn't find AlphaBlend()" );
+        msg_Dbg( getIntf(), "couldn't find AlphaBlend()" );
     }
 
     // Idem for user32.dll and SetLayeredWindowAttributes()
@@ -178,19 +221,19 @@ bool Win32Factory::init()
             GetProcAddress( m_hUser32, _T("SetLayeredWindowAttributes") ) ) )
     {
         SetLayeredWindowAttributes = NULL;
-        msg_Dbg( getIntf(), "Couldn't find SetLayeredWindowAttributes()" );
+        msg_Dbg( getIntf(), "couldn't find SetLayeredWindowAttributes()" );
     }
 
     // Initialize the resource path
-    m_resourcePath.push_back( (string)getIntf()->p_vlc->psz_homedir +
+    m_resourcePath.push_back( (string)getIntf()->p_libvlc->psz_homedir +
                                "\\" + CONFIG_DIR + "\\skins" );
-    m_resourcePath.push_back( (string)getIntf()->p_libvlc->psz_vlcpath +
+    m_resourcePath.push_back( (string)config_GetDataDir( getIntf() ) +
                               "\\skins" );
-    m_resourcePath.push_back( (string)getIntf()->p_libvlc->psz_vlcpath +
+    m_resourcePath.push_back( (string)config_GetDataDir( getIntf() ) +
                               "\\skins2" );
-    m_resourcePath.push_back( (string)getIntf()->p_libvlc->psz_vlcpath +
+    m_resourcePath.push_back( (string)config_GetDataDir( getIntf() ) +
                               "\\share\\skins" );
-    m_resourcePath.push_back( (string)getIntf()->p_libvlc->psz_vlcpath +
+    m_resourcePath.push_back( (string)config_GetDataDir( getIntf() ) +
                               "\\share\\skins2" );
 
     // All went well
@@ -203,6 +246,9 @@ Win32Factory::~Win32Factory()
     // Uninitialize the OLE library
     OleUninitialize();
 
+    // Remove the systray icon
+    removeFromTray();
+
     if( m_hParentWindow ) DestroyWindow( m_hParentWindow );
 
     // Unload msimg32.dll and user32.dll
@@ -238,6 +284,37 @@ void Win32Factory::minimize()
     ShowWindow( m_hParentWindow, SW_MINIMIZE );
 }
 
+void Win32Factory::restore()
+{
+    ShowWindow( m_hParentWindow, SW_RESTORE );
+}
+
+void Win32Factory::addInTray()
+{
+    Shell_NotifyIcon( NIM_ADD, &m_trayIcon );
+}
+
+void Win32Factory::removeFromTray()
+{
+    Shell_NotifyIcon( NIM_DELETE, &m_trayIcon );
+}
+
+void Win32Factory::addInTaskBar()
+{
+    ShowWindow( m_hParentWindow, SW_HIDE );
+    SetWindowLongPtr( m_hParentWindow, GWL_EXSTYLE,
+                      WS_EX_LAYERED|WS_EX_APPWINDOW );
+    ShowWindow( m_hParentWindow, SW_SHOW );
+}
+
+void Win32Factory::removeFromTaskBar()
+{
+    ShowWindow( m_hParentWindow, SW_HIDE );
+    SetWindowLongPtr( m_hParentWindow, GWL_EXSTYLE,
+                      WS_EX_LAYERED|WS_EX_TOOLWINDOW );
+    ShowWindow( m_hParentWindow, SW_SHOW );
+}
+
 OSTimer *Win32Factory::createOSTimer( CmdGeneric &rCmd )
 {
     return new Win32Timer( getIntf(), rCmd, m_hParentWindow );
@@ -264,10 +341,10 @@ OSPopup *Win32Factory::createOSPopup()
     // In fact, the clean way would be to have in Builder::addPopup() a call
     // to pPopup->associateToWindow() (to be written)... but the problem is
     // that there is no way to access the OS-dependent window handle from a
-    // GenericWindow (we cannot eevn access the OSWindow).
+    // GenericWindow (we cannot even access the OSWindow).
     if( m_windowMap.begin() == m_windowMap.end() )
     {
-        msg_Err( getIntf(), "No window has been created before the popup!" );
+        msg_Err( getIntf(), "no window has been created before the popup!" );
         return NULL;
     }
 
@@ -288,13 +365,12 @@ int Win32Factory::getScreenHeight() const
 }
 
 
-Rect Win32Factory::getWorkArea() const
+SkinsRect Win32Factory::getWorkArea() const
 {
     RECT r;
     SystemParametersInfo( SPI_GETWORKAREA, 0, &r, 0 );
     // Fill a Rect object
-    Rect rect( r.left, r.top, r.right, r.bottom );
-    return rect;
+    return  SkinsRect( r.left, r.top, r.right, r.bottom );
 }