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 <sal/config.h>
24 #include <sfx2/dllapi.h>
25 #include <sfx2/basedlgs.hxx>
26 #include <sal/types.h>
27 #include <vcl/builderpage.hxx>
28 #include <svl/itempool.hxx>
29 #include <svl/itemset.hxx>
30 #include <o3tl/typed_flags_set.hxx>
34 typedef std::unique_ptr
<SfxTabPage
> (*CreateTabPage
)(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
*rAttrSet
);
35 typedef const sal_uInt16
* (*GetTabPageRanges
)(); // provides international Which-value
41 #define RET_USER_CANCEL 101
43 class SFX2_DLLPUBLIC SfxTabDialogItem final
: public SfxSetItem
46 SfxTabDialogItem( sal_uInt16 nId
, const SfxItemSet
& rItemSet
);
47 SfxTabDialogItem(const SfxTabDialogItem
& rAttr
, SfxItemPool
* pItemPool
);
48 virtual SfxPoolItem
* Clone(SfxItemPool
* pToPool
= nullptr) const override
;
51 class SFX2_DLLPUBLIC SfxTabDialogController
: public SfxOkDialogController
54 std::unique_ptr
<weld::Notebook
> m_xTabCtrl
;
56 DECL_LINK(OkHdl
, weld::Button
&, void);
57 DECL_LINK(ResetHdl
, weld::Button
&, void);
58 DECL_LINK(BaseFmtHdl
, weld::Button
&, void);
59 DECL_LINK(UserHdl
, weld::Button
&, void);
60 DECL_LINK(CancelHdl
, weld::Button
&, void);
62 std::unique_ptr
<weld::Button
> m_xOKBtn
;
63 std::unique_ptr
<weld::Button
> m_xApplyBtn
;
64 std::unique_ptr
<weld::Button
> m_xUserBtn
;
65 std::unique_ptr
<weld::Button
> m_xCancelBtn
;
66 std::unique_ptr
<weld::Button
> m_xResetBtn
;
67 std::unique_ptr
<weld::Button
> m_xBaseFmtBtn
;
68 std::unique_ptr
<weld::SizeGroup
> m_xSizeGroup
;
70 std::unique_ptr
<SfxItemSet
> m_pSet
;
71 std::unique_ptr
<SfxItemSet
> m_pOutSet
;
72 std::unique_ptr
<TabDlg_Impl
> m_pImpl
;
73 std::unique_ptr
<sal_uInt16
[]> m_pRanges
;
75 bool m_bStandardPushed
;
77 DECL_DLLPRIVATE_LINK(ActivatePageHdl
, const OString
&, void);
78 DECL_DLLPRIVATE_LINK(DeactivatePageHdl
, const OString
&, bool);
79 SAL_DLLPRIVATE
void Start_Impl();
80 SAL_DLLPRIVATE
void CreatePages();
81 SAL_DLLPRIVATE
void setPreviewsToSamePlace();
85 virtual void RefreshInputSet();
86 virtual SfxItemSet
* CreateInputItemSet(const OString
& rName
);
87 virtual void PageCreated(const OString
&rName
, SfxTabPage
&rPage
);
89 std::unique_ptr
<SfxItemSet
> m_xExampleSet
;
90 SfxItemSet
* GetInputSetImpl();
91 SfxTabPage
* GetTabPage(const OString
& rPageId
) const;
93 /** prepare to leave the current page. Calls the DeactivatePage method of the current page, (if necessary),
94 handles the item sets to copy.
95 @return sal_True if it is allowed to leave the current page, sal_False otherwise
97 bool PrepareLeaveCurrentPage();
99 /** save the position of the TabDialog and which tab page is the currently active one
103 SfxTabDialogController(weld::Window
* pParent
, const OUString
& rUIXMLDescription
, const OString
& rID
,
104 const SfxItemSet
* = nullptr, bool bEditFmt
= false);
105 virtual ~SfxTabDialogController() override
;
107 void AddTabPage(const OString
& rName
, // Name of the label for the existing page in the notebook .ui
108 CreateTabPage pCreateFunc
, // != 0
109 GetTabPageRanges pRangesFunc
); // can be 0
111 void AddTabPage(const OString
& rName
, // Name of the label for the existing page in the notebook .ui
112 sal_uInt16 nPageCreateId
); // Identifier of the Factory Method to create the page
114 void AddTabPage(const OString
& rName
, // Name of the label for the new page to create
115 const OUString
& rLabel
, // UI Label for the new page to create
116 CreateTabPage pCreateFunc
); // != 0
118 void AddTabPage(const OString
& rName
, // Name of the label for the new page to create
119 const OUString
& rLabel
, // UI Label for the new page to create
120 sal_uInt16 nPageCreateId
); // Identifier of the Factory Method to create the page
122 void RemoveTabPage( const OString
& rName
); // Name of the label for the page in the notebook .ui
124 void SetCurPageId(const OString
& rName
);
125 void ShowPage(const OString
& rName
); // SetCurPageId + call Activate on it
126 OString
GetCurPageId() const;
127 SfxTabPage
* GetCurTabPage() const { return GetTabPage(GetCurPageId()); }
129 // may provide local slots converted by Map
130 const sal_uInt16
* GetInputRanges( const SfxItemPool
& );
131 void SetInputSet( const SfxItemSet
* pInSet
);
132 const SfxItemSet
* GetOutputItemSet() const { return m_pOutSet
.get(); }
134 virtual weld::Button
& GetOKButton() const override
{ return *m_xOKBtn
; }
135 weld::Button
& GetCancelButton() const { return *m_xCancelBtn
; }
136 weld::Button
* GetUserButton() const { return m_xUserBtn
.get(); }
137 void RemoveResetButton();
138 void RemoveStandardButton();
140 virtual short run() override
;
141 static bool runAsync(const std::shared_ptr
<SfxTabDialogController
>& rController
,
142 const std::function
<void(sal_Int32
)>&);
144 virtual const SfxItemSet
* GetExampleSet() const override
{ return m_xExampleSet
.get(); }
146 void SetApplyHandler(const Link
<weld::Button
&,void>& _rHdl
);
148 //calls Ok without closing dialog
150 void Applied() { m_xExampleSet
->Put(*GetInputSetImpl()); }
153 std::vector
<OString
> getAllPageUIXMLDescriptions() const;
154 bool selectPageByUIXMLDescription(const OString
& rUIXMLDescription
);
155 BitmapEx
createScreenshot() const;
156 OString
GetScreenshotId() const;
159 enum class DeactivateRC
{
160 KeepPage
= 0x00, // Error handling; page does not change
161 // 2. Fill an itemset for update
162 // parent examples, this pointer can be NULL all the time!
164 // Set, refresh and update other Page
168 template<> struct typed_flags
<DeactivateRC
> : is_typed_flags
<DeactivateRC
, 0x03> {};
171 class SFX2_DLLPUBLIC SfxTabPage
: public BuilderPage
173 friend class SfxTabDialog
;
174 friend class SfxTabDialogController
;
177 const SfxItemSet
* pSet
;
178 OUString aUserString
;
179 bool bHasExchangeSupport
;
180 std::unique_ptr
< TabPageImpl
> pImpl
;
183 SfxTabPage(weld::Container
* pPage
, weld::DialogController
* pController
, const OUString
& rUIXMLDescription
, const OString
& rID
, const SfxItemSet
*rAttrSet
);
185 sal_uInt16
GetWhich( sal_uInt16 nSlot
, bool bDeep
= true ) const
186 { return pSet
->GetPool()->GetWhich( nSlot
, bDeep
); }
187 const SfxPoolItem
* GetOldItem( const SfxItemSet
& rSet
, sal_uInt16 nSlot
, bool bDeep
= true );
188 template<class T
> const T
* GetOldItem( const SfxItemSet
& rSet
, TypedWhichId
<T
> nSlot
, bool bDeep
= true )
190 return static_cast<const T
*>(GetOldItem(rSet
, sal_uInt16(nSlot
), bDeep
));
193 SfxOkDialogController
* GetDialogController() const;
195 void SetDialogController(SfxOkDialogController
* pDialog
);
197 virtual ~SfxTabPage() override
;
199 void set_visible(bool bVisible
)
201 m_xContainer
->set_visible(bVisible
);
204 const SfxItemSet
& GetItemSet() const { return *pSet
; }
206 virtual bool FillItemSet( SfxItemSet
* );
207 virtual void Reset( const SfxItemSet
* );
209 bool HasExchangeSupport() const
210 { return bHasExchangeSupport
; }
211 void SetExchangeSupport()
212 { bHasExchangeSupport
= true; }
214 virtual void ActivatePage( const SfxItemSet
& );
215 virtual DeactivateRC
DeactivatePage( SfxItemSet
* pSet
);
216 void SetUserData(const OUString
& rString
)
217 { aUserString
= rString
; }
218 const OUString
& GetUserData() const { return aUserString
; }
219 virtual void FillUserData();
220 virtual bool IsReadOnly() const;
221 virtual void PageCreated (const SfxAllItemSet
& aSet
);
222 virtual void ChangesApplied();
223 static const SfxPoolItem
* GetItem( const SfxItemSet
& rSet
, sal_uInt16 nSlot
, bool bDeep
= true );
224 template<class T
> static const T
* GetItem( const SfxItemSet
& rSet
, TypedWhichId
<T
> nSlot
, bool bDeep
= true )
226 return static_cast<const T
*>(GetItem(rSet
, sal_uInt16(nSlot
), bDeep
));
229 void SetFrame(const css::uno::Reference
< css::frame::XFrame
>& xFrame
);
230 css::uno::Reference
< css::frame::XFrame
> GetFrame() const;
232 const SfxItemSet
* GetDialogExampleSet() const;
234 OString
GetHelpId() const;
235 OString
GetConfigId() const { return GetHelpId(); }
236 bool IsVisible() const { return m_xContainer
->get_visible(); }
238 weld::Window
* GetFrameWeld() const;
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */