1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _SMARTTAGMGR_HXX 25 #define _SMARTTAGMGR_HXX 26 27 #include <cppuhelper/implbase2.hxx> 28 #include <com/sun/star/uno/Reference.hxx> 29 #include <com/sun/star/uno/Sequence.hxx> 30 #include <com/sun/star/util/XModifyListener.hpp> 31 #include <com/sun/star/util/XChangesListener.hpp> 32 #include "svx/svxdllapi.h" 33 34 #include <vector> 35 #include <map> 36 #include <set> 37 38 namespace com { namespace sun { namespace star { namespace uno { 39 class XComponentContext; 40 } } } } 41 42 namespace com { namespace sun { namespace star { namespace smarttags { 43 class XSmartTagRecognizer; 44 class XSmartTagAction; 45 } } } } 46 47 namespace com { namespace sun { namespace star { namespace text { 48 class XTextMarkup; 49 class XTextRange; 50 } } } } 51 52 namespace com { namespace sun { namespace star { namespace i18n { 53 class XBreakIterator; 54 } } } } 55 56 namespace com { namespace sun { namespace star { namespace lang { 57 struct Locale; 58 struct EventObject; 59 struct ChangesEvent; 60 class XMultiServiceFactory; 61 } } } } 62 63 namespace com { namespace sun { namespace star { namespace beans { 64 class XPropertySet; 65 } } } } 66 67 namespace com { namespace sun { namespace star { namespace frame { 68 class XController; 69 } } } } 70 71 /** A reference to a smart tag action 72 73 An action service can support various actions. Therefore an ActionReference 74 consists of a reference to the service and and index. 75 */ 76 struct ActionReference 77 { 78 com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagAction > mxSmartTagAction; 79 sal_Int32 mnSmartTagIndex; ActionReferenceActionReference80 ActionReference( com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagAction > xSmartTagAction, sal_Int32 nSmartTagIndex ) 81 : mxSmartTagAction( xSmartTagAction), mnSmartTagIndex( nSmartTagIndex ) {} 82 }; 83 84 /** The smart tag manager maintains all installed action and recognizer services 85 86 This class organizes the available smarttag libraries and provides access functions 87 to these libraries. The smart tag manager is a singleton. 88 */ 89 class SVX_DLLPUBLIC SmartTagMgr : public cppu::WeakImplHelper2< ::com::sun::star::util::XModifyListener, 90 ::com::sun::star::util::XChangesListener > 91 { 92 private: 93 94 const rtl::OUString maApplicationName; 95 std::vector< com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagRecognizer > > maRecognizerList; 96 std::vector< com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagAction > > maActionList; 97 std::set< rtl::OUString > maDisabledSmartTagTypes; 98 std::multimap < rtl::OUString, ActionReference > maSmartTagMap; 99 mutable com::sun::star::uno::Reference< com::sun::star::i18n::XBreakIterator > mxBreakIter; 100 com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > mxMSF; 101 com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext> mxContext; 102 com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > mxConfigurationSettings; 103 bool mbLabelTextWithSmartTags; 104 105 /** Checks for installed smart tag recognizers/actions and stores them in 106 maRecognizerList and maActionList. 107 */ 108 void LoadLibraries(); 109 110 /** Prepare configuration access. 111 */ 112 void PrepareConfiguration( const rtl::OUString& rConfigurationGroupName ); 113 114 /** Reads the configuration data. 115 */ 116 void ReadConfiguration( bool bExcludedTypes, bool bRecognize ); 117 118 /** Registeres the smart tag manager as listener at the package manager. 119 */ 120 void RegisterListener(); 121 122 /** Sets up a map that maps smart tag type names to actions references. 123 */ 124 void AssociateActionsWithRecognizers(); 125 126 void CreateBreakIterator() const; 127 128 public: 129 130 SmartTagMgr( const rtl::OUString& rApplicationName ); 131 virtual ~SmartTagMgr(); 132 133 /** Triggeres configuration reading, library loading and listener registration 134 NOTE: MUST BE CALLED AFTER CONSTRUCTION! 135 */ 136 void Init( const rtl::OUString& rConfigurationGroupName ); 137 138 /** Dispatches the recognize call to all installed smart tag recognizers 139 140 @param rText 141 The string to be scanned by the recognizers. 142 143 @param xMarkup 144 The object allows the recognizers to store any found smart tags. 145 146 @param xController 147 The current controller of the document. 148 149 @param rLocale 150 The locale of rText. 151 152 @param nStart 153 The start offset of the text to be scanned in rText. 154 155 @param nLen 156 The length of the text to be scanned. 157 158 */ 159 void RecognizeString( const rtl::OUString& rText, 160 const com::sun::star::uno::Reference< com::sun::star::text::XTextMarkup > xMarkup, 161 const com::sun::star::uno::Reference< com::sun::star::frame::XController > xController, 162 const com::sun::star::lang::Locale& rLocale, 163 sal_uInt32 nStart, sal_uInt32 nLen ) const; 164 165 void RecognizeTextRange(const com::sun::star::uno::Reference< com::sun::star::text::XTextRange> xRange, 166 const com::sun::star::uno::Reference< com::sun::star::text::XTextMarkup > xMarkup, 167 const com::sun::star::uno::Reference< com::sun::star::frame::XController > xController) const; 168 169 170 /** Returns all action references associated with a given list of smart tag types 171 172 @param rSmartTagTypes 173 The list of types 174 175 @param rActionComponentsSequence 176 Output parameter 177 178 @param rActionIndicesSequence 179 Output parameter 180 */ 181 void GetActionSequences( com::sun::star::uno::Sequence < rtl::OUString >& rSmartTagTypes, 182 com::sun::star::uno::Sequence < com::sun::star::uno::Sequence< com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagAction > > >& rActionComponentsSequence, 183 com::sun::star::uno::Sequence < com::sun::star::uno::Sequence< sal_Int32 > >& rActionIndicesSequence ) const; 184 185 /** Returns the caption for a smart tag type. 186 187 @param rSmartTagType 188 The given smart tag type. 189 190 @param rLocale 191 The locale. 192 */ 193 rtl::OUString GetSmartTagCaption( const rtl::OUString& rSmartTagType, const com::sun::star::lang::Locale& rLocale ) const; 194 195 /** Returns true if the given smart tag type is enabled. 196 */ 197 bool IsSmartTagTypeEnabled( const rtl::OUString& rSmartTagType ) const; 198 199 /** Enable or disable smart tags. 200 */ IsLabelTextWithSmartTags() const201 bool IsLabelTextWithSmartTags() const { return mbLabelTextWithSmartTags; } 202 203 /** Returns the number of registered recognizers. 204 */ NumberOfRecognizers() const205 sal_uInt32 NumberOfRecognizers() const { return maRecognizerList.size(); } 206 207 /** Returns a recognizer. 208 */ 209 com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagRecognizer > GetRecognizer(sal_uInt32 i) const210 GetRecognizer( sal_uInt32 i ) const { return maRecognizerList[i]; } 211 212 /** Is smart tag recognization active? 213 */ IsSmartTagsEnabled() const214 bool IsSmartTagsEnabled() const { return 0 != NumberOfRecognizers() && 215 IsLabelTextWithSmartTags(); } 216 217 /** Writes configuration settings. 218 */ 219 void WriteConfiguration( const bool* bLabelTextWithSmartTags, 220 const std::vector< rtl::OUString >* pDisabledTypes ) const; 221 222 /** Returns the name of the application this instance has been created by. 223 */ GetApplicationName() const224 const rtl::OUString GetApplicationName() const { return maApplicationName; } 225 226 // ::com::sun::star::lang::XEventListener 227 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException); 228 229 // ::com::sun::star::util::XModifyListener 230 virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& aEvent ) throw(::com::sun::star::uno::RuntimeException); 231 232 // ::com::sun::star::util::XChangesListener 233 virtual void SAL_CALL changesOccurred( const ::com::sun::star::util::ChangesEvent& Event ) throw(::com::sun::star::uno::RuntimeException); 234 }; 235 236 #endif 237