1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <tools/debug.hxx>
#include <svx/svddrgv.hxx>
#include <svx/svdview.hxx>
#include <svx/svdundo.hxx>
#include <svx/svdocapt.hxx>
#include <svx/svdpagv.hxx>
#include <svx/svdopath.hxx>
#include <svx/svdoedge.hxx>
#include <svx/strings.hrc>
#include <svx/dialmgr.hxx>
#include "svddrgm1.hxx"
#include <svx/obj3d.hxx>
#include <svx/svdoashp.hxx>
#include <svx/sdrpaintwindow.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <svx/sdr/overlay/overlaymanager.hxx>
#include <svx/sdrpagewindow.hxx>
using namespace sdr;
// DragView
void SdrDragView::ImpClearVars()
{
mbFramDrag=false;
meDragMode=SdrDragMode::Move;
mbDragLimit=false;
mbMarkedHitMovesAlways=false;
meDragHdl=SdrHdlKind::Move;
mpDragHdl=nullptr;
mbDragHdl=false;
mpCurrentSdrDragMethod=nullptr;
mbDragStripes=false;
mbDragWithCopy=false;
mpInsPointUndo=nullptr;
mbInsGluePoint=false;
mbInsObjPointMode=false;
mbInsGluePointMode=false;
mbNoDragXorPolys=false;
mbResizeAtCenter=false;
mbCrookAtCenter=false;
// init using default
mbSolidDragging = getOptionsDrawinglayer().IsSolidDragCreate();
}
SdrDragView::SdrDragView(
SdrModel& rSdrModel,
OutputDevice* pOut)
: SdrExchangeView(rSdrModel, pOut)
{
ImpClearVars();
}
SdrDragView::~SdrDragView()
{
}
bool SdrDragView::IsAction() const
{
return (mpCurrentSdrDragMethod || SdrExchangeView::IsAction());
}
void SdrDragView::MovAction(const Point& rPnt)
{
SdrExchangeView::MovAction(rPnt);
if (mpCurrentSdrDragMethod)
{
MovDragObj(rPnt);
}
}
void SdrDragView::EndAction()
{
if (mpCurrentSdrDragMethod)
{
EndDragObj();
}
SdrExchangeView::EndAction();
}
void SdrDragView::BckAction()
{
SdrExchangeView::BckAction();
BrkDragObj();
}
void SdrDragView::BrkAction()
{
SdrExchangeView::BrkAction();
BrkDragObj();
}
void SdrDragView::TakeActionRect(tools::Rectangle& rRect) const
{
if (mpCurrentSdrDragMethod)
{
rRect=maDragStat.GetActionRect();
if (rRect.IsEmpty())
{
SdrPageView* pPV = GetSdrPageView();
if(pPV&& pPV->HasMarkedObjPageView())
{
// #i95646# is this used..?
const basegfx::B2DRange aBoundRange(mpCurrentSdrDragMethod->getCurrentRange());
if (aBoundRange.isEmpty())
{
rRect.SetEmpty();
}
else
{
rRect = tools::Rectangle(
basegfx::fround(aBoundRange.getMinX()), basegfx::fround(aBoundRange.getMinY()),
basegfx::fround(aBoundRange.getMaxX()), basegfx::fround(aBoundRange.getMaxY()));
}
}
}
if (rRect.IsEmpty())
{
rRect=tools::Rectangle(maDragStat.GetNow(),maDragStat.GetNow());
}
}
else
{
SdrExchangeView::TakeActionRect(rRect);
}
}
bool SdrDragView::TakeDragObjAnchorPos(Point& rPos, bool bTR ) const
{
tools::Rectangle aR;
TakeActionRect(aR);
rPos = bTR ? aR.TopRight() : aR.TopLeft();
if (GetMarkedObjectCount()==1 && IsDragObj() && // only on single selection
!IsDraggingPoints() && !IsDraggingGluePoints() && // not when moving points
dynamic_cast<const SdrDragMovHdl*>( mpCurrentSdrDragMethod.get() ) == nullptr) // not when moving handles
{
SdrObject* pObj=GetMarkedObjectByIndex(0);
if (dynamic_cast<const SdrCaptionObj*>( pObj) != nullptr)
{
Point aPt(static_cast<SdrCaptionObj*>(pObj)->GetTailPos());
bool bTail=meDragHdl==SdrHdlKind::Poly; // drag tail
bool bOwn=dynamic_cast<const SdrDragObjOwn*>( mpCurrentSdrDragMethod.get() ) != nullptr; // specific to object
if (!bTail)
{ // for bTail, TakeActionRect already does the right thing
if (bOwn)
{ // bOwn may be MoveTextFrame, ResizeTextFrame, but may not (any more) be DragTail
rPos=aPt;
}
else
{
// drag the whole Object (Move, Resize, ...)
const basegfx::B2DPoint aTransformed(mpCurrentSdrDragMethod->getCurrentTransformation() * basegfx::B2DPoint(aPt.X(), aPt.Y()));
rPos.setX( basegfx::fround(aTransformed.getX()) );
rPos.setY( basegfx::fround(aTransformed.getY()) );
}
}
}
return true;
}
return false;
}
bool SdrDragView::TakeDragLimit(SdrDragMode /*eMode*/, tools::Rectangle& /*rRect*/) const
{
return false;
}
bool SdrDragView::BegDragObj(const Point& rPnt, OutputDevice* pOut, SdrHdl* pHdl, short nMinMov, SdrDragMethod* _pForcedMeth)
{
BrkAction();
// so we don't leak the object on early return
std::unique_ptr<SdrDragMethod> pForcedMeth(_pForcedMeth);
bool bRet=false;
{
SetDragWithCopy(false);
//TODO: aAni.Reset();
mpCurrentSdrDragMethod=nullptr;
SdrDragMode eTmpMode=meDragMode;
if (eTmpMode==SdrDragMode::Move && pHdl!=nullptr && pHdl->GetKind()!=SdrHdlKind::Move) {
eTmpMode=SdrDragMode::Resize;
}
mbDragLimit=TakeDragLimit(eTmpMode,maDragLimit);
mbFramDrag=ImpIsFrameHandles();
if (!mbFramDrag &&
(mpMarkedObj==nullptr || !mpMarkedObj->hasSpecialDrag()) &&
(pHdl==nullptr || pHdl->GetObj()==nullptr)) {
mbFramDrag=true;
}
Point aPnt(rPnt);
basegfx::B2DVector aGridOffset(0.0, 0.0);
// Coordinate maybe affected by GridOffset, so we may need to
// adapt to Model-coordinates here
if(getPossibleGridOffsetForPosition(
aGridOffset,
basegfx::B2DPoint(aPnt.X(), aPnt.Y()),
GetSdrPageView()))
{
aPnt.AdjustX(basegfx::fround(-aGridOffset.getX()));
aPnt.AdjustY(basegfx::fround(-aGridOffset.getY()));
}
if(pHdl == nullptr
|| pHdl->GetKind() == SdrHdlKind::Move
|| pHdl->GetKind() == SdrHdlKind::MirrorAxis
|| pHdl->GetKind() == SdrHdlKind::Transparence
|| pHdl->GetKind() == SdrHdlKind::Gradient)
{
maDragStat.Reset(aPnt);
}
else
{
maDragStat.Reset(pHdl->GetPos());
}
maDragStat.SetView(static_cast<SdrView*>(this));
maDragStat.SetPageView(mpMarkedPV); // <<-- DragPV has to go here!!!
maDragStat.SetMinMove(ImpGetMinMovLogic(nMinMov,pOut));
maDragStat.SetHdl(pHdl);
maDragStat.NextPoint();
mpDragWin=pOut;
mpDragHdl=pHdl;
meDragHdl= pHdl==nullptr ? SdrHdlKind::Move : pHdl->GetKind();
mbDragHdl=meDragHdl==SdrHdlKind::Ref1 || meDragHdl==SdrHdlKind::Ref2 || meDragHdl==SdrHdlKind::MirrorAxis;
// Expand test for SdrHdlKind::Anchor_TR
bool bNotDraggable = (SdrHdlKind::Anchor == meDragHdl || SdrHdlKind::Anchor_TR == meDragHdl);
if(pHdl && (pHdl->GetKind() == SdrHdlKind::SmartTag) && pForcedMeth )
{
// just use the forced method for smart tags
}
else if(mbDragHdl)
{
mpCurrentSdrDragMethod.reset(new SdrDragMovHdl(*this));
}
else if(!bNotDraggable)
{
switch (meDragMode)
{
case SdrDragMode::Rotate: case SdrDragMode::Shear:
{
switch (meDragHdl)
{
case SdrHdlKind::Left: case SdrHdlKind::Right:
case SdrHdlKind::Upper: case SdrHdlKind::Lower:
{
// are 3D objects selected?
bool b3DObjSelected = false;
for(size_t a=0; !b3DObjSelected && a<GetMarkedObjectCount(); ++a)
{
SdrObject* pObj = GetMarkedObjectByIndex(a);
if(dynamic_cast< const E3dObject* >(pObj))
b3DObjSelected = true;
}
// If yes, allow shear even when !IsShearAllowed,
// because 3D objects are limited rotations
if (!b3DObjSelected && !IsShearAllowed())
return false;
mpCurrentSdrDragMethod.reset(new SdrDragShear(*this,meDragMode==SdrDragMode::Rotate));
} break;
case SdrHdlKind::UpperLeft: case SdrHdlKind::UpperRight:
case SdrHdlKind::LowerLeft: case SdrHdlKind::LowerRight:
{
if (meDragMode==SdrDragMode::Shear)
{
if (!IsDistortAllowed(true) && !IsDistortAllowed()) return false;
mpCurrentSdrDragMethod.reset(new SdrDragDistort(*this));
}
else
{
if (!IsRotateAllowed(true)) return false;
mpCurrentSdrDragMethod.reset(new SdrDragRotate(*this));
}
} break;
default:
{
if (IsMarkedHitMovesAlways() && meDragHdl==SdrHdlKind::Move)
{ // SdrHdlKind::Move is true, even if Obj is hit directly
if (!IsMoveAllowed()) return false;
mpCurrentSdrDragMethod.reset(new SdrDragMove(*this));
}
else
{
if (!IsRotateAllowed(true)) return false;
mpCurrentSdrDragMethod.reset(new SdrDragRotate(*this));
}
}
}
} break;
case SdrDragMode::Mirror:
{
if (meDragHdl==SdrHdlKind::Move && IsMarkedHitMovesAlways())
{
if (!IsMoveAllowed()) return false;
mpCurrentSdrDragMethod.reset(new SdrDragMove(*this));
}
else
{
if (!IsMirrorAllowed(true,true)) return false;
mpCurrentSdrDragMethod.reset(new SdrDragMirror(*this));
}
} break;
case SdrDragMode::Crop:
{
if (meDragHdl==SdrHdlKind::Move && IsMarkedHitMovesAlways())
{
if (!IsMoveAllowed())
return false;
mpCurrentSdrDragMethod.reset(new SdrDragMove(*this));
}
else
{
if (!IsCropAllowed())
return false;
mpCurrentSdrDragMethod.reset(new SdrDragCrop(*this));
}
}
break;
case SdrDragMode::Transparence:
{
if(meDragHdl == SdrHdlKind::Move && IsMarkedHitMovesAlways())
{
if(!IsMoveAllowed())
return false;
mpCurrentSdrDragMethod.reset(new SdrDragMove(*this));
}
else
{
if(!IsTransparenceAllowed())
return false;
mpCurrentSdrDragMethod.reset(new SdrDragGradient(*this, false));
}
break;
}
case SdrDragMode::Gradient:
{
if(meDragHdl == SdrHdlKind::Move && IsMarkedHitMovesAlways())
{
if(!IsMoveAllowed())
return false;
mpCurrentSdrDragMethod.reset(new SdrDragMove(*this));
}
else
{
if(!IsGradientAllowed())
return false;
mpCurrentSdrDragMethod.reset(new SdrDragGradient(*this));
}
break;
}
case SdrDragMode::Crook :
{
if (meDragHdl==SdrHdlKind::Move && IsMarkedHitMovesAlways())
{
if (!IsMoveAllowed()) return false;
mpCurrentSdrDragMethod.reset( new SdrDragMove(*this) );
}
else
{
if (!IsCrookAllowed(true) && !IsCrookAllowed()) return false;
mpCurrentSdrDragMethod.reset( new SdrDragCrook(*this) );
}
} break;
default:
{
// SdrDragMode::Move
if((meDragHdl == SdrHdlKind::Move) && !IsMoveAllowed())
{
return false;
}
else if(meDragHdl == SdrHdlKind::Glue)
{
mpCurrentSdrDragMethod.reset( new SdrDragMove(*this) );
}
else
{
if(mbFramDrag)
{
if(meDragHdl == SdrHdlKind::Move)
{
mpCurrentSdrDragMethod.reset( new SdrDragMove(*this) );
}
else
{
if(!IsResizeAllowed(true))
{
return false;
}
bool bSingleTextObjMark = false; // SJ: #i100490#
if ( GetMarkedObjectCount() == 1 )
{
mpMarkedObj=GetMarkedObjectByIndex(0);
if ( mpMarkedObj &&
dynamic_cast<const SdrTextObj*>( mpMarkedObj) != nullptr &&
static_cast<SdrTextObj*>(mpMarkedObj)->IsTextFrame() )
bSingleTextObjMark = true;
}
if ( bSingleTextObjMark )
mpCurrentSdrDragMethod.reset( new SdrDragObjOwn(*this) );
else
mpCurrentSdrDragMethod.reset( new SdrDragResize(*this) );
}
}
else
{
if(SdrHdlKind::Move == meDragHdl)
{
const bool bCustomShapeSelected(1 == GetMarkedObjectCount() && dynamic_cast<const SdrObjCustomShape*>(GetMarkedObjectByIndex(0)) != nullptr);
if(bCustomShapeSelected)
{
mpCurrentSdrDragMethod.reset( new SdrDragMove( *this ) );
}
}
else if(SdrHdlKind::Poly == meDragHdl)
{
const bool bConnectorSelected(1 == GetMarkedObjectCount() && dynamic_cast<const SdrEdgeObj*>(GetMarkedObjectByIndex(0)) != nullptr);
if(bConnectorSelected)
{
// #i97784#
// fallback to old behaviour for connectors (see
// text in task description for more details)
}
else if(!IsMoveAllowed() || !IsResizeAllowed())
{
// #i77187#
// do not allow move of polygon points if object is move or size protected
return false;
}
}
if(!mpCurrentSdrDragMethod)
{
// fallback to DragSpecial if no interaction defined
mpCurrentSdrDragMethod.reset( new SdrDragObjOwn(*this) );
}
}
}
}
}
}
if (pForcedMeth)
{
mpCurrentSdrDragMethod = std::move(pForcedMeth);
}
maDragStat.SetDragMethod(mpCurrentSdrDragMethod.get());
if (mpCurrentSdrDragMethod)
{
bRet = mpCurrentSdrDragMethod->BeginSdrDrag();
if (!bRet)
{
if (pHdl==nullptr && dynamic_cast< const SdrDragObjOwn* >(mpCurrentSdrDragMethod.get()) != nullptr)
{
// Obj may not Move SpecialDrag, so try with MoveFrameDrag
mpCurrentSdrDragMethod.reset();
if (!IsMoveAllowed())
return false;
mbFramDrag=true;
mpCurrentSdrDragMethod.reset( new SdrDragMove(*this) );
maDragStat.SetDragMethod(mpCurrentSdrDragMethod.get());
bRet = mpCurrentSdrDragMethod->BeginSdrDrag();
}
}
if (!bRet)
{
mpCurrentSdrDragMethod.reset();
maDragStat.SetDragMethod(mpCurrentSdrDragMethod.get());
}
}
}
return bRet;
}
void SdrDragView::MovDragObj(const Point& rPnt)
{
if (mpCurrentSdrDragMethod)
{
Point aPnt(rPnt);
basegfx::B2DVector aGridOffset(0.0, 0.0);
// Coordinate maybe affected by GridOffset, so we may need to
// adapt to Model-coordinates here
if(getPossibleGridOffsetForPosition(
aGridOffset,
basegfx::B2DPoint(aPnt.X(), aPnt.Y()),
GetSdrPageView()))
{
aPnt.AdjustX(basegfx::fround(-aGridOffset.getX()));
aPnt.AdjustY(basegfx::fround(-aGridOffset.getY()));
}
ImpLimitToWorkArea(aPnt);
mpCurrentSdrDragMethod->MoveSdrDrag(aPnt); // this call already makes a Hide()/Show combination
}
}
bool SdrDragView::EndDragObj(bool bCopy)
{
bool bRet(false);
// #i73341# If inserting GluePoint, do not insist on last points being different
if(mpCurrentSdrDragMethod && maDragStat.IsMinMoved() && (IsInsertGluePoint() || maDragStat.GetNow() != maDragStat.GetPrev()))
{
sal_Int32 nSavedHdlCount=0;
if (bEliminatePolyPoints)
{
nSavedHdlCount=GetMarkablePointCount();
}
const bool bUndo = IsUndoEnabled();
if (IsInsertGluePoint() && bUndo)
{
BegUndo(maInsPointUndoStr);
AddUndo(std::unique_ptr<SdrUndoAction>(mpInsPointUndo));
}
bRet = mpCurrentSdrDragMethod->EndSdrDrag(bCopy);
if( IsInsertGluePoint() && bUndo)
EndUndo();
mpCurrentSdrDragMethod.reset();
if (bEliminatePolyPoints)
{
if (nSavedHdlCount!=GetMarkablePointCount())
{
UnmarkAllPoints();
}
}
if (mbInsPolyPoint)
{
SetMarkHandles(nullptr);
mbInsPolyPoint=false;
if( bUndo )
{
BegUndo(maInsPointUndoStr);
AddUndo(std::unique_ptr<SdrUndoAction>(mpInsPointUndo));
EndUndo();
}
}
meDragHdl=SdrHdlKind::Move;
mpDragHdl=nullptr;
if (!mbSomeObjChgdFlag)
{
// Obj did not broadcast (e. g. Writer FlyFrames)
if(!mbDragHdl)
{
AdjustMarkHdl();
}
}
}
else
{
BrkDragObj();
}
mbInsPolyPoint=false;
SetInsertGluePoint(false);
return bRet;
}
void SdrDragView::BrkDragObj()
{
if (mpCurrentSdrDragMethod)
{
mpCurrentSdrDragMethod->CancelSdrDrag();
mpCurrentSdrDragMethod.reset();
if (mbInsPolyPoint)
{
mpInsPointUndo->Undo(); // delete inserted point again
delete mpInsPointUndo;
mpInsPointUndo=nullptr;
SetMarkHandles(nullptr);
mbInsPolyPoint=false;
}
if (IsInsertGluePoint())
{
mpInsPointUndo->Undo(); // delete inserted glue point again
delete mpInsPointUndo;
mpInsPointUndo=nullptr;
SetInsertGluePoint(false);
}
meDragHdl=SdrHdlKind::Move;
mpDragHdl=nullptr;
}
}
bool SdrDragView::IsInsObjPointPossible() const
{
return mpMarkedObj!=nullptr && mpMarkedObj->IsPolyObj();
}
bool SdrDragView::ImpBegInsObjPoint(bool bIdxZwang, const Point& rPnt, bool bNewObj, OutputDevice* pOut)
{
bool bRet(false);
if(auto pMarkedPath = dynamic_cast<SdrPathObj*>( mpMarkedObj))
{
BrkAction();
mpInsPointUndo = dynamic_cast< SdrUndoGeoObj* >( GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*mpMarkedObj).release() );
DBG_ASSERT( mpInsPointUndo, "svx::SdrDragView::BegInsObjPoint(), could not create correct undo object!" );
OUString aStr(SvxResId(STR_DragInsertPoint));
maInsPointUndoStr = aStr.replaceFirst("%1", mpMarkedObj->TakeObjNameSingul() );
Point aPt(rPnt);
if(bNewObj)
aPt = GetSnapPos(aPt,mpMarkedPV);
bool bClosed0 = pMarkedPath->IsClosedObj();
const sal_uInt32 nInsPointNum { bIdxZwang
? pMarkedPath->NbcInsPoint(aPt, bNewObj)
: pMarkedPath->NbcInsPointOld(aPt, bNewObj)
};
if(bClosed0 != pMarkedPath->IsClosedObj())
{
// Obj was closed implicitly
// object changed
pMarkedPath->SetChanged();
pMarkedPath->BroadcastObjectChange();
}
if (nInsPointNum != SAL_MAX_UINT32)
{
mbInsPolyPoint = true;
UnmarkAllPoints();
AdjustMarkHdl();
bRet = BegDragObj(rPnt, pOut, maHdlList.GetHdl(nInsPointNum), 0);
if (bRet)
{
maDragStat.SetMinMoved();
MovDragObj(rPnt);
}
}
else
{
delete mpInsPointUndo;
mpInsPointUndo = nullptr;
}
}
return bRet;
}
bool SdrDragView::EndInsObjPoint(SdrCreateCmd eCmd)
{
if(IsInsObjPoint())
{
Point aPnt(maDragStat.GetNow());
bool bOk=EndDragObj();
if (bOk && eCmd!=SdrCreateCmd::ForceEnd)
{
// Ret=True means: Action is over.
bOk = ! ImpBegInsObjPoint(true, aPnt, eCmd == SdrCreateCmd::NextObject, mpDragWin);
}
return bOk;
} else return false;
}
bool SdrDragView::IsInsGluePointPossible() const
{
bool bRet=false;
if (IsInsGluePointMode() && AreObjectsMarked())
{
if (GetMarkedObjectCount()==1)
{
// return sal_False, if only 1 object which is a connector.
const SdrObject* pObj=GetMarkedObjectByIndex(0);
if (dynamic_cast<const SdrEdgeObj *>(pObj) == nullptr)
{
bRet=true;
}
}
else
{
bRet=true;
}
}
return bRet;
}
bool SdrDragView::BegInsGluePoint(const Point& rPnt)
{
bool bRet=false;
SdrObject* pObj;
SdrPageView* pPV;
if (PickMarkedObj(rPnt,pObj,pPV,SdrSearchOptions::PASS2BOUND))
{
BrkAction();
UnmarkAllGluePoints();
mpInsPointUndo= dynamic_cast< SdrUndoGeoObj* >( GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj).release() );
DBG_ASSERT( mpInsPointUndo, "svx::SdrDragView::BegInsObjPoint(), could not create correct undo object!" );
OUString aStr(SvxResId(STR_DragInsertGluePoint));
maInsPointUndoStr = aStr.replaceFirst("%1", pObj->TakeObjNameSingul() );
SdrGluePointList* pGPL=pObj->ForceGluePointList();
if (pGPL!=nullptr)
{
sal_uInt16 nGlueIdx=pGPL->Insert(SdrGluePoint());
SdrGluePoint& rGP=(*pGPL)[nGlueIdx];
sal_uInt16 nGlueId=rGP.GetId();
rGP.SetAbsolutePos(rPnt,*pObj);
SdrHdl* pHdl=nullptr;
if (MarkGluePoint(pObj,nGlueId,false))
{
pHdl=GetGluePointHdl(pObj,nGlueId);
}
if (pHdl!=nullptr && pHdl->GetKind()==SdrHdlKind::Glue && pHdl->GetObj()==pObj && pHdl->GetObjHdlNum()==nGlueId)
{
SetInsertGluePoint(true);
bRet=BegDragObj(rPnt,nullptr,pHdl,0);
if (bRet)
{
maDragStat.SetMinMoved();
MovDragObj(rPnt);
}
else
{
SetInsertGluePoint(false);
delete mpInsPointUndo;
mpInsPointUndo=nullptr;
}
}
else
{
OSL_FAIL("BegInsGluePoint(): GluePoint handle not found.");
}
}
else
{
// no glue points possible for this object (e. g. Edge)
SetInsertGluePoint(false);
delete mpInsPointUndo;
mpInsPointUndo=nullptr;
}
}
return bRet;
}
void SdrDragView::ShowDragObj()
{
if(mpCurrentSdrDragMethod && !maDragStat.IsShown())
{
// Changed for the GridOffset stuff: No longer iterate over
// SdrPaintWindow(s), but now over SdrPageWindow(s), so doing the
// same as the SdrHdl visualizations (see ::CreateB2dIAObject) do.
// This is needed to get access to an ObjectContact which is needed
// to evtl. process that GridOffset in CreateOverlayGeometry
SdrPageView* pPageView(GetSdrPageView());
if(nullptr != pPageView)
{
for(sal_uInt32 a(0); a < pPageView->PageWindowCount(); a++)
{
const SdrPageWindow& rPageWindow(*pPageView->GetPageWindow(a));
const SdrPaintWindow& rPaintWindow(rPageWindow.GetPaintWindow());
if(rPaintWindow.OutputToWindow())
{
const rtl::Reference<sdr::overlay::OverlayManager>& xOverlayManager(
rPaintWindow.GetOverlayManager());
if(xOverlayManager.is())
{
mpCurrentSdrDragMethod->CreateOverlayGeometry(
*xOverlayManager,
rPageWindow.GetObjectContact());
// #i101679# Force changed overlay to be shown
xOverlayManager->flush();
}
}
}
}
maDragStat.SetShown(true);
}
}
void SdrDragView::HideDragObj()
{
if(mpCurrentSdrDragMethod && maDragStat.IsShown())
{
mpCurrentSdrDragMethod->destroyOverlayGeometry();
maDragStat.SetShown(false);
}
}
void SdrDragView::SetNoDragXorPolys(bool bOn)
{
if (IsNoDragXorPolys()!=bOn)
{
const bool bDragging(mpCurrentSdrDragMethod);
const bool bShown(bDragging && maDragStat.IsShown());
if(bShown)
{
HideDragObj();
}
mbNoDragXorPolys = bOn;
if(bDragging)
{
// force recreation of drag content
mpCurrentSdrDragMethod->resetSdrDragEntries();
}
if(bShown)
{
ShowDragObj();
}
}
}
void SdrDragView::SetDragStripes(bool bOn)
{
if (mpCurrentSdrDragMethod && maDragStat.IsShown())
{
HideDragObj();
mbDragStripes=bOn;
ShowDragObj();
}
else
{
mbDragStripes=bOn;
}
}
bool SdrDragView::IsOrthoDesired() const
{
if( dynamic_cast< const SdrDragObjOwn* >( mpCurrentSdrDragMethod.get() )
|| dynamic_cast< const SdrDragResize* >(mpCurrentSdrDragMethod.get() ))
{
return m_bOrthoDesiredOnMarked;
}
return false;
}
void SdrDragView::SetMarkHandles(SfxViewShell* pOtherShell)
{
if( mpDragHdl )
mpDragHdl = nullptr;
SdrExchangeView::SetMarkHandles(pOtherShell);
}
void SdrDragView::SetSolidDragging(bool bOn)
{
if(mbSolidDragging != bOn)
{
mbSolidDragging = bOn;
}
}
bool SdrDragView::IsSolidDragging() const
{
// allow each user to disable by having a local setting, but using AND for
// checking allowance
return mbSolidDragging && getOptionsDrawinglayer().IsSolidDragCreate();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|