36#include <wx/printdlg.h>
37#include <wx/artprov.h>
38#include <wx/stdpaths.h>
40#include <wx/listctrl.h>
41#include <wx/aui/aui.h>
43#include <wx/progdlg.h>
49#include "ocpn_frame.h"
58#include "trackprintout.h"
59#include "printtable.h"
63enum { PRINT_POSITION, PRINT_DISTANCE, PRINT_BEARING, PRINT_TIME, PRINT_SPEED };
66extern wxPrintData* g_printData;
68extern wxPageSetupData* g_pageSetupData;
70MyTrackPrintout::MyTrackPrintout(std::vector<bool> _toPrintOut,
Track* track,
72 const wxString& title)
73 :
MyPrintout(title), myTrack(track), toPrintOut(_toPrintOut) {
82 table.StartFillHeader();
85 table << (
const char*)wxString(_(
"Leg")).mb_str();
87 if (toPrintOut[PRINT_POSITION]) {
88 table << (
const char*)wxString(_(
"Position")).mb_str();
90 if (toPrintOut[PRINT_BEARING]) {
91 table << (
const char*)wxString(_(
"Course")).mb_str();
93 if (toPrintOut[PRINT_DISTANCE]) {
94 table << (
const char*)wxString(_(
"Distance")).mb_str();
96 if (toPrintOut[PRINT_TIME]) {
97 table << (
const char*)wxString(_(
"Time")).mb_str();
99 if (toPrintOut[PRINT_SPEED]) {
100 table << (
const char*)wxString(_(
"Speed")).mb_str();
103 table.StartFillWidths();
107 if (toPrintOut[PRINT_POSITION]) table << 80;
108 if (toPrintOut[PRINT_BEARING]) table << 40;
109 if (toPrintOut[PRINT_DISTANCE]) table << 40;
110 if (toPrintOut[PRINT_TIME]) table << 60;
111 if (toPrintOut[PRINT_SPEED]) table << 40;
113 table.StartFillData();
114 for (
int n = 0; n <= myTrack->GetnPoints(); n++) {
115 table << lcPoints->OnGetItemText(n, 0);
117 if (toPrintOut[PRINT_POSITION]) {
119 wxString pos = lcPoints->OnGetItemText(n, 3) + _T(
" ") +
120 lcPoints->OnGetItemText(n, 4);
123 if (toPrintOut[PRINT_BEARING])
124 table << lcPoints->OnGetItemText(n, 2);
125 if (toPrintOut[PRINT_DISTANCE])
126 table << lcPoints->OnGetItemText(n, 1);
127 if (toPrintOut[PRINT_TIME]) table << lcPoints->OnGetItemText(n, 5);
128 if (toPrintOut[PRINT_SPEED])
129 table << lcPoints->OnGetItemText(n, 6);
134void MyTrackPrintout::GetPageInfo(
int* minPage,
int* maxPage,
int* selPageFrom,
137 *maxPage = numberOfPages;
139 *selPageTo = numberOfPages;
142void MyTrackPrintout::OnPreparePrinting() {
145 wxFont trackPrintFont(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
146 wxFONTWEIGHT_NORMAL);
147 dc->SetFont(trackPrintFont);
157 int maxX = wxMin(w, 1000);
158 int maxY = wxMin(h, 1000);
161 double scaleX = (double)(w / maxX);
162 double scaleY = (double)(h / maxY);
165 double actualScale = wxMin(scaleX, scaleY);
168 dc->SetUserScale(actualScale, actualScale);
169 dc->SetDeviceOrigin((
long)marginX, (
long)marginY);
171 table.AdjustCells(dc, marginX, marginY);
172 numberOfPages = table.GetNumberPages();
175bool MyTrackPrintout::OnPrintPage(
int page) {
178 if (page <= numberOfPages) {
188void MyTrackPrintout::DrawPage(wxDC* dc) {
189 wxFont trackPrintFont_bold(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
191 dc->SetFont(trackPrintFont_bold);
192 wxBrush brush(wxColour(255, 255, 255), wxBRUSHSTYLE_TRANSPARENT);
195 int header_textOffsetX = 2;
196 int header_textOffsetY = 2;
198 dc->DrawText(myTrack->GetName(), 150, 20);
200 int currentX = marginX;
201 int currentY = marginY;
202 vector<PrintCell>& header_content = table.GetHeader();
203 for (
size_t j = 0; j < header_content.size(); j++) {
205 dc->DrawRectangle(currentX, currentY, cell.GetWidth(), cell.GetHeight());
206 dc->DrawText(cell.GetText(), currentX + header_textOffsetX,
207 currentY + header_textOffsetY);
208 currentX += cell.GetWidth();
211 wxFont trackPrintFont_normal(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
212 wxFONTWEIGHT_NORMAL);
213 dc->SetFont(trackPrintFont_normal);
215 vector<vector<PrintCell> >& cells = table.GetContent();
216 currentY = marginY + table.GetHeaderHeight();
217 int currentHeight = 0;
218 for (
size_t i = 0; i < cells.size(); i++) {
219 vector<PrintCell>& content_row = cells[i];
221 for (
size_t j = 0; j < content_row.size(); j++) {
223 if (cell.GetPage() == pageToPrint) {
224 wxRect r(currentX, currentY, cell.GetWidth(), cell.GetHeight());
225 dc->DrawRectangle(r);
226 r.Offset(textOffsetX, textOffsetY);
227 dc->DrawLabel(cell.GetText(), r);
228 currentX += cell.GetWidth();
229 currentHeight = cell.GetHeight();
232 currentY += currentHeight;
240EVT_BUTTON(ID_TRACKPRINT_SELECTION_CANCEL,
241 TrackPrintSelection::OnTrackpropCancelClick)
242EVT_BUTTON(ID_TRACKPRINT_SELECTION_OK, TrackPrintSelection::OnTrackpropOkClick)
246TrackPrintSelection::TrackPrintSelection(wxWindow* parent,
Track* _track,
248 wxWindowID
id,
const wxString& caption,
249 const wxPoint& pos,
const wxSize& size,
252 m_lcPoints = lcPoints;
256 Create(parent,
id, caption, pos, size, wstyle);
260TrackPrintSelection::~TrackPrintSelection() {}
267 const wxString& caption,
const wxPoint& pos,
268 const wxSize& size,
long style) {
269 SetExtraStyle(GetExtraStyle() | wxWS_EX_BLOCK_EVENTS);
272 style |= wxSTAY_ON_TOP;
275 wxDialog::Create(parent,
id, _(
"Print Track Selection"), pos, size, style);
288 wxStaticBox* itemStaticBoxSizer3Static =
289 new wxStaticBox(itemDialog1, wxID_ANY, _(
"Elements to print..."));
290 wxStaticBoxSizer* itemBoxSizer1 =
291 new wxStaticBoxSizer(itemStaticBoxSizer3Static, wxVERTICAL);
292 itemDialog1->SetSizer(itemBoxSizer1);
294 wxFlexGridSizer* fgSizer2;
295 fgSizer2 =
new wxFlexGridSizer(5, 2, 0, 0);
298 new wxCheckBox(itemDialog1, wxID_ANY, _(
"Position"), wxDefaultPosition,
299 wxDefaultSize, wxALIGN_LEFT);
300 m_checkBoxPosition->SetValue(
true);
301 fgSizer2->Add(m_checkBoxPosition, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
302 wxStaticText* label2 =
303 new wxStaticText(itemDialog1, wxID_ANY, _(
"Show Waypoint position."),
304 wxDefaultPosition, wxDefaultSize);
305 fgSizer2->Add(label2, 1, wxALL | wxALIGN_CENTER_VERTICAL, 5);
308 new wxCheckBox(itemDialog1, wxID_ANY, _(
"Course"), wxDefaultPosition,
309 wxDefaultSize, wxALIGN_LEFT);
310 m_checkBoxCourse->SetValue(
true);
311 fgSizer2->Add(m_checkBoxCourse, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
312 wxStaticText* label3 =
313 new wxStaticText(itemDialog1, wxID_ANY,
314 _(
"Show course from each Waypoint to the next one. "),
315 wxDefaultPosition, wxDefaultSize);
316 fgSizer2->Add(label3, 1, wxALL | wxALIGN_CENTER_VERTICAL, 5);
319 new wxCheckBox(itemDialog1, wxID_ANY, _(
"Distance"), wxDefaultPosition,
320 wxDefaultSize, wxALIGN_LEFT);
321 m_checkBoxDistance->SetValue(
true);
322 fgSizer2->Add(m_checkBoxDistance, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
323 wxStaticText* label4 =
324 new wxStaticText(itemDialog1, wxID_ANY,
325 _(
"Show Distance from each Waypoint to the next one."),
326 wxDefaultPosition, wxDefaultSize);
327 fgSizer2->Add(label4, 1, wxALL | wxALIGN_CENTER_VERTICAL, 5);
330 new wxCheckBox(itemDialog1, wxID_ANY, _(
"Time"), wxDefaultPosition,
331 wxDefaultSize, wxALIGN_LEFT);
332 m_checkBoxTime->SetValue(
true);
333 fgSizer2->Add(m_checkBoxTime, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
334 wxStaticText* label5 =
new wxStaticText(
335 itemDialog1, wxID_ANY, _(
"Show Time."), wxDefaultPosition, wxDefaultSize);
336 fgSizer2->Add(label5, 1, wxALL | wxALIGN_CENTER_VERTICAL, 5);
339 new wxCheckBox(itemDialog1, wxID_ANY, _(
"Speed"), wxDefaultPosition,
340 wxDefaultSize, wxALIGN_LEFT);
341 m_checkBoxSpeed->SetValue(
true);
342 fgSizer2->Add(m_checkBoxSpeed, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
343 wxStaticText* label6 =
344 new wxStaticText(itemDialog1, wxID_ANY, _(
"Show Speed."),
345 wxDefaultPosition, wxDefaultSize);
346 fgSizer2->Add(label6, 1, wxALL | wxALIGN_CENTER_VERTICAL, 5);
348 itemBoxSizer1->Add(fgSizer2, 5, wxEXPAND, 5);
350 wxBoxSizer* itemBoxSizer16 =
new wxBoxSizer(wxHORIZONTAL);
351 itemBoxSizer1->Add(itemBoxSizer16, 0, wxALIGN_RIGHT | wxALL, 5);
354 new wxButton(itemDialog1, ID_TRACKPRINT_SELECTION_CANCEL, _(
"Cancel"),
355 wxDefaultPosition, wxDefaultSize, 0);
356 itemBoxSizer16->Add(m_CancelButton, 0,
357 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL | wxALL, 5);
359 m_OKButton =
new wxButton(itemDialog1, ID_TRACKPRINT_SELECTION_OK, _(
"OK"),
360 wxDefaultPosition, wxDefaultSize, 0);
361 itemBoxSizer16->Add(m_OKButton, 0,
362 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL | wxALL, 5);
363 m_OKButton->SetDefault();
365 SetColorScheme((ColorScheme)0);
368void TrackPrintSelection::SetColorScheme(ColorScheme cs) { DimeControl(
this); }
374bool TrackPrintSelection::ShowToolTips() {
return TRUE; }
376void TrackPrintSelection::SetDialogTitle(
const wxString& title) {
380void TrackPrintSelection::OnTrackpropCancelClick(wxCommandEvent& event) {
385void TrackPrintSelection::OnTrackpropOkClick(wxCommandEvent& event) {
386 std::vector<bool> toPrintOut;
387 toPrintOut.push_back(m_checkBoxPosition->GetValue());
388 toPrintOut.push_back(m_checkBoxCourse->GetValue());
389 toPrintOut.push_back(m_checkBoxDistance->GetValue());
390 toPrintOut.push_back(m_checkBoxTime->GetValue());
391 toPrintOut.push_back(m_checkBoxSpeed->GetValue());
393 if (NULL == g_printData) {
394 g_printData =
new wxPrintData;
395 g_printData->SetOrientation(wxPORTRAIT);
396 g_pageSetupData =
new wxPageSetupDialogData;
402 wxPrintDialogData printDialogData(*g_printData);
403 printDialogData.EnablePageNumbers(
true);
405 wxPrinter printer(&printDialogData);
406 if (!printer.Print(
this, mytrackprintout1,
true)) {
407 if (wxPrinter::GetLastError() == wxPRINTER_ERROR) {
409 _(
"There was a problem printing.\nPerhaps your current "
410 "printer is not set correctly?"),
411 _T(
"OpenCPN" ), wxOK);
This class takes multilined string and modifies it to fit into given width for given device.
bool Create(wxWindow *parent, wxWindowID id=SYMBOL_TRACKPRINT_SELECTION_IDNAME, const wxString &caption=SYMBOL_TRACKPRINT_SELECTION_TITLE, const wxPoint &pos=SYMBOL_TRACKPRINT_SELECTION_POSITION, const wxSize &size=SYMBOL_TRACKPRINT_SELECTION_SIZE, long style=SYMBOL_TRACKPRINT_SELECTION_STYLE)