Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/sidebar/line/LineWidthValueSet.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 "LineWidthValueSet.hxx"
20
21
#include <i18nlangtag/mslangid.hxx>
22
#include <tools/mapunit.hxx>
23
#include <unotools/fontdefs.hxx>
24
#include <vcl/event.hxx>
25
#include <vcl/rendercontext/GetDefaultFontFlags.hxx>
26
#include <vcl/settings.hxx>
27
#include <vcl/svapp.hxx>
28
#include <vcl/weld/ScrolledWindow.hxx>
29
30
namespace svx::sidebar {
31
32
LineWidthValueSet::LineWidthValueSet()
33
0
    : ValueSet(nullptr)
34
0
    , nSelItem(0)
35
0
    , bCusEnable(false)
36
0
{
37
0
}
38
39
void LineWidthValueSet::Resize()
40
0
{
41
0
    SetColCount();
42
0
    SetLineCount(9);
43
0
    ValueSet::Resize();
44
0
}
45
46
LineWidthValueSet::~LineWidthValueSet()
47
0
{
48
0
}
49
50
void LineWidthValueSet::SetUnit(std::array<OUString,9> const & strUnits)
51
0
{
52
0
    maStrUnits = strUnits;
53
0
}
54
55
void LineWidthValueSet::SetSelItem(sal_uInt16 nSel)
56
0
{
57
0
    nSelItem = nSel;
58
0
    if(nSel == 0)
59
0
    {
60
0
        SelectItem(1); // ,false); // 'false' nut supported by AOO
61
0
        SetNoSelection();
62
0
    }
63
0
    else
64
0
    {
65
0
        SelectItem(nSelItem);
66
0
        GrabFocus();
67
0
    }
68
0
}
69
70
void LineWidthValueSet::SetImage(const Image& img)
71
0
{
72
0
    imgCus = img;
73
0
}
74
75
void LineWidthValueSet::SetCusEnable(bool bEnable)
76
0
{
77
0
    bCusEnable = bEnable;
78
0
}
79
80
void  LineWidthValueSet::UserDraw( const UserDrawEvent& rUDEvt )
81
0
{
82
0
    tools::Rectangle aRect = rUDEvt.GetRect();
83
0
    vcl::RenderContext* pDev = rUDEvt.GetRenderContext();
84
0
    sal_uInt16  nItemId = rUDEvt.GetItemId();
85
86
0
    tools::Long nRectHeight = aRect.GetHeight();
87
0
    tools::Long nRectWidth = aRect.GetWidth();
88
0
    Point aBLPos = aRect.TopLeft();
89
90
    //const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
91
    //Color aBackColor(0,0,200);
92
    //const Color aTextColor = rStyleSettings.GetFieldTextColor();
93
0
    auto popIt = pDev->ScopedPush(vcl::PushFlags::FONT | vcl::PushFlags::LINECOLOR | vcl::PushFlags::FILLCOLOR);
94
95
0
    vcl::Font aFont(OutputDevice::GetDefaultFont(DefaultFontType::UI_SANS, MsLangId::getConfiguredSystemLanguage(), GetDefaultFontFlags::OnlyOne));
96
0
    Size aSize = aFont.GetFontSize();
97
0
    aSize.setHeight( nRectHeight*3/5 );
98
0
    aFont.SetFontSize( aSize );
99
100
0
    Point aLineStart(aBLPos.X() + 5,            aBLPos.Y() + ( nRectHeight - nItemId )/2);
101
0
    Point aLineEnd(aBLPos.X() + nRectWidth * 7 / 9 - 10, aBLPos.Y() + ( nRectHeight - nItemId )/2);
102
0
    if (nItemId == 9)
103
0
    {
104
0
        Point aImgStart(aBLPos.X() + 5,         aBLPos.Y() + ( nRectHeight - 23 ) / 2);
105
0
        pDev->DrawImage(aImgStart, imgCus);
106
107
0
        tools::Rectangle aStrRect = aRect;
108
0
        aStrRect.AdjustTop(nRectHeight/6 );
109
0
        aStrRect.AdjustBottom( -(nRectHeight/6) );
110
0
        aStrRect.AdjustLeft(imgCus.GetSizePixel().Width() + 20 );
111
0
        if(bCusEnable)
112
0
            aFont.SetColor(Application::GetSettings().GetStyleSettings().GetFieldTextColor());
113
0
        else
114
0
            aFont.SetColor(Application::GetSettings().GetStyleSettings().GetDisableColor());
115
116
0
        pDev->SetFont(aFont);
117
0
        pDev->DrawText(aStrRect, maStrUnits[ nItemId - 1 ], DrawTextFlags::EndEllipsis);
118
0
    }
119
0
    else
120
0
    {
121
0
        if( nSelItem ==  nItemId )
122
0
        {
123
0
            tools::Rectangle aBackRect = aRect;
124
0
            aBackRect.AdjustTop(3 );
125
0
            aBackRect.AdjustBottom( -2 );
126
0
            pDev->SetFillColor(Color(50,107,197));
127
0
            pDev->DrawRect(aBackRect);
128
0
        }
129
130
        //draw text
131
0
        if(nSelItem ==  nItemId )
132
0
            aFont.SetColor(COL_WHITE);
133
0
        else
134
0
            aFont.SetColor(Application::GetSettings().GetStyleSettings().GetFieldTextColor());
135
0
        pDev->SetFont(aFont);
136
0
        Point aStart(aBLPos.X() + nRectWidth * 7 / 9 , aBLPos.Y() + nRectHeight/6);
137
0
        pDev->DrawText(aStart, maStrUnits[ nItemId - 1 ]);  //can't set DrawTextFlags::EndEllipsis here ,or the text will disappear
138
139
        //draw line
140
0
        if( nSelItem ==  nItemId )
141
0
            pDev->SetLineColor(COL_WHITE);
142
0
        else
143
0
            pDev->SetLineColor(Application::GetSettings().GetStyleSettings().GetFieldTextColor());
144
145
0
        for(sal_uInt16 i = 1; i <= nItemId; i++)
146
0
        {
147
0
            pDev->DrawLine(aLineStart,aLineEnd );
148
0
            aLineStart.setY(aLineStart.getY() + 1);
149
0
            aLineEnd.setY  (aLineEnd.getY() + 1);
150
0
        }
151
0
    }
152
153
0
    Invalidate( aRect );
154
0
}
155
156
void LineWidthValueSet::SetDrawingArea(weld::DrawingArea* pDrawingArea)
157
0
{
158
0
    ValueSet::SetDrawingArea(pDrawingArea);
159
0
    Size aSize(pDrawingArea->get_ref_device().LogicToPixel(Size(80, 12 * 9), MapMode(MapUnit::MapAppFont)));
160
0
    pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
161
0
    SetOutputSizePixel(aSize);
162
0
    SetColor(Application::GetSettings().GetStyleSettings().GetListBoxWindowBackgroundColor());
163
0
}
164
165
} // end of namespace svx::sidebar
166
167
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */