1 /**********************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: scriptdlg.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
36 #include <sfx2/objsh.hxx>
37 #include <vcl/svapp.hxx>
38 #include <vcl/msgbox.hxx>
39 #include <vos/mutex.hxx>
41 #include <svx/dialogs.hrc>
42 #include "scriptdlg.hrc"
43 #include "fmresids.hrc"
44 #include "scriptdlg.hxx"
45 #include <svx/dialmgr.hxx>
46 #include "selector.hxx"
48 #include <com/sun/star/uno/XComponentContext.hpp>
49 #include <com/sun/star/frame/XDesktop.hpp>
50 #include <com/sun/star/script/XInvocation.hpp>
51 #include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
52 #include <com/sun/star/script/provider/XScriptProvider.hpp>
53 #include <com/sun/star/script/browse/BrowseNodeTypes.hpp>
54 #include <com/sun/star/script/browse/XBrowseNodeFactory.hpp>
55 #include <com/sun/star/script/browse/BrowseNodeFactoryViewTypes.hpp>
56 #include <com/sun/star/script/provider/ScriptErrorRaisedException.hpp>
57 #include <com/sun/star/script/provider/ScriptExceptionRaisedException.hpp>
58 #include <com/sun/star/script/provider/ScriptFrameworkErrorType.hpp>
59 #include <com/sun/star/frame/XModuleManager.hpp>
60 #include <com/sun/star/script/XInvocation.hpp>
61 #include <com/sun/star/document/XEmbeddedScripts.hpp>
63 #include <cppuhelper/implbase1.hxx>
64 #include <comphelper/documentinfo.hxx>
65 #include <comphelper/uno3.hxx>
66 #include <comphelper/processfactory.hxx>
67 #include <comphelper/broadcasthelper.hxx>
68 #include <comphelper/propertycontainer.hxx>
69 #include <comphelper/proparrhlp.hxx>
71 #include <basic/sbx.hxx>
72 #include <svtools/imagemgr.hxx>
73 #include <tools/urlobj.hxx>
77 using namespace ::com::sun::star
;
78 using namespace ::com::sun::star::uno
;
79 using namespace ::com::sun::star::script
;
80 using namespace ::com::sun::star::frame
;
81 using namespace ::com::sun::star::document
;
83 void ShowErrorDialog( const Any
& aException
)
85 SvxScriptErrorDialog
* pDlg
= new SvxScriptErrorDialog( NULL
, aException
);
90 SFTreeListBox::SFTreeListBox( Window
* pParent
, const ResId
& rResId
) :
91 SvTreeListBox( pParent
, ResId( rResId
.GetId(),*rResId
.GetResMgr() ) ),
92 m_hdImage(ResId(IMG_HARDDISK
,*rResId
.GetResMgr())),
93 m_hdImage_hc(ResId(IMG_HARDDISK_HC
,*rResId
.GetResMgr())),
94 m_libImage(ResId(IMG_LIB
,*rResId
.GetResMgr())),
95 m_libImage_hc(ResId(IMG_LIB_HC
,*rResId
.GetResMgr())),
96 m_macImage(ResId(IMG_MACRO
,*rResId
.GetResMgr())),
97 m_macImage_hc(ResId(IMG_MACRO_HC
,*rResId
.GetResMgr())),
98 m_docImage(ResId(IMG_DOCUMENT
,*rResId
.GetResMgr())),
99 m_docImage_hc(ResId(IMG_DOCUMENT_HC
,*rResId
.GetResMgr())),
100 m_sMyMacros(String(ResId(STR_MYMACROS
,*rResId
.GetResMgr()))),
101 m_sProdMacros(String(ResId(STR_PRODMACROS
,*rResId
.GetResMgr())))
104 SetSelectionMode( SINGLE_SELECTION
);
106 SetWindowBits( GetStyle() | WB_CLIPCHILDREN
| WB_HSCROLL
|
107 WB_HASBUTTONS
| WB_HASBUTTONSATROOT
| WB_HIDESELECTION
|
108 WB_HASLINES
| WB_HASLINESATROOT
);
109 SetNodeDefaultImages();
111 nMode
= 0xFF; // Alles
114 SFTreeListBox::~SFTreeListBox()
119 void SFTreeListBox::delUserData( SvLBoxEntry
* pEntry
)
124 String text
= GetEntryText( pEntry
);
125 SFEntry
* pUserData
= (SFEntry
*)pEntry
->GetUserData();
129 // TBD seem to get a Select event on node that is remove ( below )
130 // so need to be able to detect that this node is not to be
131 // processed in order to do this, setting userData to NULL ( must
132 // be a better way to do this )
134 pEntry
->SetUserData( pUserData
);
139 void SFTreeListBox::deleteTree( SvLBoxEntry
* pEntry
)
142 delUserData( pEntry
);
143 pEntry
= FirstChild( pEntry
);
146 SvLBoxEntry
* pNextEntry
= NextSibling( pEntry
);
147 deleteTree( pEntry
);
148 GetModel()->Remove( pEntry
);
153 void SFTreeListBox::deleteAllTree()
155 SvLBoxEntry
* pEntry
= GetEntry( 0 );
157 // TBD - below is a candidate for a destroyAllTrees method
162 String text
= GetEntryText( pEntry
);
163 SvLBoxEntry
* pNextEntry
= NextSibling( pEntry
) ;
164 deleteTree( pEntry
);
165 GetModel()->Remove( pEntry
);
171 void SFTreeListBox::Init( const ::rtl::OUString
& language
)
173 SetUpdateMode( FALSE
);
177 Reference
< browse::XBrowseNode
> rootNode
;
178 Reference
< XComponentContext
> xCtx
;
180 Sequence
< Reference
< browse::XBrowseNode
> > children
;
182 ::rtl::OUString userStr
= ::rtl::OUString::createFromAscii("user");
183 ::rtl::OUString shareStr
= ::rtl::OUString::createFromAscii("share");
185 ::rtl::OUString singleton
= ::rtl::OUString::createFromAscii(
186 "/singletons/com.sun.star.script.browse.theBrowseNodeFactory" );
190 Reference
< beans::XPropertySet
> xProps(
191 ::comphelper::getProcessServiceFactory(), UNO_QUERY_THROW
);
193 xCtx
.set( xProps
->getPropertyValue( rtl::OUString(
194 RTL_CONSTASCII_USTRINGPARAM("DefaultContext" ))), UNO_QUERY_THROW
);
196 Reference
< browse::XBrowseNodeFactory
> xFac(
197 xCtx
->getValueByName( singleton
), UNO_QUERY_THROW
);
199 rootNode
.set( xFac
->createView(
200 browse::BrowseNodeFactoryViewTypes::MACROORGANIZER
) );
202 if ( rootNode
.is() && rootNode
->hasChildNodes() == sal_True
)
204 children
= rootNode
->getChildNodes();
207 catch( Exception
& e
)
209 OSL_TRACE("Exception getting root browse node from factory: %s",
210 ::rtl::OUStringToOString(
211 e
.Message
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
212 // TODO exception handling
215 Reference
<XModel
> xDocumentModel
;
216 for ( sal_Int32 n
= 0; n
< children
.getLength(); n
++ )
219 ::rtl::OUString uiName
= children
[ n
]->getName();
220 ::rtl::OUString factoryURL
;
221 if ( uiName
.equals( userStr
) || uiName
.equals( shareStr
) )
224 if ( uiName
.equals( userStr
) )
226 uiName
= m_sMyMacros
;
230 uiName
= m_sProdMacros
;
235 xDocumentModel
.set(getDocumentModel(xCtx
, uiName
), UNO_QUERY
);
237 if ( xDocumentModel
.is() )
239 Reference
< ::com::sun::star::frame::XModuleManager
>
240 xModuleManager( xCtx
->getServiceManager()->createInstanceWithContext(
241 ::rtl::OUString::createFromAscii("com.sun.star.frame.ModuleManager"), xCtx
),
244 Reference
<container::XNameAccess
> xModuleConfig(
245 xModuleManager
, UNO_QUERY_THROW
);
246 // get the long name of the document:
247 Sequence
<beans::PropertyValue
> moduleDescr
;
249 ::rtl::OUString appModule
= xModuleManager
->identify( xDocumentModel
);
250 xModuleConfig
->getByName(appModule
) >>= moduleDescr
;
251 } catch(const uno::Exception
&)
254 beans::PropertyValue
const * pmoduleDescr
=
255 moduleDescr
.getConstArray();
256 for ( sal_Int32 pos
= moduleDescr
.getLength(); pos
--; )
258 if (pmoduleDescr
[ pos
].Name
.equalsAsciiL(
259 RTL_CONSTASCII_STRINGPARAM(
260 "ooSetupFactoryEmptyDocumentURL") ))
262 pmoduleDescr
[ pos
].Value
>>= factoryURL
;
269 ::rtl::OUString
lang( language
);
270 Reference
< browse::XBrowseNode
> langEntries
=
271 getLangNodeFromRootNode( children
[ n
], lang
);
273 /*SvLBoxEntry* pBasicManagerRootEntry =*/
274 insertEntry( uiName
, app
? IMG_HARDDISK
: IMG_DOCUMENT
,
275 0, true, std::auto_ptr
< SFEntry
>(new SFEntry( OBJTYPE_SFROOT
, langEntries
, xDocumentModel
)), factoryURL
);
278 SetUpdateMode( TRUE
);
281 Reference
< XInterface
>
282 SFTreeListBox::getDocumentModel( Reference
< XComponentContext
>& xCtx
, ::rtl::OUString
& docName
)
284 Reference
< XInterface
> xModel
;
285 Reference
< lang::XMultiComponentFactory
> mcf
=
286 xCtx
->getServiceManager();
287 Reference
< frame::XDesktop
> desktop (
288 mcf
->createInstanceWithContext(
289 ::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop"), xCtx
),
292 Reference
< container::XEnumerationAccess
> componentsAccess
=
293 desktop
->getComponents();
294 Reference
< container::XEnumeration
> components
=
295 componentsAccess
->createEnumeration();
296 while (components
->hasMoreElements())
298 Reference
< frame::XModel
> model(
299 components
->nextElement(), UNO_QUERY
);
302 ::rtl::OUString sTdocUrl
= ::comphelper::DocumentInfo::getDocumentTitle( model
);
303 if( sTdocUrl
.equals( docName
) )
313 Reference
< browse::XBrowseNode
>
314 SFTreeListBox::getLangNodeFromRootNode( Reference
< browse::XBrowseNode
>& rootNode
, ::rtl::OUString
& language
)
316 Reference
< browse::XBrowseNode
> langNode
;
320 Sequence
< Reference
< browse::XBrowseNode
> > children
= rootNode
->getChildNodes();
321 for ( sal_Int32 n
= 0; n
< children
.getLength(); n
++ )
323 if ( children
[ n
]->getName().equals( language
) )
325 langNode
= children
[ n
];
332 // if getChildNodes() throws an exception we just return
333 // the empty Reference
338 void SFTreeListBox:: RequestSubEntries( SvLBoxEntry
* pRootEntry
, Reference
< ::com::sun::star::script::browse::XBrowseNode
>& node
,
339 Reference
< XModel
>& model
)
346 Sequence
< Reference
< browse::XBrowseNode
> > children
;
349 children
= node
->getChildNodes();
353 // if we catch an exception in getChildNodes then no entries are added
356 for ( sal_Int32 n
= 0; n
< children
.getLength(); n
++ )
358 ::rtl::OUString
name( children
[ n
]->getName() );
359 if ( children
[ n
]->getType() != browse::BrowseNodeTypes::SCRIPT
)
361 insertEntry( name
, IMG_LIB
, pRootEntry
, true, std::auto_ptr
< SFEntry
>(new SFEntry( OBJTYPE_SCRIPTCONTAINER
, children
[ n
],model
)));
365 if ( children
[ n
]->getType() == browse::BrowseNodeTypes::SCRIPT
)
367 insertEntry( name
, IMG_MACRO
, pRootEntry
, false, std::auto_ptr
< SFEntry
>(new SFEntry( OBJTYPE_METHOD
, children
[ n
],model
)));
374 void SFTreeListBox::UpdateEntries()
378 SvLBoxEntry
* SFTreeListBox::FindEntry( SvLBoxEntry
* , const String
& , BYTE
)
383 long SFTreeListBox::ExpandingHdl()
388 void SFTreeListBox::ExpandAllTrees()
392 SvLBoxEntry
* SFTreeListBox::insertEntry(
393 String
const & rText
, USHORT nBitmap
, SvLBoxEntry
* pParent
,
394 bool bChildrenOnDemand
, std::auto_ptr
< SFEntry
> aUserData
, ::rtl::OUString factoryURL
)
397 if( nBitmap
== IMG_DOCUMENT
&& factoryURL
.getLength() > 0 )
399 Image aImage
= SvFileInformationManager::GetFileImage(
400 INetURLObject(factoryURL
), false,
402 Image aHCImage
= SvFileInformationManager::GetFileImage(
403 INetURLObject(factoryURL
), false,
404 BMP_COLOR_HIGHCONTRAST
);
406 rText
, aImage
, aImage
, pParent
, bChildrenOnDemand
, LIST_APPEND
,
407 aUserData
.release()); // XXX possible leak
408 SetExpandedEntryBmp(p
, aHCImage
, BMP_COLOR_HIGHCONTRAST
);
409 SetCollapsedEntryBmp(p
, aHCImage
, BMP_COLOR_HIGHCONTRAST
);
413 p
= insertEntry( rText
, nBitmap
, pParent
, bChildrenOnDemand
, aUserData
);
418 SvLBoxEntry
* SFTreeListBox::insertEntry(
419 String
const & rText
, USHORT nBitmap
, SvLBoxEntry
* pParent
,
420 bool bChildrenOnDemand
, std::auto_ptr
< SFEntry
> aUserData
)
422 Image aHCImage
, aImage
;
423 if( nBitmap
== IMG_HARDDISK
)
426 aHCImage
= m_hdImage_hc
;
428 else if( nBitmap
== IMG_LIB
)
431 aHCImage
= m_libImage_hc
;
433 else if( nBitmap
== IMG_MACRO
)
436 aHCImage
= m_macImage_hc
;
438 else if( nBitmap
== IMG_DOCUMENT
)
441 aHCImage
= m_docImage_hc
;
443 SvLBoxEntry
* p
= InsertEntry(
444 rText
, aImage
, aImage
, pParent
, bChildrenOnDemand
, LIST_APPEND
,
445 aUserData
.release()); // XXX possible leak
446 SetExpandedEntryBmp(p
, aHCImage
, BMP_COLOR_HIGHCONTRAST
);
447 SetCollapsedEntryBmp(p
, aHCImage
, BMP_COLOR_HIGHCONTRAST
);
451 void __EXPORT
SFTreeListBox::RequestingChilds( SvLBoxEntry
* pEntry
)
453 SFEntry
* userData
= 0;
458 userData
= (SFEntry
*)pEntry
->GetUserData();
460 Reference
< browse::XBrowseNode
> node
;
461 Reference
< XModel
> model
;
462 if ( userData
&& !userData
->isLoaded() )
464 node
= userData
->GetNode();
465 model
= userData
->GetModel();
466 RequestSubEntries( pEntry
, node
, model
);
467 userData
->setLoaded();
471 void __EXPORT
SFTreeListBox::ExpandedHdl()
473 /* SvLBoxEntry* pEntry = GetHdlEntry();
474 DBG_ASSERT( pEntry, "Was wurde zugeklappt?" );
476 if ( !IsExpanded( pEntry ) && pEntry->HasChildsOnDemand() )
478 SvLBoxEntry* pChild = FirstChild( pEntry );
481 GetModel()->Remove( pChild ); // Ruft auch den DTOR
482 pChild = FirstChild( pEntry );
487 // ----------------------------------------------------------------------------
488 // InputDialog ------------------------------------------------------------
489 // ----------------------------------------------------------------------------
490 InputDialog::InputDialog(Window
* pParent
, USHORT nMode
)
491 : ModalDialog( pParent
, SVX_RES( RID_DLG_NEWLIB
) ),
492 aText( this, SVX_RES( FT_NEWLIB
) ),
493 aEdit( this, SVX_RES( ED_LIBNAME
) ),
494 aOKButton( this, SVX_RES( PB_OK
) ),
495 aCancelButton( this, SVX_RES( PB_CANCEL
) )
498 if ( nMode
== INPUTMODE_NEWLIB
)
500 SetText( String( SVX_RES( STR_NEWLIB
) ) );
502 else if ( nMode
== INPUTMODE_NEWMACRO
)
504 SetText( String( SVX_RES( STR_NEWMACRO
) ) );
505 aText
.SetText( String( SVX_RES( STR_FT_NEWMACRO
) ) );
507 else if ( nMode
== INPUTMODE_RENAME
)
509 SetText( String( SVX_RES( STR_RENAME
) ) );
510 aText
.SetText( String( SVX_RES( STR_FT_RENAME
) ) );
514 // some resizing so that the text fits
515 Point point
, newPoint
;
519 USHORT style
= TEXT_DRAW_MULTILINE
| TEXT_DRAW_TOP
|
520 TEXT_DRAW_LEFT
| TEXT_DRAW_WORDBREAK
;
522 // get dimensions of dialog instructions control
523 point
= aText
.GetPosPixel();
524 siz
= aText
.GetSizePixel();
526 // get dimensions occupied by text in the control
528 GetTextRect( Rectangle( point
, siz
), aText
.GetText(), style
);
529 newSiz
= rect
.GetSize();
531 // the gap is the difference between the text width and its control width
532 gap
= siz
.Height() - newSiz
.Height();
534 //resize the text field
535 newSiz
= Size( siz
.Width(), siz
.Height() - gap
);
536 aText
.SetSizePixel( newSiz
);
538 //move the OK & cancel buttons
539 point
= aEdit
.GetPosPixel();
540 newPoint
= Point( point
.X(), point
.Y() - gap
);
541 aEdit
.SetPosPixel( newPoint
);
545 InputDialog::~InputDialog()
548 // ----------------------------------------------------------------------------
549 // ScriptOrgDialog ------------------------------------------------------------
550 // ----------------------------------------------------------------------------
551 SvxScriptOrgDialog::SvxScriptOrgDialog( Window
* pParent
, ::rtl::OUString language
)
552 : SfxModalDialog( pParent
, SVX_RES( RID_DLG_SCRIPTORGANIZER
) ),
553 aScriptsTxt( this, SVX_RES( SF_TXT_SCRIPTS
) ),
554 aScriptsBox( this, SVX_RES( SF_CTRL_SCRIPTSBOX
) ),
555 aRunButton( this, SVX_RES( SF_PB_RUN
) ),
556 aCloseButton( this, SVX_RES( SF_PB_CLOSE
) ),
557 aCreateButton( this, SVX_RES( SF_PB_CREATE
) ),
558 aEditButton( this, SVX_RES( SF_PB_EDIT
) ),
559 aRenameButton(this, SVX_RES( SF_PB_RENAME
) ),
560 aDelButton( this, SVX_RES( SF_PB_DEL
) ),
561 aHelpButton( this, SVX_RES( SF_PB_HELP
) ),
562 m_sLanguage( language
),
563 m_delErrStr( SVX_RES( RID_SVXSTR_DELFAILED
) ),
564 m_delErrTitleStr( SVX_RES( RID_SVXSTR_DELFAILED_TITLE
) ),
565 m_delQueryStr( SVX_RES( RID_SVXSTR_DELQUERY
) ),
566 m_delQueryTitleStr( SVX_RES( RID_SVXSTR_DELQUERY_TITLE
) ) ,
567 m_createErrStr( SVX_RES ( RID_SVXSTR_CREATEFAILED
) ),
568 m_createDupStr( SVX_RES ( RID_SVXSTR_CREATEFAILEDDUP
) ),
569 m_createErrTitleStr( SVX_RES( RID_SVXSTR_CREATEFAILED_TITLE
) ),
570 m_renameErrStr( SVX_RES ( RID_SVXSTR_RENAMEFAILED
) ),
571 m_renameErrTitleStr( SVX_RES( RID_SVXSTR_RENAMEFAILED_TITLE
) )
574 // must be a neater way to deal with the strings than as above
575 // append the language to the dialog title
576 String
winTitle( GetText() );
577 winTitle
.SearchAndReplace( String::CreateFromAscii( "%MACROLANG" ), language
.pData
->buffer
);
580 aScriptsBox
.SetSelectHdl( LINK( this, SvxScriptOrgDialog
, ScriptSelectHdl
) );
581 aRunButton
.SetClickHdl( LINK( this, SvxScriptOrgDialog
, ButtonHdl
) );
582 aCloseButton
.SetClickHdl( LINK( this, SvxScriptOrgDialog
, ButtonHdl
) );
583 aRenameButton
.SetClickHdl( LINK( this, SvxScriptOrgDialog
, ButtonHdl
) );
584 aEditButton
.SetClickHdl( LINK( this, SvxScriptOrgDialog
, ButtonHdl
) );
585 aDelButton
.SetClickHdl( LINK( this, SvxScriptOrgDialog
, ButtonHdl
) );
586 aCreateButton
.SetClickHdl( LINK( this, SvxScriptOrgDialog
, ButtonHdl
) );
588 aRunButton
.Disable();
589 aRenameButton
.Disable();
590 aEditButton
.Disable();
591 aDelButton
.Disable();
592 aCreateButton
.Disable();
594 aScriptsBox
.Init( m_sLanguage
);
595 RestorePreviousSelection();
599 __EXPORT
SvxScriptOrgDialog::~SvxScriptOrgDialog()
601 // clear the SelectHdl so that it isn't called during the dtor
602 aScriptsBox
.SetSelectHdl( Link() );
605 short SvxScriptOrgDialog::Execute()
608 SfxObjectShell
*pDoc
= SfxObjectShell::GetFirst();
610 // force load of MSPs for all documents
613 Reference
< provider::XScriptProviderSupplier
> xSPS
=
614 Reference
< provider::XScriptProviderSupplier
>
615 ( pDoc
->GetModel(), UNO_QUERY
);
618 Reference
< provider::XScriptProvider
> ScriptProvider
=
619 xSPS
->getScriptProvider();
622 pDoc
= SfxObjectShell::GetNext(*pDoc
);
624 aScriptsBox
.ExpandAllTrees();
626 Window
* pPrevDlgParent
= Application::GetDefDialogParent();
627 Application::SetDefDialogParent( this );
628 short nRet
= ModalDialog::Execute();
629 Application::SetDefDialogParent( pPrevDlgParent
);
633 void SvxScriptOrgDialog::EnableButton( Button
& , BOOL
)
637 void SvxScriptOrgDialog::CheckButtons( Reference
< browse::XBrowseNode
>& node
)
641 if ( node
->getType() == browse::BrowseNodeTypes::SCRIPT
)
647 aRunButton
.Disable();
649 Reference
< beans::XPropertySet
> xProps( node
, UNO_QUERY
);
653 aEditButton
.Disable();
654 aDelButton
.Disable();
655 aCreateButton
.Disable();
656 aRunButton
.Disable();
660 ::rtl::OUString sName
;
661 sName
= String::CreateFromAscii("Editable") ;
663 if ( getBoolProperty( xProps
, sName
) )
665 aEditButton
.Enable();
669 aEditButton
.Disable();
672 sName
= String::CreateFromAscii("Deletable") ;
674 if ( getBoolProperty( xProps
, sName
) )
680 aDelButton
.Disable();
683 sName
= String::CreateFromAscii("Creatable") ;
685 if ( getBoolProperty( xProps
, sName
) )
687 aCreateButton
.Enable();
691 aCreateButton
.Disable();
694 sName
= String::CreateFromAscii("Renamable") ;
696 if ( getBoolProperty( xProps
, sName
) )
698 aRenameButton
.Enable();
702 aRenameButton
.Disable();
707 // no node info available, disable all configurable actions
708 aDelButton
.Disable();
709 aCreateButton
.Disable();
710 aEditButton
.Disable();
711 aRunButton
.Disable();
712 aRenameButton
.Disable();
716 IMPL_LINK_INLINE_START( SvxScriptOrgDialog
, MacroDoubleClickHdl
, SvTreeListBox
*, EMPTYARG
)
721 IMPL_LINK_INLINE_END( SvxScriptOrgDialog
, MacroDoubleClickHdl
, SvTreeListBox
*, EMPTYARG
)
723 IMPL_LINK( SvxScriptOrgDialog
, ScriptSelectHdl
, SvTreeListBox
*, pBox
)
725 if ( !pBox
->IsSelected( pBox
->GetHdlEntry() ) )
730 SvLBoxEntry
* pEntry
= pBox
->GetHdlEntry();
732 SFEntry
* userData
= 0;
737 userData
= (SFEntry
*)pEntry
->GetUserData();
739 Reference
< browse::XBrowseNode
> node
;
742 node
= userData
->GetNode();
743 CheckButtons( node
);
749 IMPL_LINK( SvxScriptOrgDialog
, ButtonHdl
, Button
*, pButton
)
751 if ( pButton
== &aCloseButton
)
753 StoreCurrentSelection();
756 if ( pButton
== &aEditButton
||
757 pButton
== &aCreateButton
||
758 pButton
== &aDelButton
||
759 pButton
== &aRunButton
||
760 pButton
== &aRenameButton
)
763 if ( aScriptsBox
.IsSelected( aScriptsBox
.GetHdlEntry() ) )
765 SvLBoxEntry
* pEntry
= aScriptsBox
.GetHdlEntry();
766 SFEntry
* userData
= 0;
771 userData
= (SFEntry
*)pEntry
->GetUserData();
774 Reference
< browse::XBrowseNode
> node
;
775 Reference
< XModel
> xModel
;
777 node
= userData
->GetNode();
778 xModel
= userData
->GetModel();
785 if ( pButton
== &aRunButton
)
787 ::rtl::OUString tmpString
;
788 Reference
< beans::XPropertySet
> xProp( node
, UNO_QUERY
);
789 Reference
< provider::XScriptProvider
> mspNode
;
797 Reference
< XEmbeddedScripts
> xEmbeddedScripts( xModel
, UNO_QUERY
);
798 if( !xEmbeddedScripts
.is() )
803 if (!xEmbeddedScripts
->getAllowMacroExecution())
805 // Please FIXME: Show a message box if AllowMacroExecution is false
811 SvLBoxEntry
* pParent
= aScriptsBox
.GetParent( pEntry
);
812 while ( pParent
&& !mspNode
.is() )
814 SFEntry
* mspUserData
= (SFEntry
*)pParent
->GetUserData();
815 mspNode
.set( mspUserData
->GetNode() , UNO_QUERY
);
816 pParent
= aScriptsBox
.GetParent( pParent
);
818 xProp
->getPropertyValue( String::CreateFromAscii("URI" ) ) >>= tmpString
;
819 const String
scriptURL( tmpString
);
825 Reference
< provider::XScript
> xScript(
826 mspNode
->getScript( scriptURL
), UNO_QUERY_THROW
);
828 const Sequence
< Any
> args(0);
830 Sequence
< sal_Int16
> outIndex
;
831 Sequence
< Any
> outArgs( 0 );
832 aRet
= xScript
->invoke( args
, outIndex
, outArgs
);
834 catch ( reflection::InvocationTargetException
& ite
)
836 ::com::sun::star::uno::Any a
= makeAny(ite
);
839 catch ( provider::ScriptFrameworkErrorException
& ite
)
841 ::com::sun::star::uno::Any a
= makeAny(ite
);
844 catch ( RuntimeException
& re
)
846 ::com::sun::star::uno::Any a
= makeAny(re
);
849 catch ( Exception
& e
)
851 ::com::sun::star::uno::Any a
= makeAny(e
);
855 StoreCurrentSelection();
858 else if ( pButton
== &aEditButton
)
860 Reference
< script::XInvocation
> xInv( node
, UNO_QUERY
);
863 StoreCurrentSelection();
865 Sequence
< Any
> args(0);
866 Sequence
< Any
> outArgs( 0 );
867 Sequence
< sal_Int16
> outIndex
;
870 // ISSUE need code to run script here
871 xInv
->invoke( ::rtl::OUString::createFromAscii( "Editable" ), args
, outIndex
, outArgs
);
873 catch( Exception
& e
)
875 OSL_TRACE("Caught exception trying to invoke %s", ::rtl::OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
880 else if ( pButton
== &aCreateButton
)
882 createEntry( pEntry
);
884 else if ( pButton
== &aDelButton
)
886 deleteEntry( pEntry
);
888 else if ( pButton
== &aRenameButton
)
890 renameEntry( pEntry
);
898 Reference
< browse::XBrowseNode
> SvxScriptOrgDialog::getBrowseNode( SvLBoxEntry
* pEntry
)
900 Reference
< browse::XBrowseNode
> node
;
903 SFEntry
* userData
= (SFEntry
*)pEntry
->GetUserData();
906 node
= userData
->GetNode();
913 Reference
< XModel
> SvxScriptOrgDialog::getModel( SvLBoxEntry
* pEntry
)
915 Reference
< XModel
> model
;
918 SFEntry
* userData
= (SFEntry
*)pEntry
->GetUserData();
921 model
= userData
->GetModel();
928 Reference
< XInterface
>
929 SvxScriptOrgDialog::getDocumentModel( Reference
< XComponentContext
>& xCtx
, ::rtl::OUString
& docName
)
931 Reference
< XInterface
> xModel
;
932 Reference
< lang::XMultiComponentFactory
> mcf
=
933 xCtx
->getServiceManager();
934 Reference
< frame::XDesktop
> desktop (
935 mcf
->createInstanceWithContext(
936 ::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop"), xCtx
),
939 Reference
< container::XEnumerationAccess
> componentsAccess
=
940 desktop
->getComponents();
941 Reference
< container::XEnumeration
> components
=
942 componentsAccess
->createEnumeration();
943 while (components
->hasMoreElements())
945 Reference
< frame::XModel
> model(
946 components
->nextElement(), UNO_QUERY
);
949 ::rtl::OUString sTdocUrl
= ::comphelper::DocumentInfo::getDocumentTitle( model
);
950 if( sTdocUrl
.equals( docName
) )
960 void SvxScriptOrgDialog::createEntry( SvLBoxEntry
* pEntry
)
963 Reference
< browse::XBrowseNode
> aChildNode
;
964 Reference
< browse::XBrowseNode
> node
= getBrowseNode( pEntry
);
965 Reference
< script::XInvocation
> xInv( node
, UNO_QUERY
);
969 ::rtl::OUString aNewName
;
970 ::rtl::OUString aNewStdName
;
971 USHORT nMode
= INPUTMODE_NEWLIB
;
972 if( aScriptsBox
.GetModel()->GetDepth( pEntry
) == 0 )
974 aNewStdName
= ::rtl::OUString::createFromAscii( "Library" ) ;
978 aNewStdName
= ::rtl::OUString::createFromAscii( "Macro" ) ;
979 nMode
= INPUTMODE_NEWMACRO
;
981 //do we need L10N for this? ie somethng like:
982 //String aNewStdName( ResId( STR_STDMODULENAME ) );
986 Sequence
< Reference
< browse::XBrowseNode
> > childNodes
;
987 // no children => ok to create Parcel1 or Script1 without checking
990 if( node
->hasChildNodes() == sal_False
)
992 aNewName
= aNewStdName
;
993 aNewName
+= String::CreateFromInt32( i
);
998 childNodes
= node
->getChildNodes();
1001 catch ( Exception
& )
1003 // ignore, will continue on with empty sequence
1006 ::rtl::OUString extn
;
1009 aNewName
= aNewStdName
;
1010 aNewName
+= String::CreateFromInt32( i
);
1011 BOOL bFound
= FALSE
;
1012 if(childNodes
.getLength() > 0 )
1014 ::rtl::OUString nodeName
= childNodes
[0]->getName();
1015 sal_Int32 extnPos
= nodeName
.lastIndexOf( '.' );
1017 extn
= nodeName
.copy(extnPos
);
1019 for( sal_Int32 index
= 0; index
< childNodes
.getLength(); index
++ )
1021 if ( (aNewName
+extn
).equals( childNodes
[index
]->getName() ) )
1037 std::auto_ptr
< InputDialog
> xNewDlg( new InputDialog( static_cast<Window
*>(this), nMode
) );
1038 xNewDlg
->SetObjectName( aNewName
);
1042 if ( xNewDlg
->Execute() && xNewDlg
->GetObjectName().Len() )
1044 ::rtl::OUString aUserSuppliedName
= xNewDlg
->GetObjectName();
1046 for( sal_Int32 index
= 0; index
< childNodes
.getLength(); index
++ )
1048 if ( (aUserSuppliedName
+extn
).equals( childNodes
[index
]->getName() ) )
1051 String
aError( m_createErrStr
);
1052 aError
.Append( m_createDupStr
);
1053 ErrorBox
aErrorBox( static_cast<Window
*>(this), WB_OK
| RET_OK
, aError
);
1054 aErrorBox
.SetText( m_createErrTitleStr
);
1055 aErrorBox
.Execute();
1056 xNewDlg
->SetObjectName( aNewName
);
1061 aNewName
= aUserSuppliedName
;
1065 // user hit cancel or hit OK with nothing in the editbox
1072 // open up parent node (which ensures it's loaded)
1073 aScriptsBox
.RequestingChilds( pEntry
);
1075 Sequence
< Any
> args( 1 );
1076 args
[ 0 ] <<= aNewName
;
1077 Sequence
< Any
> outArgs( 0 );
1078 Sequence
< sal_Int16
> outIndex
;
1082 aResult
= xInv
->invoke( ::rtl::OUString::createFromAscii( "Creatable" ), args
, outIndex
, outArgs
);
1083 Reference
< browse::XBrowseNode
> newNode( aResult
, UNO_QUERY
);
1084 aChildNode
= newNode
;
1087 catch( Exception
& e
)
1089 OSL_TRACE("Caught exception trying to Create %s",
1090 ::rtl::OUStringToOString(
1091 e
.Message
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
1094 if ( aChildNode
.is() )
1096 String aChildName
= aChildNode
->getName();
1097 SvLBoxEntry
* pNewEntry
= NULL
;
1100 ::rtl::OUString
name( aChildName
);
1101 Reference
<XModel
> xDocumentModel
= getModel( pEntry
);
1103 // ISSUE do we need to remove all entries for parent
1104 // to achieve sort? Just need to determine position
1105 // SvTreeListBox::InsertEntry can take position arg
1106 // -- Basic doesn't do this on create.
1107 // Suppose we could avoid this too. -> created nodes are
1108 // not in alphabetical order
1109 if ( aChildNode
->getType() == browse::BrowseNodeTypes::SCRIPT
)
1111 pNewEntry
= aScriptsBox
.insertEntry( aChildName
,
1112 IMG_MACRO
, pEntry
, false, std::auto_ptr
< SFEntry
>(new SFEntry( OBJTYPE_METHOD
, aChildNode
,xDocumentModel
) ) );
1117 pNewEntry
= aScriptsBox
.insertEntry( aChildName
,
1118 IMG_LIB
, pEntry
, false, std::auto_ptr
< SFEntry
>(new SFEntry( OBJTYPE_SCRIPTCONTAINER
, aChildNode
,xDocumentModel
) ) );
1119 // If the Parent is not loaded then set to
1120 // loaded, this will prevent RequestingChilds ( called
1121 // from vcl via RequestingChilds ) from
1122 // creating new ( duplicate ) children
1123 SFEntry
* userData
= (SFEntry
*)pEntry
->GetUserData();
1124 if ( userData
&& !userData
->isLoaded() )
1126 userData
->setLoaded();
1129 aScriptsBox
.SetCurEntry( pNewEntry
);
1130 aScriptsBox
.Select( aScriptsBox
.GetCurEntry() );
1135 //ISSUE L10N & message from exception?
1136 String
aError( m_createErrStr
);
1137 ErrorBox
aErrorBox( static_cast<Window
*>(this), WB_OK
| RET_OK
, aError
);
1138 aErrorBox
.SetText( m_createErrTitleStr
);
1139 aErrorBox
.Execute();
1143 void SvxScriptOrgDialog::renameEntry( SvLBoxEntry
* pEntry
)
1146 Reference
< browse::XBrowseNode
> aChildNode
;
1147 Reference
< browse::XBrowseNode
> node
= getBrowseNode( pEntry
);
1148 Reference
< script::XInvocation
> xInv( node
, UNO_QUERY
);
1152 ::rtl::OUString aNewName
= node
->getName();
1153 sal_Int32 extnPos
= aNewName
.lastIndexOf( '.' );
1154 ::rtl::OUString extn
;
1157 extn
= aNewName
.copy(extnPos
);
1158 aNewName
= aNewName
.copy(0,extnPos
);
1160 USHORT nMode
= INPUTMODE_RENAME
;
1162 std::auto_ptr
< InputDialog
> xNewDlg( new InputDialog( static_cast<Window
*>(this), nMode
) );
1163 xNewDlg
->SetObjectName( aNewName
);
1168 if ( xNewDlg
->Execute() && xNewDlg
->GetObjectName().Len() )
1170 ::rtl::OUString aUserSuppliedName
= xNewDlg
->GetObjectName();
1173 for( sal_Int32 index = 0; index < childNodes.getLength(); index++ )
1175 if ( (aUserSuppliedName+extn).equals( childNodes[index]->getName() ) )
1178 String aError( m_createErrStr );
1179 aError.Append( m_createDupStr );
1180 ErrorBox aErrorBox( static_cast<Window*>(this), WB_OK | RET_OK, aError );
1181 aErrorBox.SetText( m_createErrTitleStr );
1182 aErrorBox.Execute();
1183 xNewDlg->SetObjectName( aNewName );
1188 aNewName
= aUserSuppliedName
;
1192 // user hit cancel or hit OK with nothing in the editbox
1198 Sequence
< Any
> args( 1 );
1199 args
[ 0 ] <<= aNewName
;
1200 Sequence
< Any
> outArgs( 0 );
1201 Sequence
< sal_Int16
> outIndex
;
1205 aResult
= xInv
->invoke( ::rtl::OUString::createFromAscii( "Renamable" ), args
, outIndex
, outArgs
);
1206 Reference
< browse::XBrowseNode
> newNode( aResult
, UNO_QUERY
);
1207 aChildNode
= newNode
;
1210 catch( Exception
& e
)
1212 OSL_TRACE("Caught exception trying to Rename %s",
1213 ::rtl::OUStringToOString(
1214 e
.Message
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
1217 if ( aChildNode
.is() )
1219 aScriptsBox
.SetEntryText( pEntry
, aChildNode
->getName() );
1220 aScriptsBox
.SetCurEntry( pEntry
);
1221 aScriptsBox
.Select( aScriptsBox
.GetCurEntry() );
1226 //ISSUE L10N & message from exception?
1227 String
aError( m_renameErrStr
);
1228 ErrorBox
aErrorBox( static_cast<Window
*>(this), WB_OK
| RET_OK
, aError
);
1229 aErrorBox
.SetText( m_renameErrTitleStr
);
1230 aErrorBox
.Execute();
1233 void SvxScriptOrgDialog::deleteEntry( SvLBoxEntry
* pEntry
)
1235 sal_Bool result
= sal_False
;
1236 Reference
< browse::XBrowseNode
> node
= getBrowseNode( pEntry
);
1237 // ISSUE L10N string & can we centre list?
1238 String
aQuery( m_delQueryStr
);
1239 aQuery
.Append( getListOfChildren( node
, 0 ) );
1240 QueryBox
aQueryBox( static_cast<Window
*>(this), WB_YES_NO
| WB_DEF_YES
, aQuery
);
1241 aQueryBox
.SetText( m_delQueryTitleStr
);
1242 if ( aQueryBox
.Execute() == RET_NO
)
1247 Reference
< script::XInvocation
> xInv( node
, UNO_QUERY
);
1250 Sequence
< Any
> args( 0 );
1251 Sequence
< Any
> outArgs( 0 );
1252 Sequence
< sal_Int16
> outIndex
;
1256 aResult
= xInv
->invoke( ::rtl::OUString::createFromAscii( "Deletable" ), args
, outIndex
, outArgs
);
1257 aResult
>>= result
; // or do we just assume true if no exception ?
1259 catch( Exception
& e
)
1261 OSL_TRACE("Caught exception trying to delete %s",
1262 ::rtl::OUStringToOString(
1263 e
.Message
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
1267 if ( result
== sal_True
)
1269 aScriptsBox
.deleteTree( pEntry
);
1270 aScriptsBox
.GetModel()->Remove( pEntry
);
1274 //ISSUE L10N & message from exception?
1275 ErrorBox
aErrorBox( static_cast<Window
*>(this), WB_OK
| RET_OK
, m_delErrStr
);
1276 aErrorBox
.SetText( m_delErrTitleStr
);
1277 aErrorBox
.Execute();
1282 BOOL
SvxScriptOrgDialog::getBoolProperty( Reference
< beans::XPropertySet
>& xProps
,
1283 ::rtl::OUString
& propName
)
1285 BOOL result
= false;
1288 sal_Bool bTemp
= sal_False
;
1289 xProps
->getPropertyValue( propName
) >>= bTemp
;
1290 result
= ( bTemp
== sal_True
);
1292 catch ( Exception
& )
1299 String
SvxScriptOrgDialog::getListOfChildren( Reference
< browse::XBrowseNode
> node
, int depth
)
1302 result
.Append( String::CreateFromAscii( "\n" ) );
1303 for( int i
=0;i
<=depth
;i
++ )
1305 result
.Append( String::CreateFromAscii( "\t" ) );
1307 result
.Append( String( node
->getName() ) );
1311 if ( node
->hasChildNodes() == sal_True
)
1313 Sequence
< Reference
< browse::XBrowseNode
> > children
1314 = node
->getChildNodes();
1315 for ( sal_Int32 n
= 0; n
< children
.getLength(); n
++ )
1317 result
.Append( getListOfChildren( children
[ n
] , depth
+1 ) );
1321 catch ( Exception
& )
1323 // ignore, will return an empty string
1329 Selection_hash
SvxScriptOrgDialog::m_lastSelection
;
1331 void SvxScriptOrgDialog::StoreCurrentSelection()
1333 String aDescription
;
1334 if ( aScriptsBox
.IsSelected( aScriptsBox
.GetHdlEntry() ) )
1336 SvLBoxEntry
* pEntry
= aScriptsBox
.GetHdlEntry();
1339 aDescription
.Insert( aScriptsBox
.GetEntryText( pEntry
), 0 );
1340 pEntry
= aScriptsBox
.GetParent( pEntry
);
1342 aDescription
.Insert( ';', 0 );
1344 ::rtl::OUString
sDesc( aDescription
);
1345 m_lastSelection
[ m_sLanguage
] = sDesc
;
1349 void SvxScriptOrgDialog::RestorePreviousSelection()
1351 String aStoredEntry
= String( m_lastSelection
[ m_sLanguage
] );
1352 if( aStoredEntry
.Len() <= 0 )
1354 SvLBoxEntry
* pEntry
= 0;
1356 while ( nIndex
!= STRING_NOTFOUND
)
1358 String
aTmp( aStoredEntry
.GetToken( 0, ';', nIndex
) );
1359 SvLBoxEntry
* pTmpEntry
= aScriptsBox
.FirstChild( pEntry
);
1360 ::rtl::OUString
debugStr(aTmp
);
1363 debugStr
= ::rtl::OUString(aScriptsBox
.GetEntryText( pTmpEntry
));
1364 if ( aScriptsBox
.GetEntryText( pTmpEntry
) == aTmp
)
1369 pTmpEntry
= aScriptsBox
.NextSibling( pTmpEntry
);
1373 aScriptsBox
.RequestingChilds( pEntry
);
1375 aScriptsBox
.SetCurEntry( pEntry
);
1378 BOOL
SFTreeListBox::dialogSort1( Reference
< browse::XBrowseNode
> node1
,
1379 Reference
< browse::XBrowseNode
> node2
)
1381 ::rtl::OUString userStr
= ::rtl::OUString::createFromAscii("user");
1382 ::rtl::OUString shareStr
= ::rtl::OUString::createFromAscii("share");
1383 if( node1
->getName().equals( userStr
) )
1385 if( node2
->getName().equals( userStr
) )
1387 if( node1
->getName().equals( shareStr
) )
1389 if( node2
->getName().equals( shareStr
) )
1391 return dialogSort2( node1
, node2
);
1394 BOOL
SFTreeListBox::dialogSort2( Reference
< browse::XBrowseNode
> node1
,
1395 Reference
< browse::XBrowseNode
> node2
)
1397 return ( node1
->getName().compareTo( node2
->getName() ) < 0 );
1400 ::rtl::OUString
ReplaceString(
1401 const ::rtl::OUString
& source
,
1402 const ::rtl::OUString
& token
,
1403 const ::rtl::OUString
& value
)
1405 sal_Int32 pos
= source
.indexOf( token
);
1407 if ( pos
!= -1 && value
.getLength() != 0 )
1409 return source
.replaceAt( pos
, token
.getLength(), value
);
1417 ::rtl::OUString
FormatErrorString(
1418 const ::rtl::OUString
& unformatted
,
1419 const ::rtl::OUString
& language
,
1420 const ::rtl::OUString
& script
,
1421 const ::rtl::OUString
& line
,
1422 const ::rtl::OUString
& type
,
1423 const ::rtl::OUString
& message
)
1425 ::rtl::OUString result
= unformatted
.copy( 0 );
1427 result
= ReplaceString(
1428 result
, ::rtl::OUString::createFromAscii( "%LANGUAGENAME" ), language
);
1429 result
= ReplaceString(
1430 result
, ::rtl::OUString::createFromAscii( "%SCRIPTNAME" ), script
);
1431 result
= ReplaceString(
1432 result
, ::rtl::OUString::createFromAscii( "%LINENUMBER" ), line
);
1434 if ( type
.getLength() != 0 )
1436 result
+= ::rtl::OUString::createFromAscii( "\n\n" );
1437 result
+= ::rtl::OUString(String(SVX_RES(RID_SVXSTR_ERROR_TYPE_LABEL
)));
1438 result
+= ::rtl::OUString::createFromAscii( " " );
1442 if ( message
.getLength() != 0 )
1444 result
+= ::rtl::OUString::createFromAscii( "\n\n" );
1445 result
+= ::rtl::OUString(String(SVX_RES(RID_SVXSTR_ERROR_MESSAGE_LABEL
)));
1446 result
+= ::rtl::OUString::createFromAscii( " " );
1453 ::rtl::OUString
GetErrorMessage(
1454 const provider::ScriptErrorRaisedException
& eScriptError
)
1456 ::rtl::OUString unformatted
= String( SVX_RES( RID_SVXSTR_ERROR_AT_LINE
) );
1458 ::rtl::OUString unknown
= ::rtl::OUString::createFromAscii( "UNKNOWN" );
1459 ::rtl::OUString language
= unknown
;
1460 ::rtl::OUString script
= unknown
;
1461 ::rtl::OUString line
= unknown
;
1462 ::rtl::OUString type
= ::rtl::OUString();
1463 ::rtl::OUString message
= eScriptError
.Message
;
1465 if ( eScriptError
.language
.getLength() != 0 )
1467 language
= eScriptError
.language
;
1470 if ( eScriptError
.scriptName
.getLength() != 0 )
1472 script
= eScriptError
.scriptName
;
1475 if ( eScriptError
.Message
.getLength() != 0 )
1477 message
= eScriptError
.Message
;
1479 if ( eScriptError
.lineNum
!= -1 )
1481 line
= ::rtl::OUString::valueOf( eScriptError
.lineNum
);
1482 unformatted
= String(
1483 SVX_RES( RID_SVXSTR_ERROR_AT_LINE
) );
1487 unformatted
= String(
1488 SVX_RES( RID_SVXSTR_ERROR_RUNNING
) );
1491 return FormatErrorString(
1492 unformatted
, language
, script
, line
, type
, message
);
1495 ::rtl::OUString
GetErrorMessage(
1496 const provider::ScriptExceptionRaisedException
& eScriptException
)
1498 ::rtl::OUString unformatted
=
1499 String( SVX_RES( RID_SVXSTR_EXCEPTION_AT_LINE
) );
1501 ::rtl::OUString unknown
= ::rtl::OUString::createFromAscii( "UNKNOWN" );
1502 ::rtl::OUString language
= unknown
;
1503 ::rtl::OUString script
= unknown
;
1504 ::rtl::OUString line
= unknown
;
1505 ::rtl::OUString type
= unknown
;
1506 ::rtl::OUString message
= eScriptException
.Message
;
1508 if ( eScriptException
.language
.getLength() != 0 )
1510 language
= eScriptException
.language
;
1512 if ( eScriptException
.scriptName
.getLength() != 0 )
1514 script
= eScriptException
.scriptName
;
1517 if ( eScriptException
.Message
.getLength() != 0 )
1519 message
= eScriptException
.Message
;
1522 if ( eScriptException
.lineNum
!= -1 )
1524 line
= ::rtl::OUString::valueOf( eScriptException
.lineNum
);
1525 unformatted
= String(
1526 SVX_RES( RID_SVXSTR_EXCEPTION_AT_LINE
) );
1530 unformatted
= String(
1531 SVX_RES( RID_SVXSTR_EXCEPTION_RUNNING
) );
1534 if ( eScriptException
.exceptionType
.getLength() != 0 )
1536 type
= eScriptException
.exceptionType
;
1539 return FormatErrorString(
1540 unformatted
, language
, script
, line
, type
, message
);
1543 ::rtl::OUString
GetErrorMessage(
1544 const provider::ScriptFrameworkErrorException
& sError
)
1546 ::rtl::OUString unformatted
= String(
1547 SVX_RES( RID_SVXSTR_FRAMEWORK_ERROR_RUNNING
) );
1549 ::rtl::OUString language
=
1550 ::rtl::OUString::createFromAscii( "UNKNOWN" );
1552 ::rtl::OUString script
=
1553 ::rtl::OUString::createFromAscii( "UNKNOWN" );
1555 ::rtl::OUString message
;
1557 if ( sError
.scriptName
.getLength() > 0 )
1559 script
= sError
.scriptName
;
1561 if ( sError
.language
.getLength() > 0 )
1563 language
= sError
.language
;
1565 if ( sError
.errorType
== provider::ScriptFrameworkErrorType::NOTSUPPORTED
)
1568 SVX_RES( RID_SVXSTR_ERROR_LANG_NOT_SUPPORTED
) );
1569 message
= ReplaceString(
1570 message
, ::rtl::OUString::createFromAscii( "%LANGUAGENAME" ), language
);
1575 message
= sError
.Message
;
1577 return FormatErrorString(
1578 unformatted
, language
, script
, ::rtl::OUString(), ::rtl::OUString(), message
);
1581 ::rtl::OUString
GetErrorMessage( const RuntimeException
& re
)
1583 Type t
= ::getCppuType( &re
);
1584 ::rtl::OUString message
= t
.getTypeName();
1585 message
+= re
.Message
;
1590 ::rtl::OUString
GetErrorMessage( const Exception
& e
)
1592 Type t
= ::getCppuType( &e
);
1593 ::rtl::OUString message
= t
.getTypeName();
1594 message
+= e
.Message
;
1599 ::rtl::OUString
GetErrorMessage( const com::sun::star::uno::Any
& aException
)
1601 ::rtl::OUString exType
;
1602 if ( aException
.getValueType() ==
1603 ::getCppuType( (const reflection::InvocationTargetException
* ) NULL
) )
1605 reflection::InvocationTargetException ite
;
1607 if ( ite
.TargetException
.getValueType() == ::getCppuType( ( const provider::ScriptErrorRaisedException
* ) NULL
) )
1609 // Error raised by script
1610 provider::ScriptErrorRaisedException scriptError
;
1611 ite
.TargetException
>>= scriptError
;
1612 return GetErrorMessage( scriptError
);
1614 else if ( ite
.TargetException
.getValueType() == ::getCppuType( ( const provider::ScriptExceptionRaisedException
* ) NULL
) )
1616 // Exception raised by script
1617 provider::ScriptExceptionRaisedException scriptException
;
1618 ite
.TargetException
>>= scriptException
;
1619 return GetErrorMessage( scriptException
);
1623 // Unknown error, shouldn't happen
1628 else if ( aException
.getValueType() == ::getCppuType( ( const provider::ScriptFrameworkErrorException
* ) NULL
) )
1630 // A Script Framework error has occured
1631 provider::ScriptFrameworkErrorException sfe
;
1633 return GetErrorMessage( sfe
);
1636 // unknown exception
1638 RuntimeException rte
;
1639 if ( aException
>>= rte
)
1641 return GetErrorMessage( rte
);
1645 return GetErrorMessage( e
);
1649 SvxScriptErrorDialog::SvxScriptErrorDialog(
1650 Window
* , ::com::sun::star::uno::Any aException
)
1653 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1654 m_sMessage
= GetErrorMessage( aException
);
1657 SvxScriptErrorDialog::~SvxScriptErrorDialog()
1661 short SvxScriptErrorDialog::Execute()
1663 // Show Error dialog asynchronously
1665 // Pass a copy of the message to the ShowDialog method as the
1666 // SvxScriptErrorDialog may be deleted before ShowDialog is called
1667 Application::PostUserEvent(
1668 LINK( this, SvxScriptErrorDialog
, ShowDialog
),
1669 new rtl::OUString( m_sMessage
) );
1674 IMPL_LINK( SvxScriptErrorDialog
, ShowDialog
, ::rtl::OUString
*, pMessage
)
1676 ::rtl::OUString message
;
1678 if ( pMessage
&& pMessage
->getLength() != 0 )
1680 message
= *pMessage
;
1684 message
= String( SVX_RES( RID_SVXSTR_ERROR_TITLE
) );
1687 MessBox
* pBox
= new WarningBox( NULL
, WB_OK
, message
);
1688 pBox
->SetText( SVX_RES( RID_SVXSTR_ERROR_TITLE
) );
1691 if ( pBox
) delete pBox
;
1692 if ( pMessage
) delete pMessage
;