Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/source/ui/cctrl/cbuttonw.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
20
#include <comphelper/lok.hxx>
21
#include <tools/mapunit.hxx>
22
#include <vcl/outdev.hxx>
23
#include <vcl/decoview.hxx>
24
#include <vcl/svapp.hxx>
25
#include <vcl/settings.hxx>
26
#include <cbutton.hxx>
27
28
29
ScDDComboBoxButton::ScDDComboBoxButton( OutputDevice* pOutputDevice )
30
0
    :   pOut( pOutputDevice )
31
0
{
32
0
    SetOptSizePixel();
33
0
}
34
35
ScDDComboBoxButton::~ScDDComboBoxButton()
36
0
{
37
0
}
38
39
void ScDDComboBoxButton::SetOutputDevice( OutputDevice* pOutputDevice )
40
0
{
41
0
    pOut = pOutputDevice;
42
0
}
43
44
void ScDDComboBoxButton::SetOptSizePixel()
45
0
{
46
0
    aBtnSize = pOut->LogicToPixel(Size(8, 11), MapMode(MapUnit::MapAppFont));
47
0
    aBtnSize.setWidth( std::max(aBtnSize.Width(), static_cast<tools::Long>(pOut->GetSettings().GetStyleSettings().GetScrollBarSize())) );
48
0
}
49
50
void ScDDComboBoxButton::Draw( const Point& rAt,
51
                               const Size&  rSize )
52
0
{
53
0
    if ( rSize.IsEmpty() )
54
0
        return;
55
56
    // save old state
57
0
    bool        bHadFill   = pOut->IsFillColor();
58
0
    Color       aOldFill   = pOut->GetFillColor();
59
0
    bool        bHadLine   = pOut->IsLineColor();
60
0
    Color       aOldLine   = pOut->GetLineColor();
61
0
    bool        bOldEnable = pOut->IsMapModeEnabled();
62
63
0
    tools::Rectangle   aBtnRect( rAt, rSize );
64
65
0
    if (!comphelper::LibreOfficeKit::isActive())
66
0
        pOut->EnableMapMode(false);
67
68
0
    DecorationView aDecoView( pOut);
69
70
0
    tools::Rectangle aInnerRect=aDecoView.DrawButton( aBtnRect, DrawButtonFlags::Default );
71
72
0
    aInnerRect.AdjustLeft(1 );
73
0
    aInnerRect.AdjustTop(1 );
74
0
    aInnerRect.AdjustRight( -1 );
75
0
    aInnerRect.AdjustBottom( -1 );
76
77
0
    Size  aInnerSize   = aInnerRect.GetSize();
78
0
    Point aInnerCenter = aInnerRect.Center();
79
80
0
    aInnerRect.SetTop( aInnerCenter.Y() - (aInnerSize.Width()>>1) );
81
0
    aInnerRect.SetBottom( aInnerCenter.Y() + (aInnerSize.Width()>>1) );
82
83
0
    ImpDrawArrow( aInnerRect );
84
85
    // restore old state
86
0
    pOut->EnableMapMode( bOldEnable );
87
0
    if (bHadLine)
88
0
        pOut->SetLineColor(aOldLine);
89
0
    else
90
0
        pOut->SetLineColor();
91
0
    if (bHadFill)
92
0
        pOut->SetFillColor(aOldFill);
93
0
    else
94
0
        pOut->SetFillColor();
95
0
}
96
97
void ScDDComboBoxButton::ImpDrawArrow( const tools::Rectangle& rRect )
98
0
{
99
    // no need to save old line and fill color here (is restored after the call)
100
101
0
    tools::Rectangle   aPixRect = rRect;
102
0
    Point       aCenter  = aPixRect.Center();
103
0
    Size        aSize    = aPixRect.GetSize();
104
105
0
    Size aSize3;
106
0
    aSize3.setWidth( aSize.Width() >> 1 );
107
0
    aSize3.setHeight( aSize.Height() >> 1 );
108
109
0
    Size aSize4;
110
0
    aSize4.setWidth( aSize.Width() >> 2 );
111
0
    aSize4.setHeight( aSize.Height() >> 2 );
112
113
0
    tools::Rectangle aTempRect = aPixRect;
114
115
0
    const StyleSettings& rSett = Application::GetSettings().GetStyleSettings();
116
0
    Color aColor( rSett.GetButtonTextColor() );
117
0
    pOut->SetFillColor( aColor );
118
0
    pOut->SetLineColor( aColor );
119
120
0
    aTempRect.SetLeft( aCenter.X() - aSize4.Width() );
121
0
    aTempRect.SetRight( aCenter.X() + aSize4.Width() );
122
0
    aTempRect.SetTop( aCenter.Y() - aSize3.Height() );
123
0
    aTempRect.SetBottom( aCenter.Y() - 1 );
124
125
0
    pOut->DrawRect( aTempRect );
126
127
0
    Point aPos1( aCenter.X()-aSize3.Width(), aCenter.Y() );
128
0
    Point aPos2( aCenter.X()+aSize3.Width(), aCenter.Y() );
129
0
    while( aPos1.X() <= aPos2.X() )
130
0
    {
131
0
        pOut->DrawLine( aPos1, aPos2 );
132
0
        aPos1.AdjustX( 1 ); aPos2.AdjustX( -1 );
133
0
        aPos1.AdjustY( 1 ); aPos2.AdjustY( 1 );
134
0
    }
135
136
0
    pOut->DrawLine( Point( aCenter.X() - aSize3.Width(), aPos1.Y()+1 ),
137
0
                    Point( aCenter.X() + aSize3.Width(), aPos1.Y()+1 ) );
138
0
}
139
140
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */