1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ListStyle: Stores (and writes) list-based information that is
 * needed at the head of an OO document.
 *
 * Copyright (C) 2002-2003 William Lachance (wrlach@gmail.com)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 *
 * For further information visit http://libwpd.sourceforge.net
 *
 */

/* "This product is not manufactured, approved, or supported by
 * Corel Corporation or Corel Corporation Limited."
 */
#include "FilterInternal.hxx"
#include "ListStyle.hxx"
#include "DocumentElement.hxx"

OrderedListLevelStyle::OrderedListLevelStyle(const WPXPropertyList &xPropList) :
    mPropList(xPropList)
{
}

void OrderedListStyle::updateListLevel(const int iLevel, const WPXPropertyList &xPropList)
{
    if (iLevel < 0)
        return;
    if (!isListLevelDefined(iLevel))
        setListLevel(iLevel, new OrderedListLevelStyle(xPropList));
}

void OrderedListLevelStyle::write(OdfDocumentHandler *pHandler, int iLevel) const
{
    WPXString sLevel;
    sLevel.sprintf("%i", (iLevel+1));

    TagOpenElement listLevelStyleOpen("text:list-level-style-number");
    listLevelStyleOpen.addAttribute("text:level", sLevel);
    listLevelStyleOpen.addAttribute("text:style-name", "Numbering_Symbols");
    if (mPropList["style:num-prefix"])
    {
        WPXString sEscapedString(mPropList["style:num-prefix"]->getStr(), true);
        listLevelStyleOpen.addAttribute("style:num-prefix", sEscapedString);
    }
    if (mPropList["style:num-suffix"])
    {
        WPXString sEscapedString(mPropList["style:num-suffix"]->getStr(), true);
        listLevelStyleOpen.addAttribute("style:num-suffix", sEscapedString);
    }
    if (mPropList["style:num-format"])
        listLevelStyleOpen.addAttribute("style:num-format", mPropList["style:num-format"]->getStr());
    if (mPropList["text:start-value"])
    {
        // odf as to the version 1.1 does require the text:start-value to be a positive integer, means > 0
        if (mPropList["text:start-value"]->getInt() > 0)
            listLevelStyleOpen.addAttribute("text:start-value", mPropList["text:start-value"]->getStr());
        else
            listLevelStyleOpen.addAttribute("text:start-value", "1");
    }
    listLevelStyleOpen.write(pHandler);

    TagOpenElement stylePropertiesOpen("style:list-level-properties");
    if (mPropList["text:space-before"] && mPropList["text:space-before"]->getDouble() > 0.0)
        stylePropertiesOpen.addAttribute("text:space-before", mPropList["text:space-before"]->getStr());
    if (mPropList["text:min-label-width"] && mPropList["text:min-label-width"]->getDouble() > 0.0)
        stylePropertiesOpen.addAttribute("text:min-label-width", mPropList["text:min-label-width"]->getStr());
    if (mPropList["text:min-label-distance"] && mPropList["text:min-label-distance"]->getDouble() > 0.0)
        stylePropertiesOpen.addAttribute("text:min-label-distance", mPropList["text:min-label-distance"]->getStr());
    stylePropertiesOpen.write(pHandler);

    pHandler->endElement("style:list-level-properties");
    pHandler->endElement("text:list-level-style-number");
}

UnorderedListLevelStyle::UnorderedListLevelStyle(const WPXPropertyList &xPropList)
    : mPropList(xPropList)
{
}

void UnorderedListStyle::updateListLevel(const int iLevel, const WPXPropertyList &xPropList)
{
    if (iLevel < 0)
        return;
    if (!isListLevelDefined(iLevel))
        setListLevel(iLevel, new UnorderedListLevelStyle(xPropList));
}

void UnorderedListLevelStyle::write(OdfDocumentHandler *pHandler, int iLevel) const
{
    WPXString sLevel;
    sLevel.sprintf("%i", (iLevel+1));
    TagOpenElement listLevelStyleOpen("text:list-level-style-bullet");
    listLevelStyleOpen.addAttribute("text:level", sLevel);
    listLevelStyleOpen.addAttribute("text:style-name", "Bullet_Symbols");
    if (mPropList["text:bullet-char"] && (mPropList["text:bullet-char"]->getStr().len()))
    {
        // The following is needed because the odf format does not accept bullet chars longer than one character
        WPXString::Iter i(mPropList["text:bullet-char"]->getStr());
        i.rewind();
        WPXString sEscapedString(".");
        if (i.next())
            sEscapedString = WPXString(i(), true);
        listLevelStyleOpen.addAttribute("text:bullet-char", sEscapedString);

    }
    else
        listLevelStyleOpen.addAttribute("text:bullet-char", ".");
    listLevelStyleOpen.write(pHandler);

    TagOpenElement stylePropertiesOpen("style:list-level-properties");
    if (mPropList["text:space-before"] && mPropList["text:space-before"]->getDouble() > 0.0)
        stylePropertiesOpen.addAttribute("text:space-before", mPropList["text:space-before"]->getStr());
    if (mPropList["text:min-label-width"] && mPropList["text:min-label-width"]->getDouble() > 0.0)
        stylePropertiesOpen.addAttribute("text:min-label-width", mPropList["text:min-label-width"]->getStr());
    if (mPropList["text:min-label-distance"] && mPropList["text:min-label-distance"]->getDouble() > 0.0)
        stylePropertiesOpen.addAttribute("text:min-label-distance", mPropList["text:min-label-distance"]->getStr());
    stylePropertiesOpen.addAttribute("style:font-name", "OpenSymbol");
    stylePropertiesOpen.write(pHandler);

    pHandler->endElement("style:list-level-properties");
    pHandler->endElement("text:list-level-style-bullet");
}

ListStyle::ListStyle(const char *psName, const int iListID) :<--- Member variable 'ListStyle::miNumListLevels' is not initialized in the constructor.
    Style(psName),
    miListID(iListID)
{
    for (int i=0; i<WP6_NUM_LIST_LEVELS; ++i)
        mppListLevels[i] = 0;

}

ListStyle::~ListStyle()
{
    for (int i=0; i<WP6_NUM_LIST_LEVELS; ++i)
    {
        if (mppListLevels[i])
            delete(mppListLevels[i]);
    }

}

bool ListStyle::isListLevelDefined(int iLevel) const
{
    if (!mppListLevels[iLevel])
        return false;

    return true;
}

void ListStyle::setListLevel(int iLevel, ListLevelStyle *iListLevelStyle)
{
    // can't uncomment this next line without adding some extra logic.
    // figure out which is best: use the initial message, or constantly
    // update?
    if (!mppListLevels[iLevel])
        mppListLevels[iLevel] = iListLevelStyle;
}

void ListStyle::write(OdfDocumentHandler *pHandler) const
{
    TagOpenElement listStyleOpenElement("text:list-style");
    listStyleOpenElement.addAttribute("style:name", getName());
    listStyleOpenElement.write(pHandler);

    for (int i=0; i<WP6_NUM_LIST_LEVELS; ++i)
    {
        if (mppListLevels[i])
            mppListLevels[i]->write(pHandler, i);
    }

    pHandler->endElement("text:list-style");
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */