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 <svl/zforlist.hxx>
21 #include <svl/stritem.hxx>
22 #include <vcl/svapp.hxx>
24 #include "structpg.hxx"
25 #include <formula/formdata.hxx>
26 #include <formula/formula.hxx>
27 #include <formula/IFunctionDescription.hxx>
28 #include <formula/token.hxx>
29 #include <bitmaps.hlst>
34 void StructPage::SetActiveFlag(bool bFlag
)
39 StructPage::StructPage(weld::Container
* pParent
)
40 : m_xBuilder(Application::CreateBuilder(pParent
, "formula/ui/structpage.ui"))
41 , m_xContainer(m_xBuilder
->weld_container("StructPage"))
42 , m_xTlbStruct(m_xBuilder
->weld_tree_view("struct"))
43 , maImgEnd(BMP_STR_END
)
44 , maImgError(BMP_STR_ERROR
)
45 , pSelectedToken(nullptr)
48 m_xTlbStruct
->set_size_request(m_xTlbStruct
->get_approximate_digit_width() * 20,
49 m_xTlbStruct
->get_height_rows(17));
51 m_xTlbStruct
->connect_changed(LINK( this, StructPage
, SelectHdl
) );
54 StructPage::~StructPage()
58 void StructPage::ClearStruct()
61 m_xTlbStruct
->clear();
64 bool StructPage::InsertEntry(const OUString
& rText
, const weld::TreeIter
* pParent
,
65 sal_uInt16 nFlag
, int nPos
,
66 const FormulaToken
* pIFormulaToken
,
71 OUString
sId(OUString::number(reinterpret_cast<sal_Int64
>(pIFormulaToken
)));
77 m_xTlbStruct
->insert(pParent
, nPos
, &rText
, &sId
, nullptr, nullptr,
78 nullptr, false, &rRet
);
79 m_xTlbStruct
->set_image(rRet
, BMP_STR_OPEN
);
83 m_xTlbStruct
->insert(pParent
, nPos
, &rText
, &sId
, nullptr, nullptr,
84 nullptr, false, &rRet
);
85 m_xTlbStruct
->set_image(rRet
, maImgEnd
);
89 m_xTlbStruct
->insert(pParent
, nPos
, &rText
, &sId
, nullptr, nullptr,
90 nullptr, false, &rRet
);
91 m_xTlbStruct
->set_image(rRet
, maImgError
);
96 if (bEntry
&& pParent
)
97 m_xTlbStruct
->expand_row(*pParent
);
101 OUString
StructPage::GetEntryText(const weld::TreeIter
* pEntry
) const
105 aString
= m_xTlbStruct
->get_text(*pEntry
);
109 const FormulaToken
* StructPage::GetFunctionEntry(const weld::TreeIter
* pEntry
)
113 const FormulaToken
* pToken
= reinterpret_cast<const FormulaToken
*>(m_xTlbStruct
->get_id(*pEntry
).toInt64());
116 if ( !(pToken
->IsFunction() || pToken
->GetParamCount() > 1 ) )
118 std::unique_ptr
<weld::TreeIter
> xParent(m_xTlbStruct
->make_iterator(pEntry
));
119 if (!m_xTlbStruct
->iter_parent(*xParent
))
121 return GetFunctionEntry(xParent
.get());
132 IMPL_LINK(StructPage
, SelectHdl
, weld::TreeView
&, rTlb
, void)
136 if (&rTlb
== m_xTlbStruct
.get())
138 std::unique_ptr
<weld::TreeIter
> xCurEntry(m_xTlbStruct
->make_iterator());
139 if (m_xTlbStruct
->get_cursor(xCurEntry
.get()))
141 pSelectedToken
= reinterpret_cast<const FormulaToken
*>(m_xTlbStruct
->get_id(*xCurEntry
).toInt64());
144 if ( !(pSelectedToken
->IsFunction() || pSelectedToken
->GetParamCount() > 1) )
146 pSelectedToken
= GetFunctionEntry(xCurEntry
.get());
152 aSelLink
.Call(*this);
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */