xref: /trunk/main/svtools/source/inc/svimpbox.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _SVIMPLBOX_HXX
29 #define _SVIMPLBOX_HXX
30 
31 #ifndef _SELENG_HXX
32 #include <vcl/seleng.hxx>
33 #endif
34 #ifndef _SCRBAR_HXX
35 #include <vcl/scrbar.hxx>
36 #endif
37 #include <vcl/vclevent.hxx>
38 // #102891# ----------------
39 #include <unotools/intlwrapper.hxx>
40 // #97680# -----------------
41 #include <vector>
42 #include "svtaccessiblefactory.hxx"
43 
44 class SvTreeListBox;
45 class Point;
46 class DropEvent;
47 class SvLBoxTreeList;
48 class SvImpLBox;
49 class SvLBoxEntry;
50 class SvLBoxItem;
51 class SvLBoxTab;
52 class TabBar;
53 
54 class ImpLBSelEng : public FunctionSet
55 {
56 	SvImpLBox* 			pImp;
57 	SelectionEngine*	pSelEng;
58 	SvTreeListBox*		pView;
59 
60 public:
61 	ImpLBSelEng( SvImpLBox* pImp, SelectionEngine* pSelEng,
62 				 SvTreeListBox* pView );
63 	virtual ~ImpLBSelEng();
64 	void 		BeginDrag();
65 	void 		CreateAnchor();
66 	void		DestroyAnchor();
67 	sal_Bool 		SetCursorAtPoint( const Point& rPoint,
68 					sal_Bool bDontSelectAtCursor=sal_False );
69 	sal_Bool 		IsSelectionAtPoint( const Point& rPoint );
70 	void 		DeselectAtPoint( const Point& rPoint );
71 	void 		DeselectAll();
72 };
73 
74 // Flags fuer nFlag
75 #define F_VER_SBARSIZE_WITH_HBAR		0x0001
76 #define F_HOR_SBARSIZE_WITH_VBAR		0x0002
77 #define F_IGNORE_NEXT_MOUSEMOVE			0x0004	// OS/2 only
78 #define F_IN_SCROLLING					0x0008
79 #define F_DESEL_ALL						0x0010
80 #define F_START_EDITTIMER				0x0020 	// MAC only
81 #define F_IGNORE_SELECT					0x0040
82 #define F_IN_RESIZE						0x0080
83 #define F_REMOVED_ENTRY_INVISIBLE		0x0100
84 #define F_REMOVED_RECALC_MOST_RIGHT		0x0200
85 #define F_IGNORE_CHANGED_TABS			0x0400
86 #define F_PAINTED						0x0800
87 #define F_IN_PAINT						0x1000
88 #define F_ENDSCROLL_SET_VIS_SIZE	   	0x2000
89 #define F_FILLING 						0x4000
90 
91 
92 class SvImpLBox
93 {
94 friend class ImpLBSelEng;
95 friend class SvTreeListBox;
96 private:
97 	SvTreeListBox* 		pView;
98 	SvLBoxTreeList*		pTree;
99 	SvLBoxEntry*		pCursor;
100 	SvLBoxEntry*		pStartEntry;
101 	SvLBoxEntry*  		pAnchor;
102 	SvLBoxEntry*		pMostRightEntry;
103 	SvLBoxButton* 		pActiveButton;
104 	SvLBoxEntry* 		pActiveEntry;
105 	SvLBoxTab* 			pActiveTab;
106 	TabBar*				pTabBar;
107 
108 	ScrollBar   		aVerSBar;
109 	ScrollBar   		aHorSBar;
110 	ScrollBarBox 		aScrBarBox;
111 
112     ::svt::AccessibleFactoryAccess
113                         m_aFactoryAccess;
114 
115 	static Image*		s_pDefCollapsed;
116 	static Image*		s_pDefExpanded;
117 	static Image*		s_pDefCollapsedHC;
118 	static Image*		s_pDefExpandedHC;
119 	static oslInterlockedCount	s_nImageRefCount; /// When 0 all static images will be destroyed
120 
121 	// Node Bitmaps
122 	enum ImageType
123 	{
124 		itNodeExpanded = 0,		// node is expanded ( usually a bitmap showing a minus )
125 		itNodeCollapsed,		// node is collapsed ( usually a bitmap showing a plus )
126 		itNodeDontKnow,			// don't know the node state
127 		itEntryDefExpanded,		// default for expanded entries
128 		itEntryDefCollapsed,	// default for collapsed entries
129 
130 		IT_IMAGE_COUNT
131 	};
132 
133 	// all our images
134 	Image				m_aNodeAndEntryImages[ IT_IMAGE_COUNT ];
135 	// plus the high contrast versions
136 	Image				m_aNodeAndEntryImages_HC[ IT_IMAGE_COUNT ];
137 
138 	// wg. kompat. hier
139 	Size    			aOutputSize;
140 	SelectionEngine 	aSelEng;
141 	ImpLBSelEng			aFctSet;
142 	Timer				aAsyncBeginDragTimer;
143 	Point				aAsyncBeginDragPos;
144 
145 	long				nYoffsNodeBmp;
146 	long				nNodeBmpTabDistance; // typisch kleiner 0
147 	long				nNodeBmpWidth;
148 	long				nNextVerVisSize;
149 	long 				nMostRight;
150 	sal_uLong     			nVisibleCount;  // Anzahl Zeilen im Control
151 	sal_uLong				nCurUserEvent; //-1 == kein Userevent amn Laufen
152 	short				nHorSBarHeight, nVerSBarWidth;
153 	sal_uInt16				nFlags;
154 	sal_uInt16				nCurTabPos;
155 
156 	WinBits				m_nStyle;
157     ExtendedWinBits     nExtendedWinBits;
158 	sal_Bool				bSimpleTravel : 1; // ist sal_True bei SINGLE_SELECTION
159 	sal_Bool				bUpdateMode : 1;
160 	sal_Bool				bInVScrollHdl : 1;
161 	sal_Bool				bAsyncBeginDrag : 1;
162 	sal_Bool				bSubLstOpRet : 1;	// open/close sublist with return/enter, defaulted with sal_False
163 	sal_Bool				bSubLstOpLR : 1;	// open/close sublist with cursor left/right, defaulted with sal_False
164 	sal_Bool				bContextMenuHandling : 1;
165 	sal_Bool				bIsCellFocusEnabled : 1;
166 
167     sal_Bool            bAreChildrenTransient;
168 
169 	Point				aEditClickPos;
170 	Timer				aEditTimer;
171 
172 	// #102891# -------------------
173 	IntlWrapper *		pIntlWrapper;
174 
175 	// #97680# --------------------
176 	std::vector< short > aContextBmpWidthVector;
177 
178 	DECL_LINK( EditTimerCall, Timer * );
179 
180 	DECL_LINK( BeginDragHdl, void* );
181 	DECL_LINK( MyUserEvent,void*);
182 	void				StopUserEvent();
183 
184 	void 				InvalidateEntriesFrom( long nY ) const;
185 	void 				InvalidateEntry( long nY ) const;
186 	void 				ShowVerSBar();
187 	// setzt Thumb auf FirstEntryToDraw
188 	void 				SyncVerThumb();
189 	sal_Bool 				IsLineVisible( long nY ) const;
190 	long 				GetEntryLine( SvLBoxEntry* pEntry ) const;
191 	void				FillView();
192 	void 				CursorDown();
193 	void 				CursorUp();
194 	void				KeyLeftRight( long nDiff );
195 	void 				PageDown( sal_uInt16 nDelta );
196 	void 				PageUp( sal_uInt16 nDelta );
197 
198 	void				SetCursor( SvLBoxEntry* pEntry, sal_Bool bForceNoSelect = sal_False );
199 
200 	void 				DrawNet();
201 
202 	// ScrollBar-Handler
203 	DECL_LINK( ScrollUpDownHdl, ScrollBar * );
204 	DECL_LINK( ScrollLeftRightHdl, ScrollBar * );
205 	DECL_LINK( EndScrollHdl, ScrollBar * );
206 
207 	void				SetNodeBmpYOffset( const Image& );
208 	void				SetNodeBmpTabDistance();
209 
210 	// Selection-Engine
211 	SvLBoxEntry*  		MakePointVisible( const Point& rPoint,
212 							sal_Bool bNotifyScroll=sal_True );
213 
214 	void        		SetAnchorSelection( SvLBoxEntry* pOld,
215 							SvLBoxEntry* pNewCursor );
216 	void        		BeginDrag();
217 	sal_Bool				ButtonDownCheckCtrl( const MouseEvent& rMEvt,
218 							SvLBoxEntry* pEntry, long nY	);
219 	sal_Bool				MouseMoveCheckCtrl( const MouseEvent& rMEvt,
220 							SvLBoxEntry* pEntry );
221 	sal_Bool				ButtonUpCheckCtrl( const MouseEvent& rMEvt );
222 	sal_Bool 				ButtonDownCheckExpand( const MouseEvent&,
223 							SvLBoxEntry*,long nY );
224 
225 	void				PositionScrollBars( Size& rOSize, sal_uInt16 nMask );
226 	sal_uInt16				AdjustScrollBars( Size& rSize );
227 
228 	void				BeginScroll();
229 	void				EndScroll();
230 	sal_Bool				InScroll() const { return (sal_Bool)(nFlags & F_IN_SCROLLING)!=0;}
231 	Rectangle			GetVisibleArea() const;
232 	sal_Bool				EntryReallyHit(SvLBoxEntry* pEntry,const Point& rPos,long nLine);
233 	void				InitScrollBarBox();
234 	SvLBoxTab*			NextTab( SvLBoxTab* );
235 
236 	sal_Bool				SetMostRight( SvLBoxEntry* pEntry );
237 	void				FindMostRight( SvLBoxEntry* EntryToIgnore );
238 	void 				FindMostRight( SvLBoxEntry* pParent, SvLBoxEntry* EntryToIgnore );
239 	void 				FindMostRight_Impl( SvLBoxEntry* pParent,SvLBoxEntry* EntryToIgnore  );
240 	void				NotifyTabsChanged();
241 
242 	inline sal_Bool			IsExpandable() const		// if element at cursor can be expanded in general
243 							{ return pCursor->HasChilds() || pCursor->HasChildsOnDemand(); }
244 	inline sal_Bool			IsNowExpandable() const		// if element at cursor can be expanded at this moment
245 							{ return IsExpandable() && !pView->IsExpanded( pCursor ); }
246 
247 	static	void		implInitDefaultNodeImages();
248 
249 	// #102891# -------------------
250 	void 				UpdateIntlWrapper();
251 
252 	// #97680# --------------------
253 	short				UpdateContextBmpWidthVector( SvLBoxEntry* pEntry, short nWidth );
254 	void				UpdateContextBmpWidthMax( SvLBoxEntry* pEntry );
255 	void				UpdateContextBmpWidthVectorFromMovedEntry( SvLBoxEntry* pEntry );
256 
257 	void				CalcCellFocusRect( SvLBoxEntry* pEntry, Rectangle& rRect );
258 
259     inline sal_Bool     AreChildrenTransient() const { return bAreChildrenTransient; }
260     inline void         SetChildrenNotTransient() { bAreChildrenTransient = sal_False; }
261 
262 public:
263 	SvImpLBox( SvTreeListBox* pView, SvLBoxTreeList*, WinBits nWinStyle );
264 	~SvImpLBox();
265 
266 	void 				Clear();
267     void                SetStyle( WinBits i_nWinStyle );
268 	void 				SetExtendedWindowBits( ExtendedWinBits _nBits );
269     ExtendedWinBits     GetExtendedWindowBits() const { return nExtendedWinBits; }
270 	void 				SetModel( SvLBoxTreeList* pModel ) { pTree = pModel;}
271 
272 	void 				EntryInserted( SvLBoxEntry*);
273 	void 				RemovingEntry( SvLBoxEntry* pEntry );
274 	void 				EntryRemoved();
275 	void 				MovingEntry( SvLBoxEntry* pEntry );
276 	void 				EntryMoved( SvLBoxEntry* pEntry );
277 	void 				TreeInserted( SvLBoxEntry* pEntry );
278 
279 	void 				IndentChanged( short nIndentPixel );
280 	void 				EntryExpanded( SvLBoxEntry* pEntry );
281 	void 				EntryCollapsed( SvLBoxEntry* pEntry );
282 	void 				CollapsingEntry( SvLBoxEntry* pEntry );
283 	void 				EntrySelected( SvLBoxEntry*, sal_Bool bSelect );
284 
285 	void	 			Paint( const Rectangle& rRect );
286 	void 				RepaintSelectionItems();
287 	void 				MouseButtonDown( const MouseEvent& );
288 	void 				MouseButtonUp( const MouseEvent& );
289 	void 				MouseMove( const MouseEvent&);
290 	sal_Bool 				KeyInput( const KeyEvent& );
291 	void 				Resize();
292 	void 				GetFocus();
293 	void 				LoseFocus();
294 	void 				UpdateAll(
295 							sal_Bool bInvalidateCompleteView= sal_True,
296 							sal_Bool bUpdateVerSBar = sal_True );
297 	void 				SetEntryHeight( short nHeight );
298 	void 				PaintEntry( SvLBoxEntry* pEntry );
299 	void 				InvalidateEntry( SvLBoxEntry* );
300 	void 				RecalcFocusRect();
301 
302 	inline void 		SelectEntry( SvLBoxEntry* pEntry, sal_Bool bSelect );
303 	void 				SetDragDropMode( DragDropMode eDDMode );
304 	void 				SetSelectionMode( SelectionMode eSelMode  );
305 	void				SetAddMode( sal_Bool ) { aSelEng.AddAlways(sal_False); }
306 	sal_Bool				IsAddMode() const { return aSelEng.IsAlwaysAdding(); }
307 
308 	SvLBoxEntry* 		GetCurrentEntry() const { return pCursor; }
309 	sal_Bool				IsEntryInView( SvLBoxEntry* ) const;
310 	SvLBoxEntry* 		GetEntry( const Point& rPos ) const;
311 	// gibt letzten Eintrag zurueck, falls Pos unter letztem Eintrag
312 	SvLBoxEntry* 		GetClickedEntry( const Point& ) const;
313 	SvLBoxEntry* 		GetCurEntry() const { return pCursor; }
314 	void				SetCurEntry( SvLBoxEntry* );
315 	Point 				GetEntryPosition( SvLBoxEntry* ) const;
316 	void 				MakeVisible( SvLBoxEntry* pEntry, sal_Bool bMoveToTop=sal_False );
317 
318 	void 				PaintDDCursor( SvLBoxEntry* );
319 
320 	// Images
321 	inline Image&		implGetImageLocation( const ImageType _eType, BmpColorMode _eMode );
322 	inline Image&		implGetImageLocationWithFallback( const ImageType _eType, BmpColorMode _eMode ) const;
323 
324 	inline void 		SetExpandedNodeBmp( const Image& _rImg, BmpColorMode _eMode = BMP_COLOR_NORMAL );
325 	inline void 		SetCollapsedNodeBmp( const Image& _rImg, BmpColorMode _eMode = BMP_COLOR_NORMAL  );
326 	inline void 		SetDontKnowNodeBmp( const Image& rImg, BmpColorMode _eMode = BMP_COLOR_NORMAL );
327 
328 	inline const Image& GetExpandedNodeBmp( BmpColorMode _eMode = BMP_COLOR_NORMAL ) const;
329 	inline const Image& GetCollapsedNodeBmp( BmpColorMode _eMode = BMP_COLOR_NORMAL ) const;
330 	inline const Image&	GetDontKnowNodeBmp( BmpColorMode _eMode = BMP_COLOR_NORMAL ) const;
331 
332 	inline void			SetDefaultEntryExpBmp( const Image& _rImg, BmpColorMode _eMode = BMP_COLOR_NORMAL );
333 	inline void			SetDefaultEntryColBmp( const Image& _rImg, BmpColorMode _eMode = BMP_COLOR_NORMAL );
334 	inline const Image&	GetDefaultEntryExpBmp( BmpColorMode _eMode = BMP_COLOR_NORMAL );
335 	inline const Image&	GetDefaultEntryColBmp( BmpColorMode _eMode = BMP_COLOR_NORMAL );
336 
337 	static const Image&	GetDefaultExpandedNodeImage( BmpColorMode _eMode = BMP_COLOR_NORMAL );
338 	static const Image&	GetDefaultCollapsedNodeImage( BmpColorMode _eMode = BMP_COLOR_NORMAL );
339 
340 	const Size& 		GetOutputSize() const { return aOutputSize;}
341 	void 				KeyUp( sal_Bool bPageUp, sal_Bool bNotifyScroll = sal_True );
342 	void 				KeyDown( sal_Bool bPageDown, sal_Bool bNotifyScroll = sal_True );
343 	void                Command( const CommandEvent& rCEvt );
344 
345 	void				Invalidate();
346 	void				DestroyAnchor() { pAnchor=0; aSelEng.Reset(); }
347 	void        		SelAllDestrAnch( sal_Bool bSelect,
348 							sal_Bool bDestroyAnchor = sal_True,
349 							sal_Bool bSingleSelToo = sal_False );
350 	void				ShowCursor( sal_Bool bShow );
351 
352 	sal_Bool    			RequestHelp( const HelpEvent& rHEvt );
353 	void				EndSelection();
354 	sal_Bool				IsNodeButton( const Point& rPosPixel, SvLBoxEntry* pEntry ) const;
355 	void				RepaintScrollBars();
356 	void				EnableAsyncDrag( sal_Bool b) { bAsyncBeginDrag = b; }
357 	void				SetUpdateMode( sal_Bool );
358 	void 				SetUpdateModeFast( sal_Bool );
359 	sal_Bool				GetUpdateMode() const { return bUpdateMode; }
360 	Rectangle			GetClipRegionRect() const;
361 	sal_Bool				HasHorScrollBar() const { return aHorSBar.IsVisible(); }
362 	void				ShowFocusRect( const SvLBoxEntry* pEntry );
363 	void				SetTabBar( TabBar* pTabBar );
364 	void				CancelPendingEdit();
365 
366 	void				CallEventListeners( sal_uLong nEvent, void* pData = NULL );
367 
368 	/** Enables, that one cell of a tablistbox entry can be focused */
369 	inline sal_Bool			IsCellFocusEnabled() const { return bIsCellFocusEnabled; }
370 	inline void			EnableCellFocus() { bIsCellFocusEnabled = sal_True; }
371 	bool				SetCurrentTabPos( sal_uInt16 _nNewPos );
372 	inline sal_uInt16		GetCurrentTabPos() const { return nCurTabPos; }
373 
374 	bool				IsSelectable( const SvLBoxEntry* pEntry );
375 };
376 
377 inline Image& SvImpLBox::implGetImageLocation( const ImageType _eType, BmpColorMode _eMode )
378 {
379 	DBG_ASSERT( ( BMP_COLOR_HIGHCONTRAST == _eMode ) || ( BMP_COLOR_NORMAL == _eMode ),
380 		"SvImpLBox::implGetImageLocation: invalid mode!" );
381 	DBG_ASSERT( ( _eType >= 0 ) && ( _eType < IT_IMAGE_COUNT ),
382 		"SvImpLBox::implGetImageLocation: invalid image index (will crash)!" );
383 
384 	Image* _pSet = ( BMP_COLOR_HIGHCONTRAST == _eMode ) ? m_aNodeAndEntryImages_HC : m_aNodeAndEntryImages;
385 	return *( _pSet + (sal_Int32)_eType );
386 }
387 
388 inline Image& SvImpLBox::implGetImageLocationWithFallback( const ImageType _eType, BmpColorMode _eMode ) const
389 {
390 	Image& rImage = const_cast< SvImpLBox* >( this )->implGetImageLocation( _eType, _eMode );
391 	if ( !rImage )
392 		// fallback to normal images in case the one for the special mode has not been set
393 		rImage = const_cast< SvImpLBox* >( this )->implGetImageLocation( _eType, BMP_COLOR_NORMAL );
394 	return rImage;
395 }
396 
397 inline void SvImpLBox::SetDontKnowNodeBmp( const Image& rImg, BmpColorMode _eMode )
398 {
399 	implGetImageLocation( itNodeDontKnow, _eMode ) = rImg;
400 }
401 
402 inline void SvImpLBox::SetExpandedNodeBmp( const Image& rImg, BmpColorMode _eMode )
403 {
404 	implGetImageLocation( itNodeExpanded, _eMode ) = rImg;
405 	SetNodeBmpYOffset( rImg );
406 }
407 
408 inline void SvImpLBox::SetCollapsedNodeBmp( const Image& rImg, BmpColorMode _eMode )
409 {
410 	implGetImageLocation( itNodeCollapsed, _eMode ) = rImg;
411 	SetNodeBmpYOffset( rImg );
412 }
413 
414 inline const Image&	SvImpLBox::GetDontKnowNodeBmp( BmpColorMode _eMode ) const
415 {
416 	return implGetImageLocationWithFallback( itNodeDontKnow, _eMode );
417 }
418 
419 inline const Image& SvImpLBox::GetExpandedNodeBmp( BmpColorMode _eMode ) const
420 {
421 	return implGetImageLocationWithFallback( itNodeExpanded, _eMode );
422 }
423 
424 inline const Image& SvImpLBox::GetCollapsedNodeBmp( BmpColorMode _eMode ) const
425 {
426 	return implGetImageLocationWithFallback( itNodeCollapsed, _eMode );
427 }
428 
429 inline void SvImpLBox::SetDefaultEntryExpBmp( const Image& _rImg, BmpColorMode _eMode )
430 {
431 	implGetImageLocation( itEntryDefExpanded, _eMode ) = _rImg;
432 }
433 
434 inline void SvImpLBox::SetDefaultEntryColBmp( const Image& _rImg, BmpColorMode _eMode )
435 {
436 	implGetImageLocation( itEntryDefCollapsed, _eMode ) = _rImg;
437 }
438 
439 inline const Image&	SvImpLBox::GetDefaultEntryExpBmp( BmpColorMode _eMode )
440 {
441 	return implGetImageLocationWithFallback( itEntryDefExpanded, _eMode );
442 }
443 
444 inline const Image&	SvImpLBox::GetDefaultEntryColBmp( BmpColorMode _eMode )
445 {
446 	return implGetImageLocationWithFallback( itEntryDefCollapsed, _eMode );
447 }
448 
449 inline Point SvImpLBox::GetEntryPosition( SvLBoxEntry* pEntry ) const
450 {
451 	return Point( 0, GetEntryLine( pEntry ) );
452 }
453 
454 inline void SvImpLBox::PaintEntry( SvLBoxEntry* pEntry )
455 {
456 	long nY = GetEntryLine( pEntry );
457 	pView->PaintEntry( pEntry, nY );
458 }
459 
460 inline sal_Bool SvImpLBox::IsLineVisible( long nY ) const
461 {
462 	sal_Bool bRet = sal_True;
463 	if ( nY < 0 || nY >= aOutputSize.Height() )
464 		bRet = sal_False;
465 	return bRet;
466 }
467 
468 inline void SvImpLBox::TreeInserted( SvLBoxEntry* pInsTree )
469 {
470 	EntryInserted( pInsTree );
471 }
472 
473 #endif // #ifndef _SVIMPLBOX_HXX
474 
475