merge the formfield patch from ooo-build
[ooovba.git] / sw / inc / unoatxt.hxx
blob281abb76dbf0df4a13f60f81c937f22133db6ecd
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.12 $
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 #include <com/sun/star/text/XAutoTextGroup.hpp>
34 #include <com/sun/star/text/XAutoTextEntry.hpp>
35 #include <com/sun/star/text/XAutoTextContainer.hpp>
36 #include <com/sun/star/text/XText.hpp>
37 #include <com/sun/star/lang/XServiceInfo.hpp>
38 #include <com/sun/star/lang/XUnoTunnel.hpp>
39 #include <com/sun/star/container/XNamed.hpp>
40 #include <com/sun/star/container/XIndexAccess.hpp>
41 #include <com/sun/star/beans/XPropertySet.hpp>
42 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
43 #include <com/sun/star/document/XEventsSupplier.hpp>
44 #include <svtools/itemprop.hxx>
45 #include <svtools/lstner.hxx>
46 #include <cppuhelper/implbase3.hxx> // helper for implementations
47 #include <cppuhelper/implbase4.hxx> // helper for implementations
48 #include <cppuhelper/implbase5.hxx> // helper for implementations
49 #include <cppuhelper/implbase6.hxx> // helper for implementations
50 #include <svtools/unoevent.hxx>
51 class SwTextBlocks;
52 class SwGlossaries;
53 class SwDoc;
54 class SwDocShell;
55 class SwXBodyText;
57 #ifndef SW_DECL_SWDOCSHELL_DEFINED
58 #define SW_DECL_SWDOCSHELL_DEFINED
59 #include <tools/ref.hxx>
60 SV_DECL_REF( SwDocShell )
61 #endif
64 /******************************************************************************
66 ******************************************************************************/
67 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
68 SAL_CALL SwXAutoTextContainer_createInstance(
69 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & ) throw ( ::com::sun::star::uno::Exception );
71 class SwXAutoTextContainer : public cppu::WeakImplHelper3
73 ::com::sun::star::text::XAutoTextContainer,
74 ::com::sun::star::lang::XServiceInfo,
75 ::com::sun::star::container::XIndexAccess
78 SwGlossaries *pGlossaries;
80 protected:
81 virtual ~SwXAutoTextContainer(); // ref-counted objects are not to be deleted from outside -> protected dtor
83 public:
84 SwXAutoTextContainer();
86 //XIndexAccess
87 virtual sal_Int32 SAL_CALL getCount( ) throw(::com::sun::star::uno::RuntimeException);
88 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 );
90 //XNameAccess
91 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 );
92 virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getElementNames(void) throw( ::com::sun::star::uno::RuntimeException );
93 virtual sal_Bool SAL_CALL hasByName(const rtl::OUString& Name) throw( ::com::sun::star::uno::RuntimeException );
95 //XElementAccess
96 virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw(::com::sun::star::uno::RuntimeException);
97 virtual sal_Bool SAL_CALL hasElements( ) throw(::com::sun::star::uno::RuntimeException);
99 //XAutoTextContainer
100 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 );
101 virtual void SAL_CALL removeByName(const rtl::OUString& aGroupName) throw( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException );
103 //XServiceInfo
104 virtual rtl::OUString SAL_CALL getImplementationName(void) throw( ::com::sun::star::uno::RuntimeException );
105 virtual BOOL SAL_CALL supportsService(const rtl::OUString& ServiceName) throw( ::com::sun::star::uno::RuntimeException );
106 virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw( ::com::sun::star::uno::RuntimeException );
110 /* -----------------26.05.98 15:55-------------------
112 * --------------------------------------------------*/
113 class SwXAutoTextGroup : public cppu::WeakImplHelper6
115 ::com::sun::star::text::XAutoTextGroup,
116 ::com::sun::star::beans::XPropertySet,
117 ::com::sun::star::lang::XServiceInfo,
118 ::com::sun::star::container::XIndexAccess,
119 ::com::sun::star::container::XNamed,
120 ::com::sun::star::lang::XUnoTunnel
123 const SfxItemPropertySet* pPropSet;
124 SwGlossaries* pGlossaries;
125 rtl::OUString sName;
126 String m_sGroupName; // prefix m_ to disambiguate from some local vars in the implementation
128 protected:
129 virtual ~SwXAutoTextGroup(); // ref-counted objects are not to be deleted from outside -> protected dtor
131 public:
132 SwXAutoTextGroup(const rtl::OUString& rName, SwGlossaries* pGloss/*SwTextBlocks* pGroup*/);
135 static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId();
137 //XUnoTunnel
138 virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException);
140 //XAutoTextGroup
141 virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getTitles(void) throw( ::com::sun::star::uno::RuntimeException );
142 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 );
143 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 );
144 virtual void SAL_CALL removeByName(const rtl::OUString& aEntryName) throw( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException );
146 //XNamed
147 virtual rtl::OUString SAL_CALL getName(void) throw( ::com::sun::star::uno::RuntimeException );
148 virtual void SAL_CALL setName(const rtl::OUString& Name_) throw( ::com::sun::star::uno::RuntimeException );
150 //XIndexAccess
151 virtual sal_Int32 SAL_CALL getCount( ) throw(::com::sun::star::uno::RuntimeException);
152 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 );
154 //XNameAccess
155 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 );
156 virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getElementNames(void) throw( ::com::sun::star::uno::RuntimeException );
157 virtual sal_Bool SAL_CALL hasByName(const rtl::OUString& Name) throw( ::com::sun::star::uno::RuntimeException );
159 //XElementAccess
160 virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw(::com::sun::star::uno::RuntimeException);
161 virtual sal_Bool SAL_CALL hasElements( ) throw(::com::sun::star::uno::RuntimeException);
163 //XServiceInfo
164 virtual rtl::OUString SAL_CALL getImplementationName(void) throw( ::com::sun::star::uno::RuntimeException );
165 virtual BOOL SAL_CALL supportsService(const rtl::OUString& ServiceName) throw( ::com::sun::star::uno::RuntimeException );
166 virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw( ::com::sun::star::uno::RuntimeException );
168 //XPropertySet
169 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException);
170 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);
171 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);
172 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);
173 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);
174 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);
175 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);
178 void Invalidate();
181 /* -----------------17.06.98 12:03-------------------
183 * --------------------------------------------------*/
184 class SwXAutoTextEntry
185 :public SfxListener
186 ,public cppu::WeakImplHelper5
188 ::com::sun::star::text::XAutoTextEntry,
189 ::com::sun::star::lang::XServiceInfo,
190 ::com::sun::star::lang::XUnoTunnel,
191 ::com::sun::star::text::XText,
192 ::com::sun::star::document::XEventsSupplier
195 SwGlossaries* pGlossaries;
196 String sGroupName;
197 String sEntryName;
198 SwDocShellRef xDocSh;
199 SwXBodyText* pBodyText;
200 com::sun::star::uno::Reference < com::sun::star::lang::XServiceInfo> xBodyText;
202 void EnsureBodyText ()
204 if ( !pBodyText )
205 GetBodyText();
207 void GetBodyText ();
209 protected:
210 /** ensure that the current content (which may only be in-memory so far) is flushed to the auto text group file
212 <p>If somebody modifies an auto text via this class, then this is not directly reflected to the respective
213 glossaries file (on disk), instead we hold a copy of this text (in [p|x]BodyText). On the other hand,
214 in applyTo, we do not work with this _copy_, but just tell the target for the application to insert
215 the content which we're responsible for - and this target doesn't know about our copy, but only
216 about the persistent version.</br>
217 So we need to ensure that before somebody else does something with our auto text, we flush our
218 (in-memory) copy to disk.</p>
221 void implFlushDocument( bool _bCloseDoc = false );
223 // SfxListener overridables
224 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
226 protected:
227 virtual ~SwXAutoTextEntry(); // ref-counted objects are not to be deleted from outside -> protected dtor
229 public:
230 SwXAutoTextEntry(SwGlossaries* , const String& rGroupName, const String& rEntryName);
232 static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId();
234 //XUnoTunnel
235 virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException);
237 //XText
238 virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextCursor > SAL_CALL createTextCursor(void) throw( ::com::sun::star::uno::RuntimeException );
239 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 );
240 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 );
241 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 );
242 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 );
243 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);
245 //XTextRange
246 virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XText > SAL_CALL getText(void) throw( ::com::sun::star::uno::RuntimeException );
247 virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > SAL_CALL getStart(void) throw( ::com::sun::star::uno::RuntimeException );
248 virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > SAL_CALL getEnd(void) throw( ::com::sun::star::uno::RuntimeException );
249 virtual rtl::OUString SAL_CALL getString(void) throw( ::com::sun::star::uno::RuntimeException );
250 virtual void SAL_CALL setString(const rtl::OUString& aString) throw( ::com::sun::star::uno::RuntimeException );
252 //XAutoTextEntry
253 virtual void SAL_CALL applyTo(const ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > & xRange)throw( ::com::sun::star::uno::RuntimeException );
255 //XServiceInfo
256 virtual rtl::OUString SAL_CALL getImplementationName(void) throw( ::com::sun::star::uno::RuntimeException );
257 virtual BOOL SAL_CALL supportsService(const rtl::OUString& ServiceName) throw( ::com::sun::star::uno::RuntimeException );
258 virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw( ::com::sun::star::uno::RuntimeException );
260 // XEventsSupplier
261 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameReplace > SAL_CALL getEvents( ) throw( ::com::sun::star::uno::RuntimeException );
263 void Invalidate() {pGlossaries = 0;}
264 const SwGlossaries* GetGlossaries() { return pGlossaries; }
265 const String& GetGroupName() {return sGroupName;}
266 const String& GetEntryName() {return sEntryName;}
270 /** Implement the XNameAccess for the AutoText events */
271 class SwAutoTextEventDescriptor : public SvBaseEventDescriptor
273 ::rtl::OUString sSwAutoTextEventDescriptor;
275 SwXAutoTextEntry& rAutoTextEntry;
277 using SvBaseEventDescriptor::replaceByName;
278 using SvBaseEventDescriptor::getByName;
280 public:
281 SwAutoTextEventDescriptor( SwXAutoTextEntry& rAutoText );
283 ~SwAutoTextEventDescriptor();
285 virtual rtl::OUString SAL_CALL getImplementationName(void)
286 throw( ::com::sun::star::uno::RuntimeException );
288 protected:
290 virtual void replaceByName(
291 const USHORT nEvent, /// item ID of event
292 const SvxMacro& rMacro) /// event (will be copied)
293 throw(
294 ::com::sun::star::lang::IllegalArgumentException,
295 ::com::sun::star::container::NoSuchElementException,
296 ::com::sun::star::lang::WrappedTargetException,
297 ::com::sun::star::uno::RuntimeException);
299 virtual void getByName(
300 SvxMacro& rMacro, /// macro to be filled
301 const USHORT nEvent ) /// item ID of event
302 throw(
303 ::com::sun::star::container::NoSuchElementException,
304 ::com::sun::star::lang::WrappedTargetException,
305 ::com::sun::star::uno::RuntimeException);
309 #endif