lists rendering fixes (second part of patch 911377)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@26289 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -95,7 +95,7 @@ wxMSW:
|
|||||||
|
|
||||||
wxHTML:
|
wxHTML:
|
||||||
|
|
||||||
- improved tables layout algorithm (Tim Kosse)
|
- improved tables and lists layout algorithms (Tim Kosse)
|
||||||
- <div> handling fix (Xavier Nodet)
|
- <div> handling fix (Xavier Nodet)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -159,7 +159,7 @@ test.app/Contents/PkgInfo: test$(EXEEXT) $(top_srcdir)/src/mac/Info.plist.in $(L
|
|||||||
|
|
||||||
data:
|
data:
|
||||||
@mkdir -p .
|
@mkdir -p .
|
||||||
@for f in f.html fft.html imagemap.htm imagemap.png pic.png pic2.bmp tables.htm test.htm i18n.gif 8859_2.htm cp1250.htm regres.htm; do \
|
@for f in f.html fft.html imagemap.htm imagemap.png pic.png pic2.bmp tables.htm test.htm listtest.htm i18n.gif 8859_2.htm cp1250.htm regres.htm; do \
|
||||||
if test \( ! -s ./$$f \) -o \( $(srcdir)/$$f -nt ./$$f \) ; then \
|
if test \( ! -s ./$$f \) -o \( $(srcdir)/$$f -nt ./$$f \) ; then \
|
||||||
cp -pRf $(srcdir)/$$f . ; \
|
cp -pRf $(srcdir)/$$f . ; \
|
||||||
fi; \
|
fi; \
|
||||||
|
28
samples/html/test/listtest.htm
Normal file
28
samples/html/test/listtest.htm
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<ul>
|
||||||
|
<li>This is line one, try to make page width very small</li>
|
||||||
|
<li>Same with line 2</li>
|
||||||
|
</ul>
|
||||||
|
------
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<ul><li>Simple list in a table. This table cell may wrap.</li></ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
Second column, unimportant
|
||||||
|
</td>
|
||||||
|
<tr>
|
||||||
|
<tr>
|
||||||
|
<td nowrap>
|
||||||
|
<ul><li>List in a table, this cell should not wrap</li></ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
Second column, unimportant
|
||||||
|
</td>
|
||||||
|
<tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
@@ -179,7 +179,7 @@ $(OBJS)\test.exe: $(TEST_OBJECTS) $(OBJS)\test_test.res
|
|||||||
|
|
||||||
data:
|
data:
|
||||||
if not exist $(OBJS) mkdir $(OBJS)
|
if not exist $(OBJS) mkdir $(OBJS)
|
||||||
for %f in (f.html fft.html imagemap.htm imagemap.png pic.png pic2.bmp tables.htm test.htm i18n.gif 8859_2.htm cp1250.htm regres.htm) do if not exist $(OBJS)\%f copy .\%f $(OBJS)
|
for %f in (f.html fft.html imagemap.htm imagemap.png pic.png pic2.bmp tables.htm test.htm listtest.htm i18n.gif 8859_2.htm cp1250.htm regres.htm) do if not exist $(OBJS)\%f copy .\%f $(OBJS)
|
||||||
|
|
||||||
$(OBJS)\test_test.obj: .\test.cpp
|
$(OBJS)\test_test.obj: .\test.cpp
|
||||||
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) $**
|
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) $**
|
||||||
|
@@ -176,7 +176,7 @@ $(OBJS)\test.exe: $(TEST_OBJECTS) $(OBJS)\test_test_rc.o
|
|||||||
|
|
||||||
data:
|
data:
|
||||||
if not exist $(OBJS) mkdir $(OBJS)
|
if not exist $(OBJS) mkdir $(OBJS)
|
||||||
for %%f in (f.html fft.html imagemap.htm imagemap.png pic.png pic2.bmp tables.htm test.htm i18n.gif 8859_2.htm cp1250.htm regres.htm) do if not exist $(OBJS)\%%f copy .\%%f $(OBJS)
|
for %%f in (f.html fft.html imagemap.htm imagemap.png pic.png pic2.bmp tables.htm test.htm listtest.htm i18n.gif 8859_2.htm cp1250.htm regres.htm) do if not exist $(OBJS)\%%f copy .\%%f $(OBJS)
|
||||||
|
|
||||||
$(OBJS)\test_test.o: ./test.cpp
|
$(OBJS)\test_test.o: ./test.cpp
|
||||||
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $<
|
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $<
|
||||||
|
@@ -262,7 +262,7 @@ $(OBJS)\test.exe: $(TEST_OBJECTS) $(OBJS)\test_test.res
|
|||||||
|
|
||||||
data:
|
data:
|
||||||
if not exist $(OBJS) mkdir $(OBJS)
|
if not exist $(OBJS) mkdir $(OBJS)
|
||||||
for %f in (f.html fft.html imagemap.htm imagemap.png pic.png pic2.bmp tables.htm test.htm i18n.gif 8859_2.htm cp1250.htm regres.htm) do if not exist $(OBJS)\%f copy .\%f $(OBJS)
|
for %f in (f.html fft.html imagemap.htm imagemap.png pic.png pic2.bmp tables.htm test.htm listtest.htm i18n.gif 8859_2.htm cp1250.htm regres.htm) do if not exist $(OBJS)\%f copy .\%f $(OBJS)
|
||||||
|
|
||||||
$(OBJS)\test_test.obj: .\test.cpp
|
$(OBJS)\test_test.obj: .\test.cpp
|
||||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) $**
|
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) $**
|
||||||
|
@@ -216,7 +216,7 @@ $(OBJS)\test.exe : $(TEST_OBJECTS) $(OBJS)\test_test.res
|
|||||||
|
|
||||||
data : .SYMBOLIC
|
data : .SYMBOLIC
|
||||||
if not exist $(OBJS) mkdir $(OBJS)
|
if not exist $(OBJS) mkdir $(OBJS)
|
||||||
for %f in (f.html fft.html imagemap.htm imagemap.png pic.png pic2.bmp tables.htm test.htm i18n.gif 8859_2.htm cp1250.htm regres.htm) do if not exist $(OBJS)\%f copy .\%f $(OBJS)
|
for %f in (f.html fft.html imagemap.htm imagemap.png pic.png pic2.bmp tables.htm test.htm listtest.htm i18n.gif 8859_2.htm cp1250.htm regres.htm) do if not exist $(OBJS)\%f copy .\%f $(OBJS)
|
||||||
|
|
||||||
$(OBJS)\test_test.obj : .AUTODEPEND .\test.cpp
|
$(OBJS)\test_test.obj : .AUTODEPEND .\test.cpp
|
||||||
$(CXX) -zq -fo=$^@ $(TEST_CXXFLAGS) $<
|
$(CXX) -zq -fo=$^@ $(TEST_CXXFLAGS) $<
|
||||||
|
@@ -17,7 +17,8 @@
|
|||||||
<wx-data id="data">
|
<wx-data id="data">
|
||||||
<files>
|
<files>
|
||||||
f.html fft.html imagemap.htm imagemap.png pic.png pic2.bmp
|
f.html fft.html imagemap.htm imagemap.png pic.png pic2.bmp
|
||||||
tables.htm test.htm i18n.gif 8859_2.htm cp1250.htm regres.htm
|
tables.htm test.htm listtest.htm i18n.gif 8859_2.htm cp1250.htm
|
||||||
|
regres.htm
|
||||||
</files>
|
</files>
|
||||||
</wx-data>
|
</wx-data>
|
||||||
|
|
||||||
|
@@ -7,9 +7,11 @@
|
|||||||
<BODY TEXT="#000000" BGCOLOR="#B3B6E0" LINK="#0000FF" VLINK="#FF0000" ALINK="#000088">
|
<BODY TEXT="#000000" BGCOLOR="#B3B6E0" LINK="#0000FF" VLINK="#FF0000" ALINK="#000088">
|
||||||
|
|
||||||
<font size=+2>
|
<font size=+2>
|
||||||
<b><a href="tables.htm">click here to go to tables test page!</a></b>
|
<b><a href="tables.htm">click here to go to tables test page</a></b>
|
||||||
<p>
|
<p>
|
||||||
<b><a href="imagemap.htm">click here to go to IMAGEMAPs test page!</a></b>
|
<b><a href="tables.htm">click here to go to lists test page</a></b>
|
||||||
|
<p>
|
||||||
|
<b><a href="imagemap.htm">click here to go to IMAGEMAPs test page</a></b>
|
||||||
<p>
|
<p>
|
||||||
<b><a href="8859_2.htm">i18n demo 1 (iso8859-2)</a></b>
|
<b><a href="8859_2.htm">i18n demo 1 (iso8859-2)</a></b>
|
||||||
<p>
|
<p>
|
||||||
|
@@ -67,8 +67,128 @@ void wxHtmlListmarkCell::Draw(wxDC& dc, int x, int y,
|
|||||||
(m_Width / 3), (m_Width / 3));
|
(m_Width / 3), (m_Width / 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// wxHtmlListCell
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
struct wxHtmlListItemStruct
|
||||||
|
{
|
||||||
|
wxHtmlContainerCell *mark;
|
||||||
|
wxHtmlContainerCell *cont;
|
||||||
|
int minWidth;
|
||||||
|
int maxWidth;
|
||||||
|
};
|
||||||
|
|
||||||
|
class wxHtmlListCell : public wxHtmlContainerCell
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
wxBrush m_Brush;
|
||||||
|
|
||||||
|
int m_NumRows;
|
||||||
|
wxHtmlListItemStruct *m_RowInfo;
|
||||||
|
void ReallocRows(int rows);
|
||||||
|
void ComputeMinMaxWidths();
|
||||||
|
int m_ListmarkWidth;
|
||||||
|
|
||||||
|
public:
|
||||||
|
wxHtmlListCell(wxHtmlContainerCell *parent);
|
||||||
|
virtual ~wxHtmlListCell();
|
||||||
|
void AddRow(wxHtmlContainerCell *mark, wxHtmlContainerCell *cont);
|
||||||
|
virtual void Layout(int w);
|
||||||
|
|
||||||
|
DECLARE_NO_COPY_CLASS(wxHtmlListCell)
|
||||||
|
};
|
||||||
|
|
||||||
|
wxHtmlListCell::wxHtmlListCell(wxHtmlContainerCell *parent) : wxHtmlContainerCell(parent)
|
||||||
|
{
|
||||||
|
m_NumRows = 0;
|
||||||
|
m_RowInfo = 0;
|
||||||
|
m_ListmarkWidth = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxHtmlListCell::~wxHtmlListCell()
|
||||||
|
{
|
||||||
|
if (m_RowInfo) free(m_RowInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlListCell::Layout(int w)
|
||||||
|
{
|
||||||
|
wxHtmlCell::Layout(w);
|
||||||
|
|
||||||
|
ComputeMinMaxWidths();
|
||||||
|
m_Width = wxMax(m_Width, wxMin(w, GetMaxTotalWidth()));
|
||||||
|
|
||||||
|
int s_width = m_Width - m_IndentLeft;
|
||||||
|
|
||||||
|
int vpos = 0;
|
||||||
|
for (int r = 0; r < m_NumRows; r++)
|
||||||
|
{
|
||||||
|
m_RowInfo[r].mark->Layout(m_ListmarkWidth);
|
||||||
|
m_RowInfo[r].mark->SetPos(m_IndentLeft, vpos);
|
||||||
|
m_RowInfo[r].cont->Layout(s_width - m_ListmarkWidth);
|
||||||
|
m_RowInfo[r].cont->SetPos(m_IndentLeft + m_ListmarkWidth, vpos);
|
||||||
|
vpos += wxMax(m_RowInfo[r].cont->GetHeight(), m_RowInfo[r].mark->GetHeight());
|
||||||
|
}
|
||||||
|
m_Height = vpos;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlListCell::AddRow(wxHtmlContainerCell *mark, wxHtmlContainerCell *cont)
|
||||||
|
{
|
||||||
|
ReallocRows(++m_NumRows);
|
||||||
|
m_RowInfo[m_NumRows - 1].mark = mark;
|
||||||
|
m_RowInfo[m_NumRows - 1].cont = cont;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlListCell::ReallocRows(int rows)
|
||||||
|
{
|
||||||
|
m_RowInfo = (wxHtmlListItemStruct*) realloc(m_RowInfo, sizeof(wxHtmlListItemStruct) * rows);
|
||||||
|
m_RowInfo[rows - 1].mark = 0;
|
||||||
|
m_RowInfo[rows - 1].cont = 0;
|
||||||
|
m_RowInfo[rows - 1].minWidth = 0;
|
||||||
|
m_RowInfo[rows - 1].maxWidth = 0;
|
||||||
|
|
||||||
|
m_NumRows = rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlListCell::ComputeMinMaxWidths()
|
||||||
|
{
|
||||||
|
if (m_NumRows == 0) return;
|
||||||
|
|
||||||
|
m_MaxTotalWidth = 0;
|
||||||
|
m_Width = 0;
|
||||||
|
|
||||||
|
for (int r = 0; r < m_NumRows; r++)
|
||||||
|
{
|
||||||
|
wxHtmlListItemStruct& row = m_RowInfo[r];
|
||||||
|
row.mark->Layout(1);
|
||||||
|
row.cont->Layout(1);
|
||||||
|
int maxWidth = row.cont->GetMaxTotalWidth();
|
||||||
|
int width = row.cont->GetWidth();
|
||||||
|
if (row.mark->GetWidth() > m_ListmarkWidth)
|
||||||
|
m_ListmarkWidth = row.mark->GetWidth();
|
||||||
|
if (maxWidth > m_MaxTotalWidth)
|
||||||
|
m_MaxTotalWidth = maxWidth;
|
||||||
|
if (width > m_Width)
|
||||||
|
m_Width = width;
|
||||||
|
}
|
||||||
|
m_Width += m_ListmarkWidth + m_IndentLeft;
|
||||||
|
m_MaxTotalWidth += m_ListmarkWidth + m_IndentLeft;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// wxHtmlListcontentCell
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class wxHtmlListcontentCell : public wxHtmlContainerCell
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxHtmlListcontentCell(wxHtmlContainerCell *p) : wxHtmlContainerCell(p) {}
|
||||||
|
virtual void Layout(int w) {
|
||||||
|
// Reset top indentation, fixes <li><p>
|
||||||
|
SetIndent(0, wxHTML_INDENT_TOP);
|
||||||
|
wxHtmlContainerCell::Layout(w);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// The list handler:
|
// The list handler:
|
||||||
@@ -78,6 +198,7 @@ void wxHtmlListmarkCell::Draw(wxDC& dc, int x, int y,
|
|||||||
TAG_HANDLER_BEGIN(OLULLI, "OL,UL,LI")
|
TAG_HANDLER_BEGIN(OLULLI, "OL,UL,LI")
|
||||||
|
|
||||||
TAG_HANDLER_VARS
|
TAG_HANDLER_VARS
|
||||||
|
wxHtmlListCell *m_List;
|
||||||
int m_Numbering;
|
int m_Numbering;
|
||||||
// this is number of actual item of list or 0 for dots
|
// this is number of actual item of list or 0 for dots
|
||||||
|
|
||||||
@@ -91,14 +212,12 @@ TAG_HANDLER_BEGIN(OLULLI, "OL,UL,LI")
|
|||||||
wxHtmlContainerCell *c;
|
wxHtmlContainerCell *c;
|
||||||
|
|
||||||
// List Item:
|
// List Item:
|
||||||
if (tag.GetName() == wxT("LI"))
|
if (m_List && tag.GetName() == wxT("LI"))
|
||||||
{
|
{
|
||||||
m_WParser->GetContainer()->SetIndent(0, wxHTML_INDENT_TOP);
|
c = m_WParser->SetContainer(new wxHtmlContainerCell(m_List));
|
||||||
// this is to prevent indetation in <li><p> case
|
c->SetAlignVer(wxHTML_ALIGN_TOP);
|
||||||
m_WParser->CloseContainer();
|
|
||||||
m_WParser->CloseContainer();
|
|
||||||
|
|
||||||
c = m_WParser->OpenContainer();
|
wxHtmlContainerCell *mark = c;
|
||||||
c->SetWidthFloat(2 * m_WParser->GetCharWidth(), wxHTML_UNITS_PIXELS);
|
c->SetWidthFloat(2 * m_WParser->GetCharWidth(), wxHTML_UNITS_PIXELS);
|
||||||
if (m_Numbering == 0)
|
if (m_Numbering == 0)
|
||||||
{
|
{
|
||||||
@@ -116,51 +235,40 @@ TAG_HANDLER_BEGIN(OLULLI, "OL,UL,LI")
|
|||||||
m_WParser->CloseContainer();
|
m_WParser->CloseContainer();
|
||||||
|
|
||||||
c = m_WParser->OpenContainer();
|
c = m_WParser->OpenContainer();
|
||||||
c->SetIndent(m_WParser->GetCharWidth() / 4, wxHTML_INDENT_LEFT);
|
|
||||||
c->SetWidthFloat(-2 * m_WParser->GetCharWidth(), wxHTML_UNITS_PIXELS);
|
|
||||||
|
|
||||||
m_WParser->OpenContainer();
|
m_List->AddRow(mark, c);
|
||||||
|
c = m_WParser->OpenContainer();
|
||||||
|
m_WParser->SetContainer(new wxHtmlListcontentCell(c));
|
||||||
|
|
||||||
if (m_Numbering != 0) m_Numbering++;
|
if (m_Numbering != 0) m_Numbering++;
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Begin of List (not-numbered): "UL", "OL"
|
// Begin of List (not-numbered): "UL", "OL"
|
||||||
else
|
else if (tag.GetName() == wxT("UL") || tag.GetName() == wxT("OL"))
|
||||||
{
|
{
|
||||||
int oldnum = m_Numbering;
|
int oldnum = m_Numbering;
|
||||||
|
|
||||||
if (tag.GetName() == wxT("UL")) m_Numbering = 0;
|
if (tag.GetName() == wxT("UL")) m_Numbering = 0;
|
||||||
else m_Numbering = 1;
|
else m_Numbering = 1;
|
||||||
|
|
||||||
c = m_WParser->GetContainer();
|
wxHtmlContainerCell *oldcont;
|
||||||
if (c->GetFirstChild() != NULL)
|
oldcont = c = m_WParser->OpenContainer();
|
||||||
{
|
|
||||||
m_WParser->CloseContainer();
|
wxHtmlListCell *oldList = m_List;
|
||||||
m_WParser->OpenContainer();
|
m_List = new wxHtmlListCell(c);
|
||||||
c = m_WParser->GetContainer();
|
m_List->SetIndent(2 * m_WParser->GetCharWidth(), wxHTML_INDENT_LEFT);
|
||||||
}
|
|
||||||
c->SetAlignHor(wxHTML_ALIGN_LEFT);
|
|
||||||
c->SetIndent(2 * m_WParser->GetCharWidth(), wxHTML_INDENT_LEFT);
|
|
||||||
m_WParser->OpenContainer()->SetAlignVer(wxHTML_ALIGN_TOP);
|
|
||||||
|
|
||||||
m_WParser->OpenContainer();
|
|
||||||
m_WParser->OpenContainer();
|
|
||||||
ParseInner(tag);
|
ParseInner(tag);
|
||||||
|
|
||||||
m_WParser->GetContainer()->SetIndent(0, wxHTML_INDENT_TOP);
|
m_WParser->SetContainer(oldcont);
|
||||||
// this is to prevent indetation in <li><p> case
|
|
||||||
m_WParser->CloseContainer();
|
m_WParser->CloseContainer();
|
||||||
|
|
||||||
m_WParser->CloseContainer();
|
|
||||||
m_WParser->CloseContainer();
|
|
||||||
m_WParser->CloseContainer();
|
|
||||||
m_WParser->OpenContainer();
|
|
||||||
|
|
||||||
m_Numbering = oldnum;
|
m_Numbering = oldnum;
|
||||||
|
m_List = oldList;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TAG_HANDLER_END(OLULLI)
|
TAG_HANDLER_END(OLULLI)
|
||||||
|
Reference in New Issue
Block a user