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