NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
NumeRePrintout.cpp
Go to the documentation of this file.
1#include "NumeRePrintout.h"
2#include "editor.h"
3#include "wx/printdlg.h" // wxPageSetupDialog
4#include "wx/progdlg.h" // wxProgressDialog
5#include "../../common/Options.h"
6
7extern wxPrintData *g_printData;
8extern wxPageSetupData *g_pageSetupData;
9
10NumeRePrintout::NumeRePrintout (NumeReEditor *edit, Options* options, const wxString& title)
11: wxPrintout(title) {
12 m_edit = edit;
13 m_printed = 0;
14 m_options = options;
15
16}
17
29
30 wxDC *dc = GetDC();
31 if (!dc) return false;
32
33 // scale DC
34 PrintScaling (dc);
35
36 // print page
37 if (page == 1) m_printed = 0;
38 m_printed = m_edit->FormatRange (1,
39 //(int(m_pages.GetCount()) > page) ? m_pages[page - 1] : 0,
40 //m_edit->GetLength(),
41 m_pages[page-1],
42 (int(m_pages.GetCount()) > page) ? m_pages[page] : m_edit->GetLength(),
43 dc, dc, m_printRect, m_pageRect);
44
45 return true;
46}
47
59bool NumeRePrintout::OnBeginDocument (int startPage, int endPage) {
60
61 m_printed = 0;
62
63
65 {
66 // Hide line numbers until after printing is finished
67 m_edit->SetMarginWidth(0, 0);
68 m_edit->SetMarginWidth(1, 0);
69 }
70
71
72 return wxPrintout::OnBeginDocument(startPage, endPage);
73
74
75 /*
76 if (!wxPrintout::OnBeginDocument (startPage, endPage)) {
77 return false;
78 }
79
80 return true;
81 */
82}
83
97void NumeRePrintout::GetPageInfo (int *minPage, int *maxPage, int *selPageFrom, int *selPageTo) {
98
99 // initialize values
100 *minPage = 0;
101 *maxPage = 0;
102 *selPageFrom = 0;
103 *selPageTo = 0;
104
105 m_pages.Clear();
106
107 // scale DC if possible
108 wxDC *dc = GetDC();
109 if (!dc) return;
110 PrintScaling (dc);
111
112 // get print page informations and convert to printer pixels
113 wxSize ppiScr;
114 GetPPIScreen (&ppiScr.x, &ppiScr.y);
115 wxSize page = g_pageSetupData->GetPaperSize();
116 page.x = static_cast<int> (page.x * ppiScr.x / 25.4);
117 page.y = static_cast<int> (page.y * ppiScr.y / 25.4);
118 m_pageRect = wxRect (0,
119 0,
120 page.x,
121 page.y);
122
123 // get margins informations and convert to printer pixels
124 int top = 25; // default 25
125 int bottom = 25; // default 25
126 int left = 20; // default 20
127 int right = 20; // default 20
128 wxPoint (top, left) = g_pageSetupData->GetMarginTopLeft();
129 wxPoint (bottom, right) = g_pageSetupData->GetMarginBottomRight();
130 top = static_cast<int> (top * ppiScr.y / 25.4);
131 bottom = static_cast<int> (bottom * ppiScr.y / 25.4);
132 left = static_cast<int> (left * ppiScr.x / 25.4);
133 right = static_cast<int> (right * ppiScr.x / 25.4);
134 m_printRect = wxRect (left,
135 top,
136 page.x - (left + right),
137 page.y - (top + bottom));
138
139 int length = m_edit->GetLength();
140 // count pages
141 //while (HasPage (*maxPage)) {
142 while(m_printed < length)
143 {
144 m_pages.Add(m_printed);
145 m_printed = m_edit->FormatRange (0, m_printed, length,
146 dc, dc, m_printRect, m_pageRect);
147 *maxPage += 1;
148
149 }
150 if (*maxPage > 0) *minPage = 1;
151 *selPageFrom = *minPage;
152 *selPageTo = *maxPage;
153}
154
165bool NumeRePrintout::HasPage (int page) {
166
167 //return (m_printed < m_edit->GetLength());
168 return (page > 0) && (page-1 < int(m_pages.GetCount())); // pages start at 1
169}
170
182
183 // check for dc, return if none
184 if (!dc) return false;
185
186 // get printer and screen sizing values
187 wxSize ppiScr;
188 GetPPIScreen (&ppiScr.x, &ppiScr.y);
189 if (ppiScr.x == 0) { // most possible guess 96 dpi
190 ppiScr.x = 96;
191 ppiScr.y = 96;
192 }
193 wxSize ppiPrt;
194 GetPPIPrinter (&ppiPrt.x, &ppiPrt.y);
195 if (ppiPrt.x == 0) { // scaling factor to 1
196 ppiPrt.x = ppiScr.x;
197 ppiPrt.y = ppiScr.y;
198 }
199 wxSize dcSize = dc->GetSize();
200 wxSize pageSize;
201 GetPageSizePixels (&pageSize.x, &pageSize.y);
202
203 // set user scale
204 float scale_x = (float)(ppiPrt.x * dcSize.x) /
205 (float)(ppiScr.x * pageSize.x);
206 float scale_y = (float)(ppiPrt.y * dcSize.y) /
207 (float)(ppiScr.y * pageSize.y);
208 dc->SetUserScale (scale_x, scale_y);
209
210 return true;
211}
212
214{
215 // Display line numbers now that printing's done. If they were already displayed? No problem.
216 m_edit->SetMarginWidth(0, 40);
217 m_edit->SetMarginWidth(1, 16);
218
219 wxPrintout::OnEndDocument();
220}
221
wxPageSetupData * g_pageSetupData
wxPrintData * g_printData
global print data, to remember settings during the session
The class of the editor window.
Definition: editor.h:53
bool OnPrintPage(int page)
event handlers
bool OnBeginDocument(int startPage, int endPage)
void GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo)
wxArrayInt m_pages
NumeReEditor * m_edit
bool PrintScaling(wxDC *dc)
Options * m_options
NumeRePrintout(NumeReEditor *edit, Options *options, const wxString &title="")
constructor
bool HasPage(int page)
print functions
This class implements an interface of the internal Settings object adapted to be usable from the GUI.
Definition: Options.h:178
bool GetLineNumberPrinting() const
Definition: Options.h:243