1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
|
/* -*- 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.
*
************************************************************************/
#include <algorithm>
#include "scitems.hxx"
#include <editeng/eeitem.hxx>
#include <sfx2/app.hxx>
#include <editeng/adjitem.hxx>
#include <editeng/editview.hxx>
#include <editeng/editstat.hxx>
#include <editeng/frmdiritem.hxx>
#include <editeng/lspcitem.hxx>
#include <sfx2/bindings.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/event.hxx>
#include <sfx2/imgmgr.hxx>
#include <stdlib.h> // qsort
#include <editeng/scriptspaceitem.hxx>
#include <editeng/scripttypeitem.hxx>
#include <vcl/cursor.hxx>
#include <vcl/help.hxx>
#include <svl/stritem.hxx>
#include <stdio.h>
#include "inputwin.hxx"
#include "scmod.hxx"
#include "uiitems.hxx"
#include "global.hxx"
#include "scresid.hxx"
#include "sc.hrc"
#include "globstr.hrc"
#include "reffact.hxx"
#include "editutil.hxx"
#include "inputhdl.hxx"
#include "tabvwsh.hxx"
#include "document.hxx"
#include "docsh.hxx"
#include "appoptio.hxx"
#include "rangenam.hxx"
#include <formula/compiler.hrc>
#include "dbdata.hxx"
#include "rangeutl.hxx"
#include "docfunc.hxx"
#include "funcdesc.hxx"
#include "markdata.hxx"
#include <editeng/fontitem.hxx>
#include <com/sun/star/accessibility/XAccessible.hpp>
#include "AccessibleEditObject.hxx"
#include "AccessibleText.hxx"
#include <svtools/miscopt.hxx>
#include <comphelper/string.hxx>
#include <com/sun/star/frame/XLayoutManager.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/frame/XController.hpp>
#define THESIZE 1000000 //!!! langt... :-)
#define TBX_WINDOW_HEIGHT 22 // in Pixeln - fuer alle Systeme gleich?
#define LEFT_OFFSET 5
#define INPUTWIN_MULTILINES 6
const long BUTTON_OFFSET = 2; ///< space between input line and the button to expand / collapse
const long ADDITIONAL_BORDER = 1; ///< height of the line at the bottom
const long ADDITIONAL_SPACE = 4; ///< additional vertical space when the multiline edit has more lines
using com::sun::star::uno::Reference;
using com::sun::star::uno::UNO_QUERY;
using com::sun::star::frame::XLayoutManager;
using com::sun::star::frame::XModel;
using com::sun::star::frame::XFrame;
using com::sun::star::frame::XController;
using com::sun::star::beans::XPropertySet;
enum ScNameInputType
{
SC_NAME_INPUT_CELL,
SC_NAME_INPUT_RANGE,
SC_NAME_INPUT_NAMEDRANGE,
SC_NAME_INPUT_DATABASE,
SC_NAME_INPUT_ROW,
SC_NAME_INPUT_SHEET,
SC_NAME_INPUT_DEFINE,
SC_NAME_INPUT_BAD_NAME,
SC_NAME_INPUT_BAD_SELECTION,
SC_MANAGE_NAMES
};
ScTextWndBase::ScTextWndBase( Window* pParent, WinBits nStyle )
: Window ( pParent, nStyle )
{
if ( IsNativeControlSupported( CTRL_EDITBOX, PART_ENTIRE_CONTROL ) )
{
SetType( WINDOW_CALCINPUTLINE );
SetBorderStyle( WINDOW_BORDER_NWF );
}
}
//==================================================================
// class ScInputWindowWrapper
//==================================================================
SFX_IMPL_CHILDWINDOW_WITHID(ScInputWindowWrapper,FID_INPUTLINE_STATUS)
ScInputWindowWrapper::ScInputWindowWrapper( Window* pParentP,
sal_uInt16 nId,
SfxBindings* pBindings,
SfxChildWinInfo* /* pInfo */ )
: SfxChildWindow( pParentP, nId )
{
ScInputWindow* pWin=new ScInputWindow( pParentP, pBindings );
pWindow = pWin;
pWin->Show();
pWin->SetSizePixel( pWin->CalcWindowSizePixel() );
eChildAlignment = SFX_ALIGN_LOWESTTOP;
pBindings->Invalidate( FID_TOGGLEINPUTLINE );
}
// GetInfo fliegt wieder raus, wenn es ein SFX_IMPL_TOOLBOX gibt !!!!
SfxChildWinInfo ScInputWindowWrapper::GetInfo() const
{
SfxChildWinInfo aInfo = SfxChildWindow::GetInfo();
return aInfo;
}
//==================================================================
#define IMAGE(id) pImgMgr->SeekImage(id)
bool lcl_isExperimentalMode()
{
// make inputbar feature on by default, leave the switch for the
// moment in case we need to back it out easily
return true;
}
//==================================================================
// class ScInputWindow
//==================================================================
ScTextWndBase* lcl_chooseRuntimeImpl( Window* pParent, SfxBindings* pBind )
{
ScTabViewShell* pViewSh = NULL;
SfxDispatcher* pDisp = pBind->GetDispatcher();
if ( pDisp )
{
SfxViewFrame* pViewFrm = pDisp->GetFrame();
if ( pViewFrm )
pViewSh = PTR_CAST( ScTabViewShell, pViewFrm->GetViewShell() );
}
if ( !lcl_isExperimentalMode() )
return new ScTextWnd( pParent, pViewSh );
return new ScInputBarGroup( pParent, pViewSh );
}
ScInputWindow::ScInputWindow( Window* pParent, SfxBindings* pBind ) :
// mit WB_CLIPCHILDREN, sonst Flicker
ToolBox ( pParent, WinBits(WB_CLIPCHILDREN) ),
aWndPos ( this ),
pRuntimeWindow ( lcl_chooseRuntimeImpl( this, pBind ) ),
aTextWindow ( *pRuntimeWindow ),
pInputHdl ( NULL ),
aTextOk ( ScResId( SCSTR_QHELP_BTNOK ) ), // nicht immer neu aus Resource
aTextCancel ( ScResId( SCSTR_QHELP_BTNCANCEL ) ),
aTextSum ( ScResId( SCSTR_QHELP_BTNSUM ) ),
aTextEqual ( ScResId( SCSTR_QHELP_BTNEQUAL ) ),
mnMaxY (0),
bIsOkCancelMode ( false ),
bInResize ( false ),
mbIsMultiLine ( lcl_isExperimentalMode() )
{
ScModule* pScMod = SC_MOD();
SfxImageManager* pImgMgr = SfxImageManager::GetImageManager( pScMod );
// #i73615# don't rely on SfxViewShell::Current while constructing the input line
// (also for GetInputHdl below)
ScTabViewShell* pViewSh = NULL;
SfxDispatcher* pDisp = pBind->GetDispatcher();
if ( pDisp )
{
SfxViewFrame* pViewFrm = pDisp->GetFrame();
if ( pViewFrm )
pViewSh = PTR_CAST( ScTabViewShell, pViewFrm->GetViewShell() );
}
OSL_ENSURE( pViewSh, "no view shell for input window" );
// Position window, 3 buttons, input window
InsertWindow ( 1, &aWndPos, 0, 0 );
InsertSeparator ( 1 );
InsertItem ( SID_INPUT_FUNCTION, IMAGE( SID_INPUT_FUNCTION ), 0, 2 );
InsertItem ( SID_INPUT_SUM, IMAGE( SID_INPUT_SUM ), 0, 3 );
InsertItem ( SID_INPUT_EQUAL, IMAGE( SID_INPUT_EQUAL ), 0, 4 );
InsertSeparator ( 5 );
InsertWindow ( 7, &aTextWindow, 0, 6 );
aWndPos .SetQuickHelpText( ScResId( SCSTR_QHELP_POSWND ) );
aWndPos .SetHelpId ( HID_INSWIN_POS );
aTextWindow.SetQuickHelpText( ScResId( SCSTR_QHELP_INPUTWND ) );
aTextWindow.SetHelpId ( HID_INSWIN_INPUT );
// kein SetHelpText, die Hilfetexte kommen aus der Hilfe
SetItemText ( SID_INPUT_FUNCTION, ScResId( SCSTR_QHELP_BTNCALC ) );
SetHelpId ( SID_INPUT_FUNCTION, HID_INSWIN_CALC );
SetItemText ( SID_INPUT_SUM, aTextSum );
SetHelpId ( SID_INPUT_SUM, HID_INSWIN_SUMME );
SetItemText ( SID_INPUT_EQUAL, aTextEqual );
SetHelpId ( SID_INPUT_EQUAL, HID_INSWIN_FUNC );
SetHelpId( HID_SC_INPUTWIN ); // fuer die ganze Eingabezeile
aWndPos .Show();
aTextWindow.Show();
pInputHdl = SC_MOD()->GetInputHdl( pViewSh, false ); // use own handler even if ref-handler is set
if (pInputHdl)
pInputHdl->SetInputWindow( this );
if (pInputHdl && !pInputHdl->GetFormString().isEmpty())
{
// Umschalten waehrend der Funktionsautopilot aktiv ist
// -> Inhalt des Funktionsautopiloten wieder anzeigen
//! auch Selektion (am InputHdl gemerkt) wieder anzeigen
aTextWindow.SetTextString( pInputHdl->GetFormString() );
}
else if ( pInputHdl && pInputHdl->IsInputMode() )
{
// wenn waehrend des Editierens die Eingabezeile weg war
// (Editieren einer Formel, dann umschalten zu fremdem Dokument/Hilfe),
// wieder den gerade editierten Text aus dem InputHandler anzeigen
aTextWindow.SetTextString( pInputHdl->GetEditString() ); // Text anzeigen
if ( pInputHdl->IsTopMode() )
pInputHdl->SetMode( SC_INPUT_TABLE ); // Focus kommt eh nach unten
}
else if ( pViewSh )
pViewSh->UpdateInputHandler( sal_True ); // unbedingtes Update
pImgMgr->RegisterToolBox( this );
SetAccessibleName(ScResId(STR_ACC_TOOLBAR_FORMULA));
}
ScInputWindow::~ScInputWindow()
{
sal_Bool bDown = ( ScGlobal::pSysLocale == NULL ); // after Clear?
// if any view's input handler has a pointer to this input window, reset it
// (may be several ones, #74522#)
// member pInputHdl is not used here
if ( !bDown )
{
TypeId aScType = TYPE(ScTabViewShell);
SfxViewShell* pSh = SfxViewShell::GetFirst( &aScType );
while ( pSh )
{
ScInputHandler* pHdl = ((ScTabViewShell*)pSh)->GetInputHandler();
if ( pHdl && pHdl->GetInputWindow() == this )
{
pHdl->SetInputWindow( NULL );
pHdl->StopInputWinEngine( false ); // reset pTopView pointer
}
pSh = SfxViewShell::GetNext( *pSh, &aScType );
}
}
SfxImageManager::GetImageManager( SC_MOD() )->ReleaseToolBox( this );
}
void ScInputWindow::SetInputHandler( ScInputHandler* pNew )
{
// wird im Activate der View gerufen...
if ( pNew != pInputHdl )
{
// Bei Reload (letzte Version) ist pInputHdl der Input-Handler der alten,
// geloeschten ViewShell, darum hier auf keinen Fall anfassen!
pInputHdl = pNew;
if (pInputHdl)
pInputHdl->SetInputWindow( this );
}
}
bool ScInputWindow::UseSubTotal(ScRangeList* pRangeList) const
{
bool bSubTotal = false;
ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
if ( pViewSh )
{
ScDocument* pDoc = pViewSh->GetViewData()->GetDocument();
size_t nRangeCount (pRangeList->size());
size_t nRangeIndex (0);
while (!bSubTotal && nRangeIndex < nRangeCount)
{
const ScRange* pRange = (*pRangeList)[nRangeIndex];
if( pRange )
{
SCTAB nTabEnd(pRange->aEnd.Tab());
SCTAB nTab(pRange->aStart.Tab());
while (!bSubTotal && nTab <= nTabEnd)
{
SCROW nRowEnd(pRange->aEnd.Row());
SCROW nRow(pRange->aStart.Row());
while (!bSubTotal && nRow <= nRowEnd)
{
if (pDoc->RowFiltered(nRow, nTab))
bSubTotal = true;
else
++nRow;
}
++nTab;
}
}
++nRangeIndex;
}
const ScDBCollection::NamedDBs& rDBs = pDoc->GetDBCollection()->getNamedDBs();
ScDBCollection::NamedDBs::const_iterator itr = rDBs.begin(), itrEnd = rDBs.end();
for (; !bSubTotal && itr != itrEnd; ++itr)
{
const ScDBData& rDB = *itr;
if (!rDB.HasAutoFilter())
continue;
nRangeIndex = 0;
while (!bSubTotal && nRangeIndex < nRangeCount)
{
const ScRange* pRange = (*pRangeList)[nRangeIndex];
if( pRange )
{
ScRange aDBArea;
rDB.GetArea(aDBArea);
if (aDBArea.Intersects(*pRange))
bSubTotal = true;
}
++nRangeIndex;
}
}
}
return bSubTotal;
}
void ScInputWindow::Select()
{
ScModule* pScMod = SC_MOD();
ToolBox::Select();
switch ( GetCurItemId() )
{
case SID_INPUT_FUNCTION:
{
//! new method at ScModule to query if function autopilot is open
SfxViewFrame* pViewFrm = SfxViewFrame::Current();
if ( pViewFrm && !pViewFrm->GetChildWindow( SID_OPENDLG_FUNCTION ) )
{
pViewFrm->GetDispatcher()->Execute( SID_OPENDLG_FUNCTION,
SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD );
// die Toolbox wird sowieso disabled, also braucht auch nicht umgeschaltet
// zu werden, egal ob's geklappt hat oder nicht
// SetOkCancelMode();
}
}
break;
case SID_INPUT_CANCEL:
pScMod->InputCancelHandler();
SetSumAssignMode();
break;
case SID_INPUT_OK:
pScMod->InputEnterHandler();
SetSumAssignMode();
aTextWindow.Invalidate(); // sonst bleibt Selektion stehen
break;
case SID_INPUT_SUM:
{
ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
if ( pViewSh )
{
const ScMarkData& rMark = pViewSh->GetViewData()->GetMarkData();
if ( rMark.IsMarked() || rMark.IsMultiMarked() )
{
ScRangeList aMarkRangeList;
rMark.FillRangeListWithMarks( &aMarkRangeList, false );
ScDocument* pDoc = pViewSh->GetViewData()->GetDocument();
// check if one of the marked ranges is empty
bool bEmpty = false;
const size_t nCount = aMarkRangeList.size();
for ( size_t i = 0; i < nCount; ++i )
{
const ScRange aRange( *aMarkRangeList[i] );
if ( pDoc->IsBlockEmpty( aRange.aStart.Tab(),
aRange.aStart.Col(), aRange.aStart.Row(),
aRange.aEnd.Col(), aRange.aEnd.Row() ) )
{
bEmpty = true;
break;
}
}
if ( bEmpty )
{
ScRangeList aRangeList;
const sal_Bool bDataFound = pViewSh->GetAutoSumArea( aRangeList );
if ( bDataFound )
{
ScAddress aAddr = aRangeList.back()->aEnd;
aAddr.IncRow();
const sal_Bool bSubTotal( UseSubTotal( &aRangeList ) );
pViewSh->EnterAutoSum( aRangeList, bSubTotal, aAddr );
}
}
else
{
const sal_Bool bSubTotal( UseSubTotal( &aMarkRangeList ) );
for ( size_t i = 0; i < nCount; ++i )
{
const ScRange aRange( *aMarkRangeList[i] );
const bool bSetCursor = ( i == nCount - 1 ? true : false );
const bool bContinue = ( i != 0 ? true : false );
if ( !pViewSh->AutoSum( aRange, bSubTotal, bSetCursor, bContinue ) )
{
pViewSh->MarkRange( aRange, false, false );
pViewSh->SetCursor( aRange.aEnd.Col(), aRange.aEnd.Row() );
const ScRangeList aRangeList;
ScAddress aAddr = aRange.aEnd;
aAddr.IncRow();
const String aFormula = pViewSh->GetAutoSumFormula(
aRangeList, bSubTotal, aAddr );
SetFuncString( aFormula );
break;
}
}
}
}
else // nur in Eingabezeile einfuegen
{
ScRangeList aRangeList;
const sal_Bool bDataFound = pViewSh->GetAutoSumArea( aRangeList );
const sal_Bool bSubTotal( UseSubTotal( &aRangeList ) );
ScAddress aAddr = pViewSh->GetViewData()->GetCurPos();
const String aFormula = pViewSh->GetAutoSumFormula( aRangeList, bSubTotal, aAddr );
SetFuncString( aFormula );
if ( bDataFound && pScMod->IsEditMode() )
{
ScInputHandler* pHdl = pScMod->GetInputHdl( pViewSh );
if ( pHdl )
{
pHdl->InitRangeFinder( aFormula );
//! SetSelection am InputHandler ???
//! bSelIsRef setzen ???
const xub_StrLen nOpen = aFormula.Search('(');
const xub_StrLen nLen = aFormula.Len();
if ( nOpen != STRING_NOTFOUND && nLen > nOpen )
{
sal_uInt8 nAdd(1);
if (bSubTotal)
nAdd = 3;
ESelection aSel(0,nOpen+nAdd,0,nLen-1);
EditView* pTableView = pHdl->GetTableView();
if (pTableView)
pTableView->SetSelection(aSel);
EditView* pTopView = pHdl->GetTopView();
if (pTopView)
pTopView->SetSelection(aSel);
}
}
}
}
}
}
break;
case SID_INPUT_EQUAL:
{
aTextWindow.StartEditEngine();
if ( pScMod->IsEditMode() ) // nicht, wenn z.B. geschuetzt
{
aTextWindow.StartEditEngine();
aTextWindow.SetTextString(rtl::OUString('='));
EditView* pView = aTextWindow.GetEditView();
if (pView)
{
pView->SetSelection( ESelection(0,1, 0,1) );
pScMod->InputChanged(pView);
SetOkCancelMode();
pView->SetEditEngineUpdateMode(sal_True);
}
}
break;
}
}
}
void ScInputWindow::Paint( const Rectangle& rRect )
{
ToolBox::Paint( rRect );
// draw a line at the bottom to distinguish that from the grid
// (we have space for that thanks to ADDITIONAL_BORDER)
const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
SetLineColor( rStyleSettings.GetShadowColor() );
Size aSize = GetSizePixel();
DrawLine( Point( 0, aSize.Height() - 1 ), Point( aSize.Width() - 1, aSize.Height() - 1 ) );
}
void ScInputWindow::Resize()
{
ToolBox::Resize();
if ( mbIsMultiLine )
{
aTextWindow.Resize();
Size aSize = GetSizePixel();
aSize.Height() = CalcWindowSizePixel().Height() + ADDITIONAL_BORDER;
ScInputBarGroup* pGroupBar = dynamic_cast< ScInputBarGroup* > ( pRuntimeWindow.get() );
if ( pGroupBar )
{
// To ensure smooth display and prevent the items in the toolbar being
// repositioned ( vertically ) we lock the vertical positioning of the toolbox
// items when we are displaying > 1 line.
// So, we need to adjust the height of the toolbox accordingly. If we don't
// then the largest item ( e.g. the GroupBar window ) will actually be
// positioned such that the toolbar will cut off the bottom of that item
if ( pGroupBar->GetNumLines() > 1 )
aSize.Height() += pGroupBar->GetVertOffset() + ADDITIONAL_SPACE;
}
SetSizePixel(aSize);
Invalidate();
}
else
{
long nWidth = GetSizePixel().Width();
long nLeft = aTextWindow.GetPosPixel().X();
Size aSize = aTextWindow.GetSizePixel();
aSize.Width() = Max( ((long)(nWidth - nLeft - 5)), (long)0 );
aTextWindow.SetSizePixel( aSize );
aTextWindow.Invalidate();
}
}
void ScInputWindow::SetFuncString( const String& rString, sal_Bool bDoEdit )
{
//! new method at ScModule to query if function autopilot is open
SfxViewFrame* pViewFrm = SfxViewFrame::Current();
EnableButtons( pViewFrm && !pViewFrm->GetChildWindow( SID_OPENDLG_FUNCTION ) );
aTextWindow.StartEditEngine();
ScModule* pScMod = SC_MOD();
if ( pScMod->IsEditMode() )
{
if ( bDoEdit )
aTextWindow.GrabFocus();
aTextWindow.SetTextString( rString );
EditView* pView = aTextWindow.GetEditView();
if (pView)
{
xub_StrLen nLen = rString.Len();
if ( nLen > 0 )
{
nLen--;
pView->SetSelection( ESelection( 0, nLen, 0, nLen ) );
}
pScMod->InputChanged(pView);
if ( bDoEdit )
SetOkCancelMode(); // nicht, wenn gleich hinterher Enter/Cancel
pView->SetEditEngineUpdateMode(sal_True);
}
}
}
void ScInputWindow::SetPosString( const String& rStr )
{
aWndPos.SetPos( rStr );
}
void ScInputWindow::SetTextString( const String& rString )
{
if (rString.Len() <= 32767)
aTextWindow.SetTextString(rString);
else
{
String aNew = rString;
aNew.Erase(32767);
aTextWindow.SetTextString(aNew);
}
}
void ScInputWindow::SetOkCancelMode()
{
//! new method at ScModule to query if function autopilot is open
SfxViewFrame* pViewFrm = SfxViewFrame::Current();
EnableButtons( pViewFrm && !pViewFrm->GetChildWindow( SID_OPENDLG_FUNCTION ) );
ScModule* pScMod = SC_MOD();
SfxImageManager* pImgMgr = SfxImageManager::GetImageManager( pScMod );
if (!bIsOkCancelMode)
{
RemoveItem( 3 ); // SID_INPUT_SUM und SID_INPUT_EQUAL entfernen
RemoveItem( 3 );
InsertItem( SID_INPUT_CANCEL, IMAGE( SID_INPUT_CANCEL ), 0, 3 );
InsertItem( SID_INPUT_OK, IMAGE( SID_INPUT_OK ), 0, 4 );
SetItemText ( SID_INPUT_CANCEL, aTextCancel );
SetHelpId ( SID_INPUT_CANCEL, HID_INSWIN_CANCEL );
SetItemText ( SID_INPUT_OK, aTextOk );
SetHelpId ( SID_INPUT_OK, HID_INSWIN_OK );
bIsOkCancelMode = sal_True;
}
}
void ScInputWindow::SetSumAssignMode()
{
//! new method at ScModule to query if function autopilot is open
SfxViewFrame* pViewFrm = SfxViewFrame::Current();
EnableButtons( pViewFrm && !pViewFrm->GetChildWindow( SID_OPENDLG_FUNCTION ) );
ScModule* pScMod = SC_MOD();
SfxImageManager* pImgMgr = SfxImageManager::GetImageManager( pScMod );
if (bIsOkCancelMode)
{
// SID_INPUT_CANCEL, und SID_INPUT_OK entfernen
RemoveItem( 3 );
RemoveItem( 3 );
InsertItem( SID_INPUT_SUM, IMAGE( SID_INPUT_SUM ), 0, 3 );
InsertItem( SID_INPUT_EQUAL, IMAGE( SID_INPUT_EQUAL ), 0, 4 );
SetItemText ( SID_INPUT_SUM, aTextSum );
SetHelpId ( SID_INPUT_SUM, HID_INSWIN_SUMME );
SetItemText ( SID_INPUT_EQUAL, aTextEqual );
SetHelpId ( SID_INPUT_EQUAL, HID_INSWIN_FUNC );
bIsOkCancelMode = false;
SetFormulaMode(false); // kein editieren -> keine Formel
}
}
void ScInputWindow::SetFormulaMode( sal_Bool bSet )
{
aWndPos.SetFormulaMode(bSet);
aTextWindow.SetFormulaMode(bSet);
}
void ScInputWindow::SetText( const String& rString )
{
ToolBox::SetText(rString);
}
String ScInputWindow::GetText() const
{
return ToolBox::GetText();
}
sal_Bool ScInputWindow::IsInputActive()
{
return aTextWindow.IsInputActive();
}
EditView* ScInputWindow::GetEditView()
{
return aTextWindow.GetEditView();
}
void ScInputWindow::MakeDialogEditView()
{
aTextWindow.MakeDialogEditView();
}
void ScInputWindow::StopEditEngine( sal_Bool bAll )
{
aTextWindow.StopEditEngine( bAll );
}
void ScInputWindow::TextGrabFocus()
{
aTextWindow.TextGrabFocus();
}
void ScInputWindow::TextInvalidate()
{
aTextWindow.Invalidate();
}
void ScInputWindow::SwitchToTextWin()
{
// used for shift-ctrl-F2
aTextWindow.StartEditEngine();
if ( SC_MOD()->IsEditMode() )
{
aTextWindow.TextGrabFocus();
EditView* pView = aTextWindow.GetEditView();
if (pView)
{
sal_uInt16 nPara = pView->GetEditEngine()->GetParagraphCount() ? ( pView->GetEditEngine()->GetParagraphCount() - 1 ) : 0;
xub_StrLen nLen = pView->GetEditEngine()->GetTextLen( nPara );
ESelection aSel( nPara, nLen, nPara, nLen );
pView->SetSelection( aSel ); // set cursor to end of text
}
}
}
void ScInputWindow::PosGrabFocus()
{
aWndPos.GrabFocus();
}
void ScInputWindow::EnableButtons( sal_Bool bEnable )
{
// when enabling buttons, always also enable the input window itself
if ( bEnable && !IsEnabled() )
Enable();
EnableItem( SID_INPUT_FUNCTION, bEnable );
EnableItem( bIsOkCancelMode ? SID_INPUT_CANCEL : SID_INPUT_SUM, bEnable );
EnableItem( bIsOkCancelMode ? SID_INPUT_OK : SID_INPUT_EQUAL, bEnable );
// Invalidate();
}
void ScInputWindow::StateChanged( StateChangedType nType )
{
ToolBox::StateChanged( nType );
if ( nType == STATE_CHANGE_INITSHOW ) Resize();
}
void ScInputWindow::DataChanged( const DataChangedEvent& rDCEvt )
{
if ( rDCEvt.GetType() == DATACHANGED_SETTINGS && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
{
// update item images
ScModule* pScMod = SC_MOD();
SfxImageManager* pImgMgr = SfxImageManager::GetImageManager( pScMod );
// IMAGE macro uses pScMod, pImgMg
SetItemImage( SID_INPUT_FUNCTION, IMAGE( SID_INPUT_FUNCTION ) );
if ( bIsOkCancelMode )
{
SetItemImage( SID_INPUT_CANCEL, IMAGE( SID_INPUT_CANCEL ) );
SetItemImage( SID_INPUT_OK, IMAGE( SID_INPUT_OK ) );
}
else
{
SetItemImage( SID_INPUT_SUM, IMAGE( SID_INPUT_SUM ) );
SetItemImage( SID_INPUT_EQUAL, IMAGE( SID_INPUT_EQUAL ) );
}
}
ToolBox::DataChanged( rDCEvt );
}
bool ScInputWindow::IsPointerAtResizePos()
{
if ( GetOutputSizePixel().Height() - GetPointerPosPixel().Y() <= 4 )
return true;
else
return false;
}
void ScInputWindow::MouseMove( const MouseEvent& rMEvt )
{
if ( mbIsMultiLine )
{
Point aPosPixel = GetPointerPosPixel();
ScInputBarGroup* pGroupBar = dynamic_cast< ScInputBarGroup* > ( pRuntimeWindow.get() );
if ( bInResize || IsPointerAtResizePos() )
SetPointer( Pointer( POINTER_WINDOW_SSIZE ) );
else
SetPointer( Pointer( POINTER_ARROW ) );
if ( bInResize )
{
// detect direction
long nResizeThreshold = ( (long)TBX_WINDOW_HEIGHT * 0.7 );
bool bResetPointerPos = false;
// Detect attempt to expand toolbar too much
if ( aPosPixel.Y() >= mnMaxY )
{
bResetPointerPos = true;
aPosPixel.Y() = mnMaxY;
} // or expanding down
else if ( GetOutputSizePixel().Height() - aPosPixel.Y() < -nResizeThreshold )
{
pGroupBar->IncrementVerticalSize();
bResetPointerPos = true;
} // or shrinking up
else if ( ( GetOutputSizePixel().Height() - aPosPixel.Y() ) > nResizeThreshold )
{
bResetPointerPos = true;
pGroupBar->DecrementVerticalSize();
}
if ( bResetPointerPos )
{
aPosPixel.Y() = GetOutputSizePixel().Height();
SetPointerPosPixel( aPosPixel );
}
}
}
ToolBox::MouseMove( rMEvt );
}
void ScInputWindow::MouseButtonDown( const MouseEvent& rMEvt )
{
if ( mbIsMultiLine )
{
if ( rMEvt.IsLeft() )
{
if ( IsPointerAtResizePos() )
{
// Don't leave the mouse pointer leave *this* window
CaptureMouse();
bInResize = true;
// find the height of the gridwin, we don't wan't to be
// able to expand the toolbar too far so we need to
// caculate an upper limit
// I'd prefer to leave at least a single column header and a
// row but I don't know how to get that value in pixels.
// Use TBX_WINDOW_HEIGHT for the moment
ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
mnMaxY = GetOutputSizePixel().Height() + ( pViewSh->GetGridHeight(SC_SPLIT_TOP) + pViewSh->GetGridHeight(SC_SPLIT_BOTTOM) ) - TBX_WINDOW_HEIGHT;
}
}
}
ToolBox::MouseButtonDown( rMEvt );
}
void ScInputWindow::MouseButtonUp( const MouseEvent& rMEvt )
{
if ( mbIsMultiLine )
{
ReleaseMouse();
if ( rMEvt.IsLeft() )
{
bInResize = false;
mnMaxY = 0;
}
}
ToolBox::MouseButtonUp( rMEvt );
}
//========================================================================
// ScInputBarGroup
//========================================================================
ScInputBarGroup::ScInputBarGroup(Window* pParent, ScTabViewShell* pViewSh)
: ScTextWndBase ( pParent, WinBits(WB_HIDE | WB_TABSTOP ) ),
aMultiTextWnd ( this, pViewSh ),
aButton ( this, WB_TABSTOP | WB_RECTSTYLE | WB_SMALLSTYLE ),
aScrollBar ( this, WB_TABSTOP | WB_VERT | WB_DRAG ),
nVertOffset ( 0 )
{
aMultiTextWnd.Show();
aMultiTextWnd.SetQuickHelpText( ScResId( SCSTR_QHELP_INPUTWND ) );
aMultiTextWnd.SetHelpId( HID_INSWIN_INPUT );
Size aSize( GetSettings().GetStyleSettings().GetScrollBarSize(), aMultiTextWnd.GetPixelHeightForLines(1) );
aButton.SetClickHdl( LINK( this, ScInputBarGroup, ClickHdl ) );
aButton.SetSizePixel( aSize );
aButton.Enable();
aButton.SetSymbol( SYMBOL_SPIN_DOWN );
aButton.SetQuickHelpText( ScResId( SCSTR_QHELP_EXPAND_FORMULA ) );
aButton.Show();
aScrollBar.SetSizePixel( aSize );
aScrollBar.SetScrollHdl( LINK( this, ScInputBarGroup, Impl_ScrollHdl ) );
}
ScInputBarGroup::~ScInputBarGroup()
{
}
void
ScInputBarGroup::InsertAccessibleTextData( ScAccessibleEditLineTextData& rTextData )
{
aMultiTextWnd.InsertAccessibleTextData( rTextData );
}
void
ScInputBarGroup::RemoveAccessibleTextData( ScAccessibleEditLineTextData& rTextData )
{
aMultiTextWnd.RemoveAccessibleTextData( rTextData );
}
const String&
ScInputBarGroup::GetTextString() const
{
return aMultiTextWnd.GetTextString();
}
void ScInputBarGroup::SetTextString( const String& rString )
{
aMultiTextWnd.SetTextString(rString);
}
void ScInputBarGroup::Resize()
{
Window *w=GetParent();
ScInputWindow *pParent;
pParent=dynamic_cast<ScInputWindow*>(w);
if(pParent==NULL)
{
OSL_FAIL("The parent window pointer pParent is null");
return;
}
long nWidth = pParent->GetSizePixel().Width();
long nLeft = GetPosPixel().X();
Size aSize = GetSizePixel();
aSize.Width() = Max( ((long)(nWidth - nLeft - LEFT_OFFSET)), (long)0 );
aScrollBar.SetPosPixel(Point( aSize.Width() - aButton.GetSizePixel().Width(), aButton.GetSizePixel().Height() ) );
Size aTmpSize( aSize );
aTmpSize.Width() = aTmpSize.Width() - aButton.GetSizePixel().Width() - BUTTON_OFFSET;
aMultiTextWnd.SetSizePixel(aTmpSize);
aMultiTextWnd.Resize();
aSize.Height() = aMultiTextWnd.GetSizePixel().Height();
SetSizePixel(aSize);
if( aMultiTextWnd.GetNumLines() > 1 )
{
aButton.SetSymbol( SYMBOL_SPIN_UP );
aButton.SetQuickHelpText( ScResId( SCSTR_QHELP_COLLAPSE_FORMULA ) );
Size scrollSize = aButton.GetSizePixel();
scrollSize.Height() = aMultiTextWnd.GetSizePixel().Height() - aButton.GetSizePixel().Height();
aScrollBar.SetSizePixel( scrollSize );
Size aOutSz = aMultiTextWnd.GetOutputSize();
aScrollBar.SetVisibleSize( aOutSz.Height() );
aScrollBar.SetPageSize( aOutSz.Height() );
aScrollBar.SetLineSize( aMultiTextWnd.GetTextHeight() );
aScrollBar.SetRange( Range( 0, aMultiTextWnd.GetEditEngTxtHeight() ) );
aScrollBar.Resize();
aScrollBar.Show();
}
else
{
aButton.SetSymbol( SYMBOL_SPIN_DOWN );
aButton.SetQuickHelpText( ScResId( SCSTR_QHELP_EXPAND_FORMULA ) );
aScrollBar.Hide();
}
aButton.SetPosPixel(Point(aSize.Width() - aButton.GetSizePixel().Width(), 0));
Invalidate();
}
void ScInputBarGroup::StopEditEngine( sal_Bool bAll )
{
aMultiTextWnd.StopEditEngine( bAll );
}
void ScInputBarGroup::StartEditEngine()
{
aMultiTextWnd.StartEditEngine();
}
void ScInputBarGroup::MakeDialogEditView()
{
aMultiTextWnd.MakeDialogEditView();
}
EditView* ScInputBarGroup::GetEditView()
{
return aMultiTextWnd.GetEditView();
}
sal_Bool ScInputBarGroup::IsInputActive()
{
return aMultiTextWnd.IsInputActive();
}
void ScInputBarGroup::SetFormulaMode(sal_Bool bSet)
{
aMultiTextWnd.SetFormulaMode(bSet);
}
void ScInputBarGroup::IncrementVerticalSize()
{
aMultiTextWnd.SetNumLines( aMultiTextWnd.GetNumLines() + 1 );
TriggerToolboxLayout();
}
void ScInputBarGroup::DecrementVerticalSize()
{
if ( aMultiTextWnd.GetNumLines() > 1 )
{
aMultiTextWnd.SetNumLines( aMultiTextWnd.GetNumLines() - 1 );
TriggerToolboxLayout();
}
}
IMPL_LINK_NOARG(ScInputBarGroup, ClickHdl)
{
Window *w=GetParent();
ScInputWindow *pParent;
pParent=dynamic_cast<ScInputWindow*>(w);
if(pParent==NULL)
{
OSL_FAIL("The parent window pointer pParent is null");
return 1;
}
if( aMultiTextWnd.GetNumLines() > 1 )
{
aMultiTextWnd.SetNumLines( 1 );
}
else
{
aMultiTextWnd.SetNumLines( aMultiTextWnd.GetLastNumExpandedLines() );
}
TriggerToolboxLayout();
// Restore focus to input line(s) if necessary
if ( SC_MOD()->GetInputHdl()->IsTopMode() )
aMultiTextWnd.GrabFocus();
return 0;
}
void ScInputBarGroup::TriggerToolboxLayout()
{
Window *w=GetParent();
ScInputWindow *pParent;
pParent=dynamic_cast<ScInputWindow*>(w);
SfxViewFrame* pViewFrm = SfxViewFrame::Current();
// Capture the vertical position of this window in the toolbar, when we increase
// the size of the toolbar to accomadate expanded line input we need to take this
// into account
if ( !nVertOffset )
nVertOffset = pParent->GetItemPosRect( pParent->GetItemCount() - 1 ).Top();
if ( pViewFrm )
{
Reference< com::sun::star::beans::XPropertySet > xPropSet( pViewFrm->GetFrame().GetFrameInterface(), UNO_QUERY );
Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
if ( xPropSet.is() )
{
com::sun::star::uno::Any aValue = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )));
aValue >>= xLayoutManager;
}
if ( xLayoutManager.is() )
{
if ( aMultiTextWnd.GetNumLines() > 1)
pParent->SetToolbarLayoutMode( TBX_LAYOUT_LOCKVERT );
else
pParent->SetToolbarLayoutMode( TBX_LAYOUT_NORMAL );
xLayoutManager->lock();
DataChangedEvent aFakeUpdate( DATACHANGED_SETTINGS, NULL, SETTINGS_STYLE );
// this basically will trigger the reposititioning of the
// items in the toolbar from ImplFormat ( which is controlled by
// mnWinHeight ) which in turn is updated in ImplCalcItem which is
// controlled by mbCalc. Additionally the ImplFormat above is
// controlled via mbFormat. It seems the easiest way to get these
// booleans set is to send in the fake event below.
pParent->DataChanged( aFakeUpdate);
// highest item in toolbar will have been calculated via the
// event above. Call resize on InputBar to pick up the height
// change
pParent->Resize();
// unlock relayouts the toolbars in the 4 quadrants
xLayoutManager->unlock();
}
}
}
IMPL_LINK_NOARG(ScInputBarGroup, Impl_ScrollHdl)
{
aMultiTextWnd.DoScroll();
return 0;
}
void ScInputBarGroup::TextGrabFocus()
{
aMultiTextWnd.TextGrabFocus();
}
//========================================================================
// ScMultiTextWnd
//========================================================================
ScMultiTextWnd::ScMultiTextWnd( ScInputBarGroup* pParen, ScTabViewShell* pViewSh )
:
ScTextWnd( pParen, pViewSh ),
mrGroupBar(* pParen ),
mnLines( 1 ),
mnLastExpandedLines( INPUTWIN_MULTILINES ),
mbInvalidate( false )
{
Size aBorder;
aBorder = CalcWindowSize( aBorder);
mnBorderHeight = aBorder.Height();
}
ScMultiTextWnd::~ScMultiTextWnd()
{
}
void ScMultiTextWnd::Paint( const Rectangle& rRec )
{
EditView* pView = GetEditView();
if ( pView )
{
if ( mbInvalidate )
{
pView->Invalidate();
mbInvalidate = false;
}
pEditView->Paint( rRec );
}
}
EditView* ScMultiTextWnd::GetEditView()
{
if ( !pEditView )
InitEditEngine();
return pEditView;
}
long ScMultiTextWnd::GetPixelHeightForLines( long nLines )
{
// add padding ( for the borders of the window )
return ( nLines * LogicToPixel( Size( 0, GetTextHeight() ) ).Height() ) + mnBorderHeight;
}
void ScMultiTextWnd::SetNumLines( long nLines )
{
mnLines = nLines;
if ( nLines > 1 )
{
mnLastExpandedLines = nLines;
Resize();
}
}
void ScMultiTextWnd::Resize()
{
// Only Height is recalculated here, Width is applied from
// parent/container window
Size aTextBoxSize = GetSizePixel();
aTextBoxSize.Height() = GetPixelHeightForLines( mnLines );
SetSizePixel( aTextBoxSize );
if(pEditView)
{
Size aOutputSize = GetOutputSizePixel();
Rectangle aOutputArea = PixelToLogic( Rectangle( Point(), aOutputSize ));
pEditView->SetOutputArea( aOutputArea );
// Don't leave an empty area at the bottom if we can move the text down.
long nMaxVisAreaTop = pEditEngine->GetTextHeight() - aOutputArea.GetHeight();
if (pEditView->GetVisArea().Top() > nMaxVisAreaTop)
{
pEditView->Scroll(0, pEditView->GetVisArea().Top() - nMaxVisAreaTop);
}
pEditEngine->SetPaperSize( PixelToLogic( Size( aOutputSize.Width(), 10000 ) ) );
}
SetScrollBarRange();
}
IMPL_LINK(ScMultiTextWnd, ModifyHdl, EENotify*, pNotify)
{
ScTextWnd::NotifyHdl( pNotify );
return 0;
}
IMPL_LINK(ScMultiTextWnd, NotifyHdl, EENotify*, pNotify)
{
// need to process EE_NOTIFY_TEXTVIEWSCROLLED here
// sometimes we don't seem to get EE_NOTIFY_TEXTVIEWSCROLLED e.g. when
// we insert text at the begining of the text so the cursor never moves
// down to generate a scroll event
if ( pNotify && ( pNotify->eNotificationType == EE_NOTIFY_TEXTVIEWSCROLLED
|| pNotify->eNotificationType == EE_NOTIFY_TEXTHEIGHTCHANGED ) )
SetScrollBarRange();
return 0;
}
long ScMultiTextWnd::GetEditEngTxtHeight()
{
return pEditView ? pEditView->GetEditEngine()->GetTextHeight() : 0;
}
void ScMultiTextWnd::SetScrollBarRange()
{
if ( pEditView )
{
ScrollBar& rVBar = mrGroupBar.GetScrollBar();
rVBar.SetRange( Range( 0, GetEditEngTxtHeight() ) );
long currentDocPos = pEditView->GetVisArea().TopLeft().Y();
rVBar.SetThumbPos( currentDocPos );
}
}
void
ScMultiTextWnd::DoScroll()
{
if ( pEditView )
{
ScrollBar& rVBar = mrGroupBar.GetScrollBar();
long currentDocPos = pEditView->GetVisArea().TopLeft().Y();
long nDiff = currentDocPos - rVBar.GetThumbPos();
pEditView->Scroll( 0, nDiff );
currentDocPos = pEditView->GetVisArea().TopLeft().Y();
rVBar.SetThumbPos( currentDocPos );
}
}
void ScMultiTextWnd::StartEditEngine()
{
// Bei "eigener Modalitaet" (Doc-modale Dialoge) nicht aktivieren
SfxObjectShell* pObjSh = SfxObjectShell::Current();
if ( pObjSh && pObjSh->IsInModalMode() )
return;
if ( !pEditView || !pEditEngine )
{
InitEditEngine();
}
SC_MOD()->SetInputMode( SC_INPUT_TOP );
SfxViewFrame* pViewFrm = SfxViewFrame::Current();
if (pViewFrm)
pViewFrm->GetBindings().Invalidate( SID_ATTR_INSERT );
}
void lcl_ExtendEditFontAttribs( SfxItemSet& rSet )
{
const SfxPoolItem& rFontItem = rSet.Get( EE_CHAR_FONTINFO );
rSet.Put( rFontItem, EE_CHAR_FONTINFO_CJK );
rSet.Put( rFontItem, EE_CHAR_FONTINFO_CTL );
const SfxPoolItem& rHeightItem = rSet.Get( EE_CHAR_FONTHEIGHT );
rSet.Put( rHeightItem, EE_CHAR_FONTHEIGHT_CJK );
rSet.Put( rHeightItem, EE_CHAR_FONTHEIGHT_CTL );
const SfxPoolItem& rWeightItem = rSet.Get( EE_CHAR_WEIGHT );
rSet.Put( rWeightItem, EE_CHAR_WEIGHT_CJK );
rSet.Put( rWeightItem, EE_CHAR_WEIGHT_CTL );
const SfxPoolItem& rItalicItem = rSet.Get( EE_CHAR_ITALIC );
rSet.Put( rItalicItem, EE_CHAR_ITALIC_CJK );
rSet.Put( rItalicItem, EE_CHAR_ITALIC_CTL );
const SfxPoolItem& rLangItem = rSet.Get( EE_CHAR_LANGUAGE );
rSet.Put( rLangItem, EE_CHAR_LANGUAGE_CJK );
rSet.Put( rLangItem, EE_CHAR_LANGUAGE_CTL );
}
void lcl_ModifyRTLDefaults( SfxItemSet& rSet )
{
rSet.Put( SvxAdjustItem( SVX_ADJUST_RIGHT, EE_PARA_JUST ) );
// always using rtl writing direction would break formulas
//rSet.Put( SvxFrameDirectionItem( FRMDIR_HORI_RIGHT_TOP, EE_PARA_WRITINGDIR ) );
// PaperSize width is limited to USHRT_MAX in RTL mode (because of EditEngine's
// sal_uInt16 values in EditLine), so the text may be wrapped and line spacing must be
// increased to not see the beginning of the next line.
SvxLineSpacingItem aItem( SVX_LINESPACE_TWO_LINES, EE_PARA_SBL );
aItem.SetPropLineSpace( 200 );
rSet.Put( aItem );
}
void lcl_ModifyRTLVisArea( EditView* pEditView )
{
Rectangle aVisArea = pEditView->GetVisArea();
Size aPaper = pEditView->GetEditEngine()->GetPaperSize();
long nDiff = aPaper.Width() - aVisArea.Right();
aVisArea.Left() += nDiff;
aVisArea.Right() += nDiff;
pEditView->SetVisArea(aVisArea);
}
void ScMultiTextWnd::InitEditEngine()
{
ScFieldEditEngine* pNew;
ScTabViewShell* pViewSh = GetViewShell();
ScDocShell* pDocSh = NULL;
if ( pViewSh )
{
pDocSh = pViewSh->GetViewData()->GetDocShell();
ScDocument* pDoc = pViewSh->GetViewData()->GetDocument();
pNew = new ScFieldEditEngine(pDoc, pDoc->GetEnginePool(), pDoc->GetEditPool());
}
else
pNew = new ScFieldEditEngine(NULL, EditEngine::CreatePool(), NULL, true);
pNew->SetExecuteURL( false );
pEditEngine = pNew;
Size barSize=GetSizePixel();
pEditEngine->SetUpdateMode( false );
pEditEngine->SetPaperSize( PixelToLogic(Size(barSize.Width(),10000)) );
pEditEngine->SetWordDelimiters(
ScEditUtil::ModifyDelimiters( pEditEngine->GetWordDelimiters() ) );
UpdateAutoCorrFlag();
{
SfxItemSet* pSet = new SfxItemSet( pEditEngine->GetEmptyItemSet() );
pEditEngine->SetFontInfoInItemSet( *pSet, aTextFont );
lcl_ExtendEditFontAttribs( *pSet );
// turn off script spacing to match DrawText output
pSet->Put( SvxScriptSpaceItem( false, EE_PARA_ASIANCJKSPACING ) );
if ( bIsRTL )
lcl_ModifyRTLDefaults( *pSet );
pEditEngine->SetDefaults( pSet );
}
// Wenn in der Zelle URL-Felder enthalten sind, muessen die auch in
// die Eingabezeile uebernommen werden, weil sonst die Positionen nicht stimmen.
sal_Bool bFilled = false;
ScInputHandler* pHdl = SC_MOD()->GetInputHdl();
if ( pHdl ) //! Testen, ob's der richtige InputHdl ist?
bFilled = pHdl->GetTextAndFields( *pEditEngine );
pEditEngine->SetUpdateMode( sal_True );
// aString ist die Wahrheit...
if ( bFilled && pEditEngine->GetText() == aString )
Invalidate(); // Repaint fuer (hinterlegte) Felder
else
pEditEngine->SetText(aString); // dann wenigstens den richtigen Text
pEditView = new EditView( pEditEngine, this );
pEditView->SetInsertMode(bIsInsertMode);
// Text aus Clipboard wird als ASCII einzeilig uebernommen
sal_uLong n = pEditView->GetControlWord();
pEditView->SetControlWord( n | EV_CNTRL_SINGLELINEPASTE );
pEditEngine->InsertView( pEditView, EE_APPEND );
Resize();
if ( bIsRTL )
lcl_ModifyRTLVisArea( pEditView );
pEditEngine->SetModifyHdl(LINK(this, ScMultiTextWnd, ModifyHdl));
pEditEngine->SetNotifyHdl(LINK(this, ScMultiTextWnd, NotifyHdl));
if (!maAccTextDatas.empty())
maAccTextDatas.back()->StartEdit();
// as long as EditEngine and DrawText sometimes differ for CTL text,
// repaint now to have the EditEngine's version visible
if (pDocSh)
{
ScDocument* pDoc = pDocSh->GetDocument(); // any document
sal_uInt8 nScript = pDoc->GetStringScriptType( aString );
if ( nScript & SCRIPTTYPE_COMPLEX )
Invalidate();
}
}
void ScMultiTextWnd::StopEditEngine( sal_Bool bAll )
{
if ( pEditEngine )
pEditEngine->SetNotifyHdl(Link());
ScTextWnd::StopEditEngine( bAll );
}
void ScMultiTextWnd::SetTextString( const String& rNewString )
{
// Ideally it would be best to create on demand the EditEngine/EditView here, but... for
// the initialisation scenario where a cell is first clicked on we end up with the text in the
// inputbar window scrolled to the bottom if we do that here ( because the tableview and topview
// are synced I guess ).
// should fix that I suppose :-/ need to look a bit further into that
mbInvalidate = true; // ensure next Paint ( that uses editengine ) call will call Invalidate first
ScTextWnd::SetTextString( rNewString );
SetScrollBarRange();
DoScroll();
}
//========================================================================
// ScTextWnd
//========================================================================
ScTextWnd::ScTextWnd( Window* pParent, ScTabViewShell* pViewSh )
: ScTextWndBase ( pParent, WinBits(WB_HIDE | WB_BORDER) ),
DragSourceHelper( this ),
pEditEngine ( NULL ),
pEditView ( NULL ),
bIsInsertMode( sal_True ),
bFormulaMode ( false ),
bInputMode ( false ),
mpViewShell(pViewSh)
{
EnableRTL( false ); // EditEngine can't be used with VCL EnableRTL
bIsRTL = GetSettings().GetLayoutRTL();
// always use application font, so a font with cjk chars can be installed
Font aAppFont = GetFont();
aTextFont = aAppFont;
aTextFont.SetSize( PixelToLogic( aAppFont.GetSize(), MAP_TWIP ) ); // AppFont ist in Pixeln
const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
Color aBgColor= rStyleSettings.GetWindowColor();
Color aTxtColor= rStyleSettings.GetWindowTextColor();
aTextFont.SetTransparent ( sal_True );
aTextFont.SetFillColor ( aBgColor );
//aTextFont.SetColor ( COL_FIELDTEXT );
aTextFont.SetColor (aTxtColor);
aTextFont.SetWeight ( WEIGHT_NORMAL );
Size aSize(1,TBX_WINDOW_HEIGHT);
Size aMinEditSize( Edit::GetMinimumEditSize() );
if( aMinEditSize.Height() > aSize.Height() )
aSize.Height() = aMinEditSize.Height();
SetSizePixel ( aSize );
SetBackground ( aBgColor );
SetLineColor ( COL_BLACK );
SetMapMode ( MAP_TWIP );
SetPointer ( POINTER_TEXT );
SetFont( aTextFont );
}
ScTextWnd::~ScTextWnd()
{
while (!maAccTextDatas.empty()) {
maAccTextDatas.back()->Dispose();
}
delete pEditView;
delete pEditEngine;
}
void ScTextWnd::Paint( const Rectangle& rRec )
{
if (pEditView)
pEditView->Paint( rRec );
else
{
SetFont( aTextFont );
long nDiff = GetOutputSizePixel().Height()
- LogicToPixel( Size( 0, GetTextHeight() ) ).Height();
// if (nDiff<2) nDiff=2; // mind. 1 Pixel
long nStartPos = 0;
if ( bIsRTL )
{
// right-align
nStartPos += GetOutputSizePixel().Width() -
LogicToPixel( Size( GetTextWidth( aString ), 0 ) ).Width();
// LayoutMode isn't changed as long as ModifyRTLDefaults doesn't include SvxFrameDirectionItem
}
DrawText( PixelToLogic( Point( nStartPos, nDiff/2 ) ), aString );
}
}
void ScTextWnd::Resize()
{
if (pEditView)
{
Size aSize = GetOutputSizePixel();
long nDiff = aSize.Height()
- LogicToPixel( Size( 0, GetTextHeight() ) ).Height();
pEditView->SetOutputArea(
PixelToLogic( Rectangle( Point( 0, (nDiff > 0) ? nDiff/2 : 1 ),
aSize ) ) );
}
}
void ScTextWnd::MouseMove( const MouseEvent& rMEvt )
{
if (pEditView)
pEditView->MouseMove( rMEvt );
}
void ScTextWnd::MouseButtonDown( const MouseEvent& rMEvt )
{
if (!HasFocus())
{
StartEditEngine();
if ( SC_MOD()->IsEditMode() )
GrabFocus();
}
if (pEditView)
{
pEditView->SetEditEngineUpdateMode( sal_True );
pEditView->MouseButtonDown( rMEvt );
}
}
void ScTextWnd::MouseButtonUp( const MouseEvent& rMEvt )
{
if (pEditView)
if (pEditView->MouseButtonUp( rMEvt ))
{
if ( rMEvt.IsMiddle() &&
GetSettings().GetMouseSettings().GetMiddleButtonAction() == MOUSE_MIDDLE_PASTESELECTION )
{
// EditView may have pasted from selection
SC_MOD()->InputChanged( pEditView );
}
else
SC_MOD()->InputSelection( pEditView );
}
}
void ScTextWnd::Command( const CommandEvent& rCEvt )
{
bInputMode = sal_True;
sal_uInt16 nCommand = rCEvt.GetCommand();
if ( pEditView /* && ( nCommand == COMMAND_STARTDRAG || nCommand == COMMAND_VOICE ) */ )
{
ScModule* pScMod = SC_MOD();
ScTabViewShell* pStartViewSh = ScTabViewShell::GetActiveViewShell();
// don't modify the font defaults here - the right defaults are
// already set in StartEditEngine when the EditEngine is created
// verhindern, dass die EditView beim View-Umschalten wegkommt
pScMod->SetInEditCommand( true );
pEditView->Command( rCEvt );
pScMod->SetInEditCommand( false );
// COMMAND_STARTDRAG heiss noch lange nicht, dass der Inhalt geaendert wurde
// darum in dem Fall kein InputChanged
//! erkennen, ob mit Move gedraggt wurde, oder Drag&Move irgendwie verbieten
if ( nCommand == COMMAND_STARTDRAG )
{
// ist auf eine andere View gedraggt worden?
ScTabViewShell* pEndViewSh = ScTabViewShell::GetActiveViewShell();
if ( pEndViewSh != pStartViewSh && pStartViewSh != NULL )
{
ScViewData* pViewData = pStartViewSh->GetViewData();
ScInputHandler* pHdl = pScMod->GetInputHdl( pStartViewSh );
if ( pHdl && pViewData->HasEditView( pViewData->GetActivePart() ) )
{
pHdl->CancelHandler();
pViewData->GetView()->ShowCursor(); // fehlt bei KillEditView, weil nicht aktiv
}
}
}
else if ( nCommand == COMMAND_CURSORPOS )
{
// don't call InputChanged for COMMAND_CURSORPOS
}
else if ( nCommand == COMMAND_INPUTLANGUAGECHANGE )
{
// #i55929# Font and font size state depends on input language if nothing is selected,
// so the slots have to be invalidated when the input language is changed.
SfxViewFrame* pViewFrm = SfxViewFrame::Current();
if (pViewFrm)
{
SfxBindings& rBindings = pViewFrm->GetBindings();
rBindings.Invalidate( SID_ATTR_CHAR_FONT );
rBindings.Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
}
}
else if ( nCommand == COMMAND_WHEEL )
{
//don't call InputChanged for COMMAND_WHEEL
}
else
SC_MOD()->InputChanged( pEditView );
}
else
Window::Command(rCEvt); // sonst soll sich die Basisklasse drum kuemmern...
bInputMode = false;
}
void ScTextWnd::StartDrag( sal_Int8 /* nAction */, const Point& rPosPixel )
{
if ( pEditView )
{
CommandEvent aDragEvent( rPosPixel, COMMAND_STARTDRAG, sal_True );
pEditView->Command( aDragEvent );
// handling of d&d to different view (CancelHandler) can't be done here,
// because the call returns before d&d is complete.
}
}
void ScTextWnd::KeyInput(const KeyEvent& rKEvt)
{
bInputMode = sal_True;
if (!SC_MOD()->InputKeyEvent( rKEvt ))
{
sal_Bool bUsed = false;
ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
if ( pViewSh )
bUsed = pViewSh->SfxKeyInput(rKEvt); // nur Acceleratoren, keine Eingabe
if (!bUsed)
Window::KeyInput( rKEvt );
}
bInputMode = false;
}
void ScTextWnd::GetFocus()
{
ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
if ( pViewSh )
pViewSh->SetFormShellAtTop( false ); // focus in input line -> FormShell no longer on top
}
void ScTextWnd::LoseFocus()
{
}
String ScTextWnd::GetText() const
{
// ueberladen, um per Testtool an den Text heranzukommen
if ( pEditEngine )
return pEditEngine->GetText();
else
return GetTextString();
}
void ScTextWnd::SetFormulaMode( sal_Bool bSet )
{
if ( bSet != bFormulaMode )
{
bFormulaMode = bSet;
UpdateAutoCorrFlag();
}
}
void ScTextWnd::UpdateAutoCorrFlag()
{
if ( pEditEngine )
{
sal_uLong nControl = pEditEngine->GetControlWord();
sal_uLong nOld = nControl;
if ( bFormulaMode )
nControl &= ~EE_CNTRL_AUTOCORRECT; // keine Autokorrektur in Formeln
else
nControl |= EE_CNTRL_AUTOCORRECT; // sonst schon
if ( nControl != nOld )
pEditEngine->SetControlWord( nControl );
}
}
ScTabViewShell* ScTextWnd::GetViewShell()
{
return mpViewShell;
}
void ScTextWnd::StartEditEngine()
{
// Bei "eigener Modalitaet" (Doc-modale Dialoge) nicht aktivieren
SfxObjectShell* pObjSh = SfxObjectShell::Current();
if ( pObjSh && pObjSh->IsInModalMode() )
return;
if ( !pEditView || !pEditEngine )
{
ScFieldEditEngine* pNew;
ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
if ( pViewSh )
{
ScDocument* pDoc = pViewSh->GetViewData()->GetDocument();
pNew = new ScFieldEditEngine(pDoc, pDoc->GetEnginePool(), pDoc->GetEditPool());
}
else
pNew = new ScFieldEditEngine(NULL, EditEngine::CreatePool(), NULL, true);
pNew->SetExecuteURL( false );
pEditEngine = pNew;
pEditEngine->SetUpdateMode( false );
pEditEngine->SetPaperSize( Size( bIsRTL ? USHRT_MAX : THESIZE, 300 ) );
pEditEngine->SetWordDelimiters(
ScEditUtil::ModifyDelimiters( pEditEngine->GetWordDelimiters() ) );
UpdateAutoCorrFlag();
{
SfxItemSet* pSet = new SfxItemSet( pEditEngine->GetEmptyItemSet() );
pEditEngine->SetFontInfoInItemSet( *pSet, aTextFont );
lcl_ExtendEditFontAttribs( *pSet );
// turn off script spacing to match DrawText output
pSet->Put( SvxScriptSpaceItem( false, EE_PARA_ASIANCJKSPACING ) );
if ( bIsRTL )
lcl_ModifyRTLDefaults( *pSet );
pEditEngine->SetDefaults( pSet );
}
// Wenn in der Zelle URL-Felder enthalten sind, muessen die auch in
// die Eingabezeile uebernommen werden, weil sonst die Positionen nicht stimmen.
sal_Bool bFilled = false;
ScInputHandler* pHdl = SC_MOD()->GetInputHdl();
if ( pHdl ) //! Testen, ob's der richtige InputHdl ist?
bFilled = pHdl->GetTextAndFields( *pEditEngine );
pEditEngine->SetUpdateMode( sal_True );
// aString ist die Wahrheit...
if ( bFilled && pEditEngine->GetText() == aString )
Invalidate(); // Repaint fuer (hinterlegte) Felder
else
pEditEngine->SetText(aString); // dann wenigstens den richtigen Text
pEditView = new EditView( pEditEngine, this );
pEditView->SetInsertMode(bIsInsertMode);
// Text aus Clipboard wird als ASCII einzeilig uebernommen
sal_uLong n = pEditView->GetControlWord();
pEditView->SetControlWord( n | EV_CNTRL_SINGLELINEPASTE );
pEditEngine->InsertView( pEditView, EE_APPEND );
Resize();
if ( bIsRTL )
lcl_ModifyRTLVisArea( pEditView );
pEditEngine->SetModifyHdl(LINK(this, ScTextWnd, NotifyHdl));
if (!maAccTextDatas.empty())
maAccTextDatas.back()->StartEdit();
// as long as EditEngine and DrawText sometimes differ for CTL text,
// repaint now to have the EditEngine's version visible
// SfxObjectShell* pObjSh = SfxObjectShell::Current();
if ( pObjSh && pObjSh->ISA(ScDocShell) )
{
ScDocument* pDoc = ((ScDocShell*)pObjSh)->GetDocument(); // any document
sal_uInt8 nScript = pDoc->GetStringScriptType( aString );
if ( nScript & SCRIPTTYPE_COMPLEX )
Invalidate();
}
}
SC_MOD()->SetInputMode( SC_INPUT_TOP );
SfxViewFrame* pViewFrm = SfxViewFrame::Current();
if (pViewFrm)
pViewFrm->GetBindings().Invalidate( SID_ATTR_INSERT );
}
IMPL_LINK_NOARG(ScTextWnd, NotifyHdl)
{
if (pEditView && !bInputMode)
{
ScInputHandler* pHdl = SC_MOD()->GetInputHdl();
// Use the InputHandler's InOwnChange flag to prevent calling InputChanged
// while an InputHandler method is modifying the EditEngine content
if ( pHdl && !pHdl->IsInOwnChange() )
pHdl->InputChanged( pEditView, sal_True ); // #i20282# InputChanged must know if called from modify handler
}
return 0;
}
void ScTextWnd::StopEditEngine( sal_Bool bAll )
{
if (pEditView)
{
if (!maAccTextDatas.empty())
maAccTextDatas.back()->EndEdit();
ScModule* pScMod = SC_MOD();
if (!bAll)
pScMod->InputSelection( pEditView );
aString = pEditEngine->GetText();
bIsInsertMode = pEditView->IsInsertMode();
sal_Bool bSelection = pEditView->HasSelection();
pEditEngine->SetModifyHdl(Link());
DELETEZ(pEditView);
DELETEZ(pEditEngine);
if ( pScMod->IsEditMode() && !bAll )
pScMod->SetInputMode(SC_INPUT_TABLE);
SfxViewFrame* pViewFrm = SfxViewFrame::Current();
if (pViewFrm)
pViewFrm->GetBindings().Invalidate( SID_ATTR_INSERT );
if (bSelection)
Invalidate(); // damit Selektion nicht stehenbleibt
}
}
void ScTextWnd::SetTextString( const String& rNewString )
{
if ( rNewString != aString )
{
bInputMode = sal_True;
// Position der Aenderung suchen, nur Rest painten
if (!pEditEngine)
{
sal_Bool bPaintAll;
if ( bIsRTL )
bPaintAll = sal_True;
else
{
// test if CTL script type is involved
sal_uInt8 nOldScript = 0;
sal_uInt8 nNewScript = 0;
SfxObjectShell* pObjSh = SfxObjectShell::Current();
if ( pObjSh && pObjSh->ISA(ScDocShell) )
{
// any document can be used (used only for its break iterator)
ScDocument* pDoc = ((ScDocShell*)pObjSh)->GetDocument();
nOldScript = pDoc->GetStringScriptType( aString );
nNewScript = pDoc->GetStringScriptType( rNewString );
}
bPaintAll = ( nOldScript & SCRIPTTYPE_COMPLEX ) || ( nNewScript & SCRIPTTYPE_COMPLEX );
}
if ( bPaintAll )
{
// if CTL is involved, the whole text has to be redrawn
Invalidate();
}
else
{
long nTextSize = 0;
xub_StrLen nDifPos;
if (rNewString.Len() > aString.Len())
nDifPos = rNewString.Match(aString);
else
nDifPos = aString.Match(rNewString);
long nSize1 = GetTextWidth(aString);
long nSize2 = GetTextWidth(rNewString);
if ( nSize1>0 && nSize2>0 )
nTextSize = Max( nSize1, nSize2 );
else
nTextSize = GetOutputSize().Width(); // Ueberlauf
if (nDifPos == STRING_MATCH)
nDifPos = 0;
// -1 wegen Rundung und "A"
Point aLogicStart = PixelToLogic(Point(0,0));
long nStartPos = aLogicStart.X();
long nInvPos = nStartPos;
if (nDifPos)
nInvPos += GetTextWidth(aString,0,nDifPos);
sal_uInt16 nFlags = 0;
if ( nDifPos == aString.Len() ) // only new characters appended
nFlags = INVALIDATE_NOERASE; // then background is already clear
Invalidate( Rectangle( nInvPos, 0,
nStartPos+nTextSize, GetOutputSize().Height()-1 ),
nFlags );
}
}
else
{
pEditEngine->SetText(rNewString);
}
aString = rNewString;
if (!maAccTextDatas.empty())
maAccTextDatas.back()->TextChanged();
bInputMode = false;
}
}
const String& ScTextWnd::GetTextString() const
{
return aString;
}
sal_Bool ScTextWnd::IsInputActive()
{
return HasFocus();
}
EditView* ScTextWnd::GetEditView()
{
return pEditView;
}
void ScTextWnd::MakeDialogEditView()
{
if ( pEditView ) return;
ScFieldEditEngine* pNew;
ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
if ( pViewSh )
{
ScDocument* pDoc = pViewSh->GetViewData()->GetDocument();
pNew = new ScFieldEditEngine(pDoc, pDoc->GetEnginePool(), pDoc->GetEditPool());
}
else
pNew = new ScFieldEditEngine(NULL, EditEngine::CreatePool(), NULL, true);
pNew->SetExecuteURL( false );
pEditEngine = pNew;
pEditEngine->SetUpdateMode( false );
pEditEngine->SetWordDelimiters( pEditEngine->GetWordDelimiters() += '=' );
pEditEngine->SetPaperSize( Size( bIsRTL ? USHRT_MAX : THESIZE, 300 ) );
SfxItemSet* pSet = new SfxItemSet( pEditEngine->GetEmptyItemSet() );
pEditEngine->SetFontInfoInItemSet( *pSet, aTextFont );
lcl_ExtendEditFontAttribs( *pSet );
if ( bIsRTL )
lcl_ModifyRTLDefaults( *pSet );
pEditEngine->SetDefaults( pSet );
pEditEngine->SetUpdateMode( sal_True );
pEditView = new EditView( pEditEngine, this );
pEditEngine->InsertView( pEditView, EE_APPEND );
Resize();
if ( bIsRTL )
lcl_ModifyRTLVisArea( pEditView );
if (!maAccTextDatas.empty())
maAccTextDatas.back()->StartEdit();
}
void ScTextWnd::ImplInitSettings()
{
bIsRTL = GetSettings().GetLayoutRTL();
const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
Color aBgColor= rStyleSettings.GetWindowColor();
Color aTxtColor= rStyleSettings.GetWindowTextColor();
aTextFont.SetFillColor ( aBgColor );
aTextFont.SetColor (aTxtColor);
SetBackground ( aBgColor );
Invalidate();
}
::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > ScTextWnd::CreateAccessible()
{
return new ScAccessibleEditObject(GetAccessibleParentWindow()->GetAccessible(), NULL, this,
rtl::OUString(String(ScResId(STR_ACC_EDITLINE_NAME))),
rtl::OUString(String(ScResId(STR_ACC_EDITLINE_DESCR))), ScAccessibleEditObject::EditLine);
}
void ScTextWnd::InsertAccessibleTextData( ScAccessibleEditLineTextData& rTextData )
{
OSL_ENSURE( ::std::find( maAccTextDatas.begin(), maAccTextDatas.end(), &rTextData ) == maAccTextDatas.end(),
"ScTextWnd::InsertAccessibleTextData - passed object already registered" );
maAccTextDatas.push_back( &rTextData );
}
void ScTextWnd::RemoveAccessibleTextData( ScAccessibleEditLineTextData& rTextData )
{
AccTextDataVector::iterator aEnd = maAccTextDatas.end();
AccTextDataVector::iterator aIt = ::std::find( maAccTextDatas.begin(), aEnd, &rTextData );
OSL_ENSURE( aIt != aEnd, "ScTextWnd::RemoveAccessibleTextData - passed object not registered" );
if( aIt != aEnd )
maAccTextDatas.erase( aIt );
}
// -----------------------------------------------------------------------
void ScTextWnd::DataChanged( const DataChangedEvent& rDCEvt )
{
if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
(rDCEvt.GetFlags() & SETTINGS_STYLE) )
{
ImplInitSettings();
Invalidate();
}
else
Window::DataChanged( rDCEvt );
}
void ScTextWnd::TextGrabFocus()
{
GrabFocus();
}
//========================================================================
// Positionsfenster
//========================================================================
ScPosWnd::ScPosWnd( Window* pParent ) :
ComboBox ( pParent, WinBits(WB_HIDE | WB_DROPDOWN) ),
pAccel ( NULL ),
nTipVisible ( 0 ),
bFormulaMode( false )
{
Size aSize( GetTextWidth( rtl::OUString("GW99999:GW99999") ),
GetTextHeight() );
aSize.Width() += 25; // ??
aSize.Height() = CalcWindowSizePixel(11); // Funktionen: 10 MRU + "andere..."
SetSizePixel( aSize );
FillRangeNames();
StartListening( *SFX_APP() ); // fuer Navigator-Bereichsnamen-Updates
}
ScPosWnd::~ScPosWnd()
{
EndListening( *SFX_APP() );
HideTip();
delete pAccel;
}
void ScPosWnd::SetFormulaMode( sal_Bool bSet )
{
if ( bSet != bFormulaMode )
{
bFormulaMode = bSet;
if ( bSet )
FillFunctions();
else
FillRangeNames();
HideTip();
}
}
void ScPosWnd::SetPos( const String& rPosStr )
{
if ( aPosStr != rPosStr )
{
aPosStr = rPosStr;
SetText(aPosStr);
}
}
namespace {
rtl::OUString createLocalRangeName(const rtl::OUString& rName, const rtl::OUString& rTableName)
{
rtl::OUStringBuffer aString (rName);
aString.append(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" (")));
aString.append(rTableName);
aString.append(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(")")));
return aString.makeStringAndClear();
}
}
void ScPosWnd::FillRangeNames()
{
Clear();
SfxObjectShell* pObjSh = SfxObjectShell::Current();
if ( pObjSh && pObjSh->ISA(ScDocShell) )
{
ScDocument* pDoc = ((ScDocShell*)pObjSh)->GetDocument();
InsertEntry(ScGlobal::GetRscString( STR_MANAGE_NAMES ));
SetSeparatorPos(0);
ScRange aDummy;
std::set<rtl::OUString> aSet;
ScRangeName* pRangeNames = pDoc->GetRangeName();
if (!pRangeNames->empty())
{
ScRangeName::const_iterator itrBeg = pRangeNames->begin(), itrEnd = pRangeNames->end();
for (ScRangeName::const_iterator itr = itrBeg; itr != itrEnd; ++itr)
{
if (itr->second->IsValidReference(aDummy))
aSet.insert(itr->second->GetName());
}
}
for (SCTAB i = 0; i < pDoc->GetTableCount(); ++i)
{
ScRangeName* pLocalRangeName = pDoc->GetRangeName(i);
if (pLocalRangeName && !pLocalRangeName->empty())
{
rtl::OUString aTableName;
pDoc->GetName(i, aTableName);
for (ScRangeName::const_iterator itr = pLocalRangeName->begin(); itr != pLocalRangeName->end(); ++itr)
{
if (itr->second->IsValidReference(aDummy))
aSet.insert(createLocalRangeName(itr->second->GetName(), aTableName));
}
}
}
if (!aSet.empty())
{
for (std::set<rtl::OUString>::iterator itr = aSet.begin();
itr != aSet.end(); ++itr)
{
InsertEntry(*itr);
}
}
}
SetText(aPosStr);
}
void ScPosWnd::FillFunctions()
{
Clear();
String aFirstName;
const ScAppOptions& rOpt = SC_MOD()->GetAppOptions();
sal_uInt16 nMRUCount = rOpt.GetLRUFuncListCount();
const sal_uInt16* pMRUList = rOpt.GetLRUFuncList();
if (pMRUList)
{
const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList();
sal_uLong nListCount = pFuncList->GetCount();
for (sal_uInt16 i=0; i<nMRUCount; i++)
{
sal_uInt16 nId = pMRUList[i];
for (sal_uLong j=0; j<nListCount; j++)
{
const ScFuncDesc* pDesc = pFuncList->GetFunction( j );
if ( pDesc->nFIndex == nId && pDesc->pFuncName )
{
InsertEntry( *pDesc->pFuncName );
if (!aFirstName.Len())
aFirstName = *pDesc->pFuncName;
break; // nicht weitersuchen
}
}
}
}
//! Eintrag "Andere..." fuer Funktions-Autopilot wieder aufnehmen,
//! wenn der Funktions-Autopilot mit dem bisher eingegebenen Text arbeiten kann!
// InsertEntry( ScGlobal::GetRscString(STR_FUNCTIONLIST_MORE) );
SetText(aFirstName);
}
void ScPosWnd::Notify( SfxBroadcaster&, const SfxHint& rHint )
{
if ( !bFormulaMode )
{
// muss die Liste der Bereichsnamen updgedated werden?
if ( rHint.ISA(SfxSimpleHint) )
{
sal_uLong nHintId = ((SfxSimpleHint&)rHint).GetId();
if ( nHintId == SC_HINT_AREAS_CHANGED || nHintId == SC_HINT_NAVIGATOR_UPDATEALL)
FillRangeNames();
}
else if ( rHint.ISA(SfxEventHint) )
{
sal_uLong nEventId = ((SfxEventHint&)rHint).GetEventId();
if ( nEventId == SFX_EVENT_ACTIVATEDOC )
FillRangeNames();
}
}
}
void ScPosWnd::HideTip()
{
if ( nTipVisible )
{
Help::HideTip( nTipVisible );
nTipVisible = 0;
}
}
ScNameInputType lcl_GetInputType( const String& rText )
{
ScNameInputType eRet = SC_NAME_INPUT_BAD_NAME; // the more general error
ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
if ( pViewSh )
{
ScViewData* pViewData = pViewSh->GetViewData();
ScDocument* pDoc = pViewData->GetDocument();
SCTAB nTab = pViewData->GetTabNo();
formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
// test in same order as in SID_CURRENTCELL execute
ScRange aRange;
ScAddress aAddress;
ScRangeUtil aRangeUtil;
SCTAB nNameTab;
sal_Int32 nNumeric;
if (rText == ScGlobal::GetRscString(STR_MANAGE_NAMES))
eRet = SC_MANAGE_NAMES;
else if ( aRange.Parse( rText, pDoc, eConv ) & SCA_VALID )
eRet = SC_NAME_INPUT_RANGE;
else if ( aAddress.Parse( rText, pDoc, eConv ) & SCA_VALID )
eRet = SC_NAME_INPUT_CELL;
else if ( aRangeUtil.MakeRangeFromName( rText, pDoc, nTab, aRange, RUTL_NAMES, eConv ) )
eRet = SC_NAME_INPUT_NAMEDRANGE;
else if ( aRangeUtil.MakeRangeFromName( rText, pDoc, nTab, aRange, RUTL_DBASE, eConv ) )
eRet = SC_NAME_INPUT_DATABASE;
else if ( comphelper::string::isdigitAsciiString( rText ) &&
( nNumeric = rText.ToInt32() ) > 0 && nNumeric <= MAXROW+1 )
eRet = SC_NAME_INPUT_ROW;
else if ( pDoc->GetTable( rText, nNameTab ) )
eRet = SC_NAME_INPUT_SHEET;
else if ( ScRangeData::IsNameValid( rText, pDoc ) ) // nothing found, create new range?
{
if ( pViewData->GetSimpleArea( aRange ) == SC_MARK_SIMPLE )
eRet = SC_NAME_INPUT_DEFINE;
else
eRet = SC_NAME_INPUT_BAD_SELECTION;
}
else
eRet = SC_NAME_INPUT_BAD_NAME;
}
return eRet;
}
void ScPosWnd::Modify()
{
ComboBox::Modify();
HideTip();
if ( !IsTravelSelect() && !bFormulaMode )
{
// determine the action that would be taken for the current input
ScNameInputType eType = lcl_GetInputType( GetText() ); // uses current view
sal_uInt16 nStrId = 0;
switch ( eType )
{
case SC_NAME_INPUT_CELL:
nStrId = STR_NAME_INPUT_CELL;
break;
case SC_NAME_INPUT_RANGE:
case SC_NAME_INPUT_NAMEDRANGE:
nStrId = STR_NAME_INPUT_RANGE; // named range or range reference
break;
case SC_NAME_INPUT_DATABASE:
nStrId = STR_NAME_INPUT_DBRANGE;
break;
case SC_NAME_INPUT_ROW:
nStrId = STR_NAME_INPUT_ROW;
break;
case SC_NAME_INPUT_SHEET:
nStrId = STR_NAME_INPUT_SHEET;
break;
case SC_NAME_INPUT_DEFINE:
nStrId = STR_NAME_INPUT_DEFINE;
break;
default:
// other cases (error): no tip help
break;
}
if ( nStrId )
{
// show the help tip at the text cursor position
Window* pWin = GetSubEdit();
if (!pWin)
pWin = this;
Point aPos;
Cursor* pCur = pWin->GetCursor();
if (pCur)
aPos = pWin->LogicToPixel( pCur->GetPos() );
aPos = pWin->OutputToScreenPixel( aPos );
Rectangle aRect( aPos, aPos );
String aText = ScGlobal::GetRscString( nStrId );
sal_uInt16 nAlign = QUICKHELP_LEFT|QUICKHELP_BOTTOM;
nTipVisible = Help::ShowTip(pWin, aRect, aText, nAlign);
}
}
}
void ScPosWnd::Select()
{
ComboBox::Select(); // in VCL gibt GetText() erst danach den ausgewaehlten Eintrag
HideTip();
if (!IsTravelSelect())
DoEnter();
}
void ScPosWnd::DoEnter()
{
String aText = GetText();
if ( aText.Len() )
{
if ( bFormulaMode )
{
ScModule* pScMod = SC_MOD();
if ( aText == ScGlobal::GetRscString(STR_FUNCTIONLIST_MORE) )
{
// Funktions-Autopilot
//! mit dem bisher eingegebenen Text weiterarbeiten !!!
//! new method at ScModule to query if function autopilot is open
SfxViewFrame* pViewFrm = SfxViewFrame::Current();
if ( pViewFrm && !pViewFrm->GetChildWindow( SID_OPENDLG_FUNCTION ) )
pViewFrm->GetDispatcher()->Execute( SID_OPENDLG_FUNCTION,
SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD );
}
else
{
ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
ScInputHandler* pHdl = pScMod->GetInputHdl( pViewSh );
if (pHdl)
pHdl->InsertFunction( aText );
}
}
else
{
// depending on the input, select something or create a new named range
ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
if ( pViewSh )
{
ScViewData* pViewData = pViewSh->GetViewData();
ScDocShell* pDocShell = pViewData->GetDocShell();
ScDocument* pDoc = pDocShell->GetDocument();
ScNameInputType eType = lcl_GetInputType( aText );
if ( eType == SC_NAME_INPUT_BAD_NAME || eType == SC_NAME_INPUT_BAD_SELECTION )
{
sal_uInt16 nId = ( eType == SC_NAME_INPUT_BAD_NAME ) ? STR_NAME_ERROR_NAME : STR_NAME_ERROR_SELECTION;
pViewSh->ErrorMessage( nId );
}
else if ( eType == SC_NAME_INPUT_DEFINE )
{
ScRangeName* pNames = pDoc->GetRangeName();
ScRange aSelection;
if ( pNames && !pNames->findByUpperName(ScGlobal::pCharClass->uppercase(aText)) &&
(pViewData->GetSimpleArea( aSelection ) == SC_MARK_SIMPLE) )
{
ScRangeName aNewRanges( *pNames );
ScAddress aCursor( pViewData->GetCurX(), pViewData->GetCurY(), pViewData->GetTabNo() );
String aContent;
aSelection.Format( aContent, SCR_ABS_3D, pDoc, pDoc->GetAddressConvention() );
ScRangeData* pNew = new ScRangeData( pDoc, aText, aContent, aCursor );
if ( aNewRanges.insert(pNew) )
{
pDocShell->GetDocFunc().ModifyRangeNames( aNewRanges );
pViewSh->UpdateInputHandler(true);
}
}
}
else if (eType == SC_MANAGE_NAMES)
{
sal_uInt16 nId = ScNameDlgWrapper::GetChildWindowId();
SfxViewFrame* pViewFrm = pViewSh->GetViewFrame();
SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
SC_MOD()->SetRefDialog( nId, pWnd ? false : sal_True );
}
else
{
// for all selection types, excecute the SID_CURRENTCELL slot.
if (eType == SC_NAME_INPUT_CELL || eType == SC_NAME_INPUT_RANGE)
{
// Note that SID_CURRENTCELL always expects address to
// be in Calc A1 format. Convert the text.
ScRange aRange(0,0,pViewData->GetTabNo());
aRange.ParseAny(aText, pDoc, pDoc->GetAddressConvention());
aRange.Format(aText, SCR_ABS_3D, pDoc, ::formula::FormulaGrammar::CONV_OOO);
}
SfxStringItem aPosItem( SID_CURRENTCELL, aText );
SfxBoolItem aUnmarkItem( FN_PARAM_1, sal_True ); // remove existing selection
pViewSh->GetViewData()->GetDispatcher().Execute( SID_CURRENTCELL,
SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD,
&aPosItem, &aUnmarkItem, 0L );
}
}
}
}
else
SetText( aPosStr );
ReleaseFocus_Impl();
}
long ScPosWnd::Notify( NotifyEvent& rNEvt )
{
long nHandled = 0;
if ( rNEvt.GetType() == EVENT_KEYINPUT )
{
const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
switch ( pKEvt->GetKeyCode().GetCode() )
{
case KEY_RETURN:
DoEnter();
nHandled = 1;
break;
case KEY_ESCAPE:
if (nTipVisible)
{
// escape when the tip help is shown: only hide the tip
HideTip();
}
else
{
if (!bFormulaMode)
SetText( aPosStr );
ReleaseFocus_Impl();
}
nHandled = 1;
break;
}
}
if ( !nHandled )
nHandled = ComboBox::Notify( rNEvt );
if ( rNEvt.GetType() == EVENT_LOSEFOCUS )
HideTip();
return nHandled;
}
void ScPosWnd::ReleaseFocus_Impl()
{
HideTip();
SfxViewShell* pCurSh = SfxViewShell::Current();
ScInputHandler* pHdl = SC_MOD()->GetInputHdl( PTR_CAST( ScTabViewShell, pCurSh ) );
if ( pHdl && pHdl->IsTopMode() )
{
// Focus wieder in die Eingabezeile?
ScInputWindow* pInputWin = pHdl->GetInputWindow();
if (pInputWin)
{
pInputWin->TextGrabFocus();
return;
}
}
// Focus auf die aktive View
if ( pCurSh )
{
Window* pShellWnd = pCurSh->GetWindow();
if ( pShellWnd )
pShellWnd->GrabFocus();
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|