Back to index

texmacs  1.0.7.15
bridge_formatting.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : bridge_formatting.cpp
00004 * DESCRIPTION: Bridge between logical and physical local enviroment changes
00005 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #include "bridge.hpp"
00013 
00014 class bridge_formatting_rep: public bridge_rep {
00015 protected:
00016   string v;
00017   int    last;
00018   bridge body;
00019 
00020 public:
00021   bridge_formatting_rep (typesetter ttt, tree st, path ip, string v);
00022   void initialize ();
00023 
00024   void notify_assign (path p, tree u);
00025   void notify_insert (path p, tree u);
00026   void notify_remove (path p, int nr);
00027   bool notify_macro  (int type, string var, int level, path p, tree u);
00028   void notify_change ();
00029 
00030   void my_exec_until (path p);
00031   bool my_typeset_will_be_complete ();
00032   void my_typeset (int desired_status);
00033 };
00034 
00035 bridge_formatting_rep::bridge_formatting_rep (
00036   typesetter ttt, tree st, path ip, string v2):
00037     bridge_rep (ttt, st, ip), v (v2)
00038 {
00039   initialize ();
00040 }
00041 
00042 void
00043 bridge_formatting_rep::initialize () {
00044   last= N(st)-1;
00045   if (is_nil(body)) body= make_bridge (ttt, st[last], descend (ip, last));
00046   else replace_bridge (body, st[last], descend (ip, last));
00047 }
00048 
00049 bridge
00050 bridge_formatting (typesetter ttt, tree st, path ip, string v) {
00051   return tm_new<bridge_formatting_rep> (ttt, st, ip, v);
00052 }
00053 
00054 /******************************************************************************
00055 * Event notification
00056 ******************************************************************************/
00057 
00058 void
00059 bridge_formatting_rep::notify_assign (path p, tree u) {
00060   // cout << "Assign " << p << ", " << u << " in " << st << "\n";
00061   ASSERT (!is_nil (p) || is_func (u, TFORMAT), "nil path");
00062   if (is_nil (p)) {
00063     st=u;
00064     initialize ();
00065   }
00066   else {
00067     bool mp_flag= is_multi_paragraph (st);
00068     if (p->item == last) {
00069       if (is_atom (p)) body= make_bridge (ttt, u, descend (ip, last));
00070       else body->notify_assign (p->next, u);
00071       st= substitute (st, p->item, body->st);
00072     }
00073     else st= substitute (st, p, u);
00074     if (mp_flag != is_multi_paragraph (st)) initialize ();
00075   }
00076   status= CORRUPTED;
00077 }
00078 
00079 void
00080 bridge_formatting_rep::notify_insert (path p, tree u) {
00081   // cout << "Insert " << p << ", " << u << " in " << st << "\n";
00082   ASSERT (!is_nil (p), "nil path");
00083   if (is_atom (p) || (p->item != last)) bridge_rep::notify_insert (p, u);
00084   else {
00085     bool mp_flag= is_multi_paragraph (st);
00086     body->notify_insert (p->next, u);
00087     st= substitute (st, last, body->st);
00088     if (mp_flag != is_multi_paragraph (st)) initialize ();
00089   }
00090   status= CORRUPTED;
00091 }
00092 
00093 void
00094 bridge_formatting_rep::notify_remove (path p, int nr) {
00095   // cout << "Remove " << p << ", " << nr << " in " << st << "\n";
00096   ASSERT (!is_nil (p), "nil path");
00097   if (is_atom (p) || (p->item != last)) bridge_rep::notify_remove (p, nr);
00098   else {
00099     bool mp_flag= is_multi_paragraph (st);
00100     body->notify_remove (p->next, nr);
00101     st= substitute (st, last, body->st);
00102     if (mp_flag != is_multi_paragraph (st)) initialize ();
00103   }
00104   status= CORRUPTED;
00105 }
00106 
00107 bool
00108 bridge_formatting_rep::notify_macro (
00109   int type, string var, int l, path p, tree u)
00110 {
00111   bool flag= body->notify_macro (type, var, l, p, u);
00112   if (flag) status= CORRUPTED;
00113   return flag;
00114 }
00115 
00116 void
00117 bridge_formatting_rep::notify_change () {
00118   status= CORRUPTED;
00119   body->notify_change ();
00120 }
00121 
00122 /******************************************************************************
00123 * Typesetting
00124 ******************************************************************************/
00125 
00126 void
00127 bridge_formatting_rep::my_exec_until (path p) {
00128   if (p->item != last) return;
00129   tree oldv= env->read (v);
00130   tree newv= oldv * st (0, last);
00131   env->monitored_write_update (v, newv);
00132   body->exec_until (p->next);
00133 }
00134 
00135 bool
00136 bridge_formatting_rep::my_typeset_will_be_complete () {
00137   if (status != CORRUPTED) return false;
00138   return body->my_typeset_will_be_complete ();
00139 }
00140 
00141 void
00142 bridge_formatting_rep::my_typeset (int desired_status) {
00143   tree new_format= env->read (v) * st (0, last);
00144   tree old_format= env->local_begin (v, new_format);
00145   if (v != CELL_FORMAT) ttt->insert_marker (st, ip);
00146   body->typeset (desired_status);
00147   env->local_end (v, old_format);
00148 }