Coverage Report

Created: 2026-04-09 11:41

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* pDev, const Point& rPos,
181
                     SystemTextColorFlags nFlags )
182
0
{
183
0
    Point       aPos  = pDev->LogicToPixel( rPos );
184
0
    Size        aSize = GetSizePixel();
185
0
    vcl::Font   aFont = GetDrawPixelFont( pDev );
186
187
0
    auto popIt = pDev->ScopedPush();
188
0
    pDev->SetMapMode();
189
0
    pDev->SetFont( aFont );
190
0
    if ( nFlags & SystemTextColorFlags::Mono )
191
0
        pDev->SetTextColor( COL_BLACK );
192
0
    else
193
0
        pDev->SetTextColor( GetTextColor() );
194
0
    pDev->SetTextFillColor();
195
196
0
    ImplDraw( pDev, nFlags, aPos, aSize );
197
0
}
198
199
void GroupBox::Resize()
200
0
{
201
0
    Control::Resize();
202
0
    Invalidate();
203
0
}
204
205
void GroupBox::StateChanged( StateChangedType nType )
206
0
{
207
0
    Control::StateChanged( nType );
208
209
0
    if ( (nType == StateChangedType::Enable) ||
210
0
         (nType == StateChangedType::Text) ||
211
0
         (nType == StateChangedType::UpdateMode) )
212
0
    {
213
0
        if ( IsUpdateMode() )
214
0
            Invalidate();
215
0
    }
216
0
    else if ( nType == StateChangedType::Style )
217
0
    {
218
0
        SetStyle( ImplInitStyle( GetStyle() ) );
219
0
        if ( (GetPrevStyle() & GROUP_VIEW_STYLE) !=
220
0
             (GetStyle() & GROUP_VIEW_STYLE) )
221
0
            Invalidate();
222
0
    }
223
0
    else if ( (nType == StateChangedType::Zoom)  ||
224
0
              (nType == StateChangedType::ControlFont) )
225
0
    {
226
0
        ImplInitSettings( false );
227
0
        Invalidate();
228
0
    }
229
0
    else if ( nType == StateChangedType::ControlForeground )
230
0
    {
231
0
        ImplInitSettings( false );
232
0
        Invalidate();
233
0
    }
234
0
    else if ( nType == StateChangedType::ControlBackground )
235
0
    {
236
0
        ImplInitSettings( true );
237
0
        Invalidate();
238
0
    }
239
0
}
240
241
void GroupBox::DataChanged( const DataChangedEvent& rDCEvt )
242
0
{
243
0
    Control::DataChanged( rDCEvt );
244
245
0
    if ( (rDCEvt.GetType() == DataChangedEventType::FONTS) ||
246
0
         (rDCEvt.GetType() == DataChangedEventType::FONTSUBSTITUTION) ||
247
0
         ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
248
0
          (rDCEvt.GetFlags() & AllSettingsFlags::STYLE)) )
249
0
    {
250
0
        ImplInitSettings( true );
251
0
        Invalidate();
252
0
    }
253
0
}
254
255
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */