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