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 <node.hxx>
21 : #include <doc.hxx>
22 : #include <IDocumentFieldsAccess.hxx>
23 : #include <pam.hxx>
24 : #include <ndtxt.hxx>
25 : #include <fldbas.hxx>
26 : #include <docary.hxx>
27 :
28 14252 : bool CompareSwOutlineNodes::operator()( SwNode* const& lhs, SwNode* const& rhs) const
29 : {
30 14252 : return lhs->GetIndex() < rhs->GetIndex();
31 : }
32 :
33 298 : bool SwOutlineNodes::Seek_Entry(SwNode* rP, sal_uInt16* pnPos) const
34 : {
35 298 : const_iterator it = lower_bound(rP);
36 298 : *pnPos = it - begin();
37 298 : return it != end() && rP->GetIndex() == (*it)->GetIndex();
38 : }
39 :
40 498187 : void SwNodes::UpdateOutlineNode(SwNode & rNd)
41 : {
42 498187 : SwTextNode * pTextNd = rNd.GetTextNode();
43 :
44 498187 : if (pTextNd && pTextNd->IsOutlineStateChanged())
45 : {
46 1924 : bool bFound = pOutlineNds->find(pTextNd) != pOutlineNds->end();
47 :
48 1924 : if (pTextNd->IsOutline())
49 : {
50 1672 : if (! bFound)
51 : {
52 : // assure that text is in the correct nodes array
53 1672 : if ( &(pTextNd->GetNodes()) == this )
54 : {
55 1672 : pOutlineNds->insert(pTextNd);
56 : }
57 : else
58 : {
59 : OSL_FAIL( "<SwNodes::UpdateOutlineNode(..)> - given text node isn't in the correct nodes array. This is a serious defect -> inform OD" );
60 : }
61 : }
62 : }
63 : else
64 : {
65 252 : if (bFound)
66 252 : pOutlineNds->erase(pTextNd);
67 : }
68 :
69 1924 : pTextNd->UpdateOutlineState();
70 :
71 : // update the structure fields
72 1924 : GetDoc()->getIDocumentFieldsAccess().GetSysFieldType( RES_CHAPTERFLD )->UpdateFields();
73 : }
74 498187 : }
75 :
76 629 : void SwNodes::UpdateOutlineIdx( const SwNode& rNd )
77 : {
78 629 : if( pOutlineNds->empty() ) // no OutlineNodes present ?
79 1222 : return;
80 :
81 36 : const SwNodePtr pSrch = const_cast<SwNodePtr>(&rNd);
82 :
83 : sal_uInt16 nPos;
84 36 : if (!pOutlineNds->Seek_Entry(pSrch, &nPos))
85 36 : return;
86 0 : if( nPos == pOutlineNds->size() ) // none present for updating ?
87 0 : return;
88 :
89 0 : if( nPos )
90 0 : --nPos;
91 :
92 0 : if( !GetDoc()->IsInDtor() && IsDocNodes() )
93 0 : UpdateOutlineNode( *(*pOutlineNds)[ nPos ]);
94 177 : }
95 :
96 :
97 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|