1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_CUI_SOURCE_INC_CFGUTIL_HXX
20 #define INCLUDED_CUI_SOURCE_INC_CFGUTIL_HXX
24 #include <rtl/ustring.hxx>
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>
36 class SfxMacroInfoItem
;
38 struct SfxStyleInfo_Impl
48 SfxStyleInfo_Impl(const SfxStyleInfo_Impl
& rCopy
)
50 sFamily
= rCopy
.sFamily
;
51 sStyle
= rCopy
.sStyle
;
52 sCommand
= rCopy
.sCommand
;
53 sLabel
= rCopy
.sLabel
;
57 struct SfxStylesInfo_Impl
60 OUString m_aModuleName
;
61 css::uno::Reference
< css::frame::XModel
> m_xDoc
;
66 void init(const OUString
& rModuleName
, const css::uno::Reference
< css::frame::XModel
>& xModel
);
68 static bool parseStyleCommand(SfxStyleInfo_Impl
& aStyle
);
69 void getLabel4Style(SfxStyleInfo_Impl
& aStyle
);
71 std::vector
< SfxStyleInfo_Impl
> getStyleFamilies() const;
72 std::vector
< SfxStyleInfo_Impl
> getStyles(const OUString
& sFamily
);
74 static OUString
generateCommand(const OUString
& sFamily
, const OUString
& sStyle
);
81 GROUP_SCRIPTCONTAINER
= 3,
84 GROUP_ALLFUNCTIONS
= 6
87 struct SfxGroupInfo_Impl
96 SfxGroupInfo_Impl( SfxCfgKind n
, sal_uInt16 nr
, void* pObj
= nullptr ) :
97 nKind( n
), nUniqueID( nr
), pObject( pObj
) {}
100 typedef std::vector
<std::unique_ptr
<SfxGroupInfo_Impl
> > SfxGroupInfoArr_Impl
;
102 class CuiConfigFunctionListBox
104 friend class CuiConfigGroupListBox
;
105 SfxGroupInfoArr_Impl aArr
;
107 std::unique_ptr
<weld::TreeView
> m_xTreeView
;
108 std::unique_ptr
<weld::TreeIter
> m_xScratchIter
;
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)
119 m_xTreeView
->insert(pParent
, -1, &rStr
, &rId
, nullptr, nullptr, nullptr, false, nullptr);
121 std::unique_ptr
<weld::TreeIter
> tree_append(const OUString
& rId
, const OUString
& rStr
, const weld::TreeIter
* pParent
= nullptr)
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());
127 void append(const OUString
& rId
, const OUString
& rStr
, const OUString
& rImage
, const weld::TreeIter
* pParent
= nullptr)
129 m_xTreeView
->insert(pParent
, -1, &rStr
, &rId
, nullptr, nullptr, &rImage
, false, nullptr);
131 void append(const OUString
& rId
, const OUString
& rStr
, const css::uno::Reference
<css::graphic::XGraphic
>& rImage
, const weld::TreeIter
* pParent
= nullptr)
133 m_xTreeView
->insert(pParent
, -1, &rStr
, &rId
, nullptr, nullptr, nullptr, false, m_xScratchIter
.get());
134 m_xTreeView
->set_image(*m_xScratchIter
, rImage
, -1);
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
154 if (!m_xTreeView
->get_selected(m_xScratchIter
.get()))
156 return m_xTreeView
->get_text(*m_xScratchIter
);
158 OUString
get_selected_id() const
160 if (!m_xTreeView
->get_selected(m_xScratchIter
.get()))
162 return m_xTreeView
->get_id(*m_xScratchIter
);
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(); }
169 weld::TreeView
& get_widget() { return *m_xTreeView
; }
171 ~CuiConfigFunctionListBox();
174 OUString
GetSelectedScriptURI() const;
175 OUString
GetHelpText( bool bConsiderParent
= true );
176 OUString
GetCurCommand() const;
177 OUString
GetCurLabel() const;
180 struct SvxConfigGroupBoxResource_Impl
;
181 class CuiConfigGroupListBox
183 std::unique_ptr
<SvxConfigGroupBoxResource_Impl
> xImp
;
184 CuiConfigFunctionListBox
* m_pFunctionListBox
;
185 SfxGroupInfoArr_Impl aArr
;
186 OUString m_sModuleLongName
;
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
;
192 SfxStylesInfo_Impl
* m_pStylesInfo
;
193 std::unique_ptr
<weld::TreeView
> m_xTreeView
;
195 static OUString
GetImage(
196 const css::uno::Reference
< css::script::browse::XBrowseNode
>& node
,
197 css::uno::Reference
< css::uno::XComponentContext
> const & xCtx
,
200 static css::uno::Reference
< css::uno::XInterface
> getDocumentModel(
201 css::uno::Reference
< css::uno::XComponentContext
> const & xCtx
,
202 OUString
const & docName
);
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
);
210 DECL_LINK(ExpandingHdl
, const weld::TreeIter
&, bool);
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
); }
217 weld::TreeView
& get_widget() { return *m_xTreeView
; }
218 ~CuiConfigGroupListBox();
221 void Init(const css::uno::Reference
< css::uno::XComponentContext
>& xContext
,
222 const css::uno::Reference
< css::frame::XFrame
>& xFrame
,
223 const OUString
& sModuleLongName
,
225 void SetFunctionListBox( CuiConfigFunctionListBox
*pBox
)
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
);
233 class SvxScriptSelectorDialog
: public weld::GenericDialogController
235 OUString m_sDefaultDesc
;
236 SfxStylesInfo_Impl m_aStylesInfo
;
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
;
250 DECL_LINK(ClickHdl
, weld::Button
&, void);
251 DECL_LINK(SelectHdl
, weld::TreeView
&, void);
252 DECL_LINK(FunctionDoubleClickHdl
, weld::TreeView
&, bool);
257 SvxScriptSelectorDialog(weld::Window
* pParent
, bool bShowSlots
,
258 const css::uno::Reference
< css::frame::XFrame
>& xFrame
);
259 virtual ~SvxScriptSelectorDialog() override
;
261 OUString
GetScriptURL() const;
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */