LibreOffice Module sw (master)  1
unoatxt.hxx
Go to the documentation of this file.
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/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 <comphelper/compbase.hxx>
34 #include <cppuhelper/implbase.hxx>
35 #include <rtl/ref.hxx>
36 #include <svtools/unoevent.hxx>
37 
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>
48 #endif
49 
50 class SwXAutoTextContainer final : public cppu::WeakImplHelper
51 <
52  css::text::XAutoTextContainer2,
53  css::lang::XServiceInfo
54 >
55 {
57 
58  virtual ~SwXAutoTextContainer() override; // ref-counted objects are not to be deleted from outside -> protected dtor
59 
60 public:
62 
63  //XIndexAccess
64  virtual sal_Int32 SAL_CALL getCount( ) override;
65  virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override;
66 
67  //XNameAccess
68  virtual css::uno::Any SAL_CALL getByName(const OUString& Name) override;
69  virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override;
70  virtual sal_Bool SAL_CALL hasByName(const OUString& Name) override;
71 
72  //XElementAccess
73  virtual css::uno::Type SAL_CALL getElementType( ) override;
74  virtual sal_Bool SAL_CALL hasElements( ) override;
75 
76  //XAutoTextContainer
77  virtual css::uno::Reference< css::text::XAutoTextGroup > SAL_CALL insertNewByName(const OUString& aGroupName) override;
78  virtual void SAL_CALL removeByName(const OUString& aGroupName) override;
79 
80  //XServiceInfo
81  virtual OUString SAL_CALL getImplementationName() override;
82  virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
83  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
84 
85 };
86 
87 class SwXAutoTextGroup final : public cppu::WeakImplHelper
88 <
89  css::text::XAutoTextGroup,
90  css::beans::XPropertySet,
91  css::lang::XServiceInfo,
92  css::container::XIndexAccess,
93  css::container::XNamed,
94  css::lang::XUnoTunnel
95 >
96 {
99  OUString m_sName;
100  OUString m_sGroupName; // prefix m_ to disambiguate from some local vars in the implementation
101 
102  virtual ~SwXAutoTextGroup() override; // ref-counted objects are not to be deleted from outside -> protected dtor
103 
104 public:
105  SwXAutoTextGroup(const OUString& rName, SwGlossaries* pGloss);
106 
107  static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId();
108 
109  //XUnoTunnel
110  virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override;
111 
112  //XAutoTextGroup
113  virtual css::uno::Sequence< OUString > SAL_CALL getTitles() override;
114  virtual void SAL_CALL renameByName(const OUString& aElementName, const OUString& aNewElementName, const OUString& aNewElementTitle) override;
115  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;
116  virtual void SAL_CALL removeByName(const OUString& aEntryName) override;
117 
118  //XNamed
119  virtual OUString SAL_CALL getName() override;
120  virtual void SAL_CALL setName(const OUString& Name_) override;
121 
122  //XIndexAccess
123  virtual sal_Int32 SAL_CALL getCount( ) override;
124  virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override;
125 
126  //XNameAccess
127  virtual css::uno::Any SAL_CALL getByName(const OUString& Name) override;
128  virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override;
129  virtual sal_Bool SAL_CALL hasByName(const OUString& Name) override;
130 
131  //XElementAccess
132  virtual css::uno::Type SAL_CALL getElementType( ) override;
133  virtual sal_Bool SAL_CALL hasElements( ) override;
134 
135  //XServiceInfo
136  virtual OUString SAL_CALL getImplementationName() override;
137  virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
138  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
139 
140  //XPropertySet
141  virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
142  virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override;
143  virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
144  virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
145  virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
146  virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
147  virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
148 
149  void Invalidate();
150 };
151 
152 class SwXAutoTextEntry final
153  :public SfxListener
155  <
156  css::text::XAutoTextEntry,
157  css::lang::XServiceInfo,
158  css::lang::XUnoTunnel,
159  css::text::XText,
160  css::document::XEventsSupplier
161  >
162 {
164  OUString m_sGroupName;
165  OUString m_sEntryName;
169 
171  {
172  if ( !mxBodyText.is() )
173  GetBodyText();
174  }
175  void GetBodyText ();
176 
177  void disposing(std::unique_lock<std::mutex>&) override;
178 
190  void implFlushDocument( bool _bCloseDoc = false );
191 
192  // SfxListener overridables
193  virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
194 
195  virtual ~SwXAutoTextEntry() override; // ref-counted objects are not to be deleted from outside -> protected dtor
196 
197 public:
198  SwXAutoTextEntry(SwGlossaries* , const OUString& rGroupName, const OUString& rEntryName);
199 
200  static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId();
201 
202  //XUnoTunnel
203  virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override;
204 
205  //XText
206  virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursor() override;
207  virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursorByRange(const css::uno::Reference< css::text::XTextRange > & aTextPosition) override;
208  virtual void SAL_CALL insertString(const css::uno::Reference< css::text::XTextRange > & xRange, const OUString& aString, sal_Bool bAbsorb) override;
209  virtual void SAL_CALL insertControlCharacter(const css::uno::Reference< css::text::XTextRange > & xRange, sal_Int16 nControlCharacter, sal_Bool bAbsorb) override;
210  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;
211  virtual void SAL_CALL removeTextContent(const css::uno::Reference< css::text::XTextContent > & xContent) override;
212 
213  //XTextRange
214  virtual css::uno::Reference< css::text::XText > SAL_CALL getText() override;
215  virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override;
216  virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getEnd() override;
217  virtual OUString SAL_CALL getString() override;
218  virtual void SAL_CALL setString(const OUString& aString) override;
219 
220  //XAutoTextEntry
221  virtual void SAL_CALL applyTo(const css::uno::Reference< css::text::XTextRange > & xRange) override;
222 
223  //XServiceInfo
224  virtual OUString SAL_CALL getImplementationName() override;
225  virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
226  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
227 
228  // XEventsSupplier
229  virtual css::uno::Reference< css::container::XNameReplace > SAL_CALL getEvents( ) override;
230 
231  void Invalidate() {m_pGlossaries = nullptr;}
232  const SwGlossaries* GetGlossaries() const { return m_pGlossaries; }
233  const OUString& GetGroupName() const {return m_sGroupName;}
234  const OUString& GetEntryName() const {return m_sEntryName;}
235 };
236 
239 {
241 
244 
245 public:
247 
248  virtual ~SwAutoTextEventDescriptor() override;
249 
250  virtual OUString SAL_CALL getImplementationName() override;
251 
252 private:
253 
254  virtual void replaceByName(
255  const SvMacroItemId nEvent,
256  const SvxMacro& rMacro)
257  override;
258 
259  virtual void getByName(
260  SvxMacro& rMacro,
261  const SvMacroItemId nEvent )
262  override;
263 };
264 
265 #endif
266 
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL setName(const OUString &Name_) override
Definition: unoatxt.cxx:429
SwXAutoTextEntry & m_rAutoTextEntry
Definition: unoatxt.hxx:240
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
Definition: unoatxt.cxx:658
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: unoatxt.cxx:556
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
Definition: unoatxt.cxx:615
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: unoatxt.cxx:703
virtual css::uno::Type SAL_CALL getElementType() override
Definition: unoatxt.cxx:494
OUString m_sGroupName
Definition: unoatxt.hxx:100
virtual css::uno::Any SAL_CALL getByName(const OUString &Name) override
Definition: unoatxt.cxx:99
virtual sal_Bool SAL_CALL hasElements() override
Definition: unoatxt.cxx:93
SwDocShellRef m_xDocSh
Definition: unoatxt.hxx:166
virtual sal_Bool SAL_CALL hasByName(const OUString &Name) override
Definition: unoatxt.cxx:132
void disposing(std::unique_lock< std::mutex > &) override
Definition: unoatxt.cxx:746
virtual css::uno::Reference< css::text::XText > SAL_CALL getText() override
Definition: unoatxt.cxx:799
Definition: doc.hxx:187
SwGlossaries * m_pGlossaries
Definition: unoatxt.hxx:98
SvMacroItemId
const OUString & GetEntryName() const
Definition: unoatxt.hxx:234
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override
Definition: unoatxt.cxx:480
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: unoatxt.cxx:904
virtual css::uno::Any SAL_CALL getByName(const OUString &rName) override
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
Definition: unoatxt.cxx:519
virtual css::uno::Type SAL_CALL getElementType() override
Definition: unoatxt.cxx:87
void EnsureBodyText()
Definition: unoatxt.hxx:170
virtual OUString SAL_CALL getString() override
Definition: unoatxt.cxx:820
virtual void SAL_CALL insertString(const css::uno::Reference< css::text::XTextRange > &xRange, const OUString &aString, sal_Bool bAbsorb) override
Definition: unoatxt.cxx:767
virtual css::uno::Sequence< OUString > SAL_CALL getTitles() override
Definition: unoatxt.cxx:233
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override
Definition: unoatxt.cxx:78
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
Definition: unoatxt.cxx:591
virtual css::uno::Reference< css::container::XNameReplace > SAL_CALL getEvents() override
Definition: unoatxt.cxx:910
virtual void SAL_CALL applyTo(const css::uno::Reference< css::text::XTextRange > &xRange) override
Definition: unoatxt.cxx:834
virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursor() override
Definition: unoatxt.cxx:752
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &aIdentifier) override
Definition: unoatxt.cxx:664
SwXAutoTextGroup(const OUString &rName, SwGlossaries *pGloss)
Definition: unoatxt.cxx:218
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
Definition: unoatxt.cxx:114
virtual sal_Int32 SAL_CALL getCount() override
Definition: unoatxt.cxx:71
virtual void SAL_CALL removeByName(const OUString &aEntryName) override
Definition: unoatxt.cxx:409
virtual OUString SAL_CALL getImplementationName() override
Definition: unoatxt.cxx:642
OUString m_sEntryName
Definition: unoatxt.hxx:165
OUString m_sGroupName
Definition: unoatxt.hxx:164
virtual void SAL_CALL removeTextContent(const css::uno::Reference< css::text::XTextContent > &xContent) override
Definition: unoatxt.cxx:791
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override
Definition: unoatxt.cxx:806
SwXAutoTextEntry(SwGlossaries *, const OUString &rGroupName, const OUString &rEntryName)
Definition: unoatxt.cxx:669
virtual void SAL_CALL replaceByName(const OUString &rName, const css::uno::Any &rElement) override
virtual sal_Bool SAL_CALL hasElements() override
Definition: unoatxt.cxx:500
virtual sal_Int32 SAL_CALL getCount() override
Definition: unoatxt.cxx:471
virtual OUString SAL_CALL getImplementationName() override
Definition: unoatxt.cxx:933
const OUString & GetGroupName() const
Definition: unoatxt.hxx:233
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
Definition: unoatxt.cxx:630
unsigned char sal_Bool
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: unoatxt.cxx:899
tools::SvRef< SwDocShell > SwDocShellRef
Definition: unoatxt.hxx:47
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: unoatxt.cxx:647
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: unoatxt.cxx:652
void implFlushDocument(bool _bCloseDoc=false)
ensure that the current content (which may only be in-memory so far) is flushed to the auto text grou...
Definition: unoatxt.cxx:685
const SfxItemPropertySet * m_pPropSet
Definition: unoatxt.hxx:97
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
Definition: unoatxt.cxx:620
virtual void replaceByName(const SvMacroItemId nEvent, const SvxMacro &rMacro) override
event (will be copied)
Definition: unoatxt.cxx:938
virtual ~SwXAutoTextContainer() override
Definition: unoatxt.cxx:66
OUString m_sName
Definition: unoatxt.hxx:99
virtual ~SwXAutoTextGroup() override
Definition: unoatxt.cxx:229
virtual OUString SAL_CALL getName() override
Definition: unoatxt.cxx:423
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getEnd() override
Definition: unoatxt.cxx:813
virtual sal_Bool SAL_CALL hasByName(const OUString &Name) override
Definition: unoatxt.cxx:535
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
Definition: unoatxt.cxx:625
void Invalidate()
Definition: unoatxt.hxx:231
Implement the XNameAccess for the AutoText events.
Definition: unoatxt.hxx:238
virtual void SAL_CALL removeByName(const OUString &aGroupName) override
Definition: unoatxt.cxx:182
virtual void SAL_CALL setString(const OUString &aString) override
Definition: unoatxt.cxx:827
virtual ~SwXAutoTextEntry() override
Definition: unoatxt.cxx:677
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
Definition: unoatxt.cxx:562
virtual css::uno::Any SAL_CALL getByName(const OUString &Name) override
Definition: unoatxt.cxx:510
rtl::Reference< SwXBodyText > mxBodyText
Definition: unoatxt.hxx:168
virtual css::uno::Reference< css::text::XAutoTextGroup > SAL_CALL insertNewByName(const OUString &aGroupName) override
Definition: unoatxt.cxx:141
SwGlossaries * m_pGlossaries
Definition: unoatxt.hxx:163
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: unoatxt.cxx:202
virtual void getByName(SvxMacro &rMacro, const SvMacroItemId nEvent) override
item ID of event
Definition: unoatxt.cxx:971
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
Definition: unoatxt.cxx:315
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: unoatxt.cxx:197
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
Definition: unoatxt.cxx:782
virtual void SAL_CALL renameByName(const OUString &aElementName, const OUString &aNewElementName, const OUString &aNewElementTitle) override
Definition: unoatxt.cxx:249
virtual OUString SAL_CALL getImplementationName() override
Definition: unoatxt.cxx:192
void Invalidate()
Definition: unoatxt.cxx:635
virtual ~SwAutoTextEventDescriptor() override
Definition: unoatxt.cxx:929
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &aIdentifier) override
Definition: unoatxt.cxx:213
virtual void SAL_CALL insertControlCharacter(const css::uno::Reference< css::text::XTextRange > &xRange, sal_Int16 nControlCharacter, sal_Bool bAbsorb) override
Definition: unoatxt.cxx:774
SwAutoTextEventDescriptor(SwXAutoTextEntry &rAutoText)
Definition: unoatxt.cxx:922
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
Definition: unoatxt.cxx:207
virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursorByRange(const css::uno::Reference< css::text::XTextRange > &aTextPosition) override
Definition: unoatxt.cxx:759
SwGlossaries * m_pGlossaries
Definition: unoatxt.hxx:56
void GetBodyText()
Definition: unoatxt.cxx:733
const SwGlossaries * GetGlossaries() const
Definition: unoatxt.hxx:232
virtual OUString SAL_CALL getImplementationName() override
Definition: unoatxt.cxx:894