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