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