update dev300-m58
[ooovba.git] / svx / source / cui / cfgutil.cxx
blob9df95d970d82a907181757b48739e3fdb9c0647e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cfg.cxx,v $
10 * $Revision: 1.65 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include "cfgutil.hxx"
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/frame/XDispatchInformationProvider.hpp>
38 #include <com/sun/star/uno/RuntimeException.hpp>
39 #include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
40 #include <com/sun/star/script/provider/XScriptProvider.hpp>
41 #include <com/sun/star/script/browse/XBrowseNode.hpp>
42 #include <com/sun/star/script/browse/BrowseNodeTypes.hpp>
44 #include <com/sun/star/script/browse/XBrowseNodeFactory.hpp>
45 #include <com/sun/star/script/browse/BrowseNodeFactoryViewTypes.hpp>
46 #include <com/sun/star/frame/XModuleManager.hpp>
47 #include <com/sun/star/frame/XDesktop.hpp>
48 #include <com/sun/star/container/XEnumerationAccess.hpp>
49 #include <com/sun/star/container/XEnumeration.hpp>
50 #include <com/sun/star/document/XDocumentInfoSupplier.hpp>
51 #include <com/sun/star/document/XScriptInvocationContext.hpp>
52 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
54 #include "acccfg.hrc"
55 #include "helpid.hrc"
56 #include <basic/sbx.hxx>
57 #include <basic/basicmanagerrepository.hxx>
58 #include <basic/sbstar.hxx>
59 #include <basic/sbxmeth.hxx>
60 #include <basic/sbmod.hxx>
61 #include <basic/basmgr.hxx>
62 #include <tools/urlobj.hxx>
63 #include "svx/dialogs.hrc"
64 #include <sfx2/app.hxx>
65 #include <sfx2/macrconf.hxx>
66 #include <sfx2/minfitem.hxx>
67 #include <unotools/processfactory.hxx>
68 #include <comphelper/documentinfo.hxx>
69 #include <svtools/imagemgr.hxx>
70 #include <rtl/ustrbuf.hxx>
71 #include <comphelper/sequenceashashmap.hxx>
72 #include <unotools/configmgr.hxx>
73 #include "svx/dialmgr.hxx"
74 #include <svtools/stritem.hxx>
76 #define _SVSTDARR_STRINGSDTOR
77 #include <svtools/svstdarr.hxx>
79 using namespace ::com::sun::star;
80 using namespace ::com::sun::star::uno;
81 using namespace ::com::sun::star::script;
82 using namespace ::com::sun::star::frame;
83 using namespace ::com::sun::star::document;
84 namespace css = ::com::sun::star;
86 static ::rtl::OUString SERVICE_UICATEGORYDESCRIPTION = ::rtl::OUString::createFromAscii("com.sun.star.ui.UICategoryDescription" );
87 static ::rtl::OUString SERVICE_UICMDDESCRIPTION = ::rtl::OUString::createFromAscii("com.sun.star.frame.UICommandDescription");
89 SfxStylesInfo_Impl::SfxStylesInfo_Impl()
92 void SfxStylesInfo_Impl::setModel(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xModel)
94 m_xDoc = xModel;
97 static ::rtl::OUString FAMILY_CHARACTERSTYLE = ::rtl::OUString::createFromAscii("CharacterStyles");
98 static ::rtl::OUString FAMILY_PARAGRAPHSTYLE = ::rtl::OUString::createFromAscii("ParagraphStyles");
99 static ::rtl::OUString FAMILY_FRAMESTYLE = ::rtl::OUString::createFromAscii("FrameStyles" );
100 static ::rtl::OUString FAMILY_PAGESTYLE = ::rtl::OUString::createFromAscii("PageStyles" );
101 static ::rtl::OUString FAMILY_NUMBERINGSTYLE = ::rtl::OUString::createFromAscii("NumberingStyles");
103 static ::rtl::OUString CMDURL_SPART = ::rtl::OUString::createFromAscii(".uno:StyleApply?Style:string=");
104 static ::rtl::OUString CMDURL_FPART2 = ::rtl::OUString::createFromAscii("&FamilyName:string=");
106 static ::rtl::OUString CMDURL_STYLEPROT_ONLY = ::rtl::OUString::createFromAscii(".uno:StyleApply?");
107 static ::rtl::OUString CMDURL_SPART_ONLY = ::rtl::OUString::createFromAscii("Style:string=");
108 static ::rtl::OUString CMDURL_FPART_ONLY = ::rtl::OUString::createFromAscii("FamilyName:string=");
110 static ::rtl::OUString STYLEPROP_UINAME = ::rtl::OUString::createFromAscii("DisplayName");
112 ::rtl::OUString SfxStylesInfo_Impl::generateCommand(const ::rtl::OUString& sFamily, const ::rtl::OUString& sStyle)
114 ::rtl::OUStringBuffer sCommand(1024);
115 sCommand.append(CMDURL_SPART );
116 sCommand.append(sStyle );
117 sCommand.append(CMDURL_FPART2);
118 sCommand.append(sFamily );
119 return sCommand.makeStringAndClear();
122 sal_Bool SfxStylesInfo_Impl::parseStyleCommand(SfxStyleInfo_Impl& aStyle)
124 static sal_Int32 LEN_STYLEPROT = CMDURL_STYLEPROT_ONLY.getLength();
125 static sal_Int32 LEN_SPART = CMDURL_SPART_ONLY.getLength();
126 static sal_Int32 LEN_FPART = CMDURL_FPART_ONLY.getLength();
128 if (aStyle.sCommand.indexOf(CMDURL_STYLEPROT_ONLY, 0) != 0)
129 return sal_False;
131 aStyle.sFamily = ::rtl::OUString();
132 aStyle.sStyle = ::rtl::OUString();
134 sal_Int32 nCmdLen = aStyle.sCommand.getLength();
135 ::rtl::OUString sCmdArgs = aStyle.sCommand.copy(LEN_STYLEPROT, nCmdLen-LEN_STYLEPROT);
136 sal_Int32 i = sCmdArgs.indexOf('&');
137 if (i<0)
138 return sal_False;
140 ::rtl::OUString sArg = sCmdArgs.copy(0, i);
141 if (sArg.indexOf(CMDURL_SPART_ONLY) == 0)
142 aStyle.sStyle = sArg.copy(LEN_SPART, sArg.getLength()-LEN_SPART);
143 else
144 if (sArg.indexOf(CMDURL_FPART_ONLY) == 0)
145 aStyle.sFamily = sArg.copy(LEN_FPART, sArg.getLength()-LEN_FPART);
147 sArg = sCmdArgs.copy(i+1, sCmdArgs.getLength()-i-1);
148 if (sArg.indexOf(CMDURL_SPART_ONLY) == 0)
149 aStyle.sStyle = sArg.copy(LEN_SPART, sArg.getLength()-LEN_SPART);
150 else
151 if (sArg.indexOf(CMDURL_FPART_ONLY) == 0)
152 aStyle.sFamily = sArg.copy(LEN_FPART, sArg.getLength()-LEN_FPART);
154 if (aStyle.sFamily.getLength() && aStyle.sStyle.getLength())
155 return sal_True;
157 return sal_False;
160 void SfxStylesInfo_Impl::getLabel4Style(SfxStyleInfo_Impl& aStyle)
164 css::uno::Reference< css::style::XStyleFamiliesSupplier > xModel(m_xDoc, css::uno::UNO_QUERY);
166 css::uno::Reference< css::container::XNameAccess > xFamilies;
167 if (xModel.is())
168 xFamilies = xModel->getStyleFamilies();
170 css::uno::Reference< css::container::XNameAccess > xStyleSet;
171 if (xFamilies.is())
172 xFamilies->getByName(aStyle.sFamily) >>= xStyleSet;
174 css::uno::Reference< css::beans::XPropertySet > xStyle;
175 if (xStyleSet.is())
176 xStyleSet->getByName(aStyle.sStyle) >>= xStyle;
178 aStyle.sLabel = ::rtl::OUString();
179 if (xStyle.is())
180 xStyle->getPropertyValue(STYLEPROP_UINAME) >>= aStyle.sLabel;
182 catch(const css::uno::RuntimeException& exRun)
183 { throw exRun; }
184 catch(const css::uno::Exception&)
185 { aStyle.sLabel = ::rtl::OUString(); }
187 if (!aStyle.sLabel.getLength())
189 aStyle.sLabel = aStyle.sCommand;
191 #if OSL_DEBUG_LEVEL > 1
192 ::rtl::OUStringBuffer sMsg(256);
193 sMsg.appendAscii("There is no UIName for the style command \"");
194 sMsg.append (aStyle.sCommand );
195 sMsg.appendAscii("\". The UI will be invalid then ..." );
196 OSL_ENSURE(sal_False, ::rtl::OUStringToOString(sMsg.makeStringAndClear(), RTL_TEXTENCODING_UTF8).getStr());
197 #endif
202 ::std::vector< SfxStyleInfo_Impl > SfxStylesInfo_Impl::getStyleFamilies()
204 // Its an optional interface!
205 css::uno::Reference< css::style::XStyleFamiliesSupplier > xModel(m_xDoc, css::uno::UNO_QUERY);
206 if (!xModel.is())
207 return ::std::vector< SfxStyleInfo_Impl >();
209 css::uno::Reference< css::container::XNameAccess > xCont = xModel->getStyleFamilies();
210 css::uno::Sequence< ::rtl::OUString > lFamilyNames = xCont->getElementNames();
211 ::std::vector< SfxStyleInfo_Impl > lFamilies;
212 sal_Int32 c = lFamilyNames.getLength();
213 sal_Int32 i = 0;
214 for(i=0; i<c; ++i)
216 SfxStyleInfo_Impl aFamilyInfo;
217 aFamilyInfo.sFamily = lFamilyNames[i];
221 css::uno::Reference< css::beans::XPropertySet > xFamilyInfo;
222 xCont->getByName(aFamilyInfo.sFamily) >>= xFamilyInfo;
223 if (!xFamilyInfo.is())
225 // TODO_AS currently there is no support for an UIName property .. use internal family name instead
226 aFamilyInfo.sLabel = aFamilyInfo.sFamily;
228 else
229 xFamilyInfo->getPropertyValue(STYLEPROP_UINAME) >>= aFamilyInfo.sLabel;
231 catch(const css::uno::RuntimeException& exRun)
232 { throw exRun; }
233 catch(const css::uno::Exception&)
234 { return ::std::vector< SfxStyleInfo_Impl >(); }
236 lFamilies.push_back(aFamilyInfo);
239 return lFamilies;
242 ::std::vector< SfxStyleInfo_Impl > SfxStylesInfo_Impl::getStyles(const ::rtl::OUString& sFamily)
244 static ::rtl::OUString PROP_UINAME = ::rtl::OUString::createFromAscii("DisplayName");
246 css::uno::Sequence< ::rtl::OUString > lStyleNames;
247 css::uno::Reference< css::style::XStyleFamiliesSupplier > xModel(m_xDoc, css::uno::UNO_QUERY_THROW);
248 css::uno::Reference< css::container::XNameAccess > xFamilies = xModel->getStyleFamilies();
249 css::uno::Reference< css::container::XNameAccess > xStyleSet;
252 xFamilies->getByName(sFamily) >>= xStyleSet;
253 lStyleNames = xStyleSet->getElementNames();
255 catch(const css::uno::RuntimeException& exRun)
256 { throw exRun; }
257 catch(const css::uno::Exception&)
258 { return ::std::vector< SfxStyleInfo_Impl >(); }
260 ::std::vector< SfxStyleInfo_Impl > lStyles;
261 sal_Int32 c = lStyleNames.getLength();
262 sal_Int32 i = 0;
263 for (i=0; i<c; ++i)
265 SfxStyleInfo_Impl aStyleInfo;
266 aStyleInfo.sFamily = sFamily;
267 aStyleInfo.sStyle = lStyleNames[i];
268 aStyleInfo.sCommand = SfxStylesInfo_Impl::generateCommand(aStyleInfo.sFamily, aStyleInfo.sStyle);
272 css::uno::Reference< css::beans::XPropertySet > xStyle;
273 xStyleSet->getByName(aStyleInfo.sStyle) >>= xStyle;
274 if (!xStyle.is())
275 continue;
276 xStyle->getPropertyValue(PROP_UINAME) >>= aStyleInfo.sLabel;
278 catch(const css::uno::RuntimeException& exRun)
279 { throw exRun; }
280 catch(const css::uno::Exception&)
281 { continue; }
283 lStyles.push_back(aStyleInfo);
285 return lStyles;
287 SV_IMPL_PTRARR(SfxGroupInfoArr_Impl, SfxGroupInfoPtr);
288 SfxConfigFunctionListBox_Impl::SfxConfigFunctionListBox_Impl( Window* pParent, const ResId& rResId)
289 : SvTreeListBox( pParent, rResId )
290 , pCurEntry( 0 )
291 , pStylesInfo( 0 )
293 SetWindowBits( GetStyle() | WB_CLIPCHILDREN | WB_HSCROLL | WB_SORT );
294 GetModel()->SetSortMode( SortAscending );
296 // Timer f"ur die BallonHelp
297 aTimer.SetTimeout( 200 );
298 aTimer.SetTimeoutHdl(
299 LINK( this, SfxConfigFunctionListBox_Impl, TimerHdl ) );
302 SfxConfigFunctionListBox_Impl::~SfxConfigFunctionListBox_Impl()
304 ClearAll();
307 void SfxConfigFunctionListBox_Impl::MouseMove( const MouseEvent& )
309 /* --> PB 2004-12-01 #i37000# - no own help text needed any longer
310 Point aMousePos = rMEvt.GetPosPixel();
311 pCurEntry = GetCurEntry();
313 if ( pCurEntry && GetEntry( aMousePos ) == pCurEntry )
314 aTimer.Start();
315 else
317 Help::ShowBalloon( this, aMousePos, String() );
318 aTimer.Stop();
324 IMPL_LINK( SfxConfigFunctionListBox_Impl, TimerHdl, Timer*, pTimer)
325 /* Beschreibung
326 Timer-Handler f"ur die Einblendung eines Hilfetextes. Wenn nach Ablauf des Timers
327 der Mauszeiger immer noch auf dem aktuell selektierten Eintrag steht, wird der
328 Helptext des Entries als Balloon-Help eingeblendet.
331 (void)pTimer; // unused
332 /* --> PB 2004-12-01 #i37000# - no own help text needed any longer
333 aTimer.Stop();
334 Point aMousePos = GetPointerPosPixel();
335 SvLBoxEntry *pEntry = GetCurEntry();
336 if ( pEntry && GetEntry( aMousePos ) == pEntry && pCurEntry == pEntry )
338 String sHelpText = GetHelpText( pEntry );
339 Help::ShowBalloon( this, OutputToScreenPixel( aMousePos ), sHelpText );
342 return 0L;
345 void SfxConfigFunctionListBox_Impl::ClearAll()
346 /* Beschreibung
347 L"oscht alle Eintr"age in der FunctionListBox, alle UserDaten und alle evtl.
348 vorhandenen MacroInfos.
351 USHORT nCount = aArr.Count();
352 for ( USHORT i=0; i<nCount; i++ )
354 SfxGroupInfo_Impl *pData = aArr[i];
356 if ( pData->nKind == SFX_CFGFUNCTION_MACRO ||
357 pData->nKind == SFX_CFGFUNCTION_SCRIPT )
359 SfxMacroInfo *pInfo = (SfxMacroInfo*) pData->pObject;
360 SFX_APP()->GetMacroConfig()->ReleaseSlotId( pInfo->GetSlotId() );
361 delete pInfo;
364 if ( pData->nKind == SFX_CFGGROUP_SCRIPTCONTAINER
365 || pData->nKind == SFX_CFGGROUP_DOCBASICMGR
368 XInterface* xi = static_cast<XInterface *>(pData->pObject);
369 if (xi != NULL)
371 xi->release();
375 delete pData;
378 aArr.Remove( 0, nCount );
379 Clear();
382 SvLBoxEntry* SfxConfigFunctionListBox_Impl::GetEntry_Impl( const String& rName )
383 /* Beschreibung
384 Ermittelt den SvLBoxEntry zu einem "ubergebenen String. Das setzt voraus, da\s
385 die Namen eindeutig sind.
388 SvLBoxEntry *pEntry = First();
389 while ( pEntry )
391 if ( GetEntryText( pEntry ) == rName )
392 return pEntry;
393 pEntry = Next( pEntry );
396 return NULL;
399 SvLBoxEntry* SfxConfigFunctionListBox_Impl::GetEntry_Impl( USHORT nId )
400 /* Beschreibung
401 Ermittelt den SvLBoxEntry zu einer "ubergebenen Id.
404 SvLBoxEntry *pEntry = First();
405 while ( pEntry )
407 SfxGroupInfo_Impl *pData = (SfxGroupInfo_Impl*) pEntry->GetUserData();
408 if ( pData && pData->nOrd == nId )
409 return pEntry;
410 pEntry = Next( pEntry );
413 return NULL;
416 SfxMacroInfo* SfxConfigFunctionListBox_Impl::GetMacroInfo()
417 /* Beschreibung
418 Gibt die MacroInfo des selektierten Entry zur"uck ( sofern vorhanden ).
421 SvLBoxEntry *pEntry = FirstSelected();
422 if ( pEntry )
424 SfxGroupInfo_Impl *pData = (SfxGroupInfo_Impl*) pEntry->GetUserData();
425 if ( pData && ( pData->nKind == SFX_CFGFUNCTION_MACRO ||
426 pData->nKind == SFX_CFGFUNCTION_SCRIPT ) )
427 return (SfxMacroInfo*) pData->pObject;
430 return 0;
433 String SfxConfigFunctionListBox_Impl::GetCurCommand()
435 SvLBoxEntry *pEntry = FirstSelected();
436 if (!pEntry)
437 return String();
438 SfxGroupInfo_Impl *pData = (SfxGroupInfo_Impl*) pEntry->GetUserData();
439 if (!pData)
440 return String();
441 return pData->sCommand;
444 String SfxConfigFunctionListBox_Impl::GetCurLabel()
446 SvLBoxEntry *pEntry = FirstSelected();
447 if (!pEntry)
448 return String();
449 SfxGroupInfo_Impl *pData = (SfxGroupInfo_Impl*) pEntry->GetUserData();
450 if (!pData)
451 return String();
452 if (pData->sLabel.Len())
453 return pData->sLabel;
454 return pData->sCommand;
457 USHORT SfxConfigFunctionListBox_Impl::GetId( SvLBoxEntry *pEntry )
458 /* Beschreibung
459 Gibt die Ordnungsnummer ( SlotId oder Macro-Nummer ) des Eintrags zur"uck.
462 SfxGroupInfo_Impl *pData = pEntry ?
463 (SfxGroupInfo_Impl*) pEntry->GetUserData() : 0;
464 if ( pData )
465 return pData->nOrd;
466 return 0;
470 String SfxConfigFunctionListBox_Impl::GetHelpText( SvLBoxEntry *pEntry )
472 // Information zum selektierten Entry aus den Userdaten holen
473 SfxGroupInfo_Impl *pInfo = pEntry ? (SfxGroupInfo_Impl*) pEntry->GetUserData(): 0;
474 if ( pInfo )
476 switch ( pInfo->nKind )
478 case SFX_CFGGROUP_FUNCTION :
479 case SFX_CFGFUNCTION_SLOT :
481 // Eintrag ist eine Funktion, Hilfe aus der Office-Hilfe
482 USHORT nId = pInfo->nOrd;
483 String aText = Application::GetHelp()->GetHelpText( nId, this );
485 if ( !aText.Len() )
486 aText = SFX_SLOTPOOL().GetSlotHelpText_Impl( nId );
487 return aText;
490 case SFX_CFGGROUP_SCRIPTCONTAINER :
491 case SFX_CFGFUNCTION_SCRIPT :
492 case SFX_CFGGROUP_BASICMGR :
493 case SFX_CFGGROUP_DOCBASICMGR :
494 case SFX_CFGGROUP_BASICLIB :
495 case SFX_CFGGROUP_BASICMOD :
496 case SFX_CFGFUNCTION_MACRO :
498 // Eintrag ist ein Macro, Hilfe aus der MacroInfo
499 SfxMacroInfo *pMacInfo = (SfxMacroInfo*) pInfo->pObject;
500 return pMacInfo->GetHelpText();
503 case SFX_CFGGROUP_STYLES :
504 return String();
508 return String();
511 void SfxConfigFunctionListBox_Impl::FunctionSelected()
512 /* Beschreibung
513 Setzt die Balloonhelp zur"uck, da diese immer den Helptext des selektierten
514 Entry anzeigen soll.
517 /* --> PB 2004-12-01 #i37000# - no own help text needed any longer
518 Help::ShowBalloon( this, Point(), String() );
522 void SfxConfigFunctionListBox_Impl::SetStylesInfo(SfxStylesInfo_Impl* pStyles)
524 pStylesInfo = pStyles;
527 struct SvxConfigGroupBoxResource_Impl : public Resource
529 Image m_hdImage;
530 Image m_hdImage_hc;
531 Image m_libImage;
532 Image m_libImage_hc;
533 Image m_macImage;
534 Image m_macImage_hc;
535 Image m_docImage;
536 Image m_docImage_hc;
537 ::rtl::OUString m_sMyMacros;
538 ::rtl::OUString m_sProdMacros;
539 String m_sMacros;
540 String m_sDlgMacros;
541 String m_aHumanAppName;
542 String m_aStrGroupStyles;
543 String m_aScriptType;
544 Image m_collapsedImage;
545 Image m_collapsedImage_hc;
546 Image m_expandedImage;
547 Image m_expandedImage_hc;
549 SvxConfigGroupBoxResource_Impl();
552 SvxConfigGroupBoxResource_Impl::SvxConfigGroupBoxResource_Impl() :
553 Resource(SVX_RES(RID_SVXPAGE_CONFIGGROUPBOX)),
554 m_hdImage(SVX_RES(IMG_HARDDISK)),
555 m_hdImage_hc(SVX_RES(IMG_HARDDISK_HC)),
556 m_libImage(SVX_RES(IMG_LIB)),
557 m_libImage_hc(SVX_RES(IMG_LIB_HC)),
558 m_macImage(SVX_RES(IMG_MACRO)),
559 m_macImage_hc(SVX_RES(IMG_MACRO_HC)),
560 m_docImage(SVX_RES(IMG_DOC)),
561 m_docImage_hc(SVX_RES(IMG_DOC_HC)),
562 m_sMyMacros(String(SVX_RES(STR_MYMACROS))),
563 m_sProdMacros(String(SVX_RES(STR_PRODMACROS))),
564 m_sMacros(String(SVX_RES(STR_BASICMACROS))),
565 m_sDlgMacros(String(SVX_RES(STR_DLG_MACROS))),
566 m_aHumanAppName(String(SVX_RES(STR_HUMAN_APPNAME))),
567 m_aStrGroupStyles(String(SVX_RES(STR_GROUP_STYLES))),
568 m_aScriptType(String(SVX_RES(STR_BASICNAME))),
569 m_collapsedImage(SVX_RES(BMP_COLLAPSED)),
570 m_collapsedImage_hc(SVX_RES(BMP_COLLAPSED_HC)),
571 m_expandedImage(SVX_RES(BMP_EXPANDED)),
572 m_expandedImage_hc(SVX_RES(BMP_EXPANDED_HC))
574 FreeResource();
577 SfxConfigGroupListBox_Impl::SfxConfigGroupListBox_Impl(
578 Window* pParent, const ResId& rResId, ULONG nConfigMode )
579 : SvTreeListBox( pParent, rResId )
580 , pImp(new SvxConfigGroupBoxResource_Impl()), pFunctionListBox(0), nMode( nConfigMode ), bShowSF( FALSE ), bShowBasic( TRUE ), pStylesInfo(0)
582 SetWindowBits( GetStyle() | WB_CLIPCHILDREN | WB_HSCROLL | WB_HASBUTTONS | WB_HASLINES | WB_HASLINESATROOT | WB_HASBUTTONSATROOT );
583 SetNodeBitmaps( pImp->m_collapsedImage, pImp->m_expandedImage, BMP_COLOR_NORMAL );
584 SetNodeBitmaps( pImp->m_collapsedImage_hc, pImp->m_expandedImage_hc, BMP_COLOR_HIGHCONTRAST );
586 // Check configuration to see whether only Basic macros,
587 // only Scripting Framework scripts, or both should be listed
588 Any value;
589 sal_Bool tmp = false;
591 value = ::utl::ConfigManager::GetConfigManager()->GetLocalProperty(
592 ::rtl::OUString::createFromAscii(
593 "Office.Scripting/ScriptDisplaySettings/ShowBasic" ) );
595 value >>= tmp;
597 if (tmp == sal_True) {
598 bShowBasic = TRUE;
600 else {
601 bShowBasic = FALSE;
604 value = ::utl::ConfigManager::GetConfigManager()->GetLocalProperty(
605 ::rtl::OUString::createFromAscii(
606 "Office.Scripting/ScriptDisplaySettings/ShowSF" ) );
608 value >>= tmp;
610 if (tmp == sal_True) {
611 bShowSF = TRUE;
613 else {
614 bShowSF = FALSE;
619 SfxConfigGroupListBox_Impl::~SfxConfigGroupListBox_Impl()
621 ClearAll();
624 void SfxConfigGroupListBox_Impl::ClearAll()
626 USHORT nCount = aArr.Count();
627 for ( USHORT i=0; i<nCount; i++ )
629 SfxGroupInfo_Impl *pData = aArr[i];
630 if ( pData->nKind == SFX_CFGGROUP_SCRIPTCONTAINER
631 || pData->nKind == SFX_CFGGROUP_DOCBASICMGR
634 XInterface* xi = static_cast<XInterface *>(pData->pObject);
635 if (xi != NULL)
637 xi->release();
640 delete pData;
643 aArr.Remove( 0, nCount );
644 Clear();
647 void SfxConfigGroupListBox_Impl::SetScriptType( const String& rScriptType )
649 pImp->m_aScriptType = rScriptType;
650 ULONG nPos=0;
651 SvLBoxEntry *pEntry = (SvLBoxEntry*) GetModel()->GetEntryAtAbsPos( nPos++ );
652 while ( pEntry )
654 SfxGroupInfo_Impl *pInfo = (SfxGroupInfo_Impl*) pEntry->GetUserData();
655 if ( pInfo->nKind == SFX_CFGGROUP_BASICLIB && ( IsExpanded( pEntry ) || pInfo->bWasOpened ) )
657 Collapse( pEntry );
658 SvLBoxEntry *pChild = FirstChild( pEntry );
659 while (pChild)
661 GetModel()->Remove( pChild );
662 pChild = FirstChild( pEntry );
665 Expand( pEntry );
668 pEntry = (SvLBoxEntry*) GetModel()->GetEntryAtAbsPos( nPos++ );
672 void SfxConfigGroupListBox_Impl::SetStylesInfo(SfxStylesInfo_Impl* pStyles)
674 pStylesInfo = pStyles;
677 String SfxConfigGroupListBox_Impl::GetGroup()
678 /* Beschreibung
679 Gibt den Namen der selektierten Funktionsgruppe bzw. des selektierten
680 Basics zur"uck.
683 SvLBoxEntry *pEntry = FirstSelected();
684 while ( pEntry )
686 SfxGroupInfo_Impl *pInfo = (SfxGroupInfo_Impl*) pEntry->GetUserData();
687 if ( pInfo->nKind == SFX_CFGGROUP_FUNCTION )
688 return GetEntryText( pEntry );
690 if ( pInfo->nKind == SFX_CFGGROUP_BASICMGR )
692 BasicManager *pMgr = (BasicManager*) pInfo->pObject;
693 return pMgr->GetName();
696 if ( pInfo->nKind == SFX_CFGGROUP_DOCBASICMGR )
698 Reference< XModel > xDoc( static_cast< XModel* >( pInfo->pObject ) );
699 return ::comphelper::DocumentInfo::getDocumentTitle( xDoc );
702 pEntry = GetParent( pEntry );
705 return String();
708 //-----------------------------------------------
709 BasicManager* SfxConfigGroupListBox_Impl::GetBasicManager( const SvLBoxEntry& _rEntry )
711 BasicManager* pBasMgr = NULL;
713 SfxGroupInfo_Impl* pInfo = (SfxGroupInfo_Impl*) _rEntry.GetUserData();
714 switch ( pInfo->nKind )
716 case SFX_CFGGROUP_BASICMGR :
717 pBasMgr = (BasicManager*) pInfo->pObject;
718 break;
719 case SFX_CFGGROUP_DOCBASICMGR :
721 Reference< XModel > xDoc( static_cast< XModel* >( pInfo->pObject ) );
722 pBasMgr = ::basic::BasicManagerRepository::getDocumentBasicManager( xDoc );
724 break;
726 return pBasMgr;
729 //-----------------------------------------------
730 void SfxConfigGroupListBox_Impl::InitModule()
734 css::uno::Reference< css::frame::XDispatchInformationProvider > xProvider(m_xFrame, css::uno::UNO_QUERY_THROW);
735 css::uno::Sequence< sal_Int16 > lGroups = xProvider->getSupportedCommandGroups();
736 sal_Int32 c1 = lGroups.getLength();
737 sal_Int32 i1 = 0;
739 for (i1=0; i1<c1; ++i1)
741 sal_Int16& rGroupID = lGroups[i1];
742 ::rtl::OUString sGroupID = ::rtl::OUString::valueOf((sal_Int32)rGroupID);
743 ::rtl::OUString sGroupName ;
747 m_xModuleCategoryInfo->getByName(sGroupID) >>= sGroupName;
748 if (!sGroupName.getLength())
749 continue;
751 catch(const css::container::NoSuchElementException&)
752 { continue; }
754 SvLBoxEntry* pEntry = InsertEntry(sGroupName, NULL);
755 SfxGroupInfo_Impl* pInfo = new SfxGroupInfo_Impl(SFX_CFGGROUP_FUNCTION, rGroupID);
756 pEntry->SetUserData(pInfo);
759 catch(const css::uno::RuntimeException& exRun)
760 { throw exRun; }
761 catch(const css::uno::Exception&)
765 //-----------------------------------------------
766 void SfxConfigGroupListBox_Impl::InitBasic()
770 //-----------------------------------------------
771 void SfxConfigGroupListBox_Impl::InitStyles()
775 //-----------------------------------------------
776 namespace
778 //...........................................
779 /** examines a component whether it supports XEmbeddedScripts, or provides access to such a
780 component by implementing XScriptInvocationContext.
781 @return
782 the model which supports the embedded scripts, or <NULL/> if it cannot find such a
783 model
785 static Reference< XModel > lcl_getDocumentWithScripts_throw( const Reference< XInterface >& _rxComponent )
787 Reference< XEmbeddedScripts > xScripts( _rxComponent, UNO_QUERY );
788 if ( !xScripts.is() )
790 Reference< XScriptInvocationContext > xContext( _rxComponent, UNO_QUERY );
791 if ( xContext.is() )
792 xScripts.set( xContext->getScriptContainer(), UNO_QUERY );
795 return Reference< XModel >( xScripts, UNO_QUERY );
798 //...........................................
799 static Reference< XModel > lcl_getScriptableDocument_nothrow( const Reference< XFrame >& _rxFrame )
801 Reference< XModel > xDocument;
803 // examine our associated frame
806 OSL_ENSURE( _rxFrame.is(), "lcl_getScriptableDocument_nothrow: you need to pass a frame to this dialog/tab page!" );
807 if ( _rxFrame.is() )
809 // first try the model in the frame
810 Reference< XController > xController( _rxFrame->getController(), UNO_SET_THROW );
811 xDocument = lcl_getDocumentWithScripts_throw( xController->getModel() );
813 if ( !xDocument.is() )
815 // if there is no suitable document in the frame, try the controller
816 xDocument = lcl_getDocumentWithScripts_throw( _rxFrame->getController() );
820 catch( const Exception& )
822 //DBG_UNHANDLED_EXCEPTION();
825 return xDocument;
829 //-----------------------------------------------
830 void SfxConfigGroupListBox_Impl::Init(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR ,
831 const css::uno::Reference< css::frame::XFrame >& xFrame ,
832 const ::rtl::OUString& sModuleLongName)
834 SetUpdateMode(FALSE);
835 ClearAll(); // Remove all old entries from treelist box
837 m_xFrame = xFrame;
838 if ( xSMGR.is())
840 m_xSMGR = xSMGR;
841 m_sModuleLongName = sModuleLongName;
843 m_xGlobalCategoryInfo = css::uno::Reference< css::container::XNameAccess >(m_xSMGR->createInstance(SERVICE_UICATEGORYDESCRIPTION), css::uno::UNO_QUERY_THROW);
844 m_xModuleCategoryInfo = css::uno::Reference< css::container::XNameAccess >(m_xGlobalCategoryInfo->getByName(m_sModuleLongName) , css::uno::UNO_QUERY_THROW);
845 m_xUICmdDescription = css::uno::Reference< css::container::XNameAccess >(m_xSMGR->createInstance(SERVICE_UICMDDESCRIPTION) , css::uno::UNO_QUERY_THROW);
847 InitModule();
848 InitBasic();
849 InitStyles();
854 // Verwendet wird der aktuelle Slotpool
855 if ( nMode )
857 pSlotPool = pPool ? pPool : &SFX_SLOTPOOL();
858 for ( USHORT i=1; i<pSlotPool->GetGroupCount(); i++ )
860 // Gruppe anw"ahlen ( Gruppe 0 ist intern )
861 String aName = pSlotPool->SeekGroup( i );
862 const SfxSlot *pSfxSlot = pSlotPool->FirstSlot();
863 if ( pSfxSlot )
865 // Check if all entries are not useable. Don't
866 // insert a group without any useable function.
867 sal_Bool bActiveEntries = sal_False;
868 while ( pSfxSlot )
870 USHORT nId = pSfxSlot->GetSlotId();
871 if ( pSfxSlot->GetMode() & nMode )
873 bActiveEntries = sal_True;
874 break;
877 pSfxSlot = pSlotPool->NextSlot();
880 if ( bActiveEntries )
882 // Wenn Gruppe nicht leer
883 SvLBoxEntry *pEntry = InsertEntry( aName, NULL );
884 SfxGroupInfo_Impl *pInfo = new SfxGroupInfo_Impl( SFX_CFGGROUP_FUNCTION, i );
885 aArr.Insert( pInfo, aArr.Count() );
886 pEntry->SetUserData( pInfo );
892 SfxApplication *pSfxApp = SFX_APP();
893 if ( bShowBasic )
895 // Basics einsammeln
896 pSfxApp->EnterBasicCall();
897 String aMacroName(' ');
898 aMacroName += pImp->m_sDlgMacros;
900 // Zuerst AppBasic
901 BasicManager *pAppBasicMgr = pSfxApp->GetBasicManager();
902 BOOL bInsert = TRUE;
904 if ( pArr )
906 bInsert = FALSE;
907 for ( USHORT n=0; n<pArr->Count(); n++ )
909 if ( *(*pArr)[n] == pSfxApp->GetName() )
911 bInsert = TRUE;
912 break;
918 if ( bInsert )
920 pAppBasicMgr->SetName( pSfxApp->GetName() );
921 if ( pAppBasicMgr->GetLibCount() )
923 // Nur einf"ugen, wenn Bibliotheken vorhanden
924 String aAppBasTitle( pImp->m_aHumanAppName );
925 aAppBasTitle += aMacroName;
926 SvLBoxEntry *pEntry = InsertEntry( aAppBasTitle, 0 );
927 SfxGroupInfo_Impl *pInfo = new SfxGroupInfo_Impl( SFX_CFGGROUP_BASICMGR, 0, pAppBasicMgr );
928 // aArr.Insert( pInfo, aArr.Count() );
929 pEntry->SetUserData( pInfo );
930 pEntry->EnableChildsOnDemand( TRUE );
931 // Expand( pEntry );
935 Reference< XModel > xDoc( lcl_getScriptableDocument_nothrow( m_xFrame ) );
936 if ( xDoc.is() )
938 BasicManager* pBasicMgr = ::basic::BasicManagerRepository::getDocumentBasicManager( xDoc );
939 if ( pBasicMgr != pAppBasicMgr && pBasicMgr->GetLibCount() )
941 String sDocTitle( ::comphelper::DocumentInfo::getDocumentTitle( xDoc ) );
942 pBasicMgr->SetName( sDocTitle );
944 // Nur einf"ugen, wenn eigenes Basic mit Bibliotheken
945 SvLBoxEntry *pEntry = InsertEntry( sDocTitle.Append( aMacroName ), NULL );
946 xDoc->acquire();
947 SfxGroupInfo_Impl *pInfo =
948 new SfxGroupInfo_Impl( SFX_CFGGROUP_DOCBASICMGR, 0, xDoc.get() );
949 pEntry->SetUserData( pInfo );
950 pEntry->EnableChildsOnDemand( TRUE );
954 pSfxApp->LeaveBasicCall();
957 OSL_TRACE("** ** About to initialise SF Scripts");
958 if ( bShowSF )
960 OSL_TRACE("** ** bShowSF");
961 // Add Scripting Framework entries
962 Reference< browse::XBrowseNode > rootNode;
963 Reference< XComponentContext > xCtx;
966 Reference < beans::XPropertySet > xProps(
967 ::comphelper::getProcessServiceFactory(), UNO_QUERY_THROW );
968 xCtx.set( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), UNO_QUERY_THROW );
969 Reference< browse::XBrowseNodeFactory > xFac( xCtx->getValueByName(
970 ::rtl::OUString::createFromAscii( "/singletons/com.sun.star.script.browse.theBrowseNodeFactory") ), UNO_QUERY_THROW );
971 rootNode.set( xFac->createView( browse::BrowseNodeFactoryViewTypes::MACROSELECTOR ) );
972 //rootNode.set( xFac->createView( browse::BrowseNodeFactoryViewTypes::MACROORGANIZER ) );
974 catch( Exception& e )
976 OSL_TRACE(" Caught some exception whilst retrieving browse nodes from factory... Exception: %s",
977 ::rtl::OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US ).pData->buffer );
978 // TODO exception handling
982 if ( rootNode.is() )
984 if ( nMode )
986 //We call acquire on the XBrowseNode so that it does not
987 //get autodestructed and become invalid when accessed later.
988 rootNode->acquire();
990 SfxGroupInfo_Impl *pInfo =
991 new SfxGroupInfo_Impl( SFX_CFGGROUP_SCRIPTCONTAINER, 0,
992 static_cast<void *>(rootNode.get()));
994 String aTitle(pImp->m_sDlgMacros);
995 SvLBoxEntry *pNewEntry = InsertEntry( aTitle, NULL );
996 pNewEntry->SetUserData( pInfo );
997 pNewEntry->EnableChildsOnDemand( TRUE );
998 aArr.Insert( pInfo, aArr.Count() );
1000 else
1002 //We are only showing scripts not slot APIs so skip
1003 //Root node and show location nodes
1004 try {
1005 if ( rootNode->hasChildNodes() )
1007 Sequence< Reference< browse::XBrowseNode > > children =
1008 rootNode->getChildNodes();
1009 BOOL bIsRootNode = FALSE;
1011 ::rtl::OUString user = ::rtl::OUString::createFromAscii("user");
1012 ::rtl::OUString share = ::rtl::OUString::createFromAscii("share");
1013 if ( rootNode->getName().equals(::rtl::OUString::createFromAscii("Root") ))
1015 bIsRootNode = TRUE;
1018 //To mimic current starbasic behaviour we
1019 //need to make sure that only the current document
1020 //is displayed in the config tree. Tests below
1021 //set the bDisplay flag to FALSE if the current
1022 //node is a first level child of the Root and is NOT
1023 //either the current document, user or share
1024 ::rtl::OUString currentDocTitle;
1025 Reference< XModel > xDocument( lcl_getScriptableDocument_nothrow( m_xFrame ) );
1026 if ( xDocument.is() )
1028 currentDocTitle = ::comphelper::DocumentInfo::getDocumentTitle( xDocument );
1031 for ( sal_Int32 n = 0; n < children.getLength(); n++ )
1033 Reference< browse::XBrowseNode >& theChild = children[n];
1034 BOOL bDisplay = TRUE;
1035 ::rtl::OUString uiName = theChild->getName();
1036 if ( bIsRootNode )
1038 if ( ! ((theChild->getName().equals( user ) || theChild->getName().equals( share ) ||
1039 theChild->getName().equals( currentDocTitle ) ) ) )
1041 bDisplay=FALSE;
1043 else
1045 if ( uiName.equals( user ) )
1047 uiName = pImp->m_sMyMacros;
1049 else if ( uiName.equals( share ) )
1051 uiName = pImp->m_sProdMacros;
1055 if (children[n]->getType() != browse::BrowseNodeTypes::SCRIPT && bDisplay )
1058 // We call acquire on the XBrowseNode so that it does not
1059 // get autodestructed and become invalid when accessed later.
1060 theChild->acquire();
1062 SfxGroupInfo_Impl* pInfo =
1063 new SfxGroupInfo_Impl(SFX_CFGGROUP_SCRIPTCONTAINER,
1064 0, static_cast<void *>( theChild.get()));
1066 Image aImage = GetImage( theChild, xCtx, bIsRootNode,BMP_COLOR_NORMAL );
1067 SvLBoxEntry* pNewEntry =
1068 InsertEntry( uiName, NULL);
1069 SetExpandedEntryBmp(pNewEntry, aImage, BMP_COLOR_NORMAL);
1070 SetCollapsedEntryBmp(pNewEntry, aImage, BMP_COLOR_NORMAL);
1071 aImage = GetImage( theChild, xCtx, bIsRootNode,BMP_COLOR_HIGHCONTRAST );
1072 SetExpandedEntryBmp(pNewEntry, aImage, BMP_COLOR_HIGHCONTRAST);
1073 SetCollapsedEntryBmp(pNewEntry, aImage, BMP_COLOR_HIGHCONTRAST);
1075 pNewEntry->SetUserData( pInfo );
1076 aArr.Insert( pInfo, aArr.Count() );
1078 if ( children[n]->hasChildNodes() )
1080 Sequence< Reference< browse::XBrowseNode > > grandchildren =
1081 children[n]->getChildNodes();
1083 for ( sal_Int32 m = 0; m < grandchildren.getLength(); m++ )
1085 if ( grandchildren[m]->getType() == browse::BrowseNodeTypes::CONTAINER )
1087 pNewEntry->EnableChildsOnDemand( TRUE );
1088 m = grandchildren.getLength();
1096 catch (RuntimeException&) {
1097 // do nothing, the entry will not be displayed in the UI
1103 // add styles
1104 if ( m_xSMGR.is() )
1106 String sStyle( pImp->m_aStrGroupStyles );
1107 SvLBoxEntry *pEntry = InsertEntry( sStyle, 0 );
1108 SfxGroupInfo_Impl *pInfo = new SfxGroupInfo_Impl( SFX_CFGGROUP_STYLES, 0, 0 ); // TODO last parameter should contain user data
1109 aArr.Insert( pInfo, aArr.Count() );
1110 pEntry->SetUserData( pInfo );
1111 pEntry->EnableChildsOnDemand( TRUE );
1114 /* {
1115 String sSymbols( String::CreateFromAscii("Symbols") );
1116 SvLBoxEntry *pEntry = InsertEntry( sSymbols, 0 );
1117 SfxGroupInfo_Impl *pInfo = new SfxGroupInfo_Impl( SFX_CFGGROUP_SPECIALCHARACTERS, 0, 0 ); // TODO last parameter should contain user data
1118 aArr.Insert( pInfo, aArr.Count() );
1119 pEntry->SetUserData( pInfo );
1120 } */
1122 MakeVisible( GetEntry( 0,0 ) );
1123 SetUpdateMode( TRUE );
1125 Image SfxConfigGroupListBox_Impl::GetImage( Reference< browse::XBrowseNode > node, Reference< XComponentContext > xCtx, bool bIsRootNode, bool bHighContrast )
1127 Image aImage;
1128 if ( bIsRootNode )
1130 ::rtl::OUString user = ::rtl::OUString::createFromAscii("user");
1131 ::rtl::OUString share = ::rtl::OUString::createFromAscii("share");
1132 if (node->getName().equals( user ) || node->getName().equals(share ) )
1134 if( bHighContrast == BMP_COLOR_NORMAL )
1135 aImage = pImp->m_hdImage;
1136 else
1137 aImage = pImp->m_hdImage_hc;
1139 else
1141 ::rtl::OUString factoryURL;
1142 ::rtl::OUString nodeName = node->getName();
1143 Reference<XInterface> xDocumentModel = getDocumentModel(xCtx, nodeName );
1144 if ( xDocumentModel.is() )
1146 Reference< ::com::sun::star::frame::XModuleManager >
1147 xModuleManager(
1148 xCtx->getServiceManager()
1149 ->createInstanceWithContext(
1150 ::rtl::OUString::createFromAscii("" // xxx todo
1151 "com.sun.star.frame.ModuleManager"),
1152 xCtx ),
1153 UNO_QUERY_THROW );
1154 Reference<container::XNameAccess> xModuleConfig(
1155 xModuleManager, UNO_QUERY_THROW );
1156 // get the long name of the document:
1157 ::rtl::OUString appModule( xModuleManager->identify(
1158 xDocumentModel ) );
1159 Sequence<beans::PropertyValue> moduleDescr;
1160 Any aAny = xModuleConfig->getByName(appModule);
1161 if( sal_True != ( aAny >>= moduleDescr ) )
1163 throw RuntimeException(::rtl::OUString::createFromAscii("SFTreeListBox::Init: failed to get PropertyValue"), Reference< XInterface >());
1165 beans::PropertyValue const * pmoduleDescr =
1166 moduleDescr.getConstArray();
1167 for ( sal_Int32 pos = moduleDescr.getLength(); pos--; )
1169 if (pmoduleDescr[ pos ].Name.equalsAsciiL(
1170 RTL_CONSTASCII_STRINGPARAM(
1171 "ooSetupFactoryEmptyDocumentURL") ))
1173 pmoduleDescr[ pos ].Value >>= factoryURL;
1174 OSL_TRACE("factory url for doc images is %s",
1175 ::rtl::OUStringToOString( factoryURL , RTL_TEXTENCODING_ASCII_US ).pData->buffer );
1176 break;
1180 if( factoryURL.getLength() > 0 )
1182 if( bHighContrast == BMP_COLOR_NORMAL )
1183 aImage = SvFileInformationManager::GetFileImage(
1184 INetURLObject(factoryURL), false,
1185 BMP_COLOR_NORMAL );
1186 else
1187 aImage = SvFileInformationManager::GetFileImage(
1188 INetURLObject(factoryURL), false,
1189 BMP_COLOR_HIGHCONTRAST );
1191 else
1193 if( bHighContrast == BMP_COLOR_NORMAL )
1194 aImage = pImp->m_docImage;
1195 else
1196 aImage = pImp->m_docImage_hc;
1200 else
1202 if( node->getType() == browse::BrowseNodeTypes::SCRIPT )
1204 if( bHighContrast == BMP_COLOR_NORMAL )
1205 aImage = pImp->m_macImage;
1206 else
1207 aImage = pImp->m_macImage_hc;
1209 else
1211 if( bHighContrast == BMP_COLOR_NORMAL )
1212 aImage = pImp->m_libImage;
1213 else
1214 aImage = pImp->m_libImage_hc;
1217 return aImage;
1220 Reference< XInterface >
1221 SfxConfigGroupListBox_Impl::getDocumentModel( Reference< XComponentContext >& xCtx, ::rtl::OUString& docName )
1223 Reference< XInterface > xModel;
1224 Reference< lang::XMultiComponentFactory > mcf =
1225 xCtx->getServiceManager();
1226 Reference< frame::XDesktop > desktop (
1227 mcf->createInstanceWithContext(
1228 ::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop"), xCtx ),
1229 UNO_QUERY );
1231 Reference< container::XEnumerationAccess > componentsAccess =
1232 desktop->getComponents();
1233 Reference< container::XEnumeration > components =
1234 componentsAccess->createEnumeration();
1235 while (components->hasMoreElements())
1237 Reference< frame::XModel > model(
1238 components->nextElement(), UNO_QUERY );
1239 if ( model.is() )
1241 ::rtl::OUString sTdocUrl =
1242 ::comphelper::DocumentInfo::getDocumentTitle( model );
1243 if( sTdocUrl.equals( docName ) )
1245 xModel = model;
1246 break;
1250 return xModel;
1253 ::rtl::OUString SfxConfigGroupListBox_Impl::parseLocationName( const ::rtl::OUString& location )
1255 // strip out the last leaf of location name
1256 // e.g. file://dir1/dir2/Blah.sxw - > Blah.sxw
1257 ::rtl::OUString temp = location;
1258 sal_Int32 lastSlashIndex = temp.lastIndexOf( ::rtl::OUString::createFromAscii( "/" ) );
1260 if ( ( lastSlashIndex + 1 ) < temp.getLength() )
1262 temp = temp.copy( lastSlashIndex + 1 );
1264 // maybe we should throw here!!!
1265 else
1267 OSL_TRACE("Something wrong with name, perhaps we should throw an exception");
1269 return temp;
1272 //-----------------------------------------------
1273 ::rtl::OUString SfxConfigGroupListBox_Impl::MapCommand2UIName(const ::rtl::OUString& sCommand)
1275 ::rtl::OUString sUIName;
1278 css::uno::Reference< css::container::XNameAccess > xModuleConf;
1279 m_xUICmdDescription->getByName(m_sModuleLongName) >>= xModuleConf;
1280 if (xModuleConf.is())
1282 ::comphelper::SequenceAsHashMap lProps(xModuleConf->getByName(sCommand));
1283 sUIName = lProps.getUnpackedValueOrDefault(::rtl::OUString::createFromAscii("Name"), ::rtl::OUString());
1286 catch(const css::uno::RuntimeException& exRun)
1287 { throw exRun; }
1288 catch(css::uno::Exception&)
1289 { sUIName = ::rtl::OUString(); }
1291 // fallback for missing UINames !?
1292 if (!sUIName.getLength())
1294 sUIName = sCommand;
1296 #if OSL_DEBUG_LEVEL > 1
1297 ::rtl::OUStringBuffer sMsg(256);
1298 sMsg.appendAscii("There is no UIName for the internal command \"");
1299 sMsg.append (sCommand );
1300 sMsg.appendAscii("\". The UI will be invalid then ..." );
1301 OSL_ENSURE(sal_False, ::rtl::OUStringToOString(sMsg.makeStringAndClear(), RTL_TEXTENCODING_UTF8).getStr());
1302 #endif
1306 return sUIName;
1309 //-----------------------------------------------
1310 void SfxConfigGroupListBox_Impl::GroupSelected()
1311 /* Beschreibung
1312 Eine Funktionsgruppe oder eine Basicmodul wurde selektiert. Alle Funktionen bzw.
1313 Macros werden in der Functionlistbox anzeigt.
1316 SvLBoxEntry *pEntry = FirstSelected();
1317 SfxGroupInfo_Impl *pInfo = (SfxGroupInfo_Impl*) pEntry->GetUserData();
1318 pFunctionListBox->SetUpdateMode(FALSE);
1319 pFunctionListBox->ClearAll();
1320 if ( pInfo->nKind != SFX_CFGGROUP_FUNCTION &&
1321 pInfo->nKind != SFX_CFGGROUP_BASICMOD &&
1322 pInfo->nKind != SFX_CFGGROUP_SCRIPTCONTAINER &&
1323 pInfo->nKind != SFX_CFGGROUP_STYLES )
1325 pFunctionListBox->SetUpdateMode(TRUE);
1326 return;
1329 switch ( pInfo->nKind )
1331 case SFX_CFGGROUP_FUNCTION :
1333 USHORT nGroup = pInfo->nOrd;
1334 css::uno::Reference< css::frame::XDispatchInformationProvider > xProvider (m_xFrame, css::uno::UNO_QUERY_THROW);
1335 css::uno::Sequence< css::frame::DispatchInformation > lCommands = xProvider->getConfigurableDispatchInformation(nGroup);
1336 sal_Int32 c = lCommands.getLength();
1337 sal_Int32 i = 0;
1339 for (i=0; i<c; ++i)
1341 const css::frame::DispatchInformation& rInfo = lCommands[i];
1342 ::rtl::OUString sUIName = MapCommand2UIName(rInfo.Command);
1343 SvLBoxEntry* pFuncEntry = pFunctionListBox->InsertEntry(sUIName, NULL);
1344 SfxGroupInfo_Impl* pGrpInfo = new SfxGroupInfo_Impl(SFX_CFGFUNCTION_SLOT, 0);
1345 pGrpInfo->sCommand = rInfo.Command;
1346 pGrpInfo->sLabel = sUIName;
1347 pFuncEntry->SetUserData(pGrpInfo);
1350 break;
1353 case SFX_CFGGROUP_BASICMOD :
1355 SvLBoxEntry *pLibEntry = GetParent( pEntry );
1356 SfxGroupInfo_Impl *pLibInfo =
1357 (SfxGroupInfo_Impl*) pLibEntry->GetUserData();
1358 SvLBoxEntry *pBasEntry = GetParent( pLibEntry );
1359 SfxGroupInfo_Impl *pBasInfo =
1360 (SfxGroupInfo_Impl*) pBasEntry->GetUserData();
1362 StarBASIC *pLib = (StarBASIC*) pLibInfo->pObject;
1363 Reference< XModel > xDoc;
1364 if ( pBasInfo->nKind == SFX_CFGGROUP_DOCBASICMGR )
1365 xDoc = static_cast< XModel* >( pBasInfo->pObject );
1367 SbModule *pMod = (SbModule*) pInfo->pObject;
1368 for ( USHORT nMeth=0; nMeth < pMod->GetMethods()->Count(); nMeth++ )
1370 SbxMethod *pMeth = (SbxMethod*)pMod->GetMethods()->Get(nMeth);
1371 SfxMacroInfoPtr pInf = new SfxMacroInfo( !xDoc.is(),
1372 pLib->GetName(),
1373 pMod->GetName(),
1374 pMeth->GetName());
1375 if ( pMeth->GetInfo() )
1376 pInf->SetHelpText( pMeth->GetInfo()->GetComment() );
1377 USHORT nId = SFX_APP()->GetMacroConfig()->GetSlotId( pInf );
1378 if ( !nId )
1379 break; // Kein Slot mehr frei
1381 SvLBoxEntry* pFuncEntry =
1382 pFunctionListBox->InsertEntry( pMeth->GetName(), NULL );
1383 SfxGroupInfo_Impl *pGrpInfo =
1384 new SfxGroupInfo_Impl( SFX_CFGFUNCTION_MACRO, nId, pInf );
1385 pFunctionListBox->aArr.Insert( pGrpInfo, pFunctionListBox->aArr.Count() );
1386 pFuncEntry->SetUserData( pGrpInfo );
1389 break;
1392 case SFX_CFGGROUP_SCRIPTCONTAINER:
1394 if ( !GetChildCount( pEntry ) )
1396 Reference< browse::XBrowseNode > rootNode(
1397 reinterpret_cast< browse::XBrowseNode* >( pInfo->pObject ) ) ;
1399 try {
1400 if ( rootNode->hasChildNodes() )
1402 Sequence< Reference< browse::XBrowseNode > > children =
1403 rootNode->getChildNodes();
1405 for ( sal_Int32 n = 0; n < children.getLength(); n++ )
1407 if (children[n]->getType() == browse::BrowseNodeTypes::SCRIPT)
1409 ::rtl::OUString uri;
1411 Reference < beans::XPropertySet >xPropSet( children[n], UNO_QUERY );
1412 if (!xPropSet.is())
1414 continue;
1417 Any value =
1418 xPropSet->getPropertyValue( String::CreateFromAscii( "URI" ) );
1419 value >>= uri;
1421 SfxMacroInfo* aInfo = new SfxMacroInfo( (String)uri );
1422 aInfo->SetHelpText( uri );
1423 SFX_APP()->GetMacroConfig()->GetSlotId( aInfo );
1425 SfxGroupInfo_Impl* pGrpInfo =
1426 new SfxGroupInfo_Impl(SFX_CFGFUNCTION_SCRIPT,
1427 aInfo->GetSlotId(), aInfo);
1429 Image aImage = GetImage( children[n], Reference< XComponentContext >(), sal_False, BMP_COLOR_NORMAL );
1430 SvLBoxEntry* pNewEntry =
1431 pFunctionListBox->InsertEntry( children[n]->getName(), NULL );
1432 pFunctionListBox->SetExpandedEntryBmp(pNewEntry, aImage, BMP_COLOR_NORMAL);
1433 pFunctionListBox->SetCollapsedEntryBmp(pNewEntry, aImage, BMP_COLOR_NORMAL);
1434 aImage = GetImage( children[n], Reference< XComponentContext >(), sal_False, BMP_COLOR_HIGHCONTRAST );
1435 pFunctionListBox->SetExpandedEntryBmp(pNewEntry, aImage, BMP_COLOR_HIGHCONTRAST);
1436 pFunctionListBox->SetCollapsedEntryBmp(pNewEntry, aImage, BMP_COLOR_HIGHCONTRAST);
1438 pGrpInfo->sCommand = uri;
1439 pGrpInfo->sLabel = children[n]->getName();
1440 pNewEntry->SetUserData( pGrpInfo );
1442 pFunctionListBox->aArr.Insert(
1443 pGrpInfo, pFunctionListBox->aArr.Count() );
1449 catch (RuntimeException&) {
1450 // do nothing, the entry will not be displayed in the UI
1453 break;
1456 case SFX_CFGGROUP_STYLES :
1458 SfxStyleInfo_Impl* pFamily = (SfxStyleInfo_Impl*)(pInfo->pObject);
1459 if (pFamily)
1461 const ::std::vector< SfxStyleInfo_Impl > lStyles = pStylesInfo->getStyles(pFamily->sFamily);
1462 ::std::vector< SfxStyleInfo_Impl >::const_iterator pIt;
1463 for ( pIt = lStyles.begin();
1464 pIt != lStyles.end() ;
1465 ++pIt )
1467 SfxStyleInfo_Impl* pStyle = new SfxStyleInfo_Impl(*pIt);
1468 SvLBoxEntry* pFuncEntry = pFunctionListBox->InsertEntry( pStyle->sLabel, NULL );
1469 SfxGroupInfo_Impl *pGrpInfo = new SfxGroupInfo_Impl( SFX_CFGGROUP_STYLES, 0, pStyle );
1470 pFunctionListBox->aArr.Insert( pGrpInfo, pFunctionListBox->aArr.Count() );
1471 pGrpInfo->sCommand = pStyle->sCommand;
1472 pGrpInfo->sLabel = pStyle->sLabel;
1473 pFuncEntry->SetUserData( pGrpInfo );
1476 break;
1479 default:
1480 return;
1483 if ( pFunctionListBox->GetEntryCount() )
1484 pFunctionListBox->Select( pFunctionListBox->GetEntry( 0, 0 ) );
1486 pFunctionListBox->SetUpdateMode(TRUE);
1489 BOOL SfxConfigGroupListBox_Impl::Expand( SvLBoxEntry* pParent )
1491 BOOL bRet = SvTreeListBox::Expand( pParent );
1492 if ( bRet )
1494 // Wieviele Entries k"onnen angezeigt werden ?
1495 ULONG nEntries = GetOutputSizePixel().Height() / GetEntryHeight();
1497 // Wieviele Kinder sollen angezeigt werden ?
1498 ULONG nChildCount = GetVisibleChildCount( pParent );
1500 // Passen alle Kinder und der parent gleichzeitig in die View ?
1501 if ( nChildCount+1 > nEntries )
1503 // Wenn nicht, wenigstens parent ganz nach oben schieben
1504 MakeVisible( pParent, TRUE );
1506 else
1508 // An welcher relativen ViewPosition steht der aufzuklappende parent
1509 SvLBoxEntry *pEntry = GetFirstEntryInView();
1510 ULONG nParentPos = 0;
1511 while ( pEntry && pEntry != pParent )
1513 nParentPos++;
1514 pEntry = GetNextEntryInView( pEntry );
1517 // Ist unter dem parent noch genug Platz f"ur alle Kinder ?
1518 if ( nParentPos + nChildCount + 1 > nEntries )
1519 ScrollOutputArea( (short)( nEntries - ( nParentPos + nChildCount + 1 ) ) );
1523 return bRet;
1526 void SfxConfigGroupListBox_Impl::RequestingChilds( SvLBoxEntry *pEntry )
1527 /* Beschreibung
1528 Ein Basic oder eine Bibliothek werden ge"offnet
1531 SfxGroupInfo_Impl *pInfo = (SfxGroupInfo_Impl*) pEntry->GetUserData();
1532 pInfo->bWasOpened = TRUE;
1533 switch ( pInfo->nKind )
1535 case SFX_CFGGROUP_BASICMGR :
1536 case SFX_CFGGROUP_DOCBASICMGR :
1538 if ( !GetChildCount( pEntry ) )
1540 // Erstmaliges "Offnen
1541 BasicManager* pMgr( GetBasicManager( *pEntry ) );
1543 SvLBoxEntry *pLibEntry = 0;
1544 for ( USHORT nLib=0; nLib<pMgr->GetLibCount(); nLib++)
1546 StarBASIC* pLib = pMgr->GetLib( nLib );
1547 pLibEntry = InsertEntry( pMgr->GetLibName( nLib ), pEntry );
1548 SfxGroupInfo_Impl *pGrpInfo = new SfxGroupInfo_Impl( SFX_CFGGROUP_BASICLIB, nLib, pLib );
1549 aArr.Insert( pGrpInfo, aArr.Count() );
1550 pLibEntry->SetUserData( pGrpInfo );
1551 pLibEntry->EnableChildsOnDemand( TRUE );
1555 break;
1558 case SFX_CFGGROUP_BASICLIB :
1560 if ( !GetChildCount( pEntry ) )
1562 // Erstmaliges "Offnen
1563 StarBASIC *pLib = (StarBASIC*) pInfo->pObject;
1564 if ( !pLib )
1566 // Lib mu\s nachgeladen werden
1567 SvLBoxEntry *pParent = GetParent( pEntry );
1568 BasicManager *pMgr( GetBasicManager( *pParent ) );
1570 if ( pMgr->LoadLib( pInfo->nOrd ) )
1571 pInfo->pObject = pLib = pMgr->GetLib( pInfo->nOrd );
1572 else
1573 break;
1576 SvLBoxEntry *pModEntry = 0;
1577 for ( USHORT nMod=0; nMod<pLib->GetModules()->Count(); nMod++ )
1579 SbModule* pMod = (SbModule*)pLib->GetModules()->Get( nMod );
1581 BOOL bIsStarScript = FALSE; //pMod->ISA( SbJScriptModule );
1582 BOOL bWantsStarScript = pImp->m_aScriptType.EqualsAscii("StarScript");
1583 if ( bIsStarScript != bWantsStarScript )
1584 continue;
1585 pModEntry = InsertEntry( pMod->GetName(), pEntry );
1586 SfxGroupInfo_Impl *pGrpInfo = new SfxGroupInfo_Impl( SFX_CFGGROUP_BASICMOD, 0, pMod );
1587 aArr.Insert( pGrpInfo, aArr.Count() );
1588 pModEntry->SetUserData( pGrpInfo );
1592 break;
1595 case SFX_CFGGROUP_SCRIPTCONTAINER:
1597 if ( !GetChildCount( pEntry ) )
1599 Reference< browse::XBrowseNode > rootNode(
1600 reinterpret_cast< browse::XBrowseNode* >( pInfo->pObject ) ) ;
1602 try {
1603 if ( rootNode->hasChildNodes() )
1605 Sequence< Reference< browse::XBrowseNode > > children =
1606 rootNode->getChildNodes();
1607 BOOL bIsRootNode = FALSE;
1609 ::rtl::OUString user = ::rtl::OUString::createFromAscii("user");
1610 ::rtl::OUString share = ::rtl::OUString::createFromAscii("share");
1611 if ( rootNode->getName().equals(::rtl::OUString::createFromAscii("Root") ))
1613 bIsRootNode = TRUE;
1616 /* To mimic current starbasic behaviour we
1617 need to make sure that only the current document
1618 is displayed in the config tree. Tests below
1619 set the bDisplay flag to FALSE if the current
1620 node is a first level child of the Root and is NOT
1621 either the current document, user or share */
1622 ::rtl::OUString currentDocTitle;
1623 Reference< XModel > xDocument( lcl_getScriptableDocument_nothrow( m_xFrame ) );
1624 if ( xDocument.is() )
1626 currentDocTitle = ::comphelper::DocumentInfo::getDocumentTitle( xDocument );
1629 sal_Int32 nLen = children.getLength();
1630 for ( sal_Int32 n = 0; n < nLen; n++ )
1632 Reference< browse::XBrowseNode >& theChild = children[n];
1633 ::rtl::OUString aName( theChild->getName() );
1634 BOOL bDisplay = TRUE;
1635 if ( bIsRootNode )
1637 if ( !( (aName.equals(user) || aName.equals(share) || aName.equals(currentDocTitle) ) ) )
1638 bDisplay=FALSE;
1640 if ( children[n].is() && children[n]->getType() != browse::BrowseNodeTypes::SCRIPT && bDisplay )
1644 We call acquire on the XBrowseNode so that it does not
1645 get autodestructed and become invalid when accessed later.
1647 theChild->acquire();
1649 SfxGroupInfo_Impl* pGrpInfo =
1650 new SfxGroupInfo_Impl(SFX_CFGGROUP_SCRIPTCONTAINER,
1651 0, static_cast<void *>( theChild.get()));
1653 Image aImage = GetImage( theChild, Reference< XComponentContext >(), sal_False, BMP_COLOR_NORMAL );
1654 SvLBoxEntry* pNewEntry =
1655 InsertEntry( theChild->getName(), pEntry );
1656 SetExpandedEntryBmp(pNewEntry, aImage, BMP_COLOR_NORMAL);
1657 SetCollapsedEntryBmp(pNewEntry, aImage, BMP_COLOR_NORMAL);
1658 aImage = GetImage( theChild, Reference< XComponentContext >(), sal_False, BMP_COLOR_HIGHCONTRAST );
1659 SetExpandedEntryBmp(pNewEntry, aImage, BMP_COLOR_HIGHCONTRAST);
1660 SetCollapsedEntryBmp(pNewEntry, aImage, BMP_COLOR_HIGHCONTRAST);
1662 pNewEntry->SetUserData( pGrpInfo );
1663 aArr.Insert( pGrpInfo, aArr.Count() );
1665 if ( children[n]->hasChildNodes() )
1667 Sequence< Reference< browse::XBrowseNode > > grandchildren =
1668 children[n]->getChildNodes();
1670 for ( sal_Int32 m = 0; m < grandchildren.getLength(); m++ )
1672 if ( grandchildren[m]->getType() == browse::BrowseNodeTypes::CONTAINER )
1674 pNewEntry->EnableChildsOnDemand( TRUE );
1675 m = grandchildren.getLength();
1683 catch (RuntimeException&) {
1684 // do nothing, the entry will not be displayed in the UI
1687 break;
1690 case SFX_CFGGROUP_STYLES:
1692 if ( !GetChildCount( pEntry ) )
1694 const ::std::vector< SfxStyleInfo_Impl > lStyleFamilies = pStylesInfo->getStyleFamilies();
1695 ::std::vector< SfxStyleInfo_Impl >::const_iterator pIt;
1696 for ( pIt = lStyleFamilies.begin();
1697 pIt != lStyleFamilies.end() ;
1698 ++pIt )
1700 SfxStyleInfo_Impl* pFamily = new SfxStyleInfo_Impl(*pIt);
1701 SvLBoxEntry* pStyleEntry = InsertEntry( pFamily->sLabel, pEntry );
1702 SfxGroupInfo_Impl *pGrpInfo = new SfxGroupInfo_Impl( SFX_CFGGROUP_STYLES, 0, pFamily );
1703 aArr.Insert( pGrpInfo, aArr.Count() );
1704 pStyleEntry->SetUserData( pGrpInfo );
1705 pStyleEntry->EnableChildsOnDemand( FALSE );
1708 break;
1711 default:
1712 DBG_ERROR( "Falscher Gruppentyp!" );
1713 break;
1717 void SfxConfigGroupListBox_Impl::AddAndSelect( const SfxStringItem* , const SfxStringItem* )
1720 if ( pText )
1722 Select( GetEntry( GetEntryCount()-1) );
1723 SvLBoxEntry* pFuncEntry = pFunctionListBox->InsertEntry( pText->GetValue(), NULL );
1724 SfxGroupInfo_Impl *pGrpInfo = new SfxGroupInfo_Impl( SFX_CFGGROUP_SPECIALCHARACTERS, 0, 0 );
1725 String aCommand = String::CreateFromAscii(".uno:InsertSymbol?Symbols:string=");
1726 aCommand += pText->GetValue();
1727 pFunctionListBox->aArr.Insert( pGrpInfo, pFunctionListBox->aArr.Count() );
1728 pGrpInfo->sCommand = aCommand;
1729 pGrpInfo->sLabel = String::CreateFromAscii("Symbols: ");
1730 pGrpInfo->sLabel += pText->GetValue();
1731 pFuncEntry->SetUserData( pGrpInfo );
1736 void SfxConfigGroupListBox_Impl::SelectMacro( const SfxMacroInfoItem *pItem )
1738 SelectMacro( pItem->GetBasicManager()->GetName(),
1739 pItem->GetQualifiedName() );
1742 void SfxConfigGroupListBox_Impl::SelectMacro( const String& rBasic,
1743 const String& rMacro )
1745 String aBasicName( rBasic );
1746 aBasicName += ' ';
1747 aBasicName += pImp->m_sMacros;
1748 String aLib, aModule, aMethod;
1749 USHORT nCount = rMacro.GetTokenCount('.');
1750 aMethod = rMacro.GetToken( nCount-1, '.' );
1751 if ( nCount > 2 )
1753 aLib = rMacro.GetToken( 0, '.' );
1754 aModule = rMacro.GetToken( nCount-2, '.' );
1757 SvLBoxEntry *pEntry = FirstChild(0);
1758 while ( pEntry )
1760 String aEntryBas = GetEntryText( pEntry );
1761 if ( aEntryBas == aBasicName )
1763 Expand( pEntry );
1764 SvLBoxEntry *pLib = FirstChild( pEntry );
1765 while ( pLib )
1767 String aEntryLib = GetEntryText( pLib );
1768 if ( aEntryLib == aLib )
1770 Expand( pLib );
1771 SvLBoxEntry *pMod = FirstChild( pLib );
1772 while ( pMod )
1774 String aEntryMod = GetEntryText( pMod );
1775 if ( aEntryMod == aModule )
1777 Expand( pMod );
1778 MakeVisible( pMod );
1779 Select( pMod );
1780 SvLBoxEntry *pMethod = pFunctionListBox->First();
1781 while ( pMethod )
1783 String aEntryMethod = GetEntryText( pMethod );
1784 if ( aEntryMethod == aMethod )
1786 pFunctionListBox->Select( pMethod );
1787 pFunctionListBox->MakeVisible( pMethod );
1788 return;
1790 pMethod = pFunctionListBox->Next( pMethod );
1793 pMod = NextSibling( pMod );
1796 pLib = NextSibling( pLib );
1799 pEntry = NextSibling( pEntry );