bump product version to 7.6.3.2-android
[LibreOffice.git] / vcl / source / control / imivctl.hxx
blob5a052c083efa6c191456b5e03733cb797c198fdd
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 #pragma once
22 #include <sal/config.h>
24 #include <o3tl/safeint.hxx>
25 #include <vcl/virdev.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>
31 #include <vcl/toolkit/ivctrl.hxx>
32 #include <vcl/toolkit/scrbar.hxx>
34 #include <limits.h>
37 #include <memory>
38 #include <map>
40 class IcnCursor_Impl;
41 class SvtIconChoiceCtrl;
42 class SvxIconChoiceCtrlEntry;
43 class IcnViewEdit_Impl;
44 class IcnGridMap_Impl;
47 // some defines
49 #define PAINTFLAG_HOR_CENTERED 0x0001
50 #define PAINTFLAG_VER_CENTERED 0x0002
52 enum class IconChoiceFlags {
53 NONE = 0x0000,
54 AddMode = 0x0001,
55 SelectingRect = 0x0002,
56 DownCtrl = 0x0004,
57 DownDeselect = 0x0008,
58 EntryListPosValid = 0x0010,
59 ClearingSelection = 0x0020,
60 Arranging = 0x0040
62 namespace o3tl {
63 template<> struct typed_flags<IconChoiceFlags> : is_typed_flags<IconChoiceFlags, 0x007f> {};
66 // unit = pixels
67 // distances from window borders
68 #define LROFFS_WINBORDER 4
69 #define TBOFFS_WINBORDER 4
70 // for the bounding rectangle
71 #define LROFFS_BOUND 2
72 #define TBOFFS_BOUND 2
73 // distance icon to text
74 #define HOR_DIST_BMP_STRING 3
75 #define VER_DIST_BMP_STRING 3
76 // width offset of highlight rectangle for Text
77 #define LROFFS_TEXT 2
79 #define DEFAULT_MAX_VIRT_WIDTH 200
80 #define DEFAULT_MAX_VIRT_HEIGHT 200
82 #define VIEWMODE_MASK (WB_ICON | WB_SMALLICON | WB_DETAILS)
85 enum class IcnViewFieldType
87 Image,
88 Text
92 // Data about the focus of entries
94 struct LocalFocus
96 tools::Rectangle aRect;
97 Color aPenColor;
101 typedef sal_uLong GridId;
103 #define GRID_NOT_FOUND (GridId(ULONG_MAX))
105 // Implementation-class of IconChoiceCtrl
108 typedef std::map<sal_uInt16, std::unique_ptr<SvxIconChoiceCtrlColumnInfo>> SvxIconChoiceCtrlColumnInfoMap;
109 typedef std::vector<SvxIconChoiceCtrlEntry*> SvxIconChoiceCtrlEntryPtrVec;
111 class SvxIconChoiceCtrl_Impl
113 friend class IcnCursor_Impl;
114 friend class IcnGridMap_Impl;
116 std::vector< std::unique_ptr<SvxIconChoiceCtrlEntry> > maEntries;
117 VclPtr<ScrollBar> aVerSBar;
118 VclPtr<ScrollBar> aHorSBar;
119 VclPtr<ScrollBarBox> aScrBarBox;
120 tools::Rectangle aCurSelectionRect;
121 std::vector<tools::Rectangle> aSelectedRectList;
122 Idle aAutoArrangeIdle;
123 Idle aDocRectChangedIdle;
124 Idle aVisRectChangedIdle;
125 Idle aCallSelectHdlIdle;
126 Size aVirtOutputSize;
127 Size aImageSize;
128 Size aDefaultTextSize;
129 Size aOutputSize; // Pixel
130 VclPtr<SvtIconChoiceCtrl> pView;
131 std::unique_ptr<IcnCursor_Impl> pImpCursor;
132 std::unique_ptr<IcnGridMap_Impl> pGridMap;
133 tools::Long nMaxVirtWidth; // max. width aVirtOutputSize for ALIGN_TOP
134 tools::Long nMaxVirtHeight; // max. height aVirtOutputSize for ALIGN_LEFT
135 std::vector< SvxIconChoiceCtrlEntry* > maZOrderList;
136 std::unique_ptr<SvxIconChoiceCtrlColumnInfoMap> m_pColumns;
137 WinBits nWinBits;
138 tools::Long nMaxBoundHeight; // height of highest BoundRects
139 IconChoiceFlags nFlags;
140 DrawTextFlags nCurTextDrawFlags;
141 ImplSVEvent * nUserEventAdjustScrBars;
142 SvxIconChoiceCtrlEntry* pCurHighlightFrame;
143 bool bHighlightFramePressed;
144 SvxIconChoiceCtrlEntry* pHead = nullptr; // top left entry
145 SvxIconChoiceCtrlEntry* pCursor;
146 SvxIconChoiceCtrlEntry* pHdlEntry;
147 SvxIconChoiceCtrlEntry* pAnchor; // for selection
148 LocalFocus aFocus; // Data for focusrect
149 ::vcl::AccessibleFactoryAccess aAccFactory;
151 SvxIconChoiceCtrlTextMode eTextMode;
152 SelectionMode eSelectionMode;
153 sal_Int32 nSelectionCount;
154 SvxIconChoiceCtrlPositionMode ePositionMode;
155 bool bBoundRectsDirty;
156 bool bUpdateMode;
158 void ShowCursor( bool bShow );
160 void ImpArrange( bool bKeepPredecessors );
161 void AdjustVirtSize( const tools::Rectangle& );
162 void ResetVirtSize();
163 void CheckScrollBars();
165 DECL_LINK( ScrollUpDownHdl, ScrollBar*, void );
166 DECL_LINK( ScrollLeftRightHdl, ScrollBar*, void );
167 DECL_LINK( UserEventHdl, void*, void );
168 DECL_LINK( AutoArrangeHdl, Timer*, void );
169 DECL_LINK( DocRectChangedHdl, Timer*, void );
170 DECL_LINK( VisRectChangedHdl, Timer*, void );
171 DECL_LINK( CallSelectHdlHdl, Timer*, void );
173 void AdjustScrollBars();
174 void PositionScrollBars( tools::Long nRealWidth, tools::Long nRealHeight );
175 static tools::Long GetScrollBarPageSize( tools::Long nVisibleRange )
177 return ((nVisibleRange*75)/100);
179 tools::Long GetScrollBarLineSize() const
181 return nMaxBoundHeight / 2;
183 bool HandleScrollCommand( const CommandEvent& rCmd );
184 void ToDocPos( Point& rPosPixel )
186 rPosPixel -= pView->GetMapMode().GetOrigin();
188 void InitScrollBarBox();
189 void ToggleSelection( SvxIconChoiceCtrlEntry* );
190 void DeselectAllBut( SvxIconChoiceCtrlEntry const * );
191 void Center( SvxIconChoiceCtrlEntry* pEntry ) const;
192 void CallSelectHandler();
193 void SelectRect(
194 SvxIconChoiceCtrlEntry* pEntry1,
195 SvxIconChoiceCtrlEntry* pEntry2,
196 bool bAdd,
197 std::vector<tools::Rectangle>* pOtherRects
200 void SelectRange(
201 SvxIconChoiceCtrlEntry const * pStart,
202 SvxIconChoiceCtrlEntry const * pEnd,
203 bool bAdd
206 void AddSelectedRect( const tools::Rectangle& );
207 void AddSelectedRect(
208 SvxIconChoiceCtrlEntry* pEntry1,
209 SvxIconChoiceCtrlEntry* pEntry2
212 void ClearSelectedRectList();
213 tools::Rectangle CalcMaxTextRect( const SvxIconChoiceCtrlEntry* pEntry ) const;
215 void ClipAtVirtOutRect( tools::Rectangle& rRect ) const;
216 GridId GetPredecessorGrid( const Point& rDocPos) const;
218 void InitPredecessors();
219 void ClearPredecessors();
221 bool CheckVerScrollBar();
222 bool CheckHorScrollBar();
223 void CancelUserEvents();
224 void EntrySelected(
225 SvxIconChoiceCtrlEntry* pEntry,
226 bool bSelect
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 void ShowFocus ( tools::Rectangle const & rRect );
240 void DrawFocusRect(vcl::RenderContext& rRenderContext);
242 bool IsMnemonicChar( sal_Unicode cChar, sal_uLong& rPos ) const;
244 // Copy assignment is forbidden and not implemented.
245 SvxIconChoiceCtrl_Impl (const SvxIconChoiceCtrl_Impl &) = delete;
246 SvxIconChoiceCtrl_Impl & operator= (const SvxIconChoiceCtrl_Impl &) = delete;
248 public:
250 tools::Long nGridDX;
251 tools::Long nGridDY;
252 tools::Long nHorSBarHeight;
253 tools::Long nVerSBarWidth;
255 SvxIconChoiceCtrl_Impl( SvtIconChoiceCtrl* pView, WinBits nWinStyle );
256 ~SvxIconChoiceCtrl_Impl();
258 void SetSelectionMode(SelectionMode eMode)
260 eSelectionMode = eMode;
263 void Clear( bool bInCtor );
264 void SetStyle( WinBits nWinStyle );
265 WinBits GetStyle() const { return nWinBits; }
266 void InsertEntry( std::unique_ptr<SvxIconChoiceCtrlEntry>, size_t nPos );
267 void RemoveEntry( size_t nPos );
268 void FontModified();
269 void SelectAll();
270 void SelectEntry(
271 SvxIconChoiceCtrlEntry*,
272 bool bSelect,
273 bool bAddToSelection = false
275 void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect);
276 bool MouseButtonDown( const MouseEvent& );
277 bool MouseButtonUp( const MouseEvent& );
278 bool MouseMove( const MouseEvent&);
279 bool RequestHelp( const HelpEvent& rHEvt );
280 void SetCursor_Impl(
281 SvxIconChoiceCtrlEntry* pOldCursor,
282 SvxIconChoiceCtrlEntry* pNewCursor,
283 bool bMod1,
284 bool bShift
286 bool KeyInput( const KeyEvent& );
287 void Resize();
288 void GetFocus();
289 void LoseFocus();
290 void SetUpdateMode( bool bUpdate );
291 bool GetUpdateMode() const { return bUpdateMode; }
292 void PaintEntry(SvxIconChoiceCtrlEntry*, const Point&, vcl::RenderContext& rRenderContext);
294 void SetEntryPos(
295 SvxIconChoiceCtrlEntry* pEntry,
296 const Point& rPos
299 void InvalidateEntry( SvxIconChoiceCtrlEntry* );
301 void SetNoSelection();
303 SvxIconChoiceCtrlEntry* GetCurEntry() const { return pCursor; }
304 void SetCursor( SvxIconChoiceCtrlEntry* );
306 SvxIconChoiceCtrlEntry* GetEntry( const Point& rDocPos, bool bHit = false );
308 void MakeEntryVisible( SvxIconChoiceCtrlEntry* pEntry, bool bBound = true );
310 void Arrange(
311 bool bKeepPredecessors,
312 tools::Long nSetMaxVirtWidth,
313 tools::Long nSetMaxVirtHeight
316 tools::Rectangle CalcFocusRect( SvxIconChoiceCtrlEntry* );
317 tools::Rectangle CalcBmpRect( SvxIconChoiceCtrlEntry*, const Point* pPos = nullptr );
318 tools::Rectangle CalcTextRect(
319 SvxIconChoiceCtrlEntry*,
320 const Point* pPos = nullptr,
321 const OUString* pStr = nullptr
324 tools::Long CalcBoundingWidth() const;
325 tools::Long CalcBoundingHeight() const;
326 Size CalcBoundingSize() const;
327 void FindBoundingRect( SvxIconChoiceCtrlEntry* pEntry );
328 void SetBoundingRect_Impl(
329 SvxIconChoiceCtrlEntry* pEntry,
330 const Point& rPos,
331 const Size& rBoundingSize
333 // recalculates all invalid BoundRects
334 void RecalcAllBoundingRectsSmart();
335 const tools::Rectangle& GetEntryBoundRect( SvxIconChoiceCtrlEntry* );
336 void InvalidateBoundingRect( tools::Rectangle& rRect )
338 rRect.SetRight(LONG_MAX);
339 bBoundRectsDirty = true;
341 static bool IsBoundingRectValid( const tools::Rectangle& rRect ) { return ( rRect.Right() != LONG_MAX ); }
343 static void PaintEmphasis(const tools::Rectangle& rRect1, bool bSelected,
344 vcl::RenderContext& rRenderContext );
346 void PaintItem(const tools::Rectangle& rRect, IcnViewFieldType eItem, SvxIconChoiceCtrlEntry* pEntry,
347 sal_uInt16 nPaintFlags, vcl::RenderContext& rRenderContext);
349 // recalculates all BoundingRects if bMustRecalcBoundingRects == true
350 void CheckBoundingRects() { if (bBoundRectsDirty) RecalcAllBoundingRectsSmart(); }
351 void Command( const CommandEvent& rCEvt );
352 void ToTop( SvxIconChoiceCtrlEntry* );
354 sal_Int32 GetSelectionCount() const;
355 void SetGrid( const Size& );
356 Size GetMinGrid() const;
357 void Scroll( tools::Long nDeltaX, tools::Long nDeltaY );
358 const Size& GetItemSize( IcnViewFieldType ) const;
360 void HideDDIcon();
362 static bool IsOver(
363 std::vector<tools::Rectangle>* pSelectedRectList,
364 const tools::Rectangle& rEntryBoundRect
367 void SelectRect(
368 const tools::Rectangle&,
369 bool bAdd,
370 std::vector<tools::Rectangle>* pOtherRects
373 void MakeVisible(
374 const tools::Rectangle& rDocPos,
375 bool bInScrollBarEvent=false
378 #ifdef DBG_UTIL
379 void SetEntryTextMode(
380 SvxIconChoiceCtrlTextMode,
381 SvxIconChoiceCtrlEntry* pEntry
383 #endif
384 size_t GetEntryCount() const { return maEntries.size(); }
385 SvxIconChoiceCtrlEntry* GetEntry( size_t nPos )
387 return maEntries[ nPos ].get();
389 SvxIconChoiceCtrlEntry* GetEntry( size_t nPos ) const
391 return maEntries[ nPos ].get();
393 SvxIconChoiceCtrlEntry* GetFirstSelectedEntry() const;
394 sal_Int32 GetEntryListPos( SvxIconChoiceCtrlEntry const * ) const;
395 void InitSettings();
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;
423 class IcnCursor_Impl
425 SvxIconChoiceCtrl_Impl* pView;
426 std::unique_ptr<IconChoiceMap> xColumns;
427 std::unique_ptr<IconChoiceMap> xRows;
428 tools::Long nCols;
429 tools::Long nRows;
430 short nDeltaWidth;
431 short nDeltaHeight;
432 SvxIconChoiceCtrlEntry* pCurEntry;
433 void SetDeltas();
434 void ImplCreate();
435 void Create() { if( !xColumns ) ImplCreate(); }
437 sal_uInt16 GetSortListPos(
438 SvxIconChoiceCtrlEntryPtrVec& rList,
439 tools::Long nValue,
440 bool bVertical);
441 SvxIconChoiceCtrlEntry* SearchCol(
442 sal_uInt16 nCol,
443 sal_uInt16 nTop,
444 sal_uInt16 nBottom,
445 bool bDown,
446 bool bSimple
449 SvxIconChoiceCtrlEntry* SearchRow(
450 sal_uInt16 nRow,
451 sal_uInt16 nLeft,
452 sal_uInt16 nRight,
453 bool bRight,
454 bool bSimple
457 public:
458 explicit IcnCursor_Impl( SvxIconChoiceCtrl_Impl* pOwner );
459 ~IcnCursor_Impl();
460 void Clear();
462 // for Cursortravelling etc.
463 SvxIconChoiceCtrlEntry* GoLeftRight( SvxIconChoiceCtrlEntry*, bool bRight );
464 SvxIconChoiceCtrlEntry* GoUpDown( SvxIconChoiceCtrlEntry*, bool bDown );
465 SvxIconChoiceCtrlEntry* GoPageUpDown( SvxIconChoiceCtrlEntry*, bool bDown );
468 class IcnGridMap_Impl
470 tools::Rectangle _aLastOccupiedGrid;
471 SvxIconChoiceCtrl_Impl* _pView;
472 std::unique_ptr<bool[]> _pGridMap;
473 sal_uInt16 _nGridCols, _nGridRows;
475 void Expand();
476 void Create_Impl();
477 void Create() { if(!_pGridMap) Create_Impl(); }
479 void GetMinMapSize( sal_uInt16& rDX, sal_uInt16& rDY ) const;
481 public:
482 explicit IcnGridMap_Impl(SvxIconChoiceCtrl_Impl* pView);
483 ~IcnGridMap_Impl();
485 void Clear();
487 GridId GetGrid( const Point& rDocPos );
488 GridId GetGrid( sal_uInt16 nGridX, sal_uInt16 nGridY );
489 GridId GetUnoccupiedGrid();
491 void OccupyGrids( const SvxIconChoiceCtrlEntry* );
492 void OccupyGrid( GridId nId )
494 DBG_ASSERT(!_pGridMap || nId<o3tl::make_unsigned(_nGridCols*_nGridRows),"OccupyGrid: Bad GridId");
495 if(_pGridMap && nId < o3tl::make_unsigned(_nGridCols *_nGridRows) )
496 _pGridMap[ nId ] = true;
499 tools::Rectangle GetGridRect( GridId );
500 void GetGridCoord( GridId, sal_uInt16& rGridX, sal_uInt16& rGridY );
501 static sal_uLong GetGridCount(
502 const Size& rSizePixel,
503 sal_uInt16 nGridWidth,
504 sal_uInt16 nGridHeight
507 void OutputSizeChanged();
510 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */