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
88 class VCL_DLLPUBLIC SvImpLBox
90 friend class ImpLBSelEng
;
91 friend class SvTreeListBox
;
92 friend class SalInstanceTreeView
;
93 friend class IconView
;
96 SvTreeListEntry
* pAnchor
;
97 SvTreeListEntry
* pMostRightEntry
;
98 SvLBoxButton
* pActiveButton
;
99 SvTreeListEntry
* pActiveEntry
;
100 SvLBoxTab
* pActiveTab
;
102 VclPtr
<ScrollBar
> aHorSBar
;
103 VclPtr
<ScrollBarBox
> 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
;
128 Idle aAsyncBeginDragIdle
;
129 Point aAsyncBeginDragPos
;
133 short nHorSBarHeight
, nVerSBarWidth
;
134 sal_uInt16 nCurTabPos
;
136 bool bUpdateMode
: 1;
137 bool bAsyncBeginDrag
: 1;
138 bool bSubLstOpRet
: 1; // open/close sublist with return/enter, defaulted with false
139 bool bSubLstOpLR
: 1; // open/close sublist with cursor left/right, defaulted with false
140 bool bSubLstOpDblClick
: 1; // open/close sublist with mouse double click, defaulted with true
141 bool bContextMenuHandling
: 1;
142 bool bIsCellFocusEnabled
: 1;
143 bool bAreChildrenTransient
;
144 bool mbForceMakeVisible
;
149 std::unique_ptr
<comphelper::string::NaturalStringSorter
> m_pStringSorter
;
151 std::vector
< short > 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 bAreChildrenTransient
; }
205 void SetChildrenNotTransient() { bAreChildrenTransient
= false; }
208 VclPtr
<SvTreeListBox
> pView
;
209 VclPtr
<ScrollBar
> aVerSBar
;
210 SvTreeListEntry
* pCursor
;
211 SvTreeListEntry
* pStartEntry
;
212 ImplSVEvent
* nCurUserEvent
;
216 bool mbNoAutoCurEntry
; // disable the behavior of automatically selecting a "CurEntry" upon painting the control
217 SelectionEngine aSelEng
;
218 sal_uLong nVisibleCount
; // Number of lines in control
219 bool bInVScrollHdl
: 1;
220 bool bSimpleTravel
: 1; // is true if SelectionMode::Single
221 long nNextVerVisSize
;
222 long nNodeBmpTabDistance
; // typical smaller than 0
224 virtual long GetEntryLine( SvTreeListEntry
* pEntry
) const;
225 virtual void CursorDown();
226 virtual void CursorUp();
227 virtual void PageDown( sal_uInt16 nDelta
);
228 virtual void PageUp( sal_uInt16 nDelta
);
229 // set Thumb to FirstEntryToDraw
230 virtual void SyncVerThumb();
231 virtual void AdjustScrollBars( Size
& rSize
);
232 virtual void InvalidateEntry( long nY
) const;
234 tools::Rectangle
GetVisibleArea() const;
235 void SetCursor( SvTreeListEntry
* pEntry
, bool bForceNoSelect
= false );
238 void PositionScrollBars( Size
& rOSize
, sal_uInt16 nMask
);
239 void FindMostRight( SvTreeListEntry
const * EntryToIgnore
);
242 void StopUserEvent();
244 DECL_LINK( MyUserEvent
, void*, void);
247 SvImpLBox( SvTreeListBox
* pView
, SvTreeList
*, WinBits nWinStyle
);
248 virtual ~SvImpLBox();
251 void SetStyle( WinBits i_nWinStyle
);
252 void SetNoAutoCurEntry( bool b
);
253 void SetModel( SvTreeList
* pModel
) { pTree
= pModel
;}
255 void EntryInserted( SvTreeListEntry
*);
256 void RemovingEntry( SvTreeListEntry
* pEntry
);
258 void MovingEntry( SvTreeListEntry
* pEntry
);
259 void EntryMoved( SvTreeListEntry
* pEntry
);
260 void TreeInserted( SvTreeListEntry
* pEntry
);
262 void EntryExpanded( SvTreeListEntry
* pEntry
);
263 void EntryCollapsed( SvTreeListEntry
* pEntry
);
264 void CollapsingEntry( SvTreeListEntry
* pEntry
);
265 void EntrySelected( SvTreeListEntry
* pEntry
, bool bSelect
);
267 virtual void Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
);
268 void MouseButtonDown( const MouseEvent
& );
269 void MouseButtonUp( const MouseEvent
& );
270 void MouseMove( const MouseEvent
&);
271 virtual bool KeyInput( const KeyEvent
& );
275 virtual void UpdateAll( bool bInvalidateCompleteView
);
276 void SetEntryHeight();
277 void InvalidateEntry( SvTreeListEntry
* );
278 void RecalcFocusRect();
280 void SelectEntry( SvTreeListEntry
* pEntry
, bool bSelect
);
281 void SetDragDropMode( DragDropMode eDDMode
);
282 void SetSelectionMode( SelectionMode eSelMode
);
284 SvTreeListEntry
* GetCurrentEntry() const { return pCursor
; }
285 virtual bool IsEntryInView( SvTreeListEntry
* pEntry
) const;
286 virtual SvTreeListEntry
* GetEntry( const Point
& rPos
) const;
287 // returns last entry, if Pos below last entry
288 virtual SvTreeListEntry
* GetClickedEntry( const Point
& ) const;
289 SvTreeListEntry
* GetCurEntry() const { return pCursor
; }
290 void SetCurEntry( SvTreeListEntry
* );
291 virtual Point
GetEntryPosition( SvTreeListEntry
* ) const;
292 void MakeVisible( SvTreeListEntry
* pEntry
, bool bMoveToTop
= false );
293 void ScrollToAbsPos( long nPos
);
295 void PaintDDCursor(SvTreeListEntry
* pEntry
, bool bShow
);
298 inline Image
& implGetImageLocation( const ImageType _eType
);
300 inline void SetExpandedNodeBmp( const Image
& _rImg
);
301 inline void SetCollapsedNodeBmp( const Image
& _rImg
);
303 inline const Image
& GetExpandedNodeBmp( );
304 inline const Image
& GetCollapsedNodeBmp( );
305 inline const Image
& GetDontKnowNodeBmp( );
307 inline void SetDefaultEntryExpBmp( const Image
& _rImg
);
308 inline void SetDefaultEntryColBmp( const Image
& _rImg
);
309 inline const Image
& GetDefaultEntryExpBmp( );
310 inline const Image
& GetDefaultEntryColBmp( );
312 static const Image
& GetDefaultExpandedNodeImage( );
313 static const Image
& GetDefaultCollapsedNodeImage( );
315 const Size
& GetOutputSize() const { return aOutputSize
;}
316 virtual void KeyUp( bool bPageUp
);
317 virtual void KeyDown( bool bPageDown
);
318 void Command( const CommandEvent
& rCEvt
);
321 void DestroyAnchor() { pAnchor
=nullptr; aSelEng
.Reset(); }
322 void SelAllDestrAnch( bool bSelect
, bool bDestroyAnchor
= true, bool bSingleSelToo
= false );
323 void ShowCursor( bool bShow
);
325 bool RequestHelp( const HelpEvent
& rHEvt
);
327 bool IsNodeButton( const Point
& rPosPixel
, SvTreeListEntry
* pEntry
) const;
328 void EnableAsyncDrag( bool b
) { bAsyncBeginDrag
= b
; }
329 void SetUpdateMode( bool bMode
);
330 bool GetUpdateMode() const { return bUpdateMode
; }
331 tools::Rectangle
GetClipRegionRect() const;
332 bool HasHorScrollBar() const { return aHorSBar
->IsVisible(); }
333 void ShowFocusRect( const SvTreeListEntry
* pEntry
);
334 void CallEventListeners( VclEventId nEvent
, void* pData
= nullptr );
336 /** Enables, that one cell of a tablistbox entry can be focused */
337 bool IsCellFocusEnabled() const { return bIsCellFocusEnabled
; }
338 void EnableCellFocus() { bIsCellFocusEnabled
= true; }
339 bool SetCurrentTabPos( sal_uInt16 _nNewPos
);
340 sal_uInt16
GetCurrentTabPos() const { return nCurTabPos
; }
342 bool IsSelectable( const SvTreeListEntry
* pEntry
);
343 void SetForceMakeVisible(bool bEnable
) { mbForceMakeVisible
= bEnable
; }
346 inline Image
& SvImpLBox::implGetImageLocation( const ImageType _eType
)
348 return m_aNodeAndEntryImages
[_eType
];
351 inline void SvImpLBox::SetExpandedNodeBmp( const Image
& rImg
)
353 implGetImageLocation( ImageType::NodeExpanded
) = rImg
;
354 SetNodeBmpWidth( rImg
);
357 inline void SvImpLBox::SetCollapsedNodeBmp( const Image
& rImg
)
359 implGetImageLocation( ImageType::NodeCollapsed
) = rImg
;
360 SetNodeBmpWidth( rImg
);
363 inline const Image
& SvImpLBox::GetDontKnowNodeBmp( )
365 return implGetImageLocation( ImageType::NodeDontKnow
);
368 inline const Image
& SvImpLBox::GetExpandedNodeBmp( )
370 return implGetImageLocation( ImageType::NodeExpanded
);
373 inline const Image
& SvImpLBox::GetCollapsedNodeBmp( )
375 return implGetImageLocation( ImageType::NodeCollapsed
);
378 inline void SvImpLBox::SetDefaultEntryExpBmp( const Image
& _rImg
)
380 implGetImageLocation( ImageType::EntryDefExpanded
) = _rImg
;
383 inline void SvImpLBox::SetDefaultEntryColBmp( const Image
& _rImg
)
385 implGetImageLocation( ImageType::EntryDefCollapsed
) = _rImg
;
388 inline const Image
& SvImpLBox::GetDefaultEntryExpBmp( )
390 return implGetImageLocation( ImageType::EntryDefExpanded
);
393 inline const Image
& SvImpLBox::GetDefaultEntryColBmp( )
395 return implGetImageLocation( ImageType::EntryDefCollapsed
);
398 inline Point
SvImpLBox::GetEntryPosition( SvTreeListEntry
* pEntry
) const
400 return Point( 0, GetEntryLine( pEntry
) );
403 inline bool SvImpLBox::IsLineVisible( long nY
) const
406 if ( nY
< 0 || nY
>= aOutputSize
.Height() )
411 inline void SvImpLBox::TreeInserted( SvTreeListEntry
* pInsTree
)
413 EntryInserted( pInsTree
);
416 #endif // INCLUDED_VCL_SOURCE_INC_SVIMPBOX_HXX
418 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */