File: | home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx |
Warning: | line 1979, column 31 Use of memory after it is freed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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> | |||
28 | #include <vcl/commandinfoprovider.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> | |||
45 | #include <toolkit/helper/vclunohelper.hxx> | |||
46 | ||||
47 | #include <algorithm> | |||
48 | #include <strings.hrc> | |||
49 | ||||
50 | #include <acccfg.hxx> | |||
51 | #include <cfg.hxx> | |||
52 | #include <CustomNotebookbarGenerator.hxx> | |||
53 | #include <SvxMenuConfigPage.hxx> | |||
54 | #include <SvxToolbarConfigPage.hxx> | |||
55 | #include <SvxNotebookbarConfigPage.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> | |||
88 | #include <comphelper/documentinfo.hxx> | |||
89 | #include <comphelper/propertysequence.hxx> | |||
90 | #include <comphelper/processfactory.hxx> | |||
91 | ||||
92 | namespace uno = com::sun::star::uno; | |||
93 | namespace frame = com::sun::star::frame; | |||
94 | namespace lang = com::sun::star::lang; | |||
95 | namespace container = com::sun::star::container; | |||
96 | namespace beans = com::sun::star::beans; | |||
97 | namespace graphic = com::sun::star::graphic; | |||
98 | ||||
99 | #if OSL_DEBUG_LEVEL1 > 1 | |||
100 | ||||
101 | void printPropertySet( | |||
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" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "cui")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "printPropertySet: " << aPropDetails.getLength () << " properties") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("cui"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "111" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "printPropertySet: " << aPropDetails .getLength() << " properties"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "printPropertySet: " << aPropDetails.getLength() << " properties"; :: sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "111" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "printPropertySet: " << aPropDetails.getLength () << " properties") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("cui"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "111" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "printPropertySet: " << aPropDetails .getLength() << " properties"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "printPropertySet: " << aPropDetails.getLength() << " properties"; :: sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "111" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
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)do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "cui")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << prefix << ": Got property: " << aPropDetail .Name << tmp) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("cui"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "122" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << prefix << ": Got property: " << aPropDetail.Name << tmp), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << prefix << ": Got property: " << aPropDetail.Name << tmp; :: sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "122" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << prefix << ": Got property: " << aPropDetail .Name << tmp) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("cui"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "122" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << prefix << ": Got property: " << aPropDetail.Name << tmp), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << prefix << ": Got property: " << aPropDetail.Name << tmp; :: sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "122" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
123 | } | |||
124 | else if ( ( a >>= ival ) ) | |||
125 | { | |||
126 | SAL_WARN("cui", prefix << ": Got property: " << aPropDetail.Name << " = " << ival)do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "cui")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << prefix << ": Got property: " << aPropDetail .Name << " = " << ival) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "126" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << prefix << ": Got property: " << aPropDetail.Name << " = " << ival), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << prefix << ": Got property: " << aPropDetail.Name << " = " << ival; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("cui"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "126" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << prefix << ": Got property: " << aPropDetail .Name << " = " << ival) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "126" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << prefix << ": Got property: " << aPropDetail.Name << " = " << ival), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << prefix << ": Got property: " << aPropDetail.Name << " = " << ival; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("cui"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "126" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
127 | } | |||
128 | else | |||
129 | { | |||
130 | SAL_WARN("cui", prefix << ": Got property: " << aPropDetail.Name << " of type " << a.getValueTypeName())do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "cui")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << prefix << ": Got property: " << aPropDetail .Name << " of type " << a.getValueTypeName()) == 1 ) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "130" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << prefix << ": Got property: " << aPropDetail.Name << " of type " << a.getValueTypeName ()), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << prefix << ": Got property: " << aPropDetail .Name << " of type " << a.getValueTypeName(); ::sal ::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "130" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << prefix << ": Got property: " << aPropDetail .Name << " of type " << a.getValueTypeName()) == 1 ) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "130" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << prefix << ": Got property: " << aPropDetail.Name << " of type " << a.getValueTypeName ()), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << prefix << ": Got property: " << aPropDetail .Name << " of type " << a.getValueTypeName(); ::sal ::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "130" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
131 | } | |||
132 | } | |||
133 | } | |||
134 | ||||
135 | void printProperties( | |||
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)do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "cui")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << prefix << ": Got property: " << aPropVal .Name << " = " << tmp) == 1) { ::sal_detail_log( ( ::SAL_DETAIL_LOG_LEVEL_WARN), ("cui"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "145" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << prefix << ": Got property: " << aPropVal.Name << " = " << tmp), 0); } else { ::std ::ostringstream sal_detail_stream; sal_detail_stream << prefix << ": Got property: " << aPropVal.Name << " = " << tmp; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("cui"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "145" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << prefix << ": Got property: " << aPropVal .Name << " = " << tmp) == 1) { ::sal_detail_log( ( ::SAL_DETAIL_LOG_LEVEL_WARN), ("cui"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "145" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << prefix << ": Got property: " << aPropVal.Name << " = " << tmp), 0); } else { ::std ::ostringstream sal_detail_stream; sal_detail_stream << prefix << ": Got property: " << aPropVal.Name << " = " << tmp; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("cui"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "145" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
146 | } | |||
147 | } | |||
148 | ||||
149 | void printEntries(SvxEntries* entries) | |||
150 | { | |||
151 | for (auto const& entry : *entries) | |||
152 | { | |||
153 | SAL_WARN("cui", "printEntries: " << entry->GetName())do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "cui")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "printEntries: " << entry->GetName()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui" ), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "153" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "printEntries: " << entry->GetName ()), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "printEntries: " << entry->GetName(); ::sal ::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "153" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "printEntries: " << entry->GetName()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui" ), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "153" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "printEntries: " << entry->GetName ()), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "printEntries: " << entry->GetName(); ::sal ::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "153" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
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 | *****************************************************************************/ | |||
203 | SvxConfigDialog::SvxConfigDialog(weld::Window * pParent, const SfxItemSet* pInSet) | |||
204 | : SfxTabDialogController(pParent, "cui/ui/customizedialog.ui", "CustomizeDialog", pInSet) | |||
205 | { | |||
206 | SvxConfigPageHelper::InitImageType(); | |||
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(5000 + 904) ) ); | |||
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; | |||
232 | OUString aModuleId = SvxConfigPage::GetFrameWithDefaultAndIdentify(m_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 | ||||
267 | SaveInData::SaveInData( | |||
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 ); | |||
280 | m_aSeparatorSeq[0].Name = ITEM_DESCRIPTOR_TYPE; | |||
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 | |||
308 | xDefaultImgMgr = &m_xImgMgr; | |||
309 | } | |||
310 | else | |||
311 | { | |||
312 | // If this is a document configuration then use the module image manager | |||
313 | // as default. | |||
314 | if ( m_xParentCfgMgr.is() ) | |||
315 | { | |||
316 | m_xParentImgMgr.set( m_xParentCfgMgr->getImageManager(), uno::UNO_QUERY ); | |||
317 | xDefaultImgMgr = &m_xParentImgMgr; | |||
318 | } | |||
319 | } | |||
320 | } | |||
321 | ||||
322 | uno::Reference<graphic::XGraphic> SaveInData::GetImage(const OUString& rCommandURL) | |||
323 | { | |||
324 | uno::Reference< graphic::XGraphic > xGraphic = | |||
325 | SvxConfigPageHelper::GetGraphic( m_xImgMgr, rCommandURL ); | |||
326 | ||||
327 | if (!xGraphic.is() && xDefaultImgMgr != nullptr && (*xDefaultImgMgr).is()) | |||
328 | { | |||
329 | xGraphic = SvxConfigPageHelper::GetGraphic( (*xDefaultImgMgr), rCommandURL ); | |||
330 | } | |||
331 | ||||
332 | return xGraphic; | |||
333 | } | |||
334 | ||||
335 | bool SaveInData::PersistChanges( | |||
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 | |||
369 | MenuSaveInData* MenuSaveInData::pDefaultData = nullptr; | |||
370 | ||||
371 | MenuSaveInData::MenuSaveInData( | |||
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( | |||
379 | ITEM_MENUBAR_URL ), | |||
380 | m_aDescriptorContainer( | |||
381 | ITEM_DESCRIPTOR_CONTAINER ) | |||
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 | ||||
402 | MenuSaveInData::~MenuSaveInData() | |||
403 | { | |||
404 | } | |||
405 | ||||
406 | SvxEntries* | |||
407 | MenuSaveInData::GetEntries() | |||
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 | ||||
545 | bool MenuSaveInData::Apply() | |||
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( | |||
567 | m_aMenuResourceURL, m_xMenuSettings ); | |||
568 | } | |||
569 | else | |||
570 | { | |||
571 | GetConfigManager()->insertSettings( | |||
572 | m_aMenuResourceURL, m_xMenuSettings ); | |||
573 | } | |||
574 | } | |||
575 | catch ( css::uno::Exception& ) | |||
576 | { | |||
577 | TOOLS_WARN_EXCEPTION("cui.customize", "caught some other exception saving settings")do { css::uno::Any tools_warn_exception( DbgGetCaughtException () ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "cui.customize")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break ; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "caught some other exception saving settings" << " " << exceptionToString(tools_warn_exception )) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ( "cui.customize"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "577" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "caught some other exception saving settings" << " " << exceptionToString(tools_warn_exception )), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "caught some other exception saving settings" << " " << exceptionToString(tools_warn_exception); ::sal:: detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize") , ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "577" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "caught some other exception saving settings" << " " << exceptionToString(tools_warn_exception)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize" ), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "577" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "caught some other exception saving settings" << " " << exceptionToString(tools_warn_exception )), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "caught some other exception saving settings" << " " << exceptionToString(tools_warn_exception); ::sal:: detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize") , ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "577" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); } while (false); | |||
578 | } | |||
579 | ||||
580 | SetModified( false ); | |||
581 | ||||
582 | result = PersistChanges( GetConfigManager() ); | |||
583 | } | |||
584 | ||||
585 | return result; | |||
586 | } | |||
587 | ||||
588 | void MenuSaveInData::Apply( | |||
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 = | |||
597 | SvxConfigPageHelper::ConvertSvxConfigEntry(entryData); | |||
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 | ||||
613 | void SaveInData::ApplyMenu( | |||
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 = | |||
625 | SvxConfigPageHelper::ConvertSvxConfigEntry(entry); | |||
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 = | |||
650 | SvxConfigPageHelper::ConvertSvxConfigEntry(entry); | |||
651 | rMenuBar->insertByIndex( | |||
652 | rMenuBar->getCount(), uno::Any( aPropValueSeq )); | |||
653 | } | |||
654 | } | |||
655 | pMenuData->SetModified( false ); | |||
656 | } | |||
657 | ||||
658 | void | |||
659 | MenuSaveInData::Reset() | |||
660 | { | |||
661 | try | |||
662 | { | |||
663 | GetConfigManager()->removeSettings( m_aMenuResourceURL ); | |||
664 | } | |||
665 | catch ( const css::uno::Exception& ) | |||
666 | {} | |||
667 | ||||
668 | PersistChanges( GetConfigManager() ); | |||
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 | ||||
683 | ContextMenuSaveInData::ContextMenuSaveInData( | |||
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 | ||||
694 | ContextMenuSaveInData::~ContextMenuSaveInData() | |||
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 | ||||
723 | SvxEntries* ContextMenuSaveInData::GetEntries() | |||
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 | ||||
839 | bool ContextMenuSaveInData::HasSettings() | |||
840 | { | |||
841 | return m_pRootEntry && !m_pRootEntry->GetEntries()->empty(); | |||
842 | } | |||
843 | ||||
844 | bool ContextMenuSaveInData::Apply() | |||
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 | ||||
874 | void ContextMenuSaveInData::Reset() | |||
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")do { css::uno::Any tools_warn_exception( DbgGetCaughtException () ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "cui.customize")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break ; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "Exception caught while resetting context menus" << " " << exceptionToString(tools_warn_exception )) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ( "cui.customize"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "885" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "Exception caught while resetting context menus" << " " << exceptionToString(tools_warn_exception )), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "Exception caught while resetting context menus" << " " << exceptionToString(tools_warn_exception); ::sal:: detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize") , ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "885" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "Exception caught while resetting context menus" << " " << exceptionToString(tools_warn_exception)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize" ), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "885" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "Exception caught while resetting context menus" << " " << exceptionToString(tools_warn_exception )), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "Exception caught while resetting context menus" << " " << exceptionToString(tools_warn_exception); ::sal:: detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize") , ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "885" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); } while (false); | |||
886 | } | |||
887 | } | |||
888 | PersistChanges( GetConfigManager() ); | |||
889 | m_pRootEntry.reset(); | |||
890 | } | |||
891 | ||||
892 | void ContextMenuSaveInData::ResetContextMenu( const SvxConfigEntry* pEntry ) | |||
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")do { css::uno::Any tools_warn_exception( DbgGetCaughtException () ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "cui.customize")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break ; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "Exception caught while resetting context menu" << " " << exceptionToString(tools_warn_exception )) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ( "cui.customize"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "900" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "Exception caught while resetting context menu" << " " << exceptionToString(tools_warn_exception )), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "Exception caught while resetting context menu" << " " << exceptionToString(tools_warn_exception); ::sal:: detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize") , ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "900" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "Exception caught while resetting context menu" << " " << exceptionToString(tools_warn_exception)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize" ), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "900" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "Exception caught while resetting context menu" << " " << exceptionToString(tools_warn_exception )), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "Exception caught while resetting context menu" << " " << exceptionToString(tools_warn_exception); ::sal:: detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize") , ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "900" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); } while (false); | |||
901 | } | |||
902 | PersistChanges( GetConfigManager() ); | |||
903 | m_pRootEntry.reset(); | |||
904 | } | |||
905 | ||||
906 | void SvxMenuEntriesListBox::CreateDropDown() | |||
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)::tools::detail::makeLink( ::tools::detail::castTo<SvxMenuEntriesListBox *>(this), &SvxMenuEntriesListBox::LinkStubKeyInputHdl )); | |||
932 | } | |||
933 | ||||
934 | SvxMenuEntriesListBox::~SvxMenuEntriesListBox() | |||
935 | { | |||
936 | } | |||
937 | ||||
938 | IMPL_LINK(SvxMenuEntriesListBox, KeyInputHdl, const KeyEvent&, rKeyEvent, bool)bool SvxMenuEntriesListBox::LinkStubKeyInputHdl(void * instance , const KeyEvent& data) { return static_cast<SvxMenuEntriesListBox *>(instance)->KeyInputHdl(data); } bool SvxMenuEntriesListBox ::KeyInputHdl(const KeyEvent& rKeyEvent) | |||
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 | *****************************************************************************/ | |||
970 | SvxConfigPage::SvxConfigPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet) | |||
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 | { | |||
994 | CustomNotebookbarGenerator::getFileNameAndAppName(m_sAppName, m_sFileName); | |||
995 | ||||
996 | m_xTopLevelListBox->connect_changed(LINK(this, SvxConfigPage, SelectElementHdl)::tools::detail::makeLink( ::tools::detail::castTo<SvxConfigPage *>(this), &SvxConfigPage::LinkStubSelectElementHdl)); | |||
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)::tools::detail::makeLink( ::tools::detail::castTo<SvxConfigPage *>(this), &SvxConfigPage::LinkStubImplUpdateDataHdl)); | |||
1004 | m_aUpdateDataTimer.SetDebugName( "SvxConfigPage UpdateDataTimer" ); | |||
1005 | m_aUpdateDataTimer.SetTimeout(EDIT_UPDATEDATA_TIMEOUT350); | |||
1006 | ||||
1007 | m_xSearchEdit->connect_changed(LINK(this, SvxConfigPage, SearchUpdateHdl)::tools::detail::makeLink( ::tools::detail::castTo<SvxConfigPage *>(this), &SvxConfigPage::LinkStubSearchUpdateHdl)); | |||
1008 | m_xSearchEdit->connect_focus_out(LINK(this, SvxConfigPage, FocusOut_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxConfigPage *>(this), &SvxConfigPage::LinkStubFocusOut_Impl)); | |||
1009 | ||||
1010 | rTreeView.connect_row_activated(LINK(this, SvxConfigPage, FunctionDoubleClickHdl)::tools::detail::makeLink( ::tools::detail::castTo<SvxConfigPage *>(this), &SvxConfigPage::LinkStubFunctionDoubleClickHdl )); | |||
1011 | rTreeView.connect_changed(LINK(this, SvxConfigPage, SelectFunctionHdl)::tools::detail::makeLink( ::tools::detail::castTo<SvxConfigPage *>(this), &SvxConfigPage::LinkStubSelectFunctionHdl)); | |||
1012 | } | |||
1013 | ||||
1014 | IMPL_LINK_NOARG(SvxConfigPage, SelectElementHdl, weld::ComboBox&, void)void SvxConfigPage::LinkStubSelectElementHdl(void * instance, weld::ComboBox& data) { return static_cast<SvxConfigPage *>(instance)->SelectElementHdl(data); } void SvxConfigPage ::SelectElementHdl(__attribute__ ((unused)) weld::ComboBox& ) | |||
1015 | { | |||
1016 | SelectElement(); | |||
1017 | } | |||
1018 | ||||
1019 | SvxConfigPage::~SvxConfigPage() | |||
1020 | { | |||
1021 | } | |||
1022 | ||||
1023 | void SvxConfigPage::Reset( const SfxItemSet* ) | |||
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(); | |||
1041 | m_aModuleId = GetFrameWithDefaultAndIdentify( m_xFrame ); | |||
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" )do { if (true && (!(pCurrentSaveInData))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "1142" ": "), "%s", "SvxConfigPage::Reset(): no SaveInData" ); } } while (false); | |||
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")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "1164" ": ", "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 )::tools::detail::makeLink( ::tools::detail::castTo<SvxConfigPage *>(this), &SvxConfigPage::LinkStubSelectSaveInLocation ) ); | |||
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( | |||
1244 | ::comphelper::getProcessComponentContext() ); | |||
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!" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "cui.customize")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break ; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "SvxConfigPage::GetFrameWithDefaultAndIdentify(): no frame found!" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize" ), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "1262" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "SvxConfigPage::GetFrameWithDefaultAndIdentify(): no frame found!" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "SvxConfigPage::GetFrameWithDefaultAndIdentify(): no frame found!" ; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize" ), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "1262" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "SvxConfigPage::GetFrameWithDefaultAndIdentify(): no frame found!" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize" ), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "1262" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "SvxConfigPage::GetFrameWithDefaultAndIdentify(): no frame found!" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "SvxConfigPage::GetFrameWithDefaultAndIdentify(): no frame found!" ; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize" ), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "1262" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
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")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "1270" ": ", "cui.customize" );; | |||
1271 | } | |||
1272 | ||||
1273 | return sModuleID; | |||
1274 | } | |||
1275 | ||||
1276 | OUString SvxConfigPage::GetScriptURL() const | |||
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 | ||||
1294 | OUString SvxConfigPage::GetSelectedDisplayName() const | |||
1295 | { | |||
1296 | return m_xFunctions->get_selected_text(); | |||
1297 | } | |||
1298 | ||||
1299 | bool SvxConfigPage::FillItemSet( SfxItemSet* ) | |||
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"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)void SvxConfigPage::LinkStubSelectSaveInLocation(void * instance , weld::ComboBox& data) { return static_cast<SvxConfigPage *>(instance)->SelectSaveInLocation(data); } void SvxConfigPage ::SelectSaveInLocation(__attribute__ ((unused)) weld::ComboBox &) | |||
1316 | { | |||
1317 | OUString sId = m_xSaveInListBox->get_active_id(); | |||
1318 | if (sId != notebookbarTabScope"notebookbarTabScope") | |||
1319 | pCurrentSaveInData = reinterpret_cast<SaveInData*>(sId.toInt64()); | |||
1320 | Init(); | |||
1321 | } | |||
1322 | ||||
1323 | void SvxConfigPage::ReloadTopLevelListBox( SvxConfigEntry const * pToSelect ) | |||
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" )do { if (true && (!(GetSaveInData()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "1344" ": "), "%s", "SvxConfigPage::ReloadTopLevelListBox(): no SaveInData" ); } } while (false); | |||
1345 | DBG_ASSERT( GetSaveInData()->GetEntries() ,do { if (true && (!(GetSaveInData()->GetEntries()) )) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools" ), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "1346" ": "), "%s", "SvxConfigPage::ReloadTopLevelListBox(): no SaveInData entries" ); } } while (false) | |||
1346 | "SvxConfigPage::ReloadTopLevelListBox(): no SaveInData entries" )do { if (true && (!(GetSaveInData()->GetEntries()) )) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools" ), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "1346" ": "), "%s", "SvxConfigPage::ReloadTopLevelListBox(): no SaveInData entries" ); } } while (false); | |||
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 | ||||
1357 | void SvxConfigPage::AddSubMenusToUI( | |||
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 | ||||
1374 | SvxEntries* SvxConfigPage::FindParentForChild( | |||
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 | ||||
1410 | auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(aURL, m_aModuleId); | |||
1411 | ||||
1412 | if ( typeid(*pCurrentSaveInData) == typeid(ContextMenuSaveInData) ) | |||
1413 | aDisplayName = vcl::CommandInfoProvider::GetPopupLabelForCommand(aProperties); | |||
1414 | else if ( typeid(*pCurrentSaveInData) == typeid(MenuSaveInData) ) | |||
1415 | aDisplayName = vcl::CommandInfoProvider::GetMenuLabelForCommand(aProperties); | |||
1416 | else | |||
1417 | aDisplayName = vcl::CommandInfoProvider::GetLabelForCommand(aProperties); | |||
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_INCLUDEDreinterpret_cast<char const *>("RID_SVXSTR_MNUCFG_ALREADY_INCLUDED" "\004" u8"Function is already included in this popup.")))); | |||
1435 | xBox->run(); | |||
1436 | delete pNewEntryData; | |||
1437 | return -1; | |||
1438 | } | |||
1439 | } | |||
1440 | } | |||
1441 | ||||
1442 | return AppendEntry(pNewEntryData, nTarget); | |||
1443 | } | |||
1444 | ||||
1445 | int SvxConfigPage::AppendEntry( | |||
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 | ||||
1502 | GetSaveInData()->SetModified(); | |||
1503 | GetTopLevelSelection()->SetModified(); | |||
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)void SvxConfigPage::LinkStubMoveHdl(void * instance, weld::Button & data) { return static_cast<SvxConfigPage *>(instance )->MoveHdl(data); } void SvxConfigPage::MoveHdl(weld::Button & rButton) | |||
1554 | { | |||
1555 | MoveEntry(&rButton == m_xMoveUpButton.get()); | |||
1556 | } | |||
1557 | ||||
1558 | IMPL_LINK_NOARG(SvxConfigPage, FunctionDoubleClickHdl, weld::TreeView&, bool)bool SvxConfigPage::LinkStubFunctionDoubleClickHdl(void * instance , weld::TreeView& data) { return static_cast<SvxConfigPage *>(instance)->FunctionDoubleClickHdl(data); } bool SvxConfigPage ::FunctionDoubleClickHdl(__attribute__ ((unused)) weld::TreeView &) | |||
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)void SvxConfigPage::LinkStubSelectFunctionHdl(void * instance , weld::TreeView& data) { return static_cast<SvxConfigPage *>(instance)->SelectFunctionHdl(data); } void SvxConfigPage ::SelectFunctionHdl(__attribute__ ((unused)) weld::TreeView& ) | |||
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 | ||||
1578 | if (SfxHelp::IsHelpInstalled()) | |||
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_COMMANDLABELreinterpret_cast<char const *>("RID_SVXSTR_COMMANDLABEL" "\004" u8"Label")) + ": " + pData->sLabel + "\n"; | |||
1588 | OUString aName = CuiResId(RID_SVXSTR_COMMANDNAMEreinterpret_cast<char const *>("RID_SVXSTR_COMMANDLABEL" "\004" u8"Command")) + ": " + pData->sCommand + "\n"; | |||
1589 | OUString aTip = CuiResId(RID_SVXSTR_COMMANDTIPreinterpret_cast<char const *>("RID_SVXSTR_COMMANDLABEL" "\004" u8"Tooltip")) + ": " + 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)void SvxConfigPage::LinkStubImplUpdateDataHdl(void * instance , Timer* data) { return static_cast<SvxConfigPage *>(instance )->ImplUpdateDataHdl(data); } void SvxConfigPage::ImplUpdateDataHdl (__attribute__ ((unused)) Timer*) | |||
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)void SvxConfigPage::LinkStubSearchUpdateHdl(void * instance, weld ::Entry& data) { return static_cast<SvxConfigPage *> (instance)->SearchUpdateHdl(data); } void SvxConfigPage::SearchUpdateHdl (__attribute__ ((unused)) weld::Entry&) | |||
1612 | { | |||
1613 | m_aUpdateDataTimer.Start(); | |||
1614 | } | |||
1615 | ||||
1616 | IMPL_LINK_NOARG(SvxConfigPage, FocusOut_Impl, weld::Widget&, void)void SvxConfigPage::LinkStubFocusOut_Impl(void * instance, weld ::Widget& data) { return static_cast<SvxConfigPage *> (instance)->FocusOut_Impl(data); } void SvxConfigPage::FocusOut_Impl (__attribute__ ((unused)) weld::Widget&) | |||
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 | ||||
1657 | UpdateButtonStates(); | |||
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 | ||||
1692 | GetSaveInData()->SetModified(); | |||
1693 | GetTopLevelSelection()->SetModified(); | |||
1694 | ||||
1695 | return true; | |||
1696 | } | |||
1697 | ||||
1698 | return false; | |||
1699 | } | |||
1700 | ||||
1701 | SvxMainMenuOrganizerDialog::SvxMainMenuOrganizerDialog( | |||
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_MENUreinterpret_cast<char const *>("RID_SVXSTR_NEW_MENU" "\004" u8"New Menu %n") ); | |||
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)); | |||
1744 | m_xMenuListBox->append(m_sNewMenuEntryId, | |||
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)::tools::detail::makeLink( ::tools::detail::castTo<SvxMainMenuOrganizerDialog *>(this), &SvxMainMenuOrganizerDialog::LinkStubModifyHdl )); | |||
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_MENUreinterpret_cast<char const *>("RID_SVXSTR_MOVE_MENU" "\004" u8"Move Menu"))); | |||
1760 | } | |||
1761 | ||||
1762 | m_xMenuListBox->connect_changed(LINK(this, SvxMainMenuOrganizerDialog, SelectHdl)::tools::detail::makeLink( ::tools::detail::castTo<SvxMainMenuOrganizerDialog *>(this), &SvxMainMenuOrganizerDialog::LinkStubSelectHdl )); | |||
1763 | ||||
1764 | m_xMoveUpButton->connect_clicked(LINK( this, SvxMainMenuOrganizerDialog, MoveHdl)::tools::detail::makeLink( ::tools::detail::castTo<SvxMainMenuOrganizerDialog *>(this), &SvxMainMenuOrganizerDialog::LinkStubMoveHdl )); | |||
1765 | m_xMoveDownButton->connect_clicked(LINK( this, SvxMainMenuOrganizerDialog, MoveHdl)::tools::detail::makeLink( ::tools::detail::castTo<SvxMainMenuOrganizerDialog *>(this), &SvxMainMenuOrganizerDialog::LinkStubMoveHdl )); | |||
1766 | ||||
1767 | UpdateButtonStates(); | |||
1768 | } | |||
1769 | ||||
1770 | SvxMainMenuOrganizerDialog::~SvxMainMenuOrganizerDialog() | |||
1771 | { | |||
1772 | } | |||
1773 | ||||
1774 | IMPL_LINK_NOARG(SvxMainMenuOrganizerDialog, ModifyHdl, weld::Entry&, void)void SvxMainMenuOrganizerDialog::LinkStubModifyHdl(void * instance , weld::Entry& data) { return static_cast<SvxMainMenuOrganizerDialog *>(instance)->ModifyHdl(data); } void SvxMainMenuOrganizerDialog ::ModifyHdl(__attribute__ ((unused)) weld::Entry&) | |||
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 | ||||
1792 | IMPL_LINK_NOARG(SvxMainMenuOrganizerDialog, SelectHdl, weld::TreeView&, void)void SvxMainMenuOrganizerDialog::LinkStubSelectHdl(void * instance , weld::TreeView& data) { return static_cast<SvxMainMenuOrganizerDialog *>(instance)->SelectHdl(data); } void SvxMainMenuOrganizerDialog ::SelectHdl(__attribute__ ((unused)) weld::TreeView&) | |||
1793 | { | |||
1794 | UpdateButtonStates(); | |||
1795 | } | |||
1796 | ||||
1797 | void SvxMainMenuOrganizerDialog::UpdateButtonStates() | |||
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 | ||||
1805 | IMPL_LINK( SvxMainMenuOrganizerDialog, MoveHdl, weld::Button&, rButton, void )void SvxMainMenuOrganizerDialog::LinkStubMoveHdl(void * instance , weld::Button& data) { return static_cast<SvxMainMenuOrganizerDialog *>(instance)->MoveHdl(data); } void SvxMainMenuOrganizerDialog ::MoveHdl(weld::Button& rButton) | |||
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 | ||||
1834 | SvxConfigEntry* SvxMainMenuOrganizerDialog::GetSelectedEntry() | |||
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 | ||||
1862 | SvxConfigEntry::~SvxConfigEntry() | |||
1863 | { | |||
1864 | if (mpEntries) | |||
1865 | { | |||
1866 | for (auto const& entry : *mpEntries) | |||
1867 | { | |||
1868 | delete entry; | |||
1869 | } | |||
1870 | } | |||
1871 | } | |||
1872 | ||||
1873 | bool SvxConfigEntry::IsMovable() const | |||
1874 | { | |||
1875 | return !IsPopup() || IsMain(); | |||
1876 | } | |||
1877 | ||||
1878 | bool SvxConfigEntry::IsDeletable() const | |||
1879 | { | |||
1880 | return !IsMain() || IsUserDefined(); | |||
1881 | } | |||
1882 | ||||
1883 | bool SvxConfigEntry::IsRenamable() const | |||
1884 | { | |||
1885 | return !IsMain() || IsUserDefined(); | |||
1886 | } | |||
1887 | ||||
1888 | ToolbarSaveInData::ToolbarSaveInData( | |||
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 | ||||
1906 | ToolbarSaveInData::~ToolbarSaveInData() | |||
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 | ||||
1944 | void ToolbarSaveInData::SetSystemStyle( | |||
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 | ||||
1998 | void ToolbarSaveInData::SetSystemStyle( | |||
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")do { css::uno::Any tools_warn_exception( DbgGetCaughtException () ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "cui.customize")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break ; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "Exception setting toolbar style" << " " << exceptionToString(tools_warn_exception )) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ( "cui.customize"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "2033" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "Exception setting toolbar style" << " " << exceptionToString(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "Exception setting toolbar style" << " " << exceptionToString(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "2033" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "Exception setting toolbar style" << " " << exceptionToString(tools_warn_exception)) == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "2033" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "Exception setting toolbar style" << " " << exceptionToString(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "Exception setting toolbar style" << " " << exceptionToString(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "2033" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); } while (false); | |||
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 | ||||
2097 | SvxEntries* ToolbarSaveInData::GetEntries() | |||
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 | ||||
2259 | std::sort( GetEntries()->begin(), GetEntries()->end(), SvxConfigPageHelper::EntrySort ); | |||
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 | ||||
2284 | bool ToolbarSaveInData::HasSettings() | |||
2285 | { | |||
2286 | // return true if there is at least one toolbar entry | |||
2287 | return !GetEntries()->empty(); | |||
2288 | } | |||
2289 | ||||
2290 | void ToolbarSaveInData::Reset() | |||
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 | |||
2308 | PersistChanges( GetConfigManager() ); | |||
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(); | |||
2318 | PersistChanges( GetImageManager() ); | |||
2319 | } | |||
2320 | catch ( uno::Exception& ) | |||
2321 | { | |||
2322 | SAL_WARN("cui.customize", "Error resetting all icons when resetting toolbars")do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "cui.customize")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break ; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "Error resetting all icons when resetting toolbars" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize" ), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "2322" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "Error resetting all icons when resetting toolbars" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "Error resetting all icons when resetting toolbars" ; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize" ), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "2322" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "Error resetting all icons when resetting toolbars" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize" ), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "2322" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "Error resetting all icons when resetting toolbars" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "Error resetting all icons when resetting toolbars" ; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize" ), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "2322" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
2323 | } | |||
2324 | } | |||
2325 | ||||
2326 | bool ToolbarSaveInData::Apply() | |||
2327 | { | |||
2328 | // toolbar changes are instantly applied | |||
2329 | return false; | |||
2330 | } | |||
2331 | ||||
2332 | void ToolbarSaveInData::ApplyToolbar( | |||
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 = | |||
2344 | SvxConfigPageHelper::ConvertToolbarEntry(entry); | |||
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 = | |||
2367 | SvxConfigPageHelper::ConvertToolbarEntry(entry); | |||
2368 | ||||
2369 | rToolbarBar->insertByIndex( | |||
2370 | rToolbarBar->getCount(), uno::Any( aPropValueSeq )); | |||
2371 | } | |||
2372 | } | |||
2373 | } | |||
2374 | ||||
2375 | void ToolbarSaveInData::ApplyToolbar( SvxConfigEntry* pToolbar ) | |||
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( | |||
2395 | ITEM_DESCRIPTOR_UINAME, | |||
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")do { css::uno::Any tools_warn_exception( DbgGetCaughtException () ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "cui.customize")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break ; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "caught exception saving settings" << " " << exceptionToString(tools_warn_exception )) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ( "cui.customize"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "2416" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "caught exception saving settings" << " " << exceptionToString(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "caught exception saving settings" << " " << exceptionToString(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "2416" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "caught exception saving settings" << " " << exceptionToString(tools_warn_exception)) == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "2416" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "caught exception saving settings" << " " << exceptionToString(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "caught exception saving settings" << " " << exceptionToString(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "2416" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); } while (false); | |||
2417 | } | |||
2418 | ||||
2419 | PersistChanges( GetConfigManager() ); | |||
2420 | } | |||
2421 | ||||
2422 | void ToolbarSaveInData::CreateToolbar( SvxConfigEntry* pToolbar ) | |||
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( | |||
2432 | ITEM_DESCRIPTOR_UINAME, | |||
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")do { css::uno::Any tools_warn_exception( DbgGetCaughtException () ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "cui.customize")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break ; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "caught exception saving settings" << " " << exceptionToString(tools_warn_exception )) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ( "cui.customize"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "2441" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "caught exception saving settings" << " " << exceptionToString(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "caught exception saving settings" << " " << exceptionToString(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "2441" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "caught exception saving settings" << " " << exceptionToString(tools_warn_exception)) == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "2441" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "caught exception saving settings" << " " << exceptionToString(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "caught exception saving settings" << " " << exceptionToString(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "2441" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); } while (false); | |||
2442 | } | |||
2443 | ||||
2444 | GetEntries()->push_back( pToolbar ); | |||
2445 | ||||
2446 | PersistChanges( GetConfigManager() ); | |||
2447 | } | |||
2448 | ||||
2449 | void ToolbarSaveInData::RemoveToolbar( SvxConfigEntry* pToolbar ) | |||
2450 | { | |||
2451 | try | |||
2452 | { | |||
2453 | OUString url = pToolbar->GetCommand(); | |||
2454 | GetConfigManager()->removeSettings( url ); | |||
2455 | SvxConfigPageHelper::RemoveEntry( GetEntries(), pToolbar ); | |||
2456 | delete pToolbar; | |||
2457 | ||||
2458 | PersistChanges( GetConfigManager() ); | |||
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 | ||||
2472 | void ToolbarSaveInData::RestoreToolbar( SvxConfigEntry* pToolbar ) | |||
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(); | |||
2488 | PersistChanges( GetConfigManager() ); | |||
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")do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "cui.customize")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break ; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "Error restoring icon when resetting toolbar" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize" ), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "2523" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "Error restoring icon when resetting toolbar" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "Error restoring icon when resetting toolbar"; ::sal ::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize" ), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "2523" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "Error restoring icon when resetting toolbar") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize" ), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "2523" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "Error restoring icon when resetting toolbar" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "Error restoring icon when resetting toolbar"; ::sal ::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize" ), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "2523" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
2524 | } | |||
2525 | } | |||
2526 | PersistChanges( GetImageManager() ); | |||
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 | ||||
2535 | void ToolbarSaveInData::LoadToolbar( | |||
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 | ||||
2612 | SvxNewToolbarDialog::SvxNewToolbarDialog(weld::Window* pWindow, const OUString& rName) | |||
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 | ||||
2622 | SvxNewToolbarDialog::~SvxNewToolbarDialog() | |||
2623 | { | |||
2624 | } | |||
2625 | ||||
2626 | /******************************************************************************* | |||
2627 | * | |||
2628 | * The SvxIconSelectorDialog class | |||
2629 | * | |||
2630 | *******************************************************************************/ | |||
2631 | SvxIconSelectorDialog::SvxIconSelectorDialog(weld::Window *pWindow, | |||
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 | { | |||
2653 | m_xFtNote->set_label(SvxConfigPageHelper::replaceSixteen(m_xFtNote->get_label(), m_nExpectedSize)); | |||
2654 | } | |||
2655 | ||||
2656 | m_xTbSymbol->SetStyle(m_xTbSymbol->GetStyle() | WB_ITEMBORDER(WinBits(0x00010000)) | 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)::tools::detail::makeLink( ::tools::detail::castTo<SvxIconSelectorDialog *>(this), &SvxIconSelectorDialog::LinkStubSelectHdl) ); | |||
2783 | m_xBtnImport->connect_clicked( LINK(this, SvxIconSelectorDialog, ImportHdl)::tools::detail::makeLink( ::tools::detail::castTo<SvxIconSelectorDialog *>(this), &SvxIconSelectorDialog::LinkStubImportHdl) ); | |||
2784 | m_xBtnDelete->connect_clicked( LINK(this, SvxIconSelectorDialog, DeleteHdl)::tools::detail::makeLink( ::tools::detail::castTo<SvxIconSelectorDialog *>(this), &SvxIconSelectorDialog::LinkStubDeleteHdl) ); | |||
2785 | } | |||
2786 | ||||
2787 | SvxIconSelectorDialog::~SvxIconSelectorDialog() | |||
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 | ||||
2805 | IMPL_LINK_NOARG(SvxIconSelectorDialog, SelectHdl, ValueSet*, void)void SvxIconSelectorDialog::LinkStubSelectHdl(void * instance , ValueSet* data) { return static_cast<SvxIconSelectorDialog *>(instance)->SelectHdl(data); } void SvxIconSelectorDialog ::SelectHdl(__attribute__ ((unused)) ValueSet*) | |||
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 | ||||
2826 | IMPL_LINK_NOARG(SvxIconSelectorDialog, ImportHdl, weld::Button&, void)void SvxIconSelectorDialog::LinkStubImportHdl(void * instance , weld::Button& data) { return static_cast<SvxIconSelectorDialog *>(instance)->ImportHdl(data); } void SvxIconSelectorDialog ::ImportHdl(__attribute__ ((unused)) weld::Button&) | |||
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_NONEErrCode(0) == aImportDialog.Execute() ) | |||
2846 | { | |||
2847 | uno::Sequence< OUString > paths = aImportDialog.GetMPath(); | |||
2848 | ImportGraphics ( paths ); | |||
2849 | } | |||
2850 | } | |||
2851 | ||||
2852 | IMPL_LINK_NOARG(SvxIconSelectorDialog, DeleteHdl, weld::Button&, void)void SvxIconSelectorDialog::LinkStubDeleteHdl(void * instance , weld::Button& data) { return static_cast<SvxIconSelectorDialog *>(instance)->DeleteHdl(data); } void SvxIconSelectorDialog ::DeleteHdl(__attribute__ ((unused)) weld::Button&) | |||
2853 | { | |||
2854 | OUString message = CuiResId( RID_SVXSTR_DELETE_ICON_CONFIRMreinterpret_cast<char const *>("RID_SVXSTR_DELETE_ICON_CONFIRM" "\004" u8"Are you sure to delete the image?") ); | |||
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 | ||||
2874 | bool SvxIconSelectorDialog::ReplaceGraphicItem( | |||
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))(static_cast <bool> (nPos == m_xTbSymbol->GetItemPos (nId)) ? void (0) : __assert_fail ("nPos == m_xTbSymbol->GetItemPos(nId)" , "/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" , 2917, __extension__ __PRETTY_FUNCTION__)); | |||
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_WARNINGreinterpret_cast<char const *>("RID_SVXSTR_REPLACE_ICON_WARNING" "\004" u8"The icon %ICONNAME is already contained in the image list.\nWould you like to replace the existing icon?" ) ); | |||
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_CONFIRMreinterpret_cast<char const *>("RID_SVXSTR_REPLACE_ICON_CONFIRM" "\004" u8"Confirm Icon Replacement"))); | |||
2975 | m_xQueryBox->add_button(GetStandardText(StandardButtonType::Yes), 2); | |||
2976 | if (bYestoAll) | |||
2977 | m_xQueryBox->add_button(CuiResId(RID_SVXSTR_YESTOALLreinterpret_cast<char const *>("RID_SVXSTR_YESTOALL" "\004" u8"Yes to All")), 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 | ||||
2986 | void SvxIconSelectorDialog::ImportGraphics( | |||
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 = rPaths[0].copy(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")do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "cui.customize")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break ; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "could not create Image from XGraphic" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize" ), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "3137" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "could not create Image from XGraphic" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "could not create Image from XGraphic"; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "3137" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "could not create Image from XGraphic") == 1) { :: sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize" ), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "3137" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "could not create Image from XGraphic" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "could not create Image from XGraphic"; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "3137" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
3138 | } | |||
3139 | } | |||
3140 | else | |||
3141 | { | |||
3142 | SAL_WARN("cui.customize", "could not get query XGraphic")do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "cui.customize")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break ; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "could not get query XGraphic" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize" ), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "3142" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "could not get query XGraphic"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "could not get query XGraphic"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "3142" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "could not get query XGraphic") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "3142" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "could not get query XGraphic"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "could not get query XGraphic"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "3142" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
3143 | } | |||
3144 | } | |||
3145 | catch( uno::Exception const & ) | |||
3146 | { | |||
3147 | TOOLS_WARN_EXCEPTION("cui.customize", "Caught exception importing XGraphic")do { css::uno::Any tools_warn_exception( DbgGetCaughtException () ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "cui.customize")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break ; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "Caught exception importing XGraphic" << " " << exceptionToString(tools_warn_exception )) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ( "cui.customize"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "3147" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "Caught exception importing XGraphic" << " " << exceptionToString(tools_warn_exception )), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "Caught exception importing XGraphic" << " " << exceptionToString(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "3147" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "Caught exception importing XGraphic" << " " << exceptionToString(tools_warn_exception)) == 1) { :: sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize" ), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "3147" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "Caught exception importing XGraphic" << " " << exceptionToString(tools_warn_exception )), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "Caught exception importing XGraphic" << " " << exceptionToString(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.customize"), ("/home/maarten/src/libreoffice/core/cui/source/customize/cfg.cxx" ":" "3147" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); } while (false); | |||
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 | ||||
3166 | SvxConfigPageFunctionDropTarget::SvxConfigPageFunctionDropTarget(SvxConfigPage&rPage, weld::TreeView& rTreeView) | |||
3167 | : DropTargetHelper(rTreeView.get_drop_target()) | |||
3168 | , m_rPage(rPage) | |||
3169 | , m_rTreeView(rTreeView) | |||
3170 | { | |||
3171 | } | |||
3172 | ||||
3173 | sal_Int8 SvxConfigPageFunctionDropTarget::AcceptDrop(const AcceptDropEvent& rEvt) | |||
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_MOVEcss::datatransfer::dnd::DNDConstants::ACTION_MOVE; | |||
3178 | } | |||
3179 | ||||
3180 | sal_Int8 SvxConfigPageFunctionDropTarget::ExecuteDrop( const ExecuteDropEvent& rEvt ) | |||
3181 | { | |||
3182 | weld::TreeView* pSource = m_rTreeView.get_drag_source(); | |||
3183 | // only dragging within the same widget allowed | |||
3184 | if (!pSource || pSource != &m_rTreeView) | |||
3185 | return DND_ACTION_NONEcss::datatransfer::dnd::DNDConstants::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_NONEcss::datatransfer::dnd::DNDConstants::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)) | |||
3194 | nTargetPos = m_rTreeView.get_iter_index_in_parent(*xTarget); | |||
3195 | m_rTreeView.move_subtree(*xSource, nullptr, nTargetPos); | |||
3196 | ||||
3197 | m_rPage.ListModified(); | |||
3198 | ||||
3199 | return DND_ACTION_NONEcss::datatransfer::dnd::DNDConstants::ACTION_NONE; | |||
3200 | } | |||
3201 | ||||
3202 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_RTL_REF_HXX |
21 | #define INCLUDED_RTL_REF_HXX |
22 | |
23 | #include "sal/config.h" |
24 | |
25 | #include <cassert> |
26 | #include <cstddef> |
27 | #include <functional> |
28 | #ifdef LIBO_INTERNAL_ONLY1 |
29 | #include <type_traits> |
30 | #endif |
31 | |
32 | #include "sal/types.h" |
33 | |
34 | namespace rtl |
35 | { |
36 | |
37 | /** Template reference class for reference type. |
38 | */ |
39 | template <class reference_type> |
40 | class Reference |
41 | { |
42 | /** The <b>reference_type</b> body pointer. |
43 | */ |
44 | reference_type * m_pBody; |
45 | |
46 | |
47 | public: |
48 | /** Constructor... |
49 | */ |
50 | Reference() |
51 | : m_pBody (NULL__null) |
52 | {} |
53 | |
54 | |
55 | /** Constructor... |
56 | */ |
57 | Reference (reference_type * pBody, __sal_NoAcquire) |
58 | : m_pBody (pBody) |
59 | { |
60 | } |
61 | |
62 | /** Constructor... |
63 | */ |
64 | Reference (reference_type * pBody) |
65 | : m_pBody (pBody) |
66 | { |
67 | if (m_pBody) |
68 | m_pBody->acquire(); |
69 | } |
70 | |
71 | /** Copy constructor... |
72 | */ |
73 | Reference (const Reference<reference_type> & handle) |
74 | : m_pBody (handle.m_pBody) |
75 | { |
76 | if (m_pBody) |
77 | m_pBody->acquire(); |
78 | } |
79 | |
80 | #ifdef LIBO_INTERNAL_ONLY1 |
81 | /** Move constructor... |
82 | */ |
83 | Reference (Reference<reference_type> && handle) noexcept |
84 | : m_pBody (handle.m_pBody) |
85 | { |
86 | handle.m_pBody = nullptr; |
87 | } |
88 | #endif |
89 | |
90 | #if defined LIBO_INTERNAL_ONLY1 |
91 | /** Up-casting conversion constructor: Copies interface reference. |
92 | |
93 | Does not work for up-casts to ambiguous bases. |
94 | |
95 | @param rRef another reference |
96 | */ |
97 | template< class derived_type > |
98 | inline Reference( |
99 | const Reference< derived_type > & rRef, |
100 | std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 ) |
101 | : m_pBody (rRef.get()) |
102 | { |
103 | if (m_pBody) |
104 | m_pBody->acquire(); |
105 | } |
106 | #endif |
107 | |
108 | /** Destructor... |
109 | */ |
110 | ~Reference() COVERITY_NOEXCEPT_FALSE |
111 | { |
112 | if (m_pBody) |
113 | m_pBody->release(); |
114 | } |
115 | |
116 | /** Set... |
117 | Similar to assignment. |
118 | */ |
119 | Reference<reference_type> & |
120 | SAL_CALL set (reference_type * pBody) |
121 | { |
122 | if (pBody) |
123 | pBody->acquire(); |
124 | reference_type * const pOld = m_pBody; |
125 | m_pBody = pBody; |
126 | if (pOld) |
127 | pOld->release(); |
128 | return *this; |
129 | } |
130 | |
131 | /** Assignment. |
132 | Unbinds this instance from its body (if bound) and |
133 | bind it to the body represented by the handle. |
134 | */ |
135 | Reference<reference_type> & |
136 | SAL_CALL operator= (const Reference<reference_type> & handle) |
137 | { |
138 | return set( handle.m_pBody ); |
139 | } |
140 | |
141 | #ifdef LIBO_INTERNAL_ONLY1 |
142 | /** Assignment. |
143 | * Unbinds this instance from its body (if bound), |
144 | * bind it to the body represented by the handle, and |
145 | * set the body represented by the handle to nullptr. |
146 | */ |
147 | Reference<reference_type> & |
148 | operator= (Reference<reference_type> && handle) |
149 | { |
150 | // self-movement guts ourself |
151 | if (m_pBody) |
152 | m_pBody->release(); |
153 | m_pBody = handle.m_pBody; |
154 | handle.m_pBody = nullptr; |
155 | return *this; |
156 | } |
157 | #endif |
158 | |
159 | /** Assignment... |
160 | */ |
161 | Reference<reference_type> & |
162 | SAL_CALL operator= (reference_type * pBody) |
163 | { |
164 | return set( pBody ); |
165 | } |
166 | |
167 | /** Unbind the body from this handle. |
168 | Note that for a handle representing a large body, |
169 | "handle.clear().set(new body());" _might_ |
170 | perform a little bit better than "handle.set(new body());", |
171 | since in the second case two large objects exist in memory |
172 | (the old body and the new body). |
173 | */ |
174 | Reference<reference_type> & SAL_CALL clear() |
175 | { |
176 | if (m_pBody) |
177 | { |
178 | reference_type * const pOld = m_pBody; |
179 | m_pBody = NULL__null; |
180 | pOld->release(); |
181 | } |
182 | return *this; |
183 | } |
184 | |
185 | |
186 | /** Get the body. Can be used instead of operator->(). |
187 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() |
188 | are the same. |
189 | */ |
190 | reference_type * SAL_CALL get() const |
191 | { |
192 | return m_pBody; |
193 | } |
194 | |
195 | |
196 | /** Probably most common used: handle->someBodyOp(). |
197 | */ |
198 | reference_type * SAL_CALL operator->() const |
199 | { |
200 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 200, __extension__ __PRETTY_FUNCTION__)); |
201 | return m_pBody; |
202 | } |
203 | |
204 | |
205 | /** Allows (*handle).someBodyOp(). |
206 | */ |
207 | reference_type & SAL_CALL operator*() const |
208 | { |
209 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 209, __extension__ __PRETTY_FUNCTION__)); |
210 | return *m_pBody; |
211 | } |
212 | |
213 | |
214 | /** Returns True if the handle does point to a valid body. |
215 | */ |
216 | bool SAL_CALL is() const |
217 | { |
218 | return (m_pBody != NULL__null); |
219 | } |
220 | |
221 | #if defined LIBO_INTERNAL_ONLY1 |
222 | /** Returns True if the handle does point to a valid body. |
223 | */ |
224 | explicit operator bool() const |
225 | { |
226 | return is(); |
227 | } |
228 | #endif |
229 | |
230 | /** Returns True if this points to pBody. |
231 | */ |
232 | bool SAL_CALL operator== (const reference_type * pBody) const |
233 | { |
234 | return (m_pBody == pBody); |
235 | } |
236 | |
237 | |
238 | /** Returns True if handle points to the same body. |
239 | */ |
240 | bool |
241 | SAL_CALL operator== (const Reference<reference_type> & handle) const |
242 | { |
243 | return (m_pBody == handle.m_pBody); |
244 | } |
245 | |
246 | |
247 | /** Needed to place References into STL collection. |
248 | */ |
249 | bool |
250 | SAL_CALL operator!= (const Reference<reference_type> & handle) const |
251 | { |
252 | return (m_pBody != handle.m_pBody); |
253 | } |
254 | |
255 | |
256 | /** Needed to place References into STL collection. |
257 | */ |
258 | bool |
259 | SAL_CALL operator< (const Reference<reference_type> & handle) const |
260 | { |
261 | return (m_pBody < handle.m_pBody); |
262 | } |
263 | |
264 | |
265 | /** Needed to place References into STL collection. |
266 | */ |
267 | bool |
268 | SAL_CALL operator> (const Reference<reference_type> & handle) const |
269 | { |
270 | return (m_pBody > handle.m_pBody); |
271 | } |
272 | }; |
273 | |
274 | } // namespace rtl |
275 | |
276 | #if defined LIBO_INTERNAL_ONLY1 |
277 | namespace std |
278 | { |
279 | |
280 | /// @cond INTERNAL |
281 | /** |
282 | Make rtl::Reference hashable by default for use in STL containers. |
283 | |
284 | @since LibreOffice 6.3 |
285 | */ |
286 | template<typename T> |
287 | struct hash<::rtl::Reference<T>> |
288 | { |
289 | std::size_t operator()(::rtl::Reference<T> const & s) const |
290 | { return std::size_t(s.get()); } |
291 | }; |
292 | /// @endcond |
293 | |
294 | } |
295 | |
296 | #endif |
297 | |
298 | #endif /* ! INCLUDED_RTL_REF_HXX */ |
299 | |
300 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_VCL_Reference_HXX |
20 | #define INCLUDED_VCL_Reference_HXX |
21 | |
22 | #include <vcl/dllapi.h> |
23 | #include <osl/interlck.h> |
24 | |
25 | class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase |
26 | { |
27 | mutable oslInterlockedCount mnRefCnt; |
28 | |
29 | template<typename T> friend class VclPtr; |
30 | |
31 | public: |
32 | void acquire() const |
33 | { |
34 | osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1); |
35 | } |
36 | |
37 | void release() const |
38 | { |
39 | if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0) |
40 | delete this; |
41 | } |
42 | #ifdef DBG_UTIL |
43 | #ifndef _WIN32 |
44 | sal_Int32 getRefCount() const { return mnRefCnt; } |
45 | #endif |
46 | #endif |
47 | |
48 | |
49 | private: |
50 | VclReferenceBase(const VclReferenceBase&) = delete; |
51 | VclReferenceBase& operator=(const VclReferenceBase&) = delete; |
52 | |
53 | bool mbDisposed : 1; |
54 | |
55 | protected: |
56 | VclReferenceBase(); |
57 | protected: |
58 | virtual ~VclReferenceBase(); |
59 | |
60 | protected: |
61 | virtual void dispose(); |
62 | |
63 | public: |
64 | void disposeOnce(); |
65 | bool isDisposed() const { return mbDisposed; } |
66 | |
67 | }; |
68 | #endif |