Changed: Merge UL and OL code

This commit is contained in:
Nimetu 2016-01-05 20:21:40 +02:00
parent 10e7d8d4ff
commit 03a821a9b9
2 changed files with 32 additions and 54 deletions

View file

@ -438,15 +438,6 @@ namespace NLGUI
return _PRE.back();
}
// UL mode
std::vector<bool> _UL;
inline bool getUL() const
{
if (_UL.empty())
return false;
return _UL.back();
}
// DL list
std::vector<bool> _DL;
inline bool getDL() const
@ -456,7 +447,7 @@ namespace NLGUI
return _DL.back();
}
// OL
// OL and UL
class HTMLOListElement {
public:
HTMLOListElement(int start, std::string type)
@ -469,7 +460,7 @@ namespace NLGUI
std::string Type;
bool First;
};
std::vector<HTMLOListElement> _OL;
std::vector<HTMLOListElement> _UL;
// A mode
std::vector<bool> _A;

View file

@ -1709,9 +1709,9 @@ namespace NLGUI
_SelectOption = true;
break;
case HTML_LI:
if (getUL())
if (!_UL.empty())
{
// First LI ?
// UL, OL top margin if this is the first LI
if (!_LI)
{
_LI = true;
@ -1721,35 +1721,18 @@ namespace NLGUI
{
newParagraph(LIBeginSpace);
}
ucstring str;
str += (ucchar)0x2219;
str += (ucchar)' ';
addString (str);
flushString ();
getParagraph()->setFirstViewIndent(LIIndent);
}
else if (!_OL.empty())
{
if (_OL.back().First)
{
_OL.back().First = false;
newParagraph(ULBeginSpace);
}
else
{
newParagraph(LIBeginSpace);
}
// OL list index can be overridden by <li value="1"> attribute
if (present[HTML_LI_VALUE] && value[HTML_LI_VALUE])
fromString(value[HTML_LI_VALUE], _OL.back().Value);
fromString(value[HTML_LI_VALUE], _UL.back().Value);
ucstring str;
str.fromUtf8(_OL.back().getListMarkerText() + ". ");
addString(str);
flushString();
str.fromUtf8(_UL.back().getListMarkerText());
addString (str);
flushString ();
getParagraph()->setFirstViewIndent(LIIndent);
_OL.back().Value++;
_UL.back().Value++;
}
break;
case HTML_P:
@ -1934,10 +1917,11 @@ namespace NLGUI
}
break;
case HTML_UL:
_UL.push_back(HTMLOListElement(1, "disc"));
// if LI is already present
_LI = _UL.size() > 1;
_Indent += ULIndent;
_LI = false;
endParagraph();
_UL.push_back(true);
break;
case HTML_OBJECT:
_ObjectType = "";
@ -2044,7 +2028,9 @@ namespace NLGUI
if (present[HTML_OL_TYPE] && value[HTML_OL_TYPE])
type = value[HTML_OL_TYPE];
_OL.push_back(HTMLOListElement(start, type));
_UL.push_back(HTMLOListElement(start, type));
// if LI is already present
_LI = _UL.size() > 1;
_Indent += ULIndent;
endParagraph();
}
@ -2218,21 +2204,16 @@ namespace NLGUI
}
break;
case HTML_OL:
if (!_OL.empty())
{
_Indent -= ULIndent;
_Indent = std::max(_Indent, (uint)0);
endParagraph();
popIfNotEmpty(_OL);
}
break;
case HTML_UL:
if (getUL())
if (!_UL.empty())
{
_Indent -= ULIndent;
_Indent = std::max(_Indent, (uint)0);
if (_Indent > ULIndent)
_Indent = _Indent - ULIndent;
else
_Indent = 0;
endParagraph();
popIfNotEmpty (_UL);
popIfNotEmpty(_UL);
}
break;
case HTML_DL:
@ -4050,7 +4031,6 @@ namespace NLGUI
_DT = false;
_UL.clear();
_DL.clear();
_OL.clear();
_A.clear();
_Link.clear();
_LinkTitle.clear();
@ -5527,7 +5507,12 @@ namespace NLGUI
sint32 number = Value;
bool upper = false;
if (Type == "a" || Type == "A")
if (Type == "disc")
{
// (ucchar)0x2219;
ret = "\xe2\x88\x99 ";
}
else if (Type == "a" || Type == "A")
{
// @see toAlphabeticOrNumeric in WebKit
static const char lower[26] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
@ -5549,6 +5534,7 @@ namespace NLGUI
number /= size;
}
}
ret += ". ";
}
else if (Type == "i" || Type == "I")
{
@ -5592,10 +5578,11 @@ namespace NLGUI
ret = toUpper(ret);
}
}
ret += ". ";
}
else
{
ret = toString(Value);
ret = toString(Value) + ". ";
}
return ret;