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 #ifndef INCLUDED_X_NOTE_HELPER_IMPL_HXX
21 #define INCLUDED_X_NOTE_HELPER_IMPL_HXX
23 namespace writerfilter
{
27 sal_uInt32 XNoteHelper
<T
>::getCount() const
29 sal_uInt32 nResult
= 0;
31 if (mpCps
.get() != NULL
&& mpCps
->getCount() > 8)
32 nResult
= ( mpCps
->getCount() / 4) - 2;
38 CpAndFc XNoteHelper
<T
>::getCpAndFc(sal_uInt32 nPos
)
40 // There are getCount() + 1 entries in mpOffsets => greater
41 if (nPos
> getCount())
42 throw ExceptionNotFound("getCpAndFc");
44 Cp
aCp(mCpAndFcOffset
.getCp() + mpCps
->getU32(nPos
* 4));
45 Fc
aFc(mpPieceTable
->cp2fc(aCp
));
46 CpAndFc
aCpAndFc(aCp
, aFc
, meType
);
52 CpAndFc XNoteHelper
<T
>::getRefCpAndFc(sal_uInt32 nPos
)
54 // There are getCount() entries in mpRefs => greater or equal
55 if (nPos
>= getCount())
56 throw ExceptionNotFound("");
58 Cp
aCp(mpRefs
->getFc(nPos
));
59 Fc
aFc(mpPieceTable
->cp2fc(aCp
));
60 CpAndFc
aCpAndFc(aCp
, aFc
, meType
);
66 writerfilter::Reference
<Stream
>::Pointer_t
67 XNoteHelper
<T
>::get(sal_uInt32 nPos
)
69 // There are getCount() entries => greater or equal
70 if (nPos
>= getCount())
71 throw ExceptionNotFound("get");
73 writerfilter::Reference
<Stream
>::Pointer_t pResult
;
75 CpAndFc
aCpAndFcStart(getCpAndFc(nPos
));
76 CpAndFc
aCpAndFcEnd(getCpAndFc(nPos
+ 1));
78 if (aCpAndFcStart
< aCpAndFcEnd
)
79 pResult
= writerfilter::Reference
<Stream
>::Pointer_t
80 (new WW8DocumentImpl(*mpDocument
, aCpAndFcStart
, aCpAndFcEnd
));
86 sal_uInt32 XNoteHelper
<T
>::getIndexOfCpAndFc(const CpAndFc
& rCpAndFc
)
88 sal_uInt32 nResult
= getCount();
90 sal_uInt32 n
= nResult
;
95 Cp
aCp(mpRefs
->getFc(n
));
96 Fc
aFc(mpPieceTable
->cp2fc(aCp
));
97 CpAndFc
aCpAndFc(aCp
, aFc
, meType
);
99 if (aCpAndFc
<= rCpAndFc
)
110 writerfilter::Reference
<Stream
>::Pointer_t
111 XNoteHelper
<T
>::get(const CpAndFc
& rCpAndFc
)
113 writerfilter::Reference
<Stream
>::Pointer_t pResult
;
115 sal_uInt32 n
= getIndexOfCpAndFc(rCpAndFc
);
125 XNoteHelper
<T
>::getRef(sal_uInt32 nIndex
)
127 return mpRefs
->getEntryPointer(nIndex
);
132 XNoteHelper
<T
>::getRef(const CpAndFc
& rCpAndFc
)
136 sal_uInt32 n
= getIndexOfCpAndFc(rCpAndFc
);
147 void XNoteHelper
<T
>::init()
149 for (sal_uInt32 n
= 0; n
< getCount(); ++n
)
151 CpAndFc
aCpAndFc(getCpAndFc(n
));
152 mpDocument
->insertCpAndFc(aCpAndFc
);
154 CpAndFc
aCpAndFcRef(getRefCpAndFc(n
));
155 mpDocument
->insertCpAndFc(aCpAndFcRef
);
160 #endif // INCLUDED_X_NOTE_HELPER_IMPL_HXX
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */