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 <math.h>
00031 #include "FilterInternal.hxx"
00032 #include "TableStyle.hxx"
00033 #include "DocumentElement.hxx"
00034 
00035 #ifdef _MSC_VER
00036 #include <minmax.h>
00037 #endif
00038 
00039 TableCellStyle::TableCellStyle(const WPXPropertyList &xPropList, const char *psName) :
00040     Style(psName),
00041         mPropList(xPropList)
00042 {
00043 }
00044 
00045 void TableCellStyle::write(DocumentHandler &xHandler) const
00046 {
00047     TagOpenElement styleOpen("style:style");
00048     styleOpen.addAttribute("style:name", getName());
00049     styleOpen.addAttribute("style:family", "table-cell");
00050     styleOpen.write(xHandler);
00051 
00052         // WLACH_REFACTORING: Only temporary.. a much better solution is to
00053         // generalize this sort of thing into the "Style" superclass
00054         WPXPropertyList stylePropList;
00055         WPXPropertyList::Iter i(mPropList);
00056         for (i.rewind(); i.next();)
00057         {
00058                 if (strlen(i.key()) > 2 && strncmp(i.key(), "fo", 2) == 0)
00059                         stylePropList.insert(i.key(), i()->clone());
00060         }
00061         stylePropList.insert("fo:padding", "0.0382inch");
00062         xHandler.startElement("style:properties", stylePropList);
00063     xHandler.endElement("style:properties");
00064 
00065     xHandler.endElement("style:style"); 
00066 }
00067 
00068 TableRowStyle::TableRowStyle(const WPXPropertyList &propList, const char *psName) :
00069     Style(psName),
00070         mPropList(propList)
00071 {
00072 }
00073 
00074 void TableRowStyle::write(DocumentHandler &xHandler) const
00075 {
00076     TagOpenElement styleOpen("style:style");
00077     styleOpen.addAttribute("style:name", getName());
00078     styleOpen.addAttribute("style:family", "table-row");
00079     styleOpen.write(xHandler);
00080     
00081         TagOpenElement stylePropertiesOpen("style:properties");
00082         if (mPropList["style:min-row-height"])
00083                 stylePropertiesOpen.addAttribute("style:min-row-height", mPropList["style:min-row-height"]->getStr());
00084         else if (mPropList["style:row-height"])
00085                 stylePropertiesOpen.addAttribute("style:row-height", mPropList["style:row-height"]->getStr());
00086         stylePropertiesOpen.write(xHandler);
00087         xHandler.endElement("style:properties");
00088     
00089     xHandler.endElement("style:style");     
00090 }
00091     
00092 
00093 TableStyle::TableStyle(const WPXPropertyList &xPropList, const WPXPropertyListVector &columns, const char *psName) : 
00094     Style(psName),
00095         mPropList(xPropList),
00096         mColumns(columns)
00097 {
00098 }
00099 
00100 TableStyle::~TableStyle()
00101 {
00102     typedef std::vector<TableCellStyle *>::iterator TCSVIter;
00103     for (TCSVIter iterTableCellStyles = mTableCellStyles.begin() ; iterTableCellStyles != mTableCellStyles.end(); iterTableCellStyles++)
00104         delete(*iterTableCellStyles);
00105 
00106 }
00107 
00108 void TableStyle::write(DocumentHandler &xHandler) const
00109 {
00110     TagOpenElement styleOpen("style:style");
00111     styleOpen.addAttribute("style:name", getName());
00112     styleOpen.addAttribute("style:family", "table");
00113     if (getMasterPageName())
00114         styleOpen.addAttribute("style:master-page-name", getMasterPageName()->cstr());
00115     styleOpen.write(xHandler);
00116 
00117     TagOpenElement stylePropertiesOpen("style:properties");
00118         if (mPropList["table:align"])
00119                 stylePropertiesOpen.addAttribute("table:align", mPropList["table:align"]->getStr());
00120     if (mPropList["fo:margin-left"])
00121         stylePropertiesOpen.addAttribute("fo:margin-left", mPropList["fo:margin-left"]->getStr());
00122     if (mPropList["fo:margin-right"])
00123         stylePropertiesOpen.addAttribute("fo:margin-right", mPropList["fo:margin-right"]->getStr());
00124     if (mPropList["style:width"])
00125         stylePropertiesOpen.addAttribute("style:width", mPropList["style:width"]->getStr());
00126     if (mPropList["fo:break-before"])
00127         stylePropertiesOpen.addAttribute("fo:break-before", mPropList["fo:break-before"]->getStr());
00128     stylePropertiesOpen.write(xHandler);
00129 
00130     xHandler.endElement("style:properties");
00131 
00132     xHandler.endElement("style:style");
00133         
00134     int i=1;
00135         WPXPropertyListVector::Iter j(mColumns);
00136     for (j.rewind(); j.next();)
00137     {
00138         TagOpenElement styleOpen("style:style");
00139         WPXString sColumnName;
00140         sColumnName.sprintf("%s.Column%i", getName().cstr(), i);
00141         styleOpen.addAttribute("style:name", sColumnName);
00142         styleOpen.addAttribute("style:family", "table-column");
00143         styleOpen.write(xHandler);
00144 
00145                 xHandler.startElement("style:properties", j());
00146         xHandler.endElement("style:properties");
00147 
00148         xHandler.endElement("style:style");
00149 
00150         i++;
00151     }
00152 
00153     typedef std::vector<TableRowStyle *>::const_iterator TRSVIter;
00154     for (TRSVIter iterTableRow = mTableRowStyles.begin() ; iterTableRow != mTableRowStyles.end(); iterTableRow++)
00155         (*iterTableRow)->write(xHandler);
00156 
00157     typedef std::vector<TableCellStyle *>::const_iterator TCSVIter;
00158     for (TCSVIter iterTableCell = mTableCellStyles.begin() ; iterTableCell != mTableCellStyles.end(); iterTableCell++)
00159         (*iterTableCell)->write(xHandler);
00160 }
KDE Home | KDE Accessibility Home | Description of Access Keys