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
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#define _BIGINT_HXX
#define _CACHESTR_HXX
#define _CONFIG_HXX
#define _CURSOR_HXX
#define _CTRLTOOL_HXX
#define _MACRODLG_HXX
#define _OUTLINER_HXX
#define _RULER_HXX
#define _SCRWIN_HXX
#define _STDCTRL_HXX
#define _STDMENU_HXX
#define _TABBAR_HXX
#define _VALUESET_HXX
#define _PASSWD_HXX
#define _SFX_PRNMON_HXX
#define _SFX_RESMGR_HXX
#define _SFX_TEMPLDLG_HXX
#define _SFXBASIC_HXX
#define _SFXCTRLITEM
#define _SFXMNUITEM_HXX
#define _SFXMNUMGR_HXX
#define _SFXMSGPOOL_HXX
#define _SFX_MINFITEM_HXX
#define _SFXOBJFACE_HXX
#define _SFXSTBITEM_HXX
#define _SFXTBXCTRL_HXX
#define _SVTABBX_HXX
#define _SVTREEBOX_HXX
#define _SVTREELIST_HXX
#define _SVX_HYPHEN_HXX
#define _SVX_LAYCTRL_HXX
#define _SVX_OPTSAVE_HXX
#define _SVX_OPTPATH_HXX
#define _SVX_OPTLINGU_HXX
#define _SVX_RULER_HXX
#define _SVX_RULRITEM_HXX
#define _SVX_SELCTRL_HXX
#define _SVX_SPLWRAP_HXX
#define _SVX_STDDLG_HXX
#define _SVX_THESDLG_HXX
#include "scitems.hxx"
#include <svx/svdetc.hxx>
#include <svx/svditer.hxx>
#include <svx/svdoole2.hxx>
#include <svx/svdpage.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/docfile.hxx>
#include <svl/stritem.hxx>
#include <svl/ptitem.hxx>
#include <svl/urlbmk.hxx>
#include <sot/clsids.hxx>
#include <sot/formats.hxx>
#include <vcl/graph.hxx>
#include <vcl/virdev.hxx>
#include <vcl/msgbox.hxx>
#include <tools/urlobj.hxx>
#include <sot/exchange.hxx>
#include <memory>
#include "attrib.hxx"
#include "patattr.hxx"
#include "dociter.hxx"
#include "viewfunc.hxx"
#include "tabvwsh.hxx"
#include "docsh.hxx"
#include "docfunc.hxx"
#include "undoblk.hxx"
#include "refundo.hxx"
#include "globstr.hrc"
#include "global.hxx"
#include "transobj.hxx"
#include "drwtrans.hxx"
#include "rangenam.hxx"
#include "dbdata.hxx"
#include "impex.hxx" // Sylk-ID fuer CB
#include "chgtrack.hxx"
#include "waitoff.hxx"
#include "scmod.hxx"
#include "sc.hrc"
#include "inputopt.hxx"
#include "warnbox.hxx"
#include "drwlayer.hxx"
#include "editable.hxx"
#include "docuno.hxx"
#include "clipparam.hxx"
#include "undodat.hxx"
#include "drawview.hxx"
#include "cliputil.hxx"
using namespace com::sun::star;
// STATIC DATA ---------------------------------------------------------------
//============================================================================
// GlobalName der Writer-DocShell kommt jetzt aus comphelper/classids.hxx
//----------------------------------------------------------------------------
// C U T
void ScViewFunc::CutToClip( ScDocument* pClipDoc, sal_Bool bIncludeObjects )
{
UpdateInputLine();
ScEditableTester aTester( this );
if (!aTester.IsEditable()) // selection editable?
{
ErrorMessage( aTester.GetMessageId() );
return;
}
ScRange aRange; // zu loeschender Bereich
if ( GetViewData()->GetSimpleArea( aRange ) == SC_MARK_SIMPLE )
{
ScDocument* pDoc = GetViewData()->GetDocument();
ScDocShell* pDocSh = GetViewData()->GetDocShell();
ScMarkData& rMark = GetViewData()->GetMarkData();
const sal_Bool bRecord(pDoc->IsUndoEnabled()); // Undo/Redo
ScDocShellModificator aModificator( *pDocSh );
if ( !rMark.IsMarked() && !rMark.IsMultiMarked() ) // mark the range if not marked yet
{
DoneBlockMode();
InitOwnBlockMode();
rMark.SetMarkArea( aRange );
MarkDataChanged();
}
CopyToClip( pClipDoc, sal_True, false, bIncludeObjects ); // Ab ins Clipboard
ScAddress aOldEnd( aRange.aEnd ); // Zusammengefasste Zellen im Bereich?
pDoc->ExtendMerge( aRange, sal_True );
ScDocument* pUndoDoc = NULL;
if ( bRecord )
{
pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
pUndoDoc->InitUndoSelected( pDoc, rMark );
// all sheets - CopyToDocument skips those that don't exist in pUndoDoc
ScRange aCopyRange = aRange;
aCopyRange.aStart.SetTab(0);
aCopyRange.aEnd.SetTab(pDoc->GetTableCount()-1);
pDoc->CopyToDocument( aCopyRange, (IDF_ALL & ~IDF_OBJECTS) | IDF_NOCAPTIONS, false, pUndoDoc );
pDoc->BeginDrawUndo();
}
sal_uInt16 nExtFlags = 0;
pDocSh->UpdatePaintExt( nExtFlags, aRange );
rMark.MarkToMulti();
pDoc->DeleteSelection( IDF_ALL, rMark );
if ( bIncludeObjects )
pDoc->DeleteObjectsInSelection( rMark );
rMark.MarkToSimple();
if ( !AdjustRowHeight( aRange.aStart.Row(), aRange.aEnd.Row() ) )
pDocSh->PostPaint( aRange, PAINT_GRID, nExtFlags );
if ( bRecord ) // erst jetzt ist Draw-Undo verfuegbar
pDocSh->GetUndoManager()->AddUndoAction(
new ScUndoCut( pDocSh, aRange, aOldEnd, rMark, pUndoDoc ) );
aModificator.SetDocumentModified();
pDocSh->UpdateOle(GetViewData());
CellContentChanged();
}
else
ErrorMessage( STR_NOMULTISELECT );
}
//----------------------------------------------------------------------------
// C O P Y
sal_Bool ScViewFunc::CopyToClip( ScDocument* pClipDoc, sal_Bool bCut, sal_Bool bApi, sal_Bool bIncludeObjects, sal_Bool bStopEdit )
{
ScRange aRange;
ScMarkType eMarkType = GetViewData()->GetSimpleArea( aRange );
ScMarkData& rMark = GetViewData()->GetMarkData();
sal_Bool bDone = sal_False;
if ( eMarkType == SC_MARK_SIMPLE || eMarkType == SC_MARK_SIMPLE_FILTERED )
{
ScRangeList aRangeList;
aRangeList.Append( aRange );
bDone = CopyToClip( pClipDoc, aRangeList, bCut, bApi, bIncludeObjects, bStopEdit, sal_False );
}
else if (eMarkType == SC_MARK_MULTI)
{
ScRangeList aRangeList;
rMark.MarkToSimple();
rMark.FillRangeListWithMarks(&aRangeList, false);
bDone = CopyToClip( pClipDoc, aRangeList, bCut, bApi, bIncludeObjects, bStopEdit, sal_False );
}
else
{
if (!bApi)
ErrorMessage(STR_NOMULTISELECT);
}
return bDone;
}
// Copy the content of the Range into clipboard.
sal_Bool ScViewFunc::CopyToClip( ScDocument* pClipDoc, const ScRangeList& rRanges, sal_Bool bCut, sal_Bool bApi, sal_Bool bIncludeObjects, sal_Bool bStopEdit, sal_Bool bUseRangeForVBA )
{
if ( rRanges.empty() )
return false;
sal_Bool bDone = false;
if ( bStopEdit )
UpdateInputLine();
ScRange aRange = *rRanges[0];
ScClipParam aClipParam( aRange, bCut );
aClipParam.maRanges = rRanges;
ScDocument* pDoc = GetViewData()->GetDocument();
ScMarkData& rMark = GetViewData()->GetMarkData();
if ( !aClipParam.isMultiRange() )
{
if ( pDoc && ( !pDoc->HasSelectedBlockMatrixFragment( aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aEnd.Row(), rMark ) ) )
{
sal_Bool bSysClip = false;
if ( !pClipDoc ) // no clip doc specified
{
// Create one (deleted by ScTransferObj).
pClipDoc = new ScDocument( SCDOCMODE_CLIP );
bSysClip = sal_True; // and copy into system
}
if ( !bCut )
{
ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
if ( pChangeTrack )
pChangeTrack->ResetLastCut();
}
if ( bSysClip && bIncludeObjects )
{
sal_Bool bAnyOle = pDoc->HasOLEObjectsInArea( aRange );
// Update ScGlobal::pDrawClipDocShellRef.
ScDrawLayer::SetGlobalDrawPersist( ScTransferObj::SetDrawClipDoc( bAnyOle ) );
}
if ( !bUseRangeForVBA )
// is this necessary?, will setting the doc id upset the
// following paste operation with range? would be nicer to just set this always
// and lose the 'if' above
aClipParam.setSourceDocID( pDoc->GetDocumentID() );
pDoc->CopyToClip( aClipParam, pClipDoc, &rMark, false, false, bIncludeObjects, true, bUseRangeForVBA );
if ( !bUseRangeForVBA && pDoc && pClipDoc )
{
ScDrawLayer* pDrawLayer = pClipDoc->GetDrawLayer();
if ( pDrawLayer )
{
ScClipParam& rClipParam = pClipDoc->GetClipParam();
ScRangeListVector& rRangesVector = rClipParam.maProtectedChartRangesVector;
SCTAB nTabCount = pClipDoc->GetTableCount();
for ( SCTAB nTab = 0; nTab < nTabCount; ++nTab )
{
SdrPage* pPage = pDrawLayer->GetPage( static_cast< sal_uInt16 >( nTab ) );
if ( pPage )
{
ScChartHelper::FillProtectedChartRangesVector( rRangesVector, pDoc, pPage );
}
}
}
}
if ( bSysClip )
{
ScDrawLayer::SetGlobalDrawPersist(NULL);
ScGlobal::SetClipDocName( pDoc->GetDocumentShell()->GetTitle( SFX_TITLE_FULLNAME ) );
}
pClipDoc->ExtendMerge( aRange, true );
if ( bSysClip )
{
ScDocShell* pDocSh = GetViewData()->GetDocShell();
TransferableObjectDescriptor aObjDesc;
pDocSh->FillTransferableObjectDescriptor( aObjDesc );
aObjDesc.maDisplayName = pDocSh->GetMedium()->GetURLObject().GetURLNoPass();
// maSize is set in ScTransferObj ctor
ScTransferObj* pTransferObj = new ScTransferObj( pClipDoc, aObjDesc );
uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj );
if ( ScGlobal::pDrawClipDocShellRef )
{
SfxObjectShellRef aPersistRef( &(*ScGlobal::pDrawClipDocShellRef) );
pTransferObj->SetDrawPersist( aPersistRef );// keep persist for ole objects alive
}
pTransferObj->CopyToClipboard( GetActiveWin() );
SC_MOD()->SetClipObject( pTransferObj, NULL );
}
bDone = true;
}
}
else
{
bool bSuccess = false;
aClipParam.mbCutMode = false;
do
{
if (bCut)
// We con't support cutting of multi-selections.
break;
if (pClipDoc)
// TODO: What's this for?
break;
SAL_WNODEPRECATED_DECLARATIONS_PUSH
::std::auto_ptr<ScDocument> pDocClip(new ScDocument(SCDOCMODE_CLIP));
SAL_WNODEPRECATED_DECLARATIONS_POP
// Check for geometrical feasibility of the ranges.
bool bValidRanges = true;
ScRange* p = aClipParam.maRanges.front();
SCCOL nPrevColDelta = 0;
SCROW nPrevRowDelta = 0;
SCCOL nPrevCol = p->aStart.Col();
SCROW nPrevRow = p->aStart.Row();
SCCOL nPrevColSize = p->aEnd.Col() - p->aStart.Col() + 1;
SCROW nPrevRowSize = p->aEnd.Row() - p->aStart.Row() + 1;
for ( size_t i = 1; i < aClipParam.maRanges.size(); ++i )
{
p = aClipParam.maRanges[i];
if ( pDoc->HasSelectedBlockMatrixFragment(
p->aStart.Col(), p->aStart.Row(), p->aEnd.Col(), p->aEnd.Row(), rMark) )
{
if (!bApi)
ErrorMessage(STR_MATRIXFRAGMENTERR);
return false;
}
SCCOL nColDelta = p->aStart.Col() - nPrevCol;
SCROW nRowDelta = p->aStart.Row() - nPrevRow;
if ((nColDelta && nRowDelta) || (nPrevColDelta && nRowDelta) || (nPrevRowDelta && nColDelta))
{
bValidRanges = false;
break;
}
if (aClipParam.meDirection == ScClipParam::Unspecified)
{
if (nColDelta)
aClipParam.meDirection = ScClipParam::Column;
if (nRowDelta)
aClipParam.meDirection = ScClipParam::Row;
}
SCCOL nColSize = p->aEnd.Col() - p->aStart.Col() + 1;
SCROW nRowSize = p->aEnd.Row() - p->aStart.Row() + 1;
if (aClipParam.meDirection == ScClipParam::Column && nRowSize != nPrevRowSize)
{
// column-oriented ranges must have identical row size.
bValidRanges = false;
break;
}
if (aClipParam.meDirection == ScClipParam::Row && nColSize != nPrevColSize)
{
// likewise, row-oriented ranges must have identical
// column size.
bValidRanges = false;
break;
}
nPrevCol = p->aStart.Col();
nPrevRow = p->aStart.Row();
nPrevColDelta = nColDelta;
nPrevRowDelta = nRowDelta;
nPrevColSize = nColSize;
nPrevRowSize = nRowSize;
}
if (!bValidRanges)
break;
pDoc->CopyToClip(aClipParam, pDocClip.get(), &rMark, false, false, bIncludeObjects, true, bUseRangeForVBA );
ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
if ( pChangeTrack )
pChangeTrack->ResetLastCut(); // kein CutMode mehr
{
ScDocShell* pDocSh = GetViewData()->GetDocShell();
TransferableObjectDescriptor aObjDesc;
pDocSh->FillTransferableObjectDescriptor( aObjDesc );
aObjDesc.maDisplayName = pDocSh->GetMedium()->GetURLObject().GetURLNoPass();
// maSize is set in ScTransferObj ctor
ScTransferObj* pTransferObj = new ScTransferObj( pDocClip.release(), aObjDesc );
uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj );
if ( ScGlobal::pDrawClipDocShellRef )
{
SfxObjectShellRef aPersistRef( &(*ScGlobal::pDrawClipDocShellRef) );
pTransferObj->SetDrawPersist( aPersistRef ); // keep persist for ole objects alive
}
pTransferObj->CopyToClipboard( GetActiveWin() ); // system clipboard
SC_MOD()->SetClipObject( pTransferObj, NULL ); // internal clipboard
}
bSuccess = true;
}
while (false);
if (!bSuccess && !bApi)
ErrorMessage(STR_NOMULTISELECT);
bDone = bSuccess;
}
return bDone;
}
ScTransferObj* ScViewFunc::CopyToTransferable()
{
ScRange aRange;
if ( GetViewData()->GetSimpleArea( aRange ) == SC_MARK_SIMPLE )
{
ScDocument* pDoc = GetViewData()->GetDocument();
ScMarkData& rMark = GetViewData()->GetMarkData();
if ( !pDoc->HasSelectedBlockMatrixFragment(
aRange.aStart.Col(), aRange.aStart.Row(),
aRange.aEnd.Col(), aRange.aEnd.Row(),
rMark ) )
{
ScDocument *pClipDoc = new ScDocument( SCDOCMODE_CLIP ); // create one (deleted by ScTransferObj)
sal_Bool bAnyOle = pDoc->HasOLEObjectsInArea( aRange, &rMark );
ScDrawLayer::SetGlobalDrawPersist( ScTransferObj::SetDrawClipDoc( bAnyOle ) );
ScClipParam aClipParam(aRange, false);
pDoc->CopyToClip(aClipParam, pClipDoc, &rMark, false, false, true);
ScDrawLayer::SetGlobalDrawPersist(NULL);
pClipDoc->ExtendMerge( aRange, sal_True );
ScDocShell* pDocSh = GetViewData()->GetDocShell();
TransferableObjectDescriptor aObjDesc;
pDocSh->FillTransferableObjectDescriptor( aObjDesc );
aObjDesc.maDisplayName = pDocSh->GetMedium()->GetURLObject().GetURLNoPass();
ScTransferObj* pTransferObj = new ScTransferObj( pClipDoc, aObjDesc );
return pTransferObj;
}
}
return NULL;
}
//----------------------------------------------------------------------------
// P A S T E
void ScViewFunc::PasteDraw()
{
ScViewData* pViewData = GetViewData();
SCCOL nPosX = pViewData->GetCurX();
SCROW nPosY = pViewData->GetCurY();
Window* pWin = GetActiveWin();
Point aPos = pWin->PixelToLogic( pViewData->GetScrPos( nPosX, nPosY,
pViewData->GetActivePart() ) );
ScDrawTransferObj* pDrawClip = ScDrawTransferObj::GetOwnClipboard( pWin );
if (pDrawClip)
PasteDraw( aPos, pDrawClip->GetModel(), false,
pDrawClip->GetSourceDocID() == pViewData->GetDocument()->GetDocumentID() );
}
void ScViewFunc::PasteFromSystem()
{
UpdateInputLine();
Window* pWin = GetActiveWin();
ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard( pWin );
ScDrawTransferObj* pDrawClip = ScDrawTransferObj::GetOwnClipboard( pWin );
if (pOwnClip)
{
// keep a reference in case the clipboard is changed during PasteFromClip
uno::Reference<datatransfer::XTransferable> aOwnClipRef( pOwnClip );
PasteFromClip( IDF_ALL, pOwnClip->GetDocument(),
PASTE_NOFUNC, false, false, false, INS_NONE, IDF_NONE,
sal_True ); // allow warning dialog
}
else if (pDrawClip)
PasteDraw();
else
{
TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pWin ) );
{
sal_uLong nBiff8 = SotExchange::RegisterFormatName(rtl::OUString("Biff8"));
sal_uLong nBiff5 = SotExchange::RegisterFormatName(rtl::OUString("Biff5"));
// als erstes SvDraw-Model, dann Grafik
// (Grafik darf nur bei einzelner Grafik drinstehen)
if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_DRAWING ))
{
// special case for tables from drawing
if( aDataHelper.HasFormat( SOT_FORMAT_RTF ) )
{
PasteFromSystem( FORMAT_RTF );
}
else
{
PasteFromSystem( SOT_FORMATSTR_ID_DRAWING );
}
}
else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVXB ))
PasteFromSystem( SOT_FORMATSTR_ID_SVXB );
else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBED_SOURCE ))
{
// If it's a Writer object, insert RTF instead of OLE
// Else, if the class id is all-zero, and SYLK is available,
// it probably is spreadsheet cells that have been put
// on the clipboard by OOo, so use the SYLK. (fdo#31077)
sal_Bool bDoRtf = false;
TransferableObjectDescriptor aObjDesc;
if( aDataHelper.GetTransferableObjectDescriptor( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aObjDesc ) )
{
bDoRtf = ( ( aObjDesc.maClassName == SvGlobalName( SO3_SW_CLASSID ) ||
aObjDesc.maClassName == SvGlobalName( SO3_SWWEB_CLASSID ) )
&& aDataHelper.HasFormat( SOT_FORMAT_RTF ) );
}
if ( bDoRtf )
PasteFromSystem( FORMAT_RTF );
else if ( aObjDesc.maClassName == SvGlobalName( 0,0,0,0,0,0,0,0,0,0,0 )
&& aDataHelper.HasFormat( SOT_FORMATSTR_ID_SYLK ))
PasteFromSystem( SOT_FORMATSTR_ID_SYLK );
else
PasteFromSystem( SOT_FORMATSTR_ID_EMBED_SOURCE );
}
else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_LINK_SOURCE ))
PasteFromSystem( SOT_FORMATSTR_ID_LINK_SOURCE );
// the following format can not affect scenario from #89579#
else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE ))
PasteFromSystem( SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE );
// FORMAT_PRIVATE no longer here (can't work if pOwnClip is NULL)
else if (aDataHelper.HasFormat(nBiff8)) // before xxx_OLE formats
PasteFromSystem(nBiff8);
else if (aDataHelper.HasFormat(nBiff5))
PasteFromSystem(nBiff5);
else if (aDataHelper.HasFormat(FORMAT_RTF))
PasteFromSystem(FORMAT_RTF);
else if (aDataHelper.HasFormat(SOT_FORMATSTR_ID_HTML))
PasteFromSystem(SOT_FORMATSTR_ID_HTML);
else if (aDataHelper.HasFormat(SOT_FORMATSTR_ID_HTML_SIMPLE))
PasteFromSystem(SOT_FORMATSTR_ID_HTML_SIMPLE);
else if (aDataHelper.HasFormat(SOT_FORMATSTR_ID_SYLK))
PasteFromSystem(SOT_FORMATSTR_ID_SYLK);
else if (aDataHelper.HasFormat(FORMAT_STRING))
PasteFromSystem(FORMAT_STRING);
else if (aDataHelper.HasFormat(FORMAT_GDIMETAFILE))
PasteFromSystem(FORMAT_GDIMETAFILE);
else if (aDataHelper.HasFormat(FORMAT_BITMAP))
PasteFromSystem(FORMAT_BITMAP);
// xxx_OLE formats come last, like in SotExchange tables
else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBED_SOURCE_OLE ))
PasteFromSystem( SOT_FORMATSTR_ID_EMBED_SOURCE_OLE );
else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_LINK_SOURCE_OLE ))
PasteFromSystem( SOT_FORMATSTR_ID_LINK_SOURCE_OLE );
}
}
// keine Fehlermeldung, weil SID_PASTE in der idl das FastCall-Flag hat,
// also auch gerufen wird, wenn nichts im Clipboard steht (#42531#)
}
void ScViewFunc::PasteFromTransferable( const uno::Reference<datatransfer::XTransferable>& rxTransferable )
{
ScTransferObj *pOwnClip=0;
ScDrawTransferObj *pDrawClip=0;
uno::Reference<lang::XUnoTunnel> xTunnel( rxTransferable, uno::UNO_QUERY );
if ( xTunnel.is() )
{
sal_Int64 nHandle = xTunnel->getSomething( ScTransferObj::getUnoTunnelId() );
if ( nHandle )
pOwnClip = (ScTransferObj*) (sal_IntPtr) nHandle;
else
{
nHandle = xTunnel->getSomething( ScDrawTransferObj::getUnoTunnelId() );
if ( nHandle )
pDrawClip = (ScDrawTransferObj*) (sal_IntPtr) nHandle;
}
}
if (pOwnClip)
{
PasteFromClip( IDF_ALL, pOwnClip->GetDocument(),
PASTE_NOFUNC, false, false, false, INS_NONE, IDF_NONE,
sal_True ); // allow warning dialog
}
else if (pDrawClip)
{
ScViewData* pViewData = GetViewData();
SCCOL nPosX = pViewData->GetCurX();
SCROW nPosY = pViewData->GetCurY();
Window* pWin = GetActiveWin();
Point aPos = pWin->PixelToLogic( pViewData->GetScrPos( nPosX, nPosY, pViewData->GetActivePart() ) );
PasteDraw( aPos, pDrawClip->GetModel(), false, pDrawClip->GetSourceDocID() == pViewData->GetDocument()->GetDocumentID() );
}
else
{
TransferableDataHelper aDataHelper( rxTransferable );
{
sal_uLong nBiff8 = SotExchange::RegisterFormatName(rtl::OUString("Biff8"));
sal_uLong nBiff5 = SotExchange::RegisterFormatName(rtl::OUString("Biff5"));
sal_uLong nFormatId = 0;
// als erstes SvDraw-Model, dann Grafik
// (Grafik darf nur bei einzelner Grafik drinstehen)
if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_DRAWING ))
nFormatId = SOT_FORMATSTR_ID_DRAWING;
else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVXB ))
nFormatId = SOT_FORMATSTR_ID_SVXB;
else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBED_SOURCE ))
{
// If it's a Writer object, insert RTF instead of OLE
sal_Bool bDoRtf = false;
TransferableObjectDescriptor aObjDesc;
if( aDataHelper.GetTransferableObjectDescriptor( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aObjDesc ) )
{
bDoRtf = ( ( aObjDesc.maClassName == SvGlobalName( SO3_SW_CLASSID ) ||
aObjDesc.maClassName == SvGlobalName( SO3_SWWEB_CLASSID ) )
&& aDataHelper.HasFormat( SOT_FORMAT_RTF ) );
}
if ( bDoRtf )
nFormatId = FORMAT_RTF;
else
nFormatId = SOT_FORMATSTR_ID_EMBED_SOURCE;
}
else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_LINK_SOURCE ))
nFormatId = SOT_FORMATSTR_ID_LINK_SOURCE;
// the following format can not affect scenario from #89579#
else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE ))
nFormatId = SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE;
// FORMAT_PRIVATE no longer here (can't work if pOwnClip is NULL)
else if (aDataHelper.HasFormat(nBiff8)) // before xxx_OLE formats
nFormatId = nBiff8;
else if (aDataHelper.HasFormat(nBiff5))
nFormatId = nBiff5;
else if (aDataHelper.HasFormat(FORMAT_RTF))
nFormatId = FORMAT_RTF;
else if (aDataHelper.HasFormat(SOT_FORMATSTR_ID_HTML))
nFormatId = SOT_FORMATSTR_ID_HTML;
else if (aDataHelper.HasFormat(SOT_FORMATSTR_ID_HTML_SIMPLE))
nFormatId = SOT_FORMATSTR_ID_HTML_SIMPLE;
else if (aDataHelper.HasFormat(SOT_FORMATSTR_ID_SYLK))
nFormatId = SOT_FORMATSTR_ID_SYLK;
else if (aDataHelper.HasFormat(FORMAT_STRING))
nFormatId = FORMAT_STRING;
else if (aDataHelper.HasFormat(FORMAT_GDIMETAFILE))
nFormatId = FORMAT_GDIMETAFILE;
else if (aDataHelper.HasFormat(FORMAT_BITMAP))
nFormatId = FORMAT_BITMAP;
// xxx_OLE formats come last, like in SotExchange tables
else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBED_SOURCE_OLE ))
nFormatId = SOT_FORMATSTR_ID_EMBED_SOURCE_OLE;
else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_LINK_SOURCE_OLE ))
nFormatId = SOT_FORMATSTR_ID_LINK_SOURCE_OLE;
else
return;
PasteDataFormat( nFormatId, aDataHelper.GetTransferable(),
GetViewData()->GetCurX(), GetViewData()->GetCurY(),
NULL, false, false );
}
}
}
sal_Bool ScViewFunc::PasteFromSystem( sal_uLong nFormatId, sal_Bool bApi )
{
UpdateInputLine();
sal_Bool bRet = sal_True;
Window* pWin = GetActiveWin();
ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard( pWin );
if ( nFormatId == 0 && pOwnClip )
{
// keep a reference in case the clipboard is changed during PasteFromClip
uno::Reference<datatransfer::XTransferable> aOwnClipRef( pOwnClip );
PasteFromClip( IDF_ALL, pOwnClip->GetDocument(),
PASTE_NOFUNC, false, false, false, INS_NONE, IDF_NONE,
!bApi ); // allow warning dialog
}
else
{
TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pWin ) );
if ( !aDataHelper.GetTransferable().is() )
return false;
bRet = PasteDataFormat( nFormatId, aDataHelper.GetTransferable(),
GetViewData()->GetCurX(), GetViewData()->GetCurY(),
NULL, false, !bApi ); // allow warning dialog
if ( !bRet && !bApi )
ErrorMessage(STR_PASTE_ERROR);
}
return bRet;
}
//----------------------------------------------------------------------------
// P A S T E
sal_Bool ScViewFunc::PasteOnDrawObject( const uno::Reference<datatransfer::XTransferable>& rxTransferable,
SdrObject* pHitObj, sal_Bool bLink )
{
sal_Bool bRet = false;
if ( bLink )
{
TransferableDataHelper aDataHelper( rxTransferable );
if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVXB ) )
{
SotStorageStreamRef xStm;
if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_SVXB, xStm ) )
{
Graphic aGraphic;
*xStm >> aGraphic;
bRet = ApplyGraphicToObject( pHitObj, aGraphic );
}
}
else if ( aDataHelper.HasFormat( SOT_FORMAT_GDIMETAFILE ) )
{
GDIMetaFile aMtf;
if( aDataHelper.GetGDIMetaFile( FORMAT_GDIMETAFILE, aMtf ) )
bRet = ApplyGraphicToObject( pHitObj, Graphic(aMtf) );
}
else if ( aDataHelper.HasFormat( SOT_FORMAT_BITMAP ) )
{
Bitmap aBmp;
if( aDataHelper.GetBitmap( FORMAT_BITMAP, aBmp ) )
bRet = ApplyGraphicToObject( pHitObj, Graphic(aBmp) );
}
}
else
{
// ham' wa noch nich
}
return bRet;
}
static sal_Bool lcl_SelHasAttrib( ScDocument* pDoc, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
const ScMarkData& rTabSelection, sal_uInt16 nMask )
{
ScMarkData::const_iterator itr = rTabSelection.begin(), itrEnd = rTabSelection.end();
for (; itr != itrEnd; ++itr)
if ( pDoc->HasAttrib( nCol1, nRow1, *itr, nCol2, nRow2, *itr, nMask ) )
return sal_True;
return false;
}
//
// Einfuegen auf Tabelle:
//
// internes Paste
namespace {
bool checkDestRangeForOverwrite(const ScRangeList& rDestRanges, const ScDocument* pDoc, const ScMarkData& rMark, Window* pParentWnd)
{
bool bIsEmpty = true;
ScMarkData::const_iterator itrTab = rMark.begin(), itrTabEnd = rMark.end();
size_t nRangeSize = rDestRanges.size();
for (; itrTab != itrTabEnd && bIsEmpty; ++itrTab)
{
for (size_t i = 0; i < nRangeSize && bIsEmpty; ++i)
{
const ScRange& rRange = *rDestRanges[i];
bIsEmpty = pDoc->IsBlockEmpty(
*itrTab, rRange.aStart.Col(), rRange.aStart.Row(),
rRange.aEnd.Col(), rRange.aEnd.Row());
}
}
if (!bIsEmpty)
{
ScReplaceWarnBox aBox(pParentWnd);
if (aBox.Execute() != RET_YES)
{
// changing the configuration is within the ScReplaceWarnBox
return false;
}
}
return true;
}
}
bool ScViewFunc::PasteFromClip( sal_uInt16 nFlags, ScDocument* pClipDoc,
sal_uInt16 nFunction, bool bSkipEmpty,
bool bTranspose, bool bAsLink,
InsCellCmd eMoveMode, sal_uInt16 nUndoExtraFlags,
bool bAllowDialogs )
{
if (!pClipDoc)
{
OSL_FAIL("PasteFromClip: pClipDoc=0 not allowed");
return false;
}
// fuer Undo etc. immer alle oder keine Inhalte sichern
sal_uInt16 nContFlags = IDF_NONE;
if (nFlags & IDF_CONTENTS)
nContFlags |= IDF_CONTENTS;
if (nFlags & IDF_ATTRIB)
nContFlags |= IDF_ATTRIB;
// evtl. Attribute ins Undo ohne sie vom Clip ins Doc zu kopieren
sal_uInt16 nUndoFlags = nContFlags;
if (nUndoExtraFlags & IDF_ATTRIB)
nUndoFlags |= IDF_ATTRIB;
// do not copy note captions into undo document
nUndoFlags |= IDF_NOCAPTIONS;
ScClipParam& rClipParam = pClipDoc->GetClipParam();
if (rClipParam.isMultiRange())
{
// Source data is multi-range.
return PasteMultiRangesFromClip(
nFlags, pClipDoc, nFunction, bSkipEmpty, bTranspose, bAsLink, bAllowDialogs,
eMoveMode, nUndoFlags);
}
ScMarkData& rMark = GetViewData()->GetMarkData();
if (rMark.IsMultiMarked())
{
// Source data is single-range but destination is multi-range.
return PasteFromClipToMultiRanges(
nFlags, pClipDoc, nFunction, bSkipEmpty, bTranspose, bAsLink, bAllowDialogs,
eMoveMode, nUndoFlags);
}
bool bCutMode = pClipDoc->IsCutMode(); // if transposing, take from original clipdoc
bool bIncludeFiltered = bCutMode;
// paste drawing: also if IDF_NOTE is set (to create drawing layer for note captions)
bool bPasteDraw = ( pClipDoc->GetDrawLayer() && ( nFlags & (IDF_OBJECTS|IDF_NOTE) ) );
ScDocShellRef aTransShellRef; // for objects in xTransClip - must remain valid as long as xTransClip
ScDocument* pOrigClipDoc = NULL;
SAL_WNODEPRECATED_DECLARATIONS_PUSH
::std::auto_ptr< ScDocument > xTransClip;
SAL_WNODEPRECATED_DECLARATIONS_POP
if ( bTranspose )
{
SCCOL nX;
SCROW nY;
// include filtered rows until TransposeClip can skip them
bIncludeFiltered = true;
pClipDoc->GetClipArea( nX, nY, true );
if ( nY > static_cast<sal_Int32>(MAXCOL) ) // zuviele Zeilen zum Transponieren
{
ErrorMessage(STR_PASTE_FULL);
return false;
}
pOrigClipDoc = pClipDoc; // fuer Referenzen
if ( bPasteDraw )
{
aTransShellRef = new ScDocShell; // DocShell needs a Ref immediately
aTransShellRef->DoInitNew(NULL);
}
ScDrawLayer::SetGlobalDrawPersist(aTransShellRef);
xTransClip.reset( new ScDocument( SCDOCMODE_CLIP ));
pClipDoc->TransposeClip( xTransClip.get(), nFlags, bAsLink );
pClipDoc = xTransClip.get();
ScDrawLayer::SetGlobalDrawPersist(NULL);
}
SCCOL nStartCol;
SCROW nStartRow;
SCTAB nStartTab;
SCCOL nEndCol;
SCROW nEndRow;
SCTAB nEndTab;
SCCOL nClipSizeX;
SCROW nClipSizeY;
pClipDoc->GetClipArea( nClipSizeX, nClipSizeY, true ); // size in clipboard doc
// size in target doc: include filtered rows only if CutMode is set
SCCOL nDestSizeX;
SCROW nDestSizeY;
pClipDoc->GetClipArea( nDestSizeX, nDestSizeY, bIncludeFiltered );
ScDocument* pDoc = GetViewData()->GetDocument();
ScDocShell* pDocSh = GetViewData()->GetDocShell();
::svl::IUndoManager* pUndoMgr = pDocSh->GetUndoManager();
const bool bRecord(pDoc->IsUndoEnabled());
ScDocShellModificator aModificator( *pDocSh );
ScRange aMarkRange;
ScMarkData aFilteredMark( rMark); // local copy for all modifications
ScMarkType eMarkType = GetViewData()->GetSimpleArea( aMarkRange, aFilteredMark);
bool bMarkIsFiltered = (eMarkType == SC_MARK_SIMPLE_FILTERED);
bool bNoPaste = ((eMarkType != SC_MARK_SIMPLE && !bMarkIsFiltered) ||
(bMarkIsFiltered && (eMoveMode != INS_NONE || bAsLink)));
if (!bNoPaste)
{
if (!rMark.IsMarked())
{
// Create a selection with clipboard row count and check that for
// filtered.
nStartCol = GetViewData()->GetCurX();
nStartRow = GetViewData()->GetCurY();
nStartTab = GetViewData()->GetTabNo();
nEndCol = nStartCol + nDestSizeX;
nEndRow = nStartRow + nDestSizeY;
nEndTab = nStartTab;
aMarkRange = ScRange( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab);
if (ScViewUtil::HasFiltered( aMarkRange, pDoc))
{
bMarkIsFiltered = true;
// Fit to clipboard's row count unfiltered rows. If there is no
// fit assume that pasting is not possible. Note that nDestSizeY is
// size-1 (difference).
if (!ScViewUtil::FitToUnfilteredRows( aMarkRange, pDoc, nDestSizeY+1))
bNoPaste = true;
}
aFilteredMark.SetMarkArea( aMarkRange);
}
else
{
// Expand the marked area when the destination area is larger than the
// current selection, to get the undo do the right thing. (i#106711)
ScRange aRange;
aFilteredMark.GetMarkArea( aRange );
if( (aRange.aEnd.Col() - aRange.aStart.Col()) < nDestSizeX )
{
aRange.aEnd.SetCol(aRange.aStart.Col() + nDestSizeX);
aFilteredMark.SetMarkArea(aRange);
}
}
}
if (bNoPaste)
{
ErrorMessage(STR_MSSG_PASTEFROMCLIP_0);
return false;
}
SCROW nUnfilteredRows = aMarkRange.aEnd.Row() - aMarkRange.aStart.Row() + 1;
ScRangeList aRangeList;
if (bMarkIsFiltered)
{
ScViewUtil::UnmarkFiltered( aFilteredMark, pDoc);
aFilteredMark.FillRangeListWithMarks( &aRangeList, false);
nUnfilteredRows = 0;
size_t ListSize = aRangeList.size();
for ( size_t i = 0; i < ListSize; ++i )
{
ScRange* p = aRangeList[i];
nUnfilteredRows += p->aEnd.Row() - p->aStart.Row() + 1;
}
#if 0
/* This isn't needed but could be a desired restriction. */
// For filtered, destination rows have to be an exact multiple of
// source rows. Note that nDestSizeY is size-1 (difference), so
// nDestSizeY==0 fits always.
if ((nUnfilteredRows % (nDestSizeY+1)) != 0)
{
/* FIXME: this should be a more descriptive error message then. */
ErrorMessage(STR_MSSG_PASTEFROMCLIP_0);
return false;
}
#endif
}
// Also for a filtered selection the area is used, for undo et al.
if ( aFilteredMark.IsMarked() || bMarkIsFiltered )
{
aMarkRange.GetVars( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab);
SCCOL nBlockAddX = nEndCol-nStartCol;
SCROW nBlockAddY = nEndRow-nStartRow;
// Nachfrage, wenn die Selektion groesser als 1 Zeile/Spalte, aber kleiner
// als das Clipboard ist (dann wird ueber die Selektion hinaus eingefuegt)
// ClipSize is not size, but difference
if ( ( nBlockAddX != 0 && nBlockAddX < nDestSizeX ) ||
( nBlockAddY != 0 && nBlockAddY < nDestSizeY ) ||
( bMarkIsFiltered && nUnfilteredRows < nDestSizeY+1 ) )
{
ScWaitCursorOff aWaitOff( GetFrameWin() );
String aMessage = ScGlobal::GetRscString( STR_PASTE_BIGGER );
QueryBox aBox( GetViewData()->GetDialogParent(),
WinBits(WB_YES_NO | WB_DEF_NO), aMessage );
if ( aBox.Execute() != RET_YES )
{
return false;
}
}
if (nBlockAddX <= nDestSizeX)
nEndCol = nStartCol + nDestSizeX;
if (nBlockAddY <= nDestSizeY)
{
nEndRow = nStartRow + nDestSizeY;
if (bMarkIsFiltered || nEndRow > aMarkRange.aEnd.Row())
{
// Same as above if nothing was marked: re-fit selection to
// unfiltered rows. Extending the selection actually may
// introduce filtered rows where there weren't any before, so
// we also need to test for that.
aMarkRange = ScRange( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab);
if (bMarkIsFiltered || ScViewUtil::HasFiltered( aMarkRange, pDoc))
{
bMarkIsFiltered = true;
// Worst case: all rows up to the end of the sheet are filtered.
if (!ScViewUtil::FitToUnfilteredRows( aMarkRange, pDoc, nDestSizeY+1))
{
ErrorMessage(STR_PASTE_FULL);
return false;
}
}
aMarkRange.GetVars( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab);
aFilteredMark.SetMarkArea( aMarkRange);
if (bMarkIsFiltered)
{
ScViewUtil::UnmarkFiltered( aFilteredMark, pDoc);
aFilteredMark.FillRangeListWithMarks( &aRangeList, true);
}
}
}
}
else
{
nStartCol = GetViewData()->GetCurX();
nStartRow = GetViewData()->GetCurY();
nStartTab = GetViewData()->GetTabNo();
nEndCol = nStartCol + nDestSizeX;
nEndRow = nStartRow + nDestSizeY;
nEndTab = nStartTab;
}
bool bOffLimits = !ValidCol(nEndCol) || !ValidRow(nEndRow);
// Zielbereich, wie er angezeigt wird:
ScRange aUserRange( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab );
// Sollen Zellen eingefuegt werden?
// (zu grosse nEndCol/nEndRow werden weiter unten erkannt)
bool bInsertCells = ( eMoveMode != INS_NONE && !bOffLimits );
if ( bInsertCells )
{
// Instead of EnterListAction, the paste undo action is merged into the
// insert action, so Repeat can insert the right cells
MarkRange( aUserRange ); // wird vor CopyFromClip sowieso gesetzt
// CutMode is reset on insertion of cols/rows but needed again on cell move
bool bCut = pClipDoc->IsCutMode();
if (!InsertCells( eMoveMode, bRecord, true )) // is inserting possible?
{
return false;
// #i21036# EnterListAction isn't used, and InsertCells doesn't insert
// its undo action on failure, so no undo handling is needed here
}
if ( bCut )
pClipDoc->SetCutMode( bCut );
}
else if (!bOffLimits)
{
bool bAskIfNotEmpty = bAllowDialogs &&
( nFlags & IDF_CONTENTS ) &&
nFunction == PASTE_NOFUNC &&
SC_MOD()->GetInputOptions().GetReplaceCellsWarn();
if ( bAskIfNotEmpty )
{
ScRangeList aTestRanges;
aTestRanges.Append(aUserRange);
if (!checkDestRangeForOverwrite(aTestRanges, pDoc, aFilteredMark, GetViewData()->GetDialogParent()))
return false;
}
}
SCCOL nClipStartX; // Clipboard-Bereich erweitern
SCROW nClipStartY;
pClipDoc->GetClipStart( nClipStartX, nClipStartY );
SCCOL nUndoEndCol = nClipStartX + nClipSizeX;
SCROW nUndoEndRow = nClipStartY + nClipSizeY; // end of source area in clipboard document
bool bClipOver = false;
// #i68690# ExtendMerge for the clip doc must be called with the clipboard's sheet numbers.
// The same end column/row can be used for all calls because the clip doc doesn't contain
// content outside the clip area.
for (SCTAB nClipTab=0; nClipTab < pClipDoc->GetTableCount(); nClipTab++)
if ( pClipDoc->HasTable(nClipTab) )
if ( pClipDoc->ExtendMerge( nClipStartX,nClipStartY, nUndoEndCol,nUndoEndRow, nClipTab, false ) )
bClipOver = true;
nUndoEndCol -= nClipStartX + nClipSizeX;
nUndoEndRow -= nClipStartY + nClipSizeY; // now contains only the difference added by ExtendMerge
nUndoEndCol = sal::static_int_cast<SCCOL>( nUndoEndCol + nEndCol );
nUndoEndRow = sal::static_int_cast<SCROW>( nUndoEndRow + nEndRow ); // destination area, expanded for merged cells
if (nUndoEndCol>MAXCOL || nUndoEndRow>MAXROW)
{
ErrorMessage(STR_PASTE_FULL);
return false;
}
pDoc->ExtendMergeSel( nStartCol,nStartRow, nUndoEndCol,nUndoEndRow, aFilteredMark, false );
// Test auf Zellschutz
ScEditableTester aTester( pDoc, nStartTab, nStartCol,nStartRow, nUndoEndCol,nUndoEndRow );
if (!aTester.IsEditable())
{
ErrorMessage(aTester.GetMessageId());
return false;
}
//! Test auf Ueberlappung
//! nur wirkliche Schnittmenge testen !!!!!!!
ScDocFunc& rDocFunc = pDocSh->GetDocFunc();
if ( bRecord )
{
String aUndo = ScGlobal::GetRscString( pClipDoc->IsCutMode() ? STR_UNDO_MOVE : STR_UNDO_COPY );
pUndoMgr->EnterListAction( aUndo, aUndo );
}
if (bClipOver)
if (lcl_SelHasAttrib( pDoc, nStartCol,nStartRow, nUndoEndCol,nUndoEndRow, aFilteredMark, HASATTR_OVERLAPPED ))
{ // "Cell merge not possible if cells already merged"
ScDocAttrIterator aIter( pDoc, nStartTab, nStartCol, nStartRow, nUndoEndCol, nUndoEndRow );
const ScPatternAttr* pPattern = NULL;
const ScMergeAttr* pMergeFlag = NULL;
const ScMergeFlagAttr* pMergeFlagAttr = NULL;
SCCOL nCol = -1;
SCROW nRow1 = -1;
SCROW nRow2 = -1;
while ( ( pPattern = aIter.GetNext( nCol, nRow1, nRow2 ) ) != NULL )
{
pMergeFlag = (const ScMergeAttr*) &pPattern->GetItem(ATTR_MERGE);
pMergeFlagAttr = (const ScMergeFlagAttr*) &pPattern->GetItem(ATTR_MERGE_FLAG);
if( ( pMergeFlag && pMergeFlag->IsMerged() ) || ( pMergeFlagAttr && pMergeFlagAttr->IsOverlapped() ) )
{
ScRange aRange(nCol, nRow1, nStartTab);
pDoc->ExtendOverlapped(aRange);
pDoc->ExtendMerge(aRange, true);
rDocFunc.UnmergeCells(aRange, bRecord);
}
}
}
if ( !bCutMode )
{
ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
if ( pChangeTrack )
pChangeTrack->ResetLastCut(); // kein CutMode mehr
}
bool bColInfo = ( nStartRow==0 && nEndRow==MAXROW );
bool bRowInfo = ( nStartCol==0 && nEndCol==MAXCOL );
ScDocument* pUndoDoc = NULL;
ScDocument* pRefUndoDoc = NULL;
ScDocument* pRedoDoc = NULL;
ScRefUndoData* pUndoData = NULL;
if ( bRecord )
{
pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
pUndoDoc->InitUndoSelected( pDoc, aFilteredMark, bColInfo, bRowInfo );
// all sheets - CopyToDocument skips those that don't exist in pUndoDoc
SCTAB nTabCount = pDoc->GetTableCount();
pDoc->CopyToDocument( nStartCol, nStartRow, 0, nUndoEndCol, nUndoEndRow, nTabCount-1,
nUndoFlags, false, pUndoDoc );
if ( bCutMode )
{
pRefUndoDoc = new ScDocument( SCDOCMODE_UNDO );
pRefUndoDoc->InitUndo( pDoc, 0, nTabCount-1, false, false );
pUndoData = new ScRefUndoData( pDoc );
}
}
sal_uInt16 nExtFlags = 0;
pDocSh->UpdatePaintExt( nExtFlags, nStartCol, nStartRow, nStartTab,
nEndCol, nEndRow, nEndTab ); // content before the change
if (GetViewData()->IsActive())
{
DoneBlockMode();
InitOwnBlockMode();
}
rMark.SetMarkArea( aUserRange );
MarkDataChanged();
//
// Aus Clipboard kopieren,
// wenn gerechnet werden soll, Originaldaten merken
//
ScDocument* pMixDoc = NULL;
if ( bSkipEmpty || nFunction )
{
if ( nFlags & IDF_CONTENTS )
{
pMixDoc = new ScDocument( SCDOCMODE_UNDO );
pMixDoc->InitUndo( pDoc, nStartTab, nEndTab );
pDoc->CopyToDocument( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab,
IDF_CONTENTS, false, pMixDoc );
}
}
/* Make draw layer and start drawing undo.
- Needed before AdjustBlockHeight to track moved drawing objects.
- Needed before pDoc->CopyFromClip to track inserted note caption objects.
*/
if ( bPasteDraw )
pDocSh->MakeDrawLayer();
if ( bRecord )
pDoc->BeginDrawUndo();
sal_uInt16 nNoObjFlags = nFlags & ~IDF_OBJECTS;
if (!bAsLink)
{
// copy normally (original range)
pDoc->CopyFromClip( aUserRange, aFilteredMark, nNoObjFlags,
pRefUndoDoc, pClipDoc, true, false, bIncludeFiltered,
bSkipEmpty, (bMarkIsFiltered ? &aRangeList : NULL) );
// bei Transpose Referenzen per Hand anpassen
if ( bTranspose && bCutMode && (nFlags & IDF_CONTENTS) )
pDoc->UpdateTranspose( aUserRange.aStart, pOrigClipDoc, aFilteredMark, pRefUndoDoc );
}
else if (!bTranspose)
{
// copy with bAsLink=TRUE
pDoc->CopyFromClip( aUserRange, aFilteredMark, nNoObjFlags, pRefUndoDoc, pClipDoc,
true, true, bIncludeFiltered, bSkipEmpty );
}
else
{
// alle Inhalte kopieren (im TransClipDoc stehen nur Formeln)
pDoc->CopyFromClip( aUserRange, aFilteredMark, nContFlags, pRefUndoDoc, pClipDoc );
}
// skipped rows and merged cells don't mix
if ( !bIncludeFiltered && pClipDoc->HasClipFilteredRows() )
rDocFunc.UnmergeCells( aUserRange, false );
pDoc->ExtendMergeSel( nStartCol, nStartRow, nEndCol, nEndRow, aFilteredMark, true ); // Refresh
// und Bereich neu
if ( pMixDoc ) // Rechenfunktionen mit Original-Daten auszufuehren ?
{
pDoc->MixDocument( aUserRange, nFunction, bSkipEmpty, pMixDoc );
}
delete pMixDoc;
AdjustBlockHeight(); // update row heights before pasting objects
::std::vector< ::rtl::OUString > aExcludedChartNames;
SdrPage* pPage = NULL;
if ( nFlags & IDF_OBJECTS )
{
ScDrawView* pScDrawView = GetScDrawView();
SdrModel* pModel = ( pScDrawView ? pScDrawView->GetModel() : NULL );
pPage = ( pModel ? pModel->GetPage( static_cast< sal_uInt16 >( nStartTab ) ) : NULL );
if ( pPage )
{
ScChartHelper::GetChartNames( aExcludedChartNames, pPage );
}
// Paste the drawing objects after the row heights have been updated.
pDoc->CopyFromClip( aUserRange, aFilteredMark, IDF_OBJECTS, pRefUndoDoc, pClipDoc,
true, false, bIncludeFiltered );
}
pDocSh->UpdatePaintExt( nExtFlags, nStartCol, nStartRow, nStartTab,
nEndCol, nEndRow, nEndTab ); // content after the change
// ggf. Autofilter-Koepfe loeschen
if (bCutMode)
if (pDoc->RefreshAutoFilter( nClipStartX,nClipStartY, nClipStartX+nClipSizeX,
nClipStartY+nClipSizeY, nStartTab ))
{
pDocSh->PostPaint(
ScRange(nClipStartX, nClipStartY, nStartTab, nClipStartX+nClipSizeX, nClipStartY, nStartTab),
PAINT_GRID );
}
//! Block-Bereich bei RefUndoDoc weglassen !!!
if ( bRecord )
{
// Redo-Daten werden erst beim ersten Undo kopiert
// ohne RefUndoDoc muss das Redo-Doc noch nicht angelegt werden
if (pRefUndoDoc)
{
pRedoDoc = new ScDocument( SCDOCMODE_UNDO );
pRedoDoc->InitUndo( pDoc, nStartTab, nEndTab, bColInfo, bRowInfo );
// angepasste Referenzen ins Redo-Doc
SCTAB nTabCount = pDoc->GetTableCount();
pRedoDoc->AddUndoTab( 0, nTabCount-1 );
pDoc->CopyUpdated( pRefUndoDoc, pRedoDoc );
// alte Referenzen ins Undo-Doc
//! Tabellen selektieren ?
pUndoDoc->AddUndoTab( 0, nTabCount-1 );
pRefUndoDoc->DeleteArea( nStartCol, nStartRow, nEndCol, nEndRow, aFilteredMark, IDF_ALL );
pRefUndoDoc->CopyToDocument( 0,0,0, MAXCOL,MAXROW,nTabCount-1,
IDF_FORMULA, false, pUndoDoc );
delete pRefUndoDoc;
}
// DeleteUnchanged for pUndoData is in ScUndoPaste ctor,
// UndoData for redo is made during first undo
ScUndoPasteOptions aOptions; // store options for repeat
aOptions.nFunction = nFunction;
aOptions.bSkipEmpty = bSkipEmpty;
aOptions.bTranspose = bTranspose;
aOptions.bAsLink = bAsLink;
aOptions.eMoveMode = eMoveMode;
SfxUndoAction* pUndo = new ScUndoPaste(
pDocSh, ScRange(nStartCol, nStartRow, nStartTab, nUndoEndCol, nUndoEndRow, nEndTab),
aFilteredMark, pUndoDoc, pRedoDoc, nFlags | nUndoFlags, pUndoData,
false, &aOptions ); // false = Redo data not yet copied
if ( bInsertCells )
{
// Merge the paste undo action into the insert action.
// Use ScUndoWrapper so the ScUndoPaste pointer can be stored in the insert action.
pUndoMgr->AddUndoAction( new ScUndoWrapper( pUndo ), true );
}
else
pUndoMgr->AddUndoAction( pUndo );
pUndoMgr->LeaveListAction();
}
sal_uInt16 nPaint = PAINT_GRID;
if (bColInfo)
{
nPaint |= PAINT_TOP;
nUndoEndCol = MAXCOL; // nur zum Zeichnen !
}
if (bRowInfo)
{
nPaint |= PAINT_LEFT;
nUndoEndRow = MAXROW; // nur zum Zeichnen !
}
pDocSh->PostPaint(
ScRange(nStartCol, nStartRow, nStartTab, nUndoEndCol, nUndoEndRow, nEndTab),
nPaint, nExtFlags);
// AdjustBlockHeight has already been called above
aModificator.SetDocumentModified();
PostPasteFromClip(aUserRange, rMark);
if ( nFlags & IDF_OBJECTS )
{
ScModelObj* pModelObj = ( pDocSh ? ScModelObj::getImplementation( pDocSh->GetModel() ) : NULL );
if ( pDoc && pPage && pModelObj )
{
bool bSameDoc = ( rClipParam.getSourceDocID() == pDoc->GetDocumentID() );
const ScRangeListVector& rProtectedChartRangesVector( rClipParam.maProtectedChartRangesVector );
ScChartHelper::CreateProtectedChartListenersAndNotify( pDoc, pPage, pModelObj, nStartTab,
rProtectedChartRangesVector, aExcludedChartNames, bSameDoc );
}
}
return true;
}
bool ScViewFunc::PasteMultiRangesFromClip(
sal_uInt16 nFlags, ScDocument* pClipDoc, sal_uInt16 nFunction,
bool bSkipEmpty, bool bTranspose, bool bAsLink, bool bAllowDialogs,
InsCellCmd eMoveMode, sal_uInt16 nUndoFlags)
{
ScViewData& rViewData = *GetViewData();
ScDocument* pDoc = rViewData.GetDocument();
ScDocShell* pDocSh = rViewData.GetDocShell();
ScMarkData aMark(rViewData.GetMarkData());
const ScAddress& rCurPos = rViewData.GetCurPos();
ScClipParam& rClipParam = pClipDoc->GetClipParam();
SCCOL nColSize = rClipParam.getPasteColSize();
SCROW nRowSize = rClipParam.getPasteRowSize();
if (bTranspose)
{
if (static_cast<SCROW>(rCurPos.Col()) + nRowSize-1 > static_cast<SCROW>(MAXCOL))
{
ErrorMessage(STR_PASTE_FULL);
return false;
}
SAL_WNODEPRECATED_DECLARATIONS_PUSH
::std::auto_ptr<ScDocument> pTransClip(new ScDocument(SCDOCMODE_CLIP));
SAL_WNODEPRECATED_DECLARATIONS_POP
pClipDoc->TransposeClip(pTransClip.get(), nFlags, bAsLink);
pClipDoc = pTransClip.release();
SCCOL nTempColSize = nColSize;
nColSize = static_cast<SCCOL>(nRowSize);
nRowSize = static_cast<SCROW>(nTempColSize);
}
if (!ValidCol(rCurPos.Col()+nColSize-1) || !ValidRow(rCurPos.Row()+nRowSize-1))
{
ErrorMessage(STR_PASTE_FULL);
return false;
}
// Determine the first and last selected sheet numbers.
SCTAB nTab1 = aMark.GetFirstSelected();
SCTAB nTab2 = aMark.GetLastSelected();
ScDocShellModificator aModificator(*pDocSh);
// For multi-selection paste, we don't support cell duplication for larger
// destination range. In case the destination is marked, we reset it to
// the clip size.
ScRange aMarkedRange(rCurPos.Col(), rCurPos.Row(), nTab1,
rCurPos.Col()+nColSize-1, rCurPos.Row()+nRowSize-1, nTab2);
// Extend the marked range to account for filtered rows in the destination
// area.
if (ScViewUtil::HasFiltered(aMarkedRange, pDoc))
{
if (!ScViewUtil::FitToUnfilteredRows(aMarkedRange, pDoc, nRowSize))
return false;
}
bool bAskIfNotEmpty =
bAllowDialogs && (nFlags & IDF_CONTENTS) &&
nFunction == PASTE_NOFUNC && SC_MOD()->GetInputOptions().GetReplaceCellsWarn();
if (bAskIfNotEmpty)
{
ScRangeList aTestRanges;
aTestRanges.Append(aMarkedRange);
if (!checkDestRangeForOverwrite(aTestRanges, pDoc, aMark, rViewData.GetDialogParent()))
return false;
}
aMark.SetMarkArea(aMarkedRange);
MarkRange(aMarkedRange);
bool bInsertCells = (eMoveMode != INS_NONE);
if (bInsertCells)
{
if (!InsertCells(eMoveMode, pDoc->IsUndoEnabled(), true))
return false;
}
SAL_WNODEPRECATED_DECLARATIONS_PUSH
::std::auto_ptr<ScDocument> pUndoDoc;
SAL_WNODEPRECATED_DECLARATIONS_POP
if (pDoc->IsUndoEnabled())
{
pUndoDoc.reset(new ScDocument(SCDOCMODE_UNDO));
pUndoDoc->InitUndoSelected(pDoc, aMark, false, false);
pDoc->CopyToDocument(aMarkedRange, nUndoFlags, false, pUndoDoc.get(), &aMark, true);
}
SAL_WNODEPRECATED_DECLARATIONS_PUSH
::std::auto_ptr<ScDocument> pMixDoc;
SAL_WNODEPRECATED_DECLARATIONS_POP
if ( bSkipEmpty || nFunction )
{
if ( nFlags & IDF_CONTENTS )
{
pMixDoc.reset(new ScDocument(SCDOCMODE_UNDO));
pMixDoc->InitUndoSelected(pDoc, aMark, false, false);
pDoc->CopyToDocument(aMarkedRange, IDF_CONTENTS, false, pMixDoc.get(), &aMark, true);
}
}
/* Make draw layer and start drawing undo.
- Needed before AdjustBlockHeight to track moved drawing objects.
- Needed before pDoc->CopyFromClip to track inserted note caption objects.
*/
if (nFlags & IDF_OBJECTS)
pDocSh->MakeDrawLayer();
if (pDoc->IsUndoEnabled())
pDoc->BeginDrawUndo();
sal_uInt16 nNoObjFlags = nFlags & ~IDF_OBJECTS;
pDoc->CopyMultiRangeFromClip(rCurPos, aMark, nNoObjFlags, pClipDoc,
true, bAsLink, false, bSkipEmpty);
if (pMixDoc.get())
pDoc->MixDocument(aMarkedRange, nFunction, bSkipEmpty, pMixDoc.get());
AdjustBlockHeight(); // update row heights before pasting objects
if (nFlags & IDF_OBJECTS)
{
// Paste the drawing objects after the row heights have been updated.
pDoc->CopyMultiRangeFromClip(rCurPos, aMark, IDF_OBJECTS, pClipDoc,
true, false, false, true);
}
ScRange aTmp = aMarkedRange;
aTmp.aStart.SetTab(nTab1);
aTmp.aEnd.SetTab(nTab1);
pDocSh->PostPaint(aTmp, PAINT_GRID);
if (pDoc->IsUndoEnabled())
{
::svl::IUndoManager* pUndoMgr = pDocSh->GetUndoManager();
String aUndo = ScGlobal::GetRscString(
pClipDoc->IsCutMode() ? STR_UNDO_CUT : STR_UNDO_COPY);
pUndoMgr->EnterListAction(aUndo, aUndo);
ScUndoPasteOptions aOptions; // store options for repeat
aOptions.nFunction = nFunction;
aOptions.bSkipEmpty = bSkipEmpty;
aOptions.bTranspose = bTranspose;
aOptions.bAsLink = bAsLink;
aOptions.eMoveMode = eMoveMode;
ScUndoPaste* pUndo = new ScUndoPaste(pDocSh,
aMarkedRange, aMark, pUndoDoc.release(), NULL, nFlags|nUndoFlags, NULL, false, &aOptions);
if (bInsertCells)
pUndoMgr->AddUndoAction(new ScUndoWrapper(pUndo), true);
else
pUndoMgr->AddUndoAction(pUndo, false);
pUndoMgr->LeaveListAction();
}
aModificator.SetDocumentModified();
PostPasteFromClip(aMarkedRange, aMark);
return true;
}
bool ScViewFunc::PasteFromClipToMultiRanges(
sal_uInt16 nFlags, ScDocument* pClipDoc, sal_uInt16 nFunction,
bool bSkipEmpty, bool bTranspose, bool bAsLink, bool bAllowDialogs,
InsCellCmd eMoveMode, sal_uInt16 nUndoFlags )
{
if (bTranspose)
{
// We don't allow transpose for this yet.
ErrorMessage(STR_MSSG_PASTEFROMCLIP_0);
return false;
}
if (eMoveMode != INS_NONE)
{
// We don't allow insertion mode either. Too complicated.
ErrorMessage(STR_MSSG_PASTEFROMCLIP_0);
return false;
}
ScViewData& rViewData = *GetViewData();
ScClipParam& rClipParam = pClipDoc->GetClipParam();
if (rClipParam.mbCutMode)
{
// No cut and paste with this, please.
ErrorMessage(STR_MSSG_PASTEFROMCLIP_0);
return false;
}
const ScAddress& rCurPos = rViewData.GetCurPos();
ScDocument* pDoc = rViewData.GetDocument();
ScRange aSrcRange = rClipParam.getWholeRange();
SCROW nRowSize = aSrcRange.aEnd.Row() - aSrcRange.aStart.Row() + 1;
SCCOL nColSize = aSrcRange.aEnd.Col() - aSrcRange.aStart.Col() + 1;
if (!ValidCol(rCurPos.Col()+nColSize-1) || !ValidRow(rCurPos.Row()+nRowSize-1))
{
ErrorMessage(STR_PASTE_FULL);
return false;
}
ScMarkData aMark(rViewData.GetMarkData());
ScRangeList aRanges;
aMark.MarkToSimple();
aMark.FillRangeListWithMarks(&aRanges, false);
if (!ScClipUtil::CheckDestRanges(pDoc, nColSize, nRowSize, aMark, aRanges))
{
ErrorMessage(STR_MSSG_PASTEFROMCLIP_0);
return false;
}
ScDocShell* pDocSh = rViewData.GetDocShell();
ScDocShellModificator aModificator(*pDocSh);
bool bAskIfNotEmpty =
bAllowDialogs && (nFlags & IDF_CONTENTS) &&
nFunction == PASTE_NOFUNC && SC_MOD()->GetInputOptions().GetReplaceCellsWarn();
if (bAskIfNotEmpty)
{
if (!checkDestRangeForOverwrite(aRanges, pDoc, aMark, rViewData.GetDialogParent()))
return false;
}
SAL_WNODEPRECATED_DECLARATIONS_PUSH
std::auto_ptr<ScDocument> pUndoDoc;
SAL_WNODEPRECATED_DECLARATIONS_POP
if (pDoc->IsUndoEnabled())
{
pUndoDoc.reset(new ScDocument(SCDOCMODE_UNDO));
pUndoDoc->InitUndoSelected(pDoc, aMark, false, false);
for (size_t i = 0, n = aRanges.size(); i < n; ++i)
{
pDoc->CopyToDocument(
*aRanges[i], nUndoFlags, false, pUndoDoc.get(), &aMark, true);
}
}
SAL_WNODEPRECATED_DECLARATIONS_PUSH
std::auto_ptr<ScDocument> pMixDoc;
SAL_WNODEPRECATED_DECLARATIONS_POP
if (bSkipEmpty || nFunction)
{
if (nFlags & IDF_CONTENTS)
{
pMixDoc.reset(new ScDocument(SCDOCMODE_UNDO));
pMixDoc->InitUndoSelected(pDoc, aMark, false, false);
for (size_t i = 0, n = aRanges.size(); i < n; ++i)
{
pDoc->CopyToDocument(
*aRanges[i], IDF_CONTENTS, false, pMixDoc.get(), &aMark, true);
}
}
}
if (nFlags & IDF_OBJECTS)
pDocSh->MakeDrawLayer();
if (pDoc->IsUndoEnabled())
pDoc->BeginDrawUndo();
// First, paste everything but the drawing objects.
for (size_t i = 0, n = aRanges.size(); i < n; ++i)
{
pDoc->CopyFromClip(
*aRanges[i], aMark, (nFlags & ~IDF_OBJECTS), NULL, pClipDoc,
false, false, true, bSkipEmpty, NULL);
}
if (pMixDoc.get())
{
for (size_t i = 0, n = aRanges.size(); i < n; ++i)
pDoc->MixDocument(*aRanges[i], nFunction, bSkipEmpty, pMixDoc.get());
}
AdjustBlockHeight(); // update row heights before pasting objects
// Then paste the objects.
if (nFlags & IDF_OBJECTS)
{
for (size_t i = 0, n = aRanges.size(); i < n; ++i)
{
pDoc->CopyFromClip(
*aRanges[i], aMark, IDF_OBJECTS, NULL, pClipDoc,
false, false, true, bSkipEmpty, NULL);
}
}
// Refresh the range that includes all pasted ranges. We only need to
// refresh the current sheet.
pDocSh->PostPaint(aRanges, PAINT_GRID);
if (pDoc->IsUndoEnabled())
{
svl::IUndoManager* pUndoMgr = pDocSh->GetUndoManager();
String aUndo = ScGlobal::GetRscString(
pClipDoc->IsCutMode() ? STR_UNDO_CUT : STR_UNDO_COPY);
pUndoMgr->EnterListAction(aUndo, aUndo);
ScUndoPasteOptions aOptions; // store options for repeat
aOptions.nFunction = nFunction;
aOptions.bSkipEmpty = bSkipEmpty;
aOptions.bTranspose = bTranspose;
aOptions.bAsLink = bAsLink;
aOptions.eMoveMode = eMoveMode;
ScUndoPaste* pUndo = new ScUndoPaste(
pDocSh, aRanges, aMark, pUndoDoc.release(), NULL, nFlags|nUndoFlags, NULL, false, &aOptions);
pUndoMgr->AddUndoAction(pUndo, false);
pUndoMgr->LeaveListAction();
}
aModificator.SetDocumentModified();
PostPasteFromClip(aRanges, aMark);
return false;
}
void ScViewFunc::PostPasteFromClip(const ScRangeList& rPasteRanges, const ScMarkData& rMark)
{
ScViewData* pViewData = GetViewData();
ScDocShell* pDocSh = pViewData->GetDocShell();
pDocSh->UpdateOle(pViewData);
SelectionChanged();
// #i97876# Spreadsheet data changes are not notified
ScModelObj* pModelObj = ScModelObj::getImplementation( pDocSh->GetModel() );
if (!pModelObj || !pModelObj->HasChangesListeners())
return;
ScRangeList aChangeRanges;
for (size_t i = 0, n = rPasteRanges.size(); i < n; ++i)
{
const ScRange& r = *rPasteRanges[i];
ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
for (; itr != itrEnd; ++itr)
{
ScRange aChangeRange(r);
aChangeRange.aStart.SetTab(*itr);
aChangeRange.aEnd.SetTab(*itr);
aChangeRanges.Append(aChangeRange);
}
}
pModelObj->NotifyChanges( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "cell-change" ) ), aChangeRanges );
}
//----------------------------------------------------------------------------
// D R A G A N D D R O P
//
// innerhalb des Dokuments
sal_Bool ScViewFunc::MoveBlockTo( const ScRange& rSource, const ScAddress& rDestPos,
sal_Bool bCut, sal_Bool bRecord, sal_Bool bPaint, sal_Bool bApi )
{
ScDocShell* pDocSh = GetViewData()->GetDocShell();
HideAllCursors(); // wegen zusammengefassten
sal_Bool bSuccess = sal_True;
SCTAB nDestTab = rDestPos.Tab();
const ScMarkData& rMark = GetViewData()->GetMarkData();
if ( rSource.aStart.Tab() == nDestTab && rSource.aEnd.Tab() == nDestTab && rMark.GetSelectCount() > 1 )
{
// moving within one table and several tables selected -> apply to all selected tables
if ( bRecord )
{
String aUndo = ScGlobal::GetRscString( bCut ? STR_UNDO_MOVE : STR_UNDO_COPY );
pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo );
}
// collect ranges of consecutive selected tables
ScRange aLocalSource = rSource;
ScAddress aLocalDest = rDestPos;
SCTAB nTabCount = pDocSh->GetDocument()->GetTableCount();
SCTAB nStartTab = 0;
while ( nStartTab < nTabCount && bSuccess )
{
while ( nStartTab < nTabCount && !rMark.GetTableSelect(nStartTab) )
++nStartTab;
if ( nStartTab < nTabCount )
{
SCTAB nEndTab = nStartTab;
while ( nEndTab+1 < nTabCount && rMark.GetTableSelect(nEndTab+1) )
++nEndTab;
aLocalSource.aStart.SetTab( nStartTab );
aLocalSource.aEnd.SetTab( nEndTab );
aLocalDest.SetTab( nStartTab );
bSuccess = pDocSh->GetDocFunc().MoveBlock(
aLocalSource, aLocalDest, bCut, bRecord, bPaint, bApi );
nStartTab = nEndTab + 1;
}
}
if ( bRecord )
pDocSh->GetUndoManager()->LeaveListAction();
}
else
{
// move the block as specified
bSuccess = pDocSh->GetDocFunc().MoveBlock(
rSource, rDestPos, bCut, bRecord, bPaint, bApi );
}
ShowAllCursors();
if (bSuccess)
{
// Zielbereich markieren
ScAddress aDestEnd(
rDestPos.Col() + rSource.aEnd.Col() - rSource.aStart.Col(),
rDestPos.Row() + rSource.aEnd.Row() - rSource.aStart.Row(),
nDestTab );
sal_Bool bIncludeFiltered = bCut;
if ( !bIncludeFiltered )
{
// find number of non-filtered rows
SCROW nPastedCount = pDocSh->GetDocument()->CountNonFilteredRows(
rSource.aStart.Row(), rSource.aEnd.Row(), rSource.aStart.Tab());
if ( nPastedCount == 0 )
nPastedCount = 1;
aDestEnd.SetRow( rDestPos.Row() + nPastedCount - 1 );
}
MarkRange( ScRange( rDestPos, aDestEnd ), false ); //! sal_False ???
pDocSh->UpdateOle(GetViewData());
SelectionChanged();
}
return bSuccess;
}
// Link innerhalb des Dokuments
sal_Bool ScViewFunc::LinkBlock( const ScRange& rSource, const ScAddress& rDestPos, sal_Bool bApi )
{
// Test auf Ueberlappung
if ( rSource.aStart.Tab() == rDestPos.Tab() )
{
SCCOL nDestEndCol = rDestPos.Col() + ( rSource.aEnd.Col() - rSource.aStart.Col() );
SCROW nDestEndRow = rDestPos.Row() + ( rSource.aEnd.Row() - rSource.aStart.Row() );
if ( rSource.aStart.Col() <= nDestEndCol && rDestPos.Col() <= rSource.aEnd.Col() &&
rSource.aStart.Row() <= nDestEndRow && rDestPos.Row() <= rSource.aEnd.Row() )
{
if (!bApi)
ErrorMessage( STR_ERR_LINKOVERLAP );
return false;
}
}
// Ausfuehren per Paste
ScDocument* pDoc = GetViewData()->GetDocument();
ScDocument* pClipDoc = new ScDocument( SCDOCMODE_CLIP );
pDoc->CopyTabToClip( rSource.aStart.Col(), rSource.aStart.Row(),
rSource.aEnd.Col(), rSource.aEnd.Row(),
rSource.aStart.Tab(), pClipDoc );
// Zielbereich markieren (Cursor setzen, keine Markierung)
if ( GetViewData()->GetTabNo() != rDestPos.Tab() )
SetTabNo( rDestPos.Tab() );
MoveCursorAbs( rDestPos.Col(), rDestPos.Row(), SC_FOLLOW_NONE, false, false );
// Paste
PasteFromClip( IDF_ALL, pClipDoc, PASTE_NOFUNC, false, false, sal_True ); // als Link
delete pClipDoc;
return sal_True;
}
void ScViewFunc::DataFormPutData( SCROW nCurrentRow ,
SCROW nStartRow , SCCOL nStartCol ,
SCROW nEndRow , SCCOL nEndCol ,
boost::ptr_vector<boost::nullable<Edit> >& aEdits,
sal_uInt16 aColLength )
{
ScDocument* pDoc = GetViewData()->GetDocument();
ScDocShell* pDocSh = GetViewData()->GetDocShell();
ScMarkData& rMark = GetViewData()->GetMarkData();
ScDocShellModificator aModificator( *pDocSh );
::svl::IUndoManager* pUndoMgr = pDocSh->GetUndoManager();
if ( pDoc )
{
const sal_Bool bRecord( pDoc->IsUndoEnabled());
ScDocument* pUndoDoc = NULL;
ScDocument* pRedoDoc = NULL;
ScRefUndoData* pUndoData = NULL;
SCTAB nTab = GetViewData()->GetTabNo();
SCTAB nStartTab = nTab;
SCTAB nEndTab = nTab;
{
ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
if ( pChangeTrack )
pChangeTrack->ResetLastCut(); // kein CutMode mehr
}
ScRange aUserRange( nStartCol, nCurrentRow, nStartTab, nEndCol, nCurrentRow, nEndTab );
sal_Bool bColInfo = ( nStartRow==0 && nEndRow==MAXROW );
sal_Bool bRowInfo = ( nStartCol==0 && nEndCol==MAXCOL );
SCCOL nUndoEndCol = nStartCol+aColLength-1;
SCROW nUndoEndRow = nCurrentRow;
sal_uInt16 nUndoFlags = IDF_NONE;
if ( bRecord )
{
pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
pUndoDoc->InitUndoSelected( pDoc , rMark , bColInfo , bRowInfo );
pDoc->CopyToDocument( aUserRange , 1 , false , pUndoDoc );
}
sal_uInt16 nExtFlags = 0;
pDocSh->UpdatePaintExt( nExtFlags, nStartCol, nStartRow, nStartTab , nEndCol, nEndRow, nEndTab ); // content before the change
pDoc->BeginDrawUndo();
for(sal_uInt16 i = 0; i < aColLength; i++)
{
if (!aEdits.is_null(i))
{
String aFieldName=aEdits[i].GetText();
pDoc->SetString( nStartCol + i, nCurrentRow, nTab, aFieldName );
}
}
pDocSh->UpdatePaintExt( nExtFlags, nStartCol, nCurrentRow, nStartTab, nEndCol, nCurrentRow, nEndTab ); // content after the change
SfxUndoAction* pUndo = new ScUndoDataForm( pDocSh,
nStartCol, nCurrentRow, nStartTab,
nUndoEndCol, nUndoEndRow, nEndTab, rMark,
pUndoDoc, pRedoDoc, nUndoFlags,
pUndoData, NULL, NULL, NULL,
false ); // FALSE = Redo data not yet copied
pUndoMgr->AddUndoAction( new ScUndoWrapper( pUndo ), true );
sal_uInt16 nPaint = PAINT_GRID;
if (bColInfo)
{
nPaint |= PAINT_TOP;
nUndoEndCol = MAXCOL; // nur zum Zeichnen !
}
if (bRowInfo)
{
nPaint |= PAINT_LEFT;
nUndoEndRow = MAXROW; // nur zum Zeichnen !
}
pDocSh->PostPaint(
ScRange(nStartCol, nCurrentRow, nStartTab, nUndoEndCol, nUndoEndRow, nEndTab),
nPaint, nExtFlags);
pDocSh->UpdateOle(GetViewData());
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|