1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
24 #include <svtools/svtdllapi.h>
25 #include <vcl/ctrl.hxx>
26 #include <tools/link.hxx>
27 #include <tools/contnr.hxx>
28 #include <vcl/image.hxx>
29 #include <vcl/seleng.hxx>
30 #include <o3tl/typed_flags_set.hxx>
33 class SvxIconChoiceCtrl_Impl
;
36 enum class SvxIconViewFlags
42 CURSORED
= 0x0010, // Border around image
43 POS_MOVED
= 0x0020, // Moved by Drag and Drop, but not logged
44 DROP_TARGET
= 0x0040, // Set in QueryDrop
45 BLOCK_EMPHASIS
= 0x0080, // Do not paint Emphasis
46 PRED_SET
= 0x0400, // Predecessor moved
50 template<> struct typed_flags
<SvxIconViewFlags
> : is_typed_flags
<SvxIconViewFlags
, 0x04f7> {};
53 enum class SvxIconChoiceCtrlTextMode
55 Full
= 1, // Enlarge BoundRect southwards
56 Short
// Shorten with "..."
59 enum class SvxIconChoiceCtrlPositionMode
61 Free
, // Free pixel-perfect positioning
62 AutoArrange
, // Auto arrange
65 class SvxIconChoiceCtrlEntry
70 OUString aQuickHelpText
;
73 friend class SvxIconChoiceCtrl_Impl
;
74 friend class IcnCursor_Impl
;
75 friend class EntryList_Impl
;
76 friend class IcnGridMap_Impl
;
78 tools::Rectangle aRect
; // Bounding-Rectangle of the entry
79 tools::Rectangle aGridRect
; // Only valid in Grid-mode
83 The insert position in the Insertlist is equal to the (sort) order stated at the Insert
84 (-> Order of the anchors in the anchors-list!). In "AutoArrange" mode the visible order
85 can differ. The entries will be linked because of this.
87 SvxIconChoiceCtrlEntry
* pblink
; // backward (linker neighbour)
88 SvxIconChoiceCtrlEntry
* pflink
; // forward (rechter neighbour)
90 SvxIconChoiceCtrlTextMode eTextMode
;
91 sal_uInt16 nX
,nY
; // for keyboard control
92 SvxIconViewFlags nFlags
;
94 void ClearFlags( SvxIconViewFlags nMask
) { nFlags
&= (~nMask
); }
95 void SetFlags( SvxIconViewFlags nMask
) { nFlags
|= nMask
; }
96 void AssignFlags( SvxIconViewFlags _nFlags
) { nFlags
= _nFlags
; }
98 // set left neighbour (A <-> B ==> A <-> this <-> B)
99 void SetBacklink( SvxIconChoiceCtrlEntry
* pA
)
101 pA
->pflink
->pblink
= this; // X <- B
102 this->pflink
= pA
->pflink
; // X -> B
103 this->pblink
= pA
; // A <- X
104 pA
->pflink
= this; // A -> X
106 // Unlink (A <-> this <-> B ==> A <-> B)
109 this->pblink
->pflink
= this->pflink
;
110 this->pflink
->pblink
= this->pblink
;
111 this->pflink
= nullptr;
112 this->pblink
= nullptr;
116 SvxIconChoiceCtrlEntry( const OUString
& rText
, const Image
& rImage
);
118 const Image
& GetImage () const { return aImage
; }
119 void SetText ( const OUString
& rText
) { aText
= rText
; }
120 const OUString
& GetText () const { return aText
; }
121 OUString SVT_DLLPUBLIC
GetDisplayText() const;
122 void SetQuickHelpText( const OUString
& rText
) { aQuickHelpText
= rText
; }
123 const OUString
& GetQuickHelpText() const { return aQuickHelpText
; }
124 void SetUserData ( void* _pUserData
) { pUserData
= _pUserData
; }
125 void* GetUserData () { return pUserData
; }
127 SvxIconChoiceCtrlTextMode
GetTextMode() const { return eTextMode
; }
128 SvxIconViewFlags
GetFlags() const { return nFlags
; }
129 bool IsSelected() const { return bool(nFlags
& SvxIconViewFlags::SELECTED
); }
130 bool IsFocused() const { return bool(nFlags
& SvxIconViewFlags::FOCUSED
); }
131 bool IsCursored() const { return bool(nFlags
& SvxIconViewFlags::CURSORED
); }
132 bool IsDropTarget() const { return bool(nFlags
& SvxIconViewFlags::DROP_TARGET
); }
133 bool IsBlockingEmphasis() const { return bool(nFlags
& SvxIconViewFlags::BLOCK_EMPHASIS
); }
134 bool IsPosLocked() const { return bool(nFlags
& SvxIconViewFlags::POS_LOCKED
); }
137 class SvxIconChoiceCtrlColumnInfo
142 SvxIconChoiceCtrlColumnInfo() :
144 SvxIconChoiceCtrlColumnInfo( const SvxIconChoiceCtrlColumnInfo
& );
146 void SetWidth( long nWd
) { nWidth
= nWd
; }
147 long GetWidth() const { return nWidth
; }
153 WB_ICON // Text beneath the icon
154 WB_SMALL_ICON // Text right to the icon, position does not mind
155 WB_DETAILS // Text right to the icon, limited positioning
157 WB_NOHIDESELECTION // Draw selection inactively, if not focused.
161 WB_SMART_ARRANGE // Keep Visible-Area at arrange
162 WB_ALIGN_TOP // Align line vy line LTR
163 WB_ALIGN_LEFT // Align columns from top to bottom
164 WB_NODRAGSELECTION // No selection with tracking rectangle
165 WB_NOCOLUMNHEADER // No Headerbar in Details view (Headerbar not implemented)
166 WB_NOPOINTERFOCUS // No GrabFocus at MouseButtonDown
167 WB_HIGHLIGHTFRAME // The entry beneath the mouse will be highlighted
168 WB_NOASYNCSELECTHDL // Do not collect events -> Selection handlers will be called synchronously
171 #define WB_ICON WB_RECTSTYLE
172 #define WB_SMALLICON WB_SMALLSTYLE
173 #define WB_DETAILS WB_VCENTER
174 #define WB_NOHSCROLL WB_SPIN
175 #define WB_NOVSCROLL WB_DRAG
176 #define WB_NOSELECTION WB_REPEAT
177 #define WB_NODRAGSELECTION WB_PATHELLIPSIS
178 #define WB_SMART_ARRANGE WB_PASSWORD
179 #define WB_ALIGN_TOP WB_TOP
180 #define WB_ALIGN_LEFT WB_LEFT
181 #define WB_NOCOLUMNHEADER WB_CENTER
182 #define WB_HIGHLIGHTFRAME WB_IGNORETAB
183 #define WB_NOASYNCSELECTHDL WB_NOLABEL
185 class MnemonicGenerator
;
187 class SVT_DLLPUBLIC SvtIconChoiceCtrl
: public Control
189 friend class SvxIconChoiceCtrl_Impl
;
191 Link
<SvtIconChoiceCtrl
*,void> _aClickIconHdl
;
192 KeyEvent
* _pCurKeyEvent
;
193 std::unique_ptr
<SvxIconChoiceCtrl_Impl
> _pImpl
;
197 virtual void KeyInput( const KeyEvent
& rKEvt
) override
;
198 virtual void Command( const CommandEvent
& rCEvt
) override
;
199 virtual void Paint( vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
) override
;
200 virtual void MouseButtonDown( const MouseEvent
& rMEvt
) override
;
201 virtual void MouseButtonUp( const MouseEvent
& rMEvt
) override
;
202 virtual void MouseMove( const MouseEvent
& rMEvt
) override
;
203 virtual void Resize() override
;
204 virtual void GetFocus() override
;
205 virtual void LoseFocus() override
;
207 virtual void DataChanged( const DataChangedEvent
& rDCEvt
) override
;
208 virtual void RequestHelp( const HelpEvent
& rHEvt
) override
;
209 static void DrawEntryImage(
210 SvxIconChoiceCtrlEntry
* pEntry
,
212 OutputDevice
& rDev
);
214 static OUString
GetEntryText( SvxIconChoiceCtrlEntry
* pEntry
);
216 virtual void FillLayoutData() const override
;
218 void CallImplEventListeners(VclEventId nEvent
, void* pData
);
222 SvtIconChoiceCtrl( vcl::Window
* pParent
, WinBits nWinStyle
);
223 virtual ~SvtIconChoiceCtrl() override
;
224 virtual void dispose() override
;
226 void SetStyle( WinBits nWinStyle
);
227 WinBits
GetStyle() const;
229 void SetChoiceWithCursor();
231 void SetFont( const vcl::Font
& rFont
);
232 void SetPointFont( const vcl::Font
& rFont
);
234 void SetClickHdl( const Link
<SvtIconChoiceCtrl
*,void>& rLink
) { _aClickIconHdl
= rLink
; }
235 const Link
<SvtIconChoiceCtrl
*,void>& GetClickHdl() const { return _aClickIconHdl
; }
237 using OutputDevice::SetBackground
;
238 void SetBackground( const Wallpaper
& rWallpaper
);
243 SvxIconChoiceCtrlEntry
* InsertEntry( const OUString
& rText
,
244 const Image
& rImage
);
246 /** creates automatic mnemonics for all icon texts in the control
248 @param _rUsedMnemonics
249 a MnemonicGenerator at which some other mnemonics are already registered.
250 This can be used if the control needs to share the "mnemonic space" with other elements,
253 void CreateAutoMnemonics( MnemonicGenerator
& _rUsedMnemonics
);
255 bool DoKeyInput( const KeyEvent
& rKEvt
);
257 sal_Int32
GetEntryCount() const;
258 SvxIconChoiceCtrlEntry
* GetEntry( sal_Int32 nPos
) const;
259 sal_Int32
GetEntryListPos( SvxIconChoiceCtrlEntry
* pEntry
) const;
260 using Window::SetCursor
;
261 void SetCursor( SvxIconChoiceCtrlEntry
* pEntry
);
262 SvxIconChoiceCtrlEntry
* GetCursor() const;
264 // Re-calculation of cached view-data and invalidation of those in the view
265 void InvalidateEntry( SvxIconChoiceCtrlEntry
* pEntry
);
267 // Entry is selectd, if the BoundRect is selected
268 SvxIconChoiceCtrlEntry
* GetEntry( const Point
& rPosPixel
) const;
270 // sal_uLong is the position of the selected element in the list
271 SvxIconChoiceCtrlEntry
* GetSelectedEntry() const;
274 void SetEntryTextMode( SvxIconChoiceCtrlTextMode eMode
, SvxIconChoiceCtrlEntry
* pEntry
);
277 Point
GetPixelPos( const Point
& rPosLogic
) const;
278 void SetSelectionMode( SelectionMode eMode
);
280 tools::Rectangle
GetBoundingBox( SvxIconChoiceCtrlEntry
* pEntry
) const;
281 tools::Rectangle
GetEntryCharacterBounds( const sal_Int32 _nEntryPos
, const sal_Int32 _nCharacterIndex
) const;
283 void SetNoSelection();
285 // ACCESSIBILITY ==========================================================
287 /** Creates and returns the accessible object of the Box. */
288 virtual css::uno::Reference
< css::accessibility::XAccessible
> CreateAccessible() override
;
291 #endif // INCLUDED_SVTOOLS_IVCTRL_HXX
293 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */