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