Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <DocumentListItemsManager.hxx>
21 : #include <SwNodeNum.hxx>
22 : #include <ndtxt.hxx>
23 :
24 :
25 : namespace sw
26 : {
27 :
28 2958 : DocumentListItemsManager::DocumentListItemsManager() : mpListItemsList( new tImplSortedNodeNumList() ) // #i83479#
29 : {
30 2958 : }
31 :
32 132513 : bool DocumentListItemsManager::lessThanNodeNum::operator()( const SwNodeNum* pNodeNumOne,
33 : const SwNodeNum* pNodeNumTwo ) const
34 : {
35 132513 : return pNodeNumOne->LessThan( *pNodeNumTwo );
36 : }
37 :
38 6187 : void DocumentListItemsManager::addListItem( const SwNodeNum& rNodeNum )
39 : {
40 6187 : if ( mpListItemsList == 0 )
41 : {
42 6187 : return;
43 : }
44 :
45 : const bool bAlreadyInserted(
46 6187 : mpListItemsList->find( &rNodeNum ) != mpListItemsList->end() );
47 : OSL_ENSURE( !bAlreadyInserted,
48 : "<DocumentListItemsManager::addListItem(..)> - <SwNodeNum> instance already registered as numbered item!" );
49 6187 : if ( !bAlreadyInserted )
50 : {
51 6187 : mpListItemsList->insert( &rNodeNum );
52 : }
53 : }
54 :
55 6187 : void DocumentListItemsManager::removeListItem( const SwNodeNum& rNodeNum )
56 : {
57 6187 : if ( mpListItemsList == 0 )
58 : {
59 6187 : return;
60 : }
61 :
62 6187 : const tImplSortedNodeNumList::size_type nDeleted = mpListItemsList->erase( &rNodeNum );
63 : if ( nDeleted > 1 )
64 : {
65 : OSL_FAIL( "<DocumentListItemsManager::removeListItem(..)> - <SwNodeNum> was registered more than once as numbered item!" );
66 : }
67 : }
68 :
69 0 : OUString DocumentListItemsManager::getListItemText( const SwNodeNum& rNodeNum,
70 : const bool bWithNumber,
71 : const bool bWithSpacesForLevel ) const
72 : {
73 0 : return rNodeNum.GetTextNode()
74 : ? rNodeNum.GetTextNode()->GetExpandText( 0, -1, bWithNumber,
75 : bWithNumber, bWithSpacesForLevel )
76 0 : : OUString();
77 : }
78 :
79 0 : void DocumentListItemsManager::getListItems( tSortedNodeNumList& orNodeNumList ) const
80 : {
81 0 : orNodeNumList.clear();
82 0 : orNodeNumList.reserve( mpListItemsList->size() );
83 :
84 0 : tImplSortedNodeNumList::iterator aIter;
85 0 : tImplSortedNodeNumList::iterator aEndIter = mpListItemsList->end();
86 0 : for ( aIter = mpListItemsList->begin(); aIter != aEndIter; ++aIter )
87 : {
88 0 : orNodeNumList.push_back( (*aIter) );
89 : }
90 0 : }
91 :
92 0 : void DocumentListItemsManager::getNumItems( tSortedNodeNumList& orNodeNumList ) const
93 : {
94 0 : orNodeNumList.clear();
95 0 : orNodeNumList.reserve( mpListItemsList->size() );
96 :
97 0 : tImplSortedNodeNumList::iterator aIter;
98 0 : tImplSortedNodeNumList::iterator aEndIter = mpListItemsList->end();
99 0 : for ( aIter = mpListItemsList->begin(); aIter != aEndIter; ++aIter )
100 : {
101 0 : const SwNodeNum* pNodeNum = (*aIter);
102 0 : if ( pNodeNum->IsCounted() &&
103 0 : pNodeNum->GetTextNode() && pNodeNum->GetTextNode()->HasNumber() )
104 : {
105 0 : orNodeNumList.push_back( pNodeNum );
106 : }
107 : }
108 0 : }
109 :
110 8847 : DocumentListItemsManager::~DocumentListItemsManager()
111 : {
112 : // #i83479#
113 2949 : delete mpListItemsList;
114 2949 : mpListItemsList = 0;
115 5898 : }
116 :
117 :
118 177 : }
119 :
120 :
121 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|