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
|
/* -*- 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 <config_feature_desktop.h>
#ifdef IOS
#include <premac.h>
#include <UIKit/UIKit.h>
#include <postmac.h>
#endif
#include <com/sun/star/frame/theGlobalEventBroadcaster.hpp>
#include <comphelper/lok.hxx>
#include <comphelper/scopeguard.hxx>
#include <comphelper/processfactory.hxx>
#include <officecfg/Office/Common.hxx>
#include <osl/diagnose.h>
#include <svdata.hxx>
#include <window.h>
#include <brdwin.hxx>
#include <rtl/bootstrap.hxx>
#include <rtl/strbuf.hxx>
#include <sal/log.hxx>
#include <vcl/abstdlg.hxx>
#include <vcl/accel.hxx>
#include <vcl/builder.hxx>
#include <vcl/layout.hxx>
#include <vcl/svapp.hxx>
#include <vcl/event.hxx>
#include <vcl/waitobj.hxx>
#include <vcl/wrkwin.hxx>
#include <vcl/toolkit/button.hxx>
#include <vcl/mnemonic.hxx>
#include <vcl/toolkit/dialog.hxx>
#include <vcl/dialoghelper.hxx>
#include <vcl/settings.hxx>
#include <vcl/virdev.hxx>
#include <vcl/weld.hxx>
#include <vcl/uitest/uiobject.hxx>
#include <vcl/uitest/logger.hxx>
#include <vcl/IDialogRenderable.hxx>
#include <messagedialog.hxx>
#include <salframe.hxx>
#include <iostream>
#include <utility>
static OString ImplGetDialogText( Dialog* pDialog )
{
OStringBuffer aErrorStr(OUStringToOString(
pDialog->GetText(), RTL_TEXTENCODING_UTF8));
OUString sMessage;
if (MessageDialog* pMessDialog = dynamic_cast<MessageDialog*>(pDialog))
{
sMessage = pMessDialog->get_primary_text();
}
if (!sMessage.isEmpty())
{
aErrorStr.append(", ");
aErrorStr.append(OUStringToOString(
sMessage, RTL_TEXTENCODING_UTF8));
}
return aErrorStr.makeStringAndClear();
}
static bool ImplIsMnemonicCtrl( vcl::Window* pWindow )
{
if( ! pWindow->GetSettings().GetStyleSettings().GetAutoMnemonic() )
return false;
if ( (pWindow->GetType() == WindowType::RADIOBUTTON) ||
(pWindow->GetType() == WindowType::CHECKBOX) ||
(pWindow->GetType() == WindowType::TRISTATEBOX) ||
(pWindow->GetType() == WindowType::PUSHBUTTON) )
return true;
if ( pWindow->GetType() == WindowType::FIXEDTEXT )
{
FixedText *pText = static_cast<FixedText*>(pWindow);
if (pText->get_mnemonic_widget())
return true;
//This is the legacy pre-layout logic which we retain
//until we can be sure we can remove it
if (pWindow->GetStyle() & WB_NOLABEL)
return false;
vcl::Window* pNextWindow = pWindow->GetWindow( GetWindowType::Next );
if ( !pNextWindow )
return false;
pNextWindow = pNextWindow->GetWindow( GetWindowType::Client );
return !(!(pNextWindow->GetStyle() & WB_TABSTOP) ||
(pNextWindow->GetType() == WindowType::FIXEDTEXT) ||
(pNextWindow->GetType() == WindowType::GROUPBOX) ||
(pNextWindow->GetType() == WindowType::RADIOBUTTON) ||
(pNextWindow->GetType() == WindowType::CHECKBOX) ||
(pNextWindow->GetType() == WindowType::TRISTATEBOX) ||
(pNextWindow->GetType() == WindowType::PUSHBUTTON));
}
return false;
}
// Called by native error dialog popup implementations
void ImplHideSplash()
{
ImplSVData* pSVData = ImplGetSVData();
if( pSVData->mpIntroWindow )
pSVData->mpIntroWindow->Hide();
}
vcl::Window * nextLogicalChildOfParent(const vcl::Window *pTopLevel, const vcl::Window *pChild)
{
const vcl::Window *pLastChild = pChild;
if (pChild->GetType() == WindowType::SCROLLWINDOW)
pChild = static_cast<const VclScrolledWindow*>(pChild)->get_child();
else if (isContainerWindow(*pChild))
pChild = pChild->GetWindow(GetWindowType::FirstChild);
else
pChild = pChild->GetWindow(GetWindowType::Next);
while (!pChild)
{
vcl::Window *pParent = pLastChild->GetParent();
if (!pParent)
return nullptr;
if (pParent == pTopLevel)
return nullptr;
pLastChild = pParent;
pChild = pParent->GetWindow(GetWindowType::Next);
}
if (isContainerWindow(*pChild))
pChild = nextLogicalChildOfParent(pTopLevel, pChild);
return const_cast<vcl::Window *>(pChild);
}
vcl::Window * prevLogicalChildOfParent(const vcl::Window *pTopLevel, const vcl::Window *pChild)
{
const vcl::Window *pLastChild = pChild;
if (pChild->GetType() == WindowType::SCROLLWINDOW)
pChild = static_cast<const VclScrolledWindow*>(pChild)->get_child();
else if (isContainerWindow(*pChild))
pChild = pChild->GetWindow(GetWindowType::LastChild);
else
pChild = pChild->GetWindow(GetWindowType::Prev);
while (!pChild)
{
vcl::Window *pParent = pLastChild->GetParent();
if (!pParent)
return nullptr;
if (pParent == pTopLevel)
return nullptr;
pLastChild = pParent;
pChild = pParent->GetWindow(GetWindowType::Prev);
}
if (isContainerWindow(*pChild))
pChild = prevLogicalChildOfParent(pTopLevel, pChild);
return const_cast<vcl::Window *>(pChild);
}
vcl::Window * firstLogicalChildOfParent(const vcl::Window *pTopLevel)
{
const vcl::Window *pChild = pTopLevel->GetWindow(GetWindowType::FirstChild);
if (pChild && isContainerWindow(*pChild))
pChild = nextLogicalChildOfParent(pTopLevel, pChild);
return const_cast<vcl::Window *>(pChild);
}
vcl::Window * lastLogicalChildOfParent(const vcl::Window *pTopLevel)
{
const vcl::Window *pChild = pTopLevel->GetWindow(GetWindowType::LastChild);
if (pChild && isContainerWindow(*pChild))
pChild = prevLogicalChildOfParent(pTopLevel, pChild);
return const_cast<vcl::Window *>(pChild);
}
void Accelerator::GenerateAutoMnemonicsOnHierarchy(const vcl::Window* pWindow)
{
MnemonicGenerator aMnemonicGenerator;
vcl::Window* pGetChild;
vcl::Window* pChild;
// register the assigned mnemonics
pGetChild = pWindow->GetWindow( GetWindowType::FirstChild );
while ( pGetChild )
{
pChild = pGetChild->ImplGetWindow();
aMnemonicGenerator.RegisterMnemonic( pChild->GetText() );
pGetChild = nextLogicalChildOfParent(pWindow, pGetChild);
}
// take the Controls of the dialog into account for TabPages
if ( pWindow->GetType() == WindowType::TABPAGE )
{
vcl::Window* pParent = pWindow->GetParent();
if (pParent && pParent->GetType() == WindowType::TABCONTROL )
pParent = pParent->GetParent();
if (pParent && (pParent->GetStyle() & (WB_DIALOGCONTROL | WB_NODIALOGCONTROL)) == WB_DIALOGCONTROL )
{
pGetChild = pParent->GetWindow( GetWindowType::FirstChild );
while ( pGetChild )
{
pChild = pGetChild->ImplGetWindow();
aMnemonicGenerator.RegisterMnemonic( pChild->GetText() );
pGetChild = nextLogicalChildOfParent(pWindow, pGetChild);
}
}
}
// assign mnemonics to Controls which have none
pGetChild = pWindow->GetWindow( GetWindowType::FirstChild );
while ( pGetChild )
{
pChild = pGetChild->ImplGetWindow();
if ( ImplIsMnemonicCtrl( pChild ) )
{
OUString aText = pChild->GetText();
OUString aNewText = aMnemonicGenerator.CreateMnemonic( aText );
if ( aText != aNewText )
pChild->SetText( aNewText );
}
pGetChild = nextLogicalChildOfParent(pWindow, pGetChild);
}
}
static VclButtonBox* getActionArea(Dialog const *pDialog)
{
VclButtonBox *pButtonBox = nullptr;
if (pDialog->isLayoutEnabled())
{
vcl::Window *pBox = pDialog->GetWindow(GetWindowType::FirstChild);
vcl::Window *pChild = pBox->GetWindow(GetWindowType::LastChild);
while (pChild)
{
pButtonBox = dynamic_cast<VclButtonBox*>(pChild);
if (pButtonBox)
break;
pChild = pChild->GetWindow(GetWindowType::Prev);
}
}
return pButtonBox;
}
static vcl::Window* getActionAreaButtonList(Dialog const *pDialog)
{
VclButtonBox* pButtonBox = getActionArea(pDialog);
if (pButtonBox)
return pButtonBox->GetWindow(GetWindowType::FirstChild);
return pDialog->GetWindow(GetWindowType::FirstChild);
}
static PushButton* ImplGetDefaultButton( Dialog const * pDialog )
{
vcl::Window* pChild = getActionAreaButtonList(pDialog);
while ( pChild )
{
if ( pChild->ImplIsPushButton() )
{
PushButton* pPushButton = static_cast<PushButton*>(pChild);
if ( pPushButton->ImplIsDefButton() )
return pPushButton;
}
pChild = pChild->GetWindow( GetWindowType::Next );
}
return nullptr;
}
static PushButton* ImplGetOKButton( Dialog const * pDialog )
{
vcl::Window* pChild = getActionAreaButtonList(pDialog);
while ( pChild )
{
if ( pChild->GetType() == WindowType::OKBUTTON )
return static_cast<PushButton*>(pChild);
pChild = pChild->GetWindow( GetWindowType::Next );
}
return nullptr;
}
static PushButton* ImplGetCancelButton( Dialog const * pDialog )
{
vcl::Window* pChild = getActionAreaButtonList(pDialog);
while ( pChild )
{
if ( pChild->GetType() == WindowType::CANCELBUTTON )
return static_cast<PushButton*>(pChild);
pChild = pChild->GetWindow( GetWindowType::Next );
}
return nullptr;
}
static void ImplMouseAutoPos( Dialog* pDialog )
{
MouseSettingsOptions nMouseOptions = pDialog->GetSettings().GetMouseSettings().GetOptions();
if ( nMouseOptions & MouseSettingsOptions::AutoCenterPos )
{
Size aSize = pDialog->GetOutputSizePixel();
pDialog->SetPointerPosPixel( Point( aSize.Width()/2, aSize.Height()/2 ) );
}
else if ( nMouseOptions & MouseSettingsOptions::AutoDefBtnPos )
{
vcl::Window* pWindow = ImplGetDefaultButton( pDialog );
if ( !pWindow )
pWindow = ImplGetOKButton( pDialog );
if ( !pWindow )
pWindow = ImplGetCancelButton( pDialog );
if ( !pWindow )
pWindow = pDialog;
Size aSize = pWindow->GetOutputSizePixel();
pWindow->SetPointerPosPixel( Point( aSize.Width()/2, aSize.Height()/2 ) );
}
}
struct DialogImpl
{
std::vector<VclPtr<PushButton>> maOwnedButtons;
std::map<VclPtr<vcl::Window>, short> maResponses;
long mnResult;
bool mbStartedModal;
VclAbstractDialog::AsyncContext maEndCtx;
Link<const CommandEvent&, bool> m_aPopupMenuHdl;
Link<void*, vcl::ILibreOfficeKitNotifier*> m_aInstallLOKNotifierHdl;
DialogImpl() : mnResult( -1 ), mbStartedModal( false ) {}
#ifndef NDEBUG
short get_response(vcl::Window *pWindow) const
{
auto aFind = maResponses.find(pWindow);
if (aFind != maResponses.end())
return aFind->second;
return RET_CANCEL;
}
#endif
~DialogImpl()
{
for (VclPtr<PushButton> & pOwnedButton : maOwnedButtons)
pOwnedButton.disposeAndClear();
}
};
void Dialog::disposeOwnedButtons()
{
for (VclPtr<PushButton> & pOwnedButton : mpDialogImpl->maOwnedButtons)
pOwnedButton.disposeAndClear();
}
void Dialog::ImplInitDialogData()
{
mpWindowImpl->mbDialog = true;
mbInExecute = false;
mbInSyncExecute = false;
mbInClose = false;
mbModalMode = false;
mpContentArea.clear();
mpActionArea.clear();
mnMousePositioned = 0;
mpDialogImpl.reset(new DialogImpl);
}
vcl::Window* Dialog::GetDefaultParent(WinBits nStyle)
{
vcl::Window* pParent = Application::GetDefDialogParent();
if (!pParent && !(nStyle & WB_SYSTEMWINDOW))
pParent = ImplGetSVData()->maFrameData.mpAppWin;
// If Parent is disabled, then we search for a modal dialog
// in this frame
if (pParent && (!pParent->IsInputEnabled() || pParent->IsInModalMode()))
{
ImplSVData* pSVData = ImplGetSVData();
auto& rExecuteDialogs = pSVData->mpWinData->mpExecuteDialogs;
auto it = std::find_if(rExecuteDialogs.rbegin(), rExecuteDialogs.rend(),
[&pParent](VclPtr<Dialog>& rDialogPtr) {
return pParent->ImplGetFirstOverlapWindow()->IsWindowOrChild(rDialogPtr, true) &&
rDialogPtr->IsReallyVisible() && rDialogPtr->IsEnabled() &&
rDialogPtr->IsInputEnabled() && !rDialogPtr->IsInModalMode(); });
if (it != rExecuteDialogs.rend())
pParent = it->get();
}
return pParent;
}
VclPtr<vcl::Window> Dialog::AddBorderWindow(vcl::Window* pParent, WinBits nStyle)
{
VclPtrInstance<ImplBorderWindow> pBorderWin( pParent, nStyle, BorderWindowStyle::Frame );
ImplInit( pBorderWin, nStyle & ~WB_BORDER, nullptr );
pBorderWin->mpWindowImpl->mpClientWindow = this;
pBorderWin->GetBorder( mpWindowImpl->mnLeftBorder, mpWindowImpl->mnTopBorder, mpWindowImpl->mnRightBorder, mpWindowImpl->mnBottomBorder );
mpWindowImpl->mpBorderWindow = pBorderWin;
mpWindowImpl->mpRealParent = pParent;
return pBorderWin;
}
void Dialog::ImplInitDialog( vcl::Window* pParent, WinBits nStyle, InitFlag eFlag )
{
SystemWindowFlags nSysWinMode = Application::GetSystemWindowMode();
if ( !(nStyle & WB_NODIALOGCONTROL) )
nStyle |= WB_DIALOGCONTROL;
nStyle |= WB_ROLLABLE;
// Now, all Dialogs are per default system windows !!!
nStyle |= WB_SYSTEMWINDOW;
if (InitFlag::NoParent == eFlag)
{
pParent = nullptr;
}
else if (!pParent) // parent is NULL: get the default Dialog parent
{
pParent = Dialog::GetDefaultParent(nStyle);
}
if ( !pParent || (nStyle & WB_SYSTEMWINDOW) ||
(pParent->mpWindowImpl->mpFrameData->mbNeedSysWindow && !(nSysWinMode & SystemWindowFlags::NOAUTOMODE)) ||
(nSysWinMode & SystemWindowFlags::DIALOG) )
{
// create window with a small border ?
if ((nStyle & WB_ALLOWMENUBAR) || ((nStyle & (WB_BORDER | WB_NOBORDER | WB_MOVEABLE | WB_SIZEABLE | WB_CLOSEABLE)) == WB_BORDER))
{
AddBorderWindow(pParent, nStyle);
}
else
{
mpWindowImpl->mbFrame = true;
mpWindowImpl->mbOverlapWin = true;
ImplInit( pParent, (nStyle & (WB_MOVEABLE | WB_SIZEABLE | WB_ROLLABLE | WB_STANDALONE)) | WB_CLOSEABLE, nullptr );
// Now set all style bits
mpWindowImpl->mnStyle = nStyle;
}
}
else
{
VclPtrInstance<ImplBorderWindow> pBorderWin( pParent, nStyle, BorderWindowStyle::Overlap );
ImplInit( pBorderWin, nStyle & ~WB_BORDER, nullptr );
pBorderWin->mpWindowImpl->mpClientWindow = this;
pBorderWin->GetBorder( mpWindowImpl->mnLeftBorder, mpWindowImpl->mnTopBorder, mpWindowImpl->mnRightBorder, mpWindowImpl->mnBottomBorder );
mpWindowImpl->mpBorderWindow = pBorderWin;
mpWindowImpl->mpRealParent = pParent;
}
SetActivateMode( ActivateModeFlags::GrabFocus );
ImplInitSettings();
}
void Dialog::ApplySettings(vcl::RenderContext& rRenderContext)
{
if (IsControlBackground())
{
// user override
SetBackground(GetControlBackground());
}
else if (rRenderContext.IsNativeControlSupported(ControlType::WindowBackground, ControlPart::BackgroundDialog))
{
// NWF background
mpWindowImpl->mnNativeBackground = ControlPart::BackgroundDialog;
EnableChildTransparentMode();
}
else
{
// fallback to settings color
rRenderContext.SetBackground(GetSettings().GetStyleSettings().GetDialogColor());
}
}
void Dialog::ImplInitSettings()
{
// user override
if (IsControlBackground())
SetBackground(GetControlBackground());
// NWF background
else if( IsNativeControlSupported(ControlType::WindowBackground, ControlPart::BackgroundDialog))
{
mpWindowImpl->mnNativeBackground = ControlPart::BackgroundDialog;
EnableChildTransparentMode();
}
// fallback to settings color
else
SetBackground(GetSettings().GetStyleSettings().GetDialogColor());
}
void Dialog::ImplLOKNotifier(vcl::Window* pParent)
{
if (comphelper::LibreOfficeKit::isActive() && pParent)
{
if (VclPtr<vcl::Window> pWin = pParent->GetParentWithLOKNotifier())
{
SetLOKNotifier(pWin->GetLOKNotifier());
}
}
}
Dialog::Dialog( WindowType nType )
: SystemWindow( nType )
, mnInitFlag(InitFlag::Default)
{
ImplInitDialogData();
}
void VclBuilderContainer::disposeBuilder()
{
if (m_pUIBuilder)
m_pUIBuilder->disposeBuilder();
}
OUString VclBuilderContainer::getUIRootDir()
{
OUString sShareLayer("$BRAND_BASE_DIR/$BRAND_SHARE_SUBDIR/config/soffice.cfg/");
rtl::Bootstrap::expandMacros(sShareLayer);
return sShareLayer;
}
//we can't change sizeable after the fact, so need to defer until we know and then
//do the init. Find the real parent stashed in mpDialogParent.
void Dialog::doDeferredInit(WinBits nBits)
{
VclPtr<vcl::Window> pParent = mpDialogParent;
mpDialogParent = nullptr;
ImplInitDialog(pParent, nBits | WB_BORDER, mnInitFlag);
mbIsDeferredInit = false;
}
Dialog::Dialog(vcl::Window* pParent, const OUString& rID, const OUString& rUIXMLDescription)
: SystemWindow(WindowType::DIALOG)
, mnInitFlag(InitFlag::Default)
{
ImplLOKNotifier(pParent);
ImplInitDialogData();
loadUI(pParent, OUStringToOString(rID, RTL_TEXTENCODING_UTF8), rUIXMLDescription);
}
Dialog::Dialog(vcl::Window* pParent, WinBits nStyle, InitFlag eFlag)
: SystemWindow(WindowType::DIALOG)
, mnInitFlag(eFlag)
{
ImplLOKNotifier(pParent);
ImplInitDialogData();
ImplInitDialog( pParent, nStyle, eFlag );
}
void Dialog::set_action_area(VclButtonBox* pBox)
{
mpActionArea.set(pBox);
if (pBox)
{
const DialogStyle& rDialogStyle =
GetSettings().GetStyleSettings().GetDialogStyle();
pBox->set_border_width(rDialogStyle.action_area_border);
}
}
void Dialog::set_content_area(VclBox* pBox)
{
mpContentArea.set(pBox);
}
void Dialog::settingOptimalLayoutSize(Window *pBox)
{
const DialogStyle& rDialogStyle =
GetSettings().GetStyleSettings().GetDialogStyle();
VclBox * pBox2 = static_cast<VclBox*>(pBox);
pBox2->set_border_width(rDialogStyle.content_area_border);
}
Dialog::~Dialog()
{
disposeOnce();
}
void Dialog::dispose()
{
mpDialogImpl.reset();
RemoveFromDlgList();
mpActionArea.clear();
mpContentArea.clear();
css::uno::Reference< css::uno::XComponentContext > xContext(
comphelper::getProcessComponentContext() );
css::uno::Reference<css::frame::XGlobalEventBroadcaster> xEventBroadcaster(css::frame::theGlobalEventBroadcaster::get(xContext), css::uno::UNO_SET_THROW);
css::document::DocumentEvent aObject;
aObject.EventName = "DialogClosed";
xEventBroadcaster->documentEventOccured(aObject);
UITestLogger::getInstance().log("Close Dialog");
if (comphelper::LibreOfficeKit::isActive())
{
if(const vcl::ILibreOfficeKitNotifier* pNotifier = GetLOKNotifier())
{
pNotifier->notifyWindow(GetLOKWindowId(), "close");
ReleaseLOKNotifier();
}
}
SystemWindow::dispose();
}
IMPL_LINK_NOARG(Dialog, ImplAsyncCloseHdl, void*, void)
{
Close();
}
bool Dialog::EventNotify( NotifyEvent& rNEvt )
{
// first call the base class due to Tab control
bool bRet = SystemWindow::EventNotify( rNEvt );
if ( !bRet )
{
if ( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
{
const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
vcl::KeyCode aKeyCode = pKEvt->GetKeyCode();
sal_uInt16 nKeyCode = aKeyCode.GetCode();
if ( (nKeyCode == KEY_ESCAPE) &&
((GetStyle() & WB_CLOSEABLE) || ImplGetCancelButton( this ) || ImplGetOKButton( this )) )
{
// #i89505# for the benefit of slightly mentally challenged implementations
// like e.g. SfxModelessDialog which destroy themselves inside Close()
// post this Close asynchronous so we can leave our key handler before
// we get destroyed
PostUserEvent( LINK( this, Dialog, ImplAsyncCloseHdl ), nullptr, true);
return true;
}
}
else if ( rNEvt.GetType() == MouseNotifyEvent::GETFOCUS )
{
// make sure the dialog is still modal
// changing focus between application frames may
// have re-enabled input for our parent
if( mbInExecute && mbModalMode )
{
ImplSetModalInputMode( false );
ImplSetModalInputMode( true );
// #93022# def-button might have changed after show
if( !mnMousePositioned )
{
mnMousePositioned = 1;
ImplMouseAutoPos( this );
}
}
}
}
return bRet;
}
//What we really want here is something that gives the available width and
//height of a users screen, taking away the space taken up the OS
//taskbar, menus, etc.
Size bestmaxFrameSizeForScreenSize(const Size &rScreenSize)
{
#ifndef IOS
long w = rScreenSize.Width();
if (w <= 800)
w -= 15;
else if (w <= 1024)
w -= 65;
else
w -= 115;
long h = rScreenSize.Height();
if (h <= 768)
h -= 50;
else
h -= 100;
return Size(std::max<long>(w, 640 - 15),
std::max<long>(h, 480 - 50));
#else
// Don't bother with ancient magic numbers of unclear relevance on non-desktop apps anyway. It
// seems that at least currently in the iOS app, this function is called just once per dialog,
// with a rScreenSize parameter of 1x1 (!). This would lead to always returning 625x430 which is
// a bit random and needlessly small on an iPad at least. We want something that closely will
// just fit on the display in either orientation.
// We ignore the rScreenSize as it will be the dummy 1x1 from iosinst.cxx (see "Totally wrong of course").
(void) rScreenSize;
const int n = std::min<CGFloat>([[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height);
return Size(n-10, n-10);
#endif
}
void Dialog::SetPopupMenuHdl(const Link<const CommandEvent&, bool>& rLink)
{
mpDialogImpl->m_aPopupMenuHdl = rLink;
}
void Dialog::SetInstallLOKNotifierHdl(const Link<void*, vcl::ILibreOfficeKitNotifier*>& rLink)
{
mpDialogImpl->m_aInstallLOKNotifierHdl = rLink;
}
void Dialog::StateChanged( StateChangedType nType )
{
if (nType == StateChangedType::InitShow)
{
DoInitialLayout();
const bool bKitActive = comphelper::LibreOfficeKit::isActive();
if (bKitActive)
{
std::vector<vcl::LOKPayloadItem> aItems;
aItems.emplace_back("type", "dialog");
aItems.emplace_back("size", GetSizePixel().toString());
if (!GetText().isEmpty())
aItems.emplace_back("title", GetText().toUtf8());
if (const vcl::ILibreOfficeKitNotifier* pNotifier = GetLOKNotifier())
{
pNotifier->notifyWindow(GetLOKWindowId(), "created", aItems);
pNotifier->notifyWindow(GetLOKWindowId(), "created", aItems);
}
else
{
vcl::ILibreOfficeKitNotifier* pViewShell = mpDialogImpl->m_aInstallLOKNotifierHdl.Call(nullptr);
if (pViewShell)
{
SetLOKNotifier(pViewShell);
pViewShell->notifyWindow(GetLOKWindowId(), "created", aItems);
}
}
}
if ( !HasChildPathFocus() || HasFocus() )
GrabFocusToFirstControl();
if ( !(GetStyle() & WB_CLOSEABLE) )
{
if ( ImplGetCancelButton( this ) || ImplGetOKButton( this ) )
{
if ( ImplGetBorderWindow() )
static_cast<ImplBorderWindow*>(ImplGetBorderWindow())->SetCloseButton();
}
}
ImplMouseAutoPos( this );
}
else if (nType == StateChangedType::Text)
{
if (const vcl::ILibreOfficeKitNotifier* pNotifier = GetLOKNotifier())
{
std::vector<vcl::LOKPayloadItem> aPayload;
aPayload.emplace_back("title", GetText().toUtf8());
pNotifier->notifyWindow(GetLOKWindowId(), "title_changed", aPayload);
}
}
SystemWindow::StateChanged( nType );
if (nType == StateChangedType::ControlBackground)
{
ImplInitSettings();
Invalidate();
}
if (!mbModalMode && nType == StateChangedType::Visible)
{
if (const vcl::ILibreOfficeKitNotifier* pNotifier = GetLOKNotifier())
{
std::vector<vcl::LOKPayloadItem> aPayload;
aPayload.emplace_back("title", GetText().toUtf8());
pNotifier->notifyWindow(GetLOKWindowId(), IsVisible()? OUString("show"): OUString("hide"), aPayload);
}
}
}
void Dialog::DataChanged( const DataChangedEvent& rDCEvt )
{
SystemWindow::DataChanged( rDCEvt );
if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
(rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
{
ImplInitSettings();
Invalidate();
}
}
bool Dialog::Close()
{
VclPtr<vcl::Window> xWindow = this;
CallEventListeners( VclEventId::WindowClose );
if ( xWindow->IsDisposed() )
return false;
if ( mpWindowImpl->mxWindowPeer.is() && IsCreatedWithToolkit() && !IsInExecute() )
return false;
// If there's a cancel button with a custom handler, then always give it a chance to
// handle Dialog::Close
PushButton* pCustomCancelButton;
PushButton* pCancelButton = dynamic_cast<PushButton*>(get_widget_for_response(RET_CANCEL));
if (!mbInClose && pCancelButton && pCancelButton->GetClickHdl().IsSet())
pCustomCancelButton = pCancelButton;
else
pCustomCancelButton = nullptr;
mbInClose = true;
if (pCustomCancelButton)
{
pCustomCancelButton->Click();
if (xWindow->IsDisposed())
return true;
mbInClose = false;
return false;
}
if ( !(GetStyle() & WB_CLOSEABLE) )
{
bool bRet = true;
PushButton* pButton = ImplGetCancelButton( this );
if ( pButton )
pButton->Click();
else
{
pButton = ImplGetOKButton( this );
if ( pButton )
pButton->Click();
else
bRet = false;
}
if ( xWindow->IsDisposed() )
return true;
return bRet;
}
if (IsInExecute() || mpDialogImpl->maEndCtx.isSet())
{
EndDialog();
mbInClose = false;
return true;
}
else
{
mbInClose = false;
return SystemWindow::Close();
}
}
bool Dialog::ImplStartExecute()
{
setDeferredProperties();
if (IsInExecute() || mpDialogImpl->maEndCtx.isSet())
{
#ifdef DBG_UTIL
SAL_WARN( "vcl", "Dialog::StartExecuteModal() is called in Dialog::StartExecuteModal(): "
<< ImplGetDialogText(this) );
#endif
return false;
}
ImplSVData* pSVData = ImplGetSVData();
const bool bKitActive = comphelper::LibreOfficeKit::isActive();
const bool bModal = GetType() != WindowType::MODELESSDIALOG;
if (bModal)
{
if (bKitActive && !GetLOKNotifier())
SetLOKNotifier(mpDialogImpl->m_aInstallLOKNotifierHdl.Call(nullptr));
switch ( Application::GetDialogCancelMode() )
{
case DialogCancelMode::Off:
break;
case DialogCancelMode::Silent:
if (bModal && GetLOKNotifier())
{
// check if there's already some dialog being ::Execute()d
const bool bDialogExecuting = std::any_of(pSVData->mpWinData->mpExecuteDialogs.begin(),
pSVData->mpWinData->mpExecuteDialogs.end(),
[](const Dialog* pDialog) {
return pDialog->IsInSyncExecute();
});
if (!(bDialogExecuting && IsInSyncExecute()))
break;
else
SAL_WARN("lok.dialog", "Dialog \"" << ImplGetDialogText(this) << "\" is being synchronously executed over an existing synchronously executing dialog.");
}
SAL_INFO(
"vcl",
"Dialog \"" << ImplGetDialogText(this)
<< "\"cancelled in silent mode");
return false;
default: // default cannot happen
case DialogCancelMode::Fatal:
std::abort();
}
#ifdef DBG_UTIL
vcl::Window* pParent = GetParent();
if ( pParent )
{
pParent = pParent->ImplGetFirstOverlapWindow();
SAL_WARN_IF( !pParent->IsReallyVisible(), "vcl",
"Dialog::StartExecuteModal() - Parent not visible" );
SAL_WARN_IF( !pParent->IsInputEnabled(), "vcl",
"Dialog::StartExecuteModal() - Parent input disabled, use another parent to ensure modality!" );
SAL_WARN_IF( pParent->IsInModalMode(), "vcl",
"Dialog::StartExecuteModal() - Parent already modally disabled, use another parent to ensure modality!" );
}
#endif
// link all dialogs which are being executed
pSVData->mpWinData->mpExecuteDialogs.push_back(this);
// stop capturing, in order to have control over the dialog
if (pSVData->mpWinData->mpTrackWin)
pSVData->mpWinData->mpTrackWin->EndTracking(TrackingEventFlags::Cancel);
if (pSVData->mpWinData->mpCaptureWin)
pSVData->mpWinData->mpCaptureWin->ReleaseMouse();
EnableInput();
}
mbInExecute = true;
// no real modality in LibreOfficeKit
if (!bKitActive && bModal)
SetModalInputMode(true);
// FIXME: no layouting, workaround some clipping issues
ImplAdjustNWFSizes();
css::uno::Reference< css::uno::XComponentContext > xContext(
comphelper::getProcessComponentContext());
bool bForceFocusAndToFront(officecfg::Office::Common::View::NewDocumentHandling::ForceFocusAndToFront::get(xContext));
ShowFlags showFlags = bForceFocusAndToFront ? ShowFlags::ForegroundTask : ShowFlags::NONE;
Show(true, showFlags);
if (bModal)
pSVData->maAppData.mnModalMode++;
css::uno::Reference<css::frame::XGlobalEventBroadcaster> xEventBroadcaster(
css::frame::theGlobalEventBroadcaster::get(xContext), css::uno::UNO_SET_THROW);
css::document::DocumentEvent aObject;
aObject.EventName = "DialogExecute";
xEventBroadcaster->documentEventOccured(aObject);
if (bModal)
UITestLogger::getInstance().log("Open Modal " + get_id());
else
UITestLogger::getInstance().log("Open Modeless " + get_id());
if (comphelper::LibreOfficeKit::isActive())
{
if (const vcl::ILibreOfficeKitNotifier* pNotifier = GetLOKNotifier())
{
// Dialog boxes don't get the Resize call and they
// can have invalid size at 'created' message above.
// If there is no difference, the client should detect it and ignore us,
// otherwise, this should make sure that the window has the correct size.
std::vector<vcl::LOKPayloadItem> aItems;
aItems.emplace_back("size", GetSizePixel().toString());
pNotifier->notifyWindow(GetLOKWindowId(), "size_changed", aItems);
}
}
return true;
}
void Dialog::ImplEndExecuteModal()
{
ImplSVData* pSVData = ImplGetSVData();
pSVData->maAppData.mnModalMode--;
}
short Dialog::Execute()
{
// Once the Android app is based on same idea as the iOS one currently
// being developed, no conditional should be needed here. Until then,
// play it safe.
#if HAVE_FEATURE_DESKTOP || defined IOS
VclPtr<vcl::Window> xWindow = this;
mbInSyncExecute = true;
comphelper::ScopeGuard aGuard([&]() {
mbInSyncExecute = false;
});
if ( !ImplStartExecute() )
return 0;
// Yield util EndDialog is called or dialog gets destroyed
// (the latter should not happen, but better safe than sorry
while ( !xWindow->IsDisposed() && mbInExecute )
Application::Yield();
ImplEndExecuteModal();
#ifdef DBG_UTIL
assert (!mpDialogParent || !mpDialogParent->IsDisposed());
#endif
if ( !xWindow->IsDisposed() )
xWindow.clear();
else
{
OSL_FAIL( "Dialog::Execute() - Dialog destroyed in Execute()" );
}
long nRet = mpDialogImpl->mnResult;
mpDialogImpl->mnResult = -1;
return static_cast<short>(nRet);
#else
return RET_OK;
#endif
}
// virtual
bool Dialog::StartExecuteAsync( VclAbstractDialog::AsyncContext &rCtx )
{
const bool bModal = GetType() != WindowType::MODELESSDIALOG;
if (!ImplStartExecute())
{
rCtx.mxOwner.disposeAndClear();
rCtx.mxOwnerDialogController.reset();
rCtx.mxOwnerSelf.reset();
return false;
}
mpDialogImpl->maEndCtx = rCtx;
mpDialogImpl->mbStartedModal = bModal;
return true;
}
void Dialog::RemoveFromDlgList()
{
ImplSVData* pSVData = ImplGetSVData();
auto& rExecuteDialogs = pSVData->mpWinData->mpExecuteDialogs;
// remove dialog from the list of dialogs which are being executed
rExecuteDialogs.erase(std::remove_if(rExecuteDialogs.begin(), rExecuteDialogs.end(), [this](VclPtr<Dialog>& dialog){ return dialog.get() == this; }), rExecuteDialogs.end());
}
void Dialog::EndDialog( long nResult )
{
if (!mbInExecute || IsDisposed())
return;
const bool bModal = GetType() != WindowType::MODELESSDIALOG;
Hide();
if (comphelper::LibreOfficeKit::isActive())
{
if(const vcl::ILibreOfficeKitNotifier* pNotifier = GetLOKNotifier())
{
pNotifier->notifyWindow(GetLOKWindowId(), "close");
ReleaseLOKNotifier();
}
}
if (bModal)
{
SetModalInputMode(false);
RemoveFromDlgList();
// set focus to previous modal dialog if it is modal for
// the same frame parent (or NULL)
ImplSVData* pSVData = ImplGetSVData();
if (!pSVData->mpWinData->mpExecuteDialogs.empty())
{
VclPtr<Dialog> pPrevious = pSVData->mpWinData->mpExecuteDialogs.back();
vcl::Window* pFrameParent = ImplGetFrameWindow()->ImplGetParent();
vcl::Window* pPrevFrameParent = pPrevious->ImplGetFrameWindow()? pPrevious->ImplGetFrameWindow()->ImplGetParent(): nullptr;
if( ( !pFrameParent && !pPrevFrameParent ) ||
( pFrameParent && pPrevFrameParent && pFrameParent->ImplGetFrame() == pPrevFrameParent->ImplGetFrame() )
)
{
pPrevious->GrabFocus();
}
}
}
mpDialogImpl->mnResult = nResult;
if ( mpDialogImpl->mbStartedModal )
ImplEndExecuteModal();
if ( mpDialogImpl && mpDialogImpl->maEndCtx.isSet() )
{
auto fn = std::move(mpDialogImpl->maEndCtx.maEndDialogFn);
// std::move leaves maEndDialogFn in a valid state with unspecified
// value. For the SwSyncBtnDlg case gcc and msvc left maEndDialogFn
// unset, but clang left maEndDialogFn at its original value, keeping
// an extra reference to the DialogController in its lambda giving
// an inconsistent lifecycle for the dialog. Force it to be unset.
mpDialogImpl->maEndCtx.maEndDialogFn = nullptr;
fn(nResult);
}
if ( mpDialogImpl && mpDialogImpl->mbStartedModal )
{
mpDialogImpl->mbStartedModal = false;
mpDialogImpl->mnResult = -1;
}
mbInExecute = false;
if ( mpDialogImpl )
{
// Destroy ourselves (if we have a context with VclPtr owner)
std::shared_ptr<weld::DialogController> xOwnerDialogController = std::move(mpDialogImpl->maEndCtx.mxOwnerDialogController);
std::shared_ptr<weld::Dialog> xOwnerSelf = std::move(mpDialogImpl->maEndCtx.mxOwnerSelf);
mpDialogImpl->maEndCtx.mxOwner.disposeAndClear();
xOwnerDialogController.reset();
xOwnerSelf.reset();
}
}
namespace vcl
{
void EndAllDialogs( vcl::Window const * pParent )
{
ImplSVData* pSVData = ImplGetSVData();
auto& rExecuteDialogs = pSVData->mpWinData->mpExecuteDialogs;
for (auto it = rExecuteDialogs.rbegin(); it != rExecuteDialogs.rend(); ++it)
{
if (!pParent || pParent->IsWindowOrChild(*it, true))
{
(*it)->EndDialog();
(*it)->PostUserEvent(Link<void*, void>());
}
}
}
void EnableDialogInput(vcl::Window* pWindow)
{
if (Dialog* pDialog = dynamic_cast<Dialog*>(pWindow))
{
pDialog->EnableInput();
}
}
bool CloseDialog(vcl::Window* pWindow)
{
if (Dialog* pDialog = dynamic_cast<Dialog*>(pWindow))
{
pDialog->Close();
return true;
}
return false;
}
}
void Dialog::SetModalInputMode( bool bModal )
{
if ( bModal == mbModalMode )
return;
ImplGetFrame()->SetModal(bModal);
if (GetParent())
{
SalFrame* pFrame = GetParent()->ImplGetFrame();
pFrame->NotifyModalHierarchy(bModal);
}
ImplSetModalInputMode(bModal);
}
void Dialog::ImplSetModalInputMode( bool bModal )
{
if ( bModal == mbModalMode )
return;
// previously Execute()'d dialog - the one below the top-most one
VclPtr<Dialog> pPrevious;
ImplSVData* pSVData = ImplGetSVData();
auto& rExecuteDialogs = pSVData->mpWinData->mpExecuteDialogs;
if (rExecuteDialogs.size() > 1)
pPrevious = rExecuteDialogs[rExecuteDialogs.size() - 2];
mbModalMode = bModal;
if ( bModal )
{
// Disable the prev Modal Dialog, because our dialog must close at first,
// before the other dialog can be closed (because the other dialog
// is on stack since our dialog returns)
if (pPrevious && !pPrevious->IsWindowOrChild(this, true))
pPrevious->EnableInput(false, this);
// determine next overlap dialog parent
vcl::Window* pParent = GetParent();
if ( pParent )
{
// #103716# dialogs should always be modal to the whole frame window
// #115933# disable the whole frame hierarchy, useful if our parent
// is a modeless dialog
mpDialogParent = pParent->mpWindowImpl->mpFrameWindow;
mpDialogParent->IncModalCount();
}
}
else
{
if ( mpDialogParent )
{
// #115933# re-enable the whole frame hierarchy again (see above)
// note that code in getfocus assures that we do not accidentally enable
// windows that were disabled before
mpDialogParent->DecModalCount();
}
// Enable the prev Modal Dialog
if (pPrevious && !pPrevious->IsWindowOrChild(this, true))
{
pPrevious->EnableInput(true, this);
// ensure continued modality of prev dialog
// do not change modality counter
// #i119994# need find the last modal dialog before reactive it
if (pPrevious->IsModalInputMode() || !pPrevious->IsWindowOrChild(this, true))
{
pPrevious->ImplSetModalInputMode(false);
pPrevious->ImplSetModalInputMode(true);
}
}
}
}
void Dialog::GrabFocusToFirstControl()
{
vcl::Window* pFocusControl;
// find focus control, even if the dialog has focus
if ( HasFocus() )
pFocusControl = nullptr;
else
{
// prefer a child window which had focus before
pFocusControl = ImplGetFirstOverlapWindow()->mpWindowImpl->mpLastFocusWindow;
// find the control out of the dialog control
if ( pFocusControl )
pFocusControl = ImplFindDlgCtrlWindow( pFocusControl );
}
// no control had the focus before or the control is not
// part of the tab-control, now give focus to the
// first control in the tab-control
if ( !pFocusControl ||
!(pFocusControl->GetStyle() & WB_TABSTOP) ||
!isVisibleInLayout(pFocusControl) ||
!isEnabledInLayout(pFocusControl) || !pFocusControl->IsInputEnabled() )
{
pFocusControl = ImplGetDlgWindow( 0, GetDlgWindowType::First );
}
if ( pFocusControl )
pFocusControl->ImplControlFocus( GetFocusFlags::Init );
}
void Dialog::GetDrawWindowBorder( sal_Int32& rLeftBorder, sal_Int32& rTopBorder, sal_Int32& rRightBorder, sal_Int32& rBottomBorder ) const
{
ScopedVclPtrInstance<ImplBorderWindow> aImplWin( static_cast<vcl::Window*>(const_cast<Dialog *>(this)), WB_BORDER|WB_STDWORK, BorderWindowStyle::Overlap );
aImplWin->GetBorder( rLeftBorder, rTopBorder, rRightBorder, rBottomBorder );
}
void Dialog::Draw( OutputDevice* pDev, const Point& rPos, DrawFlags )
{
Point aPos = pDev->LogicToPixel( rPos );
Size aSize = GetSizePixel();
Wallpaper aWallpaper = GetBackground();
if ( !aWallpaper.IsBitmap() )
ImplInitSettings();
pDev->Push();
pDev->SetMapMode();
pDev->SetLineColor();
if ( aWallpaper.IsBitmap() )
pDev->DrawBitmapEx( aPos, aSize, aWallpaper.GetBitmap() );
else
{
pDev->SetFillColor( aWallpaper.GetColor() );
pDev->DrawRect( tools::Rectangle( aPos, aSize ) );
}
if (!( GetStyle() & WB_NOBORDER ))
{
ScopedVclPtrInstance< ImplBorderWindow > aImplWin( this, WB_BORDER|WB_STDWORK, BorderWindowStyle::Overlap );
aImplWin->SetText( GetText() );
aImplWin->setPosSizePixel( aPos.X(), aPos.Y(), aSize.Width(), aSize.Height() );
aImplWin->SetDisplayActive( true );
aImplWin->InitView();
aImplWin->Draw( pDev, aPos );
}
pDev->Pop();
}
void Dialog::queue_resize(StateChangedType eReason)
{
if (IsInClose())
return;
SystemWindow::queue_resize(eReason);
}
void Dialog::Resize()
{
SystemWindow::Resize();
if (comphelper::LibreOfficeKit::isDialogPainting())
return;
if (const vcl::ILibreOfficeKitNotifier* pNotifier = GetLOKNotifier())
{
std::vector<vcl::LOKPayloadItem> aItems;
aItems.emplace_back("size", GetSizePixel().toString());
pNotifier->notifyWindow(GetLOKWindowId(), "size_changed", aItems);
}
}
bool Dialog::set_property(const OString &rKey, const OUString &rValue)
{
if (rKey == "border-width")
set_border_width(rValue.toInt32());
else
return SystemWindow::set_property(rKey, rValue);
return true;
}
FactoryFunction Dialog::GetUITestFactory() const
{
return DialogUIObject::create;
}
IMPL_LINK(Dialog, ResponseHdl, Button*, pButton, void)
{
auto aFind = mpDialogImpl->maResponses.find(pButton);
if (aFind == mpDialogImpl->maResponses.end())
return;
short nResponse = aFind->second;
if (nResponse == RET_HELP)
{
vcl::Window* pFocusWin = Application::GetFocusWindow();
if (!pFocusWin)
pFocusWin = pButton;
HelpEvent aEvt(pFocusWin->GetPointerPosPixel(), HelpEventMode::CONTEXT);
pFocusWin->RequestHelp(aEvt);
return;
}
EndDialog(nResponse);
}
void Dialog::add_button(PushButton* pButton, int response, bool bTransferOwnership)
{
if (bTransferOwnership)
mpDialogImpl->maOwnedButtons.push_back(pButton);
mpDialogImpl->maResponses[pButton] = response;
switch (pButton->GetType())
{
case WindowType::PUSHBUTTON:
{
if (!pButton->GetClickHdl().IsSet())
pButton->SetClickHdl(LINK(this, Dialog, ResponseHdl));
break;
}
//insist that the response ids match the default actions for those
//widgets, and leave their default handlers in place
case WindowType::OKBUTTON:
assert(mpDialogImpl->get_response(pButton) == RET_OK);
break;
case WindowType::CANCELBUTTON:
assert(mpDialogImpl->get_response(pButton) == RET_CANCEL || mpDialogImpl->get_response(pButton) == RET_CLOSE);
break;
case WindowType::HELPBUTTON:
assert(mpDialogImpl->get_response(pButton) == RET_HELP);
break;
default:
SAL_WARN("vcl.layout", "The type of widget " <<
pButton->GetHelpId() << " is currently not handled");
break;
}
}
vcl::Window* Dialog::get_widget_for_response(int response)
{
//copy explicit responses
std::map<VclPtr<vcl::Window>, short> aResponses(mpDialogImpl->maResponses);
if (mpActionArea)
{
//add implicit responses
for (vcl::Window* pChild = mpActionArea->GetWindow(GetWindowType::FirstChild); pChild;
pChild = pChild->GetWindow(GetWindowType::Next))
{
if (aResponses.find(pChild) != aResponses.end())
continue;
switch (pChild->GetType())
{
case WindowType::OKBUTTON:
aResponses[pChild] = RET_OK;
break;
case WindowType::CANCELBUTTON:
aResponses[pChild] = RET_CANCEL;
break;
case WindowType::HELPBUTTON:
aResponses[pChild] = RET_HELP;
break;
default:
break;
}
}
}
for (const auto& a : aResponses)
{
if (a.second == response)
return a.first;
}
return nullptr;
}
int Dialog::get_default_response() const
{
//copy explicit responses
std::map<VclPtr<vcl::Window>, short> aResponses(mpDialogImpl->maResponses);
if (mpActionArea)
{
//add implicit responses
for (vcl::Window* pChild = mpActionArea->GetWindow(GetWindowType::FirstChild); pChild;
pChild = pChild->GetWindow(GetWindowType::Next))
{
if (aResponses.find(pChild) != aResponses.end())
continue;
switch (pChild->GetType())
{
case WindowType::OKBUTTON:
aResponses[pChild] = RET_OK;
break;
case WindowType::CANCELBUTTON:
aResponses[pChild] = RET_CANCEL;
break;
case WindowType::HELPBUTTON:
aResponses[pChild] = RET_HELP;
break;
default:
break;
}
}
}
for (const auto& a : aResponses)
{
if (a.first->GetStyle() & WB_DEFBUTTON)
{
return a.second;
}
}
return RET_CANCEL;
}
void Dialog::set_default_response(int response)
{
//copy explicit responses
std::map<VclPtr<vcl::Window>, short> aResponses(mpDialogImpl->maResponses);
if (mpActionArea)
{
//add implicit responses
for (vcl::Window* pChild = mpActionArea->GetWindow(GetWindowType::FirstChild); pChild;
pChild = pChild->GetWindow(GetWindowType::Next))
{
if (aResponses.find(pChild) != aResponses.end())
continue;
switch (pChild->GetType())
{
case WindowType::OKBUTTON:
aResponses[pChild] = RET_OK;
break;
case WindowType::CANCELBUTTON:
aResponses[pChild] = RET_CANCEL;
break;
case WindowType::HELPBUTTON:
aResponses[pChild] = RET_HELP;
break;
default:
break;
}
}
}
for (auto& a : aResponses)
{
if (a.second == response)
{
a.first->SetStyle(a.first->GetStyle() | WB_DEFBUTTON);
a.first->GrabFocus();
}
else
{
a.first->SetStyle(a.first->GetStyle() & ~WB_DEFBUTTON);
}
}
}
VclBuilderContainer::VclBuilderContainer()
{
}
VclBuilderContainer::~VclBuilderContainer()
{
}
void Dialog::Activate()
{
if (GetType() == WindowType::MODELESSDIALOG)
{
css::uno::Reference< css::uno::XComponentContext > xContext(
comphelper::getProcessComponentContext() );
css::uno::Reference<css::frame::XGlobalEventBroadcaster> xEventBroadcaster(css::frame::theGlobalEventBroadcaster::get(xContext), css::uno::UNO_SET_THROW);
css::document::DocumentEvent aObject;
aObject.EventName = "ModelessDialogVisible";
xEventBroadcaster->documentEventOccured(aObject);
}
SystemWindow::Activate();
}
void Dialog::Command(const CommandEvent& rCEvt)
{
if (mpDialogImpl && mpDialogImpl->m_aPopupMenuHdl.Call(rCEvt))
return;
SystemWindow::Command(rCEvt);
}
void TopLevelWindowLocker::incBusy(const weld::Widget* pIgnore)
{
// lock any toplevel windows from being closed until busy is over
std::vector<VclPtr<vcl::Window>> aTopLevels;
vcl::Window *pTopWin = Application::GetFirstTopLevelWindow();
while (pTopWin)
{
vcl::Window* pCandidate = pTopWin;
if (pCandidate->GetType() == WindowType::BORDERWINDOW)
pCandidate = pCandidate->GetWindow(GetWindowType::FirstChild);
// tdf#125266 ignore HelpTextWindows
if (pCandidate &&
pCandidate->GetType() != WindowType::HELPTEXTWINDOW &&
pCandidate->GetType() != WindowType::FLOATINGWINDOW &&
pCandidate->GetFrameWeld() != pIgnore)
{
aTopLevels.push_back(pCandidate);
}
pTopWin = Application::GetNextTopLevelWindow(pTopWin);
}
for (auto& a : aTopLevels)
{
a->IncModalCount();
a->ImplGetFrame()->NotifyModalHierarchy(true);
}
m_aBusyStack.push(aTopLevels);
}
void TopLevelWindowLocker::decBusy()
{
// unlock locked toplevel windows from being closed now busy is over
for (auto& a : m_aBusyStack.top())
{
if (a->IsDisposed())
continue;
a->DecModalCount();
a->ImplGetFrame()->NotifyModalHierarchy(false);
}
m_aBusyStack.pop();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|