LibreOffice Module formula (master) 1
structpg.cxx
Go to the documentation of this file.
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
22#include "structpg.hxx"
23#include <formula/formula.hxx>
24#include <formula/token.hxx>
25#include <bitmaps.hlst>
26
27namespace formula
28{
29
31{
32 bActiveFlag = bFlag;
33}
34
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)
42 , bActiveFlag(false)
43{
44 m_xTlbStruct->set_size_request(m_xTlbStruct->get_approximate_digit_width() * 20,
45 m_xTlbStruct->get_height_rows(17));
46
47 m_xTlbStruct->connect_changed(LINK( this, StructPage, SelectHdl ) );
48}
49
51{
52}
53
55{
56 SetActiveFlag(false);
57 m_xTlbStruct->clear();
58}
59
60bool StructPage::InsertEntry(const OUString& rText, const weld::TreeIter* pParent,
61 sal_uInt16 nFlag, int nPos,
62 const FormulaToken* pIFormulaToken,
63 weld::TreeIter& rRet)
64{
65 SetActiveFlag(false);
66
67 OUString sId(weld::toId(pIFormulaToken));
68
69 bool bEntry = false;
70 switch (nFlag)
71 {
72 case STRUCT_FOLDER:
73 m_xTlbStruct->insert(pParent, nPos, &rText, &sId, nullptr, nullptr,
74 false, &rRet);
75 m_xTlbStruct->set_image(rRet, BMP_STR_OPEN);
76 bEntry = true;
77 break;
78 case STRUCT_END:
79 m_xTlbStruct->insert(pParent, nPos, &rText, &sId, nullptr, nullptr,
80 false, &rRet);
81 m_xTlbStruct->set_image(rRet, maImgEnd);
82 bEntry = true;
83 break;
84 case STRUCT_ERROR:
85 m_xTlbStruct->insert(pParent, nPos, &rText, &sId, nullptr, nullptr,
86 false, &rRet);
87 m_xTlbStruct->set_image(rRet, maImgError);
88 bEntry = true;
89 break;
90 }
91
92 if (bEntry && pParent)
93 m_xTlbStruct->expand_row(*pParent);
94 return bEntry;
95}
96
97OUString StructPage::GetEntryText(const weld::TreeIter* pEntry) const
98{
99 OUString aString;
100 if (pEntry)
101 aString = m_xTlbStruct->get_text(*pEntry);
102 return aString;
103}
104
106{
107 if (!pEntry)
108 return nullptr;
109
110 const FormulaToken * pToken = weld::fromId<const FormulaToken*>(m_xTlbStruct->get_id(*pEntry));
111 if (pToken)
112 {
113 if ( !(pToken->IsFunction() || pToken->GetParamCount() > 1 ) )
114 {
115 std::unique_ptr<weld::TreeIter> xParent(m_xTlbStruct->make_iterator(pEntry));
116 if (!m_xTlbStruct->iter_parent(*xParent))
117 return nullptr;
118 return GetFunctionEntry(xParent.get());
119 }
120 else
121 {
122 return pToken;
123 }
124 }
125 return nullptr;
126}
127
128IMPL_LINK(StructPage, SelectHdl, weld::TreeView&, rTlb, void)
129{
130 if (!GetActiveFlag())
131 return;
132
133 if (&rTlb == m_xTlbStruct.get())
134 {
135 std::unique_ptr<weld::TreeIter> xCurEntry(m_xTlbStruct->make_iterator());
136 if (m_xTlbStruct->get_cursor(xCurEntry.get()))
137 {
138 pSelectedToken = weld::fromId<const FormulaToken*>(m_xTlbStruct->get_id(*xCurEntry));
139 if (pSelectedToken)
140 {
141 if ( !(pSelectedToken->IsFunction() || pSelectedToken->GetParamCount() > 1) )
142 {
143 pSelectedToken = GetFunctionEntry(xCurEntry.get());
144 }
145 }
146 }
147 }
148
149 aSelLink.Call(*this);
150}
151
152} // formula
153
154/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsFunction() const
Definition: token.cxx:71
sal_uInt8 GetParamCount() const
Definition: token.cxx:89
OUString GetEntryText(const weld::TreeIter *pEntry) const
Definition: structpg.cxx:97
std::unique_ptr< weld::TreeView > m_xTlbStruct
Definition: structpg.hxx:35
StructPage(weld::Container *pParent)
Definition: structpg.cxx:35
OUString maImgError
Definition: structpg.hxx:40
bool InsertEntry(const OUString &rText, const weld::TreeIter *pParent, sal_uInt16 nFlag, int nPos, const FormulaToken *pIFormulaToken, weld::TreeIter &rRet)
Definition: structpg.cxx:60
const FormulaToken * GetFunctionEntry(const weld::TreeIter *pEntry)
Definition: structpg.cxx:105
void SetActiveFlag(bool bFlag)
Definition: structpg.cxx:30
#define STRUCT_FOLDER
Definition: formula.hxx:42
#define STRUCT_ERROR
Definition: formula.hxx:43
#define STRUCT_END
Definition: formula.hxx:41
sal_uInt16 nPos
IMPL_LINK(FormulaDlg_Impl, BtnHdl, weld::Button &, rBtn, void)
Definition: formula.cxx:1022
OUString toId(const void *pValue)
Reference< XNameAccess > m_xContainer
OUString sId