update dev300-m58
[ooovba.git] / writerfilter / source / doctok / XNoteHelperImpl.hxx
blobf11786c16660f0df0e44638bf7a87540aeeef3b9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XNoteHelperImpl.hxx,v $
10 * $Revision: 1.6 $
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 {
35 namespace doctok
37 template <class T>
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;
45 return nResult;
48 template <class T>
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);
59 return aCpAndFc;
62 template <class T>
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);
73 return aCpAndFc;
76 template <class T>
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));
93 return pResult;
96 template <class T>
97 sal_uInt32 XNoteHelper<T>::getIndexOfCpAndFc(const CpAndFc & rCpAndFc)
99 sal_uInt32 nResult = getCount();
101 sal_uInt32 n = nResult;
102 while (n > 0)
104 --n;
106 Cp aCp(mpRefs->getFc(n));
107 Fc aFc(mpPieceTable->cp2fc(aCp));
108 CpAndFc aCpAndFc(aCp, aFc, meType);
110 if (aCpAndFc <= rCpAndFc)
112 nResult = n;
113 break;
117 return nResult;
120 template <class T>
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);
128 if (n < getCount())
129 pResult = get(n);
131 return pResult;
134 template <class T>
136 XNoteHelper<T>::getRef(sal_uInt32 nIndex)
138 return mpRefs->getEntryPointer(nIndex);
141 template <class T>
143 XNoteHelper<T>::getRef(const CpAndFc & rCpAndFc)
145 T * pResult = NULL;
147 sal_uInt32 n = getIndexOfCpAndFc(rCpAndFc);
149 if (n < getCount())
151 pResult = getRef(n);
154 return pResult;
157 template <class T>
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