xref: /trunk/main/sc/source/ui/docshell/pagedata.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 
32 #include <string.h>
33 #include <tools/debug.hxx>
34 
35 
36 #include "pagedata.hxx"
37 
38 //============================================================================
39 
40 ScPrintRangeData::ScPrintRangeData()
41 {
42     nPagesX = nPagesY = 0;
43     pPageEndX = NULL;
44     pPageEndY = NULL;
45     bTopDown = bAutomatic = sal_True;
46     nFirstPage = 1;
47 }
48 
49 ScPrintRangeData::~ScPrintRangeData()
50 {
51     delete[] pPageEndX;
52     delete[] pPageEndY;
53 }
54 
55 void ScPrintRangeData::SetPagesX( size_t nCount, const SCCOL* pData )
56 {
57     delete[] pPageEndX;
58     if ( nCount )
59     {
60         pPageEndX = new SCCOL[nCount];
61         memcpy( pPageEndX, pData, nCount * sizeof(SCCOL) );
62     }
63     else
64         pPageEndX = NULL;
65     nPagesX = nCount;
66 }
67 
68 void ScPrintRangeData::SetPagesY( size_t nCount, const SCROW* pData )
69 {
70     delete[] pPageEndY;
71     if ( nCount )
72     {
73         pPageEndY = new SCROW[nCount];
74         memcpy( pPageEndY, pData, nCount * sizeof(SCROW) );
75     }
76     else
77         pPageEndY = NULL;
78     nPagesY = nCount;
79 }
80 
81 //============================================================================
82 
83 ScPageBreakData::ScPageBreakData(size_t nMax)
84 {
85     nUsed = 0;
86     if (nMax)
87         pData = new ScPrintRangeData[nMax];
88     else
89         pData = NULL;
90     nAlloc = nMax;
91 }
92 
93 ScPageBreakData::~ScPageBreakData()
94 {
95     delete[] pData;
96 }
97 
98 ScPrintRangeData& ScPageBreakData::GetData(size_t nPos)
99 {
100     DBG_ASSERT(nPos < nAlloc, "ScPageBreakData::GetData bumm");
101 
102     if ( nPos >= nUsed )
103     {
104         DBG_ASSERT(nPos == nUsed, "ScPageBreakData::GetData falsche Reihenfolge");
105         nUsed = nPos+1;
106     }
107 
108     return pData[nPos];
109 }
110 
111 sal_Bool ScPageBreakData::IsEqual( const ScPageBreakData& rOther ) const
112 {
113     if ( nUsed != rOther.nUsed )
114         return sal_False;
115 
116     for (sal_uInt16 i=0; i<nUsed; i++)
117         if ( pData[i].GetPrintRange() != rOther.pData[i].GetPrintRange() )
118             return sal_False;
119 
120     //! ScPrintRangeData komplett vergleichen ??
121 
122     return sal_True;
123 }
124 
125 void ScPageBreakData::AddPages()
126 {
127     if ( nUsed > 1 )
128     {
129         long nPage = pData[0].GetFirstPage();
130         for (sal_uInt16 i=0; sal::static_int_cast<size_t>(i+1)<nUsed; i++)
131         {
132             nPage += ((long)pData[i].GetPagesX())*pData[i].GetPagesY();
133             pData[i+1].SetFirstPage( nPage );
134         }
135     }
136 }
137 
138 
139 
140