1 /* TableStyle: Stores (and writes) table-based information that is
2 * needed at the head of an OO document.
4 * Copyright (C) 2002-2004 William Lachance (william.lachance@sympatico.ca)
5 * Copyright (C) 2004 Net Integration Technologies, Inc. (http://www.net-itech.com)
6 * Copyright (C) 2004 Fridrich Strba (fridrich.strba@bluewin.ch)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * For further information visit http://libwpd.sourceforge.net
26 /* "This product is not manufactured, approved, or supported by
27 * Corel Corporation or Corel Corporation Limited."
31 #include "FilterInternal.hxx"
32 #include "TableStyle.hxx"
33 #include "DocumentElement.hxx"
39 TableCellStyle::TableCellStyle(const WPXPropertyList
&xPropList
, const char *psName
) :
45 void TableCellStyle::write(DocumentHandler
*pHandler
) const
47 TagOpenElement
styleOpen("style:style");
48 styleOpen
.addAttribute("style:name", getName());
49 styleOpen
.addAttribute("style:family", "table-cell");
50 styleOpen
.write(pHandler
);
52 // WLACH_REFACTORING: Only temporary.. a much better solution is to
53 // generalize this sort of thing into the "Style" superclass
54 WPXPropertyList stylePropList
;
55 WPXPropertyList::Iter
i(mPropList
);
56 for (i
.rewind(); i
.next();)
58 if (strlen(i
.key()) > 2 && strncmp(i
.key(), "fo", 2) == 0)
59 stylePropList
.insert(i
.key(), i()->clone());
61 stylePropList
.insert("fo:padding", "0.0382inch");
62 pHandler
->startElement("style:properties", stylePropList
);
63 pHandler
->endElement("style:properties");
65 pHandler
->endElement("style:style");
68 TableRowStyle::TableRowStyle(const WPXPropertyList
&propList
, const char *psName
) :
74 void TableRowStyle::write(DocumentHandler
*pHandler
) const
76 TagOpenElement
styleOpen("style:style");
77 styleOpen
.addAttribute("style:name", getName());
78 styleOpen
.addAttribute("style:family", "table-row");
79 styleOpen
.write(pHandler
);
81 TagOpenElement
stylePropertiesOpen("style:properties");
82 if (mPropList
["style:min-row-height"])
83 stylePropertiesOpen
.addAttribute("style:min-row-height", mPropList
["style:min-row-height"]->getStr());
84 else if (mPropList
["style:row-height"])
85 stylePropertiesOpen
.addAttribute("style:row-height", mPropList
["style:row-height"]->getStr());
86 stylePropertiesOpen
.write(pHandler
);
87 pHandler
->endElement("style:properties");
89 pHandler
->endElement("style:style");
93 TableStyle::TableStyle(const WPXPropertyList
&xPropList
, const WPXPropertyListVector
&columns
, const char *psName
) :
100 TableStyle::~TableStyle()
102 typedef std::vector
<TableCellStyle
*>::iterator TCSVIter
;
103 typedef std::vector
<TableRowStyle
*>::iterator TRSVIter
;
104 for (TCSVIter iterTableCellStyles
= mTableCellStyles
.begin() ; iterTableCellStyles
!= mTableCellStyles
.end(); iterTableCellStyles
++)
105 delete(*iterTableCellStyles
);
106 for (TRSVIter iterTableRowStyles
= mTableRowStyles
.begin() ; iterTableRowStyles
!= mTableRowStyles
.end(); iterTableRowStyles
++)
107 delete(*iterTableRowStyles
);
111 void TableStyle::write(DocumentHandler
*pHandler
) const
113 TagOpenElement
styleOpen("style:style");
114 styleOpen
.addAttribute("style:name", getName());
115 styleOpen
.addAttribute("style:family", "table");
116 if (getMasterPageName())
117 styleOpen
.addAttribute("style:master-page-name", getMasterPageName()->cstr());
118 styleOpen
.write(pHandler
);
120 TagOpenElement
stylePropertiesOpen("style:properties");
121 if (mPropList
["table:align"])
122 stylePropertiesOpen
.addAttribute("table:align", mPropList
["table:align"]->getStr());
123 if (mPropList
["fo:margin-left"])
124 stylePropertiesOpen
.addAttribute("fo:margin-left", mPropList
["fo:margin-left"]->getStr());
125 if (mPropList
["fo:margin-right"])
126 stylePropertiesOpen
.addAttribute("fo:margin-right", mPropList
["fo:margin-right"]->getStr());
127 if (mPropList
["style:width"])
128 stylePropertiesOpen
.addAttribute("style:width", mPropList
["style:width"]->getStr());
129 if (mPropList
["fo:break-before"])
130 stylePropertiesOpen
.addAttribute("fo:break-before", mPropList
["fo:break-before"]->getStr());
131 stylePropertiesOpen
.write(pHandler
);
133 pHandler
->endElement("style:properties");
135 pHandler
->endElement("style:style");
138 WPXPropertyListVector::Iter
j(mColumns
);
139 for (j
.rewind(); j
.next();)
141 TagOpenElement
styleNestedOpen("style:style");
142 WPXString sColumnName
;
143 sColumnName
.sprintf("%s.Column%i", getName().cstr(), i
);
144 styleNestedOpen
.addAttribute("style:name", sColumnName
);
145 styleNestedOpen
.addAttribute("style:family", "table-column");
146 styleNestedOpen
.write(pHandler
);
148 pHandler
->startElement("style:properties", j());
149 pHandler
->endElement("style:properties");
151 pHandler
->endElement("style:style");
156 typedef std::vector
<TableRowStyle
*>::const_iterator TRSVIter
;
157 for (TRSVIter iterTableRow
= mTableRowStyles
.begin() ; iterTableRow
!= mTableRowStyles
.end(); iterTableRow
++)
158 (*iterTableRow
)->write(pHandler
);
160 typedef std::vector
<TableCellStyle
*>::const_iterator TCSVIter
;
161 for (TCSVIter iterTableCell
= mTableCellStyles
.begin() ; iterTableCell
!= mTableCellStyles
.end(); iterTableCell
++)
162 (*iterTableCell
)->write(pHandler
);