xref: /trunk/main/basctl/source/basicide/moduldlg.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_basctl.hxx"
30 
31 #include <memory>
32 
33 #include <ide_pch.hxx>
34 
35 
36 #include <moduldlg.hrc>
37 #include <moduldlg.hxx>
38 #include <basidesh.hrc>
39 #include <basidesh.hxx>
40 #include <bastypes.hxx>
41 #include <baside3.hxx>
42 #include <basobj.hxx>
43 #include <baside2.hrc>
44 #include <sbxitem.hxx>
45 #include <iderdll.hxx>
46 
47 #ifndef _COM_SUN_STAR_IO_XINPUTSTREAMPROVIDER_HXX_
48 #include <com/sun/star/io/XInputStreamProvider.hpp>
49 #endif
50 #ifndef _COM_SUN_STAR_SCRIPT_XLIBRYARYCONTAINER2_HPP_
51 #include <com/sun/star/script/XLibraryContainer2.hpp>
52 #endif
53 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
54 #include <com/sun/star/resource/XStringResourceManager.hpp>
55 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
56 #include <comphelper/processfactory.hxx>
57 #include <xmlscript/xmldlg_imexp.hxx>
58 
59 #include "localizationmgr.hxx"
60 #include <basic/sbx.hxx>
61 #include <tools/diagnose_ex.h>
62 
63 using namespace ::com::sun::star;
64 using namespace ::com::sun::star::uno;
65 using namespace ::com::sun::star::lang;
66 using namespace ::com::sun::star::resource;
67 
68 
69 ExtBasicTreeListBox::ExtBasicTreeListBox( Window* pParent, const ResId& rRes )
70 	: BasicTreeListBox( pParent, rRes )
71 {
72 }
73 
74 
75 
76 ExtBasicTreeListBox::~ExtBasicTreeListBox()
77 {
78 }
79 
80 sal_Bool __EXPORT ExtBasicTreeListBox::EditingEntry( SvLBoxEntry* pEntry, Selection& )
81 {
82     sal_Bool bRet = sal_False;
83 
84     if ( pEntry )
85     {
86         sal_uInt16 nDepth = GetModel()->GetDepth( pEntry );
87         if ( nDepth >= 2 )
88         {
89             BasicEntryDescriptor aDesc( GetEntryDescriptor( pEntry ) );
90             ScriptDocument aDocument( aDesc.GetDocument() );
91             ::rtl::OUString aOULibName( aDesc.GetLibName() );
92             Reference< script::XLibraryContainer2 > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
93             Reference< script::XLibraryContainer2 > xDlgLibContainer( aDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY );
94             if ( !( ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryReadOnly( aOULibName ) ) ||
95                     ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && xDlgLibContainer->isLibraryReadOnly( aOULibName ) ) ) )
96             {
97                 // allow editing only for libraries, which are not readonly
98                 bRet = sal_True;
99             }
100         }
101     }
102 
103     return bRet;
104 }
105 
106 sal_Bool __EXPORT ExtBasicTreeListBox::EditedEntry( SvLBoxEntry* pEntry, const String& rNewText )
107 {
108 	sal_Bool bValid = BasicIDE::IsValidSbxName( rNewText );
109     if ( !bValid )
110     {
111 		ErrorBox( this, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_BADSBXNAME ) ) ).Execute();
112         return sal_False;
113     }
114 
115 	String aCurText( GetEntryText( pEntry ) );
116 	if ( aCurText == rNewText )
117         // nothing to do
118         return sal_True;
119 
120     BasicEntryDescriptor aDesc( GetEntryDescriptor( pEntry ) );
121 	ScriptDocument aDocument( aDesc.GetDocument() );
122     DBG_ASSERT( aDocument.isValid(), "ExtBasicTreeListBox::EditedEntry: no document!" );
123     if ( !aDocument.isValid() )
124         return sal_False;
125 	String aLibName( aDesc.GetLibName() );
126     BasicEntryType eType( aDesc.GetType() );
127 
128     bool bSuccess = ( eType == OBJ_TYPE_MODULE )
129         ?   BasicIDE::RenameModule( this, aDocument, aLibName, aCurText, rNewText )
130         :   BasicIDE::RenameDialog( this, aDocument, aLibName, aCurText, rNewText );
131 
132     if ( !bSuccess )
133         return sal_False;
134 
135 	BasicIDE::MarkDocumentModified( aDocument );
136 
137     BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
138     SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
139 	SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
140 	if( pDispatcher )
141 	{
142         SbxItem aSbxItem( SID_BASICIDE_ARG_SBX, aDocument, aLibName, rNewText, ConvertType( eType ) );
143 		pDispatcher->Execute( SID_BASICIDE_SBXRENAMED,
144 								SFX_CALLMODE_SYNCHRON, &aSbxItem, 0L );
145 	}
146 
147 	// OV-Bug?!
148 	SetEntryText( pEntry, rNewText );
149 	SetCurEntry( pEntry );
150 	SetCurEntry( pEntry );
151 	Select( pEntry, sal_False );
152 	Select( pEntry );		// damit Handler gerufen wird => Edit updaten
153 
154     return sal_True;
155 }
156 
157 
158 DragDropMode __EXPORT ExtBasicTreeListBox::NotifyStartDrag( TransferDataContainer&, SvLBoxEntry* pEntry )
159 {
160     DragDropMode nMode_ = SV_DRAGDROP_NONE;
161 
162     if ( pEntry )
163     {
164         sal_uInt16 nDepth = GetModel()->GetDepth( pEntry );
165         if ( nDepth >= 2 )
166         {
167             nMode_ = SV_DRAGDROP_CTRL_COPY;
168             BasicEntryDescriptor aDesc( GetEntryDescriptor( pEntry ) );
169             ScriptDocument aDocument( aDesc.GetDocument() );
170             ::rtl::OUString aOULibName( aDesc.GetLibName() );
171 			// allow MOVE mode only for libraries, which are not readonly
172             Reference< script::XLibraryContainer2 > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
173             Reference< script::XLibraryContainer2 > xDlgLibContainer( aDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY );
174             if ( !( ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryReadOnly( aOULibName ) ) ||
175                     ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && xDlgLibContainer->isLibraryReadOnly( aOULibName ) ) ) )
176             {
177 				// Only allow copy for localized libraries
178 				bool bAllowMove = true;
179 				if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) )
180 				{
181 					// Get StringResourceManager
182 					Reference< container::XNameContainer > xDialogLib( aDocument.getLibrary( E_DIALOGS, aOULibName, sal_True ) );
183 					Reference< XStringResourceManager > xSourceMgr =
184 						LocalizationMgr::getStringResourceFromDialogLibrary( xDialogLib );
185 					if( xSourceMgr.is() )
186 						bAllowMove = ( xSourceMgr->getLocales().getLength() == 0 );
187 				}
188 				if( bAllowMove )
189 					nMode_ |= SV_DRAGDROP_CTRL_MOVE;
190             }
191         }
192     }
193 
194     return nMode_;
195 }
196 
197 
198 sal_Bool __EXPORT ExtBasicTreeListBox::NotifyAcceptDrop( SvLBoxEntry* pEntry )
199 {
200 	// don't drop on a BasicManager (nDepth == 0)
201 	sal_uInt16 nDepth = pEntry ? GetModel()->GetDepth( pEntry ) : 0;
202 	sal_Bool bValid = nDepth ? sal_True : sal_False;
203 
204 	// don't drop in the same library
205 	SvLBoxEntry* pSelected = FirstSelected();
206 	if ( ( nDepth == 1 ) && ( pEntry == GetParent( pSelected ) ) )
207 		bValid = sal_False;
208 	else if ( ( nDepth == 2 ) && ( GetParent( pEntry ) == GetParent( pSelected ) ) )
209 		bValid = sal_False;
210 
211     // don't drop on a library, which is not loaded, readonly or password protected
212     // or which already has a module/dialog with this name
213     if ( bValid && ( nDepth > 0 ) )
214     {
215 		// get source module/dialog name
216         BasicEntryDescriptor aSourceDesc( GetEntryDescriptor( pSelected ) );
217 		String aSourceName( aSourceDesc.GetName() );
218         BasicEntryType eSourceType( aSourceDesc.GetType() );
219 
220         // get target shell and target library name
221         BasicEntryDescriptor aDestDesc( GetEntryDescriptor( pEntry ) );
222         const ScriptDocument& rDestDoc( aDestDesc.GetDocument() );
223         String aDestLibName( aDestDesc.GetLibName() );
224         ::rtl::OUString aOUDestLibName( aDestLibName );
225 
226         // check if module library is not loaded, readonly or password protected
227         Reference< script::XLibraryContainer2 > xModLibContainer( rDestDoc.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
228 	    if ( xModLibContainer.is() && xModLibContainer->hasByName( aOUDestLibName ) )
229         {
230             if ( !xModLibContainer->isLibraryLoaded( aOUDestLibName ) )
231                 bValid = sal_False;
232 
233             if ( xModLibContainer->isLibraryReadOnly( aOUDestLibName ) )
234                 bValid = sal_False;
235 
236             Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
237             if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aOUDestLibName ) && !xPasswd->isLibraryPasswordVerified( aOUDestLibName ) )
238                 bValid = sal_False;
239         }
240 
241         // check if dialog library is not loaded or readonly
242         Reference< script::XLibraryContainer2 > xDlgLibContainer( rDestDoc.getLibraryContainer( E_DIALOGS ), UNO_QUERY );
243         if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOUDestLibName ) )
244         {
245             if ( !xDlgLibContainer->isLibraryLoaded( aOUDestLibName ) )
246                 bValid = sal_False;
247 
248             if ( xDlgLibContainer->isLibraryReadOnly( aOUDestLibName ) )
249                 bValid = sal_False;
250         }
251 
252 	    // check, if module/dialog with this name is already existing in target library
253 		if ( ( eSourceType == OBJ_TYPE_MODULE && rDestDoc.hasModule( aDestLibName, aSourceName ) ) ||
254 			( eSourceType == OBJ_TYPE_DIALOG && rDestDoc.hasDialog( aDestLibName, aSourceName ) ) )
255 		{
256 			bValid = sal_False;
257 		}
258     }
259 
260 	return bValid;
261 }
262 
263 
264 sal_Bool __EXPORT ExtBasicTreeListBox::NotifyMoving( SvLBoxEntry* pTarget, SvLBoxEntry* pEntry,
265 						SvLBoxEntry*& rpNewParent, sal_uLong& rNewChildPos )
266 {
267 	return NotifyCopyingMoving( pTarget, pEntry,
268 									rpNewParent, rNewChildPos, sal_True );
269 }
270 
271 
272 sal_Bool __EXPORT ExtBasicTreeListBox::NotifyCopying( SvLBoxEntry* pTarget, SvLBoxEntry* pEntry,
273 						SvLBoxEntry*& rpNewParent, sal_uLong& rNewChildPos )
274 {
275 //	return sal_False;	// Wie kopiere ich ein SBX ?!
276 	return NotifyCopyingMoving( pTarget, pEntry,
277 									rpNewParent, rNewChildPos, sal_False );
278 }
279 
280 
281 void BasicIDEShell::CopyDialogResources( Reference< io::XInputStreamProvider >& io_xISP,
282 	const ScriptDocument& rSourceDoc, const String& rSourceLibName, const ScriptDocument& rDestDoc,
283 	const String& rDestLibName,	const String& rDlgName )
284 {
285 	if ( !io_xISP.is() )
286 		return;
287 
288 	// Get StringResourceManager
289 	Reference< container::XNameContainer > xSourceDialogLib( rSourceDoc.getLibrary( E_DIALOGS, rSourceLibName, sal_True ) );
290 	Reference< XStringResourceManager > xSourceMgr =
291 		LocalizationMgr::getStringResourceFromDialogLibrary( xSourceDialogLib );
292 	if( !xSourceMgr.is() )
293 		return;
294 	bool bSourceLocalized = ( xSourceMgr->getLocales().getLength() > 0 );
295 
296 	Reference< container::XNameContainer > xDestDialogLib( rDestDoc.getLibrary( E_DIALOGS, rDestLibName, sal_True ) );
297 	Reference< XStringResourceManager > xDestMgr =
298 		LocalizationMgr::getStringResourceFromDialogLibrary( xDestDialogLib );
299 	if( !xDestMgr.is() )
300 		return;
301 	bool bDestLocalized = ( xDestMgr->getLocales().getLength() > 0 );
302 
303 	if( !bSourceLocalized && !bDestLocalized )
304 		return;
305 
306 	// create dialog model
307 	Reference< lang::XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory();
308 	Reference< container::XNameContainer > xDialogModel = Reference< container::XNameContainer >( xMSF->createInstance
309 		( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialogModel" ) ) ), UNO_QUERY );
310 	Reference< io::XInputStream > xInput( io_xISP->createInputStream() );
311     Reference< XComponentContext > xContext;
312     Reference< beans::XPropertySet > xProps( xMSF, UNO_QUERY );
313     OSL_ASSERT( xProps.is() );
314     OSL_VERIFY( xProps->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext );
315 	::xmlscript::importDialogModel( xInput, xDialogModel, xContext );
316 
317 	if( xDialogModel.is() )
318 	{
319 		if( bSourceLocalized && bDestLocalized )
320 		{
321 			Reference< resource::XStringResourceResolver > xSourceStringResolver( xSourceMgr, UNO_QUERY );
322 			LocalizationMgr::copyResourceForDroppedDialog( xDialogModel, rDlgName, xDestMgr, xSourceStringResolver );
323 		}
324 		else if( bSourceLocalized )
325 		{
326 			LocalizationMgr::resetResourceForDialog( xDialogModel, xSourceMgr );
327 		}
328 		else if( bDestLocalized )
329 		{
330 			LocalizationMgr::setResourceIDsForDialog( xDialogModel, xDestMgr );
331 		}
332 		io_xISP = ::xmlscript::exportDialogModel( xDialogModel, xContext );
333 	}
334 }
335 
336 
337 sal_Bool __EXPORT ExtBasicTreeListBox::NotifyCopyingMoving( SvLBoxEntry* pTarget, SvLBoxEntry* pEntry,
338 						SvLBoxEntry*& rpNewParent, sal_uLong& rNewChildPos, sal_Bool bMove )
339 {
340 	(void)pEntry;
341 	DBG_ASSERT( pEntry, "Kein Eintrag?" );	// Hier ASS ok, sollte nicht mit
342 	DBG_ASSERT( pTarget, "Kein Ziel?" );	// NULL (ganz vorne) erreicht werden
343 	sal_uInt16 nDepth = GetModel()->GetDepth( pTarget );
344 	DBG_ASSERT( nDepth, "Tiefe?" );
345 	if ( nDepth == 1 )
346 	{
347 		// Target = Basic => Modul/Dialog unter das Basic haengen...
348 		rpNewParent = pTarget;
349 		rNewChildPos = 0;
350 	}
351 	else if ( nDepth >= 2 )
352 	{
353 		// Target = Modul/Dialog => Modul/Dialog unter das uebergeordnete Basic haengen...
354 		rpNewParent = GetParent( pTarget );
355 		rNewChildPos = GetModel()->GetRelPos( pTarget ) + 1;
356 	}
357 
358     // get target shell and target library name
359     BasicEntryDescriptor aDestDesc( GetEntryDescriptor( rpNewParent ) );
360     const ScriptDocument& rDestDoc( aDestDesc.GetDocument() );
361     String aDestLibName( aDestDesc.GetLibName() );
362 
363 	// get source shell, library name and module/dialog name
364     BasicEntryDescriptor aSourceDesc( GetEntryDescriptor( FirstSelected() ) );
365     const ScriptDocument rSourceDoc( aSourceDesc.GetDocument() );
366 	String aSourceLibName( aSourceDesc.GetLibName() );
367 	String aSourceName( aSourceDesc.GetName() );
368     BasicEntryType eType( aSourceDesc.GetType() );
369 
370 	// get dispatcher
371     BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
372     SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
373 	SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
374 
375 	if ( bMove )	// move
376 	{
377 		// remove source module/dialog window
378         if ( rSourceDoc != rDestDoc || aSourceLibName != aDestLibName )
379 		{
380 			if( pDispatcher )
381 			{
382                 SbxItem aSbxItem( SID_BASICIDE_ARG_SBX, rSourceDoc, aSourceLibName, aSourceName, ConvertType( eType ) );
383 				pDispatcher->Execute( SID_BASICIDE_SBXDELETED,
384 									  SFX_CALLMODE_SYNCHRON, &aSbxItem, 0L );
385 			}
386 		}
387 
388 		try
389 		{
390 			if ( eType == OBJ_TYPE_MODULE )	// module
391 			{
392 				// get module
393                 ::rtl::OUString aModule;
394                 if ( rSourceDoc.getModule( aSourceLibName, aSourceName, aModule ) )
395                 {
396 				    // remove module from source library
397                     if ( rSourceDoc.removeModule( aSourceLibName, aSourceName ) )
398                     {
399 				        BasicIDE::MarkDocumentModified( rSourceDoc );
400 
401 				        // insert module into target library
402                         if ( rDestDoc.insertModule( aDestLibName, aSourceName, aModule ) )
403 				            BasicIDE::MarkDocumentModified( rDestDoc );
404                     }
405                 }
406 			}
407 			else if ( eType == OBJ_TYPE_DIALOG )	// dialog
408 			{
409 				// get dialog
410                 Reference< io::XInputStreamProvider > xISP;
411                 if ( rSourceDoc.getDialog( aSourceLibName, aSourceName, xISP ) )
412 				{
413 					BasicIDEShell::CopyDialogResources( xISP, rSourceDoc,
414 						aSourceLibName, rDestDoc, aDestLibName, aSourceName );
415 
416 					// remove dialog from source library
417 					if ( BasicIDE::RemoveDialog( rSourceDoc, aSourceLibName, aSourceName ) )
418                     {
419 					    BasicIDE::MarkDocumentModified( rSourceDoc );
420 
421 					    // insert dialog into target library
422                         if ( rDestDoc.insertDialog( aDestLibName, aSourceName, xISP ) )
423 					        BasicIDE::MarkDocumentModified( rDestDoc );
424                     }
425 				}
426 			}
427 		}
428 		catch ( uno::Exception& )
429 		{
430 			DBG_UNHANDLED_EXCEPTION();
431 		}
432 	}
433 	else	// copy
434 	{
435 		try
436 		{
437 			if ( eType == OBJ_TYPE_MODULE )	// module
438 			{
439 				// get module
440 				::rtl::OUString aModule;
441                 if ( rSourceDoc.getModule( aSourceLibName, aSourceName, aModule ) )
442                 {
443 				    // insert module into target library
444                     if ( rDestDoc.insertModule( aDestLibName, aSourceName, aModule ) )
445 				        BasicIDE::MarkDocumentModified( rDestDoc );
446                 }
447 			}
448 			else if ( eType == OBJ_TYPE_DIALOG )	// dialog
449 			{
450 				// get dialog
451 				Reference< io::XInputStreamProvider > xISP;
452                 if ( rSourceDoc.getDialog( aSourceLibName, aSourceName, xISP ) )
453 				{
454 					BasicIDEShell::CopyDialogResources( xISP, rSourceDoc,
455 						aSourceLibName, rDestDoc, aDestLibName, aSourceName );
456 
457 					// insert dialog into target library
458                     if ( rDestDoc.insertDialog( aDestLibName, aSourceName, xISP ) )
459 					    BasicIDE::MarkDocumentModified( rDestDoc );
460 				}
461 			}
462 		}
463 		catch ( const Exception& )
464 		{
465 			DBG_UNHANDLED_EXCEPTION();
466 		}
467 	}
468 
469 	// create target module/dialog window
470     if ( rSourceDoc != rDestDoc || aSourceLibName != aDestLibName )
471 	{
472 		if( pDispatcher )
473 		{
474             SbxItem aSbxItem( SID_BASICIDE_ARG_SBX, rDestDoc, aDestLibName, aSourceName, ConvertType( eType ) );
475 			pDispatcher->Execute( SID_BASICIDE_SBXINSERTED,
476 								  SFX_CALLMODE_SYNCHRON, &aSbxItem, 0L );
477 		}
478 	}
479 
480 	return 2;	// Aufklappen...
481 }
482 
483 OrganizeDialog::OrganizeDialog( Window* pParent, sal_Int16 tabId, BasicEntryDescriptor& rDesc )
484     :TabDialog( pParent, IDEResId( RID_TD_ORGANIZE ) )
485     ,aTabCtrl( this, IDEResId( RID_TC_ORGANIZE ) )
486     ,m_aCurEntry( rDesc )
487 {
488 	FreeResource();
489 	aTabCtrl.SetActivatePageHdl( LINK( this, OrganizeDialog, ActivatePageHdl ) );
490     if( tabId == 0 )
491     {
492         aTabCtrl.SetCurPageId( RID_TP_MOD );
493     }
494     else if ( tabId == 1 )
495     {
496         aTabCtrl.SetCurPageId( RID_TP_DLG );
497     }
498     else
499     {
500         aTabCtrl.SetCurPageId( RID_TP_LIB );
501     }
502 
503 	ActivatePageHdl( &aTabCtrl );
504 
505     BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
506     SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
507 	SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
508     if( pDispatcher )
509 	{
510 		pDispatcher->Execute( SID_BASICIDE_STOREALLMODULESOURCES );
511 	}
512 }
513 
514 __EXPORT OrganizeDialog::~OrganizeDialog()
515 {
516 	for ( sal_uInt16 i = 0; i < aTabCtrl.GetPageCount(); i++ )
517 		delete aTabCtrl.GetTabPage( aTabCtrl.GetPageId( i ) );
518 };
519 
520 short OrganizeDialog::Execute()
521 {
522 	Window* pPrevDlgParent = Application::GetDefDialogParent();
523 	Application::SetDefDialogParent( this );
524 	short nRet = TabDialog::Execute();
525 	Application::SetDefDialogParent( pPrevDlgParent );
526 	return nRet;
527 }
528 
529 
530 IMPL_LINK( OrganizeDialog, ActivatePageHdl, TabControl *, pTabCtrl )
531 {
532 	sal_uInt16 nId = pTabCtrl->GetCurPageId();
533 	// Wenn TabPage noch nicht erzeugt wurde, dann erzeugen
534 	if ( !pTabCtrl->GetTabPage( nId ) )
535 	{
536 		TabPage* pNewTabPage = 0;
537 		switch ( nId )
538 		{
539 			case RID_TP_MOD:
540 			{
541 				pNewTabPage = new ObjectPage( pTabCtrl, IDEResId( RID_TP_MODULS ), BROWSEMODE_MODULES );
542 				((ObjectPage*)pNewTabPage)->SetTabDlg( this );
543         		((ObjectPage*)pNewTabPage)->SetCurrentEntry( m_aCurEntry );
544 			}
545 			break;
546 			case RID_TP_DLG:
547 			{
548 				pNewTabPage = new ObjectPage( pTabCtrl, IDEResId( RID_TP_DLGS ), BROWSEMODE_DIALOGS );
549 				((ObjectPage*)pNewTabPage)->SetTabDlg( this );
550         		((ObjectPage*)pNewTabPage)->SetCurrentEntry( m_aCurEntry );
551 			}
552 			break;
553 			case RID_TP_LIB:
554 			{
555 				pNewTabPage = new LibPage( pTabCtrl );
556 				((LibPage*)pNewTabPage)->SetTabDlg( this );
557 			}
558 			break;
559 			default:	DBG_ERROR( "PageHdl: Unbekannte ID!" );
560 		}
561 		DBG_ASSERT( pNewTabPage, "Keine Page!" );
562 		pTabCtrl->SetTabPage( nId, pNewTabPage );
563 	}
564 	return 0;
565 }
566 
567 ObjectPage::ObjectPage( Window * pParent, const ResId& rResId, sal_uInt16 nMode ) :
568 		TabPage(		pParent, rResId ),
569         aLibText( 		this, 	IDEResId( RID_STR_LIB ) ),
570 		aBasicBox( 		this, 	IDEResId( RID_TRLBOX ) ),
571 		aEditButton( 	this, 	IDEResId( RID_PB_EDIT ) ),
572 		aCloseButton( 	this, 	IDEResId( RID_PB_CLOSE ) ),
573 		aNewModButton( 	this, 	IDEResId( RID_PB_NEWMOD ) ),
574 		aNewDlgButton( 	this, 	IDEResId( RID_PB_NEWDLG ) ),
575 		aDelButton( 	this, 	IDEResId( RID_PB_DELETE ) )
576 {
577 	FreeResource();
578 	pTabDlg = 0;
579 
580 	aEditButton.SetClickHdl( LINK( this, ObjectPage, ButtonHdl ) );
581 	aDelButton.SetClickHdl( LINK( this, ObjectPage, ButtonHdl ) );
582 	aCloseButton.SetClickHdl( LINK( this, ObjectPage, ButtonHdl ) );
583 	aBasicBox.SetSelectHdl( LINK( this, ObjectPage, BasicBoxHighlightHdl ) );
584 
585     if( nMode & BROWSEMODE_MODULES )
586     {
587         aNewModButton.SetClickHdl( LINK( this, ObjectPage, ButtonHdl ) );
588         aNewDlgButton.Hide();
589     }
590     else if ( nMode & BROWSEMODE_DIALOGS )
591     {
592         aNewDlgButton.SetClickHdl( LINK( this, ObjectPage, ButtonHdl ) );
593         aNewModButton.Hide();
594     }
595 
596 	aBasicBox.SetDragDropMode( SV_DRAGDROP_CTRL_MOVE | SV_DRAGDROP_CTRL_COPY );
597 	aBasicBox.EnableInplaceEditing( sal_True );
598 	aBasicBox.SetMode( nMode );
599     aBasicBox.SetStyle( WB_BORDER | WB_TABSTOP |
600                         WB_HASLINES | WB_HASLINESATROOT |
601                         WB_HASBUTTONS | WB_HASBUTTONSATROOT |
602                         WB_HSCROLL );
603     aBasicBox.ScanAllEntries();
604 
605 	aEditButton.GrabFocus();
606 	CheckButtons();
607 }
608 
609 void ObjectPage::SetCurrentEntry( BasicEntryDescriptor& rDesc )
610 {
611     aBasicBox.SetCurrentEntry( rDesc );
612 }
613 
614 void __EXPORT ObjectPage::ActivatePage()
615 {
616     aBasicBox.UpdateEntries();
617 }
618 
619 void __EXPORT ObjectPage::DeactivatePage()
620 {
621 }
622 
623 void ObjectPage::CheckButtons()
624 {
625     // enable/disable edit button
626 	SvLBoxEntry* pCurEntry = aBasicBox.GetCurEntry();
627     BasicEntryDescriptor aDesc( aBasicBox.GetEntryDescriptor( pCurEntry ) );
628     ScriptDocument aDocument( aDesc.GetDocument() );
629     ::rtl::OUString aOULibName( aDesc.GetLibName() );
630     String aLibSubName( aDesc.GetLibSubName() );
631     sal_Bool bVBAEnabled = aDocument.isInVBAMode();
632     sal_uInt16 nMode = aBasicBox.GetMode();
633 
634 	sal_uInt16 nDepth = pCurEntry ? aBasicBox.GetModel()->GetDepth( pCurEntry ) : 0;
635 	if ( nDepth >= 2 )
636     {
637         if( bVBAEnabled && ( nMode & BROWSEMODE_MODULES ) && ( nDepth == 2 ) )
638             aEditButton.Disable();
639         else
640 		aEditButton.Enable();
641     }
642 	else
643 		aEditButton.Disable();
644 
645     // enable/disable new module/dialog buttons
646     LibraryLocation eLocation( aDesc.GetLocation() );
647     sal_Bool bReadOnly = sal_False;
648     if ( nDepth > 0 )
649     {
650         Reference< script::XLibraryContainer2 > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
651         Reference< script::XLibraryContainer2 > xDlgLibContainer( aDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY );
652         if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryReadOnly( aOULibName ) ) ||
653              ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && xDlgLibContainer->isLibraryReadOnly( aOULibName ) ) )
654         {
655             bReadOnly = sal_True;
656         }
657     }
658     if ( bReadOnly || eLocation == LIBRARY_LOCATION_SHARE )
659     {
660         aNewModButton.Disable();
661         aNewDlgButton.Disable();
662     }
663     else
664     {
665         aNewModButton.Enable();
666         aNewDlgButton.Enable();
667     }
668 
669     // enable/disable delete button
670     if ( nDepth >= 2 && !bReadOnly && eLocation != LIBRARY_LOCATION_SHARE )
671     {
672         if( bVBAEnabled && ( nMode & BROWSEMODE_MODULES ) && ( ( nDepth == 2 ) || aLibSubName.Equals( String( IDEResId( RID_STR_DOCUMENT_OBJECTS ) ) ) ) )
673             aDelButton.Disable();
674         else
675 		aDelButton.Enable();
676     }
677 	else
678 		aDelButton.Disable();
679 }
680 
681 IMPL_LINK( ObjectPage, BasicBoxHighlightHdl, BasicTreeListBox *, pBox )
682 {
683 	if ( !pBox->IsSelected( pBox->GetHdlEntry() ) )
684 		return 0;
685 
686 	CheckButtons();
687 	return 0;
688 }
689 
690 IMPL_LINK( ObjectPage, ButtonHdl, Button *, pButton )
691 {
692 	if ( pButton == &aEditButton )
693 	{
694         SfxAllItemSet aArgs( SFX_APP()->GetPool() );
695         SfxRequest aRequest( SID_BASICIDE_APPEAR, SFX_CALLMODE_SYNCHRON, aArgs );
696         SFX_APP()->ExecuteSlot( aRequest );
697 
698         BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
699         SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
700         SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
701         SvLBoxEntry* pCurEntry = aBasicBox.GetCurEntry();
702 		DBG_ASSERT( pCurEntry, "Entry?!" );
703 		if ( aBasicBox.GetModel()->GetDepth( pCurEntry ) >= 2 )
704 		{
705             BasicEntryDescriptor aDesc( aBasicBox.GetEntryDescriptor( pCurEntry ) );
706 			if ( pDispatcher )
707 			{
708                 String aModName( aDesc.GetName() );
709                 // extract the module name from the string like "Sheet1 (Example1)"
710                 if( aDesc.GetLibSubName().Equals( String( IDEResId( RID_STR_DOCUMENT_OBJECTS ) ) ) )
711                 {
712                     sal_uInt16 nIndex = 0;
713                     aModName = aModName.GetToken( 0, ' ', nIndex );
714                 }
715                 SbxItem aSbxItem( SID_BASICIDE_ARG_SBX, aDesc.GetDocument(), aDesc.GetLibName(),
716                                   aModName, aBasicBox.ConvertType( aDesc.GetType() ) );
717 				pDispatcher->Execute( SID_BASICIDE_SHOWSBX, SFX_CALLMODE_SYNCHRON, &aSbxItem, 0L );
718 			}
719 		}
720 		else	// Nur Lib selektiert
721 		{
722 			DBG_ASSERT( aBasicBox.GetModel()->GetDepth( pCurEntry ) == 1, "Kein LibEntry?!" );
723             ScriptDocument aDocument( ScriptDocument::getApplicationScriptDocument() );
724             SvLBoxEntry* pParentEntry = aBasicBox.GetParent( pCurEntry );
725             if ( pParentEntry )
726             {
727                 BasicDocumentEntry* pBasicDocumentEntry = (BasicDocumentEntry*)pParentEntry->GetUserData();
728                 if ( pBasicDocumentEntry )
729                     aDocument = pBasicDocumentEntry->GetDocument();
730             }
731             SfxUsrAnyItem aDocItem( SID_BASICIDE_ARG_DOCUMENT_MODEL, makeAny( aDocument.getDocumentOrNull() ) );
732 			String aLibName( aBasicBox.GetEntryText( pCurEntry ) );
733             SfxStringItem aLibNameItem( SID_BASICIDE_ARG_LIBNAME, aLibName );
734 			if ( pDispatcher )
735 			{
736 				pDispatcher->Execute( SID_BASICIDE_LIBSELECTED, SFX_CALLMODE_ASYNCHRON, &aDocItem, &aLibNameItem, 0L );
737 			}
738 		}
739 		EndTabDialog( 1 );
740 	}
741 	else if ( pButton == &aNewModButton )
742 		NewModule();
743 	else if ( pButton == &aNewDlgButton )
744 		NewDialog();
745 	else if ( pButton == &aDelButton )
746 		DeleteCurrent();
747 	else if ( pButton == &aCloseButton )
748 		EndTabDialog( 0 );
749 
750 	return 0;
751 }
752 
753 bool ObjectPage::GetSelection( ScriptDocument& rDocument, String& rLibName )
754 {
755     bool bRet = false;
756 
757     SvLBoxEntry* pCurEntry = aBasicBox.GetCurEntry();
758     BasicEntryDescriptor aDesc( aBasicBox.GetEntryDescriptor( pCurEntry ) );
759     rDocument = aDesc.GetDocument();
760     rLibName = aDesc.GetLibName();
761     if ( !rLibName.Len() )
762         rLibName = String::CreateFromAscii( "Standard" );
763 
764     DBG_ASSERT( rDocument.isAlive(), "ObjectPage::GetSelection: no or dead ScriptDocument in the selection!" );
765     if ( !rDocument.isAlive() )
766         return false;
767 
768     // check if the module library is loaded
769     sal_Bool bOK = sal_True;
770     ::rtl::OUString aOULibName( rLibName );
771     Reference< script::XLibraryContainer > xModLibContainer( rDocument.getLibraryContainer( E_SCRIPTS  ) );
772     if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && !xModLibContainer->isLibraryLoaded( aOULibName ) )
773     {
774         // check password
775         Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
776         if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aOULibName ) && !xPasswd->isLibraryPasswordVerified( aOULibName ) )
777         {
778             String aPassword;
779             bOK = QueryPassword( xModLibContainer, rLibName, aPassword );
780         }
781 
782         // load library
783         if ( bOK )
784             xModLibContainer->loadLibrary( aOULibName );
785     }
786 
787     // check if the dialog library is loaded
788     Reference< script::XLibraryContainer > xDlgLibContainer( rDocument.getLibraryContainer( E_DIALOGS ) );
789     if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && !xDlgLibContainer->isLibraryLoaded( aOULibName ) )
790     {
791         // load library
792         if ( bOK )
793             xDlgLibContainer->loadLibrary( aOULibName );
794     }
795 
796     if ( bOK )
797         bRet = true;
798 
799     return bRet;
800 }
801 
802 void ObjectPage::NewModule()
803 {
804     ScriptDocument aDocument( ScriptDocument::getApplicationScriptDocument() );
805     String aLibName;
806 
807     if ( GetSelection( aDocument, aLibName ) )
808     {
809         String aModName;
810         createModImpl( static_cast<Window*>( this ), aDocument,
811                     aBasicBox, aLibName, aModName, true );
812     }
813 }
814 
815 void ObjectPage::NewDialog()
816 {
817     ScriptDocument aDocument( ScriptDocument::getApplicationScriptDocument() );
818     String aLibName;
819 
820     if ( GetSelection( aDocument, aLibName ) )
821     {
822         aDocument.getOrCreateLibrary( E_DIALOGS, aLibName );
823 
824         std::auto_ptr< NewObjectDialog > xNewDlg(
825             new NewObjectDialog(this, NEWOBJECTMODE_DLG, true));
826 		xNewDlg->SetObjectName( aDocument.createObjectName( E_DIALOGS, aLibName ) );
827 
828         if (xNewDlg->Execute() != 0)
829 		{
830 			String aDlgName( xNewDlg->GetObjectName() );
831             if (aDlgName.Len() == 0)
832                 aDlgName = aDocument.createObjectName( E_DIALOGS, aLibName);
833 
834             if ( aDocument.hasDialog( aLibName, aDlgName ) )
835 			{
836 				ErrorBox( this, WB_OK | WB_DEF_OK,
837 						String( IDEResId( RID_STR_SBXNAMEALLREADYUSED2 ) ) ).Execute();
838 			}
839             else
840             {
841 				Reference< io::XInputStreamProvider > xISP;
842                 if ( !aDocument.createDialog( aLibName, aDlgName, xISP ) )
843                     return;
844 
845 				SbxItem aSbxItem( SID_BASICIDE_ARG_SBX, aDocument, aLibName, aDlgName, BASICIDE_TYPE_DIALOG );
846                 BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
847                 SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
848 	            SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
849                 if( pDispatcher )
850 				{
851 					pDispatcher->Execute( SID_BASICIDE_SBXINSERTED,
852 											SFX_CALLMODE_SYNCHRON, &aSbxItem, 0L );
853 				}
854                 LibraryLocation eLocation = aDocument.getLibraryLocation( aLibName );
855                 SvLBoxEntry* pRootEntry = aBasicBox.FindRootEntry( aDocument, eLocation );
856                 if ( pRootEntry )
857                 {
858                     if ( !aBasicBox.IsExpanded( pRootEntry ) )
859                         aBasicBox.Expand( pRootEntry );
860                     SvLBoxEntry* pLibEntry = aBasicBox.FindEntry( pRootEntry, aLibName, OBJ_TYPE_LIBRARY );
861                     DBG_ASSERT( pLibEntry, "Libeintrag nicht gefunden!" );
862                     if ( pLibEntry )
863                     {
864                         if ( !aBasicBox.IsExpanded( pLibEntry ) )
865                             aBasicBox.Expand( pLibEntry );
866                         SvLBoxEntry* pEntry = aBasicBox.FindEntry( pLibEntry, aDlgName, OBJ_TYPE_DIALOG );
867                         if ( !pEntry )
868                         {
869                             pEntry = aBasicBox.AddEntry(
870                                 aDlgName,
871                                 Image( IDEResId( RID_IMG_DIALOG ) ),
872                                 Image( IDEResId( RID_IMG_DIALOG_HC ) ),
873                                 pLibEntry, false,
874                                 std::auto_ptr< BasicEntry >( new BasicEntry( OBJ_TYPE_DIALOG ) ) );
875                             DBG_ASSERT( pEntry, "InsertEntry fehlgeschlagen!" );
876                         }
877                         aBasicBox.SetCurEntry( pEntry );
878                         aBasicBox.Select( aBasicBox.GetCurEntry() );		// OV-Bug?!
879                     }
880                 }
881 			}
882 		}
883 	}
884 }
885 
886 void ObjectPage::DeleteCurrent()
887 {
888 	SvLBoxEntry* pCurEntry = aBasicBox.GetCurEntry();
889 	DBG_ASSERT( pCurEntry, "Kein aktueller Eintrag!" );
890     BasicEntryDescriptor aDesc( aBasicBox.GetEntryDescriptor( pCurEntry ) );
891 	ScriptDocument aDocument( aDesc.GetDocument() );
892     DBG_ASSERT( aDocument.isAlive(), "ObjectPage::DeleteCurrent: no document!" );
893     if ( !aDocument.isAlive() )
894         return;
895 	String aLibName( aDesc.GetLibName() );
896 	String aName( aDesc.GetName() );
897     BasicEntryType eType( aDesc.GetType() );
898 
899 	if ( ( eType == OBJ_TYPE_MODULE && QueryDelModule( aName, this ) ) ||
900 		 ( eType == OBJ_TYPE_DIALOG && QueryDelDialog( aName, this ) ) )
901 	{
902 		aBasicBox.GetModel()->Remove( pCurEntry );
903 		if ( aBasicBox.GetCurEntry() )	// OV-Bug ?
904 			aBasicBox.Select( aBasicBox.GetCurEntry() );
905         BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
906         SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
907 	    SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
908         if( pDispatcher )
909 		{
910             SbxItem aSbxItem( SID_BASICIDE_ARG_SBX, aDocument, aLibName, aName, aBasicBox.ConvertType( eType ) );
911 			pDispatcher->Execute( SID_BASICIDE_SBXDELETED,
912 								  SFX_CALLMODE_SYNCHRON, &aSbxItem, 0L );
913 		}
914 
915 		try
916 		{
917             bool bSuccess = false;
918 			if ( eType == OBJ_TYPE_MODULE )
919 				bSuccess = aDocument.removeModule( aLibName, aName );
920 			else if ( eType == OBJ_TYPE_DIALOG )
921                 bSuccess = BasicIDE::RemoveDialog( aDocument, aLibName, aName );
922 
923             if ( bSuccess )
924 			    BasicIDE::MarkDocumentModified( aDocument );
925 		}
926 		catch ( container::NoSuchElementException& )
927 		{
928 			DBG_UNHANDLED_EXCEPTION();
929 		}
930 	}
931 }
932 
933 
934 
935 void ObjectPage::EndTabDialog( sal_uInt16 nRet )
936 {
937 	DBG_ASSERT( pTabDlg, "TabDlg nicht gesetzt!" );
938 	if ( pTabDlg )
939 		pTabDlg->EndDialog( nRet );
940 }
941 
942 
943 LibDialog::LibDialog( Window* pParent )
944 	: ModalDialog( pParent, IDEResId( RID_DLG_LIBS ) ),
945 		aOKButton( 		this, IDEResId( RID_PB_OK ) ),
946 		aCancelButton( 	this, IDEResId( RID_PB_CANCEL ) ),
947 		aStorageName( 	this, IDEResId( RID_FT_STORAGENAME ) ),
948 		aLibBox( 		this, IDEResId( RID_CTRL_LIBS ) ),
949         aFixedLine(		this, IDEResId( RID_FL_OPTIONS ) ),
950         aReferenceBox( 	this, IDEResId( RID_CB_REF ) ),
951         aReplaceBox( 	this, IDEResId( RID_CB_REPL ) )
952 {
953 	SetText( String( IDEResId( RID_STR_APPENDLIBS ) ) );
954 	FreeResource();
955 }
956 
957 
958 LibDialog::~LibDialog()
959 {
960 }
961 
962 void LibDialog::SetStorageName( const String& rName )
963 {
964 	String aName( IDEResId( RID_STR_FILENAME ) );
965 	aName += rName;
966 	aStorageName.SetText( aName );
967 }
968 
969 // Helper function
970 SbModule* createModImpl( Window* pWin, const ScriptDocument& rDocument,
971 	BasicTreeListBox& rBasicBox, const String& rLibName, String aModName, bool bMain )
972 {
973     OSL_ENSURE( rDocument.isAlive(), "createModImpl: invalid document!" );
974     if ( !rDocument.isAlive() )
975         return NULL;
976 
977 	SbModule* pModule = NULL;
978 
979     String aLibName( rLibName );
980     if ( !aLibName.Len() )
981         aLibName = String::CreateFromAscii( "Standard" );
982     rDocument.getOrCreateLibrary( E_SCRIPTS, aLibName );
983 	if ( !aModName.Len() )
984 		aModName = rDocument.createObjectName( E_SCRIPTS, aLibName );
985 
986     std::auto_ptr< NewObjectDialog > xNewDlg(
987         new NewObjectDialog( pWin, NEWOBJECTMODE_MOD, true ) );
988     xNewDlg->SetObjectName( aModName );
989 
990     if (xNewDlg->Execute() != 0)
991 	{
992 		if ( xNewDlg->GetObjectName().Len() )
993 			aModName = xNewDlg->GetObjectName();
994 
995 		try
996 		{
997             ::rtl::OUString sModuleCode;
998             // the module has existed
999             if( rDocument.hasModule( aLibName, aModName ) )
1000                 return NULL;
1001             rDocument.createModule( aLibName, aModName, bMain, sModuleCode );
1002             BasicManager* pBasMgr = rDocument.getBasicManager();
1003             StarBASIC* pBasic = pBasMgr? pBasMgr->GetLib( aLibName ) : 0;
1004                 if ( pBasic )
1005                     pModule = pBasic->FindModule( aModName );
1006 			SbxItem aSbxItem( SID_BASICIDE_ARG_SBX, rDocument, aLibName, aModName, BASICIDE_TYPE_MODULE );
1007 			BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
1008 			SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
1009 			SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
1010 			if( pDispatcher )
1011 			{
1012 				pDispatcher->Execute( SID_BASICIDE_SBXINSERTED,
1013 									  SFX_CALLMODE_SYNCHRON, &aSbxItem, 0L );
1014 			}
1015             LibraryLocation eLocation = rDocument.getLibraryLocation( aLibName );
1016             SvLBoxEntry* pRootEntry = rBasicBox.FindRootEntry( rDocument, eLocation );
1017             if ( pRootEntry )
1018             {
1019                 if ( !rBasicBox.IsExpanded( pRootEntry ) )
1020                     rBasicBox.Expand( pRootEntry );
1021                 SvLBoxEntry* pLibEntry = rBasicBox.FindEntry( pRootEntry, aLibName, OBJ_TYPE_LIBRARY );
1022                 DBG_ASSERT( pLibEntry, "Libeintrag nicht gefunden!" );
1023                 if ( pLibEntry )
1024                 {
1025                     if ( !rBasicBox.IsExpanded( pLibEntry ) )
1026                         rBasicBox.Expand( pLibEntry );
1027                     SvLBoxEntry* pSubRootEntry = pLibEntry;
1028                     if( pBasic && rDocument.isInVBAMode() )
1029                     {
1030                         // add the new module in the "Modules" entry
1031                         SvLBoxEntry* pLibSubEntry = rBasicBox.FindEntry( pLibEntry, String( IDEResId( RID_STR_NORMAL_MODULES ) ) , OBJ_TYPE_NORMAL_MODULES );
1032                         if( pLibSubEntry )
1033                         {
1034                             if( !rBasicBox.IsExpanded( pLibSubEntry ) )
1035                                 rBasicBox.Expand( pLibSubEntry );
1036                             pSubRootEntry = pLibSubEntry;
1037                         }
1038                     }
1039 
1040                     SvLBoxEntry* pEntry = rBasicBox.FindEntry( pSubRootEntry, aModName, OBJ_TYPE_MODULE );
1041                     if ( !pEntry )
1042                     {
1043                         pEntry = rBasicBox.AddEntry(
1044                             aModName,
1045                             Image( IDEResId( RID_IMG_MODULE ) ),
1046                             Image( IDEResId( RID_IMG_MODULE_HC ) ),
1047                             pSubRootEntry, false,
1048                             std::auto_ptr< BasicEntry >( new BasicEntry( OBJ_TYPE_MODULE ) ) );
1049                         DBG_ASSERT( pEntry, "InsertEntry fehlgeschlagen!" );
1050                     }
1051                     rBasicBox.SetCurEntry( pEntry );
1052                     rBasicBox.Select( rBasicBox.GetCurEntry() );		// OV-Bug?!
1053                 }
1054             }
1055 		}
1056 		catch ( container::ElementExistException& )
1057 		{
1058 			ErrorBox( pWin, WB_OK | WB_DEF_OK,
1059 					String( IDEResId( RID_STR_SBXNAMEALLREADYUSED2 ) ) ).Execute();
1060 		}
1061 		catch ( container::NoSuchElementException& )
1062 		{
1063 			DBG_UNHANDLED_EXCEPTION();
1064 		}
1065 	}
1066 	return pModule;
1067 }
1068 
1069 
1070 
1071 
1072