Back to index

texmacs  1.0.7.15
tm_server.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : tm_server.cpp
00004 * DESCRIPTION: The TeXmacs server
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 "config.h"
00013 #include "tm_server.hpp"
00014 #include "drd_std.hpp"
00015 #include "convert.hpp"
00016 #include "connect.hpp"
00017 #include "sys_utils.hpp"
00018 #include "file.hpp"
00019 #include "dictionary.hpp"
00020 #include "tm_link.hpp"
00021 #include "socket_notifier.hpp"
00022 #include "new_style.hpp"
00023 
00024 server* the_server= NULL;
00025 bool texmacs_started= false;
00026 url tm_init_file= url_none ();
00027 url my_init_file= url_none ();
00028 string my_init_cmds= "";
00029 
00030 /******************************************************************************
00031 * Execution of commands
00032 ******************************************************************************/
00033 
00034 void reset_inclusions ();
00035 extern string printing_dpi;
00036 extern string printing_cmd;
00037 extern string printing_on;
00038 extern int nr_windows;
00039 
00040 /******************************************************************************
00041 * Texmacs server constructor and destructor
00042 ******************************************************************************/
00043 
00044 void
00045 texmacs_interpose_handler () {
00046   if (the_server != NULL)
00047     (*the_server)->interpose_handler ();
00048 }
00049 
00050 void
00051 texmacs_wait_handler (string message, string arg, int level) {
00052   (void) level;
00053   if (texmacs_started && the_server != NULL)
00054     (*the_server)->wait_handler (message, arg);
00055 }
00056 
00057 server
00058 get_server () {
00059   ASSERT (the_server != NULL, "TeXmacs server not yet started");
00060   return *the_server;
00061 }
00062 
00063 bool
00064 in_presentation_mode () {
00065   return get_server () -> in_full_screen_mode ();
00066 }
00067 
00068 tree
00069 get_subtree (path p) {
00070   return get_server()->get_editor()->the_subtree (p);
00071 }
00072 
00073 void
00074 gui_set_output_language (string lan) {
00075   set_output_language (lan);
00076   get_server () -> refresh ();
00077   gui_refresh ();
00078 }
00079 
00080 server_rep::server_rep () {}
00081 server_rep::~server_rep () {}
00082 
00083 tm_server_rep::tm_server_rep (): vw (NULL), def_sfactor (5) {
00084   the_server= tm_new<server> (this);
00085   initialize_scheme ();
00086   gui_interpose (texmacs_interpose_handler);
00087   set_wait_handler (texmacs_wait_handler);
00088   if (is_none (tm_init_file))
00089     tm_init_file= "$TEXMACS_PATH/progs/init-texmacs.scm";
00090   if (is_none (my_init_file))
00091     my_init_file= "$TEXMACS_HOME_PATH/progs/my-init-texmacs.scm";
00092   bench_start ("initialize scheme");
00093   if (exists (tm_init_file)) exec_file (tm_init_file);
00094   if (exists (my_init_file)) exec_file (my_init_file);
00095   bench_cumul ("initialize scheme");
00096   if (my_init_cmds != "") {
00097     my_init_cmds= "(begin" * my_init_cmds * ")";
00098     exec_delayed (scheme_cmd (my_init_cmds));
00099   }
00100 #ifdef OS_GNU_LINUX
00101   return; // in order to avoid segmentation faults
00102 #elif defined OS_POWERPC_GNU_LINUX
00103   return; // in order to avoid segmentation faults
00104 #endif
00105 }
00106 
00107 tm_server_rep::~tm_server_rep () {}
00108 server::server (): rep (tm_new<tm_server_rep> ()) {}
00109 
00110 /******************************************************************************
00111 * Get and set objects associated to server
00112 ******************************************************************************/
00113 
00114 server_rep*
00115 tm_server_rep::get_server () {
00116   return this;
00117 }
00118 
00119 bool
00120 tm_server_rep::has_view () {
00121   return vw != NULL;
00122 }
00123 
00124 bool
00125 tm_server_rep::has_window () {
00126   return vw != NULL && vw->win != NULL;
00127 }
00128 
00129 tm_view
00130 tm_server_rep::get_view (bool must_be_valid) {
00131   ASSERT (!must_be_valid || vw != NULL, "no active view");
00132   return vw;
00133 }
00134 
00135 void
00136 tm_server_rep::set_view (tm_view vw2) {
00137   vw= vw2;
00138   if (vw != NULL)
00139     the_drd= vw->ed->drd;
00140 }
00141 
00142 tm_buffer
00143 tm_server_rep::get_buffer () {
00144   tm_view vw= get_view ();
00145   return vw->buf;
00146 }
00147 
00148 editor
00149 tm_server_rep::get_editor () {
00150   tm_view vw= get_view ();
00151   // cout << "Get editor" << vw->ed << "\n";
00152   return vw->ed;
00153 }
00154 
00155 tm_window
00156 tm_server_rep::get_window () {
00157   tm_view vw= get_view ();
00158   ASSERT (vw->win != NULL, "no window attached to view");
00159   return vw->win;
00160 }
00161 
00162 int
00163 tm_server_rep::get_nr_windows () {
00164   return nr_windows;
00165 }
00166 
00167 /******************************************************************************
00168 * Miscellaneous routines
00169 ******************************************************************************/
00170 
00171 void
00172 tm_server_rep::style_clear_cache () {
00173   style_invalidate_cache ();
00174 
00175   int i, j, n= N(bufs);
00176   for (i=0; i<n; i++) {
00177     tm_buffer buf= ((tm_buffer) bufs[i]);
00178     for (j=0; j<N(buf->vws); j++)
00179       ((tm_view) (buf->vws[j]))->ed->init_style ();
00180   }
00181 }
00182 
00183 void
00184 tm_server_rep::refresh () {
00185   path p= windows_list ();
00186   while (!is_nil (p)) {
00187     tm_view vw= window_find_view (p->item);
00188     vw->win->refresh ();
00189     p= p->next;
00190   }
00191   
00192 }
00193 
00194 void
00195 tm_server_rep::interpose_handler () {
00196 #ifdef QTTEXMACS
00197   // TeXmacs/Qt handles delayed messages and socket notification
00198   // in its own runloop
00199 #ifndef QTPIPES
00200   perform_select ();
00201 #endif
00202   process_all_pipes ();
00203 #else
00204   perform_select ();
00205   exec_pending_commands ();
00206 #endif
00207 
00208   int i,j;
00209   for (i=0; i<N(bufs); i++) {
00210     tm_buffer buf= (tm_buffer) bufs[i];
00211     for (j=0; j<N(buf->vws); j++) {
00212       tm_view vw= (tm_view) buf->vws[j];
00213       if (vw->win != NULL) vw->ed->apply_changes ();
00214     }
00215     for (j=0; j<N(buf->vws); j++) {
00216       tm_view vw= (tm_view) buf->vws[j];
00217       if (vw->win != NULL) vw->ed->animate ();
00218     }
00219   }
00220 
00221   windows_refresh ();
00222 }
00223 
00224 void
00225 tm_server_rep::wait_handler (string message, string arg) {
00226   show_wait_indicator (get_window () -> win, translate (message), arg);
00227 }
00228 
00229 void
00230 tm_server_rep::set_script_status (int i) {
00231   script_status= i;
00232 }
00233 
00234 void
00235 tm_server_rep::focus_on_editor (editor ed) {
00236   int i,j;
00237   for (i=0; i<N(bufs); i++) {
00238     tm_buffer buf= (tm_buffer) bufs[i];
00239     for (j=0; j<N(buf->vws); j++) {
00240       tm_view vw= (tm_view) buf->vws[j];
00241       if (vw->ed == ed) {
00242        set_view (vw);
00243        return;
00244       }
00245     }
00246   }
00247   FAILED ("invalid situation");
00248 }
00249 
00250 void
00251 tm_server_rep::set_printing_command (string cmd) {
00252   printing_cmd= cmd;
00253 }
00254 
00255 void
00256 tm_server_rep::set_printer_page_type (string type) {
00257   printing_on= type;
00258 }
00259 
00260 string
00261 tm_server_rep::get_printer_page_type () {
00262   return printing_on;
00263 }
00264 
00265 void
00266 tm_server_rep::set_printer_dpi (string dpi) {
00267   printing_dpi= dpi;
00268 }
00269 
00270 void
00271 tm_server_rep::set_default_shrinking_factor (int sf) {
00272   def_sfactor= sf;
00273 }
00274 
00275 int
00276 tm_server_rep::get_default_shrinking_factor () {
00277   return def_sfactor;
00278 }
00279 
00280 void
00281 tm_server_rep::image_gc (string which) {
00282   ::image_gc (which);
00283   typeset_update_all ();
00284 }
00285 
00286 void
00287 tm_server_rep::inclusions_gc (string which) {
00288   (void) which;
00289   reset_inclusions ();
00290   typeset_update_all ();
00291 }
00292 
00293 void
00294 tm_server_rep::typeset_update (path p) {
00295   int i, j, n= N(bufs);
00296   for (i=0; i<n; i++) {
00297     tm_buffer buf= ((tm_buffer) bufs[i]);
00298     for (j=0; j<N(buf->vws); j++)
00299       ((tm_view) (buf->vws[j]))->ed->typeset_invalidate (p);
00300   }
00301 }
00302 
00303 void
00304 tm_server_rep::typeset_update_all () {
00305   int i, j, n= N(bufs);
00306   for (i=0; i<n; i++) {
00307     tm_buffer buf= ((tm_buffer) bufs[i]);
00308     for (j=0; j<N(buf->vws); j++)
00309       ((tm_view) (buf->vws[j]))->ed->typeset_invalidate_all ();
00310   }
00311 }
00312 
00313 bool
00314 tm_server_rep::is_yes (string s) {
00315   s= locase_all (s);
00316   return
00317     (s == "ano") || (s == "a") ||
00318     (s == "yes") || (s == "y") ||
00319     (s == "oui") || (s == "o") ||
00320     (s == "ja") || (s == "j") ||
00321     (s == "si") || (s == "s") ||
00322     (s == "sim") || (s == "s") ||
00323     (s == "tak") || (s == "t");
00324 }
00325 
00326 void
00327 tm_server_rep::quit () {
00328   close_all_pipes ();
00329   call ("quit-TeXmacs-scheme");
00330   clear_pending_commands ();
00331   exit (0);
00332 }
00333 
00334 /******************************************************************************
00335 * System commands
00336 ******************************************************************************/
00337 
00338 void
00339 tm_server_rep::shell (string s) {
00340   system (s);
00341 }