Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/sfx2/tabdlg.hxx
Line
Count
Source
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
#pragma once
20
21
#include <memory>
22
#include <string_view>
23
#include <set>
24
25
#include <sal/config.h>
26
#include <sfx2/SfxTabPage.hxx>
27
#include <sfx2/dllapi.h>
28
#include <sfx2/basedlgs.hxx>
29
#include <sal/types.h>
30
#include <vcl/builderpage.hxx>
31
#include <svl/itempool.hxx>
32
#include <svl/itemset.hxx>
33
#include <svl/setitem.hxx>
34
#include <o3tl/typed_flags_set.hxx>
35
#include <map>
36
37
class Bitmap;
38
class SfxTabPage;
39
40
typedef std::unique_ptr<SfxTabPage> (*CreateTabPage)(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *rAttrSet);
41
typedef const WhichRangesContainer & (*GetTabPageRanges)(); // provides international Which-value
42
43
struct TabDlg_Impl;
44
45
namespace weld
46
{
47
class Notebook;
48
class SizeGroup;
49
}
50
51
0
#define RET_USER        100
52
53
class SFX2_DLLPUBLIC SfxTabDialogItem final : public SfxSetItem
54
{
55
public:
56
                            DECLARE_ITEM_TYPE_FUNCTION(SfxTabDialogItem)
57
                            SfxTabDialogItem( sal_uInt16 nId, const SfxItemSet& rItemSet );
58
                            SfxTabDialogItem(const SfxTabDialogItem& rAttr, SfxItemPool* pItemPool);
59
    virtual SfxTabDialogItem* Clone(SfxItemPool* pToPool = nullptr) const override;
60
};
61
62
class SFX2_DLLPUBLIC SfxTabDialogController : public SfxOkDialogController
63
{
64
protected:
65
    std::unique_ptr<weld::Notebook> m_xTabCtrl;
66
67
    DECL_LINK(OkHdl, weld::Button&, void);
68
    DECL_DLLPRIVATE_LINK(ResetHdl, weld::Button&, void);
69
    DECL_DLLPRIVATE_LINK(BaseFmtHdl, weld::Button&, void);
70
    DECL_DLLPRIVATE_LINK(UserHdl, weld::Button&, void);
71
    DECL_DLLPRIVATE_LINK(CancelHdl, weld::Button&, void);
72
private:
73
    std::unique_ptr<weld::Button> m_xOKBtn;
74
    std::unique_ptr<weld::Button> m_xApplyBtn;
75
    std::unique_ptr<weld::Button> m_xUserBtn;
76
    std::unique_ptr<weld::Button> m_xCancelBtn;
77
    std::unique_ptr<weld::Button> m_xResetBtn;
78
    std::unique_ptr<weld::Button> m_xBaseFmtBtn;
79
    std::unique_ptr<weld::SizeGroup> m_xSizeGroup;
80
81
    std::unique_ptr<SfxItemSet>           m_pSet;
82
    std::unique_ptr<SfxItemSet>           m_pOutSet;
83
    std::unique_ptr<TabDlg_Impl>          m_pImpl;
84
    WhichRangesContainer                  m_pRanges;
85
    std::map<sal_uInt16, OUString>        m_aWhichToTabMap;
86
    OUString             m_sAppPageId;
87
    bool                m_bStandardPushed;
88
    std::unique_ptr<SfxAllItemSet>       m_xItemSet;
89
    std::map<sal_uInt16, int> m_aWhichOrderMap;
90
91
    DECL_DLLPRIVATE_LINK(ActivatePageHdl, const OUString&, void);
92
    DECL_DLLPRIVATE_LINK(DeactivatePageHdl, const OUString&, bool);
93
    SAL_DLLPRIVATE void Start_Impl();
94
    SAL_DLLPRIVATE void CreatePages();
95
    SAL_DLLPRIVATE void setPreviewsToSamePlace();
96
97
protected:
98
    virtual short               Ok();
99
    std::set<sal_uInt16>        m_aInvalidatedWhichIds;
100
    virtual void                RefreshInputSet();
101
    virtual SfxItemSet*         CreateInputItemSet(const OUString& rName);
102
    virtual void                PageCreated(const OUString &rName, SfxTabPage &rPage);
103
104
    virtual void ActivatePage(const OUString& rPage);
105
    bool DeactivatePage(std::u16string_view aPage);
106
107
    std::unique_ptr<SfxItemSet> m_xExampleSet;
108
    SfxItemSet*     GetInputSetImpl();
109
    SfxTabPage*     GetTabPage(std::u16string_view rPageId) const;
110
111
    /** prepare to leave the current page. Calls the DeactivatePage method of the current page, (if necessary),
112
        handles the item sets to copy.
113
        @return sal_True if it is allowed to leave the current page, sal_False otherwise
114
    */
115
    bool PrepareLeaveCurrentPage();
116
117
    /** Called before user cancels the dialog.
118
        Calls DeactivatePage of all tab pages with IsCancelMode() set to true
119
    */
120
    void PrepareCancel();
121
122
    /** save the position of the TabDialog and which tab page is the currently active one
123
     */
124
    void SavePosAndId();
125
public:
126
    SfxTabDialogController(weld::Widget* pParent, const OUString& rUIXMLDescription, const OUString& rID,
127
                           const SfxItemSet * = nullptr, bool bEditFmt = false);
128
    virtual ~SfxTabDialogController() override;
129
130
    void                AddTabPage(const OUString& rName,          // Name of the label for the existing page in the notebook .ui
131
                                   CreateTabPage pCreateFunc,      // != 0
132
                                   GetTabPageRanges pRangesFunc);  // can be 0
133
134
    void                AddTabPage(const OUString& rName,          // Name of the label for the existing page in the notebook .ui
135
                                   sal_uInt16 nPageCreateId);      // Identifier of the Factory Method to create the page
136
137
    void                AddTabPage(const OUString& rName,          // Name of the label for the new page to create
138
                                   const OUString& rLabel,         // UI Label for the new page to create
139
                                   CreateTabPage pCreateFunc,      // != 0
140
                                   GetTabPageRanges pRangesFunc = nullptr,
141
                                   const OUString* pIconName = nullptr);
142
143
    void                AddTabPage(const OUString& rName,          // Name of the label for the new page to create
144
                                   const OUString& rLabel,         // UI Label for the new page to create
145
                                   CreateTabPage pCreateFunc,      // != 0
146
                                   GetTabPageRanges pRangesFunc,
147
                                   const OUString& rIconName);
148
149
    void                AddTabPage(const OUString& rName,
150
                                   const OUString& rLabel,
151
                                   CreateTabPage pCreateFunc,
152
                                   const OUString& rIconName);
153
154
    void                AddTabPage(const OUString& rName,          // Name of the label for the new page to create
155
                                   const OUString& rLabel,         // UI Label for the new page to create
156
                                   sal_uInt16 nPageCreateId,       // Identifier of the Factory Method to create the page
157
                                   const OUString* pIconName = nullptr);
158
159
    void                AddTabPage(const OUString& rName,
160
                                   const OUString& rLabel,
161
                                   sal_uInt16 nPageCreateId,
162
                                   const OUString& rIconName);
163
164
    void                RemoveTabPage( const OUString& rName ); // Name of the label for the page in the notebook .ui
165
166
    void                SetCurPageId(const OUString& rName);
167
    void                ShowPage(const OUString& rName);  // SetCurPageId + call Activate on it
168
    OUString             GetCurPageId() const;
169
0
    SfxTabPage*         GetCurTabPage() const { return GetTabPage(GetCurPageId()); }
170
    void                InvalidateItem(sal_uInt16 nWhich);
171
    OUString            GetTabPageNameForWhich(sal_uInt16 nWhich) const;
172
    void                BuildWhichToTabMap();
173
    OUString            GetTabPageLabel(const OUString& rPageId) const;
174
    std::vector<OUString> GetTabPageIds() const;
175
0
    int GetWhichOrder(sal_uInt16 nWhich) const {
176
0
        auto it = m_aWhichOrderMap.find(nWhich);
177
0
        return it != m_aWhichOrderMap.end() ? it->second : INT_MAX;
178
0
    }
179
0
    const SfxItemSet* GetExampleSet() const override { return m_xExampleSet.get(); }
180
181
0
    const std::set<sal_uInt16>& GetInvalidatedWhichIds() const { return m_aInvalidatedWhichIds; }
182
183
    // may provide local slots converted by Map
184
    const WhichRangesContainer& GetInputRanges( const SfxItemPool& );
185
    void                SetInputSet( const SfxItemSet* pInSet );
186
0
    const SfxItemSet*   GetOutputItemSet() const { return m_pOutSet.get(); }
187
0
    const SfxItemSet*   GetInputItemSet() const { return m_pSet.get(); }
188
189
0
    virtual weld::Button& GetOKButton() const override { return *m_xOKBtn; }
190
0
    weld::Button&       GetCancelButton() const { return *m_xCancelBtn; }
191
0
    weld::Button*       GetUserButton() const { return m_xUserBtn.get(); }
192
0
    weld::Button*       GetStandardButton() const { return m_xBaseFmtBtn.get(); }
193
0
    weld::Button*       GetApplyButton() const { return m_xApplyBtn.get(); }
194
0
    weld::Button*       GetResetButton() const { return m_xResetBtn.get(); }
195
    void                RemoveStandardButton();
196
197
    virtual short       run() override;
198
    static bool runAsync(const std::shared_ptr<SfxTabDialogController>& rController,
199
                         const std::function<void(sal_Int32)>&);
200
201
    void                SetApplyHandler(const Link<weld::Button&,void>& _rHdl);
202
203
    //calls Ok without closing dialog
204
    bool Apply();
205
0
    void Applied() { m_xExampleSet->Put(*GetInputSetImpl()); }
206
207
    //screenshotting
208
    std::vector<OUString> getAllPageUIXMLDescriptions() const;
209
    bool selectPageByUIXMLDescription(const OUString& rUIXMLDescription);
210
    Bitmap createScreenshot() const;
211
    OUString GetScreenshotId() const;
212
213
private:
214
    auto Find(std::u16string_view rId) const;
215
};
216
217
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */