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: selector.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"
33 #include <vcl/help.hxx>
34 #ifndef _MSGBOX_HXX //autogen
35 #include <vcl/msgbox.hxx>
37 #include <vcl/metric.hxx>
39 #include "selector.hxx"
40 #include <svx/dialmgr.hxx>
42 #include "selector.hrc"
43 #include "fmresids.hrc"
44 #include <svx/dialogs.hrc>
46 #include <sfx2/app.hxx>
47 #include <sfx2/msg.hxx>
48 #include <sfx2/msgpool.hxx>
49 #include <sfx2/macrconf.hxx>
50 #include <sfx2/minfitem.hxx>
51 #include <sfx2/objsh.hxx>
52 #include <sfx2/dispatch.hxx>
54 #include <comphelper/documentinfo.hxx>
55 #include <comphelper/processfactory.hxx>
56 #include <comphelper/componentcontext.hxx>
58 /** === begin UNO includes === **/
59 #include <com/sun/star/beans/XPropertySet.hpp>
60 #include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
61 #include <com/sun/star/script/provider/XScriptProvider.hpp>
62 #include <com/sun/star/script/browse/XBrowseNode.hpp>
63 #include <com/sun/star/script/browse/BrowseNodeTypes.hpp>
64 #include <com/sun/star/script/browse/XBrowseNodeFactory.hpp>
65 #include <com/sun/star/script/browse/BrowseNodeFactoryViewTypes.hpp>
66 #include <com/sun/star/frame/XModuleManager.hpp>
67 #include <com/sun/star/frame/XDesktop.hpp>
68 #include <com/sun/star/container/XEnumerationAccess.hpp>
69 #include <com/sun/star/container/XEnumeration.hpp>
70 #include <com/sun/star/document/XEmbeddedScripts.hpp>
71 #include <com/sun/star/document/XScriptInvocationContext.hpp>
72 #include <com/sun/star/frame/XDispatchInformationProvider.hpp>
73 #include <com/sun/star/frame/DispatchInformation.hpp>
74 #include <com/sun/star/container/XChild.hpp>
75 /** === end UNO includes === **/
77 using ::rtl::OUString
;
78 using namespace ::com::sun::star
;
79 using namespace ::com::sun::star::uno
;
80 using namespace ::com::sun::star::script
;
81 using namespace ::com::sun::star::frame
;
82 using namespace ::com::sun::star::document
;
83 using namespace ::com::sun::star::container
;
85 #define _SVSTDARR_STRINGSDTOR
86 #include <svtools/svstdarr.hxx>
87 #include <svtools/imagemgr.hxx>
88 #include <tools/urlobj.hxx>
89 #include <tools/diagnose_ex.h>
91 SV_IMPL_PTRARR(SvxGroupInfoArr_Impl
, SvxGroupInfoPtr
);
94 * The implementations of SvxConfigFunctionListBox_Impl and
95 * SvxConfigGroupListBox_Impl are copied from sfx2/source/dialog/cfg.cxx
97 SvxConfigFunctionListBox_Impl::SvxConfigFunctionListBox_Impl( Window
* pParent
, const ResId
& rResId
)
98 : SvTreeListBox( pParent
, rResId
)
100 , m_pDraggingEntry( 0 )
102 SetWindowBits( GetStyle() | WB_CLIPCHILDREN
| WB_HSCROLL
| WB_SORT
);
103 GetModel()->SetSortMode( SortAscending
);
105 // Timer f"ur die BallonHelp
106 aTimer
.SetTimeout( 200 );
107 aTimer
.SetTimeoutHdl(
108 LINK( this, SvxConfigFunctionListBox_Impl
, TimerHdl
) );
111 SvxConfigFunctionListBox_Impl::~SvxConfigFunctionListBox_Impl()
116 SvLBoxEntry
* SvxConfigFunctionListBox_Impl::GetLastSelectedEntry()
118 if ( m_pDraggingEntry
!= NULL
)
120 return m_pDraggingEntry
;
124 return FirstSelected();
128 void SvxConfigFunctionListBox_Impl::MouseMove( const MouseEvent
& rMEvt
)
130 Point aMousePos
= rMEvt
.GetPosPixel();
131 pCurEntry
= GetCurEntry();
133 if ( pCurEntry
&& GetEntry( aMousePos
) == pCurEntry
)
137 Help::ShowBalloon( this, aMousePos
, String() );
143 IMPL_LINK( SvxConfigFunctionListBox_Impl
, TimerHdl
, Timer
*, EMPTYARG
)
146 Point aMousePos
= GetPointerPosPixel();
147 SvLBoxEntry
*pEntry
= GetCurEntry();
148 if ( pEntry
&& GetEntry( aMousePos
) == pEntry
&& pCurEntry
== pEntry
)
149 Help::ShowBalloon( this, OutputToScreenPixel( aMousePos
), GetHelpText( pEntry
) );
153 void SvxConfigFunctionListBox_Impl::ClearAll()
155 USHORT nCount
= aArr
.Count();
156 for ( USHORT i
=0; i
<nCount
; i
++ )
158 SvxGroupInfo_Impl
*pData
= aArr
[i
];
162 aArr
.Remove( 0, nCount
);
166 SvLBoxEntry
* SvxConfigFunctionListBox_Impl::GetEntry_Impl( const String
& rName
)
168 SvLBoxEntry
*pEntry
= First();
171 if ( GetEntryText( pEntry
) == rName
)
173 pEntry
= Next( pEntry
);
179 SvLBoxEntry
* SvxConfigFunctionListBox_Impl::GetEntry_Impl( USHORT nId
)
181 SvLBoxEntry
*pEntry
= First();
184 SvxGroupInfo_Impl
*pData
= (SvxGroupInfo_Impl
*) pEntry
->GetUserData();
185 if ( pData
&& pData
->nOrd
== nId
)
187 pEntry
= Next( pEntry
);
193 USHORT
SvxConfigFunctionListBox_Impl::GetId( SvLBoxEntry
*pEntry
)
195 SvxGroupInfo_Impl
*pData
= pEntry
?
196 (SvxGroupInfo_Impl
*) pEntry
->GetUserData() : 0;
202 String
SvxConfigFunctionListBox_Impl::GetHelpText( SvLBoxEntry
*pEntry
)
204 // Information zum selektierten Entry aus den Userdaten holen
205 SvxGroupInfo_Impl
*pInfo
=
206 pEntry
? (SvxGroupInfo_Impl
*) pEntry
->GetUserData(): 0;
210 if ( pInfo
->nKind
== SVX_CFGFUNCTION_SLOT
)
212 OUString
aCmdURL( pInfo
->sURL
);
214 OUString aHelpText
= Application::GetHelp()->GetHelpText( aCmdURL
, this );
218 else if ( pInfo
->nKind
== SVX_CFGFUNCTION_SCRIPT
)
220 return pInfo
->sHelpText
;
227 void SvxConfigFunctionListBox_Impl::FunctionSelected()
229 Help::ShowBalloon( this, Point(), String() );
232 // drag and drop support
233 DragDropMode
SvxConfigFunctionListBox_Impl::NotifyStartDrag(
234 TransferDataContainer
& /*aTransferDataContainer*/, SvLBoxEntry
* pEntry
)
236 m_pDraggingEntry
= pEntry
;
237 return GetDragDropMode();
240 void SvxConfigFunctionListBox_Impl::DragFinished( sal_Int8
/*nDropAction*/ )
242 m_pDraggingEntry
= NULL
;
246 SvxConfigFunctionListBox_Impl::AcceptDrop( const AcceptDropEvent
& /*rEvt*/ )
248 return DND_ACTION_NONE
;
251 SvxConfigGroupListBox_Impl::SvxConfigGroupListBox_Impl(
252 Window
* pParent
, const ResId
& rResId
,
253 bool _bShowSlots
, const Reference
< frame::XFrame
>& xFrame
)
254 : SvTreeListBox( pParent
, rResId
)
255 , m_bShowSlots( _bShowSlots
),
256 m_hdImage(ResId(IMG_HARDDISK
,*rResId
.GetResMgr())),
257 m_hdImage_hc(ResId(IMG_HARDDISK_HC
,*rResId
.GetResMgr())),
258 m_libImage(ResId(IMG_LIB
,*rResId
.GetResMgr())),
259 m_libImage_hc(ResId(IMG_LIB_HC
,*rResId
.GetResMgr())),
260 m_macImage(ResId(IMG_MACRO
,*rResId
.GetResMgr())),
261 m_macImage_hc(ResId(IMG_MACRO_HC
,*rResId
.GetResMgr())),
262 m_docImage(ResId(IMG_DOC
,*rResId
.GetResMgr())),
263 m_docImage_hc(ResId(IMG_DOC_HC
,*rResId
.GetResMgr())),
264 m_sMyMacros(String(ResId(STR_MYMACROS
,*rResId
.GetResMgr()))),
265 m_sProdMacros(String(ResId(STR_PRODMACROS
,*rResId
.GetResMgr())))
269 if ( xFrame
!= NULL
)
271 m_xFrame
.set( xFrame
);
274 SetWindowBits( GetStyle() | WB_CLIPCHILDREN
| WB_HSCROLL
| WB_HASBUTTONS
| WB_HASLINES
| WB_HASLINESATROOT
| WB_HASBUTTONSATROOT
);
276 ImageList
aNavigatorImages( SVX_RES( RID_SVXIMGLIST_FMEXPL
) );
279 aNavigatorImages
.GetImage( RID_SVXIMG_COLLAPSEDNODE
),
280 aNavigatorImages
.GetImage( RID_SVXIMG_EXPANDEDNODE
),
284 aNavigatorImages
.GetImage( RID_SVXIMG_COLLAPSEDNODE
),
285 aNavigatorImages
.GetImage( RID_SVXIMG_EXPANDEDNODE
),
286 BMP_COLOR_HIGHCONTRAST
);
290 SvxConfigGroupListBox_Impl::~SvxConfigGroupListBox_Impl()
295 void SvxConfigGroupListBox_Impl::ClearAll()
297 USHORT nCount
= aArr
.Count();
298 for ( USHORT i
=0; i
<nCount
; i
++ )
300 SvxGroupInfo_Impl
*pData
= aArr
[i
];
304 aArr
.Remove( 0, nCount
);
308 //-----------------------------------------------
311 //...........................................
312 /** examines a component whether it supports XEmbeddedScripts, or provides access to such a
313 component by implementing XScriptInvocationContext.
315 the model which supports the embedded scripts, or <NULL/> if it cannot find such a
318 static Reference
< XModel
> lcl_getDocumentWithScripts_throw( const Reference
< XInterface
>& _rxComponent
)
320 Reference
< XEmbeddedScripts
> xScripts( _rxComponent
, UNO_QUERY
);
321 if ( !xScripts
.is() )
323 Reference
< XScriptInvocationContext
> xContext( _rxComponent
, UNO_QUERY
);
325 xScripts
.set( xContext
->getScriptContainer(), UNO_QUERY
);
328 return Reference
< XModel
>( xScripts
, UNO_QUERY
);
331 //...........................................
332 static Reference
< XModel
> lcl_getScriptableDocument_nothrow( const Reference
< XFrame
>& _rxFrame
)
334 Reference
< XModel
> xDocument
;
336 // examine our associated frame
339 OSL_ENSURE( _rxFrame
.is(), "lcl_getScriptableDocument_nothrow: you need to pass a frame to this dialog/tab page!" );
342 // first try the model in the frame
343 Reference
< XController
> xController( _rxFrame
->getController(), UNO_SET_THROW
);
344 xDocument
= lcl_getDocumentWithScripts_throw( xController
->getModel() );
346 if ( !xDocument
.is() )
348 // if there is no suitable document in the frame, try the controller
349 xDocument
= lcl_getDocumentWithScripts_throw( _rxFrame
->getController() );
353 catch( const Exception
& )
355 DBG_UNHANDLED_EXCEPTION();
362 void SvxConfigGroupListBox_Impl::fillScriptList( const Reference
< browse::XBrowseNode
>& _rxRootNode
, SvLBoxEntry
* _pParentEntry
, bool _bCheapChildsOnDemand
)
364 OSL_PRECOND( _rxRootNode
.is(), "SvxConfigGroupListBox_Impl::fillScriptList: invalid root node!" );
365 if ( !_rxRootNode
.is() )
370 if ( _rxRootNode
->hasChildNodes() )
372 Sequence
< Reference
< browse::XBrowseNode
> > children
=
373 _rxRootNode
->getChildNodes();
375 BOOL bIsRootNode
= _rxRootNode
->getName().equalsAscii("Root");
377 /* To mimic current starbasic behaviour we
378 need to make sure that only the current document
379 is displayed in the config tree. Tests below
380 set the bDisplay flag to FALSE if the current
381 node is a first level child of the Root and is NOT
382 either the current document, user or share */
383 OUString sCurrentDocTitle
;
384 Reference
< XModel
> xWorkingDocument
= lcl_getScriptableDocument_nothrow( m_xFrame
);
385 if ( xWorkingDocument
.is() )
387 sCurrentDocTitle
= ::comphelper::DocumentInfo::getDocumentTitle( xWorkingDocument
);
390 for ( long n
= 0; n
< children
.getLength(); n
++ )
392 Reference
< browse::XBrowseNode
>& theChild
= children
[n
];
393 //#139111# some crash reports show that it might be unset
394 if ( !theChild
.is() )
396 ::rtl::OUString sUIName
= theChild
->getName();
397 BOOL bDisplay
= TRUE
;
400 || ( m_bShowSlots
&& _pParentEntry
&& ( GetModel()->GetDepth( _pParentEntry
) == 0 ) )
401 // if we show slots (as in the customize dialog)
402 // then the user & share are added at depth=1
405 if ( sUIName
.equalsAscii( "user" ) )
407 sUIName
= m_sMyMacros
;
408 bIsRootNode
= sal_True
;
410 else if ( sUIName
.equalsAscii( "share" ) )
412 sUIName
= m_sProdMacros
;
413 bIsRootNode
= sal_True
;
415 else if ( !sUIName
.equals( sCurrentDocTitle
) )
424 if ( children
[n
]->getType() == browse::BrowseNodeTypes::SCRIPT
)
427 SvLBoxEntry
* pNewEntry
= InsertEntry( sUIName
, _pParentEntry
);
429 ::comphelper::ComponentContext
aContext( ::comphelper::getProcessServiceFactory() );
430 Image aImage
= GetImage( theChild
, aContext
.getUNOContext(), bIsRootNode
, BMP_COLOR_NORMAL
);
431 SetExpandedEntryBmp( pNewEntry
, aImage
, BMP_COLOR_NORMAL
);
432 SetCollapsedEntryBmp( pNewEntry
, aImage
, BMP_COLOR_NORMAL
);
434 aImage
= GetImage( theChild
, aContext
.getUNOContext(), bIsRootNode
, BMP_COLOR_HIGHCONTRAST
);
435 SetExpandedEntryBmp( pNewEntry
, aImage
, BMP_COLOR_HIGHCONTRAST
);
436 SetCollapsedEntryBmp( pNewEntry
, aImage
, BMP_COLOR_HIGHCONTRAST
);
438 SvxGroupInfo_Impl
* pInfo
=
439 new SvxGroupInfo_Impl( SVX_CFGGROUP_SCRIPTCONTAINER
, 0, theChild
);
440 pNewEntry
->SetUserData( pInfo
);
441 aArr
.Insert( pInfo
, aArr
.Count() );
443 if ( _bCheapChildsOnDemand
)
445 /* i30923 - Would be nice if there was a better
446 * way to determine if a basic lib had children
447 * without having to ask for them (which forces
448 * the library to be loaded */
449 pNewEntry
->EnableChildsOnDemand( TRUE
);
453 // if there are granchildren we're interested in, display the '+' before
454 // the entry, but do not yet expand
455 Sequence
< Reference
< browse::XBrowseNode
> > grandchildren
=
456 children
[n
]->getChildNodes();
458 for ( sal_Int32 m
= 0; m
< grandchildren
.getLength(); m
++ )
460 if ( grandchildren
[m
]->getType() == browse::BrowseNodeTypes::CONTAINER
)
462 pNewEntry
->EnableChildsOnDemand( TRUE
);
470 catch (const Exception
&)
472 DBG_UNHANDLED_EXCEPTION();
476 void SvxConfigGroupListBox_Impl::Init()
478 SetUpdateMode(FALSE
);
481 Reference
< XComponentContext
> xContext
;
482 Reference
< beans::XPropertySet
> xProps(
483 ::comphelper::getProcessServiceFactory(), UNO_QUERY_THROW
);
485 xContext
.set( xProps
->getPropertyValue(
486 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))),
489 // are we showing builtin commands?
490 if ( m_bShowSlots
&& xContext
.is() && m_xFrame
.is() )
492 Reference
< lang::XMultiComponentFactory
> xMCF
=
493 xContext
->getServiceManager();
495 Reference
< frame::XDispatchInformationProvider
> xDIP(
496 m_xFrame
, UNO_QUERY
);
498 Reference
< ::com::sun::star::frame::XModuleManager
>
499 xModuleManager( xMCF
->createInstanceWithContext(
500 OUString::createFromAscii(
501 "com.sun.star.frame.ModuleManager" ),
507 aModuleId
= xModuleManager
->identify( m_xFrame
);
508 }catch(const uno::Exception
&)
509 { aModuleId
= ::rtl::OUString(); }
511 Reference
< container::XNameAccess
> xNameAccess(
512 xMCF
->createInstanceWithContext(
513 OUString::createFromAscii(
514 "com.sun.star.frame.UICommandDescription" ),
518 if ( xNameAccess
.is() )
520 xNameAccess
->getByName( aModuleId
) >>= m_xModuleCommands
;
523 Reference
< container::XNameAccess
> xAllCategories(
524 xMCF
->createInstanceWithContext(
525 OUString::createFromAscii(
526 "com.sun.star.ui.UICategoryDescription" ),
530 Reference
< container::XNameAccess
> xModuleCategories
;
531 if ( xAllCategories
.is() )
533 if ( aModuleId
.getLength() != 0 )
537 xModuleCategories
= Reference
< container::XNameAccess
>(
538 xAllCategories
->getByName( aModuleId
), UNO_QUERY
);
540 catch ( container::NoSuchElementException
& )
545 if ( !xModuleCategories
.is() )
547 xModuleCategories
= xAllCategories
;
551 if ( xModuleCategories
.is() )
553 Sequence
< sal_Int16
> gids
=
554 xDIP
->getSupportedCommandGroups();
556 for ( sal_Int32 i
= 0; i
< gids
.getLength(); i
++ )
558 Sequence
< frame::DispatchInformation
> commands
;
562 xDIP
->getConfigurableDispatchInformation( gids
[i
] );
564 catch ( container::NoSuchElementException
& )
569 if ( commands
.getLength() == 0 )
574 sal_Int32 gid
= gids
[i
];
575 OUString idx
= OUString::valueOf( gid
);
576 OUString group
= idx
;
579 xModuleCategories
->getByName( idx
) >>= group
;
581 catch ( container::NoSuchElementException
& )
585 SvLBoxEntry
*pEntry
= InsertEntry( group
, NULL
);
587 SvxGroupInfo_Impl
*pInfo
=
588 new SvxGroupInfo_Impl( SVX_CFGGROUP_FUNCTION
, gids
[i
] );
589 aArr
.Insert( pInfo
, aArr
.Count() );
591 pEntry
->SetUserData( pInfo
);
598 // Add Scripting Framework entries
599 Reference
< browse::XBrowseNode
> rootNode
;
600 Reference
< XComponentContext
> xCtx
;
604 Reference
< beans::XPropertySet
> _xProps(
605 ::comphelper::getProcessServiceFactory(), UNO_QUERY_THROW
);
606 xCtx
.set( _xProps
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), UNO_QUERY_THROW
);
607 Reference
< browse::XBrowseNodeFactory
> xFac( xCtx
->getValueByName(
608 OUString::createFromAscii( "/singletons/com.sun.star.script.browse.theBrowseNodeFactory") ), UNO_QUERY_THROW
);
609 rootNode
.set( xFac
->createView( browse::BrowseNodeFactoryViewTypes::MACROSELECTOR
) );
611 catch( const Exception
& )
613 DBG_UNHANDLED_EXCEPTION();
620 SvxGroupInfo_Impl
*pInfo
=
621 new SvxGroupInfo_Impl( SVX_CFGGROUP_SCRIPTCONTAINER
, 0, rootNode
);
624 String( SVX_RES( STR_SELECTOR_MACROS
) );
626 SvLBoxEntry
*pNewEntry
= InsertEntry( aTitle
, NULL
);
627 pNewEntry
->SetUserData( pInfo
);
628 pNewEntry
->EnableChildsOnDemand( TRUE
);
629 aArr
.Insert( pInfo
, aArr
.Count() );
633 fillScriptList( rootNode
, NULL
, false );
637 MakeVisible( GetEntry( 0,0 ) );
638 SetUpdateMode( TRUE
);
641 Image
SvxConfigGroupListBox_Impl::GetImage( Reference
< browse::XBrowseNode
> node
, Reference
< XComponentContext
> xCtx
, bool bIsRootNode
, bool bHighContrast
)
646 if ( node
->getName().equalsAscii( "user" ) || node
->getName().equalsAscii( "share" ) )
648 if( bHighContrast
== BMP_COLOR_NORMAL
)
651 aImage
= m_hdImage_hc
;
656 OUString nodeName
= node
->getName();
657 Reference
<XInterface
> xDocumentModel
= getDocumentModel(xCtx
, nodeName
);
658 if ( xDocumentModel
.is() )
660 Reference
< ::com::sun::star::frame::XModuleManager
>
662 xCtx
->getServiceManager()
663 ->createInstanceWithContext(
664 OUString::createFromAscii("com.sun.star.frame.ModuleManager"),
667 Reference
<container::XNameAccess
> xModuleConfig(
668 xModuleManager
, UNO_QUERY_THROW
);
669 // get the long name of the document:
670 OUString
appModule( xModuleManager
->identify(
672 Sequence
<beans::PropertyValue
> moduleDescr
;
673 Any aAny
= xModuleConfig
->getByName(appModule
);
674 if( sal_True
!= ( aAny
>>= moduleDescr
) )
676 throw RuntimeException(OUString::createFromAscii("SFTreeListBox::Init: failed to get PropertyValue"), Reference
< XInterface
>());
678 beans::PropertyValue
const * pmoduleDescr
=
679 moduleDescr
.getConstArray();
680 for ( sal_Int32 pos
= moduleDescr
.getLength(); pos
--; )
682 if (pmoduleDescr
[ pos
].Name
.equalsAsciiL(
683 RTL_CONSTASCII_STRINGPARAM(
684 "ooSetupFactoryEmptyDocumentURL") ))
686 pmoduleDescr
[ pos
].Value
>>= factoryURL
;
691 if( factoryURL
.getLength() > 0 )
693 if( bHighContrast
== BMP_COLOR_NORMAL
)
694 aImage
= SvFileInformationManager::GetFileImage(
695 INetURLObject(factoryURL
), false,
698 aImage
= SvFileInformationManager::GetFileImage(
699 INetURLObject(factoryURL
), false,
700 BMP_COLOR_HIGHCONTRAST
);
704 if( bHighContrast
== BMP_COLOR_NORMAL
)
707 aImage
= m_docImage_hc
;
713 if( node
->getType() == browse::BrowseNodeTypes::SCRIPT
)
715 if( bHighContrast
== BMP_COLOR_NORMAL
)
718 aImage
= m_macImage_hc
;
722 if( bHighContrast
== BMP_COLOR_NORMAL
)
725 aImage
= m_libImage_hc
;
731 Reference
< XInterface
>
732 SvxConfigGroupListBox_Impl::getDocumentModel(
733 Reference
< XComponentContext
>& xCtx
, OUString
& docName
)
735 Reference
< XInterface
> xModel
;
736 Reference
< lang::XMultiComponentFactory
> mcf
=
737 xCtx
->getServiceManager();
738 Reference
< frame::XDesktop
> desktop (
739 mcf
->createInstanceWithContext(
740 OUString::createFromAscii("com.sun.star.frame.Desktop"), xCtx
),
743 Reference
< container::XEnumerationAccess
> componentsAccess
=
744 desktop
->getComponents();
745 Reference
< container::XEnumeration
> components
=
746 componentsAccess
->createEnumeration();
747 while (components
->hasMoreElements())
749 Reference
< frame::XModel
> model(
750 components
->nextElement(), UNO_QUERY
);
753 OUString sTdocUrl
= ::comphelper::DocumentInfo::getDocumentTitle( model
);
754 if( sTdocUrl
.equals( docName
) )
764 void SvxConfigGroupListBox_Impl::GroupSelected()
766 SvLBoxEntry
*pEntry
= FirstSelected();
767 SvxGroupInfo_Impl
*pInfo
= (SvxGroupInfo_Impl
*) pEntry
->GetUserData();
768 pFunctionListBox
->SetUpdateMode(FALSE
);
769 pFunctionListBox
->ClearAll();
770 if ( pInfo
->nKind
!= SVX_CFGGROUP_FUNCTION
&&
771 pInfo
->nKind
!= SVX_CFGGROUP_SCRIPTCONTAINER
)
773 pFunctionListBox
->SetUpdateMode(TRUE
);
777 switch ( pInfo
->nKind
)
779 case SVX_CFGGROUP_FUNCTION
:
781 SvLBoxEntry
*_pEntry
= FirstSelected();
782 if ( _pEntry
!= NULL
)
784 SvxGroupInfo_Impl
*_pInfo
=
785 (SvxGroupInfo_Impl
*) _pEntry
->GetUserData();
787 Reference
< frame::XDispatchInformationProvider
> xDIP(
788 m_xFrame
, UNO_QUERY
);
790 Sequence
< frame::DispatchInformation
> commands
;
793 commands
= xDIP
->getConfigurableDispatchInformation(
796 catch ( container::NoSuchElementException
& )
800 for ( sal_Int32 i
= 0; i
< commands
.getLength(); i
++ )
802 if ( commands
[i
].Command
.getLength() == 0 )
809 OUString
aCmdURL( commands
[i
].Command
);
811 if ( m_pImageProvider
)
813 aImage
= m_pImageProvider
->GetImage( aCmdURL
);
819 Any a
= m_xModuleCommands
->getByName( aCmdURL
);
820 Sequence
< beans::PropertyValue
> aPropSeq
;
822 if ( a
>>= aPropSeq
)
824 for ( sal_Int32 k
= 0; k
< aPropSeq
.getLength(); k
++ )
826 if ( aPropSeq
[k
].Name
.equalsAscii( "Name" ) )
828 aPropSeq
[k
].Value
>>= aLabel
;
834 catch ( container::NoSuchElementException
& )
838 if ( aLabel
.getLength() == 0 )
840 aLabel
= commands
[i
].Command
;
843 SvLBoxEntry
* pFuncEntry
= NULL
;
846 pFuncEntry
= pFunctionListBox
->InsertEntry(
847 aLabel
, aImage
, aImage
);
851 pFuncEntry
= pFunctionListBox
->InsertEntry(
855 SvxGroupInfo_Impl
*_pGroupInfo
= new SvxGroupInfo_Impl(
856 SVX_CFGFUNCTION_SLOT
, 123, aCmdURL
, ::rtl::OUString() );
858 pFunctionListBox
->aArr
.Insert(
859 _pGroupInfo
, pFunctionListBox
->aArr
.Count() );
861 pFuncEntry
->SetUserData( _pGroupInfo
);
867 case SVX_CFGGROUP_SCRIPTCONTAINER
:
869 Reference
< browse::XBrowseNode
> rootNode( pInfo
->xBrowseNode
);
872 if ( rootNode
->hasChildNodes() )
874 Sequence
< Reference
< browse::XBrowseNode
> > children
=
875 rootNode
->getChildNodes();
877 for ( long n
= 0; n
< children
.getLength(); n
++ )
879 if (!children
[n
].is())
881 if (children
[n
]->getType() == browse::BrowseNodeTypes::SCRIPT
)
884 OUString description
;
886 Reference
< beans::XPropertySet
>xPropSet( children
[n
], UNO_QUERY
);
893 xPropSet
->getPropertyValue( String::CreateFromAscii( "URI" ) );
898 value
= xPropSet
->getPropertyValue(
899 String::CreateFromAscii( "Description" ) );
900 value
>>= description
;
902 catch (Exception
&) {
903 // do nothing, the description will be empty
906 SvxGroupInfo_Impl
* _pGroupInfo
=
907 new SvxGroupInfo_Impl(
908 SVX_CFGFUNCTION_SCRIPT
, 123, uri
, description
);
910 Image aImage
= GetImage( children
[n
], Reference
< XComponentContext
>(), sal_False
, BMP_COLOR_NORMAL
);
911 SvLBoxEntry
* pNewEntry
=
912 pFunctionListBox
->InsertEntry( children
[n
]->getName(), NULL
);
913 pFunctionListBox
->SetExpandedEntryBmp(pNewEntry
, aImage
, BMP_COLOR_NORMAL
);
914 pFunctionListBox
->SetCollapsedEntryBmp(pNewEntry
, aImage
, BMP_COLOR_NORMAL
);
915 aImage
= GetImage( children
[n
], Reference
< XComponentContext
>(), sal_False
, BMP_COLOR_HIGHCONTRAST
);
916 pFunctionListBox
->SetExpandedEntryBmp(pNewEntry
, aImage
, BMP_COLOR_HIGHCONTRAST
);
917 pFunctionListBox
->SetCollapsedEntryBmp(pNewEntry
, aImage
, BMP_COLOR_HIGHCONTRAST
);
919 pNewEntry
->SetUserData( _pGroupInfo
);
921 pFunctionListBox
->aArr
.Insert(
922 _pGroupInfo
, pFunctionListBox
->aArr
.Count() );
928 catch (const Exception
&)
930 DBG_UNHANDLED_EXCEPTION();
941 if ( pFunctionListBox
->GetEntryCount() )
942 pFunctionListBox
->Select( pFunctionListBox
->GetEntry( 0, 0 ) );
944 pFunctionListBox
->SetUpdateMode(TRUE
);
947 BOOL
SvxConfigGroupListBox_Impl::Expand( SvLBoxEntry
* pParent
)
949 BOOL bRet
= SvTreeListBox::Expand( pParent
);
952 // Wieviele Entries k"onnen angezeigt werden ?
953 ULONG nEntries
= GetOutputSizePixel().Height() / GetEntryHeight();
955 // Wieviele Kinder sollen angezeigt werden ?
956 ULONG nChildCount
= GetVisibleChildCount( pParent
);
958 // Passen alle Kinder und der parent gleichzeitig in die View ?
959 if ( nChildCount
+1 > nEntries
)
961 // Wenn nicht, wenigstens parent ganz nach oben schieben
962 MakeVisible( pParent
, TRUE
);
966 // An welcher relativen ViewPosition steht der aufzuklappende parent
967 SvLBoxEntry
*pEntry
= GetFirstEntryInView();
968 ULONG nParentPos
= 0;
969 while ( pEntry
&& pEntry
!= pParent
)
972 pEntry
= GetNextEntryInView( pEntry
);
975 // Ist unter dem parent noch genug Platz f"ur alle Kinder ?
976 if ( nParentPos
+ nChildCount
+ 1 > nEntries
)
977 ScrollOutputArea( (short)( nEntries
- ( nParentPos
+ nChildCount
+ 1 ) ) );
984 void SvxConfigGroupListBox_Impl::RequestingChilds( SvLBoxEntry
*pEntry
)
986 SvxGroupInfo_Impl
*pInfo
= (SvxGroupInfo_Impl
*) pEntry
->GetUserData();
987 pInfo
->bWasOpened
= TRUE
;
988 switch ( pInfo
->nKind
)
990 case SVX_CFGGROUP_SCRIPTCONTAINER
:
992 if ( !GetChildCount( pEntry
) )
994 Reference
< browse::XBrowseNode
> rootNode( pInfo
->xBrowseNode
) ;
995 fillScriptList( rootNode
, pEntry
, true /* i30923 */ );
1001 DBG_ERROR( "Falscher Gruppentyp!" );
1007 * Implementation of SvxScriptSelectorDialog
1009 * This dialog is used for selecting Slot API commands
1010 * and Scripting Framework Scripts.
1013 SvxScriptSelectorDialog::SvxScriptSelectorDialog(
1014 Window
* pParent
, BOOL bShowSlots
, const Reference
< frame::XFrame
>& xFrame
)
1016 ModelessDialog( pParent
, SVX_RES( RID_DLG_SCRIPTSELECTOR
) ),
1017 aDialogDescription( this, SVX_RES( TXT_SELECTOR_DIALOG_DESCRIPTION
) ),
1018 aGroupText( this, SVX_RES( TXT_SELECTOR_CATEGORIES
) ),
1019 aCategories( this, SVX_RES( BOX_SELECTOR_CATEGORIES
), bShowSlots
, xFrame
),
1020 aFunctionText( this, SVX_RES( TXT_SELECTOR_COMMANDS
) ),
1021 aCommands( this, SVX_RES( BOX_SELECTOR_COMMANDS
) ),
1022 aOKButton( this, SVX_RES( BTN_SELECTOR_OK
) ),
1023 aCancelButton( this, SVX_RES( BTN_SELECTOR_CANCEL
) ),
1024 aHelpButton( this, SVX_RES( BTN_SELECTOR_HELP
) ),
1025 aDescription( this, SVX_RES( GRP_SELECTOR_DESCRIPTION
) ),
1026 aDescriptionText( this, SVX_RES( TXT_SELECTOR_DESCRIPTION
) ),
1027 m_bShowSlots( bShowSlots
)
1030 ResMgr
& rMgr
= DIALOG_MGR();
1032 // If we are showing Slot API commands update labels in the UI, and
1033 // enable drag'n'drop
1036 aGroupText
.SetText( String( ResId( STR_SELECTOR_CATEGORIES
, rMgr
) ) );
1037 aOKButton
.SetText( String( ResId( STR_SELECTOR_ADD
, rMgr
) ) );
1038 aCancelButton
.SetText( String( ResId( STR_SELECTOR_CLOSE
, rMgr
) ) );
1039 aFunctionText
.SetText( String( ResId( STR_SELECTOR_COMMANDS
, rMgr
) ) );
1040 SetDialogDescription(
1041 String( ResId( STR_SELECTOR_ADD_COMMANDS_DESCRIPTION
, rMgr
) ) );
1042 SetText( String( ResId( STR_SELECTOR_ADD_COMMANDS
, rMgr
) ) );
1044 aCommands
.SetDragDropMode( SV_DRAGDROP_APP_COPY
);
1049 aCategories
.SetFunctionListBox( &aCommands
);
1051 // aCategories.Select( aCategories.GetEntry( 0, 0 ) );
1053 aCategories
.SetSelectHdl(
1054 LINK( this, SvxScriptSelectorDialog
, SelectHdl
) );
1055 aCommands
.SetSelectHdl( LINK( this, SvxScriptSelectorDialog
, SelectHdl
) );
1056 aCommands
.SetDoubleClickHdl( LINK( this, SvxScriptSelectorDialog
, FunctionDoubleClickHdl
) );
1058 aOKButton
.SetClickHdl( LINK( this, SvxScriptSelectorDialog
, ClickHdl
) );
1059 aCancelButton
.SetClickHdl( LINK( this, SvxScriptSelectorDialog
, ClickHdl
) );
1065 void SvxScriptSelectorDialog::ResizeControls()
1071 USHORT style
= TEXT_DRAW_MULTILINE
| TEXT_DRAW_TOP
|
1072 TEXT_DRAW_LEFT
| TEXT_DRAW_WORDBREAK
;
1074 // get dimensions of dialog instructions control
1075 p
= aDialogDescription
.GetPosPixel();
1076 s
= aDialogDescription
.GetSizePixel();
1078 // get dimensions occupied by text in the control
1080 GetTextRect( Rectangle( p
, s
), aDialogDescription
.GetText(), style
);
1081 news
= rect
.GetSize();
1083 // the gap is the difference between the control height and its text height
1084 gap
= s
.Height() - news
.Height();
1086 // resize the dialog instructions control
1087 news
= Size( s
.Width(), s
.Height() - gap
);
1088 aDialogDescription
.SetSizePixel( news
);
1090 // resize other controls to fill the gap
1091 p
= aGroupText
.GetPosPixel();
1092 newp
= Point( p
.X(), p
.Y() - gap
);
1093 aGroupText
.SetPosPixel( newp
);
1095 p
= aCategories
.GetPosPixel();
1096 newp
= Point( p
.X(), p
.Y() - gap
);
1097 aCategories
.SetPosPixel( newp
);
1098 s
= aCategories
.GetSizePixel();
1099 news
= Size( s
.Width(), s
.Height() + gap
);
1100 aCategories
.SetSizePixel( news
);
1102 p
= aFunctionText
.GetPosPixel();
1103 newp
= Point( p
.X(), p
.Y() - gap
);
1104 aFunctionText
.SetPosPixel( newp
);
1106 p
= aCommands
.GetPosPixel();
1107 newp
= Point( p
.X(), p
.Y() - gap
);
1108 aCommands
.SetPosPixel( newp
);
1109 s
= aCommands
.GetSizePixel();
1110 news
= Size( s
.Width(), s
.Height() + gap
);
1111 aCommands
.SetSizePixel( news
);
1113 p
= aOKButton
.GetPosPixel();
1114 newp
= Point( p
.X(), p
.Y() - gap
);
1115 aOKButton
.SetPosPixel( newp
);
1117 p
= aCancelButton
.GetPosPixel();
1118 newp
= Point( p
.X(), p
.Y() - gap
);
1119 aCancelButton
.SetPosPixel( newp
);
1121 p
= aHelpButton
.GetPosPixel();
1122 newp
= Point( p
.X(), p
.Y() - gap
);
1123 aHelpButton
.SetPosPixel( newp
);
1126 SvxScriptSelectorDialog::~SvxScriptSelectorDialog()
1130 IMPL_LINK( SvxScriptSelectorDialog
, SelectHdl
, Control
*, pCtrl
)
1132 if ( pCtrl
== &aCategories
)
1134 aCategories
.GroupSelected();
1136 else if ( pCtrl
== &aCommands
)
1138 aCommands
.FunctionSelected();
1144 IMPL_LINK( SvxScriptSelectorDialog
, FunctionDoubleClickHdl
, Control
*, pCtrl
)
1147 if ( aOKButton
.IsEnabled() )
1148 return ClickHdl( &aOKButton
);
1152 // Check if command is selected and enable the OK button accordingly
1153 // Grab the help text for this id if available and update the description field
1155 SvxScriptSelectorDialog::UpdateUI()
1157 OUString url
= GetScriptURL();
1158 if ( url
!= NULL
&& url
.getLength() != 0 )
1161 aCommands
.GetHelpText( aCommands
.FirstSelected() );
1162 aDescriptionText
.SetText( rMessage
);
1164 aOKButton
.Enable( TRUE
);
1168 aDescriptionText
.SetText( String() );
1169 aOKButton
.Enable( FALSE
);
1173 IMPL_LINK( SvxScriptSelectorDialog
, ClickHdl
, Button
*, pButton
)
1175 if ( pButton
== &aCancelButton
)
1177 // If we are displaying Slot API commands then the dialog is being
1178 // run from Tools/Configure and we should not close it, just hide it
1179 if ( m_bShowSlots
== FALSE
)
1181 EndDialog( RET_CANCEL
);
1188 else if ( pButton
== &aOKButton
)
1190 GetAddHdl().Call( this );
1192 // If we are displaying Slot API commands then this the dialog is being
1193 // run from Tools/Configure and we should not close it
1194 if ( m_bShowSlots
== FALSE
)
1196 EndDialog( RET_OK
);
1200 // Select the next entry in the list if possible
1201 SvLBoxEntry
* current
= aCommands
.FirstSelected();
1202 SvLBoxEntry
* next
= aCommands
.NextSibling( current
);
1206 aCommands
.Select( next
);
1215 SvxScriptSelectorDialog::SetRunLabel()
1217 aOKButton
.SetText( String( SVX_RES( STR_SELECTOR_RUN
) ) );
1221 SvxScriptSelectorDialog::SetDialogDescription( const String
& rDescription
)
1223 aDialogDescription
.SetText( rDescription
);
1227 SvxScriptSelectorDialog::GetSelectedId()
1229 return aCommands
.GetId( aCommands
.GetLastSelectedEntry() );
1233 SvxScriptSelectorDialog::GetScriptURL() const
1237 SvLBoxEntry
*pEntry
= const_cast< SvxScriptSelectorDialog
* >( this )->aCommands
.GetLastSelectedEntry();
1240 SvxGroupInfo_Impl
*pData
= (SvxGroupInfo_Impl
*) pEntry
->GetUserData();
1241 if ( ( pData
->nKind
== SVX_CFGFUNCTION_SLOT
)
1242 || ( pData
->nKind
== SVX_CFGFUNCTION_SCRIPT
)
1245 result
= pData
->sURL
;
1253 SvxScriptSelectorDialog::GetSelectedDisplayName()
1255 return aCommands
.GetEntryText( aCommands
.GetLastSelectedEntry() );
1259 SvxScriptSelectorDialog::GetSelectedHelpText()
1261 return aCommands
.GetHelpText( aCommands
.GetLastSelectedEntry() );