From 5c1bfc5da0e4a79803c87747371bcccb377899e0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Tue, 18 Jan 2000 09:17:46 +0000 Subject: [PATCH] added align=justify support ; also removed relic: GetMaxLineWidth git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5490 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/html/htmlcell.h | 6 ----- src/html/htmlcell.cpp | 52 ++++++++++++++++++++++++++++---------- 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/include/wx/html/htmlcell.h b/include/wx/html/htmlcell.h index b99ca14a96..fbae189ba8 100644 --- a/include/wx/html/htmlcell.h +++ b/include/wx/html/htmlcell.h @@ -195,10 +195,6 @@ class WXDLLEXPORT wxHtmlContainerCell : public wxHtmlCell // -15 pixels percent (this means 100 % - 15 pixels) void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP) {m_MinHeight = h; m_MinHeightAlign = align; m_LastLayout = -1;} // sets minimal height of this container. - int GetMaxLineWidth() const {return m_MaxLineWidth;} - // returns maximal line width in this container. - // Call to this method is valid only after calling - // Layout() void SetBackgroundColour(const wxColour& clr) {m_UseBkColour = TRUE; m_BkColour = clr;} void SetBorder(const wxColour& clr1, const wxColour& clr2) {m_UseBorder = TRUE; m_BorderColour1 = clr1, m_BorderColour2 = clr2;} virtual wxHtmlLinkInfo* GetLink(int x = 0, int y = 0) const; @@ -215,8 +211,6 @@ class WXDLLEXPORT wxHtmlContainerCell : public wxHtmlCell // it m_Indent < 0 it is in PERCENTS, otherwise it is in pixels int m_MinHeight, m_MinHeightAlign; // minimal height. - int m_MaxLineWidth; - // maximal widht of line. Filled during Layout() wxHtmlCell *m_Cells, *m_LastCell; // internal cells, m_Cells points to the first of them, m_LastCell to the last one. // (LastCell is needed only to speed-up InsertCell) diff --git a/src/html/htmlcell.cpp b/src/html/htmlcell.cpp index 81fd8b97ce..845a709c1f 100644 --- a/src/html/htmlcell.cpp +++ b/src/html/htmlcell.cpp @@ -241,7 +241,7 @@ wxHtmlContainerCell::wxHtmlContainerCell(wxHtmlContainerCell *parent) : wxHtmlCe m_WidthFloat = 100; m_WidthFloatUnits = wxHTML_UNITS_PERCENT; m_UseBkColour = FALSE; m_UseBorder = FALSE; - m_MinHeight = m_MaxLineWidth = 0; + m_MinHeight = 0; m_MinHeightAlign = wxHTML_ALIGN_TOP; m_LastLayout = -1; } @@ -318,6 +318,9 @@ void wxHtmlContainerCell::Layout(int w) int xdelta = 0, ybasicpos = 0, ydiff; int s_width, s_indent; int ysizeup = 0, ysizedown = 0; + int MaxLineWidth = 0; + int xcnt = 0; + /* @@ -350,8 +353,6 @@ void wxHtmlContainerCell::Layout(int w) s_indent = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft; s_width = m_Width - s_indent - ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); - m_MaxLineWidth = 0; - // my own layouting: while (cell != NULL) { switch (m_AlignVer) { @@ -367,28 +368,51 @@ void wxHtmlContainerCell::Layout(int w) cell -> SetPos(xpos, ybasicpos + cell -> GetDescent()); xpos += cell -> GetWidth(); cell = cell -> GetNext(); + xcnt++; // force new line if occured: if ((cell == NULL) || (xpos + cell -> GetWidth() > s_width)) { - if (xpos > m_MaxLineWidth) m_MaxLineWidth = xpos; + if (xpos > MaxLineWidth) MaxLineWidth = xpos; if (ysizeup < 0) ysizeup = 0; if (ysizedown < 0) ysizedown = 0; switch (m_AlignHor) { - case wxHTML_ALIGN_LEFT : xdelta = 0; break; - case wxHTML_ALIGN_RIGHT : xdelta = 0 + (s_width - xpos); break; - case wxHTML_ALIGN_CENTER : xdelta = 0 + (s_width - xpos) / 2; break; + case wxHTML_ALIGN_LEFT : + case wxHTML_ALIGN_JUSTIFY : + xdelta = 0; + break; + case wxHTML_ALIGN_RIGHT : + xdelta = 0 + (s_width - xpos); + break; + case wxHTML_ALIGN_CENTER : + xdelta = 0 + (s_width - xpos) / 2; + break; } if (xdelta < 0) xdelta = 0; xdelta += s_indent; ypos += ysizeup; - while (line != cell) { - line -> SetPos(line -> GetPosX() + xdelta, ypos + line -> GetPosY()); - line = line -> GetNext(); + + if (m_AlignHor != wxHTML_ALIGN_JUSTIFY || cell == NULL) + while (line != cell) { + line -> SetPos(line -> GetPosX() + xdelta, + ypos + line -> GetPosY()); + line = line -> GetNext(); + } + else + { + int counter = 0; + int step = (s_width - xpos); + if (step < 0) step = 0; + while (line != cell) { + line -> SetPos(line -> GetPosX() + s_indent + + (counter++ * step / xcnt), + ypos + line -> GetPosY()); + line = line -> GetNext(); + } } ypos += ysizedown; - xpos = 0; + xpos = xcnt = 0; ysizeup = ysizedown = 0; line = cell; } @@ -410,8 +434,8 @@ void wxHtmlContainerCell::Layout(int w) m_Height = m_MinHeight; } - m_MaxLineWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); - if (m_Width < m_MaxLineWidth) m_Width = m_MaxLineWidth; + MaxLineWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); + if (m_Width < MaxLineWidth) m_Width = MaxLineWidth; m_LastLayout = w; @@ -510,6 +534,8 @@ void wxHtmlContainerCell::SetAlign(const wxHtmlTag& tag) SetAlignHor(wxHTML_ALIGN_CENTER); else if (alg == wxT("LEFT")) SetAlignHor(wxHTML_ALIGN_LEFT); + else if (alg == wxT("JUSTIFY")) + SetAlignHor(wxHTML_ALIGN_JUSTIFY); else if (alg == wxT("RIGHT")) SetAlignHor(wxHTML_ALIGN_RIGHT); m_LastLayout = -1; -- 2.45.2