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 _SVTREEBOX_HXX
30 : : #define _SVTREEBOX_HXX
31 : :
32 : : #include "svtools/svtdllapi.h"
33 : : #include <svtools/svlbox.hxx>
34 : : #include <svtools/svlbitm.hxx>
35 : :
36 : : // forward and defines ---------------------------------------------------
37 : :
38 : : class SvImpLBox;
39 : :
40 : : #define SV_TAB_BORDER 8
41 : :
42 : : #define SV_LISTBOX_ID_TREEBOX 1 // fuer SvLBox::IsA()
43 : : #define SV_ENTRYHEIGHTOFFS_PIXEL 2
44 : :
45 : : #define TREEFLAG_CHKBTN 0x0001
46 : : #define TREEFLAG_USESEL 0x0002
47 : : #define TREEFLAG_MANINS 0x0004
48 : : #define TREEFLAG_RECALCTABS 0x0008
49 : :
50 : : typedef sal_Int64 ExtendedWinBits;
51 : :
52 : : // disable the behavior of automatically selecting a "CurEntry" upon painting the control
53 : : #define EWB_NO_AUTO_CURENTRY 0x00000001
54 : :
55 : : // class SvTreeListBox ---------------------------------------------------
56 : :
57 : : class SVT_DLLPUBLIC SvTreeListBox : public SvLBox
58 : : {
59 : : friend class SvImpLBox;
60 : : friend class ImpLBSelEng;
61 : : friend class TreeControlPeer;
62 : :
63 : : SvImpLBox* pImp;
64 : : Link aCheckButtonHdl;
65 : : Link aScrolledHdl;
66 : : Accelerator aInpEditAcc;
67 : : Image aPrevInsertedExpBmp;
68 : : Image aPrevInsertedColBmp;
69 : : Image aCurInsertedExpBmp;
70 : : Image aCurInsertedColBmp;
71 : :
72 : : short nContextBmpWidthMax;
73 : : sal_uInt16 nFirstSelTab, nLastSelTab;
74 : : short nEntryHeight;
75 : : short nEntryHeightOffs;
76 : : short nIndent;
77 : : short nFocusWidth;
78 : : sal_uInt16 aContextBmpMode;
79 : :
80 : : long mnCheckboxItemWidth;
81 : :
82 : : #ifdef _SVTREEBX_CXX
83 : : DECL_DLLPRIVATE_LINK( CheckButtonClick, SvLBoxButtonData * );
84 : :
85 : : SVT_DLLPRIVATE short GetHeightOffset( const Image& rBmp, Size& rLogicSize);
86 : : SVT_DLLPRIVATE short GetHeightOffset( const Font& rFont, Size& rLogicSize);
87 : :
88 : : SVT_DLLPRIVATE void SetEntryHeight( SvLBoxEntry* pEntry );
89 : : SVT_DLLPRIVATE void AdjustEntryHeight( const Image& rBmp );
90 : : SVT_DLLPRIVATE void AdjustEntryHeight( const Font& rFont );
91 : :
92 : : SVT_DLLPRIVATE void ImpEntryInserted( SvLBoxEntry* pEntry );
93 : : SVT_DLLPRIVATE long PaintEntry1( SvLBoxEntry*, long nLine,
94 : : sal_uInt16 nTabFlagMask=0xffff,
95 : : sal_Bool bHasClipRegion=sal_False );
96 : :
97 : : SVT_DLLPRIVATE void InitTreeView();
98 : : SVT_DLLPRIVATE SvLBoxItem* GetItem_Impl( SvLBoxEntry*, long nX, SvLBoxTab** ppTab,
99 : : sal_uInt16 nEmptyWidth );
100 : : SVT_DLLPRIVATE void ImplInitStyle();
101 : :
102 : : #endif
103 : :
104 : : protected:
105 : : SvLBoxButtonData* pCheckButtonData;
106 : : sal_uInt16 nTreeFlags;
107 : :
108 : : SvLBoxEntry* pEdEntry;
109 : : SvLBoxItem* pEdItem;
110 : :
111 : : void EditItemText( SvLBoxEntry* pEntry, SvLBoxString* pItem,
112 : : const Selection& );
113 : : void EditedText( const XubString& );
114 : : void EditingRequest( SvLBoxEntry* pEntry, SvLBoxItem* pItem,
115 : : const Point& rMousePos );
116 : :
117 : : std::vector<SvLBoxTab*> aTabs;
118 : :
119 : : // berechnet abhaengig von TreeList-Style & Bitmap-Groessen
120 : : // alle Tabulatoren neu; wird beim Einfuegen/Austauschen von
121 : : // Bitmaps, beim Wechsel des Models usw. automatisch gerufen
122 : : virtual void SetTabs();
123 : : void SetTabs_Impl();
124 : : void AddTab( long nPos,sal_uInt16 nFlags=SV_LBOXTAB_ADJUST_LEFT,
125 : : void* pUserData = 0 );
126 : 0 : sal_uInt16 TabCount() const { return aTabs.size(); }
127 : : SvLBoxTab* GetFirstDynamicTab() const;
128 : : SvLBoxTab* GetFirstDynamicTab( sal_uInt16& rTabPos ) const;
129 : : SvLBoxTab* GetFirstTab( sal_uInt16 nFlagMask, sal_uInt16& rTabPos );
130 : : SvLBoxTab* GetLastTab( sal_uInt16 nFlagMask, sal_uInt16& rTabPos );
131 : : SvLBoxTab* GetTab( SvLBoxEntry*, SvLBoxItem* ) const;
132 : : void ClearTabList();
133 : :
134 : : virtual void InitEntry(SvLBoxEntry*,const XubString&,const Image&,const Image&,SvLBoxButtonKind);
135 : :
136 : : virtual void NotifyBeginScroll();
137 : : virtual void NotifyEndScroll();
138 : : // nLines == 0 => horizontales Scrolling
139 : : virtual void NotifyScrolling( long nLines );
140 : : virtual void NotifyScrolled();
141 : 0 : void SetScrolledHdl( const Link& rLink ) { aScrolledHdl = rLink; }
142 : : const Link& GetScrolledHdl() const { return aScrolledHdl; }
143 : 0 : long GetXOffset() const { return GetMapMode().GetOrigin().X(); }
144 : :
145 : : // wird aufgerufen, _bevor_ Bereiche im Control invalidiert werden,
146 : : // kann zum Hiden von Elementen benutzt werden, die von aussen
147 : : // in das Control hineingezeichnet werden
148 : : virtual void NotifyInvalidating();
149 : :
150 : : virtual sal_uLong GetAscInsertionPos( SvLBoxEntry*, SvLBoxEntry* pParent );
151 : : virtual sal_uLong GetDescInsertionPos( SvLBoxEntry*, SvLBoxEntry* pParent );
152 : : virtual void Command( const CommandEvent& rCEvt );
153 : :
154 : : virtual void RequestHelp( const HelpEvent& rHEvt );
155 : : virtual void CursorMoved( SvLBoxEntry* pNewCursor );
156 : : virtual void PreparePaint( SvLBoxEntry* );
157 : : virtual void DataChanged( const DataChangedEvent& rDCEvt );
158 : : virtual void StateChanged( StateChangedType nStateChange );
159 : :
160 : : void InitSettings(sal_Bool bFont,sal_Bool bForeground,sal_Bool bBackground);
161 : : sal_Bool IsCellFocusEnabled() const;
162 : : bool SetCurrentTabPos( sal_uInt16 _nNewPos );
163 : : sal_uInt16 GetCurrentTabPos() const;
164 : : void CallImplEventListeners(sal_uLong nEvent, void* pData);
165 : :
166 : : void ImplEditEntry( SvLBoxEntry* pEntry );
167 : :
168 : : sal_Bool AreChildrenTransient() const;
169 : : void SetChildrenNotTransient();
170 : :
171 : : public:
172 : : SvTreeListBox( Window* pParent, WinBits nWinStyle=0 );
173 : : SvTreeListBox( Window* pParent, const ResId& rResId );
174 : : ~SvTreeListBox();
175 : :
176 : : void SetExtendedWinBits( ExtendedWinBits _nBits );
177 : :
178 : : void DisconnectFromModel();
179 : :
180 : : void EnableCheckButton( SvLBoxButtonData* );
181 : : void SetCheckButtonData( SvLBoxButtonData* );
182 : : void SetNodeBitmaps( const Image& rCollapsedNodeBmp, const Image& rExpandedNodeBmp );
183 : :
184 : : /** returns the default image which clients should use for expanded nodes, to have a consistent user
185 : : interface experience in the whole product.
186 : : */
187 : : static const Image& GetDefaultExpandedNodeImage( );
188 : :
189 : : /** returns the default image which clients should use for expanded nodes, to have a consistent user
190 : : interface experience in the whole product.
191 : : */
192 : : static const Image& GetDefaultCollapsedNodeImage( );
193 : :
194 : : /** sets default bitmaps for collapsed and expanded nodes.
195 : : */
196 : 2 : inline void SetNodeDefaultImages( )
197 : : {
198 : : SetNodeBitmaps(
199 : 2 : GetDefaultCollapsedNodeImage( ),
200 : 2 : GetDefaultExpandedNodeImage( )
201 : 2 : );
202 : 2 : }
203 : :
204 : : virtual SvLBoxEntry* InsertEntry( const XubString& rText, SvLBoxEntry* pParent = 0,
205 : : sal_Bool bChildrenOnDemand = sal_False,
206 : : sal_uLong nPos=LIST_APPEND, void* pUserData = 0,
207 : : SvLBoxButtonKind eButtonKind = SvLBoxButtonKind_enabledCheckbox );
208 : :
209 : : virtual SvLBoxEntry* InsertEntry( const XubString& rText,
210 : : const Image& rExpandedEntryBmp,
211 : : const Image& rCollapsedEntryBmp,
212 : : SvLBoxEntry* pParent = 0,
213 : : sal_Bool bChildrenOnDemand = sal_False,
214 : : sal_uLong nPos = LIST_APPEND, void* pUserData = 0,
215 : : SvLBoxButtonKind eButtonKind = SvLBoxButtonKind_enabledCheckbox );
216 : :
217 : : const Image& GetDefaultExpandedEntryBmp( ) const;
218 : : const Image& GetDefaultCollapsedEntryBmp( ) const;
219 : :
220 : : void SetDefaultExpandedEntryBmp( const Image& rBmp );
221 : : void SetDefaultCollapsedEntryBmp( const Image& rBmp );
222 : :
223 : : void SetCheckButtonState( SvLBoxEntry*, SvButtonState );
224 : : SvButtonState GetCheckButtonState( SvLBoxEntry* ) const;
225 : :
226 : : sal_Bool IsExpandBitmapOnCursor() const { return (sal_Bool)(aContextBmpMode & SVLISTENTRYFLAG_FOCUSED)!=0; }
227 : :
228 : : void SetEntryText(SvLBoxEntry*, const XubString& );
229 : : void SetExpandedEntryBmp( SvLBoxEntry* _pEntry, const Image& _rImage );
230 : : void SetCollapsedEntryBmp( SvLBoxEntry* _pEntry, const Image& _rImage );
231 : :
232 : : virtual String GetEntryText( SvLBoxEntry* pEntry ) const;
233 : : String SearchEntryText( SvLBoxEntry* pEntry ) const;
234 : : const Image& GetExpandedEntryBmp(SvLBoxEntry* _pEntry ) const;
235 : : const Image& GetCollapsedEntryBmp(SvLBoxEntry* _pEntry ) const;
236 : :
237 : 0 : void SetCheckButtonHdl( const Link& rLink ) { aCheckButtonHdl=rLink; }
238 : 0 : Link GetCheckButtonHdl() const { return aCheckButtonHdl; }
239 : : virtual void CheckButtonHdl();
240 : :
241 : : virtual SvLBoxEntry* CloneEntry( SvLBoxEntry* pSource );
242 : :
243 : : virtual sal_uInt16 IsA();
244 : :
245 : : void SetSublistOpenWithReturn( sal_Bool bMode = sal_True ); // open/close sublist with return/enter
246 : : void SetSublistOpenWithLeftRight( sal_Bool bMode = sal_True ); // open/close sublist with cursor left/right
247 : :
248 : : void EnableInplaceEditing( sal_Bool bEnable );
249 : 120 : sal_Bool IsInplaceEditingEnabled() const { return SvLBox::IsInplaceEditingEnabled(); }
250 : 0 : inline void ForbidEmptyText() { SvLBox::ForbidEmptyText(); }
251 : : // Editiert das erste StringItem des Entries, 0==Cursor
252 : : void EditEntry( SvLBoxEntry* pEntry = NULL );
253 : : virtual sal_Bool EditingEntry( SvLBoxEntry* pEntry, Selection& );
254 : : virtual sal_Bool EditedEntry( SvLBoxEntry* pEntry, const rtl::OUString& rNewText );
255 : 631 : sal_Bool IsEditingActive() const { return SvLBox::IsEditingActive(); }
256 : 0 : void EndEditing( sal_Bool bCancel = sal_False ) { SvLBox::EndEditing( bCancel ); }
257 : 0 : sal_Bool EditingCanceled() const { return SvLBox::EditingCanceled(); }
258 : :
259 : : virtual void RequestingChildren( SvLBoxEntry* pParent );
260 : :
261 : : virtual void Paint( const Rectangle& rRect );
262 : : virtual void MouseButtonDown( const MouseEvent& rMEvt );
263 : : virtual void MouseButtonUp( const MouseEvent& rMEvt );
264 : : virtual void MouseMove( const MouseEvent& rMEvt );
265 : : virtual void KeyInput( const KeyEvent& rKEvt );
266 : : virtual void Resize();
267 : : virtual void GetFocus();
268 : : virtual void LoseFocus();
269 : : void SetUpdateMode( sal_Bool );
270 : :
271 : : using SvListView::SetModel;
272 : : void SetModel( SvLBoxTreeList* );
273 : : virtual void ModelHasCleared();
274 : : virtual void ModelHasInserted( SvListEntry* pEntry );
275 : : virtual void ModelHasInsertedTree( SvListEntry* pEntry );
276 : : virtual void ModelIsMoving(SvListEntry* pSource,
277 : : SvListEntry* pTargetParent, sal_uLong nChildPos );
278 : : virtual void ModelHasMoved(SvListEntry* pSource );
279 : : virtual void ModelIsRemoving( SvListEntry* pEntry );
280 : : virtual void ModelHasRemoved( SvListEntry* pEntry );
281 : : virtual void ModelHasEntryInvalidated( SvListEntry* pEntry );
282 : :
283 : : void ShowTargetEmphasis( SvLBoxEntry*, sal_Bool bShow );
284 : : using Window::GetDropTarget;
285 : : SvLBoxEntry* GetDropTarget( const Point& );
286 : : void ScrollOutputArea( short nDeltaEntries );
287 : :
288 : 9170 : short GetEntryHeight() const { return nEntryHeight; }
289 : : void SetEntryHeight( short nHeight, sal_Bool bAlways = sal_False );
290 : : Size GetOutputSizePixel() const;
291 : 167 : short GetIndent() const { return nIndent; }
292 : : void SetIndent( short nIndent );
293 : : void SetSpaceBetweenEntries( short nSpace );
294 : 0 : short GetSpaceBetweenEntries() const {return nEntryHeightOffs;}
295 : : Point GetEntryPosition( SvLBoxEntry* ) const;
296 : : void ShowEntry( SvLBoxEntry* ); // !!!OBSOLETE, use MakeVisible
297 : : virtual void MakeVisible( SvLBoxEntry* );
298 : : void MakeVisible( SvLBoxEntry*, sal_Bool bMoveToTop );
299 : :
300 : : void SetCollapsedNodeBmp( const Image& );
301 : : void SetExpandedNodeBmp( const Image& );
302 : : Image GetExpandedNodeBmp( ) const;
303 : :
304 : : void SetFont( const Font& rFont );
305 : :
306 : : using Window::SetCursor;
307 : : void SetCursor( SvLBoxEntry* pEntry, sal_Bool bForceNoSelect = sal_False );
308 : :
309 : : SvLBoxEntry* GetEntry( const Point& rPos, sal_Bool bHit = sal_False ) const;
310 : 132 : SvLBoxEntry* GetEntry( SvLBoxEntry* pParent, sal_uLong nPos ) const { return SvLBox::GetEntry(pParent,nPos); }
311 : 120 : SvLBoxEntry* GetEntry( sal_uLong nRootPos ) const { return SvLBox::GetEntry(nRootPos);}
312 : :
313 : : void PaintEntry( SvLBoxEntry* );
314 : : long PaintEntry( SvLBoxEntry*, long nLine,
315 : : sal_uInt16 nTabFlagMask=0xffff );
316 : : virtual Rectangle GetFocusRect( SvLBoxEntry*, long nLine );
317 : : // Beruecksichtigt Einrueckung
318 : : virtual long GetTabPos( SvLBoxEntry*, SvLBoxTab* );
319 : : void InvalidateEntry( SvLBoxEntry* );
320 : : SvLBoxItem* GetItem( SvLBoxEntry*, long nX, SvLBoxTab** ppTab);
321 : : SvLBoxItem* GetItem( SvLBoxEntry*, long nX );
322 : :
323 : : void SetDragDropMode( DragDropMode );
324 : : void SetSelectionMode( SelectionMode );
325 : :
326 : : virtual sal_Bool Expand( SvLBoxEntry* pParent );
327 : : virtual sal_Bool Collapse( SvLBoxEntry* pParent );
328 : : virtual sal_Bool Select( SvLBoxEntry* pEntry, sal_Bool bSelect=sal_True );
329 : : virtual sal_uLong SelectChildren( SvLBoxEntry* pParent, sal_Bool bSelect );
330 : : virtual void SelectAll( sal_Bool bSelect, sal_Bool bPaint = sal_True );
331 : : virtual void SetCurEntry( SvLBoxEntry* _pEntry );
332 : : virtual SvLBoxEntry*
333 : : GetCurEntry() const;
334 : :
335 : : using Window::Invalidate;
336 : : virtual void Invalidate( sal_uInt16 nFlags = 0);
337 : : virtual void Invalidate( const Rectangle&, sal_uInt16 nFlags = 0 );
338 : :
339 : : void SetHighlightRange(sal_uInt16 nFirstTab=0,sal_uInt16 nLastTab=0xffff);
340 : :
341 : : virtual Region GetDragRegion() const;
342 : :
343 : : // Children des Parents werden Children des naechstoberen Parents
344 : : void RemoveParentKeepChildren( SvLBoxEntry* pParent );
345 : :
346 : : DECL_LINK( DefaultCompare, SvSortData* );
347 : : virtual void ModelNotification( sal_uInt16 nActionId, SvListEntry* pEntry1,
348 : : SvListEntry* pEntry2, sal_uLong nPos );
349 : :
350 : : void EndSelection();
351 : : void RepaintScrollBars() const;
352 : : ScrollBar* GetVScroll();
353 : : ScrollBar* GetHScroll();
354 : : void EnableAsyncDrag( sal_Bool b );
355 : :
356 : : SvLBoxEntry* GetFirstEntryInView() const;
357 : : SvLBoxEntry* GetNextEntryInView(SvLBoxEntry*) const;
358 : : SvLBoxEntry* GetLastEntryInView() const;
359 : : void ScrollToAbsPos( long nPos );
360 : :
361 : : void ShowFocusRect( const SvLBoxEntry* pEntry );
362 : : void InitStartEntry();
363 : :
364 : : virtual PopupMenu* CreateContextMenu( void );
365 : : virtual void ExcecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry );
366 : :
367 : : void EnableContextMenuHandling( void );
368 : : void EnableContextMenuHandling( sal_Bool bEnable );
369 : : sal_Bool IsContextMenuHandlingEnabled( void ) const;
370 : :
371 : : void EnableList( bool _bEnable );
372 : :
373 : : // ACCESSIBILITY ==========================================================
374 : :
375 : : /** Creates and returns the accessible object of the Box. */
376 : : virtual ::com::sun::star::uno::Reference<
377 : : ::com::sun::star::accessibility::XAccessible > CreateAccessible();
378 : :
379 : : /** Fills the StateSet with all states (except DEFUNC, done by the accessible object). */
380 : : virtual void FillAccessibleStateSet( ::utl::AccessibleStateSetHelper& rStateSet ) const;
381 : :
382 : : /** Fills the StateSet of one entry. */
383 : : virtual void FillAccessibleEntryStateSet( SvLBoxEntry* pEntry, ::utl::AccessibleStateSetHelper& rStateSet ) const;
384 : :
385 : : /** Calculate and returns the bounding rectangle of an entry.
386 : : @param pEntry
387 : : The entry.
388 : : @return The bounding rectangle of an entry. */
389 : : virtual Rectangle GetBoundingRect( SvLBoxEntry* pEntry );
390 : :
391 : : /** Enables, that one cell of a tablistbox entry can be focused */
392 : : void EnableCellFocus();
393 : :
394 : : protected:
395 : : using SvListView::Expand;
396 : : using SvListView::Collapse;
397 : : using SvListView::Select;
398 : : using SvListView::SelectAll;
399 : : };
400 : :
401 : : #endif
402 : :
403 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|