LibreOffice Module sfx2 (master) 1
tabdlg.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_SFX2_TABDLG_HXX
20#define INCLUDED_SFX2_TABDLG_HXX
21
22#include <memory>
23#include <unordered_map>
24#include <string_view>
25
26#include <sal/config.h>
27#include <sfx2/dllapi.h>
28#include <sfx2/basedlgs.hxx>
29#include <sal/types.h>
30#include <vcl/bitmapex.hxx>
31#include <vcl/builderpage.hxx>
32#include <svl/itempool.hxx>
33#include <svl/itemset.hxx>
34#include <svl/setitem.hxx>
36
37class SfxTabPage;
38
39typedef std::unique_ptr<SfxTabPage> (*CreateTabPage)(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *rAttrSet);
40typedef WhichRangesContainer (*GetTabPageRanges)(); // provides international Which-value
41struct TabPageImpl;
42
43struct TabDlg_Impl;
44
45namespace com::sun::star::frame { class XFrame; }
46
47#define RET_USER 100
48#define RET_USER_CANCEL 101
49
51{
52public:
53 SfxTabDialogItem( sal_uInt16 nId, const SfxItemSet& rItemSet );
54 SfxTabDialogItem(const SfxTabDialogItem& rAttr, SfxItemPool* pItemPool);
55 virtual SfxTabDialogItem* Clone(SfxItemPool* pToPool = nullptr) const override;
56};
57
59{
60protected:
61 std::unique_ptr<weld::Notebook> m_xTabCtrl;
62
63 DECL_LINK(OkHdl, weld::Button&, void);
68private:
69 std::unique_ptr<weld::Button> m_xOKBtn;
70 std::unique_ptr<weld::Button> m_xApplyBtn;
71 std::unique_ptr<weld::Button> m_xUserBtn;
72 std::unique_ptr<weld::Button> m_xCancelBtn;
73 std::unique_ptr<weld::Button> m_xResetBtn;
74 std::unique_ptr<weld::Button> m_xBaseFmtBtn;
75 std::unique_ptr<weld::SizeGroup> m_xSizeGroup;
76
77 std::unique_ptr<SfxItemSet> m_pSet;
78 std::unique_ptr<SfxItemSet> m_pOutSet;
79 std::unique_ptr<TabDlg_Impl> m_pImpl;
81 OUString m_sAppPageId;
83 std::unique_ptr<SfxAllItemSet> m_xItemSet;
84
85 DECL_DLLPRIVATE_LINK(ActivatePageHdl, const OUString&, void);
86 DECL_DLLPRIVATE_LINK(DeactivatePageHdl, const OUString&, bool);
87 SAL_DLLPRIVATE void Start_Impl();
88 SAL_DLLPRIVATE void CreatePages();
89 SAL_DLLPRIVATE void setPreviewsToSamePlace();
90
91protected:
92 virtual short Ok();
93 virtual void RefreshInputSet();
94 virtual SfxItemSet* CreateInputItemSet(const OUString& rName);
95 virtual void PageCreated(const OUString &rName, SfxTabPage &rPage);
96
97 virtual void ActivatePage(const OUString& rPage);
98 bool DeactivatePage(std::u16string_view aPage);
99
100 std::unique_ptr<SfxItemSet> m_xExampleSet;
102 SfxTabPage* GetTabPage(std::u16string_view rPageId) const;
103
109
113public:
114 SfxTabDialogController(weld::Widget* pParent, const OUString& rUIXMLDescription, const OUString& rID,
115 const SfxItemSet * = nullptr, bool bEditFmt = false);
116 virtual ~SfxTabDialogController() override;
117
118 void AddTabPage(const OUString& rName, // Name of the label for the existing page in the notebook .ui
119 CreateTabPage pCreateFunc, // != 0
120 GetTabPageRanges pRangesFunc); // can be 0
121
122 void AddTabPage(const OUString& rName, // Name of the label for the existing page in the notebook .ui
123 sal_uInt16 nPageCreateId); // Identifier of the Factory Method to create the page
124
125 void AddTabPage(const OUString& rName, // Name of the label for the new page to create
126 const OUString& rLabel, // UI Label for the new page to create
127 CreateTabPage pCreateFunc); // != 0
128
129 void AddTabPage(const OUString& rName, // Name of the label for the new page to create
130 const OUString& rLabel, // UI Label for the new page to create
131 sal_uInt16 nPageCreateId); // Identifier of the Factory Method to create the page
132
133 void RemoveTabPage( const OUString& rName ); // Name of the label for the page in the notebook .ui
134
135 void SetCurPageId(const OUString& rName);
136 void ShowPage(const OUString& rName); // SetCurPageId + call Activate on it
137 OUString GetCurPageId() const;
138 SfxTabPage* GetCurTabPage() const { return GetTabPage(GetCurPageId()); }
139
140 // may provide local slots converted by Map
142 void SetInputSet( const SfxItemSet* pInSet );
143 const SfxItemSet* GetOutputItemSet() const { return m_pOutSet.get(); }
144
145 virtual weld::Button& GetOKButton() const override { return *m_xOKBtn; }
146 weld::Button& GetCancelButton() const { return *m_xCancelBtn; }
147 weld::Button* GetUserButton() const { return m_xUserBtn.get(); }
148 weld::Button* GetStandardButton() const { return m_xBaseFmtBtn.get(); }
149 weld::Button* GetApplyButton() const { return m_xApplyBtn.get(); }
150 weld::Button* GetResetButton() const { return m_xResetBtn.get(); }
153
154 virtual short run() override;
155 static bool runAsync(const std::shared_ptr<SfxTabDialogController>& rController,
156 const std::function<void(sal_Int32)>&);
157
158 virtual const SfxItemSet* GetExampleSet() const override { return m_xExampleSet.get(); }
159
161
162 //calls Ok without closing dialog
163 bool Apply();
164 void Applied() { m_xExampleSet->Put(*GetInputSetImpl()); }
165
166 //screenshotting
167 std::vector<OUString> getAllPageUIXMLDescriptions() const;
168 bool selectPageByUIXMLDescription(const OUString& rUIXMLDescription);
170 OUString GetScreenshotId() const;
171};
172
173enum class DeactivateRC {
174 KeepPage = 0x00, // Error handling; page does not change
175 // 2. Fill an itemset for update
176 // parent examples, this pointer can be NULL all the time!
177 LeavePage = 0x01,
178 // Set, refresh and update other Page
179 RefreshSet = 0x02
180};
181namespace o3tl {
182 template<> struct typed_flags<DeactivateRC> : is_typed_flags<DeactivateRC, 0x03> {};
183}
184
186{
187friend class SfxTabDialog;
189
190private:
192 OUString maUserString;
194 std::unordered_map<OUString, css::uno::Any> maAdditionalProperties;
195
196 std::unique_ptr<TabPageImpl> mpImpl;
197
198protected:
199 SfxTabPage(weld::Container* pPage, weld::DialogController* pController, const OUString& rUIXMLDescription, const OUString& rID, const SfxItemSet *rAttrSet);
200
201 sal_uInt16 GetWhich( sal_uInt16 nSlot, bool bDeep = true ) const
202 {
203 return mpSet->GetPool()->GetWhich(nSlot, bDeep);
204 }
205 template<class T>
206 TypedWhichId<T> GetWhich( TypedWhichId<T> nSlot, bool bDeep = true ) const
207 {
208 return TypedWhichId<T>(GetWhich(sal_uInt16(nSlot), bDeep));
209 }
210
211 const SfxPoolItem* GetOldItem( const SfxItemSet& rSet, sal_uInt16 nSlot, bool bDeep = true );
212 template<class T> const T* GetOldItem( const SfxItemSet& rSet, TypedWhichId<T> nSlot, bool bDeep = true )
213 {
214 return static_cast<const T*>(GetOldItem(rSet, sal_uInt16(nSlot), bDeep));
215 }
216
217 SfxOkDialogController* GetDialogController() const;
218public:
219 void SetDialogController(SfxOkDialogController* pDialog);
220public:
221 virtual ~SfxTabPage() override;
222
223 void set_visible(bool bVisible)
224 {
225 m_xContainer->set_visible(bVisible);
226 }
227
228 const SfxItemSet& GetItemSet() const
229 {
230 return *mpSet;
231 }
232
233 virtual bool FillItemSet( SfxItemSet* );
234 virtual void Reset( const SfxItemSet* );
235 // Allows to postpone some initialization to the first activation
236 virtual bool DeferResetToFirstActivation();
237
239 {
240 return mbHasExchangeSupport;
241 }
242
244 {
245 mbHasExchangeSupport = true;
246 }
247
248 virtual void ActivatePage( const SfxItemSet& );
249 virtual DeactivateRC DeactivatePage( SfxItemSet* pSet );
250 void SetUserData(const OUString& rString)
251 {
252 maUserString = rString;
253 }
254 const OUString& GetUserData() const
255 {
256 return maUserString;
257 }
258 virtual void FillUserData();
259 virtual bool IsReadOnly() const;
260 virtual void PageCreated (const SfxAllItemSet& aSet);
261 virtual void ChangesApplied();
262 static const SfxPoolItem* GetItem( const SfxItemSet& rSet, sal_uInt16 nSlot, bool bDeep = true );
263 template<class T> static const T* GetItem( const SfxItemSet& rSet, TypedWhichId<T> nSlot, bool bDeep = true )
264 {
265 return static_cast<const T*>(GetItem(rSet, sal_uInt16(nSlot), bDeep));
266 }
267
268 void SetFrame(const css::uno::Reference< css::frame::XFrame >& xFrame);
269 css::uno::Reference< css::frame::XFrame > GetFrame() const;
270
271 const SfxItemSet* GetDialogExampleSet() const;
272
273 OUString GetHelpId() const;
274 OUString GetConfigId() const { return GetHelpId(); }
275 bool IsVisible() const { return m_xContainer->get_visible(); }
276
277 weld::Window* GetFrameWeld() const;
278
279 std::unordered_map<OUString, css::uno::Any>& getAdditionalProperties()
280 {
281 return maAdditionalProperties;
282 }
283};
284
285#endif
286
287/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define GetWhich(nSlot)
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
SfxItemPool * GetPool() const
virtual SfxSetItem * Clone(SfxItemPool *pPool=nullptr) const override=0
std::unique_ptr< SfxItemSet > m_pSet
Definition: tabdlg.hxx:77
DECL_DLLPRIVATE_LINK(BaseFmtHdl, weld::Button &, void)
DECL_LINK(OkHdl, weld::Button &, void)
void AddTabPage(const OUString &rName, sal_uInt16 nPageCreateId)
virtual short Ok()
bool PrepareLeaveCurrentPage()
prepare to leave the current page.
OUString m_sAppPageId
Definition: tabdlg.hxx:81
void AddTabPage(const OUString &rName, const OUString &rLabel, sal_uInt16 nPageCreateId)
DECL_DLLPRIVATE_LINK(CancelHdl, weld::Button &, void)
SfxTabPage * GetTabPage(std::u16string_view rPageId) const
void SetCurPageId(const OUString &rName)
OUString GetCurPageId() const
void AddTabPage(const OUString &rName, CreateTabPage pCreateFunc, GetTabPageRanges pRangesFunc)
void SetInputSet(const SfxItemSet *pInSet)
std::unique_ptr< TabDlg_Impl > m_pImpl
Definition: tabdlg.hxx:79
virtual const SfxItemSet * GetExampleSet() const override
Definition: tabdlg.hxx:158
void SavePosAndId()
save the position of the TabDialog and which tab page is the currently active one
weld::Button * GetUserButton() const
Definition: tabdlg.hxx:147
std::unique_ptr< weld::Button > m_xCancelBtn
Definition: tabdlg.hxx:72
weld::Button & GetCancelButton() const
Definition: tabdlg.hxx:146
DECL_DLLPRIVATE_LINK(DeactivatePageHdl, const OUString &, bool)
SfxTabPage * GetCurTabPage() const
Definition: tabdlg.hxx:138
DECL_DLLPRIVATE_LINK(ResetHdl, weld::Button &, void)
SAL_DLLPRIVATE void Start_Impl()
std::unique_ptr< weld::Button > m_xResetBtn
Definition: tabdlg.hxx:73
std::unique_ptr< SfxItemSet > m_pOutSet
Definition: tabdlg.hxx:78
void RemoveTabPage(const OUString &rName)
std::unique_ptr< SfxAllItemSet > m_xItemSet
Definition: tabdlg.hxx:83
std::unique_ptr< weld::Button > m_xUserBtn
Definition: tabdlg.hxx:71
virtual short run() override
std::unique_ptr< SfxItemSet > m_xExampleSet
Definition: tabdlg.hxx:100
OUString GetScreenshotId() const
std::unique_ptr< weld::Button > m_xBaseFmtBtn
Definition: tabdlg.hxx:74
virtual weld::Button & GetOKButton() const override
Definition: tabdlg.hxx:145
WhichRangesContainer m_pRanges
Definition: tabdlg.hxx:80
DECL_DLLPRIVATE_LINK(ActivatePageHdl, const OUString &, void)
std::unique_ptr< weld::Notebook > m_xTabCtrl
Definition: tabdlg.hxx:61
virtual void ActivatePage(const OUString &rPage)
std::unique_ptr< weld::Button > m_xOKBtn
Definition: tabdlg.hxx:69
virtual SfxItemSet * CreateInputItemSet(const OUString &rName)
virtual void PageCreated(const OUString &rName, SfxTabPage &rPage)
void AddTabPage(const OUString &rName, const OUString &rLabel, CreateTabPage pCreateFunc)
SAL_DLLPRIVATE void setPreviewsToSamePlace()
virtual void RefreshInputSet()
std::vector< OUString > getAllPageUIXMLDescriptions() const
weld::Button * GetResetButton() const
Definition: tabdlg.hxx:150
void SetApplyHandler(const Link< weld::Button &, void > &_rHdl)
const SfxItemSet * GetOutputItemSet() const
Definition: tabdlg.hxx:143
BitmapEx createScreenshot() const
void ShowPage(const OUString &rName)
std::unique_ptr< weld::Button > m_xApplyBtn
Definition: tabdlg.hxx:70
weld::Button * GetStandardButton() const
Definition: tabdlg.hxx:148
const WhichRangesContainer & GetInputRanges(const SfxItemPool &)
std::unique_ptr< weld::SizeGroup > m_xSizeGroup
Definition: tabdlg.hxx:75
DECL_DLLPRIVATE_LINK(UserHdl, weld::Button &, void)
SAL_DLLPRIVATE void CreatePages()
static bool runAsync(const std::shared_ptr< SfxTabDialogController > &rController, const std::function< void(sal_Int32)> &)
SfxItemSet * GetInputSetImpl()
weld::Button * GetApplyButton() const
Definition: tabdlg.hxx:149
virtual ~SfxTabDialogController() override
bool selectPageByUIXMLDescription(const OUString &rUIXMLDescription)
bool DeactivatePage(std::u16string_view aPage)
bool HasExchangeSupport() const
Definition: tabdlg.hxx:238
const T * GetOldItem(const SfxItemSet &rSet, TypedWhichId< T > nSlot, bool bDeep=true)
Definition: tabdlg.hxx:212
std::unordered_map< OUString, css::uno::Any > maAdditionalProperties
Definition: tabdlg.hxx:194
bool IsVisible() const
Definition: tabdlg.hxx:275
static const T * GetItem(const SfxItemSet &rSet, TypedWhichId< T > nSlot, bool bDeep=true)
Definition: tabdlg.hxx:263
const SfxItemSet * mpSet
Definition: tabdlg.hxx:191
void set_visible(bool bVisible)
Definition: tabdlg.hxx:223
std::unique_ptr< TabPageImpl > mpImpl
Definition: tabdlg.hxx:196
const SfxItemSet & GetItemSet() const
Definition: tabdlg.hxx:228
void SetExchangeSupport()
Definition: tabdlg.hxx:243
void SetUserData(const OUString &rString)
Definition: tabdlg.hxx:250
OUString GetConfigId() const
Definition: tabdlg.hxx:274
std::unordered_map< OUString, css::uno::Any > & getAdditionalProperties()
Definition: tabdlg.hxx:279
const OUString & GetUserData() const
Definition: tabdlg.hxx:254
bool mbHasExchangeSupport
Definition: tabdlg.hxx:193
TypedWhichId< T > GetWhich(TypedWhichId< T > nSlot, bool bDeep=true) const
Definition: tabdlg.hxx:206
OUString maUserString
Definition: tabdlg.hxx:192
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
Definition: tabdlg.hxx:201
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
#define SFX2_DLLPUBLIC
Definition: dllapi.h:29
constexpr OUStringLiteral IsReadOnly(u"IsReadOnly")
const SfxPoolItem * GetItem(const SwTextAttr &rAttr, sal_uInt16 nWhich)
Reference< XNameAccess > m_xContainer
sal_Int16 nId
static SfxItemSet & rSet
Definition: shell.cxx:534
std::unique_ptr< SfxTabPage >(* CreateTabPage)(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rAttrSet)
Definition: tabdlg.hxx:39
DeactivateRC
Definition: tabdlg.hxx:173
WhichRangesContainer(* GetTabPageRanges)()
Definition: tabdlg.hxx:40
bool bVisible