bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / inc / unoatxt.hxx
blobe04e3d3ec7892a435bcc2bf1e392e89d4df088c5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef _UNOATXT_HXX
20 #define _UNOATXT_HXX
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/container/XNamed.hpp>
24 #include <com/sun/star/document/XEventsSupplier.hpp>
25 #include <com/sun/star/lang/XServiceInfo.hpp>
26 #include <com/sun/star/lang/XUnoTunnel.hpp>
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <com/sun/star/text/XAutoTextGroup.hpp>
29 #include <com/sun/star/text/XAutoTextEntry.hpp>
30 #include <com/sun/star/text/XAutoTextContainer2.hpp>
31 #include <com/sun/star/text/XText.hpp>
32 #include <svl/itemprop.hxx>
33 #include <svl/lstner.hxx>
34 #include <cppuhelper/implbase2.hxx> // helper for implementations
35 #include <cppuhelper/implbase5.hxx> // helper for implementations
36 #include <cppuhelper/implbase6.hxx> // helper for implementations
37 #include <svtools/unoevent.hxx>
38 class SwTextBlocks;
39 class SwGlossaries;
40 class SwDoc;
41 class SwDocShell;
42 class SwXBodyText;
44 #ifndef SW_DECL_SWDOCSHELL_DEFINED
45 #define SW_DECL_SWDOCSHELL_DEFINED
46 #include <tools/ref.hxx>
47 SV_DECL_REF( SwDocShell )
48 #endif
50 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
51 SAL_CALL SwXAutoTextContainer_createInstance(
52 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & ) throw ( ::com::sun::star::uno::Exception );
54 class SwXAutoTextContainer : public cppu::WeakImplHelper2
56 ::com::sun::star::text::XAutoTextContainer2,
57 ::com::sun::star::lang::XServiceInfo
60 SwGlossaries *pGlossaries;
62 protected:
63 virtual ~SwXAutoTextContainer(); // ref-counted objects are not to be deleted from outside -> protected dtor
65 public:
66 SwXAutoTextContainer();
68 //XIndexAccess
69 virtual sal_Int32 SAL_CALL getCount( ) throw(::com::sun::star::uno::RuntimeException);
70 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 );
72 //XNameAccess
73 virtual ::com::sun::star::uno::Any SAL_CALL getByName(const OUString& Name) throw( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException );
74 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getElementNames(void) throw( ::com::sun::star::uno::RuntimeException );
75 virtual sal_Bool SAL_CALL hasByName(const OUString& Name) throw( ::com::sun::star::uno::RuntimeException );
77 //XElementAccess
78 virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw(::com::sun::star::uno::RuntimeException);
79 virtual sal_Bool SAL_CALL hasElements( ) throw(::com::sun::star::uno::RuntimeException);
81 //XAutoTextContainer
82 virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XAutoTextGroup > SAL_CALL insertNewByName(const OUString& aGroupName) throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException );
83 virtual void SAL_CALL removeByName(const OUString& aGroupName) throw( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException );
85 //XServiceInfo
86 virtual OUString SAL_CALL getImplementationName(void) throw( ::com::sun::star::uno::RuntimeException );
87 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw( ::com::sun::star::uno::RuntimeException );
88 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames(void) throw( ::com::sun::star::uno::RuntimeException );
92 class SwXAutoTextGroup : public cppu::WeakImplHelper6
94 ::com::sun::star::text::XAutoTextGroup,
95 ::com::sun::star::beans::XPropertySet,
96 ::com::sun::star::lang::XServiceInfo,
97 ::com::sun::star::container::XIndexAccess,
98 ::com::sun::star::container::XNamed,
99 ::com::sun::star::lang::XUnoTunnel
102 const SfxItemPropertySet* pPropSet;
103 SwGlossaries* pGlossaries;
104 OUString sName;
105 String m_sGroupName; // prefix m_ to disambiguate from some local vars in the implementation
107 protected:
108 virtual ~SwXAutoTextGroup(); // ref-counted objects are not to be deleted from outside -> protected dtor
110 public:
111 SwXAutoTextGroup(const OUString& rName, SwGlossaries* pGloss);
114 static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId();
116 //XUnoTunnel
117 virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException);
119 //XAutoTextGroup
120 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getTitles(void) throw( ::com::sun::star::uno::RuntimeException );
121 virtual void SAL_CALL renameByName(const OUString& aElementName, const OUString& aNewElementName, const OUString& aNewElementTitle) throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException );
122 virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XAutoTextEntry > SAL_CALL insertNewByName(const OUString& aName, const 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 );
123 virtual void SAL_CALL removeByName(const OUString& aEntryName) throw( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException );
125 //XNamed
126 virtual OUString SAL_CALL getName(void) throw( ::com::sun::star::uno::RuntimeException );
127 virtual void SAL_CALL setName(const OUString& Name_) throw( ::com::sun::star::uno::RuntimeException );
129 //XIndexAccess
130 virtual sal_Int32 SAL_CALL getCount( ) throw(::com::sun::star::uno::RuntimeException);
131 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 );
133 //XNameAccess
134 virtual ::com::sun::star::uno::Any SAL_CALL getByName(const OUString& Name) throw( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException );
135 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getElementNames(void) throw( ::com::sun::star::uno::RuntimeException );
136 virtual sal_Bool SAL_CALL hasByName(const OUString& Name) throw( ::com::sun::star::uno::RuntimeException );
138 //XElementAccess
139 virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw(::com::sun::star::uno::RuntimeException);
140 virtual sal_Bool SAL_CALL hasElements( ) throw(::com::sun::star::uno::RuntimeException);
142 //XServiceInfo
143 virtual OUString SAL_CALL getImplementationName(void) throw( ::com::sun::star::uno::RuntimeException );
144 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw( ::com::sun::star::uno::RuntimeException );
145 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames(void) throw( ::com::sun::star::uno::RuntimeException );
147 //XPropertySet
148 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException);
149 virtual void SAL_CALL setPropertyValue( const 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);
150 virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
151 virtual void SAL_CALL addPropertyChangeListener( const 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);
152 virtual void SAL_CALL removePropertyChangeListener( const 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);
153 virtual void SAL_CALL addVetoableChangeListener( const 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);
154 virtual void SAL_CALL removeVetoableChangeListener( const 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);
157 void Invalidate();
160 class SwXAutoTextEntry
161 :public SfxListener
162 ,public cppu::WeakImplHelper5
164 ::com::sun::star::text::XAutoTextEntry,
165 ::com::sun::star::lang::XServiceInfo,
166 ::com::sun::star::lang::XUnoTunnel,
167 ::com::sun::star::text::XText,
168 ::com::sun::star::document::XEventsSupplier
171 SwGlossaries* pGlossaries;
172 String sGroupName;
173 String sEntryName;
174 SwDocShellRef xDocSh;
175 SwXBodyText* pBodyText;
176 com::sun::star::uno::Reference < com::sun::star::lang::XServiceInfo> xBodyText;
178 void EnsureBodyText ()
180 if ( !pBodyText )
181 GetBodyText();
183 void GetBodyText ();
185 protected:
186 /** ensure that the current content (which may only be in-memory so far) is flushed to the auto text group file
188 <p>If somebody modifies an auto text via this class, then this is not directly reflected to the respective
189 glossaries file (on disk), instead we hold a copy of this text (in [p|x]BodyText). On the other hand,
190 in applyTo, we do not work with this _copy_, but just tell the target for the application to insert
191 the content which we're responsible for - and this target doesn't know about our copy, but only
192 about the persistent version.</br>
193 So we need to ensure that before somebody else does something with our auto text, we flush our
194 (in-memory) copy to disk.</p>
197 void implFlushDocument( bool _bCloseDoc = false );
199 // SfxListener overridables
200 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
202 protected:
203 virtual ~SwXAutoTextEntry(); // ref-counted objects are not to be deleted from outside -> protected dtor
205 public:
206 SwXAutoTextEntry(SwGlossaries* , const String& rGroupName, const String& rEntryName);
208 static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId();
210 //XUnoTunnel
211 virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException);
213 //XText
214 virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextCursor > SAL_CALL createTextCursor(void) throw( ::com::sun::star::uno::RuntimeException );
215 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 );
216 virtual void SAL_CALL insertString(const ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > & xRange, const OUString& aString, sal_Bool bAbsorb) throw( ::com::sun::star::uno::RuntimeException );
217 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 );
218 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 );
219 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);
221 //XTextRange
222 virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XText > SAL_CALL getText(void) throw( ::com::sun::star::uno::RuntimeException );
223 virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > SAL_CALL getStart(void) throw( ::com::sun::star::uno::RuntimeException );
224 virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > SAL_CALL getEnd(void) throw( ::com::sun::star::uno::RuntimeException );
225 virtual OUString SAL_CALL getString(void) throw( ::com::sun::star::uno::RuntimeException );
226 virtual void SAL_CALL setString(const OUString& aString) throw( ::com::sun::star::uno::RuntimeException );
228 //XAutoTextEntry
229 virtual void SAL_CALL applyTo(const ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > & xRange)throw( ::com::sun::star::uno::RuntimeException );
231 //XServiceInfo
232 virtual OUString SAL_CALL getImplementationName(void) throw( ::com::sun::star::uno::RuntimeException );
233 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw( ::com::sun::star::uno::RuntimeException );
234 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames(void) throw( ::com::sun::star::uno::RuntimeException );
236 // XEventsSupplier
237 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameReplace > SAL_CALL getEvents( ) throw( ::com::sun::star::uno::RuntimeException );
239 void Invalidate() {pGlossaries = 0;}
240 const SwGlossaries* GetGlossaries() { return pGlossaries; }
241 const String& GetGroupName() {return sGroupName;}
242 const String& GetEntryName() {return sEntryName;}
246 /** Implement the XNameAccess for the AutoText events */
247 class SwAutoTextEventDescriptor : public SvBaseEventDescriptor
249 OUString sSwAutoTextEventDescriptor;
251 SwXAutoTextEntry& rAutoTextEntry;
253 using SvBaseEventDescriptor::replaceByName;
254 using SvBaseEventDescriptor::getByName;
256 public:
257 SwAutoTextEventDescriptor( SwXAutoTextEntry& rAutoText );
259 ~SwAutoTextEventDescriptor();
261 virtual OUString SAL_CALL getImplementationName(void)
262 throw( ::com::sun::star::uno::RuntimeException );
264 protected:
266 virtual void replaceByName(
267 const sal_uInt16 nEvent, /// item ID of event
268 const SvxMacro& rMacro) /// event (will be copied)
269 throw(
270 ::com::sun::star::lang::IllegalArgumentException,
271 ::com::sun::star::container::NoSuchElementException,
272 ::com::sun::star::lang::WrappedTargetException,
273 ::com::sun::star::uno::RuntimeException);
275 virtual void getByName(
276 SvxMacro& rMacro, /// macro to be filled
277 const sal_uInt16 nEvent ) /// item ID of event
278 throw(
279 ::com::sun::star::container::NoSuchElementException,
280 ::com::sun::star::lang::WrappedTargetException,
281 ::com::sun::star::uno::RuntimeException);
285 #endif
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */