filters

ListStyle.cxx

00001 /* ListStyle: Stores (and writes) list-based information that is 
00002  * needed at the head of an OO document.
00003  *
00004  * Copyright (C) 2002-2003 William Lachance (william.lachance@sympatico.ca)
00005  * 
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  *
00021  * For further information visit http://libwpd.sourceforge.net
00022  *
00023  */
00024 
00025 /* "This product is not manufactured, approved, or supported by 
00026  * Corel Corporation or Corel Corporation Limited."
00027  */
00028 #include "FilterInternal.hxx"
00029 #include "ListStyle.hxx"
00030 #include "DocumentElement.hxx"
00031 
00032 OrderedListLevelStyle::OrderedListLevelStyle(const WPXPropertyList &xPropList) : 
00033         mPropList(xPropList)
00034 {
00035 }
00036 
00037 void OrderedListStyle::updateListLevel(const int iLevel, const WPXPropertyList &xPropList) 
00038 { 
00039     if (iLevel < 0)
00040         return;
00041     if (!isListLevelDefined(iLevel))
00042         setListLevel(iLevel, new OrderedListLevelStyle(xPropList));
00043 }
00044 
00045 void OrderedListLevelStyle::write(DocumentHandler &xHandler, int iLevel) const
00046 {
00047     WPXString sLevel;
00048     sLevel.sprintf("%i", (iLevel+1));
00049 
00050     TagOpenElement listLevelStyleOpen("text:list-level-style-number");
00051     listLevelStyleOpen.addAttribute("text:level", sLevel);
00052     listLevelStyleOpen.addAttribute("text:style-name", "Numbering Symbols");
00053         if (mPropList["style:num-prefix"])
00054                 listLevelStyleOpen.addAttribute("style:num-prefix", mPropList["style:num-prefix"]->getStr());
00055         if (mPropList["style:num-suffix"])
00056                 listLevelStyleOpen.addAttribute("style:num-suffix", mPropList["style:num-suffix"]->getStr());
00057         if (mPropList["style:num-format"])
00058                 listLevelStyleOpen.addAttribute("style:num-format", mPropList["style:num-format"]->getStr());
00059         if (mPropList["text:start-value"])
00060                 listLevelStyleOpen.addAttribute("text:start-value", mPropList["text:start-value"]->getStr());
00061     listLevelStyleOpen.write(xHandler);
00062 
00063     TagOpenElement stylePropertiesOpen("style:properties");
00064         if (mPropList["text:space-before"])
00065                 stylePropertiesOpen.addAttribute("text:space-before", mPropList["text:space-before"]->getStr());
00066     if (mPropList["text:min-label-width"])
00067         stylePropertiesOpen.addAttribute("text:min-label-width", mPropList["text:min-label-width"]->getStr());
00068     if (mPropList["text:min-label-distance"])
00069         stylePropertiesOpen.addAttribute("text:min-label-distance", mPropList["text:min-label-distance"]->getStr());
00070     stylePropertiesOpen.write(xHandler);
00071 
00072     xHandler.endElement("style:properties");
00073     xHandler.endElement("text:list-level-style-number");
00074 }
00075 
00076 UnorderedListLevelStyle::UnorderedListLevelStyle(const WPXPropertyList &xPropList)
00077     : mPropList(xPropList)
00078 {
00079 }
00080 
00081 void UnorderedListStyle::updateListLevel(const int iLevel, const WPXPropertyList &xPropList) 
00082 { 
00083     if (iLevel < 0)
00084         return;
00085     if (!isListLevelDefined(iLevel))
00086         setListLevel(iLevel, new UnorderedListLevelStyle(xPropList));
00087 }
00088 
00089 void UnorderedListLevelStyle::write(DocumentHandler &xHandler, int iLevel) const
00090 {
00091     WPXString sLevel;
00092     sLevel.sprintf("%i", (iLevel+1));
00093     TagOpenElement listLevelStyleOpen("text:list-level-style-bullet");
00094     listLevelStyleOpen.addAttribute("text:level", sLevel);
00095     listLevelStyleOpen.addAttribute("text:style-name", "Bullet Symbols");
00096     listLevelStyleOpen.addAttribute("style:num-suffice", ".");
00097         if (mPropList["text:bullet-char"])
00098                 listLevelStyleOpen.addAttribute("text:bullet-char", mPropList["text:bullet-char"]->getStr());
00099     listLevelStyleOpen.write(xHandler);
00100 
00101     TagOpenElement stylePropertiesOpen("style:properties");
00102         if (mPropList["text:space-before"])
00103                 stylePropertiesOpen.addAttribute("text:space-before", mPropList["text:space-before"]->getStr());
00104     if (mPropList["text:min-label-width"])
00105         stylePropertiesOpen.addAttribute("text:min-label-width", mPropList["text:min-label-width"]->getStr());
00106     if (mPropList["text:min-label-distance"])
00107         stylePropertiesOpen.addAttribute("text:min-label-distance", mPropList["text:min-label-distance"]->getStr());
00108     stylePropertiesOpen.addAttribute("style:font-name", "OpenSymbol");
00109     stylePropertiesOpen.write(xHandler);
00110 
00111     xHandler.endElement("style:properties");
00112     xHandler.endElement("text:list-level-style-bullet");
00113 }
00114 
00115 ListStyle::ListStyle(const char *psName, const int iListID) :
00116     Style(psName),
00117     miListID(iListID)
00118 {
00119     for (int i=0; i<WP6_NUM_LIST_LEVELS; i++)
00120         mppListLevels[i] = NULL;
00121     
00122 }
00123 
00124 ListStyle::~ListStyle()
00125 {
00126     for (int i=0; i<WP6_NUM_LIST_LEVELS; i++) {
00127         if (mppListLevels[i])
00128             delete(mppListLevels[i]);
00129     }
00130 
00131 }
00132 
00133 const bool ListStyle::isListLevelDefined(int iLevel) const
00134 {
00135     if (mppListLevels[iLevel] == NULL) 
00136         return false;
00137     
00138     return true;
00139 }
00140 
00141 void ListStyle::setListLevel(int iLevel, ListLevelStyle *iListLevelStyle)
00142 {
00143     // can't uncomment this next line without adding some extra logic. 
00144     // figure out which is best: use the initial message, or constantly
00145     // update?
00146     if (mppListLevels[iLevel] == NULL) 
00147         mppListLevels[iLevel] = iListLevelStyle;
00148 }
00149 
00150 void ListStyle::write(DocumentHandler &xHandler) const
00151 {
00152     TagOpenElement listStyleOpenElement("text:list-style");
00153     listStyleOpenElement.addAttribute("style:name", getName());
00154     listStyleOpenElement.write(xHandler);
00155 
00156     for (int i=0; i<WP6_NUM_LIST_LEVELS; i++) {
00157         if (mppListLevels[i] != NULL) 
00158             mppListLevels[i]->write(xHandler, i);       
00159     }
00160 
00161     xHandler.endElement("text:list-style");
00162 }
KDE Home | KDE Accessibility Home | Description of Access Keys