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/treelistbox.hxx>
31 #include <o3tl/enumarray.hxx>
38 class SvTreeListEntry
;
43 class NaturalStringSorter
;
47 class ImpLBSelEng
: public FunctionSet
50 VclPtr
<SvTreeListBox
> pView
;
53 ImpLBSelEng( SvImpLBox
* pImp
, SvTreeListBox
* pView
);
54 virtual ~ImpLBSelEng() override
;
55 void BeginDrag() override
;
56 void CreateAnchor() override
;
57 void DestroyAnchor() override
;
58 void SetCursorAtPoint( const Point
& rPoint
,
59 bool bDontSelectAtCursor
=false ) override
;
60 bool IsSelectionAtPoint( const Point
& rPoint
) override
;
61 void DeselectAtPoint( const Point
& rPoint
) override
;
62 void DeselectAll() override
;
66 enum class LBoxFlags
{
70 StartEditTimer
= 0x0004, // MAC only
71 IgnoreSelect
= 0x0008,
73 RemovedEntryInvisible
= 0x0020,
74 RemovedRecalcMostRight
= 0x0040,
75 IgnoreChangedTabs
= 0x0080,
77 EndScrollSetVisSize
= 0x0200,
82 template<> struct typed_flags
<LBoxFlags
> : is_typed_flags
<LBoxFlags
, 0x07ff> {};
85 #define NODE_BMP_TABDIST_NOTVALID -2000000
86 #define FIRST_ENTRY_TAB 1
90 friend class ImpLBSelEng
;
91 friend class SvTreeListBox
;
92 friend class SalInstanceTreeView
;
93 friend class IconView
;
96 SvTreeListEntry
* m_pAnchor
;
97 SvTreeListEntry
* m_pMostRightEntry
;
98 SvLBoxButton
* m_pActiveButton
;
99 SvTreeListEntry
* m_pActiveEntry
;
100 SvLBoxTab
* m_pActiveTab
;
102 VclPtr
<ScrollBar
> m_aHorSBar
;
103 VclPtr
<ScrollBarBox
> m_aScrBarBox
;
105 ::vcl::AccessibleFactoryAccess
108 static Image
* s_pDefCollapsed
;
109 static Image
* s_pDefExpanded
;
110 static oslInterlockedCount s_nImageRefCount
; /// When 0 all static images will be destroyed
115 NodeExpanded
= 0, // node is expanded ( usually a bitmap showing a minus )
116 NodeCollapsed
, // node is collapsed ( usually a bitmap showing a plus )
117 NodeDontKnow
, // don't know the node state
118 EntryDefExpanded
, // default for expanded entries
119 EntryDefCollapsed
, // default for collapsed entries
120 LAST
= EntryDefCollapsed
124 o3tl::enumarray
<ImageType
, Image
>
125 m_aNodeAndEntryImages
;
127 ImpLBSelEng m_aFctSet
;
128 Idle m_aAsyncBeginDragIdle
;
129 Point m_aAsyncBeginDragPos
;
131 long m_nNodeBmpWidth
;
133 short m_nHorSBarHeight
, m_nVerSBarWidth
;
134 sal_uInt16 m_nCurTabPos
;
136 bool m_bUpdateMode
: 1;
137 bool m_bAsyncBeginDrag
: 1;
138 bool m_bSubLstOpRet
: 1; // open/close sublist with return/enter, defaulted with false
139 bool m_bSubLstOpLR
: 1; // open/close sublist with cursor left/right, defaulted with false
140 bool m_bSubLstOpDblClick
: 1; // open/close sublist with mouse double click, defaulted with true
141 bool m_bContextMenuHandling
: 1;
142 bool m_bIsCellFocusEnabled
: 1;
143 bool m_bAreChildrenTransient
;
144 bool mbForceMakeVisible
;
146 Point m_aEditClickPos
;
149 std::unique_ptr
<comphelper::string::NaturalStringSorter
> m_pStringSorter
;
151 std::vector
< short > m_aContextBmpWidthVector
;
153 DECL_LINK(EditTimerCall
, Timer
*, void);
155 DECL_LINK( BeginDragHdl
, Timer
*, void );
157 void InvalidateEntriesFrom( long nY
) const;
158 bool IsLineVisible( long nY
) const;
159 void KeyLeftRight( long nDiff
);
161 void DrawNet(vcl::RenderContext
& rRenderContext
);
164 DECL_LINK( ScrollUpDownHdl
, ScrollBar
*, void );
165 DECL_LINK( ScrollLeftRightHdl
, ScrollBar
*, void );
166 DECL_LINK( EndScrollHdl
, ScrollBar
*, void );
168 void SetNodeBmpWidth( const Image
& );
169 void SetNodeBmpTabDistance();
172 SvTreeListEntry
* MakePointVisible( const Point
& rPoint
);
174 void SetAnchorSelection( SvTreeListEntry
* pOld
,
175 SvTreeListEntry
* pNewCursor
);
177 bool ButtonDownCheckCtrl( const MouseEvent
& rMEvt
, SvTreeListEntry
* pEntry
);
178 bool MouseMoveCheckCtrl( const MouseEvent
& rMEvt
, SvTreeListEntry
const * pEntry
);
179 bool ButtonUpCheckCtrl( const MouseEvent
& rMEvt
);
180 bool ButtonDownCheckExpand( const MouseEvent
&, SvTreeListEntry
* );
182 bool EntryReallyHit(SvTreeListEntry
* pEntry
, const Point
& rPos
, long nLine
);
183 void InitScrollBarBox();
184 SvLBoxTab
* NextTab( SvLBoxTab
const * );
186 bool SetMostRight( SvTreeListEntry
* pEntry
);
187 void FindMostRight( SvTreeListEntry
* pParent
, SvTreeListEntry
* EntryToIgnore
);
188 void FindMostRight_Impl( SvTreeListEntry
* pParent
,SvTreeListEntry
* EntryToIgnore
);
189 void NotifyTabsChanged();
191 // if element at cursor can be expanded in general
192 bool IsExpandable() const;
194 static void implInitDefaultNodeImages();
196 void UpdateStringSorter();
198 short UpdateContextBmpWidthVector( SvTreeListEntry
const * pEntry
, short nWidth
);
199 void UpdateContextBmpWidthMax( SvTreeListEntry
const * pEntry
);
200 void UpdateContextBmpWidthVectorFromMovedEntry( SvTreeListEntry
* pEntry
);
202 void CalcCellFocusRect( SvTreeListEntry
const * pEntry
, tools::Rectangle
& rRect
);
204 bool AreChildrenTransient() const { return m_bAreChildrenTransient
; }
207 void CollapseTo(SvTreeListEntry
* pParentToCollapse
);
210 VclPtr
<SvTreeListBox
> m_pView
;
211 VclPtr
<ScrollBar
> m_aVerSBar
;
212 SvTreeListEntry
* m_pCursor
;
213 SvTreeListEntry
* m_pStartEntry
;
214 ImplSVEvent
* m_nCurUserEvent
;
218 bool mbNoAutoCurEntry
; // disable the behavior of automatically selecting a "CurEntry" upon painting the control
219 SelectionEngine m_aSelEng
;
220 sal_uLong m_nVisibleCount
; // Number of lines in control
221 bool m_bInVScrollHdl
: 1;
222 bool m_bSimpleTravel
: 1; // is true if SelectionMode::Single
223 long m_nNextVerVisSize
;
224 long m_nNodeBmpTabDistance
; // typical smaller than 0
226 virtual long GetEntryLine( SvTreeListEntry
* pEntry
) const;
227 virtual void CursorDown();
228 virtual void CursorUp();
229 virtual void PageDown( sal_uInt16 nDelta
);
230 virtual void PageUp( sal_uInt16 nDelta
);
231 // set Thumb to FirstEntryToDraw
232 virtual void SyncVerThumb();
233 virtual void AdjustScrollBars( Size
& rSize
);
234 virtual void InvalidateEntry( long nY
) const;
236 tools::Rectangle
GetVisibleArea() const;
237 void SetCursor( SvTreeListEntry
* pEntry
, bool bForceNoSelect
= false );
240 void PositionScrollBars( Size
& rOSize
, sal_uInt16 nMask
);
241 void FindMostRight( SvTreeListEntry
const * EntryToIgnore
);
244 void StopUserEvent();
246 DECL_LINK( MyUserEvent
, void*, void);
249 SvImpLBox( SvTreeListBox
* pView
, SvTreeList
*, WinBits nWinStyle
);
250 virtual ~SvImpLBox();
253 void SetStyle( WinBits i_nWinStyle
);
254 void SetNoAutoCurEntry( bool b
);
255 void SetModel( SvTreeList
* pModel
) { m_pTree
= pModel
;}
257 void EntryInserted( SvTreeListEntry
*);
258 void RemovingEntry( SvTreeListEntry
* pEntry
);
260 void MovingEntry( SvTreeListEntry
* pEntry
);
261 void EntryMoved( SvTreeListEntry
* pEntry
);
262 void TreeInserted( SvTreeListEntry
* pEntry
);
264 void EntryExpanded( SvTreeListEntry
* pEntry
);
265 void EntryCollapsed( SvTreeListEntry
* pEntry
);
266 void CollapsingEntry( SvTreeListEntry
* pEntry
);
267 void EntrySelected( SvTreeListEntry
* pEntry
, bool bSelect
);
269 virtual void Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
);
270 void MouseButtonDown( const MouseEvent
& );
271 void MouseButtonUp( const MouseEvent
& );
272 void MouseMove( const MouseEvent
&);
273 virtual bool KeyInput( const KeyEvent
& );
277 virtual void UpdateAll( bool bInvalidateCompleteView
);
278 void SetEntryHeight();
279 void InvalidateEntry( SvTreeListEntry
* );
280 void RecalcFocusRect();
282 void SelectEntry( SvTreeListEntry
* pEntry
, bool bSelect
);
283 void SetDragDropMode( DragDropMode eDDMode
);
284 void SetSelectionMode( SelectionMode eSelMode
);
286 SvTreeListEntry
* GetCurrentEntry() const { return m_pCursor
; }
287 virtual bool IsEntryInView( SvTreeListEntry
* pEntry
) const;
288 virtual SvTreeListEntry
* GetEntry( const Point
& rPos
) const;
289 // returns last entry, if Pos below last entry
290 virtual SvTreeListEntry
* GetClickedEntry( const Point
& ) const;
291 SvTreeListEntry
* GetCurEntry() const { return m_pCursor
; }
292 void SetCurEntry( SvTreeListEntry
* );
293 virtual Point
GetEntryPosition( SvTreeListEntry
* ) const;
294 void MakeVisible( SvTreeListEntry
* pEntry
, bool bMoveToTop
= false );
295 void ScrollToAbsPos( long nPos
);
297 void PaintDDCursor(SvTreeListEntry
* pEntry
, bool bShow
);
300 inline Image
& implGetImageLocation( const ImageType _eType
);
302 inline void SetExpandedNodeBmp( const Image
& _rImg
);
303 inline void SetCollapsedNodeBmp( const Image
& _rImg
);
305 inline const Image
& GetExpandedNodeBmp( );
306 inline const Image
& GetCollapsedNodeBmp( );
307 inline const Image
& GetDontKnowNodeBmp( );
309 inline void SetDefaultEntryExpBmp( const Image
& _rImg
);
310 inline void SetDefaultEntryColBmp( const Image
& _rImg
);
311 inline const Image
& GetDefaultEntryExpBmp( );
312 inline const Image
& GetDefaultEntryColBmp( );
314 static const Image
& GetDefaultExpandedNodeImage( );
315 static const Image
& GetDefaultCollapsedNodeImage( );
317 const Size
& GetOutputSize() const { return m_aOutputSize
;}
318 virtual void KeyUp( bool bPageUp
);
319 virtual void KeyDown( bool bPageDown
);
320 void Command( const CommandEvent
& rCEvt
);
323 void DestroyAnchor() { m_pAnchor
=nullptr; m_aSelEng
.Reset(); }
324 void SelAllDestrAnch( bool bSelect
, bool bDestroyAnchor
= true, bool bSingleSelToo
= false );
325 void ShowCursor( bool bShow
);
327 bool RequestHelp( const HelpEvent
& rHEvt
);
329 bool IsNodeButton( const Point
& rPosPixel
, SvTreeListEntry
* pEntry
) const;
330 void EnableAsyncDrag( bool b
) { m_bAsyncBeginDrag
= b
; }
331 void SetUpdateMode( bool bMode
);
332 bool GetUpdateMode() const { return m_bUpdateMode
; }
333 tools::Rectangle
GetClipRegionRect() const;
334 bool HasHorScrollBar() const { return m_aHorSBar
->IsVisible(); }
335 void ShowFocusRect( const SvTreeListEntry
* pEntry
);
336 void CallEventListeners( VclEventId nEvent
, void* pData
= nullptr );
338 /** Enables, that one cell of a tablistbox entry can be focused */
339 bool IsCellFocusEnabled() const { return m_bIsCellFocusEnabled
; }
340 void EnableCellFocus() { m_bIsCellFocusEnabled
= true; }
341 bool SetCurrentTabPos( sal_uInt16 _nNewPos
);
342 sal_uInt16
GetCurrentTabPos() const { return m_nCurTabPos
; }
344 bool IsSelectable( const SvTreeListEntry
* pEntry
);
345 void SetForceMakeVisible(bool bEnable
) { mbForceMakeVisible
= bEnable
; }
348 inline Image
& SvImpLBox::implGetImageLocation( const ImageType _eType
)
350 return m_aNodeAndEntryImages
[_eType
];
353 inline void SvImpLBox::SetExpandedNodeBmp( const Image
& rImg
)
355 implGetImageLocation( ImageType::NodeExpanded
) = rImg
;
356 SetNodeBmpWidth( rImg
);
359 inline void SvImpLBox::SetCollapsedNodeBmp( const Image
& rImg
)
361 implGetImageLocation( ImageType::NodeCollapsed
) = rImg
;
362 SetNodeBmpWidth( rImg
);
365 inline const Image
& SvImpLBox::GetDontKnowNodeBmp( )
367 return implGetImageLocation( ImageType::NodeDontKnow
);
370 inline const Image
& SvImpLBox::GetExpandedNodeBmp( )
372 return implGetImageLocation( ImageType::NodeExpanded
);
375 inline const Image
& SvImpLBox::GetCollapsedNodeBmp( )
377 return implGetImageLocation( ImageType::NodeCollapsed
);
380 inline void SvImpLBox::SetDefaultEntryExpBmp( const Image
& _rImg
)
382 implGetImageLocation( ImageType::EntryDefExpanded
) = _rImg
;
385 inline void SvImpLBox::SetDefaultEntryColBmp( const Image
& _rImg
)
387 implGetImageLocation( ImageType::EntryDefCollapsed
) = _rImg
;
390 inline const Image
& SvImpLBox::GetDefaultEntryExpBmp( )
392 return implGetImageLocation( ImageType::EntryDefExpanded
);
395 inline const Image
& SvImpLBox::GetDefaultEntryColBmp( )
397 return implGetImageLocation( ImageType::EntryDefCollapsed
);
400 inline Point
SvImpLBox::GetEntryPosition( SvTreeListEntry
* pEntry
) const
402 return Point( 0, GetEntryLine( pEntry
) );
405 inline bool SvImpLBox::IsLineVisible( long nY
) const
408 if ( nY
< 0 || nY
>= m_aOutputSize
.Height() )
413 inline void SvImpLBox::TreeInserted( SvTreeListEntry
* pInsTree
)
415 EntryInserted( pInsTree
);
418 #endif // INCLUDED_VCL_SOURCE_INC_SVIMPBOX_HXX
420 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */