53#include <wx/printdlg.h>
54#include <wx/artprov.h>
55#include <wx/stdpaths.h>
57#include <wx/listctrl.h>
58#include <wx/aui/aui.h>
60#include <wx/progdlg.h>
63#include <wx/tokenzr.h>
70void PrintCell::Init(
const wxString& _content, wxDC* _dc,
int _width,
71 int _cellpadding,
bool _bold_font) {
72 bold_font = _bold_font;
75 cellpadding = _cellpadding;
81void PrintCell::Adjust() {
82 wxFont orig_font = dc->GetFont();
83 wxFont _font = orig_font;
85 _font.SetWeight(wxFONTWEIGHT_BOLD);
88 vector<wxString> list;
89 list.push_back(wxString());
90 wxString separator =
" ";
91 wxStringTokenizer tokenizer(content, separator, wxTOKEN_RET_DELIMS);
93 while (tokenizer.HasMoreTokens()) {
94 wxString token = tokenizer.GetNextToken();
97 wxString tmp = list[list.size() - 1];
98 wxString tmp2 = tmp + token;
100 dc->GetMultiLineTextExtent(tmp2, &w, &h);
101 if ((w < width - 2 * cellpadding) || words_number == 1) {
102 list[list.size() - 1] = tmp2;
104 list.push_back(token);
108 for (
size_t i = 0; i < list.size() - 1; i++) {
109 modified_content = modified_content + list[i] +
'\n';
112 modified_content = modified_content + list[list.size() - 1];
116 dc->GetMultiLineTextExtent(modified_content, &w, &h);
119 dc->SetFont(orig_font);
126 state = TABLE_SETUP_WIDTHS;
127 create_next_row =
true;
131 for (vector<vector<wxString> >::iterator iter = data.begin();
132 iter != data.end(); iter++) {
139 if (create_next_row) {
141 create_next_row =
false;
145void Table::NewRow() {
146 vector<wxString> empty_row;
147 data.push_back(empty_row);
150Table& Table::operator<<(
const double& cellcontent) {
151 if (state == TABLE_SETUP_WIDTHS) {
152 widths.push_back(cellcontent);
155 if (state == TABLE_FILL_DATA) {
158 string _cellcontent = sstr.str();
160 wxString _str(_cellcontent.c_str(), wxConvUTF8);
161 data[data.size() - 1].push_back(_str);
166Table& Table::operator<<(
const wxString& cellcontent) {
168 if (state == TABLE_FILL_HEADER) {
170 header.push_back(cellcontent);
173 if (state == TABLE_SETUP_WIDTHS) {
175 state = TABLE_FILL_DATA;
178 if ((cellcontent ==
"\n")) {
179 create_next_row =
true;
182 data[data.size() - 1].push_back(cellcontent);
186Table& Table::operator<<(
const int& cellcontent) {
187 if (state == TABLE_SETUP_WIDTHS) {
188 widths.push_back((
double)cellcontent);
191 if (state == TABLE_FILL_DATA) {
194 string _cellcontent = sstr.str();
196 wxString _str(_cellcontent.c_str(), wxConvUTF8);
197 data[data.size() - 1].push_back(_str);
202ostream& operator<<(ostream& out,
Table& table) {
203 vector<vector<wxString> >& data = table.GetData();
205 for (vector<vector<wxString> >::iterator iter = data.begin();
206 iter != data.end(); iter++) {
207 vector<wxString> row = (*iter);
208 for (vector<wxString>::iterator rowiter = row.begin(); rowiter != row.end();
210 out << (*rowiter).fn_str() <<
" ";
217PrintTable::PrintTable() :
Table() { rows_heights.clear(); }
219void PrintTable::AdjustCells(wxDC* dc,
int marginX,
int marginY) {
220 number_of_pages = -1;
223 for (
size_t j = 0; j < widths.size(); j++) {
230 double scale_x, scale_y;
231 dc->GetUserScale(&scale_x, &scale_y);
235 int width = w - 4 * marginX;
237 for (
size_t j = 0; j < header.size(); j++) {
238 int cell_width = (int)((
double)width * widths[j] / sum);
240 cell_content.Init(header[j], dc, cell_width, 10,
true);
241 header_content.push_back(cell_content);
242 header_height = std::max(header_height, cell_content.GetHeight());
245 for (
size_t i = 0; i < data.size(); i++) {
246 vector<wxString> row = data[i];
247 vector<PrintCell> contents_row;
249 for (
size_t j = 0; j < row.size(); j++) {
250 int cell_width = (int)((
double)width * widths[j] / sum);
252 cell_content.Init(row[j], dc, cell_width, 10);
253 contents_row.push_back(cell_content);
254 max_height = std::max(max_height, cell_content.GetHeight());
256 rows_heights.push_back(max_height);
257 contents.push_back(contents_row);
260 int stripped_page = h - 4 * marginY - header_height;
261 int current_page = 1;
263 for (
size_t i = 0; i < data.size(); i++) {
264 int row_height = rows_heights[i];
265 if (row_height + current_y > stripped_page) {
267 current_y = row_height;
269 current_y += row_height;
271 int row_page = current_page;
272 vector<PrintCell>& contents_row = contents[i];
273 for (
size_t j = 0; j < contents_row.size(); j++) {
274 contents_row[j].SetPage(row_page);
275 contents_row[j].SetHeight(row_height);
277 number_of_pages = std::max(row_page, number_of_pages);
This class takes multilined string and modifies it to fit into given width for given device.
Represents a NxM simple table with captions.
OpenCPN Route table printout.