Systematic use of tm_ostream class instead of ostream (removing dependency on std)
[texmacs.git] / src / src / Typeset / boxes.hpp
blobf52c20324e6bdf06a7d18ea2642b4ab938592296
2 /******************************************************************************
3 * MODULE : boxes.hpp
4 * DESCRIPTION: the low level box structure
5 * and formatting routines
6 * COPYRIGHT : (C) 1999 Joris van der Hoeven
7 *******************************************************************************
8 * This software falls under the GNU general public license version 3 or later.
9 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
10 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ******************************************************************************/
13 #ifndef BOXES_H
14 #define BOXES_H
15 #include "basic.hpp"
16 #include "rectangles.hpp"
17 #include "path.hpp"
18 #include "renderer.hpp"
19 #include "font.hpp"
20 #include "language.hpp"
21 #include "hashmap.hpp"
22 #include "Graphics/frame.hpp"
23 #include "Graphics/grid.hpp"
25 #define MAX_SI 0x7fffffff
26 #define MIN_SI 0x80000000
28 #define STD_BOX 0
29 #define STACK_BOX 1
30 #define CONTROL_BOX 2
31 #define MOVE_BOX 3
32 #define SCROLL_BOX 4
34 /******************************************************************************
35 * The cursor class
36 ******************************************************************************/
38 struct cursor_rep: concrete_struct {
39 SI ox, oy; // main cursor position
40 SI delta; // infinitesimal shift to the right
41 SI y1; // under base line
42 SI y2; // upper base line
43 double slope; // slope of cursor
44 bool valid; // the cursor is valid
47 struct cursor {
48 CONCRETE(cursor);
49 cursor (SI x=0, SI y=0, SI delta=0, SI y1=0, SI y2=0,
50 double slope=0.0, bool valid=true);
52 CONCRETE_CODE(cursor);
54 cursor copy (cursor cu);
55 bool operator == (cursor cu1, cursor cu2);
56 bool operator != (cursor cu1, cursor cu2);
57 tm_ostream& operator << (tm_ostream& out, cursor cu);
59 /******************************************************************************
60 * The selection class
61 ******************************************************************************/
63 struct selection_rep: concrete_struct {
64 rectangles rs;
65 path start;
66 path end;
67 bool valid;
70 struct selection {
71 CONCRETE(selection);
72 selection (rectangles rs= rectangles(),
73 path start= path(), path end= path (),
74 bool valid= true);
76 CONCRETE_CODE(selection);
78 bool operator == (selection sel1, selection sel2);
79 bool operator != (selection sel1, selection sel2);
80 tm_ostream& operator << (tm_ostream& out, selection sel);
82 /******************************************************************************
83 * The graphical selection class
84 ******************************************************************************/
86 struct gr_selection_rep;
87 struct gr_selection {
88 CONCRETE(gr_selection);
89 gr_selection (array<path> cp= array<path> (), SI dist= 0);
92 tm_ostream& operator << (tm_ostream& out, gr_selection sel);
94 typedef array<gr_selection> gr_selections;
95 tree as_tree (gr_selections sels);
97 /******************************************************************************
98 * The box class
99 ******************************************************************************/
101 class box_rep;
102 struct lazy;
103 typedef array<double> point;
105 class box {
106 ABSTRACT_NULL(box);
107 inline box operator [] (int i);
108 box operator [] (path p);
109 operator tree ();
110 bool operator == (box b2);
111 bool operator != (box b2);
112 friend inline int N (box b);
115 class box_rep: public abstract_struct {
116 private:
117 SI x0, y0; // offset w.r.t. parent box
119 public:
120 SI x1, y1; // under left corner (logical)
121 SI x2, y2; // upper right corner (logical)
122 SI x3, y3; // under left corner (ink)
123 SI x4, y4; // upper right corner (ink)
125 path ip; // corresponding inverse path in source tree
127 /****************************** main routines ******************************/
129 inline box_rep (path ip);
130 inline virtual ~box_rep ();
131 void relocate (path p, bool force= false);
132 virtual box transform (frame fr);
133 virtual operator tree () = 0;
134 virtual void pre_display (renderer& ren);
135 virtual void post_display (renderer& ren);
136 virtual void display (renderer ren) = 0;
137 virtual void clear_incomplete (rectangles& rs, SI pixel,
138 int i, int i1, int i2);
139 virtual int subnr ();
140 virtual box subbox (int i);
141 virtual tree action (tree t, SI x, SI y, SI delta);
142 virtual void loci (SI x, SI y, SI d, list<string>& ids, rectangles& rs);
143 virtual void position_at (SI x, SI y, rectangles& change_log);
144 virtual void collect_page_numbers (hashmap<string,tree>& h, tree page);
145 virtual path find_tag (string name);
147 virtual int reindex (int i, int item, int n);
148 void redraw (renderer ren, path p, rectangles& l);
149 void redraw (renderer ren, path p, rectangles& l, SI x, SI y);
151 /*************************** positioning routines **************************/
153 inline SI w ();
154 inline SI h ();
155 inline SI& sx (int i);
156 inline SI& sy (int i);
157 inline SI sx1 (int i);
158 inline SI sy1 (int i);
159 inline SI sx2 (int i);
160 inline SI sy2 (int i);
161 inline SI sx3 (int i);
162 inline SI sy3 (int i);
163 inline SI sx4 (int i);
164 inline SI sy4 (int i);
165 inline bool test_in (SI x, SI y);
167 inline bool accessible ();
168 inline bool decoration ();
170 SI distance (int i, SI x, SI y, SI delta);
171 bool in_rectangle (SI x1, SI y1, SI x2, SI y2);
172 bool contains_rectangle (SI x1, SI y1, SI x2, SI y2);
174 /******************* path conversions and cursor routines ******************/
176 virtual path find_lip ();
177 virtual path find_rip ();
178 virtual path find_left_box_path ();
179 virtual path find_right_box_path ();
180 virtual path find_box_path (SI x, SI y, SI delta, bool force);
181 virtual cursor find_cursor (path bp);
182 virtual selection find_selection (path lbp, path rbp);
183 virtual path find_tree_path (path bp);
184 virtual path find_box_path (path p, bool& found);
186 path find_tree_path (SI x, SI y, SI delta);
187 cursor find_check_cursor (path p);
188 selection find_check_selection (path lp, path rp);
190 /************************ fine typesetting routines ************************/
192 virtual double left_slope ();
193 virtual double right_slope ();
194 virtual SI left_correction ();
195 virtual SI right_correction ();
196 virtual SI lsub_correction ();
197 virtual SI lsup_correction ();
198 virtual SI rsub_correction ();
199 virtual SI rsup_correction ();
200 virtual SI sub_lo_base (int level);
201 virtual SI sub_hi_lim (int level);
202 virtual SI sup_lo_lim (int level);
203 virtual SI sup_lo_base (int level);
204 virtual SI sup_hi_lim (int level);
206 /*************************** for graphical boxes ***************************/
208 virtual frame get_frame ();
209 virtual grid get_grid ();
210 virtual void get_limits (point& lim1, point& lim2);
212 frame find_frame (path bp, bool last= false);
213 grid find_grid (path bp);
214 void find_limits (path bp, point& lim1, point& lim2);
216 virtual SI graphical_distance (SI x, SI y);
217 virtual gr_selections graphical_select (SI x, SI y, SI dist);
218 virtual gr_selections graphical_select (SI x1, SI y1, SI x2, SI y2);
220 /************************** retrieving information *************************/
222 virtual int get_type ();
223 virtual tree get_info (tree in);
224 virtual int get_leaf_left_pos ();
225 virtual int get_leaf_right_pos ();
226 virtual string get_leaf_string ();
227 virtual font get_leaf_font ();
228 virtual color get_leaf_color ();
229 virtual language get_leaf_language ();
230 virtual tree get_leaf_tree ();
231 virtual lazy get_leaf_lazy ();
232 virtual SI get_leaf_offset (string search);
234 /******************************** animations *******************************/
236 virtual int anim_length ();
237 virtual bool anim_started ();
238 virtual bool anim_finished ();
239 virtual void anim_start_at (time_t at);
240 virtual void anim_finish_now ();
241 virtual time_t anim_next_update ();
242 void anim_check_invalid (bool& flag, time_t& at, rectangles& rs);
243 virtual void anim_get_invalid (bool& flag, time_t& at, rectangles& rs);
245 /********************************* obsolete ********************************/
247 friend struct page_box_rep; // temporary friends for accessing x0 and y0
248 friend struct lazy_paragraph_rep;
249 friend class phrase_box_rep;
250 friend class remember_box_rep;
251 friend void make_eps (url dest, box b, int dpi= 600);
253 ABSTRACT_NULL_CODE(box);
255 extern int box_count;
256 inline box_rep::box_rep (path ip2):
257 x0(0), y0(0), x1(0), y1(0), x2(0), y2(0), x3(0), y3(0), x4(0), y4(0),
258 ip (ip2) { TM_DEBUG(box_count++); }
259 inline box_rep::~box_rep () { TM_DEBUG(box_count--); }
260 inline bool box_rep::test_in (SI x, SI y) {
261 return (x>=x1) && (x<x2) && (y>=y1) && (y<y2); }
262 inline SI box_rep::w () { return x2-x1; }
263 inline SI box_rep::h () { return y2-y1; }
264 inline SI& box_rep::sx (int i) { return subbox(i)->x0; }
265 inline SI& box_rep::sy (int i) { return subbox(i)->y0; }
266 inline SI box_rep::sx1 (int i) { box b= subbox(i); return b->x0+ b->x1; }
267 inline SI box_rep::sy1 (int i) { box b= subbox(i); return b->y0+ b->y1; }
268 inline SI box_rep::sx2 (int i) { box b= subbox(i); return b->x0+ b->x2; }
269 inline SI box_rep::sy2 (int i) { box b= subbox(i); return b->y0+ b->y2; }
270 inline SI box_rep::sx3 (int i) { box b= subbox(i); return b->x0+ b->x3; }
271 inline SI box_rep::sy3 (int i) { box b= subbox(i); return b->y0+ b->y3; }
272 inline SI box_rep::sx4 (int i) { box b= subbox(i); return b->x0+ b->x4; }
273 inline SI box_rep::sy4 (int i) { box b= subbox(i); return b->y0+ b->y4; }
275 inline box box::operator [] (int i) { return rep->subbox(i); }
276 inline int N (box b) { return b.rep->subnr(); }
277 tm_ostream& operator << (tm_ostream& out, box b);
278 SI get_delta (SI x, SI x1, SI x2);
279 bool outside (SI x, SI delta, SI x1, SI x2);
280 void make_eps (url dest, box b, int dpi);
281 path find_innermost_scroll (box b, path p);
282 path find_scrolled_tree_path (box b, path sp, SI x, SI y, SI delta);
283 void find_canvas_info (box b, path sp, SI& x, SI& y, SI& sx, SI& sy,
284 rectangle& outer, rectangle& inner);
286 extern bool refresh_needed;
287 extern time_t refresh_next;
288 void refresh_at (time_t t);
290 #define DECORATION (-1)
291 #define DECORATION_LEFT (-2)
292 #define DECORATION_MIDDLE (-3)
293 #define DECORATION_RIGHT (-4)
294 #define DETACHED (-5)
295 #define is_accessible(p) ((is_nil (p)) || ((p)->item >= 0))
296 #define is_decoration(p) ((!is_nil (p)) && ((p)->item < 0))
297 inline path descend (path ip, int i) {
298 return (is_nil (ip) || (ip->item >= 0))? path (i, ip): ip; }
299 inline path decorate () {
300 return path (DECORATION); }
301 inline path decorate (path ip) {
302 return (is_nil (ip) || (ip->item >= 0))? path (DECORATION, ip): ip; }
303 inline path decorate_left (path ip) {
304 return (is_nil (ip) || (ip->item >= 0))? path (DECORATION_LEFT, ip): ip; }
305 inline path decorate_middle (path ip) {
306 return (is_nil (ip) || (ip->item >= 0))? path (DECORATION_MIDDLE, ip): ip; }
307 inline path decorate_right (path ip) {
308 return (is_nil (ip) || (ip->item >= 0))? path (DECORATION_RIGHT, ip): ip; }
309 path descend_decode (path ip, int side);
311 inline bool box_rep::accessible () { return is_accessible (find_lip ()); }
312 inline bool box_rep::decoration () { return is_decoration (find_lip ()); }
314 tree attach_dip (tree ref, path ip);
315 #define attach_here(t,ip) attach_dip(t,ip),ip
316 #define attach_deco(t,ip) attach_dip(t,decorate(ip)),decorate(ip)
317 #define attach_left(t,ip) attach_dip(t,decorate_left(ip)),decorate_left(ip)
318 #define attach_middle(t,ip) \
319 attach_dip(t,decorate_middle(ip)),decorate_middle(ip)
320 #define attach_right(t,ip) attach_dip(t,decorate_right(ip)),decorate_right(ip)
322 /******************************************************************************
323 * The graphical selection class (continued)
324 ******************************************************************************/
326 struct gr_selection_rep: concrete_struct {
327 array<path> cp;
328 array<point> pts;
329 point p;
330 SI dist;
331 curve c;
333 CONCRETE_CODE(gr_selection);
335 #endif // defined BOXES_H