Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/svtools/ctrlbox.hxx
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
#pragma once
21
22
#include <tools/date.hxx>
23
#include <svtools/borderline.hxx>
24
#include <svtools/svtdllapi.h>
25
#include <svtools/toolbarmenu.hxx>
26
#include <vcl/idle.hxx>
27
#include <vcl/metric.hxx>
28
#include <vcl/weld/Calendar.hxx>
29
#include <vcl/weld/ComboBox.hxx>
30
#include <vcl/weld/MenuButton.hxx>
31
32
#include <memory>
33
34
namespace weld
35
{
36
class Builder;
37
class Button;
38
class CustomWeld;
39
class TreeIter;
40
class TreeView;
41
}
42
43
class Bitmap;
44
class FontList;
45
class VclSimpleEvent;
46
class VirtualDevice;
47
48
enum class SvxBorderLineStyle : sal_Int16;
49
enum class FieldUnit : sal_uInt16;
50
51
/** Utility class storing the border line width, style and colors. The widths
52
    are defined in Twips.
53
  */
54
class ImpLineListData
55
{
56
private:
57
    BorderWidthImpl const m_aWidthImpl;
58
59
    Color  ( * m_pColor1Fn )( Color );
60
    Color  ( * m_pColor2Fn )( Color );
61
    Color  ( * m_pColorDistFn )( Color, Color );
62
63
    tools::Long    m_nMinWidth;
64
    SvxBorderLineStyle m_nStyle;
65
66
public:
67
    ImpLineListData( BorderWidthImpl aWidthImpl,
68
           SvxBorderLineStyle nStyle, tools::Long nMinWidth, Color ( *pColor1Fn )( Color ),
69
           Color ( *pColor2Fn )( Color ), Color ( *pColorDistFn )( Color, Color ) ) :
70
0
        m_aWidthImpl( aWidthImpl ),
71
0
        m_pColor1Fn( pColor1Fn ),
72
0
        m_pColor2Fn( pColor2Fn ),
73
0
        m_pColorDistFn( pColorDistFn ),
74
0
        m_nMinWidth( nMinWidth ),
75
0
        m_nStyle( nStyle )
76
0
    {
77
0
    }
78
79
    /** Returns the computed width of the line 1 in twips. */
80
0
    tools::Long GetLine1ForWidth( tools::Long nWidth ) const { return m_aWidthImpl.GetLine1( nWidth ); }
81
82
    /** Returns the computed width of the line 2 in twips. */
83
0
    tools::Long GetLine2ForWidth( tools::Long nWidth ) const { return m_aWidthImpl.GetLine2( nWidth ); }
84
85
    /** Returns the computed width of the gap in twips. */
86
0
    tools::Long GetDistForWidth( tools::Long nWidth ) const { return m_aWidthImpl.GetGap( nWidth ); }
87
88
    Color GetColorLine1( const Color& rMain ) const
89
0
    {
90
0
        return ( *m_pColor1Fn )( rMain );
91
0
    }
92
93
    Color GetColorLine2( const Color& rMain ) const
94
0
    {
95
0
        return ( *m_pColor2Fn )( rMain );
96
0
    }
97
98
    Color GetColorDist( const Color& rMain, const Color& rDefault ) const
99
0
    {
100
0
        return ( *m_pColorDistFn )( rMain, rDefault );
101
0
    }
102
103
    /** Returns the minimum width in twips */
104
0
    tools::Long   GetMinWidth( ) const { return m_nMinWidth;}
105
0
    SvxBorderLineStyle GetStyle( ) const { return m_nStyle;}
106
};
107
108
enum class SvxBorderLineStyle : sal_Int16;
109
110
typedef ::std::vector< FontMetric         > ImplFontList;
111
112
/*************************************************************************
113
114
class LineListBox
115
116
Description
117
118
Allows selection of line styles and sizes. Note that before first insert,
119
units and window size need to be set. Supported units are typographic point
120
(pt) and millimeters (mm). For SourceUnit, pt, mm and twips are supported.
121
All scalar numbers in 1/100 of the corresponding unit.
122
123
Line1 is the outer, Line2 the inner line, Distance is the distance between
124
these two lines. If Line2 == 0, only Line1 will be shown. Defaults for
125
source and target unit are FieldUnit::POINT.
126
127
SetColor() sets the line color.
128
129
Remarks
130
131
Contrary to a simple ListBox, user-specific data are not supported.
132
If UpdateMode is disabled, no data should be read, no selections
133
should be set, and the return code shall be ignore, as in these are
134
not defined in this mode. Also the bit WinBit WB_SORT may not be set.
135
136
--------------------------------------------------------------------------
137
138
class FontNameBox
139
140
Description
141
142
Allows selection of fonts. The ListBox will be filled using Fill parameter,
143
which is pointer to an FontList object.
144
145
Calling EnableWYSIWYG() enables rendering the font name in the currently
146
selected font.
147
148
See also
149
150
FontList; FontStyleBox; FontSizeBox; FontNameMenu
151
152
--------------------------------------------------------------------------
153
154
class FontStyleBox
155
156
Description
157
158
Allows select of FontStyle's. The parameter Fill points to a list
159
of available font styles for the font.
160
161
Reproduced styles are always added - this could change in future, as
162
potentially not all applications [Draw,Equation,FontWork] can properly
163
handle synthetic fonts. On filling, the previous name will be retained
164
if possible.
165
166
For DontKnow, the FontStyleBox should be filled with OUString(),
167
so it will contain a list with the default attributes. The currently
168
shown style probably needs to be reset by the application.
169
170
See also
171
172
FontList; FontNameBox; FontSizeBox;
173
174
--------------------------------------------------------------------------
175
176
class FontSizeBox
177
178
Description
179
180
Allows selection of font sizes. The values are retrieved via GetValue()
181
and set via SetValue(). The Fill parameter fills the ListBox with the
182
available sizes for the passed font.
183
184
All sizes are in 1/10 typographic point (pt).
185
186
The passed FontList must be retained until the next fill call.
187
188
Additionally it supports a relative mod, which allows entering
189
percentage values. This, eg., can be useful for template dialogs.
190
This mode can only be enabled, but not disabled again.
191
192
For DontKnow the FontSizeBox should be filled FontMetric(), so it will
193
contain a list with the standard sizes. Th currently shown size
194
probably needs to be reset by the application.
195
196
See also
197
198
FontList; FontNameBox; FontStyleBox; FontSizeMenu
199
200
*************************************************************************/
201
202
inline Color sameColor( Color rMain )
203
0
{
204
0
    return rMain;
205
0
}
206
207
inline Color sameDistColor( Color /*rMain*/, Color rDefault )
208
0
{
209
0
    return rDefault;
210
0
}
211
212
class ValueSet;
213
214
class SVT_DLLPUBLIC SvtLineListBox final : public WeldToolbarPopup
215
{
216
public:
217
    typedef Color (*ColorFunc)(Color);
218
    typedef Color (*ColorDistFunc)(Color, Color);
219
220
    SvtLineListBox(std::unique_ptr<weld::MenuButton> pControl);
221
    ~SvtLineListBox();
222
223
    static OUString GetLineStyleName(SvxBorderLineStyle eStyle);
224
225
    /** Set the width in Twips */
226
    void SetWidth(tools::Long nWidth)
227
0
    {
228
0
        m_nWidth = nWidth;
229
0
        UpdateEntries();
230
0
        UpdatePreview();
231
0
    }
232
233
0
    tools::Long GetWidth() const { return m_nWidth; }
234
235
    /** Insert a listbox entry with all widths in Twips. */
236
    void            InsertEntry(const BorderWidthImpl& rWidthImpl,
237
                        SvxBorderLineStyle nStyle, tools::Long nMinWidth = 0,
238
                        ColorFunc pColor1Fn = &sameColor,
239
                        ColorFunc pColor2Fn = &sameColor,
240
                        ColorDistFunc pColorDistFn = &sameDistColor);
241
242
    void            SelectEntry( SvxBorderLineStyle nStyle );
243
    SvxBorderLineStyle GetSelectEntryStyle() const;
244
245
0
    void            SetSourceUnit( FieldUnit eNewUnit ) { eSourceUnit = eNewUnit; }
246
247
    void            SetColor( const Color& rColor )
248
0
    {
249
0
        aColor = rColor;
250
0
        UpdateEntries();
251
0
        UpdatePreview();
252
0
    }
253
254
0
    void            SetSelectHdl(const Link<SvtLineListBox&,void>& rLink) { maSelectHdl = rLink; }
255
256
0
    void            set_sensitive(bool bSensitive) { m_xControl->set_sensitive(bSensitive); }
257
258
    virtual void    GrabFocus() override;
259
260
private:
261
    SVT_DLLPRIVATE Image GetLineImage(const ImpLineListData& rLineListData);
262
    SVT_DLLPRIVATE ScopedVclPtr<VirtualDevice> GetLineImage(int nIndex);
263
264
    DECL_DLLPRIVATE_LINK(ItemActivatedHdl, const weld::TreeIter&, bool);
265
    DECL_DLLPRIVATE_LINK(ToggleHdl, weld::Toggleable&, void);
266
    DECL_DLLPRIVATE_LINK(NoneHdl, weld::Button&, void);
267
    DECL_DLLPRIVATE_LINK(StyleUpdatedHdl, weld::Widget&, void);
268
269
    void            UpdateEntries();
270
271
    void HandleEntrySelection();
272
    void UpdatePreview();
273
274
                    SvtLineListBox( const SvtLineListBox& ) = delete;
275
    SvtLineListBox&    operator =( const SvtLineListBox& ) = delete;
276
277
    std::unique_ptr<weld::MenuButton> m_xControl;
278
    std::unique_ptr<weld::Button> m_xNoneButton;
279
    std::unique_ptr<weld::TreeView> m_xLineTreeView;
280
281
    std::vector<std::unique_ptr<ImpLineListData>> m_vLineList;
282
    tools::Long            m_nWidth;
283
    ScopedVclPtr<VirtualDevice>   aVirDev;
284
    Color           aColor;
285
    FieldUnit       eSourceUnit;
286
    Link<SvtLineListBox&,void> maSelectHdl;
287
};
288
289
class SVT_DLLPUBLIC SvtCalendarBox
290
{
291
public:
292
    SvtCalendarBox(std::unique_ptr<weld::MenuButton> pControl, bool bUseLabel = true);
293
    ~SvtCalendarBox();
294
295
0
    weld::MenuButton& get_button() { return *m_xControl; }
296
297
    void set_date(const Date& rDate);
298
0
    Date get_date() const { return m_xCalendar->get_date(); }
299
300
0
    void set_label(const OUString& rLabel) { m_xControl->set_label(rLabel); }
301
0
    OUString get_label() const { return m_xControl->get_label(); }
302
303
0
    void set_sensitive(bool bSensitive) { m_xControl->set_sensitive(bSensitive); }
304
0
    bool get_sensitive() const { return m_xControl->get_sensitive(); }
305
0
    void set_visible(bool bSensitive) { m_xControl->set_visible(bSensitive); }
306
0
    void show() { set_visible(true); }
307
0
    void grab_focus() { m_xControl->grab_focus(); }
308
309
0
    void connect_activated(const Link<SvtCalendarBox&, void>& rActivatedHdl) { m_aActivatedHdl = rActivatedHdl; }
310
0
    void connect_selected(const Link<SvtCalendarBox&, void>& rSelectHdl) { m_aSelectHdl = rSelectHdl; }
311
312
0
    void connect_focus_in(const Link<weld::Widget&, void>& rLink) { m_xControl->connect_focus_in(rLink); }
313
0
    void connect_focus_out(const Link<weld::Widget&, void>& rLink) { m_xControl->connect_focus_out(rLink); }
314
private:
315
    DECL_DLLPRIVATE_LINK(SelectHdl, weld::Calendar&, void);
316
    DECL_DLLPRIVATE_LINK(ActivateHdl, weld::Calendar&, void);
317
318
    bool m_bUseLabel;
319
320
    std::unique_ptr<weld::MenuButton> m_xControl;
321
    std::unique_ptr<weld::Builder> m_xBuilder;
322
    std::unique_ptr<weld::Widget> m_xTopLevel;
323
    std::unique_ptr<weld::Calendar> m_xCalendar;
324
325
    Link<SvtCalendarBox&, void> m_aActivatedHdl;
326
    Link<SvtCalendarBox&, void> m_aSelectHdl;
327
328
    void set_label_from_date();
329
};
330
331
class SVT_DLLPUBLIC FontNameBox
332
{
333
private:
334
    std::unique_ptr<weld::ComboBox> m_xComboBox;
335
    std::unique_ptr<ImplFontList> mpFontList;
336
    size_t          mnPreviewProgress;
337
    bool            mbWYSIWYG;
338
    OUString        maFontMRUEntriesFile;
339
    Idle            maUpdateIdle;
340
    Link<const FontMetric&, void> m_aLivePreviewHdl;
341
342
    SVT_DLLPRIVATE void         ImplDestroyFontList();
343
344
    DECL_DLLPRIVATE_LINK(CustomRenderHdl, weld::ComboBox::render_args, void);
345
    DECL_DLLPRIVATE_LINK(CustomGetSizeHdl, OutputDevice&, Size);
346
    DECL_DLLPRIVATE_LINK(SettingsChangedHdl, VclSimpleEvent&, void);
347
    DECL_DLLPRIVATE_LINK(UpdateHdl, Timer*, void);
348
349
    void            LoadMRUEntries( const OUString& aFontMRUEntriesFile );
350
    void            SaveMRUEntries( const OUString& aFontMRUEntriesFile ) const;
351
352
    OutputDevice&   CachePreview(size_t nIndex, Point* pTopLeft,
353
                                 sal_Int32 nDPIX = 96, sal_Int32 nDPIY = 96);
354
355
public:
356
    FontNameBox(std::unique_ptr<weld::ComboBox> p);
357
    ~FontNameBox();
358
359
    void            Fill( const FontList* pList );
360
361
    void            EnableWYSIWYG(bool bEnable);
362
0
    bool            IsWYSIWYGEnabled() const { return mbWYSIWYG; }
363
364
0
    void connect_changed(const Link<weld::ComboBox&, void>& rLink) { m_xComboBox->connect_changed(rLink); }
365
0
    void connect_focus_in(const Link<weld::Widget&, void>& rLink) { m_xComboBox->connect_focus_in(rLink); }
366
0
    void connect_focus_out(const Link<weld::Widget&, void>& rLink) { m_xComboBox->connect_focus_out(rLink); }
367
0
    void connect_key_press(const Link<const KeyEvent&, bool>& rLink) { m_xComboBox->connect_key_press(rLink); }
368
0
    void connect_popup_toggled(const Link<weld::ComboBox&, void>& rLink){ m_xComboBox->connect_popup_toggled(rLink); }
369
0
    void connect_live_preview(const Link<const FontMetric&, void>& rLink) { m_aLivePreviewHdl = rLink; }
370
0
    OUString get_active_text() const { return m_xComboBox->get_active_text(); }
371
    void set_active_or_entry_text(const OUString& rText);
372
0
    void set_active(int nPos) { m_xComboBox->set_active(nPos); }
373
0
    void set_sensitive(bool bSensitive) { m_xComboBox->set_sensitive(bSensitive); }
374
0
    void save_value() { m_xComboBox->save_value(); }
375
0
    OUString const& get_saved_value() const { return m_xComboBox->get_saved_value(); }
376
0
    void select_entry_region(int nStartPos, int nEndPos) { m_xComboBox->select_entry_region(nStartPos, nEndPos); }
377
0
    bool get_entry_selection_bounds(int& rStartPos, int& rEndPos) { return m_xComboBox->get_entry_selection_bounds(rStartPos, rEndPos); }
378
0
    void clear() { m_xComboBox->clear(); }
379
0
    void grab_focus() { m_xComboBox->grab_focus(); }
380
0
    bool has_focus() const { return m_xComboBox->has_focus(); }
381
0
    void connect_entry_activate(const Link<weld::ComboBox&, bool>& rLink) { m_xComboBox->connect_entry_activate(rLink); }
382
0
    void set_entry_width_chars(int nWidth) { m_xComboBox->set_entry_width_chars(nWidth); }
383
0
    void set_size_request(int nWidth, int nHeight) { m_xComboBox->set_size_request(nWidth, nHeight); }
384
0
    int get_max_mru_count() const { return m_xComboBox->get_max_mru_count(); }
385
0
    void set_max_mru_count(int nCount) { m_xComboBox->set_max_mru_count(nCount); }
386
387
    // font size is in points, not pixels, e.g. see Window::[G]etPointFont
388
0
    void set_entry_font(const vcl::Font& rFont) { m_xComboBox->set_entry_font(rFont); }
389
0
    void set_entry_message_type(weld::EntryMessageType eType) { m_xComboBox->set_entry_message_type(eType); }
390
0
    vcl::Font get_entry_font() { return m_xComboBox->get_entry_font(); }
391
392
0
    void set_tooltip_text(const OUString& rTip) { m_xComboBox->set_tooltip_text(rTip); }
393
394
private:
395
    void            InitFontMRUEntriesFile();
396
397
                    FontNameBox( const FontNameBox& ) = delete;
398
    FontNameBox&    operator =( const FontNameBox& ) = delete;
399
};
400
401
class SVT_DLLPUBLIC FontStyleBox
402
{
403
    std::unique_ptr<weld::ComboBox> m_xComboBox;
404
    OUString m_aLastStyle;
405
    Link<weld::ComboBox&, void> m_aChangedLink;
406
public:
407
    FontStyleBox(std::unique_ptr<weld::ComboBox> p);
408
409
    void Fill(std::u16string_view rName, const FontList* pList);
410
411
0
    void connect_changed(const Link<weld::ComboBox&, void>& rLink) { m_aChangedLink = rLink; }
412
0
    OUString get_active_text() const { return m_xComboBox->get_active_text(); }
413
    void set_active_text(const OUString& rText)
414
0
    {
415
0
        m_aLastStyle = rText;
416
0
        m_xComboBox->set_active_text(rText);
417
0
    }
418
    void set_active_or_entry_text(const OUString& rText);
419
0
    void set_size_request(int nWidth, int nHeight) {  m_xComboBox->set_size_request(nWidth, nHeight); }
420
421
0
    void append_text(const OUString& rStr) { m_xComboBox->append_text(rStr); }
422
0
    void set_sensitive(bool bSensitive) { m_xComboBox->set_sensitive(bSensitive); }
423
0
    void save_value() { m_xComboBox->save_value(); }
424
0
    OUString const& get_saved_value() const { return m_xComboBox->get_saved_value(); }
425
0
    int get_count() const { return m_xComboBox->get_count(); }
426
0
    int find_text(const OUString& rStr) const { return m_xComboBox->find_text(rStr); }
427
private:
428
    FontStyleBox(const FontStyleBox& ) = delete;
429
    FontStyleBox& operator=(const FontStyleBox&) = delete;
430
431
    DECL_LINK(ChangeHdl, weld::ComboBox&, void);
432
};
433
434
class SVT_DLLPUBLIC FontSizeBox
435
{
436
    const FontList* m_pFontList;
437
    int m_nSavedValue;
438
    int m_nMin;
439
    int m_nMax;
440
    FieldUnit m_eUnit;
441
    sal_uInt16 m_nDecimalDigits;
442
    sal_uInt16 m_nRelMin;
443
    sal_uInt16 m_nRelMax;
444
    sal_uInt16 m_nRelStep;
445
    short m_nPtRelMin;
446
    short m_nPtRelMax;
447
    short m_nPtRelStep;
448
    bool m_bRelativeMode : 1;
449
    bool m_bRelative : 1;
450
    bool m_bPtRelative : 1;
451
    bool m_bStdSize : 1;
452
    Link<weld::ComboBox&, void> m_aChangeHdl;
453
    Link<weld::Widget&, void> m_aFocusOutHdl;
454
    std::unique_ptr<weld::ComboBox> m_xComboBox;
455
456
0
    sal_uInt16 GetDecimalDigits() const { return m_nDecimalDigits; }
457
0
    void SetDecimalDigits(sal_uInt16 nDigits) { m_nDecimalDigits = nDigits; }
458
0
    FieldUnit GetUnit() const { return m_eUnit; }
459
0
    void SetUnit(FieldUnit _eUnit) { m_eUnit = _eUnit; }
460
    void SetRange(int nNewMin, int nNewMax)
461
0
    {
462
0
        m_nMin = nNewMin;
463
0
        m_nMax = nNewMax;
464
0
    }
465
    void SetValue(int nNewValue, FieldUnit eInUnit);
466
467
    void InsertValue(int i);
468
469
    OUString format_number(int nValue) const;
470
471
    DECL_DLLPRIVATE_LINK(ModifyHdl, weld::ComboBox&, void);
472
    DECL_DLLPRIVATE_LINK(ReformatHdl, weld::Widget&, void);
473
public:
474
    FontSizeBox(std::unique_ptr<weld::ComboBox> p);
475
476
    void Fill(const FontList* pList);
477
478
    void EnableRelativeMode(sal_uInt16 nMin, sal_uInt16 nMax, sal_uInt16 nStep = 5);
479
    void EnablePtRelativeMode(short nMin, short nMax, short nStep = 10);
480
0
    bool IsRelativeMode() const { return m_bRelativeMode; }
481
    void SetRelative( bool bRelative );
482
0
    bool IsRelative() const { return m_bRelative; }
483
    void SetPtRelative( bool bPtRel )
484
0
    {
485
0
        m_bPtRelative = bPtRel;
486
0
        SetRelative(true);
487
0
    }
488
0
    bool IsPtRelative() const { return m_bPtRelative; }
489
490
0
    void connect_changed(const Link<weld::ComboBox&, void>& rLink) { m_aChangeHdl = rLink; }
491
0
    void connect_focus_out(const Link<weld::Widget&, void>& rLink) { m_aFocusOutHdl = rLink; }
492
0
    void connect_key_press(const Link<const KeyEvent&, bool>& rLink) { m_xComboBox->connect_key_press(rLink); }
493
0
    OUString get_active_text() const { return m_xComboBox->get_active_text(); }
494
    void set_active_or_entry_text(const OUString& rText);
495
0
    void set_sensitive(bool bSensitive) { m_xComboBox->set_sensitive(bSensitive); }
496
0
    void set_size_request(int nWidth, int nHeight) { m_xComboBox->set_size_request(nWidth, nHeight); }
497
498
    int get_value() const;
499
    void set_value(int nValue);
500
0
    void save_value() { m_nSavedValue = get_value(); }
501
0
    int get_saved_value() const { return m_nSavedValue; }
502
0
    bool get_value_changed_from_saved() const { return get_value() != get_saved_value(); }
503
0
    bool has_focus() const { return m_xComboBox->has_focus(); }
504
0
    void connect_entry_activate(const Link<weld::ComboBox&, bool>& rLink) { m_xComboBox->connect_entry_activate(rLink); }
505
0
    void disable_entry_completion() { m_xComboBox->set_entry_completion(false, false); }
506
507
0
    weld::Widget* getWidget() { return m_xComboBox.get(); }
508
509
private:
510
    FontSizeBox(const FontSizeBox&) = delete;
511
    FontSizeBox& operator=(const FontSizeBox&) = delete;
512
};
513
514
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */