calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / vcl / inc / svimpbox.hxx
blob949a488ed816ed89a0a2fa069615cec15f4dea00
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_VCL_SOURCE_INC_SVIMPBOX_HXX
21 #define INCLUDED_VCL_SOURCE_INC_SVIMPBOX_HXX
23 #include <vcl/dllapi.h>
24 #include <vcl/seleng.hxx>
25 #include <vcl/idle.hxx>
26 #include <vcl/image.hxx>
27 #include <vcl/svtaccessiblefactory.hxx>
28 #include <vcl/vclevent.hxx>
29 #include <vcl/toolkit/scrbar.hxx>
30 #include <vcl/toolkit/treelistbox.hxx>
31 #include <o3tl/enumarray.hxx>
32 #include <memory>
33 #include <vector>
35 class SvLBoxButton;
36 class SvTreeList;
37 class SvImpLBox;
38 class SvTreeListEntry;
39 namespace comphelper::string { class NaturalStringSorter; }
41 class ImpLBSelEng final : public FunctionSet
43 SvImpLBox* pImp;
44 VclPtr<SvTreeListBox> pView;
46 public:
47 ImpLBSelEng( SvImpLBox* pImp, SvTreeListBox* pView );
48 virtual ~ImpLBSelEng() override;
49 void BeginDrag() override;
50 void CreateAnchor() override;
51 void DestroyAnchor() override;
52 void SetCursorAtPoint( const Point& rPoint,
53 bool bDontSelectAtCursor=false ) override;
54 bool IsSelectionAtPoint( const Point& rPoint ) override;
55 void DeselectAtPoint( const Point& rPoint ) override;
56 void DeselectAll() override;
59 // Flags for nFlag
60 enum class LBoxFlags {
61 NONE = 0x0000,
62 DeselectAll = 0x0002,
63 StartEditTimer = 0x0004, // MAC only
64 IgnoreSelect = 0x0008,
65 InResize = 0x0010,
66 RemovedEntryInvisible = 0x0020,
67 RemovedRecalcMostRight = 0x0040,
68 IgnoreChangedTabs = 0x0080,
69 InPaint = 0x0100,
70 EndScrollSetVisSize = 0x0200,
71 Filling = 0x0400,
73 namespace o3tl
75 template<> struct typed_flags<LBoxFlags> : is_typed_flags<LBoxFlags, 0x07fe> {};
78 #define NODE_BMP_TABDIST_NOTVALID -2000000
79 #define FIRST_ENTRY_TAB 1
81 class SvImpLBox
83 friend class ImpLBSelEng;
84 friend class SvTreeListBox;
85 friend class SalInstanceTreeView;
86 friend class IconView;
87 private:
88 SvTreeList* m_pTree;
89 SvTreeListEntry* m_pAnchor;
90 SvTreeListEntry* m_pMostRightEntry;
91 SvLBoxButton* m_pActiveButton;
92 SvTreeListEntry* m_pActiveEntry;
93 SvLBoxTab* m_pActiveTab;
95 VclPtr<ScrollBarBox> m_aScrBarBox;
97 ::vcl::AccessibleFactoryAccess
98 m_aFactoryAccess;
100 static Image* s_pDefCollapsed;
101 static Image* s_pDefExpanded;
102 static oslInterlockedCount s_nImageRefCount; /// When 0 all static images will be destroyed
104 // Node Bitmaps
105 enum class ImageType
107 NodeExpanded = 0, // node is expanded ( usually a bitmap showing a minus )
108 NodeCollapsed, // node is collapsed ( usually a bitmap showing a plus )
109 EntryDefExpanded, // default for expanded entries
110 EntryDefCollapsed, // default for collapsed entries
111 LAST = EntryDefCollapsed
114 // all our images
115 o3tl::enumarray<ImageType, Image>
116 m_aNodeAndEntryImages;
118 ImpLBSelEng m_aFctSet;
120 tools::Long m_nNodeBmpWidth;
121 tools::Long m_nMostRight;
122 short m_nHorSBarHeight, m_nVerSBarWidth;
124 bool m_bUpdateMode : 1;
125 bool m_bSubLstOpLR : 1; // open/close sublist with cursor left/right, defaulted with false
126 bool mbForceMakeVisible;
128 Point m_aEditClickPos;
129 Idle m_aEditIdle;
131 std::unique_ptr<comphelper::string::NaturalStringSorter> m_pStringSorter;
133 std::vector< short > m_aContextBmpWidthVector;
135 DECL_LINK(EditTimerCall, Timer *, void);
137 void InvalidateEntriesFrom( tools::Long nY ) const;
138 bool IsLineVisible( tools::Long nY ) const;
139 void KeyLeftRight( tools::Long nDiff );
141 void DrawNet(vcl::RenderContext& rRenderContext);
143 // ScrollBar-Handler
144 DECL_LINK( ScrollUpDownHdl, ScrollBar*, void );
145 DECL_LINK( ScrollLeftRightHdl, ScrollBar*, void );
146 DECL_LINK( EndScrollHdl, ScrollBar*, void );
148 void SetNodeBmpWidth( const Image& );
149 void SetNodeBmpTabDistance();
151 // Selection-Engine
152 SvTreeListEntry* MakePointVisible( const Point& rPoint );
154 void SetAnchorSelection( SvTreeListEntry* pOld,
155 SvTreeListEntry* pNewCursor );
156 void BeginDrag();
157 bool ButtonDownCheckCtrl( const MouseEvent& rMEvt, SvTreeListEntry* pEntry );
158 bool MouseMoveCheckCtrl( const MouseEvent& rMEvt, SvTreeListEntry const * pEntry );
159 bool ButtonUpCheckCtrl( const MouseEvent& rMEvt );
160 bool ButtonDownCheckExpand( const MouseEvent&, SvTreeListEntry* );
162 bool EntryReallyHit(SvTreeListEntry* pEntry, const Point& rPos, tools::Long nLine);
163 void InitScrollBarBox();
164 SvLBoxTab* NextTab( SvLBoxTab const * );
166 void SetMostRight( SvTreeListEntry* pEntry );
167 void FindMostRight( SvTreeListEntry* pParent );
168 void FindMostRight_Impl( SvTreeListEntry* pParent );
169 void NotifyTabsChanged();
171 // if element at cursor can be expanded in general
172 bool IsExpandable() const;
174 static void implInitDefaultNodeImages();
176 void UpdateStringSorter();
178 short UpdateContextBmpWidthVector( SvTreeListEntry const * pEntry, short nWidth );
179 void UpdateContextBmpWidthMax( SvTreeListEntry const * pEntry );
180 void UpdateContextBmpWidthVectorFromMovedEntry( SvTreeListEntry* pEntry );
182 void ExpandAll();
183 void CollapseTo(SvTreeListEntry* pParentToCollapse);
185 protected:
186 VclPtr<SvTreeListBox> m_pView;
187 VclPtr<ScrollBar> m_aHorSBar;
188 VclPtr<ScrollBar> m_aVerSBar;
189 SvTreeListEntry* m_pCursor;
190 SvTreeListEntry* m_pCursorOld;
191 SvTreeListEntry* m_pStartEntry;
192 ImplSVEvent* m_nCurUserEvent;
193 Size m_aOutputSize;
194 LBoxFlags m_nFlags;
195 WinBits m_nStyle;
196 bool mbNoAutoCurEntry; // disable the behavior of automatically selecting a "CurEntry" upon painting the control
197 SelectionEngine m_aSelEng;
198 sal_uLong m_nVisibleCount; // Number of lines in control
199 bool m_bInVScrollHdl : 1;
200 bool m_bSimpleTravel : 1; // is true if SelectionMode::Single
201 tools::Long m_nNextVerVisSize;
202 tools::Long m_nNodeBmpTabDistance; // typical smaller than 0
204 virtual tools::Long GetEntryLine(const SvTreeListEntry* pEntry) const;
205 virtual void CursorDown();
206 virtual void CursorUp();
207 virtual void PageDown( sal_uInt16 nDelta );
208 virtual void PageUp( sal_uInt16 nDelta );
209 // set Thumb to FirstEntryToDraw
210 virtual void SyncVerThumb();
211 virtual void AdjustScrollBars( Size& rSize );
212 virtual void InvalidateEntry( tools::Long nY ) const;
214 tools::Rectangle GetVisibleArea() const;
215 void SetCursor( SvTreeListEntry* pEntry, bool bForceNoSelect = false );
216 void PositionScrollBars( Size& rOSize, sal_uInt16 nMask );
217 void FindMostRight();
218 void FillView();
219 void ShowVerSBar();
220 void StopUserEvent();
222 DECL_LINK( MyUserEvent, void*, void);
224 public:
225 SvImpLBox( SvTreeListBox* pView, SvTreeList*, WinBits nWinStyle );
226 virtual ~SvImpLBox();
228 void Clear();
229 void SetStyle( WinBits i_nWinStyle );
230 void SetNoAutoCurEntry( bool b );
231 void SetModel( SvTreeList* pModel ) { m_pTree = pModel;}
233 void EntryInserted( SvTreeListEntry*);
234 void RemovingEntry( SvTreeListEntry* pEntry );
235 void EntryRemoved();
236 void MovingEntry( SvTreeListEntry* pEntry );
237 void EntryMoved( SvTreeListEntry* pEntry );
238 void TreeInserted( SvTreeListEntry* pEntry );
240 void EntryExpanded( SvTreeListEntry* pEntry );
241 void EntryCollapsed( SvTreeListEntry* pEntry );
242 void CollapsingEntry( SvTreeListEntry* pEntry );
243 void EntrySelected( SvTreeListEntry* pEntry, bool bSelect );
245 virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect);
246 void MouseButtonDown( const MouseEvent& );
247 void MouseButtonUp( const MouseEvent& );
248 void MouseMove( const MouseEvent&);
249 virtual bool KeyInput( const KeyEvent& );
250 void Resize();
251 void GetFocus();
252 void LoseFocus();
253 virtual void UpdateAll( bool bInvalidateCompleteView );
254 void SetEntryHeight();
255 void InvalidateEntry( SvTreeListEntry* );
256 void RecalcFocusRect();
258 void SelectEntry( SvTreeListEntry* pEntry, bool bSelect );
259 void SetDragDropMode( DragDropMode eDDMode );
260 void SetSelectionMode( SelectionMode eSelMode );
262 virtual bool IsEntryInView( SvTreeListEntry* pEntry ) const;
263 virtual SvTreeListEntry* GetEntry( const Point& rPos ) const;
264 // returns last entry, if Pos below last entry
265 virtual SvTreeListEntry* GetClickedEntry( const Point& ) const;
266 SvTreeListEntry* GetCurEntry() const { return m_pCursor; }
267 void SetCurEntry( SvTreeListEntry* );
268 virtual Point GetEntryPosition(const SvTreeListEntry*) const;
269 void MakeVisible( SvTreeListEntry* pEntry, bool bMoveToTop = false );
270 void ScrollToAbsPos( tools::Long nPos );
272 void PaintDDCursor(SvTreeListEntry* pEntry, bool bShow);
274 // Images
275 inline Image& implGetImageLocation( const ImageType _eType );
277 inline void SetExpandedNodeBmp( const Image& _rImg );
278 inline void SetCollapsedNodeBmp( const Image& _rImg );
280 inline const Image& GetExpandedNodeBmp( );
281 inline const Image& GetCollapsedNodeBmp( );
283 inline void SetDefaultEntryExpBmp( const Image& _rImg );
284 inline void SetDefaultEntryColBmp( const Image& _rImg );
285 inline const Image& GetDefaultEntryExpBmp( );
286 inline const Image& GetDefaultEntryColBmp( );
288 static const Image& GetDefaultExpandedNodeImage( );
289 static const Image& GetDefaultCollapsedNodeImage( );
291 const Size& GetOutputSize() const { return m_aOutputSize;}
292 virtual void KeyUp( bool bPageUp );
293 virtual void KeyDown( bool bPageDown );
294 void Command( const CommandEvent& rCEvt );
296 void Invalidate();
297 void DestroyAnchor() { m_pAnchor=nullptr; m_aSelEng.Reset(); }
298 void SelAllDestrAnch( bool bSelect, bool bDestroyAnchor = true, bool bSingleSelToo = false );
299 void ShowCursor( bool bShow );
301 bool RequestHelp( const HelpEvent& rHEvt );
302 bool IsNodeButton( const Point& rPosPixel, const SvTreeListEntry* pEntry ) const;
303 void SetUpdateMode( bool bMode );
304 bool GetUpdateMode() const { return m_bUpdateMode; }
305 tools::Rectangle GetClipRegionRect() const;
306 bool HasHorScrollBar() const { return m_aHorSBar->IsVisible(); }
307 void CallEventListeners( VclEventId nEvent, void* pData = nullptr );
309 bool IsSelectable( const SvTreeListEntry* pEntry ) const;
310 void SetForceMakeVisible(bool bEnable) { mbForceMakeVisible = bEnable; }
312 // tdf#143114 allow to ask if CaptureOnButton is active
313 // (MouseButtonDown hit on SvLBoxButton, CaptureMouse() active)
314 bool IsCaptureOnButtonActive() const;
317 inline bool SvImpLBox::IsCaptureOnButtonActive() const
319 return nullptr != m_pActiveButton && nullptr != m_pActiveEntry;
322 inline Image& SvImpLBox::implGetImageLocation( const ImageType _eType )
324 return m_aNodeAndEntryImages[_eType];
327 inline void SvImpLBox::SetExpandedNodeBmp( const Image& rImg )
329 implGetImageLocation( ImageType::NodeExpanded ) = rImg;
330 SetNodeBmpWidth( rImg );
333 inline void SvImpLBox::SetCollapsedNodeBmp( const Image& rImg )
335 implGetImageLocation( ImageType::NodeCollapsed ) = rImg;
336 SetNodeBmpWidth( rImg );
339 inline const Image& SvImpLBox::GetExpandedNodeBmp( )
341 return implGetImageLocation( ImageType::NodeExpanded );
344 inline const Image& SvImpLBox::GetCollapsedNodeBmp( )
346 return implGetImageLocation( ImageType::NodeCollapsed );
349 inline void SvImpLBox::SetDefaultEntryExpBmp( const Image& _rImg )
351 implGetImageLocation( ImageType::EntryDefExpanded ) = _rImg;
354 inline void SvImpLBox::SetDefaultEntryColBmp( const Image& _rImg )
356 implGetImageLocation( ImageType::EntryDefCollapsed ) = _rImg;
359 inline const Image& SvImpLBox::GetDefaultEntryExpBmp( )
361 return implGetImageLocation( ImageType::EntryDefExpanded );
364 inline const Image& SvImpLBox::GetDefaultEntryColBmp( )
366 return implGetImageLocation( ImageType::EntryDefCollapsed );
369 inline Point SvImpLBox::GetEntryPosition(const SvTreeListEntry* pEntry) const
371 return Point(0, GetEntryLine(pEntry));
374 inline bool SvImpLBox::IsLineVisible( tools::Long nY ) const
376 bool bRet = true;
377 if ( nY < 0 || nY >= m_aOutputSize.Height() )
378 bRet = false;
379 return bRet;
382 inline void SvImpLBox::TreeInserted( SvTreeListEntry* pInsTree )
384 EntryInserted( pInsTree );
387 #endif // INCLUDED_VCL_SOURCE_INC_SVIMPBOX_HXX
389 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */