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