LCOV - code coverage report
Current view: top level - basctl/source/basicide - baside2.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 791 0.0 %
Date: 2014-04-11 Functions: 0 87 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "baside2.hxx"
      21             : #include "brkdlg.hxx"
      22             : #include "iderdll.hxx"
      23             : #include "iderdll2.hxx"
      24             : #include "objdlg.hxx"
      25             : #include "moduldlg.hxx"
      26             : #include "docsignature.hxx"
      27             : 
      28             : #include "helpid.hrc"
      29             : #include "baside2.hrc"
      30             : 
      31             : #include <basic/basmgr.hxx>
      32             : #include <basic/basrdll.hxx>
      33             : #include <basic/sbmeth.hxx>
      34             : #include <com/sun/star/script/ModuleType.hpp>
      35             : #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
      36             : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
      37             : #include <com/sun/star/ui/dialogs/FilePicker.hpp>
      38             : #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
      39             : #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
      40             : #include <comphelper/processfactory.hxx>
      41             : #include <comphelper/string.hxx>
      42             : #include <sfx2/dinfdlg.hxx>
      43             : #include <sfx2/dispatch.hxx>
      44             : #include <sfx2/docfile.hxx>
      45             : #include <sfx2/printer.hxx>
      46             : #include <sfx2/request.hxx>
      47             : #include <svl/aeitem.hxx>
      48             : #include <svl/srchitem.hxx>
      49             : #include <svl/visitem.hxx>
      50             : #include <svl/whiter.hxx>
      51             : #include <vcl/xtextedt.hxx>
      52             : #include <vcl/settings.hxx>
      53             : #include <toolkit/helper/vclunohelper.hxx>
      54             : #include <vcl/msgbox.hxx>
      55             : #include <cassert>
      56             : #include <basic/codecompletecache.hxx>
      57             : #include <svtools/miscopt.hxx>
      58             : 
      59             : namespace basctl
      60             : {
      61             : 
      62             : namespace
      63             : {
      64             : 
      65             : namespace Print
      66             : {
      67             :     long const nLeftMargin = 1700;
      68             :     long const nRightMargin = 900;
      69             :     long const nTopMargin = 2000;
      70             :     long const nBottomMargin = 1000;
      71             :     long const nBorder = 300;
      72             : }
      73             : 
      74             : short const ValidWindow = 0x1234;
      75             : 
      76             : // What (who) are OW and MTF? Compare to baside3.cxx where an
      77             : // identically named variable, used in the same way, has the value
      78             : // "*.*" on Windows, "*" otherwise. Is that what should be done here,
      79             : // too?
      80             : 
      81             : #if defined(OW) || defined(MTF)
      82             : char const FilterMask_All[] = "*";
      83             : #else
      84             : char const FilterMask_All[] = "*.*";
      85             : #endif
      86             : 
      87             : } // namespace
      88             : 
      89             : using namespace ::com::sun::star;
      90             : using namespace ::com::sun::star::uno;
      91             : using namespace ::com::sun::star::ui::dialogs;
      92             : using namespace utl;
      93             : using namespace comphelper;
      94             : 
      95           0 : TYPEINIT1( ModulWindow , BaseWindow );
      96             : 
      97             : namespace
      98             : {
      99             : 
     100           0 : void lcl_PrintHeader( Printer* pPrinter, sal_uInt16 nPages, sal_uInt16 nCurPage, const OUString& rTitle, bool bOutput )
     101             : {
     102           0 :     Size const aSz = pPrinter->GetOutputSize();
     103             : 
     104           0 :     const Color aOldLineColor( pPrinter->GetLineColor() );
     105           0 :     const Color aOldFillColor( pPrinter->GetFillColor() );
     106           0 :     const Font  aOldFont( pPrinter->GetFont() );
     107             : 
     108           0 :     pPrinter->SetLineColor( Color( COL_BLACK ) );
     109           0 :     pPrinter->SetFillColor();
     110             : 
     111           0 :     Font aFont( aOldFont );
     112           0 :     aFont.SetWeight( WEIGHT_BOLD );
     113           0 :     aFont.SetAlign( ALIGN_BOTTOM );
     114           0 :     pPrinter->SetFont( aFont );
     115             : 
     116           0 :     long nFontHeight = pPrinter->GetTextHeight();
     117             : 
     118             :     // 1st Border => line, 2+3 Border = free space
     119           0 :     long nYTop = Print::nTopMargin - 3*Print::nBorder - nFontHeight;
     120             : 
     121           0 :     long nXLeft = Print::nLeftMargin - Print::nBorder;
     122           0 :     long nXRight = aSz.Width() - Print::nRightMargin + Print::nBorder;
     123             : 
     124           0 :     if( bOutput )
     125             :         pPrinter->DrawRect(Rectangle(
     126             :             Point(nXLeft, nYTop),
     127           0 :             Size(nXRight - nXLeft, aSz.Height() - nYTop - Print::nBottomMargin + Print::nBorder)
     128           0 :         ));
     129             : 
     130             : 
     131           0 :     long nY = Print::nTopMargin - 2*Print::nBorder;
     132           0 :     Point aPos(Print::nLeftMargin, nY);
     133           0 :     if( bOutput )
     134           0 :         pPrinter->DrawText( aPos, rTitle );
     135           0 :     if ( nPages != 1 )
     136             :     {
     137           0 :         aFont.SetWeight( WEIGHT_NORMAL );
     138           0 :         pPrinter->SetFont( aFont );
     139           0 :         aPos.X() += pPrinter->GetTextWidth( rTitle );
     140             : 
     141           0 :         if( bOutput )
     142             :         {
     143           0 :             OUString aPageStr = " [" + IDE_RESSTR(RID_STR_PAGE) + " " + OUString::number( nCurPage ) + "]";
     144           0 :             pPrinter->DrawText( aPos, aPageStr );
     145             :         }
     146             :     }
     147             : 
     148           0 :     nY = Print::nTopMargin - Print::nBorder;
     149             : 
     150           0 :     if( bOutput )
     151           0 :         pPrinter->DrawLine( Point( nXLeft, nY ), Point( nXRight, nY ) );
     152             : 
     153           0 :     pPrinter->SetFont( aOldFont );
     154           0 :     pPrinter->SetFillColor( aOldFillColor );
     155           0 :     pPrinter->SetLineColor( aOldLineColor );
     156           0 : }
     157             : 
     158           0 : void lcl_ConvertTabsToSpaces( OUString& rLine )
     159             : {
     160           0 :     if ( !rLine.isEmpty() )
     161             :     {
     162           0 :         OUStringBuffer aResult( rLine );
     163           0 :         sal_Int32 nPos = 0;
     164           0 :         sal_Int32 nMax = aResult.getLength();
     165           0 :         while ( nPos < nMax )
     166             :         {
     167           0 :             if ( aResult[nPos] == '\t' )
     168             :             {
     169             :                 // not 4 Blanks, but at 4 TabPos:
     170           0 :                 OUStringBuffer aBlanker;
     171           0 :                 string::padToLength(aBlanker, ( 4 - ( nPos % 4 ) ), ' ');
     172           0 :                 aResult.remove( nPos, 1 );
     173           0 :                 aResult.insert( nPos, aBlanker.makeStringAndClear() );
     174           0 :                 nMax = aResult.getLength();
     175             :             }
     176           0 :             ++nPos;
     177             :         }
     178           0 :         rLine = aResult.makeStringAndClear();
     179             :     }
     180           0 : }
     181             : 
     182             : // until we have some configuration lets just keep
     183             : // persist this value for the process lifetime
     184             : bool bSourceLinesEnabled = false;
     185             : 
     186             : } // namespace
     187             : 
     188             : 
     189             : 
     190             : // ModulWindow
     191             : 
     192             : 
     193             : 
     194           0 : ModulWindow::ModulWindow (
     195             :     ModulWindowLayout* pParent,
     196             :     ScriptDocument const& rDocument,
     197             :     const OUString& aLibName, const OUString& aName, OUString& aModule
     198             : ) :
     199             :     BaseWindow(pParent, rDocument, aLibName, aName),
     200             :     rLayout(*pParent),
     201             :     nValid(ValidWindow),
     202             :     aXEditorWindow(this),
     203           0 :     m_aModule(aModule)
     204             : {
     205           0 :     aXEditorWindow.Show();
     206           0 :     SetBackground();
     207           0 : }
     208             : 
     209           0 : SbModuleRef ModulWindow::XModule()
     210             : {
     211             :     // ModuleWindows can now be created as a result of the
     212             :     // modules getting created via the api. This is a result of an
     213             :     // elementInserted event from the BasicLibrary container.
     214             :     // However the SbModule is also created from a different listener to
     215             :     // the same event ( in basmgr ) Therefore it is possible when we look
     216             :     // for xModule it may not yet be available, here we keep tring to access
     217             :     // the module until such time as it exists
     218             : 
     219           0 :     if ( !xModule.Is() )
     220             :     {
     221           0 :         BasicManager* pBasMgr = GetDocument().getBasicManager();
     222           0 :         if ( pBasMgr )
     223             :         {
     224           0 :             StarBASIC* pBasic = pBasMgr->GetLib( GetLibName() );
     225           0 :             if ( pBasic )
     226             :             {
     227           0 :                 xBasic = pBasic;
     228           0 :                 xModule = (SbModule*)pBasic->FindModule( GetName() );
     229             :             }
     230             :         }
     231             :     }
     232           0 :     return xModule;
     233             : }
     234             : 
     235           0 : ModulWindow::~ModulWindow()
     236             : {
     237           0 :     nValid = 0;
     238             : 
     239           0 :     StarBASIC::Stop();
     240           0 : }
     241             : 
     242             : 
     243           0 : void ModulWindow::GetFocus()
     244             : {
     245           0 :     if (nValid != ValidWindow)
     246           0 :         return;
     247           0 :     aXEditorWindow.GetEdtWindow().GrabFocus();
     248             :     // don't call basic calls because focus is somewhere else...
     249             : }
     250             : 
     251           0 : void ModulWindow::DoInit()
     252             : {
     253           0 :     if ( GetVScrollBar() )
     254           0 :         GetVScrollBar()->Hide();
     255           0 :     GetHScrollBar()->Show();
     256           0 :     GetEditorWindow().InitScrollBars();
     257           0 : }
     258             : 
     259             : 
     260           0 : void ModulWindow::Paint( const Rectangle& )
     261             : {
     262           0 : }
     263             : 
     264           0 : void ModulWindow::Resize()
     265             : {
     266             :     aXEditorWindow.SetPosSizePixel( Point( 0, 0 ),
     267           0 :                                     Size( GetOutputSizePixel() ) );
     268           0 : }
     269             : 
     270             : 
     271           0 : void ModulWindow::CheckCompileBasic()
     272             : {
     273           0 :     if ( XModule().Is() )
     274             :     {
     275             :         // never compile while running!
     276           0 :         bool const bRunning = StarBASIC::IsRunning();
     277           0 :         bool const bModified = ( !xModule->IsCompiled() ||
     278           0 :             ( GetEditEngine() && GetEditEngine()->IsModified() ) );
     279             : 
     280           0 :         if ( !bRunning && bModified )
     281             :         {
     282           0 :             bool bDone = false;
     283             : 
     284           0 :             GetShell()->GetViewFrame()->GetWindow().EnterWait();
     285             : 
     286           0 :             if( bModified )
     287             :             {
     288           0 :                 AssertValidEditEngine();
     289           0 :                 GetEditorWindow().SetSourceInBasic();
     290             :             }
     291             : 
     292           0 :             bool bWasModified = GetBasic()->IsModified();
     293             : 
     294           0 :             bDone = GetBasic()->Compile( xModule );
     295           0 :             if ( !bWasModified )
     296           0 :                 GetBasic()->SetModified(false);
     297             : 
     298           0 :             if ( bDone )
     299             :             {
     300           0 :                 GetBreakPoints().SetBreakPointsInBasic( xModule );
     301             :             }
     302             : 
     303           0 :             GetShell()->GetViewFrame()->GetWindow().LeaveWait();
     304             : 
     305           0 :             aStatus.bError = !bDone;
     306           0 :             aStatus.bIsRunning = false;
     307             :         }
     308             :     }
     309           0 : }
     310             : 
     311           0 : bool ModulWindow::BasicExecute()
     312             : {
     313             :     // #116444# check security settings before macro execution
     314           0 :     ScriptDocument aDocument( GetDocument() );
     315           0 :     if ( aDocument.isDocument() )
     316             :     {
     317           0 :         if ( !aDocument.allowMacros() )
     318             :         {
     319           0 :             WarningBox( this, WB_OK, IDE_RESSTR(RID_STR_CANNOTRUNMACRO)).Execute();
     320           0 :             return false;
     321             :         }
     322             :     }
     323             : 
     324           0 :     CheckCompileBasic();
     325             : 
     326           0 :     if ( XModule().Is() && xModule->IsCompiled() && !aStatus.bError )
     327             :     {
     328           0 :         if ( GetBreakPoints().size() )
     329           0 :             aStatus.nBasicFlags = aStatus.nBasicFlags | SbDEBUG_BREAK;
     330             : 
     331           0 :         if ( !aStatus.bIsRunning )
     332             :         {
     333             :             DBG_ASSERT( xModule.Is(), "Kein Modul!" );
     334           0 :             AddStatus( BASWIN_RUNNINGBASIC );
     335           0 :             sal_uInt16 nStart, nEnd, nCurMethodStart = 0;
     336           0 :             TextSelection aSel = GetEditView()->GetSelection();
     337             :             // Init cursor to top
     338           0 :             nCurMethodStart = ( aSel.GetStart().GetPara() + 1 );
     339           0 :             SbMethod* pMethod = 0;
     340             :             // first Macro, else blind "Main" (ExtSearch?)
     341           0 :             for ( sal_uInt16 nMacro = 0; nMacro < xModule->GetMethods()->Count(); nMacro++ )
     342             :             {
     343           0 :                 SbMethod* pM = (SbMethod*)xModule->GetMethods()->Get( nMacro );
     344             :                 DBG_ASSERT( pM, "Method?" );
     345           0 :                 pM->GetLineRange( nStart, nEnd );
     346           0 :                 if (  nCurMethodStart >= nStart && nCurMethodStart <= nEnd )
     347             :                 {
     348             :                     // matched a method to the cursor position
     349           0 :                     pMethod = pM;
     350           0 :                     break;
     351             :                 }
     352             :             }
     353           0 :             if ( !pMethod )
     354             :             {
     355             :                 // If not in a method then prompt the user
     356           0 :                 return ( !ChooseMacro( uno::Reference< frame::XModel >(), false, OUString() ).isEmpty() );
     357             :             }
     358           0 :             if ( pMethod )
     359             :             {
     360           0 :                 pMethod->SetDebugFlags( aStatus.nBasicFlags );
     361           0 :                 BasicDLL::SetDebugMode( true );
     362           0 :                 RunMethod( pMethod );
     363           0 :                 BasicDLL::SetDebugMode( false );
     364             :                 // if cancelled during Interactive=false
     365           0 :                 BasicDLL::EnableBreak( true );
     366             :             }
     367           0 :             ClearStatus( BASWIN_RUNNINGBASIC );
     368             :         }
     369             :         else
     370           0 :             aStatus.bIsRunning = false; // cancel of Reschedule()
     371             :     }
     372             : 
     373           0 :     bool bDone = !aStatus.bError;
     374             : 
     375           0 :     return bDone;
     376             : }
     377             : 
     378           0 : bool ModulWindow::CompileBasic()
     379             : {
     380           0 :     CheckCompileBasic();
     381             : 
     382           0 :     return XModule().Is() && xModule->IsCompiled();
     383             : }
     384             : 
     385           0 : bool ModulWindow::BasicRun()
     386             : {
     387           0 :     aStatus.nBasicFlags = 0;
     388           0 :     return BasicExecute();
     389             : }
     390             : 
     391           0 : bool ModulWindow::BasicStepOver()
     392             : {
     393           0 :     aStatus.nBasicFlags = SbDEBUG_STEPINTO | SbDEBUG_STEPOVER;
     394           0 :     return BasicExecute();
     395             : }
     396             : 
     397             : 
     398           0 : bool ModulWindow::BasicStepInto()
     399             : {
     400           0 :     aStatus.nBasicFlags = SbDEBUG_STEPINTO;
     401           0 :     return BasicExecute();
     402             : }
     403             : 
     404           0 : bool ModulWindow::BasicStepOut()
     405             : {
     406           0 :     aStatus.nBasicFlags = SbDEBUG_STEPOUT;
     407           0 :     return BasicExecute();
     408             : }
     409             : 
     410             : 
     411             : 
     412           0 : void ModulWindow::BasicStop()
     413             : {
     414           0 :     GetBasic()->Stop();
     415           0 :     aStatus.bIsRunning = false;
     416           0 : }
     417             : 
     418           0 : bool ModulWindow::LoadBasic()
     419             : {
     420           0 :     bool bDone = false;
     421             : 
     422           0 :     Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
     423           0 :     Reference < XFilePicker3 > xFP = FilePicker::createWithMode(xContext, TemplateDescription::FILEOPEN_SIMPLE);
     424             : 
     425           0 :     if ( !aCurPath.isEmpty() )
     426           0 :         xFP->setDisplayDirectory ( aCurPath );
     427             : 
     428           0 :     xFP->appendFilter( "BASIC" , "*.bas" );
     429           0 :     xFP->appendFilter( IDE_RESSTR(RID_STR_FILTER_ALLFILES), OUString( FilterMask_All ) );
     430           0 :     xFP->setCurrentFilter( "BASIC" );
     431             : 
     432           0 :     if( xFP->execute() == RET_OK )
     433             :     {
     434           0 :         Sequence< OUString > aPaths = xFP->getFiles();
     435           0 :         aCurPath = aPaths[0];
     436           0 :         SfxMedium aMedium( aCurPath, STREAM_READ | STREAM_SHARE_DENYWRITE | STREAM_NOCREATE );
     437           0 :         SvStream* pStream = aMedium.GetInStream();
     438           0 :         if ( pStream )
     439             :         {
     440           0 :             AssertValidEditEngine();
     441           0 :             sal_uLong nLines = CalcLineCount( *pStream );
     442             :             // nLines*4: ReadText/Formatting/Highlighting/Formatting
     443           0 :             GetEditorWindow().CreateProgress( IDEResId(RID_STR_GENERATESOURCE).toString(), nLines*4 );
     444           0 :             GetEditEngine()->SetUpdateMode( false );
     445           0 :             GetEditView()->Read( *pStream );
     446           0 :             GetEditEngine()->SetUpdateMode( true );
     447           0 :             GetEditorWindow().Update();
     448           0 :             GetEditorWindow().ForceSyntaxTimeout();
     449           0 :             GetEditorWindow().DestroyProgress();
     450           0 :             sal_uLong nError = aMedium.GetError();
     451           0 :             if ( nError )
     452           0 :                 ErrorHandler::HandleError( nError );
     453             :             else
     454           0 :                 bDone = true;
     455             :         }
     456             :         else
     457           0 :             ErrorBox( this, WB_OK | WB_DEF_OK, IDE_RESSTR(RID_STR_COULDNTREAD) ).Execute();
     458             :     }
     459           0 :     return bDone;
     460             : }
     461             : 
     462             : 
     463           0 : bool ModulWindow::SaveBasicSource()
     464             : {
     465           0 :     bool bDone = false;
     466             : 
     467           0 :     Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
     468           0 :     Reference < XFilePicker3 > xFP = FilePicker::createWithMode(xContext, TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD);
     469             : 
     470           0 :     Reference< XFilePickerControlAccess > xFPControl(xFP, UNO_QUERY);
     471           0 :     xFPControl->enableControl(ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, false);
     472           0 :     Any aValue;
     473           0 :     aValue <<= sal_True;
     474           0 :     xFPControl->setValue(ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue);
     475             : 
     476           0 :     if ( !aCurPath.isEmpty() )
     477           0 :         xFP->setDisplayDirectory ( aCurPath );
     478             : 
     479           0 :     xFP->appendFilter( "BASIC", "*.bas" );
     480           0 :     xFP->appendFilter( IDE_RESSTR(RID_STR_FILTER_ALLFILES), OUString( FilterMask_All ) );
     481           0 :     xFP->setCurrentFilter( "BASIC" );
     482             : 
     483           0 :     if( xFP->execute() == RET_OK )
     484             :     {
     485           0 :         Sequence< OUString > aPaths = xFP->getFiles();
     486           0 :         aCurPath = aPaths[0];
     487           0 :         SfxMedium aMedium( aCurPath, STREAM_WRITE | STREAM_SHARE_DENYWRITE | STREAM_TRUNC );
     488           0 :         SvStream* pStream = aMedium.GetOutStream();
     489           0 :         if ( pStream )
     490             :         {
     491           0 :             EnterWait();
     492           0 :             AssertValidEditEngine();
     493           0 :             GetEditEngine()->Write( *pStream );
     494           0 :             aMedium.Commit();
     495           0 :             LeaveWait();
     496           0 :             sal_uLong nError = aMedium.GetError();
     497           0 :             if ( nError )
     498           0 :                 ErrorHandler::HandleError( nError );
     499             :             else
     500           0 :                 bDone = true;
     501             :         }
     502             :         else
     503           0 :             ErrorBox( this, WB_OK | WB_DEF_OK, IDEResId(RID_STR_COULDNTWRITE).toString() ).Execute();
     504             :     }
     505             : 
     506           0 :     return bDone;
     507             : }
     508             : 
     509             : extern bool implImportDialog( Window* pWin, const OUString& rCurPath, const ScriptDocument& rDocument, const OUString& aLibName ); // defined in baside3.cxx
     510             : 
     511           0 : bool ModulWindow::ImportDialog()
     512             : {
     513           0 :     const ScriptDocument& rDocument = GetDocument();
     514           0 :     OUString aLibName = GetLibName();
     515           0 :     return implImportDialog( this, aCurPath, rDocument, aLibName );
     516             : }
     517             : 
     518           0 : bool ModulWindow::ToggleBreakPoint( sal_uLong nLine )
     519             : {
     520             :     DBG_ASSERT( XModule().Is(), "Kein Modul!" );
     521             : 
     522           0 :     bool bNewBreakPoint = false;
     523             : 
     524           0 :     if ( XModule().Is() )
     525             :     {
     526           0 :         CheckCompileBasic();
     527           0 :         if ( aStatus.bError )
     528             :         {
     529           0 :             return false;
     530             :         }
     531             : 
     532           0 :         BreakPoint* pBrk = GetBreakPoints().FindBreakPoint( nLine );
     533           0 :         if ( pBrk ) // remove
     534             :         {
     535           0 :             xModule->ClearBP( (sal_uInt16)nLine );
     536           0 :             delete GetBreakPoints().remove( pBrk );
     537             :         }
     538             :         else // create one
     539             :         {
     540           0 :             if ( xModule->SetBP( (sal_uInt16)nLine) )
     541             :             {
     542           0 :                 GetBreakPoints().InsertSorted( new BreakPoint( nLine ) );
     543           0 :                 bNewBreakPoint = true;
     544           0 :                 if ( StarBASIC::IsRunning() )
     545             :                 {
     546           0 :                     for ( sal_uInt16 nMethod = 0; nMethod < xModule->GetMethods()->Count(); nMethod++ )
     547             :                     {
     548           0 :                         SbMethod* pMethod = (SbMethod*)xModule->GetMethods()->Get( nMethod );
     549             :                         DBG_ASSERT( pMethod, "Methode nicht gefunden! (NULL)" );
     550           0 :                         pMethod->SetDebugFlags( pMethod->GetDebugFlags() | SbDEBUG_BREAK );
     551             :                     }
     552             :                 }
     553             :             }
     554             :         }
     555             :     }
     556             : 
     557           0 :     return bNewBreakPoint;
     558             : }
     559             : 
     560           0 : void ModulWindow::UpdateBreakPoint( const BreakPoint& rBrk )
     561             : {
     562             :     DBG_ASSERT( XModule().Is(), "Kein Modul!" );
     563             : 
     564           0 :     if ( XModule().Is() )
     565             :     {
     566           0 :         CheckCompileBasic();
     567             : 
     568           0 :         if ( rBrk.bEnabled )
     569           0 :             xModule->SetBP( (sal_uInt16)rBrk.nLine );
     570             :         else
     571           0 :             xModule->ClearBP( (sal_uInt16)rBrk.nLine );
     572             :     }
     573           0 : }
     574             : 
     575             : 
     576           0 : bool ModulWindow::BasicToggleBreakPoint()
     577             : {
     578           0 :     AssertValidEditEngine();
     579             : 
     580           0 :     TextSelection aSel = GetEditView()->GetSelection();
     581           0 :     aSel.GetStart().GetPara()++;    // Basic lines start at 1!
     582           0 :     aSel.GetEnd().GetPara()++;
     583             : 
     584           0 :     bool bNewBreakPoint = false;
     585             : 
     586           0 :     for ( sal_uLong nLine = aSel.GetStart().GetPara(); nLine <= aSel.GetEnd().GetPara(); nLine++ )
     587             :     {
     588           0 :         if ( ToggleBreakPoint( nLine ) )
     589           0 :             bNewBreakPoint = true;
     590             :     }
     591             : 
     592           0 :     aXEditorWindow.GetBrkWindow().Invalidate();
     593           0 :     return bNewBreakPoint;
     594             : }
     595             : 
     596             : 
     597           0 : void ModulWindow::BasicToggleBreakPointEnabled()
     598             : {
     599           0 :     AssertValidEditEngine();
     600             : 
     601           0 :     ExtTextView* pView = GetEditView();
     602           0 :     if ( pView )
     603             :     {
     604           0 :         TextSelection aSel = pView->GetSelection();
     605           0 :         BreakPointList& rList = GetBreakPoints();
     606             : 
     607           0 :         for ( sal_uLong nLine = ++aSel.GetStart().GetPara(), nEnd = ++aSel.GetEnd().GetPara(); nLine <= nEnd; ++nLine )
     608             :         {
     609           0 :             BreakPoint* pBrk = rList.FindBreakPoint( nLine );
     610           0 :             if ( pBrk )
     611             :             {
     612           0 :                 pBrk->bEnabled = !pBrk->bEnabled;
     613           0 :                 UpdateBreakPoint( *pBrk );
     614             :             }
     615             :         }
     616             : 
     617           0 :         GetBreakPointWindow().Invalidate();
     618             :     }
     619           0 : }
     620             : 
     621             : 
     622           0 : void ModulWindow::ManageBreakPoints()
     623             : {
     624           0 :     BreakPointWindow& rBrkWin = GetBreakPointWindow();
     625           0 :     BreakPointDialog aBrkDlg( &rBrkWin, GetBreakPoints() );
     626           0 :     aBrkDlg.Execute();
     627           0 :     rBrkWin.Invalidate();
     628           0 : }
     629             : 
     630             : 
     631           0 : bool ModulWindow::BasicErrorHdl( StarBASIC * pBasic )
     632             : {
     633           0 :     GoOnTop();
     634             : 
     635             :     // ReturnWert: BOOL
     636             :     //  FALSE:  cancel
     637             :     //  TRUE:   go on....
     638           0 :     sal_uInt16 nErrorLine = pBasic->GetLine() - 1;
     639           0 :     sal_uInt16 nErrCol1 = pBasic->GetCol1();
     640           0 :     sal_uInt16 nErrCol2 = pBasic->GetCol2();
     641           0 :     if ( nErrCol2 != 0xFFFF )
     642           0 :         nErrCol2++;
     643             : 
     644           0 :     AssertValidEditEngine();
     645           0 :     GetEditView()->SetSelection( TextSelection( TextPaM( nErrorLine, nErrCol1 ), TextPaM( nErrorLine, nErrCol2 ) ) );
     646             : 
     647             :     // if other basic, the IDE should try to display the correct module
     648           0 :     bool const bMarkError = pBasic == GetBasic();
     649           0 :     if ( bMarkError )
     650           0 :         aXEditorWindow.GetBrkWindow().SetMarkerPos(nErrorLine, true);
     651             : 
     652             :     // #i47002#
     653           0 :     Reference< awt::XWindow > xWindow = VCLUnoHelper::GetInterface( this );
     654             : 
     655           0 :     ErrorHandler::HandleError( StarBASIC::GetErrorCode() );
     656             : 
     657             :     // #i47002#
     658           0 :     Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
     659           0 :     if ( !pWindow )
     660           0 :         return false;
     661             : 
     662           0 :     if ( bMarkError )
     663           0 :         aXEditorWindow.GetBrkWindow().SetNoMarker();
     664           0 :     return false;
     665             : }
     666             : 
     667           0 : long ModulWindow::BasicBreakHdl( StarBASIC* pBasic )
     668             : {
     669             :     // #i69280 Required in Window despite normal usage in next command!
     670             :     (void)pBasic;
     671             : 
     672             :     // Return value: sal_uInt16 => see SB-Debug-Flags
     673           0 :     sal_uInt16 nErrorLine = pBasic->GetLine();
     674             : 
     675             : 
     676           0 :     BreakPoint* pBrk = GetBreakPoints().FindBreakPoint( nErrorLine );
     677           0 :     if ( pBrk )
     678             :     {
     679           0 :         pBrk->nHitCount++;
     680           0 :         if ( pBrk->nHitCount <= pBrk->nStopAfter && GetBasic()->IsBreak() )
     681           0 :             return aStatus.nBasicFlags; // go on...
     682             :     }
     683             : 
     684           0 :     nErrorLine--;   // EditEngine starts at 0, Basic at 1
     685             : 
     686           0 :     AssertValidEditEngine();
     687           0 :     GetEditView()->SetSelection( TextSelection( TextPaM( nErrorLine, 0 ), TextPaM( nErrorLine, 0 ) ) );
     688           0 :     aXEditorWindow.GetBrkWindow().SetMarkerPos( nErrorLine );
     689             : 
     690           0 :     rLayout.UpdateDebug(false);
     691             : 
     692           0 :     aStatus.bIsInReschedule = true;
     693           0 :     aStatus.bIsRunning = true;
     694             : 
     695           0 :     AddStatus( BASWIN_INRESCHEDULE );
     696             : 
     697           0 :     InvalidateDebuggerSlots();
     698             : 
     699           0 :     while( aStatus.bIsRunning )
     700           0 :         Application::Yield();
     701             : 
     702           0 :     aStatus.bIsInReschedule = false;
     703           0 :     aXEditorWindow.GetBrkWindow().SetNoMarker();
     704             : 
     705           0 :     ClearStatus( BASWIN_INRESCHEDULE );
     706             : 
     707           0 :     return aStatus.nBasicFlags;
     708             : }
     709             : 
     710           0 : void ModulWindow::BasicAddWatch()
     711             : {
     712           0 :     AssertValidEditEngine();
     713           0 :     bool bAdd = true;
     714           0 :     if ( !GetEditView()->HasSelection() )
     715             :     {
     716           0 :         TextPaM aWordStart;
     717           0 :         OUString aWord = GetEditEngine()->GetWord( GetEditView()->GetSelection().GetEnd(), &aWordStart );
     718           0 :         if ( !aWord.isEmpty() )
     719             :         {
     720           0 :             TextSelection aSel( aWordStart );
     721           0 :             sal_uInt16& rIndex = aSel.GetEnd().GetIndex();
     722           0 :             rIndex = rIndex + aWord.getLength();
     723           0 :             GetEditView()->SetSelection( aSel );
     724           0 :             bAdd = true;
     725           0 :         }
     726             :     }
     727           0 :     if ( bAdd )
     728             :     {
     729           0 :         TextSelection aSel = GetEditView()->GetSelection();
     730           0 :         if ( aSel.GetStart().GetPara() == aSel.GetEnd().GetPara() ) // single line selection
     731           0 :             rLayout.BasicAddWatch(GetEditView()->GetSelected());
     732             :     }
     733           0 : }
     734             : 
     735             : 
     736             : 
     737           0 : void ModulWindow::EditMacro( const OUString& rMacroName )
     738             : {
     739             :     DBG_ASSERT( XModule().Is(), "Kein Modul!" );
     740             : 
     741           0 :     if ( XModule().Is() )
     742             :     {
     743           0 :         CheckCompileBasic();
     744             : 
     745           0 :         if ( !aStatus.bError )
     746             :         {
     747             :             sal_uInt16 nStart, nEnd;
     748           0 :             SbMethod* pMethod = (SbMethod*)xModule->Find( rMacroName, SbxCLASS_METHOD );
     749           0 :             if ( pMethod )
     750             :             {
     751           0 :                 pMethod->GetLineRange( nStart, nEnd );
     752           0 :                 if ( nStart )
     753             :                 {
     754           0 :                     nStart--;
     755           0 :                     nEnd--;
     756             :                 }
     757           0 :                 TextSelection aSel( TextPaM( nStart, 0 ), TextPaM( nStart, 0 ) );
     758           0 :                 AssertValidEditEngine();
     759           0 :                 TextView * pView = GetEditView();
     760             :                 // scroll if applicabel so that first line is at the top
     761           0 :                 long nVisHeight = GetOutputSizePixel().Height();
     762           0 :                 if ( (long)pView->GetTextEngine()->GetTextHeight() > nVisHeight )
     763             :                 {
     764           0 :                     long nMaxY = (long)pView->GetTextEngine()->GetTextHeight() - nVisHeight;
     765           0 :                     long nOldStartY = pView->GetStartDocPos().Y();
     766           0 :                     long nNewStartY = (long)nStart * (long)pView->GetTextEngine()->GetCharHeight();
     767           0 :                     nNewStartY = std::min( nNewStartY, nMaxY );
     768           0 :                     pView->Scroll( 0, -(nNewStartY-nOldStartY) );
     769           0 :                     pView->ShowCursor( false, true );
     770           0 :                     GetEditVScrollBar().SetThumbPos( pView->GetStartDocPos().Y() );
     771             :                 }
     772           0 :                 pView->SetSelection( aSel );
     773           0 :                 pView->ShowCursor();
     774           0 :                 pView->GetWindow()->GrabFocus();
     775             :             }
     776             :         }
     777             :     }
     778           0 : }
     779             : 
     780             : 
     781           0 : void ModulWindow::StoreData()
     782             : {
     783             :     // StoreData is called when the BasicManager is destroyed or
     784             :     // this window is closed.
     785             :     // => interrupts undesired!
     786           0 :     GetEditorWindow().SetSourceInBasic();
     787           0 : }
     788             : 
     789           0 : bool ModulWindow::CanClose()
     790             : {
     791           0 :     return true;
     792             : }
     793             : 
     794             : 
     795           0 : bool ModulWindow::AllowUndo()
     796             : {
     797           0 :     return GetEditorWindow().CanModify();
     798             : }
     799             : 
     800             : 
     801           0 : void ModulWindow::UpdateData()
     802             : {
     803             :     DBG_ASSERT( XModule().Is(), "Kein Modul!" );
     804             :     // UpdateData is called when the source has changed from outside
     805             :     // => interrupts undesired!
     806             : 
     807           0 :     if ( XModule().Is() )
     808             :     {
     809           0 :         SetModule( xModule->GetSource32() );
     810             : 
     811           0 :         if ( GetEditView() )
     812             :         {
     813           0 :             TextSelection aSel = GetEditView()->GetSelection();
     814           0 :             setTextEngineText(*GetEditEngine(), xModule->GetSource32());
     815           0 :             GetEditView()->SetSelection( aSel );
     816           0 :             GetEditEngine()->SetModified( false );
     817           0 :             MarkDocumentModified( GetDocument() );
     818             :         }
     819             :     }
     820           0 : }
     821             : 
     822           0 : sal_Int32 ModulWindow::countPages( Printer* pPrinter )
     823             : {
     824           0 :     return FormatAndPrint( pPrinter, -1 );
     825             : }
     826             : 
     827           0 : void ModulWindow::printPage( sal_Int32 nPage, Printer* pPrinter )
     828             : {
     829           0 :     FormatAndPrint( pPrinter, nPage );
     830           0 : }
     831             : 
     832             : /* implementation note: this is totally inefficient for the XRenderable interface
     833             :    usage since the whole "document" will be format for every page. Should this ever
     834             :    become a problem we should
     835             :    - format only once for every new printer
     836             :    - keep an index list for each page which is the starting paragraph
     837             : */
     838           0 : sal_Int32 ModulWindow::FormatAndPrint( Printer* pPrinter, sal_Int32 nPrintPage )
     839             : {
     840           0 :     AssertValidEditEngine();
     841             : 
     842           0 :     MapMode eOldMapMode( pPrinter->GetMapMode() );
     843           0 :     Font aOldFont( pPrinter->GetFont() );
     844             : 
     845           0 :     Font aFont( GetEditEngine()->GetFont() );
     846           0 :     aFont.SetAlign( ALIGN_BOTTOM );
     847           0 :     aFont.SetTransparent( true );
     848           0 :     aFont.SetSize( Size( 0, 360 ) );
     849           0 :     pPrinter->SetFont( aFont );
     850           0 :     pPrinter->SetMapMode( MAP_100TH_MM );
     851             : 
     852           0 :     OUString aTitle( CreateQualifiedName() );
     853             : 
     854           0 :     sal_Int32 nLineHeight = pPrinter->GetTextHeight();
     855           0 :     if(nLineHeight == 0)
     856             :     {
     857           0 :         nLineHeight = 1;
     858             :     }
     859           0 :     sal_Int32 nParaSpace = 10;
     860             : 
     861           0 :     Size aPaperSz = pPrinter->GetOutputSize();
     862           0 :     aPaperSz.Width() -= (Print::nLeftMargin + Print::nRightMargin);
     863           0 :     aPaperSz.Height() -= (Print::nTopMargin + Print::nBottomMargin);
     864             : 
     865             :     // nLinepPage is not correct if there's a line break
     866           0 :     sal_Int32 nLinespPage = aPaperSz.Height()/nLineHeight;
     867           0 :     long nXTextWidth = pPrinter->approximate_char_width();
     868             : 
     869           0 :     sal_Int32 nCharspLine = aPaperSz.Width() / (nXTextWidth > 1 ? nXTextWidth : 1);
     870           0 :     sal_uLong nParas = GetEditEngine()->GetParagraphCount();
     871             : 
     872           0 :     sal_Int32 nPages = nParas/nLinespPage+1;
     873           0 :     sal_Int32 nCurPage = 1;
     874             : 
     875           0 :     lcl_PrintHeader( pPrinter, nPages, nCurPage, aTitle, nPrintPage == 0 );
     876           0 :     Point aPos( Print::nLeftMargin, Print::nTopMargin );
     877           0 :     for ( sal_uLong nPara = 0; nPara < nParas; nPara++ )
     878             :     {
     879           0 :         OUString aLine( GetEditEngine()->GetText( nPara ) );
     880           0 :         lcl_ConvertTabsToSpaces( aLine );
     881           0 :         sal_Int32 nLines = aLine.getLength()/nCharspLine+1;
     882           0 :         for (sal_Int32 nLine = 0; nLine < nLines; ++nLine)
     883             :         {
     884           0 :             sal_Int32 nBeginIndex = nLine*nCharspLine;
     885           0 :             sal_Int32 nCopyCount = std::min<sal_Int32>(nCharspLine, aLine.getLength()-nBeginIndex);
     886           0 :             OUString aTmpLine = aLine.copy(nBeginIndex, nCopyCount);
     887           0 :             aPos.Y() += nLineHeight;
     888           0 :             if ( aPos.Y() > ( aPaperSz.Height() + Print::nTopMargin ) )
     889             :             {
     890           0 :                 nCurPage++;
     891           0 :                 lcl_PrintHeader( pPrinter, nPages, nCurPage, aTitle, nCurPage-1 == nPrintPage );
     892           0 :                 aPos = Point(Print::nLeftMargin, Print::nTopMargin + nLineHeight);
     893             :             }
     894           0 :             if( nCurPage-1 == nPrintPage )
     895           0 :                 pPrinter->DrawText( aPos, aTmpLine );
     896           0 :         }
     897           0 :         aPos.Y() += nParaSpace;
     898           0 :     }
     899             : 
     900           0 :     pPrinter->SetFont( aOldFont );
     901           0 :     pPrinter->SetMapMode( eOldMapMode );
     902             : 
     903           0 :     return nCurPage;
     904             : }
     905             : 
     906             : 
     907           0 : void ModulWindow::ExecuteCommand (SfxRequest& rReq)
     908             : {
     909           0 :     AssertValidEditEngine();
     910           0 :     switch (rReq.GetSlot())
     911             :     {
     912             :         case SID_DELETE:
     913             :         {
     914           0 :             KeyEvent aFakeDelete( 0, KEY_DELETE );
     915           0 :             bool bDone = GetEditView()->KeyInput( aFakeDelete );
     916           0 :             if (!bDone)
     917             :             {
     918           0 :                 BaseWindow::KeyInput(aFakeDelete);
     919             :             }
     920           0 :             break;
     921             :         }
     922             :         case SID_SELECTALL:
     923             :         {
     924           0 :             TextSelection aSel( TextPaM( 0, 0 ), TextPaM( TEXT_PARA_ALL, 0xFFFF ) );
     925           0 :             TextView * pView = GetEditView();
     926           0 :             pView->SetSelection( aSel );
     927           0 :             pView->GetWindow()->GrabFocus();
     928           0 :             break;
     929             :         }
     930             :         case SID_BASICRUN:
     931             :         {
     932           0 :             BasicRun();
     933             :         }
     934           0 :         break;
     935             :         case SID_BASICCOMPILE:
     936             :         {
     937           0 :             CompileBasic();
     938             :         }
     939           0 :         break;
     940             :         case SID_BASICSTEPOVER:
     941             :         {
     942           0 :             BasicStepOver();
     943             :         }
     944           0 :         break;
     945             :         case SID_BASICSTEPINTO:
     946             :         {
     947           0 :             BasicStepInto();
     948             :         }
     949           0 :         break;
     950             :         case SID_BASICSTEPOUT:
     951             :         {
     952           0 :             BasicStepOut();
     953             :         }
     954           0 :         break;
     955             :         case SID_BASICLOAD:
     956             :         {
     957           0 :             LoadBasic();
     958             :         }
     959           0 :         break;
     960             :         case SID_BASICSAVEAS:
     961             :         {
     962           0 :             SaveBasicSource();
     963             :         }
     964           0 :         break;
     965             :         case SID_IMPORT_DIALOG:
     966             :         {
     967           0 :             ImportDialog();
     968             :         }
     969           0 :         break;
     970             :         case SID_BASICIDE_MATCHGROUP:
     971             :         {
     972           0 :             GetEditView()->MatchGroup();
     973             :         }
     974           0 :         break;
     975             :         case SID_BASICIDE_TOGGLEBRKPNT:
     976             :         {
     977           0 :             BasicToggleBreakPoint();
     978             :         }
     979           0 :         break;
     980             :         case SID_BASICIDE_MANAGEBRKPNTS:
     981             :         {
     982           0 :             ManageBreakPoints();
     983             :         }
     984           0 :         break;
     985             :         case SID_BASICIDE_TOGGLEBRKPNTENABLED:
     986             :         {
     987           0 :             BasicToggleBreakPointEnabled();
     988             :         }
     989           0 :         break;
     990             :         case SID_BASICIDE_ADDWATCH:
     991             :         {
     992           0 :             BasicAddWatch();
     993             :         }
     994           0 :         break;
     995             :         case SID_BASICIDE_REMOVEWATCH:
     996             :         {
     997           0 :             rLayout.BasicRemoveWatch();
     998             :         }
     999           0 :         break;
    1000             :         case SID_CUT:
    1001             :         {
    1002           0 :             if ( !IsReadOnly() )
    1003             :             {
    1004           0 :                 GetEditView()->Cut();
    1005           0 :                 if (SfxBindings* pBindings = GetBindingsPtr())
    1006           0 :                     pBindings->Invalidate( SID_DOC_MODIFIED );
    1007             :             }
    1008             :         }
    1009           0 :         break;
    1010             :         case SID_COPY:
    1011             :         {
    1012           0 :             GetEditView()->Copy();
    1013             :         }
    1014           0 :         break;
    1015             :         case SID_PASTE:
    1016             :         {
    1017           0 :             if ( !IsReadOnly() )
    1018             :             {
    1019           0 :                 GetEditView()->Paste();
    1020           0 :                 if (SfxBindings* pBindings = GetBindingsPtr())
    1021           0 :                     pBindings->Invalidate( SID_DOC_MODIFIED );
    1022             :             }
    1023             :         }
    1024           0 :         break;
    1025             :         case SID_BASICIDE_BRKPNTSCHANGED:
    1026             :         {
    1027           0 :             GetBreakPointWindow().Invalidate();
    1028             :         }
    1029           0 :         break;
    1030             :         case SID_SHOWLINES:
    1031             :         {
    1032           0 :             SFX_REQUEST_ARG(rReq, pItem, SfxBoolItem, rReq.GetSlot(), false);
    1033           0 :             bSourceLinesEnabled = pItem && pItem->GetValue();
    1034           0 :             aXEditorWindow.SetLineNumberDisplay(bSourceLinesEnabled);
    1035             :         }
    1036           0 :         break;
    1037             :         case SID_BASICIDE_DELETECURRENT:
    1038             :         {
    1039           0 :             if (QueryDelModule(m_aName, this))
    1040           0 :                 if (m_aDocument.removeModule(m_aLibName, m_aName))
    1041           0 :                     MarkDocumentModified(m_aDocument);
    1042             :         }
    1043           0 :         break;
    1044             :         case FID_SEARCH_OFF:
    1045           0 :             GrabFocus();
    1046           0 :             break;
    1047             :         case SID_GOTOLINE:
    1048             :         {
    1049           0 :             GotoLineDialog aGotoDlg(this);
    1050           0 :             if (aGotoDlg.Execute())
    1051           0 :                 if (sal_Int32 const nLine = aGotoDlg.GetLineNumber())
    1052             :                 {
    1053           0 :                     TextSelection const aSel(TextPaM(nLine - 1, 0), TextPaM(nLine - 1, 0));
    1054           0 :                     GetEditView()->SetSelection(aSel);
    1055             :                 }
    1056           0 :             break;
    1057             :         }
    1058             :     }
    1059           0 : }
    1060             : 
    1061           0 : void ModulWindow::ExecuteGlobal (SfxRequest& rReq)
    1062             : {
    1063           0 :     switch (rReq.GetSlot())
    1064             :     {
    1065             :         case SID_SIGNATURE:
    1066             :         {
    1067           0 :             DocumentSignature aSignature(m_aDocument);
    1068           0 :             if (aSignature.supportsSignatures())
    1069             :             {
    1070           0 :                 aSignature.signScriptingContent();
    1071           0 :                 if (SfxBindings* pBindings = GetBindingsPtr())
    1072           0 :                     pBindings->Invalidate(SID_SIGNATURE);
    1073           0 :             }
    1074             :         }
    1075           0 :         break;
    1076             :     }
    1077           0 : }
    1078             : 
    1079             : 
    1080             : 
    1081           0 : void ModulWindow::GetState( SfxItemSet &rSet )
    1082             : {
    1083           0 :     SfxWhichIter aIter(rSet);
    1084           0 :     for ( sal_uInt16 nWh = aIter.FirstWhich(); 0 != nWh; nWh = aIter.NextWhich() )
    1085             :     {
    1086           0 :         switch ( nWh )
    1087             :         {
    1088             :             case SID_CUT:
    1089             :             {
    1090           0 :                 if ( !GetEditView() || !GetEditView()->HasSelection() )
    1091           0 :                     rSet.DisableItem( nWh );
    1092             : 
    1093           0 :                 if ( IsReadOnly() )
    1094           0 :                     rSet.DisableItem( nWh );
    1095             :             }
    1096           0 :             break;
    1097             :             case SID_COPY:
    1098             :             {
    1099           0 :                 if ( !GetEditView() || !GetEditView()->HasSelection() )
    1100           0 :                     rSet.DisableItem( nWh );
    1101             :             }
    1102           0 :             break;
    1103             :             case SID_PASTE:
    1104             :             {
    1105           0 :                 if ( !IsPasteAllowed() )
    1106           0 :                     rSet.DisableItem( nWh );
    1107             : 
    1108           0 :                 if ( IsReadOnly() )
    1109           0 :                     rSet.DisableItem( nWh );
    1110             :             }
    1111           0 :             break;
    1112             :             case SID_BASICIDE_STAT_POS:
    1113             :             {
    1114           0 :                 TextView* pView = GetEditView();
    1115           0 :                 if ( pView )
    1116             :                 {
    1117           0 :                     TextSelection aSel = pView->GetSelection();
    1118           0 :                     OUString aPos = OUString( IDEResId( RID_STR_LINE ) ) +
    1119           0 :                                    " " +
    1120           0 :                                    OUString::number(aSel.GetEnd().GetPara()+1) +
    1121           0 :                                    ", " +
    1122           0 :                                    OUString( IDEResId( RID_STR_COLUMN ) ) +
    1123           0 :                                    " " +
    1124           0 :                                    OUString::number(aSel.GetEnd().GetIndex()+1);
    1125           0 :                     SfxStringItem aItem( SID_BASICIDE_STAT_POS, aPos );
    1126           0 :                     rSet.Put( aItem );
    1127             :                 }
    1128             :             }
    1129           0 :             break;
    1130             :             case SID_ATTR_INSERT:
    1131             :             {
    1132           0 :                 TextView* pView = GetEditView();
    1133           0 :                 if ( pView )
    1134             :                 {
    1135           0 :                     SfxBoolItem aItem( SID_ATTR_INSERT, pView->IsInsertMode() );
    1136           0 :                     rSet.Put( aItem );
    1137             :                 }
    1138             :             }
    1139           0 :             break;
    1140             :             case SID_SHOWLINES:
    1141             :             {
    1142           0 :                 rSet.Put(SfxBoolItem(nWh, bSourceLinesEnabled));
    1143           0 :                 break;
    1144             :             }
    1145             :             case SID_SELECTALL:
    1146             :             {
    1147           0 :                 if ( !GetEditView() )
    1148           0 :                     rSet.DisableItem( nWh );
    1149             :             }
    1150           0 :             break;
    1151             :         }
    1152           0 :     }
    1153           0 : }
    1154             : 
    1155             : 
    1156           0 : void ModulWindow::DoScroll( ScrollBar* pCurScrollBar )
    1157             : {
    1158           0 :     if ( ( pCurScrollBar == GetHScrollBar() ) && GetEditView() )
    1159             :     {
    1160             :         // don't scroll with the value but rather use the Thumb-Pos for the VisArea:
    1161           0 :         long nDiff = GetEditView()->GetStartDocPos().X() - pCurScrollBar->GetThumbPos();
    1162           0 :         GetEditView()->Scroll( nDiff, 0 );
    1163           0 :         GetEditView()->ShowCursor( false, true );
    1164           0 :         pCurScrollBar->SetThumbPos( GetEditView()->GetStartDocPos().X() );
    1165             : 
    1166             :     }
    1167           0 : }
    1168             : 
    1169             : 
    1170           0 : bool ModulWindow::IsModified()
    1171             : {
    1172           0 :     return GetEditEngine() && GetEditEngine()->IsModified();
    1173             : }
    1174             : 
    1175             : 
    1176             : 
    1177           0 : void ModulWindow::GoOnTop()
    1178             : {
    1179           0 :     GetShell()->GetViewFrame()->ToTop();
    1180           0 : }
    1181             : 
    1182           0 : OUString ModulWindow::GetSbModuleName()
    1183             : {
    1184           0 :     OUString aModuleName;
    1185           0 :     if ( XModule().Is() )
    1186           0 :         aModuleName = xModule->GetName();
    1187           0 :     return aModuleName;
    1188             : }
    1189             : 
    1190           0 : OUString ModulWindow::GetTitle()
    1191             : {
    1192           0 :     return GetSbModuleName();
    1193             : }
    1194             : 
    1195           0 : void ModulWindow::FrameWindowMoved()
    1196             : {
    1197           0 : }
    1198             : 
    1199             : 
    1200             : 
    1201           0 : void ModulWindow::ShowCursor( bool bOn )
    1202             : {
    1203           0 :     if ( GetEditEngine() )
    1204             :     {
    1205           0 :         TextView* pView = GetEditEngine()->GetActiveView();
    1206           0 :         if ( pView )
    1207             :         {
    1208           0 :             if ( bOn )
    1209           0 :                 pView->ShowCursor();
    1210             :             else
    1211           0 :                 pView->HideCursor();
    1212             :         }
    1213             :     }
    1214           0 : }
    1215             : 
    1216             : 
    1217           0 : void ModulWindow::AssertValidEditEngine()
    1218             : {
    1219           0 :     if ( !GetEditEngine() )
    1220           0 :         GetEditorWindow().CreateEditEngine();
    1221           0 : }
    1222             : 
    1223           0 : void ModulWindow::Activating ()
    1224             : {
    1225           0 :     aXEditorWindow.SetLineNumberDisplay(bSourceLinesEnabled);
    1226           0 :     Show();
    1227           0 : }
    1228             : 
    1229           0 : void ModulWindow::Deactivating()
    1230             : {
    1231           0 :     Hide();
    1232           0 :     if ( GetEditView() )
    1233           0 :         GetEditView()->EraseVirtualDevice();
    1234           0 : }
    1235             : 
    1236           0 : sal_uInt16 ModulWindow::StartSearchAndReplace( const SvxSearchItem& rSearchItem, bool bFromStart )
    1237             : {
    1238           0 :     if (IsSuspended())
    1239           0 :         return 0;
    1240             : 
    1241             :     // one could also relinquish syntaxhighlighting/formatting instead of the stupid replace-everything...
    1242           0 :     AssertValidEditEngine();
    1243           0 :     ExtTextView* pView = GetEditView();
    1244           0 :     TextSelection aSel;
    1245           0 :     if ( bFromStart )
    1246             :     {
    1247           0 :         aSel = pView->GetSelection();
    1248           0 :         if ( !rSearchItem.GetBackward() )
    1249           0 :             pView->SetSelection( TextSelection() );
    1250             :         else
    1251           0 :             pView->SetSelection( TextSelection( TextPaM( 0xFFFFFFFF, 0xFFFF ), TextPaM( 0xFFFFFFFF, 0xFFFF ) ) );
    1252             :     }
    1253             : 
    1254           0 :     bool const bForward = !rSearchItem.GetBackward();
    1255           0 :     sal_uInt16 nFound = 0;
    1256           0 :     if ( ( rSearchItem.GetCommand() == SVX_SEARCHCMD_FIND ) ||
    1257           0 :          ( rSearchItem.GetCommand() == SVX_SEARCHCMD_FIND_ALL ) )
    1258             :     {
    1259           0 :         nFound = pView->Search( rSearchItem.GetSearchOptions() , bForward ) ? 1 : 0;
    1260             :     }
    1261           0 :     else if ( ( rSearchItem.GetCommand() == SVX_SEARCHCMD_REPLACE ) ||
    1262           0 :               ( rSearchItem.GetCommand() == SVX_SEARCHCMD_REPLACE_ALL ) )
    1263             :     {
    1264           0 :         if ( !IsReadOnly() )
    1265             :         {
    1266           0 :             bool const bAll = rSearchItem.GetCommand() == SVX_SEARCHCMD_REPLACE_ALL;
    1267           0 :             nFound = pView->Replace( rSearchItem.GetSearchOptions() , bAll , bForward );
    1268             :         }
    1269             :     }
    1270             : 
    1271           0 :     if ( bFromStart && !nFound )
    1272           0 :         pView->SetSelection( aSel );
    1273             : 
    1274           0 :     return nFound;
    1275             : }
    1276             : 
    1277           0 : ::svl::IUndoManager* ModulWindow::GetUndoManager()
    1278             : {
    1279           0 :     if ( GetEditEngine() )
    1280           0 :         return &GetEditEngine()->GetUndoManager();
    1281           0 :     return NULL;
    1282             : }
    1283             : 
    1284           0 : sal_uInt16 ModulWindow::GetSearchOptions()
    1285             : {
    1286             :     sal_uInt16 nOptions = SEARCH_OPTIONS_SEARCH |
    1287             :                       SEARCH_OPTIONS_WHOLE_WORDS |
    1288             :                       SEARCH_OPTIONS_BACKWARDS |
    1289             :                       SEARCH_OPTIONS_REG_EXP |
    1290             :                       SEARCH_OPTIONS_EXACT |
    1291             :                       SEARCH_OPTIONS_SELECTION |
    1292           0 :                       SEARCH_OPTIONS_SIMILARITY;
    1293             : 
    1294           0 :     if ( !IsReadOnly() )
    1295             :     {
    1296           0 :         nOptions |= SEARCH_OPTIONS_REPLACE;
    1297           0 :         nOptions |= SEARCH_OPTIONS_REPLACE_ALL;
    1298             :     }
    1299             : 
    1300           0 :     return nOptions;
    1301             : }
    1302             : 
    1303           0 : void ModulWindow::BasicStarted()
    1304             : {
    1305           0 :     if ( XModule().Is() )
    1306             :     {
    1307           0 :         aStatus.bIsRunning = true;
    1308           0 :         BreakPointList& rList = GetBreakPoints();
    1309           0 :         if ( rList.size() )
    1310             :         {
    1311           0 :             rList.ResetHitCount();
    1312           0 :             rList.SetBreakPointsInBasic( xModule );
    1313           0 :             for ( sal_uInt16 nMethod = 0; nMethod < xModule->GetMethods()->Count(); nMethod++ )
    1314             :             {
    1315           0 :                 SbMethod* pMethod = (SbMethod*)xModule->GetMethods()->Get( nMethod );
    1316             :                 DBG_ASSERT( pMethod, "Methode nicht gefunden! (NULL)" );
    1317           0 :                 pMethod->SetDebugFlags( pMethod->GetDebugFlags() | SbDEBUG_BREAK );
    1318             :             }
    1319             :         }
    1320             :     }
    1321           0 : }
    1322             : 
    1323           0 : void ModulWindow::BasicStopped()
    1324             : {
    1325           0 :     aStatus.bIsRunning = false;
    1326           0 :     GetBreakPointWindow().SetNoMarker();
    1327           0 : }
    1328             : 
    1329           0 : EntryDescriptor ModulWindow::CreateEntryDescriptor()
    1330             : {
    1331           0 :     ScriptDocument aDocument( GetDocument() );
    1332           0 :     OUString aLibName( GetLibName() );
    1333           0 :     LibraryLocation eLocation = aDocument.getLibraryLocation( aLibName );
    1334           0 :     OUString aModName( GetName() );
    1335           0 :     OUString aLibSubName;
    1336           0 :     if( xBasic.Is() && aDocument.isInVBAMode() && XModule().Is() )
    1337             :     {
    1338           0 :         switch( xModule->GetModuleType() )
    1339             :         {
    1340             :             case script::ModuleType::DOCUMENT:
    1341             :             {
    1342           0 :                 aLibSubName = OUString( IDEResId( RID_STR_DOCUMENT_OBJECTS ) );
    1343           0 :                 uno::Reference< container::XNameContainer > xLib = aDocument.getOrCreateLibrary( E_SCRIPTS, aLibName );
    1344           0 :                 if( xLib.is() )
    1345             :                 {
    1346           0 :                     OUString sObjName;
    1347           0 :                     ModuleInfoHelper::getObjectName( xLib, aModName, sObjName );
    1348           0 :                     if( !sObjName.isEmpty() )
    1349             :                     {
    1350           0 :                         aModName += " (" + sObjName + ")";
    1351           0 :                     }
    1352             :                 }
    1353           0 :                 break;
    1354             :             }
    1355             :             case script::ModuleType::FORM:
    1356           0 :                 aLibSubName = OUString( IDEResId( RID_STR_USERFORMS ) );
    1357           0 :                 break;
    1358             :             case script::ModuleType::NORMAL:
    1359           0 :                 aLibSubName = OUString( IDEResId( RID_STR_NORMAL_MODULES ) );
    1360           0 :                 break;
    1361             :             case script::ModuleType::CLASS:
    1362           0 :                 aLibSubName = OUString( IDEResId( RID_STR_CLASS_MODULES ) );
    1363           0 :                 break;
    1364             :         }
    1365             :     }
    1366           0 :     return EntryDescriptor( aDocument, eLocation, aLibName, aLibSubName, aModName, OBJ_TYPE_MODULE );
    1367             : }
    1368             : 
    1369           0 : void ModulWindow::SetReadOnly (bool b)
    1370             : {
    1371           0 :     if ( GetEditView() )
    1372           0 :         GetEditView()->SetReadOnly( b );
    1373           0 : }
    1374             : 
    1375           0 : bool ModulWindow::IsReadOnly()
    1376             : {
    1377           0 :     return GetEditView() && GetEditView()->IsReadOnly();
    1378             : }
    1379             : 
    1380           0 : bool ModulWindow::IsPasteAllowed()
    1381             : {
    1382           0 :     bool bPaste = false;
    1383             : 
    1384             :     // get clipboard
    1385           0 :     Reference< datatransfer::clipboard::XClipboard > xClipboard = GetClipboard();
    1386           0 :     if ( xClipboard.is() )
    1387             :     {
    1388             :         // get clipboard content
    1389           0 :         const sal_uInt32 nRef = Application::ReleaseSolarMutex();
    1390           0 :         Reference< datatransfer::XTransferable > xTransf = xClipboard->getContents();
    1391           0 :         Application::AcquireSolarMutex( nRef );
    1392           0 :         if ( xTransf.is() )
    1393             :         {
    1394           0 :             datatransfer::DataFlavor aFlavor;
    1395           0 :             SotExchange::GetFormatDataFlavor( SOT_FORMAT_STRING, aFlavor );
    1396           0 :             if ( xTransf->isDataFlavorSupported( aFlavor ) )
    1397           0 :                 bPaste = true;
    1398           0 :         }
    1399             :     }
    1400             : 
    1401           0 :     return bPaste;
    1402             : }
    1403             : 
    1404           0 : void ModulWindow::OnNewDocument ()
    1405             : {
    1406           0 :     aXEditorWindow.SetLineNumberDisplay(bSourceLinesEnabled);
    1407           0 : }
    1408             : 
    1409           0 : char const* ModulWindow::GetHid () const
    1410             : {
    1411           0 :     return HID_BASICIDE_MODULWINDOW;
    1412             : }
    1413           0 : ItemType ModulWindow::GetType () const
    1414             : {
    1415           0 :     return TYPE_MODULE;
    1416             : }
    1417             : 
    1418           0 : bool ModulWindow::HasActiveEditor () const
    1419             : {
    1420           0 :     return !IsSuspended();
    1421             : }
    1422             : 
    1423             : 
    1424           0 : void ModulWindow::UpdateModule ()
    1425             : {
    1426           0 :     OUString const aModule = getTextEngineText(*GetEditEngine());
    1427             : 
    1428             :     // update module in basic
    1429             :     assert(xModule);
    1430             : 
    1431             :     // update module in module window
    1432           0 :     SetModule(aModule);
    1433             : 
    1434             :     // update module in library
    1435           0 :     OSL_VERIFY(m_aDocument.updateModule(m_aLibName, m_aName, aModule));
    1436             : 
    1437           0 :     GetEditEngine()->SetModified(false);
    1438           0 :     MarkDocumentModified(m_aDocument);
    1439           0 : }
    1440             : 
    1441             : 
    1442             : 
    1443             : // ModulWindowLayout
    1444             : 
    1445             : 
    1446             : 
    1447           0 : ModulWindowLayout::ModulWindowLayout (Window* pParent, ObjectCatalog& rObjectCatalog_) :
    1448             :     Layout(pParent),
    1449             :     pChild(0),
    1450             :     aWatchWindow(this),
    1451             :     aStackWindow(this),
    1452           0 :     rObjectCatalog(rObjectCatalog_)
    1453           0 : { }
    1454             : 
    1455           0 : void ModulWindowLayout::UpdateDebug (bool bBasicStopped)
    1456             : {
    1457           0 :     aWatchWindow.UpdateWatches(bBasicStopped);
    1458           0 :     aStackWindow.UpdateCalls();
    1459           0 : }
    1460             : 
    1461           0 : void ModulWindowLayout::Paint (Rectangle const&)
    1462             : {
    1463           0 :     DrawText(Point(), IDEResId(RID_STR_NOMODULE).toString());
    1464           0 : }
    1465             : 
    1466             : // virtual
    1467           0 : void ModulWindowLayout::DataChanged (DataChangedEvent const& rDCEvt)
    1468             : {
    1469           0 :     Layout::DataChanged(rDCEvt);
    1470           0 :     if (rDCEvt.GetType() == DATACHANGED_SETTINGS && (rDCEvt.GetFlags() & SETTINGS_STYLE))
    1471           0 :         aSyntaxColors.SettingsChanged();
    1472           0 : }
    1473             : 
    1474             : 
    1475           0 : void ModulWindowLayout::Activating (BaseWindow& rChild)
    1476             : {
    1477             :     assert(dynamic_cast<ModulWindow*>(&rChild));
    1478           0 :     pChild = &static_cast<ModulWindow&>(rChild);
    1479           0 :     aWatchWindow.Show();
    1480           0 :     aStackWindow.Show();
    1481           0 :     rObjectCatalog.Show();
    1482           0 :     rObjectCatalog.SetLayoutWindow(this);
    1483           0 :     rObjectCatalog.UpdateEntries();
    1484           0 :     Layout::Activating(rChild);
    1485           0 :     aSyntaxColors.SetActiveEditor(&pChild->GetEditorWindow());
    1486           0 : }
    1487             : 
    1488           0 : void ModulWindowLayout::Deactivating ()
    1489             : {
    1490           0 :     aSyntaxColors.SetActiveEditor(0);
    1491           0 :     Layout::Deactivating();
    1492           0 :     aWatchWindow.Hide();
    1493           0 :     aStackWindow.Hide();
    1494           0 :     rObjectCatalog.Hide();
    1495           0 :     pChild = 0;
    1496           0 : }
    1497             : 
    1498           0 : void ModulWindowLayout::GetState (SfxItemSet &rSet, unsigned nWhich)
    1499             : {
    1500           0 :     switch (nWhich)
    1501             :     {
    1502             :         case SID_SHOW_PROPERTYBROWSER:
    1503           0 :             rSet.Put(SfxVisibilityItem(nWhich, false));
    1504           0 :             break;
    1505             : 
    1506             :         case SID_BASICIDE_CHOOSEMACRO:
    1507           0 :             rSet.Put(SfxVisibilityItem(nWhich, true));
    1508           0 :             break;
    1509             :     }
    1510           0 : }
    1511             : 
    1512           0 : void ModulWindowLayout::BasicAddWatch (OUString const& rWatchStr)
    1513             : {
    1514           0 :     aWatchWindow.AddWatch(rWatchStr);
    1515           0 : }
    1516             : 
    1517           0 : void ModulWindowLayout::BasicRemoveWatch ()
    1518             : {
    1519           0 :     aWatchWindow.RemoveSelectedWatch();
    1520           0 : }
    1521             : 
    1522           0 : void ModulWindowLayout::OnFirstSize (long const nWidth, long const nHeight)
    1523             : {
    1524           0 :     AddToLeft(&rObjectCatalog, Size(nWidth * 0.20, nHeight * 0.75));
    1525           0 :     AddToBottom(&aWatchWindow, Size(nWidth * 0.67, nHeight * 0.25));
    1526           0 :     AddToBottom(&aStackWindow, Size(nWidth * 0.33, nHeight * 0.25));
    1527           0 : }
    1528             : 
    1529             : 
    1530             : 
    1531             : // SyntaxColors
    1532             : 
    1533             : 
    1534             : 
    1535           0 : ModulWindowLayout::SyntaxColors::SyntaxColors () :
    1536           0 :     pEditor(0)
    1537             : {
    1538           0 :     aConfig.AddListener(this);
    1539             : 
    1540             :     aColors[TT_UNKNOWN] =
    1541             :     aColors[TT_WHITESPACE] =
    1542             :     aColors[TT_EOL] =
    1543           0 :         Application::GetSettings().GetStyleSettings().GetFieldTextColor();
    1544             : 
    1545           0 :     NewConfig(true);
    1546           0 : }
    1547             : 
    1548           0 : ModulWindowLayout::SyntaxColors::~SyntaxColors ()
    1549             : {
    1550           0 :     aConfig.RemoveListener(this);
    1551           0 : }
    1552             : 
    1553           0 : void ModulWindowLayout::SyntaxColors::SettingsChanged ()
    1554             : {
    1555           0 :     Color const aColor = Application::GetSettings().GetStyleSettings().GetFieldTextColor();
    1556           0 :     if (aColor != aColors[TT_UNKNOWN])
    1557             :     {
    1558             :         aColors[TT_UNKNOWN] =
    1559             :         aColors[TT_WHITESPACE] =
    1560             :         aColors[TT_EOL] =
    1561           0 :             aColor;
    1562           0 :         if (pEditor)
    1563           0 :             pEditor->UpdateSyntaxHighlighting();
    1564             :     }
    1565           0 : }
    1566             : 
    1567             : // virtual
    1568           0 : void ModulWindowLayout::SyntaxColors::ConfigurationChanged (utl::ConfigurationBroadcaster*, sal_uInt32)
    1569             : {
    1570           0 :     NewConfig(false);
    1571           0 : }
    1572             : 
    1573             : // when a new configuration has to be set
    1574           0 : void ModulWindowLayout::SyntaxColors::NewConfig (bool bFirst)
    1575             : {
    1576             :     static struct
    1577             :     {
    1578             :         TokenTypes eTokenType;
    1579             :         svtools::ColorConfigEntry eEntry;
    1580             :     }
    1581             :     const vIds[] =
    1582             :     {
    1583             :         { TT_IDENTIFIER,  svtools::BASICIDENTIFIER },
    1584             :         { TT_NUMBER,      svtools::BASICNUMBER },
    1585             :         { TT_STRING,      svtools::BASICSTRING },
    1586             :         { TT_COMMENT,     svtools::BASICCOMMENT },
    1587             :         { TT_ERROR,       svtools::BASICERROR },
    1588             :         { TT_OPERATOR,    svtools::BASICOPERATOR },
    1589             :         { TT_KEYWORDS,    svtools::BASICKEYWORD },
    1590             :     };
    1591             : 
    1592           0 :     bool bChanged = false;
    1593           0 :     for (unsigned i = 0; i != sizeof vIds / sizeof vIds[0]; ++i)
    1594             :     {
    1595           0 :         Color const aColor = aConfig.GetColorValue(vIds[i].eEntry).nColor;
    1596           0 :         Color& rMyColor = aColors[vIds[i].eTokenType];
    1597           0 :         if (bFirst || aColor != rMyColor)
    1598             :         {
    1599           0 :             rMyColor = aColor;
    1600           0 :             bChanged = true;
    1601             :         }
    1602             :     }
    1603           0 :     if (bChanged && !bFirst && pEditor)
    1604           0 :         pEditor->UpdateSyntaxHighlighting();
    1605           0 : }
    1606             : 
    1607             : 
    1608           0 : } // namespace basctl
    1609             : 
    1610             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10