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
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
|
/* -*- 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 "fupoor.hxx"
#include <svx/svxids.hrc>
#include <svl/aeitem.hxx>
#include <svx/svdpagv.hxx>
#include <svx/svdoole2.hxx>
#include <svx/svdograf.hxx>
#include <vcl/seleng.hxx>
#include <sfx2/app.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/bindings.hxx>
#include <sfx2/request.hxx>
#include <vcl/dialog.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/drawing/XLayer.hpp>
#include <com/sun/star/drawing/XLayerManager.hpp>
#include <com/sun/star/container/XChild.hpp>
#include "FrameView.hxx"
#include "app.hrc"
#include "fusel.hxx"
#include "sdpage.hxx"
#include "drawview.hxx"
#include "DrawViewShell.hxx"
#include "Window.hxx"
#include "drawdoc.hxx"
#include "DrawDocShell.hxx"
#include "zoomlist.hxx"
#include "Client.hxx"
#include "slideshow.hxx"
#include "LayerTabBar.hxx"
#include <sfx2/viewfrm.hxx>
#include <svx/svditer.hxx>
#include <editeng/editeng.hxx>
using namespace ::com::sun::star;
namespace sd {
FuPoor::FuPoor (
ViewShell* pViewSh,
::sd::Window* pWin,
::sd::View* pView,
SdDrawDocument* pDrDoc,
SfxRequest& rReq)
: mpView(pView),
mpViewShell(pViewSh),
mpWindow(pWin),
mpDocSh( pDrDoc->GetDocSh() ),
mpDoc(pDrDoc),
nSlotId( rReq.GetSlot() ),
pDialog(nullptr),
bIsInDragMode(false),
bNoScrollUntilInside (true),
bScrollable (false),
bDelayActive (false),
bFirstMouseMove (false),
// remember MouseButton state
mnCode(0)
{
ReceiveRequest(rReq);
aScrollTimer.SetInvokeHandler( LINK(this, FuPoor, ScrollHdl) );
aScrollTimer.SetTimeout(SELENG_AUTOREPEAT_INTERVAL);
aDragTimer.SetInvokeHandler( LINK(this, FuPoor, DragHdl) );
aDragTimer.SetTimeout(SELENG_DRAGDROP_TIMEOUT);
aDelayToScrollTimer.SetInvokeHandler( LINK(this, FuPoor, DelayHdl) );
aDelayToScrollTimer.SetTimeout(2000);
}
FuPoor::~FuPoor()
{
aDragTimer.Stop();
aScrollTimer.Stop();
aDelayToScrollTimer.Stop();
pDialog.disposeAndClear();
}
void FuPoor::Activate()
{
if (pDialog)
{
pDialog->Show();
}
}
void FuPoor::Deactivate()
{
aDragTimer.Stop();
aScrollTimer.Stop();
aDelayToScrollTimer.Stop ();
bScrollable = bDelayActive = false;
if (pDialog)
{
pDialog->Hide();
}
if (mpWindow && mpWindow->IsMouseCaptured())
mpWindow->ReleaseMouse();
}
void FuPoor::SetWindow(::sd::Window* pWin)
{
mpWindow = pWin;
}
/**
* scroll when approached the border of the window; is called by MouseMove
*/
void FuPoor::ForceScroll(const Point& aPixPos)
{
aScrollTimer.Stop();
if ( !mpView->IsDragHelpLine() && !mpView->IsSetPageOrg() &&
!SlideShow::IsRunning( mpViewShell->GetViewShellBase() ) )
{
Point aPos = mpWindow->OutputToScreenPixel(aPixPos);
const ::tools::Rectangle& rRect = mpViewShell->GetAllWindowRect();
if ( bNoScrollUntilInside )
{
if ( rRect.IsInside(aPos) )
bNoScrollUntilInside = false;
}
else
{
short dx = 0, dy = 0;
if ( aPos.X() <= rRect.Left() ) dx = -1;
if ( aPos.X() >= rRect.Right() ) dx = 1;
if ( aPos.Y() <= rRect.Top() ) dy = -1;
if ( aPos.Y() >= rRect.Bottom() ) dy = 1;
if ( dx != 0 || dy != 0 )
{
if (bScrollable)
{
// scroll action in derived class
mpViewShell->ScrollLines(dx, dy);
aScrollTimer.Start();
}
else if (! bDelayActive) StartDelayToScrollTimer ();
}
}
}
}
/**
* timer handler for window scrolling
*/
IMPL_LINK_NOARG(FuPoor, ScrollHdl, Timer *, void)
{
Point aPnt(mpWindow->GetPointerPosPixel());
// use remembered MouseButton state to create correct
// MouseEvents for this artificial MouseMove.
MouseMove(MouseEvent(aPnt, 1, MouseEventModifiers::NONE, GetMouseButtonCode()));
}
/**
* handle keyboard events
* @returns sal_True if the event was handled, sal_False otherwise
*/
bool FuPoor::KeyInput(const KeyEvent& rKEvt)
{
sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
bool bReturn = false;
bool bSlideShow = SlideShow::IsRunning( mpViewShell->GetViewShellBase() );
switch (nCode)
{
case KEY_RETURN:
{
if(rKEvt.GetKeyCode().IsMod1())
{
if( dynamic_cast< const DrawViewShell *>( mpViewShell ) != nullptr)
{
DrawViewShell* pDrawViewShell =
static_cast<DrawViewShell*>(mpViewShell);
SdPage* pActualPage = pDrawViewShell->GetActualPage();
SdrTextObj* pCandidate = nullptr;
if(pActualPage)
{
SdrObjListIter aIter(*pActualPage, SdrIterMode::DeepNoGroups);
while(aIter.IsMore() && !pCandidate)
{
SdrObject* pObj = aIter.Next();
if(pObj && dynamic_cast< const SdrTextObj *>( pObj ) != nullptr)
{
SdrInventor nInv(pObj->GetObjInventor());
sal_uInt16 nKnd(pObj->GetObjIdentifier());
if(SdrInventor::Default == nInv &&
(OBJ_TITLETEXT == nKnd || OBJ_OUTLINETEXT == nKnd || OBJ_TEXT == nKnd))
{
pCandidate = static_cast<SdrTextObj*>(pObj);
}
}
}
}
if(pCandidate)
{
mpView->UnMarkAll();
mpView->MarkObj(pCandidate, mpView->GetSdrPageView());
mpViewShell->GetViewFrame()->GetDispatcher()->Execute(
SID_ATTR_CHAR, SfxCallMode::ASYNCHRON);
}
else
{
// insert a new page with the same page layout
mpViewShell->GetViewFrame()->GetDispatcher()->Execute(
SID_INSERTPAGE_QUICK, SfxCallMode::ASYNCHRON);
}
// consumed
bReturn = true;
}
}
else
{
// activate OLE object on RETURN for selected object
// activate text edit on RETURN for selected object
const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
if( !mpView->IsTextEdit() && 1 == rMarkList.GetMarkCount() )
{
SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
if( pObj && dynamic_cast< const SdrOle2Obj* >( pObj ) != nullptr && !mpDocSh->IsUIActive() )
{
//HMHmpView->HideMarkHdl();
mpViewShell->ActivateObject( static_cast< SdrOle2Obj* >( pObj ), 0 );
}
else if( pObj && pObj->IsEmptyPresObj() && dynamic_cast< const SdrGrafObj *>( pObj ) != nullptr )
{
mpViewShell->GetViewFrame()->GetDispatcher()->Execute( SID_INSERT_GRAPHIC, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD );
}
else
{
mpViewShell->GetViewFrame()->GetDispatcher()->Execute( SID_ATTR_CHAR, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD );
}
// consumed
bReturn = true;
}
}
}
break;
case KEY_TAB:
{
// handle Mod1 and Mod2 to get travelling running on different systems
if(rKEvt.GetKeyCode().IsMod1() || rKEvt.GetKeyCode().IsMod2())
{
// do something with a selected handle?
const SdrHdlList& rHdlList = mpView->GetHdlList();
bool bForward(!rKEvt.GetKeyCode().IsShift());
const_cast<SdrHdlList&>(rHdlList).TravelFocusHdl(bForward);
// guarantee visibility of focused handle
SdrHdl* pHdl = rHdlList.GetFocusHdl();
if(pHdl)
{
Point aHdlPosition(pHdl->GetPos());
::tools::Rectangle aVisRect(aHdlPosition - Point(100, 100), Size(200, 200));
mpView->MakeVisible(aVisRect, *mpWindow);
}
// consumed
bReturn = true;
}
}
break;
case KEY_ESCAPE:
{
bReturn = FuPoor::cancel();
}
break;
case KEY_ADD:
{
if (!mpView->IsTextEdit() && !bSlideShow && !mpDocSh->IsUIActive())
{
// increase zoom
mpViewShell->SetZoom(mpWindow->GetZoom() * 3 / 2);
if( dynamic_cast< const DrawViewShell *>( mpViewShell ) != nullptr)
static_cast<DrawViewShell*>(mpViewShell)
->SetZoomOnPage(false);
bReturn = true;
}
}
break;
case KEY_SUBTRACT:
{
if (!mpView->IsTextEdit() && !bSlideShow && !mpDocSh->IsUIActive())
{
// decrease zoom
mpViewShell->SetZoom(mpWindow->GetZoom() * 2 / 3);
if( dynamic_cast< const DrawViewShell *>( mpViewShell ) != nullptr)
static_cast<DrawViewShell*>(mpViewShell)
->SetZoomOnPage(false);
bReturn = true;
}
}
break;
case KEY_MULTIPLY:
{
if (!mpView->IsTextEdit() && !bSlideShow)
{
// zoom to page
mpViewShell->GetViewFrame()->GetDispatcher()->
Execute(SID_SIZE_PAGE, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
bReturn = true;
}
}
break;
case KEY_DIVIDE:
{
if (!mpView->IsTextEdit() && !bSlideShow)
{
// zoom to selected objects
mpViewShell->GetViewFrame()->GetDispatcher()->
Execute(SID_SIZE_OPTIMAL, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
bReturn = true;
}
}
break;
case KEY_POINT:
{
ZoomList* pZoomList = mpViewShell->GetZoomList();
if (!mpView->IsTextEdit() && pZoomList->IsNextPossible() && !bSlideShow && !mpDocSh->IsUIActive())
{
// use next ZoomRect
mpViewShell->SetZoomRect(pZoomList->GetNextZoomRect());
bReturn = true;
}
}
break;
case KEY_COMMA:
{
ZoomList* pZoomList = mpViewShell->GetZoomList();
if (!mpView->IsTextEdit() && pZoomList->IsPreviousPossible() && !bSlideShow && !mpDocSh->IsUIActive())
{
// use previous ZoomRect
mpViewShell->SetZoomRect(pZoomList->GetPreviousZoomRect());
bReturn = true;
}
}
break;
case KEY_HOME:
{
if (!mpView->IsTextEdit()
&& dynamic_cast< const DrawViewShell *>( mpViewShell ) != nullptr
&& !bSlideShow)
{
// jump to first page
static_cast<DrawViewShell*>(mpViewShell)->SwitchPage(0);
bReturn = true;
}
}
break;
case KEY_END:
{
if (!mpView->IsTextEdit()
&& dynamic_cast< const DrawViewShell *>( mpViewShell ) != nullptr
&& !bSlideShow)
{
// jump to last page
SdPage* pPage =
static_cast<DrawViewShell*>(mpViewShell)->GetActualPage();
static_cast<DrawViewShell*>(mpViewShell)
->SwitchPage(mpDoc->GetSdPageCount(
pPage->GetPageKind()) - 1);
bReturn = true;
}
}
break;
case KEY_PAGEUP:
{
if( rKEvt.GetKeyCode().IsMod1() && rKEvt.GetKeyCode().IsMod2() )
break;
if( dynamic_cast< const DrawViewShell *>( mpViewShell ) != nullptr && !bSlideShow)
{
// The page-up key switches layers or pages depending on the
// modifier key.
if ( ! rKEvt.GetKeyCode().GetModifier())
{
// With no modifier pressed we move to the previous
// slide.
mpView->SdrEndTextEdit();
// Previous page.
bReturn = true;
SdPage* pPage = static_cast<DrawViewShell*>(mpViewShell)->GetActualPage();
sal_uInt16 nSdPage = (pPage->GetPageNum() - 1) / 2;
if (nSdPage > 0)
{
// Switch the page and send events regarding
// deactivation the old page and activating the new
// one.
TabControl& rPageTabControl =
static_cast<DrawViewShell*>(mpViewShell)
->GetPageTabControl();
if (rPageTabControl.IsReallyShown())
rPageTabControl.SendDeactivatePageEvent ();
static_cast<DrawViewShell*>(mpViewShell)->SwitchPage(nSdPage - 1);
if (rPageTabControl.IsReallyShown())
rPageTabControl.SendActivatePageEvent ();
}
}
else if (rKEvt.GetKeyCode().IsMod1())
{
// With the CONTROL modifier we switch layers.
if (static_cast<DrawViewShell*>(mpViewShell)->IsLayerModeActive())
{
// Moves to the previous layer.
SwitchLayer (-1);
}
}
}
}
break;
case KEY_PAGEDOWN:
{
if( rKEvt.GetKeyCode().IsMod1() && rKEvt.GetKeyCode().IsMod2() )
break;
if(dynamic_cast< const DrawViewShell *>( mpViewShell ) != nullptr && !bSlideShow)
{
// The page-down key switches layers or pages depending on the
// modifier key.
if ( ! rKEvt.GetKeyCode().GetModifier())
{
// With no modifier pressed we move to the next slide.
mpView->SdrEndTextEdit();
// Next page.
bReturn = true;
SdPage* pPage = static_cast<DrawViewShell*>(mpViewShell)->GetActualPage();
sal_uInt16 nSdPage = (pPage->GetPageNum() - 1) / 2;
if (nSdPage < mpDoc->GetSdPageCount(pPage->GetPageKind()) - 1)
{
// Switch the page and send events regarding
// deactivation the old page and activating the new
// one.
TabControl& rPageTabControl =
static_cast<DrawViewShell*>(mpViewShell)->GetPageTabControl();
if (rPageTabControl.IsReallyShown())
rPageTabControl.SendDeactivatePageEvent ();
static_cast<DrawViewShell*>(mpViewShell)->SwitchPage(nSdPage + 1);
if (rPageTabControl.IsReallyShown())
rPageTabControl.SendActivatePageEvent ();
}
}
else if (rKEvt.GetKeyCode().IsMod1())
{
// With the CONTROL modifier we switch layers.
if (static_cast<DrawViewShell*>(mpViewShell)->IsLayerModeActive())
{
// With the layer mode active pressing page-down
// moves to the next layer.
SwitchLayer (+1);
}
}
}
}
break;
// change select state when focus is on poly point
case KEY_SPACE:
{
const SdrHdlList& rHdlList = mpView->GetHdlList();
SdrHdl* pHdl = rHdlList.GetFocusHdl();
if(pHdl)
{
if(pHdl->GetKind() == SdrHdlKind::Poly)
{
// rescue ID of point with focus
sal_uInt32 nPol(pHdl->GetPolyNum());
sal_uInt32 nPnt(pHdl->GetPointNum());
if(mpView->IsPointMarked(*pHdl))
{
if(rKEvt.GetKeyCode().IsShift())
{
mpView->UnmarkPoint(*pHdl);
}
}
else
{
if(!rKEvt.GetKeyCode().IsShift())
{
mpView->UnmarkAllPoints();
}
mpView->MarkPoint(*pHdl);
}
if(nullptr == rHdlList.GetFocusHdl())
{
// restore point with focus
SdrHdl* pNewOne = nullptr;
for(size_t a = 0; !pNewOne && a < rHdlList.GetHdlCount(); ++a)
{
SdrHdl* pAct = rHdlList.GetHdl(a);
if(pAct
&& pAct->GetKind() == SdrHdlKind::Poly
&& pAct->GetPolyNum() == nPol
&& pAct->GetPointNum() == nPnt)
{
pNewOne = pAct;
}
}
if(pNewOne)
{
const_cast<SdrHdlList&>(rHdlList).SetFocusHdl(pNewOne);
}
}
bReturn = true;
}
}
}
break;
case KEY_UP:
case KEY_DOWN:
case KEY_LEFT:
case KEY_RIGHT:
{
if (!mpView->IsTextEdit() && !bSlideShow)
{
long nX = 0;
long nY = 0;
if (nCode == KEY_UP)
{
// scroll up
nX = 0;
nY =-1;
}
else if (nCode == KEY_DOWN)
{
// scroll down
nX = 0;
nY = 1;
}
else if (nCode == KEY_LEFT)
{
// scroll left
nX =-1;
nY = 0;
}
else if (nCode == KEY_RIGHT)
{
// scroll right
nX = 1;
nY = 0;
}
if (mpView->AreObjectsMarked() && !rKEvt.GetKeyCode().IsMod1() &&
!mpDocSh->IsReadOnly())
{
const SdrHdlList& rHdlList = mpView->GetHdlList();
SdrHdl* pHdl = rHdlList.GetFocusHdl();
bool bIsMoveOfConnectedHandle(false);
bool bOldSuppress = false;
SdrEdgeObj* pEdgeObj = nullptr;
if(pHdl && pHdl->GetObj() && nullptr != dynamic_cast< const SdrEdgeObj *>( pHdl->GetObj() ) && 0 == pHdl->GetPolyNum())
{
pEdgeObj = static_cast<SdrEdgeObj*>(pHdl->GetObj());
if(0L == pHdl->GetPointNum())
{
if(pEdgeObj->GetConnection(true).GetObject())
{
bIsMoveOfConnectedHandle = true;
}
}
if(1L == pHdl->GetPointNum())
{
if(pEdgeObj->GetConnection(false).GetObject())
{
bIsMoveOfConnectedHandle = true;
}
}
}
if(pEdgeObj)
{
// Suppress default connects to inside object and object center
bOldSuppress = pEdgeObj->GetSuppressDefaultConnect();
pEdgeObj->SetSuppressDefaultConnect(true);
}
if(bIsMoveOfConnectedHandle)
{
sal_uInt16 nMarkHdSiz(mpView->GetMarkHdlSizePixel());
Size aHalfConSiz(nMarkHdSiz + 1, nMarkHdSiz + 1);
aHalfConSiz = mpWindow->PixelToLogic(aHalfConSiz);
if(100 < aHalfConSiz.Width())
nX *= aHalfConSiz.Width();
else
nX *= 100;
if(100 < aHalfConSiz.Height())
nY *= aHalfConSiz.Height();
else
nY *= 100;
}
else if(rKEvt.GetKeyCode().IsMod2())
{
// move in 1 pixel distance
Size aLogicSizeOnePixel = mpWindow->PixelToLogic(Size(1,1));
nX *= aLogicSizeOnePixel.Width();
nY *= aLogicSizeOnePixel.Height();
}
else if(rKEvt.GetKeyCode().IsShift())
{
nX *= 1000;
nY *= 1000;
}
else
{
// old, fixed move distance
nX *= 100;
nY *= 100;
}
if(nullptr == pHdl)
{
// only take action when move is allowed
if(mpView->IsMoveAllowed())
{
// restrict movement to WorkArea
const ::tools::Rectangle& rWorkArea = mpView->GetWorkArea();
if(!rWorkArea.IsEmpty())
{
::tools::Rectangle aMarkRect(mpView->GetMarkedObjRect());
aMarkRect.Move(nX, nY);
if(!aMarkRect.IsInside(rWorkArea))
{
if(aMarkRect.Left() < rWorkArea.Left())
{
nX += rWorkArea.Left() - aMarkRect.Left();
}
if(aMarkRect.Right() > rWorkArea.Right())
{
nX -= aMarkRect.Right() - rWorkArea.Right();
}
if(aMarkRect.Top() < rWorkArea.Top())
{
nY += rWorkArea.Top() - aMarkRect.Top();
}
if(aMarkRect.Bottom() > rWorkArea.Bottom())
{
nY -= aMarkRect.Bottom() - rWorkArea.Bottom();
}
}
}
// no handle selected
if(0 != nX || 0 != nY)
{
mpView->MoveAllMarked(Size(nX, nY));
mpView->MakeVisible(mpView->GetAllMarkedRect(), *mpWindow);
}
}
}
else
{
// move handle with index nHandleIndex
if(pHdl && (nX || nY))
{
// now move the Handle (nX, nY)
Point aStartPoint(pHdl->GetPos());
Point aEndPoint(pHdl->GetPos() + Point(nX, nY));
const SdrDragStat& rDragStat = mpView->GetDragStat();
// start dragging
mpView->BegDragObj(aStartPoint, nullptr, pHdl, 0);
if(mpView->IsDragObj())
{
bool bWasNoSnap = rDragStat.IsNoSnap();
bool bWasSnapEnabled = mpView->IsSnapEnabled();
// switch snapping off
if(!bWasNoSnap)
const_cast<SdrDragStat&>(rDragStat).SetNoSnap();
if(bWasSnapEnabled)
mpView->SetSnapEnabled(false);
mpView->MovAction(aEndPoint);
mpView->EndDragObj();
// restore snap
if(!bWasNoSnap)
const_cast<SdrDragStat&>(rDragStat).SetNoSnap(bWasNoSnap);
if(bWasSnapEnabled)
mpView->SetSnapEnabled(bWasSnapEnabled);
}
// make moved handle visible
::tools::Rectangle aVisRect(aEndPoint - Point(100, 100), Size(200, 200));
mpView->MakeVisible(aVisRect, *mpWindow);
}
}
if(pEdgeObj)
{
// Restore original suppress value
pEdgeObj->SetSuppressDefaultConnect(bOldSuppress);
}
}
else
{
// scroll page
mpViewShell->ScrollLines(nX, nY);
}
bReturn = true;
}
}
break;
}
if (bReturn)
{
mpWindow->ReleaseMouse();
}
// when a text-editable object is selected and the
// input character is printable, activate text edit on that object
// and feed character to object
if(!bReturn && !mpDocSh->IsReadOnly())
{
if (!mpView->IsTextEdit())
{
const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
if(1 == rMarkList.GetMarkCount())
{
SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
// #i118485# allow TextInput for OLEs, too
if( dynamic_cast< const SdrTextObj *>( pObj ) != nullptr && pObj->HasTextEdit())
{
// use common IsSimpleCharInput from the EditEngine.
bool bPrintable(EditEngine::IsSimpleCharInput(rKEvt));
if(bPrintable)
{
// try to activate textedit mode for the selected object
SfxStringItem aInputString(SID_ATTR_CHAR, OUString(rKEvt.GetCharCode()));
mpViewShell->GetViewFrame()->GetDispatcher()->ExecuteList(
SID_ATTR_CHAR,
SfxCallMode::ASYNCHRON,
{ &aInputString });
// consumed
bReturn = true;
}
}
}
else
{
// test if there is a title object there. If yes, try to
// set it to edit mode and start typing...
DrawViewShell* pDrawViewShell = dynamic_cast<DrawViewShell*>(mpViewShell);
if (pDrawViewShell && EditEngine::IsSimpleCharInput(rKEvt))
{
SdPage* pActualPage = pDrawViewShell->GetActualPage();
SdrTextObj* pCandidate = nullptr;
if(pActualPage)
{
SdrObjListIter aIter(*pActualPage, SdrIterMode::DeepNoGroups);
while(aIter.IsMore() && !pCandidate)
{
SdrObject* pObj = aIter.Next();
if(pObj && dynamic_cast< const SdrTextObj *>( pObj ) != nullptr)
{
SdrInventor nInv(pObj->GetObjInventor());
sal_uInt16 nKnd(pObj->GetObjIdentifier());
if(SdrInventor::Default == nInv && OBJ_TITLETEXT == nKnd)
{
pCandidate = static_cast<SdrTextObj*>(pObj);
}
}
}
}
// when candidate found and candidate is untouched, start editing text...
if(pCandidate && pCandidate->IsEmptyPresObj())
{
mpView->UnMarkAll();
mpView->MarkObj(pCandidate, mpView->GetSdrPageView());
SfxStringItem aInputString(SID_ATTR_CHAR, OUString(rKEvt.GetCharCode()));
mpViewShell->GetViewFrame()->GetDispatcher()->ExecuteList(
SID_ATTR_CHAR,
SfxCallMode::ASYNCHRON,
{ &aInputString });
// consumed
bReturn = true;
}
}
}
}
}
return bReturn;
}
bool FuPoor::MouseMove(const MouseEvent& )
{
return false;
}
void FuPoor::SelectionHasChanged()
{
const SdrHdlList& rHdlList = mpView->GetHdlList();
const_cast<SdrHdlList&>(rHdlList).ResetFocusHdl();
}
/**
* Cut object to clipboard
*/
void FuPoor::DoCut()
{
if (mpView)
{
mpView->DoCut();
}
}
/**
* Copy object to clipboard
*/
void FuPoor::DoCopy()
{
if (mpView)
{
mpView->DoCopy();
}
}
/**
* Paste object from clipboard
*/
void FuPoor::DoPaste()
{
if (mpView)
{
mpView->DoPaste(mpWindow);
}
}
/**
* Paste unformatted text from clipboard
*/
void FuPoor::DoPasteUnformatted()
{
if (mpView)
{
sal_Int8 nAction = DND_ACTION_COPY;
TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mpViewShell->GetActiveWindow() ) );
if (aDataHelper.GetTransferable().is())
{
mpView->InsertData( aDataHelper,
mpWindow->PixelToLogic( ::tools::Rectangle( Point(), mpWindow->GetOutputSizePixel() ).Center() ),
nAction, false, SotClipboardFormatId::STRING);
}
}
}
/**
* Timer handler for Drag&Drop
*/
IMPL_LINK_NOARG(FuPoor, DragHdl, Timer *, void)
{
if( mpView )
{
sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
SdrHdl* pHdl = mpView->PickHandle(aMDPos);
if ( pHdl==nullptr && mpView->IsMarkedHit(aMDPos, nHitLog)
&& !mpView->IsPresObjSelected(false) )
{
mpWindow->ReleaseMouse();
bIsInDragMode = true;
mpView->StartDrag( aMDPos, mpWindow );
}
}
}
bool FuPoor::Command(const CommandEvent& rCEvt)
{
return mpView->Command(rCEvt,mpWindow);
}
/**
* Timer handler for window scrolling
*/
IMPL_LINK_NOARG(FuPoor, DelayHdl, Timer *, void)
{
aDelayToScrollTimer.Stop ();
bScrollable = true;
Point aPnt(mpWindow->GetPointerPosPixel());
// use remembered MouseButton state to create correct
// MouseEvents for this artificial MouseMove.
MouseMove(MouseEvent(aPnt, 1, MouseEventModifiers::NONE, GetMouseButtonCode()));
}
bool FuPoor::MouseButtonUp (const MouseEvent& rMEvt)
{
// remember button state for creation of own MouseEvents
SetMouseButtonCode(rMEvt.GetButtons());
aDelayToScrollTimer.Stop ();
return bScrollable =
bDelayActive = false;
}
bool FuPoor::MouseButtonDown(const MouseEvent& rMEvt)
{
// remember button state for creation of own MouseEvents
SetMouseButtonCode(rMEvt.GetButtons());
return false;
}
void FuPoor::StartDelayToScrollTimer ()
{
bDelayActive = true;
aDelayToScrollTimer.Start ();
}
bool FuPoor::RequestHelp(const HelpEvent& rHEvt)
{
bool bReturn = false;
SdrPageView* pPV = mpView->GetSdrPageView();
if (pPV)
{
SdPage* pPage = static_cast<SdPage*>( pPV->GetPage() );
if (pPage)
{
bReturn = FmFormPage::RequestHelp(mpWindow, mpView, rHEvt);
}
}
return bReturn;
}
void FuPoor::ReceiveRequest(SfxRequest& /*rReq*/)
{
}
SdrObject* FuPoor::CreateDefaultObject(const sal_uInt16, const ::tools::Rectangle& )
{
// empty base implementation
return nullptr;
}
void FuPoor::ImpForceQuadratic(::tools::Rectangle& rRect)
{
if(rRect.GetWidth() > rRect.GetHeight())
{
rRect = ::tools::Rectangle(
Point(rRect.Left() + ((rRect.GetWidth() - rRect.GetHeight()) / 2), rRect.Top()),
Size(rRect.GetHeight(), rRect.GetHeight()));
}
else
{
rRect = ::tools::Rectangle(
Point(rRect.Left(), rRect.Top() + ((rRect.GetHeight() - rRect.GetWidth()) / 2)),
Size(rRect.GetWidth(), rRect.GetWidth()));
}
}
void FuPoor::SwitchLayer (sal_Int32 nOffset)
{
if(mpViewShell && dynamic_cast< const DrawViewShell *>( mpViewShell ) != nullptr)
{
DrawViewShell* pDrawViewShell =
static_cast<DrawViewShell*>(mpViewShell);
// Calculate the new index.
sal_Int32 nIndex = pDrawViewShell->GetActiveTabLayerIndex() + nOffset;
// Make sure the new index lies inside the range of valid indices.
if (nIndex < 0)
nIndex = 0;
else if (nIndex >= pDrawViewShell->GetTabLayerCount ())
nIndex = pDrawViewShell->GetTabLayerCount() - 1;
// Set the new active layer.
if (nIndex != pDrawViewShell->GetActiveTabLayerIndex ())
{
LayerTabBar* pLayerTabControl =
static_cast<DrawViewShell*>(mpViewShell)->GetLayerTabControl();
if (pLayerTabControl != nullptr)
pLayerTabControl->SendDeactivatePageEvent ();
pDrawViewShell->SetActiveTabLayerIndex (nIndex);
if (pLayerTabControl != nullptr)
pLayerTabControl->SendActivatePageEvent ();
}
}
}
/** is called when the current function should be aborted. <p>
This is used when a function gets a KEY_ESCAPE but can also
be called directly.
@returns true if a active function was aborted
*/
bool FuPoor::cancel()
{
if ( dynamic_cast< const FuSelection *>( this ) == nullptr )
{
mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON);
return true;
}
return false;
}
// #i33136#
bool FuPoor::doConstructOrthogonal() const
{
// Check whether a media object is selected
bool bResizeKeepRatio = false;
// tdf#89758 Avoid interactive crop preview from being proportionally scaled by default.
if (mpView->AreObjectsMarked() && mpView->GetDragMode() != SdrDragMode::Crop)
{
const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
if (rMarkList.GetMarkCount() == 1)
{
sal_uInt16 aObjIdentifier = rMarkList.GetMark(0)->GetMarkedSdrObj()->GetObjIdentifier();
bResizeKeepRatio = aObjIdentifier == OBJ_GRAF ||
aObjIdentifier == OBJ_MEDIA ||
aObjIdentifier == OBJ_OLE2;
}
}
SdrHdl* pHdl = mpView->PickHandle(aMDPos);
// Resize proportionally when media is selected and the user drags on a corner
if (pHdl)
bResizeKeepRatio = bResizeKeepRatio && pHdl->IsCornerHdl();
return (
bResizeKeepRatio ||
SID_DRAW_XLINE == nSlotId ||
SID_DRAW_CIRCLEARC == nSlotId ||
SID_DRAW_SQUARE == nSlotId ||
SID_DRAW_SQUARE_NOFILL == nSlotId ||
SID_DRAW_SQUARE_ROUND == nSlotId ||
SID_DRAW_SQUARE_ROUND_NOFILL == nSlotId ||
SID_DRAW_CIRCLE == nSlotId ||
SID_DRAW_CIRCLE_NOFILL == nSlotId ||
SID_DRAW_CIRCLEPIE == nSlotId ||
SID_DRAW_CIRCLEPIE_NOFILL == nSlotId ||
SID_DRAW_CIRCLECUT == nSlotId ||
SID_DRAW_CIRCLECUT_NOFILL == nSlotId ||
SID_DRAW_XPOLYGON == nSlotId ||
SID_DRAW_XPOLYGON_NOFILL == nSlotId ||
SID_3D_CUBE == nSlotId ||
SID_3D_SPHERE == nSlotId ||
SID_3D_SHELL == nSlotId ||
SID_3D_HALF_SPHERE == nSlotId ||
SID_3D_TORUS == nSlotId ||
SID_3D_CYLINDER == nSlotId ||
SID_3D_CONE == nSlotId ||
SID_3D_PYRAMID == nSlotId);
}
void FuPoor::DoExecute( SfxRequest& )
{
}
} // end of namespace sd
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|