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