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_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/scrbar.hxx>
26 #include <vcl/idle.hxx>
27 #include <vcl/image.hxx>
28 #include <vcl/svtaccessiblefactory.hxx>
29 #include <vcl/vclevent.hxx>
30 #include <vcl/toolkit/treelistbox.hxx>
31 #include <o3tl/enumarray.hxx>
38 class SvTreeListEntry
;
39 namespace comphelper::string
{ class NaturalStringSorter
; }
41 class ImpLBSelEng final
: public FunctionSet
44 VclPtr
<SvTreeListBox
> pView
;
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
;
60 enum class LBoxFlags
{
63 StartEditTimer
= 0x0004, // MAC only
64 IgnoreSelect
= 0x0008,
66 RemovedEntryInvisible
= 0x0020,
67 RemovedRecalcMostRight
= 0x0040,
68 IgnoreChangedTabs
= 0x0080,
70 EndScrollSetVisSize
= 0x0200,
75 template<> struct typed_flags
<LBoxFlags
> : is_typed_flags
<LBoxFlags
, 0x07fe> {};
78 #define NODE_BMP_TABDIST_NOTVALID -2000000
79 #define FIRST_ENTRY_TAB 1
83 friend class ImpLBSelEng
;
84 friend class SvTreeListBox
;
85 friend class SalInstanceTreeView
;
86 friend class IconView
;
89 SvTreeListEntry
* m_pAnchor
;
90 SvTreeListEntry
* m_pMostRightEntry
;
91 SvLBoxButton
* m_pActiveButton
;
92 SvTreeListEntry
* m_pActiveEntry
;
93 SvLBoxTab
* m_pActiveTab
;
95 VclPtr
<ScrollBar
> m_aHorSBar
;
96 VclPtr
<ScrollBarBox
> m_aScrBarBox
;
98 ::vcl::AccessibleFactoryAccess
101 static Image
* s_pDefCollapsed
;
102 static Image
* s_pDefExpanded
;
103 static oslInterlockedCount s_nImageRefCount
; /// When 0 all static images will be destroyed
108 NodeExpanded
= 0, // node is expanded ( usually a bitmap showing a minus )
109 NodeCollapsed
, // node is collapsed ( usually a bitmap showing a plus )
110 NodeDontKnow
, // don't know the node state
111 EntryDefExpanded
, // default for expanded entries
112 EntryDefCollapsed
, // default for collapsed entries
113 LAST
= EntryDefCollapsed
117 o3tl::enumarray
<ImageType
, Image
>
118 m_aNodeAndEntryImages
;
120 ImpLBSelEng m_aFctSet
;
122 tools::Long m_nNodeBmpWidth
;
123 tools::Long m_nMostRight
;
124 short m_nHorSBarHeight
, m_nVerSBarWidth
;
126 bool m_bUpdateMode
: 1;
127 bool m_bSubLstOpLR
: 1; // open/close sublist with cursor left/right, defaulted with false
128 bool mbForceMakeVisible
;
130 Point m_aEditClickPos
;
133 std::unique_ptr
<comphelper::string::NaturalStringSorter
> m_pStringSorter
;
135 std::vector
< short > m_aContextBmpWidthVector
;
137 DECL_LINK(EditTimerCall
, Timer
*, void);
139 void InvalidateEntriesFrom( tools::Long nY
) const;
140 bool IsLineVisible( tools::Long nY
) const;
141 void KeyLeftRight( tools::Long nDiff
);
143 void DrawNet(vcl::RenderContext
& rRenderContext
);
146 DECL_LINK( ScrollUpDownHdl
, ScrollBar
*, void );
147 DECL_LINK( ScrollLeftRightHdl
, ScrollBar
*, void );
148 DECL_LINK( EndScrollHdl
, ScrollBar
*, void );
150 void SetNodeBmpWidth( const Image
& );
151 void SetNodeBmpTabDistance();
154 SvTreeListEntry
* MakePointVisible( const Point
& rPoint
);
156 void SetAnchorSelection( SvTreeListEntry
* pOld
,
157 SvTreeListEntry
* pNewCursor
);
159 bool ButtonDownCheckCtrl( const MouseEvent
& rMEvt
, SvTreeListEntry
* pEntry
);
160 bool MouseMoveCheckCtrl( const MouseEvent
& rMEvt
, SvTreeListEntry
const * pEntry
);
161 bool ButtonUpCheckCtrl( const MouseEvent
& rMEvt
);
162 bool ButtonDownCheckExpand( const MouseEvent
&, SvTreeListEntry
* );
164 bool EntryReallyHit(SvTreeListEntry
* pEntry
, const Point
& rPos
, tools::Long nLine
);
165 void InitScrollBarBox();
166 SvLBoxTab
* NextTab( SvLBoxTab
const * );
168 void SetMostRight( SvTreeListEntry
* pEntry
);
169 void FindMostRight( SvTreeListEntry
* pParent
);
170 void FindMostRight_Impl( SvTreeListEntry
* pParent
);
171 void NotifyTabsChanged();
173 // if element at cursor can be expanded in general
174 bool IsExpandable() const;
176 static void implInitDefaultNodeImages();
178 void UpdateStringSorter();
180 short UpdateContextBmpWidthVector( SvTreeListEntry
const * pEntry
, short nWidth
);
181 void UpdateContextBmpWidthMax( SvTreeListEntry
const * pEntry
);
182 void UpdateContextBmpWidthVectorFromMovedEntry( SvTreeListEntry
* pEntry
);
185 void CollapseTo(SvTreeListEntry
* pParentToCollapse
);
188 VclPtr
<SvTreeListBox
> m_pView
;
189 VclPtr
<ScrollBar
> m_aVerSBar
;
190 SvTreeListEntry
* m_pCursor
;
191 SvTreeListEntry
* m_pCursorOld
;
192 SvTreeListEntry
* m_pStartEntry
;
193 ImplSVEvent
* m_nCurUserEvent
;
197 bool mbNoAutoCurEntry
; // disable the behavior of automatically selecting a "CurEntry" upon painting the control
198 SelectionEngine m_aSelEng
;
199 sal_uLong m_nVisibleCount
; // Number of lines in control
200 bool m_bInVScrollHdl
: 1;
201 bool m_bSimpleTravel
: 1; // is true if SelectionMode::Single
202 tools::Long m_nNextVerVisSize
;
203 tools::Long m_nNodeBmpTabDistance
; // typical smaller than 0
205 virtual tools::Long
GetEntryLine(const SvTreeListEntry
* pEntry
) const;
206 virtual void CursorDown();
207 virtual void CursorUp();
208 virtual void PageDown( sal_uInt16 nDelta
);
209 virtual void PageUp( sal_uInt16 nDelta
);
210 // set Thumb to FirstEntryToDraw
211 virtual void SyncVerThumb();
212 virtual void AdjustScrollBars( Size
& rSize
);
213 virtual void InvalidateEntry( tools::Long nY
) const;
215 tools::Rectangle
GetVisibleArea() const;
216 void SetCursor( SvTreeListEntry
* pEntry
, bool bForceNoSelect
= false );
217 void PositionScrollBars( Size
& rOSize
, sal_uInt16 nMask
);
218 void FindMostRight();
221 void StopUserEvent();
223 DECL_LINK( MyUserEvent
, void*, void);
226 SvImpLBox( SvTreeListBox
* pView
, SvTreeList
*, WinBits nWinStyle
);
227 virtual ~SvImpLBox();
230 void SetStyle( WinBits i_nWinStyle
);
231 void SetNoAutoCurEntry( bool b
);
232 void SetModel( SvTreeList
* pModel
) { m_pTree
= pModel
;}
234 void EntryInserted( SvTreeListEntry
*);
235 void RemovingEntry( SvTreeListEntry
* pEntry
);
237 void MovingEntry( SvTreeListEntry
* pEntry
);
238 void EntryMoved( SvTreeListEntry
* pEntry
);
239 void TreeInserted( SvTreeListEntry
* pEntry
);
241 void EntryExpanded( SvTreeListEntry
* pEntry
);
242 void EntryCollapsed( SvTreeListEntry
* pEntry
);
243 void CollapsingEntry( SvTreeListEntry
* pEntry
);
244 void EntrySelected( SvTreeListEntry
* pEntry
, bool bSelect
);
246 virtual void Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
);
247 void MouseButtonDown( const MouseEvent
& );
248 void MouseButtonUp( const MouseEvent
& );
249 void MouseMove( const MouseEvent
&);
250 virtual bool KeyInput( const KeyEvent
& );
254 virtual void UpdateAll( bool bInvalidateCompleteView
);
255 void SetEntryHeight();
256 void InvalidateEntry( SvTreeListEntry
* );
257 void RecalcFocusRect();
259 void SelectEntry( SvTreeListEntry
* pEntry
, bool bSelect
);
260 void SetDragDropMode( DragDropMode eDDMode
);
261 void SetSelectionMode( SelectionMode eSelMode
);
263 virtual bool IsEntryInView( SvTreeListEntry
* pEntry
) const;
264 virtual SvTreeListEntry
* GetEntry( const Point
& rPos
) const;
265 // returns last entry, if Pos below last entry
266 virtual SvTreeListEntry
* GetClickedEntry( const Point
& ) const;
267 SvTreeListEntry
* GetCurEntry() const { return m_pCursor
; }
268 void SetCurEntry( SvTreeListEntry
* );
269 virtual Point
GetEntryPosition(const SvTreeListEntry
*) const;
270 void MakeVisible( SvTreeListEntry
* pEntry
, bool bMoveToTop
= false );
271 void ScrollToAbsPos( tools::Long nPos
);
273 void PaintDDCursor(SvTreeListEntry
* pEntry
, bool bShow
);
276 inline Image
& implGetImageLocation( const ImageType _eType
);
278 inline void SetExpandedNodeBmp( const Image
& _rImg
);
279 inline void SetCollapsedNodeBmp( const Image
& _rImg
);
281 inline const Image
& GetExpandedNodeBmp( );
282 inline const Image
& GetCollapsedNodeBmp( );
283 inline const Image
& GetDontKnowNodeBmp( );
285 inline void SetDefaultEntryExpBmp( const Image
& _rImg
);
286 inline void SetDefaultEntryColBmp( const Image
& _rImg
);
287 inline const Image
& GetDefaultEntryExpBmp( );
288 inline const Image
& GetDefaultEntryColBmp( );
290 static const Image
& GetDefaultExpandedNodeImage( );
291 static const Image
& GetDefaultCollapsedNodeImage( );
293 const Size
& GetOutputSize() const { return m_aOutputSize
;}
294 virtual void KeyUp( bool bPageUp
);
295 virtual void KeyDown( bool bPageDown
);
296 void Command( const CommandEvent
& rCEvt
);
299 void DestroyAnchor() { m_pAnchor
=nullptr; m_aSelEng
.Reset(); }
300 void SelAllDestrAnch( bool bSelect
, bool bDestroyAnchor
= true, bool bSingleSelToo
= false );
301 void ShowCursor( bool bShow
);
303 bool RequestHelp( const HelpEvent
& rHEvt
);
304 bool IsNodeButton( const Point
& rPosPixel
, const SvTreeListEntry
* pEntry
) const;
305 void SetUpdateMode( bool bMode
);
306 bool GetUpdateMode() const { return m_bUpdateMode
; }
307 tools::Rectangle
GetClipRegionRect() const;
308 bool HasHorScrollBar() const { return m_aHorSBar
->IsVisible(); }
309 void CallEventListeners( VclEventId nEvent
, void* pData
= nullptr );
311 bool IsSelectable( const SvTreeListEntry
* pEntry
) const;
312 void SetForceMakeVisible(bool bEnable
) { mbForceMakeVisible
= bEnable
; }
314 // tdf#143114 allow to ask if CaptureOnButton is active
315 // (MouseButtonDown hit on SvLBoxButton, CaptureMouse() active)
316 bool IsCaptureOnButtonActive() const;
319 inline bool SvImpLBox::IsCaptureOnButtonActive() const
321 return nullptr != m_pActiveButton
&& nullptr != m_pActiveEntry
;
324 inline Image
& SvImpLBox::implGetImageLocation( const ImageType _eType
)
326 return m_aNodeAndEntryImages
[_eType
];
329 inline void SvImpLBox::SetExpandedNodeBmp( const Image
& rImg
)
331 implGetImageLocation( ImageType::NodeExpanded
) = rImg
;
332 SetNodeBmpWidth( rImg
);
335 inline void SvImpLBox::SetCollapsedNodeBmp( const Image
& rImg
)
337 implGetImageLocation( ImageType::NodeCollapsed
) = rImg
;
338 SetNodeBmpWidth( rImg
);
341 inline const Image
& SvImpLBox::GetDontKnowNodeBmp( )
343 return implGetImageLocation( ImageType::NodeDontKnow
);
346 inline const Image
& SvImpLBox::GetExpandedNodeBmp( )
348 return implGetImageLocation( ImageType::NodeExpanded
);
351 inline const Image
& SvImpLBox::GetCollapsedNodeBmp( )
353 return implGetImageLocation( ImageType::NodeCollapsed
);
356 inline void SvImpLBox::SetDefaultEntryExpBmp( const Image
& _rImg
)
358 implGetImageLocation( ImageType::EntryDefExpanded
) = _rImg
;
361 inline void SvImpLBox::SetDefaultEntryColBmp( const Image
& _rImg
)
363 implGetImageLocation( ImageType::EntryDefCollapsed
) = _rImg
;
366 inline const Image
& SvImpLBox::GetDefaultEntryExpBmp( )
368 return implGetImageLocation( ImageType::EntryDefExpanded
);
371 inline const Image
& SvImpLBox::GetDefaultEntryColBmp( )
373 return implGetImageLocation( ImageType::EntryDefCollapsed
);
376 inline Point
SvImpLBox::GetEntryPosition(const SvTreeListEntry
* pEntry
) const
378 return Point(0, GetEntryLine(pEntry
));
381 inline bool SvImpLBox::IsLineVisible( tools::Long nY
) const
384 if ( nY
< 0 || nY
>= m_aOutputSize
.Height() )
389 inline void SvImpLBox::TreeInserted( SvTreeListEntry
* pInsTree
)
391 EntryInserted( pInsTree
);
394 #endif // INCLUDED_VCL_SOURCE_INC_SVIMPBOX_HXX
396 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */