xref: /AOO41X/main/cui/source/customize/cfg.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_cui.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <stdlib.h>
32*cdf0e10cSrcweir #include <time.h>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #ifndef _HELP_HXX //autogen
35*cdf0e10cSrcweir #include <vcl/help.hxx>
36*cdf0e10cSrcweir #endif
37*cdf0e10cSrcweir #ifndef _MSGBOX_HXX //autogen
38*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
39*cdf0e10cSrcweir #endif
40*cdf0e10cSrcweir #include <vcl/decoview.hxx>
41*cdf0e10cSrcweir #include <vcl/toolbox.hxx>
42*cdf0e10cSrcweir #include <vcl/scrbar.hxx>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir //added for issue73355
45*cdf0e10cSrcweir //#ifndef _SV_SVDATA_HXX
46*cdf0e10cSrcweir //#include <vcl/svdata.hxx>
47*cdf0e10cSrcweir //#endif
48*cdf0e10cSrcweir //issue73355 ends
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir #include <sfx2/app.hxx>
51*cdf0e10cSrcweir #include <sfx2/sfxdlg.hxx>
52*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
53*cdf0e10cSrcweir #include <sfx2/viewsh.hxx>
54*cdf0e10cSrcweir #include <sfx2/msg.hxx>
55*cdf0e10cSrcweir #include <sfx2/msgpool.hxx>
56*cdf0e10cSrcweir #include <sfx2/mnumgr.hxx>
57*cdf0e10cSrcweir #include <sfx2/minfitem.hxx>
58*cdf0e10cSrcweir #include <sfx2/objsh.hxx>
59*cdf0e10cSrcweir #include <sfx2/request.hxx>
60*cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx>
61*cdf0e10cSrcweir #include <svl/stritem.hxx>
62*cdf0e10cSrcweir #include <svtools/miscopt.hxx>
63*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
64*cdf0e10cSrcweir #include <toolkit/unohlp.hxx>
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir #include <algorithm>
67*cdf0e10cSrcweir //add
68*cdf0e10cSrcweir #include <cuires.hrc>
69*cdf0e10cSrcweir #include "cfg.hrc"
70*cdf0e10cSrcweir #include "helpid.hrc"
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir #include "acccfg.hxx"
73*cdf0e10cSrcweir #include "cfg.hxx"
74*cdf0e10cSrcweir #include "eventdlg.hxx"
75*cdf0e10cSrcweir #include <dialmgr.hxx>
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir #include <comphelper/documentinfo.hxx>
78*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
79*cdf0e10cSrcweir #ifndef _UNOTOOLS_CONFIGMGR_HXX_
80*cdf0e10cSrcweir #include <unotools/configmgr.hxx>
81*cdf0e10cSrcweir #endif
82*cdf0e10cSrcweir #include <com/sun/star/ui/ItemType.hpp>
83*cdf0e10cSrcweir #include <com/sun/star/ui/ItemStyle.hpp>
84*cdf0e10cSrcweir #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
85*cdf0e10cSrcweir #include <com/sun/star/frame/XController.hpp>
86*cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp>
87*cdf0e10cSrcweir #include <com/sun/star/ui/XUIConfiguration.hpp>
88*cdf0e10cSrcweir #include <com/sun/star/ui/XUIConfigurationListener.hpp>
89*cdf0e10cSrcweir #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
90*cdf0e10cSrcweir #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
91*cdf0e10cSrcweir #include <com/sun/star/ui/XUIConfigurationStorage.hpp>
92*cdf0e10cSrcweir #include <com/sun/star/ui/XModuleUIConfigurationManager.hpp>
93*cdf0e10cSrcweir #include <com/sun/star/ui/XUIElement.hpp>
94*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UI_UIElementType_HPP_
95*cdf0e10cSrcweir #include <com/sun/star/ui/UIElementType.hpp>
96*cdf0e10cSrcweir #endif
97*cdf0e10cSrcweir #include <com/sun/star/ui/ImageType.hpp>
98*cdf0e10cSrcweir #include <com/sun/star/frame/XLayoutManager.hpp>
99*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
100*cdf0e10cSrcweir #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
101*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
102*cdf0e10cSrcweir #include <com/sun/star/frame/XFramesSupplier.hpp>
103*cdf0e10cSrcweir #include <com/sun/star/frame/XFrames.hpp>
104*cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp>
105*cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp>
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir #include "dlgname.hxx"
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir #define PRTSTR(x) rtl::OUStringToOString(x, RTL_TEXTENCODING_ASCII_US).pData->buffer
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir #define ENTRY_HEIGHT 16
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir static const char ITEM_DESCRIPTOR_COMMANDURL[]  = "CommandURL";
114*cdf0e10cSrcweir static const char ITEM_DESCRIPTOR_CONTAINER[]   = "ItemDescriptorContainer";
115*cdf0e10cSrcweir static const char ITEM_DESCRIPTOR_LABEL[]       = "Label";
116*cdf0e10cSrcweir static const char ITEM_DESCRIPTOR_TYPE[]        = "Type";
117*cdf0e10cSrcweir static const char ITEM_DESCRIPTOR_STYLE[]       = "Style";
118*cdf0e10cSrcweir static const char ITEM_DESCRIPTOR_ISVISIBLE[]   = "IsVisible";
119*cdf0e10cSrcweir static const char ITEM_DESCRIPTOR_RESOURCEURL[] = "ResourceURL";
120*cdf0e10cSrcweir static const char ITEM_DESCRIPTOR_UINAME[]		= "UIName";
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir static const char ITEM_MENUBAR_URL[] = "private:resource/menubar/menubar";
123*cdf0e10cSrcweir static const char ITEM_TOOLBAR_URL[] = "private:resource/toolbar/";
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir static const char CUSTOM_TOOLBAR_STR[] = "custom_toolbar_";
126*cdf0e10cSrcweir static const char CUSTOM_MENU_STR[] = "vnd.openoffice.org:CustomMenu";
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir static const char __FAR_DATA pSeparatorStr[] =
129*cdf0e10cSrcweir 	"----------------------------------";
130*cdf0e10cSrcweir static const char __FAR_DATA pMenuSeparatorStr[]	= " | ";
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir #ifdef _MSC_VER
133*cdf0e10cSrcweir #pragma warning (disable:4355)
134*cdf0e10cSrcweir #endif
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir using rtl::OUString;
137*cdf0e10cSrcweir namespace css = com::sun::star;
138*cdf0e10cSrcweir namespace uno = com::sun::star::uno;
139*cdf0e10cSrcweir namespace frame = com::sun::star::frame;
140*cdf0e10cSrcweir namespace lang = com::sun::star::lang;
141*cdf0e10cSrcweir namespace container = com::sun::star::container;
142*cdf0e10cSrcweir namespace beans = com::sun::star::beans;
143*cdf0e10cSrcweir namespace graphic = com::sun::star::graphic;
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir void printPropertySet(
148*cdf0e10cSrcweir 	const OUString& prefix,
149*cdf0e10cSrcweir 	const uno::Reference< beans::XPropertySet >& xPropSet )
150*cdf0e10cSrcweir {
151*cdf0e10cSrcweir 	uno::Reference< beans::XPropertySetInfo > xPropSetInfo =
152*cdf0e10cSrcweir 		xPropSet->getPropertySetInfo();
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 	uno::Sequence< beans::Property > aPropDetails =
155*cdf0e10cSrcweir 		xPropSetInfo->getProperties();
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir 	OSL_TRACE("printPropertySet: %d properties", aPropDetails.getLength());
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 	for ( sal_Int32 i = 0; i < aPropDetails.getLength(); i++ )
160*cdf0e10cSrcweir 	{
161*cdf0e10cSrcweir 		OUString tmp;
162*cdf0e10cSrcweir 		sal_Int32 ival;
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir 		uno::Any a = xPropSet->getPropertyValue( aPropDetails[i].Name );
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir 		if ( ( a >>= tmp ) /* && tmp.getLength() != 0 */ )
167*cdf0e10cSrcweir 		{
168*cdf0e10cSrcweir 			OSL_TRACE("%s: Got property: %s = %s",
169*cdf0e10cSrcweir 				PRTSTR(prefix), PRTSTR(aPropDetails[i].Name), PRTSTR(tmp));
170*cdf0e10cSrcweir 		}
171*cdf0e10cSrcweir 		else if ( ( a >>= ival ) )
172*cdf0e10cSrcweir 		{
173*cdf0e10cSrcweir 			OSL_TRACE("%s: Got property: %s = %d",
174*cdf0e10cSrcweir 				PRTSTR(prefix), PRTSTR(aPropDetails[i].Name), PRTSTR(tmp));
175*cdf0e10cSrcweir 		}
176*cdf0e10cSrcweir 		else
177*cdf0e10cSrcweir 		{
178*cdf0e10cSrcweir 			OSL_TRACE("%s: Got property: %s of type %s",
179*cdf0e10cSrcweir 				PRTSTR(prefix), PRTSTR(aPropDetails[i].Name), PRTSTR(a.getValueTypeName()));
180*cdf0e10cSrcweir 		}
181*cdf0e10cSrcweir 	}
182*cdf0e10cSrcweir }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir void printProperties(
185*cdf0e10cSrcweir 	const OUString& prefix,
186*cdf0e10cSrcweir 	const uno::Sequence< beans::PropertyValue >& aProp )
187*cdf0e10cSrcweir {
188*cdf0e10cSrcweir 	for ( sal_Int32 i = 0; i < aProp.getLength(); i++ )
189*cdf0e10cSrcweir 	{
190*cdf0e10cSrcweir 		OUString tmp;
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir 		aProp[i].Value >>= tmp;
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir 		OSL_TRACE("%s: Got property: %s = %s",
195*cdf0e10cSrcweir 			PRTSTR(prefix), PRTSTR(aProp[i].Name), PRTSTR(tmp));
196*cdf0e10cSrcweir 	}
197*cdf0e10cSrcweir }
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir void printEntries(SvxEntries* entries)
200*cdf0e10cSrcweir {
201*cdf0e10cSrcweir 	SvxEntries::const_iterator iter = entries->begin();
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir 	for ( ; iter != entries->end(); iter++ )
204*cdf0e10cSrcweir 	{
205*cdf0e10cSrcweir 		SvxConfigEntry* entry = *iter;
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir         OSL_TRACE("printEntries: %s", PRTSTR(entry->GetName()));
208*cdf0e10cSrcweir 	}
209*cdf0e10cSrcweir }
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir #endif
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir OUString
214*cdf0e10cSrcweir stripHotKey( const OUString& str )
215*cdf0e10cSrcweir {
216*cdf0e10cSrcweir 	sal_Int32 index = str.indexOf( '~' );
217*cdf0e10cSrcweir 	if ( index == -1 )
218*cdf0e10cSrcweir 	{
219*cdf0e10cSrcweir 		return str;
220*cdf0e10cSrcweir 	}
221*cdf0e10cSrcweir 	else
222*cdf0e10cSrcweir 	{
223*cdf0e10cSrcweir 		return str.replaceAt( index, 1, OUString() );
224*cdf0e10cSrcweir 	}
225*cdf0e10cSrcweir }
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir OUString replaceSaveInName(
228*cdf0e10cSrcweir 	const OUString& rMessage,
229*cdf0e10cSrcweir 	const OUString& rSaveInName )
230*cdf0e10cSrcweir {
231*cdf0e10cSrcweir 	OUString name;
232*cdf0e10cSrcweir 	OUString placeholder = OUString::createFromAscii( "%SAVE IN SELECTION%" );
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir 	sal_Int32 pos = rMessage.indexOf( placeholder );
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir 	if ( pos != -1 )
237*cdf0e10cSrcweir 	{
238*cdf0e10cSrcweir 		name = rMessage.replaceAt(
239*cdf0e10cSrcweir 			pos, placeholder.getLength(), rSaveInName );
240*cdf0e10cSrcweir 	}
241*cdf0e10cSrcweir 	else
242*cdf0e10cSrcweir 	{
243*cdf0e10cSrcweir 		// don't change the message
244*cdf0e10cSrcweir 	}
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir 	return name;
247*cdf0e10cSrcweir }
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir OUString
250*cdf0e10cSrcweir replaceSixteen( const OUString& str, sal_Int32 nReplacement )
251*cdf0e10cSrcweir {
252*cdf0e10cSrcweir 	OUString result( str );
253*cdf0e10cSrcweir 	OUString sixteen = OUString::valueOf( (sal_Int32)16 );
254*cdf0e10cSrcweir 	OUString expected = OUString::valueOf( nReplacement );
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir 	sal_Int32 len = sixteen.getLength();
257*cdf0e10cSrcweir 	sal_Int32 index = result.indexOf( sixteen );
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir 	while ( index != -1 )
260*cdf0e10cSrcweir 	{
261*cdf0e10cSrcweir 		result = result.replaceAt( index, len, expected );
262*cdf0e10cSrcweir 		index = result.indexOf( sixteen, index );
263*cdf0e10cSrcweir 	}
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir 	return result;
266*cdf0e10cSrcweir }
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir OUString
269*cdf0e10cSrcweir generateCustomName(
270*cdf0e10cSrcweir 	const OUString& prefix,
271*cdf0e10cSrcweir 	SvxEntries* entries,
272*cdf0e10cSrcweir 	sal_Int32 suffix = 1 )
273*cdf0e10cSrcweir {
274*cdf0e10cSrcweir 	// find and replace the %n placeholder in the prefix string
275*cdf0e10cSrcweir 	OUString name;
276*cdf0e10cSrcweir 	OUString placeholder = OUString::createFromAscii( "%n" );
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir 	sal_Int32 pos = prefix.indexOf(
279*cdf0e10cSrcweir 		OUString::createFromAscii( "%n" ) );
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir 	if ( pos != -1 )
282*cdf0e10cSrcweir 	{
283*cdf0e10cSrcweir 		name = prefix.replaceAt(
284*cdf0e10cSrcweir 			pos, placeholder.getLength(), OUString::valueOf( suffix ) );
285*cdf0e10cSrcweir 	}
286*cdf0e10cSrcweir 	else
287*cdf0e10cSrcweir 	{
288*cdf0e10cSrcweir 		// no placeholder found so just append the suffix
289*cdf0e10cSrcweir 		name = prefix + OUString::valueOf( suffix );
290*cdf0e10cSrcweir 	}
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir 	// now check is there is an already existing entry with this name
293*cdf0e10cSrcweir 	SvxEntries::const_iterator iter = entries->begin();
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir 	SvxConfigEntry* pEntry;
296*cdf0e10cSrcweir 	while ( iter != entries->end() )
297*cdf0e10cSrcweir 	{
298*cdf0e10cSrcweir 		pEntry = *iter;
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir 		if ( name.equals( pEntry->GetName() ) )
301*cdf0e10cSrcweir 		{
302*cdf0e10cSrcweir 			break;
303*cdf0e10cSrcweir 		}
304*cdf0e10cSrcweir 		iter++;
305*cdf0e10cSrcweir 	}
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir 	if ( iter != entries->end() )
308*cdf0e10cSrcweir 	{
309*cdf0e10cSrcweir 		// name already exists so try the next number up
310*cdf0e10cSrcweir 		return generateCustomName( prefix, entries, ++suffix );
311*cdf0e10cSrcweir 	}
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir 	return name;
314*cdf0e10cSrcweir }
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir sal_uInt32 generateRandomValue()
317*cdf0e10cSrcweir {
318*cdf0e10cSrcweir     srand( unsigned( time( NULL ) ));
319*cdf0e10cSrcweir     return sal_uInt32( rand() );
320*cdf0e10cSrcweir }
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir OUString
323*cdf0e10cSrcweir generateCustomURL(
324*cdf0e10cSrcweir 	SvxEntries* entries )
325*cdf0e10cSrcweir {
326*cdf0e10cSrcweir 	OUString url = OUString::createFromAscii( ITEM_TOOLBAR_URL );
327*cdf0e10cSrcweir 	url += OUString::createFromAscii( CUSTOM_TOOLBAR_STR );
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir     // use a random number to minimize possible clash with existing custom toolbars
330*cdf0e10cSrcweir     url += OUString::valueOf( sal_Int64( generateRandomValue() ), 16 );
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir 	// now check is there is an already existing entry with this url
333*cdf0e10cSrcweir 	SvxEntries::const_iterator iter = entries->begin();
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir 	SvxConfigEntry* pEntry;
336*cdf0e10cSrcweir 	while ( iter != entries->end() )
337*cdf0e10cSrcweir 	{
338*cdf0e10cSrcweir 		pEntry = *iter;
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir 		if ( url.equals( pEntry->GetCommand() ) )
341*cdf0e10cSrcweir 		{
342*cdf0e10cSrcweir 			break;
343*cdf0e10cSrcweir 		}
344*cdf0e10cSrcweir 		iter++;
345*cdf0e10cSrcweir 	}
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir 	if ( iter != entries->end() )
348*cdf0e10cSrcweir 	{
349*cdf0e10cSrcweir 		// url already exists so try the next number up
350*cdf0e10cSrcweir 		return generateCustomURL( entries );
351*cdf0e10cSrcweir 	}
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir 	return url;
354*cdf0e10cSrcweir }
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir OUString
357*cdf0e10cSrcweir generateCustomMenuURL(
358*cdf0e10cSrcweir 	SvxEntries* entries,
359*cdf0e10cSrcweir 	sal_Int32 suffix = 1 )
360*cdf0e10cSrcweir {
361*cdf0e10cSrcweir 	OUString url = OUString::createFromAscii( CUSTOM_MENU_STR );
362*cdf0e10cSrcweir 	url += OUString::valueOf( suffix );
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir 	// now check is there is an already existing entry with this url
365*cdf0e10cSrcweir 	SvxEntries::const_iterator iter = entries->begin();
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir 	SvxConfigEntry* pEntry;
368*cdf0e10cSrcweir 	while ( iter != entries->end() )
369*cdf0e10cSrcweir 	{
370*cdf0e10cSrcweir 		pEntry = *iter;
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir 		if ( url.equals( pEntry->GetCommand() ) )
373*cdf0e10cSrcweir 		{
374*cdf0e10cSrcweir 			break;
375*cdf0e10cSrcweir 		}
376*cdf0e10cSrcweir 		iter++;
377*cdf0e10cSrcweir 	}
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir 	if ( iter != entries->end() )
380*cdf0e10cSrcweir 	{
381*cdf0e10cSrcweir 		// url already exists so try the next number up
382*cdf0e10cSrcweir 		return generateCustomMenuURL( entries, ++suffix );
383*cdf0e10cSrcweir 	}
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir 	return url;
386*cdf0e10cSrcweir }
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir static sal_Int16 theImageType =
389*cdf0e10cSrcweir 	css::ui::ImageType::COLOR_NORMAL |
390*cdf0e10cSrcweir 	css::ui::ImageType::SIZE_DEFAULT;
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir void InitImageType()
393*cdf0e10cSrcweir {
394*cdf0e10cSrcweir 	theImageType =
395*cdf0e10cSrcweir 		css::ui::ImageType::COLOR_NORMAL |
396*cdf0e10cSrcweir 		css::ui::ImageType::SIZE_DEFAULT;
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir     if ( SvtMiscOptions().AreCurrentSymbolsLarge() )
399*cdf0e10cSrcweir 	{
400*cdf0e10cSrcweir         theImageType |= css::ui::ImageType::SIZE_LARGE;
401*cdf0e10cSrcweir 	}
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir 	Window* topwin = Application::GetActiveTopWindow();
404*cdf0e10cSrcweir 	if ( topwin != NULL &&
405*cdf0e10cSrcweir 		 topwin->GetSettings().GetStyleSettings().GetHighContrastMode() )
406*cdf0e10cSrcweir 	{
407*cdf0e10cSrcweir         theImageType |= css::ui::ImageType::COLOR_HIGHCONTRAST;
408*cdf0e10cSrcweir 	}
409*cdf0e10cSrcweir }
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir sal_Int16 GetImageType()
412*cdf0e10cSrcweir {
413*cdf0e10cSrcweir 	return theImageType;
414*cdf0e10cSrcweir }
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir void RemoveEntry( SvxEntries* pEntries, SvxConfigEntry* pChildEntry )
417*cdf0e10cSrcweir {
418*cdf0e10cSrcweir 	SvxEntries::iterator iter = pEntries->begin();
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir 	while ( iter != pEntries->end() )
421*cdf0e10cSrcweir 	{
422*cdf0e10cSrcweir 		if ( pChildEntry == *iter )
423*cdf0e10cSrcweir 		{
424*cdf0e10cSrcweir 			pEntries->erase( iter );
425*cdf0e10cSrcweir 			break;
426*cdf0e10cSrcweir 		}
427*cdf0e10cSrcweir 		iter++;
428*cdf0e10cSrcweir 	}
429*cdf0e10cSrcweir }
430*cdf0e10cSrcweir 
431*cdf0e10cSrcweir bool
432*cdf0e10cSrcweir SvxConfigPage::CanConfig( const OUString& aModuleId )
433*cdf0e10cSrcweir {
434*cdf0e10cSrcweir 	OSL_TRACE("SupportsDocumentConfig: %s", PRTSTR(aModuleId));
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir 	if  (  aModuleId.equalsAscii( "com.sun.star.script.BasicIDE" )
437*cdf0e10cSrcweir         || aModuleId.equalsAscii( "com.sun.star.frame.Bibliography" )
438*cdf0e10cSrcweir         )
439*cdf0e10cSrcweir     {
440*cdf0e10cSrcweir 		return sal_False;
441*cdf0e10cSrcweir 	}
442*cdf0e10cSrcweir 	return sal_True;
443*cdf0e10cSrcweir }
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir OUString GetModuleName( const OUString& aModuleId )
446*cdf0e10cSrcweir {
447*cdf0e10cSrcweir     if ( aModuleId.equalsAscii( "com.sun.star.text.TextDocument" ) ||
448*cdf0e10cSrcweir 		 aModuleId.equalsAscii( "com.sun.star.text.GlobalDocument" ) )
449*cdf0e10cSrcweir 		return OUString::createFromAscii("Writer");
450*cdf0e10cSrcweir 	else if ( aModuleId.equalsAscii( "com.sun.star.text.WebDocument" ) )
451*cdf0e10cSrcweir 		return OUString::createFromAscii("Writer/Web");
452*cdf0e10cSrcweir 	else if ( aModuleId.equalsAscii( "com.sun.star.drawing.DrawingDocument" ) )
453*cdf0e10cSrcweir 		return OUString::createFromAscii("Draw");
454*cdf0e10cSrcweir 	else if ( aModuleId.equalsAscii( "com.sun.star.presentation.PresentationDocument" ) )
455*cdf0e10cSrcweir 		return OUString::createFromAscii("Impress");
456*cdf0e10cSrcweir 	else if ( aModuleId.equalsAscii( "com.sun.star.sheet.SpreadsheetDocument" ) )
457*cdf0e10cSrcweir 		return OUString::createFromAscii("Calc");
458*cdf0e10cSrcweir 	else if ( aModuleId.equalsAscii( "com.sun.star.script.BasicIDE" ) )
459*cdf0e10cSrcweir 		return OUString::createFromAscii("Basic");
460*cdf0e10cSrcweir 	else if ( aModuleId.equalsAscii( "com.sun.star.formula.FormulaProperties" ) )
461*cdf0e10cSrcweir 		return OUString::createFromAscii("Math");
462*cdf0e10cSrcweir     else if ( aModuleId.equalsAscii( "com.sun.star.sdb.RelationDesign" ) )
463*cdf0e10cSrcweir         return OUString::createFromAscii("Relation Design");
464*cdf0e10cSrcweir     else if ( aModuleId.equalsAscii( "com.sun.star.sdb.QueryDesign" ) )
465*cdf0e10cSrcweir         return OUString::createFromAscii("Query Design");
466*cdf0e10cSrcweir     else if ( aModuleId.equalsAscii( "com.sun.star.sdb.TableDesign" ) )
467*cdf0e10cSrcweir         return OUString::createFromAscii("Table Design");
468*cdf0e10cSrcweir     else if ( aModuleId.equalsAscii( "com.sun.star.sdb.DataSourceBrowser" ) )
469*cdf0e10cSrcweir         return OUString::createFromAscii("Data Source Browser" );
470*cdf0e10cSrcweir     else if ( aModuleId.equalsAscii( "com.sun.star.sdb.DatabaseDocument" ) )
471*cdf0e10cSrcweir         return OUString::createFromAscii("Database" );
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir     return ::rtl::OUString();
474*cdf0e10cSrcweir }
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir OUString GetUIModuleName( const OUString& aModuleId, const uno::Reference< css::frame::XModuleManager >& rModuleManager )
477*cdf0e10cSrcweir {
478*cdf0e10cSrcweir     OUString aModuleUIName;
479*cdf0e10cSrcweir 
480*cdf0e10cSrcweir     if ( rModuleManager.is() )
481*cdf0e10cSrcweir     {
482*cdf0e10cSrcweir         uno::Reference< css::container::XNameAccess > xNameAccess( rModuleManager, uno::UNO_QUERY );
483*cdf0e10cSrcweir         if ( xNameAccess.is() )
484*cdf0e10cSrcweir         {
485*cdf0e10cSrcweir             try
486*cdf0e10cSrcweir             {
487*cdf0e10cSrcweir                 uno::Any a = xNameAccess->getByName( aModuleId );
488*cdf0e10cSrcweir                 uno::Sequence< beans::PropertyValue > aSeq;
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir                 if ( a >>= aSeq )
491*cdf0e10cSrcweir                 {
492*cdf0e10cSrcweir                     OUString aUIName;
493*cdf0e10cSrcweir                     for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ )
494*cdf0e10cSrcweir                     {
495*cdf0e10cSrcweir                         if ( aSeq[i].Name.equalsAscii( "ooSetupFactoryUIName" ))
496*cdf0e10cSrcweir                         {
497*cdf0e10cSrcweir                             aSeq[i].Value >>= aModuleUIName;
498*cdf0e10cSrcweir                             break;
499*cdf0e10cSrcweir                         }
500*cdf0e10cSrcweir                     }
501*cdf0e10cSrcweir                 }
502*cdf0e10cSrcweir             }
503*cdf0e10cSrcweir             catch ( uno::RuntimeException& e )
504*cdf0e10cSrcweir             {
505*cdf0e10cSrcweir                 throw e;
506*cdf0e10cSrcweir             }
507*cdf0e10cSrcweir             catch ( uno::Exception& )
508*cdf0e10cSrcweir             {
509*cdf0e10cSrcweir             }
510*cdf0e10cSrcweir         }
511*cdf0e10cSrcweir     }
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir     if ( aModuleUIName.getLength() == 0 )
514*cdf0e10cSrcweir         aModuleUIName = GetModuleName( aModuleId );
515*cdf0e10cSrcweir 
516*cdf0e10cSrcweir     return aModuleUIName;
517*cdf0e10cSrcweir }
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir bool GetMenuItemData(
520*cdf0e10cSrcweir 	const uno::Reference< container::XIndexAccess >& rItemContainer,
521*cdf0e10cSrcweir 	sal_Int32 nIndex,
522*cdf0e10cSrcweir 	OUString& rCommandURL,
523*cdf0e10cSrcweir 	OUString& rLabel,
524*cdf0e10cSrcweir 	sal_uInt16& rType,
525*cdf0e10cSrcweir 	uno::Reference< container::XIndexAccess >& rSubMenu )
526*cdf0e10cSrcweir {
527*cdf0e10cSrcweir     try
528*cdf0e10cSrcweir     {
529*cdf0e10cSrcweir         uno::Sequence< beans::PropertyValue > aProp;
530*cdf0e10cSrcweir         if ( rItemContainer->getByIndex( nIndex ) >>= aProp )
531*cdf0e10cSrcweir         {
532*cdf0e10cSrcweir             for ( sal_Int32 i = 0; i < aProp.getLength(); i++ )
533*cdf0e10cSrcweir             {
534*cdf0e10cSrcweir                 if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_COMMANDURL ))
535*cdf0e10cSrcweir                 {
536*cdf0e10cSrcweir                     aProp[i].Value >>= rCommandURL;
537*cdf0e10cSrcweir                 }
538*cdf0e10cSrcweir                 else if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_CONTAINER ))
539*cdf0e10cSrcweir                 {
540*cdf0e10cSrcweir                     aProp[i].Value >>= rSubMenu;
541*cdf0e10cSrcweir                 }
542*cdf0e10cSrcweir                 else if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_LABEL ))
543*cdf0e10cSrcweir                 {
544*cdf0e10cSrcweir                     aProp[i].Value >>= rLabel;
545*cdf0e10cSrcweir                 }
546*cdf0e10cSrcweir                 else if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_TYPE ))
547*cdf0e10cSrcweir                 {
548*cdf0e10cSrcweir                     aProp[i].Value >>= rType;
549*cdf0e10cSrcweir                 }
550*cdf0e10cSrcweir             }
551*cdf0e10cSrcweir 
552*cdf0e10cSrcweir             return sal_True;
553*cdf0e10cSrcweir         }
554*cdf0e10cSrcweir     }
555*cdf0e10cSrcweir     catch ( ::com::sun::star::lang::IndexOutOfBoundsException& )
556*cdf0e10cSrcweir     {
557*cdf0e10cSrcweir     }
558*cdf0e10cSrcweir 
559*cdf0e10cSrcweir     return sal_False;
560*cdf0e10cSrcweir }
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir bool GetToolbarItemData(
563*cdf0e10cSrcweir 	const uno::Reference< container::XIndexAccess >& rItemContainer,
564*cdf0e10cSrcweir 	sal_Int32 nIndex,
565*cdf0e10cSrcweir 	OUString& rCommandURL,
566*cdf0e10cSrcweir 	OUString& rLabel,
567*cdf0e10cSrcweir 	sal_uInt16& rType,
568*cdf0e10cSrcweir 	sal_Bool& rIsVisible,
569*cdf0e10cSrcweir 	sal_Int32& rStyle,
570*cdf0e10cSrcweir 	uno::Reference< container::XIndexAccess >& rSubMenu )
571*cdf0e10cSrcweir {
572*cdf0e10cSrcweir     try
573*cdf0e10cSrcweir     {
574*cdf0e10cSrcweir         uno::Sequence< beans::PropertyValue > aProp;
575*cdf0e10cSrcweir         if ( rItemContainer->getByIndex( nIndex ) >>= aProp )
576*cdf0e10cSrcweir         {
577*cdf0e10cSrcweir             for ( sal_Int32 i = 0; i < aProp.getLength(); i++ )
578*cdf0e10cSrcweir             {
579*cdf0e10cSrcweir                 if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_COMMANDURL ))
580*cdf0e10cSrcweir                 {
581*cdf0e10cSrcweir                     aProp[i].Value >>= rCommandURL;
582*cdf0e10cSrcweir                 }
583*cdf0e10cSrcweir                 if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_STYLE ))
584*cdf0e10cSrcweir                 {
585*cdf0e10cSrcweir                     aProp[i].Value >>= rStyle;
586*cdf0e10cSrcweir                 }
587*cdf0e10cSrcweir                 else if (aProp[i].Name.equalsAscii(ITEM_DESCRIPTOR_CONTAINER))
588*cdf0e10cSrcweir                 {
589*cdf0e10cSrcweir                     aProp[i].Value >>= rSubMenu;
590*cdf0e10cSrcweir                 }
591*cdf0e10cSrcweir                 else if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_LABEL ))
592*cdf0e10cSrcweir                 {
593*cdf0e10cSrcweir                     aProp[i].Value >>= rLabel;
594*cdf0e10cSrcweir                 }
595*cdf0e10cSrcweir                 else if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_TYPE ))
596*cdf0e10cSrcweir                 {
597*cdf0e10cSrcweir                     aProp[i].Value >>= rType;
598*cdf0e10cSrcweir                 }
599*cdf0e10cSrcweir                 else if (aProp[i].Name.equalsAscii(ITEM_DESCRIPTOR_ISVISIBLE))
600*cdf0e10cSrcweir                 {
601*cdf0e10cSrcweir                     aProp[i].Value >>= rIsVisible;
602*cdf0e10cSrcweir                 }
603*cdf0e10cSrcweir             }
604*cdf0e10cSrcweir 
605*cdf0e10cSrcweir             return sal_True;
606*cdf0e10cSrcweir         }
607*cdf0e10cSrcweir     }
608*cdf0e10cSrcweir     catch ( ::com::sun::star::lang::IndexOutOfBoundsException& )
609*cdf0e10cSrcweir     {
610*cdf0e10cSrcweir     }
611*cdf0e10cSrcweir 
612*cdf0e10cSrcweir     return sal_False;
613*cdf0e10cSrcweir }
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue >
616*cdf0e10cSrcweir ConvertSvxConfigEntry(
617*cdf0e10cSrcweir 	const uno::Reference< container::XNameAccess >& xCommandToLabelMap,
618*cdf0e10cSrcweir 	const SvxConfigEntry* pEntry )
619*cdf0e10cSrcweir {
620*cdf0e10cSrcweir 	static const OUString aDescriptorCommandURL (
621*cdf0e10cSrcweir 		RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_COMMANDURL ) );
622*cdf0e10cSrcweir 
623*cdf0e10cSrcweir 	static const OUString aDescriptorType(
624*cdf0e10cSrcweir 			RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_TYPE ) );
625*cdf0e10cSrcweir 
626*cdf0e10cSrcweir 	static const OUString aDescriptorLabel(
627*cdf0e10cSrcweir 			RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_LABEL ) );
628*cdf0e10cSrcweir 
629*cdf0e10cSrcweir 	static const OUString aDescriptorContainer(
630*cdf0e10cSrcweir 			RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_CONTAINER ) );
631*cdf0e10cSrcweir 
632*cdf0e10cSrcweir     uno::Sequence< beans::PropertyValue > aPropSeq( 3 );
633*cdf0e10cSrcweir 
634*cdf0e10cSrcweir     aPropSeq[0].Name = aDescriptorCommandURL;
635*cdf0e10cSrcweir     aPropSeq[0].Value <<= rtl::OUString( pEntry->GetCommand() );
636*cdf0e10cSrcweir 
637*cdf0e10cSrcweir     aPropSeq[1].Name = aDescriptorType;
638*cdf0e10cSrcweir     aPropSeq[1].Value <<= css::ui::ItemType::DEFAULT;
639*cdf0e10cSrcweir 
640*cdf0e10cSrcweir     // If the name has not been changed and the name is the same as
641*cdf0e10cSrcweir     // in the default command to label map then the label can be stored
642*cdf0e10cSrcweir     // as an empty string.
643*cdf0e10cSrcweir     // It will be initialised again later using the command to label map.
644*cdf0e10cSrcweir     aPropSeq[2].Name = aDescriptorLabel;
645*cdf0e10cSrcweir     if ( pEntry->HasChangedName() == sal_False && pEntry->GetCommand().getLength() )
646*cdf0e10cSrcweir     {
647*cdf0e10cSrcweir         sal_Bool isDefaultName = sal_False;
648*cdf0e10cSrcweir         try
649*cdf0e10cSrcweir         {
650*cdf0e10cSrcweir             uno::Any a( xCommandToLabelMap->getByName( pEntry->GetCommand() ) );
651*cdf0e10cSrcweir             uno::Sequence< beans::PropertyValue > tmpPropSeq;
652*cdf0e10cSrcweir             if ( a >>= tmpPropSeq )
653*cdf0e10cSrcweir             {
654*cdf0e10cSrcweir                 for ( sal_Int32 i = 0; i < tmpPropSeq.getLength(); i++ )
655*cdf0e10cSrcweir                 {
656*cdf0e10cSrcweir                     if ( tmpPropSeq[i].Name.equals( aDescriptorLabel ) )
657*cdf0e10cSrcweir                     {
658*cdf0e10cSrcweir                         OUString tmpLabel;
659*cdf0e10cSrcweir                         tmpPropSeq[i].Value >>= tmpLabel;
660*cdf0e10cSrcweir 
661*cdf0e10cSrcweir                         if ( tmpLabel.equals( pEntry->GetName() ) )
662*cdf0e10cSrcweir                         {
663*cdf0e10cSrcweir                             isDefaultName = sal_True;
664*cdf0e10cSrcweir                         }
665*cdf0e10cSrcweir 
666*cdf0e10cSrcweir                         break;
667*cdf0e10cSrcweir                     }
668*cdf0e10cSrcweir                 }
669*cdf0e10cSrcweir             }
670*cdf0e10cSrcweir         }
671*cdf0e10cSrcweir         catch ( container::NoSuchElementException& )
672*cdf0e10cSrcweir         {
673*cdf0e10cSrcweir             // isDefaultName is left as FALSE
674*cdf0e10cSrcweir         }
675*cdf0e10cSrcweir 
676*cdf0e10cSrcweir         if ( isDefaultName )
677*cdf0e10cSrcweir         {
678*cdf0e10cSrcweir             aPropSeq[2].Value <<= rtl::OUString();
679*cdf0e10cSrcweir         }
680*cdf0e10cSrcweir         else
681*cdf0e10cSrcweir         {
682*cdf0e10cSrcweir             aPropSeq[2].Value <<= rtl::OUString( pEntry->GetName() );
683*cdf0e10cSrcweir         }
684*cdf0e10cSrcweir     }
685*cdf0e10cSrcweir     else
686*cdf0e10cSrcweir     {
687*cdf0e10cSrcweir         aPropSeq[2].Value <<= rtl::OUString( pEntry->GetName() );
688*cdf0e10cSrcweir     }
689*cdf0e10cSrcweir 
690*cdf0e10cSrcweir     return aPropSeq;
691*cdf0e10cSrcweir }
692*cdf0e10cSrcweir 
693*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue >
694*cdf0e10cSrcweir ConvertToolbarEntry(
695*cdf0e10cSrcweir 	const uno::Reference< container::XNameAccess >& xCommandToLabelMap,
696*cdf0e10cSrcweir 	const SvxConfigEntry* pEntry )
697*cdf0e10cSrcweir {
698*cdf0e10cSrcweir 	static const OUString aDescriptorCommandURL (
699*cdf0e10cSrcweir 		RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_COMMANDURL ) );
700*cdf0e10cSrcweir 
701*cdf0e10cSrcweir 	static const OUString aDescriptorType(
702*cdf0e10cSrcweir 			RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_TYPE ) );
703*cdf0e10cSrcweir 
704*cdf0e10cSrcweir 	static const OUString aDescriptorLabel(
705*cdf0e10cSrcweir 			RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_LABEL ) );
706*cdf0e10cSrcweir 
707*cdf0e10cSrcweir 	static const OUString aDescriptorContainer(
708*cdf0e10cSrcweir 			RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_CONTAINER ) );
709*cdf0e10cSrcweir 
710*cdf0e10cSrcweir 	static const OUString aIsVisible(
711*cdf0e10cSrcweir 			RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_ISVISIBLE ) );
712*cdf0e10cSrcweir 
713*cdf0e10cSrcweir     uno::Sequence< beans::PropertyValue > aPropSeq( 4 );
714*cdf0e10cSrcweir 
715*cdf0e10cSrcweir     aPropSeq[0].Name = aDescriptorCommandURL;
716*cdf0e10cSrcweir     aPropSeq[0].Value <<= rtl::OUString( pEntry->GetCommand() );
717*cdf0e10cSrcweir 
718*cdf0e10cSrcweir     aPropSeq[1].Name = aDescriptorType;
719*cdf0e10cSrcweir     aPropSeq[1].Value <<= css::ui::ItemType::DEFAULT;
720*cdf0e10cSrcweir 
721*cdf0e10cSrcweir     // If the name has not been changed and the name is the same as
722*cdf0e10cSrcweir     // in the default command to label map then the label can be stored
723*cdf0e10cSrcweir     // as an empty string.
724*cdf0e10cSrcweir     // It will be initialised again later using the command to label map.
725*cdf0e10cSrcweir     aPropSeq[2].Name = aDescriptorLabel;
726*cdf0e10cSrcweir     if ( pEntry->HasChangedName() == sal_False && pEntry->GetCommand().getLength() )
727*cdf0e10cSrcweir     {
728*cdf0e10cSrcweir         sal_Bool isDefaultName = sal_False;
729*cdf0e10cSrcweir         try
730*cdf0e10cSrcweir         {
731*cdf0e10cSrcweir             uno::Any a( xCommandToLabelMap->getByName( pEntry->GetCommand() ) );
732*cdf0e10cSrcweir             uno::Sequence< beans::PropertyValue > tmpPropSeq;
733*cdf0e10cSrcweir             if ( a >>= tmpPropSeq )
734*cdf0e10cSrcweir             {
735*cdf0e10cSrcweir                 for ( sal_Int32 i = 0; i < tmpPropSeq.getLength(); i++ )
736*cdf0e10cSrcweir                 {
737*cdf0e10cSrcweir                     if ( tmpPropSeq[i].Name.equals( aDescriptorLabel ) )
738*cdf0e10cSrcweir                     {
739*cdf0e10cSrcweir                         OUString tmpLabel;
740*cdf0e10cSrcweir                         tmpPropSeq[i].Value >>= tmpLabel;
741*cdf0e10cSrcweir 
742*cdf0e10cSrcweir                         if ( tmpLabel.equals( pEntry->GetName() ) )
743*cdf0e10cSrcweir                         {
744*cdf0e10cSrcweir                             isDefaultName = sal_True;
745*cdf0e10cSrcweir                         }
746*cdf0e10cSrcweir 
747*cdf0e10cSrcweir                         break;
748*cdf0e10cSrcweir                     }
749*cdf0e10cSrcweir                 }
750*cdf0e10cSrcweir             }
751*cdf0e10cSrcweir         }
752*cdf0e10cSrcweir         catch ( container::NoSuchElementException& )
753*cdf0e10cSrcweir         {
754*cdf0e10cSrcweir             // isDefaultName is left as FALSE
755*cdf0e10cSrcweir         }
756*cdf0e10cSrcweir 
757*cdf0e10cSrcweir         if ( isDefaultName )
758*cdf0e10cSrcweir         {
759*cdf0e10cSrcweir             aPropSeq[2].Value <<= rtl::OUString();
760*cdf0e10cSrcweir         }
761*cdf0e10cSrcweir         else
762*cdf0e10cSrcweir         {
763*cdf0e10cSrcweir             aPropSeq[2].Value <<= rtl::OUString( pEntry->GetName() );
764*cdf0e10cSrcweir         }
765*cdf0e10cSrcweir     }
766*cdf0e10cSrcweir     else
767*cdf0e10cSrcweir     {
768*cdf0e10cSrcweir         aPropSeq[2].Value <<= rtl::OUString( pEntry->GetName() );
769*cdf0e10cSrcweir     }
770*cdf0e10cSrcweir 
771*cdf0e10cSrcweir     aPropSeq[3].Name = aIsVisible;
772*cdf0e10cSrcweir     aPropSeq[3].Value <<= pEntry->IsVisible();
773*cdf0e10cSrcweir 
774*cdf0e10cSrcweir     return aPropSeq;
775*cdf0e10cSrcweir }
776*cdf0e10cSrcweir 
777*cdf0e10cSrcweir SfxTabPage *CreateSvxMenuConfigPage( Window *pParent, const SfxItemSet& rSet )
778*cdf0e10cSrcweir {
779*cdf0e10cSrcweir     return new SvxMenuConfigPage( pParent, rSet );
780*cdf0e10cSrcweir }
781*cdf0e10cSrcweir 
782*cdf0e10cSrcweir SfxTabPage *CreateKeyboardConfigPage( Window *pParent, const SfxItemSet& rSet )
783*cdf0e10cSrcweir {
784*cdf0e10cSrcweir    	return new SfxAcceleratorConfigPage( pParent, rSet );
785*cdf0e10cSrcweir }
786*cdf0e10cSrcweir 
787*cdf0e10cSrcweir SfxTabPage *CreateSvxToolbarConfigPage( Window *pParent, const SfxItemSet& rSet )
788*cdf0e10cSrcweir {
789*cdf0e10cSrcweir     return new SvxToolbarConfigPage( pParent, rSet );
790*cdf0e10cSrcweir }
791*cdf0e10cSrcweir 
792*cdf0e10cSrcweir SfxTabPage *CreateSvxEventConfigPage( Window *pParent, const SfxItemSet& rSet )
793*cdf0e10cSrcweir {
794*cdf0e10cSrcweir     return new SvxEventConfigPage( pParent, rSet, SvxEventConfigPage::EarlyInit() );
795*cdf0e10cSrcweir }
796*cdf0e10cSrcweir 
797*cdf0e10cSrcweir sal_Bool impl_showKeyConfigTabPage( const css::uno::Reference< css::frame::XFrame >& xFrame )
798*cdf0e10cSrcweir {
799*cdf0e10cSrcweir     static ::rtl::OUString SERVICENAME_MODULEMANAGER = ::rtl::OUString::createFromAscii("com.sun.star.frame.ModuleManager");
800*cdf0e10cSrcweir     static ::rtl::OUString SERVICENAME_DESKTOP       = ::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop"             );
801*cdf0e10cSrcweir     static ::rtl::OUString MODULEID_STARTMODULE      = ::rtl::OUString::createFromAscii("com.sun.star.frame.StartModule"         );
802*cdf0e10cSrcweir 
803*cdf0e10cSrcweir     try
804*cdf0e10cSrcweir     {
805*cdf0e10cSrcweir         css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR   = ::comphelper::getProcessServiceFactory();
806*cdf0e10cSrcweir 		css::uno::Reference< css::frame::XFramesSupplier >     xDesktop(xSMGR->createInstance(SERVICENAME_DESKTOP), css::uno::UNO_QUERY_THROW);
807*cdf0e10cSrcweir         css::uno::Reference< css::frame::XModuleManager >     xMM     (xSMGR->createInstance(SERVICENAME_MODULEMANAGER), css::uno::UNO_QUERY_THROW);
808*cdf0e10cSrcweir 
809*cdf0e10cSrcweir         if (xMM.is() && xFrame.is())
810*cdf0e10cSrcweir         {
811*cdf0e10cSrcweir             ::rtl::OUString sModuleId = xMM->identify(xFrame);
812*cdf0e10cSrcweir             if (
813*cdf0e10cSrcweir                 ( sModuleId.getLength()                 ) &&
814*cdf0e10cSrcweir                 (!sModuleId.equals(MODULEID_STARTMODULE))
815*cdf0e10cSrcweir                )
816*cdf0e10cSrcweir                return sal_True;
817*cdf0e10cSrcweir         }
818*cdf0e10cSrcweir     }
819*cdf0e10cSrcweir     catch(const css::uno::Exception&)
820*cdf0e10cSrcweir         {}
821*cdf0e10cSrcweir 
822*cdf0e10cSrcweir     return sal_False;
823*cdf0e10cSrcweir }
824*cdf0e10cSrcweir 
825*cdf0e10cSrcweir /******************************************************************************
826*cdf0e10cSrcweir  *
827*cdf0e10cSrcweir  * SvxConfigDialog is the configuration dialog which is brought up from the
828*cdf0e10cSrcweir  * Tools menu. It includes tabs for customizing menus, toolbars, events and
829*cdf0e10cSrcweir  * key bindings.
830*cdf0e10cSrcweir  *
831*cdf0e10cSrcweir  *****************************************************************************/
832*cdf0e10cSrcweir SvxConfigDialog::SvxConfigDialog(
833*cdf0e10cSrcweir 	Window * pParent, const SfxItemSet* pSet_ )
834*cdf0e10cSrcweir 	:
835*cdf0e10cSrcweir 		SfxTabDialog( pParent,
836*cdf0e10cSrcweir 			CUI_RES( RID_SVXDLG_CUSTOMIZE ), pSet_ )
837*cdf0e10cSrcweir {
838*cdf0e10cSrcweir 	FreeResource();
839*cdf0e10cSrcweir 
840*cdf0e10cSrcweir 	InitImageType();
841*cdf0e10cSrcweir 
842*cdf0e10cSrcweir 	AddTabPage( RID_SVXPAGE_MENUS, CreateSvxMenuConfigPage, NULL );
843*cdf0e10cSrcweir 	AddTabPage( RID_SVXPAGE_KEYBOARD, CreateKeyboardConfigPage, NULL );
844*cdf0e10cSrcweir 	AddTabPage( RID_SVXPAGE_TOOLBARS, CreateSvxToolbarConfigPage, NULL );
845*cdf0e10cSrcweir 	AddTabPage( RID_SVXPAGE_EVENTS, CreateSvxEventConfigPage, NULL );
846*cdf0e10cSrcweir 
847*cdf0e10cSrcweir 	const SfxPoolItem* pItem =
848*cdf0e10cSrcweir 		pSet_->GetItem( pSet_->GetPool()->GetWhich( SID_CONFIG ) );
849*cdf0e10cSrcweir 
850*cdf0e10cSrcweir 	if ( pItem )
851*cdf0e10cSrcweir 	{
852*cdf0e10cSrcweir 		OUString text = ((const SfxStringItem*)pItem)->GetValue();
853*cdf0e10cSrcweir 
854*cdf0e10cSrcweir 		if (text.indexOf(OUString::createFromAscii(ITEM_TOOLBAR_URL)) == 0)
855*cdf0e10cSrcweir 		{
856*cdf0e10cSrcweir 			SetCurPageId( RID_SVXPAGE_TOOLBARS );
857*cdf0e10cSrcweir 		}
858*cdf0e10cSrcweir 	}
859*cdf0e10cSrcweir }
860*cdf0e10cSrcweir 
861*cdf0e10cSrcweir void SvxConfigDialog::SetFrame(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame)
862*cdf0e10cSrcweir {
863*cdf0e10cSrcweir     m_xFrame = xFrame;
864*cdf0e10cSrcweir 
865*cdf0e10cSrcweir     if (!impl_showKeyConfigTabPage( xFrame ))
866*cdf0e10cSrcweir         RemoveTabPage( RID_SVXPAGE_KEYBOARD );
867*cdf0e10cSrcweir }
868*cdf0e10cSrcweir 
869*cdf0e10cSrcweir SvxConfigDialog::~SvxConfigDialog()
870*cdf0e10cSrcweir {
871*cdf0e10cSrcweir }
872*cdf0e10cSrcweir 
873*cdf0e10cSrcweir short SvxConfigDialog::Ok()
874*cdf0e10cSrcweir {
875*cdf0e10cSrcweir 	return SfxTabDialog::Ok();
876*cdf0e10cSrcweir }
877*cdf0e10cSrcweir 
878*cdf0e10cSrcweir void SvxConfigDialog::PageCreated( sal_uInt16 nId, SfxTabPage& rPage )
879*cdf0e10cSrcweir {
880*cdf0e10cSrcweir 	(void)rPage;
881*cdf0e10cSrcweir 
882*cdf0e10cSrcweir 	switch ( nId )
883*cdf0e10cSrcweir 	{
884*cdf0e10cSrcweir 		case RID_SVXPAGE_MENUS:
885*cdf0e10cSrcweir 		case RID_SVXPAGE_TOOLBARS:
886*cdf0e10cSrcweir         case RID_SVXPAGE_KEYBOARD:
887*cdf0e10cSrcweir             {
888*cdf0e10cSrcweir                 rPage.SetFrame(m_xFrame);
889*cdf0e10cSrcweir             }
890*cdf0e10cSrcweir 			break;
891*cdf0e10cSrcweir         case RID_SVXPAGE_EVENTS:
892*cdf0e10cSrcweir             {
893*cdf0e10cSrcweir                 dynamic_cast< SvxEventConfigPage& >( rPage ).LateInit( m_xFrame );
894*cdf0e10cSrcweir             };
895*cdf0e10cSrcweir             break;
896*cdf0e10cSrcweir 		default:
897*cdf0e10cSrcweir 			break;
898*cdf0e10cSrcweir 	}
899*cdf0e10cSrcweir }
900*cdf0e10cSrcweir 
901*cdf0e10cSrcweir /******************************************************************************
902*cdf0e10cSrcweir  *
903*cdf0e10cSrcweir  * The SaveInData class is used to hold data for entries in the Save In
904*cdf0e10cSrcweir  * ListBox controls in the menu and toolbar tabs
905*cdf0e10cSrcweir  *
906*cdf0e10cSrcweir  ******************************************************************************/
907*cdf0e10cSrcweir 
908*cdf0e10cSrcweir // Initialize static variable which holds default XImageManager
909*cdf0e10cSrcweir uno::Reference< css::ui::XImageManager>* SaveInData::xDefaultImgMgr = NULL;
910*cdf0e10cSrcweir 
911*cdf0e10cSrcweir SaveInData::SaveInData(
912*cdf0e10cSrcweir 	const uno::Reference< css::ui::XUIConfigurationManager >& xCfgMgr,
913*cdf0e10cSrcweir     const uno::Reference< css::ui::XUIConfigurationManager >& xParentCfgMgr,
914*cdf0e10cSrcweir 	const OUString& aModuleId,
915*cdf0e10cSrcweir 	bool isDocConfig )
916*cdf0e10cSrcweir 		:
917*cdf0e10cSrcweir 			bModified( sal_False ),
918*cdf0e10cSrcweir 			bDocConfig( isDocConfig ),
919*cdf0e10cSrcweir 			bReadOnly( sal_False ),
920*cdf0e10cSrcweir 			m_xCfgMgr( xCfgMgr ),
921*cdf0e10cSrcweir             m_xParentCfgMgr( xParentCfgMgr )
922*cdf0e10cSrcweir {
923*cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xProps(
924*cdf0e10cSrcweir 		::comphelper::getProcessServiceFactory(), uno::UNO_QUERY );
925*cdf0e10cSrcweir 
926*cdf0e10cSrcweir     xProps->getPropertyValue(
927*cdf0e10cSrcweir 		OUString::createFromAscii( "DefaultContext" ))
928*cdf0e10cSrcweir 			>>= m_xComponentContext;
929*cdf0e10cSrcweir 
930*cdf0e10cSrcweir     m_aSeparatorSeq.realloc( 1 );
931*cdf0e10cSrcweir     m_aSeparatorSeq[0].Name  = OUString(
932*cdf0e10cSrcweir 		RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_TYPE ) );
933*cdf0e10cSrcweir     m_aSeparatorSeq[0].Value <<= css::ui::ItemType::SEPARATOR_LINE;
934*cdf0e10cSrcweir 
935*cdf0e10cSrcweir 	if ( bDocConfig )
936*cdf0e10cSrcweir 	{
937*cdf0e10cSrcweir 		uno::Reference< css::ui::XUIConfigurationPersistence >
938*cdf0e10cSrcweir 			xDocPersistence( GetConfigManager(), uno::UNO_QUERY );
939*cdf0e10cSrcweir 
940*cdf0e10cSrcweir 		bReadOnly = xDocPersistence->isReadOnly();
941*cdf0e10cSrcweir 	}
942*cdf0e10cSrcweir 
943*cdf0e10cSrcweir 	m_xServiceManager = uno::Reference< lang::XMultiServiceFactory >(
944*cdf0e10cSrcweir 		::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
945*cdf0e10cSrcweir 
946*cdf0e10cSrcweir 	uno::Reference< container::XNameAccess > xNameAccess(
947*cdf0e10cSrcweir 		m_xServiceManager->createInstance(
948*cdf0e10cSrcweir 			OUString( RTL_CONSTASCII_USTRINGPARAM(
949*cdf0e10cSrcweir 				"com.sun.star.frame.UICommandDescription" ) ) ),
950*cdf0e10cSrcweir 		uno::UNO_QUERY );
951*cdf0e10cSrcweir 
952*cdf0e10cSrcweir 	if ( xNameAccess.is() )
953*cdf0e10cSrcweir 		xNameAccess->getByName( aModuleId ) >>= m_xCommandToLabelMap;
954*cdf0e10cSrcweir 
955*cdf0e10cSrcweir 	if ( !m_xImgMgr.is() )
956*cdf0e10cSrcweir 	{
957*cdf0e10cSrcweir 		m_xImgMgr = uno::Reference< css::ui::XImageManager >(
958*cdf0e10cSrcweir 			GetConfigManager()->getImageManager(), uno::UNO_QUERY );
959*cdf0e10cSrcweir 	}
960*cdf0e10cSrcweir 
961*cdf0e10cSrcweir 	if ( !IsDocConfig() )
962*cdf0e10cSrcweir 	{
963*cdf0e10cSrcweir 	    // If this is not a document configuration then it is the settings
964*cdf0e10cSrcweir 	    // for the module (writer, calc, impress etc.) Use this as the default
965*cdf0e10cSrcweir 	    // XImageManager instance
966*cdf0e10cSrcweir 		xDefaultImgMgr = &m_xImgMgr;
967*cdf0e10cSrcweir 	}
968*cdf0e10cSrcweir     else
969*cdf0e10cSrcweir     {
970*cdf0e10cSrcweir         // If this is a document configuration then use the module image manager
971*cdf0e10cSrcweir         // as default.
972*cdf0e10cSrcweir         if ( m_xParentCfgMgr.is() )
973*cdf0e10cSrcweir         {
974*cdf0e10cSrcweir             m_xParentImgMgr = uno::Reference< css::ui::XImageManager >(
975*cdf0e10cSrcweir                 m_xParentCfgMgr->getImageManager(), uno::UNO_QUERY );
976*cdf0e10cSrcweir             xDefaultImgMgr = &m_xParentImgMgr;
977*cdf0e10cSrcweir         }
978*cdf0e10cSrcweir     }
979*cdf0e10cSrcweir }
980*cdf0e10cSrcweir 
981*cdf0e10cSrcweir uno::Reference< graphic::XGraphic > GetGraphic(
982*cdf0e10cSrcweir 	const uno::Reference< css::ui::XImageManager >& xImageManager,
983*cdf0e10cSrcweir 	const OUString& rCommandURL )
984*cdf0e10cSrcweir {
985*cdf0e10cSrcweir 	uno::Reference< graphic::XGraphic > result;
986*cdf0e10cSrcweir 
987*cdf0e10cSrcweir 	if ( xImageManager.is() )
988*cdf0e10cSrcweir 	{
989*cdf0e10cSrcweir 		// TODO handle large and high contrast graphics
990*cdf0e10cSrcweir 		uno::Sequence< uno::Reference< graphic::XGraphic > > aGraphicSeq;
991*cdf0e10cSrcweir 
992*cdf0e10cSrcweir 		uno::Sequence< OUString > aImageCmdSeq( 1 );
993*cdf0e10cSrcweir 		aImageCmdSeq[0] = rCommandURL;
994*cdf0e10cSrcweir 
995*cdf0e10cSrcweir 		try
996*cdf0e10cSrcweir 		{
997*cdf0e10cSrcweir 			aGraphicSeq =
998*cdf0e10cSrcweir 				xImageManager->getImages( GetImageType(), aImageCmdSeq );
999*cdf0e10cSrcweir 
1000*cdf0e10cSrcweir 			if ( aGraphicSeq.getLength() > 0 )
1001*cdf0e10cSrcweir 			{
1002*cdf0e10cSrcweir 				result =  aGraphicSeq[0];
1003*cdf0e10cSrcweir 			}
1004*cdf0e10cSrcweir 		}
1005*cdf0e10cSrcweir 		catch ( uno::Exception& )
1006*cdf0e10cSrcweir 		{
1007*cdf0e10cSrcweir 			// will return empty XGraphic
1008*cdf0e10cSrcweir 		}
1009*cdf0e10cSrcweir 	}
1010*cdf0e10cSrcweir 
1011*cdf0e10cSrcweir 	return result;
1012*cdf0e10cSrcweir }
1013*cdf0e10cSrcweir 
1014*cdf0e10cSrcweir Image SaveInData::GetImage( const OUString& rCommandURL )
1015*cdf0e10cSrcweir {
1016*cdf0e10cSrcweir 	Image aImage;
1017*cdf0e10cSrcweir 
1018*cdf0e10cSrcweir 	uno::Reference< graphic::XGraphic > xGraphic =
1019*cdf0e10cSrcweir 		GetGraphic( m_xImgMgr, rCommandURL );
1020*cdf0e10cSrcweir 
1021*cdf0e10cSrcweir 	if ( xGraphic.is() )
1022*cdf0e10cSrcweir 	{
1023*cdf0e10cSrcweir 		aImage = Image( xGraphic );
1024*cdf0e10cSrcweir 	}
1025*cdf0e10cSrcweir 	else if ( xDefaultImgMgr != NULL && (*xDefaultImgMgr).is() )
1026*cdf0e10cSrcweir 	{
1027*cdf0e10cSrcweir 		xGraphic = GetGraphic( (*xDefaultImgMgr), rCommandURL );
1028*cdf0e10cSrcweir 
1029*cdf0e10cSrcweir 		if ( xGraphic.is() )
1030*cdf0e10cSrcweir 		{
1031*cdf0e10cSrcweir 			aImage = Image( xGraphic );
1032*cdf0e10cSrcweir 		}
1033*cdf0e10cSrcweir 	}
1034*cdf0e10cSrcweir 
1035*cdf0e10cSrcweir 	return aImage;
1036*cdf0e10cSrcweir }
1037*cdf0e10cSrcweir 
1038*cdf0e10cSrcweir bool SaveInData::PersistChanges(
1039*cdf0e10cSrcweir 	const uno::Reference< uno::XInterface >& xManager )
1040*cdf0e10cSrcweir {
1041*cdf0e10cSrcweir 	bool result = sal_True;
1042*cdf0e10cSrcweir 
1043*cdf0e10cSrcweir 	try
1044*cdf0e10cSrcweir 	{
1045*cdf0e10cSrcweir 		if ( xManager.is() && !IsReadOnly() )
1046*cdf0e10cSrcweir 		{
1047*cdf0e10cSrcweir 			uno::Reference< css::ui::XUIConfigurationPersistence >
1048*cdf0e10cSrcweir 				xConfigPersistence( xManager, uno::UNO_QUERY );
1049*cdf0e10cSrcweir 
1050*cdf0e10cSrcweir 			if ( xConfigPersistence->isModified() )
1051*cdf0e10cSrcweir 			{
1052*cdf0e10cSrcweir 				xConfigPersistence->store();
1053*cdf0e10cSrcweir 			}
1054*cdf0e10cSrcweir 		}
1055*cdf0e10cSrcweir 	}
1056*cdf0e10cSrcweir 	catch ( com::sun::star::io::IOException& )
1057*cdf0e10cSrcweir 	{
1058*cdf0e10cSrcweir 		result = sal_False;
1059*cdf0e10cSrcweir 	}
1060*cdf0e10cSrcweir 
1061*cdf0e10cSrcweir 	return result;
1062*cdf0e10cSrcweir }
1063*cdf0e10cSrcweir 
1064*cdf0e10cSrcweir /******************************************************************************
1065*cdf0e10cSrcweir  *
1066*cdf0e10cSrcweir  * The MenuSaveInData class extends SaveInData and provides menu specific
1067*cdf0e10cSrcweir  * load and store functionality.
1068*cdf0e10cSrcweir  *
1069*cdf0e10cSrcweir  ******************************************************************************/
1070*cdf0e10cSrcweir 
1071*cdf0e10cSrcweir // Initialize static variable which holds default Menu data
1072*cdf0e10cSrcweir MenuSaveInData* MenuSaveInData::pDefaultData = NULL;
1073*cdf0e10cSrcweir 
1074*cdf0e10cSrcweir MenuSaveInData::MenuSaveInData(
1075*cdf0e10cSrcweir 	const uno::Reference< css::ui::XUIConfigurationManager >& cfgmgr,
1076*cdf0e10cSrcweir     const uno::Reference< css::ui::XUIConfigurationManager >& xParentCfgMgr,
1077*cdf0e10cSrcweir 	const OUString& aModuleId,
1078*cdf0e10cSrcweir 	bool isDocConfig )
1079*cdf0e10cSrcweir 	:
1080*cdf0e10cSrcweir 		SaveInData( cfgmgr, xParentCfgMgr, aModuleId, isDocConfig ),
1081*cdf0e10cSrcweir 		m_aMenuResourceURL(
1082*cdf0e10cSrcweir 			RTL_CONSTASCII_USTRINGPARAM( ITEM_MENUBAR_URL ) ),
1083*cdf0e10cSrcweir 		m_aDescriptorContainer(
1084*cdf0e10cSrcweir 			RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_CONTAINER ) ),
1085*cdf0e10cSrcweir 		pRootEntry( 0 )
1086*cdf0e10cSrcweir {
1087*cdf0e10cSrcweir 	try
1088*cdf0e10cSrcweir 	{
1089*cdf0e10cSrcweir 		OUString url( RTL_CONSTASCII_USTRINGPARAM( ITEM_MENUBAR_URL ) );
1090*cdf0e10cSrcweir 		m_xMenuSettings = GetConfigManager()->getSettings( url, sal_False );
1091*cdf0e10cSrcweir 	}
1092*cdf0e10cSrcweir 	catch ( container::NoSuchElementException& )
1093*cdf0e10cSrcweir 	{
1094*cdf0e10cSrcweir 		// will use menu settings for the module
1095*cdf0e10cSrcweir 	}
1096*cdf0e10cSrcweir 
1097*cdf0e10cSrcweir 	// If this is not a document configuration then it is the settings
1098*cdf0e10cSrcweir 	// for the module (writer, calc, impress etc.). These settings should
1099*cdf0e10cSrcweir 	// be set as the default to be used for SaveIn locations that do not
1100*cdf0e10cSrcweir 	// have custom settings
1101*cdf0e10cSrcweir 	if ( !IsDocConfig() )
1102*cdf0e10cSrcweir 	{
1103*cdf0e10cSrcweir 		SetDefaultData( this );
1104*cdf0e10cSrcweir 	}
1105*cdf0e10cSrcweir }
1106*cdf0e10cSrcweir 
1107*cdf0e10cSrcweir MenuSaveInData::~MenuSaveInData()
1108*cdf0e10cSrcweir {
1109*cdf0e10cSrcweir 	if ( pRootEntry != NULL )
1110*cdf0e10cSrcweir 	{
1111*cdf0e10cSrcweir 		delete pRootEntry;
1112*cdf0e10cSrcweir 	}
1113*cdf0e10cSrcweir }
1114*cdf0e10cSrcweir 
1115*cdf0e10cSrcweir SvxEntries*
1116*cdf0e10cSrcweir MenuSaveInData::GetEntries()
1117*cdf0e10cSrcweir {
1118*cdf0e10cSrcweir 	if ( pRootEntry == NULL )
1119*cdf0e10cSrcweir 	{
1120*cdf0e10cSrcweir 		pRootEntry = new SvxConfigEntry(
1121*cdf0e10cSrcweir 			String::CreateFromAscii("MainMenus"), String(), sal_True );
1122*cdf0e10cSrcweir 
1123*cdf0e10cSrcweir 		if ( m_xMenuSettings.is() )
1124*cdf0e10cSrcweir 		{
1125*cdf0e10cSrcweir 			LoadSubMenus( m_xMenuSettings, String(), pRootEntry );
1126*cdf0e10cSrcweir 		}
1127*cdf0e10cSrcweir 		else if ( GetDefaultData() != NULL )
1128*cdf0e10cSrcweir 		{
1129*cdf0e10cSrcweir 			// If the doc has no config settings use module config settings
1130*cdf0e10cSrcweir 			LoadSubMenus( GetDefaultData()->m_xMenuSettings, String(), pRootEntry );
1131*cdf0e10cSrcweir 		}
1132*cdf0e10cSrcweir 	}
1133*cdf0e10cSrcweir 
1134*cdf0e10cSrcweir 	return pRootEntry->GetEntries();
1135*cdf0e10cSrcweir }
1136*cdf0e10cSrcweir 
1137*cdf0e10cSrcweir void
1138*cdf0e10cSrcweir MenuSaveInData::SetEntries( SvxEntries* pNewEntries )
1139*cdf0e10cSrcweir {
1140*cdf0e10cSrcweir 	// delete old menu hierarchy first
1141*cdf0e10cSrcweir 	if ( pRootEntry != NULL )
1142*cdf0e10cSrcweir 	{
1143*cdf0e10cSrcweir 		delete pRootEntry->GetEntries();
1144*cdf0e10cSrcweir 	}
1145*cdf0e10cSrcweir 
1146*cdf0e10cSrcweir 	// now set new menu hierarchy
1147*cdf0e10cSrcweir 	pRootEntry->SetEntries( pNewEntries );
1148*cdf0e10cSrcweir }
1149*cdf0e10cSrcweir 
1150*cdf0e10cSrcweir bool MenuSaveInData::LoadSubMenus(
1151*cdf0e10cSrcweir 	const uno::Reference< container::XIndexAccess >& xMenuSettings,
1152*cdf0e10cSrcweir 	const OUString& rBaseTitle,
1153*cdf0e10cSrcweir 	SvxConfigEntry* pParentData )
1154*cdf0e10cSrcweir {
1155*cdf0e10cSrcweir 	SvxEntries* pEntries = pParentData->GetEntries();
1156*cdf0e10cSrcweir 
1157*cdf0e10cSrcweir     // Don't access non existing menu configuration!
1158*cdf0e10cSrcweir     if ( !xMenuSettings.is() )
1159*cdf0e10cSrcweir         return true;
1160*cdf0e10cSrcweir 
1161*cdf0e10cSrcweir     for ( sal_Int32 nIndex = 0; nIndex < xMenuSettings->getCount(); nIndex++ )
1162*cdf0e10cSrcweir     {
1163*cdf0e10cSrcweir         uno::Reference< container::XIndexAccess >	xSubMenu;
1164*cdf0e10cSrcweir         OUString				aCommandURL;
1165*cdf0e10cSrcweir         OUString				aLabel;
1166*cdf0e10cSrcweir 		bool					bIsUserDefined = sal_True;
1167*cdf0e10cSrcweir 
1168*cdf0e10cSrcweir         sal_uInt16 nType( css::ui::ItemType::DEFAULT );
1169*cdf0e10cSrcweir 
1170*cdf0e10cSrcweir         bool bItem = GetMenuItemData( xMenuSettings, nIndex,
1171*cdf0e10cSrcweir 			aCommandURL, aLabel, nType, xSubMenu );
1172*cdf0e10cSrcweir 
1173*cdf0e10cSrcweir         if ( bItem )
1174*cdf0e10cSrcweir         {
1175*cdf0e10cSrcweir             if ( nType == css::ui::ItemType::DEFAULT )
1176*cdf0e10cSrcweir             {
1177*cdf0e10cSrcweir 				uno::Any a;
1178*cdf0e10cSrcweir 				try
1179*cdf0e10cSrcweir 				{
1180*cdf0e10cSrcweir 					a = m_xCommandToLabelMap->getByName( aCommandURL );
1181*cdf0e10cSrcweir 					bIsUserDefined = sal_False;
1182*cdf0e10cSrcweir 				}
1183*cdf0e10cSrcweir 				catch ( container::NoSuchElementException& )
1184*cdf0e10cSrcweir 				{
1185*cdf0e10cSrcweir 					bIsUserDefined = sal_True;
1186*cdf0e10cSrcweir 				}
1187*cdf0e10cSrcweir 
1188*cdf0e10cSrcweir 				// If custom label not set retrieve it from the command
1189*cdf0e10cSrcweir 				// to info service
1190*cdf0e10cSrcweir 				if ( aLabel.equals( OUString() ) )
1191*cdf0e10cSrcweir 				{
1192*cdf0e10cSrcweir 					uno::Sequence< beans::PropertyValue > aPropSeq;
1193*cdf0e10cSrcweir 					if ( a >>= aPropSeq )
1194*cdf0e10cSrcweir 					{
1195*cdf0e10cSrcweir 						for ( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
1196*cdf0e10cSrcweir 						{
1197*cdf0e10cSrcweir 							if ( aPropSeq[i].Name.equalsAscii( ITEM_DESCRIPTOR_LABEL ) )
1198*cdf0e10cSrcweir 							{
1199*cdf0e10cSrcweir 								aPropSeq[i].Value >>= aLabel;
1200*cdf0e10cSrcweir 								break;
1201*cdf0e10cSrcweir 							}
1202*cdf0e10cSrcweir 						}
1203*cdf0e10cSrcweir 					}
1204*cdf0e10cSrcweir 				}
1205*cdf0e10cSrcweir 
1206*cdf0e10cSrcweir                 if ( xSubMenu.is() )
1207*cdf0e10cSrcweir                 {
1208*cdf0e10cSrcweir                     // popup menu
1209*cdf0e10cSrcweir 					SvxConfigEntry* pEntry = new SvxConfigEntry(
1210*cdf0e10cSrcweir 						aLabel, aCommandURL, sal_True );
1211*cdf0e10cSrcweir 
1212*cdf0e10cSrcweir 					pEntry->SetUserDefined( bIsUserDefined );
1213*cdf0e10cSrcweir 
1214*cdf0e10cSrcweir 					pEntries->push_back( pEntry );
1215*cdf0e10cSrcweir 
1216*cdf0e10cSrcweir 					OUString subMenuTitle( rBaseTitle );
1217*cdf0e10cSrcweir 
1218*cdf0e10cSrcweir 					if ( subMenuTitle.getLength() != 0 )
1219*cdf0e10cSrcweir 					{
1220*cdf0e10cSrcweir 						subMenuTitle +=
1221*cdf0e10cSrcweir 							OUString::createFromAscii(pMenuSeparatorStr);
1222*cdf0e10cSrcweir 					}
1223*cdf0e10cSrcweir 					else
1224*cdf0e10cSrcweir 					{
1225*cdf0e10cSrcweir 						pEntry->SetMain( sal_True );
1226*cdf0e10cSrcweir 					}
1227*cdf0e10cSrcweir 
1228*cdf0e10cSrcweir 					subMenuTitle += stripHotKey( aLabel );
1229*cdf0e10cSrcweir 
1230*cdf0e10cSrcweir 					LoadSubMenus( xSubMenu, subMenuTitle, pEntry );
1231*cdf0e10cSrcweir                 }
1232*cdf0e10cSrcweir                 else
1233*cdf0e10cSrcweir                 {
1234*cdf0e10cSrcweir                     SvxConfigEntry* pEntry = new SvxConfigEntry(
1235*cdf0e10cSrcweir 						aLabel, aCommandURL, sal_False );
1236*cdf0e10cSrcweir 					pEntry->SetUserDefined( bIsUserDefined );
1237*cdf0e10cSrcweir 					pEntries->push_back( pEntry );
1238*cdf0e10cSrcweir                 }
1239*cdf0e10cSrcweir             }
1240*cdf0e10cSrcweir             else
1241*cdf0e10cSrcweir             {
1242*cdf0e10cSrcweir 				SvxConfigEntry* pEntry = new SvxConfigEntry;
1243*cdf0e10cSrcweir 				pEntry->SetUserDefined( bIsUserDefined );
1244*cdf0e10cSrcweir 				pEntries->push_back( pEntry );
1245*cdf0e10cSrcweir             }
1246*cdf0e10cSrcweir         }
1247*cdf0e10cSrcweir     }
1248*cdf0e10cSrcweir 	return true;
1249*cdf0e10cSrcweir }
1250*cdf0e10cSrcweir 
1251*cdf0e10cSrcweir bool MenuSaveInData::Apply()
1252*cdf0e10cSrcweir {
1253*cdf0e10cSrcweir 	bool result = sal_False;
1254*cdf0e10cSrcweir 
1255*cdf0e10cSrcweir 	if ( IsModified() )
1256*cdf0e10cSrcweir 	{
1257*cdf0e10cSrcweir         // Apply new menu bar structure to our settings container
1258*cdf0e10cSrcweir         m_xMenuSettings = uno::Reference< container::XIndexAccess >(
1259*cdf0e10cSrcweir 			GetConfigManager()->createSettings(), uno::UNO_QUERY );
1260*cdf0e10cSrcweir 
1261*cdf0e10cSrcweir         uno::Reference< container::XIndexContainer > xIndexContainer (
1262*cdf0e10cSrcweir 			m_xMenuSettings, uno::UNO_QUERY );
1263*cdf0e10cSrcweir 
1264*cdf0e10cSrcweir         uno::Reference< lang::XSingleComponentFactory > xFactory (
1265*cdf0e10cSrcweir 			m_xMenuSettings, uno::UNO_QUERY );
1266*cdf0e10cSrcweir 
1267*cdf0e10cSrcweir         Apply( pRootEntry, xIndexContainer, xFactory, NULL );
1268*cdf0e10cSrcweir 
1269*cdf0e10cSrcweir         try
1270*cdf0e10cSrcweir         {
1271*cdf0e10cSrcweir 			if ( GetConfigManager()->hasSettings( m_aMenuResourceURL ) )
1272*cdf0e10cSrcweir 			{
1273*cdf0e10cSrcweir             	GetConfigManager()->replaceSettings(
1274*cdf0e10cSrcweir 					m_aMenuResourceURL, m_xMenuSettings );
1275*cdf0e10cSrcweir 			}
1276*cdf0e10cSrcweir 			else
1277*cdf0e10cSrcweir 			{
1278*cdf0e10cSrcweir             	GetConfigManager()->insertSettings(
1279*cdf0e10cSrcweir 					m_aMenuResourceURL, m_xMenuSettings );
1280*cdf0e10cSrcweir 			}
1281*cdf0e10cSrcweir         }
1282*cdf0e10cSrcweir         catch ( container::NoSuchElementException& )
1283*cdf0e10cSrcweir         {
1284*cdf0e10cSrcweir 			OSL_TRACE("caught container::NoSuchElementException saving settings");
1285*cdf0e10cSrcweir         }
1286*cdf0e10cSrcweir         catch ( com::sun::star::io::IOException& )
1287*cdf0e10cSrcweir         {
1288*cdf0e10cSrcweir 			OSL_TRACE("caught IOException saving settings");
1289*cdf0e10cSrcweir         }
1290*cdf0e10cSrcweir         catch ( com::sun::star::uno::Exception& )
1291*cdf0e10cSrcweir 		{
1292*cdf0e10cSrcweir 			OSL_TRACE("caught some other exception saving settings");
1293*cdf0e10cSrcweir 		}
1294*cdf0e10cSrcweir 
1295*cdf0e10cSrcweir         SetModified( sal_False );
1296*cdf0e10cSrcweir 
1297*cdf0e10cSrcweir 		result = PersistChanges( GetConfigManager() );
1298*cdf0e10cSrcweir 	}
1299*cdf0e10cSrcweir 
1300*cdf0e10cSrcweir 	return result;
1301*cdf0e10cSrcweir }
1302*cdf0e10cSrcweir 
1303*cdf0e10cSrcweir void MenuSaveInData::Apply(
1304*cdf0e10cSrcweir 	SvxConfigEntry* pRootEntry_,
1305*cdf0e10cSrcweir 	uno::Reference< container::XIndexContainer >& rMenuBar,
1306*cdf0e10cSrcweir 	uno::Reference< lang::XSingleComponentFactory >& rFactory,
1307*cdf0e10cSrcweir 	SvLBoxEntry *pParentEntry )
1308*cdf0e10cSrcweir {
1309*cdf0e10cSrcweir 	(void)pRootEntry_;
1310*cdf0e10cSrcweir 	(void)pParentEntry;
1311*cdf0e10cSrcweir 
1312*cdf0e10cSrcweir 	SvxEntries::const_iterator iter = GetEntries()->begin();
1313*cdf0e10cSrcweir 	SvxEntries::const_iterator end = GetEntries()->end();
1314*cdf0e10cSrcweir 
1315*cdf0e10cSrcweir 	for ( ; iter != end; iter++ )
1316*cdf0e10cSrcweir 	{
1317*cdf0e10cSrcweir 		SvxConfigEntry* pEntryData = *iter;
1318*cdf0e10cSrcweir 
1319*cdf0e10cSrcweir 		uno::Sequence< beans::PropertyValue > aPropValueSeq =
1320*cdf0e10cSrcweir 			ConvertSvxConfigEntry( m_xCommandToLabelMap, pEntryData );
1321*cdf0e10cSrcweir 
1322*cdf0e10cSrcweir 		uno::Reference< container::XIndexContainer > xSubMenuBar(
1323*cdf0e10cSrcweir 			rFactory->createInstanceWithContext( m_xComponentContext ),
1324*cdf0e10cSrcweir 			uno::UNO_QUERY );
1325*cdf0e10cSrcweir 
1326*cdf0e10cSrcweir 		sal_Int32 nIndex = aPropValueSeq.getLength();
1327*cdf0e10cSrcweir 		aPropValueSeq.realloc( nIndex + 1 );
1328*cdf0e10cSrcweir 		aPropValueSeq[nIndex].Name = m_aDescriptorContainer;
1329*cdf0e10cSrcweir 		aPropValueSeq[nIndex].Value <<= xSubMenuBar;
1330*cdf0e10cSrcweir 		rMenuBar->insertByIndex(
1331*cdf0e10cSrcweir 			rMenuBar->getCount(), uno::makeAny( aPropValueSeq ));
1332*cdf0e10cSrcweir 		ApplyMenu( xSubMenuBar, rFactory, pEntryData );
1333*cdf0e10cSrcweir 	}
1334*cdf0e10cSrcweir }
1335*cdf0e10cSrcweir 
1336*cdf0e10cSrcweir void MenuSaveInData::ApplyMenu(
1337*cdf0e10cSrcweir 	uno::Reference< container::XIndexContainer >& rMenuBar,
1338*cdf0e10cSrcweir 	uno::Reference< lang::XSingleComponentFactory >& rFactory,
1339*cdf0e10cSrcweir 	SvxConfigEntry* pMenuData )
1340*cdf0e10cSrcweir {
1341*cdf0e10cSrcweir 	SvxEntries::const_iterator iter = pMenuData->GetEntries()->begin();
1342*cdf0e10cSrcweir 	SvxEntries::const_iterator end = pMenuData->GetEntries()->end();
1343*cdf0e10cSrcweir 
1344*cdf0e10cSrcweir 	for ( ; iter != end; iter++ )
1345*cdf0e10cSrcweir 	{
1346*cdf0e10cSrcweir 		SvxConfigEntry* pEntry = *iter;
1347*cdf0e10cSrcweir 
1348*cdf0e10cSrcweir 		if ( pEntry->IsPopup() )
1349*cdf0e10cSrcweir 		{
1350*cdf0e10cSrcweir 			uno::Sequence< beans::PropertyValue > aPropValueSeq =
1351*cdf0e10cSrcweir 				ConvertSvxConfigEntry( m_xCommandToLabelMap, pEntry );
1352*cdf0e10cSrcweir 
1353*cdf0e10cSrcweir 			uno::Reference< container::XIndexContainer > xSubMenuBar(
1354*cdf0e10cSrcweir 				rFactory->createInstanceWithContext( m_xComponentContext ),
1355*cdf0e10cSrcweir 					uno::UNO_QUERY );
1356*cdf0e10cSrcweir 
1357*cdf0e10cSrcweir 			sal_Int32 nIndex = aPropValueSeq.getLength();
1358*cdf0e10cSrcweir 			aPropValueSeq.realloc( nIndex + 1 );
1359*cdf0e10cSrcweir 			aPropValueSeq[nIndex].Name = m_aDescriptorContainer;
1360*cdf0e10cSrcweir 			aPropValueSeq[nIndex].Value <<= xSubMenuBar;
1361*cdf0e10cSrcweir 
1362*cdf0e10cSrcweir 			rMenuBar->insertByIndex(
1363*cdf0e10cSrcweir 				rMenuBar->getCount(), uno::makeAny( aPropValueSeq ));
1364*cdf0e10cSrcweir 
1365*cdf0e10cSrcweir 			ApplyMenu( xSubMenuBar, rFactory, pEntry );
1366*cdf0e10cSrcweir 		}
1367*cdf0e10cSrcweir 		else if ( pEntry->IsSeparator() )
1368*cdf0e10cSrcweir 		{
1369*cdf0e10cSrcweir 			rMenuBar->insertByIndex(
1370*cdf0e10cSrcweir 				rMenuBar->getCount(), uno::makeAny( m_aSeparatorSeq ));
1371*cdf0e10cSrcweir 		}
1372*cdf0e10cSrcweir 		else
1373*cdf0e10cSrcweir 		{
1374*cdf0e10cSrcweir 			uno::Sequence< beans::PropertyValue > aPropValueSeq =
1375*cdf0e10cSrcweir 				ConvertSvxConfigEntry( m_xCommandToLabelMap, pEntry );
1376*cdf0e10cSrcweir 			rMenuBar->insertByIndex(
1377*cdf0e10cSrcweir 				rMenuBar->getCount(), uno::makeAny( aPropValueSeq ));
1378*cdf0e10cSrcweir 		}
1379*cdf0e10cSrcweir 	}
1380*cdf0e10cSrcweir }
1381*cdf0e10cSrcweir 
1382*cdf0e10cSrcweir void
1383*cdf0e10cSrcweir MenuSaveInData::Reset()
1384*cdf0e10cSrcweir {
1385*cdf0e10cSrcweir 	GetConfigManager()->reset();
1386*cdf0e10cSrcweir 
1387*cdf0e10cSrcweir 	delete pRootEntry;
1388*cdf0e10cSrcweir 	pRootEntry = NULL;
1389*cdf0e10cSrcweir 
1390*cdf0e10cSrcweir 	try
1391*cdf0e10cSrcweir 	{
1392*cdf0e10cSrcweir 		m_xMenuSettings = GetConfigManager()->getSettings(
1393*cdf0e10cSrcweir 			m_aMenuResourceURL, sal_False );
1394*cdf0e10cSrcweir 	}
1395*cdf0e10cSrcweir 	catch ( container::NoSuchElementException& )
1396*cdf0e10cSrcweir 	{
1397*cdf0e10cSrcweir 		// will use default settings
1398*cdf0e10cSrcweir 	}
1399*cdf0e10cSrcweir }
1400*cdf0e10cSrcweir 
1401*cdf0e10cSrcweir class PopupPainter : public SvLBoxString
1402*cdf0e10cSrcweir {
1403*cdf0e10cSrcweir public:
1404*cdf0e10cSrcweir 	PopupPainter( SvLBoxEntry* pEntry, const String& rStr )
1405*cdf0e10cSrcweir 		: SvLBoxString( pEntry, 0, rStr )
1406*cdf0e10cSrcweir 	{ }
1407*cdf0e10cSrcweir 
1408*cdf0e10cSrcweir 	~PopupPainter() { }
1409*cdf0e10cSrcweir 
1410*cdf0e10cSrcweir 	void Paint( const Point& rPos, SvLBox& rOutDev,
1411*cdf0e10cSrcweir 		sal_uInt16 nViewDataEntryFlags, SvLBoxEntry* pEntry )
1412*cdf0e10cSrcweir 	{
1413*cdf0e10cSrcweir 		SvLBoxString::Paint( rPos, rOutDev, nViewDataEntryFlags, pEntry );
1414*cdf0e10cSrcweir 
1415*cdf0e10cSrcweir 		Color aOldFillColor = rOutDev.GetFillColor();
1416*cdf0e10cSrcweir 
1417*cdf0e10cSrcweir 		SvTreeListBox* pTreeBox = static_cast< SvTreeListBox* >( &rOutDev );
1418*cdf0e10cSrcweir 		long nX = pTreeBox->GetSizePixel().Width();
1419*cdf0e10cSrcweir 
1420*cdf0e10cSrcweir 		ScrollBar* pVScroll = pTreeBox->GetVScroll();
1421*cdf0e10cSrcweir 		if ( pVScroll->IsVisible() )
1422*cdf0e10cSrcweir 		{
1423*cdf0e10cSrcweir 			nX -= pVScroll->GetSizePixel().Width();
1424*cdf0e10cSrcweir 		}
1425*cdf0e10cSrcweir 
1426*cdf0e10cSrcweir 		SvViewDataItem* pItem = rOutDev.GetViewDataItem( pEntry, this );
1427*cdf0e10cSrcweir 		nX -= pItem->aSize.Height();
1428*cdf0e10cSrcweir 
1429*cdf0e10cSrcweir 		long nSize = pItem->aSize.Height() / 2;
1430*cdf0e10cSrcweir 		long nHalfSize = nSize / 2;
1431*cdf0e10cSrcweir 		long nY = rPos.Y() + nHalfSize;
1432*cdf0e10cSrcweir 
1433*cdf0e10cSrcweir 		if ( aOldFillColor == COL_WHITE )
1434*cdf0e10cSrcweir 		{
1435*cdf0e10cSrcweir 			rOutDev.SetFillColor( Color( COL_BLACK ) );
1436*cdf0e10cSrcweir 		}
1437*cdf0e10cSrcweir 		else
1438*cdf0e10cSrcweir 		{
1439*cdf0e10cSrcweir 			rOutDev.SetFillColor( Color( COL_WHITE ) );
1440*cdf0e10cSrcweir 		}
1441*cdf0e10cSrcweir 
1442*cdf0e10cSrcweir 		long n = 0;
1443*cdf0e10cSrcweir 		while ( n <= nHalfSize )
1444*cdf0e10cSrcweir 		{
1445*cdf0e10cSrcweir 			rOutDev.DrawRect( Rectangle( nX+n, nY+n, nX+n, nY+nSize-n ) );
1446*cdf0e10cSrcweir 			n++;
1447*cdf0e10cSrcweir 		}
1448*cdf0e10cSrcweir 
1449*cdf0e10cSrcweir 		rOutDev.SetFillColor( aOldFillColor );
1450*cdf0e10cSrcweir 	}
1451*cdf0e10cSrcweir };
1452*cdf0e10cSrcweir 
1453*cdf0e10cSrcweir /******************************************************************************
1454*cdf0e10cSrcweir  *
1455*cdf0e10cSrcweir  * SvxMenuEntriesListBox is the listbox in which the menu items for a
1456*cdf0e10cSrcweir  * particular menu are shown. We have a custom listbox because we need
1457*cdf0e10cSrcweir  * to add drag'n'drop support from the Macro Selector and within the
1458*cdf0e10cSrcweir  * listbox
1459*cdf0e10cSrcweir  *
1460*cdf0e10cSrcweir  *****************************************************************************/
1461*cdf0e10cSrcweir SvxMenuEntriesListBox::SvxMenuEntriesListBox(
1462*cdf0e10cSrcweir 	Window* pParent, const ResId& rResId)
1463*cdf0e10cSrcweir 	: SvTreeListBox( pParent, rResId )
1464*cdf0e10cSrcweir 	, pPage( (SvxMenuConfigPage*) pParent )
1465*cdf0e10cSrcweir 	, m_bIsInternalDrag( sal_False )
1466*cdf0e10cSrcweir {
1467*cdf0e10cSrcweir 	SetStyle(
1468*cdf0e10cSrcweir 		GetStyle() | WB_CLIPCHILDREN | WB_HSCROLL | WB_HIDESELECTION );
1469*cdf0e10cSrcweir 
1470*cdf0e10cSrcweir 	SetSpaceBetweenEntries( 3 );
1471*cdf0e10cSrcweir 	SetEntryHeight( ENTRY_HEIGHT );
1472*cdf0e10cSrcweir 
1473*cdf0e10cSrcweir 	SetHighlightRange();
1474*cdf0e10cSrcweir 	SetSelectionMode(SINGLE_SELECTION);
1475*cdf0e10cSrcweir 
1476*cdf0e10cSrcweir 	SetDragDropMode( SV_DRAGDROP_CTRL_MOVE	|
1477*cdf0e10cSrcweir 					 SV_DRAGDROP_APP_COPY	|
1478*cdf0e10cSrcweir 					 SV_DRAGDROP_ENABLE_TOP |
1479*cdf0e10cSrcweir 					 SV_DRAGDROP_APP_DROP);
1480*cdf0e10cSrcweir }
1481*cdf0e10cSrcweir 
1482*cdf0e10cSrcweir SvxMenuEntriesListBox::~SvxMenuEntriesListBox()
1483*cdf0e10cSrcweir {
1484*cdf0e10cSrcweir 	// do nothing
1485*cdf0e10cSrcweir }
1486*cdf0e10cSrcweir 
1487*cdf0e10cSrcweir // drag and drop support
1488*cdf0e10cSrcweir DragDropMode SvxMenuEntriesListBox::NotifyStartDrag(
1489*cdf0e10cSrcweir 	TransferDataContainer& aTransferDataContainer, SvLBoxEntry* pEntry )
1490*cdf0e10cSrcweir {
1491*cdf0e10cSrcweir 	(void)aTransferDataContainer;
1492*cdf0e10cSrcweir 	(void)pEntry;
1493*cdf0e10cSrcweir 
1494*cdf0e10cSrcweir 	m_bIsInternalDrag = sal_True;
1495*cdf0e10cSrcweir 	return GetDragDropMode();
1496*cdf0e10cSrcweir }
1497*cdf0e10cSrcweir 
1498*cdf0e10cSrcweir void SvxMenuEntriesListBox::DragFinished( sal_Int8 nDropAction )
1499*cdf0e10cSrcweir {
1500*cdf0e10cSrcweir 	(void)nDropAction;
1501*cdf0e10cSrcweir 	m_bIsInternalDrag = sal_False;
1502*cdf0e10cSrcweir }
1503*cdf0e10cSrcweir 
1504*cdf0e10cSrcweir sal_Int8 SvxMenuEntriesListBox::AcceptDrop( const AcceptDropEvent& rEvt )
1505*cdf0e10cSrcweir {
1506*cdf0e10cSrcweir 	if ( m_bIsInternalDrag )
1507*cdf0e10cSrcweir 	{
1508*cdf0e10cSrcweir 		// internal copy isn't allowed!
1509*cdf0e10cSrcweir 		if ( rEvt.mnAction == DND_ACTION_COPY )
1510*cdf0e10cSrcweir 			return DND_ACTION_NONE;
1511*cdf0e10cSrcweir 		else
1512*cdf0e10cSrcweir 			return SvTreeListBox::AcceptDrop( rEvt );
1513*cdf0e10cSrcweir 	}
1514*cdf0e10cSrcweir 
1515*cdf0e10cSrcweir 	// Always do COPY instead of MOVE if D&D comes from outside!
1516*cdf0e10cSrcweir 	AcceptDropEvent aNewAcceptDropEvent( rEvt );
1517*cdf0e10cSrcweir 	aNewAcceptDropEvent.mnAction = DND_ACTION_COPY;
1518*cdf0e10cSrcweir 	return SvTreeListBox::AcceptDrop( aNewAcceptDropEvent );
1519*cdf0e10cSrcweir }
1520*cdf0e10cSrcweir 
1521*cdf0e10cSrcweir sal_Bool SvxMenuEntriesListBox::NotifyAcceptDrop( SvLBoxEntry* )
1522*cdf0e10cSrcweir {
1523*cdf0e10cSrcweir 	return sal_True;
1524*cdf0e10cSrcweir }
1525*cdf0e10cSrcweir 
1526*cdf0e10cSrcweir sal_Bool SvxMenuEntriesListBox::NotifyMoving(
1527*cdf0e10cSrcweir 	SvLBoxEntry* pTarget, SvLBoxEntry* pSource,
1528*cdf0e10cSrcweir 	SvLBoxEntry*& rpNewParent, sal_uLong& rNewChildPos)
1529*cdf0e10cSrcweir {
1530*cdf0e10cSrcweir 	// only try to do a move if we are dragging within the list box
1531*cdf0e10cSrcweir 	if ( m_bIsInternalDrag )
1532*cdf0e10cSrcweir 	{
1533*cdf0e10cSrcweir 		if ( pPage->MoveEntryData( pSource, pTarget ) == sal_True )
1534*cdf0e10cSrcweir 		{
1535*cdf0e10cSrcweir 			SvTreeListBox::NotifyMoving(
1536*cdf0e10cSrcweir 				pTarget, pSource, rpNewParent, rNewChildPos );
1537*cdf0e10cSrcweir 			return sal_True;
1538*cdf0e10cSrcweir 		}
1539*cdf0e10cSrcweir 		else
1540*cdf0e10cSrcweir 		{
1541*cdf0e10cSrcweir 			return sal_False;
1542*cdf0e10cSrcweir 		}
1543*cdf0e10cSrcweir 	}
1544*cdf0e10cSrcweir 	else
1545*cdf0e10cSrcweir 	{
1546*cdf0e10cSrcweir 		return NotifyCopying( pTarget, pSource, rpNewParent, rNewChildPos );
1547*cdf0e10cSrcweir 	}
1548*cdf0e10cSrcweir }
1549*cdf0e10cSrcweir 
1550*cdf0e10cSrcweir sal_Bool SvxMenuEntriesListBox::NotifyCopying(
1551*cdf0e10cSrcweir     SvLBoxEntry* pTarget, SvLBoxEntry* pSource,
1552*cdf0e10cSrcweir     SvLBoxEntry*& rpNewParent, sal_uLong& rNewChildPos)
1553*cdf0e10cSrcweir {
1554*cdf0e10cSrcweir 	(void)pSource;
1555*cdf0e10cSrcweir 	(void)rpNewParent;
1556*cdf0e10cSrcweir 	(void)rNewChildPos;
1557*cdf0e10cSrcweir 
1558*cdf0e10cSrcweir 	if ( !m_bIsInternalDrag )
1559*cdf0e10cSrcweir 	{
1560*cdf0e10cSrcweir 		// if the target is NULL then add function to the start of the list
1561*cdf0e10cSrcweir 		pPage->AddFunction( pTarget, pTarget == NULL );
1562*cdf0e10cSrcweir 
1563*cdf0e10cSrcweir 		// AddFunction already adds the listbox entry so return FALSE
1564*cdf0e10cSrcweir 		// to stop another listbox entry being added
1565*cdf0e10cSrcweir 		return sal_False;
1566*cdf0e10cSrcweir 	}
1567*cdf0e10cSrcweir 
1568*cdf0e10cSrcweir 	// Copying is only allowed from external controls, not within the listbox
1569*cdf0e10cSrcweir 	return sal_False;
1570*cdf0e10cSrcweir }
1571*cdf0e10cSrcweir 
1572*cdf0e10cSrcweir void SvxMenuEntriesListBox::KeyInput( const KeyEvent& rKeyEvent )
1573*cdf0e10cSrcweir {
1574*cdf0e10cSrcweir 	KeyCode keycode = rKeyEvent.GetKeyCode();
1575*cdf0e10cSrcweir 
1576*cdf0e10cSrcweir 	// support DELETE for removing the current entry
1577*cdf0e10cSrcweir 	if ( keycode == KEY_DELETE )
1578*cdf0e10cSrcweir 	{
1579*cdf0e10cSrcweir 		pPage->DeleteSelectedContent();
1580*cdf0e10cSrcweir 	}
1581*cdf0e10cSrcweir 	// support CTRL+UP and CTRL+DOWN for moving selected entries
1582*cdf0e10cSrcweir 	else if ( keycode.GetCode() == KEY_UP && keycode.IsMod1() )
1583*cdf0e10cSrcweir 	{
1584*cdf0e10cSrcweir 		pPage->MoveEntry( sal_True );
1585*cdf0e10cSrcweir 	}
1586*cdf0e10cSrcweir 	else if ( keycode.GetCode() == KEY_DOWN && keycode.IsMod1() )
1587*cdf0e10cSrcweir 	{
1588*cdf0e10cSrcweir 		pPage->MoveEntry( sal_False );
1589*cdf0e10cSrcweir 	}
1590*cdf0e10cSrcweir 	else
1591*cdf0e10cSrcweir 	{
1592*cdf0e10cSrcweir 		// pass on to superclass
1593*cdf0e10cSrcweir 		SvTreeListBox::KeyInput( rKeyEvent );
1594*cdf0e10cSrcweir 	}
1595*cdf0e10cSrcweir }
1596*cdf0e10cSrcweir 
1597*cdf0e10cSrcweir // class SvxDescriptionEdit ----------------------------------------------
1598*cdf0e10cSrcweir 
1599*cdf0e10cSrcweir SvxDescriptionEdit::SvxDescriptionEdit( Window* pParent, const ResId& _rId ) :
1600*cdf0e10cSrcweir 
1601*cdf0e10cSrcweir     ExtMultiLineEdit( pParent, _rId )
1602*cdf0e10cSrcweir 
1603*cdf0e10cSrcweir {
1604*cdf0e10cSrcweir     // calculate the available space for help text
1605*cdf0e10cSrcweir     m_aRealRect = Rectangle( Point(), GetSizePixel() );
1606*cdf0e10cSrcweir     if ( GetVScrollBar() )
1607*cdf0e10cSrcweir         m_aRealRect.Right() -= ( GetVScrollBar()->GetSizePixel().Width() + 4 );
1608*cdf0e10cSrcweir 
1609*cdf0e10cSrcweir     SetLeftMargin(2);
1610*cdf0e10cSrcweir     SetBorderStyle( WINDOW_BORDER_MONO );
1611*cdf0e10cSrcweir }
1612*cdf0e10cSrcweir 
1613*cdf0e10cSrcweir // -----------------------------------------------------------------------
1614*cdf0e10cSrcweir 
1615*cdf0e10cSrcweir void SvxDescriptionEdit::SetNewText( const String& _rText )
1616*cdf0e10cSrcweir {
1617*cdf0e10cSrcweir     String sTemp( _rText );
1618*cdf0e10cSrcweir     sal_Bool bShow = sal_False;
1619*cdf0e10cSrcweir     if ( sTemp.Len() > 0 )
1620*cdf0e10cSrcweir     {
1621*cdf0e10cSrcweir         // detect if a scrollbar is necessary
1622*cdf0e10cSrcweir         Rectangle aRect = GetTextRect( m_aRealRect, sTemp, TEXT_DRAW_WORDBREAK | TEXT_DRAW_MULTILINE );
1623*cdf0e10cSrcweir         bShow = ( aRect.Bottom() > m_aRealRect.Bottom() );
1624*cdf0e10cSrcweir     }
1625*cdf0e10cSrcweir 
1626*cdf0e10cSrcweir     if ( GetVScrollBar() )
1627*cdf0e10cSrcweir         GetVScrollBar()->Show( bShow );
1628*cdf0e10cSrcweir 
1629*cdf0e10cSrcweir     if ( bShow )
1630*cdf0e10cSrcweir         sTemp += '\n';
1631*cdf0e10cSrcweir 
1632*cdf0e10cSrcweir     SetText( sTemp );
1633*cdf0e10cSrcweir }
1634*cdf0e10cSrcweir 
1635*cdf0e10cSrcweir /******************************************************************************
1636*cdf0e10cSrcweir  *
1637*cdf0e10cSrcweir  * SvxConfigPage is the abstract base class on which the Menu and Toolbar
1638*cdf0e10cSrcweir  * configuration tabpages are based. It includes methods which are common to
1639*cdf0e10cSrcweir  * both tabpages to add, delete, move and rename items etc.
1640*cdf0e10cSrcweir  *
1641*cdf0e10cSrcweir  *****************************************************************************/
1642*cdf0e10cSrcweir SvxConfigPage::SvxConfigPage(
1643*cdf0e10cSrcweir     Window *pParent, const SfxItemSet& rSet )
1644*cdf0e10cSrcweir 	:
1645*cdf0e10cSrcweir 	SfxTabPage( pParent, CUI_RES( RID_SVXPAGE_MENUS ), rSet ),
1646*cdf0e10cSrcweir 	bInitialised( sal_False ),
1647*cdf0e10cSrcweir 	pCurrentSaveInData( 0 ),
1648*cdf0e10cSrcweir 	aTopLevelSeparator( this, CUI_RES( GRP_MENUS ) ),
1649*cdf0e10cSrcweir 	aTopLevelLabel( this, CUI_RES( FT_MENUS ) ),
1650*cdf0e10cSrcweir 	aTopLevelListBox( this, CUI_RES( LB_MENUS ) ),
1651*cdf0e10cSrcweir 	aNewTopLevelButton( this, CUI_RES( BTN_NEW ) ),
1652*cdf0e10cSrcweir 	aModifyTopLevelButton( this, CUI_RES( BTN_CHANGE ) ),
1653*cdf0e10cSrcweir 	aContentsSeparator( this, CUI_RES( GRP_MENU_SEPARATOR ) ),
1654*cdf0e10cSrcweir 	aContentsLabel( this, CUI_RES( GRP_MENU_ENTRIES ) ),
1655*cdf0e10cSrcweir 	aContentsListBox( 0 ),
1656*cdf0e10cSrcweir 	aAddCommandsButton( this, CUI_RES( BTN_ADD_COMMANDS ) ),
1657*cdf0e10cSrcweir 	aModifyCommandButton( this, CUI_RES( BTN_CHANGE_ENTRY ) ),
1658*cdf0e10cSrcweir 	aMoveUpButton( this, CUI_RES( BTN_UP ) ),
1659*cdf0e10cSrcweir 	aMoveDownButton( this, CUI_RES( BTN_DOWN ) ),
1660*cdf0e10cSrcweir 	aSaveInText( this, CUI_RES( TXT_SAVEIN ) ),
1661*cdf0e10cSrcweir 	aSaveInListBox( this, CUI_RES( LB_SAVEIN ) ),
1662*cdf0e10cSrcweir     aDescriptionLabel( this, CUI_RES( FT_DESCRIPTION ) ),
1663*cdf0e10cSrcweir     aDescriptionField( this, CUI_RES( ED_DESCRIPTION ) ),
1664*cdf0e10cSrcweir 	pSelectorDlg( 0 )
1665*cdf0e10cSrcweir {
1666*cdf0e10cSrcweir     aDescriptionField.SetControlBackground( GetSettings().GetStyleSettings().GetDialogColor() );
1667*cdf0e10cSrcweir     aDescriptionField.SetAutoScroll( sal_True );
1668*cdf0e10cSrcweir     aDescriptionField.EnableCursor( sal_False );
1669*cdf0e10cSrcweir 
1670*cdf0e10cSrcweir 	aMoveUpButton.SetAccessibleName(String(CUI_RES(BUTTON_STR_UP)));
1671*cdf0e10cSrcweir 	aMoveDownButton.SetAccessibleName(String(CUI_RES(BUTTON_STR_DOWN)));
1672*cdf0e10cSrcweir 	aMoveUpButton.SetAccessibleRelationMemberOf(&aContentsSeparator);
1673*cdf0e10cSrcweir 	aMoveDownButton.SetAccessibleRelationMemberOf(&aContentsSeparator);
1674*cdf0e10cSrcweir 	aNewTopLevelButton.SetAccessibleRelationMemberOf(&aTopLevelSeparator);
1675*cdf0e10cSrcweir 	aModifyTopLevelButton.SetAccessibleRelationMemberOf(&aTopLevelSeparator);
1676*cdf0e10cSrcweir 	aAddCommandsButton.SetAccessibleRelationMemberOf(&aContentsSeparator);
1677*cdf0e10cSrcweir 	aModifyCommandButton.SetAccessibleRelationMemberOf(&aContentsSeparator);
1678*cdf0e10cSrcweir }
1679*cdf0e10cSrcweir 
1680*cdf0e10cSrcweir SvxConfigPage::~SvxConfigPage()
1681*cdf0e10cSrcweir {
1682*cdf0e10cSrcweir }
1683*cdf0e10cSrcweir 
1684*cdf0e10cSrcweir void SvxConfigPage::Reset( const SfxItemSet& )
1685*cdf0e10cSrcweir {
1686*cdf0e10cSrcweir 	// If we haven't initialised our XMultiServiceFactory reference
1687*cdf0e10cSrcweir 	// then Reset is being called at the opening of the dialog.
1688*cdf0e10cSrcweir 	//
1689*cdf0e10cSrcweir 	// Load menu configuration data for the module of the currently
1690*cdf0e10cSrcweir 	// selected document, for the currently selected document, and for
1691*cdf0e10cSrcweir 	// all other open documents of the same module type
1692*cdf0e10cSrcweir 	if ( !bInitialised )
1693*cdf0e10cSrcweir 	{
1694*cdf0e10cSrcweir 		sal_uInt16 nPos = 0;
1695*cdf0e10cSrcweir 		uno::Reference < css::ui::XUIConfigurationManager > xCfgMgr;
1696*cdf0e10cSrcweir 		uno::Reference < css::ui::XUIConfigurationManager > xDocCfgMgr;
1697*cdf0e10cSrcweir 
1698*cdf0e10cSrcweir 		uno::Reference< lang::XMultiServiceFactory > xServiceManager(
1699*cdf0e10cSrcweir 			::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
1700*cdf0e10cSrcweir 
1701*cdf0e10cSrcweir         m_xFrame = GetFrame();
1702*cdf0e10cSrcweir 		OUString aModuleId = GetFrameWithDefaultAndIdentify( m_xFrame );
1703*cdf0e10cSrcweir 
1704*cdf0e10cSrcweir 		// replace %MODULENAME in the label with the correct module name
1705*cdf0e10cSrcweir         uno::Reference< css::frame::XModuleManager > xModuleManager(
1706*cdf0e10cSrcweir 			xServiceManager->createInstance(
1707*cdf0e10cSrcweir 				OUString( RTL_CONSTASCII_USTRINGPARAM(
1708*cdf0e10cSrcweir 					"com.sun.star.frame.ModuleManager" ) ) ),
1709*cdf0e10cSrcweir 			uno::UNO_QUERY_THROW );
1710*cdf0e10cSrcweir 		OUString aModuleName = GetUIModuleName( aModuleId, xModuleManager );
1711*cdf0e10cSrcweir 
1712*cdf0e10cSrcweir 		OUString title = aTopLevelSeparator.GetText();
1713*cdf0e10cSrcweir 		OUString aSearchString = OUString::createFromAscii( "%MODULENAME" );
1714*cdf0e10cSrcweir 		sal_Int32 index = title.indexOf( aSearchString );
1715*cdf0e10cSrcweir 
1716*cdf0e10cSrcweir 		if ( index != -1 )
1717*cdf0e10cSrcweir 		{
1718*cdf0e10cSrcweir 			title = title.replaceAt(
1719*cdf0e10cSrcweir 				index, aSearchString.getLength(), aModuleName );
1720*cdf0e10cSrcweir 			aTopLevelSeparator.SetText( title );
1721*cdf0e10cSrcweir 		}
1722*cdf0e10cSrcweir 
1723*cdf0e10cSrcweir 		uno::Reference< css::ui::XModuleUIConfigurationManagerSupplier >
1724*cdf0e10cSrcweir 			xModuleCfgSupplier( xServiceManager->createInstance(
1725*cdf0e10cSrcweir 				OUString( RTL_CONSTASCII_USTRINGPARAM(
1726*cdf0e10cSrcweir 			"com.sun.star.ui.ModuleUIConfigurationManagerSupplier" ))),
1727*cdf0e10cSrcweir 			uno::UNO_QUERY );
1728*cdf0e10cSrcweir 
1729*cdf0e10cSrcweir 		// Set up data for module specific menus
1730*cdf0e10cSrcweir 		SaveInData* pModuleData = NULL;
1731*cdf0e10cSrcweir 
1732*cdf0e10cSrcweir 		try
1733*cdf0e10cSrcweir 		{
1734*cdf0e10cSrcweir 			xCfgMgr =
1735*cdf0e10cSrcweir 				xModuleCfgSupplier->getUIConfigurationManager( aModuleId );
1736*cdf0e10cSrcweir 
1737*cdf0e10cSrcweir             pModuleData = CreateSaveInData( xCfgMgr,
1738*cdf0e10cSrcweir                                             uno::Reference< css::ui::XUIConfigurationManager >(),
1739*cdf0e10cSrcweir                                             aModuleId,
1740*cdf0e10cSrcweir                                             sal_False );
1741*cdf0e10cSrcweir 		}
1742*cdf0e10cSrcweir 		catch ( container::NoSuchElementException& )
1743*cdf0e10cSrcweir 		{
1744*cdf0e10cSrcweir 		}
1745*cdf0e10cSrcweir 
1746*cdf0e10cSrcweir 		if ( pModuleData != NULL )
1747*cdf0e10cSrcweir 		{
1748*cdf0e10cSrcweir 			OUString label;
1749*cdf0e10cSrcweir 			utl::ConfigManager::GetDirectConfigProperty(
1750*cdf0e10cSrcweir 				utl::ConfigManager::PRODUCTNAME ) >>= label;
1751*cdf0e10cSrcweir 			label += OUString::createFromAscii( " " );
1752*cdf0e10cSrcweir 			label += aModuleName;
1753*cdf0e10cSrcweir 
1754*cdf0e10cSrcweir 			nPos = aSaveInListBox.InsertEntry( label );
1755*cdf0e10cSrcweir 			aSaveInListBox.SetEntryData( nPos, pModuleData );
1756*cdf0e10cSrcweir 		}
1757*cdf0e10cSrcweir 
1758*cdf0e10cSrcweir 		// try to retrieve the document based ui configuration manager
1759*cdf0e10cSrcweir 		OUString aTitle;
1760*cdf0e10cSrcweir 		uno::Reference< frame::XController > xController =
1761*cdf0e10cSrcweir 			m_xFrame->getController();
1762*cdf0e10cSrcweir 		if ( CanConfig( aModuleId ) && xController.is() )
1763*cdf0e10cSrcweir 		{
1764*cdf0e10cSrcweir 			uno::Reference< frame::XModel > xModel( xController->getModel() );
1765*cdf0e10cSrcweir 			if ( xModel.is() )
1766*cdf0e10cSrcweir 			{
1767*cdf0e10cSrcweir 				uno::Reference< css::ui::XUIConfigurationManagerSupplier >
1768*cdf0e10cSrcweir 					xCfgSupplier( xModel, uno::UNO_QUERY );
1769*cdf0e10cSrcweir 
1770*cdf0e10cSrcweir 				if ( xCfgSupplier.is() )
1771*cdf0e10cSrcweir 				{
1772*cdf0e10cSrcweir 					xDocCfgMgr = xCfgSupplier->getUIConfigurationManager();
1773*cdf0e10cSrcweir 				}
1774*cdf0e10cSrcweir                 aTitle = ::comphelper::DocumentInfo::getDocumentTitle( xModel );
1775*cdf0e10cSrcweir 			}
1776*cdf0e10cSrcweir 		}
1777*cdf0e10cSrcweir 
1778*cdf0e10cSrcweir 		SaveInData* pDocData = NULL;
1779*cdf0e10cSrcweir 		if ( xDocCfgMgr.is() )
1780*cdf0e10cSrcweir 		{
1781*cdf0e10cSrcweir 			pDocData = CreateSaveInData( xDocCfgMgr, xCfgMgr, aModuleId, sal_True );
1782*cdf0e10cSrcweir 
1783*cdf0e10cSrcweir 			if ( !pDocData->IsReadOnly() )
1784*cdf0e10cSrcweir 			{
1785*cdf0e10cSrcweir 				nPos = aSaveInListBox.InsertEntry( aTitle );
1786*cdf0e10cSrcweir 				aSaveInListBox.SetEntryData( nPos, pDocData );
1787*cdf0e10cSrcweir 			}
1788*cdf0e10cSrcweir 		}
1789*cdf0e10cSrcweir 
1790*cdf0e10cSrcweir 		// if an item to select has been passed in (eg. the ResourceURL for a
1791*cdf0e10cSrcweir 		// toolbar) then try to select the SaveInData entry that has that item
1792*cdf0e10cSrcweir 		bool bURLToSelectFound = sal_False;
1793*cdf0e10cSrcweir 		if ( m_aURLToSelect.getLength() != 0 )
1794*cdf0e10cSrcweir 		{
1795*cdf0e10cSrcweir 			if ( pDocData != NULL && pDocData->HasURL( m_aURLToSelect ) )
1796*cdf0e10cSrcweir 			{
1797*cdf0e10cSrcweir 				aSaveInListBox.SelectEntryPos( nPos, sal_True );
1798*cdf0e10cSrcweir 				pCurrentSaveInData = pDocData;
1799*cdf0e10cSrcweir 				bURLToSelectFound = sal_True;
1800*cdf0e10cSrcweir 			}
1801*cdf0e10cSrcweir 			else if ( pModuleData->HasURL( m_aURLToSelect ) )
1802*cdf0e10cSrcweir 			{
1803*cdf0e10cSrcweir 				aSaveInListBox.SelectEntryPos( 0, sal_True );
1804*cdf0e10cSrcweir 				pCurrentSaveInData = pModuleData;
1805*cdf0e10cSrcweir 				bURLToSelectFound = sal_True;
1806*cdf0e10cSrcweir 			}
1807*cdf0e10cSrcweir 		}
1808*cdf0e10cSrcweir 
1809*cdf0e10cSrcweir 		if ( bURLToSelectFound == sal_False )
1810*cdf0e10cSrcweir 		{
1811*cdf0e10cSrcweir 			// if the document has menu configuration settings select it
1812*cdf0e10cSrcweir 			// it the SaveIn listbox, otherwise select the module data
1813*cdf0e10cSrcweir 			if ( pDocData != NULL && pDocData->HasSettings() )
1814*cdf0e10cSrcweir 			{
1815*cdf0e10cSrcweir 				aSaveInListBox.SelectEntryPos( nPos, sal_True );
1816*cdf0e10cSrcweir 				pCurrentSaveInData = pDocData;
1817*cdf0e10cSrcweir 			}
1818*cdf0e10cSrcweir 			else
1819*cdf0e10cSrcweir 			{
1820*cdf0e10cSrcweir 				aSaveInListBox.SelectEntryPos( 0, sal_True );
1821*cdf0e10cSrcweir 				pCurrentSaveInData = pModuleData;
1822*cdf0e10cSrcweir 			}
1823*cdf0e10cSrcweir 		}
1824*cdf0e10cSrcweir 
1825*cdf0e10cSrcweir #ifdef DBG_UTIL
1826*cdf0e10cSrcweir         DBG_ASSERT( pCurrentSaveInData, "SvxConfigPage::Reset(): no SaveInData" );
1827*cdf0e10cSrcweir #endif
1828*cdf0e10cSrcweir 
1829*cdf0e10cSrcweir 		if ( CanConfig( aModuleId ) )
1830*cdf0e10cSrcweir         {
1831*cdf0e10cSrcweir             // Load configuration for other open documents which have
1832*cdf0e10cSrcweir 		    // same module type
1833*cdf0e10cSrcweir 		    uno::Sequence< uno::Reference< frame::XFrame > > aFrameList;
1834*cdf0e10cSrcweir             try
1835*cdf0e10cSrcweir             {
1836*cdf0e10cSrcweir 		        uno::Reference< frame::XFramesSupplier > xFramesSupplier(
1837*cdf0e10cSrcweir 			        xServiceManager->createInstance(
1838*cdf0e10cSrcweir 				        OUString( RTL_CONSTASCII_USTRINGPARAM(
1839*cdf0e10cSrcweir 					        "com.sun.star.frame.Desktop" ) ) ),
1840*cdf0e10cSrcweir 			        uno::UNO_QUERY_THROW );
1841*cdf0e10cSrcweir 
1842*cdf0e10cSrcweir 		        uno::Reference< frame::XFrames > xFrames =
1843*cdf0e10cSrcweir 			        xFramesSupplier->getFrames();
1844*cdf0e10cSrcweir 
1845*cdf0e10cSrcweir 			    aFrameList = xFrames->queryFrames(
1846*cdf0e10cSrcweir                     frame::FrameSearchFlag::ALL & ~frame::FrameSearchFlag::SELF );
1847*cdf0e10cSrcweir 
1848*cdf0e10cSrcweir             }
1849*cdf0e10cSrcweir             catch( const uno::Exception& )
1850*cdf0e10cSrcweir             {
1851*cdf0e10cSrcweir             	DBG_UNHANDLED_EXCEPTION();
1852*cdf0e10cSrcweir             }
1853*cdf0e10cSrcweir 
1854*cdf0e10cSrcweir 		    for ( sal_Int32 i = 0; i < aFrameList.getLength(); i++ )
1855*cdf0e10cSrcweir 		    {
1856*cdf0e10cSrcweir 			    SaveInData* pData = NULL;
1857*cdf0e10cSrcweir 			    uno::Reference < frame::XFrame > xf = aFrameList[i];
1858*cdf0e10cSrcweir 
1859*cdf0e10cSrcweir 			    if ( xf.is() && xf != m_xFrame )
1860*cdf0e10cSrcweir 			    {
1861*cdf0e10cSrcweir                     OUString aCheckId;
1862*cdf0e10cSrcweir                     try{
1863*cdf0e10cSrcweir                         aCheckId = xModuleManager->identify( xf );
1864*cdf0e10cSrcweir                     } catch(const uno::Exception&)
1865*cdf0e10cSrcweir                         { aCheckId = ::rtl::OUString(); }
1866*cdf0e10cSrcweir 
1867*cdf0e10cSrcweir 				    if ( aModuleId.equals( aCheckId ) )
1868*cdf0e10cSrcweir 				    {
1869*cdf0e10cSrcweir 					    // try to get the document based ui configuration manager
1870*cdf0e10cSrcweir 					    OUString aTitle2;
1871*cdf0e10cSrcweir 					    uno::Reference< frame::XController > xController_ =
1872*cdf0e10cSrcweir 						    xf->getController();
1873*cdf0e10cSrcweir 
1874*cdf0e10cSrcweir 					    if ( xController_.is() )
1875*cdf0e10cSrcweir 					    {
1876*cdf0e10cSrcweir 						    uno::Reference< frame::XModel > xModel(
1877*cdf0e10cSrcweir 							    xController_->getModel() );
1878*cdf0e10cSrcweir 
1879*cdf0e10cSrcweir 						    if ( xModel.is() )
1880*cdf0e10cSrcweir 						    {
1881*cdf0e10cSrcweir 							    uno::Reference<
1882*cdf0e10cSrcweir 								    css::ui::XUIConfigurationManagerSupplier >
1883*cdf0e10cSrcweir 									    xCfgSupplier( xModel, uno::UNO_QUERY );
1884*cdf0e10cSrcweir 
1885*cdf0e10cSrcweir 							    if ( xCfgSupplier.is() )
1886*cdf0e10cSrcweir 							    {
1887*cdf0e10cSrcweir 								    xDocCfgMgr =
1888*cdf0e10cSrcweir 									    xCfgSupplier->getUIConfigurationManager();
1889*cdf0e10cSrcweir 							    }
1890*cdf0e10cSrcweir                                 aTitle2 = ::comphelper::DocumentInfo::getDocumentTitle( xModel );
1891*cdf0e10cSrcweir 						    }
1892*cdf0e10cSrcweir 					    }
1893*cdf0e10cSrcweir 
1894*cdf0e10cSrcweir 					    if ( xDocCfgMgr.is() )
1895*cdf0e10cSrcweir 					    {
1896*cdf0e10cSrcweir 						    pData = CreateSaveInData( xDocCfgMgr, xCfgMgr, aModuleId, sal_True );
1897*cdf0e10cSrcweir 
1898*cdf0e10cSrcweir 						    if ( pData && !pData->IsReadOnly() )
1899*cdf0e10cSrcweir 						    {
1900*cdf0e10cSrcweir 							    nPos = aSaveInListBox.InsertEntry( aTitle2 );
1901*cdf0e10cSrcweir 							    aSaveInListBox.SetEntryData( nPos, pData );
1902*cdf0e10cSrcweir 						    }
1903*cdf0e10cSrcweir 					    }
1904*cdf0e10cSrcweir 				    }
1905*cdf0e10cSrcweir 			    }
1906*cdf0e10cSrcweir 		    }
1907*cdf0e10cSrcweir         }
1908*cdf0e10cSrcweir 
1909*cdf0e10cSrcweir 		aSaveInListBox.SetSelectHdl(
1910*cdf0e10cSrcweir 			LINK( this, SvxConfigPage, SelectSaveInLocation ) );
1911*cdf0e10cSrcweir 
1912*cdf0e10cSrcweir 		bInitialised = sal_True;
1913*cdf0e10cSrcweir 
1914*cdf0e10cSrcweir 		Init();
1915*cdf0e10cSrcweir 	}
1916*cdf0e10cSrcweir 	else
1917*cdf0e10cSrcweir 	{
1918*cdf0e10cSrcweir 		if ( QueryReset() == RET_YES )
1919*cdf0e10cSrcweir 		{
1920*cdf0e10cSrcweir 			// Reset menu configuration for currently selected SaveInData
1921*cdf0e10cSrcweir 			GetSaveInData()->Reset();
1922*cdf0e10cSrcweir 
1923*cdf0e10cSrcweir 			Init();
1924*cdf0e10cSrcweir 		}
1925*cdf0e10cSrcweir 	}
1926*cdf0e10cSrcweir }
1927*cdf0e10cSrcweir 
1928*cdf0e10cSrcweir ::rtl::OUString SvxConfigPage::GetFrameWithDefaultAndIdentify( uno::Reference< frame::XFrame >& _inout_rxFrame )
1929*cdf0e10cSrcweir {
1930*cdf0e10cSrcweir     ::rtl::OUString sModuleID;
1931*cdf0e10cSrcweir     try
1932*cdf0e10cSrcweir     {
1933*cdf0e10cSrcweir 		uno::Reference< lang::XMultiServiceFactory > xServiceManager(
1934*cdf0e10cSrcweir 			::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
1935*cdf0e10cSrcweir 
1936*cdf0e10cSrcweir 		uno::Reference< frame::XFramesSupplier > xFramesSupplier(
1937*cdf0e10cSrcweir 			xServiceManager->createInstance(
1938*cdf0e10cSrcweir 				OUString( RTL_CONSTASCII_USTRINGPARAM(
1939*cdf0e10cSrcweir 					"com.sun.star.frame.Desktop" ) ) ),
1940*cdf0e10cSrcweir 			uno::UNO_QUERY_THROW );
1941*cdf0e10cSrcweir 
1942*cdf0e10cSrcweir         if ( !_inout_rxFrame.is() )
1943*cdf0e10cSrcweir     		_inout_rxFrame = xFramesSupplier->getActiveFrame();
1944*cdf0e10cSrcweir 
1945*cdf0e10cSrcweir         if ( !_inout_rxFrame.is() )
1946*cdf0e10cSrcweir         {
1947*cdf0e10cSrcweir             uno::Reference< frame::XDesktop > xDesktop( xFramesSupplier, uno::UNO_QUERY_THROW );
1948*cdf0e10cSrcweir             _inout_rxFrame = xDesktop->getCurrentFrame();
1949*cdf0e10cSrcweir         }
1950*cdf0e10cSrcweir 
1951*cdf0e10cSrcweir         if ( !_inout_rxFrame.is() && SfxViewFrame::Current() )
1952*cdf0e10cSrcweir             _inout_rxFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface();
1953*cdf0e10cSrcweir 
1954*cdf0e10cSrcweir         if ( !_inout_rxFrame.is() )
1955*cdf0e10cSrcweir         {
1956*cdf0e10cSrcweir             DBG_ERRORFILE( "SvxConfigPage::GetFrameWithDefaultAndIdentify(): no frame found!" );
1957*cdf0e10cSrcweir             return sModuleID;
1958*cdf0e10cSrcweir         }
1959*cdf0e10cSrcweir 
1960*cdf0e10cSrcweir         uno::Reference< css::frame::XModuleManager > xModuleManager(
1961*cdf0e10cSrcweir 			xServiceManager->createInstance(
1962*cdf0e10cSrcweir 				OUString( RTL_CONSTASCII_USTRINGPARAM(
1963*cdf0e10cSrcweir 					"com.sun.star.frame.ModuleManager" ) ) ),
1964*cdf0e10cSrcweir 			uno::UNO_QUERY_THROW );
1965*cdf0e10cSrcweir 
1966*cdf0e10cSrcweir         try
1967*cdf0e10cSrcweir         {
1968*cdf0e10cSrcweir             sModuleID = xModuleManager->identify( _inout_rxFrame );
1969*cdf0e10cSrcweir         }
1970*cdf0e10cSrcweir         catch ( const frame::UnknownModuleException& )
1971*cdf0e10cSrcweir         {
1972*cdf0e10cSrcweir         }
1973*cdf0e10cSrcweir 
1974*cdf0e10cSrcweir     }
1975*cdf0e10cSrcweir     catch( const uno::Exception& )
1976*cdf0e10cSrcweir     {
1977*cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
1978*cdf0e10cSrcweir     }
1979*cdf0e10cSrcweir 
1980*cdf0e10cSrcweir     return sModuleID;
1981*cdf0e10cSrcweir }
1982*cdf0e10cSrcweir 
1983*cdf0e10cSrcweir sal_Bool SvxConfigPage::FillItemSet( SfxItemSet& )
1984*cdf0e10cSrcweir {
1985*cdf0e10cSrcweir 	bool result = sal_False;
1986*cdf0e10cSrcweir 
1987*cdf0e10cSrcweir 	for ( sal_uInt16 i = 0 ; i < aSaveInListBox.GetEntryCount(); i++ )
1988*cdf0e10cSrcweir 	{
1989*cdf0e10cSrcweir 		SaveInData* pData =
1990*cdf0e10cSrcweir 			(SaveInData*) aSaveInListBox.GetEntryData( i );
1991*cdf0e10cSrcweir 
1992*cdf0e10cSrcweir 		result = pData->Apply();
1993*cdf0e10cSrcweir 	}
1994*cdf0e10cSrcweir 	return result;
1995*cdf0e10cSrcweir }
1996*cdf0e10cSrcweir 
1997*cdf0e10cSrcweir void SvxConfigPage::PositionContentsListBox()
1998*cdf0e10cSrcweir {
1999*cdf0e10cSrcweir 	if ( aContentsListBox == NULL )
2000*cdf0e10cSrcweir 	{
2001*cdf0e10cSrcweir 		return;
2002*cdf0e10cSrcweir 	}
2003*cdf0e10cSrcweir 
2004*cdf0e10cSrcweir 	Point p, newp;
2005*cdf0e10cSrcweir 	Size s, news;
2006*cdf0e10cSrcweir 	long x, y, width, height;
2007*cdf0e10cSrcweir 
2008*cdf0e10cSrcweir 	// x and width is same as aTopLevelListBox
2009*cdf0e10cSrcweir 	x = aTopLevelListBox.GetPosPixel().X();
2010*cdf0e10cSrcweir 	width = aTopLevelListBox.GetSizePixel().Width();
2011*cdf0e10cSrcweir 
2012*cdf0e10cSrcweir 	// y is same as aAddCommandsButton
2013*cdf0e10cSrcweir 	y = aAddCommandsButton.GetPosPixel().Y();
2014*cdf0e10cSrcweir 
2015*cdf0e10cSrcweir 	// get gap between aAddCommandsButton and aContentsSeparator
2016*cdf0e10cSrcweir 	p = aContentsSeparator.GetPosPixel();
2017*cdf0e10cSrcweir 	s = aContentsSeparator.GetSizePixel();
2018*cdf0e10cSrcweir     long gap = y - ( p.Y() + s.Height() );
2019*cdf0e10cSrcweir 
2020*cdf0e10cSrcweir 	height = aSaveInListBox.GetPosPixel().Y() - y - gap;
2021*cdf0e10cSrcweir 
2022*cdf0e10cSrcweir 	aContentsListBox->SetPosPixel( Point( x, y ) );
2023*cdf0e10cSrcweir 	aContentsListBox->SetSizePixel( Size( width, height ) );
2024*cdf0e10cSrcweir }
2025*cdf0e10cSrcweir 
2026*cdf0e10cSrcweir IMPL_LINK( SvxConfigPage, SelectSaveInLocation, ListBox *, pBox )
2027*cdf0e10cSrcweir {
2028*cdf0e10cSrcweir 	(void)pBox;
2029*cdf0e10cSrcweir 
2030*cdf0e10cSrcweir 	pCurrentSaveInData = (SaveInData*) aSaveInListBox.GetEntryData(
2031*cdf0e10cSrcweir 			aSaveInListBox.GetSelectEntryPos());
2032*cdf0e10cSrcweir 
2033*cdf0e10cSrcweir 	Init();
2034*cdf0e10cSrcweir 	return 1;
2035*cdf0e10cSrcweir }
2036*cdf0e10cSrcweir 
2037*cdf0e10cSrcweir void SvxConfigPage::ReloadTopLevelListBox( SvxConfigEntry* pToSelect )
2038*cdf0e10cSrcweir {
2039*cdf0e10cSrcweir 	sal_uInt16 nSelectionPos = aTopLevelListBox.GetSelectEntryPos();
2040*cdf0e10cSrcweir 	aTopLevelListBox.Clear();
2041*cdf0e10cSrcweir 
2042*cdf0e10cSrcweir     if ( GetSaveInData() && GetSaveInData()->GetEntries() )
2043*cdf0e10cSrcweir     {
2044*cdf0e10cSrcweir         SvxEntries::const_iterator iter = GetSaveInData()->GetEntries()->begin();
2045*cdf0e10cSrcweir         SvxEntries::const_iterator end = GetSaveInData()->GetEntries()->end();
2046*cdf0e10cSrcweir 
2047*cdf0e10cSrcweir         for ( ; iter != end; iter++ )
2048*cdf0e10cSrcweir         {
2049*cdf0e10cSrcweir             SvxConfigEntry* pEntryData = *iter;
2050*cdf0e10cSrcweir             sal_uInt16 nPos = aTopLevelListBox.InsertEntry( stripHotKey( pEntryData->GetName() ) );
2051*cdf0e10cSrcweir             aTopLevelListBox.SetEntryData( nPos, pEntryData );
2052*cdf0e10cSrcweir 
2053*cdf0e10cSrcweir             if ( pEntryData == pToSelect )
2054*cdf0e10cSrcweir                 nSelectionPos = nPos;
2055*cdf0e10cSrcweir 
2056*cdf0e10cSrcweir             AddSubMenusToUI( stripHotKey( pEntryData->GetName() ), pEntryData );
2057*cdf0e10cSrcweir         }
2058*cdf0e10cSrcweir     }
2059*cdf0e10cSrcweir #ifdef DBG_UTIL
2060*cdf0e10cSrcweir     else
2061*cdf0e10cSrcweir     {
2062*cdf0e10cSrcweir         DBG_ASSERT( GetSaveInData(), "SvxConfigPage::ReloadTopLevelListBox(): no SaveInData" );
2063*cdf0e10cSrcweir         DBG_ASSERT( GetSaveInData()->GetEntries() ,
2064*cdf0e10cSrcweir             "SvxConfigPage::ReloadTopLevelListBox(): no SaveInData entries" );
2065*cdf0e10cSrcweir     }
2066*cdf0e10cSrcweir #endif
2067*cdf0e10cSrcweir 
2068*cdf0e10cSrcweir 	nSelectionPos = nSelectionPos < aTopLevelListBox.GetEntryCount() ?
2069*cdf0e10cSrcweir 		nSelectionPos : aTopLevelListBox.GetEntryCount() - 1;
2070*cdf0e10cSrcweir 
2071*cdf0e10cSrcweir 	aTopLevelListBox.SelectEntryPos( nSelectionPos, sal_True );
2072*cdf0e10cSrcweir 	aTopLevelListBox.GetSelectHdl().Call( this );
2073*cdf0e10cSrcweir }
2074*cdf0e10cSrcweir 
2075*cdf0e10cSrcweir void SvxConfigPage::AddSubMenusToUI(
2076*cdf0e10cSrcweir 	const String& rBaseTitle, SvxConfigEntry* pParentData )
2077*cdf0e10cSrcweir {
2078*cdf0e10cSrcweir 	SvxEntries::const_iterator iter = pParentData->GetEntries()->begin();
2079*cdf0e10cSrcweir 	SvxEntries::const_iterator end = pParentData->GetEntries()->end();
2080*cdf0e10cSrcweir 
2081*cdf0e10cSrcweir 	for ( ; iter != end; iter++ )
2082*cdf0e10cSrcweir 	{
2083*cdf0e10cSrcweir 		SvxConfigEntry* pEntryData = *iter;
2084*cdf0e10cSrcweir 
2085*cdf0e10cSrcweir 		if ( pEntryData->IsPopup() )
2086*cdf0e10cSrcweir 		{
2087*cdf0e10cSrcweir 			OUString subMenuTitle( rBaseTitle );
2088*cdf0e10cSrcweir 			subMenuTitle += OUString::createFromAscii( pMenuSeparatorStr );
2089*cdf0e10cSrcweir 			subMenuTitle += stripHotKey( pEntryData->GetName() );
2090*cdf0e10cSrcweir 
2091*cdf0e10cSrcweir 			sal_uInt16 nPos = aTopLevelListBox.InsertEntry( subMenuTitle );
2092*cdf0e10cSrcweir 			aTopLevelListBox.SetEntryData( nPos, pEntryData );
2093*cdf0e10cSrcweir 
2094*cdf0e10cSrcweir 			AddSubMenusToUI( subMenuTitle, pEntryData );
2095*cdf0e10cSrcweir 		}
2096*cdf0e10cSrcweir 	}
2097*cdf0e10cSrcweir }
2098*cdf0e10cSrcweir 
2099*cdf0e10cSrcweir SvxEntries* SvxConfigPage::FindParentForChild(
2100*cdf0e10cSrcweir 	SvxEntries* pRootEntries, SvxConfigEntry* pChildData )
2101*cdf0e10cSrcweir {
2102*cdf0e10cSrcweir 	SvxEntries::const_iterator iter = pRootEntries->begin();
2103*cdf0e10cSrcweir 	SvxEntries::const_iterator end = pRootEntries->end();
2104*cdf0e10cSrcweir 
2105*cdf0e10cSrcweir 	for ( ; iter != end; iter++ )
2106*cdf0e10cSrcweir 	{
2107*cdf0e10cSrcweir 		SvxConfigEntry* pEntryData = *iter;
2108*cdf0e10cSrcweir 
2109*cdf0e10cSrcweir 		if ( pEntryData == pChildData )
2110*cdf0e10cSrcweir 		{
2111*cdf0e10cSrcweir 			return pRootEntries;
2112*cdf0e10cSrcweir 		}
2113*cdf0e10cSrcweir 		else if ( pEntryData->IsPopup() )
2114*cdf0e10cSrcweir 		{
2115*cdf0e10cSrcweir 			SvxEntries* result =
2116*cdf0e10cSrcweir 				FindParentForChild( pEntryData->GetEntries(), pChildData );
2117*cdf0e10cSrcweir 
2118*cdf0e10cSrcweir 			if ( result != NULL )
2119*cdf0e10cSrcweir 			{
2120*cdf0e10cSrcweir 				return result;
2121*cdf0e10cSrcweir 			}
2122*cdf0e10cSrcweir 		}
2123*cdf0e10cSrcweir 	}
2124*cdf0e10cSrcweir 	return NULL;
2125*cdf0e10cSrcweir }
2126*cdf0e10cSrcweir 
2127*cdf0e10cSrcweir SvLBoxEntry* SvxConfigPage::AddFunction(
2128*cdf0e10cSrcweir 	SvLBoxEntry* pTarget, bool bFront, bool bAllowDuplicates )
2129*cdf0e10cSrcweir {
2130*cdf0e10cSrcweir 	String aDisplayName = pSelectorDlg->GetSelectedDisplayName();
2131*cdf0e10cSrcweir 	String aHelpText = pSelectorDlg->GetSelectedHelpText();
2132*cdf0e10cSrcweir 	String aURL = pSelectorDlg->GetScriptURL();
2133*cdf0e10cSrcweir 
2134*cdf0e10cSrcweir 	if ( !aURL.Len() )
2135*cdf0e10cSrcweir 	{
2136*cdf0e10cSrcweir 		return NULL;
2137*cdf0e10cSrcweir 	}
2138*cdf0e10cSrcweir 
2139*cdf0e10cSrcweir 	SvxConfigEntry* pNewEntryData =
2140*cdf0e10cSrcweir 		new SvxConfigEntry( aDisplayName, aURL, sal_False );
2141*cdf0e10cSrcweir 	pNewEntryData->SetUserDefined( sal_True );
2142*cdf0e10cSrcweir 
2143*cdf0e10cSrcweir 	// check that this function is not already in the menu
2144*cdf0e10cSrcweir 	SvxConfigEntry* pParent = GetTopLevelSelection();
2145*cdf0e10cSrcweir 
2146*cdf0e10cSrcweir 	SvxEntries::const_iterator iter = pParent->GetEntries()->begin();
2147*cdf0e10cSrcweir 	SvxEntries::const_iterator end = pParent->GetEntries()->end();
2148*cdf0e10cSrcweir 
2149*cdf0e10cSrcweir 	if ( !bAllowDuplicates )
2150*cdf0e10cSrcweir 	{
2151*cdf0e10cSrcweir 		while ( iter != end )
2152*cdf0e10cSrcweir 		{
2153*cdf0e10cSrcweir 			SvxConfigEntry *pCurEntry = *iter;
2154*cdf0e10cSrcweir 
2155*cdf0e10cSrcweir 			if ( pCurEntry->GetCommand() == pNewEntryData->GetCommand() )
2156*cdf0e10cSrcweir 			{
2157*cdf0e10cSrcweir 				// asynchronous error message, because of MsgBoxes
2158*cdf0e10cSrcweir 				PostUserEvent(
2159*cdf0e10cSrcweir 					LINK( this, SvxConfigPage, AsyncInfoMsg ) );
2160*cdf0e10cSrcweir 				return NULL;
2161*cdf0e10cSrcweir 			}
2162*cdf0e10cSrcweir 
2163*cdf0e10cSrcweir 			iter++;
2164*cdf0e10cSrcweir 		}
2165*cdf0e10cSrcweir 	}
2166*cdf0e10cSrcweir 
2167*cdf0e10cSrcweir 	return InsertEntry( pNewEntryData, pTarget, bFront );
2168*cdf0e10cSrcweir }
2169*cdf0e10cSrcweir 
2170*cdf0e10cSrcweir SvLBoxEntry* SvxConfigPage::InsertEntry(
2171*cdf0e10cSrcweir 	SvxConfigEntry* pNewEntryData,
2172*cdf0e10cSrcweir 	SvLBoxEntry* pTarget,
2173*cdf0e10cSrcweir 	bool bFront )
2174*cdf0e10cSrcweir {
2175*cdf0e10cSrcweir 	// Grab the entries list for the currently selected menu
2176*cdf0e10cSrcweir 	SvxEntries* pEntries = GetTopLevelSelection()->GetEntries();
2177*cdf0e10cSrcweir 
2178*cdf0e10cSrcweir 	SvLBoxEntry* pNewEntry = NULL;
2179*cdf0e10cSrcweir 	SvLBoxEntry* pCurEntry =
2180*cdf0e10cSrcweir 		pTarget != NULL ? pTarget : aContentsListBox->GetCurEntry();
2181*cdf0e10cSrcweir 
2182*cdf0e10cSrcweir 	if ( bFront )
2183*cdf0e10cSrcweir 	{
2184*cdf0e10cSrcweir 		pEntries->insert( pEntries->begin(), pNewEntryData );
2185*cdf0e10cSrcweir 		pNewEntry = InsertEntryIntoUI( pNewEntryData, 0 );
2186*cdf0e10cSrcweir 	}
2187*cdf0e10cSrcweir 	else if ( pCurEntry == NULL || pCurEntry == aContentsListBox->Last() )
2188*cdf0e10cSrcweir 	{
2189*cdf0e10cSrcweir 		pEntries->push_back( pNewEntryData );
2190*cdf0e10cSrcweir 		pNewEntry = InsertEntryIntoUI( pNewEntryData );
2191*cdf0e10cSrcweir 	}
2192*cdf0e10cSrcweir 	else
2193*cdf0e10cSrcweir 	{
2194*cdf0e10cSrcweir 		SvxConfigEntry* pEntryData =
2195*cdf0e10cSrcweir 			(SvxConfigEntry*) pCurEntry->GetUserData();
2196*cdf0e10cSrcweir 
2197*cdf0e10cSrcweir 		SvxEntries::iterator iter = pEntries->begin();
2198*cdf0e10cSrcweir 		SvxEntries::const_iterator end = pEntries->end();
2199*cdf0e10cSrcweir 
2200*cdf0e10cSrcweir 		// Advance the iterator to the data for currently selected entry
2201*cdf0e10cSrcweir 		sal_uInt16 nPos = 0;
2202*cdf0e10cSrcweir 		while (*iter != pEntryData && ++iter != end)
2203*cdf0e10cSrcweir 		{
2204*cdf0e10cSrcweir 			nPos++;
2205*cdf0e10cSrcweir 		}
2206*cdf0e10cSrcweir 
2207*cdf0e10cSrcweir 		// Now step past it to the entry after the currently selected one
2208*cdf0e10cSrcweir 		iter++;
2209*cdf0e10cSrcweir 		nPos++;
2210*cdf0e10cSrcweir 
2211*cdf0e10cSrcweir 		// Now add the new entry to the UI and to the parent's list
2212*cdf0e10cSrcweir 		if ( iter != end )
2213*cdf0e10cSrcweir 		{
2214*cdf0e10cSrcweir 			pEntries->insert( iter, pNewEntryData );
2215*cdf0e10cSrcweir 			pNewEntry = InsertEntryIntoUI( pNewEntryData, nPos );
2216*cdf0e10cSrcweir 		}
2217*cdf0e10cSrcweir 	}
2218*cdf0e10cSrcweir 
2219*cdf0e10cSrcweir 	if ( pNewEntry != NULL )
2220*cdf0e10cSrcweir 	{
2221*cdf0e10cSrcweir 		aContentsListBox->Select( pNewEntry );
2222*cdf0e10cSrcweir 		aContentsListBox->MakeVisible( pNewEntry );
2223*cdf0e10cSrcweir 
2224*cdf0e10cSrcweir 		GetSaveInData()->SetModified( sal_True );
2225*cdf0e10cSrcweir 	}
2226*cdf0e10cSrcweir 
2227*cdf0e10cSrcweir 	return pNewEntry;
2228*cdf0e10cSrcweir }
2229*cdf0e10cSrcweir 
2230*cdf0e10cSrcweir SvLBoxEntry* SvxConfigPage::InsertEntryIntoUI(
2231*cdf0e10cSrcweir 	SvxConfigEntry* pNewEntryData, sal_uLong nPos )
2232*cdf0e10cSrcweir {
2233*cdf0e10cSrcweir 	SvLBoxEntry* pNewEntry = NULL;
2234*cdf0e10cSrcweir 
2235*cdf0e10cSrcweir 	if (pNewEntryData->IsSeparator())
2236*cdf0e10cSrcweir 	{
2237*cdf0e10cSrcweir 		pNewEntry = aContentsListBox->InsertEntry(
2238*cdf0e10cSrcweir 			String::CreateFromAscii( pSeparatorStr ),
2239*cdf0e10cSrcweir 				0, sal_False, nPos, pNewEntryData );
2240*cdf0e10cSrcweir 	}
2241*cdf0e10cSrcweir 	else
2242*cdf0e10cSrcweir 	{
2243*cdf0e10cSrcweir 		OUString aName = stripHotKey( pNewEntryData->GetName() );
2244*cdf0e10cSrcweir 
2245*cdf0e10cSrcweir 		Image aImage = GetSaveInData()->GetImage(
2246*cdf0e10cSrcweir 			pNewEntryData->GetCommand());
2247*cdf0e10cSrcweir 
2248*cdf0e10cSrcweir 		if ( !!aImage )
2249*cdf0e10cSrcweir 		{
2250*cdf0e10cSrcweir 			pNewEntry = aContentsListBox->InsertEntry(
2251*cdf0e10cSrcweir 				aName, aImage, aImage, 0, sal_False, nPos, pNewEntryData );
2252*cdf0e10cSrcweir 		}
2253*cdf0e10cSrcweir 		else
2254*cdf0e10cSrcweir 		{
2255*cdf0e10cSrcweir 			pNewEntry = aContentsListBox->InsertEntry(
2256*cdf0e10cSrcweir 				aName, 0, sal_False, nPos, pNewEntryData );
2257*cdf0e10cSrcweir 		}
2258*cdf0e10cSrcweir 
2259*cdf0e10cSrcweir 		if ( pNewEntryData->IsPopup() ||
2260*cdf0e10cSrcweir 			 pNewEntryData->GetStyle() & css::ui::ItemStyle::DROP_DOWN )
2261*cdf0e10cSrcweir 		{
2262*cdf0e10cSrcweir 			// add new popup painter, it gets destructed by the entry
2263*cdf0e10cSrcweir 			pNewEntry->ReplaceItem(
2264*cdf0e10cSrcweir 				new PopupPainter( pNewEntry, aName ),
2265*cdf0e10cSrcweir 				pNewEntry->ItemCount() - 1 );
2266*cdf0e10cSrcweir 		}
2267*cdf0e10cSrcweir 	}
2268*cdf0e10cSrcweir 
2269*cdf0e10cSrcweir 	return pNewEntry;
2270*cdf0e10cSrcweir }
2271*cdf0e10cSrcweir 
2272*cdf0e10cSrcweir IMPL_LINK( SvxConfigPage, AsyncInfoMsg, String*, pMsg )
2273*cdf0e10cSrcweir {
2274*cdf0e10cSrcweir 	(void)pMsg;
2275*cdf0e10cSrcweir 
2276*cdf0e10cSrcweir 	// Asynchronous msg because of D&D
2277*cdf0e10cSrcweir 	InfoBox( this, CUI_RES(
2278*cdf0e10cSrcweir 		IBX_MNUCFG_ALREADY_INCLUDED ) ).Execute();
2279*cdf0e10cSrcweir 
2280*cdf0e10cSrcweir 	return 0;
2281*cdf0e10cSrcweir }
2282*cdf0e10cSrcweir 
2283*cdf0e10cSrcweir IMPL_LINK( SvxConfigPage, MoveHdl, Button *, pButton )
2284*cdf0e10cSrcweir {
2285*cdf0e10cSrcweir 	MoveEntry( pButton == &aMoveUpButton );
2286*cdf0e10cSrcweir 	return 0;
2287*cdf0e10cSrcweir }
2288*cdf0e10cSrcweir 
2289*cdf0e10cSrcweir void SvxConfigPage::MoveEntry( bool bMoveUp )
2290*cdf0e10cSrcweir {
2291*cdf0e10cSrcweir 	SvLBoxEntry *pSourceEntry = aContentsListBox->FirstSelected();
2292*cdf0e10cSrcweir 	SvLBoxEntry *pTargetEntry = NULL;
2293*cdf0e10cSrcweir 	SvLBoxEntry *pToSelect = NULL;
2294*cdf0e10cSrcweir 
2295*cdf0e10cSrcweir 	if ( !pSourceEntry )
2296*cdf0e10cSrcweir 	{
2297*cdf0e10cSrcweir 		return;
2298*cdf0e10cSrcweir 	}
2299*cdf0e10cSrcweir 
2300*cdf0e10cSrcweir 	if ( bMoveUp )
2301*cdf0e10cSrcweir 	{
2302*cdf0e10cSrcweir 		// Move Up is just a Move Down with the source and target reversed
2303*cdf0e10cSrcweir 		pTargetEntry = pSourceEntry;
2304*cdf0e10cSrcweir 		pSourceEntry = aContentsListBox->PrevSibling( pTargetEntry );
2305*cdf0e10cSrcweir 		pToSelect = pTargetEntry;
2306*cdf0e10cSrcweir 	}
2307*cdf0e10cSrcweir 	else
2308*cdf0e10cSrcweir 	{
2309*cdf0e10cSrcweir 		pTargetEntry = aContentsListBox->NextSibling( pSourceEntry );
2310*cdf0e10cSrcweir 		pToSelect = pSourceEntry;
2311*cdf0e10cSrcweir 	}
2312*cdf0e10cSrcweir 
2313*cdf0e10cSrcweir 	if ( MoveEntryData( pSourceEntry, pTargetEntry ) )
2314*cdf0e10cSrcweir 	{
2315*cdf0e10cSrcweir 		aContentsListBox->GetModel()->Move( pSourceEntry, pTargetEntry );
2316*cdf0e10cSrcweir 		aContentsListBox->Select( pToSelect );
2317*cdf0e10cSrcweir 		aContentsListBox->MakeVisible( pToSelect );
2318*cdf0e10cSrcweir 
2319*cdf0e10cSrcweir 		UpdateButtonStates();
2320*cdf0e10cSrcweir 	}
2321*cdf0e10cSrcweir }
2322*cdf0e10cSrcweir 
2323*cdf0e10cSrcweir bool SvxConfigPage::MoveEntryData(
2324*cdf0e10cSrcweir 	SvLBoxEntry* pSourceEntry, SvLBoxEntry* pTargetEntry )
2325*cdf0e10cSrcweir {
2326*cdf0e10cSrcweir 	//modified by shizhoubo for issue53677
2327*cdf0e10cSrcweir 	if ( NULL == pSourceEntry || NULL == pTargetEntry )
2328*cdf0e10cSrcweir  	{
2329*cdf0e10cSrcweir  		return sal_False;
2330*cdf0e10cSrcweir  	}
2331*cdf0e10cSrcweir 
2332*cdf0e10cSrcweir 	// Grab the entries list for the currently selected menu
2333*cdf0e10cSrcweir 	SvxEntries* pEntries = GetTopLevelSelection()->GetEntries();
2334*cdf0e10cSrcweir 
2335*cdf0e10cSrcweir 	SvxConfigEntry* pSourceData =
2336*cdf0e10cSrcweir 		(SvxConfigEntry*) pSourceEntry->GetUserData();
2337*cdf0e10cSrcweir 
2338*cdf0e10cSrcweir 	if ( pTargetEntry == NULL )
2339*cdf0e10cSrcweir 	{
2340*cdf0e10cSrcweir 		RemoveEntry( pEntries, pSourceData );
2341*cdf0e10cSrcweir 		pEntries->insert(
2342*cdf0e10cSrcweir 			pEntries->begin(), pSourceData );
2343*cdf0e10cSrcweir 
2344*cdf0e10cSrcweir 		GetSaveInData()->SetModified( sal_True );
2345*cdf0e10cSrcweir 
2346*cdf0e10cSrcweir 		return sal_True;
2347*cdf0e10cSrcweir 	}
2348*cdf0e10cSrcweir 	else
2349*cdf0e10cSrcweir 	{
2350*cdf0e10cSrcweir 		SvxConfigEntry* pTargetData =
2351*cdf0e10cSrcweir 			(SvxConfigEntry*) pTargetEntry->GetUserData();
2352*cdf0e10cSrcweir 
2353*cdf0e10cSrcweir 		if ( pSourceData != NULL && pTargetData != NULL )
2354*cdf0e10cSrcweir 		{
2355*cdf0e10cSrcweir 			// remove the source entry from our list
2356*cdf0e10cSrcweir 			RemoveEntry( pEntries, pSourceData );
2357*cdf0e10cSrcweir 
2358*cdf0e10cSrcweir 			SvxEntries::iterator iter = pEntries->begin();
2359*cdf0e10cSrcweir 			SvxEntries::const_iterator end = pEntries->end();
2360*cdf0e10cSrcweir 
2361*cdf0e10cSrcweir 			// advance the iterator to the position of the target entry
2362*cdf0e10cSrcweir 			while (*iter != pTargetData && ++iter != end) ;
2363*cdf0e10cSrcweir 
2364*cdf0e10cSrcweir 			// insert the source entry at the position after the target
2365*cdf0e10cSrcweir 			pEntries->insert( ++iter, pSourceData );
2366*cdf0e10cSrcweir 
2367*cdf0e10cSrcweir 			GetSaveInData()->SetModified( sal_True );
2368*cdf0e10cSrcweir 
2369*cdf0e10cSrcweir 			return sal_True;
2370*cdf0e10cSrcweir 		}
2371*cdf0e10cSrcweir 	}
2372*cdf0e10cSrcweir 
2373*cdf0e10cSrcweir 	return sal_False;
2374*cdf0e10cSrcweir }
2375*cdf0e10cSrcweir 
2376*cdf0e10cSrcweir SvxMenuConfigPage::SvxMenuConfigPage(
2377*cdf0e10cSrcweir     Window *pParent, const SfxItemSet& rSet )
2378*cdf0e10cSrcweir 	:
2379*cdf0e10cSrcweir 	SvxConfigPage( pParent, rSet )
2380*cdf0e10cSrcweir {
2381*cdf0e10cSrcweir 	aContentsListBox = new SvxMenuEntriesListBox( this, CUI_RES( BOX_ENTRIES ) );
2382*cdf0e10cSrcweir     FreeResource();
2383*cdf0e10cSrcweir 
2384*cdf0e10cSrcweir 	PositionContentsListBox();
2385*cdf0e10cSrcweir 	aContentsListBox->SetZOrder( &aAddCommandsButton, WINDOW_ZORDER_BEFOR );
2386*cdf0e10cSrcweir 
2387*cdf0e10cSrcweir 	aTopLevelListBox.SetSelectHdl(
2388*cdf0e10cSrcweir 		LINK( this, SvxMenuConfigPage, SelectMenu ) );
2389*cdf0e10cSrcweir 
2390*cdf0e10cSrcweir 	aContentsListBox->SetSelectHdl(
2391*cdf0e10cSrcweir 		LINK( this, SvxMenuConfigPage, SelectMenuEntry ) );
2392*cdf0e10cSrcweir 
2393*cdf0e10cSrcweir 	aMoveUpButton.SetClickHdl ( LINK( this, SvxConfigPage, MoveHdl) );
2394*cdf0e10cSrcweir 	aMoveDownButton.SetClickHdl	( LINK( this, SvxConfigPage, MoveHdl) );
2395*cdf0e10cSrcweir 
2396*cdf0e10cSrcweir 	aNewTopLevelButton.SetClickHdl	(
2397*cdf0e10cSrcweir 		LINK( this, SvxMenuConfigPage, NewMenuHdl ) );
2398*cdf0e10cSrcweir 
2399*cdf0e10cSrcweir 	aAddCommandsButton.SetClickHdl	(
2400*cdf0e10cSrcweir 		LINK( this, SvxMenuConfigPage, AddCommandsHdl ) );
2401*cdf0e10cSrcweir 
2402*cdf0e10cSrcweir 	PopupMenu* pMenu = new PopupMenu( CUI_RES( MODIFY_MENU ) );
2403*cdf0e10cSrcweir 	pMenu->SetMenuFlags(
2404*cdf0e10cSrcweir 		pMenu->GetMenuFlags() | MENU_FLAG_ALWAYSSHOWDISABLEDENTRIES );
2405*cdf0e10cSrcweir 
2406*cdf0e10cSrcweir 	aModifyTopLevelButton.SetPopupMenu( pMenu );
2407*cdf0e10cSrcweir 	aModifyTopLevelButton.SetSelectHdl(
2408*cdf0e10cSrcweir 		LINK( this, SvxMenuConfigPage, MenuSelectHdl ) );
2409*cdf0e10cSrcweir 
2410*cdf0e10cSrcweir 	PopupMenu* pEntry = new PopupMenu( CUI_RES( MODIFY_ENTRY ) );
2411*cdf0e10cSrcweir 	pEntry->SetMenuFlags(
2412*cdf0e10cSrcweir 		pEntry->GetMenuFlags() | MENU_FLAG_ALWAYSSHOWDISABLEDENTRIES );
2413*cdf0e10cSrcweir 
2414*cdf0e10cSrcweir 	aModifyCommandButton.SetPopupMenu( pEntry );
2415*cdf0e10cSrcweir 	aModifyCommandButton.SetSelectHdl(
2416*cdf0e10cSrcweir 		LINK( this, SvxMenuConfigPage, EntrySelectHdl ) );
2417*cdf0e10cSrcweir }
2418*cdf0e10cSrcweir 
2419*cdf0e10cSrcweir // Populates the Menu combo box
2420*cdf0e10cSrcweir void SvxMenuConfigPage::Init()
2421*cdf0e10cSrcweir {
2422*cdf0e10cSrcweir 	// ensure that the UI is cleared before populating it
2423*cdf0e10cSrcweir 	aTopLevelListBox.Clear();
2424*cdf0e10cSrcweir 	aContentsListBox->Clear();
2425*cdf0e10cSrcweir 
2426*cdf0e10cSrcweir 	ReloadTopLevelListBox();
2427*cdf0e10cSrcweir 
2428*cdf0e10cSrcweir 	aTopLevelListBox.SelectEntryPos(0, sal_True);
2429*cdf0e10cSrcweir 	aTopLevelListBox.GetSelectHdl().Call(this);
2430*cdf0e10cSrcweir }
2431*cdf0e10cSrcweir 
2432*cdf0e10cSrcweir SvxMenuConfigPage::~SvxMenuConfigPage()
2433*cdf0e10cSrcweir {
2434*cdf0e10cSrcweir 	for ( sal_uInt16 i = 0 ; i < aSaveInListBox.GetEntryCount(); i++ )
2435*cdf0e10cSrcweir 	{
2436*cdf0e10cSrcweir 		MenuSaveInData* pData =
2437*cdf0e10cSrcweir 			(MenuSaveInData*) aSaveInListBox.GetEntryData( i );
2438*cdf0e10cSrcweir 
2439*cdf0e10cSrcweir 		delete pData;
2440*cdf0e10cSrcweir 	}
2441*cdf0e10cSrcweir 
2442*cdf0e10cSrcweir 	if ( pSelectorDlg != NULL )
2443*cdf0e10cSrcweir 	{
2444*cdf0e10cSrcweir 		delete pSelectorDlg;
2445*cdf0e10cSrcweir 	}
2446*cdf0e10cSrcweir 
2447*cdf0e10cSrcweir 	delete aContentsListBox;
2448*cdf0e10cSrcweir }
2449*cdf0e10cSrcweir 
2450*cdf0e10cSrcweir IMPL_LINK( SvxMenuConfigPage, SelectMenuEntry, Control *, pBox )
2451*cdf0e10cSrcweir {
2452*cdf0e10cSrcweir 	(void)pBox;
2453*cdf0e10cSrcweir 
2454*cdf0e10cSrcweir 	UpdateButtonStates();
2455*cdf0e10cSrcweir 
2456*cdf0e10cSrcweir 	return 1;
2457*cdf0e10cSrcweir }
2458*cdf0e10cSrcweir 
2459*cdf0e10cSrcweir void SvxMenuConfigPage::UpdateButtonStates()
2460*cdf0e10cSrcweir {
2461*cdf0e10cSrcweir 	PopupMenu* pPopup = aModifyCommandButton.GetPopupMenu();
2462*cdf0e10cSrcweir 
2463*cdf0e10cSrcweir 	// Disable Up and Down buttons depending on current selection
2464*cdf0e10cSrcweir 	SvLBoxEntry* selection = aContentsListBox->GetCurEntry();
2465*cdf0e10cSrcweir 
2466*cdf0e10cSrcweir 	if ( aContentsListBox->GetEntryCount() == 0 || selection == NULL )
2467*cdf0e10cSrcweir 	{
2468*cdf0e10cSrcweir 		aMoveUpButton.Enable( sal_False );
2469*cdf0e10cSrcweir 		aMoveDownButton.Enable( sal_False );
2470*cdf0e10cSrcweir 
2471*cdf0e10cSrcweir 		pPopup->EnableItem( ID_BEGIN_GROUP, sal_True );
2472*cdf0e10cSrcweir 		pPopup->EnableItem( ID_RENAME, sal_False );
2473*cdf0e10cSrcweir 		pPopup->EnableItem( ID_DELETE, sal_False );
2474*cdf0e10cSrcweir 
2475*cdf0e10cSrcweir         aDescriptionField.Clear();
2476*cdf0e10cSrcweir 
2477*cdf0e10cSrcweir 		return;
2478*cdf0e10cSrcweir 	}
2479*cdf0e10cSrcweir 
2480*cdf0e10cSrcweir 	SvLBoxEntry* first = aContentsListBox->First();
2481*cdf0e10cSrcweir 	SvLBoxEntry* last = aContentsListBox->Last();
2482*cdf0e10cSrcweir 
2483*cdf0e10cSrcweir 	aMoveUpButton.Enable( selection != first );
2484*cdf0e10cSrcweir 	aMoveDownButton.Enable( selection != last );
2485*cdf0e10cSrcweir 
2486*cdf0e10cSrcweir 	SvxConfigEntry* pEntryData =
2487*cdf0e10cSrcweir 		(SvxConfigEntry*) selection->GetUserData();
2488*cdf0e10cSrcweir 
2489*cdf0e10cSrcweir 	if ( pEntryData->IsSeparator() )
2490*cdf0e10cSrcweir 	{
2491*cdf0e10cSrcweir 		pPopup->EnableItem( ID_DELETE, sal_True );
2492*cdf0e10cSrcweir 		pPopup->EnableItem( ID_BEGIN_GROUP, sal_False );
2493*cdf0e10cSrcweir 		pPopup->EnableItem( ID_RENAME, sal_False );
2494*cdf0e10cSrcweir 
2495*cdf0e10cSrcweir         aDescriptionField.Clear();
2496*cdf0e10cSrcweir 	}
2497*cdf0e10cSrcweir 	else
2498*cdf0e10cSrcweir 	{
2499*cdf0e10cSrcweir 		pPopup->EnableItem( ID_BEGIN_GROUP, sal_True );
2500*cdf0e10cSrcweir 		pPopup->EnableItem( ID_DELETE, sal_True );
2501*cdf0e10cSrcweir 		pPopup->EnableItem( ID_RENAME, sal_True );
2502*cdf0e10cSrcweir 
2503*cdf0e10cSrcweir         aDescriptionField.SetNewText( pEntryData->GetHelpText() );
2504*cdf0e10cSrcweir 	}
2505*cdf0e10cSrcweir }
2506*cdf0e10cSrcweir 
2507*cdf0e10cSrcweir void SvxMenuConfigPage::DeleteSelectedTopLevel()
2508*cdf0e10cSrcweir {
2509*cdf0e10cSrcweir 	SvxConfigEntry* pMenuData = GetTopLevelSelection();
2510*cdf0e10cSrcweir 
2511*cdf0e10cSrcweir 	SvxEntries* pParentEntries =
2512*cdf0e10cSrcweir 		FindParentForChild( GetSaveInData()->GetEntries(), pMenuData );
2513*cdf0e10cSrcweir 
2514*cdf0e10cSrcweir 	RemoveEntry( pParentEntries, pMenuData );
2515*cdf0e10cSrcweir 	delete pMenuData;
2516*cdf0e10cSrcweir 
2517*cdf0e10cSrcweir 	ReloadTopLevelListBox();
2518*cdf0e10cSrcweir 
2519*cdf0e10cSrcweir 	GetSaveInData()->SetModified( sal_True );
2520*cdf0e10cSrcweir }
2521*cdf0e10cSrcweir 
2522*cdf0e10cSrcweir bool SvxMenuConfigPage::DeleteSelectedContent()
2523*cdf0e10cSrcweir {
2524*cdf0e10cSrcweir 	SvLBoxEntry *pActEntry = aContentsListBox->FirstSelected();
2525*cdf0e10cSrcweir 
2526*cdf0e10cSrcweir 	if ( pActEntry != NULL )
2527*cdf0e10cSrcweir 	{
2528*cdf0e10cSrcweir 		// get currently selected menu entry
2529*cdf0e10cSrcweir 		SvxConfigEntry* pMenuEntry =
2530*cdf0e10cSrcweir 			(SvxConfigEntry*) pActEntry->GetUserData();
2531*cdf0e10cSrcweir 
2532*cdf0e10cSrcweir 		// get currently selected menu
2533*cdf0e10cSrcweir 		SvxConfigEntry* pMenu = GetTopLevelSelection();
2534*cdf0e10cSrcweir 
2535*cdf0e10cSrcweir 		// remove menu entry from the list for this menu
2536*cdf0e10cSrcweir 		RemoveEntry( pMenu->GetEntries(), pMenuEntry );
2537*cdf0e10cSrcweir 
2538*cdf0e10cSrcweir 		// remove menu entry from UI
2539*cdf0e10cSrcweir 		aContentsListBox->GetModel()->Remove( pActEntry );
2540*cdf0e10cSrcweir 
2541*cdf0e10cSrcweir 		// if this is a submenu entry, redraw the menus list box
2542*cdf0e10cSrcweir 		if ( pMenuEntry->IsPopup() )
2543*cdf0e10cSrcweir 		{
2544*cdf0e10cSrcweir 			ReloadTopLevelListBox();
2545*cdf0e10cSrcweir 		}
2546*cdf0e10cSrcweir 
2547*cdf0e10cSrcweir 		// delete data for menu entry
2548*cdf0e10cSrcweir 		delete pMenuEntry;
2549*cdf0e10cSrcweir 
2550*cdf0e10cSrcweir 		GetSaveInData()->SetModified( sal_True );
2551*cdf0e10cSrcweir 
2552*cdf0e10cSrcweir 		return sal_True;
2553*cdf0e10cSrcweir 	}
2554*cdf0e10cSrcweir 	return sal_False;
2555*cdf0e10cSrcweir }
2556*cdf0e10cSrcweir 
2557*cdf0e10cSrcweir short SvxMenuConfigPage::QueryReset()
2558*cdf0e10cSrcweir {
2559*cdf0e10cSrcweir 	String msg =
2560*cdf0e10cSrcweir 		String( CUI_RES( RID_SVXSTR_CONFIRM_MENU_RESET ) );
2561*cdf0e10cSrcweir 
2562*cdf0e10cSrcweir 	String saveInName = aSaveInListBox.GetEntry(
2563*cdf0e10cSrcweir 		aSaveInListBox.GetSelectEntryPos() );
2564*cdf0e10cSrcweir 
2565*cdf0e10cSrcweir 	OUString label = replaceSaveInName( msg, saveInName );
2566*cdf0e10cSrcweir 
2567*cdf0e10cSrcweir 	QueryBox qbox( this, WB_YES_NO, label );
2568*cdf0e10cSrcweir 
2569*cdf0e10cSrcweir 	return qbox.Execute();
2570*cdf0e10cSrcweir }
2571*cdf0e10cSrcweir 
2572*cdf0e10cSrcweir IMPL_LINK( SvxMenuConfigPage, SelectMenu, ListBox *, pBox )
2573*cdf0e10cSrcweir {
2574*cdf0e10cSrcweir 	(void)pBox;
2575*cdf0e10cSrcweir 
2576*cdf0e10cSrcweir 	aContentsListBox->Clear();
2577*cdf0e10cSrcweir 
2578*cdf0e10cSrcweir 	SvxConfigEntry* pMenuData = GetTopLevelSelection();
2579*cdf0e10cSrcweir 
2580*cdf0e10cSrcweir 	PopupMenu* pPopup = aModifyTopLevelButton.GetPopupMenu();
2581*cdf0e10cSrcweir     if ( pMenuData )
2582*cdf0e10cSrcweir     {
2583*cdf0e10cSrcweir 	    pPopup->EnableItem( ID_DELETE, pMenuData->IsDeletable() );
2584*cdf0e10cSrcweir 	    pPopup->EnableItem( ID_RENAME, pMenuData->IsRenamable() );
2585*cdf0e10cSrcweir 	    pPopup->EnableItem( ID_MOVE, pMenuData->IsMovable() );
2586*cdf0e10cSrcweir 
2587*cdf0e10cSrcweir 	    SvxEntries* pEntries = pMenuData->GetEntries();
2588*cdf0e10cSrcweir 	    SvxEntries::const_iterator iter = pEntries->begin();
2589*cdf0e10cSrcweir 
2590*cdf0e10cSrcweir 	    for ( ; iter != pEntries->end(); iter++ )
2591*cdf0e10cSrcweir 	    {
2592*cdf0e10cSrcweir 		    SvxConfigEntry* pEntry = *iter;
2593*cdf0e10cSrcweir 		    InsertEntryIntoUI( pEntry );
2594*cdf0e10cSrcweir 	    }
2595*cdf0e10cSrcweir     }
2596*cdf0e10cSrcweir 
2597*cdf0e10cSrcweir 	UpdateButtonStates();
2598*cdf0e10cSrcweir 
2599*cdf0e10cSrcweir 	return 0;
2600*cdf0e10cSrcweir }
2601*cdf0e10cSrcweir 
2602*cdf0e10cSrcweir IMPL_LINK( SvxMenuConfigPage, MenuSelectHdl, MenuButton *, pButton )
2603*cdf0e10cSrcweir {
2604*cdf0e10cSrcweir 	switch( pButton->GetCurItemId() )
2605*cdf0e10cSrcweir 	{
2606*cdf0e10cSrcweir 		case ID_DELETE:
2607*cdf0e10cSrcweir 		{
2608*cdf0e10cSrcweir 			DeleteSelectedTopLevel();
2609*cdf0e10cSrcweir 			break;
2610*cdf0e10cSrcweir 		}
2611*cdf0e10cSrcweir 		case ID_RENAME:
2612*cdf0e10cSrcweir 		{
2613*cdf0e10cSrcweir 			SvxConfigEntry* pMenuData = GetTopLevelSelection();
2614*cdf0e10cSrcweir 
2615*cdf0e10cSrcweir 			String aNewName( stripHotKey( pMenuData->GetName() ) );
2616*cdf0e10cSrcweir             String aDesc = CUI_RESSSTR( RID_SVXSTR_LABEL_NEW_NAME );
2617*cdf0e10cSrcweir 
2618*cdf0e10cSrcweir 			SvxNameDialog* pNameDialog = new SvxNameDialog( this, aNewName, aDesc );
2619*cdf0e10cSrcweir 			pNameDialog->SetHelpId( HID_SVX_CONFIG_RENAME_MENU );
2620*cdf0e10cSrcweir             pNameDialog->SetText( CUI_RESSTR( RID_SVXSTR_RENAME_MENU ) );
2621*cdf0e10cSrcweir 
2622*cdf0e10cSrcweir 			bool ret = pNameDialog->Execute();
2623*cdf0e10cSrcweir 
2624*cdf0e10cSrcweir 			if ( ret == RET_OK ) {
2625*cdf0e10cSrcweir 				pNameDialog->GetName( aNewName );
2626*cdf0e10cSrcweir 				pMenuData->SetName( aNewName );
2627*cdf0e10cSrcweir 
2628*cdf0e10cSrcweir 				ReloadTopLevelListBox();
2629*cdf0e10cSrcweir 
2630*cdf0e10cSrcweir 				GetSaveInData()->SetModified( sal_True );
2631*cdf0e10cSrcweir 			}
2632*cdf0e10cSrcweir 
2633*cdf0e10cSrcweir 			// #i68101# Moemory leak (!)
2634*cdf0e10cSrcweir 			delete pNameDialog;
2635*cdf0e10cSrcweir 
2636*cdf0e10cSrcweir 			break;
2637*cdf0e10cSrcweir 		}
2638*cdf0e10cSrcweir 		case ID_MOVE:
2639*cdf0e10cSrcweir 		{
2640*cdf0e10cSrcweir 			SvxConfigEntry* pMenuData = GetTopLevelSelection();
2641*cdf0e10cSrcweir 
2642*cdf0e10cSrcweir 			SvxMainMenuOrganizerDialog* pDialog =
2643*cdf0e10cSrcweir 				new SvxMainMenuOrganizerDialog( this,
2644*cdf0e10cSrcweir 					GetSaveInData()->GetEntries(), pMenuData );
2645*cdf0e10cSrcweir 
2646*cdf0e10cSrcweir 			bool ret = pDialog->Execute();
2647*cdf0e10cSrcweir 
2648*cdf0e10cSrcweir 			if ( ret == RET_OK )
2649*cdf0e10cSrcweir 			{
2650*cdf0e10cSrcweir 				GetSaveInData()->SetEntries( pDialog->GetEntries() );
2651*cdf0e10cSrcweir 
2652*cdf0e10cSrcweir 				ReloadTopLevelListBox( pDialog->GetSelectedEntry() );
2653*cdf0e10cSrcweir 
2654*cdf0e10cSrcweir 				GetSaveInData()->SetModified( sal_True );
2655*cdf0e10cSrcweir 			}
2656*cdf0e10cSrcweir 
2657*cdf0e10cSrcweir 			delete pDialog;
2658*cdf0e10cSrcweir 
2659*cdf0e10cSrcweir 			break;
2660*cdf0e10cSrcweir 		}
2661*cdf0e10cSrcweir 		default:
2662*cdf0e10cSrcweir 			return sal_False;
2663*cdf0e10cSrcweir 	}
2664*cdf0e10cSrcweir 	return sal_True;
2665*cdf0e10cSrcweir }
2666*cdf0e10cSrcweir 
2667*cdf0e10cSrcweir IMPL_LINK( SvxMenuConfigPage, EntrySelectHdl, MenuButton *, pButton )
2668*cdf0e10cSrcweir {
2669*cdf0e10cSrcweir 	switch( pButton->GetCurItemId() )
2670*cdf0e10cSrcweir 	{
2671*cdf0e10cSrcweir 		case ID_ADD_SUBMENU:
2672*cdf0e10cSrcweir 		{
2673*cdf0e10cSrcweir             String aNewName;
2674*cdf0e10cSrcweir             String aDesc = CUI_RESSSTR( RID_SVXSTR_SUBMENU_NAME );
2675*cdf0e10cSrcweir 
2676*cdf0e10cSrcweir 			SvxNameDialog* pNameDialog = new SvxNameDialog( this, aNewName, aDesc );
2677*cdf0e10cSrcweir 			pNameDialog->SetHelpId( HID_SVX_CONFIG_NAME_SUBMENU );
2678*cdf0e10cSrcweir             pNameDialog->SetText( CUI_RESSTR( RID_SVXSTR_ADD_SUBMENU ) );
2679*cdf0e10cSrcweir 
2680*cdf0e10cSrcweir 			bool ret = pNameDialog->Execute();
2681*cdf0e10cSrcweir 
2682*cdf0e10cSrcweir 			if ( ret == RET_OK ) {
2683*cdf0e10cSrcweir 				pNameDialog->GetName(aNewName);
2684*cdf0e10cSrcweir 
2685*cdf0e10cSrcweir 				SvxConfigEntry* pNewEntryData =
2686*cdf0e10cSrcweir 					new SvxConfigEntry( aNewName, aNewName, sal_True );
2687*cdf0e10cSrcweir 				pNewEntryData->SetUserDefined( sal_True );
2688*cdf0e10cSrcweir 
2689*cdf0e10cSrcweir 				InsertEntry( pNewEntryData );
2690*cdf0e10cSrcweir 
2691*cdf0e10cSrcweir 				ReloadTopLevelListBox();
2692*cdf0e10cSrcweir 
2693*cdf0e10cSrcweir 				GetSaveInData()->SetModified( sal_True );
2694*cdf0e10cSrcweir 			}
2695*cdf0e10cSrcweir 
2696*cdf0e10cSrcweir 			delete pNameDialog;
2697*cdf0e10cSrcweir 
2698*cdf0e10cSrcweir 			break;
2699*cdf0e10cSrcweir 		}
2700*cdf0e10cSrcweir 		case ID_BEGIN_GROUP:
2701*cdf0e10cSrcweir 		{
2702*cdf0e10cSrcweir 			SvxConfigEntry* pNewEntryData = new SvxConfigEntry;
2703*cdf0e10cSrcweir 			pNewEntryData->SetUserDefined( sal_True );
2704*cdf0e10cSrcweir 			InsertEntry( pNewEntryData );
2705*cdf0e10cSrcweir 
2706*cdf0e10cSrcweir 			break;
2707*cdf0e10cSrcweir 		}
2708*cdf0e10cSrcweir 		case ID_DELETE:
2709*cdf0e10cSrcweir 		{
2710*cdf0e10cSrcweir 			DeleteSelectedContent();
2711*cdf0e10cSrcweir 			break;
2712*cdf0e10cSrcweir 		}
2713*cdf0e10cSrcweir 		case ID_RENAME:
2714*cdf0e10cSrcweir 		{
2715*cdf0e10cSrcweir 			SvLBoxEntry* pActEntry = aContentsListBox->GetCurEntry();
2716*cdf0e10cSrcweir 			SvxConfigEntry* pEntry =
2717*cdf0e10cSrcweir 				(SvxConfigEntry*) pActEntry->GetUserData();
2718*cdf0e10cSrcweir 
2719*cdf0e10cSrcweir 			String aNewName( stripHotKey( pEntry->GetName() ) );
2720*cdf0e10cSrcweir             String aDesc = CUI_RESSSTR( RID_SVXSTR_LABEL_NEW_NAME );
2721*cdf0e10cSrcweir 
2722*cdf0e10cSrcweir 			SvxNameDialog* pNameDialog = new SvxNameDialog( this, aNewName, aDesc );
2723*cdf0e10cSrcweir 			pNameDialog->SetHelpId( HID_SVX_CONFIG_RENAME_MENU_ITEM );
2724*cdf0e10cSrcweir             pNameDialog->SetText( CUI_RESSTR( RID_SVXSTR_RENAME_MENU ) );
2725*cdf0e10cSrcweir 
2726*cdf0e10cSrcweir 			bool ret = pNameDialog->Execute();
2727*cdf0e10cSrcweir 
2728*cdf0e10cSrcweir 			if ( ret == RET_OK ) {
2729*cdf0e10cSrcweir 				pNameDialog->GetName(aNewName);
2730*cdf0e10cSrcweir 
2731*cdf0e10cSrcweir 				pEntry->SetName( aNewName );
2732*cdf0e10cSrcweir 				aContentsListBox->SetEntryText( pActEntry, aNewName );
2733*cdf0e10cSrcweir 
2734*cdf0e10cSrcweir 				GetSaveInData()->SetModified( sal_True );
2735*cdf0e10cSrcweir 			}
2736*cdf0e10cSrcweir 
2737*cdf0e10cSrcweir 			delete pNameDialog;
2738*cdf0e10cSrcweir 
2739*cdf0e10cSrcweir 			break;
2740*cdf0e10cSrcweir 		}
2741*cdf0e10cSrcweir 		default:
2742*cdf0e10cSrcweir 		{
2743*cdf0e10cSrcweir 			return sal_False;
2744*cdf0e10cSrcweir 		}
2745*cdf0e10cSrcweir 	}
2746*cdf0e10cSrcweir 
2747*cdf0e10cSrcweir 	if ( GetSaveInData()->IsModified() )
2748*cdf0e10cSrcweir 	{
2749*cdf0e10cSrcweir 		UpdateButtonStates();
2750*cdf0e10cSrcweir 	}
2751*cdf0e10cSrcweir 
2752*cdf0e10cSrcweir 	return sal_True;
2753*cdf0e10cSrcweir }
2754*cdf0e10cSrcweir 
2755*cdf0e10cSrcweir IMPL_LINK( SvxMenuConfigPage, AddFunctionHdl,
2756*cdf0e10cSrcweir 	SvxScriptSelectorDialog *, pDialog )
2757*cdf0e10cSrcweir {
2758*cdf0e10cSrcweir 	(void)pDialog;
2759*cdf0e10cSrcweir 
2760*cdf0e10cSrcweir 	AddFunction();
2761*cdf0e10cSrcweir 
2762*cdf0e10cSrcweir 	return 0;
2763*cdf0e10cSrcweir }
2764*cdf0e10cSrcweir 
2765*cdf0e10cSrcweir IMPL_LINK( SvxMenuConfigPage, NewMenuHdl, Button *, pButton )
2766*cdf0e10cSrcweir {
2767*cdf0e10cSrcweir 	(void)pButton;
2768*cdf0e10cSrcweir 
2769*cdf0e10cSrcweir 	SvxMainMenuOrganizerDialog* pDialog =
2770*cdf0e10cSrcweir 		new SvxMainMenuOrganizerDialog( 0,
2771*cdf0e10cSrcweir 			GetSaveInData()->GetEntries(), NULL, sal_True );
2772*cdf0e10cSrcweir 
2773*cdf0e10cSrcweir 	bool ret = pDialog->Execute();
2774*cdf0e10cSrcweir 
2775*cdf0e10cSrcweir 	if ( ret == RET_OK )
2776*cdf0e10cSrcweir 	{
2777*cdf0e10cSrcweir 		GetSaveInData()->SetEntries( pDialog->GetEntries() );
2778*cdf0e10cSrcweir 		ReloadTopLevelListBox( pDialog->GetSelectedEntry() );
2779*cdf0e10cSrcweir 		GetSaveInData()->SetModified( sal_True );
2780*cdf0e10cSrcweir 	}
2781*cdf0e10cSrcweir 
2782*cdf0e10cSrcweir 	delete pDialog;
2783*cdf0e10cSrcweir 
2784*cdf0e10cSrcweir 	return 0;
2785*cdf0e10cSrcweir }
2786*cdf0e10cSrcweir 
2787*cdf0e10cSrcweir IMPL_LINK( SvxMenuConfigPage, AddCommandsHdl, Button *, pButton )
2788*cdf0e10cSrcweir {
2789*cdf0e10cSrcweir 	(void)pButton;
2790*cdf0e10cSrcweir 
2791*cdf0e10cSrcweir 	if ( pSelectorDlg == NULL )
2792*cdf0e10cSrcweir 	{
2793*cdf0e10cSrcweir 		// Create Script Selector which also shows builtin commands
2794*cdf0e10cSrcweir 		pSelectorDlg = new SvxScriptSelectorDialog( this, sal_True, m_xFrame );
2795*cdf0e10cSrcweir 
2796*cdf0e10cSrcweir 		pSelectorDlg->SetAddHdl(
2797*cdf0e10cSrcweir 			LINK( this, SvxMenuConfigPage, AddFunctionHdl ) );
2798*cdf0e10cSrcweir 
2799*cdf0e10cSrcweir 		pSelectorDlg->SetDialogDescription( String(
2800*cdf0e10cSrcweir 			CUI_RES( RID_SVXSTR_MENU_ADDCOMMANDS_DESCRIPTION ) ) );
2801*cdf0e10cSrcweir 	}
2802*cdf0e10cSrcweir 
2803*cdf0e10cSrcweir 	// Position the Script Selector over the Add button so it is
2804*cdf0e10cSrcweir 	// beside the menu contents list and does not obscure it
2805*cdf0e10cSrcweir 	pSelectorDlg->SetPosPixel( aAddCommandsButton.GetPosPixel() );
2806*cdf0e10cSrcweir 
2807*cdf0e10cSrcweir 	pSelectorDlg->SetImageProvider(
2808*cdf0e10cSrcweir 		static_cast< ImageProvider* >( GetSaveInData() ) );
2809*cdf0e10cSrcweir 
2810*cdf0e10cSrcweir 	pSelectorDlg->Show();
2811*cdf0e10cSrcweir 	return 1;
2812*cdf0e10cSrcweir }
2813*cdf0e10cSrcweir 
2814*cdf0e10cSrcweir SaveInData* SvxMenuConfigPage::CreateSaveInData(
2815*cdf0e10cSrcweir 	const uno::Reference< css::ui::XUIConfigurationManager >& xCfgMgr,
2816*cdf0e10cSrcweir     const uno::Reference< css::ui::XUIConfigurationManager >& xParentCfgMgr,
2817*cdf0e10cSrcweir 	const OUString& aModuleId,
2818*cdf0e10cSrcweir 	bool bDocConfig )
2819*cdf0e10cSrcweir {
2820*cdf0e10cSrcweir 	return static_cast< SaveInData* >(
2821*cdf0e10cSrcweir 		new MenuSaveInData( xCfgMgr, xParentCfgMgr, aModuleId, bDocConfig ));
2822*cdf0e10cSrcweir }
2823*cdf0e10cSrcweir 
2824*cdf0e10cSrcweir SvxMainMenuOrganizerDialog::SvxMainMenuOrganizerDialog(
2825*cdf0e10cSrcweir 	Window* pParent, SvxEntries* entries,
2826*cdf0e10cSrcweir 	SvxConfigEntry* selection, bool bCreateMenu )
2827*cdf0e10cSrcweir 	:
2828*cdf0e10cSrcweir 	ModalDialog( pParent, CUI_RES( MD_MENU_ORGANISER ) ),
2829*cdf0e10cSrcweir 	aMenuNameText( this, CUI_RES( TXT_MENU_NAME ) ),
2830*cdf0e10cSrcweir 	aMenuNameEdit( this, CUI_RES( EDIT_MENU_NAME ) ),
2831*cdf0e10cSrcweir 	aMenuListText( this, CUI_RES( TXT_MENU ) ),
2832*cdf0e10cSrcweir 	aMenuListBox( this, CUI_RES( BOX_MAIN_MENUS ) ),
2833*cdf0e10cSrcweir 	aMoveUpButton( this, CUI_RES( BTN_MENU_UP ) ),
2834*cdf0e10cSrcweir 	aMoveDownButton( this, CUI_RES( BTN_MENU_DOWN ) ),
2835*cdf0e10cSrcweir 	aOKButton( this, CUI_RES( BTN_MENU_ADD ) ),
2836*cdf0e10cSrcweir 	aCloseButton( this, CUI_RES( BTN_MENU_CLOSE ) ),
2837*cdf0e10cSrcweir 	aHelpButton( this, CUI_RES( BTN_MENU_HELP ) ),
2838*cdf0e10cSrcweir 	bModified( sal_False )
2839*cdf0e10cSrcweir {
2840*cdf0e10cSrcweir 	FreeResource();
2841*cdf0e10cSrcweir 
2842*cdf0e10cSrcweir 	// Copy the entries list passed in
2843*cdf0e10cSrcweir 	if ( entries != NULL )
2844*cdf0e10cSrcweir 	{
2845*cdf0e10cSrcweir 		SvxConfigEntry* pEntry;
2846*cdf0e10cSrcweir 		SvLBoxEntry* pLBEntry;
2847*cdf0e10cSrcweir 
2848*cdf0e10cSrcweir 		pEntries = new SvxEntries();
2849*cdf0e10cSrcweir 		SvxEntries::const_iterator iter = entries->begin();
2850*cdf0e10cSrcweir 
2851*cdf0e10cSrcweir 		while ( iter != entries->end() )
2852*cdf0e10cSrcweir 		{
2853*cdf0e10cSrcweir 			pEntry = *iter;
2854*cdf0e10cSrcweir 			pLBEntry =
2855*cdf0e10cSrcweir 				aMenuListBox.InsertEntry( stripHotKey( pEntry->GetName() ) );
2856*cdf0e10cSrcweir 			pLBEntry->SetUserData( pEntry );
2857*cdf0e10cSrcweir 			pEntries->push_back( pEntry );
2858*cdf0e10cSrcweir 
2859*cdf0e10cSrcweir 			if ( pEntry == selection )
2860*cdf0e10cSrcweir 			{
2861*cdf0e10cSrcweir 				aMenuListBox.Select( pLBEntry );
2862*cdf0e10cSrcweir 			}
2863*cdf0e10cSrcweir 			iter++;
2864*cdf0e10cSrcweir 		}
2865*cdf0e10cSrcweir 	}
2866*cdf0e10cSrcweir 
2867*cdf0e10cSrcweir 	if ( bCreateMenu )
2868*cdf0e10cSrcweir 	{
2869*cdf0e10cSrcweir 		// Generate custom name for new menu
2870*cdf0e10cSrcweir 		String prefix =
2871*cdf0e10cSrcweir 			String( CUI_RES( RID_SVXSTR_NEW_MENU ) );
2872*cdf0e10cSrcweir 
2873*cdf0e10cSrcweir 		OUString newname = generateCustomName( prefix, entries );
2874*cdf0e10cSrcweir 		OUString newurl = generateCustomMenuURL( pEntries );
2875*cdf0e10cSrcweir 
2876*cdf0e10cSrcweir 		SvxConfigEntry* pNewEntryData =
2877*cdf0e10cSrcweir 			new SvxConfigEntry( newname, newurl, sal_True );
2878*cdf0e10cSrcweir 		pNewEntryData->SetUserDefined( sal_True );
2879*cdf0e10cSrcweir 		pNewEntryData->SetMain( sal_True );
2880*cdf0e10cSrcweir 
2881*cdf0e10cSrcweir 		pNewMenuEntry =
2882*cdf0e10cSrcweir 			aMenuListBox.InsertEntry( stripHotKey( pNewEntryData->GetName() ) );
2883*cdf0e10cSrcweir 		aMenuListBox.Select( pNewMenuEntry );
2884*cdf0e10cSrcweir 
2885*cdf0e10cSrcweir 		pNewMenuEntry->SetUserData( pNewEntryData );
2886*cdf0e10cSrcweir 
2887*cdf0e10cSrcweir 		pEntries->push_back( pNewEntryData );
2888*cdf0e10cSrcweir 
2889*cdf0e10cSrcweir 		aMenuNameEdit.SetText( newname );
2890*cdf0e10cSrcweir     	aMenuNameEdit.SetModifyHdl(
2891*cdf0e10cSrcweir 			LINK( this, SvxMainMenuOrganizerDialog, ModifyHdl ) );
2892*cdf0e10cSrcweir 	}
2893*cdf0e10cSrcweir 	else
2894*cdf0e10cSrcweir 	{
2895*cdf0e10cSrcweir 		Point p, newp;
2896*cdf0e10cSrcweir 		Size s, news;
2897*cdf0e10cSrcweir 
2898*cdf0e10cSrcweir 		// get offset to bottom of name textfield from top of dialog
2899*cdf0e10cSrcweir 		p = aMenuNameEdit.GetPosPixel();
2900*cdf0e10cSrcweir 		s = aMenuNameEdit.GetSizePixel();
2901*cdf0e10cSrcweir 		long offset = p.Y() + s.Height();
2902*cdf0e10cSrcweir 
2903*cdf0e10cSrcweir 		// reposition menu list and label
2904*cdf0e10cSrcweir 		aMenuListText.SetPosPixel( aMenuNameText.GetPosPixel() );
2905*cdf0e10cSrcweir 		aMenuListBox.SetPosPixel( aMenuNameEdit.GetPosPixel() );
2906*cdf0e10cSrcweir 
2907*cdf0e10cSrcweir 		// reposition up and down buttons
2908*cdf0e10cSrcweir         p = aMoveUpButton.GetPosPixel();
2909*cdf0e10cSrcweir         newp = Point( p.X(), p.Y() - offset );
2910*cdf0e10cSrcweir 		aMoveUpButton.SetPosPixel( newp );
2911*cdf0e10cSrcweir 
2912*cdf0e10cSrcweir         p = aMoveDownButton.GetPosPixel();
2913*cdf0e10cSrcweir         newp = Point( p.X(), p.Y() - offset );
2914*cdf0e10cSrcweir 		aMoveDownButton.SetPosPixel( newp );
2915*cdf0e10cSrcweir 
2916*cdf0e10cSrcweir 		// change size of dialog
2917*cdf0e10cSrcweir 		s = GetSizePixel();
2918*cdf0e10cSrcweir 		news = Size( s.Width(), s.Height() - offset );
2919*cdf0e10cSrcweir 		SetSizePixel( news );
2920*cdf0e10cSrcweir 
2921*cdf0e10cSrcweir 		// hide name label and textfield
2922*cdf0e10cSrcweir 		aMenuNameText.Hide();
2923*cdf0e10cSrcweir 		aMenuNameEdit.Hide();
2924*cdf0e10cSrcweir 
2925*cdf0e10cSrcweir 		// change the title
2926*cdf0e10cSrcweir 		SetText( CUI_RES( RID_SVXSTR_MOVE_MENU ) );
2927*cdf0e10cSrcweir 	}
2928*cdf0e10cSrcweir 
2929*cdf0e10cSrcweir 	aMenuListBox.SetSelectHdl(
2930*cdf0e10cSrcweir 		LINK( this, SvxMainMenuOrganizerDialog, SelectHdl ) );
2931*cdf0e10cSrcweir 
2932*cdf0e10cSrcweir 	aMoveUpButton.SetClickHdl (
2933*cdf0e10cSrcweir 		LINK( this, SvxMainMenuOrganizerDialog, MoveHdl) );
2934*cdf0e10cSrcweir 	aMoveDownButton.SetClickHdl	(
2935*cdf0e10cSrcweir 		LINK( this, SvxMainMenuOrganizerDialog, MoveHdl) );
2936*cdf0e10cSrcweir 
2937*cdf0e10cSrcweir 	aMoveUpButton.SetAccessibleName(String(CUI_RES(BUTTON_STR_UP)));
2938*cdf0e10cSrcweir 	aMoveDownButton.SetAccessibleName(String(CUI_RES(BUTTON_STR_DOWN)));
2939*cdf0e10cSrcweir }
2940*cdf0e10cSrcweir 
2941*cdf0e10cSrcweir IMPL_LINK(SvxMainMenuOrganizerDialog, ModifyHdl, Edit*, pEdit)
2942*cdf0e10cSrcweir {
2943*cdf0e10cSrcweir 	(void)pEdit;
2944*cdf0e10cSrcweir 
2945*cdf0e10cSrcweir 	// if the Edit control is empty do not change the name
2946*cdf0e10cSrcweir 	if ( aMenuNameEdit.GetText().Equals( String() ) )
2947*cdf0e10cSrcweir 	{
2948*cdf0e10cSrcweir 		return 0;
2949*cdf0e10cSrcweir 	}
2950*cdf0e10cSrcweir 
2951*cdf0e10cSrcweir 	SvxConfigEntry* pNewEntryData =
2952*cdf0e10cSrcweir 		(SvxConfigEntry*) pNewMenuEntry->GetUserData();
2953*cdf0e10cSrcweir 
2954*cdf0e10cSrcweir 	pNewEntryData->SetName( aMenuNameEdit.GetText() );
2955*cdf0e10cSrcweir 
2956*cdf0e10cSrcweir 	aMenuListBox.SetEntryText( pNewMenuEntry, pNewEntryData->GetName() );
2957*cdf0e10cSrcweir 
2958*cdf0e10cSrcweir     return 0;
2959*cdf0e10cSrcweir }
2960*cdf0e10cSrcweir 
2961*cdf0e10cSrcweir SvxMainMenuOrganizerDialog::~SvxMainMenuOrganizerDialog()
2962*cdf0e10cSrcweir {
2963*cdf0e10cSrcweir }
2964*cdf0e10cSrcweir 
2965*cdf0e10cSrcweir IMPL_LINK( SvxMainMenuOrganizerDialog, SelectHdl, Control*, pCtrl )
2966*cdf0e10cSrcweir {
2967*cdf0e10cSrcweir 	(void)pCtrl;
2968*cdf0e10cSrcweir 	UpdateButtonStates();
2969*cdf0e10cSrcweir 	return 1;
2970*cdf0e10cSrcweir }
2971*cdf0e10cSrcweir 
2972*cdf0e10cSrcweir void SvxMainMenuOrganizerDialog::UpdateButtonStates()
2973*cdf0e10cSrcweir {
2974*cdf0e10cSrcweir 	// Disable Up and Down buttons depending on current selection
2975*cdf0e10cSrcweir 	SvLBoxEntry* selection = aMenuListBox.GetCurEntry();
2976*cdf0e10cSrcweir 	SvLBoxEntry* first = aMenuListBox.First();
2977*cdf0e10cSrcweir 	SvLBoxEntry* last = aMenuListBox.Last();
2978*cdf0e10cSrcweir 
2979*cdf0e10cSrcweir 	aMoveUpButton.Enable( selection != first );
2980*cdf0e10cSrcweir 	aMoveDownButton.Enable( selection != last );
2981*cdf0e10cSrcweir }
2982*cdf0e10cSrcweir 
2983*cdf0e10cSrcweir IMPL_LINK( SvxMainMenuOrganizerDialog, MoveHdl, Button *, pButton )
2984*cdf0e10cSrcweir {
2985*cdf0e10cSrcweir 	SvLBoxEntry *pSourceEntry = aMenuListBox.FirstSelected();
2986*cdf0e10cSrcweir 	SvLBoxEntry *pTargetEntry = NULL;
2987*cdf0e10cSrcweir 
2988*cdf0e10cSrcweir 	if ( !pSourceEntry )
2989*cdf0e10cSrcweir 	{
2990*cdf0e10cSrcweir 		return 0;
2991*cdf0e10cSrcweir 	}
2992*cdf0e10cSrcweir 
2993*cdf0e10cSrcweir 	if ( pButton == &aMoveDownButton )
2994*cdf0e10cSrcweir 	{
2995*cdf0e10cSrcweir 		pTargetEntry = aMenuListBox.NextSibling( pSourceEntry );
2996*cdf0e10cSrcweir 	}
2997*cdf0e10cSrcweir 	else if ( pButton == &aMoveUpButton )
2998*cdf0e10cSrcweir 	{
2999*cdf0e10cSrcweir 		// Move Up is just a Move Down with the source and target reversed
3000*cdf0e10cSrcweir 		pTargetEntry = pSourceEntry;
3001*cdf0e10cSrcweir 		pSourceEntry = aMenuListBox.PrevSibling( pTargetEntry );
3002*cdf0e10cSrcweir 	}
3003*cdf0e10cSrcweir 
3004*cdf0e10cSrcweir 	if ( pSourceEntry != NULL && pTargetEntry != NULL )
3005*cdf0e10cSrcweir 	{
3006*cdf0e10cSrcweir 		SvxConfigEntry* pSourceData =
3007*cdf0e10cSrcweir 			(SvxConfigEntry*) pSourceEntry->GetUserData();
3008*cdf0e10cSrcweir 		SvxConfigEntry* pTargetData =
3009*cdf0e10cSrcweir 			(SvxConfigEntry*) pTargetEntry->GetUserData();
3010*cdf0e10cSrcweir 
3011*cdf0e10cSrcweir 		SvxEntries::iterator iter1 = GetEntries()->begin();
3012*cdf0e10cSrcweir 		SvxEntries::iterator iter2 = GetEntries()->begin();
3013*cdf0e10cSrcweir 		SvxEntries::const_iterator end = GetEntries()->end();
3014*cdf0e10cSrcweir 
3015*cdf0e10cSrcweir 		// Advance the iterators to the positions of the source and target
3016*cdf0e10cSrcweir 		while (*iter1 != pSourceData && ++iter1 != end) ;
3017*cdf0e10cSrcweir 		while (*iter2 != pTargetData && ++iter2 != end) ;
3018*cdf0e10cSrcweir 
3019*cdf0e10cSrcweir 		// Now swap the entries in the menu list and in the UI
3020*cdf0e10cSrcweir 		if ( iter1 != end && iter2 != end )
3021*cdf0e10cSrcweir 		{
3022*cdf0e10cSrcweir 			std::swap( *iter1, *iter2 );
3023*cdf0e10cSrcweir 			aMenuListBox.GetModel()->Move( pSourceEntry, pTargetEntry );
3024*cdf0e10cSrcweir 			aMenuListBox.MakeVisible( pSourceEntry );
3025*cdf0e10cSrcweir 
3026*cdf0e10cSrcweir 			bModified = sal_True;
3027*cdf0e10cSrcweir 		}
3028*cdf0e10cSrcweir 	}
3029*cdf0e10cSrcweir 
3030*cdf0e10cSrcweir 	if ( bModified )
3031*cdf0e10cSrcweir 	{
3032*cdf0e10cSrcweir 		UpdateButtonStates();
3033*cdf0e10cSrcweir 	}
3034*cdf0e10cSrcweir 
3035*cdf0e10cSrcweir 	return 0;
3036*cdf0e10cSrcweir }
3037*cdf0e10cSrcweir 
3038*cdf0e10cSrcweir SvxEntries* SvxMainMenuOrganizerDialog::GetEntries()
3039*cdf0e10cSrcweir {
3040*cdf0e10cSrcweir 	return pEntries;
3041*cdf0e10cSrcweir }
3042*cdf0e10cSrcweir 
3043*cdf0e10cSrcweir SvxConfigEntry* SvxMainMenuOrganizerDialog::GetSelectedEntry()
3044*cdf0e10cSrcweir {
3045*cdf0e10cSrcweir 	return (SvxConfigEntry*)aMenuListBox.FirstSelected()->GetUserData();
3046*cdf0e10cSrcweir }
3047*cdf0e10cSrcweir 
3048*cdf0e10cSrcweir const OUString&
3049*cdf0e10cSrcweir SvxConfigEntry::GetHelpText()
3050*cdf0e10cSrcweir {
3051*cdf0e10cSrcweir 	if ( aHelpText.getLength() == 0 )
3052*cdf0e10cSrcweir 	{
3053*cdf0e10cSrcweir 		if ( aCommand.getLength() )
3054*cdf0e10cSrcweir 		{
3055*cdf0e10cSrcweir 			aHelpText = Application::GetHelp()->GetHelpText( aCommand, NULL );
3056*cdf0e10cSrcweir 		}
3057*cdf0e10cSrcweir 	}
3058*cdf0e10cSrcweir 
3059*cdf0e10cSrcweir 	return aHelpText;
3060*cdf0e10cSrcweir }
3061*cdf0e10cSrcweir 
3062*cdf0e10cSrcweir SvxConfigEntry::SvxConfigEntry( const OUString& rDisplayName,
3063*cdf0e10cSrcweir 								const OUString& rCommandURL, bool bPopup, bool bParentData )
3064*cdf0e10cSrcweir 	: nId( 1 )
3065*cdf0e10cSrcweir 	, aLabel(rDisplayName)
3066*cdf0e10cSrcweir 	, aCommand(rCommandURL)
3067*cdf0e10cSrcweir 	, bPopUp(bPopup)
3068*cdf0e10cSrcweir 	, bStrEdited( sal_False )
3069*cdf0e10cSrcweir 	, bIsUserDefined( sal_False )
3070*cdf0e10cSrcweir 	, bIsMain( sal_False )
3071*cdf0e10cSrcweir     , bIsParentData( bParentData )
3072*cdf0e10cSrcweir 	, bIsVisible( sal_True )
3073*cdf0e10cSrcweir 	, nStyle( 0 )
3074*cdf0e10cSrcweir 	, pEntries( 0 )
3075*cdf0e10cSrcweir {
3076*cdf0e10cSrcweir 	if (bPopUp)
3077*cdf0e10cSrcweir 	{
3078*cdf0e10cSrcweir 		pEntries = new SvxEntries();
3079*cdf0e10cSrcweir 	}
3080*cdf0e10cSrcweir }
3081*cdf0e10cSrcweir 
3082*cdf0e10cSrcweir SvxConfigEntry::~SvxConfigEntry()
3083*cdf0e10cSrcweir {
3084*cdf0e10cSrcweir 	if ( pEntries != NULL )
3085*cdf0e10cSrcweir 	{
3086*cdf0e10cSrcweir 		SvxEntries::const_iterator iter = pEntries->begin();
3087*cdf0e10cSrcweir 
3088*cdf0e10cSrcweir 		for ( ; iter != pEntries->end(); iter++ )
3089*cdf0e10cSrcweir 		{
3090*cdf0e10cSrcweir 			delete *iter;
3091*cdf0e10cSrcweir 		}
3092*cdf0e10cSrcweir 		delete pEntries;
3093*cdf0e10cSrcweir 	}
3094*cdf0e10cSrcweir }
3095*cdf0e10cSrcweir 
3096*cdf0e10cSrcweir bool SvxConfigEntry::IsMovable()
3097*cdf0e10cSrcweir {
3098*cdf0e10cSrcweir 	if ( IsPopup() && !IsMain() )
3099*cdf0e10cSrcweir 	{
3100*cdf0e10cSrcweir 		return sal_False;
3101*cdf0e10cSrcweir 	}
3102*cdf0e10cSrcweir 	return sal_True;
3103*cdf0e10cSrcweir }
3104*cdf0e10cSrcweir 
3105*cdf0e10cSrcweir bool SvxConfigEntry::IsDeletable()
3106*cdf0e10cSrcweir {
3107*cdf0e10cSrcweir 	if ( IsMain() && !IsUserDefined() )
3108*cdf0e10cSrcweir 	{
3109*cdf0e10cSrcweir 		return sal_False;
3110*cdf0e10cSrcweir 	}
3111*cdf0e10cSrcweir 	return sal_True;
3112*cdf0e10cSrcweir }
3113*cdf0e10cSrcweir 
3114*cdf0e10cSrcweir bool SvxConfigEntry::IsRenamable()
3115*cdf0e10cSrcweir {
3116*cdf0e10cSrcweir 	if ( IsMain() && !IsUserDefined() )
3117*cdf0e10cSrcweir 	{
3118*cdf0e10cSrcweir 		return sal_False;
3119*cdf0e10cSrcweir 	}
3120*cdf0e10cSrcweir 	return sal_True;
3121*cdf0e10cSrcweir }
3122*cdf0e10cSrcweir 
3123*cdf0e10cSrcweir SvxToolbarConfigPage::SvxToolbarConfigPage(
3124*cdf0e10cSrcweir 	Window *pParent, const SfxItemSet& rSet )
3125*cdf0e10cSrcweir 	:
3126*cdf0e10cSrcweir 	SvxConfigPage( pParent, rSet )
3127*cdf0e10cSrcweir {
3128*cdf0e10cSrcweir 	SetHelpId( HID_SVX_CONFIG_TOOLBAR );
3129*cdf0e10cSrcweir 
3130*cdf0e10cSrcweir 	aContentsListBox = new SvxToolbarEntriesListBox(this, CUI_RES(BOX_ENTRIES));
3131*cdf0e10cSrcweir 	FreeResource();
3132*cdf0e10cSrcweir 	PositionContentsListBox();
3133*cdf0e10cSrcweir 	aContentsListBox->SetZOrder( &aAddCommandsButton, WINDOW_ZORDER_BEFOR );
3134*cdf0e10cSrcweir 
3135*cdf0e10cSrcweir 	aContentsListBox->SetHelpId( HID_SVX_CONFIG_TOOLBAR_CONTENTS );
3136*cdf0e10cSrcweir     aNewTopLevelButton.SetHelpId( HID_SVX_NEW_TOOLBAR );
3137*cdf0e10cSrcweir     aModifyTopLevelButton.SetHelpId( HID_SVX_MODIFY_TOOLBAR );
3138*cdf0e10cSrcweir     aAddCommandsButton.SetHelpId( HID_SVX_NEW_TOOLBAR_ITEM );
3139*cdf0e10cSrcweir     aModifyCommandButton.SetHelpId( HID_SVX_MODIFY_TOOLBAR_ITEM );
3140*cdf0e10cSrcweir     aSaveInListBox.SetHelpId( HID_SVX_SAVE_IN );
3141*cdf0e10cSrcweir 
3142*cdf0e10cSrcweir 	aTopLevelSeparator.SetText(
3143*cdf0e10cSrcweir 		CUI_RES ( RID_SVXSTR_PRODUCTNAME_TOOLBARS ) );
3144*cdf0e10cSrcweir 
3145*cdf0e10cSrcweir 	aTopLevelLabel.SetText( CUI_RES( RID_SVXSTR_TOOLBAR ) );
3146*cdf0e10cSrcweir 	aModifyTopLevelButton.SetText( CUI_RES( RID_SVXSTR_TOOLBAR ) );
3147*cdf0e10cSrcweir 	aContentsSeparator.SetText( CUI_RES( RID_SVXSTR_TOOLBAR_CONTENT ) );
3148*cdf0e10cSrcweir 	aContentsLabel.SetText( CUI_RES( RID_SVXSTR_COMMANDS ) );
3149*cdf0e10cSrcweir 
3150*cdf0e10cSrcweir 	aTopLevelListBox.SetSelectHdl(
3151*cdf0e10cSrcweir 		LINK( this, SvxToolbarConfigPage, SelectToolbar ) );
3152*cdf0e10cSrcweir 	aContentsListBox->SetSelectHdl(
3153*cdf0e10cSrcweir 		LINK( this, SvxToolbarConfigPage, SelectToolbarEntry ) );
3154*cdf0e10cSrcweir 
3155*cdf0e10cSrcweir 	aNewTopLevelButton.SetClickHdl	(
3156*cdf0e10cSrcweir 		LINK( this, SvxToolbarConfigPage, NewToolbarHdl ) );
3157*cdf0e10cSrcweir 
3158*cdf0e10cSrcweir 	aAddCommandsButton.SetClickHdl	(
3159*cdf0e10cSrcweir 		LINK( this, SvxToolbarConfigPage, AddCommandsHdl ) );
3160*cdf0e10cSrcweir 
3161*cdf0e10cSrcweir 	aMoveUpButton.SetClickHdl ( LINK( this, SvxToolbarConfigPage, MoveHdl) );
3162*cdf0e10cSrcweir 	aMoveDownButton.SetClickHdl	( LINK( this, SvxToolbarConfigPage, MoveHdl) );
3163*cdf0e10cSrcweir     // Always enable Up and Down buttons
3164*cdf0e10cSrcweir     // added for issue i53677 by shizhoubo
3165*cdf0e10cSrcweir     aMoveDownButton.Enable( sal_True );
3166*cdf0e10cSrcweir     aMoveUpButton.Enable( sal_True );
3167*cdf0e10cSrcweir 
3168*cdf0e10cSrcweir 	PopupMenu* pMenu = new PopupMenu( CUI_RES( MODIFY_TOOLBAR ) );
3169*cdf0e10cSrcweir 	pMenu->SetMenuFlags(
3170*cdf0e10cSrcweir 		pMenu->GetMenuFlags() | MENU_FLAG_ALWAYSSHOWDISABLEDENTRIES );
3171*cdf0e10cSrcweir 
3172*cdf0e10cSrcweir 	aModifyTopLevelButton.SetPopupMenu( pMenu );
3173*cdf0e10cSrcweir 	aModifyTopLevelButton.SetSelectHdl(
3174*cdf0e10cSrcweir 		LINK( this, SvxToolbarConfigPage, ToolbarSelectHdl ) );
3175*cdf0e10cSrcweir 
3176*cdf0e10cSrcweir 	PopupMenu* pEntry = new PopupMenu(
3177*cdf0e10cSrcweir 		CUI_RES( MODIFY_TOOLBAR_CONTENT ) );
3178*cdf0e10cSrcweir 	pEntry->SetMenuFlags(
3179*cdf0e10cSrcweir 		pEntry->GetMenuFlags() | MENU_FLAG_ALWAYSSHOWDISABLEDENTRIES );
3180*cdf0e10cSrcweir 
3181*cdf0e10cSrcweir 	aModifyCommandButton.SetPopupMenu( pEntry );
3182*cdf0e10cSrcweir 	aModifyCommandButton.SetSelectHdl(
3183*cdf0e10cSrcweir 		LINK( this, SvxToolbarConfigPage, EntrySelectHdl ) );
3184*cdf0e10cSrcweir 
3185*cdf0e10cSrcweir 	// default toolbar to select is standardbar unless a different one
3186*cdf0e10cSrcweir 	// has been passed in
3187*cdf0e10cSrcweir 	m_aURLToSelect = OUString::createFromAscii( ITEM_TOOLBAR_URL );
3188*cdf0e10cSrcweir 	m_aURLToSelect += OUString::createFromAscii( "standardbar" );
3189*cdf0e10cSrcweir 
3190*cdf0e10cSrcweir 	const SfxPoolItem* pItem =
3191*cdf0e10cSrcweir 		rSet.GetItem( rSet.GetPool()->GetWhich( SID_CONFIG ) );
3192*cdf0e10cSrcweir 
3193*cdf0e10cSrcweir 	if ( pItem )
3194*cdf0e10cSrcweir 	{
3195*cdf0e10cSrcweir 		OUString text = ((const SfxStringItem*)pItem)->GetValue();
3196*cdf0e10cSrcweir 		if (text.indexOf(OUString::createFromAscii(ITEM_TOOLBAR_URL)) == 0)
3197*cdf0e10cSrcweir 		{
3198*cdf0e10cSrcweir 			m_aURLToSelect = text.copy( 0 );
3199*cdf0e10cSrcweir 		}
3200*cdf0e10cSrcweir 	}
3201*cdf0e10cSrcweir 
3202*cdf0e10cSrcweir     long nTxtW = aTopLevelLabel.GetCtrlTextWidth( aTopLevelLabel.GetText() );
3203*cdf0e10cSrcweir     long nCtrlW = aTopLevelLabel.GetSizePixel().Width();
3204*cdf0e10cSrcweir     if ( nTxtW >= nCtrlW )
3205*cdf0e10cSrcweir     {
3206*cdf0e10cSrcweir         long nDelta = Max( (long)10, nTxtW - nCtrlW );
3207*cdf0e10cSrcweir         Size aNewSz = aTopLevelLabel.GetSizePixel();
3208*cdf0e10cSrcweir         aNewSz.Width() += nDelta;
3209*cdf0e10cSrcweir         aTopLevelLabel.SetSizePixel( aNewSz );
3210*cdf0e10cSrcweir         aNewSz = aTopLevelListBox.GetSizePixel();
3211*cdf0e10cSrcweir         aNewSz.Width() -= nDelta;
3212*cdf0e10cSrcweir         Point aNewPt = aTopLevelListBox.GetPosPixel();
3213*cdf0e10cSrcweir         aNewPt.X() += nDelta;
3214*cdf0e10cSrcweir         aTopLevelListBox.SetPosSizePixel( aNewPt, aNewSz );
3215*cdf0e10cSrcweir     }
3216*cdf0e10cSrcweir }
3217*cdf0e10cSrcweir 
3218*cdf0e10cSrcweir SvxToolbarConfigPage::~SvxToolbarConfigPage()
3219*cdf0e10cSrcweir {
3220*cdf0e10cSrcweir 	for ( sal_uInt16 i = 0 ; i < aSaveInListBox.GetEntryCount(); i++ )
3221*cdf0e10cSrcweir 	{
3222*cdf0e10cSrcweir 		ToolbarSaveInData* pData =
3223*cdf0e10cSrcweir 			(ToolbarSaveInData*) aSaveInListBox.GetEntryData( i );
3224*cdf0e10cSrcweir 
3225*cdf0e10cSrcweir 		delete pData;
3226*cdf0e10cSrcweir 	}
3227*cdf0e10cSrcweir 
3228*cdf0e10cSrcweir 	if ( pSelectorDlg != NULL )
3229*cdf0e10cSrcweir 	{
3230*cdf0e10cSrcweir 		delete pSelectorDlg;
3231*cdf0e10cSrcweir 	}
3232*cdf0e10cSrcweir 
3233*cdf0e10cSrcweir 
3234*cdf0e10cSrcweir 	delete aContentsListBox;
3235*cdf0e10cSrcweir }
3236*cdf0e10cSrcweir 
3237*cdf0e10cSrcweir void SvxToolbarConfigPage::DeleteSelectedTopLevel()
3238*cdf0e10cSrcweir {
3239*cdf0e10cSrcweir 	sal_uInt16 nSelectionPos = aTopLevelListBox.GetSelectEntryPos();
3240*cdf0e10cSrcweir 	ToolbarSaveInData* pSaveInData = (ToolbarSaveInData*) GetSaveInData();
3241*cdf0e10cSrcweir 	pSaveInData->RemoveToolbar( GetTopLevelSelection() );
3242*cdf0e10cSrcweir 
3243*cdf0e10cSrcweir 	if ( aTopLevelListBox.GetEntryCount() > 1 )
3244*cdf0e10cSrcweir 	{
3245*cdf0e10cSrcweir 		// select next entry after the one being deleted
3246*cdf0e10cSrcweir 		// selection position is indexed from 0 so need to
3247*cdf0e10cSrcweir 		// subtract one from the entry count
3248*cdf0e10cSrcweir 		if ( nSelectionPos != aTopLevelListBox.GetEntryCount() - 1 )
3249*cdf0e10cSrcweir 		{
3250*cdf0e10cSrcweir 			aTopLevelListBox.SelectEntryPos( nSelectionPos + 1, sal_True );
3251*cdf0e10cSrcweir 		}
3252*cdf0e10cSrcweir 		else
3253*cdf0e10cSrcweir 		{
3254*cdf0e10cSrcweir 			aTopLevelListBox.SelectEntryPos( nSelectionPos - 1, sal_True );
3255*cdf0e10cSrcweir 		}
3256*cdf0e10cSrcweir 		aTopLevelListBox.GetSelectHdl().Call( this );
3257*cdf0e10cSrcweir 
3258*cdf0e10cSrcweir 		// and now remove the entry
3259*cdf0e10cSrcweir 		aTopLevelListBox.RemoveEntry( nSelectionPos );
3260*cdf0e10cSrcweir 	}
3261*cdf0e10cSrcweir 	else
3262*cdf0e10cSrcweir 	{
3263*cdf0e10cSrcweir 		ReloadTopLevelListBox();
3264*cdf0e10cSrcweir 	}
3265*cdf0e10cSrcweir }
3266*cdf0e10cSrcweir 
3267*cdf0e10cSrcweir bool SvxToolbarConfigPage::DeleteSelectedContent()
3268*cdf0e10cSrcweir {
3269*cdf0e10cSrcweir 	SvLBoxEntry *pActEntry = aContentsListBox->FirstSelected();
3270*cdf0e10cSrcweir 
3271*cdf0e10cSrcweir 	if ( pActEntry != NULL )
3272*cdf0e10cSrcweir 	{
3273*cdf0e10cSrcweir 		// get currently selected entry
3274*cdf0e10cSrcweir 		SvxConfigEntry* pEntry =
3275*cdf0e10cSrcweir 			(SvxConfigEntry*) pActEntry->GetUserData();
3276*cdf0e10cSrcweir 
3277*cdf0e10cSrcweir 		SvxConfigEntry* pToolbar = GetTopLevelSelection();
3278*cdf0e10cSrcweir 
3279*cdf0e10cSrcweir 		// remove entry from the list for this toolbar
3280*cdf0e10cSrcweir 		RemoveEntry( pToolbar->GetEntries(), pEntry );
3281*cdf0e10cSrcweir 
3282*cdf0e10cSrcweir 		// remove toolbar entry from UI
3283*cdf0e10cSrcweir 		aContentsListBox->GetModel()->Remove( pActEntry );
3284*cdf0e10cSrcweir 
3285*cdf0e10cSrcweir 		// delete data for toolbar entry
3286*cdf0e10cSrcweir 		delete pEntry;
3287*cdf0e10cSrcweir 
3288*cdf0e10cSrcweir 		(( ToolbarSaveInData* ) GetSaveInData())->ApplyToolbar( pToolbar );
3289*cdf0e10cSrcweir 		UpdateButtonStates();
3290*cdf0e10cSrcweir 
3291*cdf0e10cSrcweir 		// if this is the last entry in the toolbar and it is a user
3292*cdf0e10cSrcweir 		// defined toolbar pop up a dialog asking the user if they
3293*cdf0e10cSrcweir 		// want to delete the toolbar
3294*cdf0e10cSrcweir 		if ( aContentsListBox->GetEntryCount() == 0 &&
3295*cdf0e10cSrcweir 			 GetTopLevelSelection()->IsDeletable() )
3296*cdf0e10cSrcweir 		{
3297*cdf0e10cSrcweir 			QueryBox qbox( this,
3298*cdf0e10cSrcweir 				CUI_RES( QBX_CONFIRM_DELETE_TOOLBAR ) );
3299*cdf0e10cSrcweir 
3300*cdf0e10cSrcweir 			if ( qbox.Execute() == RET_YES )
3301*cdf0e10cSrcweir 			{
3302*cdf0e10cSrcweir 				DeleteSelectedTopLevel();
3303*cdf0e10cSrcweir 			}
3304*cdf0e10cSrcweir 		}
3305*cdf0e10cSrcweir 
3306*cdf0e10cSrcweir 		return sal_True;
3307*cdf0e10cSrcweir 	}
3308*cdf0e10cSrcweir 
3309*cdf0e10cSrcweir 	return sal_False;
3310*cdf0e10cSrcweir }
3311*cdf0e10cSrcweir 
3312*cdf0e10cSrcweir IMPL_LINK( SvxToolbarConfigPage, MoveHdl, Button *, pButton )
3313*cdf0e10cSrcweir {
3314*cdf0e10cSrcweir 	MoveEntry( pButton == &aMoveUpButton );
3315*cdf0e10cSrcweir 	return 0;
3316*cdf0e10cSrcweir }
3317*cdf0e10cSrcweir 
3318*cdf0e10cSrcweir void SvxToolbarConfigPage::MoveEntry( bool bMoveUp )
3319*cdf0e10cSrcweir {
3320*cdf0e10cSrcweir 	SvxConfigPage::MoveEntry( bMoveUp );
3321*cdf0e10cSrcweir 
3322*cdf0e10cSrcweir 	// Apply change to currently selected toolbar
3323*cdf0e10cSrcweir 	SvxConfigEntry* pToolbar = GetTopLevelSelection();
3324*cdf0e10cSrcweir     if ( pToolbar )
3325*cdf0e10cSrcweir         ((ToolbarSaveInData*)GetSaveInData())->ApplyToolbar( pToolbar );
3326*cdf0e10cSrcweir     else
3327*cdf0e10cSrcweir     {
3328*cdf0e10cSrcweir         DBG_ERRORFILE( "SvxToolbarConfigPage::MoveEntry(): no entry" );
3329*cdf0e10cSrcweir         UpdateButtonStates();
3330*cdf0e10cSrcweir     }
3331*cdf0e10cSrcweir }
3332*cdf0e10cSrcweir 
3333*cdf0e10cSrcweir IMPL_LINK( SvxToolbarConfigPage, ToolbarSelectHdl, MenuButton *, pButton )
3334*cdf0e10cSrcweir {
3335*cdf0e10cSrcweir 	sal_uInt16 nSelectionPos = aTopLevelListBox.GetSelectEntryPos();
3336*cdf0e10cSrcweir 
3337*cdf0e10cSrcweir 	SvxConfigEntry* pToolbar =
3338*cdf0e10cSrcweir 		(SvxConfigEntry*)aTopLevelListBox.GetEntryData( nSelectionPos );
3339*cdf0e10cSrcweir 
3340*cdf0e10cSrcweir 	ToolbarSaveInData* pSaveInData = (ToolbarSaveInData*) GetSaveInData();
3341*cdf0e10cSrcweir 
3342*cdf0e10cSrcweir 	switch( pButton->GetCurItemId() )
3343*cdf0e10cSrcweir 	{
3344*cdf0e10cSrcweir 		case ID_DELETE:
3345*cdf0e10cSrcweir 		{
3346*cdf0e10cSrcweir 			DeleteSelectedTopLevel();
3347*cdf0e10cSrcweir             UpdateButtonStates();
3348*cdf0e10cSrcweir 			break;
3349*cdf0e10cSrcweir 		}
3350*cdf0e10cSrcweir 		case ID_RENAME:
3351*cdf0e10cSrcweir 		{
3352*cdf0e10cSrcweir 			String aNewName( stripHotKey( pToolbar->GetName() ) );
3353*cdf0e10cSrcweir             String aDesc = CUI_RESSSTR( RID_SVXSTR_LABEL_NEW_NAME );
3354*cdf0e10cSrcweir 
3355*cdf0e10cSrcweir 			SvxNameDialog* pNameDialog = new SvxNameDialog( this, aNewName, aDesc );
3356*cdf0e10cSrcweir 			pNameDialog->SetHelpId( HID_SVX_CONFIG_RENAME_TOOLBAR );
3357*cdf0e10cSrcweir             pNameDialog->SetText( CUI_RESSTR( RID_SVXSTR_RENAME_TOOLBAR ) );
3358*cdf0e10cSrcweir 
3359*cdf0e10cSrcweir 			bool ret = pNameDialog->Execute();
3360*cdf0e10cSrcweir 
3361*cdf0e10cSrcweir 			if ( ret == RET_OK )
3362*cdf0e10cSrcweir 			{
3363*cdf0e10cSrcweir 				pNameDialog->GetName(aNewName);
3364*cdf0e10cSrcweir 
3365*cdf0e10cSrcweir 				pToolbar->SetName( aNewName );
3366*cdf0e10cSrcweir 				pSaveInData->ApplyToolbar( pToolbar );
3367*cdf0e10cSrcweir 
3368*cdf0e10cSrcweir 				// have to use remove and insert to change the name
3369*cdf0e10cSrcweir 				aTopLevelListBox.RemoveEntry( nSelectionPos );
3370*cdf0e10cSrcweir 				nSelectionPos =
3371*cdf0e10cSrcweir 					aTopLevelListBox.InsertEntry( aNewName, nSelectionPos );
3372*cdf0e10cSrcweir 				aTopLevelListBox.SetEntryData( nSelectionPos, pToolbar );
3373*cdf0e10cSrcweir 				aTopLevelListBox.SelectEntryPos( nSelectionPos );
3374*cdf0e10cSrcweir 			}
3375*cdf0e10cSrcweir 
3376*cdf0e10cSrcweir 			delete pNameDialog;
3377*cdf0e10cSrcweir 
3378*cdf0e10cSrcweir 			break;
3379*cdf0e10cSrcweir 		}
3380*cdf0e10cSrcweir 		case ID_DEFAULT_STYLE:
3381*cdf0e10cSrcweir 		{
3382*cdf0e10cSrcweir 			QueryBox qbox( this,
3383*cdf0e10cSrcweir 				CUI_RES( QBX_CONFIRM_RESTORE_DEFAULT ) );
3384*cdf0e10cSrcweir 
3385*cdf0e10cSrcweir 			if ( qbox.Execute() == RET_YES )
3386*cdf0e10cSrcweir 			{
3387*cdf0e10cSrcweir 				ToolbarSaveInData* pSaveInData_ =
3388*cdf0e10cSrcweir 					(ToolbarSaveInData*) GetSaveInData();
3389*cdf0e10cSrcweir 
3390*cdf0e10cSrcweir 				pSaveInData_->RestoreToolbar( pToolbar );
3391*cdf0e10cSrcweir 
3392*cdf0e10cSrcweir 				aTopLevelListBox.GetSelectHdl().Call( this );
3393*cdf0e10cSrcweir 			}
3394*cdf0e10cSrcweir 
3395*cdf0e10cSrcweir 			break;
3396*cdf0e10cSrcweir 		}
3397*cdf0e10cSrcweir 		case ID_ICONS_ONLY:
3398*cdf0e10cSrcweir 		{
3399*cdf0e10cSrcweir 			pToolbar->SetStyle( 0 );
3400*cdf0e10cSrcweir 			pSaveInData->SetSystemStyle( m_xFrame, pToolbar->GetCommand(), 0 );
3401*cdf0e10cSrcweir 
3402*cdf0e10cSrcweir 			aTopLevelListBox.GetSelectHdl().Call( this );
3403*cdf0e10cSrcweir 
3404*cdf0e10cSrcweir 			break;
3405*cdf0e10cSrcweir 		}
3406*cdf0e10cSrcweir 		case ID_TEXT_ONLY:
3407*cdf0e10cSrcweir 		{
3408*cdf0e10cSrcweir 			pToolbar->SetStyle( 1 );
3409*cdf0e10cSrcweir 			pSaveInData->SetSystemStyle( m_xFrame, pToolbar->GetCommand(), 1 );
3410*cdf0e10cSrcweir 
3411*cdf0e10cSrcweir 			aTopLevelListBox.GetSelectHdl().Call( this );
3412*cdf0e10cSrcweir 
3413*cdf0e10cSrcweir 			break;
3414*cdf0e10cSrcweir 		}
3415*cdf0e10cSrcweir 		case ID_ICONS_AND_TEXT:
3416*cdf0e10cSrcweir 		{
3417*cdf0e10cSrcweir 			pToolbar->SetStyle( 2 );
3418*cdf0e10cSrcweir 			pSaveInData->SetSystemStyle( m_xFrame, pToolbar->GetCommand(), 2 );
3419*cdf0e10cSrcweir 
3420*cdf0e10cSrcweir 			aTopLevelListBox.GetSelectHdl().Call( this );
3421*cdf0e10cSrcweir 
3422*cdf0e10cSrcweir 			break;
3423*cdf0e10cSrcweir 		}
3424*cdf0e10cSrcweir 	}
3425*cdf0e10cSrcweir 	return 1;
3426*cdf0e10cSrcweir }
3427*cdf0e10cSrcweir 
3428*cdf0e10cSrcweir IMPL_LINK( SvxToolbarConfigPage, EntrySelectHdl, MenuButton *, pButton )
3429*cdf0e10cSrcweir {
3430*cdf0e10cSrcweir 	bool bNeedsApply = sal_False;
3431*cdf0e10cSrcweir 
3432*cdf0e10cSrcweir 	// get currently selected toolbar
3433*cdf0e10cSrcweir 	SvxConfigEntry* pToolbar = GetTopLevelSelection();
3434*cdf0e10cSrcweir 
3435*cdf0e10cSrcweir 	switch( pButton->GetCurItemId() )
3436*cdf0e10cSrcweir 	{
3437*cdf0e10cSrcweir 		case ID_RENAME:
3438*cdf0e10cSrcweir 		{
3439*cdf0e10cSrcweir 			SvLBoxEntry* pActEntry = aContentsListBox->GetCurEntry();
3440*cdf0e10cSrcweir 			SvxConfigEntry* pEntry =
3441*cdf0e10cSrcweir 				(SvxConfigEntry*) pActEntry->GetUserData();
3442*cdf0e10cSrcweir 
3443*cdf0e10cSrcweir 			String aNewName( stripHotKey( pEntry->GetName() ) );
3444*cdf0e10cSrcweir             String aDesc = CUI_RESSSTR( RID_SVXSTR_LABEL_NEW_NAME );
3445*cdf0e10cSrcweir 
3446*cdf0e10cSrcweir 			SvxNameDialog* pNameDialog = new SvxNameDialog( this, aNewName, aDesc );
3447*cdf0e10cSrcweir 			pNameDialog->SetHelpId( HID_SVX_CONFIG_RENAME_TOOLBAR_ITEM );
3448*cdf0e10cSrcweir             pNameDialog->SetText( CUI_RESSTR( RID_SVXSTR_RENAME_TOOLBAR ) );
3449*cdf0e10cSrcweir 
3450*cdf0e10cSrcweir 			bool ret = pNameDialog->Execute();
3451*cdf0e10cSrcweir 
3452*cdf0e10cSrcweir 			if ( ret == RET_OK ) {
3453*cdf0e10cSrcweir 				pNameDialog->GetName(aNewName);
3454*cdf0e10cSrcweir 
3455*cdf0e10cSrcweir 				pEntry->SetName( aNewName );
3456*cdf0e10cSrcweir 				aContentsListBox->SetEntryText( pActEntry, aNewName );
3457*cdf0e10cSrcweir 
3458*cdf0e10cSrcweir 				bNeedsApply = sal_True;
3459*cdf0e10cSrcweir 			}
3460*cdf0e10cSrcweir 
3461*cdf0e10cSrcweir 			delete pNameDialog;
3462*cdf0e10cSrcweir 			break;
3463*cdf0e10cSrcweir 		}
3464*cdf0e10cSrcweir 		case ID_DEFAULT_COMMAND:
3465*cdf0e10cSrcweir 		{
3466*cdf0e10cSrcweir 			SvLBoxEntry* pActEntry = aContentsListBox->GetCurEntry();
3467*cdf0e10cSrcweir 			SvxConfigEntry* pEntry =
3468*cdf0e10cSrcweir 				(SvxConfigEntry*) pActEntry->GetUserData();
3469*cdf0e10cSrcweir 
3470*cdf0e10cSrcweir 			sal_uInt16 nSelectionPos = 0;
3471*cdf0e10cSrcweir 
3472*cdf0e10cSrcweir 			// find position of entry within the list
3473*cdf0e10cSrcweir 			for ( sal_uInt16 i = 0; i < aContentsListBox->GetEntryCount(); i++ )
3474*cdf0e10cSrcweir 			{
3475*cdf0e10cSrcweir 				if ( aContentsListBox->GetEntry( 0, i ) == pActEntry )
3476*cdf0e10cSrcweir 				{
3477*cdf0e10cSrcweir 					nSelectionPos = i;
3478*cdf0e10cSrcweir 					break;
3479*cdf0e10cSrcweir 				}
3480*cdf0e10cSrcweir 			}
3481*cdf0e10cSrcweir 
3482*cdf0e10cSrcweir 			ToolbarSaveInData* pSaveInData =
3483*cdf0e10cSrcweir 				(ToolbarSaveInData*) GetSaveInData();
3484*cdf0e10cSrcweir 
3485*cdf0e10cSrcweir 			OUString aSystemName =
3486*cdf0e10cSrcweir 				pSaveInData->GetSystemUIName( pEntry->GetCommand() );
3487*cdf0e10cSrcweir 
3488*cdf0e10cSrcweir 			if ( !pEntry->GetName().equals( aSystemName ) )
3489*cdf0e10cSrcweir 			{
3490*cdf0e10cSrcweir 				pEntry->SetName( aSystemName );
3491*cdf0e10cSrcweir 				aContentsListBox->SetEntryText(
3492*cdf0e10cSrcweir 					pActEntry, stripHotKey( aSystemName ) );
3493*cdf0e10cSrcweir 				bNeedsApply = sal_True;
3494*cdf0e10cSrcweir 			}
3495*cdf0e10cSrcweir 
3496*cdf0e10cSrcweir 			uno::Sequence< OUString > aURLSeq( 1 );
3497*cdf0e10cSrcweir 			aURLSeq[ 0 ] = pEntry->GetCommand();
3498*cdf0e10cSrcweir 
3499*cdf0e10cSrcweir 			try
3500*cdf0e10cSrcweir 			{
3501*cdf0e10cSrcweir 				GetSaveInData()->GetImageManager()->removeImages(
3502*cdf0e10cSrcweir 					GetImageType(), aURLSeq );
3503*cdf0e10cSrcweir 
3504*cdf0e10cSrcweir 				// reset backup in entry
3505*cdf0e10cSrcweir 				pEntry->SetBackupGraphic(
3506*cdf0e10cSrcweir 					uno::Reference< graphic::XGraphic >() );
3507*cdf0e10cSrcweir 
3508*cdf0e10cSrcweir 				GetSaveInData()->PersistChanges(
3509*cdf0e10cSrcweir 				    GetSaveInData()->GetImageManager() );
3510*cdf0e10cSrcweir 
3511*cdf0e10cSrcweir 				aContentsListBox->GetModel()->Remove( pActEntry );
3512*cdf0e10cSrcweir 
3513*cdf0e10cSrcweir 				SvLBoxEntry* pNewLBEntry =
3514*cdf0e10cSrcweir 					InsertEntryIntoUI( pEntry, nSelectionPos );
3515*cdf0e10cSrcweir 
3516*cdf0e10cSrcweir 				aContentsListBox->SetCheckButtonState( pNewLBEntry,
3517*cdf0e10cSrcweir 					pEntry->IsVisible() ?
3518*cdf0e10cSrcweir 						SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
3519*cdf0e10cSrcweir 
3520*cdf0e10cSrcweir 				aContentsListBox->Select( pNewLBEntry );
3521*cdf0e10cSrcweir 				aContentsListBox->MakeVisible( pNewLBEntry );
3522*cdf0e10cSrcweir 
3523*cdf0e10cSrcweir 				bNeedsApply = sal_True;
3524*cdf0e10cSrcweir 			}
3525*cdf0e10cSrcweir            	catch ( uno::Exception& )
3526*cdf0e10cSrcweir            	{
3527*cdf0e10cSrcweir 				OSL_TRACE("Error restoring image");
3528*cdf0e10cSrcweir            	}
3529*cdf0e10cSrcweir 			break;
3530*cdf0e10cSrcweir 		}
3531*cdf0e10cSrcweir 		case ID_BEGIN_GROUP:
3532*cdf0e10cSrcweir 		{
3533*cdf0e10cSrcweir 			SvxConfigEntry* pNewEntryData = new SvxConfigEntry;
3534*cdf0e10cSrcweir 			pNewEntryData->SetUserDefined( sal_True );
3535*cdf0e10cSrcweir 
3536*cdf0e10cSrcweir 			SvLBoxEntry* pNewLBEntry = InsertEntry( pNewEntryData );
3537*cdf0e10cSrcweir 
3538*cdf0e10cSrcweir 			aContentsListBox->SetCheckButtonState(
3539*cdf0e10cSrcweir 				pNewLBEntry, SV_BUTTON_TRISTATE );
3540*cdf0e10cSrcweir 
3541*cdf0e10cSrcweir 			bNeedsApply = sal_True;
3542*cdf0e10cSrcweir 			break;
3543*cdf0e10cSrcweir 		}
3544*cdf0e10cSrcweir 		case ID_DELETE:
3545*cdf0e10cSrcweir 		{
3546*cdf0e10cSrcweir 			DeleteSelectedContent();
3547*cdf0e10cSrcweir 			break;
3548*cdf0e10cSrcweir 		}
3549*cdf0e10cSrcweir 		case ID_ICON_ONLY:
3550*cdf0e10cSrcweir 		{
3551*cdf0e10cSrcweir 			break;
3552*cdf0e10cSrcweir 		}
3553*cdf0e10cSrcweir 		case ID_TEXT_ONLY:
3554*cdf0e10cSrcweir 		{
3555*cdf0e10cSrcweir 			break;
3556*cdf0e10cSrcweir 		}
3557*cdf0e10cSrcweir 		case ID_ICON_AND_TEXT:
3558*cdf0e10cSrcweir 		{
3559*cdf0e10cSrcweir 			break;
3560*cdf0e10cSrcweir 		}
3561*cdf0e10cSrcweir 		case ID_CHANGE_SYMBOL:
3562*cdf0e10cSrcweir 		{
3563*cdf0e10cSrcweir 			SvLBoxEntry* pActEntry = aContentsListBox->GetCurEntry();
3564*cdf0e10cSrcweir 			SvxConfigEntry* pEntry =
3565*cdf0e10cSrcweir 				(SvxConfigEntry*) pActEntry->GetUserData();
3566*cdf0e10cSrcweir 
3567*cdf0e10cSrcweir 			sal_uInt16 nSelectionPos = 0;
3568*cdf0e10cSrcweir 
3569*cdf0e10cSrcweir 			// find position of entry within the list
3570*cdf0e10cSrcweir 			for ( sal_uInt16 i = 0; i < aContentsListBox->GetEntryCount(); i++ )
3571*cdf0e10cSrcweir 			{
3572*cdf0e10cSrcweir 				if ( aContentsListBox->GetEntry( 0, i ) == pActEntry )
3573*cdf0e10cSrcweir 				{
3574*cdf0e10cSrcweir 					nSelectionPos = i;
3575*cdf0e10cSrcweir 					break;
3576*cdf0e10cSrcweir 				}
3577*cdf0e10cSrcweir 			}
3578*cdf0e10cSrcweir 
3579*cdf0e10cSrcweir 			SvxIconSelectorDialog* pIconDialog =
3580*cdf0e10cSrcweir 				new SvxIconSelectorDialog( 0,
3581*cdf0e10cSrcweir 					GetSaveInData()->GetImageManager(),
3582*cdf0e10cSrcweir                     GetSaveInData()->GetParentImageManager() );
3583*cdf0e10cSrcweir 
3584*cdf0e10cSrcweir 			bool ret = pIconDialog->Execute();
3585*cdf0e10cSrcweir 
3586*cdf0e10cSrcweir 			if ( ret == RET_OK )
3587*cdf0e10cSrcweir 			{
3588*cdf0e10cSrcweir 				uno::Reference< graphic::XGraphic > newgraphic =
3589*cdf0e10cSrcweir 					pIconDialog->GetSelectedIcon();
3590*cdf0e10cSrcweir 
3591*cdf0e10cSrcweir 				if ( newgraphic.is() )
3592*cdf0e10cSrcweir 				{
3593*cdf0e10cSrcweir 					uno::Sequence< uno::Reference< graphic::XGraphic > >
3594*cdf0e10cSrcweir 						aGraphicSeq( 1 );
3595*cdf0e10cSrcweir 
3596*cdf0e10cSrcweir 					uno::Sequence< OUString > aURLSeq( 1 );
3597*cdf0e10cSrcweir 					aURLSeq[ 0 ] = pEntry->GetCommand();
3598*cdf0e10cSrcweir 
3599*cdf0e10cSrcweir 					if ( !pEntry->GetBackupGraphic().is() )
3600*cdf0e10cSrcweir 					{
3601*cdf0e10cSrcweir 						uno::Reference< graphic::XGraphic > backup;
3602*cdf0e10cSrcweir 						backup = GetGraphic(
3603*cdf0e10cSrcweir 							GetSaveInData()->GetImageManager(), aURLSeq[ 0 ] );
3604*cdf0e10cSrcweir 
3605*cdf0e10cSrcweir 						if ( backup.is() )
3606*cdf0e10cSrcweir 						{
3607*cdf0e10cSrcweir 							pEntry->SetBackupGraphic( backup );
3608*cdf0e10cSrcweir 						}
3609*cdf0e10cSrcweir 					}
3610*cdf0e10cSrcweir 
3611*cdf0e10cSrcweir 					aGraphicSeq[ 0 ] = newgraphic;
3612*cdf0e10cSrcweir 					try
3613*cdf0e10cSrcweir 					{
3614*cdf0e10cSrcweir 						GetSaveInData()->GetImageManager()->replaceImages(
3615*cdf0e10cSrcweir 							GetImageType(), aURLSeq, aGraphicSeq );
3616*cdf0e10cSrcweir 
3617*cdf0e10cSrcweir 						Image aImage( newgraphic );
3618*cdf0e10cSrcweir 
3619*cdf0e10cSrcweir 						aContentsListBox->GetModel()->Remove( pActEntry );
3620*cdf0e10cSrcweir 						SvLBoxEntry* pNewLBEntry =
3621*cdf0e10cSrcweir 							InsertEntryIntoUI( pEntry, nSelectionPos );
3622*cdf0e10cSrcweir 
3623*cdf0e10cSrcweir 						aContentsListBox->SetCheckButtonState( pNewLBEntry,
3624*cdf0e10cSrcweir 							pEntry->IsVisible() ?
3625*cdf0e10cSrcweir 								SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
3626*cdf0e10cSrcweir 
3627*cdf0e10cSrcweir 						aContentsListBox->Select( pNewLBEntry );
3628*cdf0e10cSrcweir 						aContentsListBox->MakeVisible( pNewLBEntry );
3629*cdf0e10cSrcweir 
3630*cdf0e10cSrcweir 						GetSaveInData()->PersistChanges(
3631*cdf0e10cSrcweir 							GetSaveInData()->GetImageManager() );
3632*cdf0e10cSrcweir 					}
3633*cdf0e10cSrcweir             		catch ( uno::Exception& )
3634*cdf0e10cSrcweir             		{
3635*cdf0e10cSrcweir 						OSL_TRACE("Error replacing image");
3636*cdf0e10cSrcweir             		}
3637*cdf0e10cSrcweir 				}
3638*cdf0e10cSrcweir 			}
3639*cdf0e10cSrcweir 
3640*cdf0e10cSrcweir 			delete pIconDialog;
3641*cdf0e10cSrcweir 
3642*cdf0e10cSrcweir 			break;
3643*cdf0e10cSrcweir 		}
3644*cdf0e10cSrcweir 		case ID_RESET_SYMBOL:
3645*cdf0e10cSrcweir 		{
3646*cdf0e10cSrcweir 			SvLBoxEntry* pActEntry = aContentsListBox->GetCurEntry();
3647*cdf0e10cSrcweir 			SvxConfigEntry* pEntry =
3648*cdf0e10cSrcweir 				(SvxConfigEntry*) pActEntry->GetUserData();
3649*cdf0e10cSrcweir 
3650*cdf0e10cSrcweir 			sal_uInt16 nSelectionPos = 0;
3651*cdf0e10cSrcweir 
3652*cdf0e10cSrcweir 			// find position of entry within the list
3653*cdf0e10cSrcweir 			for ( sal_uInt16 i = 0; i < aContentsListBox->GetEntryCount(); i++ )
3654*cdf0e10cSrcweir 			{
3655*cdf0e10cSrcweir 				if ( aContentsListBox->GetEntry( 0, i ) == pActEntry )
3656*cdf0e10cSrcweir 				{
3657*cdf0e10cSrcweir 					nSelectionPos = i;
3658*cdf0e10cSrcweir 					break;
3659*cdf0e10cSrcweir 				}
3660*cdf0e10cSrcweir 			}
3661*cdf0e10cSrcweir 
3662*cdf0e10cSrcweir 			uno::Reference< graphic::XGraphic > backup =
3663*cdf0e10cSrcweir 				pEntry->GetBackupGraphic();
3664*cdf0e10cSrcweir 
3665*cdf0e10cSrcweir 			uno::Sequence< uno::Reference< graphic::XGraphic > >
3666*cdf0e10cSrcweir 				aGraphicSeq( 1 );
3667*cdf0e10cSrcweir 			aGraphicSeq[ 0 ] = backup;
3668*cdf0e10cSrcweir 
3669*cdf0e10cSrcweir 			uno::Sequence< OUString > aURLSeq( 1 );
3670*cdf0e10cSrcweir 			aURLSeq[ 0 ] = pEntry->GetCommand();
3671*cdf0e10cSrcweir 
3672*cdf0e10cSrcweir 			try
3673*cdf0e10cSrcweir 			{
3674*cdf0e10cSrcweir 				GetSaveInData()->GetImageManager()->replaceImages(
3675*cdf0e10cSrcweir 					GetImageType(), aURLSeq, aGraphicSeq );
3676*cdf0e10cSrcweir 
3677*cdf0e10cSrcweir 				Image aImage( backup );
3678*cdf0e10cSrcweir 				aContentsListBox->GetModel()->Remove( pActEntry );
3679*cdf0e10cSrcweir 
3680*cdf0e10cSrcweir 				SvLBoxEntry* pNewLBEntry =
3681*cdf0e10cSrcweir 					InsertEntryIntoUI( pEntry, nSelectionPos );
3682*cdf0e10cSrcweir 
3683*cdf0e10cSrcweir 				aContentsListBox->SetCheckButtonState( pNewLBEntry,
3684*cdf0e10cSrcweir 					pEntry->IsVisible() ?
3685*cdf0e10cSrcweir 						SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
3686*cdf0e10cSrcweir 
3687*cdf0e10cSrcweir 				aContentsListBox->Select( pNewLBEntry );
3688*cdf0e10cSrcweir 				aContentsListBox->MakeVisible( pNewLBEntry );
3689*cdf0e10cSrcweir 
3690*cdf0e10cSrcweir 				// reset backup in entry
3691*cdf0e10cSrcweir 				pEntry->SetBackupGraphic(
3692*cdf0e10cSrcweir 					uno::Reference< graphic::XGraphic >() );
3693*cdf0e10cSrcweir 
3694*cdf0e10cSrcweir 				GetSaveInData()->PersistChanges(
3695*cdf0e10cSrcweir 					GetSaveInData()->GetImageManager() );
3696*cdf0e10cSrcweir 			}
3697*cdf0e10cSrcweir 			catch ( uno::Exception& )
3698*cdf0e10cSrcweir 			{
3699*cdf0e10cSrcweir 				OSL_TRACE("Error resetting image");
3700*cdf0e10cSrcweir 			}
3701*cdf0e10cSrcweir 			break;
3702*cdf0e10cSrcweir 		}
3703*cdf0e10cSrcweir 	}
3704*cdf0e10cSrcweir 
3705*cdf0e10cSrcweir 	if ( bNeedsApply == sal_True )
3706*cdf0e10cSrcweir 	{
3707*cdf0e10cSrcweir 		(( ToolbarSaveInData* ) GetSaveInData())->ApplyToolbar( pToolbar );
3708*cdf0e10cSrcweir 		UpdateButtonStates();
3709*cdf0e10cSrcweir 	}
3710*cdf0e10cSrcweir 
3711*cdf0e10cSrcweir 	return 1;
3712*cdf0e10cSrcweir }
3713*cdf0e10cSrcweir 
3714*cdf0e10cSrcweir void SvxToolbarConfigPage::Init()
3715*cdf0e10cSrcweir {
3716*cdf0e10cSrcweir 	// ensure that the UI is cleared before populating it
3717*cdf0e10cSrcweir 	aTopLevelListBox.Clear();
3718*cdf0e10cSrcweir 	aContentsListBox->Clear();
3719*cdf0e10cSrcweir 
3720*cdf0e10cSrcweir 	ReloadTopLevelListBox();
3721*cdf0e10cSrcweir 
3722*cdf0e10cSrcweir 	sal_uInt16 nPos = 0;
3723*cdf0e10cSrcweir 	if ( m_aURLToSelect.getLength() != 0 )
3724*cdf0e10cSrcweir 	{
3725*cdf0e10cSrcweir 		for ( sal_uInt16 i = 0 ; i < aTopLevelListBox.GetEntryCount(); i++ )
3726*cdf0e10cSrcweir 		{
3727*cdf0e10cSrcweir 			SvxConfigEntry* pData =
3728*cdf0e10cSrcweir 				(SvxConfigEntry*) aTopLevelListBox.GetEntryData( i );
3729*cdf0e10cSrcweir 
3730*cdf0e10cSrcweir 			if ( pData->GetCommand().equals( m_aURLToSelect ) )
3731*cdf0e10cSrcweir 			{
3732*cdf0e10cSrcweir 				nPos = i;
3733*cdf0e10cSrcweir 				break;
3734*cdf0e10cSrcweir 			}
3735*cdf0e10cSrcweir 		}
3736*cdf0e10cSrcweir 
3737*cdf0e10cSrcweir 		// in future select the default toolbar: Standard
3738*cdf0e10cSrcweir 		m_aURLToSelect = OUString::createFromAscii( ITEM_TOOLBAR_URL );
3739*cdf0e10cSrcweir 		m_aURLToSelect += OUString::createFromAscii( "standardbar" );
3740*cdf0e10cSrcweir 	}
3741*cdf0e10cSrcweir 
3742*cdf0e10cSrcweir 	aTopLevelListBox.SelectEntryPos(nPos, sal_True);
3743*cdf0e10cSrcweir 	aTopLevelListBox.GetSelectHdl().Call(this);
3744*cdf0e10cSrcweir }
3745*cdf0e10cSrcweir 
3746*cdf0e10cSrcweir SaveInData* SvxToolbarConfigPage::CreateSaveInData(
3747*cdf0e10cSrcweir 	const uno::Reference< css::ui::XUIConfigurationManager >& xCfgMgr,
3748*cdf0e10cSrcweir     const uno::Reference< css::ui::XUIConfigurationManager >& xParentCfgMgr,
3749*cdf0e10cSrcweir 	const OUString& aModuleId,
3750*cdf0e10cSrcweir 	bool bDocConfig )
3751*cdf0e10cSrcweir {
3752*cdf0e10cSrcweir 	return static_cast< SaveInData* >(
3753*cdf0e10cSrcweir 		new ToolbarSaveInData( xCfgMgr, xParentCfgMgr, aModuleId, bDocConfig ));
3754*cdf0e10cSrcweir }
3755*cdf0e10cSrcweir 
3756*cdf0e10cSrcweir ToolbarSaveInData::ToolbarSaveInData(
3757*cdf0e10cSrcweir     const uno::Reference < css::ui::XUIConfigurationManager >& xCfgMgr,
3758*cdf0e10cSrcweir     const uno::Reference < css::ui::XUIConfigurationManager >& xParentCfgMgr,
3759*cdf0e10cSrcweir 	const OUString& aModuleId,
3760*cdf0e10cSrcweir     bool docConfig ) :
3761*cdf0e10cSrcweir 
3762*cdf0e10cSrcweir     SaveInData              ( xCfgMgr, xParentCfgMgr, aModuleId, docConfig ),
3763*cdf0e10cSrcweir     pRootEntry              ( NULL ),
3764*cdf0e10cSrcweir     m_aDescriptorContainer  ( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_CONTAINER ) )
3765*cdf0e10cSrcweir 
3766*cdf0e10cSrcweir {
3767*cdf0e10cSrcweir 	// Initialize the m_xPersistentWindowState variable which is used
3768*cdf0e10cSrcweir 	// to get the default properties of system toolbars such as name
3769*cdf0e10cSrcweir 	uno::Reference< container::XNameAccess > xPWSS(
3770*cdf0e10cSrcweir 		m_xServiceManager->createInstance(
3771*cdf0e10cSrcweir 			OUString( RTL_CONSTASCII_USTRINGPARAM(
3772*cdf0e10cSrcweir 				"com.sun.star.ui.WindowStateConfiguration" ) ) ),
3773*cdf0e10cSrcweir 		uno::UNO_QUERY );
3774*cdf0e10cSrcweir 
3775*cdf0e10cSrcweir 	if ( xPWSS.is() )
3776*cdf0e10cSrcweir 		xPWSS->getByName( aModuleId ) >>= m_xPersistentWindowState;
3777*cdf0e10cSrcweir }
3778*cdf0e10cSrcweir 
3779*cdf0e10cSrcweir ToolbarSaveInData::~ToolbarSaveInData()
3780*cdf0e10cSrcweir {
3781*cdf0e10cSrcweir     delete pRootEntry;
3782*cdf0e10cSrcweir }
3783*cdf0e10cSrcweir 
3784*cdf0e10cSrcweir void ToolbarSaveInData::SetSystemStyle(
3785*cdf0e10cSrcweir 	uno::Reference< frame::XFrame > xFrame,
3786*cdf0e10cSrcweir 	const OUString& rResourceURL,
3787*cdf0e10cSrcweir 	sal_Int32 nStyle )
3788*cdf0e10cSrcweir {
3789*cdf0e10cSrcweir 	// change the style using the API
3790*cdf0e10cSrcweir 	SetSystemStyle( rResourceURL, nStyle );
3791*cdf0e10cSrcweir 
3792*cdf0e10cSrcweir 	// this code is a temporary hack as the UI is not updating after
3793*cdf0e10cSrcweir 	// changing the toolbar style via the API
3794*cdf0e10cSrcweir 	uno::Reference< css::frame::XLayoutManager > xLayoutManager;
3795*cdf0e10cSrcweir 	Window *window = NULL;
3796*cdf0e10cSrcweir 
3797*cdf0e10cSrcweir 	uno::Reference< beans::XPropertySet > xPropSet( xFrame, uno::UNO_QUERY );
3798*cdf0e10cSrcweir 	if ( xPropSet.is() )
3799*cdf0e10cSrcweir 	{
3800*cdf0e10cSrcweir 		uno::Any a = xPropSet->getPropertyValue(
3801*cdf0e10cSrcweir 			OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ) ) );
3802*cdf0e10cSrcweir 		a >>= xLayoutManager;
3803*cdf0e10cSrcweir 	}
3804*cdf0e10cSrcweir 
3805*cdf0e10cSrcweir 	if ( xLayoutManager.is() )
3806*cdf0e10cSrcweir 	{
3807*cdf0e10cSrcweir 		uno::Reference< css::ui::XUIElement > xUIElement =
3808*cdf0e10cSrcweir 			xLayoutManager->getElement( rResourceURL );
3809*cdf0e10cSrcweir 
3810*cdf0e10cSrcweir         // check reference before we call getRealInterface. The layout manager
3811*cdf0e10cSrcweir         // can only provide references for elements that have been created
3812*cdf0e10cSrcweir         // before. It's possible that the current element is not available.
3813*cdf0e10cSrcweir         uno::Reference< com::sun::star::awt::XWindow > xWindow;
3814*cdf0e10cSrcweir         if ( xUIElement.is() )
3815*cdf0e10cSrcweir             xWindow = uno::Reference< com::sun::star::awt::XWindow >(
3816*cdf0e10cSrcweir                         xUIElement->getRealInterface(), uno::UNO_QUERY );
3817*cdf0e10cSrcweir 
3818*cdf0e10cSrcweir 		window = VCLUnoHelper::GetWindow( xWindow );
3819*cdf0e10cSrcweir 	}
3820*cdf0e10cSrcweir 
3821*cdf0e10cSrcweir 	if ( window != NULL && window->GetType() == WINDOW_TOOLBOX )
3822*cdf0e10cSrcweir 	{
3823*cdf0e10cSrcweir 		ToolBox* toolbox = (ToolBox*)window;
3824*cdf0e10cSrcweir 
3825*cdf0e10cSrcweir 		if ( nStyle == 0 )
3826*cdf0e10cSrcweir 		{
3827*cdf0e10cSrcweir 			toolbox->SetButtonType( BUTTON_SYMBOL );
3828*cdf0e10cSrcweir 		}
3829*cdf0e10cSrcweir 		else if ( nStyle == 1 )
3830*cdf0e10cSrcweir 		{
3831*cdf0e10cSrcweir 			toolbox->SetButtonType( BUTTON_TEXT );
3832*cdf0e10cSrcweir 		}
3833*cdf0e10cSrcweir 		if ( nStyle == 2 )
3834*cdf0e10cSrcweir 		{
3835*cdf0e10cSrcweir 			toolbox->SetButtonType( BUTTON_SYMBOLTEXT );
3836*cdf0e10cSrcweir 		}
3837*cdf0e10cSrcweir 	}
3838*cdf0e10cSrcweir }
3839*cdf0e10cSrcweir 
3840*cdf0e10cSrcweir void ToolbarSaveInData::SetSystemStyle(
3841*cdf0e10cSrcweir 	const OUString& rResourceURL,
3842*cdf0e10cSrcweir 	sal_Int32 nStyle )
3843*cdf0e10cSrcweir {
3844*cdf0e10cSrcweir 	if ( rResourceURL.indexOf( OUString::createFromAscii( "private" ) ) == 0 &&
3845*cdf0e10cSrcweir 		 m_xPersistentWindowState.is() &&
3846*cdf0e10cSrcweir 		 m_xPersistentWindowState->hasByName( rResourceURL ) )
3847*cdf0e10cSrcweir 	{
3848*cdf0e10cSrcweir 		try
3849*cdf0e10cSrcweir 		{
3850*cdf0e10cSrcweir 			uno::Sequence< beans::PropertyValue > aProps;
3851*cdf0e10cSrcweir 
3852*cdf0e10cSrcweir 			uno::Any a( m_xPersistentWindowState->getByName( rResourceURL ) );
3853*cdf0e10cSrcweir 
3854*cdf0e10cSrcweir 			if ( a >>= aProps )
3855*cdf0e10cSrcweir 			{
3856*cdf0e10cSrcweir 				for ( sal_Int32 i = 0; i < aProps.getLength(); i++ )
3857*cdf0e10cSrcweir 				{
3858*cdf0e10cSrcweir 					if ( aProps[ i ].Name.equalsAscii( ITEM_DESCRIPTOR_STYLE) )
3859*cdf0e10cSrcweir 					{
3860*cdf0e10cSrcweir 						aProps[ i ].Value = uno::makeAny( nStyle );
3861*cdf0e10cSrcweir 						break;
3862*cdf0e10cSrcweir 					}
3863*cdf0e10cSrcweir 				}
3864*cdf0e10cSrcweir 			}
3865*cdf0e10cSrcweir 
3866*cdf0e10cSrcweir 			uno::Reference< container::XNameReplace >
3867*cdf0e10cSrcweir 				xNameReplace( m_xPersistentWindowState, uno::UNO_QUERY );
3868*cdf0e10cSrcweir 
3869*cdf0e10cSrcweir 			xNameReplace->replaceByName( rResourceURL, uno::makeAny( aProps ) );
3870*cdf0e10cSrcweir 		}
3871*cdf0e10cSrcweir 		catch ( uno::Exception& )
3872*cdf0e10cSrcweir 		{
3873*cdf0e10cSrcweir 			// do nothing, a default value is returned
3874*cdf0e10cSrcweir 			OSL_TRACE("Exception setting toolbar style");
3875*cdf0e10cSrcweir 		}
3876*cdf0e10cSrcweir 	}
3877*cdf0e10cSrcweir }
3878*cdf0e10cSrcweir 
3879*cdf0e10cSrcweir sal_Int32 ToolbarSaveInData::GetSystemStyle( const OUString& rResourceURL )
3880*cdf0e10cSrcweir {
3881*cdf0e10cSrcweir 	sal_Int32 result = 0;
3882*cdf0e10cSrcweir 
3883*cdf0e10cSrcweir 	if ( rResourceURL.indexOf( OUString::createFromAscii( "private" ) ) == 0 &&
3884*cdf0e10cSrcweir 		 m_xPersistentWindowState.is() &&
3885*cdf0e10cSrcweir 		 m_xPersistentWindowState->hasByName( rResourceURL ) )
3886*cdf0e10cSrcweir 	{
3887*cdf0e10cSrcweir 		try
3888*cdf0e10cSrcweir 		{
3889*cdf0e10cSrcweir 			uno::Sequence< beans::PropertyValue > aProps;
3890*cdf0e10cSrcweir 			uno::Any a( m_xPersistentWindowState->getByName( rResourceURL ) );
3891*cdf0e10cSrcweir 
3892*cdf0e10cSrcweir 			if ( a >>= aProps )
3893*cdf0e10cSrcweir 			{
3894*cdf0e10cSrcweir 				for ( sal_Int32 i = 0; i < aProps.getLength(); i++ )
3895*cdf0e10cSrcweir 				{
3896*cdf0e10cSrcweir 					if ( aProps[ i ].Name.equalsAscii( ITEM_DESCRIPTOR_STYLE) )
3897*cdf0e10cSrcweir 					{
3898*cdf0e10cSrcweir 						aProps[i].Value >>= result;
3899*cdf0e10cSrcweir 						break;
3900*cdf0e10cSrcweir 					}
3901*cdf0e10cSrcweir 				}
3902*cdf0e10cSrcweir 			}
3903*cdf0e10cSrcweir 		}
3904*cdf0e10cSrcweir 		catch ( uno::Exception& )
3905*cdf0e10cSrcweir 		{
3906*cdf0e10cSrcweir 			// do nothing, a default value is returned
3907*cdf0e10cSrcweir 		}
3908*cdf0e10cSrcweir 	}
3909*cdf0e10cSrcweir 
3910*cdf0e10cSrcweir 	return result;
3911*cdf0e10cSrcweir }
3912*cdf0e10cSrcweir 
3913*cdf0e10cSrcweir OUString ToolbarSaveInData::GetSystemUIName( const OUString& rResourceURL )
3914*cdf0e10cSrcweir {
3915*cdf0e10cSrcweir 	OUString result;
3916*cdf0e10cSrcweir 
3917*cdf0e10cSrcweir 	if ( rResourceURL.indexOf( OUString::createFromAscii( "private" ) ) == 0 &&
3918*cdf0e10cSrcweir 		 m_xPersistentWindowState.is() &&
3919*cdf0e10cSrcweir 		 m_xPersistentWindowState->hasByName( rResourceURL ) )
3920*cdf0e10cSrcweir 	{
3921*cdf0e10cSrcweir 		try
3922*cdf0e10cSrcweir 		{
3923*cdf0e10cSrcweir 			uno::Sequence< beans::PropertyValue > aProps;
3924*cdf0e10cSrcweir 			uno::Any a( m_xPersistentWindowState->getByName( rResourceURL ) );
3925*cdf0e10cSrcweir 
3926*cdf0e10cSrcweir 			if ( a >>= aProps )
3927*cdf0e10cSrcweir 			{
3928*cdf0e10cSrcweir 				for ( sal_Int32 i = 0; i < aProps.getLength(); i++ )
3929*cdf0e10cSrcweir 				{
3930*cdf0e10cSrcweir 					if ( aProps[ i ].Name.equalsAscii( ITEM_DESCRIPTOR_UINAME) )
3931*cdf0e10cSrcweir 					{
3932*cdf0e10cSrcweir 						aProps[ i ].Value >>= result;
3933*cdf0e10cSrcweir 					}
3934*cdf0e10cSrcweir 				}
3935*cdf0e10cSrcweir 			}
3936*cdf0e10cSrcweir 		}
3937*cdf0e10cSrcweir 		catch ( uno::Exception& )
3938*cdf0e10cSrcweir 		{
3939*cdf0e10cSrcweir 			// do nothing, an empty UIName will be returned
3940*cdf0e10cSrcweir 		}
3941*cdf0e10cSrcweir 	}
3942*cdf0e10cSrcweir 
3943*cdf0e10cSrcweir 	if ( rResourceURL.indexOf( OUString::createFromAscii( ".uno" ) ) == 0 &&
3944*cdf0e10cSrcweir 		 m_xCommandToLabelMap.is() &&
3945*cdf0e10cSrcweir 		 m_xCommandToLabelMap->hasByName( rResourceURL ) )
3946*cdf0e10cSrcweir 	{
3947*cdf0e10cSrcweir 		uno::Any a;
3948*cdf0e10cSrcweir 		try
3949*cdf0e10cSrcweir 		{
3950*cdf0e10cSrcweir 			a = m_xCommandToLabelMap->getByName( rResourceURL );
3951*cdf0e10cSrcweir 
3952*cdf0e10cSrcweir 			uno::Sequence< beans::PropertyValue > aPropSeq;
3953*cdf0e10cSrcweir 			if ( a >>= aPropSeq )
3954*cdf0e10cSrcweir 			{
3955*cdf0e10cSrcweir 				for ( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
3956*cdf0e10cSrcweir 				{
3957*cdf0e10cSrcweir 					if ( aPropSeq[i].Name.equalsAscii( ITEM_DESCRIPTOR_LABEL ) )
3958*cdf0e10cSrcweir 					{
3959*cdf0e10cSrcweir 						aPropSeq[i].Value >>= result;
3960*cdf0e10cSrcweir 					}
3961*cdf0e10cSrcweir 				}
3962*cdf0e10cSrcweir 			}
3963*cdf0e10cSrcweir 		}
3964*cdf0e10cSrcweir 		catch ( uno::Exception& )
3965*cdf0e10cSrcweir 		{
3966*cdf0e10cSrcweir 			// not a system command name
3967*cdf0e10cSrcweir 		}
3968*cdf0e10cSrcweir 	}
3969*cdf0e10cSrcweir 
3970*cdf0e10cSrcweir 	return result;
3971*cdf0e10cSrcweir }
3972*cdf0e10cSrcweir 
3973*cdf0e10cSrcweir bool EntrySort( SvxConfigEntry* a, SvxConfigEntry* b )
3974*cdf0e10cSrcweir {
3975*cdf0e10cSrcweir     return a->GetName().compareTo( b->GetName() ) < 0;
3976*cdf0e10cSrcweir }
3977*cdf0e10cSrcweir 
3978*cdf0e10cSrcweir SvxEntries*	ToolbarSaveInData::GetEntries()
3979*cdf0e10cSrcweir {
3980*cdf0e10cSrcweir     typedef ::std::hash_map< ::rtl::OUString,
3981*cdf0e10cSrcweir                              bool,
3982*cdf0e10cSrcweir                              ::rtl::OUStringHash,
3983*cdf0e10cSrcweir                              ::std::equal_to< ::rtl::OUString > > ToolbarInfo;
3984*cdf0e10cSrcweir 
3985*cdf0e10cSrcweir     ToolbarInfo aToolbarInfo;
3986*cdf0e10cSrcweir 
3987*cdf0e10cSrcweir     if ( pRootEntry == NULL )
3988*cdf0e10cSrcweir 	{
3989*cdf0e10cSrcweir 
3990*cdf0e10cSrcweir         pRootEntry = new SvxConfigEntry(
3991*cdf0e10cSrcweir 			String::CreateFromAscii("MainToolbars"), String(), sal_True );
3992*cdf0e10cSrcweir 
3993*cdf0e10cSrcweir 		uno::Sequence< uno::Sequence < beans::PropertyValue > > info =
3994*cdf0e10cSrcweir 			GetConfigManager()->getUIElementsInfo(
3995*cdf0e10cSrcweir 				css::ui::UIElementType::TOOLBAR );
3996*cdf0e10cSrcweir 
3997*cdf0e10cSrcweir 		for ( sal_Int32 i = 0; i < info.getLength(); i++ )
3998*cdf0e10cSrcweir 		{
3999*cdf0e10cSrcweir 			uno::Sequence< beans::PropertyValue > props = info[ i ];
4000*cdf0e10cSrcweir 
4001*cdf0e10cSrcweir 			OUString url;
4002*cdf0e10cSrcweir 			OUString systemname;
4003*cdf0e10cSrcweir 			OUString uiname;
4004*cdf0e10cSrcweir 
4005*cdf0e10cSrcweir 			for ( sal_Int32 j = 0; j < props.getLength(); j++ )
4006*cdf0e10cSrcweir 			{
4007*cdf0e10cSrcweir 				if ( props[ j ].Name.equalsAscii( ITEM_DESCRIPTOR_RESOURCEURL) )
4008*cdf0e10cSrcweir 				{
4009*cdf0e10cSrcweir 					props[ j ].Value >>= url;
4010*cdf0e10cSrcweir 					systemname = url.copy( url.lastIndexOf( '/' ) + 1 );
4011*cdf0e10cSrcweir 				}
4012*cdf0e10cSrcweir 				else if ( props[ j ].Name.equalsAscii( ITEM_DESCRIPTOR_UINAME) )
4013*cdf0e10cSrcweir 				{
4014*cdf0e10cSrcweir 					props[ j ].Value >>= uiname;
4015*cdf0e10cSrcweir 				}
4016*cdf0e10cSrcweir 			}
4017*cdf0e10cSrcweir 
4018*cdf0e10cSrcweir 			try
4019*cdf0e10cSrcweir 			{
4020*cdf0e10cSrcweir 				uno::Reference< container::XIndexAccess > xToolbarSettings =
4021*cdf0e10cSrcweir 					GetConfigManager()->getSettings( url, sal_False );
4022*cdf0e10cSrcweir 
4023*cdf0e10cSrcweir 				if ( uiname.getLength() == 0 )
4024*cdf0e10cSrcweir 				{
4025*cdf0e10cSrcweir 					// try to get the name from m_xPersistentWindowState
4026*cdf0e10cSrcweir 					uiname = GetSystemUIName( url );
4027*cdf0e10cSrcweir 
4028*cdf0e10cSrcweir 					if ( uiname.getLength() == 0 )
4029*cdf0e10cSrcweir 					{
4030*cdf0e10cSrcweir 						uiname = systemname;
4031*cdf0e10cSrcweir 					}
4032*cdf0e10cSrcweir 				}
4033*cdf0e10cSrcweir 
4034*cdf0e10cSrcweir 				SvxConfigEntry* pEntry = new SvxConfigEntry(
4035*cdf0e10cSrcweir 					uiname, url, sal_True );
4036*cdf0e10cSrcweir 
4037*cdf0e10cSrcweir 				pEntry->SetMain( sal_True );
4038*cdf0e10cSrcweir 				pEntry->SetStyle( GetSystemStyle( url ) );
4039*cdf0e10cSrcweir 
4040*cdf0e10cSrcweir 
4041*cdf0e10cSrcweir                 // insert into hash_map to filter duplicates from the parent
4042*cdf0e10cSrcweir                 aToolbarInfo.insert( ToolbarInfo::value_type( systemname, true ));
4043*cdf0e10cSrcweir 
4044*cdf0e10cSrcweir 				OUString custom = OUString::createFromAscii(CUSTOM_TOOLBAR_STR);
4045*cdf0e10cSrcweir 				if ( systemname.indexOf( custom ) == 0 )
4046*cdf0e10cSrcweir 				{
4047*cdf0e10cSrcweir 					pEntry->SetUserDefined( sal_True );
4048*cdf0e10cSrcweir 				}
4049*cdf0e10cSrcweir 				else
4050*cdf0e10cSrcweir 				{
4051*cdf0e10cSrcweir 					pEntry->SetUserDefined( sal_False );
4052*cdf0e10cSrcweir 				}
4053*cdf0e10cSrcweir 
4054*cdf0e10cSrcweir 				pRootEntry->GetEntries()->push_back( pEntry );
4055*cdf0e10cSrcweir 
4056*cdf0e10cSrcweir 				LoadToolbar( xToolbarSettings, pEntry );
4057*cdf0e10cSrcweir 			}
4058*cdf0e10cSrcweir 			catch ( container::NoSuchElementException& )
4059*cdf0e10cSrcweir 			{
4060*cdf0e10cSrcweir 				// TODO, handle resourceURL with no settings
4061*cdf0e10cSrcweir 			}
4062*cdf0e10cSrcweir 		}
4063*cdf0e10cSrcweir 
4064*cdf0e10cSrcweir         uno::Reference< css::ui::XUIConfigurationManager > xParentCfgMgr = GetParentConfigManager();
4065*cdf0e10cSrcweir         if ( xParentCfgMgr.is() )
4066*cdf0e10cSrcweir         {
4067*cdf0e10cSrcweir             // Retrieve also the parent toolbars to make it possible
4068*cdf0e10cSrcweir             // to configure module toolbars and save them into the document
4069*cdf0e10cSrcweir             // config manager.
4070*cdf0e10cSrcweir 		    uno::Sequence< uno::Sequence < beans::PropertyValue > > info_ =
4071*cdf0e10cSrcweir 			    xParentCfgMgr->getUIElementsInfo(
4072*cdf0e10cSrcweir 				    css::ui::UIElementType::TOOLBAR );
4073*cdf0e10cSrcweir 
4074*cdf0e10cSrcweir 		    for ( sal_Int32 i = 0; i < info_.getLength(); i++ )
4075*cdf0e10cSrcweir 		    {
4076*cdf0e10cSrcweir 			    uno::Sequence< beans::PropertyValue > props = info_[ i ];
4077*cdf0e10cSrcweir 
4078*cdf0e10cSrcweir 			    OUString url;
4079*cdf0e10cSrcweir 			    OUString systemname;
4080*cdf0e10cSrcweir 			    OUString uiname;
4081*cdf0e10cSrcweir 
4082*cdf0e10cSrcweir 			    for ( sal_Int32 j = 0; j < props.getLength(); j++ )
4083*cdf0e10cSrcweir 			    {
4084*cdf0e10cSrcweir 				    if ( props[ j ].Name.equalsAscii( ITEM_DESCRIPTOR_RESOURCEURL) )
4085*cdf0e10cSrcweir 				    {
4086*cdf0e10cSrcweir 					    props[ j ].Value >>= url;
4087*cdf0e10cSrcweir 					    systemname = url.copy( url.lastIndexOf( '/' ) + 1 );
4088*cdf0e10cSrcweir 				    }
4089*cdf0e10cSrcweir 				    else if ( props[ j ].Name.equalsAscii( ITEM_DESCRIPTOR_UINAME) )
4090*cdf0e10cSrcweir 				    {
4091*cdf0e10cSrcweir 					    props[ j ].Value >>= uiname;
4092*cdf0e10cSrcweir 				    }
4093*cdf0e10cSrcweir 			    }
4094*cdf0e10cSrcweir 
4095*cdf0e10cSrcweir                 // custom toolbars of the parent are not visible in the document layer
4096*cdf0e10cSrcweir 				OUString custom = OUString::createFromAscii(CUSTOM_TOOLBAR_STR);
4097*cdf0e10cSrcweir 				if ( systemname.indexOf( custom ) == 0 )
4098*cdf0e10cSrcweir                     continue;
4099*cdf0e10cSrcweir 
4100*cdf0e10cSrcweir                 // check if toolbar is already in the document layer
4101*cdf0e10cSrcweir                 ToolbarInfo::const_iterator pIter = aToolbarInfo.find( systemname );
4102*cdf0e10cSrcweir                 if ( pIter == aToolbarInfo.end() )
4103*cdf0e10cSrcweir                 {
4104*cdf0e10cSrcweir                     aToolbarInfo.insert( ToolbarInfo::value_type( systemname, true ));
4105*cdf0e10cSrcweir 
4106*cdf0e10cSrcweir                     try
4107*cdf0e10cSrcweir 			        {
4108*cdf0e10cSrcweir 				        uno::Reference< container::XIndexAccess > xToolbarSettings =
4109*cdf0e10cSrcweir 					        xParentCfgMgr->getSettings( url, sal_False );
4110*cdf0e10cSrcweir 
4111*cdf0e10cSrcweir 				        if ( uiname.getLength() == 0 )
4112*cdf0e10cSrcweir 				        {
4113*cdf0e10cSrcweir 					        // try to get the name from m_xPersistentWindowState
4114*cdf0e10cSrcweir 					        uiname = GetSystemUIName( url );
4115*cdf0e10cSrcweir 
4116*cdf0e10cSrcweir 					        if ( uiname.getLength() == 0 )
4117*cdf0e10cSrcweir 					        {
4118*cdf0e10cSrcweir 						        uiname = systemname;
4119*cdf0e10cSrcweir 					        }
4120*cdf0e10cSrcweir 				        }
4121*cdf0e10cSrcweir 
4122*cdf0e10cSrcweir 				        SvxConfigEntry* pEntry = new SvxConfigEntry(
4123*cdf0e10cSrcweir 					        uiname, url, sal_True, sal_True );
4124*cdf0e10cSrcweir 
4125*cdf0e10cSrcweir 				        pEntry->SetMain( sal_True );
4126*cdf0e10cSrcweir 				        pEntry->SetStyle( GetSystemStyle( url ) );
4127*cdf0e10cSrcweir 
4128*cdf0e10cSrcweir 				        if ( systemname.indexOf( custom ) == 0 )
4129*cdf0e10cSrcweir 				        {
4130*cdf0e10cSrcweir 					        pEntry->SetUserDefined( sal_True );
4131*cdf0e10cSrcweir 				        }
4132*cdf0e10cSrcweir 				        else
4133*cdf0e10cSrcweir 				        {
4134*cdf0e10cSrcweir 					        pEntry->SetUserDefined( sal_False );
4135*cdf0e10cSrcweir 				        }
4136*cdf0e10cSrcweir 
4137*cdf0e10cSrcweir 				        pRootEntry->GetEntries()->push_back( pEntry );
4138*cdf0e10cSrcweir 
4139*cdf0e10cSrcweir 				        LoadToolbar( xToolbarSettings, pEntry );
4140*cdf0e10cSrcweir 			        }
4141*cdf0e10cSrcweir 			        catch ( container::NoSuchElementException& )
4142*cdf0e10cSrcweir 			        {
4143*cdf0e10cSrcweir 				        // TODO, handle resourceURL with no settings
4144*cdf0e10cSrcweir 			        }
4145*cdf0e10cSrcweir                 }
4146*cdf0e10cSrcweir             }
4147*cdf0e10cSrcweir         }
4148*cdf0e10cSrcweir 
4149*cdf0e10cSrcweir 		std::sort( GetEntries()->begin(), GetEntries()->end(), EntrySort );
4150*cdf0e10cSrcweir 	}
4151*cdf0e10cSrcweir 
4152*cdf0e10cSrcweir 	return pRootEntry->GetEntries();
4153*cdf0e10cSrcweir }
4154*cdf0e10cSrcweir 
4155*cdf0e10cSrcweir void
4156*cdf0e10cSrcweir ToolbarSaveInData::SetEntries( SvxEntries* pNewEntries )
4157*cdf0e10cSrcweir {
4158*cdf0e10cSrcweir 	// delete old menu hierarchy first
4159*cdf0e10cSrcweir 	if ( pRootEntry != NULL && pRootEntry->GetEntries() != NULL )
4160*cdf0e10cSrcweir 	{
4161*cdf0e10cSrcweir 		delete pRootEntry->GetEntries();
4162*cdf0e10cSrcweir 	}
4163*cdf0e10cSrcweir 
4164*cdf0e10cSrcweir 	// now set new menu hierarchy
4165*cdf0e10cSrcweir 	pRootEntry->SetEntries( pNewEntries );
4166*cdf0e10cSrcweir }
4167*cdf0e10cSrcweir 
4168*cdf0e10cSrcweir bool
4169*cdf0e10cSrcweir ToolbarSaveInData::HasURL( const OUString& rURL )
4170*cdf0e10cSrcweir {
4171*cdf0e10cSrcweir 	SvxEntries::const_iterator iter = GetEntries()->begin();
4172*cdf0e10cSrcweir 	SvxEntries::const_iterator end = GetEntries()->end();
4173*cdf0e10cSrcweir 
4174*cdf0e10cSrcweir 	while ( iter != end )
4175*cdf0e10cSrcweir 	{
4176*cdf0e10cSrcweir 		SvxConfigEntry* pEntry = *iter;
4177*cdf0e10cSrcweir 
4178*cdf0e10cSrcweir 		if ( pEntry->GetCommand().equals( rURL ) )
4179*cdf0e10cSrcweir 		{
4180*cdf0e10cSrcweir 			if ( pEntry->IsParentData() )
4181*cdf0e10cSrcweir                 return sal_False;
4182*cdf0e10cSrcweir             else
4183*cdf0e10cSrcweir                 return sal_True;
4184*cdf0e10cSrcweir 		}
4185*cdf0e10cSrcweir 
4186*cdf0e10cSrcweir 		iter++;
4187*cdf0e10cSrcweir 	}
4188*cdf0e10cSrcweir 	return sal_False;
4189*cdf0e10cSrcweir }
4190*cdf0e10cSrcweir 
4191*cdf0e10cSrcweir bool ToolbarSaveInData::HasSettings()
4192*cdf0e10cSrcweir {
4193*cdf0e10cSrcweir 	// return true if there is at least one toolbar entry
4194*cdf0e10cSrcweir 	if ( GetEntries()->size() > 0 )
4195*cdf0e10cSrcweir 	{
4196*cdf0e10cSrcweir 		return sal_True;
4197*cdf0e10cSrcweir 	}
4198*cdf0e10cSrcweir 	return sal_False;
4199*cdf0e10cSrcweir }
4200*cdf0e10cSrcweir 
4201*cdf0e10cSrcweir void ToolbarSaveInData::Reset()
4202*cdf0e10cSrcweir {
4203*cdf0e10cSrcweir 	SvxEntries::const_iterator toolbars = GetEntries()->begin();
4204*cdf0e10cSrcweir 	SvxEntries::const_iterator end = GetEntries()->end();
4205*cdf0e10cSrcweir 
4206*cdf0e10cSrcweir 	// reset each toolbar by calling removeSettings for it's toolbar URL
4207*cdf0e10cSrcweir 	for ( ; toolbars != end; toolbars++ )
4208*cdf0e10cSrcweir 	{
4209*cdf0e10cSrcweir 		SvxConfigEntry* pToolbar = *toolbars;
4210*cdf0e10cSrcweir 
4211*cdf0e10cSrcweir 		try
4212*cdf0e10cSrcweir 		{
4213*cdf0e10cSrcweir 			OUString url = pToolbar->GetCommand();
4214*cdf0e10cSrcweir 			GetConfigManager()->removeSettings( url );
4215*cdf0e10cSrcweir 		}
4216*cdf0e10cSrcweir 		catch ( uno::Exception& )
4217*cdf0e10cSrcweir 		{
4218*cdf0e10cSrcweir 			// error occured removing the settings
4219*cdf0e10cSrcweir 			// TODO - add error dialog in future?
4220*cdf0e10cSrcweir 		}
4221*cdf0e10cSrcweir 	}
4222*cdf0e10cSrcweir 
4223*cdf0e10cSrcweir 	// persist changes to toolbar storage
4224*cdf0e10cSrcweir 	PersistChanges( GetConfigManager() );
4225*cdf0e10cSrcweir 
4226*cdf0e10cSrcweir 	// now delete the root SvxConfigEntry the next call to GetEntries()
4227*cdf0e10cSrcweir 	// causes it to be reinitialised
4228*cdf0e10cSrcweir 	delete pRootEntry;
4229*cdf0e10cSrcweir 	pRootEntry = NULL;
4230*cdf0e10cSrcweir 
4231*cdf0e10cSrcweir 	// reset all icons to default
4232*cdf0e10cSrcweir 	try
4233*cdf0e10cSrcweir 	{
4234*cdf0e10cSrcweir 		GetImageManager()->reset();
4235*cdf0e10cSrcweir 		PersistChanges( GetImageManager() );
4236*cdf0e10cSrcweir 	}
4237*cdf0e10cSrcweir 	catch ( uno::Exception& )
4238*cdf0e10cSrcweir 	{
4239*cdf0e10cSrcweir 		OSL_TRACE("Error resetting all icons when resetting toolbars");
4240*cdf0e10cSrcweir 	}
4241*cdf0e10cSrcweir }
4242*cdf0e10cSrcweir 
4243*cdf0e10cSrcweir bool ToolbarSaveInData::Apply()
4244*cdf0e10cSrcweir {
4245*cdf0e10cSrcweir 	// toolbar changes are instantly applied
4246*cdf0e10cSrcweir 	return sal_False;
4247*cdf0e10cSrcweir }
4248*cdf0e10cSrcweir 
4249*cdf0e10cSrcweir void ToolbarSaveInData::ApplyToolbar(
4250*cdf0e10cSrcweir 	uno::Reference< container::XIndexContainer >& rToolbarBar,
4251*cdf0e10cSrcweir 	uno::Reference< lang::XSingleComponentFactory >& rFactory,
4252*cdf0e10cSrcweir 	SvxConfigEntry* pToolbarData )
4253*cdf0e10cSrcweir {
4254*cdf0e10cSrcweir 	SvxEntries::const_iterator iter = pToolbarData->GetEntries()->begin();
4255*cdf0e10cSrcweir 	SvxEntries::const_iterator end = pToolbarData->GetEntries()->end();
4256*cdf0e10cSrcweir 
4257*cdf0e10cSrcweir 	for ( ; iter != end; iter++ )
4258*cdf0e10cSrcweir 	{
4259*cdf0e10cSrcweir 		SvxConfigEntry* pEntry = *iter;
4260*cdf0e10cSrcweir 
4261*cdf0e10cSrcweir 		if ( pEntry->IsPopup() )
4262*cdf0e10cSrcweir 		{
4263*cdf0e10cSrcweir 			uno::Sequence< beans::PropertyValue > aPropValueSeq =
4264*cdf0e10cSrcweir 				ConvertToolbarEntry( m_xCommandToLabelMap, pEntry );
4265*cdf0e10cSrcweir 
4266*cdf0e10cSrcweir 			uno::Reference< container::XIndexContainer > xSubMenuBar(
4267*cdf0e10cSrcweir 				rFactory->createInstanceWithContext( m_xComponentContext ),
4268*cdf0e10cSrcweir 					uno::UNO_QUERY );
4269*cdf0e10cSrcweir 
4270*cdf0e10cSrcweir 			sal_Int32 nIndex = aPropValueSeq.getLength();
4271*cdf0e10cSrcweir 			aPropValueSeq.realloc( nIndex + 1 );
4272*cdf0e10cSrcweir 			aPropValueSeq[nIndex].Name = m_aDescriptorContainer;
4273*cdf0e10cSrcweir 			aPropValueSeq[nIndex].Value <<= xSubMenuBar;
4274*cdf0e10cSrcweir 			rToolbarBar->insertByIndex(
4275*cdf0e10cSrcweir 				rToolbarBar->getCount(), uno::makeAny( aPropValueSeq ));
4276*cdf0e10cSrcweir 
4277*cdf0e10cSrcweir 			ApplyToolbar( xSubMenuBar, rFactory, pEntry );
4278*cdf0e10cSrcweir 		}
4279*cdf0e10cSrcweir 		else if ( pEntry->IsSeparator() )
4280*cdf0e10cSrcweir 		{
4281*cdf0e10cSrcweir 			rToolbarBar->insertByIndex(
4282*cdf0e10cSrcweir 				rToolbarBar->getCount(), uno::makeAny( m_aSeparatorSeq ));
4283*cdf0e10cSrcweir 		}
4284*cdf0e10cSrcweir 		else
4285*cdf0e10cSrcweir 		{
4286*cdf0e10cSrcweir 			uno::Sequence< beans::PropertyValue > aPropValueSeq =
4287*cdf0e10cSrcweir 				ConvertToolbarEntry( m_xCommandToLabelMap, pEntry );
4288*cdf0e10cSrcweir 
4289*cdf0e10cSrcweir 			rToolbarBar->insertByIndex(
4290*cdf0e10cSrcweir 				rToolbarBar->getCount(), uno::makeAny( aPropValueSeq ));
4291*cdf0e10cSrcweir 		}
4292*cdf0e10cSrcweir 	}
4293*cdf0e10cSrcweir }
4294*cdf0e10cSrcweir 
4295*cdf0e10cSrcweir void ToolbarSaveInData::ApplyToolbar( SvxConfigEntry* pToolbar )
4296*cdf0e10cSrcweir {
4297*cdf0e10cSrcweir 	// Apply new toolbar structure to our settings container
4298*cdf0e10cSrcweir 	uno::Reference< container::XIndexAccess > xSettings(
4299*cdf0e10cSrcweir 		GetConfigManager()->createSettings(), uno::UNO_QUERY );
4300*cdf0e10cSrcweir 
4301*cdf0e10cSrcweir 	uno::Reference< container::XIndexContainer > xIndexContainer (
4302*cdf0e10cSrcweir 		xSettings, uno::UNO_QUERY );
4303*cdf0e10cSrcweir 
4304*cdf0e10cSrcweir 	uno::Reference< lang::XSingleComponentFactory > xFactory (
4305*cdf0e10cSrcweir 		xSettings, uno::UNO_QUERY );
4306*cdf0e10cSrcweir 
4307*cdf0e10cSrcweir 	ApplyToolbar( xIndexContainer, xFactory, pToolbar );
4308*cdf0e10cSrcweir 
4309*cdf0e10cSrcweir 	uno::Reference< beans::XPropertySet > xProps(
4310*cdf0e10cSrcweir 		xSettings, uno::UNO_QUERY );
4311*cdf0e10cSrcweir 
4312*cdf0e10cSrcweir 	if ( pToolbar->IsUserDefined() )
4313*cdf0e10cSrcweir 	{
4314*cdf0e10cSrcweir 		xProps->setPropertyValue(
4315*cdf0e10cSrcweir 			OUString::createFromAscii( ITEM_DESCRIPTOR_UINAME ),
4316*cdf0e10cSrcweir 			uno::makeAny( OUString( pToolbar->GetName() ) ) );
4317*cdf0e10cSrcweir 	}
4318*cdf0e10cSrcweir 
4319*cdf0e10cSrcweir     try
4320*cdf0e10cSrcweir 	{
4321*cdf0e10cSrcweir 		if ( GetConfigManager()->hasSettings( pToolbar->GetCommand() ) )
4322*cdf0e10cSrcweir 		{
4323*cdf0e10cSrcweir 			GetConfigManager()->replaceSettings(
4324*cdf0e10cSrcweir 				pToolbar->GetCommand(), xSettings );
4325*cdf0e10cSrcweir 		}
4326*cdf0e10cSrcweir 		else
4327*cdf0e10cSrcweir 		{
4328*cdf0e10cSrcweir 			GetConfigManager()->insertSettings(
4329*cdf0e10cSrcweir 				pToolbar->GetCommand(), xSettings );
4330*cdf0e10cSrcweir             if ( pToolbar->IsParentData() )
4331*cdf0e10cSrcweir                 pToolbar->SetParentData( false );
4332*cdf0e10cSrcweir 		}
4333*cdf0e10cSrcweir 	}
4334*cdf0e10cSrcweir 	catch ( container::NoSuchElementException& )
4335*cdf0e10cSrcweir 	{
4336*cdf0e10cSrcweir 		OSL_TRACE("caught container::NoSuchElementException saving settings");
4337*cdf0e10cSrcweir 	}
4338*cdf0e10cSrcweir 	catch ( com::sun::star::io::IOException& )
4339*cdf0e10cSrcweir 	{
4340*cdf0e10cSrcweir 		OSL_TRACE("caught IOException saving settings");
4341*cdf0e10cSrcweir 	}
4342*cdf0e10cSrcweir 	catch ( com::sun::star::uno::Exception& )
4343*cdf0e10cSrcweir 	{
4344*cdf0e10cSrcweir 		OSL_TRACE("caught some other exception saving settings");
4345*cdf0e10cSrcweir 	}
4346*cdf0e10cSrcweir 
4347*cdf0e10cSrcweir 	PersistChanges( GetConfigManager() );
4348*cdf0e10cSrcweir }
4349*cdf0e10cSrcweir 
4350*cdf0e10cSrcweir void ToolbarSaveInData::CreateToolbar( SvxConfigEntry* pToolbar )
4351*cdf0e10cSrcweir {
4352*cdf0e10cSrcweir 	// show the new toolbar in the UI also
4353*cdf0e10cSrcweir 	uno::Reference< container::XIndexAccess >
4354*cdf0e10cSrcweir 		xSettings( GetConfigManager()->createSettings(), uno::UNO_QUERY );
4355*cdf0e10cSrcweir 
4356*cdf0e10cSrcweir 	uno::Reference< container::XIndexContainer >
4357*cdf0e10cSrcweir 		xIndexContainer ( xSettings, uno::UNO_QUERY );
4358*cdf0e10cSrcweir 
4359*cdf0e10cSrcweir 	uno::Reference< beans::XPropertySet >
4360*cdf0e10cSrcweir 		xPropertySet( xSettings, uno::UNO_QUERY );
4361*cdf0e10cSrcweir 
4362*cdf0e10cSrcweir 	xPropertySet->setPropertyValue(
4363*cdf0e10cSrcweir 		OUString::createFromAscii( ITEM_DESCRIPTOR_UINAME ),
4364*cdf0e10cSrcweir 			uno::makeAny( pToolbar->GetName() ) );
4365*cdf0e10cSrcweir 
4366*cdf0e10cSrcweir 	try
4367*cdf0e10cSrcweir 	{
4368*cdf0e10cSrcweir 		GetConfigManager()->insertSettings( pToolbar->GetCommand(), xSettings );
4369*cdf0e10cSrcweir 	}
4370*cdf0e10cSrcweir 	catch ( container::ElementExistException& )
4371*cdf0e10cSrcweir 	{
4372*cdf0e10cSrcweir 		OSL_TRACE("caught ElementExistsException saving settings");
4373*cdf0e10cSrcweir 	}
4374*cdf0e10cSrcweir 	catch ( com::sun::star::lang::IllegalArgumentException& )
4375*cdf0e10cSrcweir 	{
4376*cdf0e10cSrcweir 		OSL_TRACE("caught IOException saving settings");
4377*cdf0e10cSrcweir 	}
4378*cdf0e10cSrcweir 	catch ( com::sun::star::lang::IllegalAccessException& )
4379*cdf0e10cSrcweir 	{
4380*cdf0e10cSrcweir 		OSL_TRACE("caught IOException saving settings");
4381*cdf0e10cSrcweir 	}
4382*cdf0e10cSrcweir 	catch ( com::sun::star::uno::Exception& )
4383*cdf0e10cSrcweir 	{
4384*cdf0e10cSrcweir 		OSL_TRACE("caught some other exception saving settings");
4385*cdf0e10cSrcweir 	}
4386*cdf0e10cSrcweir 
4387*cdf0e10cSrcweir 	GetEntries()->push_back( pToolbar );
4388*cdf0e10cSrcweir 
4389*cdf0e10cSrcweir 	PersistChanges( GetConfigManager() );
4390*cdf0e10cSrcweir }
4391*cdf0e10cSrcweir 
4392*cdf0e10cSrcweir void ToolbarSaveInData::RemoveToolbar( SvxConfigEntry* pToolbar )
4393*cdf0e10cSrcweir {
4394*cdf0e10cSrcweir 	try
4395*cdf0e10cSrcweir 	{
4396*cdf0e10cSrcweir         OUString url = pToolbar->GetCommand();
4397*cdf0e10cSrcweir 		GetConfigManager()->removeSettings( url );
4398*cdf0e10cSrcweir 		RemoveEntry( GetEntries(), pToolbar );
4399*cdf0e10cSrcweir 		delete pToolbar;
4400*cdf0e10cSrcweir 
4401*cdf0e10cSrcweir 		PersistChanges( GetConfigManager() );
4402*cdf0e10cSrcweir 
4403*cdf0e10cSrcweir         // remove the persistent window state data
4404*cdf0e10cSrcweir         css::uno::Reference< css::container::XNameContainer > xNameContainer(
4405*cdf0e10cSrcweir             m_xPersistentWindowState, css::uno::UNO_QUERY_THROW );
4406*cdf0e10cSrcweir 
4407*cdf0e10cSrcweir         xNameContainer->removeByName( url );
4408*cdf0e10cSrcweir 	}
4409*cdf0e10cSrcweir 	catch ( uno::Exception& )
4410*cdf0e10cSrcweir 	{
4411*cdf0e10cSrcweir 		// error occured removing the settings
4412*cdf0e10cSrcweir 	}
4413*cdf0e10cSrcweir }
4414*cdf0e10cSrcweir 
4415*cdf0e10cSrcweir void ToolbarSaveInData::RestoreToolbar( SvxConfigEntry* pToolbar )
4416*cdf0e10cSrcweir {
4417*cdf0e10cSrcweir 	OUString url = pToolbar->GetCommand();
4418*cdf0e10cSrcweir 
4419*cdf0e10cSrcweir 	// Restore of toolbar is done by removing it from
4420*cdf0e10cSrcweir 	// it's configuration manager and then getting it again
4421*cdf0e10cSrcweir     bool bParentToolbar = pToolbar->IsParentData();
4422*cdf0e10cSrcweir 
4423*cdf0e10cSrcweir     // Cannot restore parent toolbar
4424*cdf0e10cSrcweir     if ( bParentToolbar )
4425*cdf0e10cSrcweir         return;
4426*cdf0e10cSrcweir 
4427*cdf0e10cSrcweir 	try
4428*cdf0e10cSrcweir 	{
4429*cdf0e10cSrcweir         GetConfigManager()->removeSettings( url );
4430*cdf0e10cSrcweir 		pToolbar->GetEntries()->clear();
4431*cdf0e10cSrcweir 		PersistChanges( GetConfigManager() );
4432*cdf0e10cSrcweir 	}
4433*cdf0e10cSrcweir 	catch ( uno::Exception& )
4434*cdf0e10cSrcweir 	{
4435*cdf0e10cSrcweir 		// if an error occurs removing the settings then just return
4436*cdf0e10cSrcweir 		return;
4437*cdf0e10cSrcweir 	}
4438*cdf0e10cSrcweir 
4439*cdf0e10cSrcweir 	// Now reload the toolbar settings
4440*cdf0e10cSrcweir 	try
4441*cdf0e10cSrcweir 	{
4442*cdf0e10cSrcweir         uno::Reference< container::XIndexAccess > xToolbarSettings;
4443*cdf0e10cSrcweir         if ( IsDocConfig() )
4444*cdf0e10cSrcweir         {
4445*cdf0e10cSrcweir             xToolbarSettings = GetParentConfigManager()->getSettings( url, sal_False );
4446*cdf0e10cSrcweir             pToolbar->SetParentData( true );
4447*cdf0e10cSrcweir         }
4448*cdf0e10cSrcweir         else
4449*cdf0e10cSrcweir             xToolbarSettings = GetConfigManager()->getSettings( url, sal_False );
4450*cdf0e10cSrcweir 
4451*cdf0e10cSrcweir 		LoadToolbar( xToolbarSettings, pToolbar );
4452*cdf0e10cSrcweir 
4453*cdf0e10cSrcweir 		// After reloading, ensure that the icon is reset of each entry
4454*cdf0e10cSrcweir 		// in the toolbar
4455*cdf0e10cSrcweir 		SvxEntries::const_iterator iter = pToolbar->GetEntries()->begin();
4456*cdf0e10cSrcweir 		uno::Sequence< OUString > aURLSeq( 1 );
4457*cdf0e10cSrcweir 		for ( ; iter != pToolbar->GetEntries()->end(); iter++ )
4458*cdf0e10cSrcweir 		{
4459*cdf0e10cSrcweir 			SvxConfigEntry* pEntry = *iter;
4460*cdf0e10cSrcweir 			aURLSeq[ 0 ] = pEntry->GetCommand();
4461*cdf0e10cSrcweir 
4462*cdf0e10cSrcweir 			try
4463*cdf0e10cSrcweir 			{
4464*cdf0e10cSrcweir 				GetImageManager()->removeImages( GetImageType(), aURLSeq );
4465*cdf0e10cSrcweir 			}
4466*cdf0e10cSrcweir            	catch ( uno::Exception& )
4467*cdf0e10cSrcweir            	{
4468*cdf0e10cSrcweir 				OSL_TRACE("Error restoring icon when resetting toolbar");
4469*cdf0e10cSrcweir            	}
4470*cdf0e10cSrcweir 		}
4471*cdf0e10cSrcweir 		PersistChanges( GetImageManager() );
4472*cdf0e10cSrcweir 	}
4473*cdf0e10cSrcweir 	catch ( container::NoSuchElementException& )
4474*cdf0e10cSrcweir 	{
4475*cdf0e10cSrcweir 		// cannot find the resource URL after removing it
4476*cdf0e10cSrcweir 		// so no entry will appear in the toolbar list
4477*cdf0e10cSrcweir 	}
4478*cdf0e10cSrcweir }
4479*cdf0e10cSrcweir 
4480*cdf0e10cSrcweir bool ToolbarSaveInData::LoadToolbar(
4481*cdf0e10cSrcweir 	const uno::Reference< container::XIndexAccess >& xToolbarSettings,
4482*cdf0e10cSrcweir 	SvxConfigEntry* pParentData )
4483*cdf0e10cSrcweir {
4484*cdf0e10cSrcweir 	SvxEntries*			pEntries			= pParentData->GetEntries();
4485*cdf0e10cSrcweir 
4486*cdf0e10cSrcweir     for ( sal_Int32 nIndex = 0; nIndex < xToolbarSettings->getCount(); nIndex++ )
4487*cdf0e10cSrcweir     {
4488*cdf0e10cSrcweir         uno::Reference< container::XIndexAccess >	xSubMenu;
4489*cdf0e10cSrcweir         OUString				aCommandURL;
4490*cdf0e10cSrcweir         OUString				aLabel;
4491*cdf0e10cSrcweir 		bool					bIsUserDefined = sal_True;
4492*cdf0e10cSrcweir 		sal_Bool				bIsVisible;
4493*cdf0e10cSrcweir 		sal_Int32				nStyle;
4494*cdf0e10cSrcweir 
4495*cdf0e10cSrcweir         sal_uInt16 nType( css::ui::ItemType::DEFAULT );
4496*cdf0e10cSrcweir 
4497*cdf0e10cSrcweir         bool bItem = GetToolbarItemData( xToolbarSettings, nIndex, aCommandURL,
4498*cdf0e10cSrcweir 			aLabel, nType, bIsVisible, nStyle, xSubMenu );
4499*cdf0e10cSrcweir 
4500*cdf0e10cSrcweir         if ( bItem )
4501*cdf0e10cSrcweir         {
4502*cdf0e10cSrcweir             if ( nType == css::ui::ItemType::DEFAULT )
4503*cdf0e10cSrcweir             {
4504*cdf0e10cSrcweir 				uno::Any a;
4505*cdf0e10cSrcweir 				try
4506*cdf0e10cSrcweir 				{
4507*cdf0e10cSrcweir 					a = m_xCommandToLabelMap->getByName( aCommandURL );
4508*cdf0e10cSrcweir 					bIsUserDefined = sal_False;
4509*cdf0e10cSrcweir 				}
4510*cdf0e10cSrcweir 				catch ( container::NoSuchElementException& )
4511*cdf0e10cSrcweir 				{
4512*cdf0e10cSrcweir 					bIsUserDefined = sal_True;
4513*cdf0e10cSrcweir 				}
4514*cdf0e10cSrcweir 
4515*cdf0e10cSrcweir 				// If custom label not set retrieve it from the command
4516*cdf0e10cSrcweir 				// to info service
4517*cdf0e10cSrcweir 				if ( aLabel.equals( OUString() ) )
4518*cdf0e10cSrcweir 				{
4519*cdf0e10cSrcweir 					uno::Sequence< beans::PropertyValue > aPropSeq;
4520*cdf0e10cSrcweir 					if ( a >>= aPropSeq )
4521*cdf0e10cSrcweir 					{
4522*cdf0e10cSrcweir 						for ( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
4523*cdf0e10cSrcweir 						{
4524*cdf0e10cSrcweir 							if ( aPropSeq[i].Name.equalsAscii( ITEM_DESCRIPTOR_LABEL ) )
4525*cdf0e10cSrcweir 							{
4526*cdf0e10cSrcweir 								aPropSeq[i].Value >>= aLabel;
4527*cdf0e10cSrcweir 								break;
4528*cdf0e10cSrcweir 							}
4529*cdf0e10cSrcweir 						}
4530*cdf0e10cSrcweir 					}
4531*cdf0e10cSrcweir 				}
4532*cdf0e10cSrcweir 
4533*cdf0e10cSrcweir                 if ( xSubMenu.is() )
4534*cdf0e10cSrcweir                 {
4535*cdf0e10cSrcweir 					SvxConfigEntry* pEntry = new SvxConfigEntry(
4536*cdf0e10cSrcweir 						aLabel, aCommandURL, sal_True );
4537*cdf0e10cSrcweir 
4538*cdf0e10cSrcweir 					pEntry->SetUserDefined( bIsUserDefined );
4539*cdf0e10cSrcweir                     pEntry->SetVisible( bIsVisible );
4540*cdf0e10cSrcweir 
4541*cdf0e10cSrcweir 					pEntries->push_back( pEntry );
4542*cdf0e10cSrcweir 
4543*cdf0e10cSrcweir 					LoadToolbar( xSubMenu, pEntry );
4544*cdf0e10cSrcweir                 }
4545*cdf0e10cSrcweir                 else
4546*cdf0e10cSrcweir                 {
4547*cdf0e10cSrcweir                     SvxConfigEntry* pEntry = new SvxConfigEntry(
4548*cdf0e10cSrcweir 						aLabel, aCommandURL, sal_False );
4549*cdf0e10cSrcweir 					pEntry->SetUserDefined( bIsUserDefined );
4550*cdf0e10cSrcweir                     pEntry->SetVisible( bIsVisible );
4551*cdf0e10cSrcweir 					pEntry->SetStyle( nStyle );
4552*cdf0e10cSrcweir 					pEntries->push_back( pEntry );
4553*cdf0e10cSrcweir                 }
4554*cdf0e10cSrcweir             }
4555*cdf0e10cSrcweir             else
4556*cdf0e10cSrcweir             {
4557*cdf0e10cSrcweir 				SvxConfigEntry* pEntry = new SvxConfigEntry;
4558*cdf0e10cSrcweir 				pEntry->SetUserDefined( bIsUserDefined );
4559*cdf0e10cSrcweir 				pEntries->push_back( pEntry );
4560*cdf0e10cSrcweir             }
4561*cdf0e10cSrcweir         }
4562*cdf0e10cSrcweir     }
4563*cdf0e10cSrcweir 
4564*cdf0e10cSrcweir 	return true;
4565*cdf0e10cSrcweir }
4566*cdf0e10cSrcweir 
4567*cdf0e10cSrcweir IMPL_LINK( SvxToolbarConfigPage, SelectToolbarEntry, Control *, pBox )
4568*cdf0e10cSrcweir {
4569*cdf0e10cSrcweir 	(void)pBox;
4570*cdf0e10cSrcweir 	UpdateButtonStates();
4571*cdf0e10cSrcweir 	return 1;
4572*cdf0e10cSrcweir }
4573*cdf0e10cSrcweir 
4574*cdf0e10cSrcweir void SvxToolbarConfigPage::UpdateButtonStates()
4575*cdf0e10cSrcweir {
4576*cdf0e10cSrcweir 	PopupMenu* pPopup = aModifyCommandButton.GetPopupMenu();
4577*cdf0e10cSrcweir     pPopup->EnableItem( ID_RENAME, sal_False );
4578*cdf0e10cSrcweir 	pPopup->EnableItem( ID_DELETE, sal_False );
4579*cdf0e10cSrcweir 	pPopup->EnableItem( ID_BEGIN_GROUP, sal_False );
4580*cdf0e10cSrcweir 	pPopup->EnableItem( ID_DEFAULT_COMMAND, sal_False );
4581*cdf0e10cSrcweir 	pPopup->EnableItem( ID_ICON_ONLY, sal_False );
4582*cdf0e10cSrcweir 	pPopup->EnableItem( ID_ICON_AND_TEXT, sal_False );
4583*cdf0e10cSrcweir 	pPopup->EnableItem( ID_TEXT_ONLY, sal_False );
4584*cdf0e10cSrcweir 	pPopup->EnableItem( ID_CHANGE_SYMBOL, sal_False );
4585*cdf0e10cSrcweir 	pPopup->EnableItem( ID_RESET_SYMBOL, sal_False );
4586*cdf0e10cSrcweir 
4587*cdf0e10cSrcweir     aDescriptionField.Clear();
4588*cdf0e10cSrcweir 
4589*cdf0e10cSrcweir     SvLBoxEntry* selection = aContentsListBox->GetCurEntry();
4590*cdf0e10cSrcweir 	if ( aContentsListBox->GetEntryCount() == 0 || selection == NULL )
4591*cdf0e10cSrcweir 	{
4592*cdf0e10cSrcweir 		return;
4593*cdf0e10cSrcweir 	}
4594*cdf0e10cSrcweir 
4595*cdf0e10cSrcweir     SvxConfigEntry* pEntryData = (SvxConfigEntry*) selection->GetUserData();
4596*cdf0e10cSrcweir 	if ( pEntryData->IsSeparator() )
4597*cdf0e10cSrcweir 		pPopup->EnableItem( ID_DELETE, sal_True );
4598*cdf0e10cSrcweir 	else
4599*cdf0e10cSrcweir 	{
4600*cdf0e10cSrcweir 		pPopup->EnableItem( ID_BEGIN_GROUP, sal_True );
4601*cdf0e10cSrcweir 		pPopup->EnableItem( ID_DELETE, sal_True );
4602*cdf0e10cSrcweir 		pPopup->EnableItem( ID_RENAME, sal_True );
4603*cdf0e10cSrcweir 		pPopup->EnableItem( ID_ICON_ONLY, sal_True );
4604*cdf0e10cSrcweir 		pPopup->EnableItem( ID_ICON_AND_TEXT, sal_True );
4605*cdf0e10cSrcweir 		pPopup->EnableItem( ID_TEXT_ONLY, sal_True );
4606*cdf0e10cSrcweir 		pPopup->EnableItem( ID_CHANGE_SYMBOL, sal_True );
4607*cdf0e10cSrcweir 
4608*cdf0e10cSrcweir 		if ( !pEntryData->IsUserDefined() )
4609*cdf0e10cSrcweir 			pPopup->EnableItem( ID_DEFAULT_COMMAND, sal_True );
4610*cdf0e10cSrcweir 
4611*cdf0e10cSrcweir 		if ( pEntryData->IsIconModified() )
4612*cdf0e10cSrcweir 			pPopup->EnableItem( ID_RESET_SYMBOL, sal_True );
4613*cdf0e10cSrcweir 
4614*cdf0e10cSrcweir         aDescriptionField.SetNewText( pEntryData->GetHelpText() );
4615*cdf0e10cSrcweir 	}
4616*cdf0e10cSrcweir }
4617*cdf0e10cSrcweir 
4618*cdf0e10cSrcweir short SvxToolbarConfigPage::QueryReset()
4619*cdf0e10cSrcweir {
4620*cdf0e10cSrcweir 	String msg =
4621*cdf0e10cSrcweir 		String( CUI_RES( RID_SVXSTR_CONFIRM_TOOLBAR_RESET ) );
4622*cdf0e10cSrcweir 
4623*cdf0e10cSrcweir 	String saveInName = aSaveInListBox.GetEntry(
4624*cdf0e10cSrcweir 		aSaveInListBox.GetSelectEntryPos() );
4625*cdf0e10cSrcweir 
4626*cdf0e10cSrcweir 	OUString label = replaceSaveInName( msg, saveInName );
4627*cdf0e10cSrcweir 
4628*cdf0e10cSrcweir 	QueryBox qbox( this, WB_YES_NO, label );
4629*cdf0e10cSrcweir 
4630*cdf0e10cSrcweir 	return qbox.Execute();
4631*cdf0e10cSrcweir }
4632*cdf0e10cSrcweir 
4633*cdf0e10cSrcweir IMPL_LINK( SvxToolbarConfigPage, SelectToolbar, ListBox *, pBox )
4634*cdf0e10cSrcweir {
4635*cdf0e10cSrcweir 	(void)pBox;
4636*cdf0e10cSrcweir 
4637*cdf0e10cSrcweir 	aContentsListBox->Clear();
4638*cdf0e10cSrcweir 
4639*cdf0e10cSrcweir 	SvxConfigEntry* pToolbar = GetTopLevelSelection();
4640*cdf0e10cSrcweir 	if ( pToolbar == NULL )
4641*cdf0e10cSrcweir 	{
4642*cdf0e10cSrcweir 		aModifyTopLevelButton.Enable( sal_False );
4643*cdf0e10cSrcweir 		aModifyCommandButton.Enable( sal_False );
4644*cdf0e10cSrcweir 		aAddCommandsButton.Enable( sal_False );
4645*cdf0e10cSrcweir 
4646*cdf0e10cSrcweir 		return 0;
4647*cdf0e10cSrcweir 	}
4648*cdf0e10cSrcweir 
4649*cdf0e10cSrcweir 	aModifyTopLevelButton.Enable( sal_True );
4650*cdf0e10cSrcweir 	aModifyCommandButton.Enable( sal_True );
4651*cdf0e10cSrcweir 	aAddCommandsButton.Enable( sal_True );
4652*cdf0e10cSrcweir 
4653*cdf0e10cSrcweir 	PopupMenu* pPopup = aModifyTopLevelButton.GetPopupMenu();
4654*cdf0e10cSrcweir 
4655*cdf0e10cSrcweir 	pPopup->EnableItem( ID_DELETE, pToolbar->IsDeletable() );
4656*cdf0e10cSrcweir 	pPopup->EnableItem( ID_RENAME, pToolbar->IsRenamable() );
4657*cdf0e10cSrcweir 	pPopup->EnableItem( ID_DEFAULT_STYLE, !pToolbar->IsRenamable() );
4658*cdf0e10cSrcweir 
4659*cdf0e10cSrcweir 	switch( pToolbar->GetStyle() )
4660*cdf0e10cSrcweir 	{
4661*cdf0e10cSrcweir 		case 0:
4662*cdf0e10cSrcweir 		{
4663*cdf0e10cSrcweir 			pPopup->CheckItem( ID_ICONS_ONLY );
4664*cdf0e10cSrcweir 			break;
4665*cdf0e10cSrcweir 		}
4666*cdf0e10cSrcweir 		case 1:
4667*cdf0e10cSrcweir 		{
4668*cdf0e10cSrcweir 			pPopup->CheckItem( ID_TEXT_ONLY );
4669*cdf0e10cSrcweir 			break;
4670*cdf0e10cSrcweir 		}
4671*cdf0e10cSrcweir 		case 2:
4672*cdf0e10cSrcweir 		{
4673*cdf0e10cSrcweir 			pPopup->CheckItem( ID_ICONS_AND_TEXT );
4674*cdf0e10cSrcweir 			break;
4675*cdf0e10cSrcweir 		}
4676*cdf0e10cSrcweir 	}
4677*cdf0e10cSrcweir 
4678*cdf0e10cSrcweir 	SvxEntries* pEntries = pToolbar->GetEntries();
4679*cdf0e10cSrcweir 	SvxEntries::const_iterator iter = pEntries->begin();
4680*cdf0e10cSrcweir 
4681*cdf0e10cSrcweir 	for ( ; iter != pEntries->end(); iter++ )
4682*cdf0e10cSrcweir 	{
4683*cdf0e10cSrcweir 		SvxConfigEntry* pEntry = *iter;
4684*cdf0e10cSrcweir 
4685*cdf0e10cSrcweir 		SvLBoxEntry* pNewLBEntry = InsertEntryIntoUI( pEntry );
4686*cdf0e10cSrcweir 
4687*cdf0e10cSrcweir 		if (pEntry->IsBinding())
4688*cdf0e10cSrcweir 		{
4689*cdf0e10cSrcweir 			aContentsListBox->SetCheckButtonState( pNewLBEntry,
4690*cdf0e10cSrcweir 				pEntry->IsVisible() ? SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
4691*cdf0e10cSrcweir 		}
4692*cdf0e10cSrcweir 		else
4693*cdf0e10cSrcweir 		{
4694*cdf0e10cSrcweir 			aContentsListBox->SetCheckButtonState(
4695*cdf0e10cSrcweir 				pNewLBEntry, SV_BUTTON_TRISTATE );
4696*cdf0e10cSrcweir 		}
4697*cdf0e10cSrcweir 	}
4698*cdf0e10cSrcweir 
4699*cdf0e10cSrcweir 	UpdateButtonStates();
4700*cdf0e10cSrcweir 
4701*cdf0e10cSrcweir 	return 0;
4702*cdf0e10cSrcweir }
4703*cdf0e10cSrcweir 
4704*cdf0e10cSrcweir IMPL_LINK( SvxToolbarConfigPage, NewToolbarHdl, Button *, pButton )
4705*cdf0e10cSrcweir {
4706*cdf0e10cSrcweir 	(void)pButton;
4707*cdf0e10cSrcweir 
4708*cdf0e10cSrcweir 	String prefix =
4709*cdf0e10cSrcweir 		String( CUI_RES( RID_SVXSTR_NEW_TOOLBAR ) );
4710*cdf0e10cSrcweir 
4711*cdf0e10cSrcweir 	OUString aNewName =
4712*cdf0e10cSrcweir 		generateCustomName( prefix, GetSaveInData()->GetEntries() );
4713*cdf0e10cSrcweir 
4714*cdf0e10cSrcweir 	OUString aNewURL =
4715*cdf0e10cSrcweir 		generateCustomURL( GetSaveInData()->GetEntries() );
4716*cdf0e10cSrcweir 
4717*cdf0e10cSrcweir 	SvxNewToolbarDialog* pNameDialog = new SvxNewToolbarDialog( 0, aNewName );
4718*cdf0e10cSrcweir 
4719*cdf0e10cSrcweir 	sal_uInt16 nInsertPos;
4720*cdf0e10cSrcweir 	for ( sal_uInt16 i = 0 ; i < aSaveInListBox.GetEntryCount(); i++ )
4721*cdf0e10cSrcweir 	{
4722*cdf0e10cSrcweir 		SaveInData* pData =
4723*cdf0e10cSrcweir 			(SaveInData*) aSaveInListBox.GetEntryData( i );
4724*cdf0e10cSrcweir 
4725*cdf0e10cSrcweir 		nInsertPos = pNameDialog->aSaveInListBox.InsertEntry(
4726*cdf0e10cSrcweir 			aSaveInListBox.GetEntry( i ) );
4727*cdf0e10cSrcweir 
4728*cdf0e10cSrcweir 		pNameDialog->aSaveInListBox.SetEntryData( nInsertPos, pData );
4729*cdf0e10cSrcweir 	}
4730*cdf0e10cSrcweir 
4731*cdf0e10cSrcweir 	pNameDialog->aSaveInListBox.SelectEntryPos(
4732*cdf0e10cSrcweir 		aSaveInListBox.GetSelectEntryPos(), sal_True );
4733*cdf0e10cSrcweir 
4734*cdf0e10cSrcweir 	bool ret = pNameDialog->Execute();
4735*cdf0e10cSrcweir 	if ( ret == RET_OK )
4736*cdf0e10cSrcweir 	{
4737*cdf0e10cSrcweir 		pNameDialog->GetName( aNewName );
4738*cdf0e10cSrcweir 
4739*cdf0e10cSrcweir 		nInsertPos = pNameDialog->aSaveInListBox.GetSelectEntryPos();
4740*cdf0e10cSrcweir 
4741*cdf0e10cSrcweir 		ToolbarSaveInData* pData = (ToolbarSaveInData*)
4742*cdf0e10cSrcweir 			pNameDialog->aSaveInListBox.GetEntryData( nInsertPos );
4743*cdf0e10cSrcweir 
4744*cdf0e10cSrcweir 		if ( GetSaveInData() != pData )
4745*cdf0e10cSrcweir 		{
4746*cdf0e10cSrcweir 			aSaveInListBox.SelectEntryPos( nInsertPos, sal_True );
4747*cdf0e10cSrcweir 			aSaveInListBox.GetSelectHdl().Call(this);
4748*cdf0e10cSrcweir 		}
4749*cdf0e10cSrcweir 
4750*cdf0e10cSrcweir 		SvxConfigEntry* pToolbar =
4751*cdf0e10cSrcweir 			new SvxConfigEntry( aNewName, aNewURL, sal_True );
4752*cdf0e10cSrcweir 
4753*cdf0e10cSrcweir 		pToolbar->SetUserDefined( sal_True );
4754*cdf0e10cSrcweir 		pToolbar->SetMain( sal_True );
4755*cdf0e10cSrcweir 
4756*cdf0e10cSrcweir 		pData->CreateToolbar( pToolbar );
4757*cdf0e10cSrcweir 
4758*cdf0e10cSrcweir         nInsertPos = aTopLevelListBox.InsertEntry( pToolbar->GetName() );
4759*cdf0e10cSrcweir 	    aTopLevelListBox.SetEntryData( nInsertPos, pToolbar );
4760*cdf0e10cSrcweir 	    aTopLevelListBox.SelectEntryPos( nInsertPos, sal_True );
4761*cdf0e10cSrcweir 	    aTopLevelListBox.GetSelectHdl().Call(this);
4762*cdf0e10cSrcweir 
4763*cdf0e10cSrcweir 		pData->SetModified( sal_True );
4764*cdf0e10cSrcweir 	}
4765*cdf0e10cSrcweir 
4766*cdf0e10cSrcweir 	delete pNameDialog;
4767*cdf0e10cSrcweir 
4768*cdf0e10cSrcweir 	return 0;
4769*cdf0e10cSrcweir }
4770*cdf0e10cSrcweir 
4771*cdf0e10cSrcweir IMPL_LINK( SvxToolbarConfigPage, AddCommandsHdl, Button *, pButton )
4772*cdf0e10cSrcweir {
4773*cdf0e10cSrcweir 	(void)pButton;
4774*cdf0e10cSrcweir 
4775*cdf0e10cSrcweir 	if ( pSelectorDlg == NULL )
4776*cdf0e10cSrcweir 	{
4777*cdf0e10cSrcweir 		// Create Script Selector which shows slot commands
4778*cdf0e10cSrcweir 		pSelectorDlg = new SvxScriptSelectorDialog( this, sal_True, m_xFrame );
4779*cdf0e10cSrcweir 
4780*cdf0e10cSrcweir 		// Position the Script Selector over the Add button so it is
4781*cdf0e10cSrcweir 		// beside the menu contents list and does not obscure it
4782*cdf0e10cSrcweir 		pSelectorDlg->SetPosPixel( aAddCommandsButton.GetPosPixel() );
4783*cdf0e10cSrcweir 
4784*cdf0e10cSrcweir 		pSelectorDlg->SetAddHdl(
4785*cdf0e10cSrcweir 			LINK( this, SvxToolbarConfigPage, AddFunctionHdl ) );
4786*cdf0e10cSrcweir 	}
4787*cdf0e10cSrcweir 
4788*cdf0e10cSrcweir 	pSelectorDlg->SetImageProvider(
4789*cdf0e10cSrcweir 		static_cast< ImageProvider* >( GetSaveInData() ) );
4790*cdf0e10cSrcweir 
4791*cdf0e10cSrcweir 	pSelectorDlg->Show();
4792*cdf0e10cSrcweir 	return 1;
4793*cdf0e10cSrcweir }
4794*cdf0e10cSrcweir 
4795*cdf0e10cSrcweir IMPL_LINK( SvxToolbarConfigPage, AddFunctionHdl,
4796*cdf0e10cSrcweir 	SvxScriptSelectorDialog *, pDialog )
4797*cdf0e10cSrcweir {
4798*cdf0e10cSrcweir 	(void)pDialog;
4799*cdf0e10cSrcweir 
4800*cdf0e10cSrcweir 	AddFunction();
4801*cdf0e10cSrcweir 
4802*cdf0e10cSrcweir 	return 0;
4803*cdf0e10cSrcweir }
4804*cdf0e10cSrcweir 
4805*cdf0e10cSrcweir SvLBoxEntry* SvxToolbarConfigPage::AddFunction(
4806*cdf0e10cSrcweir 	SvLBoxEntry* pTarget, bool bFront, bool bAllowDuplicates )
4807*cdf0e10cSrcweir {
4808*cdf0e10cSrcweir 	SvLBoxEntry* pNewLBEntry =
4809*cdf0e10cSrcweir 		SvxConfigPage::AddFunction( pTarget, bFront, bAllowDuplicates );
4810*cdf0e10cSrcweir 
4811*cdf0e10cSrcweir 	SvxConfigEntry* pEntry = (SvxConfigEntry*) pNewLBEntry->GetUserData();
4812*cdf0e10cSrcweir 
4813*cdf0e10cSrcweir 	if ( pEntry->IsBinding() )
4814*cdf0e10cSrcweir 	{
4815*cdf0e10cSrcweir 		pEntry->SetVisible( sal_True );
4816*cdf0e10cSrcweir 		aContentsListBox->SetCheckButtonState(
4817*cdf0e10cSrcweir 			pNewLBEntry, SV_BUTTON_CHECKED );
4818*cdf0e10cSrcweir 	}
4819*cdf0e10cSrcweir 	else
4820*cdf0e10cSrcweir 	{
4821*cdf0e10cSrcweir 		aContentsListBox->SetCheckButtonState(
4822*cdf0e10cSrcweir 			pNewLBEntry, SV_BUTTON_TRISTATE );
4823*cdf0e10cSrcweir 	}
4824*cdf0e10cSrcweir 
4825*cdf0e10cSrcweir 	// get currently selected toolbar and apply change
4826*cdf0e10cSrcweir 	SvxConfigEntry* pToolbar = GetTopLevelSelection();
4827*cdf0e10cSrcweir 
4828*cdf0e10cSrcweir 	if ( pToolbar != NULL )
4829*cdf0e10cSrcweir 	{
4830*cdf0e10cSrcweir 		( ( ToolbarSaveInData* ) GetSaveInData() )->ApplyToolbar( pToolbar );
4831*cdf0e10cSrcweir 	}
4832*cdf0e10cSrcweir 
4833*cdf0e10cSrcweir 	return pNewLBEntry;
4834*cdf0e10cSrcweir }
4835*cdf0e10cSrcweir 
4836*cdf0e10cSrcweir // -----------------------------------------------------------------------
4837*cdf0e10cSrcweir 
4838*cdf0e10cSrcweir SvxToolbarEntriesListBox::SvxToolbarEntriesListBox(
4839*cdf0e10cSrcweir 	Window* pParent, const ResId& aResId )
4840*cdf0e10cSrcweir 	:
4841*cdf0e10cSrcweir 		SvxMenuEntriesListBox( pParent, aResId ),
4842*cdf0e10cSrcweir 		pPage( ( SvxToolbarConfigPage* ) pParent )
4843*cdf0e10cSrcweir {
4844*cdf0e10cSrcweir 	m_pButtonData = new SvLBoxButtonData( this );
4845*cdf0e10cSrcweir 	BuildCheckBoxButtonImages( m_pButtonData );
4846*cdf0e10cSrcweir 	EnableCheckButton( m_pButtonData );
4847*cdf0e10cSrcweir 
4848*cdf0e10cSrcweir 	m_bHiContrastMode = GetSettings().GetStyleSettings().GetHighContrastMode();
4849*cdf0e10cSrcweir }
4850*cdf0e10cSrcweir 
4851*cdf0e10cSrcweir // --------------------------------------------------------
4852*cdf0e10cSrcweir 
4853*cdf0e10cSrcweir SvxToolbarEntriesListBox::~SvxToolbarEntriesListBox()
4854*cdf0e10cSrcweir {
4855*cdf0e10cSrcweir 	delete m_pButtonData;
4856*cdf0e10cSrcweir }
4857*cdf0e10cSrcweir 
4858*cdf0e10cSrcweir // --------------------------------------------------------
4859*cdf0e10cSrcweir 
4860*cdf0e10cSrcweir void SvxToolbarEntriesListBox::BuildCheckBoxButtonImages( SvLBoxButtonData* pData )
4861*cdf0e10cSrcweir {
4862*cdf0e10cSrcweir 	// Build checkbox images according to the current application
4863*cdf0e10cSrcweir 	// settings. This is necessary to be able to have correct colors
4864*cdf0e10cSrcweir 	// in all color modes, like high contrast.
4865*cdf0e10cSrcweir 	const AllSettings& rSettings = Application::GetSettings();
4866*cdf0e10cSrcweir 
4867*cdf0e10cSrcweir 	VirtualDevice	aDev;
4868*cdf0e10cSrcweir 	Size			aSize( 26, 20 );
4869*cdf0e10cSrcweir 
4870*cdf0e10cSrcweir 	aDev.SetOutputSizePixel( aSize );
4871*cdf0e10cSrcweir 
4872*cdf0e10cSrcweir 	Image aImage = GetSizedImage( aDev, aSize,
4873*cdf0e10cSrcweir 		CheckBox::GetCheckImage( rSettings, BUTTON_DRAW_DEFAULT ));
4874*cdf0e10cSrcweir 
4875*cdf0e10cSrcweir 	// Fill button data struct with new images
4876*cdf0e10cSrcweir 	pData->aBmps[SV_BMP_UNCHECKED]		= aImage;
4877*cdf0e10cSrcweir 	pData->aBmps[SV_BMP_CHECKED]		= GetSizedImage( aDev, aSize, CheckBox::GetCheckImage( rSettings, BUTTON_DRAW_CHECKED ));
4878*cdf0e10cSrcweir 	pData->aBmps[SV_BMP_HICHECKED]		= GetSizedImage( aDev, aSize, CheckBox::GetCheckImage( rSettings, BUTTON_DRAW_CHECKED | BUTTON_DRAW_PRESSED ));
4879*cdf0e10cSrcweir 	pData->aBmps[SV_BMP_HIUNCHECKED]	= GetSizedImage( aDev, aSize, CheckBox::GetCheckImage( rSettings, BUTTON_DRAW_DEFAULT | BUTTON_DRAW_PRESSED));
4880*cdf0e10cSrcweir 	pData->aBmps[SV_BMP_TRISTATE]		= GetSizedImage( aDev, aSize, Image() ); // Use tristate bitmaps to have no checkbox for separator entries
4881*cdf0e10cSrcweir 	pData->aBmps[SV_BMP_HITRISTATE]		= GetSizedImage( aDev, aSize, Image() );
4882*cdf0e10cSrcweir 
4883*cdf0e10cSrcweir 	// Get image size
4884*cdf0e10cSrcweir 	m_aCheckBoxImageSizePixel = aImage.GetSizePixel();
4885*cdf0e10cSrcweir }
4886*cdf0e10cSrcweir 
4887*cdf0e10cSrcweir Image SvxToolbarEntriesListBox::GetSizedImage(
4888*cdf0e10cSrcweir 	VirtualDevice& aDev, const Size& aNewSize, const Image& aImage )
4889*cdf0e10cSrcweir {
4890*cdf0e10cSrcweir 	// Create new checkbox images for treelistbox. They must have a
4891*cdf0e10cSrcweir 	// decent width to have a clear column for the visibility checkbox.
4892*cdf0e10cSrcweir 
4893*cdf0e10cSrcweir 	// Standard transparent color is light magenta as is won't be
4894*cdf0e10cSrcweir 	// used for other things
4895*cdf0e10cSrcweir 	Color	aFillColor( COL_LIGHTMAGENTA );
4896*cdf0e10cSrcweir 
4897*cdf0e10cSrcweir 	// Position image at the center of (width-2),(height) rectangle.
4898*cdf0e10cSrcweir 	// We need 2 pixels to have a bigger border to the next button image
4899*cdf0e10cSrcweir 	sal_uInt16	nPosX = std::max( (sal_uInt16) (((( aNewSize.Width() - 2 ) - aImage.GetSizePixel().Width() ) / 2 ) - 1), (sal_uInt16) 0 );
4900*cdf0e10cSrcweir 	sal_uInt16	nPosY = std::max( (sal_uInt16) (((( aNewSize.Height() - 2 ) - aImage.GetSizePixel().Height() ) / 2 ) + 1), (sal_uInt16) 0 );
4901*cdf0e10cSrcweir 	Point	aPos( nPosX > 0 ? nPosX : 0, nPosY > 0 ? nPosY : 0 );
4902*cdf0e10cSrcweir 	aDev.SetFillColor( aFillColor );
4903*cdf0e10cSrcweir 	aDev.SetLineColor( aFillColor );
4904*cdf0e10cSrcweir 	aDev.DrawRect( Rectangle( Point(), aNewSize ));
4905*cdf0e10cSrcweir 	aDev.DrawImage( aPos, aImage );
4906*cdf0e10cSrcweir 
4907*cdf0e10cSrcweir 	// Draw separator line 2 pixels left from the right border
4908*cdf0e10cSrcweir 	Color aLineColor = GetDisplayBackground().GetColor().IsDark() ? Color( COL_WHITE ) : Color( COL_BLACK );
4909*cdf0e10cSrcweir 	aDev.SetLineColor( aLineColor );
4910*cdf0e10cSrcweir 	aDev.DrawLine( Point( aNewSize.Width()-3, 0 ), Point( aNewSize.Width()-3, aNewSize.Height()-1 ));
4911*cdf0e10cSrcweir 
4912*cdf0e10cSrcweir 	// Create new image that uses the fillcolor as transparent
4913*cdf0e10cSrcweir 	return Image( aDev.GetBitmap( Point(), aNewSize ), aFillColor );
4914*cdf0e10cSrcweir }
4915*cdf0e10cSrcweir 
4916*cdf0e10cSrcweir void SvxToolbarEntriesListBox::DataChanged( const DataChangedEvent& rDCEvt )
4917*cdf0e10cSrcweir {
4918*cdf0e10cSrcweir 	SvTreeListBox::DataChanged( rDCEvt );
4919*cdf0e10cSrcweir 
4920*cdf0e10cSrcweir 	if (( rDCEvt.GetType() == DATACHANGED_SETTINGS ) &&
4921*cdf0e10cSrcweir         ( rDCEvt.GetFlags() & SETTINGS_STYLE ))
4922*cdf0e10cSrcweir     {
4923*cdf0e10cSrcweir         // We have to reset all images because we change to/from high contrast mode
4924*cdf0e10cSrcweir         m_bHiContrastMode = GetSettings().GetStyleSettings().GetHighContrastMode();
4925*cdf0e10cSrcweir 
4926*cdf0e10cSrcweir 		BuildCheckBoxButtonImages( m_pButtonData );
4927*cdf0e10cSrcweir         Invalidate();
4928*cdf0e10cSrcweir     }
4929*cdf0e10cSrcweir }
4930*cdf0e10cSrcweir 
4931*cdf0e10cSrcweir // --------------------------------------------------------
4932*cdf0e10cSrcweir 
4933*cdf0e10cSrcweir void SvxToolbarEntriesListBox::ChangeVisibility( SvLBoxEntry* pEntry )
4934*cdf0e10cSrcweir {
4935*cdf0e10cSrcweir 	if ( pEntry != NULL )
4936*cdf0e10cSrcweir 	{
4937*cdf0e10cSrcweir 		SvxConfigEntry* pEntryData =
4938*cdf0e10cSrcweir 			(SvxConfigEntry*) pEntry->GetUserData();
4939*cdf0e10cSrcweir 
4940*cdf0e10cSrcweir 		if ( pEntryData->IsBinding() )
4941*cdf0e10cSrcweir 		{
4942*cdf0e10cSrcweir 			pEntryData->SetVisible( !pEntryData->IsVisible() );
4943*cdf0e10cSrcweir 
4944*cdf0e10cSrcweir 			SvxConfigEntry* pToolbar = pPage->GetTopLevelSelection();
4945*cdf0e10cSrcweir 
4946*cdf0e10cSrcweir 			ToolbarSaveInData* pToolbarSaveInData = ( ToolbarSaveInData* )
4947*cdf0e10cSrcweir 				pPage->GetSaveInData();
4948*cdf0e10cSrcweir 
4949*cdf0e10cSrcweir    			pToolbarSaveInData->ApplyToolbar( pToolbar );
4950*cdf0e10cSrcweir 
4951*cdf0e10cSrcweir 			SetCheckButtonState( pEntry, pEntryData->IsVisible() ?
4952*cdf0e10cSrcweir 				SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
4953*cdf0e10cSrcweir 		}
4954*cdf0e10cSrcweir 	}
4955*cdf0e10cSrcweir }
4956*cdf0e10cSrcweir 
4957*cdf0e10cSrcweir void SvxToolbarEntriesListBox::CheckButtonHdl()
4958*cdf0e10cSrcweir {
4959*cdf0e10cSrcweir 	ChangeVisibility( GetHdlEntry() );
4960*cdf0e10cSrcweir }
4961*cdf0e10cSrcweir 
4962*cdf0e10cSrcweir void SvxToolbarEntriesListBox::KeyInput( const KeyEvent& rKeyEvent )
4963*cdf0e10cSrcweir {
4964*cdf0e10cSrcweir 	// space key will change visibility of toolbar items
4965*cdf0e10cSrcweir 	if ( rKeyEvent.GetKeyCode() == KEY_SPACE )
4966*cdf0e10cSrcweir 	{
4967*cdf0e10cSrcweir 		ChangeVisibility( GetCurEntry() );
4968*cdf0e10cSrcweir 	}
4969*cdf0e10cSrcweir 	else
4970*cdf0e10cSrcweir 	{
4971*cdf0e10cSrcweir 		// pass on to superclass
4972*cdf0e10cSrcweir 		SvxMenuEntriesListBox::KeyInput( rKeyEvent );
4973*cdf0e10cSrcweir 	}
4974*cdf0e10cSrcweir }
4975*cdf0e10cSrcweir 
4976*cdf0e10cSrcweir sal_Bool SvxToolbarEntriesListBox::NotifyMoving(
4977*cdf0e10cSrcweir 	SvLBoxEntry* pTarget, SvLBoxEntry* pSource,
4978*cdf0e10cSrcweir 	SvLBoxEntry*& rpNewParent, sal_uLong& rNewChildPos)
4979*cdf0e10cSrcweir {
4980*cdf0e10cSrcweir 	bool result = SvxMenuEntriesListBox::NotifyMoving(
4981*cdf0e10cSrcweir 		pTarget, pSource, rpNewParent, rNewChildPos );
4982*cdf0e10cSrcweir 
4983*cdf0e10cSrcweir 	if ( result == sal_True )
4984*cdf0e10cSrcweir 	{
4985*cdf0e10cSrcweir 		// Instant Apply changes to UI
4986*cdf0e10cSrcweir 		SvxConfigEntry* pToolbar = pPage->GetTopLevelSelection();
4987*cdf0e10cSrcweir 		if ( pToolbar != NULL )
4988*cdf0e10cSrcweir 		{
4989*cdf0e10cSrcweir 			ToolbarSaveInData* pSaveInData =
4990*cdf0e10cSrcweir 				( ToolbarSaveInData*) pPage->GetSaveInData();
4991*cdf0e10cSrcweir 			pSaveInData->ApplyToolbar( pToolbar );
4992*cdf0e10cSrcweir 		}
4993*cdf0e10cSrcweir 	}
4994*cdf0e10cSrcweir 
4995*cdf0e10cSrcweir 	return result;
4996*cdf0e10cSrcweir }
4997*cdf0e10cSrcweir 
4998*cdf0e10cSrcweir sal_Bool SvxToolbarEntriesListBox::NotifyCopying(
4999*cdf0e10cSrcweir     SvLBoxEntry*  pTarget,
5000*cdf0e10cSrcweir     SvLBoxEntry*  pSource,
5001*cdf0e10cSrcweir     SvLBoxEntry*& rpNewParent,
5002*cdf0e10cSrcweir     sal_uLong&      rNewChildPos)
5003*cdf0e10cSrcweir {
5004*cdf0e10cSrcweir 	(void)pSource;
5005*cdf0e10cSrcweir 	(void)rpNewParent;
5006*cdf0e10cSrcweir 	(void)rNewChildPos;
5007*cdf0e10cSrcweir 
5008*cdf0e10cSrcweir 	if ( !m_bIsInternalDrag )
5009*cdf0e10cSrcweir 	{
5010*cdf0e10cSrcweir 		// if the target is NULL then add function to the start of the list
5011*cdf0e10cSrcweir 		((SvxToolbarConfigPage*)pPage)->AddFunction( pTarget, pTarget == NULL );
5012*cdf0e10cSrcweir 
5013*cdf0e10cSrcweir 		// Instant Apply changes to UI
5014*cdf0e10cSrcweir 		SvxConfigEntry* pToolbar = pPage->GetTopLevelSelection();
5015*cdf0e10cSrcweir 		if ( pToolbar != NULL )
5016*cdf0e10cSrcweir 		{
5017*cdf0e10cSrcweir 			ToolbarSaveInData* pSaveInData =
5018*cdf0e10cSrcweir 				( ToolbarSaveInData*) pPage->GetSaveInData();
5019*cdf0e10cSrcweir 			pSaveInData->ApplyToolbar( pToolbar );
5020*cdf0e10cSrcweir 		}
5021*cdf0e10cSrcweir 
5022*cdf0e10cSrcweir 		// AddFunction already adds the listbox entry so return FALSE
5023*cdf0e10cSrcweir 		// to stop another listbox entry being added
5024*cdf0e10cSrcweir 		return sal_False;
5025*cdf0e10cSrcweir 	}
5026*cdf0e10cSrcweir 
5027*cdf0e10cSrcweir 	// Copying is only allowed from external controls, not within the listbox
5028*cdf0e10cSrcweir 	return sal_False;
5029*cdf0e10cSrcweir }
5030*cdf0e10cSrcweir 
5031*cdf0e10cSrcweir SvxNewToolbarDialog::SvxNewToolbarDialog(
5032*cdf0e10cSrcweir 	Window* pWindow, const String& rName )
5033*cdf0e10cSrcweir 	:
5034*cdf0e10cSrcweir 	ModalDialog		( pWindow, CUI_RES( MD_NEW_TOOLBAR ) ),
5035*cdf0e10cSrcweir 	aFtDescription	( this, CUI_RES( FT_NAME ) ),
5036*cdf0e10cSrcweir 	aEdtName		( this, CUI_RES( EDT_STRING ) ),
5037*cdf0e10cSrcweir 	aSaveInText		( this, CUI_RES( TXT_SAVEIN ) ),
5038*cdf0e10cSrcweir 	aBtnOK			( this, CUI_RES( BTN_OK ) ),
5039*cdf0e10cSrcweir 	aBtnCancel		( this, CUI_RES( BTN_CANCEL ) ),
5040*cdf0e10cSrcweir 	aBtnHelp		( this, CUI_RES( BTN_HELP ) ),
5041*cdf0e10cSrcweir 	aSaveInListBox	( this, CUI_RES( LB_SAVEIN ) )
5042*cdf0e10cSrcweir {
5043*cdf0e10cSrcweir 	FreeResource();
5044*cdf0e10cSrcweir 
5045*cdf0e10cSrcweir 	aEdtName.SetText( rName );
5046*cdf0e10cSrcweir     aEdtName.SetSelection(Selection(SELECTION_MIN, SELECTION_MAX));
5047*cdf0e10cSrcweir     ModifyHdl(&aEdtName);
5048*cdf0e10cSrcweir     aEdtName.SetModifyHdl(LINK(this, SvxNewToolbarDialog, ModifyHdl));
5049*cdf0e10cSrcweir }
5050*cdf0e10cSrcweir 
5051*cdf0e10cSrcweir IMPL_LINK(SvxNewToolbarDialog, ModifyHdl, Edit*, pEdit)
5052*cdf0e10cSrcweir {
5053*cdf0e10cSrcweir 	(void)pEdit;
5054*cdf0e10cSrcweir 
5055*cdf0e10cSrcweir     if(aCheckNameHdl.IsSet())
5056*cdf0e10cSrcweir         aBtnOK.Enable(aCheckNameHdl.Call(this) > 0);
5057*cdf0e10cSrcweir 
5058*cdf0e10cSrcweir     return 0;
5059*cdf0e10cSrcweir }
5060*cdf0e10cSrcweir 
5061*cdf0e10cSrcweir /*******************************************************************************
5062*cdf0e10cSrcweir *
5063*cdf0e10cSrcweir * The SvxIconSelectorDialog class
5064*cdf0e10cSrcweir *
5065*cdf0e10cSrcweir *******************************************************************************/
5066*cdf0e10cSrcweir SvxIconSelectorDialog::SvxIconSelectorDialog( Window *pWindow,
5067*cdf0e10cSrcweir     const uno::Reference< css::ui::XImageManager >& rXImageManager,
5068*cdf0e10cSrcweir 	const uno::Reference< css::ui::XImageManager >& rXParentImageManager )
5069*cdf0e10cSrcweir 	:
5070*cdf0e10cSrcweir 	ModalDialog		     ( pWindow, CUI_RES( MD_ICONSELECTOR ) ),
5071*cdf0e10cSrcweir 	aFtDescription	     ( this, CUI_RES( FT_SYMBOLS ) ),
5072*cdf0e10cSrcweir 	aTbSymbol		     ( this, CUI_RES( TB_SYMBOLS ) ),
5073*cdf0e10cSrcweir 	aFtNote			     ( this, CUI_RES( FT_NOTE ) ),
5074*cdf0e10cSrcweir 	aBtnOK			     ( this, CUI_RES( BTN_OK ) ),
5075*cdf0e10cSrcweir 	aBtnCancel		     ( this, CUI_RES( BTN_CANCEL ) ),
5076*cdf0e10cSrcweir 	aBtnHelp		     ( this, CUI_RES( BTN_HELP ) ),
5077*cdf0e10cSrcweir 	aBtnImport		     ( this, CUI_RES( BTN_IMPORT ) ),
5078*cdf0e10cSrcweir 	aBtnDelete			 ( this, CUI_RES( BTN_DELETE ) ),
5079*cdf0e10cSrcweir 	aFlSeparator		 ( this, CUI_RES( FL_SEPARATOR ) ),
5080*cdf0e10cSrcweir     m_nNextId            ( 0 ),
5081*cdf0e10cSrcweir 	m_xImageManager	     ( rXImageManager ),
5082*cdf0e10cSrcweir     m_xParentImageManager( rXParentImageManager )
5083*cdf0e10cSrcweir {
5084*cdf0e10cSrcweir 	FreeResource();
5085*cdf0e10cSrcweir 
5086*cdf0e10cSrcweir     typedef ::std::hash_map< ::rtl::OUString,
5087*cdf0e10cSrcweir                              bool,
5088*cdf0e10cSrcweir                              ::rtl::OUStringHash,
5089*cdf0e10cSrcweir                              ::std::equal_to< ::rtl::OUString > > ImageInfo;
5090*cdf0e10cSrcweir 
5091*cdf0e10cSrcweir     aTbSymbol.SetPageScroll( sal_True );
5092*cdf0e10cSrcweir 
5093*cdf0e10cSrcweir 	bool bLargeIcons = GetImageType() & css::ui::ImageType::SIZE_LARGE;
5094*cdf0e10cSrcweir 	m_nExpectedSize = bLargeIcons ? 26 : 16;
5095*cdf0e10cSrcweir 
5096*cdf0e10cSrcweir 	if ( m_nExpectedSize != 16 )
5097*cdf0e10cSrcweir 	{
5098*cdf0e10cSrcweir 		aFtNote.SetText( replaceSixteen( aFtNote.GetText(), m_nExpectedSize ) );
5099*cdf0e10cSrcweir 	}
5100*cdf0e10cSrcweir 
5101*cdf0e10cSrcweir 	uno::Reference< lang::XMultiServiceFactory > xServiceManager =
5102*cdf0e10cSrcweir 		::comphelper::getProcessServiceFactory();
5103*cdf0e10cSrcweir 
5104*cdf0e10cSrcweir 	if ( xServiceManager.is() )
5105*cdf0e10cSrcweir 	{
5106*cdf0e10cSrcweir 		m_xGraphProvider = uno::Reference< graphic::XGraphicProvider >(
5107*cdf0e10cSrcweir 			xServiceManager->createInstance(
5108*cdf0e10cSrcweir 				::rtl::OUString::createFromAscii(
5109*cdf0e10cSrcweir 					"com.sun.star.graphic.GraphicProvider" ) ),
5110*cdf0e10cSrcweir 			uno::UNO_QUERY );
5111*cdf0e10cSrcweir 	}
5112*cdf0e10cSrcweir 
5113*cdf0e10cSrcweir 	if ( !m_xGraphProvider.is() )
5114*cdf0e10cSrcweir 	{
5115*cdf0e10cSrcweir 		aBtnImport.Enable( sal_False );
5116*cdf0e10cSrcweir 	}
5117*cdf0e10cSrcweir 
5118*cdf0e10cSrcweir 	uno::Reference< beans::XPropertySet > xPropSet(
5119*cdf0e10cSrcweir 		xServiceManager->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.util.PathSettings" ) ),
5120*cdf0e10cSrcweir 		uno::UNO_QUERY );
5121*cdf0e10cSrcweir 
5122*cdf0e10cSrcweir 	uno::Any aAny = xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UserConfig" ) ) );
5123*cdf0e10cSrcweir 
5124*cdf0e10cSrcweir 	::rtl::OUString aDirectory;
5125*cdf0e10cSrcweir 
5126*cdf0e10cSrcweir 	aAny >>= aDirectory;
5127*cdf0e10cSrcweir 
5128*cdf0e10cSrcweir 	sal_Int32 aCount = aDirectory.getLength();
5129*cdf0e10cSrcweir 
5130*cdf0e10cSrcweir 	if ( aCount > 0 )
5131*cdf0e10cSrcweir 	{
5132*cdf0e10cSrcweir 		sal_Unicode aChar = aDirectory[ aCount-1 ];
5133*cdf0e10cSrcweir 		if ( aChar != '/')
5134*cdf0e10cSrcweir 		{
5135*cdf0e10cSrcweir 			aDirectory += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) );
5136*cdf0e10cSrcweir 		}
5137*cdf0e10cSrcweir 	}
5138*cdf0e10cSrcweir 	else
5139*cdf0e10cSrcweir 	{
5140*cdf0e10cSrcweir 		aBtnImport.Enable( sal_False );
5141*cdf0e10cSrcweir 	}
5142*cdf0e10cSrcweir 
5143*cdf0e10cSrcweir 	aDirectory += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "soffice.cfg/import" ) );
5144*cdf0e10cSrcweir 
5145*cdf0e10cSrcweir 	uno::Reference< lang::XSingleServiceFactory > xStorageFactory(
5146*cdf0e10cSrcweir 		xServiceManager->createInstance(
5147*cdf0e10cSrcweir 		::rtl::OUString::createFromAscii( "com.sun.star.embed.FileSystemStorageFactory" )),
5148*cdf0e10cSrcweir 		uno::UNO_QUERY );
5149*cdf0e10cSrcweir 
5150*cdf0e10cSrcweir 	uno::Sequence< uno::Any > aArgs( 2 );
5151*cdf0e10cSrcweir 	aArgs[ 0 ] <<= aDirectory;
5152*cdf0e10cSrcweir 	aArgs[ 1 ] <<= com::sun::star::embed::ElementModes::READWRITE;
5153*cdf0e10cSrcweir 
5154*cdf0e10cSrcweir 	uno::Reference< com::sun::star::embed::XStorage > xStorage(
5155*cdf0e10cSrcweir 		xStorageFactory->createInstanceWithArguments( aArgs ), uno::UNO_QUERY );
5156*cdf0e10cSrcweir 
5157*cdf0e10cSrcweir 	uno::Sequence< uno::Any > aProp( 2 );
5158*cdf0e10cSrcweir 	beans::PropertyValue aPropValue;
5159*cdf0e10cSrcweir 
5160*cdf0e10cSrcweir 	aPropValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UserConfigStorage" ) );
5161*cdf0e10cSrcweir 	aPropValue.Value <<= xStorage;
5162*cdf0e10cSrcweir 	aProp[ 0 ] <<= aPropValue;
5163*cdf0e10cSrcweir 
5164*cdf0e10cSrcweir 	aPropValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenMode" ) );
5165*cdf0e10cSrcweir 	aPropValue.Value <<= com::sun::star::embed::ElementModes::READWRITE;
5166*cdf0e10cSrcweir 	aProp[ 1 ] <<= aPropValue;
5167*cdf0e10cSrcweir 
5168*cdf0e10cSrcweir 	m_xImportedImageManager = uno::Reference< com::sun::star::ui::XImageManager >(
5169*cdf0e10cSrcweir 		xServiceManager->createInstanceWithArguments(
5170*cdf0e10cSrcweir 		::rtl::OUString::createFromAscii( "com.sun.star.ui.ImageManager" ), aProp ),
5171*cdf0e10cSrcweir 		uno::UNO_QUERY );
5172*cdf0e10cSrcweir 
5173*cdf0e10cSrcweir 	ImageInfo mImageInfo;
5174*cdf0e10cSrcweir 	uno::Sequence< OUString > names;
5175*cdf0e10cSrcweir 	if ( m_xImportedImageManager.is() )
5176*cdf0e10cSrcweir 	{
5177*cdf0e10cSrcweir 		names = m_xImportedImageManager->getAllImageNames( GetImageType() );
5178*cdf0e10cSrcweir 		for ( sal_Int32 n = 0; n < names.getLength(); n++ )
5179*cdf0e10cSrcweir 			mImageInfo.insert( ImageInfo::value_type( names[n], false ));
5180*cdf0e10cSrcweir 	}
5181*cdf0e10cSrcweir 	sal_uInt16 nId = 1;
5182*cdf0e10cSrcweir 	ImageInfo::const_iterator pConstIter = mImageInfo.begin();
5183*cdf0e10cSrcweir 	uno::Sequence< OUString > name( 1 );
5184*cdf0e10cSrcweir 	while ( pConstIter != mImageInfo.end() )
5185*cdf0e10cSrcweir 	{
5186*cdf0e10cSrcweir 		name[ 0 ] = pConstIter->first;
5187*cdf0e10cSrcweir 		uno::Sequence< uno::Reference< graphic::XGraphic> > graphics = m_xImportedImageManager->getImages( GetImageType(), name );
5188*cdf0e10cSrcweir 		if ( graphics.getLength() > 0 )
5189*cdf0e10cSrcweir 		{
5190*cdf0e10cSrcweir 			Image img = Image( graphics[ 0 ] );
5191*cdf0e10cSrcweir 			aTbSymbol.InsertItem( nId, img, pConstIter->first );
5192*cdf0e10cSrcweir 
5193*cdf0e10cSrcweir 			graphics[ 0 ]->acquire();
5194*cdf0e10cSrcweir 
5195*cdf0e10cSrcweir 			aTbSymbol.SetItemData(
5196*cdf0e10cSrcweir 				nId, static_cast< void * > ( graphics[ 0 ].get() ) );
5197*cdf0e10cSrcweir 
5198*cdf0e10cSrcweir 			++nId;
5199*cdf0e10cSrcweir 		}
5200*cdf0e10cSrcweir 		++pConstIter;
5201*cdf0e10cSrcweir 	}
5202*cdf0e10cSrcweir 
5203*cdf0e10cSrcweir     ImageInfo                 aImageInfo;
5204*cdf0e10cSrcweir 
5205*cdf0e10cSrcweir     if ( m_xParentImageManager.is() )
5206*cdf0e10cSrcweir     {
5207*cdf0e10cSrcweir         names = m_xParentImageManager->getAllImageNames( GetImageType() );
5208*cdf0e10cSrcweir         for ( sal_Int32 n = 0; n < names.getLength(); n++ )
5209*cdf0e10cSrcweir             aImageInfo.insert( ImageInfo::value_type( names[n], false ));
5210*cdf0e10cSrcweir     }
5211*cdf0e10cSrcweir 
5212*cdf0e10cSrcweir     names = m_xImageManager->getAllImageNames( GetImageType() );
5213*cdf0e10cSrcweir     for ( sal_Int32 n = 0; n < names.getLength(); n++ )
5214*cdf0e10cSrcweir     {
5215*cdf0e10cSrcweir         ImageInfo::iterator pIter = aImageInfo.find( names[n] );
5216*cdf0e10cSrcweir         if ( pIter != aImageInfo.end() )
5217*cdf0e10cSrcweir             pIter->second = true;
5218*cdf0e10cSrcweir         else
5219*cdf0e10cSrcweir             aImageInfo.insert( ImageInfo::value_type( names[n], true ));
5220*cdf0e10cSrcweir     }
5221*cdf0e10cSrcweir 
5222*cdf0e10cSrcweir 	// large growth factor, expecting many entries
5223*cdf0e10cSrcweir 	pConstIter = aImageInfo.begin();
5224*cdf0e10cSrcweir     while ( pConstIter != aImageInfo.end() )
5225*cdf0e10cSrcweir     {
5226*cdf0e10cSrcweir 		name[ 0 ] = pConstIter->first;
5227*cdf0e10cSrcweir 
5228*cdf0e10cSrcweir 		uno::Sequence< uno::Reference< graphic::XGraphic> > graphics;
5229*cdf0e10cSrcweir 		try
5230*cdf0e10cSrcweir 		{
5231*cdf0e10cSrcweir             if ( pConstIter->second )
5232*cdf0e10cSrcweir                 graphics = m_xImageManager->getImages( GetImageType(), name );
5233*cdf0e10cSrcweir             else
5234*cdf0e10cSrcweir 				graphics = m_xParentImageManager->getImages( GetImageType(), name );
5235*cdf0e10cSrcweir 		}
5236*cdf0e10cSrcweir 		catch ( uno::Exception& )
5237*cdf0e10cSrcweir 		{
5238*cdf0e10cSrcweir 			// can't get sequence for this name so it will not be
5239*cdf0e10cSrcweir 			// added to the list
5240*cdf0e10cSrcweir 		}
5241*cdf0e10cSrcweir 
5242*cdf0e10cSrcweir 		if ( graphics.getLength() > 0 )
5243*cdf0e10cSrcweir 		{
5244*cdf0e10cSrcweir 			Image img = Image( graphics[ 0 ] );
5245*cdf0e10cSrcweir 			aTbSymbol.InsertItem( nId, img, pConstIter->first );
5246*cdf0e10cSrcweir 
5247*cdf0e10cSrcweir             uno::Reference< graphic::XGraphic > xGraphic = graphics[ 0 ];
5248*cdf0e10cSrcweir 
5249*cdf0e10cSrcweir 			if ( xGraphic.is() )
5250*cdf0e10cSrcweir                 xGraphic->acquire();
5251*cdf0e10cSrcweir 
5252*cdf0e10cSrcweir 			aTbSymbol.SetItemData(
5253*cdf0e10cSrcweir 				nId, static_cast< void * > ( xGraphic.get() ) );
5254*cdf0e10cSrcweir 
5255*cdf0e10cSrcweir 	    	++nId;
5256*cdf0e10cSrcweir 		}
5257*cdf0e10cSrcweir 
5258*cdf0e10cSrcweir         ++pConstIter;
5259*cdf0e10cSrcweir 	}
5260*cdf0e10cSrcweir 
5261*cdf0e10cSrcweir 	aBtnDelete.Enable( sal_False );
5262*cdf0e10cSrcweir 	aTbSymbol.SetSelectHdl( LINK(this, SvxIconSelectorDialog, SelectHdl) );
5263*cdf0e10cSrcweir 	aBtnImport.SetClickHdl( LINK(this, SvxIconSelectorDialog, ImportHdl) );
5264*cdf0e10cSrcweir 	aBtnDelete.SetClickHdl( LINK(this, SvxIconSelectorDialog, DeleteHdl) );
5265*cdf0e10cSrcweir 
5266*cdf0e10cSrcweir     m_nNextId = aTbSymbol.GetItemCount()+1;
5267*cdf0e10cSrcweir }
5268*cdf0e10cSrcweir 
5269*cdf0e10cSrcweir SvxIconSelectorDialog::~SvxIconSelectorDialog()
5270*cdf0e10cSrcweir {
5271*cdf0e10cSrcweir 	sal_uInt16 nCount = aTbSymbol.GetItemCount();
5272*cdf0e10cSrcweir 
5273*cdf0e10cSrcweir 	for (sal_uInt16 n = 0; n < nCount; n++ )
5274*cdf0e10cSrcweir 	{
5275*cdf0e10cSrcweir 		sal_uInt16 nId = aTbSymbol.GetItemId(n);
5276*cdf0e10cSrcweir 
5277*cdf0e10cSrcweir 		uno::XInterface* xi = static_cast< uno::XInterface* >(
5278*cdf0e10cSrcweir 			aTbSymbol.GetItemData( nId ) );
5279*cdf0e10cSrcweir 
5280*cdf0e10cSrcweir 		if ( xi != NULL )
5281*cdf0e10cSrcweir 		{
5282*cdf0e10cSrcweir 			xi->release();
5283*cdf0e10cSrcweir 		}
5284*cdf0e10cSrcweir 	}
5285*cdf0e10cSrcweir }
5286*cdf0e10cSrcweir 
5287*cdf0e10cSrcweir uno::Reference< graphic::XGraphic> SvxIconSelectorDialog::GetSelectedIcon()
5288*cdf0e10cSrcweir {
5289*cdf0e10cSrcweir 	uno::Reference< graphic::XGraphic > result;
5290*cdf0e10cSrcweir 
5291*cdf0e10cSrcweir 	sal_uInt16 nId;
5292*cdf0e10cSrcweir 	for ( sal_uInt16 n = 0; n < aTbSymbol.GetItemCount(); n++ )
5293*cdf0e10cSrcweir 	{
5294*cdf0e10cSrcweir 		nId = aTbSymbol.GetItemId( n );
5295*cdf0e10cSrcweir 		if ( aTbSymbol.IsItemChecked( nId ) )
5296*cdf0e10cSrcweir 		{
5297*cdf0e10cSrcweir 			result = uno::Reference< graphic::XGraphic >(
5298*cdf0e10cSrcweir 				reinterpret_cast< graphic::XGraphic* >(
5299*cdf0e10cSrcweir 					aTbSymbol.GetItemData( nId ) ) );
5300*cdf0e10cSrcweir 		}
5301*cdf0e10cSrcweir 	}
5302*cdf0e10cSrcweir 
5303*cdf0e10cSrcweir 	return result;
5304*cdf0e10cSrcweir }
5305*cdf0e10cSrcweir 
5306*cdf0e10cSrcweir IMPL_LINK( SvxIconSelectorDialog, SelectHdl, ToolBox *, pToolBox )
5307*cdf0e10cSrcweir {
5308*cdf0e10cSrcweir 	(void)pToolBox;
5309*cdf0e10cSrcweir 
5310*cdf0e10cSrcweir 	sal_uInt16 nCount = aTbSymbol.GetItemCount();
5311*cdf0e10cSrcweir 
5312*cdf0e10cSrcweir 	for (sal_uInt16 n = 0; n < nCount; n++ )
5313*cdf0e10cSrcweir 	{
5314*cdf0e10cSrcweir 		sal_uInt16 nId = aTbSymbol.GetItemId( n );
5315*cdf0e10cSrcweir 
5316*cdf0e10cSrcweir 		if ( aTbSymbol.IsItemChecked( nId ) )
5317*cdf0e10cSrcweir 		{
5318*cdf0e10cSrcweir 			aTbSymbol.CheckItem( nId, sal_False );
5319*cdf0e10cSrcweir 		}
5320*cdf0e10cSrcweir 	}
5321*cdf0e10cSrcweir 
5322*cdf0e10cSrcweir 	sal_uInt16 nId = aTbSymbol.GetCurItemId();
5323*cdf0e10cSrcweir 	aTbSymbol.CheckItem( nId );
5324*cdf0e10cSrcweir 
5325*cdf0e10cSrcweir 	::rtl::OUString aSelImageText = aTbSymbol.GetItemText( nId );
5326*cdf0e10cSrcweir 	if ( m_xImportedImageManager->hasImage( GetImageType(), aSelImageText ) )
5327*cdf0e10cSrcweir 	{
5328*cdf0e10cSrcweir 		aBtnDelete.Enable( sal_True );
5329*cdf0e10cSrcweir 	}
5330*cdf0e10cSrcweir 	else
5331*cdf0e10cSrcweir 	{
5332*cdf0e10cSrcweir 		aBtnDelete.Enable( sal_False );
5333*cdf0e10cSrcweir 	}
5334*cdf0e10cSrcweir 
5335*cdf0e10cSrcweir 	return 0;
5336*cdf0e10cSrcweir }
5337*cdf0e10cSrcweir 
5338*cdf0e10cSrcweir IMPL_LINK( SvxIconSelectorDialog, ImportHdl, PushButton *, pButton )
5339*cdf0e10cSrcweir {
5340*cdf0e10cSrcweir 	(void)pButton;
5341*cdf0e10cSrcweir 
5342*cdf0e10cSrcweir 	sfx2::FileDialogHelper aImportDialog(
5343*cdf0e10cSrcweir 		css::ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW,
5344*cdf0e10cSrcweir         SFXWB_GRAPHIC | SFXWB_MULTISELECTION );
5345*cdf0e10cSrcweir 
5346*cdf0e10cSrcweir 	// disable the link checkbox in the dialog
5347*cdf0e10cSrcweir 	uno::Reference< css::ui::dialogs::XFilePickerControlAccess >
5348*cdf0e10cSrcweir 		xController( aImportDialog.GetFilePicker(), uno::UNO_QUERY);
5349*cdf0e10cSrcweir 	if ( xController.is() )
5350*cdf0e10cSrcweir 	{
5351*cdf0e10cSrcweir 		xController->enableControl(
5352*cdf0e10cSrcweir 			css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_LINK,
5353*cdf0e10cSrcweir 			sal_False);
5354*cdf0e10cSrcweir 	}
5355*cdf0e10cSrcweir 
5356*cdf0e10cSrcweir 	aImportDialog.SetCurrentFilter(
5357*cdf0e10cSrcweir 		String::CreateFromAscii( "PNG - Portable Network Graphic" ) );
5358*cdf0e10cSrcweir 
5359*cdf0e10cSrcweir 	if ( ERRCODE_NONE == aImportDialog.Execute() )
5360*cdf0e10cSrcweir 	{
5361*cdf0e10cSrcweir 		uno::Sequence< OUString > paths = aImportDialog.GetMPath();
5362*cdf0e10cSrcweir 		ImportGraphics ( paths );
5363*cdf0e10cSrcweir 	}
5364*cdf0e10cSrcweir 
5365*cdf0e10cSrcweir 	return 0;
5366*cdf0e10cSrcweir }
5367*cdf0e10cSrcweir 
5368*cdf0e10cSrcweir IMPL_LINK( SvxIconSelectorDialog, DeleteHdl, PushButton *, pButton )
5369*cdf0e10cSrcweir {
5370*cdf0e10cSrcweir 	(void)pButton;
5371*cdf0e10cSrcweir 
5372*cdf0e10cSrcweir 	OUString message = String( CUI_RES( RID_SVXSTR_DELETE_ICON_CONFIRM ) );
5373*cdf0e10cSrcweir 	bool ret = WarningBox( this, WinBits(WB_OK_CANCEL), message ).Execute();
5374*cdf0e10cSrcweir 
5375*cdf0e10cSrcweir 	if ( ret == RET_OK )
5376*cdf0e10cSrcweir 	{
5377*cdf0e10cSrcweir 		sal_uInt16 nCount = aTbSymbol.GetItemCount();
5378*cdf0e10cSrcweir 
5379*cdf0e10cSrcweir 		for (sal_uInt16 n = 0; n < nCount; n++ )
5380*cdf0e10cSrcweir 		{
5381*cdf0e10cSrcweir 			sal_uInt16 nId = aTbSymbol.GetItemId( n );
5382*cdf0e10cSrcweir 
5383*cdf0e10cSrcweir 			if ( aTbSymbol.IsItemChecked( nId ) )
5384*cdf0e10cSrcweir 			{
5385*cdf0e10cSrcweir 				::rtl::OUString aSelImageText = aTbSymbol.GetItemText( nId );
5386*cdf0e10cSrcweir 				uno::Sequence< OUString > URLs(1);
5387*cdf0e10cSrcweir 				URLs[0] = aSelImageText;
5388*cdf0e10cSrcweir 				aTbSymbol.RemoveItem( aTbSymbol.GetItemPos( nId ) );
5389*cdf0e10cSrcweir 				m_xImportedImageManager->removeImages( GetImageType(), URLs );
5390*cdf0e10cSrcweir 				uno::Reference< css::ui::XUIConfigurationPersistence >
5391*cdf0e10cSrcweir 					xConfigPersistence( m_xImportedImageManager, uno::UNO_QUERY );
5392*cdf0e10cSrcweir 				if ( xConfigPersistence.is() && xConfigPersistence->isModified() )
5393*cdf0e10cSrcweir 				{
5394*cdf0e10cSrcweir 					xConfigPersistence->store();
5395*cdf0e10cSrcweir 				}
5396*cdf0e10cSrcweir 				break;
5397*cdf0e10cSrcweir 			}
5398*cdf0e10cSrcweir 		}
5399*cdf0e10cSrcweir 	}
5400*cdf0e10cSrcweir 	return 0;
5401*cdf0e10cSrcweir }
5402*cdf0e10cSrcweir 
5403*cdf0e10cSrcweir bool SvxIconSelectorDialog::ReplaceGraphicItem(
5404*cdf0e10cSrcweir     const ::rtl::OUString& aURL )
5405*cdf0e10cSrcweir {
5406*cdf0e10cSrcweir 	uno::Sequence< OUString > URLs(1);
5407*cdf0e10cSrcweir 	uno::Sequence< uno::Reference<graphic::XGraphic > > aImportGraph( 1 );
5408*cdf0e10cSrcweir 	uno::Reference< css::ui::XUIConfigurationPersistence >
5409*cdf0e10cSrcweir 		xConfigPer( m_xImportedImageManager, uno::UNO_QUERY );
5410*cdf0e10cSrcweir 
5411*cdf0e10cSrcweir 	uno::Reference< graphic::XGraphic > xGraphic;
5412*cdf0e10cSrcweir 	uno::Sequence< beans::PropertyValue > aMediaProps( 1 );
5413*cdf0e10cSrcweir 	aMediaProps[0].Name = ::rtl::OUString::createFromAscii("URL");
5414*cdf0e10cSrcweir 	aMediaProps[0].Value <<= aURL;
5415*cdf0e10cSrcweir 
5416*cdf0e10cSrcweir     com::sun::star::awt::Size aSize;
5417*cdf0e10cSrcweir     bool bOK = sal_False;
5418*cdf0e10cSrcweir     try
5419*cdf0e10cSrcweir 	{
5420*cdf0e10cSrcweir         xGraphic = m_xGraphProvider->queryGraphic( aMediaProps );
5421*cdf0e10cSrcweir 
5422*cdf0e10cSrcweir 		uno::Reference< beans::XPropertySet > props =
5423*cdf0e10cSrcweir 			m_xGraphProvider->queryGraphicDescriptor( aMediaProps );
5424*cdf0e10cSrcweir 		uno::Any a = props->getPropertyValue(
5425*cdf0e10cSrcweir 			OUString::createFromAscii("SizePixel") );
5426*cdf0e10cSrcweir 		a >>= aSize;
5427*cdf0e10cSrcweir 		if (0 == aSize.Width || 0 == aSize.Height)
5428*cdf0e10cSrcweir 			return sal_False;
5429*cdf0e10cSrcweir 		else
5430*cdf0e10cSrcweir 			bOK = sal_True;
5431*cdf0e10cSrcweir     }
5432*cdf0e10cSrcweir     catch ( uno::Exception& )
5433*cdf0e10cSrcweir     {
5434*cdf0e10cSrcweir         return false;
5435*cdf0e10cSrcweir     }
5436*cdf0e10cSrcweir 
5437*cdf0e10cSrcweir     bool   bResult( false );
5438*cdf0e10cSrcweir     sal_uInt16 nCount = aTbSymbol.GetItemCount();
5439*cdf0e10cSrcweir 	for (sal_uInt16 n = 0; n < nCount; n++ )
5440*cdf0e10cSrcweir 	{
5441*cdf0e10cSrcweir 		sal_uInt16 nId = aTbSymbol.GetItemId( n );
5442*cdf0e10cSrcweir 
5443*cdf0e10cSrcweir 		if ( OUString( aTbSymbol.GetItemText( nId ) ) == aURL )
5444*cdf0e10cSrcweir 		{
5445*cdf0e10cSrcweir             try
5446*cdf0e10cSrcweir             {
5447*cdf0e10cSrcweir                 // replace/insert image with provided URL
5448*cdf0e10cSrcweir 		        aTbSymbol.RemoveItem( aTbSymbol.GetItemPos( nId ) );
5449*cdf0e10cSrcweir 		        aMediaProps[0].Value <<= aURL;
5450*cdf0e10cSrcweir 
5451*cdf0e10cSrcweir                 Image aImage( xGraphic );
5452*cdf0e10cSrcweir 				if ( bOK && ((aSize.Width != m_nExpectedSize) || (aSize.Height != m_nExpectedSize)) )
5453*cdf0e10cSrcweir 				{
5454*cdf0e10cSrcweir 					BitmapEx aBitmap = aImage.GetBitmapEx();
5455*cdf0e10cSrcweir 					BitmapEx aBitmapex = AutoScaleBitmap(aBitmap, m_nExpectedSize);
5456*cdf0e10cSrcweir 					aImage = Image( aBitmapex);
5457*cdf0e10cSrcweir 				}
5458*cdf0e10cSrcweir 				aTbSymbol.InsertItem( nId,aImage, aURL, 0, 0 ); //modify
5459*cdf0e10cSrcweir 
5460*cdf0e10cSrcweir                 xGraphic = aImage.GetXGraphic();
5461*cdf0e10cSrcweir 
5462*cdf0e10cSrcweir                 URLs[0] = aURL;
5463*cdf0e10cSrcweir 		        aImportGraph[ 0 ] = xGraphic;
5464*cdf0e10cSrcweir                 m_xImportedImageManager->replaceImages( GetImageType(), URLs, aImportGraph );
5465*cdf0e10cSrcweir                 xConfigPer->store();
5466*cdf0e10cSrcweir 
5467*cdf0e10cSrcweir                 bResult = true;
5468*cdf0e10cSrcweir                 break;
5469*cdf0e10cSrcweir             }
5470*cdf0e10cSrcweir             catch ( ::com::sun::star::uno::Exception& )
5471*cdf0e10cSrcweir             {
5472*cdf0e10cSrcweir                 break;
5473*cdf0e10cSrcweir             }
5474*cdf0e10cSrcweir 		}
5475*cdf0e10cSrcweir 	}
5476*cdf0e10cSrcweir 
5477*cdf0e10cSrcweir     return bResult;
5478*cdf0e10cSrcweir }
5479*cdf0e10cSrcweir 
5480*cdf0e10cSrcweir void SvxIconSelectorDialog::ImportGraphics(
5481*cdf0e10cSrcweir 	const uno::Sequence< OUString >& rPaths )
5482*cdf0e10cSrcweir {
5483*cdf0e10cSrcweir 	uno::Sequence< OUString > rejected( rPaths.getLength() );
5484*cdf0e10cSrcweir 	sal_Int32 rejectedCount = 0;
5485*cdf0e10cSrcweir 
5486*cdf0e10cSrcweir 	sal_uInt16 ret = 0;
5487*cdf0e10cSrcweir 	sal_Int32 aIndex;
5488*cdf0e10cSrcweir 	OUString aIconName;
5489*cdf0e10cSrcweir 	uno::Sequence< OUString > URLs(1);
5490*cdf0e10cSrcweir 	uno::Sequence< uno::Reference<graphic::XGraphic > > aImportGraph( 1 );
5491*cdf0e10cSrcweir 	uno::Sequence< beans::PropertyValue > aMediaProps( 1 );
5492*cdf0e10cSrcweir 	aMediaProps[0].Name = ::rtl::OUString::createFromAscii("URL");
5493*cdf0e10cSrcweir 	uno::Reference< css::ui::XUIConfigurationPersistence >
5494*cdf0e10cSrcweir 		xConfigPer( m_xImportedImageManager, uno::UNO_QUERY );
5495*cdf0e10cSrcweir 
5496*cdf0e10cSrcweir 	if ( rPaths.getLength() == 1 )
5497*cdf0e10cSrcweir 	{
5498*cdf0e10cSrcweir 		if ( m_xImportedImageManager->hasImage( GetImageType(), rPaths[0] ) )
5499*cdf0e10cSrcweir 		{
5500*cdf0e10cSrcweir 			aIndex = rPaths[0].lastIndexOf( '/' );
5501*cdf0e10cSrcweir 			aIconName = rPaths[0].copy( aIndex+1 );
5502*cdf0e10cSrcweir 			ret = SvxIconReplacementDialog( this, aIconName ).ShowDialog();
5503*cdf0e10cSrcweir 			if ( ret == 2 )
5504*cdf0e10cSrcweir 			{
5505*cdf0e10cSrcweir                 ReplaceGraphicItem( rPaths[0] );
5506*cdf0e10cSrcweir 			}
5507*cdf0e10cSrcweir 		}
5508*cdf0e10cSrcweir 		else
5509*cdf0e10cSrcweir 		{
5510*cdf0e10cSrcweir 			if ( ImportGraphic( rPaths[0] ) == sal_False )
5511*cdf0e10cSrcweir 			{
5512*cdf0e10cSrcweir 				rejected[0] = rPaths[0];
5513*cdf0e10cSrcweir 				rejectedCount = 1;
5514*cdf0e10cSrcweir 			}
5515*cdf0e10cSrcweir 		}
5516*cdf0e10cSrcweir 	}
5517*cdf0e10cSrcweir 	else
5518*cdf0e10cSrcweir 	{
5519*cdf0e10cSrcweir 		::rtl::OUString aSourcePath( rPaths[0] );
5520*cdf0e10cSrcweir         if ( rPaths[0].lastIndexOf( '/' ) != rPaths[0].getLength() -1 )
5521*cdf0e10cSrcweir             aSourcePath = rPaths[0] + ::rtl::OUString::createFromAscii( "/" );
5522*cdf0e10cSrcweir 
5523*cdf0e10cSrcweir 		for ( sal_Int32 i = 1; i < rPaths.getLength(); i++ )
5524*cdf0e10cSrcweir 		{
5525*cdf0e10cSrcweir             ::rtl::OUString aPath = aSourcePath + rPaths[i];
5526*cdf0e10cSrcweir 			if ( m_xImportedImageManager->hasImage( GetImageType(), aPath ) )
5527*cdf0e10cSrcweir 			{
5528*cdf0e10cSrcweir 				aIndex = rPaths[i].lastIndexOf( '/' );
5529*cdf0e10cSrcweir 				aIconName = rPaths[i].copy( aIndex+1 );
5530*cdf0e10cSrcweir 				ret = SvxIconReplacementDialog( this, aIconName, sal_True ).ShowDialog();
5531*cdf0e10cSrcweir 				if ( ret == 2 )
5532*cdf0e10cSrcweir 				{
5533*cdf0e10cSrcweir                     ReplaceGraphicItem( aPath );
5534*cdf0e10cSrcweir 				}
5535*cdf0e10cSrcweir 				else if ( ret == 5 )
5536*cdf0e10cSrcweir 				{
5537*cdf0e10cSrcweir 					for ( sal_Int32 k = i; k < rPaths.getLength(); k++ )
5538*cdf0e10cSrcweir 					{
5539*cdf0e10cSrcweir 						aPath = aSourcePath + rPaths[k];
5540*cdf0e10cSrcweir 						bool bHasReplaced = ReplaceGraphicItem( aPath );
5541*cdf0e10cSrcweir 
5542*cdf0e10cSrcweir                         if ( !bHasReplaced )
5543*cdf0e10cSrcweir 						{
5544*cdf0e10cSrcweir 							bool result = ImportGraphic( aPath );
5545*cdf0e10cSrcweir 							if ( result == sal_False )
5546*cdf0e10cSrcweir 							{
5547*cdf0e10cSrcweir 								rejected[ rejectedCount ] = rPaths[i];
5548*cdf0e10cSrcweir 								rejectedCount++;
5549*cdf0e10cSrcweir 							}
5550*cdf0e10cSrcweir 						}
5551*cdf0e10cSrcweir 					}
5552*cdf0e10cSrcweir 					break;
5553*cdf0e10cSrcweir 				}
5554*cdf0e10cSrcweir 			}
5555*cdf0e10cSrcweir 			else
5556*cdf0e10cSrcweir 			{
5557*cdf0e10cSrcweir                 bool result = ImportGraphic( aSourcePath + rPaths[i] );
5558*cdf0e10cSrcweir 				if ( result == sal_False )
5559*cdf0e10cSrcweir 				{
5560*cdf0e10cSrcweir 					rejected[ rejectedCount ] = rPaths[i];
5561*cdf0e10cSrcweir 					rejectedCount++;
5562*cdf0e10cSrcweir 				}
5563*cdf0e10cSrcweir 			}
5564*cdf0e10cSrcweir 		}
5565*cdf0e10cSrcweir 	}
5566*cdf0e10cSrcweir 
5567*cdf0e10cSrcweir 	if ( rejectedCount != 0 )
5568*cdf0e10cSrcweir 	{
5569*cdf0e10cSrcweir 		OUString message =OUString::createFromAscii("");
5570*cdf0e10cSrcweir 		OUString newLine = OUString::createFromAscii("\n");
5571*cdf0e10cSrcweir 		rtl::OUString fPath = OUString::createFromAscii("");
5572*cdf0e10cSrcweir 		if (rejectedCount > 1)
5573*cdf0e10cSrcweir   			fPath = rPaths[0].copy(8) + ::rtl::OUString::createFromAscii( "/" );
5574*cdf0e10cSrcweir 		for ( sal_Int32 i = 0; i < rejectedCount; i++ )
5575*cdf0e10cSrcweir 		{
5576*cdf0e10cSrcweir 			message += fPath + rejected[i];
5577*cdf0e10cSrcweir 			message += newLine;
5578*cdf0e10cSrcweir 		}
5579*cdf0e10cSrcweir 
5580*cdf0e10cSrcweir         SvxIconChangeDialog aDialog(this, message);
5581*cdf0e10cSrcweir 		aDialog.Execute();
5582*cdf0e10cSrcweir 	}
5583*cdf0e10cSrcweir }
5584*cdf0e10cSrcweir 
5585*cdf0e10cSrcweir bool SvxIconSelectorDialog::ImportGraphic( const OUString& aURL )
5586*cdf0e10cSrcweir {
5587*cdf0e10cSrcweir 	bool result = sal_False;
5588*cdf0e10cSrcweir 
5589*cdf0e10cSrcweir 	sal_uInt16 nId = m_nNextId;
5590*cdf0e10cSrcweir 	++m_nNextId;
5591*cdf0e10cSrcweir 
5592*cdf0e10cSrcweir 	uno::Sequence< beans::PropertyValue > aMediaProps( 1 );
5593*cdf0e10cSrcweir 	aMediaProps[0].Name = ::rtl::OUString::createFromAscii("URL");
5594*cdf0e10cSrcweir 
5595*cdf0e10cSrcweir 	uno::Reference< graphic::XGraphic > xGraphic;
5596*cdf0e10cSrcweir 	com::sun::star::awt::Size aSize;
5597*cdf0e10cSrcweir     bool bOK = sal_True;
5598*cdf0e10cSrcweir 	aMediaProps[0].Value <<= aURL;
5599*cdf0e10cSrcweir 	try
5600*cdf0e10cSrcweir 	{
5601*cdf0e10cSrcweir 		uno::Reference< beans::XPropertySet > props =
5602*cdf0e10cSrcweir 			m_xGraphProvider->queryGraphicDescriptor( aMediaProps );
5603*cdf0e10cSrcweir 
5604*cdf0e10cSrcweir 		uno::Any a = props->getPropertyValue(
5605*cdf0e10cSrcweir 			OUString::createFromAscii("SizePixel") );
5606*cdf0e10cSrcweir 
5607*cdf0e10cSrcweir 			xGraphic = m_xGraphProvider->queryGraphic( aMediaProps );
5608*cdf0e10cSrcweir 			if ( xGraphic.is() )
5609*cdf0e10cSrcweir 			{
5610*cdf0e10cSrcweir 				a >>= aSize;
5611*cdf0e10cSrcweir 				if ( 0 == aSize.Width || 0 == aSize.Height )
5612*cdf0e10cSrcweir 					bOK = sal_False;
5613*cdf0e10cSrcweir 
5614*cdf0e10cSrcweir 				Image aImage( xGraphic );
5615*cdf0e10cSrcweir 
5616*cdf0e10cSrcweir                 if ( bOK && ((aSize.Width != m_nExpectedSize) || (aSize.Height != m_nExpectedSize)) )
5617*cdf0e10cSrcweir 				{
5618*cdf0e10cSrcweir 					BitmapEx aBitmap = aImage.GetBitmapEx();
5619*cdf0e10cSrcweir 					BitmapEx aBitmapex = AutoScaleBitmap(aBitmap, m_nExpectedSize);
5620*cdf0e10cSrcweir 					aImage = Image( aBitmapex);
5621*cdf0e10cSrcweir 				}
5622*cdf0e10cSrcweir 				if ( bOK && !!aImage )
5623*cdf0e10cSrcweir 				{
5624*cdf0e10cSrcweir 					aTbSymbol.InsertItem( nId, aImage, aURL, 0, 0 );
5625*cdf0e10cSrcweir 
5626*cdf0e10cSrcweir                     xGraphic = aImage.GetXGraphic();
5627*cdf0e10cSrcweir                     xGraphic->acquire();
5628*cdf0e10cSrcweir 
5629*cdf0e10cSrcweir 					aTbSymbol.SetItemData(
5630*cdf0e10cSrcweir 						nId, static_cast< void * > ( xGraphic.get() ) );
5631*cdf0e10cSrcweir 					uno::Sequence< OUString > aImportURL( 1 );
5632*cdf0e10cSrcweir 					aImportURL[ 0 ] = aURL;
5633*cdf0e10cSrcweir 					uno::Sequence< uno::Reference<graphic::XGraphic > > aImportGraph( 1 );
5634*cdf0e10cSrcweir 					aImportGraph[ 0 ] = xGraphic;
5635*cdf0e10cSrcweir 					m_xImportedImageManager->insertImages( GetImageType(), aImportURL, aImportGraph );
5636*cdf0e10cSrcweir 					uno::Reference< css::ui::XUIConfigurationPersistence >
5637*cdf0e10cSrcweir 					xConfigPersistence( m_xImportedImageManager, uno::UNO_QUERY );
5638*cdf0e10cSrcweir 
5639*cdf0e10cSrcweir 					if ( xConfigPersistence.is() && xConfigPersistence->isModified() )
5640*cdf0e10cSrcweir 					{
5641*cdf0e10cSrcweir 						xConfigPersistence->store();
5642*cdf0e10cSrcweir 					}
5643*cdf0e10cSrcweir 
5644*cdf0e10cSrcweir 					result = sal_True;
5645*cdf0e10cSrcweir 				}
5646*cdf0e10cSrcweir 				else
5647*cdf0e10cSrcweir 				{
5648*cdf0e10cSrcweir 					OSL_TRACE("could not create Image from XGraphic");
5649*cdf0e10cSrcweir 				}
5650*cdf0e10cSrcweir 			}
5651*cdf0e10cSrcweir 			else
5652*cdf0e10cSrcweir 			{
5653*cdf0e10cSrcweir 				OSL_TRACE("could not get query XGraphic");
5654*cdf0e10cSrcweir 			}
5655*cdf0e10cSrcweir 	}
5656*cdf0e10cSrcweir 	catch( uno::Exception& e )
5657*cdf0e10cSrcweir 	{
5658*cdf0e10cSrcweir 		OSL_TRACE("Caught exception importing XGraphic: %s", PRTSTR(e.Message));
5659*cdf0e10cSrcweir 	}
5660*cdf0e10cSrcweir 	return result;
5661*cdf0e10cSrcweir }
5662*cdf0e10cSrcweir 
5663*cdf0e10cSrcweir /*******************************************************************************
5664*cdf0e10cSrcweir *
5665*cdf0e10cSrcweir * The SvxIconReplacementDialog class
5666*cdf0e10cSrcweir *
5667*cdf0e10cSrcweir *******************************************************************************/
5668*cdf0e10cSrcweir SvxIconReplacementDialog :: SvxIconReplacementDialog(
5669*cdf0e10cSrcweir 	Window *pWindow, const rtl::OUString& aMessage, bool /*bYestoAll*/ )
5670*cdf0e10cSrcweir 	:
5671*cdf0e10cSrcweir MessBox( pWindow, WB_DEF_YES, String( CUI_RES( RID_SVXSTR_REPLACE_ICON_CONFIRM ) ),  String( CUI_RES( RID_SVXSTR_REPLACE_ICON_WARNING ) ) )
5672*cdf0e10cSrcweir 
5673*cdf0e10cSrcweir {
5674*cdf0e10cSrcweir     SetImage( WarningBox::GetStandardImage() );
5675*cdf0e10cSrcweir 	SetMessText( ReplaceIconName( aMessage ) );
5676*cdf0e10cSrcweir 	RemoveButton( 1 );
5677*cdf0e10cSrcweir 	AddButton( BUTTON_YES, 2, 0 );
5678*cdf0e10cSrcweir 	AddButton( String( CUI_RES( RID_SVXSTR_YESTOALL ) ), 5, 0 );
5679*cdf0e10cSrcweir 	AddButton( BUTTON_NO, 3, 0 );
5680*cdf0e10cSrcweir 	AddButton( BUTTON_CANCEL, 4, 0 );
5681*cdf0e10cSrcweir }
5682*cdf0e10cSrcweir 
5683*cdf0e10cSrcweir SvxIconReplacementDialog :: SvxIconReplacementDialog(
5684*cdf0e10cSrcweir 	Window *pWindow, const rtl::OUString& aMessage )
5685*cdf0e10cSrcweir 	:
5686*cdf0e10cSrcweir MessBox( pWindow, WB_YES_NO_CANCEL, String( CUI_RES( RID_SVXSTR_REPLACE_ICON_CONFIRM ) ),  String( CUI_RES( RID_SVXSTR_REPLACE_ICON_WARNING ) ) )
5687*cdf0e10cSrcweir {
5688*cdf0e10cSrcweir     SetImage( WarningBox::GetStandardImage() );
5689*cdf0e10cSrcweir 	SetMessText( ReplaceIconName( aMessage ));
5690*cdf0e10cSrcweir }
5691*cdf0e10cSrcweir 
5692*cdf0e10cSrcweir rtl::OUString SvxIconReplacementDialog :: ReplaceIconName( const OUString& rMessage )
5693*cdf0e10cSrcweir {
5694*cdf0e10cSrcweir 	rtl::OUString name;
5695*cdf0e10cSrcweir 	rtl::OUString message = String( CUI_RES( RID_SVXSTR_REPLACE_ICON_WARNING ) );
5696*cdf0e10cSrcweir 	rtl::OUString placeholder = OUString::createFromAscii( "%ICONNAME" );
5697*cdf0e10cSrcweir 	sal_Int32 pos = message.indexOf( placeholder );
5698*cdf0e10cSrcweir 	if ( pos != -1 )
5699*cdf0e10cSrcweir 	{
5700*cdf0e10cSrcweir 		name = message.replaceAt(
5701*cdf0e10cSrcweir 			pos, placeholder.getLength(), rMessage );
5702*cdf0e10cSrcweir 	}
5703*cdf0e10cSrcweir 	return name;
5704*cdf0e10cSrcweir }
5705*cdf0e10cSrcweir 
5706*cdf0e10cSrcweir sal_uInt16 SvxIconReplacementDialog :: ShowDialog()
5707*cdf0e10cSrcweir {
5708*cdf0e10cSrcweir 	this->Execute();
5709*cdf0e10cSrcweir 	return ( this->GetCurButtonId() );
5710*cdf0e10cSrcweir }
5711*cdf0e10cSrcweir /*******************************************************************************
5712*cdf0e10cSrcweir *
5713*cdf0e10cSrcweir * The SvxIconChangeDialog class added for issue83555
5714*cdf0e10cSrcweir *
5715*cdf0e10cSrcweir *******************************************************************************/
5716*cdf0e10cSrcweir SvxIconChangeDialog::SvxIconChangeDialog(
5717*cdf0e10cSrcweir 	Window *pWindow, const rtl::OUString& aMessage)
5718*cdf0e10cSrcweir 	:
5719*cdf0e10cSrcweir 	ModalDialog	           ( pWindow, CUI_RES( MD_ICONCHANGE ) ),
5720*cdf0e10cSrcweir 	aFImageInfo            (this, CUI_RES( FI_INFO ) ),
5721*cdf0e10cSrcweir 	aBtnOK                 (this, CUI_RES(MD_BTN_OK)),
5722*cdf0e10cSrcweir 	aDescriptionLabel      (this, CUI_RES(FTCHGE_DESCRIPTION)),
5723*cdf0e10cSrcweir 	aLineEditDescription   (this, CUI_RES(EDT_ADDR))
5724*cdf0e10cSrcweir {
5725*cdf0e10cSrcweir 	FreeResource();
5726*cdf0e10cSrcweir 	aFImageInfo.SetImage(InfoBox::GetStandardImage());
5727*cdf0e10cSrcweir 	aLineEditDescription.SetControlBackground( GetSettings().GetStyleSettings().GetDialogColor() );
5728*cdf0e10cSrcweir 	aLineEditDescription.SetAutoScroll( sal_True );
5729*cdf0e10cSrcweir 	aLineEditDescription.EnableCursor( sal_False );
5730*cdf0e10cSrcweir 	aLineEditDescription.SetText(aMessage);
5731*cdf0e10cSrcweir }
5732*cdf0e10cSrcweir 
5733*cdf0e10cSrcweir BitmapEx SvxIconSelectorDialog::AutoScaleBitmap(BitmapEx & aBitmap, const long aStandardSize)
5734*cdf0e10cSrcweir {
5735*cdf0e10cSrcweir 	Point aEmptyPoint(0,0);
5736*cdf0e10cSrcweir 	sal_Int32 imgNewWidth = 0;
5737*cdf0e10cSrcweir 	sal_Int32 imgNewHeight = 0;
5738*cdf0e10cSrcweir 	double imgposX = 0;
5739*cdf0e10cSrcweir 	double imgposY = 0;
5740*cdf0e10cSrcweir     BitmapEx  aRet = aBitmap;
5741*cdf0e10cSrcweir 	double imgOldWidth = aRet.GetSizePixel().Width();
5742*cdf0e10cSrcweir 	double imgOldHeight =aRet.GetSizePixel().Height();
5743*cdf0e10cSrcweir 
5744*cdf0e10cSrcweir     Size aScaledSize;
5745*cdf0e10cSrcweir     if (imgOldWidth >= aStandardSize || imgOldHeight >= aStandardSize)
5746*cdf0e10cSrcweir 	{
5747*cdf0e10cSrcweir 		if (imgOldWidth >= imgOldHeight)
5748*cdf0e10cSrcweir 		{
5749*cdf0e10cSrcweir 			imgNewWidth = aStandardSize;
5750*cdf0e10cSrcweir 			imgNewHeight = sal_Int32(imgOldHeight / (imgOldWidth / aStandardSize) + 0.5);
5751*cdf0e10cSrcweir 			imgposX = 0;
5752*cdf0e10cSrcweir 			imgposY = (aStandardSize - (imgOldHeight / (imgOldWidth / aStandardSize) + 0.5)) / 2 + 0.5;
5753*cdf0e10cSrcweir 		}
5754*cdf0e10cSrcweir 		else
5755*cdf0e10cSrcweir 		{
5756*cdf0e10cSrcweir 			imgNewHeight = aStandardSize;
5757*cdf0e10cSrcweir 			imgNewWidth = sal_Int32(imgOldWidth / (imgOldHeight / aStandardSize) + 0.5);
5758*cdf0e10cSrcweir 			imgposY = 0;
5759*cdf0e10cSrcweir 			imgposX = (aStandardSize - (imgOldWidth / (imgOldHeight / aStandardSize) + 0.5)) / 2 + 0.5;
5760*cdf0e10cSrcweir 		}
5761*cdf0e10cSrcweir 
5762*cdf0e10cSrcweir 		aScaledSize = Size( imgNewWidth, imgNewHeight );
5763*cdf0e10cSrcweir         aRet.Scale( aScaledSize, BMP_SCALE_INTERPOLATE );
5764*cdf0e10cSrcweir 	}
5765*cdf0e10cSrcweir 	else
5766*cdf0e10cSrcweir 	{
5767*cdf0e10cSrcweir 		imgposX = (aStandardSize - imgOldWidth) / 2 + 0.5;
5768*cdf0e10cSrcweir 		imgposY = (aStandardSize - imgOldHeight) / 2 + 0.5;
5769*cdf0e10cSrcweir 	}
5770*cdf0e10cSrcweir 
5771*cdf0e10cSrcweir     Size aBmpSize = aRet.GetSizePixel();
5772*cdf0e10cSrcweir     Size aStdSize( aStandardSize, aStandardSize );
5773*cdf0e10cSrcweir     Rectangle aRect(aEmptyPoint, aStdSize );
5774*cdf0e10cSrcweir 
5775*cdf0e10cSrcweir     VirtualDevice aVirDevice( *Application::GetDefaultDevice(), 0, 1 );
5776*cdf0e10cSrcweir 	aVirDevice.SetOutputSizePixel( aStdSize );
5777*cdf0e10cSrcweir 	aVirDevice.SetFillColor( COL_TRANSPARENT );
5778*cdf0e10cSrcweir     aVirDevice.SetLineColor( COL_TRANSPARENT );
5779*cdf0e10cSrcweir 
5780*cdf0e10cSrcweir     //draw a rect into virDevice
5781*cdf0e10cSrcweir 	aVirDevice.DrawRect( aRect );
5782*cdf0e10cSrcweir 	Point aPointPixel( (long)imgposX, (long)imgposY );
5783*cdf0e10cSrcweir 	aVirDevice.DrawBitmapEx( aPointPixel, aRet );
5784*cdf0e10cSrcweir 	aRet = aVirDevice.GetBitmapEx( aEmptyPoint, aStdSize );
5785*cdf0e10cSrcweir 
5786*cdf0e10cSrcweir 	return aRet;
5787*cdf0e10cSrcweir }
5788