LibreOffice Module cui (master)  1
cfg.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <sal/config.h>
21 #include <sal/log.hxx>
22 
23 #include <cassert>
24 #include <stdlib.h>
25 #include <typeinfo>
26 
27 #include <vcl/stdtext.hxx>
29 #include <vcl/event.hxx>
30 #include <vcl/graph.hxx>
31 #include <vcl/svapp.hxx>
32 #include <vcl/toolbox.hxx>
33 #include <vcl/weld.hxx>
34 #include <vcl/decoview.hxx>
35 #include <vcl/virdev.hxx>
36 
37 #include <sfx2/sfxhelp.hxx>
38 #include <sfx2/viewfrm.hxx>
39 #include <sfx2/filedlghelper.hxx>
40 #include <sfx2/sfxsids.hrc>
41 #include <svl/stritem.hxx>
42 #include <tools/debug.hxx>
43 #include <tools/diagnose_ex.h>
45 
46 #include <algorithm>
47 #include <strings.hrc>
48 
49 #include <acccfg.hxx>
50 #include <cfg.hxx>
51 #include <SvxMenuConfigPage.hxx>
52 #include <SvxToolbarConfigPage.hxx>
54 #include <SvxConfigPageHelper.hxx>
55 #include "eventdlg.hxx"
56 #include <dialmgr.hxx>
57 
58 #include <unotools/configmgr.hxx>
59 #include <com/sun/star/container/XNameContainer.hpp>
60 #include <com/sun/star/embed/ElementModes.hpp>
61 #include <com/sun/star/embed/FileSystemStorageFactory.hpp>
62 #include <com/sun/star/frame/ModuleManager.hpp>
63 #include <com/sun/star/frame/UnknownModuleException.hpp>
64 #include <com/sun/star/frame/XFrames.hpp>
65 #include <com/sun/star/frame/XLayoutManager.hpp>
66 #include <com/sun/star/frame/FrameSearchFlag.hpp>
67 #include <com/sun/star/frame/XController.hpp>
68 #include <com/sun/star/frame/Desktop.hpp>
69 #include <com/sun/star/frame/theUICommandDescription.hpp>
70 #include <com/sun/star/graphic/GraphicProvider.hpp>
71 #include <com/sun/star/io/IOException.hpp>
72 #include <com/sun/star/ui/ItemType.hpp>
73 #include <com/sun/star/ui/ItemStyle.hpp>
74 #include <com/sun/star/ui/ImageManager.hpp>
75 #include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp>
76 #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
77 #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
78 #include <com/sun/star/ui/XUIElement.hpp>
79 #include <com/sun/star/ui/UIElementType.hpp>
80 #include <com/sun/star/ui/ImageType.hpp>
81 #include <com/sun/star/ui/theWindowStateConfiguration.hpp>
82 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
83 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
84 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
85 #include <com/sun/star/util/thePathSettings.hpp>
89 
90 namespace uno = com::sun::star::uno;
91 namespace frame = com::sun::star::frame;
92 namespace lang = com::sun::star::lang;
94 namespace beans = com::sun::star::beans;
96 
97 #if OSL_DEBUG_LEVEL > 1
98 
100  const OUString& prefix,
101  const uno::Reference< beans::XPropertySet >& xPropSet )
102 {
103  uno::Reference< beans::XPropertySetInfo > xPropSetInfo =
104  xPropSet->getPropertySetInfo();
105 
106  uno::Sequence< beans::Property > aPropDetails =
107  xPropSetInfo->getProperties();
108 
109  SAL_WARN("cui", "printPropertySet: " << aPropDetails.getLength() << " properties" );
110 
111  for ( sal_Int32 i = 0; i < aPropDetails.getLength(); ++i )
112  {
113  OUString tmp;
114  sal_Int32 ival;
115 
116  uno::Any a = xPropSet->getPropertyValue( aPropDetails[i].Name );
117 
118  if ( a >>= tmp )
119  {
120  SAL_WARN("cui", prefix << ": Got property: " << aPropDetails[i].Name << tmp);
121  }
122  else if ( ( a >>= ival ) )
123  {
124  SAL_WARN("cui", prefix << ": Got property: " << aPropDetails[i].Name << " = " << ival);
125  }
126  else
127  {
128  SAL_WARN("cui", prefix << ": Got property: " << aPropDetails[i].Name << " of type " << a.getValueTypeName());
129  }
130  }
131 }
132 
134  const OUString& prefix,
135  const uno::Sequence< beans::PropertyValue >& aProp )
136 {
137  for ( sal_Int32 i = 0; i < aProp.getLength(); ++i )
138  {
139  OUString tmp;
140 
141  aProp[i].Value >>= tmp;
142 
143  SAL_WARN("cui", prefix << ": Got property: " << aProp[i].Name << " = " << tmp);
144  }
145 }
146 
147 void printEntries(SvxEntries* entries)
148 {
149  for (auto const& entry : *entries)
150  {
151  SAL_WARN("cui", "printEntries: " << entry->GetName());
152  }
153 }
154 
155 #endif
156 
157 bool
158 SvxConfigPage::CanConfig( const OUString& aModuleId )
159 {
160  return !(aModuleId == "com.sun.star.script.BasicIDE" || aModuleId == "com.sun.star.frame.Bibliography");
161 }
162 
163 static std::unique_ptr<SfxTabPage> CreateSvxMenuConfigPage( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet )
164 {
165  return std::make_unique<SvxMenuConfigPage>(pPage, pController, *rSet);
166 }
167 
168 static std::unique_ptr<SfxTabPage> CreateSvxContextMenuConfigPage( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet )
169 {
170  return std::make_unique<SvxMenuConfigPage>(pPage, pController, *rSet, false);
171 }
172 
173 static std::unique_ptr<SfxTabPage> CreateKeyboardConfigPage( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet )
174 {
175  return std::make_unique<SfxAcceleratorConfigPage>(pPage, pController, *rSet);
176 }
177 
178 static std::unique_ptr<SfxTabPage> CreateSvxNotebookbarConfigPage(weld::Container* pPage, weld::DialogController* pController,
179  const SfxItemSet* rSet)
180 {
181  return std::make_unique<SvxNotebookbarConfigPage>(pPage, pController, *rSet);
182 }
183 
184 static std::unique_ptr<SfxTabPage> CreateSvxToolbarConfigPage( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet )
185 {
186  return std::make_unique<SvxToolbarConfigPage>(pPage, pController, *rSet);
187 }
188 
189 static std::unique_ptr<SfxTabPage> CreateSvxEventConfigPage( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet )
190 {
191  return std::make_unique<SvxEventConfigPage>(pPage, pController, *rSet, SvxEventConfigPage::EarlyInit());
192 }
193 
194 /******************************************************************************
195  *
196  * SvxConfigDialog is the configuration dialog which is brought up from the
197  * Tools menu. It includes tabs for customizing menus, toolbars, events and
198  * key bindings.
199  *
200  *****************************************************************************/
202  : SfxTabDialogController(pParent, "cui/ui/customizedialog.ui", "CustomizeDialog", pInSet)
203 {
205 
206  AddTabPage("menus", CreateSvxMenuConfigPage, nullptr);
207  AddTabPage("toolbars", CreateSvxToolbarConfigPage, nullptr);
208  AddTabPage("notebookbar", CreateSvxNotebookbarConfigPage, nullptr);
209  AddTabPage("contextmenus", CreateSvxContextMenuConfigPage, nullptr);
210  AddTabPage("keyboard", CreateKeyboardConfigPage, nullptr);
211  AddTabPage("events", CreateSvxEventConfigPage, nullptr);
212 
213  const SfxPoolItem* pItem =
214  pInSet->GetItem( pInSet->GetPool()->GetWhich( SID_CONFIG ) );
215 
216  if ( pItem )
217  {
218  OUString text = static_cast<const SfxStringItem*>(pItem)->GetValue();
219 
220  if (text.startsWith( ITEM_TOOLBAR_URL ) )
221  {
222  SetCurPageId("toolbars");
223  }
224  }
225 }
226 
227 void SvxConfigDialog::SetFrame(const css::uno::Reference<css::frame::XFrame>& xFrame)
228 {
229  m_xFrame = xFrame;
230  uno::Reference<uno::XComponentContext> xContext(::comphelper::getProcessComponentContext(),
231  uno::UNO_SET_THROW);
232 
234  uno::Reference<css::frame::XModuleManager2> xModuleManager(
235  css::frame::ModuleManager::create(xContext));
236  OUString aModuleName = SvxConfigPageHelper::GetUIModuleName(aModuleId, xModuleManager);
237  if (aModuleName != "Writer" && aModuleName != "Calc" && aModuleName != "Impress"
238  && aModuleName != "Draw")
239  RemoveTabPage("notebookbar");
240 
242  RemoveTabPage("keyboard");
243 }
244 
245 void SvxConfigDialog::PageCreated(const OString &rId, SfxTabPage& rPage)
246 {
247  if (rId == "menus" || rId == "keyboard" || rId == "notebookbar"
248  || rId == "toolbars" || rId == "contextmenus")
249  {
250  rPage.SetFrame(m_xFrame);
251  }
252  else if (rId == "events")
253  {
254  dynamic_cast< SvxEventConfigPage& >( rPage ).LateInit( m_xFrame );
255  }
256 }
257 
258 /******************************************************************************
259  *
260  * The SaveInData class is used to hold data for entries in the Save In
261  * ListBox controls in the menu and toolbar tabs
262  *
263  ******************************************************************************/
264 
265 // Initialize static variable which holds default XImageManager
266 uno::Reference< css::ui::XImageManager>* SaveInData::xDefaultImgMgr = nullptr;
267 
269  const uno::Reference< css::ui::XUIConfigurationManager >& xCfgMgr,
270  const uno::Reference< css::ui::XUIConfigurationManager >& xParentCfgMgr,
271  const OUString& aModuleId,
272  bool isDocConfig )
273  :
274  bModified( false ),
275  bDocConfig( isDocConfig ),
276  bReadOnly( false ),
277  m_xCfgMgr( xCfgMgr ),
278  m_xParentCfgMgr( xParentCfgMgr )
279 {
280  m_aSeparatorSeq.realloc( 1 );
282  m_aSeparatorSeq[0].Value <<= css::ui::ItemType::SEPARATOR_LINE;
283 
284  if ( bDocConfig )
285  {
286  uno::Reference< css::ui::XUIConfigurationPersistence >
287  xDocPersistence( GetConfigManager(), uno::UNO_QUERY );
288 
289  bReadOnly = xDocPersistence->isReadOnly();
290  }
291 
292  uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
293 
294  uno::Reference< container::XNameAccess > xNameAccess(
295  css::frame::theUICommandDescription::get(xContext) );
296 
297  xNameAccess->getByName( aModuleId ) >>= m_xCommandToLabelMap;
298 
299  if ( !m_xImgMgr.is() )
300  {
301  m_xImgMgr.set( GetConfigManager()->getImageManager(), uno::UNO_QUERY );
302  }
303 
304  if ( !IsDocConfig() )
305  {
306  // If this is not a document configuration then it is the settings
307  // for the module (writer, calc, impress etc.) Use this as the default
308  // XImageManager instance
310  }
311  else
312  {
313  // If this is a document configuration then use the module image manager
314  // as default.
315  if ( m_xParentCfgMgr.is() )
316  {
317  m_xParentImgMgr.set( m_xParentCfgMgr->getImageManager(), uno::UNO_QUERY );
319  }
320  }
321 }
322 
323 uno::Reference<graphic::XGraphic> SaveInData::GetImage(const OUString& rCommandURL)
324 {
325  uno::Reference< graphic::XGraphic > xGraphic =
327 
328  if (!xGraphic.is() && xDefaultImgMgr != nullptr && (*xDefaultImgMgr).is())
329  {
330  xGraphic = SvxConfigPageHelper::GetGraphic( (*xDefaultImgMgr), rCommandURL );
331  }
332 
333  return xGraphic;
334 }
335 
337  const uno::Reference< uno::XInterface >& xManager )
338 {
339  bool result = true;
340 
341  try
342  {
343  if ( xManager.is() && !IsReadOnly() )
344  {
345  uno::Reference< css::ui::XUIConfigurationPersistence >
346  xConfigPersistence( xManager, uno::UNO_QUERY );
347 
348  if ( xConfigPersistence->isModified() )
349  {
350  xConfigPersistence->store();
351  }
352  }
353  }
354  catch ( css::io::IOException& )
355  {
356  result = false;
357  }
358 
359  return result;
360 }
361 
362 /******************************************************************************
363  *
364  * The MenuSaveInData class extends SaveInData and provides menu specific
365  * load and store functionality.
366  *
367  ******************************************************************************/
368 
369 // Initialize static variable which holds default Menu data
371 
373  const uno::Reference< css::ui::XUIConfigurationManager >& cfgmgr,
374  const uno::Reference< css::ui::XUIConfigurationManager >& xParentCfgMgr,
375  const OUString& aModuleId,
376  bool isDocConfig )
377  :
378  SaveInData( cfgmgr, xParentCfgMgr, aModuleId, isDocConfig ),
379  m_aMenuResourceURL(
381  m_aDescriptorContainer(
383 {
384  try
385  {
386  OUString url( ITEM_MENUBAR_URL );
387  m_xMenuSettings = GetConfigManager()->getSettings( url, false );
388  }
389  catch ( container::NoSuchElementException& )
390  {
391  // will use menu settings for the module
392  }
393 
394  // If this is not a document configuration then it is the settings
395  // for the module (writer, calc, impress etc.). These settings should
396  // be set as the default to be used for SaveIn locations that do not
397  // have custom settings
398  if ( !IsDocConfig() )
399  {
400  SetDefaultData( this );
401  }
402 }
403 
405 {
406 }
407 
408 SvxEntries*
410 {
411  if ( pRootEntry == nullptr )
412  {
413  pRootEntry.reset( new SvxConfigEntry( "MainMenus", OUString(), true, /*bParentData*/false) );
414 
415  if ( m_xMenuSettings.is() )
416  {
417  LoadSubMenus( m_xMenuSettings, OUString(), pRootEntry.get(), false );
418  }
419  else if ( GetDefaultData() != nullptr )
420  {
421  // If the doc has no config settings use module config settings
422  LoadSubMenus( GetDefaultData()->m_xMenuSettings, OUString(), pRootEntry.get(), false );
423  }
424  }
425 
426  return pRootEntry->GetEntries();
427 }
428 
429 void
430 MenuSaveInData::SetEntries( std::unique_ptr<SvxEntries> pNewEntries )
431 {
432  pRootEntry->SetEntries( std::move(pNewEntries) );
433 }
434 
435 void SaveInData::LoadSubMenus( const uno::Reference< container::XIndexAccess >& xMenuSettings,
436  const OUString& rBaseTitle, SvxConfigEntry const * pParentData, bool bContextMenu )
437 {
438  SvxEntries* pEntries = pParentData->GetEntries();
439 
440  // Don't access non existing menu configuration!
441  if ( !xMenuSettings.is() )
442  return;
443 
444  for ( sal_Int32 nIndex = 0; nIndex < xMenuSettings->getCount(); ++nIndex )
445  {
446  uno::Reference< container::XIndexAccess > xSubMenu;
447  OUString aCommandURL;
448  OUString aLabel;
449 
450  sal_uInt16 nType( css::ui::ItemType::DEFAULT );
451  sal_Int32 nStyle(0);
452 
453  bool bItem = SvxConfigPageHelper::GetMenuItemData( xMenuSettings, nIndex,
454  aCommandURL, aLabel, nType, nStyle, xSubMenu );
455 
456  if ( bItem )
457  {
458  bool bIsUserDefined = true;
459 
460  if ( nType == css::ui::ItemType::DEFAULT )
461  {
462  uno::Any a;
463  try
464  {
465  a = m_xCommandToLabelMap->getByName( aCommandURL );
466  bIsUserDefined = false;
467  }
468  catch ( container::NoSuchElementException& )
469  {
470  bIsUserDefined = true;
471  }
472 
473  bool bUseDefaultLabel = false;
474  // If custom label not set retrieve it from the command
475  // to info service
476  if ( aLabel.isEmpty() )
477  {
478  bUseDefaultLabel = true;
479  uno::Sequence< beans::PropertyValue > aPropSeq;
480  if ( a >>= aPropSeq )
481  {
482  OUString aMenuLabel;
483  for ( sal_Int32 i = 0; i < aPropSeq.getLength(); ++i )
484  {
485  if ( bContextMenu )
486  {
487  if ( aPropSeq[i].Name == "PopupLabel" )
488  {
489  aPropSeq[i].Value >>= aLabel;
490  break;
491  }
492  else if ( aPropSeq[i].Name == "Label" )
493  {
494  aPropSeq[i].Value >>= aMenuLabel;
495  }
496  }
497  else if ( aPropSeq[i].Name == "Label" )
498  {
499  aPropSeq[i].Value >>= aLabel;
500  break;
501  }
502  }
503  if ( aLabel.isEmpty() )
504  aLabel = aMenuLabel;
505  }
506  }
507 
508  SvxConfigEntry* pEntry = new SvxConfigEntry(
509  aLabel, aCommandURL, xSubMenu.is(), /*bParentData*/false );
510 
511  pEntry->SetStyle( nStyle );
512  pEntry->SetUserDefined( bIsUserDefined );
513  if ( !bUseDefaultLabel )
514  pEntry->SetName( aLabel );
515 
516  pEntries->push_back( pEntry );
517 
518  if ( xSubMenu.is() )
519  {
520  // popup menu
521  OUString subMenuTitle( rBaseTitle );
522 
523  if ( !subMenuTitle.isEmpty() )
524  {
525  subMenuTitle += aMenuSeparatorStr;
526  }
527  else
528  {
529  pEntry->SetMain();
530  }
531 
532  subMenuTitle += SvxConfigPageHelper::stripHotKey( aLabel );
533 
534  LoadSubMenus( xSubMenu, subMenuTitle, pEntry, bContextMenu );
535  }
536  }
537  else
538  {
539  SvxConfigEntry* pEntry = new SvxConfigEntry;
540  pEntry->SetUserDefined( bIsUserDefined );
541  pEntries->push_back( pEntry );
542  }
543  }
544  }
545 }
546 
548 {
549  bool result = false;
550 
551  if ( IsModified() )
552  {
553  // Apply new menu bar structure to our settings container
554  m_xMenuSettings = GetConfigManager()->createSettings();
555 
556  uno::Reference< container::XIndexContainer > xIndexContainer (
557  m_xMenuSettings, uno::UNO_QUERY );
558 
559  uno::Reference< lang::XSingleComponentFactory > xFactory (
560  m_xMenuSettings, uno::UNO_QUERY );
561 
562  Apply( xIndexContainer, xFactory );
563 
564  try
565  {
566  if ( GetConfigManager()->hasSettings( m_aMenuResourceURL ) )
567  {
568  GetConfigManager()->replaceSettings(
570  }
571  else
572  {
573  GetConfigManager()->insertSettings(
575  }
576  }
577  catch ( css::uno::Exception& )
578  {
579  TOOLS_WARN_EXCEPTION("cui.customize", "caught some other exception saving settings");
580  }
581 
582  SetModified( false );
583 
584  result = PersistChanges( GetConfigManager() );
585  }
586 
587  return result;
588 }
589 
591  uno::Reference< container::XIndexContainer > const & rMenuBar,
592  uno::Reference< lang::XSingleComponentFactory >& rFactory )
593 {
594  uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
595 
596  for (auto const& entryData : *GetEntries())
597  {
598  uno::Sequence< beans::PropertyValue > aPropValueSeq =
600 
601  uno::Reference< container::XIndexContainer > xSubMenuBar(
602  rFactory->createInstanceWithContext( xContext ),
603  uno::UNO_QUERY );
604 
605  sal_Int32 nIndex = aPropValueSeq.getLength();
606  aPropValueSeq.realloc( nIndex + 1 );
607  aPropValueSeq[nIndex].Name = m_aDescriptorContainer;
608  aPropValueSeq[nIndex].Value <<= xSubMenuBar;
609  rMenuBar->insertByIndex(
610  rMenuBar->getCount(), uno::Any( aPropValueSeq ));
611  ApplyMenu( xSubMenuBar, rFactory, entryData );
612  }
613 }
614 
616  uno::Reference< container::XIndexContainer > const & rMenuBar,
617  uno::Reference< lang::XSingleComponentFactory >& rFactory,
618  SvxConfigEntry* pMenuData )
619 {
620  uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
621 
622  for (auto const& entry : *pMenuData->GetEntries())
623  {
624  if (entry->IsPopup())
625  {
626  uno::Sequence< beans::PropertyValue > aPropValueSeq =
628 
629  uno::Reference< container::XIndexContainer > xSubMenuBar(
630  rFactory->createInstanceWithContext( xContext ),
631  uno::UNO_QUERY );
632 
633  sal_Int32 nIndex = aPropValueSeq.getLength();
634  aPropValueSeq.realloc( nIndex + 1 );
635  aPropValueSeq[nIndex].Name = ITEM_DESCRIPTOR_CONTAINER;
636  aPropValueSeq[nIndex].Value <<= xSubMenuBar;
637 
638  rMenuBar->insertByIndex(
639  rMenuBar->getCount(), uno::Any( aPropValueSeq ));
640 
641  ApplyMenu( xSubMenuBar, rFactory, entry );
642  entry->SetModified( false );
643  }
644  else if (entry->IsSeparator())
645  {
646  rMenuBar->insertByIndex(
647  rMenuBar->getCount(), uno::Any( m_aSeparatorSeq ));
648  }
649  else
650  {
651  uno::Sequence< beans::PropertyValue > aPropValueSeq =
653  rMenuBar->insertByIndex(
654  rMenuBar->getCount(), uno::Any( aPropValueSeq ));
655  }
656  }
657  pMenuData->SetModified( false );
658 }
659 
660 void
662 {
663  try
664  {
665  GetConfigManager()->removeSettings( m_aMenuResourceURL );
666  }
667  catch ( const css::uno::Exception& )
668  {}
669 
671 
672  pRootEntry.reset();
673 
674  try
675  {
676  m_xMenuSettings = GetConfigManager()->getSettings(
677  m_aMenuResourceURL, false );
678  }
679  catch ( container::NoSuchElementException& )
680  {
681  // will use default settings
682  }
683 }
684 
686  const css::uno::Reference< css::ui::XUIConfigurationManager >& xCfgMgr,
687  const css::uno::Reference< css::ui::XUIConfigurationManager >& xParentCfgMgr,
688  const OUString& aModuleId, bool bIsDocConfig )
689  : SaveInData( xCfgMgr, xParentCfgMgr, aModuleId, bIsDocConfig )
690 {
691  css::uno::Reference< css::uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
692  css::uno::Reference< css::container::XNameAccess > xConfig( css::ui::theWindowStateConfiguration::get( xContext ) );
693  xConfig->getByName( aModuleId ) >>= m_xPersistentWindowState;
694 }
695 
697 {
698 }
699 
700 OUString ContextMenuSaveInData::GetUIName( const OUString& rResourceURL )
701 {
702  if ( m_xPersistentWindowState.is() )
703  {
704  css::uno::Sequence< css::beans::PropertyValue > aProps;
705  try
706  {
707  m_xPersistentWindowState->getByName( rResourceURL ) >>= aProps;
708  }
709  catch ( const css::uno::Exception& )
710  {}
711 
712  for ( const auto& aProp : std::as_const(aProps) )
713  {
714  if ( aProp.Name == ITEM_DESCRIPTOR_UINAME )
715  {
716  OUString aResult;
717  aProp.Value >>= aResult;
718  return aResult;
719  }
720  }
721  }
722  return OUString();
723 }
724 
726 {
727  if ( !m_pRootEntry )
728  {
729  std::unordered_map< OUString, bool > aMenuInfo;
730 
731  m_pRootEntry.reset( new SvxConfigEntry( "ContextMenus", OUString(), true, /*bParentData*/false ) );
732  css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > aElementsInfo;
733  try
734  {
735  aElementsInfo = GetConfigManager()->getUIElementsInfo( css::ui::UIElementType::POPUPMENU );
736  }
737  catch ( const css::lang::IllegalArgumentException& )
738  {}
739 
740  for ( const auto& aElement : std::as_const(aElementsInfo) )
741  {
742  OUString aUrl;
743  for ( const auto& aElementProp : aElement )
744  {
745  if ( aElementProp.Name == ITEM_DESCRIPTOR_RESOURCEURL )
746  {
747  aElementProp.Value >>= aUrl;
748  break;
749  }
750  }
751 
752  css::uno::Reference< css::container::XIndexAccess > xPopupMenu;
753  try
754  {
755  xPopupMenu = GetConfigManager()->getSettings( aUrl, false );
756  }
757  catch ( const css::uno::Exception& )
758  {}
759 
760  if ( xPopupMenu.is() )
761  {
762  // insert into std::unordered_map to filter duplicates from the parent
763  aMenuInfo.emplace( aUrl, true );
764 
765  OUString aUIMenuName = GetUIName( aUrl );
766  if ( aUIMenuName.isEmpty() )
767  // Menus without UI name aren't supposed to be customized.
768  continue;
769 
770  SvxConfigEntry* pEntry = new SvxConfigEntry( aUIMenuName, aUrl, true, /*bParentData*/false );
771  pEntry->SetMain();
772  m_pRootEntry->GetEntries()->push_back( pEntry );
773  LoadSubMenus( xPopupMenu, aUIMenuName, pEntry, true );
774  }
775  }
776 
777  // Retrieve also the parent menus, to make it possible to configure module menus and save them into the document.
778  css::uno::Reference< css::ui::XUIConfigurationManager > xParentCfgMgr = GetParentConfigManager();
779  css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > aParentElementsInfo;
780  try
781  {
782  if ( xParentCfgMgr.is() )
783  aParentElementsInfo = xParentCfgMgr->getUIElementsInfo( css::ui::UIElementType::POPUPMENU );
784  }
785  catch ( const css::lang::IllegalArgumentException& )
786  {}
787 
788  for ( const auto& aElement : std::as_const(aParentElementsInfo) )
789  {
790  OUString aUrl;
791  for ( const auto& aElementProp : aElement )
792  {
793  if ( aElementProp.Name == ITEM_DESCRIPTOR_RESOURCEURL )
794  {
795  aElementProp.Value >>= aUrl;
796  break;
797  }
798  }
799 
800  css::uno::Reference< css::container::XIndexAccess > xPopupMenu;
801  try
802  {
803  if ( aMenuInfo.find( aUrl ) == aMenuInfo.end() )
804  xPopupMenu = xParentCfgMgr->getSettings( aUrl, false );
805  }
806  catch ( const css::uno::Exception& )
807  {}
808 
809  if ( xPopupMenu.is() )
810  {
811  OUString aUIMenuName = GetUIName( aUrl );
812  if ( aUIMenuName.isEmpty() )
813  continue;
814 
815  SvxConfigEntry* pEntry = new SvxConfigEntry( aUIMenuName, aUrl, true, true );
816  pEntry->SetMain();
817  m_pRootEntry->GetEntries()->push_back( pEntry );
818  LoadSubMenus( xPopupMenu, aUIMenuName, pEntry, true );
819  }
820  }
821  std::sort( m_pRootEntry->GetEntries()->begin(), m_pRootEntry->GetEntries()->end(), SvxConfigPageHelper::EntrySort );
822  }
823  return m_pRootEntry->GetEntries();
824 }
825 
826 void ContextMenuSaveInData::SetEntries( std::unique_ptr<SvxEntries> pNewEntries )
827 {
828  m_pRootEntry->SetEntries( std::move(pNewEntries) );
829 }
830 
831 bool ContextMenuSaveInData::HasURL( const OUString& rURL )
832 {
833  SvxEntries* pEntries = GetEntries();
834  for ( const auto& pEntry : *pEntries )
835  if ( pEntry->GetCommand() == rURL )
836  return true;
837 
838  return false;
839 }
840 
842 {
843  return m_pRootEntry && !m_pRootEntry->GetEntries()->empty();
844 }
845 
847 {
848  if ( !IsModified() )
849  return false;
850 
851  SvxEntries* pEntries = GetEntries();
852  for ( const auto& pEntry : *pEntries )
853  {
854  if ( pEntry->IsModified() || SvxConfigPageHelper::SvxConfigEntryModified( pEntry ) )
855  {
856  css::uno::Reference< css::container::XIndexContainer > xIndexContainer = GetConfigManager()->createSettings();
857  css::uno::Reference< css::lang::XSingleComponentFactory > xFactory( xIndexContainer, css::uno::UNO_QUERY );
858  ApplyMenu( xIndexContainer, xFactory, pEntry );
859 
860  const OUString& aUrl = pEntry->GetCommand();
861  try
862  {
863  if ( GetConfigManager()->hasSettings( aUrl ) )
864  GetConfigManager()->replaceSettings( aUrl, xIndexContainer );
865  else
866  GetConfigManager()->insertSettings( aUrl, xIndexContainer );
867  }
868  catch ( const css::uno::Exception& )
869  {}
870  }
871  }
872  SetModified( false );
873  return PersistChanges( GetConfigManager() );
874 }
875 
877 {
878  SvxEntries* pEntries = GetEntries();
879  for ( const auto& pEntry : *pEntries )
880  {
881  try
882  {
883  GetConfigManager()->removeSettings( pEntry->GetCommand() );
884  }
885  catch ( const css::uno::Exception& )
886  {
887  TOOLS_WARN_EXCEPTION("cui.customize", "Exception caught while resetting context menus");
888  }
889  }
891  m_pRootEntry.reset();
892 }
893 
895 {
896  try
897  {
898  GetConfigManager()->removeSettings( pEntry->GetCommand() );
899  }
900  catch ( const css::uno::Exception& )
901  {
902  TOOLS_WARN_EXCEPTION("cui.customize", "Exception caught while resetting context menu");
903  }
905  m_pRootEntry.reset();
906 }
907 
909 {
910  int nWidth = m_xControl->get_text_height() / 2;
911  m_xDropDown->SetOutputSizePixel(Size(nWidth, nWidth));
912  DecorationView aDecoView(m_xDropDown.get());
913  aDecoView.DrawSymbol(tools::Rectangle(Point(0, 0), Size(nWidth, nWidth)),
914  SymbolType::SPIN_RIGHT, m_xDropDown->GetTextColor(),
915  DrawSymbolFlags::NONE);
916 }
917 
918 /******************************************************************************
919  *
920  * SvxMenuEntriesListBox is the listbox in which the menu items for a
921  * particular menu are shown. We have a custom listbox because we need
922  * to add drag'n'drop support from the Macro Selector and within the
923  * listbox
924  *
925  *****************************************************************************/
926 SvxMenuEntriesListBox::SvxMenuEntriesListBox(std::unique_ptr<weld::TreeView> xControl, SvxConfigPage* pPg)
927  : m_xControl(std::move(xControl))
928  , m_xDropDown(m_xControl->create_virtual_device())
929  , m_pPage(pPg)
930 {
931  CreateDropDown();
932  m_xControl->connect_key_press(LINK(this, SvxMenuEntriesListBox, KeyInputHdl));
933 }
934 
936 {
937 }
938 
939 IMPL_LINK(SvxMenuEntriesListBox, KeyInputHdl, const KeyEvent&, rKeyEvent, bool)
940 {
941  vcl::KeyCode keycode = rKeyEvent.GetKeyCode();
942 
943  // support DELETE for removing the current entry
944  if ( keycode == KEY_DELETE )
945  {
946  m_pPage->DeleteSelectedContent();
947  }
948  // support CTRL+UP and CTRL+DOWN for moving selected entries
949  else if ( keycode.GetCode() == KEY_UP && keycode.IsMod1() )
950  {
951  m_pPage->MoveEntry( true );
952  }
953  else if ( keycode.GetCode() == KEY_DOWN && keycode.IsMod1() )
954  {
955  m_pPage->MoveEntry( false );
956  }
957  else
958  {
959  return false; // pass on to default handler
960  }
961  return true;
962 }
963 
964 /******************************************************************************
965  *
966  * SvxConfigPage is the abstract base class on which the Menu and Toolbar
967  * configuration tabpages are based. It includes methods which are common to
968  * both tabpages to add, delete, move and rename items etc.
969  *
970  *****************************************************************************/
972  : SfxTabPage(pPage, pController, "cui/ui/menuassignpage.ui", "MenuAssignPage", &rSet)
973  , m_aUpdateDataTimer("UpdateDataTimer")
974  , bInitialised(false)
975  , pCurrentSaveInData(nullptr)
976  , m_xCommandCategoryListBox(new CommandCategoryListBox(m_xBuilder->weld_combo_box("commandcategorylist")))
977  , m_xFunctions(new CuiConfigFunctionListBox(m_xBuilder->weld_tree_view("functions")))
978  , m_xCategoryLabel(m_xBuilder->weld_label("categorylabel"))
979  , m_xDescriptionFieldLb(m_xBuilder->weld_label("descriptionlabel"))
980  , m_xDescriptionField(m_xBuilder->weld_text_view("desc"))
981  , m_xLeftFunctionLabel(m_xBuilder->weld_label("leftfunctionlabel"))
982  , m_xSearchEdit(m_xBuilder->weld_entry("searchEntry"))
983  , m_xSearchLabel(m_xBuilder->weld_label("searchlabel"))
984  , m_xCustomizeLabel(m_xBuilder->weld_label("customizelabel"))
985  , m_xTopLevelListBox(m_xBuilder->weld_combo_box("toplevellist"))
986  , m_xMoveUpButton(m_xBuilder->weld_button("up"))
987  , m_xMoveDownButton(m_xBuilder->weld_button("down"))
988  , m_xSaveInListBox(m_xBuilder->weld_combo_box("savein"))
989  , m_xInsertBtn(m_xBuilder->weld_menu_button("insert"))
990  , m_xModifyBtn(m_xBuilder->weld_menu_button("modify"))
991  , m_xResetBtn(m_xBuilder->weld_button("defaultsbtn"))
992  , m_xAddCommandButton(m_xBuilder->weld_button("add"))
993  , m_xRemoveCommandButton(m_xBuilder->weld_button("remove"))
994 {
995  m_xTopLevelListBox->connect_changed(LINK(this, SvxConfigPage, SelectElementHdl));
996 
997  weld::TreeView& rTreeView = m_xFunctions->get_widget();
998  Size aSize(rTreeView.get_approximate_digit_width() * 40, rTreeView.get_height_rows(8));
999  m_xFunctions->set_size_request(aSize.Width(), aSize.Height());
1000  m_xDescriptionField->set_size_request(aSize.Width(), m_xDescriptionField->get_height_rows(3));
1001 
1002  m_aUpdateDataTimer.SetInvokeHandler(LINK(this, SvxConfigPage, ImplUpdateDataHdl));
1003  m_aUpdateDataTimer.SetDebugName( "SvxConfigPage UpdateDataTimer" );
1005 
1006  m_xSearchEdit->connect_changed(LINK(this, SvxConfigPage, SearchUpdateHdl));
1007  m_xSearchEdit->connect_focus_out(LINK(this, SvxConfigPage, FocusOut_Impl));
1008 
1009  rTreeView.connect_row_activated(LINK(this, SvxConfigPage, FunctionDoubleClickHdl));
1010  rTreeView.connect_changed(LINK(this, SvxConfigPage, SelectFunctionHdl));
1011 }
1012 
1014 {
1015  SelectElement();
1016 }
1017 
1019 {
1020 }
1021 
1023 {
1024  // If we haven't initialised our XMultiServiceFactory reference
1025  // then Reset is being called at the opening of the dialog.
1026 
1027  // Load menu configuration data for the module of the currently
1028  // selected document, for the currently selected document, and for
1029  // all other open documents of the same module type
1030  if ( !bInitialised )
1031  {
1032  sal_Int32 nPos = 0;
1033  uno::Reference < css::ui::XUIConfigurationManager > xCfgMgr;
1034  uno::Reference < css::ui::XUIConfigurationManager > xDocCfgMgr;
1035 
1036  uno::Reference< uno::XComponentContext > xContext(
1037  ::comphelper::getProcessComponentContext(), uno::UNO_SET_THROW );
1038 
1039  m_xFrame = GetFrame();
1040  OUString aModuleId = GetFrameWithDefaultAndIdentify( m_xFrame );
1041 
1042  // replace %MODULENAME in the label with the correct module name
1043  uno::Reference< css::frame::XModuleManager2 > xModuleManager(
1044  css::frame::ModuleManager::create( xContext ));
1045  OUString aModuleName = SvxConfigPageHelper::GetUIModuleName( aModuleId, xModuleManager );
1046 
1047  uno::Reference< css::ui::XModuleUIConfigurationManagerSupplier >
1048  xModuleCfgSupplier( css::ui::theModuleUIConfigurationManagerSupplier::get(xContext) );
1049 
1050  // Set up data for module specific menus
1051  SaveInData* pModuleData = nullptr;
1052 
1053  try
1054  {
1055  xCfgMgr =
1056  xModuleCfgSupplier->getUIConfigurationManager( aModuleId );
1057 
1058  pModuleData = CreateSaveInData( xCfgMgr,
1059  uno::Reference< css::ui::XUIConfigurationManager >(),
1060  aModuleId,
1061  false );
1062  }
1063  catch ( container::NoSuchElementException& )
1064  {
1065  }
1066 
1067  if ( pModuleData != nullptr )
1068  {
1069  OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pModuleData)));
1070  m_xSaveInListBox->append(sId, utl::ConfigManager::getProductName() + " " + aModuleName);
1071  }
1072 
1073  // try to retrieve the document based ui configuration manager
1074  OUString aTitle;
1075  uno::Reference< frame::XController > xController =
1076  m_xFrame->getController();
1077  if ( CanConfig( aModuleId ) && xController.is() )
1078  {
1079  uno::Reference< frame::XModel > xModel( xController->getModel() );
1080  if ( xModel.is() )
1081  {
1082  uno::Reference< css::ui::XUIConfigurationManagerSupplier >
1083  xCfgSupplier( xModel, uno::UNO_QUERY );
1084 
1085  if ( xCfgSupplier.is() )
1086  {
1087  xDocCfgMgr = xCfgSupplier->getUIConfigurationManager();
1088  }
1089  aTitle = ::comphelper::DocumentInfo::getDocumentTitle( xModel );
1090  }
1091  }
1092 
1093  SaveInData* pDocData = nullptr;
1094  if ( xDocCfgMgr.is() )
1095  {
1096  pDocData = CreateSaveInData( xDocCfgMgr, xCfgMgr, aModuleId, true );
1097 
1098  if ( !pDocData->IsReadOnly() )
1099  {
1100  OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pDocData)));
1101  m_xSaveInListBox->append(sId, aTitle);
1102  }
1103  }
1104 
1105  // if an item to select has been passed in (eg. the ResourceURL for a
1106  // toolbar) then try to select the SaveInData entry that has that item
1107  bool bURLToSelectFound = false;
1108  if ( !m_aURLToSelect.isEmpty() )
1109  {
1110  if ( pDocData && pDocData->HasURL( m_aURLToSelect ) )
1111  {
1112  m_xSaveInListBox->set_active(nPos);
1113  pCurrentSaveInData = pDocData;
1114  bURLToSelectFound = true;
1115  }
1116  else if ( pModuleData && pModuleData->HasURL( m_aURLToSelect ) )
1117  {
1118  m_xSaveInListBox->set_active(0);
1119  pCurrentSaveInData = pModuleData;
1120  bURLToSelectFound = true;
1121  }
1122  }
1123 
1124  if ( !bURLToSelectFound )
1125  {
1126  // if the document has menu configuration settings select it
1127  // it the SaveIn listbox, otherwise select the module data
1128  if ( pDocData != nullptr && pDocData->HasSettings() )
1129  {
1130  m_xSaveInListBox->set_active(nPos);
1131  pCurrentSaveInData = pDocData;
1132  }
1133  else
1134  {
1135  m_xSaveInListBox->set_active(0);
1136  pCurrentSaveInData = pModuleData;
1137  }
1138  }
1139 
1140 #ifdef DBG_UTIL
1141  DBG_ASSERT( pCurrentSaveInData, "SvxConfigPage::Reset(): no SaveInData" );
1142 #endif
1143 
1144  if ( CanConfig( aModuleId ) )
1145  {
1146  // Load configuration for other open documents which have
1147  // same module type
1148  uno::Sequence< uno::Reference< frame::XFrame > > aFrameList;
1149  try
1150  {
1151  uno::Reference< frame::XDesktop2 > xFramesSupplier = frame::Desktop::create(
1152  xContext );
1153 
1154  uno::Reference< frame::XFrames > xFrames =
1155  xFramesSupplier->getFrames();
1156 
1157  aFrameList = xFrames->queryFrames(
1158  frame::FrameSearchFlag::ALL & ~frame::FrameSearchFlag::SELF );
1159 
1160  }
1161  catch( const uno::Exception& )
1162  {
1163  DBG_UNHANDLED_EXCEPTION("cui.customize");
1164  }
1165 
1166  for ( sal_Int32 i = 0; i < aFrameList.getLength(); ++i )
1167  {
1168  uno::Reference < frame::XFrame > xf = aFrameList[i];
1169 
1170  if ( xf.is() && xf != m_xFrame )
1171  {
1172  OUString aCheckId;
1173  try{
1174  aCheckId = xModuleManager->identify( xf );
1175  } catch(const uno::Exception&)
1176  { aCheckId.clear(); }
1177 
1178  if ( aModuleId == aCheckId )
1179  {
1180  // try to get the document based ui configuration manager
1181  OUString aTitle2;
1182  uno::Reference< frame::XController > xController_ =
1183  xf->getController();
1184 
1185  if ( xController_.is() )
1186  {
1187  uno::Reference< frame::XModel > xModel(
1188  xController_->getModel() );
1189 
1190  if ( xModel.is() )
1191  {
1192  uno::Reference<
1193  css::ui::XUIConfigurationManagerSupplier >
1194  xCfgSupplier( xModel, uno::UNO_QUERY );
1195 
1196  if ( xCfgSupplier.is() )
1197  {
1198  xDocCfgMgr =
1199  xCfgSupplier->getUIConfigurationManager();
1200  }
1201  aTitle2 = ::comphelper::DocumentInfo::getDocumentTitle( xModel );
1202  }
1203  }
1204 
1205  if ( xDocCfgMgr.is() )
1206  {
1207  SaveInData* pData = CreateSaveInData( xDocCfgMgr, xCfgMgr, aModuleId, true );
1208 
1209  if ( pData && !pData->IsReadOnly() )
1210  {
1211  OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pData)));
1212  m_xSaveInListBox->append(sId, aTitle2);
1213  }
1214  }
1215  }
1216  }
1217  }
1218  }
1219 
1220  m_xSaveInListBox->connect_changed(
1221  LINK( this, SvxConfigPage, SelectSaveInLocation ) );
1222 
1223  bInitialised = true;
1224 
1225  Init();
1226  }
1227  else
1228  {
1229  if ( QueryReset() == RET_YES )
1230  {
1231  // Reset menu configuration for currently selected SaveInData
1232  GetSaveInData()->Reset();
1233 
1234  Init();
1235  }
1236  }
1237 }
1238 
1239 OUString SvxConfigPage::GetFrameWithDefaultAndIdentify( uno::Reference< frame::XFrame >& _inout_rxFrame )
1240 {
1241  OUString sModuleID;
1242  try
1243  {
1244  uno::Reference< uno::XComponentContext > xContext(
1246 
1247  uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create(
1248  xContext );
1249 
1250  if ( !_inout_rxFrame.is() )
1251  _inout_rxFrame = xDesktop->getActiveFrame();
1252 
1253  if ( !_inout_rxFrame.is() )
1254  {
1255  _inout_rxFrame = xDesktop->getCurrentFrame();
1256  }
1257 
1258  if ( !_inout_rxFrame.is() && SfxViewFrame::Current() )
1259  _inout_rxFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface();
1260 
1261  if ( !_inout_rxFrame.is() )
1262  {
1263  SAL_WARN( "cui.customize", "SvxConfigPage::GetFrameWithDefaultAndIdentify(): no frame found!" );
1264  return sModuleID;
1265  }
1266 
1267  uno::Reference< css::frame::XModuleManager2 > xModuleManager(
1268  css::frame::ModuleManager::create( xContext ) );
1269 
1270  try
1271  {
1272  sModuleID = xModuleManager->identify( _inout_rxFrame );
1273  }
1274  catch ( const frame::UnknownModuleException& )
1275  {
1276  }
1277 
1278  }
1279  catch( const uno::Exception& )
1280  {
1281  DBG_UNHANDLED_EXCEPTION("cui.customize");
1282  }
1283 
1284  return sModuleID;
1285 }
1286 
1288 {
1289  OUString result;
1290 
1291  SfxGroupInfo_Impl *pData = reinterpret_cast<SfxGroupInfo_Impl*>(m_xFunctions->get_selected_id().toInt64());
1292  if (pData)
1293  {
1294  if ( ( pData->nKind == SfxCfgKind::FUNCTION_SLOT ) ||
1295  ( pData->nKind == SfxCfgKind::FUNCTION_SCRIPT ) ||
1296  ( pData->nKind == SfxCfgKind::GROUP_STYLES ) )
1297  {
1298  result = pData->sCommand;
1299  }
1300  }
1301 
1302  return result;
1303 }
1304 
1306 {
1307  return m_xFunctions->get_selected_text();
1308 }
1309 
1311 {
1312  bool result = false;
1313 
1314  for (int i = 0, nCount = m_xSaveInListBox->get_count(); i < nCount; ++i)
1315  {
1316  SaveInData* pData =
1317  reinterpret_cast<SaveInData*>(m_xSaveInListBox->get_id(i).toInt64());
1318  if(m_xSaveInListBox->get_id(i) != notebookbarTabScope)
1319  result = pData->Apply();
1320  }
1321  return result;
1322 }
1323 
1324 IMPL_LINK_NOARG(SvxConfigPage, SelectSaveInLocation, weld::ComboBox&, void)
1325 {
1326  pCurrentSaveInData = reinterpret_cast<SaveInData*>(m_xSaveInListBox->get_active_id().toInt64());
1327  Init();
1328 }
1329 
1331 {
1332  int nSelectionPos = m_xTopLevelListBox->get_active();
1333  m_xTopLevelListBox->clear();
1334 
1335  if ( GetSaveInData() && GetSaveInData()->GetEntries() )
1336  {
1337  for (auto const& entryData : *GetSaveInData()->GetEntries())
1338  {
1339  OUString sId(OUString::number(reinterpret_cast<sal_Int64>(entryData)));
1340  m_xTopLevelListBox->append(sId, SvxConfigPageHelper::stripHotKey(entryData->GetName()));
1341 
1342  if (entryData == pToSelect)
1343  nSelectionPos = m_xTopLevelListBox->get_count() - 1;
1344 
1345  AddSubMenusToUI( SvxConfigPageHelper::stripHotKey( entryData->GetName() ), entryData );
1346  }
1347  }
1348 #ifdef DBG_UTIL
1349  else
1350  {
1351  DBG_ASSERT( GetSaveInData(), "SvxConfigPage::ReloadTopLevelListBox(): no SaveInData" );
1352  DBG_ASSERT( GetSaveInData()->GetEntries() ,
1353  "SvxConfigPage::ReloadTopLevelListBox(): no SaveInData entries" );
1354  }
1355 #endif
1356 
1357  nSelectionPos = (nSelectionPos != -1 && nSelectionPos < m_xTopLevelListBox->get_count()) ?
1358  nSelectionPos : m_xTopLevelListBox->get_count() - 1;
1359 
1360  m_xTopLevelListBox->set_active(nSelectionPos);
1361  SelectElement();
1362 }
1363 
1365  const OUString& rBaseTitle, SvxConfigEntry const * pParentData )
1366 {
1367  for (auto const& entryData : *pParentData->GetEntries())
1368  {
1369  if (entryData->IsPopup())
1370  {
1371  OUString subMenuTitle = rBaseTitle + aMenuSeparatorStr + SvxConfigPageHelper::stripHotKey(entryData->GetName());
1372 
1373  OUString sId(OUString::number(reinterpret_cast<sal_Int64>(entryData)));
1374  m_xTopLevelListBox->append(sId, subMenuTitle);
1375 
1376  AddSubMenusToUI( subMenuTitle, entryData );
1377  }
1378  }
1379 }
1380 
1382  SvxEntries* pRootEntries, SvxConfigEntry* pChildData )
1383 {
1384  for (auto const& entryData : *pRootEntries)
1385  {
1386 
1387  if (entryData == pChildData)
1388  {
1389  return pRootEntries;
1390  }
1391  else if (entryData->IsPopup())
1392  {
1393  SvxEntries* result =
1394  FindParentForChild( entryData->GetEntries(), pChildData );
1395 
1396  if ( result != nullptr )
1397  {
1398  return result;
1399  }
1400  }
1401  }
1402  return nullptr;
1403 }
1404 
1405 int SvxConfigPage::AddFunction(int nTarget, bool bAllowDuplicates)
1406 {
1407  OUString aURL = GetScriptURL();
1408  SvxConfigEntry* pParent = GetTopLevelSelection();
1409 
1410  if ( aURL.isEmpty() || pParent == nullptr )
1411  {
1412  return -1;
1413  }
1414 
1415  OUString aDisplayName;
1417 
1418  if ( typeid(*pCurrentSaveInData) == typeid(ContextMenuSaveInData) )
1419  aDisplayName = vcl::CommandInfoProvider::GetPopupLabelForCommand( aURL, aModuleId );
1420  else if ( typeid(*pCurrentSaveInData) == typeid(MenuSaveInData) )
1421  aDisplayName = vcl::CommandInfoProvider::GetMenuLabelForCommand( aURL, aModuleId );
1422  else
1423  aDisplayName = vcl::CommandInfoProvider::GetLabelForCommand( aURL, aModuleId );
1424 
1425  SvxConfigEntry* pNewEntryData =
1426  new SvxConfigEntry( aDisplayName, aURL, false, /*bParentData*/false );
1427  pNewEntryData->SetUserDefined();
1428 
1429  if ( aDisplayName.isEmpty() )
1430  pNewEntryData->SetName( GetSelectedDisplayName() );
1431 
1432  // check that this function is not already in the menu
1433  if ( !bAllowDuplicates )
1434  {
1435  for (auto const& entry : *pParent->GetEntries())
1436  {
1437  if ( entry->GetCommand() == pNewEntryData->GetCommand() )
1438  {
1439  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(GetFrameWeld(),
1440  VclMessageType::Info, VclButtonsType::Ok, CuiResId(RID_SVXSTR_MNUCFG_ALREADY_INCLUDED)));
1441  xBox->run();
1442  delete pNewEntryData;
1443  return -1;
1444  }
1445  }
1446  }
1447 
1448  return AppendEntry(pNewEntryData, nTarget);
1449 }
1450 
1452  SvxConfigEntry* pNewEntryData,
1453  int nTarget)
1454 {
1455  SvxConfigEntry* pTopLevelSelection = GetTopLevelSelection();
1456 
1457  if (pTopLevelSelection == nullptr)
1458  return -1;
1459 
1460  // Grab the entries list for the currently selected menu
1461  SvxEntries* pEntries = pTopLevelSelection->GetEntries();
1462 
1463  int nNewEntry = -1;
1464  int nCurEntry =
1465  nTarget != -1 ? nTarget : m_xContentsListBox->get_selected_index();
1466 
1467  OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pNewEntryData)));
1468 
1469  if (nCurEntry == -1 || nCurEntry == m_xContentsListBox->n_children() - 1)
1470  {
1471  pEntries->push_back( pNewEntryData );
1472  m_xContentsListBox->insert(-1, sId);
1473  nNewEntry = m_xContentsListBox->n_children() - 1;
1474  }
1475  else
1476  {
1477  SvxConfigEntry* pEntryData =
1478  reinterpret_cast<SvxConfigEntry*>(m_xContentsListBox->get_id(nCurEntry).toInt64());
1479 
1480  SvxEntries::iterator iter = pEntries->begin();
1481  SvxEntries::const_iterator end = pEntries->end();
1482 
1483  // Advance the iterator to the data for currently selected entry
1484  sal_uInt16 nPos = 0;
1485  while (*iter != pEntryData && ++iter != end)
1486  {
1487  ++nPos;
1488  }
1489 
1490  // Now step past it to the entry after the currently selected one
1491  ++iter;
1492  ++nPos;
1493 
1494  // Now add the new entry to the UI and to the parent's list
1495  if ( iter != end )
1496  {
1497  pEntries->insert( iter, pNewEntryData );
1498  m_xContentsListBox->insert(nPos, sId);
1499  nNewEntry = nPos;
1500  }
1501  }
1502 
1503  if (nNewEntry != -1)
1504  {
1505  m_xContentsListBox->select(nNewEntry);
1506  m_xContentsListBox->scroll_to_row(nNewEntry);
1507 
1510  }
1511 
1512  return nNewEntry;
1513 }
1514 
1515 void SvxConfigPage::InsertEntryIntoUI(SvxConfigEntry* pNewEntryData, int nPos, int nStartCol)
1516 {
1517  OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pNewEntryData)));
1518 
1519  m_xContentsListBox->set_id(nPos, sId);
1520 
1521  if (pNewEntryData->IsSeparator())
1522  {
1523  m_xContentsListBox->set_text(nPos, "----------------------------------", nStartCol + 1);
1524  }
1525  else
1526  {
1527  auto xImage = GetSaveInData()->GetImage(pNewEntryData->GetCommand());
1528  if (xImage.is())
1529  m_xContentsListBox->set_image(nPos, xImage, nStartCol);
1530  OUString aName = SvxConfigPageHelper::stripHotKey( pNewEntryData->GetName() );
1531  m_xContentsListBox->set_text(nPos, aName, nStartCol + 1);
1532  }
1533 
1534  if (nStartCol == 0) // menus
1535  {
1536  if (pNewEntryData->IsPopup() || pNewEntryData->GetStyle() & css::ui::ItemStyle::DROP_DOWN)
1537  m_xContentsListBox->set_dropdown(nPos, nStartCol + 2);
1538  else
1539  m_xContentsListBox->set_image(nPos, nullptr, nStartCol + 2);
1540  }
1541 }
1542 
1543 IMPL_LINK(SvxConfigPage, MoveHdl, weld::Button&, rButton, void)
1544 {
1545  MoveEntry(&rButton == m_xMoveUpButton.get());
1546 }
1547 
1548 IMPL_LINK_NOARG(SvxConfigPage, FunctionDoubleClickHdl, weld::TreeView&, bool)
1549 {
1550  if (m_xAddCommandButton->get_sensitive())
1551  m_xAddCommandButton->clicked();
1552  return true;
1553 }
1554 
1555 IMPL_LINK_NOARG(SvxConfigPage, SelectFunctionHdl, weld::TreeView&, void)
1556 {
1557  // Store the tooltip of the description field at first run
1558  static const OUString sDescTooltip = m_xDescriptionField->get_tooltip_text();
1559 
1560  // GetScriptURL() returns a non-empty string if a
1561  // valid command is selected on the left box
1562  bool bIsValidCommand = !GetScriptURL().isEmpty();
1563 
1564  // Enable/disable Add and Remove buttons depending on current selection
1565  if (bIsValidCommand)
1566  {
1567  m_xAddCommandButton->set_sensitive(true);
1568  m_xRemoveCommandButton->set_sensitive(true);
1569 
1570  m_xDescriptionField->set_text(m_xFunctions->GetHelpText(false));
1571  }
1572  else
1573  {
1574 
1575  m_xAddCommandButton->set_sensitive(false);
1576  m_xRemoveCommandButton->set_sensitive(false);
1577 
1578  m_xDescriptionField->set_text("");
1579  }
1580 
1581  // Disable the description field and its label if the local help is not installed
1582  // And inform the user via tooltips
1583  if ( !SfxHelp::IsHelpInstalled() )
1584  {
1585  m_xDescriptionField->set_sensitive(false);
1586  m_xDescriptionFieldLb->set_sensitive(false);
1587  m_xDescriptionField->set_tooltip_text( sDescTooltip );
1588  m_xDescriptionFieldLb->set_tooltip_text( sDescTooltip );
1589  }
1590  else
1591  {
1592  m_xDescriptionField->set_sensitive(true);
1593  m_xDescriptionFieldLb->set_sensitive(true);
1594  m_xDescriptionField->set_tooltip_text("");
1595  m_xDescriptionFieldLb->set_tooltip_text("");
1596  }
1597 }
1598 
1599 IMPL_LINK_NOARG(SvxConfigPage, ImplUpdateDataHdl, Timer*, void)
1600 {
1601  OUString aSearchTerm(m_xSearchEdit->get_text());
1602  m_xCommandCategoryListBox->categorySelected(m_xFunctions.get(), aSearchTerm, GetSaveInData());
1603 }
1604 
1605 IMPL_LINK_NOARG(SvxConfigPage, SearchUpdateHdl, weld::Entry&, void)
1606 {
1607  m_aUpdateDataTimer.Start();
1608 }
1609 
1611 {
1612  if (m_aUpdateDataTimer.IsActive())
1613  {
1614  m_aUpdateDataTimer.Stop();
1615  m_aUpdateDataTimer.Invoke();
1616  }
1617 }
1618 
1619 void SvxConfigPage::MoveEntry(bool bMoveUp)
1620 {
1621  weld::TreeView& rTreeView = m_xContentsListBox->get_widget();
1622 
1623  int nSourceEntry = rTreeView.get_selected_index();
1624  int nTargetEntry = -1;
1625  int nToSelect = -1;
1626 
1627  if (nSourceEntry == -1)
1628  {
1629  return;
1630  }
1631 
1632  if ( bMoveUp )
1633  {
1634  // Move Up is just a Move Down with the source and target reversed
1635  nTargetEntry = nSourceEntry;
1636  nSourceEntry = nTargetEntry - 1;
1637  nToSelect = nSourceEntry;
1638  }
1639  else
1640  {
1641  nTargetEntry = nSourceEntry + 1;
1642  nToSelect = nTargetEntry;
1643  }
1644 
1645  if (MoveEntryData(nSourceEntry, nTargetEntry))
1646  {
1647  rTreeView.swap(nSourceEntry, nTargetEntry);
1648  rTreeView.select(nToSelect);
1649  rTreeView.scroll_to_row(nToSelect);
1650 
1652  }
1653 }
1654 
1655 bool SvxConfigPage::MoveEntryData(int nSourceEntry, int nTargetEntry)
1656 {
1657  //#i53677#
1658  if (nSourceEntry == -1 || nTargetEntry == -1)
1659  {
1660  return false;
1661  }
1662 
1663  // Grab the entries list for the currently selected menu
1664  SvxEntries* pEntries = GetTopLevelSelection()->GetEntries();
1665 
1666  SvxConfigEntry* pSourceData =
1667  reinterpret_cast<SvxConfigEntry*>(m_xContentsListBox->get_id(nSourceEntry).toInt64());
1668 
1669  SvxConfigEntry* pTargetData =
1670  reinterpret_cast<SvxConfigEntry*>(m_xContentsListBox->get_id(nTargetEntry).toInt64());
1671 
1672  if ( pSourceData != nullptr && pTargetData != nullptr )
1673  {
1674  // remove the source entry from our list
1675  SvxConfigPageHelper::RemoveEntry( pEntries, pSourceData );
1676 
1677  SvxEntries::iterator iter = pEntries->begin();
1678  SvxEntries::const_iterator end = pEntries->end();
1679 
1680  // advance the iterator to the position of the target entry
1681  while (*iter != pTargetData && ++iter != end) ;
1682 
1683  // insert the source entry at the position after the target
1684  pEntries->insert( ++iter, pSourceData );
1685 
1688 
1689  return true;
1690  }
1691 
1692  return false;
1693 }
1694 
1696  weld::Window* pParent, SvxEntries* entries,
1697  SvxConfigEntry const * selection, bool bCreateMenu )
1698  : GenericDialogController(pParent, "cui/ui/movemenu.ui", "MoveMenuDialog")
1699  , m_xMenuBox(m_xBuilder->weld_widget("namebox"))
1700  , m_xMenuNameEdit(m_xBuilder->weld_entry("menuname"))
1701  , m_xMenuListBox(m_xBuilder->weld_tree_view("menulist"))
1702  , m_xMoveUpButton(m_xBuilder->weld_button("up"))
1703  , m_xMoveDownButton(m_xBuilder->weld_button("down"))
1704 {
1705  m_xMenuListBox->set_size_request(-1, m_xMenuListBox->get_height_rows(12));
1706 
1707  // Copy the entries list passed in
1708  if ( entries != nullptr )
1709  {
1710  mpEntries.reset( new SvxEntries );
1711  for (auto const& entry : *entries)
1712  {
1713  m_xMenuListBox->append(OUString::number(reinterpret_cast<sal_uInt64>(entry)),
1714  SvxConfigPageHelper::stripHotKey(entry->GetName()));
1715  mpEntries->push_back(entry);
1716  if (entry == selection)
1717  {
1718  m_xMenuListBox->select(m_xMenuListBox->n_children() - 1);
1719  }
1720  }
1721  }
1722 
1723  if ( bCreateMenu )
1724  {
1725  // Generate custom name for new menu
1726  OUString prefix = CuiResId( RID_SVXSTR_NEW_MENU );
1727 
1728  OUString newname = SvxConfigPageHelper::generateCustomName( prefix, entries );
1729  OUString newurl = SvxConfigPageHelper::generateCustomMenuURL( mpEntries.get() );
1730 
1731  SvxConfigEntry* pNewEntryData =
1732  new SvxConfigEntry( newname, newurl, true, /*bParentData*/false );
1733  pNewEntryData->SetName( newname );
1734  pNewEntryData->SetUserDefined();
1735  pNewEntryData->SetMain();
1736 
1737  m_sNewMenuEntryId = OUString::number(reinterpret_cast<sal_uInt64>(pNewEntryData));
1739  SvxConfigPageHelper::stripHotKey(pNewEntryData->GetName()));
1740  m_xMenuListBox->select(m_xMenuListBox->n_children() - 1);
1741 
1742  if (mpEntries)
1743  mpEntries->push_back(pNewEntryData);
1744 
1745  m_xMenuNameEdit->set_text(newname);
1746  m_xMenuNameEdit->connect_changed(LINK(this, SvxMainMenuOrganizerDialog, ModifyHdl));
1747  }
1748  else
1749  {
1750  // hide name label and textfield
1751  m_xMenuBox->hide();
1752  // change the title
1753  m_xDialog->set_title(CuiResId(RID_SVXSTR_MOVE_MENU));
1754  }
1755 
1756  m_xMenuListBox->connect_changed(LINK(this, SvxMainMenuOrganizerDialog, SelectHdl));
1757 
1758  m_xMoveUpButton->connect_clicked(LINK( this, SvxMainMenuOrganizerDialog, MoveHdl));
1759  m_xMoveDownButton->connect_clicked(LINK( this, SvxMainMenuOrganizerDialog, MoveHdl));
1760 
1762 }
1763 
1765 {
1766 }
1767 
1769 {
1770  // if the Edit control is empty do not change the name
1771  if (m_xMenuNameEdit->get_text().isEmpty())
1772  {
1773  return;
1774  }
1775 
1776  SvxConfigEntry* pNewEntryData = reinterpret_cast<SvxConfigEntry*>(m_sNewMenuEntryId.toUInt64());
1777  pNewEntryData->SetName(m_xMenuNameEdit->get_text());
1778 
1779  const int nNewMenuPos = m_xMenuListBox->find_id(m_sNewMenuEntryId);
1780  const int nOldSelection = m_xMenuListBox->get_selected_index();
1781  m_xMenuListBox->remove(nNewMenuPos);
1782  m_xMenuListBox->insert(nNewMenuPos, pNewEntryData->GetName(), &m_sNewMenuEntryId, nullptr, nullptr);
1783  m_xMenuListBox->select(nOldSelection);
1784 }
1785 
1787 {
1788  UpdateButtonStates();
1789 }
1790 
1792 {
1793  // Disable Up and Down buttons depending on current selection
1794  const int nSelected = m_xMenuListBox->get_selected_index();
1795  m_xMoveUpButton->set_sensitive(nSelected > 0);
1796  m_xMoveDownButton->set_sensitive(nSelected != -1 && nSelected < m_xMenuListBox->n_children() - 1);
1797 }
1798 
1800 {
1801  int nSourceEntry = m_xMenuListBox->get_selected_index();
1802  if (nSourceEntry == -1)
1803  return;
1804 
1805  int nTargetEntry;
1806 
1807  if (&rButton == m_xMoveDownButton.get())
1808  {
1809  nTargetEntry = nSourceEntry + 1;
1810  }
1811  else
1812  {
1813  // Move Up is just a Move Down with the source and target reversed
1814  nTargetEntry = nSourceEntry - 1;
1815  }
1816 
1817  OUString sId = m_xMenuListBox->get_id(nSourceEntry);
1818  OUString sEntry = m_xMenuListBox->get_text(nSourceEntry);
1819  m_xMenuListBox->remove(nSourceEntry);
1820  m_xMenuListBox->insert(nTargetEntry, sEntry, &sId, nullptr, nullptr);
1821  m_xMenuListBox->select(nTargetEntry);
1822 
1823  std::swap(mpEntries->at(nSourceEntry), mpEntries->at(nTargetEntry));
1824 
1825  UpdateButtonStates();
1826 }
1827 
1829 {
1830  const int nSelected(m_xMenuListBox->get_selected_index());
1831  if (nSelected == -1)
1832  return nullptr;
1833  return reinterpret_cast<SvxConfigEntry*>(m_xMenuListBox->get_id(nSelected).toUInt64());
1834 }
1835 
1836 SvxConfigEntry::SvxConfigEntry( const OUString& rDisplayName,
1837  const OUString& rCommandURL, bool bPopup, bool bParentData )
1838  : nId( 1 )
1839  , aLabel(rDisplayName)
1840  , aCommand(rCommandURL)
1841  , bPopUp(bPopup)
1842  , bStrEdited( false )
1843  , bIsUserDefined( false )
1844  , bIsMain( false )
1845  , bIsParentData( bParentData )
1846  , bIsModified( false )
1847  , bIsVisible( true )
1848  , nStyle( 0 )
1849 {
1850  if (bPopUp)
1851  {
1852  mpEntries.reset( new SvxEntries );
1853  }
1854 }
1855 
1857 {
1858  if (mpEntries)
1859  {
1860  for (auto const& entry : *mpEntries)
1861  {
1862  delete entry;
1863  }
1864  }
1865 }
1866 
1868 {
1869  return !IsPopup() || IsMain();
1870 }
1871 
1873 {
1874  return !IsMain() || IsUserDefined();
1875 }
1876 
1878 {
1879  return !IsMain() || IsUserDefined();
1880 }
1881 
1883  const uno::Reference < css::ui::XUIConfigurationManager >& xCfgMgr,
1884  const uno::Reference < css::ui::XUIConfigurationManager >& xParentCfgMgr,
1885  const OUString& aModuleId,
1886  bool docConfig ) :
1887 
1888  SaveInData ( xCfgMgr, xParentCfgMgr, aModuleId, docConfig ),
1889  m_aDescriptorContainer ( ITEM_DESCRIPTOR_CONTAINER )
1890 
1891 {
1892  uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
1893  // Initialize the m_xPersistentWindowState variable which is used
1894  // to get the default properties of system toolbars such as name
1895  uno::Reference< container::XNameAccess > xPWSS = css::ui::theWindowStateConfiguration::get( xContext );
1896 
1897  xPWSS->getByName( aModuleId ) >>= m_xPersistentWindowState;
1898 }
1899 
1901 {
1902 }
1903 
1904 sal_Int32 ToolbarSaveInData::GetSystemStyle( const OUString& rResourceURL )
1905 {
1906  sal_Int32 result = 0;
1907 
1908  if ( rResourceURL.startsWith( "private" ) &&
1909  m_xPersistentWindowState.is() &&
1910  m_xPersistentWindowState->hasByName( rResourceURL ) )
1911  {
1912  try
1913  {
1914  uno::Sequence< beans::PropertyValue > aProps;
1915  uno::Any a( m_xPersistentWindowState->getByName( rResourceURL ) );
1916 
1917  if ( a >>= aProps )
1918  {
1919  for ( sal_Int32 i = 0; i < aProps.getLength(); ++i )
1920  {
1921  if ( aProps[ i ].Name == ITEM_DESCRIPTOR_STYLE )
1922  {
1923  aProps[i].Value >>= result;
1924  break;
1925  }
1926  }
1927  }
1928  }
1929  catch ( uno::Exception& )
1930  {
1931  // do nothing, a default value is returned
1932  }
1933  }
1934 
1935  return result;
1936 }
1937 
1939  const uno::Reference< frame::XFrame >& xFrame,
1940  const OUString& rResourceURL,
1941  sal_Int32 nStyle )
1942 {
1943  // change the style using the API
1944  SetSystemStyle( rResourceURL, nStyle );
1945 
1946  // this code is a temporary hack as the UI is not updating after
1947  // changing the toolbar style via the API
1948  uno::Reference< css::frame::XLayoutManager > xLayoutManager;
1949  vcl::Window *window = nullptr;
1950 
1951  uno::Reference< beans::XPropertySet > xPropSet( xFrame, uno::UNO_QUERY );
1952  if ( xPropSet.is() )
1953  {
1954  uno::Any a = xPropSet->getPropertyValue( "LayoutManager" );
1955  a >>= xLayoutManager;
1956  }
1957 
1958  if ( xLayoutManager.is() )
1959  {
1960  uno::Reference< css::ui::XUIElement > xUIElement =
1961  xLayoutManager->getElement( rResourceURL );
1962 
1963  // check reference before we call getRealInterface. The layout manager
1964  // can only provide references for elements that have been created
1965  // before. It's possible that the current element is not available.
1966  uno::Reference< css::awt::XWindow > xWindow;
1967  if ( xUIElement.is() )
1968  xWindow.set( xUIElement->getRealInterface(), uno::UNO_QUERY );
1969 
1970  window = VCLUnoHelper::GetWindow( xWindow ).get();
1971  }
1972 
1973  if ( window != nullptr && window->GetType() == WindowType::TOOLBOX )
1974  {
1975  ToolBox* toolbox = static_cast<ToolBox*>(window);
1976 
1977  if ( nStyle == 0 )
1978  {
1979  toolbox->SetButtonType( ButtonType::SYMBOLONLY );
1980  }
1981  else if ( nStyle == 1 )
1982  {
1983  toolbox->SetButtonType( ButtonType::TEXT );
1984  }
1985  if ( nStyle == 2 )
1986  {
1987  toolbox->SetButtonType( ButtonType::SYMBOLTEXT );
1988  }
1989  }
1990 }
1991 
1993  const OUString& rResourceURL,
1994  sal_Int32 nStyle )
1995 {
1996  if ( rResourceURL.startsWith( "private" ) &&
1997  m_xPersistentWindowState.is() &&
1998  m_xPersistentWindowState->hasByName( rResourceURL ) )
1999  {
2000  try
2001  {
2002  uno::Sequence< beans::PropertyValue > aProps;
2003 
2004  uno::Any a( m_xPersistentWindowState->getByName( rResourceURL ) );
2005 
2006  if ( a >>= aProps )
2007  {
2008  for ( sal_Int32 i = 0; i < aProps.getLength(); ++i )
2009  {
2010  if ( aProps[ i ].Name == ITEM_DESCRIPTOR_STYLE )
2011  {
2012  aProps[ i ].Value <<= nStyle;
2013  break;
2014  }
2015  }
2016  }
2017 
2018  uno::Reference< container::XNameReplace >
2019  xNameReplace( m_xPersistentWindowState, uno::UNO_QUERY );
2020 
2021  xNameReplace->replaceByName( rResourceURL, uno::Any( aProps ) );
2022  }
2023  catch ( uno::Exception& )
2024  {
2025  // do nothing, a default value is returned
2026  SAL_WARN("cui.customize", "Exception setting toolbar style");
2027  }
2028  }
2029 }
2030 
2031 OUString ToolbarSaveInData::GetSystemUIName( const OUString& rResourceURL )
2032 {
2033  OUString result;
2034 
2035  if ( rResourceURL.startsWith( "private" ) &&
2036  m_xPersistentWindowState.is() &&
2037  m_xPersistentWindowState->hasByName( rResourceURL ) )
2038  {
2039  try
2040  {
2041  uno::Sequence< beans::PropertyValue > aProps;
2042  uno::Any a( m_xPersistentWindowState->getByName( rResourceURL ) );
2043 
2044  if ( a >>= aProps )
2045  {
2046  for ( sal_Int32 i = 0; i < aProps.getLength(); ++i )
2047  {
2048  if ( aProps[ i ].Name == ITEM_DESCRIPTOR_UINAME )
2049  {
2050  aProps[ i ].Value >>= result;
2051  }
2052  }
2053  }
2054  }
2055  catch ( uno::Exception& )
2056  {
2057  // do nothing, an empty UIName will be returned
2058  }
2059  }
2060 
2061  if ( rResourceURL.startsWith( ".uno" ) &&
2062  m_xCommandToLabelMap.is() &&
2063  m_xCommandToLabelMap->hasByName( rResourceURL ) )
2064  {
2065  uno::Any a;
2066  try
2067  {
2068  a = m_xCommandToLabelMap->getByName( rResourceURL );
2069 
2070  uno::Sequence< beans::PropertyValue > aPropSeq;
2071  if ( a >>= aPropSeq )
2072  {
2073  for ( sal_Int32 i = 0; i < aPropSeq.getLength(); ++i )
2074  {
2075  if ( aPropSeq[i].Name == ITEM_DESCRIPTOR_LABEL )
2076  {
2077  aPropSeq[i].Value >>= result;
2078  }
2079  }
2080  }
2081  }
2082  catch ( uno::Exception& )
2083  {
2084  // not a system command name
2085  }
2086  }
2087 
2088  return result;
2089 }
2090 
2092 {
2093  typedef std::unordered_map<OUString, bool > ToolbarInfo;
2094 
2095  ToolbarInfo aToolbarInfo;
2096 
2097  if ( pRootEntry == nullptr )
2098  {
2099 
2100  pRootEntry.reset( new SvxConfigEntry( "MainToolbars", OUString(), true, /*bParentData*/false) );
2101 
2102  uno::Sequence< uno::Sequence < beans::PropertyValue > > info =
2103  GetConfigManager()->getUIElementsInfo(
2104  css::ui::UIElementType::TOOLBAR );
2105 
2106  for ( sal_Int32 i = 0; i < info.getLength(); ++i )
2107  {
2108  uno::Sequence< beans::PropertyValue > props = info[ i ];
2109 
2110  OUString url;
2111  OUString systemname;
2112  OUString uiname;
2113 
2114  for ( sal_Int32 j = 0; j < props.getLength(); ++j )
2115  {
2116  if ( props[ j ].Name == ITEM_DESCRIPTOR_RESOURCEURL )
2117  {
2118  props[ j ].Value >>= url;
2119  systemname = url.copy( url.lastIndexOf( '/' ) + 1 );
2120  }
2121  else if ( props[ j ].Name == ITEM_DESCRIPTOR_UINAME )
2122  {
2123  props[ j ].Value >>= uiname;
2124  }
2125  }
2126 
2127  try
2128  {
2129  uno::Reference< container::XIndexAccess > xToolbarSettings =
2130  GetConfigManager()->getSettings( url, false );
2131 
2132  if ( uiname.isEmpty() )
2133  {
2134  // try to get the name from m_xPersistentWindowState
2135  uiname = GetSystemUIName( url );
2136 
2137  if ( uiname.isEmpty() )
2138  {
2139  uiname = systemname;
2140  }
2141  }
2142 
2143  SvxConfigEntry* pEntry = new SvxConfigEntry(
2144  uiname, url, true, /*bParentData*/false );
2145 
2146  pEntry->SetMain();
2147  pEntry->SetStyle( GetSystemStyle( url ) );
2148 
2149 
2150  // insert into std::unordered_map to filter duplicates from the parent
2151  aToolbarInfo.emplace( systemname, true );
2152 
2153  OUString custom(CUSTOM_TOOLBAR_STR);
2154  if ( systemname.startsWith( custom ) )
2155  {
2156  pEntry->SetUserDefined();
2157  }
2158  else
2159  {
2160  pEntry->SetUserDefined( false );
2161  }
2162 
2163  pRootEntry->GetEntries()->push_back( pEntry );
2164 
2165  LoadToolbar( xToolbarSettings, pEntry );
2166  }
2167  catch ( container::NoSuchElementException& )
2168  {
2169  // TODO, handle resourceURL with no settings
2170  }
2171  }
2172 
2173  uno::Reference< css::ui::XUIConfigurationManager > xParentCfgMgr = GetParentConfigManager();
2174  if ( xParentCfgMgr.is() )
2175  {
2176  // Retrieve also the parent toolbars to make it possible
2177  // to configure module toolbars and save them into the document
2178  // config manager.
2179  uno::Sequence< uno::Sequence < beans::PropertyValue > > info_ =
2180  xParentCfgMgr->getUIElementsInfo(
2181  css::ui::UIElementType::TOOLBAR );
2182 
2183  for ( sal_Int32 i = 0; i < info_.getLength(); ++i )
2184  {
2185  uno::Sequence< beans::PropertyValue > props = info_[ i ];
2186 
2187  OUString url;
2188  OUString systemname;
2189  OUString uiname;
2190 
2191  for ( sal_Int32 j = 0; j < props.getLength(); ++j )
2192  {
2193  if ( props[ j ].Name == ITEM_DESCRIPTOR_RESOURCEURL )
2194  {
2195  props[ j ].Value >>= url;
2196  systemname = url.copy( url.lastIndexOf( '/' ) + 1 );
2197  }
2198  else if ( props[ j ].Name == ITEM_DESCRIPTOR_UINAME )
2199  {
2200  props[ j ].Value >>= uiname;
2201  }
2202  }
2203 
2204  // custom toolbars of the parent are not visible in the document layer
2205  OUString custom(CUSTOM_TOOLBAR_STR);
2206  if ( systemname.startsWith( custom ) )
2207  continue;
2208 
2209  // check if toolbar is already in the document layer
2210  ToolbarInfo::const_iterator pIter = aToolbarInfo.find( systemname );
2211  if ( pIter == aToolbarInfo.end() )
2212  {
2213  aToolbarInfo.emplace( systemname, true );
2214 
2215  try
2216  {
2217  uno::Reference< container::XIndexAccess > xToolbarSettings =
2218  xParentCfgMgr->getSettings( url, false );
2219 
2220  if ( uiname.isEmpty() )
2221  {
2222  // try to get the name from m_xPersistentWindowState
2223  uiname = GetSystemUIName( url );
2224 
2225  if ( uiname.isEmpty() )
2226  {
2227  uiname = systemname;
2228  }
2229  }
2230 
2231  SvxConfigEntry* pEntry = new SvxConfigEntry(
2232  uiname, url, true, true );
2233 
2234  pEntry->SetMain();
2235  pEntry->SetStyle( GetSystemStyle( url ) );
2236 
2237  if ( systemname.startsWith( custom ) )
2238  {
2239  pEntry->SetUserDefined();
2240  }
2241  else
2242  {
2243  pEntry->SetUserDefined( false );
2244  }
2245 
2246  pRootEntry->GetEntries()->push_back( pEntry );
2247 
2248  LoadToolbar( xToolbarSettings, pEntry );
2249  }
2250  catch ( container::NoSuchElementException& )
2251  {
2252  // TODO, handle resourceURL with no settings
2253  }
2254  }
2255  }
2256  }
2257 
2259  }
2260 
2261  return pRootEntry->GetEntries();
2262 }
2263 
2264 void
2265 ToolbarSaveInData::SetEntries( std::unique_ptr<SvxEntries> pNewEntries )
2266 {
2267  pRootEntry->SetEntries( std::move(pNewEntries) );
2268 }
2269 
2270 bool
2271 ToolbarSaveInData::HasURL( const OUString& rURL )
2272 {
2273  for (auto const& entry : *GetEntries())
2274  {
2275  if (entry->GetCommand() == rURL)
2276  {
2277  return !entry->IsParentData();
2278  }
2279  }
2280  return false;
2281 }
2282 
2284 {
2285  // return true if there is at least one toolbar entry
2286  return !GetEntries()->empty();
2287 }
2288 
2290 {
2291  // reset each toolbar by calling removeSettings for its toolbar URL
2292  for (auto const& entry : *GetEntries())
2293  {
2294  try
2295  {
2296  const OUString& url = entry->GetCommand();
2297  GetConfigManager()->removeSettings( url );
2298  }
2299  catch ( uno::Exception& )
2300  {
2301  // error occurred removing the settings
2302  // TODO - add error dialog in future?
2303  }
2304  }
2305 
2306  // persist changes to toolbar storage
2308 
2309  // now delete the root SvxConfigEntry the next call to GetEntries()
2310  // causes it to be reinitialised
2311  pRootEntry.reset();
2312 
2313  // reset all icons to default
2314  try
2315  {
2316  GetImageManager()->reset();
2318  }
2319  catch ( uno::Exception& )
2320  {
2321  SAL_WARN("cui.customize", "Error resetting all icons when resetting toolbars");
2322  }
2323 }
2324 
2326 {
2327  // toolbar changes are instantly applied
2328  return false;
2329 }
2330 
2332  uno::Reference< container::XIndexContainer > const & rToolbarBar,
2333  uno::Reference< lang::XSingleComponentFactory >& rFactory,
2334  SvxConfigEntry const * pToolbarData )
2335 {
2336  uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
2337 
2338  for (auto const& entry : *pToolbarData->GetEntries())
2339  {
2340  if (entry->IsPopup())
2341  {
2342  uno::Sequence< beans::PropertyValue > aPropValueSeq =
2344 
2345  uno::Reference< container::XIndexContainer > xSubMenuBar(
2346  rFactory->createInstanceWithContext( xContext ),
2347  uno::UNO_QUERY );
2348 
2349  sal_Int32 nIndex = aPropValueSeq.getLength();
2350  aPropValueSeq.realloc( nIndex + 1 );
2351  aPropValueSeq[nIndex].Name = m_aDescriptorContainer;
2352  aPropValueSeq[nIndex].Value <<= xSubMenuBar;
2353  rToolbarBar->insertByIndex(
2354  rToolbarBar->getCount(), uno::Any( aPropValueSeq ));
2355 
2356  ApplyToolbar(xSubMenuBar, rFactory, entry);
2357  }
2358  else if (entry->IsSeparator())
2359  {
2360  rToolbarBar->insertByIndex(
2361  rToolbarBar->getCount(), uno::Any( m_aSeparatorSeq ));
2362  }
2363  else
2364  {
2365  uno::Sequence< beans::PropertyValue > aPropValueSeq =
2367 
2368  rToolbarBar->insertByIndex(
2369  rToolbarBar->getCount(), uno::Any( aPropValueSeq ));
2370  }
2371  }
2372 }
2373 
2375 {
2376  // Apply new toolbar structure to our settings container
2377  uno::Reference< container::XIndexAccess > xSettings =
2378  GetConfigManager()->createSettings();
2379 
2380  uno::Reference< container::XIndexContainer > xIndexContainer (
2381  xSettings, uno::UNO_QUERY );
2382 
2383  uno::Reference< lang::XSingleComponentFactory > xFactory (
2384  xSettings, uno::UNO_QUERY );
2385 
2386  ApplyToolbar( xIndexContainer, xFactory, pToolbar );
2387 
2388  uno::Reference< beans::XPropertySet > xProps(
2389  xSettings, uno::UNO_QUERY );
2390 
2391  if ( pToolbar->IsUserDefined() )
2392  {
2393  xProps->setPropertyValue(
2395  uno::Any( pToolbar->GetName() ) );
2396  }
2397 
2398  try
2399  {
2400  if ( GetConfigManager()->hasSettings( pToolbar->GetCommand() ) )
2401  {
2402  GetConfigManager()->replaceSettings(
2403  pToolbar->GetCommand(), xSettings );
2404  }
2405  else
2406  {
2407  GetConfigManager()->insertSettings(
2408  pToolbar->GetCommand(), xSettings );
2409  if ( pToolbar->IsParentData() )
2410  pToolbar->SetParentData( false );
2411  }
2412  }
2413  catch ( css::uno::Exception const & )
2414  {
2415  TOOLS_WARN_EXCEPTION("cui.customize", "caught exception saving settings");
2416  }
2417 
2419 }
2420 
2422 {
2423  // show the new toolbar in the UI also
2424  uno::Reference< container::XIndexAccess >
2425  xSettings = GetConfigManager()->createSettings();
2426 
2427  uno::Reference< beans::XPropertySet >
2428  xPropertySet( xSettings, uno::UNO_QUERY );
2429 
2430  xPropertySet->setPropertyValue(
2432  uno::Any( pToolbar->GetName() ) );
2433 
2434  try
2435  {
2436  GetConfigManager()->insertSettings( pToolbar->GetCommand(), xSettings );
2437  }
2438  catch ( css::uno::Exception const & )
2439  {
2440  TOOLS_WARN_EXCEPTION("cui.customize", "caught exception saving settings");
2441  }
2442 
2443  GetEntries()->push_back( pToolbar );
2444 
2446 }
2447 
2449 {
2450  try
2451  {
2452  OUString url = pToolbar->GetCommand();
2453  GetConfigManager()->removeSettings( url );
2455  delete pToolbar;
2456 
2458 
2459  // remove the persistent window state data
2460  css::uno::Reference< css::container::XNameContainer > xNameContainer(
2461  m_xPersistentWindowState, css::uno::UNO_QUERY_THROW );
2462 
2463  xNameContainer->removeByName( url );
2464  }
2465  catch ( uno::Exception& )
2466  {
2467  // error occurred removing the settings
2468  }
2469 }
2470 
2472 {
2473  OUString url = pToolbar->GetCommand();
2474 
2475  // Restore of toolbar is done by removing it from
2476  // its configuration manager and then getting it again
2477  bool bParentToolbar = pToolbar->IsParentData();
2478 
2479  // Cannot restore parent toolbar
2480  if ( bParentToolbar )
2481  return;
2482 
2483  try
2484  {
2485  GetConfigManager()->removeSettings( url );
2486  pToolbar->GetEntries()->clear();
2488  }
2489  catch ( uno::Exception& )
2490  {
2491  // if an error occurs removing the settings then just return
2492  return;
2493  }
2494 
2495  // Now reload the toolbar settings
2496  try
2497  {
2498  uno::Reference< container::XIndexAccess > xToolbarSettings;
2499  if ( IsDocConfig() )
2500  {
2501  xToolbarSettings = GetParentConfigManager()->getSettings( url, false );
2502  pToolbar->SetParentData();
2503  }
2504  else
2505  xToolbarSettings = GetConfigManager()->getSettings( url, false );
2506 
2507  LoadToolbar( xToolbarSettings, pToolbar );
2508 
2509  // After reloading, ensure that the icon is reset of each entry
2510  // in the toolbar
2511  uno::Sequence< OUString > aURLSeq( 1 );
2512  for (auto const& entry : *pToolbar->GetEntries())
2513  {
2514  aURLSeq[ 0 ] = entry->GetCommand();
2515 
2516  try
2517  {
2518  GetImageManager()->removeImages( SvxConfigPageHelper::GetImageType(), aURLSeq );
2519  }
2520  catch ( uno::Exception& )
2521  {
2522  SAL_WARN("cui.customize", "Error restoring icon when resetting toolbar");
2523  }
2524  }
2526  }
2527  catch ( container::NoSuchElementException& )
2528  {
2529  // cannot find the resource URL after removing it
2530  // so no entry will appear in the toolbar list
2531  }
2532 }
2533 
2535  const uno::Reference< container::XIndexAccess >& xToolbarSettings,
2536  SvxConfigEntry const * pParentData )
2537 {
2538  SvxEntries* pEntries = pParentData->GetEntries();
2539 
2540  for ( sal_Int32 nIndex = 0; nIndex < xToolbarSettings->getCount(); ++nIndex )
2541  {
2542  OUString aCommandURL;
2543  OUString aLabel;
2544  bool bIsVisible;
2545  sal_Int32 nStyle;
2546 
2547  sal_uInt16 nType( css::ui::ItemType::DEFAULT );
2548 
2549  bool bItem = SvxConfigPageHelper::GetToolbarItemData( xToolbarSettings, nIndex, aCommandURL,
2550  aLabel, nType, bIsVisible, nStyle );
2551 
2552  if ( bItem )
2553  {
2554  bool bIsUserDefined = true;
2555 
2556  if ( nType == css::ui::ItemType::DEFAULT )
2557  {
2558  uno::Any a;
2559  try
2560  {
2561  a = m_xCommandToLabelMap->getByName( aCommandURL );
2562  bIsUserDefined = false;
2563  }
2564  catch ( container::NoSuchElementException& )
2565  {
2566  bIsUserDefined = true;
2567  }
2568 
2569  bool bUseDefaultLabel = false;
2570  // If custom label not set retrieve it from the command
2571  // to info service
2572  if ( aLabel.isEmpty() )
2573  {
2574  bUseDefaultLabel = true;
2575  uno::Sequence< beans::PropertyValue > aPropSeq;
2576  if ( a >>= aPropSeq )
2577  {
2578  for ( sal_Int32 i = 0; i < aPropSeq.getLength(); ++i )
2579  {
2580  if ( aPropSeq[i].Name == "Name" )
2581  {
2582  aPropSeq[i].Value >>= aLabel;
2583  break;
2584  }
2585  }
2586  }
2587  }
2588 
2589  SvxConfigEntry* pEntry = new SvxConfigEntry(
2590  aLabel, aCommandURL, false, /*bParentData*/false );
2591 
2592  pEntry->SetUserDefined( bIsUserDefined );
2593  pEntry->SetVisible( bIsVisible );
2594  pEntry->SetStyle( nStyle );
2595 
2596  if ( !bUseDefaultLabel )
2597  pEntry->SetName( aLabel );
2598 
2599  pEntries->push_back( pEntry );
2600  }
2601  else
2602  {
2603  SvxConfigEntry* pEntry = new SvxConfigEntry;
2604  pEntry->SetUserDefined( bIsUserDefined );
2605  pEntries->push_back( pEntry );
2606  }
2607  }
2608  }
2609 }
2610 
2612  : GenericDialogController(pWindow, "cui/ui/newtoolbardialog.ui", "NewToolbarDialog")
2613  , m_xEdtName(m_xBuilder->weld_entry("edit"))
2614  , m_xBtnOK(m_xBuilder->weld_button("ok"))
2615  , m_xSaveInListBox(m_xBuilder->weld_combo_box("savein"))
2616 {
2617  m_xEdtName->set_text(rName);
2618  m_xEdtName->select_region(0, -1);
2619 }
2620 
2622 {
2623 }
2624 
2625 /*******************************************************************************
2626 *
2627 * The SvxIconSelectorDialog class
2628 *
2629 *******************************************************************************/
2631  const uno::Reference< css::ui::XImageManager >& rXImageManager,
2632  const uno::Reference< css::ui::XImageManager >& rXParentImageManager)
2633  : GenericDialogController(pWindow, "cui/ui/iconselectordialog.ui", "IconSelector")
2634  , m_xImageManager(rXImageManager)
2635  , m_xParentImageManager(rXParentImageManager)
2636  , m_xTbSymbol(new SvtValueSet(m_xBuilder->weld_scrolled_window("symbolswin")))
2637  , m_xTbSymbolWin(new weld::CustomWeld(*m_xBuilder, "symbolsToolbar", *m_xTbSymbol))
2638  , m_xFtNote(m_xBuilder->weld_label("noteLabel"))
2639  , m_xBtnImport(m_xBuilder->weld_button("importButton"))
2640  , m_xBtnDelete(m_xBuilder->weld_button("deleteButton"))
2641 {
2642  typedef std::unordered_map< OUString, bool > ImageInfo;
2643 
2644  m_nExpectedSize = 16;
2645  if (SvxConfigPageHelper::GetImageType() & css::ui::ImageType::SIZE_LARGE)
2646  m_nExpectedSize = 24;
2647  else if (SvxConfigPageHelper::GetImageType() & css::ui::ImageType::SIZE_32)
2648  m_nExpectedSize = 32;
2649 
2650  if ( m_nExpectedSize != 16 )
2651  {
2653  }
2654 
2655  m_xTbSymbol->SetStyle(m_xTbSymbol->GetStyle() | WB_ITEMBORDER | WB_VSCROLL);
2656  m_xTbSymbol->SetColCount(11);
2657  m_xTbSymbol->SetLineCount(5);
2658  m_xTbSymbol->SetItemWidth(m_nExpectedSize);
2659  m_xTbSymbol->SetItemHeight(m_nExpectedSize);
2660  m_xTbSymbol->SetExtraSpacing(6);
2661  Size aSize(m_xTbSymbol->CalcWindowSizePixel(Size(m_nExpectedSize, m_nExpectedSize), 11, 5));
2662  m_xTbSymbol->set_size_request(aSize.Width(), aSize.Height());
2663 
2664  uno::Reference< uno::XComponentContext > xComponentContext =
2665  ::comphelper::getProcessComponentContext();
2666 
2667  m_xGraphProvider.set( graphic::GraphicProvider::create( xComponentContext ) );
2668 
2669  uno::Reference< css::util::XPathSettings > xPathSettings =
2670  css::util::thePathSettings::get( xComponentContext );
2671 
2672 
2673  OUString aDirectory = xPathSettings->getUserConfig();
2674 
2675  sal_Int32 aCount = aDirectory.getLength();
2676 
2677  if ( aCount > 0 )
2678  {
2679  sal_Unicode aChar = aDirectory[ aCount-1 ];
2680  if ( aChar != '/')
2681  {
2682  aDirectory += "/";
2683  }
2684  }
2685  else
2686  {
2687  m_xBtnImport->set_sensitive(false);
2688  }
2689 
2690  aDirectory += "soffice.cfg/import";
2691 
2692  uno::Reference< lang::XSingleServiceFactory > xStorageFactory(
2693  css::embed::FileSystemStorageFactory::create( xComponentContext ) );
2694 
2695  uno::Sequence< uno::Any > aArgs( 2 );
2696  aArgs[ 0 ] <<= aDirectory;
2697  aArgs[ 1 ] <<= css::embed::ElementModes::READWRITE;
2698 
2699  uno::Reference< css::embed::XStorage > xStorage(
2700  xStorageFactory->createInstanceWithArguments( aArgs ), uno::UNO_QUERY );
2701 
2702  uno::Sequence<uno::Any> aProp(comphelper::InitAnyPropertySequence(
2703  {
2704  {"UserConfigStorage", uno::Any(xStorage)},
2705  {"OpenMode", uno::Any(css::embed::ElementModes::READWRITE)}
2706  }));
2707  m_xImportedImageManager = css::ui::ImageManager::create( xComponentContext );
2708  m_xImportedImageManager->initialize(aProp);
2709 
2710  ImageInfo aImageInfo1;
2711  uno::Sequence< OUString > names;
2712  if ( m_xImportedImageManager.is() )
2713  {
2714  names = m_xImportedImageManager->getAllImageNames( SvxConfigPageHelper::GetImageType() );
2715  for ( sal_Int32 n = 0; n < names.getLength(); ++n )
2716  aImageInfo1.emplace( names[n], false );
2717  }
2718 
2719  uno::Sequence< OUString > name( 1 );
2720  for (auto const& elem : aImageInfo1)
2721  {
2722  name[ 0 ] = elem.first;
2723  uno::Sequence< uno::Reference< graphic::XGraphic> > graphics = m_xImportedImageManager->getImages( SvxConfigPageHelper::GetImageType(), name );
2724  if ( graphics.hasElements() )
2725  {
2726  m_aGraphics.push_back(graphics[0]);
2727  Image img(graphics[0]);
2728  m_xTbSymbol->InsertItem(m_aGraphics.size(), img, elem.first);
2729  }
2730  }
2731 
2732  ImageInfo aImageInfo;
2733 
2734  if ( m_xParentImageManager.is() )
2735  {
2736  names = m_xParentImageManager->getAllImageNames( SvxConfigPageHelper::GetImageType() );
2737  for ( sal_Int32 n = 0; n < names.getLength(); ++n )
2738  aImageInfo.emplace( names[n], false );
2739  }
2740 
2741  names = m_xImageManager->getAllImageNames( SvxConfigPageHelper::GetImageType() );
2742  for ( sal_Int32 n = 0; n < names.getLength(); ++n )
2743  {
2744  ImageInfo::iterator pIter = aImageInfo.find( names[n] );
2745  if ( pIter != aImageInfo.end() )
2746  pIter->second = true;
2747  else
2748  aImageInfo.emplace( names[n], true );
2749  }
2750 
2751  // large growth factor, expecting many entries
2752  for (auto const& elem : aImageInfo)
2753  {
2754  name[ 0 ] = elem.first;
2755 
2756  uno::Sequence< uno::Reference< graphic::XGraphic> > graphics;
2757  try
2758  {
2759  if (elem.second)
2760  graphics = m_xImageManager->getImages( SvxConfigPageHelper::GetImageType(), name );
2761  else
2762  graphics = m_xParentImageManager->getImages( SvxConfigPageHelper::GetImageType(), name );
2763  }
2764  catch ( uno::Exception& )
2765  {
2766  // can't get sequence for this name so it will not be
2767  // added to the list
2768  }
2769 
2770  if ( graphics.hasElements() )
2771  {
2772  Image img(graphics[0]);
2773  if (!img.GetBitmapEx().IsEmpty())
2774  {
2775  m_aGraphics.push_back(graphics[0]);
2776  m_xTbSymbol->InsertItem(m_aGraphics.size(), img, elem.first);
2777  }
2778  }
2779  }
2780 
2781  m_xBtnDelete->set_sensitive( false );
2782  m_xTbSymbol->SetSelectHdl( LINK(this, SvxIconSelectorDialog, SelectHdl) );
2783  m_xBtnImport->connect_clicked( LINK(this, SvxIconSelectorDialog, ImportHdl) );
2784  m_xBtnDelete->connect_clicked( LINK(this, SvxIconSelectorDialog, DeleteHdl) );
2785 }
2786 
2788 {
2789 }
2790 
2791 uno::Reference< graphic::XGraphic> SvxIconSelectorDialog::GetSelectedIcon()
2792 {
2793  uno::Reference<graphic::XGraphic> result;
2794 
2795  sal_uInt16 nId = m_xTbSymbol->GetSelectedItemId();
2796 
2797  if (nId)
2798  {
2799  result = m_aGraphics[nId - 1];
2800  }
2801 
2802  return result;
2803 }
2804 
2806 {
2807  sal_uInt16 nId = m_xTbSymbol->GetSelectedItemId();
2808 
2809  if (!nId)
2810  {
2811  m_xBtnDelete->set_sensitive(false);
2812  return;
2813  }
2814 
2815  OUString aSelImageText = m_xTbSymbol->GetItemText(nId);
2816  if (m_xImportedImageManager->hasImage(SvxConfigPageHelper::GetImageType(), aSelImageText))
2817  {
2818  m_xBtnDelete->set_sensitive(true);
2819  }
2820  else
2821  {
2822  m_xBtnDelete->set_sensitive(false);
2823  }
2824 }
2825 
2827 {
2828  sfx2::FileDialogHelper aImportDialog(
2829  css::ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW,
2830  FileDialogFlags::Graphic | FileDialogFlags::MultiSelection, m_xDialog.get());
2831 
2832  // disable the link checkbox in the dialog
2833  uno::Reference< css::ui::dialogs::XFilePickerControlAccess >
2834  xController( aImportDialog.GetFilePicker(), uno::UNO_QUERY);
2835  if ( xController.is() )
2836  {
2837  xController->enableControl(
2838  css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_LINK,
2839  false);
2840  }
2841 
2842  aImportDialog.SetCurrentFilter(
2843  "PNG - Portable Network Graphic");
2844 
2845  if ( ERRCODE_NONE == aImportDialog.Execute() )
2846  {
2847  uno::Sequence< OUString > paths = aImportDialog.GetMPath();
2848  ImportGraphics ( paths );
2849  }
2850 }
2851 
2853 {
2854  OUString message = CuiResId( RID_SVXSTR_DELETE_ICON_CONFIRM );
2855 
2856  std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(m_xDialog.get(),
2857  VclMessageType::Warning, VclButtonsType::OkCancel,
2858  message));
2859  if (xWarn->run() == RET_OK)
2860  {
2861  sal_uInt16 nId = m_xTbSymbol->GetSelectedItemId();
2862 
2863  OUString aSelImageText = m_xTbSymbol->GetItemText( nId );
2864  uno::Sequence< OUString > URLs { aSelImageText };
2865  m_xTbSymbol->RemoveItem(nId);
2866  m_xImportedImageManager->removeImages( SvxConfigPageHelper::GetImageType(), URLs );
2867  if ( m_xImportedImageManager->isModified() )
2868  {
2869  m_xImportedImageManager->store();
2870  }
2871  }
2872 }
2873 
2875  const OUString& aURL )
2876 {
2877  uno::Sequence< OUString > URLs(1);
2878  uno::Sequence< uno::Reference<graphic::XGraphic > > aImportGraph( 1 );
2879 
2880  uno::Reference< graphic::XGraphic > xGraphic;
2881  uno::Sequence< beans::PropertyValue > aMediaProps( 1 );
2882  aMediaProps[0].Name = "URL";
2883  aMediaProps[0].Value <<= aURL;
2884 
2885  css::awt::Size aSize;
2886  bool bOK = false;
2887  try
2888  {
2889  xGraphic = m_xGraphProvider->queryGraphic( aMediaProps );
2890 
2891  uno::Reference< beans::XPropertySet > props =
2892  m_xGraphProvider->queryGraphicDescriptor( aMediaProps );
2893  uno::Any a = props->getPropertyValue( "SizePixel" );
2894  a >>= aSize;
2895  if (0 == aSize.Width || 0 == aSize.Height)
2896  return false;
2897  else
2898  bOK = true;
2899  }
2900  catch ( uno::Exception& )
2901  {
2902  return false;
2903  }
2904 
2905  bool bResult( false );
2906  size_t nCount = m_xTbSymbol->GetItemCount();
2907  for (size_t n = 0; n < nCount; ++n)
2908  {
2909  sal_uInt16 nId = m_xTbSymbol->GetItemId( n );
2910 
2911  if ( m_xTbSymbol->GetItemText( nId ) == aURL )
2912  {
2913  try
2914  {
2915  // replace/insert image with provided URL
2916  size_t nPos = nId - 1;
2917  assert(nPos == m_xTbSymbol->GetItemPos(nId));
2918  m_xTbSymbol->RemoveItem(nId);
2919  aMediaProps[0].Value <<= aURL;
2920 
2921  Image aImage( xGraphic );
2922  if ( bOK && ((aSize.Width != m_nExpectedSize) || (aSize.Height != m_nExpectedSize)) )
2923  {
2924  BitmapEx aBitmap = aImage.GetBitmapEx();
2925  BitmapEx aBitmapex = BitmapEx::AutoScaleBitmap(aBitmap, m_nExpectedSize);
2926  aImage = Image( aBitmapex);
2927  }
2928  m_xTbSymbol->InsertItem(nId, aImage, aURL, nPos); //modify
2929 
2930  m_aGraphics[nPos] = Graphic(aImage.GetBitmapEx()).GetXGraphic();
2931 
2932  URLs[0] = aURL;
2933  aImportGraph[ 0 ] = xGraphic;
2934  m_xImportedImageManager->replaceImages( SvxConfigPageHelper::GetImageType(), URLs, aImportGraph );
2935  m_xImportedImageManager->store();
2936 
2937  bResult = true;
2938  break;
2939  }
2940  catch ( css::uno::Exception& )
2941  {
2942  break;
2943  }
2944  }
2945  }
2946 
2947  return bResult;
2948 }
2949 
2950 namespace
2951 {
2952  OUString ReplaceIconName(const OUString& rMessage)
2953  {
2954  OUString name;
2955  OUString message = CuiResId( RID_SVXSTR_REPLACE_ICON_WARNING );
2956  OUString placeholder("%ICONNAME" );
2957  sal_Int32 pos = message.indexOf( placeholder );
2958  if ( pos != -1 )
2959  {
2960  name = message.replaceAt(
2961  pos, placeholder.getLength(), rMessage );
2962  }
2963  return name;
2964  }
2965 
2966  class SvxIconReplacementDialog
2967  {
2968  private:
2969  std::unique_ptr<weld::MessageDialog> m_xQueryBox;
2970  public:
2971  SvxIconReplacementDialog(weld::Window *pParent, const OUString& rMessage, bool bYestoAll)
2972  : m_xQueryBox(Application::CreateMessageDialog(pParent, VclMessageType::Warning, VclButtonsType::NONE, ReplaceIconName(rMessage)))
2973  {
2974  m_xQueryBox->set_title(CuiResId(RID_SVXSTR_REPLACE_ICON_CONFIRM));
2975  m_xQueryBox->add_button(GetStandardText(StandardButtonType::Yes), 2);
2976  if (bYestoAll)
2977  m_xQueryBox->add_button(CuiResId(RID_SVXSTR_YESTOALL), 5);
2978  m_xQueryBox->add_button(GetStandardText(StandardButtonType::No), 4);
2979  m_xQueryBox->add_button(GetStandardText(StandardButtonType::Cancel), 6);
2980  m_xQueryBox->set_default_response(2);
2981  }
2982  short run() { return m_xQueryBox->run(); }
2983  };
2984 }
2985 
2987  const uno::Sequence< OUString >& rPaths )
2988 {
2989  uno::Sequence< OUString > rejected( rPaths.getLength() );
2990  sal_Int32 rejectedCount = 0;
2991 
2992  sal_uInt16 ret = 0;
2993  sal_Int32 aIndex;
2994  OUString aIconName;
2995 
2996  if ( rPaths.getLength() == 1 )
2997  {
2998  if ( m_xImportedImageManager->hasImage( SvxConfigPageHelper::GetImageType(), rPaths[0] ) )
2999  {
3000  aIndex = rPaths[0].lastIndexOf( '/' );
3001  aIconName = rPaths[0].copy( aIndex+1 );
3002  SvxIconReplacementDialog aDlg(m_xDialog.get(), aIconName, false);
3003  ret = aDlg.run();
3004  if ( ret == 2 )
3005  {
3006  ReplaceGraphicItem( rPaths[0] );
3007  }
3008  }
3009  else
3010  {
3011  if ( !ImportGraphic( rPaths[0] ) )
3012  {
3013  rejected[0] = rPaths[0];
3014  rejectedCount = 1;
3015  }
3016  }
3017  }
3018  else
3019  {
3020  OUString aSourcePath( rPaths[0] );
3021  if ( rPaths[0].lastIndexOf( '/' ) != rPaths[0].getLength() -1 )
3022  aSourcePath = rPaths[0] + "/";
3023 
3024  for ( sal_Int32 i = 1; i < rPaths.getLength(); ++i )
3025  {
3026  OUString aPath = aSourcePath + rPaths[i];
3027  if ( m_xImportedImageManager->hasImage( SvxConfigPageHelper::GetImageType(), aPath ) )
3028  {
3029  aIndex = rPaths[i].lastIndexOf( '/' );
3030  aIconName = rPaths[i].copy( aIndex+1 );
3031  SvxIconReplacementDialog aDlg(m_xDialog.get(), aIconName, true);
3032  ret = aDlg.run();
3033  if ( ret == 2 )
3034  {
3035  ReplaceGraphicItem( aPath );
3036  }
3037  else if ( ret == 5 )
3038  {
3039  for ( sal_Int32 k = i; k < rPaths.getLength(); ++k )
3040  {
3041  aPath = aSourcePath + rPaths[k];
3042  bool bHasReplaced = ReplaceGraphicItem( aPath );
3043 
3044  if ( !bHasReplaced )
3045  {
3046  bool result = ImportGraphic( aPath );
3047  if ( !result )
3048  {
3049  rejected[ rejectedCount ] = rPaths[i];
3050  ++rejectedCount;
3051  }
3052  }
3053  }
3054  break;
3055  }
3056  }
3057  else
3058  {
3059  bool result = ImportGraphic( aSourcePath + rPaths[i] );
3060  if ( !result )
3061  {
3062  rejected[ rejectedCount ] = rPaths[i];
3063  ++rejectedCount;
3064  }
3065  }
3066  }
3067  }
3068 
3069  if ( rejectedCount != 0 )
3070  {
3071  OUStringBuffer message;
3072  OUString fPath;
3073  if (rejectedCount > 1)
3074  fPath = rPaths[0].copy(8) + "/";
3075  for ( sal_Int32 i = 0; i < rejectedCount; ++i )
3076  {
3077  message.append(fPath).append(rejected[i]).append("\n");
3078  }
3079 
3080  SvxIconChangeDialog aDialog(m_xDialog.get(), message.makeStringAndClear());
3081  aDialog.run();
3082  }
3083 }
3084 
3085 bool SvxIconSelectorDialog::ImportGraphic( const OUString& aURL )
3086 {
3087  bool result = false;
3088 
3089  uno::Sequence< beans::PropertyValue > aMediaProps( 1 );
3090  aMediaProps[0].Name = "URL";
3091 
3092  uno::Reference< graphic::XGraphic > xGraphic;
3093  css::awt::Size aSize;
3094  aMediaProps[0].Value <<= aURL;
3095  try
3096  {
3097  uno::Reference< beans::XPropertySet > props =
3098  m_xGraphProvider->queryGraphicDescriptor( aMediaProps );
3099 
3100  uno::Any a = props->getPropertyValue("SizePixel");
3101 
3102  xGraphic = m_xGraphProvider->queryGraphic( aMediaProps );
3103  if ( xGraphic.is() )
3104  {
3105  bool bOK = true;
3106 
3107  a >>= aSize;
3108  if ( 0 == aSize.Width || 0 == aSize.Height )
3109  bOK = false;
3110 
3111  Image aImage( xGraphic );
3112 
3113  if ( bOK && ((aSize.Width != m_nExpectedSize) || (aSize.Height != m_nExpectedSize)) )
3114  {
3115  BitmapEx aBitmap = aImage.GetBitmapEx();
3116  BitmapEx aBitmapex = BitmapEx::AutoScaleBitmap(aBitmap, m_nExpectedSize);
3117  aImage = Image( aBitmapex);
3118  }
3119  if ( bOK && !!aImage )
3120  {
3121  m_aGraphics.push_back(Graphic(aImage.GetBitmapEx()).GetXGraphic());
3122  m_xTbSymbol->InsertItem(m_aGraphics.size(), aImage, aURL);
3123 
3124  uno::Sequence<OUString> aImportURL { aURL };
3125  uno::Sequence< uno::Reference<graphic::XGraphic > > aImportGraph( 1 );
3126  aImportGraph[ 0 ] = xGraphic;
3127  m_xImportedImageManager->insertImages( SvxConfigPageHelper::GetImageType(), aImportURL, aImportGraph );
3128  if ( m_xImportedImageManager->isModified() )
3129  {
3130  m_xImportedImageManager->store();
3131  }
3132 
3133  result = true;
3134  }
3135  else
3136  {
3137  SAL_WARN("cui.customize", "could not create Image from XGraphic");
3138  }
3139  }
3140  else
3141  {
3142  SAL_WARN("cui.customize", "could not get query XGraphic");
3143  }
3144  }
3145  catch( uno::Exception const & )
3146  {
3147  TOOLS_WARN_EXCEPTION("cui.customize", "Caught exception importing XGraphic");
3148  }
3149  return result;
3150 }
3151 
3152 /*******************************************************************************
3153 *
3154 * The SvxIconChangeDialog class added for issue83555
3155 *
3156 *******************************************************************************/
3157 SvxIconChangeDialog::SvxIconChangeDialog(weld::Window *pWindow, const OUString& rMessage)
3158  : MessageDialogController(pWindow, "cui/ui/iconchangedialog.ui", "IconChange", "grid")
3159  , m_xLineEditDescription(m_xBuilder->weld_text_view("addrTextview"))
3160 {
3161  m_xLineEditDescription->set_size_request(m_xLineEditDescription->get_approximate_digit_width() * 48,
3162  m_xLineEditDescription->get_text_height() * 8);
3163  m_xLineEditDescription->set_text(rMessage);
3164 }
3165 
3167  : DropTargetHelper(rTreeView.get_drop_target())
3168  , m_rPage(rPage)
3169  , m_rTreeView(rTreeView)
3170 {
3171 }
3172 
3174 {
3175  // to enable the autoscroll when we're close to the edges
3177  return DND_ACTION_MOVE;
3178 }
3179 
3181 {
3183  // only dragging within the same widget allowed
3184  if (!pSource || pSource != &m_rTreeView)
3185  return DND_ACTION_NONE;
3186 
3187  std::unique_ptr<weld::TreeIter> xSource(m_rTreeView.make_iterator());
3188  if (!m_rTreeView.get_selected(xSource.get()))
3189  return DND_ACTION_NONE;
3190 
3191  std::unique_ptr<weld::TreeIter> xTarget(m_rTreeView.make_iterator());
3192  int nTargetPos = -1;
3193  if (m_rTreeView.get_dest_row_at_pos(rEvt.maPosPixel, xTarget.get()))
3194  nTargetPos = m_rTreeView.get_iter_index_in_parent(*xTarget);
3195  m_rTreeView.move_subtree(*xSource, nullptr, nTargetPos);
3196 
3198 
3199  return DND_ACTION_NONE;
3200 }
3201 
3202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void RemoveToolbar(SvxConfigEntry *pToolbar)
Definition: cfg.cxx:2448
bool ReplaceGraphicItem(const OUString &aURL)
Definition: cfg.cxx:2874
IMPL_LINK_NOARG(SvxConfigPage, SelectElementHdl, weld::ComboBox &, void)
Definition: cfg.cxx:1013
std::shared_ptr< weld::Dialog > m_xDialog
static const char ITEM_DESCRIPTOR_RESOURCEURL[]
Definition: cfg.hxx:49
static OUString replaceSixteen(const OUString &str, sal_Int32 nReplacement)
static std::unique_ptr< SfxTabPage > CreateSvxNotebookbarConfigPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: cfg.cxx:178
OUString m_aDescriptorContainer
Definition: cfg.hxx:537
std::unique_ptr< CuiConfigFunctionListBox > m_xFunctions
Definition: cfg.hxx:388
virtual int get_iter_index_in_parent(const TreeIter &rIter) const =0
SvxEntries * GetEntries() const
Definition: cfg.hxx:288
virtual short QueryReset()=0
static const char ITEM_DESCRIPTOR_TYPE[]
Definition: cfg.hxx:46
std::unique_ptr< weld::Entry > m_xEdtName
Definition: cfg.hxx:587
std::unique_ptr< weld::Button > m_xMoveDownButton
Definition: cfg.hxx:514
#define KEY_DELETE
const css::uno::Reference< css::ui::XImageManager > & GetImageManager() const
Definition: cfg.hxx:140
const OUString & GetName() const
Definition: cfg.hxx:276
std::unique_ptr< weld::Widget > m_xMenuBox
Definition: cfg.hxx:510
void Init()
OUString m_aURLToSelect
the ResourceURL to select when opening the dialog
Definition: cfg.hxx:381
static const char ITEM_DESCRIPTOR_UINAME[]
Definition: cfg.hxx:50
virtual ~SvxMainMenuOrganizerDialog() override
Definition: cfg.cxx:1764
static OUString stripHotKey(const OUString &str)
VclButtonsType
css::uno::Reference< css::container::XNameAccess > m_xPersistentWindowState
Definition: cfg.hxx:540
std::string GetValue
void SetFrame(const css::uno::Reference< css::frame::XFrame > &xFrame)
Definition: cfg.cxx:227
void SetModified(bool bValue=true)
Definition: cfg.hxx:297
SvxConfigPage & m_rPage
Definition: cfg.hxx:358
OUString GetStandardText(StandardButtonType eButton)
OUString GetPopupLabelForCommand(const OUString &rsCommandName, const OUString &rsModuleName)
void Reset() override
Definition: cfg.cxx:661
static MenuSaveInData * GetDefaultData()
Definition: cfg.hxx:178
signed char sal_Int8
virtual SaveInData * CreateSaveInData(const css::uno::Reference< css::ui::XUIConfigurationManager > &, const css::uno::Reference< css::ui::XUIConfigurationManager > &, const OUString &aModuleId, bool docConfig)=0
OUString GetSystemUIName(const OUString &rResourceURL)
Definition: cfg.cxx:2031
bool bDocConfig
Definition: cfg.hxx:82
void Reset(const SfxItemSet *) override
Definition: cfg.cxx:1022
css::uno::Reference< css::frame::XFrame > m_xFrame
Definition: cfg.hxx:383
std::unique_ptr< weld::Button > m_xBtnImport
Definition: cfg.hxx:623
virtual void scroll_to_row(int pos)=0
static MenuSaveInData * pDefaultData
static holder of the default menu data
Definition: cfg.hxx:175
static std::unique_ptr< SfxTabPage > CreateSvxToolbarConfigPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: cfg.cxx:184
SvxConfigEntry * GetTopLevelSelection()
Definition: cfg.hxx:483
static bool showKeyConfigTabPage(const css::uno::Reference< css::frame::XFrame > &xFrame)
static sal_Int16 GetImageType()
static VclPtr< vcl::Window > GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
virtual TreeView * get_drag_source() const =0
Timer m_aUpdateDataTimer
Definition: cfg.hxx:372
bool IsPopup() const
Definition: cfg.hxx:280
css::uno::Reference< css::graphic::XGraphicProvider > m_xGraphProvider
Definition: cfg.hxx:616
bool HasSettings() override
Definition: cfg.cxx:841
void RemoveTabPage(const OString &rName)
void printEntries(SvxEntries *entries)
Definition: cfg.cxx:147
sal_Int16 nId
static OUString GetUIModuleName(const OUString &aModuleId, const css::uno::Reference< css::frame::XModuleManager2 > &rModuleManager)
const css::uno::Reference< css::ui::XUIConfigurationManager > & GetConfigManager() const
Definition: cfg.hxx:132
static void SetDefaultData(MenuSaveInData *pData)
Definition: cfg.hxx:177
css::uno::Reference< css::ui::XImageManager > m_xParentImageManager
Definition: cfg.hxx:610
sal_uInt16 GetCode() const
virtual void MoveEntry(bool bMoveUp)
Definition: cfg.cxx:1619
css::uno::Reference< css::graphic::XGraphic > GetImage(const OUString &rCommandURL)
Definition: cfg.cxx:323
void InsertEntryIntoUI(SvxConfigEntry *pNewEntryData, int nPos, int nStartCol)
Definition: cfg.cxx:1515
static const char CUSTOM_TOOLBAR_STR[]
Definition: cfg.hxx:55
WinBits const WB_VSCROLL
OUString Name
virtual sal_Int8 AcceptDrop(const AcceptDropEvent &rEvt) override
Definition: cfg.cxx:3173
bool IsReadOnly() const
Definition: cfg.hxx:127
std::unique_ptr< SvxMenuEntriesListBox > m_xContentsListBox
Definition: cfg.hxx:404
void AddSubMenusToUI(const OUString &rBaseTitle, SvxConfigEntry const *pParentData)
Definition: cfg.cxx:1364
void SetButtonType(ButtonType eNewType)
SvxIconSelectorDialog(weld::Window *pWindow, const css::uno::Reference< css::ui::XImageManager > &rXImageManager, const css::uno::Reference< css::ui::XImageManager > &rXParentImageManager)
Definition: cfg.cxx:2630
void ReloadTopLevelListBox(SvxConfigEntry const *pSelection=nullptr)
Definition: cfg.cxx:1330
static css::uno::Reference< css::graphic::XGraphic > GetGraphic(const css::uno::Reference< css::ui::XImageManager > &xImageManager, const OUString &rCommandURL)
std::unique_ptr< weld::Entry > m_xMenuNameEdit
Definition: cfg.hxx:511
OUString m_aDescriptorContainer
Definition: cfg.hxx:167
virtual std::unique_ptr< TreeIter > make_iterator(const TreeIter *pOrig=nullptr) const =0
static BitmapEx AutoScaleBitmap(BitmapEx const &aBitmap, const long aStandardSize)
NONE
static const char aMenuSeparatorStr[]
Definition: cfg.hxx:57
std::vector< SvxConfigEntry * > SvxEntries
Definition: cfg.hxx:60
bool HasURL(const OUString &rURL) override
Definition: cfg.cxx:831
std::unique_ptr< weld::ComboBox > m_xTopLevelListBox
Definition: cfg.hxx:401
#define DND_ACTION_MOVE
bool IsRenamable() const
Definition: cfg.cxx:1877
const OUString & GetCommand() const
Definition: cfg.hxx:274
static bool SvxConfigEntryModified(SvxConfigEntry const *pEntry)
void connect_changed(const Link< TreeView &, void > &rLink)
sal_uInt16 sal_Unicode
this is only to let callers know that there is a LateInit which must be called
Definition: eventdlg.hxx:43
virtual void ListModified()
Definition: cfg.hxx:481
Reference< XController > xController
RET_YES
virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent &rEvt) override
Definition: cfg.cxx:3180
bool FillItemSet(SfxItemSet *) override
Definition: cfg.cxx:1310
void LoadSubMenus(const css::uno::Reference< css::container::XIndexAccess > &xMenuSettings, const OUString &rBaseTitle, SvxConfigEntry const *pParentData, bool bContextMenu)
Definition: cfg.cxx:435
void ApplyMenu(css::uno::Reference< css::container::XIndexContainer > const &rMenuBar, css::uno::Reference< css::lang::XSingleComponentFactory > &rFactory, SvxConfigEntry *pMenuData)
Definition: cfg.cxx:615
enumrange< T >::Iterator begin(enumrange< T >)
#define WB_ITEMBORDER
SvxEntries * GetEntries() override
Definition: cfg.cxx:2091
std::unique_ptr< weld::Label > m_xFtNote
Definition: cfg.hxx:622
std::unique_ptr< weld::TreeView > m_xControl
Definition: cfg.hxx:320
SfxFrame & GetFrame() const
css::uno::Reference< css::ui::XImageManager > m_xImgMgr
Definition: cfg.hxx:92
#define DND_ACTION_NONE
static void RemoveEntry(SvxEntries *pEntries, SvxConfigEntry const *pChildEntry)
static OUString generateCustomMenuURL(SvxEntries *entries, sal_Int32 suffix=1)
bool IsModified() const
Definition: cfg.hxx:125
ToolbarSaveInData(const css::uno::Reference< css::ui::XUIConfigurationManager > &, const css::uno::Reference< css::ui::XUIConfigurationManager > &, const OUString &aModuleId, bool docConfig)
Definition: cfg.cxx:1882
void printProperties(const OUString &prefix, const uno::Sequence< beans::PropertyValue > &aProp)
Definition: cfg.cxx:133
void SetName(const OUString &rStr)
Definition: cfg.hxx:277
void SetMain()
Definition: cfg.hxx:291
static bool CanConfig(const OUString &rModuleId)
Definition: cfg.cxx:158
VclMessageType
static std::unique_ptr< SfxTabPage > CreateKeyboardConfigPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: cfg.cxx:173
std::unique_ptr< weld::Button > m_xMoveUpButton
Definition: cfg.hxx:513
bool IsParentData() const
Definition: cfg.hxx:295
void SetFrame(const css::uno::Reference< css::frame::XFrame > &xFrame)
def run
static OUString generateCustomName(const OUString &prefix, SvxEntries *entries, sal_Int32 suffix=1)
void connect_row_activated(const Link< TreeView &, bool > &rLink)
int AppendEntry(SvxConfigEntry *pNewEntryData, int nTarget)
Definition: cfg.cxx:1451
std::unique_ptr< SvxConfigEntry > pRootEntry
Definition: cfg.hxx:172
static css::uno::Reference< css::ui::XImageManager > * xDefaultImgMgr
Definition: cfg.hxx:98
OUString GetUIName(const OUString &rResourceURL)
Definition: cfg.cxx:700
const css::uno::Reference< css::ui::XUIConfigurationManager > & GetParentConfigManager() const
Definition: cfg.hxx:136
bool Apply() override
Definition: cfg.cxx:547
IMPL_LINK(SvxMenuEntriesListBox, KeyInputHdl, const KeyEvent &, rKeyEvent, bool)
Definition: cfg.cxx:939
void LoadToolbar(const css::uno::Reference< css::container::XIndexAccess > &xToolBarSettings, SvxConfigEntry const *pParentData)
Definition: cfg.cxx:2534
bool IsEmpty() const
bool HasURL(const OUString &rURL) override
Definition: cfg.cxx:2271
static bool EntrySort(SvxConfigEntry const *a, SvxConfigEntry const *b)
virtual bool Apply()=0
#define DBG_UNHANDLED_EXCEPTION(...)
void SetParentData(bool bValue=true)
Definition: cfg.hxx:294
OUString GetMenuLabelForCommand(const OUString &rsCommandName, const OUString &rsModuleName)
#define TOOLS_WARN_EXCEPTION(area, stream)
css::uno::Reference< css::container::XIndexAccess > m_xMenuSettings
Definition: cfg.hxx:170
void SetSystemStyle(const OUString &rResourceURL, sal_Int32 nStyle)
Definition: cfg.cxx:1992
SvxEntries * FindParentForChild(SvxEntries *pParentEntries, SvxConfigEntry *pChildData)
Definition: cfg.cxx:1381
css::uno::Reference< css::frame::XFrame > GetFrame() const
OUString GetModuleIdentifier(const Reference< frame::XFrame > &rxFrame)
#define DBG_ASSERT(sCon, aError)
static OUString getProductName()
css::uno::Reference< css::container::XNameAccess > m_xCommandToLabelMap
Definition: cfg.hxx:144
#define notebookbarTabScope
Definition: cfg.hxx:41
static const char ITEM_DESCRIPTOR_STYLE[]
Definition: cfg.hxx:47
std::unique_ptr< SvxConfigEntry > m_pRootEntry
Definition: cfg.hxx:206
void SetUserDefined(bool bOn=true)
Definition: cfg.hxx:282
static const char ITEM_DESCRIPTOR_LABEL[]
Definition: cfg.hxx:45
SvxMainMenuOrganizerDialog(weld::Window *, SvxEntries *, SvxConfigEntry const *, bool bCreateMenu)
Definition: cfg.cxx:1695
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
bool bInitialised
Definition: cfg.hxx:373
virtual ~ContextMenuSaveInData() override
Definition: cfg.cxx:696
virtual int get_selected_index() const =0
static css::uno::Sequence< css::beans::PropertyValue > ConvertToolbarEntry(const SvxConfigEntry *pEntry)
SfxCfgKind nKind
Definition: cfgutil.hxx:89
virtual bool get_dest_row_at_pos(const Point &rPos, weld::TreeIter *pResult)=0
MetadataImporterPluginType * result
int i
QPRO_FUNC_TYPE const nType
virtual ~ToolbarSaveInData() override
Definition: cfg.cxx:1900
static css::uno::Sequence< css::beans::PropertyValue > ConvertSvxConfigEntry(const SvxConfigEntry *pEntry)
virtual ~SvxIconSelectorDialog() override
Definition: cfg.cxx:2787
virtual ~SvxNewToolbarDialog() override
Definition: cfg.cxx:2621
css::uno::Reference< css::container::XNameAccess > m_xPersistentWindowState
Definition: cfg.hxx:207
css::uno::Reference< css::ui::XImageManager > m_xParentImgMgr
Definition: cfg.hxx:95
Object Value
void SetVisible(bool b)
Definition: cfg.hxx:304
void SetStyle(sal_Int32 style)
Definition: cfg.hxx:314
virtual void Reset()=0
bool Apply() override
Definition: cfg.cxx:2325
ContextMenuSaveInData(const css::uno::Reference< css::ui::XUIConfigurationManager > &xCfgMgr, const css::uno::Reference< css::ui::XUIConfigurationManager > &xParentCfgMgr, const OUString &aModuleId, bool bIsDocConfig)
Definition: cfg.cxx:685
static const char ITEM_TOOLBAR_URL[]
Definition: cfg.hxx:53
OUString GetScriptURL() const
Definition: cfg.cxx:1287
sal_Int32 m_nExpectedSize
Definition: cfg.hxx:604
bool PersistChanges(const css::uno::Reference< css::uno::XInterface > &xManager)
Definition: cfg.cxx:336
bool IsMovable() const
Definition: cfg.cxx:1867
void ResetContextMenu(const SvxConfigEntry *pEntry)
Definition: cfg.cxx:894
SvxNewToolbarDialog(weld::Window *pWindow, const OUString &rName)
Definition: cfg.cxx:2611
void SetTimeout(sal_uInt64 nTimeoutMs)
std::unique_ptr< SvtValueSet > m_xTbSymbol
Definition: cfg.hxx:620
SfxItemPool * GetPool() const
css::uno::Reference< css::ui::XUIConfigurationManager > m_xParentCfgMgr
Definition: cfg.hxx:89
OUString CuiResId(const char *pKey)
Definition: cuiresmgr.cxx:23
virtual ~MenuSaveInData() override
Definition: cfg.cxx:404
virtual ~SvxMenuEntriesListBox()
Definition: cfg.cxx:935
ScopedVclPtr< VirtualDevice > m_xDropDown
Definition: cfg.hxx:321
enumrange< T >::Iterator end(enumrange< T >)
static const char ITEM_MENUBAR_URL[]
Definition: cfg.hxx:52
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
std::unique_ptr< weld::TextView > m_xLineEditDescription
Definition: cfg.hxx:653
SaveInData(const css::uno::Reference< css::ui::XUIConfigurationManager > &xCfgMgr, const css::uno::Reference< css::ui::XUIConfigurationManager > &xParentCfgMgr, const OUString &aModuleId, bool docConfig)
Definition: cfg.cxx:268
bool ImportGraphic(const OUString &aURL)
Definition: cfg.cxx:3085
OUString GetSelectedDisplayName() const
Definition: cfg.cxx:1305
std::unique_ptr< weld::Entry > m_xSearchEdit
Definition: cfg.hxx:394
OUString m_sNewMenuEntryId
Definition: cfg.hxx:508
std::unique_ptr< SvxEntries > mpEntries
Definition: cfg.hxx:250
sal_Int32 GetStyle() const
Definition: cfg.hxx:313
bool IsUserDefined() const
Definition: cfg.hxx:283
SaveInData * pCurrentSaveInData
Definition: cfg.hxx:374
virtual ~SvxConfigPage() override
Definition: cfg.cxx:1018
void Reset() override
Definition: cfg.cxx:2289
virtual void swap(int pos1, int pos2)=0
void RestoreToolbar(SvxConfigEntry *pToolbar)
Definition: cfg.cxx:2471
virtual void select(int pos)=0
static const char ITEM_DESCRIPTOR_CONTAINER[]
Definition: cfg.hxx:44
weld::Window * GetFrameWeld() const
std::unique_ptr< SvxEntries > mpEntries
Definition: cfg.hxx:507
static SfxViewFrame * Current()
SvxMenuEntriesListBox(std::unique_ptr< weld::TreeView > xControl, SvxConfigPage *pPage)
Definition: cfg.cxx:926
bool MoveEntryData(int SourceEntry, int nTargetEntry)
Definition: cfg.cxx:1655
css::uno::Reference< css::ui::XImageManager > m_xImageManager
Definition: cfg.hxx:607
virtual void UpdateButtonStates()=0
#define KEY_DOWN
bool Apply() override
Definition: cfg.cxx:846
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
#define ERRCODE_NONE
virtual bool get_selected(TreeIter *pIter) const =0
bool IsMain() const
Definition: cfg.hxx:292
static std::unique_ptr< SfxTabPage > CreateSvxEventConfigPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: cfg.cxx:189
OUString sCommand
Definition: cfgutil.hxx:92
void SetModified(bool bValue=true)
Definition: cfg.hxx:124
#define EDIT_UPDATEDATA_TIMEOUT
int AddFunction(int nTarget, bool bAllowDuplicates)
Definition: cfg.cxx:1405
~SvxConfigEntry()
Definition: cfg.cxx:1856
void SetEntries(std::unique_ptr< SvxEntries > pNewEntries) override
Definition: cfg.cxx:826
bool bPopUp
Definition: cfg.hxx:236
virtual bool HasSettings()=0
SvxIconChangeDialog(weld::Window *pWindow, const OUString &rMessage)
Definition: cfg.cxx:3157
bool HasSettings() override
Definition: cfg.cxx:2283
RET_OK
bool IsDeletable() const
Definition: cfg.cxx:1872
virtual void Init()=0
SvxConfigDialog(weld::Window *, const SfxItemSet *)
Definition: cfg.cxx:201
bool IsMod1() const
void ImportGraphics(const css::uno::Sequence< OUString > &aURLs)
Definition: cfg.cxx:2986
SvxConfigPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &)
Definition: cfg.cxx:971
void AddTabPage(const OString &rName, CreateTabPage pCreateFunc, GetTabPageRanges pRangesFunc)
virtual int get_height_rows(int nRows) const =0
virtual short run()
Reference< XComponentContext > getProcessComponentContext()
void CreateToolbar(SvxConfigEntry *pToolbar)
Definition: cfg.cxx:2421
static std::unique_ptr< SfxTabPage > CreateSvxMenuConfigPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: cfg.cxx:163
const char * name
void SetEntries(std::unique_ptr< SvxEntries >) override
Definition: cfg.cxx:430
void SetInvokeHandler(const Link< Timer *, void > &rLink)
double getLength(const B2DPolygon &rCandidate)
static bool IsHelpInstalled()
std::unique_ptr< weld::Button > m_xBtnDelete
Definition: cfg.hxx:624
SvxEntries * GetEntries() override
Definition: cfg.cxx:725
SvxConfigPageFunctionDropTarget(SvxConfigPage &rPage, weld::TreeView &rTreeView)
Definition: cfg.cxx:3166
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage)
SvxEntries * GetEntries() override
methods inherited from SaveInData
Definition: cfg.cxx:409
BitmapEx GetBitmapEx() const
std::unique_ptr< weld::ComboBox > m_xSaveInListBox
Definition: cfg.hxx:410
virtual bool HasURL(const OUString &aURL)=0
OUString GetLabelForCommand(const OUString &rsCommandName, const OUString &rsModuleName)
void ApplyToolbar(css::uno::Reference< css::container::XIndexContainer > const &rNewToolbarBar, css::uno::Reference< css::lang::XSingleComponentFactory > &rFactory, SvxConfigEntry const *pToolbar)
void SetEntries(std::unique_ptr< SvxEntries >) override
Definition: cfg.cxx:2265
SvxConfigEntry * GetSelectedEntry()
Definition: cfg.cxx:1828
static bool GetToolbarItemData(const css::uno::Reference< css::container::XIndexAccess > &rItemContainer, sal_Int32 nIndex, OUString &rCommandURL, OUString &rLabel, sal_uInt16 &rType, bool &rIsVisible, sal_Int32 &rStyle)
def text(shape, st)
OString const aName
void Reset() override
Definition: cfg.cxx:876
WindowType GetType() const
std::unique_ptr< weld::TreeView > m_xMenuListBox
Definition: cfg.hxx:512
std::unique_ptr< weld::TextView > m_xDescriptionField
Definition: cfg.hxx:392
bool bReadOnly
Definition: cfg.hxx:83
VirtualDevice * get() const
weld::TreeView & m_rTreeView
Definition: cfg.hxx:359
css::uno::Reference< css::ui::XImageManager > m_xImportedImageManager
Definition: cfg.hxx:613
#define SAL_WARN(area, stream)
void DrawSymbol(const tools::Rectangle &rRect, SymbolType eType, const Color &rColor, DrawSymbolFlags nStyle=DrawSymbolFlags::NONE)
Reference< XModel > xModel
static OUString GetFrameWithDefaultAndIdentify(css::uno::Reference< css::frame::XFrame > &_inout_rxFrame)
identifies the module in the given frame.
Definition: cfg.cxx:1239
css::uno::Reference< css::graphic::XGraphic > GetSelectedIcon()
Definition: cfg.cxx:2791
std::vector< css::uno::Reference< css::graphic::XGraphic > > m_aGraphics
Definition: cfg.hxx:618
bool IsSeparator() const
Definition: cfg.hxx:286
static bool GetMenuItemData(const css::uno::Reference< css::container::XIndexAccess > &rItemContainer, sal_Int32 nIndex, OUString &rCommandURL, OUString &rLabel, sal_uInt16 &rType, sal_Int32 &rStyle, css::uno::Reference< css::container::XIndexAccess > &rSubMenu)
css::uno::Sequence< css::beans::PropertyValue > m_aSeparatorSeq
Definition: cfg.hxx:150
static std::unique_ptr< SfxTabPage > CreateSvxContextMenuConfigPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: cfg.cxx:168
void CreateDropDown()
Definition: cfg.cxx:908
bool IsDocConfig() const
Definition: cfg.hxx:128
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
OUString m_aMenuResourceURL
Definition: cfg.hxx:166
sal_Int32 nPos
void printPropertySet(const OUString &prefix, const uno::Reference< beans::XPropertySet > &xPropSet)
Definition: cfg.cxx:99
css::uno::Reference< css::frame::XFrame > m_xFrame
Definition: cfg.hxx:67
virtual void PageCreated(const OString &rId, SfxTabPage &rPage) override
Definition: cfg.cxx:245
Warning
SaveInData * GetSaveInData()
Definition: cfg.hxx:466
virtual float get_approximate_digit_width() const =0
virtual void move_subtree(TreeIter &rNode, const TreeIter *pNewParent, int nIndexInNewParent)=0
MenuSaveInData(const css::uno::Reference< css::ui::XUIConfigurationManager > &, const css::uno::Reference< css::ui::XUIConfigurationManager > &, const OUString &aModuleId, bool docConfig)
Definition: cfg.cxx:372
sal_Int32 GetSystemStyle(const OUString &rResourceURL)
Definition: cfg.cxx:1904
virtual void SelectElement()=0
void SetCurPageId(const OString &rName)
void SetDebugName(const sal_Char *pDebugName)
std::unique_ptr< SvxConfigEntry > pRootEntry
Definition: cfg.hxx:536
#define KEY_UP
SvxConfigEntry()
Definition: cfg.hxx:259
OUString sId