Kaydet (Commit) a64c066b authored tarafından Jürgen Schmidt's avatar Jürgen Schmidt

#121730# add new optional interface XRangeBasedSmartTagRecognizer for SmartTags

Patch by: Kai Labusch
Review by: arielch, jsc
üst bc3d9d8e
/**************************************************************
*
* 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
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*************************************************************/
#ifndef __com_sun_star_smarttags_XRangeBasedSmartTagRecognizer_idl__
#define __com_sun_star_smarttags_XRangeBasedSmartTagRecognizer_idl__
#ifndef __com_sun_star_uno_XInitialization_idl__
#include <com/sun/star/lang/XInitialization.idl>
#endif
#ifndef __com_sun_star_lang_Locale_idl__
#include <com/sun/star/lang/Locale.idl>
#endif
#ifndef __com_sun_star_smarttags_SmartTagRecognizerMode_idl__
#include <com/sun/star/smarttags/SmartTagRecognizerMode.idl>
#endif
#ifndef __com_sun_star_text_XTextMarkup_idl__
#include <com/sun/star/text/XTextMarkup.idl>
#endif
#ifndef __com_sun_star_frame_XController_idl__
#include <com/sun/star/frame/XController.idl>
#endif
#ifndef __com_sun_star_lang_IndexOutOfBoundsException_idl__
#include <com/sun/star/lang/IndexOutOfBoundsException.idl>
#endif
#ifndef __com_sun_star_text_XTextRange_idl__
#include <com/sun/star/text/XTextRange.idl>
#endif
//=============================================================================
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
......@@ -52,6 +52,11 @@
#include <com/sun/star/lang/IndexOutOfBoundsException.idl>
#endif
#ifndef __com_sun_star_text_XTextRange_idl__
#include <com/sun/star/text/XTextRange.idl>
#endif
//=============================================================================
module com { module sun { module star { module smarttags {
......@@ -178,7 +183,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.
......
......@@ -37,6 +37,7 @@ IDLFILES=\
SmartTagAction.idl\
SmartTagRecognizer.idl\
SmartTagRecognizerMode.idl\
XRangeBasedSmartTagRecognizer.idl\
XSmartTagAction.idl\
XSmartTagRecognizer.idl
......
......@@ -46,6 +46,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 {
......@@ -155,12 +156,17 @@ public:
The length of the text to be scanned.
*/
void Recognize( const rtl::OUString& rText,
void RecognizeString( const rtl::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
......
......@@ -30,6 +30,7 @@
#include <vos/mutex.hxx>
#include <vcl/svapp.hxx>
#include <com/sun/star/smarttags/XSmartTagRecognizer.hpp>
#include <com/sun/star/smarttags/XRangeBasedSmartTagRecognizer.hpp>
#include <com/sun/star/smarttags/XSmartTagAction.hpp>
#include <com/sun/star/deployment/ExtensionManager.hpp>
#include <com/sun/star/text/XTextMarkup.hpp>
......@@ -50,6 +51,8 @@
#include <rtl/ustring.hxx>
#include <tools/string.hxx>
#include <com/sun/star/text/XTextRange.hpp>
using namespace com::sun::star;
using namespace com::sun::star::uno;
......@@ -100,7 +103,7 @@ void SmartTagMgr::CreateBreakIterator() const
/** Dispatches the recognize call to all installed smart tag recognizers
*/
void SmartTagMgr::Recognize( const rtl::OUString& rText,
void SmartTagMgr::RecognizeString( const rtl::OUString& rText,
const Reference< text::XTextMarkup > xMarkup,
const Reference< frame::XController > xController,
const lang::Locale& rLocale,
......@@ -132,6 +135,40 @@ void SmartTagMgr::Recognize( const rtl::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 < rtl::OUString, ActionReference >::const_iterator SmartTagMapIter;
void SmartTagMgr::GetActionSequences( Sequence < rtl::OUString >& rSmartTagTypes,
......
......@@ -88,6 +88,7 @@
#include <vector>
#include <unotextrange.hxx>
using rtl::OUString;
using namespace ::com::sun::star;
......@@ -1352,7 +1353,14 @@ SwRect SwTxtFrm::SmartTagScan( SwCntntNode* /*pActNode*/, xub_StrLen /*nActPos*/
Reference< ::com::sun::star::frame::XController > xController = pNode->GetDoc()->GetDocShell()->GetController();
xub_StrLen nLangBegin = nBegin;
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;
// smart tag recognization has to be done for each language portion:
......@@ -1367,7 +1375,7 @@ SwRect SwTxtFrm::SmartTagScan( SwCntntNode* /*pActNode*/, xub_StrLen /*nActPos*/
const sal_uInt32 nExpandBegin = ModelToViewHelper::ConvertToViewPosition( pConversionMap, nLangBegin );
const sal_uInt32 nExpandEnd = ModelToViewHelper::ConvertToViewPosition( pConversionMap, nLangEnd );
rSmartTagMgr.Recognize( aExpandText, xTextMarkup, xController, aLocale, nExpandBegin, nExpandEnd - nExpandBegin );
rSmartTagMgr.RecognizeString(aExpandText, xTextMarkup, xController, aLocale, nExpandBegin, nExpandEnd - nExpandBegin );
nLangBegin = nLangEnd;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment