26#include <com/sun/star/smarttags/XSmartTagRecognizer.hpp>
27#include <com/sun/star/smarttags/XRangeBasedSmartTagRecognizer.hpp>
28#include <com/sun/star/smarttags/XSmartTagAction.hpp>
29#include <com/sun/star/deployment/ExtensionManager.hpp>
30#include <com/sun/star/smarttags/SmartTagRecognizerMode.hpp>
31#include <com/sun/star/i18n/BreakIterator.hpp>
32#include <com/sun/star/lang/XMultiServiceFactory.hpp>
33#include <com/sun/star/lang/XSingleComponentFactory.hpp>
34#include <com/sun/star/lang/XServiceInfo.hpp>
35#include <com/sun/star/configuration/theDefaultProvider.hpp>
36#include <com/sun/star/container/XContentEnumerationAccess.hpp>
37#include <com/sun/star/beans/XPropertySet.hpp>
38#include <com/sun/star/beans/PropertyValue.hpp>
39#include <com/sun/star/util/XChangesBatch.hpp>
40#include <com/sun/star/util/XChangesNotifier.hpp>
43#include <rtl/ustring.hxx>
51 : maApplicationName(
std::move( aApplicationName )),
53 mbLabelTextWithSmartTags(true)
74 const lang::Locale& rLocale,
75 sal_uInt32 nStart, sal_uInt32 nLen )
const
81 bool bCallRecognizer =
false;
82 const sal_uInt32 nSmartTagCount = xRecognizer->getSmartTagCount();
83 for ( sal_uInt32 j = 0; j < nSmartTagCount && !bCallRecognizer; ++j )
85 const OUString aSmartTagName = xRecognizer->getSmartTagName(j);
87 bCallRecognizer =
true;
90 if ( bCallRecognizer )
97 xRecognizer->recognize( rText, nStart, nLen,
98 smarttags::SmartTagRecognizerMode_PARAGRAPH,
113 if (!xRangeBasedRecognizer.is())
continue;
117 bool bCallRecognizer =
false;
118 const sal_uInt32 nSmartTagCount = xRecognizer->getSmartTagCount();
119 for ( sal_uInt32 j = 0; j < nSmartTagCount && !bCallRecognizer; ++j )
121 const OUString aSmartTagName = xRecognizer->getSmartTagName(j);
123 bCallRecognizer =
true;
126 if ( bCallRecognizer )
128 xRangeBasedRecognizer->recognizeTextRange( xRange,
129 smarttags::SmartTagRecognizerMode_PARAGRAPH,
140 rActionComponentsSequence.realloc( rSmartTagTypes.size() );
141 auto pActionComponentsSequence = rActionComponentsSequence.getArray();
142 rActionIndicesSequence.realloc( rSmartTagTypes.size() );
143 auto pActionIndicesSequence = rActionIndicesSequence.getArray();
145 for (
size_t j = 0; j < rSmartTagTypes.size(); ++j )
147 const OUString& rSmartTagType = rSmartTagTypes[j];
149 const sal_Int32 nNumberOfActionRefs =
maSmartTagMap.count( rSmartTagType );
152 auto aActionsRange = asNonConstRange(aActions);
154 auto aIndicesRange = asNonConstRange(aIndices);
159 for (
auto aActionsIter = iters.first; aActionsIter != iters.second; ++aActionsIter )
161 aActionsRange[
i ] = (*aActionsIter).second.mxSmartTagAction;
162 aIndicesRange[
i++ ] = (*aActionsIter).second.mnSmartTagIndex;
165 pActionComponentsSequence[ j ] = aActions;
166 pActionIndicesSequence[ j ] = aIndices;
186 aRet = xAction->getSmartTagCaption( nSmartTagIndex, rLocale );
204 const std::vector< OUString >* pDisabledTypes )
const
209 bool bCommit =
false;
211 if ( pIsLabelTextWithSmartTags )
213 const Any aEnabled( *pIsLabelTextWithSmartTags );
220 catch ( css::uno::Exception& )
225 if ( pDisabledTypes )
236 catch ( css::uno::Exception& )
247 catch ( css::uno::Exception& )
270 uno::Reference< frame::XModel >
xModel( rEvent.Source, uno::UNO_QUERY );
271 uno::Reference< util::XModifyBroadcaster > xMB(
xModel, uno::UNO_QUERY);
272 uno::Reference< util::XChangesNotifier > xCN(
xModel, uno::UNO_QUERY);
278 uno::Reference< util::XModifyListener > xListener(
this );
279 xMB->removeModifyListener( xListener );
283 uno::Reference< util::XChangesListener > xListener(
this );
284 xCN->removeChangesListener( xListener );
297 bool bExcludedTypes =
false;
298 bool bRecognize =
false;
300 for(
const util::ElementChange& rElementChange : rEvent.Changes)
303 rElementChange.Accessor >>= sTemp;
305 if ( sTemp ==
"ExcludedSmartTagTypes" )
306 bExcludedTypes =
true;
307 else if ( sTemp ==
"RecognizeSmartTags" )
320 if ( !rEnum.is() || !rEnum->hasMoreElements() )
324 while( rEnum->hasMoreElements())
326 const Any a = rEnum->nextElement();
331 xSCF.set(xsInfo, UNO_QUERY);
336 createInstanceWithContext(
mxContext), UNO_QUERY );
346 rEnum = rContent->createContentEnumeration(
"com.sun.star.smarttags.SmartTagAction");
351 while( rEnum->hasMoreElements())
353 const Any a = rEnum->nextElement();
358 xSCF.set(xsInfo, UNO_QUERY);
363 createInstanceWithContext(
mxContext), UNO_QUERY );
379 OUString::Concat(
"/org.openoffice.Office.Common/SmartTags/") + rConfigurationGroupName );
380 beans::PropertyValue aPathArgument;
381 aPathArgument.Name =
"nodepath";
382 aPathArgument.Value = aAny;
390 xConfigurationAccess = xConfProv->createInstanceWithArguments(
391 "com.sun.star.configuration.ConfigurationUpdateAccess",
aArguments );
393 catch ( uno::Exception& )
398 if ( !xConfigurationAccess.is() )
402 xConfigurationAccess = xConfProv->createInstanceWithArguments(
403 "com.sun.star.configuration.ConfigurationAccess",
aArguments );
405 catch ( uno::Exception& )
410 if ( xConfigurationAccess.is() )
422 if ( bExcludedTypes )
430 for (
const auto& rValue : std::as_const(aValues) )
450 deployment::ExtensionManager::get(
mxContext ) );
454 xMB->addModifyListener( xListener );
456 catch ( uno::Exception& )
465 xCN->addChangesListener( xListener );
467 catch ( uno::Exception& )
481 for ( sal_uInt32
i = 0;
i < nRecognizerCount; ++
i )
484 const sal_uInt32 nSmartTagCount = xRecognizer->getSmartTagCount();
485 for ( sal_uInt32 j = 0; j < nSmartTagCount; ++j )
487 const OUString aSmartTagName = xRecognizer->getSmartTagName(j);
494 for ( sal_uInt32 k = 0; k < nActionLibCount; ++k )
497 const sal_uInt32 nSmartTagCountInActionLib = xActionLib->getSmartTagCount();
498 for ( sal_uInt32 l = 0; l < nSmartTagCountInActionLib; ++l )
500 const OUString aSmartTagNameInActionLib = xActionLib->getSmartTagName(l);
501 if ( aSmartTagName == aSmartTagNameInActionLib )
std::pair< const OUString, ActionReference > SmartTagMapElement
virtual void SAL_CALL modified(const css::lang::EventObject &aEvent) override
css::uno::Reference< css::beans::XPropertySet > mxConfigurationSettings
SmartTagMgr(OUString aApplicationName)
css::uno::Reference< css::uno::XComponentContext > mxContext
std::vector< css::uno::Reference< css::smarttags::XSmartTagAction > > maActionList
std::vector< css::uno::Reference< css::smarttags::XSmartTagRecognizer > > maRecognizerList
const OUString maApplicationName
std::set< OUString > maDisabledSmartTagTypes
void PrepareConfiguration(std::u16string_view rConfigurationGroupName)
Prepare configuration access.
void RegisterListener()
Registers the smart tag manager as listener at the package manager.
void WriteConfiguration(const bool *bLabelTextWithSmartTags, const std::vector< OUString > *pDisabledTypes) const
Writes configuration settings.
css::uno::Reference< css::i18n::XBreakIterator > mxBreakIter
void RecognizeTextRange(const css::uno::Reference< css::text::XTextRange > &rRange, const css::uno::Reference< css::text::XTextMarkup > &rMarkup, const css::uno::Reference< css::frame::XController > &rController) const
bool mbLabelTextWithSmartTags
void GetActionSequences(std::vector< OUString > &rSmartTagTypes, css::uno::Sequence< css::uno::Sequence< css::uno::Reference< css::smarttags::XSmartTagAction > > > &rActionComponentsSequence, css::uno::Sequence< css::uno::Sequence< sal_Int32 > > &rActionIndicesSequence) const
Returns all action references associated with a given list of smart tag types.
bool IsSmartTagTypeEnabled(const OUString &rSmartTagType) const
Returns true if the given smart tag type is enabled.
void AssociateActionsWithRecognizers()
Sets up a map that maps smart tag type names to actions references.
virtual void SAL_CALL changesOccurred(const css::util::ChangesEvent &Event) override
void LoadLibraries()
Checks for installed smart tag recognizers/actions and stores them in maRecognizerList and maActionLi...
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
OUString GetSmartTagCaption(const OUString &rSmartTagType, const css::lang::Locale &rLocale) const
Returns the caption for a smart tag type.
void Init(std::u16string_view rConfigurationGroupName)
Triggers configuration reading, library loading and listener registration NOTE: MUST BE CALLED AFTER ...
void ReadConfiguration(bool bExcludedTypes, bool bRecognize)
Reads the configuration data.
std::multimap< OUString, ActionReference > maSmartTagMap
void RecognizeString(const OUString &rText, const css::uno::Reference< css::text::XTextMarkup > &rMarkup, const css::uno::Reference< css::frame::XController > &rController, const css::lang::Locale &rLocale, sal_uInt32 nStart, sal_uInt32 nLen) const
Dispatches the recognize call to all installed smart tag recognizers.
virtual ~SmartTagMgr() override
Sequence< PropertyValue > aArguments
class SvxPropertySetInfoPool
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
Reference< XComponentContext > getProcessComponentContext()
A reference to a smart tag action.
sal_Int32 mnSmartTagIndex
css::uno::Reference< css::smarttags::XSmartTagAction > mxSmartTagAction
Reference< XController > xController
Reference< XModel > xModel