Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/formula/source/ui/dlg/structpg.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 <vcl/svapp.hxx>
21
#include <vcl/weld/weldutils.hxx>
22
23
#include "structpg.hxx"
24
#include <formula/formula.hxx>
25
#include <formula/token.hxx>
26
#include <bitmaps.hlst>
27
28
namespace formula
29
{
30
31
void StructPage::SetActiveFlag(bool bFlag)
32
0
{
33
0
    bActiveFlag = bFlag;
34
0
}
35
36
StructPage::StructPage(weld::Container* pParent)
37
0
    : m_xBuilder(Application::CreateBuilder(pParent, u"formula/ui/structpage.ui"_ustr))
38
0
    , m_xContainer(m_xBuilder->weld_container(u"StructPage"_ustr))
39
0
    , m_xTlbStruct(m_xBuilder->weld_tree_view(u"struct"_ustr))
40
0
    , maImgEnd(BMP_STR_END)
41
0
    , maImgError(BMP_STR_ERROR)
42
0
    , pSelectedToken(nullptr)
43
0
    , bActiveFlag(false)
44
0
{
45
0
    m_xTlbStruct->set_size_request(m_xTlbStruct->get_approximate_digit_width() * 20,
46
0
                                   m_xTlbStruct->get_height_rows(17));
47
48
0
    m_xTlbStruct->connect_selection_changed(LINK(this, StructPage, SelectHdl));
49
0
}
50
51
StructPage::~StructPage()
52
0
{
53
0
}
54
55
void StructPage::ClearStruct()
56
0
{
57
0
    SetActiveFlag(false);
58
0
    m_xTlbStruct->clear();
59
0
}
60
61
bool StructPage::InsertEntry(const OUString& rText, const weld::TreeIter* pParent,
62
                             StructType eStructType, int nPos, const FormulaToken* pIFormulaToken,
63
                             weld::TreeIter& rRet)
64
0
{
65
0
    SetActiveFlag(false);
66
67
0
    OUString sId(weld::toId(pIFormulaToken));
68
69
0
    bool bEntry = false;
70
0
    switch (eStructType)
71
0
    {
72
0
        case StructType::Folder:
73
0
            m_xTlbStruct->insert(pParent, nPos, &rText, &sId, nullptr, nullptr,
74
0
                                 false, &rRet);
75
0
            m_xTlbStruct->set_image(rRet, BMP_STR_OPEN, 0);
76
0
            bEntry = true;
77
0
            break;
78
0
        case StructType::End:
79
0
            m_xTlbStruct->insert(pParent, nPos, &rText, &sId, nullptr, nullptr,
80
0
                                 false, &rRet);
81
0
            m_xTlbStruct->set_image(rRet, maImgEnd, 0);
82
0
            bEntry = true;
83
0
            break;
84
0
        case StructType::Error:
85
0
            m_xTlbStruct->insert(pParent, nPos, &rText, &sId, nullptr, nullptr,
86
0
                                 false, &rRet);
87
0
            m_xTlbStruct->set_image(rRet, maImgError, 0);
88
0
            bEntry = true;
89
0
            break;
90
0
    }
91
92
0
    if (bEntry && pParent)
93
0
        m_xTlbStruct->expand_row(*pParent);
94
0
    return bEntry;
95
0
}
96
97
OUString StructPage::GetEntryText(const weld::TreeIter* pEntry) const
98
0
{
99
0
    OUString aString;
100
0
    if (pEntry)
101
0
        aString = m_xTlbStruct->get_text(*pEntry);
102
0
    return aString;
103
0
}
104
105
const FormulaToken* StructPage::GetFunctionEntry(const weld::TreeIter* pEntry)
106
0
{
107
0
    if (!pEntry)
108
0
        return nullptr;
109
110
0
    const FormulaToken * pToken = weld::fromId<const FormulaToken*>(m_xTlbStruct->get_id(*pEntry));
111
0
    if (pToken)
112
0
    {
113
0
        if ( !(pToken->IsFunction() || pToken->GetParamCount() > 1 ) )
114
0
        {
115
0
            std::unique_ptr<weld::TreeIter> xParent(m_xTlbStruct->make_iterator(pEntry));
116
0
            if (!m_xTlbStruct->iter_parent(*xParent))
117
0
                return nullptr;
118
0
            return GetFunctionEntry(xParent.get());
119
0
        }
120
0
        else
121
0
        {
122
0
            return pToken;
123
0
        }
124
0
    }
125
0
    return nullptr;
126
0
}
127
128
IMPL_LINK(StructPage, SelectHdl, weld::ItemView&, rTlb, void)
129
0
{
130
0
    if (!GetActiveFlag())
131
0
        return;
132
133
0
    if (&rTlb == m_xTlbStruct.get())
134
0
    {
135
0
        if (std::unique_ptr<weld::TreeIter> xCurEntry = m_xTlbStruct->get_cursor())
136
0
        {
137
0
            pSelectedToken = weld::fromId<const FormulaToken*>(m_xTlbStruct->get_id(*xCurEntry));
138
0
            if (pSelectedToken)
139
0
            {
140
0
                if ( !(pSelectedToken->IsFunction() || pSelectedToken->GetParamCount() > 1) )
141
0
                {
142
0
                    pSelectedToken = GetFunctionEntry(xCurEntry.get());
143
0
                }
144
0
            }
145
0
        }
146
0
    }
147
148
0
    aSelLink.Call(*this);
149
0
}
150
151
} // formula
152
153
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */