diff options
Diffstat (limited to 'vcl/win/app/salinst.cxx')
-rw-r--r-- | vcl/win/app/salinst.cxx | 175 |
1 files changed, 72 insertions, 103 deletions
diff --git a/vcl/win/app/salinst.cxx b/vcl/win/app/salinst.cxx index bc0c908d9af2..437e8b594c65 100644 --- a/vcl/win/app/salinst.cxx +++ b/vcl/win/app/salinst.cxx @@ -67,9 +67,6 @@ #include <gdiplus.h> #include <shlobj.h> -#ifdef _WIN32_WINNT_WINBLUE -#include <VersionHelpers.h> -#endif #include "postwin.h" #if defined _MSC_VER @@ -359,35 +356,6 @@ SalInstance* CreateSalInstance() { SalData* pSalData = GetSalData(); - // determine the windows version - aSalShlData.mbWXP = 0; - aSalShlData.mbWVista = 0; - aSalShlData.mbW7 = 0; -// the Win32 SDK 8.1 deprecates GetVersionEx() -#ifdef _WIN32_WINNT_WINBLUE - aSalShlData.mbWXP = IsWindowsXPOrGreater() ? 1 : 0; - aSalShlData.mbWVista = IsWindowsVistaOrGreater() ? 1 : 0; - aSalShlData.mbW7 = IsWindows7OrGreater() ? 1 : 0; -#else - OSVERSIONINFO aVersionInfo; - memset( &aVersionInfo, 0, sizeof(aVersionInfo) ); - aVersionInfo.dwOSVersionInfoSize = sizeof( aVersionInfo ); - if (GetVersionEx( &aVersionInfo )) - { - // Windows XP ? - if (aVersionInfo.dwMajorVersion > 5 || - (aVersionInfo.dwMajorVersion == 5 && aVersionInfo.dwMinorVersion >= 1)) - aSalShlData.mbWXP = 1; - // Windows Vista ? - if (aVersionInfo.dwMajorVersion >= 6) - aSalShlData.mbWVista = 1; - // Windows 7 ? - if (aVersionInfo.dwMajorVersion > 6 || - (aVersionInfo.dwMajorVersion == 6 && aVersionInfo.dwMinorVersion >= 1)) - aSalShlData.mbW7 = 1; - } -#endif - pSalData->mnAppThreadId = GetCurrentThreadId(); // register frame class @@ -414,8 +382,7 @@ SalInstance* CreateSalInstance() return nullptr; // shadow effect for popups on XP - if( aSalShlData.mbWXP ) - aWndClassEx.style |= CS_DROPSHADOW; + aWndClassEx.style |= CS_DROPSHADOW; aWndClassEx.lpszClassName = SAL_TMPSUBFRAME_CLASSNAMEW; if ( !RegisterClassExW( &aWndClassEx ) ) return nullptr; @@ -865,50 +832,47 @@ void WinSalInstance::AddToRecentDocumentList(const OUString& rFileUrl, const OUS if (osl::FileBase::E_None == rc) { - if ( aSalShlData.mbW7 ) - { - IShellItem* pShellItem = nullptr; + IShellItem* pShellItem = nullptr; - HRESULT hr = SHCreateItemFromParsingName(SAL_W(system_path.getStr()), nullptr, IID_PPV_ARGS(&pShellItem)); + HRESULT hr = SHCreateItemFromParsingName(SAL_W(system_path.getStr()), nullptr, IID_PPV_ARGS(&pShellItem)); - if ( SUCCEEDED(hr) && pShellItem ) + if ( SUCCEEDED(hr) && pShellItem ) + { + OUString sApplicationName; + + if ( rDocumentService == "com.sun.star.text.TextDocument" || + rDocumentService == "com.sun.star.text.GlobalDocument" || + rDocumentService == "com.sun.star.text.WebDocument" || + rDocumentService == "com.sun.star.xforms.XMLFormDocument" ) + sApplicationName = "Writer"; + else if ( rDocumentService == "com.sun.star.sheet.SpreadsheetDocument" || + rDocumentService == "com.sun.star.chart2.ChartDocument" ) + sApplicationName = "Calc"; + else if ( rDocumentService == "com.sun.star.presentation.PresentationDocument" ) + sApplicationName = "Impress"; + else if ( rDocumentService == "com.sun.star.drawing.DrawingDocument" ) + sApplicationName = "Draw"; + else if ( rDocumentService == "com.sun.star.formula.FormulaProperties" ) + sApplicationName = "Math"; + else if ( rDocumentService == "com.sun.star.sdb.DatabaseDocument" || + rDocumentService == "com.sun.star.sdb.OfficeDatabaseDocument" || + rDocumentService == "com.sun.star.sdb.RelationDesign" || + rDocumentService == "com.sun.star.sdb.QueryDesign" || + rDocumentService == "com.sun.star.sdb.TableDesign" || + rDocumentService == "com.sun.star.sdb.DataSourceBrowser" ) + sApplicationName = "Base"; + + if ( !sApplicationName.isEmpty() ) { - OUString sApplicationName; - - if ( rDocumentService == "com.sun.star.text.TextDocument" || - rDocumentService == "com.sun.star.text.GlobalDocument" || - rDocumentService == "com.sun.star.text.WebDocument" || - rDocumentService == "com.sun.star.xforms.XMLFormDocument" ) - sApplicationName = "Writer"; - else if ( rDocumentService == "com.sun.star.sheet.SpreadsheetDocument" || - rDocumentService == "com.sun.star.chart2.ChartDocument" ) - sApplicationName = "Calc"; - else if ( rDocumentService == "com.sun.star.presentation.PresentationDocument" ) - sApplicationName = "Impress"; - else if ( rDocumentService == "com.sun.star.drawing.DrawingDocument" ) - sApplicationName = "Draw"; - else if ( rDocumentService == "com.sun.star.formula.FormulaProperties" ) - sApplicationName = "Math"; - else if ( rDocumentService == "com.sun.star.sdb.DatabaseDocument" || - rDocumentService == "com.sun.star.sdb.OfficeDatabaseDocument" || - rDocumentService == "com.sun.star.sdb.RelationDesign" || - rDocumentService == "com.sun.star.sdb.QueryDesign" || - rDocumentService == "com.sun.star.sdb.TableDesign" || - rDocumentService == "com.sun.star.sdb.DataSourceBrowser" ) - sApplicationName = "Base"; - - if ( !sApplicationName.isEmpty() ) - { - OUString sApplicationID("TheDocumentFoundation.LibreOffice."); - sApplicationID += sApplicationName; + OUString sApplicationID("TheDocumentFoundation.LibreOffice."); + sApplicationID += sApplicationName; - SHARDAPPIDINFO info; - info.psi = pShellItem; - info.pszAppID = SAL_W(sApplicationID.getStr()); + SHARDAPPIDINFO info; + info.psi = pShellItem; + info.pszAppID = SAL_W(sApplicationID.getStr()); - SHAddToRecentDocs ( SHARD_APPIDINFO, &info ); - return; - } + SHAddToRecentDocs ( SHARD_APPIDINFO, &info ); + return; } } // For whatever reason, we could not use the SHARD_APPIDINFO semantics @@ -958,38 +922,43 @@ int WinSalInstance::WorkaroundExceptionHandlingInUSER32Lib(int, LPEXCEPTION_POIN OUString WinSalInstance::getOSVersion() { - SalData* pSalData = GetSalData(); - if ( !pSalData ) - return OUString("unknown"); - - WORD nMajor = 0, nMinor = 0; -#ifdef _WIN32_WINNT_WINBLUE - // Trying to hide the real version info behind an - // uber-lame non-forward-compatible, 'compatibility' API - // seems unlikely to help OS designers, or API users. - nMajor = 30; - while( !IsWindowsVersionOrGreater( nMajor, 0, 0 ) && nMajor > 0) - nMajor--; - nMinor = 30; - while( !IsWindowsVersionOrGreater( nMajor, nMinor, 0 ) && nMinor > 0) - nMinor--; -#else - OSVERSIONINFO aVersionInfo; - memset( &aVersionInfo, 0, sizeof( aVersionInfo ) ); - aVersionInfo.dwOSVersionInfoSize = sizeof( aVersionInfo ); - if ( GetVersionEx( &aVersionInfo ) ) + // GetVersion(Ex) and VersionHelpers (based on VerifyVersionInfo) API are + // subject to manifest-based behavior since Windows 8.1, so give wrong results. + // Another approach would be to use NetWkstaGetInfo, but that has some small + // reported delays (some milliseconds), and might get slower in domains with + // poor network connections. + // So go with a solution described at https://msdn.microsoft.com/en-us/library/ms724429 + HINSTANCE hLibrary = LoadLibraryW(L"kernel32.dll"); + if (hLibrary != nullptr) { - nMajor = aVersionInfo.dwMajorVersion; - nMinor = aVersionInfo.dwMinorVersion; + wchar_t szPath[MAX_PATH]; + DWORD dwCount = GetModuleFileNameW(hLibrary, szPath, SAL_N_ELEMENTS(szPath)); + FreeLibrary(hLibrary); + if (dwCount != 0 && dwCount < SAL_N_ELEMENTS(szPath)) + { + dwCount = GetFileVersionInfoSizeW(szPath, NULL); + if (dwCount != 0) + { + std::unique_ptr<char> ver(new char[dwCount]); + if (GetFileVersionInfoW(szPath, 0, dwCount, ver.get()) != FALSE) + { + void* pBlock = nullptr; + UINT dwBlockSz = 0; + if (VerQueryValueW(ver.get(), L"\\", &pBlock, &dwBlockSz) != FALSE && dwBlockSz >= sizeof(VS_FIXEDFILEINFO)) + { + VS_FIXEDFILEINFO *vinfo = reinterpret_cast<VS_FIXEDFILEINFO *>(pBlock); + OUStringBuffer aVer; + aVer.append("Windows "); + aVer.append((sal_Int32)HIWORD(vinfo->dwProductVersionMS)); + aVer.append("."); + aVer.append((sal_Int32)LOWORD(vinfo->dwProductVersionMS)); + return aVer.makeStringAndClear(); + } + } + } + } } -#endif - OUStringBuffer aVer; - aVer.append( "Windows " ); - aVer.append( (sal_Int32)nMajor ); - aVer.append( "." ); - aVer.append( (sal_Int32)nMinor ); - - return aVer.makeStringAndClear(); + return "unknown"; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |