LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/cui/source/dialogs - scriptdlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 729 0.0 %
Date: 2013-07-09 Functions: 0 55 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 <memory>
      21             : 
      22             : #include <sfx2/objsh.hxx>
      23             : #include <vcl/svapp.hxx>
      24             : #include <vcl/msgbox.hxx>
      25             : #include <osl/mutex.hxx>
      26             : 
      27             : #include <cuires.hrc>
      28             : #include "scriptdlg.hrc"
      29             : #include "scriptdlg.hxx"
      30             : #include <dialmgr.hxx>
      31             : #include "selector.hxx"
      32             : 
      33             : #include <com/sun/star/uno/XComponentContext.hpp>
      34             : #include <com/sun/star/frame/XDesktop.hpp>
      35             : #include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
      36             : #include <com/sun/star/script/provider/XScriptProvider.hpp>
      37             : #include <com/sun/star/script/browse/BrowseNodeTypes.hpp>
      38             : #include <com/sun/star/script/browse/XBrowseNodeFactory.hpp>
      39             : #include <com/sun/star/script/browse/BrowseNodeFactoryViewTypes.hpp>
      40             : #include <com/sun/star/script/browse/theBrowseNodeFactory.hpp>
      41             : #include <com/sun/star/script/provider/ScriptErrorRaisedException.hpp>
      42             : #include <com/sun/star/script/provider/ScriptExceptionRaisedException.hpp>
      43             : #include <com/sun/star/script/provider/ScriptFrameworkErrorType.hpp>
      44             : #include <com/sun/star/frame/Desktop.hpp>
      45             : #include <com/sun/star/frame/ModuleManager.hpp>
      46             : #include <com/sun/star/script/XInvocation.hpp>
      47             : #include <com/sun/star/document/XEmbeddedScripts.hpp>
      48             : 
      49             : #include <cppuhelper/implbase1.hxx>
      50             : #include <comphelper/documentinfo.hxx>
      51             : #include <comphelper/uno3.hxx>
      52             : #include <comphelper/processfactory.hxx>
      53             : #include <comphelper/broadcasthelper.hxx>
      54             : #include <comphelper/propertycontainer.hxx>
      55             : #include <comphelper/proparrhlp.hxx>
      56             : 
      57             : #include <basic/sbx.hxx>
      58             : #include <svtools/imagemgr.hxx>
      59             : #include "svtools/treelistentry.hxx"
      60             : #include <tools/urlobj.hxx>
      61             : #include <vector>
      62             : #include <algorithm>
      63             : 
      64             : using namespace ::com::sun::star;
      65             : using namespace ::com::sun::star::uno;
      66             : using namespace ::com::sun::star::script;
      67             : using namespace ::com::sun::star::frame;
      68             : using namespace ::com::sun::star::document;
      69             : 
      70           0 : void ShowErrorDialog( const Any& aException )
      71             : {
      72           0 :     SvxScriptErrorDialog* pDlg = new SvxScriptErrorDialog( NULL, aException );
      73           0 :     pDlg->Execute();
      74           0 :     delete pDlg;
      75           0 : }
      76             : 
      77           0 : SFTreeListBox::SFTreeListBox(Window* pParent)
      78             :     : SvTreeListBox(pParent)
      79           0 :     , m_hdImage(CUI_RES(RID_CUIIMG_HARDDISK))
      80           0 :     , m_libImage(CUI_RES(RID_CUIIMG_LIB))
      81           0 :     , m_macImage(CUI_RES(RID_CUIIMG_MACRO))
      82           0 :     , m_docImage(CUI_RES(RID_CUIIMG_DOC))
      83           0 :     , m_sMyMacros(CUI_RESSTR(RID_SVXSTR_MYMACROS))
      84           0 :     , m_sProdMacros(CUI_RESSTR(RID_SVXSTR_PRODMACROS))
      85             : {
      86           0 :     SetSelectionMode( SINGLE_SELECTION );
      87             : 
      88           0 :     SetStyle( GetStyle() | WB_CLIPCHILDREN | WB_HSCROLL |
      89             :                    WB_HASBUTTONS | WB_HASBUTTONSATROOT | WB_HIDESELECTION |
      90           0 :                    WB_HASLINES | WB_HASLINESATROOT | WB_TABSTOP );
      91           0 :     SetNodeDefaultImages();
      92             : 
      93           0 :     nMode = 0xFF;    // everything
      94           0 : }
      95             : 
      96           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSFTreeListBox(Window *pParent, VclBuilder::stringmap &)
      97             : {
      98           0 :     return new SFTreeListBox(pParent);
      99             : }
     100             : 
     101           0 : SFTreeListBox::~SFTreeListBox()
     102             : {
     103           0 :     deleteAllTree();
     104           0 : }
     105             : 
     106           0 : void SFTreeListBox::delUserData( SvTreeListEntry* pEntry )
     107             : {
     108           0 :     if ( pEntry )
     109             :     {
     110           0 :         SFEntry* pUserData = (SFEntry*)pEntry->GetUserData();
     111           0 :         if ( pUserData )
     112             :         {
     113           0 :             delete pUserData;
     114             :             // TBD seem to get a Select event on node that is remove ( below )
     115             :             // so need to be able to detect that this node is not to be
     116             :             // processed in order to do this, setting userData to NULL ( must
     117             :             // be a better way to do this )
     118           0 :             pUserData = 0;
     119           0 :             pEntry->SetUserData( pUserData );
     120             :         }
     121             :     }
     122           0 : }
     123             : 
     124           0 : void SFTreeListBox::deleteTree( SvTreeListEntry* pEntry )
     125             : {
     126             : 
     127           0 :     delUserData( pEntry );
     128           0 :     pEntry = FirstChild( pEntry );
     129           0 :     while ( pEntry )
     130             :     {
     131           0 :         SvTreeListEntry* pNextEntry = NextSibling( pEntry );
     132           0 :         deleteTree( pEntry );
     133           0 :         GetModel()->Remove( pEntry );
     134           0 :         pEntry = pNextEntry;
     135             :     }
     136           0 : }
     137             : 
     138           0 : void SFTreeListBox::deleteAllTree()
     139             : {
     140           0 :     SvTreeListEntry* pEntry =  GetEntry( 0 );
     141             : 
     142             :     // TBD - below is a candidate for a destroyAllTrees method
     143           0 :     if ( pEntry )
     144             :     {
     145           0 :         while ( pEntry )
     146             :         {
     147           0 :             SvTreeListEntry* pNextEntry = NextSibling( pEntry ) ;
     148           0 :             deleteTree( pEntry );
     149           0 :             GetModel()->Remove( pEntry );
     150           0 :             pEntry = pNextEntry;
     151             :         }
     152             :     }
     153           0 : }
     154             : 
     155           0 : void SFTreeListBox::Init( const OUString& language  )
     156             : {
     157           0 :     SetUpdateMode( sal_False );
     158             : 
     159           0 :     deleteAllTree();
     160             : 
     161           0 :     Reference< browse::XBrowseNode > rootNode;
     162             :     Reference< XComponentContext > xCtx(
     163           0 :         comphelper::getProcessComponentContext() );
     164             : 
     165           0 :     Sequence< Reference< browse::XBrowseNode > > children;
     166             : 
     167           0 :     OUString userStr("user");
     168           0 :     OUString shareStr("share");
     169             : 
     170             :     try
     171             :     {
     172           0 :         Reference< browse::XBrowseNodeFactory > xFac = browse::theBrowseNodeFactory::get(xCtx);
     173             : 
     174           0 :         rootNode.set( xFac->createView(
     175           0 :             browse::BrowseNodeFactoryViewTypes::MACROORGANIZER ) );
     176             : 
     177           0 :         if (  rootNode.is() && rootNode->hasChildNodes() == sal_True )
     178             :         {
     179           0 :             children = rootNode->getChildNodes();
     180           0 :         }
     181             :     }
     182           0 :     catch( Exception& e )
     183             :     {
     184             :         OSL_TRACE("Exception getting root browse node from factory: %s",
     185             :             OUStringToOString(
     186             :                 e.Message , RTL_TEXTENCODING_ASCII_US ).pData->buffer );
     187             :         // TODO exception handling
     188             :     }
     189             : 
     190           0 :     Reference<XModel> xDocumentModel;
     191           0 :     for ( sal_Int32 n = 0; n < children.getLength(); n++ )
     192             :     {
     193           0 :         bool app = false;
     194           0 :         OUString uiName = children[ n ]->getName();
     195           0 :         OUString factoryURL;
     196           0 :         if ( uiName.equals( userStr ) || uiName.equals( shareStr ) )
     197             :         {
     198           0 :             app = true;
     199           0 :             if ( uiName.equals( userStr ) )
     200             :             {
     201           0 :                 uiName = m_sMyMacros;
     202             :             }
     203             :             else
     204             :             {
     205           0 :                 uiName = m_sProdMacros;
     206             :             }
     207             :         }
     208             :         else
     209             :         {
     210           0 :             xDocumentModel.set(getDocumentModel(xCtx, uiName ), UNO_QUERY);
     211             : 
     212           0 :             if ( xDocumentModel.is() )
     213             :             {
     214           0 :                 Reference< frame::XModuleManager2 > xModuleManager( frame::ModuleManager::create(xCtx) );
     215             : 
     216             :                 // get the long name of the document:
     217           0 :                 Sequence<beans::PropertyValue> moduleDescr;
     218             :                 try{
     219           0 :                     OUString appModule = xModuleManager->identify( xDocumentModel );
     220           0 :                     xModuleManager->getByName(appModule) >>= moduleDescr;
     221           0 :                 } catch(const uno::Exception&)
     222             :                     {}
     223             : 
     224             :                 beans::PropertyValue const * pmoduleDescr =
     225           0 :                     moduleDescr.getConstArray();
     226           0 :                 for ( sal_Int32 pos = moduleDescr.getLength(); pos--; )
     227             :                 {
     228           0 :                     if ( pmoduleDescr[ pos ].Name == "ooSetupFactoryEmptyDocumentURL" )
     229             :                     {
     230           0 :                         pmoduleDescr[ pos ].Value >>= factoryURL;
     231           0 :                         break;
     232             :                     }
     233           0 :                 }
     234             :             }
     235             :         }
     236             : 
     237           0 :         OUString lang( language );
     238             :         Reference< browse::XBrowseNode > langEntries =
     239           0 :             getLangNodeFromRootNode( children[ n ], lang );
     240             : 
     241             :         SAL_WNODEPRECATED_DECLARATIONS_PUSH
     242             :         insertEntry( uiName, app ? RID_CUIIMG_HARDDISK : RID_CUIIMG_DOC,
     243           0 :             0, true, std::auto_ptr< SFEntry >(new SFEntry( OBJTYPE_SFROOT, langEntries, xDocumentModel )), factoryURL );
     244             :         SAL_WNODEPRECATED_DECLARATIONS_POP
     245           0 :     }
     246             : 
     247           0 :     SetUpdateMode( sal_True );
     248           0 : }
     249             : 
     250             : Reference< XInterface  >
     251           0 : SFTreeListBox::getDocumentModel( Reference< XComponentContext >& xCtx, OUString& docName )
     252             : {
     253           0 :     Reference< XInterface > xModel;
     254           0 :     Reference< frame::XDesktop2 > desktop  = frame::Desktop::create(xCtx);
     255             : 
     256             :     Reference< container::XEnumerationAccess > componentsAccess =
     257           0 :         desktop->getComponents();
     258             :     Reference< container::XEnumeration > components =
     259           0 :         componentsAccess->createEnumeration();
     260           0 :     while (components->hasMoreElements())
     261             :     {
     262             :         Reference< frame::XModel > model(
     263           0 :             components->nextElement(), UNO_QUERY );
     264           0 :         if ( model.is() )
     265             :         {
     266           0 :             OUString sTdocUrl = ::comphelper::DocumentInfo::getDocumentTitle( model );
     267           0 :             if( sTdocUrl.equals( docName ) )
     268             :             {
     269           0 :                 xModel = model;
     270           0 :                 break;
     271           0 :             }
     272             :         }
     273           0 :     }
     274           0 :     return xModel;
     275             : }
     276             : 
     277             : Reference< browse::XBrowseNode >
     278           0 : SFTreeListBox::getLangNodeFromRootNode( Reference< browse::XBrowseNode >& rootNode, OUString& language )
     279             : {
     280           0 :     Reference< browse::XBrowseNode > langNode;
     281             : 
     282             :     try
     283             :     {
     284           0 :         Sequence < Reference< browse::XBrowseNode > > children = rootNode->getChildNodes();
     285           0 :         for ( sal_Int32 n = 0; n < children.getLength(); n++ )
     286             :         {
     287           0 :             if ( children[ n ]->getName().equals( language ) )
     288             :             {
     289           0 :                 langNode = children[ n ];
     290           0 :                 break;
     291             :             }
     292           0 :         }
     293             :     }
     294           0 :     catch ( Exception& )
     295             :     {
     296             :         // if getChildNodes() throws an exception we just return
     297             :         // the empty Reference
     298             :     }
     299           0 :     return langNode;
     300             : }
     301             : 
     302           0 : void SFTreeListBox:: RequestSubEntries( SvTreeListEntry* pRootEntry, Reference< ::com::sun::star::script::browse::XBrowseNode >& node,
     303             :                                        Reference< XModel >& model )
     304             : {
     305           0 :     if (! node.is() )
     306             :     {
     307           0 :         return;
     308             :     }
     309             : 
     310           0 :     Sequence< Reference< browse::XBrowseNode > > children;
     311             :     try
     312             :     {
     313           0 :         children = node->getChildNodes();
     314             :     }
     315           0 :     catch ( Exception& )
     316             :     {
     317             :         // if we catch an exception in getChildNodes then no entries are added
     318             :     }
     319             : 
     320           0 :     for ( sal_Int32 n = 0; n < children.getLength(); n++ )
     321             :     {
     322           0 :         OUString name( children[ n ]->getName() );
     323           0 :         if (  children[ n ]->getType() !=  browse::BrowseNodeTypes::SCRIPT)
     324             :         {
     325             :             SAL_WNODEPRECATED_DECLARATIONS_PUSH
     326           0 :             insertEntry( name, RID_CUIIMG_LIB, pRootEntry, true, std::auto_ptr< SFEntry >(new SFEntry( OBJTYPE_SCRIPTCONTAINER, children[ n ],model )));
     327             :             SAL_WNODEPRECATED_DECLARATIONS_POP
     328             :         }
     329             :         else
     330             :         {
     331           0 :             if ( children[ n ]->getType() == browse::BrowseNodeTypes::SCRIPT )
     332             :             {
     333             :                 SAL_WNODEPRECATED_DECLARATIONS_PUSH
     334           0 :                 insertEntry( name, RID_CUIIMG_MACRO, pRootEntry, false, std::auto_ptr< SFEntry >(new SFEntry( OBJTYPE_METHOD, children[ n ],model )));
     335             :                 SAL_WNODEPRECATED_DECLARATIONS_POP
     336             : 
     337             :             }
     338             :         }
     339           0 :     }
     340             : }
     341             : 
     342           0 : long SFTreeListBox::ExpandingHdl()
     343             : {
     344           0 :     return sal_True;
     345             : }
     346             : 
     347           0 : void SFTreeListBox::ExpandAllTrees()
     348             : {
     349           0 : }
     350             : 
     351             : SAL_WNODEPRECATED_DECLARATIONS_PUSH
     352           0 : SvTreeListEntry * SFTreeListBox::insertEntry(
     353             :     String const & rText, sal_uInt16 nBitmap, SvTreeListEntry * pParent,
     354             :     bool bChildrenOnDemand, std::auto_ptr< SFEntry > aUserData, OUString factoryURL )
     355             : {
     356             :     SvTreeListEntry * p;
     357           0 :     if( nBitmap == RID_CUIIMG_DOC && !factoryURL.isEmpty() )
     358             :     {
     359           0 :         Image aImage = SvFileInformationManager::GetFileImage( INetURLObject(factoryURL), false );
     360             :         p = InsertEntry(
     361             :             rText, aImage, aImage, pParent, bChildrenOnDemand, LIST_APPEND,
     362           0 :             aUserData.release()); // XXX possible leak
     363             :     }
     364             :     else
     365             :     {
     366           0 :         p = insertEntry( rText, nBitmap, pParent, bChildrenOnDemand, aUserData );
     367             :     }
     368           0 :     return p;
     369             : }
     370             : SAL_WNODEPRECATED_DECLARATIONS_POP
     371             : 
     372             : SAL_WNODEPRECATED_DECLARATIONS_PUSH
     373           0 : SvTreeListEntry * SFTreeListBox::insertEntry(
     374             :     String const & rText, sal_uInt16 nBitmap, SvTreeListEntry * pParent,
     375             :     bool bChildrenOnDemand, std::auto_ptr< SFEntry > aUserData )
     376             : {
     377           0 :     Image aImage;
     378           0 :     if( nBitmap == RID_CUIIMG_HARDDISK )
     379             :     {
     380           0 :         aImage = m_hdImage;
     381             :     }
     382           0 :     else if( nBitmap == RID_CUIIMG_LIB )
     383             :     {
     384           0 :         aImage = m_libImage;
     385             :     }
     386           0 :     else if( nBitmap == RID_CUIIMG_MACRO )
     387             :     {
     388           0 :         aImage = m_macImage;
     389             :     }
     390           0 :     else if( nBitmap == RID_CUIIMG_DOC )
     391             :     {
     392           0 :         aImage = m_docImage;
     393             :     }
     394             :     SvTreeListEntry * p = InsertEntry(
     395             :         rText, aImage, aImage, pParent, bChildrenOnDemand, LIST_APPEND,
     396           0 :         aUserData.release()); // XXX possible leak
     397           0 :    return p;
     398             : }
     399             : SAL_WNODEPRECATED_DECLARATIONS_POP
     400             : 
     401           0 : void SFTreeListBox::RequestingChildren( SvTreeListEntry* pEntry )
     402             : {
     403           0 :     SFEntry* userData = 0;
     404           0 :     if ( !pEntry )
     405             :     {
     406           0 :         return;
     407             :     }
     408           0 :     userData = (SFEntry*)pEntry->GetUserData();
     409             : 
     410           0 :     Reference< browse::XBrowseNode > node;
     411           0 :     Reference< XModel > model;
     412           0 :     if ( userData && !userData->isLoaded() )
     413             :     {
     414           0 :         node = userData->GetNode();
     415           0 :         model = userData->GetModel();
     416           0 :         RequestSubEntries( pEntry, node, model );
     417           0 :         userData->setLoaded();
     418           0 :     }
     419             : }
     420             : 
     421           0 : void SFTreeListBox::ExpandedHdl()
     422             : {
     423           0 : }
     424             : 
     425             : // ----------------------------------------------------------------------------
     426             : // CuiInputDialog ------------------------------------------------------------
     427             : // ----------------------------------------------------------------------------
     428           0 : CuiInputDialog::CuiInputDialog(Window * pParent, sal_uInt16 nMode )
     429           0 :     : ModalDialog( pParent, CUI_RES( RID_DLG_NEWLIB ) ),
     430           0 :         aText( this, CUI_RES( FT_NEWLIB ) ),
     431           0 :         aEdit( this, CUI_RES( ED_LIBNAME ) ),
     432           0 :         aOKButton( this, CUI_RES( PB_OK ) ),
     433           0 :         aCancelButton( this, CUI_RES( PB_CANCEL ) )
     434             : {
     435           0 :     aEdit.GrabFocus();
     436           0 :     if ( nMode == INPUTMODE_NEWLIB )
     437             :     {
     438           0 :         SetText( String( CUI_RES( STR_NEWLIB ) ) );
     439             :     }
     440           0 :     else if ( nMode == INPUTMODE_NEWMACRO )
     441             :     {
     442           0 :         SetText( String( CUI_RES( STR_NEWMACRO ) ) );
     443           0 :         aText.SetText( String( CUI_RES( STR_FT_NEWMACRO ) ) );
     444             :     }
     445           0 :     else if ( nMode == INPUTMODE_RENAME )
     446             :     {
     447           0 :         SetText( String( CUI_RES( STR_RENAME ) ) );
     448           0 :         aText.SetText( String( CUI_RES( STR_FT_RENAME ) ) );
     449             :     }
     450           0 :     FreeResource();
     451             : 
     452             :     // some resizing so that the text fits
     453           0 :     Point point, newPoint;
     454           0 :     Size siz, newSiz;
     455             :     long gap;
     456             : 
     457             :     sal_uInt16 style = TEXT_DRAW_MULTILINE | TEXT_DRAW_TOP |
     458           0 :                    TEXT_DRAW_LEFT | TEXT_DRAW_WORDBREAK;
     459             : 
     460             :     // get dimensions of dialog instructions control
     461           0 :     point = aText.GetPosPixel();
     462           0 :     siz = aText.GetSizePixel();
     463             : 
     464             :     // get dimensions occupied by text in the control
     465             :     Rectangle rect =
     466           0 :         GetTextRect( Rectangle( point, siz ), aText.GetText(), style );
     467           0 :     newSiz = rect.GetSize();
     468             : 
     469             :     // the gap is the difference between the text width and its control width
     470           0 :     gap = siz.Height() - newSiz.Height();
     471             : 
     472             :     //resize the text field
     473           0 :     newSiz = Size( siz.Width(), siz.Height() - gap );
     474           0 :     aText.SetSizePixel( newSiz );
     475             : 
     476             :     //move the OK & cancel buttons
     477           0 :     point = aEdit.GetPosPixel();
     478           0 :     newPoint = Point( point.X(), point.Y() - gap );
     479           0 :     aEdit.SetPosPixel( newPoint );
     480             : 
     481           0 : }
     482             : 
     483           0 : CuiInputDialog::~CuiInputDialog()
     484             : {
     485           0 : }
     486             : // ----------------------------------------------------------------------------
     487             : // ScriptOrgDialog ------------------------------------------------------------
     488             : // ----------------------------------------------------------------------------
     489           0 : SvxScriptOrgDialog::SvxScriptOrgDialog( Window* pParent, OUString language )
     490             :     : SfxModalDialog(pParent, "ScriptOrganizerDialog", "cui/ui/scriptorganizer.ui")
     491             :     , m_sLanguage(language)
     492           0 :     , m_delErrStr(CUI_RESSTR(RID_SVXSTR_DELFAILED))
     493           0 :     , m_delErrTitleStr(CUI_RESSTR(RID_SVXSTR_DELFAILED_TITLE))
     494           0 :     , m_delQueryStr(CUI_RES(RID_SVXSTR_DELQUERY))
     495           0 :     , m_delQueryTitleStr(CUI_RESSTR(RID_SVXSTR_DELQUERY_TITLE))
     496           0 :     , m_createErrStr(CUI_RESSTR(RID_SVXSTR_CREATEFAILED))
     497           0 :     , m_createDupStr(CUI_RESSTR(RID_SVXSTR_CREATEFAILEDDUP))
     498           0 :     , m_createErrTitleStr(CUI_RESSTR(RID_SVXSTR_CREATEFAILED_TITLE))
     499           0 :     , m_renameErrStr(CUI_RESSTR(RID_SVXSTR_RENAMEFAILED))
     500           0 :     , m_renameErrTitleStr(CUI_RESSTR(RID_SVXSTR_RENAMEFAILED_TITLE))
     501             : {
     502           0 :     get(m_pScriptsBox, "scripts");
     503           0 :     get(m_pRunButton, "run");
     504           0 :     get(m_pCloseButton, "close");
     505           0 :     get(m_pCreateButton, "create");
     506           0 :     get(m_pEditButton, "edit");
     507           0 :     get(m_pRenameButton, "rename");
     508           0 :     get(m_pDelButton, "delete");
     509             :     // must be a neater way to deal with the strings than as above
     510             :     // append the language to the dialog title
     511           0 :     String winTitle( GetText() );
     512           0 :     winTitle.SearchAndReplace( OUString( "%MACROLANG" ), m_sLanguage );
     513           0 :     SetText( winTitle );
     514             : 
     515           0 :     m_pScriptsBox->SetSelectHdl( LINK( this, SvxScriptOrgDialog, ScriptSelectHdl ) );
     516           0 :     m_pRunButton->SetClickHdl( LINK( this, SvxScriptOrgDialog, ButtonHdl ) );
     517           0 :     m_pCloseButton->SetClickHdl( LINK( this, SvxScriptOrgDialog, ButtonHdl ) );
     518           0 :     m_pRenameButton->SetClickHdl( LINK( this, SvxScriptOrgDialog, ButtonHdl ) );
     519           0 :     m_pEditButton->SetClickHdl( LINK( this, SvxScriptOrgDialog, ButtonHdl ) );
     520           0 :     m_pDelButton->SetClickHdl( LINK( this, SvxScriptOrgDialog, ButtonHdl ) );
     521           0 :     m_pCreateButton->SetClickHdl( LINK( this, SvxScriptOrgDialog, ButtonHdl ) );
     522             : 
     523           0 :     m_pRunButton->Disable();
     524           0 :     m_pRenameButton->Disable();
     525           0 :     m_pEditButton->Disable();
     526           0 :     m_pDelButton->Disable();
     527           0 :     m_pCreateButton->Disable();
     528             : 
     529           0 :     m_pScriptsBox->Init( m_sLanguage );
     530           0 :     RestorePreviousSelection();
     531           0 : }
     532             : 
     533           0 : SvxScriptOrgDialog::~SvxScriptOrgDialog()
     534             : {
     535             :     // clear the SelectHdl so that it isn't called during the dtor
     536           0 :     m_pScriptsBox->SetSelectHdl( Link() );
     537           0 : };
     538             : 
     539           0 : short SvxScriptOrgDialog::Execute()
     540             : {
     541             : 
     542           0 :     SfxObjectShell *pDoc = SfxObjectShell::GetFirst();
     543             : 
     544             :     // force load of MSPs for all documents
     545           0 :     while ( pDoc )
     546             :     {
     547             :         Reference< provider::XScriptProviderSupplier > xSPS =
     548             :             Reference< provider::XScriptProviderSupplier >
     549           0 :                                         ( pDoc->GetModel(), UNO_QUERY );
     550           0 :         if ( xSPS.is() )
     551             :         {
     552             :             Reference< provider::XScriptProvider > ScriptProvider =
     553           0 :             xSPS->getScriptProvider();
     554             :         }
     555             : 
     556           0 :         pDoc = SfxObjectShell::GetNext(*pDoc);
     557           0 :     }
     558           0 :     m_pScriptsBox->ExpandAllTrees();
     559             : 
     560           0 :     Window* pPrevDlgParent = Application::GetDefDialogParent();
     561           0 :     Application::SetDefDialogParent( this );
     562           0 :     short nRet = ModalDialog::Execute();
     563           0 :     Application::SetDefDialogParent( pPrevDlgParent );
     564           0 :     return nRet;
     565             : }
     566             : 
     567           0 : void SvxScriptOrgDialog::CheckButtons( Reference< browse::XBrowseNode >& node )
     568             : {
     569           0 :     if ( node.is() )
     570             :     {
     571           0 :         if ( node->getType() == browse::BrowseNodeTypes::SCRIPT)
     572             :         {
     573           0 :             m_pRunButton->Enable();
     574             :         }
     575             :         else
     576             :         {
     577           0 :             m_pRunButton->Disable();
     578             :         }
     579           0 :         Reference< beans::XPropertySet > xProps( node, UNO_QUERY );
     580             : 
     581           0 :         if ( !xProps.is() )
     582             :         {
     583           0 :             m_pEditButton->Disable();
     584           0 :             m_pDelButton->Disable();
     585           0 :             m_pCreateButton->Disable();
     586           0 :             m_pRunButton->Disable();
     587           0 :             return;
     588             :         }
     589             : 
     590           0 :         OUString sName("Editable")  ;
     591             : 
     592           0 :         if ( getBoolProperty( xProps, sName ) )
     593             :         {
     594           0 :             m_pEditButton->Enable();
     595             :         }
     596             :         else
     597             :         {
     598           0 :             m_pEditButton->Disable();
     599             :         }
     600             : 
     601           0 :         sName = OUString("Deletable")  ;
     602             : 
     603           0 :         if ( getBoolProperty( xProps, sName ) )
     604             :         {
     605           0 :             m_pDelButton->Enable();
     606             :         }
     607             :         else
     608             :         {
     609           0 :             m_pDelButton->Disable();
     610             :         }
     611             : 
     612           0 :         sName = OUString("Creatable")  ;
     613             : 
     614           0 :         if ( getBoolProperty( xProps, sName ) )
     615             :         {
     616           0 :             m_pCreateButton->Enable();
     617             :         }
     618             :         else
     619             :         {
     620           0 :             m_pCreateButton->Disable();
     621             :         }
     622             : 
     623           0 :         sName = OUString("Renamable")  ;
     624             : 
     625           0 :         if ( getBoolProperty( xProps, sName ) )
     626             :         {
     627           0 :             m_pRenameButton->Enable();
     628             :         }
     629             :         else
     630             :         {
     631           0 :             m_pRenameButton->Disable();
     632           0 :         }
     633             :     }
     634             :     else
     635             :     {
     636             :         // no node info available, disable all configurable actions
     637           0 :         m_pDelButton->Disable();
     638           0 :         m_pCreateButton->Disable();
     639           0 :         m_pEditButton->Disable();
     640           0 :         m_pRunButton->Disable();
     641           0 :         m_pRenameButton->Disable();
     642             :     }
     643             : }
     644             : 
     645           0 : IMPL_LINK( SvxScriptOrgDialog, ScriptSelectHdl, SvTreeListBox *, pBox )
     646             : {
     647           0 :     if ( !pBox->IsSelected( pBox->GetHdlEntry() ) )
     648             :     {
     649           0 :         return 0;
     650             :     }
     651             : 
     652           0 :     SvTreeListEntry* pEntry = pBox->GetHdlEntry();
     653             : 
     654           0 :     SFEntry* userData = 0;
     655           0 :     if ( !pEntry )
     656             :     {
     657           0 :         return 0;
     658             :     }
     659           0 :     userData = (SFEntry*)pEntry->GetUserData();
     660             : 
     661           0 :     Reference< browse::XBrowseNode > node;
     662           0 :     if ( userData )
     663             :     {
     664           0 :               node = userData->GetNode();
     665           0 :         CheckButtons( node );
     666             :     }
     667             : 
     668           0 :     return 0;
     669             : }
     670             : 
     671           0 : IMPL_LINK( SvxScriptOrgDialog, ButtonHdl, Button *, pButton )
     672             : {
     673           0 :     if ( pButton == m_pCloseButton )
     674             :     {
     675           0 :         StoreCurrentSelection();
     676           0 :         EndDialog( 0 );
     677             :     }
     678           0 :     if ( pButton == m_pEditButton ||
     679           0 :             pButton == m_pCreateButton ||
     680           0 :             pButton == m_pDelButton ||
     681           0 :             pButton == m_pRunButton ||
     682           0 :             pButton == m_pRenameButton )
     683             : 
     684             :     {
     685           0 :         if ( m_pScriptsBox->IsSelected( m_pScriptsBox->GetHdlEntry() ) )
     686             :         {
     687           0 :             SvTreeListEntry* pEntry = m_pScriptsBox->GetHdlEntry();
     688           0 :             SFEntry* userData = 0;
     689           0 :             if ( !pEntry )
     690             :             {
     691           0 :                 return 0;
     692             :             }
     693           0 :             userData = (SFEntry*)pEntry->GetUserData();
     694           0 :             if ( userData )
     695             :             {
     696           0 :                 Reference< browse::XBrowseNode > node;
     697           0 :                 Reference< XModel > xModel;
     698             : 
     699           0 :                 node = userData->GetNode();
     700           0 :                 xModel = userData->GetModel();
     701             : 
     702           0 :                 if ( !node.is() )
     703             :                 {
     704           0 :                     return 0;
     705             :                 }
     706             : 
     707           0 :                 if ( pButton == m_pRunButton )
     708             :                 {
     709           0 :                     OUString tmpString;
     710           0 :                     Reference< beans::XPropertySet > xProp( node, UNO_QUERY );
     711           0 :                     Reference< provider::XScriptProvider > mspNode;
     712           0 :                     if( !xProp.is() )
     713             :                     {
     714           0 :                         return 0;
     715             :                     }
     716             : 
     717           0 :                     if ( xModel.is() )
     718             :                     {
     719           0 :                         Reference< XEmbeddedScripts >  xEmbeddedScripts( xModel, UNO_QUERY);
     720           0 :                         if( !xEmbeddedScripts.is() )
     721             :                         {
     722           0 :                             return 0;
     723             :                         }
     724             : 
     725           0 :                         if (!xEmbeddedScripts->getAllowMacroExecution())
     726             :                         {
     727             :                             // Please FIXME: Show a message box if AllowMacroExecution is false
     728           0 :                             return 0;
     729           0 :                         }
     730             :                     }
     731             : 
     732             : 
     733           0 :                     SvTreeListEntry* pParent = m_pScriptsBox->GetParent( pEntry );
     734           0 :                     while ( pParent && !mspNode.is() )
     735             :                     {
     736           0 :                         SFEntry* mspUserData = (SFEntry*)pParent->GetUserData();
     737           0 :                         mspNode.set( mspUserData->GetNode() , UNO_QUERY );
     738           0 :                         pParent = m_pScriptsBox->GetParent( pParent );
     739             :                     }
     740           0 :                     xProp->getPropertyValue("URI") >>= tmpString;
     741           0 :                     const String scriptURL( tmpString );
     742             : 
     743           0 :                     if ( mspNode.is() )
     744             :                     {
     745             :                         try
     746             :                         {
     747             :                             Reference< provider::XScript > xScript(
     748           0 :                             mspNode->getScript( scriptURL ), UNO_QUERY_THROW );
     749             : 
     750           0 :                             const Sequence< Any > args(0);
     751           0 :                             Any aRet;
     752           0 :                             Sequence< sal_Int16 > outIndex;
     753           0 :                             Sequence< Any > outArgs( 0 );
     754           0 :                             aRet = xScript->invoke( args, outIndex, outArgs );
     755             :                         }
     756           0 :                         catch ( reflection::InvocationTargetException& ite )
     757             :                         {
     758           0 :                             ::com::sun::star::uno::Any a = makeAny(ite);
     759           0 :                             ShowErrorDialog(a);
     760             :                         }
     761           0 :                         catch ( provider::ScriptFrameworkErrorException& ite )
     762             :                         {
     763           0 :                             ::com::sun::star::uno::Any a = makeAny(ite);
     764           0 :                             ShowErrorDialog(a);
     765             :                         }
     766           0 :                         catch ( RuntimeException& re )
     767             :                         {
     768           0 :                             ::com::sun::star::uno::Any a = makeAny(re);
     769           0 :                             ShowErrorDialog(a);
     770             :                         }
     771           0 :                         catch ( Exception& e )
     772             :                         {
     773           0 :                             ::com::sun::star::uno::Any a = makeAny(e);
     774           0 :                             ShowErrorDialog(a);
     775             :                         }
     776             :                     }
     777           0 :                     StoreCurrentSelection();
     778           0 :                     EndDialog( 0 );
     779             :                 }
     780           0 :                 else if ( pButton == m_pEditButton )
     781             :                 {
     782           0 :                     Reference< script::XInvocation > xInv( node, UNO_QUERY );
     783           0 :                     if ( xInv.is() )
     784             :                     {
     785           0 :                         StoreCurrentSelection();
     786           0 :                         EndDialog( 0 );
     787           0 :                         Sequence< Any > args(0);
     788           0 :                         Sequence< Any > outArgs( 0 );
     789           0 :                         Sequence< sal_Int16 > outIndex;
     790             :                         try
     791             :                         {
     792             :                             // ISSUE need code to run script here
     793           0 :                             xInv->invoke( "Editable", args, outIndex, outArgs );
     794             :                         }
     795           0 :                         catch( Exception& e )
     796             :                         {
     797             :                             OSL_TRACE("Caught exception trying to invoke %s", OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer );
     798             : 
     799           0 :                         }
     800           0 :                     }
     801             :                 }
     802           0 :                 else if ( pButton == m_pCreateButton )
     803             :                 {
     804           0 :                     createEntry( pEntry );
     805             :                 }
     806           0 :                 else if ( pButton == m_pDelButton )
     807             :                 {
     808           0 :                     deleteEntry( pEntry );
     809             :                 }
     810           0 :                 else if ( pButton == m_pRenameButton )
     811             :                 {
     812           0 :                     renameEntry( pEntry );
     813           0 :                 }
     814             :             }
     815             :         }
     816             :     }
     817           0 :     return 0;
     818             : }
     819             : 
     820           0 : Reference< browse::XBrowseNode > SvxScriptOrgDialog::getBrowseNode( SvTreeListEntry* pEntry )
     821             : {
     822           0 :     Reference< browse::XBrowseNode > node;
     823           0 :     if ( pEntry )
     824             :     {
     825           0 :         SFEntry* userData = (SFEntry*)pEntry->GetUserData();
     826           0 :         if ( userData )
     827             :         {
     828           0 :             node = userData->GetNode();
     829             :         }
     830             :     }
     831             : 
     832           0 :     return node;
     833             : }
     834             : 
     835           0 : Reference< XModel > SvxScriptOrgDialog::getModel( SvTreeListEntry* pEntry )
     836             : {
     837           0 :     Reference< XModel > model;
     838           0 :     if ( pEntry )
     839             :     {
     840           0 :         SFEntry* userData = (SFEntry*)pEntry->GetUserData();
     841           0 :         if ( userData )
     842             :         {
     843           0 :             model = userData->GetModel();
     844             :         }
     845             :     }
     846             : 
     847           0 :     return model;
     848             : }
     849             : 
     850           0 : void SvxScriptOrgDialog::createEntry( SvTreeListEntry* pEntry )
     851             : {
     852             : 
     853           0 :     Reference< browse::XBrowseNode >  aChildNode;
     854           0 :     Reference< browse::XBrowseNode > node = getBrowseNode( pEntry );
     855           0 :     Reference< script::XInvocation > xInv( node, UNO_QUERY );
     856             : 
     857           0 :     if ( xInv.is() )
     858             :     {
     859           0 :         OUString aNewName;
     860           0 :         OUString aNewStdName;
     861           0 :         sal_uInt16 nMode = INPUTMODE_NEWLIB;
     862           0 :         if( m_pScriptsBox->GetModel()->GetDepth( pEntry ) == 0 )
     863             :         {
     864           0 :             aNewStdName = "Library" ;
     865             :         }
     866             :         else
     867             :         {
     868           0 :             aNewStdName = "Macro" ;
     869           0 :             nMode = INPUTMODE_NEWMACRO;
     870             :         }
     871             :         //do we need L10N for this? ie somethng like:
     872             :         //String aNewStdName( ResId( STR_STDMODULENAME ) );
     873           0 :         sal_Bool bValid = sal_False;
     874           0 :         sal_uInt16 i = 1;
     875             : 
     876           0 :         Sequence< Reference< browse::XBrowseNode > > childNodes;
     877             :         // no children => ok to create Parcel1 or Script1 without checking
     878             :         try
     879             :         {
     880           0 :             if( node->hasChildNodes() == sal_False )
     881             :             {
     882           0 :                 aNewName = aNewStdName + OUString::number(i);
     883           0 :                 bValid = sal_True;
     884             :             }
     885             :             else
     886             :             {
     887           0 :                 childNodes = node->getChildNodes();
     888             :             }
     889             :         }
     890           0 :         catch ( Exception& )
     891             :         {
     892             :             // ignore, will continue on with empty sequence
     893             :         }
     894             : 
     895           0 :         OUString extn;
     896           0 :         while ( !bValid )
     897             :         {
     898           0 :             aNewName = aNewStdName + OUString::number(i);
     899           0 :             sal_Bool bFound = sal_False;
     900           0 :             if(childNodes.getLength() > 0 )
     901             :             {
     902           0 :                 OUString nodeName = childNodes[0]->getName();
     903           0 :                 sal_Int32 extnPos = nodeName.lastIndexOf( '.' );
     904           0 :                 if(extnPos>0)
     905           0 :                     extn = nodeName.copy(extnPos);
     906             :             }
     907           0 :             for( sal_Int32 index = 0; index < childNodes.getLength(); index++ )
     908             :             {
     909           0 :                 if (aNewName+extn == childNodes[index]->getName())
     910             :                 {
     911           0 :                     bFound = sal_True;
     912           0 :                     break;
     913             :                 }
     914             :             }
     915           0 :             if( bFound )
     916             :             {
     917           0 :                 i++;
     918             :             }
     919             :             else
     920             :             {
     921           0 :                 bValid = sal_True;
     922             :             }
     923             :         }
     924             : 
     925             :         SAL_WNODEPRECATED_DECLARATIONS_PUSH
     926           0 :         std::auto_ptr< CuiInputDialog > xNewDlg( new CuiInputDialog( static_cast<Window*>(this), nMode ) );
     927             :         SAL_WNODEPRECATED_DECLARATIONS_POP
     928           0 :         xNewDlg->SetObjectName( aNewName );
     929             : 
     930           0 :         do
     931             :         {
     932           0 :             if ( xNewDlg->Execute() && xNewDlg->GetObjectName().Len() )
     933             :             {
     934           0 :                 OUString aUserSuppliedName = xNewDlg->GetObjectName();
     935           0 :                 bValid = sal_True;
     936           0 :                 for( sal_Int32 index = 0; index < childNodes.getLength(); index++ )
     937             :                 {
     938           0 :                     if (aUserSuppliedName+extn == childNodes[index]->getName())
     939             :                     {
     940           0 :                         bValid = sal_False;
     941           0 :                         String aError( m_createErrStr );
     942           0 :                         aError.Append( m_createDupStr );
     943           0 :                         ErrorBox aErrorBox( static_cast<Window*>(this), WB_OK | RET_OK, aError );
     944           0 :                         aErrorBox.SetText( m_createErrTitleStr );
     945           0 :                         aErrorBox.Execute();
     946           0 :                         xNewDlg->SetObjectName( aNewName );
     947           0 :                         break;
     948             :                     }
     949             :                 }
     950           0 :                 if( bValid )
     951           0 :                     aNewName = aUserSuppliedName;
     952             :             }
     953             :             else
     954             :             {
     955             :                 // user hit cancel or hit OK with nothing in the editbox
     956             : 
     957           0 :                 return;
     958             :             }
     959             :         }
     960             :         while ( !bValid );
     961             : 
     962             :         // open up parent node (which ensures it's loaded)
     963           0 :         m_pScriptsBox->RequestingChildren( pEntry );
     964             : 
     965           0 :         Sequence< Any > args( 1 );
     966           0 :         args[ 0 ] <<= aNewName;
     967           0 :         Sequence< Any > outArgs( 0 );
     968           0 :         Sequence< sal_Int16 > outIndex;
     969             :         try
     970             :         {
     971           0 :             Any aResult;
     972           0 :             aResult = xInv->invoke( "Creatable", args, outIndex, outArgs );
     973           0 :             Reference< browse::XBrowseNode > newNode( aResult, UNO_QUERY );
     974           0 :             aChildNode = newNode;
     975             : 
     976             :         }
     977           0 :         catch( Exception& e )
     978             :         {
     979             :             OSL_TRACE("Caught exception trying to Create %s",
     980             :                 OUStringToOString(
     981             :                     e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer );
     982           0 :         }
     983             :     }
     984           0 :     if ( aChildNode.is() )
     985             :     {
     986           0 :         String aChildName = aChildNode->getName();
     987           0 :         SvTreeListEntry* pNewEntry = NULL;
     988             : 
     989           0 :         Reference<XModel> xDocumentModel = getModel( pEntry );
     990             : 
     991             :         // ISSUE do we need to remove all entries for parent
     992             :         // to achieve sort? Just need to determine position
     993             :         // SvTreeListBox::InsertEntry can take position arg
     994             :         // -- Basic doesn't do this on create.
     995             :         // Suppose we could avoid this too. -> created nodes are
     996             :         // not in alphabetical order
     997           0 :         if ( aChildNode->getType() == browse::BrowseNodeTypes::SCRIPT )
     998             :         {
     999             :             SAL_WNODEPRECATED_DECLARATIONS_PUSH
    1000             :             pNewEntry = m_pScriptsBox->insertEntry( aChildName,
    1001           0 :                     RID_CUIIMG_MACRO, pEntry, false, std::auto_ptr< SFEntry >(new SFEntry( OBJTYPE_METHOD, aChildNode,xDocumentModel ) ) );
    1002             :             SAL_WNODEPRECATED_DECLARATIONS_POP
    1003             : 
    1004             :         }
    1005             :         else
    1006             :         {
    1007             :             SAL_WNODEPRECATED_DECLARATIONS_PUSH
    1008             :             pNewEntry = m_pScriptsBox->insertEntry( aChildName,
    1009           0 :                 RID_CUIIMG_LIB, pEntry, false, std::auto_ptr< SFEntry >(new SFEntry( OBJTYPE_SCRIPTCONTAINER, aChildNode,xDocumentModel ) ) );
    1010             :             SAL_WNODEPRECATED_DECLARATIONS_POP
    1011             : 
    1012             :             // If the Parent is not loaded then set to
    1013             :             // loaded, this will prevent RequestingChildren ( called
    1014             :             // from vcl via RequestingChildren ) from
    1015             :             // creating new ( duplicate ) children
    1016           0 :             SFEntry* userData = (SFEntry*)pEntry->GetUserData();
    1017           0 :             if ( userData &&  !userData->isLoaded() )
    1018             :             {
    1019           0 :                 userData->setLoaded();
    1020             :             }
    1021             :         }
    1022           0 :         m_pScriptsBox->SetCurEntry( pNewEntry );
    1023           0 :         m_pScriptsBox->Select( m_pScriptsBox->GetCurEntry() );
    1024             : 
    1025             :     }
    1026             :     else
    1027             :     {
    1028             :         //ISSUE L10N & message from exception?
    1029           0 :         OUString aError( m_createErrStr );
    1030           0 :         ErrorBox aErrorBox( static_cast<Window*>(this), WB_OK | RET_OK, aError );
    1031           0 :         aErrorBox.SetText( m_createErrTitleStr );
    1032           0 :         aErrorBox.Execute();
    1033           0 :     }
    1034             : }
    1035             : 
    1036           0 : void SvxScriptOrgDialog::renameEntry( SvTreeListEntry* pEntry )
    1037             : {
    1038             : 
    1039           0 :     Reference< browse::XBrowseNode >  aChildNode;
    1040           0 :     Reference< browse::XBrowseNode > node = getBrowseNode( pEntry );
    1041           0 :     Reference< script::XInvocation > xInv( node, UNO_QUERY );
    1042             : 
    1043           0 :     if ( xInv.is() )
    1044             :     {
    1045           0 :         OUString aNewName = node->getName();
    1046           0 :         sal_Int32 extnPos = aNewName.lastIndexOf( '.' );
    1047           0 :         OUString extn;
    1048           0 :         if(extnPos>0)
    1049             :         {
    1050           0 :             extn = aNewName.copy(extnPos);
    1051           0 :             aNewName = aNewName.copy(0,extnPos);
    1052             :         }
    1053           0 :         sal_uInt16 nMode = INPUTMODE_RENAME;
    1054             : 
    1055             :         SAL_WNODEPRECATED_DECLARATIONS_PUSH
    1056           0 :         std::auto_ptr< CuiInputDialog > xNewDlg( new CuiInputDialog( static_cast<Window*>(this), nMode ) );
    1057             :         SAL_WNODEPRECATED_DECLARATIONS_POP
    1058           0 :         xNewDlg->SetObjectName( aNewName );
    1059             : 
    1060             :         sal_Bool bValid;
    1061           0 :         do
    1062             :         {
    1063           0 :             if ( xNewDlg->Execute() && xNewDlg->GetObjectName().Len() )
    1064             :             {
    1065           0 :                 OUString aUserSuppliedName = xNewDlg->GetObjectName();
    1066           0 :                 bValid = sal_True;
    1067           0 :                 if( bValid )
    1068           0 :                     aNewName = aUserSuppliedName;
    1069             :             }
    1070             :             else
    1071             :             {
    1072             :                 // user hit cancel or hit OK with nothing in the editbox
    1073           0 :                 return;
    1074             :             }
    1075             :         }
    1076             :         while ( !bValid );
    1077             : 
    1078           0 :         Sequence< Any > args( 1 );
    1079           0 :         args[ 0 ] <<= aNewName;
    1080           0 :         Sequence< Any > outArgs( 0 );
    1081           0 :         Sequence< sal_Int16 > outIndex;
    1082             :         try
    1083             :         {
    1084           0 :             Any aResult;
    1085           0 :             aResult = xInv->invoke( "Renamable", args, outIndex, outArgs );
    1086           0 :             Reference< browse::XBrowseNode > newNode( aResult, UNO_QUERY );
    1087           0 :             aChildNode = newNode;
    1088             : 
    1089             :         }
    1090           0 :         catch( Exception& e )
    1091             :         {
    1092             :             OSL_TRACE("Caught exception trying to Rename %s",
    1093             :                 OUStringToOString(
    1094             :                     e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer );
    1095           0 :         }
    1096             :     }
    1097           0 :     if ( aChildNode.is() )
    1098             :     {
    1099           0 :         m_pScriptsBox->SetEntryText( pEntry, aChildNode->getName() );
    1100           0 :         m_pScriptsBox->SetCurEntry( pEntry );
    1101           0 :         m_pScriptsBox->Select( m_pScriptsBox->GetCurEntry() );
    1102             : 
    1103             :     }
    1104             :     else
    1105             :     {
    1106             :         //ISSUE L10N & message from exception?
    1107           0 :         String aError( m_renameErrStr );
    1108           0 :         ErrorBox aErrorBox( static_cast<Window*>(this), WB_OK | RET_OK, aError );
    1109           0 :         aErrorBox.SetText( m_renameErrTitleStr );
    1110           0 :         aErrorBox.Execute();
    1111           0 :     }
    1112             : }
    1113           0 : void SvxScriptOrgDialog::deleteEntry( SvTreeListEntry* pEntry )
    1114             : {
    1115           0 :     sal_Bool result = sal_False;
    1116           0 :     Reference< browse::XBrowseNode > node = getBrowseNode( pEntry );
    1117             :     // ISSUE L10N string & can we centre list?
    1118           0 :     OUString aQuery = m_delQueryStr + getListOfChildren( node, 0 );
    1119           0 :     QueryBox aQueryBox( static_cast<Window*>(this), WB_YES_NO | WB_DEF_YES, aQuery );
    1120           0 :     aQueryBox.SetText( m_delQueryTitleStr );
    1121           0 :     if ( aQueryBox.Execute() == RET_NO )
    1122             :     {
    1123           0 :         return;
    1124             :     }
    1125             : 
    1126           0 :     Reference< script::XInvocation > xInv( node, UNO_QUERY );
    1127           0 :     if ( xInv.is() )
    1128             :     {
    1129           0 :         Sequence< Any > args( 0 );
    1130           0 :         Sequence< Any > outArgs( 0 );
    1131           0 :         Sequence< sal_Int16 > outIndex;
    1132             :         try
    1133             :         {
    1134           0 :             Any aResult;
    1135           0 :             aResult = xInv->invoke( "Deletable", args, outIndex, outArgs );
    1136           0 :             aResult >>= result; // or do we just assume true if no exception ?
    1137             :         }
    1138           0 :         catch( Exception& e )
    1139             :         {
    1140             :             OSL_TRACE("Caught exception trying to delete %s",
    1141             :                 OUStringToOString(
    1142             :                     e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer );
    1143           0 :         }
    1144             :     }
    1145             : 
    1146           0 :     if ( result == sal_True )
    1147             :     {
    1148           0 :         m_pScriptsBox->deleteTree( pEntry );
    1149           0 :         m_pScriptsBox->GetModel()->Remove( pEntry );
    1150             :     }
    1151             :     else
    1152             :     {
    1153             :         //ISSUE L10N & message from exception?
    1154           0 :         ErrorBox aErrorBox( static_cast<Window*>(this), WB_OK | RET_OK, m_delErrStr );
    1155           0 :         aErrorBox.SetText( m_delErrTitleStr );
    1156           0 :         aErrorBox.Execute();
    1157           0 :     }
    1158             : 
    1159             : }
    1160             : 
    1161           0 : sal_Bool SvxScriptOrgDialog::getBoolProperty( Reference< beans::XPropertySet >& xProps,
    1162             :                 OUString& propName )
    1163             : {
    1164           0 :     sal_Bool result = false;
    1165             :     try
    1166             :     {
    1167           0 :         sal_Bool bTemp = sal_False;
    1168           0 :         xProps->getPropertyValue( propName ) >>= bTemp;
    1169           0 :         result = ( bTemp == sal_True );
    1170             :     }
    1171           0 :     catch ( Exception& )
    1172             :     {
    1173           0 :         return result;
    1174             :     }
    1175           0 :     return result;
    1176             : }
    1177             : 
    1178           0 : OUString SvxScriptOrgDialog::getListOfChildren( Reference< browse::XBrowseNode > node, int depth )
    1179             : {
    1180           0 :     OUString result = "\n";
    1181           0 :     for( int i=0;i<=depth;i++ )
    1182             :     {
    1183           0 :         result += "\t";
    1184             :     }
    1185           0 :     result += node->getName();
    1186             : 
    1187             :     try
    1188             :     {
    1189           0 :         if ( node->hasChildNodes() == sal_True )
    1190             :         {
    1191             :             Sequence< Reference< browse::XBrowseNode > > children
    1192           0 :                 = node->getChildNodes();
    1193           0 :             for ( sal_Int32 n = 0; n < children.getLength(); n++ )
    1194             :             {
    1195           0 :                 result += getListOfChildren( children[ n ] , depth+1 );
    1196           0 :             }
    1197             :         }
    1198             :     }
    1199           0 :     catch ( Exception& )
    1200             :     {
    1201             :         // ignore, will return an empty string
    1202             :     }
    1203             : 
    1204           0 :     return result;
    1205             : }
    1206             : 
    1207           0 : Selection_hash SvxScriptOrgDialog::m_lastSelection;
    1208             : 
    1209           0 : void SvxScriptOrgDialog::StoreCurrentSelection()
    1210             : {
    1211           0 :     OUString aDescription;
    1212           0 :     if ( m_pScriptsBox->IsSelected( m_pScriptsBox->GetHdlEntry() ) )
    1213             :     {
    1214           0 :         SvTreeListEntry* pEntry = m_pScriptsBox->GetHdlEntry();
    1215           0 :         while( pEntry )
    1216             :         {
    1217           0 :             aDescription = m_pScriptsBox->GetEntryText( pEntry ) + aDescription;
    1218           0 :             pEntry = m_pScriptsBox->GetParent( pEntry );
    1219           0 :             if ( pEntry )
    1220           0 :                 aDescription = ";" + aDescription;
    1221             :         }
    1222           0 :         OUString sDesc( aDescription );
    1223           0 :         m_lastSelection[ m_sLanguage ] = sDesc;
    1224           0 :     }
    1225           0 : }
    1226             : 
    1227           0 : void SvxScriptOrgDialog::RestorePreviousSelection()
    1228             : {
    1229           0 :     String aStoredEntry = String( m_lastSelection[ m_sLanguage ] );
    1230           0 :     if( aStoredEntry.Len() <= 0 )
    1231           0 :         return;
    1232           0 :     SvTreeListEntry* pEntry = 0;
    1233           0 :     sal_Int32 nIndex = 0;
    1234           0 :     while ( nIndex != -1 )
    1235             :     {
    1236           0 :         String aTmp( aStoredEntry.GetToken( 0, ';', nIndex ) );
    1237           0 :         SvTreeListEntry* pTmpEntry = m_pScriptsBox->FirstChild( pEntry );
    1238           0 :         while ( pTmpEntry )
    1239             :         {
    1240           0 :             if ( m_pScriptsBox->GetEntryText( pTmpEntry ) == aTmp )
    1241             :             {
    1242           0 :                 pEntry = pTmpEntry;
    1243           0 :                 break;
    1244             :             }
    1245           0 :             pTmpEntry = m_pScriptsBox->NextSibling( pTmpEntry );
    1246             :         }
    1247           0 :         if ( !pTmpEntry )
    1248           0 :             break;
    1249           0 :         m_pScriptsBox->RequestingChildren( pEntry );
    1250           0 :     }
    1251           0 :     m_pScriptsBox->SetCurEntry( pEntry );
    1252             : }
    1253             : 
    1254           0 : OUString ReplaceString(
    1255             :     const OUString& source,
    1256             :     const OUString& token,
    1257             :     const OUString& value )
    1258             : {
    1259           0 :     sal_Int32 pos = source.indexOf( token );
    1260             : 
    1261           0 :     if ( pos != -1 && !value.isEmpty() )
    1262             :     {
    1263           0 :         return source.replaceAt( pos, token.getLength(), value );
    1264             :     }
    1265             :     else
    1266             :     {
    1267           0 :         return source;
    1268             :     }
    1269             : }
    1270             : 
    1271           0 : OUString FormatErrorString(
    1272             :     const OUString& unformatted,
    1273             :     const OUString& language,
    1274             :     const OUString& script,
    1275             :     const OUString& line,
    1276             :     const OUString& type,
    1277             :     const OUString& message )
    1278             : {
    1279           0 :     OUString result = unformatted.copy( 0 );
    1280             : 
    1281           0 :     result = ReplaceString(result, "%LANGUAGENAME", language );
    1282           0 :     result = ReplaceString(result, "%SCRIPTNAME", script );
    1283           0 :     result = ReplaceString(result, "%LINENUMBER", line );
    1284             : 
    1285           0 :     if ( !type.isEmpty() )
    1286             :     {
    1287           0 :         result += "\n\n" +
    1288           0 :                   OUString(CUI_RES(RID_SVXSTR_ERROR_TYPE_LABEL)) +
    1289           0 :                   " " +
    1290           0 :                   type;
    1291             :     }
    1292             : 
    1293           0 :     if ( !message.isEmpty() )
    1294             :     {
    1295           0 :         result += "\n\n" +
    1296           0 :                   OUString(CUI_RES(RID_SVXSTR_ERROR_MESSAGE_LABEL)) +
    1297           0 :                   " " +
    1298           0 :                   message;
    1299             :     }
    1300             : 
    1301           0 :     return result;
    1302             : }
    1303             : 
    1304           0 : OUString GetErrorMessage(
    1305             :     const provider::ScriptErrorRaisedException& eScriptError )
    1306             : {
    1307           0 :     OUString unformatted = CUI_RES( RID_SVXSTR_ERROR_AT_LINE );
    1308             : 
    1309           0 :     OUString unknown("UNKNOWN");
    1310           0 :     OUString language = unknown;
    1311           0 :     OUString script = unknown;
    1312           0 :     OUString line = unknown;
    1313           0 :     OUString type = OUString();
    1314           0 :     OUString message = eScriptError.Message;
    1315             : 
    1316           0 :         if ( !eScriptError.language.isEmpty() )
    1317             :         {
    1318           0 :             language = eScriptError.language;
    1319             :         }
    1320             : 
    1321           0 :         if ( !eScriptError.scriptName.isEmpty() )
    1322             :         {
    1323           0 :             script = eScriptError.scriptName;
    1324             :         }
    1325             : 
    1326           0 :         if ( !eScriptError.Message.isEmpty() )
    1327             :         {
    1328           0 :             message = eScriptError.Message;
    1329             :         }
    1330           0 :         if ( eScriptError.lineNum != -1 )
    1331             :         {
    1332           0 :             line = OUString::valueOf( eScriptError.lineNum );
    1333           0 :             unformatted = CUI_RES( RID_SVXSTR_ERROR_AT_LINE );
    1334             :         }
    1335             :         else
    1336             :         {
    1337           0 :             unformatted = CUI_RES( RID_SVXSTR_ERROR_RUNNING );
    1338             :         }
    1339             : 
    1340             :     return FormatErrorString(
    1341           0 :         unformatted, language, script, line, type, message );
    1342             : }
    1343             : 
    1344           0 : OUString GetErrorMessage(
    1345             :     const provider::ScriptExceptionRaisedException& eScriptException )
    1346             : {
    1347           0 :     OUString unformatted = CUI_RES( RID_SVXSTR_EXCEPTION_AT_LINE );
    1348             : 
    1349           0 :     OUString unknown("UNKNOWN");
    1350           0 :     OUString language = unknown;
    1351           0 :     OUString script = unknown;
    1352           0 :     OUString line = unknown;
    1353           0 :     OUString type = unknown;
    1354           0 :     OUString message = eScriptException.Message;
    1355             : 
    1356           0 :     if ( !eScriptException.language.isEmpty() )
    1357             :     {
    1358           0 :         language = eScriptException.language;
    1359             :     }
    1360           0 :     if ( !eScriptException.scriptName.isEmpty() )
    1361             :     {
    1362           0 :         script = eScriptException.scriptName;
    1363             :     }
    1364             : 
    1365           0 :     if ( !eScriptException.Message.isEmpty() )
    1366             :     {
    1367           0 :         message = eScriptException.Message;
    1368             :     }
    1369             : 
    1370           0 :     if ( eScriptException.lineNum != -1 )
    1371             :     {
    1372           0 :         line = OUString::valueOf( eScriptException.lineNum );
    1373           0 :         unformatted = CUI_RES( RID_SVXSTR_EXCEPTION_AT_LINE );
    1374             :     }
    1375             :     else
    1376             :     {
    1377           0 :         unformatted = CUI_RES( RID_SVXSTR_EXCEPTION_RUNNING );
    1378             :     }
    1379             : 
    1380           0 :     if ( !eScriptException.exceptionType.isEmpty() )
    1381             :     {
    1382           0 :         type = eScriptException.exceptionType;
    1383             :     }
    1384             : 
    1385             :     return FormatErrorString(
    1386           0 :         unformatted, language, script, line, type, message );
    1387             : 
    1388             : }
    1389           0 : OUString GetErrorMessage(
    1390             :     const provider::ScriptFrameworkErrorException& sError )
    1391             : {
    1392           0 :     OUString unformatted = CUI_RES( RID_SVXSTR_FRAMEWORK_ERROR_RUNNING );
    1393             : 
    1394           0 :     OUString language("UNKNOWN");
    1395             : 
    1396           0 :     OUString script("UNKNOWN");
    1397             : 
    1398           0 :     OUString message;
    1399             : 
    1400           0 :     if ( !sError.scriptName.isEmpty() )
    1401             :     {
    1402           0 :         script = sError.scriptName;
    1403             :     }
    1404           0 :     if ( !sError.language.isEmpty() )
    1405             :     {
    1406           0 :         language = sError.language;
    1407             :     }
    1408           0 :     if ( sError.errorType == provider::ScriptFrameworkErrorType::NOTSUPPORTED )
    1409             :     {
    1410           0 :         message = OUString(
    1411           0 :             CUI_RES(  RID_SVXSTR_ERROR_LANG_NOT_SUPPORTED ) );
    1412           0 :         message = ReplaceString(message, "%LANGUAGENAME", language );
    1413             : 
    1414             :     }
    1415             :     else
    1416             :     {
    1417           0 :         message = sError.Message;
    1418             :     }
    1419             :     return FormatErrorString(
    1420           0 :         unformatted, language, script, OUString(), OUString(), message );
    1421             : }
    1422             : 
    1423           0 : OUString GetErrorMessage( const RuntimeException& re )
    1424             : {
    1425           0 :     Type t = ::getCppuType( &re );
    1426           0 :     OUString message = t.getTypeName();
    1427           0 :     message += re.Message;
    1428             : 
    1429           0 :     return message;
    1430             : }
    1431             : 
    1432           0 : OUString GetErrorMessage( const Exception& e )
    1433             : {
    1434           0 :     Type t = ::getCppuType( &e );
    1435           0 :     OUString message = t.getTypeName();
    1436           0 :     message += e.Message;
    1437             : 
    1438           0 :     return message;
    1439             : }
    1440             : 
    1441           0 : OUString GetErrorMessage( const com::sun::star::uno::Any& aException )
    1442             : {
    1443           0 :     if ( aException.getValueType() ==
    1444           0 :          ::getCppuType( (const reflection::InvocationTargetException* ) NULL ) )
    1445             :     {
    1446           0 :         reflection::InvocationTargetException ite;
    1447           0 :         aException >>= ite;
    1448           0 :         if ( ite.TargetException.getValueType() == ::getCppuType( ( const provider::ScriptErrorRaisedException* ) NULL ) )
    1449             :         {
    1450             :             // Error raised by script
    1451           0 :             provider::ScriptErrorRaisedException scriptError;
    1452           0 :             ite.TargetException >>= scriptError;
    1453           0 :             return GetErrorMessage( scriptError );
    1454             :         }
    1455           0 :         else if ( ite.TargetException.getValueType() == ::getCppuType( ( const provider::ScriptExceptionRaisedException* ) NULL ) )
    1456             :         {
    1457             :             // Exception raised by script
    1458           0 :             provider::ScriptExceptionRaisedException scriptException;
    1459           0 :             ite.TargetException >>= scriptException;
    1460           0 :             return GetErrorMessage( scriptException );
    1461             :         }
    1462             :         else
    1463             :         {
    1464             :             // Unknown error, shouldn't happen
    1465             :             // OSL_ASSERT(...)
    1466           0 :         }
    1467             : 
    1468             :     }
    1469           0 :     else if ( aException.getValueType() == ::getCppuType( ( const provider::ScriptFrameworkErrorException* ) NULL ) )
    1470             :     {
    1471             :         // A Script Framework error has occurred
    1472           0 :         provider::ScriptFrameworkErrorException sfe;
    1473           0 :         aException >>= sfe;
    1474           0 :         return GetErrorMessage( sfe );
    1475             : 
    1476             :     }
    1477             :     // unknown exception
    1478           0 :     Exception e;
    1479           0 :     RuntimeException rte;
    1480           0 :     if ( aException >>= rte )
    1481             :     {
    1482           0 :         return GetErrorMessage( rte );
    1483             :     }
    1484             : 
    1485           0 :     aException >>= e;
    1486           0 :     return GetErrorMessage( e );
    1487             : 
    1488             : }
    1489             : 
    1490           0 : SvxScriptErrorDialog::SvxScriptErrorDialog(
    1491             :     Window* , ::com::sun::star::uno::Any aException )
    1492           0 :     : m_sMessage()
    1493             : {
    1494           0 :     SolarMutexGuard aGuard;
    1495           0 :     m_sMessage = GetErrorMessage( aException );
    1496           0 : }
    1497             : 
    1498           0 : SvxScriptErrorDialog::~SvxScriptErrorDialog()
    1499             : {
    1500           0 : }
    1501             : 
    1502           0 : short SvxScriptErrorDialog::Execute()
    1503             : {
    1504             :     // Show Error dialog asynchronously
    1505             :     //
    1506             :     // Pass a copy of the message to the ShowDialog method as the
    1507             :     // SvxScriptErrorDialog may be deleted before ShowDialog is called
    1508             :     Application::PostUserEvent(
    1509             :         LINK( this, SvxScriptErrorDialog, ShowDialog ),
    1510           0 :         new OUString( m_sMessage ) );
    1511             : 
    1512           0 :     return 0;
    1513             : }
    1514             : 
    1515           0 : IMPL_LINK( SvxScriptErrorDialog, ShowDialog, OUString*, pMessage )
    1516             : {
    1517           0 :     OUString message;
    1518             : 
    1519           0 :     if ( pMessage && !pMessage->isEmpty() )
    1520             :     {
    1521           0 :         message = *pMessage;
    1522             :     }
    1523             :     else
    1524             :     {
    1525           0 :         message = OUString( CUI_RES( RID_SVXSTR_ERROR_TITLE ) );
    1526             :     }
    1527             : 
    1528           0 :     MessBox* pBox = new WarningBox( NULL, WB_OK, message );
    1529           0 :     pBox->SetText( CUI_RES( RID_SVXSTR_ERROR_TITLE ) );
    1530           0 :     pBox->Execute();
    1531             : 
    1532           0 :     delete pBox;
    1533           0 :     delete pMessage;
    1534             : 
    1535           0 :     return 0;
    1536           0 : }
    1537             : 
    1538             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10