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