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