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