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
|
/* -*- 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.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_svx.hxx"
#include "svx/dbexch.hrc"
#include "svx/fmgridif.hxx"
#include "fmitems.hxx"
#include "fmprop.hrc"
#include "svx/fmtools.hxx"
#include "svx/fmresids.hrc"
#include "fmservs.hxx"
#include "fmurl.hxx"
#include "formcontrolfactory.hxx"
#include "gridcell.hxx"
#include "gridcols.hxx"
#include "svx/dbaexchange.hxx"
#include "svx/dialmgr.hxx"
#include "svx/dialogs.hrc"
#include "svx/fmgridcl.hxx"
#include "svx/svxdlg.hxx"
#include "svx/svxids.hrc"
#include "trace.hxx"
#include <com/sun/star/form/XConfirmDeleteListener.hpp>
#include <com/sun/star/form/XFormComponent.hpp>
#include <com/sun/star/form/XGridColumnFactory.hpp>
#include <com/sun/star/io/XPersistObject.hpp>
#include <com/sun/star/sdb/CommandType.hpp>
#include <com/sun/star/sdb/RowChangeAction.hpp>
#include <com/sun/star/sdb/XQueriesSupplier.hpp>
#include <com/sun/star/sdbc/DataType.hpp>
#include <com/sun/star/sdbc/XPreparedStatement.hpp>
#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
#include <com/sun/star/sdbcx/XDeleteRows.hpp>
#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
#include <com/sun/star/uno/XNamingService.hpp>
#include <com/sun/star/util/XNumberFormats.hpp>
#include <com/sun/star/util/XNumberFormatsSupplier.hpp>
#include <com/sun/star/util/XURLTransformer.hpp>
#include <com/sun/star/view/XSelectionSupplier.hpp>
#ifndef _SVSTDARR_STRINGSDTOR
#define _SVSTDARR_STRINGSDTOR
#define _SVSTDARR_ULONGS
#include <svl/svstdarr.hxx>
#endif
#include <comphelper/extract.hxx>
#include <comphelper/numbers.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/property.hxx>
#include <connectivity/dbtools.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/viewfrm.hxx>
#include <svl/eitem.hxx>
#include <svtools/fmtfield.hxx>
#include <svl/numuno.hxx>
#include <tools/multisel.hxx>
#include <tools/shl.hxx>
#include <tools/diagnose_ex.h>
#include <vcl/help.hxx>
#include <vcl/image.hxx>
#include <vcl/longcurr.hxx>
#include <vcl/menu.hxx>
#include <math.h>
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::view;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::sdbcx;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::sdb;
using namespace ::com::sun::star::form;
using namespace ::com::sun::star::util;
using namespace ::com::sun::star::container;
using namespace ::cppu;
using namespace ::svxform;
using namespace ::svx;
//==============================================================================
//------------------------------------------------------------------------------
::rtl::OUString FieldServiceFromId(sal_Int32 nID)
{
switch (nID)
{
case SID_FM_EDIT : return FM_COL_TEXTFIELD;
case SID_FM_COMBOBOX : return FM_COL_COMBOBOX;
case SID_FM_LISTBOX : return FM_COL_LISTBOX;
case SID_FM_CHECKBOX : return FM_COL_CHECKBOX;
case SID_FM_DATEFIELD : return FM_COL_DATEFIELD;
case SID_FM_TIMEFIELD : return FM_COL_TIMEFIELD;
case SID_FM_NUMERICFIELD : return FM_COL_NUMERICFIELD;
case SID_FM_CURRENCYFIELD : return FM_COL_CURRENCYFIELD;
case SID_FM_PATTERNFIELD : return FM_COL_PATTERNFIELD;
case SID_FM_FORMATTEDFIELD : return FM_COL_FORMATTEDFIELD;
}
return ::rtl::OUString();
}
//==============================================================================
struct FmGridHeaderData
{
ODataAccessDescriptor aDropData;
Point aDropPosPixel;
sal_Int8 nDropAction;
Reference< XInterface > xDroppedStatement;
Reference< XInterface > xDroppedResultSet;
};
//==============================================================================
//------------------------------------------------------------------------------
const sal_Int16 nChangeTypeOffset = 1000;
void SetMenuItem(const ImageList& rList, sal_uInt16 nID, Menu* pMenu, Menu& rNewMenu, sal_Bool bDesignMode = sal_True, sal_Int16 nOffset = nChangeTypeOffset)
{
pMenu->SetItemImage(nID, rList.GetImage(nID));
pMenu->EnableItem(nID, bDesignMode);
rNewMenu.InsertItem(nID + nOffset, pMenu->GetItemText(nID));
rNewMenu.SetItemImage(nID + nOffset, rList.GetImage(nID));
rNewMenu.SetHelpId(nID + nOffset, pMenu->GetHelpId(nID));
rNewMenu.EnableItem(nID + nOffset, bDesignMode);
}
//------------------------------------------------------------------------------
FmGridHeader::FmGridHeader( BrowseBox* pParent, WinBits nWinBits)
:EditBrowserHeader(pParent, nWinBits)
,DropTargetHelper(this)
,m_pImpl(new FmGridHeaderData)
{
}
//------------------------------------------------------------------------------
FmGridHeader::~FmGridHeader()
{
delete m_pImpl;
}
//------------------------------------------------------------------------------
sal_uInt16 FmGridHeader::GetModelColumnPos(sal_uInt16 nId) const
{
return static_cast<FmGridControl*>(GetParent())->GetModelColumnPos(nId);
}
//---------------------------------------------------------------------------------------
void FmGridHeader::notifyColumnSelect(sal_uInt16 nColumnId)
{
sal_uInt16 nPos = GetModelColumnPos(nColumnId);
Reference< XIndexAccess > xColumns(((FmGridControl*)GetParent())->GetPeer()->getColumns(), UNO_QUERY);
if ( nPos < xColumns->getCount() )
{
Reference< XSelectionSupplier > xSelSupplier(xColumns, UNO_QUERY);
if ( xSelSupplier.is() )
{
Reference< XPropertySet > xColumn;
xColumns->getByIndex(nPos) >>= xColumn;
xSelSupplier->select(makeAny(xColumn));
}
}
}
//------------------------------------------------------------------------------
void FmGridHeader::Select()
{
EditBrowserHeader::Select();
notifyColumnSelect(GetCurItemId());
}
//------------------------------------------------------------------------------
void FmGridHeader::RequestHelp( const HelpEvent& rHEvt )
{
sal_uInt16 nItemId = GetItemId( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) );
if ( nItemId )
{
if ( rHEvt.GetMode() & (HELPMODE_QUICK | HELPMODE_BALLOON) )
{
Rectangle aItemRect = GetItemRect( nItemId );
Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
aItemRect.Left() = aPt.X();
aItemRect.Top() = aPt.Y();
aPt = OutputToScreenPixel( aItemRect.BottomRight() );
aItemRect.Right() = aPt.X();
aItemRect.Bottom() = aPt.Y();
sal_uInt16 nPos = GetModelColumnPos(nItemId);
Reference< ::com::sun::star::container::XIndexContainer > xColumns(static_cast<FmGridControl*>(GetParent())->GetPeer()->getColumns());
try
{
Reference< ::com::sun::star::beans::XPropertySet > xColumn(xColumns->getByIndex(nPos),UNO_QUERY);
::rtl::OUString aHelpText;
xColumn->getPropertyValue(FM_PROP_HELPTEXT) >>= aHelpText;
if ( !aHelpText.getLength() )
xColumn->getPropertyValue(FM_PROP_DESCRIPTION) >>= aHelpText;
if ( aHelpText.getLength() )
{
if ( rHEvt.GetMode() & HELPMODE_BALLOON )
Help::ShowBalloon( this, aItemRect.Center(), aItemRect, aHelpText );
else
Help::ShowQuickHelp( this, aItemRect, aHelpText );
return;
}
}
catch(Exception&)
{
return;
}
}
}
EditBrowserHeader::RequestHelp( rHEvt );
}
//------------------------------------------------------------------------------
sal_Int8 FmGridHeader::AcceptDrop( const AcceptDropEvent& rEvt )
{
// drop allowed in design mode only
if (!static_cast<FmGridControl*>(GetParent())->IsDesignMode())
return DND_ACTION_NONE;
// search for recognized formats
const DataFlavorExVector& rFlavors = GetDataFlavorExVector();
if (OColumnTransferable::canExtractColumnDescriptor(rFlavors, CTF_COLUMN_DESCRIPTOR | CTF_FIELD_DESCRIPTOR))
return rEvt.mnAction;
return DND_ACTION_NONE;
}
//------------------------------------------------------------------------------
sal_Int8 FmGridHeader::ExecuteDrop( const ExecuteDropEvent& _rEvt )
{
if (!static_cast<FmGridControl*>(GetParent())->IsDesignMode())
return DND_ACTION_NONE;
TransferableDataHelper aDroppedData(_rEvt.maDropEvent.Transferable);
// check the formats
sal_Bool bColumnDescriptor = OColumnTransferable::canExtractColumnDescriptor(aDroppedData.GetDataFlavorExVector(), CTF_COLUMN_DESCRIPTOR);
sal_Bool bFieldDescriptor = OColumnTransferable::canExtractColumnDescriptor(aDroppedData.GetDataFlavorExVector(), CTF_FIELD_DESCRIPTOR);
if (!bColumnDescriptor && !bFieldDescriptor)
{
OSL_FAIL("FmGridHeader::ExecuteDrop: should never have reached this (no extractable format)!");
return DND_ACTION_NONE;
}
// extract the descriptor
::rtl::OUString sDatasouce, sCommand, sFieldName,sDatabaseLocation,sConnnectionResource;
sal_Int32 nCommandType = CommandType::COMMAND;
Reference< XPreparedStatement > xStatement;
Reference< XResultSet > xResultSet;
Reference< XPropertySet > xField;
Reference< XConnection > xConnection;
ODataAccessDescriptor aColumn = OColumnTransferable::extractColumnDescriptor(aDroppedData);
if (aColumn.has(daDataSource)) aColumn[daDataSource] >>= sDatasouce;
if (aColumn.has(daDatabaseLocation)) aColumn[daDatabaseLocation] >>= sDatabaseLocation;
if (aColumn.has(daConnectionResource)) aColumn[daConnectionResource] >>= sConnnectionResource;
if (aColumn.has(daCommand)) aColumn[daCommand] >>= sCommand;
if (aColumn.has(daCommandType)) aColumn[daCommandType] >>= nCommandType;
if (aColumn.has(daColumnName)) aColumn[daColumnName] >>= sFieldName;
if (aColumn.has(daColumnObject))aColumn[daColumnObject] >>= xField;
if (aColumn.has(daConnection)) aColumn[daConnection] >>= xConnection;
if ( !sFieldName.getLength()
|| !sCommand.getLength()
|| ( !sDatasouce.getLength()
&& !sDatabaseLocation.getLength()
&& !xConnection.is()
)
)
{
OSL_FAIL( "FmGridHeader::ExecuteDrop: somebody started a nonsense drag operation!!" );
return DND_ACTION_NONE;
}
try
{
// need a connection
if (!xConnection.is())
{ // the transferable did not contain the connection -> build an own one
try
{
::rtl::OUString sSignificantSource( sDatasouce.getLength() ? sDatasouce : sDatabaseLocation );
xConnection = OStaticDataAccessTools().getConnection_withFeedback(sSignificantSource, ::rtl::OUString(),::rtl::OUString(),static_cast<FmGridControl*>(GetParent())->getServiceManager());
}
catch(NoSuchElementException&)
{ // allowed, means sDatasouce isn't a valid data source name ....
}
catch(Exception&)
{
OSL_FAIL("FmGridHeader::ExecuteDrop: could not retrieve the database access object !");
}
if (!xConnection.is())
{
OSL_FAIL("FmGridHeader::ExecuteDrop: could not retrieve the database access object !");
return DND_ACTION_NONE;
}
}
// try to obtain the column object
if (!xField.is())
{
#ifdef DBG_UTIL
Reference< XServiceInfo > xServiceInfo(xConnection, UNO_QUERY);
DBG_ASSERT(xServiceInfo.is() && xServiceInfo->supportsService(SRV_SDB_CONNECTION), "FmGridHeader::ExecuteDrop: invalid connection (no database access connection !)");
#endif
Reference< XNameAccess > xFields;
switch (nCommandType)
{
case CommandType::TABLE:
{
Reference< XTablesSupplier > xSupplyTables(xConnection, UNO_QUERY);
Reference< XColumnsSupplier > xSupplyColumns;
xSupplyTables->getTables()->getByName(sCommand) >>= xSupplyColumns;
xFields = xSupplyColumns->getColumns();
}
break;
case CommandType::QUERY:
{
Reference< XQueriesSupplier > xSupplyQueries(xConnection, UNO_QUERY);
Reference< XColumnsSupplier > xSupplyColumns;
xSupplyQueries->getQueries()->getByName(sCommand) >>= xSupplyColumns;
xFields = xSupplyColumns->getColumns();
}
break;
default:
{
xStatement = xConnection->prepareStatement(sCommand);
// not interested in any results
Reference< XPropertySet > xStatProps(xStatement,UNO_QUERY);
xStatProps->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MaxRows")), makeAny(sal_Int32(0)));
xResultSet = xStatement->executeQuery();
Reference< XColumnsSupplier > xSupplyCols(xResultSet, UNO_QUERY);
if (xSupplyCols.is())
xFields = xSupplyCols->getColumns();
}
}
if (xFields.is() && xFields->hasByName(sFieldName))
xFields->getByName(sFieldName) >>= xField;
if (!xField.is())
{
::comphelper::disposeComponent(xStatement);
return DND_ACTION_NONE;
}
}
// do the drop asynchronously
// (85957 - UI actions within the drop are not allowed, but we want to open a popup menu)
m_pImpl->aDropData = aColumn;
m_pImpl->aDropData[daConnection] <<= xConnection;
m_pImpl->aDropData[daColumnObject] <<= xField;
m_pImpl->nDropAction = _rEvt.mnAction;
m_pImpl->aDropPosPixel = _rEvt.maPosPixel;
m_pImpl->xDroppedStatement = xStatement;
m_pImpl->xDroppedResultSet = xResultSet;
PostUserEvent(LINK(this, FmGridHeader, OnAsyncExecuteDrop));
}
catch (Exception&)
{
OSL_FAIL("FmGridHeader::ExecuteDrop: caught an exception while creatin' the column !");
::comphelper::disposeComponent(xStatement);
return sal_False;
}
return DND_ACTION_LINK;
}
//------------------------------------------------------------------------------
IMPL_LINK( FmGridHeader, OnAsyncExecuteDrop, void*, /*NOTINTERESTEDIN*/ )
{
::rtl::OUString sCommand, sFieldName,sURL;
sal_Int32 nCommandType = CommandType::COMMAND;
Reference< XPropertySet > xField;
Reference< XConnection > xConnection;
::rtl::OUString sDatasouce = m_pImpl->aDropData.getDataSource();
if ( !sDatasouce.getLength() && m_pImpl->aDropData.has(daConnectionResource) )
m_pImpl->aDropData[daConnectionResource] >>= sURL;
m_pImpl->aDropData[daCommand] >>= sCommand;
m_pImpl->aDropData[daCommandType] >>= nCommandType;
m_pImpl->aDropData[daColumnName] >>= sFieldName;
m_pImpl->aDropData[daConnection] >>= xConnection;
m_pImpl->aDropData[daColumnObject] >>= xField;
try
{
// need number formats
Reference< XNumberFormatsSupplier > xSupplier = OStaticDataAccessTools().getNumberFormats(xConnection, sal_True);
Reference< XNumberFormats > xNumberFormats;
if (xSupplier.is())
xNumberFormats = xSupplier->getNumberFormats();
if (!xNumberFormats.is())
{
::comphelper::disposeComponent(m_pImpl->xDroppedResultSet);
::comphelper::disposeComponent(m_pImpl->xDroppedStatement);
return 0L;
}
// Vom Feld werden nun zwei Informationen benoetigt:
// a.) Name des Feldes fuer Label und ControlSource
// b.) FormatKey, um festzustellen, welches Feld erzeugt werden soll
sal_Int32 nDataType = 0;
xField->getPropertyValue(FM_PROP_FIELDTYPE) >>= nDataType;
// diese Datentypen koennen im Gridcontrol nicht verarbeitet werden
switch (nDataType)
{
case DataType::BLOB:
case DataType::LONGVARBINARY:
case DataType::BINARY:
case DataType::VARBINARY:
case DataType::OTHER:
::comphelper::disposeComponent(m_pImpl->xDroppedResultSet);
::comphelper::disposeComponent(m_pImpl->xDroppedStatement);
return 0L;
}
// Erstellen der Column
Reference< XIndexContainer > xCols(static_cast<FmGridControl*>(GetParent())->GetPeer()->getColumns());
Reference< XGridColumnFactory > xFactory(xCols, UNO_QUERY);
sal_uInt16 nColId = GetItemId(m_pImpl->aDropPosPixel);
// EinfuegePosition, immer vor der aktuellen Spalte
sal_uInt16 nPos = GetModelColumnPos(nColId);
Reference< XPropertySet > xCol, xSecondCol;
// erzeugen der Column in abhaengigkeit vom type, default textfeld
SvULongs aPossibleTypes;
switch (nDataType)
{
case DataType::BIT:
case DataType::BOOLEAN:
aPossibleTypes.Insert(SID_FM_CHECKBOX, aPossibleTypes.Count());
break;
case DataType::TINYINT:
case DataType::SMALLINT:
case DataType::INTEGER:
aPossibleTypes.Insert(SID_FM_NUMERICFIELD, aPossibleTypes.Count());
aPossibleTypes.Insert(SID_FM_FORMATTEDFIELD, aPossibleTypes.Count());
break;
case DataType::REAL:
case DataType::DOUBLE:
case DataType::NUMERIC:
case DataType::DECIMAL:
aPossibleTypes.Insert(SID_FM_FORMATTEDFIELD, aPossibleTypes.Count());
aPossibleTypes.Insert(SID_FM_NUMERICFIELD, aPossibleTypes.Count());
break;
case DataType::TIMESTAMP:
aPossibleTypes.Insert(SID_FM_TWOFIELDS_DATE_N_TIME, aPossibleTypes.Count());
aPossibleTypes.Insert(SID_FM_DATEFIELD, aPossibleTypes.Count());
aPossibleTypes.Insert(SID_FM_TIMEFIELD, aPossibleTypes.Count());
aPossibleTypes.Insert(SID_FM_FORMATTEDFIELD, aPossibleTypes.Count());
break;
case DataType::DATE:
aPossibleTypes.Insert(SID_FM_DATEFIELD, aPossibleTypes.Count());
aPossibleTypes.Insert(SID_FM_FORMATTEDFIELD, aPossibleTypes.Count());
break;
case DataType::TIME:
aPossibleTypes.Insert(SID_FM_TIMEFIELD, aPossibleTypes.Count());
aPossibleTypes.Insert(SID_FM_FORMATTEDFIELD, aPossibleTypes.Count());
break;
case DataType::CHAR:
case DataType::VARCHAR:
case DataType::LONGVARCHAR:
default:
aPossibleTypes.Insert(SID_FM_EDIT, aPossibleTypes.Count());
aPossibleTypes.Insert(SID_FM_FORMATTEDFIELD, aPossibleTypes.Count());
break;
}
// if it's a currency field, a a "currency field" option
try
{
if ( ::comphelper::hasProperty(FM_PROP_ISCURRENCY, xField)
&& ::comphelper::getBOOL(xField->getPropertyValue(FM_PROP_ISCURRENCY)))
aPossibleTypes.Insert(SID_FM_CURRENCYFIELD, 0);
}
catch(Exception&)
{
OSL_FAIL("FmGridHeader::ExecuteDrop: Exception occurred!");
}
sal_Bool bDateNTimeCol = sal_False;
if (aPossibleTypes.Count() != 0)
{
sal_Int32 nPreferedType = aPossibleTypes[0];
if ((m_pImpl->nDropAction == DND_ACTION_LINK) && (aPossibleTypes.Count() > 1))
{
ImageList aImageList( SVX_RES(RID_SVXIMGLIST_FMEXPL) );
PopupMenu aInsertMenu(SVX_RES(RID_SVXMNU_COLS));
PopupMenu aTypeMenu;
PopupMenu* pMenu = aInsertMenu.GetPopupMenu(SID_FM_INSERTCOL);
for (sal_uInt32 i=0; i<aPossibleTypes.Count(); ++i)
SetMenuItem(aImageList, sal_uInt16(aPossibleTypes[(sal_uInt16)i]), pMenu, aTypeMenu, sal_True, 0);
nPreferedType = aTypeMenu.Execute(this, m_pImpl->aDropPosPixel);
}
bDateNTimeCol = nPreferedType == SID_FM_TWOFIELDS_DATE_N_TIME;
sal_uInt16 nColCount = bDateNTimeCol ? 2 : 1;
::rtl::OUString sFieldService;
while (nColCount--)
{
if (bDateNTimeCol)
nPreferedType = nColCount ? SID_FM_DATEFIELD : SID_FM_TIMEFIELD;
sFieldService = FieldServiceFromId(nPreferedType);
Reference< XPropertySet > xThisRoundCol;
if ( sFieldService.getLength() )
xThisRoundCol = xFactory->createColumn(sFieldService);
if (nColCount)
xSecondCol = xThisRoundCol;
else
xCol = xThisRoundCol;
}
}
if (!xCol.is() || (bDateNTimeCol && !xSecondCol.is()))
{
::comphelper::disposeComponent(xCol); // in case only the creation of the second column failed
::comphelper::disposeComponent(m_pImpl->xDroppedResultSet);
::comphelper::disposeComponent(m_pImpl->xDroppedStatement);
return 0L;
}
if (bDateNTimeCol)
{
String sTimePostfix( SVX_RES( RID_STR_POSTFIX_TIME ) );
xCol->setPropertyValue(FM_PROP_LABEL, makeAny( ::rtl::OUString( sFieldName + sTimePostfix ) ) );
String sDatePostfix( SVX_RES( RID_STR_POSTFIX_DATE ) );
xSecondCol->setPropertyValue(FM_PROP_LABEL, makeAny( ::rtl::OUString( sFieldName + sDatePostfix ) ) );
}
else
xCol->setPropertyValue(FM_PROP_LABEL, makeAny(sFieldName));
FormControlFactory aControlFactory( ::comphelper::getProcessServiceFactory() );
aControlFactory.initializeControlModel( DocumentClassification::classifyHostDocument( xCols ), xCol );
aControlFactory.initializeFieldDependentProperties( xField, xCol, xNumberFormats );
xCol->setPropertyValue(FM_PROP_CONTROLSOURCE, makeAny(sFieldName));
if ( xSecondCol.is() )
xSecondCol->setPropertyValue(FM_PROP_CONTROLSOURCE, makeAny(sFieldName));
if (bDateNTimeCol)
{
String sRealName,sPurePostfix;
String aPostfix[] = {
String( SVX_RES( RID_STR_POSTFIX_DATE ) ),
String( SVX_RES( RID_STR_POSTFIX_TIME ) )
};
for ( size_t i=0; i<2; ++i )
{
sPurePostfix = aPostfix[i];
sPurePostfix.EraseLeadingChars(' ');
sPurePostfix.EraseLeadingChars('(');
sPurePostfix.EraseTrailingChars(')');
sRealName = sFieldName;
sRealName += '_';
sRealName += sPurePostfix;
if (i)
xSecondCol->setPropertyValue(FM_PROP_NAME, makeAny(::rtl::OUString(sRealName)));
else
xCol->setPropertyValue(FM_PROP_NAME, makeAny(::rtl::OUString(sRealName)));
}
}
else
xCol->setPropertyValue(FM_PROP_NAME, makeAny(sFieldName));
// jetzt einfuegen
Any aElement;
aElement <<= xCol;
xCols->insertByIndex(nPos, aElement);
if (bDateNTimeCol)
{
aElement <<= xSecondCol;
xCols->insertByIndex(nPos == (sal_uInt16)-1 ? nPos : ++nPos, aElement);
}
// ist die component::Form an die Datenbankangebunden?
Reference< XFormComponent > xFormCp(xCols, UNO_QUERY);
Reference< XPropertySet > xForm(xFormCp->getParent(), UNO_QUERY);
if (xForm.is())
{
if (!::comphelper::getString(xForm->getPropertyValue(FM_PROP_DATASOURCE)).getLength())
{
if ( sDatasouce.getLength() )
xForm->setPropertyValue(FM_PROP_DATASOURCE, makeAny(sDatasouce));
else
xForm->setPropertyValue(FM_PROP_URL, makeAny(sURL));
}
if (!::comphelper::getString(xForm->getPropertyValue(FM_PROP_COMMAND)).getLength())
{
xForm->setPropertyValue(FM_PROP_COMMAND, makeAny(sCommand));
Any aCommandType;
switch (nCommandType)
{
case CommandType::TABLE:
aCommandType <<= (sal_Int32)CommandType::TABLE;
break;
case CommandType::QUERY:
aCommandType <<= (sal_Int32)CommandType::QUERY;
break;
default:
aCommandType <<= (sal_Int32)CommandType::COMMAND;
xForm->setPropertyValue(FM_PROP_ESCAPE_PROCESSING, bool2any((sal_Bool)(2 == nCommandType)));
break;
}
xForm->setPropertyValue(FM_PROP_COMMANDTYPE, aCommandType);
}
}
}
catch (Exception&)
{
OSL_FAIL("FmGridHeader::OnAsyncExecuteDrop: caught an exception while creatin' the column !");
::comphelper::disposeComponent(m_pImpl->xDroppedResultSet);
::comphelper::disposeComponent(m_pImpl->xDroppedStatement);
return 0L;
}
::comphelper::disposeComponent(m_pImpl->xDroppedResultSet);
::comphelper::disposeComponent(m_pImpl->xDroppedStatement);
return 1L;
}
//------------------------------------------------------------------------------
void FmGridHeader::PreExecuteColumnContextMenu(sal_uInt16 nColId, PopupMenu& rMenu)
{
sal_Bool bDesignMode = static_cast<FmGridControl*>(GetParent())->IsDesignMode();
Reference< ::com::sun::star::container::XIndexContainer > xCols(static_cast<FmGridControl*>(GetParent())->GetPeer()->getColumns());
// Aufbau des Insert Menues
// mark the column if nColId != HEADERBAR_ITEM_NOTFOUND
if(nColId > 0)
{
sal_uInt16 nPos2 = GetModelColumnPos(nColId);
Reference< ::com::sun::star::container::XIndexContainer > xColumns(static_cast<FmGridControl*>(GetParent())->GetPeer()->getColumns());
Reference< ::com::sun::star::beans::XPropertySet> xColumn;
::cppu::extractInterface(xColumn, xColumns->getByIndex(nPos2));
Reference< ::com::sun::star::view::XSelectionSupplier > xSelSupplier(xColumns, UNO_QUERY);
if (xSelSupplier.is())
xSelSupplier->select(makeAny(xColumn));
}
// EinfuegePosition, immer vor der aktuellen Spalte
sal_uInt16 nPos = GetModelColumnPos(nColId);
sal_Bool bMarked = nColId && static_cast<FmGridControl*>(GetParent())->isColumnMarked(nColId);
ImageList aImageList( SVX_RES(RID_SVXIMGLIST_FMEXPL) );
PopupMenu* pControlMenu = new PopupMenu;
PopupMenu* pMenu = rMenu.GetPopupMenu(SID_FM_INSERTCOL);
if (pMenu)
{
SetMenuItem(aImageList, SID_FM_EDIT, pMenu, *pControlMenu, bDesignMode);
SetMenuItem(aImageList, SID_FM_CHECKBOX, pMenu, *pControlMenu, bDesignMode);
SetMenuItem(aImageList, SID_FM_COMBOBOX, pMenu, *pControlMenu, bDesignMode);
SetMenuItem(aImageList, SID_FM_LISTBOX, pMenu, *pControlMenu, bDesignMode);
SetMenuItem(aImageList, SID_FM_DATEFIELD, pMenu, *pControlMenu, bDesignMode);
SetMenuItem(aImageList, SID_FM_TIMEFIELD, pMenu, *pControlMenu, bDesignMode);
SetMenuItem(aImageList, SID_FM_NUMERICFIELD, pMenu, *pControlMenu, bDesignMode);
SetMenuItem(aImageList, SID_FM_CURRENCYFIELD, pMenu, *pControlMenu, bDesignMode);
SetMenuItem(aImageList, SID_FM_PATTERNFIELD, pMenu, *pControlMenu, bDesignMode);
SetMenuItem(aImageList, SID_FM_FORMATTEDFIELD, pMenu, *pControlMenu, bDesignMode);
}
if (pMenu && xCols.is() && nColId)
{
Reference< ::com::sun::star::beans::XPropertySet > xSet;
::cppu::extractInterface(xSet, xCols->getByIndex(nPos));
sal_Int16 nClassId;
xSet->getPropertyValue(FM_PROP_CLASSID) >>= nClassId;
Reference< ::com::sun::star::io::XPersistObject > xServiceQuestion(xSet, UNO_QUERY);
sal_Int32 nColType = xServiceQuestion.is() ? getColumnTypeByModelName(xServiceQuestion->getServiceName()) : 0;
if (nColType == TYPE_TEXTFIELD)
{ // edit fields and formatted fields have the same service name, thus getColumnTypeByModelName returns TYPE_TEXTFIELD
// in both cases. And as columns don't have an ::com::sun::star::lang::XServiceInfo interface, we have to distinguish both
// types via the existence of special properties
Reference< ::com::sun::star::beans::XPropertySet > xProps(xSet, UNO_QUERY);
if (xProps.is())
{
Reference< ::com::sun::star::beans::XPropertySetInfo > xPropsInfo = xProps->getPropertySetInfo();
if (xPropsInfo.is() && xPropsInfo->hasPropertyByName(FM_PROP_FORMATSSUPPLIER))
nColType = TYPE_FORMATTEDFIELD;
}
}
pControlMenu->EnableItem(SID_FM_EDIT + nChangeTypeOffset, bDesignMode && (nColType != TYPE_TEXTFIELD));
pControlMenu->EnableItem(SID_FM_COMBOBOX + nChangeTypeOffset, bDesignMode && (nColType != TYPE_COMBOBOX));
pControlMenu->EnableItem(SID_FM_LISTBOX + nChangeTypeOffset, bDesignMode && (nColType != TYPE_LISTBOX));
pControlMenu->EnableItem(SID_FM_CHECKBOX + nChangeTypeOffset, bDesignMode && (nColType != TYPE_CHECKBOX));
pControlMenu->EnableItem(SID_FM_DATEFIELD + nChangeTypeOffset, bDesignMode && (nColType != TYPE_DATEFIELD));
pControlMenu->EnableItem(SID_FM_NUMERICFIELD + nChangeTypeOffset, bDesignMode && (nColType != TYPE_NUMERICFIELD));
pControlMenu->EnableItem(SID_FM_TIMEFIELD + nChangeTypeOffset, bDesignMode && (nColType != TYPE_TIMEFIELD));
pControlMenu->EnableItem(SID_FM_CURRENCYFIELD + nChangeTypeOffset, bDesignMode && (nColType != TYPE_CURRENCYFIELD));
pControlMenu->EnableItem(SID_FM_PATTERNFIELD + nChangeTypeOffset, bDesignMode && (nColType != TYPE_PATTERNFIELD));
pControlMenu->EnableItem(SID_FM_FORMATTEDFIELD + nChangeTypeOffset, bDesignMode && (nColType != TYPE_FORMATTEDFIELD));
rMenu.SetPopupMenu(SID_FM_CHANGECOL, pControlMenu);
}
rMenu.EnableItem(SID_FM_INSERTCOL, bDesignMode && xCols.is());
rMenu.EnableItem(SID_FM_DELETECOL, bDesignMode && bMarked && xCols.is());
rMenu.EnableItem(SID_FM_CHANGECOL, bDesignMode && bMarked && xCols.is());
rMenu.EnableItem(SID_FM_SHOW_PROPERTY_BROWSER, bDesignMode && bMarked && xCols.is());
PopupMenu* pShowColsMenu = rMenu.GetPopupMenu(SID_FM_SHOWCOLS);
sal_uInt16 nHiddenCols = 0;
if (pShowColsMenu)
{
if (xCols.is())
{
// check for hidden cols
Reference< ::com::sun::star::beans::XPropertySet > xCurCol;
Any aHidden,aName;
for (sal_uInt16 i=0; i<xCols->getCount(); ++i)
{
::cppu::extractInterface(xCurCol, xCols->getByIndex(i));
DBG_ASSERT(xCurCol.is(), "FmGridHeader::PreExecuteColumnContextMenu : the Peer has invalid columns !");
aHidden = xCurCol->getPropertyValue(FM_PROP_HIDDEN);
DBG_ASSERT(aHidden.getValueType().getTypeClass() == TypeClass_BOOLEAN,
"FmGridHeader::PreExecuteColumnContextMenu : the property 'hidden' should be boolean !");
if (::comphelper::getBOOL(aHidden))
{
// put the column name into the 'show col' menu
if (nHiddenCols < 16)
{ // (only the first 16 items to keep the menu rather small)
aName = xCurCol->getPropertyValue(FM_PROP_LABEL);
pShowColsMenu->InsertItem(nHiddenCols + 1, ::comphelper::getString(aName), 0, nHiddenCols);
// the ID is arbitrary, but should be unique within the whole menu
}
++nHiddenCols;
}
}
}
pShowColsMenu->EnableItem(SID_FM_SHOWCOLS_MORE, xCols.is() && (nHiddenCols > 16));
pShowColsMenu->EnableItem(SID_FM_SHOWALLCOLS, xCols.is() && (nHiddenCols > 0));
}
// allow the 'hide column' item ?
sal_Bool bAllowHide = bMarked; // a column is marked
bAllowHide = bAllowHide || (!bDesignMode && (nPos != (sal_uInt16)-1)); // OR we are in alive mode and have hit a column
bAllowHide = bAllowHide && xCols.is(); // AND we have a column container
bAllowHide = bAllowHide && (xCols->getCount()-nHiddenCols > 1); // AND there are at least two visible columns
rMenu.EnableItem(SID_FM_HIDECOL, bAllowHide);
sal_Bool bChecked = sal_False;
if (bMarked)
{
SfxViewFrame* pCurrentFrame = SfxViewFrame::Current();
SfxItemState eState = SFX_ITEM_UNKNOWN;
// ask the bindings of the current view frame (which should be the one we're residing in) for the state
if (pCurrentFrame)
{
SfxPoolItem* pItem = NULL;
eState = pCurrentFrame->GetBindings().QueryState(SID_FM_CTL_PROPERTIES, pItem);
if (eState >= SFX_ITEM_AVAILABLE && pItem )
{
bChecked = pItem->ISA(SfxBoolItem) && ((SfxBoolItem*)pItem)->GetValue();
rMenu.CheckItem(SID_FM_SHOW_PROPERTY_BROWSER,bChecked);
}
delete pItem;
}
}
}
enum InspectorAction { eOpenInspector, eCloseInspector, eUpdateInspector, eNone };
//------------------------------------------------------------------------------
void FmGridHeader::PostExecuteColumnContextMenu(sal_uInt16 nColId, const PopupMenu& rMenu, sal_uInt16 nExecutionResult)
{
Reference< ::com::sun::star::container::XIndexContainer > xCols(static_cast<FmGridControl*>(GetParent())->GetPeer()->getColumns());
sal_uInt16 nPos = GetModelColumnPos(nColId);
// remove and delet the menu we inserted in PreExecuteColumnContextMenu
PopupMenu* pControlMenu = rMenu.GetPopupMenu(SID_FM_CHANGECOL);
delete pControlMenu;
::rtl::OUString aFieldType;
sal_Bool bReplace = sal_False;
InspectorAction eInspectorAction = eNone;
Reference< XPropertySet > xColumnToInspect;
switch (nExecutionResult)
{
case SID_FM_DELETECOL:
{
Reference< XInterface > xCol;
::cppu::extractInterface(xCol, xCols->getByIndex(nPos));
xCols->removeByIndex(nPos);
::comphelper::disposeComponent(xCol);
} break;
case SID_FM_SHOW_PROPERTY_BROWSER:
eInspectorAction = rMenu.IsItemChecked( SID_FM_SHOW_PROPERTY_BROWSER ) ? eOpenInspector : eCloseInspector;
xColumnToInspect.set( xCols->getByIndex( nPos ), UNO_QUERY );
break;
case SID_FM_EDIT + nChangeTypeOffset:
bReplace = sal_True;
case SID_FM_EDIT:
aFieldType = FM_COL_TEXTFIELD;
break;
case SID_FM_COMBOBOX + nChangeTypeOffset:
bReplace = sal_True;
case SID_FM_COMBOBOX:
aFieldType = FM_COL_COMBOBOX;
break;
case SID_FM_LISTBOX + nChangeTypeOffset:
bReplace = sal_True;
case SID_FM_LISTBOX:
aFieldType = FM_COL_LISTBOX;
break;
case SID_FM_CHECKBOX + nChangeTypeOffset:
bReplace = sal_True;
case SID_FM_CHECKBOX:
aFieldType = FM_COL_CHECKBOX;
break;
case SID_FM_DATEFIELD + nChangeTypeOffset:
bReplace = sal_True;
case SID_FM_DATEFIELD:
aFieldType = FM_COL_DATEFIELD;
break;
case SID_FM_TIMEFIELD + nChangeTypeOffset:
bReplace = sal_True;
case SID_FM_TIMEFIELD:
aFieldType = FM_COL_TIMEFIELD;
break;
case SID_FM_NUMERICFIELD + nChangeTypeOffset:
bReplace = sal_True;
case SID_FM_NUMERICFIELD:
aFieldType = FM_COL_NUMERICFIELD;
break;
case SID_FM_CURRENCYFIELD + nChangeTypeOffset:
bReplace = sal_True;
case SID_FM_CURRENCYFIELD:
aFieldType = FM_COL_CURRENCYFIELD;
break;
case SID_FM_PATTERNFIELD + nChangeTypeOffset:
bReplace = sal_True;
case SID_FM_PATTERNFIELD:
aFieldType = FM_COL_PATTERNFIELD;
break;
case SID_FM_FORMATTEDFIELD + nChangeTypeOffset:
bReplace = sal_True;
case SID_FM_FORMATTEDFIELD:
aFieldType = FM_COL_FORMATTEDFIELD;
break;
case SID_FM_HIDECOL:
{
Reference< ::com::sun::star::beans::XPropertySet > xCurCol;
::cppu::extractInterface(xCurCol, xCols->getByIndex(nPos));
xCurCol->setPropertyValue(FM_PROP_HIDDEN, makeAny((sal_Bool)sal_True));
}
break;
case SID_FM_SHOWCOLS_MORE:
{
SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
if(pFact)
{
AbstractFmShowColsDialog* pDlg = pFact->CreateFmShowColsDialog(NULL);
DBG_ASSERT(pDlg, "Dialogdiet fail!");
pDlg->SetColumns(xCols);
pDlg->Execute();
delete pDlg;
}
}
break;
case SID_FM_SHOWALLCOLS:
{
// just iterate through all the cols ...
Reference< ::com::sun::star::beans::XPropertySet > xCurCol;
for (sal_uInt16 i=0; i<xCols->getCount(); ++i)
{
::cppu::extractInterface(xCurCol, xCols->getByIndex(i));
xCurCol->setPropertyValue(FM_PROP_HIDDEN, makeAny((sal_Bool)sal_False));
}
// TODO : there must be a more clever way to do this ....
// with the above the view is updated after every single model update ...
}
break;
default:
if (nExecutionResult>0 && nExecutionResult<=16)
{ // it was a "show column/<colname>" command (there are at most 16 such items)
// search the nExecutionResult'th hidden col
Reference< ::com::sun::star::beans::XPropertySet > xCurCol;
for (sal_uInt16 i=0; i<xCols->getCount() && nExecutionResult; ++i)
{
::cppu::extractInterface(xCurCol, xCols->getByIndex(i));
Any aHidden = xCurCol->getPropertyValue(FM_PROP_HIDDEN);
if (::comphelper::getBOOL(aHidden))
if (!--nExecutionResult)
{
xCurCol->setPropertyValue(FM_PROP_HIDDEN, makeAny((sal_Bool)sal_False));
break;
}
}
}
break;
}
if ( aFieldType.getLength() )
{
try
{
Reference< XGridColumnFactory > xFactory( xCols, UNO_QUERY_THROW );
Reference< XPropertySet > xNewCol( xFactory->createColumn( aFieldType ), UNO_SET_THROW );
if ( bReplace )
{
// ein paar Properties hinueberretten
Reference< XPropertySet > xReplaced( xCols->getByIndex( nPos ), UNO_QUERY );
OStaticDataAccessTools().TransferFormComponentProperties(
xReplaced, xNewCol, Application::GetSettings().GetUILocale() );
xCols->replaceByIndex( nPos, makeAny( xNewCol ) );
::comphelper::disposeComponent( xReplaced );
eInspectorAction = eUpdateInspector;
xColumnToInspect = xNewCol;
}
else
{
FormControlFactory factory( ::comphelper::getProcessServiceFactory() );
::rtl::OUString sLabel = factory.getDefaultUniqueName_ByComponentType(
Reference< XNameAccess >( xCols, UNO_QUERY_THROW ), xNewCol );
xNewCol->setPropertyValue( FM_PROP_LABEL, makeAny( sLabel ) );
xNewCol->setPropertyValue( FM_PROP_NAME, makeAny( sLabel ) );
factory.initializeControlModel( DocumentClassification::classifyHostDocument( xCols ), xNewCol );
xCols->insertByIndex( nPos, makeAny( xNewCol ) );
}
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
}
SfxViewFrame* pCurrentFrame = SfxViewFrame::Current();
OSL_ENSURE( pCurrentFrame, "FmGridHeader::PostExecuteColumnContextMenu: no view frame -> no bindings -> no property browser!" );
if ( pCurrentFrame )
{
if ( eInspectorAction == eUpdateInspector )
{
if ( !pCurrentFrame->HasChildWindow( SID_FM_SHOW_PROPERTIES ) )
eInspectorAction = eNone;
}
if ( eInspectorAction != eNone )
{
FmInterfaceItem aIFaceItem( SID_FM_SHOW_PROPERTY_BROWSER, xColumnToInspect );
SfxBoolItem aShowItem( SID_FM_SHOW_PROPERTIES, eInspectorAction == eCloseInspector ? sal_False : sal_True );
pCurrentFrame->GetBindings().GetDispatcher()->Execute( SID_FM_SHOW_PROPERTY_BROWSER, SFX_CALLMODE_ASYNCHRON,
&aIFaceItem, &aShowItem, 0L );
}
}
}
//------------------------------------------------------------------------------
void FmGridHeader::triggerColumnContextMenu( const ::Point& _rPreferredPos )
{
// the affected col
sal_uInt16 nColId = GetItemId( _rPreferredPos );
// the menu
PopupMenu aContextMenu( SVX_RES( RID_SVXMNU_COLS ) );
// let derivees modify the menu
PreExecuteColumnContextMenu( nColId, aContextMenu );
aContextMenu.RemoveDisabledEntries( sal_True, sal_True );
// execute the menu
sal_uInt16 nResult = aContextMenu.Execute( this, _rPreferredPos );
// let derivees handle the result
PostExecuteColumnContextMenu( nColId, aContextMenu, nResult );
}
//------------------------------------------------------------------------------
void FmGridHeader::Command(const CommandEvent& rEvt)
{
switch (rEvt.GetCommand())
{
case COMMAND_CONTEXTMENU:
{
if (!rEvt.IsMouseEvent())
return;
triggerColumnContextMenu( rEvt.GetMousePosPixel() );
}
break;
default:
EditBrowserHeader::Command(rEvt);
}
}
//------------------------------------------------------------------------------
FmGridControl::FmGridControl(
Reference< ::com::sun::star::lang::XMultiServiceFactory > _rxFactory,
Window* pParent,
FmXGridPeer* _pPeer,
WinBits nBits)
:DbGridControl(_rxFactory, pParent, nBits)
,m_pPeer(_pPeer)
,m_nCurrentSelectedColumn(-1)
,m_nMarkedColumnId(BROWSER_INVALIDID)
,m_bSelecting(sal_False)
,m_bInColumnMove(sal_False)
{
EnableInteractiveRowHeight( );
}
//------------------------------------------------------------------------------
void FmGridControl::Command(const CommandEvent& _rEvt)
{
if ( COMMAND_CONTEXTMENU == _rEvt.GetCommand() )
{
FmGridHeader* pMyHeader = static_cast< FmGridHeader* >( GetHeaderBar() );
if ( pMyHeader && !_rEvt.IsMouseEvent() )
{ // context menu requested by keyboard
if ( 1 == GetSelectColumnCount() || IsDesignMode() )
{
sal_uInt16 nSelId = GetColumnId(
sal::static_int_cast< sal_uInt16 >( FirstSelectedColumn() ) );
::Rectangle aColRect( GetFieldRectPixel( 0, nSelId, sal_False ) );
Point aRelativePos( pMyHeader->ScreenToOutputPixel( OutputToScreenPixel( aColRect.TopCenter() ) ) );
pMyHeader->triggerColumnContextMenu( aRelativePos, FmGridHeader::AccessControl() );
// handled
return;
}
}
}
DbGridControl::Command( _rEvt );
}
// ::com::sun::star::beans::XPropertyChangeListener
//------------------------------------------------------------------------------
void FmGridControl::propertyChange(const ::com::sun::star::beans::PropertyChangeEvent& evt)
{
if (evt.PropertyName == FM_PROP_ROWCOUNT)
{
// if we're not in the main thread call AdjustRows asynchronously
implAdjustInSolarThread(sal_True);
return;
}
const DbGridRowRef& xRow = GetCurrentRow();
// waehrend Positionierung wird kein abgleich der Properties vorgenommen
Reference<XPropertySet> xSet(evt.Source,UNO_QUERY);
if (xRow.Is() && (::cppu::any2bool(xSet->getPropertyValue(FM_PROP_ISNEW))|| CompareBookmark(getDataSource()->getBookmark(), xRow->GetBookmark())))
{
if (evt.PropertyName == FM_PROP_ISMODIFIED)
{
// modified or clean ?
GridRowStatus eStatus = ::comphelper::getBOOL(evt.NewValue) ? GRS_MODIFIED : GRS_CLEAN;
if (eStatus != xRow->GetStatus())
{
xRow->SetStatus(eStatus);
SolarMutexGuard aGuard;
RowModified(GetCurrentPos());
}
}
}
}
//------------------------------------------------------------------------------
void FmGridControl::SetDesignMode(sal_Bool bMode)
{
sal_Bool bOldMode = IsDesignMode();
DbGridControl::SetDesignMode(bMode);
if (bOldMode != bMode)
{
if (!bMode)
{
// selection aufheben
markColumn(USHRT_MAX);
}
else
{
Reference< ::com::sun::star::container::XIndexContainer > xColumns(GetPeer()->getColumns());
Reference< ::com::sun::star::view::XSelectionSupplier > xSelSupplier(xColumns, UNO_QUERY);
if (xSelSupplier.is())
{
Any aSelection = xSelSupplier->getSelection();
Reference< ::com::sun::star::beans::XPropertySet > xColumn;
if (aSelection.getValueType().getTypeClass() == TypeClass_INTERFACE)
::cppu::extractInterface(xColumn, aSelection);
Reference< XInterface > xCurrent;
for (sal_uInt16 i=0; i<xColumns->getCount(); ++i)
{
::cppu::extractInterface(xCurrent, xColumns->getByIndex(i));
if (xCurrent == xColumn)
{
markColumn(GetColumnIdFromModelPos(i));
break;
}
}
}
}
}
}
//------------------------------------------------------------------------------
void FmGridControl::DeleteSelectedRows()
{
if (!m_pSeekCursor)
return;
// how many rows are selected?
sal_Int32 nSelectedRows = GetSelectRowCount();
// the current line should be deleted but it is currently in edit mode
if ( IsCurrentAppending() )
return;
// is the insert row selected
if (GetEmptyRow().Is() && IsRowSelected(GetRowCount() - 1))
nSelectedRows -= 1;
// nothing to do
if (nSelectedRows <= 0)
return;
// try to confirm the delete
Reference< ::com::sun::star::frame::XDispatchProvider > xDispatcher = (::com::sun::star::frame::XDispatchProvider*)GetPeer();
if (xDispatcher.is())
{
::com::sun::star::util::URL aUrl;
aUrl.Complete = FMURL_CONFIRM_DELETION;
// #100312# ------------
Reference< ::com::sun::star::util::XURLTransformer > xTransformer(
::comphelper::getProcessServiceFactory()->createInstance(
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.URLTransformer"))), UNO_QUERY);
if( xTransformer.is() )
xTransformer->parseStrict( aUrl );
Reference< ::com::sun::star::frame::XDispatch > xDispatch = xDispatcher->queryDispatch(aUrl, rtl::OUString(), 0);
Reference< ::com::sun::star::form::XConfirmDeleteListener > xConfirm(xDispatch, UNO_QUERY);
if (xConfirm.is())
{
::com::sun::star::sdb::RowChangeEvent aEvent;
aEvent.Source = (Reference< XInterface > )(*getDataSource());
aEvent.Rows = nSelectedRows;
aEvent.Action = ::com::sun::star::sdb::RowChangeAction::DELETE;
if (!xConfirm->confirmDelete(aEvent))
return;
}
}
const MultiSelection* pRowSelection = GetSelection();
if ( pRowSelection && pRowSelection->IsAllSelected() )
{
BeginCursorAction();
CursorWrapper* pCursor = getDataSource();
Reference< XResultSetUpdate > xUpdateCursor((Reference< XInterface >)*pCursor, UNO_QUERY);
try
{
pCursor->beforeFirst();
while( pCursor->next() )
xUpdateCursor->deleteRow();
SetUpdateMode(sal_False);
SetNoSelection();
xUpdateCursor->moveToInsertRow();
}
catch(const Exception&)
{
OSL_FAIL("Exception caught while deleting rows!");
}
// An den DatenCursor anpassen
AdjustDataSource(sal_True);
EndCursorAction();
SetUpdateMode(sal_True);
}
else
{
Reference< ::com::sun::star::sdbcx::XDeleteRows > xDeleteThem((Reference< XInterface >)*getDataSource(), UNO_QUERY);
// colect the bookmarks of the selected rows
Sequence < Any> aBookmarks = getSelectionBookmarks();
// determine the next row to position after deletion
Any aBookmark;
sal_Bool bNewPos = sal_False;
// if the current row isn't selected we take the row as row after deletion
OSL_ENSURE( GetCurrentRow().Is(), "FmGridControl::DeleteSelectedRows: no current row here?" );
// crash reports suggest it can happen we don't have a current row - how?
// #154303# / 2008-04-23 / frank.schoenheit@sun.com
if ( !IsRowSelected( GetCurrentPos() ) && !IsCurrentAppending() && GetCurrentRow().Is() )
{
aBookmark = GetCurrentRow()->GetBookmark();
bNewPos = sal_True;
}
else
{
// we look for the first row after the selected block for selection
long nIdx = LastSelectedRow() + 1;
if (nIdx < GetRowCount() - 1)
{
// there is a next row to position on
if (SeekCursor(nIdx))
{
GetSeekRow()->SetState(m_pSeekCursor, sal_True);
bNewPos = sal_True;
// if it's not the row for inserting we keep the bookmark
if (!IsInsertionRow(nIdx))
aBookmark = m_pSeekCursor->getBookmark();
}
}
else
{
// we look for the first row before the selected block for selection after deletion
nIdx = FirstSelectedRow() - 1;
if (nIdx >= 0 && SeekCursor(nIdx))
{
GetSeekRow()->SetState(m_pSeekCursor, sal_True);
bNewPos = sal_True;
aBookmark = m_pSeekCursor->getBookmark();
}
}
}
// Sind alle Zeilen Selectiert
// Zweite bedingung falls keine einguegeZeile existiert
sal_Bool bAllSelected = GetTotalCount() == nSelectedRows || GetRowCount() == nSelectedRows;
BeginCursorAction();
// now delete the row
Sequence <sal_Int32> aDeletedRows;
SetUpdateMode( sal_False );
try
{
aDeletedRows = xDeleteThem->deleteRows(aBookmarks);
}
catch(SQLException&)
{
}
SetUpdateMode( sal_True );
// how many rows are deleted?
sal_Int32 nDeletedRows = 0;
const sal_Int32* pSuccess = aDeletedRows.getConstArray();
for (sal_Int32 i = 0; i < aDeletedRows.getLength(); i++)
{
if (pSuccess[i])
++nDeletedRows;
}
// sind Zeilen geloescht worden?
if (nDeletedRows)
{
SetUpdateMode(sal_False);
SetNoSelection();
try
{
// did we delete all the rows than try to move to the next possible row
if (nDeletedRows == aDeletedRows.getLength())
{
// there exists a new position to move on
if (bNewPos)
{
if (aBookmark.hasValue())
getDataSource()->moveToBookmark(aBookmark);
// no valid bookmark so move to the insert row
else
{
Reference< XResultSetUpdate > xUpdateCursor((Reference< XInterface >)*m_pDataCursor, UNO_QUERY);
xUpdateCursor->moveToInsertRow();
}
}
else
{
Reference< ::com::sun::star::beans::XPropertySet > xSet((Reference< XInterface >)*m_pDataCursor, UNO_QUERY);
sal_Int32 nRecordCount(0);
xSet->getPropertyValue(FM_PROP_ROWCOUNT) >>= nRecordCount;
if ( m_pDataCursor->rowDeleted() )
--nRecordCount;
// there are no rows left and we have an insert row
if (!nRecordCount && GetEmptyRow().Is())
{
Reference< XResultSetUpdate > xUpdateCursor((Reference< XInterface >)*m_pDataCursor, UNO_QUERY);
xUpdateCursor->moveToInsertRow();
}
else if (nRecordCount)
// move to the first row
getDataSource()->first();
}
}
// not all the rows where deleted, so move to the first row which remained in the resultset
else
{
for (sal_Int32 i = 0; i < aDeletedRows.getLength(); i++)
{
if (!pSuccess[i])
{
getDataSource()->moveToBookmark(aBookmarks.getConstArray()[i]);
break;
}
}
}
}
catch(const Exception&)
{
try
{
// positioning went wrong so try to move to the first row
getDataSource()->first();
}
catch(const Exception&)
{
}
}
// An den DatenCursor anpassen
AdjustDataSource(sal_True);
// es konnten nicht alle Zeilen geloescht werden
// da nie nicht geloeschten wieder selektieren
if (nDeletedRows < nSelectedRows)
{
// waren alle selektiert
if (bAllSelected)
{
SelectAll();
if (IsInsertionRow(GetRowCount() - 1)) // einfuegeZeile nicht
SelectRow(GetRowCount() - 1, sal_False);
}
else
{
// select the remaining rows
for (sal_Int32 i = 0; i < aDeletedRows.getLength(); i++)
{
try
{
if (!pSuccess[i])
{
m_pSeekCursor->moveToBookmark(m_pDataCursor->getBookmark());
SetSeekPos(m_pSeekCursor->getRow() - 1);
SelectRow(GetSeekPos());
}
}
catch(const Exception&)
{
// keep the seekpos in all cases
SetSeekPos(m_pSeekCursor->getRow() - 1);
}
}
}
}
EndCursorAction();
SetUpdateMode(sal_True);
}
else // Zeile konnte nicht geloescht werden
{
EndCursorAction();
try
{
// currentrow is the insert row?
if (!IsCurrentAppending())
getDataSource()->refreshRow();
}
catch(const Exception&)
{
}
}
}
// if there is no selection anymore we can start editing
if (!GetSelectRowCount())
ActivateCell();
}
// XCurrentRecordListener
//------------------------------------------------------------------------------
void FmGridControl::positioned(const ::com::sun::star::lang::EventObject& /*rEvent*/)
{
TRACE_RANGE("FmGridControl::positioned");
// position on the data source (force it to be done in the main thread)
implAdjustInSolarThread(sal_False);
}
//------------------------------------------------------------------------------
sal_Bool FmGridControl::commit()
{
// Commit nur ausfuehren, wenn nicht bereits ein Update vom ::com::sun::star::form::component::GridControl ausgefuehrt
// wird
if (!IsUpdating())
{
if (Controller().Is() && Controller()->IsModified())
{
if (!SaveModified())
return sal_False;
}
}
return sal_True;
}
//------------------------------------------------------------------------------
void FmGridControl::inserted(const ::com::sun::star::lang::EventObject& /*rEvent*/)
{
const DbGridRowRef& xRow = GetCurrentRow();
if (!xRow.Is())
return;
// Zeile ist eingefuegt worden, dann den status und mode zuruecksetzen
xRow->SetState(m_pDataCursor, sal_False);
xRow->SetNew(sal_False);
}
// XCancelUpdateRecordListener
//------------------------------------------------------------------------------
void FmGridControl::restored(const ::com::sun::star::lang::EventObject& rEvent)
{
if (!GetCurrentRow().Is())
return;
sal_Bool bAppending = GetCurrentRow()->IsNew();
sal_Bool bDirty = GetCurrentRow()->IsModified();
if (bAppending && (EditBrowseBox::IsModified() || bDirty))
{
if (Controller().Is())
Controller()->ClearModified();
// jetzt die Zeile herausnehmen
RowRemoved(GetRowCount() - 1, 1, sal_True);
GetNavigationBar().InvalidateAll();
}
positioned(rEvent);
}
//------------------------------------------------------------------------------
BrowserHeader* FmGridControl::imp_CreateHeaderBar(BrowseBox* pParent)
{
DBG_ASSERT( pParent == this, "FmGridControl::imp_CreateHeaderBar: parent?" );
return new FmGridHeader( pParent );
}
//------------------------------------------------------------------------------
void FmGridControl::markColumn(sal_uInt16 nId)
{
if (GetHeaderBar() && m_nMarkedColumnId != nId)
{
// deselektieren
if (m_nMarkedColumnId != BROWSER_INVALIDID)
{
HeaderBarItemBits aBits = GetHeaderBar()->GetItemBits(m_nMarkedColumnId) & ~HIB_FLAT;
GetHeaderBar()->SetItemBits(m_nMarkedColumnId, aBits);
}
if (nId != BROWSER_INVALIDID)
{
HeaderBarItemBits aBits = GetHeaderBar()->GetItemBits(nId) | HIB_FLAT;
GetHeaderBar()->SetItemBits(nId, aBits);
}
m_nMarkedColumnId = nId;
}
}
//------------------------------------------------------------------------------
sal_Bool FmGridControl::isColumnMarked(sal_uInt16 nId) const
{
return m_nMarkedColumnId == nId;
}
//------------------------------------------------------------------------------
long FmGridControl::QueryMinimumRowHeight()
{
long nMinimalLogicHeight = 20; // 0.2 cm
long nMinimalPixelHeight = LogicToPixel( Point( 0, nMinimalLogicHeight ), MAP_10TH_MM ).Y();
return CalcZoom( nMinimalPixelHeight );
}
//------------------------------------------------------------------------------
void FmGridControl::RowHeightChanged()
{
DbGridControl::RowHeightChanged();
Reference< XPropertySet > xModel( GetPeer()->getColumns(), UNO_QUERY );
DBG_ASSERT( xModel.is(), "FmGridControl::RowHeightChanged: no model!" );
if ( xModel.is() )
{
try
{
sal_Int32 nUnzoomedPixelHeight = CalcReverseZoom( GetDataRowHeight() );
Any aProperty = makeAny( (sal_Int32)PixelToLogic( Point( 0, nUnzoomedPixelHeight ), MAP_10TH_MM ).Y() );
xModel->setPropertyValue( FM_PROP_ROWHEIGHT, aProperty );
}
catch( const Exception& )
{
OSL_ENSURE( sal_False, "FmGridControl::RowHeightChanged: caught an exception!" );
}
}
}
//------------------------------------------------------------------------------
void FmGridControl::ColumnResized(sal_uInt16 nId)
{
DbGridControl::ColumnResized(nId);
// Wert ans model uebergeben
DbGridColumn* pCol = DbGridControl::GetColumns().at( GetModelColumnPos(nId) );
Reference< ::com::sun::star::beans::XPropertySet > xColModel(pCol->getModel());
if (xColModel.is())
{
Any aWidth;
sal_Int32 nColumnWidth = GetColumnWidth(nId);
nColumnWidth = CalcReverseZoom(nColumnWidth);
// Umrechnen in 10THMM
aWidth <<= (sal_Int32)PixelToLogic(Point(nColumnWidth,0),MAP_10TH_MM).X();
xColModel->setPropertyValue(FM_PROP_WIDTH, aWidth);
}
}
//------------------------------------------------------------------------------
void FmGridControl::CellModified()
{
DbGridControl::CellModified();
GetPeer()->CellModified();
}
//------------------------------------------------------------------------------
void FmGridControl::BeginCursorAction()
{
DbGridControl::BeginCursorAction();
m_pPeer->stopCursorListening();
}
//------------------------------------------------------------------------------
void FmGridControl::EndCursorAction()
{
m_pPeer->startCursorListening();
DbGridControl::EndCursorAction();
}
//------------------------------------------------------------------------------
void FmGridControl::ColumnMoved(sal_uInt16 nId)
{
m_bInColumnMove = sal_True;
DbGridControl::ColumnMoved(nId);
Reference< ::com::sun::star::container::XIndexContainer > xColumns(GetPeer()->getColumns());
if (xColumns.is())
{
// suchen der Spalte und verschieben im Model
// ColumnPos holen
DbGridColumn* pCol = DbGridControl::GetColumns().at( GetModelColumnPos(nId) );
Reference< ::com::sun::star::beans::XPropertySet > xCol;
// Einfuegen muß sich an den Column Positionen orientieren
sal_Int32 i;
Reference< XInterface > xCurrent;
for (i = 0; !xCol.is() && i < xColumns->getCount(); i++)
{
::cppu::extractInterface(xCurrent, xColumns->getByIndex(i));
if (xCurrent == pCol->getModel())
{
xCol = pCol->getModel();
break;
}
}
DBG_ASSERT(i < xColumns->getCount(), "Falscher ::com::sun::star::sdbcx::Index");
xColumns->removeByIndex(i);
Any aElement;
aElement <<= xCol;
xColumns->insertByIndex(GetModelColumnPos(nId), aElement);
pCol->setModel(xCol);
// if the column which is shown here is selected ...
if ( isColumnSelected(nId,pCol) )
markColumn(nId); // ... -> mark it
}
m_bInColumnMove = sal_False;
}
//------------------------------------------------------------------------------
void FmGridControl::InitColumnsByModels(const Reference< ::com::sun::star::container::XIndexContainer >& xColumns)
{
// Spalten wieder neu setzen
// wenn es nur eine HandleColumn gibt, dann nicht
if (GetModelColCount())
{
RemoveColumns();
InsertHandleColumn();
}
if (!xColumns.is())
return;
SetUpdateMode(sal_False);
// Einfuegen mu� sich an den Column Positionen orientieren
sal_Int32 i;
String aName;
Any aWidth;
for (i = 0; i < xColumns->getCount(); ++i)
{
Reference< ::com::sun::star::beans::XPropertySet > xCol;
::cppu::extractInterface(xCol, xColumns->getByIndex(i));
aName = (const sal_Unicode*)::comphelper::getString(xCol->getPropertyValue(FM_PROP_LABEL));
aWidth = xCol->getPropertyValue(FM_PROP_WIDTH);
sal_Int32 nWidth = 0;
if (aWidth >>= nWidth)
nWidth = LogicToPixel(Point(nWidth,0),MAP_10TH_MM).X();
AppendColumn(aName, (sal_uInt16)nWidth);
DbGridColumn* pCol = DbGridControl::GetColumns().at( i );
pCol->setModel(xCol);
}
// und jetzt noch die hidden columns rausnehmen
// (wir haben das nicht gleich in der oberen Schleife gemacht, da wir dann Probleme mit den
// IDs der Spalten bekommen haetten : AppendColumn vergibt die automatisch, die Spalte _nach_
// einer versteckten braucht aber eine um eine erhoehte ID ....
Any aHidden;
for (i = 0; i < xColumns->getCount(); ++i)
{
Reference< ::com::sun::star::beans::XPropertySet > xCol;
::cppu::extractInterface(xCol, xColumns->getByIndex(i));
aHidden = xCol->getPropertyValue(FM_PROP_HIDDEN);
if (::comphelper::getBOOL(aHidden))
HideColumn(GetColumnIdFromModelPos((sal_uInt16)i));
}
SetUpdateMode(sal_True);
}
//------------------------------------------------------------------------------
void FmGridControl::InitColumnByField(
DbGridColumn* _pColumn, const Reference< XPropertySet >& _rxColumnModel,
const Reference< XNameAccess >& _rxFieldsByNames, const Reference< XIndexAccess >& _rxFieldsByIndex )
{
DBG_ASSERT( _rxFieldsByNames == _rxFieldsByIndex, "FmGridControl::InitColumnByField: invalid container interfaces!" );
// lookup the column which belongs to the control source
::rtl::OUString sFieldName;
_rxColumnModel->getPropertyValue( FM_PROP_CONTROLSOURCE ) >>= sFieldName;
Reference< XPropertySet > xField;
_rxColumnModel->getPropertyValue( FM_PROP_BOUNDFIELD ) >>= xField;
if ( !xField.is() && /*sFieldName.getLength() && */_rxFieldsByNames->hasByName( sFieldName ) ) // #i93452# do not check for name length
_rxFieldsByNames->getByName( sFieldName ) >>= xField;
// determine the position of this column
sal_Int32 nFieldPos = -1;
if ( xField.is() )
{
Reference< XPropertySet > xCheck;
sal_Int32 nFieldCount = _rxFieldsByIndex->getCount();
for ( sal_Int32 i = 0; i < nFieldCount; ++i)
{
_rxFieldsByIndex->getByIndex( i ) >>= xCheck;
if ( xField.get() == xCheck.get() )
{
nFieldPos = i;
break;
}
}
}
if ( xField.is() && ( nFieldPos >= 0 ) )
{
// some data types are not allowed
sal_Int32 nDataType = DataType::OTHER;
xField->getPropertyValue( FM_PROP_FIELDTYPE ) >>= nDataType;
sal_Bool bIllegalType = sal_False;
switch ( nDataType )
{
case DataType::BLOB:
case DataType::LONGVARBINARY:
case DataType::BINARY:
case DataType::VARBINARY:
case DataType::OTHER:
bIllegalType = sal_True;
break;
}
if ( bIllegalType )
{
_pColumn->SetObject( (sal_Int16)nFieldPos );
return;
}
}
// the control type is determined by the ColumnServiceName
static ::rtl::OUString s_sPropColumnServiceName( RTL_CONSTASCII_USTRINGPARAM( "ColumnServiceName" ) );
if ( !::comphelper::hasProperty( s_sPropColumnServiceName, _rxColumnModel ) )
return;
_pColumn->setModel( _rxColumnModel );
::rtl::OUString sColumnServiceName;
_rxColumnModel->getPropertyValue( s_sPropColumnServiceName ) >>= sColumnServiceName;
sal_Int32 nTypeId = getColumnTypeByModelName( sColumnServiceName );
_pColumn->CreateControl( nFieldPos, xField, nTypeId );
}
//------------------------------------------------------------------------------
void FmGridControl::InitColumnsByFields(const Reference< ::com::sun::star::container::XIndexAccess >& _rxFields)
{
if ( !_rxFields.is() )
return;
// Spalten initialisieren
Reference< XIndexContainer > xColumns( GetPeer()->getColumns() );
Reference< XNameAccess > xFieldsAsNames( _rxFields, UNO_QUERY );
// Einfuegen muss sich an den Column Positionen orientieren
for (sal_Int32 i = 0; i < xColumns->getCount(); i++)
{
DbGridColumn* pCol = GetColumns().at( i );
OSL_ENSURE(pCol,"No grid column!");
if ( pCol )
{
Reference< XPropertySet > xColumnModel;
::cppu::extractInterface( xColumnModel, xColumns->getByIndex( i ) );
InitColumnByField( pCol, xColumnModel, xFieldsAsNames, _rxFields );
}
}
}
//------------------------------------------------------------------------------
void FmGridControl::HideColumn(sal_uInt16 nId)
{
DbGridControl::HideColumn(nId);
sal_uInt16 nPos = GetModelColumnPos(nId);
if (nPos == (sal_uInt16)-1)
return;
DbGridColumn* pColumn = GetColumns().at( nPos );
if (pColumn->IsHidden())
GetPeer()->columnHidden(pColumn);
if (nId == m_nMarkedColumnId)
m_nMarkedColumnId = (sal_uInt16)-1;
}
// -----------------------------------------------------------------------------
sal_Bool FmGridControl::isColumnSelected(sal_uInt16 /*nId*/,DbGridColumn* _pColumn)
{
OSL_ENSURE(_pColumn,"Column can not be null!");
sal_Bool bSelected = sal_False;
// if the column which is shown here is selected ...
Reference< ::com::sun::star::view::XSelectionSupplier > xSelSupplier(GetPeer()->getColumns(), UNO_QUERY);
if ( xSelSupplier.is() )
{
Reference< ::com::sun::star::beans::XPropertySet > xColumn;
xSelSupplier->getSelection() >>= xColumn;
bSelected = (xColumn.get() == _pColumn->getModel().get());
}
return bSelected;
}
//------------------------------------------------------------------------------
void FmGridControl::ShowColumn(sal_uInt16 nId)
{
DbGridControl::ShowColumn(nId);
sal_uInt16 nPos = GetModelColumnPos(nId);
if (nPos == (sal_uInt16)-1)
return;
DbGridColumn* pColumn = GetColumns().at( nPos );
if (!pColumn->IsHidden())
GetPeer()->columnVisible(pColumn);
// if the column which is shown here is selected ...
if ( isColumnSelected(nId,pColumn) )
markColumn(nId); // ... -> mark it
}
//------------------------------------------------------------------------------
sal_Bool FmGridControl::selectBookmarks(const Sequence< Any >& _rBookmarks)
{
SolarMutexGuard aGuard;
// need to lock the SolarMutex so that no paint call disturbs us ...
if ( !m_pSeekCursor )
{
OSL_FAIL( "FmGridControl::selectBookmarks: no seek cursor!" );
return sal_False;
}
const Any* pBookmark = _rBookmarks.getConstArray();
const Any* pBookmarkEnd = pBookmark + _rBookmarks.getLength();
SetNoSelection();
sal_Bool bAllSuccessfull = sal_True;
try
{
for (; pBookmark != pBookmarkEnd; ++pBookmark)
{
// move the seek cursor to the row given
if (m_pSeekCursor->moveToBookmark(*pBookmark))
SelectRow( m_pSeekCursor->getRow() - 1);
else
bAllSuccessfull = sal_False;
}
}
catch(Exception&)
{
OSL_FAIL("FmGridControl::selectBookmarks: could not move to one of the bookmarks!");
return sal_False;
}
return bAllSuccessfull;
}
//------------------------------------------------------------------------------
Sequence< Any> FmGridControl::getSelectionBookmarks()
{
// lock our update so no paint-triggered seeks interfere ...
SetUpdateMode(sal_False);
sal_Int32 nSelectedRows = GetSelectRowCount(), i = 0;
Sequence< Any> aBookmarks(nSelectedRows);
if ( nSelectedRows )
{
Any* pBookmarks = (Any*)aBookmarks.getArray();
// (I'm not sure if the problem isn't deeper : The szenario : a large table displayed by a grid with a
// thread-safe cursor (dBase). On loading the sdb-cursor started a counting thread. While this counting progress
// was running, I tried do delete 3 records from within the grid. Deletion caused a SeekCursor, which did a
// m_pSeekCursor->moveRelative and a m_pSeekCursor->getPosition.
// Unfortunally the first call caused a propertyChanged(RECORDCOUNT) which resulted in a repaint of the
// navigation bar and the grid. The latter itself will result in SeekRow calls. So after (successfully) returning
// from the moveRelative the getPosition returns an invalid value. And so the SeekCursor fails.
// In the consequence ALL parts of code where two calls to the seek cursor are done, while the second call _relys_ on
// the first one, should be secured against recursion, with a broad-minded interpretion of "recursion" : if any of these
// code parts is executed, no other should be accessible. But this sounds very difficult to achieve ....
// )
// The next problem caused by the same behaviuor (SeekCursor causes a propertyChanged) : when adjusting rows we implicitly
// change our selection. So a "FirstSelected(); SeekCursor(); NextSelected();" may produce unpredictable results.
// That's why we _first_ collect the indicies of the selected rows and _then_ their bookmarks.
long nIdx = FirstSelectedRow();
while (nIdx >= 0)
{
// (we misuse the bookmarks array for this ...)
pBookmarks[i++] <<= (sal_Int32)nIdx;
nIdx = NextSelectedRow();
}
DBG_ASSERT(i == nSelectedRows, "FmGridControl::DeleteSelectedRows : could not collect the row indicies !");
for (i=0; i<nSelectedRows; ++i)
{
nIdx = ::comphelper::getINT32(pBookmarks[i]);
if (IsInsertionRow(nIdx))
{
// leerzeile nicht loeschen
aBookmarks.realloc(--nSelectedRows);
SelectRow(nIdx,sal_False); // selection aufheben fuer leerzeile
break;
}
// Zunaechst den DatenCursor auf den selektierten Satz pos.
if (SeekCursor(nIdx))
{
GetSeekRow()->SetState(m_pSeekCursor, sal_True);
pBookmarks[i] = m_pSeekCursor->getBookmark();
}
#ifdef DBG_UTIL
else
OSL_FAIL("FmGridControl::DeleteSelectedRows : a bookmark could not be determined !");
#endif
}
}
SetUpdateMode(sal_True);
// if one of the SeekCursor-calls failed ....
aBookmarks.realloc(i);
// (the alternative : while collecting the bookmarks lock our propertyChanged, this should resolve both our problems.
// but this would be incompatible as we need a locking flag, then ...)
return aBookmarks;
}
// -----------------------------------------------------------------------------
namespace
{
::rtl::OUString getColumnPropertyFromPeer(FmXGridPeer* _pPeer,sal_Int32 _nPosition,const ::rtl::OUString& _sPropName)
{
::rtl::OUString sRetText;
if ( _pPeer && _nPosition != -1)
{
Reference<XIndexContainer> xIndex = _pPeer->getColumns();
if ( xIndex.is() && xIndex->getCount() > _nPosition )
{
Reference<XPropertySet> xProp;
xIndex->getByIndex( _nPosition ) >>= xProp;
if ( xProp.is() )
xProp->getPropertyValue( _sPropName ) >>= sRetText;
}
}
return sRetText;
}
}
// Object data and state ------------------------------------------------------
::rtl::OUString FmGridControl::GetAccessibleObjectName( ::svt::AccessibleBrowseBoxObjType _eObjType,sal_Int32 _nPosition ) const
{
::rtl::OUString sRetText;
switch( _eObjType )
{
case ::svt::BBTYPE_BROWSEBOX:
if ( GetPeer() )
{
Reference<XPropertySet> xProp(GetPeer()->getColumns(),UNO_QUERY);
if ( xProp.is() )
xProp->getPropertyValue(FM_PROP_NAME) >>= sRetText;
}
break;
case ::svt::BBTYPE_COLUMNHEADERCELL:
sRetText = getColumnPropertyFromPeer(
GetPeer(),
GetModelColumnPos(
sal::static_int_cast< sal_uInt16 >(_nPosition)),
FM_PROP_LABEL);
break;
default:
sRetText = DbGridControl::GetAccessibleObjectName(_eObjType,_nPosition);
}
return sRetText;
}
// -----------------------------------------------------------------------------
::rtl::OUString FmGridControl::GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType _eObjType,sal_Int32 _nPosition ) const
{
::rtl::OUString sRetText;
switch( _eObjType )
{
case ::svt::BBTYPE_BROWSEBOX:
if ( GetPeer() )
{
Reference<XPropertySet> xProp(GetPeer()->getColumns(),UNO_QUERY);
if ( xProp.is() )
{
xProp->getPropertyValue(FM_PROP_HELPTEXT) >>= sRetText;
if ( !sRetText.getLength() )
xProp->getPropertyValue(FM_PROP_DESCRIPTION) >>= sRetText;
}
}
break;
case ::svt::BBTYPE_COLUMNHEADERCELL:
sRetText = getColumnPropertyFromPeer(
GetPeer(),
GetModelColumnPos(
sal::static_int_cast< sal_uInt16 >(_nPosition)),
FM_PROP_HELPTEXT);
if ( !sRetText.getLength() )
sRetText = getColumnPropertyFromPeer(
GetPeer(),
GetModelColumnPos(
sal::static_int_cast< sal_uInt16 >(_nPosition)),
FM_PROP_DESCRIPTION);
break;
default:
sRetText = DbGridControl::GetAccessibleObjectDescription(_eObjType,_nPosition);
}
return sRetText;
}
// -----------------------------------------------------------------------------
void FmGridControl::Select()
{
DbGridControl::Select();
// ... betrifft das unsere Spalten ?
const MultiSelection* pColumnSelection = GetColumnSelection();
sal_uInt16 nSelectedColumn =
pColumnSelection && pColumnSelection->GetSelectCount()
? sal::static_int_cast< sal_uInt16 >(
((MultiSelection*)pColumnSelection)->FirstSelected())
: SAL_MAX_UINT16;
// die HandleColumn wird nicht selektiert
switch (nSelectedColumn)
{
case SAL_MAX_UINT16: break; // no selection
case 0 : nSelectedColumn = SAL_MAX_UINT16; break;
// handle col can't be seledted
default :
// get the model col pos instead of the view col pos
nSelectedColumn = GetModelColumnPos(GetColumnIdFromViewPos(nSelectedColumn - 1));
break;
}
if (nSelectedColumn != m_nCurrentSelectedColumn)
{
// VOR dem Aufruf des select am SelectionSupplier !
m_nCurrentSelectedColumn = nSelectedColumn;
if (!m_bSelecting)
{
m_bSelecting = sal_True;
try
{
Reference< XIndexAccess > xColumns(GetPeer()->getColumns(), UNO_QUERY);
Reference< XSelectionSupplier > xSelSupplier(xColumns, UNO_QUERY);
if (xSelSupplier.is())
{
if (nSelectedColumn != SAL_MAX_UINT16)
{
Reference< XPropertySet > xColumn;
::cppu::extractInterface(xColumn,xColumns->getByIndex(nSelectedColumn));
xSelSupplier->select(makeAny(xColumn));
}
else
{
xSelSupplier->select(Any());
}
}
}
catch(Exception&)
{
}
m_bSelecting = sal_False;
}
}
}
// -----------------------------------------------------------------------------
sal_Int32 FmGridControl::GetSelectedColumn() const
{
return m_nCurrentSelectedColumn;
}
// -----------------------------------------------------------------------------
void FmGridControl::KeyInput( const KeyEvent& rKEvt )
{
sal_Bool bDone = sal_False;
const KeyCode& rKeyCode = rKEvt.GetKeyCode();
if ( IsDesignMode()
&& !rKeyCode.IsShift()
&& !rKeyCode.IsMod1()
&& !rKeyCode.IsMod2()
&& GetParent() )
{
switch ( rKeyCode.GetCode() )
{
case KEY_ESCAPE:
GetParent()->GrabFocus();
bDone = sal_True;
break;
case KEY_DELETE:
if ( GetSelectColumnCount() && GetPeer() && m_nCurrentSelectedColumn >= 0 )
{
Reference< ::com::sun::star::container::XIndexContainer > xCols(GetPeer()->getColumns());
if ( xCols.is() )
{
try
{
if ( m_nCurrentSelectedColumn < xCols->getCount() )
{
Reference< XInterface > xCol;
xCols->getByIndex(m_nCurrentSelectedColumn) >>= xCol;
xCols->removeByIndex(m_nCurrentSelectedColumn);
::comphelper::disposeComponent(xCol);
}
}
catch(const Exception&)
{
OSL_FAIL("exception occurred while deleting a column");
}
}
}
bDone = sal_True;
break;
}
}
if ( !bDone )
DbGridControl::KeyInput( rKEvt );
}
// -----------------------------------------------------------------------------
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|