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