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