Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #include "vbadocumentproperties.hxx"
29 : : #include <cppuhelper/implbase1.hxx>
30 : : #include <cppuhelper/implbase3.hxx>
31 : : #include <com/sun/star/document/XDocumentInfoSupplier.hpp>
32 : : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
33 : : #include <com/sun/star/beans/NamedValue.hpp>
34 : : #include <com/sun/star/beans/XPropertyContainer.hpp>
35 : : #include <ooo/vba/word/WdBuiltInProperty.hpp>
36 : : #include <ooo/vba/office/MsoDocProperties.hpp>
37 : : #include <memory>
38 : : #include <boost/shared_ptr.hpp>
39 : : #include "wordvbahelper.hxx"
40 : : #include "fesh.hxx"
41 : : #include "docsh.hxx"
42 : : using namespace ::ooo::vba;
43 : : using namespace css;
44 : :
45 : 0 : sal_Int8 lcl_toMSOPropType( const uno::Type& aType ) throw ( lang::IllegalArgumentException )
46 : : {
47 : 0 : sal_Int16 msoType = office::MsoDocProperties::msoPropertyTypeString;
48 : :
49 [ # # # # : 0 : switch ( aType.getTypeClass() )
# ]
50 : : {
51 : : case uno::TypeClass_BOOLEAN:
52 : 0 : msoType = office::MsoDocProperties::msoPropertyTypeBoolean;
53 : 0 : break;
54 : : case uno::TypeClass_FLOAT:
55 : 0 : msoType = office::MsoDocProperties::msoPropertyTypeFloat;
56 : 0 : break;
57 : : case uno::TypeClass_STRUCT: // Assume date
58 : 0 : msoType = office::MsoDocProperties::msoPropertyTypeDate;
59 : 0 : break;
60 : : case uno::TypeClass_BYTE:
61 : : case uno::TypeClass_SHORT:
62 : : case uno::TypeClass_LONG:
63 : : case uno::TypeClass_HYPER:
64 : 0 : msoType = office::MsoDocProperties::msoPropertyTypeNumber;
65 : 0 : break;
66 : : default:
67 [ # # ]: 0 : throw lang::IllegalArgumentException();
68 : : }
69 : 0 : return msoType;
70 : : }
71 : :
72 : : class PropertGetSetHelper
73 : : {
74 : : protected:
75 : : uno::Reference< frame::XModel > m_xModel;
76 : : uno::Reference< beans::XPropertySet > mxProps;
77 : : public:
78 : 0 : PropertGetSetHelper( const uno::Reference< frame::XModel >& xModel ):m_xModel( xModel )
79 : : {
80 [ # # ]: 0 : uno::Reference< document::XDocumentInfoSupplier > xDocInfoSupp( m_xModel, uno::UNO_QUERY_THROW );
81 [ # # ][ # # ]: 0 : mxProps.set( xDocInfoSupp->getDocumentInfo(), uno::UNO_QUERY_THROW );
[ # # ]
82 : 0 : }
83 [ # # ]: 0 : virtual ~PropertGetSetHelper() {}
84 : : virtual uno::Any getPropertyValue( const rtl::OUString& rPropName ) = 0;
85 : : virtual void setPropertyValue( const rtl::OUString& rPropName, const uno::Any& aValue ) = 0;
86 : 0 : virtual uno::Reference< beans::XPropertySet > getUnoProperties() { return mxProps; }
87 : :
88 : : };
89 : :
90 [ # # ]: 0 : class BuiltinPropertyGetSetHelper : public PropertGetSetHelper
91 : : {
92 : : public:
93 : 0 : BuiltinPropertyGetSetHelper( const uno::Reference< frame::XModel >& xModel ) :PropertGetSetHelper( xModel )
94 : : {
95 : 0 : }
96 : 0 : virtual uno::Any getPropertyValue( const rtl::OUString& rPropName )
97 : : {
98 [ # # ]: 0 : if ( rPropName == "EditingDuration" )
99 : : {
100 : 0 : sal_Int32 nSecs = 0;
101 [ # # ][ # # ]: 0 : mxProps->getPropertyValue( rPropName ) >>= nSecs;
102 [ # # ]: 0 : return uno::makeAny( nSecs/60 ); // minutes
103 : : }
104 : 0 : return mxProps->getPropertyValue( rPropName );
105 : : }
106 : 0 : virtual void setPropertyValue( const rtl::OUString& rPropName, const uno::Any& aValue )
107 : : {
108 : 0 : mxProps->setPropertyValue( rPropName, aValue );
109 : 0 : }
110 : : };
111 : :
112 [ # # ]: 0 : class CustomPropertyGetSetHelper : public BuiltinPropertyGetSetHelper
113 : : {
114 : : public:
115 : 0 : CustomPropertyGetSetHelper( const uno::Reference< frame::XModel >& xModel ) :BuiltinPropertyGetSetHelper( xModel )
116 : : {
117 [ # # ]: 0 : uno::Reference< document::XDocumentPropertiesSupplier > xDocPropSupp( mxProps, uno::UNO_QUERY_THROW );
118 [ # # ][ # # ]: 0 : uno::Reference< document::XDocumentProperties > xDocProp( xDocPropSupp->getDocumentProperties(), uno::UNO_QUERY_THROW );
[ # # ]
119 [ # # ][ # # ]: 0 : mxProps.set( xDocProp->getUserDefinedProperties(), uno::UNO_QUERY_THROW );
[ # # ]
120 : 0 : }
121 : : };
122 [ # # ]: 0 : class StatisticPropertyGetSetHelper : public PropertGetSetHelper
123 : : {
124 : : SwDocShell* mpDocShell;
125 : : uno::Reference< beans::XPropertySet > mxModelProps;
126 : : public:
127 : 0 : StatisticPropertyGetSetHelper( const uno::Reference< frame::XModel >& xModel ) :PropertGetSetHelper( xModel ) , mpDocShell( NULL )
128 : : {
129 [ # # ]: 0 : mxModelProps.set( m_xModel, uno::UNO_QUERY_THROW );
130 [ # # ]: 0 : mpDocShell = word::getDocShell( xModel );
131 : 0 : }
132 : 0 : virtual uno::Any getPropertyValue( const rtl::OUString& rPropName )
133 : : {
134 [ # # ]: 0 : uno::Sequence< beans::NamedValue > stats;
135 : : try
136 : : {
137 : : // Characters, ParagraphCount & WordCount are available from
138 : : // the model ( and addtionally these also update the statics object )
139 [ # # ][ # # ]: 0 : return mxModelProps->getPropertyValue( rPropName );
140 : : }
141 [ # # ]: 0 : catch (const uno::Exception&)
142 : : {
143 : : OSL_TRACE("Got exception");
144 : : }
145 : 0 : uno::Any aReturn;
146 [ # # ]: 0 : if ( rPropName == "LineCount" ) // special processing needed
147 : : {
148 [ # # ]: 0 : if ( mpDocShell )
149 : : {
150 [ # # ]: 0 : SwFEShell* pFEShell = mpDocShell->GetFEShell();
151 [ # # ]: 0 : if(pFEShell)
152 : : {
153 [ # # # # ]: 0 : aReturn <<= pFEShell->GetLineCount(sal_False);
154 : : }
155 : : }
156 : : }
157 : : else
158 : : {
159 [ # # # # : 0 : mxModelProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParagraphCount") ) ) >>= stats;
# # # # ]
160 [ # # # # : 0 : mxProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("DocumentStatistic") ) ) >>= stats;
# # # # ]
161 : :
162 : 0 : sal_Int32 nLen = stats.getLength();
163 : 0 : bool bFound = false;
164 [ # # # # : 0 : for ( sal_Int32 index = 0; index < nLen && !bFound ; ++index )
# # ]
165 : : {
166 [ # # # # ]: 0 : if ( rPropName.equals( stats[ index ].Name ) )
167 : : {
168 [ # # ]: 0 : aReturn = stats[ index ].Value;
169 : 0 : bFound = true;
170 : : }
171 : : }
172 [ # # ]: 0 : if ( !bFound )
173 [ # # ]: 0 : throw uno::RuntimeException(); // bad Property
174 : : }
175 [ # # ][ # # ]: 0 : return aReturn;
176 : : }
177 : :
178 : 0 : virtual void setPropertyValue( const rtl::OUString& rPropName, const uno::Any& aValue )
179 : : {
180 : :
181 [ # # ]: 0 : uno::Sequence< beans::NamedValue > stats;
182 [ # # ][ # # ]: 0 : mxProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("DocumentStatistic") ) ) >>= stats;
[ # # ][ # # ]
183 : :
184 : 0 : sal_Int32 nLen = stats.getLength();
185 [ # # ]: 0 : for ( sal_Int32 index = 0; index < nLen; ++index )
186 : : {
187 [ # # ][ # # ]: 0 : if ( rPropName.equals( stats[ index ].Name ) )
188 : : {
189 [ # # ]: 0 : stats[ index ].Value = aValue;
190 [ # # ][ # # ]: 0 : mxProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("DocumentStatistic") ), uno::makeAny( stats ) );
[ # # ][ # # ]
191 : 0 : break;
192 : : }
193 [ # # ]: 0 : }
194 : 0 : }
195 : : };
196 : :
197 [ # # ][ # # ]: 0 : class DocPropInfo
[ # # ]
198 : : {
199 : : public:
200 : : rtl::OUString msMSODesc;
201 : : rtl::OUString msOOOPropName;
202 : : boost::shared_ptr< PropertGetSetHelper > mpPropGetSetHelper;
203 : :
204 : 0 : static DocPropInfo createDocPropInfo( const rtl::OUString& sDesc, const rtl::OUString& sPropName, boost::shared_ptr< PropertGetSetHelper >& rHelper )
205 : : {
206 : 0 : DocPropInfo aItem;
207 : 0 : aItem.msMSODesc = sDesc;
208 : 0 : aItem.msOOOPropName = sPropName;
209 [ # # ]: 0 : aItem.mpPropGetSetHelper = rHelper;
210 : 0 : return aItem;
211 : : }
212 : :
213 : 0 : static DocPropInfo createDocPropInfo( const sal_Char* sDesc, const sal_Char* sPropName, boost::shared_ptr< PropertGetSetHelper >& rHelper )
214 : : {
215 [ # # ]: 0 : return createDocPropInfo( rtl::OUString::createFromAscii( sDesc ), rtl::OUString::createFromAscii( sPropName ), rHelper );
216 : : }
217 : 0 : uno::Any getValue()
218 : : {
219 [ # # ]: 0 : if ( mpPropGetSetHelper.get() )
220 : 0 : return mpPropGetSetHelper->getPropertyValue( msOOOPropName );
221 : 0 : return uno::Any();
222 : : }
223 : 0 : void setValue( const uno::Any& rValue )
224 : : {
225 [ # # ]: 0 : if ( mpPropGetSetHelper.get() )
226 : 0 : mpPropGetSetHelper->setPropertyValue( msOOOPropName, rValue );
227 : 0 : }
228 : 0 : uno::Reference< beans::XPropertySet > getUnoProperties()
229 : : {
230 : :
231 : 0 : uno::Reference< beans::XPropertySet > xProps;
232 [ # # ]: 0 : if ( mpPropGetSetHelper.get() )
233 [ # # ]: 0 : return mpPropGetSetHelper->getUnoProperties();
234 : 0 : return xProps;
235 : : }
236 : : };
237 : :
238 : :
239 : : typedef boost::unordered_map< sal_Int32, DocPropInfo > MSOIndexToOODocPropInfo;
240 : :
241 : 0 : class BuiltInIndexHelper
242 : : {
243 : : MSOIndexToOODocPropInfo m_docPropInfoMap;
244 : : BuiltInIndexHelper();
245 : : public:
246 : 0 : BuiltInIndexHelper( const uno::Reference< frame::XModel >& xModel )
247 [ # # ]: 0 : {
248 [ # # ][ # # ]: 0 : boost::shared_ptr< PropertGetSetHelper > aStandardHelper( new BuiltinPropertyGetSetHelper( xModel ) );
[ # # ]
249 [ # # ][ # # ]: 0 : boost::shared_ptr< PropertGetSetHelper > aUsingStatsHelper( new StatisticPropertyGetSetHelper( xModel ) );
[ # # ]
250 : :
251 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyTitle ] = DocPropInfo::createDocPropInfo( "Title", "Title", aStandardHelper );
[ # # ][ # # ]
252 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertySubject ] = DocPropInfo::createDocPropInfo( "Subject", "Subject", aStandardHelper );
[ # # ][ # # ]
253 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyAuthor ] = DocPropInfo::createDocPropInfo( "Author", "Author", aStandardHelper );
[ # # ][ # # ]
254 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyKeywords ] = DocPropInfo::createDocPropInfo( "Keywords", "Keywords", aStandardHelper );
[ # # ][ # # ]
255 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyComments ] = DocPropInfo::createDocPropInfo( "Comments", "Description", aStandardHelper );
[ # # ][ # # ]
256 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyTemplate ] = DocPropInfo::createDocPropInfo( "Template", "Template", aStandardHelper );
[ # # ][ # # ]
257 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyLastAuthor ] = DocPropInfo::createDocPropInfo( "Last author", "ModifiedBy", aStandardHelper ); // doesn't seem to exist - throw or return nothing ?
[ # # ][ # # ]
258 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyRevision ] = DocPropInfo::createDocPropInfo( "Revision number", "EditingCycles", aStandardHelper ); // doesn't seem to exist - throw or return nothing ?
[ # # ][ # # ]
259 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyAppName ] = DocPropInfo::createDocPropInfo( "Application name", "Generator", aStandardHelper ); // doesn't seem to exist - throw or return nothing ?
[ # # ][ # # ]
260 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyTimeLastPrinted ] = DocPropInfo::createDocPropInfo( "Last print date", "PrintDate", aStandardHelper ); // doesn't seem to exist - throw or return nothing ?
[ # # ][ # # ]
261 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyTimeCreated ] = DocPropInfo::createDocPropInfo( "Creation date", "CreationDate", aStandardHelper );
[ # # ][ # # ]
262 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyTimeLastSaved ] = DocPropInfo::createDocPropInfo( "Last save time", "ModifyDate", aStandardHelper );
[ # # ][ # # ]
263 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyVBATotalEdit ] = DocPropInfo::createDocPropInfo( "Total editing time", "EditingDuration", aStandardHelper ); // Not sure if this is correct
[ # # ][ # # ]
264 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyPages ] = DocPropInfo::createDocPropInfo( "Number of pages", "PageCount", aUsingStatsHelper ); // special handling required ?
[ # # ][ # # ]
265 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyWords ] = DocPropInfo::createDocPropInfo( "Number of words", "WordCount", aUsingStatsHelper ); // special handling require ?
[ # # ][ # # ]
266 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyCharacters ] = DocPropInfo::createDocPropInfo( "Number of characters", "CharacterCount", aUsingStatsHelper ); // special handling required ?
[ # # ][ # # ]
267 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertySecurity ] = DocPropInfo::createDocPropInfo( "Security", "", aStandardHelper ); // doesn't seem to exist
[ # # ][ # # ]
268 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyCategory ] = DocPropInfo::createDocPropInfo( "Category", "Category", aStandardHelper ); // hacked in
[ # # ][ # # ]
269 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyFormat ] = DocPropInfo::createDocPropInfo( "Format", "", aStandardHelper ); // doesn't seem to exist
[ # # ][ # # ]
270 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyManager ] = DocPropInfo::createDocPropInfo( "Manager", "Manager", aStandardHelper ); // hacked in
[ # # ][ # # ]
271 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyCompany ] = DocPropInfo::createDocPropInfo( "Company", "Company", aStandardHelper ); // hacked in
[ # # ][ # # ]
272 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyBytes ] = DocPropInfo::createDocPropInfo( "Number of bytes", "", aStandardHelper ); // doesn't seem to exist - size on disk exists ( for an already saved document ) perhaps it will do ( or we need something else )
[ # # ][ # # ]
273 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyLines ] = DocPropInfo::createDocPropInfo( "Number of lines", "LineCount", aUsingStatsHelper ); // special handling
[ # # ][ # # ]
274 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyParas ] = DocPropInfo::createDocPropInfo( "Number of paragraphs", "ParagraphCount", aUsingStatsHelper ); // special handling
[ # # ][ # # ]
275 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertySlides ] = DocPropInfo::createDocPropInfo( "Number of slides", "" , aStandardHelper ); // doesn't seem to exist
[ # # ][ # # ]
276 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyNotes ] = DocPropInfo::createDocPropInfo( "Number of notes", "", aStandardHelper ); // doesn't seem to exist
[ # # ][ # # ]
277 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyHiddenSlides ] = DocPropInfo::createDocPropInfo("Number of hidden Slides", "", aStandardHelper ); // doesn't seem to exist
[ # # ][ # # ]
278 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyMMClips ] = DocPropInfo::createDocPropInfo( "Number of multimedia clips", "", aStandardHelper ); // doesn't seem to exist
[ # # ][ # # ]
279 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyHyperlinkBase ] = DocPropInfo::createDocPropInfo( "Hyperlink base", "AutoloadURL", aStandardHelper );
[ # # ][ # # ]
280 [ # # ][ # # ]: 0 : m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyCharsWSpaces ] = DocPropInfo::createDocPropInfo( "Number of characters (with spaces)", "", aStandardHelper ); // doesn't seem to be supported
[ # # ][ # # ]
[ # # ][ # # ]
281 : 0 : }
282 : :
283 : 0 : MSOIndexToOODocPropInfo& getDocPropInfoMap() { return m_docPropInfoMap; }
284 : : };
285 : :
286 : :
287 : : typedef InheritedHelperInterfaceImpl1< ooo::vba::XDocumentProperty > SwVbaDocumentProperty_BASE;
288 : :
289 [ # # ][ # # ]: 0 : class SwVbaBuiltInDocumentProperty : public SwVbaDocumentProperty_BASE
290 : : {
291 : : protected:
292 : : DocPropInfo mPropInfo;
293 : : public:
294 : : SwVbaBuiltInDocumentProperty( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const DocPropInfo& rInfo );
295 : : // XDocumentProperty
296 : : virtual void SAL_CALL Delete( ) throw (script::BasicErrorException, uno::RuntimeException);
297 : : virtual ::rtl::OUString SAL_CALL getName( ) throw (script::BasicErrorException, uno::RuntimeException);
298 : : virtual void SAL_CALL setName( const ::rtl::OUString& Name ) throw (script::BasicErrorException, uno::RuntimeException);
299 : : virtual ::sal_Int8 SAL_CALL getType( ) throw (script::BasicErrorException, uno::RuntimeException);
300 : : virtual void SAL_CALL setType( ::sal_Int8 Type ) throw (script::BasicErrorException, uno::RuntimeException);
301 : : virtual ::sal_Bool SAL_CALL getLinkToContent( ) throw (script::BasicErrorException, uno::RuntimeException);
302 : : virtual void SAL_CALL setLinkToContent( ::sal_Bool LinkToContent ) throw (script::BasicErrorException, uno::RuntimeException);
303 : : virtual uno::Any SAL_CALL getValue( ) throw (script::BasicErrorException, uno::RuntimeException);
304 : : virtual void SAL_CALL setValue( const uno::Any& Value ) throw (script::BasicErrorException, uno::RuntimeException);
305 : : virtual rtl::OUString SAL_CALL getLinkSource( ) throw (script::BasicErrorException, uno::RuntimeException);
306 : : virtual void SAL_CALL setLinkSource( const rtl::OUString& LinkSource ) throw (script::BasicErrorException, uno::RuntimeException);
307 : : //XDefaultProperty
308 : 0 : virtual ::rtl::OUString SAL_CALL getDefaultPropertyName( ) throw (uno::RuntimeException) { return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Value")); }
309 : : // XHelperInterface
310 : : virtual rtl::OUString getServiceImplName();
311 : : virtual uno::Sequence<rtl::OUString> getServiceNames();
312 : : };
313 : :
314 [ # # ]: 0 : class SwVbaCustomDocumentProperty : public SwVbaBuiltInDocumentProperty
315 : : {
316 : : public:
317 : :
318 : : SwVbaCustomDocumentProperty( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const DocPropInfo& rInfo );
319 : :
320 : : virtual ::sal_Bool SAL_CALL getLinkToContent( ) throw (script::BasicErrorException, uno::RuntimeException);
321 : : virtual void SAL_CALL setLinkToContent( ::sal_Bool LinkToContent ) throw (script::BasicErrorException, uno::RuntimeException);
322 : :
323 : : virtual rtl::OUString SAL_CALL getLinkSource( ) throw (script::BasicErrorException, uno::RuntimeException);
324 : : virtual void SAL_CALL setLinkSource( const rtl::OUString& LinkSource ) throw (script::BasicErrorException, uno::RuntimeException);
325 : : virtual void SAL_CALL Delete( ) throw (script::BasicErrorException, uno::RuntimeException);
326 : : virtual void SAL_CALL setName( const ::rtl::OUString& Name ) throw (script::BasicErrorException, uno::RuntimeException);
327 : : virtual void SAL_CALL setType( ::sal_Int8 Type ) throw (script::BasicErrorException, uno::RuntimeException);
328 : :
329 : : };
330 : :
331 : :
332 : 0 : SwVbaCustomDocumentProperty::SwVbaCustomDocumentProperty( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const DocPropInfo& rInfo ) : SwVbaBuiltInDocumentProperty( xParent, xContext, rInfo )
333 : : {
334 : 0 : }
335 : :
336 : : sal_Bool
337 : 0 : SwVbaCustomDocumentProperty::getLinkToContent( ) throw (script::BasicErrorException, uno::RuntimeException)
338 : : {
339 : : // #FIXME we need to store the link content somewhere
340 : 0 : return sal_False;
341 : : }
342 : :
343 : : void
344 : 0 : SwVbaCustomDocumentProperty::setLinkToContent( sal_Bool /*bLinkContent*/ ) throw (script::BasicErrorException, uno::RuntimeException)
345 : : {
346 : 0 : }
347 : :
348 : : rtl::OUString
349 : 0 : SwVbaCustomDocumentProperty::getLinkSource( ) throw (script::BasicErrorException, uno::RuntimeException)
350 : : {
351 : : // #FIXME we need to store the link content somewhere
352 : 0 : return rtl::OUString();
353 : : }
354 : :
355 : : void
356 : 0 : SwVbaCustomDocumentProperty::setLinkSource( const rtl::OUString& /*rsLinkContent*/ ) throw (script::BasicErrorException, uno::RuntimeException)
357 : : {
358 : : // #FIXME we need to store the link source somewhere
359 : 0 : }
360 : :
361 : : void SAL_CALL
362 : 0 : SwVbaCustomDocumentProperty::setName( const ::rtl::OUString& /*Name*/ ) throw (script::BasicErrorException, uno::RuntimeException)
363 : : {
364 : : // setName on existing property ?
365 : : // #FIXME
366 : : // do we need to delete existing property and create a new one?
367 : 0 : }
368 : :
369 : : void SAL_CALL
370 : 0 : SwVbaCustomDocumentProperty::setType( ::sal_Int8 /*Type*/ ) throw (script::BasicErrorException, uno::RuntimeException)
371 : : {
372 : : // setType, do we need to do a conversion?
373 : : // #FIXME the underlying value needs to be changed to the new type
374 : 0 : }
375 : :
376 : : void SAL_CALL
377 : 0 : SwVbaCustomDocumentProperty::Delete( ) throw (script::BasicErrorException, uno::RuntimeException)
378 : : {
379 [ # # ][ # # ]: 0 : uno::Reference< beans::XPropertyContainer > xContainer( mPropInfo.getUnoProperties(), uno::UNO_QUERY_THROW );
380 [ # # ][ # # ]: 0 : xContainer->removeProperty( getName() );
[ # # ]
381 : 0 : }
382 : :
383 [ # # ]: 0 : SwVbaBuiltInDocumentProperty::SwVbaBuiltInDocumentProperty( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const DocPropInfo& rInfo ) : SwVbaDocumentProperty_BASE( xParent, xContext ), mPropInfo( rInfo )
384 : : {
385 : 0 : }
386 : :
387 : : void SAL_CALL
388 : 0 : SwVbaBuiltInDocumentProperty::Delete( ) throw (script::BasicErrorException, uno::RuntimeException)
389 : : {
390 : : // not valid for Builtin
391 [ # # ]: 0 : throw uno::RuntimeException();
392 : : }
393 : :
394 : : ::rtl::OUString SAL_CALL
395 : 0 : SwVbaBuiltInDocumentProperty::getName( ) throw (script::BasicErrorException, uno::RuntimeException)
396 : : {
397 : 0 : return mPropInfo.msMSODesc;
398 : : }
399 : :
400 : : void SAL_CALL
401 : 0 : SwVbaBuiltInDocumentProperty::setName( const rtl::OUString& ) throw (script::BasicErrorException, uno::RuntimeException)
402 : : {
403 : : // not valid for Builtin
404 [ # # ]: 0 : throw uno::RuntimeException();
405 : : }
406 : :
407 : : ::sal_Int8 SAL_CALL
408 : 0 : SwVbaBuiltInDocumentProperty::getType( ) throw (script::BasicErrorException, uno::RuntimeException)
409 : : {
410 [ # # ]: 0 : return lcl_toMSOPropType( getValue().getValueType() );
411 : : }
412 : :
413 : : void SAL_CALL
414 : 0 : SwVbaBuiltInDocumentProperty::setType( ::sal_Int8 /*Type*/ ) throw (script::BasicErrorException, uno::RuntimeException)
415 : : {
416 : : // not valid for Builtin
417 [ # # ]: 0 : throw uno::RuntimeException();
418 : : }
419 : :
420 : : ::sal_Bool SAL_CALL
421 : 0 : SwVbaBuiltInDocumentProperty::getLinkToContent( ) throw (script::BasicErrorException, uno::RuntimeException)
422 : : {
423 : 0 : return sal_False; // built-in always false
424 : : }
425 : :
426 : : void SAL_CALL
427 : 0 : SwVbaBuiltInDocumentProperty::setLinkToContent( ::sal_Bool /*LinkToContent*/ ) throw (script::BasicErrorException, uno::RuntimeException)
428 : : {
429 : : // not valid for Builtin
430 [ # # ]: 0 : throw uno::RuntimeException();
431 : : }
432 : :
433 : : uno::Any SAL_CALL
434 : 0 : SwVbaBuiltInDocumentProperty::getValue( ) throw (script::BasicErrorException, uno::RuntimeException)
435 : : {
436 : 0 : uno::Any aRet = mPropInfo.getValue();
437 [ # # ]: 0 : if ( !aRet.hasValue() )
438 [ # # ]: 0 : throw uno::RuntimeException();
439 : 0 : return aRet;
440 : : }
441 : :
442 : : void SAL_CALL
443 : 0 : SwVbaBuiltInDocumentProperty::setValue( const uno::Any& Value ) throw (script::BasicErrorException, uno::RuntimeException)
444 : : {
445 : 0 : mPropInfo.setValue( Value );
446 : 0 : }
447 : :
448 : : rtl::OUString SAL_CALL
449 : 0 : SwVbaBuiltInDocumentProperty::getLinkSource( ) throw (script::BasicErrorException, uno::RuntimeException)
450 : : {
451 : : // not valid for Builtin
452 [ # # ]: 0 : throw uno::RuntimeException();
453 : : }
454 : :
455 : : void SAL_CALL
456 : 0 : SwVbaBuiltInDocumentProperty::setLinkSource( const rtl::OUString& /*LinkSource*/ ) throw (script::BasicErrorException, uno::RuntimeException)
457 : : {
458 : : // not valid for Builtin
459 [ # # ]: 0 : throw uno::RuntimeException();
460 : : }
461 : :
462 : : rtl::OUString
463 : 0 : SwVbaBuiltInDocumentProperty::getServiceImplName()
464 : : {
465 : 0 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwVbaBuiltinDocumentProperty"));
466 : : }
467 : :
468 : : uno::Sequence<rtl::OUString>
469 : 0 : SwVbaBuiltInDocumentProperty::getServiceNames()
470 : : {
471 [ # # ][ # # ]: 0 : static uno::Sequence< rtl::OUString > aServiceNames;
[ # # ][ # # ]
472 [ # # ]: 0 : if ( aServiceNames.getLength() == 0 )
473 : : {
474 : 0 : aServiceNames.realloc( 1 );
475 [ # # ]: 0 : aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.DocumentProperty" ) );
476 : : }
477 : 0 : return aServiceNames;
478 : : }
479 : : typedef ::cppu::WeakImplHelper3< com::sun::star::container::XIndexAccess
480 : : ,com::sun::star::container::XNameAccess
481 : : ,com::sun::star::container::XEnumerationAccess
482 : : > PropertiesImpl_BASE;
483 : :
484 : : typedef boost::unordered_map< sal_Int32, uno::Reference< XDocumentProperty > > DocProps;
485 : :
486 : : typedef ::cppu::WeakImplHelper1< com::sun::star::container::XEnumeration > DocPropEnumeration_BASE;
487 [ # # ][ # # ]: 0 : class DocPropEnumeration : public DocPropEnumeration_BASE
488 : : {
489 : : DocProps mDocProps;
490 : : DocProps::iterator mIt;
491 : : public:
492 : :
493 [ # # ][ # # ]: 0 : DocPropEnumeration( const DocProps& rProps ) : mDocProps( rProps ), mIt( mDocProps.begin() ) {}
494 : 0 : virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException)
495 : : {
496 : 0 : return mIt != mDocProps.end();
497 : : }
498 : 0 : virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
499 : : {
500 [ # # ]: 0 : if ( !hasMoreElements() )
501 [ # # ]: 0 : throw container::NoSuchElementException();
502 [ # # ][ # # ]: 0 : return uno::makeAny( mIt++->second );
503 : : }
504 : : };
505 : :
506 : : typedef boost::unordered_map< rtl::OUString, uno::Reference< XDocumentProperty >, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > DocPropsByName;
507 : :
508 [ # # ][ # # ]: 0 : class BuiltInPropertiesImpl : public PropertiesImpl_BASE
[ # # ]
509 : : {
510 : : protected:
511 : :
512 : : uno::Reference< XHelperInterface > m_xParent;
513 : : uno::Reference< uno::XComponentContext > m_xContext;
514 : : uno::Reference< frame::XModel > m_xModel;
515 : : uno::Reference< document::XDocumentInfo > m_xOOOBuiltIns;
516 : :
517 : : DocProps mDocProps;
518 : : DocPropsByName mNamedDocProps;
519 : :
520 : : public:
521 [ # # ][ # # ]: 0 : BuiltInPropertiesImpl( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ) : m_xParent( xParent ), m_xContext( xContext ), m_xModel( xModel )
522 : : {
523 [ # # ]: 0 : BuiltInIndexHelper builtIns( m_xModel );
524 [ # # ]: 0 : for ( sal_Int32 index = word::WdBuiltInProperty::wdPropertyTitle; index <= word::WdBuiltInProperty::wdPropertyCharsWSpaces; ++index )
525 : : {
526 [ # # ][ # # ]: 0 : mDocProps[ index ] = new SwVbaBuiltInDocumentProperty( xParent, xContext, builtIns.getDocPropInfoMap()[ index ] );
[ # # ][ # # ]
[ # # ]
527 [ # # ][ # # ]: 0 : mNamedDocProps[ mDocProps[ index ]->getName() ] = mDocProps[ index ];
[ # # ][ # # ]
[ # # ][ # # ]
528 [ # # ]: 0 : }
529 : 0 : }
530 : : // XIndexAccess
531 : 0 : virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException)
532 : : {
533 : 0 : return mDocProps.size();
534 : : }
535 : 0 : virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException )
536 : : {
537 : : // correct the correct by the base class for 1 based indices
538 [ # # ]: 0 : DocProps::iterator it = mDocProps.find( ++Index );
539 [ # # ][ # # ]: 0 : if ( it == mDocProps.end() )
540 [ # # ]: 0 : throw lang::IndexOutOfBoundsException();
541 [ # # ][ # # ]: 0 : return uno::makeAny( it->second );
542 : : }
543 : 0 : virtual uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
544 : : {
545 [ # # ][ # # ]: 0 : if ( !hasByName( aName ) )
546 [ # # ]: 0 : throw container::NoSuchElementException();
547 [ # # ]: 0 : DocPropsByName::iterator it = mNamedDocProps.find( aName );
548 [ # # ][ # # ]: 0 : return uno::Any( it->second );
549 : :
550 : : }
551 : 0 : virtual uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (uno::RuntimeException)
552 : : {
553 [ # # ][ # # ]: 0 : uno::Sequence< rtl::OUString > aNames( getCount() );
554 [ # # ]: 0 : rtl::OUString* pName = aNames.getArray();
555 [ # # ]: 0 : DocPropsByName::iterator it_end = mNamedDocProps.end();
556 [ # # ][ # # ]: 0 : for( DocPropsByName::iterator it = mNamedDocProps.begin(); it != it_end; ++it, ++pName )
557 [ # # ]: 0 : *pName = it->first;
558 : 0 : return aNames;
559 : : }
560 : :
561 : 0 : virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (uno::RuntimeException)
562 : : {
563 [ # # ]: 0 : DocPropsByName::iterator it = mNamedDocProps.find( aName );
564 [ # # ][ # # ]: 0 : if ( it == mNamedDocProps.end() )
565 : 0 : return sal_False;
566 : 0 : return sal_True;
567 : : }
568 : : // XElementAccess
569 : 0 : virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException)
570 : : {
571 : 0 : return XDocumentProperty::static_type(0);
572 : : }
573 : 0 : virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException)
574 : : {
575 : 0 : return mDocProps.size() > 0;
576 : : }
577 : 0 : virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) throw (uno::RuntimeException)
578 : : {
579 [ # # ][ # # ]: 0 : return new DocPropEnumeration( mDocProps );
580 : : }
581 : : };
582 : :
583 [ # # ][ # # ]: 0 : SwVbaBuiltinDocumentProperties::SwVbaBuiltinDocumentProperties( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ) : SwVbaDocumentproperties_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( new BuiltInPropertiesImpl( xParent, xContext, xModel ) ) ), m_xModel( xModel )
[ # # ]
584 : : {
585 : 0 : }
586 : :
587 : : uno::Reference< XDocumentProperty > SAL_CALL
588 : 0 : SwVbaBuiltinDocumentProperties::Add( const ::rtl::OUString& /*Name*/, ::sal_Bool /*LinkToContent*/, ::sal_Int8 /*Type*/, const uno::Any& /*value*/, const uno::Any& /*LinkSource*/ ) throw (script::BasicErrorException, uno::RuntimeException)
589 : : {
590 : : throw uno::RuntimeException(
591 [ # # ][ # # ]: 0 : rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("not supported for Builtin properties") ), uno::Reference< uno::XInterface >() );
592 : : }
593 : :
594 : : // XEnumerationAccess
595 : : uno::Type SAL_CALL
596 : 0 : SwVbaBuiltinDocumentProperties::getElementType() throw (uno::RuntimeException)
597 : : {
598 : 0 : return XDocumentProperty::static_type(0);
599 : : }
600 : :
601 : : uno::Reference< container::XEnumeration > SAL_CALL
602 : 0 : SwVbaBuiltinDocumentProperties::createEnumeration() throw (uno::RuntimeException)
603 : : {
604 [ # # ]: 0 : uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
605 [ # # ][ # # ]: 0 : return xEnumAccess->createEnumeration();
606 : : }
607 : :
608 : : // ScVbaCollectionBaseImpl
609 : : uno::Any
610 : 0 : SwVbaBuiltinDocumentProperties::createCollectionObject( const uno::Any& aSource )
611 : : {
612 : : // pass through
613 : 0 : return aSource;
614 : : }
615 : :
616 : : // XHelperInterface
617 : : rtl::OUString
618 : 0 : SwVbaBuiltinDocumentProperties::getServiceImplName()
619 : : {
620 : 0 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwVbaBuiltinDocumentProperties"));
621 : : }
622 : :
623 : : uno::Sequence<rtl::OUString>
624 : 0 : SwVbaBuiltinDocumentProperties::getServiceNames()
625 : : {
626 [ # # ][ # # ]: 0 : static uno::Sequence< rtl::OUString > aServiceNames;
[ # # ][ # # ]
627 [ # # ]: 0 : if ( aServiceNames.getLength() == 0 )
628 : : {
629 : 0 : aServiceNames.realloc( 1 );
630 [ # # ]: 0 : aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.DocumentProperties" ) );
631 : : }
632 : 0 : return aServiceNames;
633 : : }
634 : :
635 [ # # ][ # # ]: 0 : class CustomPropertiesImpl : public PropertiesImpl_BASE
636 : : {
637 : : uno::Reference< XHelperInterface > m_xParent;
638 : : uno::Reference< uno::XComponentContext > m_xContext;
639 : : uno::Reference< frame::XModel > m_xModel;
640 : : uno::Reference< beans::XPropertySet > mxUserDefinedProp;
641 : : boost::shared_ptr< PropertGetSetHelper > mpPropGetSetHelper;
642 : : public:
643 [ # # ]: 0 : CustomPropertiesImpl( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ) : m_xParent( xParent ), m_xContext( xContext ), m_xModel( xModel )
644 : : {
645 : : // suck in the document( custom ) properties
646 [ # # ]: 0 : uno::Reference< document::XDocumentInfoSupplier > xDocInfoSupp( m_xModel, uno::UNO_QUERY_THROW );
647 [ # # ][ # # ]: 0 : uno::Reference< document::XDocumentPropertiesSupplier > xDocPropSupp( xDocInfoSupp->getDocumentInfo(), uno::UNO_QUERY_THROW );
[ # # ]
648 [ # # ][ # # ]: 0 : uno::Reference< document::XDocumentProperties > xDocProp( xDocPropSupp->getDocumentProperties(), uno::UNO_QUERY_THROW );
[ # # ]
649 [ # # ][ # # ]: 0 : mxUserDefinedProp.set( xDocProp->getUserDefinedProperties(), uno::UNO_QUERY_THROW );
[ # # ]
650 [ # # ][ # # ]: 0 : mpPropGetSetHelper.reset( new CustomPropertyGetSetHelper( m_xModel ) );
[ # # ]
651 : 0 : };
652 : : // XIndexAccess
653 : 0 : virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException)
654 : : {
655 [ # # ][ # # ]: 0 : return mxUserDefinedProp->getPropertySetInfo()->getProperties().getLength();
[ # # ]
656 : : }
657 : :
658 : 0 : virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException )
659 : : {
660 [ # # ][ # # ]: 0 : uno::Sequence< beans::Property > aProps = mxUserDefinedProp->getPropertySetInfo()->getProperties();
[ # # ][ # # ]
661 [ # # ]: 0 : if ( Index >= aProps.getLength() )
662 [ # # ]: 0 : throw lang::IndexOutOfBoundsException();
663 : : // How to determine type e.g Date? ( com.sun.star.util.DateTime )
664 [ # # ][ # # ]: 0 : DocPropInfo aPropInfo = DocPropInfo::createDocPropInfo( aProps[ Index ].Name, aProps[ Index ].Name, mpPropGetSetHelper );
[ # # ]
665 [ # # ][ # # ]: 0 : return uno::makeAny( uno::Reference< XDocumentProperty >( new SwVbaCustomDocumentProperty( m_xParent, m_xContext, aPropInfo ) ) );
[ # # ][ # # ]
[ # # ][ # # ]
666 : : }
667 : :
668 : 0 : virtual uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
669 : : {
670 [ # # ][ # # ]: 0 : if ( !hasByName( aName ) )
671 [ # # ]: 0 : throw container::NoSuchElementException();
672 : :
673 [ # # ]: 0 : DocPropInfo aPropInfo = DocPropInfo::createDocPropInfo( aName, aName, mpPropGetSetHelper );
674 [ # # ][ # # ]: 0 : return uno::makeAny( uno::Reference< XDocumentProperty >( new SwVbaCustomDocumentProperty( m_xParent, m_xContext, aPropInfo ) ) );
[ # # ][ # # ]
[ # # ]
675 : : }
676 : :
677 : 0 : virtual uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (uno::RuntimeException)
678 : : {
679 [ # # ][ # # ]: 0 : uno::Sequence< beans::Property > aProps = mxUserDefinedProp->getPropertySetInfo()->getProperties();
[ # # ][ # # ]
680 [ # # ]: 0 : uno::Sequence< rtl::OUString > aNames( aProps.getLength() );
681 [ # # ]: 0 : rtl::OUString* pString = aNames.getArray();
682 : 0 : rtl::OUString* pEnd = ( pString + aNames.getLength() );
683 [ # # ]: 0 : beans::Property* pProp = aProps.getArray();
684 [ # # ]: 0 : for ( ; pString != pEnd; ++pString, ++pProp )
685 : 0 : *pString = pProp->Name;
686 [ # # ]: 0 : return aNames;
687 : : }
688 : :
689 : 0 : virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (uno::RuntimeException)
690 : : {
691 : : OSL_TRACE("hasByName(%s) returns %d", rtl::OUStringToOString( aName, RTL_TEXTENCODING_UTF8 ).getStr(), mxUserDefinedProp->getPropertySetInfo()->hasPropertyByName( aName ) );
692 [ # # ][ # # ]: 0 : return mxUserDefinedProp->getPropertySetInfo()->hasPropertyByName( aName );
693 : : }
694 : :
695 : : // XElementAccess
696 : 0 : virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException)
697 : : {
698 : 0 : return XDocumentProperty::static_type(0);
699 : : }
700 : :
701 : 0 : virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException)
702 : : {
703 : 0 : return getCount() > 0;
704 : : }
705 : :
706 : 0 : virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) throw (uno::RuntimeException)
707 : : {
708 : : // create a map of properties ( the key doesn't matter )
709 : : OSL_TRACE("Creating an enumeration");
710 : 0 : sal_Int32 key = 0;
711 [ # # ]: 0 : sal_Int32 nElem = getCount();
712 [ # # ]: 0 : DocProps simpleDocPropSnapShot;
713 [ # # ]: 0 : for ( ; key < nElem; ++key )
714 [ # # ][ # # ]: 0 : simpleDocPropSnapShot[ key ].set( getByIndex( key ), uno::UNO_QUERY_THROW );
[ # # ]
715 : : OSL_TRACE("After creating the enumeration");
716 [ # # ][ # # ]: 0 : return new DocPropEnumeration( simpleDocPropSnapShot );
[ # # ][ # # ]
717 : : }
718 : :
719 : 0 : void addProp( const ::rtl::OUString& Name, ::sal_Int8 /*Type*/, const uno::Any& Value )
720 : : {
721 : 0 : sal_Int16 attributes = 128;
722 [ # # ]: 0 : uno::Reference< beans::XPropertyContainer > xContainer( mxUserDefinedProp, uno::UNO_QUERY_THROW );
723 : : // TODO fixme, perform the necessary Type Value conversions
724 [ # # ][ # # ]: 0 : xContainer->addProperty( Name, attributes, Value );
725 : 0 : }
726 : :
727 : : };
728 : :
729 : :
730 : 0 : SwVbaCustomDocumentProperties::SwVbaCustomDocumentProperties( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ) : SwVbaBuiltinDocumentProperties( xParent, xContext, xModel )
731 : : {
732 : : // replace the m_xIndexAccess implementation ( we need a virtual init )
733 [ # # ][ # # ]: 0 : m_xIndexAccess.set( new CustomPropertiesImpl( xParent, xContext, xModel ) );
[ # # ]
734 [ # # ]: 0 : m_xNameAccess.set( m_xIndexAccess, uno::UNO_QUERY_THROW );
735 : 0 : }
736 : :
737 : : uno::Reference< XDocumentProperty > SAL_CALL
738 : 0 : SwVbaCustomDocumentProperties::Add( const ::rtl::OUString& Name, ::sal_Bool LinkToContent, ::sal_Int8 Type, const uno::Any& Value, const uno::Any& LinkSource ) throw (script::BasicErrorException, uno::RuntimeException)
739 : : {
740 [ # # ]: 0 : CustomPropertiesImpl* pCustomProps = dynamic_cast< CustomPropertiesImpl* > ( m_xIndexAccess.get() );
741 : 0 : uno::Reference< XDocumentProperty > xDocProp;
742 [ # # ]: 0 : if ( pCustomProps )
743 : : {
744 : 0 : rtl::OUString sLinkSource;
745 [ # # ]: 0 : pCustomProps->addProp( Name, Type, Value );
746 : :
747 [ # # ][ # # ]: 0 : xDocProp.set( m_xNameAccess->getByName( Name ), uno::UNO_QUERY_THROW );
[ # # ]
748 [ # # ][ # # ]: 0 : xDocProp->setLinkToContent( LinkToContent );
749 : :
750 [ # # ]: 0 : if ( LinkSource >>= sLinkSource )
751 [ # # ][ # # ]: 0 : xDocProp->setLinkSource( sLinkSource );
752 : : }
753 : 0 : return xDocProp;
754 : : }
755 : :
756 : : // XHelperInterface
757 : : rtl::OUString
758 : 0 : SwVbaCustomDocumentProperties::getServiceImplName()
759 : : {
760 : 0 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwVbaCustomDocumentProperties"));
761 : : }
762 : :
763 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|