1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "cfgutil.hxx"
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/container/XEnumerationAccess.hpp>
24 #include <com/sun/star/container/XEnumeration.hpp>
25 #include <com/sun/star/document/XScriptInvocationContext.hpp>
26 #include <com/sun/star/frame/ModuleManager.hpp>
27 #include <com/sun/star/frame/Desktop.hpp>
28 #include <com/sun/star/frame/UICommandDescription.hpp>
29 #include <com/sun/star/frame/XDispatchInformationProvider.hpp>
30 #include <com/sun/star/script/browse/XBrowseNode.hpp>
31 #include <com/sun/star/script/browse/BrowseNodeTypes.hpp>
32 #include <com/sun/star/script/browse/theBrowseNodeFactory.hpp>
33 #include <com/sun/star/script/browse/BrowseNodeFactoryViewTypes.hpp>
34 #include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
35 #include <com/sun/star/script/provider/XScriptProvider.hpp>
36 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
37 #include <com/sun/star/uno/RuntimeException.hpp>
38 #include <com/sun/star/ui/UICategoryDescription.hpp>
42 #include <basic/sbx.hxx>
43 #include <basic/basicmanagerrepository.hxx>
44 #include <basic/sbstar.hxx>
45 #include <basic/sbxmeth.hxx>
46 #include <basic/sbmod.hxx>
47 #include <basic/basmgr.hxx>
48 #include <tools/urlobj.hxx>
50 #include <sfx2/app.hxx>
51 #include <sfx2/minfitem.hxx>
52 #include <comphelper/documentinfo.hxx>
53 #include <comphelper/processfactory.hxx>
54 #include <comphelper/sequenceashashmap.hxx>
55 #include <comphelper/string.hxx>
56 #include <svtools/imagemgr.hxx>
57 #include "svtools/treelistentry.hxx"
58 #include <rtl/ustrbuf.hxx>
59 #include <unotools/configmgr.hxx>
60 #include "dialmgr.hxx"
61 #include <svl/stritem.hxx>
63 using namespace ::com::sun::star
;
64 using namespace ::com::sun::star::uno
;
65 using namespace ::com::sun::star::script
;
66 using namespace ::com::sun::star::frame
;
67 using namespace ::com::sun::star::document
;
69 SfxStylesInfo_Impl::SfxStylesInfo_Impl()
72 void SfxStylesInfo_Impl::setModel(const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>& xModel
)
77 static OUString
CMDURL_SPART (".uno:StyleApply?Style:string=");
78 static OUString
CMDURL_FPART2 ("&FamilyName:string=");
80 static OUString
CMDURL_STYLEPROT_ONLY (".uno:StyleApply?");
81 static OUString
CMDURL_SPART_ONLY ("Style:string=");
82 static OUString
CMDURL_FPART_ONLY ("FamilyName:string=");
84 static OUString
STYLEPROP_UINAME ("DisplayName");
86 OUString
SfxStylesInfo_Impl::generateCommand(const OUString
& sFamily
, const OUString
& sStyle
)
88 OUStringBuffer
sCommand(1024);
89 sCommand
.append(CMDURL_SPART
);
90 sCommand
.append(sStyle
);
91 sCommand
.append(CMDURL_FPART2
);
92 sCommand
.append(sFamily
);
93 return sCommand
.makeStringAndClear();
96 sal_Bool
SfxStylesInfo_Impl::parseStyleCommand(SfxStyleInfo_Impl
& aStyle
)
98 static sal_Int32 LEN_STYLEPROT
= CMDURL_STYLEPROT_ONLY
.getLength();
99 static sal_Int32 LEN_SPART
= CMDURL_SPART_ONLY
.getLength();
100 static sal_Int32 LEN_FPART
= CMDURL_FPART_ONLY
.getLength();
102 if (aStyle
.sCommand
.indexOf(CMDURL_STYLEPROT_ONLY
, 0) != 0)
105 aStyle
.sFamily
= OUString();
106 aStyle
.sStyle
= OUString();
108 sal_Int32 nCmdLen
= aStyle
.sCommand
.getLength();
109 OUString sCmdArgs
= aStyle
.sCommand
.copy(LEN_STYLEPROT
, nCmdLen
-LEN_STYLEPROT
);
110 sal_Int32 i
= sCmdArgs
.indexOf('&');
114 OUString sArg
= sCmdArgs
.copy(0, i
);
115 if (sArg
.indexOf(CMDURL_SPART_ONLY
) == 0)
116 aStyle
.sStyle
= sArg
.copy(LEN_SPART
, sArg
.getLength()-LEN_SPART
);
117 else if (sArg
.indexOf(CMDURL_FPART_ONLY
) == 0)
118 aStyle
.sFamily
= sArg
.copy(LEN_FPART
, sArg
.getLength()-LEN_FPART
);
120 sArg
= sCmdArgs
.copy(i
+1, sCmdArgs
.getLength()-i
-1);
121 if (sArg
.indexOf(CMDURL_SPART_ONLY
) == 0)
122 aStyle
.sStyle
= sArg
.copy(LEN_SPART
, sArg
.getLength()-LEN_SPART
);
123 else if (sArg
.indexOf(CMDURL_FPART_ONLY
) == 0)
124 aStyle
.sFamily
= sArg
.copy(LEN_FPART
, sArg
.getLength()-LEN_FPART
);
126 if (!(aStyle
.sFamily
.isEmpty() || aStyle
.sStyle
.isEmpty()))
132 void SfxStylesInfo_Impl::getLabel4Style(SfxStyleInfo_Impl
& aStyle
)
136 css::uno::Reference
< css::style::XStyleFamiliesSupplier
> xModel(m_xDoc
, css::uno::UNO_QUERY
);
138 css::uno::Reference
< css::container::XNameAccess
> xFamilies
;
140 xFamilies
= xModel
->getStyleFamilies();
142 css::uno::Reference
< css::container::XNameAccess
> xStyleSet
;
144 xFamilies
->getByName(aStyle
.sFamily
) >>= xStyleSet
;
146 css::uno::Reference
< css::beans::XPropertySet
> xStyle
;
148 xStyleSet
->getByName(aStyle
.sStyle
) >>= xStyle
;
150 aStyle
.sLabel
= OUString();
152 xStyle
->getPropertyValue(STYLEPROP_UINAME
) >>= aStyle
.sLabel
;
154 catch(const css::uno::RuntimeException
&)
156 catch(const css::uno::Exception
&)
157 { aStyle
.sLabel
= OUString(); }
159 if (aStyle
.sLabel
.isEmpty())
161 aStyle
.sLabel
= aStyle
.sCommand
;
165 ::std::vector
< SfxStyleInfo_Impl
> SfxStylesInfo_Impl::getStyleFamilies()
167 // Its an optional interface!
168 css::uno::Reference
< css::style::XStyleFamiliesSupplier
> xModel(m_xDoc
, css::uno::UNO_QUERY
);
170 return ::std::vector
< SfxStyleInfo_Impl
>();
172 css::uno::Reference
< css::container::XNameAccess
> xCont
= xModel
->getStyleFamilies();
173 css::uno::Sequence
< OUString
> lFamilyNames
= xCont
->getElementNames();
174 ::std::vector
< SfxStyleInfo_Impl
> lFamilies
;
175 sal_Int32 c
= lFamilyNames
.getLength();
179 SfxStyleInfo_Impl aFamilyInfo
;
180 aFamilyInfo
.sFamily
= lFamilyNames
[i
];
184 css::uno::Reference
< css::beans::XPropertySet
> xFamilyInfo
;
185 xCont
->getByName(aFamilyInfo
.sFamily
) >>= xFamilyInfo
;
186 if (!xFamilyInfo
.is())
188 // TODO_AS currently there is no support for an UIName property .. use internal family name instead
189 aFamilyInfo
.sLabel
= aFamilyInfo
.sFamily
;
192 xFamilyInfo
->getPropertyValue(STYLEPROP_UINAME
) >>= aFamilyInfo
.sLabel
;
194 catch(const css::uno::RuntimeException
&)
196 catch(const css::uno::Exception
&)
197 { return ::std::vector
< SfxStyleInfo_Impl
>(); }
199 lFamilies
.push_back(aFamilyInfo
);
205 ::std::vector
< SfxStyleInfo_Impl
> SfxStylesInfo_Impl::getStyles(const OUString
& sFamily
)
207 static OUString
PROP_UINAME ("DisplayName");
209 css::uno::Sequence
< OUString
> lStyleNames
;
210 css::uno::Reference
< css::style::XStyleFamiliesSupplier
> xModel(m_xDoc
, css::uno::UNO_QUERY_THROW
);
211 css::uno::Reference
< css::container::XNameAccess
> xFamilies
= xModel
->getStyleFamilies();
212 css::uno::Reference
< css::container::XNameAccess
> xStyleSet
;
215 xFamilies
->getByName(sFamily
) >>= xStyleSet
;
216 lStyleNames
= xStyleSet
->getElementNames();
218 catch(const css::uno::RuntimeException
&)
220 catch(const css::uno::Exception
&)
221 { return ::std::vector
< SfxStyleInfo_Impl
>(); }
223 ::std::vector
< SfxStyleInfo_Impl
> lStyles
;
224 sal_Int32 c
= lStyleNames
.getLength();
228 SfxStyleInfo_Impl aStyleInfo
;
229 aStyleInfo
.sFamily
= sFamily
;
230 aStyleInfo
.sStyle
= lStyleNames
[i
];
231 aStyleInfo
.sCommand
= SfxStylesInfo_Impl::generateCommand(aStyleInfo
.sFamily
, aStyleInfo
.sStyle
);
235 css::uno::Reference
< css::beans::XPropertySet
> xStyle
;
236 xStyleSet
->getByName(aStyleInfo
.sStyle
) >>= xStyle
;
239 xStyle
->getPropertyValue(PROP_UINAME
) >>= aStyleInfo
.sLabel
;
241 catch(const css::uno::RuntimeException
&)
243 catch(const css::uno::Exception
&)
246 lStyles
.push_back(aStyleInfo
);
251 SfxConfigFunctionListBox_Impl::SfxConfigFunctionListBox_Impl( Window
* pParent
, const ResId
& rResId
)
252 : SvTreeListBox( pParent
, rResId
)
256 SetStyle( GetStyle() | WB_CLIPCHILDREN
| WB_HSCROLL
| WB_SORT
);
257 GetModel()->SetSortMode( SortAscending
);
259 // Timer for the BallonHelp
260 aTimer
.SetTimeout( 200 );
261 aTimer
.SetTimeoutHdl(
262 LINK( this, SfxConfigFunctionListBox_Impl
, TimerHdl
) );
265 SfxConfigFunctionListBox_Impl::~SfxConfigFunctionListBox_Impl()
270 void SfxConfigFunctionListBox_Impl::MouseMove( const MouseEvent
& )
274 IMPL_LINK( SfxConfigFunctionListBox_Impl
, TimerHdl
, Timer
*, pTimer
)
276 Timer-handler for showing a help-text. If the mouse pointer is
277 still on the currently selected entry after the timer has run out,
278 the entry's help-text is shown as a balloon-help.
281 (void)pTimer
; // unused
285 void SfxConfigFunctionListBox_Impl::ClearAll()
287 Deletes all entries in the FunctionListBox, all UserData and all
288 possibly existing MacroInfo.
291 sal_uInt16 nCount
= aArr
.size();
292 for ( sal_uInt16 i
=0; i
<nCount
; ++i
)
294 SfxGroupInfo_Impl
*pData
= &aArr
[i
];
296 if ( pData
->nKind
== SFX_CFGFUNCTION_SCRIPT
)
298 String
* pScriptURI
= (String
*)pData
->pObject
;
302 if ( pData
->nKind
== SFX_CFGGROUP_SCRIPTCONTAINER
)
304 XInterface
* xi
= static_cast<XInterface
*>(pData
->pObject
);
316 String
SfxConfigFunctionListBox_Impl::GetSelectedScriptURI()
318 SvTreeListEntry
*pEntry
= FirstSelected();
321 SfxGroupInfo_Impl
*pData
= (SfxGroupInfo_Impl
*) pEntry
->GetUserData();
322 if ( pData
&& ( pData
->nKind
== SFX_CFGFUNCTION_SCRIPT
) )
323 return *(String
*)pData
->pObject
;
328 String
SfxConfigFunctionListBox_Impl::GetCurCommand()
330 SvTreeListEntry
*pEntry
= FirstSelected();
333 SfxGroupInfo_Impl
*pData
= (SfxGroupInfo_Impl
*) pEntry
->GetUserData();
336 return pData
->sCommand
;
339 String
SfxConfigFunctionListBox_Impl::GetCurLabel()
341 SvTreeListEntry
*pEntry
= FirstSelected();
344 SfxGroupInfo_Impl
*pData
= (SfxGroupInfo_Impl
*) pEntry
->GetUserData();
347 if (pData
->sLabel
.Len())
348 return pData
->sLabel
;
349 return pData
->sCommand
;
352 void SfxConfigFunctionListBox_Impl::FunctionSelected()
354 Resets the balloon-help because it shall
355 always show the help-text of the selected entry.
360 void SfxConfigFunctionListBox_Impl::SetStylesInfo(SfxStylesInfo_Impl
* pStyles
)
362 pStylesInfo
= pStyles
;
365 struct SvxConfigGroupBoxResource_Impl
: public Resource
371 OUString m_sMyMacros
;
372 OUString m_sProdMacros
;
375 String m_aHumanAppName
;
376 String m_aStrGroupStyles
;
377 Image m_collapsedImage
;
378 Image m_expandedImage
;
380 SvxConfigGroupBoxResource_Impl();
383 SvxConfigGroupBoxResource_Impl::SvxConfigGroupBoxResource_Impl() :
384 Resource(CUI_RES(RID_SVXPAGE_CONFIGGROUPBOX
)),
385 m_hdImage(CUI_RES(RID_CUIIMG_HARDDISK
)),
386 m_libImage(CUI_RES(RID_CUIIMG_LIB
)),
387 m_macImage(CUI_RES(RID_CUIIMG_MACRO
)),
388 m_docImage(CUI_RES(RID_CUIIMG_DOC
)),
389 m_sMyMacros(CUI_RESSTR(RID_SVXSTR_MYMACROS
)),
390 m_sProdMacros(CUI_RESSTR(RID_SVXSTR_PRODMACROS
)),
391 m_sMacros(CUI_RESSTR(STR_BASICMACROS
)),
392 m_sDlgMacros(CUI_RESSTR(RID_SVXSTR_PRODMACROS
)),
393 m_aHumanAppName(CUI_RESSTR(STR_HUMAN_APPNAME
)),
394 m_aStrGroupStyles(CUI_RESSTR(STR_GROUP_STYLES
)),
395 m_collapsedImage(CUI_RES(BMP_COLLAPSED
)),
396 m_expandedImage(CUI_RES(BMP_EXPANDED
))
401 SfxConfigGroupListBox_Impl::SfxConfigGroupListBox_Impl(
402 Window
* pParent
, const ResId
& rResId
, sal_uLong nConfigMode
)
403 : SvTreeListBox( pParent
, rResId
)
404 , pImp(new SvxConfigGroupBoxResource_Impl()), pFunctionListBox(0), nMode( nConfigMode
), pStylesInfo(0)
406 SetStyle( GetStyle() | WB_CLIPCHILDREN
| WB_HSCROLL
| WB_HASBUTTONS
| WB_HASLINES
| WB_HASLINESATROOT
| WB_HASBUTTONSATROOT
);
407 SetNodeBitmaps( pImp
->m_collapsedImage
, pImp
->m_expandedImage
);
411 SfxConfigGroupListBox_Impl::~SfxConfigGroupListBox_Impl()
416 void SfxConfigGroupListBox_Impl::ClearAll()
418 sal_uInt16 nCount
= aArr
.size();
419 for ( sal_uInt16 i
=0; i
<nCount
; ++i
)
421 SfxGroupInfo_Impl
*pData
= &aArr
[i
];
422 if (pData
->nKind
== SFX_CFGGROUP_SCRIPTCONTAINER
)
424 XInterface
* xi
= static_cast<XInterface
*>(pData
->pObject
);
436 void SfxConfigGroupListBox_Impl::SetStylesInfo(SfxStylesInfo_Impl
* pStyles
)
438 pStylesInfo
= pStyles
;
441 //-----------------------------------------------
442 void SfxConfigGroupListBox_Impl::InitModule()
446 css::uno::Reference
< css::frame::XDispatchInformationProvider
> xProvider(m_xFrame
, css::uno::UNO_QUERY_THROW
);
447 css::uno::Sequence
< sal_Int16
> lGroups
= xProvider
->getSupportedCommandGroups();
448 sal_Int32 c1
= lGroups
.getLength();
451 for (i1
=0; i1
<c1
; ++i1
)
453 sal_Int16
& rGroupID
= lGroups
[i1
];
454 OUString sGroupID
= OUString::valueOf((sal_Int32
)rGroupID
);
455 OUString sGroupName
;
459 m_xModuleCategoryInfo
->getByName(sGroupID
) >>= sGroupName
;
460 if (sGroupName
.isEmpty())
463 catch(const css::container::NoSuchElementException
&)
466 SvTreeListEntry
* pEntry
= InsertEntry(sGroupName
, NULL
);
467 SfxGroupInfo_Impl
* pInfo
= new SfxGroupInfo_Impl(SFX_CFGGROUP_FUNCTION
, rGroupID
);
468 pEntry
->SetUserData(pInfo
);
471 catch(const css::uno::RuntimeException
&)
473 catch(const css::uno::Exception
&)
477 //-----------------------------------------------
478 void SfxConfigGroupListBox_Impl::InitBasic()
482 //-----------------------------------------------
483 void SfxConfigGroupListBox_Impl::InitStyles()
487 //-----------------------------------------------
490 //...........................................
491 /** examines a component whether it supports XEmbeddedScripts, or provides access to such a
492 component by implementing XScriptInvocationContext.
494 the model which supports the embedded scripts, or <NULL/> if it cannot find such a
497 static Reference
< XModel
> lcl_getDocumentWithScripts_throw( const Reference
< XInterface
>& _rxComponent
)
499 Reference
< XEmbeddedScripts
> xScripts( _rxComponent
, UNO_QUERY
);
500 if ( !xScripts
.is() )
502 Reference
< XScriptInvocationContext
> xContext( _rxComponent
, UNO_QUERY
);
504 xScripts
.set( xContext
->getScriptContainer(), UNO_QUERY
);
507 return Reference
< XModel
>( xScripts
, UNO_QUERY
);
510 //...........................................
511 static Reference
< XModel
> lcl_getScriptableDocument_nothrow( const Reference
< XFrame
>& _rxFrame
)
513 Reference
< XModel
> xDocument
;
515 // examine our associated frame
518 OSL_ENSURE( _rxFrame
.is(), "lcl_getScriptableDocument_nothrow: you need to pass a frame to this dialog/tab page!" );
521 // first try the model in the frame
522 Reference
< XController
> xController( _rxFrame
->getController(), UNO_SET_THROW
);
523 xDocument
= lcl_getDocumentWithScripts_throw( xController
->getModel() );
525 if ( !xDocument
.is() )
527 // if there is no suitable document in the frame, try the controller
528 xDocument
= lcl_getDocumentWithScripts_throw( _rxFrame
->getController() );
532 catch( const Exception
& )
540 //-----------------------------------------------
541 void SfxConfigGroupListBox_Impl::Init(const css::uno::Reference
< css::uno::XComponentContext
>& xContext
,
542 const css::uno::Reference
< css::frame::XFrame
>& xFrame
,
543 const OUString
& sModuleLongName
)
545 SetUpdateMode(sal_False
);
546 ClearAll(); // Remove all old entries from treelist box
551 m_xContext
= xContext
;
552 m_sModuleLongName
= sModuleLongName
;
554 m_xGlobalCategoryInfo
= css::ui::UICategoryDescription::create( m_xContext
);
555 m_xModuleCategoryInfo
= css::uno::Reference
< css::container::XNameAccess
>(m_xGlobalCategoryInfo
->getByName(m_sModuleLongName
), css::uno::UNO_QUERY_THROW
);
556 m_xUICmdDescription
= css::frame::UICommandDescription::create( m_xContext
);
563 OSL_TRACE("** ** About to initialise SF Scripts");
564 // Add Scripting Framework entries
565 Reference
< browse::XBrowseNode
> rootNode
;
566 Reference
< XComponentContext
> xCtx(
567 comphelper::getProcessComponentContext() );
570 Reference
< browse::XBrowseNodeFactory
> xFac
= browse::theBrowseNodeFactory::get( xCtx
);
571 rootNode
.set( xFac
->createView( browse::BrowseNodeFactoryViewTypes::MACROSELECTOR
) );
573 catch( Exception
& e
)
575 OSL_TRACE(" Caught some exception whilst retrieving browse nodes from factory... Exception: %s",
576 OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
577 // TODO exception handling
585 //We call acquire on the XBrowseNode so that it does not
586 //get autodestructed and become invalid when accessed later.
589 SfxGroupInfo_Impl
*pInfo
=
590 new SfxGroupInfo_Impl( SFX_CFGGROUP_SCRIPTCONTAINER
, 0,
591 static_cast<void *>(rootNode
.get()));
593 String
aTitle(pImp
->m_sDlgMacros
);
594 SvTreeListEntry
*pNewEntry
= InsertEntry( aTitle
, NULL
);
595 pNewEntry
->SetUserData( pInfo
);
596 pNewEntry
->EnableChildrenOnDemand( sal_True
);
597 aArr
.push_back( pInfo
);
601 //We are only showing scripts not slot APIs so skip
602 //Root node and show location nodes
604 if ( rootNode
->hasChildNodes() )
606 Sequence
< Reference
< browse::XBrowseNode
> > children
=
607 rootNode
->getChildNodes();
608 sal_Bool bIsRootNode
= sal_False
;
610 OUString
user("user");
611 OUString
share("share");
612 if ( rootNode
->getName() == "Root" )
614 bIsRootNode
= sal_True
;
617 //To mimic current starbasic behaviour we
618 //need to make sure that only the current document
619 //is displayed in the config tree. Tests below
620 //set the bDisplay flag to FALSE if the current
621 //node is a first level child of the Root and is NOT
622 //either the current document, user or share
623 OUString currentDocTitle
;
624 Reference
< XModel
> xDocument( lcl_getScriptableDocument_nothrow( m_xFrame
) );
625 if ( xDocument
.is() )
627 currentDocTitle
= ::comphelper::DocumentInfo::getDocumentTitle( xDocument
);
630 for ( sal_Int32 n
= 0; n
< children
.getLength(); ++n
)
632 Reference
< browse::XBrowseNode
>& theChild
= children
[n
];
633 sal_Bool bDisplay
= sal_True
;
634 OUString uiName
= theChild
->getName();
637 if ( ! ((theChild
->getName().equals( user
) || theChild
->getName().equals( share
) ||
638 theChild
->getName().equals( currentDocTitle
) ) ) )
644 if ( uiName
.equals( user
) )
646 uiName
= pImp
->m_sMyMacros
;
648 else if ( uiName
.equals( share
) )
650 uiName
= pImp
->m_sProdMacros
;
654 if (children
[n
]->getType() != browse::BrowseNodeTypes::SCRIPT
&& bDisplay
)
656 // We call acquire on the XBrowseNode so that it does not
657 // get autodestructed and become invalid when accessed later.
660 SfxGroupInfo_Impl
* pInfo
=
661 new SfxGroupInfo_Impl(SFX_CFGGROUP_SCRIPTCONTAINER
,
662 0, static_cast<void *>( theChild
.get()));
664 Image aImage
= GetImage( theChild
, xCtx
, bIsRootNode
);
665 SvTreeListEntry
* pNewEntry
=
666 InsertEntry( uiName
, NULL
);
667 SetExpandedEntryBmp( pNewEntry
, aImage
);
668 SetCollapsedEntryBmp( pNewEntry
, aImage
);
670 pNewEntry
->SetUserData( pInfo
);
671 aArr
.push_back( pInfo
);
673 if ( children
[n
]->hasChildNodes() )
675 Sequence
< Reference
< browse::XBrowseNode
> > grandchildren
=
676 children
[n
]->getChildNodes();
678 for ( sal_Int32 m
= 0; m
< grandchildren
.getLength(); ++m
)
680 if ( grandchildren
[m
]->getType() == browse::BrowseNodeTypes::CONTAINER
)
682 pNewEntry
->EnableChildrenOnDemand( sal_True
);
683 m
= grandchildren
.getLength();
691 catch (RuntimeException
&) {
692 // do nothing, the entry will not be displayed in the UI
698 if ( m_xContext
.is() )
700 String
sStyle( pImp
->m_aStrGroupStyles
);
701 SvTreeListEntry
*pEntry
= InsertEntry( sStyle
, 0 );
702 SfxGroupInfo_Impl
*pInfo
= new SfxGroupInfo_Impl( SFX_CFGGROUP_STYLES
, 0, 0 ); // TODO last parameter should contain user data
703 aArr
.push_back( pInfo
);
704 pEntry
->SetUserData( pInfo
);
705 pEntry
->EnableChildrenOnDemand( sal_True
);
708 MakeVisible( GetEntry( 0,0 ) );
709 SetUpdateMode( sal_True
);
711 Image
SfxConfigGroupListBox_Impl::GetImage(
712 Reference
< browse::XBrowseNode
> node
,
713 Reference
< XComponentContext
> xCtx
,
720 OUString
user("user");
721 OUString
share("share");
722 if (node
->getName().equals( user
) || node
->getName().equals(share
) )
724 aImage
= pImp
->m_hdImage
;
729 OUString nodeName
= node
->getName();
730 Reference
<XInterface
> xDocumentModel
= getDocumentModel(xCtx
, nodeName
);
731 if ( xDocumentModel
.is() )
733 Reference
< frame::XModuleManager2
> xModuleManager( frame::ModuleManager::create(xCtx
) );
734 // get the long name of the document:
735 OUString
appModule( xModuleManager
->identify(
737 Sequence
<beans::PropertyValue
> moduleDescr
;
738 Any aAny
= xModuleManager
->getByName(appModule
);
739 if( sal_True
!= ( aAny
>>= moduleDescr
) )
741 throw RuntimeException(OUString("SFTreeListBox::Init: failed to get PropertyValue"), Reference
< XInterface
>());
743 beans::PropertyValue
const * pmoduleDescr
=
744 moduleDescr
.getConstArray();
745 for ( sal_Int32 pos
= moduleDescr
.getLength(); pos
--; )
747 if ( pmoduleDescr
[ pos
].Name
== "ooSetupFactoryEmptyDocumentURL" )
749 pmoduleDescr
[ pos
].Value
>>= factoryURL
;
750 OSL_TRACE("factory url for doc images is %s",
751 OUStringToOString( factoryURL
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
756 if( !factoryURL
.isEmpty() )
758 aImage
= SvFileInformationManager::GetFileImage( INetURLObject(factoryURL
), false );
762 aImage
= pImp
->m_docImage
;
768 if( node
->getType() == browse::BrowseNodeTypes::SCRIPT
)
769 aImage
= pImp
->m_macImage
;
771 aImage
= pImp
->m_libImage
;
776 Reference
< XInterface
>
777 SfxConfigGroupListBox_Impl::getDocumentModel( Reference
< XComponentContext
>& xCtx
, OUString
& docName
)
779 Reference
< XInterface
> xModel
;
780 Reference
< frame::XDesktop2
> desktop
= frame::Desktop::create( xCtx
);
782 Reference
< container::XEnumerationAccess
> componentsAccess
=
783 desktop
->getComponents();
784 Reference
< container::XEnumeration
> components
=
785 componentsAccess
->createEnumeration();
786 while (components
->hasMoreElements())
788 Reference
< frame::XModel
> model(
789 components
->nextElement(), UNO_QUERY
);
793 ::comphelper::DocumentInfo::getDocumentTitle( model
);
794 if( sTdocUrl
.equals( docName
) )
804 //-----------------------------------------------
805 OUString
SfxConfigGroupListBox_Impl::MapCommand2UIName(const OUString
& sCommand
)
810 css::uno::Reference
< css::container::XNameAccess
> xModuleConf
;
811 m_xUICmdDescription
->getByName(m_sModuleLongName
) >>= xModuleConf
;
812 if (xModuleConf
.is())
814 ::comphelper::SequenceAsHashMap
lProps(xModuleConf
->getByName(sCommand
));
815 sUIName
= lProps
.getUnpackedValueOrDefault(OUString("Name"), OUString());
818 catch(const css::uno::RuntimeException
&)
820 catch(css::uno::Exception
&)
821 { sUIName
= OUString(); }
823 // fallback for missing UINames !?
824 if (sUIName
.isEmpty())
832 //-----------------------------------------------
833 void SfxConfigGroupListBox_Impl::GroupSelected()
835 A function group or a basic module has been selected.
836 All functions/macros are displayed in the functionlistbox.
839 SvTreeListEntry
*pEntry
= FirstSelected();
840 SfxGroupInfo_Impl
*pInfo
= (SfxGroupInfo_Impl
*) pEntry
->GetUserData();
841 pFunctionListBox
->SetUpdateMode(sal_False
);
842 pFunctionListBox
->ClearAll();
843 if ( pInfo
->nKind
!= SFX_CFGGROUP_FUNCTION
&&
844 pInfo
->nKind
!= SFX_CFGGROUP_SCRIPTCONTAINER
&&
845 pInfo
->nKind
!= SFX_CFGGROUP_STYLES
)
847 pFunctionListBox
->SetUpdateMode(sal_True
);
851 switch ( pInfo
->nKind
)
853 case SFX_CFGGROUP_FUNCTION
:
855 sal_uInt16 nGroup
= pInfo
->nUniqueID
;
856 css::uno::Reference
< css::frame::XDispatchInformationProvider
> xProvider (m_xFrame
, css::uno::UNO_QUERY_THROW
);
857 css::uno::Sequence
< css::frame::DispatchInformation
> lCommands
= xProvider
->getConfigurableDispatchInformation(nGroup
);
858 sal_Int32 c
= lCommands
.getLength();
863 const css::frame::DispatchInformation
& rInfo
= lCommands
[i
];
864 OUString sUIName
= MapCommand2UIName(rInfo
.Command
);
865 SvTreeListEntry
* pFuncEntry
= pFunctionListBox
->InsertEntry(sUIName
, NULL
);
866 SfxGroupInfo_Impl
* pGrpInfo
= new SfxGroupInfo_Impl(SFX_CFGFUNCTION_SLOT
, 0);
867 pGrpInfo
->sCommand
= rInfo
.Command
;
868 pGrpInfo
->sLabel
= sUIName
;
869 pFuncEntry
->SetUserData(pGrpInfo
);
875 case SFX_CFGGROUP_SCRIPTCONTAINER
:
877 if ( !GetChildCount( pEntry
) )
879 Reference
< browse::XBrowseNode
> rootNode(
880 reinterpret_cast< browse::XBrowseNode
* >( pInfo
->pObject
) ) ;
883 if ( rootNode
->hasChildNodes() )
885 Sequence
< Reference
< browse::XBrowseNode
> > children
=
886 rootNode
->getChildNodes();
888 for ( sal_Int32 n
= 0; n
< children
.getLength(); ++n
)
890 if (children
[n
]->getType() == browse::BrowseNodeTypes::SCRIPT
)
894 Reference
< beans::XPropertySet
>xPropSet( children
[n
], UNO_QUERY
);
901 xPropSet
->getPropertyValue( OUString("URI") );
904 String
* pScriptURI
= new String( uri
);
905 SfxGroupInfo_Impl
* pGrpInfo
= new SfxGroupInfo_Impl( SFX_CFGFUNCTION_SCRIPT
, 0, pScriptURI
);
907 Image aImage
= GetImage( children
[n
], Reference
< XComponentContext
>(), sal_False
);
908 SvTreeListEntry
* pNewEntry
=
909 pFunctionListBox
->InsertEntry( children
[n
]->getName(), NULL
);
910 pFunctionListBox
->SetExpandedEntryBmp( pNewEntry
, aImage
);
911 pFunctionListBox
->SetCollapsedEntryBmp(pNewEntry
, aImage
);
913 pGrpInfo
->sCommand
= uri
;
914 pGrpInfo
->sLabel
= children
[n
]->getName();
915 pNewEntry
->SetUserData( pGrpInfo
);
917 pFunctionListBox
->aArr
.push_back( pGrpInfo
);
923 catch (RuntimeException
&) {
924 // do nothing, the entry will not be displayed in the UI
930 case SFX_CFGGROUP_STYLES
:
932 SfxStyleInfo_Impl
* pFamily
= (SfxStyleInfo_Impl
*)(pInfo
->pObject
);
935 const ::std::vector
< SfxStyleInfo_Impl
> lStyles
= pStylesInfo
->getStyles(pFamily
->sFamily
);
936 ::std::vector
< SfxStyleInfo_Impl
>::const_iterator pIt
;
937 for ( pIt
= lStyles
.begin();
938 pIt
!= lStyles
.end() ;
941 SfxStyleInfo_Impl
* pStyle
= new SfxStyleInfo_Impl(*pIt
);
942 SvTreeListEntry
* pFuncEntry
= pFunctionListBox
->InsertEntry( pStyle
->sLabel
, NULL
);
943 SfxGroupInfo_Impl
*pGrpInfo
= new SfxGroupInfo_Impl( SFX_CFGGROUP_STYLES
, 0, pStyle
);
944 pFunctionListBox
->aArr
.push_back( pGrpInfo
);
945 pGrpInfo
->sCommand
= pStyle
->sCommand
;
946 pGrpInfo
->sLabel
= pStyle
->sLabel
;
947 pFuncEntry
->SetUserData( pGrpInfo
);
957 if ( pFunctionListBox
->GetEntryCount() )
958 pFunctionListBox
->Select( pFunctionListBox
->GetEntry( 0, 0 ) );
960 pFunctionListBox
->SetUpdateMode(sal_True
);
963 sal_Bool
SfxConfigGroupListBox_Impl::Expand( SvTreeListEntry
* pParent
)
965 sal_Bool bRet
= SvTreeListBox::Expand( pParent
);
968 sal_uLong nEntries
= GetOutputSizePixel().Height() / GetEntryHeight();
970 sal_uLong nChildCount
= GetVisibleChildCount( pParent
);
972 if ( nChildCount
+1 > nEntries
)
974 MakeVisible( pParent
, sal_True
);
978 SvTreeListEntry
*pEntry
= GetFirstEntryInView();
979 sal_uLong nParentPos
= 0;
980 while ( pEntry
&& pEntry
!= pParent
)
983 pEntry
= GetNextEntryInView( pEntry
);
986 if ( nParentPos
+ nChildCount
+ 1 > nEntries
)
987 ScrollOutputArea( (short)( nEntries
- ( nParentPos
+ nChildCount
+ 1 ) ) );
994 void SfxConfigGroupListBox_Impl::RequestingChildren( SvTreeListEntry
*pEntry
)
996 A basic or a library is opened.
999 SfxGroupInfo_Impl
*pInfo
= (SfxGroupInfo_Impl
*) pEntry
->GetUserData();
1000 pInfo
->bWasOpened
= sal_True
;
1001 switch ( pInfo
->nKind
)
1003 case SFX_CFGGROUP_SCRIPTCONTAINER
:
1005 if ( !GetChildCount( pEntry
) )
1007 Reference
< browse::XBrowseNode
> rootNode(
1008 reinterpret_cast< browse::XBrowseNode
* >( pInfo
->pObject
) ) ;
1011 if ( rootNode
->hasChildNodes() )
1013 Sequence
< Reference
< browse::XBrowseNode
> > children
=
1014 rootNode
->getChildNodes();
1015 sal_Bool bIsRootNode
= sal_False
;
1017 OUString
user("user");
1018 OUString
share("share" );
1019 if ( rootNode
->getName() == "Root" )
1021 bIsRootNode
= sal_True
;
1024 /* To mimic current starbasic behaviour we
1025 need to make sure that only the current document
1026 is displayed in the config tree. Tests below
1027 set the bDisplay flag to sal_False if the current
1028 node is a first level child of the Root and is NOT
1029 either the current document, user or share */
1030 OUString currentDocTitle
;
1031 Reference
< XModel
> xDocument( lcl_getScriptableDocument_nothrow( m_xFrame
) );
1032 if ( xDocument
.is() )
1034 currentDocTitle
= ::comphelper::DocumentInfo::getDocumentTitle( xDocument
);
1037 sal_Int32 nLen
= children
.getLength();
1038 for ( sal_Int32 n
= 0; n
< nLen
; ++n
)
1040 Reference
< browse::XBrowseNode
>& theChild
= children
[n
];
1041 OUString
aName( theChild
->getName() );
1042 sal_Bool bDisplay
= sal_True
;
1045 if ( !( (aName
.equals(user
) || aName
.equals(share
) || aName
.equals(currentDocTitle
) ) ) )
1048 if ( children
[n
].is() && children
[n
]->getType() != browse::BrowseNodeTypes::SCRIPT
&& bDisplay
)
1052 We call acquire on the XBrowseNode so that it does not
1053 get autodestructed and become invalid when accessed later.
1055 theChild
->acquire();
1057 SfxGroupInfo_Impl
* pGrpInfo
=
1058 new SfxGroupInfo_Impl(SFX_CFGGROUP_SCRIPTCONTAINER
,
1059 0, static_cast<void *>( theChild
.get()));
1061 Image aImage
= GetImage( theChild
, Reference
< XComponentContext
>(), sal_False
);
1062 SvTreeListEntry
* pNewEntry
=
1063 InsertEntry( theChild
->getName(), pEntry
);
1064 SetExpandedEntryBmp( pNewEntry
, aImage
);
1065 SetCollapsedEntryBmp(pNewEntry
, aImage
);
1067 pNewEntry
->SetUserData( pGrpInfo
);
1068 aArr
.push_back( pGrpInfo
);
1070 if ( children
[n
]->hasChildNodes() )
1072 Sequence
< Reference
< browse::XBrowseNode
> > grandchildren
=
1073 children
[n
]->getChildNodes();
1075 for ( sal_Int32 m
= 0; m
< grandchildren
.getLength(); ++m
)
1077 if ( grandchildren
[m
]->getType() == browse::BrowseNodeTypes::CONTAINER
)
1079 pNewEntry
->EnableChildrenOnDemand( sal_True
);
1080 m
= grandchildren
.getLength();
1088 catch (RuntimeException
&) {
1089 // do nothing, the entry will not be displayed in the UI
1095 case SFX_CFGGROUP_STYLES
:
1097 if ( !GetChildCount( pEntry
) )
1099 const ::std::vector
< SfxStyleInfo_Impl
> lStyleFamilies
= pStylesInfo
->getStyleFamilies();
1100 ::std::vector
< SfxStyleInfo_Impl
>::const_iterator pIt
;
1101 for ( pIt
= lStyleFamilies
.begin();
1102 pIt
!= lStyleFamilies
.end() ;
1105 SfxStyleInfo_Impl
* pFamily
= new SfxStyleInfo_Impl(*pIt
);
1106 SvTreeListEntry
* pStyleEntry
= InsertEntry( pFamily
->sLabel
, pEntry
);
1107 SfxGroupInfo_Impl
*pGrpInfo
= new SfxGroupInfo_Impl( SFX_CFGGROUP_STYLES
, 0, pFamily
);
1108 aArr
.push_back( pGrpInfo
);
1109 pStyleEntry
->SetUserData( pGrpInfo
);
1110 pStyleEntry
->EnableChildrenOnDemand( sal_False
);
1117 OSL_FAIL( "Falscher Gruppentyp!" );
1122 void SfxConfigGroupListBox_Impl::SelectMacro( const SfxMacroInfoItem
*pItem
)
1124 SelectMacro( pItem
->GetBasicManager()->GetName(),
1125 pItem
->GetQualifiedName() );
1128 void SfxConfigGroupListBox_Impl::SelectMacro( const String
& rBasic
,
1129 const String
& rMacro
)
1131 String
aBasicName( rBasic
);
1133 aBasicName
+= pImp
->m_sMacros
;
1134 String aLib
, aModule
, aMethod
;
1135 sal_uInt16 nCount
= comphelper::string::getTokenCount(rMacro
, '.');
1136 aMethod
= rMacro
.GetToken( nCount
-1, '.' );
1139 aLib
= rMacro
.GetToken( 0, '.' );
1140 aModule
= rMacro
.GetToken( nCount
-2, '.' );
1143 SvTreeListEntry
*pEntry
= FirstChild(0);
1146 String aEntryBas
= GetEntryText( pEntry
);
1147 if ( aEntryBas
== aBasicName
)
1150 SvTreeListEntry
*pLib
= FirstChild( pEntry
);
1153 String aEntryLib
= GetEntryText( pLib
);
1154 if ( aEntryLib
== aLib
)
1157 SvTreeListEntry
*pMod
= FirstChild( pLib
);
1160 String aEntryMod
= GetEntryText( pMod
);
1161 if ( aEntryMod
== aModule
)
1164 MakeVisible( pMod
);
1166 SvTreeListEntry
*pMethod
= pFunctionListBox
->First();
1169 String aEntryMethod
= GetEntryText( pMethod
);
1170 if ( aEntryMethod
== aMethod
)
1172 pFunctionListBox
->Select( pMethod
);
1173 pFunctionListBox
->MakeVisible( pMethod
);
1176 pMethod
= pFunctionListBox
->Next( pMethod
);
1179 pMod
= NextSibling( pMod
);
1182 pLib
= NextSibling( pLib
);
1185 pEntry
= NextSibling( pEntry
);
1189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */