Coverage Report

Created: 2026-08-14 10:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sd/source/ui/sidebar/AllMasterPagesSelector.cxx
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
#include "AllMasterPagesSelector.hxx"
21
#include <ViewShellBase.hxx>
22
#include "MasterPageContainer.hxx"
23
#include "MasterPageDescriptor.hxx"
24
#include <helpids.h>
25
26
#include <set>
27
28
namespace {
29
30
using namespace sd::sidebar;
31
32
int GetURLPriority (const SharedMasterPageDescriptor& rpDescriptor)
33
0
{
34
0
    int nPriority (0);
35
0
    switch (rpDescriptor->GetURLClassification())
36
0
    {
37
0
        case MasterPageDescriptor::URLCLASS_USER:         nPriority = 0; break;
38
0
        case MasterPageDescriptor::URLCLASS_LAYOUT:       nPriority = 1; break;
39
0
        case MasterPageDescriptor::URLCLASS_PRESENTATION: nPriority = 2; break;
40
0
        case MasterPageDescriptor::URLCLASS_OTHER:        nPriority = 3; break;
41
0
        case MasterPageDescriptor::URLCLASS_UNKNOWN:      nPriority = 4; break;
42
0
        default:
43
0
        case MasterPageDescriptor::URLCLASS_UNDETERMINED: nPriority = 5; break;
44
0
    }
45
0
    return nPriority;
46
0
}
47
48
class MasterPageDescriptorOrder
49
{
50
public:
51
    bool operator() (
52
        const SharedMasterPageDescriptor& rp1,
53
        const SharedMasterPageDescriptor& rp2) const
54
0
    {
55
0
        if (rp1->meOrigin == MasterPageContainer::DEFAULT)
56
0
            return true;
57
0
        else if (rp2->meOrigin == MasterPageContainer::DEFAULT)
58
0
            return false;
59
0
        else if (rp1->GetURLClassification() == rp2->GetURLClassification())
60
0
            return rp1->mnTemplateIndex < rp2->mnTemplateIndex;
61
0
        else
62
0
            return GetURLPriority(rp1) < GetURLPriority(rp2);
63
0
    }
64
};
65
66
} // end of anonymous namespace
67
68
namespace sd::sidebar {
69
70
class AllMasterPagesSelector::SortedMasterPageDescriptorList
71
    : public ::std::set<SharedMasterPageDescriptor,MasterPageDescriptorOrder>
72
{
73
public:
74
0
    SortedMasterPageDescriptorList() {}
75
};
76
77
std::unique_ptr<PanelLayout> AllMasterPagesSelector::Create (
78
    weld::Widget* pParent,
79
    ViewShellBase& rViewShellBase,
80
    const css::uno::Reference<css::ui::XSidebar>& rxSidebar)
81
0
{
82
0
    SdDrawDocument* pDocument = rViewShellBase.GetDocument();
83
0
    if (pDocument == nullptr)
84
0
        return nullptr;
85
86
0
    auto pContainer = std::make_shared<MasterPageContainer>();
87
88
0
    auto xSelector(std::make_unique<AllMasterPagesSelector>(
89
0
            pParent,
90
0
            *pDocument,
91
0
            rViewShellBase,
92
0
            pContainer,
93
0
            rxSidebar));
94
0
    xSelector->SetHelpId(HID_SD_TASK_PANE_PREVIEW_ALL);
95
96
0
    return xSelector;
97
0
}
98
99
AllMasterPagesSelector::AllMasterPagesSelector(
100
    weld::Widget* pParent, SdDrawDocument& rDocument, ViewShellBase& rBase,
101
    const std::shared_ptr<MasterPageContainer>& rpContainer,
102
    const css::uno::Reference<css::ui::XSidebar>& rxSidebar)
103
0
    : MasterPagesSelector(pParent, rDocument, rBase, rpContainer, rxSidebar,
104
0
                          u"modules/simpress/ui/masterpagepanelall.ui"_ustr,
105
0
                          u"masterpageall_icons"_ustr)
106
0
    , mpSortedMasterPages(new SortedMasterPageDescriptorList())
107
0
{
108
0
}
109
110
AllMasterPagesSelector::AllMasterPagesSelector(
111
    weld::Widget* pParent, SdDrawDocument& rDocument, ViewShellBase& rBase,
112
    const std::shared_ptr<MasterPageContainer>& rpContainer)
113
0
    : MasterPagesSelector(pParent, rDocument, rBase, rpContainer,
114
0
                          u"modules/simpress/ui/masterpagepanelall.ui"_ustr,
115
0
                          u"masterpageall_icons"_ustr)
116
0
    , mpSortedMasterPages(new SortedMasterPageDescriptorList())
117
0
{
118
0
}
119
120
121
AllMasterPagesSelector::~AllMasterPagesSelector()
122
0
{
123
0
}
124
125
void AllMasterPagesSelector::Fill (ItemList& rItemList)
126
0
{
127
0
    if (mpSortedMasterPages->empty())
128
0
        UpdateMasterPageList();
129
0
    UpdatePageSet(rItemList);
130
0
}
131
132
void AllMasterPagesSelector::NotifyContainerChangeEvent (
133
    const MasterPageContainerChangeEvent& rEvent)
134
0
{
135
0
    switch (rEvent.meEventType)
136
0
    {
137
0
        case MasterPageContainerChangeEvent::EventType::CHILD_ADDED:
138
0
            AddItem(rEvent.maChildToken);
139
0
            MasterPagesSelector::Fill();
140
0
            break;
141
142
0
        case MasterPageContainerChangeEvent::EventType::INDEX_CHANGED:
143
0
            mpSortedMasterPages->clear();
144
0
            MasterPagesSelector::Fill();
145
0
            break;
146
147
0
        default:
148
0
            MasterPagesSelector::NotifyContainerChangeEvent(rEvent);
149
0
            break;
150
0
    }
151
0
}
152
153
void AllMasterPagesSelector::UpdateMasterPageList()
154
0
{
155
0
    mpSortedMasterPages->clear();
156
0
    int nTokenCount = mpContainer->GetTokenCount();
157
0
    for (int i=0; i<nTokenCount; i++)
158
0
        AddItem(mpContainer->GetTokenForIndex(i));
159
0
}
160
161
void AllMasterPagesSelector::AddItem (MasterPageContainer::Token aToken)
162
0
{
163
0
    switch (mpContainer->GetOriginForToken(aToken))
164
0
    {
165
0
        case MasterPageContainer::DEFAULT:
166
0
        case MasterPageContainer::TEMPLATE:
167
            // Templates are added only when coming from the
168
            // MasterPageContainerFiller so that they have an id which
169
            // defines their place in the list.  Templates (pre) loaded from
170
            // RecentlyUsedMasterPages are ignored (they will be loaded
171
            // later by the MasterPageContainerFiller.)
172
0
            if (mpContainer->GetTemplateIndexForToken(aToken) >= 0)
173
0
                mpSortedMasterPages->insert(mpContainer->GetDescriptorForToken(aToken));
174
0
            break;
175
176
0
        default:
177
0
            break;
178
0
    }
179
0
}
180
181
void AllMasterPagesSelector::UpdatePageSet (ItemList& rItemList)
182
0
{
183
0
    for (const auto& rxDescriptor : *mpSortedMasterPages)
184
0
        rItemList.push_back(rxDescriptor->maToken);
185
0
}
186
187
} // end of namespace sd::sidebar
188
189
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */