/src/libreoffice/vcl/inc/svimpbox.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #pragma once |
21 | | |
22 | | #include <vcl/seleng.hxx> |
23 | | #include <vcl/idle.hxx> |
24 | | #include <vcl/image.hxx> |
25 | | #include <vcl/vclevent.hxx> |
26 | | #include <vcl/toolkit/scrbar.hxx> |
27 | | #include <vcl/toolkit/treelistbox.hxx> |
28 | | #include <o3tl/enumarray.hxx> |
29 | | #include <memory> |
30 | | #include <vector> |
31 | | |
32 | | class SvLBoxButton; |
33 | | class SvTreeList; |
34 | | class SvImpLBox; |
35 | | class SvTreeListEntry; |
36 | | namespace comphelper::string { class NaturalStringSorter; } |
37 | | |
38 | | class ImpLBSelEng final : public FunctionSet |
39 | | { |
40 | | SvImpLBox& m_rImp; |
41 | | VclPtr<SvTreeListBox> pView; |
42 | | |
43 | | public: |
44 | | ImpLBSelEng(SvImpLBox& rImp, SvTreeListBox& rView); |
45 | | virtual ~ImpLBSelEng() override; |
46 | | void BeginDrag() override; |
47 | | void CreateAnchor() override; |
48 | | void DestroyAnchor() override; |
49 | | void SetCursorAtPoint( const Point& rPoint, |
50 | | bool bDontSelectAtCursor=false ) override; |
51 | | bool IsSelectionAtPoint( const Point& rPoint ) override; |
52 | | void DeselectAtPoint( const Point& rPoint ) override; |
53 | | void DeselectAll() override; |
54 | | }; |
55 | | |
56 | | // Flags for nFlag |
57 | | enum class LBoxFlags { |
58 | | NONE = 0x0000, |
59 | | DeselectAll = 0x0002, |
60 | | StartEditTimer = 0x0004, // MAC only |
61 | | IgnoreSelect = 0x0008, |
62 | | InResize = 0x0010, |
63 | | RemovedEntryInvisible = 0x0020, |
64 | | RemovedRecalcMostRight = 0x0040, |
65 | | IgnoreChangedTabs = 0x0080, |
66 | | InPaint = 0x0100, |
67 | | EndScrollSetVisSize = 0x0200, |
68 | | Filling = 0x0400, |
69 | | }; |
70 | | namespace o3tl |
71 | | { |
72 | | template<> struct typed_flags<LBoxFlags> : is_typed_flags<LBoxFlags, 0x07fe> {}; |
73 | | } |
74 | | |
75 | | enum class ScrollBarMask |
76 | | { |
77 | | None = 0x0000, |
78 | | Vertical = 0x0001, |
79 | | Horizontal = 0x0002, |
80 | | }; |
81 | | |
82 | | namespace o3tl |
83 | | { |
84 | | template <> struct typed_flags<ScrollBarMask> : is_typed_flags<ScrollBarMask, 0x0003> |
85 | | { |
86 | | }; |
87 | | } |
88 | | |
89 | 0 | #define NODE_BMP_TABDIST_NOTVALID -2000000 |
90 | | #define FIRST_ENTRY_TAB 1 |
91 | | |
92 | | class SvImpLBox |
93 | | { |
94 | | friend class ImpLBSelEng; |
95 | | friend class SvTreeListBox; |
96 | | friend class SalInstanceTreeView; |
97 | | friend class IconView; |
98 | | private: |
99 | | SvTreeList& m_rTree; |
100 | | SvTreeListEntry* m_pAnchor; |
101 | | SvTreeListEntry* m_pMostRightEntry; |
102 | | SvLBoxButton* m_pActiveButton; |
103 | | SvTreeListEntry* m_pActiveEntry; |
104 | | VclPtr<ScrollBarBox> m_aScrBarBox; |
105 | | |
106 | | static Image* s_pDefCollapsed; |
107 | | static Image* s_pDefExpanded; |
108 | | static oslInterlockedCount s_nImageRefCount; /// When 0 all static images will be destroyed |
109 | | |
110 | | // Node Bitmaps |
111 | | enum class ImageType |
112 | | { |
113 | | NodeExpanded = 0, // node is expanded ( usually a bitmap showing a minus ) |
114 | | NodeCollapsed, // node is collapsed ( usually a bitmap showing a plus ) |
115 | | EntryDefExpanded, // default for expanded entries |
116 | | EntryDefCollapsed, // default for collapsed entries |
117 | | LAST = EntryDefCollapsed |
118 | | }; |
119 | | |
120 | | // all our images |
121 | | o3tl::enumarray<ImageType, Image> |
122 | | m_aNodeAndEntryImages; |
123 | | |
124 | | ImpLBSelEng m_aFctSet; |
125 | | |
126 | | tools::Long m_nNodeBmpWidth; |
127 | | tools::Long m_nMostRight; |
128 | | short m_nHorSBarHeight, m_nVerSBarWidth; |
129 | | |
130 | | bool m_bUpdateMode : 1; |
131 | | bool m_bSubLstOpLR : 1; // open/close sublist with cursor left/right, defaulted with false |
132 | | bool mbForceMakeVisible; |
133 | | |
134 | | Point m_aEditClickPos; |
135 | | Idle m_aEditIdle; |
136 | | |
137 | | std::unique_ptr<comphelper::string::NaturalStringSorter> m_pStringSorter; |
138 | | |
139 | | std::vector< short > m_aContextBmpWidthVector; |
140 | | |
141 | | DECL_LINK(EditTimerCall, Timer *, void); |
142 | | |
143 | | void InvalidateEntriesFrom( tools::Long nY ) const; |
144 | | bool IsLineVisible( tools::Long nY ) const; |
145 | | void KeyLeftRight( tools::Long nDiff ); |
146 | | |
147 | | void DrawNet(vcl::RenderContext& rRenderContext); |
148 | | |
149 | | // ScrollBar-Handler |
150 | | DECL_LINK( ScrollUpDownHdl, ScrollBar*, void ); |
151 | | DECL_LINK( ScrollLeftRightHdl, ScrollBar*, void ); |
152 | | DECL_LINK( EndScrollHdl, ScrollBar*, void ); |
153 | | |
154 | | void SetNodeBmpWidth( const Image& ); |
155 | | void SetNodeBmpTabDistance(); |
156 | | |
157 | | // Selection-Engine |
158 | | SvTreeListEntry* MakePointVisible( const Point& rPoint ); |
159 | | |
160 | | void SetAnchorSelection( SvTreeListEntry* pOld, |
161 | | SvTreeListEntry* pNewCursor ); |
162 | | void BeginDrag(); |
163 | | bool ButtonDownCheckCtrl( const MouseEvent& rMEvt, SvTreeListEntry* pEntry ); |
164 | | bool MouseMoveCheckCtrl( const MouseEvent& rMEvt, SvTreeListEntry const * pEntry ); |
165 | | bool ButtonUpCheckCtrl( const MouseEvent& rMEvt ); |
166 | | bool ButtonDownCheckExpand( const MouseEvent&, SvTreeListEntry* ); |
167 | | |
168 | | bool EntryReallyHit(SvTreeListEntry& rEntry, const Point& rPos, tools::Long nLine); |
169 | | void InitScrollBarBox(); |
170 | | SvLBoxTab* NextTab( SvLBoxTab const * ); |
171 | | |
172 | | void SetMostRight( SvTreeListEntry* pEntry ); |
173 | | void FindMostRight( SvTreeListEntry* pParent ); |
174 | | void FindMostRight_Impl( SvTreeListEntry* pParent ); |
175 | | void NotifyTabsChanged(); |
176 | | |
177 | | // if element at cursor can be expanded in general |
178 | | bool IsExpandable() const; |
179 | | |
180 | | static void implInitDefaultNodeImages(); |
181 | | |
182 | | void UpdateStringSorter(); |
183 | | |
184 | | short UpdateContextBmpWidthVector( SvTreeListEntry const * pEntry, short nWidth ); |
185 | | void UpdateContextBmpWidthMax( SvTreeListEntry const * pEntry ); |
186 | | void UpdateContextBmpWidthVectorFromMovedEntry( SvTreeListEntry* pEntry ); |
187 | | |
188 | | void ExpandAll(); |
189 | | void CollapseTo(SvTreeListEntry* pParentToCollapse); |
190 | | |
191 | | protected: |
192 | | SvTreeListBox& m_rView; |
193 | | VclPtr<ScrollBar> m_aHorSBar; |
194 | | VclPtr<ScrollBar> m_aVerSBar; |
195 | | SvTreeListEntry* m_pCursor; |
196 | | SvTreeListEntry* m_pCursorOld; |
197 | | SvTreeListEntry* m_pStartEntry; |
198 | | ImplSVEvent* m_nCurUserEvent; |
199 | | Size m_aOutputSize; |
200 | | LBoxFlags m_nFlags; |
201 | | WinBits m_nStyle; |
202 | | bool mbNoAutoCurEntry; // disable the behavior of automatically selecting a "CurEntry" upon painting the control |
203 | | SelectionEngine m_aSelEng; |
204 | | sal_uLong m_nVisibleCount; // Number of lines in control |
205 | | bool m_bInVScrollHdl : 1; |
206 | | bool m_bSimpleTravel : 1; // is true if SelectionMode::Single |
207 | | tools::Long m_nNextVerVisSize; |
208 | | tools::Long m_nNodeBmpTabDistance; // typical smaller than 0 |
209 | | |
210 | | virtual tools::Long GetEntryLine(const SvTreeListEntry* pEntry) const; |
211 | | virtual void CursorDown(); |
212 | | virtual void CursorUp(); |
213 | | virtual void PageDown( sal_uInt16 nDelta ); |
214 | | virtual void PageUp( sal_uInt16 nDelta ); |
215 | | // set Thumb to FirstEntryToDraw |
216 | | virtual void SyncVerThumb(); |
217 | | virtual void AdjustScrollBars( Size& rSize ); |
218 | | virtual void InvalidateEntry( tools::Long nY ) const; |
219 | | |
220 | | tools::Rectangle GetVisibleArea() const; |
221 | | void SetCursor( SvTreeListEntry* pEntry, bool bForceNoSelect = false ); |
222 | | void PositionScrollBars(Size& rOSize, ScrollBarMask eMask); |
223 | | void FindMostRight(); |
224 | | void FillView(); |
225 | | void ShowVerSBar(); |
226 | | void StopUserEvent(); |
227 | | |
228 | | DECL_LINK( MyUserEvent, void*, void); |
229 | | |
230 | | public: |
231 | | SvImpLBox(SvTreeListBox& rView, SvTreeList& rTree, WinBits nWinStyle); |
232 | | virtual ~SvImpLBox(); |
233 | | |
234 | | void Clear(); |
235 | | void SetStyle( WinBits i_nWinStyle ); |
236 | | void SetNoAutoCurEntry( bool b ); |
237 | | |
238 | | void EntryInserted( SvTreeListEntry*); |
239 | | void RemovingEntry( SvTreeListEntry* pEntry ); |
240 | | void EntryRemoved(); |
241 | | void MovingEntry( SvTreeListEntry* pEntry ); |
242 | | void EntryMoved( SvTreeListEntry* pEntry ); |
243 | | void TreeInserted( SvTreeListEntry* pEntry ); |
244 | | |
245 | | void EntryExpanded( SvTreeListEntry* pEntry ); |
246 | | void EntryCollapsed( SvTreeListEntry* pEntry ); |
247 | | void CollapsingEntry( SvTreeListEntry* pEntry ); |
248 | | void EntrySelected( SvTreeListEntry* pEntry, bool bSelect ); |
249 | | |
250 | | virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect); |
251 | | void MouseButtonDown( const MouseEvent& ); |
252 | | void MouseButtonUp( const MouseEvent& ); |
253 | | void MouseMove( const MouseEvent&); |
254 | | virtual bool KeyInput( const KeyEvent& ); |
255 | | void Resize(); |
256 | | void GetFocus(); |
257 | | void LoseFocus(); |
258 | | virtual void UpdateAll(); |
259 | | void SetEntryHeight(); |
260 | | void InvalidateEntry( SvTreeListEntry* ); |
261 | | void RecalcFocusRect(); |
262 | | |
263 | | void SelectEntry( SvTreeListEntry* pEntry, bool bSelect ); |
264 | | void SetDragDropMode( DragDropMode eDDMode ); |
265 | | void SetSelectionMode( SelectionMode eSelMode ); |
266 | | |
267 | | virtual bool IsEntryInView( SvTreeListEntry* pEntry ) const; |
268 | | virtual SvTreeListEntry* GetEntry( const Point& rPos ) const; |
269 | | // returns last entry, if Pos below last entry |
270 | | virtual SvTreeListEntry* GetClickedEntry( const Point& ) const; |
271 | 0 | SvTreeListEntry* GetCurEntry() const { return m_pCursor; } |
272 | | void SetCurEntry( SvTreeListEntry* ); |
273 | | virtual Point GetEntryPosition(const SvTreeListEntry*) const; |
274 | | void MakeVisible( SvTreeListEntry* pEntry, bool bMoveToTop = false ); |
275 | | void ScrollToAbsPos( tools::Long nPos ); |
276 | | |
277 | | void PaintDDCursor(SvTreeListEntry* pEntry, bool bShow); |
278 | | |
279 | | // Images |
280 | | inline Image& implGetImageLocation( const ImageType _eType ); |
281 | | |
282 | | inline void SetExpandedNodeBmp( const Image& _rImg ); |
283 | | inline void SetCollapsedNodeBmp( const Image& _rImg ); |
284 | | |
285 | | inline const Image& GetExpandedNodeBmp( ); |
286 | | inline const Image& GetCollapsedNodeBmp( ); |
287 | | |
288 | | inline void SetDefaultEntryExpBmp( const Image& _rImg ); |
289 | | inline void SetDefaultEntryColBmp( const Image& _rImg ); |
290 | | inline const Image& GetDefaultEntryExpBmp( ); |
291 | | inline const Image& GetDefaultEntryColBmp( ); |
292 | | |
293 | | static const Image& GetDefaultExpandedNodeImage( ); |
294 | | static const Image& GetDefaultCollapsedNodeImage( ); |
295 | | |
296 | 0 | const Size& GetOutputSize() const { return m_aOutputSize;} |
297 | | virtual void KeyUp( bool bPageUp ); |
298 | | virtual void KeyDown( bool bPageDown ); |
299 | | void Command( const CommandEvent& rCEvt ); |
300 | | |
301 | | void Invalidate(); |
302 | 0 | void DestroyAnchor() { m_pAnchor=nullptr; m_aSelEng.Reset(); } |
303 | | void SelAllDestrAnch( bool bSelect, bool bDestroyAnchor = true, bool bSingleSelToo = false ); |
304 | | void ShowCursor( bool bShow ); |
305 | | |
306 | | bool RequestHelp( const HelpEvent& rHEvt ); |
307 | | bool IsNodeButton( const Point& rPosPixel, const SvTreeListEntry* pEntry ) const; |
308 | | void SetUpdateMode( bool bMode ); |
309 | 0 | bool GetUpdateMode() const { return m_bUpdateMode; } |
310 | | tools::Rectangle GetClipRegionRect() const; |
311 | 0 | bool HasHorScrollBar() const { return m_aHorSBar->IsVisible(); } |
312 | | void CallEventListeners( VclEventId nEvent, void* pData = nullptr ); |
313 | | |
314 | | bool IsSelectable(const SvTreeListEntry& rEntry) const; |
315 | 0 | void SetForceMakeVisible(bool bEnable) { mbForceMakeVisible = bEnable; } |
316 | | |
317 | | // tdf#143114 allow to ask if CaptureOnButton is active |
318 | | // (MouseButtonDown hit on SvLBoxButton, CaptureMouse() active) |
319 | | bool IsCaptureOnButtonActive() const; |
320 | | }; |
321 | | |
322 | | inline bool SvImpLBox::IsCaptureOnButtonActive() const |
323 | 0 | { |
324 | 0 | return nullptr != m_pActiveButton && nullptr != m_pActiveEntry; |
325 | 0 | } |
326 | | |
327 | | inline Image& SvImpLBox::implGetImageLocation( const ImageType _eType ) |
328 | 0 | { |
329 | 0 | return m_aNodeAndEntryImages[_eType]; |
330 | 0 | } |
331 | | |
332 | | inline void SvImpLBox::SetExpandedNodeBmp( const Image& rImg ) |
333 | 0 | { |
334 | 0 | implGetImageLocation( ImageType::NodeExpanded ) = rImg; |
335 | 0 | SetNodeBmpWidth( rImg ); |
336 | 0 | } |
337 | | |
338 | | inline void SvImpLBox::SetCollapsedNodeBmp( const Image& rImg ) |
339 | 0 | { |
340 | 0 | implGetImageLocation( ImageType::NodeCollapsed ) = rImg; |
341 | 0 | SetNodeBmpWidth( rImg ); |
342 | 0 | } |
343 | | |
344 | | inline const Image& SvImpLBox::GetExpandedNodeBmp( ) |
345 | 0 | { |
346 | 0 | return implGetImageLocation( ImageType::NodeExpanded ); |
347 | 0 | } |
348 | | |
349 | | inline const Image& SvImpLBox::GetCollapsedNodeBmp( ) |
350 | 0 | { |
351 | 0 | return implGetImageLocation( ImageType::NodeCollapsed ); |
352 | 0 | } |
353 | | |
354 | | inline void SvImpLBox::SetDefaultEntryExpBmp( const Image& _rImg ) |
355 | 0 | { |
356 | 0 | implGetImageLocation( ImageType::EntryDefExpanded ) = _rImg; |
357 | 0 | } |
358 | | |
359 | | inline void SvImpLBox::SetDefaultEntryColBmp( const Image& _rImg ) |
360 | 0 | { |
361 | 0 | implGetImageLocation( ImageType::EntryDefCollapsed ) = _rImg; |
362 | 0 | } |
363 | | |
364 | | inline const Image& SvImpLBox::GetDefaultEntryExpBmp( ) |
365 | 0 | { |
366 | 0 | return implGetImageLocation( ImageType::EntryDefExpanded ); |
367 | 0 | } |
368 | | |
369 | | inline const Image& SvImpLBox::GetDefaultEntryColBmp( ) |
370 | 0 | { |
371 | 0 | return implGetImageLocation( ImageType::EntryDefCollapsed ); |
372 | 0 | } |
373 | | |
374 | | inline Point SvImpLBox::GetEntryPosition(const SvTreeListEntry* pEntry) const |
375 | 0 | { |
376 | 0 | return Point(0, GetEntryLine(pEntry)); |
377 | 0 | } |
378 | | |
379 | | inline bool SvImpLBox::IsLineVisible( tools::Long nY ) const |
380 | 0 | { |
381 | 0 | bool bRet = true; |
382 | 0 | if ( nY < 0 || nY >= m_aOutputSize.Height() ) |
383 | 0 | bRet = false; |
384 | 0 | return bRet; |
385 | 0 | } |
386 | | |
387 | | inline void SvImpLBox::TreeInserted( SvTreeListEntry* pInsTree ) |
388 | 0 | { |
389 | 0 | EntryInserted( pInsTree ); |
390 | 0 | } |
391 | | |
392 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |