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 "hintids.hxx"
21 : #include <editeng/protitem.hxx>
22 : #include <svx/svdpagv.hxx>
23 : #include <svx/fmmodel.hxx>
24 : #include <sot/exchange.hxx>
25 : #include <svx/sdrundomanager.hxx>
26 : #include <editeng/outliner.hxx>
27 : #include <com/sun/star/embed/EmbedMisc.hpp>
28 :
29 : #include "swtypes.hxx"
30 : #include "pagefrm.hxx"
31 : #include "rootfrm.hxx"
32 : #include "cntfrm.hxx"
33 : #include "flyfrm.hxx"
34 : #include "frmfmt.hxx"
35 : #include "dflyobj.hxx"
36 : #include "dcontact.hxx"
37 : #include "textboxhelper.hxx"
38 : #include "frmatr.hxx"
39 : #include "viewsh.hxx"
40 : #include "viewimp.hxx"
41 : #include "dview.hxx"
42 : #include "dpage.hxx"
43 : #include "doc.hxx"
44 : #include "mdiexp.hxx"
45 : #include <ndole.hxx>
46 : #include <fmtanchr.hxx>
47 : #include "shellres.hxx"
48 : #include <IDocumentUndoRedo.hxx>
49 : #include <DocumentSettingManager.hxx>
50 : #include <IDocumentLayoutAccess.hxx>
51 :
52 : #include <com/sun/star/embed/Aspects.hpp>
53 :
54 : #include <vector>
55 :
56 : #include <sortedobjs.hxx>
57 : #include <flyfrms.hxx>
58 : #include <UndoManager.hxx>
59 :
60 : using namespace com::sun::star;
61 :
62 20 : class SwSdrHdl : public SdrHdl
63 : {
64 : public:
65 10 : SwSdrHdl(const Point& rPnt, bool bTopRight ) :
66 10 : SdrHdl( rPnt, bTopRight ? HDL_ANCHOR_TR : HDL_ANCHOR ) {}
67 : virtual bool IsFocusHdl() const SAL_OVERRIDE;
68 : };
69 :
70 10 : bool SwSdrHdl::IsFocusHdl() const
71 : {
72 10 : if( HDL_ANCHOR == eKind || HDL_ANCHOR_TR == eKind )
73 10 : return true;
74 0 : return SdrHdl::IsFocusHdl();
75 : }
76 :
77 0 : static const SwFrm *lcl_FindAnchor( const SdrObject *pObj, bool bAll )
78 : {
79 0 : const SwVirtFlyDrawObj *pVirt = pObj->ISA(SwVirtFlyDrawObj) ?
80 0 : (SwVirtFlyDrawObj*)pObj : 0;
81 0 : if ( pVirt )
82 : {
83 0 : if ( bAll || !pVirt->GetFlyFrm()->IsFlyInCntFrm() )
84 0 : return pVirt->GetFlyFrm()->GetAnchorFrm();
85 : }
86 : else
87 : {
88 0 : const SwDrawContact *pCont = (const SwDrawContact*)GetUserCall(pObj);
89 0 : if ( pCont )
90 0 : return pCont->GetAnchorFrm( pObj );
91 : }
92 0 : return 0;
93 : }
94 :
95 5318 : SwDrawView::SwDrawView( SwViewImp &rI, SdrModel *pMd, OutputDevice *pOutDev) :
96 : FmFormView( (FmFormModel*)pMd, pOutDev ),
97 5318 : rImp( rI )
98 : {
99 5318 : SetPageVisible( false );
100 5318 : SetBordVisible( false );
101 5318 : SetGridVisible( false );
102 5318 : SetHlplVisible( false );
103 5318 : SetGlueVisible( false );
104 5318 : SetFrameDragSingles( true );
105 5318 : SetVirtualObjectBundling( true );
106 5318 : SetSwapAsynchron( true );
107 :
108 5318 : EnableExtendedKeyInputDispatcher( false );
109 5318 : EnableExtendedMouseEventDispatcher( false );
110 5318 : EnableExtendedCommandEventDispatcher( false );
111 :
112 5318 : SetHitTolerancePixel( GetMarkHdlSizePixel()/2 );
113 :
114 5318 : SetPrintPreview( rI.GetShell()->IsPreview() );
115 :
116 : // #i73602# Use default from the configuration
117 5318 : SetBufferedOverlayAllowed(getOptionsDrawinglayer().IsOverlayBuffer_Writer());
118 :
119 : // #i74769#, #i75172# Use default from the configuration
120 5318 : SetBufferedOutputAllowed(getOptionsDrawinglayer().IsPaintBuffer_Writer());
121 5318 : }
122 :
123 : // #i99665#
124 574 : bool SwDrawView::IsAntiAliasing() const
125 : {
126 574 : return getOptionsDrawinglayer().IsAntiAliasing();
127 : }
128 :
129 10 : SdrObject* impLocalHitCorrection(SdrObject* pRetval, const Point& rPnt, sal_uInt16 nTol, const SdrMarkList &rMrkList)
130 : {
131 10 : if(!nTol)
132 : {
133 : // the old method forced back to outer bounds test when nTol == 0, so
134 : // do not try to correct when nTol is not set (used from HelpContent)
135 : }
136 : else
137 : {
138 : // rebuild logic from former SwVirtFlyDrawObj::CheckSdrObjectHit. This is needed since
139 : // the SdrObject-specific CheckHit implementations are now replaced with primitives and
140 : // 'tricks' like in the old implementation (e.g. using a view from a model-data class to
141 : // detect if object is selected) are no longer valid.
142 : // The standard primitive hit-test for SwVirtFlyDrawObj now is the outer bound. The old
143 : // implementation reduced this excluding the inner bound when the object was not selected.
144 10 : SwVirtFlyDrawObj* pSwVirtFlyDrawObj = dynamic_cast< SwVirtFlyDrawObj* >(pRetval);
145 :
146 10 : if(pSwVirtFlyDrawObj)
147 : {
148 10 : if(pSwVirtFlyDrawObj->GetFlyFrm()->Lower() && pSwVirtFlyDrawObj->GetFlyFrm()->Lower()->IsNoTxtFrm())
149 : {
150 : // the old method used IsNoTxtFrm (should be for SW's own OLE and
151 : // graphic's) to accept hit only based on outer bounds; nothing to do
152 : }
153 : else
154 : {
155 : // check if the object is selected in this view
156 0 : const size_t nMarkCount(rMrkList.GetMarkCount());
157 0 : bool bSelected(false);
158 :
159 0 : for(size_t a = 0; !bSelected && a < nMarkCount; ++a)
160 : {
161 0 : if(pSwVirtFlyDrawObj == rMrkList.GetMark(a)->GetMarkedSdrObj())
162 : {
163 0 : bSelected = true;
164 : }
165 : }
166 :
167 0 : if(!bSelected)
168 : {
169 : // when not selected, the object is not hit when hit position is inside
170 : // inner range. Get and shrink inner range
171 0 : basegfx::B2DRange aInnerBound(pSwVirtFlyDrawObj->getInnerBound());
172 :
173 0 : aInnerBound.grow(-1.0 * nTol);
174 :
175 0 : if(aInnerBound.isInside(basegfx::B2DPoint(rPnt.X(), rPnt.Y())))
176 : {
177 : // exclude this hit
178 0 : pRetval = 0;
179 : }
180 : }
181 : }
182 : }
183 : }
184 :
185 10 : return pRetval;
186 : }
187 :
188 5508 : SdrObject* SwDrawView::CheckSingleSdrObjectHit(const Point& rPnt, sal_uInt16 nTol, SdrObject* pObj, SdrPageView* pPV, sal_uLong nOptions, const SetOfByte* pMVisLay) const
189 : {
190 : // call parent
191 5508 : SdrObject* pRetval = FmFormView::CheckSingleSdrObjectHit(rPnt, nTol, pObj, pPV, nOptions, pMVisLay);
192 :
193 5508 : if(pRetval)
194 : {
195 : // overloaded to allow extra handling when picking SwVirtFlyDrawObj's
196 10 : pRetval = impLocalHitCorrection(pRetval, rPnt, nTol, GetMarkedObjectList());
197 : }
198 :
199 5508 : return pRetval;
200 : }
201 :
202 : /// Gets called every time the handles need to be build
203 48364 : void SwDrawView::AddCustomHdl()
204 : {
205 48364 : const SdrMarkList &rMrkList = GetMarkedObjectList();
206 :
207 48364 : if(rMrkList.GetMarkCount() != 1 || !GetUserCall(rMrkList.GetMark( 0 )->GetMarkedSdrObj()))
208 96708 : return;
209 :
210 10 : SdrObject *pObj = rMrkList.GetMark(0)->GetMarkedSdrObj();
211 : // make code robust
212 10 : SwFrmFmt* pFrmFmt( ::FindFrmFmt( pObj ) );
213 10 : if ( !pFrmFmt )
214 : {
215 : OSL_FAIL( "<SwDrawView::AddCustomHdl()> - missing frame format!" );
216 0 : return;
217 : }
218 10 : const SwFmtAnchor &rAnchor = pFrmFmt->GetAnchor();
219 :
220 10 : if (FLY_AS_CHAR == rAnchor.GetAnchorId())
221 0 : return;
222 :
223 : const SwFrm* pAnch;
224 10 : if(0 == (pAnch = CalcAnchor()))
225 0 : return;
226 :
227 10 : Point aPos(aAnchorPoint);
228 :
229 10 : if ( FLY_AT_CHAR == rAnchor.GetAnchorId() )
230 : {
231 : // #i28701# - use last character rectangle saved at object
232 : // in order to avoid a format of the anchor frame
233 0 : SwAnchoredObject* pAnchoredObj = ::GetUserCall( pObj )->GetAnchoredObj( pObj );
234 0 : SwRect aAutoPos = pAnchoredObj->GetLastCharRect();
235 0 : if ( aAutoPos.Height() )
236 : {
237 0 : aPos = aAutoPos.Pos();
238 : }
239 : }
240 :
241 : // add anchor handle:
242 20 : aHdl.AddHdl( new SwSdrHdl( aPos, ( pAnch->IsVertical() && !pAnch->IsVertLR() ) ||
243 20 : pAnch->IsRightToLeft() ) );
244 : }
245 :
246 0 : SdrObject* SwDrawView::GetMaxToTopObj( SdrObject* pObj ) const
247 : {
248 0 : if ( GetUserCall(pObj) )
249 : {
250 0 : const SwFrm *pAnch = ::lcl_FindAnchor( pObj, false );
251 0 : if ( pAnch )
252 : {
253 : //The topmost Obj within the anchor must not be overtaken.
254 0 : const SwFlyFrm *pFly = pAnch->FindFlyFrm();
255 0 : if ( pFly )
256 : {
257 0 : const SwPageFrm *pPage = pFly->FindPageFrm();
258 0 : if ( pPage->GetSortedObjs() )
259 : {
260 0 : size_t nOrdNum = 0;
261 0 : for ( size_t i = 0; i < pPage->GetSortedObjs()->size(); ++i )
262 : {
263 0 : const SdrObject *pO = (*pPage->GetSortedObjs())[i]->GetDrawObj();
264 :
265 0 : if ( pO->GetOrdNumDirect() > nOrdNum )
266 : {
267 0 : const SwFrm *pTmpAnch = ::lcl_FindAnchor( pO, false );
268 0 : if ( pFly->IsAnLower( pTmpAnch ) )
269 : {
270 0 : nOrdNum = pO->GetOrdNumDirect();
271 : }
272 : }
273 : }
274 0 : if ( nOrdNum )
275 : {
276 0 : SdrPage *pTmpPage = GetModel()->GetPage( 0 );
277 0 : ++nOrdNum;
278 0 : if ( nOrdNum < pTmpPage->GetObjCount() )
279 : {
280 0 : return pTmpPage->GetObj( nOrdNum );
281 : }
282 : }
283 : }
284 : }
285 : }
286 : }
287 0 : return 0;
288 : }
289 :
290 0 : SdrObject* SwDrawView::GetMaxToBtmObj(SdrObject* pObj) const
291 : {
292 0 : if ( GetUserCall(pObj) )
293 : {
294 0 : const SwFrm *pAnch = ::lcl_FindAnchor( pObj, false );
295 0 : if ( pAnch )
296 : {
297 : //The Fly of the anchor must not be "flying under".
298 0 : const SwFlyFrm *pFly = pAnch->FindFlyFrm();
299 0 : if ( pFly )
300 : {
301 0 : SdrObject *pRet = (SdrObject*)pFly->GetVirtDrawObj();
302 0 : return pRet != pObj ? pRet : 0;
303 : }
304 : }
305 : }
306 0 : return 0;
307 : }
308 :
309 : /// determine maximal order number for a 'child' object of given 'parent' object
310 0 : sal_uInt32 SwDrawView::_GetMaxChildOrdNum( const SwFlyFrm& _rParentObj,
311 : const SdrObject* _pExclChildObj ) const
312 : {
313 0 : sal_uInt32 nMaxChildOrdNum = _rParentObj.GetDrawObj()->GetOrdNum();
314 :
315 0 : const SdrPage* pDrawPage = _rParentObj.GetDrawObj()->GetPage();
316 : OSL_ENSURE( pDrawPage,
317 : "<SwDrawView::_GetMaxChildOrdNum(..) - missing drawing page at parent object - crash!" );
318 :
319 0 : const size_t nObjCount = pDrawPage->GetObjCount();
320 0 : for ( size_t i = nObjCount-1; i > _rParentObj.GetDrawObj()->GetOrdNum() ; --i )
321 : {
322 0 : const SdrObject* pObj = pDrawPage->GetObj( i );
323 :
324 : // Don't consider 'child' object <_pExclChildObj>
325 0 : if ( pObj == _pExclChildObj )
326 : {
327 0 : continue;
328 : }
329 :
330 0 : if ( pObj->GetOrdNum() > nMaxChildOrdNum &&
331 0 : _rParentObj.IsAnLower( lcl_FindAnchor( pObj, true ) ) )
332 : {
333 0 : nMaxChildOrdNum = pObj->GetOrdNum();
334 0 : break;
335 : }
336 : }
337 :
338 0 : return nMaxChildOrdNum;
339 : }
340 :
341 : /// method to move 'repeated' objects of the given moved object to the according level
342 0 : void SwDrawView::_MoveRepeatedObjs( const SwAnchoredObject& _rMovedAnchoredObj,
343 : const std::vector<SdrObject*>& _rMovedChildObjs ) const
344 : {
345 : // determine 'repeated' objects of already moved object <_rMovedAnchoredObj>
346 0 : std::list<SwAnchoredObject*> aAnchoredObjs;
347 : {
348 0 : const SwContact* pContact = ::GetUserCall( _rMovedAnchoredObj.GetDrawObj() );
349 : OSL_ENSURE( pContact,
350 : "SwDrawView::_MoveRepeatedObjs(..) - missing contact object -> crash." );
351 0 : pContact->GetAnchoredObjs( aAnchoredObjs );
352 : }
353 :
354 : // check, if 'repeated' objects exists.
355 0 : if ( aAnchoredObjs.size() > 1 )
356 : {
357 0 : SdrPage* pDrawPage = GetModel()->GetPage( 0 );
358 :
359 : // move 'repeated' ones to the same order number as the already moved one.
360 0 : const size_t nNewPos = _rMovedAnchoredObj.GetDrawObj()->GetOrdNum();
361 0 : while ( !aAnchoredObjs.empty() )
362 : {
363 0 : SwAnchoredObject* pAnchoredObj = aAnchoredObjs.back();
364 0 : if ( pAnchoredObj != &_rMovedAnchoredObj )
365 : {
366 0 : pDrawPage->SetObjectOrdNum( pAnchoredObj->GetDrawObj()->GetOrdNum(),
367 0 : nNewPos );
368 0 : pDrawPage->RecalcObjOrdNums();
369 : // adjustments for accessibility API
370 0 : if ( pAnchoredObj->ISA(SwFlyFrm) )
371 : {
372 0 : const SwFlyFrm *pTmpFlyFrm = static_cast<SwFlyFrm*>(pAnchoredObj);
373 0 : rImp.DisposeAccessibleFrm( pTmpFlyFrm );
374 0 : rImp.AddAccessibleFrm( pTmpFlyFrm );
375 : }
376 : else
377 : {
378 0 : rImp.DisposeAccessibleObj( pAnchoredObj->GetDrawObj() );
379 0 : rImp.AddAccessibleObj( pAnchoredObj->GetDrawObj() );
380 : }
381 : }
382 0 : aAnchoredObjs.pop_back();
383 : }
384 :
385 : // move 'repeated' ones of 'child' objects
386 0 : for ( std::vector<SdrObject*>::const_iterator aObjIter = _rMovedChildObjs.begin();
387 0 : aObjIter != _rMovedChildObjs.end(); ++aObjIter )
388 : {
389 0 : SdrObject* pChildObj = (*aObjIter);
390 : {
391 0 : const SwContact* pContact = ::GetUserCall( pChildObj );
392 : OSL_ENSURE( pContact,
393 : "SwDrawView::_MoveRepeatedObjs(..) - missing contact object -> crash." );
394 0 : pContact->GetAnchoredObjs( aAnchoredObjs );
395 : }
396 : // move 'repeated' ones to the same order number as the already moved one.
397 0 : const size_t nTmpNewPos = pChildObj->GetOrdNum();
398 0 : while ( !aAnchoredObjs.empty() )
399 : {
400 0 : SwAnchoredObject* pAnchoredObj = aAnchoredObjs.back();
401 0 : if ( pAnchoredObj->GetDrawObj() != pChildObj )
402 : {
403 0 : pDrawPage->SetObjectOrdNum( pAnchoredObj->GetDrawObj()->GetOrdNum(),
404 0 : nTmpNewPos );
405 0 : pDrawPage->RecalcObjOrdNums();
406 : // adjustments for accessibility API
407 0 : if ( pAnchoredObj->ISA(SwFlyFrm) )
408 : {
409 0 : const SwFlyFrm *pTmpFlyFrm = static_cast<SwFlyFrm*>(pAnchoredObj);
410 0 : rImp.DisposeAccessibleFrm( pTmpFlyFrm );
411 0 : rImp.AddAccessibleFrm( pTmpFlyFrm );
412 : }
413 : else
414 : {
415 0 : rImp.DisposeAccessibleObj( pAnchoredObj->GetDrawObj() );
416 0 : rImp.AddAccessibleObj( pAnchoredObj->GetDrawObj() );
417 : }
418 : }
419 0 : aAnchoredObjs.pop_back();
420 : }
421 : }
422 0 : }
423 0 : }
424 :
425 : // --> adjustment and re-factoring of method
426 0 : void SwDrawView::ObjOrderChanged( SdrObject* pObj, sal_uLong nOldPos,
427 : sal_uLong nNewPos )
428 : {
429 : // nothing to do for group members
430 0 : if ( pObj->GetUpGroup() )
431 : {
432 0 : return;
433 : }
434 :
435 : // determine drawing page and assure that the order numbers are correct.
436 0 : SdrPage* pDrawPage = GetModel()->GetPage( 0 );
437 0 : if ( pDrawPage->IsObjOrdNumsDirty() )
438 0 : pDrawPage->RecalcObjOrdNums();
439 0 : const size_t nObjCount = pDrawPage->GetObjCount();
440 :
441 : SwAnchoredObject* pMovedAnchoredObj =
442 0 : ::GetUserCall( pObj )->GetAnchoredObj( pObj );
443 : const SwFlyFrm* pParentAnchoredObj =
444 0 : pMovedAnchoredObj->GetAnchorFrm()->FindFlyFrm();
445 :
446 0 : const bool bMovedForward = nOldPos < nNewPos;
447 :
448 : // assure for a 'child' object, that it doesn't exceed the limits of its 'parent'
449 0 : if ( pParentAnchoredObj )
450 : {
451 0 : if ( bMovedForward )
452 : {
453 : const size_t nMaxChildOrdNumWithoutMoved =
454 0 : _GetMaxChildOrdNum( *pParentAnchoredObj, pMovedAnchoredObj->GetDrawObj() );
455 0 : if ( nNewPos > nMaxChildOrdNumWithoutMoved+1 )
456 : {
457 : // set position to the top of the 'child' object group
458 0 : pDrawPage->SetObjectOrdNum( nNewPos, nMaxChildOrdNumWithoutMoved+1 );
459 0 : nNewPos = nMaxChildOrdNumWithoutMoved+1;
460 : }
461 : }
462 : else
463 : {
464 0 : const size_t nParentOrdNum = pParentAnchoredObj->GetDrawObj()->GetOrdNum();
465 0 : if ( nNewPos < nParentOrdNum )
466 : {
467 : // set position to the bottom of the 'child' object group
468 0 : pDrawPage->SetObjectOrdNum( nNewPos, nParentOrdNum );
469 0 : nNewPos = nParentOrdNum;
470 : }
471 : }
472 0 : if ( pDrawPage->IsObjOrdNumsDirty() )
473 0 : pDrawPage->RecalcObjOrdNums();
474 : }
475 :
476 : // Assure, that object isn't positioned between 'repeated' ones
477 0 : if ( ( bMovedForward && nNewPos < nObjCount - 1 ) ||
478 0 : ( !bMovedForward && nNewPos > 0 ) )
479 : {
480 : const SdrObject* pTmpObj =
481 0 : pDrawPage->GetObj( bMovedForward ? nNewPos - 1 : nNewPos + 1 );
482 0 : if ( pTmpObj )
483 : {
484 0 : size_t nTmpNewPos( nNewPos );
485 0 : if ( bMovedForward )
486 : {
487 : // move before the top 'repeated' object
488 : const sal_uInt32 nTmpMaxOrdNum =
489 0 : ::GetUserCall( pTmpObj )->GetMaxOrdNum();
490 0 : if ( nTmpMaxOrdNum > nNewPos )
491 0 : nTmpNewPos = nTmpMaxOrdNum;
492 : }
493 : else
494 : {
495 : // move behind the bottom 'repeated' object
496 : const sal_uInt32 nTmpMinOrdNum =
497 0 : ::GetUserCall( pTmpObj )->GetMinOrdNum();
498 0 : if ( nTmpMinOrdNum < nNewPos )
499 0 : nTmpNewPos = nTmpMinOrdNum;
500 : }
501 0 : if ( nTmpNewPos != nNewPos )
502 : {
503 0 : pDrawPage->SetObjectOrdNum( nNewPos, nTmpNewPos );
504 0 : nNewPos = nTmpNewPos;
505 0 : pDrawPage->RecalcObjOrdNums();
506 : }
507 : }
508 : }
509 :
510 : // On move forward, assure that object is moved before its own children.
511 : // Only Writer fly frames can have children.
512 0 : if ( pMovedAnchoredObj->ISA(SwFlyFrm) &&
513 0 : bMovedForward && nNewPos < nObjCount - 1 )
514 : {
515 : sal_uInt32 nMaxChildOrdNum =
516 0 : _GetMaxChildOrdNum( *(static_cast<const SwFlyFrm*>(pMovedAnchoredObj)) );
517 0 : if ( nNewPos < nMaxChildOrdNum )
518 : {
519 : // determine position before the object before its top 'child' object
520 0 : const SdrObject* pTmpObj = pDrawPage->GetObj( nMaxChildOrdNum );
521 0 : size_t nTmpNewPos = ::GetUserCall( pTmpObj )->GetMaxOrdNum() + 1;
522 0 : if ( nTmpNewPos >= nObjCount )
523 : {
524 0 : --nTmpNewPos;
525 : }
526 : // assure, that determined position isn't between 'repeated' objects
527 0 : pTmpObj = pDrawPage->GetObj( nTmpNewPos );
528 0 : nTmpNewPos = ::GetUserCall( pTmpObj )->GetMaxOrdNum();
529 : // apply new position
530 0 : pDrawPage->SetObjectOrdNum( nNewPos, nTmpNewPos );
531 0 : nNewPos = nTmpNewPos;
532 0 : pDrawPage->RecalcObjOrdNums();
533 : }
534 : }
535 :
536 : // Assure, that object isn't positioned between nested objects
537 0 : if ( ( bMovedForward && nNewPos < nObjCount - 1 ) ||
538 0 : ( !bMovedForward && nNewPos > 0 ) )
539 : {
540 0 : size_t nTmpNewPos( nNewPos );
541 : const SwFrmFmt* pParentFrmFmt =
542 0 : pParentAnchoredObj ? &(pParentAnchoredObj->GetFrmFmt()) : 0L;
543 0 : const SdrObject* pTmpObj = pDrawPage->GetObj( nNewPos + 1 );
544 0 : while ( pTmpObj )
545 : {
546 : // #i38563# - assure, that anchor frame exists.
547 : // If object is anchored inside a invisible part of the document
548 : // (e.g. page header, whose page style isn't applied, or hidden
549 : // section), no anchor frame exists.
550 0 : const SwFrm* pTmpAnchorFrm = lcl_FindAnchor( pTmpObj, true );
551 : const SwFlyFrm* pTmpParentObj = pTmpAnchorFrm
552 0 : ? pTmpAnchorFrm->FindFlyFrm() : 0L;
553 0 : if ( pTmpParentObj &&
554 0 : &(pTmpParentObj->GetFrmFmt()) != pParentFrmFmt )
555 : {
556 0 : if ( bMovedForward )
557 : {
558 0 : nTmpNewPos = ::GetUserCall( pTmpObj )->GetMaxOrdNum();
559 0 : pTmpObj = pDrawPage->GetObj( nTmpNewPos + 1 );
560 : }
561 : else
562 : {
563 : nTmpNewPos = ::GetUserCall( pTmpParentObj->GetDrawObj() )
564 0 : ->GetMinOrdNum();
565 0 : pTmpObj = pTmpParentObj->GetDrawObj();
566 : }
567 : }
568 : else
569 0 : break;
570 : }
571 0 : if ( nTmpNewPos != nNewPos )
572 : {
573 0 : pDrawPage->SetObjectOrdNum( nNewPos, nTmpNewPos );
574 0 : nNewPos = nTmpNewPos;
575 0 : pDrawPage->RecalcObjOrdNums();
576 : }
577 : }
578 :
579 : // setup collection of moved 'child' objects to move its 'repeated' objects.
580 0 : std::vector< SdrObject* > aMovedChildObjs;
581 :
582 : // move 'children' accordingly
583 0 : if ( pMovedAnchoredObj->ISA(SwFlyFrm) )
584 : {
585 0 : const SwFlyFrm* pFlyFrm = static_cast<SwFlyFrm*>(pMovedAnchoredObj);
586 :
587 : // adjustments for accessibility API
588 0 : rImp.DisposeAccessibleFrm( pFlyFrm );
589 0 : rImp.AddAccessibleFrm( pFlyFrm );
590 :
591 0 : const sal_uInt32 nChildNewPos = bMovedForward ? nNewPos : nNewPos+1;
592 0 : size_t i = bMovedForward ? nOldPos : nObjCount-1;
593 0 : do
594 : {
595 0 : SdrObject* pTmpObj = pDrawPage->GetObj( i );
596 0 : if ( pTmpObj == pObj )
597 0 : break;
598 :
599 : // #i38563# - assure, that anchor frame exists.
600 : // If object is anchored inside a invisible part of the document
601 : // (e.g. page header, whose page style isn't applied, or hidden
602 : // section), no anchor frame exists.
603 0 : const SwFrm* pTmpAnchorFrm = lcl_FindAnchor( pTmpObj, true );
604 : const SwFlyFrm* pTmpParentObj = pTmpAnchorFrm
605 0 : ? pTmpAnchorFrm->FindFlyFrm() : 0L;
606 0 : if ( pTmpParentObj &&
607 0 : ( ( pTmpParentObj == pFlyFrm ) ||
608 0 : ( pFlyFrm->IsUpperOf( *pTmpParentObj ) ) ) )
609 : {
610 : // move child object.,
611 0 : pDrawPage->SetObjectOrdNum( i, nChildNewPos );
612 0 : pDrawPage->RecalcObjOrdNums();
613 : // collect 'child' object
614 0 : aMovedChildObjs.push_back( pTmpObj );
615 : // adjustments for accessibility API
616 0 : if ( pTmpObj->ISA(SwVirtFlyDrawObj) )
617 : {
618 : const SwFlyFrm *pTmpFlyFrm =
619 0 : static_cast<SwVirtFlyDrawObj*>(pTmpObj)->GetFlyFrm();
620 0 : rImp.DisposeAccessibleFrm( pTmpFlyFrm );
621 0 : rImp.AddAccessibleFrm( pTmpFlyFrm );
622 : }
623 : else
624 : {
625 0 : rImp.DisposeAccessibleObj( pTmpObj );
626 0 : rImp.AddAccessibleObj( pTmpObj );
627 : }
628 : }
629 : else
630 : {
631 : // adjust loop counter
632 0 : if ( bMovedForward )
633 0 : ++i;
634 0 : else if ( !bMovedForward && i > 0 )
635 0 : --i;
636 : }
637 :
638 0 : } while ( ( bMovedForward && i < ( nObjCount - aMovedChildObjs.size() ) ) ||
639 0 : ( !bMovedForward && i > ( nNewPos + aMovedChildObjs.size() ) ) );
640 : }
641 : else
642 : {
643 : // adjustments for accessibility API
644 0 : rImp.DisposeAccessibleObj( pObj );
645 0 : rImp.AddAccessibleObj( pObj );
646 : }
647 :
648 0 : _MoveRepeatedObjs( *pMovedAnchoredObj, aMovedChildObjs );
649 : }
650 :
651 0 : bool SwDrawView::TakeDragLimit( SdrDragMode eMode,
652 : Rectangle& rRect ) const
653 : {
654 0 : const SdrMarkList &rMrkList = GetMarkedObjectList();
655 0 : bool bRet = false;
656 0 : if( 1 == rMrkList.GetMarkCount() )
657 : {
658 0 : const SdrObject *pObj = rMrkList.GetMark( 0 )->GetMarkedSdrObj();
659 0 : SwRect aRect;
660 0 : if( ::CalcClipRect( pObj, aRect, eMode == SDRDRAG_MOVE ) )
661 : {
662 0 : rRect = aRect.SVRect();
663 0 : bRet = true;
664 : }
665 : }
666 0 : return bRet;
667 : }
668 :
669 10 : const SwFrm* SwDrawView::CalcAnchor()
670 : {
671 10 : const SdrMarkList &rMrkList = GetMarkedObjectList();
672 10 : if ( rMrkList.GetMarkCount() != 1 )
673 0 : return NULL;
674 :
675 10 : SdrObject* pObj = rMrkList.GetMark( 0 )->GetMarkedSdrObj();
676 :
677 : //Search for paragraph bound objects, otherwise only the
678 : //current anchor. Search only if we currently drag.
679 : const SwFrm* pAnch;
680 10 : Rectangle aMyRect;
681 10 : const bool bFly = pObj->ISA(SwVirtFlyDrawObj);
682 10 : if ( bFly )
683 : {
684 2 : pAnch = ((SwVirtFlyDrawObj*)pObj)->GetFlyFrm()->GetAnchorFrm();
685 2 : aMyRect = ((SwVirtFlyDrawObj*)pObj)->GetFlyFrm()->Frm().SVRect();
686 : }
687 : else
688 : {
689 8 : SwDrawContact *pC = (SwDrawContact*)GetUserCall(pObj);
690 : // determine correct anchor position for 'virtual' drawing objects.
691 : // #i26791#
692 8 : pAnch = pC->GetAnchorFrm( pObj );
693 8 : if( !pAnch )
694 : {
695 0 : pC->ConnectToLayout();
696 : // determine correct anchor position for 'virtual' drawing objects.
697 : // #i26791#
698 0 : pAnch = pC->GetAnchorFrm( pObj );
699 : }
700 8 : aMyRect = pObj->GetSnapRect();
701 : }
702 :
703 10 : const bool bTopRight = pAnch && ( ( pAnch->IsVertical() &&
704 10 : !pAnch->IsVertLR() ) ||
705 20 : pAnch->IsRightToLeft() );
706 10 : const Point aMyPt = bTopRight ? aMyRect.TopRight() : aMyRect.TopLeft();
707 :
708 10 : Point aPt;
709 10 : if ( IsAction() )
710 : {
711 0 : if ( !TakeDragObjAnchorPos( aPt, bTopRight ) )
712 0 : return NULL;
713 : }
714 : else
715 : {
716 10 : Rectangle aRect = pObj->GetSnapRect();
717 10 : aPt = bTopRight ? aRect.TopRight() : aRect.TopLeft();
718 : }
719 :
720 10 : if ( aPt != aMyPt )
721 : {
722 0 : if ( pAnch && pAnch->IsCntntFrm() )
723 : {
724 : // allow drawing objects in header/footer,
725 : // but exclude control objects.
726 0 : bool bBodyOnly = CheckControlLayer( pObj );
727 0 : pAnch = ::FindAnchor( (SwCntntFrm*)pAnch, aPt, bBodyOnly );
728 : }
729 0 : else if ( !bFly )
730 : {
731 0 : const SwRect aRect( aPt.getX(), aPt.getY(), 1, 1 );
732 :
733 0 : SwDrawContact* pContact = (SwDrawContact*)GetUserCall(pObj);
734 0 : if ( pContact->GetAnchorFrm( pObj ) &&
735 0 : pContact->GetAnchorFrm( pObj )->IsPageFrm() )
736 0 : pAnch = pContact->GetPageFrm();
737 : else
738 0 : pAnch = pContact->FindPage( aRect );
739 : }
740 : }
741 10 : if( pAnch && !pAnch->IsProtected() )
742 10 : aAnchorPoint = pAnch->GetFrmAnchorPos( ::HasWrap( pObj ) );
743 : else
744 0 : pAnch = 0;
745 10 : return pAnch;
746 : }
747 :
748 0 : void SwDrawView::ShowDragAnchor()
749 : {
750 0 : SdrHdl* pHdl = aHdl.GetHdl(HDL_ANCHOR);
751 0 : if ( ! pHdl )
752 0 : pHdl = aHdl.GetHdl(HDL_ANCHOR_TR);
753 :
754 0 : if(pHdl)
755 : {
756 0 : CalcAnchor();
757 0 : pHdl->SetPos(aAnchorPoint);
758 : }
759 0 : }
760 :
761 5362 : void SwDrawView::MarkListHasChanged()
762 : {
763 5362 : Imp().GetShell()->DrawSelChanged();
764 5362 : FmFormView::MarkListHasChanged();
765 5362 : }
766 :
767 : // #i7672#
768 2406 : void SwDrawView::ModelHasChanged()
769 : {
770 : // The ModelHasChanged() call in DrawingLayer also updates
771 : // a eventually active text edit view (OutlinerView). This also leads
772 : // to newly setting the background color for that edit view. Thus,
773 : // this method rescues the current background color if a OutlinerView
774 : // exists and re-establishes it then. To be more safe, the OutlinerView
775 : // will be fetched again (maybe textedit has ended).
776 2406 : OutlinerView* pView = GetTextEditOutlinerView();
777 2406 : Color aBackColor;
778 2406 : bool bColorWasSaved(false);
779 :
780 2406 : if(pView)
781 : {
782 0 : aBackColor = pView->GetBackgroundColor();
783 0 : bColorWasSaved = true;
784 : }
785 :
786 : // call parent
787 2406 : FmFormView::ModelHasChanged();
788 :
789 2406 : if(bColorWasSaved)
790 : {
791 0 : pView = GetTextEditOutlinerView();
792 :
793 0 : if(pView)
794 : {
795 0 : pView->SetBackgroundColor(aBackColor);
796 : }
797 : }
798 2406 : }
799 :
800 4 : void SwDrawView::MakeVisible( const Rectangle &rRect, vcl::Window & )
801 : {
802 : OSL_ENSURE( rImp.GetShell()->GetWin(), "MakeVisible, unknown Window");
803 4 : rImp.GetShell()->MakeVisible( SwRect( rRect ) );
804 4 : }
805 :
806 0 : void SwDrawView::CheckPossibilities()
807 : {
808 0 : FmFormView::CheckPossibilities();
809 :
810 : //In addition to the existing flags of the objects themselves,
811 : //which are evaluated by the DrawingEngine, other circumstances
812 : //lead to a protection.
813 : //Objects that are anchored in frames need to be protected
814 : //if the content of the frame is protected.
815 : //OLE-Objects may themselves wish a resize protection (StarMath)
816 :
817 0 : const SdrMarkList &rMrkList = GetMarkedObjectList();
818 0 : bool bProtect = false;
819 0 : bool bSzProtect = false;
820 0 : for ( size_t i = 0; !bProtect && i < rMrkList.GetMarkCount(); ++i )
821 : {
822 0 : const SdrObject *pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
823 0 : const SwFrm *pFrm = NULL;
824 0 : if ( pObj->ISA(SwVirtFlyDrawObj) )
825 : {
826 0 : const SwFlyFrm *pFly = ((SwVirtFlyDrawObj*)pObj)->GetFlyFrm();
827 0 : if ( pFly )
828 : {
829 0 : pFrm = pFly->GetAnchorFrm();
830 0 : if ( pFly->Lower() && pFly->Lower()->IsNoTxtFrm() )
831 : {
832 0 : SwOLENode *pNd = ((SwCntntFrm*)pFly->Lower())->GetNode()->GetOLENode();
833 0 : if ( pNd )
834 : {
835 0 : uno::Reference < embed::XEmbeddedObject > xObj = pNd->GetOLEObj().GetOleRef();
836 0 : if ( xObj.is() )
837 : {
838 : // --> improvement for the future, when more
839 : // than one Writer fly frame can be selected.
840 :
841 : // TODO/LATER: retrieve Aspect - from where?!
842 0 : bSzProtect |= ( embed::EmbedMisc::EMBED_NEVERRESIZE & xObj->getStatus( embed::Aspects::MSOLE_CONTENT ) ) != 0;
843 :
844 : // #i972: protect position if it is a Math object anchored 'as char' and baseline alignment is activated
845 0 : SwDoc* pDoc = Imp().GetShell()->GetDoc();
846 0 : const bool bProtectMathPos = SotExchange::IsMath( xObj->getClassID() )
847 0 : && FLY_AS_CHAR == pFly->GetFmt()->GetAnchor().GetAnchorId()
848 0 : && pDoc->GetDocumentSettingManager().get( IDocumentSettingAccess::MATH_BASELINE_ALIGNMENT );
849 0 : if (bProtectMathPos)
850 0 : bMoveProtect = true;
851 0 : }
852 : }
853 : }
854 : }
855 : }
856 : else
857 : {
858 0 : SwDrawContact *pC = (SwDrawContact*)GetUserCall(pObj);
859 0 : if ( pC )
860 0 : pFrm = pC->GetAnchorFrm( pObj );
861 : }
862 0 : if ( pFrm )
863 0 : bProtect = pFrm->IsProtected(); //Frames, areas etc.
864 : {
865 0 : SwFrmFmt* pFrmFmt( ::FindFrmFmt( const_cast<SdrObject*>(pObj) ) );
866 0 : if ( !pFrmFmt )
867 : {
868 : OSL_FAIL( "<SwDrawView::CheckPossibilities()> - missing frame format" );
869 0 : bProtect = true;
870 : }
871 0 : else if ((FLY_AS_CHAR == pFrmFmt->GetAnchor().GetAnchorId()) &&
872 0 : rMrkList.GetMarkCount() > 1 )
873 : {
874 0 : bProtect = true;
875 : }
876 : }
877 : }
878 0 : bMoveProtect |= bProtect;
879 0 : bResizeProtect |= bProtect || bSzProtect;
880 0 : }
881 :
882 : /// replace marked <SwDrawVirtObj>-objects by its reference object for delete marked objects.
883 2 : void SwDrawView::ReplaceMarkedDrawVirtObjs( SdrMarkView& _rMarkView )
884 : {
885 2 : SdrPageView* pDrawPageView = _rMarkView.GetSdrPageView();
886 2 : const SdrMarkList& rMarkList = _rMarkView.GetMarkedObjectList();
887 :
888 2 : if( rMarkList.GetMarkCount() )
889 : {
890 : // collect marked objects in a local data structure
891 2 : std::vector<SdrObject*> aMarkedObjs;
892 4 : for( size_t i = 0; i < rMarkList.GetMarkCount(); ++i )
893 : {
894 2 : SdrObject* pMarkedObj = rMarkList.GetMark( i )->GetMarkedSdrObj();
895 2 : aMarkedObjs.push_back( pMarkedObj );
896 : }
897 : // unmark all objects
898 2 : _rMarkView.UnmarkAllObj();
899 : // re-mark objects, but for marked <SwDrawVirtObj>-objects marked its
900 : // reference object.
901 6 : while ( !aMarkedObjs.empty() )
902 : {
903 2 : SdrObject* pMarkObj = aMarkedObjs.back();
904 2 : if ( pMarkObj->ISA(SwDrawVirtObj) )
905 : {
906 0 : SdrObject* pRefObj = &(static_cast<SwDrawVirtObj*>(pMarkObj)->ReferencedObj());
907 0 : if ( !_rMarkView.IsObjMarked( pRefObj ) )
908 : {
909 0 : _rMarkView.MarkObj( pRefObj, pDrawPageView );
910 : }
911 : }
912 : else
913 : {
914 2 : _rMarkView.MarkObj( pMarkObj, pDrawPageView );
915 : }
916 :
917 2 : aMarkedObjs.pop_back();
918 : }
919 : // sort marked list in order to assure consistent state in drawing layer
920 2 : _rMarkView.SortMarkedObjects();
921 : }
922 2 : }
923 :
924 2 : void SwDrawView::DeleteMarked()
925 : {
926 2 : SwDoc* pDoc = Imp().GetShell()->GetDoc();
927 2 : SwRootFrm *pTmpRoot = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
928 2 : if ( pTmpRoot )
929 2 : pTmpRoot->StartAllAction();
930 2 : pDoc->GetIDocumentUndoRedo().StartUndo(UNDO_EMPTY, NULL);
931 : // replace marked <SwDrawVirtObj>-objects by its reference objects.
932 : {
933 2 : SdrPageView* pDrawPageView = rImp.GetPageView();
934 2 : if ( pDrawPageView )
935 : {
936 2 : SdrMarkView* pMarkView = PTR_CAST( SdrMarkView, &(pDrawPageView->GetView()) );
937 2 : if ( pMarkView )
938 : {
939 2 : ReplaceMarkedDrawVirtObjs( *pMarkView );
940 : }
941 : }
942 : }
943 :
944 : // Check what textboxes have to be deleted afterwards.
945 2 : const SdrMarkList& rMarkList = GetMarkedObjectList();
946 2 : std::vector<SwFrmFmt*> aTextBoxesToDelete;
947 4 : for (size_t i = 0; i < rMarkList.GetMarkCount(); ++i)
948 : {
949 2 : SdrObject *pObject = rMarkList.GetMark(i)->GetMarkedSdrObj();
950 2 : SwDrawContact* pDrawContact = static_cast<SwDrawContact*>(GetUserCall(pObject));
951 2 : SwFrmFmt* pFmt = pDrawContact->GetFmt();
952 2 : if (SwFrmFmt* pTextBox = SwTextBoxHelper::findTextBox(pFmt))
953 2 : aTextBoxesToDelete.push_back(pTextBox);
954 : }
955 :
956 2 : if ( pDoc->DeleteSelection( *this ) )
957 : {
958 2 : FmFormView::DeleteMarked();
959 2 : ::FrameNotify( Imp().GetShell(), FLY_DRAG_END );
960 :
961 : // Only delete these now: earlier deletion would clear the mark list as well.
962 4 : for (std::vector<SwFrmFmt*>::iterator i = aTextBoxesToDelete.begin(); i != aTextBoxesToDelete.end(); ++i)
963 2 : pDoc->getIDocumentLayoutAccess().DelLayoutFmt(*i);
964 : }
965 2 : pDoc->GetIDocumentUndoRedo().EndUndo(UNDO_EMPTY, NULL);
966 2 : if( pTmpRoot )
967 2 : pTmpRoot->EndAllAction();
968 2 : }
969 :
970 : // support enhanced text edit for draw objects
971 0 : SdrUndoManager* SwDrawView::getSdrUndoManagerForEnhancedTextEdit() const
972 : {
973 0 : SwDoc* pDoc = Imp().GetShell()->GetDoc();
974 :
975 0 : return pDoc ? dynamic_cast< SdrUndoManager* >(&(pDoc->GetUndoManager())) : 0;
976 270 : }
977 :
978 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|