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