Coverage Report

Created: 2026-07-10 11:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sd/source/ui/inc/ViewTabBar.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
20
#pragma once
21
22
#include "framework/AbstractResource.hxx"
23
#include "framework/ConfigurationChangeListener.hxx"
24
#include <ResourceId.hxx>
25
#include <comphelper/compbase.hxx>
26
#include <vcl/InterimItemWindow.hxx>
27
#include <vcl/weld/Notebook.hxx>
28
29
#include <vector>
30
31
namespace vcl { class Window; }
32
33
namespace sd {
34
    class DrawController;
35
    class ViewShellBase;
36
    class ViewTabBar;
37
}
38
namespace sd::framework { class ConfigurationController; }
39
namespace sd::framework { class ResourceId; }
40
41
namespace sd {
42
43
class TabBarControl final : public InterimItemWindow
44
{
45
public:
46
    TabBarControl(vcl::Window* pParentWindow, ::rtl::Reference<ViewTabBar> pViewTabBar);
47
    virtual void dispose() override;
48
    virtual ~TabBarControl() override;
49
0
    weld::Notebook& GetNotebook() { return *mxTabControl; }
50
0
    int GetAllocatedWidth() const { return mnAllocatedWidth; }
51
private:
52
    std::unique_ptr<weld::Notebook> mxTabControl;
53
    ::rtl::Reference<ViewTabBar> mpViewTabBar;
54
    int mnAllocatedWidth;
55
56
    DECL_LINK(ActivatePageHdl, const OUString&, void);
57
    DECL_LINK(NotebookSizeAllocHdl, const Size&, void);
58
};
59
60
/** Descriptor of a tab bar button.  Tab bar buttons are typically used to
61
    offer the user the choice between different views to be displayed in
62
    one pane.
63
    <p>For identification only the #ResourceId is used, so for
64
    some methods of the XTabBar interface only the
65
    #ResourceId member is evaluated.</p>
66
*/
67
struct TabBarButton
68
{
69
    /** This label is displayed on the UI as button text.
70
        <p>The label is expected to be localized.</p>
71
    */
72
    OUString ButtonLabel;
73
74
    /** ResourceId object of the resource that is requested to be
75
        displayed when the tab bar button is activated.
76
        <p>For some methods of the XTabBar interface only this
77
        member is evaluated.  That is because only this member is used to
78
        identify a tab bar button.</p>
79
    */
80
    rtl::Reference<sd::framework::ResourceId> ResourceId;
81
};
82
83
84
/** Tab control for switching between views in the center pane.
85
86
    UI control for the selection of views in a pane.
87
    <p>Every tab of a tab bar has, besides its localized title and help
88
    text, the URL of a view.  A possible alternative would be to use a
89
    command URL instead of the view URL.</p>
90
    <p>In the current Impress implementation a tab bar is only used for the
91
    center pane to switch between views in the center pane.  Tab bars can
92
    make sense for other panes as well, i.e. for showing either the slide
93
    sorter or the outline view in the left pane.</p>
94
    <p>Tab bar buttons are identified by their resource id.  Note that
95
    because the resource anchors are all the same (the tab bar), it is the
96
    resource URL that really identifies a button. There can not be two
97
    buttons with the same resource id.</p>
98
    </p>
99
    <p>A better place for this interface (in an extended version) would be
100
    <code>com::sun::star::awt</code></p>
101
    @see TabBarButton
102
*/
103
class ViewTabBar final
104
    : public sd::framework::AbstractResource
105
{
106
public:
107
    ViewTabBar (
108
        const rtl::Reference<framework::ResourceId>& rxViewTabBarId,
109
        const rtl::Reference< ::sd::DrawController>& rxController);
110
    virtual ~ViewTabBar() override;
111
112
    virtual void disposing(std::unique_lock<std::mutex>&) override;
113
114
0
    const VclPtr<TabBarControl>& GetTabControl() const { return mpTabControl; }
115
116
    bool ActivatePage(size_t nIndex);
117
118
    /** Add a tab bar button to the right of another one.
119
        @param aButton
120
            The new tab bar button that is to be inserted.  If a button with
121
            the same resource id is already present than that is removed before the
122
            new button is inserted.
123
        @param aAnchor
124
            The new button is inserted to the right of this button.  When
125
            its ResourceId is empty then the new button is inserted at the left
126
            most position.
127
    */
128
    void
129
        addTabBarButtonAfter (
130
            const TabBarButton& rButton,
131
            const TabBarButton& rAnchor);
132
133
    /** Test whether the specified button exists in the tab bar.
134
        @param aButton
135
            The tab bar button whose existence is tested.
136
        @return
137
            Returns `TRUE` when the button exists.
138
    */
139
    bool
140
        hasTabBarButton (
141
            const TabBarButton& rButton);
142
143
    //----- AbstractResource ---------------------------------------------------------
144
145
    virtual rtl::Reference<framework::ResourceId> getResourceId() override;
146
147
    virtual bool isAnchorOnly() override;
148
149
    /** The returned value is calculated as the difference between the
150
        total height of the control and the height of its first tab page.
151
        This can be considered a hack.
152
        This procedure works only when the control is visible.  Calling this
153
        method when the control is not visible results in returning a
154
        default value.
155
        To be on the safe side wait for this control to become visible and
156
        the call this method again.
157
    */
158
    int GetHeight() const;
159
160
    void UpdateActiveButton();
161
162
    void AddTabBarButton (
163
        const TabBarButton& rButton,
164
        const TabBarButton& rAnchor);
165
    bool HasTabBarButton (
166
        const TabBarButton& rButton);
167
168
private:
169
    class Listener : public sd::framework::ConfigurationChangeListener
170
    {
171
    public:
172
0
        Listener(ViewTabBar& rParent) : mrParent(rParent) {}
173
174
        //----- sd::framework::ConfigurationChangeListener ------------------
175
        virtual void
176
            notifyConfigurationChange (
177
                const sd::framework::ConfigurationChangeEvent& rEvent) override;
178
179
        //----- XEventListener ----------------------------------------------------
180
        using WeakComponentImplHelperBase::disposing;
181
        virtual void SAL_CALL disposing(
182
            const css::lang::EventObject& rEvent) override;
183
    private:
184
        ViewTabBar& mrParent;
185
    };
186
    rtl::Reference<Listener> mxListener;
187
    VclPtr<TabBarControl> mpTabControl;
188
    rtl::Reference<::sd::DrawController> mxController;
189
    rtl::Reference<::sd::framework::ConfigurationController> mxConfigurationController;
190
    typedef ::std::vector<TabBarButton> TabBarButtonList;
191
    TabBarButtonList maTabBarButtons;
192
    rtl::Reference<sd::framework::ResourceId> mxViewTabBarId;
193
    ViewShellBase* mpViewShellBase;
194
    int mnNoteBookWidthPadding;
195
196
    void AddTabBarButton (
197
        const TabBarButton& rButton,
198
        sal_Int32 nPosition);
199
    void UpdateTabBarButtons();
200
201
    /** This method is called from the constructor to get the window for an
202
        anchor ResourceId and pass it to our base class.  It has to be
203
        static because it must not access any of the, not yet initialized
204
        members.
205
    */
206
    static vcl::Window* GetAnchorWindow(
207
        const rtl::Reference<sd::framework::ResourceId>& rxViewTabBarId,
208
        const rtl::Reference<::sd::DrawController>& rxController);
209
};
210
211
} // end of namespace sd
212
213
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */