1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XNoteHelperImpl.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef INCLUDED_X_NOTE_HELPER_IMPL_HXX
32 #define INCLUDED_X_NOTE_HELPER_IMPL_HXX
34 namespace writerfilter
{
38 sal_uInt32 XNoteHelper
<T
>::getCount() const
40 sal_uInt32 nResult
= 0;
42 if (mpCps
.get() != NULL
&& mpCps
->getCount() > 8)
43 nResult
= ( mpCps
->getCount() / 4) - 2;
49 CpAndFc XNoteHelper
<T
>::getCpAndFc(sal_uInt32 nPos
)
51 // There are getCount() + 1 entries in mpOffsets => greater
52 if (nPos
> getCount())
53 throw ExceptionNotFound("getCpAndFc");
55 Cp
aCp(mCpAndFcOffset
.getCp() + mpCps
->getU32(nPos
* 4));
56 Fc
aFc(mpPieceTable
->cp2fc(aCp
));
57 CpAndFc
aCpAndFc(aCp
, aFc
, meType
);
63 CpAndFc XNoteHelper
<T
>::getRefCpAndFc(sal_uInt32 nPos
)
65 // There are getCount() entries in mpRefs => greater or equal
66 if (nPos
>= getCount())
67 throw ExceptionNotFound("");
69 Cp
aCp(mpRefs
->getFc(nPos
));
70 Fc
aFc(mpPieceTable
->cp2fc(aCp
));
71 CpAndFc
aCpAndFc(aCp
, aFc
, meType
);
77 writerfilter::Reference
<Stream
>::Pointer_t
78 XNoteHelper
<T
>::get(sal_uInt32 nPos
)
80 // There are getCount() entries => greater or equal
81 if (nPos
>= getCount())
82 throw ExceptionNotFound("get");
84 writerfilter::Reference
<Stream
>::Pointer_t pResult
;
86 CpAndFc
aCpAndFcStart(getCpAndFc(nPos
));
87 CpAndFc
aCpAndFcEnd(getCpAndFc(nPos
+ 1));
89 if (aCpAndFcStart
< aCpAndFcEnd
)
90 pResult
= writerfilter::Reference
<Stream
>::Pointer_t
91 (new WW8DocumentImpl(*mpDocument
, aCpAndFcStart
, aCpAndFcEnd
));
97 sal_uInt32 XNoteHelper
<T
>::getIndexOfCpAndFc(const CpAndFc
& rCpAndFc
)
99 sal_uInt32 nResult
= getCount();
101 sal_uInt32 n
= nResult
;
106 Cp
aCp(mpRefs
->getFc(n
));
107 Fc
aFc(mpPieceTable
->cp2fc(aCp
));
108 CpAndFc
aCpAndFc(aCp
, aFc
, meType
);
110 if (aCpAndFc
<= rCpAndFc
)
121 writerfilter::Reference
<Stream
>::Pointer_t
122 XNoteHelper
<T
>::get(const CpAndFc
& rCpAndFc
)
124 writerfilter::Reference
<Stream
>::Pointer_t pResult
;
126 sal_uInt32 n
= getIndexOfCpAndFc(rCpAndFc
);
136 XNoteHelper
<T
>::getRef(sal_uInt32 nIndex
)
138 return mpRefs
->getEntryPointer(nIndex
);
143 XNoteHelper
<T
>::getRef(const CpAndFc
& rCpAndFc
)
147 sal_uInt32 n
= getIndexOfCpAndFc(rCpAndFc
);
158 void XNoteHelper
<T
>::init()
160 for (sal_uInt32 n
= 0; n
< getCount(); ++n
)
162 CpAndFc
aCpAndFc(getCpAndFc(n
));
163 mpDocument
->insertCpAndFc(aCpAndFc
);
165 CpAndFc
aCpAndFcRef(getRefCpAndFc(n
));
166 mpDocument
->insertCpAndFc(aCpAndFcRef
);
171 #endif // INCLUDED_X_NOTE_HELPER_IMPL_HXX