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 #ifndef INCLUDED_CUI_SOURCE_INC_CFGUTIL_HXX
20 #define INCLUDED_CUI_SOURCE_INC_CFGUTIL_HXX
21 
22 #include <vector>
23 #include <memory>
24 #include <rtl/ustring.hxx>
25 
26 #include <com/sun/star/frame/DispatchInformation.hpp>
27 #include <com/sun/star/frame/XModel.hpp>
28 #include <com/sun/star/frame/XFrame.hpp>
29 #include <com/sun/star/container/XNameAccess.hpp>
30 #include <com/sun/star/script/browse/XBrowseNode.hpp>
31 #include <com/sun/star/uno/XComponentContext.hpp>
32 #include <vcl/weld.hxx>
33 
34 class Button;
35 class SaveInData;
36 class SfxMacroInfoItem;
37 
39 {
40  OUString sFamily;
41  OUString sStyle;
42  OUString sCommand;
43  OUString sLabel;
44 
46  {}
47 
49  {
50  sFamily = rCopy.sFamily;
51  sStyle = rCopy.sStyle;
52  sCommand = rCopy.sCommand;
53  sLabel = rCopy.sLabel;
54  }
55 };
56 
58 {
59 private:
60  OUString m_aModuleName;
61  css::uno::Reference< css::frame::XModel > m_xDoc;
62 
63 public:
64 
66  void init(const OUString& rModuleName, const css::uno::Reference< css::frame::XModel >& xModel);
67 
68  static bool parseStyleCommand(SfxStyleInfo_Impl& aStyle);
69  void getLabel4Style(SfxStyleInfo_Impl& aStyle);
70 
71  std::vector< SfxStyleInfo_Impl > getStyleFamilies() const;
72  std::vector< SfxStyleInfo_Impl > getStyles(const OUString& sFamily);
73 
74  static OUString generateCommand(const OUString& sFamily, const OUString& sStyle);
75 };
76 
77 enum class SfxCfgKind
78 {
79  GROUP_FUNCTION = 1,
80  FUNCTION_SLOT = 2,
82  FUNCTION_SCRIPT = 4,
83  GROUP_STYLES = 5,
85 };
86 
88 {
90  sal_uInt16 nUniqueID;
91  void* pObject;
92  OUString sCommand;
93  OUString sLabel;
94  OUString sHelpText;
95  OUString sTooltip;
96 
97  SfxGroupInfo_Impl( SfxCfgKind n, sal_uInt16 nr, void* pObj = nullptr ) :
98  nKind( n ), nUniqueID( nr ), pObject( pObj ) {}
99 };
100 
101 typedef std::vector<std::unique_ptr<SfxGroupInfo_Impl> > SfxGroupInfoArr_Impl;
102 
104 {
105  friend class CuiConfigGroupListBox;
107 
108  std::unique_ptr<weld::TreeView> m_xTreeView;
109  std::unique_ptr<weld::TreeIter> m_xScratchIter;
110 
111 public:
112  CuiConfigFunctionListBox(std::unique_ptr<weld::TreeView> xTreeView);
113  void set_sensitive(bool bSensitive) { m_xTreeView->set_sensitive(bSensitive); }
114  void connect_changed(const Link<weld::TreeView&, void>& rLink) { m_xTreeView->connect_changed(rLink); }
115  void connect_row_activated(const Link<weld::TreeView&, bool>& rLink) { m_xTreeView->connect_row_activated(rLink); }
116  void freeze() { m_xTreeView->freeze(); }
117  void thaw() { m_xTreeView->thaw(); }
118  void append(const OUString& rId, const OUString& rStr, const weld::TreeIter* pParent = nullptr)
119  {
120  m_xTreeView->insert(pParent, -1, &rStr, &rId, nullptr, nullptr, nullptr, false, nullptr);
121  }
122  std::unique_ptr<weld::TreeIter> tree_append(const OUString& rId, const OUString& rStr, const weld::TreeIter* pParent = nullptr)
123  {
124  std::unique_ptr<weld::TreeIter> xIter(m_xTreeView->make_iterator());
125  m_xTreeView->insert(pParent, -1, &rStr, &rId, nullptr, nullptr, nullptr, false, xIter.get());
126  return xIter;
127  }
128  void append(const OUString& rId, const OUString& rStr, const OUString& rImage, const weld::TreeIter* pParent = nullptr)
129  {
130  m_xTreeView->insert(pParent, -1, &rStr, &rId, nullptr, nullptr, &rImage, false, nullptr);
131  }
132  void append(const OUString& rId, const OUString& rStr, const css::uno::Reference<css::graphic::XGraphic>& rImage, const weld::TreeIter* pParent = nullptr)
133  {
134  m_xTreeView->insert(pParent, -1, &rStr, &rId, nullptr, nullptr, nullptr, false, m_xScratchIter.get());
135  m_xTreeView->set_image(*m_xScratchIter, rImage, -1);
136  }
137  void remove(int nPos) { m_xTreeView->remove(nPos); }
138  void scroll_to_row(int pos) { m_xTreeView->scroll_to_row(pos); }
139  void remove(const weld::TreeIter& rIter) { m_xTreeView->remove(rIter); }
140  void expand_row(const weld::TreeIter& rIter) { m_xTreeView->expand_row(rIter); }
141  int n_children() const { return m_xTreeView->n_children(); }
142  std::unique_ptr<weld::TreeIter> make_iterator(const weld::TreeIter* pOrig = nullptr) const { return m_xTreeView->make_iterator(pOrig); }
143  bool get_iter_first(weld::TreeIter& rIter) const { return m_xTreeView->get_iter_first(rIter); }
144  // set iter to point to next node, depth first, then sibling
145  bool iter_next(weld::TreeIter& rIter) const { return m_xTreeView->iter_next(rIter); }
146  bool iter_next_sibling(weld::TreeIter& rIter) const { return m_xTreeView->iter_next_sibling(rIter); }
147  bool iter_has_child(const weld::TreeIter& rIter) const { return m_xTreeView->iter_has_child(rIter); }
148  OUString get_text(const weld::TreeIter& rIter) const { return m_xTreeView->get_text(rIter); }
149  OUString get_text(int nPos) const { return m_xTreeView->get_text(nPos); }
150  OUString get_id(const weld::TreeIter& rIter) const { return m_xTreeView->get_id(rIter); }
151  OUString get_id(int nPos) const { return m_xTreeView->get_id(nPos); }
152  bool get_selected(weld::TreeIter* pIter) const { return m_xTreeView->get_selected(pIter); }
153  OUString get_selected_text() const
154  {
155  if (!m_xTreeView->get_selected(m_xScratchIter.get()))
156  return OUString();
157  return m_xTreeView->get_text(*m_xScratchIter);
158  }
159  OUString get_selected_id() const
160  {
161  if (!m_xTreeView->get_selected(m_xScratchIter.get()))
162  return OUString();
163  return m_xTreeView->get_id(*m_xScratchIter);
164  }
165  int get_selected_index() const { return m_xTreeView->get_selected_index(); }
166  void select(const weld::TreeIter& rIter) { m_xTreeView->select(rIter); }
167  void select(int pos) { m_xTreeView->select(pos); }
168  void set_size_request(int nWidth, int nHeight) { m_xTreeView->set_size_request(nWidth, nHeight); }
169  Size get_size_request() const { return m_xTreeView->get_size_request(); }
171 
173 
174  void ClearAll();
175  OUString GetSelectedScriptURI() const;
176  OUString GetHelpText( bool bConsiderParent = true );
177  OUString GetCurCommand() const;
178  OUString GetCurLabel() const;
179 
180  DECL_LINK(QueryTooltip, const weld::TreeIter& rIter, OUString);
181 };
182 
185 {
186  std::unique_ptr<SvxConfigGroupBoxResource_Impl> xImp;
190  css::uno::Reference< css::uno::XComponentContext > m_xContext;
191  css::uno::Reference< css::frame::XFrame > m_xFrame;
192  css::uno::Reference< css::container::XNameAccess > m_xGlobalCategoryInfo;
193  css::uno::Reference< css::container::XNameAccess > m_xModuleCategoryInfo;
194  css::uno::Reference< css::container::XNameAccess > m_xUICmdDescription;
196  std::unique_ptr<weld::TreeView> m_xTreeView;
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  OUString const & docName);
206 
207  void InitModule();
208  void FillScriptList(const css::uno::Reference< css::script::browse::XBrowseNode >& xRootNode,
209  const weld::TreeIter* pParentEntry, bool bCheapChildrenOnDemand);
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 
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); }
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  void SelectMacro(const SfxMacroInfoItem*);
232  void SelectMacro(const OUString&, const OUString&);
233  void SetStylesInfo(SfxStylesInfo_Impl* pStyles);
234 };
235 
237 {
238  OUString m_sDefaultDesc;
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_xCategoryFT;
247  std::unique_ptr<weld::Label> m_xMacronameFT;
248  std::unique_ptr<weld::Label> m_xCommandsFT;
249  std::unique_ptr<weld::Button> m_xOKButton;
250  std::unique_ptr<weld::Button> m_xCancelButton;
251  std::unique_ptr<weld::TextView> m_xDescriptionText;
252 
253  DECL_LINK(ClickHdl, weld::Button&, void);
254  DECL_LINK(SelectHdl, weld::TreeView&, void);
255  DECL_LINK(FunctionDoubleClickHdl, weld::TreeView&, bool);
256 
257  void UpdateUI();
258 
259 public:
260  SvxScriptSelectorDialog(weld::Window* pParent, bool bShowSlots,
261  const css::uno::Reference< css::frame::XFrame >& xFrame);
262  virtual ~SvxScriptSelectorDialog() override;
263 
264  OUString GetScriptURL() const;
265  void SetRunLabel();
266 };
267 
268 #endif
269 
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
weld::TreeView & get_widget()
Definition: cfgutil.hxx:170
DECL_LINK(ExpandingHdl, const weld::TreeIter &, bool)
std::unique_ptr< SvxConfigGroupBoxResource_Impl > xImp
Definition: cfgutil.hxx:186
css::uno::Reference< css::container::XNameAccess > m_xGlobalCategoryInfo
Definition: cfgutil.hxx:192
void SetFunctionListBox(CuiConfigFunctionListBox *pBox)
Definition: cfgutil.hxx:228
std::vector< SfxStyleInfo_Impl > getStyleFamilies() const
Definition: cfgutil.cxx:151
OUString sStyle
Definition: cfgutil.hxx:41
OUString GetHelpText(bool bConsiderParent=true)
Definition: cfgutil.cxx:237
OUString sTooltip
Definition: cfgutil.hxx:95
std::unique_ptr< CuiConfigFunctionListBox > m_xCommands
Definition: cfgutil.hxx:244
void FillScriptList(const css::uno::Reference< css::script::browse::XBrowseNode > &xRootNode, const weld::TreeIter *pParentEntry, bool bCheapChildrenOnDemand)
Definition: cfgutil.cxx:494
OUString GetScriptURL() const
Definition: cfgutil.cxx:1194
css::uno::Reference< css::frame::XModel > m_xDoc
Definition: cfgutil.hxx:61
SfxStylesInfo_Impl * m_pStylesInfo
Definition: cfgutil.hxx:195
css::uno::Reference< css::container::XNameAccess > m_xUICmdDescription
Definition: cfgutil.hxx:194
Size get_size_request() const
Definition: cfgutil.hxx:169
OUString get_id(int nPos) const
Definition: cfgutil.hxx:151
void getLabel4Style(SfxStyleInfo_Impl &aStyle)
Definition: cfgutil.cxx:118
void set_sensitive(bool bSensitive)
Definition: cfgutil.hxx:217
std::unique_ptr< weld::TreeIter > tree_append(const OUString &rId, const OUString &rStr, const weld::TreeIter *pParent=nullptr)
Definition: cfgutil.hxx:122
void append(const OUString &rId, const OUString &rStr, const OUString &rImage, const weld::TreeIter *pParent=nullptr)
Definition: cfgutil.hxx:128
css::uno::Reference< css::container::XNameAccess > m_xModuleCategoryInfo
Definition: cfgutil.hxx:193
bool iter_has_child(const weld::TreeIter &rIter) const
Definition: cfgutil.hxx:147
DECL_LINK(QueryTooltip, const weld::TreeIter &rIter, OUString)
OUString MapCommand2UIName(const OUString &sCommand)
Definition: cfgutil.cxx:775
OUString get_text(int nPos) const
Definition: cfgutil.hxx:149
OUString get_selected_text() const
Definition: cfgutil.hxx:153
DECL_LINK(ClickHdl, weld::Button &, void)
std::unique_ptr< CuiConfigGroupListBox > m_xCategories
Definition: cfgutil.hxx:243
void select(int pos)
Definition: cfgutil.hxx:167
int n_children() const
Definition: cfgutil.hxx:141
SfxGroupInfoArr_Impl aArr
Definition: cfgutil.hxx:188
OUString sFamily
Definition: cfgutil.hxx:40
OUString GetCurLabel() const
Definition: cfgutil.cxx:265
void set_size_request(int nWidth, int nHeight)
Definition: cfgutil.hxx:219
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:615
std::unique_ptr< weld::TreeView > m_xTreeView
Definition: cfgutil.hxx:196
OUString sLabel
Definition: cfgutil.hxx:43
bool get_selected(weld::TreeIter *pIter) const
Definition: cfgutil.hxx:152
SfxStylesInfo_Impl m_aStylesInfo
Definition: cfgutil.hxx:239
void connect_changed(const Link< weld::TreeView &, void > &rLink)
Definition: cfgutil.hxx:114
OUString get_text(const weld::TreeIter &rIter) const
Definition: cfgutil.hxx:148
SfxGroupInfo_Impl(SfxCfgKind n, sal_uInt16 nr, void *pObj=nullptr)
Definition: cfgutil.hxx:97
bool iter_next(weld::TreeIter &rIter) const
Definition: cfgutil.hxx:145
void select(const weld::TreeIter &rIter)
Definition: cfgutil.hxx:166
void set_size_request(int nWidth, int nHeight)
Definition: cfgutil.hxx:168
void connect_changed(const Link< weld::TreeView &, void > &rLink)
Definition: cfgutil.hxx:218
std::unique_ptr< weld::Label > m_xLibraryFT
Definition: cfgutil.hxx:245
void append(const OUString &rId, const OUString &rStr, const css::uno::Reference< css::graphic::XGraphic > &rImage, const weld::TreeIter *pParent=nullptr)
Definition: cfgutil.hxx:132
OUString sHelpText
Definition: cfgutil.hxx:94
std::vector< SfxStyleInfo_Impl > getStyles(const OUString &sFamily)
Definition: cfgutil.cxx:193
virtual ~SvxScriptSelectorDialog() override
Definition: cfgutil.cxx:1123
SfxCfgKind nKind
Definition: cfgutil.hxx:89
css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: cfgutil.hxx:190
OUString GetCurCommand() const
Definition: cfgutil.cxx:257
void scroll_to_row(int pos)
Definition: cfgutil.hxx:138
OUString GetSelectedScriptURI() const
Definition: cfgutil.cxx:331
SfxCfgKind
Definition: cfgutil.hxx:77
OUString get_selected_id() const
Definition: cfgutil.hxx:159
SfxStyleInfo_Impl(const SfxStyleInfo_Impl &rCopy)
Definition: cfgutil.hxx:48
sal_uInt16 nUniqueID
Definition: cfgutil.hxx:90
void SetStylesInfo(SfxStylesInfo_Impl *pStyles)
Definition: cfgutil.cxx:359
OUString m_sModuleLongName
Definition: cfgutil.hxx:189
OUString sCommand
Definition: cfgutil.hxx:42
void init(const OUString &rModuleName, const css::uno::Reference< css::frame::XModel > &xModel)
Definition: cfgutil.cxx:65
void connect_row_activated(const Link< weld::TreeView &, bool > &rLink)
Definition: cfgutil.hxx:115
std::unique_ptr< weld::TreeIter > make_iterator(const weld::TreeIter *pOrig=nullptr) const
Definition: cfgutil.hxx:142
std::vector< std::unique_ptr< SfxGroupInfo_Impl > > SfxGroupInfoArr_Impl
Definition: cfgutil.hxx:101
SvxScriptSelectorDialog(weld::Window *pParent, bool bShowSlots, const css::uno::Reference< css::frame::XFrame > &xFrame)
Definition: cfgutil.cxx:1066
std::unique_ptr< weld::Label > m_xMacronameFT
Definition: cfgutil.hxx:247
void FillFunctionsList(const css::uno::Sequence< css::frame::DispatchInformation > &xCommands)
Definition: cfgutil.cxx:597
SfxGroupInfoArr_Impl aArr
Definition: cfgutil.hxx:106
CuiConfigFunctionListBox(std::unique_ptr< weld::TreeView > xTreeView)
Definition: cfgutil.cxx:275
OUString sCommand
Definition: cfgutil.hxx:92
static css::uno::Reference< css::uno::XInterface > getDocumentModel(css::uno::Reference< css::uno::XComponentContext > const &xCtx, OUString const &docName)
Definition: cfgutil.cxx:748
std::unique_ptr< weld::Label > m_xCommandsFT
Definition: cfgutil.hxx:248
bool iter_next_sibling(weld::TreeIter &rIter) const
Definition: cfgutil.hxx:146
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:686
void expand_row(const weld::TreeIter &rIter)
Definition: cfgutil.hxx:140
std::unique_ptr< weld::Label > m_xDialogDescription
Definition: cfgutil.hxx:242
std::unique_ptr< weld::TreeIter > m_xScratchIter
Definition: cfgutil.hxx:109
CuiConfigFunctionListBox * m_pFunctionListBox
Definition: cfgutil.hxx:187
static bool parseStyleCommand(SfxStyleInfo_Impl &aStyle)
Definition: cfgutil.cxx:85
OUString sLabel
Definition: cfgutil.hxx:93
OUString get_id(const weld::TreeIter &rIter) const
Definition: cfgutil.hxx:150
static OUString generateCommand(const OUString &sFamily, const OUString &sStyle)
Definition: cfgutil.cxx:77
OUString m_aModuleName
Definition: cfgutil.hxx:60
std::unique_ptr< weld::Button > m_xOKButton
Definition: cfgutil.hxx:249
bool get_iter_first(weld::TreeIter &rIter) const
Definition: cfgutil.hxx:143
void SelectMacro(const SfxMacroInfoItem *)
Definition: cfgutil.cxx:983
std::unique_ptr< weld::Label > m_xCategoryFT
Definition: cfgutil.hxx:246
weld::TreeView & get_widget()
Definition: cfgutil.hxx:220
std::unique_ptr< weld::Button > m_xCancelButton
Definition: cfgutil.hxx:250
CuiConfigGroupListBox(std::unique_ptr< weld::TreeView > xTreeView)
Definition: cfgutil.cxx:416
int get_selected_index() const
Definition: cfgutil.hxx:165
css::uno::Reference< css::frame::XFrame > m_xFrame
Definition: cfgutil.hxx:191
std::unique_ptr< weld::TreeView > m_xTreeView
Definition: cfgutil.hxx:108
sal_uInt16 nPos
void set_sensitive(bool bSensitive)
Definition: cfgutil.hxx:113
std::unique_ptr< weld::TextView > m_xDescriptionText
Definition: cfgutil.hxx:251
void append(const OUString &rId, const OUString &rStr, const weld::TreeIter *pParent=nullptr)
Definition: cfgutil.hxx:118