LibreOffice Module svx (master)  1
SmartTagMgr.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 
20 #ifndef INCLUDED_SVX_SMARTTAGMGR_HXX
21 #define INCLUDED_SVX_SMARTTAGMGR_HXX
22 
23 #include <cppuhelper/implbase.hxx>
24 #include <com/sun/star/uno/Reference.hxx>
25 #include <com/sun/star/uno/Sequence.hxx>
26 #include <com/sun/star/util/XModifyListener.hpp>
27 #include <com/sun/star/util/XChangesListener.hpp>
28 #include <svx/svxdllapi.h>
29 
30 #include <vector>
31 #include <map>
32 #include <set>
33 #include <string_view>
34 
35 namespace com::sun::star::uno {
36  class XComponentContext;
37 }
38 
40  class XSmartTagRecognizer;
41  class XSmartTagAction;
42 }
43 
44 namespace com::sun::star::text {
45  class XTextMarkup;
46  class XTextRange;
47 }
48 
49 namespace com::sun::star::i18n {
50  class XBreakIterator;
51 }
52 
53 namespace com::sun::star::lang {
54  struct Locale;
55  struct EventObject;
56  struct ChangesEvent;
57 }
58 
59 namespace com::sun::star::beans {
60  class XPropertySet;
61 }
62 
63 namespace com::sun::star::frame {
64  class XController;
65 }
66 
73 {
74  css::uno::Reference< css::smarttags::XSmartTagAction > mxSmartTagAction;
75  sal_Int32 mnSmartTagIndex;
76  ActionReference( css::uno::Reference< css::smarttags::XSmartTagAction > const & xSmartTagAction, sal_Int32 nSmartTagIndex )
77  : mxSmartTagAction( xSmartTagAction), mnSmartTagIndex( nSmartTagIndex ) {}
78 };
79 
85 class SVX_DLLPUBLIC SmartTagMgr : public cppu::WeakImplHelper< css::util::XModifyListener,
86  css::util::XChangesListener >
87 {
88 private:
89 
90  const OUString maApplicationName;
91  std::vector< css::uno::Reference< css::smarttags::XSmartTagRecognizer > > maRecognizerList;
92  std::vector< css::uno::Reference< css::smarttags::XSmartTagAction > > maActionList;
93  std::set< OUString > maDisabledSmartTagTypes;
94  std::multimap < OUString, ActionReference > maSmartTagMap;
95  mutable css::uno::Reference< css::i18n::XBreakIterator > mxBreakIter;
96  css::uno::Reference< css::uno::XComponentContext> mxContext;
97  css::uno::Reference< css::beans::XPropertySet > mxConfigurationSettings;
99 
103  void LoadLibraries();
104 
107  void PrepareConfiguration( std::u16string_view rConfigurationGroupName );
108 
111  void ReadConfiguration( bool bExcludedTypes, bool bRecognize );
112 
115  void RegisterListener();
116 
119  void AssociateActionsWithRecognizers();
120 
121 public:
122 
123  SmartTagMgr( const OUString& rApplicationName );
124  virtual ~SmartTagMgr() override;
125 
129  void Init( std::u16string_view rConfigurationGroupName );
130 
153  void RecognizeString( const OUString& rText,
154  const css::uno::Reference< css::text::XTextMarkup >& rMarkup,
155  const css::uno::Reference< css::frame::XController >& rController,
156  const css::lang::Locale& rLocale,
157  sal_uInt32 nStart, sal_uInt32 nLen ) const;
158 
159  void RecognizeTextRange(const css::uno::Reference< css::text::XTextRange>& rRange,
160  const css::uno::Reference< css::text::XTextMarkup >& rMarkup,
161  const css::uno::Reference< css::frame::XController >& rController) const;
162 
174  void GetActionSequences( std::vector< OUString >& rSmartTagTypes,
175  css::uno::Sequence < css::uno::Sequence< css::uno::Reference< css::smarttags::XSmartTagAction > > >& rActionComponentsSequence,
176  css::uno::Sequence < css::uno::Sequence< sal_Int32 > >& rActionIndicesSequence ) const;
177 
186  OUString GetSmartTagCaption( const OUString& rSmartTagType, const css::lang::Locale& rLocale ) const;
187 
190  bool IsSmartTagTypeEnabled( const OUString& rSmartTagType ) const;
191 
194  bool IsLabelTextWithSmartTags() const { return mbLabelTextWithSmartTags; }
195 
198  sal_uInt32 NumberOfRecognizers() const { return maRecognizerList.size(); }
199 
202  css::uno::Reference< css::smarttags::XSmartTagRecognizer > const &
203  GetRecognizer( sal_uInt32 i ) const { return maRecognizerList[i]; }
204 
207  bool IsSmartTagsEnabled() const { return 0 != NumberOfRecognizers() &&
208  IsLabelTextWithSmartTags(); }
209 
212  void WriteConfiguration( const bool* bLabelTextWithSmartTags,
213  const std::vector< OUString >* pDisabledTypes ) const;
214 
217  const OUString& GetApplicationName() const { return maApplicationName; }
218 
219  // css::lang::XEventListener
220  virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
221 
222  // css::util::XModifyListener
223  virtual void SAL_CALL modified( const css::lang::EventObject& aEvent ) override;
224 
225  // css::util::XChangesListener
226  virtual void SAL_CALL changesOccurred( const css::util::ChangesEvent& Event ) override;
227 };
228 
229 #endif
230 
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void Init()
std::multimap< OUString, ActionReference > maSmartTagMap
Definition: SmartTagMgr.hxx:94
css::uno::Reference< css::i18n::XBreakIterator > mxBreakIter
Definition: SmartTagMgr.hxx:95
#define SVX_DLLPUBLIC
Definition: svxdllapi.h:28
bool IsLabelTextWithSmartTags() const
Enable or disable smart tags.
std::set< OUString > maDisabledSmartTagTypes
Definition: SmartTagMgr.hxx:93
std::vector< css::uno::Reference< css::smarttags::XSmartTagAction > > maActionList
Definition: SmartTagMgr.hxx:92
const OUString maApplicationName
Definition: SmartTagMgr.hxx:90
css::uno::Reference< css::uno::XComponentContext > mxContext
Definition: SmartTagMgr.hxx:96
css::uno::Reference< css::smarttags::XSmartTagAction > mxSmartTagAction
Definition: SmartTagMgr.hxx:74
sal_Int32 mnSmartTagIndex
Definition: SmartTagMgr.hxx:75
class SAL_NO_VTABLE XPropertySet
Definition: xmlexchg.hxx:28
A reference to a smart tag action.
Definition: SmartTagMgr.hxx:72
bool IsSmartTagsEnabled() const
Is smart tag recognition active?
std::vector< css::uno::Reference< css::smarttags::XSmartTagRecognizer > > maRecognizerList
Definition: SmartTagMgr.hxx:91
css::uno::Reference< css::beans::XPropertySet > mxConfigurationSettings
Definition: SmartTagMgr.hxx:97
css::uno::Reference< css::smarttags::XSmartTagRecognizer > const & GetRecognizer(sal_uInt32 i) const
Returns a recognizer.
bool mbLabelTextWithSmartTags
Definition: SmartTagMgr.hxx:98
const OUString & GetApplicationName() const
Returns the name of the application this instance has been created by.
ActionReference(css::uno::Reference< css::smarttags::XSmartTagAction > const &xSmartTagAction, sal_Int32 nSmartTagIndex)
Definition: SmartTagMgr.hxx:76
sal_uInt32 NumberOfRecognizers() const
Returns the number of registered recognizers.
The smart tag manager maintains all installed action and recognizer services.
Definition: SmartTagMgr.hxx:85