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