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