update dev300-m58
[ooovba.git] / basctl / source / basicide / baside2.cxx
blob098094652d41eb475ec91765d50e066aa4641308
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: baside2.cxx,v $
10 * $Revision: 1.46.2.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basctl.hxx"
35 #include <ide_pch.hxx>
38 #include <svtools/texteng.hxx>
39 #include <svtools/textview.hxx>
40 #include <svtools/xtextedt.hxx>
41 #include <basic/sbx.hxx>
42 #include <comphelper/processfactory.hxx>
43 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
44 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
45 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
46 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
47 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
48 #ifndef _COM_SUN_STAR_SCRIPT_XLIBRYARYCONTAINER2_HPP_
49 #include <com/sun/star/script/XLibraryContainer2.hpp>
50 #endif
51 #include <com/sun/star/document/MacroExecMode.hpp>
52 #include <com/sun/star/script/ModuleType.hpp>
53 #include <toolkit/helper/vclunohelper.hxx>
54 #include <sfx2/docfile.hxx>
55 #include <basic/basrdll.hxx>
58 #include <baside2.hrc>
59 #include <baside2.hxx>
60 #include <objdlg.hxx>
61 #include <iderdll.hxx>
62 #include <iderdll2.hxx>
64 #include <basobj.hxx>
65 #include <brkdlg.hxx>
67 #include <svx/srchdlg.hxx>
69 #include <vcl/sound.hxx>
71 //#ifndef _TXTCMP_HXX //autogen
72 //#include <svtools/txtcmp.hxx>
73 //#endif
75 #include <unotools/textsearch.hxx>
76 #include <tools/diagnose_ex.h>
78 using namespace ::com::sun::star;
79 using namespace ::com::sun::star::uno;
82 #define SPLIT_MARGIN 5
83 #define SPLIT_HEIGHT 2
85 #define LMARGPRN 1700
86 #define RMARGPRN 900
87 #define TMARGPRN 2000
88 #define BMARGPRN 1000
89 #define BORDERPRN 300
91 #define APPWAIT_START 100
93 #define VALIDWINDOW 0x1234
95 #if defined(OW) || defined(MTF)
96 #define FILTERMASK_ALL "*"
97 #elif defined(PM2)
98 #define FILTERMASK_ALL ""
99 #else
100 #define FILTERMASK_ALL "*.*"
101 #endif
103 using namespace ::com::sun::star;
104 using namespace ::com::sun::star::uno;
105 using namespace ::com::sun::star::ui::dialogs;
106 using namespace utl;
107 using namespace comphelper;
110 DBG_NAME( ModulWindow )
112 TYPEINIT1( ModulWindow , IDEBaseWindow );
114 void lcl_getObjectName( const uno::Reference< container::XNameContainer >& rLib, const String& rModName, String& rObjName );
116 void lcl_PrintHeader( Printer* pPrinter, USHORT nPages, USHORT nCurPage, const String& rTitle )
118 short nLeftMargin = LMARGPRN;
119 Size aSz = pPrinter->GetOutputSize();
120 short nBorder = BORDERPRN;
122 const Color aOldLineColor( pPrinter->GetLineColor() );
123 const Color aOldFillColor( pPrinter->GetFillColor() );
124 const Font aOldFont( pPrinter->GetFont() );
126 pPrinter->SetLineColor( Color( COL_BLACK ) );
127 pPrinter->SetFillColor();
129 Font aFont( aOldFont );
130 aFont.SetWeight( WEIGHT_BOLD );
131 aFont.SetAlign( ALIGN_BOTTOM );
132 pPrinter->SetFont( aFont );
134 long nFontHeight = pPrinter->GetTextHeight();
136 // 1.Border => Strich, 2+3 Border = Freiraum.
137 long nYTop = TMARGPRN-3*nBorder-nFontHeight;
139 long nXLeft = nLeftMargin-nBorder;
140 long nXRight = aSz.Width()-RMARGPRN+nBorder;
142 pPrinter->DrawRect( Rectangle(
143 Point( nXLeft, nYTop ),
144 Size( nXRight-nXLeft, aSz.Height() - nYTop - BMARGPRN + nBorder ) ) );
147 long nY = TMARGPRN-2*nBorder;
148 Point aPos( nLeftMargin, nY );
149 pPrinter->DrawText( aPos, rTitle );
150 if ( nPages != 1 )
152 aFont.SetWeight( WEIGHT_NORMAL );
153 pPrinter->SetFont( aFont );
154 String aPageStr( RTL_CONSTASCII_USTRINGPARAM( " [" ) );
155 aPageStr += String( IDEResId( RID_STR_PAGE ) );
156 aPageStr += ' ';
157 aPageStr += String::CreateFromInt32( nCurPage );
158 aPageStr += ']';
159 aPos.X() += pPrinter->GetTextWidth( rTitle );
160 pPrinter->DrawText( aPos, aPageStr );
164 nY = TMARGPRN-nBorder;
166 pPrinter->DrawLine( Point( nXLeft, nY ), Point( nXRight, nY ) );
168 pPrinter->SetFont( aOldFont );
169 pPrinter->SetFillColor( aOldFillColor );
170 pPrinter->SetLineColor( aOldLineColor );
173 void lcl_ConvertTabsToSpaces( String& rLine )
175 if ( rLine.Len() )
177 USHORT nPos = 0;
178 USHORT nMax = rLine.Len();
179 while ( nPos < nMax )
181 if ( rLine.GetChar( nPos ) == '\t' )
183 // Nicht 4 Blanks, sondern an 4er TabPos:
184 String aBlanker;
185 aBlanker.Fill( ( 4 - ( nPos % 4 ) ), ' ' );
186 rLine.Erase( nPos, 1 );
187 rLine.Insert( aBlanker, nPos );
188 nMax = rLine.Len();
190 nPos++; // Nicht optimal, falls Tab, aber auch nicht verkehrt...
196 ModulWindow::ModulWindow( ModulWindowLayout* pParent, const ScriptDocument& rDocument, String aLibName,
197 String aName, ::rtl::OUString& aModule )
198 :IDEBaseWindow( pParent, rDocument, aLibName, aName )
199 ,aXEditorWindow( this )
200 ,m_aModule( aModule )
202 DBG_CTOR( ModulWindow, 0 );
203 nValid = VALIDWINDOW;
204 pLayout = pParent;
205 aXEditorWindow.Show();
207 BasicManager* pBasMgr = rDocument.getBasicManager();
208 if ( pBasMgr )
210 StarBASIC* pBasic = pBasMgr->GetLib( aLibName );
211 if ( pBasic )
213 xBasic = pBasic;
214 xModule = (SbModule*)pBasic->FindModule( aName );
218 SetBackground();
222 __EXPORT ModulWindow::~ModulWindow()
224 DBG_DTOR( ModulWindow, 0 );
225 nValid = 0;
227 StarBASIC::Stop();
231 void __EXPORT ModulWindow::GetFocus()
233 if ( nValid != VALIDWINDOW )
234 return;
235 DBG_CHKTHIS( ModulWindow, 0 );
236 aXEditorWindow.GetEdtWindow().GrabFocus();
237 // Basisklasse nicht rufen, weil Focus jetzt woanders...
240 void ModulWindow::DoInit()
242 DBG_CHKTHIS( ModulWindow, 0 );
243 // Wird beim Umschalten der Fenster gerufen...
244 if ( GetVScrollBar() )
245 GetVScrollBar()->Hide();
246 GetHScrollBar()->Show();
247 // GetEditorWindow().SetScrollBarRanges();
248 GetEditorWindow().InitScrollBars();
249 // GetEditorWindow().GrabFocus();
253 void __EXPORT ModulWindow::Paint( const Rectangle& )
257 void __EXPORT ModulWindow::Resize()
259 aXEditorWindow.SetPosSizePixel( Point( 0, 0 ),
260 Size( GetOutputSizePixel() ) );
264 // "Import" von baside4.cxx
265 void CreateEngineForBasic( StarBASIC* pBasic );
267 void ModulWindow::CheckCompileBasic()
269 DBG_CHKTHIS( ModulWindow, 0 );
271 if ( xModule.Is() )
273 // Zur Laufzeit wird niemals compiliert!
274 BOOL bRunning = StarBASIC::IsRunning();
275 BOOL bModified = ( !xModule->IsCompiled() ||
276 ( GetEditEngine() && GetEditEngine()->IsModified() ) );
278 if ( !bRunning && bModified )
280 BOOL bDone = FALSE;
282 BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
283 pIDEShell->GetViewFrame()->GetWindow().EnterWait();
285 if( bModified )
287 AssertValidEditEngine();
288 GetEditorWindow().SetSourceInBasic( FALSE );
291 BOOL bWasModified = GetBasic()->IsModified();
293 bDone = GetBasic()->Compile( xModule );
294 if ( !bWasModified )
295 GetBasic()->SetModified( FALSE );
297 if ( bDone )
299 GetBreakPoints().SetBreakPointsInBasic( xModule );
302 pIDEShell->GetViewFrame()->GetWindow().LeaveWait();
304 aStatus.bError = !bDone;
305 aStatus.bIsRunning = FALSE;
310 BOOL ModulWindow::BasicExecute()
312 DBG_CHKTHIS( ModulWindow, 0 );
314 // #116444# check security settings before macro execution
315 ScriptDocument aDocument( GetDocument() );
316 if ( aDocument.isDocument() )
318 if ( !aDocument.allowMacros() )
320 WarningBox( this, WB_OK, String( IDEResId( RID_STR_CANNOTRUNMACRO ) ) ).Execute();
321 return FALSE;
325 CheckCompileBasic();
327 if ( xModule.Is() && xModule->IsCompiled() && !aStatus.bError )
329 if ( GetBreakPoints().Count() )
330 aStatus.nBasicFlags = aStatus.nBasicFlags | SbDEBUG_BREAK;
332 if ( !aStatus.bIsRunning )
334 DBG_ASSERT( xModule.Is(), "Kein Modul!" );
335 AddStatus( BASWIN_RUNNINGBASIC );
336 USHORT nStart, nEnd, nCurMethodStart = 0;
337 TextSelection aSel = GetEditView()->GetSelection();
338 nCurMethodStart = ( aSel.GetStart().GetPara() + 1 );
339 SbMethod* pMethod = 0;
340 // erstes Macro, sonst blind "Main" (ExtSearch?)
341 for ( USHORT nMacro = 0; nMacro < xModule->GetMethods()->Count(); nMacro++ )
343 SbMethod* pM = (SbMethod*)xModule->GetMethods()->Get( nMacro );
344 DBG_ASSERT( pM, "Method?" );
345 pM->GetLineRange( nStart, nEnd );
346 if ( nCurMethodStart >= nStart && nCurMethodStart <= nEnd )
348 pMethod = pM;
349 break;
352 if ( !pMethod )
353 return ( BasicIDE::ChooseMacro( uno::Reference< frame::XModel >(), FALSE, rtl::OUString() ).getLength() > 0 ) ? TRUE : FALSE;
355 else
357 pMethod->SetDebugFlags( aStatus.nBasicFlags );
358 BasicDLL::SetDebugMode( TRUE );
359 BasicIDE::RunMethod( pMethod );
360 BasicDLL::SetDebugMode( FALSE );
361 // Falls waehrend Interactive=FALSE abgebrochen
362 BasicDLL::EnableBreak( TRUE );
364 ClearStatus( BASWIN_RUNNINGBASIC );
366 else
367 aStatus.bIsRunning = FALSE; // Abbruch von Reschedule()
370 BOOL bDone = !aStatus.bError;
372 return bDone;
375 BOOL ModulWindow::CompileBasic()
377 DBG_CHKTHIS( ModulWindow, 0 );
378 CheckCompileBasic();
380 BOOL bIsCompiled = FALSE;
381 if ( xModule.Is() )
382 bIsCompiled = xModule->IsCompiled();
384 return bIsCompiled;
387 BOOL ModulWindow::BasicRun()
389 DBG_CHKTHIS( ModulWindow, 0 );
391 aStatus.nBasicFlags = 0;
392 BOOL bDone = BasicExecute();
393 return bDone;
396 BOOL ModulWindow::BasicStepOver()
398 DBG_CHKTHIS( ModulWindow, 0 );
399 aStatus.nBasicFlags = SbDEBUG_STEPINTO | SbDEBUG_STEPOVER;
400 BOOL bDone = BasicExecute();
401 return bDone;
405 BOOL ModulWindow::BasicStepInto()
407 DBG_CHKTHIS( ModulWindow, 0 );
409 aStatus.nBasicFlags = SbDEBUG_STEPINTO;
410 BOOL bDone = BasicExecute();
411 return bDone;
414 BOOL ModulWindow::BasicStepOut()
416 DBG_CHKTHIS( ModulWindow, 0 );
418 aStatus.nBasicFlags = SbDEBUG_STEPOUT;
419 BOOL bDone = BasicExecute();
420 return bDone;
425 void ModulWindow::BasicStop()
427 DBG_CHKTHIS( ModulWindow, 0 );
429 GetBasic()->Stop();
430 aStatus.bIsRunning = FALSE;
433 BOOL ModulWindow::LoadBasic()
435 DBG_CHKTHIS( ModulWindow, 0 );
436 BOOL bDone = FALSE;
438 Reference< lang::XMultiServiceFactory > xMSF( ::comphelper::getProcessServiceFactory() );
439 Reference < XFilePicker > xFP;
440 if( xMSF.is() )
442 Sequence <Any> aServiceType(1);
443 aServiceType[0] <<= TemplateDescription::FILEOPEN_SIMPLE;
444 xFP = Reference< XFilePicker >( xMSF->createInstanceWithArguments(
445 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ) ), aServiceType ), UNO_QUERY );
448 if ( aCurPath.Len() )
449 xFP->setDisplayDirectory ( aCurPath );
451 //xFP->setTitle( String( IDEResId( RID_STR_OPEN ) ) );
453 Reference< XFilterManager > xFltMgr(xFP, UNO_QUERY);
454 xFltMgr->appendFilter( String( RTL_CONSTASCII_USTRINGPARAM( "BASIC" ) ), String( RTL_CONSTASCII_USTRINGPARAM( "*.bas" ) ) );
455 xFltMgr->appendFilter( String( IDEResId( RID_STR_FILTER_ALLFILES ) ), String( RTL_CONSTASCII_USTRINGPARAM( FILTERMASK_ALL ) ) );
456 xFltMgr->setCurrentFilter( String( RTL_CONSTASCII_USTRINGPARAM( "BASIC" ) ) );
458 if( xFP->execute() == RET_OK )
460 Sequence< ::rtl::OUString > aPaths = xFP->getFiles();
461 aCurPath = aPaths[0];
462 SfxMedium aMedium( aCurPath, STREAM_READ | STREAM_SHARE_DENYWRITE | STREAM_NOCREATE, TRUE );
463 SvStream* pStream = aMedium.GetInStream();
464 if ( pStream )
466 AssertValidEditEngine();
467 ULONG nLines = CalcLineCount( *pStream );
468 // nLines*4: ReadText/Formatting/Highlighting/Formatting
469 GetEditorWindow().CreateProgress( String( IDEResId( RID_STR_GENERATESOURCE ) ), nLines*4 );
470 GetEditEngine()->SetUpdateMode( FALSE );
471 GetEditView()->Read( *pStream );
472 GetEditEngine()->SetUpdateMode( TRUE );
473 GetEditorWindow().Update(); // Es wurde bei UpdateMode = TRUE nur Invalidiert
474 GetEditorWindow().ForceSyntaxTimeout();
475 GetEditorWindow().DestroyProgress();
476 ULONG nError = aMedium.GetError();
477 if ( nError )
478 ErrorHandler::HandleError( nError );
479 else
480 bDone = TRUE;
482 else
483 ErrorBox( this, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_COULDNTREAD ) ) ).Execute();
485 return bDone;
489 BOOL ModulWindow::SaveBasicSource()
491 DBG_CHKTHIS( ModulWindow, 0 );
492 BOOL bDone = FALSE;
494 Reference< lang::XMultiServiceFactory > xMSF( ::comphelper::getProcessServiceFactory() );
495 Reference < XFilePicker > xFP;
496 if( xMSF.is() )
498 Sequence <Any> aServiceType(1);
499 aServiceType[0] <<= TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD;
500 xFP = Reference< XFilePicker >( xMSF->createInstanceWithArguments(
501 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ) ), aServiceType ), UNO_QUERY );
504 Reference< XFilePickerControlAccess > xFPControl(xFP, UNO_QUERY);
505 xFPControl->enableControl(ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, sal_False);
506 Any aValue;
507 aValue <<= (sal_Bool) sal_True;
508 xFPControl->setValue(ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue);
510 if ( aCurPath.Len() )
511 xFP->setDisplayDirectory ( aCurPath );
513 //xFP->setTitle( String( IDEResId( RID_STR_SAVE ) ) );
515 Reference< XFilterManager > xFltMgr(xFP, UNO_QUERY);
516 xFltMgr->appendFilter( String( RTL_CONSTASCII_USTRINGPARAM( "BASIC" ) ), String( RTL_CONSTASCII_USTRINGPARAM( "*.bas" ) ) );
517 xFltMgr->appendFilter( String( IDEResId( RID_STR_FILTER_ALLFILES ) ), String( RTL_CONSTASCII_USTRINGPARAM( FILTERMASK_ALL ) ) );
518 xFltMgr->setCurrentFilter( String( RTL_CONSTASCII_USTRINGPARAM( "BASIC" ) ) );
520 if( xFP->execute() == RET_OK )
522 Sequence< ::rtl::OUString > aPaths = xFP->getFiles();
523 aCurPath = aPaths[0];
524 SfxMedium aMedium( aCurPath, STREAM_WRITE | STREAM_SHARE_DENYWRITE | STREAM_TRUNC, TRUE, FALSE );
525 SvStream* pStream = aMedium.GetOutStream();
526 if ( pStream )
528 EnterWait();
529 AssertValidEditEngine();
530 GetEditEngine()->Write( *pStream );
531 aMedium.Commit();
532 LeaveWait();
533 ULONG nError = aMedium.GetError();
534 if ( nError )
535 ErrorHandler::HandleError( nError );
536 else
537 bDone = TRUE;
539 else
540 ErrorBox( this, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_COULDNTWRITE) ) ).Execute();
543 return bDone;
547 BOOL ModulWindow::ToggleBreakPoint( ULONG nLine )
549 DBG_ASSERT( xModule.Is(), "Kein Modul!" );
551 BOOL bNewBreakPoint = FALSE;
553 if ( xModule.Is() )
555 CheckCompileBasic();
556 if ( aStatus.bError )
558 Sound::Beep();
559 return FALSE;
562 BreakPoint* pBrk = GetBreakPoints().FindBreakPoint( nLine );
563 if ( pBrk ) // entfernen
565 xModule->ClearBP( (USHORT)nLine );
566 delete GetBreakPoints().Remove( pBrk );
568 else // einen erzeugen
570 if ( xModule->SetBP( (USHORT)nLine) )
572 GetBreakPoints().InsertSorted( new BreakPoint( nLine ) );
573 bNewBreakPoint = TRUE;
574 if ( StarBASIC::IsRunning() )
576 for ( USHORT nMethod = 0; nMethod < xModule->GetMethods()->Count(); nMethod++ )
578 SbMethod* pMethod = (SbMethod*)xModule->GetMethods()->Get( nMethod );
579 DBG_ASSERT( pMethod, "Methode nicht gefunden! (NULL)" );
580 pMethod->SetDebugFlags( pMethod->GetDebugFlags() | SbDEBUG_BREAK );
585 if ( !bNewBreakPoint )
586 Sound::Beep();
590 return bNewBreakPoint;
593 void ModulWindow::UpdateBreakPoint( const BreakPoint& rBrk )
595 DBG_ASSERT( xModule.Is(), "Kein Modul!" );
597 if ( xModule.Is() )
599 CheckCompileBasic();
601 if ( rBrk.bEnabled )
602 xModule->SetBP( (USHORT)rBrk.nLine );
603 else
604 xModule->ClearBP( (USHORT)rBrk.nLine );
609 BOOL ModulWindow::BasicToggleBreakPoint()
611 DBG_CHKTHIS( ModulWindow, 0 );
612 AssertValidEditEngine();
614 TextSelection aSel = GetEditView()->GetSelection();
615 aSel.GetStart().GetPara()++; // Basic-Zeilen beginnen bei 1!
616 aSel.GetEnd().GetPara()++;
618 BOOL bNewBreakPoint = FALSE;
620 for ( ULONG nLine = aSel.GetStart().GetPara(); nLine <= aSel.GetEnd().GetPara(); nLine++ )
622 if ( ToggleBreakPoint( nLine ) )
623 bNewBreakPoint = TRUE;
626 aXEditorWindow.GetBrkWindow().Invalidate();
627 return bNewBreakPoint;
631 void ModulWindow::BasicToggleBreakPointEnabled()
633 DBG_CHKTHIS( ModulWindow, 0 );
634 AssertValidEditEngine();
636 ExtTextView* pView = GetEditView();
637 if ( pView )
639 TextSelection aSel = pView->GetSelection();
640 BreakPointList& rList = GetBreakPoints();
642 for ( ULONG nLine = ++aSel.GetStart().GetPara(), nEnd = ++aSel.GetEnd().GetPara(); nLine <= nEnd; ++nLine )
644 BreakPoint* pBrk = rList.FindBreakPoint( nLine );
645 if ( pBrk )
647 pBrk->bEnabled = pBrk->bEnabled ? FALSE : TRUE;
648 UpdateBreakPoint( *pBrk );
652 GetBreakPointWindow().Invalidate();
657 void ModulWindow::ManageBreakPoints()
659 BreakPointWindow& rBrkWin = GetBreakPointWindow();
660 BreakPointDialog aBrkDlg( &rBrkWin, GetBreakPoints() );
661 aBrkDlg.Execute();
662 rBrkWin.Invalidate();
666 IMPL_LINK( ModulWindow, BasicErrorHdl, StarBASIC *, pBasic )
668 DBG_CHKTHIS( ModulWindow, 0 );
669 GoOnTop();
671 // ReturnWert: BOOL
672 // FALSE: Abbrechen
673 // TRUE: Weiter....
674 String aErrorText( pBasic->GetErrorText() );
675 USHORT nErrorLine = pBasic->GetLine() - 1;
676 USHORT nErrCol1 = pBasic->GetCol1();
677 USHORT nErrCol2 = pBasic->GetCol2();
678 if ( nErrCol2 != 0xFFFF )
679 nErrCol2++;
681 AssertValidEditEngine();
682 GetEditView()->SetSelection( TextSelection( TextPaM( nErrorLine, nErrCol1 ), TextPaM( nErrorLine, nErrCol2 ) ) );
684 String aErrorTextPrefix;
685 if( pBasic->IsCompilerError() )
687 aErrorTextPrefix = String( IDEResId( RID_STR_COMPILEERROR ) );
689 else
691 aErrorTextPrefix = String( IDEResId( RID_STR_RUNTIMEERROR ) );
692 aErrorTextPrefix += StarBASIC::GetVBErrorCode( pBasic->GetErrorCode() );
693 aErrorTextPrefix += ' ';
694 pLayout->GetStackWindow().UpdateCalls();
696 // Wenn anderes Basic, dan sollte die IDE versuchen, da richtige
697 // Modul anzuzeigen...
698 BOOL bMarkError = ( pBasic == GetBasic() ) ? TRUE : FALSE;
699 if ( bMarkError )
700 aXEditorWindow.GetBrkWindow().SetMarkerPos( nErrorLine, TRUE );
701 // ErrorBox( this, WB_OK | WB_DEF_OK, String( aErrorTextPrefix + aErrorText ) ).Execute();
702 // ErrorHandler::HandleError( pBasic->GetErrorCode() );
704 // #i47002#
705 Reference< awt::XWindow > xWindow = VCLUnoHelper::GetInterface( this );
707 ErrorHandler::HandleError( StarBASIC::GetErrorCode() );
709 // #i47002#
710 Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
711 if ( !pWindow )
712 return FALSE;
714 if ( bMarkError )
715 aXEditorWindow.GetBrkWindow().SetMarkerPos( MARKER_NOMARKER );
716 return FALSE;
719 long __EXPORT ModulWindow::BasicBreakHdl( StarBASIC* pBasic )
721 DBG_CHKTHIS( ModulWindow, 0 );
722 // Ein GoOnTop aktiviert da Fenster, das veraendert aber den Context fuer
723 // das Programm!
724 // GoOnTop();
726 // #i69280 Required in Window despite normal usage in next command!
727 (void)pBasic;
729 // ReturnWert: USHORT => siehe SB-Debug-Flags
730 USHORT nErrorLine = pBasic->GetLine();
732 // Gibt es hier einen BreakPoint?
733 BreakPoint* pBrk = GetBreakPoints().FindBreakPoint( nErrorLine );
734 if ( pBrk )
736 pBrk->nHitCount++;
737 if ( pBrk->nHitCount < pBrk->nStopAfter && GetBasic()->IsBreak() )
738 return aStatus.nBasicFlags; // weiterlaufen...
741 nErrorLine--; // EditEngine begint bei 0, Basic bei 1
742 // Alleine schon damit gescrollt wird...
743 AssertValidEditEngine();
744 GetEditView()->SetSelection( TextSelection( TextPaM( nErrorLine, 0 ), TextPaM( nErrorLine, 0 ) ) );
745 aXEditorWindow.GetBrkWindow().SetMarkerPos( nErrorLine );
747 pLayout->GetWatchWindow().UpdateWatches();
748 pLayout->GetStackWindow().UpdateCalls();
750 aStatus.bIsInReschedule = TRUE;
751 aStatus.bIsRunning = TRUE;
753 AddStatus( BASWIN_INRESCHEDULE );
755 BasicIDE::InvalidateDebuggerSlots();
757 while( aStatus.bIsRunning )
758 Application::Yield();
760 aStatus.bIsInReschedule = FALSE;
761 aXEditorWindow.GetBrkWindow().SetMarkerPos( MARKER_NOMARKER );
763 ClearStatus( BASWIN_INRESCHEDULE );
765 return aStatus.nBasicFlags;
768 void ModulWindow::BasicAddWatch()
770 DBG_CHKTHIS( ModulWindow, 0 );
771 String aWatchStr;
772 BOOL bInserted = FALSE;
773 AssertValidEditEngine();
774 BOOL bAdd = TRUE;
775 if ( !GetEditView()->HasSelection() )
777 // bAdd = GetEditView()->SelectCurrentWord();
778 TextPaM aWordStart;
779 String aWord = GetEditEngine()->GetWord( GetEditView()->GetSelection().GetEnd(), &aWordStart );
780 if ( aWord.Len() )
782 TextSelection aSel( aWordStart );
783 USHORT& rIndex = aSel.GetEnd().GetIndex();
784 rIndex = rIndex + aWord.Len();
785 // aSel.GetEnd().GetIndex() += sal::static_int_cast<int>( aWord.Len() );
786 GetEditView()->SetSelection( aSel );
787 bAdd = TRUE;
790 if ( bAdd )
792 TextSelection aSel = GetEditView()->GetSelection();
793 if ( aSel.GetStart().GetPara() == aSel.GetEnd().GetPara() )
795 aWatchStr = GetEditView()->GetSelected();
796 pLayout->GetWatchWindow().AddWatch( aWatchStr );
797 pLayout->GetWatchWindow().UpdateWatches();
798 bInserted = TRUE;
802 if ( !bInserted )
803 Sound::Beep();
808 void ModulWindow::BasicRemoveWatch()
810 DBG_CHKTHIS( ModulWindow, 0 );
811 BOOL bRemoved = pLayout->GetWatchWindow().RemoveSelectedWatch();
813 if ( !bRemoved )
814 Sound::Beep();
818 void ModulWindow::EditMacro( const String& rMacroName )
820 DBG_CHKTHIS( ModulWindow, 0 );
821 DBG_ASSERT( xModule.Is(), "Kein Modul!" );
823 if ( xModule.Is() )
825 CheckCompileBasic();
827 if ( !aStatus.bError )
829 USHORT nStart, nEnd;
830 SbMethod* pMethod = (SbMethod*)xModule->Find( rMacroName, SbxCLASS_METHOD );
831 if ( pMethod )
833 pMethod->GetLineRange( nStart, nEnd );
834 if ( nStart )
836 // Basic beginnt bei 1
837 nStart--;
838 nEnd--;
840 TextSelection aSel( TextPaM( nStart, 0 ), TextPaM( nStart, 0 ) );
841 AssertValidEditEngine();
842 TextView * pView = GetEditView();
843 // ggf. hinscrollen, so dass erste Zeile oben...
844 long nVisHeight = GetOutputSizePixel().Height();
845 if ( (long)pView->GetTextEngine()->GetTextHeight() > nVisHeight )
847 long nMaxY = pView->GetTextEngine()->GetTextHeight() - nVisHeight;
848 long nOldStartY = pView->GetStartDocPos().Y();
849 long nNewStartY = nStart * pView->GetTextEngine()->GetCharHeight();
850 nNewStartY = Min( nNewStartY, nMaxY );
851 pView->Scroll( 0, -(nNewStartY-nOldStartY) );
852 pView->ShowCursor( FALSE, TRUE );
853 GetEditVScrollBar().SetThumbPos( pView->GetStartDocPos().Y() );
855 pView->SetSelection( aSel );
856 pView->ShowCursor();
857 pView->GetWindow()->GrabFocus();
864 void __EXPORT ModulWindow::StoreData()
866 DBG_CHKTHIS( ModulWindow, 0 );
867 // StoreData wird gerufen, wenn der BasicManager zerstoert oder
868 // dieses Fenster beendet wird.
869 // => Keine Unterbrechungen erwuenscht!
870 // Und bei SAVE, wenn AppBasic...
871 GetEditorWindow().SetSourceInBasic( TRUE );
872 // Nicht das Modify loeschen, sonst wird das Basic nicht gespeichert
873 // Es wird beim Speichern sowieso geloescht.
874 // xModule->SetModified( FALSE );
877 BOOL __EXPORT ModulWindow::CanClose()
879 DBG_CHKTHIS( ModulWindow, 0 );
880 return TRUE;
884 BOOL __EXPORT ModulWindow::AllowUndo()
886 return GetEditorWindow().CanModify();
890 void __EXPORT ModulWindow::UpdateData()
892 DBG_CHKTHIS( ModulWindow, 0 );
893 DBG_ASSERT( xModule.Is(), "Kein Modul!" );
894 // UpdateData wird gerufen, wenn sich der Source von aussen
895 // geaendert hat.
896 // => Keine Unterbrechungen erwuenscht!
898 if ( xModule.Is() )
900 SetModule( xModule->GetSource32() );
902 if ( GetEditView() )
904 TextSelection aSel = GetEditView()->GetSelection();
905 setTextEngineText( GetEditEngine(), xModule->GetSource32() );
906 GetEditView()->SetSelection( aSel );
907 GetEditEngine()->SetModified( FALSE );
908 BasicIDE::MarkDocumentModified( GetDocument() );
914 void __EXPORT ModulWindow::PrintData( Printer* pPrinter )
916 DBG_CHKTHIS( ModulWindow, 0 );
918 AssertValidEditEngine();
920 MapMode eOldMapMode( pPrinter->GetMapMode() );
921 Font aOldFont( pPrinter->GetFont() );
923 // Font aFont( GetEditEngine()->CreateFontFromItemSet( GetEditEngine()->GetEmptyItemSet() ) );
924 Font aFont( GetEditEngine()->GetFont() );
925 aFont.SetAlign( ALIGN_BOTTOM );
926 aFont.SetTransparent( TRUE );
927 aFont.SetSize( Size( 0, 360 ) );
928 pPrinter->SetFont( aFont );
929 pPrinter->SetMapMode( MAP_100TH_MM );
931 String aTitle( CreateQualifiedName() );
933 USHORT nLineHeight = (USHORT) pPrinter->GetTextHeight(); // etwas mehr.
934 USHORT nParaSpace = 10;
936 Size aPaperSz = pPrinter->GetOutputSize();
937 aPaperSz.Width() -= (LMARGPRN+RMARGPRN);
938 aPaperSz.Height() -= (TMARGPRN+BMARGPRN);
940 // nLinepPage stimmt nicht, wenn Zeilen umgebrochen werden muessen...
941 USHORT nLinespPage = (USHORT) (aPaperSz.Height()/nLineHeight);
942 USHORT nCharspLine = (USHORT) (aPaperSz.Width() / pPrinter->GetTextWidth( 'X' ) );
943 ULONG nParas = GetEditEngine()->GetParagraphCount();
945 USHORT nPages = (USHORT) (nParas/nLinespPage+1 );
946 USHORT nCurPage = 1;
948 pPrinter->StartJob( aTitle );
949 pPrinter->StartPage();
950 // Header drucken...
951 lcl_PrintHeader( pPrinter, nPages, nCurPage, aTitle );
952 Point aPos( LMARGPRN, TMARGPRN );
953 for ( ULONG nPara = 0; nPara < nParas; nPara++ )
955 String aLine( GetEditEngine()->GetText( nPara ) );
956 lcl_ConvertTabsToSpaces( aLine );
957 USHORT nLines = aLine.Len()/nCharspLine+1;
958 for ( USHORT nLine = 0; nLine < nLines; nLine++ )
960 String aTmpLine( aLine, nLine*nCharspLine, nCharspLine );
961 aPos.Y() += nLineHeight;
962 if ( aPos.Y() > ( aPaperSz.Height()+TMARGPRN ) )
964 nCurPage++;
965 pPrinter->EndPage();
966 pPrinter->StartPage();
967 lcl_PrintHeader( pPrinter, nPages, nCurPage, aTitle );
968 aPos = Point( LMARGPRN, TMARGPRN+nLineHeight );
970 pPrinter->DrawText( aPos, aTmpLine );
972 aPos.Y() += nParaSpace;
974 pPrinter->EndPage();
975 pPrinter->EndJob();
977 pPrinter->SetFont( aOldFont );
978 pPrinter->SetMapMode( eOldMapMode );
982 void __EXPORT ModulWindow::ExecuteCommand( SfxRequest& rReq )
984 DBG_CHKTHIS( ModulWindow, 0 );
985 AssertValidEditEngine();
986 USHORT nSlot = rReq.GetSlot();
987 switch ( nSlot )
989 case SID_BASICRUN:
991 BasicRun();
993 break;
994 case SID_BASICCOMPILE:
996 CompileBasic();
998 break;
999 case SID_BASICSTEPOVER:
1001 BasicStepOver();
1003 break;
1004 case SID_BASICSTEPINTO:
1006 BasicStepInto();
1008 break;
1009 case SID_BASICSTEPOUT:
1011 BasicStepOut();
1013 break;
1014 case SID_BASICLOAD:
1016 LoadBasic();
1018 break;
1019 case SID_BASICSAVEAS:
1021 SaveBasicSource();
1023 break;
1024 case SID_BASICIDE_MATCHGROUP:
1026 if ( !GetEditView()->MatchGroup() )
1027 Sound::Beep();
1029 break;
1030 case SID_BASICIDE_TOGGLEBRKPNT:
1032 BasicToggleBreakPoint();
1034 break;
1035 case SID_BASICIDE_MANAGEBRKPNTS:
1037 ManageBreakPoints();
1039 break;
1040 case SID_BASICIDE_TOGGLEBRKPNTENABLED:
1042 BasicToggleBreakPointEnabled();
1044 break;
1045 case SID_BASICIDE_ADDWATCH:
1047 BasicAddWatch();
1049 break;
1050 case SID_BASICIDE_REMOVEWATCH:
1052 BasicRemoveWatch();
1054 break;
1055 case SID_CUT:
1057 if ( !IsReadOnly() )
1059 GetEditView()->Cut();
1060 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
1061 if ( pBindings )
1062 pBindings->Invalidate( SID_DOC_MODIFIED );
1065 break;
1066 case SID_COPY:
1068 GetEditView()->Copy();
1070 break;
1071 case SID_PASTE:
1073 if ( !IsReadOnly() )
1075 GetEditView()->Paste();
1076 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
1077 if ( pBindings )
1078 pBindings->Invalidate( SID_DOC_MODIFIED );
1081 break;
1082 case SID_BASICIDE_BRKPNTSCHANGED:
1084 GetBreakPointWindow().Invalidate();
1086 break;
1092 void __EXPORT ModulWindow::GetState( SfxItemSet &rSet )
1094 DBG_CHKTHIS( ModulWindow, 0 );
1095 SfxWhichIter aIter(rSet);
1096 for ( USHORT nWh = aIter.FirstWhich(); 0 != nWh; nWh = aIter.NextWhich() )
1098 switch ( nWh )
1100 // allgemeine Items:
1101 case SID_CUT:
1103 if ( !GetEditView() || !GetEditView()->HasSelection() )
1104 rSet.DisableItem( nWh );
1106 if ( IsReadOnly() )
1107 rSet.DisableItem( nWh );
1109 break;
1110 case SID_COPY:
1112 if ( !GetEditView() || !GetEditView()->HasSelection() )
1113 rSet.DisableItem( nWh );
1115 break;
1116 case SID_PASTE:
1118 if ( !IsPasteAllowed() )
1119 rSet.DisableItem( nWh );
1121 if ( IsReadOnly() )
1122 rSet.DisableItem( nWh );
1124 break;
1125 case SID_BASICIDE_STAT_POS:
1127 TextView* pView = GetEditView();
1128 if ( pView )
1130 TextSelection aSel = pView->GetSelection();
1131 String aPos( IDEResId( RID_STR_LINE ) );
1132 aPos += ' ';
1133 aPos += String::CreateFromInt32( aSel.GetEnd().GetPara()+1 );
1134 aPos += String( RTL_CONSTASCII_USTRINGPARAM( ", " ) );
1135 aPos += String( IDEResId( RID_STR_COLUMN ) );
1136 aPos += ' ';
1137 aPos += String::CreateFromInt32( aSel.GetEnd().GetIndex()+1 );
1138 SfxStringItem aItem( SID_BASICIDE_STAT_POS, aPos );
1139 rSet.Put( aItem );
1142 break;
1143 case SID_ATTR_INSERT:
1145 TextView* pView = GetEditView();
1146 if ( pView )
1148 SfxBoolItem aItem( SID_ATTR_INSERT, pView->IsInsertMode() );
1149 rSet.Put( aItem );
1152 break;
1158 void __EXPORT ModulWindow::DoScroll( ScrollBar* pCurScrollBar )
1160 DBG_CHKTHIS( ModulWindow, 0 );
1161 if ( ( pCurScrollBar == GetHScrollBar() ) && GetEditView() )
1163 // Nicht mit dem Wert Scrollen, sondern lieber die Thumb-Pos fuer die
1164 // VisArea verwenden:
1165 long nDiff = GetEditView()->GetStartDocPos().X() - pCurScrollBar->GetThumbPos();
1166 GetEditView()->Scroll( nDiff, 0 );
1167 GetEditView()->ShowCursor( FALSE, TRUE );
1168 pCurScrollBar->SetThumbPos( GetEditView()->GetStartDocPos().X() );
1174 BOOL ModulWindow::RenameModule( const String& rNewName )
1176 if ( !BasicIDE::RenameModule( this, GetDocument(), GetLibName(), GetName(), rNewName ) )
1177 return FALSE;
1179 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
1180 if ( pBindings )
1181 pBindings->Invalidate( SID_DOC_MODIFIED );
1183 return TRUE;
1187 BOOL __EXPORT ModulWindow::IsModified()
1189 return GetEditEngine() ? GetEditEngine()->IsModified() : FALSE;
1194 void __EXPORT ModulWindow::GoOnTop()
1196 IDE_DLL()->GetShell()->GetViewFrame()->ToTop();
1199 String ModulWindow::GetSbModuleName()
1201 String aModuleName;
1202 if ( xModule.Is() )
1203 aModuleName = xModule->GetName();
1204 return aModuleName;
1209 String __EXPORT ModulWindow::GetTitle()
1211 return GetSbModuleName();
1216 void ModulWindow::FrameWindowMoved()
1218 // if ( GetEditEngine() && GetEditEngine()->IsInSelectionMode() )
1219 // GetEditEngine()->StopSelectionMode();
1224 void ModulWindow::ShowCursor( BOOL bOn )
1226 if ( GetEditEngine() )
1228 TextView* pView = GetEditEngine()->GetActiveView();
1229 if ( pView )
1231 if ( bOn )
1232 pView->ShowCursor();
1233 else
1234 pView->HideCursor();
1240 Window* __EXPORT ModulWindow::GetLayoutWindow()
1242 return pLayout;
1245 void ModulWindow::AssertValidEditEngine()
1247 if ( !GetEditEngine() )
1248 GetEditorWindow().CreateEditEngine();
1251 void ModulWindow::Deactivating()
1253 if ( GetEditView() )
1254 GetEditView()->EraseVirtualDevice();
1257 USHORT ModulWindow::StartSearchAndReplace( const SvxSearchItem& rSearchItem, BOOL bFromStart )
1259 // Mann koennte fuer das blinde Alle-Ersetzen auch auf
1260 // Syntaxhighlighting/Formatierung verzichten...
1261 AssertValidEditEngine();
1262 ExtTextView* pView = GetEditView();
1263 TextSelection aSel;
1264 if ( bFromStart )
1266 aSel = pView->GetSelection();
1267 if ( !rSearchItem.GetBackward() )
1268 pView->SetSelection( TextSelection() );
1269 else
1270 pView->SetSelection( TextSelection( TextPaM( 0xFFFFFFFF, 0xFFFF ), TextPaM( 0xFFFFFFFF, 0xFFFF ) ) );
1273 BOOL bForward = !rSearchItem.GetBackward();
1274 USHORT nFound = 0;
1275 if ( ( rSearchItem.GetCommand() == SVX_SEARCHCMD_FIND ) ||
1276 ( rSearchItem.GetCommand() == SVX_SEARCHCMD_FIND_ALL ) )
1278 nFound = pView->Search( rSearchItem.GetSearchOptions() , bForward );
1280 else if ( ( rSearchItem.GetCommand() == SVX_SEARCHCMD_REPLACE ) ||
1281 ( rSearchItem.GetCommand() == SVX_SEARCHCMD_REPLACE_ALL ) )
1283 if ( !IsReadOnly() )
1285 BOOL bAll = rSearchItem.GetCommand() == SVX_SEARCHCMD_REPLACE_ALL;
1286 nFound = pView->Replace( rSearchItem.GetSearchOptions() , bAll , bForward );
1290 if ( bFromStart && !nFound )
1291 pView->SetSelection( aSel );
1293 return nFound;
1296 SfxUndoManager* __EXPORT ModulWindow::GetUndoManager()
1298 if ( GetEditEngine() )
1299 return &GetEditEngine()->GetUndoManager();
1300 return NULL;
1303 USHORT __EXPORT ModulWindow::GetSearchOptions()
1305 USHORT nOptions = SEARCH_OPTIONS_SEARCH |
1306 SEARCH_OPTIONS_WHOLE_WORDS |
1307 SEARCH_OPTIONS_BACKWARDS |
1308 SEARCH_OPTIONS_REG_EXP |
1309 SEARCH_OPTIONS_EXACT |
1310 SEARCH_OPTIONS_SELECTION |
1311 SEARCH_OPTIONS_SIMILARITY;
1313 if ( !IsReadOnly() )
1315 nOptions |= SEARCH_OPTIONS_REPLACE;
1316 nOptions |= SEARCH_OPTIONS_REPLACE_ALL;
1319 return nOptions;
1322 void __EXPORT ModulWindow::BasicStarted()
1324 if ( xModule.Is() )
1326 aStatus.bIsRunning = TRUE;
1327 BreakPointList& rList = GetBreakPoints();
1328 if ( rList.Count() )
1330 rList.ResetHitCount();
1331 rList.SetBreakPointsInBasic( xModule );
1332 for ( USHORT nMethod = 0; nMethod < xModule->GetMethods()->Count(); nMethod++ )
1334 SbMethod* pMethod = (SbMethod*)xModule->GetMethods()->Get( nMethod );
1335 DBG_ASSERT( pMethod, "Methode nicht gefunden! (NULL)" );
1336 pMethod->SetDebugFlags( pMethod->GetDebugFlags() | SbDEBUG_BREAK );
1342 void __EXPORT ModulWindow::BasicStopped()
1344 aStatus.bIsRunning = FALSE;
1345 GetBreakPointWindow().SetMarkerPos( MARKER_NOMARKER );
1348 BasicEntryDescriptor ModulWindow::CreateEntryDescriptor()
1350 ScriptDocument aDocument( GetDocument() );
1351 String aLibName( GetLibName() );
1352 LibraryLocation eLocation = aDocument.getLibraryLocation( aLibName );
1353 String aModName( GetName() );
1354 String aLibSubName;
1355 if( xBasic.Is() && xBasic->isVBAEnabled() && xModule.Is() )
1357 switch( xModule->GetModuleType() )
1359 case script::ModuleType::Document:
1361 aLibSubName = String( IDEResId( RID_STR_DOCUMENT_OBJECTS ) );
1362 uno::Reference< container::XNameContainer > xLib = aDocument.getOrCreateLibrary( E_SCRIPTS, aLibName );
1363 if( xLib.is() )
1365 String sObjName;
1366 lcl_getObjectName( xLib, aModName, sObjName );
1367 if( sObjName.Len() )
1369 aModName.AppendAscii(" (").Append(sObjName).AppendAscii(")");
1372 break;
1374 case script::ModuleType::Form:
1375 aLibSubName = String( IDEResId( RID_STR_USERFORMS ) );
1376 break;
1377 case script::ModuleType::Normal:
1378 aLibSubName = String( IDEResId( RID_STR_NORMAL_MODULES ) );
1379 break;
1380 case script::ModuleType::Class:
1381 aLibSubName = String( IDEResId( RID_STR_CLASS_MODULES ) );
1382 break;
1385 return BasicEntryDescriptor( aDocument, eLocation, aLibName, aLibSubName, aModName, OBJ_TYPE_MODULE );
1388 void ModulWindow::SetReadOnly( BOOL b )
1390 if ( GetEditView() )
1391 GetEditView()->SetReadOnly( b );
1394 BOOL ModulWindow::IsReadOnly()
1396 BOOL bReadOnly = FALSE;
1398 if ( GetEditView() )
1399 bReadOnly = GetEditView()->IsReadOnly();
1401 return bReadOnly;
1404 BOOL ModulWindow::IsPasteAllowed()
1406 BOOL bPaste = FALSE;
1408 // get clipboard
1409 Reference< datatransfer::clipboard::XClipboard > xClipboard = GetClipboard();
1410 if ( xClipboard.is() )
1412 // get clipboard content
1413 const sal_uInt32 nRef = Application::ReleaseSolarMutex();
1414 Reference< datatransfer::XTransferable > xTransf = xClipboard->getContents();
1415 Application::AcquireSolarMutex( nRef );
1416 if ( xTransf.is() )
1418 datatransfer::DataFlavor aFlavor;
1419 SotExchange::GetFormatDataFlavor( SOT_FORMAT_STRING, aFlavor );
1420 if ( xTransf->isDataFlavorSupported( aFlavor ) )
1422 bPaste = TRUE;
1427 return bPaste;
1430 ModulWindowLayout::ModulWindowLayout( Window* pParent ) :
1431 Window( pParent, WB_CLIPCHILDREN ),
1432 aVSplitter( this, WinBits( WB_VSCROLL ) ),
1433 aHSplitter( this, WinBits( WB_HSCROLL ) ),
1434 aWatchWindow( this ),
1435 aStackWindow( this ),
1436 bVSplitted(FALSE),
1437 bHSplitted(FALSE),
1438 m_pModulWindow(0),
1439 m_aImagesNormal(IDEResId(RID_IMGLST_LAYOUT)),
1440 m_aImagesHighContrast(IDEResId(RID_IMGLST_LAYOUT_HC))
1442 SetBackground(GetSettings().GetStyleSettings().GetWindowColor());
1444 aVSplitter.SetSplitHdl( LINK( this, ModulWindowLayout, SplitHdl ) );
1445 aHSplitter.SetSplitHdl( LINK( this, ModulWindowLayout, SplitHdl ) );
1446 aVSplitter.Show();
1447 aHSplitter.Show();
1449 aWatchWindow.Show();
1450 aStackWindow.Show();
1452 Color aColor(GetSettings().GetStyleSettings().GetFieldTextColor());
1453 m_aSyntaxColors[TT_UNKNOWN] = aColor;
1454 m_aSyntaxColors[TT_WHITESPACE] = aColor;
1455 m_aSyntaxColors[TT_EOL] = aColor;
1456 StartListening(m_aColorConfig);
1457 m_aSyntaxColors[TT_IDENTIFIER]
1458 = Color(m_aColorConfig.GetColorValue(svtools::BASICIDENTIFIER).nColor);
1459 m_aSyntaxColors[TT_NUMBER]
1460 = Color(m_aColorConfig.GetColorValue(svtools::BASICNUMBER).nColor);
1461 m_aSyntaxColors[TT_STRING]
1462 = Color(m_aColorConfig.GetColorValue(svtools::BASICSTRING).nColor);
1463 m_aSyntaxColors[TT_COMMENT]
1464 = Color(m_aColorConfig.GetColorValue(svtools::BASICCOMMENT).nColor);
1465 m_aSyntaxColors[TT_ERROR]
1466 = Color(m_aColorConfig.GetColorValue(svtools::BASICERROR).nColor);
1467 m_aSyntaxColors[TT_OPERATOR]
1468 = Color(m_aColorConfig.GetColorValue(svtools::BASICOPERATOR).nColor);
1469 m_aSyntaxColors[TT_KEYWORDS]
1470 = Color(m_aColorConfig.GetColorValue(svtools::BASICKEYWORD).nColor);
1472 Font aFont( GetFont() );
1473 Size aSz( aFont.GetSize() );
1474 aSz.Height() *= 3;
1475 aSz.Height() /= 2;
1476 aFont.SetSize( aSz );
1477 aFont.SetWeight( WEIGHT_BOLD );
1478 aFont.SetColor(GetSettings().GetStyleSettings().GetWindowTextColor());
1479 SetFont( aFont );
1482 ModulWindowLayout::~ModulWindowLayout()
1484 EndListening(m_aColorConfig);
1487 void __EXPORT ModulWindowLayout::Resize()
1489 // ScrollBars, etc. passiert in BasicIDEShell:Adjust...
1490 ArrangeWindows();
1491 // Invalidate();
1494 void __EXPORT ModulWindowLayout::Paint( const Rectangle& )
1496 DrawText( Point(), String( IDEResId( RID_STR_NOMODULE ) ) );
1500 void ModulWindowLayout::ArrangeWindows()
1502 Size aSz = GetOutputSizePixel();
1504 // prueffen, ob der Splitter in einem gueltigen Bereich liegt...
1505 long nMinPos = SPLIT_MARGIN;
1506 long nMaxPos = aSz.Height() - SPLIT_MARGIN;
1508 long nVSplitPos = aVSplitter.GetSplitPosPixel();
1509 long nHSplitPos = aHSplitter.GetSplitPosPixel();
1510 if ( !bVSplitted )
1512 // Wenn noch nie gesplitted wurde, Verhaeltniss = 3 : 4
1513 nVSplitPos = aSz.Height() * 3 / 4;
1514 aVSplitter.SetSplitPosPixel( nVSplitPos );
1516 if ( !bHSplitted )
1518 // Wenn noch nie gesplitted wurde, Verhaeltniss = 2 : 3
1519 nHSplitPos = aSz.Width() * 2 / 3;
1520 aHSplitter.SetSplitPosPixel( nHSplitPos );
1522 if ( ( nVSplitPos < nMinPos ) || ( nVSplitPos > nMaxPos ) )
1523 nVSplitPos = ( nVSplitPos < nMinPos ) ? 0 : ( aSz.Height() - SPLIT_HEIGHT );
1525 Size aXEWSz;
1526 aXEWSz.Width() = aSz.Width();
1527 aXEWSz.Height() = nVSplitPos + 1;
1528 if ( m_pModulWindow )
1530 DBG_CHKOBJ( m_pModulWindow, ModulWindow, 0 );
1531 m_pModulWindow->SetPosSizePixel( Point( 0, 0 ), aXEWSz );
1534 aVSplitter.SetDragRectPixel( Rectangle( Point( 0, 0 ), Size( aSz.Width(), aSz.Height() ) ) );
1535 aVSplitter.SetPosPixel( Point( 0, nVSplitPos ) );
1536 aVSplitter.SetSizePixel( Size( aSz.Width(), SPLIT_HEIGHT ) );
1538 aHSplitter.SetDragRectPixel( Rectangle( Point( 0, nVSplitPos+SPLIT_HEIGHT ), Size( aSz.Width(), aSz.Height() - nVSplitPos - SPLIT_HEIGHT ) ) );
1539 aHSplitter.SetPosPixel( Point( nHSplitPos, nVSplitPos ) );
1540 aHSplitter.SetSizePixel( Size( SPLIT_HEIGHT, aSz.Height() - nVSplitPos ) );
1542 Size aWWSz;
1543 Point aWWPos( 0, nVSplitPos+SPLIT_HEIGHT );
1544 aWWSz.Width() = nHSplitPos;
1545 aWWSz.Height() = aSz.Height() - aWWPos.Y();
1546 if ( !aWatchWindow.IsFloatingMode() )
1547 aWatchWindow.SetPosSizePixel( aWWPos, aWWSz );
1549 Size aSWSz;
1550 Point aSWPos( nHSplitPos+SPLIT_HEIGHT, nVSplitPos+SPLIT_HEIGHT );
1551 aSWSz.Width() = aSz.Width() - aSWPos.X();
1552 aSWSz.Height() = aSz.Height() - aSWPos.Y();
1553 if ( !aStackWindow.IsFloatingMode() )
1554 aStackWindow.SetPosSizePixel( aSWPos, aSWSz );
1556 if ( aStackWindow.IsFloatingMode() && aWatchWindow.IsFloatingMode() )
1557 aHSplitter.Hide();
1558 else
1559 aHSplitter.Show();
1561 long nHDoubleClickSplitPosX = aSz.Width()-aHSplitter.GetSizePixel().Width();
1562 if ( aHSplitter.GetSplitPosPixel() < nHDoubleClickSplitPosX )
1563 aHSplitter.SetLastSplitPosPixel( nHDoubleClickSplitPosX );
1566 long nHDoubleClickSplitPosY = aSz.Height()-aVSplitter.GetSizePixel().Height();
1567 if ( aVSplitter.GetSplitPosPixel() < nHDoubleClickSplitPosY )
1568 aVSplitter.SetLastSplitPosPixel( nHDoubleClickSplitPosY );
1571 IMPL_LINK( ModulWindowLayout, SplitHdl, Splitter *, pSplitter )
1573 if ( pSplitter == &aVSplitter )
1574 bVSplitted = TRUE;
1575 else
1576 bHSplitted = TRUE;
1578 ArrangeWindows();
1579 return 0;
1582 BOOL ModulWindowLayout::IsToBeDocked( DockingWindow* pDockingWindow, const Point& rPos, Rectangle& rRect )
1584 // prueffen, ob als Dock oder als Child:
1585 // TRUE: Floating
1586 // FALSE: Child
1587 Point aPosInMe = ScreenToOutputPixel( rPos );
1588 Size aSz = GetOutputSizePixel();
1589 if ( ( aPosInMe.X() > 0 ) && ( aPosInMe.X() < aSz.Width() ) &&
1590 ( aPosInMe.Y() > 0 ) && ( aPosInMe.Y() < aSz.Height() ) )
1592 long nVSplitPos = aVSplitter.GetSplitPosPixel();
1593 long nHSplitPos = aHSplitter.GetSplitPosPixel();
1594 if ( pDockingWindow == &aWatchWindow )
1596 if ( ( aPosInMe.Y() > nVSplitPos ) && ( aPosInMe.X() < nHSplitPos ) )
1598 rRect.SetSize( Size( nHSplitPos, aSz.Height() - nVSplitPos ) );
1599 rRect.SetPos( OutputToScreenPixel( Point( 0, nVSplitPos ) ) );
1600 return TRUE;
1603 if ( pDockingWindow == &aStackWindow )
1605 if ( ( aPosInMe.Y() > nVSplitPos ) && ( aPosInMe.X() > nHSplitPos ) )
1607 rRect.SetSize( Size( aSz.Width() - nHSplitPos, aSz.Height() - nVSplitPos ) );
1608 rRect.SetPos( OutputToScreenPixel( Point( nHSplitPos, nVSplitPos ) ) );
1609 return TRUE;
1613 return FALSE;
1616 void ModulWindowLayout::DockaWindow( DockingWindow* pDockingWindow )
1618 if ( pDockingWindow == &aWatchWindow )
1620 // evtl. Sonderbehandlung...
1621 ArrangeWindows();
1623 else if ( pDockingWindow == &aStackWindow )
1625 // evtl. Sonderbehandlung...
1626 ArrangeWindows();
1628 #ifndef PRODUCT
1629 else
1630 DBG_ERROR( "Wer will sich denn hier andocken ?" );
1631 #endif
1634 void ModulWindowLayout::SetModulWindow( ModulWindow* pModWin )
1636 m_pModulWindow = pModWin;
1637 ArrangeWindows();
1640 // virtual
1641 void ModulWindowLayout::DataChanged(DataChangedEvent const & rDCEvt)
1643 Window::DataChanged(rDCEvt);
1644 if (rDCEvt.GetType() == DATACHANGED_SETTINGS
1645 && (rDCEvt.GetFlags() & SETTINGS_STYLE) != 0)
1647 bool bInvalidate = false;
1648 Color aColor(GetSettings().GetStyleSettings().GetWindowColor());
1649 if (aColor
1650 != rDCEvt.GetOldSettings()->GetStyleSettings().GetWindowColor())
1652 SetBackground(Wallpaper(aColor));
1653 bInvalidate = true;
1655 aColor = GetSettings().GetStyleSettings().GetWindowTextColor();
1656 if (aColor != rDCEvt.GetOldSettings()->
1657 GetStyleSettings().GetWindowTextColor())
1659 Font aFont(GetFont());
1660 aFont.SetColor(aColor);
1661 SetFont(aFont);
1662 bInvalidate = true;
1664 if (bInvalidate)
1665 Invalidate();
1666 aColor = GetSettings().GetStyleSettings().GetFieldTextColor();
1667 if (aColor != m_aSyntaxColors[TT_UNKNOWN])
1669 m_aSyntaxColors[TT_UNKNOWN] = aColor;
1670 m_aSyntaxColors[TT_WHITESPACE] = aColor;
1671 m_aSyntaxColors[TT_EOL] = aColor;
1672 updateSyntaxHighlighting();
1677 // virtual
1678 void ModulWindowLayout::Notify(SfxBroadcaster & rBc, SfxHint const & rHint)
1680 (void)rBc;
1682 if (rHint.ISA(SfxSimpleHint)
1683 && (static_cast< SfxSimpleHint const & >(rHint).GetId()
1684 == SFX_HINT_COLORS_CHANGED))
1686 Color aColor(m_aColorConfig.GetColorValue(svtools::BASICIDENTIFIER).
1687 nColor);
1688 bool bChanged = aColor != m_aSyntaxColors[TT_IDENTIFIER];
1689 m_aSyntaxColors[TT_IDENTIFIER] = aColor;
1690 aColor = Color(m_aColorConfig.GetColorValue(svtools::BASICNUMBER).nColor);
1691 if (bChanged || aColor != m_aSyntaxColors[TT_NUMBER])
1692 bChanged = true;
1693 m_aSyntaxColors[TT_NUMBER] = aColor;
1694 aColor = Color(m_aColorConfig.GetColorValue(svtools::BASICSTRING).nColor);
1695 if (bChanged || aColor != m_aSyntaxColors[TT_STRING])
1696 bChanged = true;
1697 m_aSyntaxColors[TT_STRING] = aColor;
1698 aColor = Color(m_aColorConfig.GetColorValue(svtools::BASICCOMMENT).
1699 nColor);
1700 if (bChanged || aColor != m_aSyntaxColors[TT_COMMENT])
1701 bChanged = true;
1702 m_aSyntaxColors[TT_COMMENT] = aColor;
1703 aColor = Color(m_aColorConfig.GetColorValue(svtools::BASICERROR).nColor);
1704 if (bChanged || aColor != m_aSyntaxColors[TT_ERROR])
1705 bChanged = true;
1706 m_aSyntaxColors[TT_ERROR] = aColor;
1707 aColor = Color(m_aColorConfig.GetColorValue(svtools::BASICOPERATOR).
1708 nColor);
1709 if (bChanged || aColor != m_aSyntaxColors[TT_OPERATOR])
1710 bChanged = true;
1711 m_aSyntaxColors[TT_OPERATOR] = aColor;
1712 aColor = Color(m_aColorConfig.GetColorValue(svtools::BASICKEYWORD).
1713 nColor);
1714 if (bChanged || aColor != m_aSyntaxColors[TT_KEYWORDS])
1715 bChanged = true;
1716 m_aSyntaxColors[TT_KEYWORDS] = aColor;
1717 if (bChanged)
1718 updateSyntaxHighlighting();
1722 void ModulWindowLayout::updateSyntaxHighlighting()
1724 if (m_pModulWindow != 0)
1726 EditorWindow & rEditor = m_pModulWindow->GetEditorWindow();
1727 ULONG nCount = rEditor.GetEditEngine()->GetParagraphCount();
1728 for (ULONG i = 0; i < nCount; ++i)
1729 rEditor.DoDelayedSyntaxHighlight(i);
1733 Image ModulWindowLayout::getImage(USHORT nId, bool bHighContrastMode) const
1735 return (bHighContrastMode ? m_aImagesHighContrast : m_aImagesNormal).
1736 GetImage(nId);