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