1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: moduldlg.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basctl.hxx"
36 #include <ide_pch.hxx>
39 #include <moduldlg.hrc>
40 #include <moduldlg.hxx>
41 #include <basidesh.hrc>
42 #include <basidesh.hxx>
43 #include <bastypes.hxx>
44 #include <baside3.hxx>
46 #include <baside2.hrc>
47 #include <sbxitem.hxx>
48 #include <iderdll.hxx>
50 #ifndef _COM_SUN_STAR_IO_XINPUTSTREAMPROVIDER_HXX_
51 #include <com/sun/star/io/XInputStreamProvider.hpp>
53 #ifndef _COM_SUN_STAR_SCRIPT_XLIBRYARYCONTAINER2_HPP_
54 #include <com/sun/star/script/XLibraryContainer2.hpp>
56 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
57 #include <com/sun/star/resource/XStringResourceManager.hpp>
58 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
59 #include <comphelper/processfactory.hxx>
60 #include <xmlscript/xmldlg_imexp.hxx>
62 #include "localizationmgr.hxx"
63 #include <basic/sbx.hxx>
64 #include <tools/diagnose_ex.h>
66 using namespace ::com::sun::star
;
67 using namespace ::com::sun::star::uno
;
68 using namespace ::com::sun::star::lang
;
69 using namespace ::com::sun::star::resource
;
72 ExtBasicTreeListBox::ExtBasicTreeListBox( Window
* pParent
, const ResId
& rRes
)
73 : BasicTreeListBox( pParent
, rRes
)
79 ExtBasicTreeListBox::~ExtBasicTreeListBox()
83 BOOL __EXPORT
ExtBasicTreeListBox::EditingEntry( SvLBoxEntry
* pEntry
, Selection
& )
89 USHORT nDepth
= GetModel()->GetDepth( pEntry
);
92 BasicEntryDescriptor
aDesc( GetEntryDescriptor( pEntry
) );
93 ScriptDocument
aDocument( aDesc
.GetDocument() );
94 ::rtl::OUString
aOULibName( aDesc
.GetLibName() );
95 Reference
< script::XLibraryContainer2
> xModLibContainer( aDocument
.getLibraryContainer( E_SCRIPTS
), UNO_QUERY
);
96 Reference
< script::XLibraryContainer2
> xDlgLibContainer( aDocument
.getLibraryContainer( E_DIALOGS
), UNO_QUERY
);
97 if ( !( ( xModLibContainer
.is() && xModLibContainer
->hasByName( aOULibName
) && xModLibContainer
->isLibraryReadOnly( aOULibName
) ) ||
98 ( xDlgLibContainer
.is() && xDlgLibContainer
->hasByName( aOULibName
) && xDlgLibContainer
->isLibraryReadOnly( aOULibName
) ) ) )
100 // allow editing only for libraries, which are not readonly
109 BOOL __EXPORT
ExtBasicTreeListBox::EditedEntry( SvLBoxEntry
* pEntry
, const String
& rNewText
)
111 BOOL bValid
= BasicIDE::IsValidSbxName( rNewText
);
114 ErrorBox( this, WB_OK
| WB_DEF_OK
, String( IDEResId( RID_STR_BADSBXNAME
) ) ).Execute();
118 String
aCurText( GetEntryText( pEntry
) );
119 if ( aCurText
== rNewText
)
123 BasicEntryDescriptor
aDesc( GetEntryDescriptor( pEntry
) );
124 ScriptDocument
aDocument( aDesc
.GetDocument() );
125 DBG_ASSERT( aDocument
.isValid(), "ExtBasicTreeListBox::EditedEntry: no document!" );
126 if ( !aDocument
.isValid() )
128 String
aLibName( aDesc
.GetLibName() );
129 BasicEntryType
eType( aDesc
.GetType() );
131 bool bSuccess
= ( eType
== OBJ_TYPE_MODULE
)
132 ? BasicIDE::RenameModule( this, aDocument
, aLibName
, aCurText
, rNewText
)
133 : BasicIDE::RenameDialog( this, aDocument
, aLibName
, aCurText
, rNewText
);
138 BasicIDE::MarkDocumentModified( aDocument
);
140 BasicIDEShell
* pIDEShell
= IDE_DLL()->GetShell();
141 SfxViewFrame
* pViewFrame
= pIDEShell
? pIDEShell
->GetViewFrame() : NULL
;
142 SfxDispatcher
* pDispatcher
= pViewFrame
? pViewFrame
->GetDispatcher() : NULL
;
145 SbxItem
aSbxItem( SID_BASICIDE_ARG_SBX
, aDocument
, aLibName
, rNewText
, ConvertType( eType
) );
146 pDispatcher
->Execute( SID_BASICIDE_SBXRENAMED
,
147 SFX_CALLMODE_SYNCHRON
, &aSbxItem
, 0L );
151 SetEntryText( pEntry
, rNewText
);
152 SetCurEntry( pEntry
);
153 SetCurEntry( pEntry
);
154 Select( pEntry
, FALSE
);
155 Select( pEntry
); // damit Handler gerufen wird => Edit updaten
161 DragDropMode __EXPORT
ExtBasicTreeListBox::NotifyStartDrag( TransferDataContainer
&, SvLBoxEntry
* pEntry
)
163 DragDropMode nMode_
= SV_DRAGDROP_NONE
;
167 USHORT nDepth
= GetModel()->GetDepth( pEntry
);
170 nMode_
= SV_DRAGDROP_CTRL_COPY
;
171 BasicEntryDescriptor
aDesc( GetEntryDescriptor( pEntry
) );
172 ScriptDocument
aDocument( aDesc
.GetDocument() );
173 ::rtl::OUString
aOULibName( aDesc
.GetLibName() );
174 // allow MOVE mode only for libraries, which are not readonly
175 Reference
< script::XLibraryContainer2
> xModLibContainer( aDocument
.getLibraryContainer( E_SCRIPTS
), UNO_QUERY
);
176 Reference
< script::XLibraryContainer2
> xDlgLibContainer( aDocument
.getLibraryContainer( E_DIALOGS
), UNO_QUERY
);
177 if ( !( ( xModLibContainer
.is() && xModLibContainer
->hasByName( aOULibName
) && xModLibContainer
->isLibraryReadOnly( aOULibName
) ) ||
178 ( xDlgLibContainer
.is() && xDlgLibContainer
->hasByName( aOULibName
) && xDlgLibContainer
->isLibraryReadOnly( aOULibName
) ) ) )
180 // Only allow copy for localized libraries
181 bool bAllowMove
= true;
182 if ( xDlgLibContainer
.is() && xDlgLibContainer
->hasByName( aOULibName
) )
184 // Get StringResourceManager
185 Reference
< container::XNameContainer
> xDialogLib( aDocument
.getLibrary( E_DIALOGS
, aOULibName
, TRUE
) );
186 Reference
< XStringResourceManager
> xSourceMgr
=
187 LocalizationMgr::getStringResourceFromDialogLibrary( xDialogLib
);
188 if( xSourceMgr
.is() )
189 bAllowMove
= ( xSourceMgr
->getLocales().getLength() == 0 );
192 nMode_
|= SV_DRAGDROP_CTRL_MOVE
;
201 BOOL __EXPORT
ExtBasicTreeListBox::NotifyAcceptDrop( SvLBoxEntry
* pEntry
)
203 // don't drop on a BasicManager (nDepth == 0)
204 USHORT nDepth
= pEntry
? GetModel()->GetDepth( pEntry
) : 0;
205 BOOL bValid
= nDepth
? TRUE
: FALSE
;
207 // don't drop in the same library
208 SvLBoxEntry
* pSelected
= FirstSelected();
209 if ( ( nDepth
== 1 ) && ( pEntry
== GetParent( pSelected
) ) )
211 else if ( ( nDepth
== 2 ) && ( GetParent( pEntry
) == GetParent( pSelected
) ) )
214 // don't drop on a library, which is not loaded, readonly or password protected
215 // or which already has a module/dialog with this name
216 if ( bValid
&& ( nDepth
> 0 ) )
218 // get source module/dialog name
219 BasicEntryDescriptor
aSourceDesc( GetEntryDescriptor( pSelected
) );
220 String
aSourceName( aSourceDesc
.GetName() );
221 BasicEntryType
eSourceType( aSourceDesc
.GetType() );
223 // get target shell and target library name
224 BasicEntryDescriptor
aDestDesc( GetEntryDescriptor( pEntry
) );
225 const ScriptDocument
& rDestDoc( aDestDesc
.GetDocument() );
226 String
aDestLibName( aDestDesc
.GetLibName() );
227 ::rtl::OUString
aOUDestLibName( aDestLibName
);
229 // check if module library is not loaded, readonly or password protected
230 Reference
< script::XLibraryContainer2
> xModLibContainer( rDestDoc
.getLibraryContainer( E_SCRIPTS
), UNO_QUERY
);
231 if ( xModLibContainer
.is() && xModLibContainer
->hasByName( aOUDestLibName
) )
233 if ( !xModLibContainer
->isLibraryLoaded( aOUDestLibName
) )
236 if ( xModLibContainer
->isLibraryReadOnly( aOUDestLibName
) )
239 Reference
< script::XLibraryContainerPassword
> xPasswd( xModLibContainer
, UNO_QUERY
);
240 if ( xPasswd
.is() && xPasswd
->isLibraryPasswordProtected( aOUDestLibName
) && !xPasswd
->isLibraryPasswordVerified( aOUDestLibName
) )
244 // check if dialog library is not loaded or readonly
245 Reference
< script::XLibraryContainer2
> xDlgLibContainer( rDestDoc
.getLibraryContainer( E_DIALOGS
), UNO_QUERY
);
246 if ( xDlgLibContainer
.is() && xDlgLibContainer
->hasByName( aOUDestLibName
) )
248 if ( !xDlgLibContainer
->isLibraryLoaded( aOUDestLibName
) )
251 if ( xDlgLibContainer
->isLibraryReadOnly( aOUDestLibName
) )
255 // check, if module/dialog with this name is already existing in target library
256 if ( ( eSourceType
== OBJ_TYPE_MODULE
&& rDestDoc
.hasModule( aDestLibName
, aSourceName
) ) ||
257 ( eSourceType
== OBJ_TYPE_DIALOG
&& rDestDoc
.hasDialog( aDestLibName
, aSourceName
) ) )
267 BOOL __EXPORT
ExtBasicTreeListBox::NotifyMoving( SvLBoxEntry
* pTarget
, SvLBoxEntry
* pEntry
,
268 SvLBoxEntry
*& rpNewParent
, ULONG
& rNewChildPos
)
270 return NotifyCopyingMoving( pTarget
, pEntry
,
271 rpNewParent
, rNewChildPos
, TRUE
);
275 BOOL __EXPORT
ExtBasicTreeListBox::NotifyCopying( SvLBoxEntry
* pTarget
, SvLBoxEntry
* pEntry
,
276 SvLBoxEntry
*& rpNewParent
, ULONG
& rNewChildPos
)
278 // return FALSE; // Wie kopiere ich ein SBX ?!
279 return NotifyCopyingMoving( pTarget
, pEntry
,
280 rpNewParent
, rNewChildPos
, FALSE
);
284 void BasicIDEShell::CopyDialogResources( Reference
< io::XInputStreamProvider
>& io_xISP
,
285 const ScriptDocument
& rSourceDoc
, const String
& rSourceLibName
, const ScriptDocument
& rDestDoc
,
286 const String
& rDestLibName
, const String
& rDlgName
)
291 // Get StringResourceManager
292 Reference
< container::XNameContainer
> xSourceDialogLib( rSourceDoc
.getLibrary( E_DIALOGS
, rSourceLibName
, TRUE
) );
293 Reference
< XStringResourceManager
> xSourceMgr
=
294 LocalizationMgr::getStringResourceFromDialogLibrary( xSourceDialogLib
);
295 if( !xSourceMgr
.is() )
297 bool bSourceLocalized
= ( xSourceMgr
->getLocales().getLength() > 0 );
299 Reference
< container::XNameContainer
> xDestDialogLib( rDestDoc
.getLibrary( E_DIALOGS
, rDestLibName
, TRUE
) );
300 Reference
< XStringResourceManager
> xDestMgr
=
301 LocalizationMgr::getStringResourceFromDialogLibrary( xDestDialogLib
);
304 bool bDestLocalized
= ( xDestMgr
->getLocales().getLength() > 0 );
306 if( !bSourceLocalized
&& !bDestLocalized
)
309 // create dialog model
310 Reference
< lang::XMultiServiceFactory
> xMSF
= ::comphelper::getProcessServiceFactory();
311 Reference
< container::XNameContainer
> xDialogModel
= Reference
< container::XNameContainer
>( xMSF
->createInstance
312 ( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialogModel" ) ) ), UNO_QUERY
);
313 Reference
< io::XInputStream
> xInput( io_xISP
->createInputStream() );
314 Reference
< XComponentContext
> xContext
;
315 Reference
< beans::XPropertySet
> xProps( xMSF
, UNO_QUERY
);
316 OSL_ASSERT( xProps
.is() );
317 OSL_VERIFY( xProps
->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext
);
318 ::xmlscript::importDialogModel( xInput
, xDialogModel
, xContext
, rSourceDoc
.getDocument() );
320 if( xDialogModel
.is() )
322 if( bSourceLocalized
&& bDestLocalized
)
324 Reference
< resource::XStringResourceResolver
> xSourceStringResolver( xSourceMgr
, UNO_QUERY
);
325 LocalizationMgr::copyResourceForDroppedDialog( xDialogModel
, rDlgName
, xDestMgr
, xSourceStringResolver
);
327 else if( bSourceLocalized
)
329 LocalizationMgr::resetResourceForDialog( xDialogModel
, xSourceMgr
);
331 else if( bDestLocalized
)
333 LocalizationMgr::setResourceIDsForDialog( xDialogModel
, xDestMgr
);
335 io_xISP
= ::xmlscript::exportDialogModel( xDialogModel
, xContext
, rDestDoc
.getDocument() );
340 BOOL __EXPORT
ExtBasicTreeListBox::NotifyCopyingMoving( SvLBoxEntry
* pTarget
, SvLBoxEntry
* pEntry
,
341 SvLBoxEntry
*& rpNewParent
, ULONG
& rNewChildPos
, BOOL bMove
)
344 DBG_ASSERT( pEntry
, "Kein Eintrag?" ); // Hier ASS ok, sollte nicht mit
345 DBG_ASSERT( pTarget
, "Kein Ziel?" ); // NULL (ganz vorne) erreicht werden
346 USHORT nDepth
= GetModel()->GetDepth( pTarget
);
347 DBG_ASSERT( nDepth
, "Tiefe?" );
350 // Target = Basic => Modul/Dialog unter das Basic haengen...
351 rpNewParent
= pTarget
;
354 else if ( nDepth
>= 2 )
356 // Target = Modul/Dialog => Modul/Dialog unter das uebergeordnete Basic haengen...
357 rpNewParent
= GetParent( pTarget
);
358 rNewChildPos
= GetModel()->GetRelPos( pTarget
) + 1;
361 // get target shell and target library name
362 BasicEntryDescriptor
aDestDesc( GetEntryDescriptor( rpNewParent
) );
363 const ScriptDocument
& rDestDoc( aDestDesc
.GetDocument() );
364 String
aDestLibName( aDestDesc
.GetLibName() );
366 // get source shell, library name and module/dialog name
367 BasicEntryDescriptor
aSourceDesc( GetEntryDescriptor( FirstSelected() ) );
368 const ScriptDocument
rSourceDoc( aSourceDesc
.GetDocument() );
369 String
aSourceLibName( aSourceDesc
.GetLibName() );
370 String
aSourceName( aSourceDesc
.GetName() );
371 BasicEntryType
eType( aSourceDesc
.GetType() );
374 BasicIDEShell
* pIDEShell
= IDE_DLL()->GetShell();
375 SfxViewFrame
* pViewFrame
= pIDEShell
? pIDEShell
->GetViewFrame() : NULL
;
376 SfxDispatcher
* pDispatcher
= pViewFrame
? pViewFrame
->GetDispatcher() : NULL
;
380 // remove source module/dialog window
381 if ( rSourceDoc
!= rDestDoc
|| aSourceLibName
!= aDestLibName
)
385 SbxItem
aSbxItem( SID_BASICIDE_ARG_SBX
, rSourceDoc
, aSourceLibName
, aSourceName
, ConvertType( eType
) );
386 pDispatcher
->Execute( SID_BASICIDE_SBXDELETED
,
387 SFX_CALLMODE_SYNCHRON
, &aSbxItem
, 0L );
393 if ( eType
== OBJ_TYPE_MODULE
) // module
396 ::rtl::OUString aModule
;
397 if ( rSourceDoc
.getModule( aSourceLibName
, aSourceName
, aModule
) )
399 // remove module from source library
400 if ( rSourceDoc
.removeModule( aSourceLibName
, aSourceName
) )
402 BasicIDE::MarkDocumentModified( rSourceDoc
);
404 // insert module into target library
405 if ( rDestDoc
.insertModule( aDestLibName
, aSourceName
, aModule
) )
406 BasicIDE::MarkDocumentModified( rDestDoc
);
410 else if ( eType
== OBJ_TYPE_DIALOG
) // dialog
413 Reference
< io::XInputStreamProvider
> xISP
;
414 if ( rSourceDoc
.getDialog( aSourceLibName
, aSourceName
, xISP
) )
416 BasicIDEShell::CopyDialogResources( xISP
, rSourceDoc
,
417 aSourceLibName
, rDestDoc
, aDestLibName
, aSourceName
);
419 // remove dialog from source library
420 if ( BasicIDE::RemoveDialog( rSourceDoc
, aSourceLibName
, aSourceName
) )
422 BasicIDE::MarkDocumentModified( rSourceDoc
);
424 // insert dialog into target library
425 if ( rDestDoc
.insertDialog( aDestLibName
, aSourceName
, xISP
) )
426 BasicIDE::MarkDocumentModified( rDestDoc
);
431 catch ( uno::Exception
& )
433 DBG_UNHANDLED_EXCEPTION();
440 if ( eType
== OBJ_TYPE_MODULE
) // module
443 ::rtl::OUString aModule
;
444 if ( rSourceDoc
.getModule( aSourceLibName
, aSourceName
, aModule
) )
446 // insert module into target library
447 if ( rDestDoc
.insertModule( aDestLibName
, aSourceName
, aModule
) )
448 BasicIDE::MarkDocumentModified( rDestDoc
);
451 else if ( eType
== OBJ_TYPE_DIALOG
) // dialog
454 Reference
< io::XInputStreamProvider
> xISP
;
455 if ( rSourceDoc
.getDialog( aSourceLibName
, aSourceName
, xISP
) )
457 BasicIDEShell::CopyDialogResources( xISP
, rSourceDoc
,
458 aSourceLibName
, rDestDoc
, aDestLibName
, aSourceName
);
460 // insert dialog into target library
461 if ( rDestDoc
.insertDialog( aDestLibName
, aSourceName
, xISP
) )
462 BasicIDE::MarkDocumentModified( rDestDoc
);
466 catch ( const Exception
& )
468 DBG_UNHANDLED_EXCEPTION();
472 // create target module/dialog window
473 if ( rSourceDoc
!= rDestDoc
|| aSourceLibName
!= aDestLibName
)
477 SbxItem
aSbxItem( SID_BASICIDE_ARG_SBX
, rDestDoc
, aDestLibName
, aSourceName
, ConvertType( eType
) );
478 pDispatcher
->Execute( SID_BASICIDE_SBXINSERTED
,
479 SFX_CALLMODE_SYNCHRON
, &aSbxItem
, 0L );
483 return 2; // Aufklappen...
486 OrganizeDialog::OrganizeDialog( Window
* pParent
, INT16 tabId
, BasicEntryDescriptor
& rDesc
)
487 :TabDialog( pParent
, IDEResId( RID_TD_ORGANIZE
) )
488 ,aTabCtrl( this, IDEResId( RID_TC_ORGANIZE
) )
489 ,m_aCurEntry( rDesc
)
492 aTabCtrl
.SetActivatePageHdl( LINK( this, OrganizeDialog
, ActivatePageHdl
) );
495 aTabCtrl
.SetCurPageId( RID_TP_MOD
);
497 else if ( tabId
== 1 )
499 aTabCtrl
.SetCurPageId( RID_TP_DLG
);
503 aTabCtrl
.SetCurPageId( RID_TP_LIB
);
506 ActivatePageHdl( &aTabCtrl
);
508 BasicIDEShell
* pIDEShell
= IDE_DLL()->GetShell();
509 SfxViewFrame
* pViewFrame
= pIDEShell
? pIDEShell
->GetViewFrame() : NULL
;
510 SfxDispatcher
* pDispatcher
= pViewFrame
? pViewFrame
->GetDispatcher() : NULL
;
513 pDispatcher
->Execute( SID_BASICIDE_STOREALLMODULESOURCES
);
517 __EXPORT
OrganizeDialog::~OrganizeDialog()
519 for ( USHORT i
= 0; i
< aTabCtrl
.GetPageCount(); i
++ )
520 delete aTabCtrl
.GetTabPage( aTabCtrl
.GetPageId( i
) );
523 short OrganizeDialog::Execute()
525 Window
* pPrevDlgParent
= Application::GetDefDialogParent();
526 Application::SetDefDialogParent( this );
527 short nRet
= TabDialog::Execute();
528 Application::SetDefDialogParent( pPrevDlgParent
);
533 IMPL_LINK( OrganizeDialog
, ActivatePageHdl
, TabControl
*, pTabCtrl
)
535 USHORT nId
= pTabCtrl
->GetCurPageId();
536 // Wenn TabPage noch nicht erzeugt wurde, dann erzeugen
537 if ( !pTabCtrl
->GetTabPage( nId
) )
539 TabPage
* pNewTabPage
= 0;
544 pNewTabPage
= new ObjectPage( pTabCtrl
, IDEResId( RID_TP_MODULS
), BROWSEMODE_MODULES
);
545 ((ObjectPage
*)pNewTabPage
)->SetTabDlg( this );
546 ((ObjectPage
*)pNewTabPage
)->SetCurrentEntry( m_aCurEntry
);
551 pNewTabPage
= new ObjectPage( pTabCtrl
, IDEResId( RID_TP_DLGS
), BROWSEMODE_DIALOGS
);
552 ((ObjectPage
*)pNewTabPage
)->SetTabDlg( this );
553 ((ObjectPage
*)pNewTabPage
)->SetCurrentEntry( m_aCurEntry
);
558 pNewTabPage
= new LibPage( pTabCtrl
);
559 ((LibPage
*)pNewTabPage
)->SetTabDlg( this );
562 default: DBG_ERROR( "PageHdl: Unbekannte ID!" );
564 DBG_ASSERT( pNewTabPage
, "Keine Page!" );
565 pTabCtrl
->SetTabPage( nId
, pNewTabPage
);
570 ObjectPage::ObjectPage( Window
* pParent
, const ResId
& rResId
, USHORT nMode
) :
571 TabPage( pParent
, rResId
),
572 aLibText( this, IDEResId( RID_STR_LIB
) ),
573 aBasicBox( this, IDEResId( RID_TRLBOX
) ),
574 aEditButton( this, IDEResId( RID_PB_EDIT
) ),
575 aCloseButton( this, IDEResId( RID_PB_CLOSE
) ),
576 aNewModButton( this, IDEResId( RID_PB_NEWMOD
) ),
577 aNewDlgButton( this, IDEResId( RID_PB_NEWDLG
) ),
578 aDelButton( this, IDEResId( RID_PB_DELETE
) )
583 aEditButton
.SetClickHdl( LINK( this, ObjectPage
, ButtonHdl
) );
584 aDelButton
.SetClickHdl( LINK( this, ObjectPage
, ButtonHdl
) );
585 aCloseButton
.SetClickHdl( LINK( this, ObjectPage
, ButtonHdl
) );
586 aBasicBox
.SetSelectHdl( LINK( this, ObjectPage
, BasicBoxHighlightHdl
) );
588 if( nMode
& BROWSEMODE_MODULES
)
590 aNewModButton
.SetClickHdl( LINK( this, ObjectPage
, ButtonHdl
) );
591 aNewDlgButton
.Hide();
593 else if ( nMode
& BROWSEMODE_DIALOGS
)
595 aNewDlgButton
.SetClickHdl( LINK( this, ObjectPage
, ButtonHdl
) );
596 aNewModButton
.Hide();
599 aBasicBox
.SetDragDropMode( SV_DRAGDROP_CTRL_MOVE
| SV_DRAGDROP_CTRL_COPY
);
600 aBasicBox
.EnableInplaceEditing( TRUE
);
601 aBasicBox
.SetMode( nMode
);
602 aBasicBox
.SetWindowBits( WB_HASLINES
| WB_HASLINESATROOT
|
603 WB_HASBUTTONS
| WB_HASBUTTONSATROOT
|
605 aBasicBox
.ScanAllEntries();
607 aEditButton
.GrabFocus();
611 void ObjectPage::SetCurrentEntry( BasicEntryDescriptor
& rDesc
)
613 aBasicBox
.SetCurrentEntry( rDesc
);
616 void __EXPORT
ObjectPage::ActivatePage()
618 aBasicBox
.UpdateEntries();
621 void __EXPORT
ObjectPage::DeactivatePage()
625 void ObjectPage::CheckButtons()
627 // enable/disable edit button
628 SvLBoxEntry
* pCurEntry
= aBasicBox
.GetCurEntry();
629 BasicEntryDescriptor
aDesc( aBasicBox
.GetEntryDescriptor( pCurEntry
) );
630 ScriptDocument
aDocument( aDesc
.GetDocument() );
631 ::rtl::OUString
aOULibName( aDesc
.GetLibName() );
632 String
aLibSubName( aDesc
.GetLibSubName() );
633 BasicManager
* pBasMgr
= aDocument
.getBasicManager();
634 StarBASIC
* pBasic
= pBasMgr
? pBasMgr
->GetLib( aOULibName
) : 0;
635 sal_Bool bVBAEnabled
= pBasic
? pBasic
->isVBAEnabled(): sal_False
;
636 USHORT nMode
= aBasicBox
.GetMode();
638 USHORT nDepth
= pCurEntry
? aBasicBox
.GetModel()->GetDepth( pCurEntry
) : 0;
641 if( bVBAEnabled
&& ( nMode
& BROWSEMODE_MODULES
) && ( nDepth
== 2 ) )
642 aEditButton
.Disable();
644 aEditButton
.Enable();
647 aEditButton
.Disable();
649 // enable/disable new module/dialog buttons
650 LibraryLocation
eLocation( aDesc
.GetLocation() );
651 BOOL bReadOnly
= FALSE
;
654 Reference
< script::XLibraryContainer2
> xModLibContainer( aDocument
.getLibraryContainer( E_SCRIPTS
), UNO_QUERY
);
655 Reference
< script::XLibraryContainer2
> xDlgLibContainer( aDocument
.getLibraryContainer( E_DIALOGS
), UNO_QUERY
);
656 if ( ( xModLibContainer
.is() && xModLibContainer
->hasByName( aOULibName
) && xModLibContainer
->isLibraryReadOnly( aOULibName
) ) ||
657 ( xDlgLibContainer
.is() && xDlgLibContainer
->hasByName( aOULibName
) && xDlgLibContainer
->isLibraryReadOnly( aOULibName
) ) )
662 if ( bReadOnly
|| eLocation
== LIBRARY_LOCATION_SHARE
)
664 aNewModButton
.Disable();
665 aNewDlgButton
.Disable();
669 aNewModButton
.Enable();
670 aNewDlgButton
.Enable();
673 // enable/disable delete button
674 if ( nDepth
>= 2 && !bReadOnly
&& eLocation
!= LIBRARY_LOCATION_SHARE
)
676 if( bVBAEnabled
&& ( nMode
& BROWSEMODE_MODULES
) && ( ( nDepth
== 2 ) || aLibSubName
.Equals( String( IDEResId( RID_STR_DOCUMENT_OBJECTS
) ) ) ) )
677 aDelButton
.Disable();
682 aDelButton
.Disable();
685 IMPL_LINK( ObjectPage
, BasicBoxHighlightHdl
, BasicTreeListBox
*, pBox
)
687 if ( !pBox
->IsSelected( pBox
->GetHdlEntry() ) )
694 IMPL_LINK( ObjectPage
, ButtonHdl
, Button
*, pButton
)
696 if ( pButton
== &aEditButton
)
698 SfxAllItemSet
aArgs( SFX_APP()->GetPool() );
699 SfxRequest
aRequest( SID_BASICIDE_APPEAR
, SFX_CALLMODE_SYNCHRON
, aArgs
);
700 SFX_APP()->ExecuteSlot( aRequest
);
702 BasicIDEShell
* pIDEShell
= IDE_DLL()->GetShell();
703 SfxViewFrame
* pViewFrame
= pIDEShell
? pIDEShell
->GetViewFrame() : NULL
;
704 SfxDispatcher
* pDispatcher
= pViewFrame
? pViewFrame
->GetDispatcher() : NULL
;
705 SvLBoxEntry
* pCurEntry
= aBasicBox
.GetCurEntry();
706 DBG_ASSERT( pCurEntry
, "Entry?!" );
707 if ( aBasicBox
.GetModel()->GetDepth( pCurEntry
) >= 2 )
709 BasicEntryDescriptor
aDesc( aBasicBox
.GetEntryDescriptor( pCurEntry
) );
712 String
aModName( aDesc
.GetName() );
713 // extract the module name from the string like "Sheet1 (Example1)"
714 if( aDesc
.GetLibSubName().Equals( String( IDEResId( RID_STR_DOCUMENT_OBJECTS
) ) ) )
716 sal_uInt16 nIndex
= 0;
717 aModName
= aModName
.GetToken( 0, ' ', nIndex
);
719 SbxItem
aSbxItem( SID_BASICIDE_ARG_SBX
, aDesc
.GetDocument(), aDesc
.GetLibName(),
720 aModName
, aBasicBox
.ConvertType( aDesc
.GetType() ) );
721 pDispatcher
->Execute( SID_BASICIDE_SHOWSBX
, SFX_CALLMODE_SYNCHRON
, &aSbxItem
, 0L );
724 else // Nur Lib selektiert
726 DBG_ASSERT( aBasicBox
.GetModel()->GetDepth( pCurEntry
) == 1, "Kein LibEntry?!" );
727 ScriptDocument
aDocument( ScriptDocument::getApplicationScriptDocument() );
728 SvLBoxEntry
* pParentEntry
= aBasicBox
.GetParent( pCurEntry
);
731 BasicDocumentEntry
* pBasicDocumentEntry
= (BasicDocumentEntry
*)pParentEntry
->GetUserData();
732 if ( pBasicDocumentEntry
)
733 aDocument
= pBasicDocumentEntry
->GetDocument();
735 SfxUsrAnyItem
aDocItem( SID_BASICIDE_ARG_DOCUMENT_MODEL
, makeAny( aDocument
.getDocumentOrNull() ) );
736 String
aLibName( aBasicBox
.GetEntryText( pCurEntry
) );
737 SfxStringItem
aLibNameItem( SID_BASICIDE_ARG_LIBNAME
, aLibName
);
740 pDispatcher
->Execute( SID_BASICIDE_LIBSELECTED
, SFX_CALLMODE_ASYNCHRON
, &aDocItem
, &aLibNameItem
, 0L );
745 else if ( pButton
== &aNewModButton
)
747 else if ( pButton
== &aNewDlgButton
)
749 else if ( pButton
== &aDelButton
)
751 else if ( pButton
== &aCloseButton
)
757 bool ObjectPage::GetSelection( ScriptDocument
& rDocument
, String
& rLibName
)
761 SvLBoxEntry
* pCurEntry
= aBasicBox
.GetCurEntry();
762 BasicEntryDescriptor
aDesc( aBasicBox
.GetEntryDescriptor( pCurEntry
) );
763 rDocument
= aDesc
.GetDocument();
764 rLibName
= aDesc
.GetLibName();
765 if ( !rLibName
.Len() )
766 rLibName
= String::CreateFromAscii( "Standard" );
768 DBG_ASSERT( rDocument
.isAlive(), "ObjectPage::GetSelection: no or dead ScriptDocument in the selection!" );
769 if ( !rDocument
.isAlive() )
772 // check if the module library is loaded
774 ::rtl::OUString
aOULibName( rLibName
);
775 Reference
< script::XLibraryContainer
> xModLibContainer( rDocument
.getLibraryContainer( E_SCRIPTS
) );
776 if ( xModLibContainer
.is() && xModLibContainer
->hasByName( aOULibName
) && !xModLibContainer
->isLibraryLoaded( aOULibName
) )
779 Reference
< script::XLibraryContainerPassword
> xPasswd( xModLibContainer
, UNO_QUERY
);
780 if ( xPasswd
.is() && xPasswd
->isLibraryPasswordProtected( aOULibName
) && !xPasswd
->isLibraryPasswordVerified( aOULibName
) )
783 bOK
= QueryPassword( xModLibContainer
, rLibName
, aPassword
);
788 xModLibContainer
->loadLibrary( aOULibName
);
791 // check if the dialog library is loaded
792 Reference
< script::XLibraryContainer
> xDlgLibContainer( rDocument
.getLibraryContainer( E_DIALOGS
) );
793 if ( xDlgLibContainer
.is() && xDlgLibContainer
->hasByName( aOULibName
) && !xDlgLibContainer
->isLibraryLoaded( aOULibName
) )
797 xDlgLibContainer
->loadLibrary( aOULibName
);
806 void ObjectPage::NewModule()
808 ScriptDocument
aDocument( ScriptDocument::getApplicationScriptDocument() );
811 if ( GetSelection( aDocument
, aLibName
) )
814 createModImpl( static_cast<Window
*>( this ), aDocument
,
815 aBasicBox
, aLibName
, aModName
, true );
819 void ObjectPage::NewDialog()
821 ScriptDocument
aDocument( ScriptDocument::getApplicationScriptDocument() );
824 if ( GetSelection( aDocument
, aLibName
) )
826 aDocument
.getOrCreateLibrary( E_DIALOGS
, aLibName
);
828 std::auto_ptr
< NewObjectDialog
> xNewDlg(
829 new NewObjectDialog(this, NEWOBJECTMODE_DLG
, true));
830 xNewDlg
->SetObjectName( aDocument
.createObjectName( E_DIALOGS
, aLibName
) );
832 if (xNewDlg
->Execute() != 0)
834 String
aDlgName( xNewDlg
->GetObjectName() );
835 if (aDlgName
.Len() == 0)
836 aDlgName
= aDocument
.createObjectName( E_DIALOGS
, aLibName
);
838 if ( aDocument
.hasDialog( aLibName
, aDlgName
) )
840 ErrorBox( this, WB_OK
| WB_DEF_OK
,
841 String( IDEResId( RID_STR_SBXNAMEALLREADYUSED2
) ) ).Execute();
845 Reference
< io::XInputStreamProvider
> xISP
;
846 if ( !aDocument
.createDialog( aLibName
, aDlgName
, xISP
) )
849 SbxItem
aSbxItem( SID_BASICIDE_ARG_SBX
, aDocument
, aLibName
, aDlgName
, BASICIDE_TYPE_DIALOG
);
850 BasicIDEShell
* pIDEShell
= IDE_DLL()->GetShell();
851 SfxViewFrame
* pViewFrame
= pIDEShell
? pIDEShell
->GetViewFrame() : NULL
;
852 SfxDispatcher
* pDispatcher
= pViewFrame
? pViewFrame
->GetDispatcher() : NULL
;
855 pDispatcher
->Execute( SID_BASICIDE_SBXINSERTED
,
856 SFX_CALLMODE_SYNCHRON
, &aSbxItem
, 0L );
858 LibraryLocation eLocation
= aDocument
.getLibraryLocation( aLibName
);
859 SvLBoxEntry
* pRootEntry
= aBasicBox
.FindRootEntry( aDocument
, eLocation
);
862 if ( !aBasicBox
.IsExpanded( pRootEntry
) )
863 aBasicBox
.Expand( pRootEntry
);
864 SvLBoxEntry
* pLibEntry
= aBasicBox
.FindEntry( pRootEntry
, aLibName
, OBJ_TYPE_LIBRARY
);
865 DBG_ASSERT( pLibEntry
, "Libeintrag nicht gefunden!" );
868 if ( !aBasicBox
.IsExpanded( pLibEntry
) )
869 aBasicBox
.Expand( pLibEntry
);
870 SvLBoxEntry
* pEntry
= aBasicBox
.FindEntry( pLibEntry
, aDlgName
, OBJ_TYPE_DIALOG
);
873 pEntry
= aBasicBox
.AddEntry(
875 Image( IDEResId( RID_IMG_DIALOG
) ),
876 Image( IDEResId( RID_IMG_DIALOG_HC
) ),
878 std::auto_ptr
< BasicEntry
>( new BasicEntry( OBJ_TYPE_DIALOG
) ) );
879 DBG_ASSERT( pEntry
, "InsertEntry fehlgeschlagen!" );
881 aBasicBox
.SetCurEntry( pEntry
);
882 aBasicBox
.Select( aBasicBox
.GetCurEntry() ); // OV-Bug?!
890 void ObjectPage::DeleteCurrent()
892 SvLBoxEntry
* pCurEntry
= aBasicBox
.GetCurEntry();
893 DBG_ASSERT( pCurEntry
, "Kein aktueller Eintrag!" );
894 BasicEntryDescriptor
aDesc( aBasicBox
.GetEntryDescriptor( pCurEntry
) );
895 ScriptDocument
aDocument( aDesc
.GetDocument() );
896 DBG_ASSERT( aDocument
.isAlive(), "ObjectPage::DeleteCurrent: no document!" );
897 if ( !aDocument
.isAlive() )
899 String
aLibName( aDesc
.GetLibName() );
900 String
aName( aDesc
.GetName() );
901 BasicEntryType
eType( aDesc
.GetType() );
903 if ( ( eType
== OBJ_TYPE_MODULE
&& QueryDelModule( aName
, this ) ) ||
904 ( eType
== OBJ_TYPE_DIALOG
&& QueryDelDialog( aName
, this ) ) )
906 aBasicBox
.GetModel()->Remove( pCurEntry
);
907 if ( aBasicBox
.GetCurEntry() ) // OV-Bug ?
908 aBasicBox
.Select( aBasicBox
.GetCurEntry() );
909 BasicIDEShell
* pIDEShell
= IDE_DLL()->GetShell();
910 SfxViewFrame
* pViewFrame
= pIDEShell
? pIDEShell
->GetViewFrame() : NULL
;
911 SfxDispatcher
* pDispatcher
= pViewFrame
? pViewFrame
->GetDispatcher() : NULL
;
914 SbxItem
aSbxItem( SID_BASICIDE_ARG_SBX
, aDocument
, aLibName
, aName
, aBasicBox
.ConvertType( eType
) );
915 pDispatcher
->Execute( SID_BASICIDE_SBXDELETED
,
916 SFX_CALLMODE_SYNCHRON
, &aSbxItem
, 0L );
921 bool bSuccess
= false;
922 if ( eType
== OBJ_TYPE_MODULE
)
923 bSuccess
= aDocument
.removeModule( aLibName
, aName
);
924 else if ( eType
== OBJ_TYPE_DIALOG
)
925 bSuccess
= BasicIDE::RemoveDialog( aDocument
, aLibName
, aName
);
928 BasicIDE::MarkDocumentModified( aDocument
);
930 catch ( container::NoSuchElementException
& )
932 DBG_UNHANDLED_EXCEPTION();
939 void ObjectPage::EndTabDialog( USHORT nRet
)
941 DBG_ASSERT( pTabDlg
, "TabDlg nicht gesetzt!" );
943 pTabDlg
->EndDialog( nRet
);
947 LibDialog::LibDialog( Window
* pParent
)
948 : ModalDialog( pParent
, IDEResId( RID_DLG_LIBS
) ),
949 aOKButton( this, IDEResId( RID_PB_OK
) ),
950 aCancelButton( this, IDEResId( RID_PB_CANCEL
) ),
951 aStorageName( this, IDEResId( RID_FT_STORAGENAME
) ),
952 aLibBox( this, IDEResId( RID_CTRL_LIBS
) ),
953 aFixedLine( this, IDEResId( RID_FL_OPTIONS
) ),
954 aReferenceBox( this, IDEResId( RID_CB_REF
) ),
955 aReplaceBox( this, IDEResId( RID_CB_REPL
) )
957 SetText( String( IDEResId( RID_STR_APPENDLIBS
) ) );
962 LibDialog::~LibDialog()
966 void LibDialog::SetStorageName( const String
& rName
)
968 String
aName( IDEResId( RID_STR_FILENAME
) );
970 aStorageName
.SetText( aName
);
974 SbModule
* createModImpl( Window
* pWin
, const ScriptDocument
& rDocument
,
975 BasicTreeListBox
& rBasicBox
, const String
& rLibName
, String aModName
, bool bMain
)
977 OSL_ENSURE( rDocument
.isAlive(), "createModImpl: invalid document!" );
978 if ( !rDocument
.isAlive() )
981 SbModule
* pModule
= NULL
;
983 String
aLibName( rLibName
);
984 if ( !aLibName
.Len() )
985 aLibName
= String::CreateFromAscii( "Standard" );
986 rDocument
.getOrCreateLibrary( E_SCRIPTS
, aLibName
);
987 if ( !aModName
.Len() )
988 aModName
= rDocument
.createObjectName( E_SCRIPTS
, aLibName
);
990 std::auto_ptr
< NewObjectDialog
> xNewDlg(
991 new NewObjectDialog( pWin
, NEWOBJECTMODE_MOD
, true ) );
992 xNewDlg
->SetObjectName( aModName
);
994 if (xNewDlg
->Execute() != 0)
996 if ( xNewDlg
->GetObjectName().Len() )
997 aModName
= xNewDlg
->GetObjectName();
1001 ::rtl::OUString sModuleCode
;
1002 // the module has existed
1003 if( rDocument
.hasModule( aLibName
, aModName
) )
1005 rDocument
.createModule( aLibName
, aModName
, bMain
, sModuleCode
);
1006 BasicManager
* pBasMgr
= rDocument
.getBasicManager();
1007 StarBASIC
* pBasic
= pBasMgr
? pBasMgr
->GetLib( aLibName
) : 0;
1009 pModule
= pBasic
->FindModule( aModName
);
1010 SbxItem
aSbxItem( SID_BASICIDE_ARG_SBX
, rDocument
, aLibName
, aModName
, BASICIDE_TYPE_MODULE
);
1011 BasicIDEShell
* pIDEShell
= IDE_DLL()->GetShell();
1012 SfxViewFrame
* pViewFrame
= pIDEShell
? pIDEShell
->GetViewFrame() : NULL
;
1013 SfxDispatcher
* pDispatcher
= pViewFrame
? pViewFrame
->GetDispatcher() : NULL
;
1016 pDispatcher
->Execute( SID_BASICIDE_SBXINSERTED
,
1017 SFX_CALLMODE_SYNCHRON
, &aSbxItem
, 0L );
1019 LibraryLocation eLocation
= rDocument
.getLibraryLocation( aLibName
);
1020 SvLBoxEntry
* pRootEntry
= rBasicBox
.FindRootEntry( rDocument
, eLocation
);
1023 if ( !rBasicBox
.IsExpanded( pRootEntry
) )
1024 rBasicBox
.Expand( pRootEntry
);
1025 SvLBoxEntry
* pLibEntry
= rBasicBox
.FindEntry( pRootEntry
, aLibName
, OBJ_TYPE_LIBRARY
);
1026 DBG_ASSERT( pLibEntry
, "Libeintrag nicht gefunden!" );
1029 if ( !rBasicBox
.IsExpanded( pLibEntry
) )
1030 rBasicBox
.Expand( pLibEntry
);
1031 SvLBoxEntry
* pSubRootEntry
= pLibEntry
;
1032 if( pBasic
&& pBasic
->isVBAEnabled() )
1034 // add the new module in the "Modules" entry
1035 SvLBoxEntry
* pLibSubEntry
= rBasicBox
.FindEntry( pLibEntry
, String( IDEResId( RID_STR_NORMAL_MODULES
) ) , OBJ_TYPE_NORMAL_MODULES
);
1038 if( !rBasicBox
.IsExpanded( pLibSubEntry
) )
1039 rBasicBox
.Expand( pLibSubEntry
);
1040 pSubRootEntry
= pLibSubEntry
;
1044 SvLBoxEntry
* pEntry
= rBasicBox
.FindEntry( pSubRootEntry
, aModName
, OBJ_TYPE_MODULE
);
1047 pEntry
= rBasicBox
.AddEntry(
1049 Image( IDEResId( RID_IMG_MODULE
) ),
1050 Image( IDEResId( RID_IMG_MODULE_HC
) ),
1051 pSubRootEntry
, false,
1052 std::auto_ptr
< BasicEntry
>( new BasicEntry( OBJ_TYPE_MODULE
) ) );
1053 DBG_ASSERT( pEntry
, "InsertEntry fehlgeschlagen!" );
1055 rBasicBox
.SetCurEntry( pEntry
);
1056 rBasicBox
.Select( rBasicBox
.GetCurEntry() ); // OV-Bug?!
1060 catch ( container::ElementExistException
& )
1062 ErrorBox( pWin
, WB_OK
| WB_DEF_OK
,
1063 String( IDEResId( RID_STR_SBXNAMEALLREADYUSED2
) ) ).Execute();
1065 catch ( container::NoSuchElementException
& )
1067 DBG_UNHANDLED_EXCEPTION();