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 
96  SfxGroupInfo_Impl( SfxCfgKind n, sal_uInt16 nr, void* pObj = nullptr ) :
97  nKind( n ), nUniqueID( nr ), pObject( pObj ) {}
98 };
99 
100 typedef std::vector<std::unique_ptr<SfxGroupInfo_Impl> > SfxGroupInfoArr_Impl;
101 
103 {
104  friend class CuiConfigGroupListBox;
106 
107  std::unique_ptr<weld::TreeView> m_xTreeView;
108  std::unique_ptr<weld::TreeIter> m_xScratchIter;
109 
110 public:
111  CuiConfigFunctionListBox(std::unique_ptr<weld::TreeView> xTreeView);
112  void set_sensitive(bool bSensitive) { m_xTreeView->set_sensitive(bSensitive); }
113  void connect_changed(const Link<weld::TreeView&, void>& rLink) { m_xTreeView->connect_changed(rLink); }
114  void connect_row_activated(const Link<weld::TreeView&, bool>& rLink) { m_xTreeView->connect_row_activated(rLink); }
115  void freeze() { m_xTreeView->freeze(); }
116  void thaw() { m_xTreeView->thaw(); }
117  void append(const OUString& rId, const OUString& rStr, const weld::TreeIter* pParent = nullptr)
118  {
119  m_xTreeView->insert(pParent, -1, &rStr, &rId, nullptr, nullptr, nullptr, false, nullptr);
120  }
121  std::unique_ptr<weld::TreeIter> tree_append(const OUString& rId, const OUString& rStr, const weld::TreeIter* pParent = nullptr)
122  {
123  std::unique_ptr<weld::TreeIter> xIter(m_xTreeView->make_iterator());
124  m_xTreeView->insert(pParent, -1, &rStr, &rId, nullptr, nullptr, nullptr, false, xIter.get());
125  return xIter;
126  }
127  void append(const OUString& rId, const OUString& rStr, const OUString& rImage, const weld::TreeIter* pParent = nullptr)
128  {
129  m_xTreeView->insert(pParent, -1, &rStr, &rId, nullptr, nullptr, &rImage, false, nullptr);
130  }
131  void append(const OUString& rId, const OUString& rStr, const css::uno::Reference<css::graphic::XGraphic>& rImage, const weld::TreeIter* pParent = nullptr)
132  {
133  m_xTreeView->insert(pParent, -1, &rStr, &rId, nullptr, nullptr, nullptr, false, m_xScratchIter.get());
134  m_xTreeView->set_image(*m_xScratchIter, rImage, -1);
135  }
136  void remove(int nPos) { m_xTreeView->remove(nPos); }
137  void scroll_to_row(int pos) { m_xTreeView->scroll_to_row(pos); }
138  void remove(const weld::TreeIter& rIter) { m_xTreeView->remove(rIter); }
139  void expand_row(const weld::TreeIter& rIter) { m_xTreeView->expand_row(rIter); }
140  int n_children() const { return m_xTreeView->n_children(); }
141  std::unique_ptr<weld::TreeIter> make_iterator(const weld::TreeIter* pOrig = nullptr) const { return m_xTreeView->make_iterator(pOrig); }
142  bool get_iter_first(weld::TreeIter& rIter) const { return m_xTreeView->get_iter_first(rIter); }
143  // set iter to point to next node, depth first, then sibling
144  bool iter_next(weld::TreeIter& rIter) const { return m_xTreeView->iter_next(rIter); }
145  bool iter_next_sibling(weld::TreeIter& rIter) const { return m_xTreeView->iter_next_sibling(rIter); }
146  bool iter_has_child(const weld::TreeIter& rIter) const { return m_xTreeView->iter_has_child(rIter); }
147  OUString get_text(const weld::TreeIter& rIter) const { return m_xTreeView->get_text(rIter); }
148  OUString get_text(int nPos) const { return m_xTreeView->get_text(nPos); }
149  OUString get_id(const weld::TreeIter& rIter) const { return m_xTreeView->get_id(rIter); }
150  OUString get_id(int nPos) const { return m_xTreeView->get_id(nPos); }
151  bool get_selected(weld::TreeIter* pIter) const { return m_xTreeView->get_selected(pIter); }
152  OUString get_selected_text() const
153  {
154  if (!m_xTreeView->get_selected(m_xScratchIter.get()))
155  return OUString();
156  return m_xTreeView->get_text(*m_xScratchIter);
157  }
158  OUString get_selected_id() const
159  {
160  if (!m_xTreeView->get_selected(m_xScratchIter.get()))
161  return OUString();
162  return m_xTreeView->get_id(*m_xScratchIter);
163  }
164  int get_selected_index() const { return m_xTreeView->get_selected_index(); }
165  void select(const weld::TreeIter& rIter) { m_xTreeView->select(rIter); }
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 
182 {
183  std::unique_ptr<SvxConfigGroupBoxResource_Impl> xImp;
187  css::uno::Reference< css::uno::XComponentContext > m_xContext;
188  css::uno::Reference< css::frame::XFrame > m_xFrame;
189  css::uno::Reference< css::container::XNameAccess > m_xGlobalCategoryInfo;
190  css::uno::Reference< css::container::XNameAccess > m_xModuleCategoryInfo;
191  css::uno::Reference< css::container::XNameAccess > m_xUICmdDescription;
193  std::unique_ptr<weld::TreeView> m_xTreeView;
194 
195  static OUString GetImage(
196  const css::uno::Reference< css::script::browse::XBrowseNode >& node,
197  css::uno::Reference< css::uno::XComponentContext > const & xCtx,
198  bool bIsRootNode);
199 
200  static css::uno::Reference< css::uno::XInterface > getDocumentModel(
201  css::uno::Reference< css::uno::XComponentContext > const & xCtx,
202  OUString const & docName);
203 
204  void InitModule();
205  void FillScriptList(const css::uno::Reference< css::script::browse::XBrowseNode >& xRootNode,
206  const weld::TreeIter* pParentEntry, bool bCheapChildrenOnDemand);
207  void FillFunctionsList(const css::uno::Sequence< css::frame::DispatchInformation >& xCommands);
208  OUString MapCommand2UIName(const OUString& sCommand);
209 
210  DECL_LINK(ExpandingHdl, const weld::TreeIter&, bool);
211 
212 public:
213  CuiConfigGroupListBox(std::unique_ptr<weld::TreeView> xTreeView);
214  void set_sensitive(bool bSensitive) { m_xTreeView->set_sensitive(bSensitive); }
215  void connect_changed(const Link<weld::TreeView&, void>& rLink) { m_xTreeView->connect_changed(rLink); }
216  void set_size_request(int nWidth, int nHeight) { m_xTreeView->set_size_request(nWidth, nHeight); }
219  void ClearAll();
220 
221  void Init(const css::uno::Reference< css::uno::XComponentContext >& xContext,
222  const css::uno::Reference< css::frame::XFrame >& xFrame,
223  const OUString& sModuleLongName,
224  bool bEventMode);
226  { m_pFunctionListBox = pBox; }
227  void GroupSelected();
228  void SelectMacro(const SfxMacroInfoItem*);
229  void SelectMacro(const OUString&, const OUString&);
230  void SetStylesInfo(SfxStylesInfo_Impl* pStyles);
231 };
232 
234 {
235  OUString m_sDefaultDesc;
238 
239  std::unique_ptr<weld::Label> m_xDialogDescription;
240  std::unique_ptr<CuiConfigGroupListBox> m_xCategories;
241  std::unique_ptr<CuiConfigFunctionListBox> m_xCommands;
242  std::unique_ptr<weld::Label> m_xLibraryFT;
243  std::unique_ptr<weld::Label> m_xCategoryFT;
244  std::unique_ptr<weld::Label> m_xMacronameFT;
245  std::unique_ptr<weld::Label> m_xCommandsFT;
246  std::unique_ptr<weld::Button> m_xOKButton;
247  std::unique_ptr<weld::Button> m_xCancelButton;
248  std::unique_ptr<weld::TextView> m_xDescriptionText;
249 
250  DECL_LINK(ClickHdl, weld::Button&, void);
251  DECL_LINK(SelectHdl, weld::TreeView&, void);
252  DECL_LINK(FunctionDoubleClickHdl, weld::TreeView&, bool);
253 
254  void UpdateUI();
255 
256 public:
257  SvxScriptSelectorDialog(weld::Window* pParent, bool bShowSlots,
258  const css::uno::Reference< css::frame::XFrame >& xFrame);
259  virtual ~SvxScriptSelectorDialog() override;
260 
261  OUString GetScriptURL() const;
262  void SetRunLabel();
263 };
264 
265 #endif
266 
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
weld::TreeView & get_widget()
Definition: cfgutil.hxx:169
DECL_LINK(ExpandingHdl, const weld::TreeIter &, bool)
std::unique_ptr< SvxConfigGroupBoxResource_Impl > xImp
Definition: cfgutil.hxx:183
css::uno::Reference< css::container::XNameAccess > m_xGlobalCategoryInfo
Definition: cfgutil.hxx:189
void SetFunctionListBox(CuiConfigFunctionListBox *pBox)
Definition: cfgutil.hxx:225
std::vector< SfxStyleInfo_Impl > getStyleFamilies() const
Definition: cfgutil.cxx:152
OUString sStyle
Definition: cfgutil.hxx:41
OUString GetHelpText(bool bConsiderParent=true)
Definition: cfgutil.cxx:238
std::unique_ptr< CuiConfigFunctionListBox > m_xCommands
Definition: cfgutil.hxx:241
void FillScriptList(const css::uno::Reference< css::script::browse::XBrowseNode > &xRootNode, const weld::TreeIter *pParentEntry, bool bCheapChildrenOnDemand)
Definition: cfgutil.cxx:483
OUString GetScriptURL() const
Definition: cfgutil.cxx:1181
css::uno::Reference< css::frame::XModel > m_xDoc
Definition: cfgutil.hxx:61
SfxStylesInfo_Impl * m_pStylesInfo
Definition: cfgutil.hxx:192
css::uno::Reference< css::container::XNameAccess > m_xUICmdDescription
Definition: cfgutil.hxx:191
Size get_size_request() const
Definition: cfgutil.hxx:168
OUString get_id(int nPos) const
Definition: cfgutil.hxx:150
void getLabel4Style(SfxStyleInfo_Impl &aStyle)
Definition: cfgutil.cxx:119
void set_sensitive(bool bSensitive)
Definition: cfgutil.hxx:214
std::unique_ptr< weld::TreeIter > tree_append(const OUString &rId, const OUString &rStr, const weld::TreeIter *pParent=nullptr)
Definition: cfgutil.hxx:121
void append(const OUString &rId, const OUString &rStr, const OUString &rImage, const weld::TreeIter *pParent=nullptr)
Definition: cfgutil.hxx:127
css::uno::Reference< css::container::XNameAccess > m_xModuleCategoryInfo
Definition: cfgutil.hxx:190
bool iter_has_child(const weld::TreeIter &rIter) const
Definition: cfgutil.hxx:146
OUString MapCommand2UIName(const OUString &sCommand)
Definition: cfgutil.cxx:762
OUString get_text(int nPos) const
Definition: cfgutil.hxx:148
OUString get_selected_text() const
Definition: cfgutil.hxx:152
DECL_LINK(ClickHdl, weld::Button &, void)
std::unique_ptr< CuiConfigGroupListBox > m_xCategories
Definition: cfgutil.hxx:240
void select(int pos)
Definition: cfgutil.hxx:166
int n_children() const
Definition: cfgutil.hxx:140
SfxGroupInfoArr_Impl aArr
Definition: cfgutil.hxx:185
OUString sFamily
Definition: cfgutil.hxx:40
OUString GetCurLabel() const
Definition: cfgutil.cxx:266
void set_size_request(int nWidth, int nHeight)
Definition: cfgutil.hxx:216
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:602
std::unique_ptr< weld::TreeView > m_xTreeView
Definition: cfgutil.hxx:193
OUString sLabel
Definition: cfgutil.hxx:43
bool get_selected(weld::TreeIter *pIter) const
Definition: cfgutil.hxx:151
SfxStylesInfo_Impl m_aStylesInfo
Definition: cfgutil.hxx:236
void connect_changed(const Link< weld::TreeView &, void > &rLink)
Definition: cfgutil.hxx:113
OUString get_text(const weld::TreeIter &rIter) const
Definition: cfgutil.hxx:147
SfxGroupInfo_Impl(SfxCfgKind n, sal_uInt16 nr, void *pObj=nullptr)
Definition: cfgutil.hxx:96
bool iter_next(weld::TreeIter &rIter) const
Definition: cfgutil.hxx:144
void select(const weld::TreeIter &rIter)
Definition: cfgutil.hxx:165
void set_size_request(int nWidth, int nHeight)
Definition: cfgutil.hxx:167
void connect_changed(const Link< weld::TreeView &, void > &rLink)
Definition: cfgutil.hxx:215
std::unique_ptr< weld::Label > m_xLibraryFT
Definition: cfgutil.hxx:242
void append(const OUString &rId, const OUString &rStr, const css::uno::Reference< css::graphic::XGraphic > &rImage, const weld::TreeIter *pParent=nullptr)
Definition: cfgutil.hxx:131
OUString sHelpText
Definition: cfgutil.hxx:94
std::vector< SfxStyleInfo_Impl > getStyles(const OUString &sFamily)
Definition: cfgutil.cxx:194
virtual ~SvxScriptSelectorDialog() override
Definition: cfgutil.cxx:1110
SfxCfgKind nKind
Definition: cfgutil.hxx:89
css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: cfgutil.hxx:187
OUString GetCurCommand() const
Definition: cfgutil.cxx:258
void scroll_to_row(int pos)
Definition: cfgutil.hxx:137
OUString GetSelectedScriptURI() const
Definition: cfgutil.cxx:320
SfxCfgKind
Definition: cfgutil.hxx:77
OUString get_selected_id() const
Definition: cfgutil.hxx:158
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:348
OUString m_sModuleLongName
Definition: cfgutil.hxx:186
OUString sCommand
Definition: cfgutil.hxx:42
void init(const OUString &rModuleName, const css::uno::Reference< css::frame::XModel > &xModel)
Definition: cfgutil.cxx:66
void connect_row_activated(const Link< weld::TreeView &, bool > &rLink)
Definition: cfgutil.hxx:114
std::unique_ptr< weld::TreeIter > make_iterator(const weld::TreeIter *pOrig=nullptr) const
Definition: cfgutil.hxx:141
std::vector< std::unique_ptr< SfxGroupInfo_Impl > > SfxGroupInfoArr_Impl
Definition: cfgutil.hxx:100
SvxScriptSelectorDialog(weld::Window *pParent, bool bShowSlots, const css::uno::Reference< css::frame::XFrame > &xFrame)
Definition: cfgutil.cxx:1053
std::unique_ptr< weld::Label > m_xMacronameFT
Definition: cfgutil.hxx:244
void FillFunctionsList(const css::uno::Sequence< css::frame::DispatchInformation > &xCommands)
Definition: cfgutil.cxx:587
SfxGroupInfoArr_Impl aArr
Definition: cfgutil.hxx:105
CuiConfigFunctionListBox(std::unique_ptr< weld::TreeView > xTreeView)
Definition: cfgutil.cxx:276
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:735
std::unique_ptr< weld::Label > m_xCommandsFT
Definition: cfgutil.hxx:245
bool iter_next_sibling(weld::TreeIter &rIter) const
Definition: cfgutil.hxx:145
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:673
void expand_row(const weld::TreeIter &rIter)
Definition: cfgutil.hxx:139
std::unique_ptr< weld::Label > m_xDialogDescription
Definition: cfgutil.hxx:239
std::unique_ptr< weld::TreeIter > m_xScratchIter
Definition: cfgutil.hxx:108
CuiConfigFunctionListBox * m_pFunctionListBox
Definition: cfgutil.hxx:184
static bool parseStyleCommand(SfxStyleInfo_Impl &aStyle)
Definition: cfgutil.cxx:86
OUString sLabel
Definition: cfgutil.hxx:93
OUString get_id(const weld::TreeIter &rIter) const
Definition: cfgutil.hxx:149
static OUString generateCommand(const OUString &sFamily, const OUString &sStyle)
Definition: cfgutil.cxx:78
OUString m_aModuleName
Definition: cfgutil.hxx:60
std::unique_ptr< weld::Button > m_xOKButton
Definition: cfgutil.hxx:246
bool get_iter_first(weld::TreeIter &rIter) const
Definition: cfgutil.hxx:142
void SelectMacro(const SfxMacroInfoItem *)
Definition: cfgutil.cxx:970
std::unique_ptr< weld::Label > m_xCategoryFT
Definition: cfgutil.hxx:243
weld::TreeView & get_widget()
Definition: cfgutil.hxx:217
std::unique_ptr< weld::Button > m_xCancelButton
Definition: cfgutil.hxx:247
CuiConfigGroupListBox(std::unique_ptr< weld::TreeView > xTreeView)
Definition: cfgutil.cxx:405
sal_Int32 nPos
int get_selected_index() const
Definition: cfgutil.hxx:164
css::uno::Reference< css::frame::XFrame > m_xFrame
Definition: cfgutil.hxx:188
std::unique_ptr< weld::TreeView > m_xTreeView
Definition: cfgutil.hxx:107
void set_sensitive(bool bSensitive)
Definition: cfgutil.hxx:112
std::unique_ptr< weld::TextView > m_xDescriptionText
Definition: cfgutil.hxx:248
void append(const OUString &rId, const OUString &rStr, const weld::TreeIter *pParent=nullptr)
Definition: cfgutil.hxx:117