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 
35 class Button;
36 class SaveInData;
37 class SfxMacroInfoItem;
38 
40 {
41  OUString sFamily;
42  OUString sStyle;
43  OUString sCommand;
44  OUString sLabel;
45 
47  {}
48 
50  {
51  sFamily = rCopy.sFamily;
52  sStyle = rCopy.sStyle;
53  sCommand = rCopy.sCommand;
54  sLabel = rCopy.sLabel;
55  }
56 };
57 
59 {
60 private:
61  OUString m_aModuleName;
62  css::uno::Reference< css::frame::XModel > m_xDoc;
63 
64 public:
65 
67  void init(const OUString& rModuleName, const css::uno::Reference< css::frame::XModel >& xModel);
68 
69  static bool parseStyleCommand(SfxStyleInfo_Impl& aStyle);
70  void getLabel4Style(SfxStyleInfo_Impl& aStyle);
71 
72  std::vector< SfxStyleInfo_Impl > getStyleFamilies() const;
73  std::vector< SfxStyleInfo_Impl > getStyles(const OUString& sFamily);
74 
75  static OUString generateCommand(std::u16string_view sFamily, std::u16string_view sStyle);
76 };
77 
78 enum class SfxCfgKind
79 {
80  GROUP_FUNCTION = 1,
81  FUNCTION_SLOT = 2,
83  FUNCTION_SCRIPT = 4,
84  GROUP_STYLES = 5,
86 };
87 
89 {
91  sal_uInt16 nUniqueID;
92  void* pObject;
93  OUString sCommand;
94  OUString sLabel;
95  OUString sHelpText;
96  OUString sTooltip;
97 
98  SfxGroupInfo_Impl( SfxCfgKind n, sal_uInt16 nr, void* pObj = nullptr ) :
99  nKind( n ), nUniqueID( nr ), pObject( pObj ) {}
100 };
101 
102 typedef std::vector<std::unique_ptr<SfxGroupInfo_Impl> > SfxGroupInfoArr_Impl;
103 
105 {
106  friend class CuiConfigGroupListBox;
108 
109  std::unique_ptr<weld::TreeView> m_xTreeView;
110  std::unique_ptr<weld::TreeIter> m_xScratchIter;
111 
112 public:
113  CuiConfigFunctionListBox(std::unique_ptr<weld::TreeView> xTreeView);
114  void set_sensitive(bool bSensitive) { m_xTreeView->set_sensitive(bSensitive); }
115  void connect_changed(const Link<weld::TreeView&, void>& rLink) { m_xTreeView->connect_changed(rLink); }
116  void connect_popup_menu(const Link<const CommandEvent&, bool>& rLink) { m_xTreeView->connect_popup_menu(rLink); }
117  void connect_row_activated(const Link<weld::TreeView&, bool>& rLink) { m_xTreeView->connect_row_activated(rLink); }
118  void freeze() { m_xTreeView->freeze(); }
119  void thaw() { m_xTreeView->thaw(); }
120  void append(const OUString& rId, const OUString& rStr, const weld::TreeIter* pParent = nullptr)
121  {
122  m_xTreeView->insert(pParent, -1, &rStr, &rId, nullptr, nullptr, false, nullptr);
123  }
124  std::unique_ptr<weld::TreeIter> tree_append(const OUString& rId, const OUString& rStr, const weld::TreeIter* pParent = nullptr)
125  {
126  std::unique_ptr<weld::TreeIter> xIter(m_xTreeView->make_iterator());
127  m_xTreeView->insert(pParent, -1, &rStr, &rId, nullptr, nullptr, false, xIter.get());
128  return xIter;
129  }
130  void append(const OUString& rId, const OUString& rStr, const OUString& rImage, const weld::TreeIter* pParent = nullptr)
131  {
132  m_xTreeView->insert(pParent, -1, &rStr, &rId, nullptr, nullptr, false, m_xScratchIter.get());
133  m_xTreeView->set_image(*m_xScratchIter, rImage);
134  }
135  void append(const OUString& rId, const OUString& rStr, const css::uno::Reference<css::graphic::XGraphic>& rImage, const weld::TreeIter* pParent = nullptr)
136  {
137  m_xTreeView->insert(pParent, -1, &rStr, &rId, nullptr, nullptr, false, m_xScratchIter.get());
138  m_xTreeView->set_image(*m_xScratchIter, rImage, -1);
139  }
140  void remove(int nPos) { m_xTreeView->remove(nPos); }
141  void scroll_to_row(int pos) { m_xTreeView->scroll_to_row(pos); }
142  void remove(const weld::TreeIter& rIter) { m_xTreeView->remove(rIter); }
143  void expand_row(const weld::TreeIter& rIter) { m_xTreeView->expand_row(rIter); }
144  int n_children() const { return m_xTreeView->n_children(); }
145  std::unique_ptr<weld::TreeIter> make_iterator(const weld::TreeIter* pOrig = nullptr) const { return m_xTreeView->make_iterator(pOrig); }
146  bool iter_has_child(const weld::TreeIter& rIter) const { return m_xTreeView->iter_has_child(rIter); }
147  OUString get_text(int nPos) const { return m_xTreeView->get_text(nPos); }
148  OUString get_id(const weld::TreeIter& rIter) const { return m_xTreeView->get_id(rIter); }
149  bool get_selected(weld::TreeIter* pIter) const { return m_xTreeView->get_selected(pIter); }
150  OUString get_selected_text() const
151  {
152  if (!m_xTreeView->get_selected(m_xScratchIter.get()))
153  return OUString();
154  return m_xTreeView->get_text(*m_xScratchIter);
155  }
156  OUString get_selected_id() const
157  {
158  if (!m_xTreeView->get_selected(m_xScratchIter.get()))
159  return OUString();
160  return m_xTreeView->get_id(*m_xScratchIter);
161  }
162  void select(int pos) { m_xTreeView->select(pos); }
163  void set_size_request(int nWidth, int nHeight) { m_xTreeView->set_size_request(nWidth, nHeight); }
164  Size get_size_request() const { return m_xTreeView->get_size_request(); }
166 
168 
169  void ClearAll();
170  OUString GetSelectedScriptURI() const;
171  OUString GetHelpText( bool bConsiderParent = true );
172  OUString GetCurCommand() const;
173  OUString GetCurLabel() const;
174 
175  DECL_LINK(QueryTooltip, const weld::TreeIter& rIter, OUString);
176 };
177 
180 {
181  std::unique_ptr<SvxConfigGroupBoxResource_Impl> xImp;
185  css::uno::Reference< css::uno::XComponentContext > m_xContext;
186  css::uno::Reference< css::frame::XFrame > m_xFrame;
187  css::uno::Reference< css::container::XNameAccess > m_xGlobalCategoryInfo;
188  css::uno::Reference< css::container::XNameAccess > m_xModuleCategoryInfo;
189  css::uno::Reference< css::container::XNameAccess > m_xUICmdDescription;
191  std::unique_ptr<weld::TreeView> m_xTreeView;
192  std::unique_ptr<weld::TreeIter> m_xScratchIter;
193 
194  static OUString GetImage(
195  const css::uno::Reference< css::script::browse::XBrowseNode >& node,
196  css::uno::Reference< css::uno::XComponentContext > const & xCtx,
197  bool bIsRootNode);
198 
199  static css::uno::Reference< css::uno::XInterface > getDocumentModel(
200  css::uno::Reference< css::uno::XComponentContext > const & xCtx,
201  std::u16string_view docName);
202 
203  void InitModule();
204  void FillScriptList(const css::uno::Reference< css::script::browse::XBrowseNode >& xRootNode,
205  const weld::TreeIter* pParentEntry);
206  void FillFunctionsList(const css::uno::Sequence< css::frame::DispatchInformation >& xCommands);
207  OUString MapCommand2UIName(const OUString& sCommand);
208 
209  DECL_LINK(ExpandingHdl, const weld::TreeIter&, bool);
210 
211 public:
212  CuiConfigGroupListBox(std::unique_ptr<weld::TreeView> xTreeView);
213  void set_sensitive(bool bSensitive) { m_xTreeView->set_sensitive(bSensitive); }
214  void connect_changed(const Link<weld::TreeView&, void>& rLink) { m_xTreeView->connect_changed(rLink); }
215  void set_size_request(int nWidth, int nHeight) { m_xTreeView->set_size_request(nWidth, nHeight); }
218  void ClearAll();
219 
220  void Init(const css::uno::Reference< css::uno::XComponentContext >& xContext,
221  const css::uno::Reference< css::frame::XFrame >& xFrame,
222  const OUString& sModuleLongName,
223  bool bEventMode);
225  { m_pFunctionListBox = pBox; }
226  void GroupSelected();
227  void SelectMacro(const SfxMacroInfoItem*);
228  void SelectMacro(std::u16string_view, const OUString&);
229  void SetStylesInfo(SfxStylesInfo_Impl* pStyles);
230 };
231 
233 {
234  OUString m_sDefaultDesc;
236 
237  std::unique_ptr<weld::Label> m_xDialogDescription;
238  std::unique_ptr<CuiConfigGroupListBox> m_xCategories;
239  std::unique_ptr<CuiConfigFunctionListBox> m_xCommands;
240  std::unique_ptr<weld::Label> m_xLibraryFT;
241  std::unique_ptr<weld::Label> m_xCategoryFT;
242  std::unique_ptr<weld::Label> m_xMacronameFT;
243  std::unique_ptr<weld::Label> m_xCommandsFT;
244  std::unique_ptr<weld::Button> m_xOKButton;
245  std::unique_ptr<weld::Button> m_xCancelButton;
246  std::unique_ptr<weld::TextView> m_xDescriptionText;
247 
248  DECL_LINK(ClickHdl, weld::Button&, void);
249  DECL_LINK(SelectHdl, weld::TreeView&, void);
250  DECL_LINK(FunctionDoubleClickHdl, weld::TreeView&, bool);
251  DECL_LINK(ContextMenuHdl, const CommandEvent&, bool);
252 
253  void UpdateUI();
254 
255 public:
257  const css::uno::Reference< css::frame::XFrame >& xFrame);
258  virtual ~SvxScriptSelectorDialog() override;
259 
260  OUString GetScriptURL() const;
261  void SetRunLabel();
262 };
263 
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
weld::TreeView & get_widget()
Definition: cfgutil.hxx:165
DECL_LINK(ExpandingHdl, const weld::TreeIter &, bool)
std::unique_ptr< SvxConfigGroupBoxResource_Impl > xImp
Definition: cfgutil.hxx:181
css::uno::Reference< css::container::XNameAccess > m_xGlobalCategoryInfo
Definition: cfgutil.hxx:187
void SetFunctionListBox(CuiConfigFunctionListBox *pBox)
Definition: cfgutil.hxx:224
std::vector< SfxStyleInfo_Impl > getStyleFamilies() const
Definition: cfgutil.cxx:154
OUString sStyle
Definition: cfgutil.hxx:42
OUString GetHelpText(bool bConsiderParent=true)
Definition: cfgutil.cxx:240
OUString sTooltip
Definition: cfgutil.hxx:96
std::unique_ptr< CuiConfigFunctionListBox > m_xCommands
Definition: cfgutil.hxx:239
OUString GetScriptURL() const
Definition: cfgutil.cxx:1214
css::uno::Reference< css::frame::XModel > m_xDoc
Definition: cfgutil.hxx:62
SfxStylesInfo_Impl * m_pStylesInfo
Definition: cfgutil.hxx:190
css::uno::Reference< css::container::XNameAccess > m_xUICmdDescription
Definition: cfgutil.hxx:189
Size get_size_request() const
Definition: cfgutil.hxx:164
void getLabel4Style(SfxStyleInfo_Impl &aStyle)
Definition: cfgutil.cxx:121
void set_sensitive(bool bSensitive)
Definition: cfgutil.hxx:213
std::unique_ptr< weld::TreeIter > m_xScratchIter
Definition: cfgutil.hxx:192
std::unique_ptr< weld::TreeIter > tree_append(const OUString &rId, const OUString &rStr, const weld::TreeIter *pParent=nullptr)
Definition: cfgutil.hxx:124
void append(const OUString &rId, const OUString &rStr, const OUString &rImage, const weld::TreeIter *pParent=nullptr)
Definition: cfgutil.hxx:130
css::uno::Reference< css::container::XNameAccess > m_xModuleCategoryInfo
Definition: cfgutil.hxx:188
bool iter_has_child(const weld::TreeIter &rIter) const
Definition: cfgutil.hxx:146
DECL_LINK(QueryTooltip, const weld::TreeIter &rIter, OUString)
OUString MapCommand2UIName(const OUString &sCommand)
Definition: cfgutil.cxx:782
OUString get_text(int nPos) const
Definition: cfgutil.hxx:147
OUString get_selected_text() const
Definition: cfgutil.hxx:150
DECL_LINK(ClickHdl, weld::Button &, void)
std::unique_ptr< CuiConfigGroupListBox > m_xCategories
Definition: cfgutil.hxx:238
void select(int pos)
Definition: cfgutil.hxx:162
int n_children() const
Definition: cfgutil.hxx:144
SfxGroupInfoArr_Impl aArr
Definition: cfgutil.hxx:183
OUString sFamily
Definition: cfgutil.hxx:41
OUString GetCurLabel() const
Definition: cfgutil.cxx:268
void set_size_request(int nWidth, int nHeight)
Definition: cfgutil.hxx:215
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:622
std::unique_ptr< weld::TreeView > m_xTreeView
Definition: cfgutil.hxx:191
OUString sLabel
Definition: cfgutil.hxx:44
bool get_selected(weld::TreeIter *pIter) const
Definition: cfgutil.hxx:149
SvxScriptSelectorDialog(weld::Window *pParent, const css::uno::Reference< css::frame::XFrame > &xFrame)
Definition: cfgutil.cxx:1073
SfxStylesInfo_Impl m_aStylesInfo
Definition: cfgutil.hxx:235
void connect_changed(const Link< weld::TreeView &, void > &rLink)
Definition: cfgutil.hxx:115
SfxGroupInfo_Impl(SfxCfgKind n, sal_uInt16 nr, void *pObj=nullptr)
Definition: cfgutil.hxx:98
void set_size_request(int nWidth, int nHeight)
Definition: cfgutil.hxx:163
void connect_changed(const Link< weld::TreeView &, void > &rLink)
Definition: cfgutil.hxx:214
std::unique_ptr< weld::Label > m_xLibraryFT
Definition: cfgutil.hxx:240
void append(const OUString &rId, const OUString &rStr, const css::uno::Reference< css::graphic::XGraphic > &rImage, const weld::TreeIter *pParent=nullptr)
Definition: cfgutil.hxx:135
OUString sHelpText
Definition: cfgutil.hxx:95
std::vector< SfxStyleInfo_Impl > getStyles(const OUString &sFamily)
Definition: cfgutil.cxx:196
virtual ~SvxScriptSelectorDialog() override
Definition: cfgutil.cxx:1125
SfxCfgKind nKind
Definition: cfgutil.hxx:90
css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: cfgutil.hxx:185
OUString GetCurCommand() const
Definition: cfgutil.cxx:260
void scroll_to_row(int pos)
Definition: cfgutil.hxx:141
OUString GetSelectedScriptURI() const
Definition: cfgutil.cxx:334
SfxCfgKind
Definition: cfgutil.hxx:78
OUString get_selected_id() const
Definition: cfgutil.hxx:156
SfxStyleInfo_Impl(const SfxStyleInfo_Impl &rCopy)
Definition: cfgutil.hxx:49
sal_uInt16 nUniqueID
Definition: cfgutil.hxx:91
void SetStylesInfo(SfxStylesInfo_Impl *pStyles)
Definition: cfgutil.cxx:362
OUString m_sModuleLongName
Definition: cfgutil.hxx:184
OUString sCommand
Definition: cfgutil.hxx:43
void init(const OUString &rModuleName, const css::uno::Reference< css::frame::XModel > &xModel)
Definition: cfgutil.cxx:67
void connect_row_activated(const Link< weld::TreeView &, bool > &rLink)
Definition: cfgutil.hxx:117
std::unique_ptr< weld::TreeIter > make_iterator(const weld::TreeIter *pOrig=nullptr) const
Definition: cfgutil.hxx:145
void FillScriptList(const css::uno::Reference< css::script::browse::XBrowseNode > &xRootNode, const weld::TreeIter *pParentEntry)
Definition: cfgutil.cxx:508
std::vector< std::unique_ptr< SfxGroupInfo_Impl > > SfxGroupInfoArr_Impl
Definition: cfgutil.hxx:102
std::unique_ptr< weld::Label > m_xMacronameFT
Definition: cfgutil.hxx:242
void FillFunctionsList(const css::uno::Sequence< css::frame::DispatchInformation > &xCommands)
Definition: cfgutil.cxx:604
SfxGroupInfoArr_Impl aArr
Definition: cfgutil.hxx:107
CuiConfigFunctionListBox(std::unique_ptr< weld::TreeView > xTreeView)
Definition: cfgutil.cxx:278
OUString sCommand
Definition: cfgutil.hxx:93
std::unique_ptr< weld::Label > m_xCommandsFT
Definition: cfgutil.hxx:243
static OUString generateCommand(std::u16string_view sFamily, std::u16string_view sStyle)
Definition: cfgutil.cxx:79
void connect_popup_menu(const Link< const CommandEvent &, bool > &rLink)
Definition: cfgutil.hxx:116
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:693
void expand_row(const weld::TreeIter &rIter)
Definition: cfgutil.hxx:143
std::unique_ptr< weld::Label > m_xDialogDescription
Definition: cfgutil.hxx:237
std::unique_ptr< weld::TreeIter > m_xScratchIter
Definition: cfgutil.hxx:110
CuiConfigFunctionListBox * m_pFunctionListBox
Definition: cfgutil.hxx:182
static css::uno::Reference< css::uno::XInterface > getDocumentModel(css::uno::Reference< css::uno::XComponentContext > const &xCtx, std::u16string_view docName)
Definition: cfgutil.cxx:755
static bool parseStyleCommand(SfxStyleInfo_Impl &aStyle)
Definition: cfgutil.cxx:88
OUString sLabel
Definition: cfgutil.hxx:94
OUString get_id(const weld::TreeIter &rIter) const
Definition: cfgutil.hxx:148
OUString m_aModuleName
Definition: cfgutil.hxx:61
std::unique_ptr< weld::Button > m_xOKButton
Definition: cfgutil.hxx:244
void SelectMacro(const SfxMacroInfoItem *)
Definition: cfgutil.cxx:990
std::unique_ptr< weld::Label > m_xCategoryFT
Definition: cfgutil.hxx:241
weld::TreeView & get_widget()
Definition: cfgutil.hxx:216
std::unique_ptr< weld::Button > m_xCancelButton
Definition: cfgutil.hxx:245
CuiConfigGroupListBox(std::unique_ptr< weld::TreeView > xTreeView)
Definition: cfgutil.cxx:419
css::uno::Reference< css::frame::XFrame > m_xFrame
Definition: cfgutil.hxx:186
std::unique_ptr< weld::TreeView > m_xTreeView
Definition: cfgutil.hxx:109
sal_uInt16 nPos
void set_sensitive(bool bSensitive)
Definition: cfgutil.hxx:114
std::unique_ptr< weld::TextView > m_xDescriptionText
Definition: cfgutil.hxx:246
void append(const OUString &rId, const OUString &rStr, const weld::TreeIter *pParent=nullptr)
Definition: cfgutil.hxx:120