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 <cppuhelper/basemutex.hxx>
34 #include <cppuhelper/compbase.hxx>
35 #include <cppuhelper/implbase.hxx>
36 #include <rtl/ref.hxx>
37 #include <svtools/unoevent.hxx>
38 
39 class SwTextBlocks;
40 class SwGlossaries;
41 class SwDoc;
42 class SwDocShell;
43 class SwXBodyText;
44 
45 #ifndef SW_DECL_SWDOCSHELL_DEFINED
46 #define SW_DECL_SWDOCSHELL_DEFINED
47 #include <tools/ref.hxx>
49 #endif
50 
51 class SwXAutoTextContainer : public cppu::WeakImplHelper
52 <
53  css::text::XAutoTextContainer2,
54  css::lang::XServiceInfo
55 >
56 {
58 
59 protected:
60  virtual ~SwXAutoTextContainer() override; // ref-counted objects are not to be deleted from outside -> protected dtor
61 
62 public:
64 
65  //XIndexAccess
66  virtual sal_Int32 SAL_CALL getCount( ) override;
67  virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override;
68 
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;
73 
74  //XElementAccess
75  virtual css::uno::Type SAL_CALL getElementType( ) override;
76  virtual sal_Bool SAL_CALL hasElements( ) override;
77 
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;
81 
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;
86 
87 };
88 
89 class SwXAutoTextGroup : public cppu::WeakImplHelper
90 <
91  css::text::XAutoTextGroup,
92  css::beans::XPropertySet,
93  css::lang::XServiceInfo,
94  css::container::XIndexAccess,
95  css::container::XNamed,
96  css::lang::XUnoTunnel
97 >
98 {
101  OUString sName;
102  OUString m_sGroupName; // prefix m_ to disambiguate from some local vars in the implementation
103 
104 protected:
105  virtual ~SwXAutoTextGroup() override; // ref-counted objects are not to be deleted from outside -> protected dtor
106 
107 public:
108  SwXAutoTextGroup(const OUString& rName, SwGlossaries* pGloss);
109 
110  static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId();
111 
112  //XUnoTunnel
113  virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override;
114 
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;
120 
121  //XNamed
122  virtual OUString SAL_CALL getName() override;
123  virtual void SAL_CALL setName(const OUString& Name_) override;
124 
125  //XIndexAccess
126  virtual sal_Int32 SAL_CALL getCount( ) override;
127  virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override;
128 
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;
133 
134  //XElementAccess
135  virtual css::uno::Type SAL_CALL getElementType( ) override;
136  virtual sal_Bool SAL_CALL hasElements( ) override;
137 
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;
142 
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;
151 
152  void Invalidate();
153 };
154 
155 class SwXAutoTextEntry final
156  :public SfxListener
157  ,public cppu::BaseMutex
158  ,public cppu::WeakComponentImplHelper
159  <
160  css::text::XAutoTextEntry,
161  css::lang::XServiceInfo,
162  css::lang::XUnoTunnel,
163  css::text::XText,
164  css::document::XEventsSupplier
165  >
166 {
168  OUString const sGroupName;
169  OUString const sEntryName;
173 
175  {
176  if ( !mxBodyText.is() )
177  GetBodyText();
178  }
179  void GetBodyText ();
180 
181  void SAL_CALL disposing() override;
182 
194  void implFlushDocument( bool _bCloseDoc = false );
195 
196  // SfxListener overridables
197  virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
198 
199  virtual ~SwXAutoTextEntry() override; // ref-counted objects are not to be deleted from outside -> protected dtor
200 
201 public:
202  SwXAutoTextEntry(SwGlossaries* , const OUString& rGroupName, const OUString& rEntryName);
203 
204  static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId();
205 
206  //XUnoTunnel
207  virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override;
208 
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;
216 
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;
223 
224  //XAutoTextEntry
225  virtual void SAL_CALL applyTo(const css::uno::Reference< css::text::XTextRange > & xRange) override;
226 
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;
231 
232  // XEventsSupplier
233  virtual css::uno::Reference< css::container::XNameReplace > SAL_CALL getEvents( ) override;
234 
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;}
239 };
240 
243 {
245 
248 
249 public:
251 
252  virtual ~SwAutoTextEventDescriptor() override;
253 
254  virtual OUString SAL_CALL getImplementationName() override;
255 
256 protected:
257 
258  virtual void replaceByName(
259  const SvMacroItemId nEvent,
260  const SvxMacro& rMacro)
261  override;
262 
263  virtual void getByName(
264  SvxMacro& rMacro,
265  const SvMacroItemId nEvent )
266  override;
267 };
268 
269 #endif
270 
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL setName(const OUString &Name_) override
Definition: unoatxt.cxx:451
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
Definition: unoatxt.cxx:683
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: unoatxt.cxx:576
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
Definition: unoatxt.cxx:635
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: unoatxt.cxx:732
virtual css::uno::Type SAL_CALL getElementType() override
Definition: unoatxt.cxx:514
OUString m_sGroupName
Definition: unoatxt.hxx:102
virtual css::uno::Any SAL_CALL getByName(const OUString &Name) override
Definition: unoatxt.cxx:105
virtual sal_Bool SAL_CALL hasElements() override
Definition: unoatxt.cxx:99
virtual sal_Bool SAL_CALL hasByName(const OUString &Name) override
Definition: unoatxt.cxx:138
virtual css::uno::Reference< css::text::XText > SAL_CALL getText() override
Definition: unoatxt.cxx:827
Definition: doc.hxx:185
SvMacroItemId
const OUString & GetEntryName() const
Definition: unoatxt.hxx:238
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override
Definition: unoatxt.cxx:502
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: unoatxt.cxx:944
virtual css::uno::Any SAL_CALL getByName(const OUString &rName) override
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
Definition: unoatxt.cxx:539
virtual css::uno::Type SAL_CALL getElementType() override
Definition: unoatxt.cxx:93
void EnsureBodyText()
Definition: unoatxt.hxx:174
void SAL_CALL disposing() override
Definition: unoatxt.cxx:774
virtual OUString SAL_CALL getString() override
Definition: unoatxt.cxx:848
virtual void SAL_CALL insertString(const css::uno::Reference< css::text::XTextRange > &xRange, const OUString &aString, sal_Bool bAbsorb) override
Definition: unoatxt.cxx:795
virtual css::uno::Sequence< OUString > SAL_CALL getTitles() override
Definition: unoatxt.cxx:247
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override
Definition: unoatxt.cxx:84
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
Definition: unoatxt.cxx:611
virtual css::uno::Reference< css::container::XNameReplace > SAL_CALL getEvents() override
Definition: unoatxt.cxx:950
virtual void SAL_CALL applyTo(const css::uno::Reference< css::text::XTextRange > &xRange) override
Definition: unoatxt.cxx:862
virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursor() override
Definition: unoatxt.cxx:780
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &aIdentifier) override
Definition: unoatxt.cxx:688
SwXAutoTextGroup(const OUString &rName, SwGlossaries *pGloss)
Definition: unoatxt.cxx:232
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
Definition: unoatxt.cxx:120
OUString sName
Definition: unoatxt.hxx:101
virtual sal_Int32 SAL_CALL getCount() override
Definition: unoatxt.cxx:77
virtual void SAL_CALL removeByName(const OUString &aEntryName) override
Definition: unoatxt.cxx:431
virtual OUString SAL_CALL getImplementationName() override
Definition: unoatxt.cxx:662
virtual void SAL_CALL removeTextContent(const css::uno::Reference< css::text::XTextContent > &xContent) override
Definition: unoatxt.cxx:819
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override
Definition: unoatxt.cxx:834
SwXAutoTextEntry(SwGlossaries *, const OUString &rGroupName, const OUString &rEntryName)
Definition: unoatxt.cxx:697
virtual void SAL_CALL replaceByName(const OUString &rName, const css::uno::Any &rElement) override
virtual sal_Bool SAL_CALL hasElements() override
Definition: unoatxt.cxx:520
virtual sal_Int32 SAL_CALL getCount() override
Definition: unoatxt.cxx:493
virtual OUString SAL_CALL getImplementationName() override
Definition: unoatxt.cxx:973
const OUString & GetGroupName() const
Definition: unoatxt.hxx:237
SwDocShellRef xDocSh
Definition: unoatxt.hxx:170
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
Definition: unoatxt.cxx:650
unsigned char sal_Bool
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: unoatxt.cxx:939
tools::SvRef< SwDocShell > SwDocShellRef
Definition: unoatxt.hxx:48
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: unoatxt.cxx:667
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: unoatxt.cxx:672
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:714
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
Definition: unoatxt.cxx:640
virtual void replaceByName(const SvMacroItemId nEvent, const SvxMacro &rMacro) override
event (will be copied)
Definition: unoatxt.cxx:978
virtual ~SwXAutoTextContainer() override
Definition: unoatxt.cxx:72
OUString const sEntryName
Definition: unoatxt.hxx:169
OUString const sGroupName
Definition: unoatxt.hxx:168
virtual ~SwXAutoTextGroup() override
Definition: unoatxt.cxx:243
virtual OUString SAL_CALL getName() override
Definition: unoatxt.cxx:445
const SfxItemPropertySet * pPropSet
Definition: unoatxt.hxx:99
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getEnd() override
Definition: unoatxt.cxx:841
virtual sal_Bool SAL_CALL hasByName(const OUString &Name) override
Definition: unoatxt.cxx:555
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
Definition: unoatxt.cxx:645
void Invalidate()
Definition: unoatxt.hxx:235
Implement the XNameAccess for the AutoText events.
Definition: unoatxt.hxx:242
virtual void SAL_CALL removeByName(const OUString &aGroupName) override
Definition: unoatxt.cxx:188
virtual void SAL_CALL setString(const OUString &aString) override
Definition: unoatxt.cxx:855
virtual ~SwXAutoTextEntry() override
Definition: unoatxt.cxx:706
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
Definition: unoatxt.cxx:582
virtual css::uno::Any SAL_CALL getByName(const OUString &Name) override
Definition: unoatxt.cxx:530
rtl::Reference< SwXBodyText > mxBodyText
Definition: unoatxt.hxx:172
virtual css::uno::Reference< css::text::XAutoTextGroup > SAL_CALL insertNewByName(const OUString &aGroupName) override
Definition: unoatxt.cxx:147
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: unoatxt.cxx:208
virtual void getByName(SvxMacro &rMacro, const SvMacroItemId nEvent) override
item ID of event
Definition: unoatxt.cxx:1011
SwGlossaries * pGlossaries
Definition: unoatxt.hxx:100
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:330
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: unoatxt.cxx:203
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:810
virtual void SAL_CALL renameByName(const OUString &aElementName, const OUString &aNewElementName, const OUString &aNewElementTitle) override
Definition: unoatxt.cxx:263
virtual OUString SAL_CALL getImplementationName() override
Definition: unoatxt.cxx:198
void Invalidate()
Definition: unoatxt.cxx:655
virtual ~SwAutoTextEventDescriptor() override
Definition: unoatxt.cxx:969
SwXAutoTextEntry & rAutoTextEntry
Definition: unoatxt.hxx:244
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &aIdentifier) override
Definition: unoatxt.cxx:223
virtual void SAL_CALL insertControlCharacter(const css::uno::Reference< css::text::XTextRange > &xRange, sal_Int16 nControlCharacter, sal_Bool bAbsorb) override
Definition: unoatxt.cxx:802
SwAutoTextEventDescriptor(SwXAutoTextEntry &rAutoText)
Definition: unoatxt.cxx:962
SwGlossaries * pGlossaries
Definition: unoatxt.hxx:57
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
Definition: unoatxt.cxx:218
virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursorByRange(const css::uno::Reference< css::text::XTextRange > &aTextPosition) override
Definition: unoatxt.cxx:787
void GetBodyText()
Definition: unoatxt.cxx:761
SwGlossaries * pGlossaries
Definition: unoatxt.hxx:167
const SwGlossaries * GetGlossaries() const
Definition: unoatxt.hxx:236
virtual OUString SAL_CALL getImplementationName() override
Definition: unoatxt.cxx:934