Back to index

texmacs  1.0.7.15
modifier_boxes.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : modifier.cpp
00004 * DESCRIPTION: a modifier box modifies the behaviour of another box
00005 *              as to cursor movements etc. , but displays in the same way
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 #include "Boxes/modifier.hpp"
00014 #include "Boxes/composite.hpp"
00015 
00016 /******************************************************************************
00017 * Modifier boxes
00018 ******************************************************************************/
00019 
00020 modifier_box_rep::modifier_box_rep (path ip, box b2):
00021   box_rep (ip), b (b2)
00022 {
00023   x1= b->x1; y1= b->y1;
00024   x2= b->x2; y2= b->y2;
00025   x3= b->x3; y3= b->y3;
00026   x4= b->x4; y4= b->y4;
00027 }
00028 
00029 modifier_box_rep::~modifier_box_rep () {}
00030 
00031 int
00032 modifier_box_rep::subnr () {
00033   return 1;
00034 }
00035 
00036 box
00037 modifier_box_rep::subbox (int i) { (void) i;
00038   return b;
00039 }
00040 
00041 void
00042 modifier_box_rep::display (renderer ren) {
00043   (void) ren;
00044 }
00045 
00046 tree
00047 modifier_box_rep::action (tree t, SI x, SI y, SI delta) {
00048   return b->action (t, x, y, delta);
00049 }
00050 
00051 void
00052 modifier_box_rep::loci (SI x, SI y, SI delta,
00053                      list<string>& ids, rectangles& rs)
00054 {
00055   return b->loci (x, y, delta, ids, rs);
00056 }
00057 
00058 void
00059 modifier_box_rep::collect_page_numbers (hashmap<string,tree>& h, tree page) {
00060   b->collect_page_numbers (h, page);
00061 }
00062 
00063 path
00064 modifier_box_rep::find_tag (string name) {
00065   return b->find_tag (name);
00066 }
00067 
00068 modifier_box_rep::operator tree () {
00069   return (tree) b;
00070 }
00071 
00072 double modifier_box_rep::left_slope () { return b->left_slope (); }
00073 double modifier_box_rep::right_slope () { return b->right_slope (); }
00074 SI modifier_box_rep::left_correction () { return b->left_correction (); }
00075 SI modifier_box_rep::right_correction () { return b->right_correction (); }
00076 SI modifier_box_rep::lsub_correction () {
00077   return b->lsub_correction (); }
00078 SI modifier_box_rep::lsup_correction () {
00079   return b->lsup_correction (); }
00080 SI modifier_box_rep::rsub_correction () {
00081   return b->rsub_correction (); }
00082 SI modifier_box_rep::rsup_correction () {
00083   return b->rsup_correction (); }
00084 SI modifier_box_rep::sub_lo_base (int level) {
00085   return b->sub_lo_base (level); }
00086 SI modifier_box_rep::sub_hi_lim  (int level) {
00087   return b->sub_hi_lim (level); }
00088 SI modifier_box_rep::sup_lo_lim  (int level) {
00089   return b->sup_lo_lim (level); }
00090 SI modifier_box_rep::sup_lo_base (int level) {
00091   return b->sup_lo_base (level); }
00092 SI modifier_box_rep::sup_hi_lim  (int level) {
00093   return b->sup_hi_lim (level); }
00094 
00095 /******************************************************************************
00096 * New routines concerning the cursor
00097 ******************************************************************************/
00098 
00099 path
00100 modifier_box_rep::find_box_path (SI x, SI y, SI delta, bool force) {
00101   return path (0, b->find_box_path (x, y, delta, force));
00102 }
00103 
00104 path
00105 modifier_box_rep::find_lip () {
00106   return b->find_lip ();
00107 }
00108 
00109 path
00110 modifier_box_rep::find_rip () {
00111   return b->find_rip ();
00112 }
00113 
00114 path
00115 modifier_box_rep::find_left_box_path () {
00116   return path (0, b->find_left_box_path ());
00117 }
00118 
00119 path
00120 modifier_box_rep::find_right_box_path () {
00121   return path (0, b->find_right_box_path ());
00122 }
00123 
00124 path
00125 modifier_box_rep::find_box_path (path p, bool& found) {
00126   return path (0, b->find_box_path (p, found));
00127 }
00128 
00129 path
00130 modifier_box_rep::find_tree_path (path bp) {
00131   return b->find_tree_path (bp->next);
00132 }
00133 
00134 cursor
00135 modifier_box_rep::find_cursor (path bp) {
00136   return b->find_cursor (bp->next);
00137 }
00138 
00139 selection
00140 modifier_box_rep::find_selection (path lbp, path rbp) {
00141   return b->find_selection (lbp->next, rbp->next);
00142 }
00143 
00144 gr_selections
00145 modifier_box_rep::graphical_select (SI x, SI y, SI dist) {
00146   return b->graphical_select (x- sx(0), y- sy(0), dist);
00147 }
00148 
00149 gr_selections
00150 modifier_box_rep::graphical_select (SI x1, SI y1, SI x2, SI y2) {
00151   return b->graphical_select (x1- sx(0), y1- sy(0), x2- sx(0), y2- sy(0));
00152 }
00153 
00154 /******************************************************************************
00155 * Animations
00156 ******************************************************************************/
00157 
00158 int modifier_box_rep::anim_length () { return b->anim_length (); }
00159 bool modifier_box_rep::anim_started () { return b->anim_started (); }
00160 bool modifier_box_rep::anim_finished () { return b->anim_finished (); }
00161 void modifier_box_rep::anim_finish_now () { b->anim_finish_now (); }
00162 void modifier_box_rep::anim_start_at (time_t at) { b->anim_start_at (at); }
00163 void modifier_box_rep::anim_get_invalid (bool& f, time_t& at, rectangles& rs) {
00164   b->anim_get_invalid (f, at, rs); }
00165 
00166 /******************************************************************************
00167 * Symbol boxes
00168 ******************************************************************************/
00169 
00170 class symbol_box_rep: public modifier_box_rep {
00171   int n;
00172 public:
00173   symbol_box_rep (path ip, box b, int n);
00174   operator tree () { return tree (TUPLE, "symbol", subbox(0)); }
00175   path find_box_path (SI x, SI y, SI delta, bool force);
00176 };
00177 
00178 symbol_box_rep::symbol_box_rep (path ip, box b2, int n2):
00179   modifier_box_rep (ip, b2), n (n2) {}
00180 
00181 static box
00182 subbox (box b, path p) {
00183   if (is_nil (p)) return b;
00184   return subbox (b[p->item], p->next);
00185 }
00186 
00187 path
00188 symbol_box_rep::find_box_path (SI x, SI y, SI delta, bool force) {
00189   path p= modifier_box_rep::find_box_path (x, y, delta, force);
00190   box leaf= ::subbox (box (this), path_up (p));
00191   if (is_accessible (leaf->ip) || force) {
00192     if (last_item (p) <= (n>>1)) return path_up (p) * 0;
00193     else return path_up (p) * n;
00194   }
00195   else return p;
00196 }
00197 
00198 /******************************************************************************
00199 * Shorter boxes are used for hyphenation
00200 ******************************************************************************/
00201 
00202 class shorter_box_rep: public modifier_box_rep {
00203   int pos, len;
00204 public:
00205   shorter_box_rep (path ip, box b, int len);
00206   operator tree () { return tuple ("shorter", subbox(0)); }
00207   path   find_box_path (SI x, SI y, SI delta, bool force);
00208   path   find_rip ();
00209   path   find_right_box_path ();
00210   int    get_leaf_left_pos ();
00211   int    get_leaf_right_pos ();
00212   string get_leaf_string ();
00213   font   get_leaf_font ();
00214   color  get_leaf_color ();
00215   SI     get_leaf_offset (string search);
00216 };
00217 
00218 shorter_box_rep::shorter_box_rep (path ip, box b2, int len2):
00219   modifier_box_rep (ip, b2), pos (b->get_leaf_left_pos ()), len (len2) {}
00220 
00221 path
00222 shorter_box_rep::find_box_path (SI x, SI y, SI delta, bool force) {
00223   path p= modifier_box_rep::find_box_path (x, y, delta, force);
00224   box leaf= ::subbox (box (this), path_up (p));
00225   if ((is_accessible (leaf->ip) || force) && (last_item (p) > len))
00226     return path_up (p) * len;
00227   else return p;
00228 }
00229 
00230 path
00231 shorter_box_rep::find_rip () {
00232   path p= modifier_box_rep::find_rip ();
00233   if (is_accessible (ip) && (!is_nil(p)) && (p->item > (pos+ len)))
00234     return descend (p->next, pos+ len);
00235   else return p;  
00236 }
00237 
00238 path
00239 shorter_box_rep::find_right_box_path () {
00240   path bp= b->find_right_box_path ();
00241   return path (0, path_up (bp) * min (last_item (bp), len));
00242 }
00243 
00244 int
00245 shorter_box_rep::get_leaf_left_pos () {
00246   return pos;
00247 }
00248 
00249 int
00250 shorter_box_rep::get_leaf_right_pos () {
00251   return pos+ len;
00252 }
00253 
00254 string
00255 shorter_box_rep::get_leaf_string () {
00256   return b->get_leaf_string () (0, len);
00257 }
00258 
00259 font
00260 shorter_box_rep::get_leaf_font () {
00261   return b->get_leaf_font ();
00262 }
00263 
00264 color
00265 shorter_box_rep::get_leaf_color () {
00266   return b->get_leaf_color ();
00267 }
00268 
00269 SI
00270 shorter_box_rep::get_leaf_offset (string search) {
00271   return b->get_leaf_offset (search);
00272 }
00273 
00274 /******************************************************************************
00275 * Frozen boxes
00276 ******************************************************************************/
00277 
00278 class frozen_box_rep: public modifier_box_rep {
00279 public:
00280   frozen_box_rep (path ip, box b);
00281   operator tree () { return tree (TUPLE, "frozen", subbox(0)); }
00282   path find_lip ();
00283   path find_rip ();
00284 };
00285 
00286 frozen_box_rep::frozen_box_rep (path ip, box b2):
00287   modifier_box_rep (ip, b2) {}
00288 
00289 path
00290 frozen_box_rep::find_lip () {
00291   return box_rep::find_lip ();
00292 }
00293 
00294 path
00295 frozen_box_rep::find_rip () {
00296   return box_rep::find_rip ();
00297 }
00298 
00299 /******************************************************************************
00300 * macro expansions
00301 ******************************************************************************/
00302 
00303 struct macro_box_rep: public composite_box_rep {
00304   font big_fn; // big character font if non nil
00305   macro_box_rep (path ip, box b, font big_fn);
00306   operator tree () { return tree (TUPLE, "macro", (tree) bs[0]); }
00307 
00308   int       find_child (SI x, SI y, SI delta, bool force);
00309   path      find_box_path (SI x, SI y, SI delta, bool force);
00310   path      find_lip ();
00311   path      find_rip ();
00312   path      find_box_path (path p, bool& found);
00313   path      find_tree_path (path bp);
00314   cursor    find_cursor (path bp);
00315   selection find_selection (path lbp, path rbp);
00316   string    get_leaf_string ();
00317   font      get_leaf_font ();
00318   color     get_leaf_color ();
00319   SI        get_leaf_offset (string search);
00320 
00321   double left_slope () { return bs[0]->left_slope(); }
00322   double right_slope () { return bs[0]->right_slope(); }
00323   SI left_correction () { return bs[0]->left_correction(); }
00324   SI right_correction () { return bs[0]->right_correction(); }
00325   SI lsub_correction () { return bs[0]->lsub_correction(); }
00326   SI lsup_correction () { return bs[0]->lsup_correction(); }
00327   SI rsub_correction () { return bs[0]->rsub_correction(); }
00328   SI rsup_correction () { return bs[0]->rsup_correction(); }
00329   SI sub_lo_base (int l) {
00330     // second test separates small and large big operators
00331     return (!is_nil (big_fn)) && ((y2-y1) <= 3*big_fn->yx)?
00332       y1 - (l>0? 0: big_fn->yshift): box_rep::sub_lo_base (l); }
00333   SI sub_hi_lim (int l) {
00334     // second test separates small and large size big operators
00335     return (!is_nil (big_fn)) && ((y2-y1) <= 3*big_fn->yx)?
00336       y1 - (l>0? 0: big_fn->yshift) +
00337         bs[0]->sub_hi_lim (l) - bs[0]->sub_lo_base (l):
00338       box_rep::sub_hi_lim (l); }
00339   SI sup_lo_base (int l) {
00340     if (is_nil (big_fn)) return box_rep::sup_lo_base (l);
00341     SI syx= big_fn->yx * script (big_fn->size, 1) / big_fn->size;
00342     if ((y2-y1) <= 3*big_fn->yx) syx -= (l<0? 0: big_fn->yshift);
00343     return y2- syx; }
00344 };
00345 
00346 macro_box_rep::macro_box_rep (path ip, box b, font fn):
00347   composite_box_rep (ip), big_fn (fn) {
00348     insert (b, 0, 0); position (); finalize (); }
00349 int macro_box_rep::find_child (SI x, SI y, SI delta, bool force) {
00350   (void) x; (void) y; (void) delta; (void) force; return -1; }
00351 path macro_box_rep::find_box_path (SI x, SI y, SI delta, bool force) {
00352   return box_rep::find_box_path (x, y, delta, force); }
00353 path macro_box_rep::find_lip () {
00354   return box_rep::find_lip (); }
00355 path macro_box_rep::find_rip () {
00356   return box_rep::find_rip (); }
00357 path macro_box_rep::find_box_path (path p, bool& found) {
00358   return box_rep::find_box_path (p, found); }
00359 path macro_box_rep::find_tree_path (path bp) {
00360   return box_rep::find_tree_path (bp); }
00361 cursor macro_box_rep::find_cursor (path bp) {
00362   return box_rep::find_cursor (bp); }
00363 selection macro_box_rep::find_selection (path lbp, path rbp) {
00364   return box_rep::find_selection (lbp, rbp); }
00365 string macro_box_rep::get_leaf_string () {
00366   return bs[0]->get_leaf_string (); }
00367 font macro_box_rep::get_leaf_font () {
00368   return bs[0]->get_leaf_font (); }
00369 color macro_box_rep::get_leaf_color () {
00370   return bs[0]->get_leaf_color (); }
00371 SI macro_box_rep::get_leaf_offset (string search) {
00372   return bs[0]->get_leaf_offset (search); }
00373 
00374 /******************************************************************************
00375 * box construction routines
00376 ******************************************************************************/
00377 
00378 box
00379 symbol_box (path ip, box b, int n) {
00380   return tm_new<symbol_box_rep> (ip, b, n);
00381 }
00382 
00383 box
00384 shorter_box (path ip, box b, int len) {
00385   return tm_new<shorter_box_rep> (ip, b, len);
00386 }
00387 
00388 box
00389 frozen_box (path ip, box b) {
00390   return tm_new<frozen_box_rep> (ip, b);
00391 }
00392 
00393 box
00394 macro_box (path ip, box b, font big_fn) {
00395   return tm_new<macro_box_rep> (ip, b, big_fn);
00396 }