Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <vcl/wrkwin.hxx>
21 : #include <vcl/dialog.hxx>
22 : #include <vcl/msgbox.hxx>
23 : #include <vcl/svapp.hxx>
24 : #include <vcl/settings.hxx>
25 :
26 : #include <impedit.hxx>
27 : #include <editeng/editeng.hxx>
28 : #include <editeng/editview.hxx>
29 : #include <tools/poly.hxx>
30 : #include <editeng/unolingu.hxx>
31 : #include <com/sun/star/linguistic2/XDictionaryEntry.hpp>
32 : #include <com/sun/star/linguistic2/DictionaryType.hpp>
33 : #include <com/sun/star/linguistic2/DictionaryEvent.hpp>
34 : #include <com/sun/star/linguistic2/XDictionaryEventListener.hpp>
35 : #include <com/sun/star/linguistic2/DictionaryEventFlags.hpp>
36 : #include <com/sun/star/linguistic2/XDictionary.hpp>
37 : #include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
38 : #include <com/sun/star/datatransfer/dnd/XDragGestureRecognizer.hpp>
39 : #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
40 : #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
41 : #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
42 : #include <osl/mutex.hxx>
43 : #include <editeng/flditem.hxx>
44 : #include <svl/intitem.hxx>
45 : #include <svtools/transfer.hxx>
46 : #include <sot/exchange.hxx>
47 : #include <sot/formats.hxx>
48 : #include <LibreOfficeKit/LibreOfficeKitEnums.h>
49 :
50 : using namespace ::com::sun::star;
51 : using namespace ::com::sun::star::uno;
52 : using namespace ::com::sun::star::linguistic2;
53 :
54 : #define SCRLRANGE 20 // Scroll 1/20 of the width/height, when in QueryDrop
55 :
56 50 : static inline void lcl_AllignToPixel( Point& rPoint, OutputDevice* pOutDev, short nDiffX, short nDiffY )
57 : {
58 50 : rPoint = pOutDev->LogicToPixel( rPoint );
59 :
60 50 : if ( nDiffX )
61 25 : rPoint.X() += nDiffX;
62 50 : if ( nDiffY )
63 17 : rPoint.Y() += nDiffY;
64 :
65 50 : rPoint = pOutDev->PixelToLogic( rPoint );
66 50 : }
67 :
68 :
69 : // class ImpEditView
70 :
71 377 : ImpEditView::ImpEditView( EditView* pView, EditEngine* pEng, vcl::Window* pWindow ) :
72 377 : aOutArea( Point(), pEng->GetPaperSize() )
73 : {
74 377 : pEditView = pView;
75 377 : pEditEngine = pEng;
76 377 : pOutWin = pWindow;
77 377 : pPointer = NULL;
78 377 : pBackgroundColor = NULL;
79 377 : mbTiledRendering = false;
80 377 : mpLibreOfficeKitCallback = 0;
81 377 : mpLibreOfficeKitData = 0;
82 377 : nScrollDiffX = 0;
83 377 : nExtraCursorFlags = 0;
84 377 : nCursorBidiLevel = CURSOR_BIDILEVEL_DONTKNOW;
85 377 : pCursor = NULL;
86 377 : pDragAndDropInfo = NULL;
87 377 : bReadOnly = false;
88 377 : bClickedInSelection = false;
89 377 : eSelectionMode = EE_SELMODE_TXTONLY;
90 377 : eAnchorMode = ANCHOR_TOP_LEFT;
91 377 : nInvMore = 1;
92 377 : nTravelXPos = TRAVEL_X_DONTKNOW;
93 377 : nControl = EVControlBits::AUTOSCROLL | EVControlBits::ENABLEPASTE;
94 377 : bActiveDragAndDropListener = false;
95 :
96 377 : aEditSelection.Min() = pEng->GetEditDoc().GetStartPaM();
97 377 : aEditSelection.Max() = pEng->GetEditDoc().GetEndPaM();
98 377 : }
99 :
100 1128 : ImpEditView::~ImpEditView()
101 : {
102 376 : RemoveDragAndDropListeners();
103 :
104 376 : if ( pOutWin && ( pOutWin->GetCursor() == pCursor ) )
105 261 : pOutWin->SetCursor( NULL );
106 :
107 376 : delete pCursor;
108 376 : delete pBackgroundColor;
109 376 : delete pPointer;
110 376 : delete pDragAndDropInfo;
111 752 : }
112 :
113 95 : void ImpEditView::SetBackgroundColor( const Color& rColor )
114 : {
115 95 : delete pBackgroundColor;
116 95 : pBackgroundColor = new Color( rColor );
117 95 : }
118 :
119 9 : void ImpEditView::setTiledRendering(bool bTiledRendering)
120 : {
121 9 : mbTiledRendering = bTiledRendering;
122 9 : }
123 :
124 9551 : bool ImpEditView::isTiledRendering() const
125 : {
126 9551 : return mbTiledRendering;
127 : }
128 :
129 9 : void ImpEditView::registerLibreOfficeKitCallback(LibreOfficeKitCallback pCallback, void* pData)
130 : {
131 9 : mpLibreOfficeKitCallback = pCallback;
132 9 : mpLibreOfficeKitData = pData;
133 9 : }
134 :
135 229 : void ImpEditView::libreOfficeKitCallback(int nType, const char* pPayload) const
136 : {
137 229 : if (mpLibreOfficeKitCallback)
138 60 : mpLibreOfficeKitCallback(nType, pPayload, mpLibreOfficeKitData);
139 229 : }
140 :
141 1413 : void ImpEditView::SetEditSelection( const EditSelection& rEditSelection )
142 : {
143 : // set state before notification
144 1413 : aEditSelection = rEditSelection;
145 :
146 1413 : if (isTiledRendering())
147 : // Tiled rendering: selections are only painted when we are in selection mode.
148 51 : pEditEngine->SetInSelectionMode(aEditSelection.HasRange());
149 :
150 1413 : if ( pEditEngine->pImpEditEngine->GetNotifyHdl().IsSet() )
151 : {
152 333 : const EditDoc& rDoc = pEditEngine->GetEditDoc();
153 333 : const EditPaM pmEnd = rDoc.GetEndPaM();
154 : EENotifyType eNotifyType;
155 666 : if (rDoc.Count() > 1 &&
156 333 : pmEnd == rEditSelection.Min() &&
157 0 : pmEnd == rEditSelection.Max())//if move cursor to the last para.
158 : {
159 0 : eNotifyType = EE_NOTIFY_TEXTVIEWSELECTIONCHANGED_ENDD_PARA;
160 : }
161 : else
162 : {
163 333 : eNotifyType = EE_NOTIFY_TEXTVIEWSELECTIONCHANGED;
164 : }
165 : //EENotify aNotify( EE_NOTIFY_TEXTVIEWSELECTIONCHANGED );
166 333 : EENotify aNotify( eNotifyType );
167 333 : aNotify.pEditEngine = pEditEngine;
168 333 : aNotify.pEditView = GetEditViewPtr();
169 333 : pEditEngine->pImpEditEngine->CallNotify( aNotify );
170 : }
171 1413 : }
172 :
173 :
174 2145 : void ImpEditView::DrawSelection( EditSelection aTmpSel, vcl::Region* pRegion, OutputDevice* pTargetDevice )
175 : {
176 2145 : if ( GetSelectionMode() == EE_SELMODE_HIDDEN )
177 2087 : return;
178 :
179 : // It must be ensured before rendering the selection, that the contents of
180 : // the window is completely valid! Must be here so that in any case if
181 : // empty, then later on two-Paint Events! Must be done even before the
182 : // query from bUpdate, if after Invalidate paints still in the queue,
183 : // but someone switches the update mode!
184 :
185 : // pRegion: When not NULL, then only calculate Region.
186 :
187 2143 : vcl::Region aRegion;
188 2143 : if (isTiledRendering())
189 : {
190 : assert(!pRegion);
191 52 : pRegion = &aRegion;
192 : }
193 :
194 2143 : tools::PolyPolygon* pPolyPoly = NULL;
195 2143 : if ( pRegion )
196 52 : pPolyPoly = new tools::PolyPolygon;
197 :
198 2143 : OutputDevice* pTarget = pTargetDevice ? pTargetDevice : pOutWin;
199 2143 : bool bClipRegion = pTarget->IsClipRegion();
200 2203 : vcl::Region aOldRegion = pTarget->GetClipRegion();
201 :
202 2143 : if ( !pRegion )
203 : {
204 2091 : if ( !pEditEngine->pImpEditEngine->GetUpdateMode() )
205 2266 : return;
206 1908 : if ( pEditEngine->pImpEditEngine->IsInUndo() )
207 0 : return;
208 :
209 1908 : if ( !aTmpSel.HasRange() )
210 1900 : return;
211 :
212 : // aTmpOutArea: if OutputArea > Paper width and
213 : // Text > Paper width ( over large fields )
214 8 : Rectangle aTmpOutArea( aOutArea );
215 8 : if ( aTmpOutArea.GetWidth() > pEditEngine->pImpEditEngine->GetPaperSize().Width() )
216 0 : aTmpOutArea.Right() = aTmpOutArea.Left() + pEditEngine->pImpEditEngine->GetPaperSize().Width();
217 8 : pTarget->IntersectClipRegion( aTmpOutArea );
218 :
219 8 : if ( pOutWin->GetCursor() )
220 0 : pOutWin->GetCursor()->Hide();
221 : }
222 :
223 : DBG_ASSERT( !pEditEngine->IsIdleFormatterActive(), "DrawSelection: Not formatted!" );
224 60 : aTmpSel.Adjust( pEditEngine->GetEditDoc() );
225 :
226 60 : ContentNode* pStartNode = aTmpSel.Min().GetNode();
227 60 : ContentNode* pEndNode = aTmpSel.Max().GetNode();
228 60 : sal_Int32 nStartPara = pEditEngine->GetEditDoc().GetPos( pStartNode );
229 60 : sal_Int32 nEndPara = pEditEngine->GetEditDoc().GetPos( pEndNode );
230 120 : for ( sal_Int32 nPara = nStartPara; nPara <= nEndPara; nPara++ )
231 : {
232 60 : ParaPortion* pTmpPortion = pEditEngine->GetParaPortions().SafeGetObject( nPara );
233 : DBG_ASSERT( pTmpPortion, "Portion in Selection not found!" );
234 : DBG_ASSERT( !pTmpPortion->IsInvalid(), "Portion in Selection not formatted!" );
235 :
236 60 : if ( !pTmpPortion->IsVisible() || pTmpPortion->IsInvalid() )
237 0 : continue;
238 :
239 60 : long nParaStart = pEditEngine->GetParaPortions().GetYOffset( pTmpPortion );
240 60 : if ( ( nParaStart + pTmpPortion->GetHeight() ) < GetVisDocTop() )
241 0 : continue;
242 60 : if ( nParaStart > GetVisDocBottom() )
243 0 : break;
244 :
245 60 : sal_uInt16 nStartLine = 0;
246 60 : sal_uInt16 nEndLine = pTmpPortion->GetLines().Count() -1;
247 60 : if ( nPara == nStartPara )
248 60 : nStartLine = pTmpPortion->GetLines().FindLine( aTmpSel.Min().GetIndex(), false );
249 60 : if ( nPara == nEndPara )
250 60 : nEndLine = pTmpPortion->GetLines().FindLine( aTmpSel.Max().GetIndex(), true );
251 :
252 120 : for ( sal_uInt16 nLine = nStartLine; nLine <= nEndLine; nLine++ )
253 : {
254 60 : const EditLine* pLine = pTmpPortion->GetLines()[nLine];
255 : DBG_ASSERT( pLine, "Line not found: DrawSelection()" );
256 :
257 60 : bool bPartOfLine = false;
258 60 : sal_Int32 nStartIndex = pLine->GetStart();
259 60 : sal_Int32 nEndIndex = pLine->GetEnd();
260 60 : if ( ( nPara == nStartPara ) && ( nLine == nStartLine ) && ( nStartIndex != aTmpSel.Min().GetIndex() ) )
261 : {
262 37 : nStartIndex = aTmpSel.Min().GetIndex();
263 37 : bPartOfLine = true;
264 : }
265 60 : if ( ( nPara == nEndPara ) && ( nLine == nEndLine ) && ( nEndIndex != aTmpSel.Max().GetIndex() ) )
266 : {
267 37 : nEndIndex = aTmpSel.Max().GetIndex();
268 37 : bPartOfLine = true;
269 : }
270 :
271 : // Can happen if at the beginning of a wrapped line.
272 60 : if ( nEndIndex < nStartIndex )
273 0 : nEndIndex = nStartIndex;
274 :
275 60 : Rectangle aTmpRect( pEditEngine->pImpEditEngine->GetEditCursor( pTmpPortion, nStartIndex ) );
276 60 : Point aTopLeft( aTmpRect.TopLeft() );
277 60 : Point aBottomRight( aTmpRect.BottomRight() );
278 :
279 60 : aTopLeft.Y() += nParaStart;
280 60 : aBottomRight.Y() += nParaStart;
281 :
282 : // Only paint if in the visible range ...
283 60 : if ( aTopLeft.Y() > GetVisDocBottom() )
284 0 : break;
285 :
286 60 : if ( aBottomRight.Y() < GetVisDocTop() )
287 0 : continue;
288 :
289 : // Now that we have Bidi, the first/last index doesn't have to be the 'most outside' position
290 60 : if ( !bPartOfLine )
291 : {
292 9 : Range aLineXPosStartEnd = pEditEngine->GetLineXPosStartEnd(pTmpPortion, pLine);
293 9 : aTopLeft.X() = aLineXPosStartEnd.Min();
294 9 : aBottomRight.X() = aLineXPosStartEnd.Max();
295 9 : ImplDrawHighlightRect( pTarget, aTopLeft, aBottomRight, pPolyPoly );
296 : }
297 : else
298 : {
299 51 : sal_Int32 nTmpStartIndex = nStartIndex;
300 : sal_Int32 nWritingDirStart, nTmpEndIndex;
301 :
302 124 : while ( nTmpStartIndex < nEndIndex )
303 : {
304 22 : pEditEngine->pImpEditEngine->GetRightToLeft( nPara, nTmpStartIndex+1, &nWritingDirStart, &nTmpEndIndex );
305 22 : if ( nTmpEndIndex > nEndIndex )
306 19 : nTmpEndIndex = nEndIndex;
307 :
308 : DBG_ASSERT( nTmpEndIndex > nTmpStartIndex, "DrawSelection, Start >= End?" );
309 :
310 22 : long nX1 = pEditEngine->GetXPos(pTmpPortion, pLine, nTmpStartIndex, true);
311 22 : long nX2 = pEditEngine->GetXPos(pTmpPortion, pLine, nTmpEndIndex);
312 :
313 22 : Point aPt1( std::min( nX1, nX2 ), aTopLeft.Y() );
314 22 : Point aPt2( std::max( nX1, nX2 ), aBottomRight.Y() );
315 :
316 22 : ImplDrawHighlightRect( pTarget, aPt1, aPt2, pPolyPoly );
317 :
318 22 : nTmpStartIndex = nTmpEndIndex;
319 : }
320 : }
321 :
322 : }
323 : }
324 :
325 60 : if ( pRegion )
326 : {
327 52 : *pRegion = vcl::Region( *pPolyPoly );
328 :
329 52 : if (isTiledRendering())
330 : {
331 52 : bool bMm100ToTwip = pOutWin->GetMapMode().GetMapUnit() == MAP_100TH_MM;
332 52 : OString sRectangle;
333 : // If we are not in selection mode, then the exported selection should be empty.
334 52 : if (pEditEngine->pImpEditEngine->IsInSelectionMode())
335 : {
336 17 : std::vector<Rectangle> aRectangles;
337 17 : pRegion->GetRegionRectangles(aRectangles);
338 :
339 17 : if (!aRectangles.empty())
340 : {
341 17 : Rectangle& rStart = aRectangles.front();
342 17 : Rectangle aStart = Rectangle(rStart.Left(), rStart.Top(), rStart.Left() + 1, rStart.Bottom());
343 17 : if (bMm100ToTwip)
344 9 : aStart = OutputDevice::LogicToLogic(aStart, MAP_100TH_MM, MAP_TWIP);
345 17 : libreOfficeKitCallback(LOK_CALLBACK_TEXT_SELECTION_START, aStart.toString().getStr());
346 :
347 17 : Rectangle& rEnd = aRectangles.back();
348 17 : Rectangle aEnd = Rectangle(rEnd.Right() - 1, rEnd.Top(), rEnd.Right(), rEnd.Bottom());
349 17 : if (bMm100ToTwip)
350 9 : aEnd = OutputDevice::LogicToLogic(aEnd, MAP_100TH_MM, MAP_TWIP);
351 17 : libreOfficeKitCallback(LOK_CALLBACK_TEXT_SELECTION_END, aEnd.toString().getStr());
352 : }
353 :
354 34 : std::stringstream ss;
355 34 : for (size_t i = 0; i < aRectangles.size(); ++i)
356 : {
357 17 : Rectangle& rRectangle = aRectangles[i];
358 17 : if (i)
359 0 : ss << "; ";
360 17 : if (bMm100ToTwip)
361 9 : rRectangle = OutputDevice::LogicToLogic(rRectangle, MAP_100TH_MM, MAP_TWIP);
362 17 : ss << rRectangle.toString().getStr();
363 : }
364 34 : sRectangle = ss.str().c_str();
365 : }
366 52 : libreOfficeKitCallback(LOK_CALLBACK_TEXT_SELECTION, sRectangle.getStr());
367 : }
368 :
369 52 : delete pPolyPoly;
370 : }
371 : else
372 : {
373 8 : if ( pOutWin->GetCursor() )
374 0 : pOutWin->GetCursor()->Show();
375 :
376 8 : if ( bClipRegion )
377 0 : pTarget->SetClipRegion( aOldRegion );
378 : else
379 8 : pTarget->SetClipRegion();
380 60 : }
381 : }
382 :
383 31 : void ImpEditView::ImplDrawHighlightRect( OutputDevice* _pTarget, const Point& rDocPosTopLeft, const Point& rDocPosBottomRight, tools::PolyPolygon* pPolyPoly )
384 : {
385 31 : if ( rDocPosTopLeft.X() != rDocPosBottomRight.X() )
386 : {
387 25 : bool bPixelMode = _pTarget->GetMapMode() == MAP_PIXEL;
388 :
389 25 : Point aPnt1( GetWindowPos( rDocPosTopLeft ) );
390 25 : Point aPnt2( GetWindowPos( rDocPosBottomRight ) );
391 :
392 25 : if ( !IsVertical() )
393 : {
394 25 : lcl_AllignToPixel( aPnt1, _pTarget, +1, 0 );
395 25 : lcl_AllignToPixel( aPnt2, _pTarget, 0, ( bPixelMode ? 0 : -1 ) );
396 : }
397 : else
398 : {
399 0 : lcl_AllignToPixel( aPnt1, _pTarget, 0, +1 );
400 0 : lcl_AllignToPixel( aPnt2, _pTarget, ( bPixelMode ? 0 : +1 ), 0 );
401 : }
402 :
403 25 : Rectangle aRect( aPnt1, aPnt2 );
404 25 : if ( pPolyPoly )
405 : {
406 17 : Polygon aTmpPoly( 4 );
407 17 : aTmpPoly[0] = aRect.TopLeft();
408 17 : aTmpPoly[1] = aRect.TopRight();
409 17 : aTmpPoly[2] = aRect.BottomRight();
410 17 : aTmpPoly[3] = aRect.BottomLeft();
411 17 : pPolyPoly->Insert( aTmpPoly );
412 : }
413 : else
414 : {
415 8 : vcl::Window* pWindow = dynamic_cast< vcl::Window* >(_pTarget);
416 :
417 8 : if(pWindow)
418 : {
419 8 : pWindow->Invert( aRect );
420 : }
421 : else
422 : {
423 0 : _pTarget->Push(PushFlags::LINECOLOR|PushFlags::FILLCOLOR|PushFlags::RASTEROP);
424 0 : _pTarget->SetLineColor();
425 0 : _pTarget->SetFillColor(COL_BLACK);
426 0 : _pTarget->SetRasterOp(ROP_INVERT);
427 0 : _pTarget->DrawRect(aRect);
428 0 : _pTarget->Pop();
429 : }
430 : }
431 : }
432 31 : }
433 :
434 :
435 20991 : bool ImpEditView::IsVertical() const
436 : {
437 20991 : return pEditEngine->pImpEditEngine->IsVertical();
438 : }
439 :
440 3456 : Rectangle ImpEditView::GetVisDocArea() const
441 : {
442 3456 : return Rectangle( GetVisDocLeft(), GetVisDocTop(), GetVisDocRight(), GetVisDocBottom() );
443 : }
444 :
445 518 : Point ImpEditView::GetDocPos( const Point& rWindowPos ) const
446 : {
447 : // Window Position => Position Document
448 518 : Point aPoint;
449 :
450 518 : if ( !pEditEngine->pImpEditEngine->IsVertical() )
451 : {
452 518 : aPoint.X() = rWindowPos.X() - aOutArea.Left() + GetVisDocLeft();
453 518 : aPoint.Y() = rWindowPos.Y() - aOutArea.Top() + GetVisDocTop();
454 : }
455 : else
456 : {
457 0 : aPoint.X() = rWindowPos.Y() - aOutArea.Top() + GetVisDocLeft();
458 0 : aPoint.Y() = aOutArea.Right() - rWindowPos.X() + GetVisDocTop();
459 : }
460 :
461 518 : return aPoint;
462 : }
463 :
464 3026 : Point ImpEditView::GetWindowPos( const Point& rDocPos ) const
465 : {
466 : // Document position => window position
467 3026 : Point aPoint;
468 :
469 3026 : if ( !pEditEngine->pImpEditEngine->IsVertical() )
470 : {
471 3026 : aPoint.X() = rDocPos.X() + aOutArea.Left() - GetVisDocLeft();
472 3026 : aPoint.Y() = rDocPos.Y() + aOutArea.Top() - GetVisDocTop();
473 : }
474 : else
475 : {
476 0 : aPoint.X() = aOutArea.Right() - rDocPos.Y() + GetVisDocTop();
477 0 : aPoint.Y() = rDocPos.X() + aOutArea.Top() - GetVisDocLeft();
478 : }
479 :
480 3026 : return aPoint;
481 : }
482 :
483 2973 : Rectangle ImpEditView::GetWindowPos( const Rectangle& rDocRect ) const
484 : {
485 : // Document position => window position
486 2973 : Point aPos( GetWindowPos( rDocRect.TopLeft() ) );
487 2973 : Size aSz = rDocRect.GetSize();
488 2973 : Rectangle aRect;
489 2973 : if ( !pEditEngine->pImpEditEngine->IsVertical() )
490 : {
491 2973 : aRect = Rectangle( aPos, aSz );
492 : }
493 : else
494 : {
495 0 : Point aNewPos( aPos.X()-aSz.Height(), aPos.Y() );
496 0 : aRect = Rectangle( aNewPos, Size( aSz.Height(), aSz.Width() ) );
497 : }
498 2973 : return aRect;
499 : }
500 :
501 106 : void ImpEditView::SetSelectionMode( EESelectionMode eNewMode )
502 : {
503 106 : if ( eSelectionMode != eNewMode )
504 : {
505 13 : DrawSelection();
506 13 : eSelectionMode = eNewMode;
507 13 : DrawSelection(); // redraw
508 : }
509 106 : }
510 :
511 577 : void ImpEditView::SetOutputArea( const Rectangle& rRect )
512 : {
513 : // should be better be aligned on pixels!
514 577 : Rectangle aNewRect( pOutWin->LogicToPixel( rRect ) );
515 577 : aNewRect = pOutWin->PixelToLogic( aNewRect );
516 577 : aOutArea = aNewRect;
517 577 : if ( aOutArea.Right() < aOutArea.Left() )
518 54 : aOutArea.Right() = aOutArea.Left();
519 577 : if ( aOutArea.Bottom() < aOutArea.Top() )
520 54 : aOutArea.Bottom() = aOutArea.Top();
521 :
522 577 : if ( DoBigScroll() )
523 0 : SetScrollDiffX( (sal_uInt16)aOutArea.GetWidth() * 3 / 10 );
524 : else
525 577 : SetScrollDiffX( (sal_uInt16)aOutArea.GetWidth() * 2 / 10 );
526 577 : }
527 :
528 9 : void ImpEditView::ResetOutputArea( const Rectangle& rRect )
529 : {
530 : // remember old out area
531 9 : const Rectangle aOldArea(aOutArea);
532 :
533 : // apply new one
534 9 : SetOutputArea(rRect);
535 :
536 : // invalidate surrounding areas if update is true
537 9 : if(!aOldArea.IsEmpty() && pEditEngine->pImpEditEngine->GetUpdateMode())
538 : {
539 : // #i119885# use grown area if needed; do when getting bigger OR smaller
540 9 : const sal_Int32 nMore(DoInvalidateMore() ? GetWindow()->PixelToLogic(Size(nInvMore, 0)).Width() : 0);
541 :
542 9 : if(aOldArea.Left() > aOutArea.Left())
543 : {
544 9 : GetWindow()->Invalidate(Rectangle(aOutArea.Left() - nMore, aOldArea.Top() - nMore, aOldArea.Left(), aOldArea.Bottom() + nMore));
545 : }
546 0 : else if(aOldArea.Left() < aOutArea.Left())
547 : {
548 0 : GetWindow()->Invalidate(Rectangle(aOldArea.Left() - nMore, aOldArea.Top() - nMore, aOutArea.Left(), aOldArea.Bottom() + nMore));
549 : }
550 :
551 9 : if(aOldArea.Right() > aOutArea.Right())
552 : {
553 9 : GetWindow()->Invalidate(Rectangle(aOutArea.Right(), aOldArea.Top() - nMore, aOldArea.Right() + nMore, aOldArea.Bottom() + nMore));
554 : }
555 0 : else if(aOldArea.Right() < aOutArea.Right())
556 : {
557 0 : GetWindow()->Invalidate(Rectangle(aOldArea.Right(), aOldArea.Top() - nMore, aOutArea.Right() + nMore, aOldArea.Bottom() + nMore));
558 : }
559 :
560 9 : if(aOldArea.Top() > aOutArea.Top())
561 : {
562 8 : GetWindow()->Invalidate(Rectangle(aOldArea.Left() - nMore, aOutArea.Top() - nMore, aOldArea.Right() + nMore, aOldArea.Top()));
563 : }
564 1 : else if(aOldArea.Top() < aOutArea.Top())
565 : {
566 0 : GetWindow()->Invalidate(Rectangle(aOldArea.Left() - nMore, aOldArea.Top() - nMore, aOldArea.Right() + nMore, aOutArea.Top()));
567 : }
568 :
569 9 : if(aOldArea.Bottom() > aOutArea.Bottom())
570 : {
571 8 : GetWindow()->Invalidate(Rectangle(aOldArea.Left() - nMore, aOutArea.Bottom(), aOldArea.Right() + nMore, aOldArea.Bottom() + nMore));
572 : }
573 1 : else if(aOldArea.Bottom() < aOutArea.Bottom())
574 : {
575 0 : GetWindow()->Invalidate(Rectangle(aOldArea.Left() - nMore, aOldArea.Bottom(), aOldArea.Right() + nMore, aOutArea.Bottom() + nMore));
576 : }
577 : }
578 9 : }
579 :
580 9 : void ImpEditView::RecalcOutputArea()
581 : {
582 9 : Point aNewTopLeft( aOutArea.TopLeft() );
583 9 : Size aNewSz( aOutArea.GetSize() );
584 :
585 : // X:
586 9 : if ( DoAutoWidth() )
587 : {
588 9 : if ( pEditEngine->pImpEditEngine->GetStatus().AutoPageWidth() )
589 9 : aNewSz.Width() = pEditEngine->pImpEditEngine->GetPaperSize().Width();
590 9 : switch ( eAnchorMode )
591 : {
592 : case ANCHOR_TOP_LEFT:
593 : case ANCHOR_VCENTER_LEFT:
594 : case ANCHOR_BOTTOM_LEFT:
595 : {
596 0 : aNewTopLeft.X() = aAnchorPoint.X();
597 : }
598 0 : break;
599 : case ANCHOR_TOP_HCENTER:
600 : case ANCHOR_VCENTER_HCENTER:
601 : case ANCHOR_BOTTOM_HCENTER:
602 : {
603 9 : aNewTopLeft.X() = aAnchorPoint.X() - aNewSz.Width() / 2;
604 : }
605 9 : break;
606 : case ANCHOR_TOP_RIGHT:
607 : case ANCHOR_VCENTER_RIGHT:
608 : case ANCHOR_BOTTOM_RIGHT:
609 : {
610 0 : aNewTopLeft.X() = aAnchorPoint.X() - aNewSz.Width() - 1;
611 : }
612 0 : break;
613 : }
614 : }
615 :
616 : // Y:
617 9 : if ( DoAutoHeight() )
618 : {
619 9 : if ( pEditEngine->pImpEditEngine->GetStatus().AutoPageHeight() )
620 9 : aNewSz.Height() = pEditEngine->pImpEditEngine->GetPaperSize().Height();
621 9 : switch ( eAnchorMode )
622 : {
623 : case ANCHOR_TOP_LEFT:
624 : case ANCHOR_TOP_HCENTER:
625 : case ANCHOR_TOP_RIGHT:
626 : {
627 1 : aNewTopLeft.Y() = aAnchorPoint.Y();
628 : }
629 1 : break;
630 : case ANCHOR_VCENTER_LEFT:
631 : case ANCHOR_VCENTER_HCENTER:
632 : case ANCHOR_VCENTER_RIGHT:
633 : {
634 8 : aNewTopLeft.Y() = aAnchorPoint.Y() - aNewSz.Height() / 2;
635 : }
636 8 : break;
637 : case ANCHOR_BOTTOM_LEFT:
638 : case ANCHOR_BOTTOM_HCENTER:
639 : case ANCHOR_BOTTOM_RIGHT:
640 : {
641 0 : aNewTopLeft.Y() = aAnchorPoint.Y() - aNewSz.Height() - 1;
642 : }
643 0 : break;
644 : }
645 : }
646 9 : ResetOutputArea( Rectangle( aNewTopLeft, aNewSz ) );
647 9 : }
648 :
649 9 : void ImpEditView::SetAnchorMode( EVAnchorMode eMode )
650 : {
651 9 : eAnchorMode = eMode;
652 9 : CalcAnchorPoint();
653 9 : }
654 :
655 577 : void ImpEditView::CalcAnchorPoint()
656 : {
657 : // GetHeight() and GetWidth() -1, because rectangle calculation not preferred.
658 :
659 : // X:
660 577 : switch ( eAnchorMode )
661 : {
662 : case ANCHOR_TOP_LEFT:
663 : case ANCHOR_VCENTER_LEFT:
664 : case ANCHOR_BOTTOM_LEFT:
665 : {
666 544 : aAnchorPoint.X() = aOutArea.Left();
667 : }
668 544 : break;
669 : case ANCHOR_TOP_HCENTER:
670 : case ANCHOR_VCENTER_HCENTER:
671 : case ANCHOR_BOTTOM_HCENTER:
672 : {
673 33 : aAnchorPoint.X() = aOutArea.Left() + (aOutArea.GetWidth()-1) / 2;
674 : }
675 33 : break;
676 : case ANCHOR_TOP_RIGHT:
677 : case ANCHOR_VCENTER_RIGHT:
678 : case ANCHOR_BOTTOM_RIGHT:
679 : {
680 0 : aAnchorPoint.X() = aOutArea.Right();
681 : }
682 0 : break;
683 : }
684 :
685 : // Y:
686 577 : switch ( eAnchorMode )
687 : {
688 : case ANCHOR_TOP_LEFT:
689 : case ANCHOR_TOP_HCENTER:
690 : case ANCHOR_TOP_RIGHT:
691 : {
692 559 : aAnchorPoint.Y() = aOutArea.Top();
693 : }
694 559 : break;
695 : case ANCHOR_VCENTER_LEFT:
696 : case ANCHOR_VCENTER_HCENTER:
697 : case ANCHOR_VCENTER_RIGHT:
698 : {
699 18 : aAnchorPoint.Y() = aOutArea.Top() + (aOutArea.GetHeight()-1) / 2;
700 : }
701 18 : break;
702 : case ANCHOR_BOTTOM_LEFT:
703 : case ANCHOR_BOTTOM_HCENTER:
704 : case ANCHOR_BOTTOM_RIGHT:
705 : {
706 0 : aAnchorPoint.Y() = aOutArea.Bottom() - 1;
707 : }
708 0 : break;
709 : }
710 577 : }
711 :
712 2935 : void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor, sal_uInt16 nShowCursorFlags )
713 : {
714 : // No ShowCursor in an empty View ...
715 2935 : if ( ( aOutArea.Left() >= aOutArea.Right() ) && ( aOutArea.Top() >= aOutArea.Bottom() ) )
716 1028 : return;
717 :
718 2725 : pEditEngine->CheckIdleFormatter();
719 2725 : if (!pEditEngine->IsFormatted())
720 30 : pEditEngine->pImpEditEngine->FormatDoc();
721 :
722 : // For some reasons I end up here during the formatting, if the Outliner
723 : // is initialized in Paint, because no SetPool();
724 2725 : if ( pEditEngine->pImpEditEngine->IsFormatting() )
725 0 : return;
726 2725 : if ( !pEditEngine->pImpEditEngine->GetUpdateMode() )
727 605 : return;
728 2120 : if ( pEditEngine->pImpEditEngine->IsInUndo() )
729 0 : return;
730 :
731 2120 : if ( pOutWin->GetCursor() != GetCursor() )
732 348 : pOutWin->SetCursor( GetCursor() );
733 :
734 2120 : EditPaM aPaM( aEditSelection.Max() );
735 :
736 2120 : sal_Int32 nTextPortionStart = 0;
737 2120 : sal_Int32 nPara = pEditEngine->GetEditDoc().GetPos( aPaM.GetNode() );
738 2120 : if (nPara == EE_PARA_NOT_FOUND) // #i94322
739 3 : return;
740 :
741 2117 : const ParaPortion* pParaPortion = pEditEngine->GetParaPortions()[nPara];
742 :
743 2117 : nShowCursorFlags |= nExtraCursorFlags;
744 :
745 2117 : nShowCursorFlags |= GETCRSR_TXTONLY;
746 :
747 : // Use CursorBidiLevel 0/1 in meaning of
748 : // 0: prefer portion end, normal mode
749 : // 1: prefer portion start
750 :
751 2117 : if ( ( GetCursorBidiLevel() != CURSOR_BIDILEVEL_DONTKNOW ) && GetCursorBidiLevel() )
752 : {
753 0 : nShowCursorFlags |= GETCRSR_PREFERPORTIONSTART;
754 : }
755 :
756 2117 : Rectangle aEditCursor = pEditEngine->pImpEditEngine->PaMtoEditCursor( aPaM, nShowCursorFlags );
757 2117 : if ( !IsInsertMode() && !aEditSelection.HasRange() )
758 : {
759 0 : if ( aPaM.GetNode()->Len() && ( aPaM.GetIndex() < aPaM.GetNode()->Len() ) )
760 : {
761 : // If we are behind a portion, and the next portion has other direction, we must change position...
762 0 : aEditCursor.Left() = aEditCursor.Right() = pEditEngine->pImpEditEngine->PaMtoEditCursor( aPaM, GETCRSR_TXTONLY|GETCRSR_PREFERPORTIONSTART ).Left();
763 :
764 0 : sal_Int32 nTextPortion = pParaPortion->GetTextPortions().FindPortion( aPaM.GetIndex(), nTextPortionStart, true );
765 0 : const TextPortion* pTextPortion = pParaPortion->GetTextPortions()[nTextPortion];
766 0 : if ( pTextPortion->GetKind() == PortionKind::TAB )
767 : {
768 0 : aEditCursor.Right() += pTextPortion->GetSize().Width();
769 : }
770 : else
771 : {
772 0 : EditPaM aNext = pEditEngine->CursorRight( aPaM, (sal_uInt16)i18n::CharacterIteratorMode::SKIPCELL );
773 0 : Rectangle aTmpRect = pEditEngine->pImpEditEngine->PaMtoEditCursor( aNext, GETCRSR_TXTONLY );
774 0 : if ( aTmpRect.Top() != aEditCursor.Top() )
775 0 : aTmpRect = pEditEngine->pImpEditEngine->PaMtoEditCursor( aNext, GETCRSR_TXTONLY|GETCRSR_ENDOFLINE );
776 0 : aEditCursor.Right() = aTmpRect.Left();
777 : }
778 : }
779 : }
780 2117 : long nMaxHeight = !IsVertical() ? aOutArea.GetHeight() : aOutArea.GetWidth();
781 2117 : if ( aEditCursor.GetHeight() > nMaxHeight )
782 : {
783 1834 : aEditCursor.Bottom() = aEditCursor.Top() + nMaxHeight - 1;
784 : }
785 2117 : if ( bGotoCursor ) // && (!pEditEngine->pImpEditEngine->GetStatus().AutoPageSize() ) )
786 : {
787 : // check if scrolling is necessary...
788 : // if scrolling, then update () and Scroll ()!
789 1005 : long nDocDiffX = 0;
790 1005 : long nDocDiffY = 0;
791 :
792 1005 : Rectangle aTmpVisArea( GetVisDocArea() );
793 : // aTmpOutArea: if OutputArea > Paper width and
794 : // Text > Paper width ( over large fields )
795 1005 : long nMaxTextWidth = !IsVertical() ? pEditEngine->pImpEditEngine->GetPaperSize().Width() : pEditEngine->pImpEditEngine->GetPaperSize().Height();
796 1005 : if ( aTmpVisArea.GetWidth() > nMaxTextWidth )
797 0 : aTmpVisArea.Right() = aTmpVisArea.Left() + nMaxTextWidth;
798 :
799 1005 : if ( aEditCursor.Bottom() > aTmpVisArea.Bottom() )
800 : { // Scroll up, here positive
801 13 : nDocDiffY = aEditCursor.Bottom() - aTmpVisArea.Bottom();
802 : }
803 992 : else if ( aEditCursor.Top() < aTmpVisArea.Top() )
804 : { // Scroll down, here negative
805 0 : nDocDiffY = aEditCursor.Top() - aTmpVisArea.Top();
806 : }
807 :
808 1005 : if ( aEditCursor.Right() > aTmpVisArea.Right() )
809 : {
810 : // Scroll left, positiv
811 13 : nDocDiffX = aEditCursor.Right() - aTmpVisArea.Right();
812 : // Can it be a little more?
813 13 : if ( aEditCursor.Right() < ( nMaxTextWidth - GetScrollDiffX() ) )
814 13 : nDocDiffX += GetScrollDiffX();
815 : else
816 : {
817 0 : long n = nMaxTextWidth - aEditCursor.Right();
818 : // If MapMode != RefMapMode then the EditCursor can go beyond
819 : // the paper width!
820 0 : nDocDiffX += ( n > 0 ? n : -n );
821 : }
822 : }
823 992 : else if ( aEditCursor.Left() < aTmpVisArea.Left() )
824 : {
825 : // Scroll right, negative:
826 13 : nDocDiffX = aEditCursor.Left() - aTmpVisArea.Left();
827 : // Can it be a little more?
828 13 : if ( aEditCursor.Left() > ( - (long)GetScrollDiffX() ) )
829 13 : nDocDiffX -= GetScrollDiffX();
830 : else
831 0 : nDocDiffX -= aEditCursor.Left();
832 : }
833 1005 : if ( aPaM.GetIndex() == 0 ) // Olli needed for the Outliner
834 : {
835 : // But make sure that the cursor is not leaving visible area
836 : // because of this!
837 964 : if ( aEditCursor.Left() < aTmpVisArea.GetWidth() )
838 : {
839 964 : nDocDiffX = -aTmpVisArea.Left();
840 : }
841 : }
842 :
843 1005 : if ( nDocDiffX | nDocDiffY )
844 : {
845 26 : long nDiffX = !IsVertical() ? nDocDiffX : -nDocDiffY;
846 26 : long nDiffY = !IsVertical() ? nDocDiffY : nDocDiffX;
847 :
848 : // Negative: Back to the top or left edge
849 26 : if ( ( std::abs( nDiffY ) > pEditEngine->GetOnePixelInRef() ) && DoBigScroll() )
850 : {
851 0 : long nH = aOutArea.GetHeight() / 4;
852 0 : if ( ( nH > aEditCursor.GetHeight() ) && ( std::abs( nDiffY ) < nH ) )
853 : {
854 0 : if ( nDiffY < 0 )
855 0 : nDiffY -= nH;
856 : else
857 0 : nDiffY += nH;
858 : }
859 : }
860 :
861 26 : if ( ( std::abs( nDiffX ) > pEditEngine->GetOnePixelInRef() ) && DoBigScroll() )
862 : {
863 0 : long nW = aOutArea.GetWidth() / 4;
864 0 : if ( std::abs( nDiffX ) < nW )
865 : {
866 0 : if ( nDiffY < 0 )
867 0 : nDiffY -= nW;
868 : else
869 0 : nDiffY += nW;
870 : }
871 : }
872 :
873 26 : if ( nDiffX )
874 26 : pEditEngine->GetInternalEditStatus().GetStatusWord() = pEditEngine->GetInternalEditStatus().GetStatusWord() | EditStatusFlags::HSCROLL;
875 26 : if ( nDiffY )
876 13 : pEditEngine->GetInternalEditStatus().GetStatusWord() = pEditEngine->GetInternalEditStatus().GetStatusWord() | EditStatusFlags::VSCROLL;
877 26 : Scroll( -nDiffX, -nDiffY );
878 26 : pEditEngine->pImpEditEngine->DelayedCallStatusHdl();
879 : }
880 : }
881 :
882 : // Cursor may trim a little ...
883 4234 : if ( ( aEditCursor.Bottom() > GetVisDocTop() ) &&
884 2117 : ( aEditCursor.Top() < GetVisDocBottom() ) )
885 : {
886 2117 : if ( aEditCursor.Bottom() > GetVisDocBottom() )
887 0 : aEditCursor.Bottom() = GetVisDocBottom();
888 2117 : if ( aEditCursor.Top() < GetVisDocTop() )
889 0 : aEditCursor.Top() = GetVisDocTop();
890 : }
891 :
892 2117 : long nOnePixel = pOutWin->PixelToLogic( Size( 1, 0 ) ).Width();
893 :
894 2117 : if ( /* pEditEngine->pImpEditEngine->GetStatus().AutoPageSize() || */
895 4234 : ( ( aEditCursor.Top() + nOnePixel >= GetVisDocTop() ) &&
896 4234 : ( aEditCursor.Bottom() - nOnePixel <= GetVisDocBottom() ) &&
897 6351 : ( aEditCursor.Left() + nOnePixel >= GetVisDocLeft() ) &&
898 2117 : ( aEditCursor.Right() - nOnePixel <= GetVisDocRight() ) ) )
899 : {
900 2117 : Rectangle aCursorRect = GetWindowPos( aEditCursor );
901 2117 : GetCursor()->SetPos( aCursorRect.TopLeft() );
902 2117 : Size aCursorSz( aCursorRect.GetSize() );
903 : // Rectangle is inclusive
904 2117 : aCursorSz.Width()--;
905 2117 : aCursorSz.Height()--;
906 2117 : if ( !aCursorSz.Width() || !aCursorSz.Height() )
907 : {
908 2117 : long nCursorSz = pOutWin->GetSettings().GetStyleSettings().GetCursorSize();
909 2117 : nCursorSz = pOutWin->PixelToLogic( Size( nCursorSz, 0 ) ).Width();
910 2117 : if ( !aCursorSz.Width() )
911 2117 : aCursorSz.Width() = nCursorSz;
912 2117 : if ( !aCursorSz.Height() )
913 0 : aCursorSz.Height() = nCursorSz;
914 : }
915 : // #111036# Let VCL do orientation for cursor, otherwise problem when cursor has direction flag
916 2117 : if ( IsVertical() )
917 : {
918 0 : Size aOldSz( aCursorSz );
919 0 : aCursorSz.Width() = aOldSz.Height();
920 0 : aCursorSz.Height() = aOldSz.Width();
921 0 : GetCursor()->SetPos( aCursorRect.TopRight() );
922 0 : GetCursor()->SetOrientation( 2700 );
923 : }
924 : else
925 : // #i32593# Reset correct orientation in horizontal layout
926 2117 : GetCursor()->SetOrientation( 0 );
927 :
928 2117 : GetCursor()->SetSize( aCursorSz );
929 :
930 2117 : if (isTiledRendering())
931 : {
932 57 : const Point& rPos = GetCursor()->GetPos();
933 57 : Rectangle aRect(rPos.getX(), rPos.getY(), rPos.getX() + GetCursor()->GetWidth(), rPos.getY() + GetCursor()->GetHeight());
934 :
935 : // LOK output is always in twips, convert from mm100 if necessary.
936 57 : if (pOutWin->GetMapMode().GetMapUnit() == MAP_100TH_MM)
937 39 : aRect = OutputDevice::LogicToLogic(aRect, MAP_100TH_MM, MAP_TWIP);
938 : // Let the LOK client decide the cursor width.
939 57 : aRect.setWidth(0);
940 :
941 57 : OString sRect = aRect.toString();
942 57 : libreOfficeKitCallback(LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, sRect.getStr());
943 : }
944 :
945 2117 : CursorDirection nCursorDir = CursorDirection::NONE;
946 2117 : if ( IsInsertMode() && !aEditSelection.HasRange() && ( pEditEngine->pImpEditEngine->HasDifferentRTLLevels( aPaM.GetNode() ) ) )
947 : {
948 0 : sal_uInt16 nTextPortion = pParaPortion->GetTextPortions().FindPortion( aPaM.GetIndex(), nTextPortionStart, (nShowCursorFlags & GETCRSR_PREFERPORTIONSTART) != 0 );
949 0 : const TextPortion* pTextPortion = pParaPortion->GetTextPortions()[nTextPortion];
950 0 : sal_uInt16 nRTLLevel = pTextPortion->GetRightToLeft();
951 0 : if ( nRTLLevel%2 )
952 0 : nCursorDir = CursorDirection::RTL;
953 : else
954 0 : nCursorDir = CursorDirection::LTR;
955 :
956 : }
957 2117 : GetCursor()->SetDirection( nCursorDir );
958 :
959 2117 : if ( bForceVisCursor )
960 865 : GetCursor()->Show();
961 : {
962 2117 : SvxFont aFont;
963 2117 : pEditEngine->SeekCursor( aPaM.GetNode(), aPaM.GetIndex()+1, aFont );
964 2117 : InputContextFlags nContextFlags = InputContextFlags::Text|InputContextFlags::ExtText;
965 2117 : GetWindow()->SetInputContext( InputContext( aFont, nContextFlags ) );
966 : }
967 : }
968 : else
969 : {
970 0 : pEditEngine->pImpEditEngine->GetStatus().GetStatusWord() = pEditEngine->pImpEditEngine->GetStatus().GetStatusWord() | EditStatusFlags::CURSOROUT;
971 0 : GetCursor()->Hide();
972 0 : GetCursor()->SetPos( Point( -1, -1 ) );
973 0 : GetCursor()->SetSize( Size( 0, 0 ) );
974 : }
975 : }
976 :
977 191 : Pair ImpEditView::Scroll( long ndX, long ndY, sal_uInt8 nRangeCheck )
978 : {
979 : DBG_ASSERT( pEditEngine->pImpEditEngine->IsFormatted(), "Scroll: Not formatted!" );
980 191 : if ( !ndX && !ndY )
981 165 : return Range( 0, 0 );
982 :
983 : #ifdef DBG_UTIL
984 : Rectangle aR( aOutArea );
985 : aR = pOutWin->LogicToPixel( aR );
986 : aR = pOutWin->PixelToLogic( aR );
987 : DBG_ASSERTWARNING( aR == aOutArea, "OutArea before Scroll not aligned" );
988 : #endif
989 :
990 26 : Rectangle aNewVisArea( GetVisDocArea() );
991 :
992 : // Vertical:
993 26 : if ( !IsVertical() )
994 : {
995 26 : aNewVisArea.Top() -= ndY;
996 26 : aNewVisArea.Bottom() -= ndY;
997 : }
998 : else
999 : {
1000 0 : aNewVisArea.Top() += ndX;
1001 0 : aNewVisArea.Bottom() += ndX;
1002 : }
1003 26 : if ( ( nRangeCheck == RGCHK_PAPERSZ1 ) && ( aNewVisArea.Bottom() > (long)pEditEngine->pImpEditEngine->GetTextHeight() ) )
1004 : {
1005 : // GetTextHeight still optimizing!
1006 0 : long nDiff = pEditEngine->pImpEditEngine->GetTextHeight() - aNewVisArea.Bottom(); // negative
1007 0 : aNewVisArea.Move( 0, nDiff ); // could end up in the negative area...
1008 : }
1009 26 : if ( ( aNewVisArea.Top() < 0 ) && ( nRangeCheck != RGCHK_NONE ) )
1010 0 : aNewVisArea.Move( 0, -aNewVisArea.Top() );
1011 :
1012 : // Horizontal:
1013 26 : if ( !IsVertical() )
1014 : {
1015 26 : aNewVisArea.Left() -= ndX;
1016 26 : aNewVisArea.Right() -= ndX;
1017 : }
1018 : else
1019 : {
1020 0 : aNewVisArea.Left() -= ndY;
1021 0 : aNewVisArea.Right() -= ndY;
1022 : }
1023 26 : if ( ( nRangeCheck == RGCHK_PAPERSZ1 ) && ( aNewVisArea.Right() > (long)pEditEngine->pImpEditEngine->CalcTextWidth( false ) ) )
1024 : {
1025 0 : long nDiff = pEditEngine->pImpEditEngine->CalcTextWidth( false ) - aNewVisArea.Right(); // negative
1026 0 : aNewVisArea.Move( nDiff, 0 ); // could end up in the negative area...
1027 : }
1028 26 : if ( ( aNewVisArea.Left() < 0 ) && ( nRangeCheck != RGCHK_NONE ) )
1029 0 : aNewVisArea.Move( -aNewVisArea.Left(), 0 );
1030 :
1031 : // The difference must be alignt on pixel (due to scroll!)
1032 26 : long nDiffX = !IsVertical() ? ( GetVisDocLeft() - aNewVisArea.Left() ) : -( GetVisDocTop() - aNewVisArea.Top() );
1033 26 : long nDiffY = !IsVertical() ? ( GetVisDocTop() - aNewVisArea.Top() ) : ( GetVisDocLeft() - aNewVisArea.Left() );
1034 :
1035 26 : Size aDiffs( nDiffX, nDiffY );
1036 26 : aDiffs = pOutWin->LogicToPixel( aDiffs );
1037 26 : aDiffs = pOutWin->PixelToLogic( aDiffs );
1038 :
1039 26 : long nRealDiffX = aDiffs.Width();
1040 26 : long nRealDiffY = aDiffs.Height();
1041 :
1042 :
1043 26 : if ( nRealDiffX || nRealDiffY )
1044 : {
1045 26 : vcl::Cursor* pCrsr = GetCursor();
1046 26 : bool bVisCursor = pCrsr->IsVisible();
1047 26 : pCrsr->Hide();
1048 26 : pOutWin->Update();
1049 26 : if ( !IsVertical() )
1050 26 : aVisDocStartPos.Move( -nRealDiffX, -nRealDiffY );
1051 : else
1052 0 : aVisDocStartPos.Move( -nRealDiffY, nRealDiffX );
1053 : // Das Move um den allignten Wert ergibt nicht unbedingt ein
1054 : // alligntes Rechteck...
1055 : // Aligned value of the move does not necessarily result in aligned
1056 : // rectangle ...
1057 26 : aVisDocStartPos = pOutWin->LogicToPixel( aVisDocStartPos );
1058 26 : aVisDocStartPos = pOutWin->PixelToLogic( aVisDocStartPos );
1059 26 : Rectangle aRect( aOutArea );
1060 26 : pOutWin->Scroll( nRealDiffX, nRealDiffY, aRect, ScrollFlags::Clip );
1061 26 : pOutWin->Update();
1062 26 : pCrsr->SetPos( pCrsr->GetPos() + Point( nRealDiffX, nRealDiffY ) );
1063 26 : if ( bVisCursor )
1064 : {
1065 0 : Rectangle aCursorRect( pCrsr->GetPos(), pCrsr->GetSize() );
1066 0 : if ( aOutArea.IsInside( aCursorRect ) )
1067 0 : pCrsr->Show();
1068 : }
1069 :
1070 26 : if ( pEditEngine->pImpEditEngine->GetNotifyHdl().IsSet() )
1071 : {
1072 0 : EENotify aNotify( EE_NOTIFY_TEXTVIEWSCROLLED );
1073 0 : aNotify.pEditEngine = pEditEngine;
1074 0 : aNotify.pEditView = GetEditViewPtr();
1075 0 : pEditEngine->pImpEditEngine->CallNotify( aNotify );
1076 : }
1077 : }
1078 :
1079 26 : return Pair( nRealDiffX, nRealDiffY );
1080 : }
1081 :
1082 3 : bool ImpEditView::PostKeyEvent( const KeyEvent& rKeyEvent, vcl::Window* pFrameWin )
1083 : {
1084 3 : bool bDone = false;
1085 :
1086 3 : KeyFuncType eFunc = rKeyEvent.GetKeyCode().GetFunction();
1087 3 : if ( eFunc != KeyFuncType::DONTKNOW )
1088 : {
1089 0 : switch ( eFunc )
1090 : {
1091 : case KeyFuncType::CUT:
1092 : {
1093 0 : if ( !bReadOnly )
1094 : {
1095 0 : Reference<com::sun::star::datatransfer::clipboard::XClipboard> aClipBoard(GetWindow()->GetClipboard());
1096 0 : CutCopy( aClipBoard, true );
1097 0 : bDone = true;
1098 : }
1099 : }
1100 0 : break;
1101 : case KeyFuncType::COPY:
1102 : {
1103 0 : Reference<com::sun::star::datatransfer::clipboard::XClipboard> aClipBoard(GetWindow()->GetClipboard());
1104 0 : CutCopy( aClipBoard, false );
1105 0 : bDone = true;
1106 : }
1107 0 : break;
1108 : case KeyFuncType::PASTE:
1109 : {
1110 0 : if ( !bReadOnly && IsPasteEnabled() )
1111 : {
1112 0 : pEditEngine->pImpEditEngine->UndoActionStart( EDITUNDO_PASTE );
1113 0 : Reference<com::sun::star::datatransfer::clipboard::XClipboard> aClipBoard(GetWindow()->GetClipboard());
1114 0 : Paste( aClipBoard, pEditEngine->pImpEditEngine->GetStatus().AllowPasteSpecial() );
1115 0 : pEditEngine->pImpEditEngine->UndoActionEnd( EDITUNDO_PASTE );
1116 0 : bDone = true;
1117 : }
1118 : }
1119 0 : break;
1120 : default:
1121 0 : break;
1122 : }
1123 : }
1124 :
1125 3 : if( !bDone )
1126 3 : bDone = pEditEngine->PostKeyEvent( rKeyEvent, GetEditViewPtr(), pFrameWin );
1127 :
1128 3 : return bDone;
1129 : }
1130 :
1131 1 : bool ImpEditView::MouseButtonUp( const MouseEvent& rMouseEvent )
1132 : {
1133 1 : if ( pEditEngine->GetInternalEditStatus().NotifyCursorMovements() )
1134 : {
1135 0 : if ( pEditEngine->GetInternalEditStatus().GetPrevParagraph() != pEditEngine->GetEditDoc().GetPos( GetEditSelection().Max().GetNode() ) )
1136 : {
1137 0 : pEditEngine->GetInternalEditStatus().GetStatusWord() = pEditEngine->GetInternalEditStatus().GetStatusWord() | EditStatusFlags::CRSRLEFTPARA;
1138 0 : pEditEngine->pImpEditEngine->CallStatusHdl();
1139 : }
1140 : }
1141 1 : nTravelXPos = TRAVEL_X_DONTKNOW;
1142 1 : nCursorBidiLevel = CURSOR_BIDILEVEL_DONTKNOW;
1143 1 : nExtraCursorFlags = 0;
1144 1 : bClickedInSelection = false;
1145 :
1146 1 : if ( rMouseEvent.IsMiddle() && !bReadOnly &&
1147 0 : ( GetWindow()->GetSettings().GetMouseSettings().GetMiddleButtonAction() == MouseMiddleButtonAction::PasteSelection ) )
1148 : {
1149 0 : Reference<com::sun::star::datatransfer::clipboard::XClipboard> aClipBoard(GetWindow()->GetPrimarySelection());
1150 0 : Paste( aClipBoard );
1151 : }
1152 1 : else if ( rMouseEvent.IsLeft() && GetEditSelection().HasRange() )
1153 : {
1154 0 : Reference<com::sun::star::datatransfer::clipboard::XClipboard> aClipBoard(GetWindow()->GetPrimarySelection());
1155 0 : CutCopy( aClipBoard, false );
1156 : }
1157 :
1158 1 : return pEditEngine->pImpEditEngine->MouseButtonUp( rMouseEvent, GetEditViewPtr() );
1159 : }
1160 :
1161 0 : void ImpEditView::ReleaseMouse()
1162 : {
1163 0 : pEditEngine->pImpEditEngine->ReleaseMouse();
1164 0 : }
1165 :
1166 1 : bool ImpEditView::MouseButtonDown( const MouseEvent& rMouseEvent )
1167 : {
1168 1 : pEditEngine->CheckIdleFormatter(); // If fast typing and mouse button downs
1169 1 : if ( pEditEngine->GetInternalEditStatus().NotifyCursorMovements() )
1170 0 : pEditEngine->GetInternalEditStatus().GetPrevParagraph() = pEditEngine->GetEditDoc().GetPos( GetEditSelection().Max().GetNode() );
1171 1 : nTravelXPos = TRAVEL_X_DONTKNOW;
1172 1 : nExtraCursorFlags = 0;
1173 1 : nCursorBidiLevel = CURSOR_BIDILEVEL_DONTKNOW;
1174 1 : bClickedInSelection = IsSelectionAtPoint( rMouseEvent.GetPosPixel() );
1175 1 : return pEditEngine->pImpEditEngine->MouseButtonDown( rMouseEvent, GetEditViewPtr() );
1176 : }
1177 :
1178 0 : bool ImpEditView::MouseMove( const MouseEvent& rMouseEvent )
1179 : {
1180 0 : return pEditEngine->pImpEditEngine->MouseMove( rMouseEvent, GetEditViewPtr() );
1181 : }
1182 :
1183 0 : void ImpEditView::Command( const CommandEvent& rCEvt )
1184 : {
1185 0 : pEditEngine->CheckIdleFormatter(); // If fast typing and mouse button down
1186 0 : pEditEngine->pImpEditEngine->Command( rCEvt, GetEditViewPtr() );
1187 0 : }
1188 :
1189 :
1190 239 : void ImpEditView::SetInsertMode( bool bInsert )
1191 : {
1192 239 : if ( bInsert != IsInsertMode() )
1193 : {
1194 0 : SetFlags( nControl, EVControlBits::OVERWRITE, !bInsert );
1195 0 : ShowCursor( DoAutoScroll(), false );
1196 : }
1197 239 : }
1198 :
1199 0 : bool ImpEditView::IsWrongSpelledWord( const EditPaM& rPaM, bool bMarkIfWrong )
1200 : {
1201 0 : bool bIsWrong = false;
1202 0 : if ( rPaM.GetNode()->GetWrongList() )
1203 : {
1204 0 : EditSelection aSel = pEditEngine->SelectWord( rPaM, ::com::sun::star::i18n::WordType::DICTIONARY_WORD );
1205 0 : bIsWrong = rPaM.GetNode()->GetWrongList()->HasWrong( aSel.Min().GetIndex(), aSel.Max().GetIndex() );
1206 0 : if ( bIsWrong && bMarkIfWrong )
1207 : {
1208 0 : DrawSelection();
1209 0 : SetEditSelection( aSel );
1210 0 : DrawSelection();
1211 : }
1212 : }
1213 0 : return bIsWrong;
1214 : }
1215 :
1216 0 : OUString ImpEditView::SpellIgnoreOrAddWord( bool bAdd )
1217 : {
1218 0 : OUString aWord;
1219 0 : if ( pEditEngine->pImpEditEngine->GetSpeller().is() )
1220 : {
1221 0 : EditPaM aPaM = GetEditSelection().Max();
1222 0 : if ( !HasSelection() )
1223 : {
1224 0 : EditSelection aSel = pEditEngine->SelectWord(aPaM);
1225 0 : aWord = pEditEngine->pImpEditEngine->GetSelected( aSel );
1226 : }
1227 : else
1228 : {
1229 0 : aWord = pEditEngine->pImpEditEngine->GetSelected( GetEditSelection() );
1230 : // And deselect
1231 0 : DrawSelection();
1232 0 : SetEditSelection( EditSelection( aPaM, aPaM ) );
1233 0 : DrawSelection();
1234 : }
1235 :
1236 0 : if ( !aWord.isEmpty() )
1237 : {
1238 0 : if ( bAdd )
1239 : {
1240 : OSL_FAIL( "Sorry, AddWord not implemented" );
1241 : }
1242 : else // Ignore
1243 : {
1244 0 : Reference< XDictionary > xDic( SvxGetIgnoreAllList(), UNO_QUERY );
1245 0 : if (xDic.is())
1246 0 : xDic->add( aWord, sal_False, OUString() );
1247 : }
1248 0 : EditDoc& rDoc = pEditEngine->GetEditDoc();
1249 0 : sal_Int32 nNodes = rDoc.Count();
1250 0 : for ( sal_Int32 n = 0; n < nNodes; n++ )
1251 : {
1252 0 : ContentNode* pNode = rDoc.GetObject( n );
1253 0 : pNode->GetWrongList()->MarkWrongsInvalid();
1254 : }
1255 0 : pEditEngine->pImpEditEngine->DoOnlineSpelling( aPaM.GetNode() );
1256 0 : pEditEngine->pImpEditEngine->StartOnlineSpellTimer();
1257 : }
1258 : }
1259 0 : return aWord;
1260 : }
1261 :
1262 3 : void ImpEditView::DeleteSelected()
1263 : {
1264 3 : DrawSelection();
1265 :
1266 3 : pEditEngine->pImpEditEngine->UndoActionStart( EDITUNDO_DELETE );
1267 :
1268 3 : EditPaM aPaM = pEditEngine->pImpEditEngine->DeleteSelected( GetEditSelection() );
1269 :
1270 3 : pEditEngine->pImpEditEngine->UndoActionEnd( EDITUNDO_DELETE );
1271 :
1272 3 : SetEditSelection( EditSelection( aPaM, aPaM ) );
1273 3 : pEditEngine->pImpEditEngine->FormatAndUpdate( GetEditViewPtr() );
1274 3 : ShowCursor( DoAutoScroll(), true );
1275 3 : }
1276 :
1277 1 : const SvxFieldItem* ImpEditView::GetField( const Point& rPos, sal_Int32* pPara, sal_Int32* pPos ) const
1278 : {
1279 1 : if( !GetOutputArea().IsInside( rPos ) )
1280 0 : return 0;
1281 :
1282 1 : Point aDocPos( GetDocPos( rPos ) );
1283 1 : EditPaM aPaM = pEditEngine->GetPaM(aDocPos, false);
1284 :
1285 1 : if ( aPaM.GetIndex() == aPaM.GetNode()->Len() )
1286 : {
1287 : // Otherwise, whenever the Field at the very end and mouse under the text
1288 0 : return 0;
1289 : }
1290 :
1291 1 : const CharAttribList::AttribsType& rAttrs = aPaM.GetNode()->GetCharAttribs().GetAttribs();
1292 1 : const sal_Int32 nXPos = aPaM.GetIndex();
1293 2 : for (size_t nAttr = rAttrs.size(); nAttr; )
1294 : {
1295 0 : const EditCharAttrib& rAttr = rAttrs[--nAttr];
1296 0 : if (rAttr.GetStart() == nXPos)
1297 : {
1298 0 : if (rAttr.Which() == EE_FEATURE_FIELD)
1299 : {
1300 : DBG_ASSERT(dynamic_cast<const SvxFieldItem*>(rAttr.GetItem()), "No FieldItem...");
1301 0 : if ( pPara )
1302 0 : *pPara = pEditEngine->GetEditDoc().GetPos( aPaM.GetNode() );
1303 0 : if ( pPos )
1304 0 : *pPos = rAttr.GetStart();
1305 0 : return static_cast<const SvxFieldItem*>(rAttr.GetItem());
1306 : }
1307 : }
1308 : }
1309 1 : return NULL;
1310 : }
1311 :
1312 0 : bool ImpEditView::IsBulletArea( const Point& rPos, sal_Int32* pPara )
1313 : {
1314 0 : if ( pPara )
1315 0 : *pPara = EE_PARA_NOT_FOUND;
1316 :
1317 0 : if( !GetOutputArea().IsInside( rPos ) )
1318 0 : return false;
1319 :
1320 0 : Point aDocPos( GetDocPos( rPos ) );
1321 0 : EditPaM aPaM = pEditEngine->GetPaM(aDocPos, false);
1322 :
1323 0 : if ( aPaM.GetIndex() == 0 )
1324 : {
1325 0 : sal_Int32 nPara = pEditEngine->GetEditDoc().GetPos( aPaM.GetNode() );
1326 0 : Rectangle aBulletArea = pEditEngine->GetBulletArea( nPara );
1327 0 : long nY = pEditEngine->GetDocPosTopLeft( nPara ).Y();
1328 0 : const ParaPortion* pParaPortion = pEditEngine->GetParaPortions()[nPara];
1329 0 : nY += pParaPortion->GetFirstLineOffset();
1330 0 : if ( ( aDocPos.Y() > ( nY + aBulletArea.Top() ) ) &&
1331 0 : ( aDocPos.Y() < ( nY + aBulletArea.Bottom() ) ) &&
1332 0 : ( aDocPos.X() > ( aBulletArea.Left() ) ) &&
1333 0 : ( aDocPos.X() < ( aBulletArea.Right() ) ) )
1334 : {
1335 0 : if ( pPara )
1336 0 : *pPara = nPara;
1337 0 : return true;
1338 : }
1339 : }
1340 :
1341 0 : return false;
1342 : }
1343 :
1344 0 : void ImpEditView::CutCopy( ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard >& rxClipboard, bool bCut )
1345 : {
1346 0 : if ( rxClipboard.is() && GetEditSelection().HasRange() )
1347 : {
1348 0 : uno::Reference<datatransfer::XTransferable> xData = pEditEngine->CreateTransferable( GetEditSelection() );
1349 :
1350 : {
1351 0 : SolarMutexReleaser aReleaser;
1352 :
1353 : try
1354 : {
1355 0 : rxClipboard->setContents( xData, NULL );
1356 :
1357 : // #87756# FlushClipboard, but it would be better to become a TerminateListener to the Desktop and flush on demand...
1358 0 : uno::Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( rxClipboard, uno::UNO_QUERY );
1359 0 : if( xFlushableClipboard.is() )
1360 0 : xFlushableClipboard->flushClipboard();
1361 : }
1362 0 : catch( const ::com::sun::star::uno::Exception& )
1363 : {
1364 0 : }
1365 :
1366 : }
1367 :
1368 0 : if ( bCut )
1369 : {
1370 0 : pEditEngine->pImpEditEngine->UndoActionStart( EDITUNDO_CUT );
1371 0 : DeleteSelected();
1372 0 : pEditEngine->pImpEditEngine->UndoActionEnd( EDITUNDO_CUT );
1373 :
1374 0 : }
1375 : }
1376 0 : }
1377 :
1378 0 : void ImpEditView::Paste( ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard >& rxClipboard, bool bUseSpecial )
1379 : {
1380 0 : if ( rxClipboard.is() )
1381 : {
1382 0 : uno::Reference< datatransfer::XTransferable > xDataObj;
1383 :
1384 : try
1385 : {
1386 0 : SolarMutexReleaser aReleaser;
1387 0 : xDataObj = rxClipboard->getContents();
1388 : }
1389 0 : catch( const ::com::sun::star::uno::Exception& )
1390 : {
1391 : }
1392 :
1393 0 : if ( xDataObj.is() && EditEngine::HasValidData( xDataObj ) )
1394 : {
1395 0 : pEditEngine->pImpEditEngine->UndoActionStart( EDITUNDO_PASTE );
1396 :
1397 0 : EditSelection aSel( GetEditSelection() );
1398 0 : if ( aSel.HasRange() )
1399 : {
1400 0 : DrawSelection();
1401 0 : aSel = pEditEngine->DeleteSelection(aSel);
1402 : }
1403 :
1404 0 : PasteOrDropInfos aPasteOrDropInfos;
1405 0 : aPasteOrDropInfos.nAction = EE_ACTION_PASTE;
1406 0 : aPasteOrDropInfos.nStartPara = pEditEngine->GetEditDoc().GetPos( aSel.Min().GetNode() );
1407 0 : pEditEngine->HandleBeginPasteOrDrop(aPasteOrDropInfos);
1408 :
1409 0 : if ( DoSingleLinePaste() )
1410 : {
1411 0 : datatransfer::DataFlavor aFlavor;
1412 0 : SotExchange::GetFormatDataFlavor( SotClipboardFormatId::STRING, aFlavor );
1413 0 : if ( xDataObj->isDataFlavorSupported( aFlavor ) )
1414 : {
1415 : try
1416 : {
1417 0 : uno::Any aData = xDataObj->getTransferData( aFlavor );
1418 0 : OUString aTmpText;
1419 0 : aData >>= aTmpText;
1420 0 : OUString aText(convertLineEnd(aTmpText, LINEEND_LF));
1421 0 : aText = aText.replaceAll( OUString(LINE_SEP), " " );
1422 0 : aSel = pEditEngine->InsertText(aSel, aText);
1423 : }
1424 0 : catch( ... )
1425 : {
1426 : ; // #i9286# can happen, even if isDataFlavorSupported returns true...
1427 : }
1428 0 : }
1429 : }
1430 : else
1431 : {
1432 0 : aSel = pEditEngine->InsertText(
1433 0 : xDataObj, OUString(), aSel.Min(),
1434 0 : bUseSpecial && pEditEngine->GetInternalEditStatus().AllowPasteSpecial());
1435 : }
1436 :
1437 0 : aPasteOrDropInfos.nEndPara = pEditEngine->GetEditDoc().GetPos( aSel.Max().GetNode() );
1438 0 : pEditEngine->HandleEndPasteOrDrop(aPasteOrDropInfos);
1439 :
1440 0 : pEditEngine->pImpEditEngine->UndoActionEnd( EDITUNDO_PASTE );
1441 0 : SetEditSelection( aSel );
1442 0 : pEditEngine->pImpEditEngine->UpdateSelections();
1443 0 : pEditEngine->pImpEditEngine->FormatAndUpdate( GetEditViewPtr() );
1444 0 : ShowCursor( DoAutoScroll(), true );
1445 0 : }
1446 : }
1447 0 : }
1448 :
1449 :
1450 2 : bool ImpEditView::IsInSelection( const EditPaM& rPaM )
1451 : {
1452 2 : EditSelection aSel = GetEditSelection();
1453 2 : if ( !aSel.HasRange() )
1454 2 : return false;
1455 :
1456 0 : aSel.Adjust( pEditEngine->GetEditDoc() );
1457 :
1458 0 : sal_Int32 nStartNode = pEditEngine->GetEditDoc().GetPos( aSel.Min().GetNode() );
1459 0 : sal_Int32 nEndNode = pEditEngine->GetEditDoc().GetPos( aSel.Max().GetNode() );
1460 0 : sal_Int32 nCurNode = pEditEngine->GetEditDoc().GetPos( rPaM.GetNode() );
1461 :
1462 0 : if ( ( nCurNode > nStartNode ) && ( nCurNode < nEndNode ) )
1463 0 : return true;
1464 :
1465 0 : if ( nStartNode == nEndNode )
1466 : {
1467 0 : if ( nCurNode == nStartNode )
1468 0 : if ( ( rPaM.GetIndex() >= aSel.Min().GetIndex() ) && ( rPaM.GetIndex() < aSel.Max().GetIndex() ) )
1469 0 : return true;
1470 : }
1471 0 : else if ( ( nCurNode == nStartNode ) && ( rPaM.GetIndex() >= aSel.Min().GetIndex() ) )
1472 0 : return true;
1473 0 : else if ( ( nCurNode == nEndNode ) && ( rPaM.GetIndex() < aSel.Max().GetIndex() ) )
1474 0 : return true;
1475 :
1476 0 : return false;
1477 : }
1478 :
1479 1 : void ImpEditView::CreateAnchor()
1480 : {
1481 1 : pEditEngine->SetInSelectionMode(true);
1482 1 : GetEditSelection().Min() = GetEditSelection().Max();
1483 1 : }
1484 :
1485 1 : void ImpEditView::DeselectAll()
1486 : {
1487 1 : pEditEngine->SetInSelectionMode(false);
1488 1 : DrawSelection();
1489 1 : GetEditSelection().Min() = GetEditSelection().Max();
1490 1 : }
1491 :
1492 2 : bool ImpEditView::IsSelectionAtPoint( const Point& rPosPixel )
1493 : {
1494 2 : if ( pDragAndDropInfo && pDragAndDropInfo->pField )
1495 0 : return true;
1496 :
1497 2 : Point aMousePos( rPosPixel );
1498 :
1499 : // Logical units ...
1500 2 : aMousePos = GetWindow()->PixelToLogic( aMousePos );
1501 :
1502 2 : if ( ( !GetOutputArea().IsInside( aMousePos ) ) && !pEditEngine->pImpEditEngine->IsInSelectionMode() )
1503 : {
1504 0 : return false;
1505 : }
1506 :
1507 2 : Point aDocPos( GetDocPos( aMousePos ) );
1508 2 : EditPaM aPaM = pEditEngine->GetPaM(aDocPos, false);
1509 2 : return IsInSelection( aPaM );
1510 : }
1511 :
1512 1 : bool ImpEditView::SetCursorAtPoint( const Point& rPointPixel )
1513 : {
1514 1 : pEditEngine->CheckIdleFormatter();
1515 :
1516 1 : Point aMousePos( rPointPixel );
1517 :
1518 : // Logical units ...
1519 1 : aMousePos = GetWindow()->PixelToLogic( aMousePos );
1520 :
1521 1 : if ( ( !GetOutputArea().IsInside( aMousePos ) ) && !pEditEngine->pImpEditEngine->IsInSelectionMode() )
1522 : {
1523 0 : return false;
1524 : }
1525 :
1526 1 : Point aDocPos( GetDocPos( aMousePos ) );
1527 :
1528 : // Can be optimized: first go through the lines within a paragraph for PAM,
1529 : // then again with the PaM for the Rect, even though the line is already
1530 : // known .... This must not be, though!
1531 1 : EditPaM aPaM = pEditEngine->GetPaM(aDocPos);
1532 1 : bool bGotoCursor = DoAutoScroll();
1533 :
1534 : // aTmpNewSel: Diff between old and new, not the new selection, unless tiled rendering
1535 1 : EditSelection aTmpNewSel( isTiledRendering() ? GetEditSelection().Min() : GetEditSelection().Max(), aPaM );
1536 :
1537 : // #i27299#
1538 : // work on copy of current selection and set new selection, if it has changed.
1539 1 : EditSelection aNewEditSelection( GetEditSelection() );
1540 :
1541 1 : aNewEditSelection.Max() = aPaM;
1542 1 : if (!pEditEngine->GetSelectionEngine().HasAnchor())
1543 : {
1544 1 : if ( aNewEditSelection.Min() != aPaM )
1545 1 : pEditEngine->CursorMoved(aNewEditSelection.Min().GetNode());
1546 1 : aNewEditSelection.Min() = aPaM;
1547 : }
1548 : else
1549 : {
1550 0 : DrawSelection( aTmpNewSel );
1551 : }
1552 :
1553 : // set changed text selection
1554 1 : if ( GetEditSelection() != aNewEditSelection )
1555 : {
1556 1 : SetEditSelection( aNewEditSelection );
1557 : }
1558 :
1559 1 : bool bForceCursor = pDragAndDropInfo == nullptr && !pEditEngine->pImpEditEngine->IsInSelectionMode();
1560 1 : ShowCursor( bGotoCursor, bForceCursor );
1561 1 : return true;
1562 : }
1563 :
1564 :
1565 0 : void ImpEditView::HideDDCursor()
1566 : {
1567 0 : if ( pDragAndDropInfo && pDragAndDropInfo->bVisCursor )
1568 : {
1569 0 : GetWindow()->DrawOutDev( pDragAndDropInfo->aCurSavedCursor.TopLeft(), pDragAndDropInfo->aCurSavedCursor.GetSize(),
1570 0 : Point(0,0), pDragAndDropInfo->aCurSavedCursor.GetSize(),*pDragAndDropInfo->pBackground );
1571 0 : pDragAndDropInfo->bVisCursor = false;
1572 : }
1573 0 : }
1574 :
1575 0 : void ImpEditView::ShowDDCursor( const Rectangle& rRect )
1576 : {
1577 0 : if ( pDragAndDropInfo && !pDragAndDropInfo->bVisCursor )
1578 : {
1579 0 : if ( pOutWin->GetCursor() )
1580 0 : pOutWin->GetCursor()->Hide();
1581 :
1582 0 : Color aOldFillColor = GetWindow()->GetFillColor();
1583 0 : GetWindow()->SetFillColor( Color(4210752) ); // GRAY BRUSH_50, OLDSV, change to DDCursor!
1584 :
1585 : // Save background ...
1586 0 : Rectangle aSaveRect( GetWindow()->LogicToPixel( rRect ) );
1587 : // prefer to save some more ...
1588 0 : aSaveRect.Right() += 1;
1589 0 : aSaveRect.Bottom() += 1;
1590 :
1591 : #ifdef DBG_UTIL
1592 : Size aNewSzPx( aSaveRect.GetSize() );
1593 : #endif
1594 0 : if ( !pDragAndDropInfo->pBackground )
1595 : {
1596 0 : pDragAndDropInfo->pBackground = VclPtr<VirtualDevice>::Create( *GetWindow() );
1597 0 : MapMode aMapMode( GetWindow()->GetMapMode() );
1598 0 : aMapMode.SetOrigin( Point( 0, 0 ) );
1599 0 : pDragAndDropInfo->pBackground->SetMapMode( aMapMode );
1600 :
1601 : }
1602 :
1603 : #ifdef DBG_UTIL
1604 : Size aCurSzPx( pDragAndDropInfo->pBackground->GetOutputSizePixel() );
1605 : if ( ( aCurSzPx.Width() < aNewSzPx.Width() ) ||( aCurSzPx.Height() < aNewSzPx.Height() ) )
1606 : {
1607 : bool bDone = pDragAndDropInfo->pBackground->SetOutputSizePixel( aNewSzPx );
1608 : DBG_ASSERT( bDone, "Virtual Device broken?" );
1609 : }
1610 : #endif
1611 :
1612 0 : aSaveRect = GetWindow()->PixelToLogic( aSaveRect );
1613 :
1614 0 : pDragAndDropInfo->pBackground->DrawOutDev( Point(0,0), aSaveRect.GetSize(),
1615 0 : aSaveRect.TopLeft(), aSaveRect.GetSize(), *GetWindow() );
1616 0 : pDragAndDropInfo->aCurSavedCursor = aSaveRect;
1617 :
1618 : // Draw Cursor...
1619 0 : GetWindow()->DrawRect( rRect );
1620 :
1621 0 : pDragAndDropInfo->bVisCursor = true;
1622 0 : pDragAndDropInfo->aCurCursor = rRect;
1623 :
1624 0 : GetWindow()->SetFillColor( aOldFillColor );
1625 : }
1626 0 : }
1627 :
1628 0 : void ImpEditView::dragGestureRecognized(const ::com::sun::star::datatransfer::dnd::DragGestureEvent& rDGE)
1629 : throw (::com::sun::star::uno::RuntimeException,
1630 : std::exception)
1631 : {
1632 : DBG_ASSERT( !pDragAndDropInfo, "dragGestureRecognized - DragAndDropInfo exist!" );
1633 :
1634 0 : SolarMutexGuard aVclGuard;
1635 :
1636 0 : pDragAndDropInfo = NULL;
1637 :
1638 0 : Point aMousePosPixel( rDGE.DragOriginX, rDGE.DragOriginY );
1639 :
1640 0 : EditSelection aCopySel( GetEditSelection() );
1641 0 : aCopySel.Adjust( pEditEngine->GetEditDoc() );
1642 :
1643 0 : if ( GetEditSelection().HasRange() && bClickedInSelection )
1644 : {
1645 0 : pDragAndDropInfo = new DragAndDropInfo();
1646 : }
1647 : else
1648 : {
1649 : // Field?!
1650 : sal_Int32 nPara;
1651 : sal_Int32 nPos;
1652 0 : Point aMousePos = GetWindow()->PixelToLogic( aMousePosPixel );
1653 0 : const SvxFieldItem* pField = GetField( aMousePos, &nPara, &nPos );
1654 0 : if ( pField )
1655 : {
1656 0 : pDragAndDropInfo = new DragAndDropInfo();
1657 0 : pDragAndDropInfo->pField = pField;
1658 0 : ContentNode* pNode = pEditEngine->GetEditDoc().GetObject( nPara );
1659 0 : aCopySel = EditSelection( EditPaM( pNode, nPos ), EditPaM( pNode, nPos+1 ) );
1660 0 : GetEditSelection() = aCopySel;
1661 0 : DrawSelection();
1662 0 : bool bGotoCursor = DoAutoScroll();
1663 0 : ShowCursor( bGotoCursor, /*bForceCursor=*/false );
1664 : }
1665 0 : else if ( IsBulletArea( aMousePos, &nPara ) )
1666 : {
1667 0 : pDragAndDropInfo = new DragAndDropInfo();
1668 0 : pDragAndDropInfo->bOutlinerMode = true;
1669 0 : EditPaM aStartPaM( pEditEngine->GetEditDoc().GetObject( nPara ), 0 );
1670 0 : EditPaM aEndPaM( aStartPaM );
1671 0 : const SfxInt16Item& rLevel = static_cast<const SfxInt16Item&>(pEditEngine->GetParaAttrib( nPara, EE_PARA_OUTLLEVEL ));
1672 0 : for ( sal_Int32 n = nPara +1; n < pEditEngine->GetEditDoc().Count(); n++ )
1673 : {
1674 0 : const SfxInt16Item& rL = static_cast<const SfxInt16Item&>( pEditEngine->GetParaAttrib( n, EE_PARA_OUTLLEVEL ) );
1675 0 : if ( rL.GetValue() > rLevel.GetValue() )
1676 : {
1677 0 : aEndPaM.SetNode( pEditEngine->GetEditDoc().GetObject( n ) );
1678 : }
1679 : else
1680 : {
1681 0 : break;
1682 : }
1683 : }
1684 0 : aEndPaM.SetIndex( aEndPaM.GetNode()->Len() );
1685 0 : SetEditSelection( EditSelection( aStartPaM, aEndPaM ) );
1686 : }
1687 : }
1688 :
1689 0 : if ( pDragAndDropInfo )
1690 : {
1691 :
1692 0 : pDragAndDropInfo->bStarterOfDD = true;
1693 :
1694 : // Sensitive area to be scrolled.
1695 0 : Size aSz( 5, 0 );
1696 0 : aSz = GetWindow()->PixelToLogic( aSz );
1697 0 : pDragAndDropInfo->nSensibleRange = (sal_uInt16) aSz.Width();
1698 0 : pDragAndDropInfo->nCursorWidth = (sal_uInt16) aSz.Width() / 2;
1699 0 : pDragAndDropInfo->aBeginDragSel = pEditEngine->pImpEditEngine->CreateESel( aCopySel );
1700 :
1701 0 : uno::Reference<datatransfer::XTransferable> xData = pEditEngine->CreateTransferable(aCopySel);
1702 :
1703 0 : sal_Int8 nActions = bReadOnly ? datatransfer::dnd::DNDConstants::ACTION_COPY : datatransfer::dnd::DNDConstants::ACTION_COPY_OR_MOVE;
1704 :
1705 0 : rDGE.DragSource->startDrag( rDGE, nActions, 0 /*cursor*/, 0 /*image*/, xData, mxDnDListener );
1706 : // If Drag&Move in an Engine, thenCopy&Del has to be optional!
1707 0 : GetCursor()->Hide();
1708 :
1709 0 : }
1710 0 : }
1711 :
1712 0 : void ImpEditView::dragDropEnd( const ::com::sun::star::datatransfer::dnd::DragSourceDropEvent& rDSDE )
1713 : throw (::com::sun::star::uno::RuntimeException,
1714 : std::exception)
1715 : {
1716 0 : SolarMutexGuard aVclGuard;
1717 :
1718 : DBG_ASSERT( pDragAndDropInfo, "ImpEditView::dragDropEnd: pDragAndDropInfo is NULL!" );
1719 :
1720 : // #123688# Shouldn't happen, but seems to happen...
1721 0 : if ( pDragAndDropInfo )
1722 : {
1723 0 : if ( !bReadOnly && rDSDE.DropSuccess && !pDragAndDropInfo->bOutlinerMode && ( rDSDE.DropAction & datatransfer::dnd::DNDConstants::ACTION_MOVE ) )
1724 : {
1725 0 : if ( pDragAndDropInfo->bStarterOfDD && pDragAndDropInfo->bDroppedInMe )
1726 : {
1727 : // DropPos: Where was it dropped, irrespective of length.
1728 0 : ESelection aDropPos( pDragAndDropInfo->aDropSel.nStartPara, pDragAndDropInfo->aDropSel.nStartPos, pDragAndDropInfo->aDropSel.nStartPara, pDragAndDropInfo->aDropSel.nStartPos );
1729 0 : ESelection aToBeDelSel = pDragAndDropInfo->aBeginDragSel;
1730 : ESelection aNewSel( pDragAndDropInfo->aDropSel.nEndPara, pDragAndDropInfo->aDropSel.nEndPos,
1731 0 : pDragAndDropInfo->aDropSel.nEndPara, pDragAndDropInfo->aDropSel.nEndPos );
1732 0 : bool bBeforeSelection = aDropPos.IsLess( pDragAndDropInfo->aBeginDragSel );
1733 0 : sal_Int32 nParaDiff = pDragAndDropInfo->aBeginDragSel.nEndPara - pDragAndDropInfo->aBeginDragSel.nStartPara;
1734 0 : if ( bBeforeSelection )
1735 : {
1736 : // Adjust aToBeDelSel.
1737 : DBG_ASSERT( pDragAndDropInfo->aBeginDragSel.nStartPara >= pDragAndDropInfo->aDropSel.nStartPara, "But not before? ");
1738 0 : aToBeDelSel.nStartPara = aToBeDelSel.nStartPara + nParaDiff;
1739 0 : aToBeDelSel.nEndPara = aToBeDelSel.nEndPara + nParaDiff;
1740 : // To correct the character?
1741 0 : if ( aToBeDelSel.nStartPara == pDragAndDropInfo->aDropSel.nEndPara )
1742 : {
1743 : sal_uInt16 nMoreChars;
1744 0 : if ( pDragAndDropInfo->aDropSel.nStartPara == pDragAndDropInfo->aDropSel.nEndPara )
1745 0 : nMoreChars = pDragAndDropInfo->aDropSel.nEndPos - pDragAndDropInfo->aDropSel.nStartPos;
1746 : else
1747 0 : nMoreChars = pDragAndDropInfo->aDropSel.nEndPos;
1748 : aToBeDelSel.nStartPos =
1749 0 : aToBeDelSel.nStartPos + nMoreChars;
1750 0 : if ( aToBeDelSel.nStartPara == aToBeDelSel.nEndPara )
1751 : aToBeDelSel.nEndPos =
1752 0 : aToBeDelSel.nEndPos + nMoreChars;
1753 : }
1754 : }
1755 : else
1756 : {
1757 : // aToBeDelSel is ok, but the selection of the View
1758 : // has to be adapted, if it was deleted before!
1759 : DBG_ASSERT( pDragAndDropInfo->aBeginDragSel.nStartPara <= pDragAndDropInfo->aDropSel.nStartPara, "But not before? ");
1760 0 : aNewSel.nStartPara = aNewSel.nStartPara - nParaDiff;
1761 0 : aNewSel.nEndPara = aNewSel.nEndPara - nParaDiff;
1762 : // To correct the character?
1763 0 : if ( pDragAndDropInfo->aBeginDragSel.nEndPara == pDragAndDropInfo->aDropSel.nStartPara )
1764 : {
1765 : sal_uInt16 nLessChars;
1766 0 : if ( pDragAndDropInfo->aBeginDragSel.nStartPara == pDragAndDropInfo->aBeginDragSel.nEndPara )
1767 0 : nLessChars = pDragAndDropInfo->aBeginDragSel.nEndPos - pDragAndDropInfo->aBeginDragSel.nStartPos;
1768 : else
1769 0 : nLessChars = pDragAndDropInfo->aBeginDragSel.nEndPos;
1770 0 : aNewSel.nStartPos = aNewSel.nStartPos - nLessChars;
1771 0 : if ( aNewSel.nStartPara == aNewSel.nEndPara )
1772 0 : aNewSel.nEndPos = aNewSel.nEndPos - nLessChars;
1773 : }
1774 : }
1775 :
1776 0 : DrawSelection();
1777 0 : EditSelection aDelSel( pEditEngine->pImpEditEngine->CreateSel( aToBeDelSel ) );
1778 : DBG_ASSERT( !aDelSel.DbgIsBuggy( pEditEngine->GetEditDoc() ), "ToBeDel is buggy!" );
1779 0 : pEditEngine->DeleteSelection(aDelSel);
1780 0 : if ( !bBeforeSelection )
1781 : {
1782 : DBG_ASSERT( !pEditEngine->pImpEditEngine->CreateSel( aNewSel ).DbgIsBuggy(pEditEngine->GetEditDoc()), "Bad" );
1783 0 : SetEditSelection( pEditEngine->pImpEditEngine->CreateSel( aNewSel ) );
1784 : }
1785 0 : pEditEngine->pImpEditEngine->FormatAndUpdate( pEditEngine->pImpEditEngine->GetActiveView() );
1786 0 : DrawSelection();
1787 : }
1788 : else
1789 : {
1790 : // other EditEngine ...
1791 0 : if (pEditEngine->HasText()) // #88630# SC is removing the content when switching the task
1792 0 : DeleteSelected();
1793 : }
1794 : }
1795 :
1796 0 : if ( pDragAndDropInfo->bUndoAction )
1797 0 : pEditEngine->pImpEditEngine->UndoActionEnd( EDITUNDO_DRAGANDDROP );
1798 :
1799 0 : HideDDCursor();
1800 0 : ShowCursor( DoAutoScroll(), true );
1801 0 : delete pDragAndDropInfo;
1802 0 : pDragAndDropInfo = NULL;
1803 0 : pEditEngine->GetEndDropHdl().Call(GetEditViewPtr());
1804 0 : }
1805 0 : }
1806 :
1807 0 : void ImpEditView::drop( const ::com::sun::star::datatransfer::dnd::DropTargetDropEvent& rDTDE )
1808 : throw (::com::sun::star::uno::RuntimeException,
1809 : std::exception)
1810 : {
1811 0 : SolarMutexGuard aVclGuard;
1812 :
1813 : DBG_ASSERT( pDragAndDropInfo, "Drop - No Drag&Drop info?!" );
1814 :
1815 0 : if ( pDragAndDropInfo && pDragAndDropInfo->bDragAccepted )
1816 : {
1817 0 : pEditEngine->GetBeginDropHdl().Call(GetEditViewPtr());
1818 0 : bool bChanges = false;
1819 :
1820 0 : HideDDCursor();
1821 :
1822 0 : if ( pDragAndDropInfo->bStarterOfDD )
1823 : {
1824 0 : pEditEngine->pImpEditEngine->UndoActionStart( EDITUNDO_DRAGANDDROP );
1825 0 : pDragAndDropInfo->bUndoAction = true;
1826 : }
1827 :
1828 0 : if ( pDragAndDropInfo->bOutlinerMode )
1829 : {
1830 0 : bChanges = true;
1831 0 : GetEditViewPtr()->MoveParagraphs( Range( pDragAndDropInfo->aBeginDragSel.nStartPara, pDragAndDropInfo->aBeginDragSel.nEndPara ), pDragAndDropInfo->nOutlinerDropDest );
1832 : }
1833 : else
1834 : {
1835 0 : uno::Reference< datatransfer::XTransferable > xDataObj = rDTDE.Transferable;
1836 0 : if ( xDataObj.is() )
1837 : {
1838 0 : bChanges = true;
1839 : // remove Selection ...
1840 0 : DrawSelection();
1841 0 : EditPaM aPaM( pDragAndDropInfo->aDropDest );
1842 :
1843 0 : PasteOrDropInfos aPasteOrDropInfos;
1844 0 : aPasteOrDropInfos.nAction = EE_ACTION_DROP;
1845 0 : aPasteOrDropInfos.nStartPara = pEditEngine->GetEditDoc().GetPos( aPaM.GetNode() );
1846 0 : pEditEngine->HandleBeginPasteOrDrop(aPasteOrDropInfos);
1847 :
1848 : EditSelection aNewSel = pEditEngine->InsertText(
1849 0 : xDataObj, OUString(), aPaM, pEditEngine->GetInternalEditStatus().AllowPasteSpecial());
1850 :
1851 0 : aPasteOrDropInfos.nEndPara = pEditEngine->GetEditDoc().GetPos( aNewSel.Max().GetNode() );
1852 0 : pEditEngine->HandleEndPasteOrDrop(aPasteOrDropInfos);
1853 :
1854 0 : SetEditSelection( aNewSel );
1855 0 : pEditEngine->pImpEditEngine->FormatAndUpdate( pEditEngine->pImpEditEngine->GetActiveView() );
1856 0 : if ( pDragAndDropInfo->bStarterOfDD )
1857 : {
1858 : // Only set if the same engine!
1859 0 : pDragAndDropInfo->aDropSel.nStartPara = pEditEngine->GetEditDoc().GetPos( aPaM.GetNode() );
1860 0 : pDragAndDropInfo->aDropSel.nStartPos = aPaM.GetIndex();
1861 0 : pDragAndDropInfo->aDropSel.nEndPara = pEditEngine->GetEditDoc().GetPos( aNewSel.Max().GetNode() );
1862 0 : pDragAndDropInfo->aDropSel.nEndPos = aNewSel.Max().GetIndex();
1863 0 : pDragAndDropInfo->bDroppedInMe = true;
1864 : }
1865 0 : }
1866 : }
1867 :
1868 0 : if ( bChanges )
1869 : {
1870 0 : rDTDE.Context->acceptDrop( rDTDE.DropAction );
1871 : }
1872 :
1873 0 : if ( !pDragAndDropInfo->bStarterOfDD )
1874 : {
1875 0 : delete pDragAndDropInfo;
1876 0 : pDragAndDropInfo = NULL;
1877 : }
1878 :
1879 0 : rDTDE.Context->dropComplete( bChanges );
1880 0 : }
1881 0 : }
1882 :
1883 0 : void ImpEditView::dragEnter( const ::com::sun::star::datatransfer::dnd::DropTargetDragEnterEvent& rDTDEE ) throw (::com::sun::star::uno::RuntimeException, std::exception)
1884 : {
1885 0 : SolarMutexGuard aVclGuard;
1886 :
1887 0 : if ( !pDragAndDropInfo )
1888 0 : pDragAndDropInfo = new DragAndDropInfo( );
1889 :
1890 0 : pDragAndDropInfo->bHasValidData = false;
1891 :
1892 : // Check for supported format...
1893 : // Only check for text, will also be there if bin or rtf
1894 0 : datatransfer::DataFlavor aTextFlavor;
1895 0 : SotExchange::GetFormatDataFlavor( SotClipboardFormatId::STRING, aTextFlavor );
1896 0 : const ::com::sun::star::datatransfer::DataFlavor* pFlavors = rDTDEE.SupportedDataFlavors.getConstArray();
1897 0 : int nFlavors = rDTDEE.SupportedDataFlavors.getLength();
1898 0 : for ( int n = 0; n < nFlavors; n++ )
1899 : {
1900 0 : if( TransferableDataHelper::IsEqual( pFlavors[n], aTextFlavor ) )
1901 : {
1902 0 : pDragAndDropInfo->bHasValidData = true;
1903 0 : break;
1904 : }
1905 : }
1906 :
1907 0 : dragOver( rDTDEE );
1908 0 : }
1909 :
1910 0 : void ImpEditView::dragExit( const ::com::sun::star::datatransfer::dnd::DropTargetEvent& ) throw (::com::sun::star::uno::RuntimeException, std::exception)
1911 : {
1912 0 : SolarMutexGuard aVclGuard;
1913 :
1914 0 : HideDDCursor();
1915 :
1916 0 : if ( pDragAndDropInfo && !pDragAndDropInfo->bStarterOfDD )
1917 : {
1918 0 : delete pDragAndDropInfo;
1919 0 : pDragAndDropInfo = NULL;
1920 0 : }
1921 0 : }
1922 :
1923 0 : void ImpEditView::dragOver(const ::com::sun::star::datatransfer::dnd::DropTargetDragEvent& rDTDE)
1924 : throw (::com::sun::star::uno::RuntimeException,
1925 : std::exception)
1926 : {
1927 0 : SolarMutexGuard aVclGuard;
1928 :
1929 0 : Point aMousePos( rDTDE.LocationX, rDTDE.LocationY );
1930 0 : aMousePos = GetWindow()->PixelToLogic( aMousePos );
1931 :
1932 0 : bool bAccept = false;
1933 :
1934 0 : if ( GetOutputArea().IsInside( aMousePos ) && !bReadOnly )
1935 : {
1936 0 : if ( pDragAndDropInfo && pDragAndDropInfo->bHasValidData )
1937 : {
1938 0 : bAccept = true;
1939 :
1940 0 : bool bAllowScroll = DoAutoScroll();
1941 0 : if ( bAllowScroll )
1942 : {
1943 0 : long nScrollX = 0;
1944 0 : long nScrollY = 0;
1945 : // Chech if in the sensitive area
1946 0 : if ( ( (aMousePos.X()-pDragAndDropInfo->nSensibleRange) < GetOutputArea().Left() ) && ( ( aMousePos.X() + pDragAndDropInfo->nSensibleRange ) > GetOutputArea().Left() ) )
1947 0 : nScrollX = GetOutputArea().GetWidth() / SCRLRANGE;
1948 0 : else if ( ( (aMousePos.X()+pDragAndDropInfo->nSensibleRange) > GetOutputArea().Right() ) && ( ( aMousePos.X() - pDragAndDropInfo->nSensibleRange ) < GetOutputArea().Right() ) )
1949 0 : nScrollX = -( GetOutputArea().GetWidth() / SCRLRANGE );
1950 :
1951 0 : if ( ( (aMousePos.Y()-pDragAndDropInfo->nSensibleRange) < GetOutputArea().Top() ) && ( ( aMousePos.Y() + pDragAndDropInfo->nSensibleRange ) > GetOutputArea().Top() ) )
1952 0 : nScrollY = GetOutputArea().GetHeight() / SCRLRANGE;
1953 0 : else if ( ( (aMousePos.Y()+pDragAndDropInfo->nSensibleRange) > GetOutputArea().Bottom() ) && ( ( aMousePos.Y() - pDragAndDropInfo->nSensibleRange ) < GetOutputArea().Bottom() ) )
1954 0 : nScrollY = -( GetOutputArea().GetHeight() / SCRLRANGE );
1955 :
1956 0 : if ( nScrollX || nScrollY )
1957 : {
1958 0 : HideDDCursor();
1959 0 : Scroll( nScrollX, nScrollY, RGCHK_PAPERSZ1 );
1960 : }
1961 : }
1962 :
1963 0 : Point aDocPos( GetDocPos( aMousePos ) );
1964 0 : EditPaM aPaM = pEditEngine->GetPaM( aDocPos );
1965 0 : pDragAndDropInfo->aDropDest = aPaM;
1966 0 : if ( pDragAndDropInfo->bOutlinerMode )
1967 : {
1968 0 : sal_Int32 nPara = pEditEngine->GetEditDoc().GetPos( aPaM.GetNode() );
1969 0 : ParaPortion* pPPortion = pEditEngine->GetParaPortions().SafeGetObject( nPara );
1970 0 : long nDestParaStartY = pEditEngine->GetParaPortions().GetYOffset( pPPortion );
1971 0 : long nRel = aDocPos.Y() - nDestParaStartY;
1972 0 : if ( nRel < ( pPPortion->GetHeight() / 2 ) )
1973 : {
1974 0 : pDragAndDropInfo->nOutlinerDropDest = nPara;
1975 : }
1976 : else
1977 : {
1978 0 : pDragAndDropInfo->nOutlinerDropDest = nPara+1;
1979 : }
1980 :
1981 0 : if( ( pDragAndDropInfo->nOutlinerDropDest >= pDragAndDropInfo->aBeginDragSel.nStartPara ) &&
1982 0 : ( pDragAndDropInfo->nOutlinerDropDest <= (pDragAndDropInfo->aBeginDragSel.nEndPara+1) ) )
1983 : {
1984 0 : bAccept = false;
1985 : }
1986 : }
1987 0 : else if ( HasSelection() )
1988 : {
1989 : // it must not be dropped into a selection
1990 0 : EPaM aP = pEditEngine->pImpEditEngine->CreateEPaM( aPaM );
1991 0 : ESelection aDestSel( aP.nPara, aP.nIndex, aP.nPara, aP.nIndex);
1992 0 : ESelection aCurSel = pEditEngine->pImpEditEngine->CreateESel( GetEditSelection() );
1993 0 : aCurSel.Adjust();
1994 0 : if ( !aDestSel.IsLess( aCurSel ) && !aDestSel.IsGreater( aCurSel ) )
1995 : {
1996 0 : bAccept = false;
1997 : }
1998 : }
1999 0 : if ( bAccept )
2000 : {
2001 0 : Rectangle aEditCursor;
2002 0 : if ( pDragAndDropInfo->bOutlinerMode )
2003 : {
2004 : long nDDYPos;
2005 0 : if ( pDragAndDropInfo->nOutlinerDropDest < pEditEngine->GetEditDoc().Count() )
2006 : {
2007 0 : ParaPortion* pPPortion = pEditEngine->GetParaPortions().SafeGetObject( pDragAndDropInfo->nOutlinerDropDest );
2008 0 : nDDYPos = pEditEngine->GetParaPortions().GetYOffset( pPPortion );
2009 : }
2010 : else
2011 : {
2012 0 : nDDYPos = pEditEngine->pImpEditEngine->GetTextHeight();
2013 : }
2014 0 : Point aStartPos( 0, nDDYPos );
2015 0 : aStartPos = GetWindowPos( aStartPos );
2016 0 : Point aEndPos( GetOutputArea().GetWidth(), nDDYPos );
2017 0 : aEndPos = GetWindowPos( aEndPos );
2018 0 : aEditCursor = GetWindow()->LogicToPixel( Rectangle( aStartPos, aEndPos ) );
2019 0 : if ( !pEditEngine->IsVertical() )
2020 : {
2021 0 : aEditCursor.Top()--;
2022 0 : aEditCursor.Bottom()++;
2023 : }
2024 : else
2025 : {
2026 0 : aEditCursor.Left()--;
2027 0 : aEditCursor.Right()++;
2028 : }
2029 0 : aEditCursor = GetWindow()->PixelToLogic( aEditCursor );
2030 : }
2031 : else
2032 : {
2033 0 : aEditCursor = pEditEngine->pImpEditEngine->PaMtoEditCursor( aPaM );
2034 0 : Point aTopLeft( GetWindowPos( aEditCursor.TopLeft() ) );
2035 0 : aEditCursor.SetPos( aTopLeft );
2036 0 : aEditCursor.Right() = aEditCursor.Left() + pDragAndDropInfo->nCursorWidth;
2037 0 : aEditCursor = GetWindow()->LogicToPixel( aEditCursor );
2038 0 : aEditCursor = GetWindow()->PixelToLogic( aEditCursor );
2039 : }
2040 :
2041 0 : bool bCursorChanged = !pDragAndDropInfo->bVisCursor || ( pDragAndDropInfo->aCurCursor != aEditCursor );
2042 0 : if ( bCursorChanged )
2043 : {
2044 0 : HideDDCursor();
2045 0 : ShowDDCursor(aEditCursor );
2046 : }
2047 0 : pDragAndDropInfo->bDragAccepted = true;
2048 0 : rDTDE.Context->acceptDrag( rDTDE.DropAction );
2049 : }
2050 : }
2051 : }
2052 :
2053 0 : if ( !bAccept )
2054 : {
2055 0 : HideDDCursor();
2056 0 : if (pDragAndDropInfo)
2057 0 : pDragAndDropInfo->bDragAccepted = false;
2058 0 : rDTDE.Context->rejectDrag();
2059 0 : }
2060 0 : }
2061 :
2062 379 : void ImpEditView::AddDragAndDropListeners()
2063 : {
2064 379 : vcl::Window* pWindow = GetWindow();
2065 379 : if ( !bActiveDragAndDropListener && pWindow && pWindow->GetDragGestureRecognizer().is() )
2066 : {
2067 379 : vcl::unohelper::DragAndDropWrapper* pDnDWrapper = new vcl::unohelper::DragAndDropWrapper( this );
2068 379 : mxDnDListener = pDnDWrapper;
2069 :
2070 379 : uno::Reference< datatransfer::dnd::XDragGestureListener> xDGL( mxDnDListener, uno::UNO_QUERY );
2071 379 : pWindow->GetDragGestureRecognizer()->addDragGestureListener( xDGL );
2072 758 : uno::Reference< datatransfer::dnd::XDropTargetListener> xDTL( xDGL, uno::UNO_QUERY );
2073 379 : pWindow->GetDropTarget()->addDropTargetListener( xDTL );
2074 379 : pWindow->GetDropTarget()->setActive( sal_True );
2075 379 : pWindow->GetDropTarget()->setDefaultActions( datatransfer::dnd::DNDConstants::ACTION_COPY_OR_MOVE );
2076 :
2077 758 : bActiveDragAndDropListener = true;
2078 : }
2079 379 : }
2080 :
2081 432 : void ImpEditView::RemoveDragAndDropListeners()
2082 : {
2083 432 : if ( bActiveDragAndDropListener && GetWindow() && GetWindow()->GetDragGestureRecognizer().is() )
2084 : {
2085 294 : uno::Reference< datatransfer::dnd::XDragGestureListener> xDGL( mxDnDListener, uno::UNO_QUERY );
2086 294 : GetWindow()->GetDragGestureRecognizer()->removeDragGestureListener( xDGL );
2087 588 : uno::Reference< datatransfer::dnd::XDropTargetListener> xDTL( xDGL, uno::UNO_QUERY );
2088 294 : GetWindow()->GetDropTarget()->removeDropTargetListener( xDTL );
2089 :
2090 294 : if ( mxDnDListener.is() )
2091 : {
2092 294 : uno::Reference< lang::XEventListener> xEL( mxDnDListener, uno::UNO_QUERY );
2093 294 : xEL->disposing( lang::EventObject() ); // #95154# Empty Source means it's the Client
2094 294 : mxDnDListener.clear();
2095 : }
2096 :
2097 588 : bActiveDragAndDropListener = false;
2098 : }
2099 432 : }
2100 :
2101 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|