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_SOURCE_CONTNR_IMIVCTL_HXX
21 #define INCLUDED_SVTOOLS_SOURCE_CONTNR_IMIVCTL_HXX
23 #include <sal/config.h>
25 #include <o3tl/safeint.hxx>
26 #include <vcl/toolkit/ivctrl.hxx>
27 #include <vcl/virdev.hxx>
28 #include <vcl/scrbar.hxx>
29 #include <vcl/timer.hxx>
30 #include <vcl/idle.hxx>
31 #include <vcl/vclptr.hxx>
32 #include <tools/debug.hxx>
33 #include <vcl/svtaccessiblefactory.hxx>
42 class SvtIconChoiceCtrl
;
43 class SvxIconChoiceCtrlEntry
;
44 class IcnViewEdit_Impl
;
45 class IcnGridMap_Impl
;
50 #define PAINTFLAG_HOR_CENTERED 0x0001
51 #define PAINTFLAG_VER_CENTERED 0x0002
53 enum class IconChoiceFlags
{
56 SelectingRect
= 0x0002,
58 DownDeselect
= 0x0008,
59 EntryListPosValid
= 0x0010,
60 ClearingSelection
= 0x0020,
64 template<> struct typed_flags
<IconChoiceFlags
> : is_typed_flags
<IconChoiceFlags
, 0x007f> {};
68 // distances from window borders
69 #define LROFFS_WINBORDER 4
70 #define TBOFFS_WINBORDER 4
71 // for the bounding rectangle
72 #define LROFFS_BOUND 2
73 #define TBOFFS_BOUND 2
74 // distance icon to text
75 #define HOR_DIST_BMP_STRING 3
76 #define VER_DIST_BMP_STRING 3
77 // width offset of highlight rectangle for Text
80 #define DEFAULT_MAX_VIRT_WIDTH 200
81 #define DEFAULT_MAX_VIRT_HEIGHT 200
83 #define VIEWMODE_MASK (WB_ICON | WB_SMALLICON | WB_DETAILS)
86 enum class IcnViewFieldType
93 // Data about the focus of entries
97 tools::Rectangle aRect
;
102 typedef sal_uLong GridId
;
104 #define GRID_NOT_FOUND (GridId(ULONG_MAX))
106 // Implementation-class of IconChoiceCtrl
109 typedef std::map
<sal_uInt16
, std::unique_ptr
<SvxIconChoiceCtrlColumnInfo
>> SvxIconChoiceCtrlColumnInfoMap
;
110 typedef std::vector
<SvxIconChoiceCtrlEntry
*> SvxIconChoiceCtrlEntryPtrVec
;
112 class SvxIconChoiceCtrl_Impl
114 friend class IcnCursor_Impl
;
115 friend class IcnGridMap_Impl
;
117 std::vector
< std::unique_ptr
<SvxIconChoiceCtrlEntry
> > maEntries
;
118 VclPtr
<ScrollBar
> aVerSBar
;
119 VclPtr
<ScrollBar
> aHorSBar
;
120 VclPtr
<ScrollBarBox
> aScrBarBox
;
121 tools::Rectangle aCurSelectionRect
;
122 std::vector
<tools::Rectangle
> aSelectedRectList
;
123 Idle aAutoArrangeIdle
;
124 Idle aDocRectChangedIdle
;
125 Idle aVisRectChangedIdle
;
126 Idle aCallSelectHdlIdle
;
127 Size aVirtOutputSize
;
129 Size aDefaultTextSize
;
130 Size aOutputSize
; // Pixel
131 VclPtr
<SvtIconChoiceCtrl
> pView
;
132 std::unique_ptr
<IcnCursor_Impl
> pImpCursor
;
133 std::unique_ptr
<IcnGridMap_Impl
> pGridMap
;
134 tools::Long nMaxVirtWidth
; // max. width aVirtOutputSize for ALIGN_TOP
135 tools::Long nMaxVirtHeight
; // max. height aVirtOutputSize for ALIGN_LEFT
136 std::vector
< SvxIconChoiceCtrlEntry
* > maZOrderList
;
137 std::unique_ptr
<SvxIconChoiceCtrlColumnInfoMap
> m_pColumns
;
139 tools::Long nMaxBoundHeight
; // height of highest BoundRects
140 IconChoiceFlags nFlags
;
141 DrawTextFlags nCurTextDrawFlags
;
142 ImplSVEvent
* nUserEventAdjustScrBars
;
143 SvxIconChoiceCtrlEntry
* pCurHighlightFrame
;
144 bool bHighlightFramePressed
;
145 SvxIconChoiceCtrlEntry
* pHead
= nullptr; // top left entry
146 SvxIconChoiceCtrlEntry
* pCursor
;
147 SvxIconChoiceCtrlEntry
* pHdlEntry
;
148 SvxIconChoiceCtrlEntry
* pAnchor
; // for selection
149 LocalFocus aFocus
; // Data for focusrect
150 ::vcl::AccessibleFactoryAccess aAccFactory
;
152 SvxIconChoiceCtrlTextMode eTextMode
;
153 SelectionMode eSelectionMode
;
154 sal_Int32 nSelectionCount
;
155 SvxIconChoiceCtrlPositionMode ePositionMode
;
156 bool bBoundRectsDirty
;
159 void ShowCursor( bool bShow
);
161 void ImpArrange( bool bKeepPredecessors
);
162 void AdjustVirtSize( const tools::Rectangle
& );
163 void ResetVirtSize();
164 void CheckScrollBars();
166 DECL_LINK( ScrollUpDownHdl
, ScrollBar
*, void );
167 DECL_LINK( ScrollLeftRightHdl
, ScrollBar
*, void );
168 DECL_LINK( UserEventHdl
, void*, void );
169 DECL_LINK( AutoArrangeHdl
, Timer
*, void );
170 DECL_LINK( DocRectChangedHdl
, Timer
*, void );
171 DECL_LINK( VisRectChangedHdl
, Timer
*, void );
172 DECL_LINK( CallSelectHdlHdl
, Timer
*, void );
174 void AdjustScrollBars();
175 void PositionScrollBars( tools::Long nRealWidth
, tools::Long nRealHeight
);
176 static tools::Long
GetScrollBarPageSize( tools::Long nVisibleRange
)
178 return ((nVisibleRange
*75)/100);
180 tools::Long
GetScrollBarLineSize() const
182 return nMaxBoundHeight
/ 2;
184 bool HandleScrollCommand( const CommandEvent
& rCmd
);
185 void ToDocPos( Point
& rPosPixel
)
187 rPosPixel
-= pView
->GetMapMode().GetOrigin();
189 void InitScrollBarBox();
190 void ToggleSelection( SvxIconChoiceCtrlEntry
* );
191 void DeselectAllBut( SvxIconChoiceCtrlEntry
const * );
192 void Center( SvxIconChoiceCtrlEntry
* pEntry
) const;
193 void CallSelectHandler();
195 SvxIconChoiceCtrlEntry
* pEntry1
,
196 SvxIconChoiceCtrlEntry
* pEntry2
,
198 std::vector
<tools::Rectangle
>* pOtherRects
202 SvxIconChoiceCtrlEntry
const * pStart
,
203 SvxIconChoiceCtrlEntry
const * pEnd
,
207 void AddSelectedRect( const tools::Rectangle
& );
208 void AddSelectedRect(
209 SvxIconChoiceCtrlEntry
* pEntry1
,
210 SvxIconChoiceCtrlEntry
* pEntry2
213 void ClearSelectedRectList();
214 tools::Rectangle
CalcMaxTextRect( const SvxIconChoiceCtrlEntry
* pEntry
) const;
216 void ClipAtVirtOutRect( tools::Rectangle
& rRect
) const;
217 GridId
GetPredecessorGrid( const Point
& rDocPos
) const;
219 void InitPredecessors();
220 void ClearPredecessors();
222 bool CheckVerScrollBar();
223 bool CheckHorScrollBar();
224 void CancelUserEvents();
226 SvxIconChoiceCtrlEntry
* pEntry
,
229 void RepaintSelectedEntries();
230 void SetListPositions();
231 void SetDefaultTextSize();
232 bool IsAutoArrange() const
234 return (ePositionMode
== SvxIconChoiceCtrlPositionMode::AutoArrange
);
236 void DocRectChanged() { aDocRectChangedIdle
.Start(); }
237 void VisRectChanged() { aVisRectChangedIdle
.Start(); }
238 void SetOrigin( const Point
& );
240 void ShowFocus ( tools::Rectangle
const & rRect
);
241 void DrawFocusRect(vcl::RenderContext
& rRenderContext
);
243 bool IsMnemonicChar( sal_Unicode cChar
, sal_uLong
& rPos
) const;
245 // Copy assignment is forbidden and not implemented.
246 SvxIconChoiceCtrl_Impl (const SvxIconChoiceCtrl_Impl
&) = delete;
247 SvxIconChoiceCtrl_Impl
& operator= (const SvxIconChoiceCtrl_Impl
&) = delete;
253 tools::Long nHorSBarHeight
;
254 tools::Long nVerSBarWidth
;
256 SvxIconChoiceCtrl_Impl( SvtIconChoiceCtrl
* pView
, WinBits nWinStyle
);
257 ~SvxIconChoiceCtrl_Impl();
259 void SetSelectionMode(SelectionMode eMode
)
261 eSelectionMode
= eMode
;
264 void Clear( bool bInCtor
);
265 void SetStyle( WinBits nWinStyle
);
266 WinBits
GetStyle() const { return nWinBits
; }
267 void InsertEntry( std::unique_ptr
<SvxIconChoiceCtrlEntry
>, size_t nPos
);
268 void RemoveEntry( size_t nPos
);
272 SvxIconChoiceCtrlEntry
*,
274 bool bAddToSelection
= false
276 void Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
);
277 bool MouseButtonDown( const MouseEvent
& );
278 bool MouseButtonUp( const MouseEvent
& );
279 bool MouseMove( const MouseEvent
&);
280 bool RequestHelp( const HelpEvent
& rHEvt
);
282 SvxIconChoiceCtrlEntry
* pOldCursor
,
283 SvxIconChoiceCtrlEntry
* pNewCursor
,
287 bool KeyInput( const KeyEvent
& );
291 void SetUpdateMode( bool bUpdate
);
292 bool GetUpdateMode() const { return bUpdateMode
; }
293 void PaintEntry(SvxIconChoiceCtrlEntry
*, const Point
&, vcl::RenderContext
& rRenderContext
);
296 SvxIconChoiceCtrlEntry
* pEntry
,
300 void InvalidateEntry( SvxIconChoiceCtrlEntry
* );
302 void SetNoSelection();
304 SvxIconChoiceCtrlEntry
* GetCurEntry() const { return pCursor
; }
305 void SetCursor( SvxIconChoiceCtrlEntry
* );
307 SvxIconChoiceCtrlEntry
* GetEntry( const Point
& rDocPos
, bool bHit
= false );
309 void MakeEntryVisible( SvxIconChoiceCtrlEntry
* pEntry
, bool bBound
= true );
312 bool bKeepPredecessors
,
313 tools::Long nSetMaxVirtWidth
,
314 tools::Long nSetMaxVirtHeight
317 tools::Rectangle
CalcFocusRect( SvxIconChoiceCtrlEntry
* );
318 tools::Rectangle
CalcBmpRect( SvxIconChoiceCtrlEntry
*, const Point
* pPos
= nullptr );
319 tools::Rectangle
CalcTextRect(
320 SvxIconChoiceCtrlEntry
*,
321 const Point
* pPos
= nullptr,
322 const OUString
* pStr
= nullptr
325 tools::Long
CalcBoundingWidth() const;
326 tools::Long
CalcBoundingHeight() const;
327 Size
CalcBoundingSize() const;
328 void FindBoundingRect( SvxIconChoiceCtrlEntry
* pEntry
);
329 void SetBoundingRect_Impl(
330 SvxIconChoiceCtrlEntry
* pEntry
,
332 const Size
& rBoundingSize
334 // recalculates all invalid BoundRects
335 void RecalcAllBoundingRectsSmart();
336 const tools::Rectangle
& GetEntryBoundRect( SvxIconChoiceCtrlEntry
* );
337 void InvalidateBoundingRect( tools::Rectangle
& rRect
)
339 rRect
.SetRight(LONG_MAX
);
340 bBoundRectsDirty
= true;
342 static bool IsBoundingRectValid( const tools::Rectangle
& rRect
) { return ( rRect
.Right() != LONG_MAX
); }
344 static void PaintEmphasis(const tools::Rectangle
& rRect1
, bool bSelected
,
345 vcl::RenderContext
& rRenderContext
);
347 void PaintItem(const tools::Rectangle
& rRect
, IcnViewFieldType eItem
, SvxIconChoiceCtrlEntry
* pEntry
,
348 sal_uInt16 nPaintFlags
, vcl::RenderContext
& rRenderContext
);
350 // recalculates all BoundingRects if bMustRecalcBoundingRects == true
351 void CheckBoundingRects() { if (bBoundRectsDirty
) RecalcAllBoundingRectsSmart(); }
352 void Command( const CommandEvent
& rCEvt
);
353 void ToTop( SvxIconChoiceCtrlEntry
* );
355 sal_Int32
GetSelectionCount() const;
356 void SetGrid( const Size
& );
357 Size
GetMinGrid() const;
358 void Scroll( tools::Long nDeltaX
, tools::Long nDeltaY
);
359 const Size
& GetItemSize( IcnViewFieldType
) const;
364 std::vector
<tools::Rectangle
>* pSelectedRectList
,
365 const tools::Rectangle
& rEntryBoundRect
369 const tools::Rectangle
&,
371 std::vector
<tools::Rectangle
>* pOtherRects
375 const tools::Rectangle
& rDocPos
,
376 bool bInScrollBarEvent
=false
380 void SetEntryTextMode(
381 SvxIconChoiceCtrlTextMode
,
382 SvxIconChoiceCtrlEntry
* pEntry
385 size_t GetEntryCount() const { return maEntries
.size(); }
386 SvxIconChoiceCtrlEntry
* GetEntry( size_t nPos
)
388 return maEntries
[ nPos
].get();
390 SvxIconChoiceCtrlEntry
* GetEntry( size_t nPos
) const
392 return maEntries
[ nPos
].get();
394 SvxIconChoiceCtrlEntry
* GetFirstSelectedEntry() const;
395 sal_Int32
GetEntryListPos( SvxIconChoiceCtrlEntry
const * ) const;
397 tools::Rectangle
GetOutputRect() const;
399 void SetEntryPredecessor(SvxIconChoiceCtrlEntry
* pEntry
,SvxIconChoiceCtrlEntry
* pPredecessor
);
400 // only delivers valid results when in AutoArrange mode!
401 SvxIconChoiceCtrlEntry
* FindEntryPredecessor( SvxIconChoiceCtrlEntry
* pEntry
, const Point
& );
403 void SetPositionMode( SvxIconChoiceCtrlPositionMode
);
405 void SetColumn( sal_uInt16 nIndex
, const SvxIconChoiceCtrlColumnInfo
& );
406 const SvxIconChoiceCtrlColumnInfo
* GetColumn( sal_uInt16 nIndex
) const;
408 void SetEntryHighlightFrame(
409 SvxIconChoiceCtrlEntry
* pEntry
,
410 bool bKeepHighlightFlags
412 void DrawHighlightFrame(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rBmpRect
);
414 void CallEventListeners( VclEventId nEvent
, void* pData
);
416 ::vcl::IAccessibleFactory
& GetAccessibleFactory()
418 return aAccFactory
.getFactory();
422 typedef std::map
<sal_uInt16
, SvxIconChoiceCtrlEntryPtrVec
> IconChoiceMap
;
426 SvxIconChoiceCtrl_Impl
* pView
;
427 std::unique_ptr
<IconChoiceMap
> xColumns
;
428 std::unique_ptr
<IconChoiceMap
> xRows
;
433 SvxIconChoiceCtrlEntry
* pCurEntry
;
436 void Create() { if( !xColumns
) ImplCreate(); }
438 sal_uInt16
GetSortListPos(
439 SvxIconChoiceCtrlEntryPtrVec
& rList
,
442 SvxIconChoiceCtrlEntry
* SearchCol(
450 SvxIconChoiceCtrlEntry
* SearchRow(
459 explicit IcnCursor_Impl( SvxIconChoiceCtrl_Impl
* pOwner
);
463 // for Cursortravelling etc.
464 SvxIconChoiceCtrlEntry
* GoLeftRight( SvxIconChoiceCtrlEntry
*, bool bRight
);
465 SvxIconChoiceCtrlEntry
* GoUpDown( SvxIconChoiceCtrlEntry
*, bool bDown
);
466 SvxIconChoiceCtrlEntry
* GoPageUpDown( SvxIconChoiceCtrlEntry
*, bool bDown
);
469 class IcnGridMap_Impl
471 tools::Rectangle _aLastOccupiedGrid
;
472 SvxIconChoiceCtrl_Impl
* _pView
;
473 std::unique_ptr
<bool[]> _pGridMap
;
474 sal_uInt16 _nGridCols
, _nGridRows
;
478 void Create() { if(!_pGridMap
) Create_Impl(); }
480 void GetMinMapSize( sal_uInt16
& rDX
, sal_uInt16
& rDY
) const;
483 explicit IcnGridMap_Impl(SvxIconChoiceCtrl_Impl
* pView
);
488 GridId
GetGrid( const Point
& rDocPos
);
489 GridId
GetGrid( sal_uInt16 nGridX
, sal_uInt16 nGridY
);
490 GridId
GetUnoccupiedGrid();
492 void OccupyGrids( const SvxIconChoiceCtrlEntry
* );
493 void OccupyGrid( GridId nId
)
495 DBG_ASSERT(!_pGridMap
|| nId
<o3tl::make_unsigned(_nGridCols
*_nGridRows
),"OccupyGrid: Bad GridId");
496 if(_pGridMap
&& nId
< o3tl::make_unsigned(_nGridCols
*_nGridRows
) )
497 _pGridMap
[ nId
] = true;
500 tools::Rectangle
GetGridRect( GridId
);
501 void GetGridCoord( GridId
, sal_uInt16
& rGridX
, sal_uInt16
& rGridY
);
502 static sal_uLong
GetGridCount(
503 const Size
& rSizePixel
,
504 sal_uInt16 nGridWidth
,
505 sal_uInt16 nGridHeight
508 void OutputSizeChanged();
513 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */