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
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
|
/* -*- 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 <com/sun/star/table/BorderLineStyle.hpp>
#include <comphelper/lok.hxx>
#include <editeng/boxitem.hxx>
#include <editeng/langitem.hxx>
#include <o3tl/temporary.hxx>
#include <sfx2/bindings.hxx>
#include <sfx2/request.hxx>
#include <sfx2/sfxdlg.hxx>
#include <sfx2/sidebar/Sidebar.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/newstyle.hxx>
#include <sfx2/tplpitem.hxx>
#include <svl/ilstitem.hxx>
#include <svl/numformat.hxx>
#include <svl/zformat.hxx>
#include <svl/int64item.hxx>
#include <svl/ptitem.hxx>
#include <svl/srchitem.hxx>
#include <svl/srchdefs.hxx>
#include <svl/stritem.hxx>
#include <svl/whiter.hxx>
#include <svx/numinf.hxx>
#include <svx/xbtmpit.hxx>
#include <svx/xlndsit.hxx>
#include <svx/xlnstit.hxx>
#include <svx/xlnedit.hxx>
#include <svx/xflgrit.hxx>
#include <svx/xflftrit.hxx>
#include <svx/xflhtit.hxx>
#include <svx/zoomslideritem.hxx>
#include <global.hxx>
#include <appoptio.hxx>
#include <attrib.hxx>
#include <cellform.hxx>
#include <cellvalue.hxx>
#include <compiler.hxx>
#include <docsh.hxx>
#include <document.hxx>
#include <formulacell.hxx>
#include <globstr.hrc>
#include <inputhdl.hxx>
#include <inputwin.hxx>
#include <markdata.hxx>
#include <patattr.hxx>
#include <sc.hrc>
#include <scabstdlg.hxx>
#include <scitems.hxx>
#include <scmod.hxx>
#include <scresid.hxx>
#include <stlpool.hxx>
#include <tabvwsh.hxx>
#include <tokenarray.hxx>
#include <viewdata.hxx>
#include <docpool.hxx>
#include <printfun.hxx>
#include <undostyl.hxx>
#include <futext.hxx>
#include <memory>
using namespace com::sun::star;
bool ScTabViewShell::GetFunction( OUString& rFuncStr, FormulaError nErrCode )
{
sal_uInt32 nFuncs = SC_MOD()->GetAppOptions().GetStatusFunc();
ScViewData& rViewData = GetViewData();
ScMarkData& rMark = rViewData.GetMarkData();
bool bIgnoreError = (rMark.IsMarked() || rMark.IsMultiMarked());
bool bFirst = true;
for ( sal_uInt16 nFunc = 0; nFunc < 32; nFunc++ )
{
if ( !(nFuncs & (1U << nFunc)) )
continue;
ScSubTotalFunc eFunc = static_cast<ScSubTotalFunc>(nFunc);
if (bIgnoreError && (eFunc == SUBTOTAL_FUNC_CNT || eFunc == SUBTOTAL_FUNC_CNT2))
nErrCode = FormulaError::NONE;
if (nErrCode != FormulaError::NONE)
{
rFuncStr = ScGlobal::GetLongErrorString(nErrCode);
return true;
}
TranslateId pGlobStrId;
switch (eFunc)
{
case SUBTOTAL_FUNC_AVE: pGlobStrId = STR_FUN_TEXT_AVG; break;
case SUBTOTAL_FUNC_CNT: pGlobStrId = STR_FUN_TEXT_COUNT; break;
case SUBTOTAL_FUNC_CNT2: pGlobStrId = STR_FUN_TEXT_COUNT2; break;
case SUBTOTAL_FUNC_MAX: pGlobStrId = STR_FUN_TEXT_MAX; break;
case SUBTOTAL_FUNC_MIN: pGlobStrId = STR_FUN_TEXT_MIN; break;
case SUBTOTAL_FUNC_SUM: pGlobStrId = STR_FUN_TEXT_SUM; break;
case SUBTOTAL_FUNC_SELECTION_COUNT: pGlobStrId = STR_FUN_TEXT_SELECTION_COUNT; break;
default:
{
// added to avoid warnings
}
}
if (pGlobStrId)
{
ScDocument& rDoc = rViewData.GetDocument();
SCCOL nPosX = rViewData.GetCurX();
SCROW nPosY = rViewData.GetCurY();
SCTAB nTab = rViewData.GetTabNo();
OUString aStr = ScResId(pGlobStrId) + ": ";
ScAddress aCursor( nPosX, nPosY, nTab );
double nVal;
if ( rDoc.GetSelectionFunction( eFunc, aCursor, rMark, nVal ) )
{
if ( nVal == 0.0 )
aStr += "0";
else
{
// Number in the standard format, the other on the cursor position
SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
sal_uInt32 nNumFmt = 0;
if ( eFunc != SUBTOTAL_FUNC_CNT && eFunc != SUBTOTAL_FUNC_CNT2 && eFunc != SUBTOTAL_FUNC_SELECTION_COUNT)
{
// number format from attributes or formula
nNumFmt = rDoc.GetNumberFormat( nPosX, nPosY, nTab );
// If the number format is time (without date) and the
// result is not within 24 hours, use a duration
// format. Summing date+time doesn't make much sense
// otherwise but we also don't want to display duration
// for a single date+time value.
if (nVal < 0.0 || nVal >= 1.0)
{
const SvNumberformat* pFormat = pFormatter->GetEntry(nNumFmt);
if (pFormat && (pFormat->GetType() == SvNumFormatType::TIME))
nNumFmt = pFormatter->GetTimeFormat( nVal, pFormat->GetLanguage(), true);
}
}
OUString aValStr;
const Color* pDummy;
pFormatter->GetOutputString( nVal, nNumFmt, aValStr, &pDummy );
aStr += aValStr;
}
}
if ( bFirst )
{
rFuncStr += aStr;
bFirst = false;
}
else
rFuncStr += "; " + aStr;
}
}
return !rFuncStr.isEmpty();
}
// Functions that are disabled, depending on the selection
// Default:
// SID_DELETE,
// SID_DELETE_CONTENTS,
// FID_DELETE_CELL
// FID_VALIDATION
void ScTabViewShell::GetState( SfxItemSet& rSet )
{
ScViewData& rViewData = GetViewData();
ScDocument& rDoc = rViewData.GetDocument();
ScDocShell* pDocShell = rViewData.GetDocShell();
ScMarkData& rMark = rViewData.GetMarkData();
SCCOL nPosX = rViewData.GetCurX();
SCROW nPosY = rViewData.GetCurY();
SCTAB nTab = rViewData.GetTabNo();
SfxViewFrame& rThisFrame = GetViewFrame();
bool bOle = GetViewFrame().GetFrame().IsInPlace();
SCTAB nTabSelCount = rMark.GetSelectCount();
SfxWhichIter aIter(rSet);
sal_uInt16 nWhich = aIter.FirstWhich();
while ( nWhich )
{
switch ( nWhich )
{
case FID_CHG_COMMENT:
{
ScDocShell* pDocSh = GetViewData().GetDocShell();
ScAddress aPos( nPosX, nPosY, nTab );
if ( pDocSh->IsReadOnly() || !pDocSh->GetChangeAction(aPos) || pDocSh->IsDocShared() )
rSet.DisableItem( nWhich );
}
break;
case SID_OPENDLG_EDIT_PRINTAREA:
case SID_ADD_PRINTAREA:
case SID_DEFINE_PRINTAREA:
{
if ( pDocShell && pDocShell->IsDocShared() )
{
rSet.DisableItem( nWhich );
}
}
break;
case SID_DELETE_PRINTAREA:
if ( pDocShell && pDocShell->IsDocShared() )
{
rSet.DisableItem( nWhich );
}
else if (rDoc.IsPrintEntireSheet(nTab))
rSet.DisableItem(nWhich);
break;
case SID_STATUS_PAGESTYLE:
case SID_HFEDIT:
GetViewData().GetDocShell()->GetStatePageStyle( rSet, nTab );
break;
case SID_SEARCH_ITEM:
{
SvxSearchItem aItem(ScGlobal::GetSearchItem()); // make a copy.
// Search on current selection if a range is marked.
aItem.SetSelection(rMark.IsMarked());
rSet.Put(aItem);
break;
}
case SID_SEARCH_OPTIONS:
{
// Anything goes
SearchOptionFlags nOptions = SearchOptionFlags::ALL;
// No replacement if ReadOnly
if (GetViewData().GetDocShell()->IsReadOnly())
nOptions &= ~SearchOptionFlags( SearchOptionFlags::REPLACE | SearchOptionFlags::REPLACE_ALL );
rSet.Put( SfxUInt16Item( nWhich, static_cast<sal_uInt16>(nOptions) ) );
}
break;
case SID_CURRENTCELL:
{
ScAddress aScAddress( GetViewData().GetCurX(), GetViewData().GetCurY(), 0 );
OUString aAddr(aScAddress.Format(ScRefFlags::ADDR_ABS, nullptr, rDoc.GetAddressConvention()));
SfxStringItem aPosItem( SID_CURRENTCELL, aAddr );
rSet.Put( aPosItem );
}
break;
case SID_CURRENTTAB:
// Table for Basic is 1-based
rSet.Put( SfxUInt16Item( nWhich, static_cast<sal_uInt16>(GetViewData().GetTabNo()) + 1 ) );
break;
case SID_CURRENTDOC:
rSet.Put( SfxStringItem( nWhich, GetViewData().GetDocShell()->GetTitle() ) );
break;
case FID_TOGGLEINPUTLINE:
{
sal_uInt16 nId = ScInputWindowWrapper::GetChildWindowId();
if ( rThisFrame.KnowsChildWindow( nId ) )
{
SfxChildWindow* pWnd = rThisFrame.GetChildWindow( nId );
rSet.Put( SfxBoolItem( nWhich, pWnd != nullptr ) );
}
else
rSet.DisableItem( nWhich );
}
break;
case FID_DEL_MANUALBREAKS:
if (!rDoc.HasManualBreaks(nTab))
rSet.DisableItem( nWhich );
break;
case FID_RESET_PRINTZOOM:
{
// disable if already set to default
OUString aStyleName = rDoc.GetPageStyle( nTab );
ScStyleSheetPool* pStylePool = rDoc.GetStyleSheetPool();
SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName,
SfxStyleFamily::Page );
OSL_ENSURE( pStyleSheet, "PageStyle not found" );
if ( pStyleSheet )
{
SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
sal_uInt16 nScale = rStyleSet.Get(ATTR_PAGE_SCALE).GetValue();
sal_uInt16 nPages = rStyleSet.Get(ATTR_PAGE_SCALETOPAGES).GetValue();
if ( nScale == 100 && nPages == 0 )
rSet.DisableItem( nWhich );
}
}
break;
case SID_ZOOM_IN:
{
const Fraction& rZoomY = GetViewData().GetZoomY();
tools::Long nZoom = tools::Long(rZoomY * 100);
if (nZoom >= MAXZOOM)
rSet.DisableItem(nWhich);
}
break;
case SID_ZOOM_OUT:
{
const Fraction& rZoomY = GetViewData().GetZoomY();
tools::Long nZoom = tools::Long(rZoomY * 100);
if (nZoom <= MINZOOM)
rSet.DisableItem(nWhich);
}
break;
case FID_SCALE:
case SID_ATTR_ZOOM:
if ( bOle )
rSet.DisableItem( nWhich );
else
{
const Fraction& rOldY = GetViewData().GetZoomY();
sal_uInt16 nZoom = static_cast<sal_uInt16>(tools::Long( rOldY * 100 ));
rSet.Put( SvxZoomItem( SvxZoomType::PERCENT, nZoom, TypedWhichId<SvxZoomItem>(nWhich) ) );
}
break;
case SID_ATTR_ZOOMSLIDER:
{
if ( bOle )
rSet.DisableItem( nWhich );
else
{
const Fraction& rOldY = GetViewData().GetZoomY();
sal_uInt16 nCurrentZoom = static_cast<sal_uInt16>(tools::Long( rOldY * 100 ));
if( nCurrentZoom )
{
SvxZoomSliderItem aZoomSliderItem( nCurrentZoom, MINZOOM, MAXZOOM, SID_ATTR_ZOOMSLIDER );
aZoomSliderItem.AddSnappingPoint( 100 );
rSet.Put( aZoomSliderItem );
}
}
}
break;
case FID_FUNCTION_BOX:
{
const bool bBoxOpen = ::sfx2::sidebar::Sidebar::IsPanelVisible(u"ScFunctionsPanel",
rThisFrame.GetFrame().GetFrameInterface());
rSet.Put(SfxBoolItem(nWhich, bBoxOpen));
break;
}
case FID_TOGGLESYNTAX:
rSet.Put(SfxBoolItem(nWhich, GetViewData().IsSyntaxMode()));
break;
case FID_TOGGLEHEADERS:
rSet.Put(SfxBoolItem(nWhich, GetViewData().IsHeaderMode()));
break;
case FID_TOGGLEFORMULA:
{
const ScViewOptions& rOpts = rViewData.GetOptions();
bool bFormulaMode = rOpts.GetOption( VOPT_FORMULAS );
rSet.Put(SfxBoolItem(nWhich, bFormulaMode ));
}
break;
case FID_NORMALVIEWMODE:
case FID_PAGEBREAKMODE:
// always handle both slots - they exclude each other
if ( bOle )
{
rSet.DisableItem( FID_NORMALVIEWMODE );
rSet.DisableItem( FID_PAGEBREAKMODE );
}
else
{
rSet.Put(SfxBoolItem(FID_NORMALVIEWMODE, !GetViewData().IsPagebreakMode()));
rSet.Put(SfxBoolItem(FID_PAGEBREAKMODE, GetViewData().IsPagebreakMode()));
}
break;
case FID_PROTECT_DOC:
{
if ( pDocShell && pDocShell->IsDocShared() )
{
rSet.DisableItem( nWhich );
}
else
{
rSet.Put( SfxBoolItem( nWhich, rDoc.IsDocProtected() ) );
}
}
break;
case FID_PROTECT_TABLE:
{
if ( pDocShell && pDocShell->IsDocShared() )
{
rSet.DisableItem( nWhich );
}
else
{
rSet.Put( SfxBoolItem( nWhich, rDoc.IsTabProtected( nTab ) ) );
}
}
break;
case SID_AUTO_OUTLINE:
{
if (rDoc.GetChangeTrack()!=nullptr || GetViewData().IsMultiMarked())
{
rSet.DisableItem( nWhich );
}
}
break;
case SID_OUTLINE_DELETEALL:
{
SCTAB nOlTab = GetViewData().GetTabNo();
ScOutlineTable* pOlTable = rDoc.GetOutlineTable( nOlTab );
if (pOlTable == nullptr)
rSet.DisableItem( nWhich );
}
break;
case SID_WINDOW_SPLIT:
rSet.Put(SfxBoolItem(nWhich,
rViewData.GetHSplitMode() == SC_SPLIT_NORMAL ||
rViewData.GetVSplitMode() == SC_SPLIT_NORMAL ));
break;
case SID_WINDOW_FIX:
if(!comphelper::LibreOfficeKit::isActive())
{
rSet.Put(SfxBoolItem(nWhich,
rViewData.GetHSplitMode() == SC_SPLIT_FIX ||
rViewData.GetVSplitMode() == SC_SPLIT_FIX ));
}
else
{
rSet.Put(SfxBoolItem(nWhich,
rViewData.GetLOKSheetFreezeIndex(true) > 0 ||
rViewData.GetLOKSheetFreezeIndex(false) > 0 ));
}
break;
case SID_WINDOW_FIX_COL:
case SID_WINDOW_FIX_ROW:
{
Point aPos;
bool bIsCol = (nWhich == SID_WINDOW_FIX_COL);
aPos.setX(rViewData.GetLOKSheetFreezeIndex(bIsCol));
aPos.setY(rViewData.GetTabNo());
rSet.Put(SfxPointItem(nWhich, aPos));
}
break;
case FID_CHG_SHOW:
{
if ( rDoc.GetChangeTrack() == nullptr || ( pDocShell && pDocShell->IsDocShared() ) )
rSet.DisableItem( nWhich );
}
break;
case FID_CHG_ACCEPT:
{
if(
( !rDoc.GetChangeTrack() && !rThisFrame.HasChildWindow(FID_CHG_ACCEPT) )
||
( pDocShell && pDocShell->IsDocShared() )
)
{
rSet.DisableItem( nWhich);
}
else
{
rSet.Put(SfxBoolItem(FID_CHG_ACCEPT,
rThisFrame.HasChildWindow(FID_CHG_ACCEPT)));
}
}
break;
case SID_FORMATPAGE:
// in protected tables
if ( pDocShell && ( pDocShell->IsReadOnly() || pDocShell->IsDocShared() ) )
rSet.DisableItem( nWhich );
break;
case SID_PRINTPREVIEW:
// Toggle slot needs a State
rSet.Put( SfxBoolItem( nWhich, false ) );
break;
case SID_READONLY_MODE:
rSet.Put( SfxBoolItem( nWhich, GetViewData().GetDocShell()->IsReadOnly() ) );
break;
case FID_TAB_DESELECTALL:
if ( nTabSelCount == 1 )
rSet.DisableItem( nWhich ); // enabled only if several sheets are selected
break;
case FID_TOGGLEHIDDENCOLROW:
const svtools::ColorConfig& rColorCfg = SC_MOD()->GetColorConfig();
rSet.Put( SfxBoolItem( nWhich, rColorCfg.GetColorValue(svtools::CALCHIDDENROWCOL).bIsVisible) );
break;
} // switch ( nWitch )
nWhich = aIter.NextWhich();
} // while ( nWitch )
}
void ScTabViewShell::ExecuteCellFormatDlg(SfxRequest& rReq, const OUString &rName)
{
ScDocument& rDoc = GetViewData().GetDocument();
std::shared_ptr<SvxBoxItem> aLineOuter(std::make_shared<SvxBoxItem>(ATTR_BORDER));
std::shared_ptr<SvxBoxInfoItem> aLineInner(std::make_shared<SvxBoxInfoItem>(ATTR_BORDER_INNER));
const ScPatternAttr* pOldAttrs = GetSelectionPattern();
auto pOldSet = std::make_shared<SfxItemSet>(pOldAttrs->GetItemSet());
pOldSet->MergeRange(XATTR_FILLSTYLE, XATTR_FILLCOLOR);
pOldSet->MergeRange(SID_ATTR_BORDER_STYLES, SID_ATTR_BORDER_DEFAULT_WIDTH);
// We only allow these border line types.
std::vector<sal_Int32> aBorderStyles{
table::BorderLineStyle::SOLID,
table::BorderLineStyle::DOTTED,
table::BorderLineStyle::DASHED,
table::BorderLineStyle::FINE_DASHED,
table::BorderLineStyle::DASH_DOT,
table::BorderLineStyle::DASH_DOT_DOT,
table::BorderLineStyle::DOUBLE_THIN };
pOldSet->Put(SfxIntegerListItem(SID_ATTR_BORDER_STYLES, std::move(aBorderStyles)));
// Set the default border width to 0.75 points.
SfxInt64Item aBorderWidthItem(SID_ATTR_BORDER_DEFAULT_WIDTH, 75);
pOldSet->Put(aBorderWidthItem);
// Get border items and put them in the set:
GetSelectionFrame( aLineOuter, aLineInner );
//Fix border incorrect for RTL fdo#62399
if( rDoc.IsLayoutRTL( GetViewData().GetTabNo() ) )
{
std::unique_ptr<SvxBoxItem> aNewFrame(aLineOuter->Clone());
std::unique_ptr<SvxBoxInfoItem> aTempInfo(aLineInner->Clone());
if ( aLineInner->IsValid(SvxBoxInfoItemValidFlags::LEFT) )
aNewFrame->SetLine( aLineOuter->GetLeft(), SvxBoxItemLine::RIGHT );
if ( aLineInner->IsValid(SvxBoxInfoItemValidFlags::RIGHT) )
aNewFrame->SetLine( aLineOuter->GetRight(), SvxBoxItemLine::LEFT );
aLineInner->SetValid( SvxBoxInfoItemValidFlags::LEFT, aTempInfo->IsValid(SvxBoxInfoItemValidFlags::RIGHT));
aLineInner->SetValid( SvxBoxInfoItemValidFlags::RIGHT, aTempInfo->IsValid(SvxBoxInfoItemValidFlags::LEFT));
pOldSet->Put( std::move(aNewFrame) );
}
else
{
pOldSet->Put( *aLineOuter );
}
pOldSet->Put( *aLineInner );
// Generate NumberFormat Value from Value and Language and box it.
pOldSet->Put( SfxUInt32Item( ATTR_VALUE_FORMAT,
pOldAttrs->GetNumberFormat( rDoc.GetFormatTable() ) ) );
std::unique_ptr<SvxNumberInfoItem> pNumberInfoItem = MakeNumberInfoItem(rDoc, GetViewData());
pOldSet->MergeRange( SID_ATTR_NUMBERFORMAT_INFO, SID_ATTR_NUMBERFORMAT_INFO );
pOldSet->Put( std::move(pNumberInfoItem) );
bInFormatDialog = true;
ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
VclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateScAttrDlg(GetFrameWeld(), pOldSet.get()));
if (!rName.isEmpty())
pDlg->SetCurPageId(rName);
auto pRequest = std::make_shared<SfxRequest>(rReq);
rReq.Ignore(); // the 'old' request is not relevant any more
pDlg->StartExecuteAsync([pDlg, pOldSet, pRequest, this](sal_Int32 nResult){
bInFormatDialog = false;
if ( nResult == RET_OK )
{
const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
if(const SvxNumberInfoItem* pItem = pOutSet->GetItemIfSet(SID_ATTR_NUMBERFORMAT_INFO))
{
UpdateNumberFormatter(*pItem);
}
ApplyAttributes(pOutSet, pOldSet.get());
pRequest->Done(*pOutSet);
}
pDlg->disposeOnce();
});
}
bool ScTabViewShell::IsRefInputMode() const
{
ScModule* pScMod = SC_MOD();
if ( pScMod )
{
if( pScMod->IsRefDialogOpen() )
return pScMod->IsFormulaMode();
if( pScMod->IsFormulaMode() )
{
ScInputHandler* pHdl = pScMod->GetInputHdl();
if ( pHdl )
{
const ScViewData& rViewData = GetViewData();
ScDocument& rDoc = rViewData.GetDocument();
const ScAddress aPos( rViewData.GetCurPos() );
const sal_uInt32 nIndex = rDoc.GetAttr(aPos, ATTR_VALUE_FORMAT )->GetValue();
const SvNumFormatType nType = rDoc.GetFormatTable()->GetType(nIndex);
if (nType == SvNumFormatType::TEXT)
{
return false;
}
OUString aString = pHdl->GetEditString();
if ( !pHdl->GetSelIsRef() && aString.getLength() > 1 &&
( aString[0] == '+' || aString[0] == '-' ) )
{
ScCompiler aComp( rDoc, aPos, rDoc.GetGrammar() );
aComp.SetCloseBrackets( false );
std::unique_ptr<ScTokenArray> pArr(aComp.CompileString(aString));
if ( pArr && pArr->MayReferenceFollow() )
{
return true;
}
}
else
{
return true;
}
}
}
}
return false;
}
void ScTabViewShell::ExecuteInputDirect()
{
if ( !IsRefInputMode() )
{
ScModule* pScMod = SC_MOD();
if ( pScMod )
{
pScMod->InputEnterHandler();
}
}
}
void ScTabViewShell::UpdateInputHandler( bool bForce /* = sal_False */, bool bStopEditing /* = sal_True */ )
{
ScInputHandler* pHdl = mpInputHandler ? mpInputHandler.get() : SC_MOD()->GetInputHdl();
if ( pHdl )
{
OUString aString;
const EditTextObject* pObject = nullptr;
ScViewData& rViewData = GetViewData();
ScDocument& rDoc = rViewData.GetDocument();
SCCOL nPosX = rViewData.GetCurX();
SCROW nPosY = rViewData.GetCurY();
SCTAB nTab = rViewData.GetTabNo();
SCTAB nStartTab = 0;
SCTAB nEndTab = 0;
SCCOL nStartCol = 0;
SCROW nStartRow = 0;
SCCOL nEndCol = 0;
SCROW nEndRow = 0;
ScAddress aPos = rViewData.GetCurPos();
rViewData.GetSimpleArea( nStartCol, nStartRow, nStartTab,
nEndCol, nEndRow, nEndTab );
PutInOrder( nStartCol, nEndCol );
PutInOrder( nStartRow, nEndRow );
PutInOrder( nStartTab, nEndTab );
bool bHideFormula = false;
bool bHideAll = false;
if (rDoc.IsTabProtected(nTab))
{
const ScProtectionAttr* pProt = rDoc.GetAttr( nPosX,nPosY,nTab,
ATTR_PROTECTION);
bHideFormula = pProt->GetHideFormula();
bHideAll = pProt->GetHideCell();
}
if (!bHideAll)
{
ScRefCellValue rCell(rDoc, aPos);
if (rCell.getType() == CELLTYPE_FORMULA)
{
if (!bHideFormula)
aString = rCell.getFormula()->GetFormula();
}
else if (rCell.getType() == CELLTYPE_EDIT)
{
pObject = rCell.getEditText();
}
else
{
SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
sal_uInt32 nNumFmt = rDoc.GetNumberFormat( aPos );
aString = ScCellFormat::GetInputString( rCell, nNumFmt, *pFormatter, rDoc );
if (rCell.getType() == CELLTYPE_STRING)
{
// Put a ' in front if necessary, so that the string is not
// unintentionally interpreted as a number, and to show the
// user that it is a string (#35060#).
// If cell is not formatted as Text, a leading apostrophe
// needs another prepended, also '=' or '+' or '-'
// otherwise starting a formula.
// NOTE: this corresponds with
// sc/source/core/data/column3.cxx ScColumn::ParseString()
// removing one apostrophe.
// For number format Text IsNumberFormat() would never
// result in numeric anyway.
if (!pFormatter->IsTextFormat(nNumFmt) && (aString.startsWith("'")
|| aString.startsWith("=") || aString.startsWith("+") || aString.startsWith("-")
|| pFormatter->IsNumberFormat(aString, nNumFmt, o3tl::temporary(double()))))
aString = "'" + aString;
}
}
}
ScInputHdlState aState( ScAddress( nPosX, nPosY, nTab ),
ScAddress( nStartCol, nStartRow, nTab ),
ScAddress( nEndCol, nEndRow, nTab ),
aString,
pObject );
// if using the view's local input handler, this view can always be set
// as current view inside NotifyChange.
ScTabViewShell* pSourceSh = mpInputHandler ? this : nullptr;
pHdl->NotifyChange( &aState, bForce, pSourceSh, bStopEditing );
}
SfxBindings& rBindings = GetViewFrame().GetBindings();
rBindings.Invalidate( SID_STATUS_SUM ); // always together with the input row
rBindings.Invalidate( SID_ATTR_SIZE );
rBindings.Invalidate( SID_TABLE_CELL );
}
void ScTabViewShell::UpdateInputHandlerCellAdjust( SvxCellHorJustify eJust )
{
if( ScInputHandler* pHdl = mpInputHandler ? mpInputHandler.get() : SC_MOD()->GetInputHdl() )
pHdl->UpdateCellAdjust( eJust );
}
void ScTabViewShell::ExecuteSave( SfxRequest& rReq )
{
// only SID_SAVEDOC / SID_SAVEASDOC
bool bCommitChanges = true;
const SfxItemSet* pReqArgs = rReq.GetArgs();
const SfxPoolItem* pItem;
if (pReqArgs && pReqArgs->HasItem(FN_PARAM_1, &pItem))
bCommitChanges = !static_cast<const SfxBoolItem*>(pItem)->GetValue();
// Finish entering unless 'DontTerminateEdit' is specified, even if a formula is being processed
if (bCommitChanges)
{
bool bLOKActive = comphelper::LibreOfficeKit::isActive();
// Disable error dialog box when about to save in lok mode as
// this ultimately invokes SvpSalInstance::DoYield() when we want
// to save immediately without committing any erroneous input in possibly
// a cell with validation rules. After save is complete the user
// can continue editing.
SC_MOD()->InputEnterHandler(ScEnterMode::NORMAL, bLOKActive /* bBeforeSavingInLOK */);
if (bLOKActive)
{
// Normally this isn't needed, but in Calc when editing a cell formula
// and manually saving (without changing cells or hitting enter), while
// InputEnterHandler will mark the doc as modified (when it is), because
// we will save the doc immediately afterwards, the modified state event
// is clobbered. To avoid that, we need to update SID_DOC_MODIFIED so that
// a possible state of "true" after "InputEnterHandler" will be sent
// as a notification. It is important that the notification goes through
// normal process (cache) rather than directly notifying the views.
// Otherwise, because there is a previous state of "false" in cache, the
// "false" state after saving will be ignored.
// This will work only if .uno:ModifiedStatus message will be removed from
// the mechanism that keeps in the message queue only last message of
// a particular status even if the values are different.
GetViewData().GetDocShell()->GetViewBindings()->Update(SID_DOC_MODIFIED);
}
}
if ( GetViewData().GetDocShell()->IsDocShared() )
{
GetViewData().GetDocShell()->SetDocumentModified();
}
// otherwise as normal
GetViewData().GetDocShell()->ExecuteSlot( rReq );
}
void ScTabViewShell::GetSaveState( SfxItemSet& rSet )
{
SfxShell* pDocSh = GetViewData().GetDocShell();
SfxWhichIter aIter(rSet);
sal_uInt16 nWhich = aIter.FirstWhich();
while( nWhich )
{
if ( nWhich != SID_SAVEDOC || !GetViewData().GetDocShell()->IsDocShared() )
{
// get state from DocShell
pDocSh->GetSlotState( nWhich, nullptr, &rSet );
}
nWhich = aIter.NextWhich();
}
}
void ScTabViewShell::ExecDrawOpt( const SfxRequest& rReq )
{
ScViewOptions aViewOptions = GetViewData().GetOptions();
ScGridOptions aGridOptions = aViewOptions.GetGridOptions();
SfxBindings& rBindings = GetViewFrame().GetBindings();
const SfxItemSet* pArgs = rReq.GetArgs();
const SfxPoolItem* pItem;
sal_uInt16 nSlotId = rReq.GetSlot();
switch (nSlotId)
{
case SID_GRID_VISIBLE:
if ( pArgs && pArgs->GetItemState(nSlotId,true,&pItem) == SfxItemState::SET )
{
aGridOptions.SetGridVisible( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
aViewOptions.SetGridOptions(aGridOptions);
rBindings.Invalidate(SID_GRID_VISIBLE);
}
break;
case SID_GRID_USE:
if ( pArgs && pArgs->GetItemState(nSlotId,true,&pItem) == SfxItemState::SET )
{
aGridOptions.SetUseGridSnap( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
aViewOptions.SetGridOptions(aGridOptions);
rBindings.Invalidate(SID_GRID_USE);
}
break;
case SID_HELPLINES_MOVE:
if ( pArgs && pArgs->GetItemState(nSlotId,true,&pItem) == SfxItemState::SET )
{
aViewOptions.SetOption( VOPT_HELPLINES, static_cast<const SfxBoolItem*>(pItem)->GetValue() );
rBindings.Invalidate(SID_HELPLINES_MOVE);
}
break;
}
GetViewData().SetOptions(aViewOptions);
}
void ScTabViewShell::GetDrawOptState( SfxItemSet& rSet )
{
SfxBoolItem aBool;
const ScViewOptions& rViewOptions = GetViewData().GetOptions();
const ScGridOptions& rGridOptions = rViewOptions.GetGridOptions();
aBool.SetValue(rGridOptions.GetGridVisible());
aBool.SetWhich( SID_GRID_VISIBLE );
rSet.Put( aBool );
aBool.SetValue(rGridOptions.GetUseGridSnap());
aBool.SetWhich( SID_GRID_USE );
rSet.Put( aBool );
aBool.SetValue(rViewOptions.GetOption( VOPT_HELPLINES ));
aBool.SetWhich( SID_HELPLINES_MOVE );
rSet.Put( aBool );
}
void ScTabViewShell::ExecStyle( SfxRequest& rReq )
{
const SfxItemSet* pArgs = rReq.GetArgs();
const sal_uInt16 nSlotId = rReq.GetSlot();
if ( !pArgs && nSlotId != SID_STYLE_NEW_BY_EXAMPLE && nSlotId != SID_STYLE_UPDATE_BY_EXAMPLE )
{
// in case of vertical toolbar
GetDispatcher()->Execute( SID_STYLE_DESIGNER, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD );
return;
}
SfxBindings& rBindings = GetViewData().GetBindings();
const SCTAB nCurTab = GetViewData().GetTabNo();
ScDocShell* pDocSh = GetViewData().GetDocShell();
ScDocument& rDoc = pDocSh->GetDocument();
ScMarkData& rMark = GetViewData().GetMarkData();
ScModule* pScMod = SC_MOD();
SdrObject* pEditObject = GetDrawView()->GetTextEditObject();
OUString aRefName;
bool bUndo = rDoc.IsUndoEnabled();
SfxStyleSheetBasePool* pStylePool = rDoc.GetStyleSheetPool();
SfxStyleSheetBase* pStyleSheet = nullptr;
bool bStyleToMarked = false;
bool bListAction = false;
bool bAddUndo = false; // add ScUndoModifyStyle (style modified)
ScStyleSaveData aOldData; // for undo/redo
ScStyleSaveData aNewData;
SfxStyleFamily eFamily = SfxStyleFamily::Para;
const SfxUInt16Item* pFamItem;
const SfxStringItem* pFamilyNameItem;
if ( pArgs && (pFamItem = pArgs->GetItemIfSet( SID_STYLE_FAMILY )) )
eFamily = static_cast<SfxStyleFamily>(pFamItem->GetValue());
else if ( pArgs && (pFamilyNameItem = pArgs->GetItemIfSet( SID_STYLE_FAMILYNAME )) )
{
OUString sFamily = pFamilyNameItem->GetValue();
if (sFamily == "CellStyles")
eFamily = SfxStyleFamily::Para;
else if (sFamily == "PageStyles")
eFamily = SfxStyleFamily::Page;
else if (sFamily == "GraphicStyles")
eFamily = SfxStyleFamily::Frame;
}
OUString aStyleName;
sal_uInt16 nRetMask = 0xffff;
switch ( nSlotId )
{
case SID_STYLE_NEW:
{
const SfxPoolItem* pNameItem;
if (pArgs && SfxItemState::SET == pArgs->GetItemState( nSlotId, true, &pNameItem ))
aStyleName = static_cast<const SfxStringItem*>(pNameItem)->GetValue();
const SfxStringItem* pRefItem=nullptr;
if (pArgs && (pRefItem = pArgs->GetItemIfSet( SID_STYLE_REFERENCE )))
{
aRefName = pRefItem->GetValue();
}
pStyleSheet = &(pStylePool->Make( aStyleName, eFamily,
SfxStyleSearchBits::UserDefined ) );
if (pStyleSheet->HasParentSupport())
pStyleSheet->SetParent(aRefName);
}
break;
case SID_STYLE_APPLY:
{
const SfxStringItem* pNameItem = rReq.GetArg<SfxStringItem>(SID_APPLY_STYLE);
const SfxStringItem* pFamilyItem = rReq.GetArg<SfxStringItem>(SID_STYLE_FAMILYNAME);
if ( pFamilyItem && pNameItem )
{
try
{
css::uno::Reference< css::container::XNameAccess > xStyles;
css::uno::Reference< css::container::XNameAccess > xCont = pDocSh->GetModel()->getStyleFamilies();
xCont->getByName(pFamilyItem->GetValue()) >>= xStyles;
css::uno::Reference< css::beans::XPropertySet > xInfo;
xStyles->getByName( pNameItem->GetValue() ) >>= xInfo;
OUString aUIName;
xInfo->getPropertyValue("DisplayName") >>= aUIName;
if ( !aUIName.isEmpty() )
rReq.AppendItem( SfxStringItem( SID_STYLE_APPLY, aUIName ) );
}
catch( css::uno::Exception& )
{
}
}
[[fallthrough]];
}
case SID_STYLE_EDIT:
case SID_STYLE_DELETE:
case SID_STYLE_HIDE:
case SID_STYLE_SHOW:
case SID_STYLE_NEW_BY_EXAMPLE:
{
const SfxPoolItem* pNameItem;
if (pArgs && SfxItemState::SET == pArgs->GetItemState( nSlotId, true, &pNameItem ))
aStyleName = static_cast<const SfxStringItem*>(pNameItem)->GetValue();
else if ( nSlotId == SID_STYLE_NEW_BY_EXAMPLE )
{
weld::Window* pDialogParent = rReq.GetFrameWeld();
if (!pDialogParent)
pDialogParent = GetFrameWeld();
SfxNewStyleDlg aDlg(pDialogParent, *pStylePool, eFamily);
if (aDlg.run() != RET_OK)
return;
aStyleName = aDlg.GetName();
}
pStyleSheet = pStylePool->Find( aStyleName, eFamily );
aOldData.InitFromStyle( pStyleSheet );
}
break;
case SID_STYLE_WATERCAN:
{
bool bWaterCan = pScMod->GetIsWaterCan();
if( !bWaterCan )
{
const SfxPoolItem* pItem;
if ( SfxItemState::SET ==
pArgs->GetItemState( nSlotId, true, &pItem ) )
{
const SfxStringItem* pStrItem = dynamic_cast< const SfxStringItem *>( pItem );
if ( pStrItem )
{
aStyleName = pStrItem->GetValue();
pStyleSheet = pStylePool->Find( aStyleName, eFamily );
if ( pStyleSheet )
{
static_cast<ScStyleSheetPool*>(pStylePool)->
SetActualStyleSheet( pStyleSheet );
rReq.Done();
}
}
}
}
if ( !bWaterCan && pStyleSheet )
{
pScMod->SetWaterCan( true );
SetActivePointer( PointerStyle::Fill );
rReq.Done();
}
else
{
pScMod->SetWaterCan( false );
SetActivePointer( PointerStyle::Arrow );
rReq.Done();
}
}
break;
default:
break;
}
// set new style for paintbrush format mode
if ( nSlotId == SID_STYLE_APPLY && pScMod->GetIsWaterCan() && pStyleSheet )
static_cast<ScStyleSheetPool*>(pStylePool)->SetActualStyleSheet( pStyleSheet );
switch ( eFamily )
{
case SfxStyleFamily::Para:
{
switch ( nSlotId )
{
case SID_STYLE_DELETE:
{
if ( pStyleSheet )
{
RemoveStyleSheetInUse( pStyleSheet );
pStylePool->Remove( pStyleSheet );
InvalidateAttribs();
nRetMask = sal_uInt16(true);
bAddUndo = true;
rReq.Done();
}
else
nRetMask = sal_uInt16(false);
}
break;
case SID_STYLE_HIDE:
case SID_STYLE_SHOW:
{
if ( pStyleSheet )
{
pStyleSheet->SetHidden( nSlotId == SID_STYLE_HIDE );
InvalidateAttribs();
rReq.Done();
}
else
nRetMask = sal_uInt16(false);
}
break;
case SID_STYLE_APPLY:
{
if ( pStyleSheet && !pScMod->GetIsWaterCan() )
{
// apply style sheet to document
SetStyleSheetToMarked( static_cast<SfxStyleSheet*>(pStyleSheet) );
InvalidateAttribs();
rReq.Done();
}
}
break;
case SID_STYLE_NEW_BY_EXAMPLE:
case SID_STYLE_UPDATE_BY_EXAMPLE:
{
// create/replace style sheet by attributes
// at cursor position:
const ScPatternAttr* pAttrItem = nullptr;
// The query if marked, was always wrong here,
// so now no more, and just from the cursor.
// If attributes are to be removed from the selection, still need to be
// cautious not to adopt items from templates
// (GetSelectionPattern also collects items from originals) (# 44748 #)
SCCOL nCol = GetViewData().GetCurX();
SCROW nRow = GetViewData().GetCurY();
pAttrItem = rDoc.GetPattern( nCol, nRow, nCurTab );
SfxItemSet aAttrSet = pAttrItem->GetItemSet();
aAttrSet.ClearItem( ATTR_MERGE );
aAttrSet.ClearItem( ATTR_MERGE_FLAG );
// Do not adopt conditional formatting and validity,
// because they can not be edited in the template
aAttrSet.ClearItem( ATTR_VALIDDATA );
aAttrSet.ClearItem( ATTR_CONDITIONAL );
if ( SID_STYLE_NEW_BY_EXAMPLE == nSlotId )
{
if ( bUndo )
{
OUString aUndo = ScResId( STR_UNDO_EDITCELLSTYLE );
pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo, 0, GetViewShellId() );
bListAction = true;
}
bool bConvertBack = false;
SfxStyleSheet* pSheetInUse = const_cast<SfxStyleSheet*>(GetStyleSheetFromMarked());
// when a new style is present and is used in the selection,
// then the parent can not be adopted:
if ( pStyleSheet && pSheetInUse && pStyleSheet == pSheetInUse )
pSheetInUse = nullptr;
// if already present, first remove ...
if ( pStyleSheet )
{
// style pointer to names before erase,
// otherwise cells will get invalid pointer
//!!! As it happens, a method that does it for a particular style
rDoc.StylesToNames();
bConvertBack = true;
pStylePool->Remove(pStyleSheet);
}
// ...and create new
pStyleSheet = &pStylePool->Make( aStyleName, eFamily,
SfxStyleSearchBits::UserDefined );
// when a style is present, then this will become
// the parent of the new style:
if ( pSheetInUse && pStyleSheet->HasParentSupport() )
pStyleSheet->SetParent( pSheetInUse->GetName() );
if ( bConvertBack )
// Name to style pointer
rDoc.UpdStlShtPtrsFrmNms();
else
rDoc.GetPool()->CellStyleCreated( aStyleName, rDoc );
// Adopt attribute and use style
pStyleSheet->GetItemSet().Put( aAttrSet );
UpdateStyleSheetInUse( pStyleSheet );
// call SetStyleSheetToMarked after adding the ScUndoModifyStyle
// (pStyleSheet pointer is used!)
bStyleToMarked = true;
}
else // ( nSlotId == SID_STYLE_UPDATE_BY_EXAMPLE )
{
pStyleSheet = const_cast<SfxStyleSheet*>(GetStyleSheetFromMarked());
if ( pStyleSheet )
{
aOldData.InitFromStyle( pStyleSheet );
if ( bUndo )
{
OUString aUndo = ScResId( STR_UNDO_EDITCELLSTYLE );
pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo, 0, GetViewShellId() );
bListAction = true;
}
pStyleSheet->GetItemSet().Put( aAttrSet );
UpdateStyleSheetInUse( pStyleSheet );
// call SetStyleSheetToMarked after adding the ScUndoModifyStyle
// (pStyleSheet pointer is used!)
bStyleToMarked = true;
}
}
aNewData.InitFromStyle( pStyleSheet );
bAddUndo = true;
rReq.Done();
}
break;
default:
break;
}
} // case SfxStyleFamily::Para:
break;
case SfxStyleFamily::Page:
{
switch ( nSlotId )
{
case SID_STYLE_DELETE:
{
nRetMask = sal_uInt16( nullptr != pStyleSheet );
if ( pStyleSheet )
{
if ( rDoc.RemovePageStyleInUse( pStyleSheet->GetName() ) )
{
ScPrintFunc( pDocSh, GetPrinter(true), nCurTab ).UpdatePages();
rBindings.Invalidate( SID_STATUS_PAGESTYLE );
rBindings.Invalidate( FID_RESET_PRINTZOOM );
}
pStylePool->Remove( pStyleSheet );
rBindings.Invalidate( SID_STYLE_FAMILY4 );
pDocSh->SetDocumentModified();
bAddUndo = true;
rReq.Done();
}
}
break;
case SID_STYLE_HIDE:
case SID_STYLE_SHOW:
{
nRetMask = sal_uInt16( nullptr != pStyleSheet );
if ( pStyleSheet )
{
pStyleSheet->SetHidden( nSlotId == SID_STYLE_HIDE );
rBindings.Invalidate( SID_STYLE_FAMILY4 );
pDocSh->SetDocumentModified();
rReq.Done();
}
}
break;
case SID_STYLE_APPLY:
{
nRetMask = sal_uInt16( nullptr != pStyleSheet );
if ( pStyleSheet && !pScMod->GetIsWaterCan() )
{
std::unique_ptr<ScUndoApplyPageStyle> pUndoAction;
SCTAB nTabCount = rDoc.GetTableCount();
for (const auto& rTab : rMark)
{
if (rTab >= nTabCount)
break;
OUString aOldName = rDoc.GetPageStyle( rTab );
if ( aOldName != aStyleName )
{
rDoc.SetPageStyle( rTab, aStyleName );
ScPrintFunc( pDocSh, GetPrinter(true), rTab ).UpdatePages();
if( !pUndoAction )
pUndoAction.reset(new ScUndoApplyPageStyle( pDocSh, aStyleName ));
pUndoAction->AddSheetAction( rTab, aOldName );
}
}
if( pUndoAction )
{
pDocSh->GetUndoManager()->AddUndoAction( std::move(pUndoAction) );
pDocSh->SetDocumentModified();
rBindings.Invalidate( SID_STYLE_FAMILY4 );
rBindings.Invalidate( SID_STATUS_PAGESTYLE );
rBindings.Invalidate( FID_RESET_PRINTZOOM );
}
rReq.Done();
}
}
break;
case SID_STYLE_NEW_BY_EXAMPLE:
{
const OUString& rStrCurStyle = rDoc.GetPageStyle( nCurTab );
if ( rStrCurStyle != aStyleName )
{
SfxStyleSheetBase* pCurStyle = pStylePool->Find( rStrCurStyle, eFamily );
SfxItemSet aAttrSet = pCurStyle->GetItemSet();
SCTAB nInTab;
bool bUsed = rDoc.IsPageStyleInUse( aStyleName, &nInTab );
// if already present, first remove...
if ( pStyleSheet )
pStylePool->Remove( pStyleSheet );
// ...and create new
pStyleSheet = &pStylePool->Make( aStyleName, eFamily,
SfxStyleSearchBits::UserDefined );
// Adopt attribute
pStyleSheet->GetItemSet().Put( aAttrSet );
pDocSh->SetDocumentModified();
// If being used -> Update
if ( bUsed )
ScPrintFunc( pDocSh, GetPrinter(true), nInTab ).UpdatePages();
aNewData.InitFromStyle( pStyleSheet );
bAddUndo = true;
rReq.Done();
nRetMask = sal_uInt16(true);
}
}
break;
default:
break;
} // switch ( nSlotId )
} // case SfxStyleFamily::Page:
break;
case SfxStyleFamily::Frame:
{
switch ( nSlotId )
{
case SID_STYLE_DELETE:
{
if ( pStyleSheet )
{
pStylePool->Remove( pStyleSheet );
InvalidateAttribs();
pDocSh->SetDocumentModified();
nRetMask = sal_uInt16(true);
bAddUndo = true;
rReq.Done();
}
else
nRetMask = sal_uInt16(false);
}
break;
case SID_STYLE_HIDE:
case SID_STYLE_SHOW:
{
if ( pStyleSheet )
{
pStyleSheet->SetHidden( nSlotId == SID_STYLE_HIDE );
InvalidateAttribs();
rReq.Done();
}
else
nRetMask = sal_uInt16(false);
}
break;
case SID_STYLE_APPLY:
{
if ( pStyleSheet && !pScMod->GetIsWaterCan() )
{
GetScDrawView()->ScEndTextEdit();
GetScDrawView()->SetStyleSheet(static_cast<SfxStyleSheet*>(pStyleSheet), false);
GetScDrawView()->InvalidateAttribs();
InvalidateAttribs();
rReq.Done();
}
}
break;
case SID_STYLE_NEW_BY_EXAMPLE:
case SID_STYLE_UPDATE_BY_EXAMPLE:
{
if (nSlotId == SID_STYLE_NEW_BY_EXAMPLE)
{
pStyleSheet = &pStylePool->Make( aStyleName, eFamily, SfxStyleSearchBits::UserDefined );
// when a style is present, then this will become
// the parent of the new style:
if (SfxStyleSheet* pOldStyle = GetDrawView()->GetStyleSheet())
pStyleSheet->SetParent(pOldStyle->GetName());
}
else
{
pStyleSheet = GetDrawView()->GetStyleSheet();
aOldData.InitFromStyle( pStyleSheet );
}
if ( bUndo )
{
OUString aUndo = ScResId( STR_UNDO_EDITGRAPHICSTYLE );
pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo, 0, GetViewShellId() );
bListAction = true;
}
SfxItemSet aCoreSet(GetDrawView()->GetModel().GetItemPool());
GetDrawView()->GetAttributes(aCoreSet, true);
SfxItemSet* pStyleSet = &pStyleSheet->GetItemSet();
pStyleSet->Put(aCoreSet);
static_cast<SfxStyleSheet*>(pStyleSheet)->Broadcast(SfxHint(SfxHintId::DataChanged));
aNewData.InitFromStyle( pStyleSheet );
bAddUndo = true;
// call SetStyleSheet after adding the ScUndoModifyStyle
// (pStyleSheet pointer is used!)
bStyleToMarked = true;
rReq.Done();
}
break;
default:
break;
}
}
break;
default:
break;
} // switch ( eFamily )
// create new or process through Dialog:
if ( nSlotId == SID_STYLE_NEW || nSlotId == SID_STYLE_EDIT )
{
if ( pStyleSheet )
{
SfxStyleFamily eFam = pStyleSheet->GetFamily();
ScopedVclPtr<SfxAbstractTabDialog> pDlg;
bool bPage = false;
// Store old Items from the style
SfxItemSet aOldSet = pStyleSheet->GetItemSet();
OUString aOldName = pStyleSheet->GetName();
switch ( eFam )
{
case SfxStyleFamily::Page:
bPage = true;
break;
case SfxStyleFamily::Para:
{
SfxItemSet& rSet = pStyleSheet->GetItemSet();
if ( const SfxUInt32Item* pItem = rSet.GetItemIfSet( ATTR_VALUE_FORMAT,
false ) )
{
// Produce and format NumberFormat Value from Value and Language
sal_uLong nFormat = pItem->GetValue();
LanguageType eLang =
rSet.Get(ATTR_LANGUAGE_FORMAT ).GetLanguage();
sal_uLong nLangFormat = rDoc.GetFormatTable()->
GetFormatForLanguageIfBuiltIn( nFormat, eLang );
if ( nLangFormat != nFormat )
{
SfxUInt32Item aNewItem( ATTR_VALUE_FORMAT, nLangFormat );
rSet.Put( aNewItem );
aOldSet.Put( aNewItem );
// Also in aOldSet for comparison after the dialog,
// Otherwise might miss a language change
}
}
std::unique_ptr<SvxNumberInfoItem> pNumberInfoItem(
ScTabViewShell::MakeNumberInfoItem(rDoc, GetViewData()));
pDocSh->PutItem( *pNumberInfoItem );
bPage = false;
// Definitely a SvxBoxInfoItem with Table = sal_False in set:
// (If there is no item, the dialogue will also delete the
// BORDER_OUTER SvxBoxItem from the Template Set)
if ( rSet.GetItemState( ATTR_BORDER_INNER, false ) != SfxItemState::SET )
{
SvxBoxInfoItem aBoxInfoItem( ATTR_BORDER_INNER );
aBoxInfoItem.SetTable(false); // no inner lines
aBoxInfoItem.SetDist(true);
aBoxInfoItem.SetMinDist(false);
rSet.Put( aBoxInfoItem );
}
}
break;
case SfxStyleFamily::Frame:
default:
break;
}
SetInFormatDialog(true);
SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
rStyleSet.MergeRange( XATTR_FILL_FIRST, XATTR_FILL_LAST );
ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
weld::Window* pDialogParent = rReq.GetFrameWeld();
if (!pDialogParent)
pDialogParent = GetFrameWeld();
if (eFam == SfxStyleFamily::Frame)
pDlg.disposeAndReset(pFact->CreateScDrawStyleDlg(pDialogParent, *pStyleSheet, GetDrawView()));
else
pDlg.disposeAndReset(pFact->CreateScStyleDlg(pDialogParent, *pStyleSheet, bPage));
short nResult = pDlg->Execute();
SetInFormatDialog(false);
if ( nResult == RET_OK )
{
const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
if ( pOutSet )
{
nRetMask = sal_uInt16(pStyleSheet->GetMask());
// Attribute comparisons (earlier in ModifyStyleSheet) now here
// with the old values (the style is already changed)
if ( SfxStyleFamily::Para == eFam )
{
SfxItemSet& rNewSet = pStyleSheet->GetItemSet();
bool bNumFormatChanged;
if ( ScGlobal::CheckWidthInvalidate(
bNumFormatChanged, rNewSet, aOldSet ) )
rDoc.InvalidateTextWidth( nullptr, nullptr, bNumFormatChanged );
SCTAB nTabCount = rDoc.GetTableCount();
for (SCTAB nTab=0; nTab<nTabCount; nTab++)
rDoc.SetStreamValid(nTab, false);
sal_uLong nOldFormat = aOldSet.Get( ATTR_VALUE_FORMAT ).GetValue();
sal_uLong nNewFormat = rNewSet.Get( ATTR_VALUE_FORMAT ).GetValue();
if ( nNewFormat != nOldFormat )
{
SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
const SvNumberformat* pOld = pFormatter->GetEntry( nOldFormat );
const SvNumberformat* pNew = pFormatter->GetEntry( nNewFormat );
if ( pOld && pNew && pOld->GetLanguage() != pNew->GetLanguage() )
rNewSet.Put( SvxLanguageItem(
pNew->GetLanguage(), ATTR_LANGUAGE_FORMAT ) );
}
rDoc.GetPool()->CellStyleCreated( pStyleSheet->GetName(), rDoc );
}
else if ( SfxStyleFamily::Page == eFam )
{
//! Here also queries for Page Styles
OUString aNewName = pStyleSheet->GetName();
if ( aNewName != aOldName &&
rDoc.RenamePageStyleInUse( aOldName, aNewName ) )
{
rBindings.Invalidate( SID_STATUS_PAGESTYLE );
rBindings.Invalidate( FID_RESET_PRINTZOOM );
}
rDoc.ModifyStyleSheet( *pStyleSheet, *pOutSet );
rBindings.Invalidate( FID_RESET_PRINTZOOM );
}
else
{
SfxItemSet& rAttr = pStyleSheet->GetItemSet();
sdr::properties::CleanupFillProperties(rAttr);
// check for unique names of named items for xml
auto checkForUniqueItem = [&] (auto nWhichId)
{
if (auto pOldItem = rAttr.GetItemIfSet(nWhichId, false))
{
if (auto pNewItem = pOldItem->checkForUniqueItem(&GetDrawView()->GetModel()))
rAttr.Put(std::move(pNewItem));
}
};
checkForUniqueItem(XATTR_FILLBITMAP);
checkForUniqueItem(XATTR_LINEDASH);
checkForUniqueItem(XATTR_LINESTART);
checkForUniqueItem(XATTR_LINEEND);
checkForUniqueItem(XATTR_FILLGRADIENT);
checkForUniqueItem(XATTR_FILLFLOATTRANSPARENCE);
checkForUniqueItem(XATTR_FILLHATCH);
static_cast<SfxStyleSheet*>(pStyleSheet)->Broadcast(SfxHint(SfxHintId::DataChanged));
GetScDrawView()->InvalidateAttribs();
}
pDocSh->SetDocumentModified();
if ( SfxStyleFamily::Para == eFam )
{
ScTabViewShell::UpdateNumberFormatter(
*( pDocSh->GetItem(SID_ATTR_NUMBERFORMAT_INFO) ));
UpdateStyleSheetInUse( pStyleSheet );
InvalidateAttribs();
}
aNewData.InitFromStyle( pStyleSheet );
bAddUndo = true;
}
}
else
{
if ( nSlotId == SID_STYLE_NEW )
pStylePool->Remove( pStyleSheet );
else
{
// If in the meantime something was painted with the
// temporary changed item set
pDocSh->PostPaintGridAll();
}
}
}
}
rReq.SetReturnValue( SfxUInt16Item( nSlotId, nRetMask ) );
if ( bAddUndo && bUndo)
pDocSh->GetUndoManager()->AddUndoAction(
std::make_unique<ScUndoModifyStyle>( pDocSh, eFamily, aOldData, aNewData ) );
if ( bStyleToMarked )
{
// call SetStyleSheetToMarked after adding the ScUndoModifyStyle,
// so redo will find the modified style
if (eFamily == SfxStyleFamily::Para)
{
SetStyleSheetToMarked( static_cast<SfxStyleSheet*>(pStyleSheet) );
}
else if (eFamily == SfxStyleFamily::Frame)
{
GetScDrawView()->ScEndTextEdit();
GetScDrawView()->SetStyleSheet( static_cast<SfxStyleSheet*>(pStyleSheet), false );
}
InvalidateAttribs();
}
if ( bListAction )
pDocSh->GetUndoManager()->LeaveListAction();
// The above call to ScEndTextEdit left us in an inconsistent state:
// Text editing isn't active, but the text edit shell still is. And we
// couldn't just deactivate it fully, because in case of editing a
// comment, that will make the comment disappear. So let's try to
// reactivate text editing instead:
auto pFuText = dynamic_cast<FuText*>(GetDrawFuncPtr());
if (pFuText && pEditObject != GetDrawView()->GetTextEditObject())
pFuText->SetInEditMode(pEditObject);
}
void ScTabViewShell::GetStyleState( SfxItemSet& rSet )
{
ScDocument& rDoc = GetViewData().GetDocument();
SfxStyleSheetBasePool* pStylePool = rDoc.GetStyleSheetPool();
bool bProtected = false;
SCTAB nTabCount = rDoc.GetTableCount();
for (SCTAB i=0; i<nTabCount && !bProtected; i++)
if (rDoc.IsTabProtected(i)) // look after protected table
bProtected = true;
SfxWhichIter aIter(rSet);
sal_uInt16 nWhich = aIter.FirstWhich();
sal_uInt16 nSlotId = 0;
while ( nWhich )
{
nSlotId = SfxItemPool::IsWhich( nWhich )
? GetPool().GetSlotId( nWhich )
: nWhich;
switch ( nSlotId )
{
case SID_STYLE_APPLY:
if ( !pStylePool )
rSet.DisableItem( nSlotId );
break;
case SID_STYLE_FAMILY2: // cell style sheets
{
SfxStyleSheet* pStyleSheet = const_cast<SfxStyleSheet*>(GetStyleSheetFromMarked());
if ( pStyleSheet )
rSet.Put( SfxTemplateItem( nSlotId, pStyleSheet->GetName() ) );
else
rSet.Put( SfxTemplateItem( nSlotId, OUString() ) );
}
break;
case SID_STYLE_FAMILY3: // drawing style sheets
{
SfxStyleSheet* pStyleSheet = GetDrawView()->GetStyleSheet();
if ( pStyleSheet )
rSet.Put( SfxTemplateItem( nSlotId, pStyleSheet->GetName() ) );
else
rSet.Put( SfxTemplateItem( nSlotId, OUString() ) );
}
break;
case SID_STYLE_FAMILY4: // page style sheets
{
SCTAB nCurTab = GetViewData().GetTabNo();
OUString aPageStyle = rDoc.GetPageStyle( nCurTab );
SfxStyleSheet* pStyleSheet = pStylePool ? static_cast<SfxStyleSheet*>(pStylePool->
Find( aPageStyle, SfxStyleFamily::Page )) : nullptr;
if ( pStyleSheet )
rSet.Put( SfxTemplateItem( nSlotId, aPageStyle ) );
else
rSet.Put( SfxTemplateItem( nSlotId, OUString() ) );
}
break;
case SID_STYLE_WATERCAN:
{
rSet.Put( SfxBoolItem( nSlotId, SC_MOD()->GetIsWaterCan() ) );
}
break;
case SID_STYLE_UPDATE_BY_EXAMPLE:
{
std::unique_ptr<SfxUInt16Item> pFamilyItem;
GetViewFrame().GetBindings().QueryState(SID_STYLE_FAMILY, pFamilyItem);
bool bPage = pFamilyItem && SfxStyleFamily::Page == static_cast<SfxStyleFamily>(pFamilyItem->GetValue());
if ( bProtected || bPage )
rSet.DisableItem( nSlotId );
}
break;
case SID_STYLE_EDIT:
case SID_STYLE_DELETE:
case SID_STYLE_HIDE:
case SID_STYLE_SHOW:
{
std::unique_ptr<SfxUInt16Item> pFamilyItem;
GetViewFrame().GetBindings().QueryState(SID_STYLE_FAMILY, pFamilyItem);
bool bPage = pFamilyItem && SfxStyleFamily::Page == static_cast<SfxStyleFamily>(pFamilyItem->GetValue());
if ( bProtected && !bPage )
rSet.DisableItem( nSlotId );
}
break;
default:
break;
}
nWhich = aIter.NextWhich();
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|