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.
59 : ************************************************************************/
60 : #include "xfcell.hxx"
61 : #include "xfparagraph.hxx"
62 : #include "xftable.hxx"
63 : #include "xfrow.hxx"
64 :
65 20 : XFCell::XFCell()
66 : {
67 20 : m_pSubTable = NULL;
68 20 : m_pOwnerRow = NULL;
69 20 : m_nCol = 0;
70 20 : m_nColSpaned = 1;
71 20 : m_nRepeated = 0;
72 20 : m_eValueType = enumXFValueTypeNone;
73 20 : m_bProtect = false;
74 20 : }
75 :
76 0 : XFCell::~XFCell()
77 : {
78 0 : if( m_pSubTable )
79 0 : delete m_pSubTable;
80 0 : }
81 :
82 0 : void XFCell::Add(XFContent *pContent)
83 : {
84 0 : if( m_eValueType != enumXFValueTypeNone )
85 : {
86 0 : Reset();
87 0 : m_eValueType = enumXFValueTypeNone;
88 : }
89 0 : if( m_pSubTable )
90 : {
91 : assert(false);
92 0 : return;
93 : }
94 0 : if( pContent->GetContentType() == enumXFContentTable )
95 : {
96 0 : XFTable *pTable = static_cast<XFTable*>(pContent);
97 0 : if( !pTable )
98 0 : return;
99 : //the sub table will fill all the cell, there can't be other contents.
100 0 : pTable->SetOwnerCell(this);
101 0 : m_pSubTable = pTable;
102 : }
103 0 : else if( pContent->GetContentType() == enumXFContentText )
104 : {
105 0 : XFParagraph *pPara = new XFParagraph();
106 0 : pPara->Add(pContent);
107 0 : XFContentContainer::Add(pPara);
108 : }
109 0 : else if( pContent->GetContentType() == enumXFContentFrame )
110 : {
111 0 : XFParagraph *pPara = new XFParagraph();
112 0 : pPara->Add(pContent);
113 0 : XFContentContainer::Add(pPara);
114 : }
115 : else
116 : {
117 0 : XFContentContainer::Add(pContent);
118 : }
119 : }
120 :
121 0 : void XFCell::SetValue(double value)
122 : {
123 0 : SetValue(OUString::number(value));
124 0 : }
125 :
126 0 : void XFCell::SetValue(const OUString& value)
127 : {
128 0 : m_eValueType = enumXFValueTypeFloat;
129 0 : m_strValue = value;
130 0 : }
131 :
132 0 : OUString XFCell::GetCellName()
133 : {
134 0 : XFRow *pRow = m_pOwnerRow;
135 :
136 0 : if( !pRow )
137 0 : return OUString("");
138 :
139 0 : XFTable *pTable = pRow->GetOwnerTable();
140 :
141 0 : if( !pTable )
142 0 : return OUString("");
143 :
144 0 : OUString name;
145 0 : if( pTable->IsSubTable() )
146 : {
147 0 : name = pTable->GetTableName() + "." + OUString::number(m_nCol) + "." + OUString::number(pRow->GetRow());
148 : }
149 : else
150 : {
151 0 : name = GetTableColName(m_nCol) + OUString::number(pRow->GetRow());
152 : }
153 0 : return name;
154 : }
155 :
156 0 : void XFCell::ToXml(IXFStream *pStrm)
157 : {
158 0 : IXFAttrList *pAttrList = pStrm->GetAttrList();
159 :
160 0 : pAttrList->Clear();
161 0 : if( !GetStyleName().isEmpty() )
162 0 : pAttrList->AddAttribute( "table:style-name", GetStyleName() );
163 0 : if( m_nColSpaned>1 )
164 0 : pAttrList->AddAttribute( "table:number-columns-spanned", OUString::number(m_nColSpaned) );
165 0 : if( m_nRepeated )
166 0 : pAttrList->AddAttribute( "table:number-columns-repeated", OUString::number(m_nRepeated) );
167 0 : if( m_eValueType != enumXFValueTypeNone )
168 : {
169 0 : pAttrList->AddAttribute( "table:value-type", GetValueType(m_eValueType) );
170 0 : pAttrList->AddAttribute( "table:value", m_strValue );
171 : }
172 0 : if( !m_strFormula.isEmpty() )
173 0 : pAttrList->AddAttribute( "table:formula", m_strFormula );
174 :
175 0 : if( m_bProtect )
176 0 : pAttrList->AddAttribute( "table:protected", "true" );
177 :
178 : //for test only.
179 : // pAttrList->AddAttribute( "table:cell-name", GetCellName() );
180 :
181 0 : pStrm->StartElement( "table:table-cell" );
182 :
183 0 : if( m_pSubTable )
184 0 : m_pSubTable->ToXml(pStrm);
185 : else
186 : {
187 0 : XFContentContainer::ToXml(pStrm);
188 : }
189 :
190 0 : pStrm->EndElement( "table:table-cell" );
191 0 : }
192 :
193 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|