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 #ifndef _VCL_VCLEVENT_HXX
41 #include <vcl/vclevent.hxx>
43 // #102891# ----------------
44 #ifndef _UNOTOOLS_INTLWRAPPER_HXX
45 #include <unotools/intlwrapper.hxx>
47 // #97680# -----------------
50 #ifndef SVTOOLS_ACCESSIBLE_FACTORY_ACCESS_HXX
51 #include "svtaccessiblefactory.hxx"
69 class ImpLBSelEng
: public FunctionSet
72 SelectionEngine
* pSelEng
;
76 ImpLBSelEng( SvImpLBox
* pImp
, SelectionEngine
* pSelEng
,
77 SvTreeListBox
* pView
);
78 virtual ~ImpLBSelEng();
82 BOOL
SetCursorAtPoint( const Point
& rPoint
,
83 BOOL bDontSelectAtCursor
=FALSE
);
84 BOOL
IsSelectionAtPoint( const Point
& rPoint
);
85 void DeselectAtPoint( const Point
& rPoint
);
90 #define F_VER_SBARSIZE_WITH_HBAR 0x0001
91 #define F_HOR_SBARSIZE_WITH_VBAR 0x0002
92 #define F_IGNORE_NEXT_MOUSEMOVE 0x0004 // OS/2 only
93 #define F_IN_SCROLLING 0x0008
94 #define F_DESEL_ALL 0x0010
95 #define F_START_EDITTIMER 0x0020 // MAC only
96 #define F_IGNORE_SELECT 0x0040
97 #define F_IN_RESIZE 0x0080
98 #define F_REMOVED_ENTRY_INVISIBLE 0x0100
99 #define F_REMOVED_RECALC_MOST_RIGHT 0x0200
100 #define F_IGNORE_CHANGED_TABS 0x0400
101 #define F_PAINTED 0x0800
102 #define F_IN_PAINT 0x1000
103 #define F_ENDSCROLL_SET_VIS_SIZE 0x2000
104 #define F_FILLING 0x4000
109 friend class ImpLBSelEng
;
110 friend class SvTreeListBox
;
112 SvTreeListBox
* pView
;
113 SvLBoxTreeList
* pTree
;
114 SvLBoxEntry
* pCursor
;
115 SvLBoxEntry
* pStartEntry
;
116 SvLBoxEntry
* pAnchor
;
117 SvLBoxEntry
* pMostRightEntry
;
118 SvLBoxButton
* pActiveButton
;
119 SvLBoxEntry
* pActiveEntry
;
120 SvLBoxTab
* pActiveTab
;
125 ScrollBarBox aScrBarBox
;
127 AccessibleFactoryAccess
130 static Image
* s_pDefCollapsed
;
131 static Image
* s_pDefExpanded
;
132 static Image
* s_pDefCollapsedHC
;
133 static Image
* s_pDefExpandedHC
;
134 static oslInterlockedCount s_nImageRefCount
; /// When 0 all static images will be destroyed
139 itNodeExpanded
= 0, // node is expanded ( usually a bitmap showing a minus )
140 itNodeCollapsed
, // node is collapsed ( usually a bitmap showing a plus )
141 itNodeDontKnow
, // don't know the node state
142 itEntryDefExpanded
, // default for expanded entries
143 itEntryDefCollapsed
, // default for collapsed entries
149 Image m_aNodeAndEntryImages
[ IT_IMAGE_COUNT
];
150 // plus the high contrast versions
151 Image m_aNodeAndEntryImages_HC
[ IT_IMAGE_COUNT
];
155 SelectionEngine aSelEng
;
157 Timer aAsyncBeginDragTimer
;
158 Point aAsyncBeginDragPos
;
161 long nNodeBmpTabDistance
; // typisch kleiner 0
163 long nNextVerVisSize
;
165 ULONG nVisibleCount
; // Anzahl Zeilen im Control
166 ULONG nCurUserEvent
; //-1 == kein Userevent amn Laufen
167 short nHorSBarHeight
, nVerSBarWidth
;
172 ExtendedWinBits nExtendedWinBits
;
173 BOOL bSimpleTravel
: 1; // ist TRUE bei SINGLE_SELECTION
174 BOOL bUpdateMode
: 1;
175 BOOL bInVScrollHdl
: 1;
176 BOOL bAsyncBeginDrag
: 1;
177 BOOL bSubLstOpRet
: 1; // open/close sublist with return/enter, defaulted with FALSE
178 BOOL bSubLstOpLR
: 1; // open/close sublist with cursor left/right, defaulted with FALSE
179 BOOL bContextMenuHandling
: 1;
180 BOOL bIsCellFocusEnabled
: 1;
182 sal_Bool bAreChildrenTransient
;
187 // #102891# -------------------
188 IntlWrapper
* pIntlWrapper
;
190 // #97680# --------------------
191 std::vector
< short > aContextBmpWidthVector
;
193 DECL_LINK( EditTimerCall
, Timer
* );
195 DECL_LINK( BeginDragHdl
, void* );
196 DECL_LINK( MyUserEvent
,void*);
197 void StopUserEvent();
199 void InvalidateEntriesFrom( long nY
) const;
200 void InvalidateEntry( long nY
) const;
202 // setzt Thumb auf FirstEntryToDraw
204 BOOL
IsLineVisible( long nY
) const;
205 long GetEntryLine( SvLBoxEntry
* pEntry
) const;
209 void KeyLeftRight( long nDiff
);
210 void PageDown( USHORT nDelta
);
211 void PageUp( USHORT nDelta
);
213 void SetCursor( SvLBoxEntry
* pEntry
, BOOL bForceNoSelect
= FALSE
);
218 DECL_LINK( ScrollUpDownHdl
, ScrollBar
* );
219 DECL_LINK( ScrollLeftRightHdl
, ScrollBar
* );
220 DECL_LINK( EndScrollHdl
, ScrollBar
* );
222 void SetNodeBmpYOffset( const Image
& );
223 void SetNodeBmpTabDistance();
226 SvLBoxEntry
* MakePointVisible( const Point
& rPoint
,
227 BOOL bNotifyScroll
=TRUE
);
229 void SetAnchorSelection( SvLBoxEntry
* pOld
,
230 SvLBoxEntry
* pNewCursor
);
232 BOOL
ButtonDownCheckCtrl( const MouseEvent
& rMEvt
,
233 SvLBoxEntry
* pEntry
, long nY
);
234 BOOL
MouseMoveCheckCtrl( const MouseEvent
& rMEvt
,
235 SvLBoxEntry
* pEntry
);
236 BOOL
ButtonUpCheckCtrl( const MouseEvent
& rMEvt
);
237 BOOL
ButtonDownCheckExpand( const MouseEvent
&,
238 SvLBoxEntry
*,long nY
);
240 void PositionScrollBars( Size
& rOSize
, USHORT nMask
);
241 USHORT
AdjustScrollBars( Size
& rSize
);
245 BOOL
InScroll() const { return (BOOL
)(nFlags
& F_IN_SCROLLING
)!=0;}
246 Rectangle
GetVisibleArea() const;
247 BOOL
EntryReallyHit(SvLBoxEntry
* pEntry
,const Point
& rPos
,long nLine
);
248 void InitScrollBarBox();
249 SvLBoxTab
* NextTab( SvLBoxTab
* );
251 BOOL
SetMostRight( SvLBoxEntry
* pEntry
);
252 void FindMostRight( SvLBoxEntry
* EntryToIgnore
);
253 void FindMostRight( SvLBoxEntry
* pParent
, SvLBoxEntry
* EntryToIgnore
);
254 void FindMostRight_Impl( SvLBoxEntry
* pParent
,SvLBoxEntry
* EntryToIgnore
);
255 void NotifyTabsChanged();
257 inline BOOL
IsExpandable() const // if element at cursor can be expanded in general
258 { return pCursor
->HasChilds() || pCursor
->HasChildsOnDemand(); }
259 inline BOOL
IsNowExpandable() const // if element at cursor can be expanded at this moment
260 { return IsExpandable() && !pView
->IsExpanded( pCursor
); }
262 static void implInitDefaultNodeImages();
264 // #102891# -------------------
265 void UpdateIntlWrapper();
267 // #97680# --------------------
268 short UpdateContextBmpWidthVector( SvLBoxEntry
* pEntry
, short nWidth
);
269 void UpdateContextBmpWidthMax( SvLBoxEntry
* pEntry
);
270 void UpdateContextBmpWidthVectorFromMovedEntry( SvLBoxEntry
* pEntry
);
272 void CalcCellFocusRect( SvLBoxEntry
* pEntry
, Rectangle
& rRect
);
274 inline sal_Bool
AreChildrenTransient() const { return bAreChildrenTransient
; }
275 inline void SetChildrenNotTransient() { bAreChildrenTransient
= sal_False
; }
278 SvImpLBox( SvTreeListBox
* pView
, SvLBoxTreeList
*, WinBits nWinStyle
);
282 void SetWindowBits( WinBits nWinStyle
);
283 void SetExtendedWindowBits( ExtendedWinBits _nBits
);
284 ExtendedWinBits
GetExtendedWindowBits() const { return nExtendedWinBits
; }
285 void SetModel( SvLBoxTreeList
* pModel
) { pTree
= pModel
;}
287 void EntryInserted( SvLBoxEntry
*);
288 void RemovingEntry( SvLBoxEntry
* pEntry
);
290 void MovingEntry( SvLBoxEntry
* pEntry
);
291 void EntryMoved( SvLBoxEntry
* pEntry
);
292 void TreeInserted( SvLBoxEntry
* pEntry
);
294 void IndentChanged( short nIndentPixel
);
295 void EntryExpanded( SvLBoxEntry
* pEntry
);
296 void EntryCollapsed( SvLBoxEntry
* pEntry
);
297 void CollapsingEntry( SvLBoxEntry
* pEntry
);
298 void EntrySelected( SvLBoxEntry
*, BOOL bSelect
);
300 void Paint( const Rectangle
& rRect
);
301 void RepaintSelectionItems();
302 void MouseButtonDown( const MouseEvent
& );
303 void MouseButtonUp( const MouseEvent
& );
304 void MouseMove( const MouseEvent
&);
305 BOOL
KeyInput( const KeyEvent
& );
310 BOOL bInvalidateCompleteView
= TRUE
,
311 BOOL bUpdateVerSBar
= TRUE
);
312 void SetEntryHeight( short nHeight
);
313 void PaintEntry( SvLBoxEntry
* pEntry
);
314 void InvalidateEntry( SvLBoxEntry
* );
315 void RecalcFocusRect();
317 inline void SelectEntry( SvLBoxEntry
* pEntry
, BOOL bSelect
);
318 void SetDragDropMode( DragDropMode eDDMode
);
319 void SetSelectionMode( SelectionMode eSelMode
);
320 void SetAddMode( BOOL
) { aSelEng
.AddAlways(FALSE
); }
321 BOOL
IsAddMode() const { return aSelEng
.IsAlwaysAdding(); }
323 SvLBoxEntry
* GetCurrentEntry() const { return pCursor
; }
324 BOOL
IsEntryInView( SvLBoxEntry
* ) const;
325 SvLBoxEntry
* GetEntry( const Point
& rPos
) const;
326 // gibt letzten Eintrag zurueck, falls Pos unter letztem Eintrag
327 SvLBoxEntry
* GetClickedEntry( const Point
& ) const;
328 SvLBoxEntry
* GetCurEntry() const { return pCursor
; }
329 void SetCurEntry( SvLBoxEntry
* );
330 Point
GetEntryPosition( SvLBoxEntry
* ) const;
331 void MakeVisible( SvLBoxEntry
* pEntry
, BOOL bMoveToTop
=FALSE
);
333 void PaintDDCursor( SvLBoxEntry
* );
336 inline Image
& implGetImageLocation( const ImageType _eType
, BmpColorMode _eMode
);
337 inline Image
& implGetImageLocationWithFallback( const ImageType _eType
, BmpColorMode _eMode
) const;
339 inline void SetExpandedNodeBmp( const Image
& _rImg
, BmpColorMode _eMode
= BMP_COLOR_NORMAL
);
340 inline void SetCollapsedNodeBmp( const Image
& _rImg
, BmpColorMode _eMode
= BMP_COLOR_NORMAL
);
341 inline void SetDontKnowNodeBmp( const Image
& rImg
, BmpColorMode _eMode
= BMP_COLOR_NORMAL
);
343 inline const Image
& GetExpandedNodeBmp( BmpColorMode _eMode
= BMP_COLOR_NORMAL
) const;
344 inline const Image
& GetCollapsedNodeBmp( BmpColorMode _eMode
= BMP_COLOR_NORMAL
) const;
345 inline const Image
& GetDontKnowNodeBmp( BmpColorMode _eMode
= BMP_COLOR_NORMAL
) const;
347 inline void SetDefaultEntryExpBmp( const Image
& _rImg
, BmpColorMode _eMode
= BMP_COLOR_NORMAL
);
348 inline void SetDefaultEntryColBmp( const Image
& _rImg
, BmpColorMode _eMode
= BMP_COLOR_NORMAL
);
349 inline const Image
& GetDefaultEntryExpBmp( BmpColorMode _eMode
= BMP_COLOR_NORMAL
);
350 inline const Image
& GetDefaultEntryColBmp( BmpColorMode _eMode
= BMP_COLOR_NORMAL
);
352 static const Image
& GetDefaultExpandedNodeImage( BmpColorMode _eMode
= BMP_COLOR_NORMAL
);
353 static const Image
& GetDefaultCollapsedNodeImage( BmpColorMode _eMode
= BMP_COLOR_NORMAL
);
355 const Size
& GetOutputSize() const { return aOutputSize
;}
356 void KeyUp( BOOL bPageUp
, BOOL bNotifyScroll
= TRUE
);
357 void KeyDown( BOOL bPageDown
, BOOL bNotifyScroll
= TRUE
);
358 void Command( const CommandEvent
& rCEvt
);
361 void DestroyAnchor() { pAnchor
=0; aSelEng
.Reset(); }
362 void SelAllDestrAnch( BOOL bSelect
,
363 BOOL bDestroyAnchor
= TRUE
,
364 BOOL bSingleSelToo
= FALSE
);
365 void ShowCursor( BOOL bShow
);
367 BOOL
RequestHelp( const HelpEvent
& rHEvt
);
369 BOOL
IsNodeButton( const Point
& rPosPixel
, SvLBoxEntry
* pEntry
) const;
370 void RepaintScrollBars();
371 void EnableAsyncDrag( BOOL b
) { bAsyncBeginDrag
= b
; }
372 void SetUpdateMode( BOOL
);
373 void SetUpdateModeFast( BOOL
);
374 BOOL
GetUpdateMode() const { return bUpdateMode
; }
375 Rectangle
GetClipRegionRect() const;
376 BOOL
HasHorScrollBar() const { return aHorSBar
.IsVisible(); }
377 void ShowFocusRect( const SvLBoxEntry
* pEntry
);
378 void SetTabBar( TabBar
* pTabBar
);
379 void CancelPendingEdit();
381 void CallEventListeners( ULONG nEvent
, void* pData
= NULL
);
383 /** Enables, that one cell of a tablistbox entry can be focused */
384 inline BOOL
IsCellFocusEnabled() const { return bIsCellFocusEnabled
; }
385 inline void EnableCellFocus() { bIsCellFocusEnabled
= TRUE
; }
386 bool SetCurrentTabPos( USHORT _nNewPos
);
387 inline USHORT
GetCurrentTabPos() const { return nCurTabPos
; }
389 bool IsSelectable( const SvLBoxEntry
* pEntry
);
392 inline Image
& SvImpLBox::implGetImageLocation( const ImageType _eType
, BmpColorMode _eMode
)
394 DBG_ASSERT( ( BMP_COLOR_HIGHCONTRAST
== _eMode
) || ( BMP_COLOR_NORMAL
== _eMode
),
395 "SvImpLBox::implGetImageLocation: invalid mode!" );
396 DBG_ASSERT( ( _eType
>= 0 ) && ( _eType
< IT_IMAGE_COUNT
),
397 "SvImpLBox::implGetImageLocation: invalid image index (will crash)!" );
399 Image
* _pSet
= ( BMP_COLOR_HIGHCONTRAST
== _eMode
) ? m_aNodeAndEntryImages_HC
: m_aNodeAndEntryImages
;
400 return *( _pSet
+ (sal_Int32
)_eType
);
403 inline Image
& SvImpLBox::implGetImageLocationWithFallback( const ImageType _eType
, BmpColorMode _eMode
) const
405 Image
& rImage
= const_cast< SvImpLBox
* >( this )->implGetImageLocation( _eType
, _eMode
);
407 // fallback to normal images in case the one for the special mode has not been set
408 rImage
= const_cast< SvImpLBox
* >( this )->implGetImageLocation( _eType
, BMP_COLOR_NORMAL
);
412 inline void SvImpLBox::SetDontKnowNodeBmp( const Image
& rImg
, BmpColorMode _eMode
)
414 implGetImageLocation( itNodeDontKnow
, _eMode
) = rImg
;
417 inline void SvImpLBox::SetExpandedNodeBmp( const Image
& rImg
, BmpColorMode _eMode
)
419 implGetImageLocation( itNodeExpanded
, _eMode
) = rImg
;
420 SetNodeBmpYOffset( rImg
);
423 inline void SvImpLBox::SetCollapsedNodeBmp( const Image
& rImg
, BmpColorMode _eMode
)
425 implGetImageLocation( itNodeCollapsed
, _eMode
) = rImg
;
426 SetNodeBmpYOffset( rImg
);
429 inline const Image
& SvImpLBox::GetDontKnowNodeBmp( BmpColorMode _eMode
) const
431 return implGetImageLocationWithFallback( itNodeDontKnow
, _eMode
);
434 inline const Image
& SvImpLBox::GetExpandedNodeBmp( BmpColorMode _eMode
) const
436 return implGetImageLocationWithFallback( itNodeExpanded
, _eMode
);
439 inline const Image
& SvImpLBox::GetCollapsedNodeBmp( BmpColorMode _eMode
) const
441 return implGetImageLocationWithFallback( itNodeCollapsed
, _eMode
);
444 inline void SvImpLBox::SetDefaultEntryExpBmp( const Image
& _rImg
, BmpColorMode _eMode
)
446 implGetImageLocation( itEntryDefExpanded
, _eMode
) = _rImg
;
449 inline void SvImpLBox::SetDefaultEntryColBmp( const Image
& _rImg
, BmpColorMode _eMode
)
451 implGetImageLocation( itEntryDefCollapsed
, _eMode
) = _rImg
;
454 inline const Image
& SvImpLBox::GetDefaultEntryExpBmp( BmpColorMode _eMode
)
456 return implGetImageLocationWithFallback( itEntryDefExpanded
, _eMode
);
459 inline const Image
& SvImpLBox::GetDefaultEntryColBmp( BmpColorMode _eMode
)
461 return implGetImageLocationWithFallback( itEntryDefCollapsed
, _eMode
);
464 inline Point
SvImpLBox::GetEntryPosition( SvLBoxEntry
* pEntry
) const
466 return Point( 0, GetEntryLine( pEntry
) );
469 inline void SvImpLBox::PaintEntry( SvLBoxEntry
* pEntry
)
471 long nY
= GetEntryLine( pEntry
);
472 pView
->PaintEntry( pEntry
, nY
);
475 inline BOOL
SvImpLBox::IsLineVisible( long nY
) const
478 if ( nY
< 0 || nY
>= aOutputSize
.Height() )
483 inline void SvImpLBox::TreeInserted( SvLBoxEntry
* pInsTree
)
485 EntryInserted( pInsTree
);
490 #endif // #ifndef _SVIMPLBOX_HXX