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