55#include <wx/printdlg.h>
56#include <wx/artprov.h>
57#include <wx/stdpaths.h>
59#include <wx/listctrl.h>
60#include <wx/aui/aui.h>
62#include <wx/progdlg.h>
65#include <wx/tokenzr.h>
72void PrintCell::Init(
const wxString& _content, wxDC* _dc,
int _width,
73 int _cellpadding,
bool _bold_font) {
74 bold_font = _bold_font;
77 cellpadding = _cellpadding;
83void PrintCell::Adjust() {
84 wxFont orig_font = dc->GetFont();
85 wxFont _font = orig_font;
87 _font.SetWeight(wxFONTWEIGHT_BOLD);
90 vector<wxString> list;
91 list.push_back(wxString());
92 wxString separator =
" ";
93 wxStringTokenizer tokenizer(content, separator, wxTOKEN_RET_DELIMS);
95 while (tokenizer.HasMoreTokens()) {
96 wxString token = tokenizer.GetNextToken();
99 wxString tmp = list[list.size() - 1];
100 wxString tmp2 = tmp + token;
102 dc->GetMultiLineTextExtent(tmp2, &w, &h);
103 if ((w < width - 2 * cellpadding) || words_number == 1) {
104 list[list.size() - 1] = tmp2;
106 list.push_back(token);
110 for (
size_t i = 0; i < list.size() - 1; i++) {
111 modified_content = modified_content + list[i] +
'\n';
114 modified_content = modified_content + list[list.size() - 1];
118 dc->GetMultiLineTextExtent(modified_content, &w, &h);
121 dc->SetFont(orig_font);
128 state = TABLE_SETUP_WIDTHS;
129 create_next_row =
true;
133 for (vector<vector<wxString> >::iterator iter = data.begin();
134 iter != data.end(); iter++) {
141 if (create_next_row) {
143 create_next_row =
false;
147void Table::NewRow() {
148 vector<wxString> empty_row;
149 data.push_back(empty_row);
152Table& Table::operator<<(
const double& cellcontent) {
153 if (state == TABLE_SETUP_WIDTHS) {
154 widths.push_back(cellcontent);
157 if (state == TABLE_FILL_DATA) {
160 string _cellcontent = sstr.str();
162 wxString _str(_cellcontent.c_str(), wxConvUTF8);
163 data[data.size() - 1].push_back(_str);
168Table& Table::operator<<(
const wxString& cellcontent) {
170 if (state == TABLE_FILL_HEADER) {
172 header.push_back(cellcontent);
175 if (state == TABLE_SETUP_WIDTHS) {
177 state = TABLE_FILL_DATA;
180 if ((cellcontent ==
"\n")) {
181 create_next_row =
true;
184 data[data.size() - 1].push_back(cellcontent);
188Table& Table::operator<<(
const int& cellcontent) {
189 if (state == TABLE_SETUP_WIDTHS) {
190 widths.push_back((
double)cellcontent);
193 if (state == TABLE_FILL_DATA) {
196 string _cellcontent = sstr.str();
198 wxString _str(_cellcontent.c_str(), wxConvUTF8);
199 data[data.size() - 1].push_back(_str);
204ostream& operator<<(ostream& out,
Table& table) {
205 vector<vector<wxString> >& data = table.GetData();
207 for (vector<vector<wxString> >::iterator iter = data.begin();
208 iter != data.end(); iter++) {
209 vector<wxString> row = (*iter);
210 for (vector<wxString>::iterator rowiter = row.begin(); rowiter != row.end();
212 out << (*rowiter).fn_str() <<
" ";
219PrintTable::PrintTable() :
Table() { rows_heights.clear(); }
221void PrintTable::AdjustCells(wxDC* dc,
int marginX,
int marginY) {
222 number_of_pages = -1;
225 for (
size_t j = 0; j < widths.size(); j++) {
232 double scale_x, scale_y;
233 dc->GetUserScale(&scale_x, &scale_y);
237 int width = w - 4 * marginX;
239 for (
size_t j = 0; j < header.size(); j++) {
240 int cell_width = (int)((
double)width * widths[j] / sum);
242 cell_content.Init(header[j], dc, cell_width, 10,
true);
243 header_content.push_back(cell_content);
244 header_height = std::max(header_height, cell_content.GetHeight());
247 for (
size_t i = 0; i < data.size(); i++) {
248 vector<wxString> row = data[i];
249 vector<PrintCell> contents_row;
251 for (
size_t j = 0; j < row.size(); j++) {
252 int cell_width = (int)((
double)width * widths[j] / sum);
254 cell_content.Init(row[j], dc, cell_width, 10);
255 contents_row.push_back(cell_content);
256 max_height = std::max(max_height, cell_content.GetHeight());
258 rows_heights.push_back(max_height);
259 contents.push_back(contents_row);
262 int stripped_page = h - 4 * marginY - header_height;
263 int current_page = 1;
265 for (
size_t i = 0; i < data.size(); i++) {
266 int row_height = rows_heights[i];
267 if (row_height + current_y > stripped_page) {
269 current_y = row_height;
271 current_y += row_height;
273 int row_page = current_page;
274 vector<PrintCell>& contents_row = contents[i];
275 for (
size_t j = 0; j < contents_row.size(); j++) {
276 contents_row[j].SetPage(row_page);
277 contents_row[j].SetHeight(row_height);
279 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.