Files
libreoffice/sw/source/core/unocore/unotextmarkup.cxx

532 lines
18 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: Patches contributed by Oliver-Rainer Wittmann sw34bf06: #i117783# - Writer's implementation of XPagePrintable - apply print settings to new printing routines http://svn.apache.org/viewvc?view=revision&revision=1172115 sw34bf06: #o12311627# use <rtl_random> methods to create unique ids for list styles and list ids http://svn.apache.org/viewvc?view=revision&revision=1172112 sw34bf06 #i114725#,#i115828# - method <SwDoc::ClearDoc()> - clear list structures completely http://svn.apache.org/viewvc?view=revision&revision=1172122 i#118572 - remove ui string and help content regarding usage of Java Mail in Writer's Mail Merge as Java Mail is not used. http://svn.apache.org/viewvc?view=revision&revision=1197035 Patches contributed by Mathias Bauer cws mba34issues01: #i117718#: provide filter name in case storage of medium does not allow to detect one http://svn.apache.org/viewvc?view=revision&revision=1172350 cws mba34issues01: #i117721#: directly provide parameters retrieved from SfxMedium http://svn.apache.org/viewvc?view=revision&revision=1172353 gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 http://svn.apache.org/viewvc?view=revision&revision=1396797 http://svn.apache.org/viewvc?view=revision&revision=1397315 cws mba34issues01: #i117723#: convert assertion into trace http://svn.apache.org/viewvc?view=revision&revision=1172355 cws mba34issues01: #i117699#: keep layout alive until swdoc dies http://svn.apache.org/viewvc?view=revision&revision=1172362 cws mba34issues01: #i117943#: missing color attributes in RTF clipboard http://svn.apache.org/viewvc?view=revision&revision=1172363 Patch contributed by Henning Brinkmann imported patch i#103878 http://svn.apache.org/viewvc?view=revision&revision=1172109 Patches contributed by Michael Stahl sw34bf06: #i117955#: WW8 export: disable storing of section breaks in endnotes http://svn.apache.org/viewvc?view=revision&revision=1172119 Patch contributed by imacat Fixed the Asian language work count. http://svn.apache.org/viewvc?view=revision&revision=1241345 Patch contributed by Pedro Giffuni i#20878 - Add comment with BZ issue for reference. http://svn.apache.org/viewvc?view=revision&revision=1244517 Patch contributed by Andre Fischer Do not add targets for junit tests when junit is disabled. http://svn.apache.org/viewvc?view=revision&revision=1241508 add writerperfect dependency.
2011-03-31 10:05:04 +02:00
/*
* This file is part of the LibreOffice project.
*
re-base on ALv2 code. Includes: Patches contributed by Oliver-Rainer Wittmann sw34bf06: #i117783# - Writer's implementation of XPagePrintable - apply print settings to new printing routines http://svn.apache.org/viewvc?view=revision&revision=1172115 sw34bf06: #o12311627# use <rtl_random> methods to create unique ids for list styles and list ids http://svn.apache.org/viewvc?view=revision&revision=1172112 sw34bf06 #i114725#,#i115828# - method <SwDoc::ClearDoc()> - clear list structures completely http://svn.apache.org/viewvc?view=revision&revision=1172122 i#118572 - remove ui string and help content regarding usage of Java Mail in Writer's Mail Merge as Java Mail is not used. http://svn.apache.org/viewvc?view=revision&revision=1197035 Patches contributed by Mathias Bauer cws mba34issues01: #i117718#: provide filter name in case storage of medium does not allow to detect one http://svn.apache.org/viewvc?view=revision&revision=1172350 cws mba34issues01: #i117721#: directly provide parameters retrieved from SfxMedium http://svn.apache.org/viewvc?view=revision&revision=1172353 gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 http://svn.apache.org/viewvc?view=revision&revision=1396797 http://svn.apache.org/viewvc?view=revision&revision=1397315 cws mba34issues01: #i117723#: convert assertion into trace http://svn.apache.org/viewvc?view=revision&revision=1172355 cws mba34issues01: #i117699#: keep layout alive until swdoc dies http://svn.apache.org/viewvc?view=revision&revision=1172362 cws mba34issues01: #i117943#: missing color attributes in RTF clipboard http://svn.apache.org/viewvc?view=revision&revision=1172363 Patch contributed by Henning Brinkmann imported patch i#103878 http://svn.apache.org/viewvc?view=revision&revision=1172109 Patches contributed by Michael Stahl sw34bf06: #i117955#: WW8 export: disable storing of section breaks in endnotes http://svn.apache.org/viewvc?view=revision&revision=1172119 Patch contributed by imacat Fixed the Asian language work count. http://svn.apache.org/viewvc?view=revision&revision=1241345 Patch contributed by Pedro Giffuni i#20878 - Add comment with BZ issue for reference. http://svn.apache.org/viewvc?view=revision&revision=1244517 Patch contributed by Andre Fischer Do not add targets for junit tests when junit is disabled. http://svn.apache.org/viewvc?view=revision&revision=1241508 add writerperfect dependency.
2011-03-31 10:05:04 +02:00
* 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/.
*
re-base on ALv2 code. Includes: Patches contributed by Oliver-Rainer Wittmann sw34bf06: #i117783# - Writer's implementation of XPagePrintable - apply print settings to new printing routines http://svn.apache.org/viewvc?view=revision&revision=1172115 sw34bf06: #o12311627# use <rtl_random> methods to create unique ids for list styles and list ids http://svn.apache.org/viewvc?view=revision&revision=1172112 sw34bf06 #i114725#,#i115828# - method <SwDoc::ClearDoc()> - clear list structures completely http://svn.apache.org/viewvc?view=revision&revision=1172122 i#118572 - remove ui string and help content regarding usage of Java Mail in Writer's Mail Merge as Java Mail is not used. http://svn.apache.org/viewvc?view=revision&revision=1197035 Patches contributed by Mathias Bauer cws mba34issues01: #i117718#: provide filter name in case storage of medium does not allow to detect one http://svn.apache.org/viewvc?view=revision&revision=1172350 cws mba34issues01: #i117721#: directly provide parameters retrieved from SfxMedium http://svn.apache.org/viewvc?view=revision&revision=1172353 gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 http://svn.apache.org/viewvc?view=revision&revision=1396797 http://svn.apache.org/viewvc?view=revision&revision=1397315 cws mba34issues01: #i117723#: convert assertion into trace http://svn.apache.org/viewvc?view=revision&revision=1172355 cws mba34issues01: #i117699#: keep layout alive until swdoc dies http://svn.apache.org/viewvc?view=revision&revision=1172362 cws mba34issues01: #i117943#: missing color attributes in RTF clipboard http://svn.apache.org/viewvc?view=revision&revision=1172363 Patch contributed by Henning Brinkmann imported patch i#103878 http://svn.apache.org/viewvc?view=revision&revision=1172109 Patches contributed by Michael Stahl sw34bf06: #i117955#: WW8 export: disable storing of section breaks in endnotes http://svn.apache.org/viewvc?view=revision&revision=1172119 Patch contributed by imacat Fixed the Asian language work count. http://svn.apache.org/viewvc?view=revision&revision=1241345 Patch contributed by Pedro Giffuni i#20878 - Add comment with BZ issue for reference. http://svn.apache.org/viewvc?view=revision&revision=1244517 Patch contributed by Andre Fischer Do not add targets for junit tests when junit is disabled. http://svn.apache.org/viewvc?view=revision&revision=1241508 add writerperfect dependency.
2011-03-31 10:05:04 +02:00
* This file incorporates work covered by the following license notice:
*
re-base on ALv2 code. Includes: Patches contributed by Oliver-Rainer Wittmann sw34bf06: #i117783# - Writer's implementation of XPagePrintable - apply print settings to new printing routines http://svn.apache.org/viewvc?view=revision&revision=1172115 sw34bf06: #o12311627# use <rtl_random> methods to create unique ids for list styles and list ids http://svn.apache.org/viewvc?view=revision&revision=1172112 sw34bf06 #i114725#,#i115828# - method <SwDoc::ClearDoc()> - clear list structures completely http://svn.apache.org/viewvc?view=revision&revision=1172122 i#118572 - remove ui string and help content regarding usage of Java Mail in Writer's Mail Merge as Java Mail is not used. http://svn.apache.org/viewvc?view=revision&revision=1197035 Patches contributed by Mathias Bauer cws mba34issues01: #i117718#: provide filter name in case storage of medium does not allow to detect one http://svn.apache.org/viewvc?view=revision&revision=1172350 cws mba34issues01: #i117721#: directly provide parameters retrieved from SfxMedium http://svn.apache.org/viewvc?view=revision&revision=1172353 gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 http://svn.apache.org/viewvc?view=revision&revision=1396797 http://svn.apache.org/viewvc?view=revision&revision=1397315 cws mba34issues01: #i117723#: convert assertion into trace http://svn.apache.org/viewvc?view=revision&revision=1172355 cws mba34issues01: #i117699#: keep layout alive until swdoc dies http://svn.apache.org/viewvc?view=revision&revision=1172362 cws mba34issues01: #i117943#: missing color attributes in RTF clipboard http://svn.apache.org/viewvc?view=revision&revision=1172363 Patch contributed by Henning Brinkmann imported patch i#103878 http://svn.apache.org/viewvc?view=revision&revision=1172109 Patches contributed by Michael Stahl sw34bf06: #i117955#: WW8 export: disable storing of section breaks in endnotes http://svn.apache.org/viewvc?view=revision&revision=1172119 Patch contributed by imacat Fixed the Asian language work count. http://svn.apache.org/viewvc?view=revision&revision=1241345 Patch contributed by Pedro Giffuni i#20878 - Add comment with BZ issue for reference. http://svn.apache.org/viewvc?view=revision&revision=1244517 Patch contributed by Andre Fischer Do not add targets for junit tests when junit is disabled. http://svn.apache.org/viewvc?view=revision&revision=1241508 add writerperfect dependency.
2011-03-31 10:05:04 +02:00
* 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 .
*/
#include <unotextmarkup.hxx>
#include <osl/mutex.hxx>
#include <vcl/svapp.hxx>
#include <SwSmartTagMgr.hxx>
#include <com/sun/star/text/TextMarkupType.hpp>
2008-12-15 12:01:46 +00:00
#include <com/sun/star/text/TextMarkupDescriptor.hpp>
#include <com/sun/star/container/XStringKeyMap.hpp>
#include <ndtxt.hxx>
#include <SwGrammarMarkUp.hxx>
#include <IGrammarContact.hxx>
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <com/sun/star/text/XTextRange.hpp>
#include <pam.hxx>
#include <unotextrange.hxx>
#include <unotextcursor.hxx>
using namespace ::com::sun::star;
/*
* SwXTextMarkup
*/
SwXTextMarkup::SwXTextMarkup( SwTxtNode& rTxtNode, const ModelToViewHelper& rMap )
: mpTxtNode( &rTxtNode ), maConversionMap( rMap )
{
// FME 2007-07-16 #i79641# SwXTextMarkup is allowed to be removed ...
SetIsAllowedToBeRemovedInModifyCall(true);
mpTxtNode->Add(this);
}
SwXTextMarkup::~SwXTextMarkup()
{
}
uno::Reference< container::XStringKeyMap > SAL_CALL SwXTextMarkup::getMarkupInfoContainer() throw (uno::RuntimeException)
{
SolarMutexGuard aGuard;
uno::Reference< container::XStringKeyMap > xProp = new SwXStringKeyMap;
return xProp;
}
void SAL_CALL SwXTextMarkup::commitTextRangeMarkup(::sal_Int32 nType, const ::rtl::OUString & aIdentifier, const uno::Reference< text::XTextRange> & xRange,
const uno::Reference< container::XStringKeyMap > & xMarkupInfoContainer) throw (uno::RuntimeException)
{
SolarMutexGuard aGuard;
uno::Reference<lang::XUnoTunnel> xRangeTunnel( xRange, uno::UNO_QUERY);
if(!xRangeTunnel.is()) return;
SwXTextRange* pRange = 0;
OTextCursorHelper* pCursor = 0;
if(xRangeTunnel.is())
{
pRange = reinterpret_cast<SwXTextRange*>( sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething(SwXTextRange::getUnoTunnelId())));
pCursor = reinterpret_cast<OTextCursorHelper*>( sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething(OTextCursorHelper::getUnoTunnelId())));
}
if (pRange)
{
SwDoc* pDoc = reinterpret_cast<SwDoc*>(pRange->GetDoc());
if (!pDoc) return;
SwUnoInternalPaM aPam(*pDoc);
::sw::XTextRangeToSwPaM(aPam, xRange);
SwPosition* startPos = aPam.Start();
SwPosition* endPos = aPam.End();
commitStringMarkup (nType, aIdentifier, startPos->nContent.GetIndex(), endPos->nContent.GetIndex() - startPos->nContent.GetIndex(), xMarkupInfoContainer);
}
else if (pCursor)
{
SwPaM aPam(*pCursor->GetPaM());
SwPosition* startPos = aPam.Start();
SwPosition* endPos = aPam.End();
commitStringMarkup (nType, aIdentifier, startPos->nContent.GetIndex(), endPos->nContent.GetIndex() - startPos->nContent.GetIndex(), xMarkupInfoContainer);
}
}
void SAL_CALL SwXTextMarkup::commitStringMarkup(
::sal_Int32 nType,
const OUString & rIdentifier,
::sal_Int32 nStart,
::sal_Int32 nLength,
const uno::Reference< container::XStringKeyMap > & xMarkupInfoContainer)
throw (uno::RuntimeException)
{
SolarMutexGuard aGuard;
// paragraph already dead or modified?
if ( !mpTxtNode || nLength <= 0 )
return;
if ( nType == text::TextMarkupType::SMARTTAG &&
!SwSmartTagMgr::Get().IsSmartTagTypeEnabled( rIdentifier ) )
return;
// get appropriate list to use...
SwWrongList* pWList = 0;
bool bRepaint = false;
if ( nType == text::TextMarkupType::SPELLCHECK )
{
pWList = mpTxtNode->GetWrong();
if ( !pWList )
{
pWList = new SwWrongList( WRONGLIST_SPELL );
mpTxtNode->SetWrong( pWList );
}
}
2008-12-15 12:01:46 +00:00
else if ( nType == text::TextMarkupType::PROOFREADING || nType == text::TextMarkupType::SENTENCE )
{
IGrammarContact *pGrammarContact = getGrammarContact( *mpTxtNode );
if( pGrammarContact )
{
pWList = pGrammarContact->getGrammarCheck( *mpTxtNode, true );
OSL_ENSURE( pWList, "GrammarContact _has_ to deliver a wrong list" );
}
else
{
pWList = mpTxtNode->GetGrammarCheck();
if ( !pWList )
{
mpTxtNode->SetGrammarCheck( new SwGrammarMarkUp() );
pWList = mpTxtNode->GetGrammarCheck();
}
}
bRepaint = pWList == mpTxtNode->GetGrammarCheck();
if( pWList->GetBeginInv() < STRING_LEN )
((SwGrammarMarkUp*)pWList)->ClearGrammarList();
}
else if ( nType == text::TextMarkupType::SMARTTAG )
{
pWList = mpTxtNode->GetSmartTags();
if ( !pWList )
{
pWList = new SwWrongList( WRONGLIST_SMARTTAG );
mpTxtNode->SetSmartTags( pWList );
}
}
else
{
OSL_FAIL( "Unknown mark-up type" );
return;
}
const ModelToViewHelper::ModelPosition aStartPos =
maConversionMap.ConvertToModelPosition( nStart );
const ModelToViewHelper::ModelPosition aEndPos =
maConversionMap.ConvertToModelPosition( nStart + nLength - 1);
const bool bStartInField = aStartPos.mbIsField;
const bool bEndInField = aEndPos.mbIsField;
bool bCommit = false;
if ( bStartInField && bEndInField && aStartPos.mnPos == aEndPos.mnPos )
{
nStart = aStartPos.mnSubPos;
const xub_StrLen nFieldPosModel = static_cast< xub_StrLen >(aStartPos.mnPos);
const sal_uInt16 nInsertPos = pWList->GetWrongPos( nFieldPosModel );
SwWrongList* pSubList = pWList->SubList( nInsertPos );
if ( !pSubList )
{
2008-12-15 12:01:46 +00:00
if( nType == text::TextMarkupType::PROOFREADING || nType == text::TextMarkupType::SENTENCE )
pSubList = new SwGrammarMarkUp();
else
pSubList = new SwWrongList( pWList->GetWrongListType() );
pWList->InsertSubList( nFieldPosModel, 1, nInsertPos, pSubList );
}
pWList = pSubList;
bCommit = true;
}
else if ( !bStartInField && !bEndInField )
{
nStart = aStartPos.mnPos;
bCommit = true;
nLength = aEndPos.mnPos + 1 - aStartPos.mnPos;
}
2008-12-15 12:01:46 +00:00
else if( nType == text::TextMarkupType::PROOFREADING || nType == text::TextMarkupType::SENTENCE )
{
bCommit = true;
nStart = aStartPos.mnPos;
sal_Int32 nEnd = aEndPos.mnPos;
if( bStartInField && nType != text::TextMarkupType::SENTENCE )
{
const xub_StrLen nFieldPosModel = static_cast< xub_StrLen >(aStartPos.mnPos);
const sal_uInt16 nInsertPos = pWList->GetWrongPos( nFieldPosModel );
SwWrongList* pSubList = pWList->SubList( nInsertPos );
if ( !pSubList )
{
pSubList = new SwGrammarMarkUp();
pWList->InsertSubList( nFieldPosModel, 1, nInsertPos, pSubList );
}
const sal_Int32 nTmpStart = maConversionMap.ConvertToViewPosition( aStartPos.mnPos );
const sal_Int32 nTmpLen = maConversionMap.ConvertToViewPosition( aStartPos.mnPos + 1 )
- nTmpStart - aStartPos.mnSubPos;
if( nTmpLen > 0 )
{
if( nType == text::TextMarkupType::SENTENCE )
{
((SwGrammarMarkUp*)pSubList)->setSentence( static_cast< xub_StrLen >(aStartPos.mnSubPos) );
bCommit = false;
}
else
pSubList->Insert( rIdentifier, xMarkupInfoContainer,
static_cast< xub_StrLen >(aStartPos.mnSubPos), static_cast< xub_StrLen >(nTmpLen) );
}
++nStart;
}
if( bEndInField && nType != text::TextMarkupType::SENTENCE )
{
const xub_StrLen nFieldPosModel = static_cast< xub_StrLen >(aEndPos.mnPos);
const sal_uInt16 nInsertPos = pWList->GetWrongPos( nFieldPosModel );
SwWrongList* pSubList = pWList->SubList( nInsertPos );
if ( !pSubList )
{
pSubList = new SwGrammarMarkUp();
pWList->InsertSubList( nFieldPosModel, 1, nInsertPos, pSubList );
}
const sal_Int32 nTmpLen = aEndPos.mnSubPos + 1;
pSubList->Insert( rIdentifier, xMarkupInfoContainer, 0, static_cast< xub_StrLen >(nTmpLen) );
}
else
++nEnd;
if( nEnd > nStart )
nLength = nEnd - nStart;
else
bCommit = false;
}
if ( bCommit )
{
if( nType == text::TextMarkupType::SENTENCE )
((SwGrammarMarkUp*)pWList)->setSentence( static_cast< xub_StrLen >(nStart) );
else
pWList->Insert( rIdentifier, xMarkupInfoContainer,
static_cast< xub_StrLen >(nStart), static_cast< xub_StrLen >(nLength) );
}
if( bRepaint )
finishGrammarCheck( *mpTxtNode );
}
2008-12-15 12:01:46 +00:00
static void lcl_commitGrammarMarkUp(
const ModelToViewHelper& rConversionMap,
2008-12-15 12:01:46 +00:00
SwGrammarMarkUp* pWList,
::sal_Int32 nType,
const OUString & rIdentifier,
2008-12-15 12:01:46 +00:00
::sal_Int32 nStart,
::sal_Int32 nLength,
const uno::Reference< container::XStringKeyMap > & xMarkupInfoContainer)
{
OSL_ENSURE( nType == text::TextMarkupType::PROOFREADING || nType == text::TextMarkupType::SENTENCE, "Wrong mark-up type" );
2008-12-15 12:01:46 +00:00
const ModelToViewHelper::ModelPosition aStartPos =
rConversionMap.ConvertToModelPosition( nStart );
2008-12-15 12:01:46 +00:00
const ModelToViewHelper::ModelPosition aEndPos =
rConversionMap.ConvertToModelPosition( nStart + nLength - 1);
2008-12-15 12:01:46 +00:00
const bool bStartInField = aStartPos.mbIsField;
const bool bEndInField = aEndPos.mbIsField;
bool bCommit = false;
if ( bStartInField && bEndInField && aStartPos.mnPos == aEndPos.mnPos )
{
nStart = aStartPos.mnSubPos;
const xub_StrLen nFieldPosModel = static_cast< xub_StrLen >(aStartPos.mnPos);
const sal_uInt16 nInsertPos = pWList->GetWrongPos( nFieldPosModel );
2008-12-15 12:01:46 +00:00
SwGrammarMarkUp* pSubList = (SwGrammarMarkUp*)pWList->SubList( nInsertPos );
if ( !pSubList )
{
pSubList = new SwGrammarMarkUp();
pWList->InsertSubList( nFieldPosModel, 1, nInsertPos, pSubList );
}
pWList = pSubList;
bCommit = true;
}
else if ( !bStartInField && !bEndInField )
{
nStart = aStartPos.mnPos;
bCommit = true;
nLength = aEndPos.mnPos + 1 - aStartPos.mnPos;
}
else
{
bCommit = true;
nStart = aStartPos.mnPos;
sal_Int32 nEnd = aEndPos.mnPos;
if( bStartInField && nType != text::TextMarkupType::SENTENCE )
{
const xub_StrLen nFieldPosModel = static_cast< xub_StrLen >(aStartPos.mnPos);
const sal_uInt16 nInsertPos = pWList->GetWrongPos( nFieldPosModel );
2008-12-15 12:01:46 +00:00
SwGrammarMarkUp* pSubList = (SwGrammarMarkUp*)pWList->SubList( nInsertPos );
if ( !pSubList )
{
pSubList = new SwGrammarMarkUp();
pWList->InsertSubList( nFieldPosModel, 1, nInsertPos, pSubList );
}
const sal_Int32 nTmpStart = rConversionMap.ConvertToViewPosition( aStartPos.mnPos );
const sal_Int32 nTmpLen = rConversionMap.ConvertToViewPosition( aStartPos.mnPos + 1 )
2008-12-15 12:01:46 +00:00
- nTmpStart - aStartPos.mnSubPos;
if( nTmpLen > 0 )
pSubList->Insert( rIdentifier, xMarkupInfoContainer,
static_cast< xub_StrLen >(aStartPos.mnSubPos), static_cast< xub_StrLen >(nTmpLen) );
++nStart;
}
if( bEndInField && nType != text::TextMarkupType::SENTENCE )
{
const xub_StrLen nFieldPosModel = static_cast< xub_StrLen >(aEndPos.mnPos);
const sal_uInt16 nInsertPos = pWList->GetWrongPos( nFieldPosModel );
2008-12-15 12:01:46 +00:00
SwGrammarMarkUp* pSubList = (SwGrammarMarkUp*)pWList->SubList( nInsertPos );
if ( !pSubList )
{
pSubList = new SwGrammarMarkUp();
pWList->InsertSubList( nFieldPosModel, 1, nInsertPos, pSubList );
}
const sal_Int32 nTmpLen = aEndPos.mnSubPos + 1;
2008-12-15 12:01:46 +00:00
pSubList->Insert( rIdentifier, xMarkupInfoContainer, 0, static_cast< xub_StrLen >(nTmpLen) );
}
else
++nEnd;
if( nEnd > nStart )
nLength = nEnd - nStart;
else
bCommit = false;
}
if ( bCommit )
{
if( nType == text::TextMarkupType::SENTENCE )
((SwGrammarMarkUp*)pWList)->setSentence( static_cast< xub_StrLen >(nStart+nLength) );
else
pWList->Insert( rIdentifier, xMarkupInfoContainer,
static_cast< xub_StrLen >(nStart), static_cast< xub_StrLen >(nLength) );
}
}
void SAL_CALL SwXTextMarkup::commitMultiTextMarkup(
const uno::Sequence< text::TextMarkupDescriptor > &rMarkups )
throw (lang::IllegalArgumentException, uno::RuntimeException)
{
SolarMutexGuard aGuard;
2008-12-15 12:01:46 +00:00
// paragraph already dead or modified?
if ( !mpTxtNode )
return;
// check for equal length of all sequnces
sal_Int32 nLen = rMarkups.getLength();
// for grammar checking there should be exactly one sentence markup
// and 0..n grammar markups.
// Different markups are not expected but may be applied anyway since
// that should be no problem...
// but it has to be implemented, at the moment only this function is for
// grammar markups and sentence markup only!
sal_Int32 nSentenceMarkUpIndex = -1;
const text::TextMarkupDescriptor *pMarkups = rMarkups.getConstArray();
sal_Int32 i;
for( i = 0; i < nLen; ++i )
{
if (pMarkups[i].nType == text::TextMarkupType::SENTENCE)
{
if (nSentenceMarkUpIndex == -1)
nSentenceMarkUpIndex = i;
else // there is already one sentence markup
throw lang::IllegalArgumentException();
}
else if( pMarkups[i].nType != text::TextMarkupType::PROOFREADING )
return;
}
if( nSentenceMarkUpIndex == -1 )
return;
// get appropriate list to use...
SwGrammarMarkUp* pWList = 0;
bool bRepaint = false;
IGrammarContact *pGrammarContact = getGrammarContact( *mpTxtNode );
if( pGrammarContact )
{
pWList = pGrammarContact->getGrammarCheck( *mpTxtNode, true );
OSL_ENSURE( pWList, "GrammarContact _has_ to deliver a wrong list" );
2008-12-15 12:01:46 +00:00
}
else
{
pWList = mpTxtNode->GetGrammarCheck();
if ( !pWList )
{
mpTxtNode->SetGrammarCheck( new SwGrammarMarkUp() );
pWList = mpTxtNode->GetGrammarCheck();
pWList->SetInvalid( 0, STRING_LEN );
}
}
bRepaint = pWList == mpTxtNode->GetGrammarCheck();
bool bAcceptGrammarError = false;
if( pWList->GetBeginInv() < STRING_LEN )
{
const ModelToViewHelper::ModelPosition aSentenceEnd =
maConversionMap.ConvertToModelPosition(
2008-12-15 12:01:46 +00:00
pMarkups[nSentenceMarkUpIndex].nOffset + pMarkups[nSentenceMarkUpIndex].nLength );
bAcceptGrammarError = (xub_StrLen)aSentenceEnd.mnPos > pWList->GetBeginInv();
pWList->ClearGrammarList( (xub_StrLen)aSentenceEnd.mnPos );
}
if( bAcceptGrammarError )
{
for( i = 0; i < nLen; ++i )
{
const text::TextMarkupDescriptor &rDesc = pMarkups[i];
lcl_commitGrammarMarkUp( maConversionMap, pWList, rDesc.nType,
2008-12-15 12:01:46 +00:00
rDesc.aIdentifier, rDesc.nOffset, rDesc.nLength, rDesc.xMarkupInfoContainer );
}
}
else
{
bRepaint = false;
i = nSentenceMarkUpIndex;
const text::TextMarkupDescriptor &rDesc = pMarkups[i];
lcl_commitGrammarMarkUp( maConversionMap, pWList, rDesc.nType,
2008-12-15 12:01:46 +00:00
rDesc.aIdentifier, rDesc.nOffset, rDesc.nLength, rDesc.xMarkupInfoContainer );
}
if( bRepaint )
finishGrammarCheck( *mpTxtNode );
return;
}
void SwXTextMarkup::Modify( const SfxPoolItem* /*pOld*/, const SfxPoolItem* /*pNew*/ )
{
// FME 2007-07-16 #i79641# In my opinion this is perfectly legal,
// therefore I remove the assertion in SwModify::_Remove()
if ( GetRegisteredIn() )
GetRegisteredInNonConst()->Remove( this );
SolarMutexGuard aGuard;
mpTxtNode = 0;
}
/*
* SwXStringKeyMap
*/
SwXStringKeyMap::SwXStringKeyMap()
{
}
uno::Any SAL_CALL SwXStringKeyMap::getValue(const OUString & aKey) throw (uno::RuntimeException, container::NoSuchElementException)
{
std::map< OUString, uno::Any >::const_iterator aIter = maMap.find( aKey );
if ( aIter == maMap.end() )
throw container::NoSuchElementException();
return (*aIter).second;
}
::sal_Bool SAL_CALL SwXStringKeyMap::hasValue(const OUString & aKey) throw (uno::RuntimeException)
{
return maMap.find( aKey ) != maMap.end();
}
void SAL_CALL SwXStringKeyMap::insertValue(const OUString & aKey, const uno::Any & aValue) throw (uno::RuntimeException, lang::IllegalArgumentException, container::ElementExistException)
{
std::map< OUString, uno::Any >::const_iterator aIter = maMap.find( aKey );
if ( aIter != maMap.end() )
throw container::ElementExistException();
maMap[ aKey ] = aValue;
}
::sal_Int32 SAL_CALL SwXStringKeyMap::getCount() throw (uno::RuntimeException)
{
return maMap.size();
}
OUString SAL_CALL SwXStringKeyMap::getKeyByIndex(::sal_Int32 nIndex) throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
{
if ( (sal_uInt32)nIndex >= maMap.size() )
throw lang::IndexOutOfBoundsException();
return OUString();
}
uno::Any SAL_CALL SwXStringKeyMap::getValueByIndex(::sal_Int32 nIndex) throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
{
if ( (sal_uInt32)nIndex >= maMap.size() )
throw lang::IndexOutOfBoundsException();
return uno::Any();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */