Coverage Report

Created: 2026-07-10 11:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sfx2/source/dialog/styledlg.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 <svl/whiter.hxx>
21
#include <svl/style.hxx>
22
23
#include <sfx2/styledlg.hxx>
24
#include <sfx2/sfxresid.hxx>
25
#include <sfx2/strings.hrc>
26
27
#include "mgetempl.hxx"
28
29
#include <vcl/tabs.hrc>
30
#include <vcl/vclenum.hxx>
31
#include <vcl/weld/Button.hxx>
32
#include <vcl/weld/Dialog.hxx>
33
34
/*  [Description]
35
36
    Constructor: Add Manage TabPage, set ExampleSet from style.
37
*/
38
SfxStyleDialogController::SfxStyleDialogController
39
(
40
    weld::Window* pParent,           // Parent
41
    const OUString& rUIXMLDescription, const OUString& rID,
42
    SfxStyleSheetBase& rStyle  // stylesheet to be processed
43
)
44
0
    : SfxTabDialogController(pParent, rUIXMLDescription, rID, &rStyle.GetItemSet(), true)
45
0
    , m_rStyle(rStyle)
46
0
{
47
    // without ParentSupport suppress the standardButton
48
0
    if (!rStyle.HasParentSupport())
49
0
        RemoveStandardButton();
50
51
0
    AddTabPage(u"organizer"_ustr, TabResId(RID_TAB_ORGANIZER.aLabel),
52
0
               SfxManageStyleSheetPage::Create, RID_M + RID_TAB_ORGANIZER.sIconName);
53
54
    // With new template always set the management page as the current page
55
0
    if (rStyle.GetName().isEmpty())
56
0
        SetCurPageId(u"organizer"_ustr);
57
0
    else
58
0
    {
59
0
        OUString sTxt = m_xDialog->get_title() + ": " + rStyle.GetName();
60
0
        m_xDialog->set_title(sTxt);
61
0
    }
62
0
    m_xExampleSet.reset(&m_rStyle.GetItemSet()); // in SfxTabDialog::Ctor() already created, reset will delete it
63
64
0
    GetCancelButton().connect_clicked(LINK(this, SfxStyleDialogController, CancelHdl));
65
0
}
66
67
/*  [Description]
68
69
    Destructor: set ExampleSet to NULL, so that SfxTabDialog does not delete
70
    the Set from Style.
71
*/
72
SfxStyleDialogController::~SfxStyleDialogController()
73
0
{
74
    // coverity[leaked_storage] - deliberate, ownership is really with m_rStyle
75
0
    m_xExampleSet.release();
76
0
}
77
78
/*  [Description]
79
80
    Override so that always RET_OK is returned.
81
*/
82
short SfxStyleDialogController::Ok()
83
0
{
84
0
    SfxTabDialogController::Ok();
85
86
    // tdf#171281: Page and List (Pseudo) styles do not support inheritance
87
    // via property chips, so applying chip-based resets would discard the
88
    // user's modifications instead of restoring parent values.
89
0
    const SfxStyleFamily nFamily = m_rStyle.GetFamily();
90
0
    if (nFamily != SfxStyleFamily::Pseudo &&
91
0
        nFamily != SfxStyleFamily::Page)
92
0
    {
93
0
        SfxItemSet& rStyleSet = m_rStyle.GetItemSet();
94
0
        for (sal_uInt16 nWhich : m_aInvalidatedWhichIds)
95
0
            rStyleSet.ClearItem(nWhich);
96
0
    }
97
98
0
    return RET_OK;
99
0
}
100
101
/*  [Description]
102
103
    If the dialogue was canceled, then all selected attributes must be reset
104
    again.
105
*/
106
IMPL_LINK_NOARG(SfxStyleDialogController, CancelHdl, weld::Button&, void)
107
0
{
108
0
    SfxTabPage* pPage = GetTabPage(u"organizer");
109
110
0
    const SfxItemSet* pInSet = GetInputSetImpl();
111
0
    SfxWhichIter aIter(*pInSet);
112
0
    sal_uInt16 nWhich = aIter.FirstWhich();
113
114
0
    while (nWhich)
115
0
    {
116
0
        SfxItemState eState = aIter.GetItemState(false);
117
118
0
        if (SfxItemState::DEFAULT == eState)
119
0
            m_xExampleSet->ClearItem(nWhich);
120
0
        else
121
0
            m_xExampleSet->Put(pInSet->Get(nWhich));
122
0
        nWhich = aIter.NextWhich();
123
0
    }
124
125
0
    if (pPage)
126
0
        pPage->Reset(GetInputSetImpl());
127
128
0
    m_xDialog->response(RET_CANCEL);
129
0
}
130
131
OUString SfxStyleDialogController::GenerateUnusedName(SfxStyleSheetBasePool &rPool, SfxStyleFamily eFam)
132
0
{
133
0
    OUString aNo(SfxResId(STR_NONAME));
134
0
    sal_uInt16 i = 1;
135
0
    OUString aNoName = aNo + OUString::number(i);
136
0
    while (rPool.Find(aNoName, eFam))
137
0
    {
138
0
        ++i;
139
0
        aNoName = aNo + OUString::number(i);
140
0
    }
141
0
    return aNoName;
142
0
}
143
144
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */