/src/libreoffice/sw/source/uibase/inc/unoatxt.hxx
Line | Count | Source |
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/text/XAutoTextGroup.hpp> |
27 | | #include <com/sun/star/text/XAutoTextEntry.hpp> |
28 | | #include <com/sun/star/text/XAutoTextContainer2.hpp> |
29 | | #include <com/sun/star/text/XText.hpp> |
30 | | #include <svl/itemprop.hxx> |
31 | | #include <svl/lstner.hxx> |
32 | | #include <comphelper/compbase.hxx> |
33 | | #include <cppuhelper/implbase.hxx> |
34 | | #include <rtl/ref.hxx> |
35 | | #include <svtools/unoevent.hxx> |
36 | | |
37 | | class SwGlossaries; |
38 | | class SwDocShell; |
39 | | class SwXBodyText; |
40 | | |
41 | | #ifndef SW_DECL_SWDOCSHELL_DEFINED |
42 | | #define SW_DECL_SWDOCSHELL_DEFINED |
43 | | typedef rtl::Reference<SwDocShell> SwDocShellRef; |
44 | | #endif |
45 | | |
46 | | class SwXAutoTextContainer final : public cppu::WeakImplHelper |
47 | | < |
48 | | css::text::XAutoTextContainer2, |
49 | | css::lang::XServiceInfo |
50 | | > |
51 | | { |
52 | | SwGlossaries *m_pGlossaries; |
53 | | |
54 | | virtual ~SwXAutoTextContainer() override; // ref-counted objects are not to be deleted from outside -> protected dtor |
55 | | |
56 | | public: |
57 | | SwXAutoTextContainer(); |
58 | | |
59 | | //XIndexAccess |
60 | | virtual sal_Int32 SAL_CALL getCount( ) override; |
61 | | virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override; |
62 | | |
63 | | //XNameAccess |
64 | | virtual css::uno::Any SAL_CALL getByName(const OUString& Name) override; |
65 | | virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override; |
66 | | virtual sal_Bool SAL_CALL hasByName(const OUString& Name) override; |
67 | | |
68 | | //XElementAccess |
69 | | virtual css::uno::Type SAL_CALL getElementType( ) override; |
70 | | virtual sal_Bool SAL_CALL hasElements( ) override; |
71 | | |
72 | | //XAutoTextContainer |
73 | | virtual css::uno::Reference< css::text::XAutoTextGroup > SAL_CALL insertNewByName(const OUString& aGroupName) override; |
74 | | virtual void SAL_CALL removeByName(const OUString& aGroupName) override; |
75 | | |
76 | | //XServiceInfo |
77 | | virtual OUString SAL_CALL getImplementationName() override; |
78 | | virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; |
79 | | virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; |
80 | | |
81 | | }; |
82 | | |
83 | | class SwXAutoTextGroup final : public cppu::WeakImplHelper |
84 | | < |
85 | | css::text::XAutoTextGroup, |
86 | | css::beans::XPropertySet, |
87 | | css::lang::XServiceInfo, |
88 | | css::container::XIndexAccess, |
89 | | css::container::XNamed |
90 | | > |
91 | | { |
92 | | const SfxItemPropertySet* m_pPropSet; |
93 | | SwGlossaries* m_pGlossaries; |
94 | | OUString m_sName; |
95 | | OUString m_sGroupName; // prefix m_ to disambiguate from some local vars in the implementation |
96 | | |
97 | | virtual ~SwXAutoTextGroup() override; // ref-counted objects are not to be deleted from outside -> protected dtor |
98 | | |
99 | | public: |
100 | | SwXAutoTextGroup(const OUString& rName, SwGlossaries* pGloss); |
101 | | |
102 | | //XAutoTextGroup |
103 | | virtual css::uno::Sequence< OUString > SAL_CALL getTitles() override; |
104 | | virtual void SAL_CALL renameByName(const OUString& aElementName, const OUString& aNewElementName, const OUString& aNewElementTitle) override; |
105 | | 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; |
106 | | virtual void SAL_CALL removeByName(const OUString& aEntryName) override; |
107 | | |
108 | | //XNamed |
109 | | virtual OUString SAL_CALL getName() override; |
110 | | virtual void SAL_CALL setName(const OUString& Name_) override; |
111 | | |
112 | | //XIndexAccess |
113 | | virtual sal_Int32 SAL_CALL getCount( ) override; |
114 | | virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override; |
115 | | |
116 | | //XNameAccess |
117 | | virtual css::uno::Any SAL_CALL getByName(const OUString& Name) override; |
118 | | virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override; |
119 | | virtual sal_Bool SAL_CALL hasByName(const OUString& Name) override; |
120 | | |
121 | | //XElementAccess |
122 | | virtual css::uno::Type SAL_CALL getElementType( ) override; |
123 | | virtual sal_Bool SAL_CALL hasElements( ) override; |
124 | | |
125 | | //XServiceInfo |
126 | | virtual OUString SAL_CALL getImplementationName() override; |
127 | | virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; |
128 | | virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; |
129 | | |
130 | | //XPropertySet |
131 | | virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; |
132 | | virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override; |
133 | | virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override; |
134 | | virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override; |
135 | | virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override; |
136 | | virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override; |
137 | | virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override; |
138 | | |
139 | | void Invalidate(); |
140 | | }; |
141 | | |
142 | | class SwXAutoTextEntry final |
143 | | :public SfxListener |
144 | | ,public comphelper::WeakComponentImplHelper |
145 | | < |
146 | | css::text::XAutoTextEntry, |
147 | | css::lang::XServiceInfo, |
148 | | css::text::XText, |
149 | | css::document::XEventsSupplier |
150 | | > |
151 | | { |
152 | | SwGlossaries* m_pGlossaries; |
153 | | OUString m_sGroupName; |
154 | | OUString m_sEntryName; |
155 | | SwDocShellRef m_xDocSh; |
156 | | rtl::Reference<SwXBodyText> |
157 | | mxBodyText; |
158 | | |
159 | | void EnsureBodyText () |
160 | 0 | { |
161 | 0 | if ( !mxBodyText.is() ) |
162 | 0 | GetBodyText(); |
163 | 0 | } |
164 | | void GetBodyText (); |
165 | | |
166 | | void disposing(std::unique_lock<std::mutex>&) override; |
167 | | |
168 | | /** ensure that the current content (which may only be in-memory so far) is flushed to the auto text group file |
169 | | |
170 | | <p>If somebody modifies an auto text via this class, then this is not directly reflected to the respective |
171 | | glossaries file (on disk), instead we hold a copy of this text (in [p|x]BodyText). On the other hand, |
172 | | in applyTo, we do not work with this _copy_, but just tell the target for the application to insert |
173 | | the content which we're responsible for - and this target doesn't know about our copy, but only |
174 | | about the persistent version.</br> |
175 | | So we need to ensure that before somebody else does something with our auto text, we flush our |
176 | | (in-memory) copy to disk.</p> |
177 | | |
178 | | */ |
179 | | void implFlushDocument( bool _bCloseDoc = false ); |
180 | | |
181 | | // SfxListener overridables |
182 | | virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override; |
183 | | |
184 | | virtual ~SwXAutoTextEntry() override; // ref-counted objects are not to be deleted from outside -> protected dtor |
185 | | |
186 | | public: |
187 | | SwXAutoTextEntry(SwGlossaries* , OUString aGroupName, OUString aEntryName); |
188 | | |
189 | | //XText |
190 | | virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursor() override; |
191 | | virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursorByRange(const css::uno::Reference< css::text::XTextRange > & aTextPosition) override; |
192 | | virtual void SAL_CALL insertString(const css::uno::Reference< css::text::XTextRange > & xRange, const OUString& aString, sal_Bool bAbsorb) override; |
193 | | virtual void SAL_CALL insertControlCharacter(const css::uno::Reference< css::text::XTextRange > & xRange, sal_Int16 nControlCharacter, sal_Bool bAbsorb) override; |
194 | | 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; |
195 | | virtual void SAL_CALL removeTextContent(const css::uno::Reference< css::text::XTextContent > & xContent) override; |
196 | | |
197 | | //XTextRange |
198 | | virtual css::uno::Reference< css::text::XText > SAL_CALL getText() override; |
199 | | virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override; |
200 | | virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getEnd() override; |
201 | | virtual OUString SAL_CALL getString() override; |
202 | | virtual void SAL_CALL setString(const OUString& aString) override; |
203 | | |
204 | | //XAutoTextEntry |
205 | | virtual void SAL_CALL applyTo(const css::uno::Reference< css::text::XTextRange > & xRange) override; |
206 | | |
207 | | //XServiceInfo |
208 | | virtual OUString SAL_CALL getImplementationName() override; |
209 | | virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; |
210 | | virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; |
211 | | |
212 | | // XEventsSupplier |
213 | | virtual css::uno::Reference< css::container::XNameReplace > SAL_CALL getEvents( ) override; |
214 | | |
215 | 0 | void Invalidate() {m_pGlossaries = nullptr;} |
216 | 0 | const SwGlossaries* GetGlossaries() const { return m_pGlossaries; } |
217 | 0 | const OUString& GetGroupName() const {return m_sGroupName;} |
218 | 0 | const OUString& GetEntryName() const {return m_sEntryName;} |
219 | | }; |
220 | | |
221 | | /** Implement the XNameAccess for the AutoText events */ |
222 | | class SwAutoTextEventDescriptor final : public SvBaseEventDescriptor |
223 | | { |
224 | | SwXAutoTextEntry& m_rAutoTextEntry; |
225 | | |
226 | | using SvBaseEventDescriptor::replaceByName; |
227 | | using SvBaseEventDescriptor::getByName; |
228 | | |
229 | | public: |
230 | | SwAutoTextEventDescriptor( SwXAutoTextEntry& rAutoText ); |
231 | | |
232 | | virtual ~SwAutoTextEventDescriptor() override; |
233 | | |
234 | | virtual OUString SAL_CALL getImplementationName() override; |
235 | | |
236 | | private: |
237 | | |
238 | | virtual void replaceByName( |
239 | | const SvMacroItemId nEvent, /// item ID of event |
240 | | const SvxMacro& rMacro) /// event (will be copied) |
241 | | override; |
242 | | |
243 | | virtual void getByName( |
244 | | SvxMacro& rMacro, /// macro to be filled |
245 | | const SvMacroItemId nEvent ) /// item ID of event |
246 | | override; |
247 | | }; |
248 | | |
249 | | #endif |
250 | | |
251 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |