Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / formula / source / ui / dlg / structpg.cxx
blobf35d34a5a336a01aa2d0c8dbc81d392c3346962d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
31 namespace formula
34 void StructPage::SetActiveFlag(bool bFlag)
36 bActiveFlag = 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)
46 , bActiveFlag(false)
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()
60 SetActiveFlag(false);
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,
67 weld::TreeIter& rRet)
69 SetActiveFlag(false);
71 OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pIFormulaToken)));
73 bool bEntry = false;
74 switch (nFlag)
76 case STRUCT_FOLDER:
77 m_xTlbStruct->insert(pParent, nPos, &rText, &sId, nullptr, nullptr,
78 nullptr, false, &rRet);
79 m_xTlbStruct->set_image(rRet, BMP_STR_OPEN);
80 bEntry = true;
81 break;
82 case STRUCT_END:
83 m_xTlbStruct->insert(pParent, nPos, &rText, &sId, nullptr, nullptr,
84 nullptr, false, &rRet);
85 m_xTlbStruct->set_image(rRet, maImgEnd);
86 bEntry = true;
87 break;
88 case STRUCT_ERROR:
89 m_xTlbStruct->insert(pParent, nPos, &rText, &sId, nullptr, nullptr,
90 nullptr, false, &rRet);
91 m_xTlbStruct->set_image(rRet, maImgError);
92 bEntry = true;
93 break;
96 if (bEntry && pParent)
97 m_xTlbStruct->expand_row(*pParent);
98 return bEntry;
101 OUString StructPage::GetEntryText(const weld::TreeIter* pEntry) const
103 OUString aString;
104 if (pEntry)
105 aString = m_xTlbStruct->get_text(*pEntry);
106 return aString;
109 const FormulaToken* StructPage::GetFunctionEntry(const weld::TreeIter* pEntry)
111 if (pEntry)
113 const FormulaToken * pToken = reinterpret_cast<const FormulaToken *>(m_xTlbStruct->get_id(*pEntry).toInt64());
114 if (pToken)
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))
120 return nullptr;
121 return GetFunctionEntry(xParent.get());
123 else
125 return pToken;
129 return nullptr;
132 IMPL_LINK(StructPage, SelectHdl, weld::TreeView&, rTlb, void)
134 if (GetActiveFlag())
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());
142 if (pSelectedToken)
144 if ( !(pSelectedToken->IsFunction() || pSelectedToken->GetParamCount() > 1) )
146 pSelectedToken = GetFunctionEntry(xCurEntry.get());
152 aSelLink.Call(*this);
156 } // formula
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */