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: bastype3.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"
35 #include <ide_pch.hxx>
37 #define _SI_NOSBXCONTROLS
39 #include <basic/sbx.hxx>
40 #include <bastype2.hxx>
42 #include <baside2.hrc>
44 #include <bastypes.hxx>
46 #include <com/sun/star/script/XLibraryContainer.hpp>
47 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
49 using namespace ::com::sun::star::uno
;
50 using namespace ::com::sun::star
;
53 SV_DECL_VARARR( EntryArray
, SvLBoxEntry
*, 4, 4 )
55 SV_IMPL_VARARR( EntryArray
, SvLBoxEntry
*);
58 void __EXPORT
BasicTreeListBox::RequestingChilds( SvLBoxEntry
* pEntry
)
60 BasicEntryDescriptor
aDesc( GetEntryDescriptor( pEntry
) );
61 ScriptDocument
aDocument( aDesc
.GetDocument() );
62 OSL_ENSURE( aDocument
.isAlive(), "BasicTreeListBox::RequestingChilds: invalid document!" );
63 if ( !aDocument
.isAlive() )
66 LibraryLocation
eLocation( aDesc
.GetLocation() );
67 BasicEntryType
eType( aDesc
.GetType() );
69 if ( eType
== OBJ_TYPE_DOCUMENT
)
71 ImpCreateLibEntries( pEntry
, aDocument
, eLocation
);
73 else if ( eType
== OBJ_TYPE_LIBRARY
)
75 String
aLibName( aDesc
.GetLibName() );
76 ::rtl::OUString
aOULibName( aLibName
);
80 Reference
< script::XLibraryContainer
> xModLibContainer( aDocument
.getLibraryContainer( E_SCRIPTS
) );
81 if ( xModLibContainer
.is() && xModLibContainer
->hasByName( aOULibName
) )
83 Reference
< script::XLibraryContainerPassword
> xPasswd( xModLibContainer
, UNO_QUERY
);
84 if ( xPasswd
.is() && xPasswd
->isLibraryPasswordProtected( aOULibName
) && !xPasswd
->isLibraryPasswordVerified( aOULibName
) )
87 bOK
= QueryPassword( xModLibContainer
, aLibName
, aPassword
);
93 // load module library
94 BOOL bModLibLoaded
= FALSE
;
95 if ( xModLibContainer
.is() && xModLibContainer
->hasByName( aOULibName
) )
97 if ( !xModLibContainer
->isLibraryLoaded( aOULibName
) )
100 xModLibContainer
->loadLibrary( aOULibName
);
103 bModLibLoaded
= xModLibContainer
->isLibraryLoaded( aOULibName
);
106 // load dialog library
107 BOOL bDlgLibLoaded
= FALSE
;
108 Reference
< script::XLibraryContainer
> xDlgLibContainer( aDocument
.getLibraryContainer( E_DIALOGS
), UNO_QUERY
);
109 if ( xDlgLibContainer
.is() && xDlgLibContainer
->hasByName( aOULibName
) )
111 if ( !xDlgLibContainer
->isLibraryLoaded( aOULibName
) )
114 xDlgLibContainer
->loadLibrary( aOULibName
);
117 bDlgLibLoaded
= xDlgLibContainer
->isLibraryLoaded( aOULibName
);
120 if ( bModLibLoaded
|| bDlgLibLoaded
)
122 // create the sub entries
123 ImpCreateLibSubEntries( pEntry
, aDocument
, aLibName
);
126 bool bDlgMode
= ( nMode
& BROWSEMODE_DIALOGS
) && !( nMode
& BROWSEMODE_MODULES
);
127 Image
aImage( IDEResId( bDlgMode
? RID_IMG_DLGLIB
: RID_IMG_MODLIB
) );
128 Image
aImageHC( IDEResId( bDlgMode
? RID_IMG_DLGLIB_HC
: RID_IMG_MODLIB_HC
) );
129 SetEntryBitmaps( pEntry
, aImage
, aImageHC
);
133 DBG_ERROR( "BasicTreeListBox::RequestingChilds: Error loading library!" );
137 else if ( eType
== OBJ_TYPE_DOCUMENT_OBJECTS
138 || eType
== OBJ_TYPE_USERFORMS
139 || eType
== OBJ_TYPE_NORMAL_MODULES
140 || eType
== OBJ_TYPE_CLASS_MODULES
)
142 String
aLibName( aDesc
.GetLibName() );
143 ImpCreateLibSubSubEntriesInVBAMode( pEntry
, aDocument
, aLibName
);
146 DBG_ERROR( "BasicTreeListBox::RequestingChilds: Unknown Type!" );
150 void __EXPORT
BasicTreeListBox::ExpandedHdl()
152 SvLBoxEntry
* pEntry
= GetHdlEntry();
153 DBG_ASSERT( pEntry
, "Was wurde zugeklappt?" );
154 // Die OnDemand erzeugten Childs loeschen,
155 // SubChilds werden automatisch geloescht.
156 if ( !IsExpanded( pEntry
) && pEntry
->HasChildsOnDemand() )
158 SvLBoxEntry
* pChild
= FirstChild( pEntry
);
161 GetModel()->Remove( pChild
); // Ruft auch den DTOR
162 pChild
= FirstChild( pEntry
);
167 void BasicTreeListBox::ScanAllEntries()
169 ScanEntry( ScriptDocument::getApplicationScriptDocument(), LIBRARY_LOCATION_USER
);
170 ScanEntry( ScriptDocument::getApplicationScriptDocument(), LIBRARY_LOCATION_SHARE
);
172 ScriptDocuments
aDocuments( ScriptDocument::getAllScriptDocuments( ScriptDocument::DocumentsSorted
) );
173 for ( ScriptDocuments::const_iterator doc
= aDocuments
.begin();
174 doc
!= aDocuments
.end();
178 if ( doc
->isAlive() )
179 ScanEntry( *doc
, LIBRARY_LOCATION_DOCUMENT
);
183 SbxVariable
* BasicTreeListBox::FindVariable( SvLBoxEntry
* pEntry
)
188 String aLib
, aModOrObj
, aSubOrPropOrSObj
, aPropOrSubInSObj
;
189 ScriptDocument
aDocument( ScriptDocument::getApplicationScriptDocument() );
194 USHORT nDepth
= GetModel()->GetDepth( pEntry
);
202 aEntries
.C40_INSERT( SvLBoxEntry
, pEntry
, 0 );
207 aDocument
= ((BasicDocumentEntry
*)pEntry
->GetUserData())->GetDocument();
211 pEntry
= GetParent( pEntry
);
214 SbxVariable
* pVar
= 0;
215 bool bDocumentObjects
= false;
216 if ( aEntries
.Count() )
218 for ( USHORT n
= 0; n
< aEntries
.Count(); n
++ )
220 SvLBoxEntry
* pLE
= aEntries
[n
];
221 DBG_ASSERT( pLE
, "Entrie im Array nicht gefunden" );
222 BasicEntry
* pBE
= (BasicEntry
*)pLE
->GetUserData();
223 DBG_ASSERT( pBE
, "Keine Daten im Eintrag gefunden!" );
224 String
aName( GetEntryText( pLE
) );
226 switch ( pBE
->GetType() )
228 case OBJ_TYPE_LIBRARY
:
230 BasicManager
* pBasMgr
= aDocument
.getBasicManager();
232 pVar
= pBasMgr
->GetLib( aName
);
235 case OBJ_TYPE_MODULE
:
237 DBG_ASSERT( pVar
&& pVar
->IsA( TYPE(StarBASIC
) ), "FindVariable: Ungueltiges Basic" );
238 // extract the module name from the string like "Sheet1 (Example1)"
239 if( bDocumentObjects
)
241 sal_uInt16 nIndex
= 0;
242 aName
= aName
.GetToken( 0, ' ', nIndex
);
244 pVar
= ((StarBASIC
*)pVar
)->FindModule( aName
);
247 case OBJ_TYPE_METHOD
:
249 DBG_ASSERT( pVar
&& ( (pVar
->IsA( TYPE(SbModule
) )) || (pVar
->IsA( TYPE(SbxObject
) )) ), "FindVariable: Ungueltiges Modul/Objekt" );
250 pVar
= ((SbxObject
*)pVar
)->GetMethods()->Find( aName
, SbxCLASS_METHOD
);
253 case OBJ_TYPE_DIALOG
:
255 // sbx dialogs removed
258 case OBJ_TYPE_DOCUMENT_OBJECTS
:
259 bDocumentObjects
= true;
260 case OBJ_TYPE_USERFORMS
:
261 case OBJ_TYPE_NORMAL_MODULES
:
262 case OBJ_TYPE_CLASS_MODULES
:
264 // skip, to find the child entry.
269 DBG_ERROR( "FindVariable: Unbekannter Typ!" );
282 BasicEntryDescriptor
BasicTreeListBox::GetEntryDescriptor( SvLBoxEntry
* pEntry
)
284 ScriptDocument
aDocument( ScriptDocument::getApplicationScriptDocument() );
285 LibraryLocation eLocation
= LIBRARY_LOCATION_UNKNOWN
;
290 BasicEntryType eType
= OBJ_TYPE_UNKNOWN
;
293 return BasicEntryDescriptor( aDocument
, eLocation
, aLibName
, aLibSubName
, aName
, aMethodName
, eType
);
299 USHORT nDepth
= GetModel()->GetDepth( pEntry
);
307 aEntries
.C40_INSERT( SvLBoxEntry
, pEntry
, 0 );
312 BasicDocumentEntry
* pBasicDocumentEntry
= (BasicDocumentEntry
*)pEntry
->GetUserData();
313 if ( pBasicDocumentEntry
)
315 aDocument
= pBasicDocumentEntry
->GetDocument();
316 eLocation
= pBasicDocumentEntry
->GetLocation();
317 eType
= OBJ_TYPE_DOCUMENT
;
322 pEntry
= GetParent( pEntry
);
325 if ( aEntries
.Count() )
327 for ( USHORT n
= 0; n
< aEntries
.Count(); n
++ )
329 SvLBoxEntry
* pLE
= aEntries
[n
];
330 DBG_ASSERT( pLE
, "Entrie im Array nicht gefunden" );
331 BasicEntry
* pBE
= (BasicEntry
*)pLE
->GetUserData();
332 DBG_ASSERT( pBE
, "Keine Daten im Eintrag gefunden!" );
334 switch ( pBE
->GetType() )
336 case OBJ_TYPE_LIBRARY
:
338 aLibName
= GetEntryText( pLE
);
339 eType
= pBE
->GetType();
342 case OBJ_TYPE_MODULE
:
344 aName
= GetEntryText( pLE
);
345 eType
= pBE
->GetType();
348 case OBJ_TYPE_METHOD
:
350 aMethodName
= GetEntryText( pLE
);
351 eType
= pBE
->GetType();
354 case OBJ_TYPE_DIALOG
:
356 aName
= GetEntryText( pLE
);
357 eType
= pBE
->GetType();
360 case OBJ_TYPE_DOCUMENT_OBJECTS
:
361 case OBJ_TYPE_USERFORMS
:
362 case OBJ_TYPE_NORMAL_MODULES
:
363 case OBJ_TYPE_CLASS_MODULES
:
365 aLibSubName
= GetEntryText( pLE
);
366 eType
= pBE
->GetType();
371 DBG_ERROR( "GetEntryDescriptor: Unbekannter Typ!" );
372 eType
= OBJ_TYPE_UNKNOWN
;
377 if ( eType
== OBJ_TYPE_UNKNOWN
)
382 return BasicEntryDescriptor( aDocument
, eLocation
, aLibName
, aLibSubName
, aName
, aMethodName
, eType
);
385 USHORT
BasicTreeListBox::ConvertType( BasicEntryType eType
)
387 USHORT nType
= OBJ_TYPE_UNKNOWN
;
391 case OBJ_TYPE_DOCUMENT
:
393 nType
= BASICIDE_TYPE_SHELL
;
396 case OBJ_TYPE_LIBRARY
:
398 nType
= BASICIDE_TYPE_LIBRARY
;
401 case OBJ_TYPE_MODULE
:
403 nType
= BASICIDE_TYPE_MODULE
;
406 case OBJ_TYPE_DIALOG
:
408 nType
= BASICIDE_TYPE_DIALOG
;
411 case OBJ_TYPE_METHOD
:
413 nType
= BASICIDE_TYPE_METHOD
;
422 bool BasicTreeListBox::IsValidEntry( SvLBoxEntry
* pEntry
)
424 bool bIsValid
= false;
426 BasicEntryDescriptor
aDesc( GetEntryDescriptor( pEntry
) );
427 ScriptDocument
aDocument( aDesc
.GetDocument() );
428 LibraryLocation
eLocation( aDesc
.GetLocation() );
429 String
aLibName( aDesc
.GetLibName() );
430 String
aName( aDesc
.GetName() );
431 String
aMethodName( aDesc
.GetMethodName() );
432 BasicEntryType
eType( aDesc
.GetType() );
436 case OBJ_TYPE_DOCUMENT
:
438 bIsValid
= aDocument
.isAlive()
439 && ( aDocument
.isApplication()
440 || GetRootEntryName( aDocument
, eLocation
) == GetEntryText( pEntry
)
444 case OBJ_TYPE_LIBRARY
:
446 bIsValid
= aDocument
.hasLibrary( E_SCRIPTS
, aLibName
) || aDocument
.hasLibrary( E_DIALOGS
, aLibName
);
449 case OBJ_TYPE_MODULE
:
451 bIsValid
= aDocument
.hasModule( aLibName
, aName
);
454 case OBJ_TYPE_DIALOG
:
456 bIsValid
= aDocument
.hasDialog( aLibName
, aName
);
459 case OBJ_TYPE_METHOD
:
461 bIsValid
= BasicIDE::HasMethod( aDocument
, aLibName
, aName
, aMethodName
);
464 case OBJ_TYPE_DOCUMENT_OBJECTS
:
465 case OBJ_TYPE_USERFORMS
:
466 case OBJ_TYPE_NORMAL_MODULES
:
467 case OBJ_TYPE_CLASS_MODULES
:
478 SbModule
* BasicTreeListBox::FindModule( SvLBoxEntry
* pEntry
)
480 SbxVariable
* pVar
= FindVariable( pEntry
);
481 if ( pVar
&& pVar
->IsA( TYPE(SbModule
) ) )
482 return (SbModule
*)pVar
;
486 SvLBoxEntry
* BasicTreeListBox::FindRootEntry( const ScriptDocument
& rDocument
, LibraryLocation eLocation
)
488 OSL_ENSURE( rDocument
.isValid(), "BasicTreeListBox::FindRootEntry: invalid document!" );
490 SvLBoxEntry
* pRootEntry
= GetEntry( nRootPos
);
493 DBG_ASSERT( (((BasicEntry
*)pRootEntry
->GetUserData())->GetType() == OBJ_TYPE_DOCUMENT
), "Kein Shelleintrag?" );
494 BasicDocumentEntry
* pBasicDocumentEntry
= (BasicDocumentEntry
*)pRootEntry
->GetUserData();
495 if ( pBasicDocumentEntry
&& ( pBasicDocumentEntry
->GetDocument() == rDocument
) && pBasicDocumentEntry
->GetLocation() == eLocation
)
497 pRootEntry
= GetEntry( ++nRootPos
);
502 String
CreateMgrAndLibStr( const String
& rMgrName
, const String
& rLibName
)
506 aName
+= String( RTL_CONSTASCII_USTRINGPARAM( "]." ) );