LCOV - code coverage report
Current view: top level - libreoffice/basctl/source/basicide - moduldlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 516 0.0 %
Date: 2012-12-17 Functions: 0 36 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10