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 <vcl/help.hxx>
30 : : #include <vcl/msgbox.hxx>
31 : : #include <vcl/metric.hxx>
32 : : #include "selector.hxx"
33 : : #include <dialmgr.hxx>
34 : : #include "selector.hrc"
35 : : #include <svx/fmresids.hrc> // for RID_SVXIMG_...
36 : : #include <svx/dialmgr.hxx> // for RID_SVXIMG_...
37 : : #include <cuires.hrc>
38 : : #include <sfx2/app.hxx>
39 : : #include <sfx2/msg.hxx>
40 : : #include <sfx2/msgpool.hxx>
41 : : #include <sfx2/minfitem.hxx>
42 : : #include <sfx2/objsh.hxx>
43 : : #include <sfx2/dispatch.hxx>
44 : :
45 : : #include <comphelper/documentinfo.hxx>
46 : : #include <comphelper/processfactory.hxx>
47 : : #include <comphelper/componentcontext.hxx>
48 : :
49 : : #include <com/sun/star/beans/XPropertySet.hpp>
50 : : #include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
51 : : #include <com/sun/star/script/provider/XScriptProvider.hpp>
52 : : #include <com/sun/star/script/browse/XBrowseNode.hpp>
53 : : #include <com/sun/star/script/browse/BrowseNodeTypes.hpp>
54 : : #include <com/sun/star/script/browse/XBrowseNodeFactory.hpp>
55 : : #include <com/sun/star/script/browse/BrowseNodeFactoryViewTypes.hpp>
56 : : #include <com/sun/star/frame/XModuleManager.hpp>
57 : : #include <com/sun/star/frame/XDesktop.hpp>
58 : : #include <com/sun/star/container/XEnumerationAccess.hpp>
59 : : #include <com/sun/star/container/XEnumeration.hpp>
60 : : #include <com/sun/star/document/XEmbeddedScripts.hpp>
61 : : #include <com/sun/star/document/XScriptInvocationContext.hpp>
62 : : #include <com/sun/star/frame/XDispatchInformationProvider.hpp>
63 : : #include <com/sun/star/frame/DispatchInformation.hpp>
64 : : #include <com/sun/star/container/XChild.hpp>
65 : :
66 : : using ::rtl::OUString;
67 : : using namespace ::com::sun::star;
68 : : using namespace ::com::sun::star::uno;
69 : : using namespace ::com::sun::star::script;
70 : : using namespace ::com::sun::star::frame;
71 : : using namespace ::com::sun::star::document;
72 : : using namespace ::com::sun::star::container;
73 : :
74 : : #include <svtools/imagemgr.hxx>
75 : : #include <tools/urlobj.hxx>
76 : : #include <tools/diagnose_ex.h>
77 : :
78 : : /*
79 : : * The implementations of SvxConfigFunctionListBox_Impl and
80 : : * SvxConfigGroupListBox_Impl are copied from sfx2/source/dialog/cfg.cxx
81 : : */
82 : 0 : SvxConfigFunctionListBox_Impl::SvxConfigFunctionListBox_Impl( Window* pParent, const ResId& rResId)
83 : : : SvTreeListBox( pParent, rResId )
84 : : , pCurEntry( 0 )
85 [ # # ][ # # ]: 0 : , m_pDraggingEntry( 0 )
86 : : {
87 [ # # ][ # # ]: 0 : SetStyle( GetStyle() | WB_CLIPCHILDREN | WB_HSCROLL | WB_SORT );
88 : 0 : GetModel()->SetSortMode( SortAscending );
89 : :
90 : : // Timer for the BallonHelp
91 [ # # ]: 0 : aTimer.SetTimeout( 200 );
92 : : aTimer.SetTimeoutHdl(
93 [ # # ]: 0 : LINK( this, SvxConfigFunctionListBox_Impl, TimerHdl ) );
94 : 0 : }
95 : :
96 [ # # ][ # # ]: 0 : SvxConfigFunctionListBox_Impl::~SvxConfigFunctionListBox_Impl()
97 : : {
98 [ # # ]: 0 : ClearAll();
99 [ # # ]: 0 : }
100 : :
101 : 0 : SvLBoxEntry* SvxConfigFunctionListBox_Impl::GetLastSelectedEntry()
102 : : {
103 [ # # ]: 0 : if ( m_pDraggingEntry != NULL )
104 : : {
105 : 0 : return m_pDraggingEntry;
106 : : }
107 : : else
108 : : {
109 : 0 : return FirstSelected();
110 : : }
111 : : }
112 : :
113 : 0 : void SvxConfigFunctionListBox_Impl::MouseMove( const MouseEvent& rMEvt )
114 : : {
115 : 0 : Point aMousePos = rMEvt.GetPosPixel();
116 [ # # ]: 0 : pCurEntry = GetCurEntry();
117 : :
118 [ # # ][ # # ]: 0 : if ( pCurEntry && GetEntry( aMousePos ) == pCurEntry )
[ # # ][ # # ]
119 [ # # ]: 0 : aTimer.Start();
120 : : else
121 : : {
122 [ # # ][ # # ]: 0 : Help::ShowBalloon( this, aMousePos, String() );
[ # # ]
123 [ # # ]: 0 : aTimer.Stop();
124 : : }
125 : 0 : }
126 : :
127 : :
128 : 0 : IMPL_LINK_NOARG(SvxConfigFunctionListBox_Impl, TimerHdl)
129 : : {
130 [ # # ]: 0 : aTimer.Stop();
131 [ # # ]: 0 : Point aMousePos = GetPointerPosPixel();
132 [ # # ]: 0 : SvLBoxEntry *pEntry = GetCurEntry();
133 [ # # ][ # # ]: 0 : if ( pEntry && GetEntry( aMousePos ) == pEntry && pCurEntry == pEntry )
[ # # ][ # # ]
[ # # ]
134 [ # # ][ # # ]: 0 : Help::ShowBalloon( this, OutputToScreenPixel( aMousePos ), GetHelpText( pEntry ) );
[ # # ][ # # ]
135 : 0 : return 0L;
136 : : }
137 : :
138 : 0 : void SvxConfigFunctionListBox_Impl::ClearAll()
139 : : {
140 : 0 : aArr.clear();
141 : 0 : Clear();
142 : 0 : }
143 : :
144 : 0 : String SvxConfigFunctionListBox_Impl::GetHelpText( SvLBoxEntry *pEntry )
145 : : {
146 : : SvxGroupInfo_Impl *pInfo =
147 [ # # ]: 0 : pEntry ? (SvxGroupInfo_Impl*) pEntry->GetUserData(): 0;
148 : :
149 [ # # ]: 0 : if ( pInfo )
150 : : {
151 [ # # ]: 0 : if ( pInfo->nKind == SVX_CFGFUNCTION_SLOT )
152 : : {
153 : 0 : OUString aCmdURL( pInfo->sURL );
154 : :
155 [ # # ][ # # ]: 0 : OUString aHelpText = Application::GetHelp()->GetHelpText( aCmdURL, this );
[ # # ][ # # ]
[ # # ][ # # ]
156 : :
157 [ # # ]: 0 : return aHelpText;
158 : : }
159 [ # # ]: 0 : else if ( pInfo->nKind == SVX_CFGFUNCTION_SCRIPT )
160 : : {
161 : 0 : return pInfo->sHelpText;
162 : : }
163 : : }
164 : :
165 : 0 : return String();
166 : : }
167 : :
168 : 0 : void SvxConfigFunctionListBox_Impl::FunctionSelected()
169 : : {
170 [ # # ]: 0 : Help::ShowBalloon( this, Point(), String() );
171 : 0 : }
172 : :
173 : : // drag and drop support
174 : 0 : DragDropMode SvxConfigFunctionListBox_Impl::NotifyStartDrag(
175 : : TransferDataContainer& /*aTransferDataContainer*/, SvLBoxEntry* pEntry )
176 : : {
177 : 0 : m_pDraggingEntry = pEntry;
178 : 0 : return GetDragDropMode();
179 : : }
180 : :
181 : 0 : void SvxConfigFunctionListBox_Impl::DragFinished( sal_Int8 /*nDropAction*/ )
182 : : {
183 : 0 : m_pDraggingEntry = NULL;
184 : 0 : }
185 : :
186 : : sal_Int8
187 : 0 : SvxConfigFunctionListBox_Impl::AcceptDrop( const AcceptDropEvent& /*rEvt*/ )
188 : : {
189 : 0 : return DND_ACTION_NONE;
190 : : }
191 : :
192 : 0 : SvxConfigGroupListBox_Impl::SvxConfigGroupListBox_Impl(
193 : : Window* pParent, const ResId& rResId,
194 : : bool _bShowSlots, const Reference< frame::XFrame >& xFrame )
195 : : : SvTreeListBox( pParent, rResId )
196 : : , m_bShowSlots( _bShowSlots ),
197 : 0 : m_hdImage(ResId(IMG_HARDDISK,*rResId.GetResMgr())),
198 : 0 : m_libImage(ResId(IMG_LIB,*rResId.GetResMgr())),
199 : 0 : m_macImage(ResId(IMG_MACRO,*rResId.GetResMgr())),
200 : 0 : m_docImage(ResId(IMG_DOC,*rResId.GetResMgr())),
201 : 0 : m_sMyMacros(String(ResId(STR_MYMACROS,*rResId.GetResMgr()))),
202 [ # # ][ # # : 0 : m_sProdMacros(String(ResId(STR_PRODMACROS,*rResId.GetResMgr())))
# # # # #
# # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
203 : : {
204 [ # # ]: 0 : FreeResource();
205 : :
206 [ # # ][ # # ]: 0 : if ( xFrame != NULL )
207 : : {
208 [ # # ]: 0 : m_xFrame.set( xFrame );
209 : : }
210 : :
211 [ # # ][ # # ]: 0 : SetStyle( GetStyle() | WB_CLIPCHILDREN | WB_HSCROLL | WB_HASBUTTONS | WB_HASLINES | WB_HASLINESATROOT | WB_HASBUTTONSATROOT );
212 : :
213 [ # # ][ # # ]: 0 : ImageList aNavigatorImages( SVX_RES( RID_SVXIMGLIST_FMEXPL ) );
214 : :
215 : : SetNodeBitmaps(
216 : : aNavigatorImages.GetImage( RID_SVXIMG_COLLAPSEDNODE ),
217 : : aNavigatorImages.GetImage( RID_SVXIMG_EXPANDEDNODE )
218 [ # # ][ # # ]: 0 : );
[ # # ][ # # ]
[ # # ][ # # ]
219 : 0 : }
220 : :
221 : :
222 [ # # ][ # # ]: 0 : SvxConfigGroupListBox_Impl::~SvxConfigGroupListBox_Impl()
[ # # ][ # # ]
[ # # ]
223 : : {
224 [ # # ]: 0 : ClearAll();
225 [ # # ]: 0 : }
226 : :
227 : 0 : void SvxConfigGroupListBox_Impl::ClearAll()
228 : : {
229 : 0 : aArr.clear();
230 : 0 : Clear();
231 : 0 : }
232 : :
233 : : //-----------------------------------------------
234 : : namespace
235 : : {
236 : : //...........................................
237 : : /** examines a component whether it supports XEmbeddedScripts, or provides access to such a
238 : : component by implementing XScriptInvocationContext.
239 : : @return
240 : : the model which supports the embedded scripts, or <NULL/> if it cannot find such a
241 : : model
242 : : */
243 : 0 : static Reference< XModel > lcl_getDocumentWithScripts_throw( const Reference< XInterface >& _rxComponent )
244 : : {
245 [ # # ]: 0 : Reference< XEmbeddedScripts > xScripts( _rxComponent, UNO_QUERY );
246 [ # # ]: 0 : if ( !xScripts.is() )
247 : : {
248 [ # # ]: 0 : Reference< XScriptInvocationContext > xContext( _rxComponent, UNO_QUERY );
249 [ # # ]: 0 : if ( xContext.is() )
250 [ # # ][ # # ]: 0 : xScripts.set( xContext->getScriptContainer(), UNO_QUERY );
[ # # ]
251 : : }
252 : :
253 [ # # ]: 0 : return Reference< XModel >( xScripts, UNO_QUERY );
254 : : }
255 : :
256 : : //...........................................
257 : 0 : static Reference< XModel > lcl_getScriptableDocument_nothrow( const Reference< XFrame >& _rxFrame )
258 : : {
259 : 0 : Reference< XModel > xDocument;
260 : :
261 : : // examine our associated frame
262 : : try
263 : : {
264 : : OSL_ENSURE( _rxFrame.is(), "lcl_getScriptableDocument_nothrow: you need to pass a frame to this dialog/tab page!" );
265 [ # # ]: 0 : if ( _rxFrame.is() )
266 : : {
267 : : // first try the model in the frame
268 [ # # ][ # # ]: 0 : Reference< XController > xController( _rxFrame->getController(), UNO_SET_THROW );
[ # # ]
269 [ # # ][ # # ]: 0 : xDocument = lcl_getDocumentWithScripts_throw( xController->getModel() );
[ # # ][ # # ]
270 : :
271 [ # # ]: 0 : if ( !xDocument.is() )
272 : : {
273 : : // if there is no suitable document in the frame, try the controller
274 [ # # ][ # # ]: 0 : xDocument = lcl_getDocumentWithScripts_throw( _rxFrame->getController() );
[ # # ][ # # ]
275 [ # # ]: 0 : }
276 : : }
277 : : }
278 [ # # ]: 0 : catch( const Exception& )
279 : : {
280 : : DBG_UNHANDLED_EXCEPTION();
281 : : }
282 : :
283 : 0 : return xDocument;
284 : : }
285 : : }
286 : :
287 : 0 : void SvxConfigGroupListBox_Impl::fillScriptList( const Reference< browse::XBrowseNode >& _rxRootNode, SvLBoxEntry* _pParentEntry, bool _bCheapChildrenOnDemand )
288 : : {
289 : : OSL_PRECOND( _rxRootNode.is(), "SvxConfigGroupListBox_Impl::fillScriptList: invalid root node!" );
290 [ # # ]: 0 : if ( !_rxRootNode.is() )
291 : 0 : return;
292 : :
293 : : try
294 : : {
295 [ # # ][ # # ]: 0 : if ( _rxRootNode->hasChildNodes() )
[ # # ]
296 : : {
297 : : Sequence< Reference< browse::XBrowseNode > > children =
298 [ # # ][ # # ]: 0 : _rxRootNode->getChildNodes();
299 : :
300 [ # # ][ # # ]: 0 : sal_Bool bIsRootNode = _rxRootNode->getName() == "Root";
301 : :
302 : : /* To mimic current starbasic behaviour we
303 : : need to make sure that only the current document
304 : : is displayed in the config tree. Tests below
305 : : set the bDisplay flag to sal_False if the current
306 : : node is a first level child of the Root and is NOT
307 : : either the current document, user or share */
308 : 0 : OUString sCurrentDocTitle;
309 [ # # ]: 0 : Reference< XModel > xWorkingDocument = lcl_getScriptableDocument_nothrow( m_xFrame );
310 [ # # ]: 0 : if ( xWorkingDocument.is() )
311 : : {
312 [ # # ]: 0 : sCurrentDocTitle = ::comphelper::DocumentInfo::getDocumentTitle( xWorkingDocument );
313 : : }
314 : :
315 [ # # ]: 0 : for ( long n = 0; n < children.getLength(); ++n )
316 : : {
317 [ # # ]: 0 : Reference< browse::XBrowseNode >& theChild = children[n];
318 : : //#139111# some crash reports show that it might be unset
319 [ # # ]: 0 : if ( !theChild.is() )
320 : 0 : continue;
321 [ # # ][ # # ]: 0 : ::rtl::OUString sUIName = theChild->getName();
322 : 0 : sal_Bool bDisplay = sal_True;
323 : :
324 [ # # ][ # # ]: 0 : if ( bIsRootNode
[ # # ][ # # ]
[ # # ]
325 [ # # ]: 0 : || ( m_bShowSlots && _pParentEntry && ( GetModel()->GetDepth( _pParentEntry ) == 0 ) )
326 : : // if we show slots (as in the customize dialog)
327 : : // then the user & share are added at depth=1
328 : : )
329 : : {
330 [ # # ]: 0 : if ( sUIName == "user" )
331 : : {
332 : 0 : sUIName = m_sMyMacros;
333 : 0 : bIsRootNode = sal_True;
334 : : }
335 [ # # ]: 0 : else if ( sUIName == "share" )
336 : : {
337 : 0 : sUIName = m_sProdMacros;
338 : 0 : bIsRootNode = sal_True;
339 : : }
340 [ # # ]: 0 : else if ( !sUIName.equals( sCurrentDocTitle ) )
341 : : {
342 : 0 : bDisplay = sal_False;
343 : : }
344 : : }
345 : :
346 [ # # ]: 0 : if ( !bDisplay )
347 : 0 : continue;
348 : :
349 [ # # ][ # # ]: 0 : if ( children[n]->getType() == browse::BrowseNodeTypes::SCRIPT )
[ # # ][ # # ]
350 : 0 : continue;
351 : :
352 [ # # ][ # # ]: 0 : SvLBoxEntry* pNewEntry = InsertEntry( sUIName, _pParentEntry );
[ # # ]
353 : :
354 [ # # ][ # # ]: 0 : ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
355 [ # # ][ # # ]: 0 : Image aImage = GetImage( theChild, aContext.getUNOContext(), bIsRootNode );
356 [ # # ]: 0 : SetExpandedEntryBmp( pNewEntry, aImage );
357 [ # # ]: 0 : SetCollapsedEntryBmp( pNewEntry, aImage );
358 : :
359 : : SvxGroupInfo_Impl* pInfo =
360 [ # # ][ # # ]: 0 : new SvxGroupInfo_Impl( SVX_CFGGROUP_SCRIPTCONTAINER, 0, theChild );
361 : 0 : pNewEntry->SetUserData( pInfo );
362 [ # # ]: 0 : aArr.push_back( pInfo );
363 : :
364 [ # # ]: 0 : if ( _bCheapChildrenOnDemand )
365 : : {
366 : : /* i30923 - Would be nice if there was a better
367 : : * way to determine if a basic lib had children
368 : : * without having to ask for them (which forces
369 : : * the library to be loaded */
370 [ # # ]: 0 : pNewEntry->EnableChildrenOnDemand( sal_True );
371 : : }
372 : : else
373 : : {
374 : : // if there are granchildren we're interested in, display the '+' before
375 : : // the entry, but do not yet expand
376 : : Sequence< Reference< browse::XBrowseNode > > grandchildren =
377 [ # # ][ # # ]: 0 : children[n]->getChildNodes();
[ # # ]
378 : :
379 [ # # ]: 0 : for ( sal_Int32 m = 0; m < grandchildren.getLength(); ++m )
380 : : {
381 [ # # ][ # # ]: 0 : if ( grandchildren[m]->getType() == browse::BrowseNodeTypes::CONTAINER )
[ # # ][ # # ]
382 : : {
383 [ # # ]: 0 : pNewEntry->EnableChildrenOnDemand( sal_True );
384 : 0 : break;
385 : : }
386 [ # # ]: 0 : }
387 : : }
388 [ # # ][ # # ]: 0 : }
[ # # ][ # # ]
[ # # ]
389 : : }
390 : : }
391 : 0 : catch (const Exception&)
392 : : {
393 : : DBG_UNHANDLED_EXCEPTION();
394 : : }
395 : : }
396 : :
397 : 0 : void SvxConfigGroupListBox_Impl::Init()
398 : : {
399 [ # # ]: 0 : SetUpdateMode(sal_False);
400 [ # # ]: 0 : ClearAll();
401 : :
402 : 0 : Reference< XComponentContext > xContext;
403 : : Reference < beans::XPropertySet > xProps(
404 [ # # ][ # # ]: 0 : ::comphelper::getProcessServiceFactory(), UNO_QUERY_THROW );
405 : :
406 [ # # ]: 0 : xContext.set( xProps->getPropertyValue(
407 : 0 : rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))),
408 [ # # ][ # # ]: 0 : UNO_QUERY );
[ # # ]
409 : :
410 : : // are we showing builtin commands?
411 [ # # ][ # # ]: 0 : if ( m_bShowSlots && xContext.is() && m_xFrame.is() )
[ # # ][ # # ]
412 : : {
413 : : Reference< lang::XMultiComponentFactory > xMCF =
414 [ # # ][ # # ]: 0 : xContext->getServiceManager();
415 : :
416 : : Reference< frame::XDispatchInformationProvider > xDIP(
417 [ # # ]: 0 : m_xFrame, UNO_QUERY );
418 : :
419 : : Reference< ::com::sun::star::frame::XModuleManager >
420 [ # # ]: 0 : xModuleManager( xMCF->createInstanceWithContext(
421 : : OUString(RTL_CONSTASCII_USTRINGPARAM(
422 : : "com.sun.star.frame.ModuleManager" )),
423 : 0 : xContext ),
424 [ # # ][ # # ]: 0 : UNO_QUERY );
[ # # ][ # # ]
425 : :
426 : 0 : OUString aModuleId;
427 : : try{
428 [ # # ][ # # ]: 0 : aModuleId = xModuleManager->identify( m_xFrame );
429 [ # # ]: 0 : }catch(const uno::Exception&)
430 : 0 : { aModuleId = ::rtl::OUString(); }
431 : :
432 : : Reference< container::XNameAccess > xNameAccess(
433 [ # # ]: 0 : xMCF->createInstanceWithContext(
434 : : OUString(RTL_CONSTASCII_USTRINGPARAM(
435 : : "com.sun.star.frame.UICommandDescription" )),
436 : 0 : xContext ),
437 [ # # ][ # # ]: 0 : UNO_QUERY );
[ # # ]
438 : :
439 [ # # ]: 0 : if ( xNameAccess.is() )
440 : : {
441 [ # # ][ # # ]: 0 : xNameAccess->getByName( aModuleId ) >>= m_xModuleCommands;
[ # # ]
442 : : }
443 : :
444 : : Reference< container::XNameAccess > xAllCategories(
445 [ # # ]: 0 : xMCF->createInstanceWithContext(
446 : : OUString(RTL_CONSTASCII_USTRINGPARAM(
447 : : "com.sun.star.ui.UICategoryDescription" )),
448 : 0 : xContext ),
449 [ # # ][ # # ]: 0 : UNO_QUERY );
[ # # ]
450 : :
451 : 0 : Reference< container::XNameAccess > xModuleCategories;
452 [ # # ]: 0 : if ( xAllCategories.is() )
453 : : {
454 [ # # ]: 0 : if ( !aModuleId.isEmpty() )
455 : : {
456 : : try
457 : : {
458 : : xModuleCategories = Reference< container::XNameAccess >(
459 [ # # ][ # # ]: 0 : xAllCategories->getByName( aModuleId ), UNO_QUERY );
[ # # ][ # # ]
[ # # ]
460 : : }
461 [ # # ]: 0 : catch ( container::NoSuchElementException& )
462 : : {
463 : : }
464 : : }
465 : :
466 [ # # ]: 0 : if ( !xModuleCategories.is() )
467 : : {
468 [ # # ]: 0 : xModuleCategories = xAllCategories;
469 : : }
470 : : }
471 : :
472 [ # # ]: 0 : if ( xModuleCategories.is() )
473 : : {
474 : : Sequence< sal_Int16 > gids =
475 [ # # ][ # # ]: 0 : xDIP->getSupportedCommandGroups();
476 : :
477 [ # # ]: 0 : for ( sal_Int32 i = 0; i < gids.getLength(); ++i )
478 : : {
479 [ # # ]: 0 : Sequence< frame::DispatchInformation > commands;
480 : : try
481 : : {
482 : : commands =
483 [ # # ][ # # ]: 0 : xDIP->getConfigurableDispatchInformation( gids[i] );
[ # # ][ # # ]
[ # # # # ]
484 : : }
485 [ # # # # ]: 0 : catch ( container::NoSuchElementException& )
486 : : {
487 : 0 : continue;
488 : : }
489 : :
490 [ # # ]: 0 : if ( commands.getLength() == 0 )
491 : : {
492 : 0 : continue;
493 : : }
494 : :
495 [ # # ]: 0 : sal_Int32 gid = gids[i];
496 : 0 : OUString idx = OUString::valueOf( gid );
497 : 0 : OUString group = idx;
498 : : try
499 : : {
500 [ # # ][ # # ]: 0 : xModuleCategories->getByName( idx ) >>= group;
501 : : }
502 [ # # ]: 0 : catch ( container::NoSuchElementException& )
503 : : {
504 : : }
505 : :
506 [ # # ][ # # ]: 0 : SvLBoxEntry *pEntry = InsertEntry( group, NULL );
[ # # ]
507 : :
508 : : SvxGroupInfo_Impl *pInfo =
509 [ # # ][ # # ]: 0 : new SvxGroupInfo_Impl( SVX_CFGGROUP_FUNCTION, gids[i] );
[ # # ]
510 [ # # ]: 0 : aArr.push_back( pInfo );
511 : :
512 : 0 : pEntry->SetUserData( pInfo );
513 [ # # ][ # # ]: 0 : }
[ # # ]
514 : 0 : }
515 : : }
516 : :
517 [ # # ]: 0 : if ( xContext.is() )
518 : : {
519 : : // Add Scripting Framework entries
520 : 0 : Reference< browse::XBrowseNode > rootNode;
521 : 0 : Reference< XComponentContext> xCtx;
522 : :
523 : : try
524 : : {
525 : : Reference < beans::XPropertySet > _xProps(
526 [ # # ][ # # ]: 0 : ::comphelper::getProcessServiceFactory(), UNO_QUERY_THROW );
527 [ # # ][ # # ]: 0 : xCtx.set( _xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), UNO_QUERY_THROW );
[ # # ][ # # ]
528 [ # # ]: 0 : Reference< browse::XBrowseNodeFactory > xFac( xCtx->getValueByName(
529 [ # # ][ # # ]: 0 : OUString(RTL_CONSTASCII_USTRINGPARAM( "/singletons/com.sun.star.script.browse.theBrowseNodeFactory")) ), UNO_QUERY_THROW );
[ # # ]
530 [ # # ][ # # ]: 0 : rootNode.set( xFac->createView( browse::BrowseNodeFactoryViewTypes::MACROSELECTOR ) );
[ # # ][ # # ]
531 : : }
532 [ # # ]: 0 : catch( const Exception& )
533 : : {
534 : : DBG_UNHANDLED_EXCEPTION();
535 : : }
536 : :
537 [ # # ]: 0 : if ( rootNode.is() )
538 : : {
539 [ # # ]: 0 : if ( m_bShowSlots )
540 : : {
541 : : SvxGroupInfo_Impl *pInfo =
542 [ # # ][ # # ]: 0 : new SvxGroupInfo_Impl( SVX_CFGGROUP_SCRIPTCONTAINER, 0, rootNode );
543 : :
544 : : String aTitle =
545 [ # # ][ # # ]: 0 : String( CUI_RES( STR_SELECTOR_MACROS ) );
546 : :
547 [ # # ]: 0 : SvLBoxEntry *pNewEntry = InsertEntry( aTitle, NULL );
548 : 0 : pNewEntry->SetUserData( pInfo );
549 [ # # ]: 0 : pNewEntry->EnableChildrenOnDemand( sal_True );
550 [ # # ][ # # ]: 0 : aArr.push_back( pInfo );
551 : : }
552 : : else
553 : : {
554 [ # # ]: 0 : fillScriptList( rootNode, NULL, false );
555 : : }
556 : 0 : }
557 : : }
558 [ # # ][ # # ]: 0 : MakeVisible( GetEntry( 0,0 ) );
559 [ # # ]: 0 : SetUpdateMode( sal_True );
560 : 0 : }
561 : :
562 : 0 : Image SvxConfigGroupListBox_Impl::GetImage(
563 : : Reference< browse::XBrowseNode > node,
564 : : Reference< XComponentContext > xCtx,
565 : : bool bIsRootNode
566 : : )
567 : : {
568 : 0 : Image aImage;
569 [ # # ]: 0 : if ( bIsRootNode )
570 : : {
571 [ # # ][ # # ]: 0 : if ( node->getName() == "user" || node->getName() == "share" )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # #
# # ]
572 : : {
573 [ # # ]: 0 : aImage = m_hdImage;
574 : : }
575 : : else
576 : : {
577 : 0 : OUString factoryURL;
578 [ # # ][ # # ]: 0 : OUString nodeName = node->getName();
579 [ # # ]: 0 : Reference<XInterface> xDocumentModel = getDocumentModel(xCtx, nodeName );
580 [ # # ]: 0 : if ( xDocumentModel.is() )
581 : : {
582 : : Reference< ::com::sun::star::frame::XModuleManager >
583 : : xModuleManager(
584 [ # # ]: 0 : xCtx->getServiceManager()
585 [ # # ][ # # ]: 0 : ->createInstanceWithContext(
586 : : OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.ModuleManager")),
587 : 0 : xCtx ),
588 [ # # ][ # # ]: 0 : UNO_QUERY_THROW );
[ # # ]
589 : : Reference<container::XNameAccess> xModuleConfig(
590 [ # # ]: 0 : xModuleManager, UNO_QUERY_THROW );
591 : : // get the long name of the document:
592 [ # # ]: 0 : OUString appModule( xModuleManager->identify(
593 [ # # ]: 0 : xDocumentModel ) );
594 [ # # ]: 0 : Sequence<beans::PropertyValue> moduleDescr;
595 [ # # ][ # # ]: 0 : Any aAny = xModuleConfig->getByName(appModule);
596 [ # # ][ # # ]: 0 : if( sal_True != ( aAny >>= moduleDescr ) )
597 : : {
598 [ # # ][ # # ]: 0 : throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("SFTreeListBox::Init: failed to get PropertyValue")), Reference< XInterface >());
599 : : }
600 : : beans::PropertyValue const * pmoduleDescr =
601 : 0 : moduleDescr.getConstArray();
602 [ # # ]: 0 : for ( sal_Int32 pos = moduleDescr.getLength(); pos--; )
603 : : {
604 [ # # ]: 0 : if ( pmoduleDescr[ pos ].Name == "ooSetupFactoryEmptyDocumentURL" )
605 : : {
606 : 0 : pmoduleDescr[ pos ].Value >>= factoryURL;
607 : 0 : break;
608 : : }
609 [ # # ]: 0 : }
610 : : }
611 [ # # ]: 0 : if( !factoryURL.isEmpty() )
612 : : {
613 [ # # ][ # # ]: 0 : aImage = SvFileInformationManager::GetFileImage( INetURLObject(factoryURL), false );
[ # # ][ # # ]
[ # # ]
614 : : }
615 : : else
616 : : {
617 [ # # ]: 0 : aImage = m_docImage;
618 : 0 : }
619 : : }
620 : : }
621 : : else
622 : : {
623 [ # # ][ # # ]: 0 : if( node->getType() == browse::BrowseNodeTypes::SCRIPT )
[ # # ]
624 [ # # ]: 0 : aImage = m_macImage;
625 : : else
626 [ # # ]: 0 : aImage = m_libImage;
627 : : }
628 : 0 : return aImage;
629 : : }
630 : :
631 : : Reference< XInterface >
632 : 0 : SvxConfigGroupListBox_Impl::getDocumentModel(
633 : : Reference< XComponentContext >& xCtx, OUString& docName )
634 : : {
635 : 0 : Reference< XInterface > xModel;
636 : : Reference< lang::XMultiComponentFactory > mcf =
637 [ # # ][ # # ]: 0 : xCtx->getServiceManager();
638 : : Reference< frame::XDesktop > desktop (
639 [ # # ]: 0 : mcf->createInstanceWithContext(
640 : 0 : OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop")), xCtx ),
641 [ # # ][ # # ]: 0 : UNO_QUERY );
[ # # ]
642 : :
643 : : Reference< container::XEnumerationAccess > componentsAccess =
644 [ # # ][ # # ]: 0 : desktop->getComponents();
645 : : Reference< container::XEnumeration > components =
646 [ # # ][ # # ]: 0 : componentsAccess->createEnumeration();
647 [ # # ][ # # ]: 0 : while (components->hasMoreElements())
[ # # ]
648 : : {
649 : : Reference< frame::XModel > model(
650 [ # # ][ # # ]: 0 : components->nextElement(), UNO_QUERY );
[ # # ]
651 [ # # ]: 0 : if ( model.is() )
652 : : {
653 [ # # ]: 0 : OUString sTdocUrl = ::comphelper::DocumentInfo::getDocumentTitle( model );
654 [ # # ]: 0 : if( sTdocUrl.equals( docName ) )
655 : : {
656 [ # # ]: 0 : xModel = model;
657 : : break;
658 [ # # ]: 0 : }
659 : : }
660 [ # # ]: 0 : }
661 : 0 : return xModel;
662 : : }
663 : :
664 : 0 : void SvxConfigGroupListBox_Impl::GroupSelected()
665 : : {
666 : 0 : SvLBoxEntry *pEntry = FirstSelected();
667 : 0 : SvxGroupInfo_Impl *pInfo = (SvxGroupInfo_Impl*) pEntry->GetUserData();
668 : 0 : pFunctionListBox->SetUpdateMode(sal_False);
669 : 0 : pFunctionListBox->ClearAll();
670 [ # # ][ # # ]: 0 : if ( pInfo->nKind != SVX_CFGGROUP_FUNCTION &&
671 : : pInfo->nKind != SVX_CFGGROUP_SCRIPTCONTAINER )
672 : : {
673 : 0 : pFunctionListBox->SetUpdateMode(sal_True);
674 : 0 : return;
675 : : }
676 : :
677 [ # # # ]: 0 : switch ( pInfo->nKind )
678 : : {
679 : : case SVX_CFGGROUP_FUNCTION :
680 : : {
681 : 0 : SvLBoxEntry *_pEntry = FirstSelected();
682 [ # # ]: 0 : if ( _pEntry != NULL )
683 : : {
684 : : SvxGroupInfo_Impl *_pInfo =
685 : 0 : (SvxGroupInfo_Impl*) _pEntry->GetUserData();
686 : :
687 : : Reference< frame::XDispatchInformationProvider > xDIP(
688 [ # # ]: 0 : m_xFrame, UNO_QUERY );
689 : :
690 [ # # ]: 0 : Sequence< frame::DispatchInformation > commands;
691 : : try
692 : : {
693 [ # # ]: 0 : commands = xDIP->getConfigurableDispatchInformation(
694 [ # # ][ # # ]: 0 : _pInfo->nOrd );
[ # # ][ # # ]
695 : : }
696 [ # # ]: 0 : catch ( container::NoSuchElementException& )
697 : : {
698 : : }
699 : :
700 [ # # ]: 0 : for ( sal_Int32 i = 0; i < commands.getLength(); ++i )
701 : : {
702 [ # # ][ # # ]: 0 : if ( commands[i].Command.isEmpty() )
703 : : {
704 : 0 : continue;
705 : : }
706 : :
707 [ # # ]: 0 : Image aImage;
708 : :
709 [ # # ]: 0 : OUString aCmdURL( commands[i].Command );
710 : :
711 [ # # ]: 0 : if ( m_pImageProvider )
712 : : {
713 [ # # ][ # # ]: 0 : aImage = m_pImageProvider->GetImage( aCmdURL );
[ # # ]
714 : : }
715 : :
716 : 0 : OUString aLabel;
717 : : try
718 : : {
719 [ # # ][ # # ]: 0 : Any a = m_xModuleCommands->getByName( aCmdURL );
720 [ # # ]: 0 : Sequence< beans::PropertyValue > aPropSeq;
721 : :
722 [ # # ][ # # ]: 0 : if ( a >>= aPropSeq )
723 : : {
724 [ # # ]: 0 : for ( sal_Int32 k = 0; k < aPropSeq.getLength(); ++k )
725 : : {
726 [ # # ][ # # ]: 0 : if ( aPropSeq[k].Name == "Name" )
727 : : {
728 [ # # ]: 0 : aPropSeq[k].Value >>= aLabel;
729 : 0 : break;
730 : : }
731 : : }
732 [ # # ][ # # ]: 0 : }
733 : : }
734 [ # # ]: 0 : catch ( container::NoSuchElementException& )
735 : : {
736 : : }
737 : :
738 [ # # ]: 0 : if ( aLabel.isEmpty() )
739 : : {
740 [ # # ]: 0 : aLabel = commands[i].Command;
741 : : }
742 : :
743 : 0 : SvLBoxEntry* pFuncEntry = NULL;
744 [ # # ]: 0 : if ( !!aImage )
745 : : {
746 : : pFuncEntry = pFunctionListBox->InsertEntry(
747 [ # # ][ # # ]: 0 : aLabel, aImage, aImage );
[ # # ]
748 : : }
749 : : else
750 : : {
751 : : pFuncEntry = pFunctionListBox->InsertEntry(
752 [ # # ][ # # ]: 0 : aLabel, NULL );
[ # # ]
753 : : }
754 : :
755 : : SvxGroupInfo_Impl *_pGroupInfo = new SvxGroupInfo_Impl(
756 [ # # ][ # # ]: 0 : SVX_CFGFUNCTION_SLOT, 123, aCmdURL, ::rtl::OUString() );
757 : :
758 [ # # ]: 0 : pFunctionListBox->aArr.push_back( _pGroupInfo );
759 : :
760 : 0 : pFuncEntry->SetUserData( _pGroupInfo );
761 [ # # ][ # # ]: 0 : }
762 : : }
763 : 0 : break;
764 : : }
765 : :
766 : : case SVX_CFGGROUP_SCRIPTCONTAINER:
767 : : {
768 : 0 : Reference< browse::XBrowseNode > rootNode( pInfo->xBrowseNode );
769 : :
770 : : try {
771 [ # # ][ # # ]: 0 : if ( rootNode->hasChildNodes() )
[ # # ]
772 : : {
773 : : Sequence< Reference< browse::XBrowseNode > > children =
774 [ # # ][ # # ]: 0 : rootNode->getChildNodes();
775 : :
776 [ # # ]: 0 : for ( sal_Int32 n = 0; n < children.getLength(); ++n )
777 : : {
778 [ # # ][ # # ]: 0 : if (!children[n].is())
779 : 0 : continue;
780 [ # # ][ # # ]: 0 : if (children[n]->getType() == browse::BrowseNodeTypes::SCRIPT)
[ # # ][ # # ]
781 : : {
782 : 0 : OUString uri;
783 : 0 : OUString description;
784 : :
785 [ # # ][ # # ]: 0 : Reference < beans::XPropertySet >xPropSet( children[n], UNO_QUERY );
786 [ # # ]: 0 : if (!xPropSet.is())
787 : : {
788 : 0 : continue;
789 : : }
790 : :
791 [ # # ]: 0 : Any value = xPropSet->getPropertyValue(
792 [ # # ][ # # ]: 0 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("URI")));
793 : 0 : value >>= uri;
794 : :
795 : : try
796 : : {
797 [ # # ]: 0 : value = xPropSet->getPropertyValue(
798 [ # # ][ # # ]: 0 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Description")));
[ # # ]
799 : 0 : value >>= description;
800 : : }
801 [ # # ]: 0 : catch (Exception &) {
802 : : // do nothing, the description will be empty
803 : : }
804 : :
805 : : SvxGroupInfo_Impl* _pGroupInfo =
806 : : new SvxGroupInfo_Impl(
807 [ # # ][ # # ]: 0 : SVX_CFGFUNCTION_SCRIPT, 123, uri, description );
808 : :
809 [ # # ][ # # ]: 0 : Image aImage = GetImage( children[n], Reference< XComponentContext >(), sal_False );
810 : : SvLBoxEntry* pNewEntry =
811 [ # # ][ # # ]: 0 : pFunctionListBox->InsertEntry( children[n]->getName(), NULL );
[ # # ][ # # ]
[ # # ][ # # ]
812 [ # # ]: 0 : pFunctionListBox->SetExpandedEntryBmp( pNewEntry, aImage );
813 [ # # ]: 0 : pFunctionListBox->SetCollapsedEntryBmp(pNewEntry, aImage );
814 : :
815 : 0 : pNewEntry->SetUserData( _pGroupInfo );
816 : :
817 [ # # ][ # # ]: 0 : pFunctionListBox->aArr.push_back( _pGroupInfo );
[ # # ][ # # ]
[ # # ]
818 : :
819 : : }
820 [ # # ][ # # ]: 0 : }
821 : : }
822 : : }
823 [ # # ]: 0 : catch (const Exception&)
824 : : {
825 : : DBG_UNHANDLED_EXCEPTION();
826 : : }
827 : 0 : break;
828 : : }
829 : :
830 : : default:
831 : : {
832 : 0 : return;
833 : : }
834 : : }
835 : :
836 [ # # ]: 0 : if ( pFunctionListBox->GetEntryCount() )
837 : 0 : pFunctionListBox->Select( pFunctionListBox->GetEntry( 0, 0 ) );
838 : :
839 : 0 : pFunctionListBox->SetUpdateMode(sal_True);
840 : : }
841 : :
842 : 0 : sal_Bool SvxConfigGroupListBox_Impl::Expand( SvLBoxEntry* pParent )
843 : : {
844 : 0 : sal_Bool bRet = SvTreeListBox::Expand( pParent );
845 [ # # ]: 0 : if ( bRet )
846 : : {
847 : 0 : sal_uLong nEntries = GetOutputSizePixel().Height() / GetEntryHeight();
848 : :
849 : 0 : sal_uLong nChildCount = GetVisibleChildCount( pParent );
850 : :
851 [ # # ]: 0 : if ( nChildCount+1 > nEntries )
852 : : {
853 : 0 : MakeVisible( pParent, sal_True );
854 : : }
855 : : else
856 : : {
857 : 0 : SvLBoxEntry *pEntry = GetFirstEntryInView();
858 : 0 : sal_uLong nParentPos = 0;
859 [ # # ][ # # ]: 0 : while ( pEntry && pEntry != pParent )
[ # # ]
860 : : {
861 : 0 : ++nParentPos;
862 : 0 : pEntry = GetNextEntryInView( pEntry );
863 : : }
864 : :
865 [ # # ]: 0 : if ( nParentPos + nChildCount + 1 > nEntries )
866 : 0 : ScrollOutputArea( (short)( nEntries - ( nParentPos + nChildCount + 1 ) ) );
867 : : }
868 : : }
869 : :
870 : 0 : return bRet;
871 : : }
872 : :
873 : 0 : void SvxConfigGroupListBox_Impl::RequestingChildren( SvLBoxEntry *pEntry )
874 : : {
875 : 0 : SvxGroupInfo_Impl *pInfo = (SvxGroupInfo_Impl*) pEntry->GetUserData();
876 : 0 : pInfo->bWasOpened = sal_True;
877 [ # # ]: 0 : switch ( pInfo->nKind )
878 : : {
879 : : case SVX_CFGGROUP_SCRIPTCONTAINER:
880 : : {
881 [ # # ]: 0 : if ( !GetChildCount( pEntry ) )
882 : : {
883 : 0 : Reference< browse::XBrowseNode > rootNode( pInfo->xBrowseNode ) ;
884 [ # # ]: 0 : fillScriptList( rootNode, pEntry, true /* i30923 */ );
885 : : }
886 : 0 : break;
887 : : }
888 : :
889 : : default:
890 : : OSL_FAIL( "Falscher Gruppentyp!" );
891 : 0 : break;
892 : : }
893 : 0 : }
894 : :
895 : : /*
896 : : * Implementation of SvxScriptSelectorDialog
897 : : *
898 : : * This dialog is used for selecting Slot API commands
899 : : * and Scripting Framework Scripts.
900 : : */
901 : :
902 : 0 : SvxScriptSelectorDialog::SvxScriptSelectorDialog(
903 : : Window* pParent, sal_Bool bShowSlots, const Reference< frame::XFrame >& xFrame )
904 : : :
905 : 0 : ModelessDialog( pParent, CUI_RES( RID_DLG_SCRIPTSELECTOR ) ),
906 [ # # ]: 0 : aDialogDescription( this, CUI_RES( TXT_SELECTOR_DIALOG_DESCRIPTION ) ),
907 [ # # ]: 0 : aGroupText( this, CUI_RES( TXT_SELECTOR_CATEGORIES ) ),
908 [ # # ]: 0 : aCategories( this, CUI_RES( BOX_SELECTOR_CATEGORIES ), bShowSlots, xFrame ),
909 [ # # ]: 0 : aFunctionText( this, CUI_RES( TXT_SELECTOR_COMMANDS ) ),
910 [ # # ]: 0 : aCommands( this, CUI_RES( BOX_SELECTOR_COMMANDS ) ),
911 [ # # ]: 0 : aOKButton( this, CUI_RES( BTN_SELECTOR_OK ) ),
912 [ # # ]: 0 : aCancelButton( this, CUI_RES( BTN_SELECTOR_CANCEL ) ),
913 [ # # ]: 0 : aHelpButton( this, CUI_RES( BTN_SELECTOR_HELP ) ),
914 [ # # ]: 0 : aDescription( this, CUI_RES( GRP_SELECTOR_DESCRIPTION ) ),
915 [ # # ]: 0 : aDescriptionText( this, CUI_RES( TXT_SELECTOR_DESCRIPTION ) ),
916 [ # # ][ # # ]: 0 : m_bShowSlots( bShowSlots )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
917 : : {
918 : :
919 [ # # ]: 0 : ResMgr& rMgr = CUI_MGR();
920 : :
921 : : // If we are showing Slot API commands update labels in the UI, and
922 : : // enable drag'n'drop
923 [ # # ]: 0 : if ( m_bShowSlots )
924 : : {
925 [ # # ][ # # ]: 0 : aGroupText.SetText( String( ResId( STR_SELECTOR_CATEGORIES, rMgr ) ) );
[ # # ]
926 [ # # ][ # # ]: 0 : aOKButton.SetText( String( ResId( STR_SELECTOR_ADD, rMgr ) ) );
[ # # ]
927 [ # # ][ # # ]: 0 : aCancelButton.SetText( String( ResId( STR_SELECTOR_CLOSE, rMgr ) ) );
[ # # ]
928 [ # # ][ # # ]: 0 : aFunctionText.SetText( String( ResId( STR_SELECTOR_COMMANDS, rMgr ) ) );
[ # # ]
929 : : SetDialogDescription(
930 [ # # ][ # # ]: 0 : String( ResId( STR_SELECTOR_ADD_COMMANDS_DESCRIPTION, rMgr ) ) );
[ # # ]
931 [ # # ][ # # ]: 0 : SetText( String( ResId( STR_SELECTOR_ADD_COMMANDS, rMgr ) ) );
[ # # ]
932 : :
933 [ # # ]: 0 : aCommands.SetDragDropMode( SV_DRAGDROP_APP_COPY );
934 : : }
935 : :
936 [ # # ]: 0 : ResizeControls();
937 : :
938 : 0 : aCategories.SetFunctionListBox( &aCommands );
939 [ # # ]: 0 : aCategories.Init();
940 : :
941 : : aCategories.SetSelectHdl(
942 [ # # ]: 0 : LINK( this, SvxScriptSelectorDialog, SelectHdl ) );
943 [ # # ]: 0 : aCommands.SetSelectHdl( LINK( this, SvxScriptSelectorDialog, SelectHdl ) );
944 [ # # ]: 0 : aCommands.SetDoubleClickHdl( LINK( this, SvxScriptSelectorDialog, FunctionDoubleClickHdl ) );
945 : :
946 [ # # ]: 0 : aOKButton.SetClickHdl( LINK( this, SvxScriptSelectorDialog, ClickHdl ) );
947 [ # # ]: 0 : aCancelButton.SetClickHdl( LINK( this, SvxScriptSelectorDialog, ClickHdl ) );
948 : :
949 [ # # ]: 0 : UpdateUI();
950 [ # # ]: 0 : FreeResource();
951 : 0 : }
952 : :
953 : 0 : void SvxScriptSelectorDialog::ResizeControls()
954 : : {
955 : 0 : Point p, newp;
956 : 0 : Size s, news;
957 : : long gap;
958 : :
959 : : sal_uInt16 style = TEXT_DRAW_MULTILINE | TEXT_DRAW_TOP |
960 : 0 : TEXT_DRAW_LEFT | TEXT_DRAW_WORDBREAK;
961 : :
962 : : // get dimensions of dialog instructions control
963 [ # # ]: 0 : p = aDialogDescription.GetPosPixel();
964 [ # # ]: 0 : s = aDialogDescription.GetSizePixel();
965 : :
966 : : // get dimensions occupied by text in the control
967 : : Rectangle rect =
968 [ # # ][ # # ]: 0 : GetTextRect( Rectangle( p, s ), aDialogDescription.GetText(), style );
[ # # ][ # # ]
969 [ # # ]: 0 : news = rect.GetSize();
970 : :
971 : : // the gap is the difference between the control height and its text height
972 : 0 : gap = s.Height() - news.Height();
973 : :
974 : : // resize the dialog instructions control
975 : 0 : news = Size( s.Width(), s.Height() - gap );
976 [ # # ]: 0 : aDialogDescription.SetSizePixel( news );
977 : :
978 : : // resize other controls to fill the gap
979 [ # # ]: 0 : p = aGroupText.GetPosPixel();
980 : 0 : newp = Point( p.X(), p.Y() - gap );
981 [ # # ]: 0 : aGroupText.SetPosPixel( newp );
982 : :
983 [ # # ]: 0 : p = aCategories.GetPosPixel();
984 : 0 : newp = Point( p.X(), p.Y() - gap );
985 [ # # ]: 0 : aCategories.SetPosPixel( newp );
986 [ # # ]: 0 : s = aCategories.GetSizePixel();
987 : 0 : news = Size( s.Width(), s.Height() + gap );
988 [ # # ]: 0 : aCategories.SetSizePixel( news );
989 : :
990 [ # # ]: 0 : p = aFunctionText.GetPosPixel();
991 : 0 : newp = Point( p.X(), p.Y() - gap );
992 [ # # ]: 0 : aFunctionText.SetPosPixel( newp );
993 : :
994 [ # # ]: 0 : p = aCommands.GetPosPixel();
995 : 0 : newp = Point( p.X(), p.Y() - gap );
996 [ # # ]: 0 : aCommands.SetPosPixel( newp );
997 [ # # ]: 0 : s = aCommands.GetSizePixel();
998 : 0 : news = Size( s.Width(), s.Height() + gap );
999 [ # # ]: 0 : aCommands.SetSizePixel( news );
1000 : :
1001 [ # # ]: 0 : p = aOKButton.GetPosPixel();
1002 : 0 : newp = Point( p.X(), p.Y() - gap );
1003 [ # # ]: 0 : aOKButton.SetPosPixel( newp );
1004 : :
1005 [ # # ]: 0 : p = aCancelButton.GetPosPixel();
1006 : 0 : newp = Point( p.X(), p.Y() - gap );
1007 [ # # ]: 0 : aCancelButton.SetPosPixel( newp );
1008 : :
1009 [ # # ]: 0 : p = aHelpButton.GetPosPixel();
1010 : 0 : newp = Point( p.X(), p.Y() - gap );
1011 [ # # ]: 0 : aHelpButton.SetPosPixel( newp );
1012 : 0 : }
1013 : :
1014 [ # # ][ # # ]: 0 : SvxScriptSelectorDialog::~SvxScriptSelectorDialog()
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
1015 : : {
1016 [ # # ]: 0 : }
1017 : :
1018 : 0 : IMPL_LINK( SvxScriptSelectorDialog, SelectHdl, Control*, pCtrl )
1019 : : {
1020 [ # # ]: 0 : if ( pCtrl == &aCategories )
1021 : : {
1022 : 0 : aCategories.GroupSelected();
1023 : : }
1024 [ # # ]: 0 : else if ( pCtrl == &aCommands )
1025 : : {
1026 : 0 : aCommands.FunctionSelected();
1027 : : }
1028 : 0 : UpdateUI();
1029 : 0 : return 0;
1030 : : }
1031 : :
1032 : 0 : IMPL_LINK( SvxScriptSelectorDialog, FunctionDoubleClickHdl, Control*, pCtrl )
1033 : : {
1034 : : (void)pCtrl;
1035 [ # # ]: 0 : if ( aOKButton.IsEnabled() )
1036 : 0 : return ClickHdl( &aOKButton );
1037 : 0 : return 0;
1038 : : }
1039 : :
1040 : : // Check if command is selected and enable the OK button accordingly
1041 : : // Grab the help text for this id if available and update the description field
1042 : : void
1043 : 0 : SvxScriptSelectorDialog::UpdateUI()
1044 : : {
1045 [ # # ][ # # ]: 0 : OUString url = GetScriptURL();
[ # # ]
1046 [ # # ][ # # ]: 0 : if ( url != NULL && !url.isEmpty() )
[ # # ]
1047 : : {
1048 : : String rMessage =
1049 [ # # ][ # # ]: 0 : aCommands.GetHelpText( aCommands.FirstSelected() );
1050 [ # # ]: 0 : aDescriptionText.SetText( rMessage );
1051 : :
1052 [ # # ][ # # ]: 0 : aOKButton.Enable( sal_True );
1053 : : }
1054 : : else
1055 : : {
1056 [ # # ][ # # ]: 0 : aDescriptionText.SetText( String() );
[ # # ]
1057 [ # # ]: 0 : aOKButton.Enable( sal_False );
1058 : 0 : }
1059 : 0 : }
1060 : :
1061 : 0 : IMPL_LINK( SvxScriptSelectorDialog, ClickHdl, Button *, pButton )
1062 : : {
1063 [ # # ]: 0 : if ( pButton == &aCancelButton )
1064 : : {
1065 : : // If we are displaying Slot API commands then the dialog is being
1066 : : // run from Tools/Configure and we should not close it, just hide it
1067 [ # # ]: 0 : if ( m_bShowSlots == sal_False )
1068 : : {
1069 : 0 : EndDialog( RET_CANCEL );
1070 : : }
1071 : : else
1072 : : {
1073 : 0 : Hide();
1074 : : }
1075 : : }
1076 [ # # ]: 0 : else if ( pButton == &aOKButton )
1077 : : {
1078 : 0 : GetAddHdl().Call( this );
1079 : :
1080 : : // If we are displaying Slot API commands then this the dialog is being
1081 : : // run from Tools/Configure and we should not close it
1082 [ # # ]: 0 : if ( m_bShowSlots == sal_False )
1083 : : {
1084 : 0 : EndDialog( RET_OK );
1085 : : }
1086 : : else
1087 : : {
1088 : : // Select the next entry in the list if possible
1089 : 0 : SvLBoxEntry* current = aCommands.FirstSelected();
1090 : 0 : SvLBoxEntry* next = aCommands.NextSibling( current );
1091 : :
1092 [ # # ]: 0 : if ( next != NULL )
1093 : : {
1094 : 0 : aCommands.Select( next );
1095 : : }
1096 : : }
1097 : : }
1098 : :
1099 : 0 : return 0;
1100 : : }
1101 : :
1102 : : void
1103 : 0 : SvxScriptSelectorDialog::SetRunLabel()
1104 : : {
1105 [ # # ][ # # ]: 0 : aOKButton.SetText( String( CUI_RES( STR_SELECTOR_RUN ) ) );
[ # # ]
1106 : 0 : }
1107 : :
1108 : : void
1109 : 0 : SvxScriptSelectorDialog::SetDialogDescription( const String& rDescription )
1110 : : {
1111 : 0 : aDialogDescription.SetText( rDescription );
1112 : 0 : }
1113 : :
1114 : : String
1115 : 0 : SvxScriptSelectorDialog::GetScriptURL() const
1116 : : {
1117 : 0 : OUString result;
1118 : :
1119 [ # # ]: 0 : SvLBoxEntry *pEntry = const_cast< SvxScriptSelectorDialog* >( this )->aCommands.GetLastSelectedEntry();
1120 [ # # ]: 0 : if ( pEntry )
1121 : : {
1122 : 0 : SvxGroupInfo_Impl *pData = (SvxGroupInfo_Impl*) pEntry->GetUserData();
1123 [ # # ][ # # ]: 0 : if ( ( pData->nKind == SVX_CFGFUNCTION_SLOT )
1124 : : || ( pData->nKind == SVX_CFGFUNCTION_SCRIPT )
1125 : : )
1126 : : {
1127 : 0 : result = pData->sURL;
1128 : : }
1129 : : }
1130 : :
1131 [ # # ]: 0 : return result;
1132 : : }
1133 : :
1134 : : String
1135 : 0 : SvxScriptSelectorDialog::GetSelectedDisplayName()
1136 : : {
1137 : 0 : return aCommands.GetEntryText( aCommands.GetLastSelectedEntry() );
1138 : : }
1139 : :
1140 : : String
1141 : 0 : SvxScriptSelectorDialog::GetSelectedHelpText()
1142 : : {
1143 : 0 : return aCommands.GetHelpText( aCommands.GetLastSelectedEntry() );
1144 : : }
1145 : :
1146 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|