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 | /* -*- 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 <sal/config.h>
#include <algorithm>
#include "PosSizePropertyPanel.hxx"
#include <sal/log.hxx>
#include <svx/svxids.hrc>
#include <sfx2/dispatch.hxx>
#include <sfx2/bindings.hxx>
#include <sfx2/module.hxx>
#include <sfx2/viewsh.hxx>
#include <sfx2/objsh.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/weldutils.hxx>
#include <svx/dialcontrol.hxx>
#include <svx/rectenum.hxx>
#include <unotools/viewoptions.hxx>
#include <unotools/localedatawrapper.hxx>
#include <vcl/canvastools.hxx>
#include <vcl/fieldvalues.hxx>
#include <svl/intitem.hxx>
#include <svx/svdpagv.hxx>
#include <svx/svdview.hxx>
#include <svx/transfrmhelper.hxx>
#include <boost/property_tree/json_parser.hpp>
#include <svtools/unitconv.hxx>
using namespace css;
using namespace css::uno;
const char USERITEM_NAME[] = "FitItem";
namespace svx::sidebar {
PosSizePropertyPanel::PosSizePropertyPanel(
vcl::Window* pParent,
const css::uno::Reference<css::frame::XFrame>& rxFrame,
SfxBindings* pBindings,
const css::uno::Reference<css::ui::XSidebar>& rxSidebar)
: PanelLayout(pParent, "PosSizePropertyPanel", "svx/ui/sidebarpossize.ui", rxFrame),
mxFtPosX(m_xBuilder->weld_label("horizontallabel")),
mxMtrPosX(m_xBuilder->weld_metric_spin_button("horizontalpos", FieldUnit::CM)),
mxFtPosY(m_xBuilder->weld_label("verticallabel")),
mxMtrPosY(m_xBuilder->weld_metric_spin_button("verticalpos", FieldUnit::CM)),
mxFtWidth(m_xBuilder->weld_label("widthlabel")),
mxMtrWidth(m_xBuilder->weld_metric_spin_button("selectwidth", FieldUnit::CM)),
mxFtHeight(m_xBuilder->weld_label("heightlabel")),
mxMtrHeight(m_xBuilder->weld_metric_spin_button("selectheight", FieldUnit::CM)),
mxCbxScale(m_xBuilder->weld_check_button("ratio")),
mxFtAngle(m_xBuilder->weld_label("rotationlabel")),
mxMtrAngle(m_xBuilder->weld_metric_spin_button("rotation", FieldUnit::DEGREE)),
mxCtrlDial(new DialControl),
mxDial(new weld::CustomWeld(*m_xBuilder, "orientationcontrol", *mxCtrlDial)),
mxFtFlip(m_xBuilder->weld_label("fliplabel")),
mxFlipTbx(m_xBuilder->weld_toolbar("selectrotationtype")),
mxFlipDispatch(new ToolbarUnoDispatcher(*mxFlipTbx, *m_xBuilder, rxFrame)),
mxArrangeTbx(m_xBuilder->weld_toolbar("arrangetoolbar")),
mxArrangeDispatch(new ToolbarUnoDispatcher(*mxArrangeTbx, *m_xBuilder, rxFrame)),
mxArrangeTbx2(m_xBuilder->weld_toolbar("arrangetoolbar2")),
mxArrangeDispatch2(new ToolbarUnoDispatcher(*mxArrangeTbx2, *m_xBuilder, rxFrame)),
mxAlignTbx(m_xBuilder->weld_toolbar("aligntoolbar")),
mxAlignDispatch(new ToolbarUnoDispatcher(*mxAlignTbx, *m_xBuilder, rxFrame)),
mxAlignTbx2(m_xBuilder->weld_toolbar("aligntoolbar2")),
mxAlignDispatch2(new ToolbarUnoDispatcher(*mxAlignTbx2, *m_xBuilder, rxFrame)),
mxBtnEditChart(m_xBuilder->weld_button("btnEditChart")),
maRect(),
mpView(nullptr),
mlOldWidth(1),
mlOldHeight(1),
mlRotX(0),
mlRotY(0),
maUIScale(),
mePoolUnit(),
meDlgUnit(FieldUnit::INCH), // #i124409# init with fallback default
maTransfPosXControl(SID_ATTR_TRANSFORM_POS_X, *pBindings, *this),
maTransfPosYControl(SID_ATTR_TRANSFORM_POS_Y, *pBindings, *this),
maTransfWidthControl(SID_ATTR_TRANSFORM_WIDTH, *pBindings, *this),
maTransfHeightControl(SID_ATTR_TRANSFORM_HEIGHT, *pBindings, *this),
maSvxAngleControl( SID_ATTR_TRANSFORM_ANGLE, *pBindings, *this),
maRotXControl(SID_ATTR_TRANSFORM_ROT_X, *pBindings, *this),
maRotYControl(SID_ATTR_TRANSFORM_ROT_Y, *pBindings, *this),
maProPosControl(SID_ATTR_TRANSFORM_PROTECT_POS, *pBindings, *this),
maProSizeControl(SID_ATTR_TRANSFORM_PROTECT_SIZE, *pBindings, *this),
maAutoWidthControl(SID_ATTR_TRANSFORM_AUTOWIDTH, *pBindings, *this),
maAutoHeightControl(SID_ATTR_TRANSFORM_AUTOHEIGHT, *pBindings, *this),
m_aMetricCtl(SID_ATTR_METRIC, *pBindings, *this),
maContext(),
mpBindings(pBindings),
mbSizeProtected(false),
mbPositionProtected(false),
mbAutoWidth(false),
mbAutoHeight(false),
mbAdjustEnabled(false),
mxSidebar(rxSidebar)
{
Initialize();
mpBindings->Update( SID_ATTR_METRIC );
mpBindings->Update( SID_ATTR_TRANSFORM_WIDTH );
mpBindings->Update( SID_ATTR_TRANSFORM_HEIGHT );
mpBindings->Update( SID_ATTR_TRANSFORM_PROTECT_SIZE );
}
PosSizePropertyPanel::~PosSizePropertyPanel()
{
disposeOnce();
}
void PosSizePropertyPanel::dispose()
{
mxFtPosX.reset();
mxMtrPosX.reset();
mxFtPosY.reset();
mxMtrPosY.reset();
mxFtWidth.reset();
mxMtrWidth.reset();
mxFtHeight.reset();
mxMtrHeight.reset();
mxCbxScale.reset();
mxFtAngle.reset();
mxMtrAngle.reset();
mxDial.reset();
mxCtrlDial.reset();
mxFtFlip.reset();
mxFlipDispatch.reset();
mxFlipTbx.reset();
mxAlignDispatch.reset();
mxAlignDispatch2.reset();
mxAlignTbx.reset();
mxAlignTbx2.reset();
mxArrangeDispatch.reset();
mxArrangeDispatch2.reset();
mxArrangeTbx.reset();
mxArrangeTbx2.reset();
mxBtnEditChart.reset();
maTransfPosXControl.dispose();
maTransfPosYControl.dispose();
maTransfWidthControl.dispose();
maTransfHeightControl.dispose();
maSvxAngleControl.dispose();
maRotXControl.dispose();
maRotYControl.dispose();
maProPosControl.dispose();
maProSizeControl.dispose();
maAutoWidthControl.dispose();
maAutoHeightControl.dispose();
m_aMetricCtl.dispose();
PanelLayout::dispose();
}
namespace
{
bool hasText(const SdrView& rSdrView)
{
const SdrMarkList& rMarkList = rSdrView.GetMarkedObjectList();
if(1 == rMarkList.GetMarkCount())
{
const SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
const SdrObjKind eKind(static_cast<SdrObjKind>(pObj->GetObjIdentifier()));
if((pObj->GetObjInventor() == SdrInventor::Default) && (OBJ_TEXT == eKind || OBJ_TITLETEXT == eKind || OBJ_OUTLINETEXT == eKind))
{
const SdrTextObj* pSdrTextObj = dynamic_cast< const SdrTextObj* >(pObj);
if(pSdrTextObj && pSdrTextObj->HasText())
{
return true;
}
}
}
return false;
}
} // end of anonymous namespace
void PosSizePropertyPanel::Initialize()
{
//Position : Horizontal / Vertical
mxMtrPosX->connect_value_changed( LINK( this, PosSizePropertyPanel, ChangePosXHdl ) );
mxMtrPosY->connect_value_changed( LINK( this, PosSizePropertyPanel, ChangePosYHdl ) );
//Size : Width / Height
mxMtrWidth->connect_value_changed( LINK( this, PosSizePropertyPanel, ChangeWidthHdl ) );
mxMtrHeight->connect_value_changed( LINK( this, PosSizePropertyPanel, ChangeHeightHdl ) );
//Size : Keep ratio
mxCbxScale->connect_toggled( LINK( this, PosSizePropertyPanel, ClickAutoHdl ) );
//rotation control
mxCtrlDial->SetLinkedField(mxMtrAngle.get());
mxCtrlDial->SetModifyHdl(LINK( this, PosSizePropertyPanel, RotationHdl));
//use same logic as DialControl_Impl::SetSize
weld::DrawingArea* pDrawingArea = mxCtrlDial->GetDrawingArea();
int nDim = (std::min<int>(pDrawingArea->get_approximate_digit_width() * 6,
pDrawingArea->get_text_height() * 3) - 1) | 1;
Size aSize(nDim, nDim);
pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
mxCtrlDial->Init(aSize);
mxBtnEditChart->connect_clicked( LINK( this, PosSizePropertyPanel, ClickChartEditHdl ) );
SfxViewShell* pCurSh = SfxViewShell::Current();
if ( pCurSh )
mpView = pCurSh->GetDrawView();
else
mpView = nullptr;
if ( mpView != nullptr )
{
maUIScale = mpView->GetModel()->GetUIScale();
mbAdjustEnabled = hasText(*mpView);
}
mePoolUnit = maTransfWidthControl.GetCoreMetric();
}
VclPtr<vcl::Window> PosSizePropertyPanel::Create (
vcl::Window* pParent,
const css::uno::Reference<css::frame::XFrame>& rxFrame,
SfxBindings* pBindings,
const css::uno::Reference<css::ui::XSidebar>& rxSidebar)
{
if (pParent == nullptr)
throw lang::IllegalArgumentException("no parent Window given to PosSizePropertyPanel::Create", nullptr, 0);
if ( ! rxFrame.is())
throw lang::IllegalArgumentException("no XFrame given to PosSizePropertyPanel::Create", nullptr, 1);
if (pBindings == nullptr)
throw lang::IllegalArgumentException("no SfxBindings given to PosSizePropertyPanel::Create", nullptr, 2);
return VclPtr<PosSizePropertyPanel>::Create(
pParent,
rxFrame,
pBindings,
rxSidebar);
}
void PosSizePropertyPanel::DataChanged(
const DataChangedEvent& /*rEvent*/)
{
}
void PosSizePropertyPanel::HandleContextChange(
const vcl::EnumContext& rContext)
{
if (maContext == rContext)
{
// Nothing to do.
return;
}
maContext = rContext;
bool bShowPosition = false;
bool bShowAngle = false;
bool bShowFlip = false;
bool bShowEditChart = false;
bool bShowArrangeTbx2 = false;
switch (maContext.GetCombinedContext_DI())
{
case CombinedEnumContext(Application::WriterVariants, Context::Draw):
bShowAngle = true;
bShowFlip = true;
bShowArrangeTbx2 = true;
break;
case CombinedEnumContext(Application::WriterVariants, Context::Graphic):
bShowFlip = true;
bShowAngle = true; // RotGrfFlyFrame: Writer FlyFrames for Graphics now support angle
break;
case CombinedEnumContext(Application::Calc, Context::Draw):
case CombinedEnumContext(Application::Calc, Context::DrawLine):
case CombinedEnumContext(Application::Calc, Context::Graphic):
case CombinedEnumContext(Application::DrawImpress, Context::Draw):
case CombinedEnumContext(Application::DrawImpress, Context::DrawLine):
case CombinedEnumContext(Application::DrawImpress, Context::TextObject):
case CombinedEnumContext(Application::DrawImpress, Context::Graphic):
bShowPosition = true;
bShowAngle = true;
bShowFlip = true;
break;
case CombinedEnumContext(Application::WriterVariants, Context::OLE):
bShowEditChart = true;
break;
case CombinedEnumContext(Application::Calc, Context::OLE):
case CombinedEnumContext(Application::DrawImpress, Context::OLE):
bShowPosition = true;
bShowEditChart = true;
break;
case CombinedEnumContext(Application::Calc, Context::Chart):
case CombinedEnumContext(Application::Calc, Context::Form):
case CombinedEnumContext(Application::Calc, Context::Media):
case CombinedEnumContext(Application::Calc, Context::MultiObject):
case CombinedEnumContext(Application::DrawImpress, Context::Media):
case CombinedEnumContext(Application::DrawImpress, Context::Form):
case CombinedEnumContext(Application::DrawImpress, Context::ThreeDObject):
case CombinedEnumContext(Application::DrawImpress, Context::MultiObject):
bShowPosition = true;
break;
}
// Position
mxFtPosX->set_visible(bShowPosition);
mxMtrPosX->set_visible(bShowPosition);
mxFtPosY->set_visible(bShowPosition);
mxMtrPosY->set_visible(bShowPosition);
// Rotation
mxFtAngle->set_visible(bShowAngle);
mxMtrAngle->set_visible(bShowAngle);
mxCtrlDial->set_visible(bShowAngle);
// Flip
mxFtFlip->set_visible(bShowFlip);
mxFlipTbx->set_visible(bShowFlip);
// Edit Chart
mxBtnEditChart->set_visible(bShowEditChart);
// Arrange tool bar 2
mxArrangeTbx2->set_visible(bShowArrangeTbx2);
if (mxSidebar.is())
mxSidebar->requestLayout();
}
IMPL_LINK_NOARG( PosSizePropertyPanel, ChangeWidthHdl, weld::MetricSpinButton&, void )<--- syntax error
{
if( mxCbxScale->get_active() &&
mxCbxScale->get_sensitive() )
{
long nHeight = static_cast<long>( (static_cast<double>(mlOldHeight) * static_cast<double>(mxMtrWidth->get_value(FieldUnit::NONE))) / static_cast<double>(mlOldWidth) );
if( nHeight <= mxMtrHeight->get_max( FieldUnit::NONE ) )
{
mxMtrHeight->set_value( nHeight, FieldUnit::NONE );
}
else
{
nHeight = static_cast<long>(mxMtrHeight->get_max( FieldUnit::NONE ));
mxMtrHeight->set_value(nHeight, FieldUnit::NONE);
const long nWidth = static_cast<long>( (static_cast<double>(mlOldWidth) * static_cast<double>(nHeight)) / static_cast<double>(mlOldHeight) );
mxMtrWidth->set_value( nWidth, FieldUnit::NONE );
}
}
executeSize();
}
IMPL_LINK_NOARG( PosSizePropertyPanel, ChangeHeightHdl, weld::MetricSpinButton&, void )
{
if( mxCbxScale->get_active() &&
mxCbxScale->get_sensitive() )
{
long nWidth = static_cast<long>( (static_cast<double>(mlOldWidth) * static_cast<double>(mxMtrHeight->get_value(FieldUnit::NONE))) / static_cast<double>(mlOldHeight) );
if( nWidth <= mxMtrWidth->get_max( FieldUnit::NONE ) )
{
mxMtrWidth->set_value( nWidth, FieldUnit::NONE );
}
else
{
nWidth = static_cast<long>(mxMtrWidth->get_max( FieldUnit::NONE ));
mxMtrWidth->set_value( nWidth, FieldUnit::NONE );
const long nHeight = static_cast<long>( (static_cast<double>(mlOldHeight) * static_cast<double>(nWidth)) / static_cast<double>(mlOldWidth) );
mxMtrHeight->set_value( nHeight, FieldUnit::NONE );
}
}
executeSize();
}
IMPL_LINK_NOARG( PosSizePropertyPanel, ChangePosXHdl, weld::MetricSpinButton&, void )
{
if ( mxMtrPosX->get_value_changed_from_saved())
{
long lX = GetCoreValue( *mxMtrPosX, mePoolUnit );
Fraction aUIScale = mpView->GetModel()->GetUIScale();
lX = long( lX * aUIScale );
SfxInt32Item aPosXItem( SID_ATTR_TRANSFORM_POS_X,static_cast<sal_uInt32>(lX));
GetBindings()->GetDispatcher()->ExecuteList(
SID_ATTR_TRANSFORM, SfxCallMode::RECORD, { &aPosXItem });
}
}
IMPL_LINK_NOARG( PosSizePropertyPanel, ChangePosYHdl, weld::MetricSpinButton&, void )
{
if ( mxMtrPosY->get_value_changed_from_saved() )
{
long lY = GetCoreValue( *mxMtrPosY, mePoolUnit );
Fraction aUIScale = mpView->GetModel()->GetUIScale();
lY = long( lY * aUIScale );
SfxInt32Item aPosYItem( SID_ATTR_TRANSFORM_POS_Y,static_cast<sal_uInt32>(lY));
GetBindings()->GetDispatcher()->ExecuteList(
SID_ATTR_TRANSFORM, SfxCallMode::RECORD, { &aPosYItem });
}
}
IMPL_LINK_NOARG( PosSizePropertyPanel, ClickAutoHdl, weld::ToggleButton&, void )
{
if ( mxCbxScale->get_active() )
{
mlOldWidth = std::max(GetCoreValue(*mxMtrWidth, mePoolUnit), 1);
mlOldHeight = std::max(GetCoreValue(*mxMtrHeight, mePoolUnit), 1);
}
// mxCbxScale must synchronized with that on Position and Size tabpage on Shape Properties dialog
SvtViewOptions aPageOpt(EViewType::TabPage, "cui/ui/possizetabpage/PositionAndSize");
aPageOpt.SetUserItem( USERITEM_NAME, css::uno::makeAny( OUString::number( int(mxCbxScale->get_active()) ) ) );
}
IMPL_LINK_NOARG( PosSizePropertyPanel, RotationHdl, DialControl&, void )
{
sal_Int32 nTmp = mxCtrlDial->GetRotation();
// #i123993# Need to take UIScale into account when executing rotations
const double fUIScale(mpView && mpView->GetModel() ? double(mpView->GetModel()->GetUIScale()) : 1.0);
SfxInt32Item aAngleItem( SID_ATTR_TRANSFORM_ANGLE,static_cast<sal_uInt32>(nTmp));
SfxInt32Item aRotXItem( SID_ATTR_TRANSFORM_ROT_X, basegfx::fround(mlRotX * fUIScale));
SfxInt32Item aRotYItem( SID_ATTR_TRANSFORM_ROT_Y, basegfx::fround(mlRotY * fUIScale));
GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_TRANSFORM,
SfxCallMode::RECORD, { &aAngleItem, &aRotXItem, &aRotYItem });
}
IMPL_STATIC_LINK_NOARG( PosSizePropertyPanel, ClickChartEditHdl, weld::Button&, void )
{
SfxViewShell* pCurSh = SfxViewShell::Current();
if ( pCurSh)
{
pCurSh->DoVerb( -1 );
}
}
namespace
{
void limitWidth(weld::MetricSpinButton& rMetricSpinButton)
{
// space is limited in the sidebar, so limit MetricSpinButtons to a width of 7 digits
const int nMaxDigits = 7;
weld::SpinButton& rSpinButton = rMetricSpinButton.get_widget();
rSpinButton.set_width_chars(std::min(rSpinButton.get_width_chars(), nMaxDigits));
}
}
void PosSizePropertyPanel::NotifyItemUpdate(
sal_uInt16 nSID,
SfxItemState eState,
const SfxPoolItem* pState)
{
mxFtAngle->set_sensitive(true);
mxMtrAngle->set_sensitive(true);
mxDial->set_sensitive(true);
mxFtFlip->set_sensitive(true);
mxFlipTbx->set_sensitive(true);
const SfxUInt32Item* pWidthItem;
const SfxUInt32Item* pHeightItem;
SfxViewShell* pCurSh = SfxViewShell::Current();
if ( pCurSh )
mpView = pCurSh->GetDrawView();
else
mpView = nullptr;
if ( mpView == nullptr )
return;
mbAdjustEnabled = hasText(*mpView);
// Pool unit and dialog unit may have changed, make sure that we
// have the current values.
mePoolUnit = maTransfWidthControl.GetCoreMetric();
switch (nSID)
{
case SID_ATTR_TRANSFORM_WIDTH:
if ( SfxItemState::DEFAULT == eState )
{
pWidthItem = dynamic_cast< const SfxUInt32Item* >(pState);
if(pWidthItem)
{
long lOldWidth1 = long( pWidthItem->GetValue() / maUIScale );
SetFieldUnit( *mxMtrWidth, meDlgUnit, true );
SetMetricValue( *mxMtrWidth, lOldWidth1, mePoolUnit );
limitWidth(*mxMtrWidth);
mlOldWidth = lOldWidth1;
mxMtrWidth->save_value();
break;
}
}
mxMtrWidth->set_text( "" );
break;
case SID_ATTR_TRANSFORM_HEIGHT:
if ( SfxItemState::DEFAULT == eState )
{
pHeightItem = dynamic_cast< const SfxUInt32Item* >(pState);
if(pHeightItem)
{
long nTmp = long( pHeightItem->GetValue() / maUIScale);
SetFieldUnit( *mxMtrHeight, meDlgUnit, true );
SetMetricValue( *mxMtrHeight, nTmp, mePoolUnit );
limitWidth(*mxMtrHeight);
mlOldHeight = nTmp;
mxMtrHeight->save_value();
break;
}
}
mxMtrHeight->set_text( "");
break;
case SID_ATTR_TRANSFORM_POS_X:
if(SfxItemState::DEFAULT == eState)
{
const SfxInt32Item* pItem = dynamic_cast< const SfxInt32Item* >(pState);
if(pItem)
{
long nTmp = long(pItem->GetValue() / maUIScale);
SetFieldUnit( *mxMtrPosX, meDlgUnit, true );
SetMetricValue( *mxMtrPosX, nTmp, mePoolUnit );
limitWidth(*mxMtrPosX);
mxMtrPosX->save_value();
break;
}
}
mxMtrPosX->set_text( "" );
break;
case SID_ATTR_TRANSFORM_POS_Y:
if(SfxItemState::DEFAULT == eState)
{
const SfxInt32Item* pItem = dynamic_cast< const SfxInt32Item* >(pState);
if(pItem)
{
long nTmp = long(pItem->GetValue() / maUIScale);
SetFieldUnit( *mxMtrPosY, meDlgUnit, true );
SetMetricValue( *mxMtrPosY, nTmp, mePoolUnit );
limitWidth(*mxMtrPosY);
mxMtrPosY->save_value();
break;
}
}
mxMtrPosY->set_text( "" );
break;
case SID_ATTR_TRANSFORM_ROT_X:
if (SfxItemState::DEFAULT == eState)
{
const SfxInt32Item* pItem = dynamic_cast< const SfxInt32Item* >(pState);
if(pItem)
{
mlRotX = pItem->GetValue();
mlRotX = long( mlRotX / maUIScale );
}
}
break;
case SID_ATTR_TRANSFORM_ROT_Y:
if (SfxItemState::DEFAULT == eState)
{
const SfxInt32Item* pItem = dynamic_cast< const SfxInt32Item* >(pState);
if(pItem)
{
mlRotY = pItem->GetValue();
mlRotY = long( mlRotY / maUIScale );
}
}
break;
case SID_ATTR_TRANSFORM_PROTECT_POS:
if(SfxItemState::DEFAULT == eState)
{
const SfxBoolItem* pItem = dynamic_cast< const SfxBoolItem* >(pState);
if(pItem)
{
// record the state of position protect
mbPositionProtected = pItem->GetValue();
break;
}
}
mbPositionProtected = false;
break;
case SID_ATTR_TRANSFORM_PROTECT_SIZE:
if(SfxItemState::DEFAULT == eState)
{
const SfxBoolItem* pItem = dynamic_cast< const SfxBoolItem* >(pState);
if(pItem)
{
// record the state of size protect
mbSizeProtected = pItem->GetValue();
break;
}
}
mbSizeProtected = false;
break;
case SID_ATTR_TRANSFORM_AUTOWIDTH:
if(SfxItemState::DEFAULT == eState)
{
const SfxBoolItem* pItem = dynamic_cast< const SfxBoolItem* >(pState);
if(pItem)
{
mbAutoWidth = pItem->GetValue();
}
}
break;
case SID_ATTR_TRANSFORM_AUTOHEIGHT:
if(SfxItemState::DEFAULT == eState)
{
const SfxBoolItem* pItem = dynamic_cast< const SfxBoolItem* >(pState);
if(pItem)
{
mbAutoHeight = pItem->GetValue();
}
}
break;
case SID_ATTR_TRANSFORM_ANGLE:
if (eState >= SfxItemState::DEFAULT)
{
const SfxInt32Item* pItem = dynamic_cast< const SfxInt32Item* >(pState);
if(pItem)
{
long nTmp = pItem->GetValue();
nTmp = nTmp < 0 ? 36000+nTmp : nTmp;
mxMtrAngle->set_value(nTmp, FieldUnit::DEGREE);
mxCtrlDial->SetRotation(nTmp);
break;
}
}
mxMtrAngle->set_text( "" );
mxCtrlDial->SetRotation( 0 );
break;
case SID_ATTR_METRIC:
MetricState( eState, pState );
UpdateUIScale();
break;
default:
break;
}
const sal_Int32 nCombinedContext(maContext.GetCombinedContext_DI());
const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
switch (rMarkList.GetMarkCount())
{
case 0:
break;
case 1:
{
const SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
const SdrObjKind eKind(static_cast<SdrObjKind>(pObj->GetObjIdentifier()));
if(((nCombinedContext == CombinedEnumContext(Application::DrawImpress, Context::Draw)
|| nCombinedContext == CombinedEnumContext(Application::DrawImpress, Context::TextObject)
) && OBJ_EDGE == eKind)
|| OBJ_CAPTION == eKind)
{
mxFtAngle->set_sensitive(false);
mxMtrAngle->set_sensitive(false);
mxDial->set_sensitive(false);
mxFlipTbx->set_sensitive(false);
mxFtFlip->set_sensitive(false);
}
break;
}
default:
{
sal_uInt16 nMarkObj = 0;
bool isNoEdge = true;
while(isNoEdge && rMarkList.GetMark(nMarkObj))
{
const SdrObject* pObj = rMarkList.GetMark(nMarkObj)->GetMarkedSdrObj();
const SdrObjKind eKind(static_cast<SdrObjKind>(pObj->GetObjIdentifier()));
if(((nCombinedContext == CombinedEnumContext(Application::DrawImpress, Context::Draw)
|| nCombinedContext == CombinedEnumContext(Application::DrawImpress, Context::TextObject)
) && OBJ_EDGE == eKind)
|| OBJ_CAPTION == eKind)
{
isNoEdge = false;
break;
}
nMarkObj++;
}
if(!isNoEdge)
{
mxFtAngle->set_sensitive(false);
mxMtrAngle->set_sensitive(false);
mxDial->set_sensitive(false);
mxFlipTbx->set_sensitive(false);
mxFtFlip->set_sensitive(false);
}
break;
}
}
if(nCombinedContext == CombinedEnumContext(Application::DrawImpress, Context::TextObject))
{
mxFlipTbx->set_sensitive(false);
mxFtFlip->set_sensitive(false);
}
DisableControls();
// mxCbxScale must synchronized with that on Position and Size tabpage on Shape Properties dialog
SvtViewOptions aPageOpt(EViewType::TabPage, "cui/ui/possizetabpage/PositionAndSize");
OUString sUserData;
css::uno::Any aUserItem = aPageOpt.GetUserItem( USERITEM_NAME );
OUString aTemp;
if ( aUserItem >>= aTemp )
sUserData = aTemp;
mxCbxScale->set_active(static_cast<bool>(sUserData.toInt32()));
}
void PosSizePropertyPanel::GetControlState(const sal_uInt16 nSID, boost::property_tree::ptree& rState)
{
weld::MetricSpinButton* pControl = nullptr;
switch (nSID)
{
case SID_ATTR_TRANSFORM_POS_X:
pControl = mxMtrPosX.get();
break;
case SID_ATTR_TRANSFORM_POS_Y:
pControl = mxMtrPosY.get();
break;
case SID_ATTR_TRANSFORM_WIDTH:
pControl = mxMtrWidth.get();
break;
case SID_ATTR_TRANSFORM_HEIGHT:
pControl = mxMtrHeight.get();
break;
}
if (pControl && !pControl->get_text().isEmpty())
{
OUString sValue = Application::GetSettings().GetNeutralLocaleDataWrapper().
getNum(pControl->get_value(pControl->get_unit()), pControl->get_digits(), false, false);
rState.put(pControl->get_buildable_name().getStr(), sValue.toUtf8().getStr());
}
}
void PosSizePropertyPanel::executeSize()
{
if ( !mxMtrWidth->get_value_changed_from_saved() && !mxMtrHeight->get_value_changed_from_saved())
return;
Fraction aUIScale = mpView->GetModel()->GetUIScale();
// get Width
double nWidth = static_cast<double>(mxMtrWidth->get_value(FieldUnit::MM_100TH));
long lWidth = long(nWidth * static_cast<double>(aUIScale));
lWidth = OutputDevice::LogicToLogic( lWidth, MapUnit::Map100thMM, mePoolUnit );
lWidth = static_cast<long>(mxMtrWidth->denormalize( lWidth ));
// get Height
double nHeight = static_cast<double>(mxMtrHeight->get_value(FieldUnit::MM_100TH));
long lHeight = long(nHeight * static_cast<double>(aUIScale));
lHeight = OutputDevice::LogicToLogic( lHeight, MapUnit::Map100thMM, mePoolUnit );
lHeight = static_cast<long>(mxMtrHeight->denormalize( lHeight ));
// put Width & Height to itemset
SfxUInt32Item aWidthItem( SID_ATTR_TRANSFORM_WIDTH, static_cast<sal_uInt32>(lWidth));
SfxUInt32Item aHeightItem( SID_ATTR_TRANSFORM_HEIGHT, static_cast<sal_uInt32>(lHeight));
SfxUInt16Item aPointItem (SID_ATTR_TRANSFORM_SIZE_POINT, sal_uInt16(RectPoint::LT));
const sal_Int32 nCombinedContext(maContext.GetCombinedContext_DI());
if( nCombinedContext == CombinedEnumContext(Application::WriterVariants, Context::Graphic)
|| nCombinedContext == CombinedEnumContext(Application::WriterVariants, Context::OLE)
)
{
GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_TRANSFORM,
SfxCallMode::RECORD, { &aWidthItem, &aHeightItem, &aPointItem });
}
else
{
if ( (mxMtrWidth->get_value_changed_from_saved()) && (mxMtrHeight->get_value_changed_from_saved()))
GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_TRANSFORM,
SfxCallMode::RECORD, { &aWidthItem, &aHeightItem, &aPointItem });
else if( mxMtrWidth->get_value_changed_from_saved())
GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_TRANSFORM,
SfxCallMode::RECORD, { &aWidthItem, &aPointItem });
else if ( mxMtrHeight->get_value_changed_from_saved())
GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_TRANSFORM,
SfxCallMode::RECORD, { &aHeightItem, &aPointItem });
}
}
boost::property_tree::ptree PosSizePropertyPanel::DumpAsPropertyTree()
{
if (meDlgUnit != GetCurrentUnit(SfxItemState::DEFAULT, nullptr))
{
mpBindings->Update( SID_ATTR_METRIC );
}
return PanelLayout::DumpAsPropertyTree();
}
void PosSizePropertyPanel::MetricState( SfxItemState eState, const SfxPoolItem* pState )
{
bool bPosXBlank = false;
bool bPosYBlank = false;
bool bWidthBlank = false;
bool bHeightBlank = false;
// #i124409# use the given Item to get the correct UI unit and initialize it
// and the Fields using it
meDlgUnit = GetCurrentUnit(eState,pState);
if (mxMtrPosX->get_text().isEmpty())
bPosXBlank = true;
SetFieldUnit( *mxMtrPosX, meDlgUnit, true );
if(bPosXBlank)
mxMtrPosX->set_text(OUString());
if (mxMtrPosY->get_text().isEmpty())
bPosYBlank = true;
SetFieldUnit( *mxMtrPosY, meDlgUnit, true );
if(bPosYBlank)
mxMtrPosY->set_text(OUString());
SetPosSizeMinMax();
if (mxMtrWidth->get_text().isEmpty())
bWidthBlank = true;
SetFieldUnit( *mxMtrWidth, meDlgUnit, true );
if(bWidthBlank)
mxMtrWidth->set_text(OUString());
if (mxMtrHeight->get_text().isEmpty())
bHeightBlank = true;
SetFieldUnit( *mxMtrHeight, meDlgUnit, true );
if(bHeightBlank)
mxMtrHeight->set_text(OUString());
}
FieldUnit PosSizePropertyPanel::GetCurrentUnit( SfxItemState eState, const SfxPoolItem* pState )
{
FieldUnit eUnit = FieldUnit::NONE;
if ( pState && eState >= SfxItemState::DEFAULT )
{
eUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(pState)->GetValue());
}
else
{
SfxViewFrame* pFrame = SfxViewFrame::Current();
SfxObjectShell* pSh = nullptr;
if ( pFrame )
pSh = pFrame->GetObjectShell();
if ( pSh )
{
SfxModule* pModule = pSh->GetModule();
if ( pModule )
{
const SfxPoolItem* pItem = pModule->GetItem( SID_ATTR_METRIC );
if ( pItem )
eUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(pItem)->GetValue());
}
else
{
SAL_WARN("svx.sidebar", "GetModuleFieldUnit(): no module found");
}
}
}
return eUnit;
}
void PosSizePropertyPanel::DisableControls()
{
if( mbPositionProtected )
{
// the position is protected("Position protect" option in modal dialog is checked),
// disable all the Position controls in sidebar
mxFtPosX->set_sensitive(false);
mxMtrPosX->set_sensitive(false);
mxFtPosY->set_sensitive(false);
mxMtrPosY->set_sensitive(false);
mxFtAngle->set_sensitive(false);
mxMtrAngle->set_sensitive(false);
mxDial->set_sensitive(false);
mxFtFlip->set_sensitive(false);
mxFlipTbx->set_sensitive(false);
mxFtWidth->set_sensitive(false);
mxMtrWidth->set_sensitive(false);
mxFtHeight->set_sensitive(false);
mxMtrHeight->set_sensitive(false);
mxCbxScale->set_sensitive(false);
}
else
{
mxFtPosX->set_sensitive(true);
mxMtrPosX->set_sensitive(true);
mxFtPosY->set_sensitive(true);
mxMtrPosY->set_sensitive(true);
if( mbSizeProtected )
{
mxFtWidth->set_sensitive(false);
mxMtrWidth->set_sensitive(false);
mxFtHeight->set_sensitive(false);
mxMtrHeight->set_sensitive(false);
mxCbxScale->set_sensitive(false);
}
else
{
if( mbAdjustEnabled )
{
if( mbAutoWidth )
{
mxFtWidth->set_sensitive(false);
mxMtrWidth->set_sensitive(false);
mxCbxScale->set_sensitive(false);
}
else
{
mxFtWidth->set_sensitive(true);
mxMtrWidth->set_sensitive(true);
}
if( mbAutoHeight )
{
mxFtHeight->set_sensitive(false);
mxMtrHeight->set_sensitive(false);
mxCbxScale->set_sensitive(false);
}
else
{
mxFtHeight->set_sensitive(true);
mxMtrHeight->set_sensitive(true);
}
if( !mbAutoWidth && !mbAutoHeight )
mxCbxScale->set_sensitive(true);
}
else
{
mxFtWidth->set_sensitive(true);
mxMtrWidth->set_sensitive(true);
mxFtHeight->set_sensitive(true);
mxMtrHeight->set_sensitive(true);
mxCbxScale->set_sensitive(true);
}
}
}
}
void PosSizePropertyPanel::SetPosSizeMinMax()
{
SdrPageView* pPV = mpView->GetSdrPageView();
if (!pPV)
return;
tools::Rectangle aTmpRect(mpView->GetAllMarkedRect());
pPV->LogicToPagePos(aTmpRect);
maRect = vcl::unotools::b2DRectangleFromRectangle(aTmpRect);
tools::Rectangle aTmpRect2(mpView->GetWorkArea());
pPV->LogicToPagePos(aTmpRect2);
maWorkArea = vcl::unotools::b2DRectangleFromRectangle(aTmpRect2);
const Fraction aUIScale(mpView->GetModel()->GetUIScale());
TransfrmHelper::ScaleRect( maWorkArea, aUIScale );
TransfrmHelper::ScaleRect( maRect, aUIScale );
const sal_uInt16 nDigits(mxMtrPosX->get_digits());
TransfrmHelper::ConvertRect( maWorkArea, nDigits, mePoolUnit, meDlgUnit );
TransfrmHelper::ConvertRect( maRect, nDigits, mePoolUnit, meDlgUnit );
double fLeft(maWorkArea.getMinX());
double fTop(maWorkArea.getMinY());
double fRight(maWorkArea.getMaxX());
double fBottom(maWorkArea.getMaxY());
// seems that sidebar defaults to top left reference point
// and there's no way to set it to something else
fRight -= maRect.getWidth();
fBottom -= maRect.getHeight();
const double fMaxLong(static_cast<double>(vcl::ConvertValue( LONG_MAX, 0, MapUnit::Map100thMM, meDlgUnit ) - 1));
fLeft = std::clamp(fLeft, -fMaxLong, fMaxLong);
fRight = std::clamp(fRight, -fMaxLong, fMaxLong);
fTop = std::clamp(fTop, - fMaxLong, fMaxLong);
fBottom = std::clamp(fBottom, -fMaxLong, fMaxLong);
mxMtrPosX->set_range(basegfx::fround64(fLeft), basegfx::fround64(fRight), FieldUnit::NONE);
limitWidth(*mxMtrPosX);
mxMtrPosY->set_range(basegfx::fround64(fTop), basegfx::fround64(fBottom), FieldUnit::NONE);
limitWidth(*mxMtrPosY);
double fMaxWidth = maWorkArea.getWidth() - (maRect.getWidth() - fLeft);
double fMaxHeight = maWorkArea.getHeight() - (maRect.getHeight() - fTop);
mxMtrWidth->set_max(basegfx::fround64(fMaxWidth*100), FieldUnit::NONE);
limitWidth(*mxMtrWidth);
mxMtrHeight->set_max(basegfx::fround64(fMaxHeight*100), FieldUnit::NONE);
limitWidth(*mxMtrHeight);
}
void PosSizePropertyPanel::UpdateUIScale()
{
const Fraction aUIScale (mpView->GetModel()->GetUIScale());
if (maUIScale != aUIScale)
{
// UI scale has changed.
// Remember the new UI scale.
maUIScale = aUIScale;
// The content of the position and size boxes is only updated when item changes are notified.
// Request such notifications without changing the actual item values.
GetBindings()->Invalidate(SID_ATTR_TRANSFORM_POS_X, true);
GetBindings()->Invalidate(SID_ATTR_TRANSFORM_POS_Y, true);
GetBindings()->Invalidate(SID_ATTR_TRANSFORM_WIDTH, true);
GetBindings()->Invalidate(SID_ATTR_TRANSFORM_HEIGHT, true);
}
}
} // end of namespace svx::sidebar
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|