Files
libreoffice/sw/source/core/doc/extinput.cxx

289 lines
9.6 KiB
C++
Raw Normal View History

2000-09-18 23:08:29 +00:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2000-09-18 23:08:29 +00:00
*
* Copyright 2008 by Sun Microsystems, Inc.
2000-09-18 23:08:29 +00:00
*
* OpenOffice.org - a multi-platform office productivity suite
2000-09-18 23:08:29 +00:00
*
* $RCSfile: extinput.cxx,v $
* $Revision: 1.16 $
2000-09-18 23:08:29 +00:00
*
* This file is part of OpenOffice.org.
2000-09-18 23:08:29 +00:00
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
2000-09-18 23:08:29 +00:00
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
2000-09-18 23:08:29 +00:00
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
2000-09-18 23:08:29 +00:00
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sw.hxx"
2000-09-18 23:08:29 +00:00
#include <hintids.hxx>
#include <vcl/keycodes.hxx>
#include <vcl/cmdevt.hxx>
#include <extinput.hxx>
#include <doc.hxx>
#include <index.hxx>
#include <ndtxt.hxx>
#include <txtfrm.hxx>
#include <swundo.hxx>
#include <svx/langitem.hxx>
#include <svx/scripttypeitem.hxx>
#include <com/sun/star/i18n/ScriptType.hpp>
2000-09-18 23:08:29 +00:00
using namespace ::com::sun::star;
2000-09-18 23:08:29 +00:00
SwExtTextInput::SwExtTextInput( const SwPaM& rPam, Ring* pRing )
: SwPaM( *rPam.GetPoint(), (SwPaM*)pRing ),
eInputLanguage(LANGUAGE_DONTKNOW)
2000-09-18 23:08:29 +00:00
{
2000-11-28 17:49:16 +00:00
bIsOverwriteCursor = FALSE;
bInsText = TRUE;
2000-09-18 23:08:29 +00:00
}
SwExtTextInput::~SwExtTextInput()
{
SwTxtNode* pTNd = GetPoint()->nNode.GetNode().GetTxtNode();
if( pTNd )
{
SwIndex& rIdx = GetPoint()->nContent;
xub_StrLen nSttCnt = rIdx.GetIndex(),
nEndCnt = GetMark()->nContent.GetIndex();
2000-09-18 23:08:29 +00:00
if( nEndCnt != nSttCnt )
{
if( nEndCnt < nSttCnt )
{
xub_StrLen n = nEndCnt; nEndCnt = nSttCnt; nSttCnt = n;
}
// damit Undo / Redlining usw. richtig funktioniert,
// muss ueber die Doc-Schnittstellen gegangen werden !!!
SwDoc* pDoc = GetDoc();
if(eInputLanguage != LANGUAGE_DONTKNOW)
{
// --> FME 2005-02-11 #i41974# Only set language attribute
// for CJK/CTL scripts.
bool bLang = true;
// <--
USHORT nWhich = RES_CHRATR_LANGUAGE;
switch(GetI18NScriptTypeOfLanguage(eInputLanguage))
{
case i18n::ScriptType::ASIAN: nWhich = RES_CHRATR_CJK_LANGUAGE; break;
case i18n::ScriptType::COMPLEX: nWhich = RES_CHRATR_CTL_LANGUAGE; break;
default: bLang = false;
}
if ( bLang )
{
SvxLanguageItem aLangItem( eInputLanguage, nWhich );
pDoc->Insert(*this, aLangItem, 0 );
}
}
rIdx = nSttCnt;
2000-09-18 23:08:29 +00:00
String sTxt( pTNd->GetTxt().Copy( nSttCnt, nEndCnt - nSttCnt ));
if( bIsOverwriteCursor && sOverwriteText.Len() )
{
xub_StrLen nLen = sTxt.Len();
if( nLen > sOverwriteText.Len() )
{
rIdx += sOverwriteText.Len();
pTNd->Erase( rIdx, nLen - sOverwriteText.Len() );
rIdx = nSttCnt;
pTNd->Replace( rIdx, sOverwriteText.Len(),
sOverwriteText );
if( bInsText )
{
rIdx = nSttCnt;
pDoc->StartUndo( UNDO_OVERWRITE, NULL );
pDoc->Overwrite( *this, sTxt.Copy( 0,
sOverwriteText.Len() ));
pDoc->Insert( *this, sTxt.Copy( sOverwriteText.Len() ), true);
pDoc->EndUndo( UNDO_OVERWRITE, NULL );
}
}
else
{
pTNd->Replace( rIdx, nLen, sOverwriteText.Copy( 0, nLen ));
if( bInsText )
{
rIdx = nSttCnt;
pDoc->Overwrite( *this, sTxt );
}
}
}
else
{
pTNd->Erase( rIdx, nEndCnt - nSttCnt );
2000-09-18 23:08:29 +00:00
if( bInsText )
pDoc->Insert( *this, sTxt, true );
}
2000-09-18 23:08:29 +00:00
}
}
}
void SwExtTextInput::SetInputData( const CommandExtTextInputData& rData )
{
SwTxtNode* pTNd = GetPoint()->nNode.GetNode().GetTxtNode();
if( pTNd )
{
xub_StrLen nSttCnt = GetPoint()->nContent.GetIndex(),
nEndCnt = GetMark()->nContent.GetIndex();
2000-09-18 23:08:29 +00:00
if( nEndCnt < nSttCnt )
{
xub_StrLen n = nEndCnt; nEndCnt = nSttCnt; nSttCnt = n;
}
2000-09-18 23:08:29 +00:00
SwIndex aIdx( pTNd, nSttCnt );
const String& rNewStr = rData.GetText();
2000-09-18 23:08:29 +00:00
if( bIsOverwriteCursor && sOverwriteText.Len() )
{
xub_StrLen nReplace = nEndCnt - nSttCnt;
if( rNewStr.Len() < nReplace )
{
// then we must insert from the saved original text
// some characters
nReplace = nReplace - rNewStr.Len();
aIdx += rNewStr.Len();
pTNd->Replace( aIdx, nReplace,
sOverwriteText.Copy( rNewStr.Len(), nReplace ));
aIdx = nSttCnt;
nReplace = rNewStr.Len();
}
else if( sOverwriteText.Len() < nReplace )
{
nReplace = nReplace - sOverwriteText.Len();
aIdx += sOverwriteText.Len();
pTNd->Erase( aIdx, nReplace );
aIdx = nSttCnt;
nReplace = sOverwriteText.Len();
}
else if( (nReplace = sOverwriteText.Len()) > rNewStr.Len() )
nReplace = rNewStr.Len();
2000-09-18 23:08:29 +00:00
pTNd->Replace( aIdx, nReplace, rNewStr );
if( !HasMark() )
SetMark();
GetMark()->nContent = aIdx;
}
else
{
if( nSttCnt < nEndCnt )
pTNd->Erase( aIdx, nEndCnt - nSttCnt );
pTNd->Insert( rNewStr, aIdx, INS_EMPTYEXPAND );
if( !HasMark() )
SetMark();
}
2000-09-18 23:08:29 +00:00
GetPoint()->nContent = nSttCnt;
if( aAttrs.Count() )
aAttrs.Remove( 0, aAttrs.Count() );
if( rData.GetTextAttr() )
aAttrs.Insert( rData.GetTextAttr(), rData.GetText().Len(), 0 );
}
}
void SwExtTextInput::SetOverwriteCursor( BOOL bFlag )
{
bIsOverwriteCursor = bFlag;
SwTxtNode* pTNd;
if( bIsOverwriteCursor &&
0 != (pTNd = GetPoint()->nNode.GetNode().GetTxtNode()) )
{
xub_StrLen nSttCnt = GetPoint()->nContent.GetIndex(),
nEndCnt = GetMark()->nContent.GetIndex();
sOverwriteText = pTNd->GetTxt().Copy( nEndCnt < nSttCnt ? nEndCnt
: nSttCnt );
if( sOverwriteText.Len() )
{
xub_StrLen nInWrdAttrPos = sOverwriteText.Search( CH_TXTATR_INWORD ),
nWrdAttrPos = sOverwriteText.Search( CH_TXTATR_BREAKWORD );
if( nWrdAttrPos < nInWrdAttrPos )
nInWrdAttrPos = nWrdAttrPos;
if( STRING_NOTFOUND != nInWrdAttrPos )
sOverwriteText.Erase( nInWrdAttrPos );
}
}
}
2000-09-18 23:08:29 +00:00
// die Doc Schnittstellen:
SwExtTextInput* SwDoc::CreateExtTextInput( const SwPaM& rPam )
{
SwExtTextInput* pNew = new SwExtTextInput( rPam, pExtInputRing );
if( !pExtInputRing )
pExtInputRing = pNew;
pNew->SetMark();
return pNew;
}
void SwDoc::DeleteExtTextInput( SwExtTextInput* pDel )
{
if( pDel == pExtInputRing )
{
if( pDel->GetNext() != pExtInputRing )
pExtInputRing = (SwPaM*)pDel->GetNext();
else
pExtInputRing = 0;
}
delete pDel;
}
SwExtTextInput* SwDoc::GetExtTextInput( const SwNode& rNd,
xub_StrLen nCntntPos ) const
{
SwExtTextInput* pRet = 0;
if( pExtInputRing )
{
ULONG nNdIdx = rNd.GetIndex();
SwExtTextInput* pTmp = (SwExtTextInput*)pExtInputRing;
do {
ULONG nPt = pTmp->GetPoint()->nNode.GetIndex(),
nMk = pTmp->GetMark()->nNode.GetIndex();
xub_StrLen nPtCnt = pTmp->GetPoint()->nContent.GetIndex(),
nMkCnt = pTmp->GetMark()->nContent.GetIndex();
if( nPt < nMk || ( nPt == nMk && nPtCnt < nMkCnt ))
{
ULONG nTmp = nMk; nMk = nPt; nPt = nTmp;
nTmp = nMkCnt; nMkCnt = nPtCnt; nPtCnt = (xub_StrLen)nTmp;
}
if( nMk <= nNdIdx && nNdIdx <= nPt &&
( STRING_NOTFOUND == nCntntPos ||
( nMkCnt <= nCntntPos && nCntntPos <= nPtCnt )))
{
pRet = pTmp;
break;
}
} while( pExtInputRing != (pTmp = (SwExtTextInput*)pExtInputRing ) );
}
return pRet;
}
SwExtTextInput* SwDoc::GetExtTextInput() const
{
ASSERT( !pExtInputRing || pExtInputRing == pExtInputRing->GetNext(),
"more then one InputEngine available" );
return (SwExtTextInput*)pExtInputRing;
}
2000-09-18 23:08:29 +00:00