LCOV - code coverage report
Current view: top level - basctl/source/basicide - moduldlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 532 0.0 %
Date: 2012-08-25 Functions: 0 36 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

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

Generated by: LCOV version 1.10