1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: propsheets.cxx,v $
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"
39 #include "internal/utilities.hxx"
40 #include "internal/resource.h"
41 #include "listviewbuilder.hxx"
44 #pragma warning(push, 1)
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
) :
73 InterlockedIncrement(&g_DllRefCnt
);
76 //-----------------------------
78 //-----------------------------
80 CPropertySheet::~CPropertySheet()
82 InterlockedDecrement(&g_DllRefCnt
);
85 //-----------------------------
87 //-----------------------------
89 HRESULT STDMETHODCALLTYPE
CPropertySheet::QueryInterface(
90 REFIID riid
, void __RPC_FAR
*__RPC_FAR
*ppvObject
)
95 if (IID_IUnknown
== riid
|| IID_IShellExtInit
== riid
)
97 pUnk
= static_cast<IShellExtInit
*>(this);
102 else if (IID_IShellPropSheetExt
== riid
)
104 pUnk
= static_cast<IShellPropSheetExt
*>(this);
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
);
136 //-----------------------------
138 //-----------------------------
140 HRESULT STDMETHODCALLTYPE
CPropertySheet::Initialize(
141 LPCITEMIDLIST
/*pidlFolder*/, LPDATAOBJECT lpdobj
, HKEY
/*hkeyProgID*/)
143 InitCommonControls();
146 FORMATETC fe
= {CF_HDROP
, NULL
, DVASPECT_CONTENT
, -1, TYMED_HGLOBAL
};
148 HRESULT hr
= lpdobj
->GetData(&fe
, &medium
);
150 // save the file name
152 (1 == DragQueryFileA(
153 reinterpret_cast<HDROP
>(medium
.hGlobal
),
159 reinterpret_cast<HDROP
>(medium
.hGlobal
),
162 sizeof(m_szFileName
));
169 ReleaseStgMedium(&medium
);
174 //-----------------------------
175 // IShellPropSheetExt
176 //-----------------------------
178 HRESULT STDMETHODCALLTYPE
CPropertySheet::AddPages(LPFNADDPROPSHEETPAGE lpfnAddPage
, LPARAM lParam
)
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
208 if (lpfnAddPage(hPage
, lParam
))
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
);
226 if (lpfnAddPage(hPage
, lParam
))
229 DestroyPropertySheetPage(hPage
);
232 // always return success else
233 // no property sheet will be
238 //-----------------------------
240 //-----------------------------
242 HRESULT STDMETHODCALLTYPE
CPropertySheet::ReplacePage(
243 UINT
/*uPageID*/, LPFNADDPROPSHEETPAGE
/*lpfnReplaceWith*/, LPARAM
/*lParam*/)
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
)
269 //-----------------------------
271 //-----------------------------
273 BOOL CALLBACK
CPropertySheet::PropPageSummaryProc(HWND hwnd
, UINT uiMsg
, WPARAM
/*wParam*/, LPARAM lParam
)
279 LPPROPSHEETPAGE psp
= reinterpret_cast<LPPROPSHEETPAGE
>(lParam
);
280 CPropertySheet
* pImpl
= reinterpret_cast<CPropertySheet
*>(psp
->lParam
);
281 pImpl
->InitPropPageSummary(hwnd
, psp
);
289 //-----------------------------
291 //-----------------------------
293 BOOL CALLBACK
CPropertySheet::PropPageStatisticsProc(HWND hwnd
, UINT uiMsg
, WPARAM
/*wParam*/, LPARAM lParam
)
299 LPPROPSHEETPAGE psp
= reinterpret_cast<LPPROPSHEETPAGE
>(lParam
);
300 CPropertySheet
* pImpl
= reinterpret_cast<CPropertySheet
*>(psp
->lParam
);
301 pImpl
->InitPropPageStatistics(hwnd
, psp
);
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
);