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