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 : * Table cell style. Number format, string value, and so on...
59 : ************************************************************************/
60 : #include "xfcellstyle.hxx"
61 : #include "xfborders.hxx"
62 : #include "xffont.hxx"
63 : #include "xfbgimage.hxx"
64 :
65 :
66 150 : XFCellStyle::XFCellStyle()
67 : {
68 150 : m_eHoriAlign = enumXFAlignNone;
69 150 : m_eVertAlign = enumXFAlignNone;
70 150 : m_fTextIndent = 0;
71 150 : m_pBorders = NULL;
72 150 : m_pFont = NULL;
73 150 : m_pBackImage = NULL;
74 150 : m_bWrapText = sal_False;
75 150 : }
76 :
77 450 : XFCellStyle::~XFCellStyle()
78 : {
79 150 : if( m_pBorders )
80 38 : delete m_pBorders;
81 300 : }
82 :
83 150 : void XFCellStyle::SetPadding(double left, double right,double top, double bottom)
84 : {
85 150 : if( left != -1 )
86 150 : m_aPadding.SetLeft(left);
87 150 : if( right != -1 )
88 150 : m_aPadding.SetRight(right);
89 150 : if( top != -1 )
90 150 : m_aPadding.SetTop(top);
91 150 : if( bottom != -1 )
92 150 : m_aPadding.SetBottom( bottom );
93 150 : }
94 :
95 0 : void XFCellStyle::SetBackColor(XFColor& color)
96 : {
97 0 : m_aBackColor = color;
98 0 : }
99 :
100 0 : void XFCellStyle::SetBackImage(XFBGImage *pImage)
101 : {
102 0 : if( m_pBackImage )
103 0 : delete m_pBackImage;
104 0 : m_pBackImage = pImage;
105 0 : }
106 :
107 38 : void XFCellStyle::SetBorders(XFBorders *pBorders)
108 : {
109 38 : if( m_pBorders )
110 0 : delete m_pBorders;
111 38 : m_pBorders = pBorders;
112 38 : }
113 :
114 2974 : enumXFStyle XFCellStyle::GetStyleFamily()
115 : {
116 2974 : return enumXFStyleTableCell;
117 : }
118 :
119 : /**
120 : *Affirm whether two XFCellStyle objects are equal.
121 : */
122 424 : sal_Bool XFCellStyle::Equal(IXFStyle *pStyle)
123 : {
124 424 : if( this == pStyle )
125 0 : return sal_True;
126 424 : if( !pStyle || pStyle->GetStyleFamily() != enumXFStyleTableCell )
127 0 : return sal_False;
128 :
129 424 : XFCellStyle *pOther = static_cast<XFCellStyle*>(pStyle);
130 424 : if( !pOther )
131 0 : return sal_False;
132 :
133 424 : if( m_strDataStyle != pOther->m_strDataStyle )
134 162 : return sal_False;
135 :
136 262 : if( m_strParentStyleName != pOther->m_strParentStyleName )
137 0 : return sal_False;
138 262 : if( m_fTextIndent != pOther->m_fTextIndent )
139 0 : return sal_False;
140 :
141 : //align:
142 262 : if( m_eHoriAlign != pOther->m_eHoriAlign )
143 0 : return sal_False;
144 262 : if( m_eVertAlign != pOther->m_eVertAlign )
145 0 : return sal_False;
146 :
147 262 : if( m_aBackColor != pOther->m_aBackColor )
148 0 : return sal_False;
149 : //shadow:
150 262 : if( m_aShadow != pOther->m_aShadow )
151 0 : return sal_False;
152 : //margin:
153 262 : if( m_aMargin != pOther->m_aMargin )
154 0 : return sal_False;
155 : //padding:
156 262 : if( m_aPadding != pOther->m_aPadding )
157 96 : return sal_False;
158 :
159 : //wrap:
160 166 : if( m_bWrapText != pOther->m_bWrapText )
161 0 : return sal_False;
162 :
163 : //font:
164 166 : if( m_pFont )
165 : {
166 0 : if( !pOther->m_pFont )
167 0 : return sal_False;
168 0 : if(*m_pFont != *pOther->m_pFont )
169 0 : return sal_False;
170 : }
171 166 : else if( pOther->m_pFont )
172 0 : return sal_False;
173 :
174 : //border:
175 166 : if( m_pBorders )
176 : {
177 66 : if( !pOther->m_pBorders )
178 0 : return sal_False;
179 66 : if( *m_pBorders != *pOther->m_pBorders )
180 60 : return sal_False;
181 : }
182 100 : else if( pOther->m_pBorders )
183 16 : return sal_False;
184 :
185 : //if there is backimage
186 90 : if( m_pBackImage )
187 : {
188 0 : if( !pOther->m_pBackImage )
189 0 : return sal_False;
190 0 : if( !m_pBackImage->Equal(pOther) )
191 0 : return sal_False;
192 : }
193 : else
194 : {
195 90 : if( pOther->m_pBackImage )
196 0 : return sal_False;
197 : }
198 :
199 90 : return sal_True;
200 : }
201 :
202 44 : void XFCellStyle::ToXml(IXFStream *pStrm)
203 : {
204 44 : IXFAttrList *pAttrList = pStrm->GetAttrList();
205 44 : rtl::OUString style = GetStyleName();
206 :
207 44 : pAttrList->Clear();
208 44 : if( !style.isEmpty() )
209 44 : pAttrList->AddAttribute(A2OUSTR("style:name"),GetStyleName());
210 44 : if( !GetParentStyleName().isEmpty() )
211 0 : pAttrList->AddAttribute(A2OUSTR("style:parent-style-name"),GetParentStyleName());
212 :
213 44 : pAttrList->AddAttribute(A2OUSTR("style:family"), A2OUSTR("table-cell"));
214 44 : if( !m_strParentStyleName.isEmpty() )
215 0 : pAttrList->AddAttribute(A2OUSTR("style:parent-style-name"),m_strParentStyleName);
216 44 : if( !m_strDataStyle.isEmpty() )
217 26 : pAttrList->AddAttribute( A2OUSTR("style:data-style-name"), m_strDataStyle );
218 :
219 44 : pStrm->StartElement(A2OUSTR("style:style"));
220 :
221 : //Paragraph properties:
222 44 : pAttrList->Clear();
223 :
224 : //text indent:
225 44 : if( m_fTextIndent>FLOAT_MIN )
226 : {
227 0 : pAttrList->AddAttribute(A2OUSTR("fo:text-indent"), DoubleToOUString(m_fTextIndent) + A2OUSTR("cm") );
228 : }
229 : //padding:
230 44 : m_aPadding.ToXml(pStrm);
231 : //margin:
232 44 : m_aMargin.ToXml(pStrm);
233 :
234 : //text horizontal align:
235 44 : if( m_eHoriAlign != enumXFAlignNone )
236 : {
237 0 : pAttrList->AddAttribute(A2OUSTR("fo:text-align"), GetAlignName(m_eHoriAlign) );
238 : }
239 : //text vertical align
240 44 : if( m_eVertAlign != enumXFAlignNone )
241 44 : pAttrList->AddAttribute( A2OUSTR("fo:vertical-align"), GetAlignName(m_eVertAlign) );
242 :
243 : //wrap text:
244 44 : if( m_bWrapText )
245 0 : pAttrList->AddAttribute( A2OUSTR("fo:wrap-option"), A2OUSTR("wrap") );
246 :
247 : //shadow:
248 44 : m_aShadow.ToXml(pStrm);
249 : //borders:
250 44 : if( m_pBorders )
251 24 : m_pBorders->ToXml(pStrm);
252 :
253 : //background color:
254 44 : if( m_aBackColor.IsValid() && !m_pBackImage )
255 : {
256 0 : pAttrList->AddAttribute(A2OUSTR("fo:background-color"), m_aBackColor.ToString() );
257 : }
258 : //Font properties:
259 44 : if( m_pFont )
260 0 : m_pFont->ToXml(pStrm);
261 :
262 44 : pStrm->StartElement(A2OUSTR("style:properties"));
263 :
264 44 : if( m_pBackImage )
265 0 : m_pBackImage->ToXml(pStrm);
266 :
267 44 : pStrm->EndElement(A2OUSTR("style:properties"));
268 :
269 44 : pStrm->EndElement(A2OUSTR("style:style"));
270 44 : }
271 :
272 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|