Back to index

texmacs  1.0.7.15
boxes.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : boxes.hpp
00004 * DESCRIPTION: the low level box structure
00005 *              and formatting routines
00006 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
00007 *******************************************************************************
00008 * This software falls under the GNU general public license version 3 or later.
00009 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00010 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00011 ******************************************************************************/
00012 
00013 #ifndef BOXES_H
00014 #define BOXES_H
00015 #include "basic.hpp"
00016 #include "rectangles.hpp"
00017 #include "path.hpp"
00018 #include "renderer.hpp"
00019 #include "timer.hpp"
00020 #include "font.hpp"
00021 #include "language.hpp"
00022 #include "hashmap.hpp"
00023 #include "Graphics/frame.hpp"
00024 #include "Graphics/grid.hpp"
00025 
00026 #define MAX_SI 0x7fffffff
00027 #define MIN_SI 0x80000000
00028 
00029 #define STD_BOX       0
00030 #define STACK_BOX     1
00031 #define CONTROL_BOX   2
00032 #define MOVE_BOX      3
00033 #define SCROLL_BOX    4
00034 
00035 /******************************************************************************
00036 * The cursor class
00037 ******************************************************************************/
00038 
00039 struct cursor_rep: concrete_struct {
00040   SI ox, oy;    // main cursor position
00041   SI delta;     // infinitesimal shift to the right
00042   SI y1;        // under base line
00043   SI y2;        // upper base line
00044   double slope; // slope of cursor
00045   bool valid;   // the cursor is valid
00046 };
00047 
00048 struct cursor {
00049   CONCRETE(cursor);
00050   cursor (SI x=0, SI y=0, SI delta=0, SI y1=0, SI y2=0,
00051          double slope=0.0, bool valid=true);
00052 };
00053 CONCRETE_CODE(cursor);
00054 
00055 cursor copy (cursor cu);
00056 bool operator == (cursor cu1, cursor cu2);
00057 bool operator != (cursor cu1, cursor cu2);
00058 tm_ostream& operator << (tm_ostream& out, cursor cu);
00059 
00060 /******************************************************************************
00061 * The selection class
00062 ******************************************************************************/
00063 
00064 struct selection_rep: concrete_struct {
00065   rectangles rs;
00066   path start;
00067   path end;
00068   bool valid;
00069 };
00070 
00071 struct selection {
00072   CONCRETE(selection);
00073   selection (rectangles rs= rectangles(),
00074             path start= path(), path end= path (),
00075             bool valid= true);
00076 };
00077 CONCRETE_CODE(selection);
00078 
00079 bool operator == (selection sel1, selection sel2);
00080 bool operator != (selection sel1, selection sel2);
00081 tm_ostream& operator << (tm_ostream& out, selection sel);
00082 
00083 /******************************************************************************
00084 * The graphical selection class
00085 ******************************************************************************/
00086 
00087 struct gr_selection_rep;
00088 struct gr_selection {
00089   CONCRETE(gr_selection);
00090   gr_selection (array<path> cp= array<path> (), SI dist= 0);
00091 };
00092 
00093 tm_ostream& operator << (tm_ostream& out, gr_selection sel);
00094 
00095 typedef array<gr_selection> gr_selections;
00096 void sort (gr_selections& sels);
00097 tree as_tree (gr_selections sels);
00098 
00099 /******************************************************************************
00100 * The box class
00101 ******************************************************************************/
00102 
00103 class box_rep;
00104 struct lazy;
00105 typedef array<double> point;
00106 
00107 class box {
00108   ABSTRACT_NULL(box);
00109   inline box operator [] (int i);
00110   box operator [] (path p);
00111   operator tree ();
00112   bool operator == (box b2);
00113   bool operator != (box b2);
00114   friend inline int N (box b);
00115 };
00116 
00117 class box_rep: public abstract_struct {
00118 private:
00119   SI x0, y0;    // offset w.r.t. parent box
00120 
00121 public:
00122   SI x1, y1;    // under left corner (logical)
00123   SI x2, y2;    // upper right corner (logical)
00124   SI x3, y3;    // under left corner (ink)
00125   SI x4, y4;    // upper right corner (ink)
00126 
00127   path ip;      // corresponding inverse path in source tree
00128 
00129   /****************************** main routines ******************************/
00130 
00131   inline            box_rep (path ip);
00132   inline            virtual ~box_rep ();
00133   void              relocate (path p, bool force= false);
00134   virtual box     transform (frame fr);
00135   virtual operator  tree () = 0;
00136   virtual void      pre_display (renderer& ren);
00137   virtual void      post_display (renderer& ren);
00138   virtual void      display (renderer ren) = 0;
00139   virtual void      clear_incomplete (rectangles& rs, SI pixel,
00140                                   int i, int i1, int i2);
00141   virtual int       subnr ();
00142   virtual box       subbox (int i);
00143   virtual tree      action (tree t, SI x, SI y, SI delta);
00144   virtual void      loci (SI x, SI y, SI d, list<string>& ids, rectangles& rs);
00145   virtual void      position_at (SI x, SI y, rectangles& change_log);
00146   virtual void      collect_page_numbers (hashmap<string,tree>& h, tree page);
00147   virtual path      find_tag (string name);
00148 
00149   virtual int  reindex (int i, int item, int n);
00150   void redraw (renderer ren, path p, rectangles& l);
00151   void redraw (renderer ren, path p, rectangles& l, SI x, SI y);
00152 
00153   /*************************** positioning routines **************************/
00154 
00155   inline SI   w ();
00156   inline SI   h ();
00157   inline SI&  sx (int i);
00158   inline SI&  sy (int i);
00159   inline SI   sx1 (int i);
00160   inline SI   sy1 (int i);
00161   inline SI   sx2 (int i);
00162   inline SI   sy2 (int i);
00163   inline SI   sx3 (int i);
00164   inline SI   sy3 (int i);
00165   inline SI   sx4 (int i);
00166   inline SI   sy4 (int i);
00167   inline bool test_in (SI x, SI y);
00168 
00169   inline bool accessible ();
00170   inline bool decoration ();
00171 
00172   SI distance (int i, SI x, SI y, SI delta);
00173   bool in_rectangle (SI x1, SI y1, SI x2, SI y2);
00174   bool contains_rectangle (SI x1, SI y1, SI x2, SI y2);
00175 
00176   /******************* path conversions and cursor routines ******************/
00177 
00178   virtual path      find_lip ();
00179   virtual path      find_rip ();
00180   virtual path      find_left_box_path ();
00181   virtual path      find_right_box_path ();
00182   virtual path      find_box_path (SI x, SI y, SI delta, bool force);
00183   virtual cursor    find_cursor (path bp);
00184   virtual selection find_selection (path lbp, path rbp);
00185   virtual path      find_tree_path (path bp);
00186   virtual path      find_box_path (path p, bool& found);
00187        
00188   path      find_tree_path (SI x, SI y, SI delta);
00189   cursor    find_check_cursor (path p);
00190   selection find_check_selection (path lp, path rp);
00191 
00192   /************************ fine typesetting routines ************************/
00193 
00194   virtual double    left_slope ();
00195   virtual double    right_slope ();
00196   virtual SI        left_correction ();
00197   virtual SI        right_correction ();
00198   virtual SI        lsub_correction ();
00199   virtual SI        lsup_correction ();
00200   virtual SI        rsub_correction ();
00201   virtual SI        rsup_correction ();
00202   virtual SI        sub_lo_base (int level);
00203   virtual SI        sub_hi_lim  (int level);
00204   virtual SI        sup_lo_lim  (int level);
00205   virtual SI        sup_lo_base (int level);
00206   virtual SI        sup_hi_lim  (int level);
00207 
00208   /*************************** for graphical boxes ***************************/
00209 
00210   virtual frame     get_frame ();
00211   virtual grid      get_grid ();
00212   virtual void      get_limits (point& lim1, point& lim2);
00213 
00214   frame     find_frame (path bp, bool last= false);
00215   grid      find_grid (path bp);
00216   void      find_limits (path bp, point& lim1, point& lim2);
00217 
00218   virtual SI             graphical_distance (SI x, SI y);
00219   virtual gr_selections  graphical_select (SI x, SI y, SI dist);
00220   virtual gr_selections  graphical_select (SI x1, SI y1, SI x2, SI y2);
00221 
00222   /************************** retrieving information *************************/
00223 
00224   virtual int       get_type ();
00225   virtual tree      get_info (tree in);
00226   virtual int       get_leaf_left_pos ();
00227   virtual int       get_leaf_right_pos ();
00228   virtual string    get_leaf_string ();
00229   virtual font      get_leaf_font ();
00230   virtual color     get_leaf_color ();
00231   virtual language  get_leaf_language ();
00232   virtual tree      get_leaf_tree ();
00233   virtual lazy      get_leaf_lazy ();
00234   virtual SI        get_leaf_offset (string search);
00235 
00236   /******************************** animations *******************************/
00237 
00238   virtual int    anim_length ();
00239   virtual bool   anim_started ();
00240   virtual bool   anim_finished ();
00241   virtual void   anim_start_at (time_t at);
00242   virtual void   anim_finish_now ();
00243   virtual time_t anim_next_update ();
00244           void   anim_check_invalid (bool& flag, time_t& at, rectangles& rs);
00245   virtual void   anim_get_invalid (bool& flag, time_t& at, rectangles& rs);
00246 
00247   /********************************* obsolete ********************************/
00248 
00249   friend struct page_box_rep; // temporary friends for accessing x0 and y0
00250   friend struct lazy_paragraph_rep;
00251   friend class  phrase_box_rep;
00252   friend class  remember_box_rep;
00253   friend void make_eps (url dest, box b, int dpi= 600);
00254 };
00255 ABSTRACT_NULL_CODE(box);
00256 
00257 extern int box_count;
00258 inline box_rep::box_rep (path ip2):
00259   x0(0), y0(0), x1(0), y1(0), x2(0), y2(0), x3(0), y3(0), x4(0), y4(0),
00260   ip (ip2) { TM_DEBUG(box_count++); }
00261 inline box_rep::~box_rep () { TM_DEBUG(box_count--); }
00262 inline bool box_rep::test_in (SI x, SI y) {
00263   return (x>=x1) && (x<x2) && (y>=y1) && (y<y2); }
00264 inline SI box_rep::w () { return x2-x1; }
00265 inline SI box_rep::h () { return y2-y1; }
00266 inline SI& box_rep::sx (int i) { return subbox(i)->x0; }
00267 inline SI& box_rep::sy (int i) { return subbox(i)->y0; }
00268 inline SI box_rep::sx1 (int i) { box b= subbox(i); return b->x0+ b->x1; }
00269 inline SI box_rep::sy1 (int i) { box b= subbox(i); return b->y0+ b->y1; }
00270 inline SI box_rep::sx2 (int i) { box b= subbox(i); return b->x0+ b->x2; }
00271 inline SI box_rep::sy2 (int i) { box b= subbox(i); return b->y0+ b->y2; }
00272 inline SI box_rep::sx3 (int i) { box b= subbox(i); return b->x0+ b->x3; }
00273 inline SI box_rep::sy3 (int i) { box b= subbox(i); return b->y0+ b->y3; }
00274 inline SI box_rep::sx4 (int i) { box b= subbox(i); return b->x0+ b->x4; }
00275 inline SI box_rep::sy4 (int i) { box b= subbox(i); return b->y0+ b->y4; }
00276 
00277 inline box box::operator [] (int i) { return rep->subbox(i); }
00278 inline int N (box b) { return b.rep->subnr(); }
00279 tm_ostream& operator << (tm_ostream& out, box b);
00280 SI   get_delta (SI x, SI x1, SI x2);
00281 bool outside (SI x, SI delta, SI x1, SI x2);
00282 void make_eps (url dest, box b, int dpi);
00283 path find_innermost_scroll (box b, path p);
00284 path find_scrolled_tree_path (box b, path sp, SI x, SI y, SI delta);
00285 void find_canvas_info (box b, path sp, SI& x, SI& y, SI& sx, SI& sy,
00286                      rectangle& outer, rectangle& inner);
00287 
00288 extern bool   refresh_needed;
00289 extern time_t refresh_next;
00290 void          refresh_at (time_t t);
00291 
00292 #define DECORATION        (-1)
00293 #define DECORATION_LEFT   (-2)
00294 #define DECORATION_MIDDLE (-3)
00295 #define DECORATION_RIGHT  (-4)
00296 #define DETACHED          (-5)
00297 #define is_accessible(p) ((is_nil (p)) || ((p)->item >= 0))
00298 #define is_decoration(p) ((!is_nil (p)) && ((p)->item < 0))
00299 inline path descend (path ip, int i) {
00300   return (is_nil (ip) || (ip->item >= 0))? path (i, ip): ip; }
00301 inline path decorate () {
00302   return path (DECORATION); }
00303 inline path decorate (path ip) {
00304   return (is_nil (ip) || (ip->item >= 0))? path (DECORATION, ip): ip; }
00305 inline path decorate_left (path ip) {
00306   return (is_nil (ip) || (ip->item >= 0))? path (DECORATION_LEFT, ip): ip; }
00307 inline path decorate_middle (path ip) {
00308   return (is_nil (ip) || (ip->item >= 0))? path (DECORATION_MIDDLE, ip): ip; }
00309 inline path decorate_right (path ip) {
00310   return (is_nil (ip) || (ip->item >= 0))? path (DECORATION_RIGHT, ip): ip; }
00311 path descend_decode (path ip, int side);
00312 
00313 inline bool box_rep::accessible () { return is_accessible (find_lip ()); }
00314 inline bool box_rep::decoration () { return is_decoration (find_lip ()); }
00315 
00316 tree attach_dip (tree ref, path ip);
00317 #define attach_here(t,ip) attach_dip(t,ip),ip
00318 #define attach_deco(t,ip) attach_dip(t,decorate(ip)),decorate(ip)
00319 #define attach_left(t,ip) attach_dip(t,decorate_left(ip)),decorate_left(ip)
00320 #define attach_middle(t,ip) \
00321   attach_dip(t,decorate_middle(ip)),decorate_middle(ip)
00322 #define attach_right(t,ip) attach_dip(t,decorate_right(ip)),decorate_right(ip)
00323 
00324 /******************************************************************************
00325 * The graphical selection class (continued)
00326 ******************************************************************************/
00327 
00328 struct gr_selection_rep: concrete_struct {
00329   string type;
00330   array<path> cp;
00331   array<point> pts;
00332   point p;
00333   SI dist;
00334   curve c;
00335 };
00336 CONCRETE_CODE(gr_selection);
00337 
00338 #endif // defined BOXES_H