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
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_basctl.hxx"
#include <ide_pch.hxx>
#include <svtools/texteng.hxx>
#include <svtools/textview.hxx>
#include <svtools/xtextedt.hxx>
#include <basic/sbx.hxx>
#include <comphelper/processfactory.hxx>
#include <com/sun/star/ui/dialogs/XFilePicker.hpp>
#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
#include <com/sun/star/ui/dialogs/XFilterManager.hpp>
#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
#include <com/sun/star/script/XLibraryContainer2.hpp>
#include <com/sun/star/document/MacroExecMode.hpp>
#include <com/sun/star/script/ModuleType.hpp>
#include <toolkit/helper/vclunohelper.hxx>
#include <sfx2/docfile.hxx>
#include <basic/basrdll.hxx>
#include <baside2.hrc>
#include <baside2.hxx>
#include <objdlg.hxx>
#include <iderdll.hxx>
#include <iderdll2.hxx>
#include <basobj.hxx>
#include <brkdlg.hxx>
#include <vcl/sound.hxx>
#include <unotools/textsearch.hxx>
#include <tools/diagnose_ex.h>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
#define SPLIT_MARGIN 5
#define SPLIT_HEIGHT 2
#define LMARGPRN 1700
#define RMARGPRN 900
#define TMARGPRN 2000
#define BMARGPRN 1000
#define BORDERPRN 300
#define APPWAIT_START 100
#define VALIDWINDOW 0x1234
#if defined(OW) || defined(MTF)
#define FILTERMASK_ALL "*"
#else
#define FILTERMASK_ALL "*.*"
#endif
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::ui::dialogs;
using namespace utl;
using namespace comphelper;
DBG_NAME( ModulWindow )
TYPEINIT1( ModulWindow , IDEBaseWindow );
void lcl_PrintHeader( Printer* pPrinter, sal_uInt16 nPages, sal_uInt16 nCurPage, const String& rTitle, bool bOutput )
{
short nLeftMargin = LMARGPRN;
Size aSz = pPrinter->GetOutputSize();
short nBorder = BORDERPRN;
const Color aOldLineColor( pPrinter->GetLineColor() );
const Color aOldFillColor( pPrinter->GetFillColor() );
const Font aOldFont( pPrinter->GetFont() );
pPrinter->SetLineColor( Color( COL_BLACK ) );
pPrinter->SetFillColor();
Font aFont( aOldFont );
aFont.SetWeight( WEIGHT_BOLD );
aFont.SetAlign( ALIGN_BOTTOM );
pPrinter->SetFont( aFont );
long nFontHeight = pPrinter->GetTextHeight();
// 1.Border => Strich, 2+3 Border = Freiraum.
long nYTop = TMARGPRN-3*nBorder-nFontHeight;
long nXLeft = nLeftMargin-nBorder;
long nXRight = aSz.Width()-RMARGPRN+nBorder;
if( bOutput )
pPrinter->DrawRect( Rectangle(
Point( nXLeft, nYTop ),
Size( nXRight-nXLeft, aSz.Height() - nYTop - BMARGPRN + nBorder ) ) );
long nY = TMARGPRN-2*nBorder;
Point aPos( nLeftMargin, nY );
if( bOutput )
pPrinter->DrawText( aPos, rTitle );
if ( nPages != 1 )
{
aFont.SetWeight( WEIGHT_NORMAL );
pPrinter->SetFont( aFont );
String aPageStr( RTL_CONSTASCII_USTRINGPARAM( " [" ) );
aPageStr += String( IDEResId( RID_STR_PAGE ) );
aPageStr += ' ';
aPageStr += String::CreateFromInt32( nCurPage );
aPageStr += ']';
aPos.X() += pPrinter->GetTextWidth( rTitle );
if( bOutput )
pPrinter->DrawText( aPos, aPageStr );
}
nY = TMARGPRN-nBorder;
if( bOutput )
pPrinter->DrawLine( Point( nXLeft, nY ), Point( nXRight, nY ) );
pPrinter->SetFont( aOldFont );
pPrinter->SetFillColor( aOldFillColor );
pPrinter->SetLineColor( aOldLineColor );
}
void lcl_ConvertTabsToSpaces( String& rLine )
{
if ( rLine.Len() )
{
sal_uInt16 nPos = 0;
sal_uInt16 nMax = rLine.Len();
while ( nPos < nMax )
{
if ( rLine.GetChar( nPos ) == '\t' )
{
// Nicht 4 Blanks, sondern an 4er TabPos:
String aBlanker;
aBlanker.Fill( ( 4 - ( nPos % 4 ) ), ' ' );
rLine.Erase( nPos, 1 );
rLine.Insert( aBlanker, nPos );
nMax = rLine.Len();
}
nPos++; // Nicht optimal, falls Tab, aber auch nicht verkehrt...
}
}
}
ModulWindow::ModulWindow( ModulWindowLayout* pParent, const ScriptDocument& rDocument, String aLibName,
String aName, ::rtl::OUString& aModule )
:IDEBaseWindow( pParent, rDocument, aLibName, aName )
,aXEditorWindow( this )
,m_aModule( aModule )
{
DBG_CTOR( ModulWindow, 0 );
nValid = VALIDWINDOW;
pLayout = pParent;
aXEditorWindow.Show();
SetBackground();
}
SbModuleRef ModulWindow::XModule()
{
// ModuleWindows can now be created as a result of the
// modules getting created via the api. This is a result of an
// elementInserted event from the BasicLibrary container.
// However the SbModule is also created from a different listener to
// the same event ( in basmgr ) Therefore it is possible when we look
// for xModule it may not yet be available, here we keep tring to access
// the module until such time as it exists
if ( !xModule.Is() )
{
BasicManager* pBasMgr = GetDocument().getBasicManager();
if ( pBasMgr )
{
StarBASIC* pBasic = pBasMgr->GetLib( GetLibName() );
if ( pBasic )
{
xBasic = pBasic;
xModule = (SbModule*)pBasic->FindModule( GetName() );
}
}
}
return xModule;
}
ModulWindow::~ModulWindow()
{
DBG_DTOR( ModulWindow, 0 );
nValid = 0;
StarBASIC::Stop();
}
void ModulWindow::GetFocus()
{
if ( nValid != VALIDWINDOW )
return;
DBG_CHKTHIS( ModulWindow, 0 );
aXEditorWindow.GetEdtWindow().GrabFocus();
// Basisklasse nicht rufen, weil Focus jetzt woanders...
}
void ModulWindow::DoInit()
{
DBG_CHKTHIS( ModulWindow, 0 );
// Wird beim Umschalten der Fenster gerufen...
if ( GetVScrollBar() )
GetVScrollBar()->Hide();
GetHScrollBar()->Show();
GetEditorWindow().InitScrollBars();
}
void ModulWindow::Paint( const Rectangle& )
{
}
void ModulWindow::Resize()
{
aXEditorWindow.SetPosSizePixel( Point( 0, 0 ),
Size( GetOutputSizePixel() ) );
}
// "Import" von baside4.cxx
void CreateEngineForBasic( StarBASIC* pBasic );
void ModulWindow::CheckCompileBasic()
{
DBG_CHKTHIS( ModulWindow, 0 );
if ( XModule().Is() )
{
// Zur Laufzeit wird niemals compiliert!
sal_Bool bRunning = StarBASIC::IsRunning();
sal_Bool bModified = ( !xModule->IsCompiled() ||
( GetEditEngine() && GetEditEngine()->IsModified() ) );
if ( !bRunning && bModified )
{
sal_Bool bDone = sal_False;
BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
pIDEShell->GetViewFrame()->GetWindow().EnterWait();
if( bModified )
{
AssertValidEditEngine();
GetEditorWindow().SetSourceInBasic( sal_False );
}
sal_Bool bWasModified = GetBasic()->IsModified();
bDone = GetBasic()->Compile( xModule );
if ( !bWasModified )
GetBasic()->SetModified( sal_False );
if ( bDone )
{
GetBreakPoints().SetBreakPointsInBasic( xModule );
}
pIDEShell->GetViewFrame()->GetWindow().LeaveWait();
aStatus.bError = !bDone;
aStatus.bIsRunning = sal_False;
}
}
}
sal_Bool ModulWindow::BasicExecute()
{
DBG_CHKTHIS( ModulWindow, 0 );
// #116444# check security settings before macro execution
ScriptDocument aDocument( GetDocument() );
if ( aDocument.isDocument() )
{
if ( !aDocument.allowMacros() )
{
WarningBox( this, WB_OK, String( IDEResId( RID_STR_CANNOTRUNMACRO ) ) ).Execute();
return sal_False;
}
}
CheckCompileBasic();
if ( XModule().Is() && xModule->IsCompiled() && !aStatus.bError )
{
if ( GetBreakPoints().size() )
aStatus.nBasicFlags = aStatus.nBasicFlags | SbDEBUG_BREAK;
if ( !aStatus.bIsRunning )
{
DBG_ASSERT( xModule.Is(), "Kein Modul!" );
AddStatus( BASWIN_RUNNINGBASIC );
sal_uInt16 nStart, nEnd, nCurMethodStart = 0;
TextSelection aSel = GetEditView()->GetSelection();
// Init cursor to top
nCurMethodStart = ( aSel.GetStart().GetPara() + 1 );
SbMethod* pMethod = 0;
// erstes Macro, sonst blind "Main" (ExtSearch?)
for ( sal_uInt16 nMacro = 0; nMacro < xModule->GetMethods()->Count(); nMacro++ )
{
SbMethod* pM = (SbMethod*)xModule->GetMethods()->Get( nMacro );
DBG_ASSERT( pM, "Method?" );
pM->GetLineRange( nStart, nEnd );
if ( nCurMethodStart >= nStart && nCurMethodStart <= nEnd )
{
// matched a method to the cursor position
pMethod = pM;
break;
}
}
if ( !pMethod )
{
// If not in a method then prompt the user
return ( BasicIDE::ChooseMacro( uno::Reference< frame::XModel >(), sal_False, rtl::OUString() ).getLength() > 0 ) ? sal_True : sal_False;
}
if ( pMethod )
{
pMethod->SetDebugFlags( aStatus.nBasicFlags );
BasicDLL::SetDebugMode( sal_True );
BasicIDE::RunMethod( pMethod );
BasicDLL::SetDebugMode( sal_False );
// Falls waehrend Interactive=sal_False abgebrochen
BasicDLL::EnableBreak( sal_True );
}
ClearStatus( BASWIN_RUNNINGBASIC );
}
else
aStatus.bIsRunning = sal_False; // Abbruch von Reschedule()
}
sal_Bool bDone = !aStatus.bError;
return bDone;
}
sal_Bool ModulWindow::CompileBasic()
{
DBG_CHKTHIS( ModulWindow, 0 );
CheckCompileBasic();
sal_Bool bIsCompiled = sal_False;
if ( XModule().Is() )
bIsCompiled = xModule->IsCompiled();
return bIsCompiled;
}
sal_Bool ModulWindow::BasicRun()
{
DBG_CHKTHIS( ModulWindow, 0 );
aStatus.nBasicFlags = 0;
sal_Bool bDone = BasicExecute();
return bDone;
}
sal_Bool ModulWindow::BasicStepOver()
{
DBG_CHKTHIS( ModulWindow, 0 );
aStatus.nBasicFlags = SbDEBUG_STEPINTO | SbDEBUG_STEPOVER;
sal_Bool bDone = BasicExecute();
return bDone;
}
sal_Bool ModulWindow::BasicStepInto()
{
DBG_CHKTHIS( ModulWindow, 0 );
aStatus.nBasicFlags = SbDEBUG_STEPINTO;
sal_Bool bDone = BasicExecute();
return bDone;
}
sal_Bool ModulWindow::BasicStepOut()
{
DBG_CHKTHIS( ModulWindow, 0 );
aStatus.nBasicFlags = SbDEBUG_STEPOUT;
sal_Bool bDone = BasicExecute();
return bDone;
}
void ModulWindow::BasicStop()
{
DBG_CHKTHIS( ModulWindow, 0 );
GetBasic()->Stop();
aStatus.bIsRunning = sal_False;
}
sal_Bool ModulWindow::LoadBasic()
{
DBG_CHKTHIS( ModulWindow, 0 );
sal_Bool bDone = sal_False;
Reference< lang::XMultiServiceFactory > xMSF( ::comphelper::getProcessServiceFactory() );
Reference < XFilePicker > xFP;
if( xMSF.is() )
{
Sequence <Any> aServiceType(1);
aServiceType[0] <<= TemplateDescription::FILEOPEN_SIMPLE;
xFP = Reference< XFilePicker >( xMSF->createInstanceWithArguments(
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ) ), aServiceType ), UNO_QUERY );
}
if ( aCurPath.Len() )
xFP->setDisplayDirectory ( aCurPath );
Reference< XFilterManager > xFltMgr(xFP, UNO_QUERY);
xFltMgr->appendFilter( String( RTL_CONSTASCII_USTRINGPARAM( "BASIC" ) ), String( RTL_CONSTASCII_USTRINGPARAM( "*.bas" ) ) );
xFltMgr->appendFilter( String( IDEResId( RID_STR_FILTER_ALLFILES ) ), String( RTL_CONSTASCII_USTRINGPARAM( FILTERMASK_ALL ) ) );
xFltMgr->setCurrentFilter( String( RTL_CONSTASCII_USTRINGPARAM( "BASIC" ) ) );
if( xFP->execute() == RET_OK )
{
Sequence< ::rtl::OUString > aPaths = xFP->getFiles();
aCurPath = aPaths[0];
SfxMedium aMedium( aCurPath, STREAM_READ | STREAM_SHARE_DENYWRITE | STREAM_NOCREATE, sal_True );
SvStream* pStream = aMedium.GetInStream();
if ( pStream )
{
AssertValidEditEngine();
sal_uLong nLines = CalcLineCount( *pStream );
// nLines*4: ReadText/Formatting/Highlighting/Formatting
GetEditorWindow().CreateProgress( String( IDEResId( RID_STR_GENERATESOURCE ) ), nLines*4 );
GetEditEngine()->SetUpdateMode( sal_False );
GetEditView()->Read( *pStream );
GetEditEngine()->SetUpdateMode( sal_True );
GetEditorWindow().Update(); // Es wurde bei UpdateMode = sal_True nur Invalidiert
GetEditorWindow().ForceSyntaxTimeout();
GetEditorWindow().DestroyProgress();
sal_uLong nError = aMedium.GetError();
if ( nError )
ErrorHandler::HandleError( nError );
else
bDone = sal_True;
}
else
ErrorBox( this, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_COULDNTREAD ) ) ).Execute();
}
return bDone;
}
sal_Bool ModulWindow::SaveBasicSource()
{
DBG_CHKTHIS( ModulWindow, 0 );
sal_Bool bDone = sal_False;
Reference< lang::XMultiServiceFactory > xMSF( ::comphelper::getProcessServiceFactory() );
Reference < XFilePicker > xFP;
if( xMSF.is() )
{
Sequence <Any> aServiceType(1);
aServiceType[0] <<= TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD;
xFP = Reference< XFilePicker >( xMSF->createInstanceWithArguments(
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ) ), aServiceType ), UNO_QUERY );
}
Reference< XFilePickerControlAccess > xFPControl(xFP, UNO_QUERY);
xFPControl->enableControl(ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, sal_False);
Any aValue;
aValue <<= (sal_Bool) sal_True;
xFPControl->setValue(ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue);
if ( aCurPath.Len() )
xFP->setDisplayDirectory ( aCurPath );
Reference< XFilterManager > xFltMgr(xFP, UNO_QUERY);
xFltMgr->appendFilter( String( RTL_CONSTASCII_USTRINGPARAM( "BASIC" ) ), String( RTL_CONSTASCII_USTRINGPARAM( "*.bas" ) ) );
xFltMgr->appendFilter( String( IDEResId( RID_STR_FILTER_ALLFILES ) ), String( RTL_CONSTASCII_USTRINGPARAM( FILTERMASK_ALL ) ) );
xFltMgr->setCurrentFilter( String( RTL_CONSTASCII_USTRINGPARAM( "BASIC" ) ) );
if( xFP->execute() == RET_OK )
{
Sequence< ::rtl::OUString > aPaths = xFP->getFiles();
aCurPath = aPaths[0];
SfxMedium aMedium( aCurPath, STREAM_WRITE | STREAM_SHARE_DENYWRITE | STREAM_TRUNC, sal_True, sal_False );
SvStream* pStream = aMedium.GetOutStream();
if ( pStream )
{
EnterWait();
AssertValidEditEngine();
GetEditEngine()->Write( *pStream );
aMedium.Commit();
LeaveWait();
sal_uLong nError = aMedium.GetError();
if ( nError )
ErrorHandler::HandleError( nError );
else
bDone = sal_True;
}
else
ErrorBox( this, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_COULDNTWRITE) ) ).Execute();
}
return bDone;
}
sal_Bool implImportDialog( Window* pWin, const String& rCurPath, const ScriptDocument& rDocument, const String& aLibName );
sal_Bool ModulWindow::ImportDialog()
{
const ScriptDocument& rDocument = GetDocument();
String aLibName = GetLibName();
sal_Bool bRet = implImportDialog( this, aCurPath, rDocument, aLibName );
return bRet;
}
sal_Bool ModulWindow::ToggleBreakPoint( sal_uLong nLine )
{
DBG_ASSERT( XModule().Is(), "Kein Modul!" );
sal_Bool bNewBreakPoint = sal_False;
if ( XModule().Is() )
{
CheckCompileBasic();
if ( aStatus.bError )
{
Sound::Beep();
return sal_False;
}
BreakPoint* pBrk = GetBreakPoints().FindBreakPoint( nLine );
if ( pBrk ) // entfernen
{
xModule->ClearBP( (sal_uInt16)nLine );
delete GetBreakPoints().remove( pBrk );
}
else // einen erzeugen
{
if ( xModule->SetBP( (sal_uInt16)nLine) )
{
GetBreakPoints().InsertSorted( new BreakPoint( nLine ) );
bNewBreakPoint = sal_True;
if ( StarBASIC::IsRunning() )
{
for ( sal_uInt16 nMethod = 0; nMethod < xModule->GetMethods()->Count(); nMethod++ )
{
SbMethod* pMethod = (SbMethod*)xModule->GetMethods()->Get( nMethod );
DBG_ASSERT( pMethod, "Methode nicht gefunden! (NULL)" );
pMethod->SetDebugFlags( pMethod->GetDebugFlags() | SbDEBUG_BREAK );
}
}
}
if ( !bNewBreakPoint )
Sound::Beep();
}
}
return bNewBreakPoint;
}
void ModulWindow::UpdateBreakPoint( const BreakPoint& rBrk )
{
DBG_ASSERT( XModule().Is(), "Kein Modul!" );
if ( XModule().Is() )
{
CheckCompileBasic();
if ( rBrk.bEnabled )
xModule->SetBP( (sal_uInt16)rBrk.nLine );
else
xModule->ClearBP( (sal_uInt16)rBrk.nLine );
}
}
sal_Bool ModulWindow::BasicToggleBreakPoint()
{
DBG_CHKTHIS( ModulWindow, 0 );
AssertValidEditEngine();
TextSelection aSel = GetEditView()->GetSelection();
aSel.GetStart().GetPara()++; // Basic-Zeilen beginnen bei 1!
aSel.GetEnd().GetPara()++;
sal_Bool bNewBreakPoint = sal_False;
for ( sal_uLong nLine = aSel.GetStart().GetPara(); nLine <= aSel.GetEnd().GetPara(); nLine++ )
{
if ( ToggleBreakPoint( nLine ) )
bNewBreakPoint = sal_True;
}
aXEditorWindow.GetBrkWindow().Invalidate();
return bNewBreakPoint;
}
void ModulWindow::BasicToggleBreakPointEnabled()
{
DBG_CHKTHIS( ModulWindow, 0 );
AssertValidEditEngine();
ExtTextView* pView = GetEditView();
if ( pView )
{
TextSelection aSel = pView->GetSelection();
BreakPointList& rList = GetBreakPoints();
for ( sal_uLong nLine = ++aSel.GetStart().GetPara(), nEnd = ++aSel.GetEnd().GetPara(); nLine <= nEnd; ++nLine )
{
BreakPoint* pBrk = rList.FindBreakPoint( nLine );
if ( pBrk )
{
pBrk->bEnabled = pBrk->bEnabled ? sal_False : sal_True;
UpdateBreakPoint( *pBrk );
}
}
GetBreakPointWindow().Invalidate();
}
}
void ModulWindow::ManageBreakPoints()
{
BreakPointWindow& rBrkWin = GetBreakPointWindow();
BreakPointDialog aBrkDlg( &rBrkWin, GetBreakPoints() );
aBrkDlg.Execute();
rBrkWin.Invalidate();
}
IMPL_LINK( ModulWindow, BasicErrorHdl, StarBASIC *, pBasic )
{
DBG_CHKTHIS( ModulWindow, 0 );
GoOnTop();
// ReturnWert: BOOL
// FALSE: Abbrechen
// TRUE: Weiter....
String aErrorText( pBasic->GetErrorText() );
sal_uInt16 nErrorLine = pBasic->GetLine() - 1;
sal_uInt16 nErrCol1 = pBasic->GetCol1();
sal_uInt16 nErrCol2 = pBasic->GetCol2();
if ( nErrCol2 != 0xFFFF )
nErrCol2++;
AssertValidEditEngine();
GetEditView()->SetSelection( TextSelection( TextPaM( nErrorLine, nErrCol1 ), TextPaM( nErrorLine, nErrCol2 ) ) );
String aErrorTextPrefix;
if( pBasic->IsCompilerError() )
{
aErrorTextPrefix = String( IDEResId( RID_STR_COMPILEERROR ) );
}
else
{
aErrorTextPrefix = String( IDEResId( RID_STR_RUNTIMEERROR ) );
aErrorTextPrefix += StarBASIC::GetVBErrorCode( pBasic->GetErrorCode() );
aErrorTextPrefix += ' ';
pLayout->GetStackWindow().UpdateCalls();
}
// Wenn anderes Basic, dan sollte die IDE versuchen, da richtige
// Modul anzuzeigen...
sal_Bool bMarkError = ( pBasic == GetBasic() ) ? sal_True : sal_False;
if ( bMarkError )
aXEditorWindow.GetBrkWindow().SetMarkerPos( nErrorLine, sal_True );
// #i47002#
Reference< awt::XWindow > xWindow = VCLUnoHelper::GetInterface( this );
ErrorHandler::HandleError( StarBASIC::GetErrorCode() );
// #i47002#
Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
if ( !pWindow )
return sal_False;
if ( bMarkError )
aXEditorWindow.GetBrkWindow().SetMarkerPos( MARKER_NOMARKER );
return sal_False;
}
long ModulWindow::BasicBreakHdl( StarBASIC* pBasic )
{
DBG_CHKTHIS( ModulWindow, 0 );
// #i69280 Required in Window despite normal usage in next command!
(void)pBasic;
// ReturnWert: sal_uInt16 => siehe SB-Debug-Flags
sal_uInt16 nErrorLine = pBasic->GetLine();
// Gibt es hier einen BreakPoint?
BreakPoint* pBrk = GetBreakPoints().FindBreakPoint( nErrorLine );
if ( pBrk )
{
pBrk->nHitCount++;
if ( pBrk->nHitCount < pBrk->nStopAfter && GetBasic()->IsBreak() )
return aStatus.nBasicFlags; // weiterlaufen...
}
nErrorLine--; // EditEngine begint bei 0, Basic bei 1
// Alleine schon damit gescrollt wird...
AssertValidEditEngine();
GetEditView()->SetSelection( TextSelection( TextPaM( nErrorLine, 0 ), TextPaM( nErrorLine, 0 ) ) );
aXEditorWindow.GetBrkWindow().SetMarkerPos( nErrorLine );
pLayout->GetWatchWindow().UpdateWatches();
pLayout->GetStackWindow().UpdateCalls();
aStatus.bIsInReschedule = sal_True;
aStatus.bIsRunning = sal_True;
AddStatus( BASWIN_INRESCHEDULE );
BasicIDE::InvalidateDebuggerSlots();
while( aStatus.bIsRunning )
Application::Yield();
aStatus.bIsInReschedule = sal_False;
aXEditorWindow.GetBrkWindow().SetMarkerPos( MARKER_NOMARKER );
ClearStatus( BASWIN_INRESCHEDULE );
return aStatus.nBasicFlags;
}
void ModulWindow::BasicAddWatch()
{
DBG_CHKTHIS( ModulWindow, 0 );
String aWatchStr;
sal_Bool bInserted = sal_False;
AssertValidEditEngine();
sal_Bool bAdd = sal_True;
if ( !GetEditView()->HasSelection() )
{
TextPaM aWordStart;
String aWord = GetEditEngine()->GetWord( GetEditView()->GetSelection().GetEnd(), &aWordStart );
if ( aWord.Len() )
{
TextSelection aSel( aWordStart );
sal_uInt16& rIndex = aSel.GetEnd().GetIndex();
rIndex = rIndex + aWord.Len();
GetEditView()->SetSelection( aSel );
bAdd = sal_True;
}
}
if ( bAdd )
{
TextSelection aSel = GetEditView()->GetSelection();
if ( aSel.GetStart().GetPara() == aSel.GetEnd().GetPara() )
{
aWatchStr = GetEditView()->GetSelected();
pLayout->GetWatchWindow().AddWatch( aWatchStr );
pLayout->GetWatchWindow().UpdateWatches();
bInserted = sal_True;
}
}
if ( !bInserted )
Sound::Beep();
}
void ModulWindow::BasicRemoveWatch()
{
DBG_CHKTHIS( ModulWindow, 0 );
sal_Bool bRemoved = pLayout->GetWatchWindow().RemoveSelectedWatch();
if ( !bRemoved )
Sound::Beep();
}
void ModulWindow::EditMacro( const String& rMacroName )
{
DBG_CHKTHIS( ModulWindow, 0 );
DBG_ASSERT( XModule().Is(), "Kein Modul!" );
if ( XModule().Is() )
{
CheckCompileBasic();
if ( !aStatus.bError )
{
sal_uInt16 nStart, nEnd;
SbMethod* pMethod = (SbMethod*)xModule->Find( rMacroName, SbxCLASS_METHOD );
if ( pMethod )
{
pMethod->GetLineRange( nStart, nEnd );
if ( nStart )
{
// Basic beginnt bei 1
nStart--;
nEnd--;
}
TextSelection aSel( TextPaM( nStart, 0 ), TextPaM( nStart, 0 ) );
AssertValidEditEngine();
TextView * pView = GetEditView();
// ggf. hinscrollen, so dass erste Zeile oben...
long nVisHeight = GetOutputSizePixel().Height();
if ( (long)pView->GetTextEngine()->GetTextHeight() > nVisHeight )
{
long nMaxY = pView->GetTextEngine()->GetTextHeight() - nVisHeight;
long nOldStartY = pView->GetStartDocPos().Y();
long nNewStartY = nStart * pView->GetTextEngine()->GetCharHeight();
nNewStartY = Min( nNewStartY, nMaxY );
pView->Scroll( 0, -(nNewStartY-nOldStartY) );
pView->ShowCursor( sal_False, sal_True );
GetEditVScrollBar().SetThumbPos( pView->GetStartDocPos().Y() );
}
pView->SetSelection( aSel );
pView->ShowCursor();
pView->GetWindow()->GrabFocus();
}
}
}
}
void ModulWindow::StoreData()
{
DBG_CHKTHIS( ModulWindow, 0 );
// StoreData wird gerufen, wenn der BasicManager zerstoert oder
// dieses Fenster beendet wird.
// => Keine Unterbrechungen erwuenscht!
// Und bei SAVE, wenn AppBasic...
GetEditorWindow().SetSourceInBasic( sal_True );
}
sal_Bool ModulWindow::CanClose()
{
DBG_CHKTHIS( ModulWindow, 0 );
return sal_True;
}
sal_Bool ModulWindow::AllowUndo()
{
return GetEditorWindow().CanModify();
}
void ModulWindow::UpdateData()
{
DBG_CHKTHIS( ModulWindow, 0 );
DBG_ASSERT( XModule().Is(), "Kein Modul!" );
// UpdateData wird gerufen, wenn sich der Source von aussen
// geaendert hat.
// => Keine Unterbrechungen erwuenscht!
if ( XModule().Is() )
{
SetModule( xModule->GetSource32() );
if ( GetEditView() )
{
TextSelection aSel = GetEditView()->GetSelection();
setTextEngineText( GetEditEngine(), xModule->GetSource32() );
GetEditView()->SetSelection( aSel );
GetEditEngine()->SetModified( sal_False );
BasicIDE::MarkDocumentModified( GetDocument() );
}
}
}
sal_Int32 ModulWindow::countPages( Printer* pPrinter )
{
return FormatAndPrint( pPrinter, -1 );
}
void ModulWindow::printPage( sal_Int32 nPage, Printer* pPrinter )
{
FormatAndPrint( pPrinter, nPage );
}
/* implementation note: this is totally inefficient for the XRenderable interface
usage since the whole "document" will be format for every page. Should this ever
become a problem we should
- format only once for every new printer
- keep an index list for each page which is the starting paragraph
*/
sal_Int32 ModulWindow::FormatAndPrint( Printer* pPrinter, sal_Int32 nPrintPage )
{
DBG_CHKTHIS( ModulWindow, 0 );
AssertValidEditEngine();
MapMode eOldMapMode( pPrinter->GetMapMode() );
Font aOldFont( pPrinter->GetFont() );
Font aFont( GetEditEngine()->GetFont() );
aFont.SetAlign( ALIGN_BOTTOM );
aFont.SetTransparent( sal_True );
aFont.SetSize( Size( 0, 360 ) );
pPrinter->SetFont( aFont );
pPrinter->SetMapMode( MAP_100TH_MM );
String aTitle( CreateQualifiedName() );
sal_uInt16 nLineHeight = (sal_uInt16) pPrinter->GetTextHeight(); // etwas mehr.
sal_uInt16 nParaSpace = 10;
Size aPaperSz = pPrinter->GetOutputSize();
aPaperSz.Width() -= (LMARGPRN+RMARGPRN);
aPaperSz.Height() -= (TMARGPRN+BMARGPRN);
// nLinepPage stimmt nicht, wenn Zeilen umgebrochen werden muessen...
sal_uInt16 nLinespPage = (sal_uInt16) (aPaperSz.Height()/nLineHeight);
sal_uInt16 nCharspLine = (sal_uInt16) (aPaperSz.Width() / pPrinter->GetTextWidth( 'X' ) );
sal_uLong nParas = GetEditEngine()->GetParagraphCount();
sal_uInt16 nPages = (sal_uInt16) (nParas/nLinespPage+1 );
sal_uInt16 nCurPage = 1;
// Header drucken...
lcl_PrintHeader( pPrinter, nPages, nCurPage, aTitle, nPrintPage == 0 );
Point aPos( LMARGPRN, TMARGPRN );
for ( sal_uLong nPara = 0; nPara < nParas; nPara++ )
{
String aLine( GetEditEngine()->GetText( nPara ) );
lcl_ConvertTabsToSpaces( aLine );
sal_uInt16 nLines = aLine.Len()/nCharspLine+1;
for ( sal_uInt16 nLine = 0; nLine < nLines; nLine++ )
{
String aTmpLine( aLine, nLine*nCharspLine, nCharspLine );
aPos.Y() += nLineHeight;
if ( aPos.Y() > ( aPaperSz.Height()+TMARGPRN ) )
{
nCurPage++;
lcl_PrintHeader( pPrinter, nPages, nCurPage, aTitle, nCurPage-1 == nPrintPage );
aPos = Point( LMARGPRN, TMARGPRN+nLineHeight );
}
if( nCurPage-1 == nPrintPage )
pPrinter->DrawText( aPos, aTmpLine );
}
aPos.Y() += nParaSpace;
}
pPrinter->SetFont( aOldFont );
pPrinter->SetMapMode( eOldMapMode );
return sal_Int32(nCurPage);
}
void ModulWindow::ExecuteCommand( SfxRequest& rReq )
{
DBG_CHKTHIS( ModulWindow, 0 );
AssertValidEditEngine();
sal_uInt16 nSlot = rReq.GetSlot();
switch ( nSlot )
{
case SID_DELETE:
{
KeyEvent aFakeDelete( 0, KEY_DELETE );
GetEditView()->KeyInput( aFakeDelete );
break;
}
case SID_SELECTALL:
GetEditView()->SetSelection( TextSelection( TextPaM( 0, 0 ), TextPaM( 0xFFFFFFFF, 0xFFFF ) ) );
break;
case SID_BASICRUN:
{
BasicRun();
}
break;
case SID_BASICCOMPILE:
{
CompileBasic();
}
break;
case SID_BASICSTEPOVER:
{
BasicStepOver();
}
break;
case SID_BASICSTEPINTO:
{
BasicStepInto();
}
break;
case SID_BASICSTEPOUT:
{
BasicStepOut();
}
break;
case SID_BASICLOAD:
{
LoadBasic();
}
break;
case SID_BASICSAVEAS:
{
SaveBasicSource();
}
break;
case SID_IMPORT_DIALOG:
{
ImportDialog();
}
break;
case SID_BASICIDE_MATCHGROUP:
{
if ( !GetEditView()->MatchGroup() )
Sound::Beep();
}
break;
case SID_BASICIDE_TOGGLEBRKPNT:
{
BasicToggleBreakPoint();
}
break;
case SID_BASICIDE_MANAGEBRKPNTS:
{
ManageBreakPoints();
}
break;
case SID_BASICIDE_TOGGLEBRKPNTENABLED:
{
BasicToggleBreakPointEnabled();
}
break;
case SID_BASICIDE_ADDWATCH:
{
BasicAddWatch();
}
break;
case SID_BASICIDE_REMOVEWATCH:
{
BasicRemoveWatch();
}
break;
case SID_CUT:
{
if ( !IsReadOnly() )
{
GetEditView()->Cut();
SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
if ( pBindings )
pBindings->Invalidate( SID_DOC_MODIFIED );
}
}
break;
case SID_COPY:
{
GetEditView()->Copy();
}
break;
case SID_PASTE:
{
if ( !IsReadOnly() )
{
GetEditView()->Paste();
SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
if ( pBindings )
pBindings->Invalidate( SID_DOC_MODIFIED );
}
}
break;
case SID_BASICIDE_BRKPNTSCHANGED:
{
GetBreakPointWindow().Invalidate();
}
break;
}
}
void ModulWindow::GetState( SfxItemSet &rSet )
{
DBG_CHKTHIS( ModulWindow, 0 );
SfxWhichIter aIter(rSet);
for ( sal_uInt16 nWh = aIter.FirstWhich(); 0 != nWh; nWh = aIter.NextWhich() )
{
switch ( nWh )
{
// allgemeine Items:
case SID_CUT:
{
if ( !GetEditView() || !GetEditView()->HasSelection() )
rSet.DisableItem( nWh );
if ( IsReadOnly() )
rSet.DisableItem( nWh );
}
break;
case SID_COPY:
{
if ( !GetEditView() || !GetEditView()->HasSelection() )
rSet.DisableItem( nWh );
}
break;
case SID_PASTE:
{
if ( !IsPasteAllowed() )
rSet.DisableItem( nWh );
if ( IsReadOnly() )
rSet.DisableItem( nWh );
}
break;
case SID_BASICIDE_STAT_POS:
{
TextView* pView = GetEditView();
if ( pView )
{
TextSelection aSel = pView->GetSelection();
String aPos( IDEResId( RID_STR_LINE ) );
aPos += ' ';
aPos += String::CreateFromInt32( aSel.GetEnd().GetPara()+1 );
aPos += String( RTL_CONSTASCII_USTRINGPARAM( ", " ) );
aPos += String( IDEResId( RID_STR_COLUMN ) );
aPos += ' ';
aPos += String::CreateFromInt32( aSel.GetEnd().GetIndex()+1 );
SfxStringItem aItem( SID_BASICIDE_STAT_POS, aPos );
rSet.Put( aItem );
}
}
break;
case SID_ATTR_INSERT:
{
TextView* pView = GetEditView();
if ( pView )
{
SfxBoolItem aItem( SID_ATTR_INSERT, pView->IsInsertMode() );
rSet.Put( aItem );
}
}
break;
}
}
}
void ModulWindow::DoScroll( ScrollBar* pCurScrollBar )
{
DBG_CHKTHIS( ModulWindow, 0 );
if ( ( pCurScrollBar == GetHScrollBar() ) && GetEditView() )
{
// Nicht mit dem Wert Scrollen, sondern lieber die Thumb-Pos fuer die
// VisArea verwenden:
long nDiff = GetEditView()->GetStartDocPos().X() - pCurScrollBar->GetThumbPos();
GetEditView()->Scroll( nDiff, 0 );
GetEditView()->ShowCursor( sal_False, sal_True );
pCurScrollBar->SetThumbPos( GetEditView()->GetStartDocPos().X() );
}
}
sal_Bool ModulWindow::IsModified()
{
return GetEditEngine() ? GetEditEngine()->IsModified() : sal_False;
}
void ModulWindow::GoOnTop()
{
IDE_DLL()->GetShell()->GetViewFrame()->ToTop();
}
String ModulWindow::GetSbModuleName()
{
String aModuleName;
if ( XModule().Is() )
aModuleName = xModule->GetName();
return aModuleName;
}
String ModulWindow::GetTitle()
{
return GetSbModuleName();
}
void ModulWindow::FrameWindowMoved()
{
}
void ModulWindow::ShowCursor( sal_Bool bOn )
{
if ( GetEditEngine() )
{
TextView* pView = GetEditEngine()->GetActiveView();
if ( pView )
{
if ( bOn )
pView->ShowCursor();
else
pView->HideCursor();
}
}
}
Window* ModulWindow::GetLayoutWindow()
{
return pLayout;
}
void ModulWindow::AssertValidEditEngine()
{
if ( !GetEditEngine() )
GetEditorWindow().CreateEditEngine();
}
void ModulWindow::Deactivating()
{
if ( GetEditView() )
GetEditView()->EraseVirtualDevice();
}
sal_uInt16 ModulWindow::StartSearchAndReplace( const SvxSearchItem& rSearchItem, sal_Bool bFromStart )
{
// Mann koennte fuer das blinde Alle-Ersetzen auch auf
// Syntaxhighlighting/Formatierung verzichten...
AssertValidEditEngine();
ExtTextView* pView = GetEditView();
TextSelection aSel;
if ( bFromStart )
{
aSel = pView->GetSelection();
if ( !rSearchItem.GetBackward() )
pView->SetSelection( TextSelection() );
else
pView->SetSelection( TextSelection( TextPaM( 0xFFFFFFFF, 0xFFFF ), TextPaM( 0xFFFFFFFF, 0xFFFF ) ) );
}
sal_Bool bForward = !rSearchItem.GetBackward();
sal_uInt16 nFound = 0;
if ( ( rSearchItem.GetCommand() == SVX_SEARCHCMD_FIND ) ||
( rSearchItem.GetCommand() == SVX_SEARCHCMD_FIND_ALL ) )
{
nFound = pView->Search( rSearchItem.GetSearchOptions() , bForward );
}
else if ( ( rSearchItem.GetCommand() == SVX_SEARCHCMD_REPLACE ) ||
( rSearchItem.GetCommand() == SVX_SEARCHCMD_REPLACE_ALL ) )
{
if ( !IsReadOnly() )
{
sal_Bool bAll = rSearchItem.GetCommand() == SVX_SEARCHCMD_REPLACE_ALL;
nFound = pView->Replace( rSearchItem.GetSearchOptions() , bAll , bForward );
}
}
if ( bFromStart && !nFound )
pView->SetSelection( aSel );
return nFound;
}
::svl::IUndoManager* ModulWindow::GetUndoManager()
{
if ( GetEditEngine() )
return &GetEditEngine()->GetUndoManager();
return NULL;
}
sal_uInt16 ModulWindow::GetSearchOptions()
{
sal_uInt16 nOptions = SEARCH_OPTIONS_SEARCH |
SEARCH_OPTIONS_WHOLE_WORDS |
SEARCH_OPTIONS_BACKWARDS |
SEARCH_OPTIONS_REG_EXP |
SEARCH_OPTIONS_EXACT |
SEARCH_OPTIONS_SELECTION |
SEARCH_OPTIONS_SIMILARITY;
if ( !IsReadOnly() )
{
nOptions |= SEARCH_OPTIONS_REPLACE;
nOptions |= SEARCH_OPTIONS_REPLACE_ALL;
}
return nOptions;
}
void ModulWindow::BasicStarted()
{
if ( XModule().Is() )
{
aStatus.bIsRunning = sal_True;
BreakPointList& rList = GetBreakPoints();
if ( rList.size() )
{
rList.ResetHitCount();
rList.SetBreakPointsInBasic( xModule );
for ( sal_uInt16 nMethod = 0; nMethod < xModule->GetMethods()->Count(); nMethod++ )
{
SbMethod* pMethod = (SbMethod*)xModule->GetMethods()->Get( nMethod );
DBG_ASSERT( pMethod, "Methode nicht gefunden! (NULL)" );
pMethod->SetDebugFlags( pMethod->GetDebugFlags() | SbDEBUG_BREAK );
}
}
}
}
void ModulWindow::BasicStopped()
{
aStatus.bIsRunning = sal_False;
GetBreakPointWindow().SetMarkerPos( MARKER_NOMARKER );
}
BasicEntryDescriptor ModulWindow::CreateEntryDescriptor()
{
ScriptDocument aDocument( GetDocument() );
String aLibName( GetLibName() );
LibraryLocation eLocation = aDocument.getLibraryLocation( aLibName );
String aModName( GetName() );
String aLibSubName;
if( xBasic.Is() && aDocument.isInVBAMode() && XModule().Is() )
{
switch( xModule->GetModuleType() )
{
case script::ModuleType::DOCUMENT:
{
aLibSubName = String( IDEResId( RID_STR_DOCUMENT_OBJECTS ) );
uno::Reference< container::XNameContainer > xLib = aDocument.getOrCreateLibrary( E_SCRIPTS, aLibName );
if( xLib.is() )
{
String sObjName;
ModuleInfoHelper::getObjectName( xLib, aModName, sObjName );
if( sObjName.Len() )
{
aModName.AppendAscii(" (").Append(sObjName).AppendAscii(")");
}
}
break;
}
case script::ModuleType::FORM:
aLibSubName = String( IDEResId( RID_STR_USERFORMS ) );
break;
case script::ModuleType::NORMAL:
aLibSubName = String( IDEResId( RID_STR_NORMAL_MODULES ) );
break;
case script::ModuleType::CLASS:
aLibSubName = String( IDEResId( RID_STR_CLASS_MODULES ) );
break;
}
}
return BasicEntryDescriptor( aDocument, eLocation, aLibName, aLibSubName, aModName, OBJ_TYPE_MODULE );
}
void ModulWindow::SetReadOnly( sal_Bool b )
{
if ( GetEditView() )
GetEditView()->SetReadOnly( b );
}
sal_Bool ModulWindow::IsReadOnly()
{
sal_Bool bReadOnly = sal_False;
if ( GetEditView() )
bReadOnly = GetEditView()->IsReadOnly();
return bReadOnly;
}
sal_Bool ModulWindow::IsPasteAllowed()
{
sal_Bool bPaste = sal_False;
// get clipboard
Reference< datatransfer::clipboard::XClipboard > xClipboard = GetClipboard();
if ( xClipboard.is() )
{
// get clipboard content
const sal_uInt32 nRef = Application::ReleaseSolarMutex();
Reference< datatransfer::XTransferable > xTransf = xClipboard->getContents();
Application::AcquireSolarMutex( nRef );
if ( xTransf.is() )
{
datatransfer::DataFlavor aFlavor;
SotExchange::GetFormatDataFlavor( SOT_FORMAT_STRING, aFlavor );
if ( xTransf->isDataFlavorSupported( aFlavor ) )
{
bPaste = sal_True;
}
}
}
return bPaste;
}
ModulWindowLayout::ModulWindowLayout( Window* pParent ) :
Window( pParent, WB_CLIPCHILDREN ),
aVSplitter( this, WinBits( WB_VSCROLL ) ),
aHSplitter( this, WinBits( WB_HSCROLL ) ),
aWatchWindow( this ),
aStackWindow( this ),
bVSplitted(sal_False),
bHSplitted(sal_False),
m_pModulWindow(0),
m_aImagesNormal(IDEResId(RID_IMGLST_LAYOUT))
{
SetBackground(GetSettings().GetStyleSettings().GetWindowColor());
aVSplitter.SetSplitHdl( LINK( this, ModulWindowLayout, SplitHdl ) );
aHSplitter.SetSplitHdl( LINK( this, ModulWindowLayout, SplitHdl ) );
aVSplitter.Show();
aHSplitter.Show();
aWatchWindow.Show();
aStackWindow.Show();
Color aColor(GetSettings().GetStyleSettings().GetFieldTextColor());
m_aSyntaxColors[TT_UNKNOWN] = aColor;
m_aSyntaxColors[TT_WHITESPACE] = aColor;
m_aSyntaxColors[TT_EOL] = aColor;
m_aColorConfig.AddListener(this);
m_aSyntaxColors[TT_IDENTIFIER]
= Color(m_aColorConfig.GetColorValue(svtools::BASICIDENTIFIER).nColor);
m_aSyntaxColors[TT_NUMBER]
= Color(m_aColorConfig.GetColorValue(svtools::BASICNUMBER).nColor);
m_aSyntaxColors[TT_STRING]
= Color(m_aColorConfig.GetColorValue(svtools::BASICSTRING).nColor);
m_aSyntaxColors[TT_COMMENT]
= Color(m_aColorConfig.GetColorValue(svtools::BASICCOMMENT).nColor);
m_aSyntaxColors[TT_ERROR]
= Color(m_aColorConfig.GetColorValue(svtools::BASICERROR).nColor);
m_aSyntaxColors[TT_OPERATOR]
= Color(m_aColorConfig.GetColorValue(svtools::BASICOPERATOR).nColor);
m_aSyntaxColors[TT_KEYWORDS]
= Color(m_aColorConfig.GetColorValue(svtools::BASICKEYWORD).nColor);
Font aFont( GetFont() );
Size aSz( aFont.GetSize() );
aSz.Height() *= 3;
aSz.Height() /= 2;
aFont.SetSize( aSz );
aFont.SetWeight( WEIGHT_BOLD );
aFont.SetColor(GetSettings().GetStyleSettings().GetWindowTextColor());
SetFont( aFont );
}
ModulWindowLayout::~ModulWindowLayout()
{
m_aColorConfig.RemoveListener(this);
}
void ModulWindowLayout::Resize()
{
// ScrollBars, etc. passiert in BasicIDEShell:Adjust...
ArrangeWindows();
}
void ModulWindowLayout::Paint( const Rectangle& )
{
DrawText( Point(), String( IDEResId( RID_STR_NOMODULE ) ) );
}
void ModulWindowLayout::ArrangeWindows()
{
Size aSz = GetOutputSizePixel();
// prueffen, ob der Splitter in einem gueltigen Bereich liegt...
long nMinPos = SPLIT_MARGIN;
long nMaxPos = aSz.Height() - SPLIT_MARGIN;
long nVSplitPos = aVSplitter.GetSplitPosPixel();
long nHSplitPos = aHSplitter.GetSplitPosPixel();
if ( !bVSplitted )
{
// Wenn noch nie gesplitted wurde, Verhaeltniss = 3 : 4
nVSplitPos = aSz.Height() * 3 / 4;
aVSplitter.SetSplitPosPixel( nVSplitPos );
}
if ( !bHSplitted )
{
// Wenn noch nie gesplitted wurde, Verhaeltniss = 2 : 3
nHSplitPos = aSz.Width() * 2 / 3;
aHSplitter.SetSplitPosPixel( nHSplitPos );
}
if ( ( nVSplitPos < nMinPos ) || ( nVSplitPos > nMaxPos ) )
nVSplitPos = ( nVSplitPos < nMinPos ) ? 0 : ( aSz.Height() - SPLIT_HEIGHT );
Size aXEWSz;
aXEWSz.Width() = aSz.Width();
aXEWSz.Height() = nVSplitPos + 1;
if ( m_pModulWindow )
{
DBG_CHKOBJ( m_pModulWindow, ModulWindow, 0 );
m_pModulWindow->SetPosSizePixel( Point( 0, 0 ), aXEWSz );
}
aVSplitter.SetDragRectPixel( Rectangle( Point( 0, 0 ), Size( aSz.Width(), aSz.Height() ) ) );
aVSplitter.SetPosPixel( Point( 0, nVSplitPos ) );
aVSplitter.SetSizePixel( Size( aSz.Width(), SPLIT_HEIGHT ) );
aHSplitter.SetDragRectPixel( Rectangle( Point( 0, nVSplitPos+SPLIT_HEIGHT ), Size( aSz.Width(), aSz.Height() - nVSplitPos - SPLIT_HEIGHT ) ) );
aHSplitter.SetPosPixel( Point( nHSplitPos, nVSplitPos ) );
aHSplitter.SetSizePixel( Size( SPLIT_HEIGHT, aSz.Height() - nVSplitPos ) );
Size aWWSz;
Point aWWPos( 0, nVSplitPos+SPLIT_HEIGHT );
aWWSz.Width() = nHSplitPos;
aWWSz.Height() = aSz.Height() - aWWPos.Y();
if ( !aWatchWindow.IsFloatingMode() )
aWatchWindow.SetPosSizePixel( aWWPos, aWWSz );
Size aSWSz;
Point aSWPos( nHSplitPos+SPLIT_HEIGHT, nVSplitPos+SPLIT_HEIGHT );
aSWSz.Width() = aSz.Width() - aSWPos.X();
aSWSz.Height() = aSz.Height() - aSWPos.Y();
if ( !aStackWindow.IsFloatingMode() )
aStackWindow.SetPosSizePixel( aSWPos, aSWSz );
if ( aStackWindow.IsFloatingMode() && aWatchWindow.IsFloatingMode() )
aHSplitter.Hide();
else
aHSplitter.Show();
long nHDoubleClickSplitPosX = aSz.Width()-aHSplitter.GetSizePixel().Width();
if ( aHSplitter.GetSplitPosPixel() < nHDoubleClickSplitPosX )
aHSplitter.SetLastSplitPosPixel( nHDoubleClickSplitPosX );
long nHDoubleClickSplitPosY = aSz.Height()-aVSplitter.GetSizePixel().Height();
if ( aVSplitter.GetSplitPosPixel() < nHDoubleClickSplitPosY )
aVSplitter.SetLastSplitPosPixel( nHDoubleClickSplitPosY );
}
IMPL_LINK( ModulWindowLayout, SplitHdl, Splitter *, pSplitter )
{
if ( pSplitter == &aVSplitter )
bVSplitted = sal_True;
else
bHSplitted = sal_True;
ArrangeWindows();
return 0;
}
sal_Bool ModulWindowLayout::IsToBeDocked( DockingWindow* pDockingWindow, const Point& rPos, Rectangle& rRect )
{
// prueffen, ob als Dock oder als Child:
// TRUE: Floating
// FALSE: Child
Point aPosInMe = ScreenToOutputPixel( rPos );
Size aSz = GetOutputSizePixel();
if ( ( aPosInMe.X() > 0 ) && ( aPosInMe.X() < aSz.Width() ) &&
( aPosInMe.Y() > 0 ) && ( aPosInMe.Y() < aSz.Height() ) )
{
long nVSplitPos = aVSplitter.GetSplitPosPixel();
long nHSplitPos = aHSplitter.GetSplitPosPixel();
if ( pDockingWindow == &aWatchWindow )
{
if ( ( aPosInMe.Y() > nVSplitPos ) && ( aPosInMe.X() < nHSplitPos ) )
{
rRect.SetSize( Size( nHSplitPos, aSz.Height() - nVSplitPos ) );
rRect.SetPos( OutputToScreenPixel( Point( 0, nVSplitPos ) ) );
return sal_True;
}
}
if ( pDockingWindow == &aStackWindow )
{
if ( ( aPosInMe.Y() > nVSplitPos ) && ( aPosInMe.X() > nHSplitPos ) )
{
rRect.SetSize( Size( aSz.Width() - nHSplitPos, aSz.Height() - nVSplitPos ) );
rRect.SetPos( OutputToScreenPixel( Point( nHSplitPos, nVSplitPos ) ) );
return sal_True;
}
}
}
return sal_False;
}
void ModulWindowLayout::DockaWindow( DockingWindow* pDockingWindow )
{
if ( pDockingWindow == &aWatchWindow )
{
// evtl. Sonderbehandlung...
ArrangeWindows();
}
else if ( pDockingWindow == &aStackWindow )
{
// evtl. Sonderbehandlung...
ArrangeWindows();
}
#if OSL_DEBUG_LEVEL > 0
else
OSL_FAIL( "Wer will sich denn hier andocken ?" );
#endif
}
void ModulWindowLayout::SetModulWindow( ModulWindow* pModWin )
{
m_pModulWindow = pModWin;
ArrangeWindows();
}
// virtual
void ModulWindowLayout::DataChanged(DataChangedEvent const & rDCEvt)
{
Window::DataChanged(rDCEvt);
if (rDCEvt.GetType() == DATACHANGED_SETTINGS
&& (rDCEvt.GetFlags() & SETTINGS_STYLE) != 0)
{
bool bInvalidate = false;
Color aColor(GetSettings().GetStyleSettings().GetWindowColor());
if (aColor
!= rDCEvt.GetOldSettings()->GetStyleSettings().GetWindowColor())
{
SetBackground(Wallpaper(aColor));
bInvalidate = true;
}
aColor = GetSettings().GetStyleSettings().GetWindowTextColor();
if (aColor != rDCEvt.GetOldSettings()->
GetStyleSettings().GetWindowTextColor())
{
Font aFont(GetFont());
aFont.SetColor(aColor);
SetFont(aFont);
bInvalidate = true;
}
if (bInvalidate)
Invalidate();
aColor = GetSettings().GetStyleSettings().GetFieldTextColor();
if (aColor != m_aSyntaxColors[TT_UNKNOWN])
{
m_aSyntaxColors[TT_UNKNOWN] = aColor;
m_aSyntaxColors[TT_WHITESPACE] = aColor;
m_aSyntaxColors[TT_EOL] = aColor;
updateSyntaxHighlighting();
}
}
}
// virtual
void ModulWindowLayout::ConfigurationChanged( utl::ConfigurationBroadcaster*, sal_uInt32 )
{
{
Color aColor(m_aColorConfig.GetColorValue(svtools::BASICIDENTIFIER).
nColor);
bool bChanged = aColor != m_aSyntaxColors[TT_IDENTIFIER];
m_aSyntaxColors[TT_IDENTIFIER] = aColor;
aColor = Color(m_aColorConfig.GetColorValue(svtools::BASICNUMBER).nColor);
if (bChanged || aColor != m_aSyntaxColors[TT_NUMBER])
bChanged = true;
m_aSyntaxColors[TT_NUMBER] = aColor;
aColor = Color(m_aColorConfig.GetColorValue(svtools::BASICSTRING).nColor);
if (bChanged || aColor != m_aSyntaxColors[TT_STRING])
bChanged = true;
m_aSyntaxColors[TT_STRING] = aColor;
aColor = Color(m_aColorConfig.GetColorValue(svtools::BASICCOMMENT).
nColor);
if (bChanged || aColor != m_aSyntaxColors[TT_COMMENT])
bChanged = true;
m_aSyntaxColors[TT_COMMENT] = aColor;
aColor = Color(m_aColorConfig.GetColorValue(svtools::BASICERROR).nColor);
if (bChanged || aColor != m_aSyntaxColors[TT_ERROR])
bChanged = true;
m_aSyntaxColors[TT_ERROR] = aColor;
aColor = Color(m_aColorConfig.GetColorValue(svtools::BASICOPERATOR).
nColor);
if (bChanged || aColor != m_aSyntaxColors[TT_OPERATOR])
bChanged = true;
m_aSyntaxColors[TT_OPERATOR] = aColor;
aColor = Color(m_aColorConfig.GetColorValue(svtools::BASICKEYWORD).
nColor);
if (bChanged || aColor != m_aSyntaxColors[TT_KEYWORDS])
bChanged = true;
m_aSyntaxColors[TT_KEYWORDS] = aColor;
if (bChanged)
updateSyntaxHighlighting();
}
}
void ModulWindowLayout::updateSyntaxHighlighting()
{
if (m_pModulWindow != 0)
{
EditorWindow & rEditor = m_pModulWindow->GetEditorWindow();
sal_uLong nCount = rEditor.GetEditEngine()->GetParagraphCount();
for (sal_uLong i = 0; i < nCount; ++i)
rEditor.DoDelayedSyntaxHighlight(i);
}
}
Image ModulWindowLayout::getImage(sal_uInt16 nId) const
{
return m_aImagesNormal.GetImage(nId);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|