Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / cui / source / inc / cfgutil.hxx
blob44f532baa6ba02e86694b30bee55ca946b55f121
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #pragma once
21 #include <vector>
22 #include <memory>
23 #include <string_view>
25 #include <rtl/ustring.hxx>
27 #include <com/sun/star/frame/DispatchInformation.hpp>
28 #include <com/sun/star/frame/XModel.hpp>
29 #include <com/sun/star/frame/XFrame.hpp>
30 #include <com/sun/star/container/XNameAccess.hpp>
31 #include <com/sun/star/script/browse/XBrowseNode.hpp>
32 #include <com/sun/star/uno/XComponentContext.hpp>
33 #include <vcl/weld.hxx>
34 #include <config_features.h>
36 class Button;
37 class SaveInData;
38 #if HAVE_FEATURE_SCRIPTING
39 class SfxMacroInfoItem;
40 #endif
42 struct SfxStyleInfo_Impl
44 OUString sFamily;
45 OUString sStyle;
46 OUString sCommand;
47 OUString sLabel;
49 SfxStyleInfo_Impl()
52 SfxStyleInfo_Impl(const SfxStyleInfo_Impl& rCopy)
54 sFamily = rCopy.sFamily;
55 sStyle = rCopy.sStyle;
56 sCommand = rCopy.sCommand;
57 sLabel = rCopy.sLabel;
61 struct SfxStylesInfo_Impl
63 private:
64 OUString m_aModuleName;
65 css::uno::Reference< css::frame::XModel > m_xDoc;
67 public:
69 SfxStylesInfo_Impl();
70 void init(const OUString& rModuleName, const css::uno::Reference< css::frame::XModel >& xModel);
72 static bool parseStyleCommand(SfxStyleInfo_Impl& aStyle);
73 void getLabel4Style(SfxStyleInfo_Impl& aStyle);
75 std::vector< SfxStyleInfo_Impl > getStyleFamilies() const;
76 std::vector< SfxStyleInfo_Impl > getStyles(const OUString& sFamily);
78 static OUString generateCommand(std::u16string_view sFamily, std::u16string_view sStyle);
81 enum class SfxCfgKind
83 GROUP_FUNCTION = 1,
84 FUNCTION_SLOT = 2,
85 GROUP_SCRIPTCONTAINER = 3,
86 FUNCTION_SCRIPT = 4,
87 GROUP_STYLES = 5,
88 GROUP_ALLFUNCTIONS = 6,
89 GROUP_SIDEBARDECKS = 7
92 struct SfxGroupInfo_Impl
94 SfxCfgKind nKind;
95 sal_uInt16 nUniqueID;
96 void* pObject;
97 OUString sCommand;
98 OUString sLabel;
99 OUString sHelpText;
100 OUString sTooltip;
102 SfxGroupInfo_Impl( SfxCfgKind n, sal_uInt16 nr, void* pObj = nullptr ) :
103 nKind( n ), nUniqueID( nr ), pObject( pObj ) {}
106 typedef std::vector<std::unique_ptr<SfxGroupInfo_Impl> > SfxGroupInfoArr_Impl;
108 class CuiConfigFunctionListBox
110 friend class CuiConfigGroupListBox;
111 SfxGroupInfoArr_Impl aArr;
113 std::unique_ptr<weld::TreeView> m_xTreeView;
114 std::unique_ptr<weld::TreeIter> m_xScratchIter;
116 public:
117 CuiConfigFunctionListBox(std::unique_ptr<weld::TreeView> xTreeView);
118 void set_sensitive(bool bSensitive) { m_xTreeView->set_sensitive(bSensitive); }
119 void connect_changed(const Link<weld::TreeView&, void>& rLink) { m_xTreeView->connect_changed(rLink); }
120 void connect_popup_menu(const Link<const CommandEvent&, bool>& rLink) { m_xTreeView->connect_popup_menu(rLink); }
121 void connect_row_activated(const Link<weld::TreeView&, bool>& rLink) { m_xTreeView->connect_row_activated(rLink); }
122 void freeze() { m_xTreeView->freeze(); }
123 void thaw() { m_xTreeView->thaw(); }
124 void append(const OUString& rId, const OUString& rStr, const weld::TreeIter* pParent = nullptr)
126 m_xTreeView->insert(pParent, -1, &rStr, &rId, nullptr, nullptr, false, nullptr);
128 std::unique_ptr<weld::TreeIter> tree_append(const OUString& rId, const OUString& rStr, const weld::TreeIter* pParent = nullptr)
130 std::unique_ptr<weld::TreeIter> xIter(m_xTreeView->make_iterator());
131 m_xTreeView->insert(pParent, -1, &rStr, &rId, nullptr, nullptr, false, xIter.get());
132 return xIter;
134 void append(const OUString& rId, const OUString& rStr, const OUString& rImage, const weld::TreeIter* pParent = nullptr)
136 m_xTreeView->insert(pParent, -1, &rStr, &rId, nullptr, nullptr, false, m_xScratchIter.get());
137 m_xTreeView->set_image(*m_xScratchIter, rImage);
139 void append(const OUString& rId, const OUString& rStr, const css::uno::Reference<css::graphic::XGraphic>& rImage, const weld::TreeIter* pParent = nullptr)
141 m_xTreeView->insert(pParent, -1, &rStr, &rId, nullptr, nullptr, false, m_xScratchIter.get());
142 m_xTreeView->set_image(*m_xScratchIter, rImage, -1);
144 void remove(int nPos) { m_xTreeView->remove(nPos); }
145 void scroll_to_row(int pos) { m_xTreeView->scroll_to_row(pos); }
146 void remove(const weld::TreeIter& rIter) { m_xTreeView->remove(rIter); }
147 void expand_row(const weld::TreeIter& rIter) { m_xTreeView->expand_row(rIter); }
148 int n_children() const { return m_xTreeView->n_children(); }
149 std::unique_ptr<weld::TreeIter> make_iterator(const weld::TreeIter* pOrig = nullptr) const { return m_xTreeView->make_iterator(pOrig); }
150 bool iter_has_child(const weld::TreeIter& rIter) const { return m_xTreeView->iter_has_child(rIter); }
151 OUString get_text(int nPos) const { return m_xTreeView->get_text(nPos); }
152 OUString get_id(const weld::TreeIter& rIter) const { return m_xTreeView->get_id(rIter); }
153 bool get_selected(weld::TreeIter* pIter) const { return m_xTreeView->get_selected(pIter); }
154 OUString get_selected_text() const
156 if (!m_xTreeView->get_selected(m_xScratchIter.get()))
157 return OUString();
158 return m_xTreeView->get_text(*m_xScratchIter);
160 OUString get_selected_id() const
162 if (!m_xTreeView->get_selected(m_xScratchIter.get()))
163 return OUString();
164 return m_xTreeView->get_id(*m_xScratchIter);
166 void select(int pos) { m_xTreeView->select(pos); }
167 void set_size_request(int nWidth, int nHeight) { m_xTreeView->set_size_request(nWidth, nHeight); }
168 Size get_size_request() const { return m_xTreeView->get_size_request(); }
169 weld::TreeView& get_widget() { return *m_xTreeView; }
171 ~CuiConfigFunctionListBox();
173 void ClearAll();
174 OUString GetSelectedScriptURI() const;
175 OUString GetHelpText( bool bConsiderParent = true );
176 OUString GetCurCommand() const;
177 OUString GetCurLabel() const;
179 DECL_LINK(QueryTooltip, const weld::TreeIter& rIter, OUString);
182 struct SvxConfigGroupBoxResource_Impl;
183 class CuiConfigGroupListBox
185 std::unique_ptr<SvxConfigGroupBoxResource_Impl> xImp;
186 CuiConfigFunctionListBox* m_pFunctionListBox;
187 SfxGroupInfoArr_Impl aArr;
188 OUString m_sModuleLongName;
189 css::uno::Reference< css::uno::XComponentContext > m_xContext;
190 css::uno::Reference< css::frame::XFrame > m_xFrame;
191 css::uno::Reference< css::container::XNameAccess > m_xGlobalCategoryInfo;
192 css::uno::Reference< css::container::XNameAccess > m_xModuleCategoryInfo;
193 css::uno::Reference< css::container::XNameAccess > m_xUICmdDescription;
194 SfxStylesInfo_Impl* m_pStylesInfo;
195 std::unique_ptr<weld::TreeView> m_xTreeView;
196 std::unique_ptr<weld::TreeIter> m_xScratchIter;
198 static OUString GetImage(
199 const css::uno::Reference< css::script::browse::XBrowseNode >& node,
200 css::uno::Reference< css::uno::XComponentContext > const & xCtx,
201 bool bIsRootNode);
203 static css::uno::Reference< css::uno::XInterface > getDocumentModel(
204 css::uno::Reference< css::uno::XComponentContext > const & xCtx,
205 std::u16string_view docName);
207 void InitModule();
208 void FillScriptList(const css::uno::Reference< css::script::browse::XBrowseNode >& xRootNode,
209 const weld::TreeIter* pParentEntry);
210 void FillFunctionsList(const css::uno::Sequence< css::frame::DispatchInformation >& xCommands);
211 OUString MapCommand2UIName(const OUString& sCommand);
213 DECL_LINK(ExpandingHdl, const weld::TreeIter&, bool);
215 public:
216 CuiConfigGroupListBox(std::unique_ptr<weld::TreeView> xTreeView);
217 void set_sensitive(bool bSensitive) { m_xTreeView->set_sensitive(bSensitive); }
218 void connect_changed(const Link<weld::TreeView&, void>& rLink) { m_xTreeView->connect_changed(rLink); }
219 void set_size_request(int nWidth, int nHeight) { m_xTreeView->set_size_request(nWidth, nHeight); }
220 weld::TreeView& get_widget() { return *m_xTreeView; }
221 ~CuiConfigGroupListBox();
222 void ClearAll();
224 void Init(const css::uno::Reference< css::uno::XComponentContext >& xContext,
225 const css::uno::Reference< css::frame::XFrame >& xFrame,
226 const OUString& sModuleLongName,
227 bool bEventMode);
228 void SetFunctionListBox( CuiConfigFunctionListBox *pBox )
229 { m_pFunctionListBox = pBox; }
230 void GroupSelected();
231 #if HAVE_FEATURE_SCRIPTING
232 void SelectMacro(const SfxMacroInfoItem*);
233 #endif
234 void SetStylesInfo(SfxStylesInfo_Impl* pStyles);
237 class SvxScriptSelectorDialog : public weld::GenericDialogController
239 OUString m_sDefaultDesc;
240 SfxStylesInfo_Impl m_aStylesInfo;
242 std::unique_ptr<weld::Label> m_xDialogDescription;
243 std::unique_ptr<CuiConfigGroupListBox> m_xCategories;
244 std::unique_ptr<CuiConfigFunctionListBox> m_xCommands;
245 std::unique_ptr<weld::Label> m_xLibraryFT;
246 std::unique_ptr<weld::Label> m_xMacronameFT;
247 std::unique_ptr<weld::Button> m_xOKButton;
248 std::unique_ptr<weld::Button> m_xCancelButton;
249 std::unique_ptr<weld::TextView> m_xDescriptionText;
250 std::unique_ptr<weld::Frame> m_xDescriptionFrame;
252 DECL_LINK(ClickHdl, weld::Button&, void);
253 DECL_LINK(SelectHdl, weld::TreeView&, void);
254 DECL_LINK(FunctionDoubleClickHdl, weld::TreeView&, bool);
255 DECL_LINK(ContextMenuHdl, const CommandEvent&, bool);
257 void UpdateUI();
259 public:
260 SvxScriptSelectorDialog(weld::Window* pParent,
261 const css::uno::Reference< css::frame::XFrame >& xFrame);
262 virtual ~SvxScriptSelectorDialog() override;
264 OUString GetScriptURL() const;
265 void SetRunLabel();
266 void SaveLastUsedMacro();
267 void LoadLastUsedMacro();
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */