xref: /aoo41x/main/cui/source/customize/cfgutil.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
30 
31 #include "cfgutil.hxx"
32 
33 #include <com/sun/star/beans/XPropertySet.hpp>
34 #include <com/sun/star/frame/XDispatchInformationProvider.hpp>
35 #include <com/sun/star/uno/RuntimeException.hpp>
36 #include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
37 #include <com/sun/star/script/provider/XScriptProvider.hpp>
38 #include <com/sun/star/script/browse/XBrowseNode.hpp>
39 #include <com/sun/star/script/browse/BrowseNodeTypes.hpp>
40 
41 #include <com/sun/star/script/browse/XBrowseNodeFactory.hpp>
42 #include <com/sun/star/script/browse/BrowseNodeFactoryViewTypes.hpp>
43 #include <com/sun/star/frame/XModuleManager.hpp>
44 #include <com/sun/star/frame/XDesktop.hpp>
45 #include <com/sun/star/container/XEnumerationAccess.hpp>
46 #include <com/sun/star/container/XEnumeration.hpp>
47 #include <com/sun/star/document/XDocumentInfoSupplier.hpp>
48 #include <com/sun/star/document/XScriptInvocationContext.hpp>
49 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
50 
51 #include "acccfg.hrc"
52 #include "helpid.hrc"
53 #include <basic/sbx.hxx>
54 #include <basic/basicmanagerrepository.hxx>
55 #include <basic/sbstar.hxx>
56 #include <basic/sbxmeth.hxx>
57 #include <basic/sbmod.hxx>
58 #include <basic/basmgr.hxx>
59 #include <tools/urlobj.hxx>
60 #include "cuires.hrc"
61 #include <sfx2/app.hxx>
62 #include <sfx2/minfitem.hxx>
63 #include <unotools/processfactory.hxx>
64 #include <comphelper/documentinfo.hxx>
65 #include <svtools/imagemgr.hxx>
66 #include <rtl/ustrbuf.hxx>
67 #include <comphelper/sequenceashashmap.hxx>
68 #include <unotools/configmgr.hxx>
69 #include "dialmgr.hxx"
70 #include <svl/stritem.hxx>
71 
72 #define _SVSTDARR_STRINGSDTOR
73 #include <svl/svstdarr.hxx>
74 
75 using namespace ::com::sun::star;
76 using namespace ::com::sun::star::uno;
77 using namespace ::com::sun::star::script;
78 using namespace ::com::sun::star::frame;
79 using namespace ::com::sun::star::document;
80 namespace css = ::com::sun::star;
81 
82 static ::rtl::OUString SERVICE_UICATEGORYDESCRIPTION = ::rtl::OUString::createFromAscii("com.sun.star.ui.UICategoryDescription"         );
83 static ::rtl::OUString SERVICE_UICMDDESCRIPTION      = ::rtl::OUString::createFromAscii("com.sun.star.frame.UICommandDescription");
84 
85 SfxStylesInfo_Impl::SfxStylesInfo_Impl()
86 {}
87 
88 void SfxStylesInfo_Impl::setModel(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xModel)
89 {
90     m_xDoc = xModel;
91 }
92 
93 static ::rtl::OUString FAMILY_CHARACTERSTYLE = ::rtl::OUString::createFromAscii("CharacterStyles");
94 static ::rtl::OUString FAMILY_PARAGRAPHSTYLE = ::rtl::OUString::createFromAscii("ParagraphStyles");
95 static ::rtl::OUString FAMILY_FRAMESTYLE     = ::rtl::OUString::createFromAscii("FrameStyles"    );
96 static ::rtl::OUString FAMILY_PAGESTYLE      = ::rtl::OUString::createFromAscii("PageStyles"     );
97 static ::rtl::OUString FAMILY_NUMBERINGSTYLE = ::rtl::OUString::createFromAscii("NumberingStyles");
98 
99 static ::rtl::OUString CMDURL_SPART  = ::rtl::OUString::createFromAscii(".uno:StyleApply?Style:string=");
100 static ::rtl::OUString CMDURL_FPART2 = ::rtl::OUString::createFromAscii("&FamilyName:string=");
101 
102 static ::rtl::OUString CMDURL_STYLEPROT_ONLY = ::rtl::OUString::createFromAscii(".uno:StyleApply?");
103 static ::rtl::OUString CMDURL_SPART_ONLY     = ::rtl::OUString::createFromAscii("Style:string=");
104 static ::rtl::OUString CMDURL_FPART_ONLY     = ::rtl::OUString::createFromAscii("FamilyName:string=");
105 
106 static ::rtl::OUString STYLEPROP_UINAME = ::rtl::OUString::createFromAscii("DisplayName");
107 
108 ::rtl::OUString SfxStylesInfo_Impl::generateCommand(const ::rtl::OUString& sFamily, const ::rtl::OUString& sStyle)
109 {
110     ::rtl::OUStringBuffer sCommand(1024);
111     sCommand.append(CMDURL_SPART );
112     sCommand.append(sStyle       );
113     sCommand.append(CMDURL_FPART2);
114     sCommand.append(sFamily      );
115     return sCommand.makeStringAndClear();
116 }
117 
118 sal_Bool SfxStylesInfo_Impl::parseStyleCommand(SfxStyleInfo_Impl& aStyle)
119 {
120     static sal_Int32 LEN_STYLEPROT = CMDURL_STYLEPROT_ONLY.getLength();
121     static sal_Int32 LEN_SPART     = CMDURL_SPART_ONLY.getLength();
122     static sal_Int32 LEN_FPART     = CMDURL_FPART_ONLY.getLength();
123 
124     if (aStyle.sCommand.indexOf(CMDURL_STYLEPROT_ONLY, 0) != 0)
125         return sal_False;
126 
127     aStyle.sFamily = ::rtl::OUString();
128     aStyle.sStyle  = ::rtl::OUString();
129 
130     sal_Int32       nCmdLen  = aStyle.sCommand.getLength();
131     ::rtl::OUString sCmdArgs = aStyle.sCommand.copy(LEN_STYLEPROT, nCmdLen-LEN_STYLEPROT);
132     sal_Int32       i        = sCmdArgs.indexOf('&');
133     if (i<0)
134         return sal_False;
135 
136     ::rtl::OUString sArg = sCmdArgs.copy(0, i);
137     if (sArg.indexOf(CMDURL_SPART_ONLY) == 0)
138         aStyle.sStyle = sArg.copy(LEN_SPART, sArg.getLength()-LEN_SPART);
139     else
140     if (sArg.indexOf(CMDURL_FPART_ONLY) == 0)
141         aStyle.sFamily = sArg.copy(LEN_FPART, sArg.getLength()-LEN_FPART);
142 
143     sArg = sCmdArgs.copy(i+1, sCmdArgs.getLength()-i-1);
144     if (sArg.indexOf(CMDURL_SPART_ONLY) == 0)
145         aStyle.sStyle = sArg.copy(LEN_SPART, sArg.getLength()-LEN_SPART);
146     else
147     if (sArg.indexOf(CMDURL_FPART_ONLY) == 0)
148         aStyle.sFamily = sArg.copy(LEN_FPART, sArg.getLength()-LEN_FPART);
149 
150     if (aStyle.sFamily.getLength() && aStyle.sStyle.getLength())
151         return sal_True;
152 
153     return sal_False;
154 }
155 
156 void SfxStylesInfo_Impl::getLabel4Style(SfxStyleInfo_Impl& aStyle)
157 {
158     try
159     {
160         css::uno::Reference< css::style::XStyleFamiliesSupplier > xModel(m_xDoc, css::uno::UNO_QUERY);
161 
162         css::uno::Reference< css::container::XNameAccess > xFamilies;
163         if (xModel.is())
164             xFamilies = xModel->getStyleFamilies();
165 
166         css::uno::Reference< css::container::XNameAccess > xStyleSet;
167         if (xFamilies.is())
168             xFamilies->getByName(aStyle.sFamily) >>= xStyleSet;
169 
170         css::uno::Reference< css::beans::XPropertySet > xStyle;
171         if (xStyleSet.is())
172             xStyleSet->getByName(aStyle.sStyle) >>= xStyle;
173 
174         aStyle.sLabel = ::rtl::OUString();
175         if (xStyle.is())
176             xStyle->getPropertyValue(STYLEPROP_UINAME) >>= aStyle.sLabel;
177     }
178     catch(const css::uno::RuntimeException& exRun)
179         { throw exRun; }
180     catch(const css::uno::Exception&)
181         { aStyle.sLabel = ::rtl::OUString(); }
182 
183     if (!aStyle.sLabel.getLength())
184     {
185         aStyle.sLabel = aStyle.sCommand;
186         /*
187         #if OSL_DEBUG_LEVEL > 1
188         ::rtl::OUStringBuffer sMsg(256);
189         sMsg.appendAscii("There is no UIName for the style command \"");
190         sMsg.append     (aStyle.sCommand                              );
191         sMsg.appendAscii("\". The UI will be invalid then ..."        );
192         OSL_ENSURE(sal_False, ::rtl::OUStringToOString(sMsg.makeStringAndClear(), RTL_TEXTENCODING_UTF8).getStr());
193         #endif
194         */
195     }
196 }
197 
198 ::std::vector< SfxStyleInfo_Impl > SfxStylesInfo_Impl::getStyleFamilies()
199 {
200     // Its an optional interface!
201     css::uno::Reference< css::style::XStyleFamiliesSupplier > xModel(m_xDoc, css::uno::UNO_QUERY);
202     if (!xModel.is())
203         return ::std::vector< SfxStyleInfo_Impl >();
204 
205     css::uno::Reference< css::container::XNameAccess > xCont = xModel->getStyleFamilies();
206     css::uno::Sequence< ::rtl::OUString > lFamilyNames = xCont->getElementNames();
207     ::std::vector< SfxStyleInfo_Impl > lFamilies;
208     sal_Int32 c = lFamilyNames.getLength();
209     sal_Int32 i = 0;
210     for(i=0; i<c; ++i)
211     {
212         SfxStyleInfo_Impl aFamilyInfo;
213         aFamilyInfo.sFamily = lFamilyNames[i];
214 
215         try
216         {
217             css::uno::Reference< css::beans::XPropertySet > xFamilyInfo;
218             xCont->getByName(aFamilyInfo.sFamily) >>= xFamilyInfo;
219             if (!xFamilyInfo.is())
220             {
221                 // TODO_AS currently there is no support for an UIName property .. use internal family name instead
222                 aFamilyInfo.sLabel = aFamilyInfo.sFamily;
223             }
224             else
225                 xFamilyInfo->getPropertyValue(STYLEPROP_UINAME) >>= aFamilyInfo.sLabel;
226         }
227         catch(const css::uno::RuntimeException& exRun)
228             { throw exRun; }
229         catch(const css::uno::Exception&)
230             { return ::std::vector< SfxStyleInfo_Impl >(); }
231 
232         lFamilies.push_back(aFamilyInfo);
233     }
234 
235     return lFamilies;
236 }
237 
238 ::std::vector< SfxStyleInfo_Impl > SfxStylesInfo_Impl::getStyles(const ::rtl::OUString& sFamily)
239 {
240     static ::rtl::OUString PROP_UINAME = ::rtl::OUString::createFromAscii("DisplayName");
241 
242     css::uno::Sequence< ::rtl::OUString > lStyleNames;
243     css::uno::Reference< css::style::XStyleFamiliesSupplier > xModel(m_xDoc, css::uno::UNO_QUERY_THROW);
244     css::uno::Reference< css::container::XNameAccess > xFamilies = xModel->getStyleFamilies();
245     css::uno::Reference< css::container::XNameAccess > xStyleSet;
246     try
247     {
248         xFamilies->getByName(sFamily) >>= xStyleSet;
249         lStyleNames = xStyleSet->getElementNames();
250     }
251     catch(const css::uno::RuntimeException& exRun)
252         { throw exRun; }
253     catch(const css::uno::Exception&)
254         { return ::std::vector< SfxStyleInfo_Impl >(); }
255 
256     ::std::vector< SfxStyleInfo_Impl > lStyles;
257     sal_Int32                          c      = lStyleNames.getLength();
258     sal_Int32                          i      = 0;
259     for (i=0; i<c; ++i)
260     {
261         SfxStyleInfo_Impl aStyleInfo;
262         aStyleInfo.sFamily  = sFamily;
263         aStyleInfo.sStyle   = lStyleNames[i];
264         aStyleInfo.sCommand = SfxStylesInfo_Impl::generateCommand(aStyleInfo.sFamily, aStyleInfo.sStyle);
265 
266         try
267         {
268             css::uno::Reference< css::beans::XPropertySet > xStyle;
269             xStyleSet->getByName(aStyleInfo.sStyle) >>= xStyle;
270             if (!xStyle.is())
271                 continue;
272             xStyle->getPropertyValue(PROP_UINAME) >>= aStyleInfo.sLabel;
273         }
274         catch(const css::uno::RuntimeException& exRun)
275             { throw exRun; }
276         catch(const css::uno::Exception&)
277             { continue; }
278 
279         lStyles.push_back(aStyleInfo);
280     }
281     return lStyles;
282 }
283 SV_IMPL_PTRARR(SfxGroupInfoArr_Impl, SfxGroupInfoPtr);
284 SfxConfigFunctionListBox_Impl::SfxConfigFunctionListBox_Impl( Window* pParent, const ResId& rResId)
285 	: SvTreeListBox( pParent, rResId )
286 	, pCurEntry( 0 )
287     , pStylesInfo( 0 )
288 {
289 	SetStyle( GetStyle() | WB_CLIPCHILDREN | WB_HSCROLL | WB_SORT );
290 	GetModel()->SetSortMode( SortAscending );
291 
292 	// Timer f"ur die BallonHelp
293 	aTimer.SetTimeout( 200 );
294 	aTimer.SetTimeoutHdl(
295 		LINK( this, SfxConfigFunctionListBox_Impl, TimerHdl ) );
296 }
297 
298 SfxConfigFunctionListBox_Impl::~SfxConfigFunctionListBox_Impl()
299 {
300 	ClearAll();
301 }
302 
303 void SfxConfigFunctionListBox_Impl::MouseMove( const MouseEvent& )
304 {
305     /* --> PB 2004-12-01 #i37000# - no own help text needed any longer
306 	Point aMousePos = rMEvt.GetPosPixel();
307 	pCurEntry = GetCurEntry();
308 
309 	if ( pCurEntry && GetEntry( aMousePos ) == pCurEntry )
310 		aTimer.Start();
311 	else
312 	{
313         Help::ShowBalloon( this, aMousePos, String() );
314 		aTimer.Stop();
315 	}
316     */
317 }
318 
319 
320 IMPL_LINK( SfxConfigFunctionListBox_Impl, TimerHdl, Timer*, pTimer)
321 /*  Beschreibung
322 	Timer-Handler f"ur die Einblendung eines Hilfetextes. Wenn nach Ablauf des Timers
323 	der Mauszeiger immer noch auf dem aktuell selektierten Eintrag steht, wird der
324 	Helptext des Entries als Balloon-Help eingeblendet.
325 */
326 {
327     (void)pTimer; // unused
328     /* --> PB 2004-12-01 #i37000# - no own help text needed any longer
329 	aTimer.Stop();
330 	Point aMousePos = GetPointerPosPixel();
331 	SvLBoxEntry *pEntry = GetCurEntry();
332 	if ( pEntry && GetEntry( aMousePos ) == pEntry && pCurEntry == pEntry )
333     {
334         String sHelpText = GetHelpText( pEntry );
335         Help::ShowBalloon( this, OutputToScreenPixel( aMousePos ), sHelpText );
336     }
337     */
338 	return 0L;
339 }
340 
341 void SfxConfigFunctionListBox_Impl::ClearAll()
342 /* 	Beschreibung
343 	L"oscht alle Eintr"age in der FunctionListBox, alle UserDaten und alle evtl.
344 	vorhandenen MacroInfos.
345 */
346 {
347 	sal_uInt16 nCount = aArr.Count();
348 	for ( sal_uInt16 i=0; i<nCount; i++ )
349 	{
350 		SfxGroupInfo_Impl *pData = aArr[i];
351 
352 		if ( pData->nKind == SFX_CFGFUNCTION_SCRIPT )
353 		{
354 			String* pScriptURI = (String*)pData->pObject;
355 			delete pScriptURI;
356 		}
357 
358 		if  (   pData->nKind == SFX_CFGGROUP_SCRIPTCONTAINER
359             )
360 		{
361 			XInterface* xi = static_cast<XInterface *>(pData->pObject);
362 			if (xi != NULL)
363 			{
364 				xi->release();
365 			}
366 		}
367 
368 		delete pData;
369 	}
370 
371 	aArr.Remove( 0, nCount );
372 	Clear();
373 }
374 
375 String SfxConfigFunctionListBox_Impl::GetSelectedScriptURI()
376 {
377 	SvLBoxEntry *pEntry = FirstSelected();
378 	if ( pEntry )
379 	{
380 		SfxGroupInfo_Impl *pData = (SfxGroupInfo_Impl*) pEntry->GetUserData();
381 		if ( pData && ( pData->nKind == SFX_CFGFUNCTION_SCRIPT ) )
382 			return *(String*)pData->pObject;
383 	}
384 	return String();
385 }
386 
387 String SfxConfigFunctionListBox_Impl::GetCurCommand()
388 {
389 	SvLBoxEntry *pEntry = FirstSelected();
390     if (!pEntry)
391         return String();
392 	SfxGroupInfo_Impl *pData = (SfxGroupInfo_Impl*) pEntry->GetUserData();
393     if (!pData)
394         return String();
395     return pData->sCommand;
396 }
397 
398 String SfxConfigFunctionListBox_Impl::GetCurLabel()
399 {
400 	SvLBoxEntry *pEntry = FirstSelected();
401     if (!pEntry)
402         return String();
403 	SfxGroupInfo_Impl *pData = (SfxGroupInfo_Impl*) pEntry->GetUserData();
404     if (!pData)
405         return String();
406     if (pData->sLabel.Len())
407         return pData->sLabel;
408     return pData->sCommand;
409 }
410 
411 void SfxConfigFunctionListBox_Impl::FunctionSelected()
412 /*	Beschreibung
413 	Setzt die Balloonhelp zur"uck, da diese immer den Helptext des selektierten
414 	Entry anzeigen soll.
415 */
416 {
417     /* --> PB 2004-12-01 #i37000# - no own help text needed any longer
418     Help::ShowBalloon( this, Point(), String() );
419     */
420 }
421 
422 void SfxConfigFunctionListBox_Impl::SetStylesInfo(SfxStylesInfo_Impl* pStyles)
423 {
424     pStylesInfo = pStyles;
425 }
426 
427 struct SvxConfigGroupBoxResource_Impl : public Resource
428 {
429     Image m_hdImage;
430     Image m_hdImage_hc;
431     Image m_libImage;
432     Image m_libImage_hc;
433     Image m_macImage;
434     Image m_macImage_hc;
435     Image m_docImage;
436     Image m_docImage_hc;
437     ::rtl::OUString m_sMyMacros;
438     ::rtl::OUString m_sProdMacros;
439 	String m_sMacros;
440 	String m_sDlgMacros;
441 	String m_aHumanAppName;
442 	String m_aStrGroupStyles;
443 	Image m_collapsedImage;
444 	Image m_collapsedImage_hc;
445 	Image m_expandedImage;
446 	Image m_expandedImage_hc;
447 
448     SvxConfigGroupBoxResource_Impl();
449 };
450 
451 SvxConfigGroupBoxResource_Impl::SvxConfigGroupBoxResource_Impl() :
452     Resource(CUI_RES(RID_SVXPAGE_CONFIGGROUPBOX)),
453     m_hdImage(CUI_RES(IMG_HARDDISK)),
454     m_hdImage_hc(CUI_RES(IMG_HARDDISK_HC)),
455     m_libImage(CUI_RES(IMG_LIB)),
456     m_libImage_hc(CUI_RES(IMG_LIB_HC)),
457     m_macImage(CUI_RES(IMG_MACRO)),
458     m_macImage_hc(CUI_RES(IMG_MACRO_HC)),
459     m_docImage(CUI_RES(IMG_DOC)),
460     m_docImage_hc(CUI_RES(IMG_DOC_HC)),
461     m_sMyMacros(String(CUI_RES(STR_MYMACROS))),
462     m_sProdMacros(String(CUI_RES(STR_PRODMACROS))),
463     m_sMacros(String(CUI_RES(STR_BASICMACROS))),
464     m_sDlgMacros(String(CUI_RES(STR_DLG_MACROS))),
465 	m_aHumanAppName(String(CUI_RES(STR_HUMAN_APPNAME))),
466 	m_aStrGroupStyles(String(CUI_RES(STR_GROUP_STYLES))),
467 	m_collapsedImage(CUI_RES(BMP_COLLAPSED)),
468 	m_collapsedImage_hc(CUI_RES(BMP_COLLAPSED_HC)),
469 	m_expandedImage(CUI_RES(BMP_EXPANDED)),
470 	m_expandedImage_hc(CUI_RES(BMP_EXPANDED_HC))
471 {
472     FreeResource();
473 }
474 
475 SfxConfigGroupListBox_Impl::SfxConfigGroupListBox_Impl(
476 	Window* pParent, const ResId& rResId, sal_uLong nConfigMode )
477 		: SvTreeListBox( pParent, rResId )
478 		, pImp(new SvxConfigGroupBoxResource_Impl()), pFunctionListBox(0), nMode( nConfigMode ), pStylesInfo(0)
479 {
480     SetStyle( GetStyle() | WB_CLIPCHILDREN | WB_HSCROLL | WB_HASBUTTONS | WB_HASLINES | WB_HASLINESATROOT | WB_HASBUTTONSATROOT );
481 	SetNodeBitmaps( pImp->m_collapsedImage, pImp->m_expandedImage, BMP_COLOR_NORMAL );
482 	SetNodeBitmaps( pImp->m_collapsedImage_hc, pImp->m_expandedImage_hc, BMP_COLOR_HIGHCONTRAST );
483 }
484 
485 
486 SfxConfigGroupListBox_Impl::~SfxConfigGroupListBox_Impl()
487 {
488 	ClearAll();
489 }
490 
491 void SfxConfigGroupListBox_Impl::ClearAll()
492 {
493 	sal_uInt16 nCount = aArr.Count();
494 	for ( sal_uInt16 i=0; i<nCount; i++ )
495 	{
496 		SfxGroupInfo_Impl *pData = aArr[i];
497 		if  (   pData->nKind == SFX_CFGGROUP_SCRIPTCONTAINER
498             )
499 		{
500 			XInterface* xi = static_cast<XInterface *>(pData->pObject);
501 			if (xi != NULL)
502 			{
503 				xi->release();
504 			}
505 		}
506 		delete pData;
507 	}
508 
509 	aArr.Remove( 0, nCount );
510 	Clear();
511 }
512 
513 void SfxConfigGroupListBox_Impl::SetStylesInfo(SfxStylesInfo_Impl* pStyles)
514 {
515     pStylesInfo = pStyles;
516 }
517 
518 String SfxConfigGroupListBox_Impl::GetGroup()
519 /*	Beschreibung
520 	Gibt den Namen der selektierten Funktionsgruppe bzw. des selektierten
521 	Basics zur"uck.
522 */
523 {
524     SvLBoxEntry *pEntry = FirstSelected();
525     while ( pEntry )
526     {
527         SfxGroupInfo_Impl *pInfo = (SfxGroupInfo_Impl*) pEntry->GetUserData();
528 	    if ( pInfo->nKind == SFX_CFGGROUP_FUNCTION )
529             return GetEntryText( pEntry );
530 
531         pEntry = GetParent( pEntry );
532     }
533 
534     return String();
535 }
536 
537 //-----------------------------------------------
538 void SfxConfigGroupListBox_Impl::InitModule()
539 {
540     try
541     {
542         css::uno::Reference< css::frame::XDispatchInformationProvider > xProvider(m_xFrame, css::uno::UNO_QUERY_THROW);
543         css::uno::Sequence< sal_Int16 > lGroups = xProvider->getSupportedCommandGroups();
544         sal_Int32                       c1      = lGroups.getLength();
545         sal_Int32                       i1      = 0;
546 
547         for (i1=0; i1<c1; ++i1)
548         {
549             sal_Int16&      rGroupID   = lGroups[i1];
550             ::rtl::OUString sGroupID   = ::rtl::OUString::valueOf((sal_Int32)rGroupID);
551             ::rtl::OUString sGroupName ;
552 
553             try
554             {
555                 m_xModuleCategoryInfo->getByName(sGroupID) >>= sGroupName;
556                 if (!sGroupName.getLength())
557                     continue;
558             }
559             catch(const css::container::NoSuchElementException&)
560                 { continue; }
561 
562             SvLBoxEntry*        pEntry = InsertEntry(sGroupName, NULL);
563             SfxGroupInfo_Impl* pInfo   = new SfxGroupInfo_Impl(SFX_CFGGROUP_FUNCTION, rGroupID);
564             pEntry->SetUserData(pInfo);
565         }
566     }
567     catch(const css::uno::RuntimeException& exRun)
568         { throw exRun; }
569     catch(const css::uno::Exception&)
570         {}
571 }
572 
573 //-----------------------------------------------
574 void SfxConfigGroupListBox_Impl::InitBasic()
575 {
576 }
577 
578 //-----------------------------------------------
579 void SfxConfigGroupListBox_Impl::InitStyles()
580 {
581 }
582 
583 //-----------------------------------------------
584 namespace
585 {
586     //...........................................
587     /** examines a component whether it supports XEmbeddedScripts, or provides access to such a
588         component by implementing XScriptInvocationContext.
589         @return
590             the model which supports the embedded scripts, or <NULL/> if it cannot find such a
591             model
592     */
593     static Reference< XModel > lcl_getDocumentWithScripts_throw( const Reference< XInterface >& _rxComponent )
594     {
595         Reference< XEmbeddedScripts > xScripts( _rxComponent, UNO_QUERY );
596         if ( !xScripts.is() )
597         {
598             Reference< XScriptInvocationContext > xContext( _rxComponent, UNO_QUERY );
599             if ( xContext.is() )
600                 xScripts.set( xContext->getScriptContainer(), UNO_QUERY );
601         }
602 
603         return Reference< XModel >( xScripts, UNO_QUERY );
604     }
605 
606     //...........................................
607     static Reference< XModel > lcl_getScriptableDocument_nothrow( const Reference< XFrame >& _rxFrame )
608     {
609         Reference< XModel > xDocument;
610 
611         // examine our associated frame
612         try
613         {
614             OSL_ENSURE( _rxFrame.is(), "lcl_getScriptableDocument_nothrow: you need to pass a frame to this dialog/tab page!" );
615             if ( _rxFrame.is() )
616             {
617                 // first try the model in the frame
618                 Reference< XController > xController( _rxFrame->getController(), UNO_SET_THROW );
619                 xDocument = lcl_getDocumentWithScripts_throw( xController->getModel() );
620 
621                 if ( !xDocument.is() )
622                 {
623                     // if there is no suitable document in the frame, try the controller
624                     xDocument = lcl_getDocumentWithScripts_throw( _rxFrame->getController() );
625                 }
626             }
627         }
628         catch( const Exception& )
629         {
630         	//DBG_UNHANDLED_EXCEPTION();
631         }
632 
633         return xDocument;
634     }
635 }
636 
637 //-----------------------------------------------
638 void SfxConfigGroupListBox_Impl::Init(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR          ,
639                                       const css::uno::Reference< css::frame::XFrame >&              xFrame         ,
640                                       const ::rtl::OUString&                                        sModuleLongName)
641 {
642 	SetUpdateMode(sal_False);
643 	ClearAll(); // Remove all old entries from treelist box
644 
645     m_xFrame = xFrame;
646     if ( xSMGR.is())
647     {
648         m_xSMGR           = xSMGR;
649         m_sModuleLongName = sModuleLongName;
650 
651         m_xGlobalCategoryInfo = css::uno::Reference< css::container::XNameAccess >(m_xSMGR->createInstance(SERVICE_UICATEGORYDESCRIPTION), css::uno::UNO_QUERY_THROW);
652         m_xModuleCategoryInfo = css::uno::Reference< css::container::XNameAccess >(m_xGlobalCategoryInfo->getByName(m_sModuleLongName)   , css::uno::UNO_QUERY_THROW);
653         m_xUICmdDescription   = css::uno::Reference< css::container::XNameAccess >(m_xSMGR->createInstance(SERVICE_UICMDDESCRIPTION)     , css::uno::UNO_QUERY_THROW);
654 
655         InitModule();
656         InitBasic();
657         InitStyles();
658     }
659 
660     OSL_TRACE("** ** About to initialise SF Scripts");
661 	// Add Scripting Framework entries
662 	Reference< browse::XBrowseNode > rootNode;
663     Reference< XComponentContext > xCtx;
664 	try
665 	{
666 		Reference < beans::XPropertySet > xProps(
667 			::comphelper::getProcessServiceFactory(), UNO_QUERY_THROW );
668 		xCtx.set( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), UNO_QUERY_THROW );
669 		Reference< browse::XBrowseNodeFactory > xFac( xCtx->getValueByName(
670 			::rtl::OUString::createFromAscii( "/singletons/com.sun.star.script.browse.theBrowseNodeFactory") ), UNO_QUERY_THROW );
671 		rootNode.set( xFac->createView( browse::BrowseNodeFactoryViewTypes::MACROSELECTOR ) );
672 		//rootNode.set( xFac->createView( browse::BrowseNodeFactoryViewTypes::MACROORGANIZER ) );
673 	}
674 	catch( Exception& e )
675 	{
676 		OSL_TRACE(" Caught some exception whilst retrieving browse nodes from factory... Exception: %s",
677 			::rtl::OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US ).pData->buffer );
678 		// TODO exception handling
679 	}
680 
681 
682 	if ( rootNode.is() )
683 	{
684 		if ( nMode )
685 		{
686 				//We call acquire on the XBrowseNode so that it does not
687 				//get autodestructed and become invalid when accessed later.
688 			rootNode->acquire();
689 
690 			SfxGroupInfo_Impl *pInfo =
691 				new SfxGroupInfo_Impl( SFX_CFGGROUP_SCRIPTCONTAINER, 0,
692 					static_cast<void *>(rootNode.get()));
693 
694 			String aTitle(pImp->m_sDlgMacros);
695 			SvLBoxEntry *pNewEntry = InsertEntry( aTitle, NULL );
696 			pNewEntry->SetUserData( pInfo );
697 			pNewEntry->EnableChildsOnDemand( sal_True );
698 			aArr.Insert( pInfo, aArr.Count() );
699 		}
700 		else
701 		{
702 			 //We are only showing scripts not slot APIs so skip
703 			 //Root node and show location nodes
704 			try {
705 				if ( rootNode->hasChildNodes() )
706 				{
707 					Sequence< Reference< browse::XBrowseNode > > children =
708 						rootNode->getChildNodes();
709 					sal_Bool bIsRootNode = sal_False;
710 
711 					::rtl::OUString user = ::rtl::OUString::createFromAscii("user");
712 					::rtl::OUString share = ::rtl::OUString::createFromAscii("share");
713 					if ( rootNode->getName().equals(::rtl::OUString::createFromAscii("Root") ))
714 					{
715 						bIsRootNode = sal_True;
716 					}
717 
718 					//To mimic current starbasic behaviour we
719 					//need to make sure that only the current document
720 					//is displayed in the config tree. Tests below
721 					//set the bDisplay flag to FALSE if the current
722 					//node is a first level child of the Root and is NOT
723 					//either the current document, user or share
724 					::rtl::OUString currentDocTitle;
725                     Reference< XModel > xDocument( lcl_getScriptableDocument_nothrow( m_xFrame ) );
726                     if ( xDocument.is() )
727                     {
728                         currentDocTitle = ::comphelper::DocumentInfo::getDocumentTitle( xDocument );
729 					}
730 
731                     for ( sal_Int32 n = 0; n < children.getLength(); n++ )
732 					{
733 						Reference< browse::XBrowseNode >& theChild = children[n];
734 						sal_Bool bDisplay = sal_True;
735                         ::rtl::OUString uiName = theChild->getName();
736 						if ( bIsRootNode )
737 						{
738 							if (  ! ((theChild->getName().equals( user )  || theChild->getName().equals( share ) ||
739 								theChild->getName().equals( currentDocTitle ) ) ) )
740 							{
741 								bDisplay=sal_False;
742 							}
743                             else
744                             {
745                                 if ( uiName.equals( user ) )
746                                 {
747                                     uiName = pImp->m_sMyMacros;
748                                 }
749                                 else if ( uiName.equals( share ) )
750                                 {
751                                     uiName = pImp->m_sProdMacros;
752                                 }
753                             }
754 						}
755 						if (children[n]->getType() != browse::BrowseNodeTypes::SCRIPT  && bDisplay )
756 						{
757 
758 //									We call acquire on the XBrowseNode so that it does not
759 //									get autodestructed and become invalid when accessed later.
760 							theChild->acquire();
761 
762 							SfxGroupInfo_Impl* pInfo =
763 								new SfxGroupInfo_Impl(SFX_CFGGROUP_SCRIPTCONTAINER,
764 									0, static_cast<void *>( theChild.get()));
765 
766                             Image aImage = GetImage( theChild, xCtx, bIsRootNode,BMP_COLOR_NORMAL );
767 							SvLBoxEntry* pNewEntry =
768 								InsertEntry( uiName, NULL);
769                             SetExpandedEntryBmp(pNewEntry, aImage, BMP_COLOR_NORMAL);
770                             SetCollapsedEntryBmp(pNewEntry, aImage, BMP_COLOR_NORMAL);
771                             aImage = GetImage( theChild, xCtx, bIsRootNode,BMP_COLOR_HIGHCONTRAST );
772                             SetExpandedEntryBmp(pNewEntry, aImage, BMP_COLOR_HIGHCONTRAST);
773                             SetCollapsedEntryBmp(pNewEntry, aImage, BMP_COLOR_HIGHCONTRAST);
774 
775 							pNewEntry->SetUserData( pInfo );
776 							aArr.Insert( pInfo, aArr.Count() );
777 
778 							if ( children[n]->hasChildNodes() )
779 							{
780 								Sequence< Reference< browse::XBrowseNode > > grandchildren =
781 									children[n]->getChildNodes();
782 
783                                 for ( sal_Int32 m = 0; m < grandchildren.getLength(); m++ )
784 								{
785 									if ( grandchildren[m]->getType() == browse::BrowseNodeTypes::CONTAINER )
786 									{
787 										pNewEntry->EnableChildsOnDemand( sal_True );
788 										m = grandchildren.getLength();
789 									}
790 								}
791 							}
792 						}
793 					}
794 				}
795 			}
796             catch (RuntimeException&) {
797 				// do nothing, the entry will not be displayed in the UI
798 			}
799 		}
800 	}
801 
802     // add styles
803     if ( m_xSMGR.is() )
804     {
805         String sStyle( pImp->m_aStrGroupStyles );
806         SvLBoxEntry *pEntry = InsertEntry( sStyle, 0 );
807         SfxGroupInfo_Impl *pInfo = new SfxGroupInfo_Impl( SFX_CFGGROUP_STYLES, 0, 0 ); // TODO last parameter should contain user data
808         aArr.Insert( pInfo, aArr.Count() );
809         pEntry->SetUserData( pInfo );
810         pEntry->EnableChildsOnDemand( sal_True );
811     }
812 
813 	MakeVisible( GetEntry( 0,0 ) );
814 	SetUpdateMode( sal_True );
815 }
816 Image SfxConfigGroupListBox_Impl::GetImage( Reference< browse::XBrowseNode > node, Reference< XComponentContext > xCtx, bool bIsRootNode, bool bHighContrast )
817 {
818     Image aImage;
819     if ( bIsRootNode )
820     {
821         ::rtl::OUString user = ::rtl::OUString::createFromAscii("user");
822         ::rtl::OUString share = ::rtl::OUString::createFromAscii("share");
823         if (node->getName().equals( user ) || node->getName().equals(share ) )
824         {
825             if( bHighContrast == BMP_COLOR_NORMAL )
826                 aImage = pImp->m_hdImage;
827             else
828 				aImage = pImp->m_hdImage_hc;
829         }
830         else
831         {
832             ::rtl::OUString factoryURL;
833             ::rtl::OUString nodeName = node->getName();
834             Reference<XInterface> xDocumentModel = getDocumentModel(xCtx, nodeName );
835             if ( xDocumentModel.is() )
836             {
837                 Reference< ::com::sun::star::frame::XModuleManager >
838                     xModuleManager(
839                         xCtx->getServiceManager()
840                             ->createInstanceWithContext(
841                                 ::rtl::OUString::createFromAscii("" // xxx todo
842                                       "com.sun.star.frame.ModuleManager"),
843                                 xCtx ),
844                             UNO_QUERY_THROW );
845                 Reference<container::XNameAccess> xModuleConfig(
846                     xModuleManager, UNO_QUERY_THROW );
847                 // get the long name of the document:
848                 ::rtl::OUString appModule( xModuleManager->identify(
849                                     xDocumentModel ) );
850                 Sequence<beans::PropertyValue> moduleDescr;
851                 Any aAny = xModuleConfig->getByName(appModule);
852                 if( sal_True != ( aAny >>= moduleDescr ) )
853                 {
854                     throw RuntimeException(::rtl::OUString::createFromAscii("SFTreeListBox::Init: failed to get PropertyValue"), Reference< XInterface >());
855                 }
856                 beans::PropertyValue const * pmoduleDescr =
857                     moduleDescr.getConstArray();
858                 for ( sal_Int32 pos = moduleDescr.getLength(); pos--; )
859                 {
860                     if (pmoduleDescr[ pos ].Name.equalsAsciiL(
861                             RTL_CONSTASCII_STRINGPARAM(
862                                 "ooSetupFactoryEmptyDocumentURL") ))
863                     {
864                         pmoduleDescr[ pos ].Value >>= factoryURL;
865                         OSL_TRACE("factory url for doc images is %s",
866                         ::rtl::OUStringToOString( factoryURL , RTL_TEXTENCODING_ASCII_US ).pData->buffer );
867                         break;
868                     }
869                 }
870             }
871             if( factoryURL.getLength() > 0 )
872             {
873                 if( bHighContrast == BMP_COLOR_NORMAL )
874                     aImage = SvFileInformationManager::GetFileImage(
875                         INetURLObject(factoryURL), false,
876                         BMP_COLOR_NORMAL );
877                 else
878                     aImage = SvFileInformationManager::GetFileImage(
879                         INetURLObject(factoryURL), false,
880                         BMP_COLOR_HIGHCONTRAST );
881             }
882             else
883             {
884                 if( bHighContrast == BMP_COLOR_NORMAL )
885                     aImage = pImp->m_docImage;
886                 else
887                     aImage = pImp->m_docImage_hc;
888             }
889         }
890     }
891     else
892     {
893         if( node->getType() == browse::BrowseNodeTypes::SCRIPT )
894         {
895             if( bHighContrast == BMP_COLOR_NORMAL )
896                 aImage = pImp->m_macImage;
897             else
898                 aImage = pImp->m_macImage_hc;
899         }
900         else
901         {
902             if( bHighContrast == BMP_COLOR_NORMAL )
903                 aImage = pImp->m_libImage;
904             else
905                 aImage = pImp->m_libImage_hc;
906         }
907     }
908     return aImage;
909 }
910 
911 Reference< XInterface  >
912 SfxConfigGroupListBox_Impl::getDocumentModel( Reference< XComponentContext >& xCtx, ::rtl::OUString& docName )
913 {
914     Reference< XInterface > xModel;
915     Reference< lang::XMultiComponentFactory > mcf =
916             xCtx->getServiceManager();
917     Reference< frame::XDesktop > desktop (
918         mcf->createInstanceWithContext(
919             ::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop"),                 xCtx ),
920             UNO_QUERY );
921 
922     Reference< container::XEnumerationAccess > componentsAccess =
923         desktop->getComponents();
924     Reference< container::XEnumeration > components =
925         componentsAccess->createEnumeration();
926     while (components->hasMoreElements())
927     {
928         Reference< frame::XModel > model(
929             components->nextElement(), UNO_QUERY );
930         if ( model.is() )
931         {
932             ::rtl::OUString sTdocUrl =
933                 ::comphelper::DocumentInfo::getDocumentTitle( model );
934             if( sTdocUrl.equals( docName ) )
935             {
936                 xModel = model;
937                 break;
938             }
939         }
940     }
941     return xModel;
942 }
943 
944 //-----------------------------------------------
945 ::rtl::OUString SfxConfigGroupListBox_Impl::MapCommand2UIName(const ::rtl::OUString& sCommand)
946 {
947     ::rtl::OUString sUIName;
948     try
949     {
950         css::uno::Reference< css::container::XNameAccess > xModuleConf;
951         m_xUICmdDescription->getByName(m_sModuleLongName) >>= xModuleConf;
952         if (xModuleConf.is())
953         {
954             ::comphelper::SequenceAsHashMap lProps(xModuleConf->getByName(sCommand));
955             sUIName = lProps.getUnpackedValueOrDefault(::rtl::OUString::createFromAscii("Name"), ::rtl::OUString());
956         }
957     }
958     catch(const css::uno::RuntimeException& exRun)
959         { throw exRun; }
960     catch(css::uno::Exception&)
961         { sUIName = ::rtl::OUString(); }
962 
963     // fallback for missing UINames !?
964     if (!sUIName.getLength())
965     {
966         sUIName = sCommand;
967         /*
968         #if OSL_DEBUG_LEVEL > 1
969         ::rtl::OUStringBuffer sMsg(256);
970         sMsg.appendAscii("There is no UIName for the internal command \"");
971         sMsg.append     (sCommand                                        );
972         sMsg.appendAscii("\". The UI will be invalid then ..."           );
973         OSL_ENSURE(sal_False, ::rtl::OUStringToOString(sMsg.makeStringAndClear(), RTL_TEXTENCODING_UTF8).getStr());
974         #endif
975         */
976     }
977 
978     return sUIName;
979 }
980 
981 //-----------------------------------------------
982 void SfxConfigGroupListBox_Impl::GroupSelected()
983 /*	Beschreibung
984 	Eine Funktionsgruppe oder eine Basicmodul wurde selektiert. Alle Funktionen bzw.
985 	Macros werden in der Functionlistbox anzeigt.
986 */
987 {
988 	SvLBoxEntry *pEntry = FirstSelected();
989 	SfxGroupInfo_Impl *pInfo = (SfxGroupInfo_Impl*) pEntry->GetUserData();
990 	pFunctionListBox->SetUpdateMode(sal_False);
991 	pFunctionListBox->ClearAll();
992 	if ( pInfo->nKind != SFX_CFGGROUP_FUNCTION &&
993 			 pInfo->nKind != SFX_CFGGROUP_SCRIPTCONTAINER &&
994              pInfo->nKind != SFX_CFGGROUP_STYLES )
995 	{
996 		pFunctionListBox->SetUpdateMode(sal_True);
997 		return;
998 	}
999 
1000 	switch ( pInfo->nKind )
1001 	{
1002 		case SFX_CFGGROUP_FUNCTION :
1003 		{
1004 			sal_uInt16                                                          nGroup    = pInfo->nUniqueID;
1005             css::uno::Reference< css::frame::XDispatchInformationProvider > xProvider (m_xFrame, css::uno::UNO_QUERY_THROW);
1006             css::uno::Sequence< css::frame::DispatchInformation >           lCommands = xProvider->getConfigurableDispatchInformation(nGroup);
1007             sal_Int32                                                       c         = lCommands.getLength();
1008             sal_Int32                                                       i         = 0;
1009 
1010             for (i=0; i<c; ++i)
1011             {
1012                 const css::frame::DispatchInformation& rInfo      = lCommands[i];
1013                 ::rtl::OUString                        sUIName    = MapCommand2UIName(rInfo.Command);
1014                 SvLBoxEntry*                           pFuncEntry = pFunctionListBox->InsertEntry(sUIName, NULL);
1015                 SfxGroupInfo_Impl*                     pGrpInfo   = new SfxGroupInfo_Impl(SFX_CFGFUNCTION_SLOT, 0);
1016                 pGrpInfo->sCommand = rInfo.Command;
1017                 pGrpInfo->sLabel   = sUIName;
1018                 pFuncEntry->SetUserData(pGrpInfo);
1019             }
1020 
1021 			break;
1022 		}
1023 
1024 		case SFX_CFGGROUP_SCRIPTCONTAINER:
1025 		{
1026 			if ( !GetChildCount( pEntry ) )
1027 			{
1028 				Reference< browse::XBrowseNode > rootNode(
1029 					reinterpret_cast< browse::XBrowseNode* >( pInfo->pObject ) ) ;
1030 
1031 				try {
1032 					if ( rootNode->hasChildNodes() )
1033 					{
1034 						Sequence< Reference< browse::XBrowseNode > > children =
1035 							rootNode->getChildNodes();
1036 
1037                         for ( sal_Int32 n = 0; n < children.getLength(); n++ )
1038 						{
1039 							if (children[n]->getType() == browse::BrowseNodeTypes::SCRIPT)
1040 							{
1041 								::rtl::OUString uri;
1042 
1043 								Reference < beans::XPropertySet >xPropSet( children[n], UNO_QUERY );
1044 								if (!xPropSet.is())
1045 								{
1046 									continue;
1047 								}
1048 
1049 								Any value =
1050 									xPropSet->getPropertyValue( String::CreateFromAscii( "URI" ) );
1051 								value >>= uri;
1052 
1053 								String* pScriptURI = new String( uri );
1054 								SfxGroupInfo_Impl* pGrpInfo = new SfxGroupInfo_Impl( SFX_CFGFUNCTION_SCRIPT, 0, pScriptURI );
1055 
1056                                 Image aImage = GetImage( children[n], Reference< XComponentContext >(), sal_False, BMP_COLOR_NORMAL );
1057 								SvLBoxEntry* pNewEntry =
1058 									pFunctionListBox->InsertEntry( children[n]->getName(), NULL );
1059                                 pFunctionListBox->SetExpandedEntryBmp(pNewEntry, aImage, BMP_COLOR_NORMAL);
1060                                 pFunctionListBox->SetCollapsedEntryBmp(pNewEntry, aImage, BMP_COLOR_NORMAL);
1061                                 aImage = GetImage( children[n], Reference< XComponentContext >(), sal_False, BMP_COLOR_HIGHCONTRAST );
1062                                 pFunctionListBox->SetExpandedEntryBmp(pNewEntry, aImage, BMP_COLOR_HIGHCONTRAST);
1063                                 pFunctionListBox->SetCollapsedEntryBmp(pNewEntry, aImage, BMP_COLOR_HIGHCONTRAST);
1064 
1065                                 pGrpInfo->sCommand = uri;
1066                                 pGrpInfo->sLabel = children[n]->getName();
1067 								pNewEntry->SetUserData( pGrpInfo );
1068 
1069 								pFunctionListBox->aArr.Insert(
1070 									pGrpInfo, pFunctionListBox->aArr.Count() );
1071 
1072 							}
1073 						}
1074 					}
1075 				}
1076                 catch (RuntimeException&) {
1077 					// do nothing, the entry will not be displayed in the UI
1078 				}
1079 			}
1080 			break;
1081 		}
1082 
1083 		case SFX_CFGGROUP_STYLES :
1084 		{
1085             SfxStyleInfo_Impl* pFamily = (SfxStyleInfo_Impl*)(pInfo->pObject);
1086             if (pFamily)
1087             {
1088                 const ::std::vector< SfxStyleInfo_Impl > lStyles = pStylesInfo->getStyles(pFamily->sFamily);
1089                 ::std::vector< SfxStyleInfo_Impl >::const_iterator pIt;
1090                 for (  pIt  = lStyles.begin();
1091                        pIt != lStyles.end()  ;
1092                      ++pIt                   )
1093                 {
1094                     SfxStyleInfo_Impl* pStyle = new SfxStyleInfo_Impl(*pIt);
1095 				    SvLBoxEntry* pFuncEntry = pFunctionListBox->InsertEntry( pStyle->sLabel, NULL );
1096 				    SfxGroupInfo_Impl *pGrpInfo = new SfxGroupInfo_Impl( SFX_CFGGROUP_STYLES, 0, pStyle );
1097 				    pFunctionListBox->aArr.Insert( pGrpInfo, pFunctionListBox->aArr.Count() );
1098                     pGrpInfo->sCommand = pStyle->sCommand;
1099                     pGrpInfo->sLabel = pStyle->sLabel;
1100 				    pFuncEntry->SetUserData( pGrpInfo );
1101                 }
1102             }
1103             break;
1104         }
1105 
1106 		default:
1107 			return;
1108 	}
1109 
1110 	if ( pFunctionListBox->GetEntryCount() )
1111 		pFunctionListBox->Select( pFunctionListBox->GetEntry( 0, 0 ) );
1112 
1113 	pFunctionListBox->SetUpdateMode(sal_True);
1114 }
1115 
1116 sal_Bool SfxConfigGroupListBox_Impl::Expand( SvLBoxEntry* pParent )
1117 {
1118 	sal_Bool bRet = SvTreeListBox::Expand( pParent );
1119 	if ( bRet )
1120 	{
1121 		// Wieviele Entries k"onnen angezeigt werden ?
1122 		sal_uLong nEntries = GetOutputSizePixel().Height() / GetEntryHeight();
1123 
1124 		// Wieviele Kinder sollen angezeigt werden ?
1125 		sal_uLong nChildCount = GetVisibleChildCount( pParent );
1126 
1127 		// Passen alle Kinder und der parent gleichzeitig in die View ?
1128 		if ( nChildCount+1 > nEntries )
1129 		{
1130 			// Wenn nicht, wenigstens parent ganz nach oben schieben
1131 			MakeVisible( pParent, sal_True );
1132 		}
1133 		else
1134 		{
1135 			// An welcher relativen ViewPosition steht der aufzuklappende parent
1136 			SvLBoxEntry *pEntry = GetFirstEntryInView();
1137 			sal_uLong nParentPos = 0;
1138 			while ( pEntry && pEntry != pParent )
1139 			{
1140 				nParentPos++;
1141 				pEntry = GetNextEntryInView( pEntry );
1142 			}
1143 
1144 			// Ist unter dem parent noch genug Platz f"ur alle Kinder ?
1145 			if ( nParentPos + nChildCount + 1 > nEntries )
1146 				ScrollOutputArea( (short)( nEntries - ( nParentPos + nChildCount + 1 ) ) );
1147 		}
1148 	}
1149 
1150 	return bRet;
1151 }
1152 
1153 void SfxConfigGroupListBox_Impl::RequestingChilds( SvLBoxEntry *pEntry )
1154 /*	Beschreibung
1155 	Ein Basic oder eine Bibliothek werden ge"offnet
1156 */
1157 {
1158 	SfxGroupInfo_Impl *pInfo = (SfxGroupInfo_Impl*) pEntry->GetUserData();
1159 	pInfo->bWasOpened = sal_True;
1160 	switch ( pInfo->nKind )
1161 	{
1162 		case SFX_CFGGROUP_SCRIPTCONTAINER:
1163 		{
1164 			if ( !GetChildCount( pEntry ) )
1165 			{
1166 				Reference< browse::XBrowseNode > rootNode(
1167 					reinterpret_cast< browse::XBrowseNode* >( pInfo->pObject ) ) ;
1168 
1169 				try {
1170 					if ( rootNode->hasChildNodes() )
1171 					{
1172 						Sequence< Reference< browse::XBrowseNode > > children =
1173 							rootNode->getChildNodes();
1174 						sal_Bool bIsRootNode = sal_False;
1175 
1176 						::rtl::OUString user = ::rtl::OUString::createFromAscii("user");
1177 						::rtl::OUString share = ::rtl::OUString::createFromAscii("share");
1178 						if ( rootNode->getName().equals(::rtl::OUString::createFromAscii("Root") ))
1179 						{
1180 							bIsRootNode = sal_True;
1181 						}
1182 
1183 						/* To mimic current starbasic behaviour we
1184 						need to make sure that only the current document
1185 						is displayed in the config tree. Tests below
1186 						set the bDisplay flag to sal_False if the current
1187 						node is a first level child of the Root and is NOT
1188 						either the current document, user or share */
1189 						::rtl::OUString currentDocTitle;
1190                         Reference< XModel > xDocument( lcl_getScriptableDocument_nothrow( m_xFrame ) );
1191                         if ( xDocument.is() )
1192                         {
1193                             currentDocTitle = ::comphelper::DocumentInfo::getDocumentTitle( xDocument );
1194 						}
1195 
1196 						sal_Int32 nLen = children.getLength();
1197                         for ( sal_Int32 n = 0; n < nLen; n++ )
1198 						{
1199 							Reference< browse::XBrowseNode >& theChild = children[n];
1200 							::rtl::OUString aName( theChild->getName() );
1201 							sal_Bool bDisplay = sal_True;
1202 							if ( bIsRootNode )
1203 							{
1204 								if ( !( (aName.equals(user) || aName.equals(share) || aName.equals(currentDocTitle) ) ) )
1205 									bDisplay=sal_False;
1206 							}
1207 							if ( children[n].is() && children[n]->getType() != browse::BrowseNodeTypes::SCRIPT && bDisplay )
1208 							{
1209 
1210 								/*
1211 									We call acquire on the XBrowseNode so that it does not
1212 									get autodestructed and become invalid when accessed later.
1213 								*/
1214 								theChild->acquire();
1215 
1216 								SfxGroupInfo_Impl* pGrpInfo =
1217 									new SfxGroupInfo_Impl(SFX_CFGGROUP_SCRIPTCONTAINER,
1218 										0, static_cast<void *>( theChild.get()));
1219 
1220                                 Image aImage = GetImage( theChild, Reference< XComponentContext >(), sal_False, BMP_COLOR_NORMAL );
1221 								SvLBoxEntry* pNewEntry =
1222 									InsertEntry( theChild->getName(), pEntry );
1223                                 SetExpandedEntryBmp(pNewEntry, aImage, BMP_COLOR_NORMAL);
1224                                 SetCollapsedEntryBmp(pNewEntry, aImage, BMP_COLOR_NORMAL);
1225                                 aImage = GetImage( theChild, Reference< XComponentContext >(), sal_False, BMP_COLOR_HIGHCONTRAST );
1226                                 SetExpandedEntryBmp(pNewEntry, aImage, BMP_COLOR_HIGHCONTRAST);
1227                                 SetCollapsedEntryBmp(pNewEntry, aImage, BMP_COLOR_HIGHCONTRAST);
1228 
1229 								pNewEntry->SetUserData( pGrpInfo );
1230 								aArr.Insert( pGrpInfo, aArr.Count() );
1231 
1232 								if ( children[n]->hasChildNodes() )
1233 								{
1234 									Sequence< Reference< browse::XBrowseNode > > grandchildren =
1235 										children[n]->getChildNodes();
1236 
1237                                     for ( sal_Int32 m = 0; m < grandchildren.getLength(); m++ )
1238 									{
1239 										if ( grandchildren[m]->getType() == browse::BrowseNodeTypes::CONTAINER )
1240 										{
1241 											pNewEntry->EnableChildsOnDemand( sal_True );
1242 											m = grandchildren.getLength();
1243 										}
1244 									}
1245 								}
1246 							}
1247 						}
1248 					}
1249 				}
1250                 catch (RuntimeException&) {
1251 					// do nothing, the entry will not be displayed in the UI
1252 				}
1253 			}
1254 			break;
1255 		}
1256 
1257 		case SFX_CFGGROUP_STYLES:
1258 		{
1259 			if ( !GetChildCount( pEntry ) )
1260 			{
1261                 const ::std::vector< SfxStyleInfo_Impl >                 lStyleFamilies = pStylesInfo->getStyleFamilies();
1262                       ::std::vector< SfxStyleInfo_Impl >::const_iterator pIt;
1263 				for (  pIt  = lStyleFamilies.begin();
1264 				       pIt != lStyleFamilies.end()  ;
1265                      ++pIt                          )
1266 				{
1267                     SfxStyleInfo_Impl* pFamily = new SfxStyleInfo_Impl(*pIt);
1268                     SvLBoxEntry* pStyleEntry = InsertEntry( pFamily->sLabel, pEntry );
1269 					SfxGroupInfo_Impl *pGrpInfo = new SfxGroupInfo_Impl( SFX_CFGGROUP_STYLES, 0, pFamily );
1270 					aArr.Insert( pGrpInfo, aArr.Count() );
1271 					pStyleEntry->SetUserData( pGrpInfo );
1272 					pStyleEntry->EnableChildsOnDemand( sal_False );
1273 				}
1274 			}
1275             break;
1276         }
1277 
1278 		default:
1279 			DBG_ERROR( "Falscher Gruppentyp!" );
1280 			break;
1281 	}
1282 }
1283 
1284 void SfxConfigGroupListBox_Impl::SelectMacro( const SfxMacroInfoItem *pItem )
1285 {
1286 	SelectMacro( pItem->GetBasicManager()->GetName(),
1287 				 pItem->GetQualifiedName() );
1288 }
1289 
1290 void SfxConfigGroupListBox_Impl::SelectMacro( const String& rBasic,
1291 		 const String& rMacro )
1292 {
1293 	String aBasicName( rBasic );
1294 	aBasicName += ' ';
1295 	aBasicName += pImp->m_sMacros;
1296 	String aLib, aModule, aMethod;
1297 	sal_uInt16 nCount = rMacro.GetTokenCount('.');
1298 	aMethod = rMacro.GetToken( nCount-1, '.' );
1299 	if ( nCount > 2 )
1300 	{
1301 		aLib = rMacro.GetToken( 0, '.' );
1302 		aModule = rMacro.GetToken( nCount-2, '.' );
1303 	}
1304 
1305 	SvLBoxEntry *pEntry = FirstChild(0);
1306 	while ( pEntry )
1307 	{
1308 		String aEntryBas = GetEntryText( pEntry );
1309 		if ( aEntryBas == aBasicName )
1310 		{
1311 			Expand( pEntry );
1312 			SvLBoxEntry *pLib = FirstChild( pEntry );
1313 			while ( pLib )
1314 			{
1315 				String aEntryLib = GetEntryText( pLib );
1316 				if ( aEntryLib == aLib )
1317 				{
1318 					Expand( pLib );
1319 					SvLBoxEntry *pMod = FirstChild( pLib );
1320 					while ( pMod )
1321 					{
1322 						String aEntryMod = GetEntryText( pMod );
1323 						if ( aEntryMod == aModule )
1324 						{
1325 							Expand( pMod );
1326 							MakeVisible( pMod );
1327 							Select( pMod );
1328 							SvLBoxEntry *pMethod = pFunctionListBox->First();
1329 							while ( pMethod )
1330 							{
1331 								String aEntryMethod = GetEntryText( pMethod );
1332 								if ( aEntryMethod == aMethod )
1333 								{
1334 									pFunctionListBox->Select( pMethod );
1335 									pFunctionListBox->MakeVisible( pMethod );
1336 									return;
1337 								}
1338 								pMethod = pFunctionListBox->Next( pMethod );
1339 							}
1340 						}
1341 						pMod = NextSibling( pMod );
1342 					}
1343 				}
1344 				pLib = NextSibling( pLib );
1345 			}
1346 		}
1347 		pEntry = NextSibling( pEntry );
1348 	}
1349 }
1350