~ubuntu-branches/ubuntu/hardy/texmacs/hardy

« back to all changes in this revision

Viewing changes to src/Edit/Editor/edit_main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ralf Treinen
  • Date: 2004-04-19 20:34:00 UTC
  • Revision ID: james.westby@ubuntu.com-20040419203400-g4e34ih0315wcn8v
Tags: upstream-1.0.3-R2
ImportĀ upstreamĀ versionĀ 1.0.3-R2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/******************************************************************************
 
3
* MODULE     : editor.cpp
 
4
* DESCRIPTION: routines for the editor
 
5
* COPYRIGHT  : (C) 1999  Joris van der Hoeven
 
6
*******************************************************************************
 
7
* This software falls under the GNU general public license and comes WITHOUT
 
8
* ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
 
9
* If you don't have this file, write to the Free Software Foundation, Inc.,
 
10
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
11
******************************************************************************/
 
12
 
 
13
#include "edit_main.hpp"
 
14
#include "tm_widget.hpp"
 
15
#include "tm_buffer.hpp"
 
16
#include "file.hpp"
 
17
#include "sys_utils.hpp"
 
18
#include "PsDevice/printer.hpp"
 
19
#include "PsDevice/page_type.hpp"
 
20
#include "convert.hpp"
 
21
#include "connect.hpp"
 
22
#include "typesetter.hpp"
 
23
#include "drd_std.hpp"
 
24
 
 
25
#ifdef OS_WIN32
 
26
#include "dlfcn.hpp"
 
27
#else
 
28
#include <dlfcn.h>
 
29
#endif
 
30
#include <setjmp.h>
 
31
 
 
32
/******************************************************************************
 
33
* Constructors and destructor
 
34
******************************************************************************/
 
35
 
 
36
editor_rep::editor_rep ():
 
37
  attribute_widget_rep (dis),
 
38
  drd (buf->abbr, std_drd), et (buf->t) {}
 
39
 
 
40
editor_rep::editor_rep (server_rep* sv2, display dis, tm_buffer buf2):
 
41
  attribute_widget_rep (dis),
 
42
  sv (sv2), buf (buf2), drd (buf->abbr, std_drd), et (buf2->t) {}
 
43
 
 
44
edit_main_rep::edit_main_rep (server_rep* sv, display dis, tm_buffer buf):
 
45
  editor_rep (sv, dis, buf), props (UNKNOWN)
 
46
{
 
47
  notify_change (THE_TREE);
 
48
  tp= correct_cursor (et, path (0));
 
49
}
 
50
 
 
51
edit_main_rep::~edit_main_rep () {}
 
52
 
 
53
editor
 
54
new_editor (server_rep* sv, tm_buffer buf) {
 
55
  return new edit_main_rep (sv, current_display (), buf);
 
56
}
 
57
 
 
58
/******************************************************************************
 
59
* Properties
 
60
******************************************************************************/
 
61
 
 
62
void
 
63
edit_main_rep::set_property (scheme_tree what, scheme_tree val) {
 
64
  props (what)= val;
 
65
}
 
66
 
 
67
void
 
68
edit_main_rep::set_bool_property (string what, bool val) {
 
69
  props (what)= (val? string ("true"): string ("false"));
 
70
}
 
71
 
 
72
void
 
73
edit_main_rep::set_int_property (string what, int val) {
 
74
  props (what)= as_tree (val);
 
75
}
 
76
 
 
77
void
 
78
edit_main_rep::set_string_property (string what, string val) {
 
79
  props (what)= val;
 
80
}
 
81
 
 
82
scheme_tree
 
83
edit_main_rep::get_property (scheme_tree what) {
 
84
  return props [what];
 
85
}
 
86
 
 
87
bool
 
88
edit_main_rep::get_bool_property (string what) {
 
89
  return as_bool (props [what]);
 
90
}
 
91
 
 
92
int
 
93
edit_main_rep::get_int_property (string what) {
 
94
  return as_int (props [what]);
 
95
}
 
96
 
 
97
string
 
98
edit_main_rep::get_string_property (string what) {
 
99
  return as_string (props [what]);
 
100
}
 
101
 
 
102
/******************************************************************************
 
103
* Global routines
 
104
******************************************************************************/
 
105
 
 
106
void
 
107
edit_main_rep::clear_buffer () {
 
108
  assign (path (), tree (DOCUMENT, tree ("")));
 
109
}
 
110
 
 
111
void
 
112
edit_main_rep::new_window () {
 
113
}
 
114
 
 
115
void
 
116
edit_main_rep::clone_window () {
 
117
}
 
118
 
 
119
void
 
120
edit_main_rep::tex_buffer () {
 
121
}
 
122
 
 
123
url
 
124
edit_main_rep::get_name () {
 
125
  return buf->name;
 
126
}
 
127
 
 
128
void
 
129
edit_main_rep::focus_on_this_editor () {
 
130
  sv->focus_on_editor (this);
 
131
}
 
132
 
 
133
/******************************************************************************
 
134
* Printing
 
135
******************************************************************************/
 
136
 
 
137
void
 
138
edit_main_rep::set_page_parameters () {
 
139
  if (attached ()) this << emit_invalidate_all ();
 
140
 
 
141
  string medium     = get_init_string (PAGE_MEDIUM);
 
142
  string type       = get_init_string (PAGE_TYPE);
 
143
  string orientation= get_init_string (PAGE_ORIENTATION);
 
144
  bool   landscape  = (orientation == "landscape");
 
145
 
 
146
  if (medium == "automatic") {
 
147
    init_env (PAGE_ODD, "5mm");
 
148
    init_env (PAGE_EVEN, "5mm");
 
149
    init_env (PAGE_RIGHT, "5mm");
 
150
    init_env (PAGE_TOP, "5mm");
 
151
    init_env (PAGE_BOT, "5mm");
 
152
    notify_change (THE_AUTOMATIC_SIZE);
 
153
    return;
 
154
  }
 
155
  if (type == "user") return;
 
156
 
 
157
#define PAGE_INIT(feature) \
 
158
  init_env (feature, page_get_feature (type, feature, landscape))
 
159
  PAGE_INIT (PAR_WIDTH);
 
160
  PAGE_INIT (PAGE_ODD);
 
161
  PAGE_INIT (PAGE_EVEN);
 
162
  PAGE_INIT (PAGE_RIGHT);
 
163
  PAGE_INIT (PAGE_TOP);
 
164
  PAGE_INIT (PAGE_BOT);
 
165
  PAGE_INIT (PAGE_REDUCE_LEFT);
 
166
  PAGE_INIT (PAGE_REDUCE_RIGHT);
 
167
  PAGE_INIT (PAGE_REDUCE_TOP);
 
168
  PAGE_INIT (PAGE_REDUCE_BOT);
 
169
#undef PAGE_INIT
 
170
}
 
171
 
 
172
void
 
173
edit_main_rep::set_page_medium (string medium) {
 
174
  init_env (PAGE_MEDIUM, medium);
 
175
  set_page_parameters ();
 
176
}
 
177
 
 
178
void
 
179
edit_main_rep::set_page_type (string type) {
 
180
  init_env (PAGE_TYPE, type);
 
181
  set_page_parameters ();
 
182
}
 
183
 
 
184
void
 
185
edit_main_rep::set_page_orientation (string orientation) {
 
186
  init_env (PAGE_ORIENTATION, orientation);
 
187
  set_page_parameters ();
 
188
}
 
189
 
 
190
/******************************************************************************
 
191
* Printing
 
192
******************************************************************************/
 
193
 
 
194
string printing_dpi ("600");
 
195
string printing_cmd ("lpr");
 
196
string printing_on ("a4");
 
197
 
 
198
void
 
199
edit_main_rep::print (url name, bool conform, int first, int last) {
 
200
  bool pdf= (suffix (name) == "pdf");
 
201
  url orig= name;
 
202
  if (pdf) name= url_temp (".ps");
 
203
 
 
204
  string medium = env->get_string (PAGE_MEDIUM);
 
205
  if (conform && (medium == "papyrus")) conform= false;
 
206
  if ((!conform) && (medium == "automatic")) {
 
207
    set_message (
 
208
      "Error: you should switch to ``paper'' or ``papyrus'' page type",
 
209
      "print");
 
210
    return;
 
211
  }
 
212
 
 
213
  // Set environment variables for printing
 
214
 
 
215
  typeset_prepare ();
 
216
  env->write (DPI, printing_dpi);
 
217
  env->write (PAGE_REDUCE_LEFT, "0cm");
 
218
  env->write (PAGE_REDUCE_RIGHT, "0cm");
 
219
  env->write (PAGE_REDUCE_TOP, "0cm");
 
220
  env->write (PAGE_REDUCE_BOT, "0cm");
 
221
  env->write (PAGE_SHOW_HF, "true");
 
222
  if (!conform) env->write (PAGE_MEDIUM, "paper");
 
223
 
 
224
  // Typeset pages for printing
 
225
 
 
226
  box the_box= typeset_as_document (env, et, path ());
 
227
 
 
228
  // Determine parameters for printer device
 
229
 
 
230
  string page_type = printing_on;
 
231
  double w         = env->get_length (PAGE_WIDTH);
 
232
  double h         = env->get_length (PAGE_HEIGHT);
 
233
  double cm        = env->decode_length (string ("1cm"));
 
234
  bool   landsc    = (env->get_string (PAGE_ORIENTATION) == "landscape");
 
235
  int    dpi       = as_int (printing_dpi);
 
236
  int    start     = max (0, first-1);
 
237
  int    end       = min (N(the_box[0]), last);
 
238
  int    pages     = end-start;
 
239
  if (conform) {
 
240
    page_type= "user";
 
241
    SI bw= the_box[0][0]->w();
 
242
    SI bh= the_box[0][0]->h();
 
243
    string bws= as_string (bw) * "unit";
 
244
    string bhs= as_string (bh) * "unit";
 
245
    w= env->decode_length (bws);
 
246
    h= env->decode_length (bhs);
 
247
  }
 
248
 
 
249
  // Print pages
 
250
 
 
251
  int i;
 
252
  ps_device dev=
 
253
    printer (dis, name, dpi, pages, page_type, landsc, w/cm, h/cm);
 
254
  for (i=start; i<end; i++) {
 
255
    rectangles rs;
 
256
    the_box[0]->sx(i)= 0;
 
257
    the_box[0]->sy(i)= 0;
 
258
    the_box[0][i]->redraw (dev, path (0), rs);
 
259
    if (i<end-1) dev->next_page ();
 
260
  }
 
261
  delete dev;
 
262
 
 
263
  if (pdf) {
 
264
    system ("ps2pdf", name, orig);
 
265
    ::remove (name);
 
266
  }
 
267
}
 
268
 
 
269
void
 
270
edit_main_rep::print_to_file (url name, string first, string last) {
 
271
  print (name, false, as_int (first), as_int (last));
 
272
}
 
273
 
 
274
void
 
275
edit_main_rep::print_buffer (string first, string last) {
 
276
  url temp= url_temp (".ps");
 
277
  print (temp, false, as_int (first), as_int (last));
 
278
  system (printing_cmd, temp);
 
279
  ::remove (temp);
 
280
}
 
281
 
 
282
void
 
283
edit_main_rep::export_ps (url name, string first, string last) {
 
284
  print (name, true, as_int (first), as_int (last));
 
285
}
 
286
 
 
287
/******************************************************************************
 
288
* Evaluation of expressions
 
289
******************************************************************************/
 
290
 
 
291
void
 
292
edit_main_rep::footer_eval (string s) {
 
293
  string r= object_to_string (eval (s));
 
294
  set_message (r, "evaluate expression");
 
295
}
 
296
 
 
297
tree
 
298
edit_main_rep::the_line () {
 
299
  path p= search_parent_upwards (DOCUMENT);
 
300
  return copy (subtree (et, p));
 
301
}
 
302
 
 
303
tree
 
304
edit_main_rep::the_buffer () {
 
305
  return copy (et);
 
306
}
 
307
 
 
308
path
 
309
edit_main_rep::the_path () {
 
310
  return copy (tp);
 
311
}
 
312
 
 
313
void
 
314
edit_main_rep::process_input () {
 
315
  path p= search_upwards_compound ("input");
 
316
  if (nil (p) || (N (subtree (et, p)) != 2)) return;
 
317
  tree t= subtree (et, p) [1];
 
318
  string lan= get_env_string (PROG_LANGUAGE);
 
319
 
 
320
  if (lan == "scheme") {
 
321
    start_output ();
 
322
    tree u= sv->evaluate ("scheme", "default", t);
 
323
    if (!is_document (u)) u= tree (DOCUMENT, u);
 
324
    insert_tree (u);
 
325
    start_input ();
 
326
  }
 
327
  else if (connection_declared (lan)) {
 
328
    start_output ();
 
329
    feed_input (t);
 
330
  }
 
331
  else {
 
332
    set_message ("Package#'" * lan * "'#not declared",
 
333
                 "Evaluate#'" * lan * "'#expression");
 
334
  }
 
335
}
 
336
 
 
337
/******************************************************************************
 
338
* Miscellaneous
 
339
******************************************************************************/
 
340
 
 
341
void
 
342
edit_main_rep::show_tree () {
 
343
  cout << et << "\n";
 
344
}
 
345
 
 
346
void
 
347
edit_main_rep::show_env () {
 
348
  cout << env << "\n";
 
349
}
 
350
 
 
351
void
 
352
edit_main_rep::show_path () {
 
353
  cout << tp << "\n";
 
354
}
 
355
 
 
356
void
 
357
edit_main_rep::show_cursor () {
 
358
  cout << "Principal cursor: "
 
359
       << cu->ox << ", " << cu->oy << " [" << cu->delta << "]\n";
 
360
  cout << "Ghost cursor    : "
 
361
       << mv->ox << ", " << mv->oy << " [" << mv->delta << "]\n";
 
362
}
 
363
 
 
364
void
 
365
edit_main_rep::show_selection () {
 
366
  selection sel; selection_get (sel);
 
367
  cout << "physical  selection: " << start_p << " --- " << end_p << "\n";
 
368
  cout << "logical   selection: " << sel->start << " --- " << sel->end << "\n";
 
369
}
 
370
 
 
371
void
 
372
edit_main_rep::show_meminfo () {
 
373
  mem_info ();
 
374
}
 
375
 
 
376
void
 
377
edit_main_rep::edit_special () {
 
378
}
 
379
 
 
380
void
 
381
edit_main_rep::edit_test () {
 
382
  cout << "Test !\n";
 
383
}