From fd0bab435360c3c0e889dc242458d32760f4630f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 28 May 2006 22:56:28 +0000 Subject: [PATCH] use dynamic array for the page breaks positions (patch 1483976) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39396 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 2 ++ include/wx/html/htmlcell.h | 6 ++--- include/wx/html/htmprint.h | 8 +++--- src/html/htmlcell.cpp | 35 ++++++++++++-------------- src/html/htmprint.cpp | 50 +++++++++++++++++++++++--------------- src/html/m_layout.cpp | 28 ++++++++++----------- 6 files changed, 69 insertions(+), 60 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index b97abcd600..1e0216dfad 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -22,6 +22,8 @@ INCOMPATIBLE CHANGES SINCE 2.6.x wxHtmlCell::GetMouseCursor(); old code overriding GetCursor() will continue to work with WXWIN_COMPATIBILITY_2_6, but should be rewritten to use GetMouseCursor(). +- wxHtmlCell::AdjustPagebreak() signature has changed, update your code if you + override it - wxFontEnumerator::GetFacenames() and GetEncodings() now return arrays and not pointers to arrays - wxStaticBoxSizer now deletes the associated wxStaticBox when it is deleted diff --git a/include/wx/html/htmlcell.h b/include/wx/html/htmlcell.h index f5610c6e3d..0395a8d82d 100644 --- a/include/wx/html/htmlcell.h +++ b/include/wx/html/htmlcell.h @@ -277,8 +277,7 @@ public: // Returned value : true if pagebreak was modified, false otherwise // Usage : while (container->AdjustPagebreak(&p)) {} virtual bool AdjustPagebreak(int *pagebreak, - int *known_pagebreaks = NULL, - int number_of_pages = 0) const; + wxArrayInt& known_pagebreaks) const; // Sets cell's behaviour on pagebreaks (see AdjustPagebreak). Default // is true - the cell can be split on two pages @@ -411,7 +410,8 @@ public: wxHtmlRenderingInfo& info); virtual void DrawInvisible(wxDC& dc, int x, int y, wxHtmlRenderingInfo& info); - virtual bool AdjustPagebreak(int *pagebreak, int *known_pagebreaks = NULL, int number_of_pages = 0) const; +/* virtual bool AdjustPagebreak(int *pagebreak, int *known_pagebreaks = NULL, int number_of_pages = 0) const;*/ + virtual bool AdjustPagebreak(int *pagebreak, wxArrayInt& known_pagebreaks) const; // insert cell at the end of m_Cells list void InsertCell(wxHtmlCell *cell); diff --git a/include/wx/html/htmprint.h b/include/wx/html/htmprint.h index b407ebeeec..dd6c2e0f79 100644 --- a/include/wx/html/htmprint.h +++ b/include/wx/html/htmprint.h @@ -77,9 +77,8 @@ public: // set the same pagebreak twice. // // CAUTION! Render() changes DC's user scale and does NOT restore it! - int Render(int x, int y, int from = 0, int dont_render = FALSE, - int maxHeight = INT_MAX, - int *known_pagebreaks = NULL, int number_of_pages = 0); + int Render(int x, int y, wxArrayInt& known_pagebreaks, int from = 0, + int dont_render = FALSE, int to = INT_MAX); // returns total height of the html document // (compare Render's return value with this) @@ -181,7 +180,8 @@ private: private: int m_NumPages; - int m_PageBreaks[wxHTML_PRINT_MAX_PAGES]; + //int m_PageBreaks[wxHTML_PRINT_MAX_PAGES]; + wxArrayInt m_PageBreaks; wxString m_Document, m_BasePath; bool m_BasePathIsDir; diff --git a/src/html/htmlcell.cpp b/src/html/htmlcell.cpp index 10154cb387..3a100af4d6 100644 --- a/src/html/htmlcell.cpp +++ b/src/html/htmlcell.cpp @@ -219,7 +219,8 @@ wxCursor wxHtmlCell::GetMouseCursor(wxHtmlWindowInterface *window) const } -bool wxHtmlCell::AdjustPagebreak(int *pagebreak, int* WXUNUSED(known_pagebreaks), int WXUNUSED(number_of_pages)) const +bool wxHtmlCell::AdjustPagebreak(int *pagebreak, + wxArrayInt& WXUNUSED(known_pagebreaks)) const { if ((!m_CanLiveOnPagebreak) && m_PosY < *pagebreak && m_PosY + m_Height > *pagebreak) @@ -699,32 +700,28 @@ int wxHtmlContainerCell::GetIndentUnits(int ind) const } - -bool wxHtmlContainerCell::AdjustPagebreak(int *pagebreak, int* known_pagebreaks, int number_of_pages) const +bool wxHtmlContainerCell::AdjustPagebreak(int *pagebreak, + wxArrayInt& known_pagebreaks) const { if (!m_CanLiveOnPagebreak) - return wxHtmlCell::AdjustPagebreak(pagebreak, known_pagebreaks, number_of_pages); + return wxHtmlCell::AdjustPagebreak(pagebreak, known_pagebreaks); - else - { - wxHtmlCell *c = GetFirstChild(); - bool rt = false; - int pbrk = *pagebreak - m_PosY; + wxHtmlCell *c = GetFirstChild(); + bool rt = false; + int pbrk = *pagebreak - m_PosY; - while (c) - { - if (c->AdjustPagebreak(&pbrk, known_pagebreaks, number_of_pages)) - rt = true; - c = c->GetNext(); - } - if (rt) - *pagebreak = pbrk + m_PosY; - return rt; + while (c) + { + if (c->AdjustPagebreak(&pbrk, known_pagebreaks)) + rt = true; + c = c->GetNext(); } + if (rt) + *pagebreak = pbrk + m_PosY; + return rt; } - void wxHtmlContainerCell::Layout(int w) { wxHtmlCell::Layout(w); diff --git a/src/html/htmprint.cpp b/src/html/htmprint.cpp index af75193c5a..4625c82e89 100644 --- a/src/html/htmprint.cpp +++ b/src/html/htmprint.cpp @@ -103,20 +103,19 @@ void wxHtmlDCRenderer::SetStandardFonts(int size, m_Cells->Layout(m_Width); } - -int wxHtmlDCRenderer::Render(int x, int y, int from, int dont_render, - int maxHeight, - int *known_pagebreaks, int number_of_pages) +int wxHtmlDCRenderer::Render(int x, int y, + wxArrayInt& known_pagebreaks, + int from, int dont_render, int to) { int pbreak, hght; if (m_Cells == NULL || m_DC == NULL) return 0; pbreak = (int)(from + m_Height); - while (m_Cells->AdjustPagebreak(&pbreak, known_pagebreaks, number_of_pages)) {} + while (m_Cells->AdjustPagebreak(&pbreak, known_pagebreaks)) {} hght = pbreak - from; - if (maxHeight < hght) - hght = maxHeight; + if(to < hght) + hght = to; if (!dont_render) { @@ -137,7 +136,6 @@ int wxHtmlDCRenderer::Render(int x, int y, int from, int dont_render, } - int wxHtmlDCRenderer::GetTotalHeight() { if (m_Cells) return m_Cells->GetHeight(); @@ -265,16 +263,19 @@ bool wxHtmlPrintout::OnPrintPage(int page) void wxHtmlPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo) { *minPage = 1; - *maxPage = m_NumPages; + if ( m_NumPages >= (signed)m_PageBreaks.Count()-1) + *maxPage = m_NumPages; + else + *maxPage = (signed)m_PageBreaks.Count()-1; *selPageFrom = 1; - *selPageTo = m_NumPages; + *selPageTo = (signed)m_PageBreaks.Count()-1; } bool wxHtmlPrintout::HasPage(int pageNum) { - return (pageNum >= 1 && pageNum <= m_NumPages); + return (pageNum >= 1 && pageNum-1 <= (signed)m_PageBreaks.Count()); } @@ -360,16 +361,24 @@ void wxHtmlPrintout::CountPages() ppmm_v = (float)pageHeight / mm_h; int pos = 0; - m_NumPages = 0; + // m_PageBreaks[0] = 0; - m_PageBreaks[0] = 0; + m_PageBreaks.Clear(); + m_PageBreaks.Add( 0); do { pos = m_Renderer->Render((int)( ppmm_h * m_MarginLeft), - (int) (ppmm_v * (m_MarginTop + (m_HeaderHeight == 0 ? 0 : m_MarginSpace)) + m_HeaderHeight), - pos, true, INT_MAX, m_PageBreaks, m_NumPages); - m_PageBreaks[++m_NumPages] = pos; + (int) (ppmm_v * (m_MarginTop + (m_HeaderHeight == 0 ? 0 : m_MarginSpace)) + m_HeaderHeight), + m_PageBreaks, + pos, true, INT_MAX); + m_PageBreaks.Add( pos); + if( m_PageBreaks.Count() > wxHTML_PRINT_MAX_PAGES) + { + wxMessageBox( _("HTML pagination algorithm generated more than the allowed maximum number of pages and it can continue any longer!"), + _("Warning"), wxCANCEL | wxICON_ERROR ); + break; + } } while (pos < m_Renderer->GetTotalHeight()); } @@ -403,19 +412,20 @@ void wxHtmlPrintout::RenderPage(wxDC *dc, int page) dc->SetBackgroundMode(wxTRANSPARENT); m_Renderer->Render((int) (ppmm_h * m_MarginLeft), - (int) (ppmm_v * (m_MarginTop + (m_HeaderHeight == 0 ? 0 : m_MarginSpace)) + m_HeaderHeight), + (int) (ppmm_v * (m_MarginTop + (m_HeaderHeight == 0 ? 0 : m_MarginSpace)) + m_HeaderHeight), m_PageBreaks, m_PageBreaks[page-1], false, m_PageBreaks[page]-m_PageBreaks[page-1]); + m_RendererHdr->SetDC(dc, (double)ppiPrinterY / (double)ppiScreenY); if (m_Headers[page % 2] != wxEmptyString) { m_RendererHdr->SetHtmlText(TranslateHeader(m_Headers[page % 2], page)); - m_RendererHdr->Render((int) (ppmm_h * m_MarginLeft), (int) (ppmm_v * m_MarginTop)); + m_RendererHdr->Render((int) (ppmm_h * m_MarginLeft), (int) (ppmm_v * m_MarginTop), m_PageBreaks); } if (m_Footers[page % 2] != wxEmptyString) { m_RendererHdr->SetHtmlText(TranslateHeader(m_Footers[page % 2], page)); - m_RendererHdr->Render((int) (ppmm_h * m_MarginLeft), (int) (pageHeight - ppmm_v * m_MarginBottom - m_FooterHeight)); + m_RendererHdr->Render((int) (ppmm_h * m_MarginLeft), (int) (pageHeight - ppmm_v * m_MarginBottom - m_FooterHeight), m_PageBreaks); } } @@ -429,7 +439,7 @@ wxString wxHtmlPrintout::TranslateHeader(const wxString& instr, int page) num.Printf(wxT("%i"), page); r.Replace(wxT("@PAGENUM@"), num); - num.Printf(wxT("%i"), m_NumPages); + num.Printf(wxT("%i"), m_PageBreaks.Count()-1); r.Replace(wxT("@PAGESCNT@"), num); return r; diff --git a/src/html/m_layout.cpp b/src/html/m_layout.cpp index e4242e6a66..e118e82fc7 100644 --- a/src/html/m_layout.cpp +++ b/src/html/m_layout.cpp @@ -72,8 +72,8 @@ public: wxHtmlPageBreakCell() {} bool AdjustPagebreak(int* pagebreak, - int* known_pagebreaks = NULL, - int number_of_pages = 0) const; + wxArrayInt& known_pagebreaks) const; + void Draw(wxDC& WXUNUSED(dc), int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(view_y1), int WXUNUSED(view_y2), @@ -89,7 +89,7 @@ extern "C" int wxCMPFUNC_CONV wxInteger_compare(void const* i0, void const* i1) return *(int*)i0 - *(int*)i1; } -bool wxHtmlPageBreakCell::AdjustPagebreak(int* pagebreak, int* known_pagebreaks, int number_of_pages) const +bool wxHtmlPageBreakCell::AdjustPagebreak(int* pagebreak, wxArrayInt& known_pagebreaks) const { // When we are counting pages, 'known_pagebreaks' is non-NULL. // That's the only time we change 'pagebreak'. Otherwise, pages @@ -101,10 +101,10 @@ bool wxHtmlPageBreakCell::AdjustPagebreak(int* pagebreak, int* known_pagebreaks, // vertical position. Otherwise we'd be setting a pagebreak above // the current cell, which is incorrect, or duplicating a // pagebreak that has already been set. - if(NULL == known_pagebreaks || *pagebreak <= m_PosY) - { + if( known_pagebreaks.Count() == 0 || *pagebreak <= m_PosY) + { return false; - } + } // m_PosY is only the vertical offset from the parent. The pagebreak // required here is the total page offset, so m_PosY must be added @@ -117,21 +117,21 @@ bool wxHtmlPageBreakCell::AdjustPagebreak(int* pagebreak, int* known_pagebreaks, // is known to be sorted in strictly increasing order. '1 + number_of_pages' // is used as a bsearch() argument because the array contains a leading // zero plus one element for each page. - int* where = (int*) bsearch(&total_height, known_pagebreaks, - 1 + number_of_pages, sizeof(int), - wxInteger_compare); + int where = known_pagebreaks.Index( total_height); // Add a pagebreak only if there isn't one already set here. - if(NULL != where) - { + if( wxNOT_FOUND != where) + { return false; - } + } else - { + { *pagebreak = m_PosY; return true; - } + } } + + TAG_HANDLER_BEGIN(P, "P") TAG_HANDLER_CONSTR(P) { } -- 2.45.2