1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <vcl/svapp.hxx>
22 #include "structpg.hxx"
23 #include <formula/formula.hxx>
24 #include <formula/token.hxx>
25 #include <bitmaps.hlst>
30 void StructPage::SetActiveFlag(bool bFlag
)
35 StructPage::StructPage(weld::Container
* pParent
)
36 : m_xBuilder(Application::CreateBuilder(pParent
, "formula/ui/structpage.ui"))
37 , m_xContainer(m_xBuilder
->weld_container("StructPage"))
38 , m_xTlbStruct(m_xBuilder
->weld_tree_view("struct"))
39 , maImgEnd(BMP_STR_END
)
40 , maImgError(BMP_STR_ERROR
)
41 , pSelectedToken(nullptr)
44 m_xTlbStruct
->set_size_request(m_xTlbStruct
->get_approximate_digit_width() * 20,
45 m_xTlbStruct
->get_height_rows(17));
47 m_xTlbStruct
->connect_changed(LINK( this, StructPage
, SelectHdl
) );
50 StructPage::~StructPage()
54 void StructPage::ClearStruct()
57 m_xTlbStruct
->clear();
60 bool StructPage::InsertEntry(const OUString
& rText
, const weld::TreeIter
* pParent
,
61 sal_uInt16 nFlag
, int nPos
,
62 const FormulaToken
* pIFormulaToken
,
67 OUString
sId(weld::toId(pIFormulaToken
));
73 m_xTlbStruct
->insert(pParent
, nPos
, &rText
, &sId
, nullptr, nullptr,
75 m_xTlbStruct
->set_image(rRet
, BMP_STR_OPEN
);
79 m_xTlbStruct
->insert(pParent
, nPos
, &rText
, &sId
, nullptr, nullptr,
81 m_xTlbStruct
->set_image(rRet
, maImgEnd
);
85 m_xTlbStruct
->insert(pParent
, nPos
, &rText
, &sId
, nullptr, nullptr,
87 m_xTlbStruct
->set_image(rRet
, maImgError
);
92 if (bEntry
&& pParent
)
93 m_xTlbStruct
->expand_row(*pParent
);
97 OUString
StructPage::GetEntryText(const weld::TreeIter
* pEntry
) const
101 aString
= m_xTlbStruct
->get_text(*pEntry
);
105 const FormulaToken
* StructPage::GetFunctionEntry(const weld::TreeIter
* pEntry
)
110 const FormulaToken
* pToken
= weld::fromId
<const FormulaToken
*>(m_xTlbStruct
->get_id(*pEntry
));
113 if ( !(pToken
->IsFunction() || pToken
->GetParamCount() > 1 ) )
115 std::unique_ptr
<weld::TreeIter
> xParent(m_xTlbStruct
->make_iterator(pEntry
));
116 if (!m_xTlbStruct
->iter_parent(*xParent
))
118 return GetFunctionEntry(xParent
.get());
128 IMPL_LINK(StructPage
, SelectHdl
, weld::TreeView
&, rTlb
, void)
130 if (!GetActiveFlag())
133 if (&rTlb
== m_xTlbStruct
.get())
135 std::unique_ptr
<weld::TreeIter
> xCurEntry(m_xTlbStruct
->make_iterator());
136 if (m_xTlbStruct
->get_cursor(xCurEntry
.get()))
138 pSelectedToken
= weld::fromId
<const FormulaToken
*>(m_xTlbStruct
->get_id(*xCurEntry
));
141 if ( !(pSelectedToken
->IsFunction() || pSelectedToken
->GetParamCount() > 1) )
143 pSelectedToken
= GetFunctionEntry(xCurEntry
.get());
149 aSelLink
.Call(*this);
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */