tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / include / sfx2 / tabdlg.hxx
blob6559416094a56c5f5706cf49f2b6e9cdeb689c34
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
22 #include <memory>
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>
37 class SfxTabPage;
39 typedef std::unique_ptr<SfxTabPage> (*CreateTabPage)(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *rAttrSet);
40 typedef const WhichRangesContainer & (*GetTabPageRanges)(); // provides international Which-value
41 struct TabPageImpl;
43 struct TabDlg_Impl;
45 namespace com::sun::star::frame { class XFrame; }
47 #define RET_USER 100
49 class SFX2_DLLPUBLIC SfxTabDialogItem final : public SfxSetItem
51 public:
52 SfxTabDialogItem( sal_uInt16 nId, const SfxItemSet& rItemSet );
53 SfxTabDialogItem(const SfxTabDialogItem& rAttr, SfxItemPool* pItemPool);
54 virtual SfxTabDialogItem* Clone(SfxItemPool* pToPool = nullptr) const override;
57 class SFX2_DLLPUBLIC SfxTabDialogController : public SfxOkDialogController
59 protected:
60 std::unique_ptr<weld::Notebook> m_xTabCtrl;
62 DECL_LINK(OkHdl, weld::Button&, void);
63 DECL_DLLPRIVATE_LINK(ResetHdl, weld::Button&, void);
64 DECL_DLLPRIVATE_LINK(BaseFmtHdl, weld::Button&, void);
65 DECL_DLLPRIVATE_LINK(UserHdl, weld::Button&, void);
66 DECL_DLLPRIVATE_LINK(CancelHdl, weld::Button&, void);
67 private:
68 std::unique_ptr<weld::Button> m_xOKBtn;
69 std::unique_ptr<weld::Button> m_xApplyBtn;
70 std::unique_ptr<weld::Button> m_xUserBtn;
71 std::unique_ptr<weld::Button> m_xCancelBtn;
72 std::unique_ptr<weld::Button> m_xResetBtn;
73 std::unique_ptr<weld::Button> m_xBaseFmtBtn;
74 std::unique_ptr<weld::SizeGroup> m_xSizeGroup;
76 std::unique_ptr<SfxItemSet> m_pSet;
77 std::unique_ptr<SfxItemSet> m_pOutSet;
78 std::unique_ptr<TabDlg_Impl> m_pImpl;
79 WhichRangesContainer m_pRanges;
80 OUString m_sAppPageId;
81 bool m_bStandardPushed;
82 std::unique_ptr<SfxAllItemSet> m_xItemSet;
84 DECL_DLLPRIVATE_LINK(ActivatePageHdl, const OUString&, void);
85 DECL_DLLPRIVATE_LINK(DeactivatePageHdl, const OUString&, bool);
86 SAL_DLLPRIVATE void Start_Impl();
87 SAL_DLLPRIVATE void CreatePages();
88 SAL_DLLPRIVATE void setPreviewsToSamePlace();
90 protected:
91 virtual short Ok();
92 virtual void RefreshInputSet();
93 virtual SfxItemSet* CreateInputItemSet(const OUString& rName);
94 virtual void PageCreated(const OUString &rName, SfxTabPage &rPage);
96 virtual void ActivatePage(const OUString& rPage);
97 bool DeactivatePage(std::u16string_view aPage);
99 std::unique_ptr<SfxItemSet> m_xExampleSet;
100 SfxItemSet* GetInputSetImpl();
101 SfxTabPage* GetTabPage(std::u16string_view rPageId) const;
103 /** prepare to leave the current page. Calls the DeactivatePage method of the current page, (if necessary),
104 handles the item sets to copy.
105 @return sal_True if it is allowed to leave the current page, sal_False otherwise
107 bool PrepareLeaveCurrentPage();
109 /** Called before user cancels the dialog.
110 Calls DeactivatePage of all tab pages with IsCancelMode() set to true
112 void PrepareCancel();
114 /** save the position of the TabDialog and which tab page is the currently active one
116 void SavePosAndId();
117 public:
118 SfxTabDialogController(weld::Widget* pParent, const OUString& rUIXMLDescription, const OUString& rID,
119 const SfxItemSet * = nullptr, bool bEditFmt = false);
120 virtual ~SfxTabDialogController() override;
122 void AddTabPage(const OUString& rName, // Name of the label for the existing page in the notebook .ui
123 CreateTabPage pCreateFunc, // != 0
124 GetTabPageRanges pRangesFunc); // can be 0
126 void AddTabPage(const OUString& rName, // Name of the label for the existing page in the notebook .ui
127 sal_uInt16 nPageCreateId); // Identifier of the Factory Method to create the page
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 CreateTabPage pCreateFunc); // != 0
133 void AddTabPage(const OUString& rName, // Name of the label for the new page to create
134 const OUString& rLabel, // UI Label for the new page to create
135 sal_uInt16 nPageCreateId); // Identifier of the Factory Method to create the page
137 void RemoveTabPage( const OUString& rName ); // Name of the label for the page in the notebook .ui
139 void SetCurPageId(const OUString& rName);
140 void ShowPage(const OUString& rName); // SetCurPageId + call Activate on it
141 OUString GetCurPageId() const;
142 SfxTabPage* GetCurTabPage() const { return GetTabPage(GetCurPageId()); }
144 // may provide local slots converted by Map
145 const WhichRangesContainer& GetInputRanges( const SfxItemPool& );
146 void SetInputSet( const SfxItemSet* pInSet );
147 const SfxItemSet* GetOutputItemSet() const { return m_pOutSet.get(); }
148 const SfxItemSet* GetInputItemSet() const { return m_pSet.get(); }
150 virtual weld::Button& GetOKButton() const override { return *m_xOKBtn; }
151 weld::Button& GetCancelButton() const { return *m_xCancelBtn; }
152 weld::Button* GetUserButton() const { return m_xUserBtn.get(); }
153 weld::Button* GetStandardButton() const { return m_xBaseFmtBtn.get(); }
154 weld::Button* GetApplyButton() const { return m_xApplyBtn.get(); }
155 weld::Button* GetResetButton() const { return m_xResetBtn.get(); }
156 void RemoveResetButton();
157 void RemoveStandardButton();
159 virtual short run() override;
160 static bool runAsync(const std::shared_ptr<SfxTabDialogController>& rController,
161 const std::function<void(sal_Int32)>&);
163 virtual const SfxItemSet* GetExampleSet() const override { return m_xExampleSet.get(); }
165 void SetApplyHandler(const Link<weld::Button&,void>& _rHdl);
167 //calls Ok without closing dialog
168 bool Apply();
169 void Applied() { m_xExampleSet->Put(*GetInputSetImpl()); }
171 //screenshotting
172 std::vector<OUString> getAllPageUIXMLDescriptions() const;
173 bool selectPageByUIXMLDescription(const OUString& rUIXMLDescription);
174 BitmapEx createScreenshot() const;
175 OUString GetScreenshotId() const;
178 enum class DeactivateRC {
179 KeepPage = 0x00, // Error handling; page does not change
180 // 2. Fill an itemset for update
181 // parent examples, this pointer can be NULL all the time!
182 LeavePage = 0x01,
183 // Set, refresh and update other Page
184 RefreshSet = 0x02
186 namespace o3tl {
187 template<> struct typed_flags<DeactivateRC> : is_typed_flags<DeactivateRC, 0x03> {};
190 class SFX2_DLLPUBLIC SfxTabPage : public BuilderPage
192 friend class SfxTabDialog;
193 friend class SfxTabDialogController;
195 private:
196 const SfxItemSet* mpSet;
197 OUString maUserString;
198 bool mbHasExchangeSupport;
199 bool mbCancel;
200 std::unordered_map<OUString, css::uno::Any> maAdditionalProperties;
202 std::unique_ptr<TabPageImpl> mpImpl;
204 protected:
205 SfxTabPage(weld::Container* pPage, weld::DialogController* pController, const OUString& rUIXMLDescription, const OUString& rID, const SfxItemSet *rAttrSet);
207 sal_uInt16 GetWhich( sal_uInt16 nSlot, bool bDeep = true ) const
209 return mpSet->GetPool()->GetWhichIDFromSlotID(nSlot, bDeep);
211 template<class T>
212 TypedWhichId<T> GetWhich( TypedWhichId<T> nSlot, bool bDeep = true ) const
214 return TypedWhichId<T>(GetWhich(sal_uInt16(nSlot), bDeep));
217 const SfxPoolItem* GetOldItem( const SfxItemSet& rSet, sal_uInt16 nSlot, bool bDeep = true );
218 template<class T> const T* GetOldItem( const SfxItemSet& rSet, TypedWhichId<T> nSlot, bool bDeep = true )
220 return static_cast<const T*>(GetOldItem(rSet, sal_uInt16(nSlot), bDeep));
223 SfxOkDialogController* GetDialogController() const;
224 public:
225 void SetDialogController(SfxOkDialogController* pDialog);
226 public:
227 virtual ~SfxTabPage() override;
229 void set_visible(bool bVisible)
231 m_xContainer->set_visible(bVisible);
234 const SfxItemSet& GetItemSet() const
236 return *mpSet;
239 virtual bool FillItemSet( SfxItemSet* );
240 virtual void Reset( const SfxItemSet* );
241 // Allows to postpone some initialization to the first activation
242 virtual bool DeferResetToFirstActivation();
244 bool HasExchangeSupport() const
246 return mbHasExchangeSupport;
249 void SetExchangeSupport()
251 mbHasExchangeSupport = true;
254 virtual void ActivatePage( const SfxItemSet& );
255 virtual DeactivateRC DeactivatePage( SfxItemSet* pSet );
256 void SetUserData(const OUString& rString)
258 maUserString = rString;
260 const OUString& GetUserData() const
262 return maUserString;
264 virtual void FillUserData();
265 virtual bool IsReadOnly() const;
266 // Whether the user has canceled the dialog. Allows to restore settings, etc.
267 bool IsCancelMode() { return mbCancel; }
268 void SetCancelMode(bool bCancel) { mbCancel = bCancel; }
269 virtual void PageCreated (const SfxAllItemSet& aSet);
270 virtual void ChangesApplied();
271 static const SfxPoolItem* GetItem( const SfxItemSet& rSet, sal_uInt16 nSlot, bool bDeep = true );
272 template<class T> static const T* GetItem( const SfxItemSet& rSet, TypedWhichId<T> nSlot, bool bDeep = true )
274 return static_cast<const T*>(GetItem(rSet, sal_uInt16(nSlot), bDeep));
277 virtual OUString GetAllStrings();
278 void SetFrame(const css::uno::Reference< css::frame::XFrame >& xFrame);
279 css::uno::Reference< css::frame::XFrame > GetFrame() const;
281 const SfxItemSet* GetDialogExampleSet() const;
283 OUString GetHelpId() const;
284 OUString GetConfigId() const { return GetHelpId(); }
285 bool IsVisible() const { return m_xContainer->get_visible(); }
287 weld::Window* GetFrameWeld() const;
289 std::unordered_map<OUString, css::uno::Any>& getAdditionalProperties()
291 return maAdditionalProperties;
295 #endif
297 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */