Bump version to 5.0-14
[LibreOffice.git] / svtools / source / inc / svimpbox.hxx
blobcaf45482bb2fcca9ec0b34cd8fc01adebd007dec
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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_SVTOOLS_SOURCE_INC_SVIMPBOX_HXX
21 #define INCLUDED_SVTOOLS_SOURCE_INC_SVIMPBOX_HXX
23 #include <vcl/seleng.hxx>
24 #include <vcl/scrbar.hxx>
25 #include <vcl/vclevent.hxx>
26 // #102891# ----------------
27 #include <unotools/intlwrapper.hxx>
28 // #97680# -----------------
29 #include <vector>
30 #include "svtaccessiblefactory.hxx"
32 class SvTreeListBox;
33 class Point;
34 class SvTreeList;
35 class SvImpLBox;
36 class SvTreeListEntry;
37 class SvLBoxTab;
38 namespace comphelper
40 namespace string
42 class NaturalStringSorter;
46 class ImpLBSelEng : public FunctionSet
48 SvImpLBox* pImp;
49 SelectionEngine* pSelEng;
50 VclPtr<SvTreeListBox> pView;
52 public:
53 ImpLBSelEng( SvImpLBox* pImp, SelectionEngine* pSelEng,
54 SvTreeListBox* pView );
55 virtual ~ImpLBSelEng();
56 void BeginDrag() SAL_OVERRIDE;
57 void CreateAnchor() SAL_OVERRIDE;
58 void DestroyAnchor() SAL_OVERRIDE;
59 bool SetCursorAtPoint( const Point& rPoint,
60 bool bDontSelectAtCursor=false ) SAL_OVERRIDE;
61 bool IsSelectionAtPoint( const Point& rPoint ) SAL_OVERRIDE;
62 void DeselectAtPoint( const Point& rPoint ) SAL_OVERRIDE;
63 void DeselectAll() SAL_OVERRIDE;
66 // Flags fuer nFlag
67 #define F_VER_SBARSIZE_WITH_HBAR 0x0001
68 #define F_HOR_SBARSIZE_WITH_VBAR 0x0002
69 #define F_IGNORE_NEXT_MOUSEMOVE 0x0004 // OS/2 only
70 #define F_IN_SCROLLING 0x0008
71 #define F_DESEL_ALL 0x0010
72 #define F_START_EDITTIMER 0x0020 // MAC only
73 #define F_IGNORE_SELECT 0x0040
74 #define F_IN_RESIZE 0x0080
75 #define F_REMOVED_ENTRY_INVISIBLE 0x0100
76 #define F_REMOVED_RECALC_MOST_RIGHT 0x0200
77 #define F_IGNORE_CHANGED_TABS 0x0400
78 #define F_PAINTED 0x0800
79 #define F_IN_PAINT 0x1000
80 #define F_ENDSCROLL_SET_VIS_SIZE 0x2000
81 #define F_FILLING 0x4000
84 class SvImpLBox
86 friend class ImpLBSelEng;
87 friend class SvTreeListBox;
88 private:
89 VclPtr<SvTreeListBox> pView;
90 SvTreeList* pTree;
91 SvTreeListEntry* pCursor;
92 SvTreeListEntry* pStartEntry;
93 SvTreeListEntry* pAnchor;
94 SvTreeListEntry* pMostRightEntry;
95 SvLBoxButton* pActiveButton;
96 SvTreeListEntry* pActiveEntry;
97 SvLBoxTab* pActiveTab;
99 VclPtr<ScrollBar> aVerSBar;
100 VclPtr<ScrollBar> aHorSBar;
101 VclPtr<ScrollBarBox> aScrBarBox;
103 ::svt::AccessibleFactoryAccess
104 m_aFactoryAccess;
106 static Image* s_pDefCollapsed;
107 static Image* s_pDefExpanded;
108 static oslInterlockedCount s_nImageRefCount; /// When 0 all static images will be destroyed
110 // Node Bitmaps
111 enum ImageType
113 itNodeExpanded = 0, // node is expanded ( usually a bitmap showing a minus )
114 itNodeCollapsed, // node is collapsed ( usually a bitmap showing a plus )
115 itNodeDontKnow, // don't know the node state
116 itEntryDefExpanded, // default for expanded entries
117 itEntryDefCollapsed, // default for collapsed entries
119 IT_IMAGE_COUNT
122 // all our images
123 Image m_aNodeAndEntryImages[ IT_IMAGE_COUNT ];
125 Size aOutputSize;
126 SelectionEngine aSelEng;
127 ImpLBSelEng aFctSet;
128 Idle aAsyncBeginDragIdle;
129 Point aAsyncBeginDragPos;
131 long nYoffsNodeBmp;
132 long nNodeBmpTabDistance; // typical smaller than 0
133 long nNodeBmpWidth;
134 long nNextVerVisSize;
135 long nMostRight;
136 sal_uLong nVisibleCount; // Number of lines in control
137 ImplSVEvent * nCurUserEvent;
138 short nHorSBarHeight, nVerSBarWidth;
139 sal_uInt16 nFlags;
140 sal_uInt16 nCurTabPos;
142 WinBits m_nStyle;
143 ExtendedWinBits nExtendedWinBits;
144 bool bSimpleTravel : 1; // ist true bei SINGLE_SELECTION
145 bool bUpdateMode : 1;
146 bool bInVScrollHdl : 1;
147 bool bAsyncBeginDrag : 1;
148 bool bSubLstOpRet : 1; // open/close sublist with return/enter, defaulted with false
149 bool bSubLstOpLR : 1; // open/close sublist with cursor left/right, defaulted with false
150 bool bContextMenuHandling : 1;
151 bool bIsCellFocusEnabled : 1;
153 bool bAreChildrenTransient;
155 Point aEditClickPos;
156 Idle aEditIdle;
158 // #102891# -------------------
159 comphelper::string::NaturalStringSorter *m_pStringSorter;
161 // #97680# --------------------
162 std::vector< short > aContextBmpWidthVector;
164 DECL_LINK_TYPED(EditTimerCall, Idle *, void);
166 DECL_LINK_TYPED( BeginDragHdl, Idle*, void );
167 DECL_LINK( MyUserEvent,void*);
168 void StopUserEvent();
170 void InvalidateEntriesFrom( long nY ) const;
171 void InvalidateEntry( long nY ) const;
172 void ShowVerSBar();
173 // setzt Thumb auf FirstEntryToDraw
174 void SyncVerThumb();
175 bool IsLineVisible( long nY ) const;
176 long GetEntryLine( SvTreeListEntry* pEntry ) const;
177 void FillView();
178 void CursorDown();
179 void CursorUp();
180 void KeyLeftRight( long nDiff );
181 void PageDown( sal_uInt16 nDelta );
182 void PageUp( sal_uInt16 nDelta );
184 void SetCursor( SvTreeListEntry* pEntry, bool bForceNoSelect = false );
186 void DrawNet(vcl::RenderContext& rRenderContext);
188 // ScrollBar-Handler
189 DECL_LINK( ScrollUpDownHdl, ScrollBar * );
190 DECL_LINK( ScrollLeftRightHdl, ScrollBar * );
191 DECL_LINK( EndScrollHdl, void * );
193 void SetNodeBmpYOffset( const Image& );
194 void SetNodeBmpTabDistance();
196 // Selection-Engine
197 SvTreeListEntry* MakePointVisible( const Point& rPoint, bool bNotifyScroll=true );
199 void SetAnchorSelection( SvTreeListEntry* pOld,
200 SvTreeListEntry* pNewCursor );
201 void BeginDrag();
202 bool ButtonDownCheckCtrl( const MouseEvent& rMEvt, SvTreeListEntry* pEntry, long nY );
203 bool MouseMoveCheckCtrl( const MouseEvent& rMEvt, SvTreeListEntry* pEntry );
204 bool ButtonUpCheckCtrl( const MouseEvent& rMEvt );
205 bool ButtonDownCheckExpand( const MouseEvent&, SvTreeListEntry*,long nY );
207 void PositionScrollBars( Size& rOSize, sal_uInt16 nMask );
208 sal_uInt16 AdjustScrollBars( Size& rSize );
210 void BeginScroll();
211 void EndScroll();
212 bool InScroll() const { return (nFlags & F_IN_SCROLLING) != 0; }
213 Rectangle GetVisibleArea() const;
214 bool EntryReallyHit(SvTreeListEntry* pEntry, const Point& rPos, long nLine);
215 void InitScrollBarBox();
216 SvLBoxTab* NextTab( SvLBoxTab* );
218 bool SetMostRight( SvTreeListEntry* pEntry );
219 void FindMostRight( SvTreeListEntry* EntryToIgnore );
220 void FindMostRight( SvTreeListEntry* pParent, SvTreeListEntry* EntryToIgnore );
221 void FindMostRight_Impl( SvTreeListEntry* pParent,SvTreeListEntry* EntryToIgnore );
222 void NotifyTabsChanged();
224 // if element at cursor can be expanded in general
225 bool IsExpandable() const;
227 // if element at cursor can be expanded at this moment
228 bool IsNowExpandable() const;
230 static void implInitDefaultNodeImages();
232 void UpdateStringSorter();
234 // #97680# --------------------
235 short UpdateContextBmpWidthVector( SvTreeListEntry* pEntry, short nWidth );
236 void UpdateContextBmpWidthMax( SvTreeListEntry* pEntry );
237 void UpdateContextBmpWidthVectorFromMovedEntry( SvTreeListEntry* pEntry );
239 void CalcCellFocusRect( SvTreeListEntry* pEntry, Rectangle& rRect );
241 bool AreChildrenTransient() const { return bAreChildrenTransient; }
242 inline void SetChildrenNotTransient() { bAreChildrenTransient = false; }
244 public:
245 SvImpLBox( SvTreeListBox* pView, SvTreeList*, WinBits nWinStyle );
246 ~SvImpLBox();
248 void Clear();
249 void SetStyle( WinBits i_nWinStyle );
250 void SetExtendedWindowBits( ExtendedWinBits _nBits );
251 ExtendedWinBits GetExtendedWindowBits() const { return nExtendedWinBits; }
252 void SetModel( SvTreeList* pModel ) { pTree = pModel;}
254 void EntryInserted( SvTreeListEntry*);
255 void RemovingEntry( SvTreeListEntry* pEntry );
256 void EntryRemoved();
257 void MovingEntry( SvTreeListEntry* pEntry );
258 void EntryMoved( SvTreeListEntry* pEntry );
259 void TreeInserted( SvTreeListEntry* pEntry );
261 void EntryExpanded( SvTreeListEntry* pEntry );
262 void EntryCollapsed( SvTreeListEntry* pEntry );
263 void CollapsingEntry( SvTreeListEntry* pEntry );
264 void EntrySelected( SvTreeListEntry* pEntry, bool bSelect );
266 void Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect);
267 void MouseButtonDown( const MouseEvent& );
268 void MouseButtonUp( const MouseEvent& );
269 void MouseMove( const MouseEvent&);
270 bool KeyInput( const KeyEvent& );
271 void Resize();
272 void GetFocus();
273 void LoseFocus();
274 void UpdateAll( bool bInvalidateCompleteView= true, bool bUpdateVerSBar = true );
275 void SetEntryHeight( short nHeight );
276 void PaintEntry(SvTreeListEntry* pEntry, vcl::RenderContext& rRenderContext);
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 bool IsEntryInView( SvTreeListEntry* pEntry ) const;
286 SvTreeListEntry* GetEntry( const Point& rPos ) const;
287 // returns last entry, if Pos below last entry
288 SvTreeListEntry* GetClickedEntry( const Point& ) const;
289 SvTreeListEntry* GetCurEntry() const { return pCursor; }
290 void SetCurEntry( SvTreeListEntry* );
291 Point GetEntryPosition( SvTreeListEntry* ) const;
292 void MakeVisible( SvTreeListEntry* pEntry, bool bMoveToTop = false );
293 void ScrollToAbsPos( long nPos );
295 void PaintDDCursor( SvTreeListEntry* );
297 // Images
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 void KeyUp( bool bPageUp, bool bNotifyScroll = true );
317 void KeyDown( bool bPageDown, bool bNotifyScroll = true );
318 void Command( const CommandEvent& rCEvt );
320 void Invalidate();
321 void DestroyAnchor() { pAnchor=0; aSelEng.Reset(); }
322 void SelAllDestrAnch( bool bSelect, bool bDestroyAnchor = true, bool bSingleSelToo = false );
323 void ShowCursor( bool bShow );
325 bool RequestHelp( const HelpEvent& rHEvt );
326 void EndSelection();
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 Rectangle GetClipRegionRect() const;
332 bool HasHorScrollBar() const { return aHorSBar->IsVisible(); }
333 void ShowFocusRect( const SvTreeListEntry* pEntry );
334 void CallEventListeners( sal_uLong nEvent, void* pData = NULL );
336 /** Enables, that one cell of a tablistbox entry can be focused */
337 bool IsCellFocusEnabled() const { return bIsCellFocusEnabled; }
338 inline void EnableCellFocus() { bIsCellFocusEnabled = true; }
339 bool SetCurrentTabPos( sal_uInt16 _nNewPos );
340 inline sal_uInt16 GetCurrentTabPos() const { return nCurTabPos; }
342 bool IsSelectable( const SvTreeListEntry* pEntry );
345 inline Image& SvImpLBox::implGetImageLocation( const ImageType _eType )
347 DBG_ASSERT( ( _eType >= 0 ) && ( _eType < IT_IMAGE_COUNT ),
348 "SvImpLBox::implGetImageLocation: invalid image index (will crash)!" );
350 Image* _pSet = m_aNodeAndEntryImages;
351 return *( _pSet + (sal_Int32)_eType );
354 inline void SvImpLBox::SetExpandedNodeBmp( const Image& rImg )
356 implGetImageLocation( itNodeExpanded ) = rImg;
357 SetNodeBmpYOffset( rImg );
360 inline void SvImpLBox::SetCollapsedNodeBmp( const Image& rImg )
362 implGetImageLocation( itNodeCollapsed ) = rImg;
363 SetNodeBmpYOffset( rImg );
366 inline const Image& SvImpLBox::GetDontKnowNodeBmp( )
368 return implGetImageLocation( itNodeDontKnow );
371 inline const Image& SvImpLBox::GetExpandedNodeBmp( )
373 return implGetImageLocation( itNodeExpanded );
376 inline const Image& SvImpLBox::GetCollapsedNodeBmp( )
378 return implGetImageLocation( itNodeCollapsed );
381 inline void SvImpLBox::SetDefaultEntryExpBmp( const Image& _rImg )
383 implGetImageLocation( itEntryDefExpanded ) = _rImg;
386 inline void SvImpLBox::SetDefaultEntryColBmp( const Image& _rImg )
388 implGetImageLocation( itEntryDefCollapsed ) = _rImg;
391 inline const Image& SvImpLBox::GetDefaultEntryExpBmp( )
393 return implGetImageLocation( itEntryDefExpanded );
396 inline const Image& SvImpLBox::GetDefaultEntryColBmp( )
398 return implGetImageLocation( itEntryDefCollapsed );
401 inline Point SvImpLBox::GetEntryPosition( SvTreeListEntry* pEntry ) const
403 return Point( 0, GetEntryLine( pEntry ) );
406 inline void SvImpLBox::PaintEntry(SvTreeListEntry* pEntry, vcl::RenderContext& rRenderContext)
408 long nY = GetEntryLine(pEntry);
409 pView->PaintEntry(pEntry, nY, rRenderContext);
412 inline bool SvImpLBox::IsLineVisible( long nY ) const
414 bool bRet = true;
415 if ( nY < 0 || nY >= aOutputSize.Height() )
416 bRet = false;
417 return bRet;
420 inline void SvImpLBox::TreeInserted( SvTreeListEntry* pInsTree )
422 EntryInserted( pInsTree );
425 #endif // INCLUDED_SVTOOLS_SOURCE_INC_SVIMPBOX_HXX
427 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */