Kaydet (Commit) 019ad58d authored tarafından Mike Kaganski's avatar Mike Kaganski

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 f60cc89e does
not include l10n stuff and dedicated helper executable, using dialog
resource strings.

Change-Id: I0ad53ba64272fb84728d2221e3dc85d3eefdda68
Reviewed-on: https://gerrit.libreoffice.org/72355Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
Tested-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/72518
üst d35eec7b
...@@ -33,6 +33,8 @@ $(eval $(call gb_Library_use_system_win32_libs,spsupp,\ ...@@ -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))
$(eval $(call gb_Library_add_nativeres,spsupp,spsupp_dlg))
$(eval $(call gb_Library_add_ldflags,spsupp,\ $(eval $(call gb_Library_add_ldflags,spsupp,\
/DEF:$(SRCDIR)/shell/source/win32/spsupp/spsupp.def \ /DEF:$(SRCDIR)/shell/source/win32/spsupp/spsupp.def \
)) ))
......
...@@ -35,6 +35,8 @@ $(eval $(call gb_Library_use_system_win32_libs,spsupp_x64,\ ...@@ -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))
$(eval $(call gb_Library_add_nativeres,spsupp_x64,spsupp_dlg))
$(eval $(call gb_Library_add_ldflags,spsupp_x64,\ $(eval $(call gb_Library_add_ldflags,spsupp_x64,\
/DEF:$(SRCDIR)/shell/source/win32/spsupp/spsupp.def \ /DEF:$(SRCDIR)/shell/source/win32/spsupp/spsupp.def \
)) ))
......
...@@ -57,6 +57,7 @@ $(eval $(call gb_Module_add_targets,shell,\ ...@@ -57,6 +57,7 @@ $(eval $(call gb_Module_add_targets,shell,\
CustomTarget_spsupp_idl \ CustomTarget_spsupp_idl \
Library_spsupp \ Library_spsupp \
WinResTarget_spsupp \ WinResTarget_spsupp \
WinResTarget_spsupp_dlg \
)) ))
$(eval $(call gb_Module_add_check_targets,shell,\ $(eval $(call gb_Module_add_check_targets,shell,\
......
# -*- 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:
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
ITypeLib* GetTypeLib(); ITypeLib* GetTypeLib();
const wchar_t* GetLOPath(); const wchar_t* GetLOPath();
HMODULE GetHModule();
#endif #endif
......
...@@ -15,10 +15,65 @@ ...@@ -15,10 +15,65 @@
#include <COMOpenDocuments.hpp> #include <COMOpenDocuments.hpp>
#include <spsuppServ.hpp> #include <spsuppServ.hpp>
#include <stdio.h> #include <stdio.h>
#include "res/spsuppDlg.h"
namespace 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 // Returns S_OK if successful
HRESULT LOStart(const wchar_t* sModeArg, const wchar_t* sFilePath) HRESULT LOStart(const wchar_t* sModeArg, const wchar_t* sFilePath)
{ {
...@@ -62,7 +117,6 @@ 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; } VARIANT_BOOL toVBool(bool b) { return b ? VARIANT_TRUE : VARIANT_FALSE; }
} // namespace } // namespace
long COMOpenDocuments::m_nObjCount = 0; long COMOpenDocuments::m_nObjCount = 0;
...@@ -276,14 +330,24 @@ STDMETHODIMP COMOpenDocuments::PromptedOnLastOpen( ...@@ -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 // 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 // 4 When the current user has checked it out, the user can only edit the local copy of the document
STDMETHODIMP COMOpenDocuments::ViewDocument3( 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 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 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 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 VARIANT_BOOL *pbResult) // true if the document was successfully opened; otherwise false
{ {
if (!pbResult) if (!pbResult)
return E_POINTER; 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?) // TODO: resolve the program from varProgID (nullptr -> default?)
HRESULT hr = LOStart(L"--view", bstrDocumentLocation); HRESULT hr = LOStart(L"--view", bstrDocumentLocation);
*pbResult = toVBool(SUCCEEDED(hr)); *pbResult = toVBool(SUCCEEDED(hr));
...@@ -344,7 +408,7 @@ STDMETHODIMP COMOpenDocuments::EditDocument3( ...@@ -344,7 +408,7 @@ STDMETHODIMP COMOpenDocuments::EditDocument3(
BSTR bstrDocumentLocation, // A string that contains the URL of the document to open for editing 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_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 /*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) if (!pbResult)
return E_POINTER; return E_POINTER;
......
/* -*- 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: */
/* -*- 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
...@@ -26,11 +26,14 @@ ...@@ -26,11 +26,14 @@
#include <COMOpenDocuments.hpp> #include <COMOpenDocuments.hpp>
#include <registrar.hpp> #include <registrar.hpp>
namespace { #include <shlwapi.h> // declaration of DllInstall
namespace
{
HANDLE g_hModule; HANDLE g_hModule;
} // namespace
} HMODULE GetHModule() { return static_cast<HMODULE>(g_hModule); }
ITypeLib* GetTypeLib() ITypeLib* GetTypeLib()
{ {
...@@ -38,7 +41,7 @@ ITypeLib* GetTypeLib() ...@@ -38,7 +41,7 @@ ITypeLib* GetTypeLib()
static ITypeLibGuard s_aITypeLibGuard = [] { static ITypeLibGuard s_aITypeLibGuard = [] {
ITypeLibGuard aITypeLibGuard(nullptr, [](IUnknown* p) { if (p) p->Release(); }); ITypeLibGuard aITypeLibGuard(nullptr, [](IUnknown* p) { if (p) p->Release(); });
wchar_t szFile[MAX_PATH]; 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; return aITypeLibGuard;
ITypeLib* pTypeLib; ITypeLib* pTypeLib;
if (FAILED(LoadTypeLib(szFile, &pTypeLib))) if (FAILED(LoadTypeLib(szFile, &pTypeLib)))
...@@ -53,7 +56,7 @@ const wchar_t* GetLOPath() ...@@ -53,7 +56,7 @@ const wchar_t* GetLOPath()
{ {
static wchar_t* s_sPath = []() -> wchar_t* { static wchar_t* s_sPath = []() -> wchar_t* {
static wchar_t sPath[MAX_PATH]; 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; return nullptr;
wchar_t* pSlashPos = wcsrchr(sPath, L'\\'); wchar_t* pSlashPos = wcsrchr(sPath, L'\\');
if (pSlashPos == nullptr) if (pSlashPos == nullptr)
...@@ -118,7 +121,7 @@ STDAPI DllRegisterServer(void) ...@@ -118,7 +121,7 @@ STDAPI DllRegisterServer(void)
return ResultFromScode(SELFREG_E_TYPELIB); return ResultFromScode(SELFREG_E_TYPELIB);
wchar_t szFile[MAX_PATH]; 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()); return HRESULT_FROM_WIN32(GetLastError());
HRESULT hr = RegisterTypeLib(pTypeLib, szFile, nullptr); HRESULT hr = RegisterTypeLib(pTypeLib, szFile, nullptr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment