diff options
author | npower Developer <npower@openoffice.org> | 2010-03-02 12:39:31 +0000 |
---|---|---|
committer | npower Developer <npower@openoffice.org> | 2010-03-02 12:39:31 +0000 |
commit | 07716c77cc6b451aa4717b7811fd5f5c2aa22967 (patch) | |
tree | 0b22431906616b33ce426d6edb40fb275a7b8b34 /basctl | |
parent | 97412488d9fcd77c21dbeb821dec122008cd2e32 (diff) |
npower13_objectmodule: #i109734# object module stuff
Diffstat (limited to 'basctl')
-rw-r--r-- | basctl/inc/basidesh.hrc | 4 | ||||
-rw-r--r-- | basctl/source/basicide/baside2.cxx | 47 | ||||
-rw-r--r-- | basctl/source/basicide/baside3.cxx | 14 | ||||
-rw-r--r-- | basctl/source/basicide/basides1.cxx | 10 | ||||
-rw-r--r-- | basctl/source/basicide/basides2.cxx | 48 | ||||
-rw-r--r-- | basctl/source/basicide/basidesh.cxx | 106 | ||||
-rw-r--r-- | basctl/source/basicide/basidesh.src | 16 | ||||
-rw-r--r-- | basctl/source/basicide/bastype2.cxx | 185 | ||||
-rw-r--r-- | basctl/source/basicide/bastype2.hxx | 13 | ||||
-rw-r--r-- | basctl/source/basicide/bastype3.cxx | 46 | ||||
-rw-r--r-- | basctl/source/basicide/bastypes.cxx | 23 | ||||
-rw-r--r-- | basctl/source/basicide/macrodlg.cxx | 14 | ||||
-rw-r--r-- | basctl/source/basicide/moduldlg.cxx | 70 | ||||
-rw-r--r-- | basctl/source/basicide/scriptdocument.cxx | 38 | ||||
-rw-r--r-- | basctl/source/dlged/dlged.cxx | 3 | ||||
-rw-r--r-- | basctl/source/dlged/dlgedobj.cxx | 40 | ||||
-rw-r--r-- | basctl/source/inc/basidesh.hxx | 3 | ||||
-rw-r--r-- | basctl/source/inc/dlged.hxx | 5 | ||||
-rw-r--r-- | basctl/source/inc/scriptdocument.hxx | 1 |
19 files changed, 629 insertions, 57 deletions
diff --git a/basctl/inc/basidesh.hrc b/basctl/inc/basidesh.hrc index 51d1ed2be6fc..8bf7d3316cd0 100644 --- a/basctl/inc/basidesh.hrc +++ b/basctl/inc/basidesh.hrc @@ -182,6 +182,10 @@ #define RID_STR_DLGIMP_MISMATCH_OMIT ( RID_BASICIDE_START + 115 ) #define RID_STR_DLGIMP_MISMATCH_TITLE ( RID_BASICIDE_START + 116 ) #define RID_STR_DLGIMP_MISMATCH_TEXT ( RID_BASICIDE_START + 117 ) +#define RID_STR_DOCUMENT_OBJECTS ( RID_BASICIDE_START + 118 ) +#define RID_STR_USERFORMS ( RID_BASICIDE_START + 119 ) +#define RID_STR_NORMAL_MODULES ( RID_BASICIDE_START + 120 ) +#define RID_STR_CLASS_MODULES ( RID_BASICIDE_START + 121 ) #endif // _SVX_NOIDERESIDS diff --git a/basctl/source/basicide/baside2.cxx b/basctl/source/basicide/baside2.cxx index 9fc700948249..bed5aa96dc28 100644 --- a/basctl/source/basicide/baside2.cxx +++ b/basctl/source/basicide/baside2.cxx @@ -46,6 +46,7 @@ #include <com/sun/star/script/XLibraryContainer2.hpp> #endif #include <com/sun/star/document/MacroExecMode.hpp> +#include <com/sun/star/script/ModuleType.hpp> #include <toolkit/helper/vclunohelper.hxx> #include <sfx2/docfile.hxx> #include <basic/basrdll.hxx> @@ -107,6 +108,8 @@ DBG_NAME( ModulWindow ) TYPEINIT1( ModulWindow , IDEBaseWindow ); +void lcl_getObjectName( const uno::Reference< container::XNameContainer >& rLib, const String& rModName, String& rObjName ); + void lcl_PrintHeader( Printer* pPrinter, USHORT nPages, USHORT nCurPage, const String& rTitle, bool bOutput ) { short nLeftMargin = LMARGPRN; @@ -332,6 +335,8 @@ BOOL ModulWindow::BasicExecute() DBG_ASSERT( xModule.Is(), "Kein Modul!" ); AddStatus( BASWIN_RUNNINGBASIC ); USHORT nStart, nEnd, nCurMethodStart = 0; + TextSelection aSel = GetEditView()->GetSelection(); + nCurMethodStart = ( aSel.GetStart().GetPara() + 1 ); SbMethod* pMethod = 0; // erstes Macro, sonst blind "Main" (ExtSearch?) for ( USHORT nMacro = 0; nMacro < xModule->GetMethods()->Count(); nMacro++ ) @@ -339,16 +344,16 @@ BOOL ModulWindow::BasicExecute() SbMethod* pM = (SbMethod*)xModule->GetMethods()->Get( nMacro ); DBG_ASSERT( pM, "Method?" ); pM->GetLineRange( nStart, nEnd ); - if ( !pMethod || ( nStart < nCurMethodStart ) ) + if ( nCurMethodStart >= nStart && nCurMethodStart <= nEnd ) { pMethod = pM; - nCurMethodStart = nStart; + break; } } if ( !pMethod ) - pMethod = (SbMethod*)xModule->Find( String( RTL_CONSTASCII_USTRINGPARAM( "Main" ) ), SbxCLASS_METHOD ); + return ( BasicIDE::ChooseMacro( uno::Reference< frame::XModel >(), FALSE, rtl::OUString() ).getLength() > 0 ) ? TRUE : FALSE; - if ( pMethod ) + else { pMethod->SetDebugFlags( aStatus.nBasicFlags ); BasicDLL::SetDebugMode( TRUE ); @@ -1372,7 +1377,39 @@ BasicEntryDescriptor ModulWindow::CreateEntryDescriptor() ScriptDocument aDocument( GetDocument() ); String aLibName( GetLibName() ); LibraryLocation eLocation = aDocument.getLibraryLocation( aLibName ); - return BasicEntryDescriptor( aDocument, eLocation, aLibName, GetName(), OBJ_TYPE_MODULE ); + String aModName( GetName() ); + String aLibSubName; + if( xBasic.Is() && aDocument.isInVBAMode() && xModule.Is() ) + { + switch( xModule->GetModuleType() ) + { + case script::ModuleType::Document: + { + aLibSubName = String( IDEResId( RID_STR_DOCUMENT_OBJECTS ) ); + uno::Reference< container::XNameContainer > xLib = aDocument.getOrCreateLibrary( E_SCRIPTS, aLibName ); + if( xLib.is() ) + { + String sObjName; + lcl_getObjectName( xLib, aModName, sObjName ); + if( sObjName.Len() ) + { + aModName.AppendAscii(" (").Append(sObjName).AppendAscii(")"); + } + } + break; + } + case script::ModuleType::Form: + aLibSubName = String( IDEResId( RID_STR_USERFORMS ) ); + break; + case script::ModuleType::Normal: + aLibSubName = String( IDEResId( RID_STR_NORMAL_MODULES ) ); + break; + case script::ModuleType::Class: + aLibSubName = String( IDEResId( RID_STR_CLASS_MODULES ) ); + break; + } + } + return BasicEntryDescriptor( aDocument, eLocation, aLibName, aLibSubName, aModName, OBJ_TYPE_MODULE ); } void ModulWindow::SetReadOnly( BOOL b ) diff --git a/basctl/source/basicide/baside3.cxx b/basctl/source/basicide/baside3.cxx index afbe3daf5be1..c5628451ac8f 100644 --- a/basctl/source/basicide/baside3.cxx +++ b/basctl/source/basicide/baside3.cxx @@ -82,6 +82,7 @@ #include <com/sun/star/resource/XStringResourceResolver.hpp> #include <com/sun/star/resource/StringResourceWithLocation.hpp> #include <com/sun/star/task/XInteractionHandler.hpp> +#include <com/sun/star/script/XVBACompat.hpp> using namespace comphelper; using namespace ::com::sun::star; @@ -112,8 +113,16 @@ DialogWindow::DialogWindow( Window* pParent, const ScriptDocument& rDocument, St { InitSettings( TRUE, TRUE, TRUE ); - pEditor = new DlgEditor(); + pEditor = new DlgEditor( rDocument.isDocument() ? rDocument.getDocument() : Reference< frame::XModel >() ); pEditor->SetWindow( this ); + // set vba mode on DialogModel ( allows it to work in 100thmm instead of MAP_APPFONT ) + if ( rDocument.isDocument() && rDocument.getDocument().is() ) + { + uno::Reference< script::XVBACompat > xDocVBAMode( rDocument.getLibraryContainer( E_SCRIPTS ), uno::UNO_QUERY ); + uno::Reference< script::XVBACompat > xDialogModelVBAMode( xDialogModel, uno::UNO_QUERY ); + if ( xDocVBAMode.is() && xDialogModelVBAMode.is() ) + xDialogModelVBAMode->setVBACompatModeOn( xDocVBAMode->getVBACompatModeOn() ); + } pEditor->SetDialog( xDialogModel ); // Undo einrichten @@ -1297,8 +1306,9 @@ BasicEntryDescriptor DialogWindow::CreateEntryDescriptor() { ScriptDocument aDocument( GetDocument() ); String aLibName( GetLibName() ); + String aLibSubName; LibraryLocation eLocation = aDocument.getLibraryLocation( aLibName ); - return BasicEntryDescriptor( aDocument, eLocation, aLibName, GetName(), OBJ_TYPE_DIALOG ); + return BasicEntryDescriptor( aDocument, eLocation, aLibName, aLibSubName, GetName(), OBJ_TYPE_DIALOG ); } void DialogWindow::SetReadOnly( BOOL b ) diff --git a/basctl/source/basicide/basides1.cxx b/basctl/source/basicide/basides1.cxx index 909a28543fae..ded495d416be 100644 --- a/basctl/source/basicide/basides1.cxx +++ b/basctl/source/basicide/basides1.cxx @@ -1198,10 +1198,16 @@ IDEBaseWindow* BasicIDEShell::FindWindow( const ScriptDocument& rDocument, const // return any non-suspended window return pWin; } - else if ( pWin->IsDocument( rDocument ) && pWin->GetLibName() == rLibName && pWin->GetName() == rName && + else if ( pWin->IsDocument( rDocument ) ) + { + OSL_TRACE("FindWindow pWin->GetLibName() %s rLibName %s", + rtl::OUStringToOString( pWin->GetLibName(), RTL_TEXTENCODING_UTF8 ).getStr(), + rtl::OUStringToOString( rLibName, RTL_TEXTENCODING_UTF8 ).getStr() ); + OSL_TRACE("pWin->pWin->IsA( TYPE( ModulWindow ) %d && nType %d = BASICIDE_TYPE_MODULE %d", pWin->IsA( TYPE( ModulWindow ) ), nType, BASICIDE_TYPE_MODULE ); + OSL_TRACE("pWin->pWin->IsA( TYPE( DialogWindow ) %d && nType %d = BASICIDE_TYPE_DIALOG %d", pWin->IsA( TYPE( DialogWindow ) ), nType, BASICIDE_TYPE_DIALOG ); + if ( pWin->GetLibName() == rLibName && pWin->GetName() == rName && ( ( pWin->IsA( TYPE( ModulWindow ) ) && nType == BASICIDE_TYPE_MODULE ) || ( pWin->IsA( TYPE( DialogWindow ) ) && nType == BASICIDE_TYPE_DIALOG ) ) ) - { return pWin; } } diff --git a/basctl/source/basicide/basides2.cxx b/basctl/source/basicide/basides2.cxx index 20de8e9aafba..8da483e209d4 100644 --- a/basctl/source/basicide/basides2.cxx +++ b/basctl/source/basicide/basides2.cxx @@ -51,11 +51,38 @@ #include <tools/diagnose_ex.h> #include <sfx2/sfxdefs.hxx> #include <sfx2/signaturestate.hxx> +#include <com/sun/star/script/XVBAModuleInfo.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> using namespace ::com::sun::star; using namespace ::com::sun::star::uno; namespace css = ::com::sun::star; +void lcl_getObjectName( const uno::Reference< container::XNameContainer >& rLib, const String& rModName, String& rObjName ) +{ + try + { + uno::Reference< script::XVBAModuleInfo > xVBAModuleInfo( rLib, uno::UNO_QUERY ); + if ( xVBAModuleInfo.is() && xVBAModuleInfo->hasModuleInfo( rModName ) ) + { + script::ModuleInfo aModuleInfo = xVBAModuleInfo->getModuleInfo( rModName ); + uno::Any aObject( aModuleInfo.ModuleObject ); + uno::Reference< lang::XServiceInfo > xServiceInfo( aObject, uno::UNO_QUERY ); + if( xServiceInfo.is() && xServiceInfo->supportsService( rtl::OUString::createFromAscii( "ooo.vba.excel.Worksheet" ) ) ) + { + uno::Reference< container::XNamed > xNamed( aObject, uno::UNO_QUERY ); + if( xNamed.is() ) + rObjName = xNamed->getName(); + } + } + } + catch( uno::Exception& ) + { + } +} + IMPL_LINK_INLINE_START( BasicIDEShell, ObjectDialogCancelHdl, ObjectCatalog *, EMPTYARG ) { ShowObjectDialog( FALSE, TRUE ); @@ -235,7 +262,7 @@ ModulWindow* BasicIDEShell::CreateBasWin( const ScriptDocument& rDocument, const if ( !aLibName.Len() ) aLibName = String::CreateFromAscii( "Standard" ); - rDocument.getOrCreateLibrary( E_SCRIPTS, aLibName ); + uno::Reference< container::XNameContainer > xLib = rDocument.getOrCreateLibrary( E_SCRIPTS, aLibName ); if ( !aModName.Len() ) aModName = rDocument.createObjectName( E_SCRIPTS, aLibName ); @@ -254,11 +281,14 @@ ModulWindow* BasicIDEShell::CreateBasWin( const ScriptDocument& rDocument, const if ( bSuccess ) { - // new module window + pWin = FindBasWin( rDocument, aLibName, aModName, FALSE, TRUE ); + if( !pWin ) + { // new module window pWin = new ModulWindow( pModulLayout, rDocument, aLibName, aModName, aModule ); nKey = InsertWindowInTable( pWin ); } } + } else { pWin->SetStatus( pWin->GetStatus() & ~BASWIN_SUSPENDED ); @@ -271,7 +301,21 @@ ModulWindow* BasicIDEShell::CreateBasWin( const ScriptDocument& rDocument, const } DBG_ASSERT( nKey, "CreateBasWin: Kein Key- Fenster nicht gefunden!" ); } + if( nKey ) + { + if( xLib.is() ) + { + // display a nice friendly name in the ObjectModule tab, + // combining the objectname and module name, e.g. Sheet1 ( Financials ) + String sObjName; + lcl_getObjectName( xLib, rModName, sObjName ); + if( sObjName.Len() ) + { + aModName.AppendAscii(" (").Append(sObjName).AppendAscii(")"); + } + } pTabBar->InsertPage( (USHORT)nKey, aModName ); + } pTabBar->Sort(); pWin->GrabScrollBars( &aHScrollBar, &aVScrollBar ); if ( !pCurWin ) diff --git a/basctl/source/basicide/basidesh.cxx b/basctl/source/basicide/basidesh.cxx index 2c3ccc4eb678..9e698af58917 100644 --- a/basctl/source/basicide/basidesh.cxx +++ b/basctl/source/basicide/basidesh.cxx @@ -77,6 +77,9 @@ #include <com/sun/star/script/XLibraryContainer.hpp> #include <com/sun/star/script/XLibraryContainerPassword.hpp> #include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/container/XContainer.hpp> +#include <com/sun/star/container/XContainerListener.hpp> +#include <com/sun/star/script/XLibraryContainer.hpp> #include <svx/xmlsecctrl.hxx> @@ -84,6 +87,71 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star; using ::rtl::OUString; +static const rtl::OUString sStandardLibName( rtl::OUString::createFromAscii("Standard") ); + +typedef ::cppu::WeakImplHelper1< container::XContainerListener > ContainerListenerBASE; + +class ContainerListenerImpl : public ContainerListenerBASE +{ + BasicIDEShell* mpShell; +public: + + ContainerListenerImpl( BasicIDEShell* pShell ) : mpShell( pShell ) {} + + ~ContainerListenerImpl() + { + } + + void addContainerListener( const ScriptDocument& rScriptDocument, const String& aLibName ) + { + try + { + uno::Reference< container::XContainer > xContainer( rScriptDocument.getLibrary( E_SCRIPTS, aLibName, FALSE ), uno::UNO_QUERY ); + if ( rScriptDocument.isDocument() && xContainer.is() ) + { + uno::Reference< container::XContainerListener > xContainerListener( this ); + xContainer->addContainerListener( xContainerListener ); + } + } + catch( uno::Exception& ) {} + } + void removeContainerListener( const ScriptDocument& rScriptDocument, const String& aLibName ) + { + try + { + uno::Reference< container::XContainer > xContainer( rScriptDocument.getLibrary( E_SCRIPTS, aLibName, FALSE ), uno::UNO_QUERY ); + if ( rScriptDocument.isDocument() && xContainer.is() ) + { + uno::Reference< container::XContainerListener > xContainerListener( this ); + xContainer->removeContainerListener( xContainerListener ); + } + } + catch( uno::Exception& ) {} + } + + // XEventListener + virtual void SAL_CALL disposing( const lang::EventObject& ) throw( uno::RuntimeException ) {} + + // XContainerListener + virtual void SAL_CALL elementInserted( const container::ContainerEvent& Event ) throw( uno::RuntimeException ) + { + rtl::OUString sModuleName; + if( mpShell && ( Event.Accessor >>= sModuleName ) ) + mpShell->FindBasWin( mpShell->m_aCurDocument, mpShell->m_aCurLibName, sModuleName, TRUE, FALSE ); + } + virtual void SAL_CALL elementReplaced( const container::ContainerEvent& ) throw( com::sun::star::uno::RuntimeException ) { } + virtual void SAL_CALL elementRemoved( const container::ContainerEvent& Event ) throw( com::sun::star::uno::RuntimeException ) + { + rtl::OUString sModuleName; + if( mpShell && ( Event.Accessor >>= sModuleName ) ) + { + IDEBaseWindow* pWin = mpShell->FindWindow( mpShell->m_aCurDocument, mpShell->m_aCurLibName, sModuleName, BASICIDE_TYPE_MODULE, TRUE ); + if( pWin ) + mpShell->RemoveWindow( pWin, FALSE, TRUE ); + } + } + +}; TYPEINIT1( BasicIDEShell, SfxViewShell ); @@ -121,6 +189,7 @@ BasicIDEShell::BasicIDEShell( SfxViewFrame* pFrame_, SfxViewShell* /* pOldShell m_bAppBasicModified( FALSE ), m_aNotifier( *this ) { + m_xLibListener = new ContainerListenerImpl( this ); Init(); GnBasicIDEShellCount++; } @@ -212,6 +281,12 @@ __EXPORT BasicIDEShell::~BasicIDEShell() delete pTabBar; delete pObjectCatalog; DestroyModulWindowLayout(); + + ContainerListenerImpl* pListener = dynamic_cast< ContainerListenerImpl* >( m_xLibListener.get() ); + // Destroy all ContainerListeners for Basic Container. + if ( pListener ) + pListener->removeContainerListener( m_aCurDocument, m_aCurLibName ); + // MI: Das gab einen GPF im SDT beim Schliessen da dann der ViewFrame die // ObjSh loslaesst. Es wusste auch keiner mehr wozu das gut war. // GetViewFrame()->GetObjectShell()->Broadcast( SfxSimpleHint( SFX_HINT_DYING ) ); @@ -828,9 +903,22 @@ void BasicIDEShell::RemoveWindow( IDEBaseWindow* pWindow_, BOOL bDestroy, BOOL b { pWindow_->AddStatus( BASWIN_TOBEKILLED ); pWindow_->Hide(); - StarBASIC::Stop(); - // Es kommt kein Notify... - pWindow_->BasicStopped(); + // In normal mode stop basic in windows to be deleted + // In VBA stop basic only if the running script is trying to delete + // its parent module + bool bStop = true; + if ( pWindow_->GetDocument().isInVBAMode() ) + { + SbModule* pMod = StarBASIC::GetActiveModule(); + if ( !pMod || ( pMod && ( pMod->GetName() != pWindow_->GetName() ) ) ) + bStop = false; + } + if ( bStop ) + { + StarBASIC::Stop(); + // Es kommt kein Notify... + pWindow_->BasicStopped(); + } aIDEWindowTable.Insert( nKey, pWindow_ ); // wieder einhaegen } } @@ -918,7 +1006,19 @@ void BasicIDEShell::SetCurLib( const ScriptDocument& rDocument, String aLibName, { if ( !bCheck || ( rDocument != m_aCurDocument || aLibName != m_aCurLibName ) ) { + ContainerListenerImpl* pListener = NULL; + + if ( rDocument.isInVBAMode() ) + pListener = dynamic_cast< ContainerListenerImpl* >( m_xLibListener.get() ); + + if ( pListener ) + pListener->removeContainerListener( m_aCurDocument, m_aCurLibName ); + m_aCurDocument = rDocument; + + if ( pListener ) + pListener->addContainerListener( m_aCurDocument, aLibName ); + m_aCurLibName = aLibName; if ( bUpdateWindows ) UpdateWindows(); diff --git a/basctl/source/basicide/basidesh.src b/basctl/source/basicide/basidesh.src index f0c0727cd22f..556211f690af 100644 --- a/basctl/source/basicide/basidesh.src +++ b/basctl/source/basicide/basidesh.src @@ -636,6 +636,22 @@ String RID_STR_TRANSLATION_DEFAULT { Text [ en-US ] = "[Default Language]" ; }; +String RID_STR_DOCUMENT_OBJECTS +{ + Text [ en-US ] = "Document Objects" ; +}; +String RID_STR_USERFORMS +{ + Text [ en-US ] = "Forms" ; +}; +String RID_STR_NORMAL_MODULES +{ + Text [ en-US ] = "Modules" ; +}; +String RID_STR_CLASS_MODULES +{ + Text [ en-US ] = "Class Modules" ; +}; String RID_STR_DLGIMP_CLASH_RENAME diff --git a/basctl/source/basicide/bastype2.cxx b/basctl/source/basicide/bastype2.cxx index a37eb752e2ea..bf13b554a0a6 100644 --- a/basctl/source/basicide/bastype2.cxx +++ b/basctl/source/basicide/bastype2.cxx @@ -50,10 +50,28 @@ #include <com/sun/star/frame/XModuleManager.hpp> #include <comphelper/processfactory.hxx> #include <comphelper/componentcontext.hxx> +#include <map> +#include <com/sun/star/script/ModuleType.hpp> +#include <com/sun/star/script/XVBAModuleInfo.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/script/XVBAModuleInfo.hpp> using namespace ::com::sun::star::uno; using namespace ::com::sun::star; +void lcl_getObjectName( const uno::Reference< container::XNameContainer >& rLib, const String& rModName, String& rObjName ); + +sal_Int32 lcl_getModuleType( const uno::Reference< container::XNameContainer >& rLib, const String& rModName ) +{ + sal_Int32 nType = com::sun::star::script::ModuleType::Normal; + uno::Reference< script::XVBAModuleInfo > xVBAModuleInfo( rLib, uno::UNO_QUERY ); + if ( xVBAModuleInfo.is() && xVBAModuleInfo->hasModuleInfo( rModName ) ) + { + script::ModuleInfo aModuleInfo = xVBAModuleInfo->getModuleInfo( rModName ); + nType = aModuleInfo.ModuleType; + } + return nType; +} BasicEntry::~BasicEntry() { @@ -88,20 +106,22 @@ BasicEntryDescriptor::BasicEntryDescriptor() { } -BasicEntryDescriptor::BasicEntryDescriptor( const ScriptDocument& rDocument, LibraryLocation eLocation, const String& rLibName, const String& rName, BasicEntryType eType ) +BasicEntryDescriptor::BasicEntryDescriptor( const ScriptDocument& rDocument, LibraryLocation eLocation, const String& rLibName, const String& rLibSubName, const String& rName, BasicEntryType eType ) :m_aDocument( rDocument ) ,m_eLocation( eLocation ) ,m_aLibName( rLibName ) + ,m_aLibSubName( rLibSubName ) ,m_aName( rName ) ,m_eType( eType ) { OSL_ENSURE( m_aDocument.isValid(), "BasicEntryDescriptor::BasicEntryDescriptor: invalid document!" ); } -BasicEntryDescriptor::BasicEntryDescriptor( const ScriptDocument& rDocument, LibraryLocation eLocation, const String& rLibName, const String& rName, const String& rMethodName, BasicEntryType eType ) +BasicEntryDescriptor::BasicEntryDescriptor( const ScriptDocument& rDocument, LibraryLocation eLocation, const String& rLibName, const String& rLibSubName, const String& rName, const String& rMethodName, BasicEntryType eType ) :m_aDocument( rDocument ) ,m_eLocation( eLocation ) ,m_aLibName( rLibName ) + ,m_aLibSubName( rLibSubName ) ,m_aName( rName ) ,m_aMethodName( rMethodName ) ,m_eType( eType ) @@ -117,6 +137,7 @@ BasicEntryDescriptor::BasicEntryDescriptor( const BasicEntryDescriptor& rDesc ) :m_aDocument( rDesc.m_aDocument ) ,m_eLocation( rDesc.m_eLocation ) ,m_aLibName( rDesc.m_aLibName ) + ,m_aLibSubName( rDesc.m_aLibSubName ) ,m_aName( rDesc.m_aName ) ,m_aMethodName( rDesc.m_aMethodName ) ,m_eType( rDesc.m_eType ) @@ -128,6 +149,7 @@ BasicEntryDescriptor& BasicEntryDescriptor::operator=( const BasicEntryDescripto m_aDocument = rDesc.m_aDocument; m_eLocation = rDesc.m_eLocation; m_aLibName = rDesc.m_aLibName; + m_aLibSubName = rDesc.m_aLibSubName; m_aName = rDesc.m_aName; m_aMethodName = rDesc.m_aMethodName; m_eType = rDesc.m_eType; @@ -140,6 +162,7 @@ bool BasicEntryDescriptor::operator==( const BasicEntryDescriptor& rDesc ) const return m_aDocument == rDesc.m_aDocument && m_eLocation == rDesc.m_eLocation && m_aLibName == rDesc.m_aLibName && + m_aLibSubName == rDesc.m_aLibSubName && m_aName == rDesc.m_aName && m_aMethodName == rDesc.m_aMethodName && m_eType == rDesc.m_eType; @@ -284,6 +307,11 @@ void BasicTreeListBox::ImpCreateLibSubEntries( SvLBoxEntry* pLibRootEntry, const { try { + sal_Bool bVBAEnabled = rDocument.isInVBAMode(); + if( bVBAEnabled ) + ImpCreateLibSubEntriesInVBAMode( pLibRootEntry, rDocument, rLibName ); + else + { // get a sorted list of module names Sequence< ::rtl::OUString > aModNames = rDocument.getObjectNames( E_SCRIPTS, rLibName ); sal_Int32 nModCount = aModNames.getLength(); @@ -323,6 +351,7 @@ void BasicTreeListBox::ImpCreateLibSubEntries( SvLBoxEntry* pLibRootEntry, const } } } + } catch ( const container::NoSuchElementException& ) { DBG_UNHANDLED_EXCEPTION(); @@ -365,6 +394,139 @@ void BasicTreeListBox::ImpCreateLibSubEntries( SvLBoxEntry* pLibRootEntry, const } } +void BasicTreeListBox::ImpCreateLibSubEntriesInVBAMode( SvLBoxEntry* pLibRootEntry, const ScriptDocument& rDocument, const String& rLibName ) +{ + ::std::map< BasicEntryType, ::rtl::OUString > aEntryMap; + aEntryMap.insert( ::std::make_pair( OBJ_TYPE_DOCUMENT_OBJECTS, String( IDEResId( RID_STR_DOCUMENT_OBJECTS ) ) ) ); + aEntryMap.insert( ::std::make_pair( OBJ_TYPE_USERFORMS, String( IDEResId( RID_STR_USERFORMS ) ) ) ); + aEntryMap.insert( ::std::make_pair( OBJ_TYPE_NORMAL_MODULES, String( IDEResId( RID_STR_NORMAL_MODULES ) ) ) ); + aEntryMap.insert( ::std::make_pair( OBJ_TYPE_CLASS_MODULES, String( IDEResId( RID_STR_CLASS_MODULES ) ) ) ); + + ::std::map< BasicEntryType, ::rtl::OUString >::iterator iter; + for( iter = aEntryMap.begin(); iter != aEntryMap.end(); ++iter ) + { + BasicEntryType eType = iter->first; + ::rtl::OUString aEntryName = iter->second; + SvLBoxEntry* pLibSubRootEntry = FindEntry( pLibRootEntry, aEntryName, eType ); + if( pLibSubRootEntry ) + { + SetEntryBitmaps( pLibSubRootEntry, Image( IDEResId( RID_IMG_MODLIB ) ), Image( IDEResId( RID_IMG_MODLIB_HC ) ) ); + if ( IsExpanded( pLibSubRootEntry ) ) + ImpCreateLibSubSubEntriesInVBAMode( pLibSubRootEntry, rDocument, rLibName ); + } + else + { + pLibSubRootEntry = AddEntry( + aEntryName, + Image( IDEResId( RID_IMG_MODLIB ) ), + Image( IDEResId( RID_IMG_MODLIB_HC ) ), + pLibRootEntry, true, + std::auto_ptr< BasicEntry >( new BasicEntry( eType ) ) ); + } + } +} + +void BasicTreeListBox::ImpCreateLibSubSubEntriesInVBAMode( SvLBoxEntry* pLibSubRootEntry, const ScriptDocument& rDocument, const String& rLibName ) +{ + uno::Reference< container::XNameContainer > xLib = rDocument.getOrCreateLibrary( E_SCRIPTS, rLibName ); + if( !xLib.is() ) + return; + + try + { + // get a sorted list of module names + Sequence< ::rtl::OUString > aModNames = rDocument.getObjectNames( E_SCRIPTS, rLibName ); + sal_Int32 nModCount = aModNames.getLength(); + const ::rtl::OUString* pModNames = aModNames.getConstArray(); + + BasicEntryDescriptor aDesc( GetEntryDescriptor( pLibSubRootEntry ) ); + BasicEntryType eCurrentType( aDesc.GetType() ); + + for ( sal_Int32 i = 0 ; i < nModCount ; i++ ) + { + String aModName = pModNames[ i ]; + BasicEntryType eType = OBJ_TYPE_UNKNOWN; + switch( lcl_getModuleType( xLib, aModName ) ) + { + case script::ModuleType::Document: + eType = OBJ_TYPE_DOCUMENT_OBJECTS; + break; + case script::ModuleType::Form: + eType = OBJ_TYPE_USERFORMS; + break; + case script::ModuleType::Normal: + eType = OBJ_TYPE_NORMAL_MODULES; + break; + case script::ModuleType::Class: + eType = OBJ_TYPE_CLASS_MODULES; + break; + } + if( eType != eCurrentType ) + continue; + + // display a nice friendly name in the ObjectModule tab, + // combining the objectname and module name, e.g. Sheet1 ( Financials ) + String aEntryName( aModName ); + if( eType == OBJ_TYPE_DOCUMENT_OBJECTS ) + { + String sObjName; + lcl_getObjectName( xLib, aModName, sObjName ); + if( sObjName.Len() ) + { + aEntryName.AppendAscii(" (").Append(sObjName).AppendAscii(")"); + } + } + SvLBoxEntry* pModuleEntry = FindEntry( pLibSubRootEntry, aEntryName, OBJ_TYPE_MODULE ); + if ( !pModuleEntry ) + pModuleEntry = AddEntry( + aEntryName, + Image( IDEResId( RID_IMG_MODULE ) ), + Image( IDEResId( RID_IMG_MODULE_HC ) ), + pLibSubRootEntry, false, + std::auto_ptr< BasicEntry >( new BasicEntry( OBJ_TYPE_MODULE ) ) ); + + // methods + if ( nMode & BROWSEMODE_SUBS ) + { + Sequence< ::rtl::OUString > aNames = BasicIDE::GetMethodNames( rDocument, rLibName, aModName ); + sal_Int32 nCount = aNames.getLength(); + const ::rtl::OUString* pNames = aNames.getConstArray(); + + for ( sal_Int32 j = 0 ; j < nCount ; j++ ) + { + String aName = pNames[ j ]; + SvLBoxEntry* pEntry = FindEntry( pModuleEntry, aName, OBJ_TYPE_METHOD ); + if ( !pEntry ) + pEntry = AddEntry( + aName, + Image( IDEResId( RID_IMG_MACRO ) ), + Image( IDEResId( RID_IMG_MACRO_HC ) ), + pModuleEntry, false, + std::auto_ptr< BasicEntry >( new BasicEntry( OBJ_TYPE_METHOD ) ) ); + } + } + } + } + catch ( const container::NoSuchElementException& ) + { + DBG_UNHANDLED_EXCEPTION(); + } +} + +SvLBoxEntry* BasicTreeListBox::ImpFindEntry( SvLBoxEntry* pParent, const String& rText ) +{ + ULONG nRootPos = 0; + SvLBoxEntry* pEntry = pParent ? FirstChild( pParent ) : GetEntry( nRootPos ); + while ( pEntry ) + { + if ( GetEntryText( pEntry ) == rText ) + return pEntry; + + pEntry = pParent ? NextSibling( pEntry ) : GetEntry( ++nRootPos ); + } + return 0; +} + void BasicTreeListBox::onDocumentCreated( const ScriptDocument& /*_rDocument*/ ) { UpdateEntries(); @@ -477,10 +639,11 @@ long BasicTreeListBox::ExpandingHdl() if ( aDocument.isAlive() ) { String aLibName( aDesc.GetLibName() ); + String aLibSubName( aDesc.GetLibSubName() ); String aName( aDesc.GetName() ); String aMethodName( aDesc.GetMethodName() ); - if ( aLibName.Len() && !aName.Len() && !aMethodName.Len() ) + if ( aLibName.Len() && !aLibSubName.Len() && !aName.Len() && !aMethodName.Len() ) { // check password, if library is password protected and not verified ::rtl::OUString aOULibName( aLibName ); @@ -633,7 +796,7 @@ void BasicTreeListBox::SetCurrentEntry( BasicEntryDescriptor& rDesc ) aDesc = BasicEntryDescriptor( ScriptDocument::getApplicationScriptDocument(), LIBRARY_LOCATION_USER, String::CreateFromAscii( "Standard" ), - String::CreateFromAscii( "." ), OBJ_TYPE_UNKNOWN ); + String(), String::CreateFromAscii( "." ), OBJ_TYPE_UNKNOWN ); } ScriptDocument aDocument( aDesc.GetDocument() ); OSL_ENSURE( aDocument.isValid(), "BasicTreeListBox::SetCurrentEntry: invalid document!" ); @@ -650,14 +813,24 @@ void BasicTreeListBox::SetCurrentEntry( BasicEntryDescriptor& rDesc ) if ( pLibEntry ) { pCurEntry = pLibEntry; + String aLibSubName( aDesc.GetLibSubName() ); + if( aLibSubName.Len() ) + { + Expand( pLibEntry ); + SvLBoxEntry* pLibSubEntry = ImpFindEntry( pLibEntry, aLibSubName ); + if( pLibSubEntry ) + { + pCurEntry = pLibSubEntry; + } + } String aName( aDesc.GetName() ); if ( aName.Len() ) { - Expand( pLibEntry ); + Expand( pCurEntry ); BasicEntryType eType = OBJ_TYPE_MODULE; if ( aDesc.GetType() == OBJ_TYPE_DIALOG ) eType = OBJ_TYPE_DIALOG; - SvLBoxEntry* pEntry = FindEntry( pLibEntry, aName, eType ); + SvLBoxEntry* pEntry = FindEntry( pCurEntry, aName, eType ); if ( pEntry ) { pCurEntry = pEntry; diff --git a/basctl/source/basicide/bastype2.hxx b/basctl/source/basicide/bastype2.hxx index 401282f7e1bf..4b4d42f477d0 100644 --- a/basctl/source/basicide/bastype2.hxx +++ b/basctl/source/basicide/bastype2.hxx @@ -39,7 +39,7 @@ #include <sbxitem.hxx> #include "basobj.hxx" -enum BasicEntryType { OBJ_TYPE_UNKNOWN, OBJ_TYPE_DOCUMENT, OBJ_TYPE_LIBRARY, OBJ_TYPE_MODULE, OBJ_TYPE_DIALOG, OBJ_TYPE_METHOD }; +enum BasicEntryType { OBJ_TYPE_UNKNOWN, OBJ_TYPE_DOCUMENT, OBJ_TYPE_LIBRARY, OBJ_TYPE_MODULE, OBJ_TYPE_DIALOG, OBJ_TYPE_METHOD, OBJ_TYPE_DOCUMENT_OBJECTS, OBJ_TYPE_USERFORMS, OBJ_TYPE_NORMAL_MODULES, OBJ_TYPE_CLASS_MODULES }; #define BROWSEMODE_MODULES 0x01 #define BROWSEMODE_SUBS 0x02 @@ -98,14 +98,15 @@ class BasicEntryDescriptor ScriptDocument m_aDocument; LibraryLocation m_eLocation; String m_aLibName; + String m_aLibSubName; // for vba entry: Document Objects, Class Modules, Forms and Normal Modules String m_aName; String m_aMethodName; BasicEntryType m_eType; public: BasicEntryDescriptor(); - BasicEntryDescriptor( const ScriptDocument& rDocument, LibraryLocation eLocation, const String& rLibName, const String& rName, BasicEntryType eType ); - BasicEntryDescriptor( const ScriptDocument& rDocument, LibraryLocation eLocation, const String& rLibName, const String& rName, const String& rMethodName, BasicEntryType eType ); + BasicEntryDescriptor( const ScriptDocument& rDocument, LibraryLocation eLocation, const String& rLibName, const String& rLibSubName, const String& rName, BasicEntryType eType ); + BasicEntryDescriptor( const ScriptDocument& rDocument, LibraryLocation eLocation, const String& rLibName, const String& rLibSubName, const String& rName, const String& rMethodName, BasicEntryType eType ); virtual ~BasicEntryDescriptor(); BasicEntryDescriptor( const BasicEntryDescriptor& rDesc ); @@ -122,6 +123,9 @@ public: const String& GetLibName() const { return m_aLibName; } void SetLibName( const String& aLibName ) { m_aLibName = aLibName; } + const String& GetLibSubName() const { return m_aLibSubName; } + void SetLibSubName( const String& aLibSubName ) { m_aLibSubName = aLibSubName; } + const String& GetName() const { return m_aName; } void SetName( const String& aName ) { m_aName = aName; } @@ -161,6 +165,9 @@ protected: void ImpCreateLibEntries( SvLBoxEntry* pShellRootEntry, const ScriptDocument& rDocument, LibraryLocation eLocation ); void ImpCreateLibSubEntries( SvLBoxEntry* pLibRootEntry, const ScriptDocument& rDocument, const String& rLibName ); + void ImpCreateLibSubEntriesInVBAMode( SvLBoxEntry* pLibRootEntry, const ScriptDocument& rDocument, const String& rLibName ); + void ImpCreateLibSubSubEntriesInVBAMode( SvLBoxEntry* pLibSubRootEntry, const ScriptDocument& rDocument, const String& rLibName ); + SvLBoxEntry* ImpFindEntry( SvLBoxEntry* pParent, const String& rText ); // DocumentEventListener virtual void onDocumentCreated( const ScriptDocument& _rDocument ); diff --git a/basctl/source/basicide/bastype3.cxx b/basctl/source/basicide/bastype3.cxx index a0320d89e88a..de9eff56ca24 100644 --- a/basctl/source/basicide/bastype3.cxx +++ b/basctl/source/basicide/bastype3.cxx @@ -131,6 +131,14 @@ void __EXPORT BasicTreeListBox::RequestingChilds( SvLBoxEntry* pEntry ) } } } + else if ( eType == OBJ_TYPE_DOCUMENT_OBJECTS + || eType == OBJ_TYPE_USERFORMS + || eType == OBJ_TYPE_NORMAL_MODULES + || eType == OBJ_TYPE_CLASS_MODULES ) + { + String aLibName( aDesc.GetLibName() ); + ImpCreateLibSubSubEntriesInVBAMode( pEntry, aDocument, aLibName ); + } else { DBG_ERROR( "BasicTreeListBox::RequestingChilds: Unknown Type!" ); } @@ -201,6 +209,7 @@ SbxVariable* BasicTreeListBox::FindVariable( SvLBoxEntry* pEntry ) } SbxVariable* pVar = 0; + bool bDocumentObjects = false; if ( aEntries.Count() ) { for ( USHORT n = 0; n < aEntries.Count(); n++ ) @@ -223,6 +232,12 @@ SbxVariable* BasicTreeListBox::FindVariable( SvLBoxEntry* pEntry ) case OBJ_TYPE_MODULE: { DBG_ASSERT( pVar && pVar->IsA( TYPE(StarBASIC) ), "FindVariable: Ungueltiges Basic" ); + // extract the module name from the string like "Sheet1 (Example1)" + if( bDocumentObjects ) + { + sal_uInt16 nIndex = 0; + aName = aName.GetToken( 0, ' ', nIndex ); + } pVar = ((StarBASIC*)pVar)->FindModule( aName ); } break; @@ -237,6 +252,15 @@ SbxVariable* BasicTreeListBox::FindVariable( SvLBoxEntry* pEntry ) // sbx dialogs removed } break; + case OBJ_TYPE_DOCUMENT_OBJECTS: + bDocumentObjects = true; + case OBJ_TYPE_USERFORMS: + case OBJ_TYPE_NORMAL_MODULES: + case OBJ_TYPE_CLASS_MODULES: + { + // skip, to find the child entry. + continue; + } default: { DBG_ERROR( "FindVariable: Unbekannter Typ!" ); @@ -257,12 +281,13 @@ BasicEntryDescriptor BasicTreeListBox::GetEntryDescriptor( SvLBoxEntry* pEntry ) ScriptDocument aDocument( ScriptDocument::getApplicationScriptDocument() ); LibraryLocation eLocation = LIBRARY_LOCATION_UNKNOWN; String aLibName; + String aLibSubName; String aName; String aMethodName; BasicEntryType eType = OBJ_TYPE_UNKNOWN; if ( !pEntry ) - return BasicEntryDescriptor( aDocument, eLocation, aLibName, aName, aMethodName, eType ); + return BasicEntryDescriptor( aDocument, eLocation, aLibName, aLibSubName, aName, aMethodName, eType ); EntryArray aEntries; @@ -329,6 +354,15 @@ BasicEntryDescriptor BasicTreeListBox::GetEntryDescriptor( SvLBoxEntry* pEntry ) eType = pBE->GetType(); } break; + case OBJ_TYPE_DOCUMENT_OBJECTS: + case OBJ_TYPE_USERFORMS: + case OBJ_TYPE_NORMAL_MODULES: + case OBJ_TYPE_CLASS_MODULES: + { + aLibSubName = GetEntryText( pLE ); + eType = pBE->GetType(); + } + break; default: { DBG_ERROR( "GetEntryDescriptor: Unbekannter Typ!" ); @@ -342,7 +376,7 @@ BasicEntryDescriptor BasicTreeListBox::GetEntryDescriptor( SvLBoxEntry* pEntry ) } } - return BasicEntryDescriptor( aDocument, eLocation, aLibName, aName, aMethodName, eType ); + return BasicEntryDescriptor( aDocument, eLocation, aLibName, aLibSubName, aName, aMethodName, eType ); } USHORT BasicTreeListBox::ConvertType( BasicEntryType eType ) @@ -424,6 +458,14 @@ bool BasicTreeListBox::IsValidEntry( SvLBoxEntry* pEntry ) bIsValid = BasicIDE::HasMethod( aDocument, aLibName, aName, aMethodName ); } break; + case OBJ_TYPE_DOCUMENT_OBJECTS: + case OBJ_TYPE_USERFORMS: + case OBJ_TYPE_NORMAL_MODULES: + case OBJ_TYPE_CLASS_MODULES: + { + bIsValid = true; + } + break; default: ; } diff --git a/basctl/source/basicide/bastypes.cxx b/basctl/source/basicide/bastypes.cxx index af42503a5dae..53f33dfc7e89 100644 --- a/basctl/source/basicide/bastypes.cxx +++ b/basctl/source/basicide/bastypes.cxx @@ -57,6 +57,7 @@ #include <com/sun/star/script/XLibraryContainer2.hpp> #endif #include <com/sun/star/script/XLibraryContainerPassword.hpp> +#include <com/sun/star/script/ModuleType.hpp> using namespace ::com::sun::star::uno; using namespace ::com::sun::star; @@ -584,7 +585,29 @@ void __EXPORT BasicIDETabBar::Command( const CommandEvent& rCEvt ) aPopup.EnableItem( SID_BASICIDE_RENAMECURRENT, FALSE ); aPopup.RemoveDisabledEntries(); } + + // disable to delete or remove object modules in IDE + BasicManager* pBasMgr = aDocument.getBasicManager(); + if ( pBasMgr ) + { + StarBASIC* pBasic = pBasMgr->GetLib( aOULibName ); + if( pBasic ) + { + IDEWindowTable& aIDEWindowTable = pIDEShell->GetIDEWindowTable(); + IDEBaseWindow* pWin = aIDEWindowTable.Get( GetCurPageId() ); + if( pWin && pWin->ISA( ModulWindow ) ) + { + SbModule* pActiveModule = (SbModule*)pBasic->FindModule( pWin->GetName() ); + if( pActiveModule && ( pActiveModule->GetModuleType() == script::ModuleType::Document ) ) + { + aPopup.EnableItem( SID_BASICIDE_DELETECURRENT, FALSE ); + aPopup.EnableItem( SID_BASICIDE_RENAMECURRENT, FALSE ); } + } + } + } + } + SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL; SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL; diff --git a/basctl/source/basicide/macrodlg.cxx b/basctl/source/basicide/macrodlg.cxx index f3e41e60d34b..41a5fa488950 100644 --- a/basctl/source/basicide/macrodlg.cxx +++ b/basctl/source/basicide/macrodlg.cxx @@ -382,7 +382,15 @@ SbMethod* MacroChooser::CreateMacro() SbModule* pModule = 0; String aModName( aDesc.GetName() ); if ( aModName.Len() ) + { + // extract the module name from the string like "Sheet1 (Example1)" + if( aDesc.GetLibSubName().Equals( String( IDEResId( RID_STR_DOCUMENT_OBJECTS ) ) ) ) + { + sal_uInt16 nIndex = 0; + aModName = aModName.GetToken( 0, ' ', nIndex ); + } pModule = pBasic->FindModule( aModName ); + } else if ( pBasic->GetModules()->Count() ) pModule = (SbModule*)pBasic->GetModules()->Get( 0 ); @@ -710,6 +718,12 @@ IMPL_LINK( MacroChooser, ButtonHdl, Button *, pButton ) BasicManager* pBasMgr = aDocument.getBasicManager(); String aLib( aDesc.GetLibName() ); String aMod( aDesc.GetName() ); + // extract the module name from the string like "Sheet1 (Example1)" + if( aDesc.GetLibSubName().Equals( String( IDEResId( RID_STR_DOCUMENT_OBJECTS ) ) ) ) + { + sal_uInt16 nIndex = 0; + aMod = aMod.GetToken( 0, ' ', nIndex ); + } String aSub( aDesc.GetMethodName() ); SfxMacroInfoItem aInfoItem( SID_BASICIDE_ARG_MACROINFO, pBasMgr, aLib, aMod, aSub, String() ); if ( pButton == &aEditButton ) diff --git a/basctl/source/basicide/moduldlg.cxx b/basctl/source/basicide/moduldlg.cxx index 478d56546f41..0f66a6ebe120 100644 --- a/basctl/source/basicide/moduldlg.cxx +++ b/basctl/source/basicide/moduldlg.cxx @@ -84,7 +84,7 @@ BOOL __EXPORT ExtBasicTreeListBox::EditingEntry( SvLBoxEntry* pEntry, Selection& if ( pEntry ) { USHORT nDepth = GetModel()->GetDepth( pEntry ); - if ( nDepth == 2 ) + if ( nDepth >= 2 ) { BasicEntryDescriptor aDesc( GetEntryDescriptor( pEntry ) ); ScriptDocument aDocument( aDesc.GetDocument() ); @@ -162,7 +162,7 @@ DragDropMode __EXPORT ExtBasicTreeListBox::NotifyStartDrag( TransferDataContaine if ( pEntry ) { USHORT nDepth = GetModel()->GetDepth( pEntry ); - if ( nDepth == 2 ) + if ( nDepth >= 2 ) { nMode_ = SV_DRAGDROP_CTRL_COPY; BasicEntryDescriptor aDesc( GetEntryDescriptor( pEntry ) ); @@ -210,7 +210,7 @@ BOOL __EXPORT ExtBasicTreeListBox::NotifyAcceptDrop( SvLBoxEntry* pEntry ) // don't drop on a library, which is not loaded, readonly or password protected // or which already has a module/dialog with this name - if ( bValid && ( nDepth == 1 || nDepth == 2 ) ) + if ( bValid && ( nDepth > 0 ) ) { // get source module/dialog name BasicEntryDescriptor aSourceDesc( GetEntryDescriptor( pSelected ) ); @@ -348,7 +348,7 @@ BOOL __EXPORT ExtBasicTreeListBox::NotifyCopyingMoving( SvLBoxEntry* pTarget, Sv rpNewParent = pTarget; rNewChildPos = 0; } - else if ( nDepth == 2 ) + else if ( nDepth >= 2 ) { // Target = Modul/Dialog => Modul/Dialog unter das uebergeordnete Basic haengen... rpNewParent = GetParent( pTarget ); @@ -623,20 +623,29 @@ void ObjectPage::CheckButtons() { // enable/disable edit button SvLBoxEntry* pCurEntry = aBasicBox.GetCurEntry(); + BasicEntryDescriptor aDesc( aBasicBox.GetEntryDescriptor( pCurEntry ) ); + ScriptDocument aDocument( aDesc.GetDocument() ); + ::rtl::OUString aOULibName( aDesc.GetLibName() ); + String aLibSubName( aDesc.GetLibSubName() ); + sal_Bool bVBAEnabled = aDocument.isInVBAMode(); + USHORT nMode = aBasicBox.GetMode(); + USHORT nDepth = pCurEntry ? aBasicBox.GetModel()->GetDepth( pCurEntry ) : 0; - if ( nDepth == 2 ) + if ( nDepth >= 2 ) + { + if( bVBAEnabled && ( nMode & BROWSEMODE_MODULES ) && ( nDepth == 2 ) ) + aEditButton.Disable(); + else aEditButton.Enable(); + } else aEditButton.Disable(); // enable/disable new module/dialog buttons - BasicEntryDescriptor aDesc( aBasicBox.GetEntryDescriptor( pCurEntry ) ); LibraryLocation eLocation( aDesc.GetLocation() ); BOOL bReadOnly = FALSE; - if ( nDepth == 1 || nDepth == 2 ) + if ( nDepth > 0 ) { - ScriptDocument aDocument( aDesc.GetDocument() ); - ::rtl::OUString aOULibName( aDesc.GetLibName() ); Reference< script::XLibraryContainer2 > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY ); Reference< script::XLibraryContainer2 > xDlgLibContainer( aDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY ); if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryReadOnly( aOULibName ) ) || @@ -657,8 +666,13 @@ void ObjectPage::CheckButtons() } // enable/disable delete button - if ( nDepth == 2 && !bReadOnly && eLocation != LIBRARY_LOCATION_SHARE ) + if ( nDepth >= 2 && !bReadOnly && eLocation != LIBRARY_LOCATION_SHARE ) + { + if( bVBAEnabled && ( nMode & BROWSEMODE_MODULES ) && ( ( nDepth == 2 ) || aLibSubName.Equals( String( IDEResId( RID_STR_DOCUMENT_OBJECTS ) ) ) ) ) + aDelButton.Disable(); + else aDelButton.Enable(); + } else aDelButton.Disable(); } @@ -685,13 +699,20 @@ IMPL_LINK( ObjectPage, ButtonHdl, Button *, pButton ) SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL; SvLBoxEntry* pCurEntry = aBasicBox.GetCurEntry(); DBG_ASSERT( pCurEntry, "Entry?!" ); - if ( aBasicBox.GetModel()->GetDepth( pCurEntry ) == 2 ) + if ( aBasicBox.GetModel()->GetDepth( pCurEntry ) >= 2 ) { BasicEntryDescriptor aDesc( aBasicBox.GetEntryDescriptor( pCurEntry ) ); if ( pDispatcher ) { + String aModName( aDesc.GetName() ); + // extract the module name from the string like "Sheet1 (Example1)" + if( aDesc.GetLibSubName().Equals( String( IDEResId( RID_STR_DOCUMENT_OBJECTS ) ) ) ) + { + sal_uInt16 nIndex = 0; + aModName = aModName.GetToken( 0, ' ', nIndex ); + } SbxItem aSbxItem( SID_BASICIDE_ARG_SBX, aDesc.GetDocument(), aDesc.GetLibName(), - aDesc.GetName(), aBasicBox.ConvertType( aDesc.GetType() ) ); + aModName, aBasicBox.ConvertType( aDesc.GetType() ) ); pDispatcher->Execute( SID_BASICIDE_SHOWSBX, SFX_CALLMODE_SYNCHRON, &aSbxItem, 0L ); } } @@ -973,14 +994,14 @@ SbModule* createModImpl( Window* pWin, const ScriptDocument& rDocument, try { ::rtl::OUString sModuleCode; + // the module has existed + if( rDocument.hasModule( aLibName, aModName ) ) + return NULL; rDocument.createModule( aLibName, aModName, bMain, sModuleCode ); BasicManager* pBasMgr = rDocument.getBasicManager(); - if ( pBasMgr ) - { - StarBASIC* pBasic = pBasMgr->GetLib( aLibName ); + StarBASIC* pBasic = pBasMgr? pBasMgr->GetLib( aLibName ) : 0; if ( pBasic ) pModule = pBasic->FindModule( aModName ); - } SbxItem aSbxItem( SID_BASICIDE_ARG_SBX, rDocument, aLibName, aModName, BASICIDE_TYPE_MODULE ); BasicIDEShell* pIDEShell = IDE_DLL()->GetShell(); SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL; @@ -1002,14 +1023,27 @@ SbModule* createModImpl( Window* pWin, const ScriptDocument& rDocument, { if ( !rBasicBox.IsExpanded( pLibEntry ) ) rBasicBox.Expand( pLibEntry ); - SvLBoxEntry* pEntry = rBasicBox.FindEntry( pLibEntry, aModName, OBJ_TYPE_MODULE ); + SvLBoxEntry* pSubRootEntry = pLibEntry; + if( pBasic && rDocument.isInVBAMode() ) + { + // add the new module in the "Modules" entry + SvLBoxEntry* pLibSubEntry = rBasicBox.FindEntry( pLibEntry, String( IDEResId( RID_STR_NORMAL_MODULES ) ) , OBJ_TYPE_NORMAL_MODULES ); + if( pLibSubEntry ) + { + if( !rBasicBox.IsExpanded( pLibSubEntry ) ) + rBasicBox.Expand( pLibSubEntry ); + pSubRootEntry = pLibSubEntry; + } + } + + SvLBoxEntry* pEntry = rBasicBox.FindEntry( pSubRootEntry, aModName, OBJ_TYPE_MODULE ); if ( !pEntry ) { pEntry = rBasicBox.AddEntry( aModName, Image( IDEResId( RID_IMG_MODULE ) ), Image( IDEResId( RID_IMG_MODULE_HC ) ), - pLibEntry, false, + pSubRootEntry, false, std::auto_ptr< BasicEntry >( new BasicEntry( OBJ_TYPE_MODULE ) ) ); DBG_ASSERT( pEntry, "InsertEntry fehlgeschlagen!" ); } diff --git a/basctl/source/basicide/scriptdocument.cxx b/basctl/source/basicide/scriptdocument.cxx index dd10a00e2bde..f246e1613dd8 100644 --- a/basctl/source/basicide/scriptdocument.cxx +++ b/basctl/source/basicide/scriptdocument.cxx @@ -53,6 +53,8 @@ #include <com/sun/star/frame/XModel2.hpp> #include <com/sun/star/awt/XWindow2.hpp> #include <com/sun/star/document/XEmbeddedScripts.hpp> +#include <com/sun/star/script/XVBAModuleInfo.hpp> +#include <com/sun/star/script/XVBACompat.hpp> /** === end UNO includes === **/ #include <sfx2/objsh.hxx> @@ -139,6 +141,9 @@ namespace basctl using ::com::sun::star::uno::RuntimeException; using ::com::sun::star::document::XEventBroadcaster; using ::com::sun::star::document::XEmbeddedScripts; + using ::com::sun::star::script::ModuleInfo; + using ::com::sun::star::script::XVBAModuleInfo; + using ::com::sun::star::script::XVBACompat; /** === end UNO using === **/ namespace MacroExecMode = ::com::sun::star::document::MacroExecMode; namespace FrameSearchFlag = ::com::sun::star::frame::FrameSearchFlag; @@ -272,6 +277,7 @@ namespace basctl // versions with the same signature/semantics as in ScriptDocument itself bool isReadOnly() const; + bool isInVBAMode() const; BasicManager* getBasicManager() const; Reference< XModel > @@ -444,6 +450,18 @@ namespace basctl return bIsReadOnly; } + bool ScriptDocument_Impl::isInVBAMode() const + { + bool bResult = false; + if ( !isApplication() ) + { + Reference< XVBACompat > xVBACompat( getLibraryContainer( E_SCRIPTS ), UNO_QUERY ); + if ( xVBACompat.is() ) + bResult = xVBACompat->getVBACompatModeOn(); + } + return bResult; + } + //-------------------------------------------------------------------- BasicManager* ScriptDocument_Impl::getBasicManager() const { @@ -462,6 +480,8 @@ namespace basctl { OSL_ENSURE( isValid(), "ScriptDocument_Impl::getDocument: invalid state!" ); OSL_ENSURE( isDocument(), "ScriptDocument_Impl::getDocument: for documents only!" ); + if ( !isDocument() ) + OSL_TRACE("**** BAHHHH!!!*****"); if ( !isValid() || !isDocument() ) return NULL; @@ -671,6 +691,16 @@ namespace basctl } // insert element by new name in container + if ( _eType == E_SCRIPTS ) + { + Reference< XVBAModuleInfo > xVBAModuleInfo( xLib, UNO_QUERY ); + if ( xVBAModuleInfo->hasModuleInfo( _rOldName ) ) + { + ModuleInfo sModuleInfo = xVBAModuleInfo->getModuleInfo( _rOldName ); + xVBAModuleInfo->removeModuleInfo( _rOldName ); + xVBAModuleInfo->insertModuleInfo( _rNewName, sModuleInfo ); + } + } xLib->insertByName( _rNewName, aElement ); return true; } @@ -735,8 +765,7 @@ namespace basctl Reference< XNameContainer > xLib( getOrCreateLibrary( E_SCRIPTS, _rLibName ), UNO_QUERY_THROW ); if ( !xLib->hasByName( _rModName ) ) return false; - - xLib->replaceByName( _rModName, makeAny( _rModuleCode ) ); + xLib->replaceByName( _rModName, makeAny( _rModuleCode ) ); return true; } catch( const Exception& ) @@ -1351,6 +1380,11 @@ namespace basctl return m_pImpl->isApplication(); } + bool ScriptDocument::isInVBAMode() const + { + return m_pImpl->isInVBAMode(); + } + //-------------------------------------------------------------------- BasicManager* ScriptDocument::getBasicManager() const { diff --git a/basctl/source/dlged/dlged.cxx b/basctl/source/dlged/dlged.cxx index 326098976d87..65059f3b759b 100644 --- a/basctl/source/dlged/dlged.cxx +++ b/basctl/source/dlged/dlged.cxx @@ -205,7 +205,7 @@ BOOL DlgEditor::RemarkDialog() //---------------------------------------------------------------------------- -DlgEditor::DlgEditor() +DlgEditor::DlgEditor( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xModel ) :pHScroll(NULL) ,pVScroll(NULL) ,pDlgEdModel(NULL) @@ -227,6 +227,7 @@ DlgEditor::DlgEditor() ,bCreateOK(TRUE) ,bDialogModelChanged(FALSE) ,mnPaintGuard(0) + ,m_xDocument( xModel ) { pDlgEdModel = new DlgEdModel(); pDlgEdModel->GetItemPool().FreezeIdRanges(); diff --git a/basctl/source/dlged/dlgedobj.cxx b/basctl/source/dlged/dlgedobj.cxx index 5af7519f85f0..fcade49d1c8b 100644 --- a/basctl/source/dlged/dlgedobj.cxx +++ b/basctl/source/dlged/dlgedobj.cxx @@ -74,6 +74,22 @@ TYPEINIT1(DlgEdObj, SdrUnoObj); DBG_NAME(DlgEdObj); //---------------------------------------------------------------------------- +MapMode lcl_getMapModeForForm( DlgEdForm* pForm ) +{ + MapMode aMode( MAP_APPFONT ); //Default + try + { + uno::Reference< beans::XPropertySet > xProps( pForm ? pForm->GetUnoControlModel() : NULL, uno::UNO_QUERY_THROW ); + sal_Bool bVBAForm = sal_False; + xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("VBAForm") ) ) >>= bVBAForm; + if ( bVBAForm ) + aMode = MapMode( MAP_100TH_MM ); + } + catch ( Exception& ) + { + } + return aMode; +} DlgEdObj::DlgEdObj() :SdrUnoObj(String(), sal_False) @@ -194,8 +210,9 @@ bool DlgEdObj::TransformSdrToControlCoordinates( } // convert pixel to logic units - aPos = pDevice->PixelToLogic( aPos, MapMode( MAP_APPFONT ) ); - aSize = pDevice->PixelToLogic( aSize, MapMode( MAP_APPFONT ) ); + MapMode aConvMode = lcl_getMapModeForForm( pForm ); + aPos = pDevice->PixelToLogic( aPos, aConvMode ); + aSize = pDevice->PixelToLogic( aSize, aConvMode ); // set out parameters nXOut = aPos.Width(); @@ -242,10 +259,10 @@ bool DlgEdObj::TransformSdrToFormCoordinates( aSize.Width() -= aDeviceInfo.LeftInset + aDeviceInfo.RightInset; aSize.Height() -= aDeviceInfo.TopInset + aDeviceInfo.BottomInset; } - + MapMode aConvMode = lcl_getMapModeForForm( pForm ); // convert pixel to logic units - aPos = pDevice->PixelToLogic( aPos, MapMode( MAP_APPFONT ) ); - aSize = pDevice->PixelToLogic( aSize, MapMode( MAP_APPFONT ) ); + aPos = pDevice->PixelToLogic( aPos, aConvMode ); + aSize = pDevice->PixelToLogic( aSize, aConvMode ); // set out parameters nXOut = aPos.Width(); @@ -287,9 +304,10 @@ bool DlgEdObj::TransformControlToSdrCoordinates( DBG_ASSERT( pDevice, "DlgEdObj::TransformControlToSdrCoordinates: missing default device!" ); if ( !pDevice ) return false; - aPos = pDevice->LogicToPixel( aPos, MapMode( MAP_APPFONT ) ); - aSize = pDevice->LogicToPixel( aSize, MapMode( MAP_APPFONT ) ); - aFormPos = pDevice->LogicToPixel( aFormPos, MapMode( MAP_APPFONT ) ); + MapMode aConvMode = lcl_getMapModeForForm( pForm ); + aPos = pDevice->LogicToPixel( aPos, aConvMode ); + aSize = pDevice->LogicToPixel( aSize, aConvMode ); + aFormPos = pDevice->LogicToPixel( aFormPos, aConvMode ); // add form position aPos.Width() += aFormPos.Width(); @@ -333,14 +351,16 @@ bool DlgEdObj::TransformFormToSdrCoordinates( DBG_ASSERT( pDevice, "DlgEdObj::TransformFormToSdrCoordinates: missing default device!" ); if ( !pDevice ) return false; - aPos = pDevice->LogicToPixel( aPos, MapMode( MAP_APPFONT ) ); - aSize = pDevice->LogicToPixel( aSize, MapMode( MAP_APPFONT ) ); // take window borders into account DlgEdForm* pForm = NULL; if ( !lcl_getDlgEdForm( this, pForm ) ) return false; + MapMode aConvMode = lcl_getMapModeForForm( pForm ); + aPos = pDevice->LogicToPixel( aPos, aConvMode ); + aSize = pDevice->LogicToPixel( aSize, aConvMode ); + // take window borders into account Reference< beans::XPropertySet > xPSetForm( pForm->GetUnoControlModel(), UNO_QUERY ); DBG_ASSERT( xPSetForm.is(), "DlgEdObj::TransformFormToSdrCoordinates: no form property set!" ); diff --git a/basctl/source/inc/basidesh.hxx b/basctl/source/inc/basidesh.hxx index cf21d3488dd3..07bc2dfa3149 100644 --- a/basctl/source/inc/basidesh.hxx +++ b/basctl/source/inc/basidesh.hxx @@ -46,6 +46,7 @@ #include <com/sun/star/io/XInputStreamProvider.hpp> #endif +#include <com/sun/star/container/XContainerListener.hpp> //---------------------------------------------------------------------------- @@ -105,6 +106,8 @@ friend bool BasicIDE::RemoveDialog( const ScriptDocument& rDocument, const Strin BOOL m_bAppBasicModified; ::basctl::DocumentEventNotifier m_aNotifier; +friend class ContainerListenerImpl; + ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener > m_xLibListener; #if _SOLAR__PRIVATE void Init(); diff --git a/basctl/source/inc/dlged.hxx b/basctl/source/inc/dlged.hxx index 1444bab59c65..f49d684cbe80 100644 --- a/basctl/source/inc/dlged.hxx +++ b/basctl/source/inc/dlged.hxx @@ -32,6 +32,7 @@ #include <com/sun/star/awt/XControlContainer.hpp> #include <com/sun/star/datatransfer/DataFlavor.hpp> #include <com/sun/star/util/XNumberFormatsSupplier.hpp> +#include <com/sun/star/frame/XModel.hpp> #include <tools/link.hxx> #include <tools/gen.hxx> #include <vcl/timer.hxx> @@ -128,9 +129,11 @@ protected: BOOL bDialogModelChanged; Timer aMarkTimer; long mnPaintGuard; + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > m_xDocument; + DlgEditor(); // not implemented public: - DlgEditor(); + DlgEditor( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xModel ); ~DlgEditor(); void SetWindow( Window* pWindow ); diff --git a/basctl/source/inc/scriptdocument.hxx b/basctl/source/inc/scriptdocument.hxx index 34d1a72963ce..9439c05f7249 100644 --- a/basctl/source/inc/scriptdocument.hxx +++ b/basctl/source/inc/scriptdocument.hxx @@ -212,6 +212,7 @@ namespace basctl */ bool isAlive() const; + bool isInVBAMode() const; /// returns the BasicManager associated with this instance BasicManager* getBasicManager() const; |