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
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <string>
#include <comphelper/fileurl.hxx>
#include <rtl/ustrbuf.hxx>
#include <sal/log.hxx>
#include <tools/long.hxx>
#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <osl/file.h>
#include <vcl/event.hxx>
#include <vcl/inputctx.hxx>
#include <vcl/svapp.hxx>
#include <vcl/window.hxx>
#include <vcl/syswin.hxx>
#include <vcl/settings.hxx>
#include <osx/saldata.hxx>
#include <quartz/salgdi.h>
#include <osx/salframe.h>
#include <osx/salmenu.h>
#include <osx/salinst.h>
#include <osx/salframeview.h>
#include <osx/a11yfactory.h>
#include <osx/runinmain.hxx>
#include <quartz/utils.h>
#include <salwtype.hxx>
#include <premac.h>
#include <objc/objc-runtime.h>
// needed for theming
// FIXME: move theming code to salnativewidgets.cxx
#include <Carbon/Carbon.h>
#include <quartz/CGHelpers.hxx>
#include <postmac.h>
const int nMinBlinkCursorDelay = 500;
AquaSalFrame* AquaSalFrame::s_pCaptureFrame = nullptr;
AquaSalFrame::AquaSalFrame( SalFrame* pParent, SalFrameStyleFlags salFrameStyle ) :
mpNSWindow(nil),
mpNSView(nil),
mpDockMenuEntry(nil),
mpGraphics(nullptr),
mpParent(nullptr),
mnMinWidth(0),
mnMinHeight(0),
mnMaxWidth(0),
mnMaxHeight(0),
mbGraphics(false),
mbFullScreen( false ),
mbShown(false),
mbInitShow(true),
mbPositioned(false),
mbSized(false),
mbPresentation( false ),
mnStyle( salFrameStyle ),
mnStyleMask( 0 ),
mnLastEventTime( 0 ),
mnLastModifierFlags( 0 ),
mpMenu( nullptr ),
mnExtStyle( 0 ),
mePointerStyle( PointerStyle::Arrow ),
mrClippingPath( nullptr ),
mnICOptions( InputContextFlags::NONE ),
mnBlinkCursorDelay( nMinBlinkCursorDelay ),
mbForceFlush( false )
{
mpParent = dynamic_cast<AquaSalFrame*>(pParent);
initWindowAndView();
SalData* pSalData = GetSalData();
pSalData->mpInstance->insertFrame( this );
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
// tdf#150177 Limit minimum blink cursor rate
// This bug occurs when the values for NSTextInsertionPointBlinkPeriodOn or
// NSTextInsertionPointBlinkPeriodOff are set to zero or close to zero.
// LibreOffice becomes very sluggish opening documents when either is set
// at 100 milliseconds or less so set the blink rate to the maximum of
// nMinBlinkCursorDelay, NSTextInsertionPointBlinkPeriodOn, and
// NSTextInsertionPointBlinkPeriodOff.
mnBlinkCursorDelay = nMinBlinkCursorDelay;
if (userDefaults != nil)
{
id setting = [userDefaults objectForKey: @"NSTextInsertionPointBlinkPeriodOn"];
if (setting && [setting isKindOfClass:[NSNumber class]])
mnBlinkCursorDelay = std::max(mnBlinkCursorDelay, [setting intValue]);
setting = [userDefaults objectForKey: @"NSTextInsertionPointBlinkPeriodOff"];
if (setting && [setting isKindOfClass:[NSNumber class]])
mnBlinkCursorDelay = std::max(mnBlinkCursorDelay, [setting intValue]);
}
}
AquaSalFrame::~AquaSalFrame()
{
if (mbFullScreen)
doShowFullScreen(false, maGeometry.screen());
assert( GetSalData()->mpInstance->IsMainThread() );
// if the frame is destroyed and has the current menubar
// set the default menubar
if( mpMenu && mpMenu->mbMenuBar && AquaSalMenu::pCurrentMenuBar == mpMenu )
AquaSalMenu::setDefaultMenu();
// cleanup clipping stuff
doResetClipRegion();
[SalFrameView unsetMouseFrame: this];
SalData* pSalData = GetSalData();
pSalData->mpInstance->eraseFrame( this );
pSalData->maPresentationFrames.remove( this );
SAL_WARN_IF( this == s_pCaptureFrame, "vcl", "capture frame destroyed" );
if( this == s_pCaptureFrame )
s_pCaptureFrame = nullptr;
delete mpGraphics;
if( mpDockMenuEntry )
{
NSMenu* pDock = AquaSalInstance::GetDynamicDockMenu();
// life cycle comment: the menu has ownership of the item, so no release
[pDock removeItem: mpDockMenuEntry];
if ([pDock numberOfItems] != 0
&& [[pDock itemAtIndex: 0] isSeparatorItem])
{
[pDock removeItemAtIndex: 0];
}
}
if ( mpNSView ) {
if ([mpNSView isKindOfClass:[SalFrameView class]])
[static_cast<SalFrameView*>(mpNSView) revokeWrapper];
[mpNSView release];
}
if ( mpNSWindow )
[mpNSWindow release];
}
void AquaSalFrame::initWindowAndView()
{
OSX_SALDATA_RUNINMAIN( initWindowAndView() )
// initialize mirroring parameters
// FIXME: screens changing
NSScreen* pNSScreen = [mpNSWindow screen];
if( pNSScreen == nil )
pNSScreen = [NSScreen mainScreen];
maScreenRect = [pNSScreen frame];
// calculate some default geometry
NSRect aVisibleRect = [pNSScreen visibleFrame];
CocoaToVCL( aVisibleRect );
maGeometry.setX(static_cast<sal_Int32>(aVisibleRect.origin.x + aVisibleRect.size.width / 10));
maGeometry.setY(static_cast<sal_Int32>(aVisibleRect.origin.y + aVisibleRect.size.height / 10));
maGeometry.setWidth(static_cast<sal_uInt32>(aVisibleRect.size.width * 0.8));
maGeometry.setHeight(static_cast<sal_uInt32>(aVisibleRect.size.height * 0.8));
// calculate style mask
if( (mnStyle & SalFrameStyleFlags::FLOAT) ||
(mnStyle & SalFrameStyleFlags::OWNERDRAWDECORATION) )
mnStyleMask = NSWindowStyleMaskBorderless;
else if( mnStyle & SalFrameStyleFlags::DEFAULT )
{
mnStyleMask = NSWindowStyleMaskTitled |
NSWindowStyleMaskMiniaturizable |
NSWindowStyleMaskResizable |
NSWindowStyleMaskClosable;
// make default window "maximized"
maGeometry.setX(static_cast<sal_Int32>(aVisibleRect.origin.x));
maGeometry.setY(static_cast<sal_Int32>(aVisibleRect.origin.y));
maGeometry.setWidth(static_cast<sal_uInt32>(aVisibleRect.size.width));
maGeometry.setHeight(static_cast<sal_uInt32>(aVisibleRect.size.height));
mbPositioned = mbSized = true;
}
else
{
if( mnStyle & SalFrameStyleFlags::MOVEABLE )
{
mnStyleMask |= NSWindowStyleMaskTitled;
if( mpParent == nullptr )
mnStyleMask |= NSWindowStyleMaskMiniaturizable;
}
if( mnStyle & SalFrameStyleFlags::SIZEABLE )
mnStyleMask |= NSWindowStyleMaskResizable;
if( mnStyle & SalFrameStyleFlags::CLOSEABLE )
mnStyleMask |= NSWindowStyleMaskClosable;
// documentation says anything other than NSWindowStyleMaskBorderless (=0)
// should also include NSWindowStyleMaskTitled;
if( mnStyleMask != 0 )
mnStyleMask |= NSWindowStyleMaskTitled;
}
if (Application::IsBitmapRendering())
return;
// #i91990# support GUI-less (daemon) execution
@try
{
mpNSWindow = [[SalFrameWindow alloc] initWithSalFrame: this];
mpNSView = [[SalFrameView alloc] initWithSalFrame: this];
}
@catch ( id )
{
std::abort();
}
if( mnStyle & SalFrameStyleFlags::TOOLTIP )
[mpNSWindow setIgnoresMouseEvents: YES];
else
// Related: tdf#155092 mouse events are now handled by tracking areas
[mpNSWindow setAcceptsMouseMovedEvents: NO];
[mpNSWindow setHasShadow: YES];
[mpNSWindow setDelegate: static_cast<id<NSWindowDelegate> >(mpNSWindow)];
[mpNSWindow setRestorable:NO];
// tdf#155092 use tracking areas instead of tracking rectangles
// Apparently, the older, tracking rectangles selectors cause
// unexpected window resizing upon the first mouse down after the
// window has been manually resized so switch to the newer,
// tracking areas selectors. Also, the NSTrackingInVisibleRect
// option allows us to create one single tracking area that
// resizes itself automatically over the lifetime of the view.
// Note: for some unknown reason, both NSTrackingMouseMoved and
// NSTrackingAssumeInside are necessary options for this fix
// to work.
NSTrackingArea *pTrackingArea = [[NSTrackingArea alloc] initWithRect: [mpNSView bounds] options: ( NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingActiveAlways | NSTrackingAssumeInside | NSTrackingInVisibleRect ) owner: mpNSView userInfo: nil];
[mpNSView addTrackingArea: pTrackingArea];
[pTrackingArea release];
maSysData.mpNSView = mpNSView;
UpdateFrameGeometry();
[mpNSWindow setContentView: mpNSView];
}
void AquaSalFrame::CocoaToVCL( NSRect& io_rRect, bool bRelativeToScreen )
{
if( bRelativeToScreen )
io_rRect.origin.y = maScreenRect.size.height - (io_rRect.origin.y+io_rRect.size.height);
else
io_rRect.origin.y = maGeometry.height() - (io_rRect.origin.y+io_rRect.size.height);
}
void AquaSalFrame::VCLToCocoa( NSRect& io_rRect, bool bRelativeToScreen )
{
if( bRelativeToScreen )
io_rRect.origin.y = maScreenRect.size.height - (io_rRect.origin.y+io_rRect.size.height);
else
io_rRect.origin.y = maGeometry.height() - (io_rRect.origin.y+io_rRect.size.height);
}
void AquaSalFrame::CocoaToVCL( NSPoint& io_rPoint, bool bRelativeToScreen )
{
if( bRelativeToScreen )
io_rPoint.y = maScreenRect.size.height - io_rPoint.y;
else
io_rPoint.y = maGeometry.height() - io_rPoint.y;
}
void AquaSalFrame::VCLToCocoa( NSPoint& io_rPoint, bool bRelativeToScreen )
{
if( bRelativeToScreen )
io_rPoint.y = maScreenRect.size.height - io_rPoint.y;
else
io_rPoint.y = maGeometry.height() - io_rPoint.y;
}
void AquaSalFrame::screenParametersChanged()
{
OSX_SALDATA_RUNINMAIN( screenParametersChanged() )
sal::aqua::resetTotalScreenBounds();
sal::aqua::resetWindowScaling();
UpdateFrameGeometry();
if( mpGraphics )
mpGraphics->updateResolution();
if (!mbGeometryDidChange)
return;
CallCallback( SalEvent::DisplayChanged, nullptr );
}
SalGraphics* AquaSalFrame::AcquireGraphics()
{
if ( mbGraphics )
return nullptr;
if ( !mpGraphics )
{
mpGraphics = new AquaSalGraphics;
mpGraphics->SetWindowGraphics( this );
}
mbGraphics = true;
return mpGraphics;
}
void AquaSalFrame::ReleaseGraphics( SalGraphics *pGraphics )
{
SAL_WARN_IF( pGraphics != mpGraphics, "vcl", "graphics released on wrong frame" );
mbGraphics = false;
}
bool AquaSalFrame::PostEvent(std::unique_ptr<ImplSVEvent> pData)
{
GetSalData()->mpInstance->PostEvent( this, pData.release(), SalEvent::UserEvent );
return true;
}
void AquaSalFrame::SetTitle(const OUString& rTitle)
{
if ( !mpNSWindow )
return;
OSX_SALDATA_RUNINMAIN( SetTitle(rTitle) )
// #i113170# may not be the main thread if called from UNO API
SalData::ensureThreadAutoreleasePool();
NSString* pTitle = CreateNSString( rTitle );
[mpNSWindow setTitle: pTitle];
// create an entry in the dock menu
const SalFrameStyleFlags nAppWindowStyle = SalFrameStyleFlags::CLOSEABLE | SalFrameStyleFlags::MOVEABLE;
if( mpParent == nullptr &&
(mnStyle & nAppWindowStyle) == nAppWindowStyle )
{
if( mpDockMenuEntry == nullptr )
{
NSMenu* pDock = AquaSalInstance::GetDynamicDockMenu();
if ([pDock numberOfItems] != 0) {
NSMenuItem* pTopItem = [pDock itemAtIndex: 0];
if ( [pTopItem hasSubmenu] )
[pDock insertItem: [NSMenuItem separatorItem] atIndex: 0];
}
mpDockMenuEntry = [pDock insertItemWithTitle: pTitle
action: @selector(dockMenuItemTriggered:)
keyEquivalent: @""
atIndex: 0];
[mpDockMenuEntry setTarget: mpNSWindow];
// TODO: image (either the generic window image or an icon
// check mark (for "main" window ?)
}
else
[mpDockMenuEntry setTitle: pTitle];
}
if (pTitle)
[pTitle release];
}
void AquaSalFrame::SetIcon( sal_uInt16 )
{
}
void AquaSalFrame::SetRepresentedURL( const OUString& i_rDocURL )
{
OSX_SALDATA_RUNINMAIN( SetRepresentedURL( i_rDocURL ) )
if( comphelper::isFileUrl(i_rDocURL) )
{
OUString aSysPath;
osl_getSystemPathFromFileURL( i_rDocURL.pData, &aSysPath.pData );
NSString* pStr = CreateNSString( aSysPath );
if( pStr )
{
[pStr autorelease];
[mpNSWindow setRepresentedFilename: pStr];
}
}
}
void AquaSalFrame::initShow()
{
OSX_SALDATA_RUNINMAIN( initShow() )
mbInitShow = false;
if( ! mbPositioned && ! mbFullScreen )
{
AbsoluteScreenPixelRectangle aScreenRect;
GetWorkArea( aScreenRect );
if( mpParent ) // center relative to parent
{
// center on parent
tools::Long nNewX = mpParent->maGeometry.x() + (static_cast<tools::Long>(mpParent->maGeometry.width()) - static_cast<tools::Long>(maGeometry.width())) / 2;
if( nNewX < aScreenRect.Left() )
nNewX = aScreenRect.Left();
if (static_cast<tools::Long>(nNewX + maGeometry.width()) > aScreenRect.Right())
nNewX = aScreenRect.Right() - maGeometry.width() - 1;
tools::Long nNewY = mpParent->maGeometry.y() + (static_cast<tools::Long>(mpParent->maGeometry.height()) - static_cast<tools::Long>(maGeometry.height())) / 2;
if( nNewY < aScreenRect.Top() )
nNewY = aScreenRect.Top();
if( nNewY > aScreenRect.Bottom() )
nNewY = aScreenRect.Bottom() - maGeometry.height() - 1;
SetPosSize( nNewX - mpParent->maGeometry.x(),
nNewY - mpParent->maGeometry.y(),
0, 0, SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y );
}
else if( ! (mnStyle & SalFrameStyleFlags::SIZEABLE) )
{
// center on screen
tools::Long nNewX = (aScreenRect.GetWidth() - maGeometry.width()) / 2;
tools::Long nNewY = (aScreenRect.GetHeight() - maGeometry.height()) / 2;
SetPosSize( nNewX, nNewY, 0, 0, SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y );
}
}
// make sure the view is present in the wrapper list before any children receive focus
if (mpNSView && [mpNSView isKindOfClass:[SalFrameView class]])
[static_cast<SalFrameView*>(mpNSView) registerWrapper];
}
void AquaSalFrame::SendPaintEvent( const tools::Rectangle* pRect )
{
OSX_SALDATA_RUNINMAIN( SendPaintEvent( pRect ) )
SalPaintEvent aPaintEvt(0, 0, maGeometry.width(), maGeometry.height(), true);
if( pRect )
{
aPaintEvt.mnBoundX = pRect->Left();
aPaintEvt.mnBoundY = pRect->Top();
aPaintEvt.mnBoundWidth = pRect->GetWidth();
aPaintEvt.mnBoundHeight = pRect->GetHeight();
}
CallCallback(SalEvent::Paint, &aPaintEvt);
}
void AquaSalFrame::Show(bool bVisible, bool bNoActivate)
{
if ( !mpNSWindow )
return;
OSX_SALDATA_RUNINMAIN( Show(bVisible, bNoActivate) )
// tdf#152173 Don't display tooltip windows when application is inactive
// Starting with macOS 13 Ventura, inactive applications receive mouse
// move events so when LibreOffice is inactive, a mouse move event causes
// a tooltip to be displayed. Since the tooltip window is attached to its
// parent window (to ensure that the tooltip is above the parent window),
// displaying a tooltip pulls the parent window in front of the windows
// of all other inactive applications.
// Also, don't display tooltips when mousing over non-key windows even if
// the application is active as the tooltip window will pull the non-key
// window in front of the key window.
if (bVisible && (mnStyle & SalFrameStyleFlags::TOOLTIP))
{
if (![NSApp isActive])
return;
if (mpParent)
{
// tdf#157565 show tooltip if any parent window is the key window
bool bKeyWindowFound = false;
NSWindow *pParent = mpParent->mpNSWindow;
while (pParent)
{
if ([pParent isKeyWindow])
{
bKeyWindowFound = true;
break;
}
pParent = [pParent parentWindow];
}
if (!bKeyWindowFound)
return;
}
}
mbShown = bVisible;
if(bVisible)
{
if( mbInitShow )
initShow();
CallCallback(SalEvent::Resize, nullptr);
// trigger filling our backbuffer
SendPaintEvent();
if( bNoActivate || [mpNSWindow canBecomeKeyWindow] == NO )
[mpNSWindow orderFront: NSApp];
else
[mpNSWindow makeKeyAndOrderFront: NSApp];
if( mpParent )
{
/* #i92674# #i96433# we do not want an invisible parent to show up (which adding a visible
child implicitly does). However we also do not want a parentless toolbar.
HACK: try to decide when we should not insert a child to its parent
floaters and ownerdraw windows have not yet shown up in cases where
we don't want the parent to become visible
*/
if( mpParent->mbShown || (mnStyle & (SalFrameStyleFlags::OWNERDRAWDECORATION | SalFrameStyleFlags::FLOAT) ) )
{
[mpParent->mpNSWindow addChildWindow: mpNSWindow ordered: NSWindowAbove];
}
}
if( mbPresentation )
[mpNSWindow makeMainWindow];
}
else
{
// if the frame holding the current menubar gets hidden
// show the default menubar
if( mpMenu && mpMenu->mbMenuBar && AquaSalMenu::pCurrentMenuBar == mpMenu )
AquaSalMenu::setDefaultMenu();
// #i90440# #i94443# work around the focus going back to some other window
// if a child gets hidden for a parent window
if( mpParent && mpParent->mbShown && [mpNSWindow isKeyWindow] )
[mpParent->mpNSWindow makeKeyAndOrderFront: NSApp];
[SalFrameView unsetMouseFrame: this];
if( mpParent && [mpNSWindow parentWindow] == mpParent->mpNSWindow )
[mpParent->mpNSWindow removeChildWindow: mpNSWindow];
[mpNSWindow orderOut: NSApp];
}
}
void AquaSalFrame::SetMinClientSize( tools::Long nWidth, tools::Long nHeight )
{
OSX_SALDATA_RUNINMAIN( SetMinClientSize( nWidth, nHeight ) )
mnMinWidth = nWidth;
mnMinHeight = nHeight;
if( mpNSWindow )
{
// Always add the decoration as the dimension concerns only
// the content rectangle
nWidth += maGeometry.leftDecoration() + maGeometry.rightDecoration();
nHeight += maGeometry.topDecoration() + maGeometry.bottomDecoration();
NSSize aSize = { static_cast<CGFloat>(nWidth), static_cast<CGFloat>(nHeight) };
// Size of full window (content+structure) although we only
// have the client size in arguments
[mpNSWindow setMinSize: aSize];
}
}
void AquaSalFrame::SetMaxClientSize( tools::Long nWidth, tools::Long nHeight )
{
OSX_SALDATA_RUNINMAIN( SetMaxClientSize( nWidth, nHeight ) )
mnMaxWidth = nWidth;
mnMaxHeight = nHeight;
if( mpNSWindow )
{
// Always add the decoration as the dimension concerns only
// the content rectangle
nWidth += maGeometry.leftDecoration() + maGeometry.rightDecoration();
nHeight += maGeometry.topDecoration() + maGeometry.bottomDecoration();
// Carbon windows can't have a size greater than 32767x32767
if (nWidth>32767) nWidth=32767;
if (nHeight>32767) nHeight=32767;
NSSize aSize = { static_cast<CGFloat>(nWidth), static_cast<CGFloat>(nHeight) };
// Size of full window (content+structure) although we only
// have the client size in arguments
[mpNSWindow setMaxSize: aSize];
}
}
void AquaSalFrame::GetClientSize( tools::Long& rWidth, tools::Long& rHeight )
{
if (mbShown || mbInitShow || Application::IsBitmapRendering())
{
rWidth = maGeometry.width();
rHeight = maGeometry.height();
}
else
{
rWidth = 0;
rHeight = 0;
}
}
SalEvent AquaSalFrame::PreparePosSize(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, sal_uInt16 nFlags)
{
SalEvent nEvent = SalEvent::NONE;
assert(mpNSWindow || Application::IsBitmapRendering());
if (nFlags & (SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y))
{
mbPositioned = true;
nEvent = SalEvent::Move;
}
if (nFlags & (SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT))
{
mbSized = true;
nEvent = (nEvent == SalEvent::Move) ? SalEvent::MoveResize : SalEvent::Resize;
}
if (Application::IsBitmapRendering())
{
if (nFlags & SAL_FRAME_POSSIZE_X)
maGeometry.setX(nX);
if (nFlags & SAL_FRAME_POSSIZE_Y)
maGeometry.setY(nY);
if (nFlags & SAL_FRAME_POSSIZE_WIDTH)
{
maGeometry.setWidth(nWidth);
if (mnMaxWidth > 0 && maGeometry.width() > mnMaxWidth)
maGeometry.setWidth(mnMaxWidth);
if (mnMinWidth > 0 && maGeometry.width() < mnMinWidth)
maGeometry.setWidth(mnMinWidth);
}
if (nFlags & SAL_FRAME_POSSIZE_HEIGHT)
{
maGeometry.setHeight(nHeight);
if (mnMaxHeight > 0 && maGeometry.height() > mnMaxHeight)
maGeometry.setHeight(mnMaxHeight);
if (mnMinHeight > 0 && maGeometry.height() < mnMinHeight)
maGeometry.setHeight(mnMinHeight);
}
if (nEvent != SalEvent::NONE)
CallCallback(nEvent, nullptr);
}
return nEvent;
}
void AquaSalFrame::SetWindowState(const vcl::WindowData* pState)
{
if (!mpNSWindow && !Application::IsBitmapRendering())
return;
OSX_SALDATA_RUNINMAIN( SetWindowState( pState ) )
sal_uInt16 nFlags = 0;
nFlags |= ((pState->mask() & vcl::WindowDataMask::X) ? SAL_FRAME_POSSIZE_X : 0);
nFlags |= ((pState->mask() & vcl::WindowDataMask::Y) ? SAL_FRAME_POSSIZE_Y : 0);
nFlags |= ((pState->mask() & vcl::WindowDataMask::Width) ? SAL_FRAME_POSSIZE_WIDTH : 0);
nFlags |= ((pState->mask() & vcl::WindowDataMask::Height) ? SAL_FRAME_POSSIZE_HEIGHT : 0);
SalEvent nEvent = PreparePosSize(pState->x(), pState->y(), pState->width(), pState->height(), nFlags);
if (Application::IsBitmapRendering())
return;
// set normal state
NSRect aStateRect = [mpNSWindow frame];
aStateRect = [NSWindow contentRectForFrameRect: aStateRect styleMask: mnStyleMask];
CocoaToVCL(aStateRect);
if (pState->mask() & vcl::WindowDataMask::X)
aStateRect.origin.x = float(pState->x());
if (pState->mask() & vcl::WindowDataMask::Y)
aStateRect.origin.y = float(pState->y());
if (pState->mask() & vcl::WindowDataMask::Width)
aStateRect.size.width = float(pState->width());
if (pState->mask() & vcl::WindowDataMask::Height)
aStateRect.size.height = float(pState->height());
VCLToCocoa(aStateRect);
aStateRect = [NSWindow frameRectForContentRect: aStateRect styleMask: mnStyleMask];
[mpNSWindow setFrame: aStateRect display: NO];
if (pState->state() == vcl::WindowState::Minimized)
[mpNSWindow miniaturize: NSApp];
else if ([mpNSWindow isMiniaturized])
[mpNSWindow deminiaturize: NSApp];
/* ZOOMED is not really maximized (actually it toggles between a user set size and
the program specified one), but comes closest since the default behavior is
"maximized" if the user did not intervene
*/
if (pState->state() == vcl::WindowState::Maximized)
{
if (![mpNSWindow isZoomed])
[mpNSWindow zoom: NSApp];
}
else
{
if ([mpNSWindow isZoomed])
[mpNSWindow zoom: NSApp];
}
// get new geometry
UpdateFrameGeometry();
// send event that we were moved/sized
if( nEvent != SalEvent::NONE )
CallCallback( nEvent, nullptr );
if (mbShown)
{
// trigger filling our backbuffer
SendPaintEvent();
// tell the system the views need to be updated
[mpNSWindow display];
}
}
bool AquaSalFrame::GetWindowState(vcl::WindowData* pState)
{
if (!mpNSWindow)
{
if (Application::IsBitmapRendering())
{
pState->setMask(vcl::WindowDataMask::PosSizeState);
pState->setPosSize(maGeometry.posSize());
pState->setState(vcl::WindowState::Normal);
return true;
}
return false;
}
OSX_SALDATA_RUNINMAIN_UNION( GetWindowState( pState ), boolean )
pState->setMask(vcl::WindowDataMask::PosSizeState);
NSRect aStateRect = [mpNSWindow frame];
aStateRect = [NSWindow contentRectForFrameRect: aStateRect styleMask: mnStyleMask];
CocoaToVCL( aStateRect );
pState->setX(static_cast<sal_Int32>(aStateRect.origin.x));
pState->setY(static_cast<sal_Int32>(aStateRect.origin.y));
pState->setWidth(static_cast<sal_uInt32>(aStateRect.size.width));
pState->setHeight(static_cast<sal_uInt32>(aStateRect.size.height));
if( [mpNSWindow isMiniaturized] )
pState->setState(vcl::WindowState::Minimized);
else if( ! [mpNSWindow isZoomed] )
pState->setState(vcl::WindowState::Normal);
else
pState->setState(vcl::WindowState::Maximized);
return true;
}
void AquaSalFrame::SetScreenNumber(unsigned int nScreen)
{
if ( !mpNSWindow )
return;
OSX_SALDATA_RUNINMAIN( SetScreenNumber( nScreen ) )
NSArray* pScreens = [NSScreen screens];
NSScreen* pScreen = nil;
if( pScreens && nScreen < [pScreens count] )
{
// get new screen frame
pScreen = [pScreens objectAtIndex: nScreen];
NSRect aNewScreen = [pScreen frame];
// get current screen frame
pScreen = [mpNSWindow screen];
if( pScreen )
{
NSRect aCurScreen = [pScreen frame];
if( aCurScreen.origin.x != aNewScreen.origin.x ||
aCurScreen.origin.y != aNewScreen.origin.y )
{
NSRect aFrameRect = [mpNSWindow frame];
aFrameRect.origin.x += aNewScreen.origin.x - aCurScreen.origin.x;
aFrameRect.origin.y += aNewScreen.origin.y - aCurScreen.origin.y;
[mpNSWindow setFrame: aFrameRect display: NO];
UpdateFrameGeometry();
}
}
}
}
void AquaSalFrame::SetApplicationID( const OUString &/*rApplicationID*/ )
{
}
void AquaSalFrame::ShowFullScreen( bool bFullScreen, sal_Int32 nDisplay )
{
doShowFullScreen(bFullScreen, nDisplay);
}
void AquaSalFrame::doShowFullScreen( bool bFullScreen, sal_Int32 nDisplay )
{
if (!mpNSWindow)
{
if (Application::IsBitmapRendering() && bFullScreen)
SetPosSize(0, 0, 1024, 768, SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT);
return;
}
SAL_INFO("vcl.osx", __func__ << ": mbFullScreen=" << mbFullScreen << ", bFullScreen=" << bFullScreen);
if( mbFullScreen == bFullScreen )
return;
OSX_SALDATA_RUNINMAIN( ShowFullScreen( bFullScreen, nDisplay ) )
mbFullScreen = bFullScreen;
if( bFullScreen )
{
// hide the dock and the menubar if we are on the menu screen
// which is always on index 0 according to documentation
bool bHideMenu = (nDisplay == 0);
NSRect aNewContentRect = NSZeroRect;
// get correct screen
NSScreen* pScreen = nil;
NSArray* pScreens = [NSScreen screens];
if( pScreens )
{
if( nDisplay >= 0 && o3tl::make_unsigned(nDisplay) < [pScreens count] )
pScreen = [pScreens objectAtIndex: nDisplay];
else
{
// this means span all screens
bHideMenu = true;
NSEnumerator* pEnum = [pScreens objectEnumerator];
while( (pScreen = [pEnum nextObject]) != nil )
{
NSRect aScreenRect = [pScreen frame];
if( aScreenRect.origin.x < aNewContentRect.origin.x )
{
aNewContentRect.size.width += aNewContentRect.origin.x - aScreenRect.origin.x;
aNewContentRect.origin.x = aScreenRect.origin.x;
}
if( aScreenRect.origin.y < aNewContentRect.origin.y )
{
aNewContentRect.size.height += aNewContentRect.origin.y - aScreenRect.origin.y;
aNewContentRect.origin.y = aScreenRect.origin.y;
}
if( aScreenRect.origin.x + aScreenRect.size.width > aNewContentRect.origin.x + aNewContentRect.size.width )
aNewContentRect.size.width = aScreenRect.origin.x + aScreenRect.size.width - aNewContentRect.origin.x;
if( aScreenRect.origin.y + aScreenRect.size.height > aNewContentRect.origin.y + aNewContentRect.size.height )
aNewContentRect.size.height = aScreenRect.origin.y + aScreenRect.size.height - aNewContentRect.origin.y;
}
}
}
if( aNewContentRect.size.width == 0 && aNewContentRect.size.height == 0 )
{
if( pScreen == nil )
pScreen = [mpNSWindow screen];
if( pScreen == nil )
pScreen = [NSScreen mainScreen];
aNewContentRect = [pScreen frame];
}
if( bHideMenu )
[NSMenu setMenuBarVisible:NO];
maFullScreenRect = [mpNSWindow frame];
[mpNSWindow setFrame: [NSWindow frameRectForContentRect: aNewContentRect styleMask: mnStyleMask] display: mbShown ? YES : NO];
}
else
{
[mpNSWindow setFrame: maFullScreenRect display: mbShown ? YES : NO];
// show the dock and the menubar
[NSMenu setMenuBarVisible:YES];
}
UpdateFrameGeometry();
if (mbShown)
{
CallCallback(SalEvent::MoveResize, nullptr);
// trigger filling our backbuffer
SendPaintEvent();
}
}
void AquaSalFrame::StartPresentation( bool bStart )
{
if ( !mpNSWindow )
return;
OSX_SALDATA_RUNINMAIN( StartPresentation( bStart ) )
if( bStart )
{
GetSalData()->maPresentationFrames.push_back( this );
IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep,
kIOPMAssertionLevelOn,
CFSTR("LibreOffice presentation running"),
&mnAssertionID);
[mpNSWindow setLevel: NSPopUpMenuWindowLevel];
if( mbShown )
[mpNSWindow makeMainWindow];
}
else
{
GetSalData()->maPresentationFrames.remove( this );
IOPMAssertionRelease(mnAssertionID);
[mpNSWindow setLevel: NSNormalWindowLevel];
}
}
void AquaSalFrame::SetAlwaysOnTop( bool )
{
}
void AquaSalFrame::ToTop(SalFrameToTop nFlags)
{
if ( !mpNSWindow )
return;
OSX_SALDATA_RUNINMAIN( ToTop( nFlags ) )
if( ! (nFlags & SalFrameToTop::RestoreWhenMin) )
{
if( ! [mpNSWindow isVisible] || [mpNSWindow isMiniaturized] )
return;
}
if( nFlags & SalFrameToTop::GrabFocus )
[mpNSWindow makeKeyAndOrderFront: NSApp];
else
[mpNSWindow orderFront: NSApp];
}
NSCursor* AquaSalFrame::getCurrentCursor()
{
OSX_SALDATA_RUNINMAIN_POINTER( getCurrentCursor(), NSCursor* )
NSCursor* pCursor = nil;
switch( mePointerStyle )
{
case PointerStyle::Text: pCursor = [NSCursor IBeamCursor]; break;
case PointerStyle::Cross: pCursor = [NSCursor crosshairCursor]; break;
case PointerStyle::Hand:
case PointerStyle::Move: pCursor = [NSCursor openHandCursor]; break;
case PointerStyle::NSize: pCursor = [NSCursor resizeUpCursor]; break;
case PointerStyle::SSize: pCursor = [NSCursor resizeDownCursor]; break;
case PointerStyle::ESize: pCursor = [NSCursor resizeRightCursor]; break;
case PointerStyle::WSize: pCursor = [NSCursor resizeLeftCursor]; break;
case PointerStyle::Arrow: pCursor = [NSCursor arrowCursor]; break;
case PointerStyle::VSplit:
case PointerStyle::VSizeBar:
case PointerStyle::WindowNSize:
case PointerStyle::WindowSSize:
pCursor = [NSCursor resizeUpDownCursor]; break;
case PointerStyle::HSplit:
case PointerStyle::HSizeBar:
case PointerStyle::WindowESize:
case PointerStyle::WindowWSize:
pCursor = [NSCursor resizeLeftRightCursor]; break;
case PointerStyle::RefHand: pCursor = [NSCursor pointingHandCursor]; break;
default:
pCursor = GetSalData()->getCursor( mePointerStyle );
if( pCursor == nil )
{
assert( false && "unmapped cursor" );
pCursor = [NSCursor arrowCursor];
}
break;
}
return pCursor;
}
void AquaSalFrame::SetPointer( PointerStyle ePointerStyle )
{
if ( !mpNSWindow )
return;
if( ePointerStyle == mePointerStyle )
return;
OSX_SALDATA_RUNINMAIN( SetPointer( ePointerStyle ) )
mePointerStyle = ePointerStyle;
[mpNSWindow invalidateCursorRectsForView: mpNSView];
}
void AquaSalFrame::SetPointerPos( tools::Long nX, tools::Long nY )
{
OSX_SALDATA_RUNINMAIN( SetPointerPos( nX, nY ) )
// FIXME: use Cocoa functions
// FIXME: multiscreen support
CGPoint aPoint = { static_cast<CGFloat>(nX + maGeometry.x()), static_cast<CGFloat>(nY + maGeometry.y()) };
CGDirectDisplayID mainDisplayID = CGMainDisplayID();
CGDisplayMoveCursorToPoint( mainDisplayID, aPoint );
}
void AquaSalFrame::Flush()
{
if( !(mbGraphics && mpGraphics && mpNSView && mbShown) )
return;
OSX_SALDATA_RUNINMAIN( Flush() )
[mpNSView setNeedsDisplay: YES];
// outside of the application's event loop (e.g. IntroWindow)
// nothing would trigger paint event handling
// => fall back to synchronous painting
if( mbForceFlush || ImplGetSVData()->maAppData.mnDispatchLevel <= 0 )
{
mbForceFlush = false;
mpGraphics->Flush();
// Related: tdf#155266 skip redisplay of the view when forcing flush
// It appears that calling -[NSView display] overwhelms some Intel Macs
// so only flush the graphics and skip immediate redisplay of the view.
if( ImplGetSVData()->maAppData.mnDispatchLevel <= 0 )
[mpNSView display];
}
}
void AquaSalFrame::Flush( const tools::Rectangle& rRect )
{
if( !(mbGraphics && mpGraphics && mpNSView && mbShown) )
return;
OSX_SALDATA_RUNINMAIN( Flush( rRect ) )
NSRect aNSRect = { { static_cast<CGFloat>(rRect.Left()), static_cast<CGFloat>(rRect.Top()) }, { static_cast<CGFloat>(rRect.GetWidth()), static_cast<CGFloat>(rRect.GetHeight()) } };
VCLToCocoa( aNSRect, false );
[mpNSView setNeedsDisplayInRect: aNSRect];
// outside of the application's event loop (e.g. IntroWindow)
// nothing would trigger paint event handling
// => fall back to synchronous painting
if( mbForceFlush || ImplGetSVData()->maAppData.mnDispatchLevel <= 0 )
{
mbForceFlush = false;
mpGraphics->Flush( rRect );
// Related: tdf#155266 skip redisplay of the view when forcing flush
// It appears that calling -[NSView display] overwhelms some Intel Macs
// so only flush the graphics and skip immediate redisplay of the view.
if( ImplGetSVData()->maAppData.mnDispatchLevel <= 0 )
[mpNSView display];
}
}
void AquaSalFrame::SetInputContext( SalInputContext* pContext )
{
if (!pContext)
{
mnICOptions = InputContextFlags::NONE;
return;
}
mnICOptions = pContext->mnOptions;
if(!(pContext->mnOptions & InputContextFlags::Text))
return;
}
void AquaSalFrame::EndExtTextInput( EndExtTextInputFlags nFlags )
{
// tdf#82115 Commit uncommitted text when a popup menu is opened
// The Windows implementation of this method commits or discards the native
// input method session. It appears that very few, if any, macOS
// applications discard the uncommitted text when cancelling a session so
// always commit the uncommitted text.
SalFrameWindow *pWindow = static_cast<SalFrameWindow*>(mpNSWindow);
if (pWindow && [pWindow isKindOfClass:[SalFrameWindow class]])
[pWindow endExtTextInput:nFlags];
}
OUString AquaSalFrame::GetKeyName( sal_uInt16 nKeyCode )
{
static std::map< sal_uInt16, OUString > aKeyMap;
if( aKeyMap.empty() )
{
sal_uInt16 i;
for( i = KEY_A; i <= KEY_Z; i++ )
aKeyMap[ i ] = OUString( sal_Unicode( 'A' + (i - KEY_A) ) );
for( i = KEY_0; i <= KEY_9; i++ )
aKeyMap[ i ] = OUString( sal_Unicode( '0' + (i - KEY_0) ) );
for( i = KEY_F1; i <= KEY_F26; i++ )
{
aKeyMap[ i ] = "F" + OUString::number(i - KEY_F1 + 1);
}
aKeyMap[ KEY_DOWN ] = OUString( u'\x21e3' );
aKeyMap[ KEY_UP ] = OUString( u'\x21e1' );
aKeyMap[ KEY_LEFT ] = OUString( u'\x21e0' );
aKeyMap[ KEY_RIGHT ] = OUString( u'\x21e2' );
aKeyMap[ KEY_HOME ] = OUString( u'\x2196' );
aKeyMap[ KEY_END ] = OUString( u'\x2198' );
aKeyMap[ KEY_PAGEUP ] = OUString( u'\x21de' );
aKeyMap[ KEY_PAGEDOWN ] = OUString( u'\x21df' );
aKeyMap[ KEY_RETURN ] = OUString( u'\x21a9' );
aKeyMap[ KEY_ESCAPE ] = "esc";
aKeyMap[ KEY_TAB ] = OUString( u'\x21e5' );
aKeyMap[ KEY_BACKSPACE ]= OUString( u'\x232b' );
aKeyMap[ KEY_SPACE ] = OUString( u'\x2423' );
aKeyMap[ KEY_DELETE ] = OUString( u'\x2326' );
aKeyMap[ KEY_ADD ] = "+";
aKeyMap[ KEY_SUBTRACT ] = "-";
aKeyMap[ KEY_DIVIDE ] = "/";
aKeyMap[ KEY_MULTIPLY ] = "*";
aKeyMap[ KEY_POINT ] = ".";
aKeyMap[ KEY_COMMA ] = ",";
aKeyMap[ KEY_LESS ] = "<";
aKeyMap[ KEY_GREATER ] = ">";
aKeyMap[ KEY_EQUAL ] = "=";
aKeyMap[ KEY_OPEN ] = OUString( u'\x23cf' );
aKeyMap[ KEY_TILDE ] = "~";
aKeyMap[ KEY_BRACKETLEFT ] = "[";
aKeyMap[ KEY_BRACKETRIGHT ] = "]";
aKeyMap[ KEY_SEMICOLON ] = ";";
aKeyMap[ KEY_QUOTERIGHT ] = "'";
aKeyMap[ KEY_RIGHTCURLYBRACKET ] = "}";
aKeyMap[ KEY_NUMBERSIGN ] = "#";
aKeyMap[ KEY_COLON ] = ":";
/* yet unmapped KEYCODES:
aKeyMap[ KEY_INSERT ] = OUString( sal_Unicode( ) );
aKeyMap[ KEY_CUT ] = OUString( sal_Unicode( ) );
aKeyMap[ KEY_COPY ] = OUString( sal_Unicode( ) );
aKeyMap[ KEY_PASTE ] = OUString( sal_Unicode( ) );
aKeyMap[ KEY_UNDO ] = OUString( sal_Unicode( ) );
aKeyMap[ KEY_REPEAT ] = OUString( sal_Unicode( ) );
aKeyMap[ KEY_FIND ] = OUString( sal_Unicode( ) );
aKeyMap[ KEY_PROPERTIES ] = OUString( sal_Unicode( ) );
aKeyMap[ KEY_FRONT ] = OUString( sal_Unicode( ) );
aKeyMap[ KEY_CONTEXTMENU ] = OUString( sal_Unicode( ) );
aKeyMap[ KEY_MENU ] = OUString( sal_Unicode( ) );
aKeyMap[ KEY_HELP ] = OUString( sal_Unicode( ) );
aKeyMap[ KEY_HANGUL_HANJA ] = OUString( sal_Unicode( ) );
aKeyMap[ KEY_DECIMAL ] = OUString( sal_Unicode( ) );
aKeyMap[ KEY_QUOTELEFT ]= OUString( sal_Unicode( ) );
aKeyMap[ KEY_CAPSLOCK ]= OUString( sal_Unicode( ) );
aKeyMap[ KEY_NUMLOCK ]= OUString( sal_Unicode( ) );
aKeyMap[ KEY_SCROLLLOCK ]= OUString( sal_Unicode( ) );
*/
}
OUStringBuffer aResult( 16 );
sal_uInt16 nUnmodifiedCode = (nKeyCode & KEY_CODE_MASK);
std::map< sal_uInt16, OUString >::const_iterator it = aKeyMap.find( nUnmodifiedCode );
if( it != aKeyMap.end() )
{
if( (nKeyCode & KEY_SHIFT) != 0 )
aResult.append( u'\x21e7' ); // shift
if( (nKeyCode & KEY_MOD1) != 0 )
aResult.append( u'\x2318' ); // command
if( (nKeyCode & KEY_MOD2) != 0 )
aResult.append( u'\x2325' ); // alternate
if( (nKeyCode & KEY_MOD3) != 0 )
aResult.append( u'\x2303' ); // control
aResult.append( it->second );
}
return aResult.makeStringAndClear();
}
static void getAppleScrollBarVariant(StyleSettings &rSettings)
{
bool bIsScrollbarDoubleMax = true; // default is DoubleMax
CFStringRef AppleScrollBarType = CFSTR("AppleScrollBarVariant");
if( AppleScrollBarType )
{
CFStringRef ScrollBarVariant = static_cast<CFStringRef>(CFPreferencesCopyAppValue( AppleScrollBarType, kCFPreferencesCurrentApplication ));
if( ScrollBarVariant )
{
if( CFGetTypeID( ScrollBarVariant ) == CFStringGetTypeID() )
{
// TODO: check for the less important variants "DoubleMin" and "DoubleBoth" too
CFStringRef DoubleMax = CFSTR("DoubleMax");
if (DoubleMax)
{
if ( !CFStringCompare(ScrollBarVariant, DoubleMax, kCFCompareCaseInsensitive) )
bIsScrollbarDoubleMax = true;
else
bIsScrollbarDoubleMax = false;
CFRelease(DoubleMax);
}
}
CFRelease( ScrollBarVariant );
}
CFRelease(AppleScrollBarType);
}
GetSalData()->mbIsScrollbarDoubleMax = bIsScrollbarDoubleMax;
CFStringRef jumpScroll = CFSTR("AppleScrollerPagingBehavior");
if( jumpScroll )
{
CFBooleanRef jumpStr = static_cast<CFBooleanRef>(CFPreferencesCopyAppValue( jumpScroll, kCFPreferencesCurrentApplication ));
if( jumpStr )
{
if( CFGetTypeID( jumpStr ) == CFBooleanGetTypeID() )
rSettings.SetPrimaryButtonWarpsSlider(jumpStr == kCFBooleanTrue);
CFRelease( jumpStr );
}
CFRelease( jumpScroll );
}
}
static Color getNSBoxBackgroundColor(NSColor* pSysColor)
{
// Figuring out what a NSBox will draw for windowBackground, etc. seems very difficult.
// So just draw to a 1x1 surface and read what actually gets drawn
// This is similar to getPixel
#if defined OSL_BIGENDIAN
struct
{
unsigned char b, g, r, a;
} aPixel;
#else
struct
{
unsigned char a, r, g, b;
} aPixel;
#endif
// create a one-pixel bitmap context
CGContextRef xOnePixelContext = CGBitmapContextCreate(
&aPixel, 1, 1, 8, 32, GetSalData()->mxRGBSpace,
uint32_t(kCGImageAlphaNoneSkipFirst) | uint32_t(kCGBitmapByteOrder32Big));
NSGraphicsContext* graphicsContext = [NSGraphicsContext graphicsContextWithCGContext:xOnePixelContext flipped:NO];
NSRect rect = { NSZeroPoint, NSMakeSize(1, 1) };
NSBox* pBox = [[NSBox alloc] initWithFrame: rect];
[pBox setBoxType: NSBoxCustom];
[pBox setFillColor: pSysColor];
SAL_WNODEPRECATED_DECLARATIONS_PUSH // setBorderType first deprecated in macOS 10.15
[pBox setBorderType: NSNoBorder];
SAL_WNODEPRECATED_DECLARATIONS_POP
[pBox displayRectIgnoringOpacity: rect inContext: graphicsContext];
[pBox release];
CGContextRelease(xOnePixelContext);
return Color(aPixel.r, aPixel.g, aPixel.b);
}
static Color getColor( NSColor* pSysColor, const Color& rDefault, NSWindow* pWin )
{
Color aRet( rDefault );
if( pSysColor )
{
// transform to RGB
SAL_WNODEPRECATED_DECLARATIONS_PUSH
// "'colorUsingColorSpaceName:device:' is deprecated: first deprecated in macOS 10.14 -
// Use -colorUsingType: or -colorUsingColorSpace: instead"
NSColor* pRBGColor = [pSysColor colorUsingColorSpaceName: NSDeviceRGBColorSpace device: [pWin deviceDescription]];
SAL_WNODEPRECATED_DECLARATIONS_POP
if( pRBGColor )
{
CGFloat r = 0, g = 0, b = 0, a = 0;
[pRBGColor getRed: &r green: &g blue: &b alpha: &a];
aRet = Color( int(r*255.999), int(g*255.999), int(b*255.999) );
}
}
return aRet;
}
static vcl::Font getFont( NSFont* pFont, sal_Int32 nDPIY, const vcl::Font& rDefault )
{
vcl::Font aResult( rDefault );
if( pFont )
{
aResult.SetFamilyName( GetOUString( [pFont familyName] ) );
aResult.SetFontHeight( static_cast<int>(ceil([pFont pointSize] * 72.0 / static_cast<float>(nDPIY))) );
aResult.SetItalic( ([pFont italicAngle] != 0.0) ? ITALIC_NORMAL : ITALIC_NONE );
// FIMXE: bold ?
}
return aResult;
}
void AquaSalFrame::getResolution( sal_Int32& o_rDPIX, sal_Int32& o_rDPIY )
{
OSX_SALDATA_RUNINMAIN( getResolution( o_rDPIX, o_rDPIY ) )
if( ! mpGraphics )
{
AcquireGraphics();
ReleaseGraphics( mpGraphics );
}
mpGraphics->GetResolution( o_rDPIX, o_rDPIY );
}
void AquaSalFrame::UpdateDarkMode()
{
if (@available(macOS 10.14, iOS 13, *))
{
switch (MiscSettings::GetDarkMode())
{
case 0: // auto
default:
[NSApp setAppearance: nil];
break;
case 1: // light
[NSApp setAppearance: [NSAppearance appearanceNamed: NSAppearanceNameAqua]];
break;
case 2: // dark
[NSApp setAppearance: [NSAppearance appearanceNamed: NSAppearanceNameDarkAqua]];
break;
}
}
}
bool AquaSalFrame::GetUseDarkMode() const
{
if (!mpNSView)
return false;
bool bUseDarkMode(false);
if (@available(macOS 10.14, iOS 13, *))
{
NSAppearanceName match = [mpNSView.effectiveAppearance bestMatchFromAppearancesWithNames: @[
NSAppearanceNameAqua, NSAppearanceNameDarkAqua]];
bUseDarkMode = [match isEqualToString: NSAppearanceNameDarkAqua];
}
return bUseDarkMode;
}
bool AquaSalFrame::GetUseReducedAnimation() const
{
return [[NSWorkspace sharedWorkspace] accessibilityDisplayShouldReduceMotion];
}
// on OSX-Aqua the style settings are independent of the frame, so it does
// not really belong here. Since the connection to the Appearance_Manager
// is currently done in salnativewidgets.cxx this would be a good place.
// On the other hand VCL's platform independent code currently only asks
// SalFrames for system settings anyway, so moving the code somewhere else
// doesn't make the anything cleaner for now
void AquaSalFrame::UpdateSettings( AllSettings& rSettings )
{
if ( !mpNSWindow )
return;
OSX_SALDATA_RUNINMAIN( UpdateSettings( rSettings ) )
SAL_WNODEPRECATED_DECLARATIONS_PUSH
// "'lockFocus' is deprecated: first deprecated in macOS 10.14 - To draw, subclass NSView
// and implement -drawRect:; AppKit's automatic deferred display mechanism will call
// -drawRect: as necessary to display the view."
if (![mpNSView lockFocusIfCanDraw])
return;
SAL_WNODEPRECATED_DECLARATIONS_POP
SAL_WNODEPRECATED_DECLARATIONS_PUSH
// "'setCurrentAppearance:' is deprecated: first deprecated in macOS 12.0 - Use
// -performAsCurrentDrawingAppearance: to temporarily set the drawing appearance, or
// +currentDrawingAppearance to access the currently drawing appearance."
[NSAppearance setCurrentAppearance: mpNSView.effectiveAppearance];
SAL_WNODEPRECATED_DECLARATIONS_POP
StyleSettings aStyleSettings = rSettings.GetStyleSettings();
bool bUseDarkMode(GetUseDarkMode());
OUString sThemeName(!bUseDarkMode ? u"sukapura" : u"sukapura_dark");
aStyleSettings.SetPreferredIconTheme(sThemeName, bUseDarkMode);
Color aControlBackgroundColor(getNSBoxBackgroundColor([NSColor controlBackgroundColor]));
Color aWindowBackgroundColor(getNSBoxBackgroundColor([NSColor windowBackgroundColor]));
Color aUnderPageBackgroundColor(getNSBoxBackgroundColor([NSColor underPageBackgroundColor]));
// Background Color
aStyleSettings.BatchSetBackgrounds( aWindowBackgroundColor, false );
aStyleSettings.SetLightBorderColor( aWindowBackgroundColor );
aStyleSettings.SetActiveTabColor(aWindowBackgroundColor);
Color aInactiveTabColor( aWindowBackgroundColor );
aInactiveTabColor.DecreaseLuminance( 32 );
aStyleSettings.SetInactiveTabColor( aInactiveTabColor );
Color aShadowColor = getColor( [NSColor systemGrayColor ],
aStyleSettings.GetShadowColor(), mpNSWindow );
aStyleSettings.SetShadowColor( aShadowColor );
// tdf#152284 for DarkMode brighten it, while darken for BrightMode
NSColor* pDarkColor = bUseDarkMode ? [[NSColor systemGrayColor] highlightWithLevel: 0.5]
: [[NSColor systemGrayColor] shadowWithLevel: 0.5];
Color aDarkShadowColor = getColor( pDarkColor, aStyleSettings.GetDarkShadowColor(), mpNSWindow );
aStyleSettings.SetDarkShadowColor(aDarkShadowColor);
// get the system font settings
vcl::Font aAppFont = aStyleSettings.GetAppFont();
sal_Int32 nDPIX = 72, nDPIY = 72;
getResolution( nDPIX, nDPIY );
aAppFont = getFont( [NSFont systemFontOfSize: 0], nDPIY, aAppFont );
aStyleSettings.SetToolbarIconSize( ToolbarIconSize::Large );
// TODO: better mapping of macOS<->LibreOffice font settings
vcl::Font aLabelFont( getFont( [NSFont labelFontOfSize: 0], nDPIY, aAppFont ) );
aStyleSettings.BatchSetFonts( aAppFont, aLabelFont );
vcl::Font aMenuFont( getFont( [NSFont menuFontOfSize: 0], nDPIY, aAppFont ) );
aStyleSettings.SetMenuFont( aMenuFont );
vcl::Font aTitleFont( getFont( [NSFont titleBarFontOfSize: 0], nDPIY, aAppFont ) );
aStyleSettings.SetTitleFont( aTitleFont );
aStyleSettings.SetFloatTitleFont( aTitleFont );
vcl::Font aTooltipFont(getFont([NSFont toolTipsFontOfSize: 0], nDPIY, aAppFont));
aStyleSettings.SetHelpFont(aTooltipFont);
Color aAccentColor( getColor( [NSColor controlAccentColor],
aStyleSettings.GetAccentColor(), mpNSWindow ) );
aStyleSettings.SetAccentColor( aAccentColor );
Color aHighlightColor( getColor( [NSColor selectedTextBackgroundColor],
aStyleSettings.GetHighlightColor(), mpNSWindow ) );
aStyleSettings.SetHighlightColor( aHighlightColor );
Color aHighlightTextColor( getColor( [NSColor selectedTextColor],
aStyleSettings.GetHighlightTextColor(), mpNSWindow ) );
aStyleSettings.SetHighlightTextColor( aHighlightTextColor );
aStyleSettings.SetLinkColor(getColor( [NSColor linkColor],
aStyleSettings.GetLinkColor(), mpNSWindow ) );
aStyleSettings.SetVisitedLinkColor(getColor( [NSColor purpleColor],
aStyleSettings.GetVisitedLinkColor(), mpNSWindow ) );
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
Color aMenuHighlightColor( getColor( [NSColor selectedMenuItemColor],
aStyleSettings.GetMenuHighlightColor(), mpNSWindow ) );
#pragma clang diagnostic pop
aStyleSettings.SetMenuHighlightColor( aMenuHighlightColor );
Color aMenuHighlightTextColor( getColor( [NSColor selectedMenuItemTextColor],
aStyleSettings.GetMenuHighlightTextColor(), mpNSWindow ) );
aStyleSettings.SetMenuHighlightTextColor( aMenuHighlightTextColor );
aStyleSettings.SetMenuColor( aWindowBackgroundColor );
Color aMenuTextColor( getColor( [NSColor textColor],
aStyleSettings.GetMenuTextColor(), mpNSWindow ) );
aStyleSettings.SetMenuTextColor( aMenuTextColor );
aStyleSettings.SetMenuBarTextColor( aMenuTextColor );
aStyleSettings.SetMenuBarRolloverTextColor( aMenuTextColor );
aStyleSettings.SetMenuBarHighlightTextColor(aStyleSettings.GetMenuHighlightTextColor());
aStyleSettings.SetListBoxWindowBackgroundColor( aWindowBackgroundColor );
aStyleSettings.SetListBoxWindowTextColor( aMenuTextColor );
aStyleSettings.SetListBoxWindowHighlightColor( aMenuHighlightColor );
aStyleSettings.SetListBoxWindowHighlightTextColor( aMenuHighlightTextColor );
// FIXME: Starting with macOS Big Sur, coloring has changed. Currently there is no documentation which system color should be
// used for some button states and for selected tab text. As a workaround the current OS version has to be considered. This code
// has to be reviewed once issue is covered by documentation.
// Set text colors for buttons and their different status according to OS settings, typically white for selected buttons,
// black otherwise
NSOperatingSystemVersion aOSVersion = { .majorVersion = 10, .minorVersion = 16, .patchVersion = 0 };
Color aControlTextColor(getColor([NSColor controlTextColor], COL_BLACK, mpNSWindow ));
Color aSelectedControlTextColor(getColor([NSColor selectedControlTextColor], COL_BLACK, mpNSWindow ));
Color aAlternateSelectedControlTextColor(getColor([NSColor alternateSelectedControlTextColor], COL_WHITE, mpNSWindow ));
aStyleSettings.SetWindowColor(aWindowBackgroundColor);
aStyleSettings.SetListBoxWindowBackgroundColor(aWindowBackgroundColor);
aStyleSettings.SetDialogTextColor(aControlTextColor);
aStyleSettings.SetButtonTextColor(aControlTextColor);
aStyleSettings.SetActionButtonTextColor(aControlTextColor);
aStyleSettings.SetRadioCheckTextColor(aControlTextColor);
aStyleSettings.SetGroupTextColor(aControlTextColor);
aStyleSettings.SetLabelTextColor(aControlTextColor);
aStyleSettings.SetWindowTextColor(aControlTextColor);
aStyleSettings.SetFieldTextColor(aControlTextColor);
aStyleSettings.SetFieldRolloverTextColor(aControlTextColor);
aStyleSettings.SetFieldColor(aControlBackgroundColor);
aStyleSettings.SetDefaultActionButtonTextColor(aAlternateSelectedControlTextColor);
aStyleSettings.SetFlatButtonTextColor(aControlTextColor);
aStyleSettings.SetDefaultButtonRolloverTextColor(aAlternateSelectedControlTextColor);
aStyleSettings.SetButtonRolloverTextColor(aControlTextColor);
aStyleSettings.SetDefaultActionButtonRolloverTextColor(aAlternateSelectedControlTextColor);
aStyleSettings.SetActionButtonRolloverTextColor(aControlTextColor);
aStyleSettings.SetFlatButtonRolloverTextColor(aControlTextColor);
aStyleSettings.SetDefaultButtonPressedRolloverTextColor(aAlternateSelectedControlTextColor);
aStyleSettings.SetDefaultActionButtonPressedRolloverTextColor(aAlternateSelectedControlTextColor);
aStyleSettings.SetFlatButtonPressedRolloverTextColor(aControlTextColor);
if ([NSProcessInfo.processInfo isOperatingSystemAtLeastVersion: aOSVersion])
{
aStyleSettings.SetDefaultButtonTextColor(aAlternateSelectedControlTextColor);
aStyleSettings.SetButtonPressedRolloverTextColor(aSelectedControlTextColor);
aStyleSettings.SetActionButtonPressedRolloverTextColor(aSelectedControlTextColor);
}
else
{
aStyleSettings.SetButtonPressedRolloverTextColor(aAlternateSelectedControlTextColor);
aStyleSettings.SetActionButtonPressedRolloverTextColor(aAlternateSelectedControlTextColor);
aStyleSettings.SetDefaultButtonTextColor(aSelectedControlTextColor);
}
aStyleSettings.SetWorkspaceColor(aUnderPageBackgroundColor);
aStyleSettings.SetHelpColor(aControlBackgroundColor);
aStyleSettings.SetHelpTextColor(aControlTextColor);
aStyleSettings.SetToolTextColor(aControlTextColor);
// Set text colors for tabs according to OS settings
aStyleSettings.SetTabTextColor(aControlTextColor);
aStyleSettings.SetTabRolloverTextColor(aControlTextColor);
if ([NSProcessInfo.processInfo isOperatingSystemAtLeastVersion: aOSVersion])
aStyleSettings.SetTabHighlightTextColor(aSelectedControlTextColor);
else
aStyleSettings.SetTabHighlightTextColor(aAlternateSelectedControlTextColor);
aStyleSettings.SetCursorBlinkTime( mnBlinkCursorDelay );
aStyleSettings.SetCursorSize(1);
// no mnemonics on macOS
aStyleSettings.SetOptions( aStyleSettings.GetOptions() | StyleSettingsOptions::NoMnemonics );
getAppleScrollBarVariant(aStyleSettings);
// set scrollbar size
aStyleSettings.SetScrollBarSize( static_cast<tools::Long>([NSScroller scrollerWidthForControlSize:NSControlSizeRegular scrollerStyle:NSScrollerStyleLegacy]) );
// images in menus false for MacOSX
aStyleSettings.SetPreferredUseImagesInMenus( false );
aStyleSettings.SetHideDisabledMenuItems( true );
aStyleSettings.SetPreferredContextMenuShortcuts( false );
rSettings.SetStyleSettings( aStyleSettings );
// don't draw frame around each and every toolbar
ImplGetSVData()->maNWFData.mbDockingAreaAvoidTBFrames = true;
SAL_WNODEPRECATED_DECLARATIONS_PUSH
// "'unlockFocus' is deprecated: first deprecated in macOS 10.14 - To draw, subclass NSView
// and implement -drawRect:; AppKit's automatic deferred display mechanism will call
// -drawRect: as necessary to display the view."
[mpNSView unlockFocus];
SAL_WNODEPRECATED_DECLARATIONS_POP
}
const SystemEnvData* AquaSalFrame::GetSystemData() const
{
return &maSysData;
}
void AquaSalFrame::Beep()
{
OSX_SALDATA_RUNINMAIN( Beep() )
NSBeep();
}
void AquaSalFrame::SetPosSize(
tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, sal_uInt16 nFlags)
{
if (!mpNSWindow && !Application::IsBitmapRendering())
return;
OSX_SALDATA_RUNINMAIN( SetPosSize( nX, nY, nWidth, nHeight, nFlags ) )
SalEvent nEvent = PreparePosSize(nX, nY, nWidth, nHeight, nFlags);
if (Application::IsBitmapRendering())
return;
if( [mpNSWindow isMiniaturized] )
[mpNSWindow deminiaturize: NSApp]; // expand the window
NSRect aFrameRect = [mpNSWindow frame];
NSRect aContentRect = [NSWindow contentRectForFrameRect: aFrameRect styleMask: mnStyleMask];
// position is always relative to parent frame
NSRect aParentContentRect;
if( mpParent )
{
if( AllSettings::GetLayoutRTL() )
{
if( (nFlags & SAL_FRAME_POSSIZE_WIDTH) != 0 )
nX = static_cast<tools::Long>(mpParent->maGeometry.width()) - nWidth - 1 - nX;
else
nX = static_cast<tools::Long>(mpParent->maGeometry.width()) - aContentRect.size.width - 1 - nX;
}
NSRect aParentFrameRect = [mpParent->mpNSWindow frame];
aParentContentRect = [NSWindow contentRectForFrameRect: aParentFrameRect styleMask: mpParent->mnStyleMask];
}
else
aParentContentRect = maScreenRect; // use screen if no parent
CocoaToVCL( aContentRect );
CocoaToVCL( aParentContentRect );
bool bPaint = false;
if( (nFlags & (SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT)) != 0 )
{
if( nWidth != aContentRect.size.width || nHeight != aContentRect.size.height )
bPaint = true;
}
// use old window pos if no new pos requested
if( (nFlags & SAL_FRAME_POSSIZE_X) != 0 )
aContentRect.origin.x = nX + aParentContentRect.origin.x;
if( (nFlags & SAL_FRAME_POSSIZE_Y) != 0)
aContentRect.origin.y = nY + aParentContentRect.origin.y;
// use old size if no new size requested
if( (nFlags & SAL_FRAME_POSSIZE_WIDTH) != 0 )
aContentRect.size.width = nWidth;
if( (nFlags & SAL_FRAME_POSSIZE_HEIGHT) != 0)
aContentRect.size.height = nHeight;
VCLToCocoa( aContentRect );
// do not display yet, we need to update our backbuffer
{
[mpNSWindow setFrame: [NSWindow frameRectForContentRect: aContentRect styleMask: mnStyleMask] display: NO];
}
UpdateFrameGeometry();
if (nEvent != SalEvent::NONE)
CallCallback(nEvent, nullptr);
if( mbShown && bPaint )
{
// trigger filling our backbuffer
SendPaintEvent();
// now inform the system that the views need to be drawn
[mpNSWindow display];
}
}
void AquaSalFrame::GetWorkArea( AbsoluteScreenPixelRectangle& rRect )
{
if (!mpNSWindow)
{
if (Application::IsBitmapRendering())
rRect = AbsoluteScreenPixelRectangle(AbsoluteScreenPixelPoint(0, 0), AbsoluteScreenPixelSize(1024, 768));
return;
}
OSX_SALDATA_RUNINMAIN( GetWorkArea( rRect ) )
NSScreen* pScreen = [mpNSWindow screen];
if( pScreen == nil )
pScreen = [NSScreen mainScreen];
NSRect aRect = [pScreen visibleFrame];
CocoaToVCL( aRect );
rRect.SetLeft( static_cast<tools::Long>(aRect.origin.x) );
rRect.SetTop( static_cast<tools::Long>(aRect.origin.y) );
rRect.SetRight( static_cast<tools::Long>(aRect.origin.x + aRect.size.width - 1) );
rRect.SetBottom( static_cast<tools::Long>(aRect.origin.y + aRect.size.height - 1) );
}
SalFrame::SalPointerState AquaSalFrame::GetPointerState()
{
OSX_SALDATA_RUNINMAIN_UNION( GetPointerState(), state )
SalPointerState state;
state.mnState = 0;
// get position
NSPoint aPt = [mpNSWindow mouseLocationOutsideOfEventStream];
CocoaToVCL( aPt, false );
state.maPos = Point(static_cast<tools::Long>(aPt.x), static_cast<tools::Long>(aPt.y));
NSEvent* pCur = [NSApp currentEvent];
bool bMouseEvent = false;
if( pCur )
{
bMouseEvent = true;
switch( [pCur type] )
{
case NSEventTypeLeftMouseDown:
state.mnState |= MOUSE_LEFT;
break;
case NSEventTypeLeftMouseUp:
break;
case NSEventTypeRightMouseDown:
state.mnState |= MOUSE_RIGHT;
break;
case NSEventTypeRightMouseUp:
break;
case NSEventTypeOtherMouseDown:
state.mnState |= ([pCur buttonNumber] == 2) ? MOUSE_MIDDLE : 0;
break;
case NSEventTypeOtherMouseUp:
break;
case NSEventTypeMouseMoved:
break;
case NSEventTypeLeftMouseDragged:
state.mnState |= MOUSE_LEFT;
break;
case NSEventTypeRightMouseDragged:
state.mnState |= MOUSE_RIGHT;
break;
case NSEventTypeOtherMouseDragged:
state.mnState |= ([pCur buttonNumber] == 2) ? MOUSE_MIDDLE : 0;
break;
default:
bMouseEvent = false;
break;
}
}
if( bMouseEvent )
{
unsigned int nMask = static_cast<unsigned int>([pCur modifierFlags]);
if( (nMask & NSEventModifierFlagShift) != 0 )
state.mnState |= KEY_SHIFT;
if( (nMask & NSEventModifierFlagControl) != 0 )
state.mnState |= KEY_MOD3;
if( (nMask & NSEventModifierFlagOption) != 0 )
state.mnState |= KEY_MOD2;
if( (nMask & NSEventModifierFlagCommand) != 0 )
state.mnState |= KEY_MOD1;
}
else
{
// FIXME: replace Carbon by Cocoa
// Cocoa does not have an equivalent for GetCurrentEventButtonState
// and GetCurrentEventKeyModifiers.
// we could try to get away with tracking all events for modifierKeys
// and all mouse events for button state in VCL_NSApplication::sendEvent,
// but it is unclear whether this will get us the same result.
// leave in GetCurrentEventButtonState and GetCurrentEventKeyModifiers for now
// fill in button state
UInt32 nState = GetCurrentEventButtonState();
state.mnState = 0;
if( nState & 1 )
state.mnState |= MOUSE_LEFT; // primary button
if( nState & 2 )
state.mnState |= MOUSE_RIGHT; // secondary button
if( nState & 4 )
state.mnState |= MOUSE_MIDDLE; // tertiary button
// fill in modifier state
nState = GetCurrentEventKeyModifiers();
if( nState & shiftKey )
state.mnState |= KEY_SHIFT;
if( nState & controlKey )
state.mnState |= KEY_MOD3;
if( nState & optionKey )
state.mnState |= KEY_MOD2;
if( nState & cmdKey )
state.mnState |= KEY_MOD1;
}
return state;
}
KeyIndicatorState AquaSalFrame::GetIndicatorState()
{
return KeyIndicatorState::NONE;
}
void AquaSalFrame::SimulateKeyPress( sal_uInt16 /*nKeyCode*/ )
{
}
void AquaSalFrame::SetPluginParent( SystemParentData* )
{
// plugin parent may be killed unexpectedly by
// plugging process;
//TODO: implement
}
bool AquaSalFrame::MapUnicodeToKeyCode( sal_Unicode , LanguageType , vcl::KeyCode& )
{
// not supported yet
return false;
}
LanguageType AquaSalFrame::GetInputLanguage()
{
//TODO: implement
return LANGUAGE_DONTKNOW;
}
void AquaSalFrame::SetMenu( SalMenu* pSalMenu )
{
OSX_SALDATA_RUNINMAIN( SetMenu( pSalMenu ) )
AquaSalMenu* pMenu = static_cast<AquaSalMenu*>(pSalMenu);
SAL_WARN_IF( pMenu && !pMenu->mbMenuBar, "vcl", "setting non menubar on frame" );
mpMenu = pMenu;
if( mpMenu )
mpMenu->setMainMenu();
}
void AquaSalFrame::SetExtendedFrameStyle( SalExtStyle nStyle )
{
if ( !mpNSWindow )
{
mnExtStyle = nStyle;
return;
}
OSX_SALDATA_RUNINMAIN( SetExtendedFrameStyle( nStyle ) )
if( (mnExtStyle & SAL_FRAME_EXT_STYLE_DOCMODIFIED) != (nStyle & SAL_FRAME_EXT_STYLE_DOCMODIFIED) )
[mpNSWindow setDocumentEdited: (nStyle & SAL_FRAME_EXT_STYLE_DOCMODIFIED) ? YES : NO];
mnExtStyle = nStyle;
}
SalFrame* AquaSalFrame::GetParent() const
{
return mpParent;
}
void AquaSalFrame::SetParent( SalFrame* pNewParent )
{
bool bShown = mbShown;
// remove from child list
if (bShown)
Show(false);
mpParent = static_cast<AquaSalFrame*>(pNewParent);
// insert to correct parent and paint
Show( bShown );
}
void AquaSalFrame::UpdateFrameGeometry()
{
mbGeometryDidChange = false;
if ( !mpNSWindow )
return;
OSX_SALDATA_RUNINMAIN( UpdateFrameGeometry() )
// keep in mind that view and window coordinates are lower left
// whereas vcl's are upper left
// update screen rect
NSScreen * pScreen = [mpNSWindow screen];
if( pScreen )
{
NSRect aNewScreenRect = [pScreen frame];
if (!NSEqualRects(maScreenRect, aNewScreenRect))
{
mbGeometryDidChange = true;
maScreenRect = aNewScreenRect;
}
NSArray* pScreens = [NSScreen screens];
if( pScreens )
{
unsigned int nNewDisplayScreenNumber = [pScreens indexOfObject: pScreen];
if (maGeometry.screen() != nNewDisplayScreenNumber)
{
mbGeometryDidChange = true;
maGeometry.setScreen(nNewDisplayScreenNumber);
}
}
}
NSRect aFrameRect = [mpNSWindow frame];
NSRect aContentRect = [NSWindow contentRectForFrameRect: aFrameRect styleMask: mnStyleMask];
NSRect aTrackRect = { NSZeroPoint, aContentRect.size };
if (!NSEqualRects(maTrackingRect, aTrackRect))
{
mbGeometryDidChange = true;
maTrackingRect = aTrackRect;
}
// convert to vcl convention
CocoaToVCL( aFrameRect );
CocoaToVCL( aContentRect );
if (!NSEqualRects(maContentRect, aContentRect) || !NSEqualRects(maFrameRect, aFrameRect))
{
mbGeometryDidChange = true;
maContentRect = aContentRect;
maFrameRect = aFrameRect;
maGeometry.setX(static_cast<sal_Int32>(aContentRect.origin.x));
maGeometry.setY(static_cast<sal_Int32>(aContentRect.origin.y));
maGeometry.setWidth(static_cast<sal_uInt32>(aContentRect.size.width));
maGeometry.setHeight(static_cast<sal_uInt32>(aContentRect.size.height));
maGeometry.setLeftDecoration(static_cast<sal_uInt32>(aContentRect.origin.x - aFrameRect.origin.x));
maGeometry.setRightDecoration(static_cast<sal_uInt32>((aFrameRect.origin.x + aFrameRect.size.width) -
(aContentRect.origin.x + aContentRect.size.width)));
maGeometry.setTopDecoration(static_cast<sal_uInt32>(aContentRect.origin.y - aFrameRect.origin.y));
maGeometry.setBottomDecoration(static_cast<sal_uInt32>((aFrameRect.origin.y + aFrameRect.size.height) -
(aContentRect.origin.y + aContentRect.size.height)));
}
}
void AquaSalFrame::CaptureMouse( bool bCapture )
{
/* Remark:
we'll try to use a pidgin version of capture mouse
on MacOSX (neither carbon nor cocoa) there is a
CaptureMouse equivalent (in Carbon there is TrackMouseLocation
but this is useless to use since it is blocking)
However on cocoa the active frame seems to get mouse events
also outside the window, so we'll try to forward mouse events
to the capture frame in the hope that one of our frames
gets a mouse event.
This will break as soon as the user activates another app, but
a mouse click will normally lead to a release of the mouse anyway.
Let's see how far we get this way. Alternatively we could use one
large overlay window like we did for the carbon implementation,
however that is resource intensive.
*/
if( bCapture )
s_pCaptureFrame = this;
else if( ! bCapture && s_pCaptureFrame == this )
s_pCaptureFrame = nullptr;
}
void AquaSalFrame::ResetClipRegion()
{
doResetClipRegion();
}
void AquaSalFrame::doResetClipRegion()
{
if ( !mpNSWindow )
return;
OSX_SALDATA_RUNINMAIN( ResetClipRegion() )
// release old path and indicate no clipping
CGPathRelease( mrClippingPath );
mrClippingPath = nullptr;
if( mpNSView && mbShown )
[mpNSView setNeedsDisplay: YES];
[mpNSWindow setOpaque: YES];
[mpNSWindow invalidateShadow];
}
void AquaSalFrame::BeginSetClipRegion( sal_uInt32 nRects )
{
if ( !mpNSWindow )
return;
OSX_SALDATA_RUNINMAIN( BeginSetClipRegion( nRects ) )
// release old path
if( mrClippingPath )
{
CGPathRelease( mrClippingPath );
mrClippingPath = nullptr;
}
if( maClippingRects.size() > SAL_CLIPRECT_COUNT && nRects < maClippingRects.size() )
{
std::vector<CGRect>().swap(maClippingRects);
}
maClippingRects.clear();
maClippingRects.reserve( nRects );
}
void AquaSalFrame::UnionClipRegion(
tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight )
{
// #i113170# may not be the main thread if called from UNO API
SalData::ensureThreadAutoreleasePool();
if( nWidth && nHeight )
{
NSRect aRect = { { static_cast<CGFloat>(nX), static_cast<CGFloat>(nY) }, { static_cast<CGFloat>(nWidth), static_cast<CGFloat>(nHeight) } };
VCLToCocoa( aRect, false );
maClippingRects.push_back( CGRectMake(aRect.origin.x, aRect.origin.y, aRect.size.width, aRect.size.height) );
}
}
void AquaSalFrame::EndSetClipRegion()
{
if ( !mpNSWindow )
return;
OSX_SALDATA_RUNINMAIN( EndSetClipRegion() )
if( ! maClippingRects.empty() )
{
mrClippingPath = CGPathCreateMutable();
CGPathAddRects( mrClippingPath, nullptr, maClippingRects.data(), maClippingRects.size() );
}
if( mpNSView && mbShown )
[mpNSView setNeedsDisplay: YES];
[mpNSWindow setOpaque: (mrClippingPath != nullptr) ? NO : YES];
[mpNSWindow setBackgroundColor: [NSColor clearColor]];
// shadow is invalidated when view gets drawn again
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|