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 8 : XFPageMaster::XFPageMaster() : m_fPageWidth(0), m_fPageHeight(0), m_eUsage(enumXFPageUsageNone),
72 : m_eTextDir(enumXFTextDirNone), m_bPrintOrient(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 8 : m_fSepSpaceBelow(0), m_nSepLengthPercent(0)
76 : {
77 8 : }
78 :
79 24 : XFPageMaster::~XFPageMaster()
80 : {
81 8 : if( m_pBorders )
82 0 : delete m_pBorders;
83 8 : if( m_pShadow )
84 0 : delete m_pShadow;
85 8 : if( m_pColumns )
86 0 : delete m_pColumns;
87 8 : if( m_pHeaderStyle )
88 8 : delete m_pHeaderStyle;
89 8 : if( m_pFooterStyle )
90 8 : delete m_pFooterStyle;
91 8 : if( m_pBGImage )
92 0 : delete m_pBGImage;
93 16 : }
94 :
95 64 : enumXFStyle XFPageMaster::GetStyleFamily()
96 : {
97 64 : return enumXFStylePageMaster;
98 : }
99 :
100 8 : void XFPageMaster::SetPageWidth(double width)
101 : {
102 8 : m_fPageWidth = width;
103 8 : }
104 :
105 8 : void XFPageMaster::SetPageHeight(double height)
106 : {
107 8 : m_fPageHeight = height;
108 8 : }
109 :
110 24 : void XFPageMaster::SetMargins(double left, double right,double top, double bottom)
111 : {
112 24 : if( left != -1 )
113 8 : m_aMargin.SetLeft(left);
114 24 : if( right != -1 )
115 8 : m_aMargin.SetRight(right);
116 24 : if( top != -1 )
117 16 : m_aMargin.SetTop(top);
118 24 : if( bottom != -1 )
119 16 : m_aMargin.SetBottom(bottom);
120 24 : }
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 8 : void XFPageMaster::SetBackColor(XFColor color)
137 : {
138 8 : m_aBackColor = color;
139 8 : }
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 8 : void XFPageMaster::SetHeaderStyle(XFHeaderStyle *pHeaderStyle)
156 : {
157 8 : if( m_pHeaderStyle && (pHeaderStyle != m_pHeaderStyle) )
158 0 : delete m_pHeaderStyle;
159 8 : m_pHeaderStyle = pHeaderStyle;
160 8 : }
161 :
162 8 : void XFPageMaster::SetFooterStyle(XFFooterStyle *pFooterStyle)
163 : {
164 8 : if( m_pFooterStyle && (pFooterStyle != m_pFooterStyle) )
165 0 : delete m_pFooterStyle;
166 8 : m_pFooterStyle = pFooterStyle;
167 8 : }
168 :
169 8 : 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 8 : m_eSepAlign = align;
179 8 : m_fSepWidth = width;
180 8 : m_nSepLengthPercent = lengthPercent;
181 8 : m_fSepSpaceAbove = spaceAbove;
182 8 : m_fSepSpaceBelow = spaceBelow;
183 8 : m_aSepColor = color;
184 8 : }
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 6 : void XFPageMaster::ToXml(IXFStream *pStream)
209 : {
210 6 : IXFAttrList *pAttrList = pStream->GetAttrList();
211 :
212 6 : pAttrList->Clear();
213 6 : pAttrList->AddAttribute("style:name",GetStyleName());
214 :
215 6 : if( m_eUsage != enumXFPageUsageNone )
216 0 : pAttrList->AddAttribute("style:page-usage", GetPageUsageName(m_eUsage));
217 :
218 6 : pStream->StartElement( "style:page-master" );
219 :
220 : //style:properties
221 6 : pAttrList->Clear();
222 6 : if( m_fPageWidth != 0 )
223 6 : pAttrList->AddAttribute( "fo:page-width", OUString::number(m_fPageWidth) + "cm" );
224 6 : if( m_fPageHeight != 0 )
225 6 : pAttrList->AddAttribute( "fo:page-height", OUString::number(m_fPageHeight) + "cm" );
226 :
227 6 : m_aMargin.ToXml(pStream);
228 :
229 6 : if( m_bPrintOrient )
230 6 : pAttrList->AddAttribute( "style:print-orientation", "portrait" );
231 : else
232 0 : pAttrList->AddAttribute( "style:print-orientation", "landscape" );
233 :
234 6 : if( m_pBorders )
235 0 : m_pBorders->ToXml(pStream);
236 6 : if( m_pShadow )
237 0 : pAttrList->AddAttribute( "style:shadow", m_pShadow->ToString() );
238 :
239 6 : if( m_aBackColor.IsValid() )
240 6 : pAttrList->AddAttribute( "fo:background-color", m_aBackColor.ToString() );
241 :
242 : //text directory
243 6 : if( m_eTextDir != enumXFTextDirNone )
244 6 : pAttrList->AddAttribute( "style:writing-mode", GetTextDirName(m_eTextDir) );
245 :
246 6 : pStream->StartElement( "style:properties" );
247 6 : if( m_pColumns )
248 0 : m_pColumns->ToXml(pStream);
249 :
250 6 : if( m_pBGImage )
251 0 : m_pBGImage->ToXml(pStream);
252 :
253 6 : if( m_eSepAlign || m_nSepLengthPercent>0 || m_fSepSpaceAbove>0 || m_fSepSpaceBelow>0 )
254 : {
255 6 : pAttrList->Clear();
256 6 : pAttrList->AddAttribute( "style:width", OUString::number(m_fSepWidth) + "cm" );
257 6 : pAttrList->AddAttribute( "style:distance-before-sep", OUString::number(m_fSepSpaceAbove) + "cm" );
258 6 : pAttrList->AddAttribute( "style:distance-after-sep", OUString::number(m_fSepSpaceBelow) + "cm" );
259 6 : pAttrList->AddAttribute( "style:color", m_aSepColor.ToString() );
260 6 : if( m_eSepAlign == enumXFAlignStart )
261 6 : pAttrList->AddAttribute( "style:adjustment", "left" );
262 0 : else if( m_eSepAlign == enumXFAlignCenter )
263 0 : pAttrList->AddAttribute( "style:adjustment", "center" );
264 0 : else if( m_eSepAlign == enumXFAlignEnd )
265 0 : pAttrList->AddAttribute( "style:adjustment", "right" );
266 6 : pAttrList->AddAttribute( "style:rel-width", OUString::number(m_nSepLengthPercent) + "%" );
267 6 : pStream->StartElement( "style:footnote-sep" );
268 6 : pStream->EndElement( "style:footnote-sep" );
269 : }
270 :
271 6 : pStream->EndElement( "style:properties" );
272 :
273 : //header style:
274 6 : if( m_pHeaderStyle )
275 6 : m_pHeaderStyle->ToXml(pStream);
276 : //footer style:
277 6 : if( m_pFooterStyle )
278 6 : m_pFooterStyle->ToXml(pStream);
279 :
280 6 : pStream->EndElement( "style:page-master" );
281 :
282 6 : }
283 :
284 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|