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