1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_basctl.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <memory> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <ide_pch.hxx> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <macrodlg.hxx> 37*cdf0e10cSrcweir #include <macrodlg.hrc> 38*cdf0e10cSrcweir #include <basidesh.hrc> 39*cdf0e10cSrcweir #include <basidesh.hxx> 40*cdf0e10cSrcweir #include <baside2.hrc> // ID's fuer Imagese 41*cdf0e10cSrcweir #include <basobj.hxx> 42*cdf0e10cSrcweir #include <baside3.hxx> 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir #include <iderdll.hxx> 45*cdf0e10cSrcweir #include <iderdll2.hxx> 46*cdf0e10cSrcweir #include <iderid.hxx> 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir #include <moduldlg.hxx> 49*cdf0e10cSrcweir #include <basic/sbx.hxx> 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir #include <bastypes.hxx> 52*cdf0e10cSrcweir #include <sbxitem.hxx> 53*cdf0e10cSrcweir #include <sfx2/minfitem.hxx> 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SCRIPT_XLIBRYARYCONTAINER2_HPP_ 56*cdf0e10cSrcweir #include <com/sun/star/script/XLibraryContainer2.hpp> 57*cdf0e10cSrcweir #endif 58*cdf0e10cSrcweir #include <com/sun/star/document/MacroExecMode.hpp> 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir using namespace ::com::sun::star; 61*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir DECLARE_LIST( MacroList, SbMethod* ) 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir MacroChooser::MacroChooser( Window* pParnt, sal_Bool bCreateEntries ) : 67*cdf0e10cSrcweir SfxModalDialog( pParnt, IDEResId( RID_MACROCHOOSER ) ), 68*cdf0e10cSrcweir aMacroNameTxt( this, IDEResId( RID_TXT_MACRONAME ) ), 69*cdf0e10cSrcweir aMacroNameEdit( this, IDEResId( RID_ED_MACRONAME ) ), 70*cdf0e10cSrcweir aMacroFromTxT( this, IDEResId( RID_TXT_MACROFROM ) ), 71*cdf0e10cSrcweir aMacrosSaveInTxt( this, IDEResId( RID_TXT_SAVEMACRO ) ), 72*cdf0e10cSrcweir aBasicBox( this, IDEResId( RID_CTRL_LIB ) ), 73*cdf0e10cSrcweir aMacrosInTxt( this, IDEResId( RID_TXT_MACROSIN ) ), 74*cdf0e10cSrcweir aMacroBox( this, IDEResId( RID_CTRL_MACRO ) ), 75*cdf0e10cSrcweir aRunButton( this, IDEResId( RID_PB_RUN ) ), 76*cdf0e10cSrcweir aCloseButton( this, IDEResId( RID_PB_CLOSE ) ), 77*cdf0e10cSrcweir aAssignButton( this, IDEResId( RID_PB_ASSIGN ) ), 78*cdf0e10cSrcweir aEditButton( this, IDEResId( RID_PB_EDIT ) ), 79*cdf0e10cSrcweir aNewDelButton( this, IDEResId( RID_PB_DEL ) ), 80*cdf0e10cSrcweir aOrganizeButton( this, IDEResId( RID_PB_ORG ) ), 81*cdf0e10cSrcweir aHelpButton( this, IDEResId( RID_PB_HELP ) ), 82*cdf0e10cSrcweir aNewLibButton( this, IDEResId( RID_PB_NEWLIB ) ), 83*cdf0e10cSrcweir aNewModButton( this, IDEResId( RID_PB_NEWMOD ) ) 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir FreeResource(); 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir nMode = MACROCHOOSER_ALL; 88*cdf0e10cSrcweir bNewDelIsDel = sal_True; 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir // Der Sfx fragt den BasicManager nicht, ob modified 91*cdf0e10cSrcweir // => Speichern anschmeissen, wenn Aenderung, aber kein Sprung in 92*cdf0e10cSrcweir // die BasicIDE. 93*cdf0e10cSrcweir bForceStoreBasic = sal_False; 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir aMacrosInTxtBaseStr = aMacrosInTxt.GetText(); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir aMacroBox.SetSelectionMode( SINGLE_SELECTION ); 98*cdf0e10cSrcweir aMacroBox.SetHighlightRange(); // ueber ganze Breite selektieren 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir aRunButton.SetClickHdl( LINK( this, MacroChooser, ButtonHdl ) ); 101*cdf0e10cSrcweir aCloseButton.SetClickHdl( LINK( this, MacroChooser, ButtonHdl ) ); 102*cdf0e10cSrcweir aAssignButton.SetClickHdl( LINK( this, MacroChooser, ButtonHdl ) ); 103*cdf0e10cSrcweir aEditButton.SetClickHdl( LINK( this, MacroChooser, ButtonHdl ) ); 104*cdf0e10cSrcweir aNewDelButton.SetClickHdl( LINK( this, MacroChooser, ButtonHdl ) ); 105*cdf0e10cSrcweir aOrganizeButton.SetClickHdl( LINK( this, MacroChooser, ButtonHdl ) ); 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir // Buttons only for MACROCHOOSER_RECORDING 108*cdf0e10cSrcweir aNewLibButton.SetClickHdl( LINK( this, MacroChooser, ButtonHdl ) ); 109*cdf0e10cSrcweir aNewModButton.SetClickHdl( LINK( this, MacroChooser, ButtonHdl ) ); 110*cdf0e10cSrcweir aNewLibButton.Hide(); // default 111*cdf0e10cSrcweir aNewModButton.Hide(); // default 112*cdf0e10cSrcweir aMacrosSaveInTxt.Hide(); // default 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir aMacrosInTxt.SetStyle( WB_NOMULTILINE | WB_PATHELLIPSIS ); 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir aMacroNameEdit.SetModifyHdl( LINK( this, MacroChooser, EditModifyHdl ) ); 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir aBasicBox.SetSelectHdl( LINK( this, MacroChooser, BasicSelectHdl ) ); 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir aMacroBox.SetDoubleClickHdl( LINK( this, MacroChooser, MacroDoubleClickHdl ) ); 121*cdf0e10cSrcweir aMacroBox.SetSelectHdl( LINK( this, MacroChooser, MacroSelectHdl ) ); 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir aBasicBox.SetMode( BROWSEMODE_MODULES ); 124*cdf0e10cSrcweir aBasicBox.SetStyle( WB_TABSTOP | WB_BORDER | 125*cdf0e10cSrcweir WB_HASLINES | WB_HASLINESATROOT | 126*cdf0e10cSrcweir WB_HASBUTTONS | WB_HASBUTTONSATROOT | 127*cdf0e10cSrcweir WB_HSCROLL ); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir BasicIDEShell* pIDEShell = IDE_DLL()->GetShell(); 130*cdf0e10cSrcweir SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL; 131*cdf0e10cSrcweir SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL; 132*cdf0e10cSrcweir if( pDispatcher ) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir pDispatcher->Execute( SID_BASICIDE_STOREALLMODULESOURCES ); 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir if ( bCreateEntries ) 138*cdf0e10cSrcweir aBasicBox.ScanAllEntries(); 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir MacroChooser::~MacroChooser() 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir if ( bForceStoreBasic ) 144*cdf0e10cSrcweir SFX_APP()->SaveBasicAndDialogContainer(); 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir void MacroChooser::StoreMacroDescription() 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir BasicEntryDescriptor aDesc( aBasicBox.GetEntryDescriptor( aBasicBox.FirstSelected() ) ); 150*cdf0e10cSrcweir String aMethodName; 151*cdf0e10cSrcweir SvLBoxEntry* pEntry = aMacroBox.FirstSelected(); 152*cdf0e10cSrcweir if ( pEntry ) 153*cdf0e10cSrcweir aMethodName = aMacroBox.GetEntryText( pEntry ); 154*cdf0e10cSrcweir else 155*cdf0e10cSrcweir aMethodName = aMacroNameEdit.GetText(); 156*cdf0e10cSrcweir if ( aMethodName.Len() ) 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir aDesc.SetMethodName( aMethodName ); 159*cdf0e10cSrcweir aDesc.SetType( OBJ_TYPE_METHOD ); 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir BasicIDEData* pData = IDE_DLL()->GetExtraData(); 163*cdf0e10cSrcweir if ( pData ) 164*cdf0e10cSrcweir pData->SetLastEntryDescriptor( aDesc ); 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir void MacroChooser::RestoreMacroDescription() 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir BasicEntryDescriptor aDesc; 170*cdf0e10cSrcweir BasicIDEShell* pIDEShell = IDE_DLL()->GetShell(); 171*cdf0e10cSrcweir if ( pIDEShell ) 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir IDEBaseWindow* pCurWin = pIDEShell->GetCurWindow(); 174*cdf0e10cSrcweir if ( pCurWin ) 175*cdf0e10cSrcweir aDesc = pCurWin->CreateEntryDescriptor(); 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir else 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir BasicIDEData* pData = IDE_DLL()->GetExtraData(); 180*cdf0e10cSrcweir if ( pData ) 181*cdf0e10cSrcweir aDesc = pData->GetLastEntryDescriptor(); 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir aBasicBox.SetCurrentEntry( aDesc ); 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir String aLastMacro( aDesc.GetMethodName() ); 187*cdf0e10cSrcweir if ( aLastMacro.Len() ) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir // find entry in macro box 190*cdf0e10cSrcweir SvLBoxEntry* pEntry = 0; 191*cdf0e10cSrcweir sal_uLong nPos = 0; 192*cdf0e10cSrcweir SvLBoxEntry* pE = aMacroBox.GetEntry( nPos ); 193*cdf0e10cSrcweir while ( pE ) 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir if ( aMacroBox.GetEntryText( pE ) == aLastMacro ) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir pEntry = pE; 198*cdf0e10cSrcweir break; 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir pE = aMacroBox.GetEntry( ++nPos ); 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir if ( pEntry ) 204*cdf0e10cSrcweir aMacroBox.SetCurEntry( pEntry ); 205*cdf0e10cSrcweir else 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir aMacroNameEdit.SetText( aLastMacro ); 208*cdf0e10cSrcweir aMacroNameEdit.SetSelection( Selection( 0, 0 ) ); 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir short __EXPORT MacroChooser::Execute() 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir RestoreMacroDescription(); 216*cdf0e10cSrcweir aRunButton.GrabFocus(); 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir // #104198 Check if "wrong" document is active 219*cdf0e10cSrcweir SvLBoxEntry* pSelectedEntry = aBasicBox.GetCurEntry(); 220*cdf0e10cSrcweir BasicEntryDescriptor aDesc( aBasicBox.GetEntryDescriptor( pSelectedEntry ) ); 221*cdf0e10cSrcweir const ScriptDocument& rSelectedDoc( aDesc.GetDocument() ); 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir // App Basic is always ok, so only check if shell was found 224*cdf0e10cSrcweir if( rSelectedDoc.isDocument() && !rSelectedDoc.isActive() ) 225*cdf0e10cSrcweir { 226*cdf0e10cSrcweir // Search for the right entry 227*cdf0e10cSrcweir sal_uLong nRootPos = 0; 228*cdf0e10cSrcweir SvLBoxEntry* pRootEntry = aBasicBox.GetEntry( nRootPos ); 229*cdf0e10cSrcweir while( pRootEntry ) 230*cdf0e10cSrcweir { 231*cdf0e10cSrcweir BasicEntryDescriptor aCmpDesc( aBasicBox.GetEntryDescriptor( pRootEntry ) ); 232*cdf0e10cSrcweir const ScriptDocument& rCmpDoc( aCmpDesc.GetDocument() ); 233*cdf0e10cSrcweir if ( rCmpDoc.isDocument() && rCmpDoc.isActive() ) 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir SvLBoxEntry* pEntry = pRootEntry; 236*cdf0e10cSrcweir SvLBoxEntry* pLastValid = pEntry; 237*cdf0e10cSrcweir while ( pEntry ) 238*cdf0e10cSrcweir { 239*cdf0e10cSrcweir pLastValid = pEntry; 240*cdf0e10cSrcweir pEntry = aBasicBox.FirstChild( pEntry ); 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir if( pLastValid ) 243*cdf0e10cSrcweir aBasicBox.SetCurEntry( pLastValid ); 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir pRootEntry = aBasicBox.GetEntry( ++nRootPos ); 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir CheckButtons(); 250*cdf0e10cSrcweir UpdateFields(); 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir if ( StarBASIC::IsRunning() ) 253*cdf0e10cSrcweir aCloseButton.GrabFocus(); 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir Window* pPrevDlgParent = Application::GetDefDialogParent(); 256*cdf0e10cSrcweir Application::SetDefDialogParent( this ); 257*cdf0e10cSrcweir short nRet = ModalDialog::Execute(); 258*cdf0e10cSrcweir // #57314# Wenn die BasicIDE aktiviert wurde, dann nicht den DefModalDialogParent auf das inaktive Dokument zuruecksetzen. 259*cdf0e10cSrcweir if ( Application::GetDefDialogParent() == this ) 260*cdf0e10cSrcweir Application::SetDefDialogParent( pPrevDlgParent ); 261*cdf0e10cSrcweir return nRet; 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir void MacroChooser::EnableButton( Button& rButton, sal_Bool bEnable ) 266*cdf0e10cSrcweir { 267*cdf0e10cSrcweir if ( bEnable ) 268*cdf0e10cSrcweir { 269*cdf0e10cSrcweir if ( nMode == MACROCHOOSER_CHOOSEONLY || nMode == MACROCHOOSER_RECORDING ) 270*cdf0e10cSrcweir { 271*cdf0e10cSrcweir // Nur der RunButton kann enabled werden 272*cdf0e10cSrcweir if ( &rButton == &aRunButton ) 273*cdf0e10cSrcweir rButton.Enable(); 274*cdf0e10cSrcweir else 275*cdf0e10cSrcweir rButton.Disable(); 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir else 278*cdf0e10cSrcweir rButton.Enable(); 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir else 281*cdf0e10cSrcweir rButton.Disable(); 282*cdf0e10cSrcweir } 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir SbMethod* MacroChooser::GetMacro() 288*cdf0e10cSrcweir { 289*cdf0e10cSrcweir SbMethod* pMethod = 0; 290*cdf0e10cSrcweir SbModule* pModule = aBasicBox.FindModule( aBasicBox.GetCurEntry() ); 291*cdf0e10cSrcweir if ( pModule ) 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir SvLBoxEntry* pEntry = aMacroBox.FirstSelected(); 294*cdf0e10cSrcweir if ( pEntry ) 295*cdf0e10cSrcweir { 296*cdf0e10cSrcweir String aMacroName( aMacroBox.GetEntryText( pEntry ) ); 297*cdf0e10cSrcweir pMethod = (SbMethod*)pModule->GetMethods()->Find( aMacroName, SbxCLASS_METHOD ); 298*cdf0e10cSrcweir } 299*cdf0e10cSrcweir } 300*cdf0e10cSrcweir return pMethod; 301*cdf0e10cSrcweir } 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir void MacroChooser::DeleteMacro() 306*cdf0e10cSrcweir { 307*cdf0e10cSrcweir SbMethod* pMethod = GetMacro(); 308*cdf0e10cSrcweir DBG_ASSERT( pMethod, "DeleteMacro: Kein Macro !" ); 309*cdf0e10cSrcweir if ( pMethod && QueryDelMacro( pMethod->GetName(), this ) ) 310*cdf0e10cSrcweir { 311*cdf0e10cSrcweir BasicIDEShell* pIDEShell = IDE_DLL()->GetShell(); 312*cdf0e10cSrcweir SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL; 313*cdf0e10cSrcweir SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL; 314*cdf0e10cSrcweir if( pDispatcher ) 315*cdf0e10cSrcweir { 316*cdf0e10cSrcweir pDispatcher->Execute( SID_BASICIDE_STOREALLMODULESOURCES ); 317*cdf0e10cSrcweir } 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir // Aktuelles Doc als geaendert markieren: 320*cdf0e10cSrcweir StarBASIC* pBasic = BasicIDE::FindBasic( pMethod ); 321*cdf0e10cSrcweir DBG_ASSERT( pBasic, "Basic?!" ); 322*cdf0e10cSrcweir BasicManager* pBasMgr = BasicIDE::FindBasicManager( pBasic ); 323*cdf0e10cSrcweir DBG_ASSERT( pBasMgr, "BasMgr?" ); 324*cdf0e10cSrcweir ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) ); 325*cdf0e10cSrcweir if ( aDocument.isDocument() ) // Muss ja nicht aus einem Document kommen... 326*cdf0e10cSrcweir { 327*cdf0e10cSrcweir aDocument.setDocumentModified(); 328*cdf0e10cSrcweir SfxBindings* pBindings = BasicIDE::GetBindingsPtr(); 329*cdf0e10cSrcweir if ( pBindings ) 330*cdf0e10cSrcweir pBindings->Invalidate( SID_SAVEDOC ); 331*cdf0e10cSrcweir } 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir SbModule* pModule = pMethod->GetModule(); 334*cdf0e10cSrcweir DBG_ASSERT( pModule, "DeleteMacro: Kein Modul?!" ); 335*cdf0e10cSrcweir ::rtl::OUString aSource( pModule->GetSource32() ); 336*cdf0e10cSrcweir sal_uInt16 nStart, nEnd; 337*cdf0e10cSrcweir pMethod->GetLineRange( nStart, nEnd ); 338*cdf0e10cSrcweir pModule->GetMethods()->Remove( pMethod ); 339*cdf0e10cSrcweir CutLines( aSource, nStart-1, nEnd-nStart+1, sal_True ); 340*cdf0e10cSrcweir pModule->SetSource32( aSource ); 341*cdf0e10cSrcweir 342*cdf0e10cSrcweir // update module in library 343*cdf0e10cSrcweir String aLibName = pBasic->GetName(); 344*cdf0e10cSrcweir String aModName = pModule->GetName(); 345*cdf0e10cSrcweir OSL_VERIFY( aDocument.updateModule( aLibName, aModName, aSource ) ); 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir SvLBoxEntry* pEntry = aMacroBox.FirstSelected(); 348*cdf0e10cSrcweir DBG_ASSERT( pEntry, "DeleteMacro: Entry ?!" ); 349*cdf0e10cSrcweir aMacroBox.GetModel()->Remove( pEntry ); 350*cdf0e10cSrcweir bForceStoreBasic = sal_True; 351*cdf0e10cSrcweir } 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir SbMethod* MacroChooser::CreateMacro() 355*cdf0e10cSrcweir { 356*cdf0e10cSrcweir SbMethod* pMethod = 0; 357*cdf0e10cSrcweir SvLBoxEntry* pCurEntry = aBasicBox.GetCurEntry(); 358*cdf0e10cSrcweir BasicEntryDescriptor aDesc( aBasicBox.GetEntryDescriptor( pCurEntry ) ); 359*cdf0e10cSrcweir ScriptDocument aDocument( aDesc.GetDocument() ); 360*cdf0e10cSrcweir OSL_ENSURE( aDocument.isAlive(), "MacroChooser::CreateMacro: no document!" ); 361*cdf0e10cSrcweir if ( !aDocument.isAlive() ) 362*cdf0e10cSrcweir return NULL; 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir String aLibName( aDesc.GetLibName() ); 365*cdf0e10cSrcweir 366*cdf0e10cSrcweir if ( !aLibName.Len() ) 367*cdf0e10cSrcweir aLibName = String::CreateFromAscii( "Standard" ); 368*cdf0e10cSrcweir 369*cdf0e10cSrcweir aDocument.getOrCreateLibrary( E_SCRIPTS, aLibName ); 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir ::rtl::OUString aOULibName( aLibName ); 372*cdf0e10cSrcweir Reference< script::XLibraryContainer > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ) ); 373*cdf0e10cSrcweir if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && !xModLibContainer->isLibraryLoaded( aOULibName ) ) 374*cdf0e10cSrcweir xModLibContainer->loadLibrary( aOULibName ); 375*cdf0e10cSrcweir Reference< script::XLibraryContainer > xDlgLibContainer( aDocument.getLibraryContainer( E_DIALOGS ) ); 376*cdf0e10cSrcweir if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && !xDlgLibContainer->isLibraryLoaded( aOULibName ) ) 377*cdf0e10cSrcweir xDlgLibContainer->loadLibrary( aOULibName ); 378*cdf0e10cSrcweir 379*cdf0e10cSrcweir BasicManager* pBasMgr = aDocument.getBasicManager(); 380*cdf0e10cSrcweir StarBASIC* pBasic = pBasMgr ? pBasMgr->GetLib( aLibName ) : 0; 381*cdf0e10cSrcweir if ( pBasic ) 382*cdf0e10cSrcweir { 383*cdf0e10cSrcweir SbModule* pModule = 0; 384*cdf0e10cSrcweir String aModName( aDesc.GetName() ); 385*cdf0e10cSrcweir if ( aModName.Len() ) 386*cdf0e10cSrcweir { 387*cdf0e10cSrcweir // extract the module name from the string like "Sheet1 (Example1)" 388*cdf0e10cSrcweir if( aDesc.GetLibSubName().Equals( String( IDEResId( RID_STR_DOCUMENT_OBJECTS ) ) ) ) 389*cdf0e10cSrcweir { 390*cdf0e10cSrcweir sal_uInt16 nIndex = 0; 391*cdf0e10cSrcweir aModName = aModName.GetToken( 0, ' ', nIndex ); 392*cdf0e10cSrcweir } 393*cdf0e10cSrcweir pModule = pBasic->FindModule( aModName ); 394*cdf0e10cSrcweir } 395*cdf0e10cSrcweir else if ( pBasic->GetModules()->Count() ) 396*cdf0e10cSrcweir pModule = (SbModule*)pBasic->GetModules()->Get( 0 ); 397*cdf0e10cSrcweir 398*cdf0e10cSrcweir if ( !pModule ) 399*cdf0e10cSrcweir { 400*cdf0e10cSrcweir pModule = createModImpl( static_cast<Window*>( this ), 401*cdf0e10cSrcweir aDocument, aBasicBox, aLibName, aModName ); 402*cdf0e10cSrcweir } 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir String aSubName = aMacroNameEdit.GetText(); 405*cdf0e10cSrcweir DBG_ASSERT( !pModule || !pModule->GetMethods()->Find( aSubName, SbxCLASS_METHOD ), "Macro existiert schon!" ); 406*cdf0e10cSrcweir pMethod = pModule ? BasicIDE::CreateMacro( pModule, aSubName ) : NULL; 407*cdf0e10cSrcweir } 408*cdf0e10cSrcweir 409*cdf0e10cSrcweir return pMethod; 410*cdf0e10cSrcweir } 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir void MacroChooser::SaveSetCurEntry( SvTreeListBox& rBox, SvLBoxEntry* pEntry ) 413*cdf0e10cSrcweir { 414*cdf0e10cSrcweir // Durch das Highlight wird das Edit sonst platt gemacht: 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir String aSaveText( aMacroNameEdit.GetText() ); 417*cdf0e10cSrcweir Selection aCurSel( aMacroNameEdit.GetSelection() ); 418*cdf0e10cSrcweir 419*cdf0e10cSrcweir rBox.SetCurEntry( pEntry ); 420*cdf0e10cSrcweir aMacroNameEdit.SetText( aSaveText ); 421*cdf0e10cSrcweir aMacroNameEdit.SetSelection( aCurSel ); 422*cdf0e10cSrcweir } 423*cdf0e10cSrcweir 424*cdf0e10cSrcweir void MacroChooser::CheckButtons() 425*cdf0e10cSrcweir { 426*cdf0e10cSrcweir SvLBoxEntry* pCurEntry = aBasicBox.GetCurEntry(); 427*cdf0e10cSrcweir BasicEntryDescriptor aDesc( aBasicBox.GetEntryDescriptor( pCurEntry ) ); 428*cdf0e10cSrcweir SvLBoxEntry* pMacroEntry = aMacroBox.FirstSelected(); 429*cdf0e10cSrcweir SbMethod* pMethod = GetMacro(); 430*cdf0e10cSrcweir 431*cdf0e10cSrcweir // check, if corresponding libraries are readonly 432*cdf0e10cSrcweir sal_Bool bReadOnly = sal_False; 433*cdf0e10cSrcweir sal_uInt16 nDepth = pCurEntry ? aBasicBox.GetModel()->GetDepth( pCurEntry ) : 0; 434*cdf0e10cSrcweir if ( nDepth == 1 || nDepth == 2 ) 435*cdf0e10cSrcweir { 436*cdf0e10cSrcweir ScriptDocument aDocument( aDesc.GetDocument() ); 437*cdf0e10cSrcweir ::rtl::OUString aOULibName( aDesc.GetLibName() ); 438*cdf0e10cSrcweir Reference< script::XLibraryContainer2 > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY ); 439*cdf0e10cSrcweir Reference< script::XLibraryContainer2 > xDlgLibContainer( aDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY ); 440*cdf0e10cSrcweir if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryReadOnly( aOULibName ) ) || 441*cdf0e10cSrcweir ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && xDlgLibContainer->isLibraryReadOnly( aOULibName ) ) ) 442*cdf0e10cSrcweir { 443*cdf0e10cSrcweir bReadOnly = sal_True; 444*cdf0e10cSrcweir } 445*cdf0e10cSrcweir } 446*cdf0e10cSrcweir 447*cdf0e10cSrcweir if ( nMode != MACROCHOOSER_RECORDING ) 448*cdf0e10cSrcweir { 449*cdf0e10cSrcweir // Run... 450*cdf0e10cSrcweir sal_Bool bEnable = pMethod ? sal_True : sal_False; 451*cdf0e10cSrcweir if ( ( nMode != MACROCHOOSER_CHOOSEONLY ) && StarBASIC::IsRunning() ) 452*cdf0e10cSrcweir bEnable = sal_False; 453*cdf0e10cSrcweir EnableButton( aRunButton, bEnable ); 454*cdf0e10cSrcweir } 455*cdf0e10cSrcweir 456*cdf0e10cSrcweir // Organisieren immer moeglich ? 457*cdf0e10cSrcweir 458*cdf0e10cSrcweir // Assign... 459*cdf0e10cSrcweir EnableButton( aAssignButton, pMethod ? sal_True : sal_False ); 460*cdf0e10cSrcweir 461*cdf0e10cSrcweir // Edit... 462*cdf0e10cSrcweir EnableButton( aEditButton, pMacroEntry ? sal_True : sal_False ); 463*cdf0e10cSrcweir 464*cdf0e10cSrcweir // aOrganizeButton 465*cdf0e10cSrcweir EnableButton( aOrganizeButton, !StarBASIC::IsRunning() && ( nMode == MACROCHOOSER_ALL )); 466*cdf0e10cSrcweir 467*cdf0e10cSrcweir // aNewDelButton.... 468*cdf0e10cSrcweir bool bProtected = aBasicBox.IsEntryProtected( pCurEntry ); 469*cdf0e10cSrcweir bool bShare = ( aDesc.GetLocation() == LIBRARY_LOCATION_SHARE ); 470*cdf0e10cSrcweir EnableButton( aNewDelButton, 471*cdf0e10cSrcweir !StarBASIC::IsRunning() && ( nMode == MACROCHOOSER_ALL ) && !bProtected && !bReadOnly && !bShare ); 472*cdf0e10cSrcweir sal_Bool bPrev = bNewDelIsDel; 473*cdf0e10cSrcweir bNewDelIsDel = pMethod ? sal_True : sal_False; 474*cdf0e10cSrcweir if ( ( bPrev != bNewDelIsDel ) && ( nMode == MACROCHOOSER_ALL ) ) 475*cdf0e10cSrcweir { 476*cdf0e10cSrcweir String aBtnText( bNewDelIsDel ? IDEResId( RID_STR_BTNDEL) : IDEResId( RID_STR_BTNNEW ) ); 477*cdf0e10cSrcweir aNewDelButton.SetText( aBtnText ); 478*cdf0e10cSrcweir } 479*cdf0e10cSrcweir 480*cdf0e10cSrcweir if ( nMode == MACROCHOOSER_RECORDING ) 481*cdf0e10cSrcweir { 482*cdf0e10cSrcweir // save button 483*cdf0e10cSrcweir if ( !bProtected && !bReadOnly && !bShare ) 484*cdf0e10cSrcweir aRunButton.Enable(); 485*cdf0e10cSrcweir else 486*cdf0e10cSrcweir aRunButton.Disable(); 487*cdf0e10cSrcweir 488*cdf0e10cSrcweir // new library button 489*cdf0e10cSrcweir if ( !bShare ) 490*cdf0e10cSrcweir aNewLibButton.Enable(); 491*cdf0e10cSrcweir else 492*cdf0e10cSrcweir aNewLibButton.Disable(); 493*cdf0e10cSrcweir 494*cdf0e10cSrcweir // new module button 495*cdf0e10cSrcweir if ( !bProtected && !bReadOnly && !bShare ) 496*cdf0e10cSrcweir aNewModButton.Enable(); 497*cdf0e10cSrcweir else 498*cdf0e10cSrcweir aNewModButton.Disable(); 499*cdf0e10cSrcweir } 500*cdf0e10cSrcweir } 501*cdf0e10cSrcweir 502*cdf0e10cSrcweir 503*cdf0e10cSrcweir 504*cdf0e10cSrcweir IMPL_LINK_INLINE_START( MacroChooser, MacroDoubleClickHdl, SvTreeListBox *, EMPTYARG ) 505*cdf0e10cSrcweir { 506*cdf0e10cSrcweir StoreMacroDescription(); 507*cdf0e10cSrcweir if ( nMode == MACROCHOOSER_RECORDING ) 508*cdf0e10cSrcweir { 509*cdf0e10cSrcweir SbMethod* pMethod = GetMacro(); 510*cdf0e10cSrcweir if ( pMethod && !QueryReplaceMacro( pMethod->GetName(), this ) ) 511*cdf0e10cSrcweir return 0; 512*cdf0e10cSrcweir } 513*cdf0e10cSrcweir 514*cdf0e10cSrcweir EndDialog( MACRO_OK_RUN ); 515*cdf0e10cSrcweir return 0; 516*cdf0e10cSrcweir } 517*cdf0e10cSrcweir IMPL_LINK_INLINE_END( MacroChooser, MacroDoubleClickHdl, SvTreeListBox *, EMPTYARG ) 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir IMPL_LINK( MacroChooser, MacroSelectHdl, SvTreeListBox *, pBox ) 520*cdf0e10cSrcweir { 521*cdf0e10cSrcweir // Wird auch gerufen, wenn Deselektiert! 522*cdf0e10cSrcweir // 2 Funktionsaufrufe in jedem SelectHdl, nur weil Olli 523*cdf0e10cSrcweir // keinen separatren DeselctHdl einfuehren wollte: 524*cdf0e10cSrcweir // Also: Feststellen, ob Select oder Deselect: 525*cdf0e10cSrcweir if ( pBox->IsSelected( pBox->GetHdlEntry() ) ) 526*cdf0e10cSrcweir { 527*cdf0e10cSrcweir UpdateFields(); 528*cdf0e10cSrcweir CheckButtons(); 529*cdf0e10cSrcweir } 530*cdf0e10cSrcweir return 0; 531*cdf0e10cSrcweir } 532*cdf0e10cSrcweir 533*cdf0e10cSrcweir IMPL_LINK( MacroChooser, BasicSelectHdl, SvTreeListBox *, pBox ) 534*cdf0e10cSrcweir { 535*cdf0e10cSrcweir static String aSpaceStr = String::CreateFromAscii(" "); 536*cdf0e10cSrcweir 537*cdf0e10cSrcweir // Wird auch gerufen, wenn Deselektiert! 538*cdf0e10cSrcweir // 2 Funktionsaufrufe in jedem SelectHdl, nur weil Olli 539*cdf0e10cSrcweir // keinen separatren DeselctHdl einfuehren wollte: 540*cdf0e10cSrcweir // Also: Feststellen, ob Select oder Deselect: 541*cdf0e10cSrcweir if ( !pBox->IsSelected( pBox->GetHdlEntry() ) ) 542*cdf0e10cSrcweir return 0; 543*cdf0e10cSrcweir 544*cdf0e10cSrcweir SbModule* pModule = aBasicBox.FindModule( aBasicBox.GetCurEntry() ); 545*cdf0e10cSrcweir 546*cdf0e10cSrcweir aMacroBox.Clear(); 547*cdf0e10cSrcweir if ( pModule ) 548*cdf0e10cSrcweir { 549*cdf0e10cSrcweir String aStr = aMacrosInTxtBaseStr; 550*cdf0e10cSrcweir aStr += aSpaceStr; 551*cdf0e10cSrcweir aStr += pModule->GetName(); 552*cdf0e10cSrcweir 553*cdf0e10cSrcweir aMacrosInTxt.SetText( aStr ); 554*cdf0e10cSrcweir 555*cdf0e10cSrcweir // Die Macros sollen in der Reihenfolge angezeigt werden, 556*cdf0e10cSrcweir // wie sie im Modul stehen. 557*cdf0e10cSrcweir MacroList aMacros; 558*cdf0e10cSrcweir sal_uInt16 nMacroCount = pModule->GetMethods()->Count(); 559*cdf0e10cSrcweir sal_uInt16 nRealMacroCount = 0; 560*cdf0e10cSrcweir sal_uInt16 iMeth; 561*cdf0e10cSrcweir for ( iMeth = 0; iMeth < nMacroCount; iMeth++ ) 562*cdf0e10cSrcweir { 563*cdf0e10cSrcweir SbMethod* pMethod = (SbMethod*)pModule->GetMethods()->Get( iMeth ); 564*cdf0e10cSrcweir if( pMethod->IsHidden() ) 565*cdf0e10cSrcweir continue; 566*cdf0e10cSrcweir ++nRealMacroCount; 567*cdf0e10cSrcweir DBG_ASSERT( pMethod, "Methode nicht gefunden! (NULL)" ); 568*cdf0e10cSrcweir sal_uLong nPos = LIST_APPEND; 569*cdf0e10cSrcweir // Eventuell weiter vorne ? 570*cdf0e10cSrcweir sal_uInt16 nStart, nEnd; 571*cdf0e10cSrcweir pMethod->GetLineRange( nStart, nEnd ); 572*cdf0e10cSrcweir for ( sal_uLong n = 0; n < aMacros.Count(); n++ ) 573*cdf0e10cSrcweir { 574*cdf0e10cSrcweir sal_uInt16 nS, nE; 575*cdf0e10cSrcweir SbMethod* pM = aMacros.GetObject( n ); 576*cdf0e10cSrcweir DBG_ASSERT( pM, "Macro nicht in Liste ?!" ); 577*cdf0e10cSrcweir pM->GetLineRange( nS, nE ); 578*cdf0e10cSrcweir if ( nS > nStart ) 579*cdf0e10cSrcweir { 580*cdf0e10cSrcweir nPos = n; 581*cdf0e10cSrcweir break; 582*cdf0e10cSrcweir } 583*cdf0e10cSrcweir } 584*cdf0e10cSrcweir aMacros.Insert( pMethod, nPos ); 585*cdf0e10cSrcweir } 586*cdf0e10cSrcweir 587*cdf0e10cSrcweir aMacroBox.SetUpdateMode( sal_False ); 588*cdf0e10cSrcweir for ( iMeth = 0; iMeth < nRealMacroCount; iMeth++ ) 589*cdf0e10cSrcweir aMacroBox.InsertEntry( aMacros.GetObject( iMeth )->GetName() ); 590*cdf0e10cSrcweir aMacroBox.SetUpdateMode( sal_True ); 591*cdf0e10cSrcweir 592*cdf0e10cSrcweir if ( aMacroBox.GetEntryCount() ) 593*cdf0e10cSrcweir { 594*cdf0e10cSrcweir SvLBoxEntry* pEntry = aMacroBox.GetEntry( 0 ); 595*cdf0e10cSrcweir DBG_ASSERT( pEntry, "Entry ?!" ); 596*cdf0e10cSrcweir aMacroBox.SetCurEntry( pEntry ); 597*cdf0e10cSrcweir } 598*cdf0e10cSrcweir } 599*cdf0e10cSrcweir 600*cdf0e10cSrcweir UpdateFields(); 601*cdf0e10cSrcweir CheckButtons(); 602*cdf0e10cSrcweir return 0; 603*cdf0e10cSrcweir } 604*cdf0e10cSrcweir 605*cdf0e10cSrcweir 606*cdf0e10cSrcweir 607*cdf0e10cSrcweir IMPL_LINK( MacroChooser, EditModifyHdl, Edit *, pEdit ) 608*cdf0e10cSrcweir { 609*cdf0e10cSrcweir (void)pEdit; 610*cdf0e10cSrcweir 611*cdf0e10cSrcweir // Das Modul, in dem bei Neu das Macro landet, selektieren, 612*cdf0e10cSrcweir // wenn BasicManager oder Lib selektiert. 613*cdf0e10cSrcweir SvLBoxEntry* pCurEntry = aBasicBox.GetCurEntry(); 614*cdf0e10cSrcweir if ( pCurEntry ) 615*cdf0e10cSrcweir { 616*cdf0e10cSrcweir sal_uInt16 nDepth = aBasicBox.GetModel()->GetDepth( pCurEntry ); 617*cdf0e10cSrcweir if ( ( nDepth == 1 ) && ( aBasicBox.IsEntryProtected( pCurEntry ) ) ) 618*cdf0e10cSrcweir { 619*cdf0e10cSrcweir // Dann auf die entsprechende Std-Lib stellen... 620*cdf0e10cSrcweir SvLBoxEntry* pManagerEntry = aBasicBox.GetModel()->GetParent( pCurEntry ); 621*cdf0e10cSrcweir pCurEntry = aBasicBox.GetModel()->FirstChild( pManagerEntry ); 622*cdf0e10cSrcweir } 623*cdf0e10cSrcweir if ( nDepth < 2 ) 624*cdf0e10cSrcweir { 625*cdf0e10cSrcweir SvLBoxEntry* pNewEntry = pCurEntry; 626*cdf0e10cSrcweir while ( pCurEntry && ( nDepth < 2 ) ) 627*cdf0e10cSrcweir { 628*cdf0e10cSrcweir pCurEntry = aBasicBox.FirstChild( pCurEntry ); 629*cdf0e10cSrcweir if ( pCurEntry ) 630*cdf0e10cSrcweir { 631*cdf0e10cSrcweir pNewEntry = pCurEntry; 632*cdf0e10cSrcweir nDepth = aBasicBox.GetModel()->GetDepth( pCurEntry ); 633*cdf0e10cSrcweir } 634*cdf0e10cSrcweir } 635*cdf0e10cSrcweir SaveSetCurEntry( aBasicBox, pNewEntry ); 636*cdf0e10cSrcweir } 637*cdf0e10cSrcweir if ( aMacroBox.GetEntryCount() ) 638*cdf0e10cSrcweir { 639*cdf0e10cSrcweir String aEdtText( aMacroNameEdit.GetText() ); 640*cdf0e10cSrcweir sal_Bool bFound = sal_False; 641*cdf0e10cSrcweir for ( sal_uInt16 n = 0; n < aMacroBox.GetEntryCount(); n++ ) 642*cdf0e10cSrcweir { 643*cdf0e10cSrcweir SvLBoxEntry* pEntry = aMacroBox.GetEntry( n ); 644*cdf0e10cSrcweir DBG_ASSERT( pEntry, "Entry ?!" ); 645*cdf0e10cSrcweir if ( aMacroBox.GetEntryText( pEntry ).CompareIgnoreCaseToAscii( aEdtText ) == COMPARE_EQUAL ) 646*cdf0e10cSrcweir { 647*cdf0e10cSrcweir SaveSetCurEntry( aMacroBox, pEntry ); 648*cdf0e10cSrcweir bFound = sal_True; 649*cdf0e10cSrcweir break; 650*cdf0e10cSrcweir } 651*cdf0e10cSrcweir } 652*cdf0e10cSrcweir if ( !bFound ) 653*cdf0e10cSrcweir { 654*cdf0e10cSrcweir SvLBoxEntry* pEntry = aMacroBox.FirstSelected(); 655*cdf0e10cSrcweir // Wenn es den Eintrag gibt ->Select ->Desription... 656*cdf0e10cSrcweir if ( pEntry ) 657*cdf0e10cSrcweir aMacroBox.Select( pEntry, sal_False ); 658*cdf0e10cSrcweir } 659*cdf0e10cSrcweir } 660*cdf0e10cSrcweir } 661*cdf0e10cSrcweir 662*cdf0e10cSrcweir CheckButtons(); 663*cdf0e10cSrcweir return 0; 664*cdf0e10cSrcweir } 665*cdf0e10cSrcweir 666*cdf0e10cSrcweir 667*cdf0e10cSrcweir 668*cdf0e10cSrcweir IMPL_LINK( MacroChooser, ButtonHdl, Button *, pButton ) 669*cdf0e10cSrcweir { 670*cdf0e10cSrcweir // ausser bei New/Record wird die Description durch LoseFocus uebernommen. 671*cdf0e10cSrcweir if ( pButton == &aRunButton ) 672*cdf0e10cSrcweir { 673*cdf0e10cSrcweir StoreMacroDescription(); 674*cdf0e10cSrcweir 675*cdf0e10cSrcweir // #116444# check security settings before macro execution 676*cdf0e10cSrcweir if ( nMode == MACROCHOOSER_ALL ) 677*cdf0e10cSrcweir { 678*cdf0e10cSrcweir SbMethod* pMethod = GetMacro(); 679*cdf0e10cSrcweir SbModule* pModule = pMethod ? pMethod->GetModule() : NULL; 680*cdf0e10cSrcweir StarBASIC* pBasic = pModule ? (StarBASIC*)pModule->GetParent() : NULL; 681*cdf0e10cSrcweir BasicManager* pBasMgr = pBasic ? BasicIDE::FindBasicManager( pBasic ) : NULL; 682*cdf0e10cSrcweir if ( pBasMgr ) 683*cdf0e10cSrcweir { 684*cdf0e10cSrcweir ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) ); 685*cdf0e10cSrcweir if ( aDocument.isDocument() && !aDocument.allowMacros() ) 686*cdf0e10cSrcweir { 687*cdf0e10cSrcweir WarningBox( this, WB_OK, String( IDEResId( RID_STR_CANNOTRUNMACRO ) ) ).Execute(); 688*cdf0e10cSrcweir return 0; 689*cdf0e10cSrcweir } 690*cdf0e10cSrcweir } 691*cdf0e10cSrcweir } 692*cdf0e10cSrcweir else if ( nMode == MACROCHOOSER_RECORDING ) 693*cdf0e10cSrcweir { 694*cdf0e10cSrcweir sal_Bool bValid = BasicIDE::IsValidSbxName( aMacroNameEdit.GetText() ); 695*cdf0e10cSrcweir if ( !bValid ) 696*cdf0e10cSrcweir { 697*cdf0e10cSrcweir ErrorBox( this, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_BADSBXNAME ) ) ).Execute(); 698*cdf0e10cSrcweir aMacroNameEdit.SetSelection( Selection( 0, aMacroNameEdit.GetText().Len() ) ); 699*cdf0e10cSrcweir aMacroNameEdit.GrabFocus(); 700*cdf0e10cSrcweir return 0; 701*cdf0e10cSrcweir } 702*cdf0e10cSrcweir 703*cdf0e10cSrcweir SbMethod* pMethod = GetMacro(); 704*cdf0e10cSrcweir if ( pMethod && !QueryReplaceMacro( pMethod->GetName(), this ) ) 705*cdf0e10cSrcweir return 0; 706*cdf0e10cSrcweir } 707*cdf0e10cSrcweir 708*cdf0e10cSrcweir EndDialog( MACRO_OK_RUN ); 709*cdf0e10cSrcweir } 710*cdf0e10cSrcweir else if ( pButton == &aCloseButton ) 711*cdf0e10cSrcweir { 712*cdf0e10cSrcweir StoreMacroDescription(); 713*cdf0e10cSrcweir EndDialog( MACRO_CLOSE ); 714*cdf0e10cSrcweir } 715*cdf0e10cSrcweir else if ( ( pButton == &aEditButton ) || ( pButton == &aNewDelButton ) ) 716*cdf0e10cSrcweir { 717*cdf0e10cSrcweir SvLBoxEntry* pCurEntry = aBasicBox.GetCurEntry(); 718*cdf0e10cSrcweir BasicEntryDescriptor aDesc( aBasicBox.GetEntryDescriptor( pCurEntry ) ); 719*cdf0e10cSrcweir ScriptDocument aDocument( aDesc.GetDocument() ); 720*cdf0e10cSrcweir DBG_ASSERT( aDocument.isAlive(), "MacroChooser::ButtonHdl: no document, or document is dead!" ); 721*cdf0e10cSrcweir if ( !aDocument.isAlive() ) 722*cdf0e10cSrcweir return 0; 723*cdf0e10cSrcweir BasicManager* pBasMgr = aDocument.getBasicManager(); 724*cdf0e10cSrcweir String aLib( aDesc.GetLibName() ); 725*cdf0e10cSrcweir String aMod( aDesc.GetName() ); 726*cdf0e10cSrcweir // extract the module name from the string like "Sheet1 (Example1)" 727*cdf0e10cSrcweir if( aDesc.GetLibSubName().Equals( String( IDEResId( RID_STR_DOCUMENT_OBJECTS ) ) ) ) 728*cdf0e10cSrcweir { 729*cdf0e10cSrcweir sal_uInt16 nIndex = 0; 730*cdf0e10cSrcweir aMod = aMod.GetToken( 0, ' ', nIndex ); 731*cdf0e10cSrcweir } 732*cdf0e10cSrcweir String aSub( aDesc.GetMethodName() ); 733*cdf0e10cSrcweir SfxMacroInfoItem aInfoItem( SID_BASICIDE_ARG_MACROINFO, pBasMgr, aLib, aMod, aSub, String() ); 734*cdf0e10cSrcweir if ( pButton == &aEditButton ) 735*cdf0e10cSrcweir { 736*cdf0e10cSrcweir SvLBoxEntry* pEntry = aMacroBox.FirstSelected(); 737*cdf0e10cSrcweir if ( pEntry ) 738*cdf0e10cSrcweir aInfoItem.SetMethod( aMacroBox.GetEntryText( pEntry ) ); 739*cdf0e10cSrcweir StoreMacroDescription(); 740*cdf0e10cSrcweir SfxAllItemSet aArgs( SFX_APP()->GetPool() ); 741*cdf0e10cSrcweir SfxRequest aRequest( SID_BASICIDE_APPEAR, SFX_CALLMODE_SYNCHRON, aArgs ); 742*cdf0e10cSrcweir SFX_APP()->ExecuteSlot( aRequest ); 743*cdf0e10cSrcweir 744*cdf0e10cSrcweir BasicIDEShell* pIDEShell = IDE_DLL()->GetShell(); 745*cdf0e10cSrcweir SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL; 746*cdf0e10cSrcweir SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL; 747*cdf0e10cSrcweir if( pDispatcher ) 748*cdf0e10cSrcweir pDispatcher->Execute( SID_BASICIDE_EDITMACRO, SFX_CALLMODE_ASYNCHRON, &aInfoItem, 0L ); 749*cdf0e10cSrcweir EndDialog( MACRO_EDIT ); 750*cdf0e10cSrcweir } 751*cdf0e10cSrcweir else 752*cdf0e10cSrcweir { 753*cdf0e10cSrcweir if ( bNewDelIsDel ) 754*cdf0e10cSrcweir { 755*cdf0e10cSrcweir DeleteMacro(); 756*cdf0e10cSrcweir BasicIDEShell* pIDEShell = IDE_DLL()->GetShell(); 757*cdf0e10cSrcweir SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL; 758*cdf0e10cSrcweir SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL; 759*cdf0e10cSrcweir if( pDispatcher ) 760*cdf0e10cSrcweir { 761*cdf0e10cSrcweir pDispatcher->Execute( SID_BASICIDE_UPDATEMODULESOURCE, 762*cdf0e10cSrcweir SFX_CALLMODE_SYNCHRON, &aInfoItem, 0L ); 763*cdf0e10cSrcweir } 764*cdf0e10cSrcweir CheckButtons(); 765*cdf0e10cSrcweir UpdateFields(); 766*cdf0e10cSrcweir //if ( aMacroBox.GetCurEntry() ) // OV-Bug ? 767*cdf0e10cSrcweir // aMacroBox.Select( aMacroBox.GetCurEntry() ); 768*cdf0e10cSrcweir } 769*cdf0e10cSrcweir else 770*cdf0e10cSrcweir { 771*cdf0e10cSrcweir sal_Bool bValid = BasicIDE::IsValidSbxName( aMacroNameEdit.GetText() ); 772*cdf0e10cSrcweir if ( !bValid ) 773*cdf0e10cSrcweir { 774*cdf0e10cSrcweir ErrorBox( this, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_BADSBXNAME ) ) ).Execute(); 775*cdf0e10cSrcweir aMacroNameEdit.SetSelection( Selection( 0, aMacroNameEdit.GetText().Len() ) ); 776*cdf0e10cSrcweir aMacroNameEdit.GrabFocus(); 777*cdf0e10cSrcweir return 1; 778*cdf0e10cSrcweir } 779*cdf0e10cSrcweir SbMethod* pMethod = CreateMacro(); 780*cdf0e10cSrcweir if ( pMethod ) 781*cdf0e10cSrcweir { 782*cdf0e10cSrcweir aInfoItem.SetMethod( pMethod->GetName() ); 783*cdf0e10cSrcweir aInfoItem.SetModule( pMethod->GetModule()->GetName() ); 784*cdf0e10cSrcweir aInfoItem.SetLib( pMethod->GetModule()->GetParent()->GetName() ); 785*cdf0e10cSrcweir SfxAllItemSet aArgs( SFX_APP()->GetPool() ); 786*cdf0e10cSrcweir SfxRequest aRequest( SID_BASICIDE_APPEAR, SFX_CALLMODE_SYNCHRON, aArgs ); 787*cdf0e10cSrcweir SFX_APP()->ExecuteSlot( aRequest ); 788*cdf0e10cSrcweir 789*cdf0e10cSrcweir BasicIDEShell* pIDEShell = IDE_DLL()->GetShell(); 790*cdf0e10cSrcweir SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL; 791*cdf0e10cSrcweir SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL; 792*cdf0e10cSrcweir if ( pDispatcher ) 793*cdf0e10cSrcweir pDispatcher->Execute( SID_BASICIDE_EDITMACRO, SFX_CALLMODE_ASYNCHRON, &aInfoItem, 0L ); 794*cdf0e10cSrcweir StoreMacroDescription(); 795*cdf0e10cSrcweir EndDialog( MACRO_NEW ); 796*cdf0e10cSrcweir } 797*cdf0e10cSrcweir } 798*cdf0e10cSrcweir } 799*cdf0e10cSrcweir } 800*cdf0e10cSrcweir 801*cdf0e10cSrcweir else if ( pButton == &aAssignButton ) 802*cdf0e10cSrcweir { 803*cdf0e10cSrcweir SvLBoxEntry* pCurEntry = aBasicBox.GetCurEntry(); 804*cdf0e10cSrcweir BasicEntryDescriptor aDesc( aBasicBox.GetEntryDescriptor( pCurEntry ) ); 805*cdf0e10cSrcweir ScriptDocument aDocument( aDesc.GetDocument() ); 806*cdf0e10cSrcweir DBG_ASSERT( aDocument.isAlive(), "MacroChooser::ButtonHdl: no document, or document is dead!" ); 807*cdf0e10cSrcweir if ( !aDocument.isAlive() ) 808*cdf0e10cSrcweir return 0; 809*cdf0e10cSrcweir BasicManager* pBasMgr = aDocument.getBasicManager(); 810*cdf0e10cSrcweir String aLib( aDesc.GetLibName() ); 811*cdf0e10cSrcweir String aMod( aDesc.GetName() ); 812*cdf0e10cSrcweir String aSub( aMacroNameEdit.GetText() ); 813*cdf0e10cSrcweir SbMethod* pMethod = GetMacro(); 814*cdf0e10cSrcweir DBG_ASSERT( pBasMgr, "BasMgr?" ); 815*cdf0e10cSrcweir DBG_ASSERT( pMethod, "Method?" ); 816*cdf0e10cSrcweir String aComment( GetInfo( pMethod ) ); 817*cdf0e10cSrcweir SfxMacroInfoItem aItem( SID_MACROINFO, pBasMgr, aLib, aMod, aSub, aComment ); 818*cdf0e10cSrcweir SfxAllItemSet Args( SFX_APP()->GetPool() ); 819*cdf0e10cSrcweir SfxRequest aRequest( SID_CONFIG, SFX_CALLMODE_SYNCHRON, Args ); 820*cdf0e10cSrcweir aRequest.AppendItem( aItem ); 821*cdf0e10cSrcweir SFX_APP()->ExecuteSlot( aRequest ); 822*cdf0e10cSrcweir } 823*cdf0e10cSrcweir else if ( pButton == &aNewLibButton ) 824*cdf0e10cSrcweir { 825*cdf0e10cSrcweir SvLBoxEntry* pCurEntry = aBasicBox.GetCurEntry(); 826*cdf0e10cSrcweir BasicEntryDescriptor aDesc( aBasicBox.GetEntryDescriptor( pCurEntry ) ); 827*cdf0e10cSrcweir ScriptDocument aDocument( aDesc.GetDocument() ); 828*cdf0e10cSrcweir createLibImpl( static_cast<Window*>( this ), aDocument, NULL, &aBasicBox ); 829*cdf0e10cSrcweir } 830*cdf0e10cSrcweir else if ( pButton == &aNewModButton ) 831*cdf0e10cSrcweir { 832*cdf0e10cSrcweir SvLBoxEntry* pCurEntry = aBasicBox.GetCurEntry(); 833*cdf0e10cSrcweir BasicEntryDescriptor aDesc( aBasicBox.GetEntryDescriptor( pCurEntry ) ); 834*cdf0e10cSrcweir ScriptDocument aDocument( aDesc.GetDocument() ); 835*cdf0e10cSrcweir String aLibName( aDesc.GetLibName() ); 836*cdf0e10cSrcweir String aModName; 837*cdf0e10cSrcweir createModImpl( static_cast<Window*>( this ), aDocument, 838*cdf0e10cSrcweir aBasicBox, aLibName, aModName, true ); 839*cdf0e10cSrcweir } 840*cdf0e10cSrcweir else if ( pButton == &aOrganizeButton ) 841*cdf0e10cSrcweir { 842*cdf0e10cSrcweir StoreMacroDescription(); 843*cdf0e10cSrcweir 844*cdf0e10cSrcweir BasicEntryDescriptor aDesc( aBasicBox.GetEntryDescriptor( aBasicBox.FirstSelected() ) ); 845*cdf0e10cSrcweir OrganizeDialog* pDlg = new OrganizeDialog( this, 0, aDesc ); 846*cdf0e10cSrcweir sal_uInt16 nRet = pDlg->Execute(); 847*cdf0e10cSrcweir delete pDlg; 848*cdf0e10cSrcweir 849*cdf0e10cSrcweir if ( nRet ) // Nicht einfach nur geschlossen 850*cdf0e10cSrcweir { 851*cdf0e10cSrcweir EndDialog( MACRO_EDIT ); 852*cdf0e10cSrcweir return 0; 853*cdf0e10cSrcweir } 854*cdf0e10cSrcweir 855*cdf0e10cSrcweir BasicIDEShell* pIDEShell = IDE_DLL()->GetShell(); 856*cdf0e10cSrcweir if ( pIDEShell && pIDEShell->IsAppBasicModified() ) 857*cdf0e10cSrcweir bForceStoreBasic = sal_True; 858*cdf0e10cSrcweir 859*cdf0e10cSrcweir aBasicBox.UpdateEntries(); 860*cdf0e10cSrcweir } 861*cdf0e10cSrcweir return 0; 862*cdf0e10cSrcweir } 863*cdf0e10cSrcweir 864*cdf0e10cSrcweir 865*cdf0e10cSrcweir 866*cdf0e10cSrcweir void MacroChooser::UpdateFields() 867*cdf0e10cSrcweir { 868*cdf0e10cSrcweir SvLBoxEntry* pMacroEntry = aMacroBox.GetCurEntry(); 869*cdf0e10cSrcweir String aEmptyStr; 870*cdf0e10cSrcweir 871*cdf0e10cSrcweir aMacroNameEdit.SetText( aEmptyStr ); 872*cdf0e10cSrcweir if ( pMacroEntry ) 873*cdf0e10cSrcweir aMacroNameEdit.SetText( aMacroBox.GetEntryText( pMacroEntry ) ); 874*cdf0e10cSrcweir } 875*cdf0e10cSrcweir 876*cdf0e10cSrcweir void MacroChooser::SetMode( sal_uInt16 nM ) 877*cdf0e10cSrcweir { 878*cdf0e10cSrcweir nMode = nM; 879*cdf0e10cSrcweir if ( nMode == MACROCHOOSER_ALL ) 880*cdf0e10cSrcweir { 881*cdf0e10cSrcweir aRunButton.SetText( String( IDEResId( RID_STR_RUN ) ) ); 882*cdf0e10cSrcweir EnableButton( aNewDelButton, sal_True ); 883*cdf0e10cSrcweir EnableButton( aOrganizeButton, sal_True ); 884*cdf0e10cSrcweir } 885*cdf0e10cSrcweir else if ( nMode == MACROCHOOSER_CHOOSEONLY ) 886*cdf0e10cSrcweir { 887*cdf0e10cSrcweir aRunButton.SetText( String( IDEResId( RID_STR_CHOOSE ) ) ); 888*cdf0e10cSrcweir EnableButton( aNewDelButton, sal_False ); 889*cdf0e10cSrcweir EnableButton( aOrganizeButton, sal_False ); 890*cdf0e10cSrcweir } 891*cdf0e10cSrcweir else if ( nMode == MACROCHOOSER_RECORDING ) 892*cdf0e10cSrcweir { 893*cdf0e10cSrcweir aRunButton.SetText( String( IDEResId( RID_STR_RECORD ) ) ); 894*cdf0e10cSrcweir EnableButton( aNewDelButton, sal_False ); 895*cdf0e10cSrcweir EnableButton( aOrganizeButton, sal_False ); 896*cdf0e10cSrcweir 897*cdf0e10cSrcweir aAssignButton.Hide(); 898*cdf0e10cSrcweir aEditButton.Hide(); 899*cdf0e10cSrcweir aNewDelButton.Hide(); 900*cdf0e10cSrcweir aOrganizeButton.Hide(); 901*cdf0e10cSrcweir aMacroFromTxT.Hide(); 902*cdf0e10cSrcweir 903*cdf0e10cSrcweir aNewLibButton.Show(); 904*cdf0e10cSrcweir aNewModButton.Show(); 905*cdf0e10cSrcweir aMacrosSaveInTxt.Show(); 906*cdf0e10cSrcweir 907*cdf0e10cSrcweir Point aHelpPos = aHelpButton.GetPosPixel(); 908*cdf0e10cSrcweir Point aHelpPosLogic = PixelToLogic( aHelpPos, MapMode(MAP_APPFONT) ); 909*cdf0e10cSrcweir aHelpPosLogic.Y() -= 34; 910*cdf0e10cSrcweir aHelpPos = LogicToPixel( aHelpPosLogic, MapMode(MAP_APPFONT) ); 911*cdf0e10cSrcweir aHelpButton.SetPosPixel( aHelpPos ); 912*cdf0e10cSrcweir } 913*cdf0e10cSrcweir CheckButtons(); 914*cdf0e10cSrcweir } 915*cdf0e10cSrcweir 916*cdf0e10cSrcweir String MacroChooser::GetInfo( SbxVariable* pVar ) 917*cdf0e10cSrcweir { 918*cdf0e10cSrcweir String aComment; 919*cdf0e10cSrcweir SbxInfoRef xInfo = pVar->GetInfo(); 920*cdf0e10cSrcweir if ( xInfo.Is() ) 921*cdf0e10cSrcweir aComment = xInfo->GetComment(); 922*cdf0e10cSrcweir return aComment; 923*cdf0e10cSrcweir } 924*cdf0e10cSrcweir 925