Debian Codegraph @

shell/source/win32/shlxthandler/propsheets/propsheets.cxx

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20 #include <config.hxx>
21 #include <global.hxx>
22
23 #include <propsheets.hxx>
24 #include <utilities.hxx>
25 #include <resource.h>
26 #include "listviewbuilder.hxx"
27
28 #include <shellapi.h>
29
30 #include <sal/macros.h>
31
32 #include <memory>
33 #include <string>
34 #include <vector>
35 #include <utility>
36 #include <strsafe.h>
37
38
39 /*---------------------------------------------
40 INFO - INFO - INFO - INFO - INFO - INFO
41
42 See MSDN "Using Windows XP Visual Styles"
43 for hints how to enable the new common
44 control library for our property sheet.
45
46 INFO - INFO - INFO - INFO - INFO - INFO
47 ----------------------------------------------*/
48
49
50 CPropertySheet::CPropertySheet(LONG RefCnt) :
51 m_RefCnt(RefCnt)
52 {
53 OutputDebugStringFormatW(L"CPropertySheet::CTor [%d], [%ld]", m_RefCnt, g_DllRefCnt );
54 InterlockedIncrement(&g_DllRefCnt);
55 }
56
57
58 CPropertySheet::~CPropertySheet()
59 {
60 OutputDebugStringFormatW(L"CPropertySheet::DTor [%d], [%ld]", m_RefCnt, g_DllRefCnt );
61 InterlockedDecrement(&g_DllRefCnt);
62 }
63
64
65 // IUnknown methods
66
67
68 HRESULT STDMETHODCALLTYPE CPropertySheet::QueryInterface(
69 REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject)
70 {
71 *ppvObject = nullptr;
72
73 IUnknown* pUnk = nullptr;
74 if (IID_IUnknown == riid || IID_IShellExtInit == riid)
75 {
76 pUnk = static_cast<IShellExtInit*>(this);
77 pUnk->AddRef();
78 *ppvObject = pUnk;
79 return S_OK;
80 }
81 else if (IID_IShellPropSheetExt == riid)
82 {
83 pUnk = static_cast<IShellPropSheetExt*>(this);
84 pUnk->AddRef();
85 *ppvObject = pUnk;
86 return S_OK;
87 }
88
89 return E_NOINTERFACE;
90 }
91
92
93 ULONG STDMETHODCALLTYPE CPropertySheet::AddRef()
94 {
95 OutputDebugStringFormatW(L"CPropertySheet::AddRef [%d]", m_RefCnt );
96 return InterlockedIncrement(&m_RefCnt);
97 }
98
99
100 ULONG STDMETHODCALLTYPE CPropertySheet::Release()
101 {
102 OutputDebugStringFormatW(L"CPropertySheet::Release [%d]", m_RefCnt );
103 LONG refcnt = InterlockedDecrement(&m_RefCnt);
104
105 if (0 == refcnt)
106 delete this;
107
108 return refcnt;
109 }
110
111
112 // IShellExtInit
113
114
115 HRESULT STDMETHODCALLTYPE CPropertySheet::Initialize(
116 LPCITEMIDLIST /*pidlFolder*/, IDataObject * lpdobj, HKEY /*hkeyProgID*/)
117 {
118 InitCommonControls();
119
120 STGMEDIUM medium;
121 FORMATETC fe = {CF_HDROP, nullptr, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
122
123 HRESULT hr = lpdobj->GetData(&fe, &medium);
124
125 // save the file name
126 if (SUCCEEDED(hr) &&
127 (1 == DragQueryFileW(
128 static_cast<HDROP>(medium.hGlobal),
129 0xFFFFFFFF,
130 nullptr,
131 0)))
132 {
133 UINT size = DragQueryFileW( static_cast<HDROP>(medium.hGlobal), 0, nullptr, 0 );
134 if ( size != 0 )
135 {
136 auto buffer = std::make_unique<WCHAR[]>( size + 1 );
137 UINT result_size = DragQueryFileW( static_cast<HDROP>(medium.hGlobal),
138 0, buffer.get(), size + 1 );
139 if ( result_size != 0 )
140 {
141 m_FileName = getShortPathName(buffer.get());
142 hr = S_OK;
143 }
144 else
145 hr = E_INVALIDARG;
146 }
147 else
148 hr = E_INVALIDARG;
149 }
150 else
151 hr = E_INVALIDARG;
152
153 ReleaseStgMedium(&medium);
154
155 return hr;
156 }
157
158
159 // IShellPropSheetExt
160
161
162 HRESULT STDMETHODCALLTYPE CPropertySheet::AddPages(LPFNSVADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam)
163 {
164 std::wstring proppage_header;
165
166 PROPSHEETPAGEW psp;
167 ZeroMemory(&psp, sizeof(psp));
168
169 // add the summary property page
170 psp.dwSize = sizeof(psp);
171 psp.dwFlags = PSP_DEFAULT | PSP_USETITLE | PSP_USECALLBACK;
172 psp.hInstance = GetCurrentModuleHandle();
173 psp.lParam = reinterpret_cast<LPARAM>(this);
174 psp.pfnCallback = reinterpret_cast<LPFNPSPCALLBACKW>(CPropertySheet::PropPageSummaryCallback);
175
176 HPROPSHEETPAGE hPage = nullptr;
177
178 // add the statistics property page
179 proppage_header = GetResString(IDS_PROPPAGE_STATISTICS_TITLE);
180
181 psp.pszTemplate = MAKEINTRESOURCEW(IDD_PROPPAGE_STATISTICS);
182 psp.pszTitle = proppage_header.c_str();
183 psp.pfnDlgProc = reinterpret_cast<DLGPROC>(CPropertySheet::PropPageStatisticsProc);
184
185 hPage = CreatePropertySheetPageW(&psp);
186
187 if (hPage)
188 {
189 if (lpfnAddPage(hPage, lParam))
190 AddRef();
191 else
192 DestroyPropertySheetPage(hPage);
193 }
194
195 // always return success else no property sheet will be displayed at all
196 return NOERROR;
197 }
198
199
200 HRESULT STDMETHODCALLTYPE CPropertySheet::ReplacePage(
201 EXPPS /*uPageID*/, LPFNSVADDPROPSHEETPAGE /*lpfnReplaceWith*/, LPARAM /*lParam*/)
202 {
203 return E_NOTIMPL;
204 }
205
206
207 UINT CALLBACK CPropertySheet::PropPageSummaryCallback(
208 HWND /*hwnd*/, UINT uMsg, LPPROPSHEETPAGE ppsp)
209 {
210 CPropertySheet* pImpl =
211 reinterpret_cast<CPropertySheet*>(ppsp->lParam);
212
213 // release this instance, acquired in the AddPages method
214 if (PSPCB_RELEASE == uMsg)
215 {
216 pImpl->Release();
217 }
218
219 return TRUE;
220 }
221
222
223 bool CALLBACK CPropertySheet::PropPageSummaryProc(HWND hwnd, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam)
224 {
225 switch (uiMsg)
226 {
227 case WM_INITDIALOG:
228 {
229 LPPROPSHEETPAGE psp = reinterpret_cast<LPPROPSHEETPAGE>(lParam);
230 CPropertySheet* pImpl = reinterpret_cast<CPropertySheet*>(psp->lParam);
231 pImpl->InitPropPageSummary(hwnd, psp);
232 return true;
233 }
234 }
235
236 return false;
237 }
238
239
240 BOOL CALLBACK CPropertySheet::PropPageStatisticsProc(HWND hwnd, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam)
241 {
242 switch (uiMsg)
243 {
244 case WM_INITDIALOG:
245 {
246 LPPROPSHEETPAGE psp = reinterpret_cast<LPPROPSHEETPAGE>(lParam);
247 CPropertySheet* pImpl = reinterpret_cast<CPropertySheet*>(psp->lParam);
248 pImpl->InitPropPageStatistics(hwnd, psp);
249 return TRUE;
250 }
251 }
252
253 return FALSE;
254 }
255
256 void CPropertySheet::InitPropPageSummary(HWND hwnd, LPPROPSHEETPAGE /*lppsp*/)
257 {
258 try
259 {
260 CMetaInfoReader metaInfo(m_FileName);
261
262 SetWindowTextW(GetDlgItem(hwnd,IDC_TITLE), metaInfo.getTagData( META_INFO_TITLE ).c_str() );
263 SetWindowTextW(GetDlgItem(hwnd,IDC_AUTHOR), metaInfo.getTagData( META_INFO_AUTHOR ).c_str() );
264 SetWindowTextW(GetDlgItem(hwnd,IDC_SUBJECT), metaInfo.getTagData( META_INFO_SUBJECT ).c_str() );
265 SetWindowTextW(GetDlgItem(hwnd,IDC_KEYWORDS), metaInfo.getTagData( META_INFO_KEYWORDS ).c_str() );
266
267 // comments read from meta.xml use "\n" for return, but this will not displayable in Edit control, add
268 // "\r" before "\n" to form "\r\n" in order to display return in Edit control.
269 std::wstring tempStr = metaInfo.getTagData( META_INFO_DESCRIPTION );
270 std::wstring::size_type itor = tempStr.find ( L"\n" , 0 );
271 while (itor != std::wstring::npos)
272 {
273 tempStr.insert(itor, L"\r");
274 itor = tempStr.find(L"\n", itor + 2);
275 }
276 SetWindowTextW(GetDlgItem(hwnd,IDC_COMMENTS), tempStr.c_str());
277 }
278 catch (const std::exception&)
279 {
280 }
281 }
282
283
284 void CPropertySheet::InitPropPageStatistics(HWND hwnd, LPPROPSHEETPAGE /*lppsp*/)
285 {
286 try
287 {
288 CMetaInfoReader metaInfo(m_FileName);
289
290 document_statistic_reader_ptr doc_stat_reader = create_document_statistic_reader(m_FileName, &metaInfo);
291
292 statistic_group_list_t sgl;
293 doc_stat_reader->read(&sgl);
294
295 list_view_builder_ptr lv_builder = create_list_view_builder(
296 GetDlgItem(hwnd, IDC_STATISTICSLIST),
297 GetResString(IDS_PROPERTY),
298 GetResString(IDS_PROPERTY_VALUE));
299
300 lv_builder->build(sgl);
301 }
302 catch (const std::exception&)
303 {
304 }
305 }
306 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */