Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/source/toolkit/group.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 <vcl/event.hxx>
21
#include <vcl/toolkit/group.hxx>
22
#include <vcl/rendercontext/SystemTextColorFlags.hxx>
23
#include <vcl/settings.hxx>
24
25
0
#define GROUP_BORDER            12
26
0
#define GROUP_TEXT_BORDER       2
27
28
0
#define GROUP_VIEW_STYLE        (WB_3DLOOK | WB_NOLABEL)
29
30
void GroupBox::ImplInit( vcl::Window* pParent, WinBits nStyle )
31
0
{
32
0
    nStyle = ImplInitStyle( nStyle );
33
0
    Control::ImplInit( pParent, nStyle, nullptr );
34
0
    SetMouseTransparent( true );
35
0
    ImplInitSettings( true );
36
0
}
37
38
WinBits GroupBox::ImplInitStyle( WinBits nStyle )
39
0
{
40
0
    if ( !(nStyle & WB_NOGROUP) )
41
0
        nStyle |= WB_GROUP;
42
0
    return nStyle;
43
0
}
44
45
const vcl::Font& GroupBox::GetCanonicalFont( const StyleSettings& _rStyle ) const
46
0
{
47
0
    return _rStyle.GetGroupFont();
48
0
}
49
50
const Color& GroupBox::GetCanonicalTextColor( const StyleSettings& _rStyle ) const
51
0
{
52
0
    return _rStyle.GetGroupTextColor();
53
0
}
54
55
void GroupBox::ImplInitSettings( bool bBackground )
56
0
{
57
0
    Control::ImplInitSettings();
58
59
0
    if ( !bBackground )
60
0
        return;
61
62
0
    vcl::Window* pParent = GetParent();
63
0
    if (pParent->IsChildTransparentModeEnabled() ||
64
0
        !(pParent->GetStyle() & WB_CLIPCHILDREN) ||
65
0
        !IsControlBackground())
66
0
    {
67
0
        EnableChildTransparentMode();
68
0
        SetParentClipMode( ParentClipMode::NoClip );
69
0
        SetPaintTransparent( true );
70
0
        SetBackground();
71
0
    }
72
0
    else
73
0
    {
74
0
        EnableChildTransparentMode( false );
75
0
        SetParentClipMode();
76
0
        SetPaintTransparent( false );
77
78
0
        if ( IsControlBackground() )
79
0
            SetBackground( GetControlBackground() );
80
0
        else
81
0
            SetBackground( pParent->GetBackground() );
82
0
    }
83
0
}
84
85
GroupBox::GroupBox( vcl::Window* pParent, WinBits nStyle ) :
86
0
    Control( WindowType::GROUPBOX )
87
0
{
88
0
    ImplInit( pParent, nStyle );
89
0
}
Unexecuted instantiation: GroupBox::GroupBox(vcl::Window*, long)
Unexecuted instantiation: GroupBox::GroupBox(vcl::Window*, long)
90
91
void GroupBox::ImplDraw( OutputDevice* pDev, SystemTextColorFlags nSystemTextColorFlags,
92
                         const Point& rPos, const Size& rSize, bool bLayout )
93
0
{
94
0
    tools::Long                    nTop;
95
0
    tools::Long                    nTextOff;
96
0
    const StyleSettings&    rStyleSettings = GetSettings().GetStyleSettings();
97
0
    OUString                aText( GetText() );
98
0
    tools::Rectangle               aRect( rPos, rSize );
99
0
    DrawTextFlags           nTextStyle = DrawTextFlags::Left | DrawTextFlags::Top | DrawTextFlags::EndEllipsis | DrawTextFlags::Mnemonic;
100
101
0
    if ( GetStyle() & WB_NOLABEL )
102
0
        nTextStyle &= ~DrawTextFlags::Mnemonic;
103
0
    if ( !IsEnabled() )
104
0
        nTextStyle |= DrawTextFlags::Disable;
105
0
    if ( (nSystemTextColorFlags & SystemTextColorFlags::Mono) ||
106
0
         (rStyleSettings.GetOptions() & StyleSettingsOptions::Mono) )
107
0
    {
108
0
        nTextStyle |= DrawTextFlags::Mono;
109
0
        nSystemTextColorFlags |= SystemTextColorFlags::Mono;
110
0
    }
111
112
0
    if (aText.isEmpty())
113
0
    {
114
0
        nTop = rPos.Y();
115
0
        nTextOff = 0;
116
0
    }
117
0
    else
118
0
    {
119
0
        aRect.AdjustLeft(GROUP_BORDER );
120
0
        aRect.AdjustRight( -(GROUP_BORDER) );
121
0
        aRect = pDev->GetTextRect( aRect, aText, nTextStyle );
122
0
        nTop = rPos.Y();
123
0
        nTop += aRect.GetHeight() / 2;
124
0
        nTextOff = GROUP_TEXT_BORDER;
125
0
    }
126
127
0
    if( ! bLayout )
128
0
    {
129
0
        if ( nSystemTextColorFlags & SystemTextColorFlags::Mono )
130
0
            pDev->SetLineColor( COL_BLACK );
131
0
        else
132
0
            pDev->SetLineColor( rStyleSettings.GetShadowColor() );
133
134
0
        if (aText.isEmpty())
135
0
            pDev->DrawLine( Point( rPos.X(), nTop ), Point( rPos.X()+rSize.Width()-2, nTop ) );
136
0
        else
137
0
        {
138
0
            pDev->DrawLine( Point( rPos.X(), nTop ), Point( aRect.Left()-nTextOff, nTop ) );
139
0
            pDev->DrawLine( Point( aRect.Right()+nTextOff, nTop ), Point( rPos.X()+rSize.Width()-2, nTop ) );
140
0
        }
141
0
        pDev->DrawLine( Point( rPos.X(), nTop ), Point( rPos.X(), rPos.Y()+rSize.Height()-2 ) );
142
0
        pDev->DrawLine( Point( rPos.X(), rPos.Y()+rSize.Height()-2 ), Point( rPos.X()+rSize.Width()-2, rPos.Y()+rSize.Height()-2 ) );
143
0
        pDev->DrawLine( Point( rPos.X()+rSize.Width()-2, rPos.Y()+rSize.Height()-2 ), Point( rPos.X()+rSize.Width()-2, nTop ) );
144
145
0
        bool bIsPrinter = OUTDEV_PRINTER == pDev->GetOutDevType();
146
        // if we're drawing onto a printer, spare the 3D effect #i46986#
147
148
0
        if ( !bIsPrinter && !(nSystemTextColorFlags & SystemTextColorFlags::Mono) )
149
0
        {
150
0
            pDev->SetLineColor( rStyleSettings.GetLightColor() );
151
0
            if (aText.isEmpty())
152
0
                pDev->DrawLine( Point( rPos.X()+1, nTop+1 ), Point( rPos.X()+rSize.Width()-3, nTop+1 ) );
153
0
            else
154
0
            {
155
0
                pDev->DrawLine( Point( rPos.X()+1, nTop+1 ), Point( aRect.Left()-nTextOff, nTop+1 ) );
156
0
                pDev->DrawLine( Point( aRect.Right()+nTextOff, nTop+1 ), Point( rPos.X()+rSize.Width()-3, nTop+1 ) );
157
0
            }
158
0
            pDev->DrawLine( Point( rPos.X()+1, nTop+1 ), Point( rPos.X()+1, rPos.Y()+rSize.Height()-3 ) );
159
0
            pDev->DrawLine( Point( rPos.X(), rPos.Y()+rSize.Height()-1 ), Point( rPos.X()+rSize.Width()-1, rPos.Y()+rSize.Height()-1 ) );
160
0
            pDev->DrawLine( Point( rPos.X()+rSize.Width()-1, rPos.Y()+rSize.Height()-1 ), Point( rPos.X()+rSize.Width()-1, nTop ) );
161
0
        }
162
0
    }
163
164
0
    std::vector< tools::Rectangle >* pVector = bLayout ? &mxLayoutData->m_aUnicodeBoundRects : nullptr;
165
0
    OUString* pDisplayText = bLayout ? &mxLayoutData->m_aDisplayText : nullptr;
166
0
    DrawControlText( *pDev, aRect, aText, nTextStyle, pVector, pDisplayText );
167
0
}
168
169
void GroupBox::FillLayoutData() const
170
0
{
171
0
    mxLayoutData.emplace();
172
0
    const_cast<GroupBox*>(this)->ImplDraw( const_cast<GroupBox*>(this)->GetOutDev(), SystemTextColorFlags::NONE, Point(), GetOutputSizePixel(), true );
173
0
}
174
175
void GroupBox::Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& )
176
0
{
177
0
    ImplDraw(&rRenderContext, SystemTextColorFlags::NONE, Point(), GetOutputSizePixel());
178
0
}
179
180
void GroupBox::Draw(OutputDevice& rDev, const Point& rPos, SystemTextColorFlags nFlags)
181
0
{
182
0
    Point aPos = rDev.LogicToPixel(rPos);
183
0
    Size        aSize = GetSizePixel();
184
0
    vcl::Font aFont = GetDrawPixelFont(&rDev);
185
186
0
    auto popIt = rDev.ScopedPush();
187
0
    rDev.SetMapMode();
188
0
    rDev.SetFont(aFont);
189
0
    if ( nFlags & SystemTextColorFlags::Mono )
190
0
        rDev.SetTextColor(COL_BLACK);
191
0
    else
192
0
        rDev.SetTextColor(GetTextColor());
193
0
    rDev.SetTextFillColor();
194
195
0
    ImplDraw(&rDev, nFlags, aPos, aSize);
196
0
}
197
198
void GroupBox::Resize()
199
0
{
200
0
    Control::Resize();
201
0
    Invalidate();
202
0
}
203
204
void GroupBox::StateChanged( StateChangedType nType )
205
0
{
206
0
    Control::StateChanged( nType );
207
208
0
    if ( (nType == StateChangedType::Enable) ||
209
0
         (nType == StateChangedType::Text) ||
210
0
         (nType == StateChangedType::UpdateMode) )
211
0
    {
212
0
        if ( IsUpdateMode() )
213
0
            Invalidate();
214
0
    }
215
0
    else if ( nType == StateChangedType::Style )
216
0
    {
217
0
        SetStyle( ImplInitStyle( GetStyle() ) );
218
0
        if ( (GetPrevStyle() & GROUP_VIEW_STYLE) !=
219
0
             (GetStyle() & GROUP_VIEW_STYLE) )
220
0
            Invalidate();
221
0
    }
222
0
    else if ( (nType == StateChangedType::Zoom)  ||
223
0
              (nType == StateChangedType::ControlFont) )
224
0
    {
225
0
        ImplInitSettings( false );
226
0
        Invalidate();
227
0
    }
228
0
    else if ( nType == StateChangedType::ControlForeground )
229
0
    {
230
0
        ImplInitSettings( false );
231
0
        Invalidate();
232
0
    }
233
0
    else if ( nType == StateChangedType::ControlBackground )
234
0
    {
235
0
        ImplInitSettings( true );
236
0
        Invalidate();
237
0
    }
238
0
}
239
240
void GroupBox::DataChanged( const DataChangedEvent& rDCEvt )
241
0
{
242
0
    Control::DataChanged( rDCEvt );
243
244
0
    if ( (rDCEvt.GetType() == DataChangedEventType::FONTS) ||
245
0
         (rDCEvt.GetType() == DataChangedEventType::FONTSUBSTITUTION) ||
246
0
         ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
247
0
          (rDCEvt.GetFlags() & AllSettingsFlags::STYLE)) )
248
0
    {
249
0
        ImplInitSettings( true );
250
0
        Invalidate();
251
0
    }
252
0
}
253
254
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */