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