Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/inc/toolbox.h
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 <vcl/ctrl.hxx>
23
#include <vcl/toolbox.hxx>
24
25
#include <optional>
26
#include <vector>
27
28
0
#define TB_DROPDOWNARROWWIDTH   11
29
30
0
#define TB_MENUBUTTON_SIZE      12
31
0
#define TB_MENUBUTTON_OFFSET    2
32
33
struct ImplToolItem
34
{
35
    VclPtr<vcl::Window> mpWindow; //don't dispose mpWindow - we get copied around
36
    bool                mbNonInteractiveWindow;
37
    void*               mpUserData;
38
    Image               maImage;
39
    Degree10            mnImageAngle;
40
    bool                mbMirrorMode;
41
    OUString            maText;
42
    OUString            maQuickHelpText;
43
    OUString            maHelpText;
44
    OUString            maAccessibleName;
45
    OUString            maCommandStr;
46
    OUString            maHelpId;
47
    tools::Rectangle           maRect;
48
    tools::Rectangle           maCalcRect;
49
    /// Widget layout may request size; set it as the minimal size (like, the item will always have at least this size).
50
    Size                maMinimalItemSize;
51
    /// The overall horizontal item size, including one or more of [image size + textlength + dropdown arrow]
52
    Size                maItemSize;
53
    tools::Long                mnSepSize;
54
    tools::Long                mnDropDownArrowWidth;
55
    /// Size of the content (bitmap or text, without dropdown) that we have in the item.
56
    Size                maContentSize;
57
    ToolBoxItemType     meType;
58
    ToolBoxItemBits     mnBits;
59
    TriState            meState;
60
    ToolBoxItemId       mnId;
61
    bool                mbEnabled:1,
62
                        mbVisible:1,
63
                        mbEmptyBtn:1,
64
                        mbShowWindow:1,
65
                        mbBreak:1,
66
                        mbVisibleText:1,    // indicates if text will definitely be drawn, influences dropdown pos
67
                        mbExpand:1;
68
69
                        ImplToolItem();
70
                        ImplToolItem( ToolBoxItemId nItemId, Image aImage,
71
                                      ToolBoxItemBits nItemBits );
72
                        ImplToolItem( ToolBoxItemId nItemId, OUString aTxt,
73
                                      OUString aCommand,
74
                                      ToolBoxItemBits nItemBits );
75
                        ImplToolItem( ToolBoxItemId nItemId, Image aImage,
76
                                      OUString aTxt,
77
                                      ToolBoxItemBits nItemBits );
78
79
    // returns the size of an item, taking toolbox orientation into account
80
    // the default size is the precomputed size for standard items
81
    // ie those that are just ordinary buttons (no windows or text etc.)
82
    // bCheckMaxWidth indicates that item windows must not exceed maxWidth in which case they will be painted as buttons
83
    Size                GetSize( bool bHorz, bool bCheckMaxWidth, tools::Long maxWidth, const Size& rDefaultSize );
84
85
    // only useful for buttons: returns if the text or image part or both can be drawn according to current button drawing style
86
    void DetermineButtonDrawStyle( ButtonType eButtonType, bool& rbImage, bool& rbText ) const;
87
88
    // returns the rectangle which contains the drop down arrow
89
    // or an empty rect if there is none
90
    // bHorz denotes the toolbox alignment
91
    tools::Rectangle   GetDropDownRect( bool bHorz ) const;
92
93
    // returns sal_True if the toolbar item is currently clipped, which can happen for docked toolbars
94
    bool IsClipped() const;
95
96
    // returns sal_True if the toolbar item is currently hidden i.e. they are unchecked in the toolbar Customize menu
97
    bool IsItemHidden() const;
98
99
private:
100
    void init(ToolBoxItemId nItemId, ToolBoxItemBits nItemBits, bool bEmptyBtn);
101
};
102
103
namespace vcl
104
{
105
106
struct ToolBoxLayoutData : public ControlLayoutData
107
{
108
    std::vector< ToolBoxItemId >               m_aLineItemIds;
109
};
110
111
} /* namespace vcl */
112
113
struct ImplToolBoxPrivateData
114
{
115
    std::optional<vcl::ToolBoxLayoutData> m_pLayoutData;
116
    ToolBox::ImplToolItems          m_aItems;
117
118
    ImplToolBoxPrivateData();
119
    ~ImplToolBoxPrivateData();
120
121
0
    void ImplClearLayoutData() { m_pLayoutData.reset(); }
122
123
    // called when dropdown items are clicked
124
    Link<ToolBox *, void> maDropdownClickHdl;
125
    Timer   maDropdownTimer { "vcl::ToolBox mpData->maDropdownTimer" }; // for opening dropdown items on "long click"
126
127
    // large or small buttons ?
128
    ToolBoxButtonSize   meButtonSize;
129
130
    // the optional custom menu
131
    VclPtr<PopupMenu>   mpMenu;
132
    ToolBoxMenuType maMenuType;
133
134
    // called when menu button is clicked and before the popup menu is executed
135
    Link<ToolBox *, void> maMenuButtonHdl;
136
137
    // a dummy item representing the custom menu button
138
    ImplToolItem   maMenubuttonItem;
139
    tools::Long           mnMenuButtonWidth;
140
141
    Wallpaper   maDisplayBackground;
142
143
    bool    mbIsLocked:1,           // keeps last lock state from ImplDockingWindowWrapper
144
            mbAssumeDocked:1,       // only used during calculations to override current floating/popup mode
145
            mbAssumeFloating:1,
146
            mbAssumePopupMode:1,
147
            mbKeyInputDisabled:1,   // no KEY input if all items disabled, closing/docking will be allowed though
148
            mbIsPaintLocked:1,      // don't allow paints
149
            mbMenubuttonSelected:1, // menu button is highlighted
150
            mbMenubuttonWasLastSelected:1, // menu button was highlighted when focus was lost
151
            mbNativeButtons:1,      // system supports native toolbar buttons
152
            mbWillUsePopupMode:1,   // this toolbox will be opened in popup mode
153
            mbDropDownByKeyboard:1; // tells whether a dropdown was started by key input
154
};
155
156
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */