nss: upgrade to release 3.73
[LibreOffice.git] / sw / source / uibase / inc / unoatxt.hxx
blobdba379b2c43ee3dcd5bd26d7ed512be727e07981
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 INCLUDED_SW_SOURCE_UIBASE_INC_UNOATXT_HXX
20 #define INCLUDED_SW_SOURCE_UIBASE_INC_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/text/XAutoTextGroup.hpp>
28 #include <com/sun/star/text/XAutoTextEntry.hpp>
29 #include <com/sun/star/text/XAutoTextContainer2.hpp>
30 #include <com/sun/star/text/XText.hpp>
31 #include <svl/itemprop.hxx>
32 #include <svl/lstner.hxx>
33 #include <cppuhelper/basemutex.hxx>
34 #include <cppuhelper/compbase.hxx>
35 #include <cppuhelper/implbase.hxx>
36 #include <rtl/ref.hxx>
37 #include <svtools/unoevent.hxx>
39 class SwTextBlocks;
40 class SwGlossaries;
41 class SwDoc;
42 class SwDocShell;
43 class SwXBodyText;
45 #ifndef SW_DECL_SWDOCSHELL_DEFINED
46 #define SW_DECL_SWDOCSHELL_DEFINED
47 #include <tools/ref.hxx>
48 typedef tools::SvRef<SwDocShell> SwDocShellRef;
49 #endif
51 class SwXAutoTextContainer : public cppu::WeakImplHelper
53 css::text::XAutoTextContainer2,
54 css::lang::XServiceInfo
57 SwGlossaries *pGlossaries;
59 protected:
60 virtual ~SwXAutoTextContainer() override; // ref-counted objects are not to be deleted from outside -> protected dtor
62 public:
63 SwXAutoTextContainer();
65 //XIndexAccess
66 virtual sal_Int32 SAL_CALL getCount( ) override;
67 virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override;
69 //XNameAccess
70 virtual css::uno::Any SAL_CALL getByName(const OUString& Name) override;
71 virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override;
72 virtual sal_Bool SAL_CALL hasByName(const OUString& Name) override;
74 //XElementAccess
75 virtual css::uno::Type SAL_CALL getElementType( ) override;
76 virtual sal_Bool SAL_CALL hasElements( ) override;
78 //XAutoTextContainer
79 virtual css::uno::Reference< css::text::XAutoTextGroup > SAL_CALL insertNewByName(const OUString& aGroupName) override;
80 virtual void SAL_CALL removeByName(const OUString& aGroupName) override;
82 //XServiceInfo
83 virtual OUString SAL_CALL getImplementationName() override;
84 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
85 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
89 class SwXAutoTextGroup : public cppu::WeakImplHelper
91 css::text::XAutoTextGroup,
92 css::beans::XPropertySet,
93 css::lang::XServiceInfo,
94 css::container::XIndexAccess,
95 css::container::XNamed,
96 css::lang::XUnoTunnel
99 const SfxItemPropertySet* pPropSet;
100 SwGlossaries* pGlossaries;
101 OUString sName;
102 OUString m_sGroupName; // prefix m_ to disambiguate from some local vars in the implementation
104 protected:
105 virtual ~SwXAutoTextGroup() override; // ref-counted objects are not to be deleted from outside -> protected dtor
107 public:
108 SwXAutoTextGroup(const OUString& rName, SwGlossaries* pGloss);
110 static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId();
112 //XUnoTunnel
113 virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override;
115 //XAutoTextGroup
116 virtual css::uno::Sequence< OUString > SAL_CALL getTitles() override;
117 virtual void SAL_CALL renameByName(const OUString& aElementName, const OUString& aNewElementName, const OUString& aNewElementTitle) override;
118 virtual css::uno::Reference< css::text::XAutoTextEntry > SAL_CALL insertNewByName(const OUString& aName, const OUString& aTitle, const css::uno::Reference< css::text::XTextRange > & xTextRange) override;
119 virtual void SAL_CALL removeByName(const OUString& aEntryName) override;
121 //XNamed
122 virtual OUString SAL_CALL getName() override;
123 virtual void SAL_CALL setName(const OUString& Name_) override;
125 //XIndexAccess
126 virtual sal_Int32 SAL_CALL getCount( ) override;
127 virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override;
129 //XNameAccess
130 virtual css::uno::Any SAL_CALL getByName(const OUString& Name) override;
131 virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override;
132 virtual sal_Bool SAL_CALL hasByName(const OUString& Name) override;
134 //XElementAccess
135 virtual css::uno::Type SAL_CALL getElementType( ) override;
136 virtual sal_Bool SAL_CALL hasElements( ) override;
138 //XServiceInfo
139 virtual OUString SAL_CALL getImplementationName() override;
140 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
141 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
143 //XPropertySet
144 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
145 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override;
146 virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
147 virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
148 virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
149 virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
150 virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
152 void Invalidate();
155 class SwXAutoTextEntry final
156 :public SfxListener
157 ,public cppu::BaseMutex
158 ,public cppu::WeakComponentImplHelper
160 css::text::XAutoTextEntry,
161 css::lang::XServiceInfo,
162 css::lang::XUnoTunnel,
163 css::text::XText,
164 css::document::XEventsSupplier
167 SwGlossaries* pGlossaries;
168 OUString sGroupName;
169 OUString sEntryName;
170 SwDocShellRef xDocSh;
171 rtl::Reference<SwXBodyText>
172 mxBodyText;
174 void EnsureBodyText ()
176 if ( !mxBodyText.is() )
177 GetBodyText();
179 void GetBodyText ();
181 void SAL_CALL disposing() override;
183 /** ensure that the current content (which may only be in-memory so far) is flushed to the auto text group file
185 <p>If somebody modifies an auto text via this class, then this is not directly reflected to the respective
186 glossaries file (on disk), instead we hold a copy of this text (in [p|x]BodyText). On the other hand,
187 in applyTo, we do not work with this _copy_, but just tell the target for the application to insert
188 the content which we're responsible for - and this target doesn't know about our copy, but only
189 about the persistent version.</br>
190 So we need to ensure that before somebody else does something with our auto text, we flush our
191 (in-memory) copy to disk.</p>
194 void implFlushDocument( bool _bCloseDoc = false );
196 // SfxListener overridables
197 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
199 virtual ~SwXAutoTextEntry() override; // ref-counted objects are not to be deleted from outside -> protected dtor
201 public:
202 SwXAutoTextEntry(SwGlossaries* , const OUString& rGroupName, const OUString& rEntryName);
204 static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId();
206 //XUnoTunnel
207 virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override;
209 //XText
210 virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursor() override;
211 virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursorByRange(const css::uno::Reference< css::text::XTextRange > & aTextPosition) override;
212 virtual void SAL_CALL insertString(const css::uno::Reference< css::text::XTextRange > & xRange, const OUString& aString, sal_Bool bAbsorb) override;
213 virtual void SAL_CALL insertControlCharacter(const css::uno::Reference< css::text::XTextRange > & xRange, sal_Int16 nControlCharacter, sal_Bool bAbsorb) override;
214 virtual void SAL_CALL insertTextContent(const css::uno::Reference< css::text::XTextRange > & xRange, const css::uno::Reference< css::text::XTextContent > & xContent, sal_Bool bAbsorb) override;
215 virtual void SAL_CALL removeTextContent(const css::uno::Reference< css::text::XTextContent > & xContent) override;
217 //XTextRange
218 virtual css::uno::Reference< css::text::XText > SAL_CALL getText() override;
219 virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override;
220 virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getEnd() override;
221 virtual OUString SAL_CALL getString() override;
222 virtual void SAL_CALL setString(const OUString& aString) override;
224 //XAutoTextEntry
225 virtual void SAL_CALL applyTo(const css::uno::Reference< css::text::XTextRange > & xRange) override;
227 //XServiceInfo
228 virtual OUString SAL_CALL getImplementationName() override;
229 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
230 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
232 // XEventsSupplier
233 virtual css::uno::Reference< css::container::XNameReplace > SAL_CALL getEvents( ) override;
235 void Invalidate() {pGlossaries = nullptr;}
236 const SwGlossaries* GetGlossaries() const { return pGlossaries; }
237 const OUString& GetGroupName() const {return sGroupName;}
238 const OUString& GetEntryName() const {return sEntryName;}
241 /** Implement the XNameAccess for the AutoText events */
242 class SwAutoTextEventDescriptor : public SvBaseEventDescriptor
244 SwXAutoTextEntry& rAutoTextEntry;
246 using SvBaseEventDescriptor::replaceByName;
247 using SvBaseEventDescriptor::getByName;
249 public:
250 SwAutoTextEventDescriptor( SwXAutoTextEntry& rAutoText );
252 virtual ~SwAutoTextEventDescriptor() override;
254 virtual OUString SAL_CALL getImplementationName() override;
256 protected:
258 virtual void replaceByName(
259 const SvMacroItemId nEvent, /// item ID of event
260 const SvxMacro& rMacro) /// event (will be copied)
261 override;
263 virtual void getByName(
264 SvxMacro& rMacro, /// macro to be filled
265 const SvMacroItemId nEvent ) /// item ID of event
266 override;
269 #endif
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */