summaryrefslogtreecommitdiff
path: root/svtools/inc/svtools/treelist.hxx
blob: 6c296d26ea443e6b42004fecd4bc26f2892f31d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef _SVTREELIST_HXX
#define _SVTREELIST_HXX

#include "svtools/svtdllapi.h"
#include <tools/solar.h>
#include <vector>

#include <tools/table.hxx>
#include <tools/link.hxx>
#include <tools/string.hxx>
#include <tools/debug.hxx>

#define LISTACTION_INSERTED         1
#define LISTACTION_REMOVING         2
#define LISTACTION_REMOVED          3
#define LISTACTION_MOVING           4
#define LISTACTION_MOVED            5
#define LISTACTION_CLEARING         6
#define LISTACTION_INSERTED_TREE    7
#define LISTACTION_INVALIDATE_ENTRY 8
#define LISTACTION_RESORTING        9
#define LISTACTION_RESORTED         10
#define LISTACTION_CLEARED          11

#define SV_TREELIST_ROOT_ENTRY  (SvListEntry*)0
#define SV_TREELIST_ERROR        0xFFFFFFFF

// Entryflags, die an der View haengen
#define SVLISTENTRYFLAG_SELECTED        0x0001
#define SVLISTENTRYFLAG_EXPANDED        0x0002
#define SVLISTENTRYFLAG_FOCUSED         0x0004
#define SVLISTENTRYFLAG_CURSORED        0x0008
#define SVLISTENTRYFLAG_NOT_SELECTABLE  0x0010

class SvListEntry;

//=============================================================================

typedef ::std::vector< SvListEntry* > SvTreeEntryList_impl;

class SVT_DLLPUBLIC SvTreeEntryList
{
private:
    SvTreeEntryList_impl    maEntryList;
    size_t                  maCurrent;

public:
                    SvTreeEntryList() { maCurrent = 0; };
                    SvTreeEntryList( SvTreeEntryList& rList );

    void            DestroyAll();
    void            push_back( SvListEntry* pItem )
                    { maEntryList.push_back( pItem ); }
    void            insert( SvListEntry* pItem, size_t i )
                    {
                        if ( i < maEntryList.size() ) {
                            maEntryList.insert( maEntryList.begin() + i, pItem );
                        } else {
                            maEntryList.push_back( pItem );
                        }
                    }
    void            remove( SvListEntry* pItem )
                    {
                        for ( SvTreeEntryList_impl::iterator it = maEntryList.begin();
                              it < maEntryList.end();
                              ++it
                        ) {
                            if ( *it == pItem ) {
                                maEntryList.erase( it );
                                break;
                            }
                        }
                    }
    void            remove( size_t i )
                    {
                        if ( i < maEntryList.size() ) {
                            maEntryList.erase( maEntryList.begin() + i );
                        }
                    }
    void            replace( SvListEntry* pNew, SvListEntry* pOld )
                    {
                        for ( size_t i = 0, n = maEntryList.size(); i < n; ++i ) {
                            if ( maEntryList[ i ] == pOld ) {
                                maEntryList[ i ] = pNew;
                                break;
                            }
                        }
                    }
    void            clear() { maEntryList.clear(); }

    bool            empty() { return maEntryList.empty(); }

    size_t          size() { return maEntryList.size(); }
    size_t          GetPos( SvListEntry* pItem )
                    {
                        for ( size_t i = 0, n = maEntryList.size(); i < n; ++i ) {
                            if ( maEntryList[ i ] == pItem ) {
                                return i;
                            }
                        }
                        return (size_t)~0;
                    }

    SvListEntry*    operator[]( size_t i )
                    { return i < maEntryList.size() ? maEntryList[ i ] : NULL; }
    SvListEntry*    First()
                    {
                        maCurrent = 0;
                        return ( maCurrent < maEntryList.size() ) ? maEntryList[ 0 ] : NULL;
                    }
    SvListEntry*    Next()
                    {
                        return ( maCurrent+1 < maEntryList.size() ) ? maEntryList[ ++maCurrent ] : NULL;
                    }
    SvListEntry*    last() { return maEntryList.empty() ? NULL : maEntryList.back(); }
};

//=============================================================================

class SVT_DLLPUBLIC SvListEntry
{
friend class SvTreeList;
friend class SvListView;

private:
    SvListEntry*        pParent;
    SvTreeEntryList*    pChilds;
    sal_uLong           nAbsPos;
    sal_uLong           nListPos;

    void                SetListPositions();
    void                InvalidateChildrensListPositions()
    {
        nListPos |= 0x80000000;
    }

public:
                        SvListEntry();
                        SvListEntry( const SvListEntry& );
    virtual             ~SvListEntry();
    sal_Bool            HasChilds() { return (sal_Bool)(pChilds!=0); }
    sal_Bool            HasChildListPos() const
    {
        if( pParent && !(pParent->nListPos & 0x80000000) )
            return sal_True;
        else return sal_False;
    }

    sal_uLong           GetChildListPos() const
    {
        if( pParent && (pParent->nListPos & 0x80000000) )
            pParent->SetListPositions();
        return ( nListPos & 0x7fffffff );
    }

    virtual void        Clone( SvListEntry* pSource );
};

class SvListView;

class SvViewData
{
friend class SvTreeList;
friend class SvListView;

    sal_uLong           nVisPos;
protected:
    sal_uInt16          nFlags;
public:
                        SvViewData();
                        SvViewData( const SvViewData& );
    virtual             ~SvViewData();

    sal_Bool            IsSelected() const
    { return (sal_Bool)(nFlags & SVLISTENTRYFLAG_SELECTED) != 0; }

    sal_Bool            IsExpanded() const
    { return (sal_Bool)(nFlags & SVLISTENTRYFLAG_EXPANDED) != 0; }

    sal_Bool            HasFocus() const
    { return (sal_Bool)(nFlags & SVLISTENTRYFLAG_FOCUSED) != 0; }

    sal_Bool            IsCursored() const
    { return (sal_Bool)(nFlags & SVLISTENTRYFLAG_CURSORED) != 0; }

    bool                IsSelectable() const
    { return (bool)(nFlags & SVLISTENTRYFLAG_NOT_SELECTABLE) == 0; }

    void                SetFocus( sal_Bool bFocus)
    {
        if ( !bFocus )
            nFlags &= (~SVLISTENTRYFLAG_FOCUSED);
        else
            nFlags |= SVLISTENTRYFLAG_FOCUSED;
    }

    void                SetCursored( sal_Bool bCursored )
    {
        if ( !bCursored )
            nFlags &= (~SVLISTENTRYFLAG_CURSORED);
        else
            nFlags |= SVLISTENTRYFLAG_CURSORED;
    }

    sal_uInt16          GetFlags() const
    { return nFlags; }

    void                SetSelectable( bool bSelectable )
    {
        if( bSelectable )
            nFlags &= (~SVLISTENTRYFLAG_NOT_SELECTABLE);
        else
            nFlags |= SVLISTENTRYFLAG_NOT_SELECTABLE;
    }
};

enum SvSortMode { SortAscending, SortDescending, SortNone };

// Rueckgabewerte Sortlink:
// siehe International::Compare( pLeft, pRight )
// ( Compare(a,b) ==> b.Compare(a) ==> strcmp(a,b) )
struct SvSortData
{
    SvListEntry* pLeft;
    SvListEntry* pRight;
};

typedef ::std::vector< SvListView* > SvListView_impl;

class SVT_DLLPUBLIC SvTreeList
{
    friend class        SvListView;

    SvListView_impl     aViewList;
    sal_uLong           nEntryCount;

    Link                aCloneLink;
    Link                aCompareLink;
    SvSortMode          eSortMode;

    sal_uInt16          nRefCount;

    sal_Bool            bAbsPositionsValid;

    SvListEntry*        FirstVisible() const { return First(); }
    SvListEntry*        NextVisible( const SvListView*,SvListEntry* pEntry, sal_uInt16* pDepth=0 ) const;
    SvListEntry*        PrevVisible( const SvListView*,SvListEntry* pEntry, sal_uInt16* pDepth=0 ) const;
    SvListEntry*        LastVisible( const SvListView*,sal_uInt16* pDepth=0 ) const;
    SvListEntry*        NextVisible( const SvListView*,SvListEntry* pEntry, sal_uInt16& rDelta ) const;
    SvListEntry*        PrevVisible( const SvListView*,SvListEntry* pEntry, sal_uInt16& rDelta ) const;

    sal_Bool            IsEntryVisible( const SvListView*,SvListEntry* pEntry ) const;
    SvListEntry*        GetEntryAtVisPos( const SvListView*,sal_uLong nVisPos ) const;
    sal_uLong           GetVisiblePos( const SvListView*,SvListEntry* pEntry ) const;
    sal_uLong           GetVisibleCount( const SvListView* ) const;
    sal_uLong           GetVisibleChildCount( const SvListView*,SvListEntry* pParent ) const;

    SvListEntry*        FirstSelected( const SvListView*) const;
    SvListEntry*        NextSelected( const SvListView*,SvListEntry* pEntry ) const;
    SvListEntry*        PrevSelected( const SvListView*,SvListEntry* pEntry ) const;
    SvListEntry*        LastSelected( const SvListView*) const;

    sal_Bool            Select( SvListView*,SvListEntry* pEntry, sal_Bool bSelect=sal_True );
    sal_uLong           SelectChilds( SvListView*,SvListEntry* pParent, sal_Bool bSelect );
    void                SelectAll( SvListView*,sal_Bool bSelect ); // ruft nicht Select-Hdl
    sal_uLong           GetChildSelectionCount( const SvListView*,SvListEntry* pParent ) const;

    void                Expand( SvListView*,SvListEntry* pParent );
    void                Collapse( SvListView*,SvListEntry* pParent );

    SVT_DLLPRIVATE void SetAbsolutePositions();
    SVT_DLLPRIVATE      SvTreeEntryList*CloneChilds(
                            SvTreeEntryList* pChilds,
                            SvListEntry* pNewParent,
                            sal_uLong& nCloneCount
                        ) const;

    SVT_DLLPRIVATE void SetListPositions( SvTreeEntryList* );

    // rPos wird bei SortModeNone nicht geaendert
    SVT_DLLPRIVATE void GetInsertionPos(
                            SvListEntry* pEntry,
                            SvListEntry* pParent,
                            sal_uLong& rPos
                        );

    SVT_DLLPRIVATE void ResortChilds( SvListEntry* pParent );

protected:
    SvListEntry*        pRootItem;

public:

                        SvTreeList();
    virtual             ~SvTreeList();

    void                InsertView( SvListView* );
    void                RemoveView( SvListView* );
    sal_uLong           GetViewCount() const
    { return aViewList.size(); }

    SvListView*         GetView( sal_uLong nPos ) const
    { return ( nPos < aViewList.size() ) ? aViewList[ nPos ] : NULL; }

    void                Broadcast(
                            sal_uInt16 nActionId,
                            SvListEntry* pEntry1=0,
                            SvListEntry* pEntry2=0,
                            sal_uLong nPos=0
                        );

    // informiert alle Listener
    void                InvalidateEntry( SvListEntry* );

    sal_uLong           GetEntryCount() const { return nEntryCount; }
    SvListEntry*        First() const;
    SvListEntry*        Next( SvListEntry* pEntry, sal_uInt16* pDepth=0 ) const;
    SvListEntry*        Prev( SvListEntry* pEntry, sal_uInt16* pDepth=0 ) const;
    SvListEntry*        Last() const;

    SvListEntry*        FirstChild( SvListEntry* pParent ) const;
    SvListEntry*        NextSibling( SvListEntry* pEntry ) const;
    SvListEntry*        PrevSibling( SvListEntry* pEntry ) const;
    SvListEntry*        LastSibling( SvListEntry* pEntry ) const;

    sal_uLong           Insert( SvListEntry* pEntry,SvListEntry* pPar,sal_uLong nPos=ULONG_MAX);
    sal_uLong           Insert( SvListEntry* pEntry,sal_uLong nRootPos = ULONG_MAX )
    { return Insert(pEntry, pRootItem, nRootPos ); }

    void                InsertTree( SvListEntry* pTree, SvListEntry* pTarget );
    void                InsertTree( SvListEntry* pTree, SvListEntry* pTargetParent, sal_uLong nListPos );

    // Entries muessen im gleichen Model stehen!
    void                Move( SvListEntry* pSource, SvListEntry* pTarget );

    // erzeugt ggf. Child-List
    sal_uLong           Move( SvListEntry* pSource, SvListEntry* pTargetParent, sal_uLong nListPos);
    void                Copy( SvListEntry* pSource, SvListEntry* pTarget );
    sal_uLong           Copy( SvListEntry* pSource, SvListEntry* pTargetParent, sal_uLong nListPos);

    sal_Bool            Remove( SvListEntry* pEntry );
    void                Clear();

    sal_Bool            HasChilds( SvListEntry* pEntry ) const;
    sal_Bool            HasParent( SvListEntry* pEntry ) const
    { return (sal_Bool)(pEntry->pParent!=pRootItem); }

    sal_Bool            IsChild( SvListEntry* pParent, SvListEntry* pChild ) const;
    sal_Bool            IsInChildList( SvListEntry* pParent, SvListEntry* pChild) const;
    SvListEntry*        GetEntry( SvListEntry* pParent, sal_uLong nPos ) const;
    SvListEntry*        GetEntry( sal_uLong nRootPos ) const;
    SvListEntry*        GetEntryAtAbsPos( sal_uLong nAbsPos ) const;
    SvListEntry*        GetParent( SvListEntry* pEntry ) const;
    SvListEntry*        GetRootLevelParent( SvListEntry* pEntry ) const;
    SvTreeEntryList*    GetChildList( SvListEntry* pParent ) const;

    sal_uLong           GetAbsPos( SvListEntry* pEntry ) const;
    sal_uLong           GetRelPos( SvListEntry* pChild ) const
    { return pChild->GetChildListPos(); }

    sal_uLong           GetChildCount( SvListEntry* pParent ) const;
    sal_uInt16          GetDepth( SvListEntry* pEntry ) const;
    sal_Bool            IsAtRootDepth( SvListEntry* pEntry ) const
    { return (sal_Bool)(pEntry->pParent==pRootItem); }

    // das Model ruft zum Clonen von Entries den Clone-Link auf,
    // damit man sich nicht vom Model ableiten muss, wenn man
    // sich von SvListEntry ableitet.
    // Deklaration des Clone-Handlers:
    // DECL_LINK(CloneHdl,SvListEntry*);
    // der Handler muss einen SvListEntry* zurueckgeben
    SvListEntry*        Clone( SvListEntry* pEntry, sal_uLong& nCloneCount ) const;
    void                SetCloneLink( const Link& rLink )
    { aCloneLink=rLink; }

    const Link&         GetCloneLink() const
    { return aCloneLink; }

    virtual SvListEntry*    CloneEntry( SvListEntry* ) const; // ruft den Clone-Link
    virtual SvListEntry*    CreateEntry() const; // zum 'new'en von Entries

    sal_uInt16          GetRefCount() const { return nRefCount; }
    void                SetRefCount( sal_uInt16 nRef ) { nRefCount = nRef; }

    void                SetSortMode( SvSortMode eMode ) { eSortMode = eMode; }
    SvSortMode          GetSortMode() const { return eSortMode; }
    virtual StringCompare   Compare( SvListEntry*, SvListEntry* ) const;
    void                SetCompareHdl( const Link& rLink ) { aCompareLink = rLink; }
    const Link&         GetCompareHdl() const { return aCompareLink; }
    void                Resort();

    void                CheckIntegrity() const;
};

class SVT_DLLPUBLIC SvListView
{
    friend class SvTreeList;

    sal_uLong           nVisibleCount;
    sal_uLong           nSelectionCount;
    sal_Bool            bVisPositionsValid;

    SVT_DLLPRIVATE void InitTable();
    SVT_DLLPRIVATE void ClearTable();
    SVT_DLLPRIVATE void RemoveViewData( SvListEntry* pParent );

protected:
    Table               aDataTable;  // Mapping SvListEntry -> ViewData
    SvTreeList*         pModel;

    void                ActionMoving( SvListEntry* pEntry,SvListEntry* pTargetPrnt,sal_uLong nChildPos);
    void                ActionMoved( SvListEntry* pEntry,SvListEntry* pTargetPrnt,sal_uLong nChildPos);
    void                ActionInserted( SvListEntry* pEntry );
    void                ActionInsertedTree( SvListEntry* pEntry );
    void                ActionRemoving( SvListEntry* pEntry );
    void                ActionRemoved( SvListEntry* pEntry );
    void                ActionClear();

public:

                        SvListView();   // !!! setzt das Model auf 0
                        SvListView( SvTreeList* pModel );
    virtual             ~SvListView();
    void                Clear();
    SvTreeList*         GetModel() const { return pModel; }
    virtual void        SetModel( SvTreeList* );
    virtual void        ModelNotification(
                            sal_uInt16 nActionId,
                            SvListEntry* pEntry1,
                            SvListEntry* pEntry2,
                            sal_uLong nPos
                        );

    sal_uLong           GetVisibleCount() const
    { return pModel->GetVisibleCount( (SvListView*)this ); }

    SvListEntry*        FirstVisible() const
    { return pModel->FirstVisible(); }

    SvListEntry*        NextVisible( SvListEntry* pEntry, sal_uInt16* pDepth=0 ) const
    { return pModel->NextVisible(this,pEntry,pDepth); }

    SvListEntry*        PrevVisible( SvListEntry* pEntry, sal_uInt16* pDepth=0 ) const
    { return pModel->PrevVisible(this,pEntry,pDepth); }

    SvListEntry*        LastVisible( sal_uInt16* pDepth=0 ) const
    { return pModel->LastVisible(this,pDepth); }

    SvListEntry*        NextVisible( SvListEntry* pEntry, sal_uInt16& rDelta ) const
    { return pModel->NextVisible(this,pEntry,rDelta); }

    SvListEntry*        PrevVisible( SvListEntry* pEntry, sal_uInt16& rDelta ) const
    { return pModel->PrevVisible(this,pEntry,rDelta); }

    sal_uLong           GetSelectionCount() const
    { return nSelectionCount; }

    SvListEntry*        FirstSelected() const
    { return pModel->FirstSelected(this); }

    SvListEntry*        NextSelected( SvListEntry* pEntry ) const
    { return pModel->NextSelected(this,pEntry); }

    SvListEntry*        PrevSelected( SvListEntry* pEntry ) const
    { return pModel->PrevSelected(this,pEntry); }

    SvListEntry*        LastSelected() const
    { return pModel->LastSelected(this); }
    SvListEntry*        GetEntryAtVisPos( sal_uLong nVisPos ) const
    { return pModel->GetEntryAtVisPos((SvListView*)this,nVisPos); }

    sal_uLong           GetVisiblePos( SvListEntry* pEntry ) const
    { return pModel->GetVisiblePos((SvListView*)this,pEntry); }

    sal_uLong           GetVisibleChildCount(SvListEntry* pParent ) const
    { return pModel->GetVisibleChildCount((SvListView*)this,pParent); }

    sal_uLong           GetChildSelectionCount( SvListEntry* pParent ) const
    { return pModel->GetChildSelectionCount((SvListView*)this,pParent); }

    void                Expand( SvListEntry* pParent )
    { pModel->Expand((SvListView*)this,pParent); }

    void                Collapse( SvListEntry* pParent )
    { pModel->Collapse((SvListView*)this,pParent); }

    sal_Bool            Select( SvListEntry* pEntry, sal_Bool bSelect=sal_True )
    { return pModel->Select((SvListView*)this,pEntry,bSelect); }

    sal_uLong           SelectChilds( SvListEntry* pParent, sal_Bool bSelect )
    { return pModel->SelectChilds((SvListView*)this,pParent, bSelect); }

    // ruft nicht Select-Hdl
    virtual void        SelectAll( sal_Bool bSelect, sal_Bool )
    { pModel->SelectAll((SvListView*)this, bSelect); }

    sal_Bool            IsEntryVisible( SvListEntry* pEntry ) const
    { return pModel->IsEntryVisible((SvListView*)this,pEntry); }

    sal_Bool            IsExpanded( SvListEntry* pEntry ) const;
    sal_Bool            IsSelected( SvListEntry* pEntry ) const;
    sal_Bool            HasEntryFocus( SvListEntry* pEntry ) const;
    void                SetEntryFocus( SvListEntry* pEntry, sal_Bool bFocus ) const;
    SvViewData*         GetViewData( SvListEntry* pEntry ) const;
    sal_Bool            HasViewData() const
    { return aDataTable.Count() > 1; }  // eine ROOT gibts immer

    virtual SvViewData* CreateViewData( SvListEntry* pEntry );
    virtual void        InitViewData( SvViewData*, SvListEntry* pEntry );

    virtual void        ModelHasCleared();
    virtual void        ModelHasInserted( SvListEntry* pEntry );
    virtual void        ModelHasInsertedTree( SvListEntry* pEntry );
    virtual void        ModelIsMoving(
                            SvListEntry* pSource,
                            SvListEntry* pTargetParent,
                            sal_uLong nPos
                        );
    virtual void        ModelHasMoved( SvListEntry* pSource );
    virtual void        ModelIsRemoving( SvListEntry* pEntry );
    virtual void        ModelHasRemoved( SvListEntry* pEntry );
    virtual void        ModelHasEntryInvalidated( SvListEntry* pEntry );
};

inline sal_Bool SvListView::IsExpanded( SvListEntry* pEntry ) const
{
    DBG_ASSERT(pEntry,"IsExpanded:No Entry");
    SvViewData* pData = (SvViewData*)aDataTable.Get( (sal_uLong)pEntry );
    DBG_ASSERT(pData,"Entry not in Table");
    return pData->IsExpanded();
}

inline sal_Bool SvListView::IsSelected( SvListEntry* pEntry ) const
{
    DBG_ASSERT(pEntry,"IsExpanded:No Entry");
    SvViewData* pData = (SvViewData*)aDataTable.Get( (sal_uLong)pEntry );
    DBG_ASSERT(pData,"Entry not in Table");
    return pData->IsSelected();
}

inline sal_Bool SvListView::HasEntryFocus( SvListEntry* pEntry ) const
{
    DBG_ASSERT(pEntry,"IsExpanded:No Entry");
    SvViewData* pData = (SvViewData*)aDataTable.Get( (sal_uLong)pEntry );
    DBG_ASSERT(pData,"Entry not in Table");
    return pData->HasFocus();
}

inline void SvListView::SetEntryFocus( SvListEntry* pEntry, sal_Bool bFocus ) const
{
    DBG_ASSERT(pEntry,"SetEntryFocus:No Entry");
    SvViewData* pData = (SvViewData*)aDataTable.Get( (sal_uLong)pEntry );
    DBG_ASSERT(pData,"Entry not in Table");
    pData->SetFocus(bFocus);
}

inline SvViewData* SvListView::GetViewData( SvListEntry* pEntry ) const
{
#ifndef DBG_UTIL
    return (SvViewData*)aDataTable.Get( (sal_uLong)pEntry );
#else
    SvViewData* pResult = (SvViewData*)aDataTable.Get( (sal_uLong)pEntry );
    DBG_ASSERT(pResult,"Entry not in model or wrong view");
    return pResult;
#endif
}

inline sal_Bool SvTreeList::HasChilds( SvListEntry* pEntry ) const
{
    if ( !pEntry )
        pEntry = pRootItem;
    return (sal_Bool)(pEntry->pChilds != 0);
}

inline SvListEntry* SvTreeList::GetEntry( SvListEntry* pParent, sal_uLong nPos ) const
{   if ( !pParent )
        pParent = pRootItem;
    SvListEntry* pRet = 0;
    if ( pParent->pChilds )
        pRet = (*pParent->pChilds)[ nPos ];
    return pRet;
}

inline SvListEntry* SvTreeList::GetEntry( sal_uLong nRootPos ) const
{
    SvListEntry* pRet = 0;
    if ( nEntryCount )
        pRet = (*pRootItem->pChilds)[ nRootPos ];
    return pRet;
}

inline SvTreeEntryList* SvTreeList::GetChildList( SvListEntry* pParent ) const
{
    if ( !pParent )
        pParent = pRootItem;
    return pParent->pChilds;
}

inline SvListEntry* SvTreeList::GetParent( SvListEntry* pEntry ) const
{
    SvListEntry* pParent = pEntry->pParent;
    if ( pParent==pRootItem )
        pParent = 0;
    return pParent;
}

#define DECLARE_SVTREELIST( ClassName, Type )                                   \
class ClassName : public SvTreeList                                             \
{                                                                               \
public:                                                                         \
    Type        First() const                                                   \
                    { return (Type)SvTreeList::First(); }                       \
    Type        Next( SvListEntry* pEntry, sal_uInt16* pDepth=0 ) const         \
                    { return (Type)SvTreeList::Next(pEntry,pDepth); }           \
    Type        Prev( SvListEntry* pEntry, sal_uInt16* pDepth=0 ) const         \
                    { return (Type)SvTreeList::Prev(pEntry,pDepth); }           \
    Type        Last() const                                                    \
                    { return (Type)SvTreeList::Last(); }                        \
                                                                                \
    Type        Clone( SvListEntry* pEntry, sal_uLong& nCloneCount ) const      \
                    { return (Type)SvTreeList::Clone(pEntry,nCloneCount); }     \
    Type        GetEntry( SvListEntry* pParent, sal_uLong nPos ) const          \
                    { return (Type)SvTreeList::GetEntry(pParent,nPos); }        \
    Type        GetEntry( sal_uLong nRootPos ) const                            \
                    { return (Type)SvTreeList::GetEntry(nRootPos); }            \
    Type        GetParent( SvListEntry* pEntry ) const                          \
                    { return (Type)SvTreeList::GetParent(pEntry); }             \
    using SvTreeList::FirstChild;                                               \
    Type        FirstChild( Type pParent ) const                                \
                    { return (Type)SvTreeList::FirstChild(pParent); }           \
    using SvTreeList::NextSibling;                                              \
    Type        NextSibling( Type pEntry ) const                                \
                    { return (Type)SvTreeList::NextSibling(pEntry); }           \
    using SvTreeList::PrevSibling;                                              \
    Type        PrevSibling( Type pEntry ) const                                \
                    { return (Type)SvTreeList::PrevSibling(pEntry); }           \
    using SvTreeList::LastSibling;                                              \
    Type        LastSibling( Type pEntry ) const                                \
                    { return (Type)SvTreeList::LastSibling(pEntry); }           \
    Type        GetEntryAtAbsPos( sal_uLong nAbsPos ) const                     \
                    { return (Type)SvTreeList::GetEntryAtAbsPos( nAbsPos); }    \
};

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */