Avoid potential negative array index access to cached text.
[LibreOffice.git] / include / sfx2 / tabdlg.hxx
blob1b2bbadd999f7000089a38cf22353eb9d094becb
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 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
48 #define RET_USER_CANCEL 101
50 class SFX2_DLLPUBLIC SfxTabDialogItem final : public SfxSetItem
52 public:
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
60 protected:
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);
68 private:
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();
91 protected:
92 virtual short Ok();
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
112 void SavePosAndId();
113 public:
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(); }
144 const SfxItemSet* GetInputItemSet() const { return m_pSet.get(); }
146 virtual weld::Button& GetOKButton() const override { return *m_xOKBtn; }
147 weld::Button& GetCancelButton() const { return *m_xCancelBtn; }
148 weld::Button* GetUserButton() const { return m_xUserBtn.get(); }
149 weld::Button* GetStandardButton() const { return m_xBaseFmtBtn.get(); }
150 weld::Button* GetApplyButton() const { return m_xApplyBtn.get(); }
151 weld::Button* GetResetButton() const { return m_xResetBtn.get(); }
152 void RemoveResetButton();
153 void RemoveStandardButton();
155 virtual short run() override;
156 static bool runAsync(const std::shared_ptr<SfxTabDialogController>& rController,
157 const std::function<void(sal_Int32)>&);
159 virtual const SfxItemSet* GetExampleSet() const override { return m_xExampleSet.get(); }
161 void SetApplyHandler(const Link<weld::Button&,void>& _rHdl);
163 //calls Ok without closing dialog
164 bool Apply();
165 void Applied() { m_xExampleSet->Put(*GetInputSetImpl()); }
167 //screenshotting
168 std::vector<OUString> getAllPageUIXMLDescriptions() const;
169 bool selectPageByUIXMLDescription(const OUString& rUIXMLDescription);
170 BitmapEx createScreenshot() const;
171 OUString GetScreenshotId() const;
174 enum class DeactivateRC {
175 KeepPage = 0x00, // Error handling; page does not change
176 // 2. Fill an itemset for update
177 // parent examples, this pointer can be NULL all the time!
178 LeavePage = 0x01,
179 // Set, refresh and update other Page
180 RefreshSet = 0x02
182 namespace o3tl {
183 template<> struct typed_flags<DeactivateRC> : is_typed_flags<DeactivateRC, 0x03> {};
186 class SFX2_DLLPUBLIC SfxTabPage : public BuilderPage
188 friend class SfxTabDialog;
189 friend class SfxTabDialogController;
191 private:
192 const SfxItemSet* mpSet;
193 OUString maUserString;
194 bool mbHasExchangeSupport;
195 std::unordered_map<OUString, css::uno::Any> maAdditionalProperties;
197 std::unique_ptr<TabPageImpl> mpImpl;
199 protected:
200 SfxTabPage(weld::Container* pPage, weld::DialogController* pController, const OUString& rUIXMLDescription, const OUString& rID, const SfxItemSet *rAttrSet);
202 sal_uInt16 GetWhich( sal_uInt16 nSlot, bool bDeep = true ) const
204 return mpSet->GetPool()->GetWhich(nSlot, bDeep);
206 template<class T>
207 TypedWhichId<T> GetWhich( TypedWhichId<T> nSlot, bool bDeep = true ) const
209 return TypedWhichId<T>(GetWhich(sal_uInt16(nSlot), bDeep));
212 const SfxPoolItem* GetOldItem( const SfxItemSet& rSet, sal_uInt16 nSlot, bool bDeep = true );
213 template<class T> const T* GetOldItem( const SfxItemSet& rSet, TypedWhichId<T> nSlot, bool bDeep = true )
215 return static_cast<const T*>(GetOldItem(rSet, sal_uInt16(nSlot), bDeep));
218 SfxOkDialogController* GetDialogController() const;
219 public:
220 void SetDialogController(SfxOkDialogController* pDialog);
221 public:
222 virtual ~SfxTabPage() override;
224 void set_visible(bool bVisible)
226 m_xContainer->set_visible(bVisible);
229 const SfxItemSet& GetItemSet() const
231 return *mpSet;
234 virtual bool FillItemSet( SfxItemSet* );
235 virtual void Reset( const SfxItemSet* );
236 // Allows to postpone some initialization to the first activation
237 virtual bool DeferResetToFirstActivation();
239 bool HasExchangeSupport() const
241 return mbHasExchangeSupport;
244 void SetExchangeSupport()
246 mbHasExchangeSupport = true;
249 virtual void ActivatePage( const SfxItemSet& );
250 virtual DeactivateRC DeactivatePage( SfxItemSet* pSet );
251 void SetUserData(const OUString& rString)
253 maUserString = rString;
255 const OUString& GetUserData() const
257 return maUserString;
259 virtual void FillUserData();
260 virtual bool IsReadOnly() const;
261 virtual void PageCreated (const SfxAllItemSet& aSet);
262 virtual void ChangesApplied();
263 static const SfxPoolItem* GetItem( const SfxItemSet& rSet, sal_uInt16 nSlot, bool bDeep = true );
264 template<class T> static const T* GetItem( const SfxItemSet& rSet, TypedWhichId<T> nSlot, bool bDeep = true )
266 return static_cast<const T*>(GetItem(rSet, sal_uInt16(nSlot), bDeep));
269 virtual OUString GetAllStrings();
270 void SetFrame(const css::uno::Reference< css::frame::XFrame >& xFrame);
271 css::uno::Reference< css::frame::XFrame > GetFrame() const;
273 const SfxItemSet* GetDialogExampleSet() const;
275 OUString GetHelpId() const;
276 OUString GetConfigId() const { return GetHelpId(); }
277 bool IsVisible() const { return m_xContainer->get_visible(); }
279 weld::Window* GetFrameWeld() const;
281 std::unordered_map<OUString, css::uno::Any>& getAdditionalProperties()
283 return maAdditionalProperties;
287 #endif
289 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */