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