LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/cui/source/customize - cfg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 2416 0.0 %
Date: 2013-07-09 Functions: 0 201 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10