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
|
/* -*- 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 <strings.hrc>
#include <helpids.h>
#include <iderid.hxx>
#include <accessibledialogwindow.hxx>
#include <baside3.hxx>
#include <basidesh.hxx>
#include <bastype2.hxx>
#include <basobj.hxx>
#include <dlged.hxx>
#include <dlgeddef.hxx>
#include <dlgedmod.hxx>
#include <dlgedview.hxx>
#include <iderdll.hxx>
#include <localizationmgr.hxx>
#include <managelang.hxx>
#include <com/sun/star/script/XLibraryContainer2.hpp>
#include <com/sun/star/resource/StringResourceWithLocation.hpp>
#include <com/sun/star/ucb/SimpleFileAccess.hpp>
#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
#include <com/sun/star/ui/dialogs/FilePicker.hpp>
#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
#include <comphelper/processfactory.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/request.hxx>
#include <sfx2/viewfrm.hxx>
#include <svl/visitem.hxx>
#include <svl/whiter.hxx>
#include <svx/svdundo.hxx>
#include <svx/svxids.hrc>
#include <tools/diagnose_ex.h>
#include <tools/urlobj.hxx>
#include <vcl/commandevent.hxx>
#include <vcl/weld.hxx>
#include <vcl/settings.hxx>
#include <vcl/stdtext.hxx>
#include <vcl/svapp.hxx>
#include <xmlscript/xmldlg_imexp.hxx>
namespace basctl
{
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::ucb;
using namespace ::com::sun::star::io;
using namespace ::com::sun::star::resource;
using namespace ::com::sun::star::ui::dialogs;
#ifdef _WIN32
char const FilterMask_All[] = "*.*";
#else
char const FilterMask_All[] = "*";
#endif
DialogWindow::DialogWindow(DialogWindowLayout* pParent, ScriptDocument const& rDocument,
const OUString& aLibName, const OUString& aName,
css::uno::Reference<css::container::XNameContainer> const& xDialogModel)
: BaseWindow(pParent, rDocument, aLibName, aName)
,m_rLayout(*pParent)
,m_pEditor(new DlgEditor(*this, m_rLayout, rDocument.isDocument()
? rDocument.getDocument()
: Reference<frame::XModel>(), xDialogModel))
,m_pUndoMgr(new SfxUndoManager)
,m_nControlSlotId(SID_INSERT_SELECT)
{
InitSettings();
m_pEditor->GetModel().SetNotifyUndoActionHdl(
&DialogWindow::NotifyUndoActionHdl
);
SetHelpId( HID_BASICIDE_DIALOGWINDOW );
// set readonly mode for readonly libraries
Reference< script::XLibraryContainer2 > xDlgLibContainer( GetDocument().getLibraryContainer( E_DIALOGS ), UNO_QUERY );
if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) && xDlgLibContainer->isLibraryReadOnly( aLibName ) )
SetReadOnly(true);
if ( rDocument.isDocument() && rDocument.isReadOnly() )
SetReadOnly(true);
}
void DialogWindow::dispose()
{
m_pEditor.reset();
BaseWindow::dispose();
}
void DialogWindow::LoseFocus()
{
if ( IsModified() )
StoreData();
Window::LoseFocus();
}
void DialogWindow::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
{
m_pEditor->Paint(rRenderContext, rRect);
}
void DialogWindow::Resize()
{
if (GetHScrollBar() && GetVScrollBar())
{
m_pEditor->SetScrollBars( GetHScrollBar(), GetVScrollBar() );
}
}
void DialogWindow::MouseButtonDown( const MouseEvent& rMEvt )
{
m_pEditor->MouseButtonDown( rMEvt );
if (SfxBindings* pBindings = GetBindingsPtr())
pBindings->Invalidate( SID_SHOW_PROPERTYBROWSER );
}
void DialogWindow::MouseButtonUp( const MouseEvent& rMEvt )
{
m_pEditor->MouseButtonUp( rMEvt );
if( (m_pEditor->GetMode() == DlgEditor::INSERT) && !m_pEditor->IsCreateOK() )
{
m_nControlSlotId = SID_INSERT_SELECT;
m_pEditor->SetMode( DlgEditor::SELECT );
Shell::InvalidateControlSlots();
}
if (SfxBindings* pBindings = GetBindingsPtr())
{
pBindings->Invalidate( SID_SHOW_PROPERTYBROWSER );
pBindings->Invalidate( SID_DOC_MODIFIED );
pBindings->Invalidate( SID_SAVEDOC );
pBindings->Invalidate( SID_COPY );
pBindings->Invalidate( SID_CUT );
}
}
void DialogWindow::MouseMove( const MouseEvent& rMEvt )
{
m_pEditor->MouseMove( rMEvt );
}
void DialogWindow::KeyInput( const KeyEvent& rKEvt )
{
SfxBindings* pBindings = GetBindingsPtr();
if( rKEvt.GetKeyCode() == KEY_BACKSPACE )
{
if (SfxDispatcher* pDispatcher = GetDispatcher())
pDispatcher->Execute( SID_BACKSPACE );
}
else
{
if( pBindings && rKEvt.GetKeyCode() == KEY_TAB )
pBindings->Invalidate( SID_SHOW_PROPERTYBROWSER );
if( !m_pEditor->KeyInput( rKEvt ) )
{
if( !SfxViewShell::Current()->KeyInput( rKEvt ) )
Window::KeyInput( rKEvt );
}
}
// may be KEY_TAB, KEY_BACKSPACE, KEY_ESCAPE
if( pBindings )
{
pBindings->Invalidate( SID_COPY );
pBindings->Invalidate( SID_CUT );
}
}
void DialogWindow::Command( const CommandEvent& rCEvt )
{
if ( ( rCEvt.GetCommand() == CommandEventId::Wheel ) ||
( rCEvt.GetCommand() == CommandEventId::StartAutoScroll ) ||
( rCEvt.GetCommand() == CommandEventId::AutoScroll ) )
{
HandleScrollCommand( rCEvt, GetHScrollBar(), GetVScrollBar() );
}
else if ( rCEvt.GetCommand() == CommandEventId::ContextMenu )
{
if (GetDispatcher())
{
SdrView& rView = GetView();
if( !rCEvt.IsMouseEvent() && rView.AreObjectsMarked() )
{
tools::Rectangle aMarkedRect( rView.GetMarkedRect() );
Point MarkedCenter( aMarkedRect.Center() );
Point PosPixel( LogicToPixel( MarkedCenter ) );
SfxDispatcher::ExecutePopup( this, &PosPixel );
}
else
{
SfxDispatcher::ExecutePopup();
}
}
}
else
BaseWindow::Command( rCEvt );
}
void DialogWindow::NotifyUndoActionHdl( std::unique_ptr<SdrUndoAction> )
{
// #i120515# pUndoAction needs to be deleted, this hand over is an ownership
// change. As long as it does not get added to the undo manager, it needs at
// least to be deleted.
}
void DialogWindow::DoInit()
{
GetHScrollBar()->Show();
GetVScrollBar()->Show();
m_pEditor->SetScrollBars( GetHScrollBar(), GetVScrollBar() );
}
void DialogWindow::DoScroll( ScrollBar* )
{
m_pEditor->DoScroll();
}
void DialogWindow::GetState( SfxItemSet& rSet )
{
SfxWhichIter aIter(rSet);
bool bIsCalc = false;
if ( GetDocument().isDocument() )
{
Reference< frame::XModel > xModel= GetDocument().getDocument();
if ( xModel.is() )
{
Reference< lang::XServiceInfo > xServiceInfo ( xModel, UNO_QUERY );
if ( xServiceInfo.is() && xServiceInfo->supportsService( "com.sun.star.sheet.SpreadsheetDocument" ) )
bIsCalc = true;
}
}
for ( sal_uInt16 nWh = aIter.FirstWhich(); nWh != 0; nWh = aIter.NextWhich() )
{
switch ( nWh )
{
case SID_PASTE:
{
if ( !IsPasteAllowed() )
rSet.DisableItem( nWh );
if ( IsReadOnly() )
rSet.DisableItem( nWh );
}
break;
case SID_COPY:
{
// any object selected?
if ( !m_pEditor->GetView().AreObjectsMarked() )
rSet.DisableItem( nWh );
}
break;
case SID_CUT:
case SID_DELETE:
case SID_BACKSPACE:
{
// any object selected?
if ( !m_pEditor->GetView().AreObjectsMarked() )
rSet.DisableItem( nWh );
if ( IsReadOnly() )
rSet.DisableItem( nWh );
}
break;
case SID_REDO:
{
if ( !m_pUndoMgr->GetUndoActionCount() )
rSet.DisableItem( nWh );
}
break;
case SID_DIALOG_TESTMODE:
{
// is the IDE still active?
bool const bBool = GetShell()->GetFrame() &&
m_pEditor->GetMode() == DlgEditor::TEST;
rSet.Put(SfxBoolItem(SID_DIALOG_TESTMODE, bBool));
}
break;
case SID_CHOOSE_CONTROLS:
{
if ( IsReadOnly() )
rSet.DisableItem( nWh );
}
break;
case SID_SHOW_PROPERTYBROWSER:
{
Shell* pShell = GetShell();
SfxViewFrame* pViewFrame = pShell ? pShell->GetViewFrame() : nullptr;
if ( pViewFrame && !pViewFrame->HasChildWindow( SID_SHOW_PROPERTYBROWSER ) && !m_pEditor->GetView().AreObjectsMarked() )
rSet.DisableItem( nWh );
if ( IsReadOnly() )
rSet.DisableItem( nWh );
}
break;
case SID_INSERT_FORM_RADIO:
case SID_INSERT_FORM_CHECK:
case SID_INSERT_FORM_LIST:
case SID_INSERT_FORM_COMBO:
case SID_INSERT_FORM_VSCROLL:
case SID_INSERT_FORM_HSCROLL:
case SID_INSERT_FORM_SPIN:
{
if ( !bIsCalc || IsReadOnly() )
rSet.DisableItem( nWh );
else
rSet.Put( SfxBoolItem( nWh, m_nControlSlotId == nWh ) );
}
break;
case SID_INSERT_SELECT:
case SID_INSERT_PUSHBUTTON:
case SID_INSERT_RADIOBUTTON:
case SID_INSERT_CHECKBOX:
case SID_INSERT_LISTBOX:
case SID_INSERT_COMBOBOX:
case SID_INSERT_GROUPBOX:
case SID_INSERT_EDIT:
case SID_INSERT_FIXEDTEXT:
case SID_INSERT_IMAGECONTROL:
case SID_INSERT_PROGRESSBAR:
case SID_INSERT_HSCROLLBAR:
case SID_INSERT_VSCROLLBAR:
case SID_INSERT_HFIXEDLINE:
case SID_INSERT_VFIXEDLINE:
case SID_INSERT_DATEFIELD:
case SID_INSERT_TIMEFIELD:
case SID_INSERT_NUMERICFIELD:
case SID_INSERT_CURRENCYFIELD:
case SID_INSERT_FORMATTEDFIELD:
case SID_INSERT_PATTERNFIELD:
case SID_INSERT_FILECONTROL:
case SID_INSERT_SPINBUTTON:
case SID_INSERT_GRIDCONTROL:
case SID_INSERT_HYPERLINKCONTROL:
case SID_INSERT_TREECONTROL:
{
if ( IsReadOnly() )
rSet.DisableItem( nWh );
else
rSet.Put( SfxBoolItem( nWh, m_nControlSlotId == nWh ) );
}
break;
case SID_SHOWLINES:
{
// if this is not a module window hide the
// setting, doesn't make sense for example if the
// dialog editor is open
rSet.DisableItem(nWh);
rSet.Put(SfxVisibilityItem(nWh, false));
break;
}
case SID_SELECTALL:
{
rSet.DisableItem( nWh );
}
break;
}
}
}
void DialogWindow::ExecuteCommand( SfxRequest& rReq )
{
const sal_uInt16 nSlotId(rReq.GetSlot());
sal_uInt16 nInsertObj(0);
switch ( nSlotId )
{
case SID_CUT:
if ( !IsReadOnly() )
{
GetEditor().Cut();
if (SfxBindings* pBindings = GetBindingsPtr())
pBindings->Invalidate( SID_DOC_MODIFIED );
}
break;
case SID_DELETE:
if ( !IsReadOnly() )
{
GetEditor().Delete();
if (SfxBindings* pBindings = GetBindingsPtr())
pBindings->Invalidate( SID_DOC_MODIFIED );
}
break;
case SID_COPY:
GetEditor().Copy();
break;
case SID_PASTE:
if ( !IsReadOnly() )
{
GetEditor().Paste();
if (SfxBindings* pBindings = GetBindingsPtr())
pBindings->Invalidate( SID_DOC_MODIFIED );
}
break;
case SID_INSERT_FORM_RADIO:
nInsertObj = OBJ_DLG_FORMRADIO;
break;
case SID_INSERT_FORM_CHECK:
nInsertObj = OBJ_DLG_FORMCHECK;
break;
case SID_INSERT_FORM_LIST:
nInsertObj = OBJ_DLG_FORMLIST;
break;
case SID_INSERT_FORM_COMBO:
nInsertObj = OBJ_DLG_FORMCOMBO;
break;
case SID_INSERT_FORM_SPIN:
nInsertObj = OBJ_DLG_FORMSPIN;
break;
case SID_INSERT_FORM_VSCROLL:
nInsertObj = OBJ_DLG_FORMVSCROLL;
break;
case SID_INSERT_FORM_HSCROLL:
nInsertObj = OBJ_DLG_FORMHSCROLL;
break;
case SID_INSERT_PUSHBUTTON:
nInsertObj = OBJ_DLG_PUSHBUTTON;
break;
case SID_INSERT_RADIOBUTTON:
nInsertObj = OBJ_DLG_RADIOBUTTON;
break;
case SID_INSERT_CHECKBOX:
nInsertObj = OBJ_DLG_CHECKBOX;
break;
case SID_INSERT_LISTBOX:
nInsertObj = OBJ_DLG_LISTBOX;
break;
case SID_INSERT_COMBOBOX:
nInsertObj = OBJ_DLG_COMBOBOX;
break;
case SID_INSERT_GROUPBOX:
nInsertObj = OBJ_DLG_GROUPBOX;
break;
case SID_INSERT_EDIT:
nInsertObj = OBJ_DLG_EDIT;
break;
case SID_INSERT_FIXEDTEXT:
nInsertObj = OBJ_DLG_FIXEDTEXT;
break;
case SID_INSERT_IMAGECONTROL:
nInsertObj = OBJ_DLG_IMAGECONTROL;
break;
case SID_INSERT_PROGRESSBAR:
nInsertObj = OBJ_DLG_PROGRESSBAR;
break;
case SID_INSERT_HSCROLLBAR:
nInsertObj = OBJ_DLG_HSCROLLBAR;
break;
case SID_INSERT_VSCROLLBAR:
nInsertObj = OBJ_DLG_VSCROLLBAR;
break;
case SID_INSERT_HFIXEDLINE:
nInsertObj = OBJ_DLG_HFIXEDLINE;
break;
case SID_INSERT_VFIXEDLINE:
nInsertObj = OBJ_DLG_VFIXEDLINE;
break;
case SID_INSERT_DATEFIELD:
nInsertObj = OBJ_DLG_DATEFIELD;
break;
case SID_INSERT_TIMEFIELD:
nInsertObj = OBJ_DLG_TIMEFIELD;
break;
case SID_INSERT_NUMERICFIELD:
nInsertObj = OBJ_DLG_NUMERICFIELD;
break;
case SID_INSERT_CURRENCYFIELD:
nInsertObj = OBJ_DLG_CURRENCYFIELD;
break;
case SID_INSERT_FORMATTEDFIELD:
nInsertObj = OBJ_DLG_FORMATTEDFIELD;
break;
case SID_INSERT_PATTERNFIELD:
nInsertObj = OBJ_DLG_PATTERNFIELD;
break;
case SID_INSERT_FILECONTROL:
nInsertObj = OBJ_DLG_FILECONTROL;
break;
case SID_INSERT_SPINBUTTON:
nInsertObj = OBJ_DLG_SPINBUTTON;
break;
case SID_INSERT_GRIDCONTROL:
nInsertObj = OBJ_DLG_GRIDCONTROL;
break;
case SID_INSERT_HYPERLINKCONTROL:
nInsertObj = OBJ_DLG_HYPERLINKCONTROL;
break;
case SID_INSERT_TREECONTROL:
nInsertObj = OBJ_DLG_TREECONTROL;
break;
case SID_INSERT_SELECT:
m_nControlSlotId = nSlotId;
GetEditor().SetMode( DlgEditor::SELECT );
Shell::InvalidateControlSlots();
break;
case SID_DIALOG_TESTMODE:
{
DlgEditor::Mode eOldMode = GetEditor().GetMode();
GetEditor().SetMode( DlgEditor::TEST );
GetEditor().SetMode( eOldMode );
rReq.Done();
if (SfxBindings* pBindings = GetBindingsPtr())
pBindings->Invalidate( SID_DIALOG_TESTMODE );
return;
}
case SID_EXPORT_DIALOG:
SaveDialog();
break;
case SID_IMPORT_DIALOG:
ImportDialog();
break;
case SID_BASICIDE_DELETECURRENT:
if (QueryDelDialog(m_aName, GetFrameWeld()))
{
if (RemoveDialog(m_aDocument, m_aLibName, m_aName))
{
MarkDocumentModified(m_aDocument);
GetShell()->RemoveWindow(this, true);
}
}
break;
}
if ( nInsertObj )
{
m_nControlSlotId = nSlotId;
GetEditor().SetMode( DlgEditor::INSERT );
GetEditor().SetInsertObj( nInsertObj );
if ( rReq.GetModifier() & KEY_MOD1 )
{
GetEditor().CreateDefaultObject();
if (SfxBindings* pBindings = GetBindingsPtr())
pBindings->Invalidate( SID_DOC_MODIFIED );
}
Shell::InvalidateControlSlots();
}
rReq.Done();
}
Reference< container::XNameContainer > const & DialogWindow::GetDialog() const
{
return m_pEditor->GetDialog();
}
bool DialogWindow::RenameDialog( const OUString& rNewName )
{
if (!basctl::RenameDialog(GetFrameWeld(), GetDocument(), GetLibName(), GetName(), rNewName))
return false;
if (SfxBindings* pBindings = GetBindingsPtr())
pBindings->Invalidate( SID_DOC_MODIFIED );
return true;
}
void DialogWindow::DisableBrowser()
{
m_rLayout.DisablePropertyBrowser();
}
void DialogWindow::UpdateBrowser()
{
m_rLayout.UpdatePropertyBrowser();
}
void DialogWindow::SaveDialog()
{
Reference< XComponentContext > xContext( comphelper::getProcessComponentContext() );
Reference < XFilePicker3 > xFP = FilePicker::createWithMode(xContext, TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD);
Reference< XFilePickerControlAccess > xFPControl(xFP, UNO_QUERY);
xFPControl->enableControl(ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, false);
Any aValue;
aValue <<= true;
xFPControl->setValue(ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue);
if ( !m_sCurPath.isEmpty() )
xFP->setDisplayDirectory ( m_sCurPath );
xFP->setDefaultName( GetName() );
OUString aDialogStr(IDEResId(RID_STR_STDDIALOGNAME));
xFP->appendFilter( aDialogStr, "*.xdl" );
xFP->appendFilter( IDEResId(RID_STR_FILTER_ALLFILES), FilterMask_All );
xFP->setCurrentFilter( aDialogStr );
if( xFP->execute() != RET_OK )
return;
Sequence< OUString > aPaths = xFP->getSelectedFiles();
m_sCurPath = aPaths[0];
// export dialog model to xml
Reference< container::XNameContainer > xDialogModel = GetDialog();
Reference< XInputStreamProvider > xISP = ::xmlscript::exportDialogModel( xDialogModel, xContext, GetDocument().isDocument() ? GetDocument().getDocument() : Reference< frame::XModel >() );
Reference< XInputStream > xInput( xISP->createInputStream() );
Reference< XSimpleFileAccess3 > xSFI( SimpleFileAccess::create(xContext) );
Reference< XOutputStream > xOutput;
try
{
if( xSFI->exists( m_sCurPath ) )
xSFI->kill( m_sCurPath );
xOutput = xSFI->openFileWrite( m_sCurPath );
}
catch(const Exception& )
{}
if( xOutput.is() )
{
Sequence< sal_Int8 > bytes;
sal_Int32 nRead = xInput->readBytes( bytes, xInput->available() );
for (;;)
{
if( nRead )
xOutput->writeBytes( bytes );
nRead = xInput->readBytes( bytes, 1024 );
if (! nRead)
break;
}
// With resource?
Reference< beans::XPropertySet > xDialogModelPropSet( xDialogModel, UNO_QUERY );
Reference< resource::XStringResourceResolver > xStringResourceResolver;
if( xDialogModelPropSet.is() )
{
try
{
Any aResourceResolver = xDialogModelPropSet->getPropertyValue( "ResourceResolver" );
aResourceResolver >>= xStringResourceResolver;
}
catch(const beans::UnknownPropertyException& )
{}
}
bool bResource = false;
if( xStringResourceResolver.is() )
{
Sequence< lang::Locale > aLocaleSeq = xStringResourceResolver->getLocales();
if( aLocaleSeq.hasElements() )
bResource = true;
}
if( bResource )
{
INetURLObject aURLObj( m_sCurPath );
aURLObj.removeExtension();
OUString aDialogName( aURLObj.getName() );
aURLObj.removeSegment();
OUString aURL( aURLObj.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
OUString aComment = "# " + aDialogName + " strings" ;
Reference< task::XInteractionHandler > xDummyHandler;
// Remove old properties files in case of overwriting Dialog files
if( xSFI->isFolder( aURL ) )
{
Sequence< OUString > aContentSeq = xSFI->getFolderContents( aURL, false );
OUString aDialogName_ = aDialogName + "_" ;
sal_Int32 nCount = aContentSeq.getLength();
const OUString* pFiles = aContentSeq.getConstArray();
for( int i = 0 ; i < nCount ; i++ )
{
OUString aCompleteName = pFiles[i];
OUString aPureName;
OUString aExtension;
sal_Int32 iDot = aCompleteName.lastIndexOf( '.' );
sal_Int32 iSlash = aCompleteName.lastIndexOf( '/' );
if( iDot != -1 )
{
sal_Int32 iCopyFrom = (iSlash != -1) ? iSlash + 1 : 0;
aPureName = aCompleteName.copy( iCopyFrom, iDot-iCopyFrom );
aExtension = aCompleteName.copy( iDot + 1 );
}
if( aExtension == "properties" || aExtension == "default" )
{
if( aPureName.startsWith( aDialogName_ ) )
{
try
{
xSFI->kill( aCompleteName );
}
catch(const uno::Exception& )
{}
}
}
}
}
Reference< XStringResourceWithLocation > xStringResourceWithLocation =
StringResourceWithLocation::create( xContext, aURL, false/*bReadOnly*/,
xStringResourceResolver->getDefaultLocale(), aDialogName, aComment, xDummyHandler );
// Add locales
Sequence< lang::Locale > aLocaleSeq = xStringResourceResolver->getLocales();
const lang::Locale* pLocales = aLocaleSeq.getConstArray();
sal_Int32 nLocaleCount = aLocaleSeq.getLength();
for( sal_Int32 iLocale = 0 ; iLocale < nLocaleCount ; iLocale++ )
{
const lang::Locale& rLocale = pLocales[ iLocale ];
xStringResourceWithLocation->newLocale( rLocale );
}
LocalizationMgr::copyResourceForDialog( xDialogModel,
xStringResourceResolver, xStringResourceWithLocation );
xStringResourceWithLocation->store();
}
}
else
{
std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(GetFrameWeld(),
VclMessageType::Warning, VclButtonsType::Ok, IDEResId(RID_STR_COULDNTWRITE)));
xBox->run();
}
}
static std::vector< lang::Locale > implGetLanguagesOnlyContainedInFirstSeq
( const Sequence< lang::Locale >& aFirstSeq, const Sequence< lang::Locale >& aSecondSeq )
{
std::vector< lang::Locale > avRet;
const lang::Locale* pFirst = aFirstSeq.getConstArray();
const lang::Locale* pSecond = aSecondSeq.getConstArray();
sal_Int32 nFirstCount = aFirstSeq.getLength();
sal_Int32 nSecondCount = aSecondSeq.getLength();
for( sal_Int32 iFirst = 0 ; iFirst < nFirstCount ; iFirst++ )
{
const lang::Locale& rFirstLocale = pFirst[ iFirst ];
bool bAlsoContainedInSecondSeq = false;
for( sal_Int32 iSecond = 0 ; iSecond < nSecondCount ; iSecond++ )
{
const lang::Locale& rSecondLocale = pSecond[ iSecond ];
bool bMatch = localesAreEqual( rFirstLocale, rSecondLocale );
if( bMatch )
{
bAlsoContainedInSecondSeq = true;
break;
}
}
if( !bAlsoContainedInSecondSeq )
avRet.push_back( rFirstLocale );
}
return avRet;
}
namespace {
class NameClashQueryBox
{
private:
std::unique_ptr<weld::MessageDialog> m_xQueryBox;
public:
NameClashQueryBox(weld::Window* pParent, const OUString& rTitle, const OUString& rMessage)
: m_xQueryBox(Application::CreateMessageDialog(pParent, VclMessageType::Question, VclButtonsType::NONE, rMessage))
{
if (!rTitle.isEmpty())
m_xQueryBox->set_title(rTitle);
m_xQueryBox->add_button(IDEResId(RID_STR_DLGIMP_CLASH_RENAME), RET_YES);
m_xQueryBox->add_button(IDEResId(RID_STR_DLGIMP_CLASH_REPLACE), RET_NO);
m_xQueryBox->add_button(GetStandardText(StandardButtonType::Cancel), RET_CANCEL);
m_xQueryBox->set_default_response(RET_YES);
}
short run() { return m_xQueryBox->run(); }
};
class LanguageMismatchQueryBox
{
private:
std::unique_ptr<weld::MessageDialog> m_xQueryBox;
public:
LanguageMismatchQueryBox(weld::Window* pParent, const OUString& rTitle, const OUString& rMessage)
: m_xQueryBox(Application::CreateMessageDialog(pParent, VclMessageType::Question, VclButtonsType::NONE, rMessage))
{
if (!rTitle.isEmpty())
m_xQueryBox->set_title(rTitle);
m_xQueryBox->add_button(IDEResId(RID_STR_DLGIMP_MISMATCH_ADD), RET_YES);
m_xQueryBox->add_button(IDEResId(RID_STR_DLGIMP_MISMATCH_OMIT), RET_NO);
m_xQueryBox->add_button(GetStandardText(StandardButtonType::Cancel), RET_CANCEL);
m_xQueryBox->add_button(GetStandardText(StandardButtonType::Help), RET_HELP);
m_xQueryBox->set_default_response(RET_YES);
}
short run() { return m_xQueryBox->run(); }
};
}
bool implImportDialog(weld::Window* pWin, const OUString& rCurPath, const ScriptDocument& rDocument, const OUString& aLibName)
{
bool bDone = false;
Reference< XComponentContext > xContext( comphelper::getProcessComponentContext() );
Reference < XFilePicker3 > xFP = FilePicker::createWithMode(xContext, TemplateDescription::FILEOPEN_SIMPLE);
Reference< XFilePickerControlAccess > xFPControl(xFP, UNO_QUERY);
xFPControl->enableControl(ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, false);
Any aValue;
aValue <<= true;
xFPControl->setValue(ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue);
OUString aCurPath( rCurPath );
if ( !aCurPath.isEmpty() )
xFP->setDisplayDirectory ( aCurPath );
OUString aDialogStr(IDEResId(RID_STR_STDDIALOGNAME));
xFP->appendFilter( aDialogStr, "*.xdl" );
xFP->appendFilter( IDEResId(RID_STR_FILTER_ALLFILES), FilterMask_All );
xFP->setCurrentFilter( aDialogStr );
if( xFP->execute() == RET_OK )
{
Sequence< OUString > aPaths = xFP->getSelectedFiles();
aCurPath = aPaths[0];
OUString aBasePath;
OUString aOUCurPath( aCurPath );
sal_Int32 iSlash = aOUCurPath.lastIndexOf( '/' );
if( iSlash != -1 )
aBasePath = aOUCurPath.copy( 0, iSlash + 1 );
try
{
// create dialog model
Reference< container::XNameContainer > xDialogModel(
xContext->getServiceManager()->createInstanceWithContext("com.sun.star.awt.UnoControlDialogModel", xContext),
UNO_QUERY_THROW );
Reference< XSimpleFileAccess3 > xSFI( SimpleFileAccess::create(xContext) );
Reference< XInputStream > xInput;
if( xSFI->exists( aCurPath ) )
xInput = xSFI->openFileRead( aCurPath );
::xmlscript::importDialogModel( xInput, xDialogModel, xContext, rDocument.isDocument() ? rDocument.getDocument() : Reference< frame::XModel >() );
OUString aXmlDlgName;
Reference< beans::XPropertySet > xDialogModelPropSet( xDialogModel, UNO_QUERY );
assert(xDialogModelPropSet.is());
try
{
Any aXmlDialogNameAny = xDialogModelPropSet->getPropertyValue( DLGED_PROP_NAME );
aXmlDialogNameAny >>= aXmlDlgName;
}
catch(const beans::UnknownPropertyException& )
{
TOOLS_WARN_EXCEPTION("basctl", "");
}
assert( !aXmlDlgName.isEmpty() );
bool bDialogAlreadyExists = rDocument.hasDialog( aLibName, aXmlDlgName );
OUString aNewDlgName = aXmlDlgName;
enum NameClashMode
{
NO_CLASH,
CLASH_OVERWRITE_DIALOG,
CLASH_RENAME_DIALOG,
};
NameClashMode eNameClashMode = NO_CLASH;
if( bDialogAlreadyExists )
{
OUString aQueryBoxTitle(IDEResId(RID_STR_DLGIMP_CLASH_TITLE));
OUString aQueryBoxText(IDEResId(RID_STR_DLGIMP_CLASH_TEXT));
aQueryBoxText = aQueryBoxText.replaceAll("$(ARG1)", aXmlDlgName);
NameClashQueryBox aQueryBox(pWin, aQueryBoxTitle, aQueryBoxText);
sal_uInt16 nRet = aQueryBox.run();
if( nRet == RET_YES )
{
// RET_YES == Rename, see NameClashQueryBox::NameClashQueryBox
eNameClashMode = CLASH_RENAME_DIALOG;
aNewDlgName = rDocument.createObjectName( E_DIALOGS, aLibName );
}
else if( nRet == RET_NO )
{
// RET_NO == Replace, see NameClashQueryBox::NameClashQueryBox
eNameClashMode = CLASH_OVERWRITE_DIALOG;
}
else if( nRet == RET_CANCEL )
{
return bDone;
}
}
Shell* pShell = GetShell();
assert(pShell);
// Resource?
css::lang::Locale aLocale = Application::GetSettings().GetUILanguageTag().getLocale();
Reference< task::XInteractionHandler > xDummyHandler;
Reference< XStringResourceWithLocation > xImportStringResource =
StringResourceWithLocation::create( xContext, aBasePath, true/*bReadOnly*/,
aLocale, aXmlDlgName, OUString(), xDummyHandler );
Sequence< lang::Locale > aImportLocaleSeq = xImportStringResource->getLocales();
sal_Int32 nImportLocaleCount = aImportLocaleSeq.getLength();
Reference< container::XNameContainer > xDialogLib( rDocument.getLibrary( E_DIALOGS, aLibName, true ) );
Reference< resource::XStringResourceManager > xLibStringResourceManager = LocalizationMgr::getStringResourceFromDialogLibrary( xDialogLib );
sal_Int32 nLibLocaleCount = 0;
Sequence< lang::Locale > aLibLocaleSeq;
if( xLibStringResourceManager.is() )
{
aLibLocaleSeq = xLibStringResourceManager->getLocales();
nLibLocaleCount = aLibLocaleSeq.getLength();
}
// Check language matches
std::vector< lang::Locale > aOnlyInImportLanguages =
implGetLanguagesOnlyContainedInFirstSeq( aImportLocaleSeq, aLibLocaleSeq );
int nOnlyInImportLanguageCount = aOnlyInImportLanguages.size();
// For now: Keep languages from lib
bool bLibLocalized = (nLibLocaleCount > 0);
bool bImportLocalized = (nImportLocaleCount > 0);
bool bAddDialogLanguagesToLib = false;
if( nOnlyInImportLanguageCount > 0 )
{
OUString aQueryBoxTitle(IDEResId(RID_STR_DLGIMP_MISMATCH_TITLE));
OUString aQueryBoxText(IDEResId(RID_STR_DLGIMP_MISMATCH_TEXT));
LanguageMismatchQueryBox aQueryBox(pWin, aQueryBoxTitle, aQueryBoxText);
sal_uInt16 nRet = aQueryBox.run();
if( nRet == RET_YES )
{
// RET_YES == Add, see LanguageMismatchQueryBox::LanguageMismatchQueryBox
bAddDialogLanguagesToLib = true;
}
// RET_NO == Omit, see LanguageMismatchQueryBox::LanguageMismatchQueryBox
// -> nothing to do here
//else if( RET_NO == nRet )
//{
//}
else if( nRet == RET_CANCEL )
{
return bDone;
}
}
if( bImportLocalized )
{
bool bCopyResourcesForDialog = true;
if( bAddDialogLanguagesToLib )
{
const std::shared_ptr<LocalizationMgr>& pCurMgr = pShell->GetCurLocalizationMgr();
lang::Locale aFirstLocale = aOnlyInImportLanguages[0];
if( nOnlyInImportLanguageCount > 1 )
{
// Check if import default belongs to only import languages and use it then
lang::Locale aImportDefaultLocale = xImportStringResource->getDefaultLocale();
lang::Locale aTmpLocale;
for( int i = 0 ; i < nOnlyInImportLanguageCount ; ++i )
{
aTmpLocale = aOnlyInImportLanguages[i];
if( localesAreEqual( aImportDefaultLocale, aTmpLocale ) )
{
aFirstLocale = aImportDefaultLocale;
break;
}
}
}
pCurMgr->handleAddLocales( {aFirstLocale} );
if( nOnlyInImportLanguageCount > 1 )
{
Sequence< lang::Locale > aRemainingLocaleSeq( nOnlyInImportLanguageCount - 1 );
lang::Locale aTmpLocale;
int iSeq = 0;
for( int i = 0 ; i < nOnlyInImportLanguageCount ; ++i )
{
aTmpLocale = aOnlyInImportLanguages[i];
if( !localesAreEqual( aFirstLocale, aTmpLocale ) )
aRemainingLocaleSeq[iSeq++] = aTmpLocale;
}
pCurMgr->handleAddLocales( aRemainingLocaleSeq );
}
}
else if( !bLibLocalized )
{
LocalizationMgr::resetResourceForDialog( xDialogModel, xImportStringResource );
bCopyResourcesForDialog = false;
}
if( bCopyResourcesForDialog )
{
LocalizationMgr::copyResourceForDroppedDialog( xDialogModel, aXmlDlgName,
xLibStringResourceManager, xImportStringResource );
}
}
else if( bLibLocalized )
{
LocalizationMgr::setResourceIDsForDialog( xDialogModel, xLibStringResourceManager );
}
LocalizationMgr::setStringResourceAtDialog( rDocument, aLibName, aNewDlgName, xDialogModel );
if( eNameClashMode == CLASH_OVERWRITE_DIALOG )
{
if (basctl::RemoveDialog( rDocument, aLibName, aNewDlgName ) )
{
BaseWindow* pDlgWin = pShell->FindDlgWin( rDocument, aLibName, aNewDlgName, false, true );
if( pDlgWin != nullptr )
pShell->RemoveWindow( pDlgWin, false );
MarkDocumentModified( rDocument );
}
else
{
// TODO: Assertion?
return bDone;
}
}
if( eNameClashMode == CLASH_RENAME_DIALOG )
{
bool bRenamed = false;
if( xDialogModelPropSet.is() )
{
try
{
xDialogModelPropSet->setPropertyValue( DLGED_PROP_NAME, Any(aNewDlgName) );
bRenamed = true;
}
catch(const beans::UnknownPropertyException& )
{}
}
if( bRenamed )
{
LocalizationMgr::renameStringResourceIDs( rDocument, aLibName, aNewDlgName, xDialogModel );
}
else
{
// TODO: Assertion?
return bDone;
}
}
Reference< XInputStreamProvider > xISP = ::xmlscript::exportDialogModel( xDialogModel, xContext, rDocument.isDocument() ? rDocument.getDocument() : Reference< frame::XModel >() );
bool bSuccess = rDocument.insertDialog( aLibName, aNewDlgName, xISP );
if( bSuccess )
{
VclPtr<DialogWindow> pNewDlgWin = pShell->CreateDlgWin( rDocument, aLibName, aNewDlgName );
pShell->SetCurWindow( pNewDlgWin, true );
}
bDone = true;
}
catch(const Exception& )
{}
}
return bDone;
}
void DialogWindow::ImportDialog()
{
const ScriptDocument& rDocument = GetDocument();
OUString aLibName = GetLibName();
implImportDialog(GetFrameWeld(), m_sCurPath, rDocument, aLibName);
}
DlgEdModel& DialogWindow::GetModel() const
{
return m_pEditor->GetModel();
}
DlgEdPage& DialogWindow::GetPage() const
{
return m_pEditor->GetPage();
}
DlgEdView& DialogWindow::GetView() const
{
return m_pEditor->GetView();
}
bool DialogWindow::IsModified()
{
return m_pEditor->IsModified();
}
SfxUndoManager* DialogWindow::GetUndoManager()
{
return m_pUndoMgr.get();
}
OUString DialogWindow::GetTitle()
{
return GetName();
}
EntryDescriptor DialogWindow::CreateEntryDescriptor()
{
ScriptDocument aDocument( GetDocument() );
OUString aLibName( GetLibName() );
LibraryLocation eLocation = aDocument.getLibraryLocation( aLibName );
return EntryDescriptor( aDocument, eLocation, aLibName, OUString(), GetName(), OBJ_TYPE_DIALOG );
}
void DialogWindow::SetReadOnly (bool bReadOnly)
{
m_pEditor->SetMode(bReadOnly ? DlgEditor::READONLY : DlgEditor::SELECT);
}
bool DialogWindow::IsReadOnly ()
{
return m_pEditor->GetMode() == DlgEditor::READONLY;
}
bool DialogWindow::IsPasteAllowed()
{
return m_pEditor->IsPasteAllowed();
}
void DialogWindow::StoreData()
{
if ( !IsModified() )
return;
try
{
Reference< container::XNameContainer > xLib = GetDocument().getLibrary( E_DIALOGS, GetLibName(), true );
if( xLib.is() )
{
Reference< container::XNameContainer > xDialogModel = m_pEditor->GetDialog();
if( xDialogModel.is() )
{
Reference< XComponentContext > xContext(
comphelper::getProcessComponentContext() );
Reference< XInputStreamProvider > xISP = ::xmlscript::exportDialogModel( xDialogModel, xContext, GetDocument().isDocument() ? GetDocument().getDocument() : Reference< frame::XModel >() );
xLib->replaceByName( GetName(), Any( xISP ) );
}
}
}
catch (const uno::Exception& )
{
DBG_UNHANDLED_EXCEPTION("basctl.basicide");
}
MarkDocumentModified( GetDocument() );
m_pEditor->ClearModifyFlag();
}
void DialogWindow::Activating ()
{
UpdateBrowser();
Show();
}
void DialogWindow::Deactivating()
{
Hide();
if ( IsModified() )
MarkDocumentModified( GetDocument() );
DisableBrowser();
}
sal_Int32 DialogWindow::countPages( Printer* )
{
return 1;
}
void DialogWindow::printPage( sal_Int32 nPage, Printer* pPrinter )
{
DlgEditor::printPage( nPage, pPrinter, CreateQualifiedName() );
}
void DialogWindow::DataChanged( const DataChangedEvent& rDCEvt )
{
if( (rDCEvt.GetType()==DataChangedEventType::SETTINGS) && (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
{
InitSettings();
Invalidate();
}
else
BaseWindow::DataChanged( rDCEvt );
}
void DialogWindow::InitSettings()
{
// FIXME RenderContext
const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
vcl::Font aFont = rStyleSettings.GetFieldFont();
SetPointFont(*this, aFont);
SetTextColor( rStyleSettings.GetFieldTextColor() );
SetTextFillColor();
SetBackground( rStyleSettings.GetFieldColor() );
}
css::uno::Reference< css::accessibility::XAccessible > DialogWindow::CreateAccessible()
{
return new AccessibleDialogWindow(this);
}
char const* DialogWindow::GetHid () const
{
return HID_BASICIDE_DIALOGWINDOW;
}
ItemType DialogWindow::GetType () const
{
return TYPE_DIALOG;
}
// DialogWindowLayout
DialogWindowLayout::DialogWindowLayout (vcl::Window* pParent, ObjectCatalog& rObjectCatalog_) :
Layout(pParent),
rObjectCatalog(rObjectCatalog_),
pPropertyBrowser(nullptr)
{
ShowPropertyBrowser();
}
DialogWindowLayout::~DialogWindowLayout()
{
disposeOnce();
}
void DialogWindowLayout::dispose()
{
if (pPropertyBrowser)
Remove(pPropertyBrowser);
pPropertyBrowser.disposeAndClear();
Layout::dispose();
}
// shows the property browser (and creates if necessary)
void DialogWindowLayout::ShowPropertyBrowser ()
{
// not exists?
if (!pPropertyBrowser)
{
// creating
pPropertyBrowser = VclPtr<PropBrw>::Create(*this);
pPropertyBrowser->Show();
// after OnFirstSize():
if (HasSize())
AddPropertyBrowser();
// updating if necessary
UpdatePropertyBrowser();
}
else
pPropertyBrowser->Show();
// refreshing the button state
if (SfxBindings* pBindings = GetBindingsPtr())
pBindings->Invalidate(SID_SHOW_PROPERTYBROWSER);
}
// disables the property browser
void DialogWindowLayout::DisablePropertyBrowser ()
{
if (pPropertyBrowser)
pPropertyBrowser->Update(nullptr);
}
// updates the property browser
void DialogWindowLayout::UpdatePropertyBrowser ()
{
if (pPropertyBrowser)
pPropertyBrowser->Update(GetShell());
}
void DialogWindowLayout::Activating (BaseWindow& rChild)
{
assert(dynamic_cast<DialogWindow*>(&rChild));
rObjectCatalog.SetLayoutWindow(this);
rObjectCatalog.UpdateEntries();
rObjectCatalog.Show();
if (pPropertyBrowser)
pPropertyBrowser->Show();
Layout::Activating(rChild);
}
void DialogWindowLayout::Deactivating ()
{
Layout::Deactivating();
rObjectCatalog.Hide();
if (pPropertyBrowser)
pPropertyBrowser->Hide();
}
void DialogWindowLayout::ExecuteGlobal (SfxRequest& rReq)
{
switch (rReq.GetSlot())
{
case SID_SHOW_PROPERTYBROWSER:
// toggling property browser
if (pPropertyBrowser && pPropertyBrowser->IsVisible())
pPropertyBrowser->Hide();
else
ShowPropertyBrowser();
ArrangeWindows();
// refreshing the button state
if (SfxBindings* pBindings = GetBindingsPtr())
pBindings->Invalidate(SID_SHOW_PROPERTYBROWSER);
break;
}
}
void DialogWindowLayout::GetState (SfxItemSet& rSet, unsigned nWhich)
{
switch (nWhich)
{
case SID_SHOW_PROPERTYBROWSER:
rSet.Put(SfxBoolItem(nWhich, pPropertyBrowser && pPropertyBrowser->IsVisible()));
break;
case SID_BASICIDE_CHOOSEMACRO:
rSet.Put(SfxVisibilityItem(nWhich, false));
break;
}
}
void DialogWindowLayout::OnFirstSize (long const nWidth, long const nHeight)
{
AddToLeft(&rObjectCatalog, Size(nWidth * 0.25, nHeight * 0.35));
if (pPropertyBrowser)
AddPropertyBrowser();
}
void DialogWindowLayout::AddPropertyBrowser () {
Size const aSize = GetOutputSizePixel();
AddToLeft(pPropertyBrowser, Size(aSize.Width() * 0.25, aSize.Height() * 0.65));
}
} // namespace basctl
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|