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