Coverage Report

Created: 2026-08-14 10:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/sidebar/line/LineWidthPopup.cxx
Line
Count
Source
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
#include <svtools/viewoptions.hxx>
20
#include <svx/sidebar/LineWidthPopup.hxx>
21
#include <svx/sidebar/LinePropertyPanelBase.hxx>
22
#include <com/sun/star/beans/NamedValue.hpp>
23
#include <svx/dialmgr.hxx>
24
#include <svx/strings.hrc>
25
#include <svx/xlnwtit.hxx>
26
#include <tools/fldunit.hxx>
27
#include <unotools/localedatawrapper.hxx>
28
#include <vcl/settings.hxx>
29
#include <vcl/svapp.hxx>
30
#include <vcl/weld/Builder.hxx>
31
#include "LineWidthValueSet.hxx"
32
#include <bitmaps.hlst>
33
34
namespace svx::sidebar
35
{
36
LineWidthPopup::LineWidthPopup(weld::Widget* pParent, LinePropertyPanelBase& rParent)
37
0
    : WeldToolbarPopup(nullptr, pParent, u"svx/ui/floatinglineproperty.ui"_ustr,
38
0
                       u"FloatingLineProperty"_ustr)
39
0
    , m_rParent(rParent)
40
0
    , m_sPt(SvxResId(RID_SVXSTR_PT))
41
0
    , m_eMapUnit(MapUnit::MapTwip)
42
0
    , m_bVSFocus(true)
43
0
    , m_bCustom(false)
44
0
    , m_nCustomWidth(0)
45
0
    , m_aIMGCus(StockImage::Yes, RID_SVXBMP_WIDTH_CUSTOM)
46
0
    , m_aIMGCusGray(StockImage::Yes, RID_SVXBMP_WIDTH_CUSTOM_GRAY)
47
0
    , m_xMFWidth(m_xBuilder->weld_metric_spin_button(u"spin"_ustr, FieldUnit::POINT))
48
0
    , m_xVSWidth(new LineWidthValueSet())
49
0
    , m_xVSWidthWin(new weld::CustomWeld(*m_xBuilder, u"lineset"_ustr, *m_xVSWidth))
50
0
{
51
0
    m_xVSWidth->SetStyle(m_xVSWidth->GetStyle() | WB_3DLOOK | WB_NO_DIRECTSELECT);
52
53
0
    maStrUnits = { u"0.5"_ustr, u"0.8"_ustr, u"1.0"_ustr,
54
0
                   u"1.5"_ustr, u"2.3"_ustr, u"3.0"_ustr,
55
0
                   u"4.5"_ustr, u"6.0"_ustr, SvxResId(RID_SVXSTR_WIDTH_LAST_CUSTOM) };
56
57
0
    const LocaleDataWrapper& rLocaleWrapper(Application::GetSettings().GetLocaleDataWrapper());
58
0
    const sal_Unicode cSep = rLocaleWrapper.getNumDecimalSep()[0];
59
60
0
    for (int i = 0; i <= 7; i++)
61
0
    {
62
0
        maStrUnits[i] = maStrUnits[i].replace('.', cSep); //Modify
63
0
        maStrUnits[i] += " ";
64
0
        maStrUnits[i] += m_sPt;
65
0
    }
66
67
0
    for (sal_uInt16 i = 1; i <= 9; ++i)
68
0
    {
69
0
        m_xVSWidth->InsertItem(i);
70
0
        m_xVSWidth->SetItemText(i, maStrUnits[i - 1]);
71
0
    }
72
73
0
    m_xVSWidth->SetUnit(maStrUnits);
74
0
    m_xVSWidth->SetItemData(1, reinterpret_cast<void*>(5));
75
0
    m_xVSWidth->SetItemData(2, reinterpret_cast<void*>(8));
76
0
    m_xVSWidth->SetItemData(3, reinterpret_cast<void*>(10));
77
0
    m_xVSWidth->SetItemData(4, reinterpret_cast<void*>(15));
78
0
    m_xVSWidth->SetItemData(5, reinterpret_cast<void*>(23));
79
0
    m_xVSWidth->SetItemData(6, reinterpret_cast<void*>(30));
80
0
    m_xVSWidth->SetItemData(7, reinterpret_cast<void*>(45));
81
0
    m_xVSWidth->SetItemData(8, reinterpret_cast<void*>(60));
82
0
    m_xVSWidth->SetImage(m_aIMGCusGray);
83
84
0
    m_xVSWidth->SetSelItem(0);
85
86
0
    m_xVSWidth->SetSelectHdl(LINK(this, LineWidthPopup, VSSelectHdl));
87
0
    m_xMFWidth->connect_value_changed(LINK(this, LineWidthPopup, MFModifyHdl));
88
0
}
89
90
0
LineWidthPopup::~LineWidthPopup() {}
91
92
IMPL_LINK_NOARG(LineWidthPopup, VSSelectHdl, ValueSet*, void)
93
0
{
94
0
    sal_uInt16 iPos = m_xVSWidth->GetSelectedItemId();
95
0
    if (iPos >= 1 && iPos <= 8)
96
0
    {
97
0
        sal_IntPtr nVal = OutputDevice::LogicToLogic(
98
0
            reinterpret_cast<sal_IntPtr>(m_xVSWidth->GetItemData(iPos)), MapUnit::MapPoint,
99
0
            m_eMapUnit);
100
0
        nVal = m_xMFWidth->denormalize(nVal);
101
0
        XLineWidthItem aWidthItem(nVal);
102
0
        m_rParent.setLineWidth(aWidthItem);
103
0
        m_rParent.SetWidthIcon(iPos);
104
0
        m_rParent.SetWidth(nVal);
105
0
    }
106
0
    else if (iPos == 9)
107
0
    { //last custom
108
        //modified
109
0
        if (m_bCustom)
110
0
        {
111
0
            tools::Long nVal
112
0
                = OutputDevice::LogicToLogic(m_nCustomWidth, MapUnit::MapPoint, m_eMapUnit);
113
0
            nVal = m_xMFWidth->denormalize(nVal);
114
0
            XLineWidthItem aWidthItem(nVal);
115
0
            m_rParent.setLineWidth(aWidthItem);
116
0
            m_rParent.SetWidth(nVal);
117
0
        }
118
0
        else
119
0
        {
120
0
            m_xVSWidth->SetNoSelection(); //add , set no selection and keep the last select item
121
0
            m_xVSWidth->SetFormat();
122
0
            m_xVSWidth->Invalidate();
123
0
        }
124
        //modify end
125
0
    }
126
127
0
    if ((iPos >= 1 && iPos <= 8) || (iPos == 9 && m_bCustom)) //add
128
0
    {
129
0
        m_rParent.EndLineWidthPopup();
130
0
    }
131
0
}
132
133
IMPL_LINK_NOARG(LineWidthPopup, MFModifyHdl, weld::MetricSpinButton&, void)
134
0
{
135
0
    if (m_xVSWidth->GetSelItem())
136
0
    {
137
0
        m_xVSWidth->SetSelItem(0);
138
0
        m_xVSWidth->SetFormat();
139
0
        m_xVSWidth->Invalidate();
140
0
    }
141
0
    tools::Long nTmp = static_cast<tools::Long>(m_xMFWidth->get_value(FieldUnit::NONE));
142
0
    tools::Long nVal = OutputDevice::LogicToLogic(nTmp, MapUnit::MapPoint, m_eMapUnit);
143
0
    sal_Int32 nNewWidth = static_cast<short>(m_xMFWidth->denormalize(nVal));
144
0
    XLineWidthItem aWidthItem(nNewWidth);
145
0
    m_rParent.setLineWidth(aWidthItem);
146
0
}
147
148
void LineWidthPopup::SetWidthSelect(tools::Long lValue, bool bValuable, MapUnit eMapUnit)
149
0
{
150
0
    m_bVSFocus = true;
151
0
    m_xVSWidth->SetSelItem(0);
152
0
    m_eMapUnit = eMapUnit;
153
0
    SvtViewOptions aWinOpt(EViewType::Window, u"PopupPanel_LineWidth"_ustr);
154
0
    if (aWinOpt.Exists())
155
0
    {
156
0
        css::uno::Sequence<css::beans::NamedValue> aSeq = aWinOpt.GetUserData();
157
0
        OUString aTmp;
158
0
        if (aSeq.hasElements())
159
0
            aSeq[0].Value >>= aTmp;
160
161
0
        OUString aWinData(aTmp);
162
0
        m_nCustomWidth = aWinData.toInt32();
163
0
        m_bCustom = true;
164
0
        m_xVSWidth->SetImage(m_aIMGCus);
165
0
        m_xVSWidth->SetCusEnable(true);
166
167
0
        OUString aStrTip = OUString::number(static_cast<double>(m_nCustomWidth) / 10) + m_sPt;
168
0
        m_xVSWidth->SetItemText(9, aStrTip);
169
0
    }
170
0
    else
171
0
    {
172
0
        m_bCustom = false;
173
0
        m_xVSWidth->SetImage(m_aIMGCusGray);
174
0
        m_xVSWidth->SetCusEnable(false);
175
0
        m_xVSWidth->SetItemText(9, maStrUnits[8]);
176
0
    }
177
178
0
    if (bValuable)
179
0
    {
180
0
        sal_Int64 nVal = OutputDevice::LogicToLogic(lValue, eMapUnit, MapUnit::Map100thMM);
181
0
        nVal = m_xMFWidth->normalize(nVal);
182
0
        m_xMFWidth->set_value(nVal, FieldUnit::MM_100TH);
183
0
    }
184
0
    else
185
0
    {
186
0
        m_xMFWidth->set_text(u""_ustr);
187
0
    }
188
189
0
    OUString strCurrValue = m_xMFWidth->get_text();
190
0
    sal_uInt16 i = 0;
191
0
    for (; i < 8; i++)
192
0
    {
193
0
        if (strCurrValue == maStrUnits[i])
194
0
        {
195
0
            m_xVSWidth->SetSelItem(i + 1);
196
0
            break;
197
0
        }
198
0
    }
199
200
0
    if (i >= 8)
201
0
    {
202
0
        m_bVSFocus = false;
203
0
        m_xVSWidth->SetSelItem(0);
204
0
    }
205
206
0
    m_xVSWidth->SetFormat();
207
0
    m_xVSWidth->Invalidate();
208
0
}
209
210
void LineWidthPopup::GrabFocus()
211
0
{
212
0
    if (m_bVSFocus)
213
0
        m_xVSWidth->GrabFocus();
214
0
    else
215
0
        m_xMFWidth->grab_focus();
216
0
}
217
218
} // end of namespace svx::sidebar
219
220
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */