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 "docsignature.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #define SI_NOCONTROL 34*cdf0e10cSrcweir #define SI_NOSBXCONTROLS 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <ide_pch.hxx> 37*cdf0e10cSrcweir #include <basic/sbx.hxx> 38*cdf0e10cSrcweir #include "basicrenderable.hxx" 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #include <com/sun/star/frame/XTitle.hpp> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir #include <vcl/sound.hxx> 43*cdf0e10cSrcweir #include <basidesh.hxx> 44*cdf0e10cSrcweir #include <basidesh.hrc> 45*cdf0e10cSrcweir #include <baside2.hxx> 46*cdf0e10cSrcweir #include <basdoc.hxx> 47*cdf0e10cSrcweir #include <basobj.hxx> 48*cdf0e10cSrcweir #include <svtools/texteng.hxx> 49*cdf0e10cSrcweir #include <svtools/textview.hxx> 50*cdf0e10cSrcweir #include <svtools/xtextedt.hxx> 51*cdf0e10cSrcweir #include <tools/diagnose_ex.h> 52*cdf0e10cSrcweir #include <sfx2/sfxdefs.hxx> 53*cdf0e10cSrcweir #include <sfx2/signaturestate.hxx> 54*cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 55*cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp> 56*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir using namespace ::com::sun::star; 59*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 60*cdf0e10cSrcweir namespace css = ::com::sun::star; 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir IMPL_LINK_INLINE_START( BasicIDEShell, ObjectDialogCancelHdl, ObjectCatalog *, EMPTYARG ) 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir ShowObjectDialog( sal_False, sal_True ); 65*cdf0e10cSrcweir return 0; 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir IMPL_LINK_INLINE_END( BasicIDEShell, ObjectDialogCancelHdl, ObjectCatalog *, EMPTYARG ) 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir /* 70*cdf0e10cSrcweir IMPL_LINK( BasicIDEShell, ObjectDialogInsertHdl, ObjectCatalog *, pObjCat ) 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir if ( !pCurWin ) 73*cdf0e10cSrcweir return 0; 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir if ( pCurWin->IsA( TYPE( ModulWindow ) ) ) 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir ModulWindow* pEditWin = (ModulWindow*)pCurWin; 78*cdf0e10cSrcweir pEditWin->InsertFromObjectCatalog( pObjCat ); 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir else 81*cdf0e10cSrcweir Sound::Beep(); 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir return 0; 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir */ 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir Reference< view::XRenderable > BasicIDEShell::GetRenderable() 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir return Reference< view::XRenderable >( new basicide::BasicRenderable( pCurWin ) ); 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir #if 0 93*cdf0e10cSrcweir sal_uInt16 __EXPORT BasicIDEShell::Print( SfxProgress &rProgress, sal_Bool bIsAPI, PrintDialog *pPrintDialog ) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir if ( pCurWin ) 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir SfxPrinter* pPrinter = GetPrinter( sal_True ); 98*cdf0e10cSrcweir if ( pPrinter ) 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir SfxViewShell::Print( rProgress, bIsAPI, pPrintDialog ); 101*cdf0e10cSrcweir pCurWin->PrintData( pPrinter ); 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir return 0; 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir #endif 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir sal_Bool BasicIDEShell::HasSelection( sal_Bool /* bText */ ) const 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir sal_Bool bSel = sal_False; 111*cdf0e10cSrcweir if ( pCurWin && pCurWin->ISA( ModulWindow ) ) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir TextView* pEditView = ((ModulWindow*)pCurWin)->GetEditView(); 114*cdf0e10cSrcweir if ( pEditView && pEditView->HasSelection() ) 115*cdf0e10cSrcweir bSel = sal_True; 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir return bSel; 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir String BasicIDEShell::GetSelectionText( sal_Bool bWholeWord ) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir String aText; 123*cdf0e10cSrcweir if ( pCurWin && pCurWin->ISA( ModulWindow ) ) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir TextView* pEditView = ((ModulWindow*)pCurWin)->GetEditView(); 126*cdf0e10cSrcweir if ( pEditView ) 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir if ( bWholeWord && !pEditView->HasSelection() ) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir // String aStrCurrentDelimiters = pEngine->GetWordDelimiters(); 131*cdf0e10cSrcweir // pEngine->SetWordDelimiters( " .,;\"'" ); 132*cdf0e10cSrcweir aText = pEditView->GetTextEngine()->GetWord( pEditView->GetSelection().GetEnd() ); 133*cdf0e10cSrcweir // pEngine->SetWordDelimiters( aStrCurrentDelimiters ); 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir else 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir TextSelection aSel = pEditView->GetSelection(); 138*cdf0e10cSrcweir if ( !bWholeWord || ( aSel.GetStart().GetPara() == aSel.GetEnd().GetPara() ) ) 139*cdf0e10cSrcweir aText = pEditView->GetSelected(); 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir return aText; 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir SfxPrinter* __EXPORT BasicIDEShell::GetPrinter( sal_Bool bCreate ) 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir if ( pCurWin ) // && pCurWin->ISA( ModulWindow ) ) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir BasicDocShell* pDocShell = (BasicDocShell*)GetViewFrame()->GetObjectShell(); 151*cdf0e10cSrcweir DBG_ASSERT( pDocShell, "DocShell ?!" ); 152*cdf0e10cSrcweir return pDocShell->GetPrinter( bCreate ); 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir return 0; 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir sal_uInt16 __EXPORT BasicIDEShell::SetPrinter( SfxPrinter *pNewPrinter, sal_uInt16 nDiffFlags, bool ) 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir (void)nDiffFlags; 160*cdf0e10cSrcweir BasicDocShell* pDocShell = (BasicDocShell*)GetViewFrame()->GetObjectShell(); 161*cdf0e10cSrcweir DBG_ASSERT( pDocShell, "DocShell ?!" ); 162*cdf0e10cSrcweir pDocShell->SetPrinter( pNewPrinter ); 163*cdf0e10cSrcweir return 0; 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir void BasicIDEShell::SetMDITitle() 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir String aTitle; 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir if ( m_aCurLibName.Len() ) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir LibraryLocation eLocation = m_aCurDocument.getLibraryLocation( m_aCurLibName ); 173*cdf0e10cSrcweir aTitle = m_aCurDocument.getTitle( eLocation ); 174*cdf0e10cSrcweir aTitle += '.'; 175*cdf0e10cSrcweir aTitle += m_aCurLibName; 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir else 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir aTitle = String( IDEResId( RID_STR_ALL ) ); 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir ::basctl::DocumentSignature aCurSignature( m_aCurDocument ); 183*cdf0e10cSrcweir if ( aCurSignature.getScriptingSignatureState() == SIGNATURESTATE_SIGNATURES_OK ) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir aTitle += String::CreateFromAscii( " " ); 186*cdf0e10cSrcweir aTitle += String( IDEResId( RID_STR_SIGNED ) ); 187*cdf0e10cSrcweir aTitle += String::CreateFromAscii( " " ); 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir SfxViewFrame* pViewFrame = GetViewFrame(); 191*cdf0e10cSrcweir if ( pViewFrame ) 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir SfxObjectShell* pShell = pViewFrame->GetObjectShell(); 194*cdf0e10cSrcweir if ( pShell && aTitle != pShell->GetTitle( SFX_TITLE_CAPTION ) ) 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir pShell->SetTitle( aTitle ); 197*cdf0e10cSrcweir pShell->SetModified( sal_False ); 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir css::uno::Reference< css::frame::XController > xController = GetController (); 201*cdf0e10cSrcweir css::uno::Reference< css::frame::XTitle > xTitle (xController, css::uno::UNO_QUERY); 202*cdf0e10cSrcweir if (xTitle.is ()) 203*cdf0e10cSrcweir xTitle->setTitle (aTitle); 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir } 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir void BasicIDEShell::DestroyModulWindowLayout() 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir delete pModulLayout; 210*cdf0e10cSrcweir pModulLayout = 0; 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir void BasicIDEShell::UpdateModulWindowLayout( bool bBasicStopped ) 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir if ( pModulLayout ) 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir pModulLayout->GetStackWindow().UpdateCalls(); 219*cdf0e10cSrcweir pModulLayout->GetWatchWindow().UpdateWatches( bBasicStopped ); 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir void BasicIDEShell::CreateModulWindowLayout() 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir pModulLayout = new ModulWindowLayout( &GetViewFrame()->GetWindow() ); 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir ModulWindow* BasicIDEShell::CreateBasWin( const ScriptDocument& rDocument, const String& rLibName, const String& rModName ) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir bCreatingWindow = sal_True; 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir sal_uLong nKey = 0; 233*cdf0e10cSrcweir ModulWindow* pWin = 0; 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir String aLibName( rLibName ); 236*cdf0e10cSrcweir String aModName( rModName ); 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir if ( !aLibName.Len() ) 239*cdf0e10cSrcweir aLibName = String::CreateFromAscii( "Standard" ); 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir uno::Reference< container::XNameContainer > xLib = rDocument.getOrCreateLibrary( E_SCRIPTS, aLibName ); 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir if ( !aModName.Len() ) 244*cdf0e10cSrcweir aModName = rDocument.createObjectName( E_SCRIPTS, aLibName ); 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir // Vielleicht gibt es ein suspendiertes? 247*cdf0e10cSrcweir pWin = FindBasWin( rDocument, aLibName, aModName, sal_False, sal_True ); 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir if ( !pWin ) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir ::rtl::OUString aModule; 252*cdf0e10cSrcweir bool bSuccess = false; 253*cdf0e10cSrcweir if ( rDocument.hasModule( aLibName, aModName ) ) 254*cdf0e10cSrcweir bSuccess = rDocument.getModule( aLibName, aModName, aModule ); 255*cdf0e10cSrcweir else 256*cdf0e10cSrcweir bSuccess = rDocument.createModule( aLibName, aModName, sal_True, aModule ); 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir if ( bSuccess ) 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir pWin = FindBasWin( rDocument, aLibName, aModName, sal_False, sal_True ); 261*cdf0e10cSrcweir if( !pWin ) 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir // new module window 264*cdf0e10cSrcweir pWin = new ModulWindow( pModulLayout, rDocument, aLibName, aModName, aModule ); 265*cdf0e10cSrcweir nKey = InsertWindowInTable( pWin ); 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir else // we've gotten called recursively ( via listener from createModule above ), get outta here 268*cdf0e10cSrcweir return pWin; 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir } 271*cdf0e10cSrcweir else 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir pWin->SetStatus( pWin->GetStatus() & ~BASWIN_SUSPENDED ); 274*cdf0e10cSrcweir IDEBaseWindow* pTmp = aIDEWindowTable.First(); 275*cdf0e10cSrcweir while ( pTmp && !nKey ) 276*cdf0e10cSrcweir { 277*cdf0e10cSrcweir if ( pTmp == pWin ) 278*cdf0e10cSrcweir nKey = aIDEWindowTable.GetCurKey(); 279*cdf0e10cSrcweir pTmp = aIDEWindowTable.Next(); 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir DBG_ASSERT( nKey, "CreateBasWin: Kein Key- Fenster nicht gefunden!" ); 282*cdf0e10cSrcweir } 283*cdf0e10cSrcweir if( nKey && xLib.is() && rDocument.isInVBAMode() ) 284*cdf0e10cSrcweir { 285*cdf0e10cSrcweir // display a nice friendly name in the ObjectModule tab, 286*cdf0e10cSrcweir // combining the objectname and module name, e.g. Sheet1 ( Financials ) 287*cdf0e10cSrcweir String sObjName; 288*cdf0e10cSrcweir ModuleInfoHelper::getObjectName( xLib, rModName, sObjName ); 289*cdf0e10cSrcweir if( sObjName.Len() ) 290*cdf0e10cSrcweir { 291*cdf0e10cSrcweir aModName.AppendAscii(" (").Append(sObjName).AppendAscii(")"); 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir } 294*cdf0e10cSrcweir pTabBar->InsertPage( (sal_uInt16)nKey, aModName ); 295*cdf0e10cSrcweir pTabBar->Sort(); 296*cdf0e10cSrcweir pWin->GrabScrollBars( &aHScrollBar, &aVScrollBar ); 297*cdf0e10cSrcweir if ( !pCurWin ) 298*cdf0e10cSrcweir SetCurWindow( pWin, sal_False, sal_False ); 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir bCreatingWindow = sal_False; 301*cdf0e10cSrcweir return pWin; 302*cdf0e10cSrcweir } 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir ModulWindow* BasicIDEShell::FindBasWin( const ScriptDocument& rDocument, const String& rLibName, const String& rModName, sal_Bool bCreateIfNotExist, sal_Bool bFindSuspended ) 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir ModulWindow* pModWin = 0; 307*cdf0e10cSrcweir IDEBaseWindow* pWin = aIDEWindowTable.First(); 308*cdf0e10cSrcweir while ( pWin && !pModWin ) 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir if ( ( !pWin->IsSuspended() || bFindSuspended ) && pWin->IsA( TYPE( ModulWindow ) ) ) 311*cdf0e10cSrcweir { 312*cdf0e10cSrcweir if ( !rLibName.Len() ) // nur irgendeins finden... 313*cdf0e10cSrcweir pModWin = (ModulWindow*)pWin; 314*cdf0e10cSrcweir else if ( pWin->IsDocument( rDocument ) && pWin->GetLibName() == rLibName && pWin->GetName() == rModName ) 315*cdf0e10cSrcweir pModWin = (ModulWindow*)pWin; 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir pWin = aIDEWindowTable.Next(); 318*cdf0e10cSrcweir } 319*cdf0e10cSrcweir if ( !pModWin && bCreateIfNotExist ) 320*cdf0e10cSrcweir pModWin = CreateBasWin( rDocument, rLibName, rModName ); 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir return pModWin; 323*cdf0e10cSrcweir } 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir void __EXPORT BasicIDEShell::Move() 326*cdf0e10cSrcweir { 327*cdf0e10cSrcweir if ( pCurWin && pCurWin->ISA( ModulWindow ) ) 328*cdf0e10cSrcweir ((ModulWindow*)pCurWin)->FrameWindowMoved(); 329*cdf0e10cSrcweir } 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir void __EXPORT BasicIDEShell::ShowCursor( FASTBOOL bOn ) 332*cdf0e10cSrcweir { 333*cdf0e10cSrcweir if ( pCurWin && pCurWin->ISA( ModulWindow ) ) 334*cdf0e10cSrcweir ((ModulWindow*)pCurWin)->ShowCursor( (sal_Bool)bOn ); 335*cdf0e10cSrcweir } 336*cdf0e10cSrcweir 337*cdf0e10cSrcweir // Hack for #101048 338*cdf0e10cSrcweir sal_Int32 getBasicIDEShellCount( void ); 339*cdf0e10cSrcweir 340*cdf0e10cSrcweir // Nur wenn Basicfenster oben: 341*cdf0e10cSrcweir void __EXPORT BasicIDEShell::ExecuteBasic( SfxRequest& rReq ) 342*cdf0e10cSrcweir { 343*cdf0e10cSrcweir if ( !pCurWin || !pCurWin->IsA( TYPE( ModulWindow ) ) ) 344*cdf0e10cSrcweir return; 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir pCurWin->ExecuteCommand( rReq ); 347*cdf0e10cSrcweir sal_Int32 nCount = getBasicIDEShellCount(); 348*cdf0e10cSrcweir if( nCount ) 349*cdf0e10cSrcweir CheckWindows(); 350*cdf0e10cSrcweir } 351*cdf0e10cSrcweir 352