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 <vcl/ivctrl.hxx>
24 #include <vcl/virdev.hxx>
25 #include <vcl/scrbar.hxx>
26 #include <vcl/timer.hxx>
27 #include <vcl/idle.hxx>
28 #include <vcl/vclptr.hxx>
29 #include <tools/debug.hxx>
30 #include <vcl/svtaccessiblefactory.hxx>
39 class SvtIconChoiceCtrl
;
40 class SvxIconChoiceCtrlEntry
;
41 class IcnViewEdit_Impl
;
42 class IcnGridMap_Impl
;
47 #define PAINTFLAG_HOR_CENTERED 0x0001
48 #define PAINTFLAG_VER_CENTERED 0x0002
50 enum class IconChoiceFlags
{
53 SelectingRect
= 0x0002,
55 DownDeselect
= 0x0008,
56 EntryListPosValid
= 0x0010,
57 ClearingSelection
= 0x0020,
61 template<> struct typed_flags
<IconChoiceFlags
> : is_typed_flags
<IconChoiceFlags
, 0x007f> {};
65 // distances from window borders
66 #define LROFFS_WINBORDER 4
67 #define TBOFFS_WINBORDER 4
68 // for the bounding rectangle
69 #define LROFFS_BOUND 2
70 #define TBOFFS_BOUND 2
71 // distance icon to text
72 #define HOR_DIST_BMP_STRING 3
73 #define VER_DIST_BMP_STRING 3
74 // width offset of highlight rectangle for Text
77 #define DEFAULT_MAX_VIRT_WIDTH 200
78 #define DEFAULT_MAX_VIRT_HEIGHT 200
80 #define VIEWMODE_MASK (WB_ICON | WB_SMALLICON | WB_DETAILS)
83 enum class IcnViewFieldType
90 // Data about the focus of entries
94 tools::Rectangle aRect
;
99 // Implementation-class of IconChoiceCtrl
102 typedef std::map
<sal_uInt16
, std::unique_ptr
<SvxIconChoiceCtrlColumnInfo
>> SvxIconChoiceCtrlColumnInfoMap
;
103 typedef std::vector
<SvxIconChoiceCtrlEntry
*> SvxIconChoiceCtrlEntryPtrVec
;
105 class SvxIconChoiceCtrl_Impl
107 friend class IcnCursor_Impl
;
108 friend class IcnGridMap_Impl
;
110 bool bChooseWithCursor
;
111 std::vector
< std::unique_ptr
<SvxIconChoiceCtrlEntry
> > maEntries
;
112 VclPtr
<ScrollBar
> aVerSBar
;
113 VclPtr
<ScrollBar
> aHorSBar
;
114 VclPtr
<ScrollBarBox
> aScrBarBox
;
115 tools::Rectangle aCurSelectionRect
;
116 std::vector
<tools::Rectangle
> aSelectedRectList
;
117 Idle aAutoArrangeIdle
;
118 Idle aDocRectChangedIdle
;
119 Idle aVisRectChangedIdle
;
120 Idle aCallSelectHdlIdle
;
121 Size aVirtOutputSize
;
122 Size
const aImageSize
;
123 Size aDefaultTextSize
;
124 Size aOutputSize
; // Pixel
125 VclPtr
<SvtIconChoiceCtrl
> pView
;
126 std::unique_ptr
<IcnCursor_Impl
> pImpCursor
;
127 std::unique_ptr
<IcnGridMap_Impl
> pGridMap
;
128 long nMaxVirtWidth
; // max. width aVirtOutputSize for ALIGN_TOP
129 long nMaxVirtHeight
; // max. height aVirtOutputSize for ALIGN_LEFT
130 std::vector
< SvxIconChoiceCtrlEntry
* > maZOrderList
;
131 std::unique_ptr
<SvxIconChoiceCtrlColumnInfoMap
> m_pColumns
;
133 long nMaxBoundHeight
; // height of highest BoundRects
134 IconChoiceFlags nFlags
;
135 DrawTextFlags nCurTextDrawFlags
;
136 ImplSVEvent
* nUserEventAdjustScrBars
;
137 SvxIconChoiceCtrlEntry
* pCurHighlightFrame
;
138 bool bHighlightFramePressed
;
139 SvxIconChoiceCtrlEntry
* pHead
= nullptr; // top left entry
140 SvxIconChoiceCtrlEntry
* pCursor
;
141 SvxIconChoiceCtrlEntry
* pHdlEntry
;
142 VclPtr
<VirtualDevice
> pDDDev
;
143 VclPtr
<VirtualDevice
> pDDBufDev
;
144 VclPtr
<VirtualDevice
> pDDTempDev
;
145 VclPtr
<VirtualDevice
> pEntryPaintDev
;
146 SvxIconChoiceCtrlEntry
* pAnchor
; // for selection
147 LocalFocus aFocus
; // Data for focusrect
148 ::vcl::AccessibleFactoryAccess aAccFactory
;
150 SvxIconChoiceCtrlTextMode eTextMode
;
151 SelectionMode eSelectionMode
;
152 sal_Int32 nSelectionCount
;
153 SvxIconChoiceCtrlPositionMode ePositionMode
;
154 bool bBoundRectsDirty
;
157 void ShowCursor( bool bShow
);
159 void ImpArrange( bool bKeepPredecessors
);
160 void AdjustVirtSize( const tools::Rectangle
& );
161 void ResetVirtSize();
162 void CheckScrollBars();
164 DECL_LINK( ScrollUpDownHdl
, ScrollBar
*, void );
165 DECL_LINK( ScrollLeftRightHdl
, ScrollBar
*, void );
166 DECL_LINK( UserEventHdl
, void*, void );
167 DECL_LINK( AutoArrangeHdl
, Timer
*, void );
168 DECL_LINK( DocRectChangedHdl
, Timer
*, void );
169 DECL_LINK( VisRectChangedHdl
, Timer
*, void );
170 DECL_LINK( CallSelectHdlHdl
, Timer
*, void );
172 void AdjustScrollBars();
173 void PositionScrollBars( long nRealWidth
, long nRealHeight
);
174 static long GetScrollBarPageSize( long nVisibleRange
)
176 return ((nVisibleRange
*75)/100);
178 long GetScrollBarLineSize() const
180 return nMaxBoundHeight
/ 2;
182 bool HandleScrollCommand( const CommandEvent
& rCmd
);
183 void ToDocPos( Point
& rPosPixel
)
185 rPosPixel
-= pView
->GetMapMode().GetOrigin();
187 void InitScrollBarBox();
188 void ToggleSelection( SvxIconChoiceCtrlEntry
* );
189 void DeselectAllBut( SvxIconChoiceCtrlEntry
const * );
190 void Center( SvxIconChoiceCtrlEntry
* pEntry
) const;
191 void CallSelectHandler();
193 SvxIconChoiceCtrlEntry
* pEntry1
,
194 SvxIconChoiceCtrlEntry
* pEntry2
,
196 std::vector
<tools::Rectangle
>* pOtherRects
200 SvxIconChoiceCtrlEntry
const * pStart
,
201 SvxIconChoiceCtrlEntry
const * pEnd
,
205 void AddSelectedRect( const tools::Rectangle
& );
206 void AddSelectedRect(
207 SvxIconChoiceCtrlEntry
* pEntry1
,
208 SvxIconChoiceCtrlEntry
* pEntry2
211 void ClearSelectedRectList();
212 void ClearColumnList();
213 tools::Rectangle
CalcMaxTextRect( const SvxIconChoiceCtrlEntry
* pEntry
) const;
215 void ClipAtVirtOutRect( tools::Rectangle
& rRect
) const;
216 sal_uLong
GetPredecessorGrid( const Point
& rDocPos
) const;
218 void InitPredecessors();
219 void ClearPredecessors();
221 bool CheckVerScrollBar();
222 bool CheckHorScrollBar();
223 void CancelUserEvents();
225 SvxIconChoiceCtrlEntry
* pEntry
,
228 void RepaintSelectedEntries();
229 void SetListPositions();
230 void SetDefaultTextSize();
231 bool IsAutoArrange() const
233 return (ePositionMode
== SvxIconChoiceCtrlPositionMode::AutoArrange
);
235 void DocRectChanged() { aDocRectChangedIdle
.Start(); }
236 void VisRectChanged() { aVisRectChangedIdle
.Start(); }
237 void SetOrigin( const Point
& );
239 DECL_LINK(TextEditEndedHdl
, LinkParamNone
*, void);
241 void ShowFocus ( tools::Rectangle
const & rRect
);
242 void DrawFocusRect(vcl::RenderContext
& rRenderContext
);
244 bool IsMnemonicChar( sal_Unicode cChar
, sal_uLong
& rPos
) const;
246 // Copy assignment is forbidden and not implemented.
247 SvxIconChoiceCtrl_Impl (const SvxIconChoiceCtrl_Impl
&) = delete;
248 SvxIconChoiceCtrl_Impl
& operator= (const SvxIconChoiceCtrl_Impl
&) = delete;
257 SvxIconChoiceCtrl_Impl( SvtIconChoiceCtrl
* pView
, WinBits nWinStyle
);
258 ~SvxIconChoiceCtrl_Impl();
260 void SetChoiceWithCursor() { bChooseWithCursor
= true; }
261 void Clear( bool bInCtor
);
262 void SetStyle( WinBits nWinStyle
);
263 WinBits
GetStyle() const { return nWinBits
; }
264 void InsertEntry( std::unique_ptr
<SvxIconChoiceCtrlEntry
>, size_t nPos
);
265 void RemoveEntry( size_t nPos
);
266 void CreateAutoMnemonics( MnemonicGenerator
* _pGenerator
);
270 SvxIconChoiceCtrlEntry
*,
272 bool bAddToSelection
= false
274 void Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
);
275 bool MouseButtonDown( const MouseEvent
& );
276 bool MouseButtonUp( const MouseEvent
& );
277 bool MouseMove( const MouseEvent
&);
278 bool RequestHelp( const HelpEvent
& rHEvt
);
280 SvxIconChoiceCtrlEntry
* pOldCursor
,
281 SvxIconChoiceCtrlEntry
* pNewCursor
,
285 bool KeyInput( const KeyEvent
& );
289 void SetUpdateMode( bool bUpdate
);
290 bool GetUpdateMode() const { return bUpdateMode
; }
291 void PaintEntry(SvxIconChoiceCtrlEntry
*, const Point
&, vcl::RenderContext
& rRenderContext
);
294 SvxIconChoiceCtrlEntry
* pEntry
,
298 void InvalidateEntry( SvxIconChoiceCtrlEntry
* );
300 void SetNoSelection();
302 SvxIconChoiceCtrlEntry
* GetCurEntry() const { return pCursor
; }
303 void SetCursor( SvxIconChoiceCtrlEntry
* );
305 SvxIconChoiceCtrlEntry
* GetEntry( const Point
& rDocPos
, bool bHit
= false );
307 void MakeEntryVisible( SvxIconChoiceCtrlEntry
* pEntry
, bool bBound
= true );
310 bool bKeepPredecessors
,
311 long nSetMaxVirtWidth
,
312 long nSetMaxVirtHeight
315 tools::Rectangle
CalcFocusRect( SvxIconChoiceCtrlEntry
* );
316 tools::Rectangle
CalcBmpRect( SvxIconChoiceCtrlEntry
*, const Point
* pPos
= nullptr );
317 tools::Rectangle
CalcTextRect(
318 SvxIconChoiceCtrlEntry
*,
319 const Point
* pPos
= nullptr,
320 const OUString
* pStr
= nullptr
323 long CalcBoundingWidth() const;
324 long CalcBoundingHeight() const;
325 Size
CalcBoundingSize() const;
326 void FindBoundingRect( SvxIconChoiceCtrlEntry
* pEntry
);
327 void SetBoundingRect_Impl(
328 SvxIconChoiceCtrlEntry
* pEntry
,
330 const Size
& rBoundingSize
332 // recalculates all invalid BoundRects
333 void RecalcAllBoundingRectsSmart();
334 const tools::Rectangle
& GetEntryBoundRect( SvxIconChoiceCtrlEntry
* );
335 void InvalidateBoundingRect( tools::Rectangle
& rRect
)
337 rRect
.SetRight(LONG_MAX
);
338 bBoundRectsDirty
= true;
340 static bool IsBoundingRectValid( const tools::Rectangle
& rRect
) { return ( rRect
.Right() != LONG_MAX
); }
342 static void PaintEmphasis(const tools::Rectangle
& rRect1
, bool bSelected
,
343 vcl::RenderContext
& rRenderContext
);
345 void PaintItem(const tools::Rectangle
& rRect
, IcnViewFieldType eItem
, SvxIconChoiceCtrlEntry
* pEntry
,
346 sal_uInt16 nPaintFlags
, vcl::RenderContext
& rRenderContext
);
348 // recalculates all BoundingRects if bMustRecalcBoundingRects == true
349 void CheckBoundingRects() { if (bBoundRectsDirty
) RecalcAllBoundingRectsSmart(); }
350 void Command( const CommandEvent
& rCEvt
);
351 void ToTop( SvxIconChoiceCtrlEntry
* );
353 sal_Int32
GetSelectionCount() const;
354 void SetGrid( const Size
& );
355 Size
GetMinGrid() const;
356 void Scroll( long nDeltaX
, long nDeltaY
);
357 const Size
& GetItemSize( IcnViewFieldType
) const;
362 std::vector
<tools::Rectangle
>* pSelectedRectList
,
363 const tools::Rectangle
& rEntryBoundRect
367 const tools::Rectangle
&,
369 std::vector
<tools::Rectangle
>* pOtherRects
373 const tools::Rectangle
& rDocPos
,
374 bool bInScrollBarEvent
=false
378 void SetEntryTextMode(
379 SvxIconChoiceCtrlTextMode
,
380 SvxIconChoiceCtrlEntry
* pEntry
383 size_t GetEntryCount() const { return maEntries
.size(); }
384 SvxIconChoiceCtrlEntry
* GetEntry( size_t nPos
)
386 return maEntries
[ nPos
].get();
388 SvxIconChoiceCtrlEntry
* GetEntry( size_t nPos
) const
390 return maEntries
[ nPos
].get();
392 SvxIconChoiceCtrlEntry
* GetFirstSelectedEntry() const;
393 void SetSelectionMode( SelectionMode eMode
) { eSelectionMode
=eMode
; }
394 sal_Int32
GetEntryListPos( SvxIconChoiceCtrlEntry
const * ) const;
396 tools::Rectangle
GetOutputRect() const;
398 void SetEntryPredecessor(SvxIconChoiceCtrlEntry
* pEntry
,SvxIconChoiceCtrlEntry
* pPredecessor
);
399 // only delivers valid results when in AutoArrange mode!
400 SvxIconChoiceCtrlEntry
* FindEntryPredecessor( SvxIconChoiceCtrlEntry
* pEntry
, const Point
& );
402 void SetPositionMode( SvxIconChoiceCtrlPositionMode
);
404 void SetColumn( sal_uInt16 nIndex
, const SvxIconChoiceCtrlColumnInfo
& );
405 const SvxIconChoiceCtrlColumnInfo
* GetColumn( sal_uInt16 nIndex
) const;
407 void SetEntryHighlightFrame(
408 SvxIconChoiceCtrlEntry
* pEntry
,
409 bool bKeepHighlightFlags
411 void DrawHighlightFrame(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rBmpRect
);
413 void CallEventListeners( VclEventId nEvent
, void* pData
);
415 ::vcl::IAccessibleFactory
& GetAccessibleFactory()
417 return aAccFactory
.getFactory();
421 typedef std::map
<sal_uInt16
, SvxIconChoiceCtrlEntryPtrVec
> IconChoiceMap
;
425 SvxIconChoiceCtrl_Impl
* pView
;
426 std::unique_ptr
<IconChoiceMap
> xColumns
;
427 std::unique_ptr
<IconChoiceMap
> xRows
;
432 SvxIconChoiceCtrlEntry
* pCurEntry
;
435 void Create() { if( !xColumns
) ImplCreate(); }
437 sal_uInt16
GetSortListPos(
438 SvxIconChoiceCtrlEntryPtrVec
& rList
,
441 SvxIconChoiceCtrlEntry
* SearchCol(
449 SvxIconChoiceCtrlEntry
* SearchRow(
458 explicit IcnCursor_Impl( SvxIconChoiceCtrl_Impl
* pOwner
);
462 // for Cursortravelling etc.
463 SvxIconChoiceCtrlEntry
* GoLeftRight( SvxIconChoiceCtrlEntry
*, bool bRight
);
464 SvxIconChoiceCtrlEntry
* GoUpDown( SvxIconChoiceCtrlEntry
*, bool bDown
);
465 SvxIconChoiceCtrlEntry
* GoPageUpDown( SvxIconChoiceCtrlEntry
*, bool bDown
);
469 typedef sal_uLong GridId
;
471 #define GRID_NOT_FOUND ((GridId)ULONG_MAX)
473 class IcnGridMap_Impl
475 tools::Rectangle _aLastOccupiedGrid
;
476 SvxIconChoiceCtrl_Impl
* _pView
;
477 std::unique_ptr
<bool[]> _pGridMap
;
478 sal_uInt16 _nGridCols
, _nGridRows
;
482 void Create() { if(!_pGridMap
) Create_Impl(); }
484 void GetMinMapSize( sal_uInt16
& rDX
, sal_uInt16
& rDY
) const;
487 explicit IcnGridMap_Impl(SvxIconChoiceCtrl_Impl
* pView
);
492 GridId
GetGrid( const Point
& rDocPos
);
493 GridId
GetGrid( sal_uInt16 nGridX
, sal_uInt16 nGridY
);
494 GridId
GetUnoccupiedGrid();
496 void OccupyGrids( const SvxIconChoiceCtrlEntry
* );
497 void OccupyGrid( GridId nId
)
499 DBG_ASSERT(!_pGridMap
|| nId
<static_cast<sal_uLong
>(_nGridCols
*_nGridRows
),"OccupyGrid: Bad GridId");
500 if(_pGridMap
&& nId
< static_cast<sal_uLong
>(_nGridCols
*_nGridRows
) )
501 _pGridMap
[ nId
] = true;
504 tools::Rectangle
GetGridRect( GridId
);
505 void GetGridCoord( GridId
, sal_uInt16
& rGridX
, sal_uInt16
& rGridY
);
506 static sal_uLong
GetGridCount(
507 const Size
& rSizePixel
,
508 sal_uInt16 nGridWidth
,
509 sal_uInt16 nGridHeight
512 void OutputSizeChanged();
517 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */