[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - shell/inc shell/Library_spsupp.mk shell/Library_spsupp_x64.mk shell/Module_shell.mk shell/source shell/WinResTarget_spsupp_dlg.mk

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Sat May 18 10:54:03 UTC 2019


 shell/Library_spsupp.mk                        |    2 
 shell/Library_spsupp_x64.mk                    |    2 
 shell/Module_shell.mk                          |    1 
 shell/WinResTarget_spsupp_dlg.mk               |   14 ++++
 shell/inc/spsupp/spsuppServ.hpp                |    1 
 shell/source/win32/spsupp/COMOpenDocuments.cxx |   74 +++++++++++++++++++++++--
 shell/source/win32/spsupp/res/spsuppDlg.h      |   27 +++++++++
 shell/source/win32/spsupp/res/spsuppDlg.rc     |   29 +++++++++
 shell/source/win32/spsupp/spsuppServ.cxx       |   13 ++--
 9 files changed, 153 insertions(+), 10 deletions(-)

New commits:
commit 019ad58d61abd3fea3e929c7e8a48435dae1152d
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Tue May 7 21:22:08 2019 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Sat May 18 12:53:17 2019 +0200

    SharePoint: Add dialog to choose opening in read-only or edit mode.
    
    ViewDocument3 method takes OpenType parameter, which allows to decide
    if user can choose opening the document read-only or to edit.
    
    This backport of commit f60cc89ec35f8b1bf56e9f69ef15143fd002c409 does
    not include l10n stuff and dedicated helper executable, using dialog
    resource strings.
    
    Change-Id: I0ad53ba64272fb84728d2221e3dc85d3eefdda68
    Reviewed-on: https://gerrit.libreoffice.org/72355
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
    Tested-by: Mike Kaganski <mike.kaganski at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/72518

diff --git a/shell/Library_spsupp.mk b/shell/Library_spsupp.mk
index fd9bdba84351..3af8ded57071 100644
--- a/shell/Library_spsupp.mk
+++ b/shell/Library_spsupp.mk
@@ -33,6 +33,8 @@ $(eval $(call gb_Library_use_system_win32_libs,spsupp,\
 
 $(eval $(call gb_Library_add_nativeres,spsupp,spsupp))
 
+$(eval $(call gb_Library_add_nativeres,spsupp,spsupp_dlg))
+
 $(eval $(call gb_Library_add_ldflags,spsupp,\
 	/DEF:$(SRCDIR)/shell/source/win32/spsupp/spsupp.def \
 ))
diff --git a/shell/Library_spsupp_x64.mk b/shell/Library_spsupp_x64.mk
index 4b36a6c8d105..231e93e53570 100644
--- a/shell/Library_spsupp_x64.mk
+++ b/shell/Library_spsupp_x64.mk
@@ -35,6 +35,8 @@ $(eval $(call gb_Library_use_system_win32_libs,spsupp_x64,\
 
 $(eval $(call gb_Library_add_nativeres,spsupp_x64,spsupp))
 
+$(eval $(call gb_Library_add_nativeres,spsupp_x64,spsupp_dlg))
+
 $(eval $(call gb_Library_add_ldflags,spsupp_x64,\
 	/DEF:$(SRCDIR)/shell/source/win32/spsupp/spsupp.def \
 ))
diff --git a/shell/Module_shell.mk b/shell/Module_shell.mk
index fb56db70e087..8b658b6a9204 100644
--- a/shell/Module_shell.mk
+++ b/shell/Module_shell.mk
@@ -57,6 +57,7 @@ $(eval $(call gb_Module_add_targets,shell,\
 	CustomTarget_spsupp_idl \
 	Library_spsupp \
 	WinResTarget_spsupp \
+	WinResTarget_spsupp_dlg \
 ))
 
 $(eval $(call gb_Module_add_check_targets,shell,\
diff --git a/shell/WinResTarget_spsupp_dlg.mk b/shell/WinResTarget_spsupp_dlg.mk
new file mode 100644
index 000000000000..9880433c7826
--- /dev/null
+++ b/shell/WinResTarget_spsupp_dlg.mk
@@ -0,0 +1,14 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_WinResTarget_WinResTarget,spsupp_dlg))
+
+$(eval $(call gb_WinResTarget_set_rcfile,spsupp_dlg,shell/source/win32/spsupp/res/spsuppDlg))
+
+# vim: set shiftwidth=4 tabstop=4 noexpandtab:
diff --git a/shell/inc/spsupp/spsuppServ.hpp b/shell/inc/spsupp/spsuppServ.hpp
index e3c78dc3fa6b..f46ecca449f5 100644
--- a/shell/inc/spsupp/spsuppServ.hpp
+++ b/shell/inc/spsupp/spsuppServ.hpp
@@ -14,6 +14,7 @@
 
 ITypeLib* GetTypeLib();
 const wchar_t* GetLOPath();
+HMODULE GetHModule();
 
 #endif
 
diff --git a/shell/source/win32/spsupp/COMOpenDocuments.cxx b/shell/source/win32/spsupp/COMOpenDocuments.cxx
index b733c258e480..a13bd9b85345 100644
--- a/shell/source/win32/spsupp/COMOpenDocuments.cxx
+++ b/shell/source/win32/spsupp/COMOpenDocuments.cxx
@@ -15,10 +15,65 @@
 #include <COMOpenDocuments.hpp>
 #include <spsuppServ.hpp>
 #include <stdio.h>
+#include "res/spsuppDlg.h"
 
 namespace
 {
 
+INT_PTR CALLBACK EditOrRODlgproc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
+{
+    switch (Msg)
+    {
+        case WM_INITDIALOG:
+        {
+            if (const wchar_t* sFilePath = reinterpret_cast<const wchar_t*>(lParam))
+            {
+                const HWND hWndMsg = GetDlgItem(hDlg, IDC_EDIT_OR_RO);
+                wchar_t buf[64 * 1024]{};
+                GetWindowTextW(hWndMsg, buf, sizeof(buf)/sizeof(*buf));
+                std::wstring sText(buf);
+                size_t pos = sText.find(L"%DOCNAME");
+                if (pos != std::wstring::npos)
+                    SetWindowTextW(hWndMsg, sText.replace(pos, 8, sFilePath).c_str());
+            }
+            return TRUE; // set default focus
+        }
+        case WM_COMMAND:
+        {
+            WORD nId = LOWORD(wParam);
+            switch (nId)
+            {
+                case IDCANCEL:
+                case ID_RO:
+                case ID_EDIT:
+                    EndDialog(hDlg, nId);
+                    return TRUE;
+            }
+            break;
+        }
+    }
+    return FALSE;
+}
+
+enum class Answer
+{
+    Cancel,
+    ReadOnly,
+    Edit
+};
+
+Answer AskIfUserWantsToEdit(const wchar_t* sFilePath)
+{
+    Answer res = Answer::Cancel;
+    INT_PTR nResult = DialogBoxParamW(GetHModule(), MAKEINTRESOURCEW(IDD_EDIT_OR_RO), nullptr,
+                                      EditOrRODlgproc, reinterpret_cast<LPARAM>(sFilePath));
+    if (nResult == ID_RO)
+        res = Answer::ReadOnly;
+    else if (nResult == ID_EDIT)
+        res = Answer::Edit;
+    return res;
+}
+
 // Returns S_OK if successful
 HRESULT LOStart(const wchar_t* sModeArg, const wchar_t* sFilePath)
 {
@@ -62,7 +117,6 @@ HRESULT LOStart(const wchar_t* sModeArg, const wchar_t* sFilePath)
 }
 
 VARIANT_BOOL toVBool(bool b) { return b ? VARIANT_TRUE : VARIANT_FALSE; }
-
 } // namespace
 
 long COMOpenDocuments::m_nObjCount = 0;
@@ -276,14 +330,24 @@ STDMETHODIMP COMOpenDocuments::PromptedOnLastOpen(
 // 3 When the document is not checked out and the document library requires that documents be checked out to be edited, the user can only read the document, or check it out and edit it
 // 4 When the current user has checked it out, the user can only edit the local copy of the document
 STDMETHODIMP COMOpenDocuments::ViewDocument3(
-    IDispatch* /*pdisp*/,      // An Object that represents the window from which the ViewDocument3 method is being activated
+    IDispatch* pdisp,          // An Object that represents the window from which the ViewDocument3 method is being activated
     BSTR bstrDocumentLocation, // A string that contains the URL of the document to open for reading
-    int /*OpenType*/,          // A Long integer that specifies the rights for opening the document
-    VARIANT /*varProgID*/,     // An optional string that contains the ProgID of the application with which to open the document. If this argument is omitted, the default viewer for the document is used
+    int OpenType,              // A Long integer that specifies the rights for opening the document
+    VARIANT varProgID,         // An optional string that contains the ProgID of the application with which to open the document. If this argument is omitted, the default viewer for the document is used
     VARIANT_BOOL *pbResult)    // true if the document was successfully opened; otherwise false
 {
     if (!pbResult)
         return E_POINTER;
+    if (OpenType == 0)
+    {
+        switch (AskIfUserWantsToEdit(bstrDocumentLocation))
+        {
+        case Answer::Cancel:
+            return S_FALSE;
+        case Answer::Edit:
+            return EditDocument3(pdisp, bstrDocumentLocation, VARIANT_FALSE, varProgID, pbResult);
+        }
+    }
     // TODO: resolve the program from varProgID (nullptr -> default?)
     HRESULT hr = LOStart(L"--view", bstrDocumentLocation);
     *pbResult = toVBool(SUCCEEDED(hr));
@@ -344,7 +408,7 @@ STDMETHODIMP COMOpenDocuments::EditDocument3(
     BSTR bstrDocumentLocation,      // A string that contains the URL of the document to open for editing
     VARIANT_BOOL /*fUseLocalCopy*/, // true to use a local copy; otherwise false
     VARIANT /*varProgID*/,          // An optional string that contains the ProgID of the application with which to edit the document. If this argument is omitted, the default editor for the document is used
-    VARIANT_BOOL *pbResult)     // true if the document was successfully opened; otherwise false
+    VARIANT_BOOL *pbResult)         // true if the document was successfully opened; otherwise false
 {
     if (!pbResult)
         return E_POINTER;
diff --git a/shell/source/win32/spsupp/res/spsuppDlg.h b/shell/source/win32/spsupp/res/spsuppDlg.h
new file mode 100644
index 000000000000..f4b6ccb34410
--- /dev/null
+++ b/shell/source/win32/spsupp/res/spsuppDlg.h
@@ -0,0 +1,27 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+* This file is part of the LibreOffice project.
+*
+* This Source Code Form is subject to the terms of the Mozilla Public
+* License, v. 2.0. If a copy of the MPL was not distributed with this
+* file, You can obtain one at http://mozilla.org/MPL/2.0/.
+*/
+
+#define IDD_EDIT_OR_RO 101
+#define IDC_STATIC -1
+#define ID_RO 1000
+#define ID_EDIT 1001
+#define IDC_EDIT_OR_RO 1002
+
+// Next default values for new objects
+
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE 103
+#define _APS_NEXT_COMMAND_VALUE 40001
+#define _APS_NEXT_CONTROL_VALUE 1002
+#define _APS_NEXT_SYMED_VALUE 101
+#endif
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/shell/source/win32/spsupp/res/spsuppDlg.rc b/shell/source/win32/spsupp/res/spsuppDlg.rc
new file mode 100644
index 000000000000..6d144cc26789
--- /dev/null
+++ b/shell/source/win32/spsupp/res/spsuppDlg.rc
@@ -0,0 +1,29 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+* This file is part of the LibreOffice project.
+*
+* This Source Code Form is subject to the terms of the Mozilla Public
+* License, v. 2.0. If a copy of the MPL was not distributed with this
+* file, You can obtain one at http://mozilla.org/MPL/2.0/.
+*/
+
+#include "spsuppDlg.h"
+// We need to include windows.h to use IDI_QUESTION
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+LANGUAGE LANG_NEUTRAL, SUBLANG_DEFAULT
+
+// Dialog
+
+IDD_EDIT_OR_RO DIALOGEX 0, 0, 309, 87
+STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Open Document"
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+    ICON            IDI_QUESTION,IDC_STATIC,7,7,21,20
+    LTEXT           "You are opening document\n\n  %DOCNAME\n\nDo you want to open it to view or to edit?",IDC_EDIT_OR_RO,36,7,266,44
+    DEFPUSHBUTTON   "View",ID_RO,91,66,77,14
+    PUSHBUTTON      "Edit",ID_EDIT,171,66,77,14
+    PUSHBUTTON      "Cancel",IDCANCEL,252,66,50,14
+END
diff --git a/shell/source/win32/spsupp/spsuppServ.cxx b/shell/source/win32/spsupp/spsuppServ.cxx
index da9d32b9cd32..ae0b1de90bef 100644
--- a/shell/source/win32/spsupp/spsuppServ.cxx
+++ b/shell/source/win32/spsupp/spsuppServ.cxx
@@ -26,11 +26,14 @@
 #include <COMOpenDocuments.hpp>
 #include <registrar.hpp>
 
-namespace {
+#include <shlwapi.h> // declaration of DllInstall
 
+namespace
+{
 HANDLE g_hModule;
+} // namespace
 
-}
+HMODULE GetHModule() { return static_cast<HMODULE>(g_hModule); }
 
 ITypeLib* GetTypeLib()
 {
@@ -38,7 +41,7 @@ ITypeLib* GetTypeLib()
     static ITypeLibGuard s_aITypeLibGuard = [] {
         ITypeLibGuard aITypeLibGuard(nullptr, [](IUnknown* p) { if (p) p->Release(); });
         wchar_t szFile[MAX_PATH];
-        if (GetModuleFileNameW(static_cast<HMODULE>(g_hModule), szFile, MAX_PATH) == 0)
+        if (GetModuleFileNameW(GetHModule(), szFile, MAX_PATH) == 0)
             return aITypeLibGuard;
         ITypeLib* pTypeLib;
         if (FAILED(LoadTypeLib(szFile, &pTypeLib)))
@@ -53,7 +56,7 @@ const wchar_t* GetLOPath()
 {
     static wchar_t* s_sPath = []() -> wchar_t* {
         static wchar_t sPath[MAX_PATH];
-        if (GetModuleFileNameW(static_cast<HMODULE>(g_hModule), sPath, MAX_PATH) == 0)
+        if (GetModuleFileNameW(GetHModule(), sPath, MAX_PATH) == 0)
             return nullptr;
         wchar_t* pSlashPos = wcsrchr(sPath, L'\\');
         if (pSlashPos == nullptr)
@@ -118,7 +121,7 @@ STDAPI DllRegisterServer(void)
         return ResultFromScode(SELFREG_E_TYPELIB);
 
     wchar_t szFile[MAX_PATH];
-    if (GetModuleFileNameW(static_cast<HMODULE>(g_hModule), szFile, MAX_PATH) == 0)
+    if (GetModuleFileNameW(GetHModule(), szFile, MAX_PATH) == 0)
         return HRESULT_FROM_WIN32(GetLastError());
 
     HRESULT hr = RegisterTypeLib(pTypeLib, szFile, nullptr);


More information about the Libreoffice-commits mailing list