X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/77ffb5937e89927b621128789401db8921fe580f..62795f413a7222863b4aee76c08764071f94bd87:/src/html/m_list.cpp diff --git a/src/html/m_list.cpp b/src/html/m_list.cpp index f1b90e4491..12d9d90d7c 100644 --- a/src/html/m_list.cpp +++ b/src/html/m_list.cpp @@ -1,26 +1,20 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: m_list.cpp +// Name: src/html/m_list.cpp // Purpose: wxHtml module for lists // Author: Vaclav Slavik -// RCS-ID: $Id$ // Copyright: (c) 1999 Vaclav Slavik -// Licence: wxWidgets Licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) -#pragma implementation -#endif #include "wx/wxprec.h" - -#include "wx/defs.h" -#if wxUSE_HTML && wxUSE_STREAMS - #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif -#ifndef WXPRECOMP +#if wxUSE_HTML && wxUSE_STREAMS + +#ifndef WX_PRECOMP #include "wx/brush.h" #include "wx/dc.h" #endif @@ -46,14 +40,15 @@ class wxHtmlListmarkCell : public wxHtmlCell void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2, wxHtmlRenderingInfo& info); - DECLARE_NO_COPY_CLASS(wxHtmlListmarkCell) + wxDECLARE_NO_COPY_CLASS(wxHtmlListmarkCell); }; -wxHtmlListmarkCell::wxHtmlListmarkCell(wxDC* dc, const wxColour& clr) : wxHtmlCell(), m_Brush(clr, wxSOLID) +wxHtmlListmarkCell::wxHtmlListmarkCell(wxDC* dc, const wxColour& clr) : wxHtmlCell(), m_Brush(clr, wxBRUSHSTYLE_SOLID) { m_Width = dc->GetCharHeight(); m_Height = dc->GetCharHeight(); - m_Descent = 0; + // bottom of list mark is lined with bottom of letters in next cell + m_Descent = m_Height / 3; } @@ -63,7 +58,7 @@ void wxHtmlListmarkCell::Draw(wxDC& dc, int x, int y, wxHtmlRenderingInfo& WXUNUSED(info)) { dc.SetBrush(m_Brush); - dc.DrawEllipse(x + m_PosX + m_Width / 3, y + m_PosY + m_Height / 3, + dc.DrawEllipse(x + m_PosX + m_Width / 3, y + m_PosY + m_Height / 3, (m_Width / 3), (m_Width / 3)); } @@ -88,6 +83,7 @@ class wxHtmlListCell : public wxHtmlContainerCell wxHtmlListItemStruct *m_RowInfo; void ReallocRows(int rows); void ComputeMinMaxWidths(); + int ComputeMaxBase(wxHtmlCell *cell); int m_ListmarkWidth; public: @@ -95,8 +91,8 @@ class wxHtmlListCell : public wxHtmlContainerCell virtual ~wxHtmlListCell(); void AddRow(wxHtmlContainerCell *mark, wxHtmlContainerCell *cont); virtual void Layout(int w); - - DECLARE_NO_COPY_CLASS(wxHtmlListCell) + + wxDECLARE_NO_COPY_CLASS(wxHtmlListCell); }; wxHtmlListCell::wxHtmlListCell(wxHtmlContainerCell *parent) : wxHtmlContainerCell(parent) @@ -111,6 +107,23 @@ wxHtmlListCell::~wxHtmlListCell() if (m_RowInfo) free(m_RowInfo); } +int wxHtmlListCell::ComputeMaxBase(wxHtmlCell *cell) +{ + if(!cell) + return 0; + + wxHtmlCell *child = cell->GetFirstChild(); + + while(child) + { + int base = ComputeMaxBase( child ); + if ( base > 0 ) return base + child->GetPosY(); + child = child->GetNext(); + } + + return cell->GetHeight() - cell->GetDescent(); +} + void wxHtmlListCell::Layout(int w) { wxHtmlCell::Layout(w); @@ -123,11 +136,20 @@ void wxHtmlListCell::Layout(int w) int vpos = 0; for (int r = 0; r < m_NumRows; r++) { + // do layout first time to layout contents and adjust pos 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()); + + const int base_mark = ComputeMaxBase( m_RowInfo[r].mark ); + const int base_cont = ComputeMaxBase( m_RowInfo[r].cont ); + const int adjust_mark = vpos + wxMax(base_cont-base_mark,0); + const int adjust_cont = vpos + wxMax(base_mark-base_cont,0); + + m_RowInfo[r].mark->SetPos(m_IndentLeft, adjust_mark); + m_RowInfo[r].cont->SetPos(m_IndentLeft + m_ListmarkWidth, adjust_cont); + + vpos = wxMax(adjust_mark + m_RowInfo[r].mark->GetHeight(), + adjust_cont + m_RowInfo[r].cont->GetHeight()); } m_Height = vpos; } @@ -142,8 +164,8 @@ void wxHtmlListCell::AddRow(wxHtmlContainerCell *mark, wxHtmlContainerCell *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].mark = NULL; + m_RowInfo[rows - 1].cont = NULL; m_RowInfo[rows - 1].minWidth = 0; m_RowInfo[rows - 1].maxWidth = 0; @@ -153,7 +175,7 @@ void wxHtmlListCell::ReallocRows(int rows) void wxHtmlListCell::ComputeMinMaxWidths() { if (m_NumRows == 0) return; - + m_MaxTotalWidth = 0; m_Width = 0; @@ -183,7 +205,7 @@ class wxHtmlListcontentCell : public wxHtmlContainerCell { public: wxHtmlListcontentCell(wxHtmlContainerCell *p) : wxHtmlContainerCell(p) {} - virtual void Layout(int w) { + virtual void Layout(int w) { // Reset top indentation, fixes
  • SetIndent(0, wxHTML_INDENT_TOP); wxHtmlContainerCell::Layout(w); @@ -204,6 +226,7 @@ TAG_HANDLER_BEGIN(OLULLI, "OL,UL,LI") TAG_HANDLER_CONSTR(OLULLI) { + m_List = NULL; m_Numbering = 0; } @@ -228,9 +251,9 @@ TAG_HANDLER_BEGIN(OLULLI, "OL,UL,LI") else { c->SetAlignHor(wxHTML_ALIGN_RIGHT); - wxString mark; - mark.Printf(wxT("%i."), m_Numbering); - c->InsertCell(new wxHtmlWordCell(mark, *(m_WParser->GetDC()))); + wxString markStr; + markStr.Printf(wxT("%i. "), m_Numbering); + c->InsertCell(new wxHtmlWordCell(markStr, *(m_WParser->GetDC()))); } m_WParser->CloseContainer(); @@ -239,7 +262,7 @@ TAG_HANDLER_BEGIN(OLULLI, "OL,UL,LI") m_List->AddRow(mark, c); c = m_WParser->OpenContainer(); m_WParser->SetContainer(new wxHtmlListcontentCell(c)); - + if (m_Numbering != 0) m_Numbering++; } @@ -257,7 +280,7 @@ TAG_HANDLER_BEGIN(OLULLI, "OL,UL,LI") wxHtmlListCell *oldList = m_List; m_List = new wxHtmlListCell(c); m_List->SetIndent(2 * m_WParser->GetCharWidth(), wxHTML_INDENT_LEFT); - + ParseInner(tag); m_WParser->SetContainer(oldcont); @@ -265,7 +288,7 @@ TAG_HANDLER_BEGIN(OLULLI, "OL,UL,LI") m_Numbering = oldnum; m_List = oldList; - return TRUE; + return true; } return false;