masterfix DEV300: #i10000# build fix
[LibreOffice.git] / cui / source / customize / cfg.cxx
blob1da522170ab29df024ccacfc187c4e7639217ea7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
31 #include <stdlib.h>
32 #include <time.h>
34 #ifndef _HELP_HXX //autogen
35 #include <vcl/help.hxx>
36 #endif
37 #ifndef _MSGBOX_HXX //autogen
38 #include <vcl/msgbox.hxx>
39 #endif
40 #include <vcl/decoview.hxx>
41 #include <vcl/toolbox.hxx>
42 #include <vcl/scrbar.hxx>
44 //added for issue73355
45 //#ifndef _SV_SVDATA_HXX
46 //#include <vcl/svdata.hxx>
47 //#endif
48 //issue73355 ends
50 #include <sfx2/app.hxx>
51 #include <sfx2/sfxdlg.hxx>
52 #include <sfx2/viewfrm.hxx>
53 #include <sfx2/viewsh.hxx>
54 #include <sfx2/msg.hxx>
55 #include <sfx2/msgpool.hxx>
56 #include <sfx2/mnumgr.hxx>
57 #include <sfx2/minfitem.hxx>
58 #include <sfx2/objsh.hxx>
59 #include <sfx2/request.hxx>
60 #include <sfx2/filedlghelper.hxx>
61 #include <svl/stritem.hxx>
62 #include <svtools/miscopt.hxx>
63 #include <tools/diagnose_ex.h>
64 #include <toolkit/unohlp.hxx>
66 #include <algorithm>
67 //add
68 #include <cuires.hrc>
69 #include "cfg.hrc"
70 #include "helpid.hrc"
72 #include "acccfg.hxx"
73 #include "cfg.hxx"
74 #include "eventdlg.hxx"
75 #include <dialmgr.hxx>
77 #include <comphelper/documentinfo.hxx>
78 #include <comphelper/processfactory.hxx>
79 #ifndef _UNOTOOLS_CONFIGMGR_HXX_
80 #include <unotools/configmgr.hxx>
81 #endif
82 #include <com/sun/star/ui/ItemType.hpp>
83 #include <com/sun/star/ui/ItemStyle.hpp>
84 #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
85 #include <com/sun/star/frame/XController.hpp>
86 #include <com/sun/star/frame/XDesktop.hpp>
87 #include <com/sun/star/ui/XUIConfiguration.hpp>
88 #include <com/sun/star/ui/XUIConfigurationListener.hpp>
89 #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
90 #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
91 #include <com/sun/star/ui/XUIConfigurationStorage.hpp>
92 #include <com/sun/star/ui/XModuleUIConfigurationManager.hpp>
93 #include <com/sun/star/ui/XUIElement.hpp>
94 #ifndef _COM_SUN_STAR_UI_UIElementType_HPP_
95 #include <com/sun/star/ui/UIElementType.hpp>
96 #endif
97 #include <com/sun/star/ui/ImageType.hpp>
98 #include <com/sun/star/frame/XLayoutManager.hpp>
99 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
100 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
101 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
102 #include <com/sun/star/frame/XFramesSupplier.hpp>
103 #include <com/sun/star/frame/XFrames.hpp>
104 #include <com/sun/star/frame/FrameSearchFlag.hpp>
105 #include <com/sun/star/embed/ElementModes.hpp>
107 #include "dlgname.hxx"
109 #define PRTSTR(x) rtl::OUStringToOString(x, RTL_TEXTENCODING_ASCII_US).pData->buffer
111 #define ENTRY_HEIGHT 16
113 static const char ITEM_DESCRIPTOR_COMMANDURL[] = "CommandURL";
114 static const char ITEM_DESCRIPTOR_CONTAINER[] = "ItemDescriptorContainer";
115 static const char ITEM_DESCRIPTOR_LABEL[] = "Label";
116 static const char ITEM_DESCRIPTOR_TYPE[] = "Type";
117 static const char ITEM_DESCRIPTOR_STYLE[] = "Style";
118 static const char ITEM_DESCRIPTOR_ISVISIBLE[] = "IsVisible";
119 static const char ITEM_DESCRIPTOR_RESOURCEURL[] = "ResourceURL";
120 static const char ITEM_DESCRIPTOR_UINAME[] = "UIName";
122 static const char ITEM_MENUBAR_URL[] = "private:resource/menubar/menubar";
123 static const char ITEM_TOOLBAR_URL[] = "private:resource/toolbar/";
125 static const char CUSTOM_TOOLBAR_STR[] = "custom_toolbar_";
126 static const char CUSTOM_MENU_STR[] = "vnd.openoffice.org:CustomMenu";
128 static const char __FAR_DATA pSeparatorStr[] =
129 "----------------------------------";
130 static const char __FAR_DATA pMenuSeparatorStr[] = " | ";
132 #ifdef _MSC_VER
133 #pragma warning (disable:4355)
134 #endif
136 using rtl::OUString;
137 namespace css = com::sun::star;
138 namespace uno = com::sun::star::uno;
139 namespace frame = com::sun::star::frame;
140 namespace lang = com::sun::star::lang;
141 namespace container = com::sun::star::container;
142 namespace beans = com::sun::star::beans;
143 namespace graphic = com::sun::star::graphic;
145 #if OSL_DEBUG_LEVEL > 1
147 void printPropertySet(
148 const OUString& prefix,
149 const uno::Reference< beans::XPropertySet >& xPropSet )
151 uno::Reference< beans::XPropertySetInfo > xPropSetInfo =
152 xPropSet->getPropertySetInfo();
154 uno::Sequence< beans::Property > aPropDetails =
155 xPropSetInfo->getProperties();
157 OSL_TRACE("printPropertySet: %d properties", aPropDetails.getLength());
159 for ( sal_Int32 i = 0; i < aPropDetails.getLength(); i++ )
161 OUString tmp;
162 sal_Int32 ival;
164 uno::Any a = xPropSet->getPropertyValue( aPropDetails[i].Name );
166 if ( ( a >>= tmp ) /* && tmp.getLength() != 0 */ )
168 OSL_TRACE("%s: Got property: %s = %s",
169 PRTSTR(prefix), PRTSTR(aPropDetails[i].Name), PRTSTR(tmp));
171 else if ( ( a >>= ival ) )
173 OSL_TRACE("%s: Got property: %s = %d",
174 PRTSTR(prefix), PRTSTR(aPropDetails[i].Name), PRTSTR(tmp));
176 else
178 OSL_TRACE("%s: Got property: %s of type %s",
179 PRTSTR(prefix), PRTSTR(aPropDetails[i].Name), PRTSTR(a.getValueTypeName()));
184 void printProperties(
185 const OUString& prefix,
186 const uno::Sequence< beans::PropertyValue >& aProp )
188 for ( sal_Int32 i = 0; i < aProp.getLength(); i++ )
190 OUString tmp;
192 aProp[i].Value >>= tmp;
194 OSL_TRACE("%s: Got property: %s = %s",
195 PRTSTR(prefix), PRTSTR(aProp[i].Name), PRTSTR(tmp));
199 void printEntries(SvxEntries* entries)
201 SvxEntries::const_iterator iter = entries->begin();
203 for ( ; iter != entries->end(); iter++ )
205 SvxConfigEntry* entry = *iter;
207 OSL_TRACE("printEntries: %s", PRTSTR(entry->GetName()));
211 #endif
213 OUString
214 stripHotKey( const OUString& str )
216 sal_Int32 index = str.indexOf( '~' );
217 if ( index == -1 )
219 return str;
221 else
223 return str.replaceAt( index, 1, OUString() );
227 OUString replaceSaveInName(
228 const OUString& rMessage,
229 const OUString& rSaveInName )
231 OUString name;
232 OUString placeholder = OUString::createFromAscii( "%SAVE IN SELECTION%" );
234 sal_Int32 pos = rMessage.indexOf( placeholder );
236 if ( pos != -1 )
238 name = rMessage.replaceAt(
239 pos, placeholder.getLength(), rSaveInName );
241 else
243 // don't change the message
246 return name;
249 OUString
250 replaceSixteen( const OUString& str, sal_Int32 nReplacement )
252 OUString result( str );
253 OUString sixteen = OUString::valueOf( (sal_Int32)16 );
254 OUString expected = OUString::valueOf( nReplacement );
256 sal_Int32 len = sixteen.getLength();
257 sal_Int32 index = result.indexOf( sixteen );
259 while ( index != -1 )
261 result = result.replaceAt( index, len, expected );
262 index = result.indexOf( sixteen, index );
265 return result;
268 OUString
269 generateCustomName(
270 const OUString& prefix,
271 SvxEntries* entries,
272 sal_Int32 suffix = 1 )
274 // find and replace the %n placeholder in the prefix string
275 OUString name;
276 OUString placeholder = OUString::createFromAscii( "%n" );
278 sal_Int32 pos = prefix.indexOf(
279 OUString::createFromAscii( "%n" ) );
281 if ( pos != -1 )
283 name = prefix.replaceAt(
284 pos, placeholder.getLength(), OUString::valueOf( suffix ) );
286 else
288 // no placeholder found so just append the suffix
289 name = prefix + OUString::valueOf( suffix );
292 // now check is there is an already existing entry with this name
293 SvxEntries::const_iterator iter = entries->begin();
295 SvxConfigEntry* pEntry;
296 while ( iter != entries->end() )
298 pEntry = *iter;
300 if ( name.equals( pEntry->GetName() ) )
302 break;
304 iter++;
307 if ( iter != entries->end() )
309 // name already exists so try the next number up
310 return generateCustomName( prefix, entries, ++suffix );
313 return name;
316 sal_uInt32 generateRandomValue()
318 srand( unsigned( time( NULL ) ));
319 return sal_uInt32( rand() );
322 OUString
323 generateCustomURL(
324 SvxEntries* entries )
326 OUString url = OUString::createFromAscii( ITEM_TOOLBAR_URL );
327 url += OUString::createFromAscii( CUSTOM_TOOLBAR_STR );
329 // use a random number to minimize possible clash with existing custom toolbars
330 url += OUString::valueOf( sal_Int64( generateRandomValue() ), 16 );
332 // now check is there is an already existing entry with this url
333 SvxEntries::const_iterator iter = entries->begin();
335 SvxConfigEntry* pEntry;
336 while ( iter != entries->end() )
338 pEntry = *iter;
340 if ( url.equals( pEntry->GetCommand() ) )
342 break;
344 iter++;
347 if ( iter != entries->end() )
349 // url already exists so try the next number up
350 return generateCustomURL( entries );
353 return url;
356 OUString
357 generateCustomMenuURL(
358 SvxEntries* entries,
359 sal_Int32 suffix = 1 )
361 OUString url = OUString::createFromAscii( CUSTOM_MENU_STR );
362 url += OUString::valueOf( suffix );
364 // now check is there is an already existing entry with this url
365 SvxEntries::const_iterator iter = entries->begin();
367 SvxConfigEntry* pEntry;
368 while ( iter != entries->end() )
370 pEntry = *iter;
372 if ( url.equals( pEntry->GetCommand() ) )
374 break;
376 iter++;
379 if ( iter != entries->end() )
381 // url already exists so try the next number up
382 return generateCustomMenuURL( entries, ++suffix );
385 return url;
388 static sal_Int16 theImageType =
389 css::ui::ImageType::COLOR_NORMAL |
390 css::ui::ImageType::SIZE_DEFAULT;
392 void InitImageType()
394 theImageType =
395 css::ui::ImageType::COLOR_NORMAL |
396 css::ui::ImageType::SIZE_DEFAULT;
398 if ( SvtMiscOptions().AreCurrentSymbolsLarge() )
400 theImageType |= css::ui::ImageType::SIZE_LARGE;
403 Window* topwin = Application::GetActiveTopWindow();
404 if ( topwin != NULL &&
405 topwin->GetSettings().GetStyleSettings().GetHighContrastMode() )
407 theImageType |= css::ui::ImageType::COLOR_HIGHCONTRAST;
411 sal_Int16 GetImageType()
413 return theImageType;
416 void RemoveEntry( SvxEntries* pEntries, SvxConfigEntry* pChildEntry )
418 SvxEntries::iterator iter = pEntries->begin();
420 while ( iter != pEntries->end() )
422 if ( pChildEntry == *iter )
424 pEntries->erase( iter );
425 break;
427 iter++;
431 bool
432 SvxConfigPage::CanConfig( const OUString& aModuleId )
434 OSL_TRACE("SupportsDocumentConfig: %s", PRTSTR(aModuleId));
436 if ( aModuleId.equalsAscii( "com.sun.star.script.BasicIDE" )
437 || aModuleId.equalsAscii( "com.sun.star.frame.Bibliography" )
440 return sal_False;
442 return sal_True;
445 OUString GetModuleName( const OUString& aModuleId )
447 if ( aModuleId.equalsAscii( "com.sun.star.text.TextDocument" ) ||
448 aModuleId.equalsAscii( "com.sun.star.text.GlobalDocument" ) )
449 return OUString::createFromAscii("Writer");
450 else if ( aModuleId.equalsAscii( "com.sun.star.text.WebDocument" ) )
451 return OUString::createFromAscii("Writer/Web");
452 else if ( aModuleId.equalsAscii( "com.sun.star.drawing.DrawingDocument" ) )
453 return OUString::createFromAscii("Draw");
454 else if ( aModuleId.equalsAscii( "com.sun.star.presentation.PresentationDocument" ) )
455 return OUString::createFromAscii("Impress");
456 else if ( aModuleId.equalsAscii( "com.sun.star.sheet.SpreadsheetDocument" ) )
457 return OUString::createFromAscii("Calc");
458 else if ( aModuleId.equalsAscii( "com.sun.star.script.BasicIDE" ) )
459 return OUString::createFromAscii("Basic");
460 else if ( aModuleId.equalsAscii( "com.sun.star.formula.FormulaProperties" ) )
461 return OUString::createFromAscii("Math");
462 else if ( aModuleId.equalsAscii( "com.sun.star.sdb.RelationDesign" ) )
463 return OUString::createFromAscii("Relation Design");
464 else if ( aModuleId.equalsAscii( "com.sun.star.sdb.QueryDesign" ) )
465 return OUString::createFromAscii("Query Design");
466 else if ( aModuleId.equalsAscii( "com.sun.star.sdb.TableDesign" ) )
467 return OUString::createFromAscii("Table Design");
468 else if ( aModuleId.equalsAscii( "com.sun.star.sdb.DataSourceBrowser" ) )
469 return OUString::createFromAscii("Data Source Browser" );
470 else if ( aModuleId.equalsAscii( "com.sun.star.sdb.DatabaseDocument" ) )
471 return OUString::createFromAscii("Database" );
473 return ::rtl::OUString();
476 OUString GetUIModuleName( const OUString& aModuleId, const uno::Reference< css::frame::XModuleManager >& rModuleManager )
478 OUString aModuleUIName;
480 if ( rModuleManager.is() )
482 uno::Reference< css::container::XNameAccess > xNameAccess( rModuleManager, uno::UNO_QUERY );
483 if ( xNameAccess.is() )
487 uno::Any a = xNameAccess->getByName( aModuleId );
488 uno::Sequence< beans::PropertyValue > aSeq;
490 if ( a >>= aSeq )
492 OUString aUIName;
493 for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ )
495 if ( aSeq[i].Name.equalsAscii( "ooSetupFactoryUIName" ))
497 aSeq[i].Value >>= aModuleUIName;
498 break;
503 catch ( uno::RuntimeException& e )
505 throw e;
507 catch ( uno::Exception& )
513 if ( aModuleUIName.getLength() == 0 )
514 aModuleUIName = GetModuleName( aModuleId );
516 return aModuleUIName;
519 bool GetMenuItemData(
520 const uno::Reference< container::XIndexAccess >& rItemContainer,
521 sal_Int32 nIndex,
522 OUString& rCommandURL,
523 OUString& rLabel,
524 sal_uInt16& rType,
525 uno::Reference< container::XIndexAccess >& rSubMenu )
529 uno::Sequence< beans::PropertyValue > aProp;
530 if ( rItemContainer->getByIndex( nIndex ) >>= aProp )
532 for ( sal_Int32 i = 0; i < aProp.getLength(); i++ )
534 if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_COMMANDURL ))
536 aProp[i].Value >>= rCommandURL;
538 else if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_CONTAINER ))
540 aProp[i].Value >>= rSubMenu;
542 else if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_LABEL ))
544 aProp[i].Value >>= rLabel;
546 else if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_TYPE ))
548 aProp[i].Value >>= rType;
552 return sal_True;
555 catch ( ::com::sun::star::lang::IndexOutOfBoundsException& )
559 return sal_False;
562 bool GetToolbarItemData(
563 const uno::Reference< container::XIndexAccess >& rItemContainer,
564 sal_Int32 nIndex,
565 OUString& rCommandURL,
566 OUString& rLabel,
567 sal_uInt16& rType,
568 sal_Bool& rIsVisible,
569 sal_Int32& rStyle,
570 uno::Reference< container::XIndexAccess >& rSubMenu )
574 uno::Sequence< beans::PropertyValue > aProp;
575 if ( rItemContainer->getByIndex( nIndex ) >>= aProp )
577 for ( sal_Int32 i = 0; i < aProp.getLength(); i++ )
579 if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_COMMANDURL ))
581 aProp[i].Value >>= rCommandURL;
583 if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_STYLE ))
585 aProp[i].Value >>= rStyle;
587 else if (aProp[i].Name.equalsAscii(ITEM_DESCRIPTOR_CONTAINER))
589 aProp[i].Value >>= rSubMenu;
591 else if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_LABEL ))
593 aProp[i].Value >>= rLabel;
595 else if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_TYPE ))
597 aProp[i].Value >>= rType;
599 else if (aProp[i].Name.equalsAscii(ITEM_DESCRIPTOR_ISVISIBLE))
601 aProp[i].Value >>= rIsVisible;
605 return sal_True;
608 catch ( ::com::sun::star::lang::IndexOutOfBoundsException& )
612 return sal_False;
615 uno::Sequence< beans::PropertyValue >
616 ConvertSvxConfigEntry(
617 const uno::Reference< container::XNameAccess >& xCommandToLabelMap,
618 const SvxConfigEntry* pEntry )
620 static const OUString aDescriptorCommandURL (
621 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_COMMANDURL ) );
623 static const OUString aDescriptorType(
624 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_TYPE ) );
626 static const OUString aDescriptorLabel(
627 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_LABEL ) );
629 static const OUString aDescriptorContainer(
630 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_CONTAINER ) );
632 uno::Sequence< beans::PropertyValue > aPropSeq( 3 );
634 aPropSeq[0].Name = aDescriptorCommandURL;
635 aPropSeq[0].Value <<= rtl::OUString( pEntry->GetCommand() );
637 aPropSeq[1].Name = aDescriptorType;
638 aPropSeq[1].Value <<= css::ui::ItemType::DEFAULT;
640 // If the name has not been changed and the name is the same as
641 // in the default command to label map then the label can be stored
642 // as an empty string.
643 // It will be initialised again later using the command to label map.
644 aPropSeq[2].Name = aDescriptorLabel;
645 if ( pEntry->HasChangedName() == sal_False && pEntry->GetCommand().getLength() )
647 sal_Bool isDefaultName = sal_False;
650 uno::Any a( xCommandToLabelMap->getByName( pEntry->GetCommand() ) );
651 uno::Sequence< beans::PropertyValue > tmpPropSeq;
652 if ( a >>= tmpPropSeq )
654 for ( sal_Int32 i = 0; i < tmpPropSeq.getLength(); i++ )
656 if ( tmpPropSeq[i].Name.equals( aDescriptorLabel ) )
658 OUString tmpLabel;
659 tmpPropSeq[i].Value >>= tmpLabel;
661 if ( tmpLabel.equals( pEntry->GetName() ) )
663 isDefaultName = sal_True;
666 break;
671 catch ( container::NoSuchElementException& )
673 // isDefaultName is left as FALSE
676 if ( isDefaultName )
678 aPropSeq[2].Value <<= rtl::OUString();
680 else
682 aPropSeq[2].Value <<= rtl::OUString( pEntry->GetName() );
685 else
687 aPropSeq[2].Value <<= rtl::OUString( pEntry->GetName() );
690 return aPropSeq;
693 uno::Sequence< beans::PropertyValue >
694 ConvertToolbarEntry(
695 const uno::Reference< container::XNameAccess >& xCommandToLabelMap,
696 const SvxConfigEntry* pEntry )
698 static const OUString aDescriptorCommandURL (
699 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_COMMANDURL ) );
701 static const OUString aDescriptorType(
702 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_TYPE ) );
704 static const OUString aDescriptorLabel(
705 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_LABEL ) );
707 static const OUString aDescriptorContainer(
708 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_CONTAINER ) );
710 static const OUString aIsVisible(
711 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_ISVISIBLE ) );
713 uno::Sequence< beans::PropertyValue > aPropSeq( 4 );
715 aPropSeq[0].Name = aDescriptorCommandURL;
716 aPropSeq[0].Value <<= rtl::OUString( pEntry->GetCommand() );
718 aPropSeq[1].Name = aDescriptorType;
719 aPropSeq[1].Value <<= css::ui::ItemType::DEFAULT;
721 // If the name has not been changed and the name is the same as
722 // in the default command to label map then the label can be stored
723 // as an empty string.
724 // It will be initialised again later using the command to label map.
725 aPropSeq[2].Name = aDescriptorLabel;
726 if ( pEntry->HasChangedName() == sal_False && pEntry->GetCommand().getLength() )
728 sal_Bool isDefaultName = sal_False;
731 uno::Any a( xCommandToLabelMap->getByName( pEntry->GetCommand() ) );
732 uno::Sequence< beans::PropertyValue > tmpPropSeq;
733 if ( a >>= tmpPropSeq )
735 for ( sal_Int32 i = 0; i < tmpPropSeq.getLength(); i++ )
737 if ( tmpPropSeq[i].Name.equals( aDescriptorLabel ) )
739 OUString tmpLabel;
740 tmpPropSeq[i].Value >>= tmpLabel;
742 if ( tmpLabel.equals( pEntry->GetName() ) )
744 isDefaultName = sal_True;
747 break;
752 catch ( container::NoSuchElementException& )
754 // isDefaultName is left as FALSE
757 if ( isDefaultName )
759 aPropSeq[2].Value <<= rtl::OUString();
761 else
763 aPropSeq[2].Value <<= rtl::OUString( pEntry->GetName() );
766 else
768 aPropSeq[2].Value <<= rtl::OUString( pEntry->GetName() );
771 aPropSeq[3].Name = aIsVisible;
772 aPropSeq[3].Value <<= pEntry->IsVisible();
774 return aPropSeq;
777 SfxTabPage *CreateSvxMenuConfigPage( Window *pParent, const SfxItemSet& rSet )
779 return new SvxMenuConfigPage( pParent, rSet );
782 SfxTabPage *CreateKeyboardConfigPage( Window *pParent, const SfxItemSet& rSet )
784 return new SfxAcceleratorConfigPage( pParent, rSet );
787 SfxTabPage *CreateSvxToolbarConfigPage( Window *pParent, const SfxItemSet& rSet )
789 return new SvxToolbarConfigPage( pParent, rSet );
792 SfxTabPage *CreateSvxEventConfigPage( Window *pParent, const SfxItemSet& rSet )
794 return new SvxEventConfigPage( pParent, rSet, SvxEventConfigPage::EarlyInit() );
797 sal_Bool impl_showKeyConfigTabPage( const css::uno::Reference< css::frame::XFrame >& xFrame )
799 static ::rtl::OUString SERVICENAME_MODULEMANAGER = ::rtl::OUString::createFromAscii("com.sun.star.frame.ModuleManager");
800 static ::rtl::OUString SERVICENAME_DESKTOP = ::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop" );
801 static ::rtl::OUString MODULEID_STARTMODULE = ::rtl::OUString::createFromAscii("com.sun.star.frame.StartModule" );
805 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
806 css::uno::Reference< css::frame::XFramesSupplier > xDesktop(xSMGR->createInstance(SERVICENAME_DESKTOP), css::uno::UNO_QUERY_THROW);
807 css::uno::Reference< css::frame::XModuleManager > xMM (xSMGR->createInstance(SERVICENAME_MODULEMANAGER), css::uno::UNO_QUERY_THROW);
809 if (xMM.is() && xFrame.is())
811 ::rtl::OUString sModuleId = xMM->identify(xFrame);
812 if (
813 ( sModuleId.getLength() ) &&
814 (!sModuleId.equals(MODULEID_STARTMODULE))
816 return sal_True;
819 catch(const css::uno::Exception&)
822 return sal_False;
825 /******************************************************************************
827 * SvxConfigDialog is the configuration dialog which is brought up from the
828 * Tools menu. It includes tabs for customizing menus, toolbars, events and
829 * key bindings.
831 *****************************************************************************/
832 SvxConfigDialog::SvxConfigDialog(
833 Window * pParent, const SfxItemSet* pSet_ )
835 SfxTabDialog( pParent,
836 CUI_RES( RID_SVXDLG_CUSTOMIZE ), pSet_ )
838 FreeResource();
840 InitImageType();
842 AddTabPage( RID_SVXPAGE_MENUS, CreateSvxMenuConfigPage, NULL );
843 AddTabPage( RID_SVXPAGE_KEYBOARD, CreateKeyboardConfigPage, NULL );
844 AddTabPage( RID_SVXPAGE_TOOLBARS, CreateSvxToolbarConfigPage, NULL );
845 AddTabPage( RID_SVXPAGE_EVENTS, CreateSvxEventConfigPage, NULL );
847 const SfxPoolItem* pItem =
848 pSet_->GetItem( pSet_->GetPool()->GetWhich( SID_CONFIG ) );
850 if ( pItem )
852 OUString text = ((const SfxStringItem*)pItem)->GetValue();
854 if (text.indexOf(OUString::createFromAscii(ITEM_TOOLBAR_URL)) == 0)
856 SetCurPageId( RID_SVXPAGE_TOOLBARS );
861 void SvxConfigDialog::SetFrame(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame)
863 m_xFrame = xFrame;
865 if (!impl_showKeyConfigTabPage( xFrame ))
866 RemoveTabPage( RID_SVXPAGE_KEYBOARD );
869 SvxConfigDialog::~SvxConfigDialog()
873 short SvxConfigDialog::Ok()
875 return SfxTabDialog::Ok();
878 void SvxConfigDialog::PageCreated( sal_uInt16 nId, SfxTabPage& rPage )
880 (void)rPage;
882 switch ( nId )
884 case RID_SVXPAGE_MENUS:
885 case RID_SVXPAGE_TOOLBARS:
886 case RID_SVXPAGE_KEYBOARD:
888 rPage.SetFrame(m_xFrame);
890 break;
891 case RID_SVXPAGE_EVENTS:
893 dynamic_cast< SvxEventConfigPage& >( rPage ).LateInit( m_xFrame );
895 break;
896 default:
897 break;
901 /******************************************************************************
903 * The SaveInData class is used to hold data for entries in the Save In
904 * ListBox controls in the menu and toolbar tabs
906 ******************************************************************************/
908 // Initialize static variable which holds default XImageManager
909 uno::Reference< css::ui::XImageManager>* SaveInData::xDefaultImgMgr = NULL;
911 SaveInData::SaveInData(
912 const uno::Reference< css::ui::XUIConfigurationManager >& xCfgMgr,
913 const uno::Reference< css::ui::XUIConfigurationManager >& xParentCfgMgr,
914 const OUString& aModuleId,
915 bool isDocConfig )
917 bModified( sal_False ),
918 bDocConfig( isDocConfig ),
919 bReadOnly( sal_False ),
920 m_xCfgMgr( xCfgMgr ),
921 m_xParentCfgMgr( xParentCfgMgr )
923 uno::Reference< beans::XPropertySet > xProps(
924 ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY );
926 xProps->getPropertyValue(
927 OUString::createFromAscii( "DefaultContext" ))
928 >>= m_xComponentContext;
930 m_aSeparatorSeq.realloc( 1 );
931 m_aSeparatorSeq[0].Name = OUString(
932 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_TYPE ) );
933 m_aSeparatorSeq[0].Value <<= css::ui::ItemType::SEPARATOR_LINE;
935 if ( bDocConfig )
937 uno::Reference< css::ui::XUIConfigurationPersistence >
938 xDocPersistence( GetConfigManager(), uno::UNO_QUERY );
940 bReadOnly = xDocPersistence->isReadOnly();
943 m_xServiceManager = uno::Reference< lang::XMultiServiceFactory >(
944 ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
946 uno::Reference< container::XNameAccess > xNameAccess(
947 m_xServiceManager->createInstance(
948 OUString( RTL_CONSTASCII_USTRINGPARAM(
949 "com.sun.star.frame.UICommandDescription" ) ) ),
950 uno::UNO_QUERY );
952 if ( xNameAccess.is() )
953 xNameAccess->getByName( aModuleId ) >>= m_xCommandToLabelMap;
955 if ( !m_xImgMgr.is() )
957 m_xImgMgr = uno::Reference< css::ui::XImageManager >(
958 GetConfigManager()->getImageManager(), uno::UNO_QUERY );
961 if ( !IsDocConfig() )
963 // If this is not a document configuration then it is the settings
964 // for the module (writer, calc, impress etc.) Use this as the default
965 // XImageManager instance
966 xDefaultImgMgr = &m_xImgMgr;
968 else
970 // If this is a document configuration then use the module image manager
971 // as default.
972 if ( m_xParentCfgMgr.is() )
974 m_xParentImgMgr = uno::Reference< css::ui::XImageManager >(
975 m_xParentCfgMgr->getImageManager(), uno::UNO_QUERY );
976 xDefaultImgMgr = &m_xParentImgMgr;
981 uno::Reference< graphic::XGraphic > GetGraphic(
982 const uno::Reference< css::ui::XImageManager >& xImageManager,
983 const OUString& rCommandURL )
985 uno::Reference< graphic::XGraphic > result;
987 if ( xImageManager.is() )
989 // TODO handle large and high contrast graphics
990 uno::Sequence< uno::Reference< graphic::XGraphic > > aGraphicSeq;
992 uno::Sequence< OUString > aImageCmdSeq( 1 );
993 aImageCmdSeq[0] = rCommandURL;
997 aGraphicSeq =
998 xImageManager->getImages( GetImageType(), aImageCmdSeq );
1000 if ( aGraphicSeq.getLength() > 0 )
1002 result = aGraphicSeq[0];
1005 catch ( uno::Exception& )
1007 // will return empty XGraphic
1011 return result;
1014 Image SaveInData::GetImage( const OUString& rCommandURL )
1016 Image aImage;
1018 uno::Reference< graphic::XGraphic > xGraphic =
1019 GetGraphic( m_xImgMgr, rCommandURL );
1021 if ( xGraphic.is() )
1023 aImage = Image( xGraphic );
1025 else if ( xDefaultImgMgr != NULL && (*xDefaultImgMgr).is() )
1027 xGraphic = GetGraphic( (*xDefaultImgMgr), rCommandURL );
1029 if ( xGraphic.is() )
1031 aImage = Image( xGraphic );
1035 return aImage;
1038 bool SaveInData::PersistChanges(
1039 const uno::Reference< uno::XInterface >& xManager )
1041 bool result = sal_True;
1045 if ( xManager.is() && !IsReadOnly() )
1047 uno::Reference< css::ui::XUIConfigurationPersistence >
1048 xConfigPersistence( xManager, uno::UNO_QUERY );
1050 if ( xConfigPersistence->isModified() )
1052 xConfigPersistence->store();
1056 catch ( com::sun::star::io::IOException& )
1058 result = sal_False;
1061 return result;
1064 /******************************************************************************
1066 * The MenuSaveInData class extends SaveInData and provides menu specific
1067 * load and store functionality.
1069 ******************************************************************************/
1071 // Initialize static variable which holds default Menu data
1072 MenuSaveInData* MenuSaveInData::pDefaultData = NULL;
1074 MenuSaveInData::MenuSaveInData(
1075 const uno::Reference< css::ui::XUIConfigurationManager >& cfgmgr,
1076 const uno::Reference< css::ui::XUIConfigurationManager >& xParentCfgMgr,
1077 const OUString& aModuleId,
1078 bool isDocConfig )
1080 SaveInData( cfgmgr, xParentCfgMgr, aModuleId, isDocConfig ),
1081 m_aMenuResourceURL(
1082 RTL_CONSTASCII_USTRINGPARAM( ITEM_MENUBAR_URL ) ),
1083 m_aDescriptorContainer(
1084 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_CONTAINER ) ),
1085 pRootEntry( 0 )
1089 OUString url( RTL_CONSTASCII_USTRINGPARAM( ITEM_MENUBAR_URL ) );
1090 m_xMenuSettings = GetConfigManager()->getSettings( url, sal_False );
1092 catch ( container::NoSuchElementException& )
1094 // will use menu settings for the module
1097 // If this is not a document configuration then it is the settings
1098 // for the module (writer, calc, impress etc.). These settings should
1099 // be set as the default to be used for SaveIn locations that do not
1100 // have custom settings
1101 if ( !IsDocConfig() )
1103 SetDefaultData( this );
1107 MenuSaveInData::~MenuSaveInData()
1109 if ( pRootEntry != NULL )
1111 delete pRootEntry;
1115 SvxEntries*
1116 MenuSaveInData::GetEntries()
1118 if ( pRootEntry == NULL )
1120 pRootEntry = new SvxConfigEntry(
1121 String::CreateFromAscii("MainMenus"), String(), sal_True );
1123 if ( m_xMenuSettings.is() )
1125 LoadSubMenus( m_xMenuSettings, String(), pRootEntry );
1127 else if ( GetDefaultData() != NULL )
1129 // If the doc has no config settings use module config settings
1130 LoadSubMenus( GetDefaultData()->m_xMenuSettings, String(), pRootEntry );
1134 return pRootEntry->GetEntries();
1137 void
1138 MenuSaveInData::SetEntries( SvxEntries* pNewEntries )
1140 // delete old menu hierarchy first
1141 if ( pRootEntry != NULL )
1143 delete pRootEntry->GetEntries();
1146 // now set new menu hierarchy
1147 pRootEntry->SetEntries( pNewEntries );
1150 bool MenuSaveInData::LoadSubMenus(
1151 const uno::Reference< container::XIndexAccess >& xMenuSettings,
1152 const OUString& rBaseTitle,
1153 SvxConfigEntry* pParentData )
1155 SvxEntries* pEntries = pParentData->GetEntries();
1157 // Don't access non existing menu configuration!
1158 if ( !xMenuSettings.is() )
1159 return true;
1161 for ( sal_Int32 nIndex = 0; nIndex < xMenuSettings->getCount(); nIndex++ )
1163 uno::Reference< container::XIndexAccess > xSubMenu;
1164 OUString aCommandURL;
1165 OUString aLabel;
1166 bool bIsUserDefined = sal_True;
1168 sal_uInt16 nType( css::ui::ItemType::DEFAULT );
1170 bool bItem = GetMenuItemData( xMenuSettings, nIndex,
1171 aCommandURL, aLabel, nType, xSubMenu );
1173 if ( bItem )
1175 if ( nType == css::ui::ItemType::DEFAULT )
1177 uno::Any a;
1180 a = m_xCommandToLabelMap->getByName( aCommandURL );
1181 bIsUserDefined = sal_False;
1183 catch ( container::NoSuchElementException& )
1185 bIsUserDefined = sal_True;
1188 // If custom label not set retrieve it from the command
1189 // to info service
1190 if ( aLabel.equals( OUString() ) )
1192 uno::Sequence< beans::PropertyValue > aPropSeq;
1193 if ( a >>= aPropSeq )
1195 for ( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
1197 if ( aPropSeq[i].Name.equalsAscii( ITEM_DESCRIPTOR_LABEL ) )
1199 aPropSeq[i].Value >>= aLabel;
1200 break;
1206 if ( xSubMenu.is() )
1208 // popup menu
1209 SvxConfigEntry* pEntry = new SvxConfigEntry(
1210 aLabel, aCommandURL, sal_True );
1212 pEntry->SetUserDefined( bIsUserDefined );
1214 pEntries->push_back( pEntry );
1216 OUString subMenuTitle( rBaseTitle );
1218 if ( subMenuTitle.getLength() != 0 )
1220 subMenuTitle +=
1221 OUString::createFromAscii(pMenuSeparatorStr);
1223 else
1225 pEntry->SetMain( sal_True );
1228 subMenuTitle += stripHotKey( aLabel );
1230 LoadSubMenus( xSubMenu, subMenuTitle, pEntry );
1232 else
1234 SvxConfigEntry* pEntry = new SvxConfigEntry(
1235 aLabel, aCommandURL, sal_False );
1236 pEntry->SetUserDefined( bIsUserDefined );
1237 pEntries->push_back( pEntry );
1240 else
1242 SvxConfigEntry* pEntry = new SvxConfigEntry;
1243 pEntry->SetUserDefined( bIsUserDefined );
1244 pEntries->push_back( pEntry );
1248 return true;
1251 bool MenuSaveInData::Apply()
1253 bool result = sal_False;
1255 if ( IsModified() )
1257 // Apply new menu bar structure to our settings container
1258 m_xMenuSettings = uno::Reference< container::XIndexAccess >(
1259 GetConfigManager()->createSettings(), uno::UNO_QUERY );
1261 uno::Reference< container::XIndexContainer > xIndexContainer (
1262 m_xMenuSettings, uno::UNO_QUERY );
1264 uno::Reference< lang::XSingleComponentFactory > xFactory (
1265 m_xMenuSettings, uno::UNO_QUERY );
1267 Apply( pRootEntry, xIndexContainer, xFactory, NULL );
1271 if ( GetConfigManager()->hasSettings( m_aMenuResourceURL ) )
1273 GetConfigManager()->replaceSettings(
1274 m_aMenuResourceURL, m_xMenuSettings );
1276 else
1278 GetConfigManager()->insertSettings(
1279 m_aMenuResourceURL, m_xMenuSettings );
1282 catch ( container::NoSuchElementException& )
1284 OSL_TRACE("caught container::NoSuchElementException saving settings");
1286 catch ( com::sun::star::io::IOException& )
1288 OSL_TRACE("caught IOException saving settings");
1290 catch ( com::sun::star::uno::Exception& )
1292 OSL_TRACE("caught some other exception saving settings");
1295 SetModified( sal_False );
1297 result = PersistChanges( GetConfigManager() );
1300 return result;
1303 void MenuSaveInData::Apply(
1304 SvxConfigEntry* pRootEntry_,
1305 uno::Reference< container::XIndexContainer >& rMenuBar,
1306 uno::Reference< lang::XSingleComponentFactory >& rFactory,
1307 SvLBoxEntry *pParentEntry )
1309 (void)pRootEntry_;
1310 (void)pParentEntry;
1312 SvxEntries::const_iterator iter = GetEntries()->begin();
1313 SvxEntries::const_iterator end = GetEntries()->end();
1315 for ( ; iter != end; iter++ )
1317 SvxConfigEntry* pEntryData = *iter;
1319 uno::Sequence< beans::PropertyValue > aPropValueSeq =
1320 ConvertSvxConfigEntry( m_xCommandToLabelMap, pEntryData );
1322 uno::Reference< container::XIndexContainer > xSubMenuBar(
1323 rFactory->createInstanceWithContext( m_xComponentContext ),
1324 uno::UNO_QUERY );
1326 sal_Int32 nIndex = aPropValueSeq.getLength();
1327 aPropValueSeq.realloc( nIndex + 1 );
1328 aPropValueSeq[nIndex].Name = m_aDescriptorContainer;
1329 aPropValueSeq[nIndex].Value <<= xSubMenuBar;
1330 rMenuBar->insertByIndex(
1331 rMenuBar->getCount(), uno::makeAny( aPropValueSeq ));
1332 ApplyMenu( xSubMenuBar, rFactory, pEntryData );
1336 void MenuSaveInData::ApplyMenu(
1337 uno::Reference< container::XIndexContainer >& rMenuBar,
1338 uno::Reference< lang::XSingleComponentFactory >& rFactory,
1339 SvxConfigEntry* pMenuData )
1341 SvxEntries::const_iterator iter = pMenuData->GetEntries()->begin();
1342 SvxEntries::const_iterator end = pMenuData->GetEntries()->end();
1344 for ( ; iter != end; iter++ )
1346 SvxConfigEntry* pEntry = *iter;
1348 if ( pEntry->IsPopup() )
1350 uno::Sequence< beans::PropertyValue > aPropValueSeq =
1351 ConvertSvxConfigEntry( m_xCommandToLabelMap, pEntry );
1353 uno::Reference< container::XIndexContainer > xSubMenuBar(
1354 rFactory->createInstanceWithContext( m_xComponentContext ),
1355 uno::UNO_QUERY );
1357 sal_Int32 nIndex = aPropValueSeq.getLength();
1358 aPropValueSeq.realloc( nIndex + 1 );
1359 aPropValueSeq[nIndex].Name = m_aDescriptorContainer;
1360 aPropValueSeq[nIndex].Value <<= xSubMenuBar;
1362 rMenuBar->insertByIndex(
1363 rMenuBar->getCount(), uno::makeAny( aPropValueSeq ));
1365 ApplyMenu( xSubMenuBar, rFactory, pEntry );
1367 else if ( pEntry->IsSeparator() )
1369 rMenuBar->insertByIndex(
1370 rMenuBar->getCount(), uno::makeAny( m_aSeparatorSeq ));
1372 else
1374 uno::Sequence< beans::PropertyValue > aPropValueSeq =
1375 ConvertSvxConfigEntry( m_xCommandToLabelMap, pEntry );
1376 rMenuBar->insertByIndex(
1377 rMenuBar->getCount(), uno::makeAny( aPropValueSeq ));
1382 void
1383 MenuSaveInData::Reset()
1385 GetConfigManager()->reset();
1387 delete pRootEntry;
1388 pRootEntry = NULL;
1392 m_xMenuSettings = GetConfigManager()->getSettings(
1393 m_aMenuResourceURL, sal_False );
1395 catch ( container::NoSuchElementException& )
1397 // will use default settings
1401 class PopupPainter : public SvLBoxString
1403 public:
1404 PopupPainter( SvLBoxEntry* pEntry, const String& rStr )
1405 : SvLBoxString( pEntry, 0, rStr )
1408 ~PopupPainter() { }
1410 void Paint( const Point& rPos, SvLBox& rOutDev,
1411 sal_uInt16 nViewDataEntryFlags, SvLBoxEntry* pEntry )
1413 SvLBoxString::Paint( rPos, rOutDev, nViewDataEntryFlags, pEntry );
1415 Color aOldFillColor = rOutDev.GetFillColor();
1417 SvTreeListBox* pTreeBox = static_cast< SvTreeListBox* >( &rOutDev );
1418 long nX = pTreeBox->GetSizePixel().Width();
1420 ScrollBar* pVScroll = pTreeBox->GetVScroll();
1421 if ( pVScroll->IsVisible() )
1423 nX -= pVScroll->GetSizePixel().Width();
1426 SvViewDataItem* pItem = rOutDev.GetViewDataItem( pEntry, this );
1427 nX -= pItem->aSize.Height();
1429 long nSize = pItem->aSize.Height() / 2;
1430 long nHalfSize = nSize / 2;
1431 long nY = rPos.Y() + nHalfSize;
1433 if ( aOldFillColor == COL_WHITE )
1435 rOutDev.SetFillColor( Color( COL_BLACK ) );
1437 else
1439 rOutDev.SetFillColor( Color( COL_WHITE ) );
1442 long n = 0;
1443 while ( n <= nHalfSize )
1445 rOutDev.DrawRect( Rectangle( nX+n, nY+n, nX+n, nY+nSize-n ) );
1446 n++;
1449 rOutDev.SetFillColor( aOldFillColor );
1453 /******************************************************************************
1455 * SvxMenuEntriesListBox is the listbox in which the menu items for a
1456 * particular menu are shown. We have a custom listbox because we need
1457 * to add drag'n'drop support from the Macro Selector and within the
1458 * listbox
1460 *****************************************************************************/
1461 SvxMenuEntriesListBox::SvxMenuEntriesListBox(
1462 Window* pParent, const ResId& rResId)
1463 : SvTreeListBox( pParent, rResId )
1464 , pPage( (SvxMenuConfigPage*) pParent )
1465 , m_bIsInternalDrag( sal_False )
1467 SetStyle(
1468 GetStyle() | WB_CLIPCHILDREN | WB_HSCROLL | WB_HIDESELECTION );
1470 SetSpaceBetweenEntries( 3 );
1471 SetEntryHeight( ENTRY_HEIGHT );
1473 SetHighlightRange();
1474 SetSelectionMode(SINGLE_SELECTION);
1476 SetDragDropMode( SV_DRAGDROP_CTRL_MOVE |
1477 SV_DRAGDROP_APP_COPY |
1478 SV_DRAGDROP_ENABLE_TOP |
1479 SV_DRAGDROP_APP_DROP);
1482 SvxMenuEntriesListBox::~SvxMenuEntriesListBox()
1484 // do nothing
1487 // drag and drop support
1488 DragDropMode SvxMenuEntriesListBox::NotifyStartDrag(
1489 TransferDataContainer& aTransferDataContainer, SvLBoxEntry* pEntry )
1491 (void)aTransferDataContainer;
1492 (void)pEntry;
1494 m_bIsInternalDrag = sal_True;
1495 return GetDragDropMode();
1498 void SvxMenuEntriesListBox::DragFinished( sal_Int8 nDropAction )
1500 (void)nDropAction;
1501 m_bIsInternalDrag = sal_False;
1504 sal_Int8 SvxMenuEntriesListBox::AcceptDrop( const AcceptDropEvent& rEvt )
1506 if ( m_bIsInternalDrag )
1508 // internal copy isn't allowed!
1509 if ( rEvt.mnAction == DND_ACTION_COPY )
1510 return DND_ACTION_NONE;
1511 else
1512 return SvTreeListBox::AcceptDrop( rEvt );
1515 // Always do COPY instead of MOVE if D&D comes from outside!
1516 AcceptDropEvent aNewAcceptDropEvent( rEvt );
1517 aNewAcceptDropEvent.mnAction = DND_ACTION_COPY;
1518 return SvTreeListBox::AcceptDrop( aNewAcceptDropEvent );
1521 sal_Bool SvxMenuEntriesListBox::NotifyAcceptDrop( SvLBoxEntry* )
1523 return sal_True;
1526 sal_Bool SvxMenuEntriesListBox::NotifyMoving(
1527 SvLBoxEntry* pTarget, SvLBoxEntry* pSource,
1528 SvLBoxEntry*& rpNewParent, sal_uLong& rNewChildPos)
1530 // only try to do a move if we are dragging within the list box
1531 if ( m_bIsInternalDrag )
1533 if ( pPage->MoveEntryData( pSource, pTarget ) == sal_True )
1535 SvTreeListBox::NotifyMoving(
1536 pTarget, pSource, rpNewParent, rNewChildPos );
1537 return sal_True;
1539 else
1541 return sal_False;
1544 else
1546 return NotifyCopying( pTarget, pSource, rpNewParent, rNewChildPos );
1550 sal_Bool SvxMenuEntriesListBox::NotifyCopying(
1551 SvLBoxEntry* pTarget, SvLBoxEntry* pSource,
1552 SvLBoxEntry*& rpNewParent, sal_uLong& rNewChildPos)
1554 (void)pSource;
1555 (void)rpNewParent;
1556 (void)rNewChildPos;
1558 if ( !m_bIsInternalDrag )
1560 // if the target is NULL then add function to the start of the list
1561 pPage->AddFunction( pTarget, pTarget == NULL );
1563 // AddFunction already adds the listbox entry so return FALSE
1564 // to stop another listbox entry being added
1565 return sal_False;
1568 // Copying is only allowed from external controls, not within the listbox
1569 return sal_False;
1572 void SvxMenuEntriesListBox::KeyInput( const KeyEvent& rKeyEvent )
1574 KeyCode keycode = rKeyEvent.GetKeyCode();
1576 // support DELETE for removing the current entry
1577 if ( keycode == KEY_DELETE )
1579 pPage->DeleteSelectedContent();
1581 // support CTRL+UP and CTRL+DOWN for moving selected entries
1582 else if ( keycode.GetCode() == KEY_UP && keycode.IsMod1() )
1584 pPage->MoveEntry( sal_True );
1586 else if ( keycode.GetCode() == KEY_DOWN && keycode.IsMod1() )
1588 pPage->MoveEntry( sal_False );
1590 else
1592 // pass on to superclass
1593 SvTreeListBox::KeyInput( rKeyEvent );
1597 // class SvxDescriptionEdit ----------------------------------------------
1599 SvxDescriptionEdit::SvxDescriptionEdit( Window* pParent, const ResId& _rId ) :
1601 ExtMultiLineEdit( pParent, _rId )
1604 // calculate the available space for help text
1605 m_aRealRect = Rectangle( Point(), GetSizePixel() );
1606 if ( GetVScrollBar() )
1607 m_aRealRect.Right() -= ( GetVScrollBar()->GetSizePixel().Width() + 4 );
1609 SetLeftMargin(2);
1610 SetBorderStyle( WINDOW_BORDER_MONO );
1613 // -----------------------------------------------------------------------
1615 void SvxDescriptionEdit::SetNewText( const String& _rText )
1617 String sTemp( _rText );
1618 sal_Bool bShow = sal_False;
1619 if ( sTemp.Len() > 0 )
1621 // detect if a scrollbar is necessary
1622 Rectangle aRect = GetTextRect( m_aRealRect, sTemp, TEXT_DRAW_WORDBREAK | TEXT_DRAW_MULTILINE );
1623 bShow = ( aRect.Bottom() > m_aRealRect.Bottom() );
1626 if ( GetVScrollBar() )
1627 GetVScrollBar()->Show( bShow );
1629 if ( bShow )
1630 sTemp += '\n';
1632 SetText( sTemp );
1635 /******************************************************************************
1637 * SvxConfigPage is the abstract base class on which the Menu and Toolbar
1638 * configuration tabpages are based. It includes methods which are common to
1639 * both tabpages to add, delete, move and rename items etc.
1641 *****************************************************************************/
1642 SvxConfigPage::SvxConfigPage(
1643 Window *pParent, const SfxItemSet& rSet )
1645 SfxTabPage( pParent, CUI_RES( RID_SVXPAGE_MENUS ), rSet ),
1646 bInitialised( sal_False ),
1647 pCurrentSaveInData( 0 ),
1648 aTopLevelSeparator( this, CUI_RES( GRP_MENUS ) ),
1649 aTopLevelLabel( this, CUI_RES( FT_MENUS ) ),
1650 aTopLevelListBox( this, CUI_RES( LB_MENUS ) ),
1651 aNewTopLevelButton( this, CUI_RES( BTN_NEW ) ),
1652 aModifyTopLevelButton( this, CUI_RES( BTN_CHANGE ) ),
1653 aContentsSeparator( this, CUI_RES( GRP_MENU_SEPARATOR ) ),
1654 aContentsLabel( this, CUI_RES( GRP_MENU_ENTRIES ) ),
1655 aContentsListBox( 0 ),
1656 aAddCommandsButton( this, CUI_RES( BTN_ADD_COMMANDS ) ),
1657 aModifyCommandButton( this, CUI_RES( BTN_CHANGE_ENTRY ) ),
1658 aMoveUpButton( this, CUI_RES( BTN_UP ) ),
1659 aMoveDownButton( this, CUI_RES( BTN_DOWN ) ),
1660 aSaveInText( this, CUI_RES( TXT_SAVEIN ) ),
1661 aSaveInListBox( this, CUI_RES( LB_SAVEIN ) ),
1662 aDescriptionLabel( this, CUI_RES( FT_DESCRIPTION ) ),
1663 aDescriptionField( this, CUI_RES( ED_DESCRIPTION ) ),
1664 pSelectorDlg( 0 )
1666 aDescriptionField.SetControlBackground( GetSettings().GetStyleSettings().GetDialogColor() );
1667 aDescriptionField.SetAutoScroll( sal_True );
1668 aDescriptionField.EnableCursor( sal_False );
1670 aMoveUpButton.SetAccessibleName(String(CUI_RES(BUTTON_STR_UP)));
1671 aMoveDownButton.SetAccessibleName(String(CUI_RES(BUTTON_STR_DOWN)));
1672 aMoveUpButton.SetAccessibleRelationMemberOf(&aContentsSeparator);
1673 aMoveDownButton.SetAccessibleRelationMemberOf(&aContentsSeparator);
1674 aNewTopLevelButton.SetAccessibleRelationMemberOf(&aTopLevelSeparator);
1675 aModifyTopLevelButton.SetAccessibleRelationMemberOf(&aTopLevelSeparator);
1676 aAddCommandsButton.SetAccessibleRelationMemberOf(&aContentsSeparator);
1677 aModifyCommandButton.SetAccessibleRelationMemberOf(&aContentsSeparator);
1680 SvxConfigPage::~SvxConfigPage()
1684 void SvxConfigPage::Reset( const SfxItemSet& )
1686 // If we haven't initialised our XMultiServiceFactory reference
1687 // then Reset is being called at the opening of the dialog.
1689 // Load menu configuration data for the module of the currently
1690 // selected document, for the currently selected document, and for
1691 // all other open documents of the same module type
1692 if ( !bInitialised )
1694 sal_uInt16 nPos = 0;
1695 uno::Reference < css::ui::XUIConfigurationManager > xCfgMgr;
1696 uno::Reference < css::ui::XUIConfigurationManager > xDocCfgMgr;
1698 uno::Reference< lang::XMultiServiceFactory > xServiceManager(
1699 ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
1701 m_xFrame = GetFrame();
1702 OUString aModuleId = GetFrameWithDefaultAndIdentify( m_xFrame );
1704 // replace %MODULENAME in the label with the correct module name
1705 uno::Reference< css::frame::XModuleManager > xModuleManager(
1706 xServiceManager->createInstance(
1707 OUString( RTL_CONSTASCII_USTRINGPARAM(
1708 "com.sun.star.frame.ModuleManager" ) ) ),
1709 uno::UNO_QUERY_THROW );
1710 OUString aModuleName = GetUIModuleName( aModuleId, xModuleManager );
1712 OUString title = aTopLevelSeparator.GetText();
1713 OUString aSearchString = OUString::createFromAscii( "%MODULENAME" );
1714 sal_Int32 index = title.indexOf( aSearchString );
1716 if ( index != -1 )
1718 title = title.replaceAt(
1719 index, aSearchString.getLength(), aModuleName );
1720 aTopLevelSeparator.SetText( title );
1723 uno::Reference< css::ui::XModuleUIConfigurationManagerSupplier >
1724 xModuleCfgSupplier( xServiceManager->createInstance(
1725 OUString( RTL_CONSTASCII_USTRINGPARAM(
1726 "com.sun.star.ui.ModuleUIConfigurationManagerSupplier" ))),
1727 uno::UNO_QUERY );
1729 // Set up data for module specific menus
1730 SaveInData* pModuleData = NULL;
1734 xCfgMgr =
1735 xModuleCfgSupplier->getUIConfigurationManager( aModuleId );
1737 pModuleData = CreateSaveInData( xCfgMgr,
1738 uno::Reference< css::ui::XUIConfigurationManager >(),
1739 aModuleId,
1740 sal_False );
1742 catch ( container::NoSuchElementException& )
1746 if ( pModuleData != NULL )
1748 OUString label;
1749 utl::ConfigManager::GetDirectConfigProperty(
1750 utl::ConfigManager::PRODUCTNAME ) >>= label;
1751 label += OUString::createFromAscii( " " );
1752 label += aModuleName;
1754 nPos = aSaveInListBox.InsertEntry( label );
1755 aSaveInListBox.SetEntryData( nPos, pModuleData );
1758 // try to retrieve the document based ui configuration manager
1759 OUString aTitle;
1760 uno::Reference< frame::XController > xController =
1761 m_xFrame->getController();
1762 if ( CanConfig( aModuleId ) && xController.is() )
1764 uno::Reference< frame::XModel > xModel( xController->getModel() );
1765 if ( xModel.is() )
1767 uno::Reference< css::ui::XUIConfigurationManagerSupplier >
1768 xCfgSupplier( xModel, uno::UNO_QUERY );
1770 if ( xCfgSupplier.is() )
1772 xDocCfgMgr = xCfgSupplier->getUIConfigurationManager();
1774 aTitle = ::comphelper::DocumentInfo::getDocumentTitle( xModel );
1778 SaveInData* pDocData = NULL;
1779 if ( xDocCfgMgr.is() )
1781 pDocData = CreateSaveInData( xDocCfgMgr, xCfgMgr, aModuleId, sal_True );
1783 if ( !pDocData->IsReadOnly() )
1785 nPos = aSaveInListBox.InsertEntry( aTitle );
1786 aSaveInListBox.SetEntryData( nPos, pDocData );
1790 // if an item to select has been passed in (eg. the ResourceURL for a
1791 // toolbar) then try to select the SaveInData entry that has that item
1792 bool bURLToSelectFound = sal_False;
1793 if ( m_aURLToSelect.getLength() != 0 )
1795 if ( pDocData != NULL && pDocData->HasURL( m_aURLToSelect ) )
1797 aSaveInListBox.SelectEntryPos( nPos, sal_True );
1798 pCurrentSaveInData = pDocData;
1799 bURLToSelectFound = sal_True;
1801 else if ( pModuleData->HasURL( m_aURLToSelect ) )
1803 aSaveInListBox.SelectEntryPos( 0, sal_True );
1804 pCurrentSaveInData = pModuleData;
1805 bURLToSelectFound = sal_True;
1809 if ( bURLToSelectFound == sal_False )
1811 // if the document has menu configuration settings select it
1812 // it the SaveIn listbox, otherwise select the module data
1813 if ( pDocData != NULL && pDocData->HasSettings() )
1815 aSaveInListBox.SelectEntryPos( nPos, sal_True );
1816 pCurrentSaveInData = pDocData;
1818 else
1820 aSaveInListBox.SelectEntryPos( 0, sal_True );
1821 pCurrentSaveInData = pModuleData;
1825 #ifdef DBG_UTIL
1826 DBG_ASSERT( pCurrentSaveInData, "SvxConfigPage::Reset(): no SaveInData" );
1827 #endif
1829 if ( CanConfig( aModuleId ) )
1831 // Load configuration for other open documents which have
1832 // same module type
1833 uno::Sequence< uno::Reference< frame::XFrame > > aFrameList;
1836 uno::Reference< frame::XFramesSupplier > xFramesSupplier(
1837 xServiceManager->createInstance(
1838 OUString( RTL_CONSTASCII_USTRINGPARAM(
1839 "com.sun.star.frame.Desktop" ) ) ),
1840 uno::UNO_QUERY_THROW );
1842 uno::Reference< frame::XFrames > xFrames =
1843 xFramesSupplier->getFrames();
1845 aFrameList = xFrames->queryFrames(
1846 frame::FrameSearchFlag::ALL & ~frame::FrameSearchFlag::SELF );
1849 catch( const uno::Exception& )
1851 DBG_UNHANDLED_EXCEPTION();
1854 for ( sal_Int32 i = 0; i < aFrameList.getLength(); i++ )
1856 SaveInData* pData = NULL;
1857 uno::Reference < frame::XFrame > xf = aFrameList[i];
1859 if ( xf.is() && xf != m_xFrame )
1861 OUString aCheckId;
1862 try{
1863 aCheckId = xModuleManager->identify( xf );
1864 } catch(const uno::Exception&)
1865 { aCheckId = ::rtl::OUString(); }
1867 if ( aModuleId.equals( aCheckId ) )
1869 // try to get the document based ui configuration manager
1870 OUString aTitle2;
1871 uno::Reference< frame::XController > xController_ =
1872 xf->getController();
1874 if ( xController_.is() )
1876 uno::Reference< frame::XModel > xModel(
1877 xController_->getModel() );
1879 if ( xModel.is() )
1881 uno::Reference<
1882 css::ui::XUIConfigurationManagerSupplier >
1883 xCfgSupplier( xModel, uno::UNO_QUERY );
1885 if ( xCfgSupplier.is() )
1887 xDocCfgMgr =
1888 xCfgSupplier->getUIConfigurationManager();
1890 aTitle2 = ::comphelper::DocumentInfo::getDocumentTitle( xModel );
1894 if ( xDocCfgMgr.is() )
1896 pData = CreateSaveInData( xDocCfgMgr, xCfgMgr, aModuleId, sal_True );
1898 if ( pData && !pData->IsReadOnly() )
1900 nPos = aSaveInListBox.InsertEntry( aTitle2 );
1901 aSaveInListBox.SetEntryData( nPos, pData );
1909 aSaveInListBox.SetSelectHdl(
1910 LINK( this, SvxConfigPage, SelectSaveInLocation ) );
1912 bInitialised = sal_True;
1914 Init();
1916 else
1918 if ( QueryReset() == RET_YES )
1920 // Reset menu configuration for currently selected SaveInData
1921 GetSaveInData()->Reset();
1923 Init();
1928 ::rtl::OUString SvxConfigPage::GetFrameWithDefaultAndIdentify( uno::Reference< frame::XFrame >& _inout_rxFrame )
1930 ::rtl::OUString sModuleID;
1933 uno::Reference< lang::XMultiServiceFactory > xServiceManager(
1934 ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
1936 uno::Reference< frame::XFramesSupplier > xFramesSupplier(
1937 xServiceManager->createInstance(
1938 OUString( RTL_CONSTASCII_USTRINGPARAM(
1939 "com.sun.star.frame.Desktop" ) ) ),
1940 uno::UNO_QUERY_THROW );
1942 if ( !_inout_rxFrame.is() )
1943 _inout_rxFrame = xFramesSupplier->getActiveFrame();
1945 if ( !_inout_rxFrame.is() )
1947 uno::Reference< frame::XDesktop > xDesktop( xFramesSupplier, uno::UNO_QUERY_THROW );
1948 _inout_rxFrame = xDesktop->getCurrentFrame();
1951 if ( !_inout_rxFrame.is() && SfxViewFrame::Current() )
1952 _inout_rxFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface();
1954 if ( !_inout_rxFrame.is() )
1956 DBG_ERRORFILE( "SvxConfigPage::GetFrameWithDefaultAndIdentify(): no frame found!" );
1957 return sModuleID;
1960 uno::Reference< css::frame::XModuleManager > xModuleManager(
1961 xServiceManager->createInstance(
1962 OUString( RTL_CONSTASCII_USTRINGPARAM(
1963 "com.sun.star.frame.ModuleManager" ) ) ),
1964 uno::UNO_QUERY_THROW );
1968 sModuleID = xModuleManager->identify( _inout_rxFrame );
1970 catch ( const frame::UnknownModuleException& )
1975 catch( const uno::Exception& )
1977 DBG_UNHANDLED_EXCEPTION();
1980 return sModuleID;
1983 sal_Bool SvxConfigPage::FillItemSet( SfxItemSet& )
1985 bool result = sal_False;
1987 for ( sal_uInt16 i = 0 ; i < aSaveInListBox.GetEntryCount(); i++ )
1989 SaveInData* pData =
1990 (SaveInData*) aSaveInListBox.GetEntryData( i );
1992 result = pData->Apply();
1994 return result;
1997 void SvxConfigPage::PositionContentsListBox()
1999 if ( aContentsListBox == NULL )
2001 return;
2004 Point p, newp;
2005 Size s, news;
2006 long x, y, width, height;
2008 // x and width is same as aTopLevelListBox
2009 x = aTopLevelListBox.GetPosPixel().X();
2010 width = aTopLevelListBox.GetSizePixel().Width();
2012 // y is same as aAddCommandsButton
2013 y = aAddCommandsButton.GetPosPixel().Y();
2015 // get gap between aAddCommandsButton and aContentsSeparator
2016 p = aContentsSeparator.GetPosPixel();
2017 s = aContentsSeparator.GetSizePixel();
2018 long gap = y - ( p.Y() + s.Height() );
2020 height = aSaveInListBox.GetPosPixel().Y() - y - gap;
2022 aContentsListBox->SetPosPixel( Point( x, y ) );
2023 aContentsListBox->SetSizePixel( Size( width, height ) );
2026 IMPL_LINK( SvxConfigPage, SelectSaveInLocation, ListBox *, pBox )
2028 (void)pBox;
2030 pCurrentSaveInData = (SaveInData*) aSaveInListBox.GetEntryData(
2031 aSaveInListBox.GetSelectEntryPos());
2033 Init();
2034 return 1;
2037 void SvxConfigPage::ReloadTopLevelListBox( SvxConfigEntry* pToSelect )
2039 sal_uInt16 nSelectionPos = aTopLevelListBox.GetSelectEntryPos();
2040 aTopLevelListBox.Clear();
2042 if ( GetSaveInData() && GetSaveInData()->GetEntries() )
2044 SvxEntries::const_iterator iter = GetSaveInData()->GetEntries()->begin();
2045 SvxEntries::const_iterator end = GetSaveInData()->GetEntries()->end();
2047 for ( ; iter != end; iter++ )
2049 SvxConfigEntry* pEntryData = *iter;
2050 sal_uInt16 nPos = aTopLevelListBox.InsertEntry( stripHotKey( pEntryData->GetName() ) );
2051 aTopLevelListBox.SetEntryData( nPos, pEntryData );
2053 if ( pEntryData == pToSelect )
2054 nSelectionPos = nPos;
2056 AddSubMenusToUI( stripHotKey( pEntryData->GetName() ), pEntryData );
2059 #ifdef DBG_UTIL
2060 else
2062 DBG_ASSERT( GetSaveInData(), "SvxConfigPage::ReloadTopLevelListBox(): no SaveInData" );
2063 DBG_ASSERT( GetSaveInData()->GetEntries() ,
2064 "SvxConfigPage::ReloadTopLevelListBox(): no SaveInData entries" );
2066 #endif
2068 nSelectionPos = nSelectionPos < aTopLevelListBox.GetEntryCount() ?
2069 nSelectionPos : aTopLevelListBox.GetEntryCount() - 1;
2071 aTopLevelListBox.SelectEntryPos( nSelectionPos, sal_True );
2072 aTopLevelListBox.GetSelectHdl().Call( this );
2075 void SvxConfigPage::AddSubMenusToUI(
2076 const String& rBaseTitle, SvxConfigEntry* pParentData )
2078 SvxEntries::const_iterator iter = pParentData->GetEntries()->begin();
2079 SvxEntries::const_iterator end = pParentData->GetEntries()->end();
2081 for ( ; iter != end; iter++ )
2083 SvxConfigEntry* pEntryData = *iter;
2085 if ( pEntryData->IsPopup() )
2087 OUString subMenuTitle( rBaseTitle );
2088 subMenuTitle += OUString::createFromAscii( pMenuSeparatorStr );
2089 subMenuTitle += stripHotKey( pEntryData->GetName() );
2091 sal_uInt16 nPos = aTopLevelListBox.InsertEntry( subMenuTitle );
2092 aTopLevelListBox.SetEntryData( nPos, pEntryData );
2094 AddSubMenusToUI( subMenuTitle, pEntryData );
2099 SvxEntries* SvxConfigPage::FindParentForChild(
2100 SvxEntries* pRootEntries, SvxConfigEntry* pChildData )
2102 SvxEntries::const_iterator iter = pRootEntries->begin();
2103 SvxEntries::const_iterator end = pRootEntries->end();
2105 for ( ; iter != end; iter++ )
2107 SvxConfigEntry* pEntryData = *iter;
2109 if ( pEntryData == pChildData )
2111 return pRootEntries;
2113 else if ( pEntryData->IsPopup() )
2115 SvxEntries* result =
2116 FindParentForChild( pEntryData->GetEntries(), pChildData );
2118 if ( result != NULL )
2120 return result;
2124 return NULL;
2127 SvLBoxEntry* SvxConfigPage::AddFunction(
2128 SvLBoxEntry* pTarget, bool bFront, bool bAllowDuplicates )
2130 String aDisplayName = pSelectorDlg->GetSelectedDisplayName();
2131 String aHelpText = pSelectorDlg->GetSelectedHelpText();
2132 String aURL = pSelectorDlg->GetScriptURL();
2134 if ( !aURL.Len() )
2136 return NULL;
2139 SvxConfigEntry* pNewEntryData =
2140 new SvxConfigEntry( aDisplayName, aURL, sal_False );
2141 pNewEntryData->SetUserDefined( sal_True );
2143 // check that this function is not already in the menu
2144 SvxConfigEntry* pParent = GetTopLevelSelection();
2146 SvxEntries::const_iterator iter = pParent->GetEntries()->begin();
2147 SvxEntries::const_iterator end = pParent->GetEntries()->end();
2149 if ( !bAllowDuplicates )
2151 while ( iter != end )
2153 SvxConfigEntry *pCurEntry = *iter;
2155 if ( pCurEntry->GetCommand() == pNewEntryData->GetCommand() )
2157 // asynchronous error message, because of MsgBoxes
2158 PostUserEvent(
2159 LINK( this, SvxConfigPage, AsyncInfoMsg ) );
2160 return NULL;
2163 iter++;
2167 return InsertEntry( pNewEntryData, pTarget, bFront );
2170 SvLBoxEntry* SvxConfigPage::InsertEntry(
2171 SvxConfigEntry* pNewEntryData,
2172 SvLBoxEntry* pTarget,
2173 bool bFront )
2175 // Grab the entries list for the currently selected menu
2176 SvxEntries* pEntries = GetTopLevelSelection()->GetEntries();
2178 SvLBoxEntry* pNewEntry = NULL;
2179 SvLBoxEntry* pCurEntry =
2180 pTarget != NULL ? pTarget : aContentsListBox->GetCurEntry();
2182 if ( bFront )
2184 pEntries->insert( pEntries->begin(), pNewEntryData );
2185 pNewEntry = InsertEntryIntoUI( pNewEntryData, 0 );
2187 else if ( pCurEntry == NULL || pCurEntry == aContentsListBox->Last() )
2189 pEntries->push_back( pNewEntryData );
2190 pNewEntry = InsertEntryIntoUI( pNewEntryData );
2192 else
2194 SvxConfigEntry* pEntryData =
2195 (SvxConfigEntry*) pCurEntry->GetUserData();
2197 SvxEntries::iterator iter = pEntries->begin();
2198 SvxEntries::const_iterator end = pEntries->end();
2200 // Advance the iterator to the data for currently selected entry
2201 sal_uInt16 nPos = 0;
2202 while (*iter != pEntryData && ++iter != end)
2204 nPos++;
2207 // Now step past it to the entry after the currently selected one
2208 iter++;
2209 nPos++;
2211 // Now add the new entry to the UI and to the parent's list
2212 if ( iter != end )
2214 pEntries->insert( iter, pNewEntryData );
2215 pNewEntry = InsertEntryIntoUI( pNewEntryData, nPos );
2219 if ( pNewEntry != NULL )
2221 aContentsListBox->Select( pNewEntry );
2222 aContentsListBox->MakeVisible( pNewEntry );
2224 GetSaveInData()->SetModified( sal_True );
2227 return pNewEntry;
2230 SvLBoxEntry* SvxConfigPage::InsertEntryIntoUI(
2231 SvxConfigEntry* pNewEntryData, sal_uLong nPos )
2233 SvLBoxEntry* pNewEntry = NULL;
2235 if (pNewEntryData->IsSeparator())
2237 pNewEntry = aContentsListBox->InsertEntry(
2238 String::CreateFromAscii( pSeparatorStr ),
2239 0, sal_False, nPos, pNewEntryData );
2241 else
2243 OUString aName = stripHotKey( pNewEntryData->GetName() );
2245 Image aImage = GetSaveInData()->GetImage(
2246 pNewEntryData->GetCommand());
2248 if ( !!aImage )
2250 pNewEntry = aContentsListBox->InsertEntry(
2251 aName, aImage, aImage, 0, sal_False, nPos, pNewEntryData );
2253 else
2255 pNewEntry = aContentsListBox->InsertEntry(
2256 aName, 0, sal_False, nPos, pNewEntryData );
2259 if ( pNewEntryData->IsPopup() ||
2260 pNewEntryData->GetStyle() & css::ui::ItemStyle::DROP_DOWN )
2262 // add new popup painter, it gets destructed by the entry
2263 pNewEntry->ReplaceItem(
2264 new PopupPainter( pNewEntry, aName ),
2265 pNewEntry->ItemCount() - 1 );
2269 return pNewEntry;
2272 IMPL_LINK( SvxConfigPage, AsyncInfoMsg, String*, pMsg )
2274 (void)pMsg;
2276 // Asynchronous msg because of D&D
2277 InfoBox( this, CUI_RES(
2278 IBX_MNUCFG_ALREADY_INCLUDED ) ).Execute();
2280 return 0;
2283 IMPL_LINK( SvxConfigPage, MoveHdl, Button *, pButton )
2285 MoveEntry( pButton == &aMoveUpButton );
2286 return 0;
2289 void SvxConfigPage::MoveEntry( bool bMoveUp )
2291 SvLBoxEntry *pSourceEntry = aContentsListBox->FirstSelected();
2292 SvLBoxEntry *pTargetEntry = NULL;
2293 SvLBoxEntry *pToSelect = NULL;
2295 if ( !pSourceEntry )
2297 return;
2300 if ( bMoveUp )
2302 // Move Up is just a Move Down with the source and target reversed
2303 pTargetEntry = pSourceEntry;
2304 pSourceEntry = aContentsListBox->PrevSibling( pTargetEntry );
2305 pToSelect = pTargetEntry;
2307 else
2309 pTargetEntry = aContentsListBox->NextSibling( pSourceEntry );
2310 pToSelect = pSourceEntry;
2313 if ( MoveEntryData( pSourceEntry, pTargetEntry ) )
2315 aContentsListBox->GetModel()->Move( pSourceEntry, pTargetEntry );
2316 aContentsListBox->Select( pToSelect );
2317 aContentsListBox->MakeVisible( pToSelect );
2319 UpdateButtonStates();
2323 bool SvxConfigPage::MoveEntryData(
2324 SvLBoxEntry* pSourceEntry, SvLBoxEntry* pTargetEntry )
2326 //modified by shizhoubo for issue53677
2327 if ( NULL == pSourceEntry || NULL == pTargetEntry )
2329 return sal_False;
2332 // Grab the entries list for the currently selected menu
2333 SvxEntries* pEntries = GetTopLevelSelection()->GetEntries();
2335 SvxConfigEntry* pSourceData =
2336 (SvxConfigEntry*) pSourceEntry->GetUserData();
2338 if ( pTargetEntry == NULL )
2340 RemoveEntry( pEntries, pSourceData );
2341 pEntries->insert(
2342 pEntries->begin(), pSourceData );
2344 GetSaveInData()->SetModified( sal_True );
2346 return sal_True;
2348 else
2350 SvxConfigEntry* pTargetData =
2351 (SvxConfigEntry*) pTargetEntry->GetUserData();
2353 if ( pSourceData != NULL && pTargetData != NULL )
2355 // remove the source entry from our list
2356 RemoveEntry( pEntries, pSourceData );
2358 SvxEntries::iterator iter = pEntries->begin();
2359 SvxEntries::const_iterator end = pEntries->end();
2361 // advance the iterator to the position of the target entry
2362 while (*iter != pTargetData && ++iter != end) ;
2364 // insert the source entry at the position after the target
2365 pEntries->insert( ++iter, pSourceData );
2367 GetSaveInData()->SetModified( sal_True );
2369 return sal_True;
2373 return sal_False;
2376 SvxMenuConfigPage::SvxMenuConfigPage(
2377 Window *pParent, const SfxItemSet& rSet )
2379 SvxConfigPage( pParent, rSet )
2381 aContentsListBox = new SvxMenuEntriesListBox( this, CUI_RES( BOX_ENTRIES ) );
2382 FreeResource();
2384 PositionContentsListBox();
2385 aContentsListBox->SetZOrder( &aAddCommandsButton, WINDOW_ZORDER_BEFOR );
2387 aTopLevelListBox.SetSelectHdl(
2388 LINK( this, SvxMenuConfigPage, SelectMenu ) );
2390 aContentsListBox->SetSelectHdl(
2391 LINK( this, SvxMenuConfigPage, SelectMenuEntry ) );
2393 aMoveUpButton.SetClickHdl ( LINK( this, SvxConfigPage, MoveHdl) );
2394 aMoveDownButton.SetClickHdl ( LINK( this, SvxConfigPage, MoveHdl) );
2396 aNewTopLevelButton.SetClickHdl (
2397 LINK( this, SvxMenuConfigPage, NewMenuHdl ) );
2399 aAddCommandsButton.SetClickHdl (
2400 LINK( this, SvxMenuConfigPage, AddCommandsHdl ) );
2402 PopupMenu* pMenu = new PopupMenu( CUI_RES( MODIFY_MENU ) );
2403 pMenu->SetMenuFlags(
2404 pMenu->GetMenuFlags() | MENU_FLAG_ALWAYSSHOWDISABLEDENTRIES );
2406 aModifyTopLevelButton.SetPopupMenu( pMenu );
2407 aModifyTopLevelButton.SetSelectHdl(
2408 LINK( this, SvxMenuConfigPage, MenuSelectHdl ) );
2410 PopupMenu* pEntry = new PopupMenu( CUI_RES( MODIFY_ENTRY ) );
2411 pEntry->SetMenuFlags(
2412 pEntry->GetMenuFlags() | MENU_FLAG_ALWAYSSHOWDISABLEDENTRIES );
2414 aModifyCommandButton.SetPopupMenu( pEntry );
2415 aModifyCommandButton.SetSelectHdl(
2416 LINK( this, SvxMenuConfigPage, EntrySelectHdl ) );
2419 // Populates the Menu combo box
2420 void SvxMenuConfigPage::Init()
2422 // ensure that the UI is cleared before populating it
2423 aTopLevelListBox.Clear();
2424 aContentsListBox->Clear();
2426 ReloadTopLevelListBox();
2428 aTopLevelListBox.SelectEntryPos(0, sal_True);
2429 aTopLevelListBox.GetSelectHdl().Call(this);
2432 SvxMenuConfigPage::~SvxMenuConfigPage()
2434 for ( sal_uInt16 i = 0 ; i < aSaveInListBox.GetEntryCount(); i++ )
2436 MenuSaveInData* pData =
2437 (MenuSaveInData*) aSaveInListBox.GetEntryData( i );
2439 delete pData;
2442 if ( pSelectorDlg != NULL )
2444 delete pSelectorDlg;
2447 delete aContentsListBox;
2450 IMPL_LINK( SvxMenuConfigPage, SelectMenuEntry, Control *, pBox )
2452 (void)pBox;
2454 UpdateButtonStates();
2456 return 1;
2459 void SvxMenuConfigPage::UpdateButtonStates()
2461 PopupMenu* pPopup = aModifyCommandButton.GetPopupMenu();
2463 // Disable Up and Down buttons depending on current selection
2464 SvLBoxEntry* selection = aContentsListBox->GetCurEntry();
2466 if ( aContentsListBox->GetEntryCount() == 0 || selection == NULL )
2468 aMoveUpButton.Enable( sal_False );
2469 aMoveDownButton.Enable( sal_False );
2471 pPopup->EnableItem( ID_BEGIN_GROUP, sal_True );
2472 pPopup->EnableItem( ID_RENAME, sal_False );
2473 pPopup->EnableItem( ID_DELETE, sal_False );
2475 aDescriptionField.Clear();
2477 return;
2480 SvLBoxEntry* first = aContentsListBox->First();
2481 SvLBoxEntry* last = aContentsListBox->Last();
2483 aMoveUpButton.Enable( selection != first );
2484 aMoveDownButton.Enable( selection != last );
2486 SvxConfigEntry* pEntryData =
2487 (SvxConfigEntry*) selection->GetUserData();
2489 if ( pEntryData->IsSeparator() )
2491 pPopup->EnableItem( ID_DELETE, sal_True );
2492 pPopup->EnableItem( ID_BEGIN_GROUP, sal_False );
2493 pPopup->EnableItem( ID_RENAME, sal_False );
2495 aDescriptionField.Clear();
2497 else
2499 pPopup->EnableItem( ID_BEGIN_GROUP, sal_True );
2500 pPopup->EnableItem( ID_DELETE, sal_True );
2501 pPopup->EnableItem( ID_RENAME, sal_True );
2503 aDescriptionField.SetNewText( pEntryData->GetHelpText() );
2507 void SvxMenuConfigPage::DeleteSelectedTopLevel()
2509 SvxConfigEntry* pMenuData = GetTopLevelSelection();
2511 SvxEntries* pParentEntries =
2512 FindParentForChild( GetSaveInData()->GetEntries(), pMenuData );
2514 RemoveEntry( pParentEntries, pMenuData );
2515 delete pMenuData;
2517 ReloadTopLevelListBox();
2519 GetSaveInData()->SetModified( sal_True );
2522 bool SvxMenuConfigPage::DeleteSelectedContent()
2524 SvLBoxEntry *pActEntry = aContentsListBox->FirstSelected();
2526 if ( pActEntry != NULL )
2528 // get currently selected menu entry
2529 SvxConfigEntry* pMenuEntry =
2530 (SvxConfigEntry*) pActEntry->GetUserData();
2532 // get currently selected menu
2533 SvxConfigEntry* pMenu = GetTopLevelSelection();
2535 // remove menu entry from the list for this menu
2536 RemoveEntry( pMenu->GetEntries(), pMenuEntry );
2538 // remove menu entry from UI
2539 aContentsListBox->GetModel()->Remove( pActEntry );
2541 // if this is a submenu entry, redraw the menus list box
2542 if ( pMenuEntry->IsPopup() )
2544 ReloadTopLevelListBox();
2547 // delete data for menu entry
2548 delete pMenuEntry;
2550 GetSaveInData()->SetModified( sal_True );
2552 return sal_True;
2554 return sal_False;
2557 short SvxMenuConfigPage::QueryReset()
2559 String msg =
2560 String( CUI_RES( RID_SVXSTR_CONFIRM_MENU_RESET ) );
2562 String saveInName = aSaveInListBox.GetEntry(
2563 aSaveInListBox.GetSelectEntryPos() );
2565 OUString label = replaceSaveInName( msg, saveInName );
2567 QueryBox qbox( this, WB_YES_NO, label );
2569 return qbox.Execute();
2572 IMPL_LINK( SvxMenuConfigPage, SelectMenu, ListBox *, pBox )
2574 (void)pBox;
2576 aContentsListBox->Clear();
2578 SvxConfigEntry* pMenuData = GetTopLevelSelection();
2580 PopupMenu* pPopup = aModifyTopLevelButton.GetPopupMenu();
2581 if ( pMenuData )
2583 pPopup->EnableItem( ID_DELETE, pMenuData->IsDeletable() );
2584 pPopup->EnableItem( ID_RENAME, pMenuData->IsRenamable() );
2585 pPopup->EnableItem( ID_MOVE, pMenuData->IsMovable() );
2587 SvxEntries* pEntries = pMenuData->GetEntries();
2588 SvxEntries::const_iterator iter = pEntries->begin();
2590 for ( ; iter != pEntries->end(); iter++ )
2592 SvxConfigEntry* pEntry = *iter;
2593 InsertEntryIntoUI( pEntry );
2597 UpdateButtonStates();
2599 return 0;
2602 IMPL_LINK( SvxMenuConfigPage, MenuSelectHdl, MenuButton *, pButton )
2604 switch( pButton->GetCurItemId() )
2606 case ID_DELETE:
2608 DeleteSelectedTopLevel();
2609 break;
2611 case ID_RENAME:
2613 SvxConfigEntry* pMenuData = GetTopLevelSelection();
2615 String aNewName( stripHotKey( pMenuData->GetName() ) );
2616 String aDesc = CUI_RESSSTR( RID_SVXSTR_LABEL_NEW_NAME );
2618 SvxNameDialog* pNameDialog = new SvxNameDialog( this, aNewName, aDesc );
2619 pNameDialog->SetHelpId( HID_SVX_CONFIG_RENAME_MENU );
2620 pNameDialog->SetText( CUI_RESSTR( RID_SVXSTR_RENAME_MENU ) );
2622 bool ret = pNameDialog->Execute();
2624 if ( ret == RET_OK ) {
2625 pNameDialog->GetName( aNewName );
2626 pMenuData->SetName( aNewName );
2628 ReloadTopLevelListBox();
2630 GetSaveInData()->SetModified( sal_True );
2633 // #i68101# Moemory leak (!)
2634 delete pNameDialog;
2636 break;
2638 case ID_MOVE:
2640 SvxConfigEntry* pMenuData = GetTopLevelSelection();
2642 SvxMainMenuOrganizerDialog* pDialog =
2643 new SvxMainMenuOrganizerDialog( this,
2644 GetSaveInData()->GetEntries(), pMenuData );
2646 bool ret = pDialog->Execute();
2648 if ( ret == RET_OK )
2650 GetSaveInData()->SetEntries( pDialog->GetEntries() );
2652 ReloadTopLevelListBox( pDialog->GetSelectedEntry() );
2654 GetSaveInData()->SetModified( sal_True );
2657 delete pDialog;
2659 break;
2661 default:
2662 return sal_False;
2664 return sal_True;
2667 IMPL_LINK( SvxMenuConfigPage, EntrySelectHdl, MenuButton *, pButton )
2669 switch( pButton->GetCurItemId() )
2671 case ID_ADD_SUBMENU:
2673 String aNewName;
2674 String aDesc = CUI_RESSSTR( RID_SVXSTR_SUBMENU_NAME );
2676 SvxNameDialog* pNameDialog = new SvxNameDialog( this, aNewName, aDesc );
2677 pNameDialog->SetHelpId( HID_SVX_CONFIG_NAME_SUBMENU );
2678 pNameDialog->SetText( CUI_RESSTR( RID_SVXSTR_ADD_SUBMENU ) );
2680 bool ret = pNameDialog->Execute();
2682 if ( ret == RET_OK ) {
2683 pNameDialog->GetName(aNewName);
2685 SvxConfigEntry* pNewEntryData =
2686 new SvxConfigEntry( aNewName, aNewName, sal_True );
2687 pNewEntryData->SetUserDefined( sal_True );
2689 InsertEntry( pNewEntryData );
2691 ReloadTopLevelListBox();
2693 GetSaveInData()->SetModified( sal_True );
2696 delete pNameDialog;
2698 break;
2700 case ID_BEGIN_GROUP:
2702 SvxConfigEntry* pNewEntryData = new SvxConfigEntry;
2703 pNewEntryData->SetUserDefined( sal_True );
2704 InsertEntry( pNewEntryData );
2706 break;
2708 case ID_DELETE:
2710 DeleteSelectedContent();
2711 break;
2713 case ID_RENAME:
2715 SvLBoxEntry* pActEntry = aContentsListBox->GetCurEntry();
2716 SvxConfigEntry* pEntry =
2717 (SvxConfigEntry*) pActEntry->GetUserData();
2719 String aNewName( stripHotKey( pEntry->GetName() ) );
2720 String aDesc = CUI_RESSSTR( RID_SVXSTR_LABEL_NEW_NAME );
2722 SvxNameDialog* pNameDialog = new SvxNameDialog( this, aNewName, aDesc );
2723 pNameDialog->SetHelpId( HID_SVX_CONFIG_RENAME_MENU_ITEM );
2724 pNameDialog->SetText( CUI_RESSTR( RID_SVXSTR_RENAME_MENU ) );
2726 bool ret = pNameDialog->Execute();
2728 if ( ret == RET_OK ) {
2729 pNameDialog->GetName(aNewName);
2731 pEntry->SetName( aNewName );
2732 aContentsListBox->SetEntryText( pActEntry, aNewName );
2734 GetSaveInData()->SetModified( sal_True );
2737 delete pNameDialog;
2739 break;
2741 default:
2743 return sal_False;
2747 if ( GetSaveInData()->IsModified() )
2749 UpdateButtonStates();
2752 return sal_True;
2755 IMPL_LINK( SvxMenuConfigPage, AddFunctionHdl,
2756 SvxScriptSelectorDialog *, pDialog )
2758 (void)pDialog;
2760 AddFunction();
2762 return 0;
2765 IMPL_LINK( SvxMenuConfigPage, NewMenuHdl, Button *, pButton )
2767 (void)pButton;
2769 SvxMainMenuOrganizerDialog* pDialog =
2770 new SvxMainMenuOrganizerDialog( 0,
2771 GetSaveInData()->GetEntries(), NULL, sal_True );
2773 bool ret = pDialog->Execute();
2775 if ( ret == RET_OK )
2777 GetSaveInData()->SetEntries( pDialog->GetEntries() );
2778 ReloadTopLevelListBox( pDialog->GetSelectedEntry() );
2779 GetSaveInData()->SetModified( sal_True );
2782 delete pDialog;
2784 return 0;
2787 IMPL_LINK( SvxMenuConfigPage, AddCommandsHdl, Button *, pButton )
2789 (void)pButton;
2791 if ( pSelectorDlg == NULL )
2793 // Create Script Selector which also shows builtin commands
2794 pSelectorDlg = new SvxScriptSelectorDialog( this, sal_True, m_xFrame );
2796 pSelectorDlg->SetAddHdl(
2797 LINK( this, SvxMenuConfigPage, AddFunctionHdl ) );
2799 pSelectorDlg->SetDialogDescription( String(
2800 CUI_RES( RID_SVXSTR_MENU_ADDCOMMANDS_DESCRIPTION ) ) );
2803 // Position the Script Selector over the Add button so it is
2804 // beside the menu contents list and does not obscure it
2805 pSelectorDlg->SetPosPixel( aAddCommandsButton.GetPosPixel() );
2807 pSelectorDlg->SetImageProvider(
2808 static_cast< ImageProvider* >( GetSaveInData() ) );
2810 pSelectorDlg->Show();
2811 return 1;
2814 SaveInData* SvxMenuConfigPage::CreateSaveInData(
2815 const uno::Reference< css::ui::XUIConfigurationManager >& xCfgMgr,
2816 const uno::Reference< css::ui::XUIConfigurationManager >& xParentCfgMgr,
2817 const OUString& aModuleId,
2818 bool bDocConfig )
2820 return static_cast< SaveInData* >(
2821 new MenuSaveInData( xCfgMgr, xParentCfgMgr, aModuleId, bDocConfig ));
2824 SvxMainMenuOrganizerDialog::SvxMainMenuOrganizerDialog(
2825 Window* pParent, SvxEntries* entries,
2826 SvxConfigEntry* selection, bool bCreateMenu )
2828 ModalDialog( pParent, CUI_RES( MD_MENU_ORGANISER ) ),
2829 aMenuNameText( this, CUI_RES( TXT_MENU_NAME ) ),
2830 aMenuNameEdit( this, CUI_RES( EDIT_MENU_NAME ) ),
2831 aMenuListText( this, CUI_RES( TXT_MENU ) ),
2832 aMenuListBox( this, CUI_RES( BOX_MAIN_MENUS ) ),
2833 aMoveUpButton( this, CUI_RES( BTN_MENU_UP ) ),
2834 aMoveDownButton( this, CUI_RES( BTN_MENU_DOWN ) ),
2835 aOKButton( this, CUI_RES( BTN_MENU_ADD ) ),
2836 aCloseButton( this, CUI_RES( BTN_MENU_CLOSE ) ),
2837 aHelpButton( this, CUI_RES( BTN_MENU_HELP ) ),
2838 bModified( sal_False )
2840 FreeResource();
2842 // Copy the entries list passed in
2843 if ( entries != NULL )
2845 SvxConfigEntry* pEntry;
2846 SvLBoxEntry* pLBEntry;
2848 pEntries = new SvxEntries();
2849 SvxEntries::const_iterator iter = entries->begin();
2851 while ( iter != entries->end() )
2853 pEntry = *iter;
2854 pLBEntry =
2855 aMenuListBox.InsertEntry( stripHotKey( pEntry->GetName() ) );
2856 pLBEntry->SetUserData( pEntry );
2857 pEntries->push_back( pEntry );
2859 if ( pEntry == selection )
2861 aMenuListBox.Select( pLBEntry );
2863 iter++;
2867 if ( bCreateMenu )
2869 // Generate custom name for new menu
2870 String prefix =
2871 String( CUI_RES( RID_SVXSTR_NEW_MENU ) );
2873 OUString newname = generateCustomName( prefix, entries );
2874 OUString newurl = generateCustomMenuURL( pEntries );
2876 SvxConfigEntry* pNewEntryData =
2877 new SvxConfigEntry( newname, newurl, sal_True );
2878 pNewEntryData->SetUserDefined( sal_True );
2879 pNewEntryData->SetMain( sal_True );
2881 pNewMenuEntry =
2882 aMenuListBox.InsertEntry( stripHotKey( pNewEntryData->GetName() ) );
2883 aMenuListBox.Select( pNewMenuEntry );
2885 pNewMenuEntry->SetUserData( pNewEntryData );
2887 pEntries->push_back( pNewEntryData );
2889 aMenuNameEdit.SetText( newname );
2890 aMenuNameEdit.SetModifyHdl(
2891 LINK( this, SvxMainMenuOrganizerDialog, ModifyHdl ) );
2893 else
2895 Point p, newp;
2896 Size s, news;
2898 // get offset to bottom of name textfield from top of dialog
2899 p = aMenuNameEdit.GetPosPixel();
2900 s = aMenuNameEdit.GetSizePixel();
2901 long offset = p.Y() + s.Height();
2903 // reposition menu list and label
2904 aMenuListText.SetPosPixel( aMenuNameText.GetPosPixel() );
2905 aMenuListBox.SetPosPixel( aMenuNameEdit.GetPosPixel() );
2907 // reposition up and down buttons
2908 p = aMoveUpButton.GetPosPixel();
2909 newp = Point( p.X(), p.Y() - offset );
2910 aMoveUpButton.SetPosPixel( newp );
2912 p = aMoveDownButton.GetPosPixel();
2913 newp = Point( p.X(), p.Y() - offset );
2914 aMoveDownButton.SetPosPixel( newp );
2916 // change size of dialog
2917 s = GetSizePixel();
2918 news = Size( s.Width(), s.Height() - offset );
2919 SetSizePixel( news );
2921 // hide name label and textfield
2922 aMenuNameText.Hide();
2923 aMenuNameEdit.Hide();
2925 // change the title
2926 SetText( CUI_RES( RID_SVXSTR_MOVE_MENU ) );
2929 aMenuListBox.SetSelectHdl(
2930 LINK( this, SvxMainMenuOrganizerDialog, SelectHdl ) );
2932 aMoveUpButton.SetClickHdl (
2933 LINK( this, SvxMainMenuOrganizerDialog, MoveHdl) );
2934 aMoveDownButton.SetClickHdl (
2935 LINK( this, SvxMainMenuOrganizerDialog, MoveHdl) );
2937 aMoveUpButton.SetAccessibleName(String(CUI_RES(BUTTON_STR_UP)));
2938 aMoveDownButton.SetAccessibleName(String(CUI_RES(BUTTON_STR_DOWN)));
2941 IMPL_LINK(SvxMainMenuOrganizerDialog, ModifyHdl, Edit*, pEdit)
2943 (void)pEdit;
2945 // if the Edit control is empty do not change the name
2946 if ( aMenuNameEdit.GetText().Equals( String() ) )
2948 return 0;
2951 SvxConfigEntry* pNewEntryData =
2952 (SvxConfigEntry*) pNewMenuEntry->GetUserData();
2954 pNewEntryData->SetName( aMenuNameEdit.GetText() );
2956 aMenuListBox.SetEntryText( pNewMenuEntry, pNewEntryData->GetName() );
2958 return 0;
2961 SvxMainMenuOrganizerDialog::~SvxMainMenuOrganizerDialog()
2965 IMPL_LINK( SvxMainMenuOrganizerDialog, SelectHdl, Control*, pCtrl )
2967 (void)pCtrl;
2968 UpdateButtonStates();
2969 return 1;
2972 void SvxMainMenuOrganizerDialog::UpdateButtonStates()
2974 // Disable Up and Down buttons depending on current selection
2975 SvLBoxEntry* selection = aMenuListBox.GetCurEntry();
2976 SvLBoxEntry* first = aMenuListBox.First();
2977 SvLBoxEntry* last = aMenuListBox.Last();
2979 aMoveUpButton.Enable( selection != first );
2980 aMoveDownButton.Enable( selection != last );
2983 IMPL_LINK( SvxMainMenuOrganizerDialog, MoveHdl, Button *, pButton )
2985 SvLBoxEntry *pSourceEntry = aMenuListBox.FirstSelected();
2986 SvLBoxEntry *pTargetEntry = NULL;
2988 if ( !pSourceEntry )
2990 return 0;
2993 if ( pButton == &aMoveDownButton )
2995 pTargetEntry = aMenuListBox.NextSibling( pSourceEntry );
2997 else if ( pButton == &aMoveUpButton )
2999 // Move Up is just a Move Down with the source and target reversed
3000 pTargetEntry = pSourceEntry;
3001 pSourceEntry = aMenuListBox.PrevSibling( pTargetEntry );
3004 if ( pSourceEntry != NULL && pTargetEntry != NULL )
3006 SvxConfigEntry* pSourceData =
3007 (SvxConfigEntry*) pSourceEntry->GetUserData();
3008 SvxConfigEntry* pTargetData =
3009 (SvxConfigEntry*) pTargetEntry->GetUserData();
3011 SvxEntries::iterator iter1 = GetEntries()->begin();
3012 SvxEntries::iterator iter2 = GetEntries()->begin();
3013 SvxEntries::const_iterator end = GetEntries()->end();
3015 // Advance the iterators to the positions of the source and target
3016 while (*iter1 != pSourceData && ++iter1 != end) ;
3017 while (*iter2 != pTargetData && ++iter2 != end) ;
3019 // Now swap the entries in the menu list and in the UI
3020 if ( iter1 != end && iter2 != end )
3022 std::swap( *iter1, *iter2 );
3023 aMenuListBox.GetModel()->Move( pSourceEntry, pTargetEntry );
3024 aMenuListBox.MakeVisible( pSourceEntry );
3026 bModified = sal_True;
3030 if ( bModified )
3032 UpdateButtonStates();
3035 return 0;
3038 SvxEntries* SvxMainMenuOrganizerDialog::GetEntries()
3040 return pEntries;
3043 SvxConfigEntry* SvxMainMenuOrganizerDialog::GetSelectedEntry()
3045 return (SvxConfigEntry*)aMenuListBox.FirstSelected()->GetUserData();
3048 const OUString&
3049 SvxConfigEntry::GetHelpText()
3051 if ( aHelpText.getLength() == 0 )
3053 if ( aCommand.getLength() )
3055 aHelpText = Application::GetHelp()->GetHelpText( aCommand, NULL );
3059 return aHelpText;
3062 SvxConfigEntry::SvxConfigEntry( const OUString& rDisplayName,
3063 const OUString& rCommandURL, bool bPopup, bool bParentData )
3064 : nId( 1 )
3065 , aLabel(rDisplayName)
3066 , aCommand(rCommandURL)
3067 , bPopUp(bPopup)
3068 , bStrEdited( sal_False )
3069 , bIsUserDefined( sal_False )
3070 , bIsMain( sal_False )
3071 , bIsParentData( bParentData )
3072 , bIsVisible( sal_True )
3073 , nStyle( 0 )
3074 , pEntries( 0 )
3076 if (bPopUp)
3078 pEntries = new SvxEntries();
3082 SvxConfigEntry::~SvxConfigEntry()
3084 if ( pEntries != NULL )
3086 SvxEntries::const_iterator iter = pEntries->begin();
3088 for ( ; iter != pEntries->end(); iter++ )
3090 delete *iter;
3092 delete pEntries;
3096 bool SvxConfigEntry::IsMovable()
3098 if ( IsPopup() && !IsMain() )
3100 return sal_False;
3102 return sal_True;
3105 bool SvxConfigEntry::IsDeletable()
3107 if ( IsMain() && !IsUserDefined() )
3109 return sal_False;
3111 return sal_True;
3114 bool SvxConfigEntry::IsRenamable()
3116 if ( IsMain() && !IsUserDefined() )
3118 return sal_False;
3120 return sal_True;
3123 SvxToolbarConfigPage::SvxToolbarConfigPage(
3124 Window *pParent, const SfxItemSet& rSet )
3126 SvxConfigPage( pParent, rSet )
3128 SetHelpId( HID_SVX_CONFIG_TOOLBAR );
3130 aContentsListBox = new SvxToolbarEntriesListBox(this, CUI_RES(BOX_ENTRIES));
3131 FreeResource();
3132 PositionContentsListBox();
3133 aContentsListBox->SetZOrder( &aAddCommandsButton, WINDOW_ZORDER_BEFOR );
3135 aContentsListBox->SetHelpId( HID_SVX_CONFIG_TOOLBAR_CONTENTS );
3136 aNewTopLevelButton.SetHelpId( HID_SVX_NEW_TOOLBAR );
3137 aModifyTopLevelButton.SetHelpId( HID_SVX_MODIFY_TOOLBAR );
3138 aAddCommandsButton.SetHelpId( HID_SVX_NEW_TOOLBAR_ITEM );
3139 aModifyCommandButton.SetHelpId( HID_SVX_MODIFY_TOOLBAR_ITEM );
3140 aSaveInListBox.SetHelpId( HID_SVX_SAVE_IN );
3142 aTopLevelSeparator.SetText(
3143 CUI_RES ( RID_SVXSTR_PRODUCTNAME_TOOLBARS ) );
3145 aTopLevelLabel.SetText( CUI_RES( RID_SVXSTR_TOOLBAR ) );
3146 aModifyTopLevelButton.SetText( CUI_RES( RID_SVXSTR_TOOLBAR ) );
3147 aContentsSeparator.SetText( CUI_RES( RID_SVXSTR_TOOLBAR_CONTENT ) );
3148 aContentsLabel.SetText( CUI_RES( RID_SVXSTR_COMMANDS ) );
3150 aTopLevelListBox.SetSelectHdl(
3151 LINK( this, SvxToolbarConfigPage, SelectToolbar ) );
3152 aContentsListBox->SetSelectHdl(
3153 LINK( this, SvxToolbarConfigPage, SelectToolbarEntry ) );
3155 aNewTopLevelButton.SetClickHdl (
3156 LINK( this, SvxToolbarConfigPage, NewToolbarHdl ) );
3158 aAddCommandsButton.SetClickHdl (
3159 LINK( this, SvxToolbarConfigPage, AddCommandsHdl ) );
3161 aMoveUpButton.SetClickHdl ( LINK( this, SvxToolbarConfigPage, MoveHdl) );
3162 aMoveDownButton.SetClickHdl ( LINK( this, SvxToolbarConfigPage, MoveHdl) );
3163 // Always enable Up and Down buttons
3164 // added for issue i53677 by shizhoubo
3165 aMoveDownButton.Enable( sal_True );
3166 aMoveUpButton.Enable( sal_True );
3168 PopupMenu* pMenu = new PopupMenu( CUI_RES( MODIFY_TOOLBAR ) );
3169 pMenu->SetMenuFlags(
3170 pMenu->GetMenuFlags() | MENU_FLAG_ALWAYSSHOWDISABLEDENTRIES );
3172 aModifyTopLevelButton.SetPopupMenu( pMenu );
3173 aModifyTopLevelButton.SetSelectHdl(
3174 LINK( this, SvxToolbarConfigPage, ToolbarSelectHdl ) );
3176 PopupMenu* pEntry = new PopupMenu(
3177 CUI_RES( MODIFY_TOOLBAR_CONTENT ) );
3178 pEntry->SetMenuFlags(
3179 pEntry->GetMenuFlags() | MENU_FLAG_ALWAYSSHOWDISABLEDENTRIES );
3181 aModifyCommandButton.SetPopupMenu( pEntry );
3182 aModifyCommandButton.SetSelectHdl(
3183 LINK( this, SvxToolbarConfigPage, EntrySelectHdl ) );
3185 // default toolbar to select is standardbar unless a different one
3186 // has been passed in
3187 m_aURLToSelect = OUString::createFromAscii( ITEM_TOOLBAR_URL );
3188 m_aURLToSelect += OUString::createFromAscii( "standardbar" );
3190 const SfxPoolItem* pItem =
3191 rSet.GetItem( rSet.GetPool()->GetWhich( SID_CONFIG ) );
3193 if ( pItem )
3195 OUString text = ((const SfxStringItem*)pItem)->GetValue();
3196 if (text.indexOf(OUString::createFromAscii(ITEM_TOOLBAR_URL)) == 0)
3198 m_aURLToSelect = text.copy( 0 );
3202 long nTxtW = aTopLevelLabel.GetCtrlTextWidth( aTopLevelLabel.GetText() );
3203 long nCtrlW = aTopLevelLabel.GetSizePixel().Width();
3204 if ( nTxtW >= nCtrlW )
3206 long nDelta = Max( (long)10, nTxtW - nCtrlW );
3207 Size aNewSz = aTopLevelLabel.GetSizePixel();
3208 aNewSz.Width() += nDelta;
3209 aTopLevelLabel.SetSizePixel( aNewSz );
3210 aNewSz = aTopLevelListBox.GetSizePixel();
3211 aNewSz.Width() -= nDelta;
3212 Point aNewPt = aTopLevelListBox.GetPosPixel();
3213 aNewPt.X() += nDelta;
3214 aTopLevelListBox.SetPosSizePixel( aNewPt, aNewSz );
3218 SvxToolbarConfigPage::~SvxToolbarConfigPage()
3220 for ( sal_uInt16 i = 0 ; i < aSaveInListBox.GetEntryCount(); i++ )
3222 ToolbarSaveInData* pData =
3223 (ToolbarSaveInData*) aSaveInListBox.GetEntryData( i );
3225 delete pData;
3228 if ( pSelectorDlg != NULL )
3230 delete pSelectorDlg;
3234 delete aContentsListBox;
3237 void SvxToolbarConfigPage::DeleteSelectedTopLevel()
3239 sal_uInt16 nSelectionPos = aTopLevelListBox.GetSelectEntryPos();
3240 ToolbarSaveInData* pSaveInData = (ToolbarSaveInData*) GetSaveInData();
3241 pSaveInData->RemoveToolbar( GetTopLevelSelection() );
3243 if ( aTopLevelListBox.GetEntryCount() > 1 )
3245 // select next entry after the one being deleted
3246 // selection position is indexed from 0 so need to
3247 // subtract one from the entry count
3248 if ( nSelectionPos != aTopLevelListBox.GetEntryCount() - 1 )
3250 aTopLevelListBox.SelectEntryPos( nSelectionPos + 1, sal_True );
3252 else
3254 aTopLevelListBox.SelectEntryPos( nSelectionPos - 1, sal_True );
3256 aTopLevelListBox.GetSelectHdl().Call( this );
3258 // and now remove the entry
3259 aTopLevelListBox.RemoveEntry( nSelectionPos );
3261 else
3263 ReloadTopLevelListBox();
3267 bool SvxToolbarConfigPage::DeleteSelectedContent()
3269 SvLBoxEntry *pActEntry = aContentsListBox->FirstSelected();
3271 if ( pActEntry != NULL )
3273 // get currently selected entry
3274 SvxConfigEntry* pEntry =
3275 (SvxConfigEntry*) pActEntry->GetUserData();
3277 SvxConfigEntry* pToolbar = GetTopLevelSelection();
3279 // remove entry from the list for this toolbar
3280 RemoveEntry( pToolbar->GetEntries(), pEntry );
3282 // remove toolbar entry from UI
3283 aContentsListBox->GetModel()->Remove( pActEntry );
3285 // delete data for toolbar entry
3286 delete pEntry;
3288 (( ToolbarSaveInData* ) GetSaveInData())->ApplyToolbar( pToolbar );
3289 UpdateButtonStates();
3291 // if this is the last entry in the toolbar and it is a user
3292 // defined toolbar pop up a dialog asking the user if they
3293 // want to delete the toolbar
3294 if ( aContentsListBox->GetEntryCount() == 0 &&
3295 GetTopLevelSelection()->IsDeletable() )
3297 QueryBox qbox( this,
3298 CUI_RES( QBX_CONFIRM_DELETE_TOOLBAR ) );
3300 if ( qbox.Execute() == RET_YES )
3302 DeleteSelectedTopLevel();
3306 return sal_True;
3309 return sal_False;
3312 IMPL_LINK( SvxToolbarConfigPage, MoveHdl, Button *, pButton )
3314 MoveEntry( pButton == &aMoveUpButton );
3315 return 0;
3318 void SvxToolbarConfigPage::MoveEntry( bool bMoveUp )
3320 SvxConfigPage::MoveEntry( bMoveUp );
3322 // Apply change to currently selected toolbar
3323 SvxConfigEntry* pToolbar = GetTopLevelSelection();
3324 if ( pToolbar )
3325 ((ToolbarSaveInData*)GetSaveInData())->ApplyToolbar( pToolbar );
3326 else
3328 DBG_ERRORFILE( "SvxToolbarConfigPage::MoveEntry(): no entry" );
3329 UpdateButtonStates();
3333 IMPL_LINK( SvxToolbarConfigPage, ToolbarSelectHdl, MenuButton *, pButton )
3335 sal_uInt16 nSelectionPos = aTopLevelListBox.GetSelectEntryPos();
3337 SvxConfigEntry* pToolbar =
3338 (SvxConfigEntry*)aTopLevelListBox.GetEntryData( nSelectionPos );
3340 ToolbarSaveInData* pSaveInData = (ToolbarSaveInData*) GetSaveInData();
3342 switch( pButton->GetCurItemId() )
3344 case ID_DELETE:
3346 DeleteSelectedTopLevel();
3347 UpdateButtonStates();
3348 break;
3350 case ID_RENAME:
3352 String aNewName( stripHotKey( pToolbar->GetName() ) );
3353 String aDesc = CUI_RESSSTR( RID_SVXSTR_LABEL_NEW_NAME );
3355 SvxNameDialog* pNameDialog = new SvxNameDialog( this, aNewName, aDesc );
3356 pNameDialog->SetHelpId( HID_SVX_CONFIG_RENAME_TOOLBAR );
3357 pNameDialog->SetText( CUI_RESSTR( RID_SVXSTR_RENAME_TOOLBAR ) );
3359 bool ret = pNameDialog->Execute();
3361 if ( ret == RET_OK )
3363 pNameDialog->GetName(aNewName);
3365 pToolbar->SetName( aNewName );
3366 pSaveInData->ApplyToolbar( pToolbar );
3368 // have to use remove and insert to change the name
3369 aTopLevelListBox.RemoveEntry( nSelectionPos );
3370 nSelectionPos =
3371 aTopLevelListBox.InsertEntry( aNewName, nSelectionPos );
3372 aTopLevelListBox.SetEntryData( nSelectionPos, pToolbar );
3373 aTopLevelListBox.SelectEntryPos( nSelectionPos );
3376 delete pNameDialog;
3378 break;
3380 case ID_DEFAULT_STYLE:
3382 QueryBox qbox( this,
3383 CUI_RES( QBX_CONFIRM_RESTORE_DEFAULT ) );
3385 if ( qbox.Execute() == RET_YES )
3387 ToolbarSaveInData* pSaveInData_ =
3388 (ToolbarSaveInData*) GetSaveInData();
3390 pSaveInData_->RestoreToolbar( pToolbar );
3392 aTopLevelListBox.GetSelectHdl().Call( this );
3395 break;
3397 case ID_ICONS_ONLY:
3399 pToolbar->SetStyle( 0 );
3400 pSaveInData->SetSystemStyle( m_xFrame, pToolbar->GetCommand(), 0 );
3402 aTopLevelListBox.GetSelectHdl().Call( this );
3404 break;
3406 case ID_TEXT_ONLY:
3408 pToolbar->SetStyle( 1 );
3409 pSaveInData->SetSystemStyle( m_xFrame, pToolbar->GetCommand(), 1 );
3411 aTopLevelListBox.GetSelectHdl().Call( this );
3413 break;
3415 case ID_ICONS_AND_TEXT:
3417 pToolbar->SetStyle( 2 );
3418 pSaveInData->SetSystemStyle( m_xFrame, pToolbar->GetCommand(), 2 );
3420 aTopLevelListBox.GetSelectHdl().Call( this );
3422 break;
3425 return 1;
3428 IMPL_LINK( SvxToolbarConfigPage, EntrySelectHdl, MenuButton *, pButton )
3430 bool bNeedsApply = sal_False;
3432 // get currently selected toolbar
3433 SvxConfigEntry* pToolbar = GetTopLevelSelection();
3435 switch( pButton->GetCurItemId() )
3437 case ID_RENAME:
3439 SvLBoxEntry* pActEntry = aContentsListBox->GetCurEntry();
3440 SvxConfigEntry* pEntry =
3441 (SvxConfigEntry*) pActEntry->GetUserData();
3443 String aNewName( stripHotKey( pEntry->GetName() ) );
3444 String aDesc = CUI_RESSSTR( RID_SVXSTR_LABEL_NEW_NAME );
3446 SvxNameDialog* pNameDialog = new SvxNameDialog( this, aNewName, aDesc );
3447 pNameDialog->SetHelpId( HID_SVX_CONFIG_RENAME_TOOLBAR_ITEM );
3448 pNameDialog->SetText( CUI_RESSTR( RID_SVXSTR_RENAME_TOOLBAR ) );
3450 bool ret = pNameDialog->Execute();
3452 if ( ret == RET_OK ) {
3453 pNameDialog->GetName(aNewName);
3455 pEntry->SetName( aNewName );
3456 aContentsListBox->SetEntryText( pActEntry, aNewName );
3458 bNeedsApply = sal_True;
3461 delete pNameDialog;
3462 break;
3464 case ID_DEFAULT_COMMAND:
3466 SvLBoxEntry* pActEntry = aContentsListBox->GetCurEntry();
3467 SvxConfigEntry* pEntry =
3468 (SvxConfigEntry*) pActEntry->GetUserData();
3470 sal_uInt16 nSelectionPos = 0;
3472 // find position of entry within the list
3473 for ( sal_uInt16 i = 0; i < aContentsListBox->GetEntryCount(); i++ )
3475 if ( aContentsListBox->GetEntry( 0, i ) == pActEntry )
3477 nSelectionPos = i;
3478 break;
3482 ToolbarSaveInData* pSaveInData =
3483 (ToolbarSaveInData*) GetSaveInData();
3485 OUString aSystemName =
3486 pSaveInData->GetSystemUIName( pEntry->GetCommand() );
3488 if ( !pEntry->GetName().equals( aSystemName ) )
3490 pEntry->SetName( aSystemName );
3491 aContentsListBox->SetEntryText(
3492 pActEntry, stripHotKey( aSystemName ) );
3493 bNeedsApply = sal_True;
3496 uno::Sequence< OUString > aURLSeq( 1 );
3497 aURLSeq[ 0 ] = pEntry->GetCommand();
3501 GetSaveInData()->GetImageManager()->removeImages(
3502 GetImageType(), aURLSeq );
3504 // reset backup in entry
3505 pEntry->SetBackupGraphic(
3506 uno::Reference< graphic::XGraphic >() );
3508 GetSaveInData()->PersistChanges(
3509 GetSaveInData()->GetImageManager() );
3511 aContentsListBox->GetModel()->Remove( pActEntry );
3513 SvLBoxEntry* pNewLBEntry =
3514 InsertEntryIntoUI( pEntry, nSelectionPos );
3516 aContentsListBox->SetCheckButtonState( pNewLBEntry,
3517 pEntry->IsVisible() ?
3518 SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
3520 aContentsListBox->Select( pNewLBEntry );
3521 aContentsListBox->MakeVisible( pNewLBEntry );
3523 bNeedsApply = sal_True;
3525 catch ( uno::Exception& )
3527 OSL_TRACE("Error restoring image");
3529 break;
3531 case ID_BEGIN_GROUP:
3533 SvxConfigEntry* pNewEntryData = new SvxConfigEntry;
3534 pNewEntryData->SetUserDefined( sal_True );
3536 SvLBoxEntry* pNewLBEntry = InsertEntry( pNewEntryData );
3538 aContentsListBox->SetCheckButtonState(
3539 pNewLBEntry, SV_BUTTON_TRISTATE );
3541 bNeedsApply = sal_True;
3542 break;
3544 case ID_DELETE:
3546 DeleteSelectedContent();
3547 break;
3549 case ID_ICON_ONLY:
3551 break;
3553 case ID_TEXT_ONLY:
3555 break;
3557 case ID_ICON_AND_TEXT:
3559 break;
3561 case ID_CHANGE_SYMBOL:
3563 SvLBoxEntry* pActEntry = aContentsListBox->GetCurEntry();
3564 SvxConfigEntry* pEntry =
3565 (SvxConfigEntry*) pActEntry->GetUserData();
3567 sal_uInt16 nSelectionPos = 0;
3569 // find position of entry within the list
3570 for ( sal_uInt16 i = 0; i < aContentsListBox->GetEntryCount(); i++ )
3572 if ( aContentsListBox->GetEntry( 0, i ) == pActEntry )
3574 nSelectionPos = i;
3575 break;
3579 SvxIconSelectorDialog* pIconDialog =
3580 new SvxIconSelectorDialog( 0,
3581 GetSaveInData()->GetImageManager(),
3582 GetSaveInData()->GetParentImageManager() );
3584 bool ret = pIconDialog->Execute();
3586 if ( ret == RET_OK )
3588 uno::Reference< graphic::XGraphic > newgraphic =
3589 pIconDialog->GetSelectedIcon();
3591 if ( newgraphic.is() )
3593 uno::Sequence< uno::Reference< graphic::XGraphic > >
3594 aGraphicSeq( 1 );
3596 uno::Sequence< OUString > aURLSeq( 1 );
3597 aURLSeq[ 0 ] = pEntry->GetCommand();
3599 if ( !pEntry->GetBackupGraphic().is() )
3601 uno::Reference< graphic::XGraphic > backup;
3602 backup = GetGraphic(
3603 GetSaveInData()->GetImageManager(), aURLSeq[ 0 ] );
3605 if ( backup.is() )
3607 pEntry->SetBackupGraphic( backup );
3611 aGraphicSeq[ 0 ] = newgraphic;
3614 GetSaveInData()->GetImageManager()->replaceImages(
3615 GetImageType(), aURLSeq, aGraphicSeq );
3617 Image aImage( newgraphic );
3619 aContentsListBox->GetModel()->Remove( pActEntry );
3620 SvLBoxEntry* pNewLBEntry =
3621 InsertEntryIntoUI( pEntry, nSelectionPos );
3623 aContentsListBox->SetCheckButtonState( pNewLBEntry,
3624 pEntry->IsVisible() ?
3625 SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
3627 aContentsListBox->Select( pNewLBEntry );
3628 aContentsListBox->MakeVisible( pNewLBEntry );
3630 GetSaveInData()->PersistChanges(
3631 GetSaveInData()->GetImageManager() );
3633 catch ( uno::Exception& )
3635 OSL_TRACE("Error replacing image");
3640 delete pIconDialog;
3642 break;
3644 case ID_RESET_SYMBOL:
3646 SvLBoxEntry* pActEntry = aContentsListBox->GetCurEntry();
3647 SvxConfigEntry* pEntry =
3648 (SvxConfigEntry*) pActEntry->GetUserData();
3650 sal_uInt16 nSelectionPos = 0;
3652 // find position of entry within the list
3653 for ( sal_uInt16 i = 0; i < aContentsListBox->GetEntryCount(); i++ )
3655 if ( aContentsListBox->GetEntry( 0, i ) == pActEntry )
3657 nSelectionPos = i;
3658 break;
3662 uno::Reference< graphic::XGraphic > backup =
3663 pEntry->GetBackupGraphic();
3665 uno::Sequence< uno::Reference< graphic::XGraphic > >
3666 aGraphicSeq( 1 );
3667 aGraphicSeq[ 0 ] = backup;
3669 uno::Sequence< OUString > aURLSeq( 1 );
3670 aURLSeq[ 0 ] = pEntry->GetCommand();
3674 GetSaveInData()->GetImageManager()->replaceImages(
3675 GetImageType(), aURLSeq, aGraphicSeq );
3677 Image aImage( backup );
3678 aContentsListBox->GetModel()->Remove( pActEntry );
3680 SvLBoxEntry* pNewLBEntry =
3681 InsertEntryIntoUI( pEntry, nSelectionPos );
3683 aContentsListBox->SetCheckButtonState( pNewLBEntry,
3684 pEntry->IsVisible() ?
3685 SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
3687 aContentsListBox->Select( pNewLBEntry );
3688 aContentsListBox->MakeVisible( pNewLBEntry );
3690 // reset backup in entry
3691 pEntry->SetBackupGraphic(
3692 uno::Reference< graphic::XGraphic >() );
3694 GetSaveInData()->PersistChanges(
3695 GetSaveInData()->GetImageManager() );
3697 catch ( uno::Exception& )
3699 OSL_TRACE("Error resetting image");
3701 break;
3705 if ( bNeedsApply == sal_True )
3707 (( ToolbarSaveInData* ) GetSaveInData())->ApplyToolbar( pToolbar );
3708 UpdateButtonStates();
3711 return 1;
3714 void SvxToolbarConfigPage::Init()
3716 // ensure that the UI is cleared before populating it
3717 aTopLevelListBox.Clear();
3718 aContentsListBox->Clear();
3720 ReloadTopLevelListBox();
3722 sal_uInt16 nPos = 0;
3723 if ( m_aURLToSelect.getLength() != 0 )
3725 for ( sal_uInt16 i = 0 ; i < aTopLevelListBox.GetEntryCount(); i++ )
3727 SvxConfigEntry* pData =
3728 (SvxConfigEntry*) aTopLevelListBox.GetEntryData( i );
3730 if ( pData->GetCommand().equals( m_aURLToSelect ) )
3732 nPos = i;
3733 break;
3737 // in future select the default toolbar: Standard
3738 m_aURLToSelect = OUString::createFromAscii( ITEM_TOOLBAR_URL );
3739 m_aURLToSelect += OUString::createFromAscii( "standardbar" );
3742 aTopLevelListBox.SelectEntryPos(nPos, sal_True);
3743 aTopLevelListBox.GetSelectHdl().Call(this);
3746 SaveInData* SvxToolbarConfigPage::CreateSaveInData(
3747 const uno::Reference< css::ui::XUIConfigurationManager >& xCfgMgr,
3748 const uno::Reference< css::ui::XUIConfigurationManager >& xParentCfgMgr,
3749 const OUString& aModuleId,
3750 bool bDocConfig )
3752 return static_cast< SaveInData* >(
3753 new ToolbarSaveInData( xCfgMgr, xParentCfgMgr, aModuleId, bDocConfig ));
3756 ToolbarSaveInData::ToolbarSaveInData(
3757 const uno::Reference < css::ui::XUIConfigurationManager >& xCfgMgr,
3758 const uno::Reference < css::ui::XUIConfigurationManager >& xParentCfgMgr,
3759 const OUString& aModuleId,
3760 bool docConfig ) :
3762 SaveInData ( xCfgMgr, xParentCfgMgr, aModuleId, docConfig ),
3763 pRootEntry ( NULL ),
3764 m_aDescriptorContainer ( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_CONTAINER ) )
3767 // Initialize the m_xPersistentWindowState variable which is used
3768 // to get the default properties of system toolbars such as name
3769 uno::Reference< container::XNameAccess > xPWSS(
3770 m_xServiceManager->createInstance(
3771 OUString( RTL_CONSTASCII_USTRINGPARAM(
3772 "com.sun.star.ui.WindowStateConfiguration" ) ) ),
3773 uno::UNO_QUERY );
3775 if ( xPWSS.is() )
3776 xPWSS->getByName( aModuleId ) >>= m_xPersistentWindowState;
3779 ToolbarSaveInData::~ToolbarSaveInData()
3781 delete pRootEntry;
3784 void ToolbarSaveInData::SetSystemStyle(
3785 uno::Reference< frame::XFrame > xFrame,
3786 const OUString& rResourceURL,
3787 sal_Int32 nStyle )
3789 // change the style using the API
3790 SetSystemStyle( rResourceURL, nStyle );
3792 // this code is a temporary hack as the UI is not updating after
3793 // changing the toolbar style via the API
3794 uno::Reference< css::frame::XLayoutManager > xLayoutManager;
3795 Window *window = NULL;
3797 uno::Reference< beans::XPropertySet > xPropSet( xFrame, uno::UNO_QUERY );
3798 if ( xPropSet.is() )
3800 uno::Any a = xPropSet->getPropertyValue(
3801 OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ) ) );
3802 a >>= xLayoutManager;
3805 if ( xLayoutManager.is() )
3807 uno::Reference< css::ui::XUIElement > xUIElement =
3808 xLayoutManager->getElement( rResourceURL );
3810 // check reference before we call getRealInterface. The layout manager
3811 // can only provide references for elements that have been created
3812 // before. It's possible that the current element is not available.
3813 uno::Reference< com::sun::star::awt::XWindow > xWindow;
3814 if ( xUIElement.is() )
3815 xWindow = uno::Reference< com::sun::star::awt::XWindow >(
3816 xUIElement->getRealInterface(), uno::UNO_QUERY );
3818 window = VCLUnoHelper::GetWindow( xWindow );
3821 if ( window != NULL && window->GetType() == WINDOW_TOOLBOX )
3823 ToolBox* toolbox = (ToolBox*)window;
3825 if ( nStyle == 0 )
3827 toolbox->SetButtonType( BUTTON_SYMBOL );
3829 else if ( nStyle == 1 )
3831 toolbox->SetButtonType( BUTTON_TEXT );
3833 if ( nStyle == 2 )
3835 toolbox->SetButtonType( BUTTON_SYMBOLTEXT );
3840 void ToolbarSaveInData::SetSystemStyle(
3841 const OUString& rResourceURL,
3842 sal_Int32 nStyle )
3844 if ( rResourceURL.indexOf( OUString::createFromAscii( "private" ) ) == 0 &&
3845 m_xPersistentWindowState.is() &&
3846 m_xPersistentWindowState->hasByName( rResourceURL ) )
3850 uno::Sequence< beans::PropertyValue > aProps;
3852 uno::Any a( m_xPersistentWindowState->getByName( rResourceURL ) );
3854 if ( a >>= aProps )
3856 for ( sal_Int32 i = 0; i < aProps.getLength(); i++ )
3858 if ( aProps[ i ].Name.equalsAscii( ITEM_DESCRIPTOR_STYLE) )
3860 aProps[ i ].Value = uno::makeAny( nStyle );
3861 break;
3866 uno::Reference< container::XNameReplace >
3867 xNameReplace( m_xPersistentWindowState, uno::UNO_QUERY );
3869 xNameReplace->replaceByName( rResourceURL, uno::makeAny( aProps ) );
3871 catch ( uno::Exception& )
3873 // do nothing, a default value is returned
3874 OSL_TRACE("Exception setting toolbar style");
3879 sal_Int32 ToolbarSaveInData::GetSystemStyle( const OUString& rResourceURL )
3881 sal_Int32 result = 0;
3883 if ( rResourceURL.indexOf( OUString::createFromAscii( "private" ) ) == 0 &&
3884 m_xPersistentWindowState.is() &&
3885 m_xPersistentWindowState->hasByName( rResourceURL ) )
3889 uno::Sequence< beans::PropertyValue > aProps;
3890 uno::Any a( m_xPersistentWindowState->getByName( rResourceURL ) );
3892 if ( a >>= aProps )
3894 for ( sal_Int32 i = 0; i < aProps.getLength(); i++ )
3896 if ( aProps[ i ].Name.equalsAscii( ITEM_DESCRIPTOR_STYLE) )
3898 aProps[i].Value >>= result;
3899 break;
3904 catch ( uno::Exception& )
3906 // do nothing, a default value is returned
3910 return result;
3913 OUString ToolbarSaveInData::GetSystemUIName( const OUString& rResourceURL )
3915 OUString result;
3917 if ( rResourceURL.indexOf( OUString::createFromAscii( "private" ) ) == 0 &&
3918 m_xPersistentWindowState.is() &&
3919 m_xPersistentWindowState->hasByName( rResourceURL ) )
3923 uno::Sequence< beans::PropertyValue > aProps;
3924 uno::Any a( m_xPersistentWindowState->getByName( rResourceURL ) );
3926 if ( a >>= aProps )
3928 for ( sal_Int32 i = 0; i < aProps.getLength(); i++ )
3930 if ( aProps[ i ].Name.equalsAscii( ITEM_DESCRIPTOR_UINAME) )
3932 aProps[ i ].Value >>= result;
3937 catch ( uno::Exception& )
3939 // do nothing, an empty UIName will be returned
3943 if ( rResourceURL.indexOf( OUString::createFromAscii( ".uno" ) ) == 0 &&
3944 m_xCommandToLabelMap.is() &&
3945 m_xCommandToLabelMap->hasByName( rResourceURL ) )
3947 uno::Any a;
3950 a = m_xCommandToLabelMap->getByName( rResourceURL );
3952 uno::Sequence< beans::PropertyValue > aPropSeq;
3953 if ( a >>= aPropSeq )
3955 for ( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
3957 if ( aPropSeq[i].Name.equalsAscii( ITEM_DESCRIPTOR_LABEL ) )
3959 aPropSeq[i].Value >>= result;
3964 catch ( uno::Exception& )
3966 // not a system command name
3970 return result;
3973 bool EntrySort( SvxConfigEntry* a, SvxConfigEntry* b )
3975 return a->GetName().compareTo( b->GetName() ) < 0;
3978 SvxEntries* ToolbarSaveInData::GetEntries()
3980 typedef ::std::hash_map< ::rtl::OUString,
3981 bool,
3982 ::rtl::OUStringHash,
3983 ::std::equal_to< ::rtl::OUString > > ToolbarInfo;
3985 ToolbarInfo aToolbarInfo;
3987 if ( pRootEntry == NULL )
3990 pRootEntry = new SvxConfigEntry(
3991 String::CreateFromAscii("MainToolbars"), String(), sal_True );
3993 uno::Sequence< uno::Sequence < beans::PropertyValue > > info =
3994 GetConfigManager()->getUIElementsInfo(
3995 css::ui::UIElementType::TOOLBAR );
3997 for ( sal_Int32 i = 0; i < info.getLength(); i++ )
3999 uno::Sequence< beans::PropertyValue > props = info[ i ];
4001 OUString url;
4002 OUString systemname;
4003 OUString uiname;
4005 for ( sal_Int32 j = 0; j < props.getLength(); j++ )
4007 if ( props[ j ].Name.equalsAscii( ITEM_DESCRIPTOR_RESOURCEURL) )
4009 props[ j ].Value >>= url;
4010 systemname = url.copy( url.lastIndexOf( '/' ) + 1 );
4012 else if ( props[ j ].Name.equalsAscii( ITEM_DESCRIPTOR_UINAME) )
4014 props[ j ].Value >>= uiname;
4020 uno::Reference< container::XIndexAccess > xToolbarSettings =
4021 GetConfigManager()->getSettings( url, sal_False );
4023 if ( uiname.getLength() == 0 )
4025 // try to get the name from m_xPersistentWindowState
4026 uiname = GetSystemUIName( url );
4028 if ( uiname.getLength() == 0 )
4030 uiname = systemname;
4034 SvxConfigEntry* pEntry = new SvxConfigEntry(
4035 uiname, url, sal_True );
4037 pEntry->SetMain( sal_True );
4038 pEntry->SetStyle( GetSystemStyle( url ) );
4041 // insert into hash_map to filter duplicates from the parent
4042 aToolbarInfo.insert( ToolbarInfo::value_type( systemname, true ));
4044 OUString custom = OUString::createFromAscii(CUSTOM_TOOLBAR_STR);
4045 if ( systemname.indexOf( custom ) == 0 )
4047 pEntry->SetUserDefined( sal_True );
4049 else
4051 pEntry->SetUserDefined( sal_False );
4054 pRootEntry->GetEntries()->push_back( pEntry );
4056 LoadToolbar( xToolbarSettings, pEntry );
4058 catch ( container::NoSuchElementException& )
4060 // TODO, handle resourceURL with no settings
4064 uno::Reference< css::ui::XUIConfigurationManager > xParentCfgMgr = GetParentConfigManager();
4065 if ( xParentCfgMgr.is() )
4067 // Retrieve also the parent toolbars to make it possible
4068 // to configure module toolbars and save them into the document
4069 // config manager.
4070 uno::Sequence< uno::Sequence < beans::PropertyValue > > info_ =
4071 xParentCfgMgr->getUIElementsInfo(
4072 css::ui::UIElementType::TOOLBAR );
4074 for ( sal_Int32 i = 0; i < info_.getLength(); i++ )
4076 uno::Sequence< beans::PropertyValue > props = info_[ i ];
4078 OUString url;
4079 OUString systemname;
4080 OUString uiname;
4082 for ( sal_Int32 j = 0; j < props.getLength(); j++ )
4084 if ( props[ j ].Name.equalsAscii( ITEM_DESCRIPTOR_RESOURCEURL) )
4086 props[ j ].Value >>= url;
4087 systemname = url.copy( url.lastIndexOf( '/' ) + 1 );
4089 else if ( props[ j ].Name.equalsAscii( ITEM_DESCRIPTOR_UINAME) )
4091 props[ j ].Value >>= uiname;
4095 // custom toolbars of the parent are not visible in the document layer
4096 OUString custom = OUString::createFromAscii(CUSTOM_TOOLBAR_STR);
4097 if ( systemname.indexOf( custom ) == 0 )
4098 continue;
4100 // check if toolbar is already in the document layer
4101 ToolbarInfo::const_iterator pIter = aToolbarInfo.find( systemname );
4102 if ( pIter == aToolbarInfo.end() )
4104 aToolbarInfo.insert( ToolbarInfo::value_type( systemname, true ));
4108 uno::Reference< container::XIndexAccess > xToolbarSettings =
4109 xParentCfgMgr->getSettings( url, sal_False );
4111 if ( uiname.getLength() == 0 )
4113 // try to get the name from m_xPersistentWindowState
4114 uiname = GetSystemUIName( url );
4116 if ( uiname.getLength() == 0 )
4118 uiname = systemname;
4122 SvxConfigEntry* pEntry = new SvxConfigEntry(
4123 uiname, url, sal_True, sal_True );
4125 pEntry->SetMain( sal_True );
4126 pEntry->SetStyle( GetSystemStyle( url ) );
4128 if ( systemname.indexOf( custom ) == 0 )
4130 pEntry->SetUserDefined( sal_True );
4132 else
4134 pEntry->SetUserDefined( sal_False );
4137 pRootEntry->GetEntries()->push_back( pEntry );
4139 LoadToolbar( xToolbarSettings, pEntry );
4141 catch ( container::NoSuchElementException& )
4143 // TODO, handle resourceURL with no settings
4149 std::sort( GetEntries()->begin(), GetEntries()->end(), EntrySort );
4152 return pRootEntry->GetEntries();
4155 void
4156 ToolbarSaveInData::SetEntries( SvxEntries* pNewEntries )
4158 // delete old menu hierarchy first
4159 if ( pRootEntry != NULL && pRootEntry->GetEntries() != NULL )
4161 delete pRootEntry->GetEntries();
4164 // now set new menu hierarchy
4165 pRootEntry->SetEntries( pNewEntries );
4168 bool
4169 ToolbarSaveInData::HasURL( const OUString& rURL )
4171 SvxEntries::const_iterator iter = GetEntries()->begin();
4172 SvxEntries::const_iterator end = GetEntries()->end();
4174 while ( iter != end )
4176 SvxConfigEntry* pEntry = *iter;
4178 if ( pEntry->GetCommand().equals( rURL ) )
4180 if ( pEntry->IsParentData() )
4181 return sal_False;
4182 else
4183 return sal_True;
4186 iter++;
4188 return sal_False;
4191 bool ToolbarSaveInData::HasSettings()
4193 // return true if there is at least one toolbar entry
4194 if ( GetEntries()->size() > 0 )
4196 return sal_True;
4198 return sal_False;
4201 void ToolbarSaveInData::Reset()
4203 SvxEntries::const_iterator toolbars = GetEntries()->begin();
4204 SvxEntries::const_iterator end = GetEntries()->end();
4206 // reset each toolbar by calling removeSettings for it's toolbar URL
4207 for ( ; toolbars != end; toolbars++ )
4209 SvxConfigEntry* pToolbar = *toolbars;
4213 OUString url = pToolbar->GetCommand();
4214 GetConfigManager()->removeSettings( url );
4216 catch ( uno::Exception& )
4218 // error occured removing the settings
4219 // TODO - add error dialog in future?
4223 // persist changes to toolbar storage
4224 PersistChanges( GetConfigManager() );
4226 // now delete the root SvxConfigEntry the next call to GetEntries()
4227 // causes it to be reinitialised
4228 delete pRootEntry;
4229 pRootEntry = NULL;
4231 // reset all icons to default
4234 GetImageManager()->reset();
4235 PersistChanges( GetImageManager() );
4237 catch ( uno::Exception& )
4239 OSL_TRACE("Error resetting all icons when resetting toolbars");
4243 bool ToolbarSaveInData::Apply()
4245 // toolbar changes are instantly applied
4246 return sal_False;
4249 void ToolbarSaveInData::ApplyToolbar(
4250 uno::Reference< container::XIndexContainer >& rToolbarBar,
4251 uno::Reference< lang::XSingleComponentFactory >& rFactory,
4252 SvxConfigEntry* pToolbarData )
4254 SvxEntries::const_iterator iter = pToolbarData->GetEntries()->begin();
4255 SvxEntries::const_iterator end = pToolbarData->GetEntries()->end();
4257 for ( ; iter != end; iter++ )
4259 SvxConfigEntry* pEntry = *iter;
4261 if ( pEntry->IsPopup() )
4263 uno::Sequence< beans::PropertyValue > aPropValueSeq =
4264 ConvertToolbarEntry( m_xCommandToLabelMap, pEntry );
4266 uno::Reference< container::XIndexContainer > xSubMenuBar(
4267 rFactory->createInstanceWithContext( m_xComponentContext ),
4268 uno::UNO_QUERY );
4270 sal_Int32 nIndex = aPropValueSeq.getLength();
4271 aPropValueSeq.realloc( nIndex + 1 );
4272 aPropValueSeq[nIndex].Name = m_aDescriptorContainer;
4273 aPropValueSeq[nIndex].Value <<= xSubMenuBar;
4274 rToolbarBar->insertByIndex(
4275 rToolbarBar->getCount(), uno::makeAny( aPropValueSeq ));
4277 ApplyToolbar( xSubMenuBar, rFactory, pEntry );
4279 else if ( pEntry->IsSeparator() )
4281 rToolbarBar->insertByIndex(
4282 rToolbarBar->getCount(), uno::makeAny( m_aSeparatorSeq ));
4284 else
4286 uno::Sequence< beans::PropertyValue > aPropValueSeq =
4287 ConvertToolbarEntry( m_xCommandToLabelMap, pEntry );
4289 rToolbarBar->insertByIndex(
4290 rToolbarBar->getCount(), uno::makeAny( aPropValueSeq ));
4295 void ToolbarSaveInData::ApplyToolbar( SvxConfigEntry* pToolbar )
4297 // Apply new toolbar structure to our settings container
4298 uno::Reference< container::XIndexAccess > xSettings(
4299 GetConfigManager()->createSettings(), uno::UNO_QUERY );
4301 uno::Reference< container::XIndexContainer > xIndexContainer (
4302 xSettings, uno::UNO_QUERY );
4304 uno::Reference< lang::XSingleComponentFactory > xFactory (
4305 xSettings, uno::UNO_QUERY );
4307 ApplyToolbar( xIndexContainer, xFactory, pToolbar );
4309 uno::Reference< beans::XPropertySet > xProps(
4310 xSettings, uno::UNO_QUERY );
4312 if ( pToolbar->IsUserDefined() )
4314 xProps->setPropertyValue(
4315 OUString::createFromAscii( ITEM_DESCRIPTOR_UINAME ),
4316 uno::makeAny( OUString( pToolbar->GetName() ) ) );
4321 if ( GetConfigManager()->hasSettings( pToolbar->GetCommand() ) )
4323 GetConfigManager()->replaceSettings(
4324 pToolbar->GetCommand(), xSettings );
4326 else
4328 GetConfigManager()->insertSettings(
4329 pToolbar->GetCommand(), xSettings );
4330 if ( pToolbar->IsParentData() )
4331 pToolbar->SetParentData( false );
4334 catch ( container::NoSuchElementException& )
4336 OSL_TRACE("caught container::NoSuchElementException saving settings");
4338 catch ( com::sun::star::io::IOException& )
4340 OSL_TRACE("caught IOException saving settings");
4342 catch ( com::sun::star::uno::Exception& )
4344 OSL_TRACE("caught some other exception saving settings");
4347 PersistChanges( GetConfigManager() );
4350 void ToolbarSaveInData::CreateToolbar( SvxConfigEntry* pToolbar )
4352 // show the new toolbar in the UI also
4353 uno::Reference< container::XIndexAccess >
4354 xSettings( GetConfigManager()->createSettings(), uno::UNO_QUERY );
4356 uno::Reference< container::XIndexContainer >
4357 xIndexContainer ( xSettings, uno::UNO_QUERY );
4359 uno::Reference< beans::XPropertySet >
4360 xPropertySet( xSettings, uno::UNO_QUERY );
4362 xPropertySet->setPropertyValue(
4363 OUString::createFromAscii( ITEM_DESCRIPTOR_UINAME ),
4364 uno::makeAny( pToolbar->GetName() ) );
4368 GetConfigManager()->insertSettings( pToolbar->GetCommand(), xSettings );
4370 catch ( container::ElementExistException& )
4372 OSL_TRACE("caught ElementExistsException saving settings");
4374 catch ( com::sun::star::lang::IllegalArgumentException& )
4376 OSL_TRACE("caught IOException saving settings");
4378 catch ( com::sun::star::lang::IllegalAccessException& )
4380 OSL_TRACE("caught IOException saving settings");
4382 catch ( com::sun::star::uno::Exception& )
4384 OSL_TRACE("caught some other exception saving settings");
4387 GetEntries()->push_back( pToolbar );
4389 PersistChanges( GetConfigManager() );
4392 void ToolbarSaveInData::RemoveToolbar( SvxConfigEntry* pToolbar )
4396 OUString url = pToolbar->GetCommand();
4397 GetConfigManager()->removeSettings( url );
4398 RemoveEntry( GetEntries(), pToolbar );
4399 delete pToolbar;
4401 PersistChanges( GetConfigManager() );
4403 // remove the persistent window state data
4404 css::uno::Reference< css::container::XNameContainer > xNameContainer(
4405 m_xPersistentWindowState, css::uno::UNO_QUERY_THROW );
4407 xNameContainer->removeByName( url );
4409 catch ( uno::Exception& )
4411 // error occured removing the settings
4415 void ToolbarSaveInData::RestoreToolbar( SvxConfigEntry* pToolbar )
4417 OUString url = pToolbar->GetCommand();
4419 // Restore of toolbar is done by removing it from
4420 // it's configuration manager and then getting it again
4421 bool bParentToolbar = pToolbar->IsParentData();
4423 // Cannot restore parent toolbar
4424 if ( bParentToolbar )
4425 return;
4429 GetConfigManager()->removeSettings( url );
4430 pToolbar->GetEntries()->clear();
4431 PersistChanges( GetConfigManager() );
4433 catch ( uno::Exception& )
4435 // if an error occurs removing the settings then just return
4436 return;
4439 // Now reload the toolbar settings
4442 uno::Reference< container::XIndexAccess > xToolbarSettings;
4443 if ( IsDocConfig() )
4445 xToolbarSettings = GetParentConfigManager()->getSettings( url, sal_False );
4446 pToolbar->SetParentData( true );
4448 else
4449 xToolbarSettings = GetConfigManager()->getSettings( url, sal_False );
4451 LoadToolbar( xToolbarSettings, pToolbar );
4453 // After reloading, ensure that the icon is reset of each entry
4454 // in the toolbar
4455 SvxEntries::const_iterator iter = pToolbar->GetEntries()->begin();
4456 uno::Sequence< OUString > aURLSeq( 1 );
4457 for ( ; iter != pToolbar->GetEntries()->end(); iter++ )
4459 SvxConfigEntry* pEntry = *iter;
4460 aURLSeq[ 0 ] = pEntry->GetCommand();
4464 GetImageManager()->removeImages( GetImageType(), aURLSeq );
4466 catch ( uno::Exception& )
4468 OSL_TRACE("Error restoring icon when resetting toolbar");
4471 PersistChanges( GetImageManager() );
4473 catch ( container::NoSuchElementException& )
4475 // cannot find the resource URL after removing it
4476 // so no entry will appear in the toolbar list
4480 bool ToolbarSaveInData::LoadToolbar(
4481 const uno::Reference< container::XIndexAccess >& xToolbarSettings,
4482 SvxConfigEntry* pParentData )
4484 SvxEntries* pEntries = pParentData->GetEntries();
4486 for ( sal_Int32 nIndex = 0; nIndex < xToolbarSettings->getCount(); nIndex++ )
4488 uno::Reference< container::XIndexAccess > xSubMenu;
4489 OUString aCommandURL;
4490 OUString aLabel;
4491 bool bIsUserDefined = sal_True;
4492 sal_Bool bIsVisible;
4493 sal_Int32 nStyle;
4495 sal_uInt16 nType( css::ui::ItemType::DEFAULT );
4497 bool bItem = GetToolbarItemData( xToolbarSettings, nIndex, aCommandURL,
4498 aLabel, nType, bIsVisible, nStyle, xSubMenu );
4500 if ( bItem )
4502 if ( nType == css::ui::ItemType::DEFAULT )
4504 uno::Any a;
4507 a = m_xCommandToLabelMap->getByName( aCommandURL );
4508 bIsUserDefined = sal_False;
4510 catch ( container::NoSuchElementException& )
4512 bIsUserDefined = sal_True;
4515 // If custom label not set retrieve it from the command
4516 // to info service
4517 if ( aLabel.equals( OUString() ) )
4519 uno::Sequence< beans::PropertyValue > aPropSeq;
4520 if ( a >>= aPropSeq )
4522 for ( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
4524 if ( aPropSeq[i].Name.equalsAscii( ITEM_DESCRIPTOR_LABEL ) )
4526 aPropSeq[i].Value >>= aLabel;
4527 break;
4533 if ( xSubMenu.is() )
4535 SvxConfigEntry* pEntry = new SvxConfigEntry(
4536 aLabel, aCommandURL, sal_True );
4538 pEntry->SetUserDefined( bIsUserDefined );
4539 pEntry->SetVisible( bIsVisible );
4541 pEntries->push_back( pEntry );
4543 LoadToolbar( xSubMenu, pEntry );
4545 else
4547 SvxConfigEntry* pEntry = new SvxConfigEntry(
4548 aLabel, aCommandURL, sal_False );
4549 pEntry->SetUserDefined( bIsUserDefined );
4550 pEntry->SetVisible( bIsVisible );
4551 pEntry->SetStyle( nStyle );
4552 pEntries->push_back( pEntry );
4555 else
4557 SvxConfigEntry* pEntry = new SvxConfigEntry;
4558 pEntry->SetUserDefined( bIsUserDefined );
4559 pEntries->push_back( pEntry );
4564 return true;
4567 IMPL_LINK( SvxToolbarConfigPage, SelectToolbarEntry, Control *, pBox )
4569 (void)pBox;
4570 UpdateButtonStates();
4571 return 1;
4574 void SvxToolbarConfigPage::UpdateButtonStates()
4576 PopupMenu* pPopup = aModifyCommandButton.GetPopupMenu();
4577 pPopup->EnableItem( ID_RENAME, sal_False );
4578 pPopup->EnableItem( ID_DELETE, sal_False );
4579 pPopup->EnableItem( ID_BEGIN_GROUP, sal_False );
4580 pPopup->EnableItem( ID_DEFAULT_COMMAND, sal_False );
4581 pPopup->EnableItem( ID_ICON_ONLY, sal_False );
4582 pPopup->EnableItem( ID_ICON_AND_TEXT, sal_False );
4583 pPopup->EnableItem( ID_TEXT_ONLY, sal_False );
4584 pPopup->EnableItem( ID_CHANGE_SYMBOL, sal_False );
4585 pPopup->EnableItem( ID_RESET_SYMBOL, sal_False );
4587 aDescriptionField.Clear();
4589 SvLBoxEntry* selection = aContentsListBox->GetCurEntry();
4590 if ( aContentsListBox->GetEntryCount() == 0 || selection == NULL )
4592 return;
4595 SvxConfigEntry* pEntryData = (SvxConfigEntry*) selection->GetUserData();
4596 if ( pEntryData->IsSeparator() )
4597 pPopup->EnableItem( ID_DELETE, sal_True );
4598 else
4600 pPopup->EnableItem( ID_BEGIN_GROUP, sal_True );
4601 pPopup->EnableItem( ID_DELETE, sal_True );
4602 pPopup->EnableItem( ID_RENAME, sal_True );
4603 pPopup->EnableItem( ID_ICON_ONLY, sal_True );
4604 pPopup->EnableItem( ID_ICON_AND_TEXT, sal_True );
4605 pPopup->EnableItem( ID_TEXT_ONLY, sal_True );
4606 pPopup->EnableItem( ID_CHANGE_SYMBOL, sal_True );
4608 if ( !pEntryData->IsUserDefined() )
4609 pPopup->EnableItem( ID_DEFAULT_COMMAND, sal_True );
4611 if ( pEntryData->IsIconModified() )
4612 pPopup->EnableItem( ID_RESET_SYMBOL, sal_True );
4614 aDescriptionField.SetNewText( pEntryData->GetHelpText() );
4618 short SvxToolbarConfigPage::QueryReset()
4620 String msg =
4621 String( CUI_RES( RID_SVXSTR_CONFIRM_TOOLBAR_RESET ) );
4623 String saveInName = aSaveInListBox.GetEntry(
4624 aSaveInListBox.GetSelectEntryPos() );
4626 OUString label = replaceSaveInName( msg, saveInName );
4628 QueryBox qbox( this, WB_YES_NO, label );
4630 return qbox.Execute();
4633 IMPL_LINK( SvxToolbarConfigPage, SelectToolbar, ListBox *, pBox )
4635 (void)pBox;
4637 aContentsListBox->Clear();
4639 SvxConfigEntry* pToolbar = GetTopLevelSelection();
4640 if ( pToolbar == NULL )
4642 aModifyTopLevelButton.Enable( sal_False );
4643 aModifyCommandButton.Enable( sal_False );
4644 aAddCommandsButton.Enable( sal_False );
4646 return 0;
4649 aModifyTopLevelButton.Enable( sal_True );
4650 aModifyCommandButton.Enable( sal_True );
4651 aAddCommandsButton.Enable( sal_True );
4653 PopupMenu* pPopup = aModifyTopLevelButton.GetPopupMenu();
4655 pPopup->EnableItem( ID_DELETE, pToolbar->IsDeletable() );
4656 pPopup->EnableItem( ID_RENAME, pToolbar->IsRenamable() );
4657 pPopup->EnableItem( ID_DEFAULT_STYLE, !pToolbar->IsRenamable() );
4659 switch( pToolbar->GetStyle() )
4661 case 0:
4663 pPopup->CheckItem( ID_ICONS_ONLY );
4664 break;
4666 case 1:
4668 pPopup->CheckItem( ID_TEXT_ONLY );
4669 break;
4671 case 2:
4673 pPopup->CheckItem( ID_ICONS_AND_TEXT );
4674 break;
4678 SvxEntries* pEntries = pToolbar->GetEntries();
4679 SvxEntries::const_iterator iter = pEntries->begin();
4681 for ( ; iter != pEntries->end(); iter++ )
4683 SvxConfigEntry* pEntry = *iter;
4685 SvLBoxEntry* pNewLBEntry = InsertEntryIntoUI( pEntry );
4687 if (pEntry->IsBinding())
4689 aContentsListBox->SetCheckButtonState( pNewLBEntry,
4690 pEntry->IsVisible() ? SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
4692 else
4694 aContentsListBox->SetCheckButtonState(
4695 pNewLBEntry, SV_BUTTON_TRISTATE );
4699 UpdateButtonStates();
4701 return 0;
4704 IMPL_LINK( SvxToolbarConfigPage, NewToolbarHdl, Button *, pButton )
4706 (void)pButton;
4708 String prefix =
4709 String( CUI_RES( RID_SVXSTR_NEW_TOOLBAR ) );
4711 OUString aNewName =
4712 generateCustomName( prefix, GetSaveInData()->GetEntries() );
4714 OUString aNewURL =
4715 generateCustomURL( GetSaveInData()->GetEntries() );
4717 SvxNewToolbarDialog* pNameDialog = new SvxNewToolbarDialog( 0, aNewName );
4719 sal_uInt16 nInsertPos;
4720 for ( sal_uInt16 i = 0 ; i < aSaveInListBox.GetEntryCount(); i++ )
4722 SaveInData* pData =
4723 (SaveInData*) aSaveInListBox.GetEntryData( i );
4725 nInsertPos = pNameDialog->aSaveInListBox.InsertEntry(
4726 aSaveInListBox.GetEntry( i ) );
4728 pNameDialog->aSaveInListBox.SetEntryData( nInsertPos, pData );
4731 pNameDialog->aSaveInListBox.SelectEntryPos(
4732 aSaveInListBox.GetSelectEntryPos(), sal_True );
4734 bool ret = pNameDialog->Execute();
4735 if ( ret == RET_OK )
4737 pNameDialog->GetName( aNewName );
4739 nInsertPos = pNameDialog->aSaveInListBox.GetSelectEntryPos();
4741 ToolbarSaveInData* pData = (ToolbarSaveInData*)
4742 pNameDialog->aSaveInListBox.GetEntryData( nInsertPos );
4744 if ( GetSaveInData() != pData )
4746 aSaveInListBox.SelectEntryPos( nInsertPos, sal_True );
4747 aSaveInListBox.GetSelectHdl().Call(this);
4750 SvxConfigEntry* pToolbar =
4751 new SvxConfigEntry( aNewName, aNewURL, sal_True );
4753 pToolbar->SetUserDefined( sal_True );
4754 pToolbar->SetMain( sal_True );
4756 pData->CreateToolbar( pToolbar );
4758 nInsertPos = aTopLevelListBox.InsertEntry( pToolbar->GetName() );
4759 aTopLevelListBox.SetEntryData( nInsertPos, pToolbar );
4760 aTopLevelListBox.SelectEntryPos( nInsertPos, sal_True );
4761 aTopLevelListBox.GetSelectHdl().Call(this);
4763 pData->SetModified( sal_True );
4766 delete pNameDialog;
4768 return 0;
4771 IMPL_LINK( SvxToolbarConfigPage, AddCommandsHdl, Button *, pButton )
4773 (void)pButton;
4775 if ( pSelectorDlg == NULL )
4777 // Create Script Selector which shows slot commands
4778 pSelectorDlg = new SvxScriptSelectorDialog( this, sal_True, m_xFrame );
4780 // Position the Script Selector over the Add button so it is
4781 // beside the menu contents list and does not obscure it
4782 pSelectorDlg->SetPosPixel( aAddCommandsButton.GetPosPixel() );
4784 pSelectorDlg->SetAddHdl(
4785 LINK( this, SvxToolbarConfigPage, AddFunctionHdl ) );
4788 pSelectorDlg->SetImageProvider(
4789 static_cast< ImageProvider* >( GetSaveInData() ) );
4791 pSelectorDlg->Show();
4792 return 1;
4795 IMPL_LINK( SvxToolbarConfigPage, AddFunctionHdl,
4796 SvxScriptSelectorDialog *, pDialog )
4798 (void)pDialog;
4800 AddFunction();
4802 return 0;
4805 SvLBoxEntry* SvxToolbarConfigPage::AddFunction(
4806 SvLBoxEntry* pTarget, bool bFront, bool bAllowDuplicates )
4808 SvLBoxEntry* pNewLBEntry =
4809 SvxConfigPage::AddFunction( pTarget, bFront, bAllowDuplicates );
4811 SvxConfigEntry* pEntry = (SvxConfigEntry*) pNewLBEntry->GetUserData();
4813 if ( pEntry->IsBinding() )
4815 pEntry->SetVisible( sal_True );
4816 aContentsListBox->SetCheckButtonState(
4817 pNewLBEntry, SV_BUTTON_CHECKED );
4819 else
4821 aContentsListBox->SetCheckButtonState(
4822 pNewLBEntry, SV_BUTTON_TRISTATE );
4825 // get currently selected toolbar and apply change
4826 SvxConfigEntry* pToolbar = GetTopLevelSelection();
4828 if ( pToolbar != NULL )
4830 ( ( ToolbarSaveInData* ) GetSaveInData() )->ApplyToolbar( pToolbar );
4833 return pNewLBEntry;
4836 // -----------------------------------------------------------------------
4838 SvxToolbarEntriesListBox::SvxToolbarEntriesListBox(
4839 Window* pParent, const ResId& aResId )
4841 SvxMenuEntriesListBox( pParent, aResId ),
4842 pPage( ( SvxToolbarConfigPage* ) pParent )
4844 m_pButtonData = new SvLBoxButtonData( this );
4845 BuildCheckBoxButtonImages( m_pButtonData );
4846 EnableCheckButton( m_pButtonData );
4848 m_bHiContrastMode = GetSettings().GetStyleSettings().GetHighContrastMode();
4851 // --------------------------------------------------------
4853 SvxToolbarEntriesListBox::~SvxToolbarEntriesListBox()
4855 delete m_pButtonData;
4858 // --------------------------------------------------------
4860 void SvxToolbarEntriesListBox::BuildCheckBoxButtonImages( SvLBoxButtonData* pData )
4862 // Build checkbox images according to the current application
4863 // settings. This is necessary to be able to have correct colors
4864 // in all color modes, like high contrast.
4865 const AllSettings& rSettings = Application::GetSettings();
4867 VirtualDevice aDev;
4868 Size aSize( 26, 20 );
4870 aDev.SetOutputSizePixel( aSize );
4872 Image aImage = GetSizedImage( aDev, aSize,
4873 CheckBox::GetCheckImage( rSettings, BUTTON_DRAW_DEFAULT ));
4875 // Fill button data struct with new images
4876 pData->aBmps[SV_BMP_UNCHECKED] = aImage;
4877 pData->aBmps[SV_BMP_CHECKED] = GetSizedImage( aDev, aSize, CheckBox::GetCheckImage( rSettings, BUTTON_DRAW_CHECKED ));
4878 pData->aBmps[SV_BMP_HICHECKED] = GetSizedImage( aDev, aSize, CheckBox::GetCheckImage( rSettings, BUTTON_DRAW_CHECKED | BUTTON_DRAW_PRESSED ));
4879 pData->aBmps[SV_BMP_HIUNCHECKED] = GetSizedImage( aDev, aSize, CheckBox::GetCheckImage( rSettings, BUTTON_DRAW_DEFAULT | BUTTON_DRAW_PRESSED));
4880 pData->aBmps[SV_BMP_TRISTATE] = GetSizedImage( aDev, aSize, Image() ); // Use tristate bitmaps to have no checkbox for separator entries
4881 pData->aBmps[SV_BMP_HITRISTATE] = GetSizedImage( aDev, aSize, Image() );
4883 // Get image size
4884 m_aCheckBoxImageSizePixel = aImage.GetSizePixel();
4887 Image SvxToolbarEntriesListBox::GetSizedImage(
4888 VirtualDevice& aDev, const Size& aNewSize, const Image& aImage )
4890 // Create new checkbox images for treelistbox. They must have a
4891 // decent width to have a clear column for the visibility checkbox.
4893 // Standard transparent color is light magenta as is won't be
4894 // used for other things
4895 Color aFillColor( COL_LIGHTMAGENTA );
4897 // Position image at the center of (width-2),(height) rectangle.
4898 // We need 2 pixels to have a bigger border to the next button image
4899 sal_uInt16 nPosX = std::max( (sal_uInt16) (((( aNewSize.Width() - 2 ) - aImage.GetSizePixel().Width() ) / 2 ) - 1), (sal_uInt16) 0 );
4900 sal_uInt16 nPosY = std::max( (sal_uInt16) (((( aNewSize.Height() - 2 ) - aImage.GetSizePixel().Height() ) / 2 ) + 1), (sal_uInt16) 0 );
4901 Point aPos( nPosX > 0 ? nPosX : 0, nPosY > 0 ? nPosY : 0 );
4902 aDev.SetFillColor( aFillColor );
4903 aDev.SetLineColor( aFillColor );
4904 aDev.DrawRect( Rectangle( Point(), aNewSize ));
4905 aDev.DrawImage( aPos, aImage );
4907 // Draw separator line 2 pixels left from the right border
4908 Color aLineColor = GetDisplayBackground().GetColor().IsDark() ? Color( COL_WHITE ) : Color( COL_BLACK );
4909 aDev.SetLineColor( aLineColor );
4910 aDev.DrawLine( Point( aNewSize.Width()-3, 0 ), Point( aNewSize.Width()-3, aNewSize.Height()-1 ));
4912 // Create new image that uses the fillcolor as transparent
4913 return Image( aDev.GetBitmap( Point(), aNewSize ), aFillColor );
4916 void SvxToolbarEntriesListBox::DataChanged( const DataChangedEvent& rDCEvt )
4918 SvTreeListBox::DataChanged( rDCEvt );
4920 if (( rDCEvt.GetType() == DATACHANGED_SETTINGS ) &&
4921 ( rDCEvt.GetFlags() & SETTINGS_STYLE ))
4923 // We have to reset all images because we change to/from high contrast mode
4924 m_bHiContrastMode = GetSettings().GetStyleSettings().GetHighContrastMode();
4926 BuildCheckBoxButtonImages( m_pButtonData );
4927 Invalidate();
4931 // --------------------------------------------------------
4933 void SvxToolbarEntriesListBox::ChangeVisibility( SvLBoxEntry* pEntry )
4935 if ( pEntry != NULL )
4937 SvxConfigEntry* pEntryData =
4938 (SvxConfigEntry*) pEntry->GetUserData();
4940 if ( pEntryData->IsBinding() )
4942 pEntryData->SetVisible( !pEntryData->IsVisible() );
4944 SvxConfigEntry* pToolbar = pPage->GetTopLevelSelection();
4946 ToolbarSaveInData* pToolbarSaveInData = ( ToolbarSaveInData* )
4947 pPage->GetSaveInData();
4949 pToolbarSaveInData->ApplyToolbar( pToolbar );
4951 SetCheckButtonState( pEntry, pEntryData->IsVisible() ?
4952 SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
4957 void SvxToolbarEntriesListBox::CheckButtonHdl()
4959 ChangeVisibility( GetHdlEntry() );
4962 void SvxToolbarEntriesListBox::KeyInput( const KeyEvent& rKeyEvent )
4964 // space key will change visibility of toolbar items
4965 if ( rKeyEvent.GetKeyCode() == KEY_SPACE )
4967 ChangeVisibility( GetCurEntry() );
4969 else
4971 // pass on to superclass
4972 SvxMenuEntriesListBox::KeyInput( rKeyEvent );
4976 sal_Bool SvxToolbarEntriesListBox::NotifyMoving(
4977 SvLBoxEntry* pTarget, SvLBoxEntry* pSource,
4978 SvLBoxEntry*& rpNewParent, sal_uLong& rNewChildPos)
4980 bool result = SvxMenuEntriesListBox::NotifyMoving(
4981 pTarget, pSource, rpNewParent, rNewChildPos );
4983 if ( result == sal_True )
4985 // Instant Apply changes to UI
4986 SvxConfigEntry* pToolbar = pPage->GetTopLevelSelection();
4987 if ( pToolbar != NULL )
4989 ToolbarSaveInData* pSaveInData =
4990 ( ToolbarSaveInData*) pPage->GetSaveInData();
4991 pSaveInData->ApplyToolbar( pToolbar );
4995 return result;
4998 sal_Bool SvxToolbarEntriesListBox::NotifyCopying(
4999 SvLBoxEntry* pTarget,
5000 SvLBoxEntry* pSource,
5001 SvLBoxEntry*& rpNewParent,
5002 sal_uLong& rNewChildPos)
5004 (void)pSource;
5005 (void)rpNewParent;
5006 (void)rNewChildPos;
5008 if ( !m_bIsInternalDrag )
5010 // if the target is NULL then add function to the start of the list
5011 ((SvxToolbarConfigPage*)pPage)->AddFunction( pTarget, pTarget == NULL );
5013 // Instant Apply changes to UI
5014 SvxConfigEntry* pToolbar = pPage->GetTopLevelSelection();
5015 if ( pToolbar != NULL )
5017 ToolbarSaveInData* pSaveInData =
5018 ( ToolbarSaveInData*) pPage->GetSaveInData();
5019 pSaveInData->ApplyToolbar( pToolbar );
5022 // AddFunction already adds the listbox entry so return FALSE
5023 // to stop another listbox entry being added
5024 return sal_False;
5027 // Copying is only allowed from external controls, not within the listbox
5028 return sal_False;
5031 SvxNewToolbarDialog::SvxNewToolbarDialog(
5032 Window* pWindow, const String& rName )
5034 ModalDialog ( pWindow, CUI_RES( MD_NEW_TOOLBAR ) ),
5035 aFtDescription ( this, CUI_RES( FT_NAME ) ),
5036 aEdtName ( this, CUI_RES( EDT_STRING ) ),
5037 aSaveInText ( this, CUI_RES( TXT_SAVEIN ) ),
5038 aBtnOK ( this, CUI_RES( BTN_OK ) ),
5039 aBtnCancel ( this, CUI_RES( BTN_CANCEL ) ),
5040 aBtnHelp ( this, CUI_RES( BTN_HELP ) ),
5041 aSaveInListBox ( this, CUI_RES( LB_SAVEIN ) )
5043 FreeResource();
5045 aEdtName.SetText( rName );
5046 aEdtName.SetSelection(Selection(SELECTION_MIN, SELECTION_MAX));
5047 ModifyHdl(&aEdtName);
5048 aEdtName.SetModifyHdl(LINK(this, SvxNewToolbarDialog, ModifyHdl));
5051 IMPL_LINK(SvxNewToolbarDialog, ModifyHdl, Edit*, pEdit)
5053 (void)pEdit;
5055 if(aCheckNameHdl.IsSet())
5056 aBtnOK.Enable(aCheckNameHdl.Call(this) > 0);
5058 return 0;
5061 /*******************************************************************************
5063 * The SvxIconSelectorDialog class
5065 *******************************************************************************/
5066 SvxIconSelectorDialog::SvxIconSelectorDialog( Window *pWindow,
5067 const uno::Reference< css::ui::XImageManager >& rXImageManager,
5068 const uno::Reference< css::ui::XImageManager >& rXParentImageManager )
5070 ModalDialog ( pWindow, CUI_RES( MD_ICONSELECTOR ) ),
5071 aFtDescription ( this, CUI_RES( FT_SYMBOLS ) ),
5072 aTbSymbol ( this, CUI_RES( TB_SYMBOLS ) ),
5073 aFtNote ( this, CUI_RES( FT_NOTE ) ),
5074 aBtnOK ( this, CUI_RES( BTN_OK ) ),
5075 aBtnCancel ( this, CUI_RES( BTN_CANCEL ) ),
5076 aBtnHelp ( this, CUI_RES( BTN_HELP ) ),
5077 aBtnImport ( this, CUI_RES( BTN_IMPORT ) ),
5078 aBtnDelete ( this, CUI_RES( BTN_DELETE ) ),
5079 aFlSeparator ( this, CUI_RES( FL_SEPARATOR ) ),
5080 m_nNextId ( 0 ),
5081 m_xImageManager ( rXImageManager ),
5082 m_xParentImageManager( rXParentImageManager )
5084 FreeResource();
5086 typedef ::std::hash_map< ::rtl::OUString,
5087 bool,
5088 ::rtl::OUStringHash,
5089 ::std::equal_to< ::rtl::OUString > > ImageInfo;
5091 aTbSymbol.SetPageScroll( sal_True );
5093 bool bLargeIcons = GetImageType() & css::ui::ImageType::SIZE_LARGE;
5094 m_nExpectedSize = bLargeIcons ? 26 : 16;
5096 if ( m_nExpectedSize != 16 )
5098 aFtNote.SetText( replaceSixteen( aFtNote.GetText(), m_nExpectedSize ) );
5101 uno::Reference< lang::XMultiServiceFactory > xServiceManager =
5102 ::comphelper::getProcessServiceFactory();
5104 if ( xServiceManager.is() )
5106 m_xGraphProvider = uno::Reference< graphic::XGraphicProvider >(
5107 xServiceManager->createInstance(
5108 ::rtl::OUString::createFromAscii(
5109 "com.sun.star.graphic.GraphicProvider" ) ),
5110 uno::UNO_QUERY );
5113 if ( !m_xGraphProvider.is() )
5115 aBtnImport.Enable( sal_False );
5118 uno::Reference< beans::XPropertySet > xPropSet(
5119 xServiceManager->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.util.PathSettings" ) ),
5120 uno::UNO_QUERY );
5122 uno::Any aAny = xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UserConfig" ) ) );
5124 ::rtl::OUString aDirectory;
5126 aAny >>= aDirectory;
5128 sal_Int32 aCount = aDirectory.getLength();
5130 if ( aCount > 0 )
5132 sal_Unicode aChar = aDirectory[ aCount-1 ];
5133 if ( aChar != '/')
5135 aDirectory += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) );
5138 else
5140 aBtnImport.Enable( sal_False );
5143 aDirectory += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "soffice.cfg/import" ) );
5145 uno::Reference< lang::XSingleServiceFactory > xStorageFactory(
5146 xServiceManager->createInstance(
5147 ::rtl::OUString::createFromAscii( "com.sun.star.embed.FileSystemStorageFactory" )),
5148 uno::UNO_QUERY );
5150 uno::Sequence< uno::Any > aArgs( 2 );
5151 aArgs[ 0 ] <<= aDirectory;
5152 aArgs[ 1 ] <<= com::sun::star::embed::ElementModes::READWRITE;
5154 uno::Reference< com::sun::star::embed::XStorage > xStorage(
5155 xStorageFactory->createInstanceWithArguments( aArgs ), uno::UNO_QUERY );
5157 uno::Sequence< uno::Any > aProp( 2 );
5158 beans::PropertyValue aPropValue;
5160 aPropValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UserConfigStorage" ) );
5161 aPropValue.Value <<= xStorage;
5162 aProp[ 0 ] <<= aPropValue;
5164 aPropValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenMode" ) );
5165 aPropValue.Value <<= com::sun::star::embed::ElementModes::READWRITE;
5166 aProp[ 1 ] <<= aPropValue;
5168 m_xImportedImageManager = uno::Reference< com::sun::star::ui::XImageManager >(
5169 xServiceManager->createInstanceWithArguments(
5170 ::rtl::OUString::createFromAscii( "com.sun.star.ui.ImageManager" ), aProp ),
5171 uno::UNO_QUERY );
5173 ImageInfo mImageInfo;
5174 uno::Sequence< OUString > names;
5175 if ( m_xImportedImageManager.is() )
5177 names = m_xImportedImageManager->getAllImageNames( GetImageType() );
5178 for ( sal_Int32 n = 0; n < names.getLength(); n++ )
5179 mImageInfo.insert( ImageInfo::value_type( names[n], false ));
5181 sal_uInt16 nId = 1;
5182 ImageInfo::const_iterator pConstIter = mImageInfo.begin();
5183 uno::Sequence< OUString > name( 1 );
5184 while ( pConstIter != mImageInfo.end() )
5186 name[ 0 ] = pConstIter->first;
5187 uno::Sequence< uno::Reference< graphic::XGraphic> > graphics = m_xImportedImageManager->getImages( GetImageType(), name );
5188 if ( graphics.getLength() > 0 )
5190 Image img = Image( graphics[ 0 ] );
5191 aTbSymbol.InsertItem( nId, img, pConstIter->first );
5193 graphics[ 0 ]->acquire();
5195 aTbSymbol.SetItemData(
5196 nId, static_cast< void * > ( graphics[ 0 ].get() ) );
5198 ++nId;
5200 ++pConstIter;
5203 ImageInfo aImageInfo;
5205 if ( m_xParentImageManager.is() )
5207 names = m_xParentImageManager->getAllImageNames( GetImageType() );
5208 for ( sal_Int32 n = 0; n < names.getLength(); n++ )
5209 aImageInfo.insert( ImageInfo::value_type( names[n], false ));
5212 names = m_xImageManager->getAllImageNames( GetImageType() );
5213 for ( sal_Int32 n = 0; n < names.getLength(); n++ )
5215 ImageInfo::iterator pIter = aImageInfo.find( names[n] );
5216 if ( pIter != aImageInfo.end() )
5217 pIter->second = true;
5218 else
5219 aImageInfo.insert( ImageInfo::value_type( names[n], true ));
5222 // large growth factor, expecting many entries
5223 pConstIter = aImageInfo.begin();
5224 while ( pConstIter != aImageInfo.end() )
5226 name[ 0 ] = pConstIter->first;
5228 uno::Sequence< uno::Reference< graphic::XGraphic> > graphics;
5231 if ( pConstIter->second )
5232 graphics = m_xImageManager->getImages( GetImageType(), name );
5233 else
5234 graphics = m_xParentImageManager->getImages( GetImageType(), name );
5236 catch ( uno::Exception& )
5238 // can't get sequence for this name so it will not be
5239 // added to the list
5242 if ( graphics.getLength() > 0 )
5244 Image img = Image( graphics[ 0 ] );
5245 aTbSymbol.InsertItem( nId, img, pConstIter->first );
5247 uno::Reference< graphic::XGraphic > xGraphic = graphics[ 0 ];
5249 if ( xGraphic.is() )
5250 xGraphic->acquire();
5252 aTbSymbol.SetItemData(
5253 nId, static_cast< void * > ( xGraphic.get() ) );
5255 ++nId;
5258 ++pConstIter;
5261 aBtnDelete.Enable( sal_False );
5262 aTbSymbol.SetSelectHdl( LINK(this, SvxIconSelectorDialog, SelectHdl) );
5263 aBtnImport.SetClickHdl( LINK(this, SvxIconSelectorDialog, ImportHdl) );
5264 aBtnDelete.SetClickHdl( LINK(this, SvxIconSelectorDialog, DeleteHdl) );
5266 m_nNextId = aTbSymbol.GetItemCount()+1;
5269 SvxIconSelectorDialog::~SvxIconSelectorDialog()
5271 sal_uInt16 nCount = aTbSymbol.GetItemCount();
5273 for (sal_uInt16 n = 0; n < nCount; n++ )
5275 sal_uInt16 nId = aTbSymbol.GetItemId(n);
5277 uno::XInterface* xi = static_cast< uno::XInterface* >(
5278 aTbSymbol.GetItemData( nId ) );
5280 if ( xi != NULL )
5282 xi->release();
5287 uno::Reference< graphic::XGraphic> SvxIconSelectorDialog::GetSelectedIcon()
5289 uno::Reference< graphic::XGraphic > result;
5291 sal_uInt16 nId;
5292 for ( sal_uInt16 n = 0; n < aTbSymbol.GetItemCount(); n++ )
5294 nId = aTbSymbol.GetItemId( n );
5295 if ( aTbSymbol.IsItemChecked( nId ) )
5297 result = uno::Reference< graphic::XGraphic >(
5298 reinterpret_cast< graphic::XGraphic* >(
5299 aTbSymbol.GetItemData( nId ) ) );
5303 return result;
5306 IMPL_LINK( SvxIconSelectorDialog, SelectHdl, ToolBox *, pToolBox )
5308 (void)pToolBox;
5310 sal_uInt16 nCount = aTbSymbol.GetItemCount();
5312 for (sal_uInt16 n = 0; n < nCount; n++ )
5314 sal_uInt16 nId = aTbSymbol.GetItemId( n );
5316 if ( aTbSymbol.IsItemChecked( nId ) )
5318 aTbSymbol.CheckItem( nId, sal_False );
5322 sal_uInt16 nId = aTbSymbol.GetCurItemId();
5323 aTbSymbol.CheckItem( nId );
5325 ::rtl::OUString aSelImageText = aTbSymbol.GetItemText( nId );
5326 if ( m_xImportedImageManager->hasImage( GetImageType(), aSelImageText ) )
5328 aBtnDelete.Enable( sal_True );
5330 else
5332 aBtnDelete.Enable( sal_False );
5335 return 0;
5338 IMPL_LINK( SvxIconSelectorDialog, ImportHdl, PushButton *, pButton )
5340 (void)pButton;
5342 sfx2::FileDialogHelper aImportDialog(
5343 css::ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW,
5344 SFXWB_GRAPHIC | SFXWB_MULTISELECTION );
5346 // disable the link checkbox in the dialog
5347 uno::Reference< css::ui::dialogs::XFilePickerControlAccess >
5348 xController( aImportDialog.GetFilePicker(), uno::UNO_QUERY);
5349 if ( xController.is() )
5351 xController->enableControl(
5352 css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_LINK,
5353 sal_False);
5356 aImportDialog.SetCurrentFilter(
5357 String::CreateFromAscii( "PNG - Portable Network Graphic" ) );
5359 if ( ERRCODE_NONE == aImportDialog.Execute() )
5361 uno::Sequence< OUString > paths = aImportDialog.GetMPath();
5362 ImportGraphics ( paths );
5365 return 0;
5368 IMPL_LINK( SvxIconSelectorDialog, DeleteHdl, PushButton *, pButton )
5370 (void)pButton;
5372 OUString message = String( CUI_RES( RID_SVXSTR_DELETE_ICON_CONFIRM ) );
5373 bool ret = WarningBox( this, WinBits(WB_OK_CANCEL), message ).Execute();
5375 if ( ret == RET_OK )
5377 sal_uInt16 nCount = aTbSymbol.GetItemCount();
5379 for (sal_uInt16 n = 0; n < nCount; n++ )
5381 sal_uInt16 nId = aTbSymbol.GetItemId( n );
5383 if ( aTbSymbol.IsItemChecked( nId ) )
5385 ::rtl::OUString aSelImageText = aTbSymbol.GetItemText( nId );
5386 uno::Sequence< OUString > URLs(1);
5387 URLs[0] = aSelImageText;
5388 aTbSymbol.RemoveItem( aTbSymbol.GetItemPos( nId ) );
5389 m_xImportedImageManager->removeImages( GetImageType(), URLs );
5390 uno::Reference< css::ui::XUIConfigurationPersistence >
5391 xConfigPersistence( m_xImportedImageManager, uno::UNO_QUERY );
5392 if ( xConfigPersistence.is() && xConfigPersistence->isModified() )
5394 xConfigPersistence->store();
5396 break;
5400 return 0;
5403 bool SvxIconSelectorDialog::ReplaceGraphicItem(
5404 const ::rtl::OUString& aURL )
5406 uno::Sequence< OUString > URLs(1);
5407 uno::Sequence< uno::Reference<graphic::XGraphic > > aImportGraph( 1 );
5408 uno::Reference< css::ui::XUIConfigurationPersistence >
5409 xConfigPer( m_xImportedImageManager, uno::UNO_QUERY );
5411 uno::Reference< graphic::XGraphic > xGraphic;
5412 uno::Sequence< beans::PropertyValue > aMediaProps( 1 );
5413 aMediaProps[0].Name = ::rtl::OUString::createFromAscii("URL");
5414 aMediaProps[0].Value <<= aURL;
5416 com::sun::star::awt::Size aSize;
5417 bool bOK = sal_False;
5420 xGraphic = m_xGraphProvider->queryGraphic( aMediaProps );
5422 uno::Reference< beans::XPropertySet > props =
5423 m_xGraphProvider->queryGraphicDescriptor( aMediaProps );
5424 uno::Any a = props->getPropertyValue(
5425 OUString::createFromAscii("SizePixel") );
5426 a >>= aSize;
5427 if (0 == aSize.Width || 0 == aSize.Height)
5428 return sal_False;
5429 else
5430 bOK = sal_True;
5432 catch ( uno::Exception& )
5434 return false;
5437 bool bResult( false );
5438 sal_uInt16 nCount = aTbSymbol.GetItemCount();
5439 for (sal_uInt16 n = 0; n < nCount; n++ )
5441 sal_uInt16 nId = aTbSymbol.GetItemId( n );
5443 if ( OUString( aTbSymbol.GetItemText( nId ) ) == aURL )
5447 // replace/insert image with provided URL
5448 aTbSymbol.RemoveItem( aTbSymbol.GetItemPos( nId ) );
5449 aMediaProps[0].Value <<= aURL;
5451 Image aImage( xGraphic );
5452 if ( bOK && ((aSize.Width != m_nExpectedSize) || (aSize.Height != m_nExpectedSize)) )
5454 BitmapEx aBitmap = aImage.GetBitmapEx();
5455 BitmapEx aBitmapex = AutoScaleBitmap(aBitmap, m_nExpectedSize);
5456 aImage = Image( aBitmapex);
5458 aTbSymbol.InsertItem( nId,aImage, aURL, 0, 0 ); //modify
5460 xGraphic = aImage.GetXGraphic();
5462 URLs[0] = aURL;
5463 aImportGraph[ 0 ] = xGraphic;
5464 m_xImportedImageManager->replaceImages( GetImageType(), URLs, aImportGraph );
5465 xConfigPer->store();
5467 bResult = true;
5468 break;
5470 catch ( ::com::sun::star::uno::Exception& )
5472 break;
5477 return bResult;
5480 void SvxIconSelectorDialog::ImportGraphics(
5481 const uno::Sequence< OUString >& rPaths )
5483 uno::Sequence< OUString > rejected( rPaths.getLength() );
5484 sal_Int32 rejectedCount = 0;
5486 sal_uInt16 ret = 0;
5487 sal_Int32 aIndex;
5488 OUString aIconName;
5489 uno::Sequence< OUString > URLs(1);
5490 uno::Sequence< uno::Reference<graphic::XGraphic > > aImportGraph( 1 );
5491 uno::Sequence< beans::PropertyValue > aMediaProps( 1 );
5492 aMediaProps[0].Name = ::rtl::OUString::createFromAscii("URL");
5493 uno::Reference< css::ui::XUIConfigurationPersistence >
5494 xConfigPer( m_xImportedImageManager, uno::UNO_QUERY );
5496 if ( rPaths.getLength() == 1 )
5498 if ( m_xImportedImageManager->hasImage( GetImageType(), rPaths[0] ) )
5500 aIndex = rPaths[0].lastIndexOf( '/' );
5501 aIconName = rPaths[0].copy( aIndex+1 );
5502 ret = SvxIconReplacementDialog( this, aIconName ).ShowDialog();
5503 if ( ret == 2 )
5505 ReplaceGraphicItem( rPaths[0] );
5508 else
5510 if ( ImportGraphic( rPaths[0] ) == sal_False )
5512 rejected[0] = rPaths[0];
5513 rejectedCount = 1;
5517 else
5519 ::rtl::OUString aSourcePath( rPaths[0] );
5520 if ( rPaths[0].lastIndexOf( '/' ) != rPaths[0].getLength() -1 )
5521 aSourcePath = rPaths[0] + ::rtl::OUString::createFromAscii( "/" );
5523 for ( sal_Int32 i = 1; i < rPaths.getLength(); i++ )
5525 ::rtl::OUString aPath = aSourcePath + rPaths[i];
5526 if ( m_xImportedImageManager->hasImage( GetImageType(), aPath ) )
5528 aIndex = rPaths[i].lastIndexOf( '/' );
5529 aIconName = rPaths[i].copy( aIndex+1 );
5530 ret = SvxIconReplacementDialog( this, aIconName, sal_True ).ShowDialog();
5531 if ( ret == 2 )
5533 ReplaceGraphicItem( aPath );
5535 else if ( ret == 5 )
5537 for ( sal_Int32 k = i; k < rPaths.getLength(); k++ )
5539 aPath = aSourcePath + rPaths[k];
5540 bool bHasReplaced = ReplaceGraphicItem( aPath );
5542 if ( !bHasReplaced )
5544 bool result = ImportGraphic( aPath );
5545 if ( result == sal_False )
5547 rejected[ rejectedCount ] = rPaths[i];
5548 rejectedCount++;
5552 break;
5555 else
5557 bool result = ImportGraphic( aSourcePath + rPaths[i] );
5558 if ( result == sal_False )
5560 rejected[ rejectedCount ] = rPaths[i];
5561 rejectedCount++;
5567 if ( rejectedCount != 0 )
5569 OUString message =OUString::createFromAscii("");
5570 OUString newLine = OUString::createFromAscii("\n");
5571 rtl::OUString fPath = OUString::createFromAscii("");
5572 if (rejectedCount > 1)
5573 fPath = rPaths[0].copy(8) + ::rtl::OUString::createFromAscii( "/" );
5574 for ( sal_Int32 i = 0; i < rejectedCount; i++ )
5576 message += fPath + rejected[i];
5577 message += newLine;
5580 SvxIconChangeDialog aDialog(this, message);
5581 aDialog.Execute();
5585 bool SvxIconSelectorDialog::ImportGraphic( const OUString& aURL )
5587 bool result = sal_False;
5589 sal_uInt16 nId = m_nNextId;
5590 ++m_nNextId;
5592 uno::Sequence< beans::PropertyValue > aMediaProps( 1 );
5593 aMediaProps[0].Name = ::rtl::OUString::createFromAscii("URL");
5595 uno::Reference< graphic::XGraphic > xGraphic;
5596 com::sun::star::awt::Size aSize;
5597 bool bOK = sal_True;
5598 aMediaProps[0].Value <<= aURL;
5601 uno::Reference< beans::XPropertySet > props =
5602 m_xGraphProvider->queryGraphicDescriptor( aMediaProps );
5604 uno::Any a = props->getPropertyValue(
5605 OUString::createFromAscii("SizePixel") );
5607 xGraphic = m_xGraphProvider->queryGraphic( aMediaProps );
5608 if ( xGraphic.is() )
5610 a >>= aSize;
5611 if ( 0 == aSize.Width || 0 == aSize.Height )
5612 bOK = sal_False;
5614 Image aImage( xGraphic );
5616 if ( bOK && ((aSize.Width != m_nExpectedSize) || (aSize.Height != m_nExpectedSize)) )
5618 BitmapEx aBitmap = aImage.GetBitmapEx();
5619 BitmapEx aBitmapex = AutoScaleBitmap(aBitmap, m_nExpectedSize);
5620 aImage = Image( aBitmapex);
5622 if ( bOK && !!aImage )
5624 aTbSymbol.InsertItem( nId, aImage, aURL, 0, 0 );
5626 xGraphic = aImage.GetXGraphic();
5627 xGraphic->acquire();
5629 aTbSymbol.SetItemData(
5630 nId, static_cast< void * > ( xGraphic.get() ) );
5631 uno::Sequence< OUString > aImportURL( 1 );
5632 aImportURL[ 0 ] = aURL;
5633 uno::Sequence< uno::Reference<graphic::XGraphic > > aImportGraph( 1 );
5634 aImportGraph[ 0 ] = xGraphic;
5635 m_xImportedImageManager->insertImages( GetImageType(), aImportURL, aImportGraph );
5636 uno::Reference< css::ui::XUIConfigurationPersistence >
5637 xConfigPersistence( m_xImportedImageManager, uno::UNO_QUERY );
5639 if ( xConfigPersistence.is() && xConfigPersistence->isModified() )
5641 xConfigPersistence->store();
5644 result = sal_True;
5646 else
5648 OSL_TRACE("could not create Image from XGraphic");
5651 else
5653 OSL_TRACE("could not get query XGraphic");
5656 catch( uno::Exception& e )
5658 OSL_TRACE("Caught exception importing XGraphic: %s", PRTSTR(e.Message));
5660 return result;
5663 /*******************************************************************************
5665 * The SvxIconReplacementDialog class
5667 *******************************************************************************/
5668 SvxIconReplacementDialog :: SvxIconReplacementDialog(
5669 Window *pWindow, const rtl::OUString& aMessage, bool /*bYestoAll*/ )
5671 MessBox( pWindow, WB_DEF_YES, String( CUI_RES( RID_SVXSTR_REPLACE_ICON_CONFIRM ) ), String( CUI_RES( RID_SVXSTR_REPLACE_ICON_WARNING ) ) )
5674 SetImage( WarningBox::GetStandardImage() );
5675 SetMessText( ReplaceIconName( aMessage ) );
5676 RemoveButton( 1 );
5677 AddButton( BUTTON_YES, 2, 0 );
5678 AddButton( String( CUI_RES( RID_SVXSTR_YESTOALL ) ), 5, 0 );
5679 AddButton( BUTTON_NO, 3, 0 );
5680 AddButton( BUTTON_CANCEL, 4, 0 );
5683 SvxIconReplacementDialog :: SvxIconReplacementDialog(
5684 Window *pWindow, const rtl::OUString& aMessage )
5686 MessBox( pWindow, WB_YES_NO_CANCEL, String( CUI_RES( RID_SVXSTR_REPLACE_ICON_CONFIRM ) ), String( CUI_RES( RID_SVXSTR_REPLACE_ICON_WARNING ) ) )
5688 SetImage( WarningBox::GetStandardImage() );
5689 SetMessText( ReplaceIconName( aMessage ));
5692 rtl::OUString SvxIconReplacementDialog :: ReplaceIconName( const OUString& rMessage )
5694 rtl::OUString name;
5695 rtl::OUString message = String( CUI_RES( RID_SVXSTR_REPLACE_ICON_WARNING ) );
5696 rtl::OUString placeholder = OUString::createFromAscii( "%ICONNAME" );
5697 sal_Int32 pos = message.indexOf( placeholder );
5698 if ( pos != -1 )
5700 name = message.replaceAt(
5701 pos, placeholder.getLength(), rMessage );
5703 return name;
5706 sal_uInt16 SvxIconReplacementDialog :: ShowDialog()
5708 this->Execute();
5709 return ( this->GetCurButtonId() );
5711 /*******************************************************************************
5713 * The SvxIconChangeDialog class added for issue83555
5715 *******************************************************************************/
5716 SvxIconChangeDialog::SvxIconChangeDialog(
5717 Window *pWindow, const rtl::OUString& aMessage)
5719 ModalDialog ( pWindow, CUI_RES( MD_ICONCHANGE ) ),
5720 aFImageInfo (this, CUI_RES( FI_INFO ) ),
5721 aBtnOK (this, CUI_RES(MD_BTN_OK)),
5722 aDescriptionLabel (this, CUI_RES(FTCHGE_DESCRIPTION)),
5723 aLineEditDescription (this, CUI_RES(EDT_ADDR))
5725 FreeResource();
5726 aFImageInfo.SetImage(InfoBox::GetStandardImage());
5727 aLineEditDescription.SetControlBackground( GetSettings().GetStyleSettings().GetDialogColor() );
5728 aLineEditDescription.SetAutoScroll( sal_True );
5729 aLineEditDescription.EnableCursor( sal_False );
5730 aLineEditDescription.SetText(aMessage);
5733 BitmapEx SvxIconSelectorDialog::AutoScaleBitmap(BitmapEx & aBitmap, const long aStandardSize)
5735 Point aEmptyPoint(0,0);
5736 sal_Int32 imgNewWidth = 0;
5737 sal_Int32 imgNewHeight = 0;
5738 double imgposX = 0;
5739 double imgposY = 0;
5740 BitmapEx aRet = aBitmap;
5741 double imgOldWidth = aRet.GetSizePixel().Width();
5742 double imgOldHeight =aRet.GetSizePixel().Height();
5744 Size aScaledSize;
5745 if (imgOldWidth >= aStandardSize || imgOldHeight >= aStandardSize)
5747 if (imgOldWidth >= imgOldHeight)
5749 imgNewWidth = aStandardSize;
5750 imgNewHeight = sal_Int32(imgOldHeight / (imgOldWidth / aStandardSize) + 0.5);
5751 imgposX = 0;
5752 imgposY = (aStandardSize - (imgOldHeight / (imgOldWidth / aStandardSize) + 0.5)) / 2 + 0.5;
5754 else
5756 imgNewHeight = aStandardSize;
5757 imgNewWidth = sal_Int32(imgOldWidth / (imgOldHeight / aStandardSize) + 0.5);
5758 imgposY = 0;
5759 imgposX = (aStandardSize - (imgOldWidth / (imgOldHeight / aStandardSize) + 0.5)) / 2 + 0.5;
5762 aScaledSize = Size( imgNewWidth, imgNewHeight );
5763 aRet.Scale( aScaledSize, BMP_SCALE_INTERPOLATE );
5765 else
5767 imgposX = (aStandardSize - imgOldWidth) / 2 + 0.5;
5768 imgposY = (aStandardSize - imgOldHeight) / 2 + 0.5;
5771 Size aBmpSize = aRet.GetSizePixel();
5772 Size aStdSize( aStandardSize, aStandardSize );
5773 Rectangle aRect(aEmptyPoint, aStdSize );
5775 VirtualDevice aVirDevice( *Application::GetDefaultDevice(), 0, 1 );
5776 aVirDevice.SetOutputSizePixel( aStdSize );
5777 aVirDevice.SetFillColor( COL_TRANSPARENT );
5778 aVirDevice.SetLineColor( COL_TRANSPARENT );
5780 //draw a rect into virDevice
5781 aVirDevice.DrawRect( aRect );
5782 Point aPointPixel( (long)imgposX, (long)imgposY );
5783 aVirDevice.DrawBitmapEx( aPointPixel, aRet );
5784 aRet = aVirDevice.GetBitmapEx( aEmptyPoint, aStdSize );
5786 return aRet;