From 03a821a9b98d6bfe25ecd8e231960233621b22b0 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Tue, 5 Jan 2016 20:21:40 +0200 Subject: [PATCH] Changed: Merge UL and OL code --- code/nel/include/nel/gui/group_html.h | 13 +---- code/nel/src/gui/group_html.cpp | 73 +++++++++++---------------- 2 files changed, 32 insertions(+), 54 deletions(-) diff --git a/code/nel/include/nel/gui/group_html.h b/code/nel/include/nel/gui/group_html.h index 314e07548..e7e6b8dcd 100644 --- a/code/nel/include/nel/gui/group_html.h +++ b/code/nel/include/nel/gui/group_html.h @@ -438,15 +438,6 @@ namespace NLGUI return _PRE.back(); } - // UL mode - std::vector _UL; - inline bool getUL() const - { - if (_UL.empty()) - return false; - return _UL.back(); - } - // DL list std::vector _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 _OL; + std::vector _UL; // A mode std::vector _A; diff --git a/code/nel/src/gui/group_html.cpp b/code/nel/src/gui/group_html.cpp index 1693cb08a..da5e89bc7 100644 --- a/code/nel/src/gui/group_html.cpp +++ b/code/nel/src/gui/group_html.cpp @@ -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
  • 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;