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