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
|
/*************************************************************************
*
* 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_dbaccess.hxx"
#define ITEMID_HORJUSTIFY SID_ATTR_ALIGN_HOR_JUSTIFY
#define ITEMID_VERJUSTIFY SID_ATTR_ALIGN_VER_JUSTIFY
//#define ITEMID_ORIENTATION SID_ATTR_ALIGN_ORIENTATION
#define ITEMID_LINEBREAK SID_ATTR_ALIGN_LINEBREAK
#define ITEMID_MARGIN SID_ATTR_ALIGN_MARGIN
#include "FieldDescControl.hxx"
#include "FieldControls.hxx"
#include <tools/debug.hxx>
#include <tools/diagnose_ex.h>
#include "TableDesignHelpBar.hxx"
#include <vcl/scrbar.hxx>
#include <vcl/button.hxx>
#include <vcl/svapp.hxx>
#include <vcl/fixed.hxx>
#include <vcl/msgbox.hxx>
#include <vector>
#include "FieldDescriptions.hxx"
#include "dlgattr.hxx"
#include <svx/numfmtsh.hxx>
#include <svx/svxids.hrc>
#include <svx/algitem.hxx>
#include <svl/itempool.hxx>
#define _ZFORLIST_DECLARE_TABLE // ohne das bekomme ich einen Compiler-Fehler in <svl/zforlist.hxx>
#include <svl/zforlist.hxx>
#include <svl/rngitem.hxx>
#include <svl/intitem.hxx>
#include <svl/numuno.hxx>
#include <svtools/transfer.hxx>
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <com/sun/star/util/NumberFormat.hpp>
#include <com/sun/star/util/XNumberFormatPreviewer.hpp>
#include <com/sun/star/util/XNumberFormatTypes.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include "QEnumTypes.hxx"
#include "dbaccess_helpid.hrc"
#include <connectivity/dbtools.hxx>
#include <connectivity/dbconversion.hxx>
#include <comphelper/numbers.hxx>
#include "UITools.hxx"
#include <memory>
#include "dbu_control.hrc"
#include "dbu_tbl.hrc"
using namespace dbaui;
using namespace dbtools;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::util;
//==================================================================
// fuer die Controls auf der OFieldDescGenPage
#define CONTROL_SPACING_X 18 // 6
#define CONTROL_SPACING_Y 4
#define CONTROL_WIDTH_1 160 // 100
#define CONTROL_WIDTH_2 100 // 60
#define CONTROL_WIDTH_3 250
#define CONTROL_WIDTH_4 (CONTROL_WIDTH_3 - 20 - 5)
#define SBA_DEF_RANGEFORMAT (100 + 143) // RangeItem
#define SBA_DEF_FMTVALUE (100 + 144) // SfxULONG, Format
#define SBA_ATTR_ALIGN_HOR_JUSTIFY (100 + 145) // SvxHorJustifyItem
#define HSCROLL_STEP 20
namespace
{
// -----------------------------------------------------------------------------
double checkDoubleForDateFormat(double _nValue,sal_Int32 _nFormatKey,const Reference< ::com::sun::star::util::XNumberFormatter>& _xNumberFormatter)
{
double nValue = _nValue;
sal_Int32 nNumberFormat = ::comphelper::getNumberFormatType(_xNumberFormatter,_nFormatKey);
if( (nNumberFormat & ::com::sun::star::util::NumberFormat::DATE) == ::com::sun::star::util::NumberFormat::DATE
|| (nNumberFormat & ::com::sun::star::util::NumberFormat::DATETIME) == ::com::sun::star::util::NumberFormat::DATETIME )
{
nValue = DBTypeConversion::toStandardDbDate(DBTypeConversion::getNULLDate(_xNumberFormatter->getNumberFormatsSupplier()),nValue);
}
return nValue;
}
// -----------------------------------------------------------------------------
template< typename T1, typename T2> void lcl_HideAndDeleteControl(short& _nPos,T1** _pControl,T2** _pControlText)
{
if ( *_pControl )
{
--_nPos;
(*_pControl)->Hide();
(*_pControlText)->Hide();
delete *_pControl;
delete *_pControlText;
(*_pControl) = NULL;
(*_pControlText) = NULL;
}
}
}
//==================================================================
// class OFieldDescControl
//==================================================================
DBG_NAME(OFieldDescControl)
//==================================================================
OFieldDescControl::OFieldDescControl( Window* pParent, const ResId& rResId, OTableDesignHelpBar* pHelpBar)
:TabPage( pParent, rResId )
,pHelp( pHelpBar )
,pLastFocusWindow(NULL)
,m_pActFocusWindow(NULL)
,pDefaultText(NULL)
,pRequiredText(NULL)
,pAutoIncrementText(NULL)
,pTextLenText(NULL)
,pNumTypeText(NULL)
,pLengthText(NULL)
,pScaleText(NULL)
,pFormatText(NULL)
,pBoolDefaultText(NULL)
,m_pColumnNameText(NULL)
,m_pTypeText(NULL)
,m_pAutoIncrementValueText(NULL)
,pRequired(NULL)
,pNumType(NULL)
,pAutoIncrement(NULL)
,pDefault(NULL)
,pTextLen(NULL)
,pLength(NULL)
,pScale(NULL)
,pFormatSample(NULL)
,pBoolDefault(NULL)
,m_pColumnName(NULL)
,m_pType(NULL)
,m_pAutoIncrementValue(NULL)
,pFormat(NULL)
,m_pVertScroll( NULL )
,m_pHorzScroll( NULL )
,m_pPreviousType()
,nCurChildId(1)
,m_nPos(-1)
,aYes(ModuleRes(STR_VALUE_YES))
,aNo(ModuleRes(STR_VALUE_NO))
,m_nOldVThumb( 0 )
,m_nOldHThumb( 0 )
,m_nWidth(50)
,nDelayedGrabFocusEvent(0)
,m_bAdded(sal_False)
,m_bRightAligned(false)
,pActFieldDescr(NULL)
{
DBG_CTOR(OFieldDescControl,NULL);
Contruct();
}
//------------------------------------------------------------------------------
OFieldDescControl::OFieldDescControl( Window* pParent, OTableDesignHelpBar* pHelpBar )
:TabPage( pParent, WB_3DLOOK | WB_DIALOGCONTROL )
,pHelp( pHelpBar )
,pLastFocusWindow(NULL)
,m_pActFocusWindow(NULL)
,pDefaultText(NULL)
,pRequiredText(NULL)
,pAutoIncrementText(NULL)
,pTextLenText(NULL)
,pNumTypeText(NULL)
,pLengthText(NULL)
,pScaleText(NULL)
,pFormatText(NULL)
,pBoolDefaultText(NULL)
,m_pColumnNameText(NULL)
,m_pTypeText(NULL)
,m_pAutoIncrementValueText(NULL)
,pRequired(NULL)
,pNumType(NULL)
,pAutoIncrement(NULL)
,pDefault(NULL)
,pTextLen(NULL)
,pLength(NULL)
,pScale(NULL)
,pFormatSample(NULL)
,pBoolDefault(NULL)
,m_pColumnName(NULL)
,m_pType(NULL)
,m_pAutoIncrementValue(NULL)
,pFormat(NULL)
,m_pVertScroll( NULL )
,m_pHorzScroll( NULL )
,m_pPreviousType()
,nCurChildId(1)
,m_nPos(-1)
,aYes(ModuleRes(STR_VALUE_YES))
,aNo(ModuleRes(STR_VALUE_NO))
,m_nOldVThumb( 0 )
,m_nOldHThumb( 0 )
,m_nWidth(50)
,nDelayedGrabFocusEvent(0)
,m_bAdded(sal_False)
,m_bRightAligned(false)
,pActFieldDescr(NULL)
{
DBG_CTOR(OFieldDescControl,NULL);
Contruct();
}
// -----------------------------------------------------------------------------
void OFieldDescControl::Contruct()
{
m_pVertScroll = new ScrollBar(this, WB_VSCROLL | WB_REPEAT | WB_DRAG);
m_pHorzScroll = new ScrollBar(this, WB_HSCROLL | WB_REPEAT | WB_DRAG);
m_pVertScroll->SetScrollHdl(LINK(this, OFieldDescControl, OnScroll));
m_pHorzScroll->SetScrollHdl(LINK(this, OFieldDescControl, OnScroll));
m_pVertScroll->Show();
m_pHorzScroll->Show();
m_pVertScroll->EnableClipSiblings();
m_pHorzScroll->EnableClipSiblings();
m_pVertScroll->SetLineSize(1);
m_pVertScroll->SetPageSize(1);
m_pHorzScroll->SetLineSize(1);
m_pHorzScroll->SetPageSize(1);
m_nOldVThumb = m_nOldHThumb = 0;
}
//------------------------------------------------------------------------------
OFieldDescControl::~OFieldDescControl()
{
DBG_DTOR(OFieldDescControl,NULL);
{
::std::auto_ptr<Window> aTemp(m_pVertScroll);
m_pVertScroll = NULL;
}
{
::std::auto_ptr<Window> aTemp(m_pHorzScroll);
m_pHorzScroll = NULL;
}
if ( m_bAdded )
::dbaui::notifySystemWindow(this,this,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
pLastFocusWindow = NULL;
//////////////////////////////////////////////////////////////////////
// Childs zerstoeren
DeactivateAggregate( tpDefault );
DeactivateAggregate( tpRequired );
DeactivateAggregate( tpTextLen );
DeactivateAggregate( tpNumType );
DeactivateAggregate( tpScale );
DeactivateAggregate( tpLength );
DeactivateAggregate( tpFormat );
DeactivateAggregate( tpAutoIncrement );
DeactivateAggregate( tpBoolDefault );
DeactivateAggregate( tpColumnName );
DeactivateAggregate( tpType );
DeactivateAggregate( tpAutoIncrementValue );
if(nDelayedGrabFocusEvent)
Application::RemoveUserEvent(nDelayedGrabFocusEvent);
}
//------------------------------------------------------------------------------
String OFieldDescControl::BoolStringPersistent(const String& rUIString) const
{
static String aZero('0');
static String aOne('1');
if (rUIString == aNo)
return aZero;
if (rUIString == aYes)
return aOne;
return String();
}
//------------------------------------------------------------------------------
String OFieldDescControl::BoolStringUI(const String& rPersistentString) const
{
static String aZero('0');
static String aOne('1');
static String aNone(ModuleRes(STR_VALUE_NONE));
// FS - 66161 - 14.05.1999 - aeltere Versionen haben eventuell einen sprachabhaengigen String als Default gespeichert
if (rPersistentString.Equals(aYes) || rPersistentString.Equals(aNo))
return rPersistentString;
if (rPersistentString == aZero)
return aNo;
if (rPersistentString == aOne)
return aYes;
return aNone;
}
//------------------------------------------------------------------------------
void OFieldDescControl::Init()
{
Reference< ::com::sun::star::util::XNumberFormatter > xFormatter = GetFormatter();
::dbaui::setEvalDateFormatForFormatter(xFormatter);
}
//------------------------------------------------------------------------------
IMPL_LINK(OFieldDescControl, OnScroll, ScrollBar*, /*pBar*/)
{
ScrollAllAggregates();
return 0;
}
// -----------------------------------------------------------------------------
namespace
{
void getMaxXPosition(Window* _pWindow,long& _rnMaxXPosition)
{
if (_pWindow)
{
long nTemp = _pWindow->GetSizePixel().Width() + _pWindow->GetPosPixel().X();
_rnMaxXPosition = ::std::max(_rnMaxXPosition, nTemp);
}
}
}
//------------------------------------------------------------------------------
void OFieldDescControl::CheckScrollBars()
{
// ein paar Berechnungen zur neuen Position der ScrollBars
Size szOverallSize = GetSizePixel();
long nHScrollHeight = m_pHorzScroll->GetSizePixel().Height();
long nVScrollWidth = m_pVertScroll->GetSizePixel().Width();
long nNewHWidth = szOverallSize.Width() - nVScrollWidth;
long nNewVHeight = szOverallSize.Height() - nHScrollHeight;
sal_Bool bNeedHScrollBar(sal_False), bNeedVScrollBar(sal_False);
// die Bereiche anpassen
// brauche ich ScrollBars eigentlich ?
// horizontal :
long lMaxXPosition = 0;
Control* ppAggregates[] = { pRequired, pNumType, pAutoIncrement, pDefault, pTextLen, pLength, pScale, pFormat, m_pColumnName, m_pType,m_pAutoIncrementValue};
for (sal_uInt16 i=0; i<sizeof(ppAggregates)/sizeof(ppAggregates[0]); ++i)
getMaxXPosition(ppAggregates[i],lMaxXPosition);
if (m_pHorzScroll)
lMaxXPosition += m_pHorzScroll->GetThumbPos() * HSCROLL_STEP;
long lMaxXAvailable = szOverallSize.Width();
bNeedHScrollBar = lMaxXPosition > lMaxXAvailable;
// aendert sich vielleicht noch
// vertikal
// wieviel Controls habe ich
sal_uInt16 nActive = CountActiveAggregates();
// welches ist das letzte, was ganz drauf passt ?
sal_uInt16 nLastVisible;
const sal_Int32 nControlHeight = GetMaxControlHeight();
const sal_Int32 nControl_Spacing_y = LogicToPixel(Size(0, CONTROL_SPACING_Y),MAP_APPFONT).Height();
if (bNeedHScrollBar)
nLastVisible = static_cast<sal_uInt16>((szOverallSize.Height() - nControl_Spacing_y - nHScrollHeight) / (nControl_Spacing_y + nControlHeight));
else
nLastVisible = static_cast<sal_uInt16>((szOverallSize.Height() - nControl_Spacing_y) / (nControl_Spacing_y + nControlHeight));
bNeedVScrollBar = nActive>nLastVisible;
if (bNeedVScrollBar)
{
// in die urspruengliche Berechnung von lMaxXAvailable ist nicht mit eingegangen, dass ich eine VScrollBar habe, also muss ich
// das nachholen
lMaxXAvailable -= nVScrollWidth;
if (!bNeedHScrollBar && (lMaxXPosition > lMaxXAvailable))
{
// durch die vertikale brauche ich jetzt ploetzlich doch eine horizontale
bNeedHScrollBar = sal_True;
// nLastVisible anpassen
nLastVisible = static_cast<sal_uInt16>((szOverallSize.Height() - nControl_Spacing_y - nHScrollHeight) / (nControl_Spacing_y + nControlHeight));
// bNeedVScrollBar aendert sich nicht : es ist schon auf sal_True und nLastVisible wird hoechstens kleiner
}
}
// jetzt kann ich sie wirklich positionieren und ihre Parameter setzen
if (bNeedVScrollBar)
{
m_pVertScroll->Show();
m_pVertScroll->SetRangeMax(nActive - nLastVisible);
// m_pVertScroll->SetThumbPos(0);
m_pVertScroll->SetPosSizePixel( Point(nNewHWidth, 0), Size(nVScrollWidth, szOverallSize.Height()) );
}
else
{
m_pVertScroll->Hide();
m_pVertScroll->SetRangeMax(0);
m_pVertScroll->SetThumbPos(0);
}
if (bNeedHScrollBar)
{
m_pHorzScroll->Show();
m_pHorzScroll->SetRangeMax((lMaxXPosition - lMaxXAvailable + HSCROLL_STEP - 1 )/HSCROLL_STEP);
// m_pHorzScroll->SetThumbPos(0);
m_pHorzScroll->SetPosSizePixel( Point(0, nNewVHeight), Size(bNeedVScrollBar ? nNewHWidth : szOverallSize.Width(), nHScrollHeight) );
}
else
{
m_pHorzScroll->Hide();
m_pHorzScroll->SetRangeMax(0);
m_pHorzScroll->SetThumbPos(0);
}
}
//------------------------------------------------------------------------------
void OFieldDescControl::Resize()
{
CheckScrollBars();
ScrollAllAggregates();
}
//------------------------------------------------------------------------------
inline void OFieldDescControl::ScrollAggregate(Control* pText, Control* pInput, Control* pButton, long nDeltaX, long nDeltaY)
{
if (!pText)
return;
pText->SetPosPixel(pText->GetPosPixel() + Point(nDeltaX, nDeltaY));
pInput->SetPosPixel(pInput->GetPosPixel() + Point(nDeltaX, nDeltaY));
if (pButton)
pButton->SetPosPixel(pButton->GetPosPixel() + Point(nDeltaX, nDeltaY));
}
//------------------------------------------------------------------------------
void OFieldDescControl::ScrollAllAggregates()
{
long nDeltaX = 0, nDeltaY = 0;
if (m_nOldHThumb != m_pHorzScroll->GetThumbPos())
{
nDeltaX = (m_nOldHThumb - m_pHorzScroll->GetThumbPos()) * HSCROLL_STEP;
m_nOldHThumb = m_pHorzScroll->GetThumbPos();
}
if (m_nOldVThumb != m_pVertScroll->GetThumbPos())
{
const sal_Int32 nControlHeight = GetMaxControlHeight();
const sal_Int32 nControl_Spacing_y = LogicToPixel(Size(0, CONTROL_SPACING_Y),MAP_APPFONT).Height();
nDeltaY = (m_nOldVThumb - m_pVertScroll->GetThumbPos()) * (nControl_Spacing_y + nControlHeight);
m_nOldVThumb = m_pVertScroll->GetThumbPos();
}
if (nDeltaX || nDeltaY)
{
Control* ppAggregates[] = { pRequired, pNumType
, pAutoIncrement, pDefault
, pTextLen, pLength
, pScale, m_pColumnName
, m_pType, m_pAutoIncrementValue};
Control* ppAggregatesText[] = { pRequiredText, pNumTypeText
, pAutoIncrementText, pDefaultText
, pTextLenText, pLengthText
, pScaleText, m_pColumnNameText
, m_pTypeText, m_pAutoIncrementValueText};
OSL_ENSURE(sizeof(ppAggregates)/sizeof(ppAggregates[0]) == sizeof(ppAggregatesText)/sizeof(ppAggregatesText[0]),"Lists are not identical!");
for (sal_uInt16 i=0; i<sizeof(ppAggregates)/sizeof(ppAggregates[0]); ++i)
ScrollAggregate(ppAggregatesText[i],ppAggregates[i],NULL,nDeltaX, nDeltaY);
ScrollAggregate(pFormatText,pFormatSample,pFormat,nDeltaX, nDeltaY);
}
}
//------------------------------------------------------------------------------
sal_uInt16 OFieldDescControl::CountActiveAggregates() const
{
Control* ppAggregates[] = { pRequired, pNumType, pAutoIncrement, pDefault, pTextLen, pLength, pScale, pFormat, m_pColumnName, m_pType,m_pAutoIncrementValue};
sal_uInt16 nVisibleAggregates = 0;
for (sal_uInt16 i=0; i<sizeof(ppAggregates)/sizeof(ppAggregates[0]); ++i)
if (ppAggregates[i])
++nVisibleAggregates;
return nVisibleAggregates;
}
//------------------------------------------------------------------------------
sal_Int32 OFieldDescControl::GetMaxControlHeight() const
{
Size aHeight;
Control* ppAggregates[] = { pRequired, pNumType, pAutoIncrement, pDefault, pTextLen, pLength, pScale, pFormat, m_pColumnName, m_pType,m_pAutoIncrementValue};
for (sal_uInt16 i=0; i<sizeof(ppAggregates)/sizeof(ppAggregates[0]); ++i)
{
if ( ppAggregates[i] )
{
const Size aTemp( ppAggregates[i]->GetOptimalSize(WINDOWSIZE_PREFERRED) );
if ( aTemp.Height() > aHeight.Height() )
aHeight.Height() = aTemp.Height();
} // if ( ppAggregates[i] )
}
return aHeight.Height();
}
//------------------------------------------------------------------------------
void OFieldDescControl::SetReadOnly( sal_Bool bReadOnly )
{
DBG_CHKTHIS(OFieldDescControl,NULL);
//////////////////////////////////////////////////////////////////////
// Controls enablen/disablen
Control* ppAggregates[] = { pRequired, pNumType
, pAutoIncrement, pDefault
, pTextLen, pLength
, pScale, m_pColumnName
, m_pType, m_pAutoIncrementValue
, pFormat};
Control* ppAggregatesText[] = { pRequiredText, pNumTypeText
, pAutoIncrementText, pDefaultText
, pTextLenText, pLengthText
, pScaleText, m_pColumnNameText
, m_pTypeText, m_pAutoIncrementValueText
, pFormatText};
OSL_ENSURE(sizeof(ppAggregates)/sizeof(ppAggregates[0]) == sizeof(ppAggregatesText)/sizeof(ppAggregatesText[0]),"Lists are not identical!");
for (sal_uInt16 i=0; i<sizeof(ppAggregates)/sizeof(ppAggregates[0]); ++i)
{
if ( ppAggregatesText[i] )
ppAggregatesText[i]->Enable( !bReadOnly );
if ( ppAggregates[i] )
ppAggregates[i]->Enable( !bReadOnly );
}
}
//------------------------------------------------------------------------------
String OFieldDescControl::GetControlText( sal_uInt16 nControlId )
{
DBG_CHKTHIS(OFieldDescControl,NULL);
//////////////////////////////////////////////////////////////////////
// Texte der Controls auslesen
switch( nControlId )
{
case FIELD_PROPERTY_BOOL_DEFAULT:
if (pBoolDefault)
return pBoolDefault->GetSelectEntry();
break;
case FIELD_PROPERTY_DEFAULT:
if (pDefault)
return pDefault->GetText();
break;
case FIELD_PROPERTY_REQUIRED:
if (pRequired)
return pRequired->GetSelectEntry();
break;
case FIELD_PROPERTY_TEXTLEN:
if (pTextLen)
return String::CreateFromInt64(pTextLen->GetValue());
case FIELD_PROPERTY_NUMTYPE:
if (pNumType)
return pNumType->GetSelectEntry();
break;
case FIELD_PROPERTY_AUTOINC:
if (pAutoIncrement)
return pAutoIncrement->GetSelectEntry();
break;
case FIELD_PROPERTY_LENGTH:
if (pLength)
return pLength->GetText();
break;
case FIELD_PROPERTY_SCALE:
if (pScale)
return pScale->GetText();
break;
case FIELD_PROPERTY_FORMAT:
if (pFormatSample)
return pFormatSample->GetText();
break;
case FIELD_PRPOERTY_COLUMNNAME:
if(m_pColumnName)
return m_pColumnName->GetText();
case FIELD_PRPOERTY_TYPE:
if(m_pType)
return m_pType->GetSelectEntry();
break;
case FIELD_PRPOERTY_AUTOINCREMENT:
if(m_pAutoIncrementValue)
return m_pAutoIncrementValue->GetText();
}
return String();
}
//------------------------------------------------------------------------------
void OFieldDescControl::SetControlText( sal_uInt16 nControlId, const String& rText )
{
DBG_CHKTHIS(OFieldDescControl,NULL);
//////////////////////////////////////////////////////////////////////
// Texte der Controls setzen
switch( nControlId )
{
case FIELD_PROPERTY_BOOL_DEFAULT:
if (pBoolDefault)
{
String sOld = pBoolDefault->GetSelectEntry();
pBoolDefault->SelectEntry(rText);
if (!sOld.Equals(rText))
LINK(this, OFieldDescControl, ChangeHdl).Call(pBoolDefault);
}
break;
case FIELD_PROPERTY_DEFAULT:
if (pDefault)
{
pDefault->SetText(rText);
UpdateFormatSample(pActFieldDescr);
}
break;
case FIELD_PROPERTY_REQUIRED:
if (pRequired)
pRequired->SelectEntry(rText);
break;
case FIELD_PROPERTY_TEXTLEN:
if (pTextLen)
pTextLen->SetText(rText);
break;
case FIELD_PROPERTY_NUMTYPE:
if (pNumType)
pNumType->SelectEntry(rText);
break;
case FIELD_PROPERTY_AUTOINC:
if (pAutoIncrement)
{
String sOld = pAutoIncrement->GetSelectEntry();
pAutoIncrement->SelectEntry(rText);
if (!sOld.Equals(rText))
LINK(this, OFieldDescControl, ChangeHdl).Call(pAutoIncrement);
}
break;
case FIELD_PROPERTY_LENGTH:
if (pLength)
pLength->SetText(rText);
break;
case FIELD_PROPERTY_SCALE:
if (pScale)
pScale->SetText(rText);
break;
case FIELD_PROPERTY_FORMAT:
if (pActFieldDescr)
UpdateFormatSample(pActFieldDescr);
break;
case FIELD_PRPOERTY_COLUMNNAME:
if(m_pColumnName)
m_pColumnName->SetText(rText);
break;
case FIELD_PRPOERTY_TYPE:
if(m_pType)
m_pType->SelectEntry(rText);
break;
case FIELD_PRPOERTY_AUTOINCREMENT:
if(m_pAutoIncrementValue)
m_pAutoIncrementValue->SetText(rText);
break;
}
}
//------------------------------------------------------------------------
IMPL_LINK( OFieldDescControl, FormatClickHdl, Button *, /*pButton*/ )
{
DBG_CHKTHIS(OFieldDescControl,NULL);
//////////////////////////////////////////////////////////////////////
// Temporaere Column erzeugen, mit der Datenaustausch mit Dialog erfolgt
if( !pActFieldDescr )
return 0;
sal_Int32 nOldFormatKey(pActFieldDescr->GetFormatKey());
SvxCellHorJustify rOldJustify = pActFieldDescr->GetHorJustify();
Reference< XNumberFormatsSupplier > xSupplier = GetFormatter()->getNumberFormatsSupplier();
SvNumberFormatsSupplierObj* pSupplierImpl = SvNumberFormatsSupplierObj::getImplementation( xSupplier );
SvNumberFormatter* pFormatter = pSupplierImpl->GetNumberFormatter();
sal_uInt16 nFlags;
if(::dbaui::callColumnFormatDialog(this,pFormatter,pActFieldDescr->GetType(),nOldFormatKey,rOldJustify,nFlags,sal_True))
{
sal_Bool bModified = sal_False;
if(nOldFormatKey != pActFieldDescr->GetFormatKey())
{
pActFieldDescr->SetFormatKey( nOldFormatKey );
bModified = sal_True;
}
if(rOldJustify != pActFieldDescr->GetHorJustify())
{
pActFieldDescr->SetHorJustify( rOldJustify );
bModified = sal_True;
}
if(bModified)
{
SetModified(sal_True);
UpdateFormatSample(pActFieldDescr);
}
}
return 0;
}
// -----------------------------------------------------------------------
void OFieldDescControl::SetModified(sal_Bool /*bModified*/)
{
}
//------------------------------------------------------------------------
IMPL_LINK( OFieldDescControl, ChangeHdl, ListBox *, pListBox )
{
DBG_CHKTHIS(OFieldDescControl,NULL);
if ( !pActFieldDescr )
return 0;
if ( pListBox->GetSavedValue() != pListBox->GetSelectEntryPos() )
SetModified(sal_True);
// Sonderbehandlund f"ur Bool Felder
if(pListBox == pRequired && pBoolDefault )
{
// wenn pRequired auf sal_True gesetzt ist, dann darf das sal_Bool Feld nicht den Eintrag <<keiner>> besitzen
String sDef = BoolStringUI(::comphelper::getString(pActFieldDescr->GetControlDefault()));
if(pRequired->GetSelectEntryPos() == 0) // JA
{
pBoolDefault->RemoveEntry(String(ModuleRes(STR_VALUE_NONE)));
if (!sDef.Equals(aYes) && !sDef.Equals(aNo))
pBoolDefault->SelectEntryPos(1); // nein als Default
else
pBoolDefault->SelectEntry(sDef);
}
else if(pBoolDefault->GetEntryCount() < 3)
{
pBoolDefault->InsertEntry(String(ModuleRes(STR_VALUE_NONE)));
pBoolDefault->SelectEntry(sDef);
}
}
// nur fuer AutoIncrement eine Sonderbehandlung
if (pListBox == pAutoIncrement)
{
if(pListBox->GetSelectEntryPos() == 1)
{ // no
DeactivateAggregate( tpAutoIncrementValue );
if(pActFieldDescr->IsPrimaryKey())
DeactivateAggregate( tpRequired );
else if( pActFieldDescr->getTypeInfo()->bNullable )
{
ActivateAggregate( tpRequired );
if(pRequired)
{
if( pActFieldDescr->IsNullable() )
pRequired->SelectEntryPos( 1 ); // no
else
pRequired->SelectEntryPos( 0 ); // yes
}
}
ActivateAggregate( tpDefault );
}
else
{
DeactivateAggregate( tpRequired );
DeactivateAggregate( tpDefault );
ActivateAggregate( tpAutoIncrementValue );
}
// und jetzt alle nach oben schieben
ArrangeAggregates();
}
if(pListBox == m_pType)
{
TOTypeInfoSP pTypeInfo = getTypeInfo(m_pType->GetSelectEntryPos());
pActFieldDescr->FillFromTypeInfo(pTypeInfo,sal_True,sal_False); // SetType(pTypeInfo);
DisplayData(pActFieldDescr);
CellModified(-1, m_pType->GetPos());
}
return 0;
}
//------------------------------------------------------------------------------
// alle Control neu anordnen, so dass sie in fester Reihenfolge und wirklich
// OBEN auf der DescriptionPage stehen
void OFieldDescControl::ArrangeAggregates()
{
DBG_CHKTHIS(OFieldDescControl,NULL);
// die Beschreibung eines Controls
struct AGGREGATE_DESCRIPTION
{
Control* pctrlInputControl; // das eigentliche Control zur Eingabe
Control* pctrlTextControl; // das Label dazu
USHORT nPosSizeArgument; // das zweite Argument fuer SetPosSize
};
AGGREGATE_DESCRIPTION adAggregates[] = {
{ m_pColumnName, m_pColumnNameText, 1},
{ m_pType, m_pTypeText, 1},
{ pAutoIncrement, pAutoIncrementText, 1 },
{ m_pAutoIncrementValue, m_pAutoIncrementValueText, 3 },
{ pNumType, pNumTypeText, 1 },
{ pRequired, pRequiredText, 1 },
{ pTextLen, pTextLenText, 1 },
{ pLength, pLengthText, 1 },
{ pScale, pScaleText, 1 },
{ pDefault, pDefaultText, 3 },
{ pFormatSample, pFormatText, 4 },
{ pBoolDefault, pBoolDefaultText, 1 },
};
long nMaxWidth = 0;
for (size_t i=0; i<sizeof(adAggregates)/sizeof(adAggregates[0]); i++)
{
if (adAggregates[i].pctrlTextControl)
{
nMaxWidth = ::std::max<long>(OutputDevice::GetTextWidth(adAggregates[i].pctrlTextControl->GetText()),nMaxWidth);
}
}
OSL_ENSURE(nMaxWidth != 0,"Invalid width!");
// und los ...
int nCurrentControlPos = 0;
Control* pZOrderPredecessor = NULL;
for (size_t i=0; i<sizeof(adAggregates)/sizeof(adAggregates[0]); i++)
{
if (adAggregates[i].pctrlInputControl)
{
SetPosSize(&adAggregates[i].pctrlTextControl, nCurrentControlPos, 0);
SetPosSize(&adAggregates[i].pctrlInputControl, nCurrentControlPos, adAggregates[i].nPosSizeArgument);
// die Z-Order so, dass die Controls auch wirklich in derselben Reihenfolge durchwandert werden koennen, in der sie
// hier angeordnet wurden
adAggregates[i].pctrlTextControl->SetZOrder(pZOrderPredecessor, pZOrderPredecessor ? WINDOW_ZORDER_BEHIND : WINDOW_ZORDER_FIRST);
adAggregates[i].pctrlInputControl->SetZOrder(adAggregates[i].pctrlTextControl, WINDOW_ZORDER_BEHIND );
pZOrderPredecessor = adAggregates[i].pctrlInputControl;
if (adAggregates[i].pctrlInputControl == pFormatSample)
{
pFormat->SetZOrder(pZOrderPredecessor, WINDOW_ZORDER_BEHIND);
pZOrderPredecessor = pFormat;
}
++nCurrentControlPos;
}
}
// eine Sonderbehandlung fuer die Format-Controls
if (pFormat)
{
Point ptSamplePos(pFormatSample->GetPosPixel());
Size szSampleSize(pFormatSample->GetSizePixel());
pFormat->SetPosPixel(Point(ptSamplePos.X() + szSampleSize.Width() + 5, ptSamplePos.Y()));
}
// als letztes noch die ScrollBars in der ZOrder ganz nach oben
m_pVertScroll->SetZOrder(NULL, WINDOW_ZORDER_FIRST);
m_pHorzScroll->SetZOrder(NULL, WINDOW_ZORDER_FIRST);
}
//------------------------------------------------------------------------------
void OFieldDescControl::ActivateAggregate( EControlType eType )
{
DBG_CHKTHIS(OFieldDescControl,NULL);
//////////////////////////////////////////////////////////////////////
// Controls erzeugen
switch( eType )
{
case tpDefault:
if( pDefault )
return;
m_nPos++;
pDefaultText = CreateText(STR_DEFAULT_VALUE);
pDefault = new OPropEditCtrl( this, STR_HELP_DEFAULT_VALUE, FIELD_PROPERTY_DEFAULT, WB_BORDER );
InitializeControl(pDefault,HID_TAB_ENT_DEFAULT,false);
break;
case tpAutoIncrementValue:
if( m_pAutoIncrementValue || !isAutoIncrementValueEnabled() )
return;
m_nPos++;
m_pAutoIncrementValueText = CreateText(STR_AUTOINCREMENT_VALUE);
m_pAutoIncrementValue = new OPropEditCtrl( this, STR_HELP_AUTOINCREMENT_VALUE, FIELD_PRPOERTY_AUTOINCREMENT, WB_BORDER );
m_pAutoIncrementValue->SetText( getAutoIncrementValue() );
InitializeControl(m_pAutoIncrementValue,HID_TAB_AUTOINCREMENTVALUE,false);
break;
case tpRequired:
{
if( pRequired )
return;
Reference< XDatabaseMetaData> xMetaData = getMetaData();
if(xMetaData.is() && xMetaData->supportsNonNullableColumns())
{
m_nPos++;
pRequiredText = CreateText(STR_FIELD_REQUIRED);
pRequired = new OPropListBoxCtrl( this, STR_HELP_FIELD_REQUIRED, FIELD_PROPERTY_REQUIRED, WB_DROPDOWN);
pRequired->InsertEntry( aYes );
pRequired->InsertEntry( aNo );
pRequired->SelectEntryPos(1);
InitializeControl(pRequired,HID_TAB_ENT_REQUIRED,true);
}
}
break;
case tpAutoIncrement:
{
if( pAutoIncrement )
return;
m_nPos++;
pAutoIncrementText = CreateText(STR_FIELD_AUTOINCREMENT);
pAutoIncrement = new OPropListBoxCtrl( this, STR_HELP_AUTOINCREMENT, FIELD_PROPERTY_AUTOINC, WB_DROPDOWN );
pAutoIncrement->InsertEntry( aYes );
pAutoIncrement->InsertEntry( aNo );
pAutoIncrement->SelectEntryPos(0);
InitializeControl(pAutoIncrement,HID_TAB_ENT_AUTOINCREMENT,true);
}
break;
case tpTextLen:
if( pTextLen )
return;
m_nPos++;
pTextLenText = CreateText(STR_TEXT_LENGTH);
pTextLen = CreateNumericControl(STR_HELP_TEXT_LENGTH, FIELD_PROPERTY_TEXTLEN,HID_TAB_ENT_TEXT_LEN);
break;
case tpType:
if( m_pType)
return;
m_nPos++;
m_pTypeText = CreateText(STR_TAB_FIELD_DATATYPE);
m_pType = new OPropListBoxCtrl( this, STR_HELP_AUTOINCREMENT, FIELD_PRPOERTY_TYPE, WB_DROPDOWN );
m_pType->SetDropDownLineCount(20);
{
const OTypeInfoMap* pTypeInfo = getTypeInfo();
OTypeInfoMap::const_iterator aIter = pTypeInfo->begin();
OTypeInfoMap::const_iterator aEnd = pTypeInfo->end();
for(;aIter != aEnd;++aIter)
m_pType->InsertEntry( aIter->second->aUIName );
}
m_pType->SelectEntryPos(0);
InitializeControl(m_pType,HID_TAB_ENT_TYPE,true);
break;
case tpColumnName:
if( m_pColumnName )
return;
m_nPos++;
{
sal_uInt32 nMax = EDIT_NOLIMIT;
::rtl::OUString aTmpString;
try
{
Reference< XDatabaseMetaData> xMetaData = getMetaData();
if ( xMetaData.is() )
{
nMax = xMetaData->getMaxColumnNameLength();
aTmpString = xMetaData->getExtraNameCharacters();
}
}
catch(Exception&)
{
DBG_UNHANDLED_EXCEPTION();
}
m_pColumnNameText = CreateText(STR_TAB_FIELD_NAME);
m_pColumnName = new OPropColumnEditCtrl( this,
aTmpString,
STR_HELP_DEFAULT_VALUE,
FIELD_PRPOERTY_COLUMNNAME,
WB_BORDER );
m_pColumnName->SetMaxTextLen(xub_StrLen( nMax ? nMax : EDIT_NOLIMIT));
m_pColumnName->setCheck( isSQL92CheckEnabled(getConnection()) );
}
InitializeControl(m_pColumnName,HID_TAB_ENT_COLUMNNAME,false);
break;
case tpNumType:
if( pNumType )
return;
m_nPos++;
pNumTypeText = CreateText(STR_NUMERIC_TYPE);
pNumType = new OPropListBoxCtrl( this, STR_HELP_NUMERIC_TYPE, FIELD_PROPERTY_NUMTYPE, WB_DROPDOWN );
pNumType->SetDropDownLineCount(5);
pNumType->InsertEntry( String::CreateFromAscii("Byte") );
pNumType->InsertEntry( String::CreateFromAscii("SmallInt") );
pNumType->InsertEntry( String::CreateFromAscii("Integer") );
pNumType->InsertEntry( String::CreateFromAscii("Single") );
pNumType->InsertEntry( String::CreateFromAscii("Double") );
pNumType->SelectEntryPos(2);
InitializeControl(pNumType,HID_TAB_ENT_NUMTYP,true);
break;
case tpLength:
if( pLength )
return;
m_nPos++;
pLengthText = CreateText(STR_LENGTH);
pLength = CreateNumericControl(STR_HELP_LENGTH, FIELD_PROPERTY_LENGTH,HID_TAB_ENT_LEN);
break;
case tpScale:
if( pScale )
return;
m_nPos++;
pScaleText = CreateText(STR_SCALE);
pScale = CreateNumericControl(STR_HELP_SCALE, FIELD_PROPERTY_SCALE,HID_TAB_ENT_SCALE);
break;
case tpFormat:
if (!pFormat)
{
m_nPos++;
pFormatText = CreateText(STR_FORMAT);
pFormatSample = new OPropEditCtrl( this, STR_HELP_FORMAT_CODE, -1, WB_BORDER );
pFormatSample->SetReadOnly(sal_True);
pFormatSample->Enable(sal_False);
InitializeControl(pFormatSample,HID_TAB_ENT_FORMAT_SAMPLE,false);
pFormat = new PushButton( this, ModuleRes(PB_FORMAT) );
const sal_Int32 nControlHeight = GetMaxControlHeight();
pFormat->SetSizePixel(Size(nControlHeight, nControlHeight));
pFormat->SetClickHdl( LINK( this, OFieldDescControl, FormatClickHdl ) );
InitializeControl(pFormat,HID_TAB_ENT_FORMAT,false);
}
UpdateFormatSample(pActFieldDescr);
break;
case tpBoolDefault:
if (pBoolDefault)
return;
m_nPos++;
pBoolDefaultText = CreateText(STR_DEFAULT_VALUE);
pBoolDefault = new OPropListBoxCtrl( this, STR_HELP_BOOL_DEFAULT, FIELD_PROPERTY_BOOL_DEFAULT, WB_DROPDOWN );
pBoolDefault->SetDropDownLineCount(3);
pBoolDefault->InsertEntry(String(ModuleRes(STR_VALUE_NONE)));
pBoolDefault->InsertEntry(aYes);
pBoolDefault->InsertEntry(aNo);
InitializeControl(pBoolDefault,HID_TAB_ENT_BOOL_DEFAULT,false);
break;
}
}
// -----------------------------------------------------------------------------
void OFieldDescControl::InitializeControl(Control* _pControl,ULONG _nHelpId,bool _bAddChangeHandler)
{
// FIXME: HELPID
#if 0
_pControl->SetHelpId(_nHelpId);
#endif
if ( _bAddChangeHandler )
((OPropListBoxCtrl*)_pControl)->SetSelectHdl(LINK(this,OFieldDescControl,ChangeHdl));
_pControl->SetGetFocusHdl(LINK(this, OFieldDescControl, OnControlFocusGot));
_pControl->SetLoseFocusHdl(LINK(this, OFieldDescControl, OnControlFocusLost));
_pControl->EnableClipSiblings();
}
// -----------------------------------------------------------------------------
FixedText* OFieldDescControl::CreateText(USHORT _nTextRes)
{
FixedText* pFixedText = new FixedText( this );
pFixedText->SetText( ModuleRes(_nTextRes) );
pFixedText->EnableClipSiblings();
return pFixedText;
}
// -----------------------------------------------------------------------------
OPropNumericEditCtrl* OFieldDescControl::CreateNumericControl(USHORT _nHelpStr,short _nProperty,ULONG _nHelpId)
{
OPropNumericEditCtrl* pControl = new OPropNumericEditCtrl( this, _nHelpStr, _nProperty, WB_BORDER );
pControl->SetDecimalDigits(0);
pControl->SetMin(0);
pControl->SetMax(0x7FFFFFFF); // soll draussen geaendert werden, wenn noetig
pControl->SetStrictFormat(TRUE);
InitializeControl(pControl,_nHelpId,false);
return pControl;
}
//------------------------------------------------------------------------------
void OFieldDescControl::DeactivateAggregate( EControlType eType )
{
DBG_CHKTHIS(OFieldDescControl,NULL);
pLastFocusWindow = NULL;
//////////////////////////////////////////////////////////////////////
// Controls zerstoeren
switch( eType )
{
case tpDefault:
lcl_HideAndDeleteControl(m_nPos,&pDefault,&pDefaultText);
break;
case tpAutoIncrementValue:
lcl_HideAndDeleteControl(m_nPos,&m_pAutoIncrementValue,&m_pAutoIncrementValueText);
break;
case tpColumnName:
lcl_HideAndDeleteControl(m_nPos,&m_pColumnName,&m_pColumnNameText);
break;
case tpType:
lcl_HideAndDeleteControl(m_nPos,&m_pType,&m_pTypeText);
break;
case tpAutoIncrement:
lcl_HideAndDeleteControl(m_nPos,&pAutoIncrement,&pAutoIncrementText);
break;
case tpRequired:
lcl_HideAndDeleteControl(m_nPos,&pRequired,&pRequiredText);
break;
case tpTextLen:
lcl_HideAndDeleteControl(m_nPos,&pTextLen,&pTextLenText);
break;
case tpNumType:
lcl_HideAndDeleteControl(m_nPos,&pNumType,&pNumTypeText);
break;
case tpLength:
lcl_HideAndDeleteControl(m_nPos,&pLength,&pLengthText);
break;
case tpScale:
lcl_HideAndDeleteControl(m_nPos,&pScale,&pScaleText);
break;
case tpFormat:
// TODO: we have to check if we have to increment m_nPos again
lcl_HideAndDeleteControl(m_nPos,&pFormat,&pFormatText);
if ( pFormatSample )
{
pFormatSample->Hide();
delete pFormatSample;
pFormatSample = NULL;
}
break;
case tpBoolDefault:
lcl_HideAndDeleteControl(m_nPos,&pBoolDefault,&pBoolDefaultText);
break;
}
}
//------------------------------------------------------------------------------
void OFieldDescControl::SetPosSize( Control** ppControl, long nRow, sal_uInt16 nCol )
{
DBG_CHKTHIS(OFieldDescControl,NULL);
//////////////////////////////////////////////////////////////////////
// Groesse ermitteln
const sal_Int32 nControlHeight = GetMaxControlHeight();
Size aSize(0,nControlHeight);
if ( isRightAligned() && nCol )
aSize.Width() = LogicToPixel(Size(m_nWidth, 0),MAP_APPFONT).Width();
else
{
switch( nCol )
{
case 0:
default:
aSize.Width() = CONTROL_WIDTH_1;
break;
case 1:
aSize.Width() = CONTROL_WIDTH_2;
break;
case 3:
aSize.Width() = CONTROL_WIDTH_3;
break;
case 4:
aSize.Width() = CONTROL_WIDTH_4;
break;
} // switch( nCol )
}
//////////////////////////////////////////////////////////////////////
// Position ermitteln
Point aPosition;
switch( nCol )
{
case 0:
aPosition.X() = 0;
aPosition.Y() = 1;
break;
case 1:
case 3:
case 4:
if ( isRightAligned() )
{
Size aOwnSize = GetSizePixel();
aPosition.X() = aOwnSize.Width() - aSize.Width();
}
else
aPosition.X() = CONTROL_WIDTH_1 + CONTROL_SPACING_X;
break;
default:
aPosition.X() = 0;
}
(*ppControl)->SetSizePixel( aSize );
aSize = (*ppControl)->GetSizePixel( );
const sal_Int32 nControl_Spacing_y = LogicToPixel(Size(0, CONTROL_SPACING_Y),MAP_APPFONT).Height();
aPosition.Y() += ((nRow+1)*nControl_Spacing_y) +
(nRow*nControlHeight);
//////////////////////////////////////////////////////////////////////
// Control anzeigen
(*ppControl)->SetPosSizePixel( aPosition, aSize );
aSize = (*ppControl)->GetSizePixel();
(*ppControl)->Show();
}
//------------------------------------------------------------------------------
void OFieldDescControl::DisplayData(OFieldDescription* pFieldDescr )
{
DBG_CHKTHIS(OFieldDescControl,NULL);
pActFieldDescr = pFieldDescr;
if(!pFieldDescr)
{
DeactivateAggregate( tpDefault );
DeactivateAggregate( tpRequired );
DeactivateAggregate( tpTextLen );
DeactivateAggregate( tpNumType );
DeactivateAggregate( tpScale );
DeactivateAggregate( tpLength );
DeactivateAggregate( tpFormat );
DeactivateAggregate( tpAutoIncrement );
DeactivateAggregate( tpBoolDefault );
DeactivateAggregate( tpColumnName );
DeactivateAggregate( tpType );
DeactivateAggregate( tpAutoIncrementValue );
m_pPreviousType = TOTypeInfoSP();
//////////////////////////////////////////////////////////////////////
// Zeiger des gespeicherten Focus zuruecksetzen
pLastFocusWindow = NULL;
if ( m_bAdded )
{
::dbaui::notifySystemWindow(this,this,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
m_bAdded = sal_False;
}
return;
}
if ( !m_bAdded )
{
::dbaui::notifySystemWindow(this,this,::comphelper::mem_fun(&TaskPaneList::AddWindow));
m_bAdded = sal_True;
}
TOTypeInfoSP pFieldType;
if( pFieldDescr )
pFieldType = pFieldDescr->getTypeInfo();
ActivateAggregate( tpColumnName );
ActivateAggregate( tpType );
OSL_ENSURE(pFieldType.get(),"We need a type information here!");
//////////////////////////////////////////////////////////////////////
// Wenn sich der Typ geaendert hat, Controls austauschen
if( m_pPreviousType != pFieldType )
{
//////////////////////////////////////////////////////////////////////
// Zeiger des gespeicherten Focus zuruecksetzen
pLastFocusWindow = NULL;
//////////////////////////////////////////////////////////////////////
// Controls, die nicht mehr angezeigt werden duerfen
DeactivateAggregate( tpNumType );
//////////////////////////////////////////////////////////////////////
// determine which controls we should show and which not
// 1. the required control
if ( pFieldType->bNullable )
ActivateAggregate( tpRequired );
else
DeactivateAggregate( tpRequired );
// 2. the autoincrement
if ( pFieldType->bAutoIncrement )
{
DeactivateAggregate( tpRequired );
DeactivateAggregate( tpDefault );
ActivateAggregate( tpAutoIncrement );
ActivateAggregate( tpAutoIncrementValue );
}
else
{
DeactivateAggregate( tpAutoIncrement );
DeactivateAggregate( tpAutoIncrementValue );
if(pFieldType->bNullable)
ActivateAggregate( tpRequired );
else
DeactivateAggregate( tpRequired );
ActivateAggregate( tpDefault );
}
// 3. the scale and precision
if (pFieldType->nPrecision)
{
ActivateAggregate( tpLength );
pLength->SetMax(::std::max<sal_Int32>(pFieldType->nPrecision,pFieldDescr->GetPrecision()));
pLength->SetSpecialReadOnly(pFieldType->aCreateParams.getLength()==0);
}
else
DeactivateAggregate( tpLength );
if (pFieldType->nMaximumScale)
{
ActivateAggregate( tpScale );
pScale->SetMax(::std::max<sal_Int32>(pFieldType->nMaximumScale,pFieldDescr->GetScale()));
pScale->SetMin(pFieldType->nMinimumScale);
static const ::rtl::OUString s_sPRECISION(RTL_CONSTASCII_USTRINGPARAM("PRECISION"));
pScale->SetSpecialReadOnly(pFieldType->aCreateParams.getLength() == 0 || pFieldType->aCreateParams == s_sPRECISION);
}
else
DeactivateAggregate( tpScale );
// and now look for type specific things
switch( pFieldType->nType )
{
case DataType::CHAR:
case DataType::VARCHAR:
case DataType::LONGVARCHAR:
DeactivateAggregate( tpLength );
DeactivateAggregate( tpBoolDefault );
ActivateAggregate( tpDefault );
ActivateAggregate( tpFormat );
if (pFieldType->nPrecision)
{
ActivateAggregate( tpTextLen );
pTextLen->SetMax(::std::max<sal_Int32>(pFieldType->nPrecision,pFieldDescr->GetPrecision()));
pTextLen->SetSpecialReadOnly(pFieldType->aCreateParams.getLength()==0);
}
else
DeactivateAggregate( tpTextLen );
break;
case DataType::DATE:
case DataType::TIME:
case DataType::TIMESTAMP:
DeactivateAggregate( tpLength ); // we don't need a length for date types
DeactivateAggregate( tpTextLen );
DeactivateAggregate( tpBoolDefault );
ActivateAggregate( tpDefault );
ActivateAggregate( tpFormat );
break;
case DataType::BIT:
if ( pFieldType->aCreateParams.getLength() )
{
DeactivateAggregate( tpFormat );
DeactivateAggregate( tpTextLen );
DeactivateAggregate( tpBoolDefault );
break;
}
// run through
case DataType::BOOLEAN:
DeactivateAggregate( tpTextLen );
DeactivateAggregate( tpFormat );
DeactivateAggregate( tpDefault );
ActivateAggregate( tpBoolDefault );
break;
case DataType::DECIMAL:
case DataType::NUMERIC:
case DataType::BIGINT:
case DataType::FLOAT:
case DataType::DOUBLE:
case DataType::TINYINT:
case DataType::SMALLINT:
case DataType::INTEGER:
case DataType::REAL:
DeactivateAggregate( tpTextLen );
DeactivateAggregate( tpBoolDefault );
ActivateAggregate( tpFormat );
break;
case DataType::BINARY:
case DataType::VARBINARY:
DeactivateAggregate( tpDefault );
DeactivateAggregate( tpRequired );
DeactivateAggregate( tpTextLen );
DeactivateAggregate( tpBoolDefault );
ActivateAggregate( tpFormat );
break;
case DataType::LONGVARBINARY:
case DataType::SQLNULL:
case DataType::OBJECT:
case DataType::DISTINCT:
case DataType::STRUCT:
case DataType::ARRAY:
case DataType::BLOB:
case DataType::CLOB:
case DataType::REF:
case DataType::OTHER:
DeactivateAggregate( tpFormat );
DeactivateAggregate( tpTextLen );
DeactivateAggregate( tpBoolDefault );
break;
default:
OSL_ENSURE(0,"Unknown type");
}
m_pPreviousType = pFieldType;
}
if(pFieldDescr)
{
if(pFieldDescr->IsPrimaryKey())
{
DeactivateAggregate( tpRequired );
}
else if ( !pAutoIncrement && pFieldType.get() )
{
if ( pFieldType->bNullable )
ActivateAggregate( tpRequired );
else
DeactivateAggregate( tpRequired );
}
}
//////////////////////////////////////////////////////////////////////
// Controls initialisieren
if( pAutoIncrement )
{
if ( pFieldDescr->IsAutoIncrement() )
{
pAutoIncrement->SelectEntryPos( 0 ); // yes
ActivateAggregate( tpAutoIncrementValue );
if ( m_pAutoIncrementValue )
m_pAutoIncrementValue->SetText(pFieldDescr->GetAutoIncrementValue());
DeactivateAggregate( tpRequired );
DeactivateAggregate( tpDefault );
}
else
{
// disable autoincrement value because it should only be visible when autoincrement is to true
DeactivateAggregate( tpAutoIncrementValue );
pAutoIncrement->SelectEntryPos( 1 ); // no
ActivateAggregate( tpDefault );
// hat Auswirkungen auf pRequired
if(!pFieldDescr->IsPrimaryKey())
ActivateAggregate( tpRequired );
}
}
if( pDefault )
{
pDefault->SetText( getControlDefault(pFieldDescr) );
pDefault->ClearModifyFlag();
}
if( pBoolDefault )
{
// wenn pRequired auf sal_True gesetzt ist, dann darf das sal_Bool Feld nicht den Eintrag <<keiner>> besitzen
::rtl::OUString sValue;
pFieldDescr->GetControlDefault() >>= sValue;
String sDef = BoolStringUI(sValue);
// sicher stellen das <<keiner>> nur vorhanden ist, wenn das Feld NULL sein darf
if ( ( pFieldType.get() && !pFieldType->bNullable ) || !pFieldDescr->IsNullable() )
{
pFieldDescr->SetIsNullable(ColumnValue::NO_NULLS); // der Typ sagt das
pBoolDefault->RemoveEntry(String(ModuleRes(STR_VALUE_NONE)));
if ( !sDef.Equals(aYes) && !sDef.Equals(aNo) )
pBoolDefault->SelectEntryPos(1); // nein als Default
else
pBoolDefault->SelectEntry(sDef);
pFieldDescr->SetControlDefault(makeAny(::rtl::OUString(BoolStringPersistent(pBoolDefault->GetSelectEntry()))));
}
else if(pBoolDefault->GetEntryCount() < 3)
{
pBoolDefault->InsertEntry(String(ModuleRes(STR_VALUE_NONE)));
pBoolDefault->SelectEntry(sDef);
}
else
pBoolDefault->SelectEntry(sDef);
}
if( pRequired )
{
if( pFieldDescr->IsNullable() )
pRequired->SelectEntryPos( 1 ); // no
else
pRequired->SelectEntryPos( 0 ); // yes
}
if( pTextLen )
{
pTextLen->SetText( String::CreateFromInt32(pFieldDescr->GetPrecision()) );
pTextLen->ClearModifyFlag();
}
if( pNumType )
{
OSL_ENSURE(sal_False, "OFieldDescControl::DisplayData: invalid num type!");
}
if( pLength )
pLength->SetText( String::CreateFromInt32(pFieldDescr->GetPrecision()) );
if( pScale )
pScale->SetText( String::CreateFromInt32(pFieldDescr->GetScale()) );
if( pFormat )
UpdateFormatSample(pFieldDescr);
if(m_pColumnName)
m_pColumnName->SetText(pFieldDescr->GetName());
if(m_pType)
{
USHORT nPos = pFieldType.get() ? m_pType->GetEntryPos(String(pFieldDescr->getTypeInfo()->aUIName)) : LISTBOX_ENTRY_NOTFOUND;
if(nPos == LISTBOX_ENTRY_NOTFOUND)
{
const OTypeInfoMap* pMap = getTypeInfo();
OTypeInfoMap::const_iterator aIter = pMap->find(pFieldType.get() ? pFieldDescr->getTypeInfo()->nType : pFieldDescr->GetType());
if(aIter == pMap->end() && !pMap->empty())
{
aIter = pMap->begin();
if(pFieldDescr->GetPrecision() > aIter->second->nPrecision)
pFieldDescr->SetPrecision(aIter->second->nPrecision);
if(pFieldDescr->GetScale() > aIter->second->nMaximumScale)
pFieldDescr->SetScale(0);
if(!aIter->second->bNullable && pFieldDescr->IsNullable())
pFieldDescr->SetIsNullable(ColumnValue::NO_NULLS);
if(!aIter->second->bAutoIncrement && pFieldDescr->IsAutoIncrement())
pFieldDescr->SetAutoIncrement(sal_False);
}
if ( aIter != pMap->end() )
{
pFieldDescr->SetType(aIter->second);
}
}
m_pType->SelectEntry(pFieldDescr->getTypeInfo()->aUIName);
}
//////////////////////////////////////////////////////////////////////
// Controls Enablen/Disablen
sal_Bool bRead(IsReadOnly());
ArrangeAggregates();
CheckScrollBars();
ScrollAllAggregates();
SetReadOnly( bRead );
}
//------------------------------------------------------------------------
IMPL_LINK(OFieldDescControl, DelayedGrabFocus, Control**, ppControl)
{
nDelayedGrabFocusEvent = 0;
if (*ppControl)
(*ppControl)->GrabFocus();
return 0L;
}
//------------------------------------------------------------------------------
IMPL_LINK(OFieldDescControl, OnControlFocusGot, Control*, pControl )
{
String strHelpText;
OPropNumericEditCtrl* pNumeric = dynamic_cast< OPropNumericEditCtrl* >( pControl );
if ( pNumeric )
{
pNumeric->SaveValue();
strHelpText = pNumeric->GetHelp();
}
OPropColumnEditCtrl* pColumn = dynamic_cast< OPropColumnEditCtrl* >( pControl );
if ( pColumn )
{
pColumn->SaveValue();
strHelpText = pColumn->GetHelp();
}
OPropEditCtrl* pEdit = dynamic_cast< OPropEditCtrl* >( pControl );
if ( pEdit )
{
pEdit->SaveValue();
strHelpText = pEdit->GetHelp();
}
OPropListBoxCtrl* pListBox = dynamic_cast< OPropListBoxCtrl* >( pControl );
if ( pListBox )
{
pListBox->SaveValue();
strHelpText = pListBox->GetHelp();
}
if (pControl == pFormat)
strHelpText =String(ModuleRes(STR_HELP_FORMAT_BUTTON));
if (strHelpText.Len() && (pHelp != NULL))
pHelp->SetHelpText(strHelpText);
m_pActFocusWindow = pControl;
return 0L;
}
//------------------------------------------------------------------------------
IMPL_LINK(OFieldDescControl, OnControlFocusLost, Control*, pControl )
{
if ((pControl == pLength) || (pControl == pTextLen) || (pControl == pScale))
{
OPropNumericEditCtrl* pConverted = (OPropNumericEditCtrl*)pControl;
if (pConverted->IsModified())
CellModified(-1, pConverted->GetPos());
}
if(pControl == m_pColumnName)
{
OPropColumnEditCtrl* pConverted = (OPropColumnEditCtrl*)pControl;
if (pConverted->IsModified())
CellModified(-1, pConverted->GetPos());
}
else if ((pControl == pDefault) || (pControl == pFormatSample) || (pControl == m_pAutoIncrementValue) )
{
OPropEditCtrl* pConverted = (OPropEditCtrl*)pControl;
if (pConverted->IsModified())
CellModified(-1, pConverted->GetPos());
}
else if ((pControl == pRequired) || (pControl == pNumType) || (pControl == pAutoIncrement) || (pControl == pBoolDefault) || (pControl == m_pType))
{
OPropListBoxCtrl* pConverted = (OPropListBoxCtrl*)pControl;
if (pConverted->IsModified())
CellModified(-1, pConverted->GetPos());
}
if (pControl == pDefault)
UpdateFormatSample(pActFieldDescr);
implFocusLost(pControl);
return 0L;
}
//------------------------------------------------------------------------------
void OFieldDescControl::SaveData( OFieldDescription* pFieldDescr )
{
DBG_CHKTHIS(OFieldDescControl,NULL);
if( !pFieldDescr )
return;
//////////////////////////////////////////////////////////////////////
// Controls auslesen
::rtl::OUString sDefault;
if (pDefault)
{
sDefault = pDefault->GetText();
}
else if (pBoolDefault)
{
sDefault = BoolStringPersistent(pBoolDefault->GetSelectEntry());
}
if ( sDefault.getLength() )
{
sal_uInt32 nFormatKey;
try
{
if ( isTextFormat(pFieldDescr,nFormatKey) || pBoolDefault )
{
pFieldDescr->SetControlDefault(makeAny(sDefault));
}
else
{
try
{
double nValue = GetFormatter()->convertStringToNumber(nFormatKey,sDefault);
nValue = checkDoubleForDateFormat(nValue,nFormatKey,GetFormatter());
pFieldDescr->SetControlDefault(makeAny(nValue));
}
catch(const Exception&)
{
if ( sDefault.getLength() )
pFieldDescr->SetControlDefault(makeAny(sDefault));
else
pFieldDescr->SetControlDefault(Any());
}
}
}
catch(const Exception&)
{
}
} // if ( sDefault.getLength() )
else
pFieldDescr->SetControlDefault(Any());
if((pRequired && pRequired->GetSelectEntryPos() == 0) || pFieldDescr->IsPrimaryKey() || (pBoolDefault && pBoolDefault->GetEntryCount() == 2)) // yes
pFieldDescr->SetIsNullable( ColumnValue::NO_NULLS );
else
pFieldDescr->SetIsNullable( ColumnValue::NULLABLE );
if ( pAutoIncrement )
pFieldDescr->SetAutoIncrement( pAutoIncrement->GetSelectEntryPos() == 0 );
if( pTextLen )
pFieldDescr->SetPrecision( static_cast<sal_Int32>(pTextLen->GetValue()) );
else if( pLength )
pFieldDescr->SetPrecision( static_cast<sal_Int32>(pLength->GetValue()) );
if( pScale )
pFieldDescr->SetScale( static_cast<sal_Int32>(pScale->GetValue()) );
if(m_pColumnName)
pFieldDescr->SetName(m_pColumnName->GetText());
if ( m_pAutoIncrementValue && isAutoIncrementValueEnabled() )
pFieldDescr->SetAutoIncrementValue(m_pAutoIncrementValue->GetText());
}
//------------------------------------------------------------------------------
void OFieldDescControl::UpdateFormatSample(OFieldDescription* pFieldDescr)
{
if ( pFieldDescr && pFormatSample )
pFormatSample->SetText(getControlDefault(pFieldDescr,sal_False));
}
//------------------------------------------------------------------------------
void OFieldDescControl::GetFocus()
{
DBG_CHKTHIS(OFieldDescControl,NULL);
//////////////////////////////////////////////////////////////////////
// Setzt den Focus auf das zuletzt aktive Control
TabPage::GetFocus();
if( pLastFocusWindow )
{
pLastFocusWindow->GrabFocus();
pLastFocusWindow = NULL;
}
}
//------------------------------------------------------------------------------
void OFieldDescControl::implFocusLost(Window* _pWhich)
{
DBG_CHKTHIS(OFieldDescControl,NULL);
DBG_ASSERT(!_pWhich || IsChild(_pWhich), "OFieldDescControl::implFocusLost : invalid window !");
//////////////////////////////////////////////////////////////////////
// Das aktive Control merken
if (!pLastFocusWindow)
pLastFocusWindow = _pWhich;
//////////////////////////////////////////////////////////////////////
// HelpText zuruecksetzen
if (pHelp && !pHelp->HasChildPathFocus())
pHelp->SetHelpText( String() );
}
//------------------------------------------------------------------------------
void OFieldDescControl::LoseFocus()
{
DBG_CHKTHIS(OFieldDescControl,NULL);
implFocusLost(NULL);
TabPage::LoseFocus();
}
// -----------------------------------------------------------------------------
sal_Bool OFieldDescControl::isCopyAllowed()
{
sal_Bool bAllowed = (m_pActFocusWindow != NULL) &&
(m_pActFocusWindow == pDefault || m_pActFocusWindow == pFormatSample ||
m_pActFocusWindow == pTextLen || m_pActFocusWindow == pLength ||
m_pActFocusWindow == pScale || m_pActFocusWindow == m_pColumnName ||
m_pActFocusWindow == m_pAutoIncrementValue) &&
static_cast<Edit*>(m_pActFocusWindow)->GetSelected().Len() != 0;
return bAllowed;
}
// -----------------------------------------------------------------------------
sal_Bool OFieldDescControl::isCutAllowed()
{
sal_Bool bAllowed = (m_pActFocusWindow != NULL) &&
(m_pActFocusWindow == pDefault || m_pActFocusWindow == pFormatSample ||
m_pActFocusWindow == pTextLen || m_pActFocusWindow == pLength ||
m_pActFocusWindow == pScale || m_pActFocusWindow == m_pColumnName ||
m_pActFocusWindow == m_pAutoIncrementValue) &&
static_cast<Edit*>(m_pActFocusWindow)->GetSelected().Len() != 0;
return bAllowed;
}
// -----------------------------------------------------------------------------
sal_Bool OFieldDescControl::isPasteAllowed()
{
sal_Bool bAllowed = (m_pActFocusWindow != NULL) &&
(m_pActFocusWindow == pDefault || m_pActFocusWindow == pFormatSample ||
m_pActFocusWindow == pTextLen || m_pActFocusWindow == pLength ||
m_pActFocusWindow == pScale || m_pActFocusWindow == m_pColumnName ||
m_pActFocusWindow == m_pAutoIncrementValue);
if ( bAllowed )
{
TransferableDataHelper aTransferData(TransferableDataHelper::CreateFromSystemClipboard(GetParent()));
bAllowed = aTransferData.HasFormat(SOT_FORMAT_STRING);
}
return bAllowed;
}
// -----------------------------------------------------------------------------
void OFieldDescControl::cut()
{
if(isCutAllowed())
static_cast<Edit*>(m_pActFocusWindow)->Cut();
}
// -----------------------------------------------------------------------------
void OFieldDescControl::copy()
{
if(isCopyAllowed()) // this only checks if the focus window is valid
static_cast<Edit*>(m_pActFocusWindow)->Copy();
}
// -----------------------------------------------------------------------------
void OFieldDescControl::paste()
{
if(m_pActFocusWindow) // this only checks if the focus window is valid
static_cast<Edit*>(m_pActFocusWindow)->Paste();
}
// -----------------------------------------------------------------------------
sal_Bool OFieldDescControl::isTextFormat(const OFieldDescription* _pFieldDescr,sal_uInt32& _nFormatKey) const
{
_nFormatKey = _pFieldDescr->GetFormatKey();
sal_Bool bTextFormat = sal_True;
try
{
if (!_nFormatKey)
{
Reference< ::com::sun::star::util::XNumberFormatTypes> xNumberTypes(GetFormatter()->getNumberFormatsSupplier()->getNumberFormats(),UNO_QUERY);
OSL_ENSURE(xNumberTypes.is(),"XNumberFormatTypes is null!");
_nFormatKey = ::dbtools::getDefaultNumberFormat( _pFieldDescr->GetType(),
_pFieldDescr->GetScale(),
_pFieldDescr->IsCurrency(),
xNumberTypes,
GetLocale());
}
sal_Int32 nNumberFormat = ::comphelper::getNumberFormatType(GetFormatter(),_nFormatKey);
bTextFormat = (nNumberFormat == ::com::sun::star::util::NumberFormat::TEXT);
}
catch(const Exception&)
{
}
return bTextFormat;
}
// -----------------------------------------------------------------------------
String OFieldDescControl::getControlDefault( const OFieldDescription* _pFieldDescr ,sal_Bool _bCheck) const
{
::rtl::OUString sDefault;
sal_Bool bCheck = !_bCheck || _pFieldDescr->GetControlDefault().hasValue();
if ( bCheck )
{
sal_uInt32 nFormatKey;
sal_Bool bTextFormat = sal_False;
double nValue = 0.0;
try
{
bTextFormat = isTextFormat(_pFieldDescr,nFormatKey);
if ( _pFieldDescr->GetControlDefault() >>= sDefault )
{
if ( !bTextFormat )
{
if ( sDefault.getLength() )
{
try
{
nValue = GetFormatter()->convertStringToNumber(nFormatKey,sDefault);
}
catch(const Exception&)
{
return ::rtl::OUString(); // return empty string for format example
}
}
}
}
else
_pFieldDescr->GetControlDefault() >>= nValue;
Reference< ::com::sun::star::util::XNumberFormatter> xNumberFormatter = GetFormatter();
Reference<XPropertySet> xFormSet = xNumberFormatter->getNumberFormatsSupplier()->getNumberFormats()->getByKey(nFormatKey);
OSL_ENSURE(xFormSet.is(),"XPropertySet is null!");
::rtl::OUString sFormat;
xFormSet->getPropertyValue(::rtl::OUString::createFromAscii("FormatString")) >>= sFormat;
if ( !bTextFormat )
{
Locale aLocale;
::comphelper::getNumberFormatProperty(xNumberFormatter,nFormatKey,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Locale"))) >>= aLocale;
sal_Int32 nNumberFormat = ::comphelper::getNumberFormatType(xNumberFormatter,nFormatKey);
if( (nNumberFormat & ::com::sun::star::util::NumberFormat::DATE) == ::com::sun::star::util::NumberFormat::DATE
|| (nNumberFormat & ::com::sun::star::util::NumberFormat::DATETIME) == ::com::sun::star::util::NumberFormat::DATETIME )
{
nValue = DBTypeConversion::toNullDate(DBTypeConversion::getNULLDate(xNumberFormatter->getNumberFormatsSupplier()),nValue);
}
Reference< ::com::sun::star::util::XNumberFormatPreviewer> xPreViewer(xNumberFormatter,UNO_QUERY);
OSL_ENSURE(xPreViewer.is(),"XNumberFormatPreviewer is null!");
sDefault = xPreViewer->convertNumberToPreviewString(sFormat,nValue,aLocale,sal_True);
}
else if ( !_bCheck || (sDefault.getLength() != 0) )
sDefault = xNumberFormatter->formatString(nFormatKey,(sDefault.getLength() != 0 )? sDefault : sFormat);
}
catch(const Exception&)
{
}
}
return sDefault;
}
// -----------------------------------------------------------------------------
|