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 <rtl/ustring.hxx>
24 
25 #include <com/sun/star/frame/DispatchInformation.hpp>
26 #include <com/sun/star/frame/XModel.hpp>
27 #include <com/sun/star/frame/XFrame.hpp>
28 #include <com/sun/star/container/XNameAccess.hpp>
29 #include <com/sun/star/script/browse/XBrowseNode.hpp>
30 #include <com/sun/star/uno/XComponentContext.hpp>
31 #include <vcl/weld.hxx>
32 
33 class Button;
34 class SaveInData;
35 class SfxMacroInfoItem;
36 
38 {
39  OUString sFamily;
40  OUString sStyle;
41  OUString sCommand;
42  OUString sLabel;
43 
45  {}
46 
48  {
49  sFamily = rCopy.sFamily;
50  sStyle = rCopy.sStyle;
51  sCommand = rCopy.sCommand;
52  sLabel = rCopy.sLabel;
53  }
54 };
55 
57 {
58 private:
59  OUString m_aModuleName;
60  css::uno::Reference< css::frame::XModel > m_xDoc;
61 
62 public:
63 
65  void init(const OUString& rModuleName, const css::uno::Reference< css::frame::XModel >& xModel);
66 
67  static bool parseStyleCommand(SfxStyleInfo_Impl& aStyle);
68  void getLabel4Style(SfxStyleInfo_Impl& aStyle);
69 
70  std::vector< SfxStyleInfo_Impl > getStyleFamilies() const;
71  std::vector< SfxStyleInfo_Impl > getStyles(const OUString& sFamily);
72 
73  static OUString generateCommand(const OUString& sFamily, const OUString& sStyle);
74 };
75 
76 enum class SfxCfgKind
77 {
78  GROUP_FUNCTION = 1,
79  FUNCTION_SLOT = 2,
81  FUNCTION_SCRIPT = 4,
82  GROUP_STYLES = 5,
84 };
85 
87 {
89  sal_uInt16 nUniqueID;
90  void* pObject;
91  OUString sCommand;
92  OUString sLabel;
93  OUString sHelpText;
94  OUString sTooltip;
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_popup_menu(const Link<const CommandEvent&, bool>& rLink) { m_xTreeView->connect_popup_menu(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, 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, 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, false, m_xScratchIter.get());
131  m_xTreeView->set_image(*m_xScratchIter, rImage);
132  }
133  void append(const OUString& rId, const OUString& rStr, const css::uno::Reference<css::graphic::XGraphic>& rImage, const weld::TreeIter* pParent = nullptr)
134  {
135  m_xTreeView->insert(pParent, -1, &rStr, &rId, nullptr, nullptr, false, m_xScratchIter.get());
136  m_xTreeView->set_image(*m_xScratchIter, rImage, -1);
137  }
138  void remove(int nPos) { m_xTreeView->remove(nPos); }
139  void scroll_to_row(int pos) { m_xTreeView->scroll_to_row(pos); }
140  void remove(const weld::TreeIter& rIter) { m_xTreeView->remove(rIter); }
141  void expand_row(const weld::TreeIter& rIter) { m_xTreeView->expand_row(rIter); }
142  int n_children() const { return m_xTreeView->n_children(); }
143  std::unique_ptr<weld::TreeIter> make_iterator(const weld::TreeIter* pOrig = nullptr) const { return m_xTreeView->make_iterator(pOrig); }
144  bool iter_has_child(const weld::TreeIter& rIter) const { return m_xTreeView->iter_has_child(rIter); }
145  OUString get_text(int nPos) const { return m_xTreeView->get_text(nPos); }
146  OUString get_id(const weld::TreeIter& rIter) const { return m_xTreeView->get_id(rIter); }
147  bool get_selected(weld::TreeIter* pIter) const { return m_xTreeView->get_selected(pIter); }
148  OUString get_selected_text() const
149  {
150  if (!m_xTreeView->get_selected(m_xScratchIter.get()))
151  return OUString();
152  return m_xTreeView->get_text(*m_xScratchIter);
153  }
154  OUString get_selected_id() const
155  {
156  if (!m_xTreeView->get_selected(m_xScratchIter.get()))
157  return OUString();
158  return m_xTreeView->get_id(*m_xScratchIter);
159  }
160  void select(int pos) { m_xTreeView->select(pos); }
161  void set_size_request(int nWidth, int nHeight) { m_xTreeView->set_size_request(nWidth, nHeight); }
162  Size get_size_request() const { return m_xTreeView->get_size_request(); }
164 
166 
167  void ClearAll();
168  OUString GetSelectedScriptURI() const;
169  OUString GetHelpText( bool bConsiderParent = true );
170  OUString GetCurCommand() const;
171  OUString GetCurLabel() const;
172 
173  DECL_LINK(QueryTooltip, const weld::TreeIter& rIter, OUString);
174 };
175 
178 {
179  std::unique_ptr<SvxConfigGroupBoxResource_Impl> xImp;
183  css::uno::Reference< css::uno::XComponentContext > m_xContext;
184  css::uno::Reference< css::frame::XFrame > m_xFrame;
185  css::uno::Reference< css::container::XNameAccess > m_xGlobalCategoryInfo;
186  css::uno::Reference< css::container::XNameAccess > m_xModuleCategoryInfo;
187  css::uno::Reference< css::container::XNameAccess > m_xUICmdDescription;
189  std::unique_ptr<weld::TreeView> m_xTreeView;
190  std::unique_ptr<weld::TreeIter> m_xScratchIter;
191 
192  static OUString GetImage(
193  const css::uno::Reference< css::script::browse::XBrowseNode >& node,
194  css::uno::Reference< css::uno::XComponentContext > const & xCtx,
195  bool bIsRootNode);
196 
197  static css::uno::Reference< css::uno::XInterface > getDocumentModel(
198  css::uno::Reference< css::uno::XComponentContext > const & xCtx,
199  OUString const & docName);
200 
201  void InitModule();
202  void FillScriptList(const css::uno::Reference< css::script::browse::XBrowseNode >& xRootNode,
203  const weld::TreeIter* pParentEntry, bool bCheapChildrenOnDemand);
204  void FillFunctionsList(const css::uno::Sequence< css::frame::DispatchInformation >& xCommands);
205  OUString MapCommand2UIName(const OUString& sCommand);
206 
207  DECL_LINK(ExpandingHdl, const weld::TreeIter&, bool);
208 
209 public:
210  CuiConfigGroupListBox(std::unique_ptr<weld::TreeView> xTreeView);
211  void set_sensitive(bool bSensitive) { m_xTreeView->set_sensitive(bSensitive); }
212  void connect_changed(const Link<weld::TreeView&, void>& rLink) { m_xTreeView->connect_changed(rLink); }
213  void set_size_request(int nWidth, int nHeight) { m_xTreeView->set_size_request(nWidth, nHeight); }
216  void ClearAll();
217 
218  void Init(const css::uno::Reference< css::uno::XComponentContext >& xContext,
219  const css::uno::Reference< css::frame::XFrame >& xFrame,
220  const OUString& sModuleLongName,
221  bool bEventMode);
223  { m_pFunctionListBox = pBox; }
224  void GroupSelected();
225  void SelectMacro(const SfxMacroInfoItem*);
226  void SelectMacro(const OUString&, const OUString&);
227  void SetStylesInfo(SfxStylesInfo_Impl* pStyles);
228 };
229 
231 {
232  OUString m_sDefaultDesc;
234 
235  std::unique_ptr<weld::Label> m_xDialogDescription;
236  std::unique_ptr<CuiConfigGroupListBox> m_xCategories;
237  std::unique_ptr<CuiConfigFunctionListBox> m_xCommands;
238  std::unique_ptr<weld::Label> m_xLibraryFT;
239  std::unique_ptr<weld::Label> m_xCategoryFT;
240  std::unique_ptr<weld::Label> m_xMacronameFT;
241  std::unique_ptr<weld::Label> m_xCommandsFT;
242  std::unique_ptr<weld::Button> m_xOKButton;
243  std::unique_ptr<weld::Button> m_xCancelButton;
244  std::unique_ptr<weld::TextView> m_xDescriptionText;
245 
246  DECL_LINK(ClickHdl, weld::Button&, void);
247  DECL_LINK(SelectHdl, weld::TreeView&, void);
248  DECL_LINK(FunctionDoubleClickHdl, weld::TreeView&, bool);
249  DECL_LINK(ContextMenuHdl, const CommandEvent&, bool);
250 
251  void UpdateUI();
252 
253 public:
255  const css::uno::Reference< css::frame::XFrame >& xFrame);
256  virtual ~SvxScriptSelectorDialog() override;
257 
258  OUString GetScriptURL() const;
259  void SetRunLabel();
260 };
261 
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
weld::TreeView & get_widget()
Definition: cfgutil.hxx:163
DECL_LINK(ExpandingHdl, const weld::TreeIter &, bool)
std::unique_ptr< SvxConfigGroupBoxResource_Impl > xImp
Definition: cfgutil.hxx:179
css::uno::Reference< css::container::XNameAccess > m_xGlobalCategoryInfo
Definition: cfgutil.hxx:185
void SetFunctionListBox(CuiConfigFunctionListBox *pBox)
Definition: cfgutil.hxx:222
std::vector< SfxStyleInfo_Impl > getStyleFamilies() const
Definition: cfgutil.cxx:152
OUString sStyle
Definition: cfgutil.hxx:40
OUString GetHelpText(bool bConsiderParent=true)
Definition: cfgutil.cxx:238
OUString sTooltip
Definition: cfgutil.hxx:94
std::unique_ptr< CuiConfigFunctionListBox > m_xCommands
Definition: cfgutil.hxx:237
void FillScriptList(const css::uno::Reference< css::script::browse::XBrowseNode > &xRootNode, const weld::TreeIter *pParentEntry, bool bCheapChildrenOnDemand)
Definition: cfgutil.cxx:506
OUString GetScriptURL() const
Definition: cfgutil.cxx:1219
css::uno::Reference< css::frame::XModel > m_xDoc
Definition: cfgutil.hxx:60
SfxStylesInfo_Impl * m_pStylesInfo
Definition: cfgutil.hxx:188
css::uno::Reference< css::container::XNameAccess > m_xUICmdDescription
Definition: cfgutil.hxx:187
Size get_size_request() const
Definition: cfgutil.hxx:162
void getLabel4Style(SfxStyleInfo_Impl &aStyle)
Definition: cfgutil.cxx:119
void set_sensitive(bool bSensitive)
Definition: cfgutil.hxx:211
std::unique_ptr< weld::TreeIter > m_xScratchIter
Definition: cfgutil.hxx:190
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:186
bool iter_has_child(const weld::TreeIter &rIter) const
Definition: cfgutil.hxx:144
DECL_LINK(QueryTooltip, const weld::TreeIter &rIter, OUString)
OUString MapCommand2UIName(const OUString &sCommand)
Definition: cfgutil.cxx:787
OUString get_text(int nPos) const
Definition: cfgutil.hxx:145
OUString get_selected_text() const
Definition: cfgutil.hxx:148
DECL_LINK(ClickHdl, weld::Button &, void)
std::unique_ptr< CuiConfigGroupListBox > m_xCategories
Definition: cfgutil.hxx:236
void select(int pos)
Definition: cfgutil.hxx:160
int n_children() const
Definition: cfgutil.hxx:142
SfxGroupInfoArr_Impl aArr
Definition: cfgutil.hxx:181
OUString sFamily
Definition: cfgutil.hxx:39
OUString GetCurLabel() const
Definition: cfgutil.cxx:266
void set_size_request(int nWidth, int nHeight)
Definition: cfgutil.hxx:213
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
std::unique_ptr< weld::TreeView > m_xTreeView
Definition: cfgutil.hxx:189
OUString sLabel
Definition: cfgutil.hxx:42
bool get_selected(weld::TreeIter *pIter) const
Definition: cfgutil.hxx:147
SvxScriptSelectorDialog(weld::Window *pParent, const css::uno::Reference< css::frame::XFrame > &xFrame)
Definition: cfgutil.cxx:1078
SfxStylesInfo_Impl m_aStylesInfo
Definition: cfgutil.hxx:233
void connect_changed(const Link< weld::TreeView &, void > &rLink)
Definition: cfgutil.hxx:113
SfxGroupInfo_Impl(SfxCfgKind n, sal_uInt16 nr, void *pObj=nullptr)
Definition: cfgutil.hxx:96
void set_size_request(int nWidth, int nHeight)
Definition: cfgutil.hxx:161
void connect_changed(const Link< weld::TreeView &, void > &rLink)
Definition: cfgutil.hxx:212
std::unique_ptr< weld::Label > m_xLibraryFT
Definition: cfgutil.hxx:238
void append(const OUString &rId, const OUString &rStr, const css::uno::Reference< css::graphic::XGraphic > &rImage, const weld::TreeIter *pParent=nullptr)
Definition: cfgutil.hxx:133
OUString sHelpText
Definition: cfgutil.hxx:93
std::vector< SfxStyleInfo_Impl > getStyles(const OUString &sFamily)
Definition: cfgutil.cxx:194
virtual ~SvxScriptSelectorDialog() override
Definition: cfgutil.cxx:1130
SfxCfgKind nKind
Definition: cfgutil.hxx:88
css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: cfgutil.hxx:183
OUString GetCurCommand() const
Definition: cfgutil.cxx:258
void scroll_to_row(int pos)
Definition: cfgutil.hxx:139
OUString GetSelectedScriptURI() const
Definition: cfgutil.cxx:332
SfxCfgKind
Definition: cfgutil.hxx:76
OUString get_selected_id() const
Definition: cfgutil.hxx:154
SfxStyleInfo_Impl(const SfxStyleInfo_Impl &rCopy)
Definition: cfgutil.hxx:47
sal_uInt16 nUniqueID
Definition: cfgutil.hxx:89
void SetStylesInfo(SfxStylesInfo_Impl *pStyles)
Definition: cfgutil.cxx:360
OUString m_sModuleLongName
Definition: cfgutil.hxx:182
OUString sCommand
Definition: cfgutil.hxx:41
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:115
std::unique_ptr< weld::TreeIter > make_iterator(const weld::TreeIter *pOrig=nullptr) const
Definition: cfgutil.hxx:143
std::vector< std::unique_ptr< SfxGroupInfo_Impl > > SfxGroupInfoArr_Impl
Definition: cfgutil.hxx:100
std::unique_ptr< weld::Label > m_xMacronameFT
Definition: cfgutil.hxx:240
void FillFunctionsList(const css::uno::Sequence< css::frame::DispatchInformation > &xCommands)
Definition: cfgutil.cxx:609
SfxGroupInfoArr_Impl aArr
Definition: cfgutil.hxx:105
CuiConfigFunctionListBox(std::unique_ptr< weld::TreeView > xTreeView)
Definition: cfgutil.cxx:276
OUString sCommand
Definition: cfgutil.hxx:91
static css::uno::Reference< css::uno::XInterface > getDocumentModel(css::uno::Reference< css::uno::XComponentContext > const &xCtx, OUString const &docName)
Definition: cfgutil.cxx:760
std::unique_ptr< weld::Label > m_xCommandsFT
Definition: cfgutil.hxx:241
void connect_popup_menu(const Link< const CommandEvent &, bool > &rLink)
Definition: cfgutil.hxx:114
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:698
void expand_row(const weld::TreeIter &rIter)
Definition: cfgutil.hxx:141
std::unique_ptr< weld::Label > m_xDialogDescription
Definition: cfgutil.hxx:235
std::unique_ptr< weld::TreeIter > m_xScratchIter
Definition: cfgutil.hxx:108
CuiConfigFunctionListBox * m_pFunctionListBox
Definition: cfgutil.hxx:180
static bool parseStyleCommand(SfxStyleInfo_Impl &aStyle)
Definition: cfgutil.cxx:86
OUString sLabel
Definition: cfgutil.hxx:92
OUString get_id(const weld::TreeIter &rIter) const
Definition: cfgutil.hxx:146
static OUString generateCommand(const OUString &sFamily, const OUString &sStyle)
Definition: cfgutil.cxx:78
OUString m_aModuleName
Definition: cfgutil.hxx:59
std::unique_ptr< weld::Button > m_xOKButton
Definition: cfgutil.hxx:242
void SelectMacro(const SfxMacroInfoItem *)
Definition: cfgutil.cxx:995
std::unique_ptr< weld::Label > m_xCategoryFT
Definition: cfgutil.hxx:239
weld::TreeView & get_widget()
Definition: cfgutil.hxx:214
std::unique_ptr< weld::Button > m_xCancelButton
Definition: cfgutil.hxx:243
CuiConfigGroupListBox(std::unique_ptr< weld::TreeView > xTreeView)
Definition: cfgutil.cxx:417
css::uno::Reference< css::frame::XFrame > m_xFrame
Definition: cfgutil.hxx:184
std::unique_ptr< weld::TreeView > m_xTreeView
Definition: cfgutil.hxx:107
sal_uInt16 nPos
void set_sensitive(bool bSensitive)
Definition: cfgutil.hxx:112
std::unique_ptr< weld::TextView > m_xDescriptionText
Definition: cfgutil.hxx:244
void append(const OUString &rId, const OUString &rStr, const weld::TreeIter *pParent=nullptr)
Definition: cfgutil.hxx:118