Bump version to 5.0-14
[LibreOffice.git] / shell / source / win32 / shlxthandler / columninfo / columninfo.cxx
blobe503bc3a3e515bfb45e6e6e330b4c5e5c4c0e7fb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "internal/global.hxx"
21 #include "internal/columninfo.hxx"
22 #include "internal/fileextensions.hxx"
23 #include "internal/metainforeader.hxx"
24 #include "internal/utilities.hxx"
25 #include "internal/config.hxx"
27 #include <sal/macros.h>
28 #include <malloc.h>
30 #if defined __GNUC__
31 #pragma GCC diagnostic warning "-Wmissing-braces"
32 #endif
36 namespace /* private */
38 SHCOLUMNINFO ColumnInfoTable[] =
40 {{PSGUID_SUMMARYINFORMATION, PIDSI_TITLE}, VT_BSTR, LVCFMT_LEFT, 30, SHCOLSTATE_TYPE_STR, L"Title", L"Title"},
41 {{PSGUID_SUMMARYINFORMATION, PIDSI_AUTHOR}, VT_BSTR, LVCFMT_LEFT, 30, SHCOLSTATE_TYPE_STR, L"Author", L"Author"},
42 {{PSGUID_SUMMARYINFORMATION, PIDSI_SUBJECT}, VT_BSTR, LVCFMT_LEFT, 30, SHCOLSTATE_TYPE_STR, L"Subject", L"Subject"},
43 {{PSGUID_SUMMARYINFORMATION, PIDSI_KEYWORDS}, VT_BSTR, LVCFMT_LEFT, 30, SHCOLSTATE_TYPE_STR, L"Keywords", L"Keywords"},
44 {{PSGUID_SUMMARYINFORMATION, PIDSI_COMMENTS}, VT_BSTR, LVCFMT_LEFT, 30, SHCOLSTATE_TYPE_STR, L"Comments", L"Comments"},
45 {{PSGUID_SUMMARYINFORMATION, PIDSI_PAGECOUNT},VT_BSTR, LVCFMT_LEFT, 30, SHCOLSTATE_TYPE_STR, L"Pagecount", L"Pagecount"}
48 size_t ColumnInfoTableSize = sizeof(ColumnInfoTable)/sizeof(ColumnInfoTable[0]);
53 CColumnInfo::CColumnInfo(long RefCnt) :
54 m_RefCnt(RefCnt)
56 InterlockedIncrement(&g_DllRefCnt);
61 CColumnInfo::~CColumnInfo()
63 InterlockedDecrement(&g_DllRefCnt);
67 // IUnknown methods
70 HRESULT STDMETHODCALLTYPE CColumnInfo::QueryInterface(REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject)
72 *ppvObject = 0;
74 if (IID_IUnknown == riid || IID_IColumnProvider == riid)
76 IUnknown* pUnk = static_cast<IColumnProvider*>(this);
77 pUnk->AddRef();
78 *ppvObject = pUnk;
79 return S_OK;
82 return E_NOINTERFACE;
87 ULONG STDMETHODCALLTYPE CColumnInfo::AddRef()
89 return InterlockedIncrement(&m_RefCnt);
94 ULONG STDMETHODCALLTYPE CColumnInfo::Release()
96 long refcnt = InterlockedDecrement(&m_RefCnt);
98 if (0 == m_RefCnt)
99 delete this;
101 return refcnt;
105 // IColumnProvider
108 HRESULT STDMETHODCALLTYPE CColumnInfo::Initialize(LPCSHCOLUMNINIT /*psci*/)
110 return S_OK;
113 // Register all columns we support
114 HRESULT STDMETHODCALLTYPE CColumnInfo::GetColumnInfo(DWORD dwIndex, SHCOLUMNINFO *psci)
116 if (dwIndex >= ColumnInfoTableSize)
117 return S_FALSE;
119 // Return information on each column we support. Return S_FALSE
120 // to indicate that we have returned information on all our
121 // columns. GetColumnInfo will be called repeatedly until S_FALSE
122 // or an error is returned
123 psci->scid.fmtid = ColumnInfoTable[dwIndex].scid.fmtid;
124 psci->scid.pid = ColumnInfoTable[dwIndex].scid.pid;
125 ZeroMemory(psci->wszTitle, sizeof(psci->wszTitle));
126 wcsncpy(psci->wszTitle, ColumnInfoTable[dwIndex].wszTitle,
127 (sizeof(psci->wszTitle) / sizeof(psci->wszTitle[0]) - 1));
129 return S_OK;
132 HRESULT STDMETHODCALLTYPE CColumnInfo::GetItemData(LPCSHCOLUMNID pscid, LPCSHCOLUMNDATA pscd, VARIANT *pvarData)
134 if (IsOOFileExtension(pscd->pwszExt))
138 std::wstring fname = getShortPathName( std::wstring( pscd->wszFile ) );
140 CMetaInfoReader meta_info_accessor(WStringToString(fname));
142 VariantClear(pvarData);
144 if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_TITLE)
146 pvarData->vt = VT_BSTR;
147 pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagData( META_INFO_TITLE ).c_str());
149 return S_OK;
151 else if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_AUTHOR)
153 pvarData->vt = VT_BSTR;
154 pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagData( META_INFO_AUTHOR).c_str());
156 return S_OK;
158 else if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_SUBJECT)
160 pvarData->vt = VT_BSTR;
161 pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagData( META_INFO_SUBJECT).c_str());
163 return S_OK;
165 else if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_KEYWORDS)
167 pvarData->vt = VT_BSTR;
168 pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagData( META_INFO_KEYWORDS).c_str());
170 return S_OK;
172 else if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_COMMENTS)
174 pvarData->vt = VT_BSTR;
175 pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagData( META_INFO_DESCRIPTION).c_str());
177 return S_OK;
179 else if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_PAGECOUNT)
181 pvarData->vt = VT_BSTR;
182 pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagAttribute( META_INFO_DOCUMENT_STATISTIC, META_INFO_PAGES).c_str());
184 return S_OK;
187 catch (const std::exception&)
189 return S_FALSE;
193 return S_FALSE;
198 bool CColumnInfo::IsOOFileExtension(wchar_t* Extension) const
200 for (size_t i = 0; i < OOFileExtensionTableSize; i++)
202 if (0 == _wcsicmp(Extension, OOFileExtensionTable[i].ExtensionUnicode))
203 return true;
206 return false;
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */