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