LibreOffice Module cui (master) 1
cfgutil.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19#pragma once
20
21#include <vector>
22#include <memory>
23#include <string_view>
24
25#include <rtl/ustring.hxx>
26
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>
35
36class Button;
37class SaveInData;
38#if HAVE_FEATURE_SCRIPTING
39class SfxMacroInfoItem;
40#endif
41
43{
44 OUString sFamily;
45 OUString sStyle;
46 OUString sCommand;
47 OUString sLabel;
48
50 {}
51
53 {
54 sFamily = rCopy.sFamily;
55 sStyle = rCopy.sStyle;
56 sCommand = rCopy.sCommand;
57 sLabel = rCopy.sLabel;
58 }
59};
60
62{
63private:
64 OUString m_aModuleName;
65 css::uno::Reference< css::frame::XModel > m_xDoc;
66
67public:
68
70 void init(const OUString& rModuleName, const css::uno::Reference< css::frame::XModel >& xModel);
71
72 static bool parseStyleCommand(SfxStyleInfo_Impl& aStyle);
74
75 std::vector< SfxStyleInfo_Impl > getStyleFamilies() const;
76 std::vector< SfxStyleInfo_Impl > getStyles(const OUString& sFamily);
77
78 static OUString generateCommand(std::u16string_view sFamily, std::u16string_view sStyle);
79};
80
81enum class SfxCfgKind
82{
84 FUNCTION_SLOT = 2,
87 GROUP_STYLES = 5,
90};
91
93{
95 sal_uInt16 nUniqueID;
96 void* pObject;
97 OUString sCommand;
98 OUString sLabel;
99 OUString sHelpText;
100 OUString sTooltip;
101
102 SfxGroupInfo_Impl( SfxCfgKind n, sal_uInt16 nr, void* pObj = nullptr ) :
103 nKind( n ), nUniqueID( nr ), pObject( pObj ) {}
104};
105
106typedef std::vector<std::unique_ptr<SfxGroupInfo_Impl> > SfxGroupInfoArr_Impl;
107
109{
112
113 std::unique_ptr<weld::TreeView> m_xTreeView;
114 std::unique_ptr<weld::TreeIter> m_xScratchIter;
115
116public:
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)
125 {
126 m_xTreeView->insert(pParent, -1, &rStr, &rId, nullptr, nullptr, false, nullptr);
127 }
128 std::unique_ptr<weld::TreeIter> tree_append(const OUString& rId, const OUString& rStr, const weld::TreeIter* pParent = nullptr)
129 {
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;
133 }
134 void append(const OUString& rId, const OUString& rStr, const OUString& rImage, const weld::TreeIter* pParent = nullptr)
135 {
136 m_xTreeView->insert(pParent, -1, &rStr, &rId, nullptr, nullptr, false, m_xScratchIter.get());
137 m_xTreeView->set_image(*m_xScratchIter, rImage);
138 }
139 void append(const OUString& rId, const OUString& rStr, const css::uno::Reference<css::graphic::XGraphic>& rImage, const weld::TreeIter* pParent = nullptr)
140 {
141 m_xTreeView->insert(pParent, -1, &rStr, &rId, nullptr, nullptr, false, m_xScratchIter.get());
142 m_xTreeView->set_image(*m_xScratchIter, rImage, -1);
143 }
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
155 {
156 if (!m_xTreeView->get_selected(m_xScratchIter.get()))
157 return OUString();
158 return m_xTreeView->get_text(*m_xScratchIter);
159 }
160 OUString get_selected_id() const
161 {
162 if (!m_xTreeView->get_selected(m_xScratchIter.get()))
163 return OUString();
164 return m_xTreeView->get_id(*m_xScratchIter);
165 }
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(); }
170
172
173 void ClearAll();
174 OUString GetSelectedScriptURI() const;
175 OUString GetHelpText( bool bConsiderParent = true );
176 OUString GetCurCommand() const;
177 OUString GetCurLabel() const;
178
179 DECL_LINK(QueryTooltip, const weld::TreeIter& rIter, OUString);
180};
181
184{
185 std::unique_ptr<SvxConfigGroupBoxResource_Impl> xImp;
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;
195 std::unique_ptr<weld::TreeView> m_xTreeView;
196 std::unique_ptr<weld::TreeIter> m_xScratchIter;
197
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);
202
203 static css::uno::Reference< css::uno::XInterface > getDocumentModel(
204 css::uno::Reference< css::uno::XComponentContext > const & xCtx,
205 std::u16string_view docName);
206
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);
212
213 DECL_LINK(ExpandingHdl, const weld::TreeIter&, bool);
214
215public:
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); }
222 void ClearAll();
223
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);
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);
235};
236
238{
241
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;
251
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);
256
257 void UpdateUI();
258
259public:
261 const css::uno::Reference< css::frame::XFrame >& xFrame);
262 virtual ~SvxScriptSelectorDialog() override;
263
264 OUString GetScriptURL() const;
265 void SetRunLabel();
266 void SaveLastUsedMacro();
267 void LoadLastUsedMacro();
268};
269
270/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< std::unique_ptr< SfxGroupInfo_Impl > > SfxGroupInfoArr_Impl
Definition: cfgutil.hxx:106
SfxCfgKind
Definition: cfgutil.hxx:82
@ GROUP_SCRIPTCONTAINER
@ GROUP_SIDEBARDECKS
@ GROUP_ALLFUNCTIONS
void select(int pos)
Definition: cfgutil.hxx:166
OUString GetCurLabel() const
Definition: cfgutil.cxx:275
void set_size_request(int nWidth, int nHeight)
Definition: cfgutil.hxx:167
std::unique_ptr< weld::TreeIter > tree_append(const OUString &rId, const OUString &rStr, const weld::TreeIter *pParent=nullptr)
Definition: cfgutil.hxx:128
SfxGroupInfoArr_Impl aArr
Definition: cfgutil.hxx:111
bool get_selected(weld::TreeIter *pIter) const
Definition: cfgutil.hxx:153
void append(const OUString &rId, const OUString &rStr, const OUString &rImage, const weld::TreeIter *pParent=nullptr)
Definition: cfgutil.hxx:134
std::unique_ptr< weld::TreeIter > make_iterator(const weld::TreeIter *pOrig=nullptr) const
Definition: cfgutil.hxx:149
OUString get_selected_text() const
Definition: cfgutil.hxx:154
void expand_row(const weld::TreeIter &rIter)
Definition: cfgutil.hxx:147
void set_sensitive(bool bSensitive)
Definition: cfgutil.hxx:118
OUString get_text(int nPos) const
Definition: cfgutil.hxx:151
OUString GetCurCommand() const
Definition: cfgutil.cxx:267
void connect_row_activated(const Link< weld::TreeView &, bool > &rLink)
Definition: cfgutil.hxx:121
void connect_popup_menu(const Link< const CommandEvent &, bool > &rLink)
Definition: cfgutil.hxx:120
OUString get_id(const weld::TreeIter &rIter) const
Definition: cfgutil.hxx:152
void scroll_to_row(int pos)
Definition: cfgutil.hxx:145
void append(const OUString &rId, const OUString &rStr, const css::uno::Reference< css::graphic::XGraphic > &rImage, const weld::TreeIter *pParent=nullptr)
Definition: cfgutil.hxx:139
OUString get_selected_id() const
Definition: cfgutil.hxx:160
weld::TreeView & get_widget()
Definition: cfgutil.hxx:169
void append(const OUString &rId, const OUString &rStr, const weld::TreeIter *pParent=nullptr)
Definition: cfgutil.hxx:124
DECL_LINK(QueryTooltip, const weld::TreeIter &rIter, OUString)
bool iter_has_child(const weld::TreeIter &rIter) const
Definition: cfgutil.hxx:150
void remove(const weld::TreeIter &rIter)
Definition: cfgutil.hxx:146
OUString GetSelectedScriptURI() const
Definition: cfgutil.cxx:341
OUString GetHelpText(bool bConsiderParent=true)
Definition: cfgutil.cxx:247
void connect_changed(const Link< weld::TreeView &, void > &rLink)
Definition: cfgutil.hxx:119
Size get_size_request() const
Definition: cfgutil.hxx:168
int n_children() const
Definition: cfgutil.hxx:148
void remove(int nPos)
Definition: cfgutil.hxx:144
std::unique_ptr< weld::TreeView > m_xTreeView
Definition: cfgutil.hxx:113
std::unique_ptr< weld::TreeIter > m_xScratchIter
Definition: cfgutil.hxx:114
CuiConfigFunctionListBox(std::unique_ptr< weld::TreeView > xTreeView)
Definition: cfgutil.cxx:285
void SetStylesInfo(SfxStylesInfo_Impl *pStyles)
Definition: cfgutil.cxx:369
OUString m_sModuleLongName
Definition: cfgutil.hxx:188
CuiConfigFunctionListBox * m_pFunctionListBox
Definition: cfgutil.hxx:186
std::unique_ptr< weld::TreeView > m_xTreeView
Definition: cfgutil.hxx:195
SfxStylesInfo_Impl * m_pStylesInfo
Definition: cfgutil.hxx:194
void Init(const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::frame::XFrame > &xFrame, const OUString &sModuleLongName, bool bEventMode)
Definition: cfgutil.cxx:627
static OUString GetImage(const css::uno::Reference< css::script::browse::XBrowseNode > &node, css::uno::Reference< css::uno::XComponentContext > const &xCtx, bool bIsRootNode)
Definition: cfgutil.cxx:703
static css::uno::Reference< css::uno::XInterface > getDocumentModel(css::uno::Reference< css::uno::XComponentContext > const &xCtx, std::u16string_view docName)
Definition: cfgutil.cxx:765
CuiConfigGroupListBox(std::unique_ptr< weld::TreeView > xTreeView)
Definition: cfgutil.cxx:426
SfxGroupInfoArr_Impl aArr
Definition: cfgutil.hxx:187
std::unique_ptr< SvxConfigGroupBoxResource_Impl > xImp
Definition: cfgutil.hxx:185
css::uno::Reference< css::container::XNameAccess > m_xGlobalCategoryInfo
Definition: cfgutil.hxx:191
OUString MapCommand2UIName(const OUString &sCommand)
Definition: cfgutil.cxx:792
void FillFunctionsList(const css::uno::Sequence< css::frame::DispatchInformation > &xCommands)
Definition: cfgutil.cxx:609
css::uno::Reference< css::container::XNameAccess > m_xModuleCategoryInfo
Definition: cfgutil.hxx:192
weld::TreeView & get_widget()
Definition: cfgutil.hxx:220
DECL_LINK(ExpandingHdl, const weld::TreeIter &, bool)
void SetFunctionListBox(CuiConfigFunctionListBox *pBox)
Definition: cfgutil.hxx:228
std::unique_ptr< weld::TreeIter > m_xScratchIter
Definition: cfgutil.hxx:196
void FillScriptList(const css::uno::Reference< css::script::browse::XBrowseNode > &xRootNode, const weld::TreeIter *pParentEntry)
Definition: cfgutil.cxx:513
css::uno::Reference< css::frame::XFrame > m_xFrame
Definition: cfgutil.hxx:190
void set_sensitive(bool bSensitive)
Definition: cfgutil.hxx:217
css::uno::Reference< css::container::XNameAccess > m_xUICmdDescription
Definition: cfgutil.hxx:193
void set_size_request(int nWidth, int nHeight)
Definition: cfgutil.hxx:219
css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: cfgutil.hxx:189
void connect_changed(const Link< weld::TreeView &, void > &rLink)
Definition: cfgutil.hxx:218
SvxScriptSelectorDialog(weld::Window *pParent, const css::uno::Reference< css::frame::XFrame > &xFrame)
Definition: cfgutil.cxx:1119
DECL_LINK(FunctionDoubleClickHdl, weld::TreeView &, bool)
std::unique_ptr< weld::Label > m_xDialogDescription
Definition: cfgutil.hxx:242
DECL_LINK(ContextMenuHdl, const CommandEvent &, bool)
DECL_LINK(SelectHdl, weld::TreeView &, void)
std::unique_ptr< weld::Button > m_xOKButton
Definition: cfgutil.hxx:247
OUString GetScriptURL() const
Definition: cfgutil.cxx:1264
std::unique_ptr< CuiConfigGroupListBox > m_xCategories
Definition: cfgutil.hxx:243
std::unique_ptr< weld::Label > m_xMacronameFT
Definition: cfgutil.hxx:246
std::unique_ptr< CuiConfigFunctionListBox > m_xCommands
Definition: cfgutil.hxx:244
std::unique_ptr< weld::TextView > m_xDescriptionText
Definition: cfgutil.hxx:249
std::unique_ptr< weld::Label > m_xLibraryFT
Definition: cfgutil.hxx:245
std::unique_ptr< weld::Button > m_xCancelButton
Definition: cfgutil.hxx:248
SfxStylesInfo_Impl m_aStylesInfo
Definition: cfgutil.hxx:240
std::unique_ptr< weld::Frame > m_xDescriptionFrame
Definition: cfgutil.hxx:250
virtual ~SvxScriptSelectorDialog() override
Definition: cfgutil.cxx:1175
DECL_LINK(ClickHdl, weld::Button &, void)
sal_Int64 n
sal_uInt16 nPos
OUString sTooltip
Definition: cfgutil.hxx:100
OUString sLabel
Definition: cfgutil.hxx:98
sal_uInt16 nUniqueID
Definition: cfgutil.hxx:95
OUString sHelpText
Definition: cfgutil.hxx:99
OUString sCommand
Definition: cfgutil.hxx:97
SfxGroupInfo_Impl(SfxCfgKind n, sal_uInt16 nr, void *pObj=nullptr)
Definition: cfgutil.hxx:102
SfxCfgKind nKind
Definition: cfgutil.hxx:94
OUString sStyle
Definition: cfgutil.hxx:45
OUString sCommand
Definition: cfgutil.hxx:46
SfxStyleInfo_Impl(const SfxStyleInfo_Impl &rCopy)
Definition: cfgutil.hxx:52
OUString sFamily
Definition: cfgutil.hxx:44
OUString sLabel
Definition: cfgutil.hxx:47
void init(const OUString &rModuleName, const css::uno::Reference< css::frame::XModel > &xModel)
Definition: cfgutil.cxx:72
static bool parseStyleCommand(SfxStyleInfo_Impl &aStyle)
Definition: cfgutil.cxx:95
static OUString generateCommand(std::u16string_view sFamily, std::u16string_view sStyle)
Definition: cfgutil.cxx:86
std::vector< SfxStyleInfo_Impl > getStyleFamilies() const
Definition: cfgutil.cxx:161
std::vector< SfxStyleInfo_Impl > getStyles(const OUString &sFamily)
Definition: cfgutil.cxx:203
css::uno::Reference< css::frame::XModel > m_xDoc
Definition: cfgutil.hxx:65
void getLabel4Style(SfxStyleInfo_Impl &aStyle)
Definition: cfgutil.cxx:128
OUString m_aModuleName
Definition: cfgutil.hxx:64
size_t pos