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