From 1cf7350be358c16dc9d89d58786af1b7c60ce511 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Olivier=20Teuli=C3=A8re?= <ipkiss@videolan.org>
Date: Sat, 13 May 2006 17:54:21 +0000
Subject: [PATCH]  * skins2: new skins2-taskbar configuration option, to allow
 removing VLC from the task bar on Windows (changing this option takes effect
 on the fly)

---
 modules/gui/skins2/commands/cmd_minimize.cpp | 16 +++++++++
 modules/gui/skins2/commands/cmd_minimize.hpp |  3 +-
 modules/gui/skins2/macosx/macosx_factory.cpp | 10 ++++++
 modules/gui/skins2/macosx/macosx_factory.hpp |  6 ++++
 modules/gui/skins2/src/os_factory.hpp        |  6 ++++
 modules/gui/skins2/src/skin_main.cpp         | 36 +++++++++++++++++++
 modules/gui/skins2/win32/win32_factory.cpp   | 38 +++++++++++++++-----
 modules/gui/skins2/win32/win32_factory.hpp   |  6 ++++
 modules/gui/skins2/x11/x11_factory.cpp       | 10 ++++++
 modules/gui/skins2/x11/x11_factory.hpp       |  6 ++++
 10 files changed, 128 insertions(+), 9 deletions(-)

diff --git a/modules/gui/skins2/commands/cmd_minimize.cpp b/modules/gui/skins2/commands/cmd_minimize.cpp
index dfdf2d54ca71..815e6f6c15b1 100644
--- a/modules/gui/skins2/commands/cmd_minimize.cpp
+++ b/modules/gui/skins2/commands/cmd_minimize.cpp
@@ -56,3 +56,19 @@ void CmdRemoveFromTray::execute()
     pOsFactory->removeFromTray();
 }
 
+
+void CmdAddInTaskBar::execute()
+{
+    // Get the instance of OSFactory
+    OSFactory *pOsFactory = OSFactory::instance( getIntf() );
+    pOsFactory->addInTaskBar();
+}
+
+
+void CmdRemoveFromTaskBar::execute()
+{
+    // Get the instance of OSFactory
+    OSFactory *pOsFactory = OSFactory::instance( getIntf() );
+    pOsFactory->removeFromTaskBar();
+}
+
diff --git a/modules/gui/skins2/commands/cmd_minimize.hpp b/modules/gui/skins2/commands/cmd_minimize.hpp
index 6cf78c0eaa62..4748313a0033 100644
--- a/modules/gui/skins2/commands/cmd_minimize.hpp
+++ b/modules/gui/skins2/commands/cmd_minimize.hpp
@@ -27,10 +27,11 @@
 #include "cmd_generic.hpp"
 
 
-/// Command to minimize VLC
 DEFINE_COMMAND(Minimize, "minimize" )
 DEFINE_COMMAND(Restore, "restore" )
 DEFINE_COMMAND(AddInTray, "add in tray" )
 DEFINE_COMMAND(RemoveFromTray, "remove from tray" )
+DEFINE_COMMAND(AddInTaskBar, "add in taskbar" )
+DEFINE_COMMAND(RemoveFromTaskBar, "remove from taskbar" )
 
 #endif
diff --git a/modules/gui/skins2/macosx/macosx_factory.cpp b/modules/gui/skins2/macosx/macosx_factory.cpp
index cf07bbc877be..be00008591b8 100644
--- a/modules/gui/skins2/macosx/macosx_factory.cpp
+++ b/modules/gui/skins2/macosx/macosx_factory.cpp
@@ -89,6 +89,16 @@ void MacOSXFactory::removeFromTray()
     // TODO
 }
 
+void MacOSXFactory::addInTaskBar()
+{
+    // TODO
+}
+
+void MacOSXFactory::removeFromTaskBar()
+{
+    // TODO
+}
+
 OSTimer *MacOSXFactory::createOSTimer( const Callback &rCallback )
 {
     return new MacOSXTimer( getIntf(), rCallback );
diff --git a/modules/gui/skins2/macosx/macosx_factory.hpp b/modules/gui/skins2/macosx/macosx_factory.hpp
index 30f7bfef9d8e..f2cd09a02fa0 100644
--- a/modules/gui/skins2/macosx/macosx_factory.hpp
+++ b/modules/gui/skins2/macosx/macosx_factory.hpp
@@ -61,6 +61,12 @@ class MacOSXFactory: public OSFactory
         /// Remove the icon from the system tray
         virtual void removeFromTray();
 
+        /// Show the task in the task bar
+        virtual void addInTaskBar();
+
+        /// Remove the task from the task bar
+        virtual void removeFromTaskBar();
+
         /// Instantiate an OSWindow object
         virtual OSWindow *createOSWindow( GenericWindow &rWindow,
                                           bool dragDrop, bool playOnDrop,
diff --git a/modules/gui/skins2/src/os_factory.hpp b/modules/gui/skins2/src/os_factory.hpp
index f01fba01ecc6..cced448cb9b1 100644
--- a/modules/gui/skins2/src/os_factory.hpp
+++ b/modules/gui/skins2/src/os_factory.hpp
@@ -90,6 +90,12 @@ class OSFactory: public SkinObject
         /// Remove the icon from the system tray
         virtual void removeFromTray() = 0;
 
+        /// Show the task in the task bar
+        virtual void addInTaskBar() = 0;
+
+        /// Remove the task from the task bar
+        virtual void removeFromTaskBar() = 0;
+
         /// Instantiate an OSTimer with the given command
         virtual OSTimer *createOSTimer( CmdGeneric &rCmd ) = 0;
 
diff --git a/modules/gui/skins2/src/skin_main.cpp b/modules/gui/skins2/src/skin_main.cpp
index f6511d14305c..503966114f0f 100644
--- a/modules/gui/skins2/src/skin_main.cpp
+++ b/modules/gui/skins2/src/skin_main.cpp
@@ -65,6 +65,9 @@ static int DemuxControl( demux_t *, int, va_list );
 static int onSystrayChange( vlc_object_t *pObj, const char *pVariable,
                             vlc_value_t oldVal, vlc_value_t newVal,
                             void *pParam );
+static int onTaskBarChange( vlc_object_t *pObj, const char *pVariable,
+                            vlc_value_t oldVal, vlc_value_t newVal,
+                            void *pParam );
 
 
 //---------------------------------------------------------------------------
@@ -378,6 +381,35 @@ static int onSystrayChange( vlc_object_t *pObj, const char *pVariable,
 }
 
 
+/// Callback for the systray configuration option
+static int onTaskBarChange( vlc_object_t *pObj, const char *pVariable,
+                            vlc_value_t oldVal, vlc_value_t newVal,
+                            void *pParam )
+{
+    intf_thread_t *pIntf =
+        (intf_thread_t*)vlc_object_find( pObj, VLC_OBJECT_INTF, FIND_ANYWHERE );
+
+    if( pIntf == NULL )
+    {
+        return VLC_EGENERIC;
+    }
+
+    AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
+    if( newVal.b_bool )
+    {
+        CmdAddInTaskBar *pCmd = new CmdAddInTaskBar( pIntf );
+        pQueue->push( CmdGenericPtr( pCmd ) );
+    }
+    else
+    {
+        CmdRemoveFromTaskBar *pCmd = new CmdRemoveFromTaskBar( pIntf );
+        pQueue->push( CmdGenericPtr( pCmd ) );
+    }
+
+    vlc_object_release( pIntf );
+}
+
+
 //---------------------------------------------------------------------------
 // Module descriptor
 //---------------------------------------------------------------------------
@@ -388,6 +420,8 @@ static int onSystrayChange( vlc_object_t *pObj, const char *pVariable,
         "This option is updated automatically, do not touch it." )
 #define SKINS2_SYSTRAY      N_("Systray icon")
 #define SKINS2_SYSTRAY_LONG N_("Show a systray icon for VLC")
+#define SKINS2_TASKBAR      N_("Show VLC on the taskbar")
+#define SKINS2_TASKBAR_LONG N_("Show VLC on the taskbar")
 #define SKINS2_TRANSPARENCY      N_("Enable transparency effects")
 #define SKINS2_TRANSPARENCY_LONG N_("You can disable all transparency effects"\
     " if you want. This is mainly useful when moving windows does not behave" \
@@ -405,6 +439,8 @@ vlc_module_begin();
 #ifdef WIN32
     add_bool( "skins2-systray", VLC_FALSE, onSystrayChange, SKINS2_SYSTRAY,
               SKINS2_SYSTRAY_LONG, VLC_FALSE );
+    add_bool( "skins2-taskbar", VLC_TRUE, onTaskBarChange, SKINS2_TASKBAR,
+              SKINS2_TASKBAR_LONG, VLC_FALSE );
     add_bool( "skins2-transparency", VLC_FALSE, NULL, SKINS2_TRANSPARENCY,
               SKINS2_TRANSPARENCY_LONG, VLC_FALSE );
 #endif
diff --git a/modules/gui/skins2/win32/win32_factory.cpp b/modules/gui/skins2/win32/win32_factory.cpp
index b94227b0bf4c..7e384f869139 100644
--- a/modules/gui/skins2/win32/win32_factory.cpp
+++ b/modules/gui/skins2/win32/win32_factory.cpp
@@ -150,7 +150,7 @@ bool Win32Factory::init()
     }
 
     // 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 )
@@ -162,6 +162,14 @@ bool Win32Factory::init()
     // 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 );
+
+    ShowWindow( m_hParentWindow, SW_SHOW );
+
     // Initialize the systray icon
     m_trayIcon.cbSize = sizeof( NOTIFYICONDATA );
     m_trayIcon.hWnd = m_hParentWindow;
@@ -177,13 +185,11 @@ bool Win32Factory::init()
         addInTray();
     }
 
-    // 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 );
-
-    ShowWindow( m_hParentWindow, SW_SHOW );
+    // 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 );
@@ -296,6 +302,22 @@ 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 );
diff --git a/modules/gui/skins2/win32/win32_factory.hpp b/modules/gui/skins2/win32/win32_factory.hpp
index f0815bbf1bfb..42a181799ed4 100644
--- a/modules/gui/skins2/win32/win32_factory.hpp
+++ b/modules/gui/skins2/win32/win32_factory.hpp
@@ -66,6 +66,12 @@ class Win32Factory: public OSFactory
         /// Remove the icon from the system tray
         virtual void removeFromTray();
 
+        /// Show the task in the task bar
+        virtual void addInTaskBar();
+
+        /// Remove the task from the task bar
+        virtual void removeFromTaskBar();
+
         /// Instantiate an OSTimer with the given command
         virtual OSTimer *createOSTimer( CmdGeneric &rCmd );
 
diff --git a/modules/gui/skins2/x11/x11_factory.cpp b/modules/gui/skins2/x11/x11_factory.cpp
index 38e38a402db5..a010836b37b2 100644
--- a/modules/gui/skins2/x11/x11_factory.cpp
+++ b/modules/gui/skins2/x11/x11_factory.cpp
@@ -118,6 +118,16 @@ void X11Factory::removeFromTray()
     // TODO
 }
 
+void X11Factory::addInTaskBar()
+{
+    // TODO
+}
+
+void X11Factory::removeFromTaskBar()
+{
+    // TODO
+}
+
 OSTimer *X11Factory::createOSTimer( CmdGeneric &rCmd )
 {
     return new X11Timer( getIntf(), rCmd );
diff --git a/modules/gui/skins2/x11/x11_factory.hpp b/modules/gui/skins2/x11/x11_factory.hpp
index 9a7ce7b9fbfb..bf99bbb3b342 100644
--- a/modules/gui/skins2/x11/x11_factory.hpp
+++ b/modules/gui/skins2/x11/x11_factory.hpp
@@ -74,6 +74,12 @@ class X11Factory: public OSFactory
         /// Remove the icon from the system tray
         virtual void removeFromTray();
 
+        /// Show the task in the task bar
+        virtual void addInTaskBar();
+
+        /// Remove the task from the task bar
+        virtual void removeFromTaskBar();
+
         /// Instantiate an OSWindow object
         virtual OSWindow *createOSWindow( GenericWindow &rWindow,
                                           bool dragDrop, bool playOnDrop,
-- 
GitLab