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 
34 namespace com::sun::star::uno {
35  class XComponentContext;
36 }
37 
39  class XSmartTagRecognizer;
40  class XSmartTagAction;
41 }
42 
43 namespace com::sun::star::text {
44  class XTextMarkup;
45  class XTextRange;
46 }
47 
48 namespace com::sun::star::i18n {
49  class XBreakIterator;
50 }
51 
52 namespace com::sun::star::lang {
53  struct Locale;
54  struct EventObject;
55  struct ChangesEvent;
56 }
57 
58 namespace com::sun::star::beans {
59  class XPropertySet;
60 }
61 
62 namespace com::sun::star::frame {
63  class XController;
64 }
65 
72 {
73  css::uno::Reference< css::smarttags::XSmartTagAction > mxSmartTagAction;
74  sal_Int32 mnSmartTagIndex;
75  ActionReference( css::uno::Reference< css::smarttags::XSmartTagAction > const & xSmartTagAction, sal_Int32 nSmartTagIndex )
76  : mxSmartTagAction( xSmartTagAction), mnSmartTagIndex( nSmartTagIndex ) {}
77 };
78 
84 class SVX_DLLPUBLIC SmartTagMgr : public cppu::WeakImplHelper< css::util::XModifyListener,
85  css::util::XChangesListener >
86 {
87 private:
88 
89  const OUString maApplicationName;
90  std::vector< css::uno::Reference< css::smarttags::XSmartTagRecognizer > > maRecognizerList;
91  std::vector< css::uno::Reference< css::smarttags::XSmartTagAction > > maActionList;
92  std::set< OUString > maDisabledSmartTagTypes;
93  std::multimap < OUString, ActionReference > maSmartTagMap;
94  mutable css::uno::Reference< css::i18n::XBreakIterator > mxBreakIter;
95  css::uno::Reference< css::uno::XComponentContext> mxContext;
96  css::uno::Reference< css::beans::XPropertySet > mxConfigurationSettings;
98 
102  void LoadLibraries();
103 
106  void PrepareConfiguration( const OUString& rConfigurationGroupName );
107 
110  void ReadConfiguration( bool bExcludedTypes, bool bRecognize );
111 
114  void RegisterListener();
115 
118  void AssociateActionsWithRecognizers();
119 
120 public:
121 
122  SmartTagMgr( const OUString& rApplicationName );
123  virtual ~SmartTagMgr() override;
124 
128  void Init( const OUString& rConfigurationGroupName );
129 
152  void RecognizeString( const OUString& rText,
153  const css::uno::Reference< css::text::XTextMarkup >& rMarkup,
154  const css::uno::Reference< css::frame::XController >& rController,
155  const css::lang::Locale& rLocale,
156  sal_uInt32 nStart, sal_uInt32 nLen ) const;
157 
158  void RecognizeTextRange(const css::uno::Reference< css::text::XTextRange>& rRange,
159  const css::uno::Reference< css::text::XTextMarkup >& rMarkup,
160  const css::uno::Reference< css::frame::XController >& rController) const;
161 
173  void GetActionSequences( std::vector< OUString >& rSmartTagTypes,
174  css::uno::Sequence < css::uno::Sequence< css::uno::Reference< css::smarttags::XSmartTagAction > > >& rActionComponentsSequence,
175  css::uno::Sequence < css::uno::Sequence< sal_Int32 > >& rActionIndicesSequence ) const;
176 
185  OUString GetSmartTagCaption( const OUString& rSmartTagType, const css::lang::Locale& rLocale ) const;
186 
189  bool IsSmartTagTypeEnabled( const OUString& rSmartTagType ) const;
190 
193  bool IsLabelTextWithSmartTags() const { return mbLabelTextWithSmartTags; }
194 
197  sal_uInt32 NumberOfRecognizers() const { return maRecognizerList.size(); }
198 
201  css::uno::Reference< css::smarttags::XSmartTagRecognizer > const &
202  GetRecognizer( sal_uInt32 i ) const { return maRecognizerList[i]; }
203 
206  bool IsSmartTagsEnabled() const { return 0 != NumberOfRecognizers() &&
207  IsLabelTextWithSmartTags(); }
208 
211  void WriteConfiguration( const bool* bLabelTextWithSmartTags,
212  const std::vector< OUString >* pDisabledTypes ) const;
213 
216  const OUString& GetApplicationName() const { return maApplicationName; }
217 
218  // css::lang::XEventListener
219  virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
220 
221  // css::util::XModifyListener
222  virtual void SAL_CALL modified( const css::lang::EventObject& aEvent ) override;
223 
224  // css::util::XChangesListener
225  virtual void SAL_CALL changesOccurred( const css::util::ChangesEvent& Event ) override;
226 };
227 
228 #endif
229 
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void Init()
std::multimap< OUString, ActionReference > maSmartTagMap
Definition: SmartTagMgr.hxx:93
css::uno::Reference< css::i18n::XBreakIterator > mxBreakIter
Definition: SmartTagMgr.hxx:94
#define SVX_DLLPUBLIC
Definition: svxdllapi.h:28
bool IsLabelTextWithSmartTags() const
Enable or disable smart tags.
std::set< OUString > maDisabledSmartTagTypes
Definition: SmartTagMgr.hxx:92
std::vector< css::uno::Reference< css::smarttags::XSmartTagAction > > maActionList
Definition: SmartTagMgr.hxx:91
const OUString maApplicationName
Definition: SmartTagMgr.hxx:89
css::uno::Reference< css::uno::XComponentContext > mxContext
Definition: SmartTagMgr.hxx:95
css::uno::Reference< css::smarttags::XSmartTagAction > mxSmartTagAction
Definition: SmartTagMgr.hxx:73
sal_Int32 mnSmartTagIndex
Definition: SmartTagMgr.hxx:74
class SAL_NO_VTABLE XPropertySet
Definition: xmlexchg.hxx:28
A reference to a smart tag action.
Definition: SmartTagMgr.hxx:71
bool IsSmartTagsEnabled() const
Is smart tag recognition active?
std::vector< css::uno::Reference< css::smarttags::XSmartTagRecognizer > > maRecognizerList
Definition: SmartTagMgr.hxx:90
css::uno::Reference< css::beans::XPropertySet > mxConfigurationSettings
Definition: SmartTagMgr.hxx:96
css::uno::Reference< css::smarttags::XSmartTagRecognizer > const & GetRecognizer(sal_uInt32 i) const
Returns a recognizer.
bool mbLabelTextWithSmartTags
Definition: SmartTagMgr.hxx:97
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:75
sal_uInt32 NumberOfRecognizers() const
Returns the number of registered recognizers.
The smart tag manager maintains all installed action and recognizer services.
Definition: SmartTagMgr.hxx:84