]> git.sesse.net Git - vlc/commitdiff
Fix skins2 Drag&Drop to accept files with non-ANSI CP characters
authorMarian Durkovic <md@videolan.org>
Wed, 8 Nov 2006 13:29:36 +0000 (13:29 +0000)
committerMarian Durkovic <md@videolan.org>
Wed, 8 Nov 2006 13:29:36 +0000 (13:29 +0000)
modules/gui/skins2/src/skin_common.hpp
modules/gui/skins2/win32/win32_dragdrop.cpp

index a36a05f53b1e5b73d13ca34868e3e2c6d4066d89..41b3b458102611bf900a4038ff27675209e02901 100644 (file)
@@ -76,6 +76,14 @@ static inline string sFromLocale( const string &rLocale )
     return res;
 }
 
+/// Wrapper around FromWide, to avoid the need to call free()
+static inline string sFromWide( const wstring &rWide )
+{
+    char *s = FromWide( rWide.c_str() );
+    string res = s;
+    free( s );
+    return res;
+}
 
 /// Wrapper around ToLocale, to avoid the need to call LocaleFree()
 static inline string sToLocale( const string &rUTF8 )
index fb1136d73d464313257e809765ee6c77922f2b3a..9d37ae42d43891771393e81e6dbababe1915a90c 100644 (file)
@@ -146,22 +146,43 @@ STDMETHODIMP Win32DragDrop::Drop( LPDATAOBJECT pDataObj, DWORD grfKeyState,
 
 void Win32DragDrop::HandleDrop( HDROP HDrop )
 {
-    // Get the number of dropped files
-    int nbFiles = DragQueryFile( HDrop, 0xFFFFFFFF, NULL, 0 );
+    if( GetVersion() < 0x80000000 )
+    {
+        // Use Unicode for Windows NT and above
+
+        // Get the number of dropped files
+        int nbFiles = DragQueryFileW( HDrop, 0xFFFFFFFF, NULL, 0 );
+
+        // For each dropped file
+        for( int i = 0; i < nbFiles; i++ )
+        {
+            // Get the name of the file
+            int nameLength = DragQueryFileW( HDrop, i, NULL, 0 ) + 1;
+            wchar_t *psz_fileName = new WCHAR[nameLength];
+            DragQueryFileW( HDrop, i, psz_fileName, nameLength );
+
+            // Add the file
+            CmdAddItem cmd(getIntf(),sFromWide(psz_fileName),m_playOnDrop);
+            cmd.execute();
 
-    // For each dropped file
-    for( int i = 0; i < nbFiles; i++ )
+            delete[] psz_fileName;
+        }
+    }
+    else
     {
-        // Get the name of the file
-        int nameLength = DragQueryFile( HDrop, i, NULL, 0 ) + 1;
-        char *psz_fileName = new char[nameLength];
-        DragQueryFile( HDrop, i, psz_fileName, nameLength );
+        int nbFiles = DragQueryFile( HDrop, 0xFFFFFFFF, NULL, 0 );
+
+        for( int i = 0; i < nbFiles; i++ )
+        {
+            int nameLength = DragQueryFile( HDrop, i, NULL, 0 ) + 1;
+            char *psz_fileName = new char[nameLength];
+            DragQueryFile( HDrop, i, psz_fileName, nameLength );
 
-        // Add the file
-        CmdAddItem cmd( getIntf(), sFromLocale( psz_fileName ), m_playOnDrop );
-        cmd.execute();
+            CmdAddItem cmd(getIntf(),sFromLocale(psz_fileName),m_playOnDrop);
+            cmd.execute();
 
-        delete[] psz_fileName;
+            delete[] psz_fileName;
+        }
     }
 
     DragFinish( HDrop );