bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / svtools / ivctrl.hxx
blobec28ec339c265a05aa09a0cf2ca2e0a34e6730f1
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_SVTOOLS_IVCTRL_HXX
21 #define INCLUDED_SVTOOLS_IVCTRL_HXX
23 #include <memory>
24 #include <svtools/svtdllapi.h>
25 #include <vcl/ctrl.hxx>
26 #include <tools/link.hxx>
27 #include <vcl/image.hxx>
28 #include <o3tl/deleter.hxx>
29 #include <o3tl/typed_flags_set.hxx>
31 class SvxIconChoiceCtrl_Impl;
33 enum class SvxIconViewFlags
35 NONE = 0x0000,
36 POS_LOCKED = 0x0001,
37 SELECTED = 0x0002,
38 FOCUSED = 0x0004,
39 POS_MOVED = 0x0008, // Moved by Drag and Drop, but not logged
41 namespace o3tl
43 template<> struct typed_flags<SvxIconViewFlags> : is_typed_flags<SvxIconViewFlags, 0x000f> {};
46 enum class SvxIconChoiceCtrlTextMode
48 Full = 1, // Enlarge BoundRect southwards
49 Short // Shorten with "..."
52 enum class SvxIconChoiceCtrlPositionMode
54 Free, // Free pixel-perfect positioning
55 AutoArrange, // Auto arrange
58 class SvxIconChoiceCtrlEntry
60 Image const aImage;
62 OUString aText;
63 OUString aQuickHelpText;
64 void* pUserData;
66 friend class SvxIconChoiceCtrl_Impl;
67 friend class IcnCursor_Impl;
68 friend class EntryList_Impl;
69 friend class IcnGridMap_Impl;
71 tools::Rectangle aRect; // Bounding-Rectangle of the entry
72 tools::Rectangle aGridRect; // Only valid in Grid-mode
73 sal_Int32 nPos;
76 The insert position in the Insertlist is equal to the (sort) order stated at the Insert
77 (-> Order of the anchors in the anchors-list!). In "AutoArrange" mode the visible order
78 can differ. The entries will be linked because of this.
80 SvxIconChoiceCtrlEntry* pblink; // backward (linker neighbour)
81 SvxIconChoiceCtrlEntry* pflink; // forward (rechter neighbour)
83 SvxIconChoiceCtrlTextMode eTextMode;
84 sal_uInt16 nX,nY; // for keyboard control
85 SvxIconViewFlags nFlags;
87 void ClearFlags( SvxIconViewFlags nMask ) { nFlags &= ~nMask; }
88 void SetFlags( SvxIconViewFlags nMask ) { nFlags |= nMask; }
89 void AssignFlags( SvxIconViewFlags _nFlags ) { nFlags = _nFlags; }
91 // set left neighbour (A <-> B ==> A <-> this <-> B)
92 void SetBacklink( SvxIconChoiceCtrlEntry* pA )
94 pA->pflink->pblink = this; // X <- B
95 this->pflink = pA->pflink; // X -> B
96 this->pblink = pA; // A <- X
97 pA->pflink = this; // A -> X
99 // Unlink (A <-> this <-> B ==> A <-> B)
100 void Unlink()
102 this->pblink->pflink = this->pflink;
103 this->pflink->pblink = this->pblink;
104 this->pflink = nullptr;
105 this->pblink = nullptr;
108 public:
109 SvxIconChoiceCtrlEntry( const OUString& rText, const Image& rImage );
111 const Image& GetImage () const { return aImage; }
112 void SetText ( const OUString& rText ) { aText = rText; }
113 const OUString& GetText () const { return aText; }
114 OUString SVT_DLLPUBLIC GetDisplayText() const;
115 void SetQuickHelpText( const OUString& rText ) { aQuickHelpText = rText; }
116 const OUString& GetQuickHelpText() const { return aQuickHelpText; }
117 void SetUserData ( void* _pUserData ) { pUserData = _pUserData; }
118 void* GetUserData () { return pUserData; }
120 SvxIconChoiceCtrlTextMode GetTextMode() const { return eTextMode; }
121 SvxIconViewFlags GetFlags() const { return nFlags; }
122 bool IsSelected() const { return bool(nFlags & SvxIconViewFlags::SELECTED); }
123 bool IsFocused() const { return bool(nFlags & SvxIconViewFlags::FOCUSED); }
124 bool IsPosLocked() const { return bool(nFlags & SvxIconViewFlags::POS_LOCKED); }
127 class SvxIconChoiceCtrlColumnInfo
129 long nWidth;
131 public:
132 SvxIconChoiceCtrlColumnInfo() :
133 nWidth( 100 ) {}
134 SvxIconChoiceCtrlColumnInfo( const SvxIconChoiceCtrlColumnInfo& );
136 void SetWidth( long nWd ) { nWidth = nWd; }
137 long GetWidth() const { return nWidth; }
142 Window-Bits:
143 WB_ICON // Text beneath the icon
144 WB_SMALL_ICON // Text right to the icon, position does not mind
145 WB_DETAILS // Text right to the icon, limited positioning
146 WB_BORDER
147 WB_NOHIDESELECTION // Draw selection inactively, if not focused.
148 WB_NOHSCROLL
149 WB_NOVSCROLL
150 WB_NOSELECTION
151 WB_SMART_ARRANGE // Keep Visible-Area at arrange
152 WB_ALIGN_TOP // Align line vy line LTR
153 WB_ALIGN_LEFT // Align columns from top to bottom
154 WB_NODRAGSELECTION // No selection with tracking rectangle
155 WB_NOCOLUMNHEADER // No Headerbar in Details view (Headerbar not implemented)
156 WB_NOPOINTERFOCUS // No GrabFocus at MouseButtonDown
157 WB_HIGHLIGHTFRAME // The entry beneath the mouse will be highlighted
158 WB_NOASYNCSELECTHDL // Do not collect events -> Selection handlers will be called synchronously
161 #define WB_ICON WB_RECTSTYLE
162 #define WB_SMALLICON WB_SMALLSTYLE
163 #define WB_DETAILS WB_VCENTER
164 #define WB_NOHSCROLL WB_SPIN
165 #define WB_NOVSCROLL WB_DRAG
166 #define WB_NOSELECTION WB_REPEAT
167 #define WB_NODRAGSELECTION WB_PATHELLIPSIS
168 #define WB_SMART_ARRANGE 0x01000000 // used to be WB_PASSWORD
169 #define WB_ALIGN_TOP WB_TOP
170 #define WB_ALIGN_LEFT WB_LEFT
171 #define WB_NOCOLUMNHEADER WB_CENTER
172 #define WB_HIGHLIGHTFRAME WB_IGNORETAB
173 #define WB_NOASYNCSELECTHDL WB_NOLABEL
175 class MnemonicGenerator;
177 class SVT_DLLPUBLIC SvtIconChoiceCtrl : public Control
179 friend class SvxIconChoiceCtrl_Impl;
181 Link<SvtIconChoiceCtrl*,void> _aClickIconHdl;
182 std::unique_ptr<SvxIconChoiceCtrl_Impl, o3tl::default_delete<SvxIconChoiceCtrl_Impl>> _pImpl;
184 protected:
186 virtual void KeyInput( const KeyEvent& rKEvt ) override;
187 virtual void Command( const CommandEvent& rCEvt ) override;
188 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
189 virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
190 virtual void MouseButtonUp( const MouseEvent& rMEvt ) override;
191 virtual void MouseMove( const MouseEvent& rMEvt ) override;
192 virtual void Resize() override;
193 virtual void GetFocus() override;
194 virtual void LoseFocus() override;
195 void ClickIcon();
196 virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
197 virtual void RequestHelp( const HelpEvent& rHEvt ) override;
198 static void DrawEntryImage(
199 SvxIconChoiceCtrlEntry const * pEntry,
200 const Point& rPos,
201 OutputDevice& rDev );
203 static OUString GetEntryText( SvxIconChoiceCtrlEntry const * pEntry );
205 virtual void FillLayoutData() const override;
207 void CallImplEventListeners(VclEventId nEvent, void* pData);
209 public:
211 SvtIconChoiceCtrl( vcl::Window* pParent, WinBits nWinStyle );
212 virtual ~SvtIconChoiceCtrl() override;
213 virtual void dispose() override;
215 void SetStyle( WinBits nWinStyle );
216 WinBits GetStyle() const;
218 void SetChoiceWithCursor();
220 void SetFont( const vcl::Font& rFont );
221 void SetPointFont( const vcl::Font& rFont );
223 void SetClickHdl( const Link<SvtIconChoiceCtrl*,void>& rLink ) { _aClickIconHdl = rLink; }
224 const Link<SvtIconChoiceCtrl*,void>& GetClickHdl() const { return _aClickIconHdl; }
226 using OutputDevice::SetBackground;
227 void SetBackground( const Wallpaper& rWallpaper );
229 void ArrangeIcons();
232 SvxIconChoiceCtrlEntry* InsertEntry( const OUString& rText,
233 const Image& rImage);
235 /** creates automatic mnemonics for all icon texts in the control
237 @param _rUsedMnemonics
238 a MnemonicGenerator at which some other mnemonics are already registered.
239 This can be used if the control needs to share the "mnemonic space" with other elements,
240 such as a menu bar.
242 void CreateAutoMnemonics( MnemonicGenerator& _rUsedMnemonics );
244 bool DoKeyInput( const KeyEvent& rKEvt );
246 sal_Int32 GetEntryCount() const;
247 SvxIconChoiceCtrlEntry* GetEntry( sal_Int32 nPos ) const;
248 sal_Int32 GetEntryListPos( SvxIconChoiceCtrlEntry const * pEntry ) const;
249 using Window::SetCursor;
250 void SetCursor( SvxIconChoiceCtrlEntry* pEntry );
251 SvxIconChoiceCtrlEntry* GetCursor() const;
253 // Re-calculation of cached view-data and invalidation of those in the view
254 void InvalidateEntry( SvxIconChoiceCtrlEntry* pEntry );
256 // Entry is selected, if the BoundRect is selected
257 SvxIconChoiceCtrlEntry* GetEntry( const Point& rPosPixel ) const;
259 // sal_uLong is the position of the selected element in the list
260 SvxIconChoiceCtrlEntry* GetSelectedEntry() const;
262 #ifdef DBG_UTIL
263 void SetEntryTextMode( SvxIconChoiceCtrlTextMode eMode, SvxIconChoiceCtrlEntry* pEntry );
264 #endif
266 void SetSelectionMode( SelectionMode eMode );
268 tools::Rectangle GetBoundingBox( SvxIconChoiceCtrlEntry* pEntry ) const;
269 tools::Rectangle GetEntryCharacterBounds( const sal_Int32 _nEntryPos, const sal_Int32 _nCharacterIndex ) const;
271 void SetNoSelection();
273 // ACCESSIBILITY ==========================================================
275 /** Creates and returns the accessible object of the Box. */
276 virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible() override;
279 #endif // INCLUDED_SVTOOLS_IVCTRL_HXX
281 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */