2
/******************************************************************************
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
******************************************************************************/
13
#include "edit_main.hpp"
14
#include "tm_widget.hpp"
15
#include "tm_buffer.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"
32
/******************************************************************************
33
* Constructors and destructor
34
******************************************************************************/
36
editor_rep::editor_rep ():
37
attribute_widget_rep (dis),
38
drd (buf->abbr, std_drd), et (buf->t) {}
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) {}
44
edit_main_rep::edit_main_rep (server_rep* sv, display dis, tm_buffer buf):
45
editor_rep (sv, dis, buf), props (UNKNOWN)
47
notify_change (THE_TREE);
48
tp= correct_cursor (et, path (0));
51
edit_main_rep::~edit_main_rep () {}
54
new_editor (server_rep* sv, tm_buffer buf) {
55
return new edit_main_rep (sv, current_display (), buf);
58
/******************************************************************************
60
******************************************************************************/
63
edit_main_rep::set_property (scheme_tree what, scheme_tree val) {
68
edit_main_rep::set_bool_property (string what, bool val) {
69
props (what)= (val? string ("true"): string ("false"));
73
edit_main_rep::set_int_property (string what, int val) {
74
props (what)= as_tree (val);
78
edit_main_rep::set_string_property (string what, string val) {
83
edit_main_rep::get_property (scheme_tree what) {
88
edit_main_rep::get_bool_property (string what) {
89
return as_bool (props [what]);
93
edit_main_rep::get_int_property (string what) {
94
return as_int (props [what]);
98
edit_main_rep::get_string_property (string what) {
99
return as_string (props [what]);
102
/******************************************************************************
104
******************************************************************************/
107
edit_main_rep::clear_buffer () {
108
assign (path (), tree (DOCUMENT, tree ("")));
112
edit_main_rep::new_window () {
116
edit_main_rep::clone_window () {
120
edit_main_rep::tex_buffer () {
124
edit_main_rep::get_name () {
129
edit_main_rep::focus_on_this_editor () {
130
sv->focus_on_editor (this);
133
/******************************************************************************
135
******************************************************************************/
138
edit_main_rep::set_page_parameters () {
139
if (attached ()) this << emit_invalidate_all ();
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");
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);
155
if (type == "user") return;
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);
173
edit_main_rep::set_page_medium (string medium) {
174
init_env (PAGE_MEDIUM, medium);
175
set_page_parameters ();
179
edit_main_rep::set_page_type (string type) {
180
init_env (PAGE_TYPE, type);
181
set_page_parameters ();
185
edit_main_rep::set_page_orientation (string orientation) {
186
init_env (PAGE_ORIENTATION, orientation);
187
set_page_parameters ();
190
/******************************************************************************
192
******************************************************************************/
194
string printing_dpi ("600");
195
string printing_cmd ("lpr");
196
string printing_on ("a4");
199
edit_main_rep::print (url name, bool conform, int first, int last) {
200
bool pdf= (suffix (name) == "pdf");
202
if (pdf) name= url_temp (".ps");
204
string medium = env->get_string (PAGE_MEDIUM);
205
if (conform && (medium == "papyrus")) conform= false;
206
if ((!conform) && (medium == "automatic")) {
208
"Error: you should switch to ``paper'' or ``papyrus'' page type",
213
// Set environment variables for printing
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");
224
// Typeset pages for printing
226
box the_box= typeset_as_document (env, et, path ());
228
// Determine parameters for printer device
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;
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);
253
printer (dis, name, dpi, pages, page_type, landsc, w/cm, h/cm);
254
for (i=start; i<end; i++) {
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 ();
264
system ("ps2pdf", name, orig);
270
edit_main_rep::print_to_file (url name, string first, string last) {
271
print (name, false, as_int (first), as_int (last));
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);
283
edit_main_rep::export_ps (url name, string first, string last) {
284
print (name, true, as_int (first), as_int (last));
287
/******************************************************************************
288
* Evaluation of expressions
289
******************************************************************************/
292
edit_main_rep::footer_eval (string s) {
293
string r= object_to_string (eval (s));
294
set_message (r, "evaluate expression");
298
edit_main_rep::the_line () {
299
path p= search_parent_upwards (DOCUMENT);
300
return copy (subtree (et, p));
304
edit_main_rep::the_buffer () {
309
edit_main_rep::the_path () {
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);
320
if (lan == "scheme") {
322
tree u= sv->evaluate ("scheme", "default", t);
323
if (!is_document (u)) u= tree (DOCUMENT, u);
327
else if (connection_declared (lan)) {
332
set_message ("Package#'" * lan * "'#not declared",
333
"Evaluate#'" * lan * "'#expression");
337
/******************************************************************************
339
******************************************************************************/
342
edit_main_rep::show_tree () {
347
edit_main_rep::show_env () {
352
edit_main_rep::show_path () {
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";
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";
372
edit_main_rep::show_meminfo () {
377
edit_main_rep::edit_special () {
381
edit_main_rep::edit_test () {