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
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
|
/* -*- 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 <svx/dialmgr.hxx>
#include <svx/fmshell.hxx>
#include <svx/fmmodel.hxx>
#include <svx/fmpage.hxx>
#include <svx/svdpagv.hxx>
#include "svx/svditer.hxx"
#include "fmhelp.hrc"
#include "fmexpl.hxx"
#include "svx/fmresids.hrc"
#include "fmshimp.hxx"
#include "fmservs.hxx"
#include "fmundo.hxx"
#include "fmpgeimp.hxx"
#include "fmitems.hxx"
#include "fmobj.hxx"
#include "fmprop.hrc"
#include <vcl/wrkwin.hxx>
#include <sfx2/viewsh.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/viewfrm.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/property.hxx>
#include <com/sun/star/form/FormComponentType.hpp>
#include <com/sun/star/sdb/CommandType.hpp>
#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <com/sun/star/script/XEventAttacherManager.hpp>
#include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
#include <com/sun/star/datatransfer/XTransferable.hpp>
#include <svx/sdrpaintwindow.hxx>
#include <svx/svxdlg.hxx>
#include <svx/dialogs.hrc>
#include "svtools/treelistentry.hxx"
namespace svxform
{
#define DROP_ACTION_TIMER_INITIAL_TICKS 10
// solange dauert es, bis das Scrollen anspringt
#define DROP_ACTION_TIMER_SCROLL_TICKS 3
// in diesen Intervallen wird jeweils eine Zeile gescrollt
#define DROP_ACTION_TIMER_TICK_BASE 10
// das ist die Basis, mit der beide Angaben multipliziert werden (in ms)
#define EXPLORER_SYNC_DELAY 200
// dieser Betrag an Millisekunden wird gewartet, ehe der Explorer nach einem Select oder Deselect die View synchronisiert
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::form;
using namespace ::com::sun::star::awt;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::script;
using namespace ::com::sun::star::datatransfer;
using namespace ::com::sun::star::datatransfer::clipboard;
using namespace ::com::sun::star::sdb;
// helper
typedef ::std::map< Reference< XInterface >, SdrObject*, ::comphelper::OInterfaceCompare< XInterface > >
MapModelToShape;
typedef MapModelToShape::value_type ModelShapePair;
void collectShapeModelMapping( SdrPage* _pPage, MapModelToShape& _rMapping )
{
OSL_ENSURE( _pPage, "collectShapeModelMapping: invalid arg!" );
_rMapping.clear();
SdrObjListIter aIter( *_pPage );
while ( aIter.IsMore() )
{
SdrObject* pSdrObject = aIter.Next();
FmFormObj* pFormObject = FmFormObj::GetFormObject( pSdrObject );
if ( !pFormObject )
continue;
Reference< XInterface > xNormalizedModel( pFormObject->GetUnoControlModel(), UNO_QUERY );
// note that this is normalized (i.e. queried for XInterface explicitly)
#ifdef DBG_UTIL
::std::pair< MapModelToShape::iterator, bool > aPos =
#endif
_rMapping.insert( ModelShapePair( xNormalizedModel, pSdrObject ) );
DBG_ASSERT( aPos.second, "collectShapeModelMapping: model was already existent!" );
// if this asserts, this would mean we have 2 shapes pointing to the same model
}
}
// class NavigatorTree
NavigatorTree::NavigatorTree( Window* pParent )
:SvTreeListBox( pParent, WB_HASBUTTONS|WB_HASLINES|WB_BORDER|WB_HSCROLL ) // #100258# OJ WB_HSCROLL added
,m_aControlExchange(this)
,m_pNavModel( NULL )
,m_pRootEntry(NULL)
,m_pEditEntry(NULL)
,nEditEvent(0)
,m_sdiState(SDI_DIRTY)
,m_aTimerTriggered(-1,-1)
,m_aDropActionType( DA_SCROLLUP )
,m_nSelectLock(0)
,m_nFormsSelected(0)
,m_nControlsSelected(0)
,m_nHiddenControls(0)
,m_aTimerCounter( DROP_ACTION_TIMER_INITIAL_TICKS )
,m_bDragDataDirty(false)
,m_bPrevSelectionMixed(false)
,m_bMarkingObjects(false)
,m_bRootSelected(false)
,m_bInitialUpdate(true)
,m_bKeyboardCut( false )
{
SetHelpId( HID_FORM_NAVIGATOR );
m_aNavigatorImages = ImageList( SVX_RES( RID_SVXIMGLIST_FMEXPL ) );
SetNodeBitmaps(
m_aNavigatorImages.GetImage( RID_SVXIMG_COLLAPSEDNODE ),
m_aNavigatorImages.GetImage( RID_SVXIMG_EXPANDEDNODE )
);
SetDragDropMode(0xFFFF);
EnableInplaceEditing( true );
SetSelectionMode(MULTIPLE_SELECTION);
m_pNavModel = new NavigatorTreeModel( m_aNavigatorImages );
Clear();
StartListening( *m_pNavModel );
m_aDropActionTimer.SetTimeoutHdl(LINK(this, NavigatorTree, OnDropActionTimer));
m_aSynchronizeTimer.SetTimeoutHdl(LINK(this, NavigatorTree, OnSynchronizeTimer));
SetSelectHdl(LINK(this, NavigatorTree, OnEntrySelDesel));
SetDeselectHdl(LINK(this, NavigatorTree, OnEntrySelDesel));
}
NavigatorTree::~NavigatorTree()
{
if( nEditEvent )
Application::RemoveUserEvent( nEditEvent );
if (m_aSynchronizeTimer.IsActive())
m_aSynchronizeTimer.Stop();
DBG_ASSERT(GetNavModel() != NULL, "NavigatorTree::~NavigatorTree : unerwartet : kein ExplorerModel");
EndListening( *m_pNavModel );
Clear();
delete m_pNavModel;
}
void NavigatorTree::Clear()
{
m_pNavModel->Clear();
}
void NavigatorTree::UpdateContent( FmFormShell* pFormShell )
{
if (m_bInitialUpdate)
{
GrabFocus();
m_bInitialUpdate = false;
}
FmFormShell* pOldShell = GetNavModel()->GetFormShell();
FmFormPage* pOldPage = GetNavModel()->GetFormPage();
FmFormPage* pNewPage = pFormShell ? pFormShell->GetCurPage() : NULL;
if ((pOldShell != pFormShell) || (pOldPage != pNewPage))
{
// neue Shell, waehrend ich gerade editiere ?
if (IsEditingActive())
CancelTextEditing();
m_bDragDataDirty = true; // sicherheitshalber, auch wenn ich gar nicht dragge
}
GetNavModel()->UpdateContent( pFormShell );
// wenn es eine Form gibt, die Root expandieren
if (m_pRootEntry && !IsExpanded(m_pRootEntry))
Expand(m_pRootEntry);
// wenn es GENAU eine Form gibt, auch diese expandieren
if (m_pRootEntry)
{
SvTreeListEntry* pFirst = FirstChild(m_pRootEntry);
if (pFirst && !NextSibling(pFirst))
Expand(pFirst);
}
}
bool NavigatorTree::implAllowExchange( sal_Int8 _nAction, bool* _pHasNonHidden )
{
SvTreeListEntry* pCurEntry = GetCurEntry();
if (!pCurEntry)
return false;
// die Informationen fuer das AcceptDrop und ExecuteDrop
CollectSelectionData(SDI_ALL);
if (m_arrCurrentSelection.empty())
// nothing to do
return false;
// testen, ob es sich vielleicht ausschliesslich um hidden controls handelt (dann koennte ich pCtrlExch noch ein
// zusaetzliches Format geben)
bool bHasNonHidden = false;
for ( SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
it != m_arrCurrentSelection.end(); ++it )
{
FmEntryData* pCurrent = static_cast< FmEntryData* >( (*it)->GetUserData() );
if ( IsHiddenControl( pCurrent ) )
continue;
bHasNonHidden = true;
break;
}
if ( bHasNonHidden && ( 0 == ( _nAction & DND_ACTION_MOVE ) ) )
// non-hidden controls need to be moved
return false;
if ( _pHasNonHidden )
*_pHasNonHidden = bHasNonHidden;
return true;
}
bool NavigatorTree::implPrepareExchange( sal_Int8 _nAction )
{
EndSelection();
bool bHasNonHidden = false;
if ( !implAllowExchange( _nAction, &bHasNonHidden ) )
return false;
m_aControlExchange.prepareDrag();
m_aControlExchange->setFocusEntry( GetCurEntry() );
for ( SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
it != m_arrCurrentSelection.end(); ++it )
m_aControlExchange->addSelectedEntry(*it);
m_aControlExchange->setFormsRoot( GetNavModel()->GetFormPage()->GetForms() );
m_aControlExchange->buildPathFormat( this, m_pRootEntry );
if (!bHasNonHidden)
{
// eine entsprechende Sequenz aufbauen
Sequence< Reference< XInterface > > seqIFaces(m_arrCurrentSelection.size());
Reference< XInterface >* pArray = seqIFaces.getArray();
for ( SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
it != m_arrCurrentSelection.end(); ++it, ++pArray )
*pArray = static_cast< FmEntryData* >( (*it)->GetUserData() )->GetElement();
// und das neue Format
m_aControlExchange->addHiddenControlsFormat(seqIFaces);
}
m_bDragDataDirty = false;
return true;
}
void NavigatorTree::StartDrag( sal_Int8 /*nAction*/, const ::Point& /*rPosPixel*/ )
{
EndSelection();
if ( !implPrepareExchange( DND_ACTION_COPYMOVE ) )
// nothing to do or something went wrong
return;
// jetzt haben wir alle in der aktuelle Situation moeglichen Formate eingesammelt, es kann also losgehen ...
m_aControlExchange.startDrag( DND_ACTION_COPYMOVE );
}
void NavigatorTree::Command( const CommandEvent& rEvt )
{
bool bHandled = false;
switch( rEvt.GetCommand() )
{
case COMMAND_CONTEXTMENU:
{
// die Stelle, an der geklickt wurde
::Point ptWhere;
if (rEvt.IsMouseEvent())
{
ptWhere = rEvt.GetMousePosPixel();
SvTreeListEntry* ptClickedOn = GetEntry(ptWhere);
if (ptClickedOn == NULL)
break;
if ( !IsSelected(ptClickedOn) )
{
SelectAll(false);
Select(ptClickedOn, true);
SetCurEntry(ptClickedOn);
}
}
else
{
if (m_arrCurrentSelection.empty()) // kann nur bei Kontextmenue ueber Tastatur passieren
break;
SvTreeListEntry* pCurrent = GetCurEntry();
if (!pCurrent)
break;
ptWhere = GetEntryPosition(pCurrent);
}
// meine Selektionsdaten auf den aktuellen Stand
CollectSelectionData(SDI_ALL);
// wenn mindestens ein Nicht-Root-Eintrag selektiert ist und die Root auch, dann nehme ich letztere aus der Selektion
// fix wieder raus
if ( (m_arrCurrentSelection.size() > 1) && m_bRootSelected )
{
Select( m_pRootEntry, false );
SetCursor( *m_arrCurrentSelection.begin(), true);
}
bool bSingleSelection = (m_arrCurrentSelection.size() == 1);
DBG_ASSERT( (m_arrCurrentSelection.size() > 0) || m_bRootSelected, "keine Eintraege selektiert" );
// solte nicht passieren, da ich oben bei der IsSelected-Abfrage auf jeden Fall einen selektiert haette,
// wenn das vorher nicht der Fall gewesen waere
// das Menue zusammenbasteln
FmFormShell* pFormShell = GetNavModel()->GetFormShell();
FmFormModel* pFormModel = pFormShell ? pFormShell->GetFormModel() : NULL;
if( pFormShell && pFormModel )
{
PopupMenu aContextMenu(SVX_RES(RID_FMEXPLORER_POPUPMENU));
PopupMenu* pSubMenuNew = aContextMenu.GetPopupMenu( SID_FM_NEW );
// das 'Neu'-Untermenue gibt es nur, wenn genau die Root oder genau ein Formular selektiert sind
aContextMenu.EnableItem( SID_FM_NEW, bSingleSelection && (m_nFormsSelected || m_bRootSelected) );
// 'Neu'\'Formular' unter genau den selben Bedingungen
pSubMenuNew->EnableItem( SID_FM_NEW_FORM, bSingleSelection && (m_nFormsSelected || m_bRootSelected) );
pSubMenuNew->SetItemImage(SID_FM_NEW_FORM, m_aNavigatorImages.GetImage(RID_SVXIMG_FORM));
pSubMenuNew->SetItemImage(SID_FM_NEW_HIDDEN, m_aNavigatorImages.GetImage(RID_SVXIMG_HIDDEN));
// 'Neu'\'verstecktes...', wenn genau ein Formular selektiert ist
pSubMenuNew->EnableItem( SID_FM_NEW_HIDDEN, bSingleSelection && m_nFormsSelected );
// 'Delete': everything which is not root can be removed
aContextMenu.EnableItem( SID_FM_DELETE, !m_bRootSelected );
// 'Cut', 'Copy' and 'Paste'
aContextMenu.EnableItem( SID_CUT, !m_bRootSelected && implAllowExchange( DND_ACTION_MOVE ) );
aContextMenu.EnableItem( SID_COPY, !m_bRootSelected && implAllowExchange( DND_ACTION_COPY ) );
aContextMenu.EnableItem( SID_PASTE, implAcceptPaste( ) );
// der TabDialog, wenn es genau ein Formular ist ...
aContextMenu.EnableItem( SID_FM_TAB_DIALOG, bSingleSelection && m_nFormsSelected );
// in XML forms, we don't allow for the properties of a form
// #i36484#
if ( pFormShell->GetImpl()->isEnhancedForm() && !m_nControlsSelected )
aContextMenu.RemoveItem( aContextMenu.GetItemPos( SID_FM_SHOW_PROPERTY_BROWSER ) );
// if the property browser is already open, we don't allow for the properties, too
if( pFormShell->GetImpl()->IsPropBrwOpen() )
aContextMenu.RemoveItem( aContextMenu.GetItemPos( SID_FM_SHOW_PROPERTY_BROWSER ) );
// and finally, if there's a mixed selection of forms and controls, disable the entry, too
else
aContextMenu.EnableItem( SID_FM_SHOW_PROPERTY_BROWSER,
(m_nControlsSelected && !m_nFormsSelected) || (!m_nControlsSelected && m_nFormsSelected) );
// Umbenennen gdw wenn ein Element und nicht die Root
aContextMenu.EnableItem( SID_FM_RENAME_OBJECT, bSingleSelection && !m_bRootSelected );
// der Reandonly-Eintrag ist nur auf der Root erlaubt
aContextMenu.EnableItem( SID_FM_OPEN_READONLY, m_bRootSelected );
// the same for automatic control focus
aContextMenu.EnableItem( SID_FM_AUTOCONTROLFOCUS, m_bRootSelected );
// die ConvertTo-Slots sind enabled, wenn genau ein Control selektiert ist, der
// dem Control entsprechende Slot ist disabled
if (!m_bRootSelected && !m_nFormsSelected && (m_nControlsSelected == 1))
{
aContextMenu.SetPopupMenu( SID_FM_CHANGECONTROLTYPE, FmXFormShell::GetConversionMenu() );
#if OSL_DEBUG_LEVEL > 0
FmControlData* pCurrent = (FmControlData*)(*m_arrCurrentSelection.begin())->GetUserData();
OSL_ENSURE( pFormShell->GetImpl()->isSolelySelected( pCurrent->GetFormComponent() ),
"NavigatorTree::Command: inconsistency between the navigator selection, and the selection as the shell knows it!" );
#endif
pFormShell->GetImpl()->checkControlConversionSlotsForCurrentSelection( *aContextMenu.GetPopupMenu( SID_FM_CHANGECONTROLTYPE ) );
}
else
aContextMenu.EnableItem( SID_FM_CHANGECONTROLTYPE, false );
// jetzt alles, was disabled wurde, wech
aContextMenu.RemoveDisabledEntries(true, true);
// OpenReadOnly setzen
aContextMenu.CheckItem( SID_FM_OPEN_READONLY, pFormModel->GetOpenInDesignMode() );
aContextMenu.CheckItem( SID_FM_AUTOCONTROLFOCUS, pFormModel->GetAutoControlFocus() );
sal_uInt16 nSlotId = aContextMenu.Execute( this, ptWhere );
switch( nSlotId )
{
case SID_FM_NEW_FORM:
{
OUString aStr(SVX_RESSTR(RID_STR_FORM));
OUString aUndoStr = SVX_RESSTR(RID_STR_UNDO_CONTAINER_INSERT).replaceAll(OUString('#'), aStr);
pFormModel->BegUndo(aUndoStr);
// der Slot war nur verfuegbar, wenn es genau einen selektierten Eintrag gibt und dieser die Root
// oder ein Formular ist
NewForm( *m_arrCurrentSelection.begin() );
pFormModel->EndUndo();
} break;
case SID_FM_NEW_HIDDEN:
{
OUString aStr(SVX_RESSTR(RID_STR_CONTROL));
OUString aUndoStr = SVX_RESSTR(RID_STR_UNDO_CONTAINER_INSERT).replaceAll(OUString('#'), aStr);
pFormModel->BegUndo(aUndoStr);
// dieser Slot war guletig bei (genau) einem selektierten Formular
OUString fControlName = FM_COMPONENT_HIDDEN;
NewControl( fControlName, *m_arrCurrentSelection.begin() );
pFormModel->EndUndo();
} break;
case SID_CUT:
doCut();
break;
case SID_COPY:
doCopy();
break;
case SID_PASTE:
doPaste();
break;
case SID_FM_DELETE:
{
DeleteSelection();
}
break;
case SID_FM_TAB_DIALOG:
{
// dieser Slot galt bei genau einem selektierten Formular
SvTreeListEntry* pSelectedForm = *m_arrCurrentSelection.begin();
DBG_ASSERT( IsFormEntry(pSelectedForm), "NavigatorTree::Command: Dieser Eintrag muss ein FormEntry sein." );
FmFormData* pFormData = (FmFormData*)pSelectedForm->GetUserData();
Reference< XForm > xForm( pFormData->GetFormIface());
Reference< XTabControllerModel > xTabController(xForm, UNO_QUERY);
if( !xTabController.is() )
break;
GetNavModel()->GetFormShell()->GetImpl()->ExecuteTabOrderDialog( xTabController );
}
break;
case SID_FM_SHOW_PROPERTY_BROWSER:
{
ShowSelectionProperties(true);
}
break;
case SID_FM_RENAME_OBJECT:
{
// das war bei genau einem Nicht-Root-Eintrag erlaubt
EditEntry( *m_arrCurrentSelection.begin() );
}
break;
case SID_FM_OPEN_READONLY:
{
pFormModel->SetOpenInDesignMode( !pFormModel->GetOpenInDesignMode() );
pFormShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_OPEN_READONLY);
}
break;
case SID_FM_AUTOCONTROLFOCUS:
{
pFormModel->SetAutoControlFocus( !pFormModel->GetAutoControlFocus() );
pFormShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_AUTOCONTROLFOCUS);
}
break;
default:
if (FmXFormShell::isControlConversionSlot(nSlotId))
{
FmControlData* pCurrent = (FmControlData*)(*m_arrCurrentSelection.begin())->GetUserData();
if ( pFormShell->GetImpl()->executeControlConversionSlot( pCurrent->GetFormComponent(), nSlotId ) )
ShowSelectionProperties();
}
}
}
bHandled = true;
} break;
}
if (!bHandled)
SvTreeListBox::Command( rEvt );
}
SvTreeListEntry* NavigatorTree::FindEntry( FmEntryData* pEntryData )
{
if( !pEntryData ) return NULL;
SvTreeListEntry* pCurEntry = First();
FmEntryData* pCurEntryData;
while( pCurEntry )
{
pCurEntryData = (FmEntryData*)pCurEntry->GetUserData();
if( pCurEntryData && pCurEntryData->IsEqualWithoutChildren(pEntryData) )
return pCurEntry;
pCurEntry = Next( pCurEntry );
}
return NULL;
}
void NavigatorTree::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
{
if( rHint.ISA(FmNavRemovedHint) )
{
FmNavRemovedHint* pRemovedHint = (FmNavRemovedHint*)&rHint;
FmEntryData* pEntryData = pRemovedHint->GetEntryData();
Remove( pEntryData );
}
else if( rHint.ISA(FmNavInsertedHint) )
{
FmNavInsertedHint* pInsertedHint = (FmNavInsertedHint*)&rHint;
FmEntryData* pEntryData = pInsertedHint->GetEntryData();
sal_uInt32 nRelPos = pInsertedHint->GetRelPos();
Insert( pEntryData, nRelPos );
}
else if( rHint.ISA(FmNavModelReplacedHint) )
{
FmEntryData* pData = ((FmNavModelReplacedHint*)&rHint)->GetEntryData();
SvTreeListEntry* pEntry = FindEntry( pData );
if (pEntry)
{ // das Image neu setzen
SetCollapsedEntryBmp( pEntry, pData->GetNormalImage() );
SetExpandedEntryBmp( pEntry, pData->GetNormalImage() );
}
}
else if( rHint.ISA(FmNavNameChangedHint) )
{
FmNavNameChangedHint* pNameChangedHint = (FmNavNameChangedHint*)&rHint;
SvTreeListEntry* pEntry = FindEntry( pNameChangedHint->GetEntryData() );
SetEntryText( pEntry, pNameChangedHint->GetNewName() );
}
else if( rHint.ISA(FmNavClearedHint) )
{
SvTreeListBox::Clear();
// Default-Eintrag "Formulare"
Image aRootImage( m_aNavigatorImages.GetImage( RID_SVXIMG_FORMS ) );
m_pRootEntry = InsertEntry( SVX_RESSTR(RID_STR_FORMS), aRootImage, aRootImage,
NULL, false, 0, NULL );
}
else if (!m_bMarkingObjects && rHint.ISA(FmNavRequestSelectHint))
{ // wenn m_bMarkingObjects sal_True ist, markiere ich gerade selber Objekte, und da der ganze Mechanismus dahinter synchron ist,
// ist das genau der Hint, der durch mein Markieren ausgeloest wird, also kann ich ihn ignorieren
FmNavRequestSelectHint* pershHint = (FmNavRequestSelectHint*)&rHint;
FmEntryDataArray& arredToSelect = pershHint->GetItems();
SynchronizeSelection(arredToSelect);
if (pershHint->IsMixedSelection())
// in diesem Fall habe ich alles deselektiert, obwohl die View u.U. eine gemischte Markierung hatte
// ich muss also im naechsten Select den Navigator an die View anpassen
m_bPrevSelectionMixed = true;
}
}
SvTreeListEntry* NavigatorTree::Insert( FmEntryData* pEntryData, sal_uIntPtr nRelPos )
{
// Aktuellen Eintrag einfuegen
SvTreeListEntry* pParentEntry = FindEntry( pEntryData->GetParent() );
SvTreeListEntry* pNewEntry;
if( !pParentEntry )
pNewEntry = InsertEntry( pEntryData->GetText(),
pEntryData->GetNormalImage(), pEntryData->GetNormalImage(),
m_pRootEntry, false, nRelPos, pEntryData );
else
pNewEntry = InsertEntry( pEntryData->GetText(),
pEntryData->GetNormalImage(), pEntryData->GetNormalImage(),
pParentEntry, false, nRelPos, pEntryData );
// Wenn Root-Eintrag Root expandieren
if( !pParentEntry )
Expand( m_pRootEntry );
// Children einfuegen
FmEntryDataList* pChildList = pEntryData->GetChildList();
size_t nChildCount = pChildList->size();
FmEntryData* pChildData;
for( size_t i = 0; i < nChildCount; i++ )
{
pChildData = pChildList->at( i );
Insert( pChildData, TREELIST_APPEND );
}
return pNewEntry;
}
void NavigatorTree::Remove( FmEntryData* pEntryData )
{
if( !pEntryData )
return;
// der Entry zu den Daten
SvTreeListEntry* pEntry = FindEntry( pEntryData );
if (!pEntry)
return;
// Eintrag aus TreeListBox entfernen
// ich darf das Select, das ich ausloese, nicht behandeln :
// Select aendert die MarkList der View, wenn das gerade auch jemand anders macht und dabei ein Remove
// triggert, haben wir mit ziemlicher Sicherheit ein Problem - Paradebeispiel war das Gruppieren von Controls mit
// offenem Navigator ...)
LockSelectionHandling();
// ein kleines Problem : ich merke mir meine selektierten Daten, wenn mir jetzt jemand einen selektierten Eintrag
// unter dem Hintern wegschiesst, werde ich inkonsistent ... was schlecht waere
Select(pEntry, false);
// beim eigentlichen Entfernen kann die Selection geaendert werden, da ich aber das SelectionHandling abgeschaltet
// habe, muss ich mich hinterher darum kuemmern
sal_uIntPtr nExpectedSelectionCount = GetSelectionCount();
if( pEntry )
GetModel()->Remove( pEntry );
if (nExpectedSelectionCount != GetSelectionCount())
SynchronizeSelection();
// und standardmaessig behandle ich das Select natuerlich
UnlockSelectionHandling();
}
bool NavigatorTree::IsFormEntry( SvTreeListEntry* pEntry )
{
FmEntryData* pEntryData = (FmEntryData*)pEntry->GetUserData();
return !pEntryData || pEntryData->ISA(FmFormData);
}
bool NavigatorTree::IsFormComponentEntry( SvTreeListEntry* pEntry )
{
FmEntryData* pEntryData = (FmEntryData*)pEntry->GetUserData();
return pEntryData && pEntryData->ISA(FmControlData);
}
bool NavigatorTree::implAcceptPaste( )
{
SvTreeListEntry* pFirstSelected = FirstSelected();
if ( !pFirstSelected || NextSelected( pFirstSelected ) )
// no selected entry, or at least two selected entries
return false;
// get the clipboard
TransferableDataHelper aClipboardContent( TransferableDataHelper::CreateFromSystemClipboard( this ) );
sal_Int8 nAction = m_aControlExchange.isClipboardOwner() && doingKeyboardCut( ) ? DND_ACTION_MOVE : DND_ACTION_COPY;
return ( nAction == implAcceptDataTransfer( aClipboardContent.GetDataFlavorExVector(), nAction, pFirstSelected, false ) );
}
sal_Int8 NavigatorTree::implAcceptDataTransfer( const DataFlavorExVector& _rFlavors, sal_Int8 _nAction, const ::Point& _rDropPos, bool _bDnD )
{
return implAcceptDataTransfer( _rFlavors, _nAction, GetEntry( _rDropPos ), _bDnD );
}
sal_Int8 NavigatorTree::implAcceptDataTransfer( const DataFlavorExVector& _rFlavors, sal_Int8 _nAction, SvTreeListEntry* _pTargetEntry, bool _bDnD )
{
// no target -> no drop
if (!_pTargetEntry)
return DND_ACTION_NONE;
// format check
bool bHasDefControlFormat = OControlExchange::hasFieldExchangeFormat( _rFlavors );
bool bHasControlPathFormat = OControlExchange::hasControlPathFormat( _rFlavors );
bool bHasHiddenControlsFormat = OControlExchange::hasHiddenControlModelsFormat( _rFlavors );
if (!bHasDefControlFormat && !bHasControlPathFormat && !bHasHiddenControlsFormat)
return DND_ACTION_NONE;
bool bSelfSource = _bDnD ? m_aControlExchange.isDragSource() : m_aControlExchange.isClipboardOwner();
if ( bHasHiddenControlsFormat )
{ // bHasHiddenControlsFormat means that only hidden controls are part of the data
// hidden controls can be copied to a form only
if ( !_pTargetEntry || ( _pTargetEntry == m_pRootEntry ) || !IsFormEntry( _pTargetEntry ) )
return DND_ACTION_NONE;
return bSelfSource ? ( DND_ACTION_COPYMOVE & _nAction ) : DND_ACTION_COPY;
}
if ( !bSelfSource )
{
// DnD or CnP crossing navigator boundaries
// The main problem here is that the current API does not allow us to sneak into the content which
// is to be inserted. So we have to allow it for the moment, but maybe reject later on (in the real drop).
// TODO: this smart behaviour later on ... at the moment, we disallow data transfer crossing navigator
// boundaries.
return DND_ACTION_NONE;
}
DBG_ASSERT( _bDnD ? m_aControlExchange.isDragSource() : m_aControlExchange.isClipboardOwner(),
"NavigatorTree::implAcceptDataTransfer: here only with source=dest!" );
// somebody changed the logic of this method ...
// from here on, I can work with m_aControlExchange instead of _rData!
bool bForeignCollection = m_aControlExchange->getFormsRoot().get() != GetNavModel()->GetFormPage()->GetForms().get();
if ( bForeignCollection )
{
// crossing shell/page boundaries, we can exchange hidden controls only
// But if we survived the checks above, we do not have hidden controls.
// -> no data transfer
DBG_ASSERT( !bHasHiddenControlsFormat, "NavigatorTree::implAcceptDataTransfer: still hidden controls format!" );
// somebody changed the logic of this method ...
return DND_ACTION_COPY;
}
if (DND_ACTION_MOVE != _nAction) // 'normal' controls within a shell are moved only (never copied)
return DND_ACTION_NONE;
if ( m_bDragDataDirty || !bHasDefControlFormat )
{
if (!bHasControlPathFormat)
// ich befinde mich zwar in der Shell/Page, aus der die Controls stammen, habe aber kein Format, das den stattgefundenen
// Shell-Wechsel ueberlebt hat (SVX_FM_CONTROLS_AS_PATH)
return DND_ACTION_NONE;
// da die Shell waehrend des Draggens umgeschaltet wude, muss ich die Liste des ExchangeObjektes wieder neu aufbauen
// (dort stehen SvLBoxEntries drin, und die sind bei der Umschaltung floeten gegangen)
m_aControlExchange->buildListFromPath(this, m_pRootEntry);
m_bDragDataDirty = false;
}
// die Liste der gedroppten Eintraege aus dem DragServer
const ListBoxEntrySet& aDropped = m_aControlExchange->selected();
DBG_ASSERT(aDropped.size() >= 1, "NavigatorTree::implAcceptDataTransfer: keine Eintraege !");
bool bDropTargetIsComponent = IsFormComponentEntry( _pTargetEntry );
//SvTreeListEntry* pDropTargetParent = GetParent( _pTargetEntry );
// conditions to disallow the drop
// 0) the root entry is part of the list (can't DnD the root!)
// 1) one of the draged entries is to be dropped onto it's own parent
// 2) - " - is to be dropped onto itself
// 3) - " - is a Form and to be dropped onto one of it's descendants
// 4) one of the entries is a control and to be dropped onto the root
// 5) a control or form will be dropped onto a control which is _not_ a sibling (dropping onto a sibling
// means moving the control)
// collect the ancestors of the drop targte (speeds up 3)
SvLBoxEntrySortedArray arrDropAnchestors;
SvTreeListEntry* pLoop = _pTargetEntry;
while (pLoop)
{
arrDropAnchestors.insert(pLoop);
pLoop = GetParent(pLoop);
}
for ( ListBoxEntrySet::const_iterator dropped = aDropped.begin();
dropped != aDropped.end();
++dropped
)
{
SvTreeListEntry* pCurrent = *dropped;
SvTreeListEntry* pCurrentParent = GetParent(pCurrent);
// test for 0)
if (pCurrent == m_pRootEntry)
return DND_ACTION_NONE;
// test for 1)
if ( _pTargetEntry == pCurrentParent )
return DND_ACTION_NONE;
// test for 2)
if (pCurrent == _pTargetEntry)
return DND_ACTION_NONE;
// test for 5)
// if ( bDropTargetIsComponent && (pDropTargetParent != pCurrentParent) )
if ( bDropTargetIsComponent ) // TODO : die obige Zeile wieder rein, dann muss aber ExecuteDrop das Vertauschen auch beherrschen
return DND_ACTION_NONE;
// test for 3)
if ( IsFormEntry(pCurrent) )
{
if ( arrDropAnchestors.find(pCurrent) != arrDropAnchestors.end() )
return DND_ACTION_NONE;
} else if ( IsFormComponentEntry(pCurrent) )
{
// test for 4)
if (_pTargetEntry == m_pRootEntry)
return DND_ACTION_NONE;
}
}
return DND_ACTION_MOVE;
}
sal_Int8 NavigatorTree::AcceptDrop( const AcceptDropEvent& rEvt )
{
::Point aDropPos = rEvt.maPosPixel;
// kuemmern wir uns erst mal um moeglich DropActions (Scrollen und Aufklappen)
if (rEvt.mbLeaving)
{
if (m_aDropActionTimer.IsActive())
m_aDropActionTimer.Stop();
} else
{
bool bNeedTrigger = false;
// auf dem ersten Eintrag ?
if ((aDropPos.Y() >= 0) && (aDropPos.Y() < GetEntryHeight()))
{
m_aDropActionType = DA_SCROLLUP;
bNeedTrigger = true;
} else
// auf dem letzten (bzw. in dem Bereich, den ein Eintrag einnehmen wuerde, wenn er unten genau buendig
// abschliessen wuerde) ?
if ((aDropPos.Y() < GetSizePixel().Height()) && (aDropPos.Y() >= GetSizePixel().Height() - GetEntryHeight()))
{
m_aDropActionType = DA_SCROLLDOWN;
bNeedTrigger = true;
} else
{ // auf einem Entry mit Children, der nicht aufgeklappt ist ?
SvTreeListEntry* pDropppedOn = GetEntry(aDropPos);
if (pDropppedOn && (GetChildCount(pDropppedOn) > 0) && !IsExpanded(pDropppedOn))
{
// -> aufklappen
m_aDropActionType = DA_EXPANDNODE;
bNeedTrigger = true;
}
}
if (bNeedTrigger && (m_aTimerTriggered != aDropPos))
{
// neu anfangen zu zaehlen
m_aTimerCounter = DROP_ACTION_TIMER_INITIAL_TICKS;
// die Pos merken, da ich auch AcceptDrops bekomme, wenn sich die Maus gar nicht bewegt hat
m_aTimerTriggered = aDropPos;
// und den Timer los
if (!m_aDropActionTimer.IsActive()) // gibt es den Timer schon ?
{
m_aDropActionTimer.SetTimeout(DROP_ACTION_TIMER_TICK_BASE);
m_aDropActionTimer.Start();
}
} else if (!bNeedTrigger)
m_aDropActionTimer.Stop();
}
return implAcceptDataTransfer( GetDataFlavorExVector(), rEvt.mnAction, aDropPos, true );
}
sal_Int8 NavigatorTree::implExecuteDataTransfer( const OControlTransferData& _rData, sal_Int8 _nAction, const ::Point& _rDropPos, bool _bDnD )
{
return implExecuteDataTransfer( _rData, _nAction, GetEntry( _rDropPos ), _bDnD );
}
sal_Int8 NavigatorTree::implExecuteDataTransfer( const OControlTransferData& _rData, sal_Int8 _nAction, SvTreeListEntry* _pTargetEntry, bool _bDnD )
{
const DataFlavorExVector& rDataFlavors = _rData.GetDataFlavorExVector();
if ( DND_ACTION_NONE == implAcceptDataTransfer( rDataFlavors, _nAction, _pTargetEntry, _bDnD ) )
// under some platforms, it may happen that ExecuteDrop is called though AcceptDrop returned DND_ACTION_NONE
return DND_ACTION_NONE;
// ware schlecht, wenn nach dem Droppen noch gescrollt wird ...
if (m_aDropActionTimer.IsActive())
m_aDropActionTimer.Stop();
if (!_pTargetEntry)
// no target -> no drop
return DND_ACTION_NONE;
// format checks
#ifdef DBG_UTIL
bool bHasHiddenControlsFormat = OControlExchange::hasHiddenControlModelsFormat( rDataFlavors );
bool bForeignCollection = _rData.getFormsRoot().get() != GetNavModel()->GetFormPage()->GetForms().get();
DBG_ASSERT(!bForeignCollection || bHasHiddenControlsFormat, "NavigatorTree::implExecuteDataTransfer: invalid format (AcceptDrop shouldn't have let this pass) !");
DBG_ASSERT(bForeignCollection || !m_bDragDataDirty, "NavigatorTree::implExecuteDataTransfer: invalid state (shell changed since last exchange resync) !");
// das sollte in AcceptDrop erledigt worden sein : dort wird in _rData die Liste der Controls aufgebaut und m_bDragDataDirty
// zurueckgesetzt
#endif
if ( DND_ACTION_COPY == _nAction )
{ // bHasHiddenControlsFormat means that only hidden controls are part of the data
DBG_ASSERT( bHasHiddenControlsFormat, "NavigatorTree::implExecuteDataTransfer: copy allowed for hidden controls only!" );
DBG_ASSERT( _pTargetEntry && ( _pTargetEntry != m_pRootEntry ) && IsFormEntry( _pTargetEntry ),
"NavigatorTree::implExecuteDataTransfer: should not be here!" );
// implAcceptDataTransfer should have caught both cases
DBG_ASSERT(bHasHiddenControlsFormat, "NavigatorTree::implExecuteDataTransfer: only copying of hidden controls is supported !");
// das sollte das AcceptDrop abgefangen haben
// da ich gleich die Zielobjekte alle selektieren will (und nur die)
SelectAll(false);
Sequence< Reference< XInterface > > aControls = _rData.hiddenControls();
sal_Int32 nCount = aControls.getLength();
const Reference< XInterface >* pControls = aControls.getConstArray();
FmFormShell* pFormShell = GetNavModel()->GetFormShell();
FmFormModel* pFormModel = pFormShell ? pFormShell->GetFormModel() : NULL;
// innerhalb eines Undo ...
if (pFormModel)
{
OUString aStr(SVX_RESSTR(RID_STR_CONTROL));
OUString aUndoStr = SVX_RESSTR(RID_STR_UNDO_CONTAINER_INSERT).replaceAll(OUString('#'), aStr);
pFormModel->BegUndo(aUndoStr);
}
// die Conrtols kopieren
for (sal_Int32 i=0; i<nCount; ++i)
{
// neues Control anlegen
OUString fControlName = FM_COMPONENT_HIDDEN;
FmControlData* pNewControlData = NewControl( fControlName, _pTargetEntry, false);
Reference< XPropertySet > xNewPropSet( pNewControlData->GetPropertySet() );
// und die Properties des alten in das neue kopieren
Reference< XPropertySet > xCurrent(pControls[i], UNO_QUERY);
#if (OSL_DEBUG_LEVEL > 1)
// nur mal eben sehen, ob das Ding tatsaechlich ein hidden control ist
sal_Int16 nClassId = ::comphelper::getINT16(xCurrent->getPropertyValue(FM_PROP_CLASSID));
OSL_ENSURE(nClassId == FormComponentType::HIDDENCONTROL, "NavigatorTree::implExecuteDataTransfer: invalid control in drop list !");
// wenn das SVX_FM_HIDDEN_CONTROLS-Format vorhanden ist, dann sollten wirklich nur hidden controls in der Sequenz
// stecken
#endif // (OSL_DEBUG_LEVEL > 1)
Reference< XPropertySetInfo > xPropInfo( xCurrent->getPropertySetInfo());
Sequence< Property> seqAllCurrentProps = xPropInfo->getProperties();
Property* pAllCurrentProps = seqAllCurrentProps.getArray();
for (sal_Int32 j=0; j<seqAllCurrentProps.getLength(); ++j)
{
OUString sCurrentProp = pAllCurrentProps[j].Name;
if (((pAllCurrentProps[j].Attributes & PropertyAttribute::READONLY) == 0) && (sCurrentProp != FM_PROP_NAME))
{ // (read-only attribs werden natuerlich nicht gesetzt, dito der Name, den hat das NewControl schon eindeutig
// festgelegt)
xNewPropSet->setPropertyValue(sCurrentProp, xCurrent->getPropertyValue(sCurrentProp));
}
}
SvTreeListEntry* pToSelect = FindEntry(pNewControlData);
Select(pToSelect, true);
if (i == 0)
SetCurEntry(pToSelect);
}
if (pFormModel)
pFormModel->EndUndo();
return _nAction;
}
if ( !OControlExchange::hasFieldExchangeFormat( _rData.GetDataFlavorExVector() ) )
{
// can't do anything without the internal format here ... usually happens when doing DnD or CnP
// over navigator boundaries
return DND_ACTION_NONE;
}
// some data for the target
bool bDropTargetIsForm = IsFormEntry(_pTargetEntry);
FmFormData* pTargetData = bDropTargetIsForm ? (FmFormData*)_pTargetEntry->GetUserData() : NULL;
DBG_ASSERT( DND_ACTION_COPY != _nAction, "NavigatorTree::implExecuteDataTransfer: somebody changed the logics!" );
// die Liste der gedraggten Eintraege
ListBoxEntrySet aDropped = _rData.selected();
DBG_ASSERT(aDropped.size() >= 1, "NavigatorTree::implExecuteDataTransfer: no entries!");
// die Shell und das Model
FmFormShell* pFormShell = GetNavModel()->GetFormShell();
FmFormModel* pFormModel = pFormShell ? pFormShell->GetFormModel() : NULL;
if (!pFormModel)
return DND_ACTION_NONE;
// fuer's Undo
const bool bUndo = pFormModel->IsUndoEnabled();
if( bUndo )
{
OUString strUndoDescription(SVX_RESSTR(RID_STR_UNDO_CONTAINER_REPLACE));
pFormModel->BegUndo(strUndoDescription);
}
// ich nehme vor dem Einfuegen eines Eintrages seine Selection raus, damit die Markierung dabei nicht flackert
// -> das Handeln des Select locken
LockSelectionHandling();
// jetzt durch alle gedroppten Eintraege ...
for ( ListBoxEntrySet::const_iterator dropped = aDropped.begin();
dropped != aDropped.end();
++dropped
)
{
// ein paar Daten zum aktuellen Element
SvTreeListEntry* pCurrent = *dropped;
DBG_ASSERT(pCurrent != NULL, "NavigatorTree::implExecuteDataTransfer: ungueltiger Eintrag");
DBG_ASSERT(GetParent(pCurrent) != NULL, "NavigatorTree::implExecuteDataTransfer: ungueltiger Eintrag");
// die Root darf nicht gedraggt werden
FmEntryData* pCurrentUserData = (FmEntryData*)pCurrent->GetUserData();
Reference< XChild > xCurrentChild(pCurrentUserData->GetChildIFace(), UNO_QUERY);
Reference< XIndexContainer > xContainer(xCurrentChild->getParent(), UNO_QUERY);
FmFormData* pCurrentParentUserData = (FmFormData*)pCurrentUserData->GetParent();
DBG_ASSERT(pCurrentParentUserData == NULL || pCurrentParentUserData->ISA(FmFormData), "NavigatorTree::implExecuteDataTransfer: ungueltiges Parent");
// beim Vater austragen
if (pCurrentParentUserData)
pCurrentParentUserData->GetChildList()->remove( pCurrentUserData );
else
GetNavModel()->GetRootList()->remove( pCurrentUserData );
// aus dem Container entfernen
sal_Int32 nIndex = getElementPos(xContainer, xCurrentChild);
GetNavModel()->m_pPropChangeList->Lock();
// die Undo-Action fuer das Rausnehmen
if ( bUndo && GetNavModel()->m_pPropChangeList->CanUndo())
{
pFormModel->AddUndo(new FmUndoContainerAction(*pFormModel, FmUndoContainerAction::Removed,
xContainer, xCurrentChild, nIndex));
}
else if( !GetNavModel()->m_pPropChangeList->CanUndo() )
{
FmUndoContainerAction::DisposeElement( xCurrentChild );
}
// Events mitkopieren
Reference< XEventAttacherManager > xManager(xContainer, UNO_QUERY);
Sequence< ScriptEventDescriptor > aEvts;
if (xManager.is() && nIndex >= 0)
aEvts = xManager->getScriptEvents(nIndex);
xContainer->removeByIndex(nIndex);
// die Selection raus
Select(pCurrent, false);
// und weg
Remove(pCurrentUserData);
// die Stelle innerhalb des DropParents, an der ich die gedroppten Eintraege einfuegen muss
if (pTargetData)
xContainer = Reference< XIndexContainer > (pTargetData->GetElement(), UNO_QUERY);
else
xContainer = Reference< XIndexContainer > (GetNavModel()->GetForms(), UNO_QUERY);
// immer ganz hinten einfuegen
nIndex = xContainer->getCount();
// UndoAction fuer das Einfuegen
if ( bUndo && GetNavModel()->m_pPropChangeList->CanUndo())
pFormModel->AddUndo(new FmUndoContainerAction(*pFormModel, FmUndoContainerAction::Inserted,
xContainer, xCurrentChild, nIndex));
// einfuegen im neuen Container
if (pTargetData)
{
// es wird in eine Form eingefuegt, dann brauche ich eine FormComponent
xContainer->insertByIndex( nIndex,
makeAny( Reference< XFormComponent >( xCurrentChild, UNO_QUERY ) ) );
}
else
{
xContainer->insertByIndex( nIndex,
makeAny( Reference< XForm >( xCurrentChild, UNO_QUERY ) ) );
}
if (aEvts.getLength())
{
xManager = Reference< XEventAttacherManager > (xContainer, UNO_QUERY);
if (xManager.is())
xManager->registerScriptEvents(nIndex, aEvts);
}
GetNavModel()->m_pPropChangeList->UnLock();
// zuerst dem Eintrag das neue Parent
pCurrentUserData->SetParent(pTargetData);
// dann dem Parent das neue Child
if (pTargetData)
pTargetData->GetChildList()->insert( pCurrentUserData, nIndex );
else
GetNavModel()->GetRootList()->insert( pCurrentUserData, nIndex );
// dann bei mir selber bekanntgeben und neu selektieren
SvTreeListEntry* pNew = Insert( pCurrentUserData, nIndex );
if ( ( aDropped.begin() == dropped ) && pNew )
{
SvTreeListEntry* pParent = GetParent( pNew );
if ( pParent )
Expand( pParent );
}
}
UnlockSelectionHandling();
if( bUndo )
pFormModel->EndUndo();
// During the move, the markings of the underlying view did not change (because the view is not affected by the logical
// hierarchy of the form/control models. But my selection changed - which means I have to adjust it according to the
// view marks, again.
SynchronizeSelection();
// in addition, with the move of controls such things as "the current form" may have changed - force the shell
// to update itself accordingly
if( pFormShell && pFormShell->GetImpl() && pFormShell->GetFormView() )
pFormShell->GetImpl()->DetermineSelection( pFormShell->GetFormView()->GetMarkedObjectList() );
if ( m_aControlExchange.isClipboardOwner() && ( DND_ACTION_MOVE == _nAction ) )
m_aControlExchange->clear();
return _nAction;
}
sal_Int8 NavigatorTree::ExecuteDrop( const ExecuteDropEvent& rEvt )
{
sal_Int8 nResult( DND_ACTION_NONE );
if ( m_aControlExchange.isDragSource() )
nResult = implExecuteDataTransfer( *m_aControlExchange, rEvt.mnAction, rEvt.maPosPixel, true );
else
{
OControlTransferData aDroppedData( rEvt.maDropEvent.Transferable );
nResult = implExecuteDataTransfer( aDroppedData, rEvt.mnAction, rEvt.maPosPixel, true );
}
return nResult;
}
void NavigatorTree::doPaste()
{
try
{
if ( m_aControlExchange.isClipboardOwner() )
{
implExecuteDataTransfer( *m_aControlExchange, doingKeyboardCut( ) ? DND_ACTION_MOVE : DND_ACTION_COPY, FirstSelected(), false );
}
else
{
// the clipboard content
Reference< XClipboard > xClipboard( GetClipboard() );
Reference< XTransferable > xTransferable;
if ( xClipboard.is() )
xTransferable = xClipboard->getContents();
OControlTransferData aClipboardContent( xTransferable );
implExecuteDataTransfer( aClipboardContent, DND_ACTION_COPY, FirstSelected(), false );
}
}
catch( const Exception& )
{
OSL_FAIL( "NavigatorTree::doPaste: caught an exception!" );
}
}
void NavigatorTree::doCopy()
{
if ( implPrepareExchange( DND_ACTION_COPY ) )
{
m_aControlExchange.setClipboardListener( LINK( this, NavigatorTree, OnClipboardAction ) );
m_aControlExchange.copyToClipboard( );
}
}
void NavigatorTree::ModelHasRemoved( SvTreeListEntry* _pEntry )
{
SvTreeListEntry* pTypedEntry = static_cast< SvTreeListEntry* >( _pEntry );
if ( doingKeyboardCut() )
m_aCutEntries.erase( pTypedEntry );
if ( m_aControlExchange.isDataExchangeActive() )
{
if ( 0 == m_aControlExchange->onEntryRemoved( pTypedEntry ) )
{
// last of the entries which we put into the clipboard has been deleted from the tree.
// Give up the clipboard ownership.
m_aControlExchange.clear();
}
}
}
void NavigatorTree::doCut()
{
if ( implPrepareExchange( DND_ACTION_MOVE ) )
{
m_aControlExchange.setClipboardListener( LINK( this, NavigatorTree, OnClipboardAction ) );
m_aControlExchange.copyToClipboard( );
m_bKeyboardCut = true;
// mark all the entries we just "cut" into the clipboard as "nearly moved"
for ( SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
it != m_arrCurrentSelection.end(); ++it )
{
SvTreeListEntry* pEntry = *it;
if ( pEntry )
{
m_aCutEntries.insert( pEntry );
pEntry->SetFlags( pEntry->GetFlags() | SV_ENTRYFLAG_SEMITRANSPARENT );
InvalidateEntry( pEntry );
}
}
}
}
void NavigatorTree::KeyInput(const ::KeyEvent& rKEvt)
{
const KeyCode& rCode = rKEvt.GetKeyCode();
// delete?
if (rKEvt.GetKeyCode().GetCode() == KEY_DELETE && !rKEvt.GetKeyCode().GetModifier())
{
DeleteSelection();
return;
}
// copy'n'paste?
switch ( rCode.GetFunction() )
{
case KEYFUNC_CUT:
doCut();
break;
case KEYFUNC_PASTE:
if ( implAcceptPaste() )
doPaste();
break;
case KEYFUNC_COPY:
doCopy();
break;
default:
break;
}
SvTreeListBox::KeyInput(rKEvt);
}
bool NavigatorTree::EditingEntry( SvTreeListEntry* pEntry, ::Selection& rSelection )
{
if (!SvTreeListBox::EditingEntry( pEntry, rSelection ))
return false;
return (pEntry && (pEntry->GetUserData() != NULL));
// die Wurzel, die ich nicht umbenennen darf, hat als UserData NULL
}
void NavigatorTree::NewForm( SvTreeListEntry* pParentEntry )
{
// ParentFormData holen
if( !IsFormEntry(pParentEntry) )
return;
FmFormData* pParentFormData = (FmFormData*)pParentEntry->GetUserData();
// Neue Form erzeugen
Reference<XComponentContext> xContext = comphelper::getProcessComponentContext();
Reference< XForm > xNewForm(xContext->getServiceManager()->createInstanceWithContext(FM_SUN_COMPONENT_FORM, xContext), UNO_QUERY);
if (!xNewForm.is())
return;
FmFormData* pNewFormData = new FmFormData( xNewForm, m_aNavigatorImages, pParentFormData );
// Namen setzen
OUString aName = GenerateName(pNewFormData);
pNewFormData->SetText(aName);
Reference< XPropertySet > xPropertySet(xNewForm, UNO_QUERY);
if (!xPropertySet.is())
return;
try
{
xPropertySet->setPropertyValue( FM_PROP_NAME, makeAny(aName) );
// a form should always have the command type table as default
xPropertySet->setPropertyValue( FM_PROP_COMMANDTYPE, makeAny(sal_Int32(CommandType::TABLE)));
}
catch ( const Exception& )
{
OSL_FAIL("NavigatorTree::NewForm : could not set esssential properties !");
}
// Form einfuegen
GetNavModel()->Insert( pNewFormData, TREELIST_APPEND, true );
// Neue Form als aktive Form setzen
FmFormShell* pFormShell = GetNavModel()->GetFormShell();
if( pFormShell )
{
InterfaceBag aSelection;
aSelection.insert( Reference<XInterface>( xNewForm, UNO_QUERY ) );
pFormShell->GetImpl()->setCurrentSelection( aSelection );
pFormShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_PROPERTIES, true, true);
}
GetNavModel()->SetModified();
// In EditMode schalten
SvTreeListEntry* pNewEntry = FindEntry( pNewFormData );
EditEntry( pNewEntry );
}
FmControlData* NavigatorTree::NewControl( const OUString& rServiceName, SvTreeListEntry* pParentEntry, bool bEditName )
{
// ParentForm holen
if (!GetNavModel()->GetFormShell())
return NULL;
if (!IsFormEntry(pParentEntry))
return NULL;
FmFormData* pParentFormData = (FmFormData*)pParentEntry->GetUserData();;
Reference< XForm > xParentForm( pParentFormData->GetFormIface());
// Neue Component erzeugen
Reference<XComponentContext> xContext = comphelper::getProcessComponentContext();
Reference<XFormComponent> xNewComponent( xContext->getServiceManager()->createInstanceWithContext(rServiceName, xContext), UNO_QUERY);
if (!xNewComponent.is())
return NULL;
FmControlData* pNewFormControlData = new FmControlData( xNewComponent, m_aNavigatorImages, pParentFormData );
// Namen setzen
FmFormView* pFormView = GetNavModel()->GetFormShell()->GetFormView();
SdrPageView* pPageView = pFormView->GetSdrPageView();
FmFormPage* pPage = (FmFormPage*)pPageView->GetPage();
OUString sName = pPage->GetImpl().setUniqueName( xNewComponent, xParentForm );
pNewFormControlData->SetText( sName );
// FormComponent einfuegen
GetNavModel()->Insert( pNewFormControlData, TREELIST_APPEND, true );
GetNavModel()->SetModified();
if (bEditName)
{
// In EditMode schalten
SvTreeListEntry* pNewEntry = FindEntry( pNewFormControlData );
Select( pNewEntry, true );
EditEntry( pNewEntry );
}
return pNewFormControlData;
}
OUString NavigatorTree::GenerateName( FmEntryData* pEntryData )
{
const sal_uInt16 nMaxCount = 99;
OUString aNewName;
// BasisNamen erzeugen
OUString aBaseName;
if( pEntryData->ISA(FmFormData) )
aBaseName = SVX_RESSTR( RID_STR_STDFORMNAME );
else if( pEntryData->ISA(FmControlData) )
aBaseName = SVX_RESSTR( RID_STR_CONTROL );
// Neuen Namen erstellen
FmFormData* pFormParentData = (FmFormData*)pEntryData->GetParent();
for( sal_Int32 i=0; i<nMaxCount; i++ )
{
aNewName = aBaseName;
if( i>0 )
{
aNewName += " ";
aNewName += OUString::number(i).getStr();
}
if( GetNavModel()->FindData(aNewName, pFormParentData,false) == NULL )
break;
}
return aNewName;
}
bool NavigatorTree::EditedEntry( SvTreeListEntry* pEntry, const OUString& rNewText )
{
if (EditingCanceled())
return true;
GrabFocus();
FmEntryData* pEntryData = (FmEntryData*)pEntry->GetUserData();
bool bRes = GetNavModel()->Rename( pEntryData, rNewText);
if( !bRes )
{
m_pEditEntry = pEntry;
nEditEvent = Application::PostUserEvent( LINK(this, NavigatorTree, OnEdit) );
} else
SetCursor(pEntry, true);
return bRes;
}
IMPL_LINK_NOARG(NavigatorTree, OnEdit)
{
nEditEvent = 0;
EditEntry( m_pEditEntry );
m_pEditEntry = NULL;
return 0L;
}
IMPL_LINK_NOARG(NavigatorTree, OnDropActionTimer)
{
if (--m_aTimerCounter > 0)
return 0L;
switch ( m_aDropActionType )
{
case DA_EXPANDNODE:
{
SvTreeListEntry* pToExpand = GetEntry(m_aTimerTriggered);
if (pToExpand && (GetChildCount(pToExpand) > 0) && !IsExpanded(pToExpand))
// tja, eigentlich muesste ich noch testen, ob die Node nicht schon expandiert ist, aber ich
// habe dazu weder in den Basisklassen noch im Model eine Methode gefunden ...
// aber ich denke, die BK sollte es auch so vertragen
Expand(pToExpand);
// nach dem Expand habe ich im Gegensatz zum Scrollen natuerlich nix mehr zu tun
m_aDropActionTimer.Stop();
}
break;
case DA_SCROLLUP :
ScrollOutputArea( 1 );
m_aTimerCounter = DROP_ACTION_TIMER_SCROLL_TICKS;
break;
case DA_SCROLLDOWN :
ScrollOutputArea( -1 );
m_aTimerCounter = DROP_ACTION_TIMER_SCROLL_TICKS;
break;
}
return 0L;
}
IMPL_LINK(NavigatorTree, OnEntrySelDesel, NavigatorTree*, /*pThis*/)
{
m_sdiState = SDI_DIRTY;
if (IsSelectionHandlingLocked())
return 0L;
if (m_aSynchronizeTimer.IsActive())
m_aSynchronizeTimer.Stop();
m_aSynchronizeTimer.SetTimeout(EXPLORER_SYNC_DELAY);
m_aSynchronizeTimer.Start();
return 0L;
}
IMPL_LINK_NOARG(NavigatorTree, OnSynchronizeTimer)
{
SynchronizeMarkList();
return 0L;
}
IMPL_LINK_NOARG(NavigatorTree, OnClipboardAction)
{
if ( !m_aControlExchange.isClipboardOwner() )
{
if ( doingKeyboardCut() )
{
for ( ListBoxEntrySet::const_iterator i = m_aCutEntries.begin();
i != m_aCutEntries.end();
++i
)
{
SvTreeListEntry* pEntry = *i;
if ( !pEntry )
continue;
pEntry->SetFlags( pEntry->GetFlags() & ~SV_ENTRYFLAG_SEMITRANSPARENT );
InvalidateEntry( pEntry );
}
ListBoxEntrySet aEmpty;
m_aCutEntries.swap( aEmpty );
m_bKeyboardCut = false;
}
}
return 0L;
}
void NavigatorTree::ShowSelectionProperties(bool bForce)
{
// zuerst brauche ich die FormShell
FmFormShell* pFormShell = GetNavModel()->GetFormShell();
if (!pFormShell)
// keine Shell -> ich koennte kein curObject setzen -> raus
return;
CollectSelectionData(SDI_ALL);
SAL_WARN_IF(static_cast<size_t>(m_nFormsSelected + m_nControlsSelected
+ (m_bRootSelected ? 1 : 0)) != m_arrCurrentSelection.size(),
"svx.form",
"NavigatorTree::ShowSelectionProperties : selection meta data invalid !");
InterfaceBag aSelection;
bool bSetSelectionAsMarkList = false;
if (m_bRootSelected)
; // no properties for the root, neither for single nor for multi selection
else if ( m_nFormsSelected + m_nControlsSelected == 0 ) // none of the two should be less 0
; // no selection -> no properties
else if ( m_nFormsSelected * m_nControlsSelected != 0 )
; // mixed selection -> no properties
else
{ // either only forms, or only controls are selected
if (m_arrCurrentSelection.size() == 1)
{
if (m_nFormsSelected > 0)
{ // es ist genau eine Form selektiert
FmFormData* pFormData = (FmFormData*)(*m_arrCurrentSelection.begin())->GetUserData();
aSelection.insert( Reference< XInterface >( pFormData->GetFormIface(), UNO_QUERY ) );
}
else
{ // es ist genau ein Control selektiert (egal ob hidden oder normal)
FmEntryData* pEntryData = (FmEntryData*)(*m_arrCurrentSelection.begin())->GetUserData();
aSelection.insert( Reference< XInterface >( pEntryData->GetElement(), UNO_QUERY ) );
}
}
else
{ // wir haben eine MultiSelection, also muessen wir ein MultiSet dafuer aufbauen
if (m_nFormsSelected > 0)
{ // ... nur Forms
// erstmal die PropertySet-Interfaces der Forms einsammeln
SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
for ( sal_Int32 i = 0; i < m_nFormsSelected; ++i )
{
FmFormData* pFormData = (FmFormData*)(*it)->GetUserData();
aSelection.insert( pFormData->GetPropertySet().get() );
++it;
}
}
else
{ // ... nur Controls
if (m_nHiddenControls == m_nControlsSelected)
{ // ein MultiSet fuer die Properties der hidden controls
SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
for ( sal_Int32 i = 0; i < m_nHiddenControls; ++i )
{
FmEntryData* pEntryData = (FmEntryData*)(*it)->GetUserData();
aSelection.insert( pEntryData->GetPropertySet().get() );
++it;
}
}
else if (m_nHiddenControls == 0)
{ // nur normale Controls
bSetSelectionAsMarkList = true;
}
}
}
}
// und dann meine Form und mein SelObject
if ( bSetSelectionAsMarkList )
pFormShell->GetImpl()->setCurrentSelectionFromMark( pFormShell->GetFormView()->GetMarkedObjectList() );
else
pFormShell->GetImpl()->setCurrentSelection( aSelection );
if ( pFormShell->GetImpl()->IsPropBrwOpen() || bForce )
{
// und jetzt kann ich das Ganze dem PropertyBrowser uebergeben
pFormShell->GetViewShell()->GetViewFrame()->GetDispatcher()->Execute( SID_FM_SHOW_PROPERTY_BROWSER, SFX_CALLMODE_ASYNCHRON );
}
}
void NavigatorTree::DeleteSelection()
{
// die Root darf ich natuerlich nicht mitloeschen
bool bRootSelected = IsSelected(m_pRootEntry);
sal_uIntPtr nSelectedEntries = GetSelectionCount();
if (bRootSelected && (nSelectedEntries > 1)) // die Root plus andere Elemente ?
Select(m_pRootEntry, false); // ja -> die Root raus
if ((nSelectedEntries == 0) || bRootSelected) // immer noch die Root ?
return; // -> sie ist das einzige selektierte -> raus
DBG_ASSERT(!m_bPrevSelectionMixed, "NavigatorTree::DeleteSelection() : loeschen nicht erlaubt wenn Markierung und Selektion nciht konsistent");
// ich brauche unten das FormModel ...
FmFormShell* pFormShell = GetNavModel()->GetFormShell();
if (!pFormShell)
return;
FmFormModel* pFormModel = pFormShell->GetFormModel();
if (!pFormModel)
return;
// jetzt muss ich noch die DeleteList etwas absichern : wenn man ein Formular und ein abhaengiges
// Element loescht - und zwar in dieser Reihenfolge - dann ist der SvLBoxEntryPtr des abhaengigen Elementes
// natuerlich schon ungueltig, wenn es geloescht werden soll ... diesen GPF, den es dann mit Sicherheit gibt,
// gilt es zu verhindern, also die 'normalisierte' Liste
CollectSelectionData( SDI_NORMALIZED );
// see below for why we need this mapping from models to shapes
FmFormView* pFormView = pFormShell->GetFormView();
SdrPageView* pPageView = pFormView ? pFormView->GetSdrPageView() : NULL;
SdrPage* pPage = pPageView ? pPageView->GetPage() : NULL;
DBG_ASSERT( pPage, "NavigatorTree::DeleteSelection: invalid form page!" );
MapModelToShape aModelShapes;
if ( pPage )
collectShapeModelMapping( pPage, aModelShapes );
// problem: we have to use ExplorerModel::Remove, since only this one properly deletes Form objects.
// But, the controls themself must be deleted via DeleteMarked (else, the Writer has some problems
// somewhere). In case I'd first delete the structure, then the controls, the UNDO would not work
// (since UNDO then would mean to first restore the controls, then the structure, means their parent
// form). The other way round, the EntryDatas would be invalid, if I'd first delete the controls and
// then go on to the strucure. This means I have to delete the forms *after* the normal controls, so
// that during UNDO, they're restored in the proper order.
pFormShell->GetImpl()->EnableTrackProperties(false);
for (SvLBoxEntrySortedArray::reverse_iterator it = m_arrCurrentSelection.rbegin();
it != m_arrCurrentSelection.rend(); )
{
FmEntryData* pCurrent = (FmEntryData*)((*it)->GetUserData());
// eine Form ?
bool bIsForm = pCurrent->ISA(FmFormData);
// da ich das Loeschen im folgenden der View ueberlasse und dabei auf deren MarkList aufbaue, im Normalfall aber bei
// einem makierten Formular nur die direkt, nicht die indirekt abhaengigen Controls markiert werden, muss ich das hier
// noch nachholen
if (bIsForm)
MarkViewObj((FmFormData*)pCurrent, true, true); // das zweite sal_True heisst "deep"
// ein hidden control ?
bool bIsHidden = IsHiddenControl(pCurrent);
// Forms und hidden Controls muss ich behalten, alles andere nicht
if (!bIsForm && !bIsHidden)
{
// well, no form and no hidden control -> we can remove it from m_arrCurrentSelection, as it will
// be deleted automatically. This is because for every model (except forms and hidden control models)
// there exist a shape, which is marked _if_and_only_if_ the model is selected in our tree.
if ( aModelShapes.find( pCurrent->GetElement() ) != aModelShapes.end() )
{
// if there's a shape for the current entry, then either it is marked or it is in a
// hidden layer (#i28502#), or something like this.
// In the first case, it will be deleted below, in the second case, we currently don't
// delete it, as there's no real (working!) API for this, neither in UNO nor in non-UNO.
m_arrCurrentSelection.erase( --(it.base()) );
}
else
++it;
// In case there is no shape for the current entry, we keep the entry in m_arrCurrentSelection,
// since then we can definitely remove it.
// #103597#
}
else
++it;
}
pFormShell->GetImpl()->EnableTrackProperties(true);
// let the view delete the marked controls
pFormShell->GetFormView()->DeleteMarked();
// start UNDO at this point. Unfortunately, this results in 2 UNDO actions, since DeleteMarked is
// creating an own one. However, if we'd move it before DeleteMarked, Writer does not really like
// this ... :(
// #i31038#
{
// initialize UNDO
OUString aUndoStr;
if ( m_arrCurrentSelection.size() == 1 )
{
aUndoStr = SVX_RESSTR(RID_STR_UNDO_CONTAINER_REMOVE);
if (m_nFormsSelected)
aUndoStr = aUndoStr.replaceFirst( "#", SVX_RESSTR( RID_STR_FORM ) );
else
// it must be a control (else the root would be selected, but it cannot be deleted)
aUndoStr = aUndoStr.replaceFirst( "#", SVX_RESSTR( RID_STR_CONTROL ) );
}
else
{
aUndoStr = SVX_RESSTR(RID_STR_UNDO_CONTAINER_REMOVE_MULTIPLE);
aUndoStr = aUndoStr.replaceFirst( "#", OUString::number( m_arrCurrentSelection.size() ) );
}
pFormModel->BegUndo(aUndoStr);
}
// remove remaining structure
for (SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
it != m_arrCurrentSelection.end(); ++it)
{
FmEntryData* pCurrent = (FmEntryData*)((*it)->GetUserData());
// if the entry still has children, we skipped deletion of one of those children.
// This may for instance be because the shape is in a hidden layer, where we're unable
// to remove it
if ( pCurrent->GetChildList()->size() )
continue;
// noch ein kleines Problem, bevor ich das ganz loesche : wenn es eine Form ist und die Shell diese als CurrentObject
// kennt, dann muss ich ihr das natuerlich ausreden
if (pCurrent->ISA(FmFormData))
{
Reference< XForm > xCurrentForm( static_cast< FmFormData* >( pCurrent )->GetFormIface() );
if ( pFormShell->GetImpl()->getCurrentForm() == xCurrentForm ) // die Shell kennt die zu loeschende Form ?
pFormShell->GetImpl()->forgetCurrentForm(); // -> wegnehmen ...
}
GetNavModel()->Remove(pCurrent, true);
}
pFormModel->EndUndo();
}
void NavigatorTree::CollectSelectionData(SELDATA_ITEMS sdiHow)
{
DBG_ASSERT(sdiHow != SDI_DIRTY, "NavigatorTree::CollectSelectionData : ever thought about your parameter ? DIRTY ?");
if (sdiHow == m_sdiState)
return;
m_arrCurrentSelection.clear();
m_nFormsSelected = m_nControlsSelected = m_nHiddenControls = 0;
m_bRootSelected = false;
SvTreeListEntry* pSelectionLoop = FirstSelected();
while (pSelectionLoop)
{
// erst mal die Zaehlung der verschiedenen Elemente
if (pSelectionLoop == m_pRootEntry)
m_bRootSelected = true;
else
{
if (IsFormEntry(pSelectionLoop))
++m_nFormsSelected;
else
{
++m_nControlsSelected;
if (IsHiddenControl((FmEntryData*)(pSelectionLoop->GetUserData())))
++m_nHiddenControls;
}
}
if (sdiHow == SDI_NORMALIZED)
{
// alles, was schon einen selektierten Vorfahr hat, nicht mitnehmen
if (pSelectionLoop == m_pRootEntry)
m_arrCurrentSelection.insert(pSelectionLoop);
else
{
SvTreeListEntry* pParentLoop = GetParent(pSelectionLoop);
while (pParentLoop)
{
// eigentlich muesste ich testen, ob das Parent in der m_arrCurrentSelection steht ...
// Aber wenn es selektiert ist, dann steht es in m_arrCurrentSelection, oder wenigstens einer seiner Vorfahren,
// wenn der auch schon selektiert war. In beiden Faellen reicht also die Abfrage IsSelected
if (IsSelected(pParentLoop))
break;
else
{
if (m_pRootEntry == pParentLoop)
{
// bis (exclusive) zur Root gab es kein selektiertes Parent -> der Eintrag gehoert in die normalisierte Liste
m_arrCurrentSelection.insert(pSelectionLoop);
break;
}
else
pParentLoop = GetParent(pParentLoop);
}
}
}
}
else if (sdiHow == SDI_NORMALIZED_FORMARK)
{
SvTreeListEntry* pParent = GetParent(pSelectionLoop);
if (!pParent || !IsSelected(pParent) || IsFormEntry(pSelectionLoop))
m_arrCurrentSelection.insert(pSelectionLoop);
}
else
m_arrCurrentSelection.insert(pSelectionLoop);
pSelectionLoop = NextSelected(pSelectionLoop);
}
m_sdiState = sdiHow;
}
void NavigatorTree::SynchronizeSelection(FmEntryDataArray& arredToSelect)
{
LockSelectionHandling();
if (arredToSelect.empty())
{
SelectAll(false);
}
else
{
// erst mal gleiche ich meine aktuelle Selektion mit der geforderten SelectList ab
SvTreeListEntry* pSelection = FirstSelected();
while (pSelection)
{
FmEntryData* pCurrent = (FmEntryData*)pSelection->GetUserData();
if (pCurrent != NULL)
{
FmEntryDataArray::iterator it = arredToSelect.find(pCurrent);
if ( it != arredToSelect.end() )
{ // der Entry ist schon selektiert, steht aber auch in der SelectList -> er kann aus letzterer
// raus
arredToSelect.erase(it);
} else
{ // der Entry ist selektiert, aber steht nicht in der SelectList -> Selektion rausnehmen
Select(pSelection, false);
// und sichtbar machen (kann ja sein, dass das die einzige Modifikation ist, die ich hier in dem
// ganzen Handler mache, dann sollte das zu sehen sein)
MakeVisible(pSelection);
}
}
else
Select(pSelection, false);
pSelection = NextSelected(pSelection);
}
// jetzt habe ich in der SelectList genau die Eintraege, die noch selektiert werden muessen
// zwei Moeglichkeiten : 1) ich gehe durch die SelectList, besorge mir zu jedem Eintrag meinen SvTreeListEntry
// und selektiere diesen (waere irgendwie intuitiver ;)) 2) ich gehe durch alle meine SvLBoxEntries und selektiere
// genau die, die ich in der SelectList finde
// 1) braucht O(k*n) (k=Laenge der SelectList, n=Anzahl meiner Entries), plus den Fakt, dass FindEntry nicht den
// Pointer auf die UserDaten vergleicht, sondern ein aufwendigeres IsEqualWithoutChildren durchfuehrt
// 2) braucht O(n*log k), dupliziert aber etwas Code (naemlich den aus FindEntry)
// da das hier eine relativ oft aufgerufenen Stelle sein koennte (bei jeder Aenderung in der Markierung in der View !),
// nehme ich doch lieber letzteres
SvTreeListEntry* pLoop = First();
while( pLoop )
{
FmEntryData* pCurEntryData = (FmEntryData*)pLoop->GetUserData();
FmEntryDataArray::iterator it = arredToSelect.find(pCurEntryData);
if ( it != arredToSelect.end() )
{
Select(pLoop, true);
MakeVisible(pLoop);
SetCursor(pLoop, true);
}
pLoop = Next( pLoop );
}
}
UnlockSelectionHandling();
}
void NavigatorTree::SynchronizeSelection()
{
// Shell und View
FmFormShell* pFormShell = GetNavModel()->GetFormShell();
if(!pFormShell) return;
FmFormView* pFormView = pFormShell->GetFormView();
if (!pFormView) return;
GetNavModel()->BroadcastMarkedObjects(pFormView->GetMarkedObjectList());
}
void NavigatorTree::SynchronizeMarkList()
{
// die Shell werde ich brauchen ...
FmFormShell* pFormShell = GetNavModel()->GetFormShell();
if (!pFormShell) return;
CollectSelectionData(SDI_NORMALIZED_FORMARK);
// Die View soll jetzt kein Notify bei einer Aenderung der MarkList rauslassen
pFormShell->GetImpl()->EnableTrackProperties(false);
UnmarkAllViewObj();
for (SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
it != m_arrCurrentSelection.end(); ++it)
{
SvTreeListEntry* pSelectionLoop = *it;
// Bei Formselektion alle Controls dieser Form markieren
if (IsFormEntry(pSelectionLoop) && (pSelectionLoop != m_pRootEntry))
MarkViewObj((FmFormData*)pSelectionLoop->GetUserData(), true, false);
// Bei Controlselektion Control-SdrObjects markieren
else if (IsFormComponentEntry(pSelectionLoop))
{
FmControlData* pControlData = (FmControlData*)pSelectionLoop->GetUserData();
if (pControlData)
{
// Beim HiddenControl kann kein Object selektiert werden
Reference< XFormComponent > xFormComponent( pControlData->GetFormComponent());
if (!xFormComponent.is())
continue;
Reference< XPropertySet > xSet(xFormComponent, UNO_QUERY);
if (!xSet.is())
continue;
sal_uInt16 nClassId = ::comphelper::getINT16(xSet->getPropertyValue(FM_PROP_CLASSID));
if (nClassId != FormComponentType::HIDDENCONTROL)
MarkViewObj(pControlData, true, true);
}
}
}
// wenn der PropertyBrowser offen ist, muss ich den entsprechend meiner Selektion anpassen
// (NICHT entsprechend der MarkList der View : wenn ich ein Formular selektiert habe, sind in der
// View alle zugehoerigen Controls markiert, trotzdem moechte ich natuerlich die Formular-Eigenschaften
// sehen)
ShowSelectionProperties(false);
// Flag an View wieder zuruecksetzen
pFormShell->GetImpl()->EnableTrackProperties(true);
// wenn jetzt genau eine Form selektiert ist, sollte die Shell das als CurrentForm mitbekommen
// (wenn SelectionHandling nicht locked ist, kuemmert sich die View eigentlich in MarkListHasChanged drum,
// aber der Mechanismus greift zum Beispiel nicht, wenn die Form leer ist)
if ((m_arrCurrentSelection.size() == 1) && (m_nFormsSelected == 1))
{
FmFormData* pSingleSelectionData = PTR_CAST( FmFormData, static_cast< FmEntryData* >( FirstSelected()->GetUserData() ) );
DBG_ASSERT( pSingleSelectionData, "NavigatorTree::SynchronizeMarkList: invalid selected form!" );
if ( pSingleSelectionData )
{
InterfaceBag aSelection;
aSelection.insert( Reference< XInterface >( pSingleSelectionData->GetFormIface(), UNO_QUERY ) );
pFormShell->GetImpl()->setCurrentSelection( aSelection );
}
}
}
bool NavigatorTree::IsHiddenControl(FmEntryData* pEntryData)
{
if (pEntryData == NULL) return false;
Reference< XPropertySet > xProperties( pEntryData->GetPropertySet() );
if (::comphelper::hasProperty(FM_PROP_CLASSID, xProperties))
{
Any aClassID = xProperties->getPropertyValue( FM_PROP_CLASSID );
return (::comphelper::getINT16(aClassID) == FormComponentType::HIDDENCONTROL);
}
return false;
}
bool NavigatorTree::Select( SvTreeListEntry* pEntry, bool bSelect )
{
if (bSelect == IsSelected(pEntry)) // das passiert manchmal, ich glaube, die Basisklasse geht zu sehr auf Nummer sicher ;)
return true;
return SvTreeListBox::Select(pEntry, bSelect );
}
void NavigatorTree::UnmarkAllViewObj()
{
FmFormShell* pFormShell = GetNavModel()->GetFormShell();
if( !pFormShell )
return;
FmFormView* pFormView = pFormShell->GetFormView();
pFormView->UnMarkAll();
}
void NavigatorTree::MarkViewObj(FmFormData* pFormData, bool bMark, bool bDeep )
{
FmFormShell* pFormShell = GetNavModel()->GetFormShell();
if( !pFormShell )
return;
// first collect all sdrobjects
::std::set< Reference< XFormComponent > > aObjects;
CollectObjects(pFormData,bDeep,aObjects);
// In der Page das entsprechende SdrObj finden und selektieren
FmFormView* pFormView = pFormShell->GetFormView();
SdrPageView* pPageView = pFormView->GetSdrPageView();
SdrPage* pPage = pPageView->GetPage();
//FmFormPage* pFormPage = dynamic_cast< FmFormPage* >( pPage );
SdrObjListIter aIter( *pPage );
while ( aIter.IsMore() )
{
SdrObject* pSdrObject = aIter.Next();
FmFormObj* pFormObject = FmFormObj::GetFormObject( pSdrObject );
if ( !pFormObject )
continue;
Reference< XFormComponent > xControlModel( pFormObject->GetUnoControlModel(),UNO_QUERY );
if ( xControlModel.is() && aObjects.find(xControlModel) != aObjects.end() && bMark != pFormView->IsObjMarked( pSdrObject ) )
{
// unfortunately, the writer doesn't like marking an already-marked object, again, so reset the mark first
pFormView->MarkObj( pSdrObject, pPageView, !bMark, false );
}
} // while ( aIter.IsMore() )
if ( bMark )
{
// make the mark visible
::Rectangle aMarkRect( pFormView->GetAllMarkedRect());
for ( sal_uInt32 i = 0; i < pFormView->PaintWindowCount(); ++i )
{
SdrPaintWindow* pPaintWindow = pFormView->GetPaintWindow( i );
OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
if ( ( OUTDEV_WINDOW == rOutDev.GetOutDevType() ) && !aMarkRect.IsEmpty() )
{
pFormView->MakeVisible( aMarkRect, (Window&)rOutDev );
}
} // for ( sal_uInt32 i = 0; i < pFormView->PaintWindowCount(); ++i )
}
}
void NavigatorTree::CollectObjects(FmFormData* pFormData, bool bDeep, ::std::set< Reference< XFormComponent > >& _rObjects)
{
FmEntryDataList* pChildList = pFormData->GetChildList();
FmEntryData* pEntryData;
FmControlData* pControlData;
for( size_t i = 0; i < pChildList->size(); ++i )
{
pEntryData = pChildList->at( i );
if( pEntryData->ISA(FmControlData) )
{
pControlData = (FmControlData*)pEntryData;
_rObjects.insert(pControlData->GetFormComponent());
} // if( pEntryData->ISA(FmControlData) )
else if (bDeep && (pEntryData->ISA(FmFormData)))
CollectObjects((FmFormData*)pEntryData,bDeep,_rObjects);
} // for( sal_uInt32 i=0; i<pChildList->Count(); i++ )
}
void NavigatorTree::MarkViewObj( FmControlData* pControlData, bool bMarkHandles, bool bMark)
{
if( !pControlData )
return;
FmFormShell* pFormShell = GetNavModel()->GetFormShell();
if( !pFormShell )
return;
// In der Page das entsprechende SdrObj finden und selektieren
FmFormView* pFormView = pFormShell->GetFormView();
Reference< XFormComponent > xFormComponent( pControlData->GetFormComponent());
SdrPageView* pPageView = pFormView->GetSdrPageView();
SdrPage* pPage = pPageView->GetPage();
bool bPaint = false;
SdrObjListIter aIter( *pPage );
while ( aIter.IsMore() )
{
SdrObject* pSdrObject = aIter.Next();
FmFormObj* pFormObject = FmFormObj::GetFormObject( pSdrObject );
if ( !pFormObject )
continue;
Reference< XInterface > xControlModel( pFormObject->GetUnoControlModel() );
if ( xControlModel != xFormComponent )
continue;
// mark the object
if ( bMark != pFormView->IsObjMarked( pSdrObject ) )
// unfortunately, the writer doesn't like marking an already-marked object, again, so reset the mark first
pFormView->MarkObj( pSdrObject, pPageView, !bMark, false );
if ( !bMarkHandles || !bMark )
continue;
bPaint = true;
} // while ( aIter.IsMore() )
if ( bPaint )
{
// make the mark visible
::Rectangle aMarkRect( pFormView->GetAllMarkedRect());
for ( sal_uInt32 i = 0; i < pFormView->PaintWindowCount(); ++i )
{
SdrPaintWindow* pPaintWindow = pFormView->GetPaintWindow( i );
OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
if ( OUTDEV_WINDOW == rOutDev.GetOutDevType() )
{
pFormView->MakeVisible( aMarkRect, (Window&)rOutDev );
}
} // for ( sal_uInt32 i = 0; i < pFormView->PaintWindowCount(); ++i )
}
}
} // namespace svxform
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|