nss: upgrade to release 3.73
[LibreOffice.git] / vcl / source / control / imivctl.hxx
blobb242ef91da7f7289566036110896f8bdcb052b88
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_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>
35 #include <limits.h>
38 #include <memory>
39 #include <map>
41 class IcnCursor_Impl;
42 class SvtIconChoiceCtrl;
43 class SvxIconChoiceCtrlEntry;
44 class IcnViewEdit_Impl;
45 class IcnGridMap_Impl;
48 // some defines
50 #define PAINTFLAG_HOR_CENTERED 0x0001
51 #define PAINTFLAG_VER_CENTERED 0x0002
53 enum class IconChoiceFlags {
54 NONE = 0x0000,
55 AddMode = 0x0001,
56 SelectingRect = 0x0002,
57 DownCtrl = 0x0004,
58 DownDeselect = 0x0008,
59 EntryListPosValid = 0x0010,
60 ClearingSelection = 0x0020,
61 Arranging = 0x0040
63 namespace o3tl {
64 template<> struct typed_flags<IconChoiceFlags> : is_typed_flags<IconChoiceFlags, 0x007f> {};
67 // unit = pixels
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
78 #define LROFFS_TEXT 2
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
88 Image,
89 Text
93 // Data about the focus of entries
95 struct LocalFocus
97 tools::Rectangle aRect;
98 Color aPenColor;
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;
128 Size aImageSize;
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;
138 WinBits nWinBits;
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;
157 bool bUpdateMode;
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();
194 void SelectRect(
195 SvxIconChoiceCtrlEntry* pEntry1,
196 SvxIconChoiceCtrlEntry* pEntry2,
197 bool bAdd,
198 std::vector<tools::Rectangle>* pOtherRects
201 void SelectRange(
202 SvxIconChoiceCtrlEntry const * pStart,
203 SvxIconChoiceCtrlEntry const * pEnd,
204 bool bAdd
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();
225 void EntrySelected(
226 SvxIconChoiceCtrlEntry* pEntry,
227 bool bSelect
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;
249 public:
251 tools::Long nGridDX;
252 tools::Long nGridDY;
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 );
269 void FontModified();
270 void SelectAll();
271 void SelectEntry(
272 SvxIconChoiceCtrlEntry*,
273 bool bSelect,
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 );
281 void SetCursor_Impl(
282 SvxIconChoiceCtrlEntry* pOldCursor,
283 SvxIconChoiceCtrlEntry* pNewCursor,
284 bool bMod1,
285 bool bShift
287 bool KeyInput( const KeyEvent& );
288 void Resize();
289 void GetFocus();
290 void LoseFocus();
291 void SetUpdateMode( bool bUpdate );
292 bool GetUpdateMode() const { return bUpdateMode; }
293 void PaintEntry(SvxIconChoiceCtrlEntry*, const Point&, vcl::RenderContext& rRenderContext);
295 void SetEntryPos(
296 SvxIconChoiceCtrlEntry* pEntry,
297 const Point& rPos
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 );
311 void Arrange(
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,
331 const Point& rPos,
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;
361 void HideDDIcon();
363 static bool IsOver(
364 std::vector<tools::Rectangle>* pSelectedRectList,
365 const tools::Rectangle& rEntryBoundRect
368 void SelectRect(
369 const tools::Rectangle&,
370 bool bAdd,
371 std::vector<tools::Rectangle>* pOtherRects
374 void MakeVisible(
375 const tools::Rectangle& rDocPos,
376 bool bInScrollBarEvent=false
379 #ifdef DBG_UTIL
380 void SetEntryTextMode(
381 SvxIconChoiceCtrlTextMode,
382 SvxIconChoiceCtrlEntry* pEntry
384 #endif
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;
396 void InitSettings();
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;
424 class IcnCursor_Impl
426 SvxIconChoiceCtrl_Impl* pView;
427 std::unique_ptr<IconChoiceMap> xColumns;
428 std::unique_ptr<IconChoiceMap> xRows;
429 tools::Long nCols;
430 tools::Long nRows;
431 short nDeltaWidth;
432 short nDeltaHeight;
433 SvxIconChoiceCtrlEntry* pCurEntry;
434 void SetDeltas();
435 void ImplCreate();
436 void Create() { if( !xColumns ) ImplCreate(); }
438 sal_uInt16 GetSortListPos(
439 SvxIconChoiceCtrlEntryPtrVec& rList,
440 tools::Long nValue,
441 bool bVertical);
442 SvxIconChoiceCtrlEntry* SearchCol(
443 sal_uInt16 nCol,
444 sal_uInt16 nTop,
445 sal_uInt16 nBottom,
446 bool bDown,
447 bool bSimple
450 SvxIconChoiceCtrlEntry* SearchRow(
451 sal_uInt16 nRow,
452 sal_uInt16 nLeft,
453 sal_uInt16 nRight,
454 bool bRight,
455 bool bSimple
458 public:
459 explicit IcnCursor_Impl( SvxIconChoiceCtrl_Impl* pOwner );
460 ~IcnCursor_Impl();
461 void Clear();
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;
476 void Expand();
477 void Create_Impl();
478 void Create() { if(!_pGridMap) Create_Impl(); }
480 void GetMinMapSize( sal_uInt16& rDX, sal_uInt16& rDY ) const;
482 public:
483 explicit IcnGridMap_Impl(SvxIconChoiceCtrl_Impl* pView);
484 ~IcnGridMap_Impl();
486 void Clear();
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();
511 #endif
513 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */