LibreOffice Module basctl (master) 1
bastype2.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20
21#include <basobj.hxx>
22#include <bastypes.hxx>
23#include <bastype2.hxx>
24#include <strings.hrc>
25#include <bitmaps.hlst>
26#include <iderid.hxx>
27#include <tools/urlobj.hxx>
29#include <svtools/imagemgr.hxx>
30#include <com/sun/star/script/XLibraryContainerPassword.hpp>
31#include <com/sun/star/frame/ModuleManager.hpp>
33#include <sfx2/dispatch.hxx>
34#include <sfx2/sfxsids.hrc>
35
36#include <initializer_list>
37#include <memory>
38#include <string_view>
39
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>
44#include <utility>
45
46namespace basctl
47{
48
49using namespace ::com::sun::star::uno;
50using namespace ::com::sun::star;
51
52void ModuleInfoHelper::getObjectName( const uno::Reference< container::XNameContainer >& rLib, const OUString& rModName, OUString& rObjName )
53{
54 try
55 {
56 uno::Reference< script::vba::XVBAModuleInfo > xVBAModuleInfo( rLib, uno::UNO_QUERY );
57 if ( xVBAModuleInfo.is() && xVBAModuleInfo->hasModuleInfo( rModName ) )
58 {
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" ) )
63 {
64 uno::Reference< container::XNamed > xNamed( aObject, uno::UNO_QUERY );
65 if( xNamed.is() )
66 rObjName = xNamed->getName();
67 }
68 }
69 }
70 catch(const uno::Exception& )
71 {
72 }
73}
74
75sal_Int32 ModuleInfoHelper::getModuleType( const uno::Reference< container::XNameContainer >& rLib, const OUString& rModName )
76{
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 ) )
80 {
81 script::ModuleInfo aModuleInfo = xVBAModuleInfo->getModuleInfo( rModName );
82 nType = aModuleInfo.ModuleType;
83 }
84 return nType;
85}
86
88{ }
89
92 LibraryLocation eLocation,
93 EntryType eType
94) :
95 Entry(eType),
96 m_aDocument(std::move(aDocument)),
97 m_eLocation(eLocation)
98{
99 OSL_ENSURE( m_aDocument.isValid(), "DocumentEntry::DocumentEntry: illegal document!" );
100}
101
103{ }
104
106 ScriptDocument const& rDocument,
107 LibraryLocation eLocation,
108 OUString aLibName
109) :
110 DocumentEntry(rDocument, eLocation, OBJ_TYPE_LIBRARY),
111 m_aLibName(std::move(aLibName))
112{ }
113
115{ }
116
118 m_aDocument(ScriptDocument::getApplicationScriptDocument()),
119 m_eLocation(LIBRARY_LOCATION_UNKNOWN),
121{ }
122
125 LibraryLocation eLocation,
126 OUString aLibName,
127 OUString aLibSubName,
128 OUString aName,
129 EntryType eType
130) :
131 m_aDocument(std::move(aDocument)),
132 m_eLocation(eLocation),
133 m_aLibName(std::move(aLibName)),
134 m_aLibSubName(std::move(aLibSubName)),
135 m_aName(std::move(aName)),
137{
138 OSL_ENSURE( m_aDocument.isValid(), "EntryDescriptor::EntryDescriptor: invalid document!" );
139}
140
143 LibraryLocation eLocation,
144 OUString aLibName,
145 OUString aLibSubName,
146 OUString aName,
147 OUString aMethodName,
148 EntryType eType
149) :
150 m_aDocument(std::move(aDocument)),
151 m_eLocation(eLocation),
152 m_aLibName(std::move(aLibName)),
153 m_aLibSubName(std::move(aLibSubName)),
154 m_aName(std::move(aName)),
155 m_aMethodName(std::move(aMethodName)),
157{
158 OSL_ENSURE( m_aDocument.isValid(), "EntryDescriptor::EntryDescriptor: invalid document!" );
159}
160
161SbTreeListBox::SbTreeListBox(std::unique_ptr<weld::TreeView> xControl, weld::Window* pTopLevel)
162 : m_xControl(std::move(xControl))
163 , m_xScratchIter(m_xControl->make_iterator())
164 , m_pTopLevel(pTopLevel)
165 , m_bFreezeOnFirstAddRemove(false)
166 , m_aNotifier(*this)
167{
168 m_xControl->connect_row_activated(LINK(this, SbTreeListBox, OpenCurrentHdl));
169 m_xControl->connect_expanding(LINK(this, SbTreeListBox, RequestingChildrenHdl));
170 nMode = BrowseMode::All; // everything
171}
172
174{
176
177 bool bValidIter = m_xControl->get_iter_first(*m_xScratchIter);
178 while (bValidIter)
179 {
180 Entry* pBasicEntry = weld::fromId<Entry*>(m_xControl->get_id(*m_xScratchIter));
181 delete pBasicEntry;
182 bValidIter = m_xControl->iter_next(*m_xScratchIter);
183 }
184}
185
186void SbTreeListBox::ScanEntry( const ScriptDocument& rDocument, LibraryLocation eLocation )
187{
188 OSL_ENSURE( rDocument.isAlive(), "TreeListBox::ScanEntry: illegal document!" );
189 if ( !rDocument.isAlive() )
190 return;
191
192 // can be called multiple times for updating!
193
194 // actually test if basic's in the tree already?!
195 // level 1: BasicManager (application, document, ...)
196 bool bDocumentRootEntry = FindRootEntry(rDocument, eLocation, *m_xScratchIter);
197 if (bDocumentRootEntry && m_xControl->get_row_expanded(*m_xScratchIter))
198 ImpCreateLibEntries(*m_xScratchIter, rDocument, eLocation);
199 if (!bDocumentRootEntry)
200 {
201 OUString aRootName(GetRootEntryName(rDocument, eLocation));
202 OUString aImage(GetRootEntryBitmaps(rDocument));
203 AddEntry(aRootName, aImage, nullptr, true, std::make_unique<DocumentEntry>(rDocument, eLocation));
204 }
205}
206
208{
209 // get a sorted list of library names
210 Sequence< OUString > aLibNames( rDocument.getLibraryNames() );
211 sal_Int32 nLibCount = aLibNames.getLength();
212 const OUString* pLibNames = aLibNames.getConstArray();
213
214 for ( sal_Int32 i = 0 ; i < nLibCount ; i++ )
215 {
216 OUString aLibName = pLibNames[ i ];
217
218 if ( eLocation == rDocument.getLibraryLocation( aLibName ) )
219 {
220 // check, if the module library is loaded
221 bool bModLibLoaded = false;
223 if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) && xModLibContainer->isLibraryLoaded( aLibName ) )
224 bModLibLoaded = true;
225
226 // check, if the dialog library is loaded
227 bool bDlgLibLoaded = false;
229 if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) && xDlgLibContainer->isLibraryLoaded( aLibName ) )
230 bDlgLibLoaded = true;
231
232 bool bLoaded = bModLibLoaded || bDlgLibLoaded;
233
234 // if only one of the libraries is loaded, load also the other
235 if ( bLoaded )
236 {
237 if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) && !xModLibContainer->isLibraryLoaded( aLibName ) )
238 xModLibContainer->loadLibrary( aLibName );
239
240 if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) && !xDlgLibContainer->isLibraryLoaded( aLibName ) )
241 xDlgLibContainer->loadLibrary( aLibName );
242 }
243
244 // create tree list box entry
245 OUString sId;
247 sId = bLoaded ? OUString(RID_BMP_DLGLIB) : OUString(RID_BMP_DLGLIBNOTLOADED);
248 else
249 sId = bLoaded ? OUString(RID_BMP_MODLIB) : OUString(RID_BMP_MODLIBNOTLOADED);
250 std::unique_ptr<weld::TreeIter> xLibRootEntry(m_xControl->make_iterator(&rIter));
251 bool bLibRootEntry = FindEntry(aLibName, OBJ_TYPE_LIBRARY, *xLibRootEntry);
252 if (bLibRootEntry)
253 {
254 SetEntryBitmaps(*xLibRootEntry, sId);
255 bool bRowExpanded = m_xControl->get_row_expanded(*xLibRootEntry);
256 bool bRowExpandAttempted = !m_xControl->get_children_on_demand(*xLibRootEntry);
257 if (bRowExpanded || bRowExpandAttempted)
258 ImpCreateLibSubEntries(*xLibRootEntry, rDocument, aLibName);
259 }
260 else
261 {
262 AddEntry(aLibName, sId, &rIter, true, std::make_unique<Entry>(OBJ_TYPE_LIBRARY));
263 }
264 }
265 }
266}
267
268void SbTreeListBox::ImpCreateLibSubEntries(const weld::TreeIter& rLibRootEntry, const ScriptDocument& rDocument, const OUString& rLibName)
269{
270 // modules
272 {
274
275 if ( xModLibContainer.is() && xModLibContainer->hasByName( rLibName ) && xModLibContainer->isLibraryLoaded( rLibName ) )
276 {
277 try
278 {
279 if( rDocument.isInVBAMode() )
280 {
281 ImpCreateLibSubEntriesInVBAMode(rLibRootEntry, rDocument, rLibName);
282 }
283 else
284 {
285 // get a sorted list of module names
286 Sequence< OUString > aModNames = rDocument.getObjectNames( E_SCRIPTS, rLibName );
287 sal_Int32 nModCount = aModNames.getLength();
288 const OUString* pModNames = aModNames.getConstArray();
289
290 auto xTreeIter = m_xControl->make_iterator();
291
292 for ( sal_Int32 i = 0 ; i < nModCount ; i++ )
293 {
294 OUString aModName = pModNames[ i ];
295 m_xControl->copy_iterator(rLibRootEntry, *xTreeIter);
296 bool bModuleEntry = FindEntry(aModName, OBJ_TYPE_MODULE, *xTreeIter);
297 if (!bModuleEntry)
298 {
299 AddEntry(aModName, RID_BMP_MODULE, &rLibRootEntry, false, std::make_unique<Entry>(OBJ_TYPE_MODULE), xTreeIter.get());
300 }
301
302 // methods
303 if ( nMode & BrowseMode::Subs )
304 {
305 Sequence< OUString > aNames = GetMethodNames( rDocument, rLibName, aModName );
306 sal_Int32 nCount = aNames.getLength();
307 const OUString* pNames = aNames.getConstArray();
308
309 auto xSubTreeIter = m_xControl->make_iterator();
310
311 for ( sal_Int32 j = 0 ; j < nCount ; j++ )
312 {
313 OUString aName = pNames[ j ];
314 m_xControl->copy_iterator(*xTreeIter, *xSubTreeIter);
315 bool bEntry = FindEntry(aName, OBJ_TYPE_METHOD, *xSubTreeIter);
316 if (!bEntry)
317 {
318 AddEntry(aName, RID_BMP_MACRO, xTreeIter.get(), false, std::make_unique<Entry>(OBJ_TYPE_METHOD));
319 }
320 }
321 }
322 }
323 }
324 }
325 catch ( const container::NoSuchElementException& )
326 {
327 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
328 }
329 }
330 }
331
332 // dialogs
333 if ( !(nMode & BrowseMode::Dialogs) )
334 return;
335
337
338 if ( !(xDlgLibContainer.is() && xDlgLibContainer->hasByName( rLibName ) && xDlgLibContainer->isLibraryLoaded( rLibName )) )
339 return;
340
341 try
342 {
343 // get a sorted list of dialog names
344 Sequence< OUString > aDlgNames( rDocument.getObjectNames( E_DIALOGS, rLibName ) );
345 sal_Int32 nDlgCount = aDlgNames.getLength();
346 const OUString* pDlgNames = aDlgNames.getConstArray();
347
348 auto xTreeIter = m_xControl->make_iterator();
349
350 for ( sal_Int32 i = 0 ; i < nDlgCount ; i++ )
351 {
352 OUString aDlgName = pDlgNames[ i ];
353 m_xControl->copy_iterator(rLibRootEntry, *xTreeIter);
354 bool bDialogEntry = FindEntry(aDlgName, OBJ_TYPE_DIALOG, *xTreeIter);
355 if (!bDialogEntry)
356 {
357 AddEntry(aDlgName, RID_BMP_DIALOG, &rLibRootEntry, false, std::make_unique<Entry>(OBJ_TYPE_DIALOG));
358 }
359 }
360 }
361 catch (const container::NoSuchElementException& )
362 {
363 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
364 }
365}
366
367void SbTreeListBox::ImpCreateLibSubEntriesInVBAMode(const weld::TreeIter& rLibRootEntry, const ScriptDocument& rDocument, const OUString& rLibName )
368{
369 auto const aEntries = {
370 std::make_pair( OBJ_TYPE_DOCUMENT_OBJECTS, IDEResId(RID_STR_DOCUMENT_OBJECTS) ),
371 std::make_pair( OBJ_TYPE_USERFORMS, IDEResId(RID_STR_USERFORMS) ),
372 std::make_pair( OBJ_TYPE_NORMAL_MODULES, IDEResId(RID_STR_NORMAL_MODULES) ),
373 std::make_pair( OBJ_TYPE_CLASS_MODULES, IDEResId(RID_STR_CLASS_MODULES) ) };
374 for( auto const & iter: aEntries )
375 {
376 EntryType eType = iter.first;
377 OUString const & aEntryName = iter.second;
378 std::unique_ptr<weld::TreeIter> xLibSubRootEntry(m_xControl->make_iterator(&rLibRootEntry));
379 bool bLibSubRootEntry = FindEntry(aEntryName, eType, *xLibSubRootEntry);
380 if (bLibSubRootEntry)
381 {
382 SetEntryBitmaps(*xLibSubRootEntry, RID_BMP_MODLIB);
383 if (m_xControl->get_row_expanded(*xLibSubRootEntry))
384 ImpCreateLibSubSubEntriesInVBAMode(*xLibSubRootEntry, rDocument, rLibName);
385 }
386 else
387 {
388 m_xControl->copy_iterator(rLibRootEntry, *xLibSubRootEntry);
389 AddEntry(aEntryName, RID_BMP_MODLIB, xLibSubRootEntry.get(), true, std::make_unique<Entry>(eType));
390 }
391 }
392}
393
394void SbTreeListBox::ImpCreateLibSubSubEntriesInVBAMode(const weld::TreeIter& rLibSubRootEntry, const ScriptDocument& rDocument, const OUString& rLibName)
395{
396 uno::Reference< container::XNameContainer > xLib = rDocument.getOrCreateLibrary( E_SCRIPTS, rLibName );
397 if( !xLib.is() )
398 return;
399
400 try
401 {
402 // get a sorted list of module names
403 Sequence< OUString > aModNames = rDocument.getObjectNames( E_SCRIPTS, rLibName );
404 sal_Int32 nModCount = aModNames.getLength();
405 const OUString* pModNames = aModNames.getConstArray();
406
407 EntryDescriptor aDesc(GetEntryDescriptor(&rLibSubRootEntry));
408 EntryType eCurrentType(aDesc.GetType());
409
410 for ( sal_Int32 i = 0 ; i < nModCount ; i++ )
411 {
412 OUString aModName = pModNames[ i ];
414 switch( ModuleInfoHelper::getModuleType( xLib, aModName ) )
415 {
416 case script::ModuleType::DOCUMENT:
418 break;
419 case script::ModuleType::FORM:
421 break;
422 case script::ModuleType::NORMAL:
424 break;
425 case script::ModuleType::CLASS:
427 break;
428 }
429 if( eType != eCurrentType )
430 continue;
431
432 // display a nice friendly name in the ObjectModule tab,
433 // combining the objectname and module name, e.g. Sheet1 ( Financials )
434 OUString aEntryName = aModName;
436 {
437 OUString sObjName;
438 ModuleInfoHelper::getObjectName( xLib, aModName, sObjName );
439 if( !sObjName.isEmpty() )
440 {
441 aEntryName += " (" + sObjName + ")";
442 }
443 }
444 std::unique_ptr<weld::TreeIter> xModuleEntry(m_xControl->make_iterator(&rLibSubRootEntry));
445 bool bModuleEntry = FindEntry(aEntryName, OBJ_TYPE_MODULE, *xModuleEntry);
446 if (!bModuleEntry)
447 {
448 m_xControl->copy_iterator(rLibSubRootEntry, *xModuleEntry);
449 AddEntry(aEntryName, RID_BMP_MODULE, xModuleEntry.get(), false,
450 std::make_unique<Entry>(OBJ_TYPE_MODULE));
451 }
452
453 // methods
454 if ( nMode & BrowseMode::Subs )
455 {
456 Sequence< OUString > aNames = GetMethodNames( rDocument, rLibName, aModName );
457 sal_Int32 nCount = aNames.getLength();
458 const OUString* pNames = aNames.getConstArray();
459
460 for ( sal_Int32 j = 0 ; j < nCount ; j++ )
461 {
462 OUString aName = pNames[ j ];
463 std::unique_ptr<weld::TreeIter> xEntry(m_xControl->make_iterator(xModuleEntry.get()));
464 bool bEntry = FindEntry(aName, OBJ_TYPE_METHOD, *xEntry);
465 if (!bEntry)
466 {
467 AddEntry(aName, RID_BMP_MACRO, xModuleEntry.get(), false, std::make_unique<Entry>(OBJ_TYPE_METHOD));
468 }
469 }
470 }
471 }
472 }
473 catch ( const container::NoSuchElementException& )
474 {
475 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
476 }
477}
478
479bool SbTreeListBox::ImpFindEntry(weld::TreeIter& rIter, std::u16string_view rText)
480{
481 bool bValidIter = m_xControl->iter_children(rIter);
482 while (bValidIter)
483 {
484 if (rText == m_xControl->get_text(rIter))
485 return true;
486 bValidIter = m_xControl->iter_next_sibling(rIter);
487 }
488 return false;
489}
490
492{
494}
495
497{
499}
500
502{
503 // not interested in
504}
505
507{
508 // not interested in
509}
510
512{
513 // not interested in
514}
515
517{
519}
520
522{
524 // The document is not yet actually deleted, so we need to remove its entry
525 // manually.
526 RemoveEntry(rDocument);
527}
528
530{
531 // not interested in
532}
533
535{
536 // not interested in
537}
538
540{
541 bool bValidIter = m_xControl->get_selected(m_xScratchIter.get());
542 EntryDescriptor aCurDesc(GetEntryDescriptor(bValidIter ? m_xScratchIter.get() : nullptr));
543
544 // removing the invalid entries
545 std::unique_ptr<weld::TreeIter> xLastValid(m_xControl->make_iterator(nullptr));
546 bool bLastValid = false;
547 bValidIter = m_xControl->get_iter_first(*m_xScratchIter);
548 while (bValidIter)
549 {
551 {
552 m_xControl->copy_iterator(*m_xScratchIter, *xLastValid);
553 bLastValid = true;
554 }
555 else
557 if (bLastValid)
558 {
559 m_xControl->copy_iterator(*xLastValid, *m_xScratchIter);
560 bValidIter = m_xControl->iter_next(*m_xScratchIter);
561 }
562 else
563 bValidIter = m_xControl->get_iter_first(*m_xScratchIter);
564 }
565
567
568 SetCurrentEntry( aCurDesc );
569}
570
571// Removes the entry from the tree.
573{
575 {
576 m_xControl->freeze();
578 }
579
580 // removing the associated user data
581 Entry* pBasicEntry = weld::fromId<Entry*>(m_xControl->get_id(rIter));
582 delete pBasicEntry;
583 // removing the entry
584 m_xControl->remove(rIter);
585}
586
587// Removes the entry of rDocument.
589{
590 // finding the entry of rDocument
591 bool bValidIter = m_xControl->get_iter_first(*m_xScratchIter);
592 while (bValidIter)
593 {
594 if (rDocument == GetEntryDescriptor(m_xScratchIter.get()).GetDocument())
595 {
597 break;
598 }
599 bValidIter = m_xControl->iter_next(*m_xScratchIter);
600 }
601}
602
603bool SbTreeListBox::FindEntry(std::u16string_view rText, EntryType eType, weld::TreeIter& rIter)
604{
605 bool bValidIter = m_xControl->iter_children(rIter);
606 while (bValidIter)
607 {
608 Entry* pBasicEntry = weld::fromId<Entry*>(m_xControl->get_id(rIter));
609 assert(pBasicEntry && "FindEntry: no Entry ?!");
610 if (pBasicEntry->GetType() == eType && rText == m_xControl->get_text(rIter))
611 return true;
612 bValidIter = m_xControl->iter_next_sibling(rIter);
613 }
614 return false;
615}
616
618{
619 bool bProtected = false;
620 if (pEntry && m_xControl->get_iter_depth(*pEntry) == 1)
621 {
622 EntryDescriptor aDesc(GetEntryDescriptor(pEntry));
623 const ScriptDocument& rDocument( aDesc.GetDocument() );
624 OSL_ENSURE( rDocument.isAlive(), "TreeListBox::IsEntryProtected: no document, or document is dead!" );
625 if ( rDocument.isAlive() )
626 {
627 const OUString& aOULibName( aDesc.GetLibName() );
629 if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) )
630 {
631 Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
632 if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aOULibName ) && !xPasswd->isLibraryPasswordVerified( aOULibName ) )
633 {
634 bProtected = true;
635 }
636 }
637 }
638 }
639 return bProtected;
640}
641
643 const OUString& rText,
644 const OUString& rImage,
645 const weld::TreeIter* pParent,
646 bool bChildrenOnDemand,
647 std::unique_ptr<Entry>&& rUserData,
648 weld::TreeIter* pRet)
649{
651 {
652 m_xControl->freeze();
654 }
655 std::unique_ptr<weld::TreeIter> xScratch = pRet ? nullptr : m_xControl->make_iterator();
656 if (!pRet)
657 pRet = xScratch.get();
658 OUString sId(weld::toId(rUserData.release()));
659 m_xControl->insert(pParent, -1, &rText, &sId, nullptr, nullptr, bChildrenOnDemand, pRet);
660 m_xControl->set_image(*pRet, rImage);
661}
662
663void SbTreeListBox::SetEntryBitmaps(const weld::TreeIter& rIter, const OUString& rImage)
664{
665 m_xControl->set_image(rIter, rImage, -1);
666}
667
669{
673 else if ( !( nMode & BrowseMode::Modules ) && ( nMode & BrowseMode::Dialogs ) )
675 return eType;
676}
677
678OUString SbTreeListBox::GetRootEntryName( const ScriptDocument& rDocument, LibraryLocation eLocation ) const
679{
680 return rDocument.getTitle( eLocation, GetLibraryType() );
681}
682
684{
685 OSL_ENSURE( rDocument.isValid(), "TreeListBox::GetRootEntryBitmaps: illegal document!" );
686 if (!rDocument.isValid())
687 return OUString();
688
689 if ( rDocument.isDocument() )
690 {
691 OUString sFactoryURL;
692 Reference<uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
693 Reference< frame::XModuleManager2 > xModuleManager( frame::ModuleManager::create(xContext) );
694 try
695 {
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();
701 for ( sal_Int32 i = 0; i < nCount; ++i )
702 {
703 if ( pModuleDescr[ i ].Name == "ooSetupFactoryEmptyDocumentURL" )
704 {
705 pModuleDescr[ i ].Value >>= sFactoryURL;
706 break;
707 }
708 }
709 }
710 catch( const Exception& )
711 {
712 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
713 }
714
715 if ( !sFactoryURL.isEmpty() )
716 {
718 }
719 else
720 {
721 // default icon
722 return RID_BMP_DOCUMENT;
723 }
724 }
725 return RID_BMP_INSTALLATION;
726}
727
729{
730 bool bCurEntry = false;
731 auto xCurIter = m_xControl->make_iterator();
732 EntryDescriptor aDesc = rDesc;
733 if ( aDesc.GetType() == OBJ_TYPE_UNKNOWN )
734 {
735 aDesc = EntryDescriptor(
737 LIBRARY_LOCATION_USER, "Standard",
738 OUString(), ".", OBJ_TYPE_UNKNOWN
739 );
740 }
742 OSL_ENSURE( aDocument.isValid(), "TreeListBox::SetCurrentEntry: invalid document!" );
743 LibraryLocation eLocation = aDesc.GetLocation();
744 bool bRootEntry = FindRootEntry(aDocument, eLocation, *m_xScratchIter);
745 if (bRootEntry)
746 {
747 m_xControl->copy_iterator(*m_xScratchIter, *xCurIter);
748 bCurEntry = true;
749 const OUString& aLibName( aDesc.GetLibName() );
750 if ( !aLibName.isEmpty() )
751 {
752 m_xControl->expand_row(*m_xScratchIter);
753 auto xLibIter = m_xControl->make_iterator(m_xScratchIter.get());
754 bool bLibEntry = FindEntry(aLibName, OBJ_TYPE_LIBRARY, *xLibIter);
755 if (bLibEntry)
756 {
757 m_xControl->copy_iterator(*xLibIter, *xCurIter);
758 const OUString& aLibSubName( aDesc.GetLibSubName() );
759 if( !aLibSubName.isEmpty() )
760 {
761 m_xControl->expand_row(*xLibIter);
762 auto xSubLibIter = m_xControl->make_iterator(xLibIter.get());
763 bool bSubLibEntry = ImpFindEntry(*xSubLibIter, aLibSubName);
764 if (bSubLibEntry)
765 {
766 m_xControl->copy_iterator(*xSubLibIter, *xCurIter);
767 }
768 }
769 const OUString& aName( aDesc.GetName() );
770 if ( !aName.isEmpty() )
771 {
772 m_xControl->expand_row(*xCurIter);
774 if ( aDesc.GetType() == OBJ_TYPE_DIALOG )
776 auto xEntryIter = m_xControl->make_iterator(xCurIter.get());
777 bool bEntry = FindEntry(aName, eType, *xEntryIter);
778 if (bEntry)
779 {
780 m_xControl->copy_iterator(*xEntryIter, *xCurIter);
781 const OUString& aMethodName( aDesc.GetMethodName() );
782 if (!aMethodName.isEmpty())
783 {
784 m_xControl->expand_row(*xCurIter);
785 auto xSubEntryIter = m_xControl->make_iterator(xCurIter.get());
786 bool bSubEntry = FindEntry(aMethodName, OBJ_TYPE_METHOD, *xSubEntryIter);
787 if (bSubEntry)
788 {
789 m_xControl->copy_iterator(*xSubEntryIter, *xCurIter);
790 }
791 else
792 {
793 m_xControl->copy_iterator(*xCurIter, *xSubEntryIter);
794 if (m_xControl->iter_children(*xSubEntryIter))
795 m_xControl->copy_iterator(*xSubEntryIter, *xCurIter);
796 }
797 }
798 }
799 else
800 {
801 auto xSubEntryIter = m_xControl->make_iterator(xCurIter.get());
802 if (m_xControl->iter_children(*xSubEntryIter))
803 m_xControl->copy_iterator(*xSubEntryIter, *xCurIter);
804 }
805 }
806 }
807 else
808 {
809 auto xSubLibIter = m_xControl->make_iterator(m_xScratchIter.get());
810 if (m_xControl->iter_children(*xSubLibIter))
811 m_xControl->copy_iterator(*xLibIter, *xCurIter);
812 }
813 }
814 }
815 else
816 {
817 bCurEntry = m_xControl->get_iter_first(*xCurIter);
818 }
819
820 if (!bCurEntry)
821 return;
822
823 m_xControl->set_cursor(*xCurIter);
824}
825
827{
828 bool bValidIter = m_xControl->get_cursor(m_xScratchIter.get());
829 if (!bValidIter)
830 return true;
831 if (!m_xControl->get_row_expanded(*m_xScratchIter))
832 m_xControl->expand_row(*m_xScratchIter);
833 else
834 m_xControl->collapse_row(*m_xScratchIter);
835
836 EntryDescriptor aDesc = GetEntryDescriptor(m_xScratchIter.get());
837 switch (aDesc.GetType())
838 {
839 case OBJ_TYPE_METHOD:
840 case OBJ_TYPE_MODULE:
841 case OBJ_TYPE_DIALOG:
842 if (SfxDispatcher* pDispatcher = GetDispatcher())
843 {
844 SbxItem aSbxItem(
845 SID_BASICIDE_ARG_SBX, aDesc.GetDocument(),
846 aDesc.GetLibName(), aDesc.GetName(), aDesc.GetMethodName(),
847 ConvertType(aDesc.GetType())
848 );
849 pDispatcher->ExecuteList(
850 SID_BASICIDE_SHOWSBX, SfxCallMode::SYNCHRON,
851 { &aSbxItem }
852 );
853 }
854 break;
855
856 default:
857 break;
858 }
859 return true;
860}
861
862} // namespace basctl
863
864/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScriptDocument aDocument
Definition: basobj2.cxx:194
static SVT_DLLPUBLIC OUString GetFileImageId(const INetURLObject &rURL)
virtual ~DocumentEntry() override
Definition: bastype2.cxx:102
DocumentEntry(ScriptDocument aDocument, LibraryLocation eLocation, EntryType eType=OBJ_TYPE_DOCUMENT)
Definition: bastype2.cxx:90
ScriptDocument m_aDocument
Definition: bastype2.hxx:88
const OUString & GetMethodName() const
Definition: bastype2.hxx:155
ScriptDocument m_aDocument
Definition: bastype2.hxx:121
LibraryLocation GetLocation() const
Definition: bastype2.hxx:150
ScriptDocument const & GetDocument() const
Definition: bastype2.hxx:149
EntryType GetType() const
Definition: bastype2.hxx:158
const OUString & GetLibName() const
Definition: bastype2.hxx:152
const OUString & GetName() const
Definition: bastype2.hxx:154
const OUString & GetLibSubName() const
Definition: bastype2.hxx:153
EntryType GetType() const
Definition: bastype2.hxx:82
virtual ~Entry()
Definition: bastype2.cxx:87
LibEntry(ScriptDocument const &rDocument, LibraryLocation eLocation, OUString aLibName)
Definition: bastype2.cxx:105
virtual ~LibEntry() override
Definition: bastype2.cxx:114
static sal_Int32 getModuleType(const css::uno::Reference< css::container::XNameContainer > &rLib, const OUString &rModName)
Definition: bastype2.cxx:75
static void getObjectName(const css::uno::Reference< css::container::XNameContainer > &rLib, const OUString &rModName, OUString &rObjName)
Definition: bastype2.cxx:52
LibraryType GetLibraryType() const
Definition: bastype2.cxx:668
EntryDescriptor GetEntryDescriptor(const weld::TreeIter *pEntry)
Definition: bastype3.cxx:240
bool FindRootEntry(const ScriptDocument &rDocument, LibraryLocation eLocation, weld::TreeIter &rIter)
Definition: bastype3.cxx:418
virtual void onDocumentSaveAs(const ScriptDocument &_rDocument) override
Definition: bastype2.cxx:511
OUString GetRootEntryName(const ScriptDocument &rDocument, LibraryLocation eLocation) const
Definition: bastype2.cxx:678
std::unique_ptr< weld::TreeView > m_xControl
Definition: bastype2.hxx:177
virtual void onDocumentSave(const ScriptDocument &_rDocument) override
Definition: bastype2.cxx:501
virtual void onDocumentClosed(const ScriptDocument &_rDocument) override
Definition: bastype2.cxx:521
void RemoveEntry(const weld::TreeIter &rIter)
Definition: bastype2.cxx:572
bool IsValidEntry(const weld::TreeIter &rEntry)
Definition: bastype3.cxx:358
void ImpCreateLibSubEntries(const weld::TreeIter &rLibRootEntry, const ScriptDocument &rDocument, const OUString &rLibName)
Definition: bastype2.cxx:268
static OUString GetRootEntryBitmaps(const ScriptDocument &rDocument)
Definition: bastype2.cxx:683
void SetCurrentEntry(EntryDescriptor const &)
Definition: bastype2.cxx:728
void ImpCreateLibSubEntriesInVBAMode(const weld::TreeIter &rLibRootEntry, const ScriptDocument &rDocument, const OUString &rLibName)
Definition: bastype2.cxx:367
bool IsEntryProtected(const weld::TreeIter *pEntry)
Definition: bastype2.cxx:617
virtual void onDocumentModeChanged(const ScriptDocument &_rDocument) override
Definition: bastype2.cxx:534
void AddEntry(const OUString &rText, const OUString &rImage, const weld::TreeIter *pParent, bool bChildrenOnDemand, std::unique_ptr< Entry > &&rUserData, weld::TreeIter *pRet=nullptr)
Definition: bastype2.cxx:642
DocumentEventNotifier m_aNotifier
Definition: bastype2.hxx:182
void ScanEntry(const ScriptDocument &rDocument, LibraryLocation eLocation)
Definition: bastype2.cxx:186
virtual void onDocumentSaveAsDone(const ScriptDocument &_rDocument) override
Definition: bastype2.cxx:516
bool FindEntry(std::u16string_view rText, EntryType eType, weld::TreeIter &rIter)
Definition: bastype2.cxx:603
virtual void onDocumentSaveDone(const ScriptDocument &_rDocument) override
Definition: bastype2.cxx:506
bool ImpFindEntry(weld::TreeIter &rIter, std::u16string_view rText)
Definition: bastype2.cxx:479
virtual void onDocumentOpened(const ScriptDocument &_rDocument) override
Definition: bastype2.cxx:496
void SetEntryBitmaps(const weld::TreeIter &rIter, const OUString &rImage)
Definition: bastype2.cxx:663
SbTreeListBox(std::unique_ptr< weld::TreeView > xControl, weld::Window *pTopLevel)
Definition: bastype2.cxx:161
virtual void onDocumentTitleChanged(const ScriptDocument &_rDocument) override
Definition: bastype2.cxx:529
virtual ~SbTreeListBox() override
Definition: bastype2.cxx:173
virtual void onDocumentCreated(const ScriptDocument &_rDocument) override
Definition: bastype2.cxx:491
void ImpCreateLibSubSubEntriesInVBAMode(const weld::TreeIter &rLibRootEntry, const ScriptDocument &rDocument, const OUString &rLibName)
Definition: bastype2.cxx:394
std::unique_ptr< weld::TreeIter > m_xScratchIter
Definition: bastype2.hxx:178
void ImpCreateLibEntries(const weld::TreeIter &rShellRootEntry, const ScriptDocument &rDocument, LibraryLocation eLocation)
Definition: bastype2.cxx:207
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
int nCount
#define DBG_UNHANDLED_EXCEPTION(...)
ScXMLEditAttributeMap::Entry const aEntries[]
const EnumerationType m_eType
DocumentType eType
OUString aName
@ LIBRARY_LOCATION_USER
@ LIBRARY_LOCATION_UNKNOWN
SfxDispatcher * GetDispatcher()
Definition: basobj3.cxx:454
Sequence< OUString > GetMethodNames(const ScriptDocument &rDocument, const OUString &rLibName, const OUString &rModName)
Definition: basobj2.cxx:356
@ OBJ_TYPE_UNKNOWN
Definition: bastype2.hxx:52
@ OBJ_TYPE_USERFORMS
Definition: bastype2.hxx:59
@ OBJ_TYPE_LIBRARY
Definition: bastype2.hxx:54
@ OBJ_TYPE_NORMAL_MODULES
Definition: bastype2.hxx:60
@ OBJ_TYPE_DIALOG
Definition: bastype2.hxx:56
@ OBJ_TYPE_CLASS_MODULES
Definition: bastype2.hxx:61
@ OBJ_TYPE_MODULE
Definition: bastype2.hxx:55
@ OBJ_TYPE_METHOD
Definition: bastype2.hxx:57
@ OBJ_TYPE_DOCUMENT_OBJECTS
Definition: bastype2.hxx:58
IMPL_LINK_NOARG(EditorWindow, SetSourceInBasicHdl, void *, void)
Definition: baside2b.cxx:987
OUString IDEResId(TranslateId aId)
Definition: iderdll.cxx:108
@ Exception
int i
OUString toId(const void *pValue)
OUString m_aName
QPRO_FUNC_TYPE nType
bool bSubEntry
char aEntryName[20]
OUString Name
OUString sId
Reference< XControl > m_xControl