1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svimpbox.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _SVIMPLBOX_HXX
32 #define _SVIMPLBOX_HXX
35 #include <vcl/seleng.hxx>
38 #include <vcl/scrbar.hxx>
40 #include <vcl/vclevent.hxx>
41 // #102891# ----------------
42 #include <unotools/intlwrapper.hxx>
43 // #97680# -----------------
45 #include "svtaccessiblefactory.hxx"
57 class ImpLBSelEng
: public FunctionSet
60 SelectionEngine
* pSelEng
;
64 ImpLBSelEng( SvImpLBox
* pImp
, SelectionEngine
* pSelEng
,
65 SvTreeListBox
* pView
);
66 virtual ~ImpLBSelEng();
70 BOOL
SetCursorAtPoint( const Point
& rPoint
,
71 BOOL bDontSelectAtCursor
=FALSE
);
72 BOOL
IsSelectionAtPoint( const Point
& rPoint
);
73 void DeselectAtPoint( const Point
& rPoint
);
78 #define F_VER_SBARSIZE_WITH_HBAR 0x0001
79 #define F_HOR_SBARSIZE_WITH_VBAR 0x0002
80 #define F_IGNORE_NEXT_MOUSEMOVE 0x0004 // OS/2 only
81 #define F_IN_SCROLLING 0x0008
82 #define F_DESEL_ALL 0x0010
83 #define F_START_EDITTIMER 0x0020 // MAC only
84 #define F_IGNORE_SELECT 0x0040
85 #define F_IN_RESIZE 0x0080
86 #define F_REMOVED_ENTRY_INVISIBLE 0x0100
87 #define F_REMOVED_RECALC_MOST_RIGHT 0x0200
88 #define F_IGNORE_CHANGED_TABS 0x0400
89 #define F_PAINTED 0x0800
90 #define F_IN_PAINT 0x1000
91 #define F_ENDSCROLL_SET_VIS_SIZE 0x2000
92 #define F_FILLING 0x4000
97 friend class ImpLBSelEng
;
98 friend class SvTreeListBox
;
100 SvTreeListBox
* pView
;
101 SvLBoxTreeList
* pTree
;
102 SvLBoxEntry
* pCursor
;
103 SvLBoxEntry
* pStartEntry
;
104 SvLBoxEntry
* pAnchor
;
105 SvLBoxEntry
* pMostRightEntry
;
106 SvLBoxButton
* pActiveButton
;
107 SvLBoxEntry
* pActiveEntry
;
108 SvLBoxTab
* pActiveTab
;
113 ScrollBarBox aScrBarBox
;
115 ::svt::AccessibleFactoryAccess
118 static Image
* s_pDefCollapsed
;
119 static Image
* s_pDefExpanded
;
120 static Image
* s_pDefCollapsedHC
;
121 static Image
* s_pDefExpandedHC
;
122 static oslInterlockedCount s_nImageRefCount
; /// When 0 all static images will be destroyed
127 itNodeExpanded
= 0, // node is expanded ( usually a bitmap showing a minus )
128 itNodeCollapsed
, // node is collapsed ( usually a bitmap showing a plus )
129 itNodeDontKnow
, // don't know the node state
130 itEntryDefExpanded
, // default for expanded entries
131 itEntryDefCollapsed
, // default for collapsed entries
137 Image m_aNodeAndEntryImages
[ IT_IMAGE_COUNT
];
138 // plus the high contrast versions
139 Image m_aNodeAndEntryImages_HC
[ IT_IMAGE_COUNT
];
143 SelectionEngine aSelEng
;
145 Timer aAsyncBeginDragTimer
;
146 Point aAsyncBeginDragPos
;
149 long nNodeBmpTabDistance
; // typisch kleiner 0
151 long nNextVerVisSize
;
153 ULONG nVisibleCount
; // Anzahl Zeilen im Control
154 ULONG nCurUserEvent
; //-1 == kein Userevent amn Laufen
155 short nHorSBarHeight
, nVerSBarWidth
;
160 ExtendedWinBits nExtendedWinBits
;
161 BOOL bSimpleTravel
: 1; // ist TRUE bei SINGLE_SELECTION
162 BOOL bUpdateMode
: 1;
163 BOOL bInVScrollHdl
: 1;
164 BOOL bAsyncBeginDrag
: 1;
165 BOOL bSubLstOpRet
: 1; // open/close sublist with return/enter, defaulted with FALSE
166 BOOL bSubLstOpLR
: 1; // open/close sublist with cursor left/right, defaulted with FALSE
167 BOOL bContextMenuHandling
: 1;
168 BOOL bIsCellFocusEnabled
: 1;
170 sal_Bool bAreChildrenTransient
;
175 // #102891# -------------------
176 IntlWrapper
* pIntlWrapper
;
178 // #97680# --------------------
179 std::vector
< short > aContextBmpWidthVector
;
181 DECL_LINK( EditTimerCall
, Timer
* );
183 DECL_LINK( BeginDragHdl
, void* );
184 DECL_LINK( MyUserEvent
,void*);
185 void StopUserEvent();
187 void InvalidateEntriesFrom( long nY
) const;
188 void InvalidateEntry( long nY
) const;
190 // setzt Thumb auf FirstEntryToDraw
192 BOOL
IsLineVisible( long nY
) const;
193 long GetEntryLine( SvLBoxEntry
* pEntry
) const;
197 void KeyLeftRight( long nDiff
);
198 void PageDown( USHORT nDelta
);
199 void PageUp( USHORT nDelta
);
201 void SetCursor( SvLBoxEntry
* pEntry
, BOOL bForceNoSelect
= FALSE
);
206 DECL_LINK( ScrollUpDownHdl
, ScrollBar
* );
207 DECL_LINK( ScrollLeftRightHdl
, ScrollBar
* );
208 DECL_LINK( EndScrollHdl
, ScrollBar
* );
210 void SetNodeBmpYOffset( const Image
& );
211 void SetNodeBmpTabDistance();
214 SvLBoxEntry
* MakePointVisible( const Point
& rPoint
,
215 BOOL bNotifyScroll
=TRUE
);
217 void SetAnchorSelection( SvLBoxEntry
* pOld
,
218 SvLBoxEntry
* pNewCursor
);
220 BOOL
ButtonDownCheckCtrl( const MouseEvent
& rMEvt
,
221 SvLBoxEntry
* pEntry
, long nY
);
222 BOOL
MouseMoveCheckCtrl( const MouseEvent
& rMEvt
,
223 SvLBoxEntry
* pEntry
);
224 BOOL
ButtonUpCheckCtrl( const MouseEvent
& rMEvt
);
225 BOOL
ButtonDownCheckExpand( const MouseEvent
&,
226 SvLBoxEntry
*,long nY
);
228 void PositionScrollBars( Size
& rOSize
, USHORT nMask
);
229 USHORT
AdjustScrollBars( Size
& rSize
);
233 BOOL
InScroll() const { return (BOOL
)(nFlags
& F_IN_SCROLLING
)!=0;}
234 Rectangle
GetVisibleArea() const;
235 BOOL
EntryReallyHit(SvLBoxEntry
* pEntry
,const Point
& rPos
,long nLine
);
236 void InitScrollBarBox();
237 SvLBoxTab
* NextTab( SvLBoxTab
* );
239 BOOL
SetMostRight( SvLBoxEntry
* pEntry
);
240 void FindMostRight( SvLBoxEntry
* EntryToIgnore
);
241 void FindMostRight( SvLBoxEntry
* pParent
, SvLBoxEntry
* EntryToIgnore
);
242 void FindMostRight_Impl( SvLBoxEntry
* pParent
,SvLBoxEntry
* EntryToIgnore
);
243 void NotifyTabsChanged();
245 inline BOOL
IsExpandable() const // if element at cursor can be expanded in general
246 { return pCursor
->HasChilds() || pCursor
->HasChildsOnDemand(); }
247 inline BOOL
IsNowExpandable() const // if element at cursor can be expanded at this moment
248 { return IsExpandable() && !pView
->IsExpanded( pCursor
); }
250 static void implInitDefaultNodeImages();
252 // #102891# -------------------
253 void UpdateIntlWrapper();
255 // #97680# --------------------
256 short UpdateContextBmpWidthVector( SvLBoxEntry
* pEntry
, short nWidth
);
257 void UpdateContextBmpWidthMax( SvLBoxEntry
* pEntry
);
258 void UpdateContextBmpWidthVectorFromMovedEntry( SvLBoxEntry
* pEntry
);
260 void CalcCellFocusRect( SvLBoxEntry
* pEntry
, Rectangle
& rRect
);
262 inline sal_Bool
AreChildrenTransient() const { return bAreChildrenTransient
; }
263 inline void SetChildrenNotTransient() { bAreChildrenTransient
= sal_False
; }
266 SvImpLBox( SvTreeListBox
* pView
, SvLBoxTreeList
*, WinBits nWinStyle
);
270 void SetWindowBits( WinBits nWinStyle
);
271 void SetExtendedWindowBits( ExtendedWinBits _nBits
);
272 ExtendedWinBits
GetExtendedWindowBits() const { return nExtendedWinBits
; }
273 void SetModel( SvLBoxTreeList
* pModel
) { pTree
= pModel
;}
275 void EntryInserted( SvLBoxEntry
*);
276 void RemovingEntry( SvLBoxEntry
* pEntry
);
278 void MovingEntry( SvLBoxEntry
* pEntry
);
279 void EntryMoved( SvLBoxEntry
* pEntry
);
280 void TreeInserted( SvLBoxEntry
* pEntry
);
282 void IndentChanged( short nIndentPixel
);
283 void EntryExpanded( SvLBoxEntry
* pEntry
);
284 void EntryCollapsed( SvLBoxEntry
* pEntry
);
285 void CollapsingEntry( SvLBoxEntry
* pEntry
);
286 void EntrySelected( SvLBoxEntry
*, BOOL bSelect
);
288 void Paint( const Rectangle
& rRect
);
289 void RepaintSelectionItems();
290 void MouseButtonDown( const MouseEvent
& );
291 void MouseButtonUp( const MouseEvent
& );
292 void MouseMove( const MouseEvent
&);
293 BOOL
KeyInput( const KeyEvent
& );
298 BOOL bInvalidateCompleteView
= TRUE
,
299 BOOL bUpdateVerSBar
= TRUE
);
300 void SetEntryHeight( short nHeight
);
301 void PaintEntry( SvLBoxEntry
* pEntry
);
302 void InvalidateEntry( SvLBoxEntry
* );
303 void RecalcFocusRect();
305 inline void SelectEntry( SvLBoxEntry
* pEntry
, BOOL bSelect
);
306 void SetDragDropMode( DragDropMode eDDMode
);
307 void SetSelectionMode( SelectionMode eSelMode
);
308 void SetAddMode( BOOL
) { aSelEng
.AddAlways(FALSE
); }
309 BOOL
IsAddMode() const { return aSelEng
.IsAlwaysAdding(); }
311 SvLBoxEntry
* GetCurrentEntry() const { return pCursor
; }
312 BOOL
IsEntryInView( SvLBoxEntry
* ) const;
313 SvLBoxEntry
* GetEntry( const Point
& rPos
) const;
314 // gibt letzten Eintrag zurueck, falls Pos unter letztem Eintrag
315 SvLBoxEntry
* GetClickedEntry( const Point
& ) const;
316 SvLBoxEntry
* GetCurEntry() const { return pCursor
; }
317 void SetCurEntry( SvLBoxEntry
* );
318 Point
GetEntryPosition( SvLBoxEntry
* ) const;
319 void MakeVisible( SvLBoxEntry
* pEntry
, BOOL bMoveToTop
=FALSE
);
321 void PaintDDCursor( SvLBoxEntry
* );
324 inline Image
& implGetImageLocation( const ImageType _eType
, BmpColorMode _eMode
);
325 inline Image
& implGetImageLocationWithFallback( const ImageType _eType
, BmpColorMode _eMode
) const;
327 inline void SetExpandedNodeBmp( const Image
& _rImg
, BmpColorMode _eMode
= BMP_COLOR_NORMAL
);
328 inline void SetCollapsedNodeBmp( const Image
& _rImg
, BmpColorMode _eMode
= BMP_COLOR_NORMAL
);
329 inline void SetDontKnowNodeBmp( const Image
& rImg
, BmpColorMode _eMode
= BMP_COLOR_NORMAL
);
331 inline const Image
& GetExpandedNodeBmp( BmpColorMode _eMode
= BMP_COLOR_NORMAL
) const;
332 inline const Image
& GetCollapsedNodeBmp( BmpColorMode _eMode
= BMP_COLOR_NORMAL
) const;
333 inline const Image
& GetDontKnowNodeBmp( BmpColorMode _eMode
= BMP_COLOR_NORMAL
) const;
335 inline void SetDefaultEntryExpBmp( const Image
& _rImg
, BmpColorMode _eMode
= BMP_COLOR_NORMAL
);
336 inline void SetDefaultEntryColBmp( const Image
& _rImg
, BmpColorMode _eMode
= BMP_COLOR_NORMAL
);
337 inline const Image
& GetDefaultEntryExpBmp( BmpColorMode _eMode
= BMP_COLOR_NORMAL
);
338 inline const Image
& GetDefaultEntryColBmp( BmpColorMode _eMode
= BMP_COLOR_NORMAL
);
340 static const Image
& GetDefaultExpandedNodeImage( BmpColorMode _eMode
= BMP_COLOR_NORMAL
);
341 static const Image
& GetDefaultCollapsedNodeImage( BmpColorMode _eMode
= BMP_COLOR_NORMAL
);
343 const Size
& GetOutputSize() const { return aOutputSize
;}
344 void KeyUp( BOOL bPageUp
, BOOL bNotifyScroll
= TRUE
);
345 void KeyDown( BOOL bPageDown
, BOOL bNotifyScroll
= TRUE
);
346 void Command( const CommandEvent
& rCEvt
);
349 void DestroyAnchor() { pAnchor
=0; aSelEng
.Reset(); }
350 void SelAllDestrAnch( BOOL bSelect
,
351 BOOL bDestroyAnchor
= TRUE
,
352 BOOL bSingleSelToo
= FALSE
);
353 void ShowCursor( BOOL bShow
);
355 BOOL
RequestHelp( const HelpEvent
& rHEvt
);
357 BOOL
IsNodeButton( const Point
& rPosPixel
, SvLBoxEntry
* pEntry
) const;
358 void RepaintScrollBars();
359 void EnableAsyncDrag( BOOL b
) { bAsyncBeginDrag
= b
; }
360 void SetUpdateMode( BOOL
);
361 void SetUpdateModeFast( BOOL
);
362 BOOL
GetUpdateMode() const { return bUpdateMode
; }
363 Rectangle
GetClipRegionRect() const;
364 BOOL
HasHorScrollBar() const { return aHorSBar
.IsVisible(); }
365 void ShowFocusRect( const SvLBoxEntry
* pEntry
);
366 void SetTabBar( TabBar
* pTabBar
);
367 void CancelPendingEdit();
369 void CallEventListeners( ULONG nEvent
, void* pData
= NULL
);
371 /** Enables, that one cell of a tablistbox entry can be focused */
372 inline BOOL
IsCellFocusEnabled() const { return bIsCellFocusEnabled
; }
373 inline void EnableCellFocus() { bIsCellFocusEnabled
= TRUE
; }
374 bool SetCurrentTabPos( USHORT _nNewPos
);
375 inline USHORT
GetCurrentTabPos() const { return nCurTabPos
; }
377 bool IsSelectable( const SvLBoxEntry
* pEntry
);
380 inline Image
& SvImpLBox::implGetImageLocation( const ImageType _eType
, BmpColorMode _eMode
)
382 DBG_ASSERT( ( BMP_COLOR_HIGHCONTRAST
== _eMode
) || ( BMP_COLOR_NORMAL
== _eMode
),
383 "SvImpLBox::implGetImageLocation: invalid mode!" );
384 DBG_ASSERT( ( _eType
>= 0 ) && ( _eType
< IT_IMAGE_COUNT
),
385 "SvImpLBox::implGetImageLocation: invalid image index (will crash)!" );
387 Image
* _pSet
= ( BMP_COLOR_HIGHCONTRAST
== _eMode
) ? m_aNodeAndEntryImages_HC
: m_aNodeAndEntryImages
;
388 return *( _pSet
+ (sal_Int32
)_eType
);
391 inline Image
& SvImpLBox::implGetImageLocationWithFallback( const ImageType _eType
, BmpColorMode _eMode
) const
393 Image
& rImage
= const_cast< SvImpLBox
* >( this )->implGetImageLocation( _eType
, _eMode
);
395 // fallback to normal images in case the one for the special mode has not been set
396 rImage
= const_cast< SvImpLBox
* >( this )->implGetImageLocation( _eType
, BMP_COLOR_NORMAL
);
400 inline void SvImpLBox::SetDontKnowNodeBmp( const Image
& rImg
, BmpColorMode _eMode
)
402 implGetImageLocation( itNodeDontKnow
, _eMode
) = rImg
;
405 inline void SvImpLBox::SetExpandedNodeBmp( const Image
& rImg
, BmpColorMode _eMode
)
407 implGetImageLocation( itNodeExpanded
, _eMode
) = rImg
;
408 SetNodeBmpYOffset( rImg
);
411 inline void SvImpLBox::SetCollapsedNodeBmp( const Image
& rImg
, BmpColorMode _eMode
)
413 implGetImageLocation( itNodeCollapsed
, _eMode
) = rImg
;
414 SetNodeBmpYOffset( rImg
);
417 inline const Image
& SvImpLBox::GetDontKnowNodeBmp( BmpColorMode _eMode
) const
419 return implGetImageLocationWithFallback( itNodeDontKnow
, _eMode
);
422 inline const Image
& SvImpLBox::GetExpandedNodeBmp( BmpColorMode _eMode
) const
424 return implGetImageLocationWithFallback( itNodeExpanded
, _eMode
);
427 inline const Image
& SvImpLBox::GetCollapsedNodeBmp( BmpColorMode _eMode
) const
429 return implGetImageLocationWithFallback( itNodeCollapsed
, _eMode
);
432 inline void SvImpLBox::SetDefaultEntryExpBmp( const Image
& _rImg
, BmpColorMode _eMode
)
434 implGetImageLocation( itEntryDefExpanded
, _eMode
) = _rImg
;
437 inline void SvImpLBox::SetDefaultEntryColBmp( const Image
& _rImg
, BmpColorMode _eMode
)
439 implGetImageLocation( itEntryDefCollapsed
, _eMode
) = _rImg
;
442 inline const Image
& SvImpLBox::GetDefaultEntryExpBmp( BmpColorMode _eMode
)
444 return implGetImageLocationWithFallback( itEntryDefExpanded
, _eMode
);
447 inline const Image
& SvImpLBox::GetDefaultEntryColBmp( BmpColorMode _eMode
)
449 return implGetImageLocationWithFallback( itEntryDefCollapsed
, _eMode
);
452 inline Point
SvImpLBox::GetEntryPosition( SvLBoxEntry
* pEntry
) const
454 return Point( 0, GetEntryLine( pEntry
) );
457 inline void SvImpLBox::PaintEntry( SvLBoxEntry
* pEntry
)
459 long nY
= GetEntryLine( pEntry
);
460 pView
->PaintEntry( pEntry
, nY
);
463 inline BOOL
SvImpLBox::IsLineVisible( long nY
) const
466 if ( nY
< 0 || nY
>= aOutputSize
.Height() )
471 inline void SvImpLBox::TreeInserted( SvLBoxEntry
* pInsTree
)
473 EntryInserted( pInsTree
);
476 #endif // #ifndef _SVIMPLBOX_HXX