fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / cui / source / customize / cfg.cxx
blob5566dcea43de04e090af4e08ca022d7d048a3718
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "sal/config.h"
22 #include <cassert>
23 #include <stdlib.h>
24 #include <time.h>
26 #include <vcl/help.hxx>
27 #include <vcl/msgbox.hxx>
28 #include <vcl/decoview.hxx>
29 #include <vcl/toolbox.hxx>
30 #include <vcl/scrbar.hxx>
31 #include <vcl/virdev.hxx>
33 #include <sfx2/app.hxx>
34 #include <sfx2/sfxdlg.hxx>
35 #include <sfx2/viewfrm.hxx>
36 #include <sfx2/viewsh.hxx>
37 #include <sfx2/msg.hxx>
38 #include <sfx2/msgpool.hxx>
39 #include <sfx2/mnumgr.hxx>
40 #include <sfx2/minfitem.hxx>
41 #include <sfx2/objsh.hxx>
42 #include <sfx2/request.hxx>
43 #include <sfx2/filedlghelper.hxx>
44 #include <svl/stritem.hxx>
45 #include <svtools/miscopt.hxx>
46 #include <svtools/svlbitm.hxx>
47 #include "svtools/treelistentry.hxx"
48 #include "svtools/viewdataentry.hxx"
49 #include <tools/diagnose_ex.h>
50 #include <toolkit/unohlp.hxx>
52 #include <algorithm>
53 #include <cuires.hrc>
54 #include "cfg.hrc"
55 #include "helpid.hrc"
57 #include "acccfg.hxx"
58 #include "cfg.hxx"
59 #include "eventdlg.hxx"
60 #include <dialmgr.hxx>
62 #include <comphelper/documentinfo.hxx>
63 #include <comphelper/processfactory.hxx>
64 #include <unotools/configmgr.hxx>
65 #include <com/sun/star/embed/ElementModes.hpp>
66 #include <com/sun/star/embed/FileSystemStorageFactory.hpp>
67 #include <com/sun/star/frame/XFramesSupplier.hpp>
68 #include <com/sun/star/frame/XFrames.hpp>
69 #include <com/sun/star/frame/XLayoutManager.hpp>
70 #include <com/sun/star/frame/FrameSearchFlag.hpp>
71 #include <com/sun/star/frame/ModuleManager.hpp>
72 #include <com/sun/star/frame/XController.hpp>
73 #include <com/sun/star/frame/Desktop.hpp>
74 #include <com/sun/star/frame/UICommandDescription.hpp>
75 #include <com/sun/star/graphic/GraphicProvider.hpp>
76 #include <com/sun/star/ui/ItemType.hpp>
77 #include <com/sun/star/ui/ItemStyle.hpp>
78 #include <com/sun/star/ui/ImageManager.hpp>
79 #include <com/sun/star/ui/ModuleUIConfigurationManagerSupplier.hpp>
80 #include <com/sun/star/ui/XUIConfiguration.hpp>
81 #include <com/sun/star/ui/XUIConfigurationListener.hpp>
82 #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
83 #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
84 #include <com/sun/star/ui/XUIConfigurationStorage.hpp>
85 #include <com/sun/star/ui/XModuleUIConfigurationManager.hpp>
86 #include <com/sun/star/ui/XUIElement.hpp>
87 #include <com/sun/star/ui/UIElementType.hpp>
88 #include <com/sun/star/ui/ImageType.hpp>
89 #include <com/sun/star/ui/WindowStateConfiguration.hpp>
90 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
91 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
92 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
93 #include <com/sun/star/util/PathSettings.hpp>
95 #include "dlgname.hxx"
97 #define PRTSTR(x) OUStringToOString(x, RTL_TEXTENCODING_ASCII_US).pData->buffer
99 #define ENTRY_HEIGHT 16
101 static const char ITEM_DESCRIPTOR_COMMANDURL[] = "CommandURL";
102 static const char ITEM_DESCRIPTOR_CONTAINER[] = "ItemDescriptorContainer";
103 static const char ITEM_DESCRIPTOR_LABEL[] = "Label";
104 static const char ITEM_DESCRIPTOR_TYPE[] = "Type";
105 static const char ITEM_DESCRIPTOR_STYLE[] = "Style";
106 static const char ITEM_DESCRIPTOR_ISVISIBLE[] = "IsVisible";
107 static const char ITEM_DESCRIPTOR_RESOURCEURL[] = "ResourceURL";
108 static const char ITEM_DESCRIPTOR_UINAME[] = "UIName";
110 static const char ITEM_MENUBAR_URL[] = "private:resource/menubar/menubar";
111 static const char ITEM_TOOLBAR_URL[] = "private:resource/toolbar/";
113 static const char CUSTOM_TOOLBAR_STR[] = "custom_toolbar_";
114 static const char CUSTOM_MENU_STR[] = "vnd.openoffice.org:CustomMenu";
116 static const char aSeparatorStr[] = "----------------------------------";
117 static const char aMenuSeparatorStr[] = " | ";
119 #ifdef _MSC_VER
120 #pragma warning (disable:4355)
121 #endif
123 namespace uno = com::sun::star::uno;
124 namespace frame = com::sun::star::frame;
125 namespace lang = com::sun::star::lang;
126 namespace container = com::sun::star::container;
127 namespace beans = com::sun::star::beans;
128 namespace graphic = com::sun::star::graphic;
130 #if OSL_DEBUG_LEVEL > 1
132 void printPropertySet(
133 const OUString& prefix,
134 const uno::Reference< beans::XPropertySet >& xPropSet )
136 uno::Reference< beans::XPropertySetInfo > xPropSetInfo =
137 xPropSet->getPropertySetInfo();
139 uno::Sequence< beans::Property > aPropDetails =
140 xPropSetInfo->getProperties();
142 OSL_TRACE("printPropertySet: %d properties", aPropDetails.getLength());
144 for ( sal_Int32 i = 0; i < aPropDetails.getLength(); ++i )
146 OUString tmp;
147 sal_Int32 ival;
149 uno::Any a = xPropSet->getPropertyValue( aPropDetails[i].Name );
151 if ( a >>= tmp )
153 OSL_TRACE("%s: Got property: %s = %s",
154 PRTSTR(prefix), PRTSTR(aPropDetails[i].Name), PRTSTR(tmp));
156 else if ( ( a >>= ival ) )
158 OSL_TRACE("%s: Got property: %s = %d",
159 PRTSTR(prefix), PRTSTR(aPropDetails[i].Name), PRTSTR(tmp));
161 else
163 OSL_TRACE("%s: Got property: %s of type %s",
164 PRTSTR(prefix), PRTSTR(aPropDetails[i].Name), PRTSTR(a.getValueTypeName()));
169 void printProperties(
170 const OUString& prefix,
171 const uno::Sequence< beans::PropertyValue >& aProp )
173 for ( sal_Int32 i = 0; i < aProp.getLength(); ++i )
175 OUString tmp;
177 aProp[i].Value >>= tmp;
179 OSL_TRACE("%s: Got property: %s = %s",
180 PRTSTR(prefix), PRTSTR(aProp[i].Name), PRTSTR(tmp));
184 void printEntries(SvxEntries* entries)
186 SvxEntries::const_iterator iter = entries->begin();
188 for ( ; iter != entries->end(); ++iter )
190 SvxConfigEntry* entry = *iter;
192 OSL_TRACE("printEntries: %s", PRTSTR(entry->GetName()));
196 #endif
198 OUString
199 stripHotKey( const OUString& str )
201 sal_Int32 index = str.indexOf( '~' );
202 if ( index == -1 )
204 return str;
206 else
208 return str.replaceAt( index, 1, OUString() );
212 OUString replaceSaveInName(
213 const OUString& rMessage,
214 const OUString& rSaveInName )
216 OUString name;
217 OUString placeholder("%SAVE IN SELECTION%" );
219 sal_Int32 pos = rMessage.indexOf( placeholder );
221 if ( pos != -1 )
223 name = rMessage.replaceAt(
224 pos, placeholder.getLength(), rSaveInName );
227 return name;
230 OUString
231 replaceSixteen( const OUString& str, sal_Int32 nReplacement )
233 OUString result( str );
234 OUString sixteen = OUString::valueOf( (sal_Int32)16 );
235 OUString expected = OUString::valueOf( nReplacement );
237 sal_Int32 len = sixteen.getLength();
238 sal_Int32 index = result.indexOf( sixteen );
240 while ( index != -1 )
242 result = result.replaceAt( index, len, expected );
243 index = result.indexOf( sixteen, index );
246 return result;
249 OUString
250 generateCustomName(
251 const OUString& prefix,
252 SvxEntries* entries,
253 sal_Int32 suffix = 1 )
255 // find and replace the %n placeholder in the prefix string
256 OUString name;
257 OUString placeholder("%n" );
259 sal_Int32 pos = prefix.indexOf( placeholder );
261 if ( pos != -1 )
263 name = prefix.replaceAt(
264 pos, placeholder.getLength(), OUString::valueOf( suffix ) );
266 else
268 // no placeholder found so just append the suffix
269 name = prefix + OUString::valueOf( suffix );
272 // now check is there is an already existing entry with this name
273 SvxEntries::const_iterator iter = entries->begin();
275 SvxConfigEntry* pEntry;
276 while ( iter != entries->end() )
278 pEntry = *iter;
280 if ( name.equals( pEntry->GetName() ) )
282 break;
284 ++iter;
287 if ( iter != entries->end() )
289 // name already exists so try the next number up
290 return generateCustomName( prefix, entries, ++suffix );
293 return name;
296 sal_uInt32 generateRandomValue()
298 srand( unsigned( time( NULL ) ));
299 return sal_uInt32( rand() );
302 OUString
303 generateCustomURL(
304 SvxEntries* entries )
306 OUString url = OUString(ITEM_TOOLBAR_URL );
307 url += OUString(CUSTOM_TOOLBAR_STR );
309 // use a random number to minimize possible clash with existing custom toolbars
310 url += OUString::valueOf( sal_Int64( generateRandomValue() ), 16 );
312 // now check is there is an already existing entry with this url
313 SvxEntries::const_iterator iter = entries->begin();
315 SvxConfigEntry* pEntry;
316 while ( iter != entries->end() )
318 pEntry = *iter;
320 if ( url.equals( pEntry->GetCommand() ) )
322 break;
324 ++iter;
327 if ( iter != entries->end() )
329 // url already exists so try the next number up
330 return generateCustomURL( entries );
333 return url;
336 OUString
337 generateCustomMenuURL(
338 SvxEntries* entries,
339 sal_Int32 suffix = 1 )
341 OUString url(CUSTOM_MENU_STR );
342 url += OUString::valueOf( suffix );
344 // now check is there is an already existing entry with this url
345 SvxEntries::const_iterator iter = entries->begin();
347 SvxConfigEntry* pEntry;
348 while ( iter != entries->end() )
350 pEntry = *iter;
352 if ( url.equals( pEntry->GetCommand() ) )
354 break;
356 ++iter;
359 if ( iter != entries->end() )
361 // url already exists so try the next number up
362 return generateCustomMenuURL( entries, ++suffix );
365 return url;
368 static sal_Int16 theImageType =
369 css::ui::ImageType::COLOR_NORMAL |
370 css::ui::ImageType::SIZE_DEFAULT;
372 void InitImageType()
374 theImageType =
375 css::ui::ImageType::COLOR_NORMAL |
376 css::ui::ImageType::SIZE_DEFAULT;
378 if ( SvtMiscOptions().AreCurrentSymbolsLarge() )
380 theImageType |= css::ui::ImageType::SIZE_LARGE;
384 sal_Int16 GetImageType()
386 return theImageType;
389 void RemoveEntry( SvxEntries* pEntries, SvxConfigEntry* pChildEntry )
391 SvxEntries::iterator iter = pEntries->begin();
393 while ( iter != pEntries->end() )
395 if ( pChildEntry == *iter )
397 pEntries->erase( iter );
398 break;
400 ++iter;
404 bool
405 SvxConfigPage::CanConfig( const OUString& aModuleId )
407 OSL_TRACE("SupportsDocumentConfig: %s", PRTSTR(aModuleId));
409 if ( aModuleId == "com.sun.star.script.BasicIDE" || aModuleId == "com.sun.star.frame.Bibliography" )
411 return sal_False;
413 return sal_True;
416 OUString GetModuleName( const OUString& aModuleId )
418 if ( aModuleId.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.text.TextDocument" ) ) ||
419 aModuleId.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.text.GlobalDocument" ) ) )
420 return OUString("Writer");
421 else if ( aModuleId == "com.sun.star.text.WebDocument" )
422 return OUString("Writer/Web");
423 else if ( aModuleId == "com.sun.star.drawing.DrawingDocument" )
424 return OUString("Draw");
425 else if ( aModuleId == "com.sun.star.presentation.PresentationDocument" )
426 return OUString("Impress");
427 else if ( aModuleId == "com.sun.star.sheet.SpreadsheetDocument" )
428 return OUString("Calc");
429 else if ( aModuleId == "com.sun.star.script.BasicIDE" )
430 return OUString("Basic");
431 else if ( aModuleId == "com.sun.star.formula.FormulaProperties" )
432 return OUString("Math");
433 else if ( aModuleId == "com.sun.star.sdb.RelationDesign" )
434 return OUString("Relation Design");
435 else if ( aModuleId == "com.sun.star.sdb.QueryDesign" )
436 return OUString("Query Design");
437 else if ( aModuleId == "com.sun.star.sdb.TableDesign" )
438 return OUString("Table Design");
439 else if ( aModuleId == "com.sun.star.sdb.DataSourceBrowser" )
440 return OUString("Data Source Browser" );
441 else if ( aModuleId == "com.sun.star.sdb.DatabaseDocument" )
442 return OUString("Database" );
444 return OUString();
447 OUString GetUIModuleName( const OUString& aModuleId, const uno::Reference< css::frame::XModuleManager2 >& rModuleManager )
449 assert(rModuleManager.is());
451 OUString aModuleUIName;
455 uno::Any a = rModuleManager->getByName( aModuleId );
456 uno::Sequence< beans::PropertyValue > aSeq;
458 if ( a >>= aSeq )
460 for ( sal_Int32 i = 0; i < aSeq.getLength(); ++i )
462 if ( aSeq[i].Name == "ooSetupFactoryUIName" )
464 aSeq[i].Value >>= aModuleUIName;
465 break;
470 catch ( uno::RuntimeException& )
472 throw;
474 catch ( uno::Exception& )
478 if ( aModuleUIName.isEmpty() )
479 aModuleUIName = GetModuleName( aModuleId );
481 return aModuleUIName;
484 bool GetMenuItemData(
485 const uno::Reference< container::XIndexAccess >& rItemContainer,
486 sal_Int32 nIndex,
487 OUString& rCommandURL,
488 OUString& rLabel,
489 sal_uInt16& rType,
490 uno::Reference< container::XIndexAccess >& rSubMenu )
494 uno::Sequence< beans::PropertyValue > aProp;
495 if ( rItemContainer->getByIndex( nIndex ) >>= aProp )
497 for ( sal_Int32 i = 0; i < aProp.getLength(); ++i )
499 if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_COMMANDURL ))
501 aProp[i].Value >>= rCommandURL;
503 else if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_CONTAINER ))
505 aProp[i].Value >>= rSubMenu;
507 else if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_LABEL ))
509 aProp[i].Value >>= rLabel;
511 else if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_TYPE ))
513 aProp[i].Value >>= rType;
517 return sal_True;
520 catch ( ::com::sun::star::lang::IndexOutOfBoundsException& )
524 return sal_False;
527 bool GetToolbarItemData(
528 const uno::Reference< container::XIndexAccess >& rItemContainer,
529 sal_Int32 nIndex,
530 OUString& rCommandURL,
531 OUString& rLabel,
532 sal_uInt16& rType,
533 sal_Bool& rIsVisible,
534 sal_Int32& rStyle,
535 uno::Reference< container::XIndexAccess >& rSubMenu )
539 uno::Sequence< beans::PropertyValue > aProp;
540 if ( rItemContainer->getByIndex( nIndex ) >>= aProp )
542 for ( sal_Int32 i = 0; i < aProp.getLength(); ++i )
544 if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_COMMANDURL ))
546 aProp[i].Value >>= rCommandURL;
548 if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_STYLE ))
550 aProp[i].Value >>= rStyle;
552 else if (aProp[i].Name.equalsAscii(ITEM_DESCRIPTOR_CONTAINER))
554 aProp[i].Value >>= rSubMenu;
556 else if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_LABEL ))
558 aProp[i].Value >>= rLabel;
560 else if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_TYPE ))
562 aProp[i].Value >>= rType;
564 else if (aProp[i].Name.equalsAscii(ITEM_DESCRIPTOR_ISVISIBLE))
566 aProp[i].Value >>= rIsVisible;
570 return sal_True;
573 catch ( ::com::sun::star::lang::IndexOutOfBoundsException& )
577 return sal_False;
580 uno::Sequence< beans::PropertyValue >
581 ConvertSvxConfigEntry(
582 const uno::Reference< container::XNameAccess >& xCommandToLabelMap,
583 const SvxConfigEntry* pEntry )
585 static const OUString aDescriptorCommandURL (
586 ITEM_DESCRIPTOR_COMMANDURL );
588 static const OUString aDescriptorType(
589 ITEM_DESCRIPTOR_TYPE );
591 static const OUString aDescriptorLabel(
592 ITEM_DESCRIPTOR_LABEL );
594 uno::Sequence< beans::PropertyValue > aPropSeq( 3 );
596 aPropSeq[0].Name = aDescriptorCommandURL;
597 aPropSeq[0].Value <<= OUString( pEntry->GetCommand() );
599 aPropSeq[1].Name = aDescriptorType;
600 aPropSeq[1].Value <<= css::ui::ItemType::DEFAULT;
602 // If the name has not been changed and the name is the same as
603 // in the default command to label map then the label can be stored
604 // as an empty string.
605 // It will be initialised again later using the command to label map.
606 aPropSeq[2].Name = aDescriptorLabel;
607 if ( pEntry->HasChangedName() == sal_False && !pEntry->GetCommand().isEmpty() )
609 sal_Bool isDefaultName = sal_False;
612 uno::Any a( xCommandToLabelMap->getByName( pEntry->GetCommand() ) );
613 uno::Sequence< beans::PropertyValue > tmpPropSeq;
614 if ( a >>= tmpPropSeq )
616 for ( sal_Int32 i = 0; i < tmpPropSeq.getLength(); ++i )
618 if ( tmpPropSeq[i].Name.equals( aDescriptorLabel ) )
620 OUString tmpLabel;
621 tmpPropSeq[i].Value >>= tmpLabel;
623 if ( tmpLabel.equals( pEntry->GetName() ) )
625 isDefaultName = sal_True;
628 break;
633 catch ( container::NoSuchElementException& )
635 // isDefaultName is left as FALSE
638 if ( isDefaultName )
640 aPropSeq[2].Value <<= OUString();
642 else
644 aPropSeq[2].Value <<= OUString( pEntry->GetName() );
647 else
649 aPropSeq[2].Value <<= OUString( pEntry->GetName() );
652 return aPropSeq;
655 uno::Sequence< beans::PropertyValue >
656 ConvertToolbarEntry(
657 const uno::Reference< container::XNameAccess >& xCommandToLabelMap,
658 const SvxConfigEntry* pEntry )
660 static const OUString aDescriptorCommandURL (
661 ITEM_DESCRIPTOR_COMMANDURL );
663 static const OUString aDescriptorType(
664 ITEM_DESCRIPTOR_TYPE );
666 static const OUString aDescriptorLabel(
667 ITEM_DESCRIPTOR_LABEL );
669 static const OUString aIsVisible(
670 ITEM_DESCRIPTOR_ISVISIBLE );
672 uno::Sequence< beans::PropertyValue > aPropSeq( 4 );
674 aPropSeq[0].Name = aDescriptorCommandURL;
675 aPropSeq[0].Value <<= OUString( pEntry->GetCommand() );
677 aPropSeq[1].Name = aDescriptorType;
678 aPropSeq[1].Value <<= css::ui::ItemType::DEFAULT;
680 // If the name has not been changed and the name is the same as
681 // in the default command to label map then the label can be stored
682 // as an empty string.
683 // It will be initialised again later using the command to label map.
684 aPropSeq[2].Name = aDescriptorLabel;
685 if ( pEntry->HasChangedName() == sal_False && !pEntry->GetCommand().isEmpty() )
687 sal_Bool isDefaultName = sal_False;
690 uno::Any a( xCommandToLabelMap->getByName( pEntry->GetCommand() ) );
691 uno::Sequence< beans::PropertyValue > tmpPropSeq;
692 if ( a >>= tmpPropSeq )
694 for ( sal_Int32 i = 0; i < tmpPropSeq.getLength(); ++i )
696 if ( tmpPropSeq[i].Name.equals( aDescriptorLabel ) )
698 OUString tmpLabel;
699 tmpPropSeq[i].Value >>= tmpLabel;
701 if ( tmpLabel.equals( pEntry->GetName() ) )
703 isDefaultName = sal_True;
706 break;
711 catch ( container::NoSuchElementException& )
713 // isDefaultName is left as FALSE
716 if ( isDefaultName )
718 aPropSeq[2].Value <<= OUString();
720 else
722 aPropSeq[2].Value <<= OUString( pEntry->GetName() );
725 else
727 aPropSeq[2].Value <<= OUString( pEntry->GetName() );
730 aPropSeq[3].Name = aIsVisible;
731 aPropSeq[3].Value <<= pEntry->IsVisible();
733 return aPropSeq;
736 SfxTabPage *CreateSvxMenuConfigPage( Window *pParent, const SfxItemSet& rSet )
738 return new SvxMenuConfigPage( pParent, rSet );
741 SfxTabPage *CreateKeyboardConfigPage( Window *pParent, const SfxItemSet& rSet )
743 return new SfxAcceleratorConfigPage( pParent, rSet );
746 SfxTabPage *CreateSvxToolbarConfigPage( Window *pParent, const SfxItemSet& rSet )
748 return new SvxToolbarConfigPage( pParent, rSet );
751 SfxTabPage *CreateSvxEventConfigPage( Window *pParent, const SfxItemSet& rSet )
753 return new SvxEventConfigPage( pParent, rSet, SvxEventConfigPage::EarlyInit() );
756 sal_Bool impl_showKeyConfigTabPage( const css::uno::Reference< css::frame::XFrame >& xFrame )
758 static OUString MODULEID_STARTMODULE ("com.sun.star.frame.StartModule" );
762 css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
763 css::uno::Reference< css::frame::XDesktop2 > xDesktop = css::frame::Desktop::create( xContext );
764 css::uno::Reference< css::frame::XModuleManager2 > xMM = css::frame::ModuleManager::create(xContext);
766 if (xFrame.is())
768 OUString sModuleId = xMM->identify(xFrame);
769 if (
770 ( !sModuleId.isEmpty() ) &&
771 (!sModuleId.equals(MODULEID_STARTMODULE))
773 return sal_True;
776 catch(const css::uno::Exception&)
779 return sal_False;
782 /******************************************************************************
784 * SvxConfigDialog is the configuration dialog which is brought up from the
785 * Tools menu. It includes tabs for customizing menus, toolbars, events and
786 * key bindings.
788 *****************************************************************************/
789 SvxConfigDialog::SvxConfigDialog(
790 Window * pParent, const SfxItemSet* pSet_ )
792 SfxTabDialog( pParent,
793 CUI_RES( RID_SVXDLG_CUSTOMIZE ), pSet_ )
795 FreeResource();
797 InitImageType();
799 AddTabPage( RID_SVXPAGE_MENUS, CreateSvxMenuConfigPage, NULL );
800 AddTabPage( RID_SVXPAGE_KEYBOARD, CreateKeyboardConfigPage, NULL );
801 AddTabPage( RID_SVXPAGE_TOOLBARS, CreateSvxToolbarConfigPage, NULL );
802 AddTabPage( RID_SVXPAGE_EVENTS, CreateSvxEventConfigPage, NULL );
804 const SfxPoolItem* pItem =
805 pSet_->GetItem( pSet_->GetPool()->GetWhich( SID_CONFIG ) );
807 if ( pItem )
809 OUString text = ((const SfxStringItem*)pItem)->GetValue();
811 if (text.indexOf( ITEM_TOOLBAR_URL ) == 0)
813 SetCurPageId( RID_SVXPAGE_TOOLBARS );
818 void SvxConfigDialog::SetFrame(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame)
820 m_xFrame = xFrame;
822 if (!impl_showKeyConfigTabPage( xFrame ))
823 RemoveTabPage( RID_SVXPAGE_KEYBOARD );
826 SvxConfigDialog::~SvxConfigDialog()
830 short SvxConfigDialog::Ok()
832 return SfxTabDialog::Ok();
835 void SvxConfigDialog::PageCreated( sal_uInt16 nId, SfxTabPage& rPage )
837 (void)rPage;
839 switch ( nId )
841 case RID_SVXPAGE_MENUS:
842 case RID_SVXPAGE_TOOLBARS:
843 case RID_SVXPAGE_KEYBOARD:
845 rPage.SetFrame(m_xFrame);
847 break;
848 case RID_SVXPAGE_EVENTS:
850 dynamic_cast< SvxEventConfigPage& >( rPage ).LateInit( m_xFrame );
852 break;
853 default:
854 break;
858 /******************************************************************************
860 * The SaveInData class is used to hold data for entries in the Save In
861 * ListBox controls in the menu and toolbar tabs
863 ******************************************************************************/
865 // Initialize static variable which holds default XImageManager
866 uno::Reference< css::ui::XImageManager>* SaveInData::xDefaultImgMgr = NULL;
868 SaveInData::SaveInData(
869 const uno::Reference< css::ui::XUIConfigurationManager >& xCfgMgr,
870 const uno::Reference< css::ui::XUIConfigurationManager >& xParentCfgMgr,
871 const OUString& aModuleId,
872 bool isDocConfig )
874 bModified( sal_False ),
875 bDocConfig( isDocConfig ),
876 bReadOnly( sal_False ),
877 m_xCfgMgr( xCfgMgr ),
878 m_xParentCfgMgr( xParentCfgMgr )
880 m_aSeparatorSeq.realloc( 1 );
881 m_aSeparatorSeq[0].Name = OUString( ITEM_DESCRIPTOR_TYPE );
882 m_aSeparatorSeq[0].Value <<= css::ui::ItemType::SEPARATOR_LINE;
884 if ( bDocConfig )
886 uno::Reference< css::ui::XUIConfigurationPersistence >
887 xDocPersistence( GetConfigManager(), uno::UNO_QUERY );
889 bReadOnly = xDocPersistence->isReadOnly();
892 uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
894 uno::Reference< container::XNameAccess > xNameAccess(
895 css::frame::UICommandDescription::create(xContext) );
897 xNameAccess->getByName( aModuleId ) >>= m_xCommandToLabelMap;
899 if ( !m_xImgMgr.is() )
901 m_xImgMgr = uno::Reference< css::ui::XImageManager >(
902 GetConfigManager()->getImageManager(), uno::UNO_QUERY );
905 if ( !IsDocConfig() )
907 // If this is not a document configuration then it is the settings
908 // for the module (writer, calc, impress etc.) Use this as the default
909 // XImageManager instance
910 xDefaultImgMgr = &m_xImgMgr;
912 else
914 // If this is a document configuration then use the module image manager
915 // as default.
916 if ( m_xParentCfgMgr.is() )
918 m_xParentImgMgr = uno::Reference< css::ui::XImageManager >(
919 m_xParentCfgMgr->getImageManager(), uno::UNO_QUERY );
920 xDefaultImgMgr = &m_xParentImgMgr;
925 uno::Reference< graphic::XGraphic > GetGraphic(
926 const uno::Reference< css::ui::XImageManager >& xImageManager,
927 const OUString& rCommandURL )
929 uno::Reference< graphic::XGraphic > result;
931 if ( xImageManager.is() )
933 // TODO handle large graphics
934 uno::Sequence< uno::Reference< graphic::XGraphic > > aGraphicSeq;
936 uno::Sequence< OUString > aImageCmdSeq( 1 );
937 aImageCmdSeq[0] = rCommandURL;
941 aGraphicSeq =
942 xImageManager->getImages( GetImageType(), aImageCmdSeq );
944 if ( aGraphicSeq.getLength() > 0 )
946 result = aGraphicSeq[0];
949 catch ( uno::Exception& )
951 // will return empty XGraphic
955 return result;
958 Image SaveInData::GetImage( const OUString& rCommandURL )
960 Image aImage;
962 uno::Reference< graphic::XGraphic > xGraphic =
963 GetGraphic( m_xImgMgr, rCommandURL );
965 if ( xGraphic.is() )
967 aImage = Image( xGraphic );
969 else if ( xDefaultImgMgr != NULL && (*xDefaultImgMgr).is() )
971 xGraphic = GetGraphic( (*xDefaultImgMgr), rCommandURL );
973 if ( xGraphic.is() )
975 aImage = Image( xGraphic );
979 return aImage;
982 bool SaveInData::PersistChanges(
983 const uno::Reference< uno::XInterface >& xManager )
985 bool result = sal_True;
989 if ( xManager.is() && !IsReadOnly() )
991 uno::Reference< css::ui::XUIConfigurationPersistence >
992 xConfigPersistence( xManager, uno::UNO_QUERY );
994 if ( xConfigPersistence->isModified() )
996 xConfigPersistence->store();
1000 catch ( com::sun::star::io::IOException& )
1002 result = sal_False;
1005 return result;
1008 /******************************************************************************
1010 * The MenuSaveInData class extends SaveInData and provides menu specific
1011 * load and store functionality.
1013 ******************************************************************************/
1015 // Initialize static variable which holds default Menu data
1016 MenuSaveInData* MenuSaveInData::pDefaultData = NULL;
1018 MenuSaveInData::MenuSaveInData(
1019 const uno::Reference< css::ui::XUIConfigurationManager >& cfgmgr,
1020 const uno::Reference< css::ui::XUIConfigurationManager >& xParentCfgMgr,
1021 const OUString& aModuleId,
1022 bool isDocConfig )
1024 SaveInData( cfgmgr, xParentCfgMgr, aModuleId, isDocConfig ),
1025 m_aMenuResourceURL(
1026 ITEM_MENUBAR_URL ),
1027 m_aDescriptorContainer(
1028 ITEM_DESCRIPTOR_CONTAINER ),
1029 pRootEntry( 0 )
1033 OUString url( ITEM_MENUBAR_URL );
1034 m_xMenuSettings = GetConfigManager()->getSettings( url, sal_False );
1036 catch ( container::NoSuchElementException& )
1038 // will use menu settings for the module
1041 // If this is not a document configuration then it is the settings
1042 // for the module (writer, calc, impress etc.). These settings should
1043 // be set as the default to be used for SaveIn locations that do not
1044 // have custom settings
1045 if ( !IsDocConfig() )
1047 SetDefaultData( this );
1051 MenuSaveInData::~MenuSaveInData()
1053 if ( pRootEntry != NULL )
1055 delete pRootEntry;
1059 SvxEntries*
1060 MenuSaveInData::GetEntries()
1062 if ( pRootEntry == NULL )
1064 pRootEntry = new SvxConfigEntry(
1065 OUString("MainMenus"),
1066 OUString(), sal_True);
1068 if ( m_xMenuSettings.is() )
1070 LoadSubMenus( m_xMenuSettings, String(), pRootEntry );
1072 else if ( GetDefaultData() != NULL )
1074 // If the doc has no config settings use module config settings
1075 LoadSubMenus( GetDefaultData()->m_xMenuSettings, String(), pRootEntry );
1079 return pRootEntry->GetEntries();
1082 void
1083 MenuSaveInData::SetEntries( SvxEntries* pNewEntries )
1085 // delete old menu hierarchy first
1086 if ( pRootEntry != NULL )
1088 delete pRootEntry->GetEntries();
1091 // now set new menu hierarchy
1092 pRootEntry->SetEntries( pNewEntries );
1095 bool MenuSaveInData::LoadSubMenus(
1096 const uno::Reference< container::XIndexAccess >& xMenuSettings,
1097 const OUString& rBaseTitle,
1098 SvxConfigEntry* pParentData )
1100 SvxEntries* pEntries = pParentData->GetEntries();
1102 // Don't access non existing menu configuration!
1103 if ( !xMenuSettings.is() )
1104 return true;
1106 for ( sal_Int32 nIndex = 0; nIndex < xMenuSettings->getCount(); ++nIndex )
1108 uno::Reference< container::XIndexAccess > xSubMenu;
1109 OUString aCommandURL;
1110 OUString aLabel;
1111 bool bIsUserDefined = sal_True;
1113 sal_uInt16 nType( css::ui::ItemType::DEFAULT );
1115 bool bItem = GetMenuItemData( xMenuSettings, nIndex,
1116 aCommandURL, aLabel, nType, xSubMenu );
1118 if ( bItem )
1120 if ( nType == css::ui::ItemType::DEFAULT )
1122 uno::Any a;
1125 a = m_xCommandToLabelMap->getByName( aCommandURL );
1126 bIsUserDefined = sal_False;
1128 catch ( container::NoSuchElementException& )
1130 bIsUserDefined = sal_True;
1133 // If custom label not set retrieve it from the command
1134 // to info service
1135 if ( aLabel.equals( OUString() ) )
1137 uno::Sequence< beans::PropertyValue > aPropSeq;
1138 if ( a >>= aPropSeq )
1140 for ( sal_Int32 i = 0; i < aPropSeq.getLength(); ++i )
1142 if ( aPropSeq[i].Name.equalsAscii( ITEM_DESCRIPTOR_LABEL ) )
1144 aPropSeq[i].Value >>= aLabel;
1145 break;
1151 if ( xSubMenu.is() )
1153 // popup menu
1154 SvxConfigEntry* pEntry = new SvxConfigEntry(
1155 aLabel, aCommandURL, sal_True );
1157 pEntry->SetUserDefined( bIsUserDefined );
1159 pEntries->push_back( pEntry );
1161 OUString subMenuTitle( rBaseTitle );
1163 if ( !subMenuTitle.isEmpty() )
1165 subMenuTitle += OUString( aMenuSeparatorStr);
1167 else
1169 pEntry->SetMain( sal_True );
1172 subMenuTitle += stripHotKey( aLabel );
1174 LoadSubMenus( xSubMenu, subMenuTitle, pEntry );
1176 else
1178 SvxConfigEntry* pEntry = new SvxConfigEntry(
1179 aLabel, aCommandURL, sal_False );
1180 pEntry->SetUserDefined( bIsUserDefined );
1181 pEntries->push_back( pEntry );
1184 else
1186 SvxConfigEntry* pEntry = new SvxConfigEntry;
1187 pEntry->SetUserDefined( bIsUserDefined );
1188 pEntries->push_back( pEntry );
1192 return true;
1195 bool MenuSaveInData::Apply()
1197 bool result = sal_False;
1199 if ( IsModified() )
1201 // Apply new menu bar structure to our settings container
1202 m_xMenuSettings = uno::Reference< container::XIndexAccess >(
1203 GetConfigManager()->createSettings(), uno::UNO_QUERY );
1205 uno::Reference< container::XIndexContainer > xIndexContainer (
1206 m_xMenuSettings, uno::UNO_QUERY );
1208 uno::Reference< lang::XSingleComponentFactory > xFactory (
1209 m_xMenuSettings, uno::UNO_QUERY );
1211 Apply( pRootEntry, xIndexContainer, xFactory, NULL );
1215 if ( GetConfigManager()->hasSettings( m_aMenuResourceURL ) )
1217 GetConfigManager()->replaceSettings(
1218 m_aMenuResourceURL, m_xMenuSettings );
1220 else
1222 GetConfigManager()->insertSettings(
1223 m_aMenuResourceURL, m_xMenuSettings );
1226 catch ( container::NoSuchElementException& )
1228 OSL_TRACE("caught container::NoSuchElementException saving settings");
1230 catch ( com::sun::star::io::IOException& )
1232 OSL_TRACE("caught IOException saving settings");
1234 catch ( com::sun::star::uno::Exception& )
1236 OSL_TRACE("caught some other exception saving settings");
1239 SetModified( sal_False );
1241 result = PersistChanges( GetConfigManager() );
1244 return result;
1247 void MenuSaveInData::Apply(
1248 SvxConfigEntry* pRootEntry_,
1249 uno::Reference< container::XIndexContainer >& rMenuBar,
1250 uno::Reference< lang::XSingleComponentFactory >& rFactory,
1251 SvTreeListEntry *pParentEntry )
1253 (void)pRootEntry_;
1254 (void)pParentEntry;
1256 SvxEntries::const_iterator iter = GetEntries()->begin();
1257 SvxEntries::const_iterator end = GetEntries()->end();
1259 uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
1261 for ( ; iter != end; ++iter )
1263 SvxConfigEntry* pEntryData = *iter;
1265 uno::Sequence< beans::PropertyValue > aPropValueSeq =
1266 ConvertSvxConfigEntry( m_xCommandToLabelMap, pEntryData );
1268 uno::Reference< container::XIndexContainer > xSubMenuBar(
1269 rFactory->createInstanceWithContext( xContext ),
1270 uno::UNO_QUERY );
1272 sal_Int32 nIndex = aPropValueSeq.getLength();
1273 aPropValueSeq.realloc( nIndex + 1 );
1274 aPropValueSeq[nIndex].Name = m_aDescriptorContainer;
1275 aPropValueSeq[nIndex].Value <<= xSubMenuBar;
1276 rMenuBar->insertByIndex(
1277 rMenuBar->getCount(), uno::makeAny( aPropValueSeq ));
1278 ApplyMenu( xSubMenuBar, rFactory, pEntryData );
1282 void MenuSaveInData::ApplyMenu(
1283 uno::Reference< container::XIndexContainer >& rMenuBar,
1284 uno::Reference< lang::XSingleComponentFactory >& rFactory,
1285 SvxConfigEntry* pMenuData )
1287 uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
1289 SvxEntries::const_iterator iter = pMenuData->GetEntries()->begin();
1290 SvxEntries::const_iterator end = pMenuData->GetEntries()->end();
1292 for ( ; iter != end; ++iter )
1294 SvxConfigEntry* pEntry = *iter;
1296 if ( pEntry->IsPopup() )
1298 uno::Sequence< beans::PropertyValue > aPropValueSeq =
1299 ConvertSvxConfigEntry( m_xCommandToLabelMap, pEntry );
1301 uno::Reference< container::XIndexContainer > xSubMenuBar(
1302 rFactory->createInstanceWithContext( xContext ),
1303 uno::UNO_QUERY );
1305 sal_Int32 nIndex = aPropValueSeq.getLength();
1306 aPropValueSeq.realloc( nIndex + 1 );
1307 aPropValueSeq[nIndex].Name = m_aDescriptorContainer;
1308 aPropValueSeq[nIndex].Value <<= xSubMenuBar;
1310 rMenuBar->insertByIndex(
1311 rMenuBar->getCount(), uno::makeAny( aPropValueSeq ));
1313 ApplyMenu( xSubMenuBar, rFactory, pEntry );
1315 else if ( pEntry->IsSeparator() )
1317 rMenuBar->insertByIndex(
1318 rMenuBar->getCount(), uno::makeAny( m_aSeparatorSeq ));
1320 else
1322 uno::Sequence< beans::PropertyValue > aPropValueSeq =
1323 ConvertSvxConfigEntry( m_xCommandToLabelMap, pEntry );
1324 rMenuBar->insertByIndex(
1325 rMenuBar->getCount(), uno::makeAny( aPropValueSeq ));
1330 void
1331 MenuSaveInData::Reset()
1333 GetConfigManager()->reset();
1335 delete pRootEntry;
1336 pRootEntry = NULL;
1340 m_xMenuSettings = GetConfigManager()->getSettings(
1341 m_aMenuResourceURL, sal_False );
1343 catch ( container::NoSuchElementException& )
1345 // will use default settings
1349 class PopupPainter : public SvLBoxString
1351 public:
1352 PopupPainter( SvTreeListEntry* pEntry, const String& rStr )
1353 : SvLBoxString( pEntry, 0, rStr )
1356 ~PopupPainter() { }
1358 virtual void Paint( const Point& rPos, SvTreeListBox& rOutDev,
1359 const SvViewDataEntry* pView, const SvTreeListEntry* pEntry)
1361 SvLBoxString::Paint(rPos, rOutDev, pView, pEntry);
1363 Color aOldFillColor = rOutDev.GetFillColor();
1365 SvTreeListBox* pTreeBox = static_cast< SvTreeListBox* >( &rOutDev );
1366 long nX = pTreeBox->GetSizePixel().Width();
1368 ScrollBar* pVScroll = pTreeBox->GetVScroll();
1369 if ( pVScroll->IsVisible() )
1371 nX -= pVScroll->GetSizePixel().Width();
1374 const SvViewDataItem* pItem = rOutDev.GetViewDataItem( pEntry, this );
1375 nX -= pItem->maSize.Height();
1377 long nSize = pItem->maSize.Height() / 2;
1378 long nHalfSize = nSize / 2;
1379 long nY = rPos.Y() + nHalfSize;
1381 if ( aOldFillColor == COL_WHITE )
1383 rOutDev.SetFillColor( Color( COL_BLACK ) );
1385 else
1387 rOutDev.SetFillColor( Color( COL_WHITE ) );
1390 long n = 0;
1391 while ( n <= nHalfSize )
1393 rOutDev.DrawRect( Rectangle( nX+n, nY+n, nX+n, nY+nSize-n ) );
1394 ++n;
1397 rOutDev.SetFillColor( aOldFillColor );
1401 /******************************************************************************
1403 * SvxMenuEntriesListBox is the listbox in which the menu items for a
1404 * particular menu are shown. We have a custom listbox because we need
1405 * to add drag'n'drop support from the Macro Selector and within the
1406 * listbox
1408 *****************************************************************************/
1409 SvxMenuEntriesListBox::SvxMenuEntriesListBox(
1410 Window* pParent, const ResId& rResId)
1411 : SvTreeListBox( pParent, rResId )
1412 , pPage( (SvxMenuConfigPage*) pParent )
1413 , m_bIsInternalDrag( sal_False )
1415 SetStyle(
1416 GetStyle() | WB_CLIPCHILDREN | WB_HSCROLL | WB_HIDESELECTION );
1418 SetSpaceBetweenEntries( 3 );
1419 SetEntryHeight( ENTRY_HEIGHT );
1421 SetHighlightRange();
1422 SetSelectionMode(SINGLE_SELECTION);
1424 SetDragDropMode( SV_DRAGDROP_CTRL_MOVE |
1425 SV_DRAGDROP_APP_COPY |
1426 SV_DRAGDROP_ENABLE_TOP |
1427 SV_DRAGDROP_APP_DROP);
1430 SvxMenuEntriesListBox::~SvxMenuEntriesListBox()
1432 // do nothing
1435 // drag and drop support
1436 DragDropMode SvxMenuEntriesListBox::NotifyStartDrag(
1437 TransferDataContainer& aTransferDataContainer, SvTreeListEntry* pEntry )
1439 (void)aTransferDataContainer;
1440 (void)pEntry;
1442 m_bIsInternalDrag = sal_True;
1443 return GetDragDropMode();
1446 void SvxMenuEntriesListBox::DragFinished( sal_Int8 nDropAction )
1448 (void)nDropAction;
1449 m_bIsInternalDrag = sal_False;
1452 sal_Int8 SvxMenuEntriesListBox::AcceptDrop( const AcceptDropEvent& rEvt )
1454 if ( m_bIsInternalDrag )
1456 // internal copy isn't allowed!
1457 if ( rEvt.mnAction == DND_ACTION_COPY )
1458 return DND_ACTION_NONE;
1459 else
1460 return SvTreeListBox::AcceptDrop( rEvt );
1463 // Always do COPY instead of MOVE if D&D comes from outside!
1464 AcceptDropEvent aNewAcceptDropEvent( rEvt );
1465 aNewAcceptDropEvent.mnAction = DND_ACTION_COPY;
1466 return SvTreeListBox::AcceptDrop( aNewAcceptDropEvent );
1469 sal_Bool SvxMenuEntriesListBox::NotifyAcceptDrop( SvTreeListEntry* )
1471 return sal_True;
1474 sal_Bool SvxMenuEntriesListBox::NotifyMoving(
1475 SvTreeListEntry* pTarget, SvTreeListEntry* pSource,
1476 SvTreeListEntry*& rpNewParent, sal_uLong& rNewChildPos)
1478 // only try to do a move if we are dragging within the list box
1479 if ( m_bIsInternalDrag )
1481 if ( pPage->MoveEntryData( pSource, pTarget ) == sal_True )
1483 SvTreeListBox::NotifyMoving(
1484 pTarget, pSource, rpNewParent, rNewChildPos );
1485 return sal_True;
1487 else
1489 return sal_False;
1492 else
1494 return NotifyCopying( pTarget, pSource, rpNewParent, rNewChildPos );
1498 sal_Bool SvxMenuEntriesListBox::NotifyCopying(
1499 SvTreeListEntry* pTarget, SvTreeListEntry* pSource,
1500 SvTreeListEntry*& rpNewParent, sal_uLong& rNewChildPos)
1502 (void)pSource;
1503 (void)rpNewParent;
1504 (void)rNewChildPos;
1506 if ( !m_bIsInternalDrag )
1508 // if the target is NULL then add function to the start of the list
1509 pPage->AddFunction( pTarget, pTarget == NULL );
1511 // AddFunction already adds the listbox entry so return FALSE
1512 // to stop another listbox entry being added
1513 return sal_False;
1516 // Copying is only allowed from external controls, not within the listbox
1517 return sal_False;
1520 void SvxMenuEntriesListBox::KeyInput( const KeyEvent& rKeyEvent )
1522 KeyCode keycode = rKeyEvent.GetKeyCode();
1524 // support DELETE for removing the current entry
1525 if ( keycode == KEY_DELETE )
1527 pPage->DeleteSelectedContent();
1529 // support CTRL+UP and CTRL+DOWN for moving selected entries
1530 else if ( keycode.GetCode() == KEY_UP && keycode.IsMod1() )
1532 pPage->MoveEntry( sal_True );
1534 else if ( keycode.GetCode() == KEY_DOWN && keycode.IsMod1() )
1536 pPage->MoveEntry( sal_False );
1538 else
1540 // pass on to superclass
1541 SvTreeListBox::KeyInput( rKeyEvent );
1545 // class SvxDescriptionEdit ----------------------------------------------
1547 SvxDescriptionEdit::SvxDescriptionEdit( Window* pParent, const ResId& _rId ) :
1549 ExtMultiLineEdit( pParent, _rId )
1552 // calculate the available space for help text
1553 m_aRealRect = Rectangle( Point(), GetSizePixel() );
1554 if ( GetVScrollBar() )
1555 m_aRealRect.Right() -= ( GetVScrollBar()->GetSizePixel().Width() + 4 );
1557 SetLeftMargin(2);
1558 SetBorderStyle( WINDOW_BORDER_MONO );
1561 // -----------------------------------------------------------------------
1563 void SvxDescriptionEdit::SetNewText( const String& _rText )
1565 String sTemp( _rText );
1566 sal_Bool bShow = sal_False;
1567 if ( sTemp.Len() > 0 )
1569 // detect if a scrollbar is necessary
1570 Rectangle aRect = GetTextRect( m_aRealRect, sTemp, TEXT_DRAW_WORDBREAK | TEXT_DRAW_MULTILINE );
1571 bShow = ( aRect.Bottom() > m_aRealRect.Bottom() );
1574 if ( GetVScrollBar() )
1575 GetVScrollBar()->Show( bShow );
1577 if ( bShow )
1578 sTemp += '\n';
1580 SetText( sTemp );
1583 /******************************************************************************
1585 * SvxConfigPage is the abstract base class on which the Menu and Toolbar
1586 * configuration tabpages are based. It includes methods which are common to
1587 * both tabpages to add, delete, move and rename items etc.
1589 *****************************************************************************/
1590 SvxConfigPage::SvxConfigPage(
1591 Window *pParent, const SfxItemSet& rSet )
1593 SfxTabPage( pParent, CUI_RES( RID_SVXPAGE_MENUS ), rSet ),
1594 bInitialised( sal_False ),
1595 pCurrentSaveInData( 0 ),
1596 aTopLevelSeparator( this, CUI_RES( GRP_MENUS ) ),
1597 aTopLevelLabel( this, CUI_RES( FT_MENUS ) ),
1598 aTopLevelListBox( this, CUI_RES( LB_MENUS ) ),
1599 aNewTopLevelButton( this, CUI_RES( BTN_NEW ) ),
1600 aModifyTopLevelButton( this, CUI_RES( BTN_CHANGE ) ),
1601 aContentsSeparator( this, CUI_RES( GRP_MENU_SEPARATOR ) ),
1602 aContentsLabel( this, CUI_RES( GRP_MENU_ENTRIES ) ),
1603 aContentsListBox( 0 ),
1604 aAddCommandsButton( this, CUI_RES( BTN_ADD_COMMANDS ) ),
1605 aModifyCommandButton( this, CUI_RES( BTN_CHANGE_ENTRY ) ),
1606 aMoveUpButton( this, CUI_RES( BTN_UP ) ),
1607 aMoveDownButton( this, CUI_RES( BTN_DOWN ) ),
1608 aSaveInText( this, CUI_RES( TXT_SAVEIN ) ),
1609 aSaveInListBox( this, CUI_RES( LB_SAVEIN ) ),
1610 aDescriptionLabel( this, CUI_RES( FT_DESCRIPTION ) ),
1611 aDescriptionField( this, CUI_RES( ED_DESCRIPTION ) ),
1612 pSelectorDlg( 0 )
1614 aDescriptionField.SetControlBackground( GetSettings().GetStyleSettings().GetDialogColor() );
1615 aDescriptionField.SetAutoScroll( sal_True );
1616 aDescriptionField.EnableCursor( sal_False );
1618 aMoveUpButton.SetAccessibleName(String(CUI_RES(BUTTON_STR_UP)));
1619 aMoveDownButton.SetAccessibleName(String(CUI_RES(BUTTON_STR_DOWN)));
1620 aMoveUpButton.SetAccessibleRelationMemberOf(&aContentsSeparator);
1621 aMoveDownButton.SetAccessibleRelationMemberOf(&aContentsSeparator);
1622 aNewTopLevelButton.SetAccessibleRelationMemberOf(&aTopLevelSeparator);
1623 aModifyTopLevelButton.SetAccessibleRelationMemberOf(&aTopLevelSeparator);
1624 aAddCommandsButton.SetAccessibleRelationMemberOf(&aContentsSeparator);
1625 aModifyCommandButton.SetAccessibleRelationMemberOf(&aContentsSeparator);
1628 SvxConfigPage::~SvxConfigPage()
1632 void SvxConfigPage::Reset( const SfxItemSet& )
1634 // If we haven't initialised our XMultiServiceFactory reference
1635 // then Reset is being called at the opening of the dialog.
1637 // Load menu configuration data for the module of the currently
1638 // selected document, for the currently selected document, and for
1639 // all other open documents of the same module type
1640 if ( !bInitialised )
1642 sal_uInt16 nPos = 0;
1643 uno::Reference < css::ui::XUIConfigurationManager > xCfgMgr;
1644 uno::Reference < css::ui::XUIConfigurationManager > xDocCfgMgr;
1646 uno::Reference< uno::XComponentContext > xContext(
1647 ::comphelper::getProcessComponentContext(), uno::UNO_QUERY_THROW );
1649 m_xFrame = GetFrame();
1650 OUString aModuleId = GetFrameWithDefaultAndIdentify( m_xFrame );
1652 // replace %MODULENAME in the label with the correct module name
1653 uno::Reference< css::frame::XModuleManager2 > xModuleManager(
1654 css::frame::ModuleManager::create( xContext ));
1655 OUString aModuleName = GetUIModuleName( aModuleId, xModuleManager );
1657 OUString title = aTopLevelSeparator.GetText();
1658 OUString aSearchString("%MODULENAME" );
1659 sal_Int32 index = title.indexOf( aSearchString );
1661 if ( index != -1 )
1663 title = title.replaceAt(
1664 index, aSearchString.getLength(), aModuleName );
1665 aTopLevelSeparator.SetText( title );
1668 uno::Reference< css::ui::XModuleUIConfigurationManagerSupplier >
1669 xModuleCfgSupplier( css::ui::ModuleUIConfigurationManagerSupplier::create(xContext) );
1671 // Set up data for module specific menus
1672 SaveInData* pModuleData = NULL;
1676 xCfgMgr =
1677 xModuleCfgSupplier->getUIConfigurationManager( aModuleId );
1679 pModuleData = CreateSaveInData( xCfgMgr,
1680 uno::Reference< css::ui::XUIConfigurationManager >(),
1681 aModuleId,
1682 sal_False );
1684 catch ( container::NoSuchElementException& )
1688 if ( pModuleData != NULL )
1690 nPos = aSaveInListBox.InsertEntry(
1691 utl::ConfigManager::getProductName() +
1692 OUString( " " ) + aModuleName );
1693 aSaveInListBox.SetEntryData( nPos, pModuleData );
1696 // try to retrieve the document based ui configuration manager
1697 OUString aTitle;
1698 uno::Reference< frame::XController > xController =
1699 m_xFrame->getController();
1700 if ( CanConfig( aModuleId ) && xController.is() )
1702 uno::Reference< frame::XModel > xModel( xController->getModel() );
1703 if ( xModel.is() )
1705 uno::Reference< css::ui::XUIConfigurationManagerSupplier >
1706 xCfgSupplier( xModel, uno::UNO_QUERY );
1708 if ( xCfgSupplier.is() )
1710 xDocCfgMgr = xCfgSupplier->getUIConfigurationManager();
1712 aTitle = ::comphelper::DocumentInfo::getDocumentTitle( xModel );
1716 SaveInData* pDocData = NULL;
1717 if ( xDocCfgMgr.is() )
1719 pDocData = CreateSaveInData( xDocCfgMgr, xCfgMgr, aModuleId, sal_True );
1721 if ( !pDocData->IsReadOnly() )
1723 nPos = aSaveInListBox.InsertEntry( aTitle );
1724 aSaveInListBox.SetEntryData( nPos, pDocData );
1728 // if an item to select has been passed in (eg. the ResourceURL for a
1729 // toolbar) then try to select the SaveInData entry that has that item
1730 bool bURLToSelectFound = sal_False;
1731 if ( !m_aURLToSelect.isEmpty() )
1733 if ( pDocData != NULL && pDocData->HasURL( m_aURLToSelect ) )
1735 aSaveInListBox.SelectEntryPos( nPos, sal_True );
1736 pCurrentSaveInData = pDocData;
1737 bURLToSelectFound = sal_True;
1739 else if ( pModuleData->HasURL( m_aURLToSelect ) )
1741 aSaveInListBox.SelectEntryPos( 0, sal_True );
1742 pCurrentSaveInData = pModuleData;
1743 bURLToSelectFound = sal_True;
1747 if ( bURLToSelectFound == sal_False )
1749 // if the document has menu configuration settings select it
1750 // it the SaveIn listbox, otherwise select the module data
1751 if ( pDocData != NULL && pDocData->HasSettings() )
1753 aSaveInListBox.SelectEntryPos( nPos, sal_True );
1754 pCurrentSaveInData = pDocData;
1756 else
1758 aSaveInListBox.SelectEntryPos( 0, sal_True );
1759 pCurrentSaveInData = pModuleData;
1763 #ifdef DBG_UTIL
1764 DBG_ASSERT( pCurrentSaveInData, "SvxConfigPage::Reset(): no SaveInData" );
1765 #endif
1767 if ( CanConfig( aModuleId ) )
1769 // Load configuration for other open documents which have
1770 // same module type
1771 uno::Sequence< uno::Reference< frame::XFrame > > aFrameList;
1774 uno::Reference< frame::XDesktop2 > xFramesSupplier = frame::Desktop::create(
1775 xContext );
1777 uno::Reference< frame::XFrames > xFrames =
1778 xFramesSupplier->getFrames();
1780 aFrameList = xFrames->queryFrames(
1781 frame::FrameSearchFlag::ALL & ~frame::FrameSearchFlag::SELF );
1784 catch( const uno::Exception& )
1786 DBG_UNHANDLED_EXCEPTION();
1789 for ( sal_Int32 i = 0; i < aFrameList.getLength(); ++i )
1791 uno::Reference < frame::XFrame > xf = aFrameList[i];
1793 if ( xf.is() && xf != m_xFrame )
1795 OUString aCheckId;
1796 try{
1797 aCheckId = xModuleManager->identify( xf );
1798 } catch(const uno::Exception&)
1799 { aCheckId = OUString(); }
1801 if ( aModuleId.equals( aCheckId ) )
1803 // try to get the document based ui configuration manager
1804 OUString aTitle2;
1805 uno::Reference< frame::XController > xController_ =
1806 xf->getController();
1808 if ( xController_.is() )
1810 uno::Reference< frame::XModel > xModel(
1811 xController_->getModel() );
1813 if ( xModel.is() )
1815 uno::Reference<
1816 css::ui::XUIConfigurationManagerSupplier >
1817 xCfgSupplier( xModel, uno::UNO_QUERY );
1819 if ( xCfgSupplier.is() )
1821 xDocCfgMgr =
1822 xCfgSupplier->getUIConfigurationManager();
1824 aTitle2 = ::comphelper::DocumentInfo::getDocumentTitle( xModel );
1828 if ( xDocCfgMgr.is() )
1830 SaveInData* pData = CreateSaveInData( xDocCfgMgr, xCfgMgr, aModuleId, sal_True );
1832 if ( pData && !pData->IsReadOnly() )
1834 nPos = aSaveInListBox.InsertEntry( aTitle2 );
1835 aSaveInListBox.SetEntryData( nPos, pData );
1843 aSaveInListBox.SetSelectHdl(
1844 LINK( this, SvxConfigPage, SelectSaveInLocation ) );
1846 bInitialised = sal_True;
1848 Init();
1850 else
1852 if ( QueryReset() == RET_YES )
1854 // Reset menu configuration for currently selected SaveInData
1855 GetSaveInData()->Reset();
1857 Init();
1862 OUString SvxConfigPage::GetFrameWithDefaultAndIdentify( uno::Reference< frame::XFrame >& _inout_rxFrame )
1864 OUString sModuleID;
1867 uno::Reference< uno::XComponentContext > xContext(
1868 ::comphelper::getProcessComponentContext() );
1870 uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create(
1871 xContext );
1873 if ( !_inout_rxFrame.is() )
1874 _inout_rxFrame = xDesktop->getActiveFrame();
1876 if ( !_inout_rxFrame.is() )
1878 _inout_rxFrame = xDesktop->getCurrentFrame();
1881 if ( !_inout_rxFrame.is() && SfxViewFrame::Current() )
1882 _inout_rxFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface();
1884 if ( !_inout_rxFrame.is() )
1886 SAL_WARN( "cui.customize", "SvxConfigPage::GetFrameWithDefaultAndIdentify(): no frame found!" );
1887 return sModuleID;
1890 uno::Reference< css::frame::XModuleManager2 > xModuleManager(
1891 css::frame::ModuleManager::create( xContext ) );
1895 sModuleID = xModuleManager->identify( _inout_rxFrame );
1897 catch ( const frame::UnknownModuleException& )
1902 catch( const uno::Exception& )
1904 DBG_UNHANDLED_EXCEPTION();
1907 return sModuleID;
1910 sal_Bool SvxConfigPage::FillItemSet( SfxItemSet& )
1912 bool result = sal_False;
1914 for ( sal_uInt16 i = 0 ; i < aSaveInListBox.GetEntryCount(); ++i )
1916 SaveInData* pData =
1917 (SaveInData*) aSaveInListBox.GetEntryData( i );
1919 result = pData->Apply();
1921 return result;
1924 void SvxConfigPage::PositionContentsListBox()
1926 if ( aContentsListBox == NULL )
1928 return;
1931 Point p;
1932 Size s;
1933 long x, y, width, height;
1935 // x and width is same as aTopLevelListBox
1936 x = aTopLevelListBox.GetPosPixel().X();
1937 width = aTopLevelListBox.GetSizePixel().Width();
1939 // y is same as aAddCommandsButton
1940 y = aAddCommandsButton.GetPosPixel().Y();
1942 // get gap between aAddCommandsButton and aContentsSeparator
1943 p = aContentsSeparator.GetPosPixel();
1944 s = aContentsSeparator.GetSizePixel();
1945 long gap = y - ( p.Y() + s.Height() );
1947 height = aSaveInListBox.GetPosPixel().Y() - y - gap;
1949 aContentsListBox->SetPosPixel( Point( x, y ) );
1950 aContentsListBox->SetSizePixel( Size( width, height ) );
1953 IMPL_LINK( SvxConfigPage, SelectSaveInLocation, ListBox *, pBox )
1955 (void)pBox;
1957 pCurrentSaveInData = (SaveInData*) aSaveInListBox.GetEntryData(
1958 aSaveInListBox.GetSelectEntryPos());
1960 Init();
1961 return 1;
1964 void SvxConfigPage::ReloadTopLevelListBox( SvxConfigEntry* pToSelect )
1966 sal_uInt16 nSelectionPos = aTopLevelListBox.GetSelectEntryPos();
1967 aTopLevelListBox.Clear();
1969 if ( GetSaveInData() && GetSaveInData()->GetEntries() )
1971 SvxEntries::const_iterator iter = GetSaveInData()->GetEntries()->begin();
1972 SvxEntries::const_iterator end = GetSaveInData()->GetEntries()->end();
1974 for ( ; iter != end; ++iter )
1976 SvxConfigEntry* pEntryData = *iter;
1977 sal_uInt16 nPos = aTopLevelListBox.InsertEntry( stripHotKey( pEntryData->GetName() ) );
1978 aTopLevelListBox.SetEntryData( nPos, pEntryData );
1980 if ( pEntryData == pToSelect )
1981 nSelectionPos = nPos;
1983 AddSubMenusToUI( stripHotKey( pEntryData->GetName() ), pEntryData );
1986 #ifdef DBG_UTIL
1987 else
1989 DBG_ASSERT( GetSaveInData(), "SvxConfigPage::ReloadTopLevelListBox(): no SaveInData" );
1990 DBG_ASSERT( GetSaveInData()->GetEntries() ,
1991 "SvxConfigPage::ReloadTopLevelListBox(): no SaveInData entries" );
1993 #endif
1995 nSelectionPos = nSelectionPos < aTopLevelListBox.GetEntryCount() ?
1996 nSelectionPos : aTopLevelListBox.GetEntryCount() - 1;
1998 aTopLevelListBox.SelectEntryPos( nSelectionPos, sal_True );
1999 aTopLevelListBox.GetSelectHdl().Call( this );
2002 void SvxConfigPage::AddSubMenusToUI(
2003 const String& rBaseTitle, SvxConfigEntry* pParentData )
2005 SvxEntries::const_iterator iter = pParentData->GetEntries()->begin();
2006 SvxEntries::const_iterator end = pParentData->GetEntries()->end();
2008 for ( ; iter != end; ++iter )
2010 SvxConfigEntry* pEntryData = *iter;
2012 if ( pEntryData->IsPopup() )
2014 OUString subMenuTitle( rBaseTitle );
2015 subMenuTitle += OUString(aMenuSeparatorStr);
2016 subMenuTitle += stripHotKey( pEntryData->GetName() );
2018 sal_uInt16 nPos = aTopLevelListBox.InsertEntry( subMenuTitle );
2019 aTopLevelListBox.SetEntryData( nPos, pEntryData );
2021 AddSubMenusToUI( subMenuTitle, pEntryData );
2026 SvxEntries* SvxConfigPage::FindParentForChild(
2027 SvxEntries* pRootEntries, SvxConfigEntry* pChildData )
2029 SvxEntries::const_iterator iter = pRootEntries->begin();
2030 SvxEntries::const_iterator end = pRootEntries->end();
2032 for ( ; iter != end; ++iter )
2034 SvxConfigEntry* pEntryData = *iter;
2036 if ( pEntryData == pChildData )
2038 return pRootEntries;
2040 else if ( pEntryData->IsPopup() )
2042 SvxEntries* result =
2043 FindParentForChild( pEntryData->GetEntries(), pChildData );
2045 if ( result != NULL )
2047 return result;
2051 return NULL;
2054 SvTreeListEntry* SvxConfigPage::AddFunction(
2055 SvTreeListEntry* pTarget, bool bFront, bool bAllowDuplicates )
2057 String aDisplayName = pSelectorDlg->GetSelectedDisplayName();
2058 String aURL = pSelectorDlg->GetScriptURL();
2060 if ( !aURL.Len() )
2062 return NULL;
2065 SvxConfigEntry* pNewEntryData =
2066 new SvxConfigEntry( aDisplayName, aURL, sal_False );
2067 pNewEntryData->SetUserDefined( sal_True );
2069 // check that this function is not already in the menu
2070 SvxConfigEntry* pParent = GetTopLevelSelection();
2072 if ( !bAllowDuplicates )
2074 for (SvxEntries::const_iterator iter(pParent->GetEntries()->begin()), end(pParent->GetEntries()->end());
2075 iter != end ; ++iter)
2077 SvxConfigEntry *pCurEntry = *iter;
2079 if ( pCurEntry->GetCommand() == pNewEntryData->GetCommand() )
2081 // asynchronous error message, because of MsgBoxes
2082 PostUserEvent(
2083 LINK( this, SvxConfigPage, AsyncInfoMsg ) );
2084 delete pNewEntryData;
2085 return NULL;
2090 return InsertEntry( pNewEntryData, pTarget, bFront );
2093 SvTreeListEntry* SvxConfigPage::InsertEntry(
2094 SvxConfigEntry* pNewEntryData,
2095 SvTreeListEntry* pTarget,
2096 bool bFront )
2098 // Grab the entries list for the currently selected menu
2099 SvxEntries* pEntries = GetTopLevelSelection()->GetEntries();
2101 SvTreeListEntry* pNewEntry = NULL;
2102 SvTreeListEntry* pCurEntry =
2103 pTarget != NULL ? pTarget : aContentsListBox->GetCurEntry();
2105 if ( bFront )
2107 pEntries->insert( pEntries->begin(), pNewEntryData );
2108 pNewEntry = InsertEntryIntoUI( pNewEntryData, 0 );
2110 else if ( pCurEntry == NULL || pCurEntry == aContentsListBox->Last() )
2112 pEntries->push_back( pNewEntryData );
2113 pNewEntry = InsertEntryIntoUI( pNewEntryData );
2115 else
2117 SvxConfigEntry* pEntryData =
2118 (SvxConfigEntry*) pCurEntry->GetUserData();
2120 SvxEntries::iterator iter = pEntries->begin();
2121 SvxEntries::const_iterator end = pEntries->end();
2123 // Advance the iterator to the data for currently selected entry
2124 sal_uInt16 nPos = 0;
2125 while (*iter != pEntryData && ++iter != end)
2127 ++nPos;
2130 // Now step past it to the entry after the currently selected one
2131 ++iter;
2132 ++nPos;
2134 // Now add the new entry to the UI and to the parent's list
2135 if ( iter != end )
2137 pEntries->insert( iter, pNewEntryData );
2138 pNewEntry = InsertEntryIntoUI( pNewEntryData, nPos );
2142 if ( pNewEntry != NULL )
2144 aContentsListBox->Select( pNewEntry );
2145 aContentsListBox->MakeVisible( pNewEntry );
2147 GetSaveInData()->SetModified( sal_True );
2150 return pNewEntry;
2153 SvTreeListEntry* SvxConfigPage::InsertEntryIntoUI(
2154 SvxConfigEntry* pNewEntryData, sal_uLong nPos )
2156 SvTreeListEntry* pNewEntry = NULL;
2158 if (pNewEntryData->IsSeparator())
2160 pNewEntry = aContentsListBox->InsertEntry(
2161 OUString(aSeparatorStr),
2162 0, sal_False, nPos, pNewEntryData);
2164 else
2166 OUString aName = stripHotKey( pNewEntryData->GetName() );
2168 Image aImage = GetSaveInData()->GetImage(
2169 pNewEntryData->GetCommand());
2171 if ( !!aImage )
2173 pNewEntry = aContentsListBox->InsertEntry(
2174 aName, aImage, aImage, 0, sal_False, nPos, pNewEntryData );
2176 else
2178 pNewEntry = aContentsListBox->InsertEntry(
2179 aName, 0, sal_False, nPos, pNewEntryData );
2182 if ( pNewEntryData->IsPopup() ||
2183 pNewEntryData->GetStyle() & css::ui::ItemStyle::DROP_DOWN )
2185 // add new popup painter, it gets destructed by the entry
2186 pNewEntry->ReplaceItem(
2187 new PopupPainter( pNewEntry, aName ),
2188 pNewEntry->ItemCount() - 1 );
2192 return pNewEntry;
2195 IMPL_LINK( SvxConfigPage, AsyncInfoMsg, String*, pMsg )
2197 (void)pMsg;
2199 // Asynchronous msg because of D&D
2200 InfoBox( this, CUI_RES(
2201 IBX_MNUCFG_ALREADY_INCLUDED ) ).Execute();
2203 return 0;
2206 IMPL_LINK( SvxConfigPage, MoveHdl, Button *, pButton )
2208 MoveEntry( pButton == &aMoveUpButton );
2209 return 0;
2212 void SvxConfigPage::MoveEntry( bool bMoveUp )
2214 SvTreeListEntry *pSourceEntry = aContentsListBox->FirstSelected();
2215 SvTreeListEntry *pTargetEntry = NULL;
2216 SvTreeListEntry *pToSelect = NULL;
2218 if ( !pSourceEntry )
2220 return;
2223 if ( bMoveUp )
2225 // Move Up is just a Move Down with the source and target reversed
2226 pTargetEntry = pSourceEntry;
2227 pSourceEntry = aContentsListBox->PrevSibling( pTargetEntry );
2228 pToSelect = pTargetEntry;
2230 else
2232 pTargetEntry = aContentsListBox->NextSibling( pSourceEntry );
2233 pToSelect = pSourceEntry;
2236 if ( MoveEntryData( pSourceEntry, pTargetEntry ) )
2238 aContentsListBox->GetModel()->Move( pSourceEntry, pTargetEntry );
2239 aContentsListBox->Select( pToSelect );
2240 aContentsListBox->MakeVisible( pToSelect );
2242 UpdateButtonStates();
2246 bool SvxConfigPage::MoveEntryData(
2247 SvTreeListEntry* pSourceEntry, SvTreeListEntry* pTargetEntry )
2249 //modified by shizhoubo for issue53677
2250 if ( NULL == pSourceEntry || NULL == pTargetEntry )
2252 return sal_False;
2255 // Grab the entries list for the currently selected menu
2256 SvxEntries* pEntries = GetTopLevelSelection()->GetEntries();
2258 SvxConfigEntry* pSourceData =
2259 (SvxConfigEntry*) pSourceEntry->GetUserData();
2261 if ( pTargetEntry == NULL )
2263 RemoveEntry( pEntries, pSourceData );
2264 pEntries->insert(
2265 pEntries->begin(), pSourceData );
2267 GetSaveInData()->SetModified( sal_True );
2269 return sal_True;
2271 else
2273 SvxConfigEntry* pTargetData =
2274 (SvxConfigEntry*) pTargetEntry->GetUserData();
2276 if ( pSourceData != NULL && pTargetData != NULL )
2278 // remove the source entry from our list
2279 RemoveEntry( pEntries, pSourceData );
2281 SvxEntries::iterator iter = pEntries->begin();
2282 SvxEntries::const_iterator end = pEntries->end();
2284 // advance the iterator to the position of the target entry
2285 while (*iter != pTargetData && ++iter != end) ;
2287 // insert the source entry at the position after the target
2288 pEntries->insert( ++iter, pSourceData );
2290 GetSaveInData()->SetModified( sal_True );
2292 return sal_True;
2296 return sal_False;
2299 SvxMenuConfigPage::SvxMenuConfigPage(
2300 Window *pParent, const SfxItemSet& rSet )
2302 SvxConfigPage( pParent, rSet )
2304 aContentsListBox = new SvxMenuEntriesListBox( this, CUI_RES( BOX_ENTRIES ) );
2305 FreeResource();
2307 PositionContentsListBox();
2308 aContentsListBox->SetZOrder( &aAddCommandsButton, WINDOW_ZORDER_BEFOR );
2310 aTopLevelListBox.SetSelectHdl(
2311 LINK( this, SvxMenuConfigPage, SelectMenu ) );
2313 aContentsListBox->SetSelectHdl(
2314 LINK( this, SvxMenuConfigPage, SelectMenuEntry ) );
2316 aMoveUpButton.SetClickHdl ( LINK( this, SvxConfigPage, MoveHdl) );
2317 aMoveDownButton.SetClickHdl ( LINK( this, SvxConfigPage, MoveHdl) );
2319 aNewTopLevelButton.SetClickHdl (
2320 LINK( this, SvxMenuConfigPage, NewMenuHdl ) );
2322 aAddCommandsButton.SetClickHdl (
2323 LINK( this, SvxMenuConfigPage, AddCommandsHdl ) );
2325 PopupMenu* pMenu = new PopupMenu( CUI_RES( MODIFY_MENU ) );
2326 pMenu->SetMenuFlags(
2327 pMenu->GetMenuFlags() | MENU_FLAG_ALWAYSSHOWDISABLEDENTRIES );
2329 aModifyTopLevelButton.SetPopupMenu( pMenu );
2330 aModifyTopLevelButton.SetSelectHdl(
2331 LINK( this, SvxMenuConfigPage, MenuSelectHdl ) );
2333 PopupMenu* pEntry = new PopupMenu( CUI_RES( MODIFY_ENTRY ) );
2334 pEntry->SetMenuFlags(
2335 pEntry->GetMenuFlags() | MENU_FLAG_ALWAYSSHOWDISABLEDENTRIES );
2337 aModifyCommandButton.SetPopupMenu( pEntry );
2338 aModifyCommandButton.SetSelectHdl(
2339 LINK( this, SvxMenuConfigPage, EntrySelectHdl ) );
2342 // Populates the Menu combo box
2343 void SvxMenuConfigPage::Init()
2345 // ensure that the UI is cleared before populating it
2346 aTopLevelListBox.Clear();
2347 aContentsListBox->Clear();
2349 ReloadTopLevelListBox();
2351 aTopLevelListBox.SelectEntryPos(0, sal_True);
2352 aTopLevelListBox.GetSelectHdl().Call(this);
2355 SvxMenuConfigPage::~SvxMenuConfigPage()
2357 for ( sal_uInt16 i = 0 ; i < aSaveInListBox.GetEntryCount(); ++i )
2359 MenuSaveInData* pData =
2360 (MenuSaveInData*) aSaveInListBox.GetEntryData( i );
2362 delete pData;
2365 if ( pSelectorDlg != NULL )
2367 delete pSelectorDlg;
2370 delete aContentsListBox;
2373 IMPL_LINK( SvxMenuConfigPage, SelectMenuEntry, Control *, pBox )
2375 (void)pBox;
2377 UpdateButtonStates();
2379 return 1;
2382 void SvxMenuConfigPage::UpdateButtonStates()
2384 PopupMenu* pPopup = aModifyCommandButton.GetPopupMenu();
2386 // Disable Up and Down buttons depending on current selection
2387 SvTreeListEntry* selection = aContentsListBox->GetCurEntry();
2389 if ( aContentsListBox->GetEntryCount() == 0 || selection == NULL )
2391 aMoveUpButton.Enable( sal_False );
2392 aMoveDownButton.Enable( sal_False );
2394 pPopup->EnableItem( ID_BEGIN_GROUP, sal_True );
2395 pPopup->EnableItem( ID_RENAME, sal_False );
2396 pPopup->EnableItem( ID_DELETE, sal_False );
2398 aDescriptionField.Clear();
2400 return;
2403 SvTreeListEntry* first = aContentsListBox->First();
2404 SvTreeListEntry* last = aContentsListBox->Last();
2406 aMoveUpButton.Enable( selection != first );
2407 aMoveDownButton.Enable( selection != last );
2409 SvxConfigEntry* pEntryData =
2410 (SvxConfigEntry*) selection->GetUserData();
2412 if ( pEntryData->IsSeparator() )
2414 pPopup->EnableItem( ID_DELETE, sal_True );
2415 pPopup->EnableItem( ID_BEGIN_GROUP, sal_False );
2416 pPopup->EnableItem( ID_RENAME, sal_False );
2418 aDescriptionField.Clear();
2420 else
2422 pPopup->EnableItem( ID_BEGIN_GROUP, sal_True );
2423 pPopup->EnableItem( ID_DELETE, sal_True );
2424 pPopup->EnableItem( ID_RENAME, sal_True );
2426 aDescriptionField.SetNewText( pEntryData->GetHelpText() );
2430 void SvxMenuConfigPage::DeleteSelectedTopLevel()
2432 SvxConfigEntry* pMenuData = GetTopLevelSelection();
2434 SvxEntries* pParentEntries =
2435 FindParentForChild( GetSaveInData()->GetEntries(), pMenuData );
2437 RemoveEntry( pParentEntries, pMenuData );
2438 delete pMenuData;
2440 ReloadTopLevelListBox();
2442 GetSaveInData()->SetModified( sal_True );
2445 bool SvxMenuConfigPage::DeleteSelectedContent()
2447 SvTreeListEntry *pActEntry = aContentsListBox->FirstSelected();
2449 if ( pActEntry != NULL )
2451 // get currently selected menu entry
2452 SvxConfigEntry* pMenuEntry =
2453 (SvxConfigEntry*) pActEntry->GetUserData();
2455 // get currently selected menu
2456 SvxConfigEntry* pMenu = GetTopLevelSelection();
2458 // remove menu entry from the list for this menu
2459 RemoveEntry( pMenu->GetEntries(), pMenuEntry );
2461 // remove menu entry from UI
2462 aContentsListBox->GetModel()->Remove( pActEntry );
2464 // if this is a submenu entry, redraw the menus list box
2465 if ( pMenuEntry->IsPopup() )
2467 ReloadTopLevelListBox();
2470 // delete data for menu entry
2471 delete pMenuEntry;
2473 GetSaveInData()->SetModified( sal_True );
2475 return sal_True;
2477 return sal_False;
2480 short SvxMenuConfigPage::QueryReset()
2482 String msg =
2483 String( CUI_RES( RID_SVXSTR_CONFIRM_MENU_RESET ) );
2485 String saveInName = aSaveInListBox.GetEntry(
2486 aSaveInListBox.GetSelectEntryPos() );
2488 OUString label = replaceSaveInName( msg, saveInName );
2490 QueryBox qbox( this, WB_YES_NO, label );
2492 return qbox.Execute();
2495 IMPL_LINK( SvxMenuConfigPage, SelectMenu, ListBox *, pBox )
2497 (void)pBox;
2499 aContentsListBox->Clear();
2501 SvxConfigEntry* pMenuData = GetTopLevelSelection();
2503 PopupMenu* pPopup = aModifyTopLevelButton.GetPopupMenu();
2504 if ( pMenuData )
2506 pPopup->EnableItem( ID_DELETE, pMenuData->IsDeletable() );
2507 pPopup->EnableItem( ID_RENAME, pMenuData->IsRenamable() );
2508 pPopup->EnableItem( ID_MOVE, pMenuData->IsMovable() );
2510 SvxEntries* pEntries = pMenuData->GetEntries();
2511 SvxEntries::const_iterator iter = pEntries->begin();
2513 for ( ; iter != pEntries->end(); ++iter )
2515 SvxConfigEntry* pEntry = *iter;
2516 InsertEntryIntoUI( pEntry );
2520 UpdateButtonStates();
2522 return 0;
2525 IMPL_LINK( SvxMenuConfigPage, MenuSelectHdl, MenuButton *, pButton )
2527 switch( pButton->GetCurItemId() )
2529 case ID_DELETE:
2531 DeleteSelectedTopLevel();
2532 break;
2534 case ID_RENAME:
2536 SvxConfigEntry* pMenuData = GetTopLevelSelection();
2538 String aNewName( stripHotKey( pMenuData->GetName() ) );
2539 String aDesc = CUI_RESSTR( RID_SVXSTR_LABEL_NEW_NAME );
2541 SvxNameDialog* pNameDialog = new SvxNameDialog( this, aNewName, aDesc );
2542 pNameDialog->SetHelpId( HID_SVX_CONFIG_RENAME_MENU );
2543 pNameDialog->SetText( CUI_RESSTR( RID_SVXSTR_RENAME_MENU ) );
2545 bool ret = pNameDialog->Execute();
2547 if ( ret == RET_OK ) {
2548 pNameDialog->GetName( aNewName );
2549 pMenuData->SetName( aNewName );
2551 ReloadTopLevelListBox();
2553 GetSaveInData()->SetModified( sal_True );
2556 // #i68101# Memory leak (!)
2557 delete pNameDialog;
2559 break;
2561 case ID_MOVE:
2563 SvxConfigEntry* pMenuData = GetTopLevelSelection();
2565 SvxMainMenuOrganizerDialog* pDialog =
2566 new SvxMainMenuOrganizerDialog( this,
2567 GetSaveInData()->GetEntries(), pMenuData );
2569 bool ret = pDialog->Execute();
2571 if ( ret == RET_OK )
2573 GetSaveInData()->SetEntries( pDialog->GetEntries() );
2575 ReloadTopLevelListBox( pDialog->GetSelectedEntry() );
2577 GetSaveInData()->SetModified( sal_True );
2580 delete pDialog;
2582 break;
2584 default:
2585 return sal_False;
2587 return sal_True;
2590 IMPL_LINK( SvxMenuConfigPage, EntrySelectHdl, MenuButton *, pButton )
2592 switch( pButton->GetCurItemId() )
2594 case ID_ADD_SUBMENU:
2596 String aNewName;
2597 String aDesc = CUI_RESSTR( RID_SVXSTR_SUBMENU_NAME );
2599 SvxNameDialog* pNameDialog = new SvxNameDialog( this, aNewName, aDesc );
2600 pNameDialog->SetHelpId( HID_SVX_CONFIG_NAME_SUBMENU );
2601 pNameDialog->SetText( CUI_RESSTR( RID_SVXSTR_ADD_SUBMENU ) );
2603 bool ret = pNameDialog->Execute();
2605 if ( ret == RET_OK ) {
2606 pNameDialog->GetName(aNewName);
2608 SvxConfigEntry* pNewEntryData =
2609 new SvxConfigEntry( aNewName, aNewName, sal_True );
2610 pNewEntryData->SetUserDefined( sal_True );
2612 InsertEntry( pNewEntryData );
2614 ReloadTopLevelListBox();
2616 GetSaveInData()->SetModified( sal_True );
2619 delete pNameDialog;
2621 break;
2623 case ID_BEGIN_GROUP:
2625 SvxConfigEntry* pNewEntryData = new SvxConfigEntry;
2626 pNewEntryData->SetUserDefined( sal_True );
2627 InsertEntry( pNewEntryData );
2629 break;
2631 case ID_DELETE:
2633 DeleteSelectedContent();
2634 break;
2636 case ID_RENAME:
2638 SvTreeListEntry* pActEntry = aContentsListBox->GetCurEntry();
2639 SvxConfigEntry* pEntry =
2640 (SvxConfigEntry*) pActEntry->GetUserData();
2642 String aNewName( stripHotKey( pEntry->GetName() ) );
2643 String aDesc = CUI_RESSTR( RID_SVXSTR_LABEL_NEW_NAME );
2645 SvxNameDialog* pNameDialog = new SvxNameDialog( this, aNewName, aDesc );
2646 pNameDialog->SetHelpId( HID_SVX_CONFIG_RENAME_MENU_ITEM );
2647 pNameDialog->SetText( CUI_RESSTR( RID_SVXSTR_RENAME_MENU ) );
2649 bool ret = pNameDialog->Execute();
2651 if ( ret == RET_OK ) {
2652 pNameDialog->GetName(aNewName);
2654 pEntry->SetName( aNewName );
2655 aContentsListBox->SetEntryText( pActEntry, aNewName );
2657 GetSaveInData()->SetModified( sal_True );
2660 delete pNameDialog;
2662 break;
2664 default:
2666 return sal_False;
2670 if ( GetSaveInData()->IsModified() )
2672 UpdateButtonStates();
2675 return sal_True;
2678 IMPL_LINK( SvxMenuConfigPage, AddFunctionHdl,
2679 SvxScriptSelectorDialog *, pDialog )
2681 (void)pDialog;
2683 AddFunction();
2685 return 0;
2688 IMPL_LINK( SvxMenuConfigPage, NewMenuHdl, Button *, pButton )
2690 (void)pButton;
2692 SvxMainMenuOrganizerDialog* pDialog =
2693 new SvxMainMenuOrganizerDialog( 0,
2694 GetSaveInData()->GetEntries(), NULL, sal_True );
2696 bool ret = pDialog->Execute();
2698 if ( ret == RET_OK )
2700 GetSaveInData()->SetEntries( pDialog->GetEntries() );
2701 ReloadTopLevelListBox( pDialog->GetSelectedEntry() );
2702 GetSaveInData()->SetModified( sal_True );
2705 delete pDialog;
2707 return 0;
2710 IMPL_LINK( SvxMenuConfigPage, AddCommandsHdl, Button *, pButton )
2712 (void)pButton;
2714 if ( pSelectorDlg == NULL )
2716 // Create Script Selector which also shows builtin commands
2717 pSelectorDlg = new SvxScriptSelectorDialog( this, sal_True, m_xFrame );
2719 pSelectorDlg->SetAddHdl(
2720 LINK( this, SvxMenuConfigPage, AddFunctionHdl ) );
2722 pSelectorDlg->SetDialogDescription( String(
2723 CUI_RES( RID_SVXSTR_MENU_ADDCOMMANDS_DESCRIPTION ) ) );
2726 // Position the Script Selector over the Add button so it is
2727 // beside the menu contents list and does not obscure it
2728 pSelectorDlg->SetPosPixel( aAddCommandsButton.GetPosPixel() );
2730 pSelectorDlg->SetImageProvider(
2731 static_cast< ImageProvider* >( GetSaveInData() ) );
2733 pSelectorDlg->Show();
2734 return 1;
2737 SaveInData* SvxMenuConfigPage::CreateSaveInData(
2738 const uno::Reference< css::ui::XUIConfigurationManager >& xCfgMgr,
2739 const uno::Reference< css::ui::XUIConfigurationManager >& xParentCfgMgr,
2740 const OUString& aModuleId,
2741 bool bDocConfig )
2743 return static_cast< SaveInData* >(
2744 new MenuSaveInData( xCfgMgr, xParentCfgMgr, aModuleId, bDocConfig ));
2747 SvxMainMenuOrganizerDialog::SvxMainMenuOrganizerDialog(
2748 Window* pParent, SvxEntries* entries,
2749 SvxConfigEntry* selection, bool bCreateMenu )
2751 ModalDialog( pParent, CUI_RES( MD_MENU_ORGANISER ) ),
2752 aMenuNameText( this, CUI_RES( TXT_MENU_NAME ) ),
2753 aMenuNameEdit( this, CUI_RES( EDIT_MENU_NAME ) ),
2754 aMenuListText( this, CUI_RES( TXT_MENU ) ),
2755 aMenuListBox( this, CUI_RES( BOX_MAIN_MENUS ) ),
2756 aMoveUpButton( this, CUI_RES( BTN_MENU_UP ) ),
2757 aMoveDownButton( this, CUI_RES( BTN_MENU_DOWN ) ),
2758 aOKButton( this, CUI_RES( BTN_MENU_ADD ) ),
2759 aCloseButton( this, CUI_RES( BTN_MENU_CLOSE ) ),
2760 aHelpButton( this, CUI_RES( BTN_MENU_HELP ) ),
2761 bModified( sal_False )
2763 FreeResource();
2765 // Copy the entries list passed in
2766 if ( entries != NULL )
2768 SvxConfigEntry* pEntry;
2769 SvTreeListEntry* pLBEntry;
2771 pEntries = new SvxEntries();
2772 SvxEntries::const_iterator iter = entries->begin();
2774 while ( iter != entries->end() )
2776 pEntry = *iter;
2777 pLBEntry =
2778 aMenuListBox.InsertEntry( stripHotKey( pEntry->GetName() ) );
2779 pLBEntry->SetUserData( pEntry );
2780 pEntries->push_back( pEntry );
2782 if ( pEntry == selection )
2784 aMenuListBox.Select( pLBEntry );
2786 ++iter;
2790 if ( bCreateMenu )
2792 // Generate custom name for new menu
2793 String prefix =
2794 String( CUI_RES( RID_SVXSTR_NEW_MENU ) );
2796 OUString newname = generateCustomName( prefix, entries );
2797 OUString newurl = generateCustomMenuURL( pEntries );
2799 SvxConfigEntry* pNewEntryData =
2800 new SvxConfigEntry( newname, newurl, sal_True );
2801 pNewEntryData->SetUserDefined( sal_True );
2802 pNewEntryData->SetMain( sal_True );
2804 pNewMenuEntry =
2805 aMenuListBox.InsertEntry( stripHotKey( pNewEntryData->GetName() ) );
2806 aMenuListBox.Select( pNewMenuEntry );
2808 pNewMenuEntry->SetUserData( pNewEntryData );
2810 pEntries->push_back( pNewEntryData );
2812 aMenuNameEdit.SetText( newname );
2813 aMenuNameEdit.SetModifyHdl(
2814 LINK( this, SvxMainMenuOrganizerDialog, ModifyHdl ) );
2816 else
2818 Point p, newp;
2819 Size s, news;
2821 // get offset to bottom of name textfield from top of dialog
2822 p = aMenuNameEdit.GetPosPixel();
2823 s = aMenuNameEdit.GetSizePixel();
2824 long offset = p.Y() + s.Height();
2826 // reposition menu list and label
2827 aMenuListText.SetPosPixel( aMenuNameText.GetPosPixel() );
2828 aMenuListBox.SetPosPixel( aMenuNameEdit.GetPosPixel() );
2830 // reposition up and down buttons
2831 p = aMoveUpButton.GetPosPixel();
2832 newp = Point( p.X(), p.Y() - offset );
2833 aMoveUpButton.SetPosPixel( newp );
2835 p = aMoveDownButton.GetPosPixel();
2836 newp = Point( p.X(), p.Y() - offset );
2837 aMoveDownButton.SetPosPixel( newp );
2839 // change size of dialog
2840 s = GetSizePixel();
2841 news = Size( s.Width(), s.Height() - offset );
2842 SetSizePixel( news );
2844 // hide name label and textfield
2845 aMenuNameText.Hide();
2846 aMenuNameEdit.Hide();
2848 // change the title
2849 SetText( CUI_RES( RID_SVXSTR_MOVE_MENU ) );
2852 aMenuListBox.SetSelectHdl(
2853 LINK( this, SvxMainMenuOrganizerDialog, SelectHdl ) );
2855 aMoveUpButton.SetClickHdl (
2856 LINK( this, SvxMainMenuOrganizerDialog, MoveHdl) );
2857 aMoveDownButton.SetClickHdl (
2858 LINK( this, SvxMainMenuOrganizerDialog, MoveHdl) );
2860 aMoveUpButton.SetAccessibleName(String(CUI_RES(BUTTON_STR_UP)));
2861 aMoveDownButton.SetAccessibleName(String(CUI_RES(BUTTON_STR_DOWN)));
2864 IMPL_LINK(SvxMainMenuOrganizerDialog, ModifyHdl, Edit*, pEdit)
2866 (void)pEdit;
2868 // if the Edit control is empty do not change the name
2869 if ( aMenuNameEdit.GetText() == "" )
2871 return 0;
2874 SvxConfigEntry* pNewEntryData =
2875 (SvxConfigEntry*) pNewMenuEntry->GetUserData();
2877 pNewEntryData->SetName( aMenuNameEdit.GetText() );
2879 aMenuListBox.SetEntryText( pNewMenuEntry, pNewEntryData->GetName() );
2881 return 0;
2884 SvxMainMenuOrganizerDialog::~SvxMainMenuOrganizerDialog()
2888 IMPL_LINK( SvxMainMenuOrganizerDialog, SelectHdl, Control*, pCtrl )
2890 (void)pCtrl;
2891 UpdateButtonStates();
2892 return 1;
2895 void SvxMainMenuOrganizerDialog::UpdateButtonStates()
2897 // Disable Up and Down buttons depending on current selection
2898 SvTreeListEntry* selection = aMenuListBox.GetCurEntry();
2899 SvTreeListEntry* first = aMenuListBox.First();
2900 SvTreeListEntry* last = aMenuListBox.Last();
2902 aMoveUpButton.Enable( selection != first );
2903 aMoveDownButton.Enable( selection != last );
2906 IMPL_LINK( SvxMainMenuOrganizerDialog, MoveHdl, Button *, pButton )
2908 SvTreeListEntry *pSourceEntry = aMenuListBox.FirstSelected();
2909 SvTreeListEntry *pTargetEntry = NULL;
2911 if ( !pSourceEntry )
2913 return 0;
2916 if ( pButton == &aMoveDownButton )
2918 pTargetEntry = aMenuListBox.NextSibling( pSourceEntry );
2920 else if ( pButton == &aMoveUpButton )
2922 // Move Up is just a Move Down with the source and target reversed
2923 pTargetEntry = pSourceEntry;
2924 pSourceEntry = aMenuListBox.PrevSibling( pTargetEntry );
2927 if ( pSourceEntry != NULL && pTargetEntry != NULL )
2929 SvxConfigEntry* pSourceData =
2930 (SvxConfigEntry*) pSourceEntry->GetUserData();
2931 SvxConfigEntry* pTargetData =
2932 (SvxConfigEntry*) pTargetEntry->GetUserData();
2934 SvxEntries::iterator iter1 = GetEntries()->begin();
2935 SvxEntries::iterator iter2 = GetEntries()->begin();
2936 SvxEntries::const_iterator end = GetEntries()->end();
2938 // Advance the iterators to the positions of the source and target
2939 while (*iter1 != pSourceData && ++iter1 != end) ;
2940 while (*iter2 != pTargetData && ++iter2 != end) ;
2942 // Now swap the entries in the menu list and in the UI
2943 if ( iter1 != end && iter2 != end )
2945 std::swap( *iter1, *iter2 );
2946 aMenuListBox.GetModel()->Move( pSourceEntry, pTargetEntry );
2947 aMenuListBox.MakeVisible( pSourceEntry );
2949 bModified = sal_True;
2953 if ( bModified )
2955 UpdateButtonStates();
2958 return 0;
2961 SvxEntries* SvxMainMenuOrganizerDialog::GetEntries()
2963 return pEntries;
2966 SvxConfigEntry* SvxMainMenuOrganizerDialog::GetSelectedEntry()
2968 return (SvxConfigEntry*)aMenuListBox.FirstSelected()->GetUserData();
2971 const OUString&
2972 SvxConfigEntry::GetHelpText()
2974 if ( aHelpText.isEmpty() )
2976 if ( !aCommand.isEmpty() )
2978 aHelpText = Application::GetHelp()->GetHelpText( aCommand, NULL );
2982 return aHelpText;
2985 SvxConfigEntry::SvxConfigEntry( const OUString& rDisplayName,
2986 const OUString& rCommandURL, bool bPopup, bool bParentData )
2987 : nId( 1 )
2988 , aLabel(rDisplayName)
2989 , aCommand(rCommandURL)
2990 , bPopUp(bPopup)
2991 , bStrEdited( sal_False )
2992 , bIsUserDefined( sal_False )
2993 , bIsMain( sal_False )
2994 , bIsParentData( bParentData )
2995 , bIsVisible( sal_True )
2996 , nStyle( 0 )
2997 , pEntries( 0 )
2999 if (bPopUp)
3001 pEntries = new SvxEntries();
3005 SvxConfigEntry::~SvxConfigEntry()
3007 if ( pEntries != NULL )
3009 SvxEntries::const_iterator iter = pEntries->begin();
3011 for ( ; iter != pEntries->end(); ++iter )
3013 delete *iter;
3015 delete pEntries;
3019 bool SvxConfigEntry::IsMovable()
3021 if ( IsPopup() && !IsMain() )
3023 return sal_False;
3025 return sal_True;
3028 bool SvxConfigEntry::IsDeletable()
3030 if ( IsMain() && !IsUserDefined() )
3032 return sal_False;
3034 return sal_True;
3037 bool SvxConfigEntry::IsRenamable()
3039 if ( IsMain() && !IsUserDefined() )
3041 return sal_False;
3043 return sal_True;
3046 SvxToolbarConfigPage::SvxToolbarConfigPage(
3047 Window *pParent, const SfxItemSet& rSet )
3049 SvxConfigPage( pParent, rSet )
3051 SetHelpId( HID_SVX_CONFIG_TOOLBAR );
3053 aContentsListBox = new SvxToolbarEntriesListBox(this, CUI_RES(BOX_ENTRIES));
3054 FreeResource();
3055 PositionContentsListBox();
3056 aContentsListBox->SetZOrder( &aAddCommandsButton, WINDOW_ZORDER_BEFOR );
3058 aContentsListBox->SetHelpId( HID_SVX_CONFIG_TOOLBAR_CONTENTS );
3059 aNewTopLevelButton.SetHelpId( HID_SVX_NEW_TOOLBAR );
3060 aModifyTopLevelButton.SetHelpId( HID_SVX_MODIFY_TOOLBAR );
3061 aAddCommandsButton.SetHelpId( HID_SVX_NEW_TOOLBAR_ITEM );
3062 aModifyCommandButton.SetHelpId( HID_SVX_MODIFY_TOOLBAR_ITEM );
3063 aSaveInListBox.SetHelpId( HID_SVX_SAVE_IN );
3065 aTopLevelSeparator.SetText(
3066 CUI_RES ( RID_SVXSTR_PRODUCTNAME_TOOLBARS ) );
3068 aTopLevelLabel.SetText( CUI_RES( RID_SVXSTR_TOOLBAR ) );
3069 aModifyTopLevelButton.SetText( CUI_RES( RID_SVXSTR_TOOLBAR ) );
3070 aContentsSeparator.SetText( CUI_RES( RID_SVXSTR_TOOLBAR_CONTENT ) );
3071 aContentsLabel.SetText( CUI_RES( RID_SVXSTR_COMMANDS ) );
3073 aTopLevelListBox.SetSelectHdl(
3074 LINK( this, SvxToolbarConfigPage, SelectToolbar ) );
3075 aContentsListBox->SetSelectHdl(
3076 LINK( this, SvxToolbarConfigPage, SelectToolbarEntry ) );
3078 aNewTopLevelButton.SetClickHdl (
3079 LINK( this, SvxToolbarConfigPage, NewToolbarHdl ) );
3081 aAddCommandsButton.SetClickHdl (
3082 LINK( this, SvxToolbarConfigPage, AddCommandsHdl ) );
3084 aMoveUpButton.SetClickHdl ( LINK( this, SvxToolbarConfigPage, MoveHdl) );
3085 aMoveDownButton.SetClickHdl ( LINK( this, SvxToolbarConfigPage, MoveHdl) );
3086 // Always enable Up and Down buttons
3087 // added for issue i53677 by shizhoubo
3088 aMoveDownButton.Enable( sal_True );
3089 aMoveUpButton.Enable( sal_True );
3091 PopupMenu* pMenu = new PopupMenu( CUI_RES( MODIFY_TOOLBAR ) );
3092 pMenu->SetMenuFlags(
3093 pMenu->GetMenuFlags() | MENU_FLAG_ALWAYSSHOWDISABLEDENTRIES );
3095 aModifyTopLevelButton.SetPopupMenu( pMenu );
3096 aModifyTopLevelButton.SetSelectHdl(
3097 LINK( this, SvxToolbarConfigPage, ToolbarSelectHdl ) );
3099 PopupMenu* pEntry = new PopupMenu(
3100 CUI_RES( MODIFY_TOOLBAR_CONTENT ) );
3101 pEntry->SetMenuFlags(
3102 pEntry->GetMenuFlags() | MENU_FLAG_ALWAYSSHOWDISABLEDENTRIES );
3104 aModifyCommandButton.SetPopupMenu( pEntry );
3105 aModifyCommandButton.SetSelectHdl(
3106 LINK( this, SvxToolbarConfigPage, EntrySelectHdl ) );
3108 // default toolbar to select is standardbar unless a different one
3109 // has been passed in
3110 m_aURLToSelect = OUString(ITEM_TOOLBAR_URL );
3111 m_aURLToSelect += "standardbar";
3113 const SfxPoolItem* pItem =
3114 rSet.GetItem( rSet.GetPool()->GetWhich( SID_CONFIG ) );
3116 if ( pItem )
3118 OUString text = ((const SfxStringItem*)pItem)->GetValue();
3119 if (text.indexOf( ITEM_TOOLBAR_URL ) == 0)
3121 m_aURLToSelect = text.copy( 0 );
3125 long nTxtW = aTopLevelLabel.GetCtrlTextWidth( aTopLevelLabel.GetText() );
3126 long nCtrlW = aTopLevelLabel.GetSizePixel().Width();
3127 if ( nTxtW >= nCtrlW )
3129 long nDelta = std::max( (long)10, nTxtW - nCtrlW );
3130 Size aNewSz = aTopLevelLabel.GetSizePixel();
3131 aNewSz.Width() += nDelta;
3132 aTopLevelLabel.SetSizePixel( aNewSz );
3133 aNewSz = aTopLevelListBox.GetSizePixel();
3134 aNewSz.Width() -= nDelta;
3135 Point aNewPt = aTopLevelListBox.GetPosPixel();
3136 aNewPt.X() += nDelta;
3137 aTopLevelListBox.SetPosSizePixel( aNewPt, aNewSz );
3141 SvxToolbarConfigPage::~SvxToolbarConfigPage()
3143 for ( sal_uInt16 i = 0 ; i < aSaveInListBox.GetEntryCount(); ++i )
3145 ToolbarSaveInData* pData =
3146 (ToolbarSaveInData*) aSaveInListBox.GetEntryData( i );
3148 delete pData;
3151 if ( pSelectorDlg != NULL )
3153 delete pSelectorDlg;
3157 delete aContentsListBox;
3160 void SvxToolbarConfigPage::DeleteSelectedTopLevel()
3162 sal_uInt16 nSelectionPos = aTopLevelListBox.GetSelectEntryPos();
3163 ToolbarSaveInData* pSaveInData = (ToolbarSaveInData*) GetSaveInData();
3164 pSaveInData->RemoveToolbar( GetTopLevelSelection() );
3166 if ( aTopLevelListBox.GetEntryCount() > 1 )
3168 // select next entry after the one being deleted
3169 // selection position is indexed from 0 so need to
3170 // subtract one from the entry count
3171 if ( nSelectionPos != aTopLevelListBox.GetEntryCount() - 1 )
3173 aTopLevelListBox.SelectEntryPos( nSelectionPos + 1, sal_True );
3175 else
3177 aTopLevelListBox.SelectEntryPos( nSelectionPos - 1, sal_True );
3179 aTopLevelListBox.GetSelectHdl().Call( this );
3181 // and now remove the entry
3182 aTopLevelListBox.RemoveEntry( nSelectionPos );
3184 else
3186 ReloadTopLevelListBox();
3190 bool SvxToolbarConfigPage::DeleteSelectedContent()
3192 SvTreeListEntry *pActEntry = aContentsListBox->FirstSelected();
3194 if ( pActEntry != NULL )
3196 // get currently selected entry
3197 SvxConfigEntry* pEntry =
3198 (SvxConfigEntry*) pActEntry->GetUserData();
3200 SvxConfigEntry* pToolbar = GetTopLevelSelection();
3202 // remove entry from the list for this toolbar
3203 RemoveEntry( pToolbar->GetEntries(), pEntry );
3205 // remove toolbar entry from UI
3206 aContentsListBox->GetModel()->Remove( pActEntry );
3208 // delete data for toolbar entry
3209 delete pEntry;
3211 (( ToolbarSaveInData* ) GetSaveInData())->ApplyToolbar( pToolbar );
3212 UpdateButtonStates();
3214 // if this is the last entry in the toolbar and it is a user
3215 // defined toolbar pop up a dialog asking the user if they
3216 // want to delete the toolbar
3217 if ( aContentsListBox->GetEntryCount() == 0 &&
3218 GetTopLevelSelection()->IsDeletable() )
3220 QueryBox qbox( this,
3221 CUI_RES( QBX_CONFIRM_DELETE_TOOLBAR ) );
3223 if ( qbox.Execute() == RET_YES )
3225 DeleteSelectedTopLevel();
3229 return sal_True;
3232 return sal_False;
3235 IMPL_LINK( SvxToolbarConfigPage, MoveHdl, Button *, pButton )
3237 MoveEntry( pButton == &aMoveUpButton );
3238 return 0;
3241 void SvxToolbarConfigPage::MoveEntry( bool bMoveUp )
3243 SvxConfigPage::MoveEntry( bMoveUp );
3245 // Apply change to currently selected toolbar
3246 SvxConfigEntry* pToolbar = GetTopLevelSelection();
3247 if ( pToolbar )
3248 ((ToolbarSaveInData*)GetSaveInData())->ApplyToolbar( pToolbar );
3249 else
3251 SAL_WARN( "cui.customize", "SvxToolbarConfigPage::MoveEntry(): no entry" );
3252 UpdateButtonStates();
3256 IMPL_LINK( SvxToolbarConfigPage, ToolbarSelectHdl, MenuButton *, pButton )
3258 sal_uInt16 nSelectionPos = aTopLevelListBox.GetSelectEntryPos();
3260 SvxConfigEntry* pToolbar =
3261 (SvxConfigEntry*)aTopLevelListBox.GetEntryData( nSelectionPos );
3263 ToolbarSaveInData* pSaveInData = (ToolbarSaveInData*) GetSaveInData();
3265 switch( pButton->GetCurItemId() )
3267 case ID_DELETE:
3269 DeleteSelectedTopLevel();
3270 UpdateButtonStates();
3271 break;
3273 case ID_RENAME:
3275 String aNewName( stripHotKey( pToolbar->GetName() ) );
3276 String aDesc = CUI_RESSTR( RID_SVXSTR_LABEL_NEW_NAME );
3278 SvxNameDialog* pNameDialog = new SvxNameDialog( this, aNewName, aDesc );
3279 pNameDialog->SetHelpId( HID_SVX_CONFIG_RENAME_TOOLBAR );
3280 pNameDialog->SetText( CUI_RESSTR( RID_SVXSTR_RENAME_TOOLBAR ) );
3282 bool ret = pNameDialog->Execute();
3284 if ( ret == RET_OK )
3286 pNameDialog->GetName(aNewName);
3288 pToolbar->SetName( aNewName );
3289 pSaveInData->ApplyToolbar( pToolbar );
3291 // have to use remove and insert to change the name
3292 aTopLevelListBox.RemoveEntry( nSelectionPos );
3293 nSelectionPos =
3294 aTopLevelListBox.InsertEntry( aNewName, nSelectionPos );
3295 aTopLevelListBox.SetEntryData( nSelectionPos, pToolbar );
3296 aTopLevelListBox.SelectEntryPos( nSelectionPos );
3299 delete pNameDialog;
3301 break;
3303 case ID_DEFAULT_STYLE:
3305 QueryBox qbox( this,
3306 CUI_RES( QBX_CONFIRM_RESTORE_DEFAULT ) );
3308 if ( qbox.Execute() == RET_YES )
3310 ToolbarSaveInData* pSaveInData_ =
3311 (ToolbarSaveInData*) GetSaveInData();
3313 pSaveInData_->RestoreToolbar( pToolbar );
3315 aTopLevelListBox.GetSelectHdl().Call( this );
3318 break;
3320 case ID_ICONS_ONLY:
3322 pToolbar->SetStyle( 0 );
3323 pSaveInData->SetSystemStyle( m_xFrame, pToolbar->GetCommand(), 0 );
3325 aTopLevelListBox.GetSelectHdl().Call( this );
3327 break;
3329 case ID_TEXT_ONLY:
3331 pToolbar->SetStyle( 1 );
3332 pSaveInData->SetSystemStyle( m_xFrame, pToolbar->GetCommand(), 1 );
3334 aTopLevelListBox.GetSelectHdl().Call( this );
3336 break;
3338 case ID_ICONS_AND_TEXT:
3340 pToolbar->SetStyle( 2 );
3341 pSaveInData->SetSystemStyle( m_xFrame, pToolbar->GetCommand(), 2 );
3343 aTopLevelListBox.GetSelectHdl().Call( this );
3345 break;
3348 return 1;
3351 IMPL_LINK( SvxToolbarConfigPage, EntrySelectHdl, MenuButton *, pButton )
3353 bool bNeedsApply = sal_False;
3355 // get currently selected toolbar
3356 SvxConfigEntry* pToolbar = GetTopLevelSelection();
3358 switch( pButton->GetCurItemId() )
3360 case ID_RENAME:
3362 SvTreeListEntry* pActEntry = aContentsListBox->GetCurEntry();
3363 SvxConfigEntry* pEntry =
3364 (SvxConfigEntry*) pActEntry->GetUserData();
3366 String aNewName( stripHotKey( pEntry->GetName() ) );
3367 String aDesc = CUI_RESSTR( RID_SVXSTR_LABEL_NEW_NAME );
3369 SvxNameDialog* pNameDialog = new SvxNameDialog( this, aNewName, aDesc );
3370 pNameDialog->SetHelpId( HID_SVX_CONFIG_RENAME_TOOLBAR_ITEM );
3371 pNameDialog->SetText( CUI_RESSTR( RID_SVXSTR_RENAME_TOOLBAR ) );
3373 bool ret = pNameDialog->Execute();
3375 if ( ret == RET_OK ) {
3376 pNameDialog->GetName(aNewName);
3378 pEntry->SetName( aNewName );
3379 aContentsListBox->SetEntryText( pActEntry, aNewName );
3381 bNeedsApply = sal_True;
3384 delete pNameDialog;
3385 break;
3387 case ID_DEFAULT_COMMAND:
3389 SvTreeListEntry* pActEntry = aContentsListBox->GetCurEntry();
3390 SvxConfigEntry* pEntry =
3391 (SvxConfigEntry*) pActEntry->GetUserData();
3393 sal_uInt16 nSelectionPos = 0;
3395 // find position of entry within the list
3396 for ( sal_uInt16 i = 0; i < aContentsListBox->GetEntryCount(); ++i )
3398 if ( aContentsListBox->GetEntry( 0, i ) == pActEntry )
3400 nSelectionPos = i;
3401 break;
3405 ToolbarSaveInData* pSaveInData =
3406 (ToolbarSaveInData*) GetSaveInData();
3408 OUString aSystemName =
3409 pSaveInData->GetSystemUIName( pEntry->GetCommand() );
3411 if ( !pEntry->GetName().equals( aSystemName ) )
3413 pEntry->SetName( aSystemName );
3414 aContentsListBox->SetEntryText(
3415 pActEntry, stripHotKey( aSystemName ) );
3416 bNeedsApply = sal_True;
3419 uno::Sequence< OUString > aURLSeq( 1 );
3420 aURLSeq[ 0 ] = pEntry->GetCommand();
3424 GetSaveInData()->GetImageManager()->removeImages(
3425 GetImageType(), aURLSeq );
3427 // reset backup in entry
3428 pEntry->SetBackupGraphic(
3429 uno::Reference< graphic::XGraphic >() );
3431 GetSaveInData()->PersistChanges(
3432 GetSaveInData()->GetImageManager() );
3434 aContentsListBox->GetModel()->Remove( pActEntry );
3436 SvTreeListEntry* pNewLBEntry =
3437 InsertEntryIntoUI( pEntry, nSelectionPos );
3439 aContentsListBox->SetCheckButtonState( pNewLBEntry,
3440 pEntry->IsVisible() ?
3441 SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
3443 aContentsListBox->Select( pNewLBEntry );
3444 aContentsListBox->MakeVisible( pNewLBEntry );
3446 bNeedsApply = sal_True;
3448 catch ( uno::Exception& )
3450 OSL_TRACE("Error restoring image");
3452 break;
3454 case ID_BEGIN_GROUP:
3456 SvxConfigEntry* pNewEntryData = new SvxConfigEntry;
3457 pNewEntryData->SetUserDefined( sal_True );
3459 SvTreeListEntry* pNewLBEntry = InsertEntry( pNewEntryData );
3461 aContentsListBox->SetCheckButtonState(
3462 pNewLBEntry, SV_BUTTON_TRISTATE );
3464 bNeedsApply = sal_True;
3465 break;
3467 case ID_DELETE:
3469 DeleteSelectedContent();
3470 break;
3472 case ID_ICON_ONLY:
3474 break;
3476 case ID_TEXT_ONLY:
3478 break;
3480 case ID_ICON_AND_TEXT:
3482 break;
3484 case ID_CHANGE_SYMBOL:
3486 SvTreeListEntry* pActEntry = aContentsListBox->GetCurEntry();
3487 SvxConfigEntry* pEntry =
3488 (SvxConfigEntry*) pActEntry->GetUserData();
3490 sal_uInt16 nSelectionPos = 0;
3492 // find position of entry within the list
3493 for ( sal_uInt16 i = 0; i < aContentsListBox->GetEntryCount(); ++i )
3495 if ( aContentsListBox->GetEntry( 0, i ) == pActEntry )
3497 nSelectionPos = i;
3498 break;
3502 SvxIconSelectorDialog* pIconDialog =
3503 new SvxIconSelectorDialog( 0,
3504 GetSaveInData()->GetImageManager(),
3505 GetSaveInData()->GetParentImageManager() );
3507 bool ret = pIconDialog->Execute();
3509 if ( ret == RET_OK )
3511 uno::Reference< graphic::XGraphic > newgraphic =
3512 pIconDialog->GetSelectedIcon();
3514 if ( newgraphic.is() )
3516 uno::Sequence< uno::Reference< graphic::XGraphic > >
3517 aGraphicSeq( 1 );
3519 uno::Sequence< OUString > aURLSeq( 1 );
3520 aURLSeq[ 0 ] = pEntry->GetCommand();
3522 if ( !pEntry->GetBackupGraphic().is() )
3524 uno::Reference< graphic::XGraphic > backup;
3525 backup = GetGraphic(
3526 GetSaveInData()->GetImageManager(), aURLSeq[ 0 ] );
3528 if ( backup.is() )
3530 pEntry->SetBackupGraphic( backup );
3534 aGraphicSeq[ 0 ] = newgraphic;
3537 GetSaveInData()->GetImageManager()->replaceImages(
3538 GetImageType(), aURLSeq, aGraphicSeq );
3540 Image aImage( newgraphic );
3542 aContentsListBox->GetModel()->Remove( pActEntry );
3543 SvTreeListEntry* pNewLBEntry =
3544 InsertEntryIntoUI( pEntry, nSelectionPos );
3546 aContentsListBox->SetCheckButtonState( pNewLBEntry,
3547 pEntry->IsVisible() ?
3548 SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
3550 aContentsListBox->Select( pNewLBEntry );
3551 aContentsListBox->MakeVisible( pNewLBEntry );
3553 GetSaveInData()->PersistChanges(
3554 GetSaveInData()->GetImageManager() );
3556 catch ( uno::Exception& )
3558 OSL_TRACE("Error replacing image");
3563 delete pIconDialog;
3565 break;
3567 case ID_RESET_SYMBOL:
3569 SvTreeListEntry* pActEntry = aContentsListBox->GetCurEntry();
3570 SvxConfigEntry* pEntry =
3571 (SvxConfigEntry*) pActEntry->GetUserData();
3573 sal_uInt16 nSelectionPos = 0;
3575 // find position of entry within the list
3576 for ( sal_uInt16 i = 0; i < aContentsListBox->GetEntryCount(); ++i )
3578 if ( aContentsListBox->GetEntry( 0, i ) == pActEntry )
3580 nSelectionPos = i;
3581 break;
3585 uno::Reference< graphic::XGraphic > backup =
3586 pEntry->GetBackupGraphic();
3588 uno::Sequence< uno::Reference< graphic::XGraphic > >
3589 aGraphicSeq( 1 );
3590 aGraphicSeq[ 0 ] = backup;
3592 uno::Sequence< OUString > aURLSeq( 1 );
3593 aURLSeq[ 0 ] = pEntry->GetCommand();
3597 GetSaveInData()->GetImageManager()->replaceImages(
3598 GetImageType(), aURLSeq, aGraphicSeq );
3600 Image aImage( backup );
3601 aContentsListBox->GetModel()->Remove( pActEntry );
3603 SvTreeListEntry* pNewLBEntry =
3604 InsertEntryIntoUI( pEntry, nSelectionPos );
3606 aContentsListBox->SetCheckButtonState( pNewLBEntry,
3607 pEntry->IsVisible() ?
3608 SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
3610 aContentsListBox->Select( pNewLBEntry );
3611 aContentsListBox->MakeVisible( pNewLBEntry );
3613 // reset backup in entry
3614 pEntry->SetBackupGraphic(
3615 uno::Reference< graphic::XGraphic >() );
3617 GetSaveInData()->PersistChanges(
3618 GetSaveInData()->GetImageManager() );
3620 catch ( uno::Exception& )
3622 OSL_TRACE("Error resetting image");
3624 break;
3628 if ( bNeedsApply == sal_True )
3630 (( ToolbarSaveInData* ) GetSaveInData())->ApplyToolbar( pToolbar );
3631 UpdateButtonStates();
3634 return 1;
3637 void SvxToolbarConfigPage::Init()
3639 // ensure that the UI is cleared before populating it
3640 aTopLevelListBox.Clear();
3641 aContentsListBox->Clear();
3643 ReloadTopLevelListBox();
3645 sal_uInt16 nPos = 0;
3646 if ( !m_aURLToSelect.isEmpty() )
3648 for ( sal_uInt16 i = 0 ; i < aTopLevelListBox.GetEntryCount(); ++i )
3650 SvxConfigEntry* pData =
3651 (SvxConfigEntry*) aTopLevelListBox.GetEntryData( i );
3653 if ( pData->GetCommand().equals( m_aURLToSelect ) )
3655 nPos = i;
3656 break;
3660 // in future select the default toolbar: Standard
3661 m_aURLToSelect = OUString(ITEM_TOOLBAR_URL );
3662 m_aURLToSelect += "standardbar";
3665 aTopLevelListBox.SelectEntryPos(nPos, sal_True);
3666 aTopLevelListBox.GetSelectHdl().Call(this);
3669 SaveInData* SvxToolbarConfigPage::CreateSaveInData(
3670 const uno::Reference< css::ui::XUIConfigurationManager >& xCfgMgr,
3671 const uno::Reference< css::ui::XUIConfigurationManager >& xParentCfgMgr,
3672 const OUString& aModuleId,
3673 bool bDocConfig )
3675 return static_cast< SaveInData* >(
3676 new ToolbarSaveInData( xCfgMgr, xParentCfgMgr, aModuleId, bDocConfig ));
3679 ToolbarSaveInData::ToolbarSaveInData(
3680 const uno::Reference < css::ui::XUIConfigurationManager >& xCfgMgr,
3681 const uno::Reference < css::ui::XUIConfigurationManager >& xParentCfgMgr,
3682 const OUString& aModuleId,
3683 bool docConfig ) :
3685 SaveInData ( xCfgMgr, xParentCfgMgr, aModuleId, docConfig ),
3686 pRootEntry ( NULL ),
3687 m_aDescriptorContainer ( ITEM_DESCRIPTOR_CONTAINER )
3690 uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
3691 // Initialize the m_xPersistentWindowState variable which is used
3692 // to get the default properties of system toolbars such as name
3693 uno::Reference< container::XNameAccess > xPWSS = css::ui::WindowStateConfiguration::create( xContext );
3695 xPWSS->getByName( aModuleId ) >>= m_xPersistentWindowState;
3698 ToolbarSaveInData::~ToolbarSaveInData()
3700 delete pRootEntry;
3703 void ToolbarSaveInData::SetSystemStyle(
3704 uno::Reference< frame::XFrame > xFrame,
3705 const OUString& rResourceURL,
3706 sal_Int32 nStyle )
3708 // change the style using the API
3709 SetSystemStyle( rResourceURL, nStyle );
3711 // this code is a temporary hack as the UI is not updating after
3712 // changing the toolbar style via the API
3713 uno::Reference< css::frame::XLayoutManager > xLayoutManager;
3714 Window *window = NULL;
3716 uno::Reference< beans::XPropertySet > xPropSet( xFrame, uno::UNO_QUERY );
3717 if ( xPropSet.is() )
3719 uno::Any a = xPropSet->getPropertyValue(
3720 OUString( "LayoutManager" ) );
3721 a >>= xLayoutManager;
3724 if ( xLayoutManager.is() )
3726 uno::Reference< css::ui::XUIElement > xUIElement =
3727 xLayoutManager->getElement( rResourceURL );
3729 // check reference before we call getRealInterface. The layout manager
3730 // can only provide references for elements that have been created
3731 // before. It's possible that the current element is not available.
3732 uno::Reference< com::sun::star::awt::XWindow > xWindow;
3733 if ( xUIElement.is() )
3734 xWindow = uno::Reference< com::sun::star::awt::XWindow >(
3735 xUIElement->getRealInterface(), uno::UNO_QUERY );
3737 window = VCLUnoHelper::GetWindow( xWindow );
3740 if ( window != NULL && window->GetType() == WINDOW_TOOLBOX )
3742 ToolBox* toolbox = (ToolBox*)window;
3744 if ( nStyle == 0 )
3746 toolbox->SetButtonType( BUTTON_SYMBOL );
3748 else if ( nStyle == 1 )
3750 toolbox->SetButtonType( BUTTON_TEXT );
3752 if ( nStyle == 2 )
3754 toolbox->SetButtonType( BUTTON_SYMBOLTEXT );
3759 void ToolbarSaveInData::SetSystemStyle(
3760 const OUString& rResourceURL,
3761 sal_Int32 nStyle )
3763 if ( rResourceURL.indexOf( "private" ) == 0 &&
3764 m_xPersistentWindowState.is() &&
3765 m_xPersistentWindowState->hasByName( rResourceURL ) )
3769 uno::Sequence< beans::PropertyValue > aProps;
3771 uno::Any a( m_xPersistentWindowState->getByName( rResourceURL ) );
3773 if ( a >>= aProps )
3775 for ( sal_Int32 i = 0; i < aProps.getLength(); ++i )
3777 if ( aProps[ i ].Name.equalsAscii( ITEM_DESCRIPTOR_STYLE) )
3779 aProps[ i ].Value = uno::makeAny( nStyle );
3780 break;
3785 uno::Reference< container::XNameReplace >
3786 xNameReplace( m_xPersistentWindowState, uno::UNO_QUERY );
3788 xNameReplace->replaceByName( rResourceURL, uno::makeAny( aProps ) );
3790 catch ( uno::Exception& )
3792 // do nothing, a default value is returned
3793 OSL_TRACE("Exception setting toolbar style");
3798 sal_Int32 ToolbarSaveInData::GetSystemStyle( const OUString& rResourceURL )
3800 sal_Int32 result = 0;
3802 if ( rResourceURL.indexOf( "private" ) == 0 &&
3803 m_xPersistentWindowState.is() &&
3804 m_xPersistentWindowState->hasByName( rResourceURL ) )
3808 uno::Sequence< beans::PropertyValue > aProps;
3809 uno::Any a( m_xPersistentWindowState->getByName( rResourceURL ) );
3811 if ( a >>= aProps )
3813 for ( sal_Int32 i = 0; i < aProps.getLength(); ++i )
3815 if ( aProps[ i ].Name.equalsAscii( ITEM_DESCRIPTOR_STYLE) )
3817 aProps[i].Value >>= result;
3818 break;
3823 catch ( uno::Exception& )
3825 // do nothing, a default value is returned
3829 return result;
3832 OUString ToolbarSaveInData::GetSystemUIName( const OUString& rResourceURL )
3834 OUString result;
3836 if ( rResourceURL.indexOf( "private" ) == 0 &&
3837 m_xPersistentWindowState.is() &&
3838 m_xPersistentWindowState->hasByName( rResourceURL ) )
3842 uno::Sequence< beans::PropertyValue > aProps;
3843 uno::Any a( m_xPersistentWindowState->getByName( rResourceURL ) );
3845 if ( a >>= aProps )
3847 for ( sal_Int32 i = 0; i < aProps.getLength(); ++i )
3849 if ( aProps[ i ].Name.equalsAscii( ITEM_DESCRIPTOR_UINAME) )
3851 aProps[ i ].Value >>= result;
3856 catch ( uno::Exception& )
3858 // do nothing, an empty UIName will be returned
3862 if ( rResourceURL.indexOf( ".uno" ) == 0 &&
3863 m_xCommandToLabelMap.is() &&
3864 m_xCommandToLabelMap->hasByName( rResourceURL ) )
3866 uno::Any a;
3869 a = m_xCommandToLabelMap->getByName( rResourceURL );
3871 uno::Sequence< beans::PropertyValue > aPropSeq;
3872 if ( a >>= aPropSeq )
3874 for ( sal_Int32 i = 0; i < aPropSeq.getLength(); ++i )
3876 if ( aPropSeq[i].Name.equalsAscii( ITEM_DESCRIPTOR_LABEL ) )
3878 aPropSeq[i].Value >>= result;
3883 catch ( uno::Exception& )
3885 // not a system command name
3889 return result;
3892 bool EntrySort( SvxConfigEntry* a, SvxConfigEntry* b )
3894 return a->GetName().compareTo( b->GetName() ) < 0;
3897 SvxEntries* ToolbarSaveInData::GetEntries()
3899 typedef ::boost::unordered_map< OUString,
3900 bool,
3901 OUStringHash,
3902 ::std::equal_to< OUString > > ToolbarInfo;
3904 ToolbarInfo aToolbarInfo;
3906 if ( pRootEntry == NULL )
3909 pRootEntry = new SvxConfigEntry(
3910 OUString("MainToolbars"),
3911 OUString(), sal_True);
3913 uno::Sequence< uno::Sequence < beans::PropertyValue > > info =
3914 GetConfigManager()->getUIElementsInfo(
3915 css::ui::UIElementType::TOOLBAR );
3917 for ( sal_Int32 i = 0; i < info.getLength(); ++i )
3919 uno::Sequence< beans::PropertyValue > props = info[ i ];
3921 OUString url;
3922 OUString systemname;
3923 OUString uiname;
3925 for ( sal_Int32 j = 0; j < props.getLength(); ++j )
3927 if ( props[ j ].Name.equalsAscii( ITEM_DESCRIPTOR_RESOURCEURL) )
3929 props[ j ].Value >>= url;
3930 systemname = url.copy( url.lastIndexOf( '/' ) + 1 );
3932 else if ( props[ j ].Name.equalsAscii( ITEM_DESCRIPTOR_UINAME) )
3934 props[ j ].Value >>= uiname;
3940 uno::Reference< container::XIndexAccess > xToolbarSettings =
3941 GetConfigManager()->getSettings( url, sal_False );
3943 if ( uiname.isEmpty() )
3945 // try to get the name from m_xPersistentWindowState
3946 uiname = GetSystemUIName( url );
3948 if ( uiname.isEmpty() )
3950 uiname = systemname;
3954 SvxConfigEntry* pEntry = new SvxConfigEntry(
3955 uiname, url, sal_True );
3957 pEntry->SetMain( sal_True );
3958 pEntry->SetStyle( GetSystemStyle( url ) );
3961 // insert into boost::unordered_map to filter duplicates from the parent
3962 aToolbarInfo.insert( ToolbarInfo::value_type( systemname, true ));
3964 OUString custom(CUSTOM_TOOLBAR_STR);
3965 if ( systemname.indexOf( custom ) == 0 )
3967 pEntry->SetUserDefined( sal_True );
3969 else
3971 pEntry->SetUserDefined( sal_False );
3974 pRootEntry->GetEntries()->push_back( pEntry );
3976 LoadToolbar( xToolbarSettings, pEntry );
3978 catch ( container::NoSuchElementException& )
3980 // TODO, handle resourceURL with no settings
3984 uno::Reference< css::ui::XUIConfigurationManager > xParentCfgMgr = GetParentConfigManager();
3985 if ( xParentCfgMgr.is() )
3987 // Retrieve also the parent toolbars to make it possible
3988 // to configure module toolbars and save them into the document
3989 // config manager.
3990 uno::Sequence< uno::Sequence < beans::PropertyValue > > info_ =
3991 xParentCfgMgr->getUIElementsInfo(
3992 css::ui::UIElementType::TOOLBAR );
3994 for ( sal_Int32 i = 0; i < info_.getLength(); ++i )
3996 uno::Sequence< beans::PropertyValue > props = info_[ i ];
3998 OUString url;
3999 OUString systemname;
4000 OUString uiname;
4002 for ( sal_Int32 j = 0; j < props.getLength(); ++j )
4004 if ( props[ j ].Name.equalsAscii( ITEM_DESCRIPTOR_RESOURCEURL) )
4006 props[ j ].Value >>= url;
4007 systemname = url.copy( url.lastIndexOf( '/' ) + 1 );
4009 else if ( props[ j ].Name.equalsAscii( ITEM_DESCRIPTOR_UINAME) )
4011 props[ j ].Value >>= uiname;
4015 // custom toolbars of the parent are not visible in the document layer
4016 OUString custom(CUSTOM_TOOLBAR_STR);
4017 if ( systemname.indexOf( custom ) == 0 )
4018 continue;
4020 // check if toolbar is already in the document layer
4021 ToolbarInfo::const_iterator pIter = aToolbarInfo.find( systemname );
4022 if ( pIter == aToolbarInfo.end() )
4024 aToolbarInfo.insert( ToolbarInfo::value_type( systemname, true ));
4028 uno::Reference< container::XIndexAccess > xToolbarSettings =
4029 xParentCfgMgr->getSettings( url, sal_False );
4031 if ( uiname.isEmpty() )
4033 // try to get the name from m_xPersistentWindowState
4034 uiname = GetSystemUIName( url );
4036 if ( uiname.isEmpty() )
4038 uiname = systemname;
4042 SvxConfigEntry* pEntry = new SvxConfigEntry(
4043 uiname, url, sal_True, sal_True );
4045 pEntry->SetMain( sal_True );
4046 pEntry->SetStyle( GetSystemStyle( url ) );
4048 if ( systemname.indexOf( custom ) == 0 )
4050 pEntry->SetUserDefined( sal_True );
4052 else
4054 pEntry->SetUserDefined( sal_False );
4057 pRootEntry->GetEntries()->push_back( pEntry );
4059 LoadToolbar( xToolbarSettings, pEntry );
4061 catch ( container::NoSuchElementException& )
4063 // TODO, handle resourceURL with no settings
4069 std::sort( GetEntries()->begin(), GetEntries()->end(), EntrySort );
4072 return pRootEntry->GetEntries();
4075 void
4076 ToolbarSaveInData::SetEntries( SvxEntries* pNewEntries )
4078 // delete old menu hierarchy first
4079 if ( pRootEntry != NULL && pRootEntry->GetEntries() != NULL )
4081 delete pRootEntry->GetEntries();
4084 // now set new menu hierarchy
4085 pRootEntry->SetEntries( pNewEntries );
4088 bool
4089 ToolbarSaveInData::HasURL( const OUString& rURL )
4091 SvxEntries::const_iterator iter = GetEntries()->begin();
4092 SvxEntries::const_iterator end = GetEntries()->end();
4094 while ( iter != end )
4096 SvxConfigEntry* pEntry = *iter;
4098 if ( pEntry->GetCommand().equals( rURL ) )
4100 if ( pEntry->IsParentData() )
4101 return sal_False;
4102 else
4103 return sal_True;
4106 ++iter;
4108 return sal_False;
4111 bool ToolbarSaveInData::HasSettings()
4113 // return true if there is at least one toolbar entry
4114 if ( GetEntries()->size() > 0 )
4116 return sal_True;
4118 return sal_False;
4121 void ToolbarSaveInData::Reset()
4123 SvxEntries::const_iterator toolbars = GetEntries()->begin();
4124 SvxEntries::const_iterator end = GetEntries()->end();
4126 // reset each toolbar by calling removeSettings for it's toolbar URL
4127 for ( ; toolbars != end; ++toolbars )
4129 SvxConfigEntry* pToolbar = *toolbars;
4133 OUString url = pToolbar->GetCommand();
4134 GetConfigManager()->removeSettings( url );
4136 catch ( uno::Exception& )
4138 // error occurred removing the settings
4139 // TODO - add error dialog in future?
4143 // persist changes to toolbar storage
4144 PersistChanges( GetConfigManager() );
4146 // now delete the root SvxConfigEntry the next call to GetEntries()
4147 // causes it to be reinitialised
4148 delete pRootEntry;
4149 pRootEntry = NULL;
4151 // reset all icons to default
4154 GetImageManager()->reset();
4155 PersistChanges( GetImageManager() );
4157 catch ( uno::Exception& )
4159 OSL_TRACE("Error resetting all icons when resetting toolbars");
4163 bool ToolbarSaveInData::Apply()
4165 // toolbar changes are instantly applied
4166 return sal_False;
4169 void ToolbarSaveInData::ApplyToolbar(
4170 uno::Reference< container::XIndexContainer >& rToolbarBar,
4171 uno::Reference< lang::XSingleComponentFactory >& rFactory,
4172 SvxConfigEntry* pToolbarData )
4174 uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
4176 SvxEntries::const_iterator iter = pToolbarData->GetEntries()->begin();
4177 SvxEntries::const_iterator end = pToolbarData->GetEntries()->end();
4179 for ( ; iter != end; ++iter )
4181 SvxConfigEntry* pEntry = *iter;
4183 if ( pEntry->IsPopup() )
4185 uno::Sequence< beans::PropertyValue > aPropValueSeq =
4186 ConvertToolbarEntry( m_xCommandToLabelMap, pEntry );
4188 uno::Reference< container::XIndexContainer > xSubMenuBar(
4189 rFactory->createInstanceWithContext( xContext ),
4190 uno::UNO_QUERY );
4192 sal_Int32 nIndex = aPropValueSeq.getLength();
4193 aPropValueSeq.realloc( nIndex + 1 );
4194 aPropValueSeq[nIndex].Name = m_aDescriptorContainer;
4195 aPropValueSeq[nIndex].Value <<= xSubMenuBar;
4196 rToolbarBar->insertByIndex(
4197 rToolbarBar->getCount(), uno::makeAny( aPropValueSeq ));
4199 ApplyToolbar( xSubMenuBar, rFactory, pEntry );
4201 else if ( pEntry->IsSeparator() )
4203 rToolbarBar->insertByIndex(
4204 rToolbarBar->getCount(), uno::makeAny( m_aSeparatorSeq ));
4206 else
4208 uno::Sequence< beans::PropertyValue > aPropValueSeq =
4209 ConvertToolbarEntry( m_xCommandToLabelMap, pEntry );
4211 rToolbarBar->insertByIndex(
4212 rToolbarBar->getCount(), uno::makeAny( aPropValueSeq ));
4217 void ToolbarSaveInData::ApplyToolbar( SvxConfigEntry* pToolbar )
4219 // Apply new toolbar structure to our settings container
4220 uno::Reference< container::XIndexAccess > xSettings(
4221 GetConfigManager()->createSettings(), uno::UNO_QUERY );
4223 uno::Reference< container::XIndexContainer > xIndexContainer (
4224 xSettings, uno::UNO_QUERY );
4226 uno::Reference< lang::XSingleComponentFactory > xFactory (
4227 xSettings, uno::UNO_QUERY );
4229 ApplyToolbar( xIndexContainer, xFactory, pToolbar );
4231 uno::Reference< beans::XPropertySet > xProps(
4232 xSettings, uno::UNO_QUERY );
4234 if ( pToolbar->IsUserDefined() )
4236 xProps->setPropertyValue(
4237 OUString(ITEM_DESCRIPTOR_UINAME ),
4238 uno::makeAny( OUString( pToolbar->GetName() ) ) );
4243 if ( GetConfigManager()->hasSettings( pToolbar->GetCommand() ) )
4245 GetConfigManager()->replaceSettings(
4246 pToolbar->GetCommand(), xSettings );
4248 else
4250 GetConfigManager()->insertSettings(
4251 pToolbar->GetCommand(), xSettings );
4252 if ( pToolbar->IsParentData() )
4253 pToolbar->SetParentData( false );
4256 catch ( container::NoSuchElementException& )
4258 OSL_TRACE("caught container::NoSuchElementException saving settings");
4260 catch ( com::sun::star::io::IOException& )
4262 OSL_TRACE("caught IOException saving settings");
4264 catch ( com::sun::star::uno::Exception& )
4266 OSL_TRACE("caught some other exception saving settings");
4269 PersistChanges( GetConfigManager() );
4272 void ToolbarSaveInData::CreateToolbar( SvxConfigEntry* pToolbar )
4274 // show the new toolbar in the UI also
4275 uno::Reference< container::XIndexAccess >
4276 xSettings( GetConfigManager()->createSettings(), uno::UNO_QUERY );
4278 uno::Reference< container::XIndexContainer >
4279 xIndexContainer ( xSettings, uno::UNO_QUERY );
4281 uno::Reference< beans::XPropertySet >
4282 xPropertySet( xSettings, uno::UNO_QUERY );
4284 xPropertySet->setPropertyValue(
4285 OUString(ITEM_DESCRIPTOR_UINAME ),
4286 uno::makeAny( pToolbar->GetName() ) );
4290 GetConfigManager()->insertSettings( pToolbar->GetCommand(), xSettings );
4292 catch ( container::ElementExistException& )
4294 OSL_TRACE("caught ElementExistsException saving settings");
4296 catch ( com::sun::star::lang::IllegalArgumentException& )
4298 OSL_TRACE("caught IOException saving settings");
4300 catch ( com::sun::star::lang::IllegalAccessException& )
4302 OSL_TRACE("caught IOException saving settings");
4304 catch ( com::sun::star::uno::Exception& )
4306 OSL_TRACE("caught some other exception saving settings");
4309 GetEntries()->push_back( pToolbar );
4311 PersistChanges( GetConfigManager() );
4314 void ToolbarSaveInData::RemoveToolbar( SvxConfigEntry* pToolbar )
4318 OUString url = pToolbar->GetCommand();
4319 GetConfigManager()->removeSettings( url );
4320 RemoveEntry( GetEntries(), pToolbar );
4321 delete pToolbar;
4323 PersistChanges( GetConfigManager() );
4325 // remove the persistent window state data
4326 css::uno::Reference< css::container::XNameContainer > xNameContainer(
4327 m_xPersistentWindowState, css::uno::UNO_QUERY_THROW );
4329 xNameContainer->removeByName( url );
4331 catch ( uno::Exception& )
4333 // error occurred removing the settings
4337 void ToolbarSaveInData::RestoreToolbar( SvxConfigEntry* pToolbar )
4339 OUString url = pToolbar->GetCommand();
4341 // Restore of toolbar is done by removing it from
4342 // it's configuration manager and then getting it again
4343 bool bParentToolbar = pToolbar->IsParentData();
4345 // Cannot restore parent toolbar
4346 if ( bParentToolbar )
4347 return;
4351 GetConfigManager()->removeSettings( url );
4352 pToolbar->GetEntries()->clear();
4353 PersistChanges( GetConfigManager() );
4355 catch ( uno::Exception& )
4357 // if an error occurs removing the settings then just return
4358 return;
4361 // Now reload the toolbar settings
4364 uno::Reference< container::XIndexAccess > xToolbarSettings;
4365 if ( IsDocConfig() )
4367 xToolbarSettings = GetParentConfigManager()->getSettings( url, sal_False );
4368 pToolbar->SetParentData( true );
4370 else
4371 xToolbarSettings = GetConfigManager()->getSettings( url, sal_False );
4373 LoadToolbar( xToolbarSettings, pToolbar );
4375 // After reloading, ensure that the icon is reset of each entry
4376 // in the toolbar
4377 SvxEntries::const_iterator iter = pToolbar->GetEntries()->begin();
4378 uno::Sequence< OUString > aURLSeq( 1 );
4379 for ( ; iter != pToolbar->GetEntries()->end(); ++iter )
4381 SvxConfigEntry* pEntry = *iter;
4382 aURLSeq[ 0 ] = pEntry->GetCommand();
4386 GetImageManager()->removeImages( GetImageType(), aURLSeq );
4388 catch ( uno::Exception& )
4390 OSL_TRACE("Error restoring icon when resetting toolbar");
4393 PersistChanges( GetImageManager() );
4395 catch ( container::NoSuchElementException& )
4397 // cannot find the resource URL after removing it
4398 // so no entry will appear in the toolbar list
4402 bool ToolbarSaveInData::LoadToolbar(
4403 const uno::Reference< container::XIndexAccess >& xToolbarSettings,
4404 SvxConfigEntry* pParentData )
4406 SvxEntries* pEntries = pParentData->GetEntries();
4408 for ( sal_Int32 nIndex = 0; nIndex < xToolbarSettings->getCount(); ++nIndex )
4410 uno::Reference< container::XIndexAccess > xSubMenu;
4411 OUString aCommandURL;
4412 OUString aLabel;
4413 bool bIsUserDefined = sal_True;
4414 sal_Bool bIsVisible;
4415 sal_Int32 nStyle;
4417 sal_uInt16 nType( css::ui::ItemType::DEFAULT );
4419 bool bItem = GetToolbarItemData( xToolbarSettings, nIndex, aCommandURL,
4420 aLabel, nType, bIsVisible, nStyle, xSubMenu );
4422 if ( bItem )
4424 if ( nType == css::ui::ItemType::DEFAULT )
4426 uno::Any a;
4429 a = m_xCommandToLabelMap->getByName( aCommandURL );
4430 bIsUserDefined = sal_False;
4432 catch ( container::NoSuchElementException& )
4434 bIsUserDefined = sal_True;
4437 // If custom label not set retrieve it from the command
4438 // to info service
4439 if ( aLabel.equals( OUString() ) )
4441 uno::Sequence< beans::PropertyValue > aPropSeq;
4442 if ( a >>= aPropSeq )
4444 for ( sal_Int32 i = 0; i < aPropSeq.getLength(); ++i )
4446 if ( aPropSeq[i].Name.equalsAscii( ITEM_DESCRIPTOR_LABEL ) )
4448 aPropSeq[i].Value >>= aLabel;
4449 break;
4455 if ( xSubMenu.is() )
4457 SvxConfigEntry* pEntry = new SvxConfigEntry(
4458 aLabel, aCommandURL, sal_True );
4460 pEntry->SetUserDefined( bIsUserDefined );
4461 pEntry->SetVisible( bIsVisible );
4463 pEntries->push_back( pEntry );
4465 LoadToolbar( xSubMenu, pEntry );
4467 else
4469 SvxConfigEntry* pEntry = new SvxConfigEntry(
4470 aLabel, aCommandURL, sal_False );
4471 pEntry->SetUserDefined( bIsUserDefined );
4472 pEntry->SetVisible( bIsVisible );
4473 pEntry->SetStyle( nStyle );
4474 pEntries->push_back( pEntry );
4477 else
4479 SvxConfigEntry* pEntry = new SvxConfigEntry;
4480 pEntry->SetUserDefined( bIsUserDefined );
4481 pEntries->push_back( pEntry );
4486 return true;
4489 IMPL_LINK( SvxToolbarConfigPage, SelectToolbarEntry, Control *, pBox )
4491 (void)pBox;
4492 UpdateButtonStates();
4493 return 1;
4496 void SvxToolbarConfigPage::UpdateButtonStates()
4498 PopupMenu* pPopup = aModifyCommandButton.GetPopupMenu();
4499 pPopup->EnableItem( ID_RENAME, sal_False );
4500 pPopup->EnableItem( ID_DELETE, sal_False );
4501 pPopup->EnableItem( ID_BEGIN_GROUP, sal_False );
4502 pPopup->EnableItem( ID_DEFAULT_COMMAND, sal_False );
4503 pPopup->EnableItem( ID_ICON_ONLY, sal_False );
4504 pPopup->EnableItem( ID_ICON_AND_TEXT, sal_False );
4505 pPopup->EnableItem( ID_TEXT_ONLY, sal_False );
4506 pPopup->EnableItem( ID_CHANGE_SYMBOL, sal_False );
4507 pPopup->EnableItem( ID_RESET_SYMBOL, sal_False );
4509 aDescriptionField.Clear();
4511 SvTreeListEntry* selection = aContentsListBox->GetCurEntry();
4512 if ( aContentsListBox->GetEntryCount() == 0 || selection == NULL )
4514 return;
4517 SvxConfigEntry* pEntryData = (SvxConfigEntry*) selection->GetUserData();
4518 if ( pEntryData->IsSeparator() )
4519 pPopup->EnableItem( ID_DELETE, sal_True );
4520 else
4522 pPopup->EnableItem( ID_BEGIN_GROUP, sal_True );
4523 pPopup->EnableItem( ID_DELETE, sal_True );
4524 pPopup->EnableItem( ID_RENAME, sal_True );
4525 pPopup->EnableItem( ID_ICON_ONLY, sal_True );
4526 pPopup->EnableItem( ID_ICON_AND_TEXT, sal_True );
4527 pPopup->EnableItem( ID_TEXT_ONLY, sal_True );
4528 pPopup->EnableItem( ID_CHANGE_SYMBOL, sal_True );
4530 if ( !pEntryData->IsUserDefined() )
4531 pPopup->EnableItem( ID_DEFAULT_COMMAND, sal_True );
4533 if ( pEntryData->IsIconModified() )
4534 pPopup->EnableItem( ID_RESET_SYMBOL, sal_True );
4536 aDescriptionField.SetNewText( pEntryData->GetHelpText() );
4540 short SvxToolbarConfigPage::QueryReset()
4542 String msg =
4543 String( CUI_RES( RID_SVXSTR_CONFIRM_TOOLBAR_RESET ) );
4545 String saveInName = aSaveInListBox.GetEntry(
4546 aSaveInListBox.GetSelectEntryPos() );
4548 OUString label = replaceSaveInName( msg, saveInName );
4550 QueryBox qbox( this, WB_YES_NO, label );
4552 return qbox.Execute();
4555 IMPL_LINK( SvxToolbarConfigPage, SelectToolbar, ListBox *, pBox )
4557 (void)pBox;
4559 aContentsListBox->Clear();
4561 SvxConfigEntry* pToolbar = GetTopLevelSelection();
4562 if ( pToolbar == NULL )
4564 aModifyTopLevelButton.Enable( sal_False );
4565 aModifyCommandButton.Enable( sal_False );
4566 aAddCommandsButton.Enable( sal_False );
4568 return 0;
4571 aModifyTopLevelButton.Enable( sal_True );
4572 aModifyCommandButton.Enable( sal_True );
4573 aAddCommandsButton.Enable( sal_True );
4575 PopupMenu* pPopup = aModifyTopLevelButton.GetPopupMenu();
4577 pPopup->EnableItem( ID_DELETE, pToolbar->IsDeletable() );
4578 pPopup->EnableItem( ID_RENAME, pToolbar->IsRenamable() );
4579 pPopup->EnableItem( ID_DEFAULT_STYLE, !pToolbar->IsRenamable() );
4581 switch( pToolbar->GetStyle() )
4583 case 0:
4585 pPopup->CheckItem( ID_ICONS_ONLY );
4586 break;
4588 case 1:
4590 pPopup->CheckItem( ID_TEXT_ONLY );
4591 break;
4593 case 2:
4595 pPopup->CheckItem( ID_ICONS_AND_TEXT );
4596 break;
4600 SvxEntries* pEntries = pToolbar->GetEntries();
4601 SvxEntries::const_iterator iter = pEntries->begin();
4603 for ( ; iter != pEntries->end(); ++iter )
4605 SvxConfigEntry* pEntry = *iter;
4607 SvTreeListEntry* pNewLBEntry = InsertEntryIntoUI( pEntry );
4609 if (pEntry->IsBinding())
4611 aContentsListBox->SetCheckButtonState( pNewLBEntry,
4612 pEntry->IsVisible() ? SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
4614 else
4616 aContentsListBox->SetCheckButtonState(
4617 pNewLBEntry, SV_BUTTON_TRISTATE );
4621 UpdateButtonStates();
4623 return 0;
4626 IMPL_LINK( SvxToolbarConfigPage, NewToolbarHdl, Button *, pButton )
4628 (void)pButton;
4630 String prefix =
4631 String( CUI_RES( RID_SVXSTR_NEW_TOOLBAR ) );
4633 OUString aNewName =
4634 generateCustomName( prefix, GetSaveInData()->GetEntries() );
4636 OUString aNewURL =
4637 generateCustomURL( GetSaveInData()->GetEntries() );
4639 SvxNewToolbarDialog* pNameDialog = new SvxNewToolbarDialog( 0, aNewName );
4641 sal_uInt16 nInsertPos;
4642 for ( sal_uInt16 i = 0 ; i < aSaveInListBox.GetEntryCount(); ++i )
4644 SaveInData* pData =
4645 (SaveInData*) aSaveInListBox.GetEntryData( i );
4647 nInsertPos = pNameDialog->m_pSaveInListBox->InsertEntry(
4648 aSaveInListBox.GetEntry( i ) );
4650 pNameDialog->m_pSaveInListBox->SetEntryData( nInsertPos, pData );
4653 pNameDialog->m_pSaveInListBox->SelectEntryPos(
4654 aSaveInListBox.GetSelectEntryPos(), sal_True );
4656 bool ret = pNameDialog->Execute();
4657 if ( ret == RET_OK )
4659 aNewName = pNameDialog->GetName();
4661 nInsertPos = pNameDialog->m_pSaveInListBox->GetSelectEntryPos();
4663 ToolbarSaveInData* pData = (ToolbarSaveInData*)
4664 pNameDialog->m_pSaveInListBox->GetEntryData( nInsertPos );
4666 if ( GetSaveInData() != pData )
4668 aSaveInListBox.SelectEntryPos( nInsertPos, sal_True );
4669 aSaveInListBox.GetSelectHdl().Call(this);
4672 SvxConfigEntry* pToolbar =
4673 new SvxConfigEntry( aNewName, aNewURL, sal_True );
4675 pToolbar->SetUserDefined( sal_True );
4676 pToolbar->SetMain( sal_True );
4678 pData->CreateToolbar( pToolbar );
4680 nInsertPos = aTopLevelListBox.InsertEntry( pToolbar->GetName() );
4681 aTopLevelListBox.SetEntryData( nInsertPos, pToolbar );
4682 aTopLevelListBox.SelectEntryPos( nInsertPos, sal_True );
4683 aTopLevelListBox.GetSelectHdl().Call(this);
4685 pData->SetModified( sal_True );
4688 delete pNameDialog;
4690 return 0;
4693 IMPL_LINK( SvxToolbarConfigPage, AddCommandsHdl, Button *, pButton )
4695 (void)pButton;
4697 if ( pSelectorDlg == NULL )
4699 // Create Script Selector which shows slot commands
4700 pSelectorDlg = new SvxScriptSelectorDialog( this, sal_True, m_xFrame );
4702 // Position the Script Selector over the Add button so it is
4703 // beside the menu contents list and does not obscure it
4704 pSelectorDlg->SetPosPixel( aAddCommandsButton.GetPosPixel() );
4706 pSelectorDlg->SetAddHdl(
4707 LINK( this, SvxToolbarConfigPage, AddFunctionHdl ) );
4710 pSelectorDlg->SetImageProvider(
4711 static_cast< ImageProvider* >( GetSaveInData() ) );
4713 pSelectorDlg->Show();
4714 return 1;
4717 IMPL_LINK( SvxToolbarConfigPage, AddFunctionHdl,
4718 SvxScriptSelectorDialog *, pDialog )
4720 (void)pDialog;
4722 AddFunction();
4724 return 0;
4727 SvTreeListEntry* SvxToolbarConfigPage::AddFunction(
4728 SvTreeListEntry* pTarget, bool bFront, bool bAllowDuplicates )
4730 SvTreeListEntry* pNewLBEntry =
4731 SvxConfigPage::AddFunction( pTarget, bFront, bAllowDuplicates );
4733 SvxConfigEntry* pEntry = (SvxConfigEntry*) pNewLBEntry->GetUserData();
4735 if ( pEntry->IsBinding() )
4737 pEntry->SetVisible( sal_True );
4738 aContentsListBox->SetCheckButtonState(
4739 pNewLBEntry, SV_BUTTON_CHECKED );
4741 else
4743 aContentsListBox->SetCheckButtonState(
4744 pNewLBEntry, SV_BUTTON_TRISTATE );
4747 // get currently selected toolbar and apply change
4748 SvxConfigEntry* pToolbar = GetTopLevelSelection();
4750 if ( pToolbar != NULL )
4752 ( ( ToolbarSaveInData* ) GetSaveInData() )->ApplyToolbar( pToolbar );
4755 return pNewLBEntry;
4758 // -----------------------------------------------------------------------
4760 SvxToolbarEntriesListBox::SvxToolbarEntriesListBox(
4761 Window* pParent, const ResId& aResId )
4763 SvxMenuEntriesListBox( pParent, aResId ),
4764 pPage( ( SvxToolbarConfigPage* ) pParent )
4766 m_pButtonData = new SvLBoxButtonData( this );
4767 BuildCheckBoxButtonImages( m_pButtonData );
4768 EnableCheckButton( m_pButtonData );
4771 // --------------------------------------------------------
4773 SvxToolbarEntriesListBox::~SvxToolbarEntriesListBox()
4775 delete m_pButtonData;
4778 // --------------------------------------------------------
4780 void SvxToolbarEntriesListBox::BuildCheckBoxButtonImages( SvLBoxButtonData* pData )
4782 // Build checkbox images according to the current application
4783 // settings. This is necessary to be able to have correct colors
4784 // in all color modes, like high contrast.
4785 const AllSettings& rSettings = Application::GetSettings();
4787 VirtualDevice aDev;
4788 Size aSize( 26, 20 );
4790 aDev.SetOutputSizePixel( aSize );
4792 Image aImage = GetSizedImage( aDev, aSize,
4793 CheckBox::GetCheckImage( rSettings, BUTTON_DRAW_DEFAULT ));
4795 // Fill button data struct with new images
4796 pData->aBmps[SV_BMP_UNCHECKED] = aImage;
4797 pData->aBmps[SV_BMP_CHECKED] = GetSizedImage( aDev, aSize, CheckBox::GetCheckImage( rSettings, BUTTON_DRAW_CHECKED ));
4798 pData->aBmps[SV_BMP_HICHECKED] = GetSizedImage( aDev, aSize, CheckBox::GetCheckImage( rSettings, BUTTON_DRAW_CHECKED | BUTTON_DRAW_PRESSED ));
4799 pData->aBmps[SV_BMP_HIUNCHECKED] = GetSizedImage( aDev, aSize, CheckBox::GetCheckImage( rSettings, BUTTON_DRAW_DEFAULT | BUTTON_DRAW_PRESSED));
4800 pData->aBmps[SV_BMP_TRISTATE] = GetSizedImage( aDev, aSize, Image() ); // Use tristate bitmaps to have no checkbox for separator entries
4801 pData->aBmps[SV_BMP_HITRISTATE] = GetSizedImage( aDev, aSize, Image() );
4803 // Get image size
4804 m_aCheckBoxImageSizePixel = aImage.GetSizePixel();
4807 Image SvxToolbarEntriesListBox::GetSizedImage(
4808 VirtualDevice& aDev, const Size& aNewSize, const Image& aImage )
4810 // Create new checkbox images for treelistbox. They must have a
4811 // decent width to have a clear column for the visibility checkbox.
4813 // Standard transparent color is light magenta as is won't be
4814 // used for other things
4815 Color aFillColor( COL_LIGHTMAGENTA );
4817 // Position image at the center of (width-2),(height) rectangle.
4818 // We need 2 pixels to have a bigger border to the next button image
4819 sal_uInt16 nPosX = std::max( (sal_uInt16) (((( aNewSize.Width() - 2 ) - aImage.GetSizePixel().Width() ) / 2 ) - 1), (sal_uInt16) 0 );
4820 sal_uInt16 nPosY = std::max( (sal_uInt16) (((( aNewSize.Height() - 2 ) - aImage.GetSizePixel().Height() ) / 2 ) + 1), (sal_uInt16) 0 );
4821 Point aPos( nPosX > 0 ? nPosX : 0, nPosY > 0 ? nPosY : 0 );
4822 aDev.SetFillColor( aFillColor );
4823 aDev.SetLineColor( aFillColor );
4824 aDev.DrawRect( Rectangle( Point(), aNewSize ));
4825 aDev.DrawImage( aPos, aImage );
4827 // Draw separator line 2 pixels left from the right border
4828 Color aLineColor = GetDisplayBackground().GetColor().IsDark() ? Color( COL_WHITE ) : Color( COL_BLACK );
4829 aDev.SetLineColor( aLineColor );
4830 aDev.DrawLine( Point( aNewSize.Width()-3, 0 ), Point( aNewSize.Width()-3, aNewSize.Height()-1 ));
4832 // Create new image that uses the fillcolor as transparent
4833 return Image( aDev.GetBitmap( Point(), aNewSize ), aFillColor );
4836 void SvxToolbarEntriesListBox::DataChanged( const DataChangedEvent& rDCEvt )
4838 SvTreeListBox::DataChanged( rDCEvt );
4840 if (( rDCEvt.GetType() == DATACHANGED_SETTINGS ) &&
4841 ( rDCEvt.GetFlags() & SETTINGS_STYLE ))
4843 BuildCheckBoxButtonImages( m_pButtonData );
4844 Invalidate();
4848 // --------------------------------------------------------
4850 void SvxToolbarEntriesListBox::ChangeVisibility( SvTreeListEntry* pEntry )
4852 if ( pEntry != NULL )
4854 SvxConfigEntry* pEntryData =
4855 (SvxConfigEntry*) pEntry->GetUserData();
4857 if ( pEntryData->IsBinding() )
4859 pEntryData->SetVisible( !pEntryData->IsVisible() );
4861 SvxConfigEntry* pToolbar = pPage->GetTopLevelSelection();
4863 ToolbarSaveInData* pToolbarSaveInData = ( ToolbarSaveInData* )
4864 pPage->GetSaveInData();
4866 pToolbarSaveInData->ApplyToolbar( pToolbar );
4868 SetCheckButtonState( pEntry, pEntryData->IsVisible() ?
4869 SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
4874 void SvxToolbarEntriesListBox::CheckButtonHdl()
4876 ChangeVisibility( GetHdlEntry() );
4879 void SvxToolbarEntriesListBox::KeyInput( const KeyEvent& rKeyEvent )
4881 // space key will change visibility of toolbar items
4882 if ( rKeyEvent.GetKeyCode() == KEY_SPACE )
4884 ChangeVisibility( GetCurEntry() );
4886 else
4888 // pass on to superclass
4889 SvxMenuEntriesListBox::KeyInput( rKeyEvent );
4893 sal_Bool SvxToolbarEntriesListBox::NotifyMoving(
4894 SvTreeListEntry* pTarget, SvTreeListEntry* pSource,
4895 SvTreeListEntry*& rpNewParent, sal_uLong& rNewChildPos)
4897 bool result = SvxMenuEntriesListBox::NotifyMoving(
4898 pTarget, pSource, rpNewParent, rNewChildPos );
4900 if ( result == sal_True )
4902 // Instant Apply changes to UI
4903 SvxConfigEntry* pToolbar = pPage->GetTopLevelSelection();
4904 if ( pToolbar != NULL )
4906 ToolbarSaveInData* pSaveInData =
4907 ( ToolbarSaveInData*) pPage->GetSaveInData();
4908 pSaveInData->ApplyToolbar( pToolbar );
4912 return result;
4915 sal_Bool SvxToolbarEntriesListBox::NotifyCopying(
4916 SvTreeListEntry* pTarget,
4917 SvTreeListEntry* pSource,
4918 SvTreeListEntry*& rpNewParent,
4919 sal_uLong& rNewChildPos)
4921 (void)pSource;
4922 (void)rpNewParent;
4923 (void)rNewChildPos;
4925 if ( !m_bIsInternalDrag )
4927 // if the target is NULL then add function to the start of the list
4928 ((SvxToolbarConfigPage*)pPage)->AddFunction( pTarget, pTarget == NULL );
4930 // Instant Apply changes to UI
4931 SvxConfigEntry* pToolbar = pPage->GetTopLevelSelection();
4932 if ( pToolbar != NULL )
4934 ToolbarSaveInData* pSaveInData =
4935 ( ToolbarSaveInData*) pPage->GetSaveInData();
4936 pSaveInData->ApplyToolbar( pToolbar );
4939 // AddFunction already adds the listbox entry so return FALSE
4940 // to stop another listbox entry being added
4941 return sal_False;
4944 // Copying is only allowed from external controls, not within the listbox
4945 return sal_False;
4948 SvxNewToolbarDialog::SvxNewToolbarDialog(Window* pWindow, const OUString& rName)
4949 : ModalDialog(pWindow, "NewToolbarDialog", "cui/ui/newtoolbardialog.ui")
4951 get(m_pEdtName, "edit");
4952 get(m_pBtnOK, "ok");
4953 get(m_pSaveInListBox, "savein");
4954 m_pEdtName->SetText( rName );
4955 m_pEdtName->SetSelection(Selection(SELECTION_MIN, SELECTION_MAX));
4956 ModifyHdl(m_pEdtName);
4957 m_pEdtName->SetModifyHdl(LINK(this, SvxNewToolbarDialog, ModifyHdl));
4960 IMPL_LINK(SvxNewToolbarDialog, ModifyHdl, Edit*, pEdit)
4962 (void)pEdit;
4964 if(aCheckNameHdl.IsSet())
4965 m_pBtnOK->Enable(aCheckNameHdl.Call(this) > 0);
4967 return 0;
4970 /*******************************************************************************
4972 * The SvxIconSelectorDialog class
4974 *******************************************************************************/
4975 SvxIconSelectorDialog::SvxIconSelectorDialog( Window *pWindow,
4976 const uno::Reference< css::ui::XImageManager >& rXImageManager,
4977 const uno::Reference< css::ui::XImageManager >& rXParentImageManager )
4979 ModalDialog ( pWindow, CUI_RES( MD_ICONSELECTOR ) ),
4980 aFtDescription ( this, CUI_RES( FT_SYMBOLS ) ),
4981 aTbSymbol ( this, CUI_RES( TB_SYMBOLS ) ),
4982 aFtNote ( this, CUI_RES( FT_NOTE ) ),
4983 aBtnOK ( this, CUI_RES( BTN_OK ) ),
4984 aBtnCancel ( this, CUI_RES( BTN_CANCEL ) ),
4985 aBtnHelp ( this, CUI_RES( BTN_HELP ) ),
4986 aBtnImport ( this, CUI_RES( BTN_IMPORT ) ),
4987 aBtnDelete ( this, CUI_RES( BTN_DELETE ) ),
4988 aFlSeparator ( this, CUI_RES( FL_SEPARATOR ) ),
4989 m_nNextId ( 0 ),
4990 m_xImageManager ( rXImageManager ),
4991 m_xParentImageManager( rXParentImageManager )
4993 FreeResource();
4995 typedef ::boost::unordered_map< OUString,
4996 bool,
4997 OUStringHash,
4998 ::std::equal_to< OUString > > ImageInfo;
5000 aTbSymbol.SetPageScroll( sal_True );
5002 bool bLargeIcons = GetImageType() & css::ui::ImageType::SIZE_LARGE;
5003 m_nExpectedSize = bLargeIcons ? 26 : 16;
5005 if ( m_nExpectedSize != 16 )
5007 aFtNote.SetText( replaceSixteen( aFtNote.GetText(), m_nExpectedSize ) );
5010 uno::Reference< uno::XComponentContext > xComponentContext =
5011 ::comphelper::getProcessComponentContext();
5013 m_xGraphProvider = uno::Reference< graphic::XGraphicProvider >(
5014 graphic::GraphicProvider::create( xComponentContext ) );
5016 uno::Reference< css::util::XPathSettings > xPathSettings =
5017 css::util::PathSettings::create( xComponentContext );
5020 OUString aDirectory = xPathSettings->getUserConfig();
5022 sal_Int32 aCount = aDirectory.getLength();
5024 if ( aCount > 0 )
5026 sal_Unicode aChar = aDirectory[ aCount-1 ];
5027 if ( aChar != '/')
5029 aDirectory += OUString( "/" );
5032 else
5034 aBtnImport.Enable( sal_False );
5037 aDirectory += OUString( "soffice.cfg/import" );
5039 uno::Reference< lang::XSingleServiceFactory > xStorageFactory(
5040 ::com::sun::star::embed::FileSystemStorageFactory::create( xComponentContext ) );
5042 uno::Sequence< uno::Any > aArgs( 2 );
5043 aArgs[ 0 ] <<= aDirectory;
5044 aArgs[ 1 ] <<= com::sun::star::embed::ElementModes::READWRITE;
5046 uno::Reference< com::sun::star::embed::XStorage > xStorage(
5047 xStorageFactory->createInstanceWithArguments( aArgs ), uno::UNO_QUERY );
5049 uno::Sequence< uno::Any > aProp( 2 );
5050 beans::PropertyValue aPropValue;
5052 aPropValue.Name = OUString( "UserConfigStorage" );
5053 aPropValue.Value <<= xStorage;
5054 aProp[ 0 ] <<= aPropValue;
5056 aPropValue.Name = OUString( "OpenMode" );
5057 aPropValue.Value <<= com::sun::star::embed::ElementModes::READWRITE;
5058 aProp[ 1 ] <<= aPropValue;
5060 m_xImportedImageManager = css::ui::ImageManager::create( xComponentContext );
5062 ImageInfo mImageInfo;
5063 uno::Sequence< OUString > names;
5064 if ( m_xImportedImageManager.is() )
5066 names = m_xImportedImageManager->getAllImageNames( GetImageType() );
5067 for ( sal_Int32 n = 0; n < names.getLength(); ++n )
5068 mImageInfo.insert( ImageInfo::value_type( names[n], false ));
5070 sal_uInt16 nId = 1;
5071 ImageInfo::const_iterator pConstIter = mImageInfo.begin();
5072 uno::Sequence< OUString > name( 1 );
5073 while ( pConstIter != mImageInfo.end() )
5075 name[ 0 ] = pConstIter->first;
5076 uno::Sequence< uno::Reference< graphic::XGraphic> > graphics = m_xImportedImageManager->getImages( GetImageType(), name );
5077 if ( graphics.getLength() > 0 )
5079 Image img = Image( graphics[ 0 ] );
5080 aTbSymbol.InsertItem( nId, img, pConstIter->first );
5082 graphics[ 0 ]->acquire();
5084 aTbSymbol.SetItemData(
5085 nId, static_cast< void * > ( graphics[ 0 ].get() ) );
5087 ++nId;
5089 ++pConstIter;
5092 ImageInfo aImageInfo;
5094 if ( m_xParentImageManager.is() )
5096 names = m_xParentImageManager->getAllImageNames( GetImageType() );
5097 for ( sal_Int32 n = 0; n < names.getLength(); ++n )
5098 aImageInfo.insert( ImageInfo::value_type( names[n], false ));
5101 names = m_xImageManager->getAllImageNames( GetImageType() );
5102 for ( sal_Int32 n = 0; n < names.getLength(); ++n )
5104 ImageInfo::iterator pIter = aImageInfo.find( names[n] );
5105 if ( pIter != aImageInfo.end() )
5106 pIter->second = true;
5107 else
5108 aImageInfo.insert( ImageInfo::value_type( names[n], true ));
5111 // large growth factor, expecting many entries
5112 pConstIter = aImageInfo.begin();
5113 while ( pConstIter != aImageInfo.end() )
5115 name[ 0 ] = pConstIter->first;
5117 uno::Sequence< uno::Reference< graphic::XGraphic> > graphics;
5120 if ( pConstIter->second )
5121 graphics = m_xImageManager->getImages( GetImageType(), name );
5122 else
5123 graphics = m_xParentImageManager->getImages( GetImageType(), name );
5125 catch ( uno::Exception& )
5127 // can't get sequence for this name so it will not be
5128 // added to the list
5131 if ( graphics.getLength() > 0 )
5133 Image img = Image( graphics[ 0 ] );
5134 aTbSymbol.InsertItem( nId, img, pConstIter->first );
5136 uno::Reference< graphic::XGraphic > xGraphic = graphics[ 0 ];
5138 if ( xGraphic.is() )
5139 xGraphic->acquire();
5141 aTbSymbol.SetItemData(
5142 nId, static_cast< void * > ( xGraphic.get() ) );
5144 ++nId;
5147 ++pConstIter;
5150 aBtnDelete.Enable( sal_False );
5151 aTbSymbol.SetSelectHdl( LINK(this, SvxIconSelectorDialog, SelectHdl) );
5152 aBtnImport.SetClickHdl( LINK(this, SvxIconSelectorDialog, ImportHdl) );
5153 aBtnDelete.SetClickHdl( LINK(this, SvxIconSelectorDialog, DeleteHdl) );
5155 m_nNextId = aTbSymbol.GetItemCount()+1;
5158 SvxIconSelectorDialog::~SvxIconSelectorDialog()
5160 sal_uInt16 nCount = aTbSymbol.GetItemCount();
5162 for (sal_uInt16 n = 0; n < nCount; ++n )
5164 sal_uInt16 nId = aTbSymbol.GetItemId(n);
5166 uno::XInterface* xi = static_cast< uno::XInterface* >(
5167 aTbSymbol.GetItemData( nId ) );
5169 if ( xi != NULL )
5171 xi->release();
5176 uno::Reference< graphic::XGraphic> SvxIconSelectorDialog::GetSelectedIcon()
5178 uno::Reference< graphic::XGraphic > result;
5180 sal_uInt16 nId;
5181 for ( sal_uInt16 n = 0; n < aTbSymbol.GetItemCount(); ++n )
5183 nId = aTbSymbol.GetItemId( n );
5184 if ( aTbSymbol.IsItemChecked( nId ) )
5186 result = uno::Reference< graphic::XGraphic >(
5187 reinterpret_cast< graphic::XGraphic* >(
5188 aTbSymbol.GetItemData( nId ) ) );
5192 return result;
5195 IMPL_LINK( SvxIconSelectorDialog, SelectHdl, ToolBox *, pToolBox )
5197 (void)pToolBox;
5199 sal_uInt16 nCount = aTbSymbol.GetItemCount();
5201 for (sal_uInt16 n = 0; n < nCount; ++n )
5203 sal_uInt16 nId = aTbSymbol.GetItemId( n );
5205 if ( aTbSymbol.IsItemChecked( nId ) )
5207 aTbSymbol.CheckItem( nId, sal_False );
5211 sal_uInt16 nId = aTbSymbol.GetCurItemId();
5212 aTbSymbol.CheckItem( nId );
5214 OUString aSelImageText = aTbSymbol.GetItemText( nId );
5215 if ( m_xImportedImageManager->hasImage( GetImageType(), aSelImageText ) )
5217 aBtnDelete.Enable( sal_True );
5219 else
5221 aBtnDelete.Enable( sal_False );
5224 return 0;
5227 IMPL_LINK( SvxIconSelectorDialog, ImportHdl, PushButton *, pButton )
5229 (void)pButton;
5231 sfx2::FileDialogHelper aImportDialog(
5232 css::ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW,
5233 SFXWB_GRAPHIC | SFXWB_MULTISELECTION );
5235 // disable the link checkbox in the dialog
5236 uno::Reference< css::ui::dialogs::XFilePickerControlAccess >
5237 xController( aImportDialog.GetFilePicker(), uno::UNO_QUERY);
5238 if ( xController.is() )
5240 xController->enableControl(
5241 css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_LINK,
5242 sal_False);
5245 aImportDialog.SetCurrentFilter(
5246 OUString("PNG - Portable Network Graphic"));
5248 if ( ERRCODE_NONE == aImportDialog.Execute() )
5250 uno::Sequence< OUString > paths = aImportDialog.GetMPath();
5251 ImportGraphics ( paths );
5254 return 0;
5257 IMPL_LINK( SvxIconSelectorDialog, DeleteHdl, PushButton *, pButton )
5259 (void)pButton;
5261 OUString message = String( CUI_RES( RID_SVXSTR_DELETE_ICON_CONFIRM ) );
5262 bool ret = WarningBox( this, WinBits(WB_OK_CANCEL), message ).Execute();
5264 if ( ret == RET_OK )
5266 sal_uInt16 nCount = aTbSymbol.GetItemCount();
5268 for (sal_uInt16 n = 0; n < nCount; ++n )
5270 sal_uInt16 nId = aTbSymbol.GetItemId( n );
5272 if ( aTbSymbol.IsItemChecked( nId ) )
5274 OUString aSelImageText = aTbSymbol.GetItemText( nId );
5275 uno::Sequence< OUString > URLs(1);
5276 URLs[0] = aSelImageText;
5277 aTbSymbol.RemoveItem( aTbSymbol.GetItemPos( nId ) );
5278 m_xImportedImageManager->removeImages( GetImageType(), URLs );
5279 uno::Reference< css::ui::XUIConfigurationPersistence >
5280 xConfigPersistence( m_xImportedImageManager, uno::UNO_QUERY );
5281 if ( xConfigPersistence.is() && xConfigPersistence->isModified() )
5283 xConfigPersistence->store();
5285 break;
5289 return 0;
5292 bool SvxIconSelectorDialog::ReplaceGraphicItem(
5293 const OUString& aURL )
5295 uno::Sequence< OUString > URLs(1);
5296 uno::Sequence< uno::Reference<graphic::XGraphic > > aImportGraph( 1 );
5297 uno::Reference< css::ui::XUIConfigurationPersistence >
5298 xConfigPer( m_xImportedImageManager, uno::UNO_QUERY );
5300 uno::Reference< graphic::XGraphic > xGraphic;
5301 uno::Sequence< beans::PropertyValue > aMediaProps( 1 );
5302 aMediaProps[0].Name = OUString("URL" );
5303 aMediaProps[0].Value <<= aURL;
5305 com::sun::star::awt::Size aSize;
5306 bool bOK = sal_False;
5309 xGraphic = m_xGraphProvider->queryGraphic( aMediaProps );
5311 uno::Reference< beans::XPropertySet > props =
5312 m_xGraphProvider->queryGraphicDescriptor( aMediaProps );
5313 uno::Any a = props->getPropertyValue(
5314 OUString("SizePixel") );
5315 a >>= aSize;
5316 if (0 == aSize.Width || 0 == aSize.Height)
5317 return sal_False;
5318 else
5319 bOK = sal_True;
5321 catch ( uno::Exception& )
5323 return false;
5326 bool bResult( false );
5327 sal_uInt16 nCount = aTbSymbol.GetItemCount();
5328 for (sal_uInt16 n = 0; n < nCount; ++n )
5330 sal_uInt16 nId = aTbSymbol.GetItemId( n );
5332 if ( OUString( aTbSymbol.GetItemText( nId ) ) == aURL )
5336 // replace/insert image with provided URL
5337 aTbSymbol.RemoveItem( aTbSymbol.GetItemPos( nId ) );
5338 aMediaProps[0].Value <<= aURL;
5340 Image aImage( xGraphic );
5341 if ( bOK && ((aSize.Width != m_nExpectedSize) || (aSize.Height != m_nExpectedSize)) )
5343 BitmapEx aBitmap = aImage.GetBitmapEx();
5344 BitmapEx aBitmapex = BitmapEx::AutoScaleBitmap(aBitmap, m_nExpectedSize);
5345 aImage = Image( aBitmapex);
5347 aTbSymbol.InsertItem( nId,aImage, aURL, 0, 0 ); //modify
5349 xGraphic = aImage.GetXGraphic();
5351 URLs[0] = aURL;
5352 aImportGraph[ 0 ] = xGraphic;
5353 m_xImportedImageManager->replaceImages( GetImageType(), URLs, aImportGraph );
5354 xConfigPer->store();
5356 bResult = true;
5357 break;
5359 catch ( ::com::sun::star::uno::Exception& )
5361 break;
5366 return bResult;
5369 void SvxIconSelectorDialog::ImportGraphics(
5370 const uno::Sequence< OUString >& rPaths )
5372 uno::Sequence< OUString > rejected( rPaths.getLength() );
5373 sal_Int32 rejectedCount = 0;
5375 sal_uInt16 ret = 0;
5376 sal_Int32 aIndex;
5377 OUString aIconName;
5378 uno::Sequence< OUString > URLs(1);
5379 uno::Sequence< uno::Reference<graphic::XGraphic > > aImportGraph( 1 );
5380 uno::Sequence< beans::PropertyValue > aMediaProps( 1 );
5381 aMediaProps[0].Name = OUString("URL" );
5382 uno::Reference< css::ui::XUIConfigurationPersistence >
5383 xConfigPer( m_xImportedImageManager, uno::UNO_QUERY );
5385 if ( rPaths.getLength() == 1 )
5387 if ( m_xImportedImageManager->hasImage( GetImageType(), rPaths[0] ) )
5389 aIndex = rPaths[0].lastIndexOf( '/' );
5390 aIconName = rPaths[0].copy( aIndex+1 );
5391 ret = SvxIconReplacementDialog( this, aIconName ).ShowDialog();
5392 if ( ret == 2 )
5394 ReplaceGraphicItem( rPaths[0] );
5397 else
5399 if ( ImportGraphic( rPaths[0] ) == sal_False )
5401 rejected[0] = rPaths[0];
5402 rejectedCount = 1;
5406 else
5408 OUString aSourcePath( rPaths[0] );
5409 if ( rPaths[0].lastIndexOf( '/' ) != rPaths[0].getLength() -1 )
5410 aSourcePath = rPaths[0] + OUString("/" );
5412 for ( sal_Int32 i = 1; i < rPaths.getLength(); ++i )
5414 OUString aPath = aSourcePath + rPaths[i];
5415 if ( m_xImportedImageManager->hasImage( GetImageType(), aPath ) )
5417 aIndex = rPaths[i].lastIndexOf( '/' );
5418 aIconName = rPaths[i].copy( aIndex+1 );
5419 ret = SvxIconReplacementDialog( this, aIconName, sal_True ).ShowDialog();
5420 if ( ret == 2 )
5422 ReplaceGraphicItem( aPath );
5424 else if ( ret == 5 )
5426 for ( sal_Int32 k = i; k < rPaths.getLength(); ++k )
5428 aPath = aSourcePath + rPaths[k];
5429 bool bHasReplaced = ReplaceGraphicItem( aPath );
5431 if ( !bHasReplaced )
5433 bool result = ImportGraphic( aPath );
5434 if ( result == sal_False )
5436 rejected[ rejectedCount ] = rPaths[i];
5437 ++rejectedCount;
5441 break;
5444 else
5446 bool result = ImportGraphic( aSourcePath + rPaths[i] );
5447 if ( result == sal_False )
5449 rejected[ rejectedCount ] = rPaths[i];
5450 ++rejectedCount;
5456 if ( rejectedCount != 0 )
5458 OUString message;
5459 OUString newLine("\n");
5460 OUString fPath;
5461 if (rejectedCount > 1)
5462 fPath = rPaths[0].copy(8) + OUString("/" );
5463 for ( sal_Int32 i = 0; i < rejectedCount; ++i )
5465 message += fPath + rejected[i];
5466 message += newLine;
5469 SvxIconChangeDialog aDialog(this, message);
5470 aDialog.Execute();
5474 bool SvxIconSelectorDialog::ImportGraphic( const OUString& aURL )
5476 bool result = sal_False;
5478 sal_uInt16 nId = m_nNextId;
5479 ++m_nNextId;
5481 uno::Sequence< beans::PropertyValue > aMediaProps( 1 );
5482 aMediaProps[0].Name = OUString("URL" );
5484 uno::Reference< graphic::XGraphic > xGraphic;
5485 com::sun::star::awt::Size aSize;
5486 bool bOK = sal_True;
5487 aMediaProps[0].Value <<= aURL;
5490 uno::Reference< beans::XPropertySet > props =
5491 m_xGraphProvider->queryGraphicDescriptor( aMediaProps );
5493 uno::Any a = props->getPropertyValue(
5494 OUString("SizePixel") );
5496 xGraphic = m_xGraphProvider->queryGraphic( aMediaProps );
5497 if ( xGraphic.is() )
5499 a >>= aSize;
5500 if ( 0 == aSize.Width || 0 == aSize.Height )
5501 bOK = sal_False;
5503 Image aImage( xGraphic );
5505 if ( bOK && ((aSize.Width != m_nExpectedSize) || (aSize.Height != m_nExpectedSize)) )
5507 BitmapEx aBitmap = aImage.GetBitmapEx();
5508 BitmapEx aBitmapex = BitmapEx::AutoScaleBitmap(aBitmap, m_nExpectedSize);
5509 aImage = Image( aBitmapex);
5511 if ( bOK && !!aImage )
5513 aTbSymbol.InsertItem( nId, aImage, aURL, 0, 0 );
5515 xGraphic = aImage.GetXGraphic();
5516 xGraphic->acquire();
5518 aTbSymbol.SetItemData(
5519 nId, static_cast< void * > ( xGraphic.get() ) );
5520 uno::Sequence< OUString > aImportURL( 1 );
5521 aImportURL[ 0 ] = aURL;
5522 uno::Sequence< uno::Reference<graphic::XGraphic > > aImportGraph( 1 );
5523 aImportGraph[ 0 ] = xGraphic;
5524 m_xImportedImageManager->insertImages( GetImageType(), aImportURL, aImportGraph );
5525 uno::Reference< css::ui::XUIConfigurationPersistence >
5526 xConfigPersistence( m_xImportedImageManager, uno::UNO_QUERY );
5528 if ( xConfigPersistence.is() && xConfigPersistence->isModified() )
5530 xConfigPersistence->store();
5533 result = sal_True;
5535 else
5537 OSL_TRACE("could not create Image from XGraphic");
5540 else
5542 OSL_TRACE("could not get query XGraphic");
5545 catch( uno::Exception& e )
5547 OSL_TRACE("Caught exception importing XGraphic: %s", PRTSTR(e.Message));
5549 return result;
5552 /*******************************************************************************
5554 * The SvxIconReplacementDialog class
5556 *******************************************************************************/
5557 SvxIconReplacementDialog :: SvxIconReplacementDialog(
5558 Window *pWindow, const OUString& aMessage, bool /*bYestoAll*/ )
5560 MessBox( pWindow, WB_DEF_YES, String( CUI_RES( RID_SVXSTR_REPLACE_ICON_CONFIRM ) ), String( CUI_RES( RID_SVXSTR_REPLACE_ICON_WARNING ) ) )
5563 SetImage( WarningBox::GetStandardImage() );
5564 SetMessText( ReplaceIconName( aMessage ) );
5565 RemoveButton( 1 );
5566 AddButton( BUTTON_YES, 2, 0 );
5567 AddButton( String( CUI_RES( RID_SVXSTR_YESTOALL ) ), 5, 0 );
5568 AddButton( BUTTON_NO, 3, 0 );
5569 AddButton( BUTTON_CANCEL, 4, 0 );
5572 SvxIconReplacementDialog :: SvxIconReplacementDialog(
5573 Window *pWindow, const OUString& aMessage )
5575 MessBox( pWindow, WB_YES_NO_CANCEL, String( CUI_RES( RID_SVXSTR_REPLACE_ICON_CONFIRM ) ), String( CUI_RES( RID_SVXSTR_REPLACE_ICON_WARNING ) ) )
5577 SetImage( WarningBox::GetStandardImage() );
5578 SetMessText( ReplaceIconName( aMessage ));
5581 OUString SvxIconReplacementDialog :: ReplaceIconName( const OUString& rMessage )
5583 OUString name;
5584 OUString message = String( CUI_RES( RID_SVXSTR_REPLACE_ICON_WARNING ) );
5585 OUString placeholder("%ICONNAME" );
5586 sal_Int32 pos = message.indexOf( placeholder );
5587 if ( pos != -1 )
5589 name = message.replaceAt(
5590 pos, placeholder.getLength(), rMessage );
5592 return name;
5595 sal_uInt16 SvxIconReplacementDialog :: ShowDialog()
5597 this->Execute();
5598 return ( this->GetCurButtonId() );
5600 /*******************************************************************************
5602 * The SvxIconChangeDialog class added for issue83555
5604 *******************************************************************************/
5605 SvxIconChangeDialog::SvxIconChangeDialog(
5606 Window *pWindow, const OUString& aMessage)
5608 ModalDialog ( pWindow, CUI_RES( MD_ICONCHANGE ) ),
5609 aFImageInfo (this, CUI_RES( FI_INFO ) ),
5610 aBtnOK (this, CUI_RES(MD_BTN_OK)),
5611 aDescriptionLabel (this, CUI_RES(FTCHGE_DESCRIPTION)),
5612 aLineEditDescription (this, CUI_RES(EDT_ADDR))
5614 FreeResource();
5615 aFImageInfo.SetImage(InfoBox::GetStandardImage());
5616 aLineEditDescription.SetControlBackground( GetSettings().GetStyleSettings().GetDialogColor() );
5617 aLineEditDescription.SetAutoScroll( sal_True );
5618 aLineEditDescription.EnableCursor( sal_False );
5619 aLineEditDescription.SetText(aMessage);
5622 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */