OpenCPN Partial API docs
Loading...
Searching...
No Matches
printtable.h
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2010 by David S. Register *
3 * Copyright (C) 2010 by Pavel Saviankou *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
17 **************************************************************************/
18
25#ifndef PRINTTABLE_H
26#define PRINTTABLE_H
27
28#include <iostream>
29#include <vector>
30
31#include <wx/print.h>
32#include <wx/datetime.h>
33#include <wx/cmdline.h>
34#include <wx/string.h>
35#ifdef __WXMSW__
36#include <wx/msw/private.h>
37#endif
38
39#include "model/ocpn_types.h"
40#include "navutil.h"
41
51enum TableState { TABLE_SETUP_WIDTHS = 0, TABLE_FILL_DATA, TABLE_FILL_HEADER };
52
62class Table {
63protected:
64 int nrows;
65 int ncols;
66
67 bool create_next_row;
68
69 std::vector<std::vector<wxString> > data;
70 std::vector<double> widths;
71 std::vector<wxString> header;
72 TableState state;
73
74 void Start();
75
76 void NewRow();
77
78public:
79 Table();
80 ~Table();
81
82 Table& operator<<(const int&);
83 Table& operator<<(const double&);
84 Table& operator<<(const wxString&);
85
86 std::vector<std::vector<wxString> >& GetData() { return data; };
87
88 void StartFillData() { state = TABLE_FILL_DATA; };
89
90 void StartFillHeader() { state = TABLE_FILL_HEADER; };
91
92 void StartFillWidths() { state = TABLE_SETUP_WIDTHS; };
93
94 int GetRowHeight(int i) { return widths[i]; };
95};
96
97std::ostream& operator<<(std::ostream&, Table&);
98
107protected:
108 // Copy of printing device
109 wxDC* dc;
110
111 // Target width
112 int width;
113
114 // Target height
115 int height;
116
117 // Cellpadding
118 int cellpadding;
119
120 // Content of a cell
121 wxString content;
122
123 // Result of modification
124 wxString modified_content;
125
126 // Rect for printing of modified string
127 wxRect rect;
128
129 // Stores page, where this cell will be printed
130 int page;
131
132 // Stores, if one has to ovveride property "weight" of the font with the value
133 // "bold" - used to print header of the table.
134 bool bold_font;
135
136 // Adjust text
137 void Adjust();
138
139public:
140 // Constructor with content to print and device
141 PrintCell() {};
142
143 // Constructor with content to print and device
144 void Init(const wxString& _content, wxDC* _dc, int _width, int _cellpadding,
145 bool bold_font = false);
146
147 // Returns rect for printing
148 wxRect GetRect() { return rect; };
149
150 // Returns modified cell content
151 wxString GetText() { return modified_content; };
152
153 // Returns height of the cell
154 int GetHeight() { return height; };
155
156 // Returns width of the cell
157 int GetWidth() { return width; };
158
159 // sets the page to print
160 void SetPage(int _page) { page = _page; };
161
162 // sets the height
163 void SetHeight(int _height) { height = _height; };
164
165 // Returns the page, where this element should be painted
166 int GetPage() { return page; };
167};
168
178class PrintTable : public Table {
179protected:
180 std::vector<std::vector<PrintCell> > contents;
181 std::vector<PrintCell> header_content;
182 std::vector<int> rows_heights;
183 int header_height;
184
185 int number_of_pages; // stores the number of pages for printing of this
186 // table. It is set by AdjustCells(...)
187
188public:
189 PrintTable();
190
191 // creates internally std::vector of PrintCell's, to calculate columns widths
192 // and row sizes
193 void AdjustCells(wxDC* _dc, int marginX, int marginY);
194
195 // delivers content of the table
196 std::vector<std::vector<PrintCell> >& GetContent() { return contents; };
197 // delivers header of the table
198 std::vector<PrintCell>& GetHeader() { return header_content; };
199 // returns the total number of needed pages;
200 int GetNumberPages() { return number_of_pages; };
201
202 // Returns the height of the header
203 int GetHeaderHeight() { return header_height; };
204};
205
206#endif // PRINTTABLE_H
This class takes multilined string and modifies it to fit into given width for given device.
Definition printtable.h:106
Extension of a class Table with printing into dc.
Definition printtable.h:178
Represents a NxM simple table with captions.
Definition printtable.h:62
Utility functions.
Navigation data types.
TableState
Enumeration is used to notice the state of the table.
Definition printtable.h:51