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 // Only if we're not at the start of the document, and
101 // even then, only if either it's a hard break or if the object
102 // can fit in a whole page (otherwise there's no point in making
103 // the rest of this page blank).
104 if (lastLine
&& (hasHardPageBreak
|| (line
->GetSize().y
<= rect
.GetHeight())))
106 // New page starting at this line
109 // We increase the offset by the difference between new and old positions
111 int increaseOffsetBy
= lineY
- newY
;
112 yOffset
+= increaseOffsetBy
;
114 m_pageBreaksStart
.Add(lastStartPos
);
115 m_pageBreaksEnd
.Add(lastLine
->GetAbsoluteRange().GetEnd());
116 m_pageYOffsets
.Add(yOffset
);
118 lastStartPos
= line
->GetAbsoluteRange().GetStart();
124 // Now create page breaks for the rest of the line, if it's larger than the page height
125 int contentLeft
= line
->GetSize().y
- rect
.GetHeight();
126 while (contentLeft
>= 0)
128 yOffset
+= rect
.GetHeight();
129 contentLeft
-= rect
.GetHeight();
131 m_pageBreaksStart
.Add(lastStartPos
);
132 m_pageBreaksEnd
.Add(lastLine
->GetAbsoluteRange().GetEnd());
133 m_pageYOffsets
.Add(yOffset
);
141 node2
= node2
->GetNext();
145 node
= node
->GetNext();
148 // Closing page break
149 m_pageBreaksStart
.Add(lastStartPos
);
150 m_pageBreaksEnd
.Add(GetRichTextBuffer()->GetOwnRange().GetEnd());
151 m_pageYOffsets
.Add(yOffset
);
155 bool wxRichTextPrintout::OnBeginDocument(int startPage
, int endPage
)
157 if (!wxPrintout::OnBeginDocument(startPage
, endPage
)) return false;
162 bool wxRichTextPrintout::OnPrintPage(int page
)
168 RenderPage(dc
, page
);
174 void wxRichTextPrintout::GetPageInfo(int *minPage
, int *maxPage
, int *selPageFrom
, int *selPageTo
)
177 *maxPage
= m_numPages
;
179 *selPageTo
= m_numPages
;
182 bool wxRichTextPrintout::HasPage(int pageNum
)
184 return pageNum
> 0 && pageNum
<= m_numPages
;
187 void wxRichTextPrintout::RenderPage(wxDC
*dc
, int page
)
189 if (!GetRichTextBuffer())
194 wxRect textRect
, headerRect
, footerRect
;
196 /// Sets the DC scaling and returns important page rectangles
197 CalculateScaling(dc
, textRect
, headerRect
, footerRect
);
199 if (page
> 1 || m_headerFooterData
.GetShowOnFirstPage())
201 if (m_headerFooterData
.GetFont().IsOk())
202 dc
->SetFont(m_headerFooterData
.GetFont());
204 dc
->SetFont(*wxNORMAL_FONT
);
205 if (m_headerFooterData
.GetTextColour().IsOk())
206 dc
->SetTextForeground(m_headerFooterData
.GetTextColour());
208 dc
->SetTextForeground(*wxBLACK
);
209 dc
->SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT
);
211 // Draw header, if any
212 wxRichTextOddEvenPage oddEven
= ((page
% 2) == 1) ? wxRICHTEXT_PAGE_ODD
: wxRICHTEXT_PAGE_EVEN
;
214 wxString headerTextCentre
= m_headerFooterData
.GetHeaderText(oddEven
, wxRICHTEXT_PAGE_CENTRE
);
215 wxString headerTextLeft
= m_headerFooterData
.GetHeaderText(oddEven
, wxRICHTEXT_PAGE_LEFT
);
216 wxString headerTextRight
= m_headerFooterData
.GetHeaderText(oddEven
, wxRICHTEXT_PAGE_RIGHT
);
218 if (!headerTextLeft
.IsEmpty())
220 SubstituteKeywords(headerTextLeft
, GetTitle(), page
, m_numPages
);
223 //dc->GetTextExtent(headerTextLeft, & tx, & ty);
225 int x
= headerRect
.GetLeft();
226 int y
= headerRect
.GetX();
227 dc
->DrawText(headerTextLeft
, x
, y
);
229 if (!headerTextCentre
.IsEmpty())
231 SubstituteKeywords(headerTextCentre
, GetTitle(), page
, m_numPages
);
234 dc
->GetTextExtent(headerTextCentre
, & tx
, & ty
);
236 int x
= headerRect
.GetWidth()/2 - tx
/2 + headerRect
.GetLeft();
237 int y
= headerRect
.GetY();
238 dc
->DrawText(headerTextCentre
, x
, y
);
240 if (!headerTextRight
.IsEmpty())
242 SubstituteKeywords(headerTextRight
, GetTitle(), page
, m_numPages
);
245 dc
->GetTextExtent(headerTextRight
, & tx
, & ty
);
247 int x
= headerRect
.GetRight() - tx
;
248 int y
= headerRect
.GetY();
249 dc
->DrawText(headerTextRight
, x
, y
);
252 // Draw footer, if any
253 wxString footerTextCentre
= m_headerFooterData
.GetFooterText(oddEven
, wxRICHTEXT_PAGE_CENTRE
);
254 wxString footerTextLeft
= m_headerFooterData
.GetFooterText(oddEven
, wxRICHTEXT_PAGE_LEFT
);
255 wxString footerTextRight
= m_headerFooterData
.GetFooterText(oddEven
, wxRICHTEXT_PAGE_RIGHT
);
257 if (!footerTextLeft
.IsEmpty())
259 SubstituteKeywords(footerTextLeft
, GetTitle(), page
, m_numPages
);
262 dc
->GetTextExtent(footerTextLeft
, & tx
, & ty
);
264 int x
= footerRect
.GetLeft();
265 int y
= footerRect
.GetBottom() - ty
;
266 dc
->DrawText(footerTextLeft
, x
, y
);
268 if (!footerTextCentre
.IsEmpty())
270 SubstituteKeywords(footerTextCentre
, GetTitle(), page
, m_numPages
);
273 dc
->GetTextExtent(footerTextCentre
, & tx
, & ty
);
275 int x
= footerRect
.GetWidth()/2 - tx
/2 + footerRect
.GetLeft();
276 int y
= footerRect
.GetBottom() - ty
;
277 dc
->DrawText(footerTextCentre
, x
, y
);
279 if (!footerTextRight
.IsEmpty())
281 SubstituteKeywords(footerTextRight
, GetTitle(), page
, m_numPages
);
284 dc
->GetTextExtent(footerTextRight
, & tx
, & ty
);
286 int x
= footerRect
.GetRight() - tx
;
287 int y
= footerRect
.GetBottom() - ty
;
288 dc
->DrawText(footerTextRight
, x
, y
);
292 wxRichTextRange
rangeToDraw(m_pageBreaksStart
[page
-1], m_pageBreaksEnd
[page
-1]);
294 wxPoint oldOrigin
= dc
->GetLogicalOrigin();
295 double scaleX
, scaleY
;
296 dc
->GetUserScale(& scaleX
, & scaleY
);
300 yOffset
= m_pageYOffsets
[page
-2];
302 if (yOffset
!= oldOrigin
.y
)
303 dc
->SetLogicalOrigin(oldOrigin
.x
, oldOrigin
.y
+ yOffset
);
305 dc
->SetClippingRegion(wxRect(textRect
.x
, textRect
.y
+ yOffset
, textRect
.width
, textRect
.height
));
307 wxRichTextDrawingContext
context(GetRichTextBuffer());
308 GetRichTextBuffer()->Draw(*dc
, context
, rangeToDraw
, wxRichTextSelection(), textRect
, 0 /* descent */, wxRICHTEXT_DRAW_IGNORE_CACHE
|wxRICHTEXT_DRAW_PRINT
/* flags */);
310 dc
->DestroyClippingRegion();
312 if (yOffset
!= oldOrigin
.y
)
313 dc
->SetLogicalOrigin(oldOrigin
.x
, oldOrigin
.y
);
316 void wxRichTextPrintout::SetMargins(int top
, int bottom
, int left
, int right
)
319 m_marginBottom
= bottom
;
321 m_marginRight
= right
;
324 /// Calculate scaling and rectangles, setting the device context scaling
325 void wxRichTextPrintout::CalculateScaling(wxDC
* dc
, wxRect
& textRect
, wxRect
& headerRect
, wxRect
& footerRect
)
327 // Get the logical pixels per inch of screen and printer
328 int ppiScreenX
, ppiScreenY
;
329 GetPPIScreen(&ppiScreenX
, &ppiScreenY
);
330 int ppiPrinterX
, ppiPrinterY
;
331 GetPPIPrinter(&ppiPrinterX
, &ppiPrinterY
);
333 // This scales the DC so that the printout roughly represents the
334 // the screen scaling.
335 float scale
= (float)((float)ppiPrinterX
/(float)ppiScreenX
);
337 // Now we have to check in case our real page size is reduced
338 // (e.g. because we're drawing to a print preview memory DC)
339 int pageWidth
, pageHeight
;
342 GetPageSizePixels(&pageWidth
, &pageHeight
);
344 // If printer pageWidth == current DC width, then this doesn't
345 // change. But w might be the preview bitmap width, so scale down.
346 float previewScale
= (float)(w
/(float)pageWidth
);
347 float overallScale
= scale
* previewScale
;
349 // The dimensions used for indentation etc. have to be unscaled
350 // during printing to be correct when scaling is applied.
351 // Also, correct the conversions in wxRTC using DC instead of print DC.
352 m_richTextBuffer
->SetScale(scale
* float(dc
->GetPPI().x
)/float(ppiPrinterX
));
355 int marginLeft
= wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX
, m_marginLeft
);
356 int marginTop
= wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX
, m_marginTop
);
357 int marginRight
= wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX
, m_marginRight
);
358 int marginBottom
= wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX
, m_marginBottom
);
360 // Header and footer margins
361 int headerMargin
= wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX
, m_headerFooterData
.GetHeaderMargin());
362 int footerMargin
= wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX
, m_headerFooterData
.GetFooterMargin());
364 dc
->SetUserScale(overallScale
, overallScale
);
366 wxRect
rect((int) (marginLeft
/scale
), (int) (marginTop
/scale
),
367 (int) ((pageWidth
- marginLeft
- marginRight
)/scale
), (int)((pageHeight
- marginTop
- marginBottom
)/scale
));
369 headerRect
= wxRect(0, 0, 0, 0);
371 if (!m_headerFooterData
.GetHeaderText(wxRICHTEXT_PAGE_ODD
, wxRICHTEXT_PAGE_LEFT
).IsEmpty() ||
372 !m_headerFooterData
.GetHeaderText(wxRICHTEXT_PAGE_ODD
, wxRICHTEXT_PAGE_CENTRE
).IsEmpty() ||
373 !m_headerFooterData
.GetHeaderText(wxRICHTEXT_PAGE_ODD
, wxRICHTEXT_PAGE_RIGHT
).IsEmpty() ||
375 !m_headerFooterData
.GetHeaderText(wxRICHTEXT_PAGE_EVEN
, wxRICHTEXT_PAGE_LEFT
).IsEmpty() ||
376 !m_headerFooterData
.GetHeaderText(wxRICHTEXT_PAGE_EVEN
, wxRICHTEXT_PAGE_CENTRE
).IsEmpty() ||
377 !m_headerFooterData
.GetHeaderText(wxRICHTEXT_PAGE_EVEN
, wxRICHTEXT_PAGE_RIGHT
).IsEmpty())
379 if (m_headerFooterData
.GetFont().IsOk())
380 dc
->SetFont(m_headerFooterData
.GetFont());
382 dc
->SetFont(*wxNORMAL_FONT
);
384 int charHeight
= dc
->GetCharHeight();
386 int headerHeight
= (int) (charHeight
+ headerMargin
/scale
);
388 headerRect
= wxRect(rect
.x
, rect
.y
, rect
.width
, headerHeight
);
390 rect
.y
+= headerHeight
;
391 rect
.height
-= headerHeight
;
394 footerRect
= wxRect(0, 0, 0, 0);
396 if (!m_headerFooterData
.GetFooterText(wxRICHTEXT_PAGE_ODD
, wxRICHTEXT_PAGE_LEFT
).IsEmpty() ||
397 !m_headerFooterData
.GetFooterText(wxRICHTEXT_PAGE_ODD
, wxRICHTEXT_PAGE_CENTRE
).IsEmpty() ||
398 !m_headerFooterData
.GetFooterText(wxRICHTEXT_PAGE_ODD
, wxRICHTEXT_PAGE_RIGHT
).IsEmpty() ||
400 !m_headerFooterData
.GetFooterText(wxRICHTEXT_PAGE_EVEN
, wxRICHTEXT_PAGE_LEFT
).IsEmpty() ||
401 !m_headerFooterData
.GetFooterText(wxRICHTEXT_PAGE_EVEN
, wxRICHTEXT_PAGE_CENTRE
).IsEmpty() ||
402 !m_headerFooterData
.GetFooterText(wxRICHTEXT_PAGE_EVEN
, wxRICHTEXT_PAGE_RIGHT
).IsEmpty())
404 if (m_headerFooterData
.GetFont().IsOk())
405 dc
->SetFont(m_headerFooterData
.GetFont());
407 dc
->SetFont(*wxNORMAL_FONT
);
409 int charHeight
= dc
->GetCharHeight();
411 int footerHeight
= (int) (charHeight
+ footerMargin
/scale
);
413 footerRect
= wxRect(rect
.x
, rect
.y
+ rect
.height
, rect
.width
, footerHeight
);
415 rect
.height
-= footerHeight
;
421 bool wxRichTextPrintout::SubstituteKeywords(wxString
& str
, const wxString
& title
, int pageNum
, int pageCount
)
425 num
.Printf(wxT("%i"), pageNum
);
426 str
.Replace(wxT("@PAGENUM@"), num
);
428 num
.Printf(wxT("%lu"), (unsigned long) pageCount
);
429 str
.Replace(wxT("@PAGESCNT@"), num
);
431 wxDateTime now
= wxDateTime::Now();
433 str
.Replace(wxT("@DATE@"), now
.FormatDate());
434 str
.Replace(wxT("@TIME@"), now
.FormatTime());
436 str
.Replace(wxT("@TITLE@"), title
);
445 wxRichTextPrinting::wxRichTextPrinting(const wxString
& name
, wxWindow
*parentWindow
)
447 m_richTextBufferPrinting
= NULL
;
448 m_richTextBufferPreview
= NULL
;
450 m_parentWindow
= parentWindow
;
454 m_previewRect
= wxRect(wxPoint(100, 100), wxSize(800, 800));
456 m_pageSetupData
= new wxPageSetupDialogData
;
457 m_pageSetupData
->EnableMargins(true);
458 m_pageSetupData
->SetMarginTopLeft(wxPoint(25, 25));
459 m_pageSetupData
->SetMarginBottomRight(wxPoint(25, 25));
462 wxRichTextPrinting::~wxRichTextPrinting()
465 delete m_pageSetupData
;
466 delete m_richTextBufferPrinting
;
467 delete m_richTextBufferPreview
;
470 wxPrintData
*wxRichTextPrinting::GetPrintData()
472 if (m_printData
== NULL
)
473 m_printData
= new wxPrintData();
477 /// Set print and page setup data
478 void wxRichTextPrinting::SetPrintData(const wxPrintData
& printData
)
480 (*GetPrintData()) = printData
;
483 void wxRichTextPrinting::SetPageSetupData(const wxPageSetupDialogData
& pageSetupData
)
485 (*GetPageSetupData()) = pageSetupData
;
488 /// Set the rich text buffer pointer, deleting the existing object if present
489 void wxRichTextPrinting::SetRichTextBufferPrinting(wxRichTextBuffer
* buf
)
491 if (m_richTextBufferPrinting
)
493 delete m_richTextBufferPrinting
;
494 m_richTextBufferPrinting
= NULL
;
496 m_richTextBufferPrinting
= buf
;
499 void wxRichTextPrinting::SetRichTextBufferPreview(wxRichTextBuffer
* buf
)
501 if (m_richTextBufferPreview
)
503 delete m_richTextBufferPreview
;
504 m_richTextBufferPreview
= NULL
;
506 m_richTextBufferPreview
= buf
;
509 #if wxUSE_FFILE && wxUSE_STREAMS
510 bool wxRichTextPrinting::PreviewFile(const wxString
& richTextFile
)
512 SetRichTextBufferPreview(new wxRichTextBuffer
);
514 if (!m_richTextBufferPreview
->LoadFile(richTextFile
))
516 SetRichTextBufferPreview(NULL
);
520 SetRichTextBufferPrinting(new wxRichTextBuffer(*m_richTextBufferPreview
));
522 wxRichTextPrintout
*p1
= CreatePrintout();
523 p1
->SetRichTextBuffer(m_richTextBufferPreview
);
525 wxRichTextPrintout
*p2
= CreatePrintout();
526 p2
->SetRichTextBuffer(m_richTextBufferPrinting
);
527 return DoPreview(p1
, p2
);
529 #endif // wxUSE_FFILE && wxUSE_STREAMS
531 bool wxRichTextPrinting::PreviewBuffer(const wxRichTextBuffer
& buffer
)
533 SetRichTextBufferPreview(new wxRichTextBuffer(buffer
));
534 SetRichTextBufferPrinting(new wxRichTextBuffer(buffer
));
536 wxRichTextPrintout
*p1
= CreatePrintout();
537 p1
->SetRichTextBuffer(m_richTextBufferPreview
);
539 wxRichTextPrintout
*p2
= CreatePrintout();
540 p2
->SetRichTextBuffer(m_richTextBufferPrinting
);
542 return DoPreview(p1
, p2
);
545 #if wxUSE_FFILE && wxUSE_STREAMS
546 bool wxRichTextPrinting::PrintFile(const wxString
& richTextFile
, bool showPrintDialog
)
548 SetRichTextBufferPrinting(new wxRichTextBuffer
);
550 if (!m_richTextBufferPrinting
->LoadFile(richTextFile
))
552 SetRichTextBufferPrinting(NULL
);
556 wxRichTextPrintout
*p
= CreatePrintout();
557 p
->SetRichTextBuffer(m_richTextBufferPrinting
);
559 bool ret
= DoPrint(p
, showPrintDialog
);
563 #endif // wxUSE_FFILE && wxUSE_STREAMS
565 bool wxRichTextPrinting::PrintBuffer(const wxRichTextBuffer
& buffer
, bool showPrintDialog
)
567 SetRichTextBufferPrinting(new wxRichTextBuffer(buffer
));
569 wxRichTextPrintout
*p
= CreatePrintout();
570 p
->SetRichTextBuffer(m_richTextBufferPrinting
);
572 bool ret
= DoPrint(p
, showPrintDialog
);
577 bool wxRichTextPrinting::DoPreview(wxRichTextPrintout
*printout1
, wxRichTextPrintout
*printout2
)
579 // Pass two printout objects: for preview, and possible printing.
580 wxPrintDialogData
printDialogData(*GetPrintData());
581 wxPrintPreview
*preview
= new wxPrintPreview(printout1
, printout2
, &printDialogData
);
582 if (!preview
->IsOk())
588 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, m_parentWindow
,
589 m_title
+ _(" Preview"),
590 m_previewRect
.GetPosition(), m_previewRect
.GetSize());
591 frame
->Centre(wxBOTH
);
597 bool wxRichTextPrinting::DoPrint(wxRichTextPrintout
*printout
, bool showPrintDialog
)
599 wxPrintDialogData
printDialogData(*GetPrintData());
600 wxPrinter
printer(&printDialogData
);
602 if (!printer
.Print(m_parentWindow
, printout
, showPrintDialog
))
607 (*GetPrintData()) = printer
.GetPrintDialogData().GetPrintData();
611 void wxRichTextPrinting::PageSetup()
613 if (!GetPrintData()->IsOk())
615 wxLogError(_("There was a problem during page setup: you may need to set a default printer."));
619 m_pageSetupData
->SetPrintData(*GetPrintData());
620 wxPageSetupDialog
pageSetupDialog(m_parentWindow
, m_pageSetupData
);
622 if (pageSetupDialog
.ShowModal() == wxID_OK
)
624 (*GetPrintData()) = pageSetupDialog
.GetPageSetupData().GetPrintData();
625 (*m_pageSetupData
) = pageSetupDialog
.GetPageSetupData();
629 wxRichTextPrintout
*wxRichTextPrinting::CreatePrintout()
631 wxRichTextPrintout
*p
= new wxRichTextPrintout(m_title
);
633 p
->SetHeaderFooterData(GetHeaderFooterData());
634 p
->SetMargins(10*m_pageSetupData
->GetMarginTopLeft().y
,
635 10*m_pageSetupData
->GetMarginBottomRight().y
,
636 10*m_pageSetupData
->GetMarginTopLeft().x
,
637 10*m_pageSetupData
->GetMarginBottomRight().x
);
642 /// Set/get header text, e.g. wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT
643 void wxRichTextPrinting::SetHeaderText(const wxString
& text
, wxRichTextOddEvenPage page
, wxRichTextPageLocation location
)
645 m_headerFooterData
.SetHeaderText(text
, page
, location
);
648 wxString
wxRichTextPrinting::GetHeaderText(wxRichTextOddEvenPage page
, wxRichTextPageLocation location
) const
650 return m_headerFooterData
.GetHeaderText(page
, location
);
653 /// Set/get footer text, e.g. wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT
654 void wxRichTextPrinting::SetFooterText(const wxString
& text
, wxRichTextOddEvenPage page
, wxRichTextPageLocation location
)
656 m_headerFooterData
.SetFooterText(text
, page
, location
);
659 wxString
wxRichTextPrinting::GetFooterText(wxRichTextOddEvenPage page
, wxRichTextPageLocation location
) const
661 return m_headerFooterData
.GetFooterText(page
, location
);
668 IMPLEMENT_CLASS(wxRichTextHeaderFooterData
, wxObject
)
671 void wxRichTextHeaderFooterData::Copy(const wxRichTextHeaderFooterData
& data
)
674 for (i
= 0; i
< 12; i
++)
675 m_text
[i
] = data
.m_text
[i
];
676 m_font
= data
.m_font
;
677 m_colour
= data
.m_colour
;
678 m_headerMargin
= data
.m_headerMargin
;
679 m_footerMargin
= data
.m_footerMargin
;
680 m_showOnFirstPage
= data
.m_showOnFirstPage
;
684 void wxRichTextHeaderFooterData::SetText(const wxString
& text
, int headerFooter
, wxRichTextOddEvenPage page
, wxRichTextPageLocation location
)
686 int idx
= headerFooter
+ (2 * (int) page
) + (4 * (int) location
);
687 wxASSERT( idx
>= 0 && idx
< 12 );
689 if (idx
>= 0 && idx
< 12)
693 wxString
wxRichTextHeaderFooterData::GetText(int headerFooter
, wxRichTextOddEvenPage page
, wxRichTextPageLocation location
) const
695 int idx
= headerFooter
+ (2 * (int) page
) + (4 * (int) location
);
696 wxASSERT( idx
>= 0 && idx
< 12 );
698 if (idx
>= 0 && idx
< 12)
701 return wxEmptyString
;
704 /// Set/get header text, e.g. wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT
705 void wxRichTextHeaderFooterData::SetHeaderText(const wxString
& text
, wxRichTextOddEvenPage page
, wxRichTextPageLocation location
)
707 if (page
== wxRICHTEXT_PAGE_ALL
)
709 SetText(text
, 0, wxRICHTEXT_PAGE_ODD
, location
);
710 SetText(text
, 0, wxRICHTEXT_PAGE_EVEN
, location
);
713 SetText(text
, 0, page
, location
);
716 wxString
wxRichTextHeaderFooterData::GetHeaderText(wxRichTextOddEvenPage page
, wxRichTextPageLocation location
) const
718 return GetText(0, page
, location
);
721 /// Set/get footer text, e.g. wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT
722 void wxRichTextHeaderFooterData::SetFooterText(const wxString
& text
, wxRichTextOddEvenPage page
, wxRichTextPageLocation location
)
724 if (page
== wxRICHTEXT_PAGE_ALL
)
726 SetText(text
, 1, wxRICHTEXT_PAGE_ODD
, location
);
727 SetText(text
, 1, wxRICHTEXT_PAGE_EVEN
, location
);
730 SetText(text
, 1, page
, location
);
733 wxString
wxRichTextHeaderFooterData::GetFooterText(wxRichTextOddEvenPage page
, wxRichTextPageLocation location
) const
735 return GetText(1, page
, location
);
739 void wxRichTextHeaderFooterData::Clear()
742 for (i
= 0; i
< 12; i
++)
743 m_text
[i
] = wxEmptyString
;
746 #endif // wxUSE_RICHTEXT & wxUSE_PRINTING_ARCHITECTURE