LCOV - code coverage report
Current view: top level - basctl/source/basicide - basides1.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 663 0.0 %
Date: 2014-04-11 Functions: 0 17 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 "basidesh.hrc"
      21             : #include "helpid.hrc"
      22             : 
      23             : #include "baside2.hxx"
      24             : #include "baside3.hxx"
      25             : #include "basobj.hxx"
      26             : #include "docsignature.hxx"
      27             : #include "iderdll.hxx"
      28             : #include "iderdll2.hxx"
      29             : #include "localizationmgr.hxx"
      30             : #include "managelang.hxx"
      31             : 
      32             : #include <basic/basmgr.hxx>
      33             : #include <basic/sbmeth.hxx>
      34             : #include <boost/scoped_ptr.hpp>
      35             : #include <com/sun/star/frame/XLayoutManager.hpp>
      36             : #include <com/sun/star/script/XLibraryContainerPassword.hpp>
      37             : #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
      38             : #include <sfx2/childwin.hxx>
      39             : #include <sfx2/docfac.hxx>
      40             : #include <sfx2/dinfdlg.hxx>
      41             : #include <sfx2/dispatch.hxx>
      42             : #include <sfx2/minfitem.hxx>
      43             : #include <sfx2/objface.hxx>
      44             : #include <sfx2/printer.hxx>
      45             : #include <sfx2/request.hxx>
      46             : #include <svl/aeitem.hxx>
      47             : #include <svl/intitem.hxx>
      48             : #include <svl/srchitem.hxx>
      49             : #include <svl/visitem.hxx>
      50             : #include <svl/whiter.hxx>
      51             : #include <vcl/xtextedt.hxx>
      52             : #include <vcl/msgbox.hxx>
      53             : 
      54             : namespace basctl
      55             : {
      56             : 
      57             : using namespace ::com::sun::star;
      58             : using namespace ::com::sun::star::uno;
      59             : using namespace ::com::sun::star::frame;
      60             : 
      61           0 : void Shell::ExecuteCurrent( SfxRequest& rReq )
      62             : {
      63           0 :     if ( !pCurWin )
      64           0 :         return;
      65             : 
      66           0 :     switch ( rReq.GetSlot() )
      67             :     {
      68             :         case SID_BASICIDE_HIDECURPAGE:
      69             :         {
      70           0 :             pCurWin->StoreData();
      71           0 :             RemoveWindow( pCurWin, false );
      72             :         }
      73           0 :         break;
      74             :         case SID_BASICIDE_RENAMECURRENT:
      75             :         {
      76           0 :             pTabBar->StartEditMode( pTabBar->GetCurPageId() );
      77             :         }
      78           0 :         break;
      79             :         case FID_SEARCH_NOW:
      80             :         {
      81           0 :             if (!pCurWin->HasActiveEditor())
      82           0 :                 break;
      83             :             DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
      84           0 :             SfxItemSet const& rArgs = *rReq.GetArgs();
      85             :             // unfortunately I don't know the ID:
      86           0 :             sal_uInt16 nWhich = rArgs.GetWhichByPos( 0 );
      87             :             DBG_ASSERT( nWhich, "Wich fuer SearchItem ?" );
      88           0 :             SfxPoolItem const& rItem = rArgs.Get(nWhich);
      89             :             DBG_ASSERT(dynamic_cast<SvxSearchItem const*>(&rItem), "no searchitem!");
      90           0 :             SvxSearchItem const& rSearchItem = static_cast<SvxSearchItem const&>(rItem);
      91             :             // memorize item because of the adjustments...
      92           0 :             GetExtraData()->SetSearchItem(rSearchItem);
      93           0 :             sal_Int32 nFound = 0;
      94           0 :             bool bCanceled = false;
      95           0 :             if (rSearchItem.GetCommand() == SVX_SEARCHCMD_REPLACE_ALL)
      96             :             {
      97           0 :                 sal_uInt16 nActModWindows = 0;
      98           0 :                 for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
      99             :                 {
     100           0 :                     BaseWindow* pWin = it->second;
     101           0 :                     if (pWin->HasActiveEditor())
     102           0 :                         nActModWindows++;
     103             :                 }
     104             : 
     105           0 :                 if ( nActModWindows <= 1 || ( !rSearchItem.GetSelection() && QueryBox( pCurWin, WB_YES_NO|WB_DEF_YES, IDEResId(RID_STR_SEARCHALLMODULES).toString() ).Execute() == RET_YES ) )
     106             :                 {
     107           0 :                     for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
     108             :                     {
     109           0 :                         BaseWindow* pWin = it->second;
     110           0 :                         nFound += pWin->StartSearchAndReplace(rSearchItem);
     111             :                     }
     112             :                 }
     113             :                 else
     114           0 :                     nFound = pCurWin->StartSearchAndReplace(rSearchItem);
     115             : 
     116           0 :                 OUString aReplStr(IDE_RESSTR(RID_STR_SEARCHREPLACES));
     117           0 :                 aReplStr = aReplStr.replaceAll("XX", OUString::number(nFound));
     118           0 :                 InfoBox( pCurWin, aReplStr ).Execute();
     119             :             }
     120             :             else
     121             :             {
     122           0 :                 nFound = pCurWin->StartSearchAndReplace(rSearchItem);
     123           0 :                 if ( !nFound && !rSearchItem.GetSelection() )
     124             :                 {
     125             :                     // search other modules...
     126           0 :                     bool bChangeCurWindow = false;
     127           0 :                     WindowTableIt it;
     128           0 :                     for (it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
     129           0 :                         if (it->second == pCurWin)
     130           0 :                             break;
     131           0 :                     if (it != aWindowTable.end())
     132           0 :                         ++it;
     133           0 :                     BaseWindow* pWin = it != aWindowTable.end() ? it->second : 0;
     134             : 
     135           0 :                     bool bSearchedFromStart = false;
     136           0 :                     while ( !nFound && !bCanceled && ( pWin || !bSearchedFromStart ) )
     137             :                     {
     138           0 :                         if ( !pWin )
     139             :                         {
     140           0 :                             SfxViewFrame* pViewFrame = GetViewFrame();
     141           0 :                             SfxChildWindow* pChildWin = pViewFrame ? pViewFrame->GetChildWindow( SID_SEARCH_DLG ) : NULL;
     142           0 :                             Window* pParent = pChildWin ? pChildWin->GetWindow() : NULL;
     143           0 :                             QueryBox aQuery(pParent, WB_YES_NO|WB_DEF_YES, IDE_RESSTR(RID_STR_SEARCHFROMSTART));
     144           0 :                             if ( aQuery.Execute() == RET_YES )
     145             :                             {
     146           0 :                                 it = aWindowTable.begin();
     147           0 :                                 if ( it != aWindowTable.end() )
     148           0 :                                     pWin = it->second;
     149           0 :                                 bSearchedFromStart = true;
     150             :                             }
     151             :                             else
     152           0 :                                 bCanceled = true;
     153             :                         }
     154             : 
     155           0 :                         if (pWin && pWin->HasActiveEditor())
     156             :                         {
     157           0 :                             if ( pWin != pCurWin )
     158             :                             {
     159           0 :                                 if ( pCurWin )
     160           0 :                                     pWin->SetSizePixel( pCurWin->GetSizePixel() );
     161           0 :                                 nFound = pWin->StartSearchAndReplace(rSearchItem, true);
     162             :                             }
     163           0 :                             if ( nFound )
     164             :                             {
     165           0 :                                 bChangeCurWindow = true;
     166           0 :                                 break;
     167             :                             }
     168             :                         }
     169           0 :                         if ( pWin && ( pWin != pCurWin ) )
     170             :                         {
     171           0 :                             if ( it != aWindowTable.end() )
     172           0 :                                 ++it;
     173           0 :                             pWin = it != aWindowTable.end() ? it->second : 0;
     174             :                         }
     175             :                         else
     176           0 :                             pWin = 0;
     177             :                     }
     178           0 :                     if ( !nFound && bSearchedFromStart )
     179           0 :                         nFound = pCurWin->StartSearchAndReplace(rSearchItem, true);
     180           0 :                     if ( bChangeCurWindow )
     181           0 :                         SetCurWindow( pWin, true );
     182             :                 }
     183           0 :                 if ( !nFound && !bCanceled )
     184           0 :                     InfoBox( pCurWin, IDEResId(RID_STR_SEARCHNOTFOUND).toString() ).Execute();
     185             :             }
     186             : 
     187           0 :             rReq.Done();
     188             :         }
     189           0 :         break;
     190             :         case SID_UNDO:
     191             :         case SID_REDO:
     192           0 :             if ( GetUndoManager() && pCurWin->AllowUndo() )
     193           0 :                 GetViewFrame()->ExecuteSlot( rReq );
     194           0 :             break;
     195             :         default:
     196           0 :             pCurWin->ExecuteCommand( rReq );
     197             :     }
     198             : }
     199             : 
     200             : //  no matter who's at the top, influence on the shell:
     201           0 : void Shell::ExecuteGlobal( SfxRequest& rReq )
     202             : {
     203           0 :     sal_uInt16 nSlot = rReq.GetSlot();
     204           0 :     switch ( nSlot )
     205             :     {
     206             :         case SID_BASICSTOP:
     207             :         {
     208             :             // maybe do not simply stop if on breakpoint!
     209           0 :             if (ModulWindow* pMCurWin = dynamic_cast<ModulWindow*>(pCurWin))
     210           0 :                 pMCurWin->BasicStop();
     211           0 :             StopBasic();
     212             :         }
     213           0 :         break;
     214             : 
     215             :         case SID_SAVEDOC:
     216             :         {
     217           0 :             if ( pCurWin )
     218             :             {
     219             :                 // rewrite date into the BASIC
     220           0 :                 StoreAllWindowData();
     221             : 
     222             :                 // document basic
     223           0 :                 ScriptDocument aDocument( pCurWin->GetDocument() );
     224           0 :                 if ( aDocument.isDocument() )
     225             :                 {
     226           0 :                     uno::Reference< task::XStatusIndicator > xStatusIndicator;
     227             : 
     228           0 :                     SFX_REQUEST_ARG( rReq, pStatusIndicatorItem, SfxUnoAnyItem,
     229             :                         SID_PROGRESS_STATUSBAR_CONTROL, false );
     230           0 :                     if ( pStatusIndicatorItem )
     231           0 :                         OSL_VERIFY( pStatusIndicatorItem->GetValue() >>= xStatusIndicator );
     232             :                     else
     233             :                     {
     234             :                         // get statusindicator
     235           0 :                         SfxViewFrame *pFrame_ = GetFrame();
     236           0 :                         if ( pFrame_ )
     237             :                         {
     238             :                             uno::Reference< task::XStatusIndicatorFactory > xStatFactory(
     239           0 :                                                                         pFrame_->GetFrame().GetFrameInterface(),
     240           0 :                                                                         uno::UNO_QUERY );
     241           0 :                             if( xStatFactory.is() )
     242           0 :                                 xStatusIndicator = xStatFactory->createStatusIndicator();
     243             :                         }
     244             : 
     245           0 :                         if ( xStatusIndicator.is() )
     246           0 :                             rReq.AppendItem( SfxUnoAnyItem( SID_PROGRESS_STATUSBAR_CONTROL, uno::makeAny( xStatusIndicator ) ) );
     247             :                     }
     248             : 
     249           0 :                     aDocument.saveDocument( xStatusIndicator );
     250             :                 }
     251             : 
     252           0 :                 if (SfxBindings* pBindings = GetBindingsPtr())
     253             :                 {
     254           0 :                     pBindings->Invalidate( SID_DOC_MODIFIED );
     255           0 :                     pBindings->Invalidate( SID_SAVEDOC );
     256           0 :                     pBindings->Invalidate( SID_SIGNATURE );
     257           0 :                 }
     258             :             }
     259             :         }
     260           0 :         break;
     261             :         case SID_BASICIDE_MODULEDLG:
     262             :         {
     263           0 :             if ( rReq.GetArgs() )
     264             :             {
     265           0 :                 const SfxUInt16Item &rTabId = (const SfxUInt16Item&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_TABID );
     266           0 :                 Organize( rTabId.GetValue() );
     267             :             }
     268             :             else
     269           0 :                 Organize( 0 );
     270             :         }
     271           0 :         break;
     272             :         case SID_BASICIDE_CHOOSEMACRO:
     273             :         {
     274           0 :             ChooseMacro( NULL, false, OUString() );
     275             :         }
     276           0 :         break;
     277             :         case SID_BASICIDE_CREATEMACRO:
     278             :         case SID_BASICIDE_EDITMACRO:
     279             :         {
     280             :             DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
     281           0 :             const SfxMacroInfoItem& rInfo = (const SfxMacroInfoItem&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_MACROINFO );
     282           0 :             BasicManager* pBasMgr = (BasicManager*)rInfo.GetBasicManager();
     283             :             DBG_ASSERT( pBasMgr, "Nichts selektiert im Basic-Baum ?" );
     284             : 
     285           0 :             ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
     286             : 
     287           0 :             StartListening( *pBasMgr, true /* log on only once */ );
     288           0 :             OUString aLibName( rInfo.GetLib() );
     289           0 :             if ( aLibName.isEmpty() )
     290           0 :                 aLibName = "Standard" ;
     291           0 :             StarBASIC* pBasic = pBasMgr->GetLib( aLibName );
     292           0 :             if ( !pBasic )
     293             :             {
     294             :                 // load module and dialog library (if not loaded)
     295           0 :                 aDocument.loadLibraryIfExists( E_SCRIPTS, aLibName );
     296           0 :                 aDocument.loadLibraryIfExists( E_DIALOGS, aLibName );
     297             : 
     298             :                 // get Basic
     299           0 :                 pBasic = pBasMgr->GetLib( aLibName );
     300             :             }
     301             :             DBG_ASSERT( pBasic, "No Basic!" );
     302             : 
     303           0 :             SetCurLib( aDocument, aLibName );
     304             : 
     305           0 :             if ( pBasic && rReq.GetSlot() == SID_BASICIDE_CREATEMACRO )
     306             :             {
     307           0 :                 SbModule* pModule = pBasic->FindModule( rInfo.GetModule() );
     308           0 :                 if ( !pModule )
     309             :                 {
     310           0 :                     if ( !rInfo.GetModule().isEmpty() || !pBasic->GetModules()->Count() )
     311             :                     {
     312           0 :                         OUString aModName = rInfo.GetModule();
     313             : 
     314           0 :                         OUString sModuleCode;
     315           0 :                         if ( aDocument.createModule( aLibName, aModName, false, sModuleCode ) )
     316           0 :                             pModule = pBasic->FindModule( aModName );
     317             :                     }
     318             :                     else
     319           0 :                         pModule = (SbModule*) pBasic->GetModules()->Get(0);
     320             :                 }
     321             :                 DBG_ASSERT( pModule, "Kein Modul!" );
     322           0 :                 if ( pModule && !pModule->GetMethods()->Find( rInfo.GetMethod(), SbxCLASS_METHOD ) )
     323           0 :                     CreateMacro( pModule, rInfo.GetMethod() );
     324             :             }
     325           0 :             SfxViewFrame* pViewFrame = GetViewFrame();
     326           0 :             if ( pViewFrame )
     327           0 :                 pViewFrame->ToTop();
     328           0 :             ModulWindow* pWin = FindBasWin( aDocument, aLibName, rInfo.GetModule(), true );
     329             :             DBG_ASSERT( pWin, "Edit/Create Macro: Fenster wurde nicht erzeugt/gefunden!" );
     330           0 :             SetCurWindow( pWin, true );
     331           0 :             pWin->EditMacro( rInfo.GetMethod() );
     332             :         }
     333           0 :         break;
     334             : 
     335             :         case SID_BASICIDE_OBJCAT:
     336             :             // toggling object catalog
     337           0 :             aObjectCatalog.Show(!aObjectCatalog.IsVisible());
     338           0 :             if (pLayout)
     339           0 :                 pLayout->ArrangeWindows();
     340             :             // refresh the button state
     341           0 :             if (SfxBindings* pBindings = GetBindingsPtr())
     342           0 :                 pBindings->Invalidate(SID_BASICIDE_OBJCAT);
     343           0 :             break;
     344             : 
     345             :         case SID_BASICIDE_NAMECHANGEDONTAB:
     346             :         {
     347             :             DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
     348           0 :             const SfxUInt16Item &rTabId = (const SfxUInt16Item&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_TABID );
     349           0 :             const SfxStringItem &rModName = (const SfxStringItem&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_MODULENAME );
     350           0 :             if ( aWindowTable.find( rTabId.GetValue() ) !=  aWindowTable.end() )
     351             :             {
     352           0 :                 BaseWindow* pWin = aWindowTable[ rTabId.GetValue() ];
     353           0 :                 OUString aNewName( rModName.GetValue() );
     354           0 :                 OUString aOldName( pWin->GetName() );
     355           0 :                 if ( aNewName != aOldName )
     356             :                 {
     357           0 :                     bool bRenameOk = false;
     358           0 :                     if (ModulWindow* pModWin = dynamic_cast<ModulWindow*>(pWin))
     359             :                     {
     360           0 :                         OUString aLibName = pModWin->GetLibName();
     361           0 :                         ScriptDocument aDocument( pWin->GetDocument() );
     362             : 
     363           0 :                         if (RenameModule(pModWin, aDocument, aLibName, aOldName, aNewName))
     364             :                         {
     365           0 :                             bRenameOk = true;
     366             :                             // Because we listen for container events for script
     367             :                             // modules, rename will delete the 'old' window
     368             :                             // pWin has been invalidated, restore now
     369           0 :                             pWin = FindBasWin( aDocument, aLibName, aNewName, true );
     370           0 :                         }
     371             : 
     372             :                     }
     373           0 :                     else if (DialogWindow* pDlgWin = dynamic_cast<DialogWindow*>(pWin))
     374             :                     {
     375           0 :                         bRenameOk = pDlgWin->RenameDialog( aNewName );
     376             :                     }
     377           0 :                     if ( bRenameOk )
     378             :                     {
     379           0 :                         MarkDocumentModified( pWin->GetDocument() );
     380             :                     }
     381             :                     else
     382             :                     {
     383             :                         // set old name in TabWriter
     384           0 :                         sal_uInt16 nId = GetWindowId( pWin );
     385             :                         DBG_ASSERT( nId, "No entry in Tabbar!" );
     386           0 :                         if ( nId )
     387           0 :                             pTabBar->SetPageText( nId, aOldName );
     388             :                     }
     389             :                 }
     390             : 
     391             :                 // set focus to current window
     392           0 :                 pWin->GrabFocus();
     393             :             }
     394             :         }
     395           0 :         break;
     396             :         case SID_BASICIDE_STOREMODULESOURCE:
     397             :         case SID_BASICIDE_UPDATEMODULESOURCE:
     398             :         {
     399             :             DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
     400           0 :             const SfxMacroInfoItem& rInfo = (const SfxMacroInfoItem&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_MACROINFO );
     401           0 :             BasicManager* pBasMgr = (BasicManager*)rInfo.GetBasicManager();
     402             :             DBG_ASSERT( pBasMgr, "Store source: Kein BasMgr?" );
     403           0 :             ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
     404           0 :             ModulWindow* pWin = FindBasWin( aDocument, rInfo.GetLib(), rInfo.GetModule(), false, true );
     405           0 :             if ( pWin )
     406             :             {
     407           0 :                 if ( rReq.GetSlot() == SID_BASICIDE_STOREMODULESOURCE )
     408           0 :                     pWin->StoreData();
     409             :                 else
     410           0 :                     pWin->UpdateData();
     411           0 :             }
     412             :         }
     413           0 :         break;
     414             :         case SID_BASICIDE_STOREALLMODULESOURCES:
     415             :         case SID_BASICIDE_UPDATEALLMODULESOURCES:
     416             :         {
     417           0 :             for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
     418             :             {
     419           0 :                 BaseWindow* pWin = it->second;
     420           0 :                 if (!pWin->IsSuspended() && dynamic_cast<ModulWindow*>(pWin))
     421             :                 {
     422           0 :                     if ( rReq.GetSlot() == SID_BASICIDE_STOREALLMODULESOURCES )
     423           0 :                         pWin->StoreData();
     424             :                     else
     425           0 :                         pWin->UpdateData();
     426             :                 }
     427             :             }
     428             :         }
     429           0 :         break;
     430             :         case SID_BASICIDE_LIBSELECTED:
     431             :         case SID_BASICIDE_LIBREMOVED:
     432             :         case SID_BASICIDE_LIBLOADED:
     433             :         {
     434             :             DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
     435           0 :             const SfxUsrAnyItem& rShellItem = (const SfxUsrAnyItem&)rReq.GetArgs()->Get( SID_BASICIDE_ARG_DOCUMENT_MODEL );
     436           0 :             uno::Reference< frame::XModel > xModel( rShellItem.GetValue(), UNO_QUERY );
     437           0 :             ScriptDocument aDocument( xModel.is() ? ScriptDocument( xModel ) : ScriptDocument::getApplicationScriptDocument() );
     438           0 :             const SfxStringItem& rLibNameItem = (const SfxStringItem&)rReq.GetArgs()->Get( SID_BASICIDE_ARG_LIBNAME );
     439           0 :             OUString aLibName( rLibNameItem.GetValue() );
     440             : 
     441           0 :             if ( nSlot == SID_BASICIDE_LIBSELECTED )
     442             :             {
     443             :                 // load module and dialog library (if not loaded)
     444           0 :                 aDocument.loadLibraryIfExists( E_SCRIPTS, aLibName );
     445           0 :                 aDocument.loadLibraryIfExists( E_DIALOGS, aLibName );
     446             : 
     447             :                 // check password, if library is password protected and not verified
     448           0 :                 bool bOK = true;
     449           0 :                 Reference< script::XLibraryContainer > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ) );
     450           0 :                 if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) )
     451             :                 {
     452           0 :                     Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
     453           0 :                     if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aLibName ) && !xPasswd->isLibraryPasswordVerified( aLibName ) )
     454             :                     {
     455           0 :                         OUString aPassword;
     456           0 :                         bOK = QueryPassword( xModLibContainer, aLibName, aPassword );
     457           0 :                     }
     458             :                 }
     459             : 
     460           0 :                 if ( bOK )
     461             :                 {
     462           0 :                     SetCurLib( aDocument, aLibName, true, false );
     463             :                 }
     464             :                 else
     465             :                 {
     466             :                     // adjust old value...
     467           0 :                     if (SfxBindings* pBindings = GetBindingsPtr())
     468           0 :                         pBindings->Invalidate(SID_BASICIDE_LIBSELECTOR, true, false);
     469           0 :                 }
     470             :             }
     471           0 :             else if ( nSlot == SID_BASICIDE_LIBREMOVED )
     472             :             {
     473           0 :                 if ( m_aCurLibName.isEmpty() || ( aDocument == m_aCurDocument && aLibName == m_aCurLibName ) )
     474             :                 {
     475           0 :                     RemoveWindows( aDocument, aLibName, true );
     476           0 :                     if ( aDocument == m_aCurDocument && aLibName == m_aCurLibName )
     477             :                     {
     478           0 :                         m_aCurDocument = ScriptDocument::getApplicationScriptDocument();
     479           0 :                         m_aCurLibName = "";
     480             :                         // no UpdateWindows!
     481           0 :                         if (SfxBindings* pBindings = GetBindingsPtr())
     482           0 :                             pBindings->Invalidate( SID_BASICIDE_LIBSELECTOR );
     483             :                     }
     484             :                 }
     485             :             }
     486             :             else    // Loaded...
     487           0 :                 UpdateWindows();
     488             :         }
     489           0 :         break;
     490             :         case SID_BASICIDE_NEWMODULE:
     491             :         {
     492           0 :             ModulWindow* pWin = CreateBasWin( m_aCurDocument, m_aCurLibName, OUString() );
     493             :             DBG_ASSERT( pWin, "New Module: Konnte Fenster nicht erzeugen!" );
     494           0 :             SetCurWindow( pWin, true );
     495             :         }
     496           0 :         break;
     497             :         case SID_BASICIDE_NEWDIALOG:
     498             :         {
     499           0 :             DialogWindow* pWin = CreateDlgWin( m_aCurDocument, m_aCurLibName, OUString() );
     500             :             DBG_ASSERT( pWin, "New Module: Konnte Fenster nicht erzeugen!" );
     501           0 :             SetCurWindow( pWin, true );
     502             :         }
     503           0 :         break;
     504             :         case SID_BASICIDE_SBXRENAMED:
     505             :         {
     506             :             DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
     507             :         }
     508           0 :         break;
     509             :         case SID_BASICIDE_SBXINSERTED:
     510             :         {
     511             :             DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
     512           0 :             const SbxItem& rSbxItem = (const SbxItem&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_SBX );
     513           0 :             ScriptDocument aDocument( rSbxItem.GetDocument() );
     514           0 :             OUString aLibName( rSbxItem.GetLibName() );
     515           0 :             OUString aName( rSbxItem.GetName() );
     516           0 :             if ( m_aCurLibName.isEmpty() || ( aDocument == m_aCurDocument && aLibName == m_aCurLibName ) )
     517             :             {
     518           0 :                 if ( rSbxItem.GetType() == TYPE_MODULE )
     519           0 :                     FindBasWin( aDocument, aLibName, aName, true );
     520           0 :                 else if ( rSbxItem.GetType() == TYPE_DIALOG )
     521           0 :                     FindDlgWin( aDocument, aLibName, aName, true );
     522           0 :             }
     523             :         }
     524           0 :         break;
     525             :         case SID_BASICIDE_SBXDELETED:
     526             :         {
     527             :             DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
     528           0 :             const SbxItem& rSbxItem = (const SbxItem&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_SBX );
     529           0 :             ScriptDocument aDocument( rSbxItem.GetDocument() );
     530           0 :             BaseWindow* pWin = FindWindow( aDocument, rSbxItem.GetLibName(), rSbxItem.GetName(), rSbxItem.GetType(), true );
     531           0 :             if ( pWin )
     532           0 :                 RemoveWindow( pWin, true );
     533             :         }
     534           0 :         break;
     535             :         case SID_BASICIDE_SHOWSBX:
     536             :         {
     537             :             DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
     538           0 :             const SbxItem& rSbxItem = (const SbxItem&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_SBX );
     539           0 :             ScriptDocument aDocument( rSbxItem.GetDocument() );
     540           0 :             OUString aLibName( rSbxItem.GetLibName() );
     541           0 :             OUString aName( rSbxItem.GetName() );
     542           0 :             SetCurLib( aDocument, aLibName );
     543           0 :             BaseWindow* pWin = 0;
     544           0 :             if ( rSbxItem.GetType() == TYPE_DIALOG )
     545             :             {
     546           0 :                 pWin = FindDlgWin( aDocument, aLibName, aName, true );
     547             :             }
     548           0 :             else if ( rSbxItem.GetType() == TYPE_MODULE )
     549             :             {
     550           0 :                 pWin = FindBasWin( aDocument, aLibName, aName, true );
     551             :             }
     552           0 :             else if ( rSbxItem.GetType() == TYPE_METHOD )
     553             :             {
     554           0 :                 pWin = FindBasWin( aDocument, aLibName, aName, true );
     555           0 :                 static_cast<ModulWindow*>(pWin)->EditMacro( rSbxItem.GetMethodName() );
     556             :             }
     557             :             DBG_ASSERT( pWin, "Fenster wurde nicht erzeugt!" );
     558           0 :             SetCurWindow( pWin, true );
     559           0 :             pTabBar->MakeVisible( pTabBar->GetCurPageId() );
     560             :         }
     561           0 :         break;
     562             :         case SID_BASICIDE_SHOWWINDOW:
     563             :         {
     564           0 :             boost::scoped_ptr< ScriptDocument > pDocument;
     565             : 
     566           0 :             SFX_REQUEST_ARG( rReq, pDocumentItem, SfxStringItem, SID_BASICIDE_ARG_DOCUMENT, false );
     567           0 :             if ( pDocumentItem )
     568             :             {
     569           0 :                 OUString sDocumentCaption = pDocumentItem->GetValue();
     570           0 :                 if ( !sDocumentCaption.isEmpty() )
     571           0 :                     pDocument.reset( new ScriptDocument( ScriptDocument::getDocumentWithURLOrCaption( sDocumentCaption ) ) );
     572             :             }
     573             : 
     574           0 :             SFX_REQUEST_ARG( rReq, pDocModelItem, SfxUsrAnyItem, SID_BASICIDE_ARG_DOCUMENT_MODEL, false );
     575           0 :             if ( !pDocument.get() && pDocModelItem )
     576             :             {
     577           0 :                 uno::Reference< frame::XModel > xModel( pDocModelItem->GetValue(), UNO_QUERY );
     578           0 :                 if ( xModel.is() )
     579           0 :                     pDocument.reset( new ScriptDocument( xModel ) );
     580             :             }
     581             : 
     582           0 :             if ( !pDocument.get() )
     583           0 :                 break;
     584             : 
     585           0 :             SFX_REQUEST_ARG( rReq, pLibNameItem, SfxStringItem, SID_BASICIDE_ARG_LIBNAME, false );
     586           0 :             if ( !pLibNameItem )
     587           0 :                 break;
     588             : 
     589           0 :             OUString aLibName( pLibNameItem->GetValue() );
     590           0 :             pDocument->loadLibraryIfExists( E_SCRIPTS, aLibName );
     591           0 :             SetCurLib( *pDocument, aLibName );
     592           0 :             SFX_REQUEST_ARG( rReq, pNameItem, SfxStringItem, SID_BASICIDE_ARG_NAME, false );
     593           0 :             if ( pNameItem )
     594             :             {
     595           0 :                 OUString aName( pNameItem->GetValue() );
     596           0 :                 OUString aModType( "Module" );
     597           0 :                 OUString aDlgType( "Dialog" );
     598           0 :                 OUString aType( aModType );
     599           0 :                 SFX_REQUEST_ARG( rReq, pTypeItem, SfxStringItem, SID_BASICIDE_ARG_TYPE, false );
     600           0 :                 if ( pTypeItem )
     601           0 :                     aType = pTypeItem->GetValue();
     602             : 
     603           0 :                 BaseWindow* pWin = 0;
     604           0 :                 if ( aType == aModType )
     605           0 :                     pWin = FindBasWin( *pDocument, aLibName, aName, false );
     606           0 :                 else if ( aType == aDlgType )
     607           0 :                     pWin = FindDlgWin( *pDocument, aLibName, aName, false );
     608             : 
     609           0 :                 if ( pWin )
     610             :                 {
     611           0 :                     SetCurWindow( pWin, true );
     612           0 :                     if ( pTabBar )
     613           0 :                         pTabBar->MakeVisible( pTabBar->GetCurPageId() );
     614             : 
     615           0 :                     if (ModulWindow* pModWin = dynamic_cast<ModulWindow*>(pWin))
     616             :                     {
     617           0 :                         SFX_REQUEST_ARG( rReq, pLineItem, SfxUInt32Item, SID_BASICIDE_ARG_LINE, false );
     618           0 :                         if ( pLineItem )
     619             :                         {
     620           0 :                             pModWin->AssertValidEditEngine();
     621           0 :                             TextView* pTextView = pModWin->GetEditView();
     622           0 :                             if ( pTextView )
     623             :                             {
     624           0 :                                 TextEngine* pTextEngine = pTextView->GetTextEngine();
     625           0 :                                 if ( pTextEngine )
     626             :                                 {
     627           0 :                                     sal_uInt32 nLine = pLineItem->GetValue();
     628           0 :                                     sal_uInt32 nLineCount = 0;
     629           0 :                                     for ( sal_uInt32 i = 0, nCount = pTextEngine->GetParagraphCount(); i < nCount; ++i )
     630           0 :                                         nLineCount += pTextEngine->GetLineCount( i );
     631           0 :                                     if ( nLine > nLineCount )
     632           0 :                                         nLine = nLineCount;
     633           0 :                                     if ( nLine > 0 )
     634           0 :                                         --nLine;
     635             : 
     636             :                                     // scroll window and set selection
     637           0 :                                     long nVisHeight = pModWin->GetOutputSizePixel().Height();
     638           0 :                                     long nTextHeight = pTextEngine->GetTextHeight();
     639           0 :                                     if ( nTextHeight > nVisHeight )
     640             :                                     {
     641           0 :                                         long nMaxY = nTextHeight - nVisHeight;
     642           0 :                                         long nOldY = pTextView->GetStartDocPos().Y();
     643           0 :                                         long nNewY = nLine * pTextEngine->GetCharHeight() - nVisHeight / 2;
     644           0 :                                         nNewY = ::std::min( nNewY, nMaxY );
     645           0 :                                         pTextView->Scroll( 0, -( nNewY - nOldY ) );
     646           0 :                                         pTextView->ShowCursor( false, true );
     647           0 :                                         pModWin->GetEditVScrollBar().SetThumbPos( pTextView->GetStartDocPos().Y() );
     648             :                                     }
     649           0 :                                     sal_uInt16 nCol1 = 0, nCol2 = 0;
     650           0 :                                     SFX_REQUEST_ARG( rReq, pCol1Item, SfxUInt16Item, SID_BASICIDE_ARG_COLUMN1, false );
     651           0 :                                     if ( pCol1Item )
     652             :                                     {
     653           0 :                                         nCol1 = pCol1Item->GetValue();
     654           0 :                                         if ( nCol1 > 0 )
     655           0 :                                             --nCol1;
     656           0 :                                         nCol2 = nCol1;
     657             :                                     }
     658           0 :                                     SFX_REQUEST_ARG( rReq, pCol2Item, SfxUInt16Item, SID_BASICIDE_ARG_COLUMN2, false );
     659           0 :                                     if ( pCol2Item )
     660             :                                     {
     661           0 :                                         nCol2 = pCol2Item->GetValue();
     662           0 :                                         if ( nCol2 > 0 )
     663           0 :                                             --nCol2;
     664             :                                     }
     665           0 :                                     TextSelection aSel( TextPaM( nLine, nCol1 ), TextPaM( nLine, nCol2 ) );
     666           0 :                                     pTextView->SetSelection( aSel );
     667           0 :                                     pTextView->ShowCursor();
     668           0 :                                     Window* pWindow_ = pTextView->GetWindow();
     669           0 :                                     if ( pWindow_ )
     670           0 :                                         pWindow_->GrabFocus();
     671             :                                 }
     672             :                             }
     673             :                         }
     674             :                     }
     675           0 :                 }
     676             :             }
     677           0 :             rReq.Done();
     678             :         }
     679           0 :         break;
     680             : 
     681             :         case SID_BASICIDE_MANAGE_LANG:
     682             :         {
     683           0 :             ManageLanguageDialog aDlg(pCurWin, m_pCurLocalizationMgr);
     684           0 :             aDlg.Execute();
     685           0 :             rReq.Done();
     686             :         }
     687           0 :         break;
     688             : 
     689             :         default:
     690           0 :             if (pLayout)
     691           0 :                 pLayout->ExecuteGlobal(rReq);
     692           0 :             if (pCurWin)
     693           0 :                 pCurWin->ExecuteGlobal(rReq);
     694           0 :             break;
     695             :     }
     696           0 : }
     697             : 
     698           0 : void Shell::GetState(SfxItemSet &rSet)
     699             : {
     700           0 :     SfxWhichIter aIter(rSet);
     701           0 :     for ( sal_uInt16 nWh = aIter.FirstWhich(); 0 != nWh; nWh = aIter.NextWhich() )
     702             :     {
     703           0 :         switch ( nWh )
     704             :         {
     705             :             case SID_DOCINFO:
     706             :             {
     707           0 :                 rSet.DisableItem( nWh );
     708             :             }
     709           0 :             break;
     710             :             case SID_SAVEDOC:
     711             :             {
     712           0 :                 bool bDisable = false;
     713             : 
     714           0 :                 if ( pCurWin )
     715             :                 {
     716           0 :                     if ( !pCurWin->IsModified() )
     717             :                     {
     718           0 :                         ScriptDocument aDocument( pCurWin->GetDocument() );
     719           0 :                         bDisable =  ( !aDocument.isAlive() )
     720           0 :                                 ||  ( aDocument.isDocument() ? !aDocument.isDocumentModified() : !IsAppBasicModified() );
     721             :                     }
     722             :                 }
     723             :                 else
     724             :                 {
     725           0 :                     bDisable = true;
     726             :                 }
     727             : 
     728           0 :                 if ( bDisable )
     729           0 :                     rSet.DisableItem( nWh );
     730             :             }
     731           0 :             break;
     732             :             case SID_NEWWINDOW:
     733             :             case SID_SAVEASDOC:
     734             :             {
     735           0 :                 rSet.DisableItem( nWh );
     736             :             }
     737           0 :             break;
     738             :             case SID_SIGNATURE:
     739             :             {
     740           0 :                 sal_uInt16 nState = 0;
     741           0 :                 if ( pCurWin )
     742             :                 {
     743           0 :                     DocumentSignature aSignature( pCurWin->GetDocument() );
     744           0 :                     nState = aSignature.getScriptingSignatureState();
     745             :                 }
     746           0 :                 rSet.Put( SfxUInt16Item( SID_SIGNATURE, nState ) );
     747             :             }
     748           0 :             break;
     749             :             case SID_BASICIDE_MODULEDLG:
     750             :             {
     751           0 :                 if ( StarBASIC::IsRunning() )
     752           0 :                     rSet.DisableItem( nWh );
     753             :             }
     754           0 :             break;
     755             :             case SID_BASICIDE_OBJCAT:
     756           0 :                 if (pLayout)
     757           0 :                     rSet.Put(SfxBoolItem(nWh, aObjectCatalog.IsVisible()));
     758             :                 else
     759           0 :                     rSet.Put(SfxVisibilityItem(nWh, false));
     760           0 :                 break;
     761             :             case SID_BASICIDE_SHOWSBX:
     762             :             case SID_BASICIDE_CREATEMACRO:
     763             :             case SID_BASICIDE_EDITMACRO:
     764             :             case SID_BASICIDE_NAMECHANGEDONTAB:
     765             :             {
     766             :                 ;
     767             :             }
     768           0 :             break;
     769             : 
     770             :             case SID_BASICIDE_ADDWATCH:
     771             :             case SID_BASICIDE_REMOVEWATCH:
     772             :             case SID_BASICLOAD:
     773             :             case SID_BASICSAVEAS:
     774             :             case SID_BASICIDE_MATCHGROUP:
     775             :             {
     776           0 :                 if (!dynamic_cast<ModulWindow*>(pCurWin))
     777           0 :                     rSet.DisableItem( nWh );
     778           0 :                 else if ( ( nWh == SID_BASICLOAD ) && ( StarBASIC::IsRunning() || ( pCurWin && pCurWin->IsReadOnly() ) ) )
     779           0 :                     rSet.DisableItem( nWh );
     780             :             }
     781           0 :             break;
     782             :             case SID_BASICRUN:
     783             :             case SID_BASICSTEPINTO:
     784             :             case SID_BASICSTEPOVER:
     785             :             case SID_BASICSTEPOUT:
     786             :             case SID_BASICIDE_TOGGLEBRKPNT:
     787             :             case SID_BASICIDE_MANAGEBRKPNTS:
     788             :             {
     789           0 :                 if (ModulWindow* pMCurWin = dynamic_cast<ModulWindow*>(pCurWin))
     790             :                 {
     791           0 :                     if (StarBASIC::IsRunning() && !pMCurWin->GetBasicStatus().bIsInReschedule)
     792           0 :                         rSet.DisableItem(nWh);
     793             :                 }
     794             :                 else
     795           0 :                     rSet.DisableItem( nWh );
     796             :             }
     797           0 :             break;
     798             :             case SID_BASICCOMPILE:
     799             :             {
     800           0 :                 if (StarBASIC::IsRunning() || !dynamic_cast<ModulWindow*>(pCurWin))
     801           0 :                     rSet.DisableItem( nWh );
     802             :             }
     803           0 :             break;
     804             :             case SID_BASICSTOP:
     805             :             {
     806             :                 // stop is always possible when some Basic is running...
     807           0 :                 if (!StarBASIC::IsRunning())
     808           0 :                     rSet.DisableItem( nWh );
     809             :             }
     810           0 :             break;
     811             :             case SID_CHOOSE_CONTROLS:
     812             :             case SID_DIALOG_TESTMODE:
     813             :             case SID_INSERT_FORM_RADIO:
     814             :             case SID_INSERT_FORM_CHECK:
     815             :             case SID_INSERT_FORM_LIST:
     816             :             case SID_INSERT_FORM_COMBO:
     817             :             case SID_INSERT_FORM_VSCROLL:
     818             :             case SID_INSERT_FORM_HSCROLL:
     819             :             case SID_INSERT_FORM_SPIN:
     820             :             {
     821           0 :                 if (!dynamic_cast<DialogWindow*>(pCurWin))
     822           0 :                     rSet.DisableItem( nWh );
     823             :             }
     824           0 :             break;
     825             :             case SID_SHOW_FORMS:
     826             :             case SID_SHOW_HIDDEN:
     827             :             {
     828           0 :                 rSet.DisableItem( nWh );
     829             :             }
     830           0 :             break;
     831             :             case SID_SEARCH_OPTIONS:
     832             :             {
     833           0 :                 sal_uInt16 nOptions = 0;
     834           0 :                 if( pCurWin )
     835           0 :                     nOptions = pCurWin->GetSearchOptions();
     836           0 :                 rSet.Put( SfxUInt16Item( SID_SEARCH_OPTIONS, nOptions ) );
     837             :             }
     838           0 :             break;
     839             :             case SID_BASICIDE_LIBSELECTOR:
     840             :             {
     841           0 :                 OUString aName;
     842           0 :                 if ( !m_aCurLibName.isEmpty() )
     843             :                 {
     844           0 :                     LibraryLocation eLocation = m_aCurDocument.getLibraryLocation( m_aCurLibName );
     845           0 :                     aName = CreateMgrAndLibStr( m_aCurDocument.getTitle( eLocation ), m_aCurLibName );
     846             :                 }
     847           0 :                 SfxStringItem aItem( SID_BASICIDE_LIBSELECTOR, aName );
     848           0 :                 rSet.Put( aItem );
     849             :             }
     850           0 :             break;
     851             :             case SID_SEARCH_ITEM:
     852             :             {
     853           0 :                 OUString aSelected = GetSelectionText(true);
     854           0 :                 SvxSearchItem& rItem = GetExtraData()->GetSearchItem();
     855           0 :                 rItem.SetSearchString( aSelected );
     856           0 :                 rSet.Put( rItem );
     857             :             }
     858           0 :             break;
     859             :             case SID_BASICIDE_STAT_DATE:
     860             :             {
     861           0 :                 OUString aDate( "Datum?!" );
     862           0 :                 SfxStringItem aItem( SID_BASICIDE_STAT_DATE, aDate );
     863           0 :                 rSet.Put( aItem );
     864             :             }
     865           0 :             break;
     866             :             case SID_DOC_MODIFIED:
     867             :             {
     868           0 :                 bool bModified = false;
     869             : 
     870           0 :                 if ( pCurWin )
     871             :                 {
     872           0 :                     if ( pCurWin->IsModified() )
     873           0 :                         bModified = true;
     874             :                     else
     875             :                     {
     876           0 :                         ScriptDocument aDocument( pCurWin->GetDocument() );
     877           0 :                         bModified = aDocument.isDocument() ? aDocument.isDocumentModified() : IsAppBasicModified();
     878             :                     }
     879             :                 }
     880             : 
     881           0 :                 SfxBoolItem aItem(SID_DOC_MODIFIED, bModified);
     882           0 :                 rSet.Put( aItem );
     883             :             }
     884           0 :             break;
     885             :             case SID_BASICIDE_STAT_TITLE:
     886             :             {
     887           0 :                 if ( pCurWin )
     888             :                 {
     889           0 :                     OUString aTitle = pCurWin->CreateQualifiedName();
     890           0 :                     SfxStringItem aItem( SID_BASICIDE_STAT_TITLE, aTitle );
     891           0 :                     rSet.Put( aItem );
     892             :                 }
     893             :             }
     894           0 :             break;
     895             :             // are interpreted by the controller:
     896             :             case SID_ATTR_SIZE:
     897             :             case SID_ATTR_INSERT:
     898           0 :             break;
     899             :             case SID_UNDO:
     900             :             case SID_REDO:
     901             :             {
     902           0 :                 if( GetUndoManager() )  // recursive GetState else
     903           0 :                     GetViewFrame()->GetSlotState( nWh, NULL, &rSet );
     904             :             }
     905           0 :             break;
     906             :             case SID_BASICIDE_CURRENT_LANG:
     907             :             {
     908           0 :                 if( (pCurWin && pCurWin->IsReadOnly()) || GetCurLibName().isEmpty() )
     909           0 :                     rSet.DisableItem( nWh );
     910             :                 else
     911             :                 {
     912           0 :                     OUString aItemStr;
     913           0 :                     boost::shared_ptr<LocalizationMgr> pCurMgr(GetCurLocalizationMgr());
     914           0 :                     if ( pCurMgr->isLibraryLocalized() )
     915             :                     {
     916           0 :                         Sequence< lang::Locale > aLocaleSeq = pCurMgr->getStringResourceManager()->getLocales();
     917           0 :                         const lang::Locale* pLocale = aLocaleSeq.getConstArray();
     918           0 :                         sal_Int32 i, nCount = aLocaleSeq.getLength();
     919             : 
     920             :                         // Force different results for any combination of locales and default locale
     921           0 :                         OUString aLangStr;
     922           0 :                         for ( i = 0;  i <= nCount;  ++i )
     923             :                         {
     924           0 :                             lang::Locale aLocale;
     925           0 :                             if( i < nCount )
     926           0 :                                 aLocale = pLocale[i];
     927             :                             else
     928           0 :                                 aLocale = pCurMgr->getStringResourceManager()->getDefaultLocale();
     929             : 
     930           0 :                             aLangStr += aLocale.Language;
     931           0 :                             aLangStr += aLocale.Country;
     932           0 :                             aLangStr += aLocale.Variant;
     933           0 :                         }
     934           0 :                         aItemStr = aLangStr;
     935             :                     }
     936           0 :                     rSet.Put( SfxStringItem( nWh, aItemStr ) );
     937             :                 }
     938             :             }
     939           0 :             break;
     940             : 
     941             :             case SID_BASICIDE_MANAGE_LANG:
     942             :             {
     943           0 :                 if( (pCurWin && pCurWin->IsReadOnly()) || GetCurLibName().isEmpty() )
     944           0 :                     rSet.DisableItem( nWh );
     945             :             }
     946           0 :             break;
     947             :             case SID_GOTOLINE:
     948             :             {
     949             :                 // if this is not a module window hide the
     950             :                 // setting, doesn't make sense for example if the
     951             :                 // dialog editor is open
     952           0 :                 if (pCurWin && !dynamic_cast<ModulWindow*>(pCurWin))
     953             :                 {
     954           0 :                     rSet.DisableItem( nWh );
     955           0 :                     rSet.Put(SfxVisibilityItem(nWh, false));
     956             :                 }
     957           0 :                 break;
     958             :             }
     959             :             default:
     960           0 :                 if (pLayout)
     961           0 :                     pLayout->GetState(rSet, nWh);
     962             :         }
     963             :     }
     964           0 :     if ( pCurWin )
     965           0 :         pCurWin->GetState( rSet );
     966           0 : }
     967             : 
     968           0 : bool Shell::HasUIFeature( sal_uInt32 nFeature )
     969             : {
     970           0 :     bool bResult = false;
     971             : 
     972           0 :     if ( (nFeature & BASICIDE_UI_FEATURE_SHOW_BROWSER) == BASICIDE_UI_FEATURE_SHOW_BROWSER )
     973             :     {
     974             :         // fade out (in) property browser in module (dialog) windows
     975           0 :         if (dynamic_cast<DialogWindow*>(pCurWin) && !pCurWin->IsReadOnly())
     976           0 :             bResult = true;
     977             :     }
     978             : 
     979           0 :     return bResult;
     980             : }
     981             : 
     982           0 : void Shell::SetCurWindow( BaseWindow* pNewWin, bool bUpdateTabBar, bool bRememberAsCurrent )
     983             : {
     984           0 :     if ( pNewWin != pCurWin )
     985             :     {
     986           0 :         pCurWin = pNewWin;
     987           0 :         if (pLayout)
     988           0 :             pLayout->Deactivating();
     989           0 :         if (pCurWin)
     990             :         {
     991           0 :             if (pCurWin->GetType() == TYPE_MODULE)
     992           0 :                 pLayout = pModulLayout.get();
     993             :             else
     994           0 :                 pLayout = pDialogLayout.get();
     995           0 :             AdjustPosSizePixel(Point(0, 0), GetViewFrame()->GetWindow().GetOutputSizePixel());
     996           0 :             pLayout->Activating(*pCurWin);
     997           0 :             GetViewFrame()->GetWindow().SetHelpId(pCurWin->GetHid());
     998           0 :             if (bRememberAsCurrent)
     999           0 :                 pCurWin->InsertLibInfo();
    1000           0 :             if (GetViewFrame()->GetWindow().IsVisible()) // SFX will do it later otherwise
    1001           0 :                 pCurWin->Show();
    1002           0 :             pCurWin->Init();
    1003           0 :             if (!GetExtraData()->ShellInCriticalSection())
    1004             :             {
    1005           0 :                 Window* pFrameWindow = &GetViewFrame()->GetWindow();
    1006           0 :                 Window* pFocusWindow = Application::GetFocusWindow();
    1007           0 :                 while ( pFocusWindow && ( pFocusWindow != pFrameWindow ) )
    1008           0 :                     pFocusWindow = pFocusWindow->GetParent();
    1009           0 :                 if ( pFocusWindow ) // Focus in BasicIDE
    1010           0 :                     pNewWin->GrabFocus();
    1011             :             }
    1012             :         }
    1013             :         else
    1014             :         {
    1015           0 :             SetWindow(pLayout);
    1016           0 :             pLayout = 0;
    1017             :         }
    1018           0 :         if ( bUpdateTabBar )
    1019             :         {
    1020           0 :             sal_uLong nKey = GetWindowId( pCurWin );
    1021           0 :             if ( pCurWin && ( pTabBar->GetPagePos( (sal_uInt16)nKey ) == TAB_PAGE_NOTFOUND ) )
    1022           0 :                 pTabBar->InsertPage( (sal_uInt16)nKey, pCurWin->GetTitle() );   // has just been faded in
    1023           0 :             pTabBar->SetCurPageId( (sal_uInt16)nKey );
    1024             :         }
    1025           0 :         if ( pCurWin && pCurWin->IsSuspended() )    // if the window is shown in the case of an error...
    1026           0 :             pCurWin->SetStatus( pCurWin->GetStatus() & ~BASWIN_SUSPENDED );
    1027           0 :         if ( pCurWin )
    1028             :         {
    1029           0 :             SetWindow( pCurWin );
    1030           0 :             if ( pCurWin->GetDocument().isDocument() )
    1031           0 :                 SfxObjectShell::SetCurrentComponent( pCurWin->GetDocument().getDocument() );
    1032             :         }
    1033           0 :         else if (pLayout)
    1034             :         {
    1035           0 :             SetWindow(pLayout);
    1036           0 :             GetViewFrame()->GetWindow().SetHelpId( HID_BASICIDE_MODULWINDOW );
    1037           0 :             SfxObjectShell::SetCurrentComponent(0);
    1038             :         }
    1039           0 :         aObjectCatalog.SetCurrentEntry(pCurWin);
    1040           0 :         SetUndoManager( pCurWin ? pCurWin->GetUndoManager() : 0 );
    1041           0 :         InvalidateBasicIDESlots();
    1042           0 :         EnableScrollbars(pCurWin != 0);
    1043             : 
    1044           0 :         if ( m_pCurLocalizationMgr )
    1045           0 :             m_pCurLocalizationMgr->handleTranslationbar();
    1046             : 
    1047           0 :         ManageToolbars();
    1048             : 
    1049             :         // fade out (in) property browser in module (dialog) windows
    1050           0 :         UIFeatureChanged();
    1051             :     }
    1052           0 : }
    1053             : 
    1054           0 : void Shell::ManageToolbars()
    1055             : {
    1056           0 :     static OUString aLayoutManagerName( "LayoutManager" );
    1057           0 :     static OUString aMacroBarResName( "private:resource/toolbar/macrobar" );
    1058           0 :     static OUString aDialogBarResName( "private:resource/toolbar/dialogbar" );
    1059           0 :     static OUString aInsertControlsBarResName( "private:resource/toolbar/insertcontrolsbar" );
    1060           0 :     static OUString aFormControlsBarResName( "private:resource/toolbar/formcontrolsbar" );
    1061             :     (void)aInsertControlsBarResName;
    1062             : 
    1063           0 :     if( !pCurWin )
    1064           0 :         return;
    1065             : 
    1066             :     Reference< beans::XPropertySet > xFrameProps
    1067           0 :         ( GetViewFrame()->GetFrame().GetFrameInterface(), uno::UNO_QUERY );
    1068           0 :     if ( xFrameProps.is() )
    1069             :     {
    1070           0 :         Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
    1071           0 :         uno::Any a = xFrameProps->getPropertyValue( aLayoutManagerName );
    1072           0 :         a >>= xLayoutManager;
    1073           0 :         if ( xLayoutManager.is() )
    1074             :         {
    1075           0 :             xLayoutManager->lock();
    1076           0 :             if (dynamic_cast<DialogWindow*>(pCurWin))
    1077             :             {
    1078           0 :                 xLayoutManager->destroyElement( aMacroBarResName );
    1079             : 
    1080           0 :                 xLayoutManager->requestElement( aDialogBarResName );
    1081           0 :                 xLayoutManager->requestElement( aInsertControlsBarResName );
    1082           0 :                 xLayoutManager->requestElement( aFormControlsBarResName );
    1083             :             }
    1084             :             else
    1085             :             {
    1086           0 :                 xLayoutManager->destroyElement( aDialogBarResName );
    1087           0 :                 xLayoutManager->destroyElement( aInsertControlsBarResName );
    1088           0 :                 xLayoutManager->destroyElement( aFormControlsBarResName );
    1089             : 
    1090           0 :                 xLayoutManager->requestElement( aMacroBarResName );
    1091             :             }
    1092           0 :             xLayoutManager->unlock();
    1093           0 :         }
    1094           0 :     }
    1095             : }
    1096             : 
    1097           0 : BaseWindow* Shell::FindApplicationWindow()
    1098             : {
    1099           0 :     return FindWindow( ScriptDocument::getApplicationScriptDocument() );
    1100             : }
    1101             : 
    1102           0 : BaseWindow* Shell::FindWindow(
    1103             :     ScriptDocument const& rDocument,
    1104             :     OUString const& rLibName, OUString const& rName,
    1105             :     ItemType eType, bool bFindSuspended
    1106             : )
    1107             : {
    1108           0 :     for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
    1109             :     {
    1110           0 :         BaseWindow* const pWin = it->second;
    1111           0 :         if (pWin->Is(rDocument, rLibName, rName, eType, bFindSuspended))
    1112           0 :             return pWin;
    1113             :     }
    1114           0 :     return 0;
    1115             : }
    1116             : 
    1117           0 : bool Shell::CallBasicErrorHdl( StarBASIC* pBasic )
    1118             : {
    1119           0 :     bool nRet = false;
    1120           0 :     ModulWindow* pModWin = ShowActiveModuleWindow( pBasic );
    1121           0 :     if ( pModWin )
    1122           0 :         nRet = pModWin->BasicErrorHdl( pBasic );
    1123           0 :     return nRet;
    1124             : }
    1125             : 
    1126           0 : long Shell::CallBasicBreakHdl( StarBASIC* pBasic )
    1127             : {
    1128           0 :     long nRet = 0;
    1129           0 :     ModulWindow* pModWin = ShowActiveModuleWindow( pBasic );
    1130           0 :     if ( pModWin )
    1131             :     {
    1132             :         bool bAppWindowDisabled, bDispatcherLocked;
    1133             :         sal_uInt16 nWaitCount;
    1134             :         SfxUInt16Item *pSWActionCount, *pSWLockViewCount;
    1135             :         BasicStopped( &bAppWindowDisabled, &bDispatcherLocked,
    1136           0 :                                 &nWaitCount, &pSWActionCount, &pSWLockViewCount );
    1137             : 
    1138           0 :         nRet = pModWin->BasicBreakHdl( pBasic );
    1139             : 
    1140           0 :         if ( StarBASIC::IsRunning() )   // if cancelled...
    1141             :         {
    1142           0 :             if ( bAppWindowDisabled )
    1143           0 :                 Application::GetDefDialogParent()->Enable(false);
    1144             : 
    1145           0 :             if ( nWaitCount )
    1146             :             {
    1147           0 :                 Shell* pShell = GetShell();
    1148           0 :                 for ( sal_uInt16 n = 0; n < nWaitCount; n++ )
    1149           0 :                     pShell->GetViewFrame()->GetWindow().EnterWait();
    1150             :             }
    1151             :         }
    1152             :     }
    1153           0 :     return nRet;
    1154             : }
    1155             : 
    1156           0 : ModulWindow* Shell::ShowActiveModuleWindow( StarBASIC* pBasic )
    1157             : {
    1158           0 :     SetCurLib( ScriptDocument::getApplicationScriptDocument(), OUString(), false );
    1159             : 
    1160           0 :     SbModule* pActiveModule = StarBASIC::GetActiveModule();
    1161           0 :     if (SbClassModuleObject* pCMO = dynamic_cast<SbClassModuleObject*>(pActiveModule))
    1162           0 :         pActiveModule = pCMO->getClassModule();
    1163             : 
    1164             :     DBG_ASSERT( pActiveModule, "Kein aktives Modul im ErrorHdl?!" );
    1165           0 :     if ( pActiveModule )
    1166             :     {
    1167           0 :         ModulWindow* pWin = 0;
    1168           0 :         SbxObject* pParent = pActiveModule->GetParent();
    1169           0 :         if (StarBASIC* pLib = dynamic_cast<StarBASIC*>(pParent))
    1170             :         {
    1171           0 :             if (BasicManager* pBasMgr = FindBasicManager(pLib))
    1172             :             {
    1173           0 :                 ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
    1174           0 :                 OUString aLibName = pLib->GetName();
    1175           0 :                 pWin = FindBasWin( aDocument, aLibName, pActiveModule->GetName(), true );
    1176             :                 DBG_ASSERT( pWin, "Error/Step-Hdl: Fenster wurde nicht erzeugt/gefunden!" );
    1177           0 :                 SetCurLib( aDocument, aLibName );
    1178           0 :                 SetCurWindow( pWin, true );
    1179             :             }
    1180             :         }
    1181             :         else
    1182             :             DBG_ASSERT(false, "No BASIC!");
    1183           0 :         if (BasicManager* pBasicMgr = FindBasicManager(pBasic))
    1184           0 :             StartListening( *pBasicMgr, true /* log on only once */ );
    1185           0 :         return pWin;
    1186             :     }
    1187           0 :     return 0;
    1188             : }
    1189             : 
    1190           0 : void Shell::AdjustPosSizePixel( const Point &rPos, const Size &rSize )
    1191             : {
    1192             :     // not if iconified because the whole text would be displaced then at restore
    1193           0 :     if ( GetViewFrame()->GetWindow().GetOutputSizePixel().Height() == 0 )
    1194           0 :         return;
    1195             : 
    1196           0 :     Size aSz( rSize );
    1197           0 :     Size aScrollBarBoxSz( aScrollBarBox.GetSizePixel() );
    1198           0 :     aSz.Height() -= aScrollBarBoxSz.Height();
    1199             : 
    1200           0 :     Size aOutSz( aSz );
    1201           0 :     aSz.Width() -= aScrollBarBoxSz.Width();
    1202           0 :     aScrollBarBox.SetPosPixel( Point( rSize.Width() - aScrollBarBoxSz.Width(), rSize.Height() - aScrollBarBoxSz.Height() ) );
    1203           0 :     aVScrollBar.SetPosSizePixel( Point( rPos.X()+aSz.Width(), rPos.Y() ), Size( aScrollBarBoxSz.Width(), aSz.Height() ) );
    1204           0 :     if ( bTabBarSplitted )
    1205             :     {
    1206             :         // SplitSize is 0 at a resize!
    1207           0 :         long nSplitPos = pTabBar->GetSizePixel().Width();
    1208           0 :         if ( nSplitPos > aSz.Width() )
    1209           0 :             nSplitPos = aSz.Width();
    1210           0 :         pTabBar->SetPosSizePixel( Point( rPos.X(), rPos.Y()+aSz.Height() ), Size( nSplitPos, aScrollBarBoxSz.Height() ) );
    1211           0 :         long nScrlStart = rPos.X() + nSplitPos;
    1212           0 :         aHScrollBar.SetPosSizePixel( Point( nScrlStart, rPos.Y()+aSz.Height() ), Size( aSz.Width() - nScrlStart + 1, aScrollBarBoxSz.Height() ) );
    1213           0 :         aHScrollBar.Update();
    1214             :     }
    1215             :     else
    1216             :     {
    1217           0 :         aHScrollBar.SetPosSizePixel( Point( rPos.X()+ aSz.Width()/2 - 1, rPos.Y()+aSz.Height() ), Size( aSz.Width()/2 + 2, aScrollBarBoxSz.Height() ) );
    1218           0 :         pTabBar->SetPosSizePixel( Point( rPos.X(), rPos.Y()+aSz.Height() ), Size( aSz.Width()/2, aScrollBarBoxSz.Height() ) );
    1219             :     }
    1220             : 
    1221           0 :     if (pLayout)
    1222           0 :         pLayout->SetPosSizePixel(rPos, dynamic_cast<DialogWindow*>(pCurWin) ? aSz : aOutSz);
    1223             : }
    1224             : 
    1225           0 : Reference< XModel > Shell::GetCurrentDocument() const
    1226             : {
    1227           0 :     Reference< XModel > xDocument;
    1228           0 :     if ( pCurWin && pCurWin->GetDocument().isDocument() )
    1229           0 :         xDocument = pCurWin->GetDocument().getDocument();
    1230           0 :     return xDocument;
    1231             : }
    1232             : 
    1233           0 : void Shell::Activate( bool bMDI )
    1234             : {
    1235           0 :     SfxViewShell::Activate( bMDI );
    1236             : 
    1237           0 :     if ( bMDI )
    1238             :     {
    1239           0 :         if (DialogWindow* pDCurWin = dynamic_cast<DialogWindow*>(pCurWin))
    1240           0 :             pDCurWin->UpdateBrowser();
    1241             :     }
    1242           0 : }
    1243             : 
    1244           0 : void Shell::Deactivate( bool bMDI )
    1245             : {
    1246             :     // bMDI == true means that another MDI has been activated; in case of a
    1247             :     // deactivate due to a MessageBox bMDI is false
    1248           0 :     if ( bMDI )
    1249             :     {
    1250           0 :         if (DialogWindow* pXDlgWin = dynamic_cast<DialogWindow*>(pCurWin))
    1251             :         {
    1252           0 :             pXDlgWin->DisableBrowser();
    1253           0 :             if( pXDlgWin->IsModified() )
    1254           0 :                 MarkDocumentModified( pXDlgWin->GetDocument() );
    1255             :         }
    1256             : 
    1257             :         // test CanClose to also test during deactivating the BasicIDE whether
    1258             :         // the sourcecode is too large in one of the modules...
    1259           0 :         for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
    1260             :         {
    1261           0 :             BaseWindow* pWin = it->second;
    1262           0 :             if ( /* !pWin->IsSuspended() && */ !pWin->CanClose() )
    1263             :             {
    1264           0 :                 if ( !m_aCurLibName.isEmpty() && ( pWin->IsDocument( m_aCurDocument ) || pWin->GetLibName() != m_aCurLibName ) )
    1265           0 :                     SetCurLib( ScriptDocument::getApplicationScriptDocument(), OUString(), false );
    1266           0 :                 SetCurWindow( pWin, true );
    1267           0 :                 break;
    1268             :             }
    1269             :         }
    1270             :     }
    1271           0 : }
    1272             : 
    1273           0 : } // namespace basctl
    1274             : 
    1275             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10