15900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
35900e8ecSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
45900e8ecSAndrew Rist * or more contributor license agreements. See the NOTICE file
55900e8ecSAndrew Rist * distributed with this work for additional information
65900e8ecSAndrew Rist * regarding copyright ownership. The ASF licenses this file
75900e8ecSAndrew Rist * to you under the Apache License, Version 2.0 (the
85900e8ecSAndrew Rist * "License"); you may not use this file except in compliance
95900e8ecSAndrew Rist * with the License. You may obtain a copy of the License at
105900e8ecSAndrew Rist *
115900e8ecSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
125900e8ecSAndrew Rist *
135900e8ecSAndrew Rist * Unless required by applicable law or agreed to in writing,
145900e8ecSAndrew Rist * software distributed under the License is distributed on an
155900e8ecSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165900e8ecSAndrew Rist * KIND, either express or implied. See the License for the
175900e8ecSAndrew Rist * specific language governing permissions and limitations
185900e8ecSAndrew Rist * under the License.
195900e8ecSAndrew Rist *
205900e8ecSAndrew Rist *************************************************************/
215900e8ecSAndrew Rist
225900e8ecSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir #include <svtools/textview.hxx>
27cdf0e10cSrcweir #include <svtools/texteng.hxx>
28cdf0e10cSrcweir #include <textdoc.hxx>
29cdf0e10cSrcweir #include <svtools/textdata.hxx>
30cdf0e10cSrcweir #include <textdat2.hxx>
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include <svl/undo.hxx>
33cdf0e10cSrcweir #include <vcl/cursor.hxx>
34cdf0e10cSrcweir #include <vcl/window.hxx>
35cdf0e10cSrcweir #include <vcl/svapp.hxx>
36cdf0e10cSrcweir #include <vcl/sound.hxx>
37cdf0e10cSrcweir #include <tools/stream.hxx>
38cdf0e10cSrcweir
39cdf0e10cSrcweir #include <sot/formats.hxx>
40cdf0e10cSrcweir #include <svl/urlbmk.hxx>
41cdf0e10cSrcweir
42cdf0e10cSrcweir #ifndef _COM_SUN_STAR_TEXT_XBREAKITERATOR_HPP_
43cdf0e10cSrcweir #include <com/sun/star/i18n/XBreakIterator.hpp>
44cdf0e10cSrcweir #endif
45cdf0e10cSrcweir
46cdf0e10cSrcweir #ifndef _COM_SUN_STAR_TEXT_CHARACTERITERATORMODE_HPP_
47cdf0e10cSrcweir #include <com/sun/star/i18n/CharacterIteratorMode.hpp>
48cdf0e10cSrcweir #endif
49cdf0e10cSrcweir
50cdf0e10cSrcweir #ifndef _COM_SUN_STAR_TEXT_WORDTYPE_HPP_
51cdf0e10cSrcweir #include <com/sun/star/i18n/WordType.hpp>
52cdf0e10cSrcweir #endif
53cdf0e10cSrcweir #include <cppuhelper/weak.hxx>
54cdf0e10cSrcweir #include <vcl/unohelp.hxx>
55cdf0e10cSrcweir #include <com/sun/star/datatransfer/XTransferable.hpp>
56cdf0e10cSrcweir #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
57cdf0e10cSrcweir #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
58cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
59cdf0e10cSrcweir
60cdf0e10cSrcweir #ifndef _COM_SUN_STAR_DATATRANSFER_DND_DNDCONSTANS_HPP_
61cdf0e10cSrcweir #include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
62cdf0e10cSrcweir #endif
63cdf0e10cSrcweir #include <com/sun/star/datatransfer/dnd/XDragGestureRecognizer.hpp>
64cdf0e10cSrcweir #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
65cdf0e10cSrcweir
66cdf0e10cSrcweir #include <vcl/edit.hxx>
67cdf0e10cSrcweir
68cdf0e10cSrcweir
69cdf0e10cSrcweir #include <sot/exchange.hxx>
70cdf0e10cSrcweir #include <sot/formats.hxx>
71cdf0e10cSrcweir
72cdf0e10cSrcweir #include <vos/mutex.hxx>
73cdf0e10cSrcweir
74cdf0e10cSrcweir
75cdf0e10cSrcweir using namespace ::com::sun::star;
76cdf0e10cSrcweir
77cdf0e10cSrcweir class TETextDataObject : public ::com::sun::star::datatransfer::XTransferable,
78cdf0e10cSrcweir public ::cppu::OWeakObject
79cdf0e10cSrcweir
80cdf0e10cSrcweir {
81cdf0e10cSrcweir private:
82cdf0e10cSrcweir String maText;
83cdf0e10cSrcweir SvMemoryStream maHTMLStream;
84cdf0e10cSrcweir
85cdf0e10cSrcweir public:
86cdf0e10cSrcweir TETextDataObject( const String& rText );
87cdf0e10cSrcweir ~TETextDataObject();
88cdf0e10cSrcweir
GetText()89cdf0e10cSrcweir String& GetText() { return maText; }
GetHTMLStream()90cdf0e10cSrcweir SvMemoryStream& GetHTMLStream() { return maHTMLStream; }
91cdf0e10cSrcweir
92cdf0e10cSrcweir // ::com::sun::star::uno::XInterface
93cdf0e10cSrcweir ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException);
acquire()94cdf0e10cSrcweir void SAL_CALL acquire() throw() { OWeakObject::acquire(); }
release()95cdf0e10cSrcweir void SAL_CALL release() throw() { OWeakObject::release(); }
96cdf0e10cSrcweir
97cdf0e10cSrcweir // ::com::sun::star::datatransfer::XTransferable
98cdf0e10cSrcweir ::com::sun::star::uno::Any SAL_CALL getTransferData( const ::com::sun::star::datatransfer::DataFlavor& aFlavor ) throw(::com::sun::star::datatransfer::UnsupportedFlavorException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
99cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::datatransfer::DataFlavor > SAL_CALL getTransferDataFlavors( ) throw(::com::sun::star::uno::RuntimeException);
100cdf0e10cSrcweir sal_Bool SAL_CALL isDataFlavorSupported( const ::com::sun::star::datatransfer::DataFlavor& aFlavor ) throw(::com::sun::star::uno::RuntimeException);
101cdf0e10cSrcweir };
102cdf0e10cSrcweir
TETextDataObject(const String & rText)103cdf0e10cSrcweir TETextDataObject::TETextDataObject( const String& rText ) : maText( rText )
104cdf0e10cSrcweir {
105cdf0e10cSrcweir }
106cdf0e10cSrcweir
~TETextDataObject()107cdf0e10cSrcweir TETextDataObject::~TETextDataObject()
108cdf0e10cSrcweir {
109cdf0e10cSrcweir }
110cdf0e10cSrcweir
111cdf0e10cSrcweir // uno::XInterface
queryInterface(const uno::Type & rType)112cdf0e10cSrcweir uno::Any TETextDataObject::queryInterface( const uno::Type & rType ) throw(uno::RuntimeException)
113cdf0e10cSrcweir {
114cdf0e10cSrcweir uno::Any aRet = ::cppu::queryInterface( rType, SAL_STATIC_CAST( datatransfer::XTransferable*, this ) );
115cdf0e10cSrcweir return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ));
116cdf0e10cSrcweir }
117cdf0e10cSrcweir
118cdf0e10cSrcweir // datatransfer::XTransferable
getTransferData(const datatransfer::DataFlavor & rFlavor)119cdf0e10cSrcweir uno::Any TETextDataObject::getTransferData( const datatransfer::DataFlavor& rFlavor ) throw(datatransfer::UnsupportedFlavorException, io::IOException, uno::RuntimeException)
120cdf0e10cSrcweir {
121cdf0e10cSrcweir uno::Any aAny;
122cdf0e10cSrcweir
123cdf0e10cSrcweir sal_uLong nT = SotExchange::GetFormat( rFlavor );
124cdf0e10cSrcweir if ( nT == SOT_FORMAT_STRING )
125cdf0e10cSrcweir {
126cdf0e10cSrcweir aAny <<= (::rtl::OUString)GetText();
127cdf0e10cSrcweir }
128cdf0e10cSrcweir else if ( nT == SOT_FORMATSTR_ID_HTML )
129cdf0e10cSrcweir {
130cdf0e10cSrcweir GetHTMLStream().Seek( STREAM_SEEK_TO_END );
131cdf0e10cSrcweir sal_uLong nLen = GetHTMLStream().Tell();
132cdf0e10cSrcweir GetHTMLStream().Seek(0);
133cdf0e10cSrcweir
134cdf0e10cSrcweir uno::Sequence< sal_Int8 > aSeq( nLen );
135cdf0e10cSrcweir memcpy( aSeq.getArray(), GetHTMLStream().GetData(), nLen );
136cdf0e10cSrcweir aAny <<= aSeq;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir else
139cdf0e10cSrcweir {
140cdf0e10cSrcweir throw datatransfer::UnsupportedFlavorException();
141cdf0e10cSrcweir }
142cdf0e10cSrcweir return aAny;
143cdf0e10cSrcweir }
144cdf0e10cSrcweir
getTransferDataFlavors()145cdf0e10cSrcweir uno::Sequence< datatransfer::DataFlavor > TETextDataObject::getTransferDataFlavors( ) throw(uno::RuntimeException)
146cdf0e10cSrcweir {
147cdf0e10cSrcweir GetHTMLStream().Seek( STREAM_SEEK_TO_END );
148cdf0e10cSrcweir sal_Bool bHTML = GetHTMLStream().Tell() > 0;
149cdf0e10cSrcweir uno::Sequence< datatransfer::DataFlavor > aDataFlavors( bHTML ? 2 : 1 );
150cdf0e10cSrcweir SotExchange::GetFormatDataFlavor( SOT_FORMAT_STRING, aDataFlavors.getArray()[0] );
151cdf0e10cSrcweir if ( bHTML )
152cdf0e10cSrcweir SotExchange::GetFormatDataFlavor( SOT_FORMATSTR_ID_HTML, aDataFlavors.getArray()[1] );
153cdf0e10cSrcweir return aDataFlavors;
154cdf0e10cSrcweir }
155cdf0e10cSrcweir
isDataFlavorSupported(const datatransfer::DataFlavor & rFlavor)156cdf0e10cSrcweir sal_Bool TETextDataObject::isDataFlavorSupported( const datatransfer::DataFlavor& rFlavor ) throw(uno::RuntimeException)
157cdf0e10cSrcweir {
158cdf0e10cSrcweir sal_uLong nT = SotExchange::GetFormat( rFlavor );
159cdf0e10cSrcweir return ( nT == SOT_FORMAT_STRING );
160cdf0e10cSrcweir }
161cdf0e10cSrcweir
162cdf0e10cSrcweir /*-- 24.06.2004 13:54:36---------------------------------------------------
163cdf0e10cSrcweir
164cdf0e10cSrcweir -----------------------------------------------------------------------*/
165cdf0e10cSrcweir struct ImpTextView
166cdf0e10cSrcweir {
167cdf0e10cSrcweir TextEngine* mpTextEngine;
168cdf0e10cSrcweir
169cdf0e10cSrcweir Window* mpWindow;
170cdf0e10cSrcweir TextSelection maSelection;
171cdf0e10cSrcweir Point maStartDocPos;
172cdf0e10cSrcweir // TextPaM maMBDownPaM;
173cdf0e10cSrcweir
174cdf0e10cSrcweir Cursor* mpCursor;
175cdf0e10cSrcweir
176cdf0e10cSrcweir TextDDInfo* mpDDInfo;
177cdf0e10cSrcweir
178cdf0e10cSrcweir VirtualDevice* mpVirtDev;
179cdf0e10cSrcweir
180cdf0e10cSrcweir SelectionEngine* mpSelEngine;
181cdf0e10cSrcweir TextSelFunctionSet* mpSelFuncSet;
182cdf0e10cSrcweir
183cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragSourceListener > mxDnDListener;
184cdf0e10cSrcweir
185cdf0e10cSrcweir sal_uInt16 mnTravelXPos;
186cdf0e10cSrcweir
187cdf0e10cSrcweir sal_Bool mbAutoScroll : 1;
188cdf0e10cSrcweir sal_Bool mbInsertMode : 1;
189cdf0e10cSrcweir sal_Bool mbReadOnly : 1;
190cdf0e10cSrcweir sal_Bool mbPaintSelection : 1;
191cdf0e10cSrcweir sal_Bool mbAutoIndent : 1;
192cdf0e10cSrcweir sal_Bool mbHighlightSelection : 1;
193cdf0e10cSrcweir sal_Bool mbCursorEnabled : 1;
194cdf0e10cSrcweir sal_Bool mbClickedInSelection : 1;
195cdf0e10cSrcweir sal_Bool mbSupportProtectAttribute : 1;
196cdf0e10cSrcweir bool mbCursorAtEndOfLine;
197cdf0e10cSrcweir };
198cdf0e10cSrcweir
199cdf0e10cSrcweir // -------------------------------------------------------------------------
200cdf0e10cSrcweir // (+) class TextView
201cdf0e10cSrcweir // -------------------------------------------------------------------------
TextView(TextEngine * pEng,Window * pWindow)202cdf0e10cSrcweir TextView::TextView( TextEngine* pEng, Window* pWindow ) :
203cdf0e10cSrcweir mpImpl(new ImpTextView)
204cdf0e10cSrcweir {
205cdf0e10cSrcweir pWindow->EnableRTL( sal_False );
206cdf0e10cSrcweir
207cdf0e10cSrcweir mpImpl->mpWindow = pWindow;
208cdf0e10cSrcweir mpImpl->mpTextEngine = pEng;
209cdf0e10cSrcweir mpImpl->mpVirtDev = NULL;
210cdf0e10cSrcweir
211cdf0e10cSrcweir mpImpl->mbPaintSelection = sal_True;
212cdf0e10cSrcweir mpImpl->mbAutoScroll = sal_True;
213cdf0e10cSrcweir mpImpl->mbInsertMode = sal_True;
214cdf0e10cSrcweir mpImpl->mbReadOnly = sal_False;
215cdf0e10cSrcweir mpImpl->mbHighlightSelection = sal_False;
216cdf0e10cSrcweir mpImpl->mbAutoIndent = sal_False;
217cdf0e10cSrcweir mpImpl->mbCursorEnabled = sal_True;
218cdf0e10cSrcweir mpImpl->mbClickedInSelection = sal_False;
219cdf0e10cSrcweir mpImpl->mbSupportProtectAttribute = sal_False;
220cdf0e10cSrcweir mpImpl->mbCursorAtEndOfLine = false;
221cdf0e10cSrcweir // mbInSelection = sal_False;
222cdf0e10cSrcweir
223cdf0e10cSrcweir mpImpl->mnTravelXPos = TRAVEL_X_DONTKNOW;
224cdf0e10cSrcweir
225cdf0e10cSrcweir mpImpl->mpSelFuncSet = new TextSelFunctionSet( this );
226cdf0e10cSrcweir mpImpl->mpSelEngine = new SelectionEngine( mpImpl->mpWindow, mpImpl->mpSelFuncSet );
227cdf0e10cSrcweir mpImpl->mpSelEngine->SetSelectionMode( RANGE_SELECTION );
228cdf0e10cSrcweir mpImpl->mpSelEngine->EnableDrag( sal_True );
229cdf0e10cSrcweir
230cdf0e10cSrcweir mpImpl->mpCursor = new Cursor;
231cdf0e10cSrcweir mpImpl->mpCursor->Show();
232cdf0e10cSrcweir pWindow->SetCursor( mpImpl->mpCursor );
233cdf0e10cSrcweir pWindow->SetInputContext( InputContext( pEng->GetFont(), INPUTCONTEXT_TEXT|INPUTCONTEXT_EXTTEXTINPUT ) );
234cdf0e10cSrcweir
235cdf0e10cSrcweir if ( pWindow->GetSettings().GetStyleSettings().GetSelectionOptions() & SELECTION_OPTION_INVERT )
236cdf0e10cSrcweir mpImpl->mbHighlightSelection = sal_True;
237cdf0e10cSrcweir
238cdf0e10cSrcweir pWindow->SetLineColor();
239cdf0e10cSrcweir
240cdf0e10cSrcweir mpImpl->mpDDInfo = NULL;
241cdf0e10cSrcweir
242cdf0e10cSrcweir if ( pWindow->GetDragGestureRecognizer().is() )
243cdf0e10cSrcweir {
244cdf0e10cSrcweir vcl::unohelper::DragAndDropWrapper* pDnDWrapper = new vcl::unohelper::DragAndDropWrapper( this );
245cdf0e10cSrcweir mpImpl->mxDnDListener = pDnDWrapper;
246cdf0e10cSrcweir
247cdf0e10cSrcweir uno::Reference< datatransfer::dnd::XDragGestureListener> xDGL( mpImpl->mxDnDListener, uno::UNO_QUERY );
248cdf0e10cSrcweir pWindow->GetDragGestureRecognizer()->addDragGestureListener( xDGL );
249cdf0e10cSrcweir uno::Reference< datatransfer::dnd::XDropTargetListener> xDTL( xDGL, uno::UNO_QUERY );
250cdf0e10cSrcweir pWindow->GetDropTarget()->addDropTargetListener( xDTL );
251cdf0e10cSrcweir pWindow->GetDropTarget()->setActive( sal_True );
252cdf0e10cSrcweir pWindow->GetDropTarget()->setDefaultActions( datatransfer::dnd::DNDConstants::ACTION_COPY_OR_MOVE );
253cdf0e10cSrcweir }
254cdf0e10cSrcweir }
255cdf0e10cSrcweir
~TextView()256cdf0e10cSrcweir TextView::~TextView()
257cdf0e10cSrcweir {
258cdf0e10cSrcweir delete mpImpl->mpSelEngine;
259cdf0e10cSrcweir delete mpImpl->mpSelFuncSet;
260cdf0e10cSrcweir delete mpImpl->mpVirtDev;
261cdf0e10cSrcweir
262cdf0e10cSrcweir if ( mpImpl->mpWindow->GetCursor() == mpImpl->mpCursor )
263cdf0e10cSrcweir mpImpl->mpWindow->SetCursor( 0 );
264cdf0e10cSrcweir delete mpImpl->mpCursor;
265cdf0e10cSrcweir delete mpImpl->mpDDInfo;
266cdf0e10cSrcweir delete mpImpl;
267cdf0e10cSrcweir }
268cdf0e10cSrcweir
Invalidate()269cdf0e10cSrcweir void TextView::Invalidate()
270cdf0e10cSrcweir {
271cdf0e10cSrcweir mpImpl->mpWindow->Invalidate();
272cdf0e10cSrcweir }
273cdf0e10cSrcweir
SetSelection(const TextSelection & rTextSel,sal_Bool bGotoCursor)274cdf0e10cSrcweir void TextView::SetSelection( const TextSelection& rTextSel, sal_Bool bGotoCursor )
275cdf0e10cSrcweir {
276cdf0e10cSrcweir // Falls jemand gerade ein leeres Attribut hinterlassen hat,
277cdf0e10cSrcweir // und dann der Outliner die Selektion manipulitert:
278cdf0e10cSrcweir if ( !mpImpl->maSelection.HasRange() )
279cdf0e10cSrcweir mpImpl->mpTextEngine->CursorMoved( mpImpl->maSelection.GetStart().GetPara() );
280cdf0e10cSrcweir
281cdf0e10cSrcweir // Wenn nach einem KeyInput die Selection manipuliert wird:
282cdf0e10cSrcweir mpImpl->mpTextEngine->CheckIdleFormatter();
283cdf0e10cSrcweir
284cdf0e10cSrcweir HideSelection();
285cdf0e10cSrcweir TextSelection aNewSel( rTextSel );
286cdf0e10cSrcweir mpImpl->mpTextEngine->ValidateSelection( aNewSel );
287cdf0e10cSrcweir ImpSetSelection( aNewSel );
288cdf0e10cSrcweir ShowSelection();
289cdf0e10cSrcweir ShowCursor( bGotoCursor );
290cdf0e10cSrcweir }
291cdf0e10cSrcweir
SetSelection(const TextSelection & rTextSel)292cdf0e10cSrcweir void TextView::SetSelection( const TextSelection& rTextSel )
293cdf0e10cSrcweir {
294cdf0e10cSrcweir SetSelection( rTextSel, mpImpl->mbAutoScroll );
295cdf0e10cSrcweir }
296cdf0e10cSrcweir
GetSelection() const297cdf0e10cSrcweir const TextSelection& TextView::GetSelection() const
298cdf0e10cSrcweir {
299cdf0e10cSrcweir return mpImpl->maSelection;
300cdf0e10cSrcweir }
GetSelection()301cdf0e10cSrcweir TextSelection& TextView::GetSelection()
302cdf0e10cSrcweir {
303cdf0e10cSrcweir return mpImpl->maSelection;
304cdf0e10cSrcweir }
305cdf0e10cSrcweir
DeleteSelected()306cdf0e10cSrcweir void TextView::DeleteSelected()
307cdf0e10cSrcweir {
308cdf0e10cSrcweir // HideSelection();
309cdf0e10cSrcweir
310cdf0e10cSrcweir mpImpl->mpTextEngine->UndoActionStart();
311cdf0e10cSrcweir TextPaM aPaM = mpImpl->mpTextEngine->ImpDeleteText( mpImpl->maSelection );
312cdf0e10cSrcweir mpImpl->mpTextEngine->UndoActionEnd();
313cdf0e10cSrcweir
314cdf0e10cSrcweir ImpSetSelection( aPaM );
315cdf0e10cSrcweir mpImpl->mpTextEngine->FormatAndUpdate( this );
316cdf0e10cSrcweir ShowCursor();
317cdf0e10cSrcweir }
318cdf0e10cSrcweir
ImpPaint(OutputDevice * pOut,const Point & rStartPos,Rectangle const * pPaintArea,TextSelection const * pPaintRange,TextSelection const * pSelection)319cdf0e10cSrcweir void TextView::ImpPaint( OutputDevice* pOut, const Point& rStartPos, Rectangle const* pPaintArea, TextSelection const* pPaintRange, TextSelection const* pSelection )
320cdf0e10cSrcweir {
321cdf0e10cSrcweir if ( !mpImpl->mbPaintSelection )
322cdf0e10cSrcweir pSelection = NULL;
323cdf0e10cSrcweir else
324cdf0e10cSrcweir {
325cdf0e10cSrcweir // Richtige Hintergrundfarbe einstellen.
326cdf0e10cSrcweir // Ich bekomme leider nicht mit, ob sich diese inzwischen geaendert hat.
327cdf0e10cSrcweir Font aFont = mpImpl->mpTextEngine->GetFont();
328cdf0e10cSrcweir Color aColor = pOut->GetBackground().GetColor();
329cdf0e10cSrcweir aColor.SetTransparency( 0 );
330cdf0e10cSrcweir if ( aColor != aFont.GetFillColor() )
331cdf0e10cSrcweir {
332cdf0e10cSrcweir if( aFont.IsTransparent() )
333cdf0e10cSrcweir aColor = Color( COL_TRANSPARENT );
334cdf0e10cSrcweir aFont.SetFillColor( aColor );
335cdf0e10cSrcweir mpImpl->mpTextEngine->maFont = aFont;
336cdf0e10cSrcweir }
337cdf0e10cSrcweir }
338cdf0e10cSrcweir
339cdf0e10cSrcweir mpImpl->mpTextEngine->ImpPaint( pOut, rStartPos, pPaintArea, pPaintRange, pSelection );
340cdf0e10cSrcweir }
341cdf0e10cSrcweir
Paint(const Rectangle & rRect)342cdf0e10cSrcweir void TextView::Paint( const Rectangle& rRect )
343cdf0e10cSrcweir {
344cdf0e10cSrcweir ImpPaint( rRect, sal_False );
345cdf0e10cSrcweir }
346cdf0e10cSrcweir
ImpPaint(const Rectangle & rRect,sal_Bool bUseVirtDev)347cdf0e10cSrcweir void TextView::ImpPaint( const Rectangle& rRect, sal_Bool bUseVirtDev )
348cdf0e10cSrcweir {
349cdf0e10cSrcweir if ( !mpImpl->mpTextEngine->GetUpdateMode() || mpImpl->mpTextEngine->IsInUndo() )
350cdf0e10cSrcweir return;
351cdf0e10cSrcweir
352cdf0e10cSrcweir TextSelection *pDrawSelection = NULL;
353cdf0e10cSrcweir if ( !mpImpl->mbHighlightSelection && mpImpl->maSelection.HasRange() )
354cdf0e10cSrcweir pDrawSelection = &mpImpl->maSelection;
355cdf0e10cSrcweir
356cdf0e10cSrcweir if ( bUseVirtDev )
357cdf0e10cSrcweir {
358cdf0e10cSrcweir VirtualDevice* pVDev = GetVirtualDevice();
359cdf0e10cSrcweir
360cdf0e10cSrcweir const Color& rBackgroundColor = mpImpl->mpWindow->GetBackground().GetColor();
361cdf0e10cSrcweir if ( pVDev->GetFillColor() != rBackgroundColor )
362cdf0e10cSrcweir pVDev->SetFillColor( rBackgroundColor );
363cdf0e10cSrcweir if ( pVDev->GetBackground().GetColor() != rBackgroundColor )
364cdf0e10cSrcweir pVDev->SetBackground( rBackgroundColor );
365cdf0e10cSrcweir
366cdf0e10cSrcweir sal_Bool bVDevValid = sal_True;
367cdf0e10cSrcweir Size aOutSz( pVDev->GetOutputSizePixel() );
368cdf0e10cSrcweir if ( ( aOutSz.Width() < rRect.GetWidth() ) ||
369cdf0e10cSrcweir ( aOutSz.Height() < rRect.GetHeight() ) )
370cdf0e10cSrcweir {
371cdf0e10cSrcweir bVDevValid = pVDev->SetOutputSizePixel( rRect.GetSize() );
372cdf0e10cSrcweir }
373cdf0e10cSrcweir else
374cdf0e10cSrcweir {
375cdf0e10cSrcweir // Das VirtDev kann bei einem Resize sehr gross werden =>
376cdf0e10cSrcweir // irgendwann mal kleiner machen!
377cdf0e10cSrcweir if ( ( aOutSz.Height() > ( rRect.GetHeight() + 20 ) ) ||
378cdf0e10cSrcweir ( aOutSz.Width() > ( rRect.GetWidth() + 20 ) ) )
379cdf0e10cSrcweir {
380cdf0e10cSrcweir bVDevValid = pVDev->SetOutputSizePixel( rRect.GetSize() );
381cdf0e10cSrcweir }
382cdf0e10cSrcweir else
383cdf0e10cSrcweir {
384cdf0e10cSrcweir pVDev->Erase();
385cdf0e10cSrcweir }
386cdf0e10cSrcweir }
387cdf0e10cSrcweir if ( !bVDevValid )
388cdf0e10cSrcweir {
389cdf0e10cSrcweir ImpPaint( rRect, sal_False /* ohne VDev */ );
390cdf0e10cSrcweir return;
391cdf0e10cSrcweir }
392cdf0e10cSrcweir
393cdf0e10cSrcweir Rectangle aTmpRec( Point( 0, 0 ), rRect.GetSize() );
394cdf0e10cSrcweir
395cdf0e10cSrcweir Point aDocPos( mpImpl->maStartDocPos.X(), mpImpl->maStartDocPos.Y() + rRect.Top() );
396cdf0e10cSrcweir Point aStartPos = ImpGetOutputStartPos( aDocPos );
397cdf0e10cSrcweir ImpPaint( pVDev, aStartPos, &aTmpRec, NULL, pDrawSelection );
398cdf0e10cSrcweir mpImpl->mpWindow->DrawOutDev( rRect.TopLeft(), rRect.GetSize(),
399cdf0e10cSrcweir Point(0,0), rRect.GetSize(), *pVDev );
400cdf0e10cSrcweir // ShowSelection();
401cdf0e10cSrcweir if ( mpImpl->mbHighlightSelection )
402cdf0e10cSrcweir ImpHighlight( mpImpl->maSelection );
403cdf0e10cSrcweir }
404cdf0e10cSrcweir else
405cdf0e10cSrcweir {
406cdf0e10cSrcweir Point aStartPos = ImpGetOutputStartPos( mpImpl->maStartDocPos );
407cdf0e10cSrcweir ImpPaint( mpImpl->mpWindow, aStartPos, &rRect, NULL, pDrawSelection );
408cdf0e10cSrcweir
409cdf0e10cSrcweir // ShowSelection();
410cdf0e10cSrcweir if ( mpImpl->mbHighlightSelection )
411cdf0e10cSrcweir ImpHighlight( mpImpl->maSelection );
412cdf0e10cSrcweir }
413cdf0e10cSrcweir }
414cdf0e10cSrcweir
ImpHighlight(const TextSelection & rSel)415cdf0e10cSrcweir void TextView::ImpHighlight( const TextSelection& rSel )
416cdf0e10cSrcweir {
417cdf0e10cSrcweir TextSelection aSel( rSel );
418cdf0e10cSrcweir aSel.Justify();
419cdf0e10cSrcweir if ( aSel.HasRange() && !mpImpl->mpTextEngine->IsInUndo() && mpImpl->mpTextEngine->GetUpdateMode() )
420cdf0e10cSrcweir {
421cdf0e10cSrcweir mpImpl->mpCursor->Hide();
422cdf0e10cSrcweir
423cdf0e10cSrcweir DBG_ASSERT( !mpImpl->mpTextEngine->mpIdleFormatter->IsActive(), "ImpHighlight: Not formatted!" );
424cdf0e10cSrcweir
425cdf0e10cSrcweir Rectangle aVisArea( mpImpl->maStartDocPos, mpImpl->mpWindow->GetOutputSizePixel() );
426cdf0e10cSrcweir long nY = 0;
427cdf0e10cSrcweir sal_uLong nStartPara = aSel.GetStart().GetPara();
428cdf0e10cSrcweir sal_uLong nEndPara = aSel.GetEnd().GetPara();
429cdf0e10cSrcweir for ( sal_uLong nPara = 0; nPara <= nEndPara; nPara++ )
430cdf0e10cSrcweir {
431cdf0e10cSrcweir long nParaHeight = (long)mpImpl->mpTextEngine->CalcParaHeight( nPara );
432cdf0e10cSrcweir if ( ( nPara >= nStartPara ) && ( ( nY + nParaHeight ) > aVisArea.Top() ) )
433cdf0e10cSrcweir {
434cdf0e10cSrcweir TEParaPortion* pTEParaPortion = mpImpl->mpTextEngine->mpTEParaPortions->GetObject( nPara );
435cdf0e10cSrcweir sal_uInt16 nStartLine = 0;
436cdf0e10cSrcweir sal_uInt16 nEndLine = pTEParaPortion->GetLines().Count() -1;
437cdf0e10cSrcweir if ( nPara == nStartPara )
438cdf0e10cSrcweir nStartLine = pTEParaPortion->GetLineNumber( aSel.GetStart().GetIndex(), sal_False );
439cdf0e10cSrcweir if ( nPara == nEndPara )
440cdf0e10cSrcweir nEndLine = pTEParaPortion->GetLineNumber( aSel.GetEnd().GetIndex(), sal_True );
441cdf0e10cSrcweir
442cdf0e10cSrcweir // ueber die Zeilen iterieren....
443cdf0e10cSrcweir for ( sal_uInt16 nLine = nStartLine; nLine <= nEndLine; nLine++ )
444cdf0e10cSrcweir {
445cdf0e10cSrcweir TextLine* pLine = pTEParaPortion->GetLines().GetObject( nLine );
446cdf0e10cSrcweir sal_uInt16 nStartIndex = pLine->GetStart();
447cdf0e10cSrcweir sal_uInt16 nEndIndex = pLine->GetEnd();
448cdf0e10cSrcweir if ( ( nPara == nStartPara ) && ( nLine == nStartLine ) )
449cdf0e10cSrcweir nStartIndex = aSel.GetStart().GetIndex();
450cdf0e10cSrcweir if ( ( nPara == nEndPara ) && ( nLine == nEndLine ) )
451cdf0e10cSrcweir nEndIndex = aSel.GetEnd().GetIndex();
452cdf0e10cSrcweir
453cdf0e10cSrcweir // Kann passieren, wenn am Anfang einer umgebrochenen Zeile.
454cdf0e10cSrcweir if ( nEndIndex < nStartIndex )
455cdf0e10cSrcweir nEndIndex = nStartIndex;
456cdf0e10cSrcweir
457cdf0e10cSrcweir Rectangle aTmpRec( mpImpl->mpTextEngine->GetEditCursor( TextPaM( nPara, nStartIndex ), sal_False ) );
458cdf0e10cSrcweir aTmpRec.Top() += nY;
459cdf0e10cSrcweir aTmpRec.Bottom() += nY;
460cdf0e10cSrcweir Point aTopLeft( aTmpRec.TopLeft() );
461cdf0e10cSrcweir
462cdf0e10cSrcweir aTmpRec = mpImpl->mpTextEngine->GetEditCursor( TextPaM( nPara, nEndIndex ), sal_True );
463cdf0e10cSrcweir aTmpRec.Top() += nY;
464cdf0e10cSrcweir aTmpRec.Bottom() += nY;
465cdf0e10cSrcweir Point aBottomRight( aTmpRec.BottomRight() );
466cdf0e10cSrcweir aBottomRight.X()--;
467cdf0e10cSrcweir
468cdf0e10cSrcweir // Nur Painten, wenn im sichtbaren Bereich...
469cdf0e10cSrcweir if ( ( aTopLeft.X() < aBottomRight.X() ) && ( aBottomRight.Y() >= aVisArea.Top() ) )
470cdf0e10cSrcweir {
471cdf0e10cSrcweir Point aPnt1( GetWindowPos( aTopLeft ) );
472cdf0e10cSrcweir Point aPnt2( GetWindowPos( aBottomRight ) );
473cdf0e10cSrcweir
474cdf0e10cSrcweir Rectangle aRect( aPnt1, aPnt2 );
475cdf0e10cSrcweir mpImpl->mpWindow->Invert( aRect );
476cdf0e10cSrcweir }
477cdf0e10cSrcweir }
478cdf0e10cSrcweir }
479cdf0e10cSrcweir nY += nParaHeight;
480cdf0e10cSrcweir
481cdf0e10cSrcweir if ( nY >= aVisArea.Bottom() )
482cdf0e10cSrcweir break;
483cdf0e10cSrcweir }
484cdf0e10cSrcweir }
485cdf0e10cSrcweir }
486cdf0e10cSrcweir
ImpSetSelection(const TextSelection & rSelection)487cdf0e10cSrcweir void TextView::ImpSetSelection( const TextSelection& rSelection )
488cdf0e10cSrcweir {
489cdf0e10cSrcweir if ( rSelection != mpImpl->maSelection )
490cdf0e10cSrcweir {
491cdf0e10cSrcweir mpImpl->maSelection = rSelection;
492cdf0e10cSrcweir mpImpl->mpTextEngine->Broadcast( TextHint( TEXT_HINT_VIEWSELECTIONCHANGED ) );
493cdf0e10cSrcweir }
494cdf0e10cSrcweir }
495cdf0e10cSrcweir
ShowSelection()496cdf0e10cSrcweir void TextView::ShowSelection()
497cdf0e10cSrcweir {
498cdf0e10cSrcweir ImpShowHideSelection( sal_True );
499cdf0e10cSrcweir }
500cdf0e10cSrcweir
HideSelection()501cdf0e10cSrcweir void TextView::HideSelection()
502cdf0e10cSrcweir {
503cdf0e10cSrcweir ImpShowHideSelection( sal_False );
504cdf0e10cSrcweir }
505cdf0e10cSrcweir
ShowSelection(const TextSelection & rRange)506cdf0e10cSrcweir void TextView::ShowSelection( const TextSelection& rRange )
507cdf0e10cSrcweir {
508cdf0e10cSrcweir ImpShowHideSelection( sal_True, &rRange );
509cdf0e10cSrcweir }
510cdf0e10cSrcweir
ImpShowHideSelection(sal_Bool bShow,const TextSelection * pRange)511cdf0e10cSrcweir void TextView::ImpShowHideSelection( sal_Bool bShow, const TextSelection* pRange )
512cdf0e10cSrcweir {
513cdf0e10cSrcweir const TextSelection* pRangeOrSelection = pRange ? pRange : &mpImpl->maSelection;
514cdf0e10cSrcweir
515cdf0e10cSrcweir if ( pRangeOrSelection->HasRange() )
516cdf0e10cSrcweir {
517cdf0e10cSrcweir if ( mpImpl->mbHighlightSelection )
518cdf0e10cSrcweir {
519cdf0e10cSrcweir ImpHighlight( *pRangeOrSelection );
520cdf0e10cSrcweir }
521cdf0e10cSrcweir else
522cdf0e10cSrcweir {
523cdf0e10cSrcweir if( mpImpl->mpWindow->IsPaintTransparent() )
524cdf0e10cSrcweir mpImpl->mpWindow->Invalidate();
525cdf0e10cSrcweir else
526cdf0e10cSrcweir {
527cdf0e10cSrcweir Rectangle aOutArea( Point( 0, 0 ), mpImpl->mpWindow->GetOutputSizePixel() );
528cdf0e10cSrcweir Point aStartPos( ImpGetOutputStartPos( mpImpl->maStartDocPos ) );
529cdf0e10cSrcweir TextSelection aRange( *pRangeOrSelection );
530cdf0e10cSrcweir aRange.Justify();
531cdf0e10cSrcweir sal_Bool bVisCursor = mpImpl->mpCursor->IsVisible();
532cdf0e10cSrcweir mpImpl->mpCursor->Hide();
533cdf0e10cSrcweir ImpPaint( mpImpl->mpWindow, aStartPos, &aOutArea, &aRange, bShow ? &mpImpl->maSelection : NULL );
534cdf0e10cSrcweir if ( bVisCursor )
535cdf0e10cSrcweir mpImpl->mpCursor->Show();
536cdf0e10cSrcweir }
537cdf0e10cSrcweir }
538cdf0e10cSrcweir }
539cdf0e10cSrcweir }
540cdf0e10cSrcweir
GetVirtualDevice()541cdf0e10cSrcweir VirtualDevice* TextView::GetVirtualDevice()
542cdf0e10cSrcweir {
543cdf0e10cSrcweir if ( !mpImpl->mpVirtDev )
544cdf0e10cSrcweir {
545cdf0e10cSrcweir mpImpl->mpVirtDev = new VirtualDevice;
546cdf0e10cSrcweir mpImpl->mpVirtDev->SetLineColor();
547cdf0e10cSrcweir }
548cdf0e10cSrcweir return mpImpl->mpVirtDev;
549cdf0e10cSrcweir }
550cdf0e10cSrcweir
EraseVirtualDevice()551cdf0e10cSrcweir void TextView::EraseVirtualDevice()
552cdf0e10cSrcweir {
553cdf0e10cSrcweir delete mpImpl->mpVirtDev;
554cdf0e10cSrcweir mpImpl->mpVirtDev = 0;
555cdf0e10cSrcweir }
556cdf0e10cSrcweir
KeyInput(const KeyEvent & rKeyEvent)557cdf0e10cSrcweir sal_Bool TextView::KeyInput( const KeyEvent& rKeyEvent )
558cdf0e10cSrcweir {
559cdf0e10cSrcweir sal_Bool bDone = sal_True;
560cdf0e10cSrcweir sal_Bool bModified = sal_False;
561cdf0e10cSrcweir sal_Bool bMoved = sal_False;
562cdf0e10cSrcweir sal_Bool bEndKey = sal_False; // spezielle CursorPosition
563cdf0e10cSrcweir sal_Bool bAllowIdle = sal_True;
564cdf0e10cSrcweir
565cdf0e10cSrcweir // Um zu pruefen ob durch irgendeine Aktion mModified, das lokale
566cdf0e10cSrcweir // bModified wird z.B. bei Cut/Paste nicht gesetzt, weil dort an anderen
567cdf0e10cSrcweir // Stellen das updaten erfolgt.
568cdf0e10cSrcweir sal_Bool bWasModified = mpImpl->mpTextEngine->IsModified();
569cdf0e10cSrcweir mpImpl->mpTextEngine->SetModified( sal_False );
570cdf0e10cSrcweir
571cdf0e10cSrcweir TextSelection aCurSel( mpImpl->maSelection );
572cdf0e10cSrcweir TextSelection aOldSel( aCurSel );
573cdf0e10cSrcweir
574cdf0e10cSrcweir sal_uInt16 nCode = rKeyEvent.GetKeyCode().GetCode();
575cdf0e10cSrcweir KeyFuncType eFunc = rKeyEvent.GetKeyCode().GetFunction();
576cdf0e10cSrcweir if ( eFunc != KEYFUNC_DONTKNOW )
577cdf0e10cSrcweir {
578cdf0e10cSrcweir switch ( eFunc )
579cdf0e10cSrcweir {
580cdf0e10cSrcweir case KEYFUNC_CUT:
581cdf0e10cSrcweir {
582cdf0e10cSrcweir if ( !mpImpl->mbReadOnly )
583cdf0e10cSrcweir Cut();
584cdf0e10cSrcweir }
585cdf0e10cSrcweir break;
586cdf0e10cSrcweir case KEYFUNC_COPY:
587cdf0e10cSrcweir {
588cdf0e10cSrcweir Copy();
589cdf0e10cSrcweir }
590cdf0e10cSrcweir break;
591cdf0e10cSrcweir case KEYFUNC_PASTE:
592cdf0e10cSrcweir {
593cdf0e10cSrcweir if ( !mpImpl->mbReadOnly )
594cdf0e10cSrcweir Paste();
595cdf0e10cSrcweir }
596cdf0e10cSrcweir break;
597cdf0e10cSrcweir case KEYFUNC_UNDO:
598cdf0e10cSrcweir {
599cdf0e10cSrcweir if ( !mpImpl->mbReadOnly )
600cdf0e10cSrcweir Undo();
601cdf0e10cSrcweir }
602cdf0e10cSrcweir break;
603cdf0e10cSrcweir case KEYFUNC_REDO:
604cdf0e10cSrcweir {
605cdf0e10cSrcweir if ( !mpImpl->mbReadOnly )
606cdf0e10cSrcweir Redo();
607cdf0e10cSrcweir }
608cdf0e10cSrcweir break;
609cdf0e10cSrcweir
610cdf0e10cSrcweir default: // wird dann evtl. unten bearbeitet.
611cdf0e10cSrcweir eFunc = KEYFUNC_DONTKNOW;
612cdf0e10cSrcweir }
613cdf0e10cSrcweir }
614cdf0e10cSrcweir if ( eFunc == KEYFUNC_DONTKNOW )
615cdf0e10cSrcweir {
616cdf0e10cSrcweir switch ( nCode )
617cdf0e10cSrcweir {
618cdf0e10cSrcweir case KEY_UP:
619cdf0e10cSrcweir case KEY_DOWN:
620cdf0e10cSrcweir case KEY_LEFT:
621cdf0e10cSrcweir case KEY_RIGHT:
622cdf0e10cSrcweir case KEY_HOME:
623cdf0e10cSrcweir case KEY_END:
624cdf0e10cSrcweir case KEY_PAGEUP:
625cdf0e10cSrcweir case KEY_PAGEDOWN:
626cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_WORD_FORWARD:
627cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_WORD_FORWARD:
628cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_WORD_BACKWARD:
629cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_WORD_BACKWARD:
630cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_BEGIN_OF_LINE:
631cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_END_OF_LINE:
632cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_BEGIN_OF_LINE:
633cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_END_OF_LINE:
634cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_BEGIN_OF_PARAGRAPH:
635cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_END_OF_PARAGRAPH:
636cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_BEGIN_OF_PARAGRAPH:
637cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_END_OF_PARAGRAPH:
638cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_BEGIN_OF_DOCUMENT:
639cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_END_OF_DOCUMENT:
640cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_BEGIN_OF_DOCUMENT:
641cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_END_OF_DOCUMENT:
642cdf0e10cSrcweir {
643cdf0e10cSrcweir if ( ( !rKeyEvent.GetKeyCode().IsMod2() || ( nCode == KEY_LEFT ) || ( nCode == KEY_RIGHT ) )
644cdf0e10cSrcweir && !( rKeyEvent.GetKeyCode().IsMod1() && ( nCode == KEY_PAGEUP || nCode == KEY_PAGEDOWN ) ) )
645cdf0e10cSrcweir {
646cdf0e10cSrcweir aCurSel = ImpMoveCursor( rKeyEvent );
647cdf0e10cSrcweir if ( aCurSel.HasRange() ) {
648cdf0e10cSrcweir uno::Reference<datatransfer::clipboard::XClipboard> aSelection(GetWindow()->GetPrimarySelection());
649cdf0e10cSrcweir Copy( aSelection );
650cdf0e10cSrcweir }
651cdf0e10cSrcweir bMoved = sal_True;
652cdf0e10cSrcweir if ( nCode == KEY_END )
653cdf0e10cSrcweir bEndKey = sal_True;
654cdf0e10cSrcweir }
655cdf0e10cSrcweir else
656cdf0e10cSrcweir bDone = sal_False;
657cdf0e10cSrcweir }
658cdf0e10cSrcweir break;
659cdf0e10cSrcweir case KEY_BACKSPACE:
660cdf0e10cSrcweir case KEY_DELETE:
661cdf0e10cSrcweir case com::sun::star::awt::Key::DELETE_WORD_BACKWARD:
662cdf0e10cSrcweir case com::sun::star::awt::Key::DELETE_WORD_FORWARD:
663cdf0e10cSrcweir case com::sun::star::awt::Key::DELETE_TO_BEGIN_OF_LINE:
664cdf0e10cSrcweir case com::sun::star::awt::Key::DELETE_TO_END_OF_LINE:
665cdf0e10cSrcweir {
666cdf0e10cSrcweir if ( !mpImpl->mbReadOnly && !rKeyEvent.GetKeyCode().IsMod2() )
667cdf0e10cSrcweir {
668cdf0e10cSrcweir sal_uInt8 nDel = ( nCode == KEY_DELETE ) ? DEL_RIGHT : DEL_LEFT;
669cdf0e10cSrcweir sal_uInt8 nMode = rKeyEvent.GetKeyCode().IsMod1() ? DELMODE_RESTOFWORD : DELMODE_SIMPLE;
670cdf0e10cSrcweir if ( ( nMode == DELMODE_RESTOFWORD ) && rKeyEvent.GetKeyCode().IsShift() )
671cdf0e10cSrcweir nMode = DELMODE_RESTOFCONTENT;
672cdf0e10cSrcweir
673cdf0e10cSrcweir switch( nCode )
674cdf0e10cSrcweir {
675cdf0e10cSrcweir case com::sun::star::awt::Key::DELETE_WORD_BACKWARD:
676cdf0e10cSrcweir nDel = DEL_LEFT;
677cdf0e10cSrcweir nMode = DELMODE_RESTOFWORD;
678cdf0e10cSrcweir break;
679cdf0e10cSrcweir case com::sun::star::awt::Key::DELETE_WORD_FORWARD:
680cdf0e10cSrcweir nDel = DEL_RIGHT;
681cdf0e10cSrcweir nMode = DELMODE_RESTOFWORD;
682cdf0e10cSrcweir break;
683cdf0e10cSrcweir case com::sun::star::awt::Key::DELETE_TO_BEGIN_OF_LINE:
684cdf0e10cSrcweir nDel = DEL_LEFT;
685cdf0e10cSrcweir nMode = DELMODE_RESTOFCONTENT;
686cdf0e10cSrcweir break;
687cdf0e10cSrcweir case com::sun::star::awt::Key::DELETE_TO_END_OF_LINE:
688cdf0e10cSrcweir nDel = DEL_RIGHT;
689cdf0e10cSrcweir nMode = DELMODE_RESTOFCONTENT;
690cdf0e10cSrcweir break;
691cdf0e10cSrcweir default: break;
692cdf0e10cSrcweir }
693cdf0e10cSrcweir
694cdf0e10cSrcweir mpImpl->mpTextEngine->UndoActionStart();
695cdf0e10cSrcweir if(mpImpl->mbSupportProtectAttribute)
696cdf0e10cSrcweir {
697cdf0e10cSrcweir //expand selection to include all protected content - if there is any
698cdf0e10cSrcweir const TextCharAttrib* pStartAttr = mpImpl->mpTextEngine->FindCharAttrib(
699cdf0e10cSrcweir TextPaM(mpImpl->maSelection.GetStart().GetPara(),
700cdf0e10cSrcweir mpImpl->maSelection.GetStart().GetIndex()),
701cdf0e10cSrcweir TEXTATTR_PROTECTED );
702cdf0e10cSrcweir const TextCharAttrib* pEndAttr = mpImpl->mpTextEngine->FindCharAttrib(
703cdf0e10cSrcweir TextPaM(mpImpl->maSelection.GetEnd().GetPara(),
704cdf0e10cSrcweir mpImpl->maSelection.GetEnd().GetIndex()),
705cdf0e10cSrcweir TEXTATTR_PROTECTED );
706cdf0e10cSrcweir if(pStartAttr && pStartAttr->GetStart() < mpImpl->maSelection.GetStart().GetIndex())
707cdf0e10cSrcweir {
708cdf0e10cSrcweir mpImpl->maSelection.GetStart().GetIndex() = pStartAttr->GetStart();
709cdf0e10cSrcweir }
710cdf0e10cSrcweir if(pEndAttr && pEndAttr->GetEnd() > mpImpl->maSelection.GetEnd().GetIndex())
711cdf0e10cSrcweir {
712cdf0e10cSrcweir mpImpl->maSelection.GetEnd().GetIndex() = pEndAttr->GetEnd();
713cdf0e10cSrcweir }
714cdf0e10cSrcweir }
715cdf0e10cSrcweir aCurSel = ImpDelete( nDel, nMode );
716cdf0e10cSrcweir mpImpl->mpTextEngine->UndoActionEnd();
717cdf0e10cSrcweir bModified = sal_True;
718cdf0e10cSrcweir bAllowIdle = sal_False;
719cdf0e10cSrcweir }
720cdf0e10cSrcweir else
721cdf0e10cSrcweir bDone = sal_False;
722cdf0e10cSrcweir }
723cdf0e10cSrcweir break;
724cdf0e10cSrcweir case KEY_TAB:
725cdf0e10cSrcweir {
726cdf0e10cSrcweir if ( !mpImpl->mbReadOnly && !rKeyEvent.GetKeyCode().IsShift() &&
727cdf0e10cSrcweir !rKeyEvent.GetKeyCode().IsMod1() && !rKeyEvent.GetKeyCode().IsMod2() &&
728cdf0e10cSrcweir ImplCheckTextLen( 'x' ) )
729cdf0e10cSrcweir {
730cdf0e10cSrcweir aCurSel = mpImpl->mpTextEngine->ImpInsertText( aCurSel, '\t', !IsInsertMode() );
731cdf0e10cSrcweir bModified = sal_True;
732cdf0e10cSrcweir }
733cdf0e10cSrcweir else
734cdf0e10cSrcweir bDone = sal_False;
735cdf0e10cSrcweir }
736cdf0e10cSrcweir break;
737cdf0e10cSrcweir case KEY_RETURN:
738cdf0e10cSrcweir {
739cdf0e10cSrcweir // Shift-RETURN darf nicht geschluckt werden, weil dann keine
740cdf0e10cSrcweir // mehrzeilige Eingabe in Dialogen/Property-Editor moeglich.
741cdf0e10cSrcweir if ( !mpImpl->mbReadOnly && !rKeyEvent.GetKeyCode().IsMod1() &&
742cdf0e10cSrcweir !rKeyEvent.GetKeyCode().IsMod2() && ImplCheckTextLen( 'x' ) )
743cdf0e10cSrcweir {
744cdf0e10cSrcweir mpImpl->mpTextEngine->UndoActionStart();
745cdf0e10cSrcweir aCurSel = mpImpl->mpTextEngine->ImpInsertParaBreak( aCurSel );
746cdf0e10cSrcweir if ( mpImpl->mbAutoIndent )
747cdf0e10cSrcweir {
748cdf0e10cSrcweir TextNode* pPrev = mpImpl->mpTextEngine->mpDoc->GetNodes().GetObject( aCurSel.GetEnd().GetPara() - 1 );
749cdf0e10cSrcweir sal_uInt16 n = 0;
750cdf0e10cSrcweir while ( ( n < pPrev->GetText().Len() ) && (
751cdf0e10cSrcweir ( pPrev->GetText().GetChar( n ) == ' ' ) ||
752cdf0e10cSrcweir ( pPrev->GetText().GetChar( n ) == '\t' ) ) )
753cdf0e10cSrcweir {
754cdf0e10cSrcweir n++;
755cdf0e10cSrcweir }
756cdf0e10cSrcweir if ( n )
757cdf0e10cSrcweir aCurSel = mpImpl->mpTextEngine->ImpInsertText( aCurSel, pPrev->GetText().Copy( 0, n ) );
758cdf0e10cSrcweir }
759cdf0e10cSrcweir mpImpl->mpTextEngine->UndoActionEnd();
760cdf0e10cSrcweir bModified = sal_True;
761cdf0e10cSrcweir }
762cdf0e10cSrcweir else
763cdf0e10cSrcweir bDone = sal_False;
764cdf0e10cSrcweir }
765cdf0e10cSrcweir break;
766cdf0e10cSrcweir case KEY_INSERT:
767cdf0e10cSrcweir {
768cdf0e10cSrcweir if ( !mpImpl->mbReadOnly )
769cdf0e10cSrcweir SetInsertMode( !IsInsertMode() );
770cdf0e10cSrcweir }
771cdf0e10cSrcweir break;
772cdf0e10cSrcweir default:
773cdf0e10cSrcweir {
774cdf0e10cSrcweir if ( TextEngine::IsSimpleCharInput( rKeyEvent ) )
775cdf0e10cSrcweir {
776cdf0e10cSrcweir xub_Unicode nCharCode = rKeyEvent.GetCharCode();
777cdf0e10cSrcweir if ( !mpImpl->mbReadOnly && ImplCheckTextLen( nCharCode ) ) // sonst trotzdem das Zeichen schlucken...
778cdf0e10cSrcweir {
779cdf0e10cSrcweir aCurSel = mpImpl->mpTextEngine->ImpInsertText( nCharCode, aCurSel, !IsInsertMode(), sal_True );
780cdf0e10cSrcweir bModified = sal_True;
781cdf0e10cSrcweir }
782cdf0e10cSrcweir }
783cdf0e10cSrcweir else
784cdf0e10cSrcweir bDone = sal_False;
785cdf0e10cSrcweir }
786cdf0e10cSrcweir }
787cdf0e10cSrcweir }
788cdf0e10cSrcweir
789cdf0e10cSrcweir if ( aCurSel != aOldSel ) // Check if changed, maybe other method already changed mpImpl->maSelection, don't overwrite that!
790cdf0e10cSrcweir ImpSetSelection( aCurSel );
791cdf0e10cSrcweir
792cdf0e10cSrcweir mpImpl->mpTextEngine->UpdateSelections();
793cdf0e10cSrcweir
794cdf0e10cSrcweir if ( ( nCode != KEY_UP ) && ( nCode != KEY_DOWN ) )
795cdf0e10cSrcweir mpImpl->mnTravelXPos = TRAVEL_X_DONTKNOW;
796cdf0e10cSrcweir
797cdf0e10cSrcweir if ( bModified )
798cdf0e10cSrcweir {
799cdf0e10cSrcweir // Idle-Formatter nur, wenn AnyInput.
800cdf0e10cSrcweir if ( bAllowIdle && Application::AnyInput( INPUT_KEYBOARD) )
801cdf0e10cSrcweir mpImpl->mpTextEngine->IdleFormatAndUpdate( this );
802cdf0e10cSrcweir else
803cdf0e10cSrcweir mpImpl->mpTextEngine->FormatAndUpdate( this);
804cdf0e10cSrcweir }
805cdf0e10cSrcweir else if ( bMoved )
806cdf0e10cSrcweir {
807cdf0e10cSrcweir // Selection wird jetzt gezielt in ImpMoveCursor gemalt.
808cdf0e10cSrcweir ImpShowCursor( mpImpl->mbAutoScroll, sal_True, bEndKey );
809cdf0e10cSrcweir }
810cdf0e10cSrcweir
811cdf0e10cSrcweir if ( mpImpl->mpTextEngine->IsModified() )
812cdf0e10cSrcweir mpImpl->mpTextEngine->Broadcast( TextHint( TEXT_HINT_MODIFIED ) );
813cdf0e10cSrcweir else if ( bWasModified )
814cdf0e10cSrcweir mpImpl->mpTextEngine->SetModified( sal_True );
815cdf0e10cSrcweir
816cdf0e10cSrcweir return bDone;
817cdf0e10cSrcweir }
818cdf0e10cSrcweir
MouseButtonUp(const MouseEvent & rMouseEvent)819cdf0e10cSrcweir void TextView::MouseButtonUp( const MouseEvent& rMouseEvent )
820cdf0e10cSrcweir {
821cdf0e10cSrcweir mpImpl->mbClickedInSelection = sal_False;
822cdf0e10cSrcweir mpImpl->mnTravelXPos = TRAVEL_X_DONTKNOW;
823cdf0e10cSrcweir mpImpl->mpSelEngine->SelMouseButtonUp( rMouseEvent );
824cdf0e10cSrcweir if ( rMouseEvent.IsMiddle() && !IsReadOnly() &&
825cdf0e10cSrcweir ( GetWindow()->GetSettings().GetMouseSettings().GetMiddleButtonAction() == MOUSE_MIDDLE_PASTESELECTION ) )
826cdf0e10cSrcweir {
827cdf0e10cSrcweir uno::Reference<datatransfer::clipboard::XClipboard> aSelection(GetWindow()->GetPrimarySelection());
828cdf0e10cSrcweir Paste( aSelection );
829cdf0e10cSrcweir if ( mpImpl->mpTextEngine->IsModified() )
830cdf0e10cSrcweir mpImpl->mpTextEngine->Broadcast( TextHint( TEXT_HINT_MODIFIED ) );
831cdf0e10cSrcweir }
832cdf0e10cSrcweir else if ( rMouseEvent.IsLeft() && GetSelection().HasRange() )
833cdf0e10cSrcweir {
834cdf0e10cSrcweir uno::Reference<datatransfer::clipboard::XClipboard> aSelection(GetWindow()->GetPrimarySelection());
835cdf0e10cSrcweir Copy( aSelection );
836cdf0e10cSrcweir }
837cdf0e10cSrcweir }
838cdf0e10cSrcweir
MouseButtonDown(const MouseEvent & rMouseEvent)839cdf0e10cSrcweir void TextView::MouseButtonDown( const MouseEvent& rMouseEvent )
840cdf0e10cSrcweir {
841cdf0e10cSrcweir mpImpl->mpTextEngine->CheckIdleFormatter(); // Falls schnelles Tippen und MouseButtonDown
842cdf0e10cSrcweir mpImpl->mnTravelXPos = TRAVEL_X_DONTKNOW;
843cdf0e10cSrcweir mpImpl->mbClickedInSelection = IsSelectionAtPoint( rMouseEvent.GetPosPixel() );
844cdf0e10cSrcweir
845cdf0e10cSrcweir mpImpl->mpTextEngine->SetActiveView( this );
846cdf0e10cSrcweir
847cdf0e10cSrcweir mpImpl->mpSelEngine->SelMouseButtonDown( rMouseEvent );
848cdf0e10cSrcweir
849cdf0e10cSrcweir // mbu 20.01.2005 - SelMouseButtonDown() possibly triggers a 'selection changed'
850cdf0e10cSrcweir // notification. The appropriate handler could change the current selection,
851cdf0e10cSrcweir // which is the case in the MailMerge address block control. To enable select'n'drag
852cdf0e10cSrcweir // we need to reevaluate the selection after the notification has been fired.
853cdf0e10cSrcweir mpImpl->mbClickedInSelection = IsSelectionAtPoint( rMouseEvent.GetPosPixel() );
854cdf0e10cSrcweir
855cdf0e10cSrcweir // Sonderbehandlungen
856cdf0e10cSrcweir if ( !rMouseEvent.IsShift() && ( rMouseEvent.GetClicks() >= 2 ) )
857cdf0e10cSrcweir {
858cdf0e10cSrcweir if ( rMouseEvent.IsMod2() )
859cdf0e10cSrcweir {
860cdf0e10cSrcweir HideSelection();
861cdf0e10cSrcweir ImpSetSelection( mpImpl->maSelection.GetEnd() );
862cdf0e10cSrcweir SetCursorAtPoint( rMouseEvent.GetPosPixel() ); // Wird von SelectionEngine bei MOD2 nicht gesetzt
863cdf0e10cSrcweir }
864cdf0e10cSrcweir
865cdf0e10cSrcweir if ( rMouseEvent.GetClicks() == 2 )
866cdf0e10cSrcweir {
867cdf0e10cSrcweir // Wort selektieren
868cdf0e10cSrcweir if ( mpImpl->maSelection.GetEnd().GetIndex() < mpImpl->mpTextEngine->GetTextLen( mpImpl->maSelection.GetEnd().GetPara() ) )
869cdf0e10cSrcweir {
870cdf0e10cSrcweir HideSelection();
871cdf0e10cSrcweir TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes().GetObject( mpImpl->maSelection.GetEnd().GetPara() );
872cdf0e10cSrcweir uno::Reference < i18n::XBreakIterator > xBI = mpImpl->mpTextEngine->GetBreakIterator();
873cdf0e10cSrcweir i18n::Boundary aBoundary = xBI->getWordBoundary( pNode->GetText(), mpImpl->maSelection.GetEnd().GetIndex(), mpImpl->mpTextEngine->GetLocale(), i18n::WordType::ANYWORD_IGNOREWHITESPACES, sal_True );
874cdf0e10cSrcweir TextSelection aNewSel( mpImpl->maSelection );
875cdf0e10cSrcweir aNewSel.GetStart().GetIndex() = (sal_uInt16)aBoundary.startPos;
876cdf0e10cSrcweir aNewSel.GetEnd().GetIndex() = (sal_uInt16)aBoundary.endPos;
877cdf0e10cSrcweir if(mpImpl->mbSupportProtectAttribute)
878cdf0e10cSrcweir {
879cdf0e10cSrcweir //expand selection to include all protected content - if there is any
880cdf0e10cSrcweir const TextCharAttrib* pStartAttr = mpImpl->mpTextEngine->FindCharAttrib(
881cdf0e10cSrcweir TextPaM(aNewSel.GetStart().GetPara(),
882cdf0e10cSrcweir (sal_uInt16)aBoundary.startPos),
883cdf0e10cSrcweir TEXTATTR_PROTECTED );
884cdf0e10cSrcweir const TextCharAttrib* pEndAttr = mpImpl->mpTextEngine->FindCharAttrib(
885cdf0e10cSrcweir TextPaM(aNewSel.GetEnd().GetPara(),
886cdf0e10cSrcweir (sal_uInt16)aBoundary.endPos),
887cdf0e10cSrcweir TEXTATTR_PROTECTED );
888cdf0e10cSrcweir if(pStartAttr && pStartAttr->GetStart() < aNewSel.GetStart().GetIndex())
889cdf0e10cSrcweir {
890cdf0e10cSrcweir aNewSel.GetStart().GetIndex() = pStartAttr->GetStart();
891cdf0e10cSrcweir }
892cdf0e10cSrcweir if(pEndAttr && pEndAttr->GetEnd() > aNewSel.GetEnd().GetIndex())
893cdf0e10cSrcweir {
894cdf0e10cSrcweir aNewSel.GetEnd().GetIndex() = pEndAttr->GetEnd();
895cdf0e10cSrcweir }
896cdf0e10cSrcweir }
897cdf0e10cSrcweir ImpSetSelection( aNewSel );
898cdf0e10cSrcweir ShowSelection();
899cdf0e10cSrcweir ShowCursor( sal_True, sal_True );
900cdf0e10cSrcweir }
901cdf0e10cSrcweir }
902cdf0e10cSrcweir else if ( rMouseEvent.GetClicks() == 3 )
903cdf0e10cSrcweir {
904cdf0e10cSrcweir // Absatz selektieren
905cdf0e10cSrcweir if ( mpImpl->maSelection.GetStart().GetIndex() || ( mpImpl->maSelection.GetEnd().GetIndex() < mpImpl->mpTextEngine->GetTextLen( mpImpl->maSelection.GetEnd().GetPara() ) ) )
906cdf0e10cSrcweir {
907cdf0e10cSrcweir HideSelection();
908cdf0e10cSrcweir TextSelection aNewSel( mpImpl->maSelection );
909cdf0e10cSrcweir aNewSel.GetStart().GetIndex() = 0;
910cdf0e10cSrcweir aNewSel.GetEnd().GetIndex() = mpImpl->mpTextEngine->mpDoc->GetNodes().GetObject( mpImpl->maSelection.GetEnd().GetPara() )->GetText().Len();
911cdf0e10cSrcweir ImpSetSelection( aNewSel );
912cdf0e10cSrcweir ShowSelection();
913cdf0e10cSrcweir ShowCursor( sal_True, sal_True );
914cdf0e10cSrcweir }
915cdf0e10cSrcweir }
916cdf0e10cSrcweir }
917cdf0e10cSrcweir }
918cdf0e10cSrcweir
919cdf0e10cSrcweir
MouseMove(const MouseEvent & rMouseEvent)920cdf0e10cSrcweir void TextView::MouseMove( const MouseEvent& rMouseEvent )
921cdf0e10cSrcweir {
922cdf0e10cSrcweir mpImpl->mnTravelXPos = TRAVEL_X_DONTKNOW;
923cdf0e10cSrcweir mpImpl->mpSelEngine->SelMouseMove( rMouseEvent );
924cdf0e10cSrcweir }
925cdf0e10cSrcweir
Command(const CommandEvent & rCEvt)926cdf0e10cSrcweir void TextView::Command( const CommandEvent& rCEvt )
927cdf0e10cSrcweir {
928cdf0e10cSrcweir mpImpl->mpTextEngine->CheckIdleFormatter(); // Falls schnelles Tippen und MouseButtonDown
929cdf0e10cSrcweir mpImpl->mpTextEngine->SetActiveView( this );
930cdf0e10cSrcweir
931cdf0e10cSrcweir if ( rCEvt.GetCommand() == COMMAND_STARTEXTTEXTINPUT )
932cdf0e10cSrcweir {
933cdf0e10cSrcweir DeleteSelected();
934cdf0e10cSrcweir delete mpImpl->mpTextEngine->mpIMEInfos;
935cdf0e10cSrcweir TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes().GetObject( GetSelection().GetEnd().GetPara() );
936cdf0e10cSrcweir mpImpl->mpTextEngine->mpIMEInfos = new TEIMEInfos( GetSelection().GetEnd(), pNode->GetText().Copy( GetSelection().GetEnd().GetIndex() ) );
937cdf0e10cSrcweir mpImpl->mpTextEngine->mpIMEInfos->bWasCursorOverwrite = !IsInsertMode();
938cdf0e10cSrcweir }
939cdf0e10cSrcweir else if ( rCEvt.GetCommand() == COMMAND_ENDEXTTEXTINPUT )
940cdf0e10cSrcweir {
941cdf0e10cSrcweir DBG_ASSERT( mpImpl->mpTextEngine->mpIMEInfos, "COMMAND_ENDEXTTEXTINPUT => Kein Start ?" );
942cdf0e10cSrcweir if( mpImpl->mpTextEngine->mpIMEInfos )
943cdf0e10cSrcweir {
944cdf0e10cSrcweir TEParaPortion* pPortion = mpImpl->mpTextEngine->mpTEParaPortions->GetObject( mpImpl->mpTextEngine->mpIMEInfos->aPos.GetPara() );
945cdf0e10cSrcweir pPortion->MarkSelectionInvalid( mpImpl->mpTextEngine->mpIMEInfos->aPos.GetIndex(), 0 );
946cdf0e10cSrcweir
947cdf0e10cSrcweir sal_Bool bInsertMode = !mpImpl->mpTextEngine->mpIMEInfos->bWasCursorOverwrite;
948cdf0e10cSrcweir
949cdf0e10cSrcweir delete mpImpl->mpTextEngine->mpIMEInfos;
950cdf0e10cSrcweir mpImpl->mpTextEngine->mpIMEInfos = NULL;
951cdf0e10cSrcweir
952cdf0e10cSrcweir mpImpl->mpTextEngine->FormatAndUpdate( this );
953cdf0e10cSrcweir
954cdf0e10cSrcweir SetInsertMode( bInsertMode );
955cdf0e10cSrcweir
956cdf0e10cSrcweir if ( mpImpl->mpTextEngine->IsModified() )
957cdf0e10cSrcweir mpImpl->mpTextEngine->Broadcast( TextHint( TEXT_HINT_MODIFIED ) );
958cdf0e10cSrcweir }
959cdf0e10cSrcweir }
960cdf0e10cSrcweir else if ( rCEvt.GetCommand() == COMMAND_EXTTEXTINPUT )
961cdf0e10cSrcweir {
962cdf0e10cSrcweir DBG_ASSERT( mpImpl->mpTextEngine->mpIMEInfos, "COMMAND_EXTTEXTINPUT => Kein Start ?" );
963cdf0e10cSrcweir if( mpImpl->mpTextEngine->mpIMEInfos )
964cdf0e10cSrcweir {
965cdf0e10cSrcweir const CommandExtTextInputData* pData = rCEvt.GetExtTextInputData();
966cdf0e10cSrcweir
967cdf0e10cSrcweir if ( !pData->IsOnlyCursorChanged() )
968cdf0e10cSrcweir {
969cdf0e10cSrcweir TextSelection aSelect( mpImpl->mpTextEngine->mpIMEInfos->aPos );
970cdf0e10cSrcweir aSelect.GetEnd().GetIndex() = aSelect.GetEnd().GetIndex() + mpImpl->mpTextEngine->mpIMEInfos->nLen;
971cdf0e10cSrcweir aSelect = mpImpl->mpTextEngine->ImpDeleteText( aSelect );
972cdf0e10cSrcweir aSelect = mpImpl->mpTextEngine->ImpInsertText( aSelect, pData->GetText() );
973cdf0e10cSrcweir
974cdf0e10cSrcweir if ( mpImpl->mpTextEngine->mpIMEInfos->bWasCursorOverwrite )
975cdf0e10cSrcweir {
976cdf0e10cSrcweir sal_uInt16 nOldIMETextLen = mpImpl->mpTextEngine->mpIMEInfos->nLen;
977cdf0e10cSrcweir sal_uInt16 nNewIMETextLen = pData->GetText().Len();
978cdf0e10cSrcweir
979cdf0e10cSrcweir if ( ( nOldIMETextLen > nNewIMETextLen ) &&
980cdf0e10cSrcweir ( nNewIMETextLen < mpImpl->mpTextEngine->mpIMEInfos->aOldTextAfterStartPos.Len() ) )
981cdf0e10cSrcweir {
982cdf0e10cSrcweir // restore old characters
983cdf0e10cSrcweir sal_uInt16 nRestore = nOldIMETextLen - nNewIMETextLen;
984cdf0e10cSrcweir TextPaM aPaM( mpImpl->mpTextEngine->mpIMEInfos->aPos );
985cdf0e10cSrcweir aPaM.GetIndex() = aPaM.GetIndex() + nNewIMETextLen;
986cdf0e10cSrcweir mpImpl->mpTextEngine->ImpInsertText( aPaM, mpImpl->mpTextEngine->mpIMEInfos->aOldTextAfterStartPos.Copy( nNewIMETextLen, nRestore ) );
987cdf0e10cSrcweir }
988cdf0e10cSrcweir else if ( ( nOldIMETextLen < nNewIMETextLen ) &&
989cdf0e10cSrcweir ( nOldIMETextLen < mpImpl->mpTextEngine->mpIMEInfos->aOldTextAfterStartPos.Len() ) )
990cdf0e10cSrcweir {
991cdf0e10cSrcweir // overwrite
992cdf0e10cSrcweir sal_uInt16 nOverwrite = nNewIMETextLen - nOldIMETextLen;
993cdf0e10cSrcweir if ( ( nOldIMETextLen + nOverwrite ) > mpImpl->mpTextEngine->mpIMEInfos->aOldTextAfterStartPos.Len() )
994cdf0e10cSrcweir nOverwrite = mpImpl->mpTextEngine->mpIMEInfos->aOldTextAfterStartPos.Len() - nOldIMETextLen;
995cdf0e10cSrcweir DBG_ASSERT( nOverwrite && (nOverwrite < 0xFF00), "IME Overwrite?!" );
996cdf0e10cSrcweir TextPaM aPaM( mpImpl->mpTextEngine->mpIMEInfos->aPos );
997cdf0e10cSrcweir aPaM.GetIndex() = aPaM.GetIndex() + nNewIMETextLen;
998cdf0e10cSrcweir TextSelection aSel( aPaM );
999cdf0e10cSrcweir aSel.GetEnd().GetIndex() =
1000cdf0e10cSrcweir aSel.GetEnd().GetIndex() + nOverwrite;
1001cdf0e10cSrcweir mpImpl->mpTextEngine->ImpDeleteText( aSel );
1002cdf0e10cSrcweir }
1003cdf0e10cSrcweir }
1004cdf0e10cSrcweir
1005cdf0e10cSrcweir if ( pData->GetTextAttr() )
1006cdf0e10cSrcweir {
1007cdf0e10cSrcweir mpImpl->mpTextEngine->mpIMEInfos->CopyAttribs( pData->GetTextAttr(), pData->GetText().Len() );
1008cdf0e10cSrcweir mpImpl->mpTextEngine->mpIMEInfos->bCursor = pData->IsCursorVisible();
1009cdf0e10cSrcweir }
1010cdf0e10cSrcweir else
1011cdf0e10cSrcweir {
1012cdf0e10cSrcweir mpImpl->mpTextEngine->mpIMEInfos->DestroyAttribs();
1013cdf0e10cSrcweir }
1014cdf0e10cSrcweir
1015cdf0e10cSrcweir TEParaPortion* pPPortion = mpImpl->mpTextEngine->mpTEParaPortions->GetObject( mpImpl->mpTextEngine->mpIMEInfos->aPos.GetPara() );
1016cdf0e10cSrcweir pPPortion->MarkSelectionInvalid( mpImpl->mpTextEngine->mpIMEInfos->aPos.GetIndex(), 0 );
1017cdf0e10cSrcweir mpImpl->mpTextEngine->FormatAndUpdate( this );
1018cdf0e10cSrcweir }
1019cdf0e10cSrcweir
1020cdf0e10cSrcweir TextSelection aNewSel = TextPaM( mpImpl->mpTextEngine->mpIMEInfos->aPos.GetPara(), mpImpl->mpTextEngine->mpIMEInfos->aPos.GetIndex()+pData->GetCursorPos() );
1021cdf0e10cSrcweir SetSelection( aNewSel );
1022cdf0e10cSrcweir SetInsertMode( !pData->IsCursorOverwrite() );
1023cdf0e10cSrcweir
1024cdf0e10cSrcweir if ( pData->IsCursorVisible() )
1025cdf0e10cSrcweir ShowCursor();
1026cdf0e10cSrcweir else
1027cdf0e10cSrcweir HideCursor();
1028cdf0e10cSrcweir }
1029cdf0e10cSrcweir }
1030cdf0e10cSrcweir else if ( rCEvt.GetCommand() == COMMAND_CURSORPOS )
1031cdf0e10cSrcweir {
1032cdf0e10cSrcweir if ( mpImpl->mpTextEngine->mpIMEInfos && mpImpl->mpTextEngine->mpIMEInfos->nLen )
1033cdf0e10cSrcweir {
1034cdf0e10cSrcweir TextPaM aPaM( GetSelection().GetEnd() );
1035cdf0e10cSrcweir Rectangle aR1 = mpImpl->mpTextEngine->PaMtoEditCursor( aPaM );
1036cdf0e10cSrcweir
1037cdf0e10cSrcweir sal_uInt16 nInputEnd = mpImpl->mpTextEngine->mpIMEInfos->aPos.GetIndex() + mpImpl->mpTextEngine->mpIMEInfos->nLen;
1038cdf0e10cSrcweir
1039cdf0e10cSrcweir if ( !mpImpl->mpTextEngine->IsFormatted() )
1040cdf0e10cSrcweir mpImpl->mpTextEngine->FormatDoc();
1041cdf0e10cSrcweir
1042cdf0e10cSrcweir TEParaPortion* pParaPortion = mpImpl->mpTextEngine->mpTEParaPortions->GetObject( aPaM.GetPara() );
1043cdf0e10cSrcweir sal_uInt16 nLine = pParaPortion->GetLineNumber( aPaM.GetIndex(), sal_True );
1044cdf0e10cSrcweir TextLine* pLine = pParaPortion->GetLines().GetObject( nLine );
1045cdf0e10cSrcweir if ( pLine && ( nInputEnd > pLine->GetEnd() ) )
1046cdf0e10cSrcweir nInputEnd = pLine->GetEnd();
1047cdf0e10cSrcweir Rectangle aR2 = mpImpl->mpTextEngine->PaMtoEditCursor( TextPaM( aPaM.GetPara(), nInputEnd ) );
1048cdf0e10cSrcweir
1049cdf0e10cSrcweir long nWidth = aR2.Left()-aR1.Right();
1050cdf0e10cSrcweir aR1.Move( -GetStartDocPos().X(), -GetStartDocPos().Y() );
1051cdf0e10cSrcweir GetWindow()->SetCursorRect( &aR1, nWidth );
1052cdf0e10cSrcweir }
1053cdf0e10cSrcweir else
1054cdf0e10cSrcweir {
1055cdf0e10cSrcweir GetWindow()->SetCursorRect();
1056cdf0e10cSrcweir }
1057cdf0e10cSrcweir }
1058cdf0e10cSrcweir else
1059cdf0e10cSrcweir {
1060cdf0e10cSrcweir mpImpl->mpSelEngine->Command( rCEvt );
1061cdf0e10cSrcweir }
1062cdf0e10cSrcweir }
1063cdf0e10cSrcweir
ShowCursor(sal_Bool bGotoCursor,sal_Bool bForceVisCursor)1064cdf0e10cSrcweir void TextView::ShowCursor( sal_Bool bGotoCursor, sal_Bool bForceVisCursor )
1065cdf0e10cSrcweir {
1066cdf0e10cSrcweir // Die Einstellung hat mehr Gewicht:
1067cdf0e10cSrcweir if ( !mpImpl->mbAutoScroll )
1068cdf0e10cSrcweir bGotoCursor = sal_False;
1069cdf0e10cSrcweir ImpShowCursor( bGotoCursor, bForceVisCursor, sal_False );
1070cdf0e10cSrcweir }
1071cdf0e10cSrcweir
HideCursor()1072cdf0e10cSrcweir void TextView::HideCursor()
1073cdf0e10cSrcweir {
1074cdf0e10cSrcweir mpImpl->mpCursor->Hide();
1075cdf0e10cSrcweir }
1076cdf0e10cSrcweir
Scroll(long ndX,long ndY)1077cdf0e10cSrcweir void TextView::Scroll( long ndX, long ndY )
1078cdf0e10cSrcweir {
1079cdf0e10cSrcweir DBG_ASSERT( mpImpl->mpTextEngine->IsFormatted(), "Scroll: Nicht formatiert!" );
1080cdf0e10cSrcweir
1081cdf0e10cSrcweir if ( !ndX && !ndY )
1082cdf0e10cSrcweir return;
1083cdf0e10cSrcweir
1084cdf0e10cSrcweir Point aNewStartPos( mpImpl->maStartDocPos );
1085cdf0e10cSrcweir
1086cdf0e10cSrcweir // Vertical:
1087cdf0e10cSrcweir aNewStartPos.Y() -= ndY;
1088cdf0e10cSrcweir if ( aNewStartPos.Y() < 0 )
1089cdf0e10cSrcweir aNewStartPos.Y() = 0;
1090cdf0e10cSrcweir
1091cdf0e10cSrcweir // Horizontal:
1092cdf0e10cSrcweir aNewStartPos.X() -= ndX;
1093cdf0e10cSrcweir if ( aNewStartPos.X() < 0 )
1094cdf0e10cSrcweir aNewStartPos.X() = 0;
1095cdf0e10cSrcweir
1096cdf0e10cSrcweir long nDiffX = mpImpl->maStartDocPos.X() - aNewStartPos.X();
1097cdf0e10cSrcweir long nDiffY = mpImpl->maStartDocPos.Y() - aNewStartPos.Y();
1098cdf0e10cSrcweir
1099cdf0e10cSrcweir if ( nDiffX || nDiffY )
1100cdf0e10cSrcweir {
1101cdf0e10cSrcweir sal_Bool bVisCursor = mpImpl->mpCursor->IsVisible();
1102cdf0e10cSrcweir mpImpl->mpCursor->Hide();
1103cdf0e10cSrcweir mpImpl->mpWindow->Update();
1104cdf0e10cSrcweir mpImpl->maStartDocPos = aNewStartPos;
1105cdf0e10cSrcweir
1106cdf0e10cSrcweir if ( mpImpl->mpTextEngine->IsRightToLeft() )
1107cdf0e10cSrcweir nDiffX = -nDiffX;
1108cdf0e10cSrcweir mpImpl->mpWindow->Scroll( nDiffX, nDiffY );
1109cdf0e10cSrcweir mpImpl->mpWindow->Update();
1110cdf0e10cSrcweir mpImpl->mpCursor->SetPos( mpImpl->mpCursor->GetPos() + Point( nDiffX, nDiffY ) );
1111cdf0e10cSrcweir if ( bVisCursor && !mpImpl->mbReadOnly )
1112cdf0e10cSrcweir mpImpl->mpCursor->Show();
1113cdf0e10cSrcweir }
1114cdf0e10cSrcweir
1115cdf0e10cSrcweir mpImpl->mpTextEngine->Broadcast( TextHint( TEXT_HINT_VIEWSCROLLED ) );
1116cdf0e10cSrcweir }
1117cdf0e10cSrcweir
Undo()1118cdf0e10cSrcweir void TextView::Undo()
1119cdf0e10cSrcweir {
1120cdf0e10cSrcweir mpImpl->mpTextEngine->SetActiveView( this );
1121cdf0e10cSrcweir mpImpl->mpTextEngine->GetUndoManager().Undo();
1122cdf0e10cSrcweir }
1123cdf0e10cSrcweir
Redo()1124cdf0e10cSrcweir void TextView::Redo()
1125cdf0e10cSrcweir {
1126cdf0e10cSrcweir mpImpl->mpTextEngine->SetActiveView( this );
1127cdf0e10cSrcweir mpImpl->mpTextEngine->GetUndoManager().Redo();
1128cdf0e10cSrcweir }
1129cdf0e10cSrcweir
Cut()1130cdf0e10cSrcweir void TextView::Cut()
1131cdf0e10cSrcweir {
1132cdf0e10cSrcweir mpImpl->mpTextEngine->UndoActionStart();
1133cdf0e10cSrcweir Copy();
1134cdf0e10cSrcweir DeleteSelected();
1135cdf0e10cSrcweir mpImpl->mpTextEngine->UndoActionEnd();
1136cdf0e10cSrcweir }
1137cdf0e10cSrcweir
Copy(uno::Reference<datatransfer::clipboard::XClipboard> & rxClipboard)1138cdf0e10cSrcweir void TextView::Copy( uno::Reference< datatransfer::clipboard::XClipboard >& rxClipboard )
1139cdf0e10cSrcweir {
1140cdf0e10cSrcweir if ( rxClipboard.is() )
1141cdf0e10cSrcweir {
1142cdf0e10cSrcweir TETextDataObject* pDataObj = new TETextDataObject( GetSelected() );
1143cdf0e10cSrcweir
1144cdf0e10cSrcweir if ( mpImpl->mpTextEngine->HasAttrib( TEXTATTR_HYPERLINK ) ) // Dann auch als HTML
1145cdf0e10cSrcweir mpImpl->mpTextEngine->Write( pDataObj->GetHTMLStream(), &mpImpl->maSelection, sal_True );
1146cdf0e10cSrcweir
1147cdf0e10cSrcweir const sal_uInt32 nRef = Application::ReleaseSolarMutex();
1148cdf0e10cSrcweir
1149cdf0e10cSrcweir try
1150cdf0e10cSrcweir {
1151cdf0e10cSrcweir rxClipboard->setContents( pDataObj, NULL );
1152cdf0e10cSrcweir
1153cdf0e10cSrcweir uno::Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( rxClipboard, uno::UNO_QUERY );
1154cdf0e10cSrcweir if( xFlushableClipboard.is() )
1155cdf0e10cSrcweir xFlushableClipboard->flushClipboard();
1156cdf0e10cSrcweir }
1157cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& )
1158cdf0e10cSrcweir {
1159cdf0e10cSrcweir }
1160cdf0e10cSrcweir
1161cdf0e10cSrcweir Application::AcquireSolarMutex( nRef );
1162cdf0e10cSrcweir }
1163cdf0e10cSrcweir }
1164cdf0e10cSrcweir
Copy()1165cdf0e10cSrcweir void TextView::Copy()
1166cdf0e10cSrcweir {
1167cdf0e10cSrcweir uno::Reference<datatransfer::clipboard::XClipboard> aClipboard(GetWindow()->GetClipboard());
1168cdf0e10cSrcweir Copy( aClipboard );
1169cdf0e10cSrcweir }
1170cdf0e10cSrcweir
Paste(uno::Reference<datatransfer::clipboard::XClipboard> & rxClipboard)1171cdf0e10cSrcweir void TextView::Paste( uno::Reference< datatransfer::clipboard::XClipboard >& rxClipboard )
1172cdf0e10cSrcweir {
1173cdf0e10cSrcweir if ( rxClipboard.is() )
1174cdf0e10cSrcweir {
1175cdf0e10cSrcweir uno::Reference< datatransfer::XTransferable > xDataObj;
1176cdf0e10cSrcweir
1177cdf0e10cSrcweir const sal_uInt32 nRef = Application::ReleaseSolarMutex();
1178cdf0e10cSrcweir
1179cdf0e10cSrcweir try
1180cdf0e10cSrcweir {
1181cdf0e10cSrcweir xDataObj = rxClipboard->getContents();
1182cdf0e10cSrcweir }
1183cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& )
1184cdf0e10cSrcweir {
1185cdf0e10cSrcweir }
1186cdf0e10cSrcweir
1187cdf0e10cSrcweir Application::AcquireSolarMutex( nRef );
1188cdf0e10cSrcweir
1189cdf0e10cSrcweir if ( xDataObj.is() )
1190cdf0e10cSrcweir {
1191cdf0e10cSrcweir datatransfer::DataFlavor aFlavor;
1192cdf0e10cSrcweir SotExchange::GetFormatDataFlavor( SOT_FORMAT_STRING, aFlavor );
1193cdf0e10cSrcweir if ( xDataObj->isDataFlavorSupported( aFlavor ) )
1194cdf0e10cSrcweir {
1195cdf0e10cSrcweir try
1196cdf0e10cSrcweir {
1197cdf0e10cSrcweir uno::Any aData = xDataObj->getTransferData( aFlavor );
1198cdf0e10cSrcweir ::rtl::OUString aText;
1199cdf0e10cSrcweir aData >>= aText;
1200cdf0e10cSrcweir bool bWasTruncated = false;
1201cdf0e10cSrcweir if( mpImpl->mpTextEngine->GetMaxTextLen() != 0 )
1202cdf0e10cSrcweir bWasTruncated = ImplTruncateNewText( aText );
1203cdf0e10cSrcweir InsertNewText( aText, sal_False );
1204cdf0e10cSrcweir mpImpl->mpTextEngine->Broadcast( TextHint( TEXT_HINT_MODIFIED ) );
1205cdf0e10cSrcweir
1206cdf0e10cSrcweir if( bWasTruncated )
1207cdf0e10cSrcweir Edit::ShowTruncationWarning( mpImpl->mpWindow );
1208cdf0e10cSrcweir }
1209cdf0e10cSrcweir catch( const ::com::sun::star::datatransfer::UnsupportedFlavorException& )
1210cdf0e10cSrcweir {
1211cdf0e10cSrcweir }
1212cdf0e10cSrcweir }
1213cdf0e10cSrcweir }
1214cdf0e10cSrcweir }
1215cdf0e10cSrcweir }
1216cdf0e10cSrcweir
Paste()1217cdf0e10cSrcweir void TextView::Paste()
1218cdf0e10cSrcweir {
1219cdf0e10cSrcweir uno::Reference<datatransfer::clipboard::XClipboard> aClipboard(GetWindow()->GetClipboard());
1220cdf0e10cSrcweir Paste( aClipboard );
1221cdf0e10cSrcweir }
1222cdf0e10cSrcweir
GetSelected()1223cdf0e10cSrcweir String TextView::GetSelected()
1224cdf0e10cSrcweir {
1225cdf0e10cSrcweir return GetSelected( GetSystemLineEnd() );
1226cdf0e10cSrcweir }
1227cdf0e10cSrcweir
GetSelected(LineEnd aSeparator)1228cdf0e10cSrcweir String TextView::GetSelected( LineEnd aSeparator )
1229cdf0e10cSrcweir {
1230cdf0e10cSrcweir return mpImpl->mpTextEngine->GetText( mpImpl->maSelection, aSeparator );
1231cdf0e10cSrcweir }
1232cdf0e10cSrcweir
SetInsertMode(sal_Bool bInsert)1233cdf0e10cSrcweir void TextView::SetInsertMode( sal_Bool bInsert )
1234cdf0e10cSrcweir {
1235cdf0e10cSrcweir if ( mpImpl->mbInsertMode != bInsert )
1236cdf0e10cSrcweir {
1237cdf0e10cSrcweir mpImpl->mbInsertMode = bInsert;
1238cdf0e10cSrcweir ShowCursor( mpImpl->mbAutoScroll, sal_False );
1239cdf0e10cSrcweir }
1240cdf0e10cSrcweir }
1241cdf0e10cSrcweir
SetReadOnly(sal_Bool bReadOnly)1242cdf0e10cSrcweir void TextView::SetReadOnly( sal_Bool bReadOnly )
1243cdf0e10cSrcweir {
1244cdf0e10cSrcweir if ( mpImpl->mbReadOnly != bReadOnly )
1245cdf0e10cSrcweir {
1246cdf0e10cSrcweir mpImpl->mbReadOnly = bReadOnly;
1247cdf0e10cSrcweir if ( !mpImpl->mbReadOnly )
1248cdf0e10cSrcweir ShowCursor( mpImpl->mbAutoScroll, sal_False );
1249cdf0e10cSrcweir else
1250cdf0e10cSrcweir HideCursor();
1251cdf0e10cSrcweir
1252cdf0e10cSrcweir GetWindow()->SetInputContext( InputContext( mpImpl->mpTextEngine->GetFont(), bReadOnly ? INPUTCONTEXT_TEXT|INPUTCONTEXT_EXTTEXTINPUT : 0 ) );
1253cdf0e10cSrcweir }
1254cdf0e10cSrcweir }
1255cdf0e10cSrcweir
ImpMoveCursor(const KeyEvent & rKeyEvent)1256cdf0e10cSrcweir TextSelection TextView::ImpMoveCursor( const KeyEvent& rKeyEvent )
1257cdf0e10cSrcweir {
1258cdf0e10cSrcweir // Eigentlich nur bei Up/Down noetig, aber was solls.
1259cdf0e10cSrcweir mpImpl->mpTextEngine->CheckIdleFormatter();
1260cdf0e10cSrcweir
1261cdf0e10cSrcweir TextPaM aPaM( mpImpl->maSelection.GetEnd() );
1262cdf0e10cSrcweir TextPaM aOldEnd( aPaM );
1263cdf0e10cSrcweir
1264cdf0e10cSrcweir TextDirectionality eTextDirection = TextDirectionality_LeftToRight_TopToBottom;
1265cdf0e10cSrcweir if ( mpImpl->mpTextEngine->IsRightToLeft() )
1266cdf0e10cSrcweir eTextDirection = TextDirectionality_RightToLeft_TopToBottom;
1267cdf0e10cSrcweir
1268cdf0e10cSrcweir KeyEvent aTranslatedKeyEvent = rKeyEvent.LogicalTextDirectionality( eTextDirection );
1269cdf0e10cSrcweir
1270cdf0e10cSrcweir sal_Bool bCtrl = aTranslatedKeyEvent.GetKeyCode().IsMod1() ? sal_True : sal_False;
1271cdf0e10cSrcweir sal_uInt16 nCode = aTranslatedKeyEvent.GetKeyCode().GetCode();
1272cdf0e10cSrcweir
1273cdf0e10cSrcweir bool bSelect = aTranslatedKeyEvent.GetKeyCode().IsShift();
1274cdf0e10cSrcweir switch ( nCode )
1275cdf0e10cSrcweir {
1276cdf0e10cSrcweir case KEY_UP: aPaM = CursorUp( aPaM );
1277cdf0e10cSrcweir break;
1278cdf0e10cSrcweir case KEY_DOWN: aPaM = CursorDown( aPaM );
1279cdf0e10cSrcweir break;
1280cdf0e10cSrcweir case KEY_HOME: aPaM = bCtrl ? CursorStartOfDoc() : CursorStartOfLine( aPaM );
1281cdf0e10cSrcweir break;
1282cdf0e10cSrcweir case KEY_END: aPaM = bCtrl ? CursorEndOfDoc() : CursorEndOfLine( aPaM );
1283cdf0e10cSrcweir break;
1284cdf0e10cSrcweir case KEY_PAGEUP: aPaM = bCtrl ? CursorStartOfDoc() : PageUp( aPaM );
1285cdf0e10cSrcweir break;
1286cdf0e10cSrcweir case KEY_PAGEDOWN: aPaM = bCtrl ? CursorEndOfDoc() : PageDown( aPaM );
1287cdf0e10cSrcweir break;
1288cdf0e10cSrcweir case KEY_LEFT: aPaM = bCtrl ? CursorWordLeft( aPaM ) : CursorLeft( aPaM, aTranslatedKeyEvent.GetKeyCode().IsMod2() ? (sal_uInt16)i18n::CharacterIteratorMode::SKIPCHARACTER : (sal_uInt16)i18n::CharacterIteratorMode::SKIPCELL );
1289cdf0e10cSrcweir break;
1290cdf0e10cSrcweir case KEY_RIGHT: aPaM = bCtrl ? CursorWordRight( aPaM ) : CursorRight( aPaM, aTranslatedKeyEvent.GetKeyCode().IsMod2() ? (sal_uInt16)i18n::CharacterIteratorMode::SKIPCHARACTER : (sal_uInt16)i18n::CharacterIteratorMode::SKIPCELL );
1291cdf0e10cSrcweir break;
1292cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_WORD_FORWARD:
1293cdf0e10cSrcweir bSelect = true; // fallthrough intentional
1294cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_WORD_FORWARD:
1295cdf0e10cSrcweir aPaM = CursorWordRight( aPaM );
1296cdf0e10cSrcweir break;
1297cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_WORD_BACKWARD:
1298cdf0e10cSrcweir bSelect = true; // fallthrough intentional
1299cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_WORD_BACKWARD:
1300cdf0e10cSrcweir aPaM = CursorWordLeft( aPaM );
1301cdf0e10cSrcweir break;
1302cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_BEGIN_OF_LINE:
1303cdf0e10cSrcweir bSelect = true; // fallthrough intentional
1304cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_BEGIN_OF_LINE:
1305cdf0e10cSrcweir aPaM = CursorStartOfLine( aPaM );
1306cdf0e10cSrcweir break;
1307cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_END_OF_LINE:
1308cdf0e10cSrcweir bSelect = true; // fallthrough intentional
1309cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_END_OF_LINE:
1310cdf0e10cSrcweir aPaM = CursorEndOfLine( aPaM );
1311cdf0e10cSrcweir break;
1312cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_BEGIN_OF_PARAGRAPH:
1313cdf0e10cSrcweir bSelect = true; // falltthrough intentional
1314cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_BEGIN_OF_PARAGRAPH:
1315cdf0e10cSrcweir aPaM = CursorStartOfParagraph( aPaM );
1316cdf0e10cSrcweir break;
1317cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_END_OF_PARAGRAPH:
1318cdf0e10cSrcweir bSelect = true; // falltthrough intentional
1319cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_END_OF_PARAGRAPH:
1320cdf0e10cSrcweir aPaM = CursorEndOfParagraph( aPaM );
1321cdf0e10cSrcweir break;
1322cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_BEGIN_OF_DOCUMENT:
1323cdf0e10cSrcweir bSelect = true; // falltthrough intentional
1324cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_BEGIN_OF_DOCUMENT:
1325cdf0e10cSrcweir aPaM = CursorStartOfDoc();
1326cdf0e10cSrcweir break;
1327cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_END_OF_DOCUMENT:
1328cdf0e10cSrcweir bSelect = true; // falltthrough intentional
1329cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_END_OF_DOCUMENT:
1330cdf0e10cSrcweir aPaM = CursorEndOfDoc();
1331cdf0e10cSrcweir break;
1332cdf0e10cSrcweir }
1333cdf0e10cSrcweir
1334cdf0e10cSrcweir // Bewirkt evtl. ein CreateAnchor oder Deselection all
1335cdf0e10cSrcweir mpImpl->mpSelEngine->CursorPosChanging( bSelect, aTranslatedKeyEvent.GetKeyCode().IsMod1() );
1336cdf0e10cSrcweir
1337cdf0e10cSrcweir if ( aOldEnd != aPaM )
1338cdf0e10cSrcweir {
1339cdf0e10cSrcweir mpImpl->mpTextEngine->CursorMoved( aOldEnd.GetPara() );
1340cdf0e10cSrcweir
1341cdf0e10cSrcweir
1342cdf0e10cSrcweir TextSelection aOldSelection( mpImpl->maSelection );
1343cdf0e10cSrcweir TextSelection aNewSelection( mpImpl->maSelection );
1344cdf0e10cSrcweir aNewSelection.GetEnd() = aPaM;
1345cdf0e10cSrcweir if ( bSelect )
1346cdf0e10cSrcweir {
1347cdf0e10cSrcweir // Dann wird die Selektion erweitert...
1348cdf0e10cSrcweir ImpSetSelection( aNewSelection );
1349cdf0e10cSrcweir ShowSelection( TextSelection( aOldEnd, aPaM ) );
1350cdf0e10cSrcweir }
1351cdf0e10cSrcweir else
1352cdf0e10cSrcweir {
1353cdf0e10cSrcweir aNewSelection.GetStart() = aPaM;
1354cdf0e10cSrcweir ImpSetSelection( aNewSelection );
1355cdf0e10cSrcweir }
1356cdf0e10cSrcweir }
1357cdf0e10cSrcweir
1358cdf0e10cSrcweir return mpImpl->maSelection;
1359cdf0e10cSrcweir }
1360cdf0e10cSrcweir
InsertText(const XubString & rStr,sal_Bool bSelect)1361cdf0e10cSrcweir void TextView::InsertText( const XubString& rStr, sal_Bool bSelect )
1362cdf0e10cSrcweir {
1363cdf0e10cSrcweir InsertNewText( rStr, bSelect );
1364cdf0e10cSrcweir }
1365cdf0e10cSrcweir
InsertNewText(const rtl::OUString & rStr,sal_Bool bSelect)1366cdf0e10cSrcweir void TextView::InsertNewText( const rtl::OUString& rStr, sal_Bool bSelect )
1367cdf0e10cSrcweir {
1368cdf0e10cSrcweir // HideSelection();
1369cdf0e10cSrcweir mpImpl->mpTextEngine->UndoActionStart();
1370cdf0e10cSrcweir
1371cdf0e10cSrcweir /* #i87633#
1372cdf0e10cSrcweir break inserted text into chunks that fit into the underlying String
1373cdf0e10cSrcweir based API (which has a maximum length of 65534 elements
1374cdf0e10cSrcweir
1375cdf0e10cSrcweir note: this will of course still cause problems for lines longer than those
1376cdf0e10cSrcweir 65534 elements, but those cases will hopefully be few.
1377cdf0e10cSrcweir In the long run someone should switch the TextEngine to OUString instead of String
1378cdf0e10cSrcweir */
1379cdf0e10cSrcweir sal_Int32 nLen = rStr.getLength();
1380cdf0e10cSrcweir sal_Int32 nPos = 0;
1381*16fc0e9dSTsutomu Uchino do
1382cdf0e10cSrcweir {
1383cdf0e10cSrcweir sal_Int32 nChunkLen = nLen > 65534 ? 65534 : nLen;
1384cdf0e10cSrcweir String aChunk( rStr.copy( nPos, nChunkLen ) );
1385cdf0e10cSrcweir
1386cdf0e10cSrcweir TextSelection aNewSel( mpImpl->maSelection );
1387cdf0e10cSrcweir
1388cdf0e10cSrcweir TextPaM aPaM = mpImpl->mpTextEngine->ImpInsertText( mpImpl->maSelection, aChunk );
1389cdf0e10cSrcweir
1390cdf0e10cSrcweir if ( bSelect )
1391cdf0e10cSrcweir {
1392cdf0e10cSrcweir aNewSel.Justify();
1393cdf0e10cSrcweir aNewSel.GetEnd() = aPaM;
1394cdf0e10cSrcweir }
1395cdf0e10cSrcweir else
1396cdf0e10cSrcweir {
1397cdf0e10cSrcweir aNewSel = aPaM;
1398cdf0e10cSrcweir }
1399cdf0e10cSrcweir
1400cdf0e10cSrcweir ImpSetSelection( aNewSel );
1401cdf0e10cSrcweir nLen -= nChunkLen;
1402cdf0e10cSrcweir nPos += nChunkLen;
1403*16fc0e9dSTsutomu Uchino } while( nLen );
1404cdf0e10cSrcweir mpImpl->mpTextEngine->UndoActionEnd();
1405cdf0e10cSrcweir
1406cdf0e10cSrcweir mpImpl->mpTextEngine->FormatAndUpdate( this );
1407cdf0e10cSrcweir }
1408cdf0e10cSrcweir
1409cdf0e10cSrcweir /*
1410cdf0e10cSrcweir void TextView::InsertText( const XubString& rStr, sal_Bool bSelect )
1411cdf0e10cSrcweir {
1412cdf0e10cSrcweir // HideSelection();
1413cdf0e10cSrcweir
1414cdf0e10cSrcweir TextSelection aNewSel( mpImpl->maSelection );
1415cdf0e10cSrcweir
1416cdf0e10cSrcweir mpImpl->mpTextEngine->UndoActionStart();
1417cdf0e10cSrcweir TextPaM aPaM = mpImpl->mpTextEngine->ImpInsertText( mpImpl->maSelection, rStr );
1418cdf0e10cSrcweir mpImpl->mpTextEngine->UndoActionEnd();
1419cdf0e10cSrcweir
1420cdf0e10cSrcweir if ( bSelect )
1421cdf0e10cSrcweir {
1422cdf0e10cSrcweir aNewSel.Justify();
1423cdf0e10cSrcweir aNewSel.GetEnd() = aPaM;
1424cdf0e10cSrcweir }
1425cdf0e10cSrcweir else
1426cdf0e10cSrcweir {
1427cdf0e10cSrcweir aNewSel = aPaM;
1428cdf0e10cSrcweir }
1429cdf0e10cSrcweir
1430cdf0e10cSrcweir ImpSetSelection( aNewSel );
1431cdf0e10cSrcweir
1432cdf0e10cSrcweir mpImpl->mpTextEngine->FormatAndUpdate( this );
1433cdf0e10cSrcweir }
1434cdf0e10cSrcweir */
1435cdf0e10cSrcweir
1436cdf0e10cSrcweir // OLD
CursorLeft(const TextPaM & rPaM,sal_Bool bWordMode)1437cdf0e10cSrcweir TextPaM TextView::CursorLeft( const TextPaM& rPaM, sal_Bool bWordMode )
1438cdf0e10cSrcweir {
1439cdf0e10cSrcweir return bWordMode ? CursorWordLeft( rPaM ) : CursorLeft( rPaM, (sal_uInt16)i18n::CharacterIteratorMode::SKIPCELL );
1440cdf0e10cSrcweir
1441cdf0e10cSrcweir // Remove (sal_uInt16) typecasts in this file when removing this method!
1442cdf0e10cSrcweir }
1443cdf0e10cSrcweir
1444cdf0e10cSrcweir // OLD
CursorRight(const TextPaM & rPaM,sal_Bool bWordMode)1445cdf0e10cSrcweir TextPaM TextView::CursorRight( const TextPaM& rPaM, sal_Bool bWordMode )
1446cdf0e10cSrcweir {
1447cdf0e10cSrcweir return bWordMode ? CursorWordRight( rPaM ) : CursorRight( rPaM, (sal_uInt16)i18n::CharacterIteratorMode::SKIPCELL );
1448cdf0e10cSrcweir
1449cdf0e10cSrcweir // Remove (sal_uInt16) typecasts in this file when removing this method!
1450cdf0e10cSrcweir }
1451cdf0e10cSrcweir
CursorLeft(const TextPaM & rPaM,sal_uInt16 nCharacterIteratorMode)1452cdf0e10cSrcweir TextPaM TextView::CursorLeft( const TextPaM& rPaM, sal_uInt16 nCharacterIteratorMode )
1453cdf0e10cSrcweir {
1454cdf0e10cSrcweir TextPaM aPaM( rPaM );
1455cdf0e10cSrcweir
1456cdf0e10cSrcweir if ( aPaM.GetIndex() )
1457cdf0e10cSrcweir {
1458cdf0e10cSrcweir TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes().GetObject( aPaM.GetPara() );
1459cdf0e10cSrcweir uno::Reference < i18n::XBreakIterator > xBI = mpImpl->mpTextEngine->GetBreakIterator();
1460cdf0e10cSrcweir sal_Int32 nCount = 1;
1461cdf0e10cSrcweir aPaM.GetIndex() = (sal_uInt16)xBI->previousCharacters( pNode->GetText(), aPaM.GetIndex(), mpImpl->mpTextEngine->GetLocale(), nCharacterIteratorMode, nCount, nCount );
1462cdf0e10cSrcweir }
1463cdf0e10cSrcweir else if ( aPaM.GetPara() )
1464cdf0e10cSrcweir {
1465cdf0e10cSrcweir aPaM.GetPara()--;
1466cdf0e10cSrcweir TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes().GetObject( aPaM.GetPara() );
1467cdf0e10cSrcweir aPaM.GetIndex() = pNode->GetText().Len();
1468cdf0e10cSrcweir }
1469cdf0e10cSrcweir return aPaM;
1470cdf0e10cSrcweir }
1471cdf0e10cSrcweir
CursorRight(const TextPaM & rPaM,sal_uInt16 nCharacterIteratorMode)1472cdf0e10cSrcweir TextPaM TextView::CursorRight( const TextPaM& rPaM, sal_uInt16 nCharacterIteratorMode )
1473cdf0e10cSrcweir {
1474cdf0e10cSrcweir TextPaM aPaM( rPaM );
1475cdf0e10cSrcweir
1476cdf0e10cSrcweir TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes().GetObject( aPaM.GetPara() );
1477cdf0e10cSrcweir if ( aPaM.GetIndex() < pNode->GetText().Len() )
1478cdf0e10cSrcweir {
1479cdf0e10cSrcweir uno::Reference < i18n::XBreakIterator > xBI = mpImpl->mpTextEngine->GetBreakIterator();
1480cdf0e10cSrcweir sal_Int32 nCount = 1;
1481cdf0e10cSrcweir aPaM.GetIndex() = (sal_uInt16)xBI->nextCharacters( pNode->GetText(), aPaM.GetIndex(), mpImpl->mpTextEngine->GetLocale(), nCharacterIteratorMode, nCount, nCount );
1482cdf0e10cSrcweir }
1483cdf0e10cSrcweir else if ( aPaM.GetPara() < ( mpImpl->mpTextEngine->mpDoc->GetNodes().Count()-1) )
1484cdf0e10cSrcweir {
1485cdf0e10cSrcweir aPaM.GetPara()++;
1486cdf0e10cSrcweir aPaM.GetIndex() = 0;
1487cdf0e10cSrcweir }
1488cdf0e10cSrcweir
1489cdf0e10cSrcweir return aPaM;
1490cdf0e10cSrcweir }
1491cdf0e10cSrcweir
1492cdf0e10cSrcweir
CursorWordLeft(const TextPaM & rPaM)1493cdf0e10cSrcweir TextPaM TextView::CursorWordLeft( const TextPaM& rPaM )
1494cdf0e10cSrcweir {
1495cdf0e10cSrcweir TextPaM aPaM( rPaM );
1496cdf0e10cSrcweir
1497cdf0e10cSrcweir if ( aPaM.GetIndex() )
1498cdf0e10cSrcweir {
1499cdf0e10cSrcweir TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes().GetObject( aPaM.GetPara() );
1500cdf0e10cSrcweir uno::Reference < i18n::XBreakIterator > xBI = mpImpl->mpTextEngine->GetBreakIterator();
1501cdf0e10cSrcweir i18n::Boundary aBoundary = xBI->getWordBoundary( pNode->GetText(), rPaM.GetIndex(), mpImpl->mpTextEngine->GetLocale(), i18n::WordType::ANYWORD_IGNOREWHITESPACES, sal_True );
1502cdf0e10cSrcweir if ( aBoundary.startPos >= rPaM.GetIndex() )
1503cdf0e10cSrcweir aBoundary = xBI->previousWord( pNode->GetText(), rPaM.GetIndex(), mpImpl->mpTextEngine->GetLocale(), i18n::WordType::ANYWORD_IGNOREWHITESPACES );
1504cdf0e10cSrcweir aPaM.GetIndex() = ( aBoundary.startPos != -1 ) ? (sal_uInt16)aBoundary.startPos : 0;
1505cdf0e10cSrcweir }
1506cdf0e10cSrcweir else if ( aPaM.GetPara() )
1507cdf0e10cSrcweir {
1508cdf0e10cSrcweir aPaM.GetPara()--;
1509cdf0e10cSrcweir TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes().GetObject( aPaM.GetPara() );
1510cdf0e10cSrcweir aPaM.GetIndex() = pNode->GetText().Len();
1511cdf0e10cSrcweir }
1512cdf0e10cSrcweir return aPaM;
1513cdf0e10cSrcweir }
1514cdf0e10cSrcweir
1515cdf0e10cSrcweir
CursorWordRight(const TextPaM & rPaM)1516cdf0e10cSrcweir TextPaM TextView::CursorWordRight( const TextPaM& rPaM )
1517cdf0e10cSrcweir {
1518cdf0e10cSrcweir TextPaM aPaM( rPaM );
1519cdf0e10cSrcweir
1520cdf0e10cSrcweir TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes().GetObject( aPaM.GetPara() );
1521cdf0e10cSrcweir if ( aPaM.GetIndex() < pNode->GetText().Len() )
1522cdf0e10cSrcweir {
1523cdf0e10cSrcweir uno::Reference < i18n::XBreakIterator > xBI = mpImpl->mpTextEngine->GetBreakIterator();
1524cdf0e10cSrcweir i18n::Boundary aBoundary = xBI->nextWord( pNode->GetText(), aPaM.GetIndex(), mpImpl->mpTextEngine->GetLocale(), i18n::WordType::ANYWORD_IGNOREWHITESPACES );
1525cdf0e10cSrcweir aPaM.GetIndex() = (sal_uInt16)aBoundary.startPos;
1526cdf0e10cSrcweir }
1527cdf0e10cSrcweir else if ( aPaM.GetPara() < ( mpImpl->mpTextEngine->mpDoc->GetNodes().Count()-1) )
1528cdf0e10cSrcweir {
1529cdf0e10cSrcweir aPaM.GetPara()++;
1530cdf0e10cSrcweir aPaM.GetIndex() = 0;
1531cdf0e10cSrcweir }
1532cdf0e10cSrcweir
1533cdf0e10cSrcweir return aPaM;
1534cdf0e10cSrcweir }
1535cdf0e10cSrcweir
ImpDelete(sal_uInt8 nMode,sal_uInt8 nDelMode)1536cdf0e10cSrcweir TextPaM TextView::ImpDelete( sal_uInt8 nMode, sal_uInt8 nDelMode )
1537cdf0e10cSrcweir {
1538cdf0e10cSrcweir if ( mpImpl->maSelection.HasRange() ) // dann nur Sel. loeschen
1539cdf0e10cSrcweir return mpImpl->mpTextEngine->ImpDeleteText( mpImpl->maSelection );
1540cdf0e10cSrcweir
1541cdf0e10cSrcweir TextPaM aStartPaM = mpImpl->maSelection.GetStart();
1542cdf0e10cSrcweir TextPaM aEndPaM = aStartPaM;
1543cdf0e10cSrcweir if ( nMode == DEL_LEFT )
1544cdf0e10cSrcweir {
1545cdf0e10cSrcweir if ( nDelMode == DELMODE_SIMPLE )
1546cdf0e10cSrcweir {
1547cdf0e10cSrcweir aEndPaM = CursorLeft( aEndPaM, (sal_uInt16)i18n::CharacterIteratorMode::SKIPCHARACTER );
1548cdf0e10cSrcweir }
1549cdf0e10cSrcweir else if ( nDelMode == DELMODE_RESTOFWORD )
1550cdf0e10cSrcweir {
1551cdf0e10cSrcweir TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes().GetObject( aEndPaM.GetPara() );
1552cdf0e10cSrcweir uno::Reference < i18n::XBreakIterator > xBI = mpImpl->mpTextEngine->GetBreakIterator();
1553cdf0e10cSrcweir i18n::Boundary aBoundary = xBI->getWordBoundary( pNode->GetText(), mpImpl->maSelection.GetEnd().GetIndex(), mpImpl->mpTextEngine->GetLocale(), i18n::WordType::ANYWORD_IGNOREWHITESPACES, sal_True );
1554cdf0e10cSrcweir if ( aBoundary.startPos == mpImpl->maSelection.GetEnd().GetIndex() )
1555cdf0e10cSrcweir aBoundary = xBI->previousWord( pNode->GetText(), mpImpl->maSelection.GetEnd().GetIndex(), mpImpl->mpTextEngine->GetLocale(), i18n::WordType::ANYWORD_IGNOREWHITESPACES );
1556cdf0e10cSrcweir // #i63506# startPos is -1 when the paragraph starts with a tab
1557cdf0e10cSrcweir aEndPaM.GetIndex() = (aBoundary.startPos >= 0) ? (sal_uInt16)aBoundary.startPos : 0;
1558cdf0e10cSrcweir }
1559cdf0e10cSrcweir else // DELMODE_RESTOFCONTENT
1560cdf0e10cSrcweir {
1561cdf0e10cSrcweir if ( aEndPaM.GetIndex() != 0 )
1562cdf0e10cSrcweir aEndPaM.GetIndex() = 0;
1563cdf0e10cSrcweir else if ( aEndPaM.GetPara() )
1564cdf0e10cSrcweir {
1565cdf0e10cSrcweir // Absatz davor
1566cdf0e10cSrcweir aEndPaM.GetPara()--;
1567cdf0e10cSrcweir aEndPaM.GetIndex() = 0;
1568cdf0e10cSrcweir }
1569cdf0e10cSrcweir }
1570cdf0e10cSrcweir }
1571cdf0e10cSrcweir else
1572cdf0e10cSrcweir {
1573cdf0e10cSrcweir if ( nDelMode == DELMODE_SIMPLE )
1574cdf0e10cSrcweir {
1575cdf0e10cSrcweir aEndPaM = CursorRight( aEndPaM, (sal_uInt16)i18n::CharacterIteratorMode::SKIPCELL );
1576cdf0e10cSrcweir }
1577cdf0e10cSrcweir else if ( nDelMode == DELMODE_RESTOFWORD )
1578cdf0e10cSrcweir {
1579cdf0e10cSrcweir TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes().GetObject( aEndPaM.GetPara() );
1580cdf0e10cSrcweir uno::Reference < i18n::XBreakIterator > xBI = mpImpl->mpTextEngine->GetBreakIterator();
1581cdf0e10cSrcweir i18n::Boundary aBoundary = xBI->nextWord( pNode->GetText(), mpImpl->maSelection.GetEnd().GetIndex(), mpImpl->mpTextEngine->GetLocale(), i18n::WordType::ANYWORD_IGNOREWHITESPACES );
1582cdf0e10cSrcweir aEndPaM.GetIndex() = (sal_uInt16)aBoundary.startPos;
1583cdf0e10cSrcweir }
1584cdf0e10cSrcweir else // DELMODE_RESTOFCONTENT
1585cdf0e10cSrcweir {
1586cdf0e10cSrcweir TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes().GetObject( aEndPaM.GetPara() );
1587cdf0e10cSrcweir if ( aEndPaM.GetIndex() < pNode->GetText().Len() )
1588cdf0e10cSrcweir aEndPaM.GetIndex() = pNode->GetText().Len();
1589cdf0e10cSrcweir else if ( aEndPaM.GetPara() < ( mpImpl->mpTextEngine->mpDoc->GetNodes().Count() - 1 ) )
1590cdf0e10cSrcweir {
1591cdf0e10cSrcweir // Absatz danach
1592cdf0e10cSrcweir aEndPaM.GetPara()++;
1593cdf0e10cSrcweir TextNode* pNextNode = mpImpl->mpTextEngine->mpDoc->GetNodes().GetObject( aEndPaM.GetPara() );
1594cdf0e10cSrcweir aEndPaM.GetIndex() = pNextNode->GetText().Len();
1595cdf0e10cSrcweir }
1596cdf0e10cSrcweir }
1597cdf0e10cSrcweir }
1598cdf0e10cSrcweir
1599cdf0e10cSrcweir return mpImpl->mpTextEngine->ImpDeleteText( TextSelection( aStartPaM, aEndPaM ) );
1600cdf0e10cSrcweir }
1601cdf0e10cSrcweir
1602cdf0e10cSrcweir
1603cdf0e10cSrcweir
CursorUp(const TextPaM & rPaM)1604cdf0e10cSrcweir TextPaM TextView::CursorUp( const TextPaM& rPaM )
1605cdf0e10cSrcweir {
1606cdf0e10cSrcweir TextPaM aPaM( rPaM );
1607cdf0e10cSrcweir
1608cdf0e10cSrcweir long nX;
1609cdf0e10cSrcweir if ( mpImpl->mnTravelXPos == TRAVEL_X_DONTKNOW )
1610cdf0e10cSrcweir {
1611cdf0e10cSrcweir nX = mpImpl->mpTextEngine->GetEditCursor( rPaM, sal_False ).Left();
1612cdf0e10cSrcweir mpImpl->mnTravelXPos = (sal_uInt16)nX+1;
1613cdf0e10cSrcweir }
1614cdf0e10cSrcweir else
1615cdf0e10cSrcweir nX = mpImpl->mnTravelXPos;
1616cdf0e10cSrcweir
1617cdf0e10cSrcweir TEParaPortion* pPPortion = mpImpl->mpTextEngine->mpTEParaPortions->GetObject( rPaM.GetPara() );
1618cdf0e10cSrcweir sal_uInt16 nLine = pPPortion->GetLineNumber( rPaM.GetIndex(), sal_False );
1619cdf0e10cSrcweir if ( nLine ) // gleicher Absatz
1620cdf0e10cSrcweir {
1621cdf0e10cSrcweir sal_uInt16 nCharPos = mpImpl->mpTextEngine->GetCharPos( rPaM.GetPara(), nLine-1, nX );
1622cdf0e10cSrcweir aPaM.GetIndex() = nCharPos;
1623cdf0e10cSrcweir // Wenn davor eine autom.Umgebrochene Zeile, und ich muss genau an das
1624cdf0e10cSrcweir // Ende dieser Zeile, landet der Cursor in der aktuellen Zeile am Anfang
1625cdf0e10cSrcweir // Siehe Problem: Letztes Zeichen einer autom.umgebr. Zeile = Cursor
1626cdf0e10cSrcweir TextLine* pLine = pPPortion->GetLines().GetObject( nLine - 1 );
1627cdf0e10cSrcweir if ( aPaM.GetIndex() && ( aPaM.GetIndex() == pLine->GetEnd() ) )
1628cdf0e10cSrcweir aPaM.GetIndex()--;
1629cdf0e10cSrcweir }
1630cdf0e10cSrcweir else if ( rPaM.GetPara() ) // vorheriger Absatz
1631cdf0e10cSrcweir {
1632cdf0e10cSrcweir aPaM.GetPara()--;
1633cdf0e10cSrcweir pPPortion = mpImpl->mpTextEngine->mpTEParaPortions->GetObject( aPaM.GetPara() );
1634cdf0e10cSrcweir sal_uInt16 nL = pPPortion->GetLines().Count() - 1;
1635cdf0e10cSrcweir sal_uInt16 nCharPos = mpImpl->mpTextEngine->GetCharPos( aPaM.GetPara(), nL, nX+1 );
1636cdf0e10cSrcweir aPaM.GetIndex() = nCharPos;
1637cdf0e10cSrcweir }
1638cdf0e10cSrcweir
1639cdf0e10cSrcweir return aPaM;
1640cdf0e10cSrcweir }
1641cdf0e10cSrcweir
CursorDown(const TextPaM & rPaM)1642cdf0e10cSrcweir TextPaM TextView::CursorDown( const TextPaM& rPaM )
1643cdf0e10cSrcweir {
1644cdf0e10cSrcweir TextPaM aPaM( rPaM );
1645cdf0e10cSrcweir
1646cdf0e10cSrcweir long nX;
1647cdf0e10cSrcweir if ( mpImpl->mnTravelXPos == TRAVEL_X_DONTKNOW )
1648cdf0e10cSrcweir {
1649cdf0e10cSrcweir nX = mpImpl->mpTextEngine->GetEditCursor( rPaM, sal_False ).Left();
1650cdf0e10cSrcweir mpImpl->mnTravelXPos = (sal_uInt16)nX+1;
1651cdf0e10cSrcweir }
1652cdf0e10cSrcweir else
1653cdf0e10cSrcweir nX = mpImpl->mnTravelXPos;
1654cdf0e10cSrcweir
1655cdf0e10cSrcweir TEParaPortion* pPPortion = mpImpl->mpTextEngine->mpTEParaPortions->GetObject( rPaM.GetPara() );
1656cdf0e10cSrcweir sal_uInt16 nLine = pPPortion->GetLineNumber( rPaM.GetIndex(), sal_False );
1657cdf0e10cSrcweir if ( nLine < ( pPPortion->GetLines().Count() - 1 ) )
1658cdf0e10cSrcweir {
1659cdf0e10cSrcweir sal_uInt16 nCharPos = mpImpl->mpTextEngine->GetCharPos( rPaM.GetPara(), nLine+1, nX );
1660cdf0e10cSrcweir aPaM.GetIndex() = nCharPos;
1661cdf0e10cSrcweir
1662cdf0e10cSrcweir // Sonderbehandlung siehe CursorUp...
1663cdf0e10cSrcweir TextLine* pLine = pPPortion->GetLines().GetObject( nLine + 1 );
1664cdf0e10cSrcweir if ( ( aPaM.GetIndex() == pLine->GetEnd() ) && ( aPaM.GetIndex() > pLine->GetStart() ) && aPaM.GetIndex() < pPPortion->GetNode()->GetText().Len() )
1665cdf0e10cSrcweir aPaM.GetIndex()--;
1666cdf0e10cSrcweir }
1667cdf0e10cSrcweir else if ( rPaM.GetPara() < ( mpImpl->mpTextEngine->mpDoc->GetNodes().Count() - 1 ) ) // naechster Absatz
1668cdf0e10cSrcweir {
1669cdf0e10cSrcweir aPaM.GetPara()++;
1670cdf0e10cSrcweir pPPortion = mpImpl->mpTextEngine->mpTEParaPortions->GetObject( aPaM.GetPara() );
1671cdf0e10cSrcweir sal_uInt16 nCharPos = mpImpl->mpTextEngine->GetCharPos( aPaM.GetPara(), 0, nX+1 );
1672cdf0e10cSrcweir aPaM.GetIndex() = nCharPos;
1673cdf0e10cSrcweir TextLine* pLine = pPPortion->GetLines().GetObject( 0 );
1674cdf0e10cSrcweir if ( ( aPaM.GetIndex() == pLine->GetEnd() ) && ( aPaM.GetIndex() > pLine->GetStart() ) && ( pPPortion->GetLines().Count() > 1 ) )
1675cdf0e10cSrcweir aPaM.GetIndex()--;
1676cdf0e10cSrcweir }
1677cdf0e10cSrcweir
1678cdf0e10cSrcweir return aPaM;
1679cdf0e10cSrcweir }
1680cdf0e10cSrcweir
CursorStartOfLine(const TextPaM & rPaM)1681cdf0e10cSrcweir TextPaM TextView::CursorStartOfLine( const TextPaM& rPaM )
1682cdf0e10cSrcweir {
1683cdf0e10cSrcweir TextPaM aPaM( rPaM );
1684cdf0e10cSrcweir
1685cdf0e10cSrcweir TEParaPortion* pPPortion = mpImpl->mpTextEngine->mpTEParaPortions->GetObject( rPaM.GetPara() );
1686cdf0e10cSrcweir sal_uInt16 nLine = pPPortion->GetLineNumber( aPaM.GetIndex(), sal_False );
1687cdf0e10cSrcweir TextLine* pLine = pPPortion->GetLines().GetObject( nLine );
1688cdf0e10cSrcweir aPaM.GetIndex() = pLine->GetStart();
1689cdf0e10cSrcweir
1690cdf0e10cSrcweir return aPaM;
1691cdf0e10cSrcweir }
1692cdf0e10cSrcweir
CursorEndOfLine(const TextPaM & rPaM)1693cdf0e10cSrcweir TextPaM TextView::CursorEndOfLine( const TextPaM& rPaM )
1694cdf0e10cSrcweir {
1695cdf0e10cSrcweir TextPaM aPaM( rPaM );
1696cdf0e10cSrcweir
1697cdf0e10cSrcweir TEParaPortion* pPPortion = mpImpl->mpTextEngine->mpTEParaPortions->GetObject( rPaM.GetPara() );
1698cdf0e10cSrcweir sal_uInt16 nLine = pPPortion->GetLineNumber( aPaM.GetIndex(), sal_False );
1699cdf0e10cSrcweir TextLine* pLine = pPPortion->GetLines().GetObject( nLine );
1700cdf0e10cSrcweir aPaM.GetIndex() = pLine->GetEnd();
1701cdf0e10cSrcweir
1702cdf0e10cSrcweir if ( pLine->GetEnd() > pLine->GetStart() ) // Leerzeile
1703cdf0e10cSrcweir {
1704cdf0e10cSrcweir xub_Unicode cLastChar = pPPortion->GetNode()->GetText().GetChar((sal_uInt16)(aPaM.GetIndex()-1) );
1705cdf0e10cSrcweir if ( ( cLastChar == ' ' ) && ( aPaM.GetIndex() != pPPortion->GetNode()->GetText().Len() ) )
1706cdf0e10cSrcweir {
1707cdf0e10cSrcweir // Bei einem Blank in einer autom. umgebrochenen Zeile macht es Sinn,
1708cdf0e10cSrcweir // davor zu stehen, da der Anwender hinter das Wort will.
1709cdf0e10cSrcweir // Wenn diese geaendert wird, Sonderbehandlung fuer Pos1 nach End!
1710cdf0e10cSrcweir aPaM.GetIndex()--;
1711cdf0e10cSrcweir }
1712cdf0e10cSrcweir }
1713cdf0e10cSrcweir return aPaM;
1714cdf0e10cSrcweir }
1715cdf0e10cSrcweir
CursorStartOfParagraph(const TextPaM & rPaM)1716cdf0e10cSrcweir TextPaM TextView::CursorStartOfParagraph( const TextPaM& rPaM )
1717cdf0e10cSrcweir {
1718cdf0e10cSrcweir TextPaM aPaM( rPaM );
1719cdf0e10cSrcweir aPaM.GetIndex() = 0;
1720cdf0e10cSrcweir return aPaM;
1721cdf0e10cSrcweir }
1722cdf0e10cSrcweir
CursorEndOfParagraph(const TextPaM & rPaM)1723cdf0e10cSrcweir TextPaM TextView::CursorEndOfParagraph( const TextPaM& rPaM )
1724cdf0e10cSrcweir {
1725cdf0e10cSrcweir TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes().GetObject( rPaM.GetPara() );
1726cdf0e10cSrcweir TextPaM aPaM( rPaM );
1727cdf0e10cSrcweir aPaM.GetIndex() = pNode->GetText().Len();
1728cdf0e10cSrcweir return aPaM;
1729cdf0e10cSrcweir }
1730cdf0e10cSrcweir
CursorStartOfDoc()1731cdf0e10cSrcweir TextPaM TextView::CursorStartOfDoc()
1732cdf0e10cSrcweir {
1733cdf0e10cSrcweir TextPaM aPaM( 0, 0 );
1734cdf0e10cSrcweir return aPaM;
1735cdf0e10cSrcweir }
1736cdf0e10cSrcweir
CursorEndOfDoc()1737cdf0e10cSrcweir TextPaM TextView::CursorEndOfDoc()
1738cdf0e10cSrcweir {
1739cdf0e10cSrcweir sal_uLong nNode = mpImpl->mpTextEngine->mpDoc->GetNodes().Count() - 1;
1740cdf0e10cSrcweir TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes().GetObject( nNode );
1741cdf0e10cSrcweir TextPaM aPaM( nNode, pNode->GetText().Len() );
1742cdf0e10cSrcweir return aPaM;
1743cdf0e10cSrcweir }
1744cdf0e10cSrcweir
PageUp(const TextPaM & rPaM)1745cdf0e10cSrcweir TextPaM TextView::PageUp( const TextPaM& rPaM )
1746cdf0e10cSrcweir {
1747cdf0e10cSrcweir Rectangle aRec = mpImpl->mpTextEngine->PaMtoEditCursor( rPaM );
1748cdf0e10cSrcweir Point aTopLeft = aRec.TopLeft();
1749cdf0e10cSrcweir aTopLeft.Y() -= mpImpl->mpWindow->GetOutputSizePixel().Height() * 9/10;
1750cdf0e10cSrcweir aTopLeft.X() += 1;
1751cdf0e10cSrcweir if ( aTopLeft.Y() < 0 )
1752cdf0e10cSrcweir aTopLeft.Y() = 0;
1753cdf0e10cSrcweir
1754cdf0e10cSrcweir TextPaM aPaM = mpImpl->mpTextEngine->GetPaM( aTopLeft );
1755cdf0e10cSrcweir return aPaM;
1756cdf0e10cSrcweir }
1757cdf0e10cSrcweir
PageDown(const TextPaM & rPaM)1758cdf0e10cSrcweir TextPaM TextView::PageDown( const TextPaM& rPaM )
1759cdf0e10cSrcweir {
1760cdf0e10cSrcweir Rectangle aRec = mpImpl->mpTextEngine->PaMtoEditCursor( rPaM );
1761cdf0e10cSrcweir Point aBottomRight = aRec.BottomRight();
1762cdf0e10cSrcweir aBottomRight.Y() += mpImpl->mpWindow->GetOutputSizePixel().Height() * 9/10;
1763cdf0e10cSrcweir aBottomRight.X() += 1;
1764cdf0e10cSrcweir long nHeight = mpImpl->mpTextEngine->GetTextHeight();
1765cdf0e10cSrcweir if ( aBottomRight.Y() > nHeight )
1766cdf0e10cSrcweir aBottomRight.Y() = nHeight-1;
1767cdf0e10cSrcweir
1768cdf0e10cSrcweir TextPaM aPaM = mpImpl->mpTextEngine->GetPaM( aBottomRight );
1769cdf0e10cSrcweir return aPaM;
1770cdf0e10cSrcweir }
1771cdf0e10cSrcweir
ImpShowCursor(sal_Bool bGotoCursor,sal_Bool bForceVisCursor,sal_Bool bSpecial)1772cdf0e10cSrcweir void TextView::ImpShowCursor( sal_Bool bGotoCursor, sal_Bool bForceVisCursor, sal_Bool bSpecial )
1773cdf0e10cSrcweir {
1774cdf0e10cSrcweir if ( mpImpl->mpTextEngine->IsFormatting() )
1775cdf0e10cSrcweir return;
1776cdf0e10cSrcweir if ( mpImpl->mpTextEngine->GetUpdateMode() == sal_False )
1777cdf0e10cSrcweir return;
1778cdf0e10cSrcweir if ( mpImpl->mpTextEngine->IsInUndo() )
1779cdf0e10cSrcweir return;
1780cdf0e10cSrcweir
1781cdf0e10cSrcweir mpImpl->mpTextEngine->CheckIdleFormatter();
1782cdf0e10cSrcweir if ( !mpImpl->mpTextEngine->IsFormatted() )
1783cdf0e10cSrcweir mpImpl->mpTextEngine->FormatAndUpdate( this );
1784cdf0e10cSrcweir
1785cdf0e10cSrcweir
1786cdf0e10cSrcweir TextPaM aPaM( mpImpl->maSelection.GetEnd() );
1787cdf0e10cSrcweir Rectangle aEditCursor = mpImpl->mpTextEngine->PaMtoEditCursor( aPaM, bSpecial );
1788cdf0e10cSrcweir
1789cdf0e10cSrcweir // Remember that we placed the cursor behind the last character of a line
1790cdf0e10cSrcweir mpImpl->mbCursorAtEndOfLine = false;
1791cdf0e10cSrcweir if( bSpecial )
1792cdf0e10cSrcweir {
1793cdf0e10cSrcweir TEParaPortion* pParaPortion = mpImpl->mpTextEngine->mpTEParaPortions->GetObject( aPaM.GetPara() );
1794cdf0e10cSrcweir mpImpl->mbCursorAtEndOfLine =
1795cdf0e10cSrcweir pParaPortion->GetLineNumber( aPaM.GetIndex(), sal_True ) != pParaPortion->GetLineNumber( aPaM.GetIndex(), sal_False );
1796cdf0e10cSrcweir }
1797cdf0e10cSrcweir
1798cdf0e10cSrcweir if ( !IsInsertMode() && !mpImpl->maSelection.HasRange() )
1799cdf0e10cSrcweir {
1800cdf0e10cSrcweir TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes().GetObject( aPaM.GetPara() );
1801cdf0e10cSrcweir if ( pNode->GetText().Len() && ( aPaM.GetIndex() < pNode->GetText().Len() ) )
1802cdf0e10cSrcweir {
1803cdf0e10cSrcweir // If we are behind a portion, and the next portion has other direction, we must change position...
1804cdf0e10cSrcweir aEditCursor.Left() = aEditCursor.Right() = mpImpl->mpTextEngine->GetEditCursor( aPaM, sal_False, sal_True ).Left();
1805cdf0e10cSrcweir
1806cdf0e10cSrcweir TEParaPortion* pParaPortion = mpImpl->mpTextEngine->mpTEParaPortions->GetObject( aPaM.GetPara() );
1807cdf0e10cSrcweir
1808cdf0e10cSrcweir sal_uInt16 nTextPortionStart = 0;
1809cdf0e10cSrcweir sal_uInt16 nTextPortion = pParaPortion->GetTextPortions().FindPortion( aPaM.GetIndex(), nTextPortionStart, sal_True );
1810cdf0e10cSrcweir TETextPortion* pTextPortion = pParaPortion->GetTextPortions().GetObject( nTextPortion );
1811cdf0e10cSrcweir if ( pTextPortion->GetKind() == PORTIONKIND_TAB )
1812cdf0e10cSrcweir {
1813cdf0e10cSrcweir if ( mpImpl->mpTextEngine->IsRightToLeft() )
1814cdf0e10cSrcweir {
1815cdf0e10cSrcweir
1816cdf0e10cSrcweir }
1817cdf0e10cSrcweir aEditCursor.Right() += pTextPortion->GetWidth();
1818cdf0e10cSrcweir }
1819cdf0e10cSrcweir else
1820cdf0e10cSrcweir {
1821cdf0e10cSrcweir TextPaM aNext = CursorRight( TextPaM( aPaM.GetPara(), aPaM.GetIndex() ), (sal_uInt16)i18n::CharacterIteratorMode::SKIPCELL );
1822cdf0e10cSrcweir aEditCursor.Right() = mpImpl->mpTextEngine->GetEditCursor( aNext, sal_True ).Left();
1823cdf0e10cSrcweir }
1824cdf0e10cSrcweir }
1825cdf0e10cSrcweir }
1826cdf0e10cSrcweir
1827cdf0e10cSrcweir Size aOutSz = mpImpl->mpWindow->GetOutputSizePixel();
1828cdf0e10cSrcweir if ( aEditCursor.GetHeight() > aOutSz.Height() )
1829cdf0e10cSrcweir aEditCursor.Bottom() = aEditCursor.Top() + aOutSz.Height() - 1;
1830cdf0e10cSrcweir
1831cdf0e10cSrcweir aEditCursor.Left() -= 1;
1832cdf0e10cSrcweir
1833cdf0e10cSrcweir if ( bGotoCursor
1834cdf0e10cSrcweir // #i81283# protext maStartDocPos against initialization problems
1835cdf0e10cSrcweir && aOutSz.Width() && aOutSz.Height()
1836cdf0e10cSrcweir )
1837cdf0e10cSrcweir {
1838cdf0e10cSrcweir long nVisStartY = mpImpl->maStartDocPos.Y();
1839cdf0e10cSrcweir long nVisEndY = mpImpl->maStartDocPos.Y() + aOutSz.Height();
1840cdf0e10cSrcweir long nVisStartX = mpImpl->maStartDocPos.X();
1841cdf0e10cSrcweir long nVisEndX = mpImpl->maStartDocPos.X() + aOutSz.Width();
1842cdf0e10cSrcweir long nMoreX = aOutSz.Width() / 4;
1843cdf0e10cSrcweir
1844cdf0e10cSrcweir Point aNewStartPos( mpImpl->maStartDocPos );
1845cdf0e10cSrcweir
1846cdf0e10cSrcweir if ( aEditCursor.Bottom() > nVisEndY )
1847cdf0e10cSrcweir {
1848cdf0e10cSrcweir aNewStartPos.Y() += ( aEditCursor.Bottom() - nVisEndY );
1849cdf0e10cSrcweir }
1850cdf0e10cSrcweir else if ( aEditCursor.Top() < nVisStartY )
1851cdf0e10cSrcweir {
1852cdf0e10cSrcweir aNewStartPos.Y() -= ( nVisStartY - aEditCursor.Top() );
1853cdf0e10cSrcweir }
1854cdf0e10cSrcweir
1855cdf0e10cSrcweir if ( aEditCursor.Right() >= nVisEndX )
1856cdf0e10cSrcweir {
1857cdf0e10cSrcweir aNewStartPos.X() += ( aEditCursor.Right() - nVisEndX );
1858cdf0e10cSrcweir
1859cdf0e10cSrcweir // Darfs ein bischen mehr sein?
1860cdf0e10cSrcweir aNewStartPos.X() += nMoreX;
1861cdf0e10cSrcweir }
1862cdf0e10cSrcweir else if ( aEditCursor.Left() <= nVisStartX )
1863cdf0e10cSrcweir {
1864cdf0e10cSrcweir aNewStartPos.X() -= ( nVisStartX - aEditCursor.Left() );
1865cdf0e10cSrcweir
1866cdf0e10cSrcweir // Darfs ein bischen mehr sein?
1867cdf0e10cSrcweir aNewStartPos.X() -= nMoreX;
1868cdf0e10cSrcweir }
1869cdf0e10cSrcweir
1870cdf0e10cSrcweir // X kann durch das 'bischen mehr' falsch sein:
1871cdf0e10cSrcweir // sal_uLong nMaxTextWidth = mpImpl->mpTextEngine->GetMaxTextWidth();
1872cdf0e10cSrcweir // if ( !nMaxTextWidth || ( nMaxTextWidth > 0x7FFFFFFF ) )
1873cdf0e10cSrcweir // nMaxTextWidth = 0x7FFFFFFF;
1874cdf0e10cSrcweir // long nMaxX = (long)nMaxTextWidth - aOutSz.Width();
1875cdf0e10cSrcweir long nMaxX = mpImpl->mpTextEngine->CalcTextWidth() - aOutSz.Width();
1876cdf0e10cSrcweir if ( nMaxX < 0 )
1877cdf0e10cSrcweir nMaxX = 0;
1878cdf0e10cSrcweir
1879cdf0e10cSrcweir if ( aNewStartPos.X() < 0 )
1880cdf0e10cSrcweir aNewStartPos.X() = 0;
1881cdf0e10cSrcweir else if ( aNewStartPos.X() > nMaxX )
1882cdf0e10cSrcweir aNewStartPos.X() = nMaxX;
1883cdf0e10cSrcweir
1884cdf0e10cSrcweir // Y sollte nicht weiter unten als noetig liegen:
1885cdf0e10cSrcweir long nYMax = mpImpl->mpTextEngine->GetTextHeight() - aOutSz.Height();
1886cdf0e10cSrcweir if ( nYMax < 0 )
1887cdf0e10cSrcweir nYMax = 0;
1888cdf0e10cSrcweir if ( aNewStartPos.Y() > nYMax )
1889cdf0e10cSrcweir aNewStartPos.Y() = nYMax;
1890cdf0e10cSrcweir
1891cdf0e10cSrcweir if ( aNewStartPos != mpImpl->maStartDocPos )
1892cdf0e10cSrcweir Scroll( -(aNewStartPos.X() - mpImpl->maStartDocPos.X()), -(aNewStartPos.Y() - mpImpl->maStartDocPos.Y()) );
1893cdf0e10cSrcweir }
1894cdf0e10cSrcweir
1895cdf0e10cSrcweir if ( aEditCursor.Right() < aEditCursor.Left() )
1896cdf0e10cSrcweir {
1897cdf0e10cSrcweir long n = aEditCursor.Left();
1898cdf0e10cSrcweir aEditCursor.Left() = aEditCursor.Right();
1899cdf0e10cSrcweir aEditCursor.Right() = n;
1900cdf0e10cSrcweir }
1901cdf0e10cSrcweir
1902cdf0e10cSrcweir Point aPoint( GetWindowPos( !mpImpl->mpTextEngine->IsRightToLeft() ? aEditCursor.TopLeft() : aEditCursor.TopRight() ) );
1903cdf0e10cSrcweir mpImpl->mpCursor->SetPos( aPoint );
1904cdf0e10cSrcweir mpImpl->mpCursor->SetSize( aEditCursor.GetSize() );
1905cdf0e10cSrcweir if ( bForceVisCursor && mpImpl->mbCursorEnabled )
1906cdf0e10cSrcweir mpImpl->mpCursor->Show();
1907cdf0e10cSrcweir }
1908cdf0e10cSrcweir
SetCursorAtPoint(const Point & rPosPixel)1909cdf0e10cSrcweir sal_Bool TextView::SetCursorAtPoint( const Point& rPosPixel )
1910cdf0e10cSrcweir {
1911cdf0e10cSrcweir mpImpl->mpTextEngine->CheckIdleFormatter();
1912cdf0e10cSrcweir
1913cdf0e10cSrcweir Point aDocPos = GetDocPos( rPosPixel );
1914cdf0e10cSrcweir
1915cdf0e10cSrcweir TextPaM aPaM = mpImpl->mpTextEngine->GetPaM( aDocPos );
1916cdf0e10cSrcweir
1917cdf0e10cSrcweir // aTmpNewSel: Diff zwischen alt und neu, nicht die neue Selektion
1918cdf0e10cSrcweir TextSelection aTmpNewSel( mpImpl->maSelection.GetEnd(), aPaM );
1919cdf0e10cSrcweir TextSelection aNewSel( mpImpl->maSelection );
1920cdf0e10cSrcweir aNewSel.GetEnd() = aPaM;
1921cdf0e10cSrcweir
1922cdf0e10cSrcweir if ( !mpImpl->mpSelEngine->HasAnchor() )
1923cdf0e10cSrcweir {
1924cdf0e10cSrcweir if ( mpImpl->maSelection.GetStart() != aPaM )
1925cdf0e10cSrcweir mpImpl->mpTextEngine->CursorMoved( mpImpl->maSelection.GetStart().GetPara() );
1926cdf0e10cSrcweir aNewSel.GetStart() = aPaM;
1927cdf0e10cSrcweir ImpSetSelection( aNewSel );
1928cdf0e10cSrcweir }
1929cdf0e10cSrcweir else
1930cdf0e10cSrcweir {
1931cdf0e10cSrcweir ImpSetSelection( aNewSel );
1932cdf0e10cSrcweir ShowSelection( aTmpNewSel );
1933cdf0e10cSrcweir }
1934cdf0e10cSrcweir
1935cdf0e10cSrcweir sal_Bool bForceCursor = mpImpl->mpDDInfo ? sal_False : sal_True; // && !mbInSelection
1936cdf0e10cSrcweir ImpShowCursor( mpImpl->mbAutoScroll, bForceCursor, sal_False );
1937cdf0e10cSrcweir return sal_True;
1938cdf0e10cSrcweir }
1939cdf0e10cSrcweir
IsSelectionAtPoint(const Point & rPosPixel)1940cdf0e10cSrcweir sal_Bool TextView::IsSelectionAtPoint( const Point& rPosPixel )
1941cdf0e10cSrcweir {
1942cdf0e10cSrcweir // if ( !Rectangle( Point(), mpImpl->mpWindow->GetOutputSizePixel() ).IsInside( rPosPixel ) && !mbInSelection )
1943cdf0e10cSrcweir // return sal_False;
1944cdf0e10cSrcweir
1945cdf0e10cSrcweir Point aDocPos = GetDocPos( rPosPixel );
1946cdf0e10cSrcweir TextPaM aPaM = mpImpl->mpTextEngine->GetPaM( aDocPos, sal_False );
1947cdf0e10cSrcweir // Bei Hyperlinks D&D auch ohne Selektion starten.
1948cdf0e10cSrcweir // BeginDrag wird aber nur gerufen, wenn IsSelectionAtPoint()
1949cdf0e10cSrcweir // Problem: IsSelectionAtPoint wird bei Command() nicht gerufen,
1950cdf0e10cSrcweir // wenn vorher im MBDown schon sal_False returnt wurde.
1951cdf0e10cSrcweir return ( IsInSelection( aPaM ) ||
1952cdf0e10cSrcweir ( /* mpImpl->mpSelEngine->IsInCommand() && */ mpImpl->mpTextEngine->FindAttrib( aPaM, TEXTATTR_HYPERLINK ) ) );
1953cdf0e10cSrcweir }
1954cdf0e10cSrcweir
IsInSelection(const TextPaM & rPaM)1955cdf0e10cSrcweir sal_Bool TextView::IsInSelection( const TextPaM& rPaM )
1956cdf0e10cSrcweir {
1957cdf0e10cSrcweir TextSelection aSel = mpImpl->maSelection;
1958cdf0e10cSrcweir aSel.Justify();
1959cdf0e10cSrcweir
1960cdf0e10cSrcweir sal_uLong nStartNode = aSel.GetStart().GetPara();
1961cdf0e10cSrcweir sal_uLong nEndNode = aSel.GetEnd().GetPara();
1962cdf0e10cSrcweir sal_uLong nCurNode = rPaM.GetPara();
1963cdf0e10cSrcweir
1964cdf0e10cSrcweir if ( ( nCurNode > nStartNode ) && ( nCurNode < nEndNode ) )
1965cdf0e10cSrcweir return sal_True;
1966cdf0e10cSrcweir
1967cdf0e10cSrcweir if ( nStartNode == nEndNode )
1968cdf0e10cSrcweir {
1969cdf0e10cSrcweir if ( nCurNode == nStartNode )
1970cdf0e10cSrcweir if ( ( rPaM.GetIndex() >= aSel.GetStart().GetIndex() ) && ( rPaM.GetIndex() < aSel.GetEnd().GetIndex() ) )
1971cdf0e10cSrcweir return sal_True;
1972cdf0e10cSrcweir }
1973cdf0e10cSrcweir else if ( ( nCurNode == nStartNode ) && ( rPaM.GetIndex() >= aSel.GetStart().GetIndex() ) )
1974cdf0e10cSrcweir return sal_True;
1975cdf0e10cSrcweir else if ( ( nCurNode == nEndNode ) && ( rPaM.GetIndex() < aSel.GetEnd().GetIndex() ) )
1976cdf0e10cSrcweir return sal_True;
1977cdf0e10cSrcweir
1978cdf0e10cSrcweir return sal_False;
1979cdf0e10cSrcweir }
1980cdf0e10cSrcweir
ImpHideDDCursor()1981cdf0e10cSrcweir void TextView::ImpHideDDCursor()
1982cdf0e10cSrcweir {
1983cdf0e10cSrcweir if ( mpImpl->mpDDInfo && mpImpl->mpDDInfo->mbVisCursor )
1984cdf0e10cSrcweir {
1985cdf0e10cSrcweir mpImpl->mpDDInfo->maCursor.Hide();
1986cdf0e10cSrcweir mpImpl->mpDDInfo->mbVisCursor = sal_False;
1987cdf0e10cSrcweir }
1988cdf0e10cSrcweir }
1989cdf0e10cSrcweir
ImpShowDDCursor()1990cdf0e10cSrcweir void TextView::ImpShowDDCursor()
1991cdf0e10cSrcweir {
1992cdf0e10cSrcweir if ( !mpImpl->mpDDInfo->mbVisCursor )
1993cdf0e10cSrcweir {
1994cdf0e10cSrcweir Rectangle aCursor = mpImpl->mpTextEngine->PaMtoEditCursor( mpImpl->mpDDInfo->maDropPos, sal_True );
1995cdf0e10cSrcweir aCursor.Right()++;
1996cdf0e10cSrcweir aCursor.SetPos( GetWindowPos( aCursor.TopLeft() ) );
1997cdf0e10cSrcweir
1998cdf0e10cSrcweir mpImpl->mpDDInfo->maCursor.SetWindow( mpImpl->mpWindow );
1999cdf0e10cSrcweir mpImpl->mpDDInfo->maCursor.SetPos( aCursor.TopLeft() );
2000cdf0e10cSrcweir mpImpl->mpDDInfo->maCursor.SetSize( aCursor.GetSize() );
2001cdf0e10cSrcweir mpImpl->mpDDInfo->maCursor.Show();
2002cdf0e10cSrcweir mpImpl->mpDDInfo->mbVisCursor = sal_True;
2003cdf0e10cSrcweir }
2004cdf0e10cSrcweir }
2005cdf0e10cSrcweir
SetPaintSelection(sal_Bool bPaint)2006cdf0e10cSrcweir void TextView::SetPaintSelection( sal_Bool bPaint )
2007cdf0e10cSrcweir {
2008cdf0e10cSrcweir if ( bPaint != mpImpl->mbPaintSelection )
2009cdf0e10cSrcweir {
2010cdf0e10cSrcweir mpImpl->mbPaintSelection = bPaint;
2011cdf0e10cSrcweir ShowSelection( mpImpl->maSelection );
2012cdf0e10cSrcweir }
2013cdf0e10cSrcweir }
2014cdf0e10cSrcweir
SetHighlightSelection(sal_Bool bSelectByHighlight)2015cdf0e10cSrcweir void TextView::SetHighlightSelection( sal_Bool bSelectByHighlight )
2016cdf0e10cSrcweir {
2017cdf0e10cSrcweir if ( bSelectByHighlight != mpImpl->mbHighlightSelection )
2018cdf0e10cSrcweir {
2019cdf0e10cSrcweir // Falls umschalten zwischendurch moeglich...
2020cdf0e10cSrcweir mpImpl->mbHighlightSelection = bSelectByHighlight;
2021cdf0e10cSrcweir }
2022cdf0e10cSrcweir }
2023cdf0e10cSrcweir
Read(SvStream & rInput)2024cdf0e10cSrcweir sal_Bool TextView::Read( SvStream& rInput )
2025cdf0e10cSrcweir {
2026cdf0e10cSrcweir sal_Bool bDone = mpImpl->mpTextEngine->Read( rInput, &mpImpl->maSelection );
2027cdf0e10cSrcweir ShowCursor();
2028cdf0e10cSrcweir return bDone;
2029cdf0e10cSrcweir }
2030cdf0e10cSrcweir
Write(SvStream & rOutput)2031cdf0e10cSrcweir sal_Bool TextView::Write( SvStream& rOutput )
2032cdf0e10cSrcweir {
2033cdf0e10cSrcweir return mpImpl->mpTextEngine->Read( rOutput, &mpImpl->maSelection );
2034cdf0e10cSrcweir }
2035cdf0e10cSrcweir
ImplTruncateNewText(rtl::OUString & rNewText) const2036cdf0e10cSrcweir bool TextView::ImplTruncateNewText( rtl::OUString& rNewText ) const
2037cdf0e10cSrcweir {
2038cdf0e10cSrcweir bool bTruncated = false;
2039cdf0e10cSrcweir
2040cdf0e10cSrcweir if( rNewText.getLength() > 65534 ) // limit to String API
2041cdf0e10cSrcweir {
2042cdf0e10cSrcweir rNewText = rNewText.copy( 0, 65534 );
2043cdf0e10cSrcweir bTruncated = true;
2044cdf0e10cSrcweir }
2045cdf0e10cSrcweir
2046cdf0e10cSrcweir sal_uLong nMaxLen = mpImpl->mpTextEngine->GetMaxTextLen();
2047cdf0e10cSrcweir // 0 means unlimited, there is just the String API limit handled above
2048cdf0e10cSrcweir if( nMaxLen != 0 )
2049cdf0e10cSrcweir {
2050cdf0e10cSrcweir sal_uLong nCurLen = mpImpl->mpTextEngine->GetTextLen();
2051cdf0e10cSrcweir
2052cdf0e10cSrcweir sal_uInt32 nNewLen = rNewText.getLength();
2053cdf0e10cSrcweir if ( nCurLen + nNewLen > nMaxLen )
2054cdf0e10cSrcweir {
2055cdf0e10cSrcweir // see how much text will be replaced
2056cdf0e10cSrcweir sal_uLong nSelLen = mpImpl->mpTextEngine->GetTextLen( mpImpl->maSelection );
2057cdf0e10cSrcweir if ( nCurLen + nNewLen - nSelLen > nMaxLen )
2058cdf0e10cSrcweir {
2059cdf0e10cSrcweir sal_uInt32 nTruncatedLen = static_cast<sal_uInt32>(nMaxLen - (nCurLen - nSelLen));
2060cdf0e10cSrcweir rNewText = rNewText.copy( 0, nTruncatedLen );
2061cdf0e10cSrcweir bTruncated = true;
2062cdf0e10cSrcweir }
2063cdf0e10cSrcweir }
2064cdf0e10cSrcweir }
2065cdf0e10cSrcweir return bTruncated;
2066cdf0e10cSrcweir }
2067cdf0e10cSrcweir
ImplCheckTextLen(const String & rNewText)2068cdf0e10cSrcweir sal_Bool TextView::ImplCheckTextLen( const String& rNewText )
2069cdf0e10cSrcweir {
2070cdf0e10cSrcweir sal_Bool bOK = sal_True;
2071cdf0e10cSrcweir if ( mpImpl->mpTextEngine->GetMaxTextLen() )
2072cdf0e10cSrcweir {
2073cdf0e10cSrcweir sal_uLong n = mpImpl->mpTextEngine->GetTextLen();
2074cdf0e10cSrcweir n += rNewText.Len();
2075cdf0e10cSrcweir if ( n > mpImpl->mpTextEngine->GetMaxTextLen() )
2076cdf0e10cSrcweir {
2077cdf0e10cSrcweir // nur dann noch ermitteln, wie viel Text geloescht wird
2078cdf0e10cSrcweir n -= mpImpl->mpTextEngine->GetTextLen( mpImpl->maSelection );
2079cdf0e10cSrcweir if ( n > mpImpl->mpTextEngine->GetMaxTextLen() )
2080cdf0e10cSrcweir {
2081cdf0e10cSrcweir // Beep hat hier eigentlich nichts verloren, sondern lieber ein Hdl,
2082cdf0e10cSrcweir // aber so funktioniert es wenigstens in ME, BasicIDE, SourceView
2083cdf0e10cSrcweir Sound::Beep();
2084cdf0e10cSrcweir bOK = sal_False;
2085cdf0e10cSrcweir }
2086cdf0e10cSrcweir }
2087cdf0e10cSrcweir }
2088cdf0e10cSrcweir return bOK;
2089cdf0e10cSrcweir }
2090cdf0e10cSrcweir
dragGestureRecognized(const::com::sun::star::datatransfer::dnd::DragGestureEvent & rDGE)2091cdf0e10cSrcweir void TextView::dragGestureRecognized( const ::com::sun::star::datatransfer::dnd::DragGestureEvent& rDGE ) throw (::com::sun::star::uno::RuntimeException)
2092cdf0e10cSrcweir {
2093cdf0e10cSrcweir if ( mpImpl->mbClickedInSelection )
2094cdf0e10cSrcweir {
2095cdf0e10cSrcweir vos::OGuard aVclGuard( Application::GetSolarMutex() );
2096cdf0e10cSrcweir
2097cdf0e10cSrcweir DBG_ASSERT( mpImpl->maSelection.HasRange(), "TextView::dragGestureRecognized: mpImpl->mbClickedInSelection, but no selection?" );
2098cdf0e10cSrcweir
2099cdf0e10cSrcweir delete mpImpl->mpDDInfo;
2100cdf0e10cSrcweir mpImpl->mpDDInfo = new TextDDInfo;
2101cdf0e10cSrcweir mpImpl->mpDDInfo->mbStarterOfDD = sal_True;
2102cdf0e10cSrcweir
2103cdf0e10cSrcweir TETextDataObject* pDataObj = new TETextDataObject( GetSelected() );
2104cdf0e10cSrcweir
2105cdf0e10cSrcweir if ( mpImpl->mpTextEngine->HasAttrib( TEXTATTR_HYPERLINK ) ) // Dann auch als HTML
2106cdf0e10cSrcweir mpImpl->mpTextEngine->Write( pDataObj->GetHTMLStream(), &mpImpl->maSelection, sal_True );
2107cdf0e10cSrcweir
2108cdf0e10cSrcweir
2109cdf0e10cSrcweir /*
2110cdf0e10cSrcweir // D&D eines Hyperlinks.
2111cdf0e10cSrcweir // Besser waere es im MBDown sich den MBDownPaM zu merken,
2112cdf0e10cSrcweir // ist dann aber inkompatibel => spaeter mal umstellen.
2113cdf0e10cSrcweir TextPaM aPaM( mpImpl->mpTextEngine->GetPaM( GetDocPos( GetWindow()->GetPointerPosPixel() ) ) );
2114cdf0e10cSrcweir const TextCharAttrib* pAttr = mpImpl->mpTextEngine->FindCharAttrib( aPaM, TEXTATTR_HYPERLINK );
2115cdf0e10cSrcweir if ( pAttr )
2116cdf0e10cSrcweir {
2117cdf0e10cSrcweir aSel = aPaM;
2118cdf0e10cSrcweir aSel.GetStart().GetIndex() = pAttr->GetStart();
2119cdf0e10cSrcweir aSel.GetEnd().GetIndex() = pAttr->GetEnd();
2120cdf0e10cSrcweir
2121cdf0e10cSrcweir const TextAttribHyperLink& rLink = (const TextAttribHyperLink&)pAttr->GetAttr();
2122cdf0e10cSrcweir String aText( rLink.GetDescription() );
2123cdf0e10cSrcweir if ( !aText.Len() )
2124cdf0e10cSrcweir aText = mpImpl->mpTextEngine->GetText( aSel );
2125cdf0e10cSrcweir INetBookmark aBookmark( rLink.GetURL(), aText );
2126cdf0e10cSrcweir aBookmark.CopyDragServer();
2127cdf0e10cSrcweir }
2128cdf0e10cSrcweir */
2129cdf0e10cSrcweir
2130cdf0e10cSrcweir mpImpl->mpCursor->Hide();
2131cdf0e10cSrcweir
2132cdf0e10cSrcweir sal_Int8 nActions = datatransfer::dnd::DNDConstants::ACTION_COPY;
2133cdf0e10cSrcweir if ( !IsReadOnly() )
2134cdf0e10cSrcweir nActions |= datatransfer::dnd::DNDConstants::ACTION_MOVE;
2135cdf0e10cSrcweir rDGE.DragSource->startDrag( rDGE, nActions, 0 /*cursor*/, 0 /*image*/, pDataObj, mpImpl->mxDnDListener );
2136cdf0e10cSrcweir }
2137cdf0e10cSrcweir }
2138cdf0e10cSrcweir
dragDropEnd(const::com::sun::star::datatransfer::dnd::DragSourceDropEvent &)2139cdf0e10cSrcweir void TextView::dragDropEnd( const ::com::sun::star::datatransfer::dnd::DragSourceDropEvent& ) throw (::com::sun::star::uno::RuntimeException)
2140cdf0e10cSrcweir {
2141cdf0e10cSrcweir ImpHideDDCursor();
2142cdf0e10cSrcweir delete mpImpl->mpDDInfo;
2143cdf0e10cSrcweir mpImpl->mpDDInfo = NULL;
2144cdf0e10cSrcweir }
2145cdf0e10cSrcweir
drop(const::com::sun::star::datatransfer::dnd::DropTargetDropEvent & rDTDE)2146cdf0e10cSrcweir void TextView::drop( const ::com::sun::star::datatransfer::dnd::DropTargetDropEvent& rDTDE ) throw (::com::sun::star::uno::RuntimeException)
2147cdf0e10cSrcweir {
2148cdf0e10cSrcweir vos::OGuard aVclGuard( Application::GetSolarMutex() );
2149cdf0e10cSrcweir
2150cdf0e10cSrcweir sal_Bool bChanges = sal_False;
2151cdf0e10cSrcweir if ( !mpImpl->mbReadOnly && mpImpl->mpDDInfo )
2152cdf0e10cSrcweir {
2153cdf0e10cSrcweir ImpHideDDCursor();
2154cdf0e10cSrcweir
2155cdf0e10cSrcweir // Daten fuer das loeschen nach einem DROP_MOVE:
2156cdf0e10cSrcweir TextSelection aPrevSel( mpImpl->maSelection );
2157cdf0e10cSrcweir aPrevSel.Justify();
2158cdf0e10cSrcweir sal_uLong nPrevParaCount = mpImpl->mpTextEngine->GetParagraphCount();
2159cdf0e10cSrcweir sal_uInt16 nPrevStartParaLen = mpImpl->mpTextEngine->GetTextLen( aPrevSel.GetStart().GetPara() );
2160cdf0e10cSrcweir
2161cdf0e10cSrcweir sal_Bool bStarterOfDD = sal_False;
2162cdf0e10cSrcweir for ( sal_uInt16 nView = mpImpl->mpTextEngine->GetViewCount(); nView && !bStarterOfDD; )
2163cdf0e10cSrcweir bStarterOfDD = mpImpl->mpTextEngine->GetView( --nView )->mpImpl->mpDDInfo ? mpImpl->mpTextEngine->GetView( nView )->mpImpl->mpDDInfo->mbStarterOfDD : sal_False;
2164cdf0e10cSrcweir
2165cdf0e10cSrcweir HideSelection();
2166cdf0e10cSrcweir ImpSetSelection( mpImpl->mpDDInfo->maDropPos );
2167cdf0e10cSrcweir
2168cdf0e10cSrcweir mpImpl->mpTextEngine->UndoActionStart();
2169cdf0e10cSrcweir
2170cdf0e10cSrcweir String aText;
2171cdf0e10cSrcweir uno::Reference< datatransfer::XTransferable > xDataObj = rDTDE.Transferable;
2172cdf0e10cSrcweir if ( xDataObj.is() )
2173cdf0e10cSrcweir {
2174cdf0e10cSrcweir datatransfer::DataFlavor aFlavor;
2175cdf0e10cSrcweir SotExchange::GetFormatDataFlavor( SOT_FORMAT_STRING, aFlavor );
2176cdf0e10cSrcweir if ( xDataObj->isDataFlavorSupported( aFlavor ) )
2177cdf0e10cSrcweir {
2178cdf0e10cSrcweir uno::Any aData = xDataObj->getTransferData( aFlavor );
2179cdf0e10cSrcweir ::rtl::OUString aOUString;
2180cdf0e10cSrcweir aData >>= aOUString;
2181cdf0e10cSrcweir aText = aOUString;
2182cdf0e10cSrcweir aText.ConvertLineEnd( LINEEND_LF );
2183cdf0e10cSrcweir }
2184cdf0e10cSrcweir }
2185cdf0e10cSrcweir
2186cdf0e10cSrcweir if ( aText.Len() && ( aText.GetChar( aText.Len()-1 ) == LINE_SEP ) )
2187cdf0e10cSrcweir aText.Erase( aText.Len()-1 );
2188cdf0e10cSrcweir
2189cdf0e10cSrcweir TextPaM aTempStart = mpImpl->maSelection.GetStart();
2190cdf0e10cSrcweir if ( ImplCheckTextLen( aText ) )
2191cdf0e10cSrcweir ImpSetSelection( mpImpl->mpTextEngine->ImpInsertText( mpImpl->mpDDInfo->maDropPos, aText ) );
2192cdf0e10cSrcweir if(mpImpl->mbSupportProtectAttribute)
2193cdf0e10cSrcweir {
2194cdf0e10cSrcweir mpImpl->mpTextEngine->SetAttrib( TextAttribProtect(),
2195cdf0e10cSrcweir aTempStart.GetPara(),
2196cdf0e10cSrcweir aTempStart.GetIndex(),
2197cdf0e10cSrcweir mpImpl->maSelection.GetEnd().GetIndex(), sal_False );
2198cdf0e10cSrcweir }
2199cdf0e10cSrcweir
2200cdf0e10cSrcweir if ( aPrevSel.HasRange() &&
2201cdf0e10cSrcweir !mpImpl->mbSupportProtectAttribute && // don't remove currently selected element
2202cdf0e10cSrcweir (( rDTDE.DropAction & datatransfer::dnd::DNDConstants::ACTION_MOVE ) || !bStarterOfDD) )
2203cdf0e10cSrcweir {
2204cdf0e10cSrcweir // ggf. Selection anpasssen:
2205cdf0e10cSrcweir if ( ( mpImpl->mpDDInfo->maDropPos.GetPara() < aPrevSel.GetStart().GetPara() ) ||
2206cdf0e10cSrcweir ( ( mpImpl->mpDDInfo->maDropPos.GetPara() == aPrevSel.GetStart().GetPara() )
2207cdf0e10cSrcweir && ( mpImpl->mpDDInfo->maDropPos.GetIndex() < aPrevSel.GetStart().GetIndex() ) ) )
2208cdf0e10cSrcweir {
2209cdf0e10cSrcweir sal_uLong nNewParasBeforeSelection =
2210cdf0e10cSrcweir mpImpl->mpTextEngine->GetParagraphCount() - nPrevParaCount;
2211cdf0e10cSrcweir
2212cdf0e10cSrcweir aPrevSel.GetStart().GetPara() += nNewParasBeforeSelection;
2213cdf0e10cSrcweir aPrevSel.GetEnd().GetPara() += nNewParasBeforeSelection;
2214cdf0e10cSrcweir
2215cdf0e10cSrcweir if ( mpImpl->mpDDInfo->maDropPos.GetPara() == aPrevSel.GetStart().GetPara() )
2216cdf0e10cSrcweir {
2217cdf0e10cSrcweir sal_uInt16 nNewChars =
2218cdf0e10cSrcweir mpImpl->mpTextEngine->GetTextLen( aPrevSel.GetStart().GetPara() ) - nPrevStartParaLen;
2219cdf0e10cSrcweir
2220cdf0e10cSrcweir aPrevSel.GetStart().GetIndex() =
2221cdf0e10cSrcweir aPrevSel.GetStart().GetIndex() + nNewChars;
2222cdf0e10cSrcweir if ( aPrevSel.GetStart().GetPara() == aPrevSel.GetEnd().GetPara() )
2223cdf0e10cSrcweir aPrevSel.GetEnd().GetIndex() =
2224cdf0e10cSrcweir aPrevSel.GetEnd().GetIndex() + nNewChars;
2225cdf0e10cSrcweir }
2226cdf0e10cSrcweir }
2227cdf0e10cSrcweir else
2228cdf0e10cSrcweir {
2229cdf0e10cSrcweir // aktuelle Selektion anpassen
2230cdf0e10cSrcweir TextPaM aPaM = mpImpl->maSelection.GetStart();
2231cdf0e10cSrcweir aPaM.GetPara() -= ( aPrevSel.GetEnd().GetPara() - aPrevSel.GetStart().GetPara() );
2232cdf0e10cSrcweir if ( aPrevSel.GetEnd().GetPara() == mpImpl->mpDDInfo->maDropPos.GetPara() )
2233cdf0e10cSrcweir {
2234cdf0e10cSrcweir aPaM.GetIndex() =
2235cdf0e10cSrcweir aPaM.GetIndex() - aPrevSel.GetEnd().GetIndex();
2236cdf0e10cSrcweir if ( aPrevSel.GetStart().GetPara() == mpImpl->mpDDInfo->maDropPos.GetPara() )
2237cdf0e10cSrcweir aPaM.GetIndex() =
2238cdf0e10cSrcweir aPaM.GetIndex() + aPrevSel.GetStart().GetIndex();
2239cdf0e10cSrcweir }
2240cdf0e10cSrcweir ImpSetSelection( aPaM );
2241cdf0e10cSrcweir
2242cdf0e10cSrcweir }
2243cdf0e10cSrcweir mpImpl->mpTextEngine->ImpDeleteText( aPrevSel );
2244cdf0e10cSrcweir }
2245cdf0e10cSrcweir
2246cdf0e10cSrcweir mpImpl->mpTextEngine->UndoActionEnd();
2247cdf0e10cSrcweir
2248cdf0e10cSrcweir delete mpImpl->mpDDInfo;
2249cdf0e10cSrcweir mpImpl->mpDDInfo = 0;
2250cdf0e10cSrcweir
2251cdf0e10cSrcweir mpImpl->mpTextEngine->FormatAndUpdate( this );
2252cdf0e10cSrcweir
2253cdf0e10cSrcweir mpImpl->mpTextEngine->Broadcast( TextHint( TEXT_HINT_MODIFIED ) );
2254cdf0e10cSrcweir }
2255cdf0e10cSrcweir rDTDE.Context->dropComplete( bChanges );
2256cdf0e10cSrcweir }
2257cdf0e10cSrcweir
dragEnter(const::com::sun::star::datatransfer::dnd::DropTargetDragEnterEvent &)2258cdf0e10cSrcweir void TextView::dragEnter( const ::com::sun::star::datatransfer::dnd::DropTargetDragEnterEvent& ) throw (::com::sun::star::uno::RuntimeException)
2259cdf0e10cSrcweir {
2260cdf0e10cSrcweir }
2261cdf0e10cSrcweir
dragExit(const::com::sun::star::datatransfer::dnd::DropTargetEvent &)2262cdf0e10cSrcweir void TextView::dragExit( const ::com::sun::star::datatransfer::dnd::DropTargetEvent& ) throw (::com::sun::star::uno::RuntimeException)
2263cdf0e10cSrcweir {
2264cdf0e10cSrcweir vos::OGuard aVclGuard( Application::GetSolarMutex() );
2265cdf0e10cSrcweir ImpHideDDCursor();
2266cdf0e10cSrcweir }
2267cdf0e10cSrcweir
dragOver(const::com::sun::star::datatransfer::dnd::DropTargetDragEvent & rDTDE)2268cdf0e10cSrcweir void TextView::dragOver( const ::com::sun::star::datatransfer::dnd::DropTargetDragEvent& rDTDE ) throw (::com::sun::star::uno::RuntimeException)
2269cdf0e10cSrcweir {
2270cdf0e10cSrcweir vos::OGuard aVclGuard( Application::GetSolarMutex() );
2271cdf0e10cSrcweir
2272cdf0e10cSrcweir if ( !mpImpl->mpDDInfo )
2273cdf0e10cSrcweir mpImpl->mpDDInfo = new TextDDInfo;
2274cdf0e10cSrcweir
2275cdf0e10cSrcweir TextPaM aPrevDropPos = mpImpl->mpDDInfo->maDropPos;
2276cdf0e10cSrcweir Point aMousePos( rDTDE.LocationX, rDTDE.LocationY );
2277cdf0e10cSrcweir Point aDocPos = GetDocPos( aMousePos );
2278cdf0e10cSrcweir mpImpl->mpDDInfo->maDropPos = mpImpl->mpTextEngine->GetPaM( aDocPos );
2279cdf0e10cSrcweir
2280cdf0e10cSrcweir /*
2281cdf0e10cSrcweir Size aOutSize = mpImpl->mpWindow->GetOutputSizePixel();
2282cdf0e10cSrcweir if ( ( aMousePos.X() < 0 ) || ( aMousePos.X() > aOutSize.Width() ) ||
2283cdf0e10cSrcweir ( aMousePos.Y() < 0 ) || ( aMousePos.Y() > aOutSize.Height() ) )
2284cdf0e10cSrcweir {
2285cdf0e10cSrcweir // Scroll?
2286cdf0e10cSrcweir // No, I will not receive events for this...
2287cdf0e10cSrcweir }
2288cdf0e10cSrcweir */
2289cdf0e10cSrcweir
2290cdf0e10cSrcweir sal_Bool bProtected = sal_False;
2291cdf0e10cSrcweir if(mpImpl->mbSupportProtectAttribute)
2292cdf0e10cSrcweir {
2293cdf0e10cSrcweir const TextCharAttrib* pStartAttr = mpImpl->mpTextEngine->FindCharAttrib(
2294cdf0e10cSrcweir mpImpl->mpDDInfo->maDropPos,
2295cdf0e10cSrcweir TEXTATTR_PROTECTED );
2296cdf0e10cSrcweir bProtected = pStartAttr != 0 &&
2297cdf0e10cSrcweir pStartAttr->GetStart() != mpImpl->mpDDInfo->maDropPos.GetIndex() &&
2298cdf0e10cSrcweir pStartAttr->GetEnd() != mpImpl->mpDDInfo->maDropPos.GetIndex();
2299cdf0e10cSrcweir }
2300cdf0e10cSrcweir // Don't drop in selection or in read only engine
2301cdf0e10cSrcweir if ( IsReadOnly() || IsInSelection( mpImpl->mpDDInfo->maDropPos ) || bProtected)
2302cdf0e10cSrcweir {
2303cdf0e10cSrcweir ImpHideDDCursor();
2304cdf0e10cSrcweir rDTDE.Context->rejectDrag();
2305cdf0e10cSrcweir }
2306cdf0e10cSrcweir else
2307cdf0e10cSrcweir {
2308cdf0e10cSrcweir // Alten Cursor wegzeichnen...
2309cdf0e10cSrcweir if ( !mpImpl->mpDDInfo->mbVisCursor || ( aPrevDropPos != mpImpl->mpDDInfo->maDropPos ) )
2310cdf0e10cSrcweir {
2311cdf0e10cSrcweir ImpHideDDCursor();
2312cdf0e10cSrcweir ImpShowDDCursor();
2313cdf0e10cSrcweir }
2314cdf0e10cSrcweir rDTDE.Context->acceptDrag( rDTDE.DropAction );
2315cdf0e10cSrcweir }
2316cdf0e10cSrcweir }
2317cdf0e10cSrcweir
ImpGetOutputStartPos(const Point & rStartDocPos) const2318cdf0e10cSrcweir Point TextView::ImpGetOutputStartPos( const Point& rStartDocPos ) const
2319cdf0e10cSrcweir {
2320cdf0e10cSrcweir Point aStartPos( -rStartDocPos.X(), -rStartDocPos.Y() );
2321cdf0e10cSrcweir if ( mpImpl->mpTextEngine->IsRightToLeft() )
2322cdf0e10cSrcweir {
2323cdf0e10cSrcweir Size aSz = mpImpl->mpWindow->GetOutputSizePixel();
2324cdf0e10cSrcweir aStartPos.X() = rStartDocPos.X() + aSz.Width() - 1; // -1: Start is 0
2325cdf0e10cSrcweir }
2326cdf0e10cSrcweir return aStartPos;
2327cdf0e10cSrcweir }
2328cdf0e10cSrcweir
GetDocPos(const Point & rWindowPos) const2329cdf0e10cSrcweir Point TextView::GetDocPos( const Point& rWindowPos ) const
2330cdf0e10cSrcweir {
2331cdf0e10cSrcweir // Fensterposition => Dokumentposition
2332cdf0e10cSrcweir
2333cdf0e10cSrcweir Point aPoint;
2334cdf0e10cSrcweir
2335cdf0e10cSrcweir aPoint.Y() = rWindowPos.Y() + mpImpl->maStartDocPos.Y();
2336cdf0e10cSrcweir
2337cdf0e10cSrcweir if ( !mpImpl->mpTextEngine->IsRightToLeft() )
2338cdf0e10cSrcweir {
2339cdf0e10cSrcweir aPoint.X() = rWindowPos.X() + mpImpl->maStartDocPos.X();
2340cdf0e10cSrcweir }
2341cdf0e10cSrcweir else
2342cdf0e10cSrcweir {
2343cdf0e10cSrcweir Size aSz = mpImpl->mpWindow->GetOutputSizePixel();
2344cdf0e10cSrcweir aPoint.X() = ( aSz.Width() - 1 ) - rWindowPos.X() + mpImpl->maStartDocPos.X();
2345cdf0e10cSrcweir }
2346cdf0e10cSrcweir
2347cdf0e10cSrcweir return aPoint;
2348cdf0e10cSrcweir }
2349cdf0e10cSrcweir
GetWindowPos(const Point & rDocPos) const2350cdf0e10cSrcweir Point TextView::GetWindowPos( const Point& rDocPos ) const
2351cdf0e10cSrcweir {
2352cdf0e10cSrcweir // Dokumentposition => Fensterposition
2353cdf0e10cSrcweir
2354cdf0e10cSrcweir Point aPoint;
2355cdf0e10cSrcweir
2356cdf0e10cSrcweir aPoint.Y() = rDocPos.Y() - mpImpl->maStartDocPos.Y();
2357cdf0e10cSrcweir
2358cdf0e10cSrcweir if ( !mpImpl->mpTextEngine->IsRightToLeft() )
2359cdf0e10cSrcweir {
2360cdf0e10cSrcweir aPoint.X() = rDocPos.X() - mpImpl->maStartDocPos.X();
2361cdf0e10cSrcweir }
2362cdf0e10cSrcweir else
2363cdf0e10cSrcweir {
2364cdf0e10cSrcweir Size aSz = mpImpl->mpWindow->GetOutputSizePixel();
2365cdf0e10cSrcweir aPoint.X() = ( aSz.Width() - 1 ) - ( rDocPos.X() - mpImpl->maStartDocPos.X() );
2366cdf0e10cSrcweir }
2367cdf0e10cSrcweir
2368cdf0e10cSrcweir return aPoint;
2369cdf0e10cSrcweir }
2370cdf0e10cSrcweir
GetLineNumberOfCursorInSelection() const2371cdf0e10cSrcweir sal_Int32 TextView::GetLineNumberOfCursorInSelection() const
2372cdf0e10cSrcweir {
2373cdf0e10cSrcweir // PROGRESS
2374cdf0e10cSrcweir sal_Int32 nLineNo = -1;
2375cdf0e10cSrcweir if( mpImpl->mbCursorEnabled )
2376cdf0e10cSrcweir {
2377cdf0e10cSrcweir TextPaM aPaM = GetSelection().GetEnd();
2378cdf0e10cSrcweir TEParaPortion* pPPortion = mpImpl->mpTextEngine->mpTEParaPortions->GetObject( aPaM.GetPara() );
2379cdf0e10cSrcweir nLineNo = pPPortion->GetLineNumber( aPaM.GetIndex(), sal_False );
2380cdf0e10cSrcweir if( mpImpl->mbCursorAtEndOfLine )
2381cdf0e10cSrcweir --nLineNo;
2382cdf0e10cSrcweir }
2383cdf0e10cSrcweir return nLineNo;
2384cdf0e10cSrcweir }
2385cdf0e10cSrcweir
2386cdf0e10cSrcweir
2387cdf0e10cSrcweir // -------------------------------------------------------------------------
2388cdf0e10cSrcweir // (+) class TextSelFunctionSet
2389cdf0e10cSrcweir // -------------------------------------------------------------------------
TextSelFunctionSet(TextView * pView)2390cdf0e10cSrcweir TextSelFunctionSet::TextSelFunctionSet( TextView* pView )
2391cdf0e10cSrcweir {
2392cdf0e10cSrcweir mpView = pView;
2393cdf0e10cSrcweir }
2394cdf0e10cSrcweir
BeginDrag()2395cdf0e10cSrcweir void __EXPORT TextSelFunctionSet::BeginDrag()
2396cdf0e10cSrcweir {
2397cdf0e10cSrcweir }
2398cdf0e10cSrcweir
CreateAnchor()2399cdf0e10cSrcweir void __EXPORT TextSelFunctionSet::CreateAnchor()
2400cdf0e10cSrcweir {
2401cdf0e10cSrcweir // TextSelection aSel( mpView->GetSelection() );
2402cdf0e10cSrcweir // aSel.GetStart() = aSel.GetEnd();
2403cdf0e10cSrcweir // mpView->SetSelection( aSel );
2404cdf0e10cSrcweir
2405cdf0e10cSrcweir // Es darf kein ShowCursor folgen:
2406cdf0e10cSrcweir mpView->HideSelection();
2407cdf0e10cSrcweir mpView->ImpSetSelection( mpView->mpImpl->maSelection.GetEnd() );
2408cdf0e10cSrcweir }
2409cdf0e10cSrcweir
SetCursorAtPoint(const Point & rPointPixel,sal_Bool)2410cdf0e10cSrcweir sal_Bool __EXPORT TextSelFunctionSet::SetCursorAtPoint( const Point& rPointPixel, sal_Bool )
2411cdf0e10cSrcweir {
2412cdf0e10cSrcweir return mpView->SetCursorAtPoint( rPointPixel );
2413cdf0e10cSrcweir }
2414cdf0e10cSrcweir
IsSelectionAtPoint(const Point & rPointPixel)2415cdf0e10cSrcweir sal_Bool __EXPORT TextSelFunctionSet::IsSelectionAtPoint( const Point& rPointPixel )
2416cdf0e10cSrcweir {
2417cdf0e10cSrcweir return mpView->IsSelectionAtPoint( rPointPixel );
2418cdf0e10cSrcweir }
2419cdf0e10cSrcweir
DeselectAll()2420cdf0e10cSrcweir void __EXPORT TextSelFunctionSet::DeselectAll()
2421cdf0e10cSrcweir {
2422cdf0e10cSrcweir CreateAnchor();
2423cdf0e10cSrcweir }
2424cdf0e10cSrcweir
DeselectAtPoint(const Point &)2425cdf0e10cSrcweir void __EXPORT TextSelFunctionSet::DeselectAtPoint( const Point& )
2426cdf0e10cSrcweir {
2427cdf0e10cSrcweir // Nur bei Mehrfachselektion
2428cdf0e10cSrcweir }
2429cdf0e10cSrcweir
DestroyAnchor()2430cdf0e10cSrcweir void __EXPORT TextSelFunctionSet::DestroyAnchor()
2431cdf0e10cSrcweir {
2432cdf0e10cSrcweir // Nur bei Mehrfachselektion
2433cdf0e10cSrcweir }
GetTextEngine() const2434cdf0e10cSrcweir TextEngine* TextView::GetTextEngine() const
2435cdf0e10cSrcweir { return mpImpl->mpTextEngine; }
GetWindow() const2436cdf0e10cSrcweir Window* TextView::GetWindow() const
2437cdf0e10cSrcweir { return mpImpl->mpWindow; }
EnableCursor(sal_Bool bEnable)2438cdf0e10cSrcweir void TextView::EnableCursor( sal_Bool bEnable )
2439cdf0e10cSrcweir { mpImpl->mbCursorEnabled = bEnable; }
IsCursorEnabled() const2440cdf0e10cSrcweir sal_Bool TextView::IsCursorEnabled() const
2441cdf0e10cSrcweir { return mpImpl->mbCursorEnabled; }
SetStartDocPos(const Point & rPos)2442cdf0e10cSrcweir void TextView::SetStartDocPos( const Point& rPos )
2443cdf0e10cSrcweir { mpImpl->maStartDocPos = rPos; }
GetStartDocPos() const2444cdf0e10cSrcweir const Point& TextView::GetStartDocPos() const
2445cdf0e10cSrcweir { return mpImpl->maStartDocPos; }
SetAutoIndentMode(sal_Bool bAutoIndent)2446cdf0e10cSrcweir void TextView::SetAutoIndentMode( sal_Bool bAutoIndent )
2447cdf0e10cSrcweir { mpImpl->mbAutoIndent = bAutoIndent; }
IsAutoIndentMode() const2448cdf0e10cSrcweir sal_Bool TextView::IsAutoIndentMode() const
2449cdf0e10cSrcweir { return mpImpl->mbAutoIndent; }
IsReadOnly() const2450cdf0e10cSrcweir sal_Bool TextView::IsReadOnly() const
2451cdf0e10cSrcweir { return mpImpl->mbReadOnly; }
SetAutoScroll(sal_Bool bAutoScroll)2452cdf0e10cSrcweir void TextView::SetAutoScroll( sal_Bool bAutoScroll )
2453cdf0e10cSrcweir { mpImpl->mbAutoScroll = bAutoScroll; }
IsAutoScroll() const2454cdf0e10cSrcweir sal_Bool TextView::IsAutoScroll() const
2455cdf0e10cSrcweir { return mpImpl->mbAutoScroll; }
IsPaintSelection() const2456cdf0e10cSrcweir sal_Bool TextView::IsPaintSelection() const
2457cdf0e10cSrcweir { return mpImpl->mbPaintSelection; }
IsHighlightSelection() const2458cdf0e10cSrcweir sal_Bool TextView::IsHighlightSelection() const
2459cdf0e10cSrcweir { return mpImpl->mbHighlightSelection; }
HasSelection() const2460cdf0e10cSrcweir sal_Bool TextView::HasSelection() const
2461cdf0e10cSrcweir { return mpImpl->maSelection.HasRange(); }
IsInsertMode() const2462cdf0e10cSrcweir sal_Bool TextView::IsInsertMode() const
2463cdf0e10cSrcweir { return mpImpl->mbInsertMode; }
SupportProtectAttribute(sal_Bool bSupport)2464cdf0e10cSrcweir void TextView::SupportProtectAttribute(sal_Bool bSupport)
2465cdf0e10cSrcweir { mpImpl->mbSupportProtectAttribute = bSupport;}
2466cdf0e10cSrcweir
2467