LibreOffice Module lotuswordpro (master) 1
xfcell.cxx
Go to the documentation of this file.
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 <xfilter/xfcell.hxx>
61
62#include <stdexcept>
63
66#include <xfilter/xftable.hxx>
67#include <xfilter/xfrow.hxx>
68#include <xfilter/xfutil.hxx>
69
71 : m_pOwnerRow(nullptr)
72 , m_nCol(0)
73 , m_nColSpaned(1)
74 , m_nRepeated(0)
75 , m_eValueType(enumXFValueTypeNone)
76 , m_bProtect(false)
77{}
78
80{
81}
82
83void XFCell::Add(XFContent *pContent)
84{
86 {
87 Reset();
89 }
90 if (m_pSubTable.is())
91 {
92 throw std::runtime_error("subtable already set");
93 }
94 if (!pContent)
95 {
96 throw std::runtime_error("no content");
97 }
98 if( pContent->GetContentType() == enumXFContentTable )
99 {
100 XFTable *pTable = dynamic_cast<XFTable*>(pContent);
101 if( !pTable )
102 return;
103 //the sub table will fill all the cell, there can't be other contents.
104 pTable->SetOwnerCell(this);
105 m_pSubTable = pTable;
106 }
107 else if( pContent->GetContentType() == enumXFContentText )
108 {
109 XFParagraph *pPara = new XFParagraph();
110 pPara->Add(pContent);
112 }
113 else if( pContent->GetContentType() == enumXFContentFrame )
114 {
115 XFParagraph *pPara = new XFParagraph();
116 pPara->Add(pContent);
118 }
119 else
120 {
121 XFContentContainer::Add(pContent);
122 }
123}
124
125void XFCell::SetValue(double value)
126{
127 SetValue(OUString::number(value));
128}
129
130void XFCell::SetValue(const OUString& value)
131{
134}
135
137{
138 XFRow *pRow = m_pOwnerRow;
139
140 if( !pRow )
141 return OUString();
142
143 XFTable *pTable = pRow->GetOwnerTable();
144
145 if( !pTable )
146 return OUString();
147
148 OUString name;
149 if( pTable->IsSubTable() )
150 {
151 name = pTable->GetTableName() + "." + OUString::number(m_nCol) + "." + OUString::number(pRow->GetRow());
152 }
153 else
154 {
155 name = GetTableColName(m_nCol) + OUString::number(pRow->GetRow());
156 }
157 return name;
158}
159
161{
162 IXFAttrList *pAttrList = pStrm->GetAttrList();
163
164 pAttrList->Clear();
165 if( !GetStyleName().isEmpty() )
166 pAttrList->AddAttribute( "table:style-name", GetStyleName() );
167 if( m_nColSpaned>1 )
168 pAttrList->AddAttribute( "table:number-columns-spanned", OUString::number(m_nColSpaned) );
169 if( m_nRepeated )
170 pAttrList->AddAttribute( "table:number-columns-repeated", OUString::number(m_nRepeated) );
172 {
173 pAttrList->AddAttribute( "table:value-type", GetValueType(m_eValueType) );
174 pAttrList->AddAttribute( "table:value", m_strValue );
175 }
176 if( !m_strFormula.isEmpty() )
177 pAttrList->AddAttribute( "table:formula", m_strFormula );
178
179 if( m_bProtect )
180 pAttrList->AddAttribute( "table:protected", "true" );
181
182 //for test only.
183// pAttrList->AddAttribute( "table:cell-name", GetCellName() );
184
185 pStrm->StartElement( "table:table-cell" );
186
187 if( m_pSubTable.is() )
188 m_pSubTable->ToXml(pStrm);
189 else
190 {
192 }
193
194 pStrm->EndElement( "table:table-cell" );
195}
196
197/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Attribute list interface for sax writer.
Definition: ixfattrlist.hxx:72
virtual void Clear()=0
@descr: Clear all the attributes in the attribute list.
virtual void AddAttribute(const OUString &name, const OUString &value)=0
@descr: Add an attribute to the attribute list.
Stream wrapper for sax writer.
Definition: ixfstream.hxx:72
virtual IXFAttrList * GetAttrList()=0
@descr return the Attribute list interface.
virtual void StartElement(const OUString &oustr)=0
@descr Wrap XDocumentHandler::startElement()
virtual void EndElement(const OUString &oustr)=0
@descr Wrap XDocumentHandler::endElement()
void Add(XFContent *pContent) override
@descr Add content for table cell.
Definition: xfcell.cxx:83
rtl::Reference< XFTable > m_pSubTable
Definition: xfcell.hxx:150
bool m_bProtect
Definition: xfcell.hxx:157
OUString m_strValue
Definition: xfcell.hxx:155
virtual ~XFCell() override
Definition: xfcell.cxx:79
sal_Int32 m_nRepeated
Definition: xfcell.hxx:153
enumXFValueType m_eValueType
Definition: xfcell.hxx:154
sal_Int32 m_nColSpaned
Definition: xfcell.hxx:152
void SetValue(double value)
@descr Set cell number value.
Definition: xfcell.cxx:125
virtual void ToXml(IXFStream *pStrm) override
@descr Output cell as xml element.
Definition: xfcell.cxx:160
XFRow * m_pOwnerRow
Definition: xfcell.hxx:148
XFCell()
Definition: xfcell.cxx:70
sal_Int32 m_nCol
Definition: xfcell.hxx:151
OUString m_strFormula
Definition: xfcell.hxx:156
OUString GetCellName()
@descr Return cell name.
Definition: xfcell.cxx:136
virtual void ToXml(IXFStream *pStrm) override
@descr Output to OOo model or local file.
virtual void Add(XFContent *pContent)
@descr Add content.
void Reset()
@descr clear all contents in the container.
@descr Base class for all content object.
Definition: xfcontent.hxx:80
const OUString & GetStyleName() const
: return the style name.
Definition: xfcontent.hxx:95
virtual enumXFContent GetContentType()
: return the content type.
Definition: xfcontent.hxx:85
Paragraph object for SODC.
Definition: xfparagraph.hxx:73
Definition: xfrow.hxx:69
sal_Int32 GetRow() const
Definition: xfrow.hxx:116
XFTable * GetOwnerTable()
Definition: xfrow.hxx:121
void SetOwnerCell(XFCell *pCell)
Definition: xftable.hxx:127
bool IsSubTable() const
Definition: xftable.hxx:133
OUString GetTableName()
Definition: xftable.cxx:145
Any value
const char * name
@ enumXFValueTypeFloat
Definition: xfdefs.hxx:410
@ enumXFValueTypeNone
Definition: xfdefs.hxx:406
@ enumXFContentFrame
Definition: xfdefs.hxx:75
@ enumXFContentText
Definition: xfdefs.hxx:66
@ enumXFContentTable
Definition: xfdefs.hxx:70
OUString GetTableColName(sal_Int32 col)
Definition: xfutil.cxx:62
OUString GetValueType(enumXFValueType type)
Definition: xfutil.cxx:342