update dev300-m58
[ooovba.git] / extensions / inc / ucbhelper / ext_content.hxx
bloba5c7945547d2952a7edb52f6984cbbfc462af369
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: ext_content.hxx,v $
10 * $Revision: 1.4 $
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 ************************************************************************/
32 #ifndef _UCBHELPER_CONTENT_HXX_
33 #define _UCBHELPER_CONTENT_HXX_
35 #include <rtl/string.hxx>
36 #include <rtl/ustring>
37 #include <osl/mutex.hxx>
38 #include <osl/thread.h>
40 #include <cppuhelper/weak.hxx>
41 #include <com/sun/star/ucb/XCommandTaskProcessor.hpp>
42 #include <com/sun/star/ucb/XCommandInfo.hpp>
43 #include <com/sun/star/ucb/XContent.hpp>
44 #include <com/sun/star/ucb/XPropertyTaskProcessor.hpp>
45 #include <com/sun/star/ucb/XContentIdentifier.hpp>
46 #include <com/sun/star/beans/XPropertiesChangeListener.hpp>
47 #include <com/sun/star/lang/XComponent.hpp>
49 #include <list>
51 using namespace cppu;
52 using namespace com::sun::star::ucb;
53 using namespace com::sun::star::uno;
54 using namespace com::sun::star::beans;
55 using namespace com::sun::star::lang;
56 using namespace std;
57 using namespace rtl;
58 using namespace osl;
62 template <class Type> class safe_list : public osl::Mutex, public std::list< Type > {};
64 class OSimpleContentIdentifier : public OWeakObject,
65 public XContentIdentifier
67 private:
68 OUString Identifier;
69 OUString ProviderScheme;
71 public:
72 OSimpleContentIdentifier( const OUString& rIdentifier, const OUString& rProviderScheme );
74 // XInterface
75 virtual Any SAL_CALL queryInterface( const Type &type ) throw( RuntimeException );
76 virtual void SAL_CALL acquire() throw(RuntimeException);
77 virtual void SAL_CALL release() throw(RuntimeException);
79 // XContentIdentifier
80 virtual OUString SAL_CALL getContentIdentifier() throw(RuntimeException);
81 virtual OUString SAL_CALL getContentProviderScheme() throw(RuntimeException);
85 //---------------------------------------------------------------------------
87 // FileSystemContent
89 //---------------------------------------------------------------------------
91 class OContent :
92 public OWeakObject,
93 public XContent,
94 public XCommandTaskProcessor,
95 public XPropertyTaskProcessor,
96 public XCommandInfo,
97 public XPropertySetInfo,
98 public XComponent
100 public:
101 struct PropertyChangeEventInfo
103 OUString Name;
104 long Handle;
106 PropertyChangeEventInfo() : Handle( -1 ) {}
108 inline int operator ==( const PropertyChangeEventInfo& crInfo ) const
109 { return Handle == crInfo.Handle && Handle > 0 || Name == crInfo.Name; }
110 #ifdef __SUNPRO_CC
111 inline int operator <( const PropertyChangeEventInfo& crInfo ) const
112 { return Handle != crInfo.Handle ? Handle < crInfo.Handle : Name < crInfo.Name; }
113 #endif
116 struct PropertyChangeListenerInfo
118 Reference< XPropertiesChangeListener > xListener;
119 list< PropertyChangeEventInfo > aEventInfos;
121 inline int operator ==( const PropertyChangeListenerInfo& crInfo ) const
122 { return xListener == crInfo.xListener; }
123 #ifdef __SUNPRO_CC
124 inline int operator <( const PropertyChangeListenerInfo& crInfo ) const
125 { return xListener < crInfo.xListener; }
126 #endif
129 protected:
130 Sequence< PropertyChangeEvent > matchListenerEvents( const Sequence< PropertyChangeEvent >& crEvents, const PropertyChangeListenerInfo & crInfo );
132 safe_list< Reference< XContentEventListener > > m_aContentListeners;
133 safe_list< Reference< XEventListener > > m_aComponentListeners;
134 safe_list< PropertyChangeListenerInfo > m_aPropertyChangeListeners;
135 public:
136 virtual ~OContent() {}
138 virtual void broadcastContentEvent( const ContentEvent & crEvent );
139 virtual void broadcastPropertiesChangeEvents( const Sequence< PropertyChangeEvent >& crEvents );
141 // To be implemented by inheritents
142 virtual Any doCommand( const Command & crCommand ) = 0;
144 // XInterface
145 virtual Any SAL_CALL queryInterface( const Type &type ) throw( RuntimeException );
147 virtual void SAL_CALL acquire() throw(RuntimeException);
148 virtual void SAL_CALL release() throw(RuntimeException);
150 // XContent
151 virtual void SAL_CALL addContentEventListener( const Reference< XContentEventListener >& rListener ) throw();
152 virtual void SAL_CALL removeContentEventListener( const Reference< XContentEventListener >& rListener ) throw();
154 // XComponent
155 virtual void SAL_CALL dispose() throw();
156 virtual void SAL_CALL addEventListener( const Reference< XEventListener >& xListener ) throw();
157 virtual void SAL_CALL removeEventListener( const Reference< XEventListener >& xListener ) throw();
159 // XCommmandTaskProcessor
160 virtual Reference< XCommandInfo > SAL_CALL getCommandsInfo() throw();
162 // XCommandInfo
163 virtual CommandInfo SAL_CALL getCommandInfoByName( const OUString& rName ) throw( UnsupportedCommandException );
164 virtual CommandInfo SAL_CALL getCommandInfoByHandle( long nHandle ) throw( UnsupportedCommandException );
165 virtual sal_Bool SAL_CALL hasCommandByName( const OUString& rName ) throw();
166 virtual sal_Bool SAL_CALL hasCommandByHandle( long nHandle ) throw();
168 // XPropertyTaskProcessor
169 virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo() throw();
171 // XPropertySetInfo
172 virtual Property SAL_CALL getPropertyByName( const OUString& Name ) throw( UnknownPropertyException );
173 virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) throw();
174 virtual void SAL_CALL addPropertiesChangeListener( const Sequence< OUString >& Names, const Reference< XPropertiesChangeListener >& xListener ) throw();
175 virtual void SAL_CALL removePropertiesChangeListener( const Sequence< OUString >& Names, const Reference< XPropertiesChangeListener >& xListener ) throw();
178 //---------------------------------------------------------------------------
180 // FolderContent
182 //---------------------------------------------------------------------------
184 // supported Commands
185 static const sal_Int32 OPEN = 0;
186 static const sal_Int32 CLOSE = 1;
188 class OFolderContent : public OContent
190 protected:
191 // Already provided children
192 safe_list< XContent > m_aChildList;
194 // OContent
195 virtual Any doCommand( const Command & crCommand );
197 // new methods, can be overloaded
198 virtual Any doOpenCommand();
199 virtual Any doCloseCommand();
201 // To be implemented by inheritants
202 virtual Sequence< XContent > getAllChildren() = 0;
204 public:
206 // XCommmandTaskProcessor
207 virtual Reference< XCommandTask > SAL_CALL createCommandTask(const Command& rCommand, const Reference< XContentTaskEnvironment >& rEnvironment ) throw();
209 // XCommandInfo
210 virtual Sequence< CommandInfo > SAL_CALL getCommands() throw();
213 //---------------------------------------------------------------------------
215 // OContentTask
217 //---------------------------------------------------------------------------
219 class OContentTask :
220 public OWeakObject,
221 public XContentTask
223 Guard< OContent > m_aContentGuard;
224 protected:
225 OContent *m_pContent;
226 Reference< XContentTaskEnvironment > m_xEnvironment;
227 ContentTaskStatus m_eStatus;
228 oslThread m_aThread;
230 static void executeWorker( void * );
231 virtual ContentTaskStatus setStatus( ContentTaskStatus eStatus );
233 // To be implemented by inheritants
234 virtual void doExecute() = 0;
235 public:
236 OContentTask( const Reference< XContentTaskEnvironment >& xEnv, OContent *pContent );
237 virtual ~OContentTask();
239 // XInterface
240 virtual Any SAL_CALL queryInterface( const Type &type ) throw( RuntimeException );
242 virtual void SAL_CALL acquire() throw(RuntimeException);
243 virtual void SAL_CALL release() throw(RuntimeException);
245 // XContentTask
246 virtual void SAL_CALL start() throw();
247 virtual void SAL_CALL execute() throw( Exception );
248 virtual void SAL_CALL abort() throw();
249 virtual ContentTaskStatus SAL_CALL getStatus() throw();
250 virtual Reference< XContentTaskEnvironment > SAL_CALL getEnvironment() throw();
253 //---------------------------------------------------------------------------
255 // OCommandTask
257 //---------------------------------------------------------------------------
259 class OCommandTask :
260 public OContentTask,
261 public XCommandTask
263 protected:
264 Command m_aCommand;
265 Any m_aResult;
267 public:
268 OCommandTask( const Reference< XContentTaskEnvironment >& xEnv, OContent *pContent, const Command& rCommand );
269 virtual ~OCommandTask();
271 virtual void doExecute();
273 // XInterface
274 virtual Any SAL_CALL queryInterface( const Type &type ) throw( RuntimeException );
275 virtual void SAL_CALL acquire() throw(RuntimeException);
276 virtual void SAL_CALL release() throw(RuntimeException);
278 // XContentTask
279 virtual void SAL_CALL start() throw();
280 virtual void SAL_CALL execute() throw( Exception );
281 virtual void SAL_CALL abort() throw();
282 virtual ContentTaskStatus SAL_CALL getStatus() throw();
283 virtual Reference< XContentTaskEnvironment > SAL_CALL getEnvironment() throw();
285 // XCommandTask
286 virtual Command SAL_CALL getCommand() throw();
287 virtual Any SAL_CALL getResult() throw();
290 //---------------------------------------------------------------------------
292 // OPropertyTask
294 //---------------------------------------------------------------------------
296 class OPropertyTask :
297 public OContentTask,
298 public XPropertyTask
300 protected:
301 Sequence< PropertyValueInfo > m_aProperties;
302 PropertyTaskType m_eType;
303 public:
304 OPropertyTask(const Reference< XContentTaskEnvironment >& Environment, OContent *pContent, const Sequence< PropertyValue >& Properties, PropertyTaskType Type );
305 virtual ~OPropertyTask();
307 virtual void doExecute();
309 // To be implemented by inheritants
310 virtual Any setPropertyValue( PropertyValueInfo & rProperty ) = 0;
311 virtual void getPropertyValue( PropertyValueInfo & rProperty ) = 0;
313 // XInterface
314 virtual Any SAL_CALL queryInterface( const Type &type ) throw( RuntimeException );
315 virtual void SAL_CALL acquire() throw(RuntimeException);
316 virtual void SAL_CALL release() throw(RuntimeException);
318 // XContentTask
319 virtual void SAL_CALL start() throw();
320 virtual void SAL_CALL execute() throw( Exception );
321 virtual void SAL_CALL abort() throw();
322 virtual ContentTaskStatus SAL_CALL getStatus() throw();
323 virtual Reference< XContentTaskEnvironment > SAL_CALL getEnvironment() throw();
325 // XPropertyTask
326 PropertyTaskType SAL_CALL getType() throw();
327 Sequence< PropertyValueInfo > SAL_CALL getProperties() throw();
330 #endif // _UCBHELPER_CONTENT_HXX_