filters

TableStyle.cxx

00001 /* TableStyle: Stores (and writes) table-based information that is 
00002  * needed at the head of an OO document.
00003  *
00004  * Copyright (C) 2002-2004 William Lachance (william.lachance@sympatico.ca)
00005  * Copyright (C) 2004 Net Integration Technologies, Inc. (http://www.net-itech.com)
00006  * Copyright (C) 2004 Fridrich Strba (fridrich.strba@bluewin.ch)
00007  * 
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2 of the License, or (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Library General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Library General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
00021  * Boston, MA 02110-1301, USA.
00022  *
00023  * For further information visit http://libwpd.sourceforge.net
00024  *
00025  */
00026 
00027 /* "This product is not manufactured, approved, or supported by 
00028  * Corel Corporation or Corel Corporation Limited."
00029  */
00030 #include <cstring>
00031 #include <math.h>
00032 #include "FilterInternal.hxx"
00033 #include "TableStyle.hxx"
00034 #include "DocumentElement.hxx"
00035 
00036 #ifdef _MSC_VER
00037 #include <minmax.h>
00038 #endif
00039 
00040 TableCellStyle::TableCellStyle(const WPXPropertyList &xPropList, const char *psName) :
00041     Style(psName),
00042         mPropList(xPropList)
00043 {
00044 }
00045 
00046 void TableCellStyle::write(DocumentHandler &xHandler) const
00047 {
00048     TagOpenElement styleOpen("style:style");
00049     styleOpen.addAttribute("style:name", getName());
00050     styleOpen.addAttribute("style:family", "table-cell");
00051     styleOpen.write(xHandler);
00052 
00053         // WLACH_REFACTORING: Only temporary.. a much better solution is to
00054         // generalize this sort of thing into the "Style" superclass
00055         WPXPropertyList stylePropList;
00056         WPXPropertyList::Iter i(mPropList);
00057         for (i.rewind(); i.next();)
00058         {
00059                 if (strlen(i.key()) > 2 && strncmp(i.key(), "fo", 2) == 0)
00060                         stylePropList.insert(i.key(), i()->clone());
00061         }
00062         stylePropList.insert("fo:padding", "0.0382inch");
00063         xHandler.startElement("style:properties", stylePropList);
00064     xHandler.endElement("style:properties");
00065 
00066     xHandler.endElement("style:style"); 
00067 }
00068 
00069 TableRowStyle::TableRowStyle(const WPXPropertyList &propList, const char *psName) :
00070     Style(psName),
00071         mPropList(propList)
00072 {
00073 }
00074 
00075 void TableRowStyle::write(DocumentHandler &xHandler) const
00076 {
00077     TagOpenElement styleOpen("style:style");
00078     styleOpen.addAttribute("style:name", getName());
00079     styleOpen.addAttribute("style:family", "table-row");
00080     styleOpen.write(xHandler);
00081     
00082         TagOpenElement stylePropertiesOpen("style:properties");
00083         if (mPropList["style:min-row-height"])
00084                 stylePropertiesOpen.addAttribute("style:min-row-height", mPropList["style:min-row-height"]->getStr());
00085         else if (mPropList["style:row-height"])
00086                 stylePropertiesOpen.addAttribute("style:row-height", mPropList["style:row-height"]->getStr());
00087         stylePropertiesOpen.write(xHandler);
00088         xHandler.endElement("style:properties");
00089     
00090     xHandler.endElement("style:style");     
00091 }
00092     
00093 
00094 TableStyle::TableStyle(const WPXPropertyList &xPropList, const WPXPropertyListVector &columns, const char *psName) : 
00095     Style(psName),
00096         mPropList(xPropList),
00097         mColumns(columns)
00098 {
00099 }
00100 
00101 TableStyle::~TableStyle()
00102 {
00103     typedef std::vector<TableCellStyle *>::iterator TCSVIter;
00104     for (TCSVIter iterTableCellStyles = mTableCellStyles.begin() ; iterTableCellStyles != mTableCellStyles.end(); iterTableCellStyles++)
00105         delete(*iterTableCellStyles);
00106 
00107 }
00108 
00109 void TableStyle::write(DocumentHandler &xHandler) const
00110 {
00111     TagOpenElement styleOpen("style:style");
00112     styleOpen.addAttribute("style:name", getName());
00113     styleOpen.addAttribute("style:family", "table");
00114     if (getMasterPageName())
00115         styleOpen.addAttribute("style:master-page-name", getMasterPageName()->cstr());
00116     styleOpen.write(xHandler);
00117 
00118     TagOpenElement stylePropertiesOpen("style:properties");
00119         if (mPropList["table:align"])
00120                 stylePropertiesOpen.addAttribute("table:align", mPropList["table:align"]->getStr());
00121     if (mPropList["fo:margin-left"])
00122         stylePropertiesOpen.addAttribute("fo:margin-left", mPropList["fo:margin-left"]->getStr());
00123     if (mPropList["fo:margin-right"])
00124         stylePropertiesOpen.addAttribute("fo:margin-right", mPropList["fo:margin-right"]->getStr());
00125     if (mPropList["style:width"])
00126         stylePropertiesOpen.addAttribute("style:width", mPropList["style:width"]->getStr());
00127     if (mPropList["fo:break-before"])
00128         stylePropertiesOpen.addAttribute("fo:break-before", mPropList["fo:break-before"]->getStr());
00129     stylePropertiesOpen.write(xHandler);
00130 
00131     xHandler.endElement("style:properties");
00132 
00133     xHandler.endElement("style:style");
00134         
00135     int i=1;
00136         WPXPropertyListVector::Iter j(mColumns);
00137     for (j.rewind(); j.next();)
00138     {
00139         TagOpenElement styleOpen("style:style");
00140         WPXString sColumnName;
00141         sColumnName.sprintf("%s.Column%i", getName().cstr(), i);
00142         styleOpen.addAttribute("style:name", sColumnName);
00143         styleOpen.addAttribute("style:family", "table-column");
00144         styleOpen.write(xHandler);
00145 
00146                 xHandler.startElement("style:properties", j());
00147         xHandler.endElement("style:properties");
00148 
00149         xHandler.endElement("style:style");
00150 
00151         i++;
00152     }
00153 
00154     typedef std::vector<TableRowStyle *>::const_iterator TRSVIter;
00155     for (TRSVIter iterTableRow = mTableRowStyles.begin() ; iterTableRow != mTableRowStyles.end(); iterTableRow++)
00156         (*iterTableRow)->write(xHandler);
00157 
00158     typedef std::vector<TableCellStyle *>::const_iterator TCSVIter;
00159     for (TCSVIter iterTableCell = mTableCellStyles.begin() ; iterTableCell != mTableCellStyles.end(); iterTableCell++)
00160         (*iterTableCell)->write(xHandler);
00161 }
KDE Home | KDE Accessibility Home | Description of Access Keys