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