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