Kaydet (Commit) 1959113e authored tarafından Jürgen Schmidt's avatar Jürgen Schmidt Kaydeden (comit) Caolán McNamara

Resolves: #i121730# add optional interface XRangeBasedSmartTagRecognizer

for SmartTags

Patch by: Kai Labusch
Review by: arielch, jsc
(cherry picked from commit a64c066b)

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
üst 403bfea1
...@@ -42,6 +42,7 @@ namespace com { namespace sun { namespace star { namespace smarttags { ...@@ -42,6 +42,7 @@ namespace com { namespace sun { namespace star { namespace smarttags {
namespace com { namespace sun { namespace star { namespace text { namespace com { namespace sun { namespace star { namespace text {
class XTextMarkup; class XTextMarkup;
class XTextRange;
} } } } } } } }
namespace com { namespace sun { namespace star { namespace i18n { namespace com { namespace sun { namespace star { namespace i18n {
...@@ -149,12 +150,17 @@ public: ...@@ -149,12 +150,17 @@ public:
The length of the text to be scanned. 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::text::XTextMarkup > xMarkup,
const com::sun::star::uno::Reference< com::sun::star::frame::XController > xController, const com::sun::star::uno::Reference< com::sun::star::frame::XController > xController,
const com::sun::star::lang::Locale& rLocale, const com::sun::star::lang::Locale& rLocale,
sal_uInt32 nStart, sal_uInt32 nLen ) const; 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 /** Returns all action references associated with a given list of smart tag types
@param rSmartTagTypes @param rSmartTagTypes
......
...@@ -3534,6 +3534,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,offapi/com/sun/star/sheet,\ ...@@ -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,\ $(eval $(call gb_UnoApi_add_idlfiles,offapi,offapi/com/sun/star/smarttags,\
SmartTagRecognizerMode \ SmartTagRecognizerMode \
XRangeBasedSmartTagRecognizer \
XSmartTagAction \ XSmartTagAction \
XSmartTagRecognizer \ XSmartTagRecognizer \
)) ))
......
/*
* 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 <com/sun/star/lang/XInitialization.idl>
#include <com/sun/star/lang/Locale.idl>
#include <com/sun/star/smarttags/SmartTagRecognizerMode.idl>
#include <com/sun/star/text/XTextMarkup.idl>
#include <com/sun/star/frame/XController.idl>
#include <com/sun/star/lang/IndexOutOfBoundsException.idl>
#include <com/sun/star/text/XTextRange.idl>
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
...@@ -25,10 +25,10 @@ ...@@ -25,10 +25,10 @@
#include <com/sun/star/i18n/XBreakIterator.idl> #include <com/sun/star/i18n/XBreakIterator.idl>
#include <com/sun/star/smarttags/SmartTagRecognizerMode.idl> #include <com/sun/star/smarttags/SmartTagRecognizerMode.idl>
#include <com/sun/star/text/XTextMarkup.idl> #include <com/sun/star/text/XTextMarkup.idl>
#include <com/sun/star/text/XTextRange.idl>
#include <com/sun/star/frame/XController.idl> #include <com/sun/star/frame/XController.idl>
#include <com/sun/star/lang/IndexOutOfBoundsException.idl> #include <com/sun/star/lang/IndexOutOfBoundsException.idl>
module com { module sun { module star { module smarttags { module com { module sun { module star { module smarttags {
...@@ -146,7 +146,6 @@ interface XSmartTagRecognizer: com::sun::star::lang::XInitialization ...@@ -146,7 +146,6 @@ interface XSmartTagRecognizer: com::sun::star::lang::XInitialization
[in] com::sun::star::frame::XController xController, [in] com::sun::star::frame::XController xController,
[in] com::sun::star::i18n::XBreakIterator xTokenizer ); [in] com::sun::star::i18n::XBreakIterator xTokenizer );
/** indicates whether there is a property page for a smart tag type. /** indicates whether there is a property page for a smart tag type.
@param nSmartTagIndex @param nSmartTagIndex
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <osl/mutex.hxx> #include <osl/mutex.hxx>
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <com/sun/star/smarttags/XSmartTagRecognizer.hpp> #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/smarttags/XSmartTagAction.hpp>
#include <com/sun/star/deployment/ExtensionManager.hpp> #include <com/sun/star/deployment/ExtensionManager.hpp>
#include <com/sun/star/text/XTextMarkup.hpp> #include <com/sun/star/text/XTextMarkup.hpp>
...@@ -44,6 +45,8 @@ ...@@ -44,6 +45,8 @@
#include <comphelper/processfactory.hxx> #include <comphelper/processfactory.hxx>
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
#include <com/sun/star/text/XTextRange.hpp>
using namespace com::sun::star; using namespace com::sun::star;
using namespace com::sun::star::uno; using namespace com::sun::star::uno;
using namespace com::sun::star::i18n; using namespace com::sun::star::i18n;
...@@ -86,7 +89,7 @@ void SmartTagMgr::CreateBreakIterator() const ...@@ -86,7 +89,7 @@ void SmartTagMgr::CreateBreakIterator() const
/** Dispatches the recognize call to all installed smart tag recognizers /** 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< text::XTextMarkup > xMarkup,
const Reference< frame::XController > xController, const Reference< frame::XController > xController,
const lang::Locale& rLocale, const lang::Locale& rLocale,
...@@ -118,6 +121,39 @@ void SmartTagMgr::Recognize( const OUString& rText, ...@@ -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; typedef std::multimap < OUString, ActionReference >::const_iterator SmartTagMapIter;
void SmartTagMgr::GetActionSequences( Sequence < OUString >& rSmartTagTypes, void SmartTagMgr::GetActionSequences( Sequence < OUString >& rSmartTagTypes,
......
...@@ -76,6 +76,8 @@ ...@@ -76,6 +76,8 @@
#include <vector> #include <vector>
#include <utility> #include <utility>
#include <unotextrange.hxx>
using namespace ::com::sun::star; using namespace ::com::sun::star;
using namespace ::com::sun::star::frame; using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::i18n; using namespace ::com::sun::star::i18n;
...@@ -1424,6 +1426,13 @@ SwRect SwTxtFrm::SmartTagScan( SwCntntNode* /*pActNode*/, xub_StrLen /*nActPos*/ ...@@ -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(); 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 nLangBegin = nBegin;
xub_StrLen nLangEnd = nEnd; xub_StrLen nLangEnd = nEnd;
...@@ -1439,7 +1448,7 @@ SwRect SwTxtFrm::SmartTagScan( SwCntntNode* /*pActNode*/, xub_StrLen /*nActPos*/ ...@@ -1439,7 +1448,7 @@ SwRect SwTxtFrm::SmartTagScan( SwCntntNode* /*pActNode*/, xub_StrLen /*nActPos*/
const sal_uInt32 nExpandBegin = aConversionMap.ConvertToViewPosition( nLangBegin ); const sal_uInt32 nExpandBegin = aConversionMap.ConvertToViewPosition( nLangBegin );
const sal_uInt32 nExpandEnd = aConversionMap.ConvertToViewPosition( nLangEnd ); 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; 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