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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
/* -*- 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 <o3tl/safeint.hxx>
#include <sal/config.h>
#include <svx/dialmgr.hxx>
#include <svx/sidebar/InspectorTextPanel.hxx>
#include <svl/cjkoptions.hxx>
#include <svl/ctloptions.hxx>
#include <com/sun/star/awt/FontSlant.hpp>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
#include <inspectorvalues.hrc>
using namespace css;
const int MinimumPanelWidth = 250;
namespace svx::sidebar
{
std::unique_ptr<PanelLayout> InspectorTextPanel::Create(weld::Widget* pParent)
{
if (pParent == nullptr)
throw lang::IllegalArgumentException("no parent Window given to InspectorTextPanel::Create",
nullptr, 0);
return std::make_unique<InspectorTextPanel>(pParent);
}
InspectorTextPanel::InspectorTextPanel(weld::Widget* pParent)
: PanelLayout(pParent, "InspectorTextPanel", "svx/ui/inspectortextpanel.ui")
, mpListBoxStyles(m_xBuilder->weld_tree_view("listbox_fonts"))
{
mpListBoxStyles->set_size_request(MinimumPanelWidth, -1);
float fWidth = mpListBoxStyles->get_approximate_digit_width();
std::vector<int> aWidths{ o3tl::narrowing<int>(fWidth * 29) };
// 2nd column will fill remaining space
mpListBoxStyles->set_column_fixed_widths(aWidths);
}
static bool GetPropertyValues(std::u16string_view rPropName, const uno::Any& rAny,
OUString& rString)
{
// Hide Asian and Complex properties
if (!SvtCJKOptions::IsCJKFontEnabled() && rPropName.find(u"Asian") != std::u16string_view::npos)
return false;
if (!SvtCTLOptions().IsCTLFontEnabled()
&& rPropName.find(u"Complex") != std::u16string_view::npos)
return false;
if (bool bValue; rAny >>= bValue)
{
rString = SvxResId(bValue ? RID_TRUE : RID_FALSE); // tdf#139136
}
else if (OUString aValue; (rAny >>= aValue) && !(aValue.isEmpty()))
{
rString = aValue;
}
else if (awt::FontSlant eValue; rAny >>= eValue)
{
rString = SvxResId(eValue == awt::FontSlant_ITALIC ? RID_ITALIC : RID_NORMAL);
}
else if (tools::Long nValueLong; rAny >>= nValueLong)
{
if (rPropName.find(u"Color") != std::u16string_view::npos)
rString = "0x" + OUString::number(nValueLong, 16);
else
rString = OUString::number(nValueLong);
}
else if (double fValue; rAny >>= fValue)
{
if (rPropName.find(u"Weight") != std::u16string_view::npos)
rString = SvxResId(fValue > 100 ? RID_BOLD : RID_NORMAL);
else
rString = OUString::number((round(fValue * 100)) / 100.00);
}
else if (short nValueShort; rAny >>= nValueShort)
{
rString = OUString::number(nValueShort);
}
else
return false;
return true;
}
static void FillBox_Impl(weld::TreeView& rListBoxStyles, const TreeNode& rCurrent,
const weld::TreeIter* pParent)
{
std::unique_ptr<weld::TreeIter> pResult = rListBoxStyles.make_iterator();
const OUString& rName = rCurrent.sNodeName;
OUString sPairValue;
if (!(rCurrent.NodeType != TreeNode::SimpleProperty
|| GetPropertyValues(rName, rCurrent.aValue, sPairValue)))
return;
rListBoxStyles.insert(pParent, -1, &rName, nullptr, nullptr, nullptr, false, pResult.get());
rListBoxStyles.set_sensitive(*pResult, !rCurrent.isGrey, 0);
rListBoxStyles.set_text_emphasis(*pResult, rCurrent.NodeType == TreeNode::Category, 0);
if (rCurrent.NodeType == TreeNode::SimpleProperty)
{
rListBoxStyles.set_text(*pResult, sPairValue, 1);
rListBoxStyles.set_sensitive(*pResult, !rCurrent.isGrey, 1);
rListBoxStyles.set_text_emphasis(*pResult, false, 1);
}
else
{
// Necessary, without this the selection line will be truncated.
rListBoxStyles.set_text(*pResult, "", 1);
}
for (const TreeNode& rChildNode : rCurrent.children)
FillBox_Impl(rListBoxStyles, rChildNode, pResult.get());
}
void InspectorTextPanel::updateEntries(const std::vector<TreeNode>& rStore, const sal_Int32 nParIdx)
{
mpListBoxStyles->freeze();
mpListBoxStyles->clear();
for (const TreeNode& rChildNode : rStore)
{
FillBox_Impl(*mpListBoxStyles, rChildNode, nullptr);
}
mpListBoxStyles->thaw();
weld::TreeView* pTreeDiagram = mpListBoxStyles.get();
pTreeDiagram->all_foreach([pTreeDiagram](weld::TreeIter& rEntry) {
pTreeDiagram->expand_row(rEntry);
return false;
});
// Collapse "Default Paragraph Style"
std::unique_ptr<weld::TreeIter> pEntry = mpListBoxStyles->make_iterator();
if (!mpListBoxStyles->get_iter_first(*pEntry))
return;
// skip the optional metadata items before "Default Paragraph Style"
for (sal_Int32 i = 0; i < nParIdx; ++i)
{
if (!mpListBoxStyles->iter_next_sibling(*pEntry))
return;
}
if (!mpListBoxStyles->iter_next(*pEntry))
return;
mpListBoxStyles->collapse_row(*pEntry);
}
InspectorTextPanel::~InspectorTextPanel() {}
} // end of namespace svx::sidebar
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|