xref: /AOO42X/main/shell/source/win32/shlxthandler/columninfo/columninfo.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3) !
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_shell.hxx"
30 #include "internal/global.hxx"
31 #include "internal/columninfo.hxx"
32 #include "internal/fileextensions.hxx"
33 #include "internal/metainforeader.hxx"
34 #include "internal/utilities.hxx"
35 #include "internal/config.hxx"
36 
37 #include <malloc.h>
38 
39 //----------------------------
40 //
41 //----------------------------
42 
43 namespace /* private */
44 {
45     SHCOLUMNINFO ColumnInfoTable[] =
46     {
47         {{PSGUID_SUMMARYINFORMATION, PIDSI_TITLE},    VT_BSTR, LVCFMT_LEFT, 30, SHCOLSTATE_TYPE_STR, L"Title",    L"Title"},
48         {{PSGUID_SUMMARYINFORMATION, PIDSI_AUTHOR},   VT_BSTR, LVCFMT_LEFT, 30, SHCOLSTATE_TYPE_STR, L"Author",   L"Author"},
49         {{PSGUID_SUMMARYINFORMATION, PIDSI_SUBJECT},  VT_BSTR, LVCFMT_LEFT, 30, SHCOLSTATE_TYPE_STR, L"Subject",  L"Subject"},
50         {{PSGUID_SUMMARYINFORMATION, PIDSI_KEYWORDS}, VT_BSTR, LVCFMT_LEFT, 30, SHCOLSTATE_TYPE_STR, L"Keywords", L"Keywords"},
51         {{PSGUID_SUMMARYINFORMATION, PIDSI_COMMENTS}, VT_BSTR, LVCFMT_LEFT, 30, SHCOLSTATE_TYPE_STR, L"Comments", L"Comments"},
52         {{PSGUID_SUMMARYINFORMATION, PIDSI_PAGECOUNT},VT_BSTR, LVCFMT_LEFT, 30, SHCOLSTATE_TYPE_STR, L"Pagecount", L"Pagecount"}
53     };
54 
55     size_t ColumnInfoTableSize = sizeof(ColumnInfoTable)/sizeof(ColumnInfoTable[0]);
56 }
57 
58 //----------------------------
59 //
60 //----------------------------
61 
62 CColumnInfo::CColumnInfo(long RefCnt) :
63     m_RefCnt(RefCnt)
64 {
65     InterlockedIncrement(&g_DllRefCnt);
66 }
67 
68 //----------------------------
69 //
70 //----------------------------
71 
72 CColumnInfo::~CColumnInfo()
73 {
74     InterlockedDecrement(&g_DllRefCnt);
75 }
76 
77 //-----------------------------
78 // IUnknown methods
79 //-----------------------------
80 
81 HRESULT STDMETHODCALLTYPE CColumnInfo::QueryInterface(REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject)
82 {
83     *ppvObject = 0;
84 
85     if (IID_IUnknown == riid || IID_IColumnProvider == riid)
86     {
87         IUnknown* pUnk = static_cast<IColumnProvider*>(this);
88         pUnk->AddRef();
89         *ppvObject = pUnk;
90         return S_OK;
91     }
92 
93     return E_NOINTERFACE;
94 }
95 
96 //----------------------------
97 //
98 //----------------------------
99 
100 ULONG STDMETHODCALLTYPE CColumnInfo::AddRef(void)
101 {
102     return InterlockedIncrement(&m_RefCnt);
103 }
104 
105 //----------------------------
106 //
107 //----------------------------
108 
109 ULONG STDMETHODCALLTYPE CColumnInfo::Release( void)
110 {
111     long refcnt = InterlockedDecrement(&m_RefCnt);
112 
113     if (0 == m_RefCnt)
114         delete this;
115 
116     return refcnt;
117 }
118 
119 //-----------------------------
120 // IColumnProvider
121 //-----------------------------
122 
123 HRESULT STDMETHODCALLTYPE CColumnInfo::Initialize(LPCSHCOLUMNINIT /*psci*/)
124 {
125     return S_OK;
126 }
127 
128 //-----------------------------
129 // Register all columns we support
130 //-----------------------------
131 
132 HRESULT STDMETHODCALLTYPE CColumnInfo::GetColumnInfo(DWORD dwIndex, SHCOLUMNINFO *psci)
133 {
134     if (dwIndex >= ColumnInfoTableSize)
135         return S_FALSE;
136 
137     //  Return information on each column we support. Return S_FALSE
138     //  to indicate that we have returned information on all our
139     //  columns. GetColumnInfo will be called repeatedly until S_FALSE
140     //  or an error is returned
141     psci->scid.fmtid = ColumnInfoTable[dwIndex].scid.fmtid;
142     psci->scid.pid   = ColumnInfoTable[dwIndex].scid.pid;
143     ZeroMemory(psci->wszTitle, sizeof(psci->wszTitle));
144     wcsncpy(psci->wszTitle, ColumnInfoTable[dwIndex].wszTitle, (sizeof(psci->wszTitle) - 1));
145 
146     //wcscpy(psci->wszTitle, ColumnInfoTable[dwIndex].wszTitle);
147 
148     return S_OK;
149 }
150 
151 //-----------------------------
152 //
153 //-----------------------------
154 
155 HRESULT STDMETHODCALLTYPE CColumnInfo::GetItemData(LPCSHCOLUMNID pscid, LPCSHCOLUMNDATA pscd, VARIANT *pvarData)
156 {
157     if (IsOOFileExtension(pscd->pwszExt))
158     {
159         try
160         {
161             std::wstring fname = getShortPathName( std::wstring( pscd->wszFile ) );
162 
163             CMetaInfoReader meta_info_accessor(WStringToString(fname));
164 
165             VariantClear(pvarData);
166 
167             if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_TITLE)
168             {
169                 pvarData->vt = VT_BSTR;
170                 pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagData( META_INFO_TITLE ).c_str());
171 
172                 return S_OK;
173             }
174             else if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_AUTHOR)
175             {
176                 pvarData->vt = VT_BSTR;
177                 pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagData( META_INFO_AUTHOR).c_str());
178 
179                 return S_OK;
180             }
181             else if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_SUBJECT)
182             {
183                 pvarData->vt = VT_BSTR;
184                 pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagData( META_INFO_SUBJECT).c_str());
185 
186                 return S_OK;
187             }
188             else if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_KEYWORDS)
189             {
190                 pvarData->vt = VT_BSTR;
191                 pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagData( META_INFO_KEYWORDS).c_str());
192 
193                 return S_OK;
194             }
195             else if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_COMMENTS)
196             {
197                 pvarData->vt = VT_BSTR;
198                 pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagData( META_INFO_DESCRIPTION).c_str());
199 
200                 return S_OK;
201             }
202             else if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_PAGECOUNT)
203             {
204                 pvarData->vt = VT_BSTR;
205                 pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagAttribute( META_INFO_DOCUMENT_STATISTIC, META_INFO_PAGES).c_str());
206 
207                 return S_OK;
208             }
209         }
210         catch (const std::exception&)
211         {
212             return S_FALSE;
213         }
214     }
215 
216     return S_FALSE;
217 }
218 
219 //-----------------------------
220 //
221 //-----------------------------
222 
223 bool CColumnInfo::IsOOFileExtension(wchar_t* Extension) const
224 {
225     for (size_t i = 0; i < OOFileExtensionTableSize; i++)
226     {
227         if (0 == _wcsicmp(Extension, OOFileExtensionTable[i].ExtensionUnicode))
228             return true;
229     }
230 
231     return false;
232 }
233