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 GetRichTextBuffer()->Layout(*GetDC(), rect
, wxRICHTEXT_FIXED_WIDTH
|wxRICHTEXT_VARIABLE_HEIGHT
);
72 // Now calculate the page breaks
76 wxRichTextLine
* lastLine
= NULL
;
78 wxRichTextObjectList::compatibility_iterator node
= GetRichTextBuffer()->GetChildren().GetFirst();
81 // child is a paragraph
82 wxRichTextParagraph
* child
= wxDynamicCast(node
->GetData(), wxRichTextParagraph
);
83 wxASSERT (child
!= NULL
);
86 wxRichTextLineList::compatibility_iterator node2
= child
->GetLines().GetFirst();
89 wxRichTextLine
* line
= node2
->GetData();
91 int lineY
= child
->GetPosition().y
+ line
->GetPosition().y
- yOffset
;
92 bool hasHardPageBreak
= ((node2
== child
->GetLines().GetFirst()) && child
->GetAttributes().HasPageBreak());
94 // Break the page if either we're going off the bottom, or this paragraph specifies
95 // an explicit page break
97 if (((lineY
+ line
->GetSize().y
) > rect
.GetBottom()) || hasHardPageBreak
)
99 // New page starting at this line
102 // We increase the offset by the difference between new and old positions
104 int increaseOffsetBy
= lineY
- newY
;
105 yOffset
+= increaseOffsetBy
;
110 m_pageBreaksStart
.Add(lastStartPos
);
111 m_pageBreaksEnd
.Add(lastLine
->GetAbsoluteRange().GetEnd());
112 m_pageYOffsets
.Add(yOffset
);
114 lastStartPos
= line
->GetAbsoluteRange().GetStart();
119 // Now create page breaks for the rest of the line, if it's larger than the page height
120 int contentLeft
= line
->GetSize().y
- rect
.GetHeight();
121 while (contentLeft
>= 0)
123 yOffset
+= rect
.GetHeight();
124 contentLeft
-= rect
.GetHeight();
126 m_pageBreaksStart
.Add(lastStartPos
);
127 m_pageBreaksEnd
.Add(lastLine
->GetAbsoluteRange().GetEnd());
128 m_pageYOffsets
.Add(yOffset
);
134 node2
= node2
->GetNext();
138 node
= node
->GetNext();
141 // Closing page break
142 if (m_pageBreaksStart
.GetCount() == 0 || (m_pageBreaksEnd
[m_pageBreaksEnd
.GetCount()-1] < (GetRichTextBuffer()->GetOwnRange().GetEnd()-1)))
144 m_pageBreaksStart
.Add(lastStartPos
);
145 m_pageBreaksEnd
.Add(GetRichTextBuffer()->GetOwnRange().GetEnd());
146 m_pageYOffsets
.Add(yOffset
);
151 bool wxRichTextPrintout::OnBeginDocument(int startPage
, int endPage
)
153 if (!wxPrintout::OnBeginDocument(startPage
, endPage
)) return false;
158 bool wxRichTextPrintout::OnPrintPage(int page
)
164 RenderPage(dc
, page
);
170 void wxRichTextPrintout::GetPageInfo(int *minPage
, int *maxPage
, int *selPageFrom
, int *selPageTo
)
173 *maxPage
= m_numPages
;
175 *selPageTo
= m_numPages
;
178 bool wxRichTextPrintout::HasPage(int pageNum
)
180 return pageNum
> 0 && pageNum
<= m_numPages
;
183 void wxRichTextPrintout::RenderPage(wxDC
*dc
, int page
)
185 if (!GetRichTextBuffer())
190 wxRect textRect
, headerRect
, footerRect
;
192 /// Sets the DC scaling and returns important page rectangles
193 CalculateScaling(dc
, textRect
, headerRect
, footerRect
);
195 if (page
> 1 || m_headerFooterData
.GetShowOnFirstPage())
197 if (m_headerFooterData
.GetFont().IsOk())
198 dc
->SetFont(m_headerFooterData
.GetFont());
200 dc
->SetFont(*wxNORMAL_FONT
);
201 if (m_headerFooterData
.GetTextColour().IsOk())
202 dc
->SetTextForeground(m_headerFooterData
.GetTextColour());
204 dc
->SetTextForeground(*wxBLACK
);
205 dc
->SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT
);
207 // Draw header, if any
208 wxRichTextOddEvenPage oddEven
= ((page
% 2) == 1) ? wxRICHTEXT_PAGE_ODD
: wxRICHTEXT_PAGE_EVEN
;
210 wxString headerTextCentre
= m_headerFooterData
.GetHeaderText(oddEven
, wxRICHTEXT_PAGE_CENTRE
);
211 wxString headerTextLeft
= m_headerFooterData
.GetHeaderText(oddEven
, wxRICHTEXT_PAGE_LEFT
);
212 wxString headerTextRight
= m_headerFooterData
.GetHeaderText(oddEven
, wxRICHTEXT_PAGE_RIGHT
);
214 if (!headerTextLeft
.IsEmpty())
216 SubstituteKeywords(headerTextLeft
, GetTitle(), page
, m_numPages
);
219 //dc->GetTextExtent(headerTextLeft, & tx, & ty);
221 int x
= headerRect
.GetLeft();
222 int y
= headerRect
.GetX();
223 dc
->DrawText(headerTextLeft
, x
, y
);
225 if (!headerTextCentre
.IsEmpty())
227 SubstituteKeywords(headerTextCentre
, GetTitle(), page
, m_numPages
);
230 dc
->GetTextExtent(headerTextCentre
, & tx
, & ty
);
232 int x
= headerRect
.GetWidth()/2 - tx
/2 + headerRect
.GetLeft();
233 int y
= headerRect
.GetY();
234 dc
->DrawText(headerTextCentre
, x
, y
);
236 if (!headerTextRight
.IsEmpty())
238 SubstituteKeywords(headerTextRight
, GetTitle(), page
, m_numPages
);
241 dc
->GetTextExtent(headerTextRight
, & tx
, & ty
);
243 int x
= headerRect
.GetRight() - tx
;
244 int y
= headerRect
.GetY();
245 dc
->DrawText(headerTextRight
, x
, y
);
248 // Draw footer, if any
249 wxString footerTextCentre
= m_headerFooterData
.GetFooterText(oddEven
, wxRICHTEXT_PAGE_CENTRE
);
250 wxString footerTextLeft
= m_headerFooterData
.GetFooterText(oddEven
, wxRICHTEXT_PAGE_LEFT
);
251 wxString footerTextRight
= m_headerFooterData
.GetFooterText(oddEven
, wxRICHTEXT_PAGE_RIGHT
);
253 if (!footerTextLeft
.IsEmpty())
255 SubstituteKeywords(footerTextLeft
, GetTitle(), page
, m_numPages
);
258 dc
->GetTextExtent(footerTextLeft
, & tx
, & ty
);
260 int x
= footerRect
.GetLeft();
261 int y
= footerRect
.GetBottom() - ty
;
262 dc
->DrawText(footerTextLeft
, x
, y
);
264 if (!footerTextCentre
.IsEmpty())
266 SubstituteKeywords(footerTextCentre
, GetTitle(), page
, m_numPages
);
269 dc
->GetTextExtent(footerTextCentre
, & tx
, & ty
);
271 int x
= footerRect
.GetWidth()/2 - tx
/2 + footerRect
.GetLeft();
272 int y
= footerRect
.GetBottom() - ty
;
273 dc
->DrawText(footerTextCentre
, x
, y
);
275 if (!footerTextRight
.IsEmpty())
277 SubstituteKeywords(footerTextRight
, GetTitle(), page
, m_numPages
);
280 dc
->GetTextExtent(footerTextRight
, & tx
, & ty
);
282 int x
= footerRect
.GetRight() - tx
;
283 int y
= footerRect
.GetBottom() - ty
;
284 dc
->DrawText(footerTextRight
, x
, y
);
288 wxRichTextRange
rangeToDraw(m_pageBreaksStart
[page
-1], m_pageBreaksEnd
[page
-1]);
290 wxPoint oldOrigin
= dc
->GetLogicalOrigin();
291 double scaleX
, scaleY
;
292 dc
->GetUserScale(& scaleX
, & scaleY
);
296 yOffset
= m_pageYOffsets
[page
-2];
298 if (yOffset
!= oldOrigin
.y
)
299 dc
->SetLogicalOrigin(oldOrigin
.x
, oldOrigin
.y
+ yOffset
);
301 dc
->SetClippingRegion(wxRect(textRect
.x
, textRect
.y
+ yOffset
, textRect
.width
, textRect
.height
));
303 GetRichTextBuffer()->Draw(*dc
, rangeToDraw
, wxRichTextSelection(), textRect
, 0 /* descent */, wxRICHTEXT_DRAW_IGNORE_CACHE
|wxRICHTEXT_DRAW_PRINT
/* flags */);
305 dc
->DestroyClippingRegion();
307 if (yOffset
!= oldOrigin
.y
)
308 dc
->SetLogicalOrigin(oldOrigin
.x
, oldOrigin
.y
);
311 void wxRichTextPrintout::SetMargins(int top
, int bottom
, int left
, int right
)
314 m_marginBottom
= bottom
;
316 m_marginRight
= right
;
319 /// Calculate scaling and rectangles, setting the device context scaling
320 void wxRichTextPrintout::CalculateScaling(wxDC
* dc
, wxRect
& textRect
, wxRect
& headerRect
, wxRect
& footerRect
)
322 // Get the logical pixels per inch of screen and printer
323 int ppiScreenX
, ppiScreenY
;
324 GetPPIScreen(&ppiScreenX
, &ppiScreenY
);
325 int ppiPrinterX
, ppiPrinterY
;
326 GetPPIPrinter(&ppiPrinterX
, &ppiPrinterY
);
328 // This scales the DC so that the printout roughly represents the
329 // the screen scaling.
330 float scale
= (float)((float)ppiPrinterX
/(float)ppiScreenX
);
332 // Now we have to check in case our real page size is reduced
333 // (e.g. because we're drawing to a print preview memory DC)
334 int pageWidth
, pageHeight
;
337 GetPageSizePixels(&pageWidth
, &pageHeight
);
339 // If printer pageWidth == current DC width, then this doesn't
340 // change. But w might be the preview bitmap width, so scale down.
341 float previewScale
= (float)(w
/(float)pageWidth
);
342 float overallScale
= scale
* previewScale
;
344 // The dimensions used for indentation etc. have to be unscaled
345 // during printing to be correct when scaling is applied.
347 m_richTextBuffer
->SetScale(scale
);
350 int marginLeft
= wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX
, m_marginLeft
);
351 int marginTop
= wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX
, m_marginTop
);
352 int marginRight
= wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX
, m_marginRight
);
353 int marginBottom
= wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX
, m_marginBottom
);
355 // Header and footer margins
356 int headerMargin
= wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX
, m_headerFooterData
.GetHeaderMargin());
357 int footerMargin
= wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX
, m_headerFooterData
.GetFooterMargin());
359 dc
->SetUserScale(overallScale
, overallScale
);
361 wxRect
rect((int) (marginLeft
/scale
), (int) (marginTop
/scale
),
362 (int) ((pageWidth
- marginLeft
- marginRight
)/scale
), (int)((pageHeight
- marginTop
- marginBottom
)/scale
));
364 headerRect
= wxRect(0, 0, 0, 0);
366 if (!m_headerFooterData
.GetHeaderText(wxRICHTEXT_PAGE_ODD
, wxRICHTEXT_PAGE_LEFT
).IsEmpty() ||
367 !m_headerFooterData
.GetHeaderText(wxRICHTEXT_PAGE_ODD
, wxRICHTEXT_PAGE_CENTRE
).IsEmpty() ||
368 !m_headerFooterData
.GetHeaderText(wxRICHTEXT_PAGE_ODD
, wxRICHTEXT_PAGE_RIGHT
).IsEmpty() ||
370 !m_headerFooterData
.GetHeaderText(wxRICHTEXT_PAGE_EVEN
, wxRICHTEXT_PAGE_LEFT
).IsEmpty() ||
371 !m_headerFooterData
.GetHeaderText(wxRICHTEXT_PAGE_EVEN
, wxRICHTEXT_PAGE_CENTRE
).IsEmpty() ||
372 !m_headerFooterData
.GetHeaderText(wxRICHTEXT_PAGE_EVEN
, wxRICHTEXT_PAGE_RIGHT
).IsEmpty())
374 if (m_headerFooterData
.GetFont().IsOk())
375 dc
->SetFont(m_headerFooterData
.GetFont());
377 dc
->SetFont(*wxNORMAL_FONT
);
379 int charHeight
= dc
->GetCharHeight();
381 int headerHeight
= (int) (charHeight
+ headerMargin
/scale
);
383 headerRect
= wxRect(rect
.x
, rect
.y
, rect
.width
, headerHeight
);
385 rect
.y
+= headerHeight
;
386 rect
.height
-= headerHeight
;
389 footerRect
= wxRect(0, 0, 0, 0);
391 if (!m_headerFooterData
.GetFooterText(wxRICHTEXT_PAGE_ODD
, wxRICHTEXT_PAGE_LEFT
).IsEmpty() ||
392 !m_headerFooterData
.GetFooterText(wxRICHTEXT_PAGE_ODD
, wxRICHTEXT_PAGE_CENTRE
).IsEmpty() ||
393 !m_headerFooterData
.GetFooterText(wxRICHTEXT_PAGE_ODD
, wxRICHTEXT_PAGE_RIGHT
).IsEmpty() ||
395 !m_headerFooterData
.GetFooterText(wxRICHTEXT_PAGE_EVEN
, wxRICHTEXT_PAGE_LEFT
).IsEmpty() ||
396 !m_headerFooterData
.GetFooterText(wxRICHTEXT_PAGE_EVEN
, wxRICHTEXT_PAGE_CENTRE
).IsEmpty() ||
397 !m_headerFooterData
.GetFooterText(wxRICHTEXT_PAGE_EVEN
, wxRICHTEXT_PAGE_RIGHT
).IsEmpty())
399 if (m_headerFooterData
.GetFont().IsOk())
400 dc
->SetFont(m_headerFooterData
.GetFont());
402 dc
->SetFont(*wxNORMAL_FONT
);
404 int charHeight
= dc
->GetCharHeight();
406 int footerHeight
= (int) (charHeight
+ footerMargin
/scale
);
408 footerRect
= wxRect(rect
.x
, rect
.y
+ rect
.height
, rect
.width
, footerHeight
);
410 rect
.height
-= footerHeight
;
416 bool wxRichTextPrintout::SubstituteKeywords(wxString
& str
, const wxString
& title
, int pageNum
, int pageCount
)
420 num
.Printf(wxT("%i"), pageNum
);
421 str
.Replace(wxT("@PAGENUM@"), num
);
423 num
.Printf(wxT("%lu"), (unsigned long) pageCount
);
424 str
.Replace(wxT("@PAGESCNT@"), num
);
426 wxDateTime now
= wxDateTime::Now();
428 str
.Replace(wxT("@DATE@"), now
.FormatDate());
429 str
.Replace(wxT("@TIME@"), now
.FormatTime());
431 str
.Replace(wxT("@TITLE@"), title
);
440 wxRichTextPrinting::wxRichTextPrinting(const wxString
& name
, wxWindow
*parentWindow
)
442 m_richTextBufferPrinting
= NULL
;
443 m_richTextBufferPreview
= NULL
;
445 m_parentWindow
= parentWindow
;
449 m_previewRect
= wxRect(wxPoint(100, 100), wxSize(800, 800));
451 m_pageSetupData
= new wxPageSetupDialogData
;
452 m_pageSetupData
->EnableMargins(true);
453 m_pageSetupData
->SetMarginTopLeft(wxPoint(25, 25));
454 m_pageSetupData
->SetMarginBottomRight(wxPoint(25, 25));
457 wxRichTextPrinting::~wxRichTextPrinting()
460 delete m_pageSetupData
;
461 delete m_richTextBufferPrinting
;
462 delete m_richTextBufferPreview
;
465 wxPrintData
*wxRichTextPrinting::GetPrintData()
467 if (m_printData
== NULL
)
468 m_printData
= new wxPrintData();
472 /// Set print and page setup data
473 void wxRichTextPrinting::SetPrintData(const wxPrintData
& printData
)
475 (*GetPrintData()) = printData
;
478 void wxRichTextPrinting::SetPageSetupData(const wxPageSetupData
& pageSetupData
)
480 (*GetPageSetupData()) = pageSetupData
;
483 /// Set the rich text buffer pointer, deleting the existing object if present
484 void wxRichTextPrinting::SetRichTextBufferPrinting(wxRichTextBuffer
* buf
)
486 if (m_richTextBufferPrinting
)
488 delete m_richTextBufferPrinting
;
489 m_richTextBufferPrinting
= NULL
;
491 m_richTextBufferPrinting
= buf
;
494 void wxRichTextPrinting::SetRichTextBufferPreview(wxRichTextBuffer
* buf
)
496 if (m_richTextBufferPreview
)
498 delete m_richTextBufferPreview
;
499 m_richTextBufferPreview
= NULL
;
501 m_richTextBufferPreview
= buf
;
504 bool wxRichTextPrinting::PreviewFile(const wxString
& richTextFile
)
506 SetRichTextBufferPreview(new wxRichTextBuffer
);
508 if (!m_richTextBufferPreview
->LoadFile(richTextFile
))
510 SetRichTextBufferPreview(NULL
);
514 SetRichTextBufferPrinting(new wxRichTextBuffer(*m_richTextBufferPreview
));
516 wxRichTextPrintout
*p1
= CreatePrintout();
517 p1
->SetRichTextBuffer(m_richTextBufferPreview
);
519 wxRichTextPrintout
*p2
= CreatePrintout();
520 p2
->SetRichTextBuffer(m_richTextBufferPrinting
);
521 return DoPreview(p1
, p2
);
524 bool wxRichTextPrinting::PreviewBuffer(const wxRichTextBuffer
& buffer
)
526 SetRichTextBufferPreview(new wxRichTextBuffer(buffer
));
527 SetRichTextBufferPrinting(new wxRichTextBuffer(buffer
));
529 wxRichTextPrintout
*p1
= CreatePrintout();
530 p1
->SetRichTextBuffer(m_richTextBufferPreview
);
532 wxRichTextPrintout
*p2
= CreatePrintout();
533 p2
->SetRichTextBuffer(m_richTextBufferPrinting
);
535 return DoPreview(p1
, p2
);
538 bool wxRichTextPrinting::PrintFile(const wxString
& richTextFile
)
540 SetRichTextBufferPrinting(new wxRichTextBuffer
);
542 if (!m_richTextBufferPrinting
->LoadFile(richTextFile
))
544 SetRichTextBufferPrinting(NULL
);
548 wxRichTextPrintout
*p
= CreatePrintout();
549 p
->SetRichTextBuffer(m_richTextBufferPrinting
);
551 bool ret
= DoPrint(p
);
556 bool wxRichTextPrinting::PrintBuffer(const wxRichTextBuffer
& buffer
)
558 SetRichTextBufferPrinting(new wxRichTextBuffer(buffer
));
560 wxRichTextPrintout
*p
= CreatePrintout();
561 p
->SetRichTextBuffer(m_richTextBufferPrinting
);
563 bool ret
= DoPrint(p
);
568 bool wxRichTextPrinting::DoPreview(wxRichTextPrintout
*printout1
, wxRichTextPrintout
*printout2
)
570 // Pass two printout objects: for preview, and possible printing.
571 wxPrintDialogData
printDialogData(*GetPrintData());
572 wxPrintPreview
*preview
= new wxPrintPreview(printout1
, printout2
, &printDialogData
);
573 if (!preview
->IsOk())
579 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, m_parentWindow
,
580 m_title
+ _(" Preview"),
581 m_previewRect
.GetPosition(), m_previewRect
.GetSize());
582 frame
->Centre(wxBOTH
);
588 bool wxRichTextPrinting::DoPrint(wxRichTextPrintout
*printout
)
590 wxPrintDialogData
printDialogData(*GetPrintData());
591 wxPrinter
printer(&printDialogData
);
593 if (!printer
.Print(m_parentWindow
, printout
, true))
598 (*GetPrintData()) = printer
.GetPrintDialogData().GetPrintData();
602 void wxRichTextPrinting::PageSetup()
604 if (!GetPrintData()->IsOk())
606 wxLogError(_("There was a problem during page setup: you may need to set a default printer."));
610 m_pageSetupData
->SetPrintData(*GetPrintData());
611 wxPageSetupDialog
pageSetupDialog(m_parentWindow
, m_pageSetupData
);
613 if (pageSetupDialog
.ShowModal() == wxID_OK
)
615 (*GetPrintData()) = pageSetupDialog
.GetPageSetupData().GetPrintData();
616 (*m_pageSetupData
) = pageSetupDialog
.GetPageSetupData();
620 wxRichTextPrintout
*wxRichTextPrinting::CreatePrintout()
622 wxRichTextPrintout
*p
= new wxRichTextPrintout(m_title
);
624 p
->SetHeaderFooterData(GetHeaderFooterData());
625 p
->SetMargins(10*m_pageSetupData
->GetMarginTopLeft().y
,
626 10*m_pageSetupData
->GetMarginBottomRight().y
,
627 10*m_pageSetupData
->GetMarginTopLeft().x
,
628 10*m_pageSetupData
->GetMarginBottomRight().x
);
633 /// Set/get header text, e.g. wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT
634 void wxRichTextPrinting::SetHeaderText(const wxString
& text
, wxRichTextOddEvenPage page
, wxRichTextPageLocation location
)
636 m_headerFooterData
.SetHeaderText(text
, page
, location
);
639 wxString
wxRichTextPrinting::GetHeaderText(wxRichTextOddEvenPage page
, wxRichTextPageLocation location
) const
641 return m_headerFooterData
.GetHeaderText(page
, location
);
644 /// Set/get footer text, e.g. wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT
645 void wxRichTextPrinting::SetFooterText(const wxString
& text
, wxRichTextOddEvenPage page
, wxRichTextPageLocation location
)
647 m_headerFooterData
.SetFooterText(text
, page
, location
);
650 wxString
wxRichTextPrinting::GetFooterText(wxRichTextOddEvenPage page
, wxRichTextPageLocation location
) const
652 return m_headerFooterData
.GetFooterText(page
, location
);
659 IMPLEMENT_CLASS(wxRichTextHeaderFooterData
, wxObject
)
662 void wxRichTextHeaderFooterData::Copy(const wxRichTextHeaderFooterData
& data
)
665 for (i
= 0; i
< 12; i
++)
666 m_text
[i
] = data
.m_text
[i
];
667 m_font
= data
.m_font
;
668 m_colour
= data
.m_colour
;
669 m_headerMargin
= data
.m_headerMargin
;
670 m_footerMargin
= data
.m_footerMargin
;
671 m_showOnFirstPage
= data
.m_showOnFirstPage
;
675 void wxRichTextHeaderFooterData::SetText(const wxString
& text
, int headerFooter
, wxRichTextOddEvenPage page
, wxRichTextPageLocation location
)
677 int idx
= headerFooter
+ (2 * (int) page
) + (4 * (int) location
);
678 wxASSERT( idx
>= 0 && idx
< 12 );
680 if (idx
>= 0 && idx
< 12)
684 wxString
wxRichTextHeaderFooterData::GetText(int headerFooter
, wxRichTextOddEvenPage page
, wxRichTextPageLocation location
) const
686 int idx
= headerFooter
+ (2 * (int) page
) + (4 * (int) location
);
687 wxASSERT( idx
>= 0 && idx
< 12 );
689 if (idx
>= 0 && idx
< 12)
692 return wxEmptyString
;
695 /// Set/get header text, e.g. wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT
696 void wxRichTextHeaderFooterData::SetHeaderText(const wxString
& text
, wxRichTextOddEvenPage page
, wxRichTextPageLocation location
)
698 if (page
== wxRICHTEXT_PAGE_ALL
)
700 SetText(text
, 0, wxRICHTEXT_PAGE_ODD
, location
);
701 SetText(text
, 0, wxRICHTEXT_PAGE_EVEN
, location
);
704 SetText(text
, 0, page
, location
);
707 wxString
wxRichTextHeaderFooterData::GetHeaderText(wxRichTextOddEvenPage page
, wxRichTextPageLocation location
) const
709 return GetText(0, page
, location
);
712 /// Set/get footer text, e.g. wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT
713 void wxRichTextHeaderFooterData::SetFooterText(const wxString
& text
, wxRichTextOddEvenPage page
, wxRichTextPageLocation location
)
715 if (page
== wxRICHTEXT_PAGE_ALL
)
717 SetText(text
, 1, wxRICHTEXT_PAGE_ODD
, location
);
718 SetText(text
, 1, wxRICHTEXT_PAGE_EVEN
, location
);
721 SetText(text
, 1, page
, location
);
724 wxString
wxRichTextHeaderFooterData::GetFooterText(wxRichTextOddEvenPage page
, wxRichTextPageLocation location
) const
726 return GetText(1, page
, location
);
730 void wxRichTextHeaderFooterData::Clear()
733 for (i
= 0; i
< 12; i
++)
734 m_text
[i
] = wxEmptyString
;
737 #endif // wxUSE_RICHTEXT & wxUSE_PRINTING_ARCHITECTURE