merge the formfield patch from ooo-build
[ooovba.git] / basctl / source / basicide / baside2.cxx
blob1d31cfc27c85abff2c0e96717d790326348408be
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;
546 BOOL implImportDialog( Window* pWin, const String& rCurPath, const ScriptDocument& rDocument, const String& aLibName );
548 BOOL ModulWindow::ImportDialog()
550 const ScriptDocument& rDocument = GetDocument();
551 String aLibName = GetLibName();
552 BOOL bRet = implImportDialog( this, aCurPath, rDocument, aLibName );
553 return bRet;
556 BOOL ModulWindow::ToggleBreakPoint( ULONG nLine )
558 DBG_ASSERT( xModule.Is(), "Kein Modul!" );
560 BOOL bNewBreakPoint = FALSE;
562 if ( xModule.Is() )
564 CheckCompileBasic();
565 if ( aStatus.bError )
567 Sound::Beep();
568 return FALSE;
571 BreakPoint* pBrk = GetBreakPoints().FindBreakPoint( nLine );
572 if ( pBrk ) // entfernen
574 xModule->ClearBP( (USHORT)nLine );
575 delete GetBreakPoints().Remove( pBrk );
577 else // einen erzeugen
579 if ( xModule->SetBP( (USHORT)nLine) )
581 GetBreakPoints().InsertSorted( new BreakPoint( nLine ) );
582 bNewBreakPoint = TRUE;
583 if ( StarBASIC::IsRunning() )
585 for ( USHORT nMethod = 0; nMethod < xModule->GetMethods()->Count(); nMethod++ )
587 SbMethod* pMethod = (SbMethod*)xModule->GetMethods()->Get( nMethod );
588 DBG_ASSERT( pMethod, "Methode nicht gefunden! (NULL)" );
589 pMethod->SetDebugFlags( pMethod->GetDebugFlags() | SbDEBUG_BREAK );
594 if ( !bNewBreakPoint )
595 Sound::Beep();
599 return bNewBreakPoint;
602 void ModulWindow::UpdateBreakPoint( const BreakPoint& rBrk )
604 DBG_ASSERT( xModule.Is(), "Kein Modul!" );
606 if ( xModule.Is() )
608 CheckCompileBasic();
610 if ( rBrk.bEnabled )
611 xModule->SetBP( (USHORT)rBrk.nLine );
612 else
613 xModule->ClearBP( (USHORT)rBrk.nLine );
618 BOOL ModulWindow::BasicToggleBreakPoint()
620 DBG_CHKTHIS( ModulWindow, 0 );
621 AssertValidEditEngine();
623 TextSelection aSel = GetEditView()->GetSelection();
624 aSel.GetStart().GetPara()++; // Basic-Zeilen beginnen bei 1!
625 aSel.GetEnd().GetPara()++;
627 BOOL bNewBreakPoint = FALSE;
629 for ( ULONG nLine = aSel.GetStart().GetPara(); nLine <= aSel.GetEnd().GetPara(); nLine++ )
631 if ( ToggleBreakPoint( nLine ) )
632 bNewBreakPoint = TRUE;
635 aXEditorWindow.GetBrkWindow().Invalidate();
636 return bNewBreakPoint;
640 void ModulWindow::BasicToggleBreakPointEnabled()
642 DBG_CHKTHIS( ModulWindow, 0 );
643 AssertValidEditEngine();
645 ExtTextView* pView = GetEditView();
646 if ( pView )
648 TextSelection aSel = pView->GetSelection();
649 BreakPointList& rList = GetBreakPoints();
651 for ( ULONG nLine = ++aSel.GetStart().GetPara(), nEnd = ++aSel.GetEnd().GetPara(); nLine <= nEnd; ++nLine )
653 BreakPoint* pBrk = rList.FindBreakPoint( nLine );
654 if ( pBrk )
656 pBrk->bEnabled = pBrk->bEnabled ? FALSE : TRUE;
657 UpdateBreakPoint( *pBrk );
661 GetBreakPointWindow().Invalidate();
666 void ModulWindow::ManageBreakPoints()
668 BreakPointWindow& rBrkWin = GetBreakPointWindow();
669 BreakPointDialog aBrkDlg( &rBrkWin, GetBreakPoints() );
670 aBrkDlg.Execute();
671 rBrkWin.Invalidate();
675 IMPL_LINK( ModulWindow, BasicErrorHdl, StarBASIC *, pBasic )
677 DBG_CHKTHIS( ModulWindow, 0 );
678 GoOnTop();
680 // ReturnWert: BOOL
681 // FALSE: Abbrechen
682 // TRUE: Weiter....
683 String aErrorText( pBasic->GetErrorText() );
684 USHORT nErrorLine = pBasic->GetLine() - 1;
685 USHORT nErrCol1 = pBasic->GetCol1();
686 USHORT nErrCol2 = pBasic->GetCol2();
687 if ( nErrCol2 != 0xFFFF )
688 nErrCol2++;
690 AssertValidEditEngine();
691 GetEditView()->SetSelection( TextSelection( TextPaM( nErrorLine, nErrCol1 ), TextPaM( nErrorLine, nErrCol2 ) ) );
693 String aErrorTextPrefix;
694 if( pBasic->IsCompilerError() )
696 aErrorTextPrefix = String( IDEResId( RID_STR_COMPILEERROR ) );
698 else
700 aErrorTextPrefix = String( IDEResId( RID_STR_RUNTIMEERROR ) );
701 aErrorTextPrefix += StarBASIC::GetVBErrorCode( pBasic->GetErrorCode() );
702 aErrorTextPrefix += ' ';
703 pLayout->GetStackWindow().UpdateCalls();
705 // Wenn anderes Basic, dan sollte die IDE versuchen, da richtige
706 // Modul anzuzeigen...
707 BOOL bMarkError = ( pBasic == GetBasic() ) ? TRUE : FALSE;
708 if ( bMarkError )
709 aXEditorWindow.GetBrkWindow().SetMarkerPos( nErrorLine, TRUE );
710 // ErrorBox( this, WB_OK | WB_DEF_OK, String( aErrorTextPrefix + aErrorText ) ).Execute();
711 // ErrorHandler::HandleError( pBasic->GetErrorCode() );
713 // #i47002#
714 Reference< awt::XWindow > xWindow = VCLUnoHelper::GetInterface( this );
716 ErrorHandler::HandleError( StarBASIC::GetErrorCode() );
718 // #i47002#
719 Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
720 if ( !pWindow )
721 return FALSE;
723 if ( bMarkError )
724 aXEditorWindow.GetBrkWindow().SetMarkerPos( MARKER_NOMARKER );
725 return FALSE;
728 long __EXPORT ModulWindow::BasicBreakHdl( StarBASIC* pBasic )
730 DBG_CHKTHIS( ModulWindow, 0 );
731 // Ein GoOnTop aktiviert da Fenster, das veraendert aber den Context fuer
732 // das Programm!
733 // GoOnTop();
735 // #i69280 Required in Window despite normal usage in next command!
736 (void)pBasic;
738 // ReturnWert: USHORT => siehe SB-Debug-Flags
739 USHORT nErrorLine = pBasic->GetLine();
741 // Gibt es hier einen BreakPoint?
742 BreakPoint* pBrk = GetBreakPoints().FindBreakPoint( nErrorLine );
743 if ( pBrk )
745 pBrk->nHitCount++;
746 if ( pBrk->nHitCount < pBrk->nStopAfter && GetBasic()->IsBreak() )
747 return aStatus.nBasicFlags; // weiterlaufen...
750 nErrorLine--; // EditEngine begint bei 0, Basic bei 1
751 // Alleine schon damit gescrollt wird...
752 AssertValidEditEngine();
753 GetEditView()->SetSelection( TextSelection( TextPaM( nErrorLine, 0 ), TextPaM( nErrorLine, 0 ) ) );
754 aXEditorWindow.GetBrkWindow().SetMarkerPos( nErrorLine );
756 pLayout->GetWatchWindow().UpdateWatches();
757 pLayout->GetStackWindow().UpdateCalls();
759 aStatus.bIsInReschedule = TRUE;
760 aStatus.bIsRunning = TRUE;
762 AddStatus( BASWIN_INRESCHEDULE );
764 BasicIDE::InvalidateDebuggerSlots();
766 while( aStatus.bIsRunning )
767 Application::Yield();
769 aStatus.bIsInReschedule = FALSE;
770 aXEditorWindow.GetBrkWindow().SetMarkerPos( MARKER_NOMARKER );
772 ClearStatus( BASWIN_INRESCHEDULE );
774 return aStatus.nBasicFlags;
777 void ModulWindow::BasicAddWatch()
779 DBG_CHKTHIS( ModulWindow, 0 );
780 String aWatchStr;
781 BOOL bInserted = FALSE;
782 AssertValidEditEngine();
783 BOOL bAdd = TRUE;
784 if ( !GetEditView()->HasSelection() )
786 // bAdd = GetEditView()->SelectCurrentWord();
787 TextPaM aWordStart;
788 String aWord = GetEditEngine()->GetWord( GetEditView()->GetSelection().GetEnd(), &aWordStart );
789 if ( aWord.Len() )
791 TextSelection aSel( aWordStart );
792 USHORT& rIndex = aSel.GetEnd().GetIndex();
793 rIndex = rIndex + aWord.Len();
794 // aSel.GetEnd().GetIndex() += sal::static_int_cast<int>( aWord.Len() );
795 GetEditView()->SetSelection( aSel );
796 bAdd = TRUE;
799 if ( bAdd )
801 TextSelection aSel = GetEditView()->GetSelection();
802 if ( aSel.GetStart().GetPara() == aSel.GetEnd().GetPara() )
804 aWatchStr = GetEditView()->GetSelected();
805 pLayout->GetWatchWindow().AddWatch( aWatchStr );
806 pLayout->GetWatchWindow().UpdateWatches();
807 bInserted = TRUE;
811 if ( !bInserted )
812 Sound::Beep();
817 void ModulWindow::BasicRemoveWatch()
819 DBG_CHKTHIS( ModulWindow, 0 );
820 BOOL bRemoved = pLayout->GetWatchWindow().RemoveSelectedWatch();
822 if ( !bRemoved )
823 Sound::Beep();
827 void ModulWindow::EditMacro( const String& rMacroName )
829 DBG_CHKTHIS( ModulWindow, 0 );
830 DBG_ASSERT( xModule.Is(), "Kein Modul!" );
832 if ( xModule.Is() )
834 CheckCompileBasic();
836 if ( !aStatus.bError )
838 USHORT nStart, nEnd;
839 SbMethod* pMethod = (SbMethod*)xModule->Find( rMacroName, SbxCLASS_METHOD );
840 if ( pMethod )
842 pMethod->GetLineRange( nStart, nEnd );
843 if ( nStart )
845 // Basic beginnt bei 1
846 nStart--;
847 nEnd--;
849 TextSelection aSel( TextPaM( nStart, 0 ), TextPaM( nStart, 0 ) );
850 AssertValidEditEngine();
851 TextView * pView = GetEditView();
852 // ggf. hinscrollen, so dass erste Zeile oben...
853 long nVisHeight = GetOutputSizePixel().Height();
854 if ( (long)pView->GetTextEngine()->GetTextHeight() > nVisHeight )
856 long nMaxY = pView->GetTextEngine()->GetTextHeight() - nVisHeight;
857 long nOldStartY = pView->GetStartDocPos().Y();
858 long nNewStartY = nStart * pView->GetTextEngine()->GetCharHeight();
859 nNewStartY = Min( nNewStartY, nMaxY );
860 pView->Scroll( 0, -(nNewStartY-nOldStartY) );
861 pView->ShowCursor( FALSE, TRUE );
862 GetEditVScrollBar().SetThumbPos( pView->GetStartDocPos().Y() );
864 pView->SetSelection( aSel );
865 pView->ShowCursor();
866 pView->GetWindow()->GrabFocus();
873 void __EXPORT ModulWindow::StoreData()
875 DBG_CHKTHIS( ModulWindow, 0 );
876 // StoreData wird gerufen, wenn der BasicManager zerstoert oder
877 // dieses Fenster beendet wird.
878 // => Keine Unterbrechungen erwuenscht!
879 // Und bei SAVE, wenn AppBasic...
880 GetEditorWindow().SetSourceInBasic( TRUE );
881 // Nicht das Modify loeschen, sonst wird das Basic nicht gespeichert
882 // Es wird beim Speichern sowieso geloescht.
883 // xModule->SetModified( FALSE );
886 BOOL __EXPORT ModulWindow::CanClose()
888 DBG_CHKTHIS( ModulWindow, 0 );
889 return TRUE;
893 BOOL __EXPORT ModulWindow::AllowUndo()
895 return GetEditorWindow().CanModify();
899 void __EXPORT ModulWindow::UpdateData()
901 DBG_CHKTHIS( ModulWindow, 0 );
902 DBG_ASSERT( xModule.Is(), "Kein Modul!" );
903 // UpdateData wird gerufen, wenn sich der Source von aussen
904 // geaendert hat.
905 // => Keine Unterbrechungen erwuenscht!
907 if ( xModule.Is() )
909 SetModule( xModule->GetSource32() );
911 if ( GetEditView() )
913 TextSelection aSel = GetEditView()->GetSelection();
914 setTextEngineText( GetEditEngine(), xModule->GetSource32() );
915 GetEditView()->SetSelection( aSel );
916 GetEditEngine()->SetModified( FALSE );
917 BasicIDE::MarkDocumentModified( GetDocument() );
923 void __EXPORT ModulWindow::PrintData( Printer* pPrinter )
925 DBG_CHKTHIS( ModulWindow, 0 );
927 AssertValidEditEngine();
929 MapMode eOldMapMode( pPrinter->GetMapMode() );
930 Font aOldFont( pPrinter->GetFont() );
932 // Font aFont( GetEditEngine()->CreateFontFromItemSet( GetEditEngine()->GetEmptyItemSet() ) );
933 Font aFont( GetEditEngine()->GetFont() );
934 aFont.SetAlign( ALIGN_BOTTOM );
935 aFont.SetTransparent( TRUE );
936 aFont.SetSize( Size( 0, 360 ) );
937 pPrinter->SetFont( aFont );
938 pPrinter->SetMapMode( MAP_100TH_MM );
940 String aTitle( CreateQualifiedName() );
942 USHORT nLineHeight = (USHORT) pPrinter->GetTextHeight(); // etwas mehr.
943 USHORT nParaSpace = 10;
945 Size aPaperSz = pPrinter->GetOutputSize();
946 aPaperSz.Width() -= (LMARGPRN+RMARGPRN);
947 aPaperSz.Height() -= (TMARGPRN+BMARGPRN);
949 // nLinepPage stimmt nicht, wenn Zeilen umgebrochen werden muessen...
950 USHORT nLinespPage = (USHORT) (aPaperSz.Height()/nLineHeight);
951 USHORT nCharspLine = (USHORT) (aPaperSz.Width() / pPrinter->GetTextWidth( 'X' ) );
952 ULONG nParas = GetEditEngine()->GetParagraphCount();
954 USHORT nPages = (USHORT) (nParas/nLinespPage+1 );
955 USHORT nCurPage = 1;
957 pPrinter->StartJob( aTitle );
958 pPrinter->StartPage();
959 // Header drucken...
960 lcl_PrintHeader( pPrinter, nPages, nCurPage, aTitle );
961 Point aPos( LMARGPRN, TMARGPRN );
962 for ( ULONG nPara = 0; nPara < nParas; nPara++ )
964 String aLine( GetEditEngine()->GetText( nPara ) );
965 lcl_ConvertTabsToSpaces( aLine );
966 USHORT nLines = aLine.Len()/nCharspLine+1;
967 for ( USHORT nLine = 0; nLine < nLines; nLine++ )
969 String aTmpLine( aLine, nLine*nCharspLine, nCharspLine );
970 aPos.Y() += nLineHeight;
971 if ( aPos.Y() > ( aPaperSz.Height()+TMARGPRN ) )
973 nCurPage++;
974 pPrinter->EndPage();
975 pPrinter->StartPage();
976 lcl_PrintHeader( pPrinter, nPages, nCurPage, aTitle );
977 aPos = Point( LMARGPRN, TMARGPRN+nLineHeight );
979 pPrinter->DrawText( aPos, aTmpLine );
981 aPos.Y() += nParaSpace;
983 pPrinter->EndPage();
984 pPrinter->EndJob();
986 pPrinter->SetFont( aOldFont );
987 pPrinter->SetMapMode( eOldMapMode );
991 void __EXPORT ModulWindow::ExecuteCommand( SfxRequest& rReq )
993 DBG_CHKTHIS( ModulWindow, 0 );
994 AssertValidEditEngine();
995 USHORT nSlot = rReq.GetSlot();
996 switch ( nSlot )
998 case SID_BASICRUN:
1000 BasicRun();
1002 break;
1003 case SID_BASICCOMPILE:
1005 CompileBasic();
1007 break;
1008 case SID_BASICSTEPOVER:
1010 BasicStepOver();
1012 break;
1013 case SID_BASICSTEPINTO:
1015 BasicStepInto();
1017 break;
1018 case SID_BASICSTEPOUT:
1020 BasicStepOut();
1022 break;
1023 case SID_BASICLOAD:
1025 LoadBasic();
1027 break;
1028 case SID_BASICSAVEAS:
1030 SaveBasicSource();
1032 break;
1033 case SID_IMPORT_DIALOG:
1035 ImportDialog();
1037 break;
1038 case SID_BASICIDE_MATCHGROUP:
1040 if ( !GetEditView()->MatchGroup() )
1041 Sound::Beep();
1043 break;
1044 case SID_BASICIDE_TOGGLEBRKPNT:
1046 BasicToggleBreakPoint();
1048 break;
1049 case SID_BASICIDE_MANAGEBRKPNTS:
1051 ManageBreakPoints();
1053 break;
1054 case SID_BASICIDE_TOGGLEBRKPNTENABLED:
1056 BasicToggleBreakPointEnabled();
1058 break;
1059 case SID_BASICIDE_ADDWATCH:
1061 BasicAddWatch();
1063 break;
1064 case SID_BASICIDE_REMOVEWATCH:
1066 BasicRemoveWatch();
1068 break;
1069 case SID_CUT:
1071 if ( !IsReadOnly() )
1073 GetEditView()->Cut();
1074 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
1075 if ( pBindings )
1076 pBindings->Invalidate( SID_DOC_MODIFIED );
1079 break;
1080 case SID_COPY:
1082 GetEditView()->Copy();
1084 break;
1085 case SID_PASTE:
1087 if ( !IsReadOnly() )
1089 GetEditView()->Paste();
1090 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
1091 if ( pBindings )
1092 pBindings->Invalidate( SID_DOC_MODIFIED );
1095 break;
1096 case SID_BASICIDE_BRKPNTSCHANGED:
1098 GetBreakPointWindow().Invalidate();
1100 break;
1106 void __EXPORT ModulWindow::GetState( SfxItemSet &rSet )
1108 DBG_CHKTHIS( ModulWindow, 0 );
1109 SfxWhichIter aIter(rSet);
1110 for ( USHORT nWh = aIter.FirstWhich(); 0 != nWh; nWh = aIter.NextWhich() )
1112 switch ( nWh )
1114 // allgemeine Items:
1115 case SID_CUT:
1117 if ( !GetEditView() || !GetEditView()->HasSelection() )
1118 rSet.DisableItem( nWh );
1120 if ( IsReadOnly() )
1121 rSet.DisableItem( nWh );
1123 break;
1124 case SID_COPY:
1126 if ( !GetEditView() || !GetEditView()->HasSelection() )
1127 rSet.DisableItem( nWh );
1129 break;
1130 case SID_PASTE:
1132 if ( !IsPasteAllowed() )
1133 rSet.DisableItem( nWh );
1135 if ( IsReadOnly() )
1136 rSet.DisableItem( nWh );
1138 break;
1139 case SID_BASICIDE_STAT_POS:
1141 TextView* pView = GetEditView();
1142 if ( pView )
1144 TextSelection aSel = pView->GetSelection();
1145 String aPos( IDEResId( RID_STR_LINE ) );
1146 aPos += ' ';
1147 aPos += String::CreateFromInt32( aSel.GetEnd().GetPara()+1 );
1148 aPos += String( RTL_CONSTASCII_USTRINGPARAM( ", " ) );
1149 aPos += String( IDEResId( RID_STR_COLUMN ) );
1150 aPos += ' ';
1151 aPos += String::CreateFromInt32( aSel.GetEnd().GetIndex()+1 );
1152 SfxStringItem aItem( SID_BASICIDE_STAT_POS, aPos );
1153 rSet.Put( aItem );
1156 break;
1157 case SID_ATTR_INSERT:
1159 TextView* pView = GetEditView();
1160 if ( pView )
1162 SfxBoolItem aItem( SID_ATTR_INSERT, pView->IsInsertMode() );
1163 rSet.Put( aItem );
1166 break;
1172 void __EXPORT ModulWindow::DoScroll( ScrollBar* pCurScrollBar )
1174 DBG_CHKTHIS( ModulWindow, 0 );
1175 if ( ( pCurScrollBar == GetHScrollBar() ) && GetEditView() )
1177 // Nicht mit dem Wert Scrollen, sondern lieber die Thumb-Pos fuer die
1178 // VisArea verwenden:
1179 long nDiff = GetEditView()->GetStartDocPos().X() - pCurScrollBar->GetThumbPos();
1180 GetEditView()->Scroll( nDiff, 0 );
1181 GetEditView()->ShowCursor( FALSE, TRUE );
1182 pCurScrollBar->SetThumbPos( GetEditView()->GetStartDocPos().X() );
1188 BOOL ModulWindow::RenameModule( const String& rNewName )
1190 if ( !BasicIDE::RenameModule( this, GetDocument(), GetLibName(), GetName(), rNewName ) )
1191 return FALSE;
1193 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
1194 if ( pBindings )
1195 pBindings->Invalidate( SID_DOC_MODIFIED );
1197 return TRUE;
1201 BOOL __EXPORT ModulWindow::IsModified()
1203 return GetEditEngine() ? GetEditEngine()->IsModified() : FALSE;
1208 void __EXPORT ModulWindow::GoOnTop()
1210 IDE_DLL()->GetShell()->GetViewFrame()->ToTop();
1213 String ModulWindow::GetSbModuleName()
1215 String aModuleName;
1216 if ( xModule.Is() )
1217 aModuleName = xModule->GetName();
1218 return aModuleName;
1223 String __EXPORT ModulWindow::GetTitle()
1225 return GetSbModuleName();
1230 void ModulWindow::FrameWindowMoved()
1232 // if ( GetEditEngine() && GetEditEngine()->IsInSelectionMode() )
1233 // GetEditEngine()->StopSelectionMode();
1238 void ModulWindow::ShowCursor( BOOL bOn )
1240 if ( GetEditEngine() )
1242 TextView* pView = GetEditEngine()->GetActiveView();
1243 if ( pView )
1245 if ( bOn )
1246 pView->ShowCursor();
1247 else
1248 pView->HideCursor();
1254 Window* __EXPORT ModulWindow::GetLayoutWindow()
1256 return pLayout;
1259 void ModulWindow::AssertValidEditEngine()
1261 if ( !GetEditEngine() )
1262 GetEditorWindow().CreateEditEngine();
1265 void ModulWindow::Deactivating()
1267 if ( GetEditView() )
1268 GetEditView()->EraseVirtualDevice();
1271 USHORT ModulWindow::StartSearchAndReplace( const SvxSearchItem& rSearchItem, BOOL bFromStart )
1273 // Mann koennte fuer das blinde Alle-Ersetzen auch auf
1274 // Syntaxhighlighting/Formatierung verzichten...
1275 AssertValidEditEngine();
1276 ExtTextView* pView = GetEditView();
1277 TextSelection aSel;
1278 if ( bFromStart )
1280 aSel = pView->GetSelection();
1281 if ( !rSearchItem.GetBackward() )
1282 pView->SetSelection( TextSelection() );
1283 else
1284 pView->SetSelection( TextSelection( TextPaM( 0xFFFFFFFF, 0xFFFF ), TextPaM( 0xFFFFFFFF, 0xFFFF ) ) );
1287 BOOL bForward = !rSearchItem.GetBackward();
1288 USHORT nFound = 0;
1289 if ( ( rSearchItem.GetCommand() == SVX_SEARCHCMD_FIND ) ||
1290 ( rSearchItem.GetCommand() == SVX_SEARCHCMD_FIND_ALL ) )
1292 nFound = pView->Search( rSearchItem.GetSearchOptions() , bForward );
1294 else if ( ( rSearchItem.GetCommand() == SVX_SEARCHCMD_REPLACE ) ||
1295 ( rSearchItem.GetCommand() == SVX_SEARCHCMD_REPLACE_ALL ) )
1297 if ( !IsReadOnly() )
1299 BOOL bAll = rSearchItem.GetCommand() == SVX_SEARCHCMD_REPLACE_ALL;
1300 nFound = pView->Replace( rSearchItem.GetSearchOptions() , bAll , bForward );
1304 if ( bFromStart && !nFound )
1305 pView->SetSelection( aSel );
1307 return nFound;
1310 SfxUndoManager* __EXPORT ModulWindow::GetUndoManager()
1312 if ( GetEditEngine() )
1313 return &GetEditEngine()->GetUndoManager();
1314 return NULL;
1317 USHORT __EXPORT ModulWindow::GetSearchOptions()
1319 USHORT nOptions = SEARCH_OPTIONS_SEARCH |
1320 SEARCH_OPTIONS_WHOLE_WORDS |
1321 SEARCH_OPTIONS_BACKWARDS |
1322 SEARCH_OPTIONS_REG_EXP |
1323 SEARCH_OPTIONS_EXACT |
1324 SEARCH_OPTIONS_SELECTION |
1325 SEARCH_OPTIONS_SIMILARITY;
1327 if ( !IsReadOnly() )
1329 nOptions |= SEARCH_OPTIONS_REPLACE;
1330 nOptions |= SEARCH_OPTIONS_REPLACE_ALL;
1333 return nOptions;
1336 void __EXPORT ModulWindow::BasicStarted()
1338 if ( xModule.Is() )
1340 aStatus.bIsRunning = TRUE;
1341 BreakPointList& rList = GetBreakPoints();
1342 if ( rList.Count() )
1344 rList.ResetHitCount();
1345 rList.SetBreakPointsInBasic( xModule );
1346 for ( USHORT nMethod = 0; nMethod < xModule->GetMethods()->Count(); nMethod++ )
1348 SbMethod* pMethod = (SbMethod*)xModule->GetMethods()->Get( nMethod );
1349 DBG_ASSERT( pMethod, "Methode nicht gefunden! (NULL)" );
1350 pMethod->SetDebugFlags( pMethod->GetDebugFlags() | SbDEBUG_BREAK );
1356 void __EXPORT ModulWindow::BasicStopped()
1358 aStatus.bIsRunning = FALSE;
1359 GetBreakPointWindow().SetMarkerPos( MARKER_NOMARKER );
1362 BasicEntryDescriptor ModulWindow::CreateEntryDescriptor()
1364 ScriptDocument aDocument( GetDocument() );
1365 String aLibName( GetLibName() );
1366 LibraryLocation eLocation = aDocument.getLibraryLocation( aLibName );
1367 String aModName( GetName() );
1368 String aLibSubName;
1369 if( xBasic.Is() && xBasic->isVBAEnabled() && xModule.Is() )
1371 switch( xModule->GetModuleType() )
1373 case script::ModuleType::Document:
1375 aLibSubName = String( IDEResId( RID_STR_DOCUMENT_OBJECTS ) );
1376 uno::Reference< container::XNameContainer > xLib = aDocument.getOrCreateLibrary( E_SCRIPTS, aLibName );
1377 if( xLib.is() )
1379 String sObjName;
1380 lcl_getObjectName( xLib, aModName, sObjName );
1381 if( sObjName.Len() )
1383 aModName.AppendAscii(" (").Append(sObjName).AppendAscii(")");
1386 break;
1388 case script::ModuleType::Form:
1389 aLibSubName = String( IDEResId( RID_STR_USERFORMS ) );
1390 break;
1391 case script::ModuleType::Normal:
1392 aLibSubName = String( IDEResId( RID_STR_NORMAL_MODULES ) );
1393 break;
1394 case script::ModuleType::Class:
1395 aLibSubName = String( IDEResId( RID_STR_CLASS_MODULES ) );
1396 break;
1399 return BasicEntryDescriptor( aDocument, eLocation, aLibName, aLibSubName, aModName, OBJ_TYPE_MODULE );
1402 void ModulWindow::SetReadOnly( BOOL b )
1404 if ( GetEditView() )
1405 GetEditView()->SetReadOnly( b );
1408 BOOL ModulWindow::IsReadOnly()
1410 BOOL bReadOnly = FALSE;
1412 if ( GetEditView() )
1413 bReadOnly = GetEditView()->IsReadOnly();
1415 return bReadOnly;
1418 BOOL ModulWindow::IsPasteAllowed()
1420 BOOL bPaste = FALSE;
1422 // get clipboard
1423 Reference< datatransfer::clipboard::XClipboard > xClipboard = GetClipboard();
1424 if ( xClipboard.is() )
1426 // get clipboard content
1427 const sal_uInt32 nRef = Application::ReleaseSolarMutex();
1428 Reference< datatransfer::XTransferable > xTransf = xClipboard->getContents();
1429 Application::AcquireSolarMutex( nRef );
1430 if ( xTransf.is() )
1432 datatransfer::DataFlavor aFlavor;
1433 SotExchange::GetFormatDataFlavor( SOT_FORMAT_STRING, aFlavor );
1434 if ( xTransf->isDataFlavorSupported( aFlavor ) )
1436 bPaste = TRUE;
1441 return bPaste;
1444 ModulWindowLayout::ModulWindowLayout( Window* pParent ) :
1445 Window( pParent, WB_CLIPCHILDREN ),
1446 aVSplitter( this, WinBits( WB_VSCROLL ) ),
1447 aHSplitter( this, WinBits( WB_HSCROLL ) ),
1448 aWatchWindow( this ),
1449 aStackWindow( this ),
1450 bVSplitted(FALSE),
1451 bHSplitted(FALSE),
1452 m_pModulWindow(0),
1453 m_aImagesNormal(IDEResId(RID_IMGLST_LAYOUT)),
1454 m_aImagesHighContrast(IDEResId(RID_IMGLST_LAYOUT_HC))
1456 SetBackground(GetSettings().GetStyleSettings().GetWindowColor());
1458 aVSplitter.SetSplitHdl( LINK( this, ModulWindowLayout, SplitHdl ) );
1459 aHSplitter.SetSplitHdl( LINK( this, ModulWindowLayout, SplitHdl ) );
1460 aVSplitter.Show();
1461 aHSplitter.Show();
1463 aWatchWindow.Show();
1464 aStackWindow.Show();
1466 Color aColor(GetSettings().GetStyleSettings().GetFieldTextColor());
1467 m_aSyntaxColors[TT_UNKNOWN] = aColor;
1468 m_aSyntaxColors[TT_WHITESPACE] = aColor;
1469 m_aSyntaxColors[TT_EOL] = aColor;
1470 StartListening(m_aColorConfig);
1471 m_aSyntaxColors[TT_IDENTIFIER]
1472 = Color(m_aColorConfig.GetColorValue(svtools::BASICIDENTIFIER).nColor);
1473 m_aSyntaxColors[TT_NUMBER]
1474 = Color(m_aColorConfig.GetColorValue(svtools::BASICNUMBER).nColor);
1475 m_aSyntaxColors[TT_STRING]
1476 = Color(m_aColorConfig.GetColorValue(svtools::BASICSTRING).nColor);
1477 m_aSyntaxColors[TT_COMMENT]
1478 = Color(m_aColorConfig.GetColorValue(svtools::BASICCOMMENT).nColor);
1479 m_aSyntaxColors[TT_ERROR]
1480 = Color(m_aColorConfig.GetColorValue(svtools::BASICERROR).nColor);
1481 m_aSyntaxColors[TT_OPERATOR]
1482 = Color(m_aColorConfig.GetColorValue(svtools::BASICOPERATOR).nColor);
1483 m_aSyntaxColors[TT_KEYWORDS]
1484 = Color(m_aColorConfig.GetColorValue(svtools::BASICKEYWORD).nColor);
1486 Font aFont( GetFont() );
1487 Size aSz( aFont.GetSize() );
1488 aSz.Height() *= 3;
1489 aSz.Height() /= 2;
1490 aFont.SetSize( aSz );
1491 aFont.SetWeight( WEIGHT_BOLD );
1492 aFont.SetColor(GetSettings().GetStyleSettings().GetWindowTextColor());
1493 SetFont( aFont );
1496 ModulWindowLayout::~ModulWindowLayout()
1498 EndListening(m_aColorConfig);
1501 void __EXPORT ModulWindowLayout::Resize()
1503 // ScrollBars, etc. passiert in BasicIDEShell:Adjust...
1504 ArrangeWindows();
1505 // Invalidate();
1508 void __EXPORT ModulWindowLayout::Paint( const Rectangle& )
1510 DrawText( Point(), String( IDEResId( RID_STR_NOMODULE ) ) );
1514 void ModulWindowLayout::ArrangeWindows()
1516 Size aSz = GetOutputSizePixel();
1518 // prueffen, ob der Splitter in einem gueltigen Bereich liegt...
1519 long nMinPos = SPLIT_MARGIN;
1520 long nMaxPos = aSz.Height() - SPLIT_MARGIN;
1522 long nVSplitPos = aVSplitter.GetSplitPosPixel();
1523 long nHSplitPos = aHSplitter.GetSplitPosPixel();
1524 if ( !bVSplitted )
1526 // Wenn noch nie gesplitted wurde, Verhaeltniss = 3 : 4
1527 nVSplitPos = aSz.Height() * 3 / 4;
1528 aVSplitter.SetSplitPosPixel( nVSplitPos );
1530 if ( !bHSplitted )
1532 // Wenn noch nie gesplitted wurde, Verhaeltniss = 2 : 3
1533 nHSplitPos = aSz.Width() * 2 / 3;
1534 aHSplitter.SetSplitPosPixel( nHSplitPos );
1536 if ( ( nVSplitPos < nMinPos ) || ( nVSplitPos > nMaxPos ) )
1537 nVSplitPos = ( nVSplitPos < nMinPos ) ? 0 : ( aSz.Height() - SPLIT_HEIGHT );
1539 Size aXEWSz;
1540 aXEWSz.Width() = aSz.Width();
1541 aXEWSz.Height() = nVSplitPos + 1;
1542 if ( m_pModulWindow )
1544 DBG_CHKOBJ( m_pModulWindow, ModulWindow, 0 );
1545 m_pModulWindow->SetPosSizePixel( Point( 0, 0 ), aXEWSz );
1548 aVSplitter.SetDragRectPixel( Rectangle( Point( 0, 0 ), Size( aSz.Width(), aSz.Height() ) ) );
1549 aVSplitter.SetPosPixel( Point( 0, nVSplitPos ) );
1550 aVSplitter.SetSizePixel( Size( aSz.Width(), SPLIT_HEIGHT ) );
1552 aHSplitter.SetDragRectPixel( Rectangle( Point( 0, nVSplitPos+SPLIT_HEIGHT ), Size( aSz.Width(), aSz.Height() - nVSplitPos - SPLIT_HEIGHT ) ) );
1553 aHSplitter.SetPosPixel( Point( nHSplitPos, nVSplitPos ) );
1554 aHSplitter.SetSizePixel( Size( SPLIT_HEIGHT, aSz.Height() - nVSplitPos ) );
1556 Size aWWSz;
1557 Point aWWPos( 0, nVSplitPos+SPLIT_HEIGHT );
1558 aWWSz.Width() = nHSplitPos;
1559 aWWSz.Height() = aSz.Height() - aWWPos.Y();
1560 if ( !aWatchWindow.IsFloatingMode() )
1561 aWatchWindow.SetPosSizePixel( aWWPos, aWWSz );
1563 Size aSWSz;
1564 Point aSWPos( nHSplitPos+SPLIT_HEIGHT, nVSplitPos+SPLIT_HEIGHT );
1565 aSWSz.Width() = aSz.Width() - aSWPos.X();
1566 aSWSz.Height() = aSz.Height() - aSWPos.Y();
1567 if ( !aStackWindow.IsFloatingMode() )
1568 aStackWindow.SetPosSizePixel( aSWPos, aSWSz );
1570 if ( aStackWindow.IsFloatingMode() && aWatchWindow.IsFloatingMode() )
1571 aHSplitter.Hide();
1572 else
1573 aHSplitter.Show();
1575 long nHDoubleClickSplitPosX = aSz.Width()-aHSplitter.GetSizePixel().Width();
1576 if ( aHSplitter.GetSplitPosPixel() < nHDoubleClickSplitPosX )
1577 aHSplitter.SetLastSplitPosPixel( nHDoubleClickSplitPosX );
1580 long nHDoubleClickSplitPosY = aSz.Height()-aVSplitter.GetSizePixel().Height();
1581 if ( aVSplitter.GetSplitPosPixel() < nHDoubleClickSplitPosY )
1582 aVSplitter.SetLastSplitPosPixel( nHDoubleClickSplitPosY );
1585 IMPL_LINK( ModulWindowLayout, SplitHdl, Splitter *, pSplitter )
1587 if ( pSplitter == &aVSplitter )
1588 bVSplitted = TRUE;
1589 else
1590 bHSplitted = TRUE;
1592 ArrangeWindows();
1593 return 0;
1596 BOOL ModulWindowLayout::IsToBeDocked( DockingWindow* pDockingWindow, const Point& rPos, Rectangle& rRect )
1598 // prueffen, ob als Dock oder als Child:
1599 // TRUE: Floating
1600 // FALSE: Child
1601 Point aPosInMe = ScreenToOutputPixel( rPos );
1602 Size aSz = GetOutputSizePixel();
1603 if ( ( aPosInMe.X() > 0 ) && ( aPosInMe.X() < aSz.Width() ) &&
1604 ( aPosInMe.Y() > 0 ) && ( aPosInMe.Y() < aSz.Height() ) )
1606 long nVSplitPos = aVSplitter.GetSplitPosPixel();
1607 long nHSplitPos = aHSplitter.GetSplitPosPixel();
1608 if ( pDockingWindow == &aWatchWindow )
1610 if ( ( aPosInMe.Y() > nVSplitPos ) && ( aPosInMe.X() < nHSplitPos ) )
1612 rRect.SetSize( Size( nHSplitPos, aSz.Height() - nVSplitPos ) );
1613 rRect.SetPos( OutputToScreenPixel( Point( 0, nVSplitPos ) ) );
1614 return TRUE;
1617 if ( pDockingWindow == &aStackWindow )
1619 if ( ( aPosInMe.Y() > nVSplitPos ) && ( aPosInMe.X() > nHSplitPos ) )
1621 rRect.SetSize( Size( aSz.Width() - nHSplitPos, aSz.Height() - nVSplitPos ) );
1622 rRect.SetPos( OutputToScreenPixel( Point( nHSplitPos, nVSplitPos ) ) );
1623 return TRUE;
1627 return FALSE;
1630 void ModulWindowLayout::DockaWindow( DockingWindow* pDockingWindow )
1632 if ( pDockingWindow == &aWatchWindow )
1634 // evtl. Sonderbehandlung...
1635 ArrangeWindows();
1637 else if ( pDockingWindow == &aStackWindow )
1639 // evtl. Sonderbehandlung...
1640 ArrangeWindows();
1642 #ifndef PRODUCT
1643 else
1644 DBG_ERROR( "Wer will sich denn hier andocken ?" );
1645 #endif
1648 void ModulWindowLayout::SetModulWindow( ModulWindow* pModWin )
1650 m_pModulWindow = pModWin;
1651 ArrangeWindows();
1654 // virtual
1655 void ModulWindowLayout::DataChanged(DataChangedEvent const & rDCEvt)
1657 Window::DataChanged(rDCEvt);
1658 if (rDCEvt.GetType() == DATACHANGED_SETTINGS
1659 && (rDCEvt.GetFlags() & SETTINGS_STYLE) != 0)
1661 bool bInvalidate = false;
1662 Color aColor(GetSettings().GetStyleSettings().GetWindowColor());
1663 if (aColor
1664 != rDCEvt.GetOldSettings()->GetStyleSettings().GetWindowColor())
1666 SetBackground(Wallpaper(aColor));
1667 bInvalidate = true;
1669 aColor = GetSettings().GetStyleSettings().GetWindowTextColor();
1670 if (aColor != rDCEvt.GetOldSettings()->
1671 GetStyleSettings().GetWindowTextColor())
1673 Font aFont(GetFont());
1674 aFont.SetColor(aColor);
1675 SetFont(aFont);
1676 bInvalidate = true;
1678 if (bInvalidate)
1679 Invalidate();
1680 aColor = GetSettings().GetStyleSettings().GetFieldTextColor();
1681 if (aColor != m_aSyntaxColors[TT_UNKNOWN])
1683 m_aSyntaxColors[TT_UNKNOWN] = aColor;
1684 m_aSyntaxColors[TT_WHITESPACE] = aColor;
1685 m_aSyntaxColors[TT_EOL] = aColor;
1686 updateSyntaxHighlighting();
1691 // virtual
1692 void ModulWindowLayout::Notify(SfxBroadcaster & rBc, SfxHint const & rHint)
1694 (void)rBc;
1696 if (rHint.ISA(SfxSimpleHint)
1697 && (static_cast< SfxSimpleHint const & >(rHint).GetId()
1698 == SFX_HINT_COLORS_CHANGED))
1700 Color aColor(m_aColorConfig.GetColorValue(svtools::BASICIDENTIFIER).
1701 nColor);
1702 bool bChanged = aColor != m_aSyntaxColors[TT_IDENTIFIER];
1703 m_aSyntaxColors[TT_IDENTIFIER] = aColor;
1704 aColor = Color(m_aColorConfig.GetColorValue(svtools::BASICNUMBER).nColor);
1705 if (bChanged || aColor != m_aSyntaxColors[TT_NUMBER])
1706 bChanged = true;
1707 m_aSyntaxColors[TT_NUMBER] = aColor;
1708 aColor = Color(m_aColorConfig.GetColorValue(svtools::BASICSTRING).nColor);
1709 if (bChanged || aColor != m_aSyntaxColors[TT_STRING])
1710 bChanged = true;
1711 m_aSyntaxColors[TT_STRING] = aColor;
1712 aColor = Color(m_aColorConfig.GetColorValue(svtools::BASICCOMMENT).
1713 nColor);
1714 if (bChanged || aColor != m_aSyntaxColors[TT_COMMENT])
1715 bChanged = true;
1716 m_aSyntaxColors[TT_COMMENT] = aColor;
1717 aColor = Color(m_aColorConfig.GetColorValue(svtools::BASICERROR).nColor);
1718 if (bChanged || aColor != m_aSyntaxColors[TT_ERROR])
1719 bChanged = true;
1720 m_aSyntaxColors[TT_ERROR] = aColor;
1721 aColor = Color(m_aColorConfig.GetColorValue(svtools::BASICOPERATOR).
1722 nColor);
1723 if (bChanged || aColor != m_aSyntaxColors[TT_OPERATOR])
1724 bChanged = true;
1725 m_aSyntaxColors[TT_OPERATOR] = aColor;
1726 aColor = Color(m_aColorConfig.GetColorValue(svtools::BASICKEYWORD).
1727 nColor);
1728 if (bChanged || aColor != m_aSyntaxColors[TT_KEYWORDS])
1729 bChanged = true;
1730 m_aSyntaxColors[TT_KEYWORDS] = aColor;
1731 if (bChanged)
1732 updateSyntaxHighlighting();
1736 void ModulWindowLayout::updateSyntaxHighlighting()
1738 if (m_pModulWindow != 0)
1740 EditorWindow & rEditor = m_pModulWindow->GetEditorWindow();
1741 ULONG nCount = rEditor.GetEditEngine()->GetParagraphCount();
1742 for (ULONG i = 0; i < nCount; ++i)
1743 rEditor.DoDelayedSyntaxHighlight(i);
1747 Image ModulWindowLayout::getImage(USHORT nId, bool bHighContrastMode) const
1749 return (bHighContrastMode ? m_aImagesHighContrast : m_aImagesNormal).
1750 GetImage(nId);