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 
36 class Button;
37 class SaveInData;
38 #if HAVE_FEATURE_SCRIPTING
39 class 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 {
63 private:
64  OUString m_aModuleName;
65  css::uno::Reference< css::frame::XModel > m_xDoc;
66 
67 public:
68 
70  void init(const OUString& rModuleName, const css::uno::Reference< css::frame::XModel >& xModel);
71 
72  static bool parseStyleCommand(SfxStyleInfo_Impl& aStyle);
73  void getLabel4Style(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 
81 enum class SfxCfgKind
82 {
83  GROUP_FUNCTION = 1,
84  FUNCTION_SLOT = 2,
86  FUNCTION_SCRIPT = 4,
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 
106 typedef std::vector<std::unique_ptr<SfxGroupInfo_Impl> > SfxGroupInfoArr_Impl;
107 
109 {
110  friend class CuiConfigGroupListBox;
112 
113  std::unique_ptr<weld::TreeView> m_xTreeView;
114  std::unique_ptr<weld::TreeIter> m_xScratchIter;
115 
116 public:
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 
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 #if HAVE_FEATURE_SCRIPTING
232  void SelectMacro(const SfxMacroInfoItem*);
233  void SelectMacro(std::u16string_view, const OUString&);
234 #endif
235  void SetStylesInfo(SfxStylesInfo_Impl* pStyles);
236 };
237 
239 {
240  OUString m_sDefaultDesc;
242 
243  std::unique_ptr<weld::Label> m_xDialogDescription;
244  std::unique_ptr<CuiConfigGroupListBox> m_xCategories;
245  std::unique_ptr<CuiConfigFunctionListBox> m_xCommands;
246  std::unique_ptr<weld::Label> m_xLibraryFT;
247  std::unique_ptr<weld::Label> m_xMacronameFT;
248  std::unique_ptr<weld::Button> m_xOKButton;
249  std::unique_ptr<weld::Button> m_xCancelButton;
250  std::unique_ptr<weld::TextView> m_xDescriptionText;
251  std::unique_ptr<weld::Frame> m_xDescriptionFrame;
252 
253  DECL_LINK(ClickHdl, weld::Button&, void);
254  DECL_LINK(SelectHdl, weld::TreeView&, void);
255  DECL_LINK(FunctionDoubleClickHdl, weld::TreeView&, bool);
256  DECL_LINK(ContextMenuHdl, const CommandEvent&, bool);
257 
258  void UpdateUI();
259 
260 public:
262  const css::uno::Reference< css::frame::XFrame >& xFrame);
263  virtual ~SvxScriptSelectorDialog() override;
264 
265  OUString GetScriptURL() const;
266  void SetRunLabel();
267 };
268 
269 /* 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:185
css::uno::Reference< css::container::XNameAccess > m_xGlobalCategoryInfo
Definition: cfgutil.hxx:191
void SetFunctionListBox(CuiConfigFunctionListBox *pBox)
Definition: cfgutil.hxx:228
std::vector< SfxStyleInfo_Impl > getStyleFamilies() const
Definition: cfgutil.cxx:157
OUString sStyle
Definition: cfgutil.hxx:45
OUString GetHelpText(bool bConsiderParent=true)
Definition: cfgutil.cxx:243
OUString sTooltip
Definition: cfgutil.hxx:100
std::unique_ptr< CuiConfigFunctionListBox > m_xCommands
Definition: cfgutil.hxx:245
OUString GetScriptURL() const
Definition: cfgutil.cxx:1251
css::uno::Reference< css::frame::XModel > m_xDoc
Definition: cfgutil.hxx:65
SfxStylesInfo_Impl * m_pStylesInfo
Definition: cfgutil.hxx:194
css::uno::Reference< css::container::XNameAccess > m_xUICmdDescription
Definition: cfgutil.hxx:193
Size get_size_request() const
Definition: cfgutil.hxx:168
void getLabel4Style(SfxStyleInfo_Impl &aStyle)
Definition: cfgutil.cxx:124
void set_sensitive(bool bSensitive)
Definition: cfgutil.hxx:217
std::unique_ptr< weld::TreeIter > m_xScratchIter
Definition: cfgutil.hxx:196
std::unique_ptr< weld::TreeIter > tree_append(const OUString &rId, const OUString &rStr, const weld::TreeIter *pParent=nullptr)
Definition: cfgutil.hxx:128
void append(const OUString &rId, const OUString &rStr, const OUString &rImage, const weld::TreeIter *pParent=nullptr)
Definition: cfgutil.hxx:134
css::uno::Reference< css::container::XNameAccess > m_xModuleCategoryInfo
Definition: cfgutil.hxx:192
bool iter_has_child(const weld::TreeIter &rIter) const
Definition: cfgutil.hxx:150
DECL_LINK(QueryTooltip, const weld::TreeIter &rIter, OUString)
OUString MapCommand2UIName(const OUString &sCommand)
Definition: cfgutil.cxx:792
OUString get_text(int nPos) const
Definition: cfgutil.hxx:151
OUString get_selected_text() const
Definition: cfgutil.hxx:154
DECL_LINK(ClickHdl, weld::Button &, void)
std::unique_ptr< CuiConfigGroupListBox > m_xCategories
Definition: cfgutil.hxx:244
void select(int pos)
Definition: cfgutil.hxx:166
int n_children() const
Definition: cfgutil.hxx:148
SfxGroupInfoArr_Impl aArr
Definition: cfgutil.hxx:187
OUString sFamily
Definition: cfgutil.hxx:44
OUString GetCurLabel() const
Definition: cfgutil.cxx:271
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:627
std::unique_ptr< weld::TreeView > m_xTreeView
Definition: cfgutil.hxx:195
OUString sLabel
Definition: cfgutil.hxx:47
bool get_selected(weld::TreeIter *pIter) const
Definition: cfgutil.hxx:153
SvxScriptSelectorDialog(weld::Window *pParent, const css::uno::Reference< css::frame::XFrame > &xFrame)
Definition: cfgutil.cxx:1110
SfxStylesInfo_Impl m_aStylesInfo
Definition: cfgutil.hxx:241
void connect_changed(const Link< weld::TreeView &, void > &rLink)
Definition: cfgutil.hxx:119
SfxGroupInfo_Impl(SfxCfgKind n, sal_uInt16 nr, void *pObj=nullptr)
Definition: cfgutil.hxx:102
void set_size_request(int nWidth, int nHeight)
Definition: cfgutil.hxx:167
void connect_changed(const Link< weld::TreeView &, void > &rLink)
Definition: cfgutil.hxx:218
std::unique_ptr< weld::Label > m_xLibraryFT
Definition: cfgutil.hxx:246
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 sHelpText
Definition: cfgutil.hxx:99
std::vector< SfxStyleInfo_Impl > getStyles(const OUString &sFamily)
Definition: cfgutil.cxx:199
virtual ~SvxScriptSelectorDialog() override
Definition: cfgutil.cxx:1162
SfxCfgKind nKind
Definition: cfgutil.hxx:94
css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: cfgutil.hxx:189
OUString GetCurCommand() const
Definition: cfgutil.cxx:263
void scroll_to_row(int pos)
Definition: cfgutil.hxx:145
OUString GetSelectedScriptURI() const
Definition: cfgutil.cxx:337
SfxCfgKind
Definition: cfgutil.hxx:81
OUString get_selected_id() const
Definition: cfgutil.hxx:160
SfxStyleInfo_Impl(const SfxStyleInfo_Impl &rCopy)
Definition: cfgutil.hxx:52
sal_uInt16 nUniqueID
Definition: cfgutil.hxx:95
void SetStylesInfo(SfxStylesInfo_Impl *pStyles)
Definition: cfgutil.cxx:367
OUString m_sModuleLongName
Definition: cfgutil.hxx:188
OUString sCommand
Definition: cfgutil.hxx:46
void init(const OUString &rModuleName, const css::uno::Reference< css::frame::XModel > &xModel)
Definition: cfgutil.cxx:70
void connect_row_activated(const Link< weld::TreeView &, bool > &rLink)
Definition: cfgutil.hxx:121
std::unique_ptr< weld::TreeIter > make_iterator(const weld::TreeIter *pOrig=nullptr) const
Definition: cfgutil.hxx:149
void FillScriptList(const css::uno::Reference< css::script::browse::XBrowseNode > &xRootNode, const weld::TreeIter *pParentEntry)
Definition: cfgutil.cxx:513
std::vector< std::unique_ptr< SfxGroupInfo_Impl > > SfxGroupInfoArr_Impl
Definition: cfgutil.hxx:106
std::unique_ptr< weld::Label > m_xMacronameFT
Definition: cfgutil.hxx:247
void FillFunctionsList(const css::uno::Sequence< css::frame::DispatchInformation > &xCommands)
Definition: cfgutil.cxx:609
SfxGroupInfoArr_Impl aArr
Definition: cfgutil.hxx:111
CuiConfigFunctionListBox(std::unique_ptr< weld::TreeView > xTreeView)
Definition: cfgutil.cxx:281
OUString sCommand
Definition: cfgutil.hxx:97
static OUString generateCommand(std::u16string_view sFamily, std::u16string_view sStyle)
Definition: cfgutil.cxx:82
void connect_popup_menu(const Link< const CommandEvent &, bool > &rLink)
Definition: cfgutil.hxx:120
std::unique_ptr< weld::Frame > m_xDescriptionFrame
Definition: cfgutil.hxx:251
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
void expand_row(const weld::TreeIter &rIter)
Definition: cfgutil.hxx:147
std::unique_ptr< weld::Label > m_xDialogDescription
Definition: cfgutil.hxx:243
std::unique_ptr< weld::TreeIter > m_xScratchIter
Definition: cfgutil.hxx:114
CuiConfigFunctionListBox * m_pFunctionListBox
Definition: cfgutil.hxx:186
static css::uno::Reference< css::uno::XInterface > getDocumentModel(css::uno::Reference< css::uno::XComponentContext > const &xCtx, std::u16string_view docName)
Definition: cfgutil.cxx:765
static bool parseStyleCommand(SfxStyleInfo_Impl &aStyle)
Definition: cfgutil.cxx:91
OUString sLabel
Definition: cfgutil.hxx:98
OUString get_id(const weld::TreeIter &rIter) const
Definition: cfgutil.hxx:152
OUString m_aModuleName
Definition: cfgutil.hxx:64
std::unique_ptr< weld::Button > m_xOKButton
Definition: cfgutil.hxx:248
weld::TreeView & get_widget()
Definition: cfgutil.hxx:220
std::unique_ptr< weld::Button > m_xCancelButton
Definition: cfgutil.hxx:249
CuiConfigGroupListBox(std::unique_ptr< weld::TreeView > xTreeView)
Definition: cfgutil.cxx:424
css::uno::Reference< css::frame::XFrame > m_xFrame
Definition: cfgutil.hxx:190
std::unique_ptr< weld::TreeView > m_xTreeView
Definition: cfgutil.hxx:113
sal_uInt16 nPos
void set_sensitive(bool bSensitive)
Definition: cfgutil.hxx:118
std::unique_ptr< weld::TextView > m_xDescriptionText
Definition: cfgutil.hxx:250
void append(const OUString &rId, const OUString &rStr, const weld::TreeIter *pParent=nullptr)
Definition: cfgutil.hxx:124