update dev300-m58
[ooovba.git] / shell / source / win32 / shlxthandler / propsheets / propsheets.cxx
blobc901c7be42700dd0193a800ddd06d7d586749ff6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: propsheets.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_shell.hxx"
33 #include "internal/config.hxx"
34 #include "internal/global.hxx"
36 #ifndef PROPSEETS_HXX_INCLUDED
37 #include "internal/propsheets.hxx"
38 #endif
39 #include "internal/utilities.hxx"
40 #include "internal/resource.h"
41 #include "listviewbuilder.hxx"
43 #if defined _MSC_VER
44 #pragma warning(push, 1)
45 #endif
46 #include <shellapi.h>
47 #if defined _MSC_VER
48 #pragma warning(pop)
49 #endif
51 #include <string>
52 #include <vector>
53 #include <utility>
56 /*---------------------------------------------
57 INFO - INFO - INFO - INFO - INFO - INFO
59 See MSDN "Using Windows XP Visual Styles"
60 for hints how to enable the new common
61 control library for our property sheet.
63 INFO - INFO - INFO - INFO - INFO - INFO
64 ----------------------------------------------*/
66 //-----------------------------
68 //-----------------------------
70 CPropertySheet::CPropertySheet(long RefCnt) :
71 m_RefCnt(RefCnt)
73 InterlockedIncrement(&g_DllRefCnt);
76 //-----------------------------
78 //-----------------------------
80 CPropertySheet::~CPropertySheet()
82 InterlockedDecrement(&g_DllRefCnt);
85 //-----------------------------
86 // IUnknown methods
87 //-----------------------------
89 HRESULT STDMETHODCALLTYPE CPropertySheet::QueryInterface(
90 REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject)
92 *ppvObject = 0;
94 IUnknown* pUnk = 0;
95 if (IID_IUnknown == riid || IID_IShellExtInit == riid)
97 pUnk = static_cast<IShellExtInit*>(this);
98 pUnk->AddRef();
99 *ppvObject = pUnk;
100 return S_OK;
102 else if (IID_IShellPropSheetExt == riid)
104 pUnk = static_cast<IShellPropSheetExt*>(this);
105 pUnk->AddRef();
106 *ppvObject = pUnk;
107 return S_OK;
110 return E_NOINTERFACE;
113 //-----------------------------
115 //-----------------------------
117 ULONG STDMETHODCALLTYPE CPropertySheet::AddRef(void)
119 return InterlockedIncrement(&m_RefCnt);
122 //-----------------------------
124 //-----------------------------
126 ULONG STDMETHODCALLTYPE CPropertySheet::Release(void)
128 long refcnt = InterlockedDecrement(&m_RefCnt);
130 if (0 == refcnt)
131 delete this;
133 return refcnt;
136 //-----------------------------
137 // IShellExtInit
138 //-----------------------------
140 HRESULT STDMETHODCALLTYPE CPropertySheet::Initialize(
141 LPCITEMIDLIST /*pidlFolder*/, LPDATAOBJECT lpdobj, HKEY /*hkeyProgID*/)
143 InitCommonControls();
145 STGMEDIUM medium;
146 FORMATETC fe = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
148 HRESULT hr = lpdobj->GetData(&fe, &medium);
150 // save the file name
151 if (SUCCEEDED(hr) &&
152 (1 == DragQueryFileA(
153 reinterpret_cast<HDROP>(medium.hGlobal),
154 0xFFFFFFFF,
155 NULL,
156 0)))
158 DragQueryFileA(
159 reinterpret_cast<HDROP>(medium.hGlobal),
161 m_szFileName,
162 sizeof(m_szFileName));
164 hr = S_OK;
166 else
167 hr = E_INVALIDARG;
169 ReleaseStgMedium(&medium);
171 return hr;
174 //-----------------------------
175 // IShellPropSheetExt
176 //-----------------------------
178 HRESULT STDMETHODCALLTYPE CPropertySheet::AddPages(LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam)
181 PROPSHEETPAGE psp;
183 // add the summary property page
185 ZeroMemory(&psp, sizeof(PROPSHEETPAGEA));
187 std::wstring proppage_header = GetResString(IDS_PROPPAGE_SUMMARY_TITLE);
189 psp.dwSize = sizeof(PROPSHEETPAGE);
190 psp.dwFlags = PSP_DEFAULT | PSP_USETITLE | PSP_USECALLBACK;
191 psp.hInstance = GetModuleHandle(MODULE_NAME);
192 psp.pszTemplate = MAKEINTRESOURCE(IDD_PROPPAGE_SUMMARY);
193 psp.pszTitle = proppage_header.c_str();
194 psp.pfnDlgProc = reinterpret_cast<DLGPROC>(CPropertySheet::PropPageSummaryProc);
195 psp.lParam = reinterpret_cast<LPARAM>(this);
196 psp.pfnCallback = reinterpret_cast<LPFNPSPCALLBACK>(CPropertySheet::PropPageSummaryCallback);
198 HPROPSHEETPAGE hPage = CreatePropertySheetPage(&psp);
200 // keep this instance alive
201 // will be released when the
202 // the page is about to be
203 // destroyed in the callback
204 // function
206 if (hPage)
208 if (lpfnAddPage(hPage, lParam))
209 AddRef();
210 else
211 DestroyPropertySheetPage(hPage);
214 // add the statistics property page
216 proppage_header = GetResString(IDS_PROPPAGE_STATISTICS_TITLE);
218 psp.pszTemplate = MAKEINTRESOURCE(IDD_PROPPAGE_STATISTICS);
219 psp.pszTitle = proppage_header.c_str();
220 psp.pfnDlgProc = reinterpret_cast<DLGPROC>(CPropertySheet::PropPageStatisticsProc);
222 hPage = CreatePropertySheetPage(&psp);
224 if (hPage)
226 if (lpfnAddPage(hPage, lParam))
227 AddRef();
228 else
229 DestroyPropertySheetPage(hPage);
232 // always return success else
233 // no property sheet will be
234 // displayed at all
235 return NOERROR;
238 //-----------------------------
240 //-----------------------------
242 HRESULT STDMETHODCALLTYPE CPropertySheet::ReplacePage(
243 UINT /*uPageID*/, LPFNADDPROPSHEETPAGE /*lpfnReplaceWith*/, LPARAM /*lParam*/)
245 return E_NOTIMPL;
248 //-----------------------------
250 //-----------------------------
252 UINT CALLBACK CPropertySheet::PropPageSummaryCallback(
253 HWND /*hwnd*/, UINT uMsg, LPPROPSHEETPAGE ppsp)
255 CPropertySheet* pImpl =
256 reinterpret_cast<CPropertySheet*>(ppsp->lParam);
258 // release this instance, acquired
259 // in the AddPages method
260 if (PSPCB_RELEASE == uMsg)
262 pImpl->Release();
265 return TRUE;
269 //-----------------------------
271 //-----------------------------
273 BOOL CALLBACK CPropertySheet::PropPageSummaryProc(HWND hwnd, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam)
275 switch (uiMsg)
277 case WM_INITDIALOG:
279 LPPROPSHEETPAGE psp = reinterpret_cast<LPPROPSHEETPAGE>(lParam);
280 CPropertySheet* pImpl = reinterpret_cast<CPropertySheet*>(psp->lParam);
281 pImpl->InitPropPageSummary(hwnd, psp);
282 return TRUE;
286 return FALSE;
289 //-----------------------------
291 //-----------------------------
293 BOOL CALLBACK CPropertySheet::PropPageStatisticsProc(HWND hwnd, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam)
295 switch (uiMsg)
297 case WM_INITDIALOG:
299 LPPROPSHEETPAGE psp = reinterpret_cast<LPPROPSHEETPAGE>(lParam);
300 CPropertySheet* pImpl = reinterpret_cast<CPropertySheet*>(psp->lParam);
301 pImpl->InitPropPageStatistics(hwnd, psp);
302 return TRUE;
306 return FALSE;
309 //##################################
310 void CPropertySheet::InitPropPageSummary(HWND hwnd, LPPROPSHEETPAGE /*lppsp*/)
313 CMetaInfoReader metaInfo(m_szFileName);
315 SetWindowText(GetDlgItem(hwnd,IDC_TITLE), metaInfo.getTagData( META_INFO_TITLE ).c_str() );
316 SetWindowText(GetDlgItem(hwnd,IDC_AUTHOR), metaInfo.getTagData( META_INFO_AUTHOR ).c_str() );
317 SetWindowText(GetDlgItem(hwnd,IDC_SUBJECT), metaInfo.getTagData( META_INFO_SUBJECT ).c_str() );
318 SetWindowText(GetDlgItem(hwnd,IDC_KEYWORDS), metaInfo.getTagData( META_INFO_KEYWORDS ).c_str() );
320 // comments read from meta.xml use "\n" for return, but this will not displayable in Edit control, add
321 // "\r" before "\n" to form "\r\n" in order to display return in Edit control.
322 std::wstring tempStr = metaInfo.getTagData( META_INFO_DESCRIPTION ).c_str();
323 std::wstring::size_type itor = tempStr.find ( L"\n" , 0 );
324 while (itor != std::wstring::npos)
326 tempStr.insert(itor, L"\r");
327 itor = tempStr.find(L"\n", itor + 2);
329 SetWindowText(GetDlgItem(hwnd,IDC_COMMENTS), tempStr.c_str());
333 //---------------------------------
336 void CPropertySheet::InitPropPageStatistics(HWND hwnd, LPPROPSHEETPAGE /*lppsp*/)
339 CMetaInfoReader metaInfo(m_szFileName);
341 document_statistic_reader_ptr doc_stat_reader = create_document_statistic_reader(m_szFileName, &metaInfo);
343 statistic_group_list_t sgl;
344 doc_stat_reader->read(&sgl);
346 list_view_builder_ptr lv_builder = create_list_view_builder(
347 GetDlgItem(hwnd, IDC_STATISTICSLIST),
348 GetResString(IDS_PROPERTY),
349 GetResString(IDS_PROPERTY_VALUE));
351 lv_builder->build(sgl);