1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <vcl/svapp.hxx>
#include "structpg.hxx"
#include <formula/formula.hxx>
#include <formula/token.hxx>
#include <bitmaps.hlst>
namespace formula
{
void StructPage::SetActiveFlag(bool bFlag)
{
bActiveFlag = bFlag;
}
StructPage::StructPage(weld::Container* pParent)
: m_xBuilder(Application::CreateBuilder(pParent, "formula/ui/structpage.ui"))
, m_xContainer(m_xBuilder->weld_container("StructPage"))
, m_xTlbStruct(m_xBuilder->weld_tree_view("struct"))
, maImgEnd(BMP_STR_END)
, maImgError(BMP_STR_ERROR)
, pSelectedToken(nullptr)
, bActiveFlag(false)
{
m_xTlbStruct->set_size_request(m_xTlbStruct->get_approximate_digit_width() * 20,
m_xTlbStruct->get_height_rows(17));
m_xTlbStruct->connect_changed(LINK( this, StructPage, SelectHdl ) );
}
StructPage::~StructPage()
{
}
void StructPage::ClearStruct()
{
SetActiveFlag(false);
m_xTlbStruct->clear();
}
bool StructPage::InsertEntry(const OUString& rText, const weld::TreeIter* pParent,
sal_uInt16 nFlag, int nPos,
const FormulaToken* pIFormulaToken,
weld::TreeIter& rRet)
{
SetActiveFlag(false);
OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pIFormulaToken)));
bool bEntry = false;
switch (nFlag)
{
case STRUCT_FOLDER:
m_xTlbStruct->insert(pParent, nPos, &rText, &sId, nullptr, nullptr,
false, &rRet);
m_xTlbStruct->set_image(rRet, BMP_STR_OPEN);
bEntry = true;
break;
case STRUCT_END:
m_xTlbStruct->insert(pParent, nPos, &rText, &sId, nullptr, nullptr,
false, &rRet);
m_xTlbStruct->set_image(rRet, maImgEnd);
bEntry = true;
break;
case STRUCT_ERROR:
m_xTlbStruct->insert(pParent, nPos, &rText, &sId, nullptr, nullptr,
false, &rRet);
m_xTlbStruct->set_image(rRet, maImgError);
bEntry = true;
break;
}
if (bEntry && pParent)
m_xTlbStruct->expand_row(*pParent);
return bEntry;
}
OUString StructPage::GetEntryText(const weld::TreeIter* pEntry) const
{
OUString aString;
if (pEntry)
aString = m_xTlbStruct->get_text(*pEntry);
return aString;
}
const FormulaToken* StructPage::GetFunctionEntry(const weld::TreeIter* pEntry)
{
if (pEntry)
{
const FormulaToken * pToken = reinterpret_cast<const FormulaToken *>(m_xTlbStruct->get_id(*pEntry).toInt64());
if (pToken)
{
if ( !(pToken->IsFunction() || pToken->GetParamCount() > 1 ) )
{
std::unique_ptr<weld::TreeIter> xParent(m_xTlbStruct->make_iterator(pEntry));
if (!m_xTlbStruct->iter_parent(*xParent))
return nullptr;
return GetFunctionEntry(xParent.get());
}
else
{
return pToken;
}
}
}
return nullptr;
}
IMPL_LINK(StructPage, SelectHdl, weld::TreeView&, rTlb, void)<--- syntax error
{
if (!GetActiveFlag())
return;
if (&rTlb == m_xTlbStruct.get())
{
std::unique_ptr<weld::TreeIter> xCurEntry(m_xTlbStruct->make_iterator());
if (m_xTlbStruct->get_cursor(xCurEntry.get()))
{
pSelectedToken = reinterpret_cast<const FormulaToken *>(m_xTlbStruct->get_id(*xCurEntry).toInt64());
if (pSelectedToken)
{
if ( !(pSelectedToken->IsFunction() || pSelectedToken->GetParamCount() > 1) )
{
pSelectedToken = GetFunctionEntry(xCurEntry.get());
}
}
}
}
aSelLink.Call(*this);
}
} // formula
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|