merge the formfield patch from ooo-build
[ooovba.git] / shell / source / win32 / shlxthandler / columninfo / columninfo.cxx
blob9d651147140a42146950ff96a18b2de23bd6fd3d
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: columninfo.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/global.hxx"
34 #include "internal/columninfo.hxx"
35 #include "internal/fileextensions.hxx"
36 #include "internal/metainforeader.hxx"
37 #include "internal/utilities.hxx"
38 #include "internal/config.hxx"
40 #include <malloc.h>
42 //----------------------------
44 //----------------------------
46 namespace /* private */
48 SHCOLUMNINFO ColumnInfoTable[] =
50 {{PSGUID_SUMMARYINFORMATION, PIDSI_TITLE}, VT_BSTR, LVCFMT_LEFT, 30, SHCOLSTATE_TYPE_STR, L"Title", L"Title"},
51 {{PSGUID_SUMMARYINFORMATION, PIDSI_AUTHOR}, VT_BSTR, LVCFMT_LEFT, 30, SHCOLSTATE_TYPE_STR, L"Author", L"Author"},
52 {{PSGUID_SUMMARYINFORMATION, PIDSI_SUBJECT}, VT_BSTR, LVCFMT_LEFT, 30, SHCOLSTATE_TYPE_STR, L"Subject", L"Subject"},
53 {{PSGUID_SUMMARYINFORMATION, PIDSI_KEYWORDS}, VT_BSTR, LVCFMT_LEFT, 30, SHCOLSTATE_TYPE_STR, L"Keywords", L"Keywords"},
54 {{PSGUID_SUMMARYINFORMATION, PIDSI_COMMENTS}, VT_BSTR, LVCFMT_LEFT, 30, SHCOLSTATE_TYPE_STR, L"Comments", L"Comments"},
55 {{PSGUID_SUMMARYINFORMATION, PIDSI_PAGECOUNT},VT_BSTR, LVCFMT_LEFT, 30, SHCOLSTATE_TYPE_STR, L"Pagecount", L"Pagecount"}
58 size_t ColumnInfoTableSize = sizeof(ColumnInfoTable)/sizeof(ColumnInfoTable[0]);
61 //----------------------------
63 //----------------------------
65 CColumnInfo::CColumnInfo(long RefCnt) :
66 m_RefCnt(RefCnt)
68 InterlockedIncrement(&g_DllRefCnt);
71 //----------------------------
73 //----------------------------
75 CColumnInfo::~CColumnInfo()
77 InterlockedDecrement(&g_DllRefCnt);
80 //-----------------------------
81 // IUnknown methods
82 //-----------------------------
84 HRESULT STDMETHODCALLTYPE CColumnInfo::QueryInterface(REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject)
86 *ppvObject = 0;
88 if (IID_IUnknown == riid || IID_IColumnProvider == riid)
90 IUnknown* pUnk = static_cast<IColumnProvider*>(this);
91 pUnk->AddRef();
92 *ppvObject = pUnk;
93 return S_OK;
96 return E_NOINTERFACE;
99 //----------------------------
101 //----------------------------
103 ULONG STDMETHODCALLTYPE CColumnInfo::AddRef(void)
105 return InterlockedIncrement(&m_RefCnt);
108 //----------------------------
110 //----------------------------
112 ULONG STDMETHODCALLTYPE CColumnInfo::Release( void)
114 long refcnt = InterlockedDecrement(&m_RefCnt);
116 if (0 == m_RefCnt)
117 delete this;
119 return refcnt;
122 //-----------------------------
123 // IColumnProvider
124 //-----------------------------
126 HRESULT STDMETHODCALLTYPE CColumnInfo::Initialize(LPCSHCOLUMNINIT /*psci*/)
128 return S_OK;
131 //-----------------------------
132 // Register all columns we support
133 //-----------------------------
135 HRESULT STDMETHODCALLTYPE CColumnInfo::GetColumnInfo(DWORD dwIndex, SHCOLUMNINFO *psci)
137 if (dwIndex >= ColumnInfoTableSize)
138 return S_FALSE;
140 // Return information on each column we support. Return S_FALSE
141 // to indicate that we have returned information on all our
142 // columns. GetColumnInfo will be called repeatedly until S_FALSE
143 // or an error is returned
144 psci->scid.fmtid = ColumnInfoTable[dwIndex].scid.fmtid;
145 psci->scid.pid = ColumnInfoTable[dwIndex].scid.pid;
146 ZeroMemory(psci->wszTitle, sizeof(psci->wszTitle));
147 wcsncpy(psci->wszTitle, ColumnInfoTable[dwIndex].wszTitle, (sizeof(psci->wszTitle) - 1));
149 //wcscpy(psci->wszTitle, ColumnInfoTable[dwIndex].wszTitle);
151 return S_OK;
154 //-----------------------------
156 //-----------------------------
158 HRESULT STDMETHODCALLTYPE CColumnInfo::GetItemData(LPCSHCOLUMNID pscid, LPCSHCOLUMNDATA pscd, VARIANT *pvarData)
160 if (IsOOFileExtension(pscd->pwszExt))
165 CMetaInfoReader meta_info_accessor(WStringToString(pscd->wszFile));
167 VariantClear(pvarData);
169 if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_TITLE)
171 pvarData->vt = VT_BSTR;
172 pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagData( META_INFO_TITLE ).c_str());
174 return S_OK;
176 else if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_AUTHOR)
178 pvarData->vt = VT_BSTR;
179 pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagData( META_INFO_AUTHOR).c_str());
181 return S_OK;
183 else if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_SUBJECT)
185 pvarData->vt = VT_BSTR;
186 pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagData( META_INFO_SUBJECT).c_str());
188 return S_OK;
190 else if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_KEYWORDS)
192 pvarData->vt = VT_BSTR;
193 pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagData( META_INFO_KEYWORDS).c_str());
195 return S_OK;
197 else if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_COMMENTS)
199 pvarData->vt = VT_BSTR;
200 pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagData( META_INFO_DESCRIPTION).c_str());
202 return S_OK;
204 else if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_PAGECOUNT)
206 pvarData->vt = VT_BSTR;
207 pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagAttribute( META_INFO_DOCUMENT_STATISTIC, META_INFO_PAGES).c_str());
209 return S_OK;
212 catch (const std::exception&)
214 return S_FALSE;
218 return S_FALSE;
221 //-----------------------------
223 //-----------------------------
225 bool CColumnInfo::IsOOFileExtension(wchar_t* Extension) const
227 for (size_t i = 0; i < OOFileExtensionTableSize; i++)
229 if (0 == _wcsicmp(Extension, OOFileExtensionTable[i].ExtensionUnicode))
230 return true;
233 return false;