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_SFX2_TABDLG_HXX
20 #define INCLUDED_SFX2_TABDLG_HXX
23 #include <unordered_map>
24 #include <string_view>
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>
35 #include <o3tl/typed_flags_set.hxx>
39 typedef std::unique_ptr
<SfxTabPage
> (*CreateTabPage
)(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
*rAttrSet
);
40 typedef WhichRangesContainer (*GetTabPageRanges
)(); // provides international Which-value
45 namespace com::sun::star::frame
{ class XFrame
; }
48 #define RET_USER_CANCEL 101
50 class SFX2_DLLPUBLIC SfxTabDialogItem final
: public SfxSetItem
53 SfxTabDialogItem( sal_uInt16 nId
, const SfxItemSet
& rItemSet
);
54 SfxTabDialogItem(const SfxTabDialogItem
& rAttr
, SfxItemPool
* pItemPool
);
55 virtual SfxTabDialogItem
* Clone(SfxItemPool
* pToPool
= nullptr) const override
;
58 class SFX2_DLLPUBLIC SfxTabDialogController
: public SfxOkDialogController
61 std::unique_ptr
<weld::Notebook
> m_xTabCtrl
;
63 DECL_LINK(OkHdl
, weld::Button
&, void);
64 DECL_DLLPRIVATE_LINK(ResetHdl
, weld::Button
&, void);
65 DECL_DLLPRIVATE_LINK(BaseFmtHdl
, weld::Button
&, void);
66 DECL_DLLPRIVATE_LINK(UserHdl
, weld::Button
&, void);
67 DECL_DLLPRIVATE_LINK(CancelHdl
, weld::Button
&, void);
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
;
77 std::unique_ptr
<SfxItemSet
> m_pSet
;
78 std::unique_ptr
<SfxItemSet
> m_pOutSet
;
79 std::unique_ptr
<TabDlg_Impl
> m_pImpl
;
80 WhichRangesContainer m_pRanges
;
81 OUString m_sAppPageId
;
82 bool m_bStandardPushed
;
83 std::unique_ptr
<SfxAllItemSet
> m_xItemSet
;
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();
93 virtual void RefreshInputSet();
94 virtual SfxItemSet
* CreateInputItemSet(const OUString
& rName
);
95 virtual void PageCreated(const OUString
&rName
, SfxTabPage
&rPage
);
97 virtual void ActivatePage(const OUString
& rPage
);
98 bool DeactivatePage(std::u16string_view aPage
);
100 std::unique_ptr
<SfxItemSet
> m_xExampleSet
;
101 SfxItemSet
* GetInputSetImpl();
102 SfxTabPage
* GetTabPage(std::u16string_view rPageId
) const;
104 /** prepare to leave the current page. Calls the DeactivatePage method of the current page, (if necessary),
105 handles the item sets to copy.
106 @return sal_True if it is allowed to leave the current page, sal_False otherwise
108 bool PrepareLeaveCurrentPage();
110 /** save the position of the TabDialog and which tab page is the currently active one
114 SfxTabDialogController(weld::Widget
* pParent
, const OUString
& rUIXMLDescription
, const OUString
& rID
,
115 const SfxItemSet
* = nullptr, bool bEditFmt
= false);
116 virtual ~SfxTabDialogController() override
;
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
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
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
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
133 void RemoveTabPage( const OUString
& rName
); // Name of the label for the page in the notebook .ui
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()); }
140 // may provide local slots converted by Map
141 const WhichRangesContainer
& GetInputRanges( const SfxItemPool
& );
142 void SetInputSet( const SfxItemSet
* pInSet
);
143 const SfxItemSet
* GetOutputItemSet() const { return m_pOutSet
.get(); }
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(); }
151 void RemoveResetButton();
152 void RemoveStandardButton();
154 virtual short run() override
;
155 static bool runAsync(const std::shared_ptr
<SfxTabDialogController
>& rController
,
156 const std::function
<void(sal_Int32
)>&);
158 virtual const SfxItemSet
* GetExampleSet() const override
{ return m_xExampleSet
.get(); }
160 void SetApplyHandler(const Link
<weld::Button
&,void>& _rHdl
);
162 //calls Ok without closing dialog
164 void Applied() { m_xExampleSet
->Put(*GetInputSetImpl()); }
167 std::vector
<OUString
> getAllPageUIXMLDescriptions() const;
168 bool selectPageByUIXMLDescription(const OUString
& rUIXMLDescription
);
169 BitmapEx
createScreenshot() const;
170 OUString
GetScreenshotId() const;
173 enum 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!
178 // Set, refresh and update other Page
182 template<> struct typed_flags
<DeactivateRC
> : is_typed_flags
<DeactivateRC
, 0x03> {};
185 class SFX2_DLLPUBLIC SfxTabPage
: public BuilderPage
187 friend class SfxTabDialog
;
188 friend class SfxTabDialogController
;
191 const SfxItemSet
* mpSet
;
192 OUString maUserString
;
193 bool mbHasExchangeSupport
;
194 std::unordered_map
<OUString
, css::uno::Any
> maAdditionalProperties
;
196 std::unique_ptr
<TabPageImpl
> mpImpl
;
199 SfxTabPage(weld::Container
* pPage
, weld::DialogController
* pController
, const OUString
& rUIXMLDescription
, const OUString
& rID
, const SfxItemSet
*rAttrSet
);
201 sal_uInt16
GetWhich( sal_uInt16 nSlot
, bool bDeep
= true ) const
203 return mpSet
->GetPool()->GetWhich(nSlot
, bDeep
);
206 TypedWhichId
<T
> GetWhich( TypedWhichId
<T
> nSlot
, bool bDeep
= true ) const
208 return TypedWhichId
<T
>(GetWhich(sal_uInt16(nSlot
), bDeep
));
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 )
214 return static_cast<const T
*>(GetOldItem(rSet
, sal_uInt16(nSlot
), bDeep
));
217 SfxOkDialogController
* GetDialogController() const;
219 void SetDialogController(SfxOkDialogController
* pDialog
);
221 virtual ~SfxTabPage() override
;
223 void set_visible(bool bVisible
)
225 m_xContainer
->set_visible(bVisible
);
228 const SfxItemSet
& GetItemSet() const
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();
238 bool HasExchangeSupport() const
240 return mbHasExchangeSupport
;
243 void SetExchangeSupport()
245 mbHasExchangeSupport
= true;
248 virtual void ActivatePage( const SfxItemSet
& );
249 virtual DeactivateRC
DeactivatePage( SfxItemSet
* pSet
);
250 void SetUserData(const OUString
& rString
)
252 maUserString
= rString
;
254 const OUString
& GetUserData() const
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 )
265 return static_cast<const T
*>(GetItem(rSet
, sal_uInt16(nSlot
), bDeep
));
268 void SetFrame(const css::uno::Reference
< css::frame::XFrame
>& xFrame
);
269 css::uno::Reference
< css::frame::XFrame
> GetFrame() const;
271 const SfxItemSet
* GetDialogExampleSet() const;
273 OUString
GetHelpId() const;
274 OUString
GetConfigId() const { return GetHelpId(); }
275 bool IsVisible() const { return m_xContainer
->get_visible(); }
277 weld::Window
* GetFrameWeld() const;
279 std::unordered_map
<OUString
, css::uno::Any
>& getAdditionalProperties()
281 return maAdditionalProperties
;
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */