LCOV - code coverage report
Current view: top level - basctl/source/basicide - macrodlg.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 468 0.0 %
Date: 2014-04-11 Functions: 0 27 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 <vcl/msgbox.hxx>
      21             : 
      22             : #include <macrodlg.hxx>
      23             : #include <macrodlg.hrc>
      24             : #include <basidesh.hrc>
      25             : #include <basidesh.hxx>
      26             : #include <baside2.hrc>
      27             : #include <basobj.hxx>
      28             : #include <baside3.hxx>
      29             : 
      30             : #include <iderdll.hxx>
      31             : #include <iderdll2.hxx>
      32             : #include <iderid.hxx>
      33             : 
      34             : #include <moduldlg.hxx>
      35             : #include <basic/basmgr.hxx>
      36             : #include <basic/sbmeth.hxx>
      37             : #include <basic/sbmod.hxx>
      38             : #include <basic/sbx.hxx>
      39             : 
      40             : #include <bastypes.hxx>
      41             : #include <sbxitem.hxx>
      42             : #include <sfx2/app.hxx>
      43             : #include <sfx2/dispatch.hxx>
      44             : #include <sfx2/minfitem.hxx>
      45             : #include <sfx2/request.hxx>
      46             : 
      47             : #include <com/sun/star/script/XLibraryContainer2.hpp>
      48             : #include <com/sun/star/document/MacroExecMode.hpp>
      49             : 
      50             : #include <map>
      51             : 
      52             : namespace basctl
      53             : {
      54             : 
      55             : using ::std::map;
      56             : using ::std::pair;
      57             : 
      58             : using namespace ::com::sun::star;
      59             : using namespace ::com::sun::star::uno;
      60             : 
      61           0 : MacroChooser::MacroChooser( Window* pParnt, bool bCreateEntries )
      62             :     : SfxModalDialog(pParnt, "BasicMacroDialog", "modules/BasicIDE/ui/basicmacrodialog.ui")
      63             :     , bNewDelIsDel(true)
      64             :     // the Sfx doesn't aske the BasicManger whether modified or not
      65             :     // => start saving in case of a change without a into the BasicIDE.
      66             :     , bForceStoreBasic(false)
      67           0 :     , nMode(All)
      68             : {
      69           0 :     get(m_pMacroNameEdit, "macronameedit");
      70           0 :     get(m_pMacroFromTxT, "macrofromft");
      71           0 :     get(m_pMacrosSaveInTxt, "macrotoft");
      72           0 :     get(m_pBasicBox, "libraries");
      73           0 :     get(m_pMacrosInTxt, "existingmacrosft");
      74           0 :     m_aMacrosInTxtBaseStr = m_pMacrosInTxt->GetText();
      75           0 :     get(m_pMacroBox, "macros");
      76           0 :     get(m_pRunButton, "run");
      77           0 :     get(m_pCloseButton, "close");
      78           0 :     get(m_pAssignButton, "assign");
      79           0 :     get(m_pEditButton, "edit");
      80           0 :     get(m_pDelButton, "delete");
      81           0 :     get(m_pOrganizeButton, "organize");
      82           0 :     get(m_pNewLibButton, "newlibrary");
      83           0 :     get(m_pNewModButton, "newmodule");
      84             : 
      85           0 :     m_pMacroBox->SetSelectionMode( SINGLE_SELECTION );
      86           0 :     m_pMacroBox->SetHighlightRange(); // select over the whole width
      87             : 
      88           0 :     m_pRunButton->SetClickHdl( LINK( this, MacroChooser, ButtonHdl ) );
      89           0 :     m_pCloseButton->SetClickHdl( LINK( this, MacroChooser, ButtonHdl ) );
      90           0 :     m_pAssignButton->SetClickHdl( LINK( this, MacroChooser, ButtonHdl ) );
      91           0 :     m_pEditButton->SetClickHdl( LINK( this, MacroChooser, ButtonHdl ) );
      92           0 :     m_pDelButton->SetClickHdl( LINK( this, MacroChooser, ButtonHdl ) );
      93           0 :     m_pOrganizeButton->SetClickHdl( LINK( this, MacroChooser, ButtonHdl ) );
      94             : 
      95             :     // Buttons only for MacroChooser::Recording
      96           0 :     m_pNewLibButton->SetClickHdl( LINK( this, MacroChooser, ButtonHdl ) );
      97           0 :     m_pNewModButton->SetClickHdl( LINK( this, MacroChooser, ButtonHdl ) );
      98           0 :     m_pNewLibButton->Hide();       // default
      99           0 :     m_pNewModButton->Hide();       // default
     100           0 :     m_pMacrosSaveInTxt->Hide();    // default
     101             : 
     102           0 :     m_pMacrosInTxt->SetStyle( WB_NOMULTILINE | WB_PATHELLIPSIS );
     103             : 
     104           0 :     m_pMacroNameEdit->SetModifyHdl( LINK( this, MacroChooser, EditModifyHdl ) );
     105             : 
     106           0 :     m_pBasicBox->SetSelectHdl( LINK( this, MacroChooser, BasicSelectHdl ) );
     107             : 
     108           0 :     m_pMacroBox->SetDoubleClickHdl( LINK( this, MacroChooser, MacroDoubleClickHdl ) );
     109           0 :     m_pMacroBox->SetSelectHdl( LINK( this, MacroChooser, MacroSelectHdl ) );
     110             : 
     111           0 :     m_pBasicBox->SetMode( BROWSEMODE_MODULES );
     112             :     m_pBasicBox->SetStyle( WB_TABSTOP | WB_BORDER |
     113             :                         WB_HASLINES | WB_HASLINESATROOT |
     114             :                         WB_HASBUTTONS | WB_HASBUTTONSATROOT |
     115           0 :                         WB_HSCROLL );
     116             : 
     117           0 :     if (SfxDispatcher* pDispatcher = GetDispatcher())
     118           0 :         pDispatcher->Execute( SID_BASICIDE_STOREALLMODULESOURCES );
     119             : 
     120           0 :     if ( bCreateEntries )
     121           0 :         m_pBasicBox->ScanAllEntries();
     122           0 : }
     123             : 
     124           0 : MacroChooser::~MacroChooser()
     125             : {
     126           0 :     if ( bForceStoreBasic )
     127           0 :         SFX_APP()->SaveBasicAndDialogContainer();
     128           0 : }
     129             : 
     130           0 : void MacroChooser::StoreMacroDescription()
     131             : {
     132           0 :     EntryDescriptor aDesc = m_pBasicBox->GetEntryDescriptor(m_pBasicBox->FirstSelected());
     133           0 :     OUString aMethodName;
     134           0 :     SvTreeListEntry* pEntry = m_pMacroBox->FirstSelected();
     135           0 :     if ( pEntry )
     136           0 :         aMethodName = m_pMacroBox->GetEntryText( pEntry );
     137             :     else
     138           0 :         aMethodName = m_pMacroNameEdit->GetText();
     139           0 :     if ( !aMethodName.isEmpty() )
     140             :     {
     141           0 :         aDesc.SetMethodName( aMethodName );
     142           0 :         aDesc.SetType( OBJ_TYPE_METHOD );
     143             :     }
     144             : 
     145           0 :     if (ExtraData* pData = basctl::GetExtraData())
     146           0 :         pData->SetLastEntryDescriptor( aDesc );
     147           0 : }
     148             : 
     149           0 : void MacroChooser::RestoreMacroDescription()
     150             : {
     151           0 :     EntryDescriptor aDesc;
     152           0 :     if (Shell* pShell = GetShell())
     153             :     {
     154           0 :         if (BaseWindow* pCurWin = pShell->GetCurWindow())
     155           0 :             aDesc = pCurWin->CreateEntryDescriptor();
     156             :     }
     157             :     else
     158             :     {
     159           0 :         if (ExtraData* pData = basctl::GetExtraData())
     160           0 :             aDesc = pData->GetLastEntryDescriptor();
     161             :     }
     162             : 
     163           0 :     m_pBasicBox->SetCurrentEntry( aDesc );
     164             : 
     165           0 :     OUString aLastMacro( aDesc.GetMethodName() );
     166           0 :     if ( !aLastMacro.isEmpty() )
     167             :     {
     168             :         // find entry in macro box
     169           0 :         SvTreeListEntry* pEntry = 0;
     170           0 :         sal_uLong nPos = 0;
     171           0 :         SvTreeListEntry* pE = m_pMacroBox->GetEntry( nPos );
     172           0 :         while ( pE )
     173             :         {
     174           0 :             if ( m_pMacroBox->GetEntryText( pE ) == aLastMacro )
     175             :             {
     176           0 :                 pEntry = pE;
     177           0 :                 break;
     178             :             }
     179           0 :             pE = m_pMacroBox->GetEntry( ++nPos );
     180             :         }
     181             : 
     182           0 :         if ( pEntry )
     183           0 :             m_pMacroBox->SetCurEntry( pEntry );
     184             :         else
     185             :         {
     186           0 :             m_pMacroNameEdit->SetText( aLastMacro );
     187           0 :             m_pMacroNameEdit->SetSelection( Selection( 0, 0 ) );
     188             :         }
     189           0 :     }
     190           0 : }
     191             : 
     192           0 : short MacroChooser::Execute()
     193             : {
     194           0 :     RestoreMacroDescription();
     195           0 :     m_pRunButton->GrabFocus();
     196             : 
     197             :     // #104198 Check if "wrong" document is active
     198           0 :     SvTreeListEntry* pSelectedEntry = m_pBasicBox->GetCurEntry();
     199           0 :     EntryDescriptor aDesc( m_pBasicBox->GetEntryDescriptor( pSelectedEntry ) );
     200           0 :     const ScriptDocument& rSelectedDoc( aDesc.GetDocument() );
     201             : 
     202             :     // App Basic is always ok, so only check if shell was found
     203           0 :     if( rSelectedDoc.isDocument() && !rSelectedDoc.isActive() )
     204             :     {
     205             :         // Search for the right entry
     206           0 :         sal_uLong nRootPos = 0;
     207           0 :         SvTreeListEntry* pRootEntry = m_pBasicBox->GetEntry( nRootPos );
     208           0 :         while( pRootEntry )
     209             :         {
     210           0 :             EntryDescriptor aCmpDesc( m_pBasicBox->GetEntryDescriptor( pRootEntry ) );
     211           0 :             const ScriptDocument& rCmpDoc( aCmpDesc.GetDocument() );
     212           0 :             if ( rCmpDoc.isDocument() && rCmpDoc.isActive() )
     213             :             {
     214           0 :                 SvTreeListEntry* pEntry = pRootEntry;
     215           0 :                 SvTreeListEntry* pLastValid = pEntry;
     216           0 :                 while ( pEntry )
     217             :                 {
     218           0 :                     pLastValid = pEntry;
     219           0 :                     pEntry = m_pBasicBox->FirstChild( pEntry );
     220             :                 }
     221           0 :                 if( pLastValid )
     222           0 :                     m_pBasicBox->SetCurEntry( pLastValid );
     223             :             }
     224           0 :             pRootEntry = m_pBasicBox->GetEntry( ++nRootPos );
     225           0 :         }
     226             :     }
     227             : 
     228           0 :     CheckButtons();
     229           0 :     UpdateFields();
     230             : 
     231           0 :     if ( StarBASIC::IsRunning() )
     232           0 :         m_pCloseButton->GrabFocus();
     233             : 
     234           0 :     Window* pPrevDlgParent = Application::GetDefDialogParent();
     235           0 :     Application::SetDefDialogParent( this );
     236           0 :     short nRet = ModalDialog::Execute();
     237             :     // #57314# If the BasicIDE has been activated, don't reset the DefModalDialogParent to the inactive document.
     238           0 :     if ( Application::GetDefDialogParent() == this )
     239           0 :         Application::SetDefDialogParent( pPrevDlgParent );
     240           0 :     return nRet;
     241             : }
     242             : 
     243             : 
     244           0 : void MacroChooser::EnableButton( Button& rButton, bool bEnable )
     245             : {
     246           0 :     if ( bEnable )
     247             :     {
     248           0 :         if (nMode == ChooseOnly || nMode == Recording)
     249           0 :             rButton.Enable(&rButton == m_pRunButton);
     250             :         else
     251           0 :             rButton.Enable();
     252             :     }
     253             :     else
     254           0 :         rButton.Disable();
     255           0 : }
     256             : 
     257             : 
     258             : 
     259             : 
     260           0 : SbMethod* MacroChooser::GetMacro()
     261             : {
     262           0 :     SbMethod* pMethod = 0;
     263           0 :     SbModule* pModule = m_pBasicBox->FindModule( m_pBasicBox->GetCurEntry() );
     264           0 :     if ( pModule )
     265             :     {
     266           0 :         SvTreeListEntry* pEntry = m_pMacroBox->FirstSelected();
     267           0 :         if ( pEntry )
     268             :         {
     269           0 :             OUString aMacroName( m_pMacroBox->GetEntryText( pEntry ) );
     270           0 :             pMethod = (SbMethod*)pModule->GetMethods()->Find( aMacroName, SbxCLASS_METHOD );
     271             :         }
     272             :     }
     273           0 :     return pMethod;
     274             : }
     275             : 
     276             : 
     277             : 
     278           0 : void MacroChooser::DeleteMacro()
     279             : {
     280           0 :     SbMethod* pMethod = GetMacro();
     281             :     DBG_ASSERT( pMethod, "DeleteMacro: Kein Macro !" );
     282           0 :     if ( pMethod && QueryDelMacro( pMethod->GetName(), this ) )
     283             :     {
     284           0 :         if (SfxDispatcher* pDispatcher = GetDispatcher())
     285           0 :             pDispatcher->Execute( SID_BASICIDE_STOREALLMODULESOURCES );
     286             : 
     287             :         // mark current doc as modified:
     288           0 :         StarBASIC* pBasic = FindBasic(pMethod);
     289             :         DBG_ASSERT( pBasic, "Basic?!" );
     290           0 :         BasicManager* pBasMgr = FindBasicManager( pBasic );
     291             :         DBG_ASSERT( pBasMgr, "BasMgr?" );
     292           0 :         ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
     293           0 :         if ( aDocument.isDocument() )
     294             :         {
     295           0 :             aDocument.setDocumentModified();
     296           0 :             if (SfxBindings* pBindings = GetBindingsPtr())
     297           0 :                 pBindings->Invalidate( SID_SAVEDOC );
     298             :         }
     299             : 
     300           0 :         SbModule* pModule = pMethod->GetModule();
     301             :         DBG_ASSERT( pModule, "DeleteMacro: Kein Modul?!" );
     302           0 :         OUString aSource( pModule->GetSource32() );
     303             :         sal_uInt16 nStart, nEnd;
     304           0 :         pMethod->GetLineRange( nStart, nEnd );
     305           0 :         pModule->GetMethods()->Remove( pMethod );
     306           0 :         CutLines( aSource, nStart-1, nEnd-nStart+1, true );
     307           0 :         pModule->SetSource32( aSource );
     308             : 
     309             :         // update module in library
     310           0 :         OUString aLibName = pBasic->GetName();
     311           0 :         OUString aModName = pModule->GetName();
     312           0 :         OSL_VERIFY( aDocument.updateModule( aLibName, aModName, aSource ) );
     313             : 
     314           0 :         SvTreeListEntry* pEntry = m_pMacroBox->FirstSelected();
     315             :         DBG_ASSERT( pEntry, "DeleteMacro: Entry ?!" );
     316           0 :         m_pMacroBox->GetModel()->Remove( pEntry );
     317           0 :         bForceStoreBasic = true;
     318             :     }
     319           0 : }
     320             : 
     321           0 : SbMethod* MacroChooser::CreateMacro()
     322             : {
     323           0 :     SbMethod* pMethod = 0;
     324           0 :     SvTreeListEntry* pCurEntry = m_pBasicBox->GetCurEntry();
     325           0 :     EntryDescriptor aDesc = m_pBasicBox->GetEntryDescriptor(pCurEntry);
     326           0 :     ScriptDocument aDocument( aDesc.GetDocument() );
     327             :     OSL_ENSURE( aDocument.isAlive(), "MacroChooser::CreateMacro: no document!" );
     328           0 :     if ( !aDocument.isAlive() )
     329           0 :         return NULL;
     330             : 
     331           0 :     OUString aLibName( aDesc.GetLibName() );
     332             : 
     333           0 :     if ( aLibName.isEmpty() )
     334           0 :         aLibName = "Standard" ;
     335             : 
     336           0 :     aDocument.getOrCreateLibrary( E_SCRIPTS, aLibName );
     337             : 
     338           0 :     OUString aOULibName( aLibName );
     339           0 :     Reference< script::XLibraryContainer > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ) );
     340           0 :     if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && !xModLibContainer->isLibraryLoaded( aOULibName ) )
     341           0 :         xModLibContainer->loadLibrary( aOULibName );
     342           0 :     Reference< script::XLibraryContainer > xDlgLibContainer( aDocument.getLibraryContainer( E_DIALOGS ) );
     343           0 :     if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && !xDlgLibContainer->isLibraryLoaded( aOULibName ) )
     344           0 :         xDlgLibContainer->loadLibrary( aOULibName );
     345             : 
     346           0 :     BasicManager* pBasMgr = aDocument.getBasicManager();
     347           0 :     StarBASIC* pBasic = pBasMgr ? pBasMgr->GetLib( aLibName ) : 0;
     348           0 :     if ( pBasic )
     349             :     {
     350           0 :         SbModule* pModule = 0;
     351           0 :         OUString aModName( aDesc.GetName() );
     352           0 :         if ( !aModName.isEmpty() )
     353             :         {
     354             :             // extract the module name from the string like "Sheet1 (Example1)"
     355           0 :             if( aDesc.GetLibSubName() == IDE_RESSTR(RID_STR_DOCUMENT_OBJECTS) )
     356             :             {
     357           0 :                 sal_Int32 nIndex = 0;
     358           0 :                 aModName = aModName.getToken( 0, ' ', nIndex );
     359             :             }
     360           0 :             pModule = pBasic->FindModule( aModName );
     361             :         }
     362           0 :         else if ( pBasic->GetModules()->Count() )
     363           0 :             pModule = (SbModule*)pBasic->GetModules()->Get( 0 );
     364             : 
     365           0 :         if ( !pModule )
     366             :         {
     367             :             pModule = createModImpl( static_cast<Window*>( this ),
     368           0 :                 aDocument, *m_pBasicBox, aLibName, aModName );
     369             :         }
     370             : 
     371           0 :         OUString aSubName = m_pMacroNameEdit->GetText();
     372             :         DBG_ASSERT( !pModule || !pModule->GetMethods()->Find( aSubName, SbxCLASS_METHOD ), "Macro existiert schon!" );
     373           0 :         pMethod = pModule ? basctl::CreateMacro( pModule, aSubName ) : NULL;
     374             :     }
     375             : 
     376           0 :     return pMethod;
     377             : }
     378             : 
     379           0 : void MacroChooser::SaveSetCurEntry( SvTreeListBox& rBox, SvTreeListEntry* pEntry )
     380             : {
     381             :     // the edit would be killed by the highlight otherwise:
     382             : 
     383           0 :     OUString aSaveText( m_pMacroNameEdit->GetText() );
     384           0 :     Selection aCurSel( m_pMacroNameEdit->GetSelection() );
     385             : 
     386           0 :     rBox.SetCurEntry( pEntry );
     387           0 :     m_pMacroNameEdit->SetText( aSaveText );
     388           0 :     m_pMacroNameEdit->SetSelection( aCurSel );
     389           0 : }
     390             : 
     391           0 : void MacroChooser::CheckButtons()
     392             : {
     393           0 :     SvTreeListEntry* pCurEntry = m_pBasicBox->GetCurEntry();
     394           0 :     EntryDescriptor aDesc = m_pBasicBox->GetEntryDescriptor(pCurEntry);
     395           0 :     SvTreeListEntry* pMacroEntry = m_pMacroBox->FirstSelected();
     396           0 :     SbMethod* pMethod = GetMacro();
     397             : 
     398             :     // check, if corresponding libraries are readonly
     399           0 :     bool bReadOnly = false;
     400           0 :     sal_uInt16 nDepth = pCurEntry ? m_pBasicBox->GetModel()->GetDepth( pCurEntry ) : 0;
     401           0 :     if ( nDepth == 1 || nDepth == 2 )
     402             :     {
     403           0 :         ScriptDocument aDocument( aDesc.GetDocument() );
     404           0 :         OUString aOULibName( aDesc.GetLibName() );
     405           0 :         Reference< script::XLibraryContainer2 > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
     406           0 :         Reference< script::XLibraryContainer2 > xDlgLibContainer( aDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY );
     407           0 :         if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryReadOnly( aOULibName ) ) ||
     408           0 :                 ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && xDlgLibContainer->isLibraryReadOnly( aOULibName ) ) )
     409             :         {
     410           0 :             bReadOnly = true;
     411           0 :         }
     412             :     }
     413             : 
     414           0 :     if (nMode != Recording)
     415             :     {
     416             :         // Run...
     417           0 :         bool bEnable = pMethod ? true : false;
     418           0 :         if (nMode != ChooseOnly && StarBASIC::IsRunning())
     419           0 :             bEnable = false;
     420           0 :         EnableButton(*m_pRunButton, bEnable);
     421             :     }
     422             : 
     423             :     // organising still possible?
     424             : 
     425             :     // Assign...
     426           0 :     EnableButton(*m_pAssignButton, pMethod ? true : false);
     427             : 
     428             :     // Edit...
     429           0 :     EnableButton(*m_pEditButton, pMacroEntry ? true : false);
     430             : 
     431             :     // Organizer...
     432           0 :     EnableButton(*m_pOrganizeButton, !StarBASIC::IsRunning() && nMode == All);
     433             : 
     434             :     // m_pDelButton->...
     435           0 :     bool bProtected = m_pBasicBox->IsEntryProtected( pCurEntry );
     436           0 :     bool bShare = ( aDesc.GetLocation() == LIBRARY_LOCATION_SHARE );
     437           0 :     EnableButton(*m_pDelButton, !StarBASIC::IsRunning() && nMode == All && !bProtected && !bReadOnly && !bShare);
     438           0 :     bool bPrev = bNewDelIsDel;
     439           0 :     bNewDelIsDel = pMethod ? true : false;
     440           0 :     if (bPrev != bNewDelIsDel && nMode == All)
     441             :     {
     442           0 :         OUString aBtnText( bNewDelIsDel ? IDEResId(RID_STR_BTNDEL).toString() : IDEResId(RID_STR_BTNNEW).toString() );
     443           0 :         m_pDelButton->SetText( aBtnText );
     444             :     }
     445             : 
     446           0 :     if (nMode == Recording)
     447             :     {
     448             :         // save button
     449           0 :         m_pRunButton->Enable(!bProtected && !bReadOnly && !bShare);
     450             :         // new library button
     451           0 :         m_pNewLibButton->Enable(!bShare);
     452             :         // new module button
     453           0 :         m_pNewModButton->Enable(!bProtected && !bReadOnly && !bShare);
     454           0 :     }
     455           0 : }
     456             : 
     457             : 
     458             : 
     459           0 : IMPL_LINK_NOARG_INLINE_START(MacroChooser, MacroDoubleClickHdl)
     460             : {
     461           0 :     StoreMacroDescription();
     462           0 :     if (nMode == Recording)
     463             :     {
     464           0 :         SbMethod* pMethod = GetMacro();
     465           0 :         if ( pMethod && !QueryReplaceMacro( pMethod->GetName(), this ) )
     466           0 :             return 0;
     467             :     }
     468             : 
     469           0 :     EndDialog(Macro_OkRun);
     470           0 :     return 0;
     471             : }
     472           0 : IMPL_LINK_NOARG_INLINE_END(MacroChooser, MacroDoubleClickHdl)
     473             : 
     474           0 : IMPL_LINK( MacroChooser, MacroSelectHdl, SvTreeListBox *, pBox )
     475             : {
     476             :     // Is also called if deselected!
     477             :     // Two function calls in every SelectHdl because
     478             :     // there's no separate DeselectHDL.
     479             :     // So find out if select or deselect:
     480           0 :     if ( pBox->IsSelected( pBox->GetHdlEntry() ) )
     481             :     {
     482           0 :         UpdateFields();
     483           0 :         CheckButtons();
     484             :     }
     485           0 :     return 0;
     486             : }
     487             : 
     488           0 : IMPL_LINK( MacroChooser, BasicSelectHdl, SvTreeListBox *, pBox )
     489             : {
     490             :     // Is also called if deselected!
     491             :     // Two function calls in every SelectHdl because
     492             :     // there's no separate DeselectHDL.
     493             :     // So find out if select or deselect:
     494           0 :     if ( !pBox->IsSelected( pBox->GetHdlEntry() ) )
     495           0 :         return 0;
     496             : 
     497           0 :     SbModule* pModule = m_pBasicBox->FindModule( m_pBasicBox->GetCurEntry() );
     498             : 
     499           0 :     m_pMacroBox->Clear();
     500           0 :     if ( pModule )
     501             :     {
     502           0 :         OUString aStr = m_aMacrosInTxtBaseStr;
     503           0 :         aStr += " " ;
     504           0 :         aStr += pModule->GetName();
     505             : 
     506           0 :         m_pMacrosInTxt->SetText( aStr );
     507             : 
     508             :         // The macros should be called in the same order that they
     509             :         // are written down in the module.
     510             : 
     511           0 :         map< sal_uInt16, SbMethod* > aMacros;
     512           0 :         size_t nMacroCount = pModule->GetMethods()->Count();
     513           0 :         for ( size_t iMeth = 0; iMeth  < nMacroCount; iMeth++ )
     514             :         {
     515           0 :             SbMethod* pMethod = (SbMethod*)pModule->GetMethods()->Get( iMeth );
     516           0 :             if( pMethod->IsHidden() )
     517           0 :                 continue;
     518             :             DBG_ASSERT( pMethod, "Methode nicht gefunden! (NULL)" );
     519             :             sal_uInt16 nStart, nEnd;
     520           0 :             pMethod->GetLineRange( nStart, nEnd );
     521           0 :             aMacros.insert( map< sal_uInt16, SbMethod*>::value_type( nStart, pMethod ) );
     522             :         }
     523             : 
     524           0 :         m_pMacroBox->SetUpdateMode(false);
     525           0 :         for ( map< sal_uInt16, SbMethod* >::iterator it = aMacros.begin(); it != aMacros.end(); ++it )
     526           0 :             m_pMacroBox->InsertEntry( (*it).second->GetName() );
     527           0 :         m_pMacroBox->SetUpdateMode(true);
     528             : 
     529           0 :         if ( m_pMacroBox->GetEntryCount() )
     530             :         {
     531           0 :             SvTreeListEntry* pEntry = m_pMacroBox->GetEntry( 0 );
     532             :             DBG_ASSERT( pEntry, "Entry ?!" );
     533           0 :             m_pMacroBox->SetCurEntry( pEntry );
     534           0 :         }
     535             :     }
     536             : 
     537           0 :     UpdateFields();
     538           0 :     CheckButtons();
     539           0 :     return 0;
     540             : }
     541             : 
     542             : 
     543             : 
     544           0 : IMPL_LINK( MacroChooser, EditModifyHdl, Edit *, pEdit )
     545             : {
     546             :     (void)pEdit;
     547             : 
     548             :     // select the module in which the macro is put at Neu (new),
     549             :     // if BasicManager or Lib is selecting
     550           0 :     SvTreeListEntry* pCurEntry = m_pBasicBox->GetCurEntry();
     551           0 :     if ( pCurEntry )
     552             :     {
     553           0 :         sal_uInt16 nDepth = m_pBasicBox->GetModel()->GetDepth( pCurEntry );
     554           0 :         if ( ( nDepth == 1 ) && ( m_pBasicBox->IsEntryProtected( pCurEntry ) ) )
     555             :         {
     556             :             // then put to the respective Std-Lib...
     557           0 :             SvTreeListEntry* pManagerEntry = m_pBasicBox->GetModel()->GetParent( pCurEntry );
     558           0 :             pCurEntry = m_pBasicBox->GetModel()->FirstChild( pManagerEntry );
     559             :         }
     560           0 :         if ( nDepth < 2 )
     561             :         {
     562           0 :             SvTreeListEntry* pNewEntry = pCurEntry;
     563           0 :             while ( pCurEntry && ( nDepth < 2 ) )
     564             :             {
     565           0 :                 pCurEntry = m_pBasicBox->FirstChild( pCurEntry );
     566           0 :                 if ( pCurEntry )
     567             :                 {
     568           0 :                     pNewEntry = pCurEntry;
     569           0 :                     nDepth = m_pBasicBox->GetModel()->GetDepth( pCurEntry );
     570             :                 }
     571             :             }
     572           0 :             SaveSetCurEntry( *m_pBasicBox, pNewEntry );
     573             :         }
     574           0 :         if ( m_pMacroBox->GetEntryCount() )
     575             :         {
     576           0 :             OUString aEdtText( m_pMacroNameEdit->GetText() );
     577           0 :             bool bFound = false;
     578           0 :             for ( sal_uInt16 n = 0; n < m_pMacroBox->GetEntryCount(); n++ )
     579             :             {
     580           0 :                 SvTreeListEntry* pEntry = m_pMacroBox->GetEntry( n );
     581             :                 DBG_ASSERT( pEntry, "Entry ?!" );
     582           0 :                 if ( m_pMacroBox->GetEntryText( pEntry ).equalsIgnoreAsciiCase( aEdtText ) )
     583             :                 {
     584           0 :                     SaveSetCurEntry(*m_pMacroBox, pEntry);
     585           0 :                     bFound = true;
     586           0 :                     break;
     587             :                 }
     588             :             }
     589           0 :             if ( !bFound )
     590             :             {
     591           0 :                 SvTreeListEntry* pEntry = m_pMacroBox->FirstSelected();
     592             :                 // if the entry exists ->Select ->Desription...
     593           0 :                 if ( pEntry )
     594           0 :                     m_pMacroBox->Select( pEntry, false );
     595           0 :             }
     596             :         }
     597             :     }
     598             : 
     599           0 :     CheckButtons();
     600           0 :     return 0;
     601             : }
     602             : 
     603             : 
     604             : 
     605           0 : IMPL_LINK( MacroChooser, ButtonHdl, Button *, pButton )
     606             : {
     607             :     // apart from New/Record the Description is done by LoseFocus
     608           0 :     if (pButton == m_pRunButton)
     609             :     {
     610           0 :         StoreMacroDescription();
     611             : 
     612             :         // #116444# check security settings before macro execution
     613           0 :         if (nMode == All)
     614             :         {
     615           0 :             SbMethod* pMethod = GetMacro();
     616           0 :             SbModule* pModule = pMethod ? pMethod->GetModule() : NULL;
     617           0 :             StarBASIC* pBasic = pModule ? (StarBASIC*)pModule->GetParent() : NULL;
     618           0 :             BasicManager* pBasMgr = pBasic ? FindBasicManager(pBasic) : NULL;
     619           0 :             if ( pBasMgr )
     620             :             {
     621           0 :                 ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
     622           0 :                 if ( aDocument.isDocument() && !aDocument.allowMacros() )
     623             :                 {
     624           0 :                     WarningBox( this, WB_OK, IDEResId(RID_STR_CANNOTRUNMACRO).toString() ).Execute();
     625           0 :                     return 0;
     626           0 :                 }
     627             :             }
     628             :         }
     629           0 :         else if (nMode == Recording )
     630             :         {
     631           0 :             if ( !IsValidSbxName(m_pMacroNameEdit->GetText()) )
     632             :             {
     633           0 :                 ErrorBox( this, WB_OK | WB_DEF_OK, IDEResId(RID_STR_BADSBXNAME).toString() ).Execute();
     634           0 :                 m_pMacroNameEdit->SetSelection( Selection( 0, m_pMacroNameEdit->GetText().getLength() ) );
     635           0 :                 m_pMacroNameEdit->GrabFocus();
     636           0 :                 return 0;
     637             :             }
     638             : 
     639           0 :             SbMethod* pMethod = GetMacro();
     640           0 :             if ( pMethod && !QueryReplaceMacro( pMethod->GetName(), this ) )
     641           0 :                 return 0;
     642             :         }
     643             : 
     644           0 :         EndDialog(Macro_OkRun);
     645             :     }
     646           0 :     else if (pButton == m_pCloseButton)
     647             :     {
     648           0 :         StoreMacroDescription();
     649           0 :         EndDialog(Macro_Close);
     650             :     }
     651           0 :     else if ((pButton == m_pEditButton) || (pButton == m_pDelButton))
     652             :     {
     653           0 :         SvTreeListEntry* pCurEntry = m_pBasicBox->GetCurEntry();
     654           0 :         EntryDescriptor aDesc = m_pBasicBox->GetEntryDescriptor(pCurEntry);
     655           0 :         ScriptDocument aDocument( aDesc.GetDocument() );
     656             :         DBG_ASSERT( aDocument.isAlive(), "MacroChooser::ButtonHdl: no document, or document is dead!" );
     657           0 :         if ( !aDocument.isAlive() )
     658           0 :             return 0;
     659           0 :         BasicManager* pBasMgr = aDocument.getBasicManager();
     660           0 :         OUString aLib( aDesc.GetLibName() );
     661           0 :         OUString aMod( aDesc.GetName() );
     662             :         // extract the module name from the string like "Sheet1 (Example1)"
     663           0 :         if( aDesc.GetLibSubName() == IDE_RESSTR(RID_STR_DOCUMENT_OBJECTS) )
     664             :         {
     665           0 :             sal_Int32 nIndex = 0;
     666           0 :             aMod = aMod.getToken( 0, ' ', nIndex );
     667             :         }
     668           0 :         OUString aSub( aDesc.GetMethodName() );
     669           0 :         SfxMacroInfoItem aInfoItem( SID_BASICIDE_ARG_MACROINFO, pBasMgr, aLib, aMod, aSub, OUString() );
     670           0 :         if (pButton == m_pEditButton)
     671             :         {
     672           0 :             SvTreeListEntry* pEntry = m_pMacroBox->FirstSelected();
     673           0 :             if ( pEntry )
     674           0 :                 aInfoItem.SetMethod( m_pMacroBox->GetEntryText( pEntry ) );
     675           0 :             StoreMacroDescription();
     676           0 :             SfxAllItemSet aArgs( SFX_APP()->GetPool() );
     677           0 :             SfxRequest aRequest( SID_BASICIDE_APPEAR, SFX_CALLMODE_SYNCHRON, aArgs );
     678           0 :             SFX_APP()->ExecuteSlot( aRequest );
     679             : 
     680           0 :             if (SfxDispatcher* pDispatcher = GetDispatcher())
     681           0 :                 pDispatcher->Execute( SID_BASICIDE_EDITMACRO, SFX_CALLMODE_ASYNCHRON, &aInfoItem, 0L );
     682           0 :             EndDialog(Macro_Edit);
     683             :         }
     684             :         else
     685             :         {
     686           0 :             if ( bNewDelIsDel )
     687             :             {
     688           0 :                 DeleteMacro();
     689           0 :                 if (SfxDispatcher* pDispatcher = GetDispatcher())
     690             :                     pDispatcher->Execute( SID_BASICIDE_UPDATEMODULESOURCE,
     691           0 :                                           SFX_CALLMODE_SYNCHRON, &aInfoItem, 0L );
     692           0 :                 CheckButtons();
     693           0 :                 UpdateFields();
     694             :                 //if ( m_pMacroBox->GetCurEntry() )    // OV-Bug ?
     695             :                 //  m_pMacroBox->Select( m_pMacroBox->GetCurEntry() );
     696             :             }
     697             :             else
     698             :             {
     699           0 :                 if ( !IsValidSbxName(m_pMacroNameEdit->GetText()) )
     700             :                 {
     701           0 :                     ErrorBox( this, WB_OK | WB_DEF_OK, IDEResId(RID_STR_BADSBXNAME).toString() ).Execute();
     702           0 :                     m_pMacroNameEdit->SetSelection( Selection( 0, m_pMacroNameEdit->GetText().getLength() ) );
     703           0 :                     m_pMacroNameEdit->GrabFocus();
     704           0 :                     return 1;
     705             :                 }
     706           0 :                 SbMethod* pMethod = CreateMacro();
     707           0 :                 if ( pMethod )
     708             :                 {
     709           0 :                     aInfoItem.SetMethod( pMethod->GetName() );
     710           0 :                     aInfoItem.SetModule( pMethod->GetModule()->GetName() );
     711           0 :                     aInfoItem.SetLib( pMethod->GetModule()->GetParent()->GetName() );
     712           0 :                     SfxAllItemSet aArgs( SFX_APP()->GetPool() );
     713           0 :                     SfxRequest aRequest( SID_BASICIDE_APPEAR, SFX_CALLMODE_SYNCHRON, aArgs );
     714           0 :                     SFX_APP()->ExecuteSlot( aRequest );
     715             : 
     716           0 :                     if (SfxDispatcher* pDispatcher = GetDispatcher())
     717           0 :                         pDispatcher->Execute( SID_BASICIDE_EDITMACRO, SFX_CALLMODE_ASYNCHRON, &aInfoItem, 0L );
     718           0 :                     StoreMacroDescription();
     719           0 :                     EndDialog(Macro_New);
     720             :                 }
     721             :             }
     722           0 :         }
     723             :     }
     724           0 :     else if (pButton == m_pAssignButton)
     725             :     {
     726           0 :         SvTreeListEntry* pCurEntry = m_pBasicBox->GetCurEntry();
     727           0 :         EntryDescriptor aDesc = m_pBasicBox->GetEntryDescriptor(pCurEntry);
     728           0 :         ScriptDocument aDocument( aDesc.GetDocument() );
     729             :         DBG_ASSERT( aDocument.isAlive(), "MacroChooser::ButtonHdl: no document, or document is dead!" );
     730           0 :         if ( !aDocument.isAlive() )
     731           0 :             return 0;
     732           0 :         BasicManager* pBasMgr = aDocument.getBasicManager();
     733           0 :         OUString aLib( aDesc.GetLibName() );
     734           0 :         OUString aMod( aDesc.GetName() );
     735           0 :         OUString aSub( m_pMacroNameEdit->GetText() );
     736           0 :         SbMethod* pMethod = GetMacro();
     737             :         DBG_ASSERT( pBasMgr, "BasMgr?" );
     738             :         DBG_ASSERT( pMethod, "Method?" );
     739           0 :         OUString aComment( GetInfo( pMethod ) );
     740           0 :         SfxMacroInfoItem aItem( SID_MACROINFO, pBasMgr, aLib, aMod, aSub, aComment );
     741           0 :         SfxAllItemSet Args( SFX_APP()->GetPool() );
     742           0 :         SfxRequest aRequest( SID_CONFIG, SFX_CALLMODE_SYNCHRON, Args );
     743           0 :         aRequest.AppendItem( aItem );
     744           0 :         SFX_APP()->ExecuteSlot( aRequest );
     745             :     }
     746           0 :     else if (pButton == m_pNewLibButton)
     747             :     {
     748           0 :         SvTreeListEntry* pCurEntry = m_pBasicBox->GetCurEntry();
     749           0 :         EntryDescriptor aDesc = m_pBasicBox->GetEntryDescriptor(pCurEntry);
     750           0 :         ScriptDocument aDocument( aDesc.GetDocument() );
     751           0 :         createLibImpl( static_cast<Window*>( this ), aDocument, NULL, m_pBasicBox );
     752             :     }
     753           0 :     else if (pButton == m_pNewModButton)
     754             :     {
     755           0 :         SvTreeListEntry* pCurEntry = m_pBasicBox->GetCurEntry();
     756           0 :         EntryDescriptor aDesc = m_pBasicBox->GetEntryDescriptor(pCurEntry);
     757           0 :         ScriptDocument aDocument( aDesc.GetDocument() );
     758           0 :         OUString aLibName( aDesc.GetLibName() );
     759           0 :         OUString aModName;
     760             :         createModImpl( static_cast<Window*>( this ), aDocument,
     761           0 :             *m_pBasicBox, aLibName, aModName, true );
     762             :     }
     763           0 :     else if (pButton == m_pOrganizeButton)
     764             :     {
     765           0 :         StoreMacroDescription();
     766             : 
     767           0 :         EntryDescriptor aDesc = m_pBasicBox->GetEntryDescriptor(m_pBasicBox->FirstSelected());
     768           0 :         OrganizeDialog* pDlg = new OrganizeDialog( this, 0, aDesc );
     769           0 :         sal_uInt16 nRet = pDlg->Execute();
     770           0 :         delete pDlg;
     771             : 
     772           0 :         if ( nRet ) // not only closed
     773             :         {
     774           0 :             EndDialog(Macro_Edit);
     775           0 :             return 0;
     776             :         }
     777             : 
     778           0 :         Shell* pShell = GetShell();
     779           0 :         if ( pShell && pShell->IsAppBasicModified() )
     780           0 :             bForceStoreBasic = true;
     781             : 
     782           0 :         m_pBasicBox->UpdateEntries();
     783             :     }
     784           0 :     return 0;
     785             : }
     786             : 
     787             : 
     788             : 
     789           0 : void MacroChooser::UpdateFields()
     790             : {
     791           0 :     SvTreeListEntry*    pMacroEntry = m_pMacroBox->GetCurEntry();
     792           0 :     OUString            aEmptyStr;
     793             : 
     794           0 :     m_pMacroNameEdit->SetText( aEmptyStr );
     795           0 :     if ( pMacroEntry )
     796           0 :         m_pMacroNameEdit->SetText( m_pMacroBox->GetEntryText( pMacroEntry ) );
     797           0 : }
     798             : 
     799           0 : void MacroChooser::SetMode (Mode nM)
     800             : {
     801           0 :     nMode = nM;
     802           0 :     switch (nMode)
     803             :     {
     804             :         case All:
     805             :         {
     806           0 :             m_pRunButton->SetText(IDEResId(RID_STR_RUN).toString());
     807           0 :             EnableButton(*m_pDelButton, true);
     808           0 :             EnableButton(*m_pOrganizeButton, true);
     809           0 :             break;
     810             :         }
     811             : 
     812             :         case ChooseOnly:
     813             :         {
     814           0 :             m_pRunButton->SetText(IDEResId(RID_STR_CHOOSE).toString());
     815           0 :             EnableButton(*m_pDelButton, false);
     816           0 :             EnableButton(*m_pOrganizeButton, false);
     817           0 :             break;
     818             :         }
     819             : 
     820             :         case Recording:
     821             :         {
     822           0 :             m_pRunButton->SetText(IDEResId(RID_STR_RECORD).toString());
     823           0 :             EnableButton(*m_pDelButton, false);
     824           0 :             EnableButton(*m_pOrganizeButton, false);
     825             : 
     826           0 :             m_pAssignButton->Hide();
     827           0 :             m_pEditButton->Hide();
     828           0 :             m_pDelButton->Hide();
     829           0 :             m_pOrganizeButton->Hide();
     830           0 :             m_pMacroFromTxT->Hide();
     831             : 
     832           0 :             m_pNewLibButton->Show();
     833           0 :             m_pNewModButton->Show();
     834           0 :             m_pMacrosSaveInTxt->Show();
     835             : 
     836           0 :             break;
     837             :         }
     838             :     }
     839           0 :     CheckButtons();
     840           0 : }
     841             : 
     842           0 : OUString MacroChooser::GetInfo( SbxVariable* pVar )
     843             : {
     844           0 :     OUString aComment;
     845           0 :     SbxInfoRef xInfo = pVar->GetInfo();
     846           0 :     if ( xInfo.Is() )
     847           0 :         aComment = xInfo->GetComment();
     848           0 :     return aComment;
     849             : }
     850             : 
     851             : 
     852           0 : } // namespace basctl
     853             : 
     854             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10