summaryrefslogtreecommitdiff
path: root/svtools/source/edit
diff options
context:
space:
mode:
Diffstat (limited to 'svtools/source/edit')
-rw-r--r--svtools/source/edit/makefile.mk135
-rw-r--r--svtools/source/edit/svmedit.cxx1396
-rw-r--r--svtools/source/edit/sychconv.cxx139
-rw-r--r--svtools/source/edit/textdat2.hxx338
-rw-r--r--svtools/source/edit/textdata.cxx329
-rw-r--r--svtools/source/edit/textdoc.cxx1073
-rw-r--r--svtools/source/edit/textdoc.hxx202
-rw-r--r--svtools/source/edit/texteng.cxx2691
-rw-r--r--svtools/source/edit/textund2.hxx182
-rw-r--r--svtools/source/edit/textundo.cxx374
-rw-r--r--svtools/source/edit/textundo.hxx118
-rw-r--r--svtools/source/edit/textview.cxx1760
-rw-r--r--svtools/source/edit/txtattr.cxx157
-rw-r--r--svtools/source/edit/xtextedt.cxx444
14 files changed, 9338 insertions, 0 deletions
diff --git a/svtools/source/edit/makefile.mk b/svtools/source/edit/makefile.mk
new file mode 100644
index 000000000000..b73818d70cb8
--- /dev/null
+++ b/svtools/source/edit/makefile.mk
@@ -0,0 +1,135 @@
+#*************************************************************************
+#
+# $RCSfile: makefile.mk,v $
+#
+# $Revision: 1.1.1.1 $
+#
+# last change: $Author: hr $ $Date: 2000-09-18 16:58:58 $
+#
+# The Contents of this file are made available subject to the terms of
+# either of the following licenses
+#
+# - GNU Lesser General Public License Version 2.1
+# - Sun Industry Standards Source License Version 1.1
+#
+# Sun Microsystems Inc., October, 2000
+#
+# GNU Lesser General Public License Version 2.1
+# =============================================
+# Copyright 2000 by Sun Microsystems, Inc.
+# 901 San Antonio Road, Palo Alto, CA 94303, USA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# This library 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 for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#
+# Sun Industry Standards Source License Version 1.1
+# =================================================
+# The contents of this file are subject to the Sun Industry Standards
+# Source License Version 1.1 (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.openoffice.org/license.html.
+#
+# Software provided under this License is provided on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+# See the License for the specific provisions governing your rights and
+# obligations concerning the Software.
+#
+# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+#
+# Copyright: 2000 by Sun Microsystems, Inc.
+#
+# All Rights Reserved.
+#
+# Contributor(s): _______________________________________
+#
+#
+#
+#*************************************************************************
+
+PRJ=..$/..
+
+PRJNAME=SVTOOLS
+TARGET=edit
+LIBTARGET=NO
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE : svpre.mk
+.INCLUDE : settings.mk
+.INCLUDE : sv.mk
+
+# --- Files --------------------------------------------------------
+
+.IF "$(header)" == ""
+
+CXXFILES= \
+ textdata.cxx \
+ textdoc.cxx \
+ texteng.cxx \
+ textundo.cxx \
+ textview.cxx \
+ txtattr.cxx \
+ xtextedt.cxx \
+ sychconv.cxx
+
+.IF "$(VCL)" != ""
+CXXFILES+= \
+ svmedit.cxx
+.ENDIF
+
+
+SLOFILES= \
+ $(SLO)$/textdata.obj \
+ $(SLO)$/textdoc.obj \
+ $(SLO)$/texteng.obj \
+ $(SLO)$/textundo.obj \
+ $(SLO)$/textview.obj \
+ $(SLO)$/txtattr.obj \
+ $(SLO)$/xtextedt.obj \
+ $(SLO)$/sychconv.obj
+
+.IF "$(VCL)" != ""
+SLOFILES+= \
+ $(SLO)$/svmedit.obj
+.ENDIF
+
+OBJFILES= \
+ $(OBJ)$/textdata.obj \
+ $(OBJ)$/textdoc.obj \
+ $(OBJ)$/texteng.obj \
+ $(OBJ)$/textundo.obj \
+ $(OBJ)$/textview.obj \
+ $(OBJ)$/txtattr.obj \
+ $(OBJ)$/xtextedt.obj \
+ $(OBJ)$/sychconv.obj
+
+.IF "$(VCL)" != ""
+OBJFILES+= \
+ $(OBJ)$/svmedit.obj
+.ENDIF
+
+LIB1TARGET= $(SLB)$/$(TARGET).lib
+LIB1OBJFILES= $(SLOFILES)
+
+LIB2TARGET= $(LB)$/$(TARGET).lib
+LIB2OBJFILES= $(OBJFILES)
+
+.ENDIF
+
+# --- Targets ------------------------------------------------------
+
+.INCLUDE : target.mk
diff --git a/svtools/source/edit/svmedit.cxx b/svtools/source/edit/svmedit.cxx
new file mode 100644
index 000000000000..29d293e734c7
--- /dev/null
+++ b/svtools/source/edit/svmedit.cxx
@@ -0,0 +1,1396 @@
+/*************************************************************************
+ *
+ * $RCSfile: svmedit.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: hr $ $Date: 2000-09-18 16:58:58 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (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.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#include <vcl/rc.h>
+#include <vcl/decoview.hxx>
+
+#include <svmedit.hxx>
+#include <xtextedt.hxx>
+#include <brdcst.hxx>
+#include <lstner.hxx>
+
+#ifndef _UNDO_HXX
+#include <undo.hxx>
+#endif
+
+
+// IDs erstmal aus VCL geklaut, muss mal richtig delivert werden...
+#define SV_MENU_EDIT_UNDO 1
+#define SV_MENU_EDIT_CUT 2
+#define SV_MENU_EDIT_COPY 3
+#define SV_MENU_EDIT_PASTE 4
+#define SV_MENU_EDIT_DELETE 5
+#define SV_MENU_EDIT_SELECTALL 6
+#define SV_MENU_EDIT_INSERTSYMBOL 7
+
+#ifndef _SV_SCRBAR_HXX //autogen
+#include <vcl/scrbar.hxx>
+#endif
+
+
+class TextWindow : public Window
+{
+private:
+ ExtTextEngine* mpExtTextEngine;
+ ExtTextView* mpExtTextView;
+
+ BOOL mbInMBDown;
+ BOOL mbFocusSelectionHide;
+ BOOL mbIgnoreTab;
+ BOOL mbActivePopup;
+
+public:
+ TextWindow( Window* pParent );
+ ~TextWindow();
+
+ ExtTextEngine* GetTextEngine() const { return mpExtTextEngine; }
+ ExtTextView* GetTextView() const { return mpExtTextView; }
+
+ virtual void MouseMove( const MouseEvent& rMEvt );
+ virtual void MouseButtonDown( const MouseEvent& rMEvt );
+ virtual void MouseButtonUp( const MouseEvent& rMEvt );
+ virtual void KeyInput( const KeyEvent& rKEvent );
+
+ virtual BOOL QueryDrop( DropEvent& rEvt );
+ virtual BOOL Drop( const DropEvent& rEvt );
+
+ virtual void Command( const CommandEvent& rCEvt );
+
+ virtual void Paint( const Rectangle& rRect );
+ virtual void Resize();
+
+ virtual void GetFocus();
+ virtual void LoseFocus();
+
+ BOOL IsAutoFocusHide() const { return mbFocusSelectionHide; }
+ void SetAutoFocusHide( BOOL bAutoHide ) { mbFocusSelectionHide = bAutoHide; }
+
+ BOOL IsIgnoreTab() const { return mbIgnoreTab; }
+ void SetIgnoreTab( BOOL bIgnore ) { mbIgnoreTab = bIgnore; }
+};
+
+
+class ImpSvMEdit : public SfxListener
+{
+private:
+ MultiLineEdit* pSvMultiLineEdit;
+
+ TextWindow* mpTextWindow;
+ ScrollBar* mpHScrollBar;
+ ScrollBar* mpVScrollBar;
+ ScrollBarBox* mpScrollBox;
+
+ Point maTextWindowOffset;
+ ULONG mnTextWidth;
+
+protected:
+ virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
+ void ImpInitScrollBars();
+ void ImpSetScrollBarRanges();
+ DECL_LINK( ScrollHdl, ScrollBar* );
+
+public:
+ ImpSvMEdit( MultiLineEdit* pSvMultiLineEdit, WinBits nWinStyle );
+ ~ImpSvMEdit();
+
+ void SetModified( BOOL bMod );
+ BOOL IsModified() const;
+
+ void SetReadOnly( BOOL bRdOnly );
+ BOOL IsReadOnly() const;
+
+ void SetMaxTextLen( ULONG nLen );
+ ULONG GetMaxTextLen() const;
+
+ void SetInsertMode( BOOL bInsert );
+ BOOL IsInsertMode() const;
+
+ void InsertText( const String& rStr );
+ String GetSelected() const;
+
+ void SetSelection( const Selection& rSelection );
+ Selection GetSelection() const;
+
+ void Cut();
+ void Copy();
+ void Paste();
+
+ void SetText( const String& rStr );
+ String GetText() const;
+ String GetTextLines() const;
+
+ void Resize();
+ void GetFocus();
+
+ BOOL HandleCommand( const CommandEvent& rCEvt );
+
+ void Enable( BOOL bEnable );
+
+ Size CalcMinimumSize() const;
+ Size CalcSize( USHORT nColumns, USHORT nLines ) const;
+ void GetMaxVisColumnsAndLines( USHORT& rnCols, USHORT& rnLines ) const;
+
+ void SetAlign( WinBits nWinStyle );
+
+ TextWindow* GetTextWindow() { return mpTextWindow; }
+ ScrollBar* GetHScrollBar() { return mpHScrollBar; }
+ ScrollBar* GetVScrollBar() { return mpVScrollBar; }
+
+ void SetTextWindowOffset( const Point& rOffset );
+};
+
+
+ImpSvMEdit::ImpSvMEdit( MultiLineEdit* pEdt, WinBits nWinStyle )
+{
+ pSvMultiLineEdit = pEdt;
+
+ mnTextWidth = 0;
+
+ mpTextWindow = new TextWindow( pEdt );
+ mpHScrollBar = ( nWinStyle & WB_HSCROLL ) ? new ScrollBar( pEdt, WB_HSCROLL|WB_DRAG ) : NULL;
+ mpVScrollBar = ( nWinStyle & WB_VSCROLL ) ? new ScrollBar( pEdt, WB_VSCROLL|WB_DRAG ) : NULL;
+ mpScrollBox = ( mpVScrollBar && mpHScrollBar ) ? new ScrollBarBox( pEdt, WB_SIZEABLE ) : NULL;
+
+ SetAlign( nWinStyle );
+ StartListening( *mpTextWindow->GetTextEngine() );
+
+ if ( nWinStyle & WB_NOHIDESELECTION )
+ mpTextWindow->SetAutoFocusHide( FALSE );
+ else
+ mpTextWindow->SetAutoFocusHide( TRUE );
+
+ if ( nWinStyle & WB_READONLY )
+ mpTextWindow->GetTextView()->SetReadOnly( TRUE );
+
+ if ( nWinStyle & WB_IGNORETAB )
+ mpTextWindow->SetIgnoreTab( TRUE );
+
+ mpTextWindow->Show();
+ if ( mpHScrollBar )
+ {
+ mpHScrollBar->Show();
+ mpHScrollBar->SetScrollHdl( LINK( this, ImpSvMEdit, ScrollHdl ) );
+ }
+ if ( mpVScrollBar )
+ {
+ mpVScrollBar->Show();
+ mpVScrollBar->SetScrollHdl( LINK( this, ImpSvMEdit, ScrollHdl ) );
+ }
+ if ( mpScrollBox )
+ mpScrollBox->Show();
+
+ ImpInitScrollBars();
+}
+
+ImpSvMEdit::~ImpSvMEdit()
+{
+ EndListening( *mpTextWindow->GetTextEngine() );
+ delete mpTextWindow;
+ delete mpHScrollBar;
+ delete mpVScrollBar;
+ delete mpScrollBox;
+}
+
+void ImpSvMEdit::ImpSetScrollBarRanges()
+{
+ if ( mpVScrollBar )
+ {
+ ULONG nTextHeight = mpTextWindow->GetTextEngine()->GetTextHeight();
+ mpVScrollBar->SetRange( Range( 0, (long)nTextHeight ) );
+ }
+ if ( mpHScrollBar )
+ {
+// ULONG nTextWidth = mpTextWindow->GetTextEngine()->CalcTextWidth();
+ // Es gibt kein Notify bei Breiten-Aenderung...
+// ULONG nW = Max( (ULONG)mpTextWindow->GetOutputSizePixel().Width()*5, (ULONG)nTextWidth );
+// mpHScrollBar->SetRange( Range( 0, (long)nW ) );
+ mpHScrollBar->SetRange( Range( 0, (long)mnTextWidth ) );
+ }
+}
+
+void ImpSvMEdit::ImpInitScrollBars()
+{
+ static const sal_Unicode sampleText[] = { 'x', '\0' };
+ if ( mpHScrollBar || mpVScrollBar )
+ {
+ ImpSetScrollBarRanges();
+ Size aCharBox;
+ aCharBox.Width() = mpTextWindow->GetTextWidth( sampleText );
+ aCharBox.Height() = mpTextWindow->GetTextHeight();
+ Size aOutSz = mpTextWindow->GetOutputSizePixel();
+ if ( mpHScrollBar )
+ {
+ mpHScrollBar->SetVisibleSize( aOutSz.Width() );
+ mpHScrollBar->SetPageSize( aOutSz.Width() * 8 / 10 );
+ mpHScrollBar->SetLineSize( aCharBox.Width()*10 );
+ mpHScrollBar->SetThumbPos( mpTextWindow->GetTextView()->GetStartDocPos().X() );
+ }
+ if ( mpVScrollBar )
+ {
+ mpVScrollBar->SetVisibleSize( aOutSz.Height() );
+ mpVScrollBar->SetPageSize( aOutSz.Height() * 8 / 10 );
+ mpVScrollBar->SetLineSize( aCharBox.Height() );
+ mpVScrollBar->SetThumbPos( mpTextWindow->GetTextView()->GetStartDocPos().Y() );
+ }
+ }
+}
+
+IMPL_LINK( ImpSvMEdit, ScrollHdl, ScrollBar*, pCurScrollBar )
+{
+ long nDiffX = 0, nDiffY = 0;
+
+ if ( pCurScrollBar == mpVScrollBar )
+ nDiffY = mpTextWindow->GetTextView()->GetStartDocPos().Y() - pCurScrollBar->GetThumbPos();
+ else if ( pCurScrollBar == mpHScrollBar )
+ nDiffX = mpTextWindow->GetTextView()->GetStartDocPos().X() - pCurScrollBar->GetThumbPos();
+
+ mpTextWindow->GetTextView()->Scroll( nDiffX, nDiffY );
+ // mpTextWindow->GetTextView()->ShowCursor( FALSE, TRUE );
+
+ return 0;
+}
+
+
+// void ImpSvMEdit::ImpModified()
+// {
+// // Wann wird das gerufen ?????????????????????
+// pSvMultiLineEdit->Modify();
+// }
+
+void ImpSvMEdit::SetAlign( WinBits nWinStyle )
+{
+ if ( nWinStyle & WB_CENTER )
+ mpTextWindow->GetTextEngine()->SetTextAlign( TXTALIGN_CENTER );
+ else if ( nWinStyle & WB_RIGHT )
+ mpTextWindow->GetTextEngine()->SetTextAlign( TXTALIGN_RIGHT );
+ else
+ mpTextWindow->GetTextEngine()->SetTextAlign( TXTALIGN_LEFT );
+}
+
+void ImpSvMEdit::SetTextWindowOffset( const Point& rOffset )
+{
+ maTextWindowOffset = rOffset;
+ Resize();
+}
+
+void ImpSvMEdit::SetModified( BOOL bMod )
+{
+ mpTextWindow->GetTextEngine()->SetModified( bMod );
+}
+
+BOOL ImpSvMEdit::IsModified() const
+{
+ return mpTextWindow->GetTextEngine()->IsModified();
+}
+
+void ImpSvMEdit::SetInsertMode( BOOL bInsert )
+{
+ mpTextWindow->GetTextView()->SetInsertMode( bInsert );
+}
+
+void ImpSvMEdit::SetReadOnly( BOOL bRdOnly )
+{
+ mpTextWindow->GetTextView()->SetReadOnly( bRdOnly );
+ // Farbe anpassen ???????????????????????????
+}
+
+BOOL ImpSvMEdit::IsReadOnly() const
+{
+ return mpTextWindow->GetTextView()->IsReadOnly();
+}
+
+void ImpSvMEdit::SetMaxTextLen( ULONG nLen )
+{
+ mpTextWindow->GetTextEngine()->SetMaxTextLen( nLen );
+}
+
+ULONG ImpSvMEdit::GetMaxTextLen() const
+{
+ return mpTextWindow->GetTextEngine()->GetMaxTextLen();
+}
+
+void ImpSvMEdit::InsertText( const String& rStr )
+{
+ mpTextWindow->GetTextView()->InsertText( rStr );
+}
+
+String ImpSvMEdit::GetSelected() const
+{
+ return mpTextWindow->GetTextView()->GetSelected();
+}
+
+void ImpSvMEdit::Resize()
+{
+ Size aSz = pSvMultiLineEdit->GetOutputSizePixel();
+ long nSBWidth = pSvMultiLineEdit->GetSettings().GetStyleSettings().GetScrollBarSize();
+ nSBWidth = pSvMultiLineEdit->CalcZoom( nSBWidth );
+
+ if ( mpHScrollBar )
+ aSz.Height() -= nSBWidth;
+ if ( mpVScrollBar )
+ aSz.Width() -= nSBWidth;
+
+ Size aTextWindowSz( aSz );
+ aTextWindowSz.Width() -= maTextWindowOffset.X();
+ aTextWindowSz.Height() -= maTextWindowOffset.Y();
+ mpTextWindow->SetPosSizePixel( maTextWindowOffset, aTextWindowSz );
+
+ if ( !mpHScrollBar )
+ mpTextWindow->GetTextEngine()->SetMaxTextWidth( aSz.Width() );
+
+ if ( mpHScrollBar )
+ mpHScrollBar->SetPosSizePixel( 0, aSz.Height(), aSz.Width(), nSBWidth );
+
+ if ( mpVScrollBar )
+ mpVScrollBar->SetPosSizePixel( aSz.Width(), 0, nSBWidth, aSz.Height() );
+
+ if ( mpScrollBox )
+ mpScrollBox->SetPosSizePixel( aSz.Width(), aSz.Height(), nSBWidth, nSBWidth );
+
+ ImpInitScrollBars();
+}
+
+void ImpSvMEdit::GetFocus()
+{
+ mpTextWindow->GrabFocus();
+}
+
+void ImpSvMEdit::Cut()
+{
+ if ( !mpTextWindow->GetTextView()->IsReadOnly() )
+ mpTextWindow->GetTextView()->Cut();
+}
+
+void ImpSvMEdit::Copy()
+{
+ mpTextWindow->GetTextView()->Copy();
+}
+
+void ImpSvMEdit::Paste()
+{
+ if ( !mpTextWindow->GetTextView()->IsReadOnly() )
+ mpTextWindow->GetTextView()->Paste();
+}
+
+void ImpSvMEdit::SetText( const String& rStr )
+{
+ BOOL bWasModified = mpTextWindow->GetTextEngine()->IsModified();
+ mpTextWindow->GetTextEngine()->SetText( rStr );
+ if ( !bWasModified )
+ mpTextWindow->GetTextEngine()->SetModified( FALSE );
+
+ mpTextWindow->GetTextView()->SetSelection( TextSelection() );
+}
+
+String ImpSvMEdit::GetText() const
+{
+ return mpTextWindow->GetTextEngine()->GetText();
+}
+
+String ImpSvMEdit::GetTextLines() const
+{
+ return mpTextWindow->GetTextEngine()->GetTextLines();
+}
+
+void ImpSvMEdit::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
+{
+ if ( rHint.ISA( TextHint ) )
+ {
+ const TextHint& rTextHint = (const TextHint&)rHint;
+ if( rTextHint.GetId() == TEXT_HINT_VIEWSCROLLED )
+ {
+ if ( mpHScrollBar )
+ mpHScrollBar->SetThumbPos( mpTextWindow->GetTextView()->GetStartDocPos().X() );
+ if ( mpVScrollBar )
+ mpVScrollBar->SetThumbPos( mpTextWindow->GetTextView()->GetStartDocPos().Y() );
+ }
+ else if( rTextHint.GetId() == TEXT_HINT_TEXTHEIGHTCHANGED )
+ {
+ if ( mpTextWindow->GetTextView()->GetStartDocPos().Y() )
+ {
+ long nOutHeight = mpTextWindow->GetOutputSizePixel().Height();
+ long nTextHeight = mpTextWindow->GetTextEngine()->GetTextHeight();
+ if ( nTextHeight < nOutHeight )
+ mpTextWindow->GetTextView()->Scroll( 0, mpTextWindow->GetTextView()->GetStartDocPos().Y() );
+ }
+
+ ImpSetScrollBarRanges();
+ }
+ else if( rTextHint.GetId() == TEXT_HINT_TEXTFORMATTED )
+ {
+ if ( mpHScrollBar )
+ {
+ ULONG nWidth = mpTextWindow->GetTextEngine()->CalcTextWidth();
+ if ( nWidth != mnTextWidth )
+ {
+ mnTextWidth = nWidth;
+ mpHScrollBar->SetRange( Range( 0, (long)mnTextWidth ) );
+ mpHScrollBar->SetThumbPos( mpTextWindow->GetTextView()->GetStartDocPos().X() );
+ }
+ }
+ }
+ else if( rTextHint.GetId() == TEXT_HINT_MODIFIED )
+ {
+ pSvMultiLineEdit->Modify();
+ }
+ }
+}
+
+void ImpSvMEdit::SetSelection( const Selection& rSelection )
+{
+ String aText = mpTextWindow->GetTextEngine()->GetText();
+
+ Selection aNewSelection( rSelection );
+ if ( aNewSelection.Min() < 0 )
+ aNewSelection.Min() = 0;
+ else if ( aNewSelection.Min() > aText.Len() )
+ aNewSelection.Min() = aText.Len();
+ if ( aNewSelection.Max() < 0 )
+ aNewSelection.Max() = 0;
+ else if ( aNewSelection.Max() > aText.Len() )
+ aNewSelection.Max() = aText.Len();
+
+ long nEnd = Max( aNewSelection.Min(), aNewSelection.Max() );
+ TextSelection aTextSel;
+ ULONG nPara = 0;
+ USHORT nChar = 0;
+ USHORT x = 0;
+ while ( x <= nEnd )
+ {
+ if ( x == aNewSelection.Min() )
+ aTextSel.GetStart() = TextPaM( nPara, nChar );
+ if ( x == aNewSelection.Max() )
+ aTextSel.GetEnd() = TextPaM( nPara, nChar );
+
+ if ( ( x < aText.Len() ) && ( aText.GetChar( x ) == '\n' ) )
+ {
+ nPara++;
+ nChar = 0;
+ }
+ else
+ nChar++;
+ x++;
+ }
+ mpTextWindow->GetTextView()->SetSelection( aTextSel );
+}
+
+Selection ImpSvMEdit::GetSelection() const
+{
+ Selection aSel;
+ TextSelection aTextSel( mpTextWindow->GetTextView()->GetSelection() );
+ aTextSel.Justify();
+ // Selektion flachklopfen => jeder Umbruch ein Zeichen...
+
+ ExtTextEngine* pExtTextEngine = mpTextWindow->GetTextEngine();
+ // Absaetze davor:
+ ULONG n;
+ for ( n = 0; n < aTextSel.GetStart().GetPara(); n++ )
+ {
+ aSel.Min() += pExtTextEngine->GetTextLen( n );
+ aSel.Min()++;
+ }
+
+ // Erster Absatz mit Selektion:
+ aSel.Max() = aSel.Min();
+ aSel.Min() += aTextSel.GetStart().GetIndex();
+
+ for ( n = aTextSel.GetStart().GetPara(); n < aTextSel.GetEnd().GetPara(); n++ )
+ {
+ aSel.Max() += pExtTextEngine->GetTextLen( n );
+ aSel.Max()++;
+ }
+
+ aSel.Max() += aTextSel.GetEnd().GetIndex();
+
+ return aSel;
+}
+
+Size ImpSvMEdit::CalcMinimumSize() const
+{
+ Size aSz( mpTextWindow->GetTextEngine()->CalcTextWidth(),
+ mpTextWindow->GetTextEngine()->GetTextHeight() );
+
+ if ( mpHScrollBar )
+ aSz.Height() += mpHScrollBar->GetSizePixel().Height();
+ if ( mpVScrollBar )
+ aSz.Width() += mpVScrollBar->GetSizePixel().Width();
+
+ return aSz;
+}
+
+Size ImpSvMEdit::CalcSize( USHORT nColumns, USHORT nLines ) const
+{
+ static const sal_Unicode sampleText[] = { 'X', '\0' };
+
+ Size aSz;
+ Size aCharSz;
+ aCharSz.Width() = mpTextWindow->GetTextWidth( sampleText );
+ aCharSz.Height() = mpTextWindow->GetTextHeight();
+
+ if ( nLines )
+ aSz.Height() = nLines*aCharSz.Height();
+ else
+ aSz.Height() = mpTextWindow->GetTextEngine()->GetTextHeight();
+
+ if ( nColumns )
+ aSz.Width() = nColumns*aCharSz.Width();
+ else
+ aSz.Width() = mpTextWindow->GetTextEngine()->CalcTextWidth();
+
+ if ( mpHScrollBar )
+ aSz.Height() += mpHScrollBar->GetSizePixel().Height();
+ if ( mpVScrollBar )
+ aSz.Width() += mpVScrollBar->GetSizePixel().Width();
+
+ return aSz;
+}
+
+void ImpSvMEdit::GetMaxVisColumnsAndLines( USHORT& rnCols, USHORT& rnLines ) const
+{
+ static const sal_Unicode sampleText[] = { 'x', '\0' };
+ Size aOutSz = mpTextWindow->GetOutputSizePixel();
+ Size aCharSz( mpTextWindow->GetTextWidth( sampleText ), mpTextWindow->GetTextHeight() );
+ rnCols = (USHORT) (aOutSz.Width()/aCharSz.Width());
+ rnLines = (USHORT) (aOutSz.Height()/aCharSz.Height());
+}
+
+void ImpSvMEdit::Enable( BOOL bEnable )
+{
+ mpTextWindow->Enable( bEnable );
+ if ( mpHScrollBar )
+ mpHScrollBar->Enable( bEnable );
+ if ( mpVScrollBar )
+ mpVScrollBar->Enable( bEnable );
+}
+
+BOOL ImpSvMEdit::HandleCommand( const CommandEvent& rCEvt )
+{
+ BOOL bDone = FALSE;
+ if ( ( rCEvt.GetCommand() == COMMAND_WHEEL ) ||
+ ( rCEvt.GetCommand() == COMMAND_STARTAUTOSCROLL ) ||
+ ( rCEvt.GetCommand() == COMMAND_AUTOSCROLL ) )
+ {
+ mpTextWindow->HandleScrollCommand( rCEvt, mpHScrollBar, mpVScrollBar );
+ bDone = TRUE;
+ }
+ return bDone;
+}
+
+
+TextWindow::TextWindow( Window* pParent ) : Window( pParent )
+{
+ mbInMBDown = FALSE;
+ mbFocusSelectionHide = FALSE;
+ mbIgnoreTab = FALSE;
+ mbActivePopup = FALSE;
+
+ SetPointer( Pointer( POINTER_TEXT ) );
+
+ mpExtTextEngine = new ExtTextEngine;
+ mpExtTextEngine->SetMaxTextLen( STRING_MAXLEN );
+ mpExtTextView = new ExtTextView( mpExtTextEngine, this );
+ mpExtTextEngine->InsertView( mpExtTextView );
+ mpExtTextEngine->EnableUndo( TRUE );
+ mpExtTextView->ShowCursor();
+
+ Color aBackgroundColor = GetSettings().GetStyleSettings().GetWorkspaceColor();
+ SetBackground( aBackgroundColor );
+ pParent->SetBackground( aBackgroundColor );
+ EnableDrop( TRUE );
+}
+
+TextWindow::~TextWindow()
+{
+ delete mpExtTextView;
+ delete mpExtTextEngine;
+}
+
+void TextWindow::MouseMove( const MouseEvent& rMEvt )
+{
+ mpExtTextView->MouseMove( rMEvt );
+ Window::MouseMove( rMEvt );
+}
+
+void TextWindow::MouseButtonDown( const MouseEvent& rMEvt )
+{
+ mbInMBDown = TRUE; // Dann im GetFocus nicht alles selektieren wird
+ mpExtTextView->MouseButtonDown( rMEvt );
+ Window::MouseButtonDown( rMEvt );
+ GrabFocus();
+ mbInMBDown = FALSE;
+}
+
+void TextWindow::MouseButtonUp( const MouseEvent& rMEvt )
+{
+ mpExtTextView->MouseButtonUp( rMEvt );
+ Window::MouseButtonUp( rMEvt );
+}
+
+void TextWindow::KeyInput( const KeyEvent& rKEvent )
+{
+ BOOL bDone = FALSE;
+ USHORT nCode = rKEvent.GetKeyCode().GetCode();
+ if ( (nCode == KEY_A) && rKEvent.GetKeyCode().IsMod1() )
+ {
+ mpExtTextView->SetSelection( TextSelection( TextPaM( 0, 0 ), TextPaM( 0xFFFF, 0xFFFF ) ) );
+ bDone = TRUE;
+ }
+ else if ( (nCode == KEY_S) && rKEvent.GetKeyCode().IsShift() && rKEvent.GetKeyCode().IsMod1() )
+ {
+ if ( Edit::GetGetSpecialCharsFunction() )
+ {
+ // Damit die Selektion erhalten bleibt
+ mbActivePopup = TRUE;
+ XubString aChars = Edit::GetGetSpecialCharsFunction()( this, GetFont() );
+ if ( aChars.Len() )
+ {
+ mpExtTextView->InsertText( aChars );
+ mpExtTextView->GetTextEngine()->SetModified( TRUE );
+ }
+ mbActivePopup = FALSE;
+ bDone = TRUE;
+ }
+ }
+ else if ( nCode == KEY_TAB )
+ {
+ if ( !mbIgnoreTab || rKEvent.GetKeyCode().IsMod1() )
+ bDone = mpExtTextView->KeyInput( rKEvent );
+ }
+ else
+ {
+ bDone = mpExtTextView->KeyInput( rKEvent );
+ }
+
+ if ( !bDone )
+ Window::KeyInput( rKEvent );
+}
+
+void TextWindow::Paint( const Rectangle& rRect )
+{
+ mpExtTextView->Paint( rRect );
+}
+
+void TextWindow::Resize()
+{
+}
+
+void TextWindow::Command( const CommandEvent& rCEvt )
+{
+ if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
+ {
+ PopupMenu* pPopup = Edit::CreatePopupMenu();
+ const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
+ if ( rStyleSettings.GetOptions() & STYLE_OPTION_HIDEDISABLED )
+ pPopup->SetMenuFlags( MENU_FLAG_HIDEDISABLEDENTRIES );
+ if ( !mpExtTextView->HasSelection() )
+ {
+ pPopup->EnableItem( SV_MENU_EDIT_CUT, FALSE );
+ pPopup->EnableItem( SV_MENU_EDIT_COPY, FALSE );
+ pPopup->EnableItem( SV_MENU_EDIT_DELETE, FALSE );
+ }
+ if ( mpExtTextView->IsReadOnly() )
+ {
+ pPopup->EnableItem( SV_MENU_EDIT_CUT, FALSE );
+ pPopup->EnableItem( SV_MENU_EDIT_PASTE, FALSE );
+ pPopup->EnableItem( SV_MENU_EDIT_DELETE, FALSE );
+ pPopup->EnableItem( SV_MENU_EDIT_INSERTSYMBOL, FALSE );
+ }
+ if ( !mpExtTextView->GetTextEngine()->HasUndoManager() || !mpExtTextView->GetTextEngine()->GetUndoManager().GetUndoActionCount() )
+ {
+ pPopup->EnableItem( SV_MENU_EDIT_UNDO, FALSE );
+ }
+// if ( ( maSelection.Min() == 0 ) && ( maSelection.Max() == maText.Len() ) )
+// {
+// pPopup->EnableItem( SV_MENU_EDIT_SELECTALL, FALSE );
+// }
+ if ( !Edit::GetGetSpecialCharsFunction() )
+ {
+ USHORT nPos = pPopup->GetItemPos( SV_MENU_EDIT_INSERTSYMBOL );
+ pPopup->RemoveItem( nPos );
+ pPopup->RemoveItem( nPos-1 );
+ }
+
+ mbActivePopup = TRUE;
+ Point aPos = rCEvt.GetMousePosPixel();
+ if ( !rCEvt.IsMouseEvent() )
+ {
+ // !!! Irgendwann einmal Menu zentriert in der Selektion anzeigen !!!
+ Size aSize = GetOutputSizePixel();
+ aPos = Point( aSize.Width()/2, aSize.Height()/2 );
+ }
+// pPopup->RemoveDisabledEntries();
+ USHORT n = pPopup->Execute( this, aPos );
+ Edit::DeletePopupMenu( pPopup );
+ switch ( n )
+ {
+ case SV_MENU_EDIT_UNDO: mpExtTextView->Undo();
+ mpExtTextEngine->SetModified( TRUE );
+ mpExtTextEngine->Broadcast( TextHint( TEXT_HINT_MODIFIED ) );
+ break;
+ case SV_MENU_EDIT_CUT: mpExtTextView->Cut();
+ mpExtTextEngine->SetModified( TRUE );
+ mpExtTextEngine->Broadcast( TextHint( TEXT_HINT_MODIFIED ) );
+ break;
+ case SV_MENU_EDIT_COPY: mpExtTextView->Copy();
+ break;
+ case SV_MENU_EDIT_PASTE: mpExtTextView->Paste();
+ mpExtTextEngine->SetModified( TRUE );
+ mpExtTextEngine->Broadcast( TextHint( TEXT_HINT_MODIFIED ) );
+ break;
+ case SV_MENU_EDIT_DELETE: mpExtTextView->DeleteSelected();
+ mpExtTextEngine->SetModified( TRUE );
+ mpExtTextEngine->Broadcast( TextHint( TEXT_HINT_MODIFIED ) );
+ break;
+ case SV_MENU_EDIT_SELECTALL: mpExtTextView->SetSelection( TextSelection( TextPaM( 0, 0 ), TextPaM( 0xFFFFFFFF, 0xFFFF ) ) );
+ break;
+ case SV_MENU_EDIT_INSERTSYMBOL:
+ {
+ XubString aChars = Edit::GetGetSpecialCharsFunction()( this, GetFont() );
+ if ( aChars.Len() )
+ {
+ mpExtTextView->InsertText( aChars );
+ mpExtTextEngine->SetModified( TRUE );
+ mpExtTextEngine->Broadcast( TextHint( TEXT_HINT_MODIFIED ) );
+ }
+ }
+ break;
+ }
+ mbActivePopup = FALSE;
+ }
+ else
+ {
+ mpExtTextView->Command( rCEvt );
+ }
+ Window::Command( rCEvt );
+}
+
+void TextWindow::GetFocus()
+{
+ Window::GetFocus();
+ if ( !mbActivePopup )
+ {
+ BOOL bGotoCursor = !mpExtTextView->IsReadOnly();
+ if ( mbFocusSelectionHide && IsReallyVisible() && !mpExtTextView->IsReadOnly()
+ && ( !mbInMBDown || ( GetSettings().GetStyleSettings().GetSelectionOptions() & SELECTION_OPTION_FOCUS ) ) )
+ {
+ // Alles selektieren, aber nicht scrollen
+ BOOL bAutoScroll = mpExtTextView->IsAutoScroll();
+ mpExtTextView->SetAutoScroll( FALSE );
+ mpExtTextView->SetSelection( TextSelection( TextPaM( 0, 0 ), TextPaM( 0xFFFF, 0xFFFF ) ) );
+ mpExtTextView->SetAutoScroll( bAutoScroll );
+ bGotoCursor = FALSE;
+ }
+ mpExtTextView->SetPaintSelection( TRUE );
+ mpExtTextView->ShowCursor( bGotoCursor );
+ }
+}
+
+void TextWindow::LoseFocus()
+{
+ Window::LoseFocus();
+
+ if ( mbFocusSelectionHide && !mbActivePopup )
+ mpExtTextView->SetPaintSelection( FALSE );
+}
+
+BOOL TextWindow::QueryDrop( DropEvent& rEvt )
+{
+ return mpExtTextView->QueryDrop( rEvt );
+}
+
+BOOL TextWindow::Drop( const DropEvent& rEvt )
+{
+ return mpExtTextView->Drop( rEvt );
+}
+
+
+MultiLineEdit::MultiLineEdit( Window* pParent, WinBits nWinStyle )
+ : Edit( pParent, nWinStyle )
+{
+ SetType( WINDOW_MULTILINEEDIT );
+ pImpSvMEdit = new ImpSvMEdit( this, nWinStyle );
+ ImplInitSettings( TRUE, TRUE, TRUE );
+ pUpdateDataTimer = 0;
+
+ SetCompoundControl( TRUE );
+ SetStyle( ImplInitStyle( nWinStyle ) );
+}
+
+MultiLineEdit::MultiLineEdit( Window* pParent, const ResId& rResId )
+ : Edit( pParent, rResId.SetRT( RSC_MULTILINEEDIT ) )
+{
+ SetType( WINDOW_MULTILINEEDIT );
+ WinBits nWinStyle = rResId.aWinBits;
+ pImpSvMEdit = new ImpSvMEdit( this, nWinStyle );
+ ImplInitSettings( TRUE, TRUE, TRUE );
+ pUpdateDataTimer = 0;
+
+ USHORT nMaxLen = Edit::GetMaxTextLen();
+ if ( nMaxLen )
+ SetMaxTextLen( nMaxLen );
+
+ SetText( Edit::GetText() );
+
+ if ( IsVisible() )
+ pImpSvMEdit->Resize();
+
+ SetCompoundControl( TRUE );
+ SetStyle( ImplInitStyle( nWinStyle ) );
+}
+
+MultiLineEdit::~MultiLineEdit()
+{
+ delete pImpSvMEdit;
+ delete pUpdateDataTimer;
+}
+
+WinBits MultiLineEdit::ImplInitStyle( WinBits nStyle )
+{
+ if ( !(nStyle & WB_NOTABSTOP) )
+ nStyle |= WB_TABSTOP;
+
+ if ( !(nStyle & WB_NOGROUP) )
+ nStyle |= WB_GROUP;
+
+ if ( !(nStyle & WB_IGNORETAB ))
+ nStyle |= WINDOW_DLGCTRL_MOD1TAB;
+
+ return nStyle;
+}
+
+
+void MultiLineEdit::ImplInitSettings( BOOL bFont, BOOL bForeground, BOOL bBackground )
+{
+ const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
+
+ // Der Font muss immer mit manipuliert werden, weil die TextEngine
+ // sich nicht um TextColor/Background kuemmert
+
+ Color aTextColor = rStyleSettings.GetFieldTextColor();
+ if ( IsControlForeground() )
+ aTextColor = GetControlForeground();
+
+ Font aFont = rStyleSettings.GetFieldFont();
+ if ( IsControlFont() )
+ aFont.Merge( GetControlFont() );
+ aFont.SetTransparent( FALSE );
+ SetZoomedPointFont( aFont );
+ Font TheFont = GetFont();
+ TheFont.SetColor( aTextColor );
+ TheFont.SetFillColor( IsControlBackground() ? GetControlBackground() : rStyleSettings.GetFieldColor() );
+ pImpSvMEdit->GetTextWindow()->SetFont( TheFont );
+ pImpSvMEdit->GetTextWindow()->GetTextEngine()->SetFont( TheFont );
+ pImpSvMEdit->GetTextWindow()->SetTextColor( aTextColor );
+
+ if ( bBackground )
+ {
+ if( IsControlBackground() )
+ pImpSvMEdit->GetTextWindow()->SetBackground( GetControlBackground() );
+ else
+ pImpSvMEdit->GetTextWindow()->SetBackground( rStyleSettings.GetFieldColor() );
+ // Auch am MultiLineEdit einstellen, weil die TextComponent
+ // ggf. die Scrollbars hidet.
+ SetBackground( pImpSvMEdit->GetTextWindow()->GetBackground() );
+ }
+}
+
+void MultiLineEdit::Modify()
+{
+ aModifyHdlLink.Call( this );
+ if ( pUpdateDataTimer )
+ pUpdateDataTimer->Start();
+}
+
+IMPL_LINK( MultiLineEdit, ImpUpdateDataHdl, Timer*, EMPTYARG )
+{
+ UpdateData();
+ return 0;
+}
+
+void MultiLineEdit::UpdateData()
+{
+ aUpdateDataHdlLink.Call( this );
+}
+
+void MultiLineEdit::SetModifyFlag()
+{
+ pImpSvMEdit->SetModified( TRUE );
+}
+
+void MultiLineEdit::ClearModifyFlag()
+{
+ pImpSvMEdit->SetModified( TRUE );
+}
+
+BOOL MultiLineEdit::IsModified() const
+{
+ return pImpSvMEdit->IsModified();
+}
+
+void MultiLineEdit::EnableUpdateData( ULONG nTimeout )
+{
+ if ( !nTimeout )
+ DisableUpdateData();
+ else
+ {
+ if ( !pUpdateDataTimer )
+ {
+ pUpdateDataTimer = new Timer;
+ pUpdateDataTimer->SetTimeoutHdl( LINK( this, MultiLineEdit, ImpUpdateDataHdl ) );
+ }
+ pUpdateDataTimer->SetTimeout( nTimeout );
+ }
+}
+
+void MultiLineEdit::SetReadOnly( BOOL bReadOnly )
+{
+ pImpSvMEdit->SetReadOnly( bReadOnly );
+ Edit::SetReadOnly( bReadOnly );
+}
+
+BOOL MultiLineEdit::IsReadOnly() const
+{
+ return pImpSvMEdit->IsReadOnly();
+}
+
+void MultiLineEdit::SetMaxTextLen( ULONG nMaxLen )
+{
+ pImpSvMEdit->SetMaxTextLen( nMaxLen );
+}
+
+ULONG MultiLineEdit::GetMaxTextLen() const
+{
+ return pImpSvMEdit->GetMaxTextLen();
+}
+
+void MultiLineEdit::ReplaceSelected( const String& rStr )
+{
+ pImpSvMEdit->InsertText( rStr );
+}
+
+void MultiLineEdit::DeleteSelected()
+{
+ pImpSvMEdit->InsertText( String() );
+}
+
+String MultiLineEdit::GetSelected() const
+{
+ return pImpSvMEdit->GetSelected();
+}
+
+void MultiLineEdit::Cut()
+{
+ pImpSvMEdit->Cut();
+}
+
+void MultiLineEdit::Copy()
+{
+ pImpSvMEdit->Copy();
+}
+
+void MultiLineEdit::Paste()
+{
+ pImpSvMEdit->Paste();
+}
+
+void MultiLineEdit::SetText( const String& rStr )
+{
+ pImpSvMEdit->SetText( rStr );
+}
+
+String MultiLineEdit::GetText() const
+{
+ return pImpSvMEdit->GetText();
+}
+
+String MultiLineEdit::GetTextLines() const
+{
+ return pImpSvMEdit->GetTextLines();
+}
+
+void MultiLineEdit::Resize()
+{
+ pImpSvMEdit->Resize();
+}
+
+void MultiLineEdit::GetFocus()
+{
+ Edit::GetFocus();
+ pImpSvMEdit->GetFocus();
+}
+
+void MultiLineEdit::SetSelection( const Selection& rSelection )
+{
+ pImpSvMEdit->SetSelection( rSelection );
+}
+
+Selection MultiLineEdit::GetSelection() const
+{
+ return pImpSvMEdit->GetSelection();
+}
+
+Size MultiLineEdit::CalcMinimumSize() const
+{
+ Size aSz = pImpSvMEdit->CalcMinimumSize();
+
+ long nLeft, nTop, nRight, nBottom;
+ ((Window*)this)->GetBorder( nLeft, nTop, nRight, nBottom );
+ aSz.Width() += nLeft+nRight;
+ aSz.Height() += nTop+nBottom;
+
+ return aSz;
+}
+
+Size MultiLineEdit::CalcAdjustedSize( const Size& rPrefSize ) const
+{
+ Size aSz = rPrefSize;
+ long nLeft, nTop, nRight, nBottom;
+ ((Window*)this)->GetBorder( nLeft, nTop, nRight, nBottom );
+
+ // In der Hoehe auf ganze Zeilen justieren
+
+ long nHeight = aSz.Height() - nTop - nBottom;
+ long nLineHeight = pImpSvMEdit->CalcSize( 1, 1 ).Height();
+ long nLines = nHeight / nLineHeight;
+ if ( nLines < 1 )
+ nLines = 1;
+
+ aSz.Height() = nLines * nLineHeight;
+ aSz.Height() += nTop+nBottom;
+
+ return aSz;
+}
+
+Size MultiLineEdit::CalcSize( USHORT nColumns, USHORT nLines ) const
+{
+ Size aSz = pImpSvMEdit->CalcSize( nColumns, nLines );
+
+ long nLeft, nTop, nRight, nBottom;
+ ((Window*)this)->GetBorder( nLeft, nTop, nRight, nBottom );
+ aSz.Width() += nLeft+nRight;
+ aSz.Height() += nTop+nBottom;
+ return aSz;
+}
+
+void MultiLineEdit::GetMaxVisColumnsAndLines( USHORT& rnCols, USHORT& rnLines ) const
+{
+ pImpSvMEdit->GetMaxVisColumnsAndLines( rnCols, rnLines );
+}
+
+void MultiLineEdit::StateChanged( StateChangedType nType )
+{
+ if( nType == STATE_CHANGE_ENABLE )
+ {
+ pImpSvMEdit->Enable( IsEnabled() );
+ }
+ else if( nType == STATE_CHANGE_READONLY )
+ {
+ pImpSvMEdit->SetReadOnly( IsReadOnly() );
+ }
+ else if ( nType == STATE_CHANGE_ZOOM )
+ {
+ pImpSvMEdit->GetTextWindow()->SetZoom( GetZoom() );
+ ImplInitSettings( TRUE, FALSE, FALSE );
+ Resize();
+ }
+ else if ( nType == STATE_CHANGE_CONTROLFONT )
+ {
+ ImplInitSettings( TRUE, FALSE, FALSE );
+ Resize();
+ Invalidate();
+ }
+ else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
+ {
+ ImplInitSettings( FALSE, TRUE, FALSE );
+ Invalidate();
+ }
+ else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
+ {
+ ImplInitSettings( FALSE, FALSE, TRUE );
+ Invalidate();
+ }
+ else if ( nType == STATE_CHANGE_STYLE )
+ {
+ pImpSvMEdit->SetAlign( GetStyle() );
+ SetStyle( ImplInitStyle( GetStyle() ) );
+ }
+
+ Control::StateChanged( nType );
+}
+
+void MultiLineEdit::DataChanged( const DataChangedEvent& rDCEvt )
+{
+ if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
+ (rDCEvt.GetFlags() & SETTINGS_STYLE) )
+ {
+ ImplInitSettings( TRUE, TRUE, TRUE );
+ Resize();
+ Invalidate();
+ }
+ else
+ Control::DataChanged( rDCEvt );
+}
+
+void MultiLineEdit::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, ULONG nFlags )
+{
+ ImplInitSettings( TRUE, TRUE, TRUE );
+
+ Point aPos = pDev->LogicToPixel( rPos );
+ Size aSize = pDev->LogicToPixel( rSize );
+ Font aFont = pImpSvMEdit->GetTextWindow()->GetDrawPixelFont( pDev );
+ aFont.SetTransparent( TRUE );
+ OutDevType eOutDevType = pDev->GetOutDevType();
+
+ pDev->Push();
+ pDev->SetMapMode();
+ pDev->SetFont( aFont );
+ pDev->SetTextFillColor();
+
+ // Border/Background
+ pDev->SetLineColor();
+ pDev->SetFillColor();
+ BOOL bBorder = !(nFlags & WINDOW_DRAW_NOBORDER ) && (GetStyle() & WB_BORDER);
+ BOOL bBackground = !(nFlags & WINDOW_DRAW_NOBACKGROUND) && IsControlBackground();
+ if ( bBorder || bBackground )
+ {
+ Rectangle aRect( aPos, aSize );
+ if ( bBorder )
+ {
+ DecorationView aDecoView( pDev );
+ aRect = aDecoView.DrawFrame( aRect, FRAME_DRAW_DOUBLEIN );
+ }
+ if ( bBackground )
+ {
+ pDev->SetFillColor( GetControlBackground() );
+ pDev->DrawRect( aRect );
+ }
+ }
+
+ // Inhalt
+ if ( ( nFlags & WINDOW_DRAW_MONO ) || ( eOutDevType == OUTDEV_PRINTER ) )
+ pDev->SetTextColor( Color( COL_BLACK ) );
+ else
+ {
+ if ( !(nFlags & WINDOW_DRAW_NODISABLE ) && !IsEnabled() )
+ {
+ const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
+ pDev->SetTextColor( rStyleSettings.GetDisableColor() );
+ }
+ else
+ {
+ pDev->SetTextColor( GetTextColor() );
+ }
+ }
+
+ XubString aText = GetText();
+ Size aTextSz( pDev->GetTextWidth( aText ), pDev->GetTextHeight() );
+ ULONG nLines = (ULONG) (aSize.Height() / aTextSz.Height());
+ if ( !nLines )
+ nLines = 1;
+ aTextSz.Height() = nLines*aTextSz.Height();
+ long nOnePixel = GetDrawPixel( pDev, 1 );
+ long nOffX = 3*nOnePixel;
+ long nOffY = 2*nOnePixel;
+
+ // Clipping?
+ if ( ( nOffY < 0 ) || ( (nOffY+aTextSz.Height()) > aSize.Height() ) || ( (nOffX+aTextSz.Width()) > aSize.Width() ) )
+ {
+ Rectangle aClip( aPos, aSize );
+ if ( aTextSz.Height() > aSize.Height() )
+ aClip.Bottom() += aTextSz.Height() - aSize.Height() + 1; // Damit HP-Drucker nicht 'weg-optimieren'
+ pDev->IntersectClipRegion( aClip );
+ }
+
+ TextEngine aTE;
+ aTE.SetText( GetText() );
+ aTE.SetMaxTextWidth( aSize.Width() );
+ aTE.SetFont( aFont );
+ aTE.SetTextAlign( pImpSvMEdit->GetTextWindow()->GetTextEngine()->GetTextAlign() );
+ aTE.Draw( pDev, Point( aPos.X() + nOffX, aPos.Y() + nOffY ) );
+
+ pDev->Pop();
+}
+
+long MultiLineEdit::Notify( NotifyEvent& rNEvt )
+{
+ long nDone = 0;
+ if( rNEvt.GetType() == EVENT_COMMAND )
+ {
+ nDone = pImpSvMEdit->HandleCommand( *rNEvt.GetCommandEvent() );
+ }
+ return nDone ? nDone : Edit::Notify( rNEvt );
+}
+
+long MultiLineEdit::PreNotify( NotifyEvent& rNEvt )
+{
+ long nDone = 0;
+
+ if( ( rNEvt.GetType() == EVENT_KEYINPUT ) && ( !GetTextView()->IsCursorEnabled() ) )
+ {
+ const KeyEvent& rKEvent = *rNEvt.GetKeyEvent();
+ if ( !rKEvent.GetKeyCode().IsShift() && ( rKEvent.GetKeyCode().GetGroup() == KEYGROUP_CURSOR ) )
+ {
+ nDone = 1;
+ TextSelection aSel = pImpSvMEdit->GetTextWindow()->GetTextView()->GetSelection();
+ if ( aSel.HasRange() )
+ {
+ aSel.GetStart() = aSel.GetEnd();
+ pImpSvMEdit->GetTextWindow()->GetTextView()->SetSelection( aSel );
+ }
+ else
+ {
+ switch ( rKEvent.GetKeyCode().GetCode() )
+ {
+ case KEY_UP:
+ {
+ if ( pImpSvMEdit->GetVScrollBar() )
+ pImpSvMEdit->GetVScrollBar()->DoScrollAction( SCROLL_LINEUP );
+ }
+ break;
+ case KEY_DOWN:
+ {
+ if ( pImpSvMEdit->GetVScrollBar() )
+ pImpSvMEdit->GetVScrollBar()->DoScrollAction( SCROLL_LINEDOWN );
+ }
+ break;
+ case KEY_PAGEUP :
+ {
+ if ( pImpSvMEdit->GetVScrollBar() )
+ pImpSvMEdit->GetVScrollBar()->DoScrollAction( SCROLL_PAGEUP );
+ }
+ break;
+ case KEY_PAGEDOWN:
+ {
+ if ( pImpSvMEdit->GetVScrollBar() )
+ pImpSvMEdit->GetVScrollBar()->DoScrollAction( SCROLL_PAGEDOWN );
+ }
+ break;
+ case KEY_LEFT:
+ {
+ if ( pImpSvMEdit->GetHScrollBar() )
+ pImpSvMEdit->GetHScrollBar()->DoScrollAction( SCROLL_LINEUP );
+ }
+ break;
+ case KEY_RIGHT:
+ {
+ if ( pImpSvMEdit->GetHScrollBar() )
+ pImpSvMEdit->GetHScrollBar()->DoScrollAction( SCROLL_LINEDOWN );
+ }
+ break;
+ case KEY_HOME:
+ {
+ if ( rKEvent.GetKeyCode().IsMod1() )
+ pImpSvMEdit->GetTextWindow()->GetTextView()->
+ SetSelection( TextSelection( TextPaM( 0, 0 ) ) );
+ }
+ break;
+ case KEY_END:
+ {
+ if ( rKEvent.GetKeyCode().IsMod1() )
+ pImpSvMEdit->GetTextWindow()->GetTextView()->
+ SetSelection( TextSelection( TextPaM( 0xFFFF, 0xFFFF ) ) );
+ }
+ break;
+ default:
+ {
+ nDone = 0;
+ }
+ }
+ }
+ }
+ }
+
+ return nDone ? nDone : Edit::PreNotify( rNEvt );
+}
+
+//
+// Internas fuer abgeleitete Klassen, z.B. TextComponent
+
+ExtTextEngine* MultiLineEdit::GetTextEngine() const
+{
+ return pImpSvMEdit->GetTextWindow()->GetTextEngine();
+}
+
+ExtTextView* MultiLineEdit::GetTextView() const
+{
+ return pImpSvMEdit->GetTextWindow()->GetTextView();
+}
+
+ScrollBar* MultiLineEdit::GetHScrollBar() const
+{
+ return pImpSvMEdit->GetHScrollBar();
+}
+
+
+ScrollBar* MultiLineEdit::GetVScrollBar() const
+{
+ return pImpSvMEdit->GetVScrollBar();
+}
+
+void MultiLineEdit::EnableFocusSelectionHide( BOOL bHide )
+{
+ pImpSvMEdit->GetTextWindow()->SetAutoFocusHide( bHide );
+}
+
+BOOL MultiLineEdit::IsFocusSelectionHideEnabled() const
+{
+ return pImpSvMEdit->GetTextWindow()->IsAutoFocusHide();
+}
diff --git a/svtools/source/edit/sychconv.cxx b/svtools/source/edit/sychconv.cxx
new file mode 100644
index 000000000000..e9bae812c5a5
--- /dev/null
+++ b/svtools/source/edit/sychconv.cxx
@@ -0,0 +1,139 @@
+/*************************************************************************
+ *
+ * $RCSfile: sychconv.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: hr $ $Date: 2000-09-18 16:58:58 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (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.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#ifndef _SYCHCONV_HXX
+#include "sychconv.hxx"
+#endif
+#ifndef _SV_OUTDEV_HXX
+#include <vcl/outdev.hxx>
+#endif
+
+const BOOL SymCharConverter::Convert( Font& rFont, UniString& rString, OutputDevice* pDev )
+{
+ // hibyte 0 = exact matching
+ // 1 = little differences,
+ // 2 = the converted character does not look like the original but got the same meaning
+ // 3 = the destination does not match looking and meaning of the original
+
+ static USHORT __READONLY_DATA aWingdingsToStarBatsTable[ 256 - 32 ] =
+ {
+ 0x0020, 0x0238, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0174, 0x02BA, 0x017B, 0x017C, 0x037C, 0x037C, 0x037C, 0x037C,
+ 0x0000, 0x0000, 0x0372, 0x0272, 0x0372, 0x0000, 0x0000, 0x0374, 0x0279, 0x0000, 0x027A, 0x0000, 0x0178, 0x0278, 0x0000, 0x0137,
+ 0x027E, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x017D, 0x0000, 0x0000, 0x0000, 0x0021, 0x03AC, 0x00AD, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x01C0, 0x0000, 0x0000, 0x0286, 0x0286, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0022, 0x0023, 0x0024, 0x0025,
+ 0x0026, 0x0027, 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x0133, 0x0000, 0x0000, 0x0000, 0x0000, 0x0193, 0x0194, 0x0000,
+ 0x0067, 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F, 0x0070, 0x0071, 0x005C, 0x005D, 0x005E, 0x005F, 0x0060,
+ 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x01A5, 0x0095,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x002E, 0x0000, 0x0125, 0x0000, 0x0000, 0x0000, 0x014B, 0x024D, 0x014E, 0x014A,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x002F, 0x0000, 0x0000, 0x0000, 0x0035, 0x0000, 0x0000, 0x0000,
+ 0x0030, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0031, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x01B1,
+ 0x01AF, 0x01B2, 0x01B0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0150, 0x0032, 0x0033, 0x0034, 0x01C8
+ };
+
+ static USHORT __READONLY_DATA aMonotypeSortsToStarBatsTable[ 256 - 32 ]=
+ {
+ 0x0020, 0x00cb, 0x00cb, 0x00cb, 0x00cb, 0x0074, 0x00ba, 0x0021, 0x00cc, 0x007b, 0x0036, 0x007d, 0x007e, 0x0037, 0x0038, 0x0038,
+ 0x0039, 0x0038, 0x0038, 0x0039, 0x003a, 0x004f, 0x0050, 0x004f, 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0086, 0x0086, 0x0086,
+ 0x0052, 0x00cd, 0x0044, 0x0045, 0x0046, 0x0047, 0x0041, 0x0041, 0x0058, 0x0057, 0x0075, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059,
+ 0x005a, 0x004b, 0x004b, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004e, 0x004b, 0x004b, 0x00ce, 0x00ce, 0x00ce,
+ 0x00ce, 0x00ce, 0x00ce, 0x00ce, 0x00cf, 0x00cf, 0x00cf, 0x00cf, 0x00cf, 0x00cf, 0x00b9, 0x00b9, 0x003b, 0x003c, 0x003d, 0x003e,
+ 0x003f, 0x003e, 0x0040, 0x00c5, 0x00c4, 0x002b, 0x002c, 0x00d0, 0x00d1, 0x00d1, 0x00d1, 0x0091, 0x0092, 0x0093, 0x0094, 0x0000,
+ 0x00d2, 0x00d3, 0x00d2, 0x00d3, 0x00d2, 0x00d3, 0x00d2, 0x00d3, 0x00d2, 0x00d3, 0x00d2, 0x00d3, 0x00d2, 0x00d3, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x00d4, 0x00d4, 0x00d4, 0x00d6, 0x00d6, 0x00d4, 0x00d4, 0x00d5, 0x002a, 0x00d6, 0x00d7, 0x0068, 0x0069, 0x006a, 0x006b,
+ 0x006c, 0x006d, 0x006e, 0x006f, 0x0070, 0x0071, 0x005d, 0x005e, 0x005f, 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066,
+ 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, 0x0070, 0x0071, 0x005d, 0x005e, 0x005f, 0x0060, 0x0061, 0x0062,
+ 0x0063, 0x0064, 0x0065, 0x0066, 0x0030, 0x0031, 0x00d8, 0x00d9, 0x00da, 0x00bc, 0x00db, 0x00bc, 0x00bc, 0x00bc, 0x00bc, 0x0031,
+ 0x0031, 0x0031, 0x002f, 0x002f, 0x002f, 0x00be, 0x00be, 0x0031, 0x0031, 0x00af, 0x00af, 0x00af, 0x00af, 0x00af, 0x00af, 0x00af,
+ 0x0000, 0x00af, 0x0035, 0x00dc, 0x00da, 0x00dc, 0x00db, 0x00da, 0x00dc, 0x00db, 0x00dc, 0x00dc, 0x00dc, 0x00dc, 0x00af, 0x0000
+ };
+
+ const USHORT* pTransTable = NULL;
+
+ BOOL bIsAvailable = ( pDev ) ? pDev->IsFontAvailable( rFont.GetName() ) : FALSE;
+ if ( !bIsAvailable )
+ {
+ if ( rFont.GetName().CompareToAscii( RTL_CONSTASCII_STRINGPARAM( "Wingdings" ) ) == COMPARE_EQUAL )
+ pTransTable = &aWingdingsToStarBatsTable[ 0 ];
+ else if ( rFont.GetName().CompareToAscii( RTL_CONSTASCII_STRINGPARAM( "Monotype Sorts" ) ) == COMPARE_EQUAL )
+ pTransTable = &aMonotypeSortsToStarBatsTable[ 0 ];
+ }
+ if ( pTransTable )
+ {
+ sal_Unicode c;
+ for ( UINT16 i = rString.Len(); i--; )
+ {
+ c = rString.GetChar( i );
+ c -= 32;
+ c = ( ((UINT16)c) >= 224 ) ? 0 : (sal_Unicode) pTransTable[ c ];
+ if ( !c ) // if character is out of range or not matching
+ c = 0xA5; // we will default a StarBats-Bullet
+ rString.SetChar( i, c );
+ }
+ rFont.SetCharSet( RTL_TEXTENCODING_SYMBOL );
+ rFont.SetName( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "StarBats" ) ) );
+ return TRUE;
+ }
+ else return FALSE;
+};
diff --git a/svtools/source/edit/textdat2.hxx b/svtools/source/edit/textdat2.hxx
new file mode 100644
index 000000000000..f96ec1890291
--- /dev/null
+++ b/svtools/source/edit/textdat2.hxx
@@ -0,0 +1,338 @@
+/*************************************************************************
+ *
+ * $RCSfile: textdat2.hxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: hr $ $Date: 2000-09-18 16:58:58 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (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.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+
+#ifndef _TEXTDAT2_HXX
+#define _TEXTDAT2_HXX
+
+#ifndef _SVARRAY_HXX
+#include <svarray.hxx>
+#endif
+
+#ifndef _LIST_HXX //autogen
+#include <tools/list.hxx>
+#endif
+
+#ifndef _SV_SELENG_HXX //autogen
+#include <vcl/seleng.hxx>
+#endif
+
+#ifndef _SV_VIRDEV_HXX //autogen
+#include <vcl/virdev.hxx>
+#endif
+
+#ifndef _SV_CURSOR_HXX
+#include <vcl/cursor.hxx>
+#endif
+
+class TextNode;
+class TextView;
+
+#define PORTIONKIND_TEXT 0
+#define PORTIONKIND_TAB 1
+
+#define DELMODE_SIMPLE 0
+#define DELMODE_RESTOFWORD 1
+#define DELMODE_RESTOFCONTENT 2
+
+#define DEL_LEFT 1
+#define DEL_RIGHT 2
+#define TRAVEL_X_DONTKNOW 0xFFFF
+#define MAXCHARSINPARA 0x3FFF-CHARPOSGROW
+
+#define LINE_SEP 0x0A
+
+
+class TextPortion
+{
+private:
+ USHORT nLen;
+ long nWidth;
+ BYTE nKind;
+
+ TextPortion() { nLen = 0; nKind = PORTIONKIND_TEXT; nWidth = -1;}
+
+public:
+ TextPortion( USHORT nL ) {
+ nLen = nL;
+ nKind = PORTIONKIND_TEXT;
+ nWidth= -1;
+ }
+
+ USHORT GetLen() const { return nLen; }
+ USHORT& GetLen() { return nLen; }
+
+ long GetWidth()const { return nWidth; }
+ long& GetWidth() { return nWidth; }
+
+ BYTE GetKind() const { return nKind; }
+ BYTE& GetKind() { return nKind; }
+
+ BOOL HasValidSize() const { return nWidth != (-1); }
+};
+
+
+
+typedef TextPortion* TextPortionPtr;
+SV_DECL_PTRARR( TextPortionArray, TextPortionPtr, 0, 8 );
+
+class TETextPortionList : public TextPortionArray
+{
+public:
+ TETextPortionList();
+ ~TETextPortionList();
+
+ void Reset();
+ USHORT FindPortion( USHORT nCharPos, USHORT& rPortionStart );
+ void DeleteFromPortion( USHORT nDelFrom );
+};
+
+
+
+class TextLine
+{
+private:
+ USHORT mnStart;
+ USHORT mnEnd;
+ USHORT mnStartPortion;
+ USHORT mnEndPortion;
+
+ short mnStartX;
+
+ BOOL mbInvalid; // fuer geschickte Formatierung/Ausgabe
+
+public:
+ TextLine() {
+ mnStart = mnEnd = 0;
+ mnStartPortion = mnEndPortion = 0;
+ mnStartX = 0;
+ mbInvalid = TRUE;
+ }
+
+ BOOL IsIn( USHORT nIndex ) const
+ { return ( (nIndex >= mnStart ) && ( nIndex < mnEnd ) ); }
+
+ BOOL IsIn( USHORT nIndex, BOOL bInclEnd ) const
+ { return ( ( nIndex >= mnStart ) && ( bInclEnd ? ( nIndex <= mnEnd ) : ( nIndex < mnEnd ) ) ); }
+
+ void SetStart( USHORT n ) { mnStart = n; }
+ USHORT GetStart() const { return mnStart; }
+ USHORT& GetStart() { return mnStart; }
+
+ void SetEnd( USHORT n ) { mnEnd = n; }
+ USHORT GetEnd() const { return mnEnd; }
+ USHORT& GetEnd() { return mnEnd; }
+
+ void SetStartPortion( USHORT n ) { mnStartPortion = n; }
+ USHORT GetStartPortion() const { return mnStartPortion; }
+ USHORT& GetStartPortion() { return mnStartPortion; }
+
+ void SetEndPortion( USHORT n ) { mnEndPortion = n; }
+ USHORT GetEndPortion() const { return mnEndPortion; }
+ USHORT& GetEndPortion() { return mnEndPortion; }
+
+ USHORT GetLen() const { return mnEnd - mnStart; }
+
+ BOOL IsInvalid() const { return mbInvalid; }
+ BOOL IsValid() const { return !mbInvalid; }
+ void SetInvalid() { mbInvalid = TRUE; }
+ void SetValid() { mbInvalid = FALSE; }
+
+ BOOL IsEmpty() const { return (mnEnd > mnStart) ? FALSE : TRUE; }
+
+ short GetStartX() const { return mnStartX; }
+ void SetStartX( short n ) { mnStartX = n; }
+
+ inline BOOL operator == ( const TextLine& rLine ) const;
+ inline BOOL operator != ( const TextLine& rLine ) const;
+};
+
+typedef TextLine* TextLinePtr;
+SV_DECL_PTRARR_DEL( TextLines, TextLinePtr, 1, 4 );
+
+inline BOOL TextLine::operator == ( const TextLine& rLine ) const
+{
+ return ( ( mnStart == rLine.mnStart ) &&
+ ( mnEnd == rLine.mnEnd ) &&
+ ( mnStartPortion == rLine.mnStartPortion ) &&
+ ( mnEndPortion == rLine.mnEndPortion ) );
+}
+
+inline BOOL TextLine::operator != ( const TextLine& rLine ) const
+{
+ return !( *this == rLine );
+}
+
+
+
+class TEParaPortion
+{
+private:
+ TextNode* mpNode;
+
+ TextLines maLines;
+ TETextPortionList maTextPortions;
+
+ USHORT mnInvalidPosStart;
+ short mnInvalidDiff;
+
+ BOOL mbInvalid;
+ BOOL mbSimple; // nur lineares Tippen
+
+
+ TEParaPortion( const TEParaPortion& ) {;}
+
+public:
+ TEParaPortion( TextNode* pNode );
+ ~TEParaPortion();
+
+
+ BOOL IsInvalid() const { return mbInvalid; }
+ BOOL IsSimpleInvalid() const { return mbSimple; }
+ void SetNotSimpleInvalid() { mbSimple = FALSE; }
+ void SetValid() { mbInvalid = FALSE; mbSimple = TRUE;}
+
+ void MarkInvalid( USHORT nStart, short nDiff);
+ void MarkSelectionInvalid( USHORT nStart, USHORT nEnd );
+
+ USHORT GetInvalidPosStart() const { return mnInvalidPosStart; }
+ short GetInvalidDiff() const { return mnInvalidDiff; }
+
+ TextNode* GetNode() const { return mpNode; }
+ TextLines& GetLines() { return maLines; }
+ TETextPortionList& GetTextPortions() { return maTextPortions; }
+
+ USHORT GetLineNumber( USHORT nIndex, BOOL bInclEnd );
+ void CorrectValuesBehindLastFormattedLine( USHORT nLastFormattedLine );
+};
+
+
+
+
+DECLARE_LIST( DummyTEParaPortionList, TEParaPortion* );
+
+class TEParaPortions : public DummyTEParaPortionList
+{
+public:
+ TEParaPortions();
+ ~TEParaPortions();
+
+ void Reset();
+// long GetYOffset( TEParaPortion* pPPortion );
+// USHORT FindParagraph( long nYOffset );
+};
+
+
+class TextSelFunctionSet: public FunctionSet
+{
+private:
+ TextView* mpView;
+
+public:
+ TextSelFunctionSet( TextView* pView );
+
+ virtual void BeginDrag();
+
+ virtual void CreateAnchor();
+
+ virtual BOOL SetCursorAtPoint( const Point& rPointPixel, BOOL bDontSelectAtCursor = FALSE );
+
+ virtual BOOL IsSelectionAtPoint( const Point& rPointPixel );
+ virtual void DeselectAll();
+
+ virtual void DeselectAtPoint( const Point& );
+ virtual void DestroyAnchor();
+};
+
+
+class IdleFormatter : public Timer
+{
+private:
+ TextView* mpView;
+ USHORT mnRestarts;
+
+public:
+ IdleFormatter();
+ ~IdleFormatter();
+
+ void DoIdleFormat( TextView* pV );
+ void ForceTimeout();
+ void ResetRestarts() { mnRestarts = 0; }
+ TextView* GetView() { return mpView; }
+};
+
+struct TextDDInfo
+{
+ Cursor maCursor;
+ TextPaM maDropPos;
+
+ BOOL mbStarterOfDD;
+ BOOL mbVisCursor;
+
+ TextDDInfo()
+ {
+ maCursor.SetStyle( CURSOR_SHADOW );
+ mbStarterOfDD = FALSE;
+ mbVisCursor = FALSE;
+ }
+};
+
+#endif // _TEXTDAT2_HXX
diff --git a/svtools/source/edit/textdata.cxx b/svtools/source/edit/textdata.cxx
new file mode 100644
index 000000000000..3b995edfbe50
--- /dev/null
+++ b/svtools/source/edit/textdata.cxx
@@ -0,0 +1,329 @@
+/*************************************************************************
+ *
+ * $RCSfile: textdata.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: hr $ $Date: 2000-09-18 16:58:58 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (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.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#include <textdata.hxx>
+#include <textdat2.hxx>
+
+#include <tools/debug.hxx>
+
+SV_IMPL_PTRARR( TextLines, TextLinePtr );
+
+
+ // -------------------------------------------------------------------------
+// (+) 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 );
+}
+
+USHORT TETextPortionList::FindPortion( USHORT nCharPos, USHORT& nPortionStart )
+{
+ // Bei nCharPos an Portion-Grenze wird die linke Portion gefunden
+ USHORT nTmpPos = 0;
+ for ( USHORT nPortion = 0; nPortion < Count(); nPortion++ )
+ {
+ TextPortion* pPortion = GetObject( nPortion );
+ nTmpPos += pPortion->GetLen();
+ if ( nTmpPos >= nCharPos )
+ {
+ nPortionStart = nTmpPos - pPortion->GetLen();
+ return nPortion;
+ }
+ }
+ DBG_ERROR( "FindPortion: Nicht gefunden!" );
+ return ( Count() - 1 );
+}
+
+ // -------------------------------------------------------------------------
+// (+) 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 ) )
+ {
+ mnInvalidDiff += nDiff;
+ }
+ // Einfaches hintereinander loeschen
+ else if ( ( nDiff < 0 ) && ( mnInvalidDiff < 0 ) && ( mnInvalidPosStart == nStart ) )
+ {
+ mnInvalidPosStart += nDiff;
+ mnInvalidDiff += nDiff;
+ }
+ 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;
+ }
+ }
+ mbInvalid = TRUE;
+}
+
+void TEParaPortion::MarkSelectionInvalid( USHORT nStart, USHORT nEnd )
+{
+ if ( mbInvalid == FALSE )
+ {
+ mnInvalidPosStart = nStart;
+// nInvalidPosEnd = nEnd;
+ }
+ else
+ {
+ mnInvalidPosStart = Min( mnInvalidPosStart, nStart );
+// nInvalidPosEnd = pNode->Len();
+ }
+ 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!
+ short nPDiff = -( nPortionDiff-1 );
+ short nTDiff = -( nTextDiff-1 );
+ if ( nPDiff || nTDiff )
+ {
+ for ( USHORT nL = nLastFormattedLine+1; nL < nLines; nL++ )
+ {
+ TextLine* pLine = maLines[ nL ];
+
+ pLine->GetStartPortion() += nPDiff;
+ pLine->GetEndPortion() += nPDiff;
+
+ pLine->GetStart() += nTDiff;
+ pLine->GetEnd() += nTDiff;
+
+ pLine->SetValid();
+ }
+ }
+ }
+}
+
+ // -------------------------------------------------------------------------
+// (+) class TEParaPortions
+// -------------------------------------------------------------------------
+TEParaPortions::TEParaPortions()
+{
+}
+
+TEParaPortions::~TEParaPortions()
+{
+ Reset();
+}
+
+void TEParaPortions::Reset()
+{
+ for ( USHORT nPortion = 0; nPortion < Count(); nPortion++ )
+ delete GetObject( nPortion );
+ Clear();
+}
+
+ // -------------------------------------------------------------------------
+// (+) class IdleFormatter
+// -------------------------------------------------------------------------
+IdleFormatter::IdleFormatter()
+{
+ mpView = 0;
+ mnRestarts = 0;
+}
+
+IdleFormatter::~IdleFormatter()
+{
+ mpView = 0;
+}
+
+void IdleFormatter::DoIdleFormat( TextView* pV )
+{
+ mpView = pV;
+
+ if ( IsActive() )
+ mnRestarts++;
+
+ if ( mnRestarts > 4 )
+ ForceTimeout();
+ else
+ Start();
+}
+
+void IdleFormatter::ForceTimeout()
+{
+ if ( IsActive() )
+ {
+ Stop();
+ ((Link&)GetTimeoutHdl()).Call( this );
+ }
+}
+
+TYPEINIT1( TextHint, SfxSimpleHint );
+
+TextHint::TextHint( ULONG nId ) : SfxSimpleHint( nId )
+{
+ mnValue = 0;
+}
+
+TextHint::TextHint( ULONG nId, ULONG nValue ) : SfxSimpleHint( nId )
+{
+ mnValue = nValue;
+}
+
diff --git a/svtools/source/edit/textdoc.cxx b/svtools/source/edit/textdoc.cxx
new file mode 100644
index 000000000000..f9e651808011
--- /dev/null
+++ b/svtools/source/edit/textdoc.cxx
@@ -0,0 +1,1073 @@
+/*************************************************************************
+ *
+ * $RCSfile: textdoc.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: hr $ $Date: 2000-09-18 16:58:58 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (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.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#include <textdoc.hxx>
+
+#include <stdlib.h>
+
+SV_IMPL_PTRARR( TextCharAttribs, TextCharAttribPtr );
+
+
+
+// Vergleichmethode wird von QuickSort gerufen...
+
+EXTERN_C
+#if defined( PM2 ) && (!defined( CSET ) && !defined ( MTW ) && !defined( WTC ))
+int _stdcall
+#else
+#ifdef WNT
+#if _MSC_VER >= 1200
+int __cdecl
+#else
+int _cdecl
+#endif
+#else
+int
+#endif
+#endif
+
+CompareStart( const void* pFirst, const void* pSecond )
+{
+ if ( (*((TextCharAttrib**)pFirst))->GetStart() < (*((TextCharAttrib**)pSecond))->GetStart() )
+ return (-1);
+ else if ( (*((TextCharAttrib**)pFirst))->GetStart() > (*((TextCharAttrib**)pSecond))->GetStart() )
+ return (1);
+ return 0;
+}
+
+
+ // -------------------------------------------------------------------------
+// (+) class TextCharAttrib
+// -------------------------------------------------------------------------
+TextCharAttrib::TextCharAttrib( const TextAttrib& rAttr, USHORT nStart, USHORT nEnd )
+{
+ mpAttr = rAttr.Clone();
+ mnStart = nStart,
+ mnEnd = nEnd;
+}
+
+TextCharAttrib::TextCharAttrib( const TextCharAttrib& rTextCharAttrib )
+{
+ mpAttr = rTextCharAttrib.GetAttr().Clone();
+ mnStart = rTextCharAttrib.mnStart;
+ mnEnd = rTextCharAttrib.mnEnd;
+}
+
+TextCharAttrib::~TextCharAttrib()
+{
+ delete mpAttr;
+}
+
+ // -------------------------------------------------------------------------
+// (+) class TextCharAttribList
+// -------------------------------------------------------------------------
+
+TextCharAttribList::TextCharAttribList()
+{
+ mbHasEmptyAttribs = FALSE;
+}
+
+TextCharAttribList::~TextCharAttribList()
+{
+ // PTRARR_DEL
+}
+
+void TextCharAttribList::Clear( BOOL bDestroyAttribs )
+{
+ if ( bDestroyAttribs )
+ TextCharAttribs::DeleteAndDestroy( 0, Count() );
+ else
+ TextCharAttribs::Remove( 0, Count() );
+}
+
+
+void TextCharAttribList::InsertAttrib( TextCharAttrib* pAttrib )
+{
+ if ( pAttrib->IsEmpty() )
+ mbHasEmptyAttribs = TRUE;
+
+ const USHORT nCount = Count();
+ const USHORT nStart = pAttrib->GetStart(); // vielleicht besser fuer Comp.Opt.
+ BOOL bInserted = FALSE;
+ for ( USHORT x = 0; x < nCount; x++ )
+ {
+ TextCharAttrib* pCurAttrib = GetObject( x );
+ if ( pCurAttrib->GetStart() > nStart )
+ {
+ Insert( pAttrib, x );
+ bInserted = TRUE;
+ break;
+ }
+ }
+ if ( !bInserted )
+ Insert( pAttrib, nCount );
+}
+
+void TextCharAttribList::ResortAttribs()
+{
+ if ( Count() )
+ qsort( (void*)GetData(), Count(), sizeof( TextCharAttrib* ), CompareStart );
+}
+
+TextCharAttrib* TextCharAttribList::FindAttrib( USHORT nWhich, USHORT nPos )
+{
+ // Rueckwaerts, falls eins dort endet, das naechste startet.
+ // => Das startende gilt...
+
+ for ( USHORT nAttr = Count(); nAttr; )
+ {
+ TextCharAttrib* pAttr = GetObject( --nAttr );
+
+ if ( pAttr->GetEnd() < nPos )
+ return 0;
+
+ if ( ( pAttr->Which() == nWhich ) && pAttr->IsIn(nPos) )
+ return pAttr;
+ }
+ return NULL;
+}
+
+TextCharAttrib* TextCharAttribList::FindNextAttrib( USHORT nWhich, USHORT nFromPos, USHORT nMaxPos ) const
+{
+ DBG_ASSERT( nWhich, "FindNextAttrib: Which?" );
+ const USHORT nAttribs = Count();
+ for ( USHORT nAttr = 0; nAttr < nAttribs; nAttr++ )
+ {
+ TextCharAttrib* pAttr = GetObject( nAttr );
+ if ( ( pAttr->GetStart() >= nFromPos ) &&
+ ( pAttr->GetEnd() <= nMaxPos ) &&
+ ( pAttr->Which() == nWhich ) )
+ return pAttr;
+ }
+ return NULL;
+}
+
+BOOL TextCharAttribList::HasAttrib( USHORT nWhich ) const
+{
+ for ( USHORT nAttr = Count(); nAttr; )
+ {
+ const TextCharAttrib* pAttr = GetObject( --nAttr );
+ if ( pAttr->Which() == nWhich )
+ return TRUE;
+ }
+ return FALSE;
+}
+
+BOOL TextCharAttribList::HasBoundingAttrib( USHORT nBound )
+{
+ // Rueckwaerts, falls eins dort endet, das naechste startet.
+ // => Das startende gilt...
+ for ( USHORT nAttr = Count(); nAttr; )
+ {
+ TextCharAttrib* pAttr = GetObject( --nAttr );
+
+ if ( pAttr->GetEnd() < nBound )
+ return FALSE;
+
+ if ( ( pAttr->GetStart() == nBound ) || ( pAttr->GetEnd() == nBound ) )
+ return TRUE;
+ }
+ return FALSE;
+}
+
+TextCharAttrib* TextCharAttribList::FindEmptyAttrib( USHORT nWhich, USHORT nPos )
+{
+ if ( !mbHasEmptyAttribs )
+ return 0;
+
+ const USHORT nAttribs = Count();
+ for ( USHORT nAttr = 0; nAttr < nAttribs; nAttr++ )
+ {
+ TextCharAttrib* pAttr = GetObject( nAttr );
+ if ( pAttr->GetStart() > nPos )
+ return 0;
+
+ if ( ( pAttr->GetStart() == nPos ) && ( pAttr->GetEnd() == nPos ) && ( pAttr->Which() == nWhich ) )
+ return pAttr;
+ }
+ return 0;
+}
+
+void TextCharAttribList::DeleteEmptyAttribs()
+{
+ for ( USHORT nAttr = 0; nAttr < Count(); nAttr++ )
+ {
+ TextCharAttrib* pAttr = GetObject( nAttr );
+ if ( pAttr->IsEmpty() )
+ {
+ Remove( nAttr );
+ delete pAttr;
+ nAttr--;
+ }
+ }
+ mbHasEmptyAttribs = FALSE;
+}
+
+#ifdef DBG_UTIL
+BOOL TextCharAttribList::DbgCheckAttribs()
+{
+ BOOL bOK = TRUE;
+ for ( USHORT nAttr = 0; nAttr < Count(); nAttr++ )
+ {
+ TextCharAttrib* pAttr = GetObject( nAttr );
+ if ( pAttr->GetStart() > pAttr->GetEnd() )
+ {
+ bOK = FALSE;
+ DBG_ERROR( "Attr verdreht" );
+ }
+ }
+ return bOK;
+}
+#endif
+
+ // -------------------------------------------------------------------------
+// (+) class TextNode
+// -------------------------------------------------------------------------
+
+TextNode::TextNode( const String& rText ) :
+ maText( rText )
+{
+}
+
+void TextNode::ExpandAttribs( USHORT nIndex, USHORT nNew )
+{
+ if ( !nNew )
+ return;
+
+ BOOL bResort = FALSE;
+ USHORT nAttribs = maCharAttribs.Count();
+ for ( USHORT nAttr = 0; nAttr < nAttribs; nAttr++ )
+ {
+ TextCharAttrib* pAttrib = maCharAttribs.GetAttrib( nAttr );
+ if ( pAttrib->GetEnd() >= nIndex )
+ {
+ // Alle Attribute hinter der Einfuegeposition verschieben...
+ if ( pAttrib->GetStart() > nIndex )
+ {
+ pAttrib->MoveForward( nNew );
+ }
+ // 0: Leeres Attribut expandieren, wenn an Einfuegestelle
+ else if ( pAttrib->IsEmpty() )
+ {
+ // Index nicht pruefen, leeres durfte nur dort liegen.
+ // Wenn spaeter doch Ueberpruefung:
+ // Spezialfall: Start == 0; AbsLen == 1, nNew = 1 => Expand, weil durch Absatzumbruch!
+ // Start <= nIndex, End >= nIndex => Start=End=nIndex!
+// if ( pAttrib->GetStart() == nIndex )
+ pAttrib->Expand( nNew );
+ }
+ // 1: Attribut startet davor, geht bis Index...
+ else if ( pAttrib->GetEnd() == nIndex ) // Start muss davor liegen
+ {
+ // Nur expandieren, wenn kein Feature,
+ // und wenn nicht in ExcludeListe!
+ // Sonst geht z.B. ein UL bis zum neuen ULDB, beide expandieren
+ if ( !maCharAttribs.FindEmptyAttrib( pAttrib->Which(), nIndex ) )
+ {
+ pAttrib->Expand( nNew );
+ }
+ else
+ bResort = TRUE;
+ }
+ // 2: Attribut startet davor, geht hinter Index...
+ else if ( ( pAttrib->GetStart() < nIndex ) && ( pAttrib->GetEnd() > nIndex ) )
+ {
+ pAttrib->Expand( nNew );
+ }
+ // 3: Attribut startet auf Index...
+ else if ( pAttrib->GetStart() == nIndex )
+ {
+ if ( nIndex == 0 )
+ {
+ pAttrib->Expand( nNew );
+// bResort = TRUE; // es gibt ja keine Features mehr...
+ }
+ else
+ pAttrib->MoveForward( nNew );
+ }
+ }
+
+ DBG_ASSERT( pAttrib->GetStart() <= pAttrib->GetEnd(), "Expand: Attribut verdreht!" );
+ DBG_ASSERT( ( pAttrib->GetEnd() <= maText.Len() ), "Expand: Attrib groesser als Absatz!" );
+ DBG_ASSERT( !pAttrib->IsEmpty(), "Leeres Attribut nach ExpandAttribs?" );
+ }
+
+ if ( bResort )
+ maCharAttribs.ResortAttribs();
+
+#ifdef EDITDEBUG
+ DBG_ASSERT( CheckOrderedList( (TextCharAttribs*)&maCharAttribs ), "Expand: Start-Liste verdreht" );
+#endif
+}
+
+void TextNode::CollapsAttribs( USHORT nIndex, USHORT nDeleted )
+{
+ if ( !nDeleted )
+ return;
+
+ BOOL bResort = FALSE;
+ USHORT nEndChanges = nIndex+nDeleted;
+
+ for ( USHORT nAttr = 0; nAttr < maCharAttribs.Count(); nAttr++ )
+ {
+ TextCharAttrib* pAttrib = maCharAttribs.GetAttrib( nAttr );
+ BOOL bDelAttr = FALSE;
+ if ( pAttrib->GetEnd() >= nIndex )
+ {
+ // Alles Attribute hinter der Einfuegeposition verschieben...
+ if ( pAttrib->GetStart() >= nEndChanges )
+ {
+ pAttrib->MoveBackward( nDeleted );
+ }
+ // 1. Innenliegende Attribute loeschen...
+ else if ( ( pAttrib->GetStart() >= nIndex ) && ( pAttrib->GetEnd() <= nEndChanges ) )
+ {
+ // Spezialfall: Attrubt deckt genau den Bereich ab
+ // => als leeres Attribut behalten.
+ if ( ( pAttrib->GetStart() == nIndex ) && ( pAttrib->GetEnd() == nEndChanges ) )
+ pAttrib->GetEnd() = nIndex; // leer
+ else
+ bDelAttr = TRUE;
+ }
+ // 2. Attribut beginnt davor, endet drinnen oder dahinter...
+ else if ( ( pAttrib->GetStart() <= nIndex ) && ( pAttrib->GetEnd() > nIndex ) )
+ {
+ if ( pAttrib->GetEnd() <= nEndChanges ) // endet drinnen
+ pAttrib->GetEnd() = nIndex;
+ else
+ pAttrib->Collaps( nDeleted ); // endet dahinter
+ }
+ // 3. Attribut beginnt drinnen, endet dahinter...
+ else if ( ( pAttrib->GetStart() >= nIndex ) && ( pAttrib->GetEnd() > nEndChanges ) )
+ {
+ // Features duerfen nicht expandieren!
+ pAttrib->GetStart() = nEndChanges;
+ pAttrib->MoveBackward( nDeleted );
+ }
+ }
+
+ DBG_ASSERT( pAttrib->GetStart() <= pAttrib->GetEnd(), "Collaps: Attribut verdreht!" );
+ DBG_ASSERT( ( pAttrib->GetEnd() <= maText.Len()) || bDelAttr, "Collaps: Attrib groesser als Absatz!" );
+ if ( bDelAttr /* || pAttrib->IsEmpty() */ )
+ {
+ bResort = TRUE;
+ maCharAttribs.RemoveAttrib( nAttr );
+ delete pAttrib;
+ nAttr--;
+ }
+ else if ( pAttrib->IsEmpty() )
+ maCharAttribs.HasEmptyAttribs() = TRUE;
+ }
+
+ if ( bResort )
+ maCharAttribs.ResortAttribs();
+
+#ifdef EDITDEBUG
+ DBG_ASSERT( CheckOrderedList( (TextCharAttribs)&maCharAttribs ), "Collaps: Start-Liste verdreht" );
+#endif
+}
+
+void TextNode::InsertText( USHORT nPos, const String& rText )
+{
+ maText.Insert( rText, nPos );
+ ExpandAttribs( nPos, rText.Len() );
+}
+
+void TextNode::InsertText( USHORT nPos, sal_Unicode c )
+{
+ maText.Insert( c, nPos );
+ ExpandAttribs( nPos, 1 );
+}
+
+void TextNode::RemoveText( USHORT nPos, USHORT nChars )
+{
+ maText.Erase( nPos, nChars );
+ CollapsAttribs( nPos, nChars );
+}
+
+TextNode* TextNode::Split( USHORT nPos, BOOL bKeepEndingAttribs )
+{
+ String aNewText = maText.Copy( nPos );
+ maText.Erase( nPos );
+ TextNode* pNew = new TextNode( aNewText );
+
+ for ( USHORT nAttr = 0; nAttr < maCharAttribs.Count(); nAttr++ )
+ {
+ TextCharAttrib* pAttrib = maCharAttribs.GetAttrib( nAttr );
+ if ( pAttrib->GetEnd() < nPos )
+ {
+ // bleiben unveraendert....
+ ;
+ }
+ else if ( pAttrib->GetEnd() == nPos )
+ {
+ // muessen als leeres Attribut kopiert werden.
+ // !FindAttrib nur sinnvoll, wenn Rueckwaerts durch Liste!
+ if ( bKeepEndingAttribs && !pNew->maCharAttribs.FindAttrib( pAttrib->Which(), 0 ) )
+ {
+ TextCharAttrib* pNewAttrib = new TextCharAttrib( *pAttrib );
+ pNewAttrib->GetStart() = 0;
+ pNewAttrib->GetEnd() = 0;
+ pNew->maCharAttribs.InsertAttrib( pNewAttrib );
+ }
+ }
+ else if ( pAttrib->IsInside( nPos ) || ( !nPos && !pAttrib->GetStart() ) )
+ {
+ // Wenn ganz vorne gecuttet wird, muss das Attribut erhalten bleiben!
+ // muessen kopiert und geaendert werden
+ TextCharAttrib* pNewAttrib = new TextCharAttrib( *pAttrib );
+ pNewAttrib->GetStart() = 0;
+ pNewAttrib->GetEnd() = pAttrib->GetEnd()-nPos;
+ pNew->maCharAttribs.InsertAttrib( pNewAttrib );
+ // stutzen:
+ pAttrib->GetEnd() = nPos;
+ }
+ else
+ {
+ DBG_ASSERT( pAttrib->GetStart() >= nPos, "Start < nPos!" );
+ DBG_ASSERT( pAttrib->GetEnd() >= nPos, "End < nPos!" );
+ // alle dahinter verschieben in den neuen Node (this)
+ maCharAttribs.RemoveAttrib( nAttr );
+ pNew->maCharAttribs.InsertAttrib( pAttrib );
+ pAttrib->GetStart() -= nPos;
+ pAttrib->GetEnd() -= nPos;
+ nAttr--;
+ }
+ }
+ return pNew;
+}
+
+void TextNode::Append( const TextNode& rNode )
+{
+ USHORT nOldLen = maText.Len();
+
+ maText += rNode.GetText();
+
+#ifdef EDITDEBUG
+ DBG_ASSERT( maCharAttribs.DbgCheckAttribs(), "Attribute VOR AppendAttribs kaputt" );
+#endif
+
+ const USHORT nAttribs = rNode.GetCharAttribs().Count();
+ for ( USHORT nAttr = 0; nAttr < nAttribs; nAttr++ )
+ {
+ TextCharAttrib* pAttrib = rNode.GetCharAttribs().GetAttrib( nAttr );
+ BOOL bMelted = FALSE;
+ if ( pAttrib->GetStart() == 0 )
+ {
+ // Evtl koennen Attribute zusammengefasst werden:
+ USHORT nTmpAttribs = maCharAttribs.Count();
+ for ( USHORT nTmpAttr = 0; nTmpAttr < nTmpAttribs; nTmpAttr++ )
+ {
+ TextCharAttrib* pTmpAttrib = maCharAttribs.GetAttrib( nTmpAttr );
+
+ if ( pTmpAttrib->GetEnd() == nOldLen )
+ {
+ if ( ( pTmpAttrib->Which() == pAttrib->Which() ) &&
+ ( pTmpAttrib->GetAttr() == pAttrib->GetAttr() ) )
+ {
+ pTmpAttrib->GetEnd() += pAttrib->GetLen();
+ bMelted = TRUE;
+ break; // es kann nur eins von der Sorte an der Stelle geben
+ }
+ }
+ }
+ }
+
+ if ( !bMelted )
+ {
+ TextCharAttrib* pNewAttrib = new TextCharAttrib( *pAttrib );
+ pNewAttrib->GetStart() += nOldLen;
+ pNewAttrib->GetEnd() += nOldLen;
+ maCharAttribs.InsertAttrib( pNewAttrib );
+ }
+ }
+
+#ifdef EDITDEBUG
+ DBG_ASSERT( maCharAttribs.DbgCheckAttribs(), "Attribute NACH AppendAttribs kaputt" );
+#endif
+}
+
+ // -------------------------------------------------------------------------
+// (+) class TextDoc
+// -------------------------------------------------------------------------
+
+TextDoc::TextDoc()
+{
+ mnLeftMargin = 0;
+};
+
+TextDoc::~TextDoc()
+{
+ DestroyTextNodes();
+}
+
+void TextDoc::Clear()
+{
+ DestroyTextNodes();
+}
+
+void TextDoc::DestroyTextNodes()
+{
+ for ( ULONG nNode = 0; nNode < maTextNodes.Count(); nNode++ )
+ delete maTextNodes.GetObject( nNode );
+ maTextNodes.Clear();
+}
+
+String TextDoc::GetText( const sal_Unicode* pSep ) const
+{
+ ULONG nLen = GetTextLen( pSep );
+ ULONG nNodes = maTextNodes.Count();
+
+ if ( nLen > STRING_MAXLEN )
+ {
+ DBG_ERROR( "Text zu gross fuer String" );
+ return String();
+ }
+
+ String aASCIIText;
+ ULONG nLastNode = nNodes-1;
+ for ( ULONG nNode = 0; nNode < nNodes; nNode++ )
+ {
+ TextNode* pNode = maTextNodes.GetObject( nNode );
+ String aTmp( pNode->GetText() );
+ aASCIIText += aTmp;
+ if ( pSep && ( nNode != nLastNode ) )
+ aASCIIText += pSep;
+ }
+
+ return aASCIIText;
+}
+
+XubString TextDoc::GetText( ULONG nPara ) const
+{
+ XubString aText;
+ TextNode* pNode = ( nPara < maTextNodes.Count() ) ? maTextNodes.GetObject( nPara ) : 0;
+ if ( pNode )
+ aText = pNode->GetText();
+
+ return aText;
+}
+
+
+ULONG TextDoc::GetTextLen( const xub_Unicode* pSep, const TextSelection* pSel ) const
+{
+ ULONG nLen = 0;
+ ULONG nNodes = maTextNodes.Count();
+ if ( nNodes )
+ {
+ ULONG nStartNode = 0;
+ ULONG nEndNode = nNodes-1;
+ if ( pSel )
+ {
+ nStartNode = pSel->GetStart().GetPara();
+ nEndNode = pSel->GetEnd().GetPara();
+ }
+
+ for ( ULONG nNode = nStartNode; nNode <= nEndNode; nNode++ )
+ {
+ TextNode* pNode = maTextNodes.GetObject( nNode );
+
+ USHORT nS = 0;
+ ULONG nE = pNode->GetText().Len();
+ if ( pSel && ( nNode == pSel->GetStart().GetPara() ) )
+ nS = pSel->GetStart().GetIndex();
+ if ( pSel && ( nNode == pSel->GetEnd().GetPara() ) )
+ nE = pSel->GetEnd().GetIndex();
+
+ nLen += ( nE - nS );
+ }
+
+ if ( pSep )
+ nLen += (nEndNode-nStartNode) * String( pSep ).Len();
+ }
+
+ return nLen;
+}
+
+TextPaM TextDoc::InsertText( const TextPaM& rPaM, xub_Unicode c )
+{
+ DBG_ASSERT( c != 0x0A, "TextDoc::InsertText: Zeilentrenner in Absatz nicht erlaubt!" );
+ DBG_ASSERT( c != 0x0D, "TextDoc::InsertText: Zeilentrenner in Absatz nicht erlaubt!" );
+
+ TextNode* pNode = maTextNodes.GetObject( rPaM.GetPara() );
+ pNode->InsertText( rPaM.GetIndex(), c );
+
+ TextPaM aPaM( rPaM.GetPara(), rPaM.GetIndex()+1 );
+ return aPaM;
+}
+
+TextPaM TextDoc::InsertText( const TextPaM& rPaM, const XubString& rStr )
+{
+ DBG_ASSERT( rStr.Search( 0x0A ) == STRING_NOTFOUND, "TextDoc::InsertText: Zeilentrenner in Absatz nicht erlaubt!" );
+ DBG_ASSERT( rStr.Search( 0x0D ) == STRING_NOTFOUND, "TextDoc::InsertText: Zeilentrenner in Absatz nicht erlaubt!" );
+
+ TextNode* pNode = maTextNodes.GetObject( rPaM.GetPara() );
+ pNode->InsertText( rPaM.GetIndex(), rStr );
+
+ TextPaM aPaM( rPaM.GetPara(), rPaM.GetIndex()+rStr.Len() );
+ return aPaM;
+}
+
+TextPaM TextDoc::InsertParaBreak( const TextPaM& rPaM, BOOL bKeepEndingAttribs )
+{
+ TextNode* pNode = maTextNodes.GetObject( rPaM.GetPara() );
+ TextNode* pNew = pNode->Split( rPaM.GetIndex(), bKeepEndingAttribs );
+
+ maTextNodes.Insert( pNew, rPaM.GetPara()+1 );
+
+ TextPaM aPaM( rPaM.GetPara()+1, 0 );
+ return aPaM;
+}
+
+TextPaM TextDoc::ConnectParagraphs( TextNode* pLeft, TextNode* pRight )
+{
+ USHORT nPrevLen = pLeft->GetText().Len();
+ pLeft->Append( *pRight );
+
+ // der rechte verschwindet.
+ ULONG nRight = maTextNodes.GetPos( pRight );
+ maTextNodes.Remove( nRight );
+ delete pRight;
+
+ ULONG nLeft = maTextNodes.GetPos( pLeft );
+ TextPaM aPaM( nLeft, nPrevLen );
+ return aPaM;
+}
+
+TextPaM TextDoc::RemoveChars( const TextPaM& rPaM, USHORT nChars )
+{
+ TextNode* pNode = maTextNodes.GetObject( rPaM.GetPara() );
+ pNode->RemoveText( rPaM.GetIndex(), nChars );
+
+ return rPaM;
+}
+
+BOOL TextDoc::IsValidPaM( const TextPaM& rPaM )
+{
+ if ( rPaM.GetPara() >= maTextNodes.Count() )
+ {
+ DBG_ERROR( "PaM: Para out of range" );
+ return FALSE;
+ }
+ TextNode * pNode = maTextNodes.GetObject( rPaM.GetPara() );
+ if ( rPaM.GetIndex() > pNode->GetText().Len() )
+ {
+ DBG_ERROR( "PaM: Index out of range" );
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/*
+
+void TextDoc::InsertAttribInSelection( TextNode* pNode, USHORT nStart, USHORT nEnd, const SfxPoolItem& rPoolItem )
+{
+ DBG_ASSERT( pNode, "Wohin mit dem Attribut?" );
+ DBG_ASSERT( nEnd <= pNode->Len(), "InsertAttrib: Attribut zu gross!" );
+
+ // fuer Optimierung:
+ // dieses endet am Anfang der Selektion => kann erweitert werden
+ TextCharAttrib* pEndingAttrib = 0;
+ // dieses startet am Ende der Selektion => kann erweitert werden
+ TextCharAttrib* pStartingAttrib = 0;
+
+ DBG_ASSERT( nStart <= nEnd, "Kleiner Rechenfehler in InsertAttribInSelection" );
+
+ RemoveAttribs( pNode, nStart, nEnd, pStartingAttrib, pEndingAttrib, rPoolItem.Which() );
+
+ if ( pStartingAttrib && pEndingAttrib &&
+ ( *(pStartingAttrib->GetItem()) == rPoolItem ) &&
+ ( *(pEndingAttrib->GetItem()) == rPoolItem ) )
+ {
+ // wird ein groesses Attribut.
+ pEndingAttrib->GetEnd() = pStartingAttrib->GetEnd();
+ pCurPool->Remove( *(pStartingAttrib->GetItem()) );
+ pNode->GetCharAttribs().GetAttribs().Remove( pNode->GetCharAttribs().GetAttribs().GetPos( pStartingAttrib ) );
+ delete pStartingAttrib;
+ }
+ else if ( pStartingAttrib && ( *(pStartingAttrib->GetItem()) == rPoolItem ) )
+ pStartingAttrib->GetStart() = nStart;
+ else if ( pEndingAttrib && ( *(pEndingAttrib->GetItem()) == rPoolItem ) )
+ pEndingAttrib->GetEnd() = nEnd;
+ else
+ InsertAttrib( rPoolItem, pNode, nStart, nEnd );
+
+ if ( pStartingAttrib )
+ pNode->GetCharAttribs().ResortAttribs();
+}
+
+BOOL TextDoc::RemoveAttribs( TextNode* pNode, USHORT nStart, USHORT nEnd, USHORT nWhich )
+{
+ TextCharAttrib* pStarting;
+ TextCharAttrib* pEnding;
+ return RemoveAttribs( pNode, nStart, nEnd, pStarting, pEnding, nWhich );
+}
+
+BOOL TextDoc::RemoveAttribs( TextNode* pNode, USHORT nStart, USHORT nEnd, TextCharAttrib*& rpStarting, TextCharAttrib*& rpEnding, USHORT nWhich )
+{
+ DBG_ASSERT( pNode, "Wohin mit dem Attribut?" );
+ DBG_ASSERT( nEnd <= pNode->Len(), "InsertAttrib: Attribut zu gross!" );
+
+ // dieses endet am Anfang der Selektion => kann erweitert werden
+ rpEnding = 0;
+ // dieses startet am Ende der Selektion => kann erweitert werden
+ rpStarting = 0;
+
+ BOOL bChanged = FALSE;
+
+ DBG_ASSERT( nStart <= nEnd, "Kleiner Rechenfehler in InsertAttribInSelection" );
+
+ // ueber die Attribute iterieren...
+ USHORT nAttr = 0;
+ TextCharAttrib* pAttr = GetAttrib( pNode->GetCharAttribs().GetAttribs(), nAttr );
+ while ( pAttr )
+ {
+ BOOL bRemoveAttrib = FALSE;
+ if ( !nWhich || ( pAttr->Which() == nWhich ) )
+ {
+ // Attribut beginnt in Selection
+ if ( ( pAttr->GetStart() >= nStart ) && ( pAttr->GetStart() <= nEnd ) )
+ {
+ bChanged = TRUE;
+ if ( pAttr->GetEnd() > nEnd )
+ {
+ pAttr->GetStart() = nEnd; // dann faengt es dahinter an
+ rpStarting = pAttr;
+ break; // es kann kein weiteres Attrib hier liegen
+ }
+ else if ( !pAttr->IsFeature() || ( pAttr->GetStart() == nStart ) )
+ {
+ // Feature nur loeschen, wenn genau an der Stelle
+ bRemoveAttrib = TRUE;
+ }
+ }
+
+ // Attribut endet in Selection
+ else if ( ( pAttr->GetEnd() >= nStart ) && ( pAttr->GetEnd() <= nEnd ) )
+ {
+ bChanged = TRUE;
+ if ( ( pAttr->GetStart() < nStart ) && !pAttr->IsFeature() )
+ {
+ pAttr->GetEnd() = nStart; // dann hoert es hier auf
+ rpEnding = pAttr;
+ }
+ else if ( !pAttr->IsFeature() || ( pAttr->GetStart() == nStart ) )
+ {
+ // Feature nur loeschen, wenn genau an der Stelle
+ bRemoveAttrib = TRUE;
+ }
+ }
+ // Attribut ueberlappt die Selektion
+ else if ( ( pAttr->GetStart() <= nStart ) && ( pAttr->GetEnd() >= nEnd ) )
+ {
+ bChanged = TRUE;
+ if ( pAttr->GetStart() == nStart )
+ {
+ pAttr->GetStart() = nEnd;
+ rpStarting = pAttr;
+ break; // es kann weitere Attribute geben!
+ }
+ else if ( pAttr->GetEnd() == nEnd )
+ {
+ pAttr->GetEnd() = nStart;
+ rpEnding = pAttr;
+ break; // es kann weitere Attribute geben!
+ }
+ else // Attribut muss gesplittet werden...
+ {
+ USHORT nOldEnd = pAttr->GetEnd();
+ pAttr->GetEnd() = nStart;
+ rpEnding = pAttr;
+// ULONG nSavePos = pNode->GetCharAttribs().GetStartList().GetCurPos();
+ InsertAttrib( *pAttr->GetItem(), pNode, nEnd, nOldEnd );
+// pNode->GetCharAttribs().GetStartList().Seek( nSavePos );
+ break; // es kann weitere Attribute geben!
+ }
+ }
+ }
+ if ( bRemoveAttrib )
+ {
+ DBG_ASSERT( ( pAttr != rpStarting ) && ( pAttr != rpEnding ), "Loeschen und behalten des gleichen Attributs ?" );
+ pNode->GetCharAttribs().GetAttribs().Remove(nAttr);
+ pCurPool->Remove( *pAttr->GetItem() );
+ delete pAttr;
+ nAttr--;
+ }
+ nAttr++;
+ pAttr = GetAttrib( pNode->GetCharAttribs().GetAttribs(), nAttr );
+ }
+ return bChanged;
+}
+
+#pragma SEG_FUNCDEF(editdoc_3f)
+
+void TextDoc::InsertAttrib( const SfxPoolItem& rPoolItem, TextNode* pNode, USHORT nStart, USHORT nEnd )
+{
+ // Diese Methode prueft nicht mehr, ob ein entspr. Attribut
+ // schon an der Stelle existiert!
+
+ // pruefen, ob neues Attrib oder einfach nur Ende eines Attribs...
+// const SfxPoolItem& rDefItem = pNode->GetContentAttribs().GetItem( rPoolItem.Which() );
+// BOOL bCreateAttrib = ( rDefItem != rPoolItem );
+
+ // Durch den Verlust der Exclude-Liste geht es nicht mehr, dass ich
+ // kein neues Attribut benoetige und nur das alte nicht expandiere...
+// if ( !bCreateAttrib )
+ {
+ // => Wenn schon Default-Item, dann wenigstens nur dann einstellen,
+ // wenn davor wirklich ein entsprechendes Attribut.
+// if ( pNode->GetCharAttribs().FindAttrib( rPoolItem.Which(), nStart ) )
+// bCreateAttrib = TRUE;
+ // Aber kleiner Trost:
+ // Die wenigsten schreiben, aendern das Attr, schreiben, und
+ // stellen dann wieder das Default-Attr ein.
+ }
+
+ // 22.9.95:
+ // Die Uberlegung, einfach das andere Attribut nicht zu expandieren, war
+ // sowieso falsch, da das DefAttr aus einer Vorlage kommen kann,
+ // die irgendwann verschwindet!
+// if ( bCreateAttrib )
+// {
+ TextCharAttrib* pAttrib = MakeCharAttrib( *pCurPool, rPoolItem, nStart, nEnd );
+ DBG_ASSERT( pAttrib, "MakeCharAttrib fehlgeschlagen!" );
+ pNode->GetCharAttribs().InsertAttrib( pAttrib );
+// }
+// else
+// {
+// TextCharAttrib* pTmpAttrib =
+// pNode->GetCharAttribs().FindAnyAttrib( rPoolItem.Which() );
+// if ( pTmpAttrib ) // sonst benoetige ich es sowieso nicht....
+// {
+// aExcludeList.Insert( pTmpAttrib->GetItem() );
+// }
+// }
+}
+
+#pragma SEG_FUNCDEF(editdoc_40)
+
+void TextDoc::InsertAttrib( TextNode* pNode, USHORT nStart, USHORT nEnd, const SfxPoolItem& rPoolItem )
+{
+ if ( nStart != nEnd )
+ {
+ InsertAttribInSelection( pNode, nStart, nEnd, rPoolItem );
+ }
+ else
+ {
+ // Pruefen, ob schon ein neues Attribut mit der WhichId an der Stelle:
+ TextCharAttrib* pAttr = pNode->GetCharAttribs().FindEmptyAttrib( rPoolItem.Which(), nStart );
+ if ( pAttr )
+ {
+ // Attribut entfernen....
+ pNode->GetCharAttribs().GetAttribs().Remove(
+ pNode->GetCharAttribs().GetAttribs().GetPos( pAttr ) );
+ }
+
+ // pruefen, ob ein 'gleiches' Attribut an der Stelle liegt.
+ pAttr = pNode->GetCharAttribs().FindAttrib( rPoolItem.Which(), nStart );
+ if ( pAttr )
+ {
+ if ( pAttr->IsInside( nStart ) ) // splitten
+ {
+ // ???????????????????????????????
+ // eigentlich noch pruefen, ob wirklich splittet, oder return !
+ // ???????????????????????????????
+ USHORT nOldEnd = pAttr->GetEnd();
+ pAttr->GetEnd() = nStart;
+ pAttr = MakeCharAttrib( *pCurPool, *(pAttr->GetItem()), nStart, nOldEnd );
+ pNode->GetCharAttribs().InsertAttrib( pAttr );
+ }
+ else if ( pAttr->GetEnd() == nStart )
+ {
+ DBG_ASSERT( !pAttr->IsEmpty(), "Doch noch ein leeres Attribut?" );
+ // pruefen, ob genau das gleiche Attribut
+ if ( *(pAttr->GetItem()) == rPoolItem )
+ return;
+ }
+ }
+ InsertAttrib( rPoolItem, pNode, nStart, nStart );
+ }
+}
+
+#pragma SEG_FUNCDEF(editdoc_41)
+
+void TextDoc::FindAttribs( TextNode* pNode, USHORT nStartPos, USHORT nEndPos, SfxItemSet& rCurSet )
+{
+ DBG_ASSERT( pNode, "Wo soll ich suchen ?" );
+ DBG_ASSERT( nStartPos <= nEndPos, "Ungueltiger Bereich!" );
+
+ USHORT nAttr = 0;
+ TextCharAttrib* pAttr = GetAttrib( pNode->GetCharAttribs().GetAttribs(), nAttr );
+ // keine Selection...
+ if ( nStartPos == nEndPos )
+ {
+ while ( pAttr && ( pAttr->GetStart() <= nEndPos) )
+ {
+ const SfxPoolItem* pItem = 0;
+ // Attribut liegt dadrueber...
+ if ( ( pAttr->GetStart() < nStartPos ) && ( pAttr->GetEnd() > nStartPos ) )
+ pItem = pAttr->GetItem();
+ // Attribut endet hier, ist nicht leer
+ else if ( ( pAttr->GetStart() < nStartPos ) && ( pAttr->GetEnd() == nStartPos ) )
+ {
+ if ( !pNode->GetCharAttribs().FindEmptyAttrib( pAttr->GetItem()->Which(), nStartPos ) )
+ pItem = pAttr->GetItem();
+ }
+ // Attribut endet hier, ist leer
+ else if ( ( pAttr->GetStart() == nStartPos ) && ( pAttr->GetEnd() == nStartPos ) )
+ {
+// if ( aExcludeList.FindAttrib( pAttr->GetItem()->Which() ) )
+ pItem = pAttr->GetItem();
+// else if ( pNode->Len() == 0 ) // Sonderfall
+// pItem = pAttr->GetItem();
+ }
+ // Attribut beginnt hier
+ else if ( ( pAttr->GetStart() == nStartPos ) && ( pAttr->GetEnd() > nStartPos ) )
+ {
+ if ( nStartPos == 0 ) // Sonderfall
+ pItem = pAttr->GetItem();
+ }
+
+ if ( pItem )
+ {
+ USHORT nWhich = pItem->Which();
+ if ( rCurSet.GetItemState( nWhich ) == SFX_ITEM_OFF )
+ {
+ rCurSet.Put( *pItem );
+ }
+ else if ( rCurSet.GetItemState( nWhich ) == SFX_ITEM_ON )
+ {
+ const SfxPoolItem& rItem = rCurSet.Get( nWhich );
+ if ( rItem != *pItem )
+ {
+ rCurSet.InvalidateItem( nWhich );
+ }
+ }
+ }
+ nAttr++;
+ pAttr = GetAttrib( pNode->GetCharAttribs().GetAttribs(), nAttr );
+ }
+ }
+ else // Selektion
+ {
+ while ( pAttr && ( pAttr->GetStart() < nEndPos) )
+ {
+ const SfxPoolItem* pItem = 0;
+ // Attribut liegt dadrueber...
+ if ( ( pAttr->GetStart() <= nStartPos ) && ( pAttr->GetEnd() >= nEndPos ) )
+ pItem = pAttr->GetItem();
+ // Attribut startet mitten drin...
+ else if ( pAttr->GetStart() >= nStartPos )
+ {
+ // !!! pItem = pAttr->GetItem();
+ // einfach nur pItem reicht nicht, da ich z.B. bei Shadow
+ // niemals ein ungleiches Item finden wuerde, da ein solche
+ // seine Anwesenheit durch Abwesenheit repraesentiert!
+ // if ( ... )
+ // Es muesste geprueft werden, on genau das gleiche Attribut
+ // an der Bruchstelle aufsetzt, was recht aufwendig ist.
+ // Da ich beim Einfuegen von Attributen aber etwas optimiere
+ // tritt der Fall nicht so schnell auf...
+ // Also aus Geschwindigkeitsgruenden:
+ rCurSet.InvalidateItem( pAttr->GetItem()->Which() );
+
+ }
+ // Attribut endet mitten drin...
+ else if ( pAttr->GetEnd() > nStartPos )
+ {
+ // pItem = pAttr->GetItem();
+ // s.o.
+
+ // -----------------31.05.95 16:01-------------------
+ // Ist falsch, wenn das gleiche Attribut sofort wieder
+ // eingestellt wird!
+ // => Sollte am besten nicht vorkommen, also gleich beim
+ // Setzen von Attributen richtig machen!
+ // --------------------------------------------------
+ rCurSet.InvalidateItem( pAttr->GetItem()->Which() );
+ }
+
+ if ( pItem )
+ {
+ USHORT nWhich = pItem->Which();
+ if ( rCurSet.GetItemState( nWhich ) == SFX_ITEM_OFF )
+ {
+ rCurSet.Put( *pItem );
+ }
+ else if ( rCurSet.GetItemState( nWhich ) == SFX_ITEM_ON )
+ {
+ const SfxPoolItem& rItem = rCurSet.Get( nWhich );
+ if ( rItem != *pItem )
+ {
+ rCurSet.InvalidateItem( nWhich );
+ }
+ }
+ }
+ nAttr++;
+ pAttr = GetAttrib( pNode->GetCharAttribs().GetAttribs(), nAttr );
+ }
+ }
+}
+
+
+*/
+
+
diff --git a/svtools/source/edit/textdoc.hxx b/svtools/source/edit/textdoc.hxx
new file mode 100644
index 000000000000..9659ccce438a
--- /dev/null
+++ b/svtools/source/edit/textdoc.hxx
@@ -0,0 +1,202 @@
+/*************************************************************************
+ *
+ * $RCSfile: textdoc.hxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: hr $ $Date: 2000-09-18 16:58:58 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (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.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#ifndef _TEXTDOC_HXX
+#define _TEXTDOC_HXX
+
+#ifndef _SVARRAY_HXX
+#include <svarray.hxx>
+#endif
+
+#ifndef _TEXTDATA_HXX
+#include <textdata.hxx>
+#endif
+
+#ifndef _TXTATTR_HXX
+#include <txtattr.hxx>
+#endif
+
+#include <tools/debug.hxx>
+
+#ifndef _STRING_HXX //autogen
+#include <tools/string.hxx>
+#endif
+
+#ifndef _LIST_HXX //autogen
+#include <tools/list.hxx>
+#endif
+
+
+typedef TextCharAttrib* TextCharAttribPtr;
+SV_DECL_PTRARR_DEL( TextCharAttribs, TextCharAttribPtr, 0, 4 );
+
+class TextCharAttribList : private TextCharAttribs
+{
+private:
+ BOOL mbHasEmptyAttribs;
+
+ TextCharAttribList( const TextCharAttribList& ) {;}
+
+public:
+ TextCharAttribList();
+ ~TextCharAttribList();
+
+ void Clear( BOOL bDestroyAttribs );
+ USHORT Count() const { return TextCharAttribs::Count(); }
+
+ TextCharAttrib* GetAttrib( USHORT n ) const { return TextCharAttribs::GetObject( n ); }
+ void RemoveAttrib( USHORT n ) { TextCharAttribs::Remove( n, 1 ); }
+
+ void InsertAttrib( TextCharAttrib* pAttrib );
+
+ void DeleteEmptyAttribs();
+ void ResortAttribs();
+
+ BOOL HasEmptyAttribs() const { return mbHasEmptyAttribs; }
+ BOOL& HasEmptyAttribs() { return mbHasEmptyAttribs; }
+
+ TextCharAttrib* FindAttrib( USHORT nWhich, USHORT nPos );
+ TextCharAttrib* FindNextAttrib( USHORT nWhich, USHORT nFromPos, USHORT nMaxPos = 0xFFFF ) const;
+ TextCharAttrib* FindEmptyAttrib( USHORT nWhich, USHORT nPos );
+ BOOL HasAttrib( USHORT nWhich ) const;
+ BOOL HasBoundingAttrib( USHORT nBound );
+
+#ifdef DBG_UTIL
+ BOOL DbgCheckAttribs();
+#endif
+};
+
+
+class TextNode
+{
+private:
+ String maText;
+ TextCharAttribList maCharAttribs;
+
+ TextNode( const TextNode& ) {;}
+protected:
+ void ExpandAttribs( USHORT nIndex, USHORT nNewChars );
+ void CollapsAttribs( USHORT nIndex, USHORT nDelChars );
+
+public:
+ TextNode( const String& rText );
+
+
+ const String& GetText() const { return maText; }
+// String& GetText() { return maText; }
+
+ const TextCharAttribList& GetCharAttribs() const { return maCharAttribs; }
+ TextCharAttribList& GetCharAttribs() { return maCharAttribs; }
+
+ void InsertText( USHORT nPos, const String& rText );
+ void InsertText( USHORT nPos, sal_Unicode c );
+ void RemoveText( USHORT nPos, USHORT nChars );
+
+ TextNode* Split( USHORT nPos, BOOL bKeepEndigAttribs );
+ void Append( const TextNode& rNode );
+};
+
+
+
+DECLARE_LIST( TextNodeList, TextNode* );
+
+class TextDoc
+{
+private:
+ TextNodeList maTextNodes;
+ USHORT mnLeftMargin;
+
+protected:
+ void DestroyTextNodes();
+
+public:
+ TextDoc();
+ ~TextDoc();
+
+ void Clear();
+
+ TextNodeList& GetNodes() { return maTextNodes; }
+ const TextNodeList& GetNodes() const { return maTextNodes; }
+
+ TextPaM RemoveChars( const TextPaM& rPaM, USHORT nChars );
+ TextPaM InsertText( const TextPaM& rPaM, sal_Unicode c );
+ TextPaM InsertText( const TextPaM& rPaM, const String& rStr );
+
+ TextPaM InsertParaBreak( const TextPaM& rPaM, BOOL bKeepEndingAttribs );
+ TextPaM ConnectParagraphs( TextNode* pLeft, TextNode* pRight );
+
+ ULONG GetTextLen( const sal_Unicode* pSep, const TextSelection* pSel = NULL ) const;
+ String GetText( const sal_Unicode* pSep ) const;
+ String GetText( ULONG nPara ) const;
+
+ void SetLeftMargin( USHORT n ) { mnLeftMargin = n; }
+ USHORT GetLeftMargin() const { return mnLeftMargin; }
+
+// BOOL RemoveAttribs( TextNode* pNode, USHORT nStart, USHORT nEnd ), USHORT nWhich = 0 );
+// BOOL RemoveAttribs( TextNode* pNode, USHORT nStart, USHORT nEnd, TextCharAttrib*& rpStarting, TextCharAttrib*& rpEnding, USHORT nWhich = 0 );
+// void InsertAttrib( const EditCharAttrib* pAttr );
+// void InsertAttribInSelection( const EditCharAttrib* pAttr );
+// void FindAttribs( TextNode* pNode, USHORT nStartPos, USHORT nEndPos, SfxItemSet& rCurSet );
+
+ BOOL IsValidPaM( const TextPaM& rPaM );
+};
+
+#endif // _TEXTDOC_HXX
diff --git a/svtools/source/edit/texteng.cxx b/svtools/source/edit/texteng.cxx
new file mode 100644
index 000000000000..1443fc3e72ed
--- /dev/null
+++ b/svtools/source/edit/texteng.cxx
@@ -0,0 +1,2691 @@
+/*************************************************************************
+ *
+ * $RCSfile: texteng.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: hr $ $Date: 2000-09-18 16:58:58 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (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.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+
+#ifndef _STREAM_HXX //autogen
+#include <tools/stream.hxx>
+#endif
+
+#include <texteng.hxx>
+#include <textview.hxx>
+#include <textdoc.hxx>
+#include <textdat2.hxx>
+#include <textundo.hxx>
+#include <textund2.hxx>
+
+#include <tools/isolang.hxx>
+
+#ifndef _SV_WINDOW_HXX //autogen
+#include <vcl/window.hxx>
+#endif
+
+#include <vcl/edit.hxx>
+
+#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_TEXT_XBREAKITERATOR_HPP_
+#include <com/sun/star/text/XBreakIterator.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_TEXT_CHARACTERITERATORMODE_HPP_
+#include <com/sun/star/text/CharacterIteratorMode.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_TEXT_WORDTYPE_HPP_
+#include <com/sun/star/text/WordType.hpp>
+#endif
+
+#ifndef _UNOTOOLS_PROCESSFACTORY_HXX_
+#include <unotools/processfactory.hxx>
+#endif
+
+#include <vcl/unohelp.hxx>
+
+using namespace ::com::sun::star;
+
+typedef TextView* TextViewPtr;
+SV_DECL_PTRARR( TextViews, TextViewPtr, 0, 1 );
+// SV_IMPL_PTRARR( TextViews, TextViewPtr );
+
+SV_DECL_VARARR_SORT( TESortedPositions, ULONG, 16, 8 );
+SV_IMPL_VARARR_SORT( TESortedPositions, ULONG );
+
+#define RESDIFF 10
+#define SCRLRANGE 20 // 1/20 der Breite/Hoehe scrollen, wenn im QueryDrop
+
+
+ // -------------------------------------------------------------------------
+// (-) class TextEngine
+// -------------------------------------------------------------------------
+TextEngine::TextEngine() : maWordDelimiters( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( " .=+-*/()[]<>{};,:\"\t" ) ) )
+{
+ mpDoc = 0;
+ mpTEParaPortions = 0;
+
+ mpViews = new TextViews;
+ mpActiveView = NULL;
+
+ mbIsFormatting = FALSE;
+ mbFormatted = FALSE;
+ mbUpdate = TRUE;
+ mbModified = FALSE;
+ mbUndoEnabled = FALSE;
+ mbIsInUndo = FALSE;
+ mbDowning = FALSE;
+
+ meAlign = TXTALIGN_LEFT;
+
+ mnMaxTextWidth = 0;
+ mnMaxTextLen = 0;
+ mnCurTextHeight = 0;
+
+ mpUndoManager = 0;
+
+ mpIdleFormatter = new IdleFormatter;
+
+ mpRefDev = new VirtualDevice;
+
+ ImpInitDoc();
+
+ Font aFont;
+ aFont.SetTransparent( FALSE );
+ Color aFillColor( aFont.GetFillColor() );
+ aFillColor.SetTransparency( 0 );
+ aFont.SetFillColor( aFillColor );
+ SetFont( aFont );
+}
+
+TextEngine::~TextEngine()
+{
+ mbDowning = TRUE;
+
+ delete mpIdleFormatter;
+ delete mpDoc;
+ delete mpTEParaPortions;
+ delete mpViews; // nur die Liste, nicht die Vies
+ delete mpRefDev;
+ delete mpUndoManager;
+}
+
+void TextEngine::InsertView( TextView* pTextView )
+{
+ mpViews->Insert( pTextView, mpViews->Count() );
+ pTextView->SetSelection( TextSelection() );
+
+ if ( !GetActiveView() )
+ SetActiveView( pTextView );
+}
+
+void TextEngine::RemoveView( TextView* pTextView )
+{
+ USHORT nPos = mpViews->GetPos( pTextView );
+ if( nPos != USHRT_MAX )
+ {
+ pTextView->HideCursor();
+ mpViews->Remove( nPos, 1 );
+ if ( pTextView == GetActiveView() )
+ SetActiveView( 0 );
+ }
+}
+
+USHORT TextEngine::GetViewCount() const
+{
+ return mpViews->Count();
+}
+
+TextView* TextEngine::GetView( USHORT nView ) const
+{
+ return mpViews->GetObject( nView );
+}
+
+TextView* TextEngine::GetActiveView() const
+{
+ return mpActiveView;
+}
+
+void TextEngine::SetActiveView( TextView* pTextView )
+{
+ if ( pTextView != mpActiveView )
+ {
+ if ( mpActiveView )
+ mpActiveView->HideSelection();
+
+ mpActiveView = pTextView;
+
+ if ( mpActiveView )
+ mpActiveView->ShowSelection();
+ }
+}
+
+void TextEngine::SetFont( const Font& rFont )
+{
+ if ( rFont != maFont )
+ {
+ maFont = rFont;
+
+ // Wegen Selektion keinen Transparenten Font zulassen...
+ // (Sonst spaeter in ImplPaint den Hintergrund anders loeschen...)
+ maFont.SetTransparent( FALSE );
+ Color aFillColor( maFont.GetFillColor() );
+ aFillColor.SetTransparency( 0 );
+ maFont.SetFillColor( aFillColor );
+
+ maFont.SetAlign( ALIGN_TOP );
+ mpRefDev->SetFont( maFont );
+ Size aTextSize;
+ aTextSize.Width() = mpRefDev->GetTextWidth( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( " " ) ) );
+ aTextSize.Height() = mpRefDev->GetTextHeight();
+ if ( !aTextSize.Width() )
+ aTextSize.Width() = mpRefDev->GetTextWidth( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "XXXX" ) ) );
+
+ mnDefTab = (USHORT)aTextSize.Width();
+ if ( !mnDefTab )
+ mnDefTab = 1;
+ mnCharHeight = (USHORT)aTextSize.Height();
+ if ( rFont.GetPitch() == PITCH_FIXED )
+ {
+ String aX100;
+ aX100.Fill( 100, 'X' );
+ mnFixCharWidth100 = (USHORT)mpRefDev->GetTextWidth( aX100 );
+ }
+ else
+ mnFixCharWidth100 = 0;
+
+ FormatFullDoc();
+ }
+}
+
+void TextEngine::SetDefTab( USHORT nDefTab )
+{
+ mnDefTab = nDefTab;
+ // evtl neu setzen?
+}
+
+void TextEngine::SetMaxTextLen( ULONG nLen )
+{
+ mnMaxTextLen = nLen;
+}
+
+void TextEngine::SetMaxTextWidth( ULONG nMaxWidth )
+{
+ if ( nMaxWidth != mnMaxTextWidth )
+ {
+ mnMaxTextWidth = Min( nMaxWidth, (ULONG)0x7FFFFFFF );
+ FormatFullDoc();
+ UpdateViews();
+ }
+}
+
+static sal_Unicode static_aLFText[] = { '\n', 0 };
+static sal_Unicode static_aCRText[] = { '\r', 0 };
+static sal_Unicode static_aCRLFText[] = { '\r', '\n', 0 };
+
+static inline const sal_Unicode* static_getLineEndText( LineEnd aLineEnd )
+{
+ const sal_Unicode* pRet = NULL;
+
+ switch( aLineEnd )
+ {
+ case LINEEND_LF: pRet = static_aLFText;break;
+ case LINEEND_CR: pRet = static_aCRText;break;
+ case LINEEND_CRLF: pRet = static_aCRLFText;break;
+ }
+ return pRet;
+}
+
+String TextEngine::GetText( LineEnd aSeparator ) const
+{
+ return mpDoc->GetText( static_getLineEndText( aSeparator ) );
+}
+
+String TextEngine::GetTextLines( LineEnd aSeparator ) const
+{
+ String aText;
+ ULONG nParas = mpTEParaPortions->Count();
+ const sal_Unicode* pSep = static_getLineEndText( aSeparator );
+ for ( ULONG nP = 0; nP < nParas; nP++ )
+ {
+ TEParaPortion* pTEParaPortion = mpTEParaPortions->GetObject( nP );
+
+ USHORT nLines = pTEParaPortion->GetLines().Count();
+ for ( USHORT nL = 0; nL < nLines; nL++ )
+ {
+ TextLine* pLine = pTEParaPortion->GetLines()[nL];
+ aText += pTEParaPortion->GetNode()->GetText().Copy( pLine->GetStart(), pLine->GetEnd() - pLine->GetStart() );
+ if ( pSep && ( ( (nP+1) < nParas ) || ( (nL+1) < nLines ) ) )
+ aText += pSep;
+ }
+ }
+ return aText;
+}
+
+String TextEngine::GetText( ULONG nPara ) const
+{
+ return mpDoc->GetText( nPara );
+}
+
+ULONG TextEngine::GetTextLen( LineEnd aSeparator ) const
+{
+ return mpDoc->GetTextLen( static_getLineEndText( aSeparator ) );
+}
+
+ULONG TextEngine::GetTextLen( const TextSelection& rSel, LineEnd aSeparator ) const
+{
+ TextSelection aSel( rSel );
+ aSel.Justify();
+ ValidateSelection( aSel );
+ return mpDoc->GetTextLen( static_getLineEndText( aSeparator ), &aSel );
+}
+
+USHORT TextEngine::GetTextLen( ULONG nPara ) const
+{
+ return mpDoc->GetNodes().GetObject( nPara )->GetText().Len();
+}
+
+void TextEngine::SetUpdateMode( BOOL bUpdate )
+{
+ if ( bUpdate != mbUpdate )
+ {
+ mbUpdate = bUpdate;
+ if ( mbUpdate )
+ {
+ FormatAndUpdate( GetActiveView() );
+ if ( GetActiveView() )
+ GetActiveView()->ShowCursor();
+ }
+ }
+}
+
+void TextEngine::SetWordDelimiters( const String& rDelimiters )
+{
+ maWordDelimiters = rDelimiters;
+ if ( maWordDelimiters.Search( ' ' ) == STRING_NOTFOUND )
+ maWordDelimiters += ' ';
+ if ( maWordDelimiters.Search( '\t' ) == STRING_NOTFOUND )
+ maWordDelimiters += '\t';
+}
+
+BOOL TextEngine::DoesKeyMoveCursor( const KeyEvent& rKeyEvent )
+{
+ BOOL bDoesMove = FALSE;
+
+ switch ( rKeyEvent.GetKeyCode().GetCode() )
+ {
+ case KEY_UP:
+ case KEY_DOWN:
+ case KEY_LEFT:
+ case KEY_RIGHT:
+ case KEY_HOME:
+ case KEY_END:
+ case KEY_PAGEUP:
+ case KEY_PAGEDOWN:
+ {
+ if ( !rKeyEvent.GetKeyCode().IsMod2() )
+ bDoesMove = TRUE;
+ }
+ break;
+ }
+ return bDoesMove;
+}
+
+BOOL TextEngine::DoesKeyChangeText( const KeyEvent& rKeyEvent )
+{
+ BOOL bDoesChange = FALSE;
+
+ KeyFuncType eFunc = rKeyEvent.GetKeyCode().GetFunction();
+ if ( eFunc != KEYFUNC_DONTKNOW )
+ {
+ switch ( eFunc )
+ {
+ case KEYFUNC_UNDO:
+ case KEYFUNC_REDO:
+ case KEYFUNC_CUT:
+ case KEYFUNC_PASTE: bDoesChange = TRUE;
+ break;
+ default: // wird dann evtl. unten bearbeitet.
+ eFunc = KEYFUNC_DONTKNOW;
+ }
+ }
+ if ( eFunc == KEYFUNC_DONTKNOW )
+ {
+ switch ( rKeyEvent.GetKeyCode().GetCode() )
+ {
+ case KEY_DELETE:
+ case KEY_BACKSPACE:
+ {
+ if ( !rKeyEvent.GetKeyCode().IsMod2() )
+ bDoesChange = TRUE;
+ }
+ break;
+ case KEY_RETURN:
+ case KEY_TAB:
+ {
+ if ( !rKeyEvent.GetKeyCode().IsMod1() && !rKeyEvent.GetKeyCode().IsMod2() )
+ bDoesChange = TRUE;
+ }
+ break;
+ default:
+ {
+ bDoesChange = TextEngine::IsSimpleCharInput( rKeyEvent );
+ }
+ }
+ }
+ return bDoesChange;
+}
+
+BOOL TextEngine::IsSimpleCharInput( const KeyEvent& rKeyEvent )
+{
+ if( rKeyEvent.GetCharCode() >= 32 && rKeyEvent.GetCharCode() != 127 &&
+#ifndef MAC
+ KEY_MOD2 != (rKeyEvent.GetKeyCode().GetModifier() & ~KEY_SHIFT ) )
+#else
+ KEY_MOD1 != rKeyEvent.GetKeyCode().GetModifier() )
+#endif
+ {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+void TextEngine::ImpInitDoc()
+{
+ if ( mpDoc )
+ mpDoc->Clear();
+ else
+ mpDoc = new TextDoc;
+
+ delete mpTEParaPortions;
+ mpTEParaPortions = new TEParaPortions;
+
+ TextNode* pNode = new TextNode( String() );
+ mpDoc->GetNodes().Insert( pNode );
+
+ TEParaPortion* pIniPortion = new TEParaPortion( pNode );
+ mpTEParaPortions->Insert( pIniPortion, (ULONG)0 );
+
+ mbFormatted = FALSE;
+
+ ImpParagraphRemoved( TEXT_PARA_ALL );
+ ImpParagraphInserted( 0 );
+}
+
+String TextEngine::GetText( const TextSelection& rSel, LineEnd aSeparator ) const
+{
+ String aText;
+
+ if ( !rSel.HasRange() )
+ return aText;
+
+ TextSelection aSel( rSel );
+ aSel.Justify();
+
+ ULONG nStartPara = aSel.GetStart().GetPara();
+ ULONG nEndPara = aSel.GetEnd().GetPara();
+ const sal_Unicode* pSep = static_getLineEndText( aSeparator );
+ for ( ULONG nNode = aSel.GetStart().GetPara(); nNode <= nEndPara; nNode++ )
+ {
+ TextNode* pNode = mpDoc->GetNodes().GetObject( nNode );
+
+ USHORT nStartPos = 0;
+ USHORT nEndPos = pNode->GetText().Len();
+ if ( nNode == nStartPara )
+ nStartPos = aSel.GetStart().GetIndex();
+ if ( nNode == nEndPara ) // kann auch == nStart sein!
+ nEndPos = aSel.GetEnd().GetIndex();
+
+ aText += pNode->GetText().Copy( nStartPos, nEndPos-nStartPos );
+ if ( nNode < nEndPara )
+ aText += pSep;
+ }
+ return aText;
+}
+
+void TextEngine::ImpRemoveText()
+{
+ ImpInitDoc();
+
+ TextPaM aStartPaM( 0, 0 );
+ TextSelection aEmptySel( aStartPaM, aStartPaM );
+ for ( USHORT nView = 0; nView < mpViews->Count(); nView++ )
+ {
+ TextView* pView = mpViews->GetObject( nView );
+ pView->maSelection = aEmptySel;
+ }
+ ResetUndo();
+}
+
+void TextEngine::SetText( const XubString& rText )
+{
+ ImpRemoveText();
+
+ BOOL bUndoCurrentlyEnabled = IsUndoEnabled();
+ // Der von Hand reingesteckte Text kann nicht vom Anwender rueckgaengig gemacht werden.
+ EnableUndo( FALSE );
+
+ TextPaM aStartPaM( 0, 0 );
+ TextSelection aEmptySel( aStartPaM, aStartPaM );
+
+ TextPaM aPaM = aStartPaM;
+ if ( rText.Len() )
+ aPaM = ImpInsertText( aEmptySel, rText );
+
+ for ( USHORT nView = 0; nView < mpViews->Count(); nView++ )
+ {
+ TextView* pView = mpViews->GetObject( nView );
+// if ( !pView->IsReadOnly() )
+// pView->maSelection = aPaM;
+// else
+ pView->maSelection = aEmptySel;
+
+ // Wenn kein Text, dann auch Kein Format&Update
+ // => Der Text bleibt stehen.
+ if ( !rText.Len() && GetUpdateMode() )
+ pView->Invalidate();
+ }
+
+ if( !rText.Len() ) // sonst muss spaeter noch invalidiert werden, !bFormatted reicht.
+ mnCurTextHeight = 0;
+
+ FormatAndUpdate();
+
+ EnableUndo( bUndoCurrentlyEnabled );
+ DBG_ASSERT( !HasUndoManager() || !GetUndoManager().GetUndoActionCount(), "Undo nach SetText?" );
+}
+
+
+void TextEngine::CursorMoved( ULONG nNode )
+{
+ // Leere Attribute loeschen, aber nur, wenn Absatz nicht leer!
+ TextNode* pNode = mpDoc->GetNodes().GetObject( nNode );
+ if ( pNode && pNode->GetCharAttribs().HasEmptyAttribs() && pNode->GetText().Len() )
+ pNode->GetCharAttribs().DeleteEmptyAttribs();
+}
+
+void TextEngine::ImpRemoveChars( const TextPaM& rPaM, USHORT nChars, SfxUndoAction* pCurUndo )
+{
+ DBG_ASSERT( nChars, "ImpRemoveChars - 0 Chars?!" );
+ if ( IsUndoEnabled() && !IsInUndo() )
+ {
+ // Attribute muessen hier vorm RemoveChars fuer UNDO gesichert werden!
+ TextNode* pNode = mpDoc->GetNodes().GetObject( rPaM.GetPara() );
+ XubString aStr( pNode->GetText().Copy( rPaM.GetIndex(), nChars ) );
+
+ // Pruefen, ob Attribute geloescht oder geaendert werden:
+ USHORT nStart = rPaM.GetIndex();
+ USHORT nEnd = nStart + nChars;
+ for ( USHORT nAttr = pNode->GetCharAttribs().Count(); nAttr; )
+ {
+ TextCharAttrib* pAttr = pNode->GetCharAttribs().GetAttrib( --nAttr );
+ if ( ( pAttr->GetEnd() >= nStart ) && ( pAttr->GetStart() < nEnd ) )
+ {
+// TextSelection aSel( rPaM );
+// aSel.GetEnd().GetIndex() += nChars;
+// TextUndoSetAttribs* pAttrUndo = CreateAttribUndo( aSel );
+// InsertUndo( pAttrUndo );
+ break; // for
+ }
+ }
+// if ( pCurUndo && ( CreateTextPaM( pCurUndo->GetEPaM() ) == rPaM ) )
+// pCurUndo->GetStr() += aStr;
+// else
+ InsertUndo( new TextUndoRemoveChars( this, rPaM, aStr ) );
+ }
+
+ mpDoc->RemoveChars( rPaM, nChars );
+ ImpCharsRemoved( rPaM.GetPara(), rPaM.GetIndex(), nChars );
+}
+
+TextPaM TextEngine::ImpConnectParagraphs( ULONG nLeft, ULONG nRight )
+{
+ DBG_ASSERT( nLeft != nRight, "Den gleichen Absatz zusammenfuegen ?" );
+
+ TextNode* pLeft = mpDoc->GetNodes().GetObject( nLeft );
+ TextNode* pRight = mpDoc->GetNodes().GetObject( nRight );
+
+ if ( IsUndoEnabled() && !IsInUndo() )
+ InsertUndo( new TextUndoConnectParas( this, nLeft, pLeft->GetText().Len() ) );
+
+ // Erstmal Portions suchen, da pRight nach ConnectParagraphs weg.
+ TEParaPortion* pLeftPortion = mpTEParaPortions->GetObject( nLeft );
+ TEParaPortion* pRightPortion = mpTEParaPortions->GetObject( nRight );
+ DBG_ASSERT( pLeft && pLeftPortion, "Blinde Portion in ImpConnectParagraphs(1)" );
+ DBG_ASSERT( pRight && pRightPortion, "Blinde Portion in ImpConnectParagraphs(2)" );
+
+ TextPaM aPaM = mpDoc->ConnectParagraphs( pLeft, pRight );
+ ImpParagraphRemoved( nRight );
+
+ pLeftPortion->MarkSelectionInvalid( aPaM.GetIndex(), pLeft->GetText().Len() );
+
+ mpTEParaPortions->Remove( nRight );
+ delete pRightPortion;
+ // der rechte Node wird von EditDoc::ConnectParagraphs() geloescht.
+
+ return aPaM;
+}
+
+TextPaM TextEngine::ImpDeleteText( const TextSelection& rSel )
+{
+ if ( !rSel.HasRange() )
+ return rSel.GetStart();
+
+ TextSelection aSel( rSel );
+ aSel.Justify();
+ TextPaM aStartPaM( aSel.GetStart() );
+ TextPaM aEndPaM( aSel.GetEnd() );
+
+ CursorMoved( aStartPaM.GetPara() ); // nur damit neu eingestellte Attribute verschwinden...
+ CursorMoved( aEndPaM.GetPara() ); // nur damit neu eingestellte Attribute verschwinden...
+
+ DBG_ASSERT( mpDoc->IsValidPaM( aStartPaM ), "Index im Wald in ImpDeleteText" )
+ DBG_ASSERT( mpDoc->IsValidPaM( aEndPaM ), "Index im Wald in ImpDeleteText" )
+
+ ULONG nStartNode = aStartPaM.GetPara();
+ ULONG nEndNode = aEndPaM.GetPara();
+
+ // Alle Nodes dazwischen entfernen....
+ for ( ULONG z = nStartNode+1; z < nEndNode; z++ )
+ {
+ // Immer nStartNode+1, wegen Remove()!
+ ImpRemoveParagraph( nStartNode+1 );
+ }
+
+ if ( nStartNode != nEndNode )
+ {
+ // Den Rest des StartNodes...
+ TextNode* pLeft = mpDoc->GetNodes().GetObject( nStartNode );
+ USHORT nChars = pLeft->GetText().Len() - aStartPaM.GetIndex();
+ if ( nChars )
+ {
+ ImpRemoveChars( aStartPaM, nChars );
+ TEParaPortion* pPortion = mpTEParaPortions->GetObject( nStartNode );
+ DBG_ASSERT( pPortion, "Blinde Portion in ImpDeleteText(3)" );
+ pPortion->MarkSelectionInvalid( aStartPaM.GetIndex(), pLeft->GetText().Len() );
+ }
+
+ // Den Anfang des EndNodes....
+ nEndNode = nStartNode+1; // Die anderen Absaetze wurden geloescht
+ nChars = aEndPaM.GetIndex();
+ if ( nChars )
+ {
+ aEndPaM.GetPara() = nEndNode;
+ aEndPaM.GetIndex() = 0;
+ ImpRemoveChars( aEndPaM, nChars );
+ TEParaPortion* pPortion = mpTEParaPortions->GetObject( nEndNode );
+ DBG_ASSERT( pPortion, "Blinde Portion in ImpDeleteText(4)" );
+ pPortion->MarkSelectionInvalid( 0, pPortion->GetNode()->GetText().Len() );
+ }
+
+ // Zusammenfuegen....
+ aStartPaM = ImpConnectParagraphs( nStartNode, nEndNode );
+ }
+ else
+ {
+ USHORT nChars;
+ nChars = aEndPaM.GetIndex() - aStartPaM.GetIndex();
+ ImpRemoveChars( aStartPaM, nChars );
+ TEParaPortion* pPortion = mpTEParaPortions->GetObject( nStartNode );
+ DBG_ASSERT( pPortion, "Blinde Portion in ImpDeleteText(5)" );
+ pPortion->MarkInvalid( aEndPaM.GetIndex(), aStartPaM.GetIndex() - aEndPaM.GetIndex() );
+ }
+
+// UpdateSelections();
+ TextModified();
+ return aStartPaM;
+}
+
+void TextEngine::ImpRemoveParagraph( ULONG nPara )
+{
+ TextNode* pNode = mpDoc->GetNodes().GetObject( nPara );
+ TEParaPortion* pPortion = mpTEParaPortions->GetObject( nPara );
+
+ // Der Node wird vom Undo verwaltet und ggf. zerstoert!
+ /* delete */ mpDoc->GetNodes().Remove( nPara );
+ if ( IsUndoEnabled() && !IsInUndo() )
+ InsertUndo( new TextUndoDelPara( this, pNode, nPara ) );
+ else
+ delete pNode;
+
+ mpTEParaPortions->Remove( nPara );
+ delete pPortion;
+
+ ImpParagraphRemoved( nPara );
+}
+
+TextPaM TextEngine::ImpInsertText( const TextSelection& rCurSel, sal_Unicode c, BOOL bOverwrite )
+{
+ DBG_ASSERT( c != '\n', "Zeilenumbruch bei InsertText ?" );
+ DBG_ASSERT( c != '\r', "Zeilenumbruch bei InsertText ?" );
+
+ TextPaM aPaM( rCurSel.GetStart() );
+ TextNode* pNode = mpDoc->GetNodes().GetObject( aPaM.GetPara() );
+
+ if ( pNode->GetText().Len() < STRING_MAXLEN )
+ {
+ BOOL bDoOverwrite = ( bOverwrite &&
+ ( aPaM.GetIndex() < pNode->GetText().Len() ) ) ? TRUE : FALSE;
+
+ BOOL bUndoAction = ( rCurSel.HasRange() || bDoOverwrite );
+
+ if ( bUndoAction )
+ UndoActionStart( TEXTUNDO_INSERT );
+
+ if ( rCurSel.HasRange() )
+ {
+ aPaM = ImpDeleteText( rCurSel );
+ }
+ else if ( bDoOverwrite )
+ {
+ // Wenn Selektion, dann kein Zeichen ueberschreiben
+ TextSelection aTmpSel( aPaM );
+ aTmpSel.GetEnd().GetIndex()++;
+ ImpDeleteText( aTmpSel );
+ }
+
+ if ( IsUndoEnabled() && !IsInUndo() )
+ {
+ TextUndoInsertChars* pNewUndo = new TextUndoInsertChars( this, aPaM, c );
+ BOOL bTryMerge = ( !bDoOverwrite && ( c != ' ' ) ) ? TRUE : FALSE;
+ InsertUndo( pNewUndo, bTryMerge );
+ }
+
+ TEParaPortion* pPortion = mpTEParaPortions->GetObject( aPaM.GetPara() );
+ pPortion->MarkInvalid( aPaM.GetIndex(), 1 );
+ if ( c == '\t' )
+ pPortion->SetNotSimpleInvalid();
+ aPaM = mpDoc->InsertText( aPaM, c );
+ ImpCharsInserted( aPaM.GetPara(), aPaM.GetIndex()-1, 1 );
+
+ TextModified();
+
+ if ( bUndoAction )
+ UndoActionEnd( TEXTUNDO_INSERT );
+ }
+
+ return aPaM;
+}
+
+TextPaM TextEngine::ImpInsertText( const TextSelection& rCurSel, const XubString& rStr )
+{
+ TextPaM aPaM;
+
+ if ( rCurSel.HasRange() )
+ aPaM = ImpDeleteText( rCurSel );
+ else
+ aPaM = rCurSel.GetEnd();
+
+ TextPaM aCurPaM( aPaM ); // fuers Invalidieren
+
+ XubString aText( rStr );
+ aText.ConvertLineEnd( LINEEND_LF );
+
+ USHORT nStart = 0;
+ while ( nStart < aText.Len() )
+ {
+ USHORT nEnd = aText.Search( LINE_SEP, nStart );
+ if ( nEnd == STRING_NOTFOUND )
+ nEnd = aText.Len(); // nicht dereferenzieren!
+
+ // Start == End => Leerzeile
+ if ( nEnd > nStart )
+ {
+ ULONG nL = aPaM.GetIndex();
+ nL += ( nEnd-nStart );
+ if ( nL > STRING_MAXLEN )
+ {
+ USHORT nDiff = (USHORT) (nL-STRING_MAXLEN);
+ nEnd -= nDiff;
+ }
+
+ XubString aLine( aText, nStart, nEnd-nStart );
+ if ( IsUndoEnabled() && !IsInUndo() )
+ InsertUndo( new TextUndoInsertChars( this, aPaM, aLine ) );
+
+ TEParaPortion* pPortion = mpTEParaPortions->GetObject( aPaM.GetPara() );
+ pPortion->MarkInvalid( aPaM.GetIndex(), aLine.Len() );
+ if ( aLine.Search( '\t' ) != STRING_NOTFOUND )
+ pPortion->SetNotSimpleInvalid();
+
+ aPaM = mpDoc->InsertText( aPaM, aLine );
+ ImpCharsInserted( aPaM.GetPara(), aPaM.GetIndex()-aLine.Len(), aLine.Len() );
+
+ }
+ if ( nEnd < aText.Len() )
+ aPaM = ImpInsertParaBreak( aPaM );
+
+ nStart = nEnd+1;
+ }
+
+ TextModified();
+ return aPaM;
+}
+
+TextPaM TextEngine::ImpInsertParaBreak( const TextSelection& rCurSel, BOOL bKeepEndingAttribs )
+{
+ TextPaM aPaM;
+ if ( rCurSel.HasRange() )
+ aPaM = ImpDeleteText( rCurSel );
+ else
+ aPaM = rCurSel.GetEnd();
+
+ return ImpInsertParaBreak( aPaM, bKeepEndingAttribs );
+}
+
+TextPaM TextEngine::ImpInsertParaBreak( const TextPaM& rPaM, BOOL bKeepEndingAttribs )
+{
+ if ( IsUndoEnabled() && !IsInUndo() )
+ InsertUndo( new TextUndoSplitPara( this, rPaM.GetPara(), rPaM.GetIndex() ) );
+
+ TextPaM aPaM( mpDoc->InsertParaBreak( rPaM, bKeepEndingAttribs ) );
+
+ TEParaPortion* pPortion = mpTEParaPortions->GetObject( rPaM.GetPara() );
+ DBG_ASSERT( pPortion, "Blinde Portion in ImpInsertParaBreak" );
+ pPortion->MarkInvalid( rPaM.GetIndex(), 0 );
+
+ TextNode* pNewNode = mpDoc->GetNodes().GetObject( aPaM.GetPara() );
+ TEParaPortion* pNewPortion = new TEParaPortion( pNewNode );
+ mpTEParaPortions->Insert( pNewPortion, aPaM.GetPara() );
+ ImpParagraphInserted( aPaM.GetPara() );
+
+ CursorMoved( rPaM.GetPara() ); // falls leeres Attribut entstanden.
+ TextModified();
+ return aPaM;
+}
+
+Rectangle TextEngine::PaMtoEditCursor( const TextPaM& rPaM, BOOL bSpecial )
+{
+ DBG_ASSERT( GetUpdateMode(), "Darf bei Update=FALSE nicht erreicht werden: PaMtoEditCursor" );
+
+ Rectangle aEditCursor;
+ long nY = 0;
+ for ( ULONG nPortion = 0; nPortion < rPaM.GetPara(); nPortion++ )
+ {
+ TEParaPortion* pPortion = mpTEParaPortions->GetObject(nPortion);
+ nY += pPortion->GetLines().Count() * mnCharHeight;
+ }
+ aEditCursor = GetEditCursor( rPaM, bSpecial );
+ aEditCursor.Top() += nY;
+ aEditCursor.Bottom() += nY;
+ return aEditCursor;
+}
+
+Rectangle TextEngine::GetEditCursor( const TextPaM& rPaM, BOOL bSpecial )
+{
+ DBG_ASSERT( IsFormatted(), "GetEditCursor: Nicht formatiert" );
+
+ TEParaPortion* pPortion = mpTEParaPortions->GetObject( rPaM.GetPara() );
+ TextNode* pNode = mpDoc->GetNodes().GetObject( rPaM.GetPara() );
+
+ /*
+ bSpecial: Wenn hinter dem letzten Zeichen einer umgebrochenen Zeile,
+ am Ende der Zeile bleiben, nicht am Anfang der naechsten.
+ Zweck: - END => wirklich hinter das letzte Zeichen
+ - Selektion....
+ */
+
+ long nY = 0;
+ USHORT nCurIndex = 0;
+ TextLine* pLine = 0;
+ for ( USHORT nLine = 0; nLine < pPortion->GetLines().Count(); nLine++ )
+ {
+ TextLine* pTmpLine = pPortion->GetLines().GetObject( nLine );
+ if ( ( pTmpLine->GetStart() == rPaM.GetIndex() ) || ( pTmpLine->IsIn( rPaM.GetIndex(), bSpecial ) ) )
+ {
+ pLine = pTmpLine;
+ break;
+ }
+
+ nCurIndex += pTmpLine->GetLen();
+ nY += mnCharHeight;
+ }
+ if ( !pLine )
+ {
+ // Cursor am Ende des Absatzes.
+ DBG_ASSERT( rPaM.GetIndex() == nCurIndex, "Index voll daneben in GetEditCursor!" );
+
+ pLine = pPortion->GetLines().GetObject( pPortion->GetLines().Count()-1 );
+ nY -= mnCharHeight;
+ nCurIndex -= pLine->GetLen();
+ }
+
+ Rectangle aEditCursor;
+
+ aEditCursor.Top() = nY;
+ nY += mnCharHeight;
+ aEditCursor.Bottom() = nY-1;
+
+ // innerhalb der Zeile suchen....
+ long nX = pLine->GetStartX();
+ for ( USHORT i = pLine->GetStartPortion(); i <= pLine->GetEndPortion(); i++ )
+ {
+ TextPortion* pTextPortion = pPortion->GetTextPortions().GetObject( i );
+ nCurIndex += pTextPortion->GetLen();
+ if ( nCurIndex <= rPaM.GetIndex() )
+ {
+ nX += pTextPortion->GetWidth();
+
+ if ( nCurIndex == rPaM.GetIndex() )
+ break; // for
+ }
+ else // suchen und Ende
+ {
+ nCurIndex -= pTextPortion->GetLen();
+ nX += (long)CalcTextWidth( rPaM.GetPara(), nCurIndex, rPaM.GetIndex()-nCurIndex );
+ break; // for
+ }
+ }
+
+ aEditCursor.Left() = aEditCursor.Right() = nX;
+ return aEditCursor;
+}
+
+const TextAttrib* TextEngine::FindAttrib( const TextPaM& rPaM, USHORT nWhich ) const
+{
+ const TextAttrib* pAttr = NULL;
+ const TextCharAttrib* pCharAttr = FindCharAttrib( rPaM, nWhich );
+ if ( pCharAttr )
+ pAttr = &pCharAttr->GetAttr();
+ return pAttr;
+}
+
+const TextCharAttrib* TextEngine::FindCharAttrib( const TextPaM& rPaM, USHORT nWhich ) const
+{
+ const TextCharAttrib* pAttr = NULL;
+ TextNode* pNode = mpDoc->GetNodes().GetObject( rPaM.GetPara() );
+ if ( pNode && ( rPaM.GetIndex() < pNode->GetText().Len() ) )
+ pAttr = pNode->GetCharAttribs().FindAttrib( nWhich, rPaM.GetIndex() );
+ return pAttr;
+}
+
+BOOL TextEngine::HasAttrib( USHORT nWhich ) const
+{
+ BOOL bAttr = FALSE;
+ for ( ULONG n = mpDoc->GetNodes().Count(); --n && !bAttr; )
+ {
+ TextNode* pNode = mpDoc->GetNodes().GetObject( n );
+ bAttr = pNode->GetCharAttribs().HasAttrib( nWhich );
+ }
+ return bAttr;
+}
+
+TextPaM TextEngine::GetPaM( const Point& rDocPos, BOOL bSmart )
+{
+ DBG_ASSERT( GetUpdateMode(), "Darf bei Update=FALSE nicht erreicht werden: GetPaM" );
+
+ long nY = 0;
+ for ( ULONG nPortion = 0; nPortion < mpTEParaPortions->Count(); nPortion++ )
+ {
+ TEParaPortion* pPortion = mpTEParaPortions->GetObject( nPortion );
+ long nTmpHeight = pPortion->GetLines().Count() * mnCharHeight;
+ nY += nTmpHeight;
+ if ( nY > rDocPos.Y() )
+ {
+ nY -= nTmpHeight;
+ Point aPosInPara( rDocPos );
+ aPosInPara.Y() -= nY;
+
+ TextPaM aPaM( nPortion, 0 );
+ aPaM.GetIndex() = ImpFindIndex( nPortion, aPosInPara, bSmart );
+ return aPaM;
+ }
+ }
+
+ // Nicht gefunden - Dann den letzten sichtbare...
+ ULONG nLastNode = mpDoc->GetNodes().Count() - 1;
+ TextNode* pLast = mpDoc->GetNodes().GetObject( nLastNode );
+ return TextPaM( nLastNode, pLast->GetText().Len() );
+}
+
+USHORT TextEngine::ImpFindIndex( ULONG nPortion, const Point& rPosInPara, BOOL bSmart )
+{
+ DBG_ASSERT( IsFormatted(), "GetPaM: Nicht formatiert" );
+ TEParaPortion* pPortion = mpTEParaPortions->GetObject( nPortion );
+
+ USHORT nCurIndex = 0;
+
+ long nY = 0;
+ TextLine* pLine = 0;
+ USHORT nLine;
+ for ( nLine = 0; nLine < pPortion->GetLines().Count(); nLine++ )
+ {
+ TextLine* pTmpLine = pPortion->GetLines().GetObject( nLine );
+ nY += mnCharHeight;
+ if ( nY > rPosInPara.Y() ) // das war 'se
+ {
+ pLine = pTmpLine;
+ break; // richtige Y-Position intressiert nicht
+ }
+ }
+ DBG_ASSERT( pLine, "ImpFindIndex: pLine ?" );
+
+ nCurIndex = GetCharPos( nPortion, nLine, rPosInPara.X(), bSmart );
+
+ if ( nCurIndex && ( nCurIndex == pLine->GetEnd() ) &&
+ ( pLine != pPortion->GetLines().GetObject( pPortion->GetLines().Count()-1) ) )
+ {
+ nCurIndex--;
+ }
+ return nCurIndex;
+}
+
+USHORT TextEngine::GetCharPos( ULONG nPortion, USHORT nLine, long nXPos, BOOL bSmart )
+{
+
+ TEParaPortion* pPortion = mpTEParaPortions->GetObject( nPortion );
+ TextLine* pLine = pPortion->GetLines().GetObject( nLine );
+
+ USHORT nCurIndex = pLine->GetStart();
+
+ if ( !nXPos )
+ return nCurIndex;
+
+ long nTmpX = pLine->GetStartX();
+ for ( USHORT i = pLine->GetStartPortion(); i <= pLine->GetEndPortion(); i++ )
+ {
+ TextPortion* pTextPortion = pPortion->GetTextPortions().GetObject( i );
+ nTmpX += pTextPortion->GetWidth();
+
+ if ( nTmpX > nXPos )
+ {
+ if( pTextPortion->GetLen() > 1 )
+ {
+ nTmpX -= pTextPortion->GetWidth(); // vor die Portion stellen
+ // Optimieren: Kein GetTextBreak, wenn feste Fontbreite...
+ Font aFont;
+ SeekCursor( nPortion, nCurIndex+1, aFont );
+ mpRefDev->SetFont( aFont );
+ nCurIndex = mpRefDev->GetTextBreak( pPortion->GetNode()->GetText(), nXPos-nTmpX, nCurIndex );
+ }
+ return nCurIndex;
+ }
+ nCurIndex += pTextPortion->GetLen();
+ }
+ return nCurIndex;
+}
+
+
+ULONG TextEngine::GetTextHeight() const
+{
+ DBG_ASSERT( GetUpdateMode(), "Sollte bei Update=FALSE nicht verwendet werden: GetTextHeight" );
+ DBG_ASSERT( IsFormatted() || IsFormatting(), "GetTextHeight: Nicht formatiert" );
+ return mnCurTextHeight;
+}
+
+ULONG TextEngine::CalcTextWidth()
+{
+ if ( !IsFormatted() && !IsFormatting() )
+ FormatDoc();
+
+ long nMaxWidth = 0;
+ long nCurWidth = 0;
+
+ // --------------------------------------------------
+ // Ueber alle Absaetze...
+ // --------------------------------------------------
+ ULONG nParas = mpTEParaPortions->Count();
+ for ( ULONG nPara = mpTEParaPortions->Count(); nPara; )
+ {
+ TEParaPortion* pPortion = mpTEParaPortions->GetObject( --nPara );
+
+ // --------------------------------------------------
+ // Ueber die Zeilen des Absatzes...
+ // --------------------------------------------------
+ for ( USHORT nLine = pPortion->GetLines().Count(); nLine; )
+ {
+ TextLine* pLine = pPortion->GetLines().GetObject( --nLine );
+ // --------------------------------------------------
+ // Ueber die Portions der Zeile
+ // --------------------------------------------------
+ nCurWidth = 0;
+ for ( USHORT nTP = pLine->GetStartPortion(); nTP <= pLine->GetEndPortion(); nTP++ )
+ {
+ TextPortion* pTextPortion = pPortion->GetTextPortions().GetObject( nTP );
+ nCurWidth += pTextPortion->GetWidth();
+ }
+ if ( nCurWidth > nMaxWidth )
+ nMaxWidth = nCurWidth;
+ }
+ }
+ nMaxWidth++; // Ein breiter, da in CreateLines bei >= umgebrochen wird.
+ return (ULONG)nMaxWidth;
+}
+
+ULONG TextEngine::CalcTextHeight()
+{
+ DBG_ASSERT( GetUpdateMode(), "Sollte bei Update=FALSE nicht verwendet werden: CalcTextHeight" );
+
+ ULONG nY = 0;
+ for ( ULONG nPortion = mpTEParaPortions->Count(); nPortion; )
+ nY += CalcParaHeight( --nPortion );
+ return nY;
+}
+
+ULONG TextEngine::CalcTextWidth( ULONG nPara, USHORT nPortionStart, USHORT nLen, const Font* pFont )
+{
+ // Innerhalb des Textes darf es keinen Portionwechsel (Attribut/Tab) geben!
+ DBG_ASSERT( mpDoc->GetNodes().GetObject( nPara )->GetText().Search( '\t', nPortionStart ) >= (nPortionStart+nLen), "CalcTextWidth: Tab!" );
+
+ ULONG nWidth;
+ if ( mnFixCharWidth100 )
+ nWidth = (ULONG)nLen*mnFixCharWidth100/100;
+ else
+ {
+ if ( pFont )
+ {
+ if ( !mpRefDev->GetFont().IsSameInstance( *pFont ) )
+ mpRefDev->SetFont( *pFont );
+ }
+ else
+ {
+ Font aFont;
+ SeekCursor( nPara, nPortionStart+1, aFont );
+ mpRefDev->SetFont( aFont );
+ }
+ TextNode* pNode = mpDoc->GetNodes().GetObject( nPara );
+ nWidth = (ULONG)mpRefDev->GetTextWidth( pNode->GetText(), nPortionStart, nLen );
+
+ }
+ return nWidth;
+}
+
+
+USHORT TextEngine::GetLineCount( ULONG nParagraph ) const
+{
+ DBG_ASSERT( nParagraph < mpTEParaPortions->Count(), "GetLineCount: Out of range" );
+
+ TEParaPortion* pPPortion = mpTEParaPortions->GetObject( nParagraph );
+ if ( pPPortion )
+ return pPPortion->GetLines().Count();
+
+ return 0xFFFF;
+}
+
+USHORT TextEngine::GetLineLen( ULONG nParagraph, USHORT nLine ) const
+{
+ DBG_ASSERT( nParagraph < mpTEParaPortions->Count(), "GetLineCount: Out of range" );
+
+ TEParaPortion* pPPortion = mpTEParaPortions->GetObject( nParagraph );
+ if ( pPPortion && ( nLine < pPPortion->GetLines().Count() ) )
+ {
+ TextLine* pLine = pPPortion->GetLines().GetObject( nLine );
+ return pLine->GetLen();
+ }
+
+ return 0xFFFF;
+}
+
+ULONG TextEngine::CalcParaHeight( ULONG nParagraph )
+{
+ ULONG nHeight = 0;
+
+ TEParaPortion* pPPortion = mpTEParaPortions->GetObject( nParagraph );
+ DBG_ASSERT( pPPortion, "Absatz nicht gefunden: GetParaHeight" );
+ if ( pPPortion )
+ nHeight = pPPortion->GetLines().Count() * mnCharHeight;
+
+ return nHeight;
+}
+
+void TextEngine::UpdateSelections()
+{
+}
+
+Range TextEngine::GetInvalidYOffsets( ULONG nPortion )
+{
+ TEParaPortion* pTEParaPortion = mpTEParaPortions->GetObject( nPortion );
+ USHORT nLines = pTEParaPortion->GetLines().Count();
+ USHORT nLastInvalid, nFirstInvalid = 0;
+ USHORT nLine;
+ for ( nLine = 0; nLine < nLines; nLine++ )
+ {
+ TextLine* pL = pTEParaPortion->GetLines().GetObject( nLine );
+ if ( pL->IsInvalid() )
+ {
+ nFirstInvalid = nLine;
+ break;
+ }
+ }
+
+ for ( nLastInvalid = nFirstInvalid; nLastInvalid < nLines; nLastInvalid++ )
+ {
+ TextLine* pL = pTEParaPortion->GetLines().GetObject( nLine );
+ if ( pL->IsValid() )
+ break;
+ }
+
+ if ( nLastInvalid >= nLines )
+ nLastInvalid = nLines-1;
+
+ return Range( nFirstInvalid*mnCharHeight, ((nLastInvalid+1)*mnCharHeight)-1 );
+}
+
+ULONG TextEngine::GetParagraphCount() const
+{
+ return mpDoc->GetNodes().Count();
+}
+
+void TextEngine::EnableUndo( BOOL bEnable )
+{
+ // Beim Umschalten des Modus Liste loeschen:
+ if ( bEnable != IsUndoEnabled() )
+ ResetUndo();
+
+ mbUndoEnabled = bEnable;
+}
+
+SfxUndoManager& TextEngine::GetUndoManager()
+{
+ if ( !mpUndoManager )
+ mpUndoManager = new TextUndoManager( this );
+ return *mpUndoManager;
+}
+
+void TextEngine::UndoActionStart( USHORT nId )
+{
+ if ( IsUndoEnabled() && !IsInUndo() )
+ {
+ String aComment;
+ // ...
+ GetUndoManager().EnterListAction( aComment, XubString(), nId );
+ }
+}
+
+void TextEngine::UndoActionEnd( USHORT nId )
+{
+ if ( IsUndoEnabled() && !IsInUndo() )
+ GetUndoManager().LeaveListAction();
+}
+
+void TextEngine::InsertUndo( TextUndo* pUndo, BOOL bTryMerge )
+{
+ DBG_ASSERT( !IsInUndo(), "InsertUndo im Undomodus!" );
+ GetUndoManager().AddUndoAction( pUndo, bTryMerge );
+}
+
+void TextEngine::ResetUndo()
+{
+ if ( mpUndoManager )
+ mpUndoManager->Clear();
+}
+
+void TextEngine::InsertContent( TextNode* pNode, ULONG nPara )
+{
+ DBG_ASSERT( pNode, "NULL-Pointer in InsertContent! " );
+ DBG_ASSERT( IsInUndo(), "InsertContent nur fuer Undo()!" );
+ TEParaPortion* pNew = new TEParaPortion( pNode );
+ mpTEParaPortions->Insert( pNew, nPara );
+ mpDoc->GetNodes().Insert( pNode, nPara );
+ ImpParagraphInserted( nPara );
+}
+
+TextPaM TextEngine::SplitContent( ULONG nNode, USHORT nSepPos )
+{
+ TextNode* pNode = mpDoc->GetNodes().GetObject( nNode );
+ DBG_ASSERT( pNode, "Ungueltiger Node in SplitContent" );
+ DBG_ASSERT( IsInUndo(), "SplitContent nur fuer Undo()!" );
+ DBG_ASSERT( nSepPos <= pNode->GetText().Len(), "Index im Wald: SplitContent" );
+ TextPaM aPaM( nNode, nSepPos );
+ return ImpInsertParaBreak( aPaM );
+}
+
+TextPaM TextEngine::ConnectContents( ULONG nLeftNode )
+{
+ DBG_ASSERT( IsInUndo(), "ConnectContent nur fuer Undo()!" );
+ return ImpConnectParagraphs( nLeftNode, nLeftNode+1 );
+}
+
+void TextEngine::SeekCursor( ULONG nPara, USHORT nPos, Font& rFont )
+{
+ rFont = maFont;
+
+ TextNode* pNode = mpDoc->GetNodes().GetObject( nPara );
+ USHORT nAttribs = pNode->GetCharAttribs().Count();
+ for ( USHORT nAttr = 0; nAttr < nAttribs; nAttr++ )
+ {
+ TextCharAttrib* pAttrib = pNode->GetCharAttribs().GetAttrib( nAttr );
+ if ( pAttrib->GetStart() > nPos )
+ break;
+
+ // Beim Seeken nicht die Attr beruecksichtigen, die dort beginnen!
+ // Leere Attribute werden beruecksichtigt( verwendet), da diese
+ // gerade eingestellt wurden.
+ // 12.4.95: Doch keine Leeren Attribute verwenden:
+ // - Wenn gerade eingestellt und leer => keine Auswirkung auf Font
+ // In einem leeren Absatz eingestellte Zeichen werden sofort wirksam.
+ if ( ( ( pAttrib->GetStart() < nPos ) && ( pAttrib->GetEnd() >= nPos ) )
+ || !pNode->GetText().Len() )
+ {
+ pAttrib->GetAttr().SetFont( rFont );
+ }
+ }
+}
+
+void TextEngine::SetUpdateMode( BOOL bUp, TextView* pCurView, BOOL bForceUpdate )
+{
+ BOOL bChanged = ( GetUpdateMode() != bUp );
+
+ mbUpdate = bUp;
+ if ( mbUpdate && ( bChanged || bForceUpdate ) )
+ FormatAndUpdate( pCurView );
+}
+
+void TextEngine::FormatAndUpdate( TextView* pCurView )
+{
+ if ( mbDowning )
+ return ;
+
+ if ( IsInUndo() )
+ IdleFormatAndUpdate( pCurView );
+ else
+ {
+ FormatDoc();
+ UpdateViews( pCurView );
+ }
+}
+
+
+void TextEngine::IdleFormatAndUpdate( TextView* pCurView )
+{
+ mpIdleFormatter->DoIdleFormat( pCurView );
+}
+
+void TextEngine::TextModified()
+{
+ mbFormatted = FALSE;
+}
+
+void TextEngine::UpdateViews( TextView* pCurView )
+{
+ if ( !GetUpdateMode() || IsFormatting() || maInvalidRec.IsEmpty() )
+ return;
+
+ DBG_ASSERT( IsFormatted(), "UpdateViews: Doc nicht formatiert!" );
+
+ for ( USHORT nView = 0; nView < mpViews->Count(); nView++ )
+ {
+ TextView* pView = mpViews->GetObject( nView );
+ pView->HideCursor();
+
+ Rectangle aClipRec( maInvalidRec );
+ Rectangle aVisArea( pView->GetStartDocPos(), pView->GetWindow()->GetOutputSizePixel() );
+ aClipRec.Intersection( aVisArea );
+ if ( !aClipRec.IsEmpty() )
+ {
+ // in Fensterkoordinaten umwandeln....
+ aClipRec.SetPos( pView->GetWindowPos( aClipRec.TopLeft() ) );
+
+ if ( pView == pCurView )
+ pView->ImpPaint( aClipRec, TRUE );
+ else
+ pView->GetWindow()->Invalidate( aClipRec );
+ }
+ }
+
+ if ( pCurView )
+ {
+ pCurView->ShowCursor( pCurView->mbAutoScroll );
+ }
+
+ maInvalidRec = Rectangle();
+}
+
+IMPL_LINK_INLINE_START( TextEngine, IdleFormatHdl, Timer *, EMPTYARG )
+{
+ mpIdleFormatter->ResetRestarts();
+ FormatAndUpdate( mpIdleFormatter->GetView() );
+ return 0;
+}
+IMPL_LINK_INLINE_END( TextEngine, IdleFormatHdl, Timer *, EMPTYARG )
+
+void TextEngine::CheckIdleFormatter()
+{
+ mpIdleFormatter->ForceTimeout();
+}
+
+void TextEngine::FormatFullDoc()
+{
+ for ( ULONG nPortion = 0; nPortion < mpTEParaPortions->Count(); nPortion++ )
+ {
+ TEParaPortion* pTEParaPortion = mpTEParaPortions->GetObject( nPortion );
+ USHORT nLen = pTEParaPortion->GetNode()->GetText().Len();
+ pTEParaPortion->MarkSelectionInvalid( 0, nLen );
+ }
+ FormatDoc();
+}
+
+void TextEngine::FormatDoc()
+{
+ if ( !GetUpdateMode() || IsFormatting() )
+ return;
+
+ mbIsFormatting = TRUE;
+ mbModified = TRUE;
+
+ long nY = 0;
+ BOOL bGrow = FALSE;
+
+ maInvalidRec = Rectangle(); // leermachen
+ for ( ULONG nPara = 0; nPara < mpTEParaPortions->Count(); nPara++ )
+ {
+ TEParaPortion* pTEParaPortion = mpTEParaPortions->GetObject( nPara );
+ if ( pTEParaPortion->IsInvalid() )
+ {
+ ImpFormattingParagraph( nPara );
+
+ if ( CreateLines( nPara ) )
+ bGrow = TRUE;
+
+ // InvalidRec nur einmal setzen...
+ if ( maInvalidRec.IsEmpty() )
+ {
+ // Bei Paperwidth 0 (AutoPageSize) bleibt es sonst Empty()...
+ long nWidth = (long)mnMaxTextWidth;
+ if ( !nWidth )
+ nWidth = 0x7FFFFFFF;
+ Range aInvRange( GetInvalidYOffsets( nPara ) );
+ maInvalidRec = Rectangle( Point( 0, nY+aInvRange.Min() ),
+ Size( nWidth, aInvRange.Len() ) );
+ }
+ else
+ {
+ maInvalidRec.Bottom() = nY + CalcParaHeight( nPara );
+ }
+ }
+ else if ( bGrow )
+ {
+ maInvalidRec.Bottom() = nY + CalcParaHeight( nPara );
+ }
+ nY += CalcParaHeight( nPara );
+ }
+
+ if ( !maInvalidRec.IsEmpty() )
+ {
+ ULONG nNewHeight = CalcTextHeight();
+ long nDiff = nNewHeight - mnCurTextHeight;
+ if ( nNewHeight < mnCurTextHeight )
+ {
+ maInvalidRec.Bottom() = (long)Max( nNewHeight, mnCurTextHeight );
+ if ( maInvalidRec.IsEmpty() )
+ {
+ maInvalidRec.Top() = 0;
+ // Left und Right werden nicht ausgewertet, aber wegen IsEmpty gesetzt.
+ maInvalidRec.Left() = 0;
+ maInvalidRec.Right() = mnMaxTextWidth;
+ }
+ }
+
+ mnCurTextHeight = nNewHeight;
+ if ( nDiff )
+ {
+ mbFormatted = TRUE;
+ ImpTextHeightChanged();
+ }
+ }
+
+ mbIsFormatting = FALSE;
+ mbFormatted = TRUE;
+
+ ImpTextFormatted();
+}
+
+void TextEngine::CreateAndInsertEmptyLine( ULONG nPara )
+{
+ TextNode* pNode = mpDoc->GetNodes().GetObject( nPara );
+ TEParaPortion* pTEParaPortion = mpTEParaPortions->GetObject( nPara );
+
+ TextLine* pTmpLine = new TextLine;
+ pTmpLine->SetStart( pNode->GetText().Len() );
+ pTmpLine->SetEnd( pTmpLine->GetStart() );
+ pTEParaPortion->GetLines().Insert( pTmpLine, pTEParaPortion->GetLines().Count() );
+
+ if ( meAlign == TXTALIGN_CENTER )
+ pTmpLine->SetStartX( (short)(mnMaxTextWidth / 2) );
+ else if ( meAlign == TXTALIGN_RIGHT )
+ pTmpLine->SetStartX( (short)mnMaxTextWidth );
+ else
+ pTmpLine->SetStartX( mpDoc->GetLeftMargin() );
+
+ BOOL bLineBreak = pNode->GetText().Len() ? TRUE : FALSE;
+
+ TextPortion* pDummyPortion = new TextPortion( 0 );
+ pDummyPortion->GetWidth() = 0;
+ pTEParaPortion->GetTextPortions().Insert( pDummyPortion, pTEParaPortion->GetTextPortions().Count() );
+
+ if ( bLineBreak == TRUE )
+ {
+ // -2: Die neue ist bereits eingefuegt.
+ TextLine* pLastLine = pTEParaPortion->GetLines().GetObject( pTEParaPortion->GetLines().Count()-2 );
+ DBG_ASSERT( pLastLine, "Weicher Umbruch, keine Zeile ?!" );
+ USHORT nPos = (USHORT) pTEParaPortion->GetTextPortions().Count() - 1 ;
+ pTmpLine->SetStartPortion( nPos );
+ pTmpLine->SetEndPortion( nPos );
+ }
+}
+
+void TextEngine::ImpBreakLine( ULONG nPara, TextLine* pLine, TextPortion* pPortion, USHORT nPortionStart, long nRemainingWidth )
+{
+ TextNode* pNode = mpDoc->GetNodes().GetObject( nPara );
+
+ // Font sollte noch eingestellt sein.
+ USHORT nMaxBreakPos = mpRefDev->GetTextBreak( pNode->GetText(), nRemainingWidth, nPortionStart );
+
+ DBG_ASSERT( nMaxBreakPos < pNode->GetText().Len(), "Break?!" );
+
+ if ( nMaxBreakPos == STRING_LEN ) // GetTextBreak() ist anderer Auffassung als GetTextSize()
+ nMaxBreakPos = pNode->GetText().Len() - 1;
+
+ uno::Reference < text::XBreakIterator > xBI = GetBreakIterator();
+ text::LineBreakHyphenationOptions aHyphOptions( NULL, 1 );
+ text::LineBreakUserOptions aUserOptions;
+ text::LineBreakResults aLBR = xBI->getLineBreak( pNode->GetText(), nMaxBreakPos, GetLocale(), pLine->GetStart(), aHyphOptions, aUserOptions );
+ USHORT nBreakPos = aLBR.breakIndex;
+ if ( nBreakPos <= pLine->GetStart() )
+ nBreakPos = nMaxBreakPos;
+
+ // die angeknackste Portion ist die End-Portion
+ pLine->SetEnd( nBreakPos );
+ USHORT nEndPortion = SplitTextPortion( nPara, nBreakPos );
+
+ sal_Bool bBlankSeparator = ( ( nBreakPos >= pLine->GetStart() ) &&
+ ( pNode->GetText().GetChar( nBreakPos ) == ' ' ) ) ? sal_True : sal_False;
+ if ( bBlankSeparator )
+ {
+ // Blanks am Zeilenende generell unterdruecken...
+ TEParaPortion* pTEParaPortion = mpTEParaPortions->GetObject( nPara );
+ TextPortion* pTP = pTEParaPortion->GetTextPortions().GetObject( nEndPortion );
+ DBG_ASSERT( nBreakPos > pLine->GetStart(), "SplitTextPortion am Anfang der Zeile?" );
+ pTP->GetWidth() = (long)CalcTextWidth( nPara, nBreakPos-pTP->GetLen(), pTP->GetLen()-1 );
+ }
+ pLine->SetEndPortion( nEndPortion );
+}
+
+USHORT TextEngine::SplitTextPortion( ULONG nPara, USHORT nPos )
+{
+
+ // Die Portion bei nPos wird geplittet, wenn bei nPos nicht
+ // sowieso ein Wechsel ist
+ if ( nPos == 0 )
+ return 0;
+
+ USHORT nSplitPortion;
+ USHORT nTmpPos = 0;
+ TextPortion* pTextPortion = 0;
+ TEParaPortion* pTEParaPortion = mpTEParaPortions->GetObject( nPara );
+ USHORT nPortions = pTEParaPortion->GetTextPortions().Count();
+ for ( nSplitPortion = 0; nSplitPortion < nPortions; nSplitPortion++ )
+ {
+ TextPortion* pTP = pTEParaPortion->GetTextPortions().GetObject(nSplitPortion);
+ nTmpPos += pTP->GetLen();
+ if ( nTmpPos >= nPos )
+ {
+ if ( nTmpPos == nPos ) // dann braucht nichts geteilt werden
+ return nSplitPortion;
+ pTextPortion = pTP;
+ break;
+ }
+ }
+
+ DBG_ASSERT( pTextPortion, "Position ausserhalb des Bereichs!" );
+
+ USHORT nOverlapp = nTmpPos - nPos;
+ pTextPortion->GetLen() -= nOverlapp;
+ TextPortion* pNewPortion = new TextPortion( nOverlapp );
+ pTEParaPortion->GetTextPortions().Insert( pNewPortion, nSplitPortion+1 );
+ pTextPortion->GetWidth() = (long)CalcTextWidth( nPara, nPos-pTextPortion->GetLen(), pTextPortion->GetLen() );
+
+ return nSplitPortion;
+}
+
+void TextEngine::CreateTextPortions( ULONG nPara, USHORT nStartPos )
+{
+ TEParaPortion* pTEParaPortion = mpTEParaPortions->GetObject( nPara );
+ TextNode* pNode = pTEParaPortion->GetNode();
+ DBG_ASSERT( pNode->GetText().Len(), "CreateTextPortions sollte nicht fuer leere Absaetze verwendet werden!" );
+
+ TESortedPositions aPositions;
+ ULONG nZero = 0;
+ aPositions.Insert( nZero );
+
+ USHORT nAttribs = pNode->GetCharAttribs().Count();
+ for ( USHORT nAttr = 0; nAttr < nAttribs; nAttr++ )
+ {
+ TextCharAttrib* pAttrib = pNode->GetCharAttribs().GetAttrib( nAttr );
+
+ // Start und Ende in das Array eintragen...
+ // Die InsertMethode laesst keine doppelten Werte zu....
+ aPositions.Insert( pAttrib->GetStart() );
+ aPositions.Insert( pAttrib->GetEnd() );
+ }
+ aPositions.Insert( pNode->GetText().Len() );
+
+ USHORT nTabPos = pNode->GetText().Search( '\t', 0 );
+ while ( nTabPos != STRING_NOTFOUND )
+ {
+ aPositions.Insert( nTabPos );
+ aPositions.Insert( nTabPos + 1 );
+ nTabPos = pNode->GetText().Search( '\t', nTabPos+1 );
+ }
+
+ // Ab ... loeschen:
+ // Leider muss die Anzahl der TextPortions mit aPositions.Count()
+ // nicht uebereinstimmen, da evtl. Zeilenumbrueche...
+ USHORT nPortionStart = 0;
+ USHORT nInvPortion = 0;
+ for ( USHORT nP = 0; nP < pTEParaPortion->GetTextPortions().Count(); nP++ )
+ {
+ TextPortion* pTmpPortion = pTEParaPortion->GetTextPortions().GetObject(nP);
+ nPortionStart += pTmpPortion->GetLen();
+ if ( nPortionStart >= nStartPos )
+ {
+ nPortionStart -= pTmpPortion->GetLen();
+ nInvPortion = nP;
+ break;
+ }
+ }
+ DBG_ASSERT( nP < pTEParaPortion->GetTextPortions().Count() || !pTEParaPortion->GetTextPortions().Count(), "Nichts zum loeschen: CreateTextPortions" );
+ if ( nInvPortion && ( nPortionStart+pTEParaPortion->GetTextPortions().GetObject(nInvPortion)->GetLen() > nStartPos ) )
+ {
+ // lieber eine davor...
+ // Aber nur wenn es mitten in der Portion war, sonst ist es evtl.
+ // die einzige in der Zeile davor !
+ nInvPortion--;
+ nPortionStart -= pTEParaPortion->GetTextPortions().GetObject(nInvPortion)->GetLen();
+ }
+ pTEParaPortion->GetTextPortions().DeleteFromPortion( nInvPortion );
+
+ // Eine Portion kann auch durch einen Zeilenumbruch entstanden sein:
+ aPositions.Insert( nPortionStart );
+
+ USHORT nInvPos;
+ BOOL bFound = aPositions.Seek_Entry( nPortionStart, &nInvPos );
+ DBG_ASSERT( bFound && ( nInvPos < (aPositions.Count()-1) ), "InvPos ?!" );
+ for ( USHORT i = nInvPos+1; i < aPositions.Count(); i++ )
+ {
+ TextPortion* pNew = new TextPortion( (USHORT)aPositions[i] - (USHORT)aPositions[i-1] );
+ pTEParaPortion->GetTextPortions().Insert( pNew, pTEParaPortion->GetTextPortions().Count());
+ }
+
+ DBG_ASSERT( pTEParaPortion->GetTextPortions().Count(), "Keine Portions?!" );
+#ifdef EDITDEBUG
+ DBG_ASSERT( pTEParaPortion->DbgCheckTextPortions(), "Portions kaputt?" );
+#endif
+}
+
+void TextEngine::RecalcTextPortion( ULONG nPara, USHORT nStartPos, short nNewChars )
+{
+ TEParaPortion* pTEParaPortion = mpTEParaPortions->GetObject( nPara );
+ DBG_ASSERT( pTEParaPortion->GetTextPortions().Count(), "Keine Portions!" );
+ DBG_ASSERT( nNewChars, "RecalcTextPortion mit Diff == 0" );
+
+ TextNode* const pNode = pTEParaPortion->GetNode();
+ if ( nNewChars > 0 )
+ {
+ // Wenn an nStartPos ein Attribut beginnt/endet, oder vor nStartPos
+ // ein Tab steht, faengt eine neue Portion an,
+ // ansonsten wird die Portion an nStartPos erweitert.
+ // Oder wenn ganz vorne ( StartPos 0 ) und dann ein Tab
+
+ if ( ( pNode->GetCharAttribs().HasBoundingAttrib( nStartPos ) ) ||
+ ( nStartPos && ( pNode->GetText().GetChar( nStartPos - 1 ) == '\t' ) ) ||
+ ( ( !nStartPos && ( nNewChars < pNode->GetText().Len() ) && pNode->GetText().GetChar( nNewChars ) == '\t' ) ) )
+ {
+ USHORT nNewPortionPos = 0;
+ if ( nStartPos )
+ nNewPortionPos = SplitTextPortion( nPara, nStartPos ) + 1;
+// else if ( ( pTEParaPortion->GetTextPortions().Count() == 1 ) &&
+// !pTEParaPortion->GetTextPortions()[0]->GetLen() )
+// pTEParaPortion->GetTextPortions().Reset(); // DummyPortion
+
+ // Eine leere Portion kann hier stehen, wenn der Absatz leer war,
+ // oder eine Zeile durch einen harten Zeilenumbruch entstanden ist.
+ if ( ( nNewPortionPos < pTEParaPortion->GetTextPortions().Count() ) &&
+ !pTEParaPortion->GetTextPortions()[nNewPortionPos]->GetLen() )
+ {
+ // Dann die leere Portion verwenden.
+ pTEParaPortion->GetTextPortions()[nNewPortionPos]->GetLen() += nNewChars;
+ }
+ else
+ {
+ TextPortion* pNewPortion = new TextPortion( nNewChars );
+ pTEParaPortion->GetTextPortions().Insert( pNewPortion, nNewPortionPos );
+ }
+ }
+ else
+ {
+ USHORT nPortionStart;
+ const USHORT nTP = pTEParaPortion->GetTextPortions().
+ FindPortion( nStartPos, nPortionStart );
+ TextPortion* const pTP = pTEParaPortion->GetTextPortions()[ nTP ];
+ DBG_ASSERT( pTP, "RecalcTextPortion: Portion nicht gefunden" );
+ pTP->GetLen() += nNewChars;
+ pTP->GetWidth() = (-1);
+ }
+ }
+ else
+ {
+ // Portion schrumpfen oder ggf. entfernen.
+ // Vor Aufruf dieser Methode muss sichergestellt sein, dass
+ // keine Portions in dem geloeschten Bereich lagen!
+
+ // Es darf keine reinragende oder im Bereich startende Portion geben,
+ // also muss nStartPos <= nPos <= nStartPos - nNewChars(neg.) sein
+ USHORT nPortion = 0;
+ USHORT nPos = 0;
+ USHORT nEnd = nStartPos-nNewChars;
+ USHORT nPortions = pTEParaPortion->GetTextPortions().Count();
+ TextPortion* pTP = 0;
+ for ( nPortion = 0; nPortion < nPortions; nPortion++ )
+ {
+ pTP = pTEParaPortion->GetTextPortions()[ nPortion ];
+ if ( ( nPos+pTP->GetLen() ) > nStartPos )
+ {
+ DBG_ASSERT( nPos <= nStartPos, "Start falsch!" );
+ DBG_ASSERT( nPos+pTP->GetLen() >= nEnd, "End falsch!" );
+ break;
+ }
+ nPos += pTP->GetLen();
+ }
+ DBG_ASSERT( pTP, "RecalcTextPortion: Portion nicht gefunden" );
+ if ( ( nPos == nStartPos ) && ( (nPos+pTP->GetLen()) == nEnd ) )
+ {
+ // Portion entfernen;
+ pTEParaPortion->GetTextPortions().Remove( nPortion );
+ delete pTP;
+ }
+ else
+ {
+ DBG_ASSERT( pTP->GetLen() > (-nNewChars), "Portion zu klein zum schrumpfen!" );
+ pTP->GetLen() += nNewChars;
+ }
+ DBG_ASSERT( pTEParaPortion->GetTextPortions().Count(), "RecalcTextPortions: Keine mehr da!" );
+ }
+
+#ifdef EDITDEBUG
+ DBG_ASSERT( pTEParaPortion->DbgCheckTextPortions(), "Portions kaputt?" );
+#endif
+}
+
+void TextEngine::ImpPaint( OutputDevice* pOutDev, const Point& rStartPos, Rectangle const* pPaintArea, TextSelection const* pPaintRange, TextSelection const* pSelection )
+{
+ if ( !GetUpdateMode() )
+ return;
+
+ if ( !IsFormatted() )
+ FormatDoc();
+
+ long nY = rStartPos.Y();
+
+ TextPaM const* pSelStart = 0;
+ TextPaM const* pSelEnd = 0;
+ if ( pSelection && pSelection->HasRange() )
+ {
+ BOOL bInvers = pSelection->GetEnd() < pSelection->GetStart();
+ pSelStart = !bInvers ? &pSelection->GetStart() : &pSelection->GetEnd();
+ pSelEnd = bInvers ? &pSelection->GetStart() : &pSelection->GetEnd();
+ }
+ DBG_ASSERT( !pPaintRange || ( pPaintRange->GetStart() < pPaintRange->GetEnd() ), "ImpPaint: Paint-Range?!" );
+
+ const StyleSettings& rStyleSettings = pOutDev->GetSettings().GetStyleSettings();
+
+ // --------------------------------------------------
+ // Ueber alle Absaetze...
+ // --------------------------------------------------
+ for ( ULONG nPara = 0; nPara < mpTEParaPortions->Count(); nPara++ )
+ {
+ TEParaPortion* pPortion = mpTEParaPortions->GetObject( nPara );
+ // falls beim Tippen Idle-Formatierung, asynchrones Paint.
+ if ( pPortion->IsInvalid() )
+ return;
+
+ ULONG nParaHeight = CalcParaHeight( nPara );
+ USHORT nIndex = 0;
+ if ( ( !pPaintArea || ( ( nY + (long)nParaHeight ) > pPaintArea->Top() ) )
+ && ( !pPaintRange || ( ( nPara >= pPaintRange->GetStart().GetPara() ) && ( nPara <= pPaintRange->GetEnd().GetPara() ) ) ) )
+ {
+ // --------------------------------------------------
+ // Ueber die Zeilen des Absatzes...
+ // --------------------------------------------------
+ USHORT nLines = pPortion->GetLines().Count();
+ for ( USHORT nLine = 0; nLine < nLines; nLine++ )
+ {
+ TextLine* pLine = pPortion->GetLines().GetObject(nLine);
+ Point aTmpPos( rStartPos.X() + pLine->GetStartX(), nY );
+
+ if ( ( !pPaintArea || ( ( nY + mnCharHeight ) > pPaintArea->Top() ) )
+ && ( !pPaintRange || (
+ ( TextPaM( nPara, pLine->GetStart() ) < pPaintRange->GetEnd() ) &&
+ ( TextPaM( nPara, pLine->GetEnd() ) > pPaintRange->GetStart() ) ) ) )
+ {
+ // --------------------------------------------------
+ // Ueber die Portions der Zeile...
+ // --------------------------------------------------
+ nIndex = pLine->GetStart();
+ for ( USHORT y = pLine->GetStartPortion(); y <= pLine->GetEndPortion(); y++ )
+ {
+ DBG_ASSERT( pPortion->GetTextPortions().Count(), "Zeile ohne Textportion im Paint!" );
+ TextPortion* pTextPortion = pPortion->GetTextPortions().GetObject( y );
+ DBG_ASSERT( pTextPortion, "NULL-Pointer im Portioniterator in UpdateViews" );
+
+ long nTxtWidth = pTextPortion->GetWidth();
+
+ // nur ausgeben, was im sichtbaren Bereich beginnt:
+ if ( ( ( aTmpPos.X() + nTxtWidth ) >= 0 )
+ && ( !pPaintRange || (
+ ( TextPaM( nPara, nIndex ) < pPaintRange->GetEnd() ) &&
+ ( TextPaM( nPara, nIndex + pTextPortion->GetLen() ) > pPaintRange->GetStart() ) ) ) )
+ {
+ switch ( pTextPortion->GetKind() )
+ {
+ case PORTIONKIND_TEXT:
+ {
+ {
+ Font aFont;
+ SeekCursor( nPara, nIndex+1, aFont );
+ if ( pSelection )
+ aFont.SetTransparent( FALSE );
+ pOutDev->SetFont( aFont );
+
+ USHORT nTmpIndex = nIndex;
+ USHORT nEnd = nTmpIndex + pTextPortion->GetLen();
+ Point aPos = aTmpPos;
+ if ( pPaintRange )
+ {
+ // evtl soll nicht alles ausgegeben werden...
+ if ( ( pPaintRange->GetStart().GetPara() == nPara )
+ && ( nTmpIndex < pPaintRange->GetStart().GetIndex() ) )
+ {
+ USHORT nL = pPaintRange->GetStart().GetIndex() - nTmpIndex;
+ // aPos.X() += pOutDev->GetTextSize( pPortion->GetNode()->GetText(), nTmpIndex, nL ).Width();
+ aPos.X() += (long)CalcTextWidth( nPara, nTmpIndex, nL, &aFont );
+ nTmpIndex += nL;
+ }
+ if ( ( pPaintRange->GetEnd().GetPara() == nPara )
+ && ( nEnd > pPaintRange->GetEnd().GetIndex() ) )
+ {
+ nEnd = pPaintRange->GetEnd().GetIndex();
+ }
+ }
+
+ BOOL bDone = FALSE;
+ if ( pSelStart )
+ {
+ // liegt ein Teil in der Selektion???
+ TextPaM aTextStart( nPara, nTmpIndex );
+ TextPaM aTextEnd( nPara, nEnd );
+ if ( ( aTextStart < *pSelEnd ) && ( aTextEnd > *pSelStart ) )
+ {
+ USHORT nL;
+
+ // 1) Bereich vor Selektion
+ if ( aTextStart < *pSelStart )
+ {
+ nL = pSelStart->GetIndex() - nTmpIndex;
+ pOutDev->SetFont( aFont );
+ pOutDev->DrawText( aPos, pPortion->GetNode()->GetText(), nTmpIndex, nL );
+ // aPos.X() += pOutDev->GetTextSize( pPortion->GetNode()->GetText(), nTmpIndex, nL ).Width();
+ aPos.X() += (long)CalcTextWidth( nPara, nTmpIndex, nL, &aFont );
+ nTmpIndex += nL;
+
+ }
+ // 2) Bereich mit Selektion
+ nL = nEnd-nTmpIndex;
+ if ( aTextEnd > *pSelEnd )
+ nL = pSelEnd->GetIndex() - nTmpIndex;
+ pOutDev->SetTextColor( rStyleSettings.GetHighlightTextColor() );
+ pOutDev->SetTextFillColor( rStyleSettings.GetHighlightColor() );
+ pOutDev->DrawText( aPos, pPortion->GetNode()->GetText(), nTmpIndex, nL );
+ // aPos.X() += pOutDev->GetTextSize( pPortion->GetNode()->GetText(), nTmpIndex, nL ).Width();
+ aPos.X() += (long)CalcTextWidth( nPara, nTmpIndex, nL, &aFont );
+ nTmpIndex += nL;
+
+ // 3) Bereich nach Selektion
+ if ( nTmpIndex < nEnd )
+ {
+ pOutDev->SetFont( aFont );
+ pOutDev->DrawText( aPos, pPortion->GetNode()->GetText(), nTmpIndex, nEnd-nTmpIndex );
+ }
+ bDone = TRUE;
+ }
+ }
+ if ( !bDone )
+ pOutDev->DrawText( aPos, pPortion->GetNode()->GetText(), nTmpIndex, nEnd-nTmpIndex );
+ }
+
+ }
+ break;
+ case PORTIONKIND_TAB:
+ {
+ // Bei HideSelection() nur Range, pSelection = 0.
+ if ( pSelStart || pPaintRange )
+ {
+ Rectangle aTabArea( aTmpPos, Point( aTmpPos.X()+nTxtWidth, aTmpPos.Y()+mnCharHeight-1 ) );
+ BOOL bDone = FALSE;
+ if ( pSelStart )
+ {
+ // liegt der Tab in der Selektion???
+ TextPaM aTextStart( nPara, nIndex );
+ TextPaM aTextEnd( nPara, nIndex+1 );
+ if ( ( aTextStart < *pSelEnd ) && ( aTextEnd > *pSelStart ) )
+ {
+ Color aOldColor = pOutDev->GetFillColor();
+ pOutDev->SetFillColor( rStyleSettings.GetHighlightColor() );
+ pOutDev->DrawRect( aTabArea );
+ pOutDev->SetFillColor( aOldColor );
+ bDone = TRUE;
+ }
+ }
+ if ( !bDone )
+ {
+ pOutDev->Erase( aTabArea );
+ }
+
+ }
+ }
+ break;
+ default: DBG_ERROR( "ImpPaint: Unknown Portion-Type !" );
+ }
+ }
+ aTmpPos.X() += nTxtWidth;
+ if ( pPaintArea && ( aTmpPos.X() > pPaintArea->Right() ) )
+ break; // Keine weitere Ausgabe in Zeile noetig
+
+ nIndex += pTextPortion->GetLen();
+ }
+ }
+
+ nY += mnCharHeight;
+
+ if ( pPaintArea && ( nY >= pPaintArea->Bottom() ) )
+ break; // keine sichtbaren Aktionen mehr...
+ }
+ }
+ else
+ {
+ nY += nParaHeight;
+ }
+
+ if ( pPaintArea && ( nY > pPaintArea->Bottom() ) )
+ break; // keine sichtbaren Aktionen mehr...
+ }
+}
+
+BOOL TextEngine::CreateLines( ULONG nPara )
+{
+ // BOOL: Aenderung der Hoehe des Absatzes Ja/Nein - TRUE/FALSE
+
+ TextNode* pNode = mpDoc->GetNodes().GetObject( nPara );
+ TEParaPortion* pTEParaPortion = mpTEParaPortions->GetObject( nPara );
+ DBG_ASSERT( pTEParaPortion->IsInvalid(), "CreateLines: Portion nicht invalid!" );
+
+ USHORT nOldLineCount = pTEParaPortion->GetLines().Count();
+
+ // ---------------------------------------------------------------
+ // Schnelle Sonderbehandlung fuer leere Absaetze...
+ // ---------------------------------------------------------------
+ if ( pTEParaPortion->GetNode()->GetText().Len() == 0 )
+ {
+ // schnelle Sonderbehandlung...
+ if ( pTEParaPortion->GetTextPortions().Count() )
+ pTEParaPortion->GetTextPortions().Reset();
+ if ( pTEParaPortion->GetLines().Count() )
+ pTEParaPortion->GetLines().DeleteAndDestroy( 0, pTEParaPortion->GetLines().Count() );
+ CreateAndInsertEmptyLine( nPara );
+ pTEParaPortion->SetValid();
+ return nOldLineCount != pTEParaPortion->GetLines().Count();
+ }
+
+ // ---------------------------------------------------------------
+ // Initialisierung......
+ // ---------------------------------------------------------------
+
+ if ( pTEParaPortion->GetLines().Count() == 0 )
+ {
+ TextLine* pL = new TextLine;
+ pTEParaPortion->GetLines().Insert( pL, 0 );
+ }
+
+ const short nInvalidDiff = pTEParaPortion->GetInvalidDiff();
+ const USHORT nInvalidStart = pTEParaPortion->GetInvalidPosStart();
+ const USHORT nInvalidEnd = nInvalidStart + Abs( nInvalidDiff );
+ BOOL bQuickFormat = FALSE;
+ if ( pTEParaPortion->IsSimpleInvalid() && ( nInvalidDiff > 0 ) )
+ {
+ bQuickFormat = TRUE;
+ }
+ else if ( ( pTEParaPortion->IsSimpleInvalid() ) && ( nInvalidDiff < 0 ) )
+ {
+ // pruefen, ob loeschen ueber Portiongrenzen erfolgte...
+ USHORT nStart = nInvalidStart; // DOPPELT !!!!!!!!!!!!!!!
+ USHORT nEnd = nStart - nInvalidDiff; // neg.
+ bQuickFormat = TRUE;
+ USHORT nPos = 0;
+ USHORT nPortions = pTEParaPortion->GetTextPortions().Count();
+ for ( USHORT nTP = 0; nTP < nPortions; nTP++ )
+ {
+ // Es darf kein Start/Ende im geloeschten Bereich liegen.
+ TextPortion* const pTP = pTEParaPortion->GetTextPortions().GetObject( nTP );
+ nPos += pTP->GetLen();
+ if ( ( nPos > nStart ) && ( nPos < nEnd ) )
+ {
+ bQuickFormat = FALSE;
+ break;
+ }
+ }
+ }
+
+ if ( bQuickFormat )
+ RecalcTextPortion( nPara, nInvalidStart, nInvalidDiff );
+ else
+ CreateTextPortions( nPara, nInvalidStart );
+
+ // ---------------------------------------------------------------
+ // Zeile mit InvalidPos suchen, eine Zeile davor beginnen...
+ // Zeilen flaggen => nicht removen !
+ // ---------------------------------------------------------------
+
+ USHORT nLine = pTEParaPortion->GetLines().Count()-1;
+ for ( USHORT nL = 0; nL <= nLine; nL++ )
+ {
+ TextLine* pLine = pTEParaPortion->GetLines().GetObject( nL );
+ if ( pLine->GetEnd() > nInvalidStart )
+ {
+ nLine = nL;
+ break;
+ }
+ pLine->SetValid();
+ }
+ // Eine Zeile davor beginnen...
+ // Wenn ganz hinten getippt wird, kann sich die Zeile davor nicht aendern.
+ if ( nLine && ( !pTEParaPortion->IsSimpleInvalid() || ( nInvalidEnd < pNode->GetText().Len() ) || ( nInvalidDiff <= 0 ) ) )
+ nLine--;
+
+ TextLine* pLine = pTEParaPortion->GetLines().GetObject( nLine );
+
+ // ---------------------------------------------------------------
+ // Ab hier alle Zeilen durchformatieren...
+ // ---------------------------------------------------------------
+ USHORT nDelFromLine = 0xFFFF;
+ BOOL bLineBreak = FALSE;
+
+ USHORT nIndex = pLine->GetStart();
+ TextLine aSaveLine( *pLine );
+
+ Font aFont;
+
+ BOOL bCalcPortion = TRUE;
+
+ while ( nIndex < pNode->GetText().Len() )
+ {
+ BOOL bEOL = FALSE;
+ BOOL bEOC = FALSE;
+ USHORT nPortionStart = 0;
+ USHORT nPortionEnd = 0;
+
+ USHORT nTmpPos = nIndex;
+ USHORT nTmpPortion = pLine->GetStartPortion();
+ long nTmpWidth = mpDoc->GetLeftMargin();
+// long nXWidth = mnMaxTextWidth ? ( mnMaxTextWidth - mpDoc->GetLeftMargin() ) : 0x7FFFFFFF;
+ // Margin nicht abziehen, ist schon in TmpWidth enthalten.
+ long nXWidth = mnMaxTextWidth ? mnMaxTextWidth : 0x7FFFFFFF;
+ if ( nXWidth < nTmpWidth )
+ nXWidth = nTmpWidth;
+
+ // Portion suchen, die nicht mehr in Zeile passt....
+ TextPortion* pPortion;
+ BOOL bBrokenLine = FALSE;
+ bLineBreak = FALSE;
+
+ while ( ( nTmpWidth <= nXWidth ) && !bEOL && ( nTmpPortion < pTEParaPortion->GetTextPortions().Count() ) )
+ {
+ nPortionStart = nTmpPos;
+ pPortion = pTEParaPortion->GetTextPortions().GetObject( nTmpPortion );
+ DBG_ASSERT( pPortion->GetLen(), "Leere Portion in CreateLines ?!" );
+ if ( pNode->GetText().GetChar( nTmpPos ) == '\t' )
+ {
+ long nCurPos = nTmpWidth-mpDoc->GetLeftMargin();
+ nTmpWidth = ((nCurPos/mnDefTab)+1)*mnDefTab+mpDoc->GetLeftMargin();
+ pPortion->GetWidth() = nTmpWidth - nCurPos - mpDoc->GetLeftMargin();
+ // Wenn dies das erste Token in der Zeile ist, und
+ // nTmpWidth > aPaperSize.Width, habe ich eine Endlos-Schleife!
+ if ( ( nTmpWidth >= nXWidth ) && ( nTmpPortion == pLine->GetStartPortion() ) )
+ {
+ // Aber was jetzt ? Tab passend machen!
+ pPortion->GetWidth() = nXWidth-1;
+ nTmpWidth = pPortion->GetWidth();
+ bEOL = TRUE;
+ bBrokenLine = TRUE;
+ }
+ pPortion->GetKind() = PORTIONKIND_TAB;
+ }
+ else
+ {
+ if ( bCalcPortion || !pPortion->HasValidSize() )
+ pPortion->GetWidth() = (long)CalcTextWidth( nPara, nTmpPos, pPortion->GetLen() );
+ nTmpWidth += pPortion->GetWidth();
+ }
+
+ nTmpPos += pPortion->GetLen();
+ nPortionEnd = nTmpPos;
+ nTmpPortion++;
+ }
+
+ // das war evtl. eine Portion zu weit:
+ BOOL bFixedEnd = FALSE;
+ if ( nTmpWidth > nXWidth )
+ {
+ nPortionEnd = nTmpPos;
+ nTmpPos -= pPortion->GetLen();
+ nPortionStart = nTmpPos;
+ nTmpPortion--;
+ bEOL = FALSE;
+ bEOC = FALSE;
+
+ nTmpWidth -= pPortion->GetWidth();
+ if ( pPortion->GetKind() == PORTIONKIND_TAB )
+ {
+ bEOL = TRUE;
+ bFixedEnd = TRUE;
+ }
+ }
+ else
+ {
+ bEOL = TRUE;
+ bEOC = TRUE;
+ pLine->SetEnd( nPortionEnd );
+ DBG_ASSERT( pTEParaPortion->GetTextPortions().Count(), "Keine TextPortions?" );
+ pLine->SetEndPortion( (USHORT)pTEParaPortion->GetTextPortions().Count() - 1 );
+ }
+
+ if ( bFixedEnd )
+ {
+ pLine->SetEnd( nPortionStart );
+ pLine->SetEndPortion( nTmpPortion-1 );
+ }
+ else if ( bLineBreak || bBrokenLine )
+ {
+ pLine->SetEnd( nPortionStart+1 );
+ pLine->SetEndPortion( nTmpPortion-1 );
+ bEOC = FALSE; // wurde oben gesetzt, vielleich mal die if's umstellen?
+ }
+ else if ( !bEOL )
+ {
+ DBG_ASSERT( (nPortionEnd-nPortionStart) == pPortion->GetLen(), "Doch eine andere Portion?!" );
+ long nRemainingWidth = mnMaxTextWidth - nTmpWidth;
+ ImpBreakLine( nPara, pLine, pPortion, nPortionStart, nRemainingWidth );
+ }
+
+ if ( ( meAlign == TXTALIGN_CENTER ) || ( meAlign == TXTALIGN_RIGHT ) )
+ {
+ // Ausrichten...
+ long nTextWidth = 0;
+ for ( USHORT nTP = pLine->GetStartPortion(); nTP <= pLine->GetEndPortion(); nTP++ )
+ {
+ TextPortion* pTextPortion = pTEParaPortion->GetTextPortions().GetObject( nTP );
+ nTextWidth += pTextPortion->GetWidth();
+ }
+ long nSpace = mnMaxTextWidth - nTextWidth;
+ if ( nSpace > 0 )
+ {
+ if ( meAlign == TXTALIGN_CENTER )
+ pLine->SetStartX( (USHORT)(nSpace / 2) );
+ else // TXTALIGN_RIGHT
+ pLine->SetStartX( (USHORT)nSpace );
+ }
+ }
+ else
+ {
+ pLine->SetStartX( mpDoc->GetLeftMargin() );
+ }
+
+ // -----------------------------------------------------------------
+ // pruefen, ob die Zeile neu ausgegeben werden muss...
+ // -----------------------------------------------------------------
+ pLine->SetInvalid();
+
+ if ( pTEParaPortion->IsSimpleInvalid() )
+ {
+ // Aenderung durch einfache Textaenderung...
+ // Formatierung nicht abbrechen, da Portions evtl. wieder
+ // gesplittet werden muessen!
+ // Wenn irgendwann mal abbrechbar, dann fogende Zeilen Validieren!
+ // Aber ggf. als Valid markieren, damit weniger Ausgabe...
+ if ( pLine->GetEnd() < nInvalidStart )
+ {
+ if ( *pLine == aSaveLine )
+ {
+ pLine->SetValid();
+ }
+ }
+ else
+ {
+ USHORT nStart = pLine->GetStart();
+ USHORT nEnd = pLine->GetEnd();
+
+ if ( nStart > nInvalidEnd )
+ {
+ if ( ( ( nStart-nInvalidDiff ) == aSaveLine.GetStart() ) &&
+ ( ( nEnd-nInvalidDiff ) == aSaveLine.GetEnd() ) )
+ {
+ pLine->SetValid();
+ if ( bCalcPortion && bQuickFormat )
+ {
+ bCalcPortion = FALSE;
+ pTEParaPortion->CorrectValuesBehindLastFormattedLine( nLine );
+ break;
+ }
+ }
+ }
+ else if ( bQuickFormat && ( nEnd > nInvalidEnd) )
+ {
+ // Wenn die ungueltige Zeile so endet, dass die naechste an
+ // der 'gleichen' Textstelle wie vorher beginnt, also nicht
+ // anders umgebrochen wird, brauche ich dort auch nicht die
+ // textbreiten neu bestimmen:
+ if ( nEnd == ( aSaveLine.GetEnd() + nInvalidDiff ) )
+ {
+ bCalcPortion = FALSE;
+ pTEParaPortion->CorrectValuesBehindLastFormattedLine( nLine );
+ break;
+ }
+ }
+ }
+ }
+
+ nIndex = pLine->GetEnd(); // naechste Zeile Start = letzte Zeile Ende
+ // weil nEnd hinter das letzte Zeichen zeigt!
+
+ USHORT nEndPortion = pLine->GetEndPortion();
+
+ // Naechste Zeile oder ggf. neue Zeile....
+ pLine = 0;
+ if ( nLine < pTEParaPortion->GetLines().Count()-1 )
+ pLine = pTEParaPortion->GetLines().GetObject( ++nLine );
+ if ( pLine && ( nIndex >= pNode->GetText().Len() ) )
+ {
+ nDelFromLine = nLine;
+ break;
+ }
+ if ( !pLine && ( nIndex < pNode->GetText().Len() ) )
+ {
+ pLine = new TextLine;
+ pTEParaPortion->GetLines().Insert( pLine, ++nLine );
+ }
+ if ( pLine )
+ {
+ aSaveLine = *pLine;
+ pLine->SetStart( nIndex );
+ pLine->SetEnd( nIndex );
+ pLine->SetStartPortion( nEndPortion+1 );
+ pLine->SetEndPortion( nEndPortion+1 );
+ }
+ } // while ( Index < Len )
+
+ if ( nDelFromLine != 0xFFFF )
+ pTEParaPortion->GetLines().DeleteAndDestroy( nDelFromLine, pTEParaPortion->GetLines().Count() - nDelFromLine );
+
+ DBG_ASSERT( pTEParaPortion->GetLines().Count(), "Keine Zeile nach CreateLines!" );
+
+ if ( bLineBreak == TRUE )
+ CreateAndInsertEmptyLine( nPara );
+
+ pTEParaPortion->SetValid();
+
+ return nOldLineCount != pTEParaPortion->GetLines().Count();
+}
+
+String TextEngine::GetWord( const TextPaM& rCursorPos, TextPaM* pStartOfWord )
+{
+ String aWord;
+ if ( rCursorPos.GetPara() < mpDoc->GetNodes().Count() )
+ {
+ TextSelection aSel( rCursorPos );
+ TextNode* pNode = mpDoc->GetNodes().GetObject( rCursorPos.GetPara() );
+ uno::Reference < text::XBreakIterator > xBI = GetBreakIterator();
+ text::Boundary aBoundary = xBI->getWordBoundary( pNode->GetText(), rCursorPos.GetIndex(), GetLocale(), text::WordType::ANYWORD_IGNOREWHITESPACES, sal_True );
+ aSel.GetStart().GetIndex() = aBoundary.startPos;
+ aSel.GetEnd().GetIndex() = aBoundary.endPos;
+ aWord = pNode->GetText().Copy( aSel.GetStart().GetIndex(), aSel.GetEnd().GetIndex() - aSel.GetStart().GetIndex() );
+ if ( pStartOfWord )
+ *pStartOfWord = aSel.GetStart();
+ }
+ return aWord;
+}
+
+BOOL TextEngine::Read( SvStream& rInput, const TextSelection* pSel )
+{
+ BOOL bUpdate = GetUpdateMode();
+ SetUpdateMode( FALSE );
+
+ UndoActionStart( TEXTUNDO_READ );
+ TextSelection aSel;
+ if ( pSel )
+ aSel = *pSel;
+ else
+ {
+ ULONG nParas = mpDoc->GetNodes().Count();
+ TextNode* pNode = mpDoc->GetNodes().GetObject( nParas - 1 );
+ aSel = TextPaM( nParas-1 , pNode->GetText().Len() );
+ }
+
+ if ( aSel.HasRange() )
+ aSel = ImpDeleteText( aSel );
+
+ ByteString aLine;
+ BOOL bDone = rInput.ReadLine( aLine );
+ String aTmpStr( aLine, rInput.GetStreamCharSet() ), aStr;
+ while ( bDone )
+ {
+ aSel = ImpInsertText( aSel, aTmpStr );
+ bDone = rInput.ReadLine( aLine );
+ aTmpStr = String( aLine, rInput.GetStreamCharSet() );
+ if ( bDone )
+ aSel = ImpInsertParaBreak( aSel.GetEnd() );
+ }
+
+ UndoActionEnd( TEXTUNDO_READ );
+
+ TextSelection aNewSel( aSel.GetEnd(), aSel.GetEnd() );
+
+ // Damit bei FormatAndUpdate nicht auf die ungueltige Selektion zugegriffen wird.
+ if ( GetActiveView() )
+ GetActiveView()->maSelection = aNewSel;
+
+ SetUpdateMode( bUpdate );
+ FormatAndUpdate( GetActiveView() );
+// if ( GetActiveView() )
+// GetActiveView()->SetSelection( aNewSel );
+ return rInput.GetError() ? FALSE : TRUE;
+}
+
+#if SUPD < 540
+BOOL TextEngine::Write( SvStream& rOutput, const TextSelection* pSel )
+{
+ return Write( rOutput, pSel, FALSE );
+}
+#endif
+
+BOOL TextEngine::Write( SvStream& rOutput, const TextSelection* pSel, BOOL bHTML )
+{
+ TextSelection aSel;
+ if ( pSel )
+ aSel = *pSel;
+ else
+ {
+ ULONG nParas = mpDoc->GetNodes().Count();
+ TextNode* pNode = mpDoc->GetNodes().GetObject( nParas - 1 );
+ aSel.GetStart() = TextPaM( 0, 0 );
+ aSel.GetEnd() = TextPaM( nParas-1, pNode->GetText().Len() );
+ }
+
+ if ( bHTML )
+ {
+ rOutput.WriteLine( "<HTML>" );
+ rOutput.WriteLine( "<BODY>" );
+ }
+
+ for ( ULONG nPara = aSel.GetStart().GetPara(); nPara <= aSel.GetEnd().GetPara(); nPara++ )
+ {
+ TextNode* pNode = mpDoc->GetNodes().GetObject( nPara );
+
+ USHORT nStartPos = 0;
+ USHORT nEndPos = pNode->GetText().Len();
+ if ( nPara == aSel.GetStart().GetPara() )
+ nStartPos = aSel.GetStart().GetIndex();
+ if ( nPara == aSel.GetEnd().GetPara() )
+ nEndPos = aSel.GetEnd().GetIndex();
+
+ String aText;
+ if ( !bHTML )
+ {
+ aText = pNode->GetText().Copy( nStartPos, nEndPos-nStartPos );
+ }
+ else
+ {
+ aText.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "<P STYLE=\"margin-bottom: 0cm\">" ) );
+
+ if ( nStartPos == nEndPos )
+ {
+ // Leerzeilen werden von Writer wegoptimiert
+ aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "<BR>" ) );
+ }
+ else
+ {
+ USHORT nTmpStart = nStartPos;
+ USHORT nTmpEnd = nEndPos;
+ do
+ {
+ TextCharAttrib* pAttr = pNode->GetCharAttribs().FindNextAttrib( TEXTATTR_HYPERLINK, nTmpStart, nEndPos );
+ nTmpEnd = pAttr ? pAttr->GetStart() : nEndPos;
+
+ // Text vor dem Attribut
+ aText += pNode->GetText().Copy( nTmpStart, nTmpEnd-nTmpStart );
+
+ if ( pAttr )
+ {
+ nTmpEnd = Min( pAttr->GetEnd(), nEndPos );
+
+ // z.B. <A HREF="http://www.mopo.de/">Morgenpost</A>
+ aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "<A HREF=\"" ) );
+ aText += ((const TextAttribHyperLink&) pAttr->GetAttr() ).GetURL();
+ aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "\">" ) );
+ nTmpStart = pAttr->GetStart();
+ aText += pNode->GetText().Copy( nTmpStart, nTmpEnd-nTmpStart );
+ aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "</A>" ) );
+
+ nTmpStart = pAttr->GetEnd();
+ }
+ } while ( nTmpEnd < nEndPos );
+ }
+
+ aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "</P>" ) );
+ }
+ rOutput.WriteLine( ByteString( aText, rOutput.GetStreamCharSet() ) );
+ }
+
+ if ( bHTML )
+ {
+ rOutput.WriteLine( "</BODY>" );
+ rOutput.WriteLine( "</HTML>" );
+ }
+
+ return rOutput.GetError() ? FALSE : TRUE;
+}
+
+void TextEngine::RemoveAttribs( ULONG nPara )
+{
+ if ( nPara < mpDoc->GetNodes().Count() )
+ {
+ TextNode* pNode = mpDoc->GetNodes().GetObject( nPara );
+ if ( pNode->GetCharAttribs().Count() )
+ {
+ pNode->GetCharAttribs().Clear( TRUE );
+
+ TEParaPortion* pTEParaPortion = mpTEParaPortions->GetObject( nPara );
+ pTEParaPortion->MarkSelectionInvalid( 0, pNode->GetText().Len() );
+
+ mbFormatted = FALSE;
+ FormatAndUpdate( NULL );
+ }
+ }
+}
+
+void TextEngine::SetAttrib( const TextAttrib& rAttr, ULONG nPara, USHORT nStart, USHORT nEnd )
+{
+ // Es wird hier erstmal nicht geprueft, ob sich Attribute ueberlappen!
+ // Diese Methode ist erstmal nur fuer einen Editor, der fuer eine Zeile
+ // _schnell_ das Syntax-Highlight einstellen will.
+
+ // Da die TextEngine z.Zt fuer Editoren gedacht ist gibt es auch kein
+ // Undo fuer Attribute!
+
+ if ( nPara < mpDoc->GetNodes().Count() )
+ {
+ TextNode* pNode = mpDoc->GetNodes().GetObject( nPara );
+ TEParaPortion* pTEParaPortion = mpTEParaPortions->GetObject( nPara );
+
+ USHORT nMax = pNode->GetText().Len();
+ if ( nStart > nMax )
+ nStart = nMax;
+ if ( nEnd > nMax )
+ nEnd = nMax;
+
+ pNode->GetCharAttribs().InsertAttrib( new TextCharAttrib( rAttr, nStart, nEnd ) );
+ pTEParaPortion->MarkSelectionInvalid( nStart, nEnd );
+
+ mbFormatted = FALSE;
+ FormatAndUpdate( NULL );
+ }
+}
+
+void TextEngine::SetTextAlign( TxtAlign eAlign )
+{
+ if ( eAlign != meAlign )
+ {
+ meAlign = eAlign;
+ FormatFullDoc();
+ }
+}
+
+
+void TextEngine::ValidateSelection( TextSelection& rSel ) const
+{
+ ValidatePaM( rSel.GetStart() );
+ ValidatePaM( rSel.GetEnd() );
+}
+
+void TextEngine::ValidatePaM( TextPaM& rPaM ) const
+{
+ ULONG nMaxPara = mpDoc->GetNodes().Count() - 1;
+ if ( rPaM.GetPara() > nMaxPara )
+ {
+ rPaM.GetPara() = nMaxPara;
+ rPaM.GetIndex() = 0xFFFF;
+ }
+
+ USHORT nMaxIndex = GetTextLen( rPaM.GetPara() );
+ if ( rPaM.GetIndex() > nMaxIndex )
+ rPaM.GetIndex() = nMaxIndex;
+}
+
+
+// Status & Selektionsanpassung
+
+void TextEngine::ImpParagraphInserted( ULONG nPara )
+{
+ // Die aktive View braucht nicht angepasst werden, aber bei allen
+ // passiven muss die Selektion angepasst werden:
+ if ( mpViews->Count() > 1 )
+ {
+ for ( USHORT nView = mpViews->Count(); nView; )
+ {
+ TextView* pView = mpViews->GetObject( --nView );
+ if ( pView != GetActiveView() )
+ {
+// BOOL bInvers = pView->maSelection.GetEnd() < pView->maSelection.GetStart();
+// TextPaM& rMin = !bInvers ? pView->maSelection.GetStart(): pView->maSelection.GetEnd();
+// TextPaM& rMax = bInvers ? pView->maSelection.GetStart() : pView->maSelection.GetEnd();
+//
+// if ( rMin.GetPara() >= nPara )
+// rMin.GetPara()++;
+// if ( rMax.GetPara() >= nPara )
+// rMax.GetPara()++;
+ for ( int n = 0; n <= 1; n++ )
+ {
+ TextPaM& rPaM = n ? pView->maSelection.GetStart(): pView->maSelection.GetEnd();
+ if ( rPaM.GetPara() >= nPara )
+ rPaM.GetPara()++;
+ }
+ }
+ }
+ }
+ Broadcast( TextHint( TEXT_HINT_PARAINSERTED, nPara ) );
+}
+
+void TextEngine::ImpParagraphRemoved( ULONG nPara )
+{
+ if ( mpViews->Count() > 1 )
+ {
+ for ( USHORT nView = mpViews->Count(); nView; )
+ {
+ TextView* pView = mpViews->GetObject( --nView );
+ if ( pView != GetActiveView() )
+ {
+ ULONG nParas = mpDoc->GetNodes().Count();
+ for ( int n = 0; n <= 1; n++ )
+ {
+ TextPaM& rPaM = n ? pView->maSelection.GetStart(): pView->maSelection.GetEnd();
+ if ( rPaM.GetPara() > nPara )
+ rPaM.GetPara()--;
+ else if ( rPaM.GetPara() == nPara )
+ {
+ rPaM.GetIndex() = 0;
+ if ( rPaM.GetPara() >= nParas )
+ rPaM.GetPara()--;
+ }
+ }
+ }
+ }
+ }
+ Broadcast( TextHint( TEXT_HINT_PARAREMOVED, nPara ) );
+}
+
+void TextEngine::ImpCharsRemoved( ULONG nPara, USHORT nPos, USHORT nChars )
+{
+ if ( mpViews->Count() > 1 )
+ {
+ for ( USHORT nView = mpViews->Count(); nView; )
+ {
+ TextView* pView = mpViews->GetObject( --nView );
+ if ( pView != GetActiveView() )
+ {
+ USHORT nEnd = nPos+nChars;
+ for ( int n = 0; n <= 1; n++ )
+ {
+ TextPaM& rPaM = n ? pView->maSelection.GetStart(): pView->maSelection.GetEnd();
+ if ( rPaM.GetPara() == nPara )
+ {
+ if ( rPaM.GetIndex() > nEnd )
+ rPaM.GetIndex() -= nChars;
+ else if ( rPaM.GetIndex() > nPos )
+ rPaM.GetIndex() = nPos;
+ }
+ }
+ }
+ }
+ }
+}
+
+void TextEngine::ImpCharsInserted( ULONG nPara, USHORT nPos, USHORT nChars )
+{
+ if ( mpViews->Count() > 1 )
+ {
+ for ( USHORT nView = mpViews->Count(); nView; )
+ {
+ TextView* pView = mpViews->GetObject( --nView );
+ if ( pView != GetActiveView() )
+ {
+ for ( int n = 0; n <= 1; n++ )
+ {
+ TextPaM& rPaM = n ? pView->maSelection.GetStart(): pView->maSelection.GetEnd();
+ if ( rPaM.GetPara() == nPara )
+ {
+ if ( rPaM.GetIndex() >= nPos )
+ rPaM.GetIndex() += nChars;
+ }
+ }
+ }
+ }
+ }
+}
+
+void TextEngine::ImpFormattingParagraph( ULONG nPara )
+{
+ Broadcast( TextHint( TEXT_HINT_FORMATPARA, nPara ) );
+}
+
+void TextEngine::ImpTextHeightChanged()
+{
+ Broadcast( TextHint( TEXT_HINT_TEXTHEIGHTCHANGED ) );
+}
+
+void TextEngine::ImpTextFormatted()
+{
+ Broadcast( TextHint( TEXT_HINT_TEXTFORMATTED ) );
+}
+
+void TextEngine::Draw( OutputDevice* pDev, const Point& rPos )
+{
+ ImpPaint( pDev, rPos, NULL );
+}
+
+void TextEngine::SetLeftMargin( USHORT n )
+{
+ mpDoc->SetLeftMargin( n );
+}
+
+USHORT TextEngine::GetLeftMargin() const
+{
+ return mpDoc->GetLeftMargin();
+}
+
+uno::Reference< text::XBreakIterator > TextEngine::GetBreakIterator()
+{
+ static uno::Reference < text::XBreakIterator > mxBreakIterator;
+ if ( !mxBreakIterator.is() )
+ mxBreakIterator = vcl::unohelper::CreateBreakIterator();
+ return mxBreakIterator;
+}
+
+::com::sun::star::lang::Locale TextEngine::GetLocale()
+{
+#if SUPD <= 594
+ static ::com::sun::star::lang::Locale maLocale;
+#endif
+ if ( !maLocale.Language.getLength() )
+ {
+ String aLanguage, aCountry;
+ ConvertLanguageToIsoNames( LANGUAGE_ENGLISH, aLanguage, aCountry );
+ maLocale.Language = aLanguage;
+ maLocale.Country = aCountry;
+ }
+ return maLocale;
+}
diff --git a/svtools/source/edit/textund2.hxx b/svtools/source/edit/textund2.hxx
new file mode 100644
index 000000000000..05d400896fed
--- /dev/null
+++ b/svtools/source/edit/textund2.hxx
@@ -0,0 +1,182 @@
+/*************************************************************************
+ *
+ * $RCSfile: textund2.hxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: hr $ $Date: 2000-09-18 16:58:58 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (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.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+#ifndef _TEXTUND2_HXX
+#define _TEXTUND2_HXX
+
+#include <textundo.hxx>
+
+
+class TextUndoDelPara : public TextUndo
+{
+private:
+ BOOL mbDelObject;
+ ULONG mnPara;
+ TextNode* mpNode; // Zeigt auf das gueltige, nicht zerstoerte Objekt!
+
+public:
+ TYPEINFO();
+ TextUndoDelPara( TextEngine* pTextEngine, TextNode* pNode, ULONG nPara );
+ ~TextUndoDelPara();
+
+ virtual void Undo();
+ virtual void Redo();
+};
+
+
+class TextUndoConnectParas : public TextUndo
+{
+private:
+ ULONG mnPara;
+ USHORT mnSepPos;
+
+public:
+ TYPEINFO();
+ TextUndoConnectParas( TextEngine* pTextEngine, ULONG nPara, USHORT nSepPos );
+ ~TextUndoConnectParas();
+
+ virtual void Undo();
+ virtual void Redo();
+};
+
+
+class TextUndoSplitPara : public TextUndo
+{
+private:
+ ULONG mnPara;
+ USHORT mnSepPos;
+
+public:
+ TYPEINFO();
+ TextUndoSplitPara( TextEngine* pTextEngine, ULONG nPara, USHORT nSepPos );
+ ~TextUndoSplitPara();
+
+ virtual void Undo();
+ virtual void Redo();
+};
+
+
+class TextUndoInsertChars : public TextUndo
+{
+private:
+ TextPaM maTextPaM;
+ String maText;
+
+public:
+ TYPEINFO();
+ TextUndoInsertChars( TextEngine* pTextEngine, const TextPaM& rTextPaM, const String& rStr );
+
+// const TextPaM& GetTextPaM() { return aTextPaM; }
+// String& GetStr() { return aText; }
+
+ virtual void Undo();
+ virtual void Redo();
+
+ virtual BOOL Merge( SfxUndoAction *pNextAction );
+};
+
+
+class TextUndoRemoveChars : public TextUndo
+{
+private:
+ TextPaM maTextPaM;
+ String maText;
+
+public:
+ TYPEINFO();
+ TextUndoRemoveChars( TextEngine* pTextEngine, const TextPaM& rTextPaM, const String& rStr );
+
+// const TextPaM& GetTextPaM() { return aTextPaM; }
+// String& GetStr() { return aText; }
+
+ virtual void Undo();
+ virtual void Redo();
+};
+
+
+class TextUndoSetAttribs: public TextUndo
+{
+private:
+ TextSelection maSelection;
+// SfxItemSet aNewAttribs;
+// TextInfoArray aPrevAttribs;
+// BYTE nSpecial;
+// BOOL bSetIsRemove;
+// USHORT nRemoveWhich;
+//
+// void ImpSetSelection( TextView* pView );
+
+
+public:
+ TYPEINFO();
+ TextUndoSetAttribs( TextEngine* pTextEngine, const TextSelection& rESel );
+ ~TextUndoSetAttribs();
+
+// TextInfoArray& GetTextInfos() { return aPrevAttribs; }
+// SfxItemSet& GetNewAttribs() { return aNewAttribs; }
+// void SetSpecial( BYTE n ) { nSpecial = n; }
+// void SetRemoveAttribs( BOOL b ) { bSetIsRemove = b; }
+// void SetRemoveWhich( USHORT n ) { nRemoveWhich = n; }
+
+ virtual void Undo();
+ virtual void Redo();
+};
+
+#endif // _TEXTUND2_HXX
diff --git a/svtools/source/edit/textundo.cxx b/svtools/source/edit/textundo.cxx
new file mode 100644
index 000000000000..2be7d39b0524
--- /dev/null
+++ b/svtools/source/edit/textundo.cxx
@@ -0,0 +1,374 @@
+/*************************************************************************
+ *
+ * $RCSfile: textundo.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: hr $ $Date: 2000-09-18 16:58:58 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (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.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#include <texteng.hxx>
+#include <textview.hxx>
+#include <textundo.hxx>
+#include <textund2.hxx>
+#include <textdata.hxx>
+#include <textdoc.hxx>
+#include <textdat2.hxx>
+
+TYPEINIT1( TextUndo, SfxUndoAction );
+TYPEINIT1( TextUndoDelPara, TextUndo );
+TYPEINIT1( TextUndoConnectParas, TextUndo );
+TYPEINIT1( TextUndoSplitPara, TextUndo );
+TYPEINIT1( TextUndoInsertChars, TextUndo );
+TYPEINIT1( TextUndoRemoveChars, TextUndo );
+TYPEINIT1( TextUndoSetAttribs, TextUndo );
+
+
+TextUndoManager::TextUndoManager( TextEngine* p )
+{
+ mpTextEngine = p;
+}
+
+TextUndoManager::~TextUndoManager()
+{
+}
+
+BOOL __EXPORT TextUndoManager::Undo( USHORT nCount )
+{
+ if ( GetUndoActionCount() == 0 )
+ return FALSE;
+
+ UndoRedoStart();
+
+ mpTextEngine->SetIsInUndo( TRUE );
+ BOOL bDone = SfxUndoManager::Undo( nCount );
+ mpTextEngine->SetIsInUndo( FALSE );
+
+ UndoRedoEnd();
+
+ return bDone;
+}
+
+BOOL __EXPORT TextUndoManager::Redo( USHORT nCount )
+{
+ if ( GetRedoActionCount() == 0 )
+ return FALSE;
+
+
+ UndoRedoStart();
+
+ mpTextEngine->SetIsInUndo( TRUE );
+ BOOL bDone = SfxUndoManager::Redo( nCount );
+ mpTextEngine->SetIsInUndo( FALSE );
+
+ UndoRedoEnd();
+
+ return bDone;
+}
+
+void TextUndoManager::UndoRedoStart()
+{
+ DBG_ASSERT( GetView(), "Undo/Redo: Active View?" );
+
+// if ( GetView() )
+// GetView()->HideSelection();
+}
+
+void TextUndoManager::UndoRedoEnd()
+{
+ if ( GetView() )
+ {
+ TextSelection aNewSel( GetView()->GetSelection() );
+ aNewSel.GetStart() = aNewSel.GetEnd();
+ GetView()->maSelection = aNewSel;
+ }
+
+ mpTextEngine->UpdateSelections();
+
+ mpTextEngine->FormatAndUpdate( GetView() );
+}
+
+
+TextUndo::TextUndo( USHORT nI, TextEngine* p )
+{
+ mnId = nI;
+ mpTextEngine = p;
+}
+
+TextUndo::~TextUndo()
+{
+}
+
+USHORT __EXPORT TextUndo::GetId() const
+{
+ //nId sollte mal entfallen => GetId ueberall ueberladen...
+ return mnId;
+}
+
+XubString __EXPORT TextUndo::GetComment() const
+{
+// return mpTextEngine->GetUndoComment( this );
+ return String();
+}
+
+void TextUndo::SetSelection( const TextSelection& rSel )
+{
+ if ( GetView() )
+ GetView()->maSelection = rSel;
+}
+
+
+TextUndoDelPara::TextUndoDelPara( TextEngine* pTextEngine, TextNode* pNode, ULONG nPara )
+ : TextUndo( TEXTUNDO_DELCONTENT, pTextEngine )
+{
+ mpNode = pNode;
+ mnPara = nPara;
+ mbDelObject = TRUE;
+}
+
+TextUndoDelPara::~TextUndoDelPara()
+{
+ if ( mbDelObject )
+ delete mpNode;
+}
+
+void __EXPORT TextUndoDelPara::Undo()
+{
+ GetTextEngine()->InsertContent( mpNode, mnPara );
+ mbDelObject = FALSE; // gehoert wieder der Engine
+
+ if ( GetView() )
+ {
+ TextSelection aSel( TextPaM( mnPara, 0 ), TextPaM( mnPara, mpNode->GetText().Len() ) );
+ SetSelection( aSel );
+ }
+}
+
+void __EXPORT TextUndoDelPara::Redo()
+{
+ // pNode stimmt nicht mehr, falls zwischendurch Undos, in denen
+ // Absaetze verschmolzen sind.
+ mpNode = GetDoc()->GetNodes().GetObject( mnPara );
+
+ delete GetTEParaPortions()->GetObject( mnPara );
+ GetTEParaPortions()->Remove( mnPara );
+
+ // Node nicht loeschen, haengt im Undo!
+ GetDoc()->GetNodes().Remove( mnPara );
+ GetTextEngine()->ImpParagraphRemoved( mnPara );
+
+ mbDelObject = TRUE; // gehoert wieder dem Undo
+
+ ULONG nParas = GetDoc()->GetNodes().Count();
+ ULONG n = mnPara < nParas ? mnPara : (nParas-1);
+ TextNode* pN = GetDoc()->GetNodes().GetObject( n );
+ TextPaM aPaM( n, pN->GetText().Len() );
+ SetSelection( aPaM );
+}
+
+ // -----------------------------------------------------------------------
+// TextUndoConnectParas
+// ------------------------------------------------------------------------
+TextUndoConnectParas::TextUndoConnectParas( TextEngine* pTextEngine, ULONG nPara, USHORT nPos )
+ : TextUndo( TEXTUNDO_CONNECTPARAS, pTextEngine )
+{
+ mnPara = nPara;
+ mnSepPos = nPos;
+}
+
+TextUndoConnectParas::~TextUndoConnectParas()
+{
+}
+
+void __EXPORT TextUndoConnectParas::Undo()
+{
+ TextPaM aPaM = GetTextEngine()->SplitContent( mnPara, mnSepPos );
+ SetSelection( aPaM );
+}
+
+void __EXPORT TextUndoConnectParas::Redo()
+{
+ TextPaM aPaM = GetTextEngine()->ConnectContents( mnPara );
+ SetSelection( aPaM );
+}
+
+
+TextUndoSplitPara::TextUndoSplitPara( TextEngine* pTextEngine, ULONG nPara, USHORT nPos )
+ : TextUndo( TEXTUNDO_SPLITPARA, pTextEngine )
+{
+ mnPara = nPara;
+ mnSepPos = nPos;
+}
+
+TextUndoSplitPara::~TextUndoSplitPara()
+{
+}
+
+void __EXPORT TextUndoSplitPara::Undo()
+{
+ TextPaM aPaM = GetTextEngine()->ConnectContents( mnPara );
+ SetSelection( aPaM );
+}
+
+void __EXPORT TextUndoSplitPara::Redo()
+{
+ TextPaM aPaM = GetTextEngine()->SplitContent( mnPara, mnSepPos );
+ SetSelection( aPaM );
+}
+
+
+TextUndoInsertChars::TextUndoInsertChars( TextEngine* pTextEngine, const TextPaM& rTextPaM, const XubString& rStr )
+ : TextUndo( TEXTUNDO_INSERTCHARS, pTextEngine ),
+ maTextPaM( rTextPaM ), maText( rStr )
+{
+}
+
+void __EXPORT TextUndoInsertChars::Undo()
+{
+ TextSelection aSel( maTextPaM, maTextPaM );
+ aSel.GetEnd().GetIndex() += maText.Len();
+ TextPaM aPaM = GetTextEngine()->ImpDeleteText( aSel );
+ SetSelection( aPaM );
+}
+
+void __EXPORT TextUndoInsertChars::Redo()
+{
+ TextSelection aSel( maTextPaM, maTextPaM );
+ GetTextEngine()->ImpInsertText( aSel, maText );
+ TextPaM aNewPaM( maTextPaM );
+ aNewPaM.GetIndex() += maText.Len();
+ SetSelection( TextSelection( aSel.GetStart(), aNewPaM ) );
+}
+
+BOOL __EXPORT TextUndoInsertChars::Merge( SfxUndoAction* pNextAction )
+{
+ if ( !pNextAction->ISA( TextUndoInsertChars ) )
+ return FALSE;
+
+ TextUndoInsertChars* pNext = (TextUndoInsertChars*)pNextAction;
+
+ if ( maTextPaM.GetPara() != pNext->maTextPaM.GetPara() )
+ return FALSE;
+
+ if ( ( maTextPaM.GetIndex() + maText.Len() ) == pNext->maTextPaM.GetIndex() )
+ {
+ maText += pNext->maText;
+ return TRUE;
+ }
+ return FALSE;
+}
+
+
+TextUndoRemoveChars::TextUndoRemoveChars( TextEngine* pTextEngine, const TextPaM& rTextPaM, const XubString& rStr )
+ : TextUndo( TEXTUNDO_REMOVECHARS, pTextEngine ),
+ maTextPaM( rTextPaM ), maText( rStr )
+{
+}
+
+void __EXPORT TextUndoRemoveChars::Undo()
+{
+ TextSelection aSel( maTextPaM, maTextPaM );
+ GetTextEngine()->ImpInsertText( aSel, maText );
+ aSel.GetEnd().GetIndex() += maText.Len();
+ SetSelection( aSel );
+}
+
+void __EXPORT TextUndoRemoveChars::Redo()
+{
+ TextSelection aSel( maTextPaM, maTextPaM );
+ aSel.GetEnd().GetIndex() += maText.Len();
+ TextPaM aPaM = GetTextEngine()->ImpDeleteText( aSel );
+ SetSelection( aPaM );
+}
+
+
+TextUndoSetAttribs::TextUndoSetAttribs( TextEngine* pTextEngine, const TextSelection& rSel )
+ : TextUndo( TEXTUNDO_ATTRIBS, pTextEngine ), maSelection( rSel )
+{
+ maSelection.Justify();
+// aNewAttribs.Set( rNewItems );
+// mbSetIsRemove = FALSE;
+// mnRemoveWhich = 0;
+// mnSpecial = 0;
+}
+
+TextUndoSetAttribs::~TextUndoSetAttribs()
+{
+ // ...............
+}
+
+void __EXPORT TextUndoSetAttribs::Undo()
+{
+ for ( ULONG nPara = maSelection.GetStart().GetPara(); nPara <= maSelection.GetEnd().GetPara(); nPara++ )
+ {
+// ContentAttribsInfo* pInf = aPrevAttribs[ (USHORT)(nPara-aESel.nStartPara) ];
+// GetTextEngine()->RemoveCharAttribs( nPara );
+// TextNode* pNode = GetTextEngine()->GetTextDoc().GetObject( nPara );
+// for ( USHORT nAttr = 0; nAttr < pInf->GetPrevCharAttribs().Count(); nAttr++ )
+// {
+// GetTextEngine()->GetTextDoc().InsertAttrib( pNode, pX->GetStart(), pX->GetEnd(), *pX->GetItem() );
+// }
+ }
+ SetSelection( maSelection );
+}
+
+void __EXPORT TextUndoSetAttribs::Redo()
+{
+// if ( !bSetIsRemove )
+// GetTextEngine()->SetAttribs( aSel, aNewAttribs, nSpecial );
+// else
+// GetTextEngine()->RemoveCharAttribs( aSel, bRemoveParaAttribs, nRemoveWhich );
+ SetSelection( maSelection );
+}
diff --git a/svtools/source/edit/textundo.hxx b/svtools/source/edit/textundo.hxx
new file mode 100644
index 000000000000..31bb776178d5
--- /dev/null
+++ b/svtools/source/edit/textundo.hxx
@@ -0,0 +1,118 @@
+/*************************************************************************
+ *
+ * $RCSfile: textundo.hxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: hr $ $Date: 2000-09-18 16:58:58 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (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.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+#ifndef _TEXTUNDO_HXX
+#define _TEXTUNDO_HXX
+
+#ifndef _UNDO_HXX
+#include <undo.hxx>
+#endif
+
+class TextEngine;
+
+class TextUndoManager : public SfxUndoManager
+{
+ TextEngine* mpTextEngine;
+
+protected:
+
+ void UndoRedoStart();
+ void UndoRedoEnd();
+
+ TextView* GetView() const { return mpTextEngine->GetActiveView(); }
+
+public:
+ TextUndoManager( TextEngine* pTextEngine );
+ ~TextUndoManager();
+
+ virtual BOOL Undo( USHORT nCount=1 );
+ virtual BOOL Redo( USHORT nCount=1 );
+
+};
+
+class TextUndo : public SfxUndoAction
+{
+private:
+ USHORT mnId;
+ TextEngine* mpTextEngine;
+
+protected:
+
+ TextView* GetView() const { return mpTextEngine->GetActiveView(); }
+ void SetSelection( const TextSelection& rSel );
+
+ TextDoc* GetDoc() const { return mpTextEngine->mpDoc; }
+ TEParaPortions* GetTEParaPortions() const { return mpTextEngine->mpTEParaPortions; }
+
+public:
+ TYPEINFO();
+ TextUndo( USHORT nId, TextEngine* pTextEngine );
+ virtual ~TextUndo();
+
+ TextEngine* GetTextEngine() const { return mpTextEngine; }
+
+ virtual void Undo() = 0;
+ virtual void Redo() = 0;
+
+ virtual XubString GetComment() const;
+ virtual USHORT GetId() const;
+};
+
+#endif // _TEXTUNDO_HXX
diff --git a/svtools/source/edit/textview.cxx b/svtools/source/edit/textview.cxx
new file mode 100644
index 000000000000..df85abfbf485
--- /dev/null
+++ b/svtools/source/edit/textview.cxx
@@ -0,0 +1,1760 @@
+/*************************************************************************
+ *
+ * $RCSfile: textview.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: hr $ $Date: 2000-09-18 16:58:58 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (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.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#pragma hdrstop
+
+#include <textview.hxx>
+#include <texteng.hxx>
+#include <textdoc.hxx>
+#include <textdata.hxx>
+#include <textdat2.hxx>
+
+#include <undo.hxx>
+
+#ifndef _SV_CURSOR_HXX //autogen
+#include <vcl/cursor.hxx>
+#endif
+
+#ifndef _SV_WINDOW_HXX //autogen
+#include <vcl/window.hxx>
+#endif
+
+#ifndef _SV_SVAPP_HXX //autogen
+#include <vcl/svapp.hxx>
+#endif
+
+#ifndef _SV_CLIP_HXX //autogen
+#include <vcl/clip.hxx>
+#endif
+
+#ifndef _SV_DRAG_HXX //autogen
+#include <vcl/drag.hxx>
+#endif
+
+#ifndef _SV_SOUND_HXX //autogen
+#include <vcl/sound.hxx>
+#endif
+
+#ifndef _STREAM_HXX //autogen
+#include <tools/stream.hxx>
+#endif
+
+#ifndef _NEW_HXX
+#include <tools/new.hxx>
+#endif
+
+#include <sot/formats.hxx>
+
+#ifndef _URLBMK_HXX
+#include <urlbmk.hxx>
+#endif
+
+#ifndef _COM_SUN_STAR_TEXT_XBREAKITERATOR_HPP_
+#include <com/sun/star/text/XBreakIterator.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_TEXT_CHARACTERITERATORMODE_HPP_
+#include <com/sun/star/text/CharacterIteratorMode.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_TEXT_WORDTYPE_HPP_
+#include <com/sun/star/text/WordType.hpp>
+#endif
+
+using namespace ::com::sun::star;
+
+
+ // -------------------------------------------------------------------------
+// (+) class TextView
+// -------------------------------------------------------------------------
+TextView::TextView( TextEngine* pEng, Window* pWindow )
+{
+ mpWindow = pWindow;
+ mpTextEngine = pEng;
+ mpVirtDev = NULL;
+
+ mbPaintSelection = TRUE;
+ mbAutoScroll = TRUE;
+ mbInsertMode = TRUE;
+ mbReadOnly = FALSE;
+ mbHighlightSelection = FALSE;
+ mbAutoIndent = FALSE;
+ mbCursorEnabled = TRUE;
+// mbInSelection = FALSE;
+
+ mnTravelXPos = TRAVEL_X_DONTKNOW;
+
+ mpSelFuncSet = new TextSelFunctionSet( this );
+ mpSelEngine = new SelectionEngine( mpWindow, mpSelFuncSet );
+ mpSelEngine->SetSelectionMode( RANGE_SELECTION );
+ mpSelEngine->EnableDrag( TRUE );
+
+ mpCursor = new Cursor;
+ mpCursor->Show();
+ pWindow->SetCursor( mpCursor );
+
+ if ( pWindow->GetSettings().GetStyleSettings().GetSelectionOptions() & SELECTION_OPTION_INVERT )
+ mbHighlightSelection = TRUE;
+
+ pWindow->SetLineColor();
+
+ mpDDInfo = 0;
+}
+
+TextView::~TextView()
+{
+ delete mpSelEngine;
+ delete mpSelFuncSet;
+ delete mpVirtDev;
+
+ if ( mpWindow->GetCursor() == mpCursor )
+ mpWindow->SetCursor( 0 );
+ delete mpCursor;
+ delete mpDDInfo;
+}
+
+void TextView::Invalidate()
+{
+ mpWindow->Invalidate();
+}
+
+void TextView::SetSelection( const TextSelection& rTextSel, BOOL bGotoCursor )
+{
+ // Falls jemand gerade ein leeres Attribut hinterlassen hat,
+ // und dann der Outliner die Selektion manipulitert:
+ if ( !maSelection.HasRange() )
+ mpTextEngine->CursorMoved( maSelection.GetStart().GetPara() );
+
+ // Wenn nach einem KeyInput die Selection manipuliert wird:
+ mpTextEngine->CheckIdleFormatter();
+
+ HideSelection();
+ maSelection = rTextSel;
+ mpTextEngine->ValidateSelection( maSelection );
+ ShowSelection();
+ ShowCursor( bGotoCursor );
+}
+
+void TextView::SetSelection( const TextSelection& rTextSel )
+{
+ SetSelection( rTextSel, mbAutoScroll );
+}
+
+const TextSelection& TextView::GetSelection() const
+{
+ return maSelection;
+}
+
+void TextView::DeleteSelected()
+{
+// HideSelection();
+
+ mpTextEngine->UndoActionStart( TEXTUNDO_DELETE );
+ TextPaM aPaM = mpTextEngine->ImpDeleteText( maSelection );
+ mpTextEngine->UndoActionEnd( TEXTUNDO_DELETE );
+
+ maSelection = aPaM;
+ mpTextEngine->FormatAndUpdate( this );
+ ShowCursor();
+}
+
+void TextView::ImpPaint( OutputDevice* pOut, const Point& rStartPos, Rectangle const* pPaintArea, TextSelection const* pPaintRange, TextSelection const* pSelection )
+{
+ if ( !mbPaintSelection )
+ pSelection = NULL;
+ else
+ {
+ // Richtige Hintergrundfarbe einstellen.
+ // Ich bekomme leider nicht mit, ob sich diese inzwischen geaendert hat.
+ Font aFont = mpTextEngine->GetFont();
+ Color aColor = pOut->GetBackground().GetColor();
+ aColor.SetTransparency( 0 );
+ if ( aColor != aFont.GetFillColor() )
+ {
+ aFont.SetTransparent( FALSE );
+ aFont.SetFillColor( aColor );
+ mpTextEngine->maFont = aFont;
+ }
+ }
+
+ mpTextEngine->ImpPaint( pOut, rStartPos, pPaintArea, pPaintRange, pSelection );
+}
+
+void TextView::Paint( const Rectangle& rRect )
+{
+ ImpPaint( rRect, FALSE );
+}
+
+void TextView::ImpPaint( const Rectangle& rRect, BOOL bUseVirtDev )
+{
+ if ( !mpTextEngine->GetUpdateMode() || mpTextEngine->IsInUndo() )
+ return;
+
+ if ( bUseVirtDev )
+ {
+ VirtualDevice* pVDev = GetVirtualDevice();
+
+ const Color& rBackgroundColor = mpWindow->GetBackground().GetColor();
+ if ( pVDev->GetFillColor() != rBackgroundColor )
+ pVDev->SetFillColor( rBackgroundColor );
+ if ( pVDev->GetBackground().GetColor() != rBackgroundColor )
+ pVDev->SetBackground( rBackgroundColor );
+
+ BOOL bVDevValid = TRUE;
+ Size aOutSz( pVDev->GetOutputSizePixel() );
+ if ( ( aOutSz.Width() < rRect.GetWidth() ) ||
+ ( aOutSz.Height() < rRect.GetHeight() ) )
+ {
+ bVDevValid = pVDev->SetOutputSizePixel( rRect.GetSize() );
+ }
+ else
+ {
+ // Das VirtDev kann bei einem Resize sehr gross werden =>
+ // irgendwann mal kleiner machen!
+ if ( ( aOutSz.Height() > ( rRect.GetHeight() + 20 ) ) ||
+ ( aOutSz.Width() > ( rRect.GetWidth() + 20 ) ) )
+ {
+ bVDevValid = pVDev->SetOutputSizePixel( rRect.GetSize() );
+ }
+ else
+ {
+ pVDev->Erase();
+ }
+ }
+ if ( !bVDevValid )
+ {
+ ImpPaint( rRect, FALSE /* ohne VDev */ );
+ return;
+ }
+
+ Rectangle aTmpRec( Point( 0, 0 ), rRect.GetSize() );
+ Point aStartPos = GetDocPos( rRect.TopLeft() );
+ aStartPos.X() *= (-1);
+ aStartPos.Y() *= (-1);
+
+ TextSelection *pTmpPtr = mbHighlightSelection ? NULL : &maSelection;
+ ImpPaint( pVDev, aStartPos, &aTmpRec, NULL, pTmpPtr );
+
+ mpWindow->DrawOutDev( rRect.TopLeft(), rRect.GetSize(),
+ Point(0,0), rRect.GetSize(), *pVDev );
+
+// ShowSelection();
+ if ( mbHighlightSelection )
+ ImpHighlight( maSelection );
+ }
+ else
+ {
+ Point aStartPos( -maStartDocPos.X(), -maStartDocPos.Y() );
+
+ TextSelection *pTmpPtr = mbHighlightSelection ? NULL : &maSelection;
+ ImpPaint( mpWindow, aStartPos, &rRect, NULL, pTmpPtr );
+
+// ShowSelection();
+ if ( mbHighlightSelection )
+ ImpHighlight( maSelection );
+ }
+}
+
+void TextView::ImpHighlight( const TextSelection& rSel )
+{
+ TextSelection aSel( rSel );
+ aSel.Justify();
+ if ( aSel.HasRange() && !mpTextEngine->IsInUndo() && mpTextEngine->GetUpdateMode() )
+ {
+ BOOL bInvertSelection = FALSE;
+#ifdef MAC
+ bInvertSelection = ( mpWindow->GetBackground().GetColor() != COL_WHITE );
+#endif
+ mpCursor->Hide();
+
+ DBG_ASSERT( !mpTextEngine->mpIdleFormatter->IsActive(), "ImpHighlight: Not formatted!" );
+
+ Rectangle aVisArea( maStartDocPos, mpWindow->GetOutputSizePixel() );
+ long nY = 0;
+ ULONG nStartPara = aSel.GetStart().GetPara();
+ ULONG nEndPara = aSel.GetEnd().GetPara();
+ for ( ULONG nPara = 0; nPara <= nEndPara; nPara++ )
+ {
+ long nParaHeight = (long)mpTextEngine->CalcParaHeight( nPara );
+ if ( ( nPara >= nStartPara ) && ( ( nY + nParaHeight ) > aVisArea.Top() ) )
+ {
+ TEParaPortion* pTEParaPortion = mpTextEngine->mpTEParaPortions->GetObject( nPara );
+ USHORT nStartLine = 0;
+ USHORT nEndLine = pTEParaPortion->GetLines().Count() -1;
+ if ( nPara == nStartPara )
+ nStartLine = pTEParaPortion->GetLineNumber( aSel.GetStart().GetIndex(), FALSE );
+ if ( nPara == nEndPara )
+ nEndLine = pTEParaPortion->GetLineNumber( aSel.GetEnd().GetIndex(), TRUE );
+
+ // ueber die Zeilen iterieren....
+ for ( USHORT nLine = nStartLine; nLine <= nEndLine; nLine++ )
+ {
+ TextLine* pLine = pTEParaPortion->GetLines().GetObject( nLine );
+ USHORT nStartIndex = pLine->GetStart();
+ USHORT nEndIndex = pLine->GetEnd();
+ if ( ( nPara == nStartPara ) && ( nLine == nStartLine ) )
+ nStartIndex = aSel.GetStart().GetIndex();
+ if ( ( nPara == nEndPara ) && ( nLine == nEndLine ) )
+ nEndIndex = aSel.GetEnd().GetIndex();
+
+ // Kann passieren, wenn am Anfang einer umgebrochenen Zeile.
+ if ( nEndIndex < nStartIndex )
+ nEndIndex = nStartIndex;
+
+ Rectangle aTmpRec( mpTextEngine->GetEditCursor( TextPaM( nPara, nStartIndex ), FALSE ) );
+ aTmpRec.Top() += nY;
+ aTmpRec.Bottom() += nY;
+ Point aTopLeft( aTmpRec.TopLeft() );
+
+ aTmpRec = mpTextEngine->GetEditCursor( TextPaM( nPara, nEndIndex ), TRUE );
+ aTmpRec.Top() += nY;
+ aTmpRec.Bottom() += nY;
+ Point aBottomRight( aTmpRec.BottomRight() );
+ aBottomRight.X()--;
+
+ // Nur Painten, wenn im sichtbaren Bereich...
+ if ( ( aTopLeft.X() < aBottomRight.X() ) && ( aBottomRight.Y() >= aVisArea.Top() ) )
+ {
+ Point aPnt1( GetWindowPos( aTopLeft ) );
+ Point aPnt2( GetWindowPos( aBottomRight ) );
+
+ Rectangle aRect( aPnt1, aPnt2 );
+ /*! (pb) NOOLDSV
+ if ( bInvertSelection )
+ mpWindow->InvertRect( aRect );
+ else
+ mpWindow->HighlightRect( aRect );
+ */
+ mpWindow->Invert( aRect );
+ }
+ }
+ }
+ nY += nParaHeight;
+
+ if ( nY >= aVisArea.Bottom() )
+ break;
+ }
+ }
+}
+
+
+void TextView::ShowSelection()
+{
+ if ( maSelection.HasRange() )
+ {
+ if ( mbHighlightSelection )
+ ImpHighlight( maSelection );
+ else
+ {
+ // Den Bereich neu zeichnen...
+ Rectangle aOutArea( Point( 0, 0 ), mpWindow->GetOutputSizePixel() );
+ Point aStartPos( -maStartDocPos.X(), -maStartDocPos.Y() );
+ TextSelection aRange( maSelection );
+ aRange.Justify();
+ BOOL bVisCursor = mpCursor->IsVisible();
+ mpCursor->Hide();
+ ImpPaint( mpWindow, aStartPos, &aOutArea, &aRange, &maSelection );
+ if ( bVisCursor )
+ mpCursor->Show();
+ }
+ }
+}
+
+void TextView::HideSelection()
+{
+ if ( maSelection.HasRange() )
+ {
+ if ( mbHighlightSelection )
+ ImpHighlight( maSelection );
+ else
+ {
+ // Den Bereich neu zeichnen...
+ Rectangle aOutArea( Point( 0, 0 ), mpWindow->GetOutputSizePixel() );
+ Point aStartPos( -maStartDocPos.X(), -maStartDocPos.Y() );
+ TextSelection aRange( maSelection );
+ aRange.Justify();
+ BOOL bVisCursor = mpCursor->IsVisible();
+ mpCursor->Hide();
+ ImpPaint( mpWindow, aStartPos, &aOutArea, &aRange, NULL );
+ if ( bVisCursor )
+ mpCursor->Show();
+ }
+ }
+}
+
+void TextView::ShowSelection( const TextSelection& rRange )
+{
+ if ( rRange.HasRange() )
+ {
+ if ( mbHighlightSelection )
+ ImpHighlight( rRange );
+ else
+ {
+ // Den Bereich neu zeichnen...
+ Rectangle aOutArea( Point( 0, 0 ), mpWindow->GetOutputSizePixel() );
+ Point aStartPos( -maStartDocPos.X(), -maStartDocPos.Y() );
+ TextSelection aRange( rRange );
+ aRange.Justify();
+ BOOL bVisCursor = mpCursor->IsVisible();
+ mpCursor->Hide();
+ ImpPaint( mpWindow, aStartPos, &aOutArea, &aRange, &maSelection );
+ if ( bVisCursor )
+ mpCursor->Show();
+ }
+ }
+}
+
+VirtualDevice* TextView::GetVirtualDevice()
+{
+ if ( !mpVirtDev )
+ {
+ mpVirtDev = new VirtualDevice;
+ mpVirtDev->SetLineColor();
+ }
+ return mpVirtDev;
+}
+
+void TextView::EraseVirtualDevice()
+{
+ delete mpVirtDev;
+ mpVirtDev = 0;
+}
+
+BOOL TextView::KeyInput( const KeyEvent& rKeyEvent )
+{
+ BOOL bDone = TRUE;
+ BOOL bModified = FALSE;
+ BOOL bMoved = FALSE;
+ BOOL bEndKey = FALSE; // spezielle CursorPosition
+ BOOL bAllowIdle = TRUE;
+
+ // Um zu pruefen ob durch irgendeine Aktion mModified, das lokale
+ // bModified wird z.B. bei Cut/Paste nicht gesetzt, weil dort an anderen
+ // Stellen das updaten erfolgt.
+ BOOL bWasModified = mpTextEngine->IsModified();
+ mpTextEngine->SetModified( FALSE );
+
+ TextSelection aCurSel( maSelection );
+ TextSelection aOldSel( aCurSel );
+
+ USHORT nCode = rKeyEvent.GetKeyCode().GetCode();
+ KeyFuncType eFunc = rKeyEvent.GetKeyCode().GetFunction();
+ if ( eFunc != KEYFUNC_DONTKNOW )
+ {
+ switch ( eFunc )
+ {
+ case KEYFUNC_CUT:
+ {
+ if ( !mbReadOnly )
+ Cut();
+ }
+ break;
+ case KEYFUNC_COPY:
+ {
+ Copy();
+ }
+ break;
+ case KEYFUNC_PASTE:
+ {
+ if ( !mbReadOnly )
+ Paste();
+ }
+ break;
+ case KEYFUNC_UNDO:
+ {
+ if ( !mbReadOnly )
+ Undo();
+ }
+ break;
+ case KEYFUNC_REDO:
+ {
+ if ( !mbReadOnly )
+ Redo();
+ }
+ break;
+
+ default: // wird dann evtl. unten bearbeitet.
+ eFunc = KEYFUNC_DONTKNOW;
+ }
+ }
+ if ( eFunc == KEYFUNC_DONTKNOW )
+ {
+ switch ( nCode )
+ {
+ case KEY_UP:
+ case KEY_DOWN:
+ case KEY_LEFT:
+ case KEY_RIGHT:
+ case KEY_HOME:
+ case KEY_END:
+ case KEY_PAGEUP:
+ case KEY_PAGEDOWN:
+ {
+ if ( !rKeyEvent.GetKeyCode().IsMod2() )
+ {
+ aCurSel = ImpMoveCursor( rKeyEvent );
+ bMoved = TRUE;
+ if ( nCode == KEY_END )
+ bEndKey = TRUE;
+ }
+ }
+ break;
+ case KEY_BACKSPACE:
+ case KEY_DELETE:
+ {
+ if ( !mbReadOnly && !rKeyEvent.GetKeyCode().IsMod2() )
+ {
+ BYTE nDel = ( nCode == KEY_DELETE ) ? DEL_RIGHT : DEL_LEFT;
+ BYTE nMode = rKeyEvent.GetKeyCode().IsMod1() ? DELMODE_RESTOFWORD : DELMODE_SIMPLE;
+ if ( ( nMode == DELMODE_RESTOFWORD ) && rKeyEvent.GetKeyCode().IsShift() )
+ nMode = DELMODE_RESTOFCONTENT;
+
+ mpTextEngine->UndoActionStart( TEXTUNDO_DELETE );
+ aCurSel = ImpDelete( nDel, nMode );
+ mpTextEngine->UndoActionEnd( TEXTUNDO_DELETE );
+ bModified = TRUE;
+ bAllowIdle = FALSE;
+ }
+ else
+ bDone = FALSE;
+ }
+ break;
+ case KEY_TAB:
+ {
+ if ( !mbReadOnly && !rKeyEvent.GetKeyCode().IsShift() &&
+ !rKeyEvent.GetKeyCode().IsMod1() && !rKeyEvent.GetKeyCode().IsMod2() &&
+ ImplCheckTextLen( 'x' ) )
+ {
+ aCurSel = mpTextEngine->ImpInsertText( aCurSel, '\t', !IsInsertMode() );
+ bModified = TRUE;
+ }
+ else
+ bDone = FALSE;
+ }
+ break;
+ case KEY_RETURN:
+ {
+ // Shift-RETURN darf nicht geschluckt werden, weil dann keine
+ // mehrzeilige Eingabe in Dialogen/Property-Editor moeglich.
+ if ( !mbReadOnly && !rKeyEvent.GetKeyCode().IsMod1() &&
+ !rKeyEvent.GetKeyCode().IsMod2() && ImplCheckTextLen( 'x' ) )
+ {
+ mpTextEngine->UndoActionStart( TEXTUNDO_INSERT );
+ aCurSel = mpTextEngine->ImpInsertParaBreak( aCurSel );
+ if ( mbAutoIndent )
+ {
+ TextNode* pPrev = mpTextEngine->mpDoc->GetNodes().GetObject( aCurSel.GetEnd().GetPara() - 1 );
+ USHORT n = 0;
+ while ( ( n < pPrev->GetText().Len() ) && (
+ ( pPrev->GetText().GetChar( n ) == ' ' ) ||
+ ( pPrev->GetText().GetChar( n ) == '\t' ) ) )
+ {
+ n++;
+ }
+ if ( n )
+ aCurSel = mpTextEngine->ImpInsertText( aCurSel, pPrev->GetText().Copy( 0, n ) );
+ }
+ mpTextEngine->UndoActionEnd( TEXTUNDO_INSERT );
+ bModified = TRUE;
+ }
+ else
+ bDone = FALSE;
+ }
+ break;
+ case KEY_INSERT:
+ {
+ if ( !mbReadOnly )
+ SetInsertMode( !IsInsertMode() );
+ }
+ break;
+ default:
+ {
+ if ( TextEngine::IsSimpleCharInput( rKeyEvent ) )
+ {
+ xub_Unicode nCharCode = rKeyEvent.GetCharCode();
+ if ( !mbReadOnly && ImplCheckTextLen( nCharCode ) ) // sonst trotzdem das Zeichen schlucken...
+ {
+ aCurSel = mpTextEngine->ImpInsertText( aCurSel, nCharCode, !IsInsertMode() );
+ bModified = TRUE;
+ }
+ }
+ else
+ bDone = FALSE;
+ }
+ }
+ }
+
+ if ( aCurSel != aOldSel )
+ maSelection = aCurSel;
+
+ mpTextEngine->UpdateSelections();
+
+ if ( ( nCode != KEY_UP ) && ( nCode != KEY_DOWN ) )
+ mnTravelXPos = TRAVEL_X_DONTKNOW;
+
+ if ( bModified )
+ {
+ // Idle-Formatter nur, wenn AnyInput.
+ if ( bAllowIdle && Application::AnyInput( INPUT_KEYBOARD) )
+ mpTextEngine->IdleFormatAndUpdate( this );
+ else
+ mpTextEngine->FormatAndUpdate( this);
+ }
+ else if ( bMoved )
+ {
+ // Selection wird jetzt gezielt in ImpMoveCursor gemalt.
+ ImpShowCursor( mbAutoScroll, TRUE, bEndKey );
+ }
+
+ if ( mpTextEngine->IsModified() )
+ mpTextEngine->Broadcast( TextHint( TEXT_HINT_MODIFIED ) );
+ else if ( bWasModified )
+ mpTextEngine->SetModified( TRUE );
+
+ return bDone;
+}
+
+void TextView::MouseButtonUp( const MouseEvent& rMouseEvent )
+{
+ mnTravelXPos = TRAVEL_X_DONTKNOW;
+ mpSelEngine->SelMouseButtonUp( rMouseEvent );
+}
+
+void TextView::MouseButtonDown( const MouseEvent& rMouseEvent )
+{
+ mpTextEngine->CheckIdleFormatter(); // Falls schnelles Tippen und MouseButtonDown
+ mnTravelXPos = TRAVEL_X_DONTKNOW;
+
+ mpTextEngine->SetActiveView( this );
+
+ mpSelEngine->SelMouseButtonDown( rMouseEvent );
+
+ // Sonderbehandlungen
+ if ( !rMouseEvent.IsShift() && ( rMouseEvent.GetClicks() >= 2 ) )
+ {
+ if ( rMouseEvent.IsMod2() )
+ {
+ HideSelection();
+ maSelection.GetStart() = maSelection.GetEnd();
+ SetCursorAtPoint( rMouseEvent.GetPosPixel() ); // Wird von SelectionEngine bei MOD2 nicht gesetzt
+ }
+
+ if ( rMouseEvent.GetClicks() == 2 )
+ {
+ // Wort selektieren
+ if ( maSelection.GetEnd().GetIndex() < mpTextEngine->GetTextLen( maSelection.GetEnd().GetPara() ) )
+ {
+ HideSelection();
+ TextNode* pNode = mpTextEngine->mpDoc->GetNodes().GetObject( maSelection.GetEnd().GetPara() );
+ uno::Reference < text::XBreakIterator > xBI = mpTextEngine->GetBreakIterator();
+ text::Boundary aBoundary = xBI->getWordBoundary( pNode->GetText(), maSelection.GetEnd().GetIndex(), mpTextEngine->GetLocale(), text::WordType::ANYWORD_IGNOREWHITESPACES, sal_True );
+ maSelection.GetStart().GetIndex() = aBoundary.startPos;
+ maSelection.GetEnd().GetIndex() = aBoundary.endPos;
+ ShowSelection();
+ ShowCursor( TRUE, TRUE );
+ }
+ }
+ else if ( rMouseEvent.GetClicks() == 3 )
+ {
+ // Absatz selektieren
+ if ( maSelection.GetEnd().GetIndex() < mpTextEngine->GetTextLen( maSelection.GetEnd().GetPara() ) )
+ {
+ HideSelection();
+ maSelection.GetStart().GetIndex() = 0;
+ maSelection.GetEnd().GetIndex() = mpTextEngine->mpDoc->GetNodes().GetObject( maSelection.GetEnd().GetPara() )->GetText().Len();
+ ShowSelection();
+ ShowCursor( TRUE, TRUE );
+ }
+ }
+ }
+}
+
+
+void TextView::MouseMove( const MouseEvent& rMouseEvent )
+{
+ mnTravelXPos = TRAVEL_X_DONTKNOW;
+ mpSelEngine->SelMouseMove( rMouseEvent );
+}
+
+void TextView::Command( const CommandEvent& rCEvt )
+{
+ mpTextEngine->CheckIdleFormatter(); // Falls schnelles Tippen und MouseButtonDown
+ mpTextEngine->SetActiveView( this );
+ BOOL bCallSelectionEngineCommand = TRUE;
+ if ( ( rCEvt.GetCommand() == COMMAND_STARTDRAG ) )
+ {
+ }
+ if ( bCallSelectionEngineCommand )
+ mpSelEngine->Command( rCEvt );
+}
+
+void TextView::ShowCursor( BOOL bGotoCursor, BOOL bForceVisCursor )
+{
+ // Die Einstellung hat mehr Gewicht:
+ if ( !mbAutoScroll )
+ bGotoCursor = FALSE;
+ ImpShowCursor( bGotoCursor, bForceVisCursor, FALSE );
+}
+
+void TextView::HideCursor()
+{
+ mpCursor->Hide();
+}
+
+void TextView::Scroll( long ndX, long ndY )
+{
+ DBG_ASSERT( mpTextEngine->IsFormatted(), "Scroll: Nicht formatiert!" );
+
+ if ( !ndX && !ndY )
+ return;
+
+ Point aNewStartPos( maStartDocPos );
+
+ // Vertical:
+ aNewStartPos.Y() -= ndY;
+ if ( aNewStartPos.Y() < 0 )
+ aNewStartPos.Y() = 0;
+
+ // Horizontal:
+ aNewStartPos.X() -= ndX;
+ if ( aNewStartPos.X() < 0 )
+ aNewStartPos.X() = 0;
+
+ long nDiffX = maStartDocPos.X() - aNewStartPos.X();
+ long nDiffY = maStartDocPos.Y() - aNewStartPos.Y();
+
+ if ( nDiffX || nDiffY )
+ {
+ BOOL bVisCursor = mpCursor->IsVisible();
+ mpCursor->Hide();
+ mpWindow->Update();
+ maStartDocPos = aNewStartPos;
+
+ mpWindow->Scroll( nDiffX, nDiffY );
+ mpWindow->Update();
+ mpCursor->SetPos( mpCursor->GetPos() + Point( nDiffX, nDiffY ) );
+ if ( bVisCursor && !mbReadOnly )
+ mpCursor->Show();
+ }
+}
+
+void TextView::Undo()
+{
+ mpTextEngine->SetActiveView( this );
+ mpTextEngine->GetUndoManager().Undo( 1 );
+}
+
+void TextView::Redo()
+{
+ mpTextEngine->SetActiveView( this );
+ mpTextEngine->GetUndoManager().Redo( 0 );
+}
+
+void TextView::Cut()
+{
+ mpTextEngine->UndoActionStart( TEXTUNDO_CUT );
+ Copy();
+ DeleteSelected();
+ mpTextEngine->UndoActionEnd( TEXTUNDO_CUT );
+}
+
+void TextView::Copy()
+{
+ Clipboard::Clear();
+ TextSelection aSel( maSelection );
+ aSel.Justify();
+ SvMemoryStream aMem;
+ mpTextEngine->Write( aMem, &aSel );
+ aMem << '\0';
+ Clipboard::CopyData( (const char*)aMem.GetData(), aMem.Tell(), FORMAT_STRING );
+ if ( mpTextEngine->HasAttrib( TEXTATTR_HYPERLINK ) )
+ {
+ // Dann auch als HTML
+ aMem.SetStreamSize( 0 );
+ aMem.Seek( 0 );
+ mpTextEngine->Write( aMem, &aSel, TRUE );
+ aMem << '\0';
+ Clipboard::CopyData( (const char*)aMem.GetData(), aMem.Tell(), SOT_FORMATSTR_ID_HTML );
+ }
+}
+
+void TextView::Paste()
+{
+ BOOL bPaste = TRUE;
+ if ( mpTextEngine->GetMaxTextLen() )
+ {
+ // QuickCheck, kein String > 64K moeglich...
+ String aStr( Clipboard::PasteString() );
+ aStr.ConvertLineEnd( LINEEND_LF );
+ bPaste = ImplCheckTextLen( aStr );
+ }
+
+ if ( bPaste )
+ {
+ mpTextEngine->UndoActionStart( TEXTUNDO_PASTE );
+
+ ULONG nLen = Clipboard::GetDataLen( FORMAT_STRING );
+ void* pBuf = SvMemAlloc( nLen );
+ Clipboard::PasteData( pBuf, nLen, FORMAT_STRING );
+
+ // commented out while converting to Unicode
+ // long nStringLen = strlen( (const char*) pBuf ); // 0-terminiert, Datenmuell im Clipborad dahinter.
+
+ SvMemoryStream aMem( (char*)pBuf, nLen /*nStringLen*/, STREAM_READ );
+ aMem.ObjectOwnsMemory( TRUE );
+ mpTextEngine->Read( aMem, &maSelection );
+
+ mpTextEngine->UndoActionEnd( TEXTUNDO_PASTE );
+ }
+}
+
+String TextView::GetSelected()
+{
+ return mpTextEngine->GetText( maSelection, GetSystemLineEnd() );
+}
+
+void TextView::SetInsertMode( BOOL bInsert )
+{
+ if ( mbInsertMode != bInsert )
+ {
+ mbInsertMode = bInsert;
+ ShowCursor( mbAutoScroll, FALSE );
+ }
+}
+
+void TextView::SetReadOnly( BOOL bReadOnly )
+{
+ if ( mbReadOnly != bReadOnly )
+ {
+ mbReadOnly = bReadOnly;
+ if ( !mbReadOnly )
+ ShowCursor( mbAutoScroll, FALSE );
+ else
+ HideCursor();
+ }
+}
+
+TextSelection TextView::ImpMoveCursor( const KeyEvent& rKeyEvent )
+{
+ // Eigentlich nur bei Up/Down noetig, aber was solls.
+ mpTextEngine->CheckIdleFormatter();
+
+ TextPaM aPaM( maSelection.GetEnd() );
+ TextPaM aOldEnd( aPaM );
+
+ BOOL bCtrl = rKeyEvent.GetKeyCode().IsMod1() ? TRUE : FALSE;
+
+ switch ( rKeyEvent.GetKeyCode().GetCode() )
+ {
+ case KEY_UP: aPaM = CursorUp( aPaM );
+ break;
+ case KEY_DOWN: aPaM = CursorDown( aPaM );
+ break;
+ case KEY_HOME: aPaM = bCtrl ? CursorStartOfDoc() : CursorStartOfLine( aPaM );
+ break;
+ case KEY_END: aPaM = bCtrl ? CursorEndOfDoc() : CursorEndOfLine( aPaM );
+ break;
+ case KEY_PAGEUP: aPaM = bCtrl ? CursorStartOfDoc() : PageUp( aPaM );
+ break;
+ case KEY_PAGEDOWN: aPaM = bCtrl ? CursorEndOfDoc() : PageDown( aPaM );
+ break;
+ case KEY_LEFT: aPaM = CursorLeft( aPaM, bCtrl );
+ break;
+ case KEY_RIGHT: aPaM = CursorRight( aPaM, bCtrl );
+ break;
+ }
+
+ // Bewirkt evtl. ein CreateAnchor oder Deselection all
+ mpSelEngine->CursorPosChanging( rKeyEvent.GetKeyCode().IsShift(), rKeyEvent.GetKeyCode().IsMod1() );
+
+ if ( aOldEnd != aPaM )
+ {
+ mpTextEngine->CursorMoved( aOldEnd.GetPara() );
+
+
+ TextSelection aOldSelection( maSelection );
+ maSelection.GetEnd() = aPaM;
+ if ( rKeyEvent.GetKeyCode().IsShift() )
+ {
+ // Dann wird die Selektion erweitert...
+ ShowSelection( TextSelection( aOldEnd, aPaM ) );
+ }
+ else
+ {
+ maSelection.GetStart() = aPaM;
+ }
+ }
+
+ return maSelection;
+}
+
+void TextView::InsertText( const XubString& rStr, BOOL bSelect )
+{
+// HideSelection();
+
+ TextSelection aNewSel( maSelection );
+
+ mpTextEngine->UndoActionStart( TEXTUNDO_INSERT );
+ TextPaM aPaM = mpTextEngine->ImpInsertText( maSelection, rStr );
+ mpTextEngine->UndoActionEnd( TEXTUNDO_INSERT );
+
+ if ( bSelect )
+ {
+ aNewSel.Justify();
+ aNewSel.GetEnd() = aPaM;
+ maSelection = aNewSel;
+ }
+ else
+ maSelection = aPaM;
+
+ mpTextEngine->FormatAndUpdate( this );
+}
+
+TextPaM TextView::CursorLeft( const TextPaM& rPaM, BOOL bWordMode )
+{
+ TextPaM aPaM( rPaM );
+
+ if ( aPaM.GetIndex() )
+ {
+ TextNode* pNode = mpTextEngine->mpDoc->GetNodes().GetObject( aPaM.GetPara() );
+ uno::Reference < text::XBreakIterator > xBI = mpTextEngine->GetBreakIterator();
+ if ( bWordMode )
+ {
+ text::Boundary aBoundary = xBI->getWordBoundary( pNode->GetText(), rPaM.GetIndex(), mpTextEngine->GetLocale(), text::WordType::ANYWORD_IGNOREWHITESPACES, sal_True );
+ if ( aBoundary.startPos == rPaM.GetIndex() )
+ aBoundary = xBI->previousWord( pNode->GetText(), rPaM.GetIndex(), mpTextEngine->GetLocale(), text::WordType::ANYWORD_IGNOREWHITESPACES );
+ aPaM.GetIndex() = aBoundary.startPos;
+ }
+ else
+ {
+ sal_Int32 nCount = 1;
+ aPaM.GetIndex() = xBI->previousCharacters( pNode->GetText(), aPaM.GetIndex(), mpTextEngine->GetLocale(), text::CharacterIteratorMode::SKIPCHARACTER, nCount, nCount );
+ }
+ }
+ else if ( aPaM.GetPara() )
+ {
+ aPaM.GetPara()--;
+ TextNode* pNode = mpTextEngine->mpDoc->GetNodes().GetObject( aPaM.GetPara() );
+ aPaM.GetIndex() = pNode->GetText().Len();
+ }
+ return aPaM;
+}
+
+TextPaM TextView::CursorRight( const TextPaM& rPaM, BOOL bWordMode )
+{
+ TextPaM aPaM( rPaM );
+
+ TextNode* pNode = mpTextEngine->mpDoc->GetNodes().GetObject( aPaM.GetPara() );
+ if ( aPaM.GetIndex() < pNode->GetText().Len() )
+ {
+ uno::Reference < text::XBreakIterator > xBI = mpTextEngine->GetBreakIterator();
+ if ( bWordMode )
+ {
+ text::Boundary aBoundary = xBI->nextWord( pNode->GetText(), aPaM.GetIndex(), mpTextEngine->GetLocale(), text::WordType::ANYWORD_IGNOREWHITESPACES );
+ aPaM.GetIndex() = aBoundary.startPos;
+ }
+ else
+ {
+ sal_Int32 nCount = 1;
+ aPaM.GetIndex() = xBI->nextCharacters( pNode->GetText(), aPaM.GetIndex(), mpTextEngine->GetLocale(), text::CharacterIteratorMode::SKIPCHARACTER, nCount, nCount );
+ }
+ }
+ else if ( aPaM.GetPara() < ( mpTextEngine->mpDoc->GetNodes().Count()-1) )
+ {
+ aPaM.GetPara()++;
+ aPaM.GetIndex() = 0;
+ }
+
+ return aPaM;
+}
+
+TextPaM TextView::ImpDelete( BYTE nMode, BYTE nDelMode )
+{
+ if ( maSelection.HasRange() ) // dann nur Sel. loeschen
+ return mpTextEngine->ImpDeleteText( maSelection );
+
+ TextPaM aStartPaM = maSelection.GetStart();
+ TextPaM aEndPaM = aStartPaM;
+ if ( nMode == DEL_LEFT )
+ {
+ if ( nDelMode == DELMODE_SIMPLE )
+ {
+ aEndPaM = CursorLeft( aEndPaM );
+ }
+ else if ( nDelMode == DELMODE_RESTOFWORD )
+ {
+ TextNode* pNode = mpTextEngine->mpDoc->GetNodes().GetObject( aEndPaM.GetPara() );
+ uno::Reference < text::XBreakIterator > xBI = mpTextEngine->GetBreakIterator();
+ text::Boundary aBoundary = xBI->getWordBoundary( pNode->GetText(), maSelection.GetEnd().GetIndex(), mpTextEngine->GetLocale(), text::WordType::ANYWORD_IGNOREWHITESPACES, sal_True );
+ if ( aBoundary.startPos == maSelection.GetEnd().GetIndex() )
+ aBoundary = xBI->previousWord( pNode->GetText(), maSelection.GetEnd().GetIndex(), mpTextEngine->GetLocale(), text::WordType::ANYWORD_IGNOREWHITESPACES );
+ aEndPaM.GetIndex() = aBoundary.startPos;
+ }
+ else // DELMODE_RESTOFCONTENT
+ {
+ if ( aEndPaM.GetIndex() != 0 )
+ aEndPaM.GetIndex() = 0;
+ else if ( aEndPaM.GetPara() )
+ {
+ // Absatz davor
+ aEndPaM.GetPara()--;
+ aEndPaM.GetIndex() = 0;
+ }
+ }
+ }
+ else
+ {
+ if ( nDelMode == DELMODE_SIMPLE )
+ {
+ aEndPaM = CursorRight( aEndPaM );
+ }
+ else if ( nDelMode == DELMODE_RESTOFWORD )
+ {
+ TextNode* pNode = mpTextEngine->mpDoc->GetNodes().GetObject( aEndPaM.GetPara() );
+ uno::Reference < text::XBreakIterator > xBI = mpTextEngine->GetBreakIterator();
+ text::Boundary aBoundary = xBI->nextWord( pNode->GetText(), maSelection.GetEnd().GetIndex(), mpTextEngine->GetLocale(), text::WordType::ANYWORD_IGNOREWHITESPACES );
+ aEndPaM.GetIndex() = aBoundary.startPos;
+ }
+ else // DELMODE_RESTOFCONTENT
+ {
+ TextNode* pNode = mpTextEngine->mpDoc->GetNodes().GetObject( aEndPaM.GetPara() );
+ if ( aEndPaM.GetIndex() < pNode->GetText().Len() )
+ aEndPaM.GetIndex() = pNode->GetText().Len();
+ else if ( aEndPaM.GetPara() < ( mpTextEngine->mpDoc->GetNodes().Count() - 1 ) )
+ {
+ // Absatz danach
+ aEndPaM.GetPara()++;
+ TextNode* pNextNode = mpTextEngine->mpDoc->GetNodes().GetObject( aEndPaM.GetPara() );
+ aEndPaM.GetIndex() = pNextNode->GetText().Len();
+ }
+ }
+ }
+
+ return mpTextEngine->ImpDeleteText( TextSelection( aStartPaM, aEndPaM ) );
+}
+
+
+
+TextPaM TextView::CursorUp( const TextPaM& rPaM )
+{
+ TextPaM aPaM( rPaM );
+
+ long nX;
+ if ( mnTravelXPos == TRAVEL_X_DONTKNOW )
+ {
+ nX = mpTextEngine->GetEditCursor( rPaM, FALSE ).Left();
+ mnTravelXPos = nX+1;
+ }
+ else
+ nX = mnTravelXPos;
+
+ TEParaPortion* pPPortion = mpTextEngine->mpTEParaPortions->GetObject( rPaM.GetPara() );
+ USHORT nLine = pPPortion->GetLineNumber( rPaM.GetIndex(), FALSE );
+ if ( nLine ) // gleicher Absatz
+ {
+ USHORT nCharPos = mpTextEngine->GetCharPos( rPaM.GetPara(), nLine-1, nX );
+ aPaM.GetIndex() = nCharPos;
+ // Wenn davor eine autom.Umgebrochene Zeile, und ich muss genau an das
+ // Ende dieser Zeile, landet der Cursor in der aktuellen Zeile am Anfang
+ // Siehe Problem: Letztes Zeichen einer autom.umgebr. Zeile = Cursor
+ TextLine* pLine = pPPortion->GetLines().GetObject( nLine - 1 );
+ if ( aPaM.GetIndex() && ( aPaM.GetIndex() == pLine->GetEnd() ) )
+ aPaM.GetIndex()--;
+ }
+ else if ( rPaM.GetPara() ) // vorheriger Absatz
+ {
+ aPaM.GetPara()--;
+ pPPortion = mpTextEngine->mpTEParaPortions->GetObject( aPaM.GetPara() );
+ USHORT nL = pPPortion->GetLines().Count() - 1;
+ USHORT nCharPos = mpTextEngine->GetCharPos( aPaM.GetPara(), nL, nX+1 );
+ aPaM.GetIndex() = nCharPos;
+ }
+
+ return aPaM;
+}
+
+TextPaM TextView::CursorDown( const TextPaM& rPaM )
+{
+ TextPaM aPaM( rPaM );
+
+ long nX;
+ if ( mnTravelXPos == TRAVEL_X_DONTKNOW )
+ {
+ nX = mpTextEngine->GetEditCursor( rPaM, FALSE ).Left();
+ mnTravelXPos = nX+1;
+ }
+ else
+ nX = mnTravelXPos;
+
+ TEParaPortion* pPPortion = mpTextEngine->mpTEParaPortions->GetObject( rPaM.GetPara() );
+ USHORT nLine = pPPortion->GetLineNumber( rPaM.GetIndex(), FALSE );
+ if ( nLine < ( pPPortion->GetLines().Count() - 1 ) )
+ {
+ USHORT nCharPos = mpTextEngine->GetCharPos( rPaM.GetPara(), nLine+1, nX );
+ aPaM.GetIndex() = nCharPos;
+
+ // Sonderbehandlung siehe CursorUp...
+ TextLine* pLine = pPPortion->GetLines().GetObject( nLine + 1 );
+ if ( ( aPaM.GetIndex() == pLine->GetEnd() ) && ( aPaM.GetIndex() > pLine->GetStart() ) && aPaM.GetIndex() < pPPortion->GetNode()->GetText().Len() )
+ aPaM.GetIndex()--;
+ }
+ else if ( rPaM.GetPara() < ( mpTextEngine->mpDoc->GetNodes().Count() - 1 ) ) // naechster Absatz
+ {
+ aPaM.GetPara()++;
+ pPPortion = mpTextEngine->mpTEParaPortions->GetObject( aPaM.GetPara() );
+ USHORT nCharPos = mpTextEngine->GetCharPos( aPaM.GetPara(), 0, nX+1 );
+ aPaM.GetIndex() = nCharPos;
+ TextLine* pLine = pPPortion->GetLines().GetObject( 0 );
+ if ( ( aPaM.GetIndex() == pLine->GetEnd() ) && ( aPaM.GetIndex() > pLine->GetStart() ) && ( pPPortion->GetLines().Count() > 1 ) )
+ aPaM.GetIndex()--;
+ }
+
+ return aPaM;
+}
+
+TextPaM TextView::CursorStartOfLine( const TextPaM& rPaM )
+{
+ TextPaM aPaM( rPaM );
+
+ TEParaPortion* pPPortion = mpTextEngine->mpTEParaPortions->GetObject( rPaM.GetPara() );
+ USHORT nLine = pPPortion->GetLineNumber( aPaM.GetIndex(), FALSE );
+ TextLine* pLine = pPPortion->GetLines().GetObject( nLine );
+ aPaM.GetIndex() = pLine->GetStart();
+
+ return aPaM;
+}
+
+TextPaM TextView::CursorEndOfLine( const TextPaM& rPaM )
+{
+ TextPaM aPaM( rPaM );
+
+ TEParaPortion* pPPortion = mpTextEngine->mpTEParaPortions->GetObject( rPaM.GetPara() );
+ USHORT nLine = pPPortion->GetLineNumber( aPaM.GetIndex(), FALSE );
+ TextLine* pLine = pPPortion->GetLines().GetObject( nLine );
+ aPaM.GetIndex() = pLine->GetEnd();
+
+ if ( pLine->GetEnd() > pLine->GetStart() ) // Leerzeile
+ {
+ xub_Unicode cLastChar = pPPortion->GetNode()->GetText().GetChar((USHORT)(aPaM.GetIndex()-1) );
+ if ( ( cLastChar == ' ' ) && ( aPaM.GetIndex() != pPPortion->GetNode()->GetText().Len() ) )
+ {
+ // Bei einem Blank in einer autom. umgebrochenen Zeile macht es Sinn,
+ // davor zu stehen, da der Anwender hinter das Wort will.
+ // Wenn diese geaendert wird, Sonderbehandlung fuer Pos1 nach End!
+ aPaM.GetIndex()--;
+ }
+ }
+ return aPaM;
+}
+
+TextPaM TextView::CursorStartOfParagraph( const TextPaM& rPaM )
+{
+ TextPaM aPaM( rPaM );
+ aPaM.GetIndex() = 0;
+ return aPaM;
+}
+
+TextPaM TextView::CursorEndOfParagraph( const TextPaM& rPaM )
+{
+ TextNode* pNode = mpTextEngine->mpDoc->GetNodes().GetObject( rPaM.GetPara() );
+ TextPaM aPaM( rPaM );
+ aPaM.GetIndex() = pNode->GetText().Len();
+ return aPaM;
+}
+
+TextPaM TextView::CursorStartOfDoc()
+{
+ TextPaM aPaM( 0, 0 );
+ return aPaM;
+}
+
+TextPaM TextView::CursorEndOfDoc()
+{
+ ULONG nNode = mpTextEngine->mpDoc->GetNodes().Count() - 1;
+ TextNode* pNode = mpTextEngine->mpDoc->GetNodes().GetObject( nNode );
+ TextPaM aPaM( nNode, pNode->GetText().Len() );
+ return aPaM;
+}
+
+TextPaM TextView::PageUp( const TextPaM& rPaM )
+{
+ Rectangle aRec = mpTextEngine->PaMtoEditCursor( rPaM );
+ Point aTopLeft = aRec.TopLeft();
+ aTopLeft.Y() -= mpWindow->GetOutputSizePixel().Height() * 9/10;
+ aTopLeft.X() += 1;
+ if ( aTopLeft.Y() < 0 )
+ aTopLeft.Y() = 0;
+
+ TextPaM aPaM = mpTextEngine->GetPaM( aTopLeft );
+ return aPaM;
+}
+
+TextPaM TextView::PageDown( const TextPaM& rPaM )
+{
+ Rectangle aRec = mpTextEngine->PaMtoEditCursor( rPaM );
+ Point aBottomRight = aRec.BottomRight();
+ aBottomRight.Y() += mpWindow->GetOutputSizePixel().Height() * 9/10;
+ aBottomRight.X() += 1;
+ long nHeight = mpTextEngine->GetTextHeight();
+ if ( aBottomRight.Y() > nHeight )
+ aBottomRight.Y() = nHeight-1;
+
+ TextPaM aPaM = mpTextEngine->GetPaM( aBottomRight );
+ return aPaM;
+}
+
+void TextView::ImpShowCursor( BOOL bGotoCursor, BOOL bForceVisCursor, BOOL bSpecial )
+{
+ if ( mpTextEngine->IsFormatting() )
+ return;
+ if ( mpTextEngine->GetUpdateMode() == FALSE )
+ return;
+ if ( mpTextEngine->IsInUndo() )
+ return;
+
+ mpTextEngine->CheckIdleFormatter();
+ if ( !mpTextEngine->IsFormatted() )
+ mpTextEngine->FormatAndUpdate( this );
+
+
+ TextPaM aPaM( maSelection.GetEnd() );
+ Rectangle aEditCursor = mpTextEngine->PaMtoEditCursor( aPaM, bSpecial );
+ if ( !IsInsertMode() && !maSelection.HasRange() )
+ {
+ TextNode* pNode = mpTextEngine->mpDoc->GetNodes().GetObject( aPaM.GetPara() );
+ if ( pNode->GetText().Len() && ( aPaM.GetIndex() < pNode->GetText().Len() ) )
+ {
+ long nWidth = (long)mpTextEngine->CalcTextWidth( aPaM.GetPara(), aPaM.GetIndex(), 1 );
+ aEditCursor.Right() += nWidth;
+ }
+ }
+
+ Size aOutSz = mpWindow->GetOutputSizePixel();
+ if ( aEditCursor.GetHeight() > aOutSz.Height() )
+ aEditCursor.Bottom() = aEditCursor.Top() + aOutSz.Height() - 1;
+
+ if ( bGotoCursor )
+ {
+ long nVisStartY = maStartDocPos.Y();
+ long nVisEndY = maStartDocPos.Y() + aOutSz.Height();
+ long nVisStartX = maStartDocPos.X();
+ long nVisEndX = maStartDocPos.X() + aOutSz.Width();
+ long nMoreX = aOutSz.Width() / 4;
+
+ Point aNewStartPos( maStartDocPos );
+
+ if ( aEditCursor.Bottom() > nVisEndY )
+ {
+ aNewStartPos.Y() += ( aEditCursor.Bottom() - nVisEndY );
+ }
+ else if ( aEditCursor.Top() < nVisStartY )
+ {
+ aNewStartPos.Y() -= ( nVisStartY - aEditCursor.Top() );
+ }
+
+ if ( aEditCursor.Right() > nVisEndX )
+ {
+ aNewStartPos.X() += ( aEditCursor.Right() - nVisEndX );
+
+ // Darfs ein bischen mehr sein?
+ aNewStartPos.X() += nMoreX;
+ }
+ else if ( aEditCursor.Left() < nVisStartX )
+ {
+ aNewStartPos.X() -= ( nVisStartX - aEditCursor.Left() );
+
+ // Darfs ein bischen mehr sein?
+ aNewStartPos.X() -= nMoreX;
+ }
+
+ // X kann durch das 'bischen mehr' falsch sein:
+// ULONG nMaxTextWidth = mpTextEngine->GetMaxTextWidth();
+// if ( !nMaxTextWidth || ( nMaxTextWidth > 0x7FFFFFFF ) )
+// nMaxTextWidth = 0x7FFFFFFF;
+// long nMaxX = (long)nMaxTextWidth - aOutSz.Width();
+ long nMaxX = mpTextEngine->CalcTextWidth() - aOutSz.Width();
+ if ( nMaxX < 0 )
+ nMaxX = 0;
+
+ if ( aNewStartPos.X() < 0 )
+ aNewStartPos.X() = 0;
+ else if ( aNewStartPos.X() > nMaxX )
+ aNewStartPos.X() = nMaxX;
+
+ // Y sollte nicht weiter unten als noetig liegen:
+ long nYMax = mpTextEngine->GetTextHeight() - aOutSz.Height();
+ if ( nYMax < 0 )
+ nYMax = 0;
+ if ( aNewStartPos.Y() > nYMax )
+ aNewStartPos.Y() = nYMax;
+
+ if ( aNewStartPos != maStartDocPos )
+ {
+ Scroll( -(aNewStartPos.X() - maStartDocPos.X()), -(aNewStartPos.Y() - maStartDocPos.Y()) );
+ mpTextEngine->Broadcast( TextHint( TEXT_HINT_VIEWSCROLLED ) );
+ }
+ }
+
+ Point aPoint( GetWindowPos( aEditCursor.TopLeft() ) );
+ mpCursor->SetPos( aPoint );
+ mpCursor->SetSize( aEditCursor.GetSize() );
+ if ( bForceVisCursor && mbCursorEnabled )
+ mpCursor->Show();
+}
+
+BOOL TextView::SetCursorAtPoint( const Point& rPosPixel )
+{
+// if ( !Rectangle( Point(), mpWindow->GetOutputSizePixel() ).IsInside( rPosPixel ) && !mbInSelection )
+// return FALSE;
+
+ mpTextEngine->CheckIdleFormatter();
+
+ Point aDocPos = GetDocPos( rPosPixel );
+
+ TextPaM aPaM = mpTextEngine->GetPaM( aDocPos );
+
+ // aTmpNewSel: Diff zwischen alt und neu, nicht die neue Selektion
+ TextSelection aTmpNewSel( maSelection.GetEnd(), aPaM );
+ maSelection.GetEnd() = aPaM;
+
+ if ( !mpSelEngine->HasAnchor() )
+ {
+ if ( maSelection.GetStart() != aPaM )
+ mpTextEngine->CursorMoved( maSelection.GetStart().GetPara() );
+ maSelection.GetStart() = aPaM;
+ }
+ else
+ {
+ ShowSelection( aTmpNewSel );
+ }
+
+ BOOL bForceCursor = mpDDInfo ? FALSE : TRUE; // && !mbInSelection
+ ImpShowCursor( mbAutoScroll, bForceCursor, FALSE );
+ return TRUE;
+}
+
+BOOL TextView::IsSelectionAtPoint( const Point& rPosPixel )
+{
+// if ( !Rectangle( Point(), mpWindow->GetOutputSizePixel() ).IsInside( rPosPixel ) && !mbInSelection )
+// return FALSE;
+
+ Point aDocPos = GetDocPos( rPosPixel );
+ TextPaM aPaM = mpTextEngine->GetPaM( aDocPos, FALSE );
+ // Bei Hyperlinks D&D auch ohne Selektion starten.
+ // BeginDrag wird aber nur gerufen, wenn IsSelectionAtPoint()
+ // Problem: IsSelectionAtPoint wird bei Command() nicht gerufen,
+ // wenn vorher im MBDown schon FALSE returnt wurde.
+ return ( IsInSelection( aPaM ) ||
+ ( /* mpSelEngine->IsInCommand() && */ mpTextEngine->FindAttrib( aPaM, TEXTATTR_HYPERLINK ) ) );
+}
+
+BOOL TextView::IsInSelection( const TextPaM& rPaM )
+{
+ TextSelection aSel = maSelection;
+ aSel.Justify();
+
+ ULONG nStartNode = aSel.GetStart().GetPara();
+ ULONG nEndNode = aSel.GetEnd().GetPara();
+ ULONG nCurNode = rPaM.GetPara();
+
+ if ( ( nCurNode > nStartNode ) && ( nCurNode < nEndNode ) )
+ return TRUE;
+
+ if ( nStartNode == nEndNode )
+ {
+ if ( nCurNode == nStartNode )
+ if ( ( rPaM.GetIndex() >= aSel.GetStart().GetIndex() ) && ( rPaM.GetIndex() < aSel.GetEnd().GetIndex() ) )
+ return TRUE;
+ }
+ else if ( ( nCurNode == nStartNode ) && ( rPaM.GetIndex() >= aSel.GetStart().GetIndex() ) )
+ return TRUE;
+ else if ( ( nCurNode == nEndNode ) && ( rPaM.GetIndex() < aSel.GetEnd().GetIndex() ) )
+ return TRUE;
+
+ return FALSE;
+}
+
+void TextView::ImpHideDDCursor()
+{
+ if ( mpDDInfo && mpDDInfo->mbVisCursor )
+ {
+ mpDDInfo->maCursor.Hide();
+ mpDDInfo->mbVisCursor = FALSE;
+ }
+}
+
+void TextView::ImpShowDDCursor()
+{
+ if ( !mpDDInfo->mbVisCursor )
+ {
+ Rectangle aCursor = mpTextEngine->PaMtoEditCursor( mpDDInfo->maDropPos, TRUE );
+ aCursor.Right()++;
+ aCursor.SetPos( GetWindowPos( aCursor.TopLeft() ) );
+
+ mpDDInfo->maCursor.SetWindow( mpWindow );
+ mpDDInfo->maCursor.SetPos( aCursor.TopLeft() );
+ mpDDInfo->maCursor.SetSize( aCursor.GetSize() );
+ mpDDInfo->maCursor.Show();
+ mpDDInfo->mbVisCursor = TRUE;
+ }
+}
+
+void TextView::BeginDrag()
+{
+ delete mpDDInfo;
+ mpDDInfo = new TextDDInfo;
+
+ mpDDInfo->mbStarterOfDD = TRUE;
+
+ DragServer::Clear();
+
+ TextSelection aSel( maSelection );
+ aSel.Justify();
+
+ // D&D eines Hyperlinks.
+ // Besser waere es im MBDown sich den MBDownPaM zu merken,
+ // ist dann aber inkompatibel => spaeter mal umstellen.
+ TextPaM aPaM( mpTextEngine->GetPaM( GetDocPos( GetWindow()->GetPointerPosPixel() ) ) );
+
+ const TextCharAttrib* pAttr = mpTextEngine->FindCharAttrib( aPaM, TEXTATTR_HYPERLINK );
+ if ( pAttr )
+ {
+ aSel = aPaM;
+ aSel.GetStart().GetIndex() = pAttr->GetStart();
+ aSel.GetEnd().GetIndex() = pAttr->GetEnd();
+
+ const TextAttribHyperLink& rLink = (const TextAttribHyperLink&)pAttr->GetAttr();
+ String aText( rLink.GetDescription() );
+ if ( !aText.Len() )
+ aText = mpTextEngine->GetText( aSel );
+ INetBookmark aBookmark( rLink.GetURL(), aText );
+ aBookmark.CopyDragServer();
+ }
+
+ DragServer::CopyString( mpTextEngine->GetText( aSel ) );
+
+ Region* pDDRegion = NULL;
+#ifdef MAC
+ // ... Region ermitteln
+ Size aOutSz = mpWindow->GetOutputSizePixel();
+ Rectangle aStartCursor( mpTextEngine->GetEditCursor( aSel.GetStart(), FALSE ) );
+ Rectangle aEndCursor( mpTextEngine->GetEditCursor( aSel.GetEnd(), TRUE ) );
+
+ Point aTopLeft = aStartCursor.TopLeft();
+ aTopLeft -= maStartDocPos;
+
+ Point aBottomRight = aStartCursor.BottomRight();
+ aBottomRight -= maStartDocPos;
+
+ if ( aStartCursor.Top() != aEndCursor.Top() )
+ {
+ // Dann einfach das Rechteck mit den kompletten Zeilem
+ aTopLeft.X() = 0;
+ aBottomRight.X() = aOutSz.Width();
+ }
+
+ pDDRegion = new Region( Rectangle( aTopLeft, aBottomRight ) );
+#endif
+
+ mpCursor->Hide();
+
+ mpWindow->ExecuteDrag( Pointer( POINTER_MOVEDATA ),
+ Pointer( POINTER_COPYDATA ), DRAG_ALL, pDDRegion );
+
+ DragServer::Clear();
+ ImpHideDDCursor();
+
+ delete mpDDInfo;
+ mpDDInfo = 0;
+}
+
+BOOL TextView::QueryDrop( DropEvent& rEvt )
+{
+ if ( rEvt.IsLeaveWindow() )
+ {
+ ImpHideDDCursor();
+ return FALSE;
+ }
+
+ BOOL bDrop = FALSE;
+ if ( !mbReadOnly && DragServer::HasFormat( 0, FORMAT_STRING ) &&
+ ( ( rEvt.GetAction() == DROP_COPY ) || ( rEvt.GetAction() == DROP_MOVE ) ) )
+ {
+ if ( !mpDDInfo )
+ mpDDInfo = new TextDDInfo;
+
+ TextPaM aPrevDropPos = mpDDInfo->maDropPos;
+ Point aDocPos = GetDocPos( rEvt.GetPosPixel() );
+ mpDDInfo->maDropPos = mpTextEngine->GetPaM( aDocPos );
+
+ Size aOutSize = mpWindow->GetOutputSizePixel();
+ if ( ( rEvt.GetPosPixel().X() < 0 ) || ( rEvt.GetPosPixel().X() > aOutSize.Width() ) ||
+ ( rEvt.GetPosPixel().Y() < 0 ) || ( rEvt.GetPosPixel().Y() > aOutSize.Height() ) )
+ {
+ // Scrollen ?
+ }
+
+ // Nicht in Selektion droppen:
+ if ( IsInSelection( mpDDInfo->maDropPos ) )
+ {
+ ImpHideDDCursor();
+ return FALSE;
+ }
+
+ // Alten Cursor wegzeichnen...
+ if ( !mpDDInfo->mbVisCursor || ( aPrevDropPos != mpDDInfo->maDropPos ) )
+ {
+ ImpHideDDCursor();
+ ImpShowDDCursor();
+ }
+ bDrop = TRUE;
+ }
+ return bDrop;
+}
+
+BOOL TextView::Drop( const DropEvent& rEvt )
+{
+ BOOL bDone = FALSE;
+ if ( !mbReadOnly && mpDDInfo )
+ {
+ ImpHideDDCursor();
+
+ // Daten fuer das loeschen nach einem DROP_MOVE:
+ TextSelection aPrevSel( maSelection );
+ aPrevSel.Justify();
+ ULONG nPrevParaCount = mpTextEngine->GetParagraphCount();
+ USHORT nPrevStartParaLen = mpTextEngine->GetTextLen( aPrevSel.GetStart().GetPara() );
+
+ BOOL bStarterOfDD = FALSE;
+ for ( USHORT nView = mpTextEngine->GetViewCount(); nView && !bStarterOfDD; )
+ bStarterOfDD = mpTextEngine->GetView( --nView )->mpDDInfo ? mpTextEngine->GetView( nView )->mpDDInfo->mbStarterOfDD : FALSE;
+
+ HideSelection();
+ maSelection = mpDDInfo->maDropPos;
+
+ mpTextEngine->UndoActionStart( TEXTUNDO_DRAGANDDROP );
+
+ String aText = DragServer::PasteString( 0 );
+ aText.ConvertLineEnd( LINEEND_LF );
+
+ if ( aText.Len() && ( aText.GetChar( aText.Len()-1 ) == LINE_SEP ) )
+ aText.Erase( aText.Len()-1 );
+
+ if ( ImplCheckTextLen( aText ) )
+ maSelection = mpTextEngine->ImpInsertText( mpDDInfo->maDropPos, aText );
+
+ if ( aPrevSel.HasRange() &&
+ ( rEvt.GetAction() == DROP_MOVE ) || !bStarterOfDD )
+ {
+ // ggf. Selection anpasssen:
+ if ( ( mpDDInfo->maDropPos.GetPara() < aPrevSel.GetStart().GetPara() ) ||
+ ( ( mpDDInfo->maDropPos.GetPara() == aPrevSel.GetStart().GetPara() )
+ && ( mpDDInfo->maDropPos.GetIndex() < aPrevSel.GetStart().GetIndex() ) ) )
+ {
+ ULONG nNewParasBeforeSelection =
+ mpTextEngine->GetParagraphCount() - nPrevParaCount;
+
+ aPrevSel.GetStart().GetPara() += nNewParasBeforeSelection;
+ aPrevSel.GetEnd().GetPara() += nNewParasBeforeSelection;
+
+ if ( mpDDInfo->maDropPos.GetPara() == aPrevSel.GetStart().GetPara() )
+ {
+ USHORT nNewChars =
+ mpTextEngine->GetTextLen( aPrevSel.GetStart().GetPara() ) - nPrevStartParaLen;
+
+ aPrevSel.GetStart().GetIndex() += nNewChars;
+ if ( aPrevSel.GetStart().GetPara() == aPrevSel.GetEnd().GetPara() )
+ aPrevSel.GetEnd().GetIndex() += nNewChars;
+ }
+ }
+ else
+ {
+ // aktuelle Selektion anpassen
+ TextPaM aPaM = maSelection.GetStart();
+ aPaM.GetPara() -= ( aPrevSel.GetEnd().GetPara() - aPrevSel.GetStart().GetPara() );
+ if ( aPrevSel.GetEnd().GetPara() == mpDDInfo->maDropPos.GetPara() )
+ {
+ aPaM.GetIndex() -= aPrevSel.GetEnd().GetIndex();
+ if ( aPrevSel.GetStart().GetPara() == mpDDInfo->maDropPos.GetPara() )
+ aPaM.GetIndex() += aPrevSel.GetStart().GetIndex();
+ }
+ maSelection = aPaM;
+
+ }
+ mpTextEngine->ImpDeleteText( aPrevSel );
+ }
+
+ mpTextEngine->UndoActionEnd( TEXTUNDO_DRAGANDDROP );
+
+ delete mpDDInfo;
+ mpDDInfo = 0;
+
+ mpTextEngine->FormatAndUpdate( this );
+
+ mpTextEngine->Broadcast( TextHint( TEXT_HINT_MODIFIED ) );
+ }
+
+ return bDone;
+}
+
+void TextView::SetPaintSelection( BOOL bPaint )
+{
+ if ( bPaint != mbPaintSelection )
+ {
+ mbPaintSelection = bPaint;
+ ShowSelection( maSelection );
+ }
+}
+
+void TextView::SetHighlightSelection( BOOL bSelectByHighlight )
+{
+ if ( bSelectByHighlight != mbHighlightSelection )
+ {
+ // Falls umschalten zwischendurch moeglich...
+ mbHighlightSelection = bSelectByHighlight;
+ }
+}
+
+BOOL TextView::Read( SvStream& rInput )
+{
+ BOOL bDone = mpTextEngine->Read( rInput, &maSelection );
+ ShowCursor();
+ return bDone;
+}
+
+BOOL TextView::Write( SvStream& rOutput )
+{
+ return mpTextEngine->Read( rOutput, &maSelection );
+}
+
+BOOL TextView::ImplCheckTextLen( const String& rNewText )
+{
+ BOOL bOK = TRUE;
+ if ( mpTextEngine->GetMaxTextLen() )
+ {
+ ULONG n = mpTextEngine->GetTextLen();
+ n += rNewText.Len();
+ if ( n > mpTextEngine->GetMaxTextLen() )
+ {
+ // nur dann noch ermitteln, wie viel Text geloescht wird
+ n -= mpTextEngine->GetTextLen( maSelection );
+ if ( n > mpTextEngine->GetMaxTextLen() )
+ {
+ // Beep hat hier eigentlich nichts verloren, sondern lieber ein Hdl,
+ // aber so funktioniert es wenigstens in ME, BasicIDE, SourceView
+ Sound::Beep();
+ bOK = FALSE;
+ }
+ }
+ }
+ return bOK;
+}
+
+
+ // -------------------------------------------------------------------------
+// (+) class TextSelFunctionSet
+// -------------------------------------------------------------------------
+TextSelFunctionSet::TextSelFunctionSet( TextView* pView )
+{
+ mpView = pView;
+}
+
+void __EXPORT TextSelFunctionSet::BeginDrag()
+{
+ mpView->BeginDrag();
+}
+
+void __EXPORT TextSelFunctionSet::CreateAnchor()
+{
+// TextSelection aSel( mpView->GetSelection() );
+// aSel.GetStart() = aSel.GetEnd();
+// mpView->SetSelection( aSel );
+
+ // Es darf kein ShowCursor folgen:
+ mpView->HideSelection();
+ mpView->maSelection.GetStart() = mpView->maSelection.GetEnd();
+}
+
+BOOL __EXPORT TextSelFunctionSet::SetCursorAtPoint( const Point& rPointPixel, BOOL )
+{
+ return mpView->SetCursorAtPoint( rPointPixel );
+}
+
+BOOL __EXPORT TextSelFunctionSet::IsSelectionAtPoint( const Point& rPointPixel )
+{
+ return mpView->IsSelectionAtPoint( rPointPixel );
+}
+
+void __EXPORT TextSelFunctionSet::DeselectAll()
+{
+ CreateAnchor();
+}
+
+void __EXPORT TextSelFunctionSet::DeselectAtPoint( const Point& )
+{
+ // Nur bei Mehrfachselektion
+}
+
+void __EXPORT TextSelFunctionSet::DestroyAnchor()
+{
+ // Nur bei Mehrfachselektion
+}
+
diff --git a/svtools/source/edit/txtattr.cxx b/svtools/source/edit/txtattr.cxx
new file mode 100644
index 000000000000..d88a4afa64bd
--- /dev/null
+++ b/svtools/source/edit/txtattr.cxx
@@ -0,0 +1,157 @@
+/*************************************************************************
+ *
+ * $RCSfile: txtattr.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: hr $ $Date: 2000-09-18 16:58:58 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (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.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#include <txtattr.hxx>
+#include <vcl/font.hxx>
+
+
+
+
+TextAttrib::~TextAttrib()
+{
+}
+
+void TextAttrib::SetFont( Font& ) const
+{
+}
+
+TextAttrib* TextAttrib::Clone() const
+{
+ return NULL;
+}
+
+int TextAttrib::operator==( const TextAttrib& rAttr ) const
+{
+ return mnWhich == rAttr.mnWhich;
+}
+
+
+TextAttribFontColor::TextAttribFontColor( const Color& rColor )
+ : TextAttrib( TEXTATTR_FONTCOLOR ), maColor( rColor )
+{
+}
+
+TextAttribFontColor::TextAttribFontColor( const TextAttribFontColor& rAttr )
+ : TextAttrib( rAttr ), maColor( rAttr.maColor )
+{
+}
+
+TextAttribFontColor::~TextAttribFontColor()
+{
+}
+
+void TextAttribFontColor::SetFont( Font& rFont ) const
+{
+ rFont.SetColor( maColor );
+}
+
+TextAttrib* TextAttribFontColor::Clone() const
+{
+ return new TextAttribFontColor( *this );
+}
+
+int TextAttribFontColor::operator==( const TextAttrib& rAttr ) const
+{
+ return ( ( TextAttrib::operator==(rAttr ) ) &&
+ ( maColor == ((const TextAttribFontColor&)rAttr).maColor ) );
+}
+
+
+TextAttribHyperLink::TextAttribHyperLink( const XubString& rURL )
+ : TextAttrib( TEXTATTR_HYPERLINK ), maURL( rURL )
+{
+ maColor = COL_BLUE;
+}
+
+TextAttribHyperLink::TextAttribHyperLink( const XubString& rURL, const XubString& rDescription )
+ : TextAttrib( TEXTATTR_HYPERLINK ), maURL( rURL ), maDescription( rDescription )
+{
+ maColor = COL_BLUE;
+}
+
+TextAttribHyperLink::TextAttribHyperLink( const TextAttribHyperLink& rAttr )
+ : TextAttrib( rAttr ), maURL( rAttr.maURL ), maDescription( rAttr.maDescription )
+{
+ maColor = rAttr.maColor;
+}
+
+TextAttribHyperLink::~TextAttribHyperLink()
+{
+}
+
+void TextAttribHyperLink::SetFont( Font& rFont ) const
+{
+ rFont.SetColor( maColor );
+ rFont.SetUnderline( UNDERLINE_SINGLE );
+}
+
+TextAttrib* TextAttribHyperLink::Clone() const
+{
+ return new TextAttribHyperLink( *this );
+}
+
+int TextAttribHyperLink::operator==( const TextAttrib& rAttr ) const
+{
+ return ( ( TextAttrib::operator==(rAttr ) ) &&
+ ( maURL == ((const TextAttribHyperLink&)rAttr).maURL ) &&
+ ( maDescription == ((const TextAttribHyperLink&)rAttr).maDescription ) &&
+ ( maColor == ((const TextAttribHyperLink&)rAttr).maColor ) );
+}
diff --git a/svtools/source/edit/xtextedt.cxx b/svtools/source/edit/xtextedt.cxx
new file mode 100644
index 000000000000..0203f0727f02
--- /dev/null
+++ b/svtools/source/edit/xtextedt.cxx
@@ -0,0 +1,444 @@
+/*************************************************************************
+ *
+ * $RCSfile: xtextedt.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: hr $ $Date: 2000-09-18 16:58:58 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (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.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#include <xtextedt.hxx>
+#include <txtcmp.hxx>
+#include <vcl/svapp.hxx> // International
+
+ // -------------------------------------------------------------------------
+// class ExtTextEngine
+// -------------------------------------------------------------------------
+ExtTextEngine::ExtTextEngine() : maGroupChars( String::CreateFromAscii( "(){}[]", 6 ) )
+{
+}
+
+ExtTextEngine::~ExtTextEngine()
+{
+}
+
+TextSelection ExtTextEngine::MatchGroup( const TextPaM& rCursor ) const
+{
+ TextSelection aSel( rCursor );
+ USHORT nPos = rCursor.GetIndex();
+ ULONG nPara = rCursor.GetPara();
+ ULONG nParas = GetParagraphCount();
+ if ( ( nPara < nParas ) && ( nPos < GetTextLen( nPara ) ) )
+ {
+ USHORT nMatchChar = maGroupChars.Search( GetText( rCursor.GetPara() ).GetChar( nPos ) );
+ if ( nMatchChar != STRING_NOTFOUND )
+ {
+ if ( ( nMatchChar % 2 ) == 0 )
+ {
+ // Vorwaerts suchen...
+ sal_Unicode nSC = maGroupChars.GetChar( nMatchChar );
+ sal_Unicode nEC = maGroupChars.GetChar( nMatchChar+1 );
+
+ USHORT nCur = nPos+1;
+ USHORT nLevel = 1;
+ while ( nLevel && ( nPara < nParas ) )
+ {
+ XubString aStr = GetText( nPara );
+ while ( nCur < aStr.Len() )
+ {
+ if ( aStr.GetChar( nCur ) == nSC )
+ nLevel++;
+ else if ( aStr.GetChar( nCur ) == nEC )
+ {
+ nLevel--;
+ if ( !nLevel )
+ break; // while nCur...
+ }
+ nCur++;
+ }
+
+ if ( nLevel )
+ {
+ nPara++;
+ nCur = 0;
+ }
+ }
+ if ( nLevel == 0 ) // gefunden
+ {
+ aSel.GetStart() = rCursor;
+ aSel.GetEnd() = TextPaM( nPara, nCur+1 );
+ }
+ }
+ else
+ {
+ // Rueckwaerts suchen...
+ xub_Unicode nEC = maGroupChars.GetChar( nMatchChar );
+ xub_Unicode nSC = maGroupChars.GetChar( nMatchChar-1 );
+
+ USHORT nCur = rCursor.GetIndex()-1;
+ USHORT nLevel = 1;
+ while ( nLevel )
+ {
+ if ( GetTextLen( nPara ) )
+ {
+ XubString aStr = GetText( nPara );
+ while ( nCur )
+ {
+ if ( aStr.GetChar( nCur ) == nSC )
+ {
+ nLevel--;
+ if ( !nLevel )
+ break; // while nCur...
+ }
+ else if ( aStr.GetChar( nCur ) == nEC )
+ nLevel++;
+
+ nCur--;
+ }
+ }
+
+ if ( nLevel )
+ {
+ if ( nPara )
+ {
+ nPara--;
+ nCur = GetTextLen( nPara )-1; // egal ob negativ, weil if Len()
+ }
+ else
+ break;
+ }
+ }
+
+ if ( nLevel == 0 ) // gefunden
+ {
+ aSel.GetStart() = rCursor;
+ aSel.GetStart().GetIndex()++; // hinter das Zeichen
+ aSel.GetEnd() = TextPaM( nPara, nCur );
+ }
+ }
+ }
+ }
+ return aSel;
+}
+
+BOOL ExtTextEngine::Search( TextSelection& rSel, const SearchParam& rSearchParam, BOOL bForward )
+{
+ TextSelection aSel( rSel );
+ aSel.Justify();
+
+ TextPaM aStartPaM( aSel.GetEnd() );
+ if ( aSel.HasRange() && (
+ ( rSearchParam.IsSrchInSelection() && bForward ) ||
+ ( !rSearchParam.IsSrchInSelection() && !bForward ) ) )
+ {
+ aStartPaM = aSel.GetStart();
+ }
+
+ BOOL bFound = FALSE;
+ ULONG nStartNode, nEndNode;
+
+ if ( rSearchParam.IsSrchInSelection() )
+ nEndNode = bForward ? aSel.GetEnd().GetPara() : aSel.GetStart().GetPara();
+ else
+ nEndNode = bForward ? (GetParagraphCount()-1) : 0;
+
+ nStartNode = aStartPaM.GetPara();
+ SearchText aSearcher( rSearchParam, Application::GetAppInternational() );
+
+ // ueber die Absaetze iterieren...
+ for ( ULONG nNode = nStartNode;
+ bForward ? ( nNode <= nEndNode) : ( nNode >= nEndNode );
+ bForward ? nNode++ : nNode-- )
+ {
+ String aText = GetText( nNode );
+ USHORT nStartPos = 0;
+ USHORT nEndPos = aText.Len();
+ if ( nNode == nStartNode )
+ {
+ if ( bForward )
+ nStartPos = aStartPaM.GetIndex();
+ else
+ nEndPos = aStartPaM.GetIndex();
+ }
+ if ( ( nNode == nEndNode ) && rSearchParam.IsSrchInSelection() )
+ {
+ if ( bForward )
+ nEndPos = aSel.GetEnd().GetIndex();
+ else
+ nStartPos = aSel.GetStart().GetIndex();
+ }
+
+ if ( bForward )
+ bFound = aSearcher.SearchFrwrd( aText, &nStartPos, &nEndPos );
+ else
+ bFound = aSearcher.SearchBkwrd( aText, &nEndPos, &nStartPos );
+
+ if ( bFound )
+ {
+ rSel.GetStart().GetPara() = nNode;
+ rSel.GetStart().GetIndex() = nStartPos;
+ rSel.GetEnd().GetPara() = nNode;
+ rSel.GetEnd().GetIndex() = nEndPos;
+ // Ueber den Absatz selektieren?
+ if( nStartPos == (USHORT)(nEndPos+1) ) // USHORT fuer 0 und -1 !
+ {
+ if ( (rSel.GetEnd().GetPara()+1) < GetParagraphCount() )
+ {
+ rSel.GetEnd().GetPara()++;
+ rSel.GetEnd().GetIndex() = 0;
+ }
+ else
+ {
+ rSel.GetEnd().GetIndex() = nStartPos;
+ bFound = FALSE;
+ }
+ }
+ else if ( bForward && ( rSel.GetEnd().GetIndex() < aText.Len() ) )
+ rSel.GetEnd().GetIndex()++;
+ else if ( !bForward && ( rSel.GetStart().GetIndex() < aText.Len() ) )
+ rSel.GetStart().GetIndex()++;
+
+ break;
+ }
+
+ if ( !bForward && !nNode ) // Bei rueckwaertsuche, wenn nEndNode = 0:
+ break;
+ }
+
+ return bFound;
+}
+
+
+ // -------------------------------------------------------------------------
+// class ExtTextView
+// -------------------------------------------------------------------------
+ExtTextView::ExtTextView( ExtTextEngine* pEng, Window* pWindow )
+ : TextView( pEng, pWindow )
+{
+}
+
+ExtTextView::~ExtTextView()
+{
+}
+
+BOOL ExtTextView::MatchGroup()
+{
+ TextSelection aTmpSel( GetSelection() );
+ aTmpSel.Justify();
+ if ( ( aTmpSel.GetStart().GetPara() != aTmpSel.GetEnd().GetPara() ) ||
+ ( ( aTmpSel.GetEnd().GetIndex() - aTmpSel.GetStart().GetIndex() ) > 1 ) )
+ {
+ return FALSE;
+ }
+
+ TextSelection aMatchSel = ((ExtTextEngine*)GetTextEngine())->MatchGroup( aTmpSel.GetStart() );
+ if ( aMatchSel.HasRange() )
+ SetSelection( aMatchSel );
+
+ return aMatchSel.HasRange() ? TRUE : FALSE;
+}
+
+BOOL ExtTextView::Search( const SearchParam& rSearchParam, BOOL bForward )
+{
+ BOOL bFound = FALSE;
+ TextSelection aSel( GetSelection() );
+ if ( ((ExtTextEngine*)GetTextEngine())->Search( aSel, rSearchParam, bForward ) )
+ {
+ bFound = TRUE;
+ // Erstmal den Anfang des Wortes als Selektion einstellen,
+ // damit das ganze Wort in den sichtbaren Bereich kommt.
+ SetSelection( aSel.GetStart() );
+ ShowCursor( TRUE, FALSE );
+ }
+ else
+ {
+ aSel = GetSelection().GetEnd();
+ }
+
+ SetSelection( aSel );
+ ShowCursor();
+
+ return bFound;
+}
+
+USHORT ExtTextView::Replace( const SearchParam& rSearchParam, BOOL bAll, BOOL bForward )
+{
+ USHORT nFound = 0;
+
+ if ( !bAll )
+ {
+ if ( GetSelection().HasRange() )
+ {
+ InsertText( rSearchParam.GetReplaceStr() );
+ nFound = 1;
+ Search( rSearchParam, bForward ); // gleich zum naechsten
+ }
+ else
+ {
+ if( Search( rSearchParam, bForward ) )
+ nFound = 1;
+ }
+ }
+ else
+ {
+ // Der Writer ersetzt alle, vom Anfang bis Ende...
+
+ ExtTextEngine* pTextEngine = (ExtTextEngine*)GetTextEngine();
+
+ // HideSelection();
+ TextSelection aSel;
+ if ( rSearchParam.IsSrchInSelection() )
+ {
+ aSel = GetSelection();
+ aSel.Justify();
+ }
+
+ TextSelection aSearchSel( aSel );
+
+ BOOL bFound = pTextEngine->Search( aSel, rSearchParam, TRUE );
+ if ( bFound )
+ pTextEngine->UndoActionStart( XTEXTUNDO_REPLACEALL );
+ while ( bFound )
+ {
+ nFound++;
+
+ TextPaM aNewStart = pTextEngine->ImpInsertText( aSel, rSearchParam.GetReplaceStr() );
+ aSel = aSearchSel;
+ aSel.GetStart() = aNewStart;
+ bFound = pTextEngine->Search( aSel, rSearchParam, TRUE );
+ }
+ if ( nFound )
+ {
+ SetSelection( aSel.GetStart() );
+ pTextEngine->FormatAndUpdate( this );
+ pTextEngine->UndoActionEnd( XTEXTUNDO_REPLACEALL );
+ }
+ }
+ return nFound;
+}
+
+BOOL ExtTextView::ImpIndentBlock( BOOL bRight )
+{
+ BOOL bDone = FALSE;
+
+ TextSelection aSel = GetSelection();
+ aSel.Justify();
+
+ HideSelection();
+ GetTextEngine()->UndoActionStart( bRight ? XTEXTUNDO_INDENTBLOCK : XTEXTUNDO_UNINDENTBLOCK );
+
+ ULONG nStartPara = aSel.GetStart().GetPara();
+ ULONG nEndPara = aSel.GetEnd().GetPara();
+ BOOL bIndentAll = TRUE;
+ if ( aSel.HasRange() && !aSel.GetEnd().GetIndex() )
+ {
+ nEndPara--; // den dann nicht einruecken...
+ }
+
+ for ( ULONG nPara = nStartPara; nPara <= nEndPara; nPara++ )
+ {
+ if ( bRight )
+ {
+ // Tabs hinzufuegen
+ GetTextEngine()->ImpInsertText( TextPaM( nPara, 0 ), '\t' );
+ bDone = TRUE;
+ }
+ else
+ {
+ // Tabs/Blanks entfernen
+ String aText = GetTextEngine()->GetText( nPara );
+ if ( aText.Len() && (
+ ( aText.GetChar( 0 ) == '\t' ) ||
+ ( aText.GetChar( 0 ) == ' ' ) ) )
+ {
+ GetTextEngine()->ImpDeleteText( TextSelection( TextPaM( nPara, 0 ), TextPaM( nPara, 1 ) ) );
+ bDone = TRUE;
+ }
+ }
+ }
+
+ GetTextEngine()->UndoActionEnd( bRight ? XTEXTUNDO_INDENTBLOCK : XTEXTUNDO_UNINDENTBLOCK );
+
+ BOOL bRange = aSel.HasRange();
+ if ( bRight )
+ {
+ aSel.GetStart().GetIndex()++;
+ if ( bRange && ( aSel.GetEnd().GetPara() == nEndPara ) )
+ aSel.GetEnd().GetIndex()++;
+ }
+ else
+ {
+ if ( aSel.GetStart().GetIndex() )
+ aSel.GetStart().GetIndex()--;
+ if ( bRange && aSel.GetEnd().GetIndex() )
+ aSel.GetEnd().GetIndex()--;
+ }
+
+ maSelection = aSel;
+ GetTextEngine()->FormatAndUpdate( this );
+
+ return bDone;
+}
+
+BOOL ExtTextView::IndentBlock()
+{
+ return ImpIndentBlock( TRUE );
+}
+
+BOOL ExtTextView::UnindentBlock()
+{
+ return ImpIndentBlock( FALSE );
+}
+