Coverage Report

Created: 2026-03-31 11:00

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