From 1959113eac6bb23310883c974ac40cba6f222493 Mon Sep 17 00:00:00 2001 From: Jürgen Schmidt Date: Wed, 20 Mar 2013 14:14:46 +0000 Subject: Resolves: #i121730# add optional interface XRangeBasedSmartTagRecognizer for SmartTags Patch by: Kai Labusch Review by: arielch, jsc (cherry picked from commit a64c066b02924371f486688df01b6881bcd0da8b) Conflicts: offapi/com/sun/star/smarttags/XSmartTagRecognizer.idl offapi/com/sun/star/smarttags/makefile.mk svx/inc/svx/SmartTagMgr.hxx svx/source/smarttags/SmartTagMgr.cxx sw/source/core/txtnode/txtedt.cxx Change-Id: I11f528b2c1a068d0b1db1e76c2f889c0632ab972 --- include/svx/SmartTagMgr.hxx | 8 ++- offapi/UnoApi_offapi.mk | 1 + .../smarttags/XRangeBasedSmartTagRecognizer.idl | 68 ++++++++++++++++++++++ .../com/sun/star/smarttags/XSmartTagRecognizer.idl | 3 +- svx/source/smarttags/SmartTagMgr.cxx | 38 +++++++++++- sw/source/core/txtnode/txtedt.cxx | 11 +++- 6 files changed, 124 insertions(+), 5 deletions(-) create mode 100644 offapi/com/sun/star/smarttags/XRangeBasedSmartTagRecognizer.idl diff --git a/include/svx/SmartTagMgr.hxx b/include/svx/SmartTagMgr.hxx index 836ff820650f..42563fd1a8ad 100644 --- a/include/svx/SmartTagMgr.hxx +++ b/include/svx/SmartTagMgr.hxx @@ -42,6 +42,7 @@ namespace com { namespace sun { namespace star { namespace smarttags { namespace com { namespace sun { namespace star { namespace text { class XTextMarkup; + class XTextRange; } } } } namespace com { namespace sun { namespace star { namespace i18n { @@ -149,12 +150,17 @@ public: The length of the text to be scanned. */ - void Recognize( const OUString& rText, + + void RecognizeString( const OUString& rText, const com::sun::star::uno::Reference< com::sun::star::text::XTextMarkup > xMarkup, const com::sun::star::uno::Reference< com::sun::star::frame::XController > xController, const com::sun::star::lang::Locale& rLocale, sal_uInt32 nStart, sal_uInt32 nLen ) const; + void RecognizeTextRange(const com::sun::star::uno::Reference< com::sun::star::text::XTextRange> xRange, + const com::sun::star::uno::Reference< com::sun::star::text::XTextMarkup > xMarkup, + const com::sun::star::uno::Reference< com::sun::star::frame::XController > xController) const; + /** Returns all action references associated with a given list of smart tag types @param rSmartTagTypes diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk index b08f125c7837..9f0df7a90fd3 100644 --- a/offapi/UnoApi_offapi.mk +++ b/offapi/UnoApi_offapi.mk @@ -3534,6 +3534,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,offapi/com/sun/star/sheet,\ )) $(eval $(call gb_UnoApi_add_idlfiles,offapi,offapi/com/sun/star/smarttags,\ SmartTagRecognizerMode \ + XRangeBasedSmartTagRecognizer \ XSmartTagAction \ XSmartTagRecognizer \ )) diff --git a/offapi/com/sun/star/smarttags/XRangeBasedSmartTagRecognizer.idl b/offapi/com/sun/star/smarttags/XRangeBasedSmartTagRecognizer.idl new file mode 100644 index 000000000000..7de76908d5d2 --- /dev/null +++ b/offapi/com/sun/star/smarttags/XRangeBasedSmartTagRecognizer.idl @@ -0,0 +1,68 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef __com_sun_star_smarttags_XRangeBasedSmartTagRecognizer_idl__ +#define __com_sun_star_smarttags_XRangeBasedSmartTagRecognizer_idl__ + +#include +#include +#include +#include +#include +#include +#include + +module com { module sun { module star { module smarttags { + +/** + provides access to a range based smart tag recognizer. + */ + +interface XRangeBasedSmartTagRecognizer: com::sun::star::lang::XInitialization +{ + /** recognizes smart tags. + + @param xRange + The text that should be scanned by the recognizer. + + @param eDataType + This value indicates the type of the passed text. + + @param aLocale + Is used to indicate the language of the passed text. + + @param xTextMarkup + This object is used to submit any recognized smart tags + to the calling application. + + @param aApplicationName + A string containing the name of the calling application. + + @param xController + The current controller of the document. + */ + + void recognizeTextRange( [in] com::sun::star::text::XTextRange xRange, + [in] SmartTagRecognizerMode eDataType, + [in] com::sun::star::text::XTextMarkup xTextMarkup, + [in] string aApplicationName, + [in] com::sun::star::frame::XController xController); +}; + +}; }; }; }; + +#endif diff --git a/offapi/com/sun/star/smarttags/XSmartTagRecognizer.idl b/offapi/com/sun/star/smarttags/XSmartTagRecognizer.idl index 1ab223bda958..4310a1747941 100644 --- a/offapi/com/sun/star/smarttags/XSmartTagRecognizer.idl +++ b/offapi/com/sun/star/smarttags/XSmartTagRecognizer.idl @@ -25,10 +25,10 @@ #include #include #include +#include #include #include - module com { module sun { module star { module smarttags { @@ -146,7 +146,6 @@ interface XSmartTagRecognizer: com::sun::star::lang::XInitialization [in] com::sun::star::frame::XController xController, [in] com::sun::star::i18n::XBreakIterator xTokenizer ); - /** indicates whether there is a property page for a smart tag type. @param nSmartTagIndex diff --git a/svx/source/smarttags/SmartTagMgr.cxx b/svx/source/smarttags/SmartTagMgr.cxx index ebd67334e16e..218406ca8138 100644 --- a/svx/source/smarttags/SmartTagMgr.cxx +++ b/svx/source/smarttags/SmartTagMgr.cxx @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -44,6 +45,8 @@ #include #include +#include + using namespace com::sun::star; using namespace com::sun::star::uno; using namespace com::sun::star::i18n; @@ -86,7 +89,7 @@ void SmartTagMgr::CreateBreakIterator() const /** Dispatches the recognize call to all installed smart tag recognizers */ -void SmartTagMgr::Recognize( const OUString& rText, +void SmartTagMgr::RecognizeString( const OUString& rText, const Reference< text::XTextMarkup > xMarkup, const Reference< frame::XController > xController, const lang::Locale& rLocale, @@ -118,6 +121,39 @@ void SmartTagMgr::Recognize( const OUString& rText, } } +void SmartTagMgr::RecognizeTextRange(const Reference< text::XTextRange> xRange, + const Reference< text::XTextMarkup > xMarkup, + const Reference< frame::XController > xController) const +{ + for ( sal_uInt32 i = 0; i < maRecognizerList.size(); i++ ) + { + Reference < smarttags::XSmartTagRecognizer > xRecognizer = maRecognizerList[i]; + + Reference< smarttags::XRangeBasedSmartTagRecognizer > xRangeBasedRecognizer = Reference< smarttags::XRangeBasedSmartTagRecognizer >( xRecognizer, UNO_QUERY); + + if (!xRangeBasedRecognizer.is()) continue; + + // if all smart tag types supported by this recognizer have been + // disabled, we do not have to call the recognizer: + bool bCallRecognizer = false; + const sal_uInt32 nSmartTagCount = xRecognizer->getSmartTagCount(); + for ( sal_uInt32 j = 0; j < nSmartTagCount && !bCallRecognizer; ++j ) + { + const rtl::OUString aSmartTagName = xRecognizer->getSmartTagName(j); + if ( IsSmartTagTypeEnabled( aSmartTagName ) ) + bCallRecognizer = true; + } + + if ( bCallRecognizer ) + { + xRangeBasedRecognizer->recognizeTextRange( xRange, + smarttags::SmartTagRecognizerMode_PARAGRAPH, + xMarkup, maApplicationName, xController); + } + } + +} + typedef std::multimap < OUString, ActionReference >::const_iterator SmartTagMapIter; void SmartTagMgr::GetActionSequences( Sequence < OUString >& rSmartTagTypes, diff --git a/sw/source/core/txtnode/txtedt.cxx b/sw/source/core/txtnode/txtedt.cxx index e1c282452d80..1716010a78f4 100644 --- a/sw/source/core/txtnode/txtedt.cxx +++ b/sw/source/core/txtnode/txtedt.cxx @@ -76,6 +76,8 @@ #include #include +#include + using namespace ::com::sun::star; using namespace ::com::sun::star::frame; using namespace ::com::sun::star::i18n; @@ -1424,6 +1426,13 @@ SwRect SwTxtFrm::SmartTagScan( SwCntntNode* /*pActNode*/, xub_StrLen /*nActPos*/ com::sun::star::uno::Reference< ::com::sun::star::frame::XController > xController = pNode->GetDoc()->GetDocShell()->GetController(); + SwPosition start(*pNode, nBegin); + SwPosition end (*pNode, nEnd); + Reference< ::com::sun::star::text::XTextRange > xRange = SwXTextRange::CreateXTextRange(*pNode->GetDoc(), start, &end); + + rSmartTagMgr.RecognizeTextRange(xRange, xTextMarkup, xController); + + xub_StrLen nLangBegin = nBegin; xub_StrLen nLangEnd = nEnd; @@ -1439,7 +1448,7 @@ SwRect SwTxtFrm::SmartTagScan( SwCntntNode* /*pActNode*/, xub_StrLen /*nActPos*/ const sal_uInt32 nExpandBegin = aConversionMap.ConvertToViewPosition( nLangBegin ); const sal_uInt32 nExpandEnd = aConversionMap.ConvertToViewPosition( nLangEnd ); - rSmartTagMgr.Recognize( aExpandText, xTextMarkup, xController, aLocale, nExpandBegin, nExpandEnd - nExpandBegin ); + rSmartTagMgr.RecognizeString(aExpandText, xTextMarkup, xController, aLocale, nExpandBegin, nExpandEnd - nExpandBegin ); nLangBegin = nLangEnd; } -- cgit