X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5ce3910231c15c40ae9e0d31148542c40c557147..789f8e6ad40488d2dd5f5f4d87e195d0f1e23422:/src/html/m_tables.cpp diff --git a/src/html/m_tables.cpp b/src/html/m_tables.cpp index adc0620081..d1abf09252 100644 --- a/src/html/m_tables.cpp +++ b/src/html/m_tables.cpp @@ -7,7 +7,7 @@ // Licence: wxWindows Licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation #endif @@ -15,7 +15,7 @@ #include "wx/defs.h" #if wxUSE_HTML && wxUSE_STREAMS -#ifdef __BORDLANDC__ +#ifdef __BORLANDC__ #pragma hdrstop #endif @@ -125,6 +125,8 @@ private: // Computes minimal and maximal widths of columns. Needs to be called // only once, before first Layout(). void ComputeMinMaxWidths(); + + DECLARE_NO_COPY_CLASS(wxHtmlTableCell) }; @@ -351,8 +353,6 @@ void wxHtmlTableCell::ComputeMinMaxWidths() { if (m_NumCols == 0 || m_ColsInfo[0].minWidth != -1) return; - int left, right, width; - for (int c = 0; c < m_NumCols; c++) { for (int r = 0; r < m_NumRows; r++) @@ -361,11 +361,9 @@ void wxHtmlTableCell::ComputeMinMaxWidths() if (cell.flag == cellUsed) { cell.cont->Layout(2*m_Padding + 1); - cell.cont->GetHorizontalConstraints(&left, &right); - width = right - left; + int width = cell.cont->GetWidth(); width -= (cell.colspan-1) * m_Spacing; // HTML 4.0 says it is acceptable to distribute min/max - // width of spanning cells evently width /= cell.colspan; for (int j = 0; j < cell.colspan; j++) if (width > m_ColsInfo[c+j].minWidth) @@ -435,13 +433,18 @@ void wxHtmlTableCell::Layout(int w) wpix -= wtemp; // 1c. setup defalut columns (no width specification supplied): - // NOTE! This algorithm doesn't conform to HTML standard : it assigns equal widths - // instead of optimal + // FIXME: This algorithm doesn't conform to HTML standard : it assigns + // equal widths instead of optimal for (i = j = 0; i < m_NumCols; i++) if (m_ColsInfo[i].width == 0) j++; for (i = 0; i < m_NumCols; i++) if (m_ColsInfo[i].width == 0) - m_ColsInfo[i].pixwidth = wpix / j; + { + // FIXME: this is not optimal, because if we allocate more than + // wpix/j pixels to one column, we should try to allocate + // smaller place to other columns + m_ColsInfo[i].pixwidth = wxMax(wpix/j, m_ColsInfo[i].minWidth); + } } /* 2. compute positions of columns: */ @@ -507,6 +510,15 @@ void wxHtmlTableCell::Layout(int w) m_Height = ypos[m_NumRows]; delete[] ypos; } + + /* 4. adjust table's width if it was too small: */ + if (m_NumCols > 0) + { + int twidth = m_ColsInfo[m_NumCols-1].leftpos + + m_ColsInfo[m_NumCols-1].pixwidth + m_Spacing; + if (twidth > m_Width) + m_Width = twidth; + } } @@ -524,13 +536,11 @@ TAG_HANDLER_BEGIN(TABLE, "TABLE,TR,TD,TH") TAG_HANDLER_VARS wxHtmlTableCell* m_Table; wxString m_tAlign, m_rAlign; - int m_OldAlign; TAG_HANDLER_CONSTR(TABLE) { m_Table = NULL; m_tAlign = m_rAlign = wxEmptyString; - m_OldAlign = wxHTML_ALIGN_LEFT; } @@ -548,14 +558,14 @@ TAG_HANDLER_BEGIN(TABLE, "TABLE,TR,TD,TH") c->SetWidthFloat(tag, m_WParser->GetPixelScale()); m_Table = new wxHtmlTableCell(c, tag, m_WParser->GetPixelScale()); - m_OldAlign = m_WParser->GetAlign(); + int oldAlign = m_WParser->GetAlign(); m_tAlign = wxEmptyString; if (tag.HasParam(wxT("ALIGN"))) m_tAlign = tag.GetParam(wxT("ALIGN")); ParseInner(tag); - m_WParser->SetAlign(m_OldAlign); + m_WParser->SetAlign(oldAlign); m_WParser->SetContainer(oldcont); m_WParser->CloseContainer(); @@ -578,29 +588,29 @@ TAG_HANDLER_BEGIN(TABLE, "TABLE,TR,TD,TH") // new cell else { - m_WParser->SetAlign(m_OldAlign); c = m_WParser->SetContainer(new wxHtmlContainerCell(m_Table)); m_Table->AddCell(c, tag); m_WParser->OpenContainer(); if (tag.GetName() == wxT("TH")) /*header style*/ - { m_WParser->SetAlign(wxHTML_ALIGN_CENTER); - } - - { - wxString als; - - als = m_rAlign; - if (tag.HasParam(wxT("ALIGN"))) - als = tag.GetParam(wxT("ALIGN")); - als.MakeUpper(); - if (als == wxT("RIGHT")) - m_WParser->SetAlign(wxHTML_ALIGN_RIGHT); - else if (als == wxT("CENTER")) - m_WParser->SetAlign(wxHTML_ALIGN_CENTER); - } + else + m_WParser->SetAlign(wxHTML_ALIGN_LEFT); + + wxString als; + + als = m_rAlign; + if (tag.HasParam(wxT("ALIGN"))) + als = tag.GetParam(wxT("ALIGN")); + als.MakeUpper(); + if (als == wxT("RIGHT")) + m_WParser->SetAlign(wxHTML_ALIGN_RIGHT); + else if (als == wxT("LEFT")) + m_WParser->SetAlign(wxHTML_ALIGN_LEFT); + else if (als == wxT("CENTER")) + m_WParser->SetAlign(wxHTML_ALIGN_CENTER); + m_WParser->OpenContainer(); } }