25#include <bitmaps.hlst>
30#include <com/sun/star/script/XLibraryContainerPassword.hpp>
31#include <com/sun/star/frame/ModuleManager.hpp>
34#include <sfx2/sfxsids.hrc>
36#include <initializer_list>
40#include <com/sun/star/script/ModuleType.hpp>
41#include <com/sun/star/script/vba/XVBAModuleInfo.hpp>
42#include <com/sun/star/lang/XServiceInfo.hpp>
43#include <com/sun/star/container/XNamed.hpp>
56 uno::Reference< script::vba::XVBAModuleInfo > xVBAModuleInfo( rLib, uno::UNO_QUERY );
57 if ( xVBAModuleInfo.is() && xVBAModuleInfo->hasModuleInfo( rModName ) )
59 script::ModuleInfo aModuleInfo = xVBAModuleInfo->getModuleInfo( rModName );
60 uno::Any aObject( aModuleInfo.ModuleObject );
61 uno::Reference< lang::XServiceInfo > xServiceInfo( aObject, uno::UNO_QUERY );
62 if( xServiceInfo.is() && xServiceInfo->supportsService(
"ooo.vba.excel.Worksheet" ) )
64 uno::Reference< container::XNamed > xNamed( aObject, uno::UNO_QUERY );
66 rObjName = xNamed->getName();
70 catch(
const uno::Exception& )
77 sal_Int32
nType = script::ModuleType::NORMAL;
78 uno::Reference< script::vba::XVBAModuleInfo > xVBAModuleInfo( rLib, uno::UNO_QUERY );
79 if ( xVBAModuleInfo.is() && xVBAModuleInfo->hasModuleInfo( rModName ) )
81 script::ModuleInfo aModuleInfo = xVBAModuleInfo->getModuleInfo( rModName );
82 nType = aModuleInfo.ModuleType;
97 m_eLocation(eLocation)
99 OSL_ENSURE(
m_aDocument.
isValid(),
"DocumentEntry::DocumentEntry: illegal document!" );
111 m_aLibName(
std::move(aLibName))
127 OUString aLibSubName,
132 m_eLocation(eLocation),
133 m_aLibName(
std::move(aLibName)),
134 m_aLibSubName(
std::move(aLibSubName)),
138 OSL_ENSURE(
m_aDocument.
isValid(),
"EntryDescriptor::EntryDescriptor: invalid document!" );
145 OUString aLibSubName,
147 OUString aMethodName,
151 m_eLocation(eLocation),
152 m_aLibName(
std::move(aLibName)),
153 m_aLibSubName(
std::move(aLibSubName)),
155 m_aMethodName(
std::move(aMethodName)),
158 OSL_ENSURE(
m_aDocument.
isValid(),
"EntryDescriptor::EntryDescriptor: invalid document!" );
164 , m_pTopLevel(pTopLevel)
165 , m_bFreezeOnFirstAddRemove(false)
188 OSL_ENSURE( rDocument.
isAlive(),
"TreeListBox::ScanEntry: illegal document!" );
199 if (!bDocumentRootEntry)
203 AddEntry(aRootName, aImage,
nullptr,
true, std::make_unique<DocumentEntry>(rDocument, eLocation));
211 sal_Int32 nLibCount = aLibNames.getLength();
212 const OUString* pLibNames = aLibNames.getConstArray();
214 for ( sal_Int32
i = 0 ;
i < nLibCount ;
i++ )
216 OUString aLibName = pLibNames[
i ];
221 bool bModLibLoaded =
false;
223 if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) && xModLibContainer->isLibraryLoaded( aLibName ) )
224 bModLibLoaded =
true;
227 bool bDlgLibLoaded =
false;
229 if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) && xDlgLibContainer->isLibraryLoaded( aLibName ) )
230 bDlgLibLoaded =
true;
232 bool bLoaded = bModLibLoaded || bDlgLibLoaded;
237 if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) && !xModLibContainer->isLibraryLoaded( aLibName ) )
238 xModLibContainer->loadLibrary( aLibName );
240 if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) && !xDlgLibContainer->isLibraryLoaded( aLibName ) )
241 xDlgLibContainer->loadLibrary( aLibName );
247 sId = bLoaded ? OUString(RID_BMP_DLGLIB) : OUString(RID_BMP_DLGLIBNOTLOADED);
249 sId = bLoaded ? OUString(RID_BMP_MODLIB) : OUString(RID_BMP_MODLIBNOTLOADED);
250 std::unique_ptr<weld::TreeIter> xLibRootEntry(
m_xControl->make_iterator(&rIter));
255 bool bRowExpanded =
m_xControl->get_row_expanded(*xLibRootEntry);
256 bool bRowExpandAttempted = !
m_xControl->get_children_on_demand(*xLibRootEntry);
257 if (bRowExpanded || bRowExpandAttempted)
275 if ( xModLibContainer.is() && xModLibContainer->hasByName( rLibName ) && xModLibContainer->isLibraryLoaded( rLibName ) )
287 sal_Int32 nModCount = aModNames.getLength();
288 const OUString* pModNames = aModNames.getConstArray();
292 for ( sal_Int32
i = 0 ;
i < nModCount ;
i++ )
294 OUString aModName = pModNames[
i ];
295 m_xControl->copy_iterator(rLibRootEntry, *xTreeIter);
299 AddEntry(aModName, RID_BMP_MODULE, &rLibRootEntry,
false, std::make_unique<Entry>(
OBJ_TYPE_MODULE), xTreeIter.get());
306 sal_Int32
nCount = aNames.getLength();
307 const OUString* pNames = aNames.getConstArray();
309 auto xSubTreeIter =
m_xControl->make_iterator();
311 for ( sal_Int32 j = 0 ; j <
nCount ; j++ )
313 OUString
aName = pNames[ j ];
314 m_xControl->copy_iterator(*xTreeIter, *xSubTreeIter);
325 catch (
const container::NoSuchElementException& )
338 if ( !(xDlgLibContainer.is() && xDlgLibContainer->hasByName( rLibName ) && xDlgLibContainer->isLibraryLoaded( rLibName )) )
345 sal_Int32 nDlgCount = aDlgNames.getLength();
346 const OUString* pDlgNames = aDlgNames.getConstArray();
350 for ( sal_Int32
i = 0 ;
i < nDlgCount ;
i++ )
352 OUString aDlgName = pDlgNames[
i ];
353 m_xControl->copy_iterator(rLibRootEntry, *xTreeIter);
361 catch (
const container::NoSuchElementException& )
378 std::unique_ptr<weld::TreeIter> xLibSubRootEntry(
m_xControl->make_iterator(&rLibRootEntry));
380 if (bLibSubRootEntry)
383 if (
m_xControl->get_row_expanded(*xLibSubRootEntry))
388 m_xControl->copy_iterator(rLibRootEntry, *xLibSubRootEntry);
404 sal_Int32 nModCount = aModNames.getLength();
405 const OUString* pModNames = aModNames.getConstArray();
410 for ( sal_Int32
i = 0 ;
i < nModCount ;
i++ )
412 OUString aModName = pModNames[
i ];
416 case script::ModuleType::DOCUMENT:
419 case script::ModuleType::FORM:
422 case script::ModuleType::NORMAL:
425 case script::ModuleType::CLASS:
429 if(
eType != eCurrentType )
439 if( !sObjName.isEmpty() )
444 std::unique_ptr<weld::TreeIter> xModuleEntry(
m_xControl->make_iterator(&rLibSubRootEntry));
448 m_xControl->copy_iterator(rLibSubRootEntry, *xModuleEntry);
457 sal_Int32
nCount = aNames.getLength();
458 const OUString* pNames = aNames.getConstArray();
460 for ( sal_Int32 j = 0 ; j <
nCount ; j++ )
462 OUString
aName = pNames[ j ];
463 std::unique_ptr<weld::TreeIter> xEntry(
m_xControl->make_iterator(xModuleEntry.get()));
473 catch (
const container::NoSuchElementException& )
481 bool bValidIter =
m_xControl->iter_children(rIter);
486 bValidIter =
m_xControl->iter_next_sibling(rIter);
545 std::unique_ptr<weld::TreeIter> xLastValid(
m_xControl->make_iterator(
nullptr));
546 bool bLastValid =
false;
605 bool bValidIter =
m_xControl->iter_children(rIter);
609 assert(pBasicEntry &&
"FindEntry: no Entry ?!");
612 bValidIter =
m_xControl->iter_next_sibling(rIter);
619 bool bProtected =
false;
620 if (pEntry &&
m_xControl->get_iter_depth(*pEntry) == 1)
624 OSL_ENSURE( rDocument.
isAlive(),
"TreeListBox::IsEntryProtected: no document, or document is dead!" );
627 const OUString& aOULibName( aDesc.
GetLibName() );
629 if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) )
632 if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aOULibName ) && !xPasswd->isLibraryPasswordVerified( aOULibName ) )
643 const OUString& rText,
644 const OUString& rImage,
646 bool bChildrenOnDemand,
647 std::unique_ptr<Entry>&& rUserData,
655 std::unique_ptr<weld::TreeIter> xScratch = pRet ? nullptr :
m_xControl->make_iterator();
657 pRet = xScratch.get();
659 m_xControl->insert(pParent, -1, &rText, &
sId,
nullptr,
nullptr, bChildrenOnDemand, pRet);
685 OSL_ENSURE( rDocument.
isValid(),
"TreeListBox::GetRootEntryBitmaps: illegal document!" );
691 OUString sFactoryURL;
696 OUString sModule( xModuleManager->identify( rDocument.
getDocument() ) );
698 xModuleManager->getByName( sModule ) >>= aModuleDescr;
699 sal_Int32
nCount = aModuleDescr.getLength();
700 const beans::PropertyValue* pModuleDescr = aModuleDescr.getConstArray();
703 if ( pModuleDescr[
i ].
Name ==
"ooSetupFactoryEmptyDocumentURL" )
705 pModuleDescr[
i ].Value >>= sFactoryURL;
715 if ( !sFactoryURL.isEmpty() )
722 return RID_BMP_DOCUMENT;
725 return RID_BMP_INSTALLATION;
730 bool bCurEntry =
false;
742 OSL_ENSURE(
aDocument.isValid(),
"TreeListBox::SetCurrentEntry: invalid document!" );
749 const OUString& aLibName( aDesc.
GetLibName() );
750 if ( !aLibName.isEmpty() )
757 m_xControl->copy_iterator(*xLibIter, *xCurIter);
759 if( !aLibSubName.isEmpty() )
762 auto xSubLibIter =
m_xControl->make_iterator(xLibIter.get());
763 bool bSubLibEntry =
ImpFindEntry(*xSubLibIter, aLibSubName);
766 m_xControl->copy_iterator(*xSubLibIter, *xCurIter);
770 if ( !
aName.isEmpty() )
776 auto xEntryIter =
m_xControl->make_iterator(xCurIter.get());
780 m_xControl->copy_iterator(*xEntryIter, *xCurIter);
782 if (!aMethodName.isEmpty())
785 auto xSubEntryIter =
m_xControl->make_iterator(xCurIter.get());
789 m_xControl->copy_iterator(*xSubEntryIter, *xCurIter);
793 m_xControl->copy_iterator(*xCurIter, *xSubEntryIter);
794 if (
m_xControl->iter_children(*xSubEntryIter))
795 m_xControl->copy_iterator(*xSubEntryIter, *xCurIter);
801 auto xSubEntryIter =
m_xControl->make_iterator(xCurIter.get());
802 if (
m_xControl->iter_children(*xSubEntryIter))
803 m_xControl->copy_iterator(*xSubEntryIter, *xCurIter);
811 m_xControl->copy_iterator(*xLibIter, *xCurIter);
817 bCurEntry =
m_xControl->get_iter_first(*xCurIter);
828 bool bValidIter =
m_xControl->get_cursor(m_xScratchIter.get());
831 if (!
m_xControl->get_row_expanded(*m_xScratchIter))
849 pDispatcher->ExecuteList(
850 SID_BASICIDE_SHOWSBX, SfxCallMode::SYNCHRON,
virtual ~DocumentEntry() override
DocumentEntry(ScriptDocument aDocument, LibraryLocation eLocation, EntryType eType=OBJ_TYPE_DOCUMENT)
ScriptDocument m_aDocument
const OUString & GetMethodName() const
ScriptDocument m_aDocument
LibraryLocation GetLocation() const
ScriptDocument const & GetDocument() const
EntryType GetType() const
const OUString & GetLibName() const
const OUString & GetName() const
const OUString & GetLibSubName() const
EntryType GetType() const
LibEntry(ScriptDocument const &rDocument, LibraryLocation eLocation, OUString aLibName)
virtual ~LibEntry() override
static sal_Int32 getModuleType(const css::uno::Reference< css::container::XNameContainer > &rLib, const OUString &rModName)
static void getObjectName(const css::uno::Reference< css::container::XNameContainer > &rLib, const OUString &rModName, OUString &rObjName)
LibraryType GetLibraryType() const
EntryDescriptor GetEntryDescriptor(const weld::TreeIter *pEntry)
bool FindRootEntry(const ScriptDocument &rDocument, LibraryLocation eLocation, weld::TreeIter &rIter)
virtual void onDocumentSaveAs(const ScriptDocument &_rDocument) override
OUString GetRootEntryName(const ScriptDocument &rDocument, LibraryLocation eLocation) const
std::unique_ptr< weld::TreeView > m_xControl
virtual void onDocumentSave(const ScriptDocument &_rDocument) override
virtual void onDocumentClosed(const ScriptDocument &_rDocument) override
void RemoveEntry(const weld::TreeIter &rIter)
bool m_bFreezeOnFirstAddRemove
bool IsValidEntry(const weld::TreeIter &rEntry)
void ImpCreateLibSubEntries(const weld::TreeIter &rLibRootEntry, const ScriptDocument &rDocument, const OUString &rLibName)
static OUString GetRootEntryBitmaps(const ScriptDocument &rDocument)
void SetCurrentEntry(EntryDescriptor const &)
void ImpCreateLibSubEntriesInVBAMode(const weld::TreeIter &rLibRootEntry, const ScriptDocument &rDocument, const OUString &rLibName)
bool IsEntryProtected(const weld::TreeIter *pEntry)
virtual void onDocumentModeChanged(const ScriptDocument &_rDocument) override
void AddEntry(const OUString &rText, const OUString &rImage, const weld::TreeIter *pParent, bool bChildrenOnDemand, std::unique_ptr< Entry > &&rUserData, weld::TreeIter *pRet=nullptr)
DocumentEventNotifier m_aNotifier
void ScanEntry(const ScriptDocument &rDocument, LibraryLocation eLocation)
virtual void onDocumentSaveAsDone(const ScriptDocument &_rDocument) override
bool FindEntry(std::u16string_view rText, EntryType eType, weld::TreeIter &rIter)
virtual void onDocumentSaveDone(const ScriptDocument &_rDocument) override
bool ImpFindEntry(weld::TreeIter &rIter, std::u16string_view rText)
virtual void onDocumentOpened(const ScriptDocument &_rDocument) override
void SetEntryBitmaps(const weld::TreeIter &rIter, const OUString &rImage)
SbTreeListBox(std::unique_ptr< weld::TreeView > xControl, weld::Window *pTopLevel)
virtual void onDocumentTitleChanged(const ScriptDocument &_rDocument) override
virtual ~SbTreeListBox() override
virtual void onDocumentCreated(const ScriptDocument &_rDocument) override
void ImpCreateLibSubSubEntriesInVBAMode(const weld::TreeIter &rLibRootEntry, const ScriptDocument &rDocument, const OUString &rLibName)
std::unique_ptr< weld::TreeIter > m_xScratchIter
void ImpCreateLibEntries(const weld::TreeIter &rShellRootEntry, const ScriptDocument &rDocument, LibraryLocation eLocation)
encapsulates a document which contains Basic scripts and dialogs
css::uno::Reference< css::container::XNameContainer > getOrCreateLibrary(LibraryContainerType _eType, const OUString &_rLibName) const
creates a script or dialog library in the document, or returns an existing one
OUString getTitle(LibraryLocation _eLocation, LibraryType _eType=LibraryType::All) const
returns the title for the document
css::uno::Reference< css::script::XLibraryContainer > getLibraryContainer(LibraryContainerType _eType) const
returns the Basic or Dialog library container of the document
css::uno::Reference< css::frame::XModel > getDocument() const
returns the UNO component representing the document which the instance operates on
bool isDocument() const
determines whether the ScriptDocument instance operates on a real document, as opposed to the whole a...
static const ScriptDocument & getApplicationScriptDocument()
returns a reference to a shared ScriptDocument instance which operates on the application-wide script...
bool isAlive() const
determines whether the document instance is alive
css::uno::Sequence< OUString > getLibraryNames() const
retrieves the (combined) names of all script and dialog libraries
css::uno::Sequence< OUString > getObjectNames(LibraryContainerType _eType, const OUString &_rLibName) const
returns the names of the modules in a given script or dialog library of the document
LibraryLocation getLibraryLocation(const OUString &_rLibName) const
returns the location of a library given by name
bool isValid() const
determines whether the document is actually able to contain Basic/Dialog libraries
#define DBG_UNHANDLED_EXCEPTION(...)
ScXMLEditAttributeMap::Entry const aEntries[]
const EnumerationType m_eType
#define LINK(Instance, Class, Member)
@ LIBRARY_LOCATION_UNKNOWN
SfxDispatcher * GetDispatcher()
Sequence< OUString > GetMethodNames(const ScriptDocument &rDocument, const OUString &rLibName, const OUString &rModName)
@ OBJ_TYPE_NORMAL_MODULES
@ OBJ_TYPE_DOCUMENT_OBJECTS
IMPL_LINK_NOARG(EditorWindow, SetSourceInBasicHdl, void *, void)
OUString IDEResId(TranslateId aId)
OUString toId(const void *pValue)