Update ooo320-m1
[ooovba.git] / binfilter / inc / bf_sw / unoatxt.hxx
blob98989191c9b30595fe5fd838fbf25f6a18ed650b
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: unoatxt.hxx,v $
10 * $Revision: 1.8 $
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 ************************************************************************/
30 #ifndef _UNOATXT_HXX
31 #define _UNOATXT_HXX
33 #ifndef _COM_SUN_STAR_TEXT_XAUTOTEXTCONTAINER_HPP_
34 #include <com/sun/star/text/XAutoTextContainer.hpp>
35 #endif
36 #ifndef _COM_SUN_STAR_LANG_XUNOTUNNEL_HPP_
37 #include <com/sun/star/lang/XUnoTunnel.hpp>
38 #endif
39 #ifndef _COM_SUN_STAR_CONTAINER_XNAMED_HPP_
40 #include <com/sun/star/container/XNamed.hpp>
41 #endif
42 #ifndef _COM_SUN_STAR_CONTAINER_XINDEXACCESS_HPP_
43 #include <com/sun/star/container/XIndexAccess.hpp>
44 #endif
45 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
46 #include <com/sun/star/beans/XPropertySet.hpp>
47 #endif
48 #ifndef _COM_SUN_STAR_DOCUMENT_XEVENTSSUPPLIER_HPP_
49 #include <com/sun/star/document/XEventsSupplier.hpp>
50 #endif
51 #ifndef _SFX_ITEMPROP_HXX
52 #include <bf_svtools/itemprop.hxx>
53 #endif
54 #ifndef _SFXLSTNER_HXX
55 #include <bf_svtools/lstner.hxx>
56 #endif
57 #ifndef _CPPUHELPER_IMPLBASE3_HXX_
58 #include <cppuhelper/implbase3.hxx> // helper for implementations
59 #endif
60 #ifndef _CPPUHELPER_IMPLBASE5_HXX_
61 #include <cppuhelper/implbase5.hxx> // helper for implementations
62 #endif
63 #ifndef _CPPUHELPER_IMPLBASE6_HXX_
64 #include <cppuhelper/implbase6.hxx> // helper for implementations
65 #endif
66 #ifndef _SVTOOLS_UNOEVENT_HXX_
67 #include <bf_svtools/unoevent.hxx>
68 #endif
69 namespace binfilter {//STRIP009
70 class SwGlossaries;
71 class SwDoc;
72 class SwDocShell;
73 class SwXBodyText;
74 } //namespace binfilter
76 #ifndef SW_DECL_SWDOCSHELL_DEFINED
77 #define SW_DECL_SWDOCSHELL_DEFINED
78 #ifndef _REF_HXX
79 #include <tools/ref.hxx>
80 #endif
81 namespace binfilter {
82 SV_DECL_REF( SwDocShell )
83 } //namespace binfilter
84 #endif
86 namespace binfilter {//STRIP009
87 /******************************************************************************
89 ******************************************************************************/
90 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
91 SAL_CALL SwXAutoTextContainer_createInstance(
92 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & ) throw ( ::com::sun::star::uno::Exception );
94 class SwXAutoTextContainer : public cppu::WeakImplHelper3
96 ::com::sun::star::text::XAutoTextContainer,
97 ::com::sun::star::lang::XServiceInfo,
98 ::com::sun::star::container::XIndexAccess
101 SwGlossaries *pGlossaries;
103 protected:
104 virtual ~SwXAutoTextContainer(); // ref-counted objects are not to be deleted from outside -> protected dtor
106 public:
107 SwXAutoTextContainer();
109 //XIndexAccess
110 virtual sal_Int32 SAL_CALL getCount( ) throw(::com::sun::star::uno::RuntimeException);
111 virtual ::com::sun::star::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) throw( ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException );
113 //XNameAccess
114 virtual ::com::sun::star::uno::Any SAL_CALL getByName(const ::rtl::OUString& Name) throw( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException );
115 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames(void) throw( ::com::sun::star::uno::RuntimeException );
116 virtual sal_Bool SAL_CALL hasByName(const ::rtl::OUString& Name) throw( ::com::sun::star::uno::RuntimeException );
118 //XElementAccess
119 virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw(::com::sun::star::uno::RuntimeException);
120 virtual sal_Bool SAL_CALL hasElements( ) throw(::com::sun::star::uno::RuntimeException);
122 //XAutoTextContainer
123 virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XAutoTextGroup > SAL_CALL insertNewByName(const ::rtl::OUString& aGroupName) throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException );
124 virtual void SAL_CALL removeByName(const ::rtl::OUString& aGroupName) throw( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException );
126 //XServiceInfo
127 virtual ::rtl::OUString SAL_CALL getImplementationName(void) throw( ::com::sun::star::uno::RuntimeException );
128 virtual BOOL SAL_CALL supportsService(const ::rtl::OUString& ServiceName) throw( ::com::sun::star::uno::RuntimeException );
129 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw( ::com::sun::star::uno::RuntimeException );
133 /* -----------------26.05.98 15:55-------------------
135 * --------------------------------------------------*/
136 class SwXAutoTextGroup : public cppu::WeakImplHelper6
138 ::com::sun::star::text::XAutoTextGroup,
139 ::com::sun::star::beans::XPropertySet,
140 ::com::sun::star::lang::XServiceInfo,
141 ::com::sun::star::container::XIndexAccess,
142 ::com::sun::star::container::XNamed,
143 ::com::sun::star::lang::XUnoTunnel
146 SfxItemPropertySet aPropSet;
147 SwGlossaries* pGlossaries;
148 ::rtl::OUString sName;
149 String m_sGroupName; // prefix m_ to disambiguate from some local vars in the implementation
151 protected:
152 virtual ~SwXAutoTextGroup(); // ref-counted objects are not to be deleted from outside -> protected dtor
154 public:
155 SwXAutoTextGroup(const ::rtl::OUString& rName, SwGlossaries* pGloss);
158 static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId();
160 //XUnoTunnel
161 virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException);
163 //XAutoTextGroup
164 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getTitles(void) throw( ::com::sun::star::uno::RuntimeException );
165 virtual void SAL_CALL renameByName(const ::rtl::OUString& aElementName, const ::rtl::OUString& aNewElementName, const ::rtl::OUString& aNewElementTitle) throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException );
166 virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XAutoTextEntry > SAL_CALL insertNewByName(const ::rtl::OUString& aName, const ::rtl::OUString& aTitle, const ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > & xTextRange) throw( ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException );
167 virtual void SAL_CALL removeByName(const ::rtl::OUString& aEntryName) throw( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException );
169 //XNamed
170 virtual ::rtl::OUString SAL_CALL getName(void) throw( ::com::sun::star::uno::RuntimeException );
171 virtual void SAL_CALL setName(const ::rtl::OUString& Name_) throw( ::com::sun::star::uno::RuntimeException );
173 //XIndexAccess
174 virtual sal_Int32 SAL_CALL getCount( ) throw(::com::sun::star::uno::RuntimeException);
175 virtual ::com::sun::star::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) throw( ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException );
177 //XNameAccess
178 virtual ::com::sun::star::uno::Any SAL_CALL getByName(const ::rtl::OUString& Name) throw( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException );
179 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames(void) throw( ::com::sun::star::uno::RuntimeException );
180 virtual sal_Bool SAL_CALL hasByName(const ::rtl::OUString& Name) throw( ::com::sun::star::uno::RuntimeException );
182 //XElementAccess
183 virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw(::com::sun::star::uno::RuntimeException);
184 virtual sal_Bool SAL_CALL hasElements( ) throw(::com::sun::star::uno::RuntimeException);
186 //XServiceInfo
187 virtual ::rtl::OUString SAL_CALL getImplementationName(void) throw( ::com::sun::star::uno::RuntimeException );
188 virtual BOOL SAL_CALL supportsService(const ::rtl::OUString& ServiceName) throw( ::com::sun::star::uno::RuntimeException );
189 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw( ::com::sun::star::uno::RuntimeException );
191 //XPropertySet
192 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException);
193 virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
194 virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
195 virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
196 virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
197 virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
198 virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
201 void Invalidate();
204 /* -----------------17.06.98 12:03-------------------
206 * --------------------------------------------------*/
207 class SwXAutoTextEntry
208 :public SfxListener
209 ,public cppu::WeakImplHelper5
211 ::com::sun::star::text::XAutoTextEntry,
212 ::com::sun::star::lang::XServiceInfo,
213 ::com::sun::star::lang::XUnoTunnel,
214 ::com::sun::star::text::XText,
215 ::com::sun::star::document::XEventsSupplier
218 SwGlossaries* pGlossaries;
219 String sGroupName;
220 String sEntryName;
221 SwDocShellRef xDocSh;
222 SwXBodyText* pBodyText;
223 ::com::sun::star::uno::Reference < ::com::sun::star::lang::XServiceInfo> xBodyText;
225 void EnsureBodyText ()
227 if ( !pBodyText )
228 GetBodyText();
230 void GetBodyText ();
232 protected:
233 /** ensure that the current content (which may only be in-memory so far) is flushed to the auto text group file
235 <p>If somebody modifies an auto text via this class, then this is not directly reflected to the respective
236 glossaries file (on disk), instead we hold a copy of this text (in [p|x]BodyText). On the other hand,
237 in applyTo, we do not work with this _copy_, but just tell the target for the application to insert
238 the content which we're responsible for - and this target doesn't know about our copy, but only
239 about the persistent version.</br>
240 So we need to ensure that before somebody else does something with our auto text, we flush our
241 (in-memory) copy to disk.</p>
244 void implFlushDocument( bool _bCloseDoc = false );
246 // SfxListener overridables
247 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
249 protected:
250 virtual ~SwXAutoTextEntry(); // ref-counted objects are not to be deleted from outside -> protected dtor
252 public:
253 SwXAutoTextEntry(SwGlossaries* , const String& rGroupName, const String& rEntryName);
255 static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId();
257 //XUnoTunnel
258 virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException);
260 //XText
261 virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextCursor > SAL_CALL createTextCursor(void) throw( ::com::sun::star::uno::RuntimeException );
262 virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextCursor > SAL_CALL createTextCursorByRange(const ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > & aTextPosition) throw( ::com::sun::star::uno::RuntimeException );
263 virtual void SAL_CALL insertString(const ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > & xRange, const ::rtl::OUString& aString, BOOL bAbsorb) throw( ::com::sun::star::uno::RuntimeException );
264 virtual void SAL_CALL insertControlCharacter(const ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > & xRange, sal_Int16 nControlCharacter, BOOL bAbsorb) throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );
265 virtual void SAL_CALL insertTextContent(const ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > & xRange, const ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextContent > & xContent, BOOL bAbsorb) throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );
266 virtual void SAL_CALL removeTextContent(const ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextContent > & xContent) throw( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException);
268 //XTextRange
269 virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XText > SAL_CALL getText(void) throw( ::com::sun::star::uno::RuntimeException );
270 virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > SAL_CALL getStart(void) throw( ::com::sun::star::uno::RuntimeException );
271 virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > SAL_CALL getEnd(void) throw( ::com::sun::star::uno::RuntimeException );
272 virtual ::rtl::OUString SAL_CALL getString(void) throw( ::com::sun::star::uno::RuntimeException );
273 virtual void SAL_CALL setString(const ::rtl::OUString& aString) throw( ::com::sun::star::uno::RuntimeException );
275 //XAutoTextEntry
276 virtual void SAL_CALL applyTo(const ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > & xRange)throw( ::com::sun::star::uno::RuntimeException );
278 //XServiceInfo
279 virtual ::rtl::OUString SAL_CALL getImplementationName(void) throw( ::com::sun::star::uno::RuntimeException );
280 virtual BOOL SAL_CALL supportsService(const ::rtl::OUString& ServiceName) throw( ::com::sun::star::uno::RuntimeException );
281 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw( ::com::sun::star::uno::RuntimeException );
283 // XEventsSupplier
284 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameReplace > SAL_CALL getEvents( ) throw( ::com::sun::star::uno::RuntimeException );
286 void Invalidate() {pGlossaries = 0;}
287 const SwGlossaries* GetGlossaries() { return pGlossaries; }
288 const String& GetGroupName() {return sGroupName;}
289 const String& GetEntryName() {return sEntryName;}
293 /** Implement the XNameAccess for the AutoText events */
294 class SwAutoTextEventDescriptor : public SvBaseEventDescriptor
296 ::rtl::OUString sSwAutoTextEventDescriptor;
298 SwXAutoTextEntry& rAutoTextEntry;
300 public:
301 SwAutoTextEventDescriptor( SwXAutoTextEntry& rAutoText );
303 ~SwAutoTextEventDescriptor();
305 virtual ::rtl::OUString SAL_CALL getImplementationName(void)
306 throw( ::com::sun::star::uno::RuntimeException );
308 protected:
310 virtual void replaceByName(
311 const USHORT nEvent, /// item ID of event
312 const SvxMacro& rMacro) /// event (will be copied)
313 throw(
314 ::com::sun::star::lang::IllegalArgumentException,
315 ::com::sun::star::container::NoSuchElementException,
316 ::com::sun::star::lang::WrappedTargetException,
317 ::com::sun::star::uno::RuntimeException);
319 virtual void getByName(
320 SvxMacro& rMacro, /// macro to be filled
321 const USHORT nEvent ) /// item ID of event
322 throw(
323 ::com::sun::star::container::NoSuchElementException,
324 ::com::sun::star::lang::WrappedTargetException,
325 ::com::sun::star::uno::RuntimeException);
329 } //namespace binfilter
330 #endif