1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "grouptable.hxx"
22 using ::com::sun::star::uno::Reference
;
23 using ::com::sun::star::container::XIndexAccess
;
25 GroupTable::GroupTable() :
26 mnCurrentGroupEntry ( 0 ),
27 mnMaxGroupEntry ( 0 ),
31 ImplResizeGroupTable( 32 );
34 // ---------------------------------------------------------------------------------------------
36 GroupTable::~GroupTable()
38 for ( sal_uInt32 i
= 0; i
< mnCurrentGroupEntry
; delete mpGroupEntry
[ i
++ ] ) ;
39 delete[] mpGroupEntry
;
42 // ---------------------------------------------------------------------------------------------
44 void GroupTable::ImplResizeGroupTable( sal_uInt32 nEntrys
)
46 if ( nEntrys
> mnMaxGroupEntry
)
48 mnMaxGroupEntry
= nEntrys
;
49 GroupEntry
** pTemp
= new GroupEntry
*[ nEntrys
];
50 for ( sal_uInt32 i
= 0; i
< mnCurrentGroupEntry
; i
++ )
51 pTemp
[ i
] = mpGroupEntry
[ i
];
53 delete[] mpGroupEntry
;
58 // ---------------------------------------------------------------------------------------------
60 sal_Bool
GroupTable::EnterGroup( ::com::sun::star::uno::Reference
< ::com::sun::star::container::XIndexAccess
>& rXIndexAccessRef
)
62 sal_Bool bRet
= sal_False
;
63 if ( rXIndexAccessRef
.is() )
65 GroupEntry
* pNewGroup
= new GroupEntry( rXIndexAccessRef
);
66 if ( pNewGroup
->mnCount
)
68 if ( mnMaxGroupEntry
== mnCurrentGroupEntry
)
69 ImplResizeGroupTable( mnMaxGroupEntry
+ 8 );
70 mpGroupEntry
[ mnCurrentGroupEntry
++ ] = pNewGroup
;
79 // ---------------------------------------------------------------------------------------------
81 sal_uInt32
GroupTable::GetGroupsClosed()
83 sal_uInt32 nRet
= mnGroupsClosed
;
88 // ---------------------------------------------------------------------------------------------
90 void GroupTable::ClearGroupTable()
92 for ( sal_uInt32 i
= 0; i
< mnCurrentGroupEntry
; i
++, delete mpGroupEntry
[ i
] ) ;
93 mnCurrentGroupEntry
= 0;
96 // ---------------------------------------------------------------------------------------------
98 void GroupTable::ResetGroupTable( sal_uInt32 nCount
)
101 mpGroupEntry
[ mnCurrentGroupEntry
++ ] = new GroupEntry( nCount
);
104 // ---------------------------------------------------------------------------------------------
106 sal_Bool
GroupTable::GetNextGroupEntry()
108 while ( mnCurrentGroupEntry
)
110 mnIndex
= mpGroupEntry
[ mnCurrentGroupEntry
- 1 ]->mnCurrentPos
++;
112 if ( mpGroupEntry
[ mnCurrentGroupEntry
- 1 ]->mnCount
> mnIndex
)
115 delete ( mpGroupEntry
[ --mnCurrentGroupEntry
] );
117 if ( mnCurrentGroupEntry
)
123 // ---------------------------------------------------------------------------------------------
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */