1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bastype2.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basctl.hxx"
36 #include "vcl/bitmap.hxx"
38 #include <ide_pch.hxx>
41 #include <basidesh.hrc>
42 #include <bastypes.hxx>
43 #include <bastype2.hxx>
45 #include <baside2.hrc>
47 #include <tools/urlobj.hxx>
48 #include <tools/diagnose_ex.h>
49 #include <basic/sbx.hxx>
50 #include <svtools/imagemgr.hxx>
51 #include <com/sun/star/script/XLibraryContainer.hpp>
52 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
53 #include <com/sun/star/frame/XModuleManager.hpp>
54 #include <comphelper/processfactory.hxx>
55 #include <comphelper/componentcontext.hxx>
57 #include <com/sun/star/script/ModuleType.hpp>
58 #include <com/sun/star/script/ModuleInfo.hpp>
59 #include <com/sun/star/container/XNameContainer.hpp>
61 using namespace ::com::sun::star::uno
;
62 using namespace ::com::sun::star
;
64 void lcl_getObjectName( const uno::Reference
< container::XNameContainer
>& rLib
, const String
& rModName
, String
& rObjName
);
66 sal_Int32
lcl_getModuleType( const uno::Reference
< container::XNameContainer
>& rLib
, const String
& rModName
)
68 sal_Int32 nType
= com::sun::star::script::ModuleType::Normal
;
69 uno::Any
aElement( rLib
->getByName( rModName
) );
70 script::ModuleInfo aModuleInfo
;
71 if( aElement
>>= aModuleInfo
)
72 nType
= aModuleInfo
.ModuleType
;
76 BasicEntry::~BasicEntry()
80 BasicDocumentEntry::BasicDocumentEntry( const ScriptDocument
& rDocument
, LibraryLocation eLocation
, BasicEntryType eType
)
82 ,m_aDocument( rDocument
)
83 ,m_eLocation( eLocation
)
85 OSL_ENSURE( m_aDocument
.isValid(), "BasicDocumentEntry::BasicDocumentEntry: illegal document!" );
88 BasicDocumentEntry::~BasicDocumentEntry()
92 BasicLibEntry::BasicLibEntry( const ScriptDocument
& rDocument
, LibraryLocation eLocation
, const String
& rLibName
, BasicEntryType eType
)
93 :BasicDocumentEntry( rDocument
, eLocation
, eType
)
94 ,m_aLibName( rLibName
)
98 BasicLibEntry::~BasicLibEntry()
102 BasicEntryDescriptor::BasicEntryDescriptor()
103 :m_aDocument( ScriptDocument::getApplicationScriptDocument() )
104 ,m_eLocation( LIBRARY_LOCATION_UNKNOWN
)
105 ,m_eType( OBJ_TYPE_UNKNOWN
)
109 BasicEntryDescriptor::BasicEntryDescriptor( const ScriptDocument
& rDocument
, LibraryLocation eLocation
, const String
& rLibName
, const String
& rLibSubName
, const String
& rName
, BasicEntryType eType
)
110 :m_aDocument( rDocument
)
111 ,m_eLocation( eLocation
)
112 ,m_aLibName( rLibName
)
113 ,m_aLibSubName( rLibSubName
)
117 OSL_ENSURE( m_aDocument
.isValid(), "BasicEntryDescriptor::BasicEntryDescriptor: invalid document!" );
120 BasicEntryDescriptor::BasicEntryDescriptor( const ScriptDocument
& rDocument
, LibraryLocation eLocation
, const String
& rLibName
, const String
& rLibSubName
, const String
& rName
, const String
& rMethodName
, BasicEntryType eType
)
121 :m_aDocument( rDocument
)
122 ,m_eLocation( eLocation
)
123 ,m_aLibName( rLibName
)
124 ,m_aLibSubName( rLibSubName
)
126 ,m_aMethodName( rMethodName
)
129 OSL_ENSURE( m_aDocument
.isValid(), "BasicEntryDescriptor::BasicEntryDescriptor: invalid document!" );
132 BasicEntryDescriptor::~BasicEntryDescriptor()
136 BasicEntryDescriptor::BasicEntryDescriptor( const BasicEntryDescriptor
& rDesc
)
137 :m_aDocument( rDesc
.m_aDocument
)
138 ,m_eLocation( rDesc
.m_eLocation
)
139 ,m_aLibName( rDesc
.m_aLibName
)
140 ,m_aLibSubName( rDesc
.m_aLibSubName
)
141 ,m_aName( rDesc
.m_aName
)
142 ,m_aMethodName( rDesc
.m_aMethodName
)
143 ,m_eType( rDesc
.m_eType
)
147 BasicEntryDescriptor
& BasicEntryDescriptor::operator=( const BasicEntryDescriptor
& rDesc
)
149 m_aDocument
= rDesc
.m_aDocument
;
150 m_eLocation
= rDesc
.m_eLocation
;
151 m_aLibName
= rDesc
.m_aLibName
;
152 m_aLibSubName
= rDesc
.m_aLibSubName
;
153 m_aName
= rDesc
.m_aName
;
154 m_aMethodName
= rDesc
.m_aMethodName
;
155 m_eType
= rDesc
.m_eType
;
160 bool BasicEntryDescriptor::operator==( const BasicEntryDescriptor
& rDesc
) const
162 return m_aDocument
== rDesc
.m_aDocument
&&
163 m_eLocation
== rDesc
.m_eLocation
&&
164 m_aLibName
== rDesc
.m_aLibName
&&
165 m_aLibSubName
== rDesc
.m_aLibSubName
&&
166 m_aName
== rDesc
.m_aName
&&
167 m_aMethodName
== rDesc
.m_aMethodName
&&
168 m_eType
== rDesc
.m_eType
;
171 BasicTreeListBox::BasicTreeListBox( Window
* pParent
, const ResId
& rRes
) :
172 SvTreeListBox( pParent
, IDEResId( sal::static_int_cast
<USHORT
>( rRes
.GetId() ) ) ),
175 SetNodeDefaultImages();
176 SetSelectionMode( SINGLE_SELECTION
);
177 nMode
= 0xFF; // Alles
182 BasicTreeListBox::~BasicTreeListBox()
184 m_aNotifier
.dispose();
186 // UserDaten zerstoeren
187 SvLBoxEntry
* pEntry
= First();
190 delete (BasicEntry
*)pEntry
->GetUserData();
191 pEntry
= Next( pEntry
);
195 void BasicTreeListBox::ScanEntry( const ScriptDocument
& rDocument
, LibraryLocation eLocation
)
197 OSL_ENSURE( rDocument
.isAlive(), "BasicTreeListBox::ScanEntry: illegal document!" );
198 if ( !rDocument
.isAlive() )
201 // can be called multiple times for updating!
203 // eigentlich prueffen, ob Basic bereits im Baum ?!
204 SetUpdateMode( FALSE
);
206 // level 1: BasicManager (application, document, ...)
207 SvLBoxEntry
* pDocumentRootEntry
= FindRootEntry( rDocument
, eLocation
);
208 if ( pDocumentRootEntry
&& IsExpanded( pDocumentRootEntry
) )
209 ImpCreateLibEntries( pDocumentRootEntry
, rDocument
, eLocation
);
210 if ( !pDocumentRootEntry
)
212 String
aRootName( GetRootEntryName( rDocument
, eLocation
) );
215 GetRootEntryBitmaps( rDocument
, aImage
, aImageHC
);
216 pDocumentRootEntry
= AddEntry(
221 std::auto_ptr
< BasicEntry
>( new BasicDocumentEntry( rDocument
, eLocation
) ) );
224 SetUpdateMode( TRUE
);
227 void BasicTreeListBox::ImpCreateLibEntries( SvLBoxEntry
* pDocumentRootEntry
, const ScriptDocument
& rDocument
, LibraryLocation eLocation
)
229 // get a sorted list of library names
230 Sequence
< ::rtl::OUString
> aLibNames( rDocument
.getLibraryNames() );
231 sal_Int32 nLibCount
= aLibNames
.getLength();
232 const ::rtl::OUString
* pLibNames
= aLibNames
.getConstArray();
234 for ( sal_Int32 i
= 0 ; i
< nLibCount
; i
++ )
236 String aLibName
= pLibNames
[ i
];
238 if ( eLocation
== rDocument
.getLibraryLocation( aLibName
) )
240 // check, if the module library is loaded
241 BOOL bModLibLoaded
= FALSE
;
242 ::rtl::OUString
aOULibName( aLibName
);
243 Reference
< script::XLibraryContainer
> xModLibContainer( rDocument
.getLibraryContainer( E_SCRIPTS
) );
244 if ( xModLibContainer
.is() && xModLibContainer
->hasByName( aOULibName
) && xModLibContainer
->isLibraryLoaded( aOULibName
) )
245 bModLibLoaded
= TRUE
;
247 // check, if the dialog library is loaded
248 BOOL bDlgLibLoaded
= FALSE
;
249 Reference
< script::XLibraryContainer
> xDlgLibContainer( rDocument
.getLibraryContainer( E_DIALOGS
) );
250 if ( xDlgLibContainer
.is() && xDlgLibContainer
->hasByName( aOULibName
) && xDlgLibContainer
->isLibraryLoaded( aOULibName
) )
251 bDlgLibLoaded
= TRUE
;
253 BOOL bLoaded
= bModLibLoaded
|| bDlgLibLoaded
;
255 // if only one of the libraries is loaded, load also the other
258 if ( xModLibContainer
.is() && xModLibContainer
->hasByName( aOULibName
) && !xModLibContainer
->isLibraryLoaded( aOULibName
) )
259 xModLibContainer
->loadLibrary( aOULibName
);
261 if ( xDlgLibContainer
.is() && xDlgLibContainer
->hasByName( aOULibName
) && !xDlgLibContainer
->isLibraryLoaded( aOULibName
) )
262 xDlgLibContainer
->loadLibrary( aOULibName
);
265 // create tree list box entry
267 if ( ( nMode
& BROWSEMODE_DIALOGS
) && !( nMode
& BROWSEMODE_MODULES
) )
269 nId
= bLoaded
? RID_IMG_DLGLIB
: RID_IMG_DLGLIBNOTLOADED
;
270 nIdHC
= bLoaded
? RID_IMG_DLGLIB_HC
: RID_IMG_DLGLIBNOTLOADED_HC
;
274 nId
= bLoaded
? RID_IMG_MODLIB
: RID_IMG_MODLIBNOTLOADED
;
275 nIdHC
= bLoaded
? RID_IMG_MODLIB_HC
: RID_IMG_MODLIBNOTLOADED_HC
;
277 SvLBoxEntry
* pLibRootEntry
= FindEntry( pDocumentRootEntry
, aLibName
, OBJ_TYPE_LIBRARY
);
280 SetEntryBitmaps( pLibRootEntry
, Image( IDEResId( nId
) ), Image( IDEResId( nIdHC
) ) );
281 if ( IsExpanded( pLibRootEntry
) )
282 ImpCreateLibSubEntries( pLibRootEntry
, rDocument
, aLibName
);
286 pLibRootEntry
= AddEntry(
288 Image( IDEResId( nId
) ),
289 Image( IDEResId( nIdHC
) ),
290 pDocumentRootEntry
, true,
291 std::auto_ptr
< BasicEntry
>( new BasicEntry( OBJ_TYPE_LIBRARY
) ) );
297 void BasicTreeListBox::ImpCreateLibSubEntries( SvLBoxEntry
* pLibRootEntry
, const ScriptDocument
& rDocument
, const String
& rLibName
)
299 ::rtl::OUString
aOULibName( rLibName
);
302 if ( nMode
& BROWSEMODE_MODULES
)
304 Reference
< script::XLibraryContainer
> xModLibContainer( rDocument
.getLibraryContainer( E_SCRIPTS
) );
306 if ( xModLibContainer
.is() && xModLibContainer
->hasByName( aOULibName
) && xModLibContainer
->isLibraryLoaded( aOULibName
) )
310 BasicManager
* pBasMgr
= rDocument
.getBasicManager();
311 StarBASIC
* pBasic
= pBasMgr
? pBasMgr
->GetLib( rLibName
) : 0;
312 sal_Bool bVBAEnabled
= pBasic
? pBasic
->isVBAEnabled(): sal_False
;
314 ImpCreateLibSubEntriesInVBAMode( pLibRootEntry
, rDocument
, rLibName
);
317 // get a sorted list of module names
318 Sequence
< ::rtl::OUString
> aModNames
= rDocument
.getObjectNames( E_SCRIPTS
, rLibName
);
319 sal_Int32 nModCount
= aModNames
.getLength();
320 const ::rtl::OUString
* pModNames
= aModNames
.getConstArray();
322 for ( sal_Int32 i
= 0 ; i
< nModCount
; i
++ )
324 String aModName
= pModNames
[ i
];
325 SvLBoxEntry
* pModuleEntry
= FindEntry( pLibRootEntry
, aModName
, OBJ_TYPE_MODULE
);
327 pModuleEntry
= AddEntry(
329 Image( IDEResId( RID_IMG_MODULE
) ),
330 Image( IDEResId( RID_IMG_MODULE_HC
) ),
331 pLibRootEntry
, false,
332 std::auto_ptr
< BasicEntry
>( new BasicEntry( OBJ_TYPE_MODULE
) ) );
335 if ( nMode
& BROWSEMODE_SUBS
)
337 Sequence
< ::rtl::OUString
> aNames
= BasicIDE::GetMethodNames( rDocument
, rLibName
, aModName
);
338 sal_Int32 nCount
= aNames
.getLength();
339 const ::rtl::OUString
* pNames
= aNames
.getConstArray();
341 for ( sal_Int32 j
= 0 ; j
< nCount
; j
++ )
343 String aName
= pNames
[ j
];
344 SvLBoxEntry
* pEntry
= FindEntry( pModuleEntry
, aName
, OBJ_TYPE_METHOD
);
348 Image( IDEResId( RID_IMG_MACRO
) ),
349 Image( IDEResId( RID_IMG_MACRO_HC
) ),
351 std::auto_ptr
< BasicEntry
>( new BasicEntry( OBJ_TYPE_METHOD
) ) );
357 catch ( const container::NoSuchElementException
& )
359 DBG_UNHANDLED_EXCEPTION();
365 if ( nMode
& BROWSEMODE_DIALOGS
)
367 Reference
< script::XLibraryContainer
> xDlgLibContainer( rDocument
.getLibraryContainer( E_SCRIPTS
) );
369 if ( xDlgLibContainer
.is() && xDlgLibContainer
->hasByName( aOULibName
) && xDlgLibContainer
->isLibraryLoaded( aOULibName
) )
373 // get a sorted list of dialog names
374 Sequence
< ::rtl::OUString
> aDlgNames( rDocument
.getObjectNames( E_DIALOGS
, rLibName
) );
375 sal_Int32 nDlgCount
= aDlgNames
.getLength();
376 const ::rtl::OUString
* pDlgNames
= aDlgNames
.getConstArray();
378 for ( sal_Int32 i
= 0 ; i
< nDlgCount
; i
++ )
380 String aDlgName
= pDlgNames
[ i
];
381 SvLBoxEntry
* pDialogEntry
= FindEntry( pLibRootEntry
, aDlgName
, OBJ_TYPE_DIALOG
);
383 pDialogEntry
= AddEntry(
385 Image( IDEResId( RID_IMG_DIALOG
) ),
386 Image( IDEResId( RID_IMG_DIALOG_HC
) ),
387 pLibRootEntry
, false,
388 std::auto_ptr
< BasicEntry
>( new BasicEntry( OBJ_TYPE_DIALOG
) ) );
391 catch ( container::NoSuchElementException
& )
393 DBG_UNHANDLED_EXCEPTION();
399 void BasicTreeListBox::ImpCreateLibSubEntriesInVBAMode( SvLBoxEntry
* pLibRootEntry
, const ScriptDocument
& rDocument
, const String
& rLibName
)
401 ::std::map
< BasicEntryType
, ::rtl::OUString
> aEntryMap
;
402 aEntryMap
.insert( ::std::make_pair( OBJ_TYPE_DOCUMENT_OBJECTS
, String( IDEResId( RID_STR_DOCUMENT_OBJECTS
) ) ) );
403 aEntryMap
.insert( ::std::make_pair( OBJ_TYPE_USERFORMS
, String( IDEResId( RID_STR_USERFORMS
) ) ) );
404 aEntryMap
.insert( ::std::make_pair( OBJ_TYPE_NORMAL_MODULES
, String( IDEResId( RID_STR_NORMAL_MODULES
) ) ) );
405 aEntryMap
.insert( ::std::make_pair( OBJ_TYPE_CLASS_MODULES
, String( IDEResId( RID_STR_CLASS_MODULES
) ) ) );
407 ::std::map
< BasicEntryType
, ::rtl::OUString
>::iterator iter
;
408 for( iter
= aEntryMap
.begin(); iter
!= aEntryMap
.end(); ++iter
)
410 BasicEntryType eType
= iter
->first
;
411 ::rtl::OUString aEntryName
= iter
->second
;
412 SvLBoxEntry
* pLibSubRootEntry
= FindEntry( pLibRootEntry
, aEntryName
, eType
);
413 if( pLibSubRootEntry
)
415 SetEntryBitmaps( pLibSubRootEntry
, Image( IDEResId( RID_IMG_MODLIB
) ), Image( IDEResId( RID_IMG_MODLIB_HC
) ) );
416 if ( IsExpanded( pLibSubRootEntry
) )
417 ImpCreateLibSubSubEntriesInVBAMode( pLibSubRootEntry
, rDocument
, rLibName
);
421 pLibSubRootEntry
= AddEntry(
423 Image( IDEResId( RID_IMG_MODLIB
) ),
424 Image( IDEResId( RID_IMG_MODLIB_HC
) ),
426 std::auto_ptr
< BasicEntry
>( new BasicEntry( eType
) ) );
431 void BasicTreeListBox::ImpCreateLibSubSubEntriesInVBAMode( SvLBoxEntry
* pLibSubRootEntry
, const ScriptDocument
& rDocument
, const String
& rLibName
)
433 uno::Reference
< container::XNameContainer
> xLib
= rDocument
.getOrCreateLibrary( E_SCRIPTS
, rLibName
);
439 // get a sorted list of module names
440 Sequence
< ::rtl::OUString
> aModNames
= rDocument
.getObjectNames( E_SCRIPTS
, rLibName
);
441 sal_Int32 nModCount
= aModNames
.getLength();
442 const ::rtl::OUString
* pModNames
= aModNames
.getConstArray();
444 BasicEntryDescriptor
aDesc( GetEntryDescriptor( pLibSubRootEntry
) );
445 BasicEntryType
eCurrentType( aDesc
.GetType() );
447 for ( sal_Int32 i
= 0 ; i
< nModCount
; i
++ )
449 String aModName
= pModNames
[ i
];
450 BasicEntryType eType
= OBJ_TYPE_UNKNOWN
;
451 switch( lcl_getModuleType( xLib
, aModName
) )
453 case script::ModuleType::Document
:
454 eType
= OBJ_TYPE_DOCUMENT_OBJECTS
;
456 case script::ModuleType::Form
:
457 eType
= OBJ_TYPE_USERFORMS
;
459 case script::ModuleType::Normal
:
460 eType
= OBJ_TYPE_NORMAL_MODULES
;
462 case script::ModuleType::Class
:
463 eType
= OBJ_TYPE_CLASS_MODULES
;
466 if( eType
!= eCurrentType
)
469 // display a nice friendly name in the ObjectModule tab,
470 // combining the objectname and module name, e.g. Sheet1 ( Financials )
471 String
aEntryName( aModName
);
472 if( eType
== OBJ_TYPE_DOCUMENT_OBJECTS
)
475 lcl_getObjectName( xLib
, aModName
, sObjName
);
478 aEntryName
.AppendAscii(" (").Append(sObjName
).AppendAscii(")");
481 SvLBoxEntry
* pModuleEntry
= FindEntry( pLibSubRootEntry
, aEntryName
, OBJ_TYPE_MODULE
);
483 pModuleEntry
= AddEntry(
485 Image( IDEResId( RID_IMG_MODULE
) ),
486 Image( IDEResId( RID_IMG_MODULE_HC
) ),
487 pLibSubRootEntry
, false,
488 std::auto_ptr
< BasicEntry
>( new BasicEntry( OBJ_TYPE_MODULE
) ) );
491 if ( nMode
& BROWSEMODE_SUBS
)
493 Sequence
< ::rtl::OUString
> aNames
= BasicIDE::GetMethodNames( rDocument
, rLibName
, aModName
);
494 sal_Int32 nCount
= aNames
.getLength();
495 const ::rtl::OUString
* pNames
= aNames
.getConstArray();
497 for ( sal_Int32 j
= 0 ; j
< nCount
; j
++ )
499 String aName
= pNames
[ j
];
500 SvLBoxEntry
* pEntry
= FindEntry( pModuleEntry
, aName
, OBJ_TYPE_METHOD
);
504 Image( IDEResId( RID_IMG_MACRO
) ),
505 Image( IDEResId( RID_IMG_MACRO_HC
) ),
507 std::auto_ptr
< BasicEntry
>( new BasicEntry( OBJ_TYPE_METHOD
) ) );
512 catch ( const container::NoSuchElementException
& )
514 DBG_UNHANDLED_EXCEPTION();
518 SvLBoxEntry
* BasicTreeListBox::ImpFindEntry( SvLBoxEntry
* pParent
, const String
& rText
)
521 SvLBoxEntry
* pEntry
= pParent
? FirstChild( pParent
) : GetEntry( nRootPos
);
524 if ( GetEntryText( pEntry
) == rText
)
527 pEntry
= pParent
? NextSibling( pEntry
) : GetEntry( ++nRootPos
);
532 void BasicTreeListBox::onDocumentCreated( const ScriptDocument
& /*_rDocument*/ )
537 void BasicTreeListBox::onDocumentOpened( const ScriptDocument
& /*_rDocument*/ )
542 void BasicTreeListBox::onDocumentSave( const ScriptDocument
& /*_rDocument*/ )
547 void BasicTreeListBox::onDocumentSaveDone( const ScriptDocument
& /*_rDocument*/ )
552 void BasicTreeListBox::onDocumentSaveAs( const ScriptDocument
& /*_rDocument*/ )
557 void BasicTreeListBox::onDocumentSaveAsDone( const ScriptDocument
& /*_rDocument*/ )
562 void BasicTreeListBox::onDocumentClosed( const ScriptDocument
& /*_rDocument*/ )
567 void BasicTreeListBox::onDocumentTitleChanged( const ScriptDocument
& /*_rDocument*/ )
572 void BasicTreeListBox::onDocumentModeChanged( const ScriptDocument
& /*_rDocument*/ )
577 void BasicTreeListBox::UpdateEntries()
579 BasicEntryDescriptor
aCurDesc( GetEntryDescriptor( FirstSelected() ) );
581 // Erstmal die vorhandenen Eintraege auf existens pruefen:
582 SvLBoxEntry
* pLastValid
= 0;
583 SvLBoxEntry
* pEntry
= First();
586 if ( IsValidEntry( pEntry
) )
590 delete (BasicEntry
*)pEntry
->GetUserData();
591 GetModel()->Remove( pEntry
);
593 pEntry
= pLastValid
? Next( pLastValid
) : First();
596 // Jetzt ueber die Basics rennen und in die Zweige eintragen
599 SetCurrentEntry( aCurDesc
);
602 SvLBoxEntry
* __EXPORT
BasicTreeListBox::CloneEntry( SvLBoxEntry
* pSource
)
604 SvLBoxEntry
* pNew
= SvTreeListBox::CloneEntry( pSource
);
605 BasicEntry
* pUser
= (BasicEntry
*)pSource
->GetUserData();
607 DBG_ASSERT( pUser
, "User-Daten?!" );
608 DBG_ASSERT( pUser
->GetType() != OBJ_TYPE_DOCUMENT
, "BasicTreeListBox::CloneEntry: document?!" );
610 BasicEntry
* pNewUser
= new BasicEntry( *pUser
);
611 pNew
->SetUserData( pNewUser
);
615 SvLBoxEntry
* BasicTreeListBox::FindEntry( SvLBoxEntry
* pParent
, const String
& rText
, BasicEntryType eType
)
618 SvLBoxEntry
* pEntry
= pParent
? FirstChild( pParent
) : GetEntry( nRootPos
);
621 BasicEntry
* pBasicEntry
= (BasicEntry
*)pEntry
->GetUserData();
622 DBG_ASSERT( pBasicEntry
, "FindEntry: Kein BasicEntry ?!" );
623 if ( ( pBasicEntry
->GetType() == eType
) && ( GetEntryText( pEntry
) == rText
) )
626 pEntry
= pParent
? NextSibling( pEntry
) : GetEntry( ++nRootPos
);
631 long BasicTreeListBox::ExpandingHdl()
633 // Expanding oder Collaps?
635 if ( GetModel()->GetDepth( GetHdlEntry() ) == 1 )
637 SvLBoxEntry
* pCurEntry
= GetCurEntry();
638 BasicEntryDescriptor
aDesc( GetEntryDescriptor( pCurEntry
) );
639 ScriptDocument
aDocument( aDesc
.GetDocument() );
640 OSL_ENSURE( aDocument
.isAlive(), "BasicTreeListBox::ExpandingHdl: no document, or document is dead!" );
641 if ( aDocument
.isAlive() )
643 String
aLibName( aDesc
.GetLibName() );
644 String
aLibSubName( aDesc
.GetLibSubName() );
645 String
aName( aDesc
.GetName() );
646 String
aMethodName( aDesc
.GetMethodName() );
648 if ( aLibName
.Len() && !aLibSubName
.Len() && !aName
.Len() && !aMethodName
.Len() )
650 // check password, if library is password protected and not verified
651 ::rtl::OUString
aOULibName( aLibName
);
652 Reference
< script::XLibraryContainer
> xModLibContainer( aDocument
.getLibraryContainer( E_SCRIPTS
) );
653 if ( xModLibContainer
.is() && xModLibContainer
->hasByName( aOULibName
) )
655 Reference
< script::XLibraryContainerPassword
> xPasswd( xModLibContainer
, UNO_QUERY
);
656 if ( xPasswd
.is() && xPasswd
->isLibraryPasswordProtected( aOULibName
) && !xPasswd
->isLibraryPasswordVerified( aOULibName
) )
659 bOK
= QueryPassword( xModLibContainer
, aLibName
, aPassword
);
668 BOOL
BasicTreeListBox::IsEntryProtected( SvLBoxEntry
* pEntry
)
670 BOOL bProtected
= FALSE
;
671 if ( pEntry
&& ( GetModel()->GetDepth( pEntry
) == 1 ) )
673 BasicEntryDescriptor
aDesc( GetEntryDescriptor( pEntry
) );
674 ScriptDocument
aDocument( aDesc
.GetDocument() );
675 OSL_ENSURE( aDocument
.isAlive(), "BasicTreeListBox::IsEntryProtected: no document, or document is dead!" );
676 if ( aDocument
.isAlive() )
678 ::rtl::OUString
aOULibName( aDesc
.GetLibName() );
679 Reference
< script::XLibraryContainer
> xModLibContainer( aDocument
.getLibraryContainer( E_SCRIPTS
) );
680 if ( xModLibContainer
.is() && xModLibContainer
->hasByName( aOULibName
) )
682 Reference
< script::XLibraryContainerPassword
> xPasswd( xModLibContainer
, UNO_QUERY
);
683 if ( xPasswd
.is() && xPasswd
->isLibraryPasswordProtected( aOULibName
) && !xPasswd
->isLibraryPasswordVerified( aOULibName
) )
693 SvLBoxEntry
* BasicTreeListBox::AddEntry(
694 const String
& rText
, const Image
& rImage
, const Image
& rImageHC
,
695 SvLBoxEntry
* pParent
, bool bChildrenOnDemand
, std::auto_ptr
< BasicEntry
> aUserData
)
697 SvLBoxEntry
* p
= InsertEntry(
698 rText
, rImage
, rImage
, pParent
, bChildrenOnDemand
, LIST_APPEND
,
699 aUserData
.release() ); // XXX possible leak
700 SetExpandedEntryBmp( p
, rImageHC
, BMP_COLOR_HIGHCONTRAST
);
701 SetCollapsedEntryBmp( p
, rImageHC
, BMP_COLOR_HIGHCONTRAST
);
705 void BasicTreeListBox::SetEntryBitmaps( SvLBoxEntry
* pEntry
, const Image
& rImage
, const Image
& rImageHC
)
707 SetExpandedEntryBmp( pEntry
, rImage
, BMP_COLOR_NORMAL
);
708 SetCollapsedEntryBmp( pEntry
, rImage
, BMP_COLOR_NORMAL
);
709 SetExpandedEntryBmp( pEntry
, rImageHC
, BMP_COLOR_HIGHCONTRAST
);
710 SetCollapsedEntryBmp( pEntry
, rImageHC
, BMP_COLOR_HIGHCONTRAST
);
713 LibraryType
BasicTreeListBox::GetLibraryType() const
715 LibraryType eType
= LIBRARY_TYPE_ALL
;
716 if ( ( nMode
& BROWSEMODE_MODULES
) && !( nMode
& BROWSEMODE_DIALOGS
) )
717 eType
= LIBRARY_TYPE_MODULE
;
718 else if ( !( nMode
& BROWSEMODE_MODULES
) && ( nMode
& BROWSEMODE_DIALOGS
) )
719 eType
= LIBRARY_TYPE_DIALOG
;
723 String
BasicTreeListBox::GetRootEntryName( const ScriptDocument
& rDocument
, LibraryLocation eLocation
) const
725 return rDocument
.getTitle( eLocation
, GetLibraryType() );
728 void BasicTreeListBox::GetRootEntryBitmaps( const ScriptDocument
& rDocument
, Image
& rImage
, Image
& rImageHC
)
730 OSL_ENSURE( rDocument
.isValid(), "BasicTreeListBox::GetRootEntryBitmaps: illegal document!" );
731 if ( !rDocument
.isValid() )
734 if ( rDocument
.isDocument() )
736 ::rtl::OUString sFactoryURL
;
737 ::comphelper::ComponentContext
aContext( ::comphelper::getProcessServiceFactory() );
738 Reference
< ::com::sun::star::frame::XModuleManager
> xModuleManager
;
739 if ( aContext
.createComponent( "com.sun.star.frame.ModuleManager", xModuleManager
) )
743 ::rtl::OUString
sModule( xModuleManager
->identify( rDocument
.getDocument() ) );
744 Reference
< container::XNameAccess
> xModuleConfig( xModuleManager
, UNO_QUERY
);
745 if ( xModuleConfig
.is() )
747 Sequence
< beans::PropertyValue
> aModuleDescr
;
748 xModuleConfig
->getByName( sModule
) >>= aModuleDescr
;
749 sal_Int32 nCount
= aModuleDescr
.getLength();
750 const beans::PropertyValue
* pModuleDescr
= aModuleDescr
.getConstArray();
751 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
753 if ( pModuleDescr
[ i
].Name
.equalsAsciiL(
754 RTL_CONSTASCII_STRINGPARAM( "ooSetupFactoryEmptyDocumentURL" ) ) )
756 pModuleDescr
[ i
].Value
>>= sFactoryURL
;
762 catch( const Exception
& )
764 DBG_UNHANDLED_EXCEPTION();
768 if ( sFactoryURL
.getLength() )
770 rImage
= SvFileInformationManager::GetFileImage( INetURLObject( sFactoryURL
),
772 FALSE
/* normal */ );
774 rImageHC
= SvFileInformationManager::GetFileImage( INetURLObject( sFactoryURL
),
776 TRUE
/* high contrast */ );
781 rImage
= Image( IDEResId( RID_IMG_DOCUMENT
) );
782 rImageHC
= Image( IDEResId( RID_IMG_DOCUMENT_HC
) );
787 rImage
= Image( IDEResId( RID_IMG_INSTALLATION
) );
788 rImageHC
= Image( IDEResId( RID_IMG_INSTALLATION_HC
) );
792 void BasicTreeListBox::SetCurrentEntry( BasicEntryDescriptor
& rDesc
)
794 SvLBoxEntry
* pCurEntry
= 0;
795 BasicEntryDescriptor
aDesc( rDesc
);
796 if ( aDesc
.GetType() == OBJ_TYPE_UNKNOWN
)
798 aDesc
= BasicEntryDescriptor(
799 ScriptDocument::getApplicationScriptDocument(),
800 LIBRARY_LOCATION_USER
, String::CreateFromAscii( "Standard" ),
801 String(), String::CreateFromAscii( "." ), OBJ_TYPE_UNKNOWN
);
803 ScriptDocument
aDocument( aDesc
.GetDocument() );
804 OSL_ENSURE( aDocument
.isValid(), "BasicTreeListBox::SetCurrentEntry: invalid document!" );
805 LibraryLocation
eLocation( aDesc
.GetLocation() );
806 SvLBoxEntry
* pRootEntry
= FindRootEntry( aDocument
, eLocation
);
809 pCurEntry
= pRootEntry
;
810 String
aLibName( aDesc
.GetLibName() );
811 if ( aLibName
.Len() )
813 Expand( pRootEntry
);
814 SvLBoxEntry
* pLibEntry
= FindEntry( pRootEntry
, aLibName
, OBJ_TYPE_LIBRARY
);
817 pCurEntry
= pLibEntry
;
818 String
aLibSubName( aDesc
.GetLibSubName() );
819 if( aLibSubName
.Len() )
822 SvLBoxEntry
* pLibSubEntry
= ImpFindEntry( pLibEntry
, aLibSubName
);
825 pCurEntry
= pLibSubEntry
;
828 String
aName( aDesc
.GetName() );
832 BasicEntryType eType
= OBJ_TYPE_MODULE
;
833 if ( aDesc
.GetType() == OBJ_TYPE_DIALOG
)
834 eType
= OBJ_TYPE_DIALOG
;
835 SvLBoxEntry
* pEntry
= FindEntry( pCurEntry
, aName
, eType
);
839 String
aMethodName( aDesc
.GetMethodName() );
840 if ( aMethodName
.Len() )
843 SvLBoxEntry
* pSubEntry
= FindEntry( pEntry
, aMethodName
, OBJ_TYPE_METHOD
);
846 pCurEntry
= pSubEntry
;
850 pSubEntry
= FirstChild( pEntry
);
852 pCurEntry
= pSubEntry
;
858 pEntry
= FirstChild( pLibEntry
);
866 pLibEntry
= FirstChild( pRootEntry
);
868 pCurEntry
= pLibEntry
;
874 pRootEntry
= First();
876 pCurEntry
= pRootEntry
;
879 SetCurEntry( pCurEntry
);