1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/richtext/richtextprint.cpp
3 // Purpose: Rich text printing classes
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
18 #if wxUSE_RICHTEXT && wxUSE_PRINTING_ARCHITECTURE && wxUSE_STREAMS
24 #include "wx/settings.h"
25 #include "wx/msgdlg.h"
28 #include "wx/datetime.h"
30 #include "wx/printdlg.h"
31 #include "wx/richtext/richtextprint.h"
32 #include "wx/wfstream.h"
38 wxRichTextPrintout::wxRichTextPrintout(const wxString
& title
) : wxPrintout(title
)
40 m_numPages
= wxRICHTEXT_PRINT_MAX_PAGES
;
42 SetMargins(); // to default values
45 wxRichTextPrintout::~wxRichTextPrintout()
49 void wxRichTextPrintout::OnPreparePrinting()
55 m_pageBreaksStart
.Clear();
56 m_pageBreaksEnd
.Clear();
57 m_pageYOffsets
.Clear();
61 wxRect rect
, headerRect
, footerRect
;
63 /// Sets the DC scaling and returns important page rectangles
64 CalculateScaling(GetDC(), rect
, headerRect
, footerRect
);
66 if (GetRichTextBuffer())
68 GetRichTextBuffer()->Invalidate(wxRICHTEXT_ALL
);
70 wxRichTextDrawingContext
context(GetRichTextBuffer());
71 GetRichTextBuffer()->Layout(*GetDC(), context
, rect
, rect
, wxRICHTEXT_FIXED_WIDTH
|wxRICHTEXT_VARIABLE_HEIGHT
);
73 // Now calculate the page breaks
77 wxRichTextLine
* lastLine
= NULL
;
79 wxRichTextObjectList::compatibility_iterator node
= GetRichTextBuffer()->GetChildren().GetFirst();
82 // child is a paragraph
83 wxRichTextParagraph
* child
= wxDynamicCast(node
->GetData(), wxRichTextParagraph
);
84 wxASSERT (child
!= NULL
);
87 wxRichTextLineList::compatibility_iterator node2
= child
->GetLines().GetFirst();
90 wxRichTextLine
* line
= node2
->GetData();
92 int lineY
= child
->GetPosition().y
+ line
->GetPosition().y
- yOffset
;
93 bool hasHardPageBreak
= ((node2
== child
->GetLines().GetFirst()) && child
->GetAttributes().HasPageBreak());
95 // Break the page if either we're going off the bottom, or this paragraph specifies
96 // an explicit page break
98 if (((lineY
+ line
->GetSize().y
) > rect
.GetBottom()) || hasHardPageBreak
)
100 // New page starting at this line
103 // We increase the offset by the difference between new and old positions
105 int increaseOffsetBy
= lineY
- newY
;
106 yOffset
+= increaseOffsetBy
;
111 m_pageBreaksStart
.Add(lastStartPos
);
112 m_pageBreaksEnd
.Add(lastLine
->GetAbsoluteRange().GetEnd());
113 m_pageYOffsets
.Add(yOffset
);
115 lastStartPos
= line
->GetAbsoluteRange().GetStart();
120 // Now create page breaks for the rest of the line, if it's larger than the page height
121 int contentLeft
= line
->GetSize().y
- rect
.GetHeight();
122 while (contentLeft
>= 0)
124 yOffset
+= rect
.GetHeight();
125 contentLeft
-= rect
.GetHeight();
127 m_pageBreaksStart
.Add(lastStartPos
);
128 m_pageBreaksEnd
.Add(lastLine
->GetAbsoluteRange().GetEnd());
129 m_pageYOffsets
.Add(yOffset
);
135 node2
= node2
->GetNext();
139 node
= node
->GetNext();
142 // Closing page break
143 if (m_pageBreaksStart
.GetCount() == 0 || (m_pageBreaksEnd
[m_pageBreaksEnd
.GetCount()-1] < (GetRichTextBuffer()->GetOwnRange().GetEnd()-1)))
145 m_pageBreaksStart
.Add(lastStartPos
);
146 m_pageBreaksEnd
.Add(GetRichTextBuffer()->GetOwnRange().GetEnd());
147 m_pageYOffsets
.Add(yOffset
);
152 bool wxRichTextPrintout::OnBeginDocument(int startPage
, int endPage
)
154 if (!wxPrintout::OnBeginDocument(startPage
, endPage
)) return false;
159 bool wxRichTextPrintout::OnPrintPage(int page
)
165 RenderPage(dc
, page
);
171 void wxRichTextPrintout::GetPageInfo(int *minPage
, int *maxPage
, int *selPageFrom
, int *selPageTo
)
174 *maxPage
= m_numPages
;
176 *selPageTo
= m_numPages
;
179 bool wxRichTextPrintout::HasPage(int pageNum
)
181 return pageNum
> 0 && pageNum
<= m_numPages
;
184 void wxRichTextPrintout::RenderPage(wxDC
*dc
, int page
)
186 if (!GetRichTextBuffer())
191 wxRect textRect
, headerRect
, footerRect
;
193 /// Sets the DC scaling and returns important page rectangles
194 CalculateScaling(dc
, textRect
, headerRect
, footerRect
);
196 if (page
> 1 || m_headerFooterData
.GetShowOnFirstPage())
198 if (m_headerFooterData
.GetFont().IsOk())
199 dc
->SetFont(m_headerFooterData
.GetFont());
201 dc
->SetFont(*wxNORMAL_FONT
);
202 if (m_headerFooterData
.GetTextColour().IsOk())
203 dc
->SetTextForeground(m_headerFooterData
.GetTextColour());
205 dc
->SetTextForeground(*wxBLACK
);
206 dc
->SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT
);
208 // Draw header, if any
209 wxRichTextOddEvenPage oddEven
= ((page
% 2) == 1) ? wxRICHTEXT_PAGE_ODD
: wxRICHTEXT_PAGE_EVEN
;
211 wxString headerTextCentre
= m_headerFooterData
.GetHeaderText(oddEven
, wxRICHTEXT_PAGE_CENTRE
);
212 wxString headerTextLeft
= m_headerFooterData
.GetHeaderText(oddEven
, wxRICHTEXT_PAGE_LEFT
);
213 wxString headerTextRight
= m_headerFooterData
.GetHeaderText(oddEven
, wxRICHTEXT_PAGE_RIGHT
);
215 if (!headerTextLeft
.IsEmpty())
217 SubstituteKeywords(headerTextLeft
, GetTitle(), page
, m_numPages
);
220 //dc->GetTextExtent(headerTextLeft, & tx, & ty);
222 int x
= headerRect
.GetLeft();
223 int y
= headerRect
.GetX();
224 dc
->DrawText(headerTextLeft
, x
, y
);
226 if (!headerTextCentre
.IsEmpty())
228 SubstituteKeywords(headerTextCentre
, GetTitle(), page
, m_numPages
);
231 dc
->GetTextExtent(headerTextCentre
, & tx
, & ty
);
233 int x
= headerRect
.GetWidth()/2 - tx
/2 + headerRect
.GetLeft();
234 int y
= headerRect
.GetY();
235 dc
->DrawText(headerTextCentre
, x
, y
);
237 if (!headerTextRight
.IsEmpty())
239 SubstituteKeywords(headerTextRight
, GetTitle(), page
, m_numPages
);
242 dc
->GetTextExtent(headerTextRight
, & tx
, & ty
);
244 int x
= headerRect
.GetRight() - tx
;
245 int y
= headerRect
.GetY();
246 dc
->DrawText(headerTextRight
, x
, y
);
249 // Draw footer, if any
250 wxString footerTextCentre
= m_headerFooterData
.GetFooterText(oddEven
, wxRICHTEXT_PAGE_CENTRE
);
251 wxString footerTextLeft
= m_headerFooterData
.GetFooterText(oddEven
, wxRICHTEXT_PAGE_LEFT
);
252 wxString footerTextRight
= m_headerFooterData
.GetFooterText(oddEven
, wxRICHTEXT_PAGE_RIGHT
);
254 if (!footerTextLeft
.IsEmpty())
256 SubstituteKeywords(footerTextLeft
, GetTitle(), page
, m_numPages
);
259 dc
->GetTextExtent(footerTextLeft
, & tx
, & ty
);
261 int x
= footerRect
.GetLeft();
262 int y
= footerRect
.GetBottom() - ty
;
263 dc
->DrawText(footerTextLeft
, x
, y
);
265 if (!footerTextCentre
.IsEmpty())
267 SubstituteKeywords(footerTextCentre
, GetTitle(), page
, m_numPages
);
270 dc
->GetTextExtent(footerTextCentre
, & tx
, & ty
);
272 int x
= footerRect
.GetWidth()/2 - tx
/2 + footerRect
.GetLeft();
273 int y
= footerRect
.GetBottom() - ty
;
274 dc
->DrawText(footerTextCentre
, x
, y
);
276 if (!footerTextRight
.IsEmpty())
278 SubstituteKeywords(footerTextRight
, GetTitle(), page
, m_numPages
);
281 dc
->GetTextExtent(footerTextRight
, & tx
, & ty
);
283 int x
= footerRect
.GetRight() - tx
;
284 int y
= footerRect
.GetBottom() - ty
;
285 dc
->DrawText(footerTextRight
, x
, y
);
289 wxRichTextRange
rangeToDraw(m_pageBreaksStart
[page
-1], m_pageBreaksEnd
[page
-1]);
291 wxPoint oldOrigin
= dc
->GetLogicalOrigin();
292 double scaleX
, scaleY
;
293 dc
->GetUserScale(& scaleX
, & scaleY
);
297 yOffset
= m_pageYOffsets
[page
-2];
299 if (yOffset
!= oldOrigin
.y
)
300 dc
->SetLogicalOrigin(oldOrigin
.x
, oldOrigin
.y
+ yOffset
);
302 dc
->SetClippingRegion(wxRect(textRect
.x
, textRect
.y
+ yOffset
, textRect
.width
, textRect
.height
));
304 wxRichTextDrawingContext
context(GetRichTextBuffer());
305 GetRichTextBuffer()->Draw(*dc
, context
, rangeToDraw
, wxRichTextSelection(), textRect
, 0 /* descent */, wxRICHTEXT_DRAW_IGNORE_CACHE
|wxRICHTEXT_DRAW_PRINT
/* flags */);
307 dc
->DestroyClippingRegion();
309 if (yOffset
!= oldOrigin
.y
)
310 dc
->SetLogicalOrigin(oldOrigin
.x
, oldOrigin
.y
);
313 void wxRichTextPrintout::SetMargins(int top
, int bottom
, int left
, int right
)
316 m_marginBottom
= bottom
;
318 m_marginRight
= right
;
321 /// Calculate scaling and rectangles, setting the device context scaling
322 void wxRichTextPrintout::CalculateScaling(wxDC
* dc
, wxRect
& textRect
, wxRect
& headerRect
, wxRect
& footerRect
)
324 // Get the logical pixels per inch of screen and printer
325 int ppiScreenX
, ppiScreenY
;
326 GetPPIScreen(&ppiScreenX
, &ppiScreenY
);
327 int ppiPrinterX
, ppiPrinterY
;
328 GetPPIPrinter(&ppiPrinterX
, &ppiPrinterY
);
330 // This scales the DC so that the printout roughly represents the
331 // the screen scaling.
332 float scale
= (float)((float)ppiPrinterX
/(float)ppiScreenX
);
334 // Now we have to check in case our real page size is reduced
335 // (e.g. because we're drawing to a print preview memory DC)
336 int pageWidth
, pageHeight
;
339 GetPageSizePixels(&pageWidth
, &pageHeight
);
341 // If printer pageWidth == current DC width, then this doesn't
342 // change. But w might be the preview bitmap width, so scale down.
343 float previewScale
= (float)(w
/(float)pageWidth
);
344 float overallScale
= scale
* previewScale
;
346 // The dimensions used for indentation etc. have to be unscaled
347 // during printing to be correct when scaling is applied.
348 // Also, correct the conversions in wxRTC using DC instead of print DC.
349 m_richTextBuffer
->SetScale(scale
* float(dc
->GetPPI().x
)/float(ppiPrinterX
));
352 int marginLeft
= wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX
, m_marginLeft
);
353 int marginTop
= wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX
, m_marginTop
);
354 int marginRight
= wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX
, m_marginRight
);
355 int marginBottom
= wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX
, m_marginBottom
);
357 // Header and footer margins
358 int headerMargin
= wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX
, m_headerFooterData
.GetHeaderMargin());
359 int footerMargin
= wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX
, m_headerFooterData
.GetFooterMargin());
361 dc
->SetUserScale(overallScale
, overallScale
);
363 wxRect
rect((int) (marginLeft
/scale
), (int) (marginTop
/scale
),
364 (int) ((pageWidth
- marginLeft
- marginRight
)/scale
), (int)((pageHeight
- marginTop
- marginBottom
)/scale
));
366 headerRect
= wxRect(0, 0, 0, 0);
368 if (!m_headerFooterData
.GetHeaderText(wxRICHTEXT_PAGE_ODD
, wxRICHTEXT_PAGE_LEFT
).IsEmpty() ||
369 !m_headerFooterData
.GetHeaderText(wxRICHTEXT_PAGE_ODD
, wxRICHTEXT_PAGE_CENTRE
).IsEmpty() ||
370 !m_headerFooterData
.GetHeaderText(wxRICHTEXT_PAGE_ODD
, wxRICHTEXT_PAGE_RIGHT
).IsEmpty() ||
372 !m_headerFooterData
.GetHeaderText(wxRICHTEXT_PAGE_EVEN
, wxRICHTEXT_PAGE_LEFT
).IsEmpty() ||
373 !m_headerFooterData
.GetHeaderText(wxRICHTEXT_PAGE_EVEN
, wxRICHTEXT_PAGE_CENTRE
).IsEmpty() ||
374 !m_headerFooterData
.GetHeaderText(wxRICHTEXT_PAGE_EVEN
, wxRICHTEXT_PAGE_RIGHT
).IsEmpty())
376 if (m_headerFooterData
.GetFont().IsOk())
377 dc
->SetFont(m_headerFooterData
.GetFont());
379 dc
->SetFont(*wxNORMAL_FONT
);
381 int charHeight
= dc
->GetCharHeight();
383 int headerHeight
= (int) (charHeight
+ headerMargin
/scale
);
385 headerRect
= wxRect(rect
.x
, rect
.y
, rect
.width
, headerHeight
);
387 rect
.y
+= headerHeight
;
388 rect
.height
-= headerHeight
;
391 footerRect
= wxRect(0, 0, 0, 0);
393 if (!m_headerFooterData
.GetFooterText(wxRICHTEXT_PAGE_ODD
, wxRICHTEXT_PAGE_LEFT
).IsEmpty() ||
394 !m_headerFooterData
.GetFooterText(wxRICHTEXT_PAGE_ODD
, wxRICHTEXT_PAGE_CENTRE
).IsEmpty() ||
395 !m_headerFooterData
.GetFooterText(wxRICHTEXT_PAGE_ODD
, wxRICHTEXT_PAGE_RIGHT
).IsEmpty() ||
397 !m_headerFooterData
.GetFooterText(wxRICHTEXT_PAGE_EVEN
, wxRICHTEXT_PAGE_LEFT
).IsEmpty() ||
398 !m_headerFooterData
.GetFooterText(wxRICHTEXT_PAGE_EVEN
, wxRICHTEXT_PAGE_CENTRE
).IsEmpty() ||
399 !m_headerFooterData
.GetFooterText(wxRICHTEXT_PAGE_EVEN
, wxRICHTEXT_PAGE_RIGHT
).IsEmpty())
401 if (m_headerFooterData
.GetFont().IsOk())
402 dc
->SetFont(m_headerFooterData
.GetFont());
404 dc
->SetFont(*wxNORMAL_FONT
);
406 int charHeight
= dc
->GetCharHeight();
408 int footerHeight
= (int) (charHeight
+ footerMargin
/scale
);
410 footerRect
= wxRect(rect
.x
, rect
.y
+ rect
.height
, rect
.width
, footerHeight
);
412 rect
.height
-= footerHeight
;
418 bool wxRichTextPrintout::SubstituteKeywords(wxString
& str
, const wxString
& title
, int pageNum
, int pageCount
)
422 num
.Printf(wxT("%i"), pageNum
);
423 str
.Replace(wxT("@PAGENUM@"), num
);
425 num
.Printf(wxT("%lu"), (unsigned long) pageCount
);
426 str
.Replace(wxT("@PAGESCNT@"), num
);
428 wxDateTime now
= wxDateTime::Now();
430 str
.Replace(wxT("@DATE@"), now
.FormatDate());
431 str
.Replace(wxT("@TIME@"), now
.FormatTime());
433 str
.Replace(wxT("@TITLE@"), title
);
442 wxRichTextPrinting::wxRichTextPrinting(const wxString
& name
, wxWindow
*parentWindow
)
444 m_richTextBufferPrinting
= NULL
;
445 m_richTextBufferPreview
= NULL
;
447 m_parentWindow
= parentWindow
;
451 m_previewRect
= wxRect(wxPoint(100, 100), wxSize(800, 800));
453 m_pageSetupData
= new wxPageSetupDialogData
;
454 m_pageSetupData
->EnableMargins(true);
455 m_pageSetupData
->SetMarginTopLeft(wxPoint(25, 25));
456 m_pageSetupData
->SetMarginBottomRight(wxPoint(25, 25));
459 wxRichTextPrinting::~wxRichTextPrinting()
462 delete m_pageSetupData
;
463 delete m_richTextBufferPrinting
;
464 delete m_richTextBufferPreview
;
467 wxPrintData
*wxRichTextPrinting::GetPrintData()
469 if (m_printData
== NULL
)
470 m_printData
= new wxPrintData();
474 /// Set print and page setup data
475 void wxRichTextPrinting::SetPrintData(const wxPrintData
& printData
)
477 (*GetPrintData()) = printData
;
480 void wxRichTextPrinting::SetPageSetupData(const wxPageSetupDialogData
& pageSetupData
)
482 (*GetPageSetupData()) = pageSetupData
;
485 /// Set the rich text buffer pointer, deleting the existing object if present
486 void wxRichTextPrinting::SetRichTextBufferPrinting(wxRichTextBuffer
* buf
)
488 if (m_richTextBufferPrinting
)
490 delete m_richTextBufferPrinting
;
491 m_richTextBufferPrinting
= NULL
;
493 m_richTextBufferPrinting
= buf
;
496 void wxRichTextPrinting::SetRichTextBufferPreview(wxRichTextBuffer
* buf
)
498 if (m_richTextBufferPreview
)
500 delete m_richTextBufferPreview
;
501 m_richTextBufferPreview
= NULL
;
503 m_richTextBufferPreview
= buf
;
506 bool wxRichTextPrinting::PreviewFile(const wxString
& richTextFile
)
508 SetRichTextBufferPreview(new wxRichTextBuffer
);
510 if (!m_richTextBufferPreview
->LoadFile(richTextFile
))
512 SetRichTextBufferPreview(NULL
);
516 SetRichTextBufferPrinting(new wxRichTextBuffer(*m_richTextBufferPreview
));
518 wxRichTextPrintout
*p1
= CreatePrintout();
519 p1
->SetRichTextBuffer(m_richTextBufferPreview
);
521 wxRichTextPrintout
*p2
= CreatePrintout();
522 p2
->SetRichTextBuffer(m_richTextBufferPrinting
);
523 return DoPreview(p1
, p2
);
526 bool wxRichTextPrinting::PreviewBuffer(const wxRichTextBuffer
& buffer
)
528 SetRichTextBufferPreview(new wxRichTextBuffer(buffer
));
529 SetRichTextBufferPrinting(new wxRichTextBuffer(buffer
));
531 wxRichTextPrintout
*p1
= CreatePrintout();
532 p1
->SetRichTextBuffer(m_richTextBufferPreview
);
534 wxRichTextPrintout
*p2
= CreatePrintout();
535 p2
->SetRichTextBuffer(m_richTextBufferPrinting
);
537 return DoPreview(p1
, p2
);
540 bool wxRichTextPrinting::PrintFile(const wxString
& richTextFile
, bool showPrintDialog
)
542 SetRichTextBufferPrinting(new wxRichTextBuffer
);
544 if (!m_richTextBufferPrinting
->LoadFile(richTextFile
))
546 SetRichTextBufferPrinting(NULL
);
550 wxRichTextPrintout
*p
= CreatePrintout();
551 p
->SetRichTextBuffer(m_richTextBufferPrinting
);
553 bool ret
= DoPrint(p
, showPrintDialog
);
558 bool wxRichTextPrinting::PrintBuffer(const wxRichTextBuffer
& buffer
, bool showPrintDialog
)
560 SetRichTextBufferPrinting(new wxRichTextBuffer(buffer
));
562 wxRichTextPrintout
*p
= CreatePrintout();
563 p
->SetRichTextBuffer(m_richTextBufferPrinting
);
565 bool ret
= DoPrint(p
, showPrintDialog
);
570 bool wxRichTextPrinting::DoPreview(wxRichTextPrintout
*printout1
, wxRichTextPrintout
*printout2
)
572 // Pass two printout objects: for preview, and possible printing.
573 wxPrintDialogData
printDialogData(*GetPrintData());
574 wxPrintPreview
*preview
= new wxPrintPreview(printout1
, printout2
, &printDialogData
);
575 if (!preview
->IsOk())
581 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, m_parentWindow
,
582 m_title
+ _(" Preview"),
583 m_previewRect
.GetPosition(), m_previewRect
.GetSize());
584 frame
->Centre(wxBOTH
);
590 bool wxRichTextPrinting::DoPrint(wxRichTextPrintout
*printout
, bool showPrintDialog
)
592 wxPrintDialogData
printDialogData(*GetPrintData());
593 wxPrinter
printer(&printDialogData
);
595 if (!printer
.Print(m_parentWindow
, printout
, showPrintDialog
))
600 (*GetPrintData()) = printer
.GetPrintDialogData().GetPrintData();
604 void wxRichTextPrinting::PageSetup()
606 if (!GetPrintData()->IsOk())
608 wxLogError(_("There was a problem during page setup: you may need to set a default printer."));
612 m_pageSetupData
->SetPrintData(*GetPrintData());
613 wxPageSetupDialog
pageSetupDialog(m_parentWindow
, m_pageSetupData
);
615 if (pageSetupDialog
.ShowModal() == wxID_OK
)
617 (*GetPrintData()) = pageSetupDialog
.GetPageSetupData().GetPrintData();
618 (*m_pageSetupData
) = pageSetupDialog
.GetPageSetupData();
622 wxRichTextPrintout
*wxRichTextPrinting::CreatePrintout()
624 wxRichTextPrintout
*p
= new wxRichTextPrintout(m_title
);
626 p
->SetHeaderFooterData(GetHeaderFooterData());
627 p
->SetMargins(10*m_pageSetupData
->GetMarginTopLeft().y
,
628 10*m_pageSetupData
->GetMarginBottomRight().y
,
629 10*m_pageSetupData
->GetMarginTopLeft().x
,
630 10*m_pageSetupData
->GetMarginBottomRight().x
);
635 /// Set/get header text, e.g. wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT
636 void wxRichTextPrinting::SetHeaderText(const wxString
& text
, wxRichTextOddEvenPage page
, wxRichTextPageLocation location
)
638 m_headerFooterData
.SetHeaderText(text
, page
, location
);
641 wxString
wxRichTextPrinting::GetHeaderText(wxRichTextOddEvenPage page
, wxRichTextPageLocation location
) const
643 return m_headerFooterData
.GetHeaderText(page
, location
);
646 /// Set/get footer text, e.g. wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT
647 void wxRichTextPrinting::SetFooterText(const wxString
& text
, wxRichTextOddEvenPage page
, wxRichTextPageLocation location
)
649 m_headerFooterData
.SetFooterText(text
, page
, location
);
652 wxString
wxRichTextPrinting::GetFooterText(wxRichTextOddEvenPage page
, wxRichTextPageLocation location
) const
654 return m_headerFooterData
.GetFooterText(page
, location
);
661 IMPLEMENT_CLASS(wxRichTextHeaderFooterData
, wxObject
)
664 void wxRichTextHeaderFooterData::Copy(const wxRichTextHeaderFooterData
& data
)
667 for (i
= 0; i
< 12; i
++)
668 m_text
[i
] = data
.m_text
[i
];
669 m_font
= data
.m_font
;
670 m_colour
= data
.m_colour
;
671 m_headerMargin
= data
.m_headerMargin
;
672 m_footerMargin
= data
.m_footerMargin
;
673 m_showOnFirstPage
= data
.m_showOnFirstPage
;
677 void wxRichTextHeaderFooterData::SetText(const wxString
& text
, int headerFooter
, wxRichTextOddEvenPage page
, wxRichTextPageLocation location
)
679 int idx
= headerFooter
+ (2 * (int) page
) + (4 * (int) location
);
680 wxASSERT( idx
>= 0 && idx
< 12 );
682 if (idx
>= 0 && idx
< 12)
686 wxString
wxRichTextHeaderFooterData::GetText(int headerFooter
, wxRichTextOddEvenPage page
, wxRichTextPageLocation location
) const
688 int idx
= headerFooter
+ (2 * (int) page
) + (4 * (int) location
);
689 wxASSERT( idx
>= 0 && idx
< 12 );
691 if (idx
>= 0 && idx
< 12)
694 return wxEmptyString
;
697 /// Set/get header text, e.g. wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT
698 void wxRichTextHeaderFooterData::SetHeaderText(const wxString
& text
, wxRichTextOddEvenPage page
, wxRichTextPageLocation location
)
700 if (page
== wxRICHTEXT_PAGE_ALL
)
702 SetText(text
, 0, wxRICHTEXT_PAGE_ODD
, location
);
703 SetText(text
, 0, wxRICHTEXT_PAGE_EVEN
, location
);
706 SetText(text
, 0, page
, location
);
709 wxString
wxRichTextHeaderFooterData::GetHeaderText(wxRichTextOddEvenPage page
, wxRichTextPageLocation location
) const
711 return GetText(0, page
, location
);
714 /// Set/get footer text, e.g. wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT
715 void wxRichTextHeaderFooterData::SetFooterText(const wxString
& text
, wxRichTextOddEvenPage page
, wxRichTextPageLocation location
)
717 if (page
== wxRICHTEXT_PAGE_ALL
)
719 SetText(text
, 1, wxRICHTEXT_PAGE_ODD
, location
);
720 SetText(text
, 1, wxRICHTEXT_PAGE_EVEN
, location
);
723 SetText(text
, 1, page
, location
);
726 wxString
wxRichTextHeaderFooterData::GetFooterText(wxRichTextOddEvenPage page
, wxRichTextPageLocation location
) const
728 return GetText(1, page
, location
);
732 void wxRichTextHeaderFooterData::Clear()
735 for (i
= 0; i
< 12; i
++)
736 m_text
[i
] = wxEmptyString
;
739 #endif // wxUSE_RICHTEXT & wxUSE_PRINTING_ARCHITECTURE