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