]> git.saurik.com Git - wxWidgets.git/commitdiff
use dynamic array for the page breaks positions (patch 1483976)
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 28 May 2006 22:56:28 +0000 (22:56 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 28 May 2006 22:56:28 +0000 (22:56 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39396 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/html/htmlcell.h
include/wx/html/htmprint.h
src/html/htmlcell.cpp
src/html/htmprint.cpp
src/html/m_layout.cpp

index b97abcd6008c2d255a99d4a7439799d7c823f8c2..1e0216dfad2e6664e11cf95b65c182568788a3d0 100644 (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
index f5610c6e3d1daf49a822e2743641226f4dceb3ba..0395a8d82d43303d4563c4e2ed4105c0944459db 100644 (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);
index b407ebeeec90c7ecbc133ff17b4dff5719667aaa..dd6c2e0f7934e4b0f7f258f28b5d858a088fe415 100644 (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;
index 10154cb387c546a455810935c1af2c0e3cd9c9ea..3a100af4d6c65654147fa1d37217c66967ccac9d 100644 (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,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);
index af75193c5a3ea782e2f8acc3172cbd8a9354c85e..4625c82e897bb18df6fe05456a1cc4dd1aed8f42 100644 (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;
-    *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;
index e4242e6a6621764405e1e8d827534cd9ec23ffa0..e118e82fc7c9216385796d3d672020fff8265ba5 100644 (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,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) { }