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 final : public cppu::WeakImplHelper
52 <
53  css::text::XAutoTextContainer2,
54  css::lang::XServiceInfo
55 >
56 {
58 
59  virtual ~SwXAutoTextContainer() override; // ref-counted objects are not to be deleted from outside -> protected dtor
60 
61 public:
63 
64  //XIndexAccess
65  virtual sal_Int32 SAL_CALL getCount( ) override;
66  virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override;
67 
68  //XNameAccess
69  virtual css::uno::Any SAL_CALL getByName(const OUString& Name) override;
70  virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override;
71  virtual sal_Bool SAL_CALL hasByName(const OUString& Name) override;
72 
73  //XElementAccess
74  virtual css::uno::Type SAL_CALL getElementType( ) override;
75  virtual sal_Bool SAL_CALL hasElements( ) override;
76 
77  //XAutoTextContainer
78  virtual css::uno::Reference< css::text::XAutoTextGroup > SAL_CALL insertNewByName(const OUString& aGroupName) override;
79  virtual void SAL_CALL removeByName(const OUString& aGroupName) override;
80 
81  //XServiceInfo
82  virtual OUString SAL_CALL getImplementationName() override;
83  virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
84  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
85 
86 };
87 
88 class SwXAutoTextGroup final : public cppu::WeakImplHelper
89 <
90  css::text::XAutoTextGroup,
91  css::beans::XPropertySet,
92  css::lang::XServiceInfo,
93  css::container::XIndexAccess,
94  css::container::XNamed,
95  css::lang::XUnoTunnel
96 >
97 {
100  OUString sName;
101  OUString m_sGroupName; // prefix m_ to disambiguate from some local vars in the implementation
102 
103  virtual ~SwXAutoTextGroup() override; // ref-counted objects are not to be deleted from outside -> protected dtor
104 
105 public:
106  SwXAutoTextGroup(const OUString& rName, SwGlossaries* pGloss);
107 
108  static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId();
109 
110  //XUnoTunnel
111  virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override;
112 
113  //XAutoTextGroup
114  virtual css::uno::Sequence< OUString > SAL_CALL getTitles() override;
115  virtual void SAL_CALL renameByName(const OUString& aElementName, const OUString& aNewElementName, const OUString& aNewElementTitle) override;
116  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;
117  virtual void SAL_CALL removeByName(const OUString& aEntryName) override;
118 
119  //XNamed
120  virtual OUString SAL_CALL getName() override;
121  virtual void SAL_CALL setName(const OUString& Name_) override;
122 
123  //XIndexAccess
124  virtual sal_Int32 SAL_CALL getCount( ) override;
125  virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override;
126 
127  //XNameAccess
128  virtual css::uno::Any SAL_CALL getByName(const OUString& Name) override;
129  virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override;
130  virtual sal_Bool SAL_CALL hasByName(const OUString& Name) override;
131 
132  //XElementAccess
133  virtual css::uno::Type SAL_CALL getElementType( ) override;
134  virtual sal_Bool SAL_CALL hasElements( ) override;
135 
136  //XServiceInfo
137  virtual OUString SAL_CALL getImplementationName() override;
138  virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
139  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
140 
141  //XPropertySet
142  virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
143  virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override;
144  virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
145  virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
146  virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
147  virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
148  virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
149 
150  void Invalidate();
151 };
152 
153 class SwXAutoTextEntry final
154  :public SfxListener
155  ,public cppu::BaseMutex
156  ,public cppu::WeakComponentImplHelper
157  <
158  css::text::XAutoTextEntry,
159  css::lang::XServiceInfo,
160  css::lang::XUnoTunnel,
161  css::text::XText,
162  css::document::XEventsSupplier
163  >
164 {
166  OUString sGroupName;
167  OUString sEntryName;
171 
173  {
174  if ( !mxBodyText.is() )
175  GetBodyText();
176  }
177  void GetBodyText ();
178 
179  void SAL_CALL disposing() override;
180 
192  void implFlushDocument( bool _bCloseDoc = false );
193 
194  // SfxListener overridables
195  virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
196 
197  virtual ~SwXAutoTextEntry() override; // ref-counted objects are not to be deleted from outside -> protected dtor
198 
199 public:
200  SwXAutoTextEntry(SwGlossaries* , const OUString& rGroupName, const OUString& rEntryName);
201 
202  static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId();
203 
204  //XUnoTunnel
205  virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override;
206 
207  //XText
208  virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursor() override;
209  virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursorByRange(const css::uno::Reference< css::text::XTextRange > & aTextPosition) override;
210  virtual void SAL_CALL insertString(const css::uno::Reference< css::text::XTextRange > & xRange, const OUString& aString, sal_Bool bAbsorb) override;
211  virtual void SAL_CALL insertControlCharacter(const css::uno::Reference< css::text::XTextRange > & xRange, sal_Int16 nControlCharacter, sal_Bool bAbsorb) override;
212  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;
213  virtual void SAL_CALL removeTextContent(const css::uno::Reference< css::text::XTextContent > & xContent) override;
214 
215  //XTextRange
216  virtual css::uno::Reference< css::text::XText > SAL_CALL getText() override;
217  virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override;
218  virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getEnd() override;
219  virtual OUString SAL_CALL getString() override;
220  virtual void SAL_CALL setString(const OUString& aString) override;
221 
222  //XAutoTextEntry
223  virtual void SAL_CALL applyTo(const css::uno::Reference< css::text::XTextRange > & xRange) override;
224 
225  //XServiceInfo
226  virtual OUString SAL_CALL getImplementationName() override;
227  virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
228  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
229 
230  // XEventsSupplier
231  virtual css::uno::Reference< css::container::XNameReplace > SAL_CALL getEvents( ) override;
232 
233  void Invalidate() {pGlossaries = nullptr;}
234  const SwGlossaries* GetGlossaries() const { return pGlossaries; }
235  const OUString& GetGroupName() const {return sGroupName;}
236  const OUString& GetEntryName() const {return sEntryName;}
237 };
238 
241 {
243 
246 
247 public:
249 
250  virtual ~SwAutoTextEventDescriptor() override;
251 
252  virtual OUString SAL_CALL getImplementationName() override;
253 
254 private:
255 
256  virtual void replaceByName(
257  const SvMacroItemId nEvent,
258  const SvxMacro& rMacro)
259  override;
260 
261  virtual void getByName(
262  SvxMacro& rMacro,
263  const SvMacroItemId nEvent )
264  override;
265 };
266 
267 #endif
268 
269 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL setName(const OUString &Name_) override
Definition: unoatxt.cxx:429
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:704
virtual css::uno::Type SAL_CALL getElementType() override
Definition: unoatxt.cxx:494
OUString m_sGroupName
Definition: unoatxt.hxx:101
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
virtual sal_Bool SAL_CALL hasByName(const OUString &Name) override
Definition: unoatxt.cxx:132
virtual css::uno::Reference< css::text::XText > SAL_CALL getText() override
Definition: unoatxt.cxx:800
Definition: doc.hxx:188
OUString sGroupName
Definition: unoatxt.hxx:166
SvMacroItemId
const OUString & GetEntryName() const
Definition: unoatxt.hxx:236
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:905
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:172
void SAL_CALL disposing() override
Definition: unoatxt.cxx:747
virtual OUString SAL_CALL getString() override
Definition: unoatxt.cxx:821
virtual void SAL_CALL insertString(const css::uno::Reference< css::text::XTextRange > &xRange, const OUString &aString, sal_Bool bAbsorb) override
Definition: unoatxt.cxx:768
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:911
virtual void SAL_CALL applyTo(const css::uno::Reference< css::text::XTextRange > &xRange) override
Definition: unoatxt.cxx:835
virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursor() override
Definition: unoatxt.cxx:753
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
OUString sName
Definition: unoatxt.hxx:100
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
virtual void SAL_CALL removeTextContent(const css::uno::Reference< css::text::XTextContent > &xContent) override
Definition: unoatxt.cxx:792
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override
Definition: unoatxt.cxx:807
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:934
const OUString & GetGroupName() const
Definition: unoatxt.hxx:235
SwDocShellRef xDocSh
Definition: unoatxt.hxx:168
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:900
tools::SvRef< SwDocShell > SwDocShellRef
Definition: unoatxt.hxx:48
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:686
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:939
virtual ~SwXAutoTextContainer() override
Definition: unoatxt.cxx:66
virtual ~SwXAutoTextGroup() override
Definition: unoatxt.cxx:229
virtual OUString SAL_CALL getName() override
Definition: unoatxt.cxx:423
const SfxItemPropertySet * pPropSet
Definition: unoatxt.hxx:98
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getEnd() override
Definition: unoatxt.cxx:814
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:233
Implement the XNameAccess for the AutoText events.
Definition: unoatxt.hxx:240
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:828
virtual ~SwXAutoTextEntry() override
Definition: unoatxt.cxx:678
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:170
virtual css::uno::Reference< css::text::XAutoTextGroup > SAL_CALL insertNewByName(const OUString &aGroupName) override
Definition: unoatxt.cxx:141
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:972
SwGlossaries * pGlossaries
Definition: unoatxt.hxx:99
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:783
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:930
SwXAutoTextEntry & rAutoTextEntry
Definition: unoatxt.hxx:242
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:775
SwAutoTextEventDescriptor(SwXAutoTextEntry &rAutoText)
Definition: unoatxt.cxx:923
SwGlossaries * pGlossaries
Definition: unoatxt.hxx:57
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:760
void GetBodyText()
Definition: unoatxt.cxx:734
SwGlossaries * pGlossaries
Definition: unoatxt.hxx:165
const SwGlossaries * GetGlossaries() const
Definition: unoatxt.hxx:234
virtual OUString SAL_CALL getImplementationName() override
Definition: unoatxt.cxx:895
OUString sEntryName
Definition: unoatxt.hxx:167