Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #ifndef _UNOATXT_HXX
29 : : #define _UNOATXT_HXX
30 : :
31 : : #include <com/sun/star/text/XAutoTextGroup.hpp>
32 : : #include <com/sun/star/text/XAutoTextEntry.hpp>
33 : : #include <com/sun/star/text/XAutoTextContainer.hpp>
34 : : #include <com/sun/star/text/XText.hpp>
35 : : #include <com/sun/star/lang/XServiceInfo.hpp>
36 : : #include <com/sun/star/lang/XUnoTunnel.hpp>
37 : : #include <com/sun/star/container/XNamed.hpp>
38 : : #include <com/sun/star/container/XIndexAccess.hpp>
39 : : #include <com/sun/star/beans/XPropertySet.hpp>
40 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41 : : #include <com/sun/star/document/XEventsSupplier.hpp>
42 : : #include <svl/itemprop.hxx>
43 : : #include <svl/lstner.hxx>
44 : : #include <cppuhelper/implbase3.hxx> // helper for implementations
45 : : #include <cppuhelper/implbase4.hxx> // helper for implementations
46 : : #include <cppuhelper/implbase5.hxx> // helper for implementations
47 : : #include <cppuhelper/implbase6.hxx> // helper for implementations
48 : : #include <svtools/unoevent.hxx>
49 : : class SwTextBlocks;
50 : : class SwGlossaries;
51 : : class SwDoc;
52 : : class SwDocShell;
53 : : class SwXBodyText;
54 : :
55 : : #ifndef SW_DECL_SWDOCSHELL_DEFINED
56 : : #define SW_DECL_SWDOCSHELL_DEFINED
57 : : #include <tools/ref.hxx>
58 : : SV_DECL_REF( SwDocShell )
59 : : #endif
60 : :
61 : : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
62 : : SAL_CALL SwXAutoTextContainer_createInstance(
63 : : const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & ) throw ( ::com::sun::star::uno::Exception );
64 : :
65 : : class SwXAutoTextContainer : public cppu::WeakImplHelper3
66 : : <
67 : : ::com::sun::star::text::XAutoTextContainer,
68 : : ::com::sun::star::lang::XServiceInfo,
69 : : ::com::sun::star::container::XIndexAccess
70 : : >
71 : : {
72 : : SwGlossaries *pGlossaries;
73 : :
74 : : protected:
75 : : virtual ~SwXAutoTextContainer(); // ref-counted objects are not to be deleted from outside -> protected dtor
76 : :
77 : : public:
78 : : SwXAutoTextContainer();
79 : :
80 : : //XIndexAccess
81 : : virtual sal_Int32 SAL_CALL getCount( ) throw(::com::sun::star::uno::RuntimeException);
82 : : 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 );
83 : :
84 : : //XNameAccess
85 : : 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 );
86 : : virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getElementNames(void) throw( ::com::sun::star::uno::RuntimeException );
87 : : virtual sal_Bool SAL_CALL hasByName(const rtl::OUString& Name) throw( ::com::sun::star::uno::RuntimeException );
88 : :
89 : : //XElementAccess
90 : : virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw(::com::sun::star::uno::RuntimeException);
91 : : virtual sal_Bool SAL_CALL hasElements( ) throw(::com::sun::star::uno::RuntimeException);
92 : :
93 : : //XAutoTextContainer
94 : : 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 );
95 : : virtual void SAL_CALL removeByName(const rtl::OUString& aGroupName) throw( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException );
96 : :
97 : : //XServiceInfo
98 : : virtual rtl::OUString SAL_CALL getImplementationName(void) throw( ::com::sun::star::uno::RuntimeException );
99 : : virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) throw( ::com::sun::star::uno::RuntimeException );
100 : : virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw( ::com::sun::star::uno::RuntimeException );
101 : :
102 : : };
103 : :
104 : : class SwXAutoTextGroup : public cppu::WeakImplHelper6
105 : : <
106 : : ::com::sun::star::text::XAutoTextGroup,
107 : : ::com::sun::star::beans::XPropertySet,
108 : : ::com::sun::star::lang::XServiceInfo,
109 : : ::com::sun::star::container::XIndexAccess,
110 : : ::com::sun::star::container::XNamed,
111 : : ::com::sun::star::lang::XUnoTunnel
112 : : >
113 : : {
114 : : const SfxItemPropertySet* pPropSet;
115 : : SwGlossaries* pGlossaries;
116 : : rtl::OUString sName;
117 : : String m_sGroupName; // prefix m_ to disambiguate from some local vars in the implementation
118 : :
119 : : protected:
120 : : virtual ~SwXAutoTextGroup(); // ref-counted objects are not to be deleted from outside -> protected dtor
121 : :
122 : : public:
123 : : SwXAutoTextGroup(const rtl::OUString& rName, SwGlossaries* pGloss);
124 : :
125 : :
126 : : static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId();
127 : :
128 : : //XUnoTunnel
129 : : virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException);
130 : :
131 : : //XAutoTextGroup
132 : : virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getTitles(void) throw( ::com::sun::star::uno::RuntimeException );
133 : : 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 );
134 : : 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 );
135 : : virtual void SAL_CALL removeByName(const rtl::OUString& aEntryName) throw( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException );
136 : :
137 : : //XNamed
138 : : virtual rtl::OUString SAL_CALL getName(void) throw( ::com::sun::star::uno::RuntimeException );
139 : : virtual void SAL_CALL setName(const rtl::OUString& Name_) throw( ::com::sun::star::uno::RuntimeException );
140 : :
141 : : //XIndexAccess
142 : : virtual sal_Int32 SAL_CALL getCount( ) throw(::com::sun::star::uno::RuntimeException);
143 : : 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 );
144 : :
145 : : //XNameAccess
146 : : 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 );
147 : : virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getElementNames(void) throw( ::com::sun::star::uno::RuntimeException );
148 : : virtual sal_Bool SAL_CALL hasByName(const rtl::OUString& Name) throw( ::com::sun::star::uno::RuntimeException );
149 : :
150 : : //XElementAccess
151 : : virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw(::com::sun::star::uno::RuntimeException);
152 : : virtual sal_Bool SAL_CALL hasElements( ) throw(::com::sun::star::uno::RuntimeException);
153 : :
154 : : //XServiceInfo
155 : : virtual rtl::OUString SAL_CALL getImplementationName(void) throw( ::com::sun::star::uno::RuntimeException );
156 : : virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) throw( ::com::sun::star::uno::RuntimeException );
157 : : virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw( ::com::sun::star::uno::RuntimeException );
158 : :
159 : : //XPropertySet
160 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException);
161 : : 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);
162 : : 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);
163 : : 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);
164 : : 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);
165 : : 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);
166 : : 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);
167 : :
168 : : //
169 : : void Invalidate();
170 : : };
171 : :
172 : : class SwXAutoTextEntry
173 : : :public SfxListener
174 : : ,public cppu::WeakImplHelper5
175 : : <
176 : : ::com::sun::star::text::XAutoTextEntry,
177 : : ::com::sun::star::lang::XServiceInfo,
178 : : ::com::sun::star::lang::XUnoTunnel,
179 : : ::com::sun::star::text::XText,
180 : : ::com::sun::star::document::XEventsSupplier
181 : : >
182 : : {
183 : : SwGlossaries* pGlossaries;
184 : : String sGroupName;
185 : : String sEntryName;
186 : : SwDocShellRef xDocSh;
187 : : SwXBodyText* pBodyText;
188 : : com::sun::star::uno::Reference < com::sun::star::lang::XServiceInfo> xBodyText;
189 : :
190 : 48 : void EnsureBodyText ()
191 : : {
192 [ + + ]: 48 : if ( !pBodyText )
193 : 2 : GetBodyText();
194 : 48 : }
195 : : void GetBodyText ();
196 : :
197 : : protected:
198 : : /** ensure that the current content (which may only be in-memory so far) is flushed to the auto text group file
199 : :
200 : : <p>If somebody modifies an auto text via this class, then this is not directly reflected to the respective
201 : : glossaries file (on disk), instead we hold a copy of this text (in [p|x]BodyText). On the other hand,
202 : : in applyTo, we do not work with this _copy_, but just tell the target for the application to insert
203 : : the content which we're responsible for - and this target doesn't know about our copy, but only
204 : : about the persistent version.</br>
205 : : So we need to ensure that before somebody else does something with our auto text, we flush our
206 : : (in-memory) copy to disk.</p>
207 : :
208 : : */
209 : : void implFlushDocument( bool _bCloseDoc = false );
210 : :
211 : : // SfxListener overridables
212 : : virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
213 : :
214 : : protected:
215 : : virtual ~SwXAutoTextEntry(); // ref-counted objects are not to be deleted from outside -> protected dtor
216 : :
217 : : public:
218 : : SwXAutoTextEntry(SwGlossaries* , const String& rGroupName, const String& rEntryName);
219 : :
220 : : static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId();
221 : :
222 : : //XUnoTunnel
223 : : virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException);
224 : :
225 : : //XText
226 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextCursor > SAL_CALL createTextCursor(void) throw( ::com::sun::star::uno::RuntimeException );
227 : : 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 );
228 : : 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 );
229 : : 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 );
230 : : 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 );
231 : : 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);
232 : :
233 : : //XTextRange
234 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XText > SAL_CALL getText(void) throw( ::com::sun::star::uno::RuntimeException );
235 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > SAL_CALL getStart(void) throw( ::com::sun::star::uno::RuntimeException );
236 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > SAL_CALL getEnd(void) throw( ::com::sun::star::uno::RuntimeException );
237 : : virtual rtl::OUString SAL_CALL getString(void) throw( ::com::sun::star::uno::RuntimeException );
238 : : virtual void SAL_CALL setString(const rtl::OUString& aString) throw( ::com::sun::star::uno::RuntimeException );
239 : :
240 : : //XAutoTextEntry
241 : : virtual void SAL_CALL applyTo(const ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > & xRange)throw( ::com::sun::star::uno::RuntimeException );
242 : :
243 : : //XServiceInfo
244 : : virtual rtl::OUString SAL_CALL getImplementationName(void) throw( ::com::sun::star::uno::RuntimeException );
245 : : virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) throw( ::com::sun::star::uno::RuntimeException );
246 : : virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw( ::com::sun::star::uno::RuntimeException );
247 : :
248 : : // XEventsSupplier
249 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameReplace > SAL_CALL getEvents( ) throw( ::com::sun::star::uno::RuntimeException );
250 : :
251 : 6 : void Invalidate() {pGlossaries = 0;}
252 : 0 : const SwGlossaries* GetGlossaries() { return pGlossaries; }
253 : 24 : const String& GetGroupName() {return sGroupName;}
254 : 8 : const String& GetEntryName() {return sEntryName;}
255 : : };
256 : :
257 : :
258 : : /** Implement the XNameAccess for the AutoText events */
259 : : class SwAutoTextEventDescriptor : public SvBaseEventDescriptor
260 : : {
261 : : ::rtl::OUString sSwAutoTextEventDescriptor;
262 : :
263 : : SwXAutoTextEntry& rAutoTextEntry;
264 : :
265 : : using SvBaseEventDescriptor::replaceByName;
266 : : using SvBaseEventDescriptor::getByName;
267 : :
268 : : public:
269 : : SwAutoTextEventDescriptor( SwXAutoTextEntry& rAutoText );
270 : :
271 : : ~SwAutoTextEventDescriptor();
272 : :
273 : : virtual rtl::OUString SAL_CALL getImplementationName(void)
274 : : throw( ::com::sun::star::uno::RuntimeException );
275 : :
276 : : protected:
277 : :
278 : : virtual void replaceByName(
279 : : const sal_uInt16 nEvent, /// item ID of event
280 : : const SvxMacro& rMacro) /// event (will be copied)
281 : : throw(
282 : : ::com::sun::star::lang::IllegalArgumentException,
283 : : ::com::sun::star::container::NoSuchElementException,
284 : : ::com::sun::star::lang::WrappedTargetException,
285 : : ::com::sun::star::uno::RuntimeException);
286 : :
287 : : virtual void getByName(
288 : : SvxMacro& rMacro, /// macro to be filled
289 : : const sal_uInt16 nEvent ) /// item ID of event
290 : : throw(
291 : : ::com::sun::star::container::NoSuchElementException,
292 : : ::com::sun::star::lang::WrappedTargetException,
293 : : ::com::sun::star::uno::RuntimeException);
294 : : };
295 : :
296 : :
297 : : #endif
298 : :
299 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|