summaryrefslogtreecommitdiff
path: root/writerperfect
diff options
context:
space:
mode:
authorLaurent Alonso <laurent.alonso@inria.fr>2013-02-18 13:20:14 +0100
committerFridrich Štrba <fridrich.strba@bluewin.ch>2013-02-18 13:20:53 +0100
commitf3929090a0b12018b629d0d65b89d17d0afdc7e3 (patch)
tree46e2b835c1da5b5c5c2789e8d6f7035bbce18323 /writerperfect
parent162a4f8d01210bed52f348b74e076ff245c33309 (diff)
Writerperfect: Improve list code
Change-Id: I21fc40a0cb16e4f8295477cc2db50a58bc7287ea
Diffstat (limited to 'writerperfect')
-rw-r--r--writerperfect/source/filter/ListStyle.cxx29
-rw-r--r--writerperfect/source/filter/ListStyle.hxx15
-rw-r--r--writerperfect/source/filter/OdtGenerator.cxx54
3 files changed, 44 insertions, 54 deletions
diff --git a/writerperfect/source/filter/ListStyle.cxx b/writerperfect/source/filter/ListStyle.cxx
index e1e514485c3b..f7659089afa4 100644
--- a/writerperfect/source/filter/ListStyle.cxx
+++ b/writerperfect/source/filter/ListStyle.cxx
@@ -19,14 +19,6 @@ OrderedListLevelStyle::OrderedListLevelStyle(const WPXPropertyList &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;
@@ -75,14 +67,6 @@ UnorderedListLevelStyle::UnorderedListLevelStyle(const WPXPropertyList &xPropLis
{
}
-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;
@@ -155,6 +139,19 @@ void ListStyle::setListLevel(int iLevel, ListLevelStyle *iListLevelStyle)
mppListLevels[iLevel] = iListLevelStyle;
}
+void ListStyle::updateListLevel(const int iLevel, const WPXPropertyList &xPropList, bool ordered)
+{
+ if (iLevel < 0)
+ return;
+ if (!isListLevelDefined(iLevel))
+ {
+ if (ordered)
+ setListLevel(iLevel, new OrderedListLevelStyle(xPropList));
+ else
+ setListLevel(iLevel, new UnorderedListLevelStyle(xPropList));
+ }
+}
+
void ListStyle::write(OdfDocumentHandler *pHandler) const
{
TagOpenElement listStyleOpenElement("text:list-style");
diff --git a/writerperfect/source/filter/ListStyle.hxx b/writerperfect/source/filter/ListStyle.hxx
index 44d090d63d92..53ee67ed33b4 100644
--- a/writerperfect/source/filter/ListStyle.hxx
+++ b/writerperfect/source/filter/ListStyle.hxx
@@ -48,7 +48,7 @@ class ListStyle : public Style
public:
ListStyle(const char *psName, const int iListID);
virtual ~ListStyle();
- virtual void updateListLevel(const int iLevel, const WPXPropertyList &xPropList) = 0;
+ void updateListLevel(const int iLevel, const WPXPropertyList &xPropList, bool ordered);
virtual void write(OdfDocumentHandler *pHandler) const;
int getListID()
{
@@ -64,19 +64,6 @@ private:
const int miListID;
};
-class OrderedListStyle : public ListStyle
-{
-public:
- OrderedListStyle(const char *psName, const int iListID) : ListStyle(psName, iListID) {}
- void updateListLevel(const int iLevel, const WPXPropertyList &xPropList);
-};
-
-class UnorderedListStyle : public ListStyle
-{
-public:
- UnorderedListStyle(const char *psName, const int iListID) : ListStyle(psName, iListID) {}
- void updateListLevel(const int iLevel, const WPXPropertyList &xPropList);
-};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerperfect/source/filter/OdtGenerator.cxx b/writerperfect/source/filter/OdtGenerator.cxx
index fc4ccbb72dc1..88bcc18ca418 100644
--- a/writerperfect/source/filter/OdtGenerator.cxx
+++ b/writerperfect/source/filter/OdtGenerator.cxx
@@ -640,15 +640,15 @@ void OdtGenerator::defineOrderedListLevel(const WPXPropertyList &propList)
if (propList["libwpd:id"])
id = propList["libwpd:id"]->getInt();
- OrderedListStyle *pOrderedListStyle = 0;
+ ListStyle *pListStyle = 0;
if (mpImpl->mWriterListStates.top().mpCurrentListStyle && mpImpl->mWriterListStates.top().mpCurrentListStyle->getListID() == id)
- pOrderedListStyle = static_cast<OrderedListStyle *>(mpImpl->mWriterListStates.top().mpCurrentListStyle); // FIXME: using a dynamic cast here causes oo to crash?!
+ pListStyle = mpImpl->mWriterListStates.top().mpCurrentListStyle;
// this rather appalling conditional makes sure we only start a new list (rather than continue an old
// one) if: (1) we have no prior list OR (2) the prior list is actually definitively different
// from the list that is just being defined (listIDs differ) OR (3) we can tell that the user actually
// is starting a new list at level 1 (and only level 1)
- if (pOrderedListStyle == 0 || pOrderedListStyle->getListID() != id ||
+ if (pListStyle == 0 || pListStyle->getListID() != id ||
(propList["libwpd:level"] && propList["libwpd:level"]->getInt()==1 &&
(propList["text:start-value"] && propList["text:start-value"]->getInt() != int(mpImpl->mWriterListStates.top().miLastListNumber+1))))
{
@@ -656,9 +656,9 @@ void OdtGenerator::defineOrderedListLevel(const WPXPropertyList &propList)
WPXString sName;
sName.sprintf("OL%i", mpImpl->miNumListStyles);
mpImpl->miNumListStyles++;
- pOrderedListStyle = new OrderedListStyle(sName.cstr(), id);
- mpImpl->mListStyles.push_back(pOrderedListStyle);
- mpImpl->mWriterListStates.top().mpCurrentListStyle = pOrderedListStyle;
+ pListStyle = new ListStyle(sName.cstr(), id);
+ mpImpl->mListStyles.push_back(pListStyle);
+ mpImpl->mWriterListStates.top().mpCurrentListStyle = pListStyle;
mpImpl->mWriterListStates.top().mbListContinueNumbering = false;
mpImpl->mWriterListStates.top().miLastListNumber = 0;
}
@@ -668,10 +668,10 @@ void OdtGenerator::defineOrderedListLevel(const WPXPropertyList &propList)
// Iterate through ALL list styles with the same WordPerfect list id and define a level if it is not already defined
// This solves certain problems with lists that start and finish without reaching certain levels and then begin again
// and reach those levels. See gradguide0405_PC.wpd in the regression suite
- for (std::vector<ListStyle *>::iterator iterOrderedListStyles = mpImpl->mListStyles.begin(); iterOrderedListStyles != mpImpl->mListStyles.end(); ++iterOrderedListStyles)
+ for (std::vector<ListStyle *>::iterator iterListStyles = mpImpl->mListStyles.begin(); iterListStyles != mpImpl->mListStyles.end(); ++iterListStyles)
{
- if ((* iterOrderedListStyles) && (* iterOrderedListStyles)->getListID() == id && propList["libwpd:level"])
- (* iterOrderedListStyles)->updateListLevel((propList["libwpd:level"]->getInt() - 1), propList);
+ if ((* iterListStyles) && (* iterListStyles)->getListID() == id && propList["libwpd:level"])
+ (* iterListStyles)->updateListLevel((propList["libwpd:level"]->getInt() - 1), propList, true);
}
}
@@ -681,26 +681,26 @@ void OdtGenerator::defineUnorderedListLevel(const WPXPropertyList &propList)
if (propList["libwpd:id"])
id = propList["libwpd:id"]->getInt();
- UnorderedListStyle *pUnorderedListStyle = 0;
+ ListStyle *pListStyle = 0;
if (mpImpl->mWriterListStates.top().mpCurrentListStyle && mpImpl->mWriterListStates.top().mpCurrentListStyle->getListID() == id)
- pUnorderedListStyle = static_cast<UnorderedListStyle *>(mpImpl->mWriterListStates.top().mpCurrentListStyle); // FIXME: using a dynamic cast here causes oo to crash?!
+ pListStyle = mpImpl->mWriterListStates.top().mpCurrentListStyle;
- if (pUnorderedListStyle == 0)
+ if (pListStyle == 0)
{
WRITER_DEBUG_MSG(("Attempting to create a new unordered list style (listid: %i)\n", id));
WPXString sName;
sName.sprintf("UL%i", mpImpl->miNumListStyles);
mpImpl->miNumListStyles++;
- pUnorderedListStyle = new UnorderedListStyle(sName.cstr(), id);
- mpImpl->mListStyles.push_back(pUnorderedListStyle);
- mpImpl->mWriterListStates.top().mpCurrentListStyle = pUnorderedListStyle;
+ pListStyle = new ListStyle(sName.cstr(), id);
+ mpImpl->mListStyles.push_back(pListStyle);
+ mpImpl->mWriterListStates.top().mpCurrentListStyle = pListStyle;
}
// See comment in OdtGenerator::defineOrderedListLevel
- for (std::vector<ListStyle *>::iterator iterUnorderedListStyles = mpImpl->mListStyles.begin(); iterUnorderedListStyles != mpImpl->mListStyles.end(); ++iterUnorderedListStyles)
+ for (std::vector<ListStyle *>::iterator iterListStyles = mpImpl->mListStyles.begin(); iterListStyles != mpImpl->mListStyles.end(); ++iterListStyles)
{
- if ((* iterUnorderedListStyles) && (* iterUnorderedListStyles)->getListID() == id && propList["libwpd:level"])
- (* iterUnorderedListStyles)->updateListLevel((propList["libwpd:level"]->getInt() - 1), propList);
+ if ((* iterListStyles) && (* iterListStyles)->getListID() == id && propList["libwpd:level"])
+ (* iterListStyles)->updateListLevel((propList["libwpd:level"]->getInt() - 1), propList, false);
}
}
@@ -747,7 +747,11 @@ void OdtGeneratorPrivate::_openListLevel(TagOpenElement *pListLevelOpenElement)
mWriterListStates.top().mbListElementOpened.push(false);
if (mWriterListStates.top().mbListElementOpened.size() == 1)
{
- pListLevelOpenElement->addAttribute("text:style-name", mWriterListStates.top().mpCurrentListStyle->getName());
+ // add a sanity check ( to avoid a crash if mpCurrentListStyle is NULL)
+ if (mWriterListStates.top().mpCurrentListStyle)
+ {
+ pListLevelOpenElement->addAttribute("text:style-name", mWriterListStates.top().mpCurrentListStyle->getName());
+ }
}
}
@@ -763,6 +767,12 @@ void OdtGenerator::closeUnorderedListLevel()
void OdtGeneratorPrivate::_closeListLevel()
{
+ if (mWriterListStates.top().mbListElementOpened.empty())
+ {
+ // this implies that openListLevel was not called, so it is better to stop here
+ WRITER_DEBUG_MSG(("attempting to close an unexisting level\n"));
+ return;
+ }
if (mWriterListStates.top().mbListElementOpened.top())
{
mpCurrentContentElements->push_back(new TagCloseElement("text:list-item"));
@@ -770,11 +780,7 @@ void OdtGeneratorPrivate::_closeListLevel()
}
mpCurrentContentElements->push_back(new TagCloseElement("text:list"));
-
- if (!mWriterListStates.top().mbListElementOpened.empty())
- {
- mWriterListStates.top().mbListElementOpened.pop();
- }
+ mWriterListStates.top().mbListElementOpened.pop();
}
void OdtGenerator::openListElement(const WPXPropertyList &propList, const WPXPropertyListVector &tabStops)