1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cfg.cxx,v $
10 * $Revision: 1.50.84.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
37 #ifndef _HELP_HXX //autogen
38 #include <vcl/help.hxx>
40 #ifndef _MSGBOX_HXX //autogen
41 #include <vcl/msgbox.hxx>
43 #include <vcl/decoview.hxx>
44 #include <vcl/toolbox.hxx>
45 #include <vcl/scrbar.hxx>
47 //added for issue73355
48 //#ifndef _SV_SVDATA_HXX
49 //#include <vcl/svdata.hxx>
53 #include <sfx2/app.hxx>
54 #include <sfx2/sfxdlg.hxx>
55 #include <sfx2/viewfrm.hxx>
56 #include <sfx2/viewsh.hxx>
57 #include <sfx2/msg.hxx>
58 #include <sfx2/msgpool.hxx>
59 #include <sfx2/mnumgr.hxx>
60 #include <sfx2/macrconf.hxx>
61 #include <sfx2/minfitem.hxx>
62 #include <sfx2/objsh.hxx>
63 #include <sfx2/request.hxx>
64 #include <sfx2/filedlghelper.hxx>
65 #include <svtools/stritem.hxx>
66 #include <svtools/miscopt.hxx>
67 #include <tools/diagnose_ex.h>
68 #include <toolkit/unohlp.hxx>
72 #include <svx/dialogs.hrc>
78 #include "eventdlg.hxx"
79 #include <svx/dialmgr.hxx>
81 #include <comphelper/documentinfo.hxx>
82 #include <comphelper/processfactory.hxx>
83 #ifndef _UNOTOOLS_CONFIGMGR_HXX_
84 #include <unotools/configmgr.hxx>
86 #include <com/sun/star/ui/ItemType.hpp>
87 #include <com/sun/star/ui/ItemStyle.hpp>
88 #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
89 #include <com/sun/star/frame/XController.hpp>
90 #include <com/sun/star/frame/XDesktop.hpp>
91 #include <com/sun/star/ui/XUIConfiguration.hpp>
92 #include <com/sun/star/ui/XUIConfigurationListener.hpp>
93 #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
94 #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
95 #include <com/sun/star/ui/XUIConfigurationStorage.hpp>
96 #include <com/sun/star/ui/XModuleUIConfigurationManager.hpp>
97 #include <com/sun/star/ui/XUIElement.hpp>
98 #ifndef _COM_SUN_STAR_UI_UIElementType_HPP_
99 #include <com/sun/star/ui/UIElementType.hpp>
101 #include <com/sun/star/ui/ImageType.hpp>
102 #include <com/sun/star/frame/XLayoutManager.hpp>
103 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
104 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
105 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
106 #include <com/sun/star/frame/XFramesSupplier.hpp>
107 #include <com/sun/star/frame/XFrames.hpp>
108 #include <com/sun/star/frame/FrameSearchFlag.hpp>
109 #include <com/sun/star/embed/ElementModes.hpp>
111 #include "dlgname.hxx"
113 #define PRTSTR(x) rtl::OUStringToOString(x, RTL_TEXTENCODING_ASCII_US).pData->buffer
115 #define ENTRY_HEIGHT 16
117 static const char ITEM_DESCRIPTOR_COMMANDURL
[] = "CommandURL";
118 static const char ITEM_DESCRIPTOR_HELPURL
[] = "HelpURL";
119 static const char ITEM_DESCRIPTOR_CONTAINER
[] = "ItemDescriptorContainer";
120 static const char ITEM_DESCRIPTOR_LABEL
[] = "Label";
121 static const char ITEM_DESCRIPTOR_TYPE
[] = "Type";
122 static const char ITEM_DESCRIPTOR_STYLE
[] = "Style";
123 static const char ITEM_DESCRIPTOR_ISVISIBLE
[] = "IsVisible";
124 static const char ITEM_DESCRIPTOR_RESOURCEURL
[] = "ResourceURL";
125 static const char ITEM_DESCRIPTOR_UINAME
[] = "UIName";
127 static const char ITEM_MENUBAR_URL
[] = "private:resource/menubar/menubar";
128 static const char ITEM_TOOLBAR_URL
[] = "private:resource/toolbar/";
130 static const char CUSTOM_TOOLBAR_STR
[] = "custom_toolbar_";
131 static const char CUSTOM_MENU_STR
[] = "vnd.openoffice.org:CustomMenu";
133 static const char __FAR_DATA pSeparatorStr
[] =
134 "----------------------------------";
135 static const char __FAR_DATA pMenuSeparatorStr
[] = " | ";
138 #pragma warning (disable:4355)
142 namespace css
= com::sun::star
;
143 namespace uno
= com::sun::star::uno
;
144 namespace frame
= com::sun::star::frame
;
145 namespace lang
= com::sun::star::lang
;
146 namespace container
= com::sun::star::container
;
147 namespace beans
= com::sun::star::beans
;
148 namespace graphic
= com::sun::star::graphic
;
150 void printPropertySet(
151 const OUString
& prefix
,
152 const uno::Reference
< beans::XPropertySet
>& xPropSet
)
154 uno::Reference
< beans::XPropertySetInfo
> xPropSetInfo
=
155 xPropSet
->getPropertySetInfo();
157 uno::Sequence
< beans::Property
> aPropDetails
=
158 xPropSetInfo
->getProperties();
160 OSL_TRACE("printPropertySet: %d properties", aPropDetails
.getLength());
162 for ( sal_Int32 i
= 0; i
< aPropDetails
.getLength(); i
++ )
167 uno::Any a
= xPropSet
->getPropertyValue( aPropDetails
[i
].Name
);
169 if ( ( a
>>= tmp
) /* && tmp.getLength() != 0 */ )
171 OSL_TRACE("%s: Got property: %s = %s",
172 PRTSTR(prefix
), PRTSTR(aPropDetails
[i
].Name
), PRTSTR(tmp
));
174 else if ( ( a
>>= ival
) )
176 OSL_TRACE("%s: Got property: %s = %d",
177 PRTSTR(prefix
), PRTSTR(aPropDetails
[i
].Name
), PRTSTR(tmp
));
181 OSL_TRACE("%s: Got property: %s of type %s",
182 PRTSTR(prefix
), PRTSTR(aPropDetails
[i
].Name
), PRTSTR(a
.getValueTypeName()));
187 void printProperties(
188 const OUString
& prefix
,
189 const uno::Sequence
< beans::PropertyValue
>& aProp
)
191 for ( sal_Int32 i
= 0; i
< aProp
.getLength(); i
++ )
195 aProp
[i
].Value
>>= tmp
;
197 OSL_TRACE("%s: Got property: %s = %s",
198 PRTSTR(prefix
), PRTSTR(aProp
[i
].Name
), PRTSTR(tmp
));
202 void printEntries(SvxEntries
* entries
)
204 SvxEntries::const_iterator iter
= entries
->begin();
206 for ( ; iter
!= entries
->end(); iter
++ )
208 SvxConfigEntry
* entry
= *iter
;
210 OSL_TRACE("printEntries: %s", PRTSTR(entry
->GetName()));
215 stripHotKey( const OUString
& str
)
217 sal_Int32 index
= str
.indexOf( '~' );
224 return str
.replaceAt( index
, 1, OUString() );
228 OUString
replaceSaveInName(
229 const OUString
& rMessage
,
230 const OUString
& rSaveInName
)
233 OUString placeholder
= OUString::createFromAscii( "%SAVE IN SELECTION%" );
235 sal_Int32 pos
= rMessage
.indexOf( placeholder
);
239 name
= rMessage
.replaceAt(
240 pos
, placeholder
.getLength(), rSaveInName
);
244 // don't change the message
251 replaceSixteen( const OUString
& str
, sal_Int32 nReplacement
)
253 OUString
result( str
);
254 OUString sixteen
= OUString::valueOf( (sal_Int32
)16 );
255 OUString expected
= OUString::valueOf( nReplacement
);
257 sal_Int32 len
= sixteen
.getLength();
258 sal_Int32 index
= result
.indexOf( sixteen
);
260 while ( index
!= -1 )
262 result
= result
.replaceAt( index
, len
, expected
);
263 index
= result
.indexOf( sixteen
, index
);
271 const OUString
& prefix
,
273 sal_Int32 suffix
= 1 )
275 // find and replace the %n placeholder in the prefix string
277 OUString placeholder
= OUString::createFromAscii( "%n" );
279 sal_Int32 pos
= prefix
.indexOf(
280 OUString::createFromAscii( "%n" ) );
284 name
= prefix
.replaceAt(
285 pos
, placeholder
.getLength(), OUString::valueOf( suffix
) );
289 // no placeholder found so just append the suffix
290 name
= prefix
+ OUString::valueOf( suffix
);
293 // now check is there is an already existing entry with this name
294 SvxEntries::const_iterator iter
= entries
->begin();
296 SvxConfigEntry
* pEntry
;
297 while ( iter
!= entries
->end() )
301 if ( name
.equals( pEntry
->GetName() ) )
308 if ( iter
!= entries
->end() )
310 // name already exists so try the next number up
311 return generateCustomName( prefix
, entries
, ++suffix
);
317 sal_uInt32
generateRandomValue()
319 srand( unsigned( time( NULL
) ));
320 return sal_uInt32( rand() );
325 SvxEntries
* entries
)
327 OUString url
= OUString::createFromAscii( ITEM_TOOLBAR_URL
);
328 url
+= OUString::createFromAscii( CUSTOM_TOOLBAR_STR
);
330 // use a random number to minimize possible clash with existing custom toolbars
331 url
+= OUString::valueOf( sal_Int64( generateRandomValue() ), 16 );
333 // now check is there is an already existing entry with this url
334 SvxEntries::const_iterator iter
= entries
->begin();
336 SvxConfigEntry
* pEntry
;
337 while ( iter
!= entries
->end() )
341 if ( url
.equals( pEntry
->GetCommand() ) )
348 if ( iter
!= entries
->end() )
350 // url already exists so try the next number up
351 return generateCustomURL( entries
);
358 generateCustomMenuURL(
360 sal_Int32 suffix
= 1 )
362 OUString url
= OUString::createFromAscii( CUSTOM_MENU_STR
);
363 url
+= OUString::valueOf( suffix
);
365 // now check is there is an already existing entry with this url
366 SvxEntries::const_iterator iter
= entries
->begin();
368 SvxConfigEntry
* pEntry
;
369 while ( iter
!= entries
->end() )
373 if ( url
.equals( pEntry
->GetCommand() ) )
380 if ( iter
!= entries
->end() )
382 // url already exists so try the next number up
383 return generateCustomMenuURL( entries
, ++suffix
);
389 static sal_Int16 theImageType
=
390 css::ui::ImageType::COLOR_NORMAL
|
391 css::ui::ImageType::SIZE_DEFAULT
;
396 css::ui::ImageType::COLOR_NORMAL
|
397 css::ui::ImageType::SIZE_DEFAULT
;
399 if ( SvtMiscOptions().AreCurrentSymbolsLarge() )
401 theImageType
|= css::ui::ImageType::SIZE_LARGE
;
404 Window
* topwin
= Application::GetActiveTopWindow();
405 if ( topwin
!= NULL
&&
406 topwin
->GetDisplayBackground().GetColor().IsDark() )
408 theImageType
|= css::ui::ImageType::COLOR_HIGHCONTRAST
;
412 sal_Int16
GetImageType()
417 void RemoveEntry( SvxEntries
* pEntries
, SvxConfigEntry
* pChildEntry
)
419 SvxEntries::iterator iter
= pEntries
->begin();
421 while ( iter
!= pEntries
->end() )
423 if ( pChildEntry
== *iter
)
425 pEntries
->erase( iter
);
433 SvxConfigPage::CanConfig( const OUString
& aModuleId
)
435 OSL_TRACE("SupportsDocumentConfig: %s", PRTSTR(aModuleId
));
437 if ( aModuleId
.equalsAscii( "com.sun.star.script.BasicIDE" )
438 || aModuleId
.equalsAscii( "com.sun.star.frame.Bibliography" )
446 OUString
GetModuleName( const OUString
& aModuleId
)
448 if ( aModuleId
.equalsAscii( "com.sun.star.text.TextDocument" ) ||
449 aModuleId
.equalsAscii( "com.sun.star.text.GlobalDocument" ) )
450 return OUString::createFromAscii("Writer");
451 else if ( aModuleId
.equalsAscii( "com.sun.star.text.WebDocument" ) )
452 return OUString::createFromAscii("Writer/Web");
453 else if ( aModuleId
.equalsAscii( "com.sun.star.drawing.DrawingDocument" ) )
454 return OUString::createFromAscii("Draw");
455 else if ( aModuleId
.equalsAscii( "com.sun.star.presentation.PresentationDocument" ) )
456 return OUString::createFromAscii("Impress");
457 else if ( aModuleId
.equalsAscii( "com.sun.star.sheet.SpreadsheetDocument" ) )
458 return OUString::createFromAscii("Calc");
459 else if ( aModuleId
.equalsAscii( "com.sun.star.script.BasicIDE" ) )
460 return OUString::createFromAscii("Basic");
461 else if ( aModuleId
.equalsAscii( "com.sun.star.formula.FormulaProperties" ) )
462 return OUString::createFromAscii("Math");
463 else if ( aModuleId
.equalsAscii( "com.sun.star.sdb.RelationDesign" ) )
464 return OUString::createFromAscii("Relation Design");
465 else if ( aModuleId
.equalsAscii( "com.sun.star.sdb.QueryDesign" ) )
466 return OUString::createFromAscii("Query Design");
467 else if ( aModuleId
.equalsAscii( "com.sun.star.sdb.TableDesign" ) )
468 return OUString::createFromAscii("Table Design");
469 else if ( aModuleId
.equalsAscii( "com.sun.star.sdb.DataSourceBrowser" ) )
470 return OUString::createFromAscii("Data Source Browser" );
471 else if ( aModuleId
.equalsAscii( "com.sun.star.sdb.DatabaseDocument" ) )
472 return OUString::createFromAscii("Database" );
474 return ::rtl::OUString();
477 OUString
GetUIModuleName( const OUString
& aModuleId
, const uno::Reference
< css::frame::XModuleManager
>& rModuleManager
)
479 OUString aModuleUIName
;
481 if ( rModuleManager
.is() )
483 uno::Reference
< css::container::XNameAccess
> xNameAccess( rModuleManager
, uno::UNO_QUERY
);
484 if ( xNameAccess
.is() )
488 uno::Any a
= xNameAccess
->getByName( aModuleId
);
489 uno::Sequence
< beans::PropertyValue
> aSeq
;
494 for ( sal_Int32 i
= 0; i
< aSeq
.getLength(); i
++ )
496 if ( aSeq
[i
].Name
.equalsAscii( "ooSetupFactoryUIName" ))
498 aSeq
[i
].Value
>>= aModuleUIName
;
504 catch ( uno::RuntimeException
& e
)
508 catch ( uno::Exception
& )
514 if ( aModuleUIName
.getLength() == 0 )
515 aModuleUIName
= GetModuleName( aModuleId
);
517 return aModuleUIName
;
520 bool GetMenuItemData(
521 const uno::Reference
< container::XIndexAccess
>& rItemContainer
,
523 OUString
& rCommandURL
,
527 uno::Reference
< container::XIndexAccess
>& rSubMenu
)
531 uno::Sequence
< beans::PropertyValue
> aProp
;
532 if ( rItemContainer
->getByIndex( nIndex
) >>= aProp
)
534 for ( sal_Int32 i
= 0; i
< aProp
.getLength(); i
++ )
536 if ( aProp
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_COMMANDURL
))
538 aProp
[i
].Value
>>= rCommandURL
;
540 else if ( aProp
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_HELPURL
))
542 aProp
[i
].Value
>>= rHelpURL
;
544 else if ( aProp
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_CONTAINER
))
546 aProp
[i
].Value
>>= rSubMenu
;
548 else if ( aProp
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_LABEL
))
550 aProp
[i
].Value
>>= rLabel
;
552 else if ( aProp
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_TYPE
))
554 aProp
[i
].Value
>>= rType
;
561 catch ( ::com::sun::star::lang::IndexOutOfBoundsException
& )
568 bool GetToolbarItemData(
569 const uno::Reference
< container::XIndexAccess
>& rItemContainer
,
571 OUString
& rCommandURL
,
575 sal_Bool
& rIsVisible
,
577 uno::Reference
< container::XIndexAccess
>& rSubMenu
)
581 uno::Sequence
< beans::PropertyValue
> aProp
;
582 if ( rItemContainer
->getByIndex( nIndex
) >>= aProp
)
584 for ( sal_Int32 i
= 0; i
< aProp
.getLength(); i
++ )
586 if ( aProp
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_COMMANDURL
))
588 aProp
[i
].Value
>>= rCommandURL
;
590 if ( aProp
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_STYLE
))
592 aProp
[i
].Value
>>= rStyle
;
594 else if ( aProp
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_HELPURL
))
596 aProp
[i
].Value
>>= rHelpURL
;
598 else if (aProp
[i
].Name
.equalsAscii(ITEM_DESCRIPTOR_CONTAINER
))
600 aProp
[i
].Value
>>= rSubMenu
;
602 else if ( aProp
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_LABEL
))
604 aProp
[i
].Value
>>= rLabel
;
606 else if ( aProp
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_TYPE
))
608 aProp
[i
].Value
>>= rType
;
610 else if (aProp
[i
].Name
.equalsAscii(ITEM_DESCRIPTOR_ISVISIBLE
))
612 aProp
[i
].Value
>>= rIsVisible
;
619 catch ( ::com::sun::star::lang::IndexOutOfBoundsException
& )
626 uno::Sequence
< beans::PropertyValue
>
627 ConvertSvxConfigEntry(
628 const uno::Reference
< container::XNameAccess
>& xCommandToLabelMap
,
629 const SvxConfigEntry
* pEntry
)
631 static const OUString
aDescriptorCommandURL (
632 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_COMMANDURL
) );
634 static const OUString
aDescriptorType(
635 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_TYPE
) );
637 static const OUString
aDescriptorLabel(
638 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_LABEL
) );
640 static const OUString
aDescriptorHelpURL(
641 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_HELPURL
) );
643 static const OUString
aDescriptorContainer(
644 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_CONTAINER
) );
646 uno::Sequence
< beans::PropertyValue
> aPropSeq( 4 );
648 aPropSeq
[0].Name
= aDescriptorCommandURL
;
649 aPropSeq
[0].Value
<<= rtl::OUString( pEntry
->GetCommand() );
651 aPropSeq
[1].Name
= aDescriptorType
;
652 aPropSeq
[1].Value
<<= css::ui::ItemType::DEFAULT
;
654 // If the name has not been changed and the name is the same as
655 // in the default command to label map then the label can be stored
656 // as an empty string.
657 // It will be initialised again later using the command to label map.
658 aPropSeq
[2].Name
= aDescriptorLabel
;
659 if ( pEntry
->HasChangedName() == FALSE
&& pEntry
->GetCommand().getLength() )
661 BOOL isDefaultName
= FALSE
;
664 uno::Any
a( xCommandToLabelMap
->getByName( pEntry
->GetCommand() ) );
665 uno::Sequence
< beans::PropertyValue
> tmpPropSeq
;
666 if ( a
>>= tmpPropSeq
)
668 for ( sal_Int32 i
= 0; i
< tmpPropSeq
.getLength(); i
++ )
670 if ( tmpPropSeq
[i
].Name
.equals( aDescriptorLabel
) )
673 tmpPropSeq
[i
].Value
>>= tmpLabel
;
675 if ( tmpLabel
.equals( pEntry
->GetName() ) )
677 isDefaultName
= TRUE
;
685 catch ( container::NoSuchElementException
& )
687 // isDefaultName is left as FALSE
692 aPropSeq
[2].Value
<<= rtl::OUString();
696 aPropSeq
[2].Value
<<= rtl::OUString( pEntry
->GetName() );
701 aPropSeq
[2].Value
<<= rtl::OUString( pEntry
->GetName() );
704 aPropSeq
[3].Name
= aDescriptorHelpURL
;
705 aPropSeq
[3].Value
<<= rtl::OUString( pEntry
->GetHelpURL() );
710 uno::Sequence
< beans::PropertyValue
>
712 const uno::Reference
< container::XNameAccess
>& xCommandToLabelMap
,
713 const SvxConfigEntry
* pEntry
)
715 static const OUString
aDescriptorCommandURL (
716 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_COMMANDURL
) );
718 static const OUString
aDescriptorType(
719 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_TYPE
) );
721 static const OUString
aDescriptorLabel(
722 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_LABEL
) );
724 static const OUString
aDescriptorHelpURL(
725 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_HELPURL
) );
727 static const OUString
aDescriptorContainer(
728 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_CONTAINER
) );
730 static const OUString
aIsVisible(
731 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_ISVISIBLE
) );
733 uno::Sequence
< beans::PropertyValue
> aPropSeq( 5 );
735 aPropSeq
[0].Name
= aDescriptorCommandURL
;
736 aPropSeq
[0].Value
<<= rtl::OUString( pEntry
->GetCommand() );
738 aPropSeq
[1].Name
= aDescriptorType
;
739 aPropSeq
[1].Value
<<= css::ui::ItemType::DEFAULT
;
741 // If the name has not been changed and the name is the same as
742 // in the default command to label map then the label can be stored
743 // as an empty string.
744 // It will be initialised again later using the command to label map.
745 aPropSeq
[2].Name
= aDescriptorLabel
;
746 if ( pEntry
->HasChangedName() == FALSE
&& pEntry
->GetCommand().getLength() )
748 BOOL isDefaultName
= FALSE
;
751 uno::Any
a( xCommandToLabelMap
->getByName( pEntry
->GetCommand() ) );
752 uno::Sequence
< beans::PropertyValue
> tmpPropSeq
;
753 if ( a
>>= tmpPropSeq
)
755 for ( sal_Int32 i
= 0; i
< tmpPropSeq
.getLength(); i
++ )
757 if ( tmpPropSeq
[i
].Name
.equals( aDescriptorLabel
) )
760 tmpPropSeq
[i
].Value
>>= tmpLabel
;
762 if ( tmpLabel
.equals( pEntry
->GetName() ) )
764 isDefaultName
= TRUE
;
772 catch ( container::NoSuchElementException
& )
774 // isDefaultName is left as FALSE
779 aPropSeq
[2].Value
<<= rtl::OUString();
783 aPropSeq
[2].Value
<<= rtl::OUString( pEntry
->GetName() );
788 aPropSeq
[2].Value
<<= rtl::OUString( pEntry
->GetName() );
791 aPropSeq
[3].Name
= aDescriptorHelpURL
;
792 aPropSeq
[3].Value
<<= rtl::OUString( pEntry
->GetHelpURL() );
794 aPropSeq
[4].Name
= aIsVisible
;
795 aPropSeq
[4].Value
<<= pEntry
->IsVisible();
800 SfxTabPage
*CreateSvxMenuConfigPage( Window
*pParent
, const SfxItemSet
& rSet
)
802 return new SvxMenuConfigPage( pParent
, rSet
);
805 SfxTabPage
*CreateKeyboardConfigPage( Window
*pParent
, const SfxItemSet
& rSet
)
807 return new SfxAcceleratorConfigPage( pParent
, rSet
);
810 SfxTabPage
*CreateSvxToolbarConfigPage( Window
*pParent
, const SfxItemSet
& rSet
)
812 return new SvxToolbarConfigPage( pParent
, rSet
);
815 SfxTabPage
*CreateSvxEventConfigPage( Window
*pParent
, const SfxItemSet
& rSet
)
817 return new SvxEventConfigPage( pParent
, rSet
, SvxEventConfigPage::EarlyInit() );
820 sal_Bool
impl_showKeyConfigTabPage( const css::uno::Reference
< css::frame::XFrame
>& xFrame
)
822 static ::rtl::OUString SERVICENAME_MODULEMANAGER
= ::rtl::OUString::createFromAscii("com.sun.star.frame.ModuleManager");
823 static ::rtl::OUString SERVICENAME_DESKTOP
= ::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop" );
824 static ::rtl::OUString MODULEID_STARTMODULE
= ::rtl::OUString::createFromAscii("com.sun.star.frame.StartModule" );
828 css::uno::Reference
< css::lang::XMultiServiceFactory
> xSMGR
= ::comphelper::getProcessServiceFactory();
829 css::uno::Reference
< css::frame::XFramesSupplier
> xDesktop(xSMGR
->createInstance(SERVICENAME_DESKTOP
), css::uno::UNO_QUERY_THROW
);
830 css::uno::Reference
< css::frame::XModuleManager
> xMM (xSMGR
->createInstance(SERVICENAME_MODULEMANAGER
), css::uno::UNO_QUERY_THROW
);
832 if (xMM
.is() && xFrame
.is())
834 ::rtl::OUString sModuleId
= xMM
->identify(xFrame
);
836 ( sModuleId
.getLength() ) &&
837 (!sModuleId
.equals(MODULEID_STARTMODULE
))
842 catch(const css::uno::Exception
&)
848 /******************************************************************************
850 * SvxConfigDialog is the configuration dialog which is brought up from the
851 * Tools menu. It includes tabs for customizing menus, toolbars, events and
854 *****************************************************************************/
855 SvxConfigDialog::SvxConfigDialog(
856 Window
* pParent
, const SfxItemSet
* pSet_
)
858 SfxTabDialog( pParent
,
859 SVX_RES( RID_SVXDLG_CUSTOMIZE
), pSet_
)
865 AddTabPage( RID_SVXPAGE_MENUS
, CreateSvxMenuConfigPage
, NULL
);
866 AddTabPage( RID_SVXPAGE_KEYBOARD
, CreateKeyboardConfigPage
, NULL
);
867 AddTabPage( RID_SVXPAGE_TOOLBARS
, CreateSvxToolbarConfigPage
, NULL
);
868 AddTabPage( RID_SVXPAGE_EVENTS
, CreateSvxEventConfigPage
, NULL
);
870 const SfxPoolItem
* pItem
=
871 pSet_
->GetItem( pSet_
->GetPool()->GetWhich( SID_CONFIG
) );
875 OUString text
= ((const SfxStringItem
*)pItem
)->GetValue();
877 if (text
.indexOf(OUString::createFromAscii(ITEM_TOOLBAR_URL
)) == 0)
879 SetCurPageId( RID_SVXPAGE_TOOLBARS
);
884 void SvxConfigDialog::SetFrame(const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
>& xFrame
)
888 if (!impl_showKeyConfigTabPage( xFrame
))
889 RemoveTabPage( RID_SVXPAGE_KEYBOARD
);
892 SvxConfigDialog::~SvxConfigDialog()
896 short SvxConfigDialog::Ok()
898 return SfxTabDialog::Ok();
901 void SvxConfigDialog::PageCreated( USHORT nId
, SfxTabPage
& rPage
)
907 case RID_SVXPAGE_MENUS
:
908 case RID_SVXPAGE_TOOLBARS
:
909 case RID_SVXPAGE_KEYBOARD
:
911 rPage
.SetFrame(m_xFrame
);
914 case RID_SVXPAGE_EVENTS
:
916 dynamic_cast< SvxEventConfigPage
& >( rPage
).LateInit( m_xFrame
);
924 void SvxConfigDialog::ActivateTabPage( USHORT nSlotId
)
929 /******************************************************************************
931 * The SaveInData class is used to hold data for entries in the Save In
932 * ListBox controls in the menu and toolbar tabs
934 ******************************************************************************/
936 // Initialize static variable which holds default XImageManager
937 uno::Reference
< css::ui::XImageManager
>* SaveInData::xDefaultImgMgr
= NULL
;
939 SaveInData::SaveInData(
940 const uno::Reference
< css::ui::XUIConfigurationManager
>& xCfgMgr
,
941 const uno::Reference
< css::ui::XUIConfigurationManager
>& xParentCfgMgr
,
942 const OUString
& aModuleId
,
946 bDocConfig( isDocConfig
),
948 m_xCfgMgr( xCfgMgr
),
949 m_xParentCfgMgr( xParentCfgMgr
)
951 uno::Reference
< beans::XPropertySet
> xProps(
952 ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY
);
954 xProps
->getPropertyValue(
955 OUString::createFromAscii( "DefaultContext" ))
956 >>= m_xComponentContext
;
958 m_aSeparatorSeq
.realloc( 1 );
959 m_aSeparatorSeq
[0].Name
= OUString(
960 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_TYPE
) );
961 m_aSeparatorSeq
[0].Value
<<= css::ui::ItemType::SEPARATOR_LINE
;
965 uno::Reference
< css::ui::XUIConfigurationPersistence
>
966 xDocPersistence( GetConfigManager(), uno::UNO_QUERY
);
968 bReadOnly
= xDocPersistence
->isReadOnly();
971 m_xServiceManager
= uno::Reference
< lang::XMultiServiceFactory
>(
972 ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW
);
974 uno::Reference
< container::XNameAccess
> xNameAccess(
975 m_xServiceManager
->createInstance(
976 OUString( RTL_CONSTASCII_USTRINGPARAM(
977 "com.sun.star.frame.UICommandDescription" ) ) ),
980 if ( xNameAccess
.is() )
981 xNameAccess
->getByName( aModuleId
) >>= m_xCommandToLabelMap
;
983 if ( !m_xImgMgr
.is() )
985 m_xImgMgr
= uno::Reference
< css::ui::XImageManager
>(
986 GetConfigManager()->getImageManager(), uno::UNO_QUERY
);
989 if ( !IsDocConfig() )
991 // If this is not a document configuration then it is the settings
992 // for the module (writer, calc, impress etc.) Use this as the default
993 // XImageManager instance
994 xDefaultImgMgr
= &m_xImgMgr
;
998 // If this is a document configuration then use the module image manager
1000 if ( m_xParentCfgMgr
.is() )
1002 m_xParentImgMgr
= uno::Reference
< css::ui::XImageManager
>(
1003 m_xParentCfgMgr
->getImageManager(), uno::UNO_QUERY
);
1004 xDefaultImgMgr
= &m_xParentImgMgr
;
1009 uno::Reference
< graphic::XGraphic
> GetGraphic(
1010 const uno::Reference
< css::ui::XImageManager
>& xImageManager
,
1011 const OUString
& rCommandURL
)
1013 uno::Reference
< graphic::XGraphic
> result
;
1015 if ( xImageManager
.is() )
1017 // TODO handle large and high contrast graphics
1018 uno::Sequence
< uno::Reference
< graphic::XGraphic
> > aGraphicSeq
;
1020 uno::Sequence
< OUString
> aImageCmdSeq( 1 );
1021 aImageCmdSeq
[0] = rCommandURL
;
1026 xImageManager
->getImages( GetImageType(), aImageCmdSeq
);
1028 if ( aGraphicSeq
.getLength() > 0 )
1030 result
= aGraphicSeq
[0];
1033 catch ( uno::Exception
& )
1035 // will return empty XGraphic
1042 Image
SaveInData::GetImage( const OUString
& rCommandURL
)
1046 uno::Reference
< graphic::XGraphic
> xGraphic
=
1047 GetGraphic( m_xImgMgr
, rCommandURL
);
1049 if ( xGraphic
.is() )
1051 aImage
= Image( xGraphic
);
1053 else if ( xDefaultImgMgr
!= NULL
&& (*xDefaultImgMgr
).is() )
1055 xGraphic
= GetGraphic( (*xDefaultImgMgr
), rCommandURL
);
1057 if ( xGraphic
.is() )
1059 aImage
= Image( xGraphic
);
1066 bool SaveInData::PersistChanges(
1067 const uno::Reference
< uno::XInterface
>& xManager
)
1073 if ( xManager
.is() && !IsReadOnly() )
1075 uno::Reference
< css::ui::XUIConfigurationPersistence
>
1076 xConfigPersistence( xManager
, uno::UNO_QUERY
);
1078 if ( xConfigPersistence
->isModified() )
1080 xConfigPersistence
->store();
1084 catch ( com::sun::star::io::IOException
& )
1092 /******************************************************************************
1094 * The MenuSaveInData class extends SaveInData and provides menu specific
1095 * load and store functionality.
1097 ******************************************************************************/
1099 // Initialize static variable which holds default Menu data
1100 MenuSaveInData
* MenuSaveInData::pDefaultData
= NULL
;
1102 MenuSaveInData::MenuSaveInData(
1103 const uno::Reference
< css::ui::XUIConfigurationManager
>& cfgmgr
,
1104 const uno::Reference
< css::ui::XUIConfigurationManager
>& xParentCfgMgr
,
1105 const OUString
& aModuleId
,
1108 SaveInData( cfgmgr
, xParentCfgMgr
, aModuleId
, isDocConfig
),
1110 RTL_CONSTASCII_USTRINGPARAM( ITEM_MENUBAR_URL
) ),
1111 m_aDescriptorContainer(
1112 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_CONTAINER
) ),
1117 OUString
url( RTL_CONSTASCII_USTRINGPARAM( ITEM_MENUBAR_URL
) );
1118 m_xMenuSettings
= GetConfigManager()->getSettings( url
, sal_False
);
1120 catch ( container::NoSuchElementException
& )
1122 // will use menu settings for the module
1125 // If this is not a document configuration then it is the settings
1126 // for the module (writer, calc, impress etc.). These settings should
1127 // be set as the default to be used for SaveIn locations that do not
1128 // have custom settings
1129 if ( !IsDocConfig() )
1131 SetDefaultData( this );
1135 MenuSaveInData::~MenuSaveInData()
1137 if ( pRootEntry
!= NULL
)
1144 MenuSaveInData::GetEntries()
1146 if ( pRootEntry
== NULL
)
1148 pRootEntry
= new SvxConfigEntry(
1149 String::CreateFromAscii("MainMenus"), String(), TRUE
);
1151 if ( m_xMenuSettings
.is() )
1153 LoadSubMenus( m_xMenuSettings
, String(), pRootEntry
);
1155 else if ( GetDefaultData() != NULL
)
1157 // If the doc has no config settings use module config settings
1158 LoadSubMenus( GetDefaultData()->m_xMenuSettings
, String(), pRootEntry
);
1162 return pRootEntry
->GetEntries();
1166 MenuSaveInData::SetEntries( SvxEntries
* pNewEntries
)
1168 // delete old menu hierarchy first
1169 if ( pRootEntry
!= NULL
)
1171 delete pRootEntry
->GetEntries();
1174 // now set new menu hierarchy
1175 pRootEntry
->SetEntries( pNewEntries
);
1178 bool MenuSaveInData::LoadSubMenus(
1179 const uno::Reference
< container::XIndexAccess
>& xMenuSettings
,
1180 const OUString
& rBaseTitle
,
1181 SvxConfigEntry
* pParentData
)
1183 SvxEntries
* pEntries
= pParentData
->GetEntries();
1185 for ( sal_Int32 nIndex
= 0; nIndex
< xMenuSettings
->getCount(); nIndex
++ )
1187 uno::Reference
< container::XIndexAccess
> xSubMenu
;
1188 OUString aCommandURL
;
1191 bool bIsUserDefined
= TRUE
;
1193 sal_uInt16
nType( css::ui::ItemType::DEFAULT
);
1195 bool bItem
= GetMenuItemData( xMenuSettings
, nIndex
,
1196 aCommandURL
, aHelpURL
, aLabel
, nType
, xSubMenu
);
1200 if ( nType
== css::ui::ItemType::DEFAULT
)
1205 a
= m_xCommandToLabelMap
->getByName( aCommandURL
);
1206 bIsUserDefined
= FALSE
;
1208 catch ( container::NoSuchElementException
& )
1210 bIsUserDefined
= TRUE
;
1213 // If custom label not set retrieve it from the command
1215 if ( aLabel
.equals( OUString() ) )
1217 uno::Sequence
< beans::PropertyValue
> aPropSeq
;
1218 if ( a
>>= aPropSeq
)
1220 for ( sal_Int32 i
= 0; i
< aPropSeq
.getLength(); i
++ )
1222 if ( aPropSeq
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_LABEL
) )
1224 aPropSeq
[i
].Value
>>= aLabel
;
1231 if ( xSubMenu
.is() )
1234 SvxConfigEntry
* pEntry
= new SvxConfigEntry(
1235 aLabel
, aCommandURL
, TRUE
);
1237 pEntry
->SetUserDefined( bIsUserDefined
);
1238 pEntry
->SetHelpURL( aHelpURL
);
1240 pEntries
->push_back( pEntry
);
1242 OUString
subMenuTitle( rBaseTitle
);
1244 if ( subMenuTitle
.getLength() != 0 )
1247 OUString::createFromAscii(pMenuSeparatorStr
);
1251 pEntry
->SetMain( TRUE
);
1254 subMenuTitle
+= stripHotKey( aLabel
);
1256 LoadSubMenus( xSubMenu
, subMenuTitle
, pEntry
);
1260 SvxConfigEntry
* pEntry
= new SvxConfigEntry(
1261 aLabel
, aCommandURL
, FALSE
);
1262 pEntry
->SetUserDefined( bIsUserDefined
);
1263 pEntry
->SetHelpURL( aHelpURL
);
1264 pEntries
->push_back( pEntry
);
1269 SvxConfigEntry
* pEntry
= new SvxConfigEntry
;
1270 pEntry
->SetUserDefined( bIsUserDefined
);
1271 pEntries
->push_back( pEntry
);
1278 bool MenuSaveInData::Apply()
1280 bool result
= FALSE
;
1284 // Apply new menu bar structure to our settings container
1285 m_xMenuSettings
= uno::Reference
< container::XIndexAccess
>(
1286 GetConfigManager()->createSettings(), uno::UNO_QUERY
);
1288 uno::Reference
< container::XIndexContainer
> xIndexContainer (
1289 m_xMenuSettings
, uno::UNO_QUERY
);
1291 uno::Reference
< lang::XSingleComponentFactory
> xFactory (
1292 m_xMenuSettings
, uno::UNO_QUERY
);
1294 Apply( pRootEntry
, xIndexContainer
, xFactory
, NULL
);
1298 if ( GetConfigManager()->hasSettings( m_aMenuResourceURL
) )
1300 GetConfigManager()->replaceSettings(
1301 m_aMenuResourceURL
, m_xMenuSettings
);
1305 GetConfigManager()->insertSettings(
1306 m_aMenuResourceURL
, m_xMenuSettings
);
1309 catch ( container::NoSuchElementException
& )
1311 OSL_TRACE("caught container::NoSuchElementException saving settings");
1313 catch ( com::sun::star::io::IOException
& )
1315 OSL_TRACE("caught IOException saving settings");
1317 catch ( com::sun::star::uno::Exception
& )
1319 OSL_TRACE("caught some other exception saving settings");
1322 SetModified( FALSE
);
1324 result
= PersistChanges( GetConfigManager() );
1330 void MenuSaveInData::Apply(
1331 SvxConfigEntry
* pRootEntry_
,
1332 uno::Reference
< container::XIndexContainer
>& rMenuBar
,
1333 uno::Reference
< lang::XSingleComponentFactory
>& rFactory
,
1334 SvLBoxEntry
*pParentEntry
)
1339 SvxEntries::const_iterator iter
= GetEntries()->begin();
1340 SvxEntries::const_iterator end
= GetEntries()->end();
1342 for ( ; iter
!= end
; iter
++ )
1344 SvxConfigEntry
* pEntryData
= *iter
;
1346 uno::Sequence
< beans::PropertyValue
> aPropValueSeq
=
1347 ConvertSvxConfigEntry( m_xCommandToLabelMap
, pEntryData
);
1349 uno::Reference
< container::XIndexContainer
> xSubMenuBar(
1350 rFactory
->createInstanceWithContext( m_xComponentContext
),
1353 sal_Int32 nIndex
= aPropValueSeq
.getLength();
1354 aPropValueSeq
.realloc( nIndex
+ 1 );
1355 aPropValueSeq
[nIndex
].Name
= m_aDescriptorContainer
;
1356 aPropValueSeq
[nIndex
].Value
<<= xSubMenuBar
;
1357 rMenuBar
->insertByIndex(
1358 rMenuBar
->getCount(), uno::makeAny( aPropValueSeq
));
1359 ApplyMenu( xSubMenuBar
, rFactory
, pEntryData
);
1363 void MenuSaveInData::ApplyMenu(
1364 uno::Reference
< container::XIndexContainer
>& rMenuBar
,
1365 uno::Reference
< lang::XSingleComponentFactory
>& rFactory
,
1366 SvxConfigEntry
* pMenuData
)
1368 SvxEntries::const_iterator iter
= pMenuData
->GetEntries()->begin();
1369 SvxEntries::const_iterator end
= pMenuData
->GetEntries()->end();
1371 for ( ; iter
!= end
; iter
++ )
1373 SvxConfigEntry
* pEntry
= *iter
;
1375 if ( pEntry
->IsPopup() )
1377 uno::Sequence
< beans::PropertyValue
> aPropValueSeq
=
1378 ConvertSvxConfigEntry( m_xCommandToLabelMap
, pEntry
);
1380 uno::Reference
< container::XIndexContainer
> xSubMenuBar(
1381 rFactory
->createInstanceWithContext( m_xComponentContext
),
1384 sal_Int32 nIndex
= aPropValueSeq
.getLength();
1385 aPropValueSeq
.realloc( nIndex
+ 1 );
1386 aPropValueSeq
[nIndex
].Name
= m_aDescriptorContainer
;
1387 aPropValueSeq
[nIndex
].Value
<<= xSubMenuBar
;
1389 rMenuBar
->insertByIndex(
1390 rMenuBar
->getCount(), uno::makeAny( aPropValueSeq
));
1392 ApplyMenu( xSubMenuBar
, rFactory
, pEntry
);
1394 else if ( pEntry
->IsSeparator() )
1396 rMenuBar
->insertByIndex(
1397 rMenuBar
->getCount(), uno::makeAny( m_aSeparatorSeq
));
1401 uno::Sequence
< beans::PropertyValue
> aPropValueSeq
=
1402 ConvertSvxConfigEntry( m_xCommandToLabelMap
, pEntry
);
1403 rMenuBar
->insertByIndex(
1404 rMenuBar
->getCount(), uno::makeAny( aPropValueSeq
));
1410 MenuSaveInData::Reset()
1412 GetConfigManager()->reset();
1419 m_xMenuSettings
= GetConfigManager()->getSettings(
1420 m_aMenuResourceURL
, sal_False
);
1422 catch ( container::NoSuchElementException
& )
1424 // will use default settings
1428 class PopupPainter
: public SvLBoxString
1431 PopupPainter( SvLBoxEntry
* pEntry
, const String
& rStr
)
1432 : SvLBoxString( pEntry
, 0, rStr
)
1437 void Paint( const Point
& rPos
, SvLBox
& rOutDev
,
1438 USHORT nViewDataEntryFlags
, SvLBoxEntry
* pEntry
)
1440 SvLBoxString::Paint( rPos
, rOutDev
, nViewDataEntryFlags
, pEntry
);
1442 Color aOldFillColor
= rOutDev
.GetFillColor();
1444 SvTreeListBox
* pTreeBox
= static_cast< SvTreeListBox
* >( &rOutDev
);
1445 long nX
= pTreeBox
->GetSizePixel().Width();
1447 ScrollBar
* pVScroll
= pTreeBox
->GetVScroll();
1448 if ( pVScroll
->IsVisible() )
1450 nX
-= pVScroll
->GetSizePixel().Width();
1453 SvViewDataItem
* pItem
= rOutDev
.GetViewDataItem( pEntry
, this );
1454 nX
-= pItem
->aSize
.Height();
1456 long nSize
= pItem
->aSize
.Height() / 2;
1457 long nHalfSize
= nSize
/ 2;
1458 long nY
= rPos
.Y() + nHalfSize
;
1460 if ( aOldFillColor
== COL_WHITE
)
1462 rOutDev
.SetFillColor( Color( COL_BLACK
) );
1466 rOutDev
.SetFillColor( Color( COL_WHITE
) );
1470 while ( n
<= nHalfSize
)
1472 rOutDev
.DrawRect( Rectangle( nX
+n
, nY
+n
, nX
+n
, nY
+nSize
-n
) );
1476 rOutDev
.SetFillColor( aOldFillColor
);
1480 /******************************************************************************
1482 * SvxMenuEntriesListBox is the listbox in which the menu items for a
1483 * particular menu are shown. We have a custom listbox because we need
1484 * to add drag'n'drop support from the Macro Selector and within the
1487 *****************************************************************************/
1488 SvxMenuEntriesListBox::SvxMenuEntriesListBox(
1489 Window
* pParent
, const ResId
& rResId
)
1490 : SvTreeListBox( pParent
, rResId
)
1491 , pPage( (SvxMenuConfigPage
*) pParent
)
1492 , m_bIsInternalDrag( FALSE
)
1495 GetStyle() | WB_CLIPCHILDREN
| WB_HSCROLL
| WB_HIDESELECTION
);
1497 SetSpaceBetweenEntries( 3 );
1498 SetEntryHeight( ENTRY_HEIGHT
);
1500 SetHighlightRange();
1501 SetSelectionMode(SINGLE_SELECTION
);
1503 SetDragDropMode( SV_DRAGDROP_CTRL_MOVE
|
1504 SV_DRAGDROP_APP_COPY
|
1505 SV_DRAGDROP_ENABLE_TOP
|
1506 SV_DRAGDROP_APP_DROP
);
1509 SvxMenuEntriesListBox::~SvxMenuEntriesListBox()
1514 // drag and drop support
1515 DragDropMode
SvxMenuEntriesListBox::NotifyStartDrag(
1516 TransferDataContainer
& aTransferDataContainer
, SvLBoxEntry
* pEntry
)
1518 (void)aTransferDataContainer
;
1521 m_bIsInternalDrag
= TRUE
;
1522 return GetDragDropMode();
1525 void SvxMenuEntriesListBox::DragFinished( sal_Int8 nDropAction
)
1528 m_bIsInternalDrag
= FALSE
;
1531 sal_Int8
SvxMenuEntriesListBox::AcceptDrop( const AcceptDropEvent
& rEvt
)
1533 if ( m_bIsInternalDrag
)
1535 // internal copy isn't allowed!
1536 if ( rEvt
.mnAction
== DND_ACTION_COPY
)
1537 return DND_ACTION_NONE
;
1539 return SvTreeListBox::AcceptDrop( rEvt
);
1542 // Always do COPY instead of MOVE if D&D comes from outside!
1543 AcceptDropEvent
aNewAcceptDropEvent( rEvt
);
1544 aNewAcceptDropEvent
.mnAction
= DND_ACTION_COPY
;
1545 return SvTreeListBox::AcceptDrop( aNewAcceptDropEvent
);
1548 BOOL
SvxMenuEntriesListBox::NotifyAcceptDrop( SvLBoxEntry
* )
1553 BOOL
SvxMenuEntriesListBox::NotifyMoving(
1554 SvLBoxEntry
* pTarget
, SvLBoxEntry
* pSource
,
1555 SvLBoxEntry
*& rpNewParent
, ULONG
& rNewChildPos
)
1557 // only try to do a move if we are dragging within the list box
1558 if ( m_bIsInternalDrag
)
1560 if ( pPage
->MoveEntryData( pSource
, pTarget
) == TRUE
)
1562 SvTreeListBox::NotifyMoving(
1563 pTarget
, pSource
, rpNewParent
, rNewChildPos
);
1573 return NotifyCopying( pTarget
, pSource
, rpNewParent
, rNewChildPos
);
1577 BOOL
SvxMenuEntriesListBox::NotifyCopying(
1578 SvLBoxEntry
* pTarget
, SvLBoxEntry
* pSource
,
1579 SvLBoxEntry
*& rpNewParent
, ULONG
& rNewChildPos
)
1585 if ( !m_bIsInternalDrag
)
1587 // if the target is NULL then add function to the start of the list
1588 pPage
->AddFunction( pTarget
, pTarget
== NULL
);
1590 // AddFunction already adds the listbox entry so return FALSE
1591 // to stop another listbox entry being added
1595 // Copying is only allowed from external controls, not within the listbox
1599 void SvxMenuEntriesListBox::KeyInput( const KeyEvent
& rKeyEvent
)
1601 KeyCode keycode
= rKeyEvent
.GetKeyCode();
1603 // support DELETE for removing the current entry
1604 if ( keycode
== KEY_DELETE
)
1606 pPage
->DeleteSelectedContent();
1608 // support CTRL+UP and CTRL+DOWN for moving selected entries
1609 else if ( keycode
.GetCode() == KEY_UP
&& keycode
.IsMod1() )
1611 pPage
->MoveEntry( TRUE
);
1613 else if ( keycode
.GetCode() == KEY_DOWN
&& keycode
.IsMod1() )
1615 pPage
->MoveEntry( FALSE
);
1619 // pass on to superclass
1620 SvTreeListBox::KeyInput( rKeyEvent
);
1624 // class SvxDescriptionEdit ----------------------------------------------
1626 SvxDescriptionEdit::SvxDescriptionEdit( Window
* pParent
, const ResId
& _rId
) :
1628 ExtMultiLineEdit( pParent
, _rId
)
1631 // calculate the available space for help text
1632 m_aRealRect
= Rectangle( Point(), GetSizePixel() );
1633 if ( GetVScrollBar() )
1634 m_aRealRect
.Right() -= ( GetVScrollBar()->GetSizePixel().Width() + 4 );
1637 SetBorderStyle( WINDOW_BORDER_MONO
);
1640 // -----------------------------------------------------------------------
1642 void SvxDescriptionEdit::SetNewText( const String
& _rText
)
1644 String
sTemp( _rText
);
1645 sal_Bool bShow
= sal_False
;
1646 if ( sTemp
.Len() > 0 )
1648 // detect if a scrollbar is necessary
1649 Rectangle aRect
= GetTextRect( m_aRealRect
, sTemp
, TEXT_DRAW_WORDBREAK
| TEXT_DRAW_MULTILINE
);
1650 bShow
= ( aRect
.Bottom() > m_aRealRect
.Bottom() );
1653 if ( GetVScrollBar() )
1654 GetVScrollBar()->Show( bShow
);
1662 /******************************************************************************
1664 * SvxConfigPage is the abstract base class on which the Menu and Toolbar
1665 * configuration tabpages are based. It includes methods which are common to
1666 * both tabpages to add, delete, move and rename items etc.
1668 *****************************************************************************/
1669 SvxConfigPage::SvxConfigPage(
1670 Window
*pParent
, const SfxItemSet
& rSet
)
1672 SfxTabPage( pParent
, SVX_RES( RID_SVXPAGE_MENUS
), rSet
),
1673 bInitialised( FALSE
),
1674 pCurrentSaveInData( 0 ),
1675 aTopLevelSeparator( this, SVX_RES( GRP_MENUS
) ),
1676 aTopLevelLabel( this, SVX_RES( FT_MENUS
) ),
1677 aTopLevelListBox( this, SVX_RES( LB_MENUS
) ),
1678 aNewTopLevelButton( this, SVX_RES( BTN_NEW
) ),
1679 aModifyTopLevelButton( this, SVX_RES( BTN_CHANGE
) ),
1680 aContentsSeparator( this, SVX_RES( GRP_MENU_SEPARATOR
) ),
1681 aContentsLabel( this, SVX_RES( GRP_MENU_ENTRIES
) ),
1682 aContentsListBox( 0 ),
1683 aAddCommandsButton( this, SVX_RES( BTN_ADD_COMMANDS
) ),
1684 aModifyCommandButton( this, SVX_RES( BTN_CHANGE_ENTRY
) ),
1685 aMoveUpButton( this, SVX_RES( BTN_UP
) ),
1686 aMoveDownButton( this, SVX_RES( BTN_DOWN
) ),
1687 aSaveInText( this, SVX_RES( TXT_SAVEIN
) ),
1688 aSaveInListBox( this, SVX_RES( LB_SAVEIN
) ),
1689 aDescriptionLabel( this, SVX_RES( FT_DESCRIPTION
) ),
1690 aDescriptionField( this, SVX_RES( ED_DESCRIPTION
) ),
1693 aDescriptionField
.SetControlBackground( GetSettings().GetStyleSettings().GetDialogColor() );
1694 aDescriptionField
.SetAutoScroll( TRUE
);
1695 aDescriptionField
.EnableCursor( FALSE
);
1698 SvxConfigPage::~SvxConfigPage()
1702 void SvxConfigPage::Reset( const SfxItemSet
& )
1704 // If we haven't initialised our XMultiServiceFactory reference
1705 // then Reset is being called at the opening of the dialog.
1707 // Load menu configuration data for the module of the currently
1708 // selected document, for the currently selected document, and for
1709 // all other open documents of the same module type
1710 if ( !bInitialised
)
1713 uno::Reference
< css::ui::XUIConfigurationManager
> xCfgMgr
;
1714 uno::Reference
< css::ui::XUIConfigurationManager
> xDocCfgMgr
;
1716 uno::Reference
< lang::XMultiServiceFactory
> xServiceManager(
1717 ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW
);
1719 m_xFrame
= GetFrame();
1720 OUString aModuleId
= GetFrameWithDefaultAndIdentify( m_xFrame
);
1722 // replace %MODULENAME in the label with the correct module name
1723 uno::Reference
< css::frame::XModuleManager
> xModuleManager(
1724 xServiceManager
->createInstance(
1725 OUString( RTL_CONSTASCII_USTRINGPARAM(
1726 "com.sun.star.frame.ModuleManager" ) ) ),
1727 uno::UNO_QUERY_THROW
);
1728 OUString aModuleName
= GetUIModuleName( aModuleId
, xModuleManager
);
1730 OUString title
= aTopLevelSeparator
.GetText();
1731 OUString aSearchString
= OUString::createFromAscii( "%MODULENAME" );
1732 sal_Int32 index
= title
.indexOf( aSearchString
);
1736 title
= title
.replaceAt(
1737 index
, aSearchString
.getLength(), aModuleName
);
1738 aTopLevelSeparator
.SetText( title
);
1741 uno::Reference
< css::ui::XModuleUIConfigurationManagerSupplier
>
1742 xModuleCfgSupplier( xServiceManager
->createInstance(
1743 OUString( RTL_CONSTASCII_USTRINGPARAM(
1744 "com.sun.star.ui.ModuleUIConfigurationManagerSupplier" ))),
1747 // Set up data for module specific menus
1748 SaveInData
* pModuleData
= NULL
;
1753 xModuleCfgSupplier
->getUIConfigurationManager( aModuleId
);
1755 pModuleData
= CreateSaveInData( xCfgMgr
,
1756 uno::Reference
< css::ui::XUIConfigurationManager
>(),
1760 catch ( container::NoSuchElementException
& )
1764 if ( pModuleData
!= NULL
)
1767 utl::ConfigManager::GetDirectConfigProperty(
1768 utl::ConfigManager::PRODUCTNAME
) >>= label
;
1769 label
+= OUString::createFromAscii( " " );
1770 label
+= aModuleName
;
1772 nPos
= aSaveInListBox
.InsertEntry( label
);
1773 aSaveInListBox
.SetEntryData( nPos
, pModuleData
);
1776 // try to retrieve the document based ui configuration manager
1778 uno::Reference
< frame::XController
> xController
=
1779 m_xFrame
->getController();
1780 if ( CanConfig( aModuleId
) && xController
.is() )
1782 uno::Reference
< frame::XModel
> xModel( xController
->getModel() );
1785 uno::Reference
< css::ui::XUIConfigurationManagerSupplier
>
1786 xCfgSupplier( xModel
, uno::UNO_QUERY
);
1788 if ( xCfgSupplier
.is() )
1790 xDocCfgMgr
= xCfgSupplier
->getUIConfigurationManager();
1792 aTitle
= ::comphelper::DocumentInfo::getDocumentTitle( xModel
);
1796 SaveInData
* pDocData
= NULL
;
1797 if ( xDocCfgMgr
.is() )
1799 pDocData
= CreateSaveInData( xDocCfgMgr
, xCfgMgr
, aModuleId
, TRUE
);
1801 if ( !pDocData
->IsReadOnly() )
1803 nPos
= aSaveInListBox
.InsertEntry( aTitle
);
1804 aSaveInListBox
.SetEntryData( nPos
, pDocData
);
1808 // if an item to select has been passed in (eg. the ResourceURL for a
1809 // toolbar) then try to select the SaveInData entry that has that item
1810 bool bURLToSelectFound
= FALSE
;
1811 if ( m_aURLToSelect
.getLength() != 0 )
1813 if ( pDocData
!= NULL
&& pDocData
->HasURL( m_aURLToSelect
) )
1815 aSaveInListBox
.SelectEntryPos( nPos
, TRUE
);
1816 pCurrentSaveInData
= pDocData
;
1817 bURLToSelectFound
= TRUE
;
1819 else if ( pModuleData
->HasURL( m_aURLToSelect
) )
1821 aSaveInListBox
.SelectEntryPos( 0, TRUE
);
1822 pCurrentSaveInData
= pModuleData
;
1823 bURLToSelectFound
= TRUE
;
1827 if ( bURLToSelectFound
== FALSE
)
1829 // if the document has menu configuration settings select it
1830 // it the SaveIn listbox, otherwise select the module data
1831 if ( pDocData
!= NULL
&& pDocData
->HasSettings() )
1833 aSaveInListBox
.SelectEntryPos( nPos
, TRUE
);
1834 pCurrentSaveInData
= pDocData
;
1838 aSaveInListBox
.SelectEntryPos( 0, TRUE
);
1839 pCurrentSaveInData
= pModuleData
;
1844 DBG_ASSERT( pCurrentSaveInData
, "SvxConfigPage::Reset(): no SaveInData" );
1847 if ( CanConfig( aModuleId
) )
1849 // Load configuration for other open documents which have
1851 uno::Sequence
< uno::Reference
< frame::XFrame
> > aFrameList
;
1854 uno::Reference
< frame::XFramesSupplier
> xFramesSupplier(
1855 xServiceManager
->createInstance(
1856 OUString( RTL_CONSTASCII_USTRINGPARAM(
1857 "com.sun.star.frame.Desktop" ) ) ),
1858 uno::UNO_QUERY_THROW
);
1860 uno::Reference
< frame::XFrames
> xFrames
=
1861 xFramesSupplier
->getFrames();
1863 aFrameList
= xFrames
->queryFrames(
1864 frame::FrameSearchFlag::ALL
& ~frame::FrameSearchFlag::SELF
);
1867 catch( const uno::Exception
& )
1869 DBG_UNHANDLED_EXCEPTION();
1872 for ( sal_Int32 i
= 0; i
< aFrameList
.getLength(); i
++ )
1874 SaveInData
* pData
= NULL
;
1875 uno::Reference
< frame::XFrame
> xf
= aFrameList
[i
];
1877 if ( xf
.is() && xf
!= m_xFrame
)
1881 aCheckId
= xModuleManager
->identify( xf
);
1882 } catch(const uno::Exception
&)
1883 { aCheckId
= ::rtl::OUString(); }
1885 if ( aModuleId
.equals( aCheckId
) )
1887 // try to get the document based ui configuration manager
1889 uno::Reference
< frame::XController
> xController_
=
1890 xf
->getController();
1892 if ( xController_
.is() )
1894 uno::Reference
< frame::XModel
> xModel(
1895 xController_
->getModel() );
1900 css::ui::XUIConfigurationManagerSupplier
>
1901 xCfgSupplier( xModel
, uno::UNO_QUERY
);
1903 if ( xCfgSupplier
.is() )
1906 xCfgSupplier
->getUIConfigurationManager();
1908 aTitle2
= ::comphelper::DocumentInfo::getDocumentTitle( xModel
);
1912 if ( xDocCfgMgr
.is() )
1914 pData
= CreateSaveInData( xDocCfgMgr
, xCfgMgr
, aModuleId
, TRUE
);
1916 if ( pData
&& !pData
->IsReadOnly() )
1918 nPos
= aSaveInListBox
.InsertEntry( aTitle2
);
1919 aSaveInListBox
.SetEntryData( nPos
, pData
);
1927 aSaveInListBox
.SetSelectHdl(
1928 LINK( this, SvxConfigPage
, SelectSaveInLocation
) );
1930 bInitialised
= TRUE
;
1936 if ( QueryReset() == RET_YES
)
1938 // Reset menu configuration for currently selected SaveInData
1939 GetSaveInData()->Reset();
1946 ::rtl::OUString
SvxConfigPage::GetFrameWithDefaultAndIdentify( uno::Reference
< frame::XFrame
>& _inout_rxFrame
)
1948 ::rtl::OUString sModuleID
;
1951 uno::Reference
< lang::XMultiServiceFactory
> xServiceManager(
1952 ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW
);
1954 uno::Reference
< frame::XFramesSupplier
> xFramesSupplier(
1955 xServiceManager
->createInstance(
1956 OUString( RTL_CONSTASCII_USTRINGPARAM(
1957 "com.sun.star.frame.Desktop" ) ) ),
1958 uno::UNO_QUERY_THROW
);
1960 if ( !_inout_rxFrame
.is() )
1961 _inout_rxFrame
= xFramesSupplier
->getActiveFrame();
1963 if ( !_inout_rxFrame
.is() )
1965 uno::Reference
< frame::XDesktop
> xDesktop( xFramesSupplier
, uno::UNO_QUERY_THROW
);
1966 _inout_rxFrame
= xDesktop
->getCurrentFrame();
1969 if ( !_inout_rxFrame
.is() && SfxViewFrame::Current() )
1970 _inout_rxFrame
= SfxViewFrame::Current()->GetFrame()->GetFrameInterface();
1972 if ( !_inout_rxFrame
.is() )
1974 DBG_ERRORFILE( "SvxConfigPage::GetFrameWithDefaultAndIdentify(): no frame found!" );
1978 uno::Reference
< css::frame::XModuleManager
> xModuleManager(
1979 xServiceManager
->createInstance(
1980 OUString( RTL_CONSTASCII_USTRINGPARAM(
1981 "com.sun.star.frame.ModuleManager" ) ) ),
1982 uno::UNO_QUERY_THROW
);
1986 sModuleID
= xModuleManager
->identify( _inout_rxFrame
);
1988 catch ( const frame::UnknownModuleException
& )
1993 catch( const uno::Exception
& )
1995 DBG_UNHANDLED_EXCEPTION();
2001 BOOL
SvxConfigPage::FillItemSet( SfxItemSet
& )
2003 bool result
= FALSE
;
2005 for ( USHORT i
= 0 ; i
< aSaveInListBox
.GetEntryCount(); i
++ )
2008 (SaveInData
*) aSaveInListBox
.GetEntryData( i
);
2010 result
= pData
->Apply();
2015 void SvxConfigPage::PositionContentsListBox()
2017 if ( aContentsListBox
== NULL
)
2024 long x
, y
, width
, height
;
2026 // x and width is same as aTopLevelListBox
2027 x
= aTopLevelListBox
.GetPosPixel().X();
2028 width
= aTopLevelListBox
.GetSizePixel().Width();
2030 // y is same as aAddCommandsButton
2031 y
= aAddCommandsButton
.GetPosPixel().Y();
2033 // get gap between aAddCommandsButton and aContentsSeparator
2034 p
= aContentsSeparator
.GetPosPixel();
2035 s
= aContentsSeparator
.GetSizePixel();
2036 long gap
= y
- ( p
.Y() + s
.Height() );
2038 height
= aSaveInListBox
.GetPosPixel().Y() - y
- gap
;
2040 aContentsListBox
->SetPosPixel( Point( x
, y
) );
2041 aContentsListBox
->SetSizePixel( Size( width
, height
) );
2044 IMPL_LINK( SvxConfigPage
, SelectSaveInLocation
, ListBox
*, pBox
)
2048 pCurrentSaveInData
= (SaveInData
*) aSaveInListBox
.GetEntryData(
2049 aSaveInListBox
.GetSelectEntryPos());
2055 void SvxConfigPage::ReloadTopLevelListBox( SvxConfigEntry
* pToSelect
)
2057 USHORT nSelectionPos
= aTopLevelListBox
.GetSelectEntryPos();
2058 aTopLevelListBox
.Clear();
2060 if ( GetSaveInData() && GetSaveInData()->GetEntries() )
2062 SvxEntries::const_iterator iter
= GetSaveInData()->GetEntries()->begin();
2063 SvxEntries::const_iterator end
= GetSaveInData()->GetEntries()->end();
2065 for ( ; iter
!= end
; iter
++ )
2067 SvxConfigEntry
* pEntryData
= *iter
;
2068 USHORT nPos
= aTopLevelListBox
.InsertEntry( stripHotKey( pEntryData
->GetName() ) );
2069 aTopLevelListBox
.SetEntryData( nPos
, pEntryData
);
2071 if ( pEntryData
== pToSelect
)
2072 nSelectionPos
= nPos
;
2074 AddSubMenusToUI( stripHotKey( pEntryData
->GetName() ), pEntryData
);
2080 DBG_ASSERT( GetSaveInData(), "SvxConfigPage::ReloadTopLevelListBox(): no SaveInData" );
2081 DBG_ASSERT( GetSaveInData()->GetEntries() ,
2082 "SvxConfigPage::ReloadTopLevelListBox(): no SaveInData entries" );
2086 nSelectionPos
= nSelectionPos
< aTopLevelListBox
.GetEntryCount() ?
2087 nSelectionPos
: aTopLevelListBox
.GetEntryCount() - 1;
2089 aTopLevelListBox
.SelectEntryPos( nSelectionPos
, TRUE
);
2090 aTopLevelListBox
.GetSelectHdl().Call( this );
2093 void SvxConfigPage::AddSubMenusToUI(
2094 const String
& rBaseTitle
, SvxConfigEntry
* pParentData
)
2096 SvxEntries::const_iterator iter
= pParentData
->GetEntries()->begin();
2097 SvxEntries::const_iterator end
= pParentData
->GetEntries()->end();
2099 for ( ; iter
!= end
; iter
++ )
2101 SvxConfigEntry
* pEntryData
= *iter
;
2103 if ( pEntryData
->IsPopup() )
2105 OUString
subMenuTitle( rBaseTitle
);
2106 subMenuTitle
+= OUString::createFromAscii( pMenuSeparatorStr
);
2107 subMenuTitle
+= stripHotKey( pEntryData
->GetName() );
2109 USHORT nPos
= aTopLevelListBox
.InsertEntry( subMenuTitle
);
2110 aTopLevelListBox
.SetEntryData( nPos
, pEntryData
);
2112 AddSubMenusToUI( subMenuTitle
, pEntryData
);
2117 SvxEntries
* SvxConfigPage::FindParentForChild(
2118 SvxEntries
* pRootEntries
, SvxConfigEntry
* pChildData
)
2120 SvxEntries::const_iterator iter
= pRootEntries
->begin();
2121 SvxEntries::const_iterator end
= pRootEntries
->end();
2123 for ( ; iter
!= end
; iter
++ )
2125 SvxConfigEntry
* pEntryData
= *iter
;
2127 if ( pEntryData
== pChildData
)
2129 return pRootEntries
;
2131 else if ( pEntryData
->IsPopup() )
2133 SvxEntries
* result
=
2134 FindParentForChild( pEntryData
->GetEntries(), pChildData
);
2136 if ( result
!= NULL
)
2145 SvLBoxEntry
* SvxConfigPage::AddFunction(
2146 SvLBoxEntry
* pTarget
, bool bFront
, bool bAllowDuplicates
)
2148 String aDisplayName
= pSelectorDlg
->GetSelectedDisplayName();
2149 String aHelpText
= pSelectorDlg
->GetSelectedHelpText();
2150 String aURL
= pSelectorDlg
->GetScriptURL();
2157 SvxConfigEntry
* pNewEntryData
=
2158 new SvxConfigEntry( aDisplayName
, aURL
, FALSE
);
2159 pNewEntryData
->SetUserDefined( TRUE
);
2160 pNewEntryData
->SetHelpURL( aURL
);
2162 // check that this function is not already in the menu
2163 SvxConfigEntry
* pParent
= GetTopLevelSelection();
2165 SvxEntries::const_iterator iter
= pParent
->GetEntries()->begin();
2166 SvxEntries::const_iterator end
= pParent
->GetEntries()->end();
2168 if ( !bAllowDuplicates
)
2170 while ( iter
!= end
)
2172 SvxConfigEntry
*pCurEntry
= *iter
;
2174 if ( pCurEntry
->GetCommand() == pNewEntryData
->GetCommand() )
2176 // asynchronous error message, because of MsgBoxes
2178 LINK( this, SvxConfigPage
, AsyncInfoMsg
) );
2186 return InsertEntry( pNewEntryData
, pTarget
, bFront
);
2189 SvLBoxEntry
* SvxConfigPage::InsertEntry(
2190 SvxConfigEntry
* pNewEntryData
,
2191 SvLBoxEntry
* pTarget
,
2194 // Grab the entries list for the currently selected menu
2195 SvxEntries
* pEntries
= GetTopLevelSelection()->GetEntries();
2197 SvLBoxEntry
* pNewEntry
= NULL
;
2198 SvLBoxEntry
* pCurEntry
=
2199 pTarget
!= NULL
? pTarget
: aContentsListBox
->GetCurEntry();
2203 pEntries
->insert( pEntries
->begin(), pNewEntryData
);
2204 pNewEntry
= InsertEntryIntoUI( pNewEntryData
, 0 );
2206 else if ( pCurEntry
== NULL
|| pCurEntry
== aContentsListBox
->Last() )
2208 pEntries
->push_back( pNewEntryData
);
2209 pNewEntry
= InsertEntryIntoUI( pNewEntryData
);
2213 SvxConfigEntry
* pEntryData
=
2214 (SvxConfigEntry
*) pCurEntry
->GetUserData();
2216 SvxEntries::iterator iter
= pEntries
->begin();
2217 SvxEntries::const_iterator end
= pEntries
->end();
2219 // Advance the iterator to the data for currently selected entry
2221 while (*iter
!= pEntryData
&& ++iter
!= end
)
2226 // Now step past it to the entry after the currently selected one
2230 // Now add the new entry to the UI and to the parent's list
2233 pEntries
->insert( iter
, pNewEntryData
);
2234 pNewEntry
= InsertEntryIntoUI( pNewEntryData
, nPos
);
2238 if ( pNewEntry
!= NULL
)
2240 aContentsListBox
->Select( pNewEntry
);
2241 aContentsListBox
->MakeVisible( pNewEntry
);
2243 GetSaveInData()->SetModified( TRUE
);
2249 SvLBoxEntry
* SvxConfigPage::InsertEntryIntoUI(
2250 SvxConfigEntry
* pNewEntryData
, ULONG nPos
)
2252 SvLBoxEntry
* pNewEntry
= NULL
;
2254 if (pNewEntryData
->IsSeparator())
2256 pNewEntry
= aContentsListBox
->InsertEntry(
2257 String::CreateFromAscii( pSeparatorStr
),
2258 0, FALSE
, nPos
, pNewEntryData
);
2262 OUString aName
= stripHotKey( pNewEntryData
->GetName() );
2264 Image aImage
= GetSaveInData()->GetImage(
2265 pNewEntryData
->GetCommand());
2269 pNewEntry
= aContentsListBox
->InsertEntry(
2270 aName
, aImage
, aImage
, 0, FALSE
, nPos
, pNewEntryData
);
2274 pNewEntry
= aContentsListBox
->InsertEntry(
2275 aName
, 0, FALSE
, nPos
, pNewEntryData
);
2278 if ( pNewEntryData
->IsPopup() ||
2279 pNewEntryData
->GetStyle() & css::ui::ItemStyle::DROP_DOWN
)
2281 // add new popup painter, it gets destructed by the entry
2282 pNewEntry
->ReplaceItem(
2283 new PopupPainter( pNewEntry
, aName
),
2284 pNewEntry
->ItemCount() - 1 );
2291 IMPL_LINK( SvxConfigPage
, AsyncInfoMsg
, String
*, pMsg
)
2295 // Asynchronous msg because of D&D
2296 InfoBox( this, SVX_RES(
2297 IBX_MNUCFG_ALREADY_INCLUDED
) ).Execute();
2302 IMPL_LINK( SvxConfigPage
, MoveHdl
, Button
*, pButton
)
2304 MoveEntry( pButton
== &aMoveUpButton
);
2308 void SvxConfigPage::MoveEntry( bool bMoveUp
)
2310 SvLBoxEntry
*pSourceEntry
= aContentsListBox
->FirstSelected();
2311 SvLBoxEntry
*pTargetEntry
= NULL
;
2312 SvLBoxEntry
*pToSelect
= NULL
;
2314 if ( !pSourceEntry
)
2321 // Move Up is just a Move Down with the source and target reversed
2322 pTargetEntry
= pSourceEntry
;
2323 pSourceEntry
= aContentsListBox
->PrevSibling( pTargetEntry
);
2324 pToSelect
= pTargetEntry
;
2328 pTargetEntry
= aContentsListBox
->NextSibling( pSourceEntry
);
2329 pToSelect
= pSourceEntry
;
2332 if ( MoveEntryData( pSourceEntry
, pTargetEntry
) )
2334 aContentsListBox
->GetModel()->Move( pSourceEntry
, pTargetEntry
);
2335 aContentsListBox
->Select( pToSelect
);
2336 aContentsListBox
->MakeVisible( pToSelect
);
2338 UpdateButtonStates();
2342 bool SvxConfigPage::MoveEntryData(
2343 SvLBoxEntry
* pSourceEntry
, SvLBoxEntry
* pTargetEntry
)
2345 //modified by shizhoubo for issue53677
2346 if ( NULL
== pSourceEntry
|| NULL
== pTargetEntry
)
2351 // Grab the entries list for the currently selected menu
2352 SvxEntries
* pEntries
= GetTopLevelSelection()->GetEntries();
2354 SvxConfigEntry
* pSourceData
=
2355 (SvxConfigEntry
*) pSourceEntry
->GetUserData();
2357 if ( pTargetEntry
== NULL
)
2359 RemoveEntry( pEntries
, pSourceData
);
2361 pEntries
->begin(), pSourceData
);
2363 GetSaveInData()->SetModified( TRUE
);
2369 SvxConfigEntry
* pTargetData
=
2370 (SvxConfigEntry
*) pTargetEntry
->GetUserData();
2372 if ( pSourceData
!= NULL
&& pTargetData
!= NULL
)
2374 // remove the source entry from our list
2375 RemoveEntry( pEntries
, pSourceData
);
2377 SvxEntries::iterator iter
= pEntries
->begin();
2378 SvxEntries::const_iterator end
= pEntries
->end();
2380 // advance the iterator to the position of the target entry
2381 while (*iter
!= pTargetData
&& ++iter
!= end
) ;
2383 // insert the source entry at the position after the target
2384 pEntries
->insert( ++iter
, pSourceData
);
2386 GetSaveInData()->SetModified( TRUE
);
2395 SvxMenuConfigPage::SvxMenuConfigPage(
2396 Window
*pParent
, const SfxItemSet
& rSet
)
2398 SvxConfigPage( pParent
, rSet
)
2400 aContentsListBox
= new SvxMenuEntriesListBox( this, SVX_RES( BOX_ENTRIES
) );
2403 PositionContentsListBox();
2404 aContentsListBox
->SetZOrder( &aAddCommandsButton
, WINDOW_ZORDER_BEFOR
);
2406 aTopLevelListBox
.SetSelectHdl(
2407 LINK( this, SvxMenuConfigPage
, SelectMenu
) );
2409 aContentsListBox
->SetSelectHdl(
2410 LINK( this, SvxMenuConfigPage
, SelectMenuEntry
) );
2412 aMoveUpButton
.SetClickHdl ( LINK( this, SvxConfigPage
, MoveHdl
) );
2413 aMoveDownButton
.SetClickHdl ( LINK( this, SvxConfigPage
, MoveHdl
) );
2415 aNewTopLevelButton
.SetClickHdl (
2416 LINK( this, SvxMenuConfigPage
, NewMenuHdl
) );
2418 aAddCommandsButton
.SetClickHdl (
2419 LINK( this, SvxMenuConfigPage
, AddCommandsHdl
) );
2421 PopupMenu
* pMenu
= new PopupMenu( SVX_RES( MODIFY_MENU
) );
2422 pMenu
->SetMenuFlags(
2423 pMenu
->GetMenuFlags() | MENU_FLAG_ALWAYSSHOWDISABLEDENTRIES
);
2425 aModifyTopLevelButton
.SetPopupMenu( pMenu
);
2426 aModifyTopLevelButton
.SetSelectHdl(
2427 LINK( this, SvxMenuConfigPage
, MenuSelectHdl
) );
2429 PopupMenu
* pEntry
= new PopupMenu( SVX_RES( MODIFY_ENTRY
) );
2430 pEntry
->SetMenuFlags(
2431 pEntry
->GetMenuFlags() | MENU_FLAG_ALWAYSSHOWDISABLEDENTRIES
);
2433 aModifyCommandButton
.SetPopupMenu( pEntry
);
2434 aModifyCommandButton
.SetSelectHdl(
2435 LINK( this, SvxMenuConfigPage
, EntrySelectHdl
) );
2438 // Populates the Menu combo box
2439 void SvxMenuConfigPage::Init()
2441 // ensure that the UI is cleared before populating it
2442 aTopLevelListBox
.Clear();
2443 aContentsListBox
->Clear();
2445 ReloadTopLevelListBox();
2447 aTopLevelListBox
.SelectEntryPos(0, TRUE
);
2448 aTopLevelListBox
.GetSelectHdl().Call(this);
2451 SvxMenuConfigPage::~SvxMenuConfigPage()
2453 for ( USHORT i
= 0 ; i
< aSaveInListBox
.GetEntryCount(); i
++ )
2455 MenuSaveInData
* pData
=
2456 (MenuSaveInData
*) aSaveInListBox
.GetEntryData( i
);
2461 if ( pSelectorDlg
!= NULL
)
2463 delete pSelectorDlg
;
2466 delete aContentsListBox
;
2469 IMPL_LINK( SvxMenuConfigPage
, SelectMenuEntry
, Control
*, pBox
)
2473 UpdateButtonStates();
2478 void SvxMenuConfigPage::UpdateButtonStates()
2480 PopupMenu
* pPopup
= aModifyCommandButton
.GetPopupMenu();
2482 // Disable Up and Down buttons depending on current selection
2483 SvLBoxEntry
* selection
= aContentsListBox
->GetCurEntry();
2485 if ( aContentsListBox
->GetEntryCount() == 0 || selection
== NULL
)
2487 aMoveUpButton
.Enable( FALSE
);
2488 aMoveDownButton
.Enable( FALSE
);
2490 pPopup
->EnableItem( ID_BEGIN_GROUP
, TRUE
);
2491 pPopup
->EnableItem( ID_RENAME
, FALSE
);
2492 pPopup
->EnableItem( ID_DELETE
, FALSE
);
2494 aDescriptionField
.Clear();
2499 SvLBoxEntry
* first
= aContentsListBox
->First();
2500 SvLBoxEntry
* last
= aContentsListBox
->Last();
2502 aMoveUpButton
.Enable( selection
!= first
);
2503 aMoveDownButton
.Enable( selection
!= last
);
2505 SvxConfigEntry
* pEntryData
=
2506 (SvxConfigEntry
*) selection
->GetUserData();
2508 if ( pEntryData
->IsSeparator() )
2510 pPopup
->EnableItem( ID_DELETE
, TRUE
);
2511 pPopup
->EnableItem( ID_BEGIN_GROUP
, FALSE
);
2512 pPopup
->EnableItem( ID_RENAME
, FALSE
);
2514 aDescriptionField
.Clear();
2518 pPopup
->EnableItem( ID_BEGIN_GROUP
, TRUE
);
2519 pPopup
->EnableItem( ID_DELETE
, TRUE
);
2520 pPopup
->EnableItem( ID_RENAME
, TRUE
);
2522 aDescriptionField
.SetNewText( pEntryData
->GetHelpText() );
2526 void SvxMenuConfigPage::DeleteSelectedTopLevel()
2528 SvxConfigEntry
* pMenuData
= GetTopLevelSelection();
2530 SvxEntries
* pParentEntries
=
2531 FindParentForChild( GetSaveInData()->GetEntries(), pMenuData
);
2533 RemoveEntry( pParentEntries
, pMenuData
);
2536 ReloadTopLevelListBox();
2538 GetSaveInData()->SetModified( TRUE
);
2541 bool SvxMenuConfigPage::DeleteSelectedContent()
2543 SvLBoxEntry
*pActEntry
= aContentsListBox
->FirstSelected();
2545 if ( pActEntry
!= NULL
)
2547 // get currently selected menu entry
2548 SvxConfigEntry
* pMenuEntry
=
2549 (SvxConfigEntry
*) pActEntry
->GetUserData();
2551 // get currently selected menu
2552 SvxConfigEntry
* pMenu
= GetTopLevelSelection();
2554 // remove menu entry from the list for this menu
2555 RemoveEntry( pMenu
->GetEntries(), pMenuEntry
);
2557 // remove menu entry from UI
2558 aContentsListBox
->GetModel()->Remove( pActEntry
);
2560 // if this is a submenu entry, redraw the menus list box
2561 if ( pMenuEntry
->IsPopup() )
2563 ReloadTopLevelListBox();
2566 // delete data for menu entry
2569 GetSaveInData()->SetModified( TRUE
);
2576 short SvxMenuConfigPage::QueryReset()
2579 String( SVX_RES( RID_SVXSTR_CONFIRM_MENU_RESET
) );
2581 String saveInName
= aSaveInListBox
.GetEntry(
2582 aSaveInListBox
.GetSelectEntryPos() );
2584 OUString label
= replaceSaveInName( msg
, saveInName
);
2586 QueryBox
qbox( this, WB_YES_NO
, label
);
2588 return qbox
.Execute();
2591 IMPL_LINK( SvxMenuConfigPage
, SelectMenu
, ListBox
*, pBox
)
2595 aContentsListBox
->Clear();
2597 SvxConfigEntry
* pMenuData
= GetTopLevelSelection();
2599 PopupMenu
* pPopup
= aModifyTopLevelButton
.GetPopupMenu();
2600 pPopup
->EnableItem( ID_DELETE
, pMenuData
->IsDeletable() );
2601 pPopup
->EnableItem( ID_RENAME
, pMenuData
->IsRenamable() );
2602 pPopup
->EnableItem( ID_MOVE
, pMenuData
->IsMovable() );
2604 SvxEntries
* pEntries
= pMenuData
->GetEntries();
2605 SvxEntries::const_iterator iter
= pEntries
->begin();
2607 for ( ; iter
!= pEntries
->end(); iter
++ )
2609 SvxConfigEntry
* pEntry
= *iter
;
2610 InsertEntryIntoUI( pEntry
);
2613 UpdateButtonStates();
2618 IMPL_LINK( SvxMenuConfigPage
, MenuSelectHdl
, MenuButton
*, pButton
)
2620 switch( pButton
->GetCurItemId() )
2624 DeleteSelectedTopLevel();
2629 SvxConfigEntry
* pMenuData
= GetTopLevelSelection();
2631 String
aNewName( stripHotKey( pMenuData
->GetName() ) );
2632 String aDesc
= SVX_RESSSTR( RID_SVXSTR_LABEL_NEW_NAME
);
2634 SvxNameDialog
* pNameDialog
= new SvxNameDialog( this, aNewName
, aDesc
);
2635 pNameDialog
->SetHelpId( HID_SVX_CONFIG_RENAME_MENU
);
2636 pNameDialog
->SetText( SVX_RESSTR( RID_SVXSTR_RENAME_MENU
) );
2638 bool ret
= pNameDialog
->Execute();
2640 if ( ret
== RET_OK
) {
2641 pNameDialog
->GetName( aNewName
);
2642 pMenuData
->SetName( aNewName
);
2644 ReloadTopLevelListBox();
2646 GetSaveInData()->SetModified( TRUE
);
2649 // #i68101# Moemory leak (!)
2656 SvxConfigEntry
* pMenuData
= GetTopLevelSelection();
2658 SvxMainMenuOrganizerDialog
* pDialog
=
2659 new SvxMainMenuOrganizerDialog( this,
2660 GetSaveInData()->GetEntries(), pMenuData
);
2662 bool ret
= pDialog
->Execute();
2664 if ( ret
== RET_OK
)
2666 GetSaveInData()->SetEntries( pDialog
->GetEntries() );
2668 ReloadTopLevelListBox( pDialog
->GetSelectedEntry() );
2670 GetSaveInData()->SetModified( TRUE
);
2683 IMPL_LINK( SvxMenuConfigPage
, EntrySelectHdl
, MenuButton
*, pButton
)
2685 switch( pButton
->GetCurItemId() )
2687 case ID_ADD_SUBMENU
:
2690 String aDesc
= SVX_RESSSTR( RID_SVXSTR_SUBMENU_NAME
);
2692 SvxNameDialog
* pNameDialog
= new SvxNameDialog( this, aNewName
, aDesc
);
2693 pNameDialog
->SetHelpId( HID_SVX_CONFIG_NAME_SUBMENU
);
2694 pNameDialog
->SetText( SVX_RESSTR( RID_SVXSTR_ADD_SUBMENU
) );
2696 bool ret
= pNameDialog
->Execute();
2698 if ( ret
== RET_OK
) {
2699 pNameDialog
->GetName(aNewName
);
2701 SvxConfigEntry
* pNewEntryData
=
2702 new SvxConfigEntry( aNewName
, aNewName
, TRUE
);
2703 pNewEntryData
->SetUserDefined( TRUE
);
2705 InsertEntry( pNewEntryData
);
2707 ReloadTopLevelListBox();
2709 GetSaveInData()->SetModified( TRUE
);
2716 case ID_BEGIN_GROUP
:
2718 SvxConfigEntry
* pNewEntryData
= new SvxConfigEntry
;
2719 pNewEntryData
->SetUserDefined( TRUE
);
2720 InsertEntry( pNewEntryData
);
2726 DeleteSelectedContent();
2731 SvLBoxEntry
* pActEntry
= aContentsListBox
->GetCurEntry();
2732 SvxConfigEntry
* pEntry
=
2733 (SvxConfigEntry
*) pActEntry
->GetUserData();
2735 String
aNewName( stripHotKey( pEntry
->GetName() ) );
2736 String aDesc
= SVX_RESSSTR( RID_SVXSTR_LABEL_NEW_NAME
);
2738 SvxNameDialog
* pNameDialog
= new SvxNameDialog( this, aNewName
, aDesc
);
2739 pNameDialog
->SetHelpId( HID_SVX_CONFIG_RENAME_MENU_ITEM
);
2740 pNameDialog
->SetText( SVX_RESSTR( RID_SVXSTR_RENAME_MENU
) );
2742 bool ret
= pNameDialog
->Execute();
2744 if ( ret
== RET_OK
) {
2745 pNameDialog
->GetName(aNewName
);
2747 pEntry
->SetName( aNewName
);
2748 aContentsListBox
->SetEntryText( pActEntry
, aNewName
);
2750 GetSaveInData()->SetModified( TRUE
);
2763 if ( GetSaveInData()->IsModified() )
2765 UpdateButtonStates();
2771 IMPL_LINK( SvxMenuConfigPage
, AddFunctionHdl
,
2772 SvxScriptSelectorDialog
*, pDialog
)
2781 IMPL_LINK( SvxMenuConfigPage
, NewMenuHdl
, Button
*, pButton
)
2785 SvxMainMenuOrganizerDialog
* pDialog
=
2786 new SvxMainMenuOrganizerDialog( 0,
2787 GetSaveInData()->GetEntries(), NULL
, TRUE
);
2789 bool ret
= pDialog
->Execute();
2791 if ( ret
== RET_OK
)
2793 GetSaveInData()->SetEntries( pDialog
->GetEntries() );
2794 ReloadTopLevelListBox( pDialog
->GetSelectedEntry() );
2795 GetSaveInData()->SetModified( TRUE
);
2803 IMPL_LINK( SvxMenuConfigPage
, AddCommandsHdl
, Button
*, pButton
)
2807 if ( pSelectorDlg
== NULL
)
2809 // Create Script Selector which also shows builtin commands
2810 pSelectorDlg
= new SvxScriptSelectorDialog( this, TRUE
, m_xFrame
);
2812 pSelectorDlg
->SetAddHdl(
2813 LINK( this, SvxMenuConfigPage
, AddFunctionHdl
) );
2815 pSelectorDlg
->SetDialogDescription( String(
2816 SVX_RES( RID_SVXSTR_MENU_ADDCOMMANDS_DESCRIPTION
) ) );
2819 // Position the Script Selector over the Add button so it is
2820 // beside the menu contents list and does not obscure it
2821 pSelectorDlg
->SetPosPixel( aAddCommandsButton
.GetPosPixel() );
2823 pSelectorDlg
->SetImageProvider(
2824 static_cast< ImageProvider
* >( GetSaveInData() ) );
2826 pSelectorDlg
->Show();
2830 SaveInData
* SvxMenuConfigPage::CreateSaveInData(
2831 const uno::Reference
< css::ui::XUIConfigurationManager
>& xCfgMgr
,
2832 const uno::Reference
< css::ui::XUIConfigurationManager
>& xParentCfgMgr
,
2833 const OUString
& aModuleId
,
2836 return static_cast< SaveInData
* >(
2837 new MenuSaveInData( xCfgMgr
, xParentCfgMgr
, aModuleId
, bDocConfig
));
2840 SvxMainMenuOrganizerDialog::SvxMainMenuOrganizerDialog(
2841 Window
* pParent
, SvxEntries
* entries
,
2842 SvxConfigEntry
* selection
, bool bCreateMenu
)
2844 ModalDialog( pParent
, SVX_RES( MD_MENU_ORGANISER
) ),
2845 aMenuNameText( this, SVX_RES( TXT_MENU_NAME
) ),
2846 aMenuNameEdit( this, SVX_RES( EDIT_MENU_NAME
) ),
2847 aMenuListText( this, SVX_RES( TXT_MENU
) ),
2848 aMenuListBox( this, SVX_RES( BOX_MAIN_MENUS
) ),
2849 aMoveUpButton( this, SVX_RES( BTN_MENU_UP
) ),
2850 aMoveDownButton( this, SVX_RES( BTN_MENU_DOWN
) ),
2851 aOKButton( this, SVX_RES( BTN_MENU_ADD
) ),
2852 aCloseButton( this, SVX_RES( BTN_MENU_CLOSE
) ),
2853 aHelpButton( this, SVX_RES( BTN_MENU_HELP
) ),
2858 // Copy the entries list passed in
2859 if ( entries
!= NULL
)
2861 SvxConfigEntry
* pEntry
;
2862 SvLBoxEntry
* pLBEntry
;
2864 pEntries
= new SvxEntries();
2865 SvxEntries::const_iterator iter
= entries
->begin();
2867 while ( iter
!= entries
->end() )
2871 aMenuListBox
.InsertEntry( stripHotKey( pEntry
->GetName() ) );
2872 pLBEntry
->SetUserData( pEntry
);
2873 pEntries
->push_back( pEntry
);
2875 if ( pEntry
== selection
)
2877 aMenuListBox
.Select( pLBEntry
);
2885 // Generate custom name for new menu
2887 String( SVX_RES( RID_SVXSTR_NEW_MENU
) );
2889 OUString newname
= generateCustomName( prefix
, entries
);
2890 OUString newurl
= generateCustomMenuURL( pEntries
);
2892 SvxConfigEntry
* pNewEntryData
=
2893 new SvxConfigEntry( newname
, newurl
, TRUE
);
2894 pNewEntryData
->SetUserDefined( TRUE
);
2895 pNewEntryData
->SetMain( TRUE
);
2898 aMenuListBox
.InsertEntry( stripHotKey( pNewEntryData
->GetName() ) );
2899 aMenuListBox
.Select( pNewMenuEntry
);
2901 pNewMenuEntry
->SetUserData( pNewEntryData
);
2903 pEntries
->push_back( pNewEntryData
);
2905 aMenuNameEdit
.SetText( newname
);
2906 aMenuNameEdit
.SetModifyHdl(
2907 LINK( this, SvxMainMenuOrganizerDialog
, ModifyHdl
) );
2914 // get offset to bottom of name textfield from top of dialog
2915 p
= aMenuNameEdit
.GetPosPixel();
2916 s
= aMenuNameEdit
.GetSizePixel();
2917 long offset
= p
.Y() + s
.Height();
2919 // reposition menu list and label
2920 aMenuListText
.SetPosPixel( aMenuNameText
.GetPosPixel() );
2921 aMenuListBox
.SetPosPixel( aMenuNameEdit
.GetPosPixel() );
2923 // reposition up and down buttons
2924 p
= aMoveUpButton
.GetPosPixel();
2925 newp
= Point( p
.X(), p
.Y() - offset
);
2926 aMoveUpButton
.SetPosPixel( newp
);
2928 p
= aMoveDownButton
.GetPosPixel();
2929 newp
= Point( p
.X(), p
.Y() - offset
);
2930 aMoveDownButton
.SetPosPixel( newp
);
2932 // change size of dialog
2934 news
= Size( s
.Width(), s
.Height() - offset
);
2935 SetSizePixel( news
);
2937 // hide name label and textfield
2938 aMenuNameText
.Hide();
2939 aMenuNameEdit
.Hide();
2942 SetText( SVX_RES( RID_SVXSTR_MOVE_MENU
) );
2945 aMenuListBox
.SetSelectHdl(
2946 LINK( this, SvxMainMenuOrganizerDialog
, SelectHdl
) );
2948 aMoveUpButton
.SetClickHdl (
2949 LINK( this, SvxMainMenuOrganizerDialog
, MoveHdl
) );
2950 aMoveDownButton
.SetClickHdl (
2951 LINK( this, SvxMainMenuOrganizerDialog
, MoveHdl
) );
2954 IMPL_LINK(SvxMainMenuOrganizerDialog
, ModifyHdl
, Edit
*, pEdit
)
2958 // if the Edit control is empty do not change the name
2959 if ( aMenuNameEdit
.GetText().Equals( String() ) )
2964 SvxConfigEntry
* pNewEntryData
=
2965 (SvxConfigEntry
*) pNewMenuEntry
->GetUserData();
2967 pNewEntryData
->SetName( aMenuNameEdit
.GetText() );
2969 aMenuListBox
.SetEntryText( pNewMenuEntry
, pNewEntryData
->GetName() );
2974 SvxMainMenuOrganizerDialog::~SvxMainMenuOrganizerDialog()
2978 IMPL_LINK( SvxMainMenuOrganizerDialog
, SelectHdl
, Control
*, pCtrl
)
2981 UpdateButtonStates();
2985 void SvxMainMenuOrganizerDialog::UpdateButtonStates()
2987 // Disable Up and Down buttons depending on current selection
2988 SvLBoxEntry
* selection
= aMenuListBox
.GetCurEntry();
2989 SvLBoxEntry
* first
= aMenuListBox
.First();
2990 SvLBoxEntry
* last
= aMenuListBox
.Last();
2992 aMoveUpButton
.Enable( selection
!= first
);
2993 aMoveDownButton
.Enable( selection
!= last
);
2996 IMPL_LINK( SvxMainMenuOrganizerDialog
, MoveHdl
, Button
*, pButton
)
2998 SvLBoxEntry
*pSourceEntry
= aMenuListBox
.FirstSelected();
2999 SvLBoxEntry
*pTargetEntry
= NULL
;
3001 if ( !pSourceEntry
)
3006 if ( pButton
== &aMoveDownButton
)
3008 pTargetEntry
= aMenuListBox
.NextSibling( pSourceEntry
);
3010 else if ( pButton
== &aMoveUpButton
)
3012 // Move Up is just a Move Down with the source and target reversed
3013 pTargetEntry
= pSourceEntry
;
3014 pSourceEntry
= aMenuListBox
.PrevSibling( pTargetEntry
);
3017 if ( pSourceEntry
!= NULL
&& pTargetEntry
!= NULL
)
3019 SvxConfigEntry
* pSourceData
=
3020 (SvxConfigEntry
*) pSourceEntry
->GetUserData();
3021 SvxConfigEntry
* pTargetData
=
3022 (SvxConfigEntry
*) pTargetEntry
->GetUserData();
3024 SvxEntries::iterator iter1
= GetEntries()->begin();
3025 SvxEntries::iterator iter2
= GetEntries()->begin();
3026 SvxEntries::const_iterator end
= GetEntries()->end();
3028 // Advance the iterators to the positions of the source and target
3029 while (*iter1
!= pSourceData
&& ++iter1
!= end
) ;
3030 while (*iter2
!= pTargetData
&& ++iter2
!= end
) ;
3032 // Now swap the entries in the menu list and in the UI
3033 if ( iter1
!= end
&& iter2
!= end
)
3035 std::swap( *iter1
, *iter2
);
3036 aMenuListBox
.GetModel()->Move( pSourceEntry
, pTargetEntry
);
3037 aMenuListBox
.MakeVisible( pSourceEntry
);
3045 UpdateButtonStates();
3051 SvxEntries
* SvxMainMenuOrganizerDialog::GetEntries()
3056 SvxConfigEntry
* SvxMainMenuOrganizerDialog::GetSelectedEntry()
3058 return (SvxConfigEntry
*)aMenuListBox
.FirstSelected()->GetUserData();
3061 SvxConfigEntry::SvxConfigEntry(
3062 const uno::Sequence
< beans::PropertyValue
>& rProperties
,
3063 const uno::Reference
< container::XNameAccess
>& rCommandToLabelMap
)
3067 bStrEdited( FALSE
),
3068 bIsUserDefined( FALSE
),
3070 bIsParentData( FALSE
),
3075 sal_uInt16
nType( css::ui::ItemType::DEFAULT
);
3078 for ( sal_Int32 i
= 0; i
< rProperties
.getLength(); i
++ )
3080 if ( rProperties
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_COMMANDURL
))
3082 rProperties
[i
].Value
>>= aCommand
;
3084 else if ( rProperties
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_HELPURL
))
3086 rProperties
[i
].Value
>>= aHelpURL_
;
3088 else if ( rProperties
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_LABEL
))
3090 rProperties
[i
].Value
>>= aLabel
;
3092 else if ( rProperties
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_TYPE
))
3094 rProperties
[i
].Value
>>= nType
;
3098 if ( nType
== css::ui::ItemType::DEFAULT
)
3103 a
= rCommandToLabelMap
->getByName( aCommand
);
3104 bIsUserDefined
= FALSE
;
3106 catch ( container::NoSuchElementException
& )
3108 bIsUserDefined
= TRUE
;
3111 // If custom label not set retrieve it from the command to info service
3112 if ( aLabel
.equals( OUString() ) )
3114 uno::Sequence
< beans::PropertyValue
> aPropSeq
;
3115 if ( a
>>= aPropSeq
)
3117 for ( sal_Int32 i
= 0; i
< aPropSeq
.getLength(); i
++ )
3119 if ( aPropSeq
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_LABEL
) )
3121 aPropSeq
[i
].Value
>>= aLabel
;
3131 SvxConfigEntry::GetHelpText()
3133 if ( aHelpText
.getLength() == 0 )
3135 OUString helpid
= OUString::createFromAscii( "helpid:" );
3136 if ( aHelpURL
.indexOf( helpid
) != -1 )
3138 aHelpURL
= aHelpURL
.copy( helpid
.getLength() );
3141 Help
* pHelp
= Application::GetHelp();
3142 if ( aHelpURL
.toInt32() != 0 )
3144 aHelpText
= pHelp
->GetHelpText( aHelpURL
.toInt32(), NULL
);
3147 if ( aHelpText
.getLength() == 0 && aCommand
.getLength() != 0 )
3149 aHelpText
= pHelp
->GetHelpText( aCommand
, NULL
);
3156 uno::Sequence
< beans::PropertyValue
>
3157 SvxConfigEntry::GetProperties(
3158 const uno::Reference
< container::XNameAccess
>& rCommandToLabelMap
)
3160 if ( IsSeparator() )
3162 uno::Sequence
< beans::PropertyValue
> aPropSeq( 1 );
3164 aPropSeq
[0].Name
= OUString(
3165 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_TYPE
) );
3166 aPropSeq
[0].Value
<<= css::ui::ItemType::SEPARATOR_LINE
;
3171 static const OUString
aDescriptorCommandURL (
3172 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_COMMANDURL
) );
3174 static const OUString
aDescriptorType(
3175 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_TYPE
) );
3177 static const OUString
aDescriptorLabel(
3178 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_LABEL
) );
3180 static const OUString
aDescriptorHelpURL(
3181 RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_HELPURL
) );
3183 uno::Sequence
< beans::PropertyValue
> aPropSeq( 4 );
3185 aPropSeq
[0].Name
= aDescriptorCommandURL
;
3186 aPropSeq
[0].Value
<<= rtl::OUString( GetCommand() );
3188 aPropSeq
[1].Name
= aDescriptorType
;
3189 aPropSeq
[1].Value
<<= css::ui::ItemType::DEFAULT
;
3191 // If the name has not been changed and the name is the same as
3192 // in the default command to label map then the label can be stored
3193 // as an empty string.
3194 // It will be initialised again later using the command to label map.
3195 aPropSeq
[2].Name
= aDescriptorLabel
;
3196 if ( HasChangedName() == FALSE
&& GetCommand().getLength() )
3198 BOOL isDefaultName
= FALSE
;
3201 uno::Any
a( rCommandToLabelMap
->getByName( GetCommand() ) );
3202 uno::Sequence
< beans::PropertyValue
> tmpPropSeq
;
3203 if ( a
>>= tmpPropSeq
)
3205 for ( sal_Int32 i
= 0; i
< tmpPropSeq
.getLength(); i
++ )
3207 if ( tmpPropSeq
[i
].Name
.equals( aDescriptorLabel
) )
3210 tmpPropSeq
[i
].Value
>>= tmpLabel
;
3212 if ( tmpLabel
.equals( GetName() ) )
3214 isDefaultName
= TRUE
;
3222 catch ( container::NoSuchElementException
& )
3224 // isDefaultName is left as FALSE
3227 if ( isDefaultName
)
3229 aPropSeq
[2].Value
<<= rtl::OUString();
3233 aPropSeq
[2].Value
<<= rtl::OUString( GetName() );
3238 aPropSeq
[2].Value
<<= rtl::OUString( GetName() );
3241 aPropSeq
[3].Name
= aDescriptorHelpURL
;
3242 aPropSeq
[3].Value
<<= rtl::OUString( GetHelpURL() );
3248 SvxMenuConfigEntry::SvxMenuConfigEntry(
3249 const uno::Sequence< beans::PropertyValue >& rProperties,
3250 const uno::Reference< container::XNameAccess >& rCommandToLabelMap )
3252 SvxConfigEntry( rProperties, rCommandToLabelMap )
3254 uno::Reference< container::XIndexAccess > aChildren;
3256 for ( sal_Int32 i = 0; i < rProperties.getLength(); i++ )
3258 if ( rProperties[i].Name.equalsAscii( ITEM_DESCRIPTOR_CONTAINER ))
3260 rProperties[i].Value >>= aChildren;
3264 if ( aChildren.is() )
3267 SetEntries( new SvxEntries() );
3269 uno::Sequence< beans::PropertyValue > aProps;
3270 for ( sal_Int32 i = 0; i < aChildren->getCount(); i++ )
3272 if ( aChildren->getByIndex( i ) >>= aProps )
3274 SvxConfigEntry* pEntry =
3275 new SvxMenuConfigEntry( aProps, rCommandToLabelMap );
3276 GetEntries()->push_back( pEntry );
3283 SvxConfigEntry::SvxConfigEntry( const OUString
& rDisplayName
,
3284 const OUString
& rCommandURL
, bool bPopup
, bool bParentData
)
3286 , aLabel(rDisplayName
)
3287 , aCommand(rCommandURL
)
3289 , bStrEdited( FALSE
)
3290 , bIsUserDefined( FALSE
)
3292 , bIsParentData( bParentData
)
3293 , bIsVisible( TRUE
)
3299 pEntries
= new SvxEntries();
3303 SvxConfigEntry::~SvxConfigEntry()
3305 if ( pEntries
!= NULL
)
3307 SvxEntries::const_iterator iter
= pEntries
->begin();
3309 for ( ; iter
!= pEntries
->end(); iter
++ )
3317 bool SvxConfigEntry::IsMovable()
3319 if ( IsPopup() && !IsMain() )
3326 bool SvxConfigEntry::IsDeletable()
3328 if ( IsMain() && !IsUserDefined() )
3335 bool SvxConfigEntry::IsRenamable()
3337 if ( IsMain() && !IsUserDefined() )
3344 SvxToolbarConfigPage::SvxToolbarConfigPage(
3345 Window
*pParent
, const SfxItemSet
& rSet
)
3347 SvxConfigPage( pParent
, rSet
)
3349 SetHelpId( HID_SVX_CONFIG_TOOLBAR
);
3351 aContentsListBox
= new SvxToolbarEntriesListBox(this, SVX_RES(BOX_ENTRIES
));
3353 PositionContentsListBox();
3354 aContentsListBox
->SetZOrder( &aAddCommandsButton
, WINDOW_ZORDER_BEFOR
);
3356 aContentsListBox
->SetHelpId( HID_SVX_CONFIG_TOOLBAR_CONTENTS
);
3357 aNewTopLevelButton
.SetHelpId( HID_SVX_NEW_TOOLBAR
);
3358 aModifyTopLevelButton
.SetHelpId( HID_SVX_MODIFY_TOOLBAR
);
3359 aAddCommandsButton
.SetHelpId( HID_SVX_NEW_TOOLBAR_ITEM
);
3360 aModifyCommandButton
.SetHelpId( HID_SVX_MODIFY_TOOLBAR_ITEM
);
3361 aSaveInListBox
.SetHelpId( HID_SVX_SAVE_IN
);
3363 aTopLevelSeparator
.SetText(
3364 SVX_RES ( RID_SVXSTR_PRODUCTNAME_TOOLBARS
) );
3366 aTopLevelLabel
.SetText( SVX_RES( RID_SVXSTR_TOOLBAR
) );
3367 aModifyTopLevelButton
.SetText( SVX_RES( RID_SVXSTR_TOOLBAR
) );
3368 aContentsSeparator
.SetText( SVX_RES( RID_SVXSTR_TOOLBAR_CONTENT
) );
3369 aContentsLabel
.SetText( SVX_RES( RID_SVXSTR_COMMANDS
) );
3371 aTopLevelListBox
.SetSelectHdl(
3372 LINK( this, SvxToolbarConfigPage
, SelectToolbar
) );
3373 aContentsListBox
->SetSelectHdl(
3374 LINK( this, SvxToolbarConfigPage
, SelectToolbarEntry
) );
3376 aNewTopLevelButton
.SetClickHdl (
3377 LINK( this, SvxToolbarConfigPage
, NewToolbarHdl
) );
3379 aAddCommandsButton
.SetClickHdl (
3380 LINK( this, SvxToolbarConfigPage
, AddCommandsHdl
) );
3382 aMoveUpButton
.SetClickHdl ( LINK( this, SvxToolbarConfigPage
, MoveHdl
) );
3383 aMoveDownButton
.SetClickHdl ( LINK( this, SvxToolbarConfigPage
, MoveHdl
) );
3384 // Always enable Up and Down buttons
3385 // added for issue i53677 by shizhoubo
3386 aMoveDownButton
.Enable( TRUE
);
3387 aMoveUpButton
.Enable( TRUE
);
3389 PopupMenu
* pMenu
= new PopupMenu( SVX_RES( MODIFY_TOOLBAR
) );
3390 pMenu
->SetMenuFlags(
3391 pMenu
->GetMenuFlags() | MENU_FLAG_ALWAYSSHOWDISABLEDENTRIES
);
3393 aModifyTopLevelButton
.SetPopupMenu( pMenu
);
3394 aModifyTopLevelButton
.SetSelectHdl(
3395 LINK( this, SvxToolbarConfigPage
, ToolbarSelectHdl
) );
3397 PopupMenu
* pEntry
= new PopupMenu(
3398 SVX_RES( MODIFY_TOOLBAR_CONTENT
) );
3399 pEntry
->SetMenuFlags(
3400 pEntry
->GetMenuFlags() | MENU_FLAG_ALWAYSSHOWDISABLEDENTRIES
);
3402 aModifyCommandButton
.SetPopupMenu( pEntry
);
3403 aModifyCommandButton
.SetSelectHdl(
3404 LINK( this, SvxToolbarConfigPage
, EntrySelectHdl
) );
3406 // default toolbar to select is standardbar unless a different one
3407 // has been passed in
3408 m_aURLToSelect
= OUString::createFromAscii( ITEM_TOOLBAR_URL
);
3409 m_aURLToSelect
+= OUString::createFromAscii( "standardbar" );
3411 const SfxPoolItem
* pItem
=
3412 rSet
.GetItem( rSet
.GetPool()->GetWhich( SID_CONFIG
) );
3416 OUString text
= ((const SfxStringItem
*)pItem
)->GetValue();
3417 if (text
.indexOf(OUString::createFromAscii(ITEM_TOOLBAR_URL
)) == 0)
3419 m_aURLToSelect
= text
.copy( 0 );
3423 long nTxtW
= aTopLevelLabel
.GetCtrlTextWidth( aTopLevelLabel
.GetText() );
3424 long nCtrlW
= aTopLevelLabel
.GetSizePixel().Width();
3425 if ( nTxtW
>= nCtrlW
)
3427 long nDelta
= Max( (long)10, nTxtW
- nCtrlW
);
3428 Size aNewSz
= aTopLevelLabel
.GetSizePixel();
3429 aNewSz
.Width() += nDelta
;
3430 aTopLevelLabel
.SetSizePixel( aNewSz
);
3431 aNewSz
= aTopLevelListBox
.GetSizePixel();
3432 aNewSz
.Width() -= nDelta
;
3433 Point aNewPt
= aTopLevelListBox
.GetPosPixel();
3434 aNewPt
.X() += nDelta
;
3435 aTopLevelListBox
.SetPosSizePixel( aNewPt
, aNewSz
);
3439 SvxToolbarConfigPage::~SvxToolbarConfigPage()
3441 for ( USHORT i
= 0 ; i
< aSaveInListBox
.GetEntryCount(); i
++ )
3443 ToolbarSaveInData
* pData
=
3444 (ToolbarSaveInData
*) aSaveInListBox
.GetEntryData( i
);
3449 if ( pSelectorDlg
!= NULL
)
3451 delete pSelectorDlg
;
3455 delete aContentsListBox
;
3458 void SvxToolbarConfigPage::DeleteSelectedTopLevel()
3460 USHORT nSelectionPos
= aTopLevelListBox
.GetSelectEntryPos();
3461 ToolbarSaveInData
* pSaveInData
= (ToolbarSaveInData
*) GetSaveInData();
3462 pSaveInData
->RemoveToolbar( GetTopLevelSelection() );
3464 if ( aTopLevelListBox
.GetEntryCount() > 1 )
3466 // select next entry after the one being deleted
3467 // selection position is indexed from 0 so need to
3468 // subtract one from the entry count
3469 if ( nSelectionPos
!= aTopLevelListBox
.GetEntryCount() - 1 )
3471 aTopLevelListBox
.SelectEntryPos( nSelectionPos
+ 1, TRUE
);
3475 aTopLevelListBox
.SelectEntryPos( nSelectionPos
- 1, TRUE
);
3477 aTopLevelListBox
.GetSelectHdl().Call( this );
3479 // and now remove the entry
3480 aTopLevelListBox
.RemoveEntry( nSelectionPos
);
3484 ReloadTopLevelListBox();
3488 bool SvxToolbarConfigPage::DeleteSelectedContent()
3490 SvLBoxEntry
*pActEntry
= aContentsListBox
->FirstSelected();
3492 if ( pActEntry
!= NULL
)
3494 // get currently selected entry
3495 SvxConfigEntry
* pEntry
=
3496 (SvxConfigEntry
*) pActEntry
->GetUserData();
3498 SvxConfigEntry
* pToolbar
= GetTopLevelSelection();
3500 // remove entry from the list for this toolbar
3501 RemoveEntry( pToolbar
->GetEntries(), pEntry
);
3503 // remove toolbar entry from UI
3504 aContentsListBox
->GetModel()->Remove( pActEntry
);
3506 // delete data for toolbar entry
3509 (( ToolbarSaveInData
* ) GetSaveInData())->ApplyToolbar( pToolbar
);
3510 UpdateButtonStates();
3512 // if this is the last entry in the toolbar and it is a user
3513 // defined toolbar pop up a dialog asking the user if they
3514 // want to delete the toolbar
3515 if ( aContentsListBox
->GetEntryCount() == 0 &&
3516 GetTopLevelSelection()->IsDeletable() )
3518 QueryBox
qbox( this,
3519 SVX_RES( QBX_CONFIRM_DELETE_TOOLBAR
) );
3521 if ( qbox
.Execute() == RET_YES
)
3523 DeleteSelectedTopLevel();
3533 IMPL_LINK( SvxToolbarConfigPage
, MoveHdl
, Button
*, pButton
)
3535 MoveEntry( pButton
== &aMoveUpButton
);
3539 void SvxToolbarConfigPage::MoveEntry( bool bMoveUp
)
3541 SvxConfigPage::MoveEntry( bMoveUp
);
3543 // Apply change to currently selected toolbar
3544 SvxConfigEntry
* pToolbar
= GetTopLevelSelection();
3546 ((ToolbarSaveInData
*)GetSaveInData())->ApplyToolbar( pToolbar
);
3549 DBG_ERRORFILE( "SvxToolbarConfigPage::MoveEntry(): no entry" );
3550 UpdateButtonStates();
3554 IMPL_LINK( SvxToolbarConfigPage
, ToolbarSelectHdl
, MenuButton
*, pButton
)
3556 USHORT nSelectionPos
= aTopLevelListBox
.GetSelectEntryPos();
3558 SvxConfigEntry
* pToolbar
=
3559 (SvxConfigEntry
*)aTopLevelListBox
.GetEntryData( nSelectionPos
);
3561 ToolbarSaveInData
* pSaveInData
= (ToolbarSaveInData
*) GetSaveInData();
3563 switch( pButton
->GetCurItemId() )
3567 DeleteSelectedTopLevel();
3568 UpdateButtonStates();
3573 String
aNewName( stripHotKey( pToolbar
->GetName() ) );
3574 String aDesc
= SVX_RESSSTR( RID_SVXSTR_LABEL_NEW_NAME
);
3576 SvxNameDialog
* pNameDialog
= new SvxNameDialog( this, aNewName
, aDesc
);
3577 pNameDialog
->SetHelpId( HID_SVX_CONFIG_RENAME_TOOLBAR
);
3578 pNameDialog
->SetText( SVX_RESSTR( RID_SVXSTR_RENAME_TOOLBAR
) );
3580 bool ret
= pNameDialog
->Execute();
3582 if ( ret
== RET_OK
)
3584 pNameDialog
->GetName(aNewName
);
3586 pToolbar
->SetName( aNewName
);
3587 pSaveInData
->ApplyToolbar( pToolbar
);
3589 // have to use remove and insert to change the name
3590 aTopLevelListBox
.RemoveEntry( nSelectionPos
);
3592 aTopLevelListBox
.InsertEntry( aNewName
, nSelectionPos
);
3593 aTopLevelListBox
.SetEntryData( nSelectionPos
, pToolbar
);
3594 aTopLevelListBox
.SelectEntryPos( nSelectionPos
);
3601 case ID_DEFAULT_STYLE
:
3603 QueryBox
qbox( this,
3604 SVX_RES( QBX_CONFIRM_RESTORE_DEFAULT
) );
3606 if ( qbox
.Execute() == RET_YES
)
3608 ToolbarSaveInData
* pSaveInData_
=
3609 (ToolbarSaveInData
*) GetSaveInData();
3611 pSaveInData_
->RestoreToolbar( pToolbar
);
3613 aTopLevelListBox
.GetSelectHdl().Call( this );
3620 pToolbar
->SetStyle( 0 );
3621 pSaveInData
->SetSystemStyle( m_xFrame
, pToolbar
->GetCommand(), 0 );
3623 aTopLevelListBox
.GetSelectHdl().Call( this );
3629 pToolbar
->SetStyle( 1 );
3630 pSaveInData
->SetSystemStyle( m_xFrame
, pToolbar
->GetCommand(), 1 );
3632 aTopLevelListBox
.GetSelectHdl().Call( this );
3636 case ID_ICONS_AND_TEXT
:
3638 pToolbar
->SetStyle( 2 );
3639 pSaveInData
->SetSystemStyle( m_xFrame
, pToolbar
->GetCommand(), 2 );
3641 aTopLevelListBox
.GetSelectHdl().Call( this );
3649 IMPL_LINK( SvxToolbarConfigPage
, EntrySelectHdl
, MenuButton
*, pButton
)
3651 bool bNeedsApply
= FALSE
;
3653 // get currently selected toolbar
3654 SvxConfigEntry
* pToolbar
= GetTopLevelSelection();
3656 switch( pButton
->GetCurItemId() )
3660 SvLBoxEntry
* pActEntry
= aContentsListBox
->GetCurEntry();
3661 SvxConfigEntry
* pEntry
=
3662 (SvxConfigEntry
*) pActEntry
->GetUserData();
3664 String
aNewName( stripHotKey( pEntry
->GetName() ) );
3665 String aDesc
= SVX_RESSSTR( RID_SVXSTR_LABEL_NEW_NAME
);
3667 SvxNameDialog
* pNameDialog
= new SvxNameDialog( this, aNewName
, aDesc
);
3668 pNameDialog
->SetHelpId( HID_SVX_CONFIG_RENAME_TOOLBAR_ITEM
);
3669 pNameDialog
->SetText( SVX_RESSTR( RID_SVXSTR_RENAME_TOOLBAR
) );
3671 bool ret
= pNameDialog
->Execute();
3673 if ( ret
== RET_OK
) {
3674 pNameDialog
->GetName(aNewName
);
3676 pEntry
->SetName( aNewName
);
3677 aContentsListBox
->SetEntryText( pActEntry
, aNewName
);
3685 case ID_DEFAULT_COMMAND
:
3687 SvLBoxEntry
* pActEntry
= aContentsListBox
->GetCurEntry();
3688 SvxConfigEntry
* pEntry
=
3689 (SvxConfigEntry
*) pActEntry
->GetUserData();
3691 USHORT nSelectionPos
= 0;
3693 // find position of entry within the list
3694 for ( USHORT i
= 0; i
< aContentsListBox
->GetEntryCount(); i
++ )
3696 if ( aContentsListBox
->GetEntry( 0, i
) == pActEntry
)
3703 ToolbarSaveInData
* pSaveInData
=
3704 (ToolbarSaveInData
*) GetSaveInData();
3706 OUString aSystemName
=
3707 pSaveInData
->GetSystemUIName( pEntry
->GetCommand() );
3709 if ( !pEntry
->GetName().equals( aSystemName
) )
3711 pEntry
->SetName( aSystemName
);
3712 aContentsListBox
->SetEntryText(
3713 pActEntry
, stripHotKey( aSystemName
) );
3717 uno::Sequence
< OUString
> aURLSeq( 1 );
3718 aURLSeq
[ 0 ] = pEntry
->GetCommand();
3722 GetSaveInData()->GetImageManager()->removeImages(
3723 GetImageType(), aURLSeq
);
3725 // reset backup in entry
3726 pEntry
->SetBackupGraphic(
3727 uno::Reference
< graphic::XGraphic
>() );
3729 GetSaveInData()->PersistChanges(
3730 GetSaveInData()->GetImageManager() );
3732 aContentsListBox
->GetModel()->Remove( pActEntry
);
3734 SvLBoxEntry
* pNewLBEntry
=
3735 InsertEntryIntoUI( pEntry
, nSelectionPos
);
3737 aContentsListBox
->SetCheckButtonState( pNewLBEntry
,
3738 pEntry
->IsVisible() ?
3739 SV_BUTTON_CHECKED
: SV_BUTTON_UNCHECKED
);
3741 aContentsListBox
->Select( pNewLBEntry
);
3742 aContentsListBox
->MakeVisible( pNewLBEntry
);
3746 catch ( uno::Exception
& )
3748 OSL_TRACE("Error restoring image");
3752 case ID_BEGIN_GROUP
:
3754 SvxConfigEntry
* pNewEntryData
= new SvxConfigEntry
;
3755 pNewEntryData
->SetUserDefined( TRUE
);
3757 SvLBoxEntry
* pNewLBEntry
= InsertEntry( pNewEntryData
);
3759 aContentsListBox
->SetCheckButtonState(
3760 pNewLBEntry
, SV_BUTTON_TRISTATE
);
3767 DeleteSelectedContent();
3778 case ID_ICON_AND_TEXT
:
3782 case ID_CHANGE_SYMBOL
:
3784 SvLBoxEntry
* pActEntry
= aContentsListBox
->GetCurEntry();
3785 SvxConfigEntry
* pEntry
=
3786 (SvxConfigEntry
*) pActEntry
->GetUserData();
3788 USHORT nSelectionPos
= 0;
3790 // find position of entry within the list
3791 for ( USHORT i
= 0; i
< aContentsListBox
->GetEntryCount(); i
++ )
3793 if ( aContentsListBox
->GetEntry( 0, i
) == pActEntry
)
3800 SvxIconSelectorDialog
* pIconDialog
=
3801 new SvxIconSelectorDialog( 0,
3802 GetSaveInData()->GetImageManager(),
3803 GetSaveInData()->GetParentImageManager() );
3805 bool ret
= pIconDialog
->Execute();
3807 if ( ret
== RET_OK
)
3809 uno::Reference
< graphic::XGraphic
> newgraphic
=
3810 pIconDialog
->GetSelectedIcon();
3812 if ( newgraphic
.is() )
3814 uno::Sequence
< uno::Reference
< graphic::XGraphic
> >
3817 uno::Sequence
< OUString
> aURLSeq( 1 );
3818 aURLSeq
[ 0 ] = pEntry
->GetCommand();
3820 if ( !pEntry
->GetBackupGraphic().is() )
3822 uno::Reference
< graphic::XGraphic
> backup
;
3823 backup
= GetGraphic(
3824 GetSaveInData()->GetImageManager(), aURLSeq
[ 0 ] );
3828 pEntry
->SetBackupGraphic( backup
);
3832 aGraphicSeq
[ 0 ] = newgraphic
;
3835 GetSaveInData()->GetImageManager()->replaceImages(
3836 GetImageType(), aURLSeq
, aGraphicSeq
);
3838 Image
aImage( newgraphic
);
3840 aContentsListBox
->GetModel()->Remove( pActEntry
);
3841 SvLBoxEntry
* pNewLBEntry
=
3842 InsertEntryIntoUI( pEntry
, nSelectionPos
);
3844 aContentsListBox
->SetCheckButtonState( pNewLBEntry
,
3845 pEntry
->IsVisible() ?
3846 SV_BUTTON_CHECKED
: SV_BUTTON_UNCHECKED
);
3848 aContentsListBox
->Select( pNewLBEntry
);
3849 aContentsListBox
->MakeVisible( pNewLBEntry
);
3851 GetSaveInData()->PersistChanges(
3852 GetSaveInData()->GetImageManager() );
3854 catch ( uno::Exception
& )
3856 OSL_TRACE("Error replacing image");
3865 case ID_RESET_SYMBOL
:
3867 SvLBoxEntry
* pActEntry
= aContentsListBox
->GetCurEntry();
3868 SvxConfigEntry
* pEntry
=
3869 (SvxConfigEntry
*) pActEntry
->GetUserData();
3871 USHORT nSelectionPos
= 0;
3873 // find position of entry within the list
3874 for ( USHORT i
= 0; i
< aContentsListBox
->GetEntryCount(); i
++ )
3876 if ( aContentsListBox
->GetEntry( 0, i
) == pActEntry
)
3883 uno::Reference
< graphic::XGraphic
> backup
=
3884 pEntry
->GetBackupGraphic();
3886 uno::Sequence
< uno::Reference
< graphic::XGraphic
> >
3888 aGraphicSeq
[ 0 ] = backup
;
3890 uno::Sequence
< OUString
> aURLSeq( 1 );
3891 aURLSeq
[ 0 ] = pEntry
->GetCommand();
3895 GetSaveInData()->GetImageManager()->replaceImages(
3896 GetImageType(), aURLSeq
, aGraphicSeq
);
3898 Image
aImage( backup
);
3899 aContentsListBox
->GetModel()->Remove( pActEntry
);
3901 SvLBoxEntry
* pNewLBEntry
=
3902 InsertEntryIntoUI( pEntry
, nSelectionPos
);
3904 aContentsListBox
->SetCheckButtonState( pNewLBEntry
,
3905 pEntry
->IsVisible() ?
3906 SV_BUTTON_CHECKED
: SV_BUTTON_UNCHECKED
);
3908 aContentsListBox
->Select( pNewLBEntry
);
3909 aContentsListBox
->MakeVisible( pNewLBEntry
);
3911 // reset backup in entry
3912 pEntry
->SetBackupGraphic(
3913 uno::Reference
< graphic::XGraphic
>() );
3915 GetSaveInData()->PersistChanges(
3916 GetSaveInData()->GetImageManager() );
3918 catch ( uno::Exception
& )
3920 OSL_TRACE("Error resetting image");
3926 if ( bNeedsApply
== TRUE
)
3928 (( ToolbarSaveInData
* ) GetSaveInData())->ApplyToolbar( pToolbar
);
3929 UpdateButtonStates();
3935 void SvxToolbarConfigPage::Init()
3937 // ensure that the UI is cleared before populating it
3938 aTopLevelListBox
.Clear();
3939 aContentsListBox
->Clear();
3941 ReloadTopLevelListBox();
3944 if ( m_aURLToSelect
.getLength() != 0 )
3946 for ( USHORT i
= 0 ; i
< aTopLevelListBox
.GetEntryCount(); i
++ )
3948 SvxConfigEntry
* pData
=
3949 (SvxConfigEntry
*) aTopLevelListBox
.GetEntryData( i
);
3951 if ( pData
->GetCommand().equals( m_aURLToSelect
) )
3958 // in future select the default toolbar: Standard
3959 m_aURLToSelect
= OUString::createFromAscii( ITEM_TOOLBAR_URL
);
3960 m_aURLToSelect
+= OUString::createFromAscii( "standardbar" );
3963 aTopLevelListBox
.SelectEntryPos(nPos
, TRUE
);
3964 aTopLevelListBox
.GetSelectHdl().Call(this);
3967 SaveInData
* SvxToolbarConfigPage::CreateSaveInData(
3968 const uno::Reference
< css::ui::XUIConfigurationManager
>& xCfgMgr
,
3969 const uno::Reference
< css::ui::XUIConfigurationManager
>& xParentCfgMgr
,
3970 const OUString
& aModuleId
,
3973 return static_cast< SaveInData
* >(
3974 new ToolbarSaveInData( xCfgMgr
, xParentCfgMgr
, aModuleId
, bDocConfig
));
3977 ToolbarSaveInData::ToolbarSaveInData(
3978 const uno::Reference
< css::ui::XUIConfigurationManager
>& xCfgMgr
,
3979 const uno::Reference
< css::ui::XUIConfigurationManager
>& xParentCfgMgr
,
3980 const OUString
& aModuleId
,
3983 SaveInData ( xCfgMgr
, xParentCfgMgr
, aModuleId
, docConfig
),
3984 pRootEntry ( NULL
),
3985 m_aDescriptorContainer ( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_CONTAINER
) )
3988 // Initialize the m_xPersistentWindowState variable which is used
3989 // to get the default properties of system toolbars such as name
3990 uno::Reference
< container::XNameAccess
> xPWSS(
3991 m_xServiceManager
->createInstance(
3992 OUString( RTL_CONSTASCII_USTRINGPARAM(
3993 "com.sun.star.ui.WindowStateConfiguration" ) ) ),
3997 xPWSS
->getByName( aModuleId
) >>= m_xPersistentWindowState
;
4000 ToolbarSaveInData::~ToolbarSaveInData()
4005 void ToolbarSaveInData::SetSystemStyle(
4006 uno::Reference
< frame::XFrame
> xFrame
,
4007 const OUString
& rResourceURL
,
4010 // change the style using the API
4011 SetSystemStyle( rResourceURL
, nStyle
);
4013 // this code is a temporary hack as the UI is not updating after
4014 // changing the toolbar style via the API
4015 uno::Reference
< css::frame::XLayoutManager
> xLayoutManager
;
4016 Window
*window
= NULL
;
4018 uno::Reference
< beans::XPropertySet
> xPropSet( xFrame
, uno::UNO_QUERY
);
4019 if ( xPropSet
.is() )
4021 uno::Any a
= xPropSet
->getPropertyValue(
4022 OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ) ) );
4023 a
>>= xLayoutManager
;
4026 if ( xLayoutManager
.is() )
4028 uno::Reference
< css::ui::XUIElement
> xUIElement
=
4029 xLayoutManager
->getElement( rResourceURL
);
4031 // check reference before we call getRealInterface. The layout manager
4032 // can only provide references for elements that have been created
4033 // before. It's possible that the current element is not available.
4034 uno::Reference
< com::sun::star::awt::XWindow
> xWindow
;
4035 if ( xUIElement
.is() )
4036 xWindow
= uno::Reference
< com::sun::star::awt::XWindow
>(
4037 xUIElement
->getRealInterface(), uno::UNO_QUERY
);
4039 window
= VCLUnoHelper::GetWindow( xWindow
);
4042 if ( window
!= NULL
&& window
->GetType() == WINDOW_TOOLBOX
)
4044 ToolBox
* toolbox
= (ToolBox
*)window
;
4048 toolbox
->SetButtonType( BUTTON_SYMBOL
);
4050 else if ( nStyle
== 1 )
4052 toolbox
->SetButtonType( BUTTON_TEXT
);
4056 toolbox
->SetButtonType( BUTTON_SYMBOLTEXT
);
4061 void ToolbarSaveInData::SetSystemStyle(
4062 const OUString
& rResourceURL
,
4065 if ( rResourceURL
.indexOf( OUString::createFromAscii( "private" ) ) == 0 &&
4066 m_xPersistentWindowState
.is() &&
4067 m_xPersistentWindowState
->hasByName( rResourceURL
) )
4071 uno::Sequence
< beans::PropertyValue
> aProps
;
4073 uno::Any
a( m_xPersistentWindowState
->getByName( rResourceURL
) );
4077 for ( sal_Int32 i
= 0; i
< aProps
.getLength(); i
++ )
4079 if ( aProps
[ i
].Name
.equalsAscii( ITEM_DESCRIPTOR_STYLE
) )
4081 aProps
[ i
].Value
= uno::makeAny( nStyle
);
4087 uno::Reference
< container::XNameReplace
>
4088 xNameReplace( m_xPersistentWindowState
, uno::UNO_QUERY
);
4090 xNameReplace
->replaceByName( rResourceURL
, uno::makeAny( aProps
) );
4092 catch ( uno::Exception
& )
4094 // do nothing, a default value is returned
4095 OSL_TRACE("Exception setting toolbar style");
4100 sal_Int32
ToolbarSaveInData::GetSystemStyle( const OUString
& rResourceURL
)
4102 sal_Int32 result
= 0;
4104 if ( rResourceURL
.indexOf( OUString::createFromAscii( "private" ) ) == 0 &&
4105 m_xPersistentWindowState
.is() &&
4106 m_xPersistentWindowState
->hasByName( rResourceURL
) )
4110 uno::Sequence
< beans::PropertyValue
> aProps
;
4111 uno::Any
a( m_xPersistentWindowState
->getByName( rResourceURL
) );
4115 for ( sal_Int32 i
= 0; i
< aProps
.getLength(); i
++ )
4117 if ( aProps
[ i
].Name
.equalsAscii( ITEM_DESCRIPTOR_STYLE
) )
4119 aProps
[i
].Value
>>= result
;
4125 catch ( uno::Exception
& )
4127 // do nothing, a default value is returned
4134 OUString
ToolbarSaveInData::GetSystemUIName( const OUString
& rResourceURL
)
4138 if ( rResourceURL
.indexOf( OUString::createFromAscii( "private" ) ) == 0 &&
4139 m_xPersistentWindowState
.is() &&
4140 m_xPersistentWindowState
->hasByName( rResourceURL
) )
4144 uno::Sequence
< beans::PropertyValue
> aProps
;
4145 uno::Any
a( m_xPersistentWindowState
->getByName( rResourceURL
) );
4149 for ( sal_Int32 i
= 0; i
< aProps
.getLength(); i
++ )
4151 if ( aProps
[ i
].Name
.equalsAscii( ITEM_DESCRIPTOR_UINAME
) )
4153 aProps
[ i
].Value
>>= result
;
4158 catch ( uno::Exception
& )
4160 // do nothing, an empty UIName will be returned
4164 if ( rResourceURL
.indexOf( OUString::createFromAscii( ".uno" ) ) == 0 &&
4165 m_xCommandToLabelMap
.is() &&
4166 m_xCommandToLabelMap
->hasByName( rResourceURL
) )
4171 a
= m_xCommandToLabelMap
->getByName( rResourceURL
);
4173 uno::Sequence
< beans::PropertyValue
> aPropSeq
;
4174 if ( a
>>= aPropSeq
)
4176 for ( sal_Int32 i
= 0; i
< aPropSeq
.getLength(); i
++ )
4178 if ( aPropSeq
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_LABEL
) )
4180 aPropSeq
[i
].Value
>>= result
;
4185 catch ( uno::Exception
& )
4187 // not a system command name
4194 bool EntrySort( SvxConfigEntry
* a
, SvxConfigEntry
* b
)
4196 return a
->GetName().compareTo( b
->GetName() ) < 0;
4199 SvxEntries
* ToolbarSaveInData::GetEntries()
4201 typedef ::std::hash_map
< ::rtl::OUString
,
4203 ::rtl::OUStringHash
,
4204 ::std::equal_to
< ::rtl::OUString
> > ToolbarInfo
;
4206 ToolbarInfo aToolbarInfo
;
4208 if ( pRootEntry
== NULL
)
4211 pRootEntry
= new SvxConfigEntry(
4212 String::CreateFromAscii("MainToolbars"), String(), TRUE
);
4214 uno::Sequence
< uno::Sequence
< beans::PropertyValue
> > info
=
4215 GetConfigManager()->getUIElementsInfo(
4216 css::ui::UIElementType::TOOLBAR
);
4218 for ( sal_Int32 i
= 0; i
< info
.getLength(); i
++ )
4220 uno::Sequence
< beans::PropertyValue
> props
= info
[ i
];
4223 OUString systemname
;
4226 for ( sal_Int32 j
= 0; j
< props
.getLength(); j
++ )
4228 if ( props
[ j
].Name
.equalsAscii( ITEM_DESCRIPTOR_RESOURCEURL
) )
4230 props
[ j
].Value
>>= url
;
4231 systemname
= url
.copy( url
.lastIndexOf( '/' ) + 1 );
4233 else if ( props
[ j
].Name
.equalsAscii( ITEM_DESCRIPTOR_UINAME
) )
4235 props
[ j
].Value
>>= uiname
;
4241 uno::Reference
< container::XIndexAccess
> xToolbarSettings
=
4242 GetConfigManager()->getSettings( url
, sal_False
);
4244 if ( uiname
.getLength() == 0 )
4246 // try to get the name from m_xPersistentWindowState
4247 uiname
= GetSystemUIName( url
);
4249 if ( uiname
.getLength() == 0 )
4251 uiname
= systemname
;
4255 SvxConfigEntry
* pEntry
= new SvxConfigEntry(
4256 uiname
, url
, TRUE
);
4258 pEntry
->SetMain( TRUE
);
4259 pEntry
->SetStyle( GetSystemStyle( url
) );
4262 // insert into hash_map to filter duplicates from the parent
4263 aToolbarInfo
.insert( ToolbarInfo::value_type( systemname
, true ));
4265 OUString custom
= OUString::createFromAscii(CUSTOM_TOOLBAR_STR
);
4266 if ( systemname
.indexOf( custom
) == 0 )
4268 pEntry
->SetUserDefined( TRUE
);
4272 pEntry
->SetUserDefined( FALSE
);
4275 pRootEntry
->GetEntries()->push_back( pEntry
);
4277 LoadToolbar( xToolbarSettings
, pEntry
);
4279 catch ( container::NoSuchElementException
& )
4281 // TODO, handle resourceURL with no settings
4285 uno::Reference
< css::ui::XUIConfigurationManager
> xParentCfgMgr
= GetParentConfigManager();
4286 if ( xParentCfgMgr
.is() )
4288 // Retrieve also the parent toolbars to make it possible
4289 // to configure module toolbars and save them into the document
4291 uno::Sequence
< uno::Sequence
< beans::PropertyValue
> > info_
=
4292 xParentCfgMgr
->getUIElementsInfo(
4293 css::ui::UIElementType::TOOLBAR
);
4295 for ( sal_Int32 i
= 0; i
< info_
.getLength(); i
++ )
4297 uno::Sequence
< beans::PropertyValue
> props
= info_
[ i
];
4300 OUString systemname
;
4303 for ( sal_Int32 j
= 0; j
< props
.getLength(); j
++ )
4305 if ( props
[ j
].Name
.equalsAscii( ITEM_DESCRIPTOR_RESOURCEURL
) )
4307 props
[ j
].Value
>>= url
;
4308 systemname
= url
.copy( url
.lastIndexOf( '/' ) + 1 );
4310 else if ( props
[ j
].Name
.equalsAscii( ITEM_DESCRIPTOR_UINAME
) )
4312 props
[ j
].Value
>>= uiname
;
4316 // custom toolbars of the parent are not visible in the document layer
4317 OUString custom
= OUString::createFromAscii(CUSTOM_TOOLBAR_STR
);
4318 if ( systemname
.indexOf( custom
) == 0 )
4321 // check if toolbar is already in the document layer
4322 ToolbarInfo::const_iterator pIter
= aToolbarInfo
.find( systemname
);
4323 if ( pIter
== aToolbarInfo
.end() )
4325 aToolbarInfo
.insert( ToolbarInfo::value_type( systemname
, true ));
4329 uno::Reference
< container::XIndexAccess
> xToolbarSettings
=
4330 xParentCfgMgr
->getSettings( url
, sal_False
);
4332 if ( uiname
.getLength() == 0 )
4334 // try to get the name from m_xPersistentWindowState
4335 uiname
= GetSystemUIName( url
);
4337 if ( uiname
.getLength() == 0 )
4339 uiname
= systemname
;
4343 SvxConfigEntry
* pEntry
= new SvxConfigEntry(
4344 uiname
, url
, TRUE
, TRUE
);
4346 pEntry
->SetMain( TRUE
);
4347 pEntry
->SetStyle( GetSystemStyle( url
) );
4349 if ( systemname
.indexOf( custom
) == 0 )
4351 pEntry
->SetUserDefined( TRUE
);
4355 pEntry
->SetUserDefined( FALSE
);
4358 pRootEntry
->GetEntries()->push_back( pEntry
);
4360 LoadToolbar( xToolbarSettings
, pEntry
);
4362 catch ( container::NoSuchElementException
& )
4364 // TODO, handle resourceURL with no settings
4370 std::sort( GetEntries()->begin(), GetEntries()->end(), EntrySort
);
4373 return pRootEntry
->GetEntries();
4377 ToolbarSaveInData::SetEntries( SvxEntries
* pNewEntries
)
4379 // delete old menu hierarchy first
4380 if ( pRootEntry
!= NULL
&& pRootEntry
->GetEntries() != NULL
)
4382 delete pRootEntry
->GetEntries();
4385 // now set new menu hierarchy
4386 pRootEntry
->SetEntries( pNewEntries
);
4390 ToolbarSaveInData::HasURL( const OUString
& rURL
)
4392 SvxEntries::const_iterator iter
= GetEntries()->begin();
4393 SvxEntries::const_iterator end
= GetEntries()->end();
4395 while ( iter
!= end
)
4397 SvxConfigEntry
* pEntry
= *iter
;
4399 if ( pEntry
->GetCommand().equals( rURL
) )
4401 if ( pEntry
->IsParentData() )
4412 bool ToolbarSaveInData::HasSettings()
4414 // return true if there is at least one toolbar entry
4415 if ( GetEntries()->size() > 0 )
4422 void ToolbarSaveInData::Reset()
4424 SvxEntries::const_iterator toolbars
= GetEntries()->begin();
4425 SvxEntries::const_iterator end
= GetEntries()->end();
4427 // reset each toolbar by calling removeSettings for it's toolbar URL
4428 for ( ; toolbars
!= end
; toolbars
++ )
4430 SvxConfigEntry
* pToolbar
= *toolbars
;
4434 OUString url
= pToolbar
->GetCommand();
4435 GetConfigManager()->removeSettings( url
);
4437 catch ( uno::Exception
& )
4439 // error occured removing the settings
4440 // TODO - add error dialog in future?
4444 // persist changes to toolbar storage
4445 PersistChanges( GetConfigManager() );
4447 // now delete the root SvxConfigEntry the next call to GetEntries()
4448 // causes it to be reinitialised
4452 // reset all icons to default
4455 GetImageManager()->reset();
4456 PersistChanges( GetImageManager() );
4458 catch ( uno::Exception
& )
4460 OSL_TRACE("Error resetting all icons when resetting toolbars");
4464 bool ToolbarSaveInData::Apply()
4466 // toolbar changes are instantly applied
4470 void ToolbarSaveInData::ApplyToolbar(
4471 uno::Reference
< container::XIndexContainer
>& rToolbarBar
,
4472 uno::Reference
< lang::XSingleComponentFactory
>& rFactory
,
4473 SvxConfigEntry
* pToolbarData
)
4475 SvxEntries::const_iterator iter
= pToolbarData
->GetEntries()->begin();
4476 SvxEntries::const_iterator end
= pToolbarData
->GetEntries()->end();
4478 for ( ; iter
!= end
; iter
++ )
4480 SvxConfigEntry
* pEntry
= *iter
;
4482 if ( pEntry
->IsPopup() )
4484 uno::Sequence
< beans::PropertyValue
> aPropValueSeq
=
4485 ConvertToolbarEntry( m_xCommandToLabelMap
, pEntry
);
4487 uno::Reference
< container::XIndexContainer
> xSubMenuBar(
4488 rFactory
->createInstanceWithContext( m_xComponentContext
),
4491 sal_Int32 nIndex
= aPropValueSeq
.getLength();
4492 aPropValueSeq
.realloc( nIndex
+ 1 );
4493 aPropValueSeq
[nIndex
].Name
= m_aDescriptorContainer
;
4494 aPropValueSeq
[nIndex
].Value
<<= xSubMenuBar
;
4495 rToolbarBar
->insertByIndex(
4496 rToolbarBar
->getCount(), uno::makeAny( aPropValueSeq
));
4498 ApplyToolbar( xSubMenuBar
, rFactory
, pEntry
);
4500 else if ( pEntry
->IsSeparator() )
4502 rToolbarBar
->insertByIndex(
4503 rToolbarBar
->getCount(), uno::makeAny( m_aSeparatorSeq
));
4507 uno::Sequence
< beans::PropertyValue
> aPropValueSeq
=
4508 ConvertToolbarEntry( m_xCommandToLabelMap
, pEntry
);
4510 rToolbarBar
->insertByIndex(
4511 rToolbarBar
->getCount(), uno::makeAny( aPropValueSeq
));
4516 void ToolbarSaveInData::ApplyToolbar( SvxConfigEntry
* pToolbar
)
4518 // Apply new toolbar structure to our settings container
4519 uno::Reference
< container::XIndexAccess
> xSettings(
4520 GetConfigManager()->createSettings(), uno::UNO_QUERY
);
4522 uno::Reference
< container::XIndexContainer
> xIndexContainer (
4523 xSettings
, uno::UNO_QUERY
);
4525 uno::Reference
< lang::XSingleComponentFactory
> xFactory (
4526 xSettings
, uno::UNO_QUERY
);
4528 ApplyToolbar( xIndexContainer
, xFactory
, pToolbar
);
4530 uno::Reference
< beans::XPropertySet
> xProps(
4531 xSettings
, uno::UNO_QUERY
);
4533 if ( pToolbar
->IsUserDefined() )
4535 xProps
->setPropertyValue(
4536 OUString::createFromAscii( ITEM_DESCRIPTOR_UINAME
),
4537 uno::makeAny( OUString( pToolbar
->GetName() ) ) );
4542 if ( GetConfigManager()->hasSettings( pToolbar
->GetCommand() ) )
4544 GetConfigManager()->replaceSettings(
4545 pToolbar
->GetCommand(), xSettings
);
4549 GetConfigManager()->insertSettings(
4550 pToolbar
->GetCommand(), xSettings
);
4551 if ( pToolbar
->IsParentData() )
4552 pToolbar
->SetParentData( false );
4555 catch ( container::NoSuchElementException
& )
4557 OSL_TRACE("caught container::NoSuchElementException saving settings");
4559 catch ( com::sun::star::io::IOException
& )
4561 OSL_TRACE("caught IOException saving settings");
4563 catch ( com::sun::star::uno::Exception
& )
4565 OSL_TRACE("caught some other exception saving settings");
4568 PersistChanges( GetConfigManager() );
4571 void ToolbarSaveInData::CreateToolbar( SvxConfigEntry
* pToolbar
)
4573 // show the new toolbar in the UI also
4574 uno::Reference
< container::XIndexAccess
>
4575 xSettings( GetConfigManager()->createSettings(), uno::UNO_QUERY
);
4577 uno::Reference
< container::XIndexContainer
>
4578 xIndexContainer ( xSettings
, uno::UNO_QUERY
);
4580 uno::Reference
< beans::XPropertySet
>
4581 xPropertySet( xSettings
, uno::UNO_QUERY
);
4583 xPropertySet
->setPropertyValue(
4584 OUString::createFromAscii( ITEM_DESCRIPTOR_UINAME
),
4585 uno::makeAny( pToolbar
->GetName() ) );
4589 GetConfigManager()->insertSettings( pToolbar
->GetCommand(), xSettings
);
4591 catch ( container::ElementExistException
& )
4593 OSL_TRACE("caught ElementExistsException saving settings");
4595 catch ( com::sun::star::lang::IllegalArgumentException
& )
4597 OSL_TRACE("caught IOException saving settings");
4599 catch ( com::sun::star::lang::IllegalAccessException
& )
4601 OSL_TRACE("caught IOException saving settings");
4603 catch ( com::sun::star::uno::Exception
& )
4605 OSL_TRACE("caught some other exception saving settings");
4608 GetEntries()->push_back( pToolbar
);
4610 PersistChanges( GetConfigManager() );
4613 void ToolbarSaveInData::RemoveToolbar( SvxConfigEntry
* pToolbar
)
4617 OUString url
= pToolbar
->GetCommand();
4618 GetConfigManager()->removeSettings( url
);
4619 RemoveEntry( GetEntries(), pToolbar
);
4622 PersistChanges( GetConfigManager() );
4624 // remove the persistent window state data
4625 css::uno::Reference
< css::container::XNameContainer
> xNameContainer(
4626 m_xPersistentWindowState
, css::uno::UNO_QUERY_THROW
);
4628 xNameContainer
->removeByName( url
);
4630 catch ( uno::Exception
& )
4632 // error occured removing the settings
4636 void ToolbarSaveInData::RestoreToolbar( SvxConfigEntry
* pToolbar
)
4638 OUString url
= pToolbar
->GetCommand();
4640 // Restore of toolbar is done by removing it from
4641 // it's configuration manager and then getting it again
4642 bool bParentToolbar
= pToolbar
->IsParentData();
4644 // Cannot restore parent toolbar
4645 if ( bParentToolbar
)
4650 GetConfigManager()->removeSettings( url
);
4651 pToolbar
->GetEntries()->clear();
4652 PersistChanges( GetConfigManager() );
4654 catch ( uno::Exception
& )
4656 // if an error occurs removing the settings then just return
4660 // Now reload the toolbar settings
4663 uno::Reference
< container::XIndexAccess
> xToolbarSettings
;
4664 if ( IsDocConfig() )
4666 xToolbarSettings
= GetParentConfigManager()->getSettings( url
, sal_False
);
4667 pToolbar
->SetParentData( true );
4670 xToolbarSettings
= GetConfigManager()->getSettings( url
, sal_False
);
4672 LoadToolbar( xToolbarSettings
, pToolbar
);
4674 // After reloading, ensure that the icon is reset of each entry
4676 SvxEntries::const_iterator iter
= pToolbar
->GetEntries()->begin();
4677 uno::Sequence
< OUString
> aURLSeq( 1 );
4678 for ( ; iter
!= pToolbar
->GetEntries()->end(); iter
++ )
4680 SvxConfigEntry
* pEntry
= *iter
;
4681 aURLSeq
[ 0 ] = pEntry
->GetCommand();
4685 GetImageManager()->removeImages( GetImageType(), aURLSeq
);
4687 catch ( uno::Exception
& )
4689 OSL_TRACE("Error restoring icon when resetting toolbar");
4692 PersistChanges( GetImageManager() );
4694 catch ( container::NoSuchElementException
& )
4696 // cannot find the resource URL after removing it
4697 // so no entry will appear in the toolbar list
4701 void ToolbarSaveInData::ReloadToolbar( const OUString
& rResourceURL
)
4703 SvxEntries::const_iterator iter
= GetEntries()->begin();
4704 SvxConfigEntry
* pToolbar
= NULL
;
4706 for ( ; iter
!= GetEntries()->end(); iter
++ )
4708 SvxConfigEntry
* pEntry
= *iter
;
4710 if ( pEntry
->GetCommand().equals( rResourceURL
) )
4717 if ( pToolbar
!= NULL
)
4719 delete pToolbar
->GetEntries();
4723 uno::Reference
< container::XIndexAccess
> xToolbarSettings
;
4725 if ( pToolbar
->IsParentData() )
4727 xToolbarSettings
= GetParentConfigManager()->getSettings(
4728 pToolbar
->GetCommand(), sal_False
);
4732 xToolbarSettings
= GetConfigManager()->getSettings(
4733 pToolbar
->GetCommand(), sal_False
);
4736 LoadToolbar( xToolbarSettings
, pToolbar
);
4738 catch ( container::NoSuchElementException
& )
4740 // toolbar not found for some reason
4741 // it will not appear in the toolbar list
4746 bool ToolbarSaveInData::LoadToolbar(
4747 const uno::Reference
< container::XIndexAccess
>& xToolbarSettings
,
4748 SvxConfigEntry
* pParentData
)
4750 SvxEntries
* pEntries
= pParentData
->GetEntries();
4752 for ( sal_Int32 nIndex
= 0; nIndex
< xToolbarSettings
->getCount(); nIndex
++ )
4754 uno::Reference
< container::XIndexAccess
> xSubMenu
;
4755 OUString aCommandURL
;
4758 bool bIsUserDefined
= TRUE
;
4759 sal_Bool bIsVisible
;
4762 sal_uInt16
nType( css::ui::ItemType::DEFAULT
);
4764 bool bItem
= GetToolbarItemData( xToolbarSettings
, nIndex
, aCommandURL
,
4765 aHelpURL
, aLabel
, nType
, bIsVisible
, nStyle
, xSubMenu
);
4769 if ( nType
== css::ui::ItemType::DEFAULT
)
4774 a
= m_xCommandToLabelMap
->getByName( aCommandURL
);
4775 bIsUserDefined
= FALSE
;
4777 catch ( container::NoSuchElementException
& )
4779 bIsUserDefined
= TRUE
;
4782 // If custom label not set retrieve it from the command
4784 if ( aLabel
.equals( OUString() ) )
4786 uno::Sequence
< beans::PropertyValue
> aPropSeq
;
4787 if ( a
>>= aPropSeq
)
4789 for ( sal_Int32 i
= 0; i
< aPropSeq
.getLength(); i
++ )
4791 if ( aPropSeq
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_LABEL
) )
4793 aPropSeq
[i
].Value
>>= aLabel
;
4800 if ( xSubMenu
.is() )
4802 SvxConfigEntry
* pEntry
= new SvxConfigEntry(
4803 aLabel
, aCommandURL
, TRUE
);
4805 pEntry
->SetUserDefined( bIsUserDefined
);
4806 pEntry
->SetHelpURL( aHelpURL
);
4807 pEntry
->SetVisible( bIsVisible
);
4809 pEntries
->push_back( pEntry
);
4811 LoadToolbar( xSubMenu
, pEntry
);
4815 SvxConfigEntry
* pEntry
= new SvxConfigEntry(
4816 aLabel
, aCommandURL
, FALSE
);
4817 pEntry
->SetUserDefined( bIsUserDefined
);
4818 pEntry
->SetHelpURL( aHelpURL
);
4819 pEntry
->SetVisible( bIsVisible
);
4820 pEntry
->SetStyle( nStyle
);
4821 pEntries
->push_back( pEntry
);
4826 SvxConfigEntry
* pEntry
= new SvxConfigEntry
;
4827 pEntry
->SetUserDefined( bIsUserDefined
);
4828 pEntries
->push_back( pEntry
);
4836 IMPL_LINK( SvxToolbarConfigPage
, SelectToolbarEntry
, Control
*, pBox
)
4839 UpdateButtonStates();
4843 void SvxToolbarConfigPage::UpdateButtonStates()
4845 PopupMenu
* pPopup
= aModifyCommandButton
.GetPopupMenu();
4846 pPopup
->EnableItem( ID_RENAME
, FALSE
);
4847 pPopup
->EnableItem( ID_DELETE
, FALSE
);
4848 pPopup
->EnableItem( ID_BEGIN_GROUP
, FALSE
);
4849 pPopup
->EnableItem( ID_DEFAULT_COMMAND
, FALSE
);
4850 pPopup
->EnableItem( ID_ICON_ONLY
, FALSE
);
4851 pPopup
->EnableItem( ID_ICON_AND_TEXT
, FALSE
);
4852 pPopup
->EnableItem( ID_TEXT_ONLY
, FALSE
);
4853 pPopup
->EnableItem( ID_CHANGE_SYMBOL
, FALSE
);
4854 pPopup
->EnableItem( ID_RESET_SYMBOL
, FALSE
);
4856 aDescriptionField
.Clear();
4858 SvLBoxEntry
* selection
= aContentsListBox
->GetCurEntry();
4859 if ( aContentsListBox
->GetEntryCount() == 0 || selection
== NULL
)
4864 SvxConfigEntry
* pEntryData
= (SvxConfigEntry
*) selection
->GetUserData();
4865 if ( pEntryData
->IsSeparator() )
4866 pPopup
->EnableItem( ID_DELETE
, TRUE
);
4869 pPopup
->EnableItem( ID_BEGIN_GROUP
, TRUE
);
4870 pPopup
->EnableItem( ID_DELETE
, TRUE
);
4871 pPopup
->EnableItem( ID_RENAME
, TRUE
);
4872 pPopup
->EnableItem( ID_ICON_ONLY
, TRUE
);
4873 pPopup
->EnableItem( ID_ICON_AND_TEXT
, TRUE
);
4874 pPopup
->EnableItem( ID_TEXT_ONLY
, TRUE
);
4875 pPopup
->EnableItem( ID_CHANGE_SYMBOL
, TRUE
);
4877 if ( !pEntryData
->IsUserDefined() )
4878 pPopup
->EnableItem( ID_DEFAULT_COMMAND
, TRUE
);
4880 if ( pEntryData
->IsIconModified() )
4881 pPopup
->EnableItem( ID_RESET_SYMBOL
, TRUE
);
4883 aDescriptionField
.SetNewText( pEntryData
->GetHelpText() );
4887 short SvxToolbarConfigPage::QueryReset()
4890 String( SVX_RES( RID_SVXSTR_CONFIRM_TOOLBAR_RESET
) );
4892 String saveInName
= aSaveInListBox
.GetEntry(
4893 aSaveInListBox
.GetSelectEntryPos() );
4895 OUString label
= replaceSaveInName( msg
, saveInName
);
4897 QueryBox
qbox( this, WB_YES_NO
, label
);
4899 return qbox
.Execute();
4902 IMPL_LINK( SvxToolbarConfigPage
, SelectToolbar
, ListBox
*, pBox
)
4906 aContentsListBox
->Clear();
4908 SvxConfigEntry
* pToolbar
= GetTopLevelSelection();
4909 if ( pToolbar
== NULL
)
4911 aModifyTopLevelButton
.Enable( FALSE
);
4912 aModifyCommandButton
.Enable( FALSE
);
4913 aAddCommandsButton
.Enable( FALSE
);
4918 aModifyTopLevelButton
.Enable( TRUE
);
4919 aModifyCommandButton
.Enable( TRUE
);
4920 aAddCommandsButton
.Enable( TRUE
);
4922 PopupMenu
* pPopup
= aModifyTopLevelButton
.GetPopupMenu();
4924 pPopup
->EnableItem( ID_DELETE
, pToolbar
->IsDeletable() );
4925 pPopup
->EnableItem( ID_RENAME
, pToolbar
->IsRenamable() );
4926 pPopup
->EnableItem( ID_DEFAULT_STYLE
, !pToolbar
->IsRenamable() );
4928 switch( pToolbar
->GetStyle() )
4932 pPopup
->CheckItem( ID_ICONS_ONLY
);
4937 pPopup
->CheckItem( ID_TEXT_ONLY
);
4942 pPopup
->CheckItem( ID_ICONS_AND_TEXT
);
4947 SvxEntries
* pEntries
= pToolbar
->GetEntries();
4948 SvxEntries::const_iterator iter
= pEntries
->begin();
4950 for ( ; iter
!= pEntries
->end(); iter
++ )
4952 SvxConfigEntry
* pEntry
= *iter
;
4954 SvLBoxEntry
* pNewLBEntry
= InsertEntryIntoUI( pEntry
);
4956 if (pEntry
->IsBinding())
4958 aContentsListBox
->SetCheckButtonState( pNewLBEntry
,
4959 pEntry
->IsVisible() ? SV_BUTTON_CHECKED
: SV_BUTTON_UNCHECKED
);
4963 aContentsListBox
->SetCheckButtonState(
4964 pNewLBEntry
, SV_BUTTON_TRISTATE
);
4968 UpdateButtonStates();
4973 IMPL_LINK( SvxToolbarConfigPage
, NewToolbarHdl
, Button
*, pButton
)
4978 String( SVX_RES( RID_SVXSTR_NEW_TOOLBAR
) );
4981 generateCustomName( prefix
, GetSaveInData()->GetEntries() );
4984 generateCustomURL( GetSaveInData()->GetEntries() );
4986 SvxNewToolbarDialog
* pNameDialog
= new SvxNewToolbarDialog( 0, aNewName
);
4989 for ( USHORT i
= 0 ; i
< aSaveInListBox
.GetEntryCount(); i
++ )
4992 (SaveInData
*) aSaveInListBox
.GetEntryData( i
);
4994 nInsertPos
= pNameDialog
->aSaveInListBox
.InsertEntry(
4995 aSaveInListBox
.GetEntry( i
) );
4997 pNameDialog
->aSaveInListBox
.SetEntryData( nInsertPos
, pData
);
5000 pNameDialog
->aSaveInListBox
.SelectEntryPos(
5001 aSaveInListBox
.GetSelectEntryPos(), TRUE
);
5003 bool ret
= pNameDialog
->Execute();
5004 if ( ret
== RET_OK
)
5006 pNameDialog
->GetName( aNewName
);
5008 nInsertPos
= pNameDialog
->aSaveInListBox
.GetSelectEntryPos();
5010 ToolbarSaveInData
* pData
= (ToolbarSaveInData
*)
5011 pNameDialog
->aSaveInListBox
.GetEntryData( nInsertPos
);
5013 if ( GetSaveInData() != pData
)
5015 aSaveInListBox
.SelectEntryPos( nInsertPos
, TRUE
);
5016 aSaveInListBox
.GetSelectHdl().Call(this);
5019 SvxConfigEntry
* pToolbar
=
5020 new SvxConfigEntry( aNewName
, aNewURL
, TRUE
);
5022 pToolbar
->SetUserDefined( TRUE
);
5023 pToolbar
->SetMain( TRUE
);
5025 pData
->CreateToolbar( pToolbar
);
5027 nInsertPos
= aTopLevelListBox
.InsertEntry( pToolbar
->GetName() );
5028 aTopLevelListBox
.SetEntryData( nInsertPos
, pToolbar
);
5029 aTopLevelListBox
.SelectEntryPos( nInsertPos
, TRUE
);
5030 aTopLevelListBox
.GetSelectHdl().Call(this);
5032 pData
->SetModified( TRUE
);
5040 IMPL_LINK( SvxToolbarConfigPage
, AddCommandsHdl
, Button
*, pButton
)
5044 if ( pSelectorDlg
== NULL
)
5046 // Create Script Selector which shows slot commands
5047 pSelectorDlg
= new SvxScriptSelectorDialog( this, TRUE
, m_xFrame
);
5049 // Position the Script Selector over the Add button so it is
5050 // beside the menu contents list and does not obscure it
5051 pSelectorDlg
->SetPosPixel( aAddCommandsButton
.GetPosPixel() );
5053 pSelectorDlg
->SetAddHdl(
5054 LINK( this, SvxToolbarConfigPage
, AddFunctionHdl
) );
5057 pSelectorDlg
->SetImageProvider(
5058 static_cast< ImageProvider
* >( GetSaveInData() ) );
5060 pSelectorDlg
->Show();
5064 IMPL_LINK( SvxToolbarConfigPage
, AddFunctionHdl
,
5065 SvxScriptSelectorDialog
*, pDialog
)
5074 SvLBoxEntry
* SvxToolbarConfigPage::AddFunction(
5075 SvLBoxEntry
* pTarget
, bool bFront
, bool bAllowDuplicates
)
5077 SvLBoxEntry
* pNewLBEntry
=
5078 SvxConfigPage::AddFunction( pTarget
, bFront
, bAllowDuplicates
);
5080 SvxConfigEntry
* pEntry
= (SvxConfigEntry
*) pNewLBEntry
->GetUserData();
5082 if ( pEntry
->IsBinding() )
5084 pEntry
->SetVisible( TRUE
);
5085 aContentsListBox
->SetCheckButtonState(
5086 pNewLBEntry
, SV_BUTTON_CHECKED
);
5090 aContentsListBox
->SetCheckButtonState(
5091 pNewLBEntry
, SV_BUTTON_TRISTATE
);
5094 // get currently selected toolbar and apply change
5095 SvxConfigEntry
* pToolbar
= GetTopLevelSelection();
5097 if ( pToolbar
!= NULL
)
5099 ( ( ToolbarSaveInData
* ) GetSaveInData() )->ApplyToolbar( pToolbar
);
5105 // -----------------------------------------------------------------------
5107 SvxToolbarEntriesListBox::SvxToolbarEntriesListBox(
5108 Window
* pParent
, const ResId
& aResId
)
5110 SvxMenuEntriesListBox( pParent
, aResId
),
5111 pPage( ( SvxToolbarConfigPage
* ) pParent
)
5113 m_pButtonData
= new SvLBoxButtonData( this );
5114 BuildCheckBoxButtonImages( m_pButtonData
);
5115 EnableCheckButton( m_pButtonData
);
5117 m_bHiContrastMode
= GetDisplayBackground().GetColor().IsDark();
5120 // --------------------------------------------------------
5122 SvxToolbarEntriesListBox::~SvxToolbarEntriesListBox()
5124 delete m_pButtonData
;
5127 // --------------------------------------------------------
5129 void SvxToolbarEntriesListBox::BuildCheckBoxButtonImages( SvLBoxButtonData
* pData
)
5131 // Build checkbox images according to the current application
5132 // settings. This is necessary to be able to have correct colors
5133 // in all color modes, like high contrast.
5134 const AllSettings
& rSettings
= Application::GetSettings();
5137 Size
aSize( 26, 20 );
5139 aDev
.SetOutputSizePixel( aSize
);
5141 Image aImage
= GetSizedImage( aDev
, aSize
,
5142 CheckBox::GetCheckImage( rSettings
, BUTTON_DRAW_DEFAULT
));
5144 // Fill button data struct with new images
5145 pData
->aBmps
[SV_BMP_UNCHECKED
] = aImage
;
5146 pData
->aBmps
[SV_BMP_CHECKED
] = GetSizedImage( aDev
, aSize
, CheckBox::GetCheckImage( rSettings
, BUTTON_DRAW_CHECKED
));
5147 pData
->aBmps
[SV_BMP_HICHECKED
] = GetSizedImage( aDev
, aSize
, CheckBox::GetCheckImage( rSettings
, BUTTON_DRAW_CHECKED
| BUTTON_DRAW_PRESSED
));
5148 pData
->aBmps
[SV_BMP_HIUNCHECKED
] = GetSizedImage( aDev
, aSize
, CheckBox::GetCheckImage( rSettings
, BUTTON_DRAW_DEFAULT
| BUTTON_DRAW_PRESSED
));
5149 pData
->aBmps
[SV_BMP_TRISTATE
] = GetSizedImage( aDev
, aSize
, Image() ); // Use tristate bitmaps to have no checkbox for separator entries
5150 pData
->aBmps
[SV_BMP_HITRISTATE
] = GetSizedImage( aDev
, aSize
, Image() );
5153 m_aCheckBoxImageSizePixel
= aImage
.GetSizePixel();
5156 Image
SvxToolbarEntriesListBox::GetSizedImage(
5157 VirtualDevice
& aDev
, const Size
& aNewSize
, const Image
& aImage
)
5159 // Create new checkbox images for treelistbox. They must have a
5160 // decent width to have a clear column for the visibility checkbox.
5162 // Standard transparent color is light magenta as is won't be
5163 // used for other things
5164 Color
aFillColor( COL_LIGHTMAGENTA
);
5166 // Position image at the center of (width-2),(height) rectangle.
5167 // We need 2 pixels to have a bigger border to the next button image
5168 USHORT nPosX
= std::max( (USHORT
) (((( aNewSize
.Width() - 2 ) - aImage
.GetSizePixel().Width() ) / 2 ) - 1), (USHORT
) 0 );
5169 USHORT nPosY
= std::max( (USHORT
) (((( aNewSize
.Height() - 2 ) - aImage
.GetSizePixel().Height() ) / 2 ) + 1), (USHORT
) 0 );
5170 Point
aPos( nPosX
> 0 ? nPosX
: 0, nPosY
> 0 ? nPosY
: 0 );
5171 aDev
.SetFillColor( aFillColor
);
5172 aDev
.SetLineColor( aFillColor
);
5173 aDev
.DrawRect( Rectangle( Point(), aNewSize
));
5174 aDev
.DrawImage( aPos
, aImage
);
5176 // Draw separator line 2 pixels left from the right border
5177 Color aLineColor
= GetDisplayBackground().GetColor().IsDark() ? Color( COL_WHITE
) : Color( COL_BLACK
);
5178 aDev
.SetLineColor( aLineColor
);
5179 aDev
.DrawLine( Point( aNewSize
.Width()-3, 0 ), Point( aNewSize
.Width()-3, aNewSize
.Height()-1 ));
5181 // Create new image that uses the fillcolor as transparent
5182 return Image( aDev
.GetBitmap( Point(), aNewSize
), aFillColor
);
5185 void SvxToolbarEntriesListBox::DataChanged( const DataChangedEvent
& rDCEvt
)
5187 SvTreeListBox::DataChanged( rDCEvt
);
5189 if (( rDCEvt
.GetType() == DATACHANGED_SETTINGS
) &&
5190 ( rDCEvt
.GetFlags() & SETTINGS_STYLE
))
5192 if ( m_bHiContrastMode
!= GetDisplayBackground().GetColor().IsDark() )
5194 // We have to reset all images because we change to/from high contrast mode
5195 m_bHiContrastMode
= GetDisplayBackground().GetColor().IsDark();
5198 BuildCheckBoxButtonImages( m_pButtonData
);
5203 // --------------------------------------------------------
5205 void SvxToolbarEntriesListBox::ChangeVisibility( SvLBoxEntry
* pEntry
)
5207 if ( pEntry
!= NULL
)
5209 SvxConfigEntry
* pEntryData
=
5210 (SvxConfigEntry
*) pEntry
->GetUserData();
5212 if ( pEntryData
->IsBinding() )
5214 pEntryData
->SetVisible( !pEntryData
->IsVisible() );
5216 SvxConfigEntry
* pToolbar
= pPage
->GetTopLevelSelection();
5218 ToolbarSaveInData
* pToolbarSaveInData
= ( ToolbarSaveInData
* )
5219 pPage
->GetSaveInData();
5221 pToolbarSaveInData
->ApplyToolbar( pToolbar
);
5223 SetCheckButtonState( pEntry
, pEntryData
->IsVisible() ?
5224 SV_BUTTON_CHECKED
: SV_BUTTON_UNCHECKED
);
5229 void SvxToolbarEntriesListBox::CheckButtonHdl()
5231 ChangeVisibility( GetHdlEntry() );
5234 void SvxToolbarEntriesListBox::KeyInput( const KeyEvent
& rKeyEvent
)
5236 // space key will change visibility of toolbar items
5237 if ( rKeyEvent
.GetKeyCode() == KEY_SPACE
)
5239 ChangeVisibility( GetCurEntry() );
5243 // pass on to superclass
5244 SvxMenuEntriesListBox::KeyInput( rKeyEvent
);
5248 BOOL
SvxToolbarEntriesListBox::NotifyMoving(
5249 SvLBoxEntry
* pTarget
, SvLBoxEntry
* pSource
,
5250 SvLBoxEntry
*& rpNewParent
, ULONG
& rNewChildPos
)
5252 bool result
= SvxMenuEntriesListBox::NotifyMoving(
5253 pTarget
, pSource
, rpNewParent
, rNewChildPos
);
5255 if ( result
== TRUE
)
5257 // Instant Apply changes to UI
5258 SvxConfigEntry
* pToolbar
= pPage
->GetTopLevelSelection();
5259 if ( pToolbar
!= NULL
)
5261 ToolbarSaveInData
* pSaveInData
=
5262 ( ToolbarSaveInData
*) pPage
->GetSaveInData();
5263 pSaveInData
->ApplyToolbar( pToolbar
);
5270 BOOL
SvxToolbarEntriesListBox::NotifyCopying(
5271 SvLBoxEntry
* pTarget
,
5272 SvLBoxEntry
* pSource
,
5273 SvLBoxEntry
*& rpNewParent
,
5274 ULONG
& rNewChildPos
)
5280 if ( !m_bIsInternalDrag
)
5282 // if the target is NULL then add function to the start of the list
5283 ((SvxToolbarConfigPage
*)pPage
)->AddFunction( pTarget
, pTarget
== NULL
);
5285 // Instant Apply changes to UI
5286 SvxConfigEntry
* pToolbar
= pPage
->GetTopLevelSelection();
5287 if ( pToolbar
!= NULL
)
5289 ToolbarSaveInData
* pSaveInData
=
5290 ( ToolbarSaveInData
*) pPage
->GetSaveInData();
5291 pSaveInData
->ApplyToolbar( pToolbar
);
5294 // AddFunction already adds the listbox entry so return FALSE
5295 // to stop another listbox entry being added
5299 // Copying is only allowed from external controls, not within the listbox
5303 SvxNewToolbarDialog::SvxNewToolbarDialog(
5304 Window
* pWindow
, const String
& rName
)
5306 ModalDialog ( pWindow
, SVX_RES( MD_NEW_TOOLBAR
) ),
5307 aFtDescription ( this, SVX_RES( FT_NAME
) ),
5308 aEdtName ( this, SVX_RES( EDT_STRING
) ),
5309 aSaveInText ( this, SVX_RES( TXT_SAVEIN
) ),
5310 aBtnOK ( this, SVX_RES( BTN_OK
) ),
5311 aBtnCancel ( this, SVX_RES( BTN_CANCEL
) ),
5312 aBtnHelp ( this, SVX_RES( BTN_HELP
) ),
5313 aSaveInListBox ( this, SVX_RES( LB_SAVEIN
) )
5317 aEdtName
.SetText( rName
);
5318 aEdtName
.SetSelection(Selection(SELECTION_MIN
, SELECTION_MAX
));
5319 ModifyHdl(&aEdtName
);
5320 aEdtName
.SetModifyHdl(LINK(this, SvxNewToolbarDialog
, ModifyHdl
));
5323 IMPL_LINK(SvxNewToolbarDialog
, ModifyHdl
, Edit
*, pEdit
)
5327 if(aCheckNameHdl
.IsSet())
5328 aBtnOK
.Enable(aCheckNameHdl
.Call(this) > 0);
5333 /*******************************************************************************
5335 * The SvxIconSelectorDialog class
5337 *******************************************************************************/
5338 SvxIconSelectorDialog::SvxIconSelectorDialog( Window
*pWindow
,
5339 const uno::Reference
< css::ui::XImageManager
>& rXImageManager
,
5340 const uno::Reference
< css::ui::XImageManager
>& rXParentImageManager
)
5342 ModalDialog ( pWindow
, SVX_RES( MD_ICONSELECTOR
) ),
5343 aFtDescription ( this, SVX_RES( FT_SYMBOLS
) ),
5344 aTbSymbol ( this, SVX_RES( TB_SYMBOLS
) ),
5345 aFtNote ( this, SVX_RES( FT_NOTE
) ),
5346 aBtnOK ( this, SVX_RES( BTN_OK
) ),
5347 aBtnCancel ( this, SVX_RES( BTN_CANCEL
) ),
5348 aBtnHelp ( this, SVX_RES( BTN_HELP
) ),
5349 aBtnImport ( this, SVX_RES( BTN_IMPORT
) ),
5350 aBtnDelete ( this, SVX_RES( BTN_DELETE
) ),
5351 aFlSeparator ( this, SVX_RES( FL_SEPARATOR
) ),
5353 m_xImageManager ( rXImageManager
),
5354 m_xParentImageManager( rXParentImageManager
)
5358 typedef ::std::hash_map
< ::rtl::OUString
,
5360 ::rtl::OUStringHash
,
5361 ::std::equal_to
< ::rtl::OUString
> > ImageInfo
;
5363 aTbSymbol
.SetPageScroll( TRUE
);
5365 bool bLargeIcons
= GetImageType() & css::ui::ImageType::SIZE_LARGE
;
5366 m_nExpectedSize
= bLargeIcons
? 26 : 16;
5368 if ( m_nExpectedSize
!= 16 )
5370 aFtNote
.SetText( replaceSixteen( aFtNote
.GetText(), m_nExpectedSize
) );
5373 uno::Reference
< lang::XMultiServiceFactory
> xServiceManager
=
5374 ::comphelper::getProcessServiceFactory();
5376 if ( xServiceManager
.is() )
5378 m_xGraphProvider
= uno::Reference
< graphic::XGraphicProvider
>(
5379 xServiceManager
->createInstance(
5380 ::rtl::OUString::createFromAscii(
5381 "com.sun.star.graphic.GraphicProvider" ) ),
5385 if ( !m_xGraphProvider
.is() )
5387 aBtnImport
.Enable( FALSE
);
5390 uno::Reference
< beans::XPropertySet
> xPropSet(
5391 xServiceManager
->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.util.PathSettings" ) ),
5394 uno::Any aAny
= xPropSet
->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UserConfig" ) ) );
5396 ::rtl::OUString aDirectory
;
5398 aAny
>>= aDirectory
;
5400 sal_Int32 aCount
= aDirectory
.getLength();
5404 sal_Unicode aChar
= aDirectory
[ aCount
-1 ];
5407 aDirectory
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) );
5412 aBtnImport
.Enable( FALSE
);
5415 aDirectory
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "soffice.cfg/import" ) );
5417 uno::Reference
< lang::XSingleServiceFactory
> xStorageFactory(
5418 xServiceManager
->createInstance(
5419 ::rtl::OUString::createFromAscii( "com.sun.star.embed.FileSystemStorageFactory" )),
5422 uno::Sequence
< uno::Any
> aArgs( 2 );
5423 aArgs
[ 0 ] <<= aDirectory
;
5424 aArgs
[ 1 ] <<= com::sun::star::embed::ElementModes::READWRITE
;
5426 uno::Reference
< com::sun::star::embed::XStorage
> xStorage(
5427 xStorageFactory
->createInstanceWithArguments( aArgs
), uno::UNO_QUERY
);
5429 uno::Sequence
< uno::Any
> aProp( 2 );
5430 beans::PropertyValue aPropValue
;
5432 aPropValue
.Name
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UserConfigStorage" ) );
5433 aPropValue
.Value
<<= xStorage
;
5434 aProp
[ 0 ] <<= aPropValue
;
5436 aPropValue
.Name
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenMode" ) );
5437 aPropValue
.Value
<<= com::sun::star::embed::ElementModes::READWRITE
;
5438 aProp
[ 1 ] <<= aPropValue
;
5440 m_xImportedImageManager
= uno::Reference
< com::sun::star::ui::XImageManager
>(
5441 xServiceManager
->createInstanceWithArguments(
5442 ::rtl::OUString::createFromAscii( "com.sun.star.ui.ImageManager" ), aProp
),
5445 ImageInfo mImageInfo
;
5446 uno::Sequence
< OUString
> names
;
5447 if ( m_xImportedImageManager
.is() )
5449 names
= m_xImportedImageManager
->getAllImageNames( GetImageType() );
5450 for ( sal_Int32 n
= 0; n
< names
.getLength(); n
++ )
5451 mImageInfo
.insert( ImageInfo::value_type( names
[n
], false ));
5454 ImageInfo::const_iterator pConstIter
= mImageInfo
.begin();
5455 uno::Sequence
< OUString
> name( 1 );
5456 while ( pConstIter
!= mImageInfo
.end() )
5458 name
[ 0 ] = pConstIter
->first
;
5459 uno::Sequence
< uno::Reference
< graphic::XGraphic
> > graphics
= m_xImportedImageManager
->getImages( GetImageType(), name
);
5460 if ( graphics
.getLength() > 0 )
5462 Image img
= Image( graphics
[ 0 ] );
5463 aTbSymbol
.InsertItem( nId
, img
, pConstIter
->first
);
5465 graphics
[ 0 ]->acquire();
5467 aTbSymbol
.SetItemData(
5468 nId
, static_cast< void * > ( graphics
[ 0 ].get() ) );
5475 ImageInfo aImageInfo
;
5477 if ( m_xParentImageManager
.is() )
5479 names
= m_xParentImageManager
->getAllImageNames( GetImageType() );
5480 for ( sal_Int32 n
= 0; n
< names
.getLength(); n
++ )
5481 aImageInfo
.insert( ImageInfo::value_type( names
[n
], false ));
5484 names
= m_xImageManager
->getAllImageNames( GetImageType() );
5485 for ( sal_Int32 n
= 0; n
< names
.getLength(); n
++ )
5487 ImageInfo::iterator pIter
= aImageInfo
.find( names
[n
] );
5488 if ( pIter
!= aImageInfo
.end() )
5489 pIter
->second
= true;
5491 aImageInfo
.insert( ImageInfo::value_type( names
[n
], true ));
5494 // large growth factor, expecting many entries
5495 pConstIter
= aImageInfo
.begin();
5496 while ( pConstIter
!= aImageInfo
.end() )
5498 name
[ 0 ] = pConstIter
->first
;
5500 uno::Sequence
< uno::Reference
< graphic::XGraphic
> > graphics
;
5503 if ( pConstIter
->second
)
5504 graphics
= m_xImageManager
->getImages( GetImageType(), name
);
5506 graphics
= m_xParentImageManager
->getImages( GetImageType(), name
);
5508 catch ( uno::Exception
& )
5510 // can't get sequence for this name so it will not be
5511 // added to the list
5514 if ( graphics
.getLength() > 0 )
5516 Image img
= Image( graphics
[ 0 ] );
5517 aTbSymbol
.InsertItem( nId
, img
, pConstIter
->first
);
5519 uno::Reference
< graphic::XGraphic
> xGraphic
= graphics
[ 0 ];
5521 if ( xGraphic
.is() )
5522 xGraphic
->acquire();
5524 aTbSymbol
.SetItemData(
5525 nId
, static_cast< void * > ( xGraphic
.get() ) );
5533 aBtnDelete
.Enable( FALSE
);
5534 aTbSymbol
.SetSelectHdl( LINK(this, SvxIconSelectorDialog
, SelectHdl
) );
5535 aBtnImport
.SetClickHdl( LINK(this, SvxIconSelectorDialog
, ImportHdl
) );
5536 aBtnDelete
.SetClickHdl( LINK(this, SvxIconSelectorDialog
, DeleteHdl
) );
5538 m_nNextId
= aTbSymbol
.GetItemCount()+1;
5541 SvxIconSelectorDialog::~SvxIconSelectorDialog()
5543 USHORT nCount
= aTbSymbol
.GetItemCount();
5545 for (USHORT n
= 0; n
< nCount
; n
++ )
5547 USHORT nId
= aTbSymbol
.GetItemId(n
);
5549 uno::XInterface
* xi
= static_cast< uno::XInterface
* >(
5550 aTbSymbol
.GetItemData( nId
) );
5559 uno::Reference
< graphic::XGraphic
> SvxIconSelectorDialog::GetSelectedIcon()
5561 uno::Reference
< graphic::XGraphic
> result
;
5564 for ( USHORT n
= 0; n
< aTbSymbol
.GetItemCount(); n
++ )
5566 nId
= aTbSymbol
.GetItemId( n
);
5567 if ( aTbSymbol
.IsItemChecked( nId
) )
5569 result
= uno::Reference
< graphic::XGraphic
>(
5570 reinterpret_cast< graphic::XGraphic
* >(
5571 aTbSymbol
.GetItemData( nId
) ) );
5578 IMPL_LINK( SvxIconSelectorDialog
, SelectHdl
, ToolBox
*, pToolBox
)
5582 USHORT nCount
= aTbSymbol
.GetItemCount();
5584 for (USHORT n
= 0; n
< nCount
; n
++ )
5586 USHORT nId
= aTbSymbol
.GetItemId( n
);
5588 if ( aTbSymbol
.IsItemChecked( nId
) )
5590 aTbSymbol
.CheckItem( nId
, FALSE
);
5594 USHORT nId
= aTbSymbol
.GetCurItemId();
5595 aTbSymbol
.CheckItem( nId
);
5597 ::rtl::OUString aSelImageText
= aTbSymbol
.GetItemText( nId
);
5598 if ( m_xImportedImageManager
->hasImage( GetImageType(), aSelImageText
) )
5600 aBtnDelete
.Enable( TRUE
);
5604 aBtnDelete
.Enable( FALSE
);
5610 IMPL_LINK( SvxIconSelectorDialog
, ImportHdl
, PushButton
*, pButton
)
5614 sfx2::FileDialogHelper
aImportDialog(
5615 css::ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW
,
5616 SFXWB_GRAPHIC
| SFXWB_MULTISELECTION
);
5618 // disable the link checkbox in the dialog
5619 uno::Reference
< css::ui::dialogs::XFilePickerControlAccess
>
5620 xController( aImportDialog
.GetFilePicker(), uno::UNO_QUERY
);
5621 if ( xController
.is() )
5623 xController
->enableControl(
5624 css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_LINK
,
5628 aImportDialog
.SetCurrentFilter(
5629 String::CreateFromAscii( "PNG - Portable Network Graphic" ) );
5631 if ( ERRCODE_NONE
== aImportDialog
.Execute() )
5633 uno::Sequence
< OUString
> paths
= aImportDialog
.GetMPath();
5634 ImportGraphics ( paths
);
5640 IMPL_LINK( SvxIconSelectorDialog
, DeleteHdl
, PushButton
*, pButton
)
5644 OUString message
= String( SVX_RES( RID_SVXSTR_DELETE_ICON_CONFIRM
) );
5645 bool ret
= WarningBox( this, WinBits(WB_OK_CANCEL
), message
).Execute();
5647 if ( ret
== RET_OK
)
5649 USHORT nCount
= aTbSymbol
.GetItemCount();
5651 for (USHORT n
= 0; n
< nCount
; n
++ )
5653 USHORT nId
= aTbSymbol
.GetItemId( n
);
5655 if ( aTbSymbol
.IsItemChecked( nId
) )
5657 ::rtl::OUString aSelImageText
= aTbSymbol
.GetItemText( nId
);
5658 uno::Sequence
< OUString
> URLs(1);
5659 URLs
[0] = aSelImageText
;
5660 aTbSymbol
.RemoveItem( aTbSymbol
.GetItemPos( nId
) );
5661 m_xImportedImageManager
->removeImages( GetImageType(), URLs
);
5662 uno::Reference
< css::ui::XUIConfigurationPersistence
>
5663 xConfigPersistence( m_xImportedImageManager
, uno::UNO_QUERY
);
5664 if ( xConfigPersistence
.is() && xConfigPersistence
->isModified() )
5666 xConfigPersistence
->store();
5675 bool SvxIconSelectorDialog::ReplaceGraphicItem(
5676 const ::rtl::OUString
& aURL
)
5678 uno::Sequence
< OUString
> URLs(1);
5679 uno::Sequence
< uno::Reference
<graphic::XGraphic
> > aImportGraph( 1 );
5680 uno::Reference
< css::ui::XUIConfigurationPersistence
>
5681 xConfigPer( m_xImportedImageManager
, uno::UNO_QUERY
);
5683 uno::Reference
< graphic::XGraphic
> xGraphic
;
5684 uno::Sequence
< beans::PropertyValue
> aMediaProps( 1 );
5685 aMediaProps
[0].Name
= ::rtl::OUString::createFromAscii("URL");
5686 aMediaProps
[0].Value
<<= aURL
;
5688 com::sun::star::awt::Size aSize
;
5692 xGraphic
= m_xGraphProvider
->queryGraphic( aMediaProps
);
5694 uno::Reference
< beans::XPropertySet
> props
=
5695 m_xGraphProvider
->queryGraphicDescriptor( aMediaProps
);
5696 uno::Any a
= props
->getPropertyValue(
5697 OUString::createFromAscii("SizePixel") );
5699 if (0 == aSize
.Width
|| 0 == aSize
.Height
)
5704 catch ( uno::Exception
& )
5709 bool bResult( false );
5710 USHORT nCount
= aTbSymbol
.GetItemCount();
5711 for (USHORT n
= 0; n
< nCount
; n
++ )
5713 USHORT nId
= aTbSymbol
.GetItemId( n
);
5715 if ( OUString( aTbSymbol
.GetItemText( nId
) ) == aURL
)
5719 // replace/insert image with provided URL
5720 aTbSymbol
.RemoveItem( aTbSymbol
.GetItemPos( nId
) );
5721 aMediaProps
[0].Value
<<= aURL
;
5723 Image
aImage( xGraphic
);
5724 if ( bOK
&& ((aSize
.Width
!= m_nExpectedSize
) || (aSize
.Height
!= m_nExpectedSize
)) )
5726 BitmapEx aBitmap
= aImage
.GetBitmapEx();
5727 BitmapEx aBitmapex
= BitmapEx::AutoScaleBitmap(aBitmap
, m_nExpectedSize
);
5728 aImage
= Image( aBitmapex
);
5730 aTbSymbol
.InsertItem( nId
,aImage
, aURL
, 0, 0 ); //modify
5732 xGraphic
= aImage
.GetXGraphic();
5735 aImportGraph
[ 0 ] = xGraphic
;
5736 m_xImportedImageManager
->replaceImages( GetImageType(), URLs
, aImportGraph
);
5737 xConfigPer
->store();
5742 catch ( ::com::sun::star::uno::Exception
& )
5752 void SvxIconSelectorDialog::ImportGraphics(
5753 const uno::Sequence
< OUString
>& rPaths
)
5755 uno::Sequence
< OUString
> rejected( rPaths
.getLength() );
5756 sal_Int32 rejectedCount
= 0;
5761 uno::Sequence
< OUString
> URLs(1);
5762 uno::Sequence
< uno::Reference
<graphic::XGraphic
> > aImportGraph( 1 );
5763 uno::Sequence
< beans::PropertyValue
> aMediaProps( 1 );
5764 aMediaProps
[0].Name
= ::rtl::OUString::createFromAscii("URL");
5765 uno::Reference
< css::ui::XUIConfigurationPersistence
>
5766 xConfigPer( m_xImportedImageManager
, uno::UNO_QUERY
);
5768 if ( rPaths
.getLength() == 1 )
5770 if ( m_xImportedImageManager
->hasImage( GetImageType(), rPaths
[0] ) )
5772 aIndex
= rPaths
[0].lastIndexOf( '/' );
5773 aIconName
= rPaths
[0].copy( aIndex
+1 );
5774 ret
= SvxIconReplacementDialog( this, aIconName
).ShowDialog();
5777 ReplaceGraphicItem( rPaths
[0] );
5782 if ( ImportGraphic( rPaths
[0] ) == FALSE
)
5784 rejected
[0] = rPaths
[0];
5791 ::rtl::OUString
aSourcePath( rPaths
[0] );
5792 if ( rPaths
[0].lastIndexOf( '/' ) != rPaths
[0].getLength() -1 )
5793 aSourcePath
= rPaths
[0] + ::rtl::OUString::createFromAscii( "/" );
5795 for ( sal_Int32 i
= 1; i
< rPaths
.getLength(); i
++ )
5797 ::rtl::OUString aPath
= aSourcePath
+ rPaths
[i
];
5798 if ( m_xImportedImageManager
->hasImage( GetImageType(), aPath
) )
5800 aIndex
= rPaths
[i
].lastIndexOf( '/' );
5801 aIconName
= rPaths
[i
].copy( aIndex
+1 );
5802 ret
= SvxIconReplacementDialog( this, aIconName
, TRUE
).ShowDialog();
5805 ReplaceGraphicItem( aPath
);
5807 else if ( ret
== 5 )
5809 for ( sal_Int32 k
= i
; k
< rPaths
.getLength(); k
++ )
5811 aPath
= aSourcePath
+ rPaths
[k
];
5812 bool bHasReplaced
= ReplaceGraphicItem( aPath
);
5814 if ( !bHasReplaced
)
5816 bool result
= ImportGraphic( aPath
);
5817 if ( result
== FALSE
)
5819 rejected
[ rejectedCount
] = rPaths
[i
];
5829 bool result
= ImportGraphic( aSourcePath
+ rPaths
[i
] );
5830 if ( result
== FALSE
)
5832 rejected
[ rejectedCount
] = rPaths
[i
];
5839 if ( rejectedCount
!= 0 )
5841 OUString message
=OUString::createFromAscii("");
5842 OUString newLine
= OUString::createFromAscii("\n");
5843 rtl::OUString fPath
= OUString::createFromAscii("");
5844 if (rejectedCount
> 1)
5845 fPath
= rPaths
[0].copy(8) + ::rtl::OUString::createFromAscii( "/" );
5846 for ( sal_Int32 i
= 0; i
< rejectedCount
; i
++ )
5848 message
+= fPath
+ rejected
[i
];
5852 SvxIconChangeDialog
aDialog(this, message
);
5857 bool SvxIconSelectorDialog::ImportGraphic( const OUString
& aURL
)
5859 bool result
= FALSE
;
5861 USHORT nId
= m_nNextId
;
5864 uno::Sequence
< beans::PropertyValue
> aMediaProps( 1 );
5865 aMediaProps
[0].Name
= ::rtl::OUString::createFromAscii("URL");
5867 uno::Reference
< graphic::XGraphic
> xGraphic
;
5868 com::sun::star::awt::Size aSize
;
5870 aMediaProps
[0].Value
<<= aURL
;
5873 uno::Reference
< beans::XPropertySet
> props
=
5874 m_xGraphProvider
->queryGraphicDescriptor( aMediaProps
);
5876 uno::Any a
= props
->getPropertyValue(
5877 OUString::createFromAscii("SizePixel") );
5879 xGraphic
= m_xGraphProvider
->queryGraphic( aMediaProps
);
5880 if ( xGraphic
.is() )
5883 if ( 0 == aSize
.Width
|| 0 == aSize
.Height
)
5886 Image
aImage( xGraphic
);
5888 if ( bOK
&& ((aSize
.Width
!= m_nExpectedSize
) || (aSize
.Height
!= m_nExpectedSize
)) )
5890 BitmapEx aBitmap
= aImage
.GetBitmapEx();
5891 BitmapEx aBitmapex
= BitmapEx::AutoScaleBitmap(aBitmap
, m_nExpectedSize
);
5892 aImage
= Image( aBitmapex
);
5894 if ( bOK
&& !!aImage
)
5896 aTbSymbol
.InsertItem( nId
, aImage
, aURL
, 0, 0 );
5898 xGraphic
= aImage
.GetXGraphic();
5899 xGraphic
->acquire();
5901 aTbSymbol
.SetItemData(
5902 nId
, static_cast< void * > ( xGraphic
.get() ) );
5903 uno::Sequence
< OUString
> aImportURL( 1 );
5904 aImportURL
[ 0 ] = aURL
;
5905 uno::Sequence
< uno::Reference
<graphic::XGraphic
> > aImportGraph( 1 );
5906 aImportGraph
[ 0 ] = xGraphic
;
5907 m_xImportedImageManager
->insertImages( GetImageType(), aImportURL
, aImportGraph
);
5908 uno::Reference
< css::ui::XUIConfigurationPersistence
>
5909 xConfigPersistence( m_xImportedImageManager
, uno::UNO_QUERY
);
5911 if ( xConfigPersistence
.is() && xConfigPersistence
->isModified() )
5913 xConfigPersistence
->store();
5920 OSL_TRACE("could not create Image from XGraphic");
5925 OSL_TRACE("could not get query XGraphic");
5928 catch( uno::Exception
& e
)
5930 OSL_TRACE("Caught exception importing XGraphic: %s", PRTSTR(e
.Message
));
5935 /*******************************************************************************
5937 * The SvxIconReplacementDialog class
5939 *******************************************************************************/
5940 SvxIconReplacementDialog :: SvxIconReplacementDialog(
5941 Window
*pWindow
, const rtl::OUString
& aMessage
, bool /*bYestoAll*/ )
5943 MessBox( pWindow
, WB_DEF_YES
, String( SVX_RES( RID_SVXSTR_REPLACE_ICON_CONFIRM
) ), String( SVX_RES( RID_SVXSTR_REPLACE_ICON_WARNING
) ) )
5946 SetImage( WarningBox::GetStandardImage() );
5947 SetMessText( ReplaceIconName( aMessage
) );
5949 AddButton( BUTTON_YES
, 2, 0 );
5950 AddButton( String( SVX_RES( RID_SVXSTR_YESTOALL
) ), 5, 0 );
5951 AddButton( BUTTON_NO
, 3, 0 );
5952 AddButton( BUTTON_CANCEL
, 4, 0 );
5955 SvxIconReplacementDialog :: SvxIconReplacementDialog(
5956 Window
*pWindow
, const rtl::OUString
& aMessage
)
5958 MessBox( pWindow
, WB_YES_NO_CANCEL
, String( SVX_RES( RID_SVXSTR_REPLACE_ICON_CONFIRM
) ), String( SVX_RES( RID_SVXSTR_REPLACE_ICON_WARNING
) ) )
5960 SetImage( WarningBox::GetStandardImage() );
5961 SetMessText( ReplaceIconName( aMessage
));
5964 rtl::OUString
SvxIconReplacementDialog :: ReplaceIconName( const OUString
& rMessage
)
5967 rtl::OUString message
= String( SVX_RES( RID_SVXSTR_REPLACE_ICON_WARNING
) );
5968 rtl::OUString placeholder
= OUString::createFromAscii( "%ICONNAME" );
5969 sal_Int32 pos
= message
.indexOf( placeholder
);
5972 name
= message
.replaceAt(
5973 pos
, placeholder
.getLength(), rMessage
);
5978 USHORT
SvxIconReplacementDialog :: ShowDialog()
5981 return ( this->GetCurButtonId() );
5983 /*******************************************************************************
5985 * The SvxIconChangeDialog class added for issue83555
5987 *******************************************************************************/
5988 SvxIconChangeDialog::SvxIconChangeDialog(
5989 Window
*pWindow
, const rtl::OUString
& aMessage
)
5991 ModalDialog ( pWindow
, SVX_RES( MD_ICONCHANGE
) ),
5992 aFImageInfo (this, SVX_RES( FI_INFO
) ),
5993 aBtnOK (this, SVX_RES(MD_BTN_OK
)),
5994 aDescriptionLabel (this, SVX_RES(FTCHGE_DESCRIPTION
)),
5995 aLineEditDescription (this, SVX_RES(EDT_ADDR
))
5998 aFImageInfo
.SetImage(InfoBox::GetStandardImage());
5999 aLineEditDescription
.SetControlBackground( GetSettings().GetStyleSettings().GetDialogColor() );
6000 aLineEditDescription
.SetAutoScroll( TRUE
);
6001 aLineEditDescription
.EnableCursor( FALSE
);
6002 aLineEditDescription
.SetText(aMessage
);
6005 BitmapEx
SvxIconSelectorDialog::AutoScaleBitmap(BitmapEx
& aBitmap
, const long aStandardSize
)
6007 Point
aEmptyPoint(0,0);
6008 sal_Int32 imgNewWidth
= 0;
6009 sal_Int32 imgNewHeight
= 0;
6012 BitmapEx aRet
= aBitmap
;
6013 double imgOldWidth
= aRet
.GetSizePixel().Width();
6014 double imgOldHeight
=aRet
.GetSizePixel().Height();
6017 if (imgOldWidth
>= aStandardSize
|| imgOldHeight
>= aStandardSize
)
6019 if (imgOldWidth
>= imgOldHeight
)
6021 imgNewWidth
= aStandardSize
;
6022 imgNewHeight
= sal_Int32(imgOldHeight
/ (imgOldWidth
/ aStandardSize
) + 0.5);
6024 imgposY
= (aStandardSize
- (imgOldHeight
/ (imgOldWidth
/ aStandardSize
) + 0.5)) / 2 + 0.5;
6028 imgNewHeight
= aStandardSize
;
6029 imgNewWidth
= sal_Int32(imgOldWidth
/ (imgOldHeight
/ aStandardSize
) + 0.5);
6031 imgposX
= (aStandardSize
- (imgOldWidth
/ (imgOldHeight
/ aStandardSize
) + 0.5)) / 2 + 0.5;
6034 aScaledSize
= Size( imgNewWidth
, imgNewHeight
);
6035 aRet
.Scale( aScaledSize
, BMP_SCALE_INTERPOLATE
);
6039 imgposX
= (aStandardSize
- imgOldWidth
) / 2 + 0.5;
6040 imgposY
= (aStandardSize
- imgOldHeight
) / 2 + 0.5;
6043 Size aBmpSize
= aRet
.GetSizePixel();
6044 Size
aStdSize( aStandardSize
, aStandardSize
);
6045 Rectangle
aRect(aEmptyPoint
, aStdSize
);
6047 VirtualDevice
aVirDevice( *Application::GetDefaultDevice(), 0, 1 );
6048 aVirDevice
.SetOutputSizePixel( aStdSize
);
6049 aVirDevice
.SetFillColor( COL_TRANSPARENT
);
6050 aVirDevice
.SetLineColor( COL_TRANSPARENT
);
6052 //draw a rect into virDevice
6053 aVirDevice
.DrawRect( aRect
);
6054 Point
aPointPixel( (long)imgposX
, (long)imgposY
);
6055 aVirDevice
.DrawBitmapEx( aPointPixel
, aRet
);
6056 aRet
= aVirDevice
.GetBitmapEx( aEmptyPoint
, aStdSize
);