LCOV - code coverage report
Current view: top level - basctl/source/basicide - moduldl2.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 833 0.0 %
Date: 2014-04-11 Functions: 0 69 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 <vcl/layout.hxx>
      21             : #include <sot/storinfo.hxx>
      22             : 
      23             : #include <moduldlg.hxx>
      24             : #include <basidesh.hrc>
      25             : #include <basidesh.hxx>
      26             : #include <bastypes.hxx>
      27             : #include <basobj.hxx>
      28             : #include <baside2.hrc>
      29             : #include <iderdll.hxx>
      30             : #include <iderdll2.hxx>
      31             : #include <svx/passwd.hxx>
      32             : #include <sbxitem.hxx>
      33             : #include <basdoc.hxx>
      34             : #include <ucbhelper/content.hxx>
      35             : #include <rtl/uri.hxx>
      36             : #include <sfx2/app.hxx>
      37             : #include <sfx2/dinfdlg.hxx>
      38             : #include <sfx2/dispatch.hxx>
      39             : #include <sfx2/request.hxx>
      40             : #include <tools/urlobj.hxx>
      41             : #include <tools/diagnose_ex.h>
      42             : #include <svtools/svlbitm.hxx>
      43             : #include <svtools/treelistentry.hxx>
      44             : 
      45             : #include <sot/storage.hxx>
      46             : #include <com/sun/star/io/Pipe.hpp>
      47             : #include <com/sun/star/ui/dialogs/FilePicker.hpp>
      48             : #include <com/sun/star/ui/dialogs/FolderPicker.hpp>
      49             : #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
      50             : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
      51             : #include <com/sun/star/script/DocumentScriptLibraryContainer.hpp>
      52             : #include <com/sun/star/script/DocumentDialogLibraryContainer.hpp>
      53             : #include <com/sun/star/script/XLibraryContainerPassword.hpp>
      54             : #include <com/sun/star/script/XLibraryContainerExport.hpp>
      55             : #include <com/sun/star/task/InteractionHandler.hpp>
      56             : #include <com/sun/star/ucb/SimpleFileAccess.hpp>
      57             : #include <com/sun/star/ucb/XCommandEnvironment.hpp>
      58             : #include <com/sun/star/ucb/NameClash.hpp>
      59             : #include <com/sun/star/packages/manifest/ManifestWriter.hpp>
      60             : #include <unotools/pathoptions.hxx>
      61             : #include <comphelper/processfactory.hxx>
      62             : 
      63             : #include <com/sun/star/util/VetoException.hpp>
      64             : #include <com/sun/star/script/ModuleSizeExceededRequest.hpp>
      65             : 
      66             : #include <cassert>
      67             : 
      68             : namespace basctl
      69             : {
      70             : 
      71             : using namespace ::com::sun::star;
      72             : using namespace ::com::sun::star::uno;
      73             : using namespace ::com::sun::star::lang;
      74             : using namespace ::com::sun::star::ucb;
      75             : using namespace ::com::sun::star::ui::dialogs;
      76             : 
      77             : typedef ::cppu::WeakImplHelper1< task::XInteractionHandler > HandlerImpl_BASE;
      78             : 
      79             : namespace
      80             : {
      81             : 
      82           0 : class DummyInteractionHandler  : public HandlerImpl_BASE
      83             : {
      84             :     Reference< task::XInteractionHandler2 > m_xHandler;
      85             : public:
      86           0 :     DummyInteractionHandler( const Reference< task::XInteractionHandler2 >& xHandler ) : m_xHandler( xHandler ){}
      87             : 
      88           0 :     virtual void SAL_CALL handle( const Reference< task::XInteractionRequest >& rRequest ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
      89             :     {
      90           0 :         if ( m_xHandler.is() )
      91             :         {
      92           0 :         script::ModuleSizeExceededRequest aModSizeException;
      93           0 :         if ( rRequest->getRequest() >>= aModSizeException )
      94           0 :             m_xHandler->handle( rRequest );
      95             :         }
      96           0 :     }
      97             : };
      98             : 
      99             : // LibUserData
     100             : class LibUserData
     101             : {
     102             : private:
     103             :     ScriptDocument m_aDocument;
     104             : 
     105             : public:
     106           0 :     LibUserData (ScriptDocument const& rDocument) : m_aDocument(rDocument) { }
     107           0 :     virtual ~LibUserData() {};
     108             : 
     109           0 :     const ScriptDocument& GetDocument() const { return m_aDocument; }
     110             : };
     111             : 
     112             : //  LibLBoxString
     113           0 : class LibLBoxString : public SvLBoxString
     114             : {
     115             : public:
     116           0 :     LibLBoxString( SvTreeListEntry* pEntry, sal_uInt16 nFlags, const OUString& rTxt ) :
     117           0 :         SvLBoxString( pEntry, nFlags, rTxt ) {}
     118             : 
     119             :     virtual void Paint(const Point& rPos, SvTreeListBox& rDev, const SvViewDataEntry* pView, const SvTreeListEntry* pEntry) SAL_OVERRIDE;
     120             : };
     121             : 
     122           0 : void LibLBoxString::Paint(const Point& rPos, SvTreeListBox& rDev, const SvViewDataEntry* /*pView*/, const SvTreeListEntry* pEntry)
     123             : {
     124             :     // Change text color if library is read only:
     125           0 :     bool bReadOnly = false;
     126           0 :     if (pEntry && pEntry->GetUserData())
     127             :     {
     128             :         ScriptDocument aDocument(
     129           0 :             static_cast<LibUserData*>(pEntry->GetUserData())->
     130           0 :             GetDocument() );
     131             : 
     132           0 :         OUString aLibName = static_cast<const SvLBoxString*>(pEntry->GetItem(1))->GetText();
     133             :         Reference< script::XLibraryContainer2 > xModLibContainer(
     134           0 :             aDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY);
     135             :         Reference< script::XLibraryContainer2 > xDlgLibContainer(
     136           0 :             aDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY);
     137             :         bReadOnly
     138           0 :             = (xModLibContainer.is() && xModLibContainer->hasByName(aLibName)
     139           0 :                && xModLibContainer->isLibraryReadOnly(aLibName))
     140           0 :             || (xDlgLibContainer.is() && xDlgLibContainer->hasByName(aLibName)
     141           0 :                 && xDlgLibContainer->isLibraryReadOnly(aLibName));
     142             :     }
     143           0 :     if (bReadOnly)
     144           0 :         rDev.DrawCtrlText(rPos, GetText(), 0, -1, TEXT_DRAW_DISABLE);
     145             :     else
     146           0 :         rDev.DrawText(rPos, GetText());
     147           0 : }
     148             : 
     149             : } // namespace
     150             : 
     151             : //  basctl::CheckBox
     152           0 : CheckBox::CheckBox(Window* pParent, WinBits nStyle)
     153             :     : SvTabListBox(pParent, nStyle)
     154             :     , eMode(ObjectMode::Module)
     155           0 :     , m_aDocument(ScriptDocument::getApplicationScriptDocument())
     156             : {
     157           0 :     long aTabs_[] = { 1, 12 };  // TabPos needs at least one...
     158             :                                 // 12 because of the CheckBox
     159           0 :     SetTabs( aTabs_ );
     160           0 :     Init();
     161           0 : }
     162             : 
     163           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeCheckBox(Window *pParent, VclBuilder::stringmap &rMap)
     164             : {
     165           0 :     WinBits nWinBits = WB_TABSTOP;
     166           0 :     OString sBorder = VclBuilder::extractCustomProperty(rMap);
     167           0 :     if (!sBorder.isEmpty())
     168           0 :        nWinBits |= WB_BORDER;
     169           0 :     return new CheckBox(pParent, nWinBits);
     170             : }
     171             : 
     172           0 : CheckBox::~CheckBox()
     173             : {
     174           0 :     delete pCheckButton;
     175             : 
     176             :     // delete user data
     177           0 :     SvTreeListEntry* pEntry = First();
     178           0 :     while ( pEntry )
     179             :     {
     180           0 :         delete static_cast<LibUserData*>(pEntry->GetUserData());
     181           0 :         pEntry = Next( pEntry );
     182             :     }
     183           0 : }
     184             : 
     185           0 : void CheckBox::Init()
     186             : {
     187           0 :     pCheckButton = new SvLBoxButtonData(this);
     188             : 
     189           0 :     if (eMode == ObjectMode::Library)
     190           0 :         EnableCheckButton( pCheckButton );
     191             :     else
     192           0 :         EnableCheckButton( 0 );
     193             : 
     194           0 :     SetHighlightRange();
     195           0 : }
     196             : 
     197           0 : void CheckBox::SetMode (ObjectMode::Mode e)
     198             : {
     199           0 :     eMode = e;
     200             : 
     201           0 :     if (eMode == ObjectMode::Library)
     202           0 :         EnableCheckButton( pCheckButton );
     203             :     else
     204           0 :         EnableCheckButton( 0 );
     205           0 : }
     206             : 
     207           0 : SvTreeListEntry* CheckBox::DoInsertEntry( const OUString& rStr, sal_uLong nPos )
     208             : {
     209           0 :     return SvTabListBox::InsertEntryToColumn( rStr, nPos, 0 );
     210             : }
     211             : 
     212           0 : SvTreeListEntry* CheckBox::FindEntry( const OUString& rName )
     213             : {
     214           0 :     sal_uLong nCount = GetEntryCount();
     215           0 :     for ( sal_uLong i = 0; i < nCount; i++ )
     216             :     {
     217           0 :         SvTreeListEntry* pEntry = GetEntry( i );
     218             :         DBG_ASSERT( pEntry, "pEntry?!" );
     219           0 :         if ( rName.equalsIgnoreAsciiCase( GetEntryText( pEntry, 0 ) ) )
     220           0 :             return pEntry;
     221             :     }
     222           0 :     return 0;
     223             : }
     224             : 
     225           0 : void CheckBox::CheckEntryPos( sal_uLong nPos )
     226             : {
     227           0 :     if ( nPos < GetEntryCount() )
     228             :     {
     229           0 :         SvTreeListEntry* pEntry = GetEntry( nPos );
     230             : 
     231           0 :         if ( GetCheckButtonState( pEntry ) != SV_BUTTON_CHECKED )
     232           0 :             SetCheckButtonState( pEntry, SvButtonState(SV_BUTTON_CHECKED) );
     233             :     }
     234           0 : }
     235             : 
     236           0 : bool CheckBox::IsChecked( sal_uLong nPos ) const
     237             : {
     238           0 :     if ( nPos < GetEntryCount() )
     239           0 :         return GetCheckButtonState(GetEntry(nPos)) == SV_BUTTON_CHECKED;
     240           0 :     return false;
     241             : }
     242             : 
     243           0 : void CheckBox::InitEntry(SvTreeListEntry* pEntry, const OUString& rTxt,
     244             :     const Image& rImg1, const Image& rImg2, SvLBoxButtonKind eButtonKind )
     245             : {
     246           0 :     SvTabListBox::InitEntry(pEntry, rTxt, rImg1, rImg2, eButtonKind);
     247             : 
     248           0 :     if (eMode == ObjectMode::Module)
     249             :     {
     250             :         // initialize all columns with own string class (column 0 == bitmap)
     251           0 :         sal_uInt16 nCount = pEntry->ItemCount();
     252           0 :         for ( sal_uInt16 nCol = 1; nCol < nCount; ++nCol )
     253             :         {
     254           0 :             SvLBoxString* pCol = (SvLBoxString*)pEntry->GetItem( nCol );
     255           0 :             LibLBoxString* pStr = new LibLBoxString( pEntry, 0, pCol->GetText() );
     256           0 :             pEntry->ReplaceItem( pStr, nCol );
     257             :         }
     258             :     }
     259           0 : }
     260             : 
     261           0 : bool CheckBox::EditingEntry( SvTreeListEntry* pEntry, Selection& )
     262             : {
     263           0 :     if (eMode != ObjectMode::Module)
     264           0 :         return false;
     265             : 
     266             :     DBG_ASSERT( pEntry, "Kein Eintrag?" );
     267             : 
     268             :     // check, if Standard library
     269           0 :     OUString aLibName = GetEntryText( pEntry, 0 );
     270           0 :     if ( aLibName.equalsIgnoreAsciiCase( "Standard" ) )
     271             :     {
     272           0 :         MessageDialog(this, IDE_RESSTR(RID_STR_CANNOTCHANGENAMESTDLIB)).Execute();
     273           0 :         return false;
     274             :     }
     275             : 
     276             :     // check, if library is readonly
     277           0 :     Reference< script::XLibraryContainer2 > xModLibContainer( m_aDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
     278           0 :     Reference< script::XLibraryContainer2 > xDlgLibContainer( m_aDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY );
     279           0 :     if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) && xModLibContainer->isLibraryReadOnly( aLibName ) && !xModLibContainer->isLibraryLink( aLibName ) ) ||
     280           0 :          ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) && xDlgLibContainer->isLibraryReadOnly( aLibName ) && !xDlgLibContainer->isLibraryLink( aLibName ) ) )
     281             :     {
     282           0 :         MessageDialog(this, IDE_RESSTR(RID_STR_LIBISREADONLY)).Execute();
     283           0 :         return false;
     284             :     }
     285             : 
     286             :     // i24094: Password verification necessary for renaming
     287           0 :     bool bOK = true;
     288           0 :     if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) && !xModLibContainer->isLibraryLoaded( aLibName ) )
     289             :     {
     290             :         // check password
     291           0 :         Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
     292           0 :         if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aLibName ) && !xPasswd->isLibraryPasswordVerified( aLibName ) )
     293             :         {
     294           0 :             OUString aPassword;
     295           0 :             Reference< script::XLibraryContainer > xModLibContainer1( xModLibContainer, UNO_QUERY );
     296           0 :             bOK = QueryPassword( xModLibContainer1, aLibName, aPassword );
     297             :         }
     298           0 :         if ( !bOK )
     299           0 :             return false;
     300             :     }
     301             : 
     302             :     // TODO: check if library is reference/link
     303             : 
     304           0 :     return true;
     305             : }
     306             : 
     307           0 : bool CheckBox::EditedEntry( SvTreeListEntry* pEntry, const OUString& rNewName )
     308             : {
     309           0 :     bool bValid = rNewName.getLength() <= 30 && IsValidSbxName(rNewName);
     310           0 :     OUString aOldName( GetEntryText( pEntry, 0 ) );
     311           0 :     if ( bValid && ( aOldName != rNewName ) )
     312             :     {
     313             :         try
     314             :         {
     315           0 :             Reference< script::XLibraryContainer2 > xModLibContainer( m_aDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
     316           0 :             if ( xModLibContainer.is() )
     317           0 :                 xModLibContainer->renameLibrary( aOldName, rNewName );
     318             : 
     319           0 :             Reference< script::XLibraryContainer2 > xDlgLibContainer( m_aDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY );
     320           0 :             if ( xDlgLibContainer.is() )
     321           0 :                 xDlgLibContainer->renameLibrary( aOldName, rNewName );
     322             : 
     323           0 :             MarkDocumentModified( m_aDocument );
     324           0 :             if (SfxBindings* pBindings = GetBindingsPtr())
     325             :             {
     326           0 :                 pBindings->Invalidate( SID_BASICIDE_LIBSELECTOR );
     327           0 :                 pBindings->Update( SID_BASICIDE_LIBSELECTOR );
     328           0 :             }
     329             :         }
     330           0 :         catch (const container::ElementExistException& )
     331             :         {
     332           0 :             MessageDialog(this, IDE_RESSTR(RID_STR_SBXNAMEALLREADYUSED)).Execute();
     333           0 :             return false;
     334             :         }
     335           0 :         catch (const container::NoSuchElementException& )
     336             :         {
     337             :             DBG_UNHANDLED_EXCEPTION();
     338           0 :             return false;
     339             :         }
     340             :     }
     341             : 
     342           0 :     if ( !bValid )
     343             :     {
     344           0 :         if ( rNewName.getLength() > 30 )
     345           0 :             MessageDialog(this, IDE_RESSTR(RID_STR_LIBNAMETOLONG)).Execute();
     346             :         else
     347           0 :             MessageDialog(this, IDE_RESSTR(RID_STR_BADSBXNAME)).Execute();
     348             :     }
     349             : 
     350           0 :     return bValid;
     351             : }
     352             : 
     353             : // NewObjectDialog
     354           0 : IMPL_LINK_NOARG(NewObjectDialog, OkButtonHandler)
     355             : {
     356           0 :     if (IsValidSbxName(m_pEdit->GetText()))
     357           0 :         EndDialog(1);
     358             :     else
     359             :     {
     360           0 :         MessageDialog(this, IDE_RESSTR(RID_STR_BADSBXNAME)).Execute();
     361           0 :         m_pEdit->GrabFocus();
     362             :     }
     363           0 :     return 0;
     364             : }
     365             : 
     366           0 : NewObjectDialog::NewObjectDialog(Window * pParent, ObjectMode::Mode eMode,
     367             :     bool bCheckName)
     368           0 :     : ModalDialog(pParent, "NewLibDialog", "modules/BasicIDE/ui/newlibdialog.ui")
     369             : {
     370           0 :     get(m_pOKButton, "ok");
     371           0 :     get(m_pEdit, "entry");
     372             : 
     373           0 :     m_pEdit->GrabFocus();
     374             : 
     375           0 :     switch (eMode)
     376             :     {
     377             :         case ObjectMode::Library:
     378           0 :             SetText( IDE_RESSTR(RID_STR_NEWLIB) );
     379           0 :             break;
     380             :         case ObjectMode::Module:
     381           0 :             SetText( IDE_RESSTR(RID_STR_NEWMOD) );
     382           0 :             break;
     383             :         case ObjectMode::Method:
     384           0 :             SetText( IDE_RESSTR(RID_STR_NEWMETH) );
     385           0 :             break;
     386             :         case ObjectMode::Dialog:
     387           0 :             SetText( IDE_RESSTR(RID_STR_NEWDLG) );
     388           0 :             break;
     389             :         default:
     390             :             assert(false);
     391             :     }
     392             : 
     393           0 :     if (bCheckName)
     394           0 :         m_pOKButton->SetClickHdl(LINK(this, NewObjectDialog, OkButtonHandler));
     395           0 : }
     396             : 
     397             : // GotoLineDialog
     398           0 : GotoLineDialog::GotoLineDialog(Window * pParent )
     399             :     : ModalDialog(pParent, "GotoLineDialog",
     400           0 :         "modules/BasicIDE/ui/gotolinedialog.ui")
     401             : {
     402           0 :     get(m_pEdit, "entry");
     403           0 :     get(m_pOKButton, "ok");
     404           0 :     m_pEdit->GrabFocus();
     405           0 :     m_pOKButton->SetClickHdl(LINK(this, GotoLineDialog, OkButtonHandler));
     406           0 : }
     407             : 
     408           0 : sal_Int32 GotoLineDialog::GetLineNumber() const
     409             : {
     410           0 :     return m_pEdit->GetText().toInt32();
     411             : }
     412             : 
     413           0 : IMPL_LINK_NOARG(GotoLineDialog, OkButtonHandler)
     414             : {
     415           0 :     if ( GetLineNumber() )
     416           0 :         EndDialog(1);
     417             :     else
     418           0 :         m_pEdit->SetText(m_pEdit->GetText(), Selection(0, m_pEdit->GetText().getLength()));
     419           0 :     return 0;
     420             : }
     421             : 
     422             : // ExportDialog
     423           0 : IMPL_LINK_NOARG(ExportDialog, OkButtonHandler)
     424             : {
     425           0 :     mbExportAsPackage = m_pExportAsPackageButton->IsChecked();
     426           0 :     EndDialog(1);
     427           0 :     return 0;
     428             : }
     429             : 
     430           0 : ExportDialog::ExportDialog(Window * pParent)
     431             :     : ModalDialog(pParent, "ExportDialog",
     432             :         "modules/BasicIDE/ui/exportdialog.ui")
     433           0 :     , mbExportAsPackage(false)
     434             : {
     435           0 :     get(m_pExportAsPackageButton, "extension");
     436           0 :     get(m_pOKButton, "ok");
     437             : 
     438           0 :     m_pExportAsPackageButton->Check();
     439           0 :     m_pOKButton->SetClickHdl(LINK(this, ExportDialog, OkButtonHandler));
     440           0 : }
     441             : 
     442             : // LibPage
     443           0 : LibPage::LibPage(Window * pParent)
     444             :     : TabPage(pParent, "LibPage",
     445             :         "modules/BasicIDE/ui/libpage.ui")
     446           0 :     , m_aCurDocument(ScriptDocument::getApplicationScriptDocument())
     447           0 :     , m_eCurLocation(LIBRARY_LOCATION_UNKNOWN)
     448             : {
     449           0 :     get(m_pBasicsBox, "location");
     450           0 :     get(m_pLibBox, "library");
     451           0 :     Size aSize(m_pLibBox->LogicToPixel(Size(130, 87), MAP_APPFONT));
     452           0 :     m_pLibBox->set_height_request(aSize.Height());
     453           0 :     m_pLibBox->set_width_request(aSize.Width());
     454           0 :     get(m_pEditButton, "edit");
     455           0 :     get(m_pPasswordButton, "password");
     456           0 :     get(m_pNewLibButton, "new");
     457           0 :     get(m_pInsertLibButton, "import");
     458           0 :     get(m_pExportButton, "export");
     459           0 :     get(m_pDelButton, "delete");
     460             : 
     461           0 :     pTabDlg = 0;
     462             : 
     463           0 :     m_pEditButton->SetClickHdl( LINK( this, LibPage, ButtonHdl ) );
     464           0 :     m_pNewLibButton->SetClickHdl( LINK( this, LibPage, ButtonHdl ) );
     465           0 :     m_pPasswordButton->SetClickHdl( LINK( this, LibPage, ButtonHdl ) );
     466           0 :     m_pExportButton->SetClickHdl( LINK( this, LibPage, ButtonHdl ) );
     467           0 :     m_pInsertLibButton->SetClickHdl( LINK( this, LibPage, ButtonHdl ) );
     468           0 :     m_pDelButton->SetClickHdl( LINK( this, LibPage, ButtonHdl ) );
     469           0 :     m_pLibBox->SetSelectHdl( LINK( this, LibPage, TreeListHighlightHdl ) );
     470             : 
     471           0 :     m_pBasicsBox->SetSelectHdl( LINK( this, LibPage, BasicSelectHdl ) );
     472             : 
     473           0 :     m_pLibBox->SetMode(ObjectMode::Module);
     474           0 :     m_pLibBox->EnableInplaceEditing(true);
     475           0 :     m_pLibBox->SetStyle( WB_HSCROLL | WB_BORDER | WB_TABSTOP );
     476             : 
     477           0 :     long aTabs[] = { 2, 30, 120 };
     478           0 :     m_pLibBox->SetTabs( aTabs, MAP_PIXEL );
     479             : 
     480           0 :     FillListBox();
     481           0 :     m_pBasicsBox->SelectEntryPos( 0 );
     482           0 :     SetCurLib();
     483             : 
     484           0 :     CheckButtons();
     485           0 : }
     486             : 
     487           0 : LibPage::~LibPage()
     488             : {
     489           0 :     sal_uInt16 nCount = m_pBasicsBox->GetEntryCount();
     490           0 :     for ( sal_uInt16 i = 0; i < nCount; ++i )
     491             :     {
     492           0 :         DocumentEntry* pEntry = (DocumentEntry*)m_pBasicsBox->GetEntryData( i );
     493           0 :         delete pEntry;
     494             :     }
     495           0 : }
     496             : 
     497           0 : void LibPage::CheckButtons()
     498             : {
     499           0 :     SvTreeListEntry* pCur = m_pLibBox->GetCurEntry();
     500           0 :     if ( pCur )
     501             :     {
     502           0 :         OUString aLibName = m_pLibBox->GetEntryText( pCur, 0 );
     503           0 :         Reference< script::XLibraryContainer2 > xModLibContainer( m_aCurDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
     504           0 :         Reference< script::XLibraryContainer2 > xDlgLibContainer( m_aCurDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY );
     505             : 
     506           0 :         if ( m_eCurLocation == LIBRARY_LOCATION_SHARE )
     507             :         {
     508           0 :             m_pPasswordButton->Disable();
     509           0 :             m_pNewLibButton->Disable();
     510           0 :             m_pInsertLibButton->Disable();
     511           0 :             m_pDelButton->Disable();
     512             :         }
     513           0 :         else if ( aLibName.equalsIgnoreAsciiCase( "Standard" ) )
     514             :         {
     515           0 :             m_pPasswordButton->Disable();
     516           0 :             m_pNewLibButton->Enable();
     517           0 :             m_pInsertLibButton->Enable();
     518           0 :             m_pExportButton->Disable();
     519           0 :             m_pDelButton->Disable();
     520             :         }
     521           0 :         else if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) && xModLibContainer->isLibraryReadOnly( aLibName ) ) ||
     522           0 :                   ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) && xDlgLibContainer->isLibraryReadOnly( aLibName ) ) )
     523             :         {
     524           0 :             m_pPasswordButton->Disable();
     525           0 :             m_pNewLibButton->Enable();
     526           0 :             m_pInsertLibButton->Enable();
     527           0 :             if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) && xModLibContainer->isLibraryReadOnly( aLibName ) && !xModLibContainer->isLibraryLink( aLibName ) ) ||
     528           0 :                  ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) && xDlgLibContainer->isLibraryReadOnly( aLibName ) && !xDlgLibContainer->isLibraryLink( aLibName ) ) )
     529           0 :                 m_pDelButton->Disable();
     530             :             else
     531           0 :                 m_pDelButton->Enable();
     532             :         }
     533             :         else
     534             :         {
     535           0 :             if ( xModLibContainer.is() && !xModLibContainer->hasByName( aLibName ) )
     536           0 :                 m_pPasswordButton->Disable();
     537             :             else
     538           0 :                 m_pPasswordButton->Enable();
     539             : 
     540           0 :             m_pNewLibButton->Enable();
     541           0 :             m_pInsertLibButton->Enable();
     542           0 :             m_pExportButton->Enable();
     543           0 :             m_pDelButton->Enable();
     544           0 :         }
     545             :     }
     546           0 : }
     547             : 
     548           0 : void LibPage::ActivatePage()
     549             : {
     550           0 :     SetCurLib();
     551           0 : }
     552             : 
     553           0 : void LibPage::DeactivatePage()
     554             : {
     555           0 : }
     556             : 
     557           0 : IMPL_LINK_INLINE_START( LibPage, TreeListHighlightHdl, SvTreeListBox *, pBox )
     558             : {
     559           0 :     if ( pBox->IsSelected( pBox->GetHdlEntry() ) )
     560           0 :         CheckButtons();
     561           0 :     return 0;
     562             : }
     563           0 : IMPL_LINK_INLINE_END( LibPage, TreeListHighlightHdl, SvTreeListBox *, pBox )
     564             : 
     565           0 : IMPL_LINK_INLINE_START( LibPage, BasicSelectHdl, ListBox *, pBox )
     566             : {
     567             :     (void)pBox;
     568           0 :     SetCurLib();
     569           0 :     CheckButtons();
     570           0 :     return 0;
     571             : }
     572           0 : IMPL_LINK_INLINE_END( LibPage, BasicSelectHdl, ListBox *, pBox )
     573             : 
     574           0 : IMPL_LINK( LibPage, ButtonHdl, Button *, pButton )
     575             : {
     576           0 :     if (pButton == m_pEditButton)
     577             :     {
     578           0 :         SfxAllItemSet aArgs( SFX_APP()->GetPool() );
     579           0 :         SfxRequest aRequest( SID_BASICIDE_APPEAR, SFX_CALLMODE_SYNCHRON, aArgs );
     580           0 :         SFX_APP()->ExecuteSlot( aRequest );
     581             : 
     582           0 :         SfxUsrAnyItem aDocItem( SID_BASICIDE_ARG_DOCUMENT_MODEL, makeAny( m_aCurDocument.getDocumentOrNull() ) );
     583           0 :         SvTreeListEntry* pCurEntry = m_pLibBox->GetCurEntry();
     584             :         DBG_ASSERT( pCurEntry, "Entry?!" );
     585           0 :         OUString aLibName( m_pLibBox->GetEntryText( pCurEntry, 0 ) );
     586           0 :         SfxStringItem aLibNameItem( SID_BASICIDE_ARG_LIBNAME, aLibName );
     587           0 :         if (SfxDispatcher* pDispatcher = GetDispatcher())
     588             :             pDispatcher->Execute( SID_BASICIDE_LIBSELECTED,
     589           0 :                                     SFX_CALLMODE_ASYNCHRON, &aDocItem, &aLibNameItem, 0L );
     590           0 :         EndTabDialog( 1 );
     591           0 :         return 0;
     592             :     }
     593           0 :     else if (pButton == m_pNewLibButton)
     594           0 :         NewLib();
     595           0 :     else if (pButton == m_pInsertLibButton)
     596           0 :         InsertLib();
     597           0 :     else if (pButton == m_pExportButton)
     598           0 :         Export();
     599           0 :     else if (pButton == m_pDelButton)
     600           0 :         DeleteCurrent();
     601           0 :     else if (pButton == m_pPasswordButton)
     602             :     {
     603           0 :         SvTreeListEntry* pCurEntry = m_pLibBox->GetCurEntry();
     604           0 :         OUString aLibName( m_pLibBox->GetEntryText( pCurEntry, 0 ) );
     605             : 
     606             :         // load module library (if not loaded)
     607           0 :         Reference< script::XLibraryContainer > xModLibContainer = m_aCurDocument.getLibraryContainer( E_SCRIPTS );
     608           0 :         if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) && !xModLibContainer->isLibraryLoaded( aLibName ) )
     609             :         {
     610           0 :             Shell* pShell = GetShell();
     611           0 :             if (pShell)
     612           0 :                 pShell->GetViewFrame()->GetWindow().EnterWait();
     613           0 :             xModLibContainer->loadLibrary( aLibName );
     614           0 :             if (pShell)
     615           0 :                 pShell->GetViewFrame()->GetWindow().LeaveWait();
     616             :         }
     617             : 
     618             :         // load dialog library (if not loaded)
     619           0 :         Reference< script::XLibraryContainer > xDlgLibContainer = m_aCurDocument.getLibraryContainer( E_DIALOGS );
     620           0 :         if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) && !xDlgLibContainer->isLibraryLoaded( aLibName ) )
     621             :         {
     622           0 :             Shell* pShell = GetShell();
     623           0 :             if (pShell)
     624           0 :                 pShell->GetViewFrame()->GetWindow().EnterWait();
     625           0 :             xDlgLibContainer->loadLibrary( aLibName );
     626           0 :             if (pShell)
     627           0 :                 pShell->GetViewFrame()->GetWindow().LeaveWait();
     628             :         }
     629             : 
     630             :         // check, if library is password protected
     631           0 :         if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) )
     632             :         {
     633           0 :             Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
     634           0 :             if ( xPasswd.is() )
     635             :             {
     636           0 :                 bool const bProtected = xPasswd->isLibraryPasswordProtected( aLibName );
     637             : 
     638             :                 // change password dialog
     639           0 :                 SvxPasswordDialog* pDlg = new SvxPasswordDialog( this, true, !bProtected );
     640           0 :                 pDlg->SetCheckPasswordHdl( LINK( this, LibPage, CheckPasswordHdl ) );
     641             : 
     642           0 :                 if ( pDlg->Execute() == RET_OK )
     643             :                 {
     644           0 :                     bool const bNewProtected = xPasswd->isLibraryPasswordProtected( aLibName );
     645             : 
     646           0 :                     if ( bNewProtected != bProtected )
     647             :                     {
     648           0 :                         sal_uLong nPos = (sal_uLong)m_pLibBox->GetModel()->GetAbsPos( pCurEntry );
     649           0 :                         m_pLibBox->GetModel()->Remove( pCurEntry );
     650           0 :                         ImpInsertLibEntry( aLibName, nPos );
     651           0 :                         m_pLibBox->SetCurEntry( m_pLibBox->GetEntry( nPos ) );
     652             :                     }
     653             : 
     654           0 :                     MarkDocumentModified( m_aCurDocument );
     655             :                 }
     656           0 :                 delete pDlg;
     657           0 :             }
     658           0 :         }
     659             :     }
     660           0 :     CheckButtons();
     661           0 :     return 0;
     662             : }
     663             : 
     664           0 : IMPL_LINK_INLINE_START( LibPage, CheckPasswordHdl, SvxPasswordDialog *, pDlg )
     665             : {
     666           0 :     long nRet = 0;
     667             : 
     668           0 :     SvTreeListEntry* pCurEntry = m_pLibBox->GetCurEntry();
     669           0 :     OUString aLibName( m_pLibBox->GetEntryText( pCurEntry, 0 ) );
     670           0 :     Reference< script::XLibraryContainerPassword > xPasswd( m_aCurDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
     671             : 
     672           0 :     if ( xPasswd.is() )
     673             :     {
     674             :         try
     675             :         {
     676           0 :             OUString aOldPassword( pDlg->GetOldPassword() );
     677           0 :             OUString aNewPassword( pDlg->GetNewPassword() );
     678           0 :             xPasswd->changeLibraryPassword( aLibName, aOldPassword, aNewPassword );
     679           0 :             nRet = 1;
     680             :         }
     681           0 :         catch (...)
     682             :         {
     683             :         }
     684             :     }
     685             : 
     686           0 :     return nRet;
     687             : }
     688           0 : IMPL_LINK_INLINE_END( LibPage, CheckPasswordHdl, SvxPasswordDialog *, pDlg )
     689             : 
     690           0 : void LibPage::NewLib()
     691             : {
     692           0 :     createLibImpl( static_cast<Window*>( this ), m_aCurDocument, m_pLibBox, NULL);
     693           0 : }
     694             : 
     695           0 : void LibPage::InsertLib()
     696             : {
     697           0 :     Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
     698             :     // file open dialog
     699           0 :     Reference < XFilePicker3 > xFP = FilePicker::createWithMode(xContext, TemplateDescription::FILEOPEN_SIMPLE);
     700           0 :     xFP->setTitle(IDEResId(RID_STR_APPENDLIBS).toString());
     701             : 
     702             :     // filter
     703           0 :     OUString aTitle(IDEResId(RID_STR_BASIC).toString());
     704           0 :     OUString aFilter;
     705           0 :     aFilter =  "*.sbl;*.xlc;*.xlb" ;        // library files
     706           0 :     aFilter += ";*.sdw;*.sxw;*.odt" ;       // text
     707           0 :     aFilter += ";*.vor;*.stw;*.ott" ;       // text template
     708           0 :     aFilter += ";*.sgl;*.sxg;*.odm" ;       // master document
     709           0 :     aFilter += ";*.oth" ;                   // html document template
     710           0 :     aFilter += ";*.sdc;*.sxc;*.ods" ;       // spreadsheet
     711           0 :     aFilter += ";*.stc;*.ots" ;             // spreadsheet template
     712           0 :     aFilter += ";*.sda;*.sxd;*.odg" ;       // drawing
     713           0 :     aFilter += ";*.std;*.otg" ;             // drawing template
     714           0 :     aFilter += ";*.sdd;*.sxi;*.odp" ;       // presentation
     715           0 :     aFilter += ";*.sti;*.otp" ;             // presentation template
     716           0 :     aFilter += ";*.sxm;*.odf" ;             // formula
     717           0 :     xFP->appendFilter( aTitle, aFilter );
     718             : 
     719             :     // set display directory and filter
     720           0 :     OUString aPath(GetExtraData()->GetAddLibPath());
     721           0 :     if ( !aPath.isEmpty() )
     722           0 :         xFP->setDisplayDirectory( aPath );
     723             :     else
     724             :     {
     725             :         // macro path from configuration management
     726           0 :         xFP->setDisplayDirectory( SvtPathOptions().GetWorkPath() );
     727             :     }
     728             : 
     729           0 :     OUString aLastFilter(GetExtraData()->GetAddLibFilter());
     730           0 :     if ( !aLastFilter.isEmpty() )
     731           0 :         xFP->setCurrentFilter( aLastFilter );
     732             :     else
     733           0 :         xFP->setCurrentFilter( IDE_RESSTR(RID_STR_BASIC) );
     734             : 
     735           0 :     if ( xFP->execute() == RET_OK )
     736             :     {
     737           0 :         GetExtraData()->SetAddLibPath( xFP->getDisplayDirectory() );
     738           0 :         GetExtraData()->SetAddLibFilter( xFP->getCurrentFilter() );
     739             : 
     740             :         // library containers for import
     741           0 :         Reference< script::XLibraryContainer2 > xModLibContImport;
     742           0 :         Reference< script::XLibraryContainer2 > xDlgLibContImport;
     743             : 
     744             :         // file URLs
     745           0 :         Sequence< OUString > aFiles = xFP->getFiles();
     746           0 :         INetURLObject aURLObj( aFiles[0] );
     747           0 :         INetURLObject aModURLObj( aURLObj );
     748           0 :         INetURLObject aDlgURLObj( aURLObj );
     749             : 
     750           0 :         OUString aBase = aURLObj.getBase();
     751           0 :         OUString aModBase( "script" );
     752           0 :         OUString aDlgBase( "dialog" );
     753             : 
     754           0 :         if ( aBase == aModBase || aBase == aDlgBase )
     755             :         {
     756           0 :             aModURLObj.setBase( aModBase );
     757           0 :             aDlgURLObj.setBase( aDlgBase );
     758             :         }
     759             : 
     760           0 :         Reference< XSimpleFileAccess3 > xSFA( SimpleFileAccess::create(comphelper::getProcessComponentContext()) );
     761             : 
     762           0 :         OUString aModURL( aModURLObj.GetMainURL( INetURLObject::NO_DECODE ) );
     763           0 :         if ( xSFA->exists( aModURL ) )
     764             :         {
     765           0 :             xModLibContImport = Reference< script::XLibraryContainer2 >(
     766           0 :                         script::DocumentScriptLibraryContainer::createWithURL(xContext, aModURL), UNO_QUERY );
     767             :         }
     768             : 
     769           0 :         OUString aDlgURL( aDlgURLObj.GetMainURL( INetURLObject::NO_DECODE ) );
     770           0 :         if ( xSFA->exists( aDlgURL ) )
     771             :         {
     772           0 :             xDlgLibContImport = Reference< script::XLibraryContainer2 >(
     773           0 :                         script::DocumentDialogLibraryContainer::createWithURL(xContext, aDlgURL), UNO_QUERY );
     774             :         }
     775             : 
     776           0 :         if ( xModLibContImport.is() || xDlgLibContImport.is() )
     777             :         {
     778           0 :             LibDialog* pLibDlg = 0;
     779             : 
     780           0 :             Reference< script::XLibraryContainer > xModLibContImp( xModLibContImport, UNO_QUERY );
     781           0 :             Reference< script::XLibraryContainer > xDlgLibContImp( xDlgLibContImport, UNO_QUERY );
     782           0 :             Sequence< OUString > aLibNames = GetMergedLibraryNames( xModLibContImp, xDlgLibContImp );
     783           0 :             sal_Int32 nLibCount = aLibNames.getLength();
     784           0 :             const OUString* pLibNames = aLibNames.getConstArray();
     785           0 :             for ( sal_Int32 i = 0 ; i < nLibCount ; i++ )
     786             :             {
     787             :                 // library import dialog
     788           0 :                 if ( !pLibDlg )
     789             :                 {
     790           0 :                     pLibDlg = new LibDialog( this );
     791           0 :                     pLibDlg->SetStorageName( aURLObj.getName() );
     792           0 :                     pLibDlg->GetLibBox().SetMode(ObjectMode::Library);
     793             :                 }
     794             : 
     795             :                 // libbox entries
     796           0 :                 OUString aLibName( pLibNames[ i ] );
     797           0 :                 if ( !( ( xModLibContImport.is() && xModLibContImport->hasByName( aLibName ) && xModLibContImport->isLibraryLink( aLibName ) ) ||
     798           0 :                         ( xDlgLibContImport.is() && xDlgLibContImport->hasByName( aLibName ) && xDlgLibContImport->isLibraryLink( aLibName ) ) ) )
     799             :                 {
     800           0 :                     SvTreeListEntry* pEntry = pLibDlg->GetLibBox().DoInsertEntry( aLibName );
     801           0 :                     sal_uInt16 nPos = (sal_uInt16) pLibDlg->GetLibBox().GetModel()->GetAbsPos( pEntry );
     802           0 :                     pLibDlg->GetLibBox().CheckEntryPos(nPos);
     803             :                 }
     804           0 :             }
     805             : 
     806           0 :             if ( !pLibDlg )
     807           0 :                 MessageDialog(this, IDE_RESSTR(RID_STR_NOLIBINSTORAGE), VCL_MESSAGE_INFO).Execute();
     808             :             else
     809             :             {
     810           0 :                 bool bChanges = false;
     811           0 :                 OUString aExtension( aURLObj.getExtension() );
     812           0 :                 OUString aLibExtension( "xlb" );
     813           0 :                 OUString aContExtension( "xlc" );
     814             : 
     815             :                 // disable reference checkbox for documents and sbls
     816           0 :                 if ( aExtension != aLibExtension && aExtension != aContExtension )
     817           0 :                     pLibDlg->EnableReference(false);
     818             : 
     819           0 :                 if ( pLibDlg->Execute() )
     820             :                 {
     821           0 :                     sal_uLong nNewPos = m_pLibBox->GetEntryCount();
     822           0 :                     bool bRemove = false;
     823           0 :                     bool bReplace = pLibDlg->IsReplace();
     824           0 :                     bool bReference = pLibDlg->IsReference();
     825           0 :                     for ( sal_uInt16 nLib = 0; nLib < pLibDlg->GetLibBox().GetEntryCount(); nLib++ )
     826             :                     {
     827           0 :                         if ( pLibDlg->GetLibBox().IsChecked( nLib ) )
     828             :                         {
     829           0 :                             SvTreeListEntry* pEntry = pLibDlg->GetLibBox().GetEntry( nLib );
     830             :                             DBG_ASSERT( pEntry, "Entry?!" );
     831           0 :                             OUString aLibName( pLibDlg->GetLibBox().GetEntryText( pEntry, 0 ) );
     832           0 :                             Reference< script::XLibraryContainer2 > xModLibContainer( m_aCurDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
     833           0 :                             Reference< script::XLibraryContainer2 > xDlgLibContainer( m_aCurDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY );
     834             : 
     835             :                             // check, if the library is already existing
     836           0 :                             if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) ) ||
     837           0 :                                  ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) ) )
     838             :                             {
     839           0 :                                 if ( bReplace )
     840             :                                 {
     841             :                                     // check, if the library is the Standard library
     842           0 :                                     if ( aLibName == "Standard" )
     843             :                                     {
     844           0 :                                         MessageDialog(this, IDE_RESSTR(RID_STR_REPLACESTDLIB)).Execute();
     845           0 :                                         continue;
     846             :                                     }
     847             : 
     848             :                                     // check, if the library is readonly and not a link
     849           0 :                                     if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) && xModLibContainer->isLibraryReadOnly( aLibName ) && !xModLibContainer->isLibraryLink( aLibName ) ) ||
     850           0 :                                          ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) && xDlgLibContainer->isLibraryReadOnly( aLibName ) && !xDlgLibContainer->isLibraryLink( aLibName ) ) )
     851             :                                     {
     852           0 :                                         OUString aErrStr( IDE_RESSTR(RID_STR_REPLACELIB) );
     853           0 :                                         aErrStr = aErrStr.replaceAll("XX", aLibName);
     854           0 :                                         aErrStr += "\n";
     855           0 :                                         aErrStr += IDE_RESSTR(RID_STR_LIBISREADONLY);
     856           0 :                                         MessageDialog(this, aErrStr).Execute();
     857           0 :                                         continue;
     858             :                                     }
     859             : 
     860             :                                     // remove existing libraries
     861           0 :                                     bRemove = true;
     862             :                                 }
     863             :                                 else
     864             :                                 {
     865           0 :                                     OUString aErrStr;
     866           0 :                                     if ( bReference )
     867           0 :                                         aErrStr = IDE_RESSTR(RID_STR_REFNOTPOSSIBLE);
     868             :                                     else
     869           0 :                                         aErrStr = IDE_RESSTR(RID_STR_IMPORTNOTPOSSIBLE);
     870           0 :                                     aErrStr = aErrStr.replaceAll("XX", aLibName);
     871           0 :                                     aErrStr += "\n" ;
     872           0 :                                     aErrStr += IDE_RESSTR(RID_STR_SBXNAMEALLREADYUSED);
     873           0 :                                     MessageDialog(this, aErrStr).Execute();
     874           0 :                                     continue;
     875             :                                 }
     876             :                             }
     877             : 
     878             :                             // check, if the library is password protected
     879           0 :                             bool bOK = false;
     880           0 :                             OUString aPassword;
     881           0 :                             if ( xModLibContImport.is() && xModLibContImport->hasByName( aLibName ) )
     882             :                             {
     883           0 :                                 Reference< script::XLibraryContainerPassword > xPasswd( xModLibContImport, UNO_QUERY );
     884           0 :                                 if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aLibName ) && !xPasswd->isLibraryPasswordVerified( aLibName ) && !bReference )
     885             :                                 {
     886           0 :                                     bOK = QueryPassword( xModLibContImp, aLibName, aPassword, true, true );
     887             : 
     888           0 :                                     if ( !bOK )
     889             :                                     {
     890           0 :                                         OUString aErrStr( IDE_RESSTR(RID_STR_NOIMPORT) );
     891           0 :                                         aErrStr = aErrStr.replaceAll("XX", aLibName);
     892           0 :                                         MessageDialog(this, aErrStr).Execute();
     893           0 :                                         continue;
     894             :                                     }
     895           0 :                                 }
     896             :                             }
     897             : 
     898             :                             // remove existing libraries
     899           0 :                             if ( bRemove )
     900             :                             {
     901             :                                 // remove listbox entry
     902           0 :                                 SvTreeListEntry* pEntry_ = m_pLibBox->FindEntry( aLibName );
     903           0 :                                 if ( pEntry_ )
     904           0 :                                     m_pLibBox->SvTreeListBox::GetModel()->Remove( pEntry_ );
     905             : 
     906             :                                 // remove module library
     907           0 :                                 if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) )
     908           0 :                                     xModLibContainer->removeLibrary( aLibName );
     909             : 
     910             :                                 // remove dialog library
     911           0 :                                 if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) )
     912           0 :                                     xDlgLibContainer->removeLibrary( aLibName );
     913             :                             }
     914             : 
     915             :                             // copy module library
     916           0 :                             if ( xModLibContImport.is() && xModLibContImport->hasByName( aLibName ) && xModLibContainer.is() && !xModLibContainer->hasByName( aLibName ) )
     917             :                             {
     918           0 :                                 Reference< container::XNameContainer > xModLib;
     919           0 :                                 if ( bReference )
     920             :                                 {
     921             :                                     // storage URL
     922           0 :                                     INetURLObject aModStorageURLObj( aModURLObj );
     923           0 :                                     if ( aExtension == aContExtension )
     924             :                                     {
     925           0 :                                         sal_Int32 nCount = aModStorageURLObj.getSegmentCount();
     926           0 :                                         aModStorageURLObj.insertName( aLibName, false, nCount-1 );
     927           0 :                                         aModStorageURLObj.setExtension( aLibExtension );
     928           0 :                                         aModStorageURLObj.setFinalSlash();
     929             :                                     }
     930           0 :                                     OUString aModStorageURL( aModStorageURLObj.GetMainURL( INetURLObject::NO_DECODE ) );
     931             : 
     932             :                                     // create library link
     933           0 :                                     xModLib = Reference< container::XNameContainer >( xModLibContainer->createLibraryLink( aLibName, aModStorageURL, true ), UNO_QUERY);
     934             :                                 }
     935             :                                 else
     936             :                                 {
     937             :                                     // create library
     938           0 :                                     xModLib = xModLibContainer->createLibrary( aLibName );
     939           0 :                                     if ( xModLib.is() )
     940             :                                     {
     941             :                                         // get import library
     942           0 :                                         Reference< container::XNameContainer > xModLibImport;
     943           0 :                                         Any aElement = xModLibContImport->getByName( aLibName );
     944           0 :                                         aElement >>= xModLibImport;
     945             : 
     946           0 :                                         if ( xModLibImport.is() )
     947             :                                         {
     948             :                                             // load library
     949           0 :                                             if ( !xModLibContImport->isLibraryLoaded( aLibName ) )
     950           0 :                                                 xModLibContImport->loadLibrary( aLibName );
     951             : 
     952             :                                             // copy all modules
     953           0 :                                             Sequence< OUString > aModNames = xModLibImport->getElementNames();
     954           0 :                                             sal_Int32 nModCount = aModNames.getLength();
     955           0 :                                             const OUString* pModNames = aModNames.getConstArray();
     956           0 :                                             for ( sal_Int32 i = 0 ; i < nModCount ; i++ )
     957             :                                             {
     958           0 :                                                 OUString aModName( pModNames[ i ] );
     959           0 :                                                 Any aElement_ = xModLibImport->getByName( aModName );
     960           0 :                                                 xModLib->insertByName( aModName, aElement_ );
     961           0 :                                             }
     962             : 
     963             :                                             // set password
     964           0 :                                             if ( bOK )
     965             :                                             {
     966           0 :                                                 Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
     967           0 :                                                 if ( xPasswd.is() )
     968             :                                                 {
     969             :                                                     try
     970             :                                                     {
     971           0 :                                                         OUString _aPassword( aPassword );
     972           0 :                                                         xPasswd->changeLibraryPassword( aLibName, OUString(), _aPassword );
     973             :                                                     }
     974           0 :                                                     catch (...)
     975             :                                                     {
     976             :                                                     }
     977           0 :                                                 }
     978           0 :                                             }
     979           0 :                                         }
     980             :                                     }
     981           0 :                                 }
     982             :                             }
     983             : 
     984             :                             // copy dialog library
     985           0 :                             if ( xDlgLibContImport.is() && xDlgLibContImport->hasByName( aLibName ) && xDlgLibContainer.is() && !xDlgLibContainer->hasByName( aLibName ) )
     986             :                             {
     987           0 :                                 Reference< container::XNameContainer > xDlgLib;
     988           0 :                                 if ( bReference )
     989             :                                 {
     990             :                                     // storage URL
     991           0 :                                     INetURLObject aDlgStorageURLObj( aDlgURLObj );
     992           0 :                                     if ( aExtension == aContExtension )
     993             :                                     {
     994           0 :                                         sal_Int32 nCount = aDlgStorageURLObj.getSegmentCount();
     995           0 :                                         aDlgStorageURLObj.insertName( aLibName, false, nCount - 1 );
     996           0 :                                         aDlgStorageURLObj.setExtension( aLibExtension );
     997           0 :                                         aDlgStorageURLObj.setFinalSlash();
     998             :                                     }
     999           0 :                                     OUString aDlgStorageURL( aDlgStorageURLObj.GetMainURL( INetURLObject::NO_DECODE ) );
    1000             : 
    1001             :                                     // create library link
    1002           0 :                                     xDlgLib = Reference< container::XNameContainer >( xDlgLibContainer->createLibraryLink( aLibName, aDlgStorageURL, true ), UNO_QUERY);
    1003             :                                 }
    1004             :                                 else
    1005             :                                 {
    1006             :                                     // create library
    1007           0 :                                     xDlgLib = xDlgLibContainer->createLibrary( aLibName );
    1008           0 :                                     if ( xDlgLib.is() )
    1009             :                                     {
    1010             :                                         // get import library
    1011           0 :                                         Reference< container::XNameContainer > xDlgLibImport;
    1012           0 :                                         Any aElement = xDlgLibContImport->getByName( aLibName );
    1013           0 :                                         aElement >>= xDlgLibImport;
    1014             : 
    1015           0 :                                         if ( xDlgLibImport.is() )
    1016             :                                         {
    1017             :                                             // load library
    1018           0 :                                             if ( !xDlgLibContImport->isLibraryLoaded( aLibName ) )
    1019           0 :                                                 xDlgLibContImport->loadLibrary( aLibName );
    1020             : 
    1021             :                                             // copy all dialogs
    1022           0 :                                             Sequence< OUString > aDlgNames = xDlgLibImport->getElementNames();
    1023           0 :                                             sal_Int32 nDlgCount = aDlgNames.getLength();
    1024           0 :                                             const OUString* pDlgNames = aDlgNames.getConstArray();
    1025           0 :                                             for ( sal_Int32 i = 0 ; i < nDlgCount ; i++ )
    1026             :                                             {
    1027           0 :                                                 OUString aDlgName( pDlgNames[ i ] );
    1028           0 :                                                 Any aElement_ = xDlgLibImport->getByName( aDlgName );
    1029           0 :                                                 xDlgLib->insertByName( aDlgName, aElement_ );
    1030           0 :                                             }
    1031           0 :                                         }
    1032             :                                     }
    1033           0 :                                 }
    1034             :                             }
    1035             : 
    1036             :                             // insert listbox entry
    1037           0 :                             ImpInsertLibEntry( aLibName, m_pLibBox->GetEntryCount() );
    1038           0 :                             bChanges = true;
    1039             :                         }
    1040             :                     }
    1041             : 
    1042           0 :                     SvTreeListEntry* pFirstNew = m_pLibBox->GetEntry( nNewPos );
    1043           0 :                     if ( pFirstNew )
    1044           0 :                         m_pLibBox->SetCurEntry( pFirstNew );
    1045             :                 }
    1046             : 
    1047           0 :                 delete pLibDlg;
    1048           0 :                 if ( bChanges )
    1049           0 :                     MarkDocumentModified( m_aCurDocument );
    1050           0 :             }
    1051           0 :         }
    1052           0 :     }
    1053           0 : }
    1054             : 
    1055           0 : void LibPage::Export( void )
    1056             : {
    1057           0 :     SvTreeListEntry* pCurEntry = m_pLibBox->GetCurEntry();
    1058           0 :     OUString aLibName( m_pLibBox->GetEntryText( pCurEntry, 0 ) );
    1059             : 
    1060             :     // Password verification
    1061           0 :     OUString aOULibName( aLibName );
    1062           0 :     Reference< script::XLibraryContainer2 > xModLibContainer( m_aCurDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
    1063             : 
    1064           0 :     if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && !xModLibContainer->isLibraryLoaded( aOULibName ) )
    1065             :     {
    1066           0 :         bool bOK = true;
    1067             : 
    1068             :         // check password
    1069           0 :         Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
    1070           0 :         if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aOULibName ) && !xPasswd->isLibraryPasswordVerified( aOULibName ) )
    1071             :         {
    1072           0 :             OUString aPassword;
    1073           0 :             Reference< script::XLibraryContainer > xModLibContainer1( xModLibContainer, UNO_QUERY );
    1074           0 :             bOK = QueryPassword( xModLibContainer1, aLibName, aPassword );
    1075             :         }
    1076           0 :         if ( !bOK )
    1077           0 :             return;
    1078             :     }
    1079             : 
    1080           0 :     ExportDialog aNewDlg(this);
    1081           0 :     if (aNewDlg.Execute() == RET_OK)
    1082             :     {
    1083             :         try
    1084             :         {
    1085           0 :             if (aNewDlg.isExportAsPackage())
    1086           0 :                 ExportAsPackage( aLibName );
    1087             :             else
    1088           0 :                 ExportAsBasic( aLibName );
    1089             :         }
    1090           0 :         catch(const util::VetoException& ) // user cancled operation
    1091             :         {
    1092             :         }
    1093           0 :     }
    1094             : }
    1095             : 
    1096           0 : void LibPage::implExportLib( const OUString& aLibName, const OUString& aTargetURL,
    1097             :     const Reference< task::XInteractionHandler >& Handler )
    1098             : {
    1099           0 :     OUString aOULibName( aLibName );
    1100             :     Reference< script::XLibraryContainerExport > xModLibContainerExport
    1101           0 :         ( m_aCurDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
    1102             :     Reference< script::XLibraryContainerExport > xDlgLibContainerExport
    1103           0 :         ( m_aCurDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY );
    1104           0 :     if ( xModLibContainerExport.is() )
    1105           0 :         xModLibContainerExport->exportLibrary( aOULibName, aTargetURL, Handler );
    1106             : 
    1107           0 :     if ( xDlgLibContainerExport.is() )
    1108           0 :         xDlgLibContainerExport->exportLibrary( aOULibName, aTargetURL, Handler );
    1109           0 : }
    1110             : 
    1111             : // Implementation XCommandEnvironment
    1112             : typedef cppu::WeakImplHelper1< XCommandEnvironment > LibCommandEnvironmentHelper;
    1113             : 
    1114           0 : class OLibCommandEnvironment : public LibCommandEnvironmentHelper
    1115             : {
    1116             :     Reference< task::XInteractionHandler > mxInteraction;
    1117             : 
    1118             : public:
    1119           0 :     OLibCommandEnvironment( Reference< task::XInteractionHandler > xInteraction )
    1120           0 :         : mxInteraction( xInteraction )
    1121           0 :     {}
    1122             : 
    1123             :     // Methods
    1124             :     virtual Reference< task::XInteractionHandler > SAL_CALL getInteractionHandler()
    1125             :         throw(RuntimeException, std::exception) SAL_OVERRIDE;
    1126             :     virtual Reference< XProgressHandler > SAL_CALL getProgressHandler()
    1127             :         throw(RuntimeException, std::exception) SAL_OVERRIDE;
    1128             : };
    1129             : 
    1130           0 : Reference< task::XInteractionHandler > OLibCommandEnvironment::getInteractionHandler()
    1131             :     throw(RuntimeException, std::exception)
    1132             : {
    1133           0 :     return mxInteraction;
    1134             : }
    1135             : 
    1136           0 : Reference< XProgressHandler > OLibCommandEnvironment::getProgressHandler()
    1137             :     throw(RuntimeException, std::exception)
    1138             : {
    1139           0 :     Reference< XProgressHandler > xRet;
    1140           0 :     return xRet;
    1141             : }
    1142             : 
    1143           0 : void LibPage::ExportAsPackage( const OUString& aLibName )
    1144             : {
    1145             :     // file open dialog
    1146           0 :     Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
    1147           0 :     Reference< task::XInteractionHandler2 > xHandler( task::InteractionHandler::createWithParent(xContext, 0) );
    1148           0 :     Reference< XSimpleFileAccess3 > xSFA = SimpleFileAccess::create(xContext);
    1149             : 
    1150           0 :     Reference < XFilePicker3 > xFP = FilePicker::createWithMode(xContext, TemplateDescription::FILESAVE_SIMPLE);
    1151             : 
    1152           0 :     xFP->setTitle(IDEResId(RID_STR_EXPORTPACKAGE).toString());
    1153             : 
    1154             :     // filter
    1155           0 :     OUString aTitle(IDEResId(RID_STR_PACKAGE_BUNDLE).toString());
    1156           0 :     OUString aFilter;
    1157           0 :     aFilter = "*.oxt" ;       // library files
    1158           0 :     xFP->appendFilter( aTitle, aFilter );
    1159             : 
    1160             :     // set display directory and filter
    1161           0 :     OUString aPath = GetExtraData()->GetAddLibPath();
    1162           0 :     if ( !aPath.isEmpty() )
    1163             :     {
    1164           0 :         xFP->setDisplayDirectory( aPath );
    1165             :     }
    1166             :     else
    1167             :     {
    1168             :         // macro path from configuration management
    1169           0 :         xFP->setDisplayDirectory( SvtPathOptions().GetWorkPath() );
    1170             :     }
    1171           0 :     xFP->setCurrentFilter( aTitle );
    1172             : 
    1173           0 :     if ( xFP->execute() == RET_OK )
    1174             :     {
    1175           0 :         GetExtraData()->SetAddLibPath(xFP->getDisplayDirectory());
    1176             : 
    1177           0 :         Sequence< OUString > aFiles = xFP->getFiles();
    1178           0 :         INetURLObject aURL( aFiles[0] );
    1179           0 :         if( aURL.getExtension().isEmpty() )
    1180           0 :             aURL.setExtension( "oxt" );
    1181             : 
    1182           0 :         OUString aPackageURL( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
    1183             : 
    1184           0 :         OUString aTmpPath = SvtPathOptions().GetTempPath();
    1185           0 :         INetURLObject aInetObj( aTmpPath );
    1186           0 :         aInetObj.insertName( aLibName, true, INetURLObject::LAST_SEGMENT, true, INetURLObject::ENCODE_ALL );
    1187           0 :         OUString aSourcePath = aInetObj.GetMainURL( INetURLObject::NO_DECODE );
    1188           0 :         if( xSFA->exists( aSourcePath ) )
    1189           0 :             xSFA->kill( aSourcePath );
    1190           0 :         Reference< task::XInteractionHandler > xDummyHandler( new DummyInteractionHandler( xHandler ) );
    1191           0 :         implExportLib( aLibName, aTmpPath, xDummyHandler );
    1192             : 
    1193             :         Reference< XCommandEnvironment > xCmdEnv =
    1194             :             static_cast<XCommandEnvironment*>(
    1195             :                 new OLibCommandEnvironment(
    1196             :                     Reference< task::XInteractionHandler >(
    1197           0 :                         xHandler, UNO_QUERY ) ) );
    1198             : 
    1199           0 :         ::ucbhelper::Content sourceContent( aSourcePath, xCmdEnv, comphelper::getProcessComponentContext() );
    1200             : 
    1201           0 :         OUString destFolder = "vnd.sun.star.zip://" +
    1202             :                               ::rtl::Uri::encode( aPackageURL,
    1203             :                                                   rtl_UriCharClassRegName,
    1204             :                                                   rtl_UriEncodeIgnoreEscapes,
    1205           0 :                                                   RTL_TEXTENCODING_UTF8 ) +
    1206           0 :                               "/";
    1207             : 
    1208           0 :         if( xSFA->exists( aPackageURL ) )
    1209           0 :             xSFA->kill( aPackageURL );
    1210             : 
    1211           0 :         ::ucbhelper::Content destFolderContent( destFolder, xCmdEnv, comphelper::getProcessComponentContext() );
    1212             :         destFolderContent.transferContent(
    1213             :             sourceContent, ::ucbhelper::InsertOperation_COPY,
    1214           0 :             OUString(), NameClash::OVERWRITE );
    1215             : 
    1216           0 :         INetURLObject aMetaInfInetObj( aTmpPath );
    1217             :         aMetaInfInetObj.insertName( "META-INF",
    1218           0 :             true, INetURLObject::LAST_SEGMENT, true, INetURLObject::ENCODE_ALL );
    1219           0 :         OUString aMetaInfFolder = aMetaInfInetObj.GetMainURL( INetURLObject::NO_DECODE );
    1220           0 :         if( xSFA->exists( aMetaInfFolder ) )
    1221           0 :             xSFA->kill( aMetaInfFolder );
    1222           0 :         xSFA->createFolder( aMetaInfFolder );
    1223             : 
    1224           0 :         ::std::vector< Sequence<beans::PropertyValue> > manifest;
    1225           0 :         const OUString strMediaType = "MediaType" ;
    1226           0 :         const OUString strFullPath = "FullPath" ;
    1227           0 :         const OUString strBasicMediaType = "application/vnd.sun.star.basic-library" ;
    1228             : 
    1229           0 :         Sequence<beans::PropertyValue> attribs( 2 );
    1230           0 :         beans::PropertyValue * pattribs = attribs.getArray();
    1231           0 :         pattribs[ 0 ].Name = strFullPath;
    1232           0 :         OUString fullPath = aLibName;
    1233           0 :         fullPath += "/" ;
    1234           0 :         pattribs[ 0 ].Value <<= fullPath;
    1235           0 :         pattribs[ 1 ].Name = strMediaType;
    1236           0 :         pattribs[ 1 ].Value <<= strBasicMediaType;
    1237           0 :         manifest.push_back( attribs );
    1238             : 
    1239             :         // write into pipe:
    1240           0 :         Reference<packages::manifest::XManifestWriter> xManifestWriter = packages::manifest::ManifestWriter::create( xContext );
    1241           0 :         Reference<io::XOutputStream> xPipe( io::Pipe::create( xContext ), UNO_QUERY_THROW );
    1242           0 :         xManifestWriter->writeManifestSequence(
    1243             :             xPipe, Sequence< Sequence<beans::PropertyValue> >(
    1244           0 :                 &manifest[ 0 ], manifest.size() ) );
    1245             : 
    1246             :         aMetaInfInetObj.insertName( "manifest.xml",
    1247           0 :             true, INetURLObject::LAST_SEGMENT, true, INetURLObject::ENCODE_ALL );
    1248             : 
    1249             :         // write buffered pipe data to content:
    1250           0 :         ::ucbhelper::Content manifestContent( aMetaInfInetObj.GetMainURL( INetURLObject::NO_DECODE ), xCmdEnv, comphelper::getProcessComponentContext() );
    1251           0 :         manifestContent.writeStream( Reference<io::XInputStream>( xPipe, UNO_QUERY_THROW ), true );
    1252             : 
    1253           0 :         ::ucbhelper::Content MetaInfContent( aMetaInfFolder, xCmdEnv, comphelper::getProcessComponentContext() );
    1254             :         destFolderContent.transferContent(
    1255             :             MetaInfContent, ::ucbhelper::InsertOperation_COPY,
    1256           0 :             OUString(), NameClash::OVERWRITE );
    1257             : 
    1258           0 :         if( xSFA->exists( aSourcePath ) )
    1259           0 :             xSFA->kill( aSourcePath );
    1260           0 :         if( xSFA->exists( aMetaInfFolder ) )
    1261           0 :             xSFA->kill( aMetaInfFolder );
    1262           0 :     }
    1263           0 : }
    1264             : 
    1265           0 : void LibPage::ExportAsBasic( const OUString& aLibName )
    1266             : {
    1267             :     // Folder picker
    1268           0 :     Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
    1269           0 :     Reference< XFolderPicker2 > xFolderPicker = FolderPicker::create(xContext);
    1270           0 :     Reference< task::XInteractionHandler2 > xHandler( task::InteractionHandler::createWithParent(xContext, 0) );
    1271             : 
    1272           0 :     xFolderPicker->setTitle(IDEResId(RID_STR_EXPORTBASIC).toString());
    1273             : 
    1274             :     // set display directory and filter
    1275           0 :     OUString aPath =GetExtraData()->GetAddLibPath();
    1276           0 :     if( aPath.isEmpty() )
    1277           0 :         aPath = SvtPathOptions().GetWorkPath();
    1278             : 
    1279             :     // INetURLObject aURL(m_sSavePath, INET_PROT_FILE);
    1280           0 :     xFolderPicker->setDisplayDirectory( aPath );
    1281           0 :     short nRet = xFolderPicker->execute();
    1282           0 :     if( nRet == RET_OK )
    1283             :     {
    1284           0 :         OUString aTargetURL = xFolderPicker->getDirectory();
    1285           0 :         GetExtraData()->SetAddLibPath(aTargetURL);
    1286             : 
    1287           0 :         Reference< task::XInteractionHandler > xDummyHandler( new DummyInteractionHandler( xHandler ) );
    1288           0 :         implExportLib( aLibName, aTargetURL, xDummyHandler );
    1289           0 :     }
    1290           0 : }
    1291             : 
    1292           0 : void LibPage::DeleteCurrent()
    1293             : {
    1294           0 :     SvTreeListEntry* pCurEntry = m_pLibBox->GetCurEntry();
    1295           0 :     OUString aLibName( m_pLibBox->GetEntryText( pCurEntry, 0 ) );
    1296             : 
    1297             :     // check, if library is link
    1298           0 :     bool bIsLibraryLink = false;
    1299           0 :     OUString aOULibName( aLibName );
    1300           0 :     Reference< script::XLibraryContainer2 > xModLibContainer( m_aCurDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
    1301           0 :     Reference< script::XLibraryContainer2 > xDlgLibContainer( m_aCurDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY );
    1302           0 :     if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryLink( aOULibName ) ) ||
    1303           0 :          ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && xDlgLibContainer->isLibraryLink( aOULibName ) ) )
    1304             :     {
    1305           0 :         bIsLibraryLink = true;
    1306             :     }
    1307             : 
    1308           0 :     if ( QueryDelLib( aLibName, bIsLibraryLink, this ) )
    1309             :     {
    1310             :         // inform BasicIDE
    1311           0 :         SfxUsrAnyItem aDocItem( SID_BASICIDE_ARG_DOCUMENT_MODEL, makeAny( m_aCurDocument.getDocumentOrNull() ) );
    1312           0 :         SfxStringItem aLibNameItem( SID_BASICIDE_ARG_LIBNAME, aLibName );
    1313           0 :         if (SfxDispatcher* pDispatcher = GetDispatcher())
    1314             :             pDispatcher->Execute( SID_BASICIDE_LIBREMOVED,
    1315           0 :                                   SFX_CALLMODE_SYNCHRON, &aDocItem, &aLibNameItem, 0L );
    1316             : 
    1317             :         // remove library from module and dialog library containers
    1318           0 :         if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) )
    1319           0 :             xModLibContainer->removeLibrary( aOULibName );
    1320           0 :         if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) )
    1321           0 :             xDlgLibContainer->removeLibrary( aOULibName );
    1322             : 
    1323           0 :         static_cast<SvTreeListBox&>(*m_pLibBox).GetModel()->Remove( pCurEntry );
    1324           0 :         MarkDocumentModified( m_aCurDocument );
    1325           0 :     }
    1326           0 : }
    1327             : 
    1328           0 : void LibPage::EndTabDialog( sal_uInt16 nRet )
    1329             : {
    1330             :     DBG_ASSERT( pTabDlg, "TabDlg nicht gesetzt!" );
    1331           0 :     if ( pTabDlg )
    1332           0 :         pTabDlg->EndDialog( nRet );
    1333           0 : }
    1334             : 
    1335           0 : void LibPage::FillListBox()
    1336             : {
    1337           0 :     InsertListBoxEntry( ScriptDocument::getApplicationScriptDocument(), LIBRARY_LOCATION_USER );
    1338           0 :     InsertListBoxEntry( ScriptDocument::getApplicationScriptDocument(), LIBRARY_LOCATION_SHARE );
    1339             : 
    1340           0 :     ScriptDocuments aDocuments( ScriptDocument::getAllScriptDocuments( ScriptDocument::DocumentsSorted ) );
    1341           0 :     for (   ScriptDocuments::const_iterator doc = aDocuments.begin();
    1342           0 :             doc != aDocuments.end();
    1343             :             ++doc
    1344             :         )
    1345             :     {
    1346           0 :         InsertListBoxEntry( *doc, LIBRARY_LOCATION_DOCUMENT );
    1347           0 :     }
    1348           0 : }
    1349             : 
    1350           0 : void LibPage::InsertListBoxEntry( const ScriptDocument& rDocument, LibraryLocation eLocation )
    1351             : {
    1352           0 :     OUString aEntryText( rDocument.getTitle( eLocation ) );
    1353           0 :     sal_uInt16 nPos = m_pBasicsBox->InsertEntry( aEntryText, LISTBOX_APPEND );
    1354           0 :     m_pBasicsBox->SetEntryData( nPos, new DocumentEntry(rDocument, eLocation) );
    1355           0 : }
    1356             : 
    1357           0 : void LibPage::SetCurLib()
    1358             : {
    1359           0 :     sal_uInt16 nSelPos = m_pBasicsBox->GetSelectEntryPos();
    1360           0 :     DocumentEntry* pEntry = (DocumentEntry*)m_pBasicsBox->GetEntryData( nSelPos );
    1361           0 :     if ( pEntry )
    1362             :     {
    1363           0 :         ScriptDocument aDocument( pEntry->GetDocument() );
    1364             :         DBG_ASSERT( aDocument.isAlive(), "LibPage::SetCurLib: no document, or document is dead!" );
    1365           0 :         if ( !aDocument.isAlive() )
    1366           0 :             return;
    1367           0 :         LibraryLocation eLocation = pEntry->GetLocation();
    1368           0 :         if ( aDocument != m_aCurDocument || eLocation != m_eCurLocation )
    1369             :         {
    1370           0 :             m_aCurDocument = aDocument;
    1371           0 :             m_eCurLocation = eLocation;
    1372           0 :             m_pLibBox->SetDocument( aDocument );
    1373           0 :             m_pLibBox->Clear();
    1374             : 
    1375             :             // get a sorted list of library names
    1376           0 :             Sequence< OUString > aLibNames = aDocument.getLibraryNames();
    1377           0 :             sal_Int32 nLibCount = aLibNames.getLength();
    1378           0 :             const OUString* pLibNames = aLibNames.getConstArray();
    1379             : 
    1380           0 :             for ( sal_Int32 i = 0 ; i < nLibCount ; i++ )
    1381             :             {
    1382           0 :                 OUString aLibName( pLibNames[ i ] );
    1383           0 :                 if ( eLocation == aDocument.getLibraryLocation( aLibName ) )
    1384           0 :                     ImpInsertLibEntry( aLibName, i );
    1385           0 :             }
    1386             : 
    1387           0 :             SvTreeListEntry* pEntry_ = m_pLibBox->FindEntry( OUString( "Standard" ) );
    1388           0 :             if ( !pEntry_ )
    1389           0 :                 pEntry_ = m_pLibBox->GetEntry( 0 );
    1390           0 :             m_pLibBox->SetCurEntry( pEntry_ );
    1391           0 :         }
    1392             :     }
    1393             : }
    1394             : 
    1395           0 : SvTreeListEntry* LibPage::ImpInsertLibEntry( const OUString& rLibName, sal_uLong nPos )
    1396             : {
    1397             :     // check, if library is password protected
    1398           0 :     bool bProtected = false;
    1399           0 :     OUString aOULibName( rLibName );
    1400           0 :     Reference< script::XLibraryContainer2 > xModLibContainer( m_aCurDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
    1401           0 :     if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) )
    1402             :     {
    1403           0 :         Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
    1404           0 :         if ( xPasswd.is() )
    1405             :         {
    1406           0 :             bProtected = xPasswd->isLibraryPasswordProtected( aOULibName );
    1407           0 :         }
    1408             :     }
    1409             : 
    1410           0 :     SvTreeListEntry* pNewEntry = m_pLibBox->DoInsertEntry( rLibName, nPos );
    1411           0 :     pNewEntry->SetUserData( new LibUserData(m_aCurDocument) );
    1412             : 
    1413           0 :     if (bProtected)
    1414             :     {
    1415           0 :         Image aImage(IDEResId(RID_IMG_LOCKED));
    1416           0 :         m_pLibBox->SetExpandedEntryBmp(pNewEntry, aImage);
    1417           0 :         m_pLibBox->SetCollapsedEntryBmp(pNewEntry, aImage);
    1418             :     }
    1419             : 
    1420             :     // check, if library is link
    1421           0 :     if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryLink( aOULibName ) )
    1422             :     {
    1423           0 :         OUString aLinkURL = xModLibContainer->getLibraryLinkURL( aOULibName );
    1424           0 :         m_pLibBox->SetEntryText( aLinkURL, pNewEntry, 1 );
    1425             :     }
    1426             : 
    1427           0 :     return pNewEntry;
    1428             : }
    1429             : 
    1430             : // Helper function
    1431           0 : void createLibImpl( Window* pWin, const ScriptDocument& rDocument,
    1432             :                     CheckBox* pLibBox, TreeListBox* pBasicBox )
    1433             : {
    1434             :     OSL_ENSURE( rDocument.isAlive(), "createLibImpl: invalid document!" );
    1435           0 :     if ( !rDocument.isAlive() )
    1436           0 :         return;
    1437             : 
    1438             :     // create library name
    1439           0 :     OUString aLibName;
    1440           0 :     OUString aLibStdName( "Library" );
    1441             :     //String aLibStdName( IDEResId( RID_STR_STDLIBNAME ) );
    1442           0 :     bool bValid = false;
    1443           0 :     sal_Int32 i = 1;
    1444           0 :     while ( !bValid )
    1445             :     {
    1446           0 :         aLibName = aLibStdName + OUString::number( i );
    1447           0 :         if ( !rDocument.hasLibrary( E_SCRIPTS, aLibName ) && !rDocument.hasLibrary( E_DIALOGS, aLibName ) )
    1448           0 :             bValid = true;
    1449           0 :         i++;
    1450             :     }
    1451             : 
    1452           0 :     NewObjectDialog aNewDlg(pWin, ObjectMode::Library);
    1453           0 :     aNewDlg.SetObjectName(aLibName);
    1454             : 
    1455           0 :     if (aNewDlg.Execute())
    1456             :     {
    1457           0 :         if (!aNewDlg.GetObjectName().isEmpty())
    1458           0 :             aLibName = aNewDlg.GetObjectName();
    1459             : 
    1460           0 :         if ( aLibName.getLength() > 30 )
    1461             :         {
    1462           0 :             MessageDialog(pWin, IDEResId(RID_STR_LIBNAMETOLONG).toString()).Execute();
    1463             :         }
    1464           0 :         else if ( !IsValidSbxName( aLibName ) )
    1465             :         {
    1466           0 :             MessageDialog(pWin, IDEResId(RID_STR_BADSBXNAME).toString()).Execute();
    1467             :         }
    1468           0 :         else if ( rDocument.hasLibrary( E_SCRIPTS, aLibName ) || rDocument.hasLibrary( E_DIALOGS, aLibName ) )
    1469             :         {
    1470           0 :             MessageDialog(pWin, IDEResId(RID_STR_SBXNAMEALLREADYUSED2).toString()).Execute();
    1471             :         }
    1472             :         else
    1473             :         {
    1474             :             try
    1475             :             {
    1476             :                 // create module and dialog library
    1477           0 :                 Reference< container::XNameContainer > xModLib( rDocument.getOrCreateLibrary( E_SCRIPTS, aLibName ) );
    1478           0 :                 Reference< container::XNameContainer > xDlgLib( rDocument.getOrCreateLibrary( E_DIALOGS, aLibName ) );
    1479             : 
    1480           0 :                 if( pLibBox )
    1481             :                 {
    1482           0 :                     SvTreeListEntry* pEntry = pLibBox->DoInsertEntry( aLibName );
    1483           0 :                     pEntry->SetUserData( new LibUserData( rDocument ) );
    1484           0 :                     pLibBox->SetCurEntry( pEntry );
    1485             :                 }
    1486             : 
    1487             :                 // create a module
    1488           0 :                 OUString aModName = rDocument.createObjectName( E_SCRIPTS, aLibName );
    1489           0 :                 OUString sModuleCode;
    1490           0 :                 if ( !rDocument.createModule( aLibName, aModName, true, sModuleCode ) )
    1491           0 :                     throw Exception();
    1492             : 
    1493           0 :                 SbxItem aSbxItem( SID_BASICIDE_ARG_SBX, rDocument, aLibName, aModName, TYPE_MODULE );
    1494           0 :                 if (SfxDispatcher* pDispatcher = GetDispatcher())
    1495             :                     pDispatcher->Execute( SID_BASICIDE_SBXINSERTED,
    1496           0 :                                           SFX_CALLMODE_SYNCHRON, &aSbxItem, 0L );
    1497             : 
    1498           0 :                 if( pBasicBox )
    1499             :                 {
    1500           0 :                     SvTreeListEntry* pEntry = pBasicBox->GetCurEntry();
    1501           0 :                     SvTreeListEntry* pRootEntry = NULL;
    1502           0 :                     while( pEntry )
    1503             :                     {
    1504           0 :                         pRootEntry = pEntry;
    1505           0 :                         pEntry = pBasicBox->GetParent( pEntry );
    1506             :                     }
    1507             : 
    1508           0 :                     sal_uInt16 nMode = pBasicBox->GetMode();
    1509           0 :                     bool bDlgMode = ( nMode & BROWSEMODE_DIALOGS ) && !( nMode & BROWSEMODE_MODULES );
    1510           0 :                     sal_uInt16 nId = bDlgMode ? RID_IMG_DLGLIB : RID_IMG_MODLIB;
    1511           0 :                     o3tl::heap_ptr<Entry> e(new Entry(OBJ_TYPE_LIBRARY));
    1512             :                     SvTreeListEntry* pNewLibEntry = pBasicBox->AddEntry(
    1513             :                         aLibName,
    1514             :                         Image( IDEResId( nId ) ),
    1515           0 :                         pRootEntry, false, &e);
    1516             :                     DBG_ASSERT( pNewLibEntry, "InsertEntry fehlgeschlagen!" );
    1517             : 
    1518           0 :                     if( pNewLibEntry )
    1519             :                     {
    1520           0 :                         o3tl::heap_ptr<Entry>(new Entry(OBJ_TYPE_MODULE));
    1521             :                         SvTreeListEntry* pEntry_ = pBasicBox->AddEntry(
    1522             :                             aModName,
    1523             :                             Image( IDEResId( RID_IMG_MODULE ) ),
    1524           0 :                             pNewLibEntry, false, &e);
    1525             :                         DBG_ASSERT( pEntry_, "InsertEntry fehlgeschlagen!" );
    1526           0 :                         pBasicBox->SetCurEntry( pEntry_ );
    1527           0 :                         pBasicBox->Select( pBasicBox->GetCurEntry() );      // OV-Bug?!
    1528           0 :                     }
    1529           0 :                 }
    1530             :             }
    1531           0 :             catch (const uno::Exception& )
    1532             :             {
    1533             :                 DBG_UNHANDLED_EXCEPTION();
    1534             :             }
    1535             :         }
    1536           0 :     }
    1537             : }
    1538           0 : } // namespace basctl
    1539             : 
    1540             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10