2000-09-18 16:07:07 +00:00
|
|
|
|
/*************************************************************************
|
|
|
|
|
|
*
|
2008-04-10 19:42:10 +00:00
|
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-09-18 16:07:07 +00:00
|
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2000-09-18 16:07:07 +00:00
|
|
|
|
*
|
2008-04-10 19:42:10 +00:00
|
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 16:07:07 +00:00
|
|
|
|
*
|
2008-04-10 19:42:10 +00:00
|
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-18 16:07:07 +00:00
|
|
|
|
*
|
2008-04-10 19:42:10 +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 16:07:07 +00:00
|
|
|
|
*
|
2008-04-10 19:42:10 +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 16:07:07 +00:00
|
|
|
|
*
|
2008-04-10 19:42:10 +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 16:07:07 +00:00
|
|
|
|
*
|
|
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
2006-09-17 13:47:46 +00:00
|
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
|
|
#include "precompiled_svtools.hxx"
|
|
|
|
|
|
|
2007-06-27 20:31:04 +00:00
|
|
|
|
#include <svtools/textdata.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
|
#include <textdat2.hxx>
|
|
|
|
|
|
|
|
|
|
|
|
#include <tools/debug.hxx>
|
|
|
|
|
|
|
|
|
|
|
|
SV_IMPL_PTRARR( TextLines, TextLinePtr );
|
2002-08-12 14:36:21 +00:00
|
|
|
|
SV_IMPL_VARARR( TEWritingDirectionInfos, TEWritingDirectionInfo );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
// (+) class TextSelection
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
TextSelection::TextSelection()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TextSelection::TextSelection( const TextPaM& rPaM ) :
|
|
|
|
|
|
maStartPaM( rPaM ), maEndPaM( rPaM )
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TextSelection::TextSelection( const TextPaM& rStart, const TextPaM& rEnd ) :
|
|
|
|
|
|
maStartPaM( rStart ), maEndPaM( rEnd )
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TextSelection::Justify()
|
|
|
|
|
|
{
|
|
|
|
|
|
if ( maEndPaM < maStartPaM )
|
|
|
|
|
|
{
|
|
|
|
|
|
TextPaM aTemp( maStartPaM );
|
|
|
|
|
|
maStartPaM = maEndPaM;
|
|
|
|
|
|
maEndPaM = aTemp;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
// (+) class TETextPortionList
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
TETextPortionList::TETextPortionList()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TETextPortionList::~TETextPortionList()
|
|
|
|
|
|
{
|
|
|
|
|
|
Reset();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TETextPortionList::Reset()
|
|
|
|
|
|
{
|
|
|
|
|
|
for ( USHORT nPortion = 0; nPortion < Count(); nPortion++ )
|
|
|
|
|
|
delete GetObject( nPortion );
|
|
|
|
|
|
Remove( 0, Count() );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TETextPortionList::DeleteFromPortion( USHORT nDelFrom )
|
|
|
|
|
|
{
|
|
|
|
|
|
DBG_ASSERT( ( nDelFrom < Count() ) || ( (nDelFrom == 0) && (Count() == 0) ), "DeleteFromPortion: Out of range" );
|
|
|
|
|
|
for ( USHORT nP = nDelFrom; nP < Count(); nP++ )
|
|
|
|
|
|
delete GetObject( nP );
|
|
|
|
|
|
Remove( nDelFrom, Count()-nDelFrom );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2002-08-12 14:36:21 +00:00
|
|
|
|
USHORT TETextPortionList::FindPortion( USHORT nCharPos, USHORT& nPortionStart, BOOL bPreferStartingPortion )
|
2000-09-18 16:07:07 +00:00
|
|
|
|
{
|
|
|
|
|
|
// Bei nCharPos an Portion-Grenze wird die linke Portion gefunden
|
|
|
|
|
|
USHORT nTmpPos = 0;
|
|
|
|
|
|
for ( USHORT nPortion = 0; nPortion < Count(); nPortion++ )
|
|
|
|
|
|
{
|
2002-08-12 14:36:21 +00:00
|
|
|
|
TETextPortion* pPortion = GetObject( nPortion );
|
2006-10-12 14:15:14 +00:00
|
|
|
|
nTmpPos = nTmpPos + pPortion->GetLen();
|
2000-09-18 16:07:07 +00:00
|
|
|
|
if ( nTmpPos >= nCharPos )
|
|
|
|
|
|
{
|
2002-08-12 14:36:21 +00:00
|
|
|
|
// take this one if we don't prefer the starting portion, or if it's the last one
|
|
|
|
|
|
if ( ( nTmpPos != nCharPos ) || !bPreferStartingPortion || ( nPortion == Count() - 1 ) )
|
|
|
|
|
|
{
|
|
|
|
|
|
nPortionStart = nTmpPos - pPortion->GetLen();
|
|
|
|
|
|
return nPortion;
|
|
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
DBG_ERROR( "FindPortion: Nicht gefunden!" );
|
|
|
|
|
|
return ( Count() - 1 );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2002-08-12 14:36:21 +00:00
|
|
|
|
/*
|
|
|
|
|
|
USHORT TETextPortionList::GetPortionStartIndex( USHORT nPortion )
|
|
|
|
|
|
{
|
|
|
|
|
|
USHORT nPos = 0;
|
|
|
|
|
|
for ( USHORT nP = 0; nP < nPortion; nP++ )
|
|
|
|
|
|
{
|
|
|
|
|
|
TETextPortion* pPortion = GetObject( nP );
|
|
|
|
|
|
nPos += pPortion->GetLen();
|
|
|
|
|
|
}
|
|
|
|
|
|
return nPos;
|
|
|
|
|
|
}
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
// (+) class TEParaPortion
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
TEParaPortion::TEParaPortion( TextNode* pN )
|
|
|
|
|
|
{
|
|
|
|
|
|
mpNode = pN;
|
|
|
|
|
|
mnInvalidPosStart = mnInvalidDiff = 0;
|
|
|
|
|
|
mbInvalid = TRUE;
|
|
|
|
|
|
mbSimple = FALSE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEParaPortion::~TEParaPortion()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TEParaPortion::MarkInvalid( USHORT nStart, short nDiff )
|
|
|
|
|
|
{
|
|
|
|
|
|
if ( mbInvalid == FALSE )
|
|
|
|
|
|
{
|
|
|
|
|
|
mnInvalidPosStart = ( nDiff >= 0 ) ? nStart : ( nStart + nDiff );
|
|
|
|
|
|
mnInvalidDiff = nDiff;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// Einfaches hintereinander tippen
|
|
|
|
|
|
if ( ( nDiff > 0 ) && ( mnInvalidDiff > 0 ) &&
|
|
|
|
|
|
( ( mnInvalidPosStart+mnInvalidDiff ) == nStart ) )
|
|
|
|
|
|
{
|
2006-10-12 14:15:14 +00:00
|
|
|
|
mnInvalidDiff = mnInvalidDiff + nDiff;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
// Einfaches hintereinander loeschen
|
|
|
|
|
|
else if ( ( nDiff < 0 ) && ( mnInvalidDiff < 0 ) && ( mnInvalidPosStart == nStart ) )
|
|
|
|
|
|
{
|
2006-10-12 14:15:14 +00:00
|
|
|
|
mnInvalidPosStart = mnInvalidPosStart + nDiff;
|
|
|
|
|
|
mnInvalidDiff = mnInvalidDiff + nDiff;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
DBG_ASSERT( ( nDiff >= 0 ) || ( (nStart+nDiff) >= 0 ), "MarkInvalid: Diff out of Range" );
|
|
|
|
|
|
mnInvalidPosStart = Min( mnInvalidPosStart, (USHORT) ( (nDiff < 0) ? nStart+nDiff : nDiff ) );
|
|
|
|
|
|
mnInvalidDiff = 0;
|
|
|
|
|
|
mbSimple = FALSE;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2002-08-12 14:36:21 +00:00
|
|
|
|
|
|
|
|
|
|
maWritingDirectionInfos.Remove( 0, maWritingDirectionInfos.Count() );
|
|
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
|
mbInvalid = TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-06-19 20:02:06 +00:00
|
|
|
|
void TEParaPortion::MarkSelectionInvalid( USHORT nStart, USHORT /*nEnd*/ )
|
2000-09-18 16:07:07 +00:00
|
|
|
|
{
|
|
|
|
|
|
if ( mbInvalid == FALSE )
|
|
|
|
|
|
{
|
|
|
|
|
|
mnInvalidPosStart = nStart;
|
|
|
|
|
|
// nInvalidPosEnd = nEnd;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
mnInvalidPosStart = Min( mnInvalidPosStart, nStart );
|
|
|
|
|
|
// nInvalidPosEnd = pNode->Len();
|
|
|
|
|
|
}
|
2002-08-12 14:36:21 +00:00
|
|
|
|
|
|
|
|
|
|
maWritingDirectionInfos.Remove( 0, maWritingDirectionInfos.Count() );
|
|
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
|
mnInvalidDiff = 0;
|
|
|
|
|
|
mbInvalid = TRUE;
|
|
|
|
|
|
mbSimple = FALSE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
USHORT TEParaPortion::GetLineNumber( USHORT nChar, BOOL bInclEnd )
|
|
|
|
|
|
{
|
|
|
|
|
|
for ( USHORT nLine = 0; nLine < maLines.Count(); nLine++ )
|
|
|
|
|
|
{
|
|
|
|
|
|
TextLine* pLine = maLines.GetObject( nLine );
|
|
|
|
|
|
if ( ( bInclEnd && ( pLine->GetEnd() >= nChar ) ) ||
|
|
|
|
|
|
( pLine->GetEnd() > nChar ) )
|
|
|
|
|
|
{
|
|
|
|
|
|
return nLine;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Dann sollte es am Ende der letzten Zeile sein!
|
|
|
|
|
|
DBG_ASSERT( nChar == maLines[ maLines.Count() - 1 ]->GetEnd(), "Index voll daneben!" );
|
|
|
|
|
|
DBG_ASSERT( !bInclEnd, "Zeile nicht gefunden: FindLine" );
|
|
|
|
|
|
return ( maLines.Count() - 1 );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TEParaPortion::CorrectValuesBehindLastFormattedLine( USHORT nLastFormattedLine )
|
|
|
|
|
|
{
|
|
|
|
|
|
USHORT nLines = maLines.Count();
|
|
|
|
|
|
DBG_ASSERT( nLines, "CorrectPortionNumbersFromLine: Leere Portion?" );
|
|
|
|
|
|
if ( nLastFormattedLine < ( nLines - 1 ) )
|
|
|
|
|
|
{
|
|
|
|
|
|
const TextLine* pLastFormatted = maLines[ nLastFormattedLine ];
|
|
|
|
|
|
const TextLine* pUnformatted = maLines[ nLastFormattedLine+1 ];
|
|
|
|
|
|
short nPortionDiff = pUnformatted->GetStartPortion() - pLastFormatted->GetEndPortion();
|
|
|
|
|
|
short nTextDiff = pUnformatted->GetStart() - pLastFormatted->GetEnd();
|
|
|
|
|
|
nTextDiff++; // LastFormatted->GetEnd() war incl. => 1 zuviel abgezogen!
|
|
|
|
|
|
|
|
|
|
|
|
// Die erste unformatierte muss genau eine Portion hinter der letzten der
|
|
|
|
|
|
// formatierten beginnen:
|
|
|
|
|
|
// Wenn in der geaenderten Zeile eine Portion gesplittet wurde,
|
|
|
|
|
|
// kann nLastEnd > nNextStart sein!
|
2006-10-12 14:15:14 +00:00
|
|
|
|
short nPDiff = sal::static_int_cast< short >(-( nPortionDiff-1 ));
|
|
|
|
|
|
short nTDiff = sal::static_int_cast< short >(-( nTextDiff-1 ));
|
2000-09-18 16:07:07 +00:00
|
|
|
|
if ( nPDiff || nTDiff )
|
|
|
|
|
|
{
|
|
|
|
|
|
for ( USHORT nL = nLastFormattedLine+1; nL < nLines; nL++ )
|
|
|
|
|
|
{
|
|
|
|
|
|
TextLine* pLine = maLines[ nL ];
|
|
|
|
|
|
|
2006-10-12 14:15:14 +00:00
|
|
|
|
pLine->GetStartPortion() = pLine->GetStartPortion() + nPDiff;
|
|
|
|
|
|
pLine->GetEndPortion() = pLine->GetEndPortion() + nPDiff;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
2006-10-12 14:15:14 +00:00
|
|
|
|
pLine->GetStart() = pLine->GetStart() + nTDiff;
|
|
|
|
|
|
pLine->GetEnd() = pLine->GetEnd() + nTDiff;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
|
|
|
pLine->SetValid();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
// (+) class TEParaPortions
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
TEParaPortions::TEParaPortions()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEParaPortions::~TEParaPortions()
|
|
|
|
|
|
{
|
|
|
|
|
|
Reset();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TEParaPortions::Reset()
|
|
|
|
|
|
{
|
2003-11-12 16:17:55 +00:00
|
|
|
|
TEParaPortions::iterator aIter( begin() );
|
|
|
|
|
|
while ( aIter != end() )
|
|
|
|
|
|
delete *aIter++;
|
|
|
|
|
|
clear();
|
2000-09-18 16:07:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
// (+) class IdleFormatter
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
IdleFormatter::IdleFormatter()
|
|
|
|
|
|
{
|
|
|
|
|
|
mpView = 0;
|
|
|
|
|
|
mnRestarts = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IdleFormatter::~IdleFormatter()
|
|
|
|
|
|
{
|
|
|
|
|
|
mpView = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-11-12 16:17:55 +00:00
|
|
|
|
void IdleFormatter::DoIdleFormat( TextView* pV, USHORT nMaxRestarts )
|
2000-09-18 16:07:07 +00:00
|
|
|
|
{
|
|
|
|
|
|
mpView = pV;
|
|
|
|
|
|
|
|
|
|
|
|
if ( IsActive() )
|
|
|
|
|
|
mnRestarts++;
|
|
|
|
|
|
|
2003-11-12 16:17:55 +00:00
|
|
|
|
if ( mnRestarts > nMaxRestarts )
|
|
|
|
|
|
{
|
|
|
|
|
|
mnRestarts = 0;
|
|
|
|
|
|
((Link&)GetTimeoutHdl()).Call( this );
|
|
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
|
else
|
2003-11-12 16:17:55 +00:00
|
|
|
|
{
|
2000-09-18 16:07:07 +00:00
|
|
|
|
Start();
|
2003-11-12 16:17:55 +00:00
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void IdleFormatter::ForceTimeout()
|
|
|
|
|
|
{
|
|
|
|
|
|
if ( IsActive() )
|
|
|
|
|
|
{
|
|
|
|
|
|
Stop();
|
2003-11-12 16:17:55 +00:00
|
|
|
|
mnRestarts = 0;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
((Link&)GetTimeoutHdl()).Call( this );
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TYPEINIT1( TextHint, SfxSimpleHint );
|
|
|
|
|
|
|
2006-06-19 20:02:06 +00:00
|
|
|
|
TextHint::TextHint( ULONG Id ) : SfxSimpleHint( Id )
|
2000-09-18 16:07:07 +00:00
|
|
|
|
{
|
|
|
|
|
|
mnValue = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-06-19 20:02:06 +00:00
|
|
|
|
TextHint::TextHint( ULONG Id, ULONG nValue ) : SfxSimpleHint( Id )
|
2000-09-18 16:07:07 +00:00
|
|
|
|
{
|
|
|
|
|
|
mnValue = nValue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2001-06-14 09:46:01 +00:00
|
|
|
|
TEIMEInfos::TEIMEInfos( const TextPaM& rPos, const String& rOldTextAfterStartPos )
|
|
|
|
|
|
: aOldTextAfterStartPos( rOldTextAfterStartPos )
|
2000-10-13 08:55:28 +00:00
|
|
|
|
{
|
|
|
|
|
|
aPos = rPos;
|
|
|
|
|
|
nLen = 0;
|
|
|
|
|
|
bCursor = TRUE;
|
|
|
|
|
|
pAttribs = NULL;
|
2000-11-08 09:42:11 +00:00
|
|
|
|
bWasCursorOverwrite = FALSE;
|
2000-10-13 08:55:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEIMEInfos::~TEIMEInfos()
|
|
|
|
|
|
{
|
2002-07-12 12:41:47 +00:00
|
|
|
|
delete[] pAttribs;
|
2000-10-13 08:55:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TEIMEInfos::CopyAttribs( const USHORT* pA, USHORT nL )
|
|
|
|
|
|
{
|
|
|
|
|
|
nLen = nL;
|
|
|
|
|
|
delete pAttribs;
|
|
|
|
|
|
pAttribs = new USHORT[ nL ];
|
|
|
|
|
|
memcpy( pAttribs, pA, nL*sizeof(USHORT) );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TEIMEInfos::DestroyAttribs()
|
|
|
|
|
|
{
|
|
|
|
|
|
delete pAttribs;
|
|
|
|
|
|
pAttribs = NULL;
|
2001-05-03 11:53:23 +00:00
|
|
|
|
nLen = 0;
|
2000-10-13 08:55:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|