Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/source/control/ivctrl.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
21
#include <utility>
22
#include <ivctrl.hxx>
23
#include "imivctl.hxx"
24
#include <vcl/bitmap.hxx>
25
#include <vcl/commandevent.hxx>
26
#include <vcl/event.hxx>
27
#include <vcl/mnemonic.hxx>
28
#include <vcl/settings.hxx>
29
#include <vcl/tabctrl.hxx>
30
#include <vcl/vclevent.hxx>
31
#include <vcl/uitest/logger.hxx>
32
#include <vcl/uitest/eventdescription.hxx>
33
#include <accessibility/accessibleiconchoicectrl.hxx>
34
35
using namespace ::com::sun::star::accessibility;
36
37
SvxIconChoiceCtrlEntry::SvxIconChoiceCtrlEntry( OUString _aText,
38
                                                Image _aImage )
39
0
    : aImage(std::move(_aImage))
40
0
    , aText(std::move(_aText))
41
0
    , nX(0)
42
0
    , nY(0)
43
0
    , nFlags(SvxIconViewFlags::NONE)
44
0
{
45
0
}
46
47
OUString SvxIconChoiceCtrlEntry::GetDisplayText() const
48
0
{
49
0
    return MnemonicGenerator::EraseAllMnemonicChars( aText );
50
0
}
51
52
SvtIconChoiceCtrl::SvtIconChoiceCtrl( vcl::Window* pParent, WinBits nWinStyle ) :
53
54
     // WB_CLIPCHILDREN on, as ScrollBars lie on the window!
55
0
    Control( pParent, nWinStyle | WB_CLIPCHILDREN ),
56
57
0
    _pImpl           ( new SvxIconChoiceCtrl_Impl( this, nWinStyle ) ),
58
0
    m_nWidth(-1)
59
0
{
60
0
    GetOutDev()->SetLineColor();
61
0
    _pImpl->InitSettings();
62
0
}
Unexecuted instantiation: SvtIconChoiceCtrl::SvtIconChoiceCtrl(vcl::Window*, long)
Unexecuted instantiation: SvtIconChoiceCtrl::SvtIconChoiceCtrl(vcl::Window*, long)
63
64
SvtIconChoiceCtrl::~SvtIconChoiceCtrl()
65
0
{
66
0
    disposeOnce();
67
0
}
68
69
void SvtIconChoiceCtrl::dispose()
70
0
{
71
0
    if (_pImpl)
72
0
    {
73
0
        _pImpl->CallEventListeners( VclEventId::ObjectDying, nullptr );
74
0
        _pImpl.reset();
75
0
    }
76
0
    Control::dispose();
77
0
}
78
79
SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::InsertEntry( const OUString& rText, const Image& rImage  )
80
0
{
81
0
    SvxIconChoiceCtrlEntry* pEntry = new SvxIconChoiceCtrlEntry( rText, rImage);
82
83
0
    _pImpl->InsertEntry(std::unique_ptr<SvxIconChoiceCtrlEntry>(pEntry), _pImpl->GetEntryCount());
84
85
0
    return pEntry;
86
0
}
87
88
void SvtIconChoiceCtrl::RemoveEntry(sal_Int32 nIndex)
89
0
{
90
0
    _pImpl->RemoveEntry(nIndex);
91
0
}
92
93
void SvtIconChoiceCtrl::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
94
0
{
95
0
    _pImpl->Paint(rRenderContext, rRect);
96
0
}
97
98
void SvtIconChoiceCtrl::MouseButtonDown( const MouseEvent& rMEvt )
99
0
{
100
0
    if( !_pImpl->MouseButtonDown( rMEvt ) )
101
0
        Control::MouseButtonDown( rMEvt );
102
0
}
103
104
void SvtIconChoiceCtrl::MouseMove( const MouseEvent& rMEvt )
105
0
{
106
0
    if( !_pImpl->MouseMove( rMEvt ) )
107
0
        Control::MouseMove( rMEvt );
108
0
}
109
void SvtIconChoiceCtrl::ArrangeIcons()
110
0
{
111
0
    Size aFullSize;
112
0
    tools::Rectangle aEntryRect;
113
114
0
    for ( sal_Int32 i = 0; i < GetEntryCount(); i++ )
115
0
    {
116
0
        SvxIconChoiceCtrlEntry* pEntry = GetEntry ( i );
117
0
        aEntryRect = _pImpl->GetEntryBoundRect ( pEntry );
118
119
0
        aFullSize.setHeight ( aFullSize.getHeight()+aEntryRect.GetHeight() );
120
0
    }
121
122
0
    _pImpl->Arrange(aFullSize.getHeight());
123
124
0
    _pImpl->Arrange(1000);
125
0
}
126
127
long SvtIconChoiceCtrl::AdjustWidth(const long nWidth)
128
0
{
129
0
    const long cMargin = 9;
130
131
0
    if (nWidth + cMargin > m_nWidth)
132
0
    {
133
0
        m_nWidth = nWidth + cMargin;
134
0
        this->set_width_request(m_nWidth);
135
0
        _pImpl->SetGrid(Size(m_nWidth, 32));
136
0
    }
137
0
    return m_nWidth - cMargin;
138
0
}
139
140
void SvtIconChoiceCtrl::Resize()
141
0
{
142
0
    _pImpl->Resize();
143
0
    Control::Resize();
144
0
}
145
146
void SvtIconChoiceCtrl::GetFocus()
147
0
{
148
0
    _pImpl->GetFocus();
149
0
    Control::GetFocus();
150
0
}
151
152
void SvtIconChoiceCtrl::LoseFocus()
153
0
{
154
0
    if (_pImpl)
155
0
        _pImpl->LoseFocus();
156
0
    Control::LoseFocus();
157
0
}
158
159
void SvtIconChoiceCtrl::SetFont(const vcl::Font& rFont)
160
0
{
161
0
    if (rFont != GetFont())
162
0
    {
163
0
        Control::SetFont(rFont);
164
0
        _pImpl->FontModified();
165
0
    }
166
0
}
167
168
void SvtIconChoiceCtrl::SetPointFont(const vcl::Font& rFont)
169
0
{
170
0
    if (rFont != GetPointFont(*GetOutDev())) //FIXME
171
0
    {
172
0
        Control::SetPointFont(*GetOutDev(), rFont); //FIXME
173
0
        _pImpl->FontModified();
174
0
    }
175
0
}
176
177
void SvtIconChoiceCtrl::Command(const CommandEvent& rCEvt)
178
0
{
179
0
    _pImpl->Command( rCEvt );
180
    //pass at least alt press/release to parent impl
181
0
    if (rCEvt.GetCommand() == CommandEventId::ModKeyChange)
182
0
        Control::Command(rCEvt);
183
0
}
184
185
sal_Int32 SvtIconChoiceCtrl::GetEntryCount() const
186
0
{
187
0
    return _pImpl ? _pImpl->GetEntryCount() : 0;
188
0
}
189
190
SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::GetEntry( sal_Int32 nPos ) const
191
0
{
192
0
    return _pImpl ? _pImpl->GetEntry( nPos ) : nullptr;
193
0
}
194
195
SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::GetSelectedEntry() const
196
0
{
197
0
    return _pImpl ? _pImpl->GetFirstSelectedEntry() : nullptr;
198
0
}
199
200
void SvtIconChoiceCtrl::ClickIcon()
201
0
{
202
0
    GetSelectedEntry();
203
0
    _aClickIconHdl.Call( this );
204
0
}
205
206
void SvtIconChoiceCtrl::KeyInput( const KeyEvent& rKEvt )
207
0
{
208
0
    bool bKeyUsed = DoKeyInput( rKEvt );
209
0
    if ( !bKeyUsed )
210
0
    {
211
0
        Control::KeyInput( rKEvt );
212
0
    }
213
0
}
214
bool SvtIconChoiceCtrl::DoKeyInput( const KeyEvent& rKEvt )
215
0
{
216
0
    return _pImpl->KeyInput( rKEvt );
217
0
}
218
sal_Int32 SvtIconChoiceCtrl::GetEntryListPos( SvxIconChoiceCtrlEntry const * pEntry ) const
219
0
{
220
0
    return _pImpl->GetEntryListPos( pEntry );
221
0
}
222
SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::GetCursor( ) const
223
0
{
224
0
    return _pImpl->GetCurEntry( );
225
0
}
226
void SvtIconChoiceCtrl::SetCursor( SvxIconChoiceCtrlEntry* pEntry )
227
0
{
228
0
    _pImpl->SetCursor( pEntry );
229
0
}
230
231
void SvtIconChoiceCtrl::DataChanged( const DataChangedEvent& rDCEvt )
232
0
{
233
0
    if ( ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) ||
234
0
         (rDCEvt.GetType() == DataChangedEventType::FONTSUBSTITUTION) ||
235
0
         (rDCEvt.GetType() == DataChangedEventType::FONTS) ) &&
236
0
         (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
237
0
    {
238
0
        _pImpl->InitSettings();
239
0
        Invalidate(InvalidateFlags::NoChildren);
240
0
    }
241
0
    else
242
0
        Control::DataChanged( rDCEvt );
243
0
}
244
245
void SvtIconChoiceCtrl::SetBackground( const Wallpaper& rPaper )
246
0
{
247
0
    if( rPaper == GetBackground() )
248
0
        return;
249
250
0
    const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
251
    // if it is the default (empty) wallpaper
252
0
    if (rPaper.IsEmpty())
253
0
    {
254
0
        Control::SetBackground( rStyleSettings.GetFieldColor() );
255
0
    }
256
0
    else
257
0
    {
258
0
        Wallpaper aBackground( rPaper );
259
        // HACK, as background might be transparent!
260
0
        if( !aBackground.IsBitmap() )
261
0
            aBackground.SetStyle( WallpaperStyle::Tile );
262
263
0
        WallpaperStyle eStyle = aBackground.GetStyle();
264
0
        Color aBack( aBackground.GetColor());
265
0
        if( aBack == COL_TRANSPARENT &&
266
0
            (!aBackground.IsBitmap() ||
267
0
             aBackground.GetBitmap().HasAlpha() ||
268
0
             (eStyle != WallpaperStyle::Tile && eStyle != WallpaperStyle::Scale)) )
269
0
        {
270
0
            aBackground.SetColor( rStyleSettings.GetFieldColor() );
271
0
        }
272
0
        if( aBackground.IsScrollable() )
273
0
        {
274
0
            tools::Rectangle aRect;
275
0
            aRect.SetSize( Size(32765, 32765) );
276
0
            aBackground.SetRect( aRect );
277
0
        }
278
0
        else
279
0
        {
280
0
            tools::Rectangle aRect( _pImpl->GetOutputRect() );
281
0
            aBackground.SetRect( aRect );
282
0
        }
283
0
        Control::SetBackground( aBackground );
284
0
    }
285
286
    // If text colors are attributed "hard," don't use automatism to select
287
    // a readable text color.
288
0
    vcl::Font aFont( GetFont() );
289
0
    aFont.SetColor( rStyleSettings.GetFieldTextColor() );
290
0
    SetFont( aFont );
291
292
0
    Invalidate(InvalidateFlags::NoChildren);
293
0
}
294
295
void SvtIconChoiceCtrl::RequestHelp( const HelpEvent& rHEvt )
296
0
{
297
0
    if ( !_pImpl->RequestHelp( rHEvt ) )
298
0
        Control::RequestHelp( rHEvt );
299
0
}
300
301
tools::Rectangle SvtIconChoiceCtrl::GetBoundingBox( SvxIconChoiceCtrlEntry* pEntry ) const
302
0
{
303
0
    return _pImpl->GetEntryBoundRect( pEntry );
304
0
}
305
306
void SvtIconChoiceCtrl::FillLayoutData() const
307
0
{
308
0
    CreateLayoutData();
309
0
    const_cast<SvtIconChoiceCtrl*>(this)->Invalidate();
310
0
}
311
312
tools::Rectangle SvtIconChoiceCtrl::GetEntryCharacterBounds( const sal_Int32 _nEntryPos, const sal_Int32 _nCharacterIndex ) const
313
0
{
314
0
    tools::Rectangle aRect;
315
316
0
    Pair aEntryCharacterRange = GetLineStartEnd( _nEntryPos );
317
0
    if ( aEntryCharacterRange.A() + _nCharacterIndex < aEntryCharacterRange.B() )
318
0
    {
319
0
        aRect = GetCharacterBounds( aEntryCharacterRange.A() + _nCharacterIndex );
320
0
    }
321
322
0
    return aRect;
323
0
}
324
325
void SvtIconChoiceCtrl::CallImplEventListeners(VclEventId nEvent, void* pData)
326
0
{
327
0
    CallEventListeners(nEvent, pData);
328
0
}
329
330
rtl::Reference<comphelper::OAccessible> SvtIconChoiceCtrl::CreateAccessible()
331
0
{
332
0
    return new AccessibleIconChoiceCtrl(*this);
333
0
}
334
335
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */