sdext: adapt xpdfwrapper to poppler 24.12
[LibreOffice.git] / vcl / source / control / imivctl.hxx
blob3fd3503a644838d154d1307806129ec334eaf8c5
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/toolkit/ivctrl.hxx>
31 #include <vcl/toolkit/scrbar.hxx>
33 #include <limits.h>
36 #include <memory>
37 #include <map>
39 class IcnCursor_Impl;
40 class SvtIconChoiceCtrl;
41 class SvxIconChoiceCtrlEntry;
42 class IcnGridMap_Impl;
45 // some defines
47 #define PAINTFLAG_HOR_CENTERED 0x0001
48 #define PAINTFLAG_VER_CENTERED 0x0002
50 enum class IconChoiceFlags {
51 NONE = 0x0000,
52 AddMode = 0x0001,
53 ClearingSelection = 0x0002,
54 Arranging = 0x0004,
56 namespace o3tl {
57 template<> struct typed_flags<IconChoiceFlags> : is_typed_flags<IconChoiceFlags, 0x007f> {};
60 // unit = pixels
61 // distances from window borders
62 #define LROFFS_WINBORDER 4
63 #define TBOFFS_WINBORDER 4
64 // for the bounding rectangle
65 #define LROFFS_BOUND 2
66 // distance icon to text
67 #define HOR_DIST_BMP_STRING 3
68 #define VER_DIST_BMP_STRING 3
69 // width offset of highlight rectangle for Text
70 #define LROFFS_TEXT 2
71 // Vertical text padding when the item contains only text
72 #define VERT_TEXT_PADDING 4
73 // Width of the marker used for the selected tab (native controls only)
74 #define TAB_MARK_WIDTH 3
76 #define DEFAULT_MAX_VIRT_WIDTH 200
77 #define DEFAULT_MAX_VIRT_HEIGHT 200
79 #define VIEWMODE_MASK (WB_ICON | WB_SMALLICON | WB_DETAILS)
82 enum class IcnViewFieldType
84 Image,
85 Text
89 // Data about the focus of entries
91 struct LocalFocus
93 tools::Rectangle aRect;
94 Color aPenColor;
98 typedef sal_uLong GridId;
100 // Implementation-class of IconChoiceCtrl
103 typedef std::vector<SvxIconChoiceCtrlEntry*> SvxIconChoiceCtrlEntryPtrVec;
105 class SvxIconChoiceCtrl_Impl
107 friend class IcnCursor_Impl;
108 friend class IcnGridMap_Impl;
110 std::vector< std::unique_ptr<SvxIconChoiceCtrlEntry> > maEntries;
111 VclPtr<ScrollBar> aVerSBar;
112 VclPtr<ScrollBar> aHorSBar;
113 VclPtr<ScrollBarBox> aScrBarBox;
114 Idle aDocRectChangedIdle;
115 Idle aVisRectChangedIdle;
116 Size aVirtOutputSize;
117 Size aImageSize;
118 Size aDefaultTextSize;
119 Size aOutputSize; // Pixel
120 VclPtr<SvtIconChoiceCtrl> pView;
121 std::unique_ptr<IcnCursor_Impl> pImpCursor;
122 std::unique_ptr<IcnGridMap_Impl> pGridMap;
123 tools::Long nMaxVirtHeight; // max. height aVirtOutputSize
124 std::vector< SvxIconChoiceCtrlEntry* > maZOrderList;
125 WinBits nWinBits;
126 tools::Long nMaxBoundHeight; // height of highest BoundRects
127 IconChoiceFlags nFlags;
128 DrawTextFlags nCurTextDrawFlags;
129 ImplSVEvent * nUserEventAdjustScrBars;
130 SvxIconChoiceCtrlEntry* pCurHighlightFrame;
131 SvxIconChoiceCtrlEntry* pCursor;
132 LocalFocus aFocus; // Data for focusrect
134 bool bBoundRectsDirty;
136 void ShowCursor( bool bShow );
138 void ImpArrange();
139 void AdjustVirtSize( const tools::Rectangle& );
140 void ResetVirtSize();
141 void CheckScrollBars();
143 DECL_LINK( ScrollUpDownHdl, ScrollBar*, void );
144 DECL_LINK( ScrollLeftRightHdl, ScrollBar*, void );
145 DECL_LINK( UserEventHdl, void*, void );
146 DECL_LINK( DocRectChangedHdl, Timer*, void );
147 DECL_LINK( VisRectChangedHdl, Timer*, void );
149 void AdjustScrollBars();
150 void PositionScrollBars( tools::Long nRealWidth, tools::Long nRealHeight );
151 static tools::Long GetScrollBarPageSize( tools::Long nVisibleRange )
153 return ((nVisibleRange*75)/100);
155 tools::Long GetScrollBarLineSize() const
157 return nMaxBoundHeight / 2;
159 bool HandleScrollCommand( const CommandEvent& rCmd );
160 void ToDocPos( Point& rPosPixel )
162 rPosPixel -= pView->GetMapMode().GetOrigin();
164 void InitScrollBarBox();
165 void DeselectAllBut( SvxIconChoiceCtrlEntry const * );
167 tools::Rectangle CalcMaxTextRect( const SvxIconChoiceCtrlEntry* pEntry ) const;
169 void ClipAtVirtOutRect( tools::Rectangle& rRect ) const;
171 bool CheckVerScrollBar();
172 bool CheckHorScrollBar();
173 void CancelUserEvents();
174 void EntrySelected(
175 SvxIconChoiceCtrlEntry* pEntry,
176 bool bSelect
178 void RepaintSelectedEntries();
179 void SetDefaultTextSize();
180 void DocRectChanged() { aDocRectChangedIdle.Start(); }
181 void VisRectChanged() { aVisRectChangedIdle.Start(); }
182 void SetOrigin( const Point& );
184 void ShowFocus ( tools::Rectangle const & rRect );
185 void DrawFocusRect(vcl::RenderContext& rRenderContext, SvxIconChoiceCtrlEntry* pEntry);
187 bool IsMnemonicChar( sal_Unicode cChar, sal_uLong& rPos ) const;
189 // Copy assignment is forbidden and not implemented.
190 SvxIconChoiceCtrl_Impl (const SvxIconChoiceCtrl_Impl &) = delete;
191 SvxIconChoiceCtrl_Impl & operator= (const SvxIconChoiceCtrl_Impl &) = delete;
193 public:
195 tools::Long nGridDX;
196 tools::Long nGridDY;
197 tools::Long nHorSBarHeight;
198 tools::Long nVerSBarWidth;
200 SvxIconChoiceCtrl_Impl( SvtIconChoiceCtrl* pView, WinBits nWinStyle );
201 ~SvxIconChoiceCtrl_Impl();
203 void Clear( bool bInCtor );
204 void SetStyle( WinBits nWinStyle );
205 void InsertEntry( std::unique_ptr<SvxIconChoiceCtrlEntry>, size_t nPos );
206 void RemoveEntry( size_t nPos );
207 void FontModified();
208 void SelectEntry(
209 SvxIconChoiceCtrlEntry*,
210 bool bSelect,
211 bool bAddToSelection = false
213 void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect);
214 bool MouseButtonDown( const MouseEvent& );
215 bool MouseMove( const MouseEvent&);
216 bool RequestHelp( const HelpEvent& rHEvt );
217 void SetCursor_Impl(SvxIconChoiceCtrlEntry* pNewCursor);
218 bool KeyInput( const KeyEvent& );
219 void Resize();
220 void GetFocus();
221 void LoseFocus();
222 void PaintEntry(SvxIconChoiceCtrlEntry*, const Point&, vcl::RenderContext& rRenderContext);
224 SvxIconChoiceCtrlEntry* GetCurEntry() const { return pCursor; }
225 void SetCursor( SvxIconChoiceCtrlEntry* );
227 SvxIconChoiceCtrlEntry* GetEntry( const Point& rDocPos );
229 void MakeEntryVisible(SvxIconChoiceCtrlEntry* pEntry);
231 void Arrange(tools::Long nSetMaxVirtHeight);
233 tools::Rectangle CalcFocusRect( SvxIconChoiceCtrlEntry* );
234 tools::Rectangle CalcBmpRect( SvxIconChoiceCtrlEntry*, const Point* pPos = nullptr );
235 tools::Rectangle CalcTextRect(
236 SvxIconChoiceCtrlEntry*,
237 const Point* pPos = nullptr
240 tools::Long CalcBoundingWidth() const;
241 tools::Long CalcBoundingHeight() const;
242 Size CalcBoundingSize() const;
243 void FindBoundingRect( SvxIconChoiceCtrlEntry* pEntry );
244 // recalculates all invalid BoundRects
245 void RecalcAllBoundingRectsSmart();
246 const tools::Rectangle& GetEntryBoundRect( SvxIconChoiceCtrlEntry* );
247 void InvalidateBoundingRect( tools::Rectangle& rRect )
249 rRect.SetRight(LONG_MAX);
250 bBoundRectsDirty = true;
252 static bool IsBoundingRectValid( const tools::Rectangle& rRect ) { return ( rRect.Right() != LONG_MAX ); }
254 static void PaintEmphasis(const tools::Rectangle& rRect1, vcl::RenderContext& rRenderContext);
256 void PaintItem(const tools::Rectangle& rRect, IcnViewFieldType eItem, SvxIconChoiceCtrlEntry* pEntry,
257 sal_uInt16 nPaintFlags, vcl::RenderContext& rRenderContext);
259 // recalculates all BoundingRects if bMustRecalcBoundingRects == true
260 void CheckBoundingRects() { if (bBoundRectsDirty) RecalcAllBoundingRectsSmart(); }
261 void Command( const CommandEvent& rCEvt );
262 void ToTop( SvxIconChoiceCtrlEntry* );
264 void SetGrid( const Size& );
265 Size GetMinGrid() const;
266 void Scroll( tools::Long nDeltaX, tools::Long nDeltaY );
267 const Size& GetItemSize( IcnViewFieldType ) const;
269 void MakeVisible(
270 const tools::Rectangle& rDocPos,
271 bool bInScrollBarEvent=false
274 size_t GetEntryCount() const { return maEntries.size(); }
275 SvxIconChoiceCtrlEntry* GetEntry( size_t nPos )
277 return maEntries[ nPos ].get();
279 SvxIconChoiceCtrlEntry* GetEntry( size_t nPos ) const
281 return maEntries[ nPos ].get();
283 SvxIconChoiceCtrlEntry* GetFirstSelectedEntry() const;
284 sal_Int32 GetEntryListPos( SvxIconChoiceCtrlEntry const * ) const;
285 void InitSettings();
286 tools::Rectangle GetOutputRect() const;
288 void SetEntryHighlightFrame(SvxIconChoiceCtrlEntry* pEntry);
289 static void DrawHighlightFrame(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect);
291 void CallEventListeners( VclEventId nEvent, void* pData );
294 typedef std::map<sal_uInt16, SvxIconChoiceCtrlEntryPtrVec> IconChoiceMap;
296 class IcnCursor_Impl
298 SvxIconChoiceCtrl_Impl* pView;
299 std::unique_ptr<IconChoiceMap> xColumns;
300 std::unique_ptr<IconChoiceMap> xRows;
301 tools::Long nCols;
302 tools::Long nRows;
303 short nDeltaWidth;
304 short nDeltaHeight;
305 SvxIconChoiceCtrlEntry* pCurEntry;
306 void SetDeltas();
307 void ImplCreate();
308 void Create() { if( !xColumns ) ImplCreate(); }
310 sal_uInt16 GetSortListPos(
311 SvxIconChoiceCtrlEntryPtrVec& rList,
312 tools::Long nValue,
313 bool bVertical);
314 SvxIconChoiceCtrlEntry* SearchCol(
315 sal_uInt16 nCol,
316 sal_uInt16 nTop,
317 sal_uInt16 nBottom,
318 bool bDown,
319 bool bSimple
322 SvxIconChoiceCtrlEntry* SearchRow(
323 sal_uInt16 nRow,
324 sal_uInt16 nLeft,
325 sal_uInt16 nRight,
326 bool bRight,
327 bool bSimple
330 public:
331 explicit IcnCursor_Impl( SvxIconChoiceCtrl_Impl* pOwner );
332 ~IcnCursor_Impl();
333 void Clear();
335 // for Cursortravelling etc.
336 SvxIconChoiceCtrlEntry* GoLeftRight( SvxIconChoiceCtrlEntry*, bool bRight );
337 SvxIconChoiceCtrlEntry* GoUpDown( SvxIconChoiceCtrlEntry*, bool bDown );
338 SvxIconChoiceCtrlEntry* GoPageUpDown( SvxIconChoiceCtrlEntry*, bool bDown );
341 class IcnGridMap_Impl
343 tools::Rectangle _aLastOccupiedGrid;
344 SvxIconChoiceCtrl_Impl* _pView;
345 std::unique_ptr<bool[]> _pGridMap;
346 sal_uInt16 _nGridCols, _nGridRows;
348 void Expand();
349 void Create_Impl();
350 void Create() { if(!_pGridMap) Create_Impl(); }
352 void GetMinMapSize( sal_uInt16& rDX, sal_uInt16& rDY ) const;
354 public:
355 explicit IcnGridMap_Impl(SvxIconChoiceCtrl_Impl* pView);
356 ~IcnGridMap_Impl();
358 void Clear();
360 GridId GetGrid( const Point& rDocPos );
361 GridId GetGrid( sal_uInt16 nGridX, sal_uInt16 nGridY );
362 GridId GetUnoccupiedGrid();
364 void OccupyGrids( const SvxIconChoiceCtrlEntry* );
365 void OccupyGrid( GridId nId )
367 DBG_ASSERT(!_pGridMap || nId<o3tl::make_unsigned(_nGridCols*_nGridRows),"OccupyGrid: Bad GridId");
368 if(_pGridMap && nId < o3tl::make_unsigned(_nGridCols *_nGridRows) )
369 _pGridMap[ nId ] = true;
372 tools::Rectangle GetGridRect( GridId );
373 void GetGridCoord( GridId, sal_uInt16& rGridX, sal_uInt16& rGridY );
374 static sal_uLong GetGridCount(
375 const Size& rSizePixel,
376 sal_uInt16 nGridWidth,
377 sal_uInt16 nGridHeight
380 void OutputSizeChanged();
383 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */