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/seleng.hxx>
24 #include <vcl/idle.hxx>
25 #include <vcl/image.hxx>
26 #include <vcl/svtaccessiblefactory.hxx>
27 #include <vcl/vclevent.hxx>
28 #include <vcl/toolkit/scrbar.hxx>
29 #include <vcl/toolkit/treelistbox.hxx>
30 #include <o3tl/enumarray.hxx>
37 class SvTreeListEntry
;
38 namespace comphelper::string
{ class NaturalStringSorter
; }
40 class ImpLBSelEng final
: public FunctionSet
43 VclPtr
<SvTreeListBox
> pView
;
46 ImpLBSelEng( SvImpLBox
* pImp
, SvTreeListBox
* pView
);
47 virtual ~ImpLBSelEng() override
;
48 void BeginDrag() override
;
49 void CreateAnchor() override
;
50 void DestroyAnchor() override
;
51 void SetCursorAtPoint( const Point
& rPoint
,
52 bool bDontSelectAtCursor
=false ) override
;
53 bool IsSelectionAtPoint( const Point
& rPoint
) override
;
54 void DeselectAtPoint( const Point
& rPoint
) override
;
55 void DeselectAll() override
;
59 enum class LBoxFlags
{
62 StartEditTimer
= 0x0004, // MAC only
63 IgnoreSelect
= 0x0008,
65 RemovedEntryInvisible
= 0x0020,
66 RemovedRecalcMostRight
= 0x0040,
67 IgnoreChangedTabs
= 0x0080,
69 EndScrollSetVisSize
= 0x0200,
74 template<> struct typed_flags
<LBoxFlags
> : is_typed_flags
<LBoxFlags
, 0x07fe> {};
77 #define NODE_BMP_TABDIST_NOTVALID -2000000
78 #define FIRST_ENTRY_TAB 1
82 friend class ImpLBSelEng
;
83 friend class SvTreeListBox
;
84 friend class SalInstanceTreeView
;
85 friend class IconView
;
88 SvTreeListEntry
* m_pAnchor
;
89 SvTreeListEntry
* m_pMostRightEntry
;
90 SvLBoxButton
* m_pActiveButton
;
91 SvTreeListEntry
* m_pActiveEntry
;
92 SvLBoxTab
* m_pActiveTab
;
94 VclPtr
<ScrollBarBox
> m_aScrBarBox
;
96 ::vcl::AccessibleFactoryAccess
99 static Image
* s_pDefCollapsed
;
100 static Image
* s_pDefExpanded
;
101 static oslInterlockedCount s_nImageRefCount
; /// When 0 all static images will be destroyed
106 NodeExpanded
= 0, // node is expanded ( usually a bitmap showing a minus )
107 NodeCollapsed
, // node is collapsed ( usually a bitmap showing a plus )
108 EntryDefExpanded
, // default for expanded entries
109 EntryDefCollapsed
, // default for collapsed entries
110 LAST
= EntryDefCollapsed
114 o3tl::enumarray
<ImageType
, Image
>
115 m_aNodeAndEntryImages
;
117 ImpLBSelEng m_aFctSet
;
119 tools::Long m_nNodeBmpWidth
;
120 tools::Long m_nMostRight
;
121 short m_nHorSBarHeight
, m_nVerSBarWidth
;
123 bool m_bUpdateMode
: 1;
124 bool m_bSubLstOpLR
: 1; // open/close sublist with cursor left/right, defaulted with false
125 bool mbForceMakeVisible
;
127 Point m_aEditClickPos
;
130 std::unique_ptr
<comphelper::string::NaturalStringSorter
> m_pStringSorter
;
132 std::vector
< short > m_aContextBmpWidthVector
;
134 DECL_LINK(EditTimerCall
, Timer
*, void);
136 void InvalidateEntriesFrom( tools::Long nY
) const;
137 bool IsLineVisible( tools::Long nY
) const;
138 void KeyLeftRight( tools::Long nDiff
);
140 void DrawNet(vcl::RenderContext
& rRenderContext
);
143 DECL_LINK( ScrollUpDownHdl
, ScrollBar
*, void );
144 DECL_LINK( ScrollLeftRightHdl
, ScrollBar
*, void );
145 DECL_LINK( EndScrollHdl
, ScrollBar
*, void );
147 void SetNodeBmpWidth( const Image
& );
148 void SetNodeBmpTabDistance();
151 SvTreeListEntry
* MakePointVisible( const Point
& rPoint
);
153 void SetAnchorSelection( SvTreeListEntry
* pOld
,
154 SvTreeListEntry
* pNewCursor
);
156 bool ButtonDownCheckCtrl( const MouseEvent
& rMEvt
, SvTreeListEntry
* pEntry
);
157 bool MouseMoveCheckCtrl( const MouseEvent
& rMEvt
, SvTreeListEntry
const * pEntry
);
158 bool ButtonUpCheckCtrl( const MouseEvent
& rMEvt
);
159 bool ButtonDownCheckExpand( const MouseEvent
&, SvTreeListEntry
* );
161 bool EntryReallyHit(SvTreeListEntry
* pEntry
, const Point
& rPos
, tools::Long nLine
);
162 void InitScrollBarBox();
163 SvLBoxTab
* NextTab( SvLBoxTab
const * );
165 void SetMostRight( SvTreeListEntry
* pEntry
);
166 void FindMostRight( SvTreeListEntry
* pParent
);
167 void FindMostRight_Impl( SvTreeListEntry
* pParent
);
168 void NotifyTabsChanged();
170 // if element at cursor can be expanded in general
171 bool IsExpandable() const;
173 static void implInitDefaultNodeImages();
175 void UpdateStringSorter();
177 short UpdateContextBmpWidthVector( SvTreeListEntry
const * pEntry
, short nWidth
);
178 void UpdateContextBmpWidthMax( SvTreeListEntry
const * pEntry
);
179 void UpdateContextBmpWidthVectorFromMovedEntry( SvTreeListEntry
* pEntry
);
182 void CollapseTo(SvTreeListEntry
* pParentToCollapse
);
185 VclPtr
<SvTreeListBox
> m_pView
;
186 VclPtr
<ScrollBar
> m_aHorSBar
;
187 VclPtr
<ScrollBar
> m_aVerSBar
;
188 SvTreeListEntry
* m_pCursor
;
189 SvTreeListEntry
* m_pCursorOld
;
190 SvTreeListEntry
* m_pStartEntry
;
191 ImplSVEvent
* m_nCurUserEvent
;
195 bool mbNoAutoCurEntry
; // disable the behavior of automatically selecting a "CurEntry" upon painting the control
196 SelectionEngine m_aSelEng
;
197 sal_uLong m_nVisibleCount
; // Number of lines in control
198 bool m_bInVScrollHdl
: 1;
199 bool m_bSimpleTravel
: 1; // is true if SelectionMode::Single
200 tools::Long m_nNextVerVisSize
;
201 tools::Long m_nNodeBmpTabDistance
; // typical smaller than 0
203 virtual tools::Long
GetEntryLine(const SvTreeListEntry
* pEntry
) const;
204 virtual void CursorDown();
205 virtual void CursorUp();
206 virtual void PageDown( sal_uInt16 nDelta
);
207 virtual void PageUp( sal_uInt16 nDelta
);
208 // set Thumb to FirstEntryToDraw
209 virtual void SyncVerThumb();
210 virtual void AdjustScrollBars( Size
& rSize
);
211 virtual void InvalidateEntry( tools::Long nY
) const;
213 tools::Rectangle
GetVisibleArea() const;
214 void SetCursor( SvTreeListEntry
* pEntry
, bool bForceNoSelect
= false );
215 void PositionScrollBars( Size
& rOSize
, sal_uInt16 nMask
);
216 void FindMostRight();
219 void StopUserEvent();
221 DECL_LINK( MyUserEvent
, void*, void);
224 SvImpLBox( SvTreeListBox
* pView
, SvTreeList
*, WinBits nWinStyle
);
225 virtual ~SvImpLBox();
228 void SetStyle( WinBits i_nWinStyle
);
229 void SetNoAutoCurEntry( bool b
);
230 void SetModel( SvTreeList
* pModel
) { m_pTree
= pModel
;}
232 void EntryInserted( SvTreeListEntry
*);
233 void RemovingEntry( SvTreeListEntry
* pEntry
);
235 void MovingEntry( SvTreeListEntry
* pEntry
);
236 void EntryMoved( SvTreeListEntry
* pEntry
);
237 void TreeInserted( SvTreeListEntry
* pEntry
);
239 void EntryExpanded( SvTreeListEntry
* pEntry
);
240 void EntryCollapsed( SvTreeListEntry
* pEntry
);
241 void CollapsingEntry( SvTreeListEntry
* pEntry
);
242 void EntrySelected( SvTreeListEntry
* pEntry
, bool bSelect
);
244 virtual void Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
);
245 void MouseButtonDown( const MouseEvent
& );
246 void MouseButtonUp( const MouseEvent
& );
247 void MouseMove( const MouseEvent
&);
248 virtual bool KeyInput( const KeyEvent
& );
252 virtual void UpdateAll();
253 void SetEntryHeight();
254 void InvalidateEntry( SvTreeListEntry
* );
255 void RecalcFocusRect();
257 void SelectEntry( SvTreeListEntry
* pEntry
, bool bSelect
);
258 void SetDragDropMode( DragDropMode eDDMode
);
259 void SetSelectionMode( SelectionMode eSelMode
);
261 virtual bool IsEntryInView( SvTreeListEntry
* pEntry
) const;
262 virtual SvTreeListEntry
* GetEntry( const Point
& rPos
) const;
263 // returns last entry, if Pos below last entry
264 virtual SvTreeListEntry
* GetClickedEntry( const Point
& ) const;
265 SvTreeListEntry
* GetCurEntry() const { return m_pCursor
; }
266 void SetCurEntry( SvTreeListEntry
* );
267 virtual Point
GetEntryPosition(const SvTreeListEntry
*) const;
268 void MakeVisible( SvTreeListEntry
* pEntry
, bool bMoveToTop
= false );
269 void ScrollToAbsPos( tools::Long nPos
);
271 void PaintDDCursor(SvTreeListEntry
* pEntry
, bool bShow
);
274 inline Image
& implGetImageLocation( const ImageType _eType
);
276 inline void SetExpandedNodeBmp( const Image
& _rImg
);
277 inline void SetCollapsedNodeBmp( const Image
& _rImg
);
279 inline const Image
& GetExpandedNodeBmp( );
280 inline const Image
& GetCollapsedNodeBmp( );
282 inline void SetDefaultEntryExpBmp( const Image
& _rImg
);
283 inline void SetDefaultEntryColBmp( const Image
& _rImg
);
284 inline const Image
& GetDefaultEntryExpBmp( );
285 inline const Image
& GetDefaultEntryColBmp( );
287 static const Image
& GetDefaultExpandedNodeImage( );
288 static const Image
& GetDefaultCollapsedNodeImage( );
290 const Size
& GetOutputSize() const { return m_aOutputSize
;}
291 virtual void KeyUp( bool bPageUp
);
292 virtual void KeyDown( bool bPageDown
);
293 void Command( const CommandEvent
& rCEvt
);
296 void DestroyAnchor() { m_pAnchor
=nullptr; m_aSelEng
.Reset(); }
297 void SelAllDestrAnch( bool bSelect
, bool bDestroyAnchor
= true, bool bSingleSelToo
= false );
298 void ShowCursor( bool bShow
);
300 bool RequestHelp( const HelpEvent
& rHEvt
);
301 bool IsNodeButton( const Point
& rPosPixel
, const SvTreeListEntry
* pEntry
) const;
302 void SetUpdateMode( bool bMode
);
303 bool GetUpdateMode() const { return m_bUpdateMode
; }
304 tools::Rectangle
GetClipRegionRect() const;
305 bool HasHorScrollBar() const { return m_aHorSBar
->IsVisible(); }
306 void CallEventListeners( VclEventId nEvent
, void* pData
= nullptr );
308 bool IsSelectable( const SvTreeListEntry
* pEntry
) const;
309 void SetForceMakeVisible(bool bEnable
) { mbForceMakeVisible
= bEnable
; }
311 // tdf#143114 allow to ask if CaptureOnButton is active
312 // (MouseButtonDown hit on SvLBoxButton, CaptureMouse() active)
313 bool IsCaptureOnButtonActive() const;
316 inline bool SvImpLBox::IsCaptureOnButtonActive() const
318 return nullptr != m_pActiveButton
&& nullptr != m_pActiveEntry
;
321 inline Image
& SvImpLBox::implGetImageLocation( const ImageType _eType
)
323 return m_aNodeAndEntryImages
[_eType
];
326 inline void SvImpLBox::SetExpandedNodeBmp( const Image
& rImg
)
328 implGetImageLocation( ImageType::NodeExpanded
) = rImg
;
329 SetNodeBmpWidth( rImg
);
332 inline void SvImpLBox::SetCollapsedNodeBmp( const Image
& rImg
)
334 implGetImageLocation( ImageType::NodeCollapsed
) = rImg
;
335 SetNodeBmpWidth( rImg
);
338 inline const Image
& SvImpLBox::GetExpandedNodeBmp( )
340 return implGetImageLocation( ImageType::NodeExpanded
);
343 inline const Image
& SvImpLBox::GetCollapsedNodeBmp( )
345 return implGetImageLocation( ImageType::NodeCollapsed
);
348 inline void SvImpLBox::SetDefaultEntryExpBmp( const Image
& _rImg
)
350 implGetImageLocation( ImageType::EntryDefExpanded
) = _rImg
;
353 inline void SvImpLBox::SetDefaultEntryColBmp( const Image
& _rImg
)
355 implGetImageLocation( ImageType::EntryDefCollapsed
) = _rImg
;
358 inline const Image
& SvImpLBox::GetDefaultEntryExpBmp( )
360 return implGetImageLocation( ImageType::EntryDefExpanded
);
363 inline const Image
& SvImpLBox::GetDefaultEntryColBmp( )
365 return implGetImageLocation( ImageType::EntryDefCollapsed
);
368 inline Point
SvImpLBox::GetEntryPosition(const SvTreeListEntry
* pEntry
) const
370 return Point(0, GetEntryLine(pEntry
));
373 inline bool SvImpLBox::IsLineVisible( tools::Long nY
) const
376 if ( nY
< 0 || nY
>= m_aOutputSize
.Height() )
381 inline void SvImpLBox::TreeInserted( SvTreeListEntry
* pInsTree
)
383 EntryInserted( pInsTree
);
386 #endif // INCLUDED_VCL_SOURCE_INC_SVIMPBOX_HXX
388 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */