Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * The Contents of this file are made available subject to the terms of
5 : : * either of the following licenses
6 : : *
7 : : * - GNU Lesser General Public License Version 2.1
8 : : * - Sun Industry Standards Source License Version 1.1
9 : : *
10 : : * Sun Microsystems Inc., October, 2000
11 : : *
12 : : * GNU Lesser General Public License Version 2.1
13 : : * =============================================
14 : : * Copyright 2000 by Sun Microsystems, Inc.
15 : : * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 : : *
17 : : * This library is free software; you can redistribute it and/or
18 : : * modify it under the terms of the GNU Lesser General Public
19 : : * License version 2.1, as published by the Free Software Foundation.
20 : : *
21 : : * This library is distributed in the hope that it will be useful,
22 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 : : * Lesser General Public License for more details.
25 : : *
26 : : * You should have received a copy of the GNU Lesser General Public
27 : : * License along with this library; if not, write to the Free Software
28 : : * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 : : * MA 02111-1307 USA
30 : : *
31 : : *
32 : : * Sun Industry Standards Source License Version 1.1
33 : : * =================================================
34 : : * The contents of this file are subject to the Sun Industry Standards
35 : : * Source License Version 1.1 (the "License"); You may not use this file
36 : : * except in compliance with the License. You may obtain a copy of the
37 : : * License at http://www.openoffice.org/license.html.
38 : : *
39 : : * Software provided under this License is provided on an "AS IS" basis,
40 : : * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 : : * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 : : * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 : : * See the License for the specific provisions governing your rights and
44 : : * obligations concerning the Software.
45 : : *
46 : : * The Initial Developer of the Original Code is: IBM Corporation
47 : : *
48 : : * Copyright: 2008 by IBM Corporation
49 : : *
50 : : * All Rights Reserved.
51 : : *
52 : : * Contributor(s): _______________________________________
53 : : *
54 : : *
55 : : ************************************************************************/
56 : : /*************************************************************************
57 : : * @file
58 : : * Page master used bye XFMasterPage.
59 : : * It is the real object to define header and footer of pages.
60 : : ************************************************************************/
61 : : #include "xfpagemaster.hxx"
62 : : #include "ixfstream.hxx"
63 : : #include "ixfattrlist.hxx"
64 : : #include "xfborders.hxx"
65 : : #include "xfshadow.hxx"
66 : : #include "xfcolumns.hxx"
67 : : #include "xfheaderstyle.hxx"
68 : : #include "xffooterstyle.hxx"
69 : : #include "xfbgimage.hxx"
70 : :
71 : 40 : XFPageMaster::XFPageMaster() : m_fPageWidth(0), m_fPageHeight(0), m_eUsage(enumXFPageUsageNone),
72 : : m_eTextDir(enumXFTextDirNone), m_bPrintOrient(sal_True), m_pBorders(NULL), m_pShadow(NULL),
73 : : m_pColumns(NULL), m_pBGImage(NULL), m_pHeaderStyle(NULL), m_pFooterStyle(NULL),
74 : : m_eSepAlign(enumXFAlignNone), m_fSepWidth(0), m_aSepColor(0), m_fSepSpaceAbove(0),
75 [ + - ]: 40 : m_fSepSpaceBelow(0), m_nSepLengthPercent(0)
76 : : {
77 : 40 : }
78 : :
79 : 40 : XFPageMaster::~XFPageMaster()
80 : : {
81 [ - + ]: 40 : if( m_pBorders )
82 : 0 : delete m_pBorders;
83 [ - + ]: 40 : if( m_pShadow )
84 [ # # ][ # # ]: 0 : delete m_pShadow;
85 [ - + ]: 40 : if( m_pColumns )
86 [ # # ][ # # ]: 0 : delete m_pColumns;
87 [ + - ]: 40 : if( m_pHeaderStyle )
88 [ + - ][ + - ]: 40 : delete m_pHeaderStyle;
89 [ + - ]: 40 : if( m_pFooterStyle )
90 [ + - ][ + - ]: 40 : delete m_pFooterStyle;
91 [ - + ]: 40 : if( m_pBGImage )
92 [ # # ][ # # ]: 0 : delete m_pBGImage;
93 [ - + ]: 80 : }
94 : :
95 : 320 : enumXFStyle XFPageMaster::GetStyleFamily()
96 : : {
97 : 320 : return enumXFStylePageMaster;
98 : : }
99 : :
100 : 40 : void XFPageMaster::SetPageWidth(double width)
101 : : {
102 : 40 : m_fPageWidth = width;
103 : 40 : }
104 : :
105 : 40 : void XFPageMaster::SetPageHeight(double height)
106 : : {
107 : 40 : m_fPageHeight = height;
108 : 40 : }
109 : :
110 : 120 : void XFPageMaster::SetMargins(double left, double right,double top, double bottom)
111 : : {
112 [ + + ]: 120 : if( left != -1 )
113 : 40 : m_aMargin.SetLeft(left);
114 [ + + ]: 120 : if( right != -1 )
115 : 40 : m_aMargin.SetRight(right);
116 [ + + ]: 120 : if( top != -1 )
117 : 80 : m_aMargin.SetTop(top);
118 [ + + ]: 120 : if( bottom != -1 )
119 : 80 : m_aMargin.SetBottom(bottom);
120 : 120 : }
121 : :
122 : 0 : void XFPageMaster::SetBorders(XFBorders *pBorders)
123 : : {
124 [ # # ][ # # ]: 0 : if( m_pBorders && (pBorders != m_pBorders) )
125 : 0 : delete m_pBorders;
126 : 0 : m_pBorders = pBorders;
127 : 0 : }
128 : :
129 : 0 : void XFPageMaster::SetShadow(XFShadow *pShadow)
130 : : {
131 [ # # ][ # # ]: 0 : if( m_pShadow && (pShadow != m_pShadow) )
132 [ # # ]: 0 : delete m_pShadow;
133 : 0 : m_pShadow = pShadow;
134 : 0 : }
135 : :
136 : 40 : void XFPageMaster::SetBackColor(XFColor color)
137 : : {
138 : 40 : m_aBackColor = color;
139 : 40 : }
140 : :
141 : 0 : void XFPageMaster::SetBackImage(XFBGImage *image)
142 : : {
143 [ # # ]: 0 : if( m_pBGImage )
144 [ # # ]: 0 : delete m_pBGImage;
145 : 0 : m_pBGImage = image;
146 : 0 : }
147 : :
148 : 0 : void XFPageMaster::SetColumns(XFColumns *pColumns)
149 : : {
150 [ # # ][ # # ]: 0 : if( m_pColumns && (pColumns != m_pColumns) )
151 [ # # ]: 0 : delete m_pColumns;
152 : 0 : m_pColumns = pColumns;
153 : 0 : }
154 : :
155 : 40 : void XFPageMaster::SetHeaderStyle(XFHeaderStyle *pHeaderStyle)
156 : : {
157 [ - + ][ # # ]: 40 : if( m_pHeaderStyle && (pHeaderStyle != m_pHeaderStyle) )
158 [ # # ]: 0 : delete m_pHeaderStyle;
159 : 40 : m_pHeaderStyle = pHeaderStyle;
160 : 40 : }
161 : :
162 : 40 : void XFPageMaster::SetFooterStyle(XFFooterStyle *pFooterStyle)
163 : : {
164 [ - + ][ # # ]: 40 : if( m_pFooterStyle && (pFooterStyle != m_pFooterStyle) )
165 [ # # ]: 0 : delete m_pFooterStyle;
166 : 40 : m_pFooterStyle = pFooterStyle;
167 : 40 : }
168 : :
169 : 40 : void XFPageMaster::SetFootNoteSeparator(
170 : : enumXFAlignType align,
171 : : double width,
172 : : sal_Int32 lengthPercent,
173 : : double spaceAbove,
174 : : double spaceBelow,
175 : : XFColor color
176 : : )
177 : : {
178 : 40 : m_eSepAlign = align;
179 : 40 : m_fSepWidth = width;
180 : 40 : m_nSepLengthPercent = lengthPercent;
181 : 40 : m_fSepSpaceAbove = spaceAbove;
182 : 40 : m_fSepSpaceBelow = spaceBelow;
183 : 40 : m_aSepColor = color;
184 : 40 : }
185 : :
186 : : /**
187 : : *
188 : : <style:page-master style:name="pm1">
189 : : <style:properties fo:page-width="20.999cm" fo:page-height="29.699cm" style:num-format="1"
190 : : style:print-orientation="portrait" fo:margin-top="1.249cm" fo:margin-bottom="1.249cm"
191 : : fo:margin-left="3.175cm" fo:margin-right="3.175cm" style:writing-mode="lr-tb"
192 : : style:layout-grid-color="#c0c0c0" style:layout-grid-lines="42"
193 : : style:layout-grid-base-height="0.494cm" style:layout-grid-ruby-height="0.141cm"
194 : : style:layout-grid-mode="none" style:layout-grid-ruby-below="false" style:layout-grid-print="false"
195 : : style:layout-grid-display="false" style:footnote-max-height="0cm">
196 : : <style:footnote-sep style:width="0.018cm" style:distance-before-sep="0.101cm"
197 : : style:distance-after-sep="0.101cm" style:adjustment="left" style:rel-width="25%" style:color="#000000"/>
198 : : </style:properties>
199 : : <style:header-style>
200 : : <style:properties fo:min-height="1.291cm" fo:margin-bottom="0.792cm" style:dynamic-spacing="true"/>
201 : : </style:header-style>
202 : : <style:footer-style>
203 : : <style:properties fo:min-height="1.291cm" fo:margin-top="0.792cm" style:dynamic-spacing="true"/>
204 : : </style:footer-style>
205 : : </style:page-master>
206 : :
207 : : */
208 : 30 : void XFPageMaster::ToXml(IXFStream *pStream)
209 : : {
210 : 30 : IXFAttrList *pAttrList = pStream->GetAttrList();
211 : :
212 : 30 : pAttrList->Clear();
213 [ + - ]: 30 : pAttrList->AddAttribute(A2OUSTR("style:name"),GetStyleName());
214 : :
215 [ - + ]: 30 : if( m_eUsage != enumXFPageUsageNone )
216 [ # # ]: 0 : pAttrList->AddAttribute(A2OUSTR("style:page-usage"), GetPageUsageName(m_eUsage));
217 : :
218 [ + - ]: 30 : pStream->StartElement( A2OUSTR("style:page-master") );
219 : :
220 : : //style:properties
221 : 30 : pAttrList->Clear();
222 [ + - ]: 30 : if( m_fPageWidth != 0 )
223 [ + - ][ + - ]: 30 : pAttrList->AddAttribute( A2OUSTR("fo:page-width"), DoubleToOUString(m_fPageWidth) + A2OUSTR("cm") );
224 [ + - ]: 30 : if( m_fPageHeight != 0 )
225 [ + - ][ + - ]: 30 : pAttrList->AddAttribute( A2OUSTR("fo:page-height"), DoubleToOUString(m_fPageHeight) + A2OUSTR("cm") );
226 : :
227 : 30 : m_aMargin.ToXml(pStream);
228 : :
229 [ + - ]: 30 : if( m_bPrintOrient )
230 [ + - ]: 30 : pAttrList->AddAttribute( A2OUSTR("style:print-orientation"), A2OUSTR("portrait") );
231 : : else
232 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("style:print-orientation"), A2OUSTR("landscape") );
233 : :
234 [ - + ]: 30 : if( m_pBorders )
235 : 0 : m_pBorders->ToXml(pStream);
236 [ - + ]: 30 : if( m_pShadow )
237 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("style:shadow"), m_pShadow->ToString() );
238 : :
239 [ + - ]: 30 : if( m_aBackColor.IsValid() )
240 [ + - ]: 30 : pAttrList->AddAttribute( A2OUSTR("fo:background-color"), m_aBackColor.ToString() );
241 : :
242 : : //text directory
243 [ + - ]: 30 : if( m_eTextDir != enumXFTextDirNone )
244 [ + - ]: 30 : pAttrList->AddAttribute( A2OUSTR("style:writing-mode"), GetTextDirName(m_eTextDir) );
245 : :
246 [ + - ]: 30 : pStream->StartElement( A2OUSTR("style:properties") );
247 [ - + ]: 30 : if( m_pColumns )
248 : 0 : m_pColumns->ToXml(pStream);
249 : :
250 [ - + ]: 30 : if( m_pBGImage )
251 : 0 : m_pBGImage->ToXml(pStream);
252 : :
253 [ - + ][ # # ]: 30 : if( m_eSepAlign || m_nSepLengthPercent>0 || m_fSepSpaceAbove>0 || m_fSepSpaceBelow>0 )
[ # # ][ # # ]
254 : : {
255 : 30 : pAttrList->Clear();
256 [ + - ][ + - ]: 30 : pAttrList->AddAttribute( A2OUSTR("style:width"), DoubleToOUString(m_fSepWidth) + A2OUSTR("cm") );
257 [ + - ][ + - ]: 30 : pAttrList->AddAttribute( A2OUSTR("style:distance-before-sep"), DoubleToOUString(m_fSepSpaceAbove) + A2OUSTR("cm") );
258 [ + - ][ + - ]: 30 : pAttrList->AddAttribute( A2OUSTR("style:distance-after-sep"), DoubleToOUString(m_fSepSpaceBelow) + A2OUSTR("cm") );
259 [ + - ]: 30 : pAttrList->AddAttribute( A2OUSTR("style:color"), m_aSepColor.ToString() );
260 [ + - ]: 30 : if( m_eSepAlign == enumXFAlignStart )
261 [ + - ]: 30 : pAttrList->AddAttribute( A2OUSTR("style:adjustment"), A2OUSTR("left") );
262 [ # # ]: 0 : else if( m_eSepAlign == enumXFAlignCenter )
263 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("style:adjustment"), A2OUSTR("center") );
264 [ # # ]: 0 : else if( m_eSepAlign == enumXFAlignEnd )
265 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("style:adjustment"), A2OUSTR("right") );
266 [ + - ][ + - ]: 30 : pAttrList->AddAttribute( A2OUSTR("style:rel-width"), Int32ToOUString(m_nSepLengthPercent) + A2OUSTR("%") );
267 [ + - ]: 30 : pStream->StartElement( A2OUSTR("style:footnote-sep") );
268 [ + - ]: 30 : pStream->EndElement( A2OUSTR("style:footnote-sep") );
269 : : }
270 : :
271 [ + - ]: 30 : pStream->EndElement( A2OUSTR("style:properties") );
272 : :
273 : : //header style:
274 [ + - ]: 30 : if( m_pHeaderStyle )
275 : 30 : m_pHeaderStyle->ToXml(pStream);
276 : : //footer style:
277 [ + - ]: 30 : if( m_pFooterStyle )
278 : 30 : m_pFooterStyle->ToXml(pStream);
279 : :
280 [ + - ]: 30 : pStream->EndElement( A2OUSTR("style:page-master") );
281 : :
282 : 30 : }
283 : :
284 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|