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
This commit is contained in:
Vadim Zeitlin
2006-05-28 22:56:28 +00:00
parent db759dde87
commit fd0bab4353
6 changed files with 69 additions and 60 deletions

View File

@@ -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

View File

@@ -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);

View File

@@ -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;

View File

@@ -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,21 +700,19 @@ 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;
while (c)
{
if (c->AdjustPagebreak(&pbrk, known_pagebreaks, number_of_pages))
if (c->AdjustPagebreak(&pbrk, known_pagebreaks))
rt = true;
c = c->GetNext();
}
@@ -721,8 +720,6 @@ bool wxHtmlContainerCell::AdjustPagebreak(int *pagebreak, int* known_pagebreaks,
*pagebreak = pbrk + m_PosY;
return rt;
}
}
void wxHtmlContainerCell::Layout(int w)

View File

@@ -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;
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;
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;

View File

@@ -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,7 +101,7 @@ 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;
}
@@ -117,11 +117,9 @@ 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;
}
@@ -132,6 +130,8 @@ bool wxHtmlPageBreakCell::AdjustPagebreak(int* pagebreak, int* known_pagebreaks,
}
}
TAG_HANDLER_BEGIN(P, "P")
TAG_HANDLER_CONSTR(P) { }