0
|
1 /*
|
|
2 * $Id: screen.c,v 1.7 2002/06/22 13:26:21 hiroo Exp $
|
|
3 */
|
|
4
|
|
5 /*
|
|
6 * FreeWnn is a network-extensible Kana-to-Kanji conversion system.
|
|
7 * This file is part of FreeWnn.
|
|
8 *
|
|
9 * Copyright Kyoto University Research Institute for Mathematical Sciences
|
|
10 * 1987, 1988, 1989, 1990, 1991, 1992
|
|
11 * Copyright OMRON Corporation. 1987, 1988, 1989, 1990, 1991, 1992, 1999
|
|
12 * Copyright ASTEC, Inc. 1987, 1988, 1989, 1990, 1991, 1992
|
|
13 * Copyright FreeWnn Project 1999, 2000, 2002
|
|
14 *
|
|
15 * Maintainer: FreeWnn Project <freewnn@tomo.gr.jp>
|
|
16 *
|
|
17 * This program is free software; you can redistribute it and/or modify
|
|
18 * it under the terms of the GNU General Public License as published by
|
|
19 * the Free Software Foundation; either version 2 of the License, or
|
|
20 * (at your option) any later version.
|
|
21 *
|
|
22 * This program is distributed in the hope that it will be useful,
|
|
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
25 * GNU General Public License for more details.
|
|
26 *
|
|
27 * You should have received a copy of the GNU General Public License
|
|
28 * along with this program; if not, write to the Free Software
|
|
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
30 */
|
|
31 #ifdef HAVE_CONFIG_H
|
|
32 # include <config.h>
|
|
33 #endif
|
|
34
|
|
35 #include <stdio.h>
|
|
36 #if STDC_HEADERS
|
|
37 # include <string.h>
|
|
38 #else
|
|
39 # if HAVE_STRINGS_H
|
|
40 # include <strings.h>
|
|
41 # endif
|
|
42 #endif /* STDC_HEADERS */
|
|
43
|
|
44 #include "commonhd.h"
|
|
45 #include "wnn_config.h"
|
|
46 #include "sdefine.h"
|
|
47 #include "sheader.h"
|
|
48 #include "wnn_os.h"
|
|
49 #include "buffer.h"
|
|
50
|
|
51 /*
|
|
52 このファイルは、画面制御部分とのインターフェースを行う関数を
|
|
53 定義している。これらの関数を用いずに、画面を制御してはならない。
|
|
54 このファイルからextern されている関数を示す。
|
|
55 なお、画面の制御は、c_b->buffer の中でのインデックスを用いて
|
|
56 行われる。今、c_b->buffer の中のどの部分が画面に出されている
|
|
57 かは意識しなくてよい。
|
|
58
|
|
59 t_move(x) :
|
|
60 カーソルを x に飛ばす。リドローが必要 (反転、カセンの
|
|
61 ため) な部分も勝手に考えて行って来れる。
|
|
62 t_redraw_move(x , start , end,clr_l) :
|
|
63 buffer の中で、start から end までのバッファの内容が
|
|
64 変えられた時に、カーソルをx に飛ばすのに用いる。
|
|
65 print_buf_msg(msg) :
|
|
66 メッセージ部分を表示する。
|
|
67 disp_mode():
|
|
68 romkan のモードを表示する。
|
|
69 disp_mode_line():
|
|
70 romkan のモードを表示する。
|
|
71 t_print_l():
|
|
72 画面をリドローする。
|
|
73 t_throw():
|
|
74 カーソルを飛ばす
|
|
75 init_screen():
|
|
76 画面関係(vst)をイニシャライズし、画面表示を行う。
|
|
77 */
|
|
78
|
|
79 /* 文字の画面上での大きさを返す。*/
|
|
80
|
|
81 static int col = 0; /** startichiからの画面上のカーソル位置 */
|
|
82 static int oldmaxcol = 0; /** redraw sita tokini doko made mae ni kaita data ga nokotteiruka wo simesu */
|
|
83
|
|
84 #define CHAR_BYTE 2
|
|
85
|
|
86 #define w_putchar_move(x) {col += w_putchar(x);}
|
|
87 #define putchar_move(x) {col += 1; putchar_norm(x);}
|
|
88 #define putchar_move1(x) {col += 1; putchar1(x);}
|
|
89
|
|
90 #define throw0(x) throw_c((x) + c_b->start_col)
|
|
91 /*
|
|
92 #define throw(x) {int tmptmp = (x);if(cs == 0 || col != tmptmp){throw0((col = tmptmp) + 1);}}
|
|
93 */
|
|
94
|
|
95 /* カーソルをcol に飛ばすのには、throwを
|
|
96 用いる。 */
|
|
97 #define MARJIN 1 /* カーソルが右端からこれだけの所にくれば、次の画面に行く */
|
|
98
|
|
99 static void t_cont_line_note ();
|
|
100 static int find_character_on_that_col (), set_vst ();
|
|
101
|
|
102 void
|
|
103 throw (x)
|
|
104 int x;
|
|
105 {
|
|
106 throw0 ((col = x) + 1);
|
|
107 }
|
|
108
|
|
109 int
|
|
110 char_len (x)
|
|
111 w_char x;
|
|
112 {
|
|
113 return ((*char_len_func) (x));
|
|
114 }
|
|
115
|
|
116 /* vst をセットし直して、リドローする*/
|
|
117 void
|
|
118 t_redraw_one_line ()
|
|
119 {
|
|
120 if (c_b->vst)
|
|
121 {
|
|
122 t_cont_line_note ();
|
|
123 }
|
|
124 else
|
|
125 {
|
|
126 t_cont_line_note_delete ();
|
|
127 }
|
|
128 t_print_line (c_b->vst, c_b->maxlen, 1);
|
|
129 }
|
|
130
|
|
131 void
|
|
132 init_screen ()
|
|
133 {
|
|
134 int tmp;
|
|
135
|
|
136 oldmaxcol = 0;
|
|
137 tmp = cur_ichi (c_b->t_c_p, 0);
|
|
138 if ((tmp >= c_b->vlen - c_b->duplicate) && (tmp % (c_b->vlen - c_b->duplicate)) < c_b->duplicate - 1)
|
|
139 {
|
|
140 c_b->vst = find_character_on_that_col ((tmp / (c_b->vlen - c_b->duplicate) - 1) * (c_b->vlen - c_b->duplicate), 0);
|
|
141 }
|
|
142 else
|
|
143 {
|
|
144 c_b->vst = find_character_on_that_col ((tmp / (c_b->vlen - c_b->duplicate)) * (c_b->vlen - c_b->duplicate), 0);
|
|
145 }
|
|
146 if (c_b->maxlen || *c_b->buf_msg)
|
|
147 t_print_l ();
|
|
148 }
|
|
149
|
|
150 /* hituyouga areba vst wo settosinaosite, settosinaosita tokiniha 1 wo kaesu */
|
|
151 int
|
|
152 check_vst ()
|
|
153 {
|
|
154 int k = -1;
|
|
155
|
|
156 if ((c_b->t_c_p < c_b->vst) || (cur_ichi (c_b->t_c_p, c_b->vst) >= (c_b->vlen - MARJIN)) || (cur_ichi (c_b->t_m_start, c_b->vst) > (c_b->vlen - MARJIN)))
|
|
157 {
|
|
158 k = set_vst ();
|
|
159 }
|
|
160 if (k == -1)
|
|
161 {
|
|
162 return (0);
|
|
163 }
|
|
164 else
|
|
165 {
|
|
166 return (1);
|
|
167 }
|
|
168 }
|
|
169
|
|
170 int
|
|
171 t_redraw_move (x, start, end, clr_l)
|
|
172 int x;
|
|
173 int start;
|
|
174 int end;
|
|
175 int clr_l;
|
|
176 {
|
|
177 (*t_redraw_move_func) (x, start, end, clr_l);
|
|
178 return (0);
|
|
179 }
|
|
180
|
|
181 int
|
|
182 t_move (x)
|
|
183 int x;
|
|
184 {
|
|
185 int old_cp = c_b->t_c_p;
|
|
186
|
|
187 if (((c_b->hanten >> 2) & 0x3) != ((c_b->hanten >> 4) & 0x3))
|
|
188 {
|
|
189 t_redraw_move_normal (x, min (old_cp, x), max (old_cp, x), 0);
|
|
190 return (0);
|
|
191 }
|
|
192 if (x >= c_b->maxlen)
|
|
193 x = c_b->maxlen;
|
|
194 c_b->t_c_p = x;
|
|
195 if (check_vst ())
|
|
196 {
|
|
197 t_redraw_one_line ();
|
|
198 }
|
|
199 throw (cur_ichi (c_b->t_c_p, c_b->vst));
|
|
200 flush ();
|
|
201 return (0);
|
|
202 }
|
|
203
|
|
204 int
|
|
205 t_print_l ()
|
|
206 {
|
|
207 (*t_print_l_func) ();
|
|
208 return (0);
|
|
209 }
|
|
210
|
|
211 #define set_screen_reverse(X,Y){set_hanten_ul(c_b->hanten & X, c_b->hanten & Y);}
|
|
212 #define reset_screen_reverse(X,Y){flushw_buf(); if(c_b->hanten & X)h_r_off();if(c_b->hanten & Y)u_s_off(); flush();}
|
|
213
|
|
214 #define set_screen_bold(X){flushw_buf(); set_bold(c_b->hanten & X);}
|
|
215 #define reset_screen_bold(X){flushw_buf(); reset_bold(c_b->hanten & X);flush();}
|
|
216
|
|
217 /* st must be bigger than vst */
|
|
218
|
|
219
|
|
220 /* このファイルで一番重要な関数。
|
|
221 c_b->buffer の中で、st から end までで画面に現れている所(vstより先)を
|
|
222 表示し直し、行末処理もする。
|
|
223 リバースの状況は、c_b->hantenによって決められる。
|
|
224 */
|
|
225
|
|
226 void
|
|
227 t_print_line (st, end, clr_l)
|
|
228 int st, end, clr_l;
|
|
229 {
|
|
230 register int k;
|
|
231 register int col1;
|
|
232 register int end_of_line = maxlength - disp_mode_length - 1 - c_b->start_col;
|
|
233 int tmp;
|
|
234
|
|
235 int mst = min (c_b->t_m_start, c_b->t_c_p);
|
|
236 int mend = max (c_b->t_m_start, c_b->t_c_p);
|
|
237
|
|
238 int bst = c_b->t_b_st;
|
|
239 int bend = c_b->t_b_end;
|
|
240 int bold = 0;
|
|
241
|
|
242 if (end > c_b->maxlen)
|
|
243 end = c_b->maxlen;
|
|
244 col1 = cur_ichi (st, c_b->vst);
|
|
245 if (col1 == -1)
|
|
246 {
|
|
247 col1 = 0;
|
|
248 k = st = c_b->vst;
|
|
249 }
|
|
250 else
|
|
251 {
|
|
252 k = st;
|
|
253 }
|
|
254
|
|
255 for (; end_of_line <= col1; end_of_line += maxlength);
|
|
256
|
|
257 throw (col1);
|
|
258 if (mst >= 0)
|
|
259 {
|
|
260 if (st < mst)
|
|
261 {
|
|
262 set_screen_reverse (0x01, 0x02);
|
|
263 for (k = st; k < mst; k++)
|
|
264 {
|
|
265
|
|
266 if (bold == 0 && k >= bst && k < bend)
|
|
267 {
|
|
268 set_screen_bold (0x40);
|
|
269 bold = 1;
|
|
270 }
|
|
271 else if (bold && (k < bst || k >= bend))
|
|
272 {
|
|
273 reset_screen_bold (0x40);
|
|
274 set_screen_reverse (0x01, 0x02);
|
|
275 bold = 0;
|
|
276 }
|
|
277 if (k >= end)
|
|
278 {
|
|
279 reset_screen_reverse (0x01, 0x02);
|
|
280 reset_screen_bold (0x40);
|
|
281 bold = 0;
|
|
282 goto normal_out;
|
|
283 }
|
|
284 tmp = char_len (c_b->buffer[k]);
|
|
285 if (tmp + col > c_b->vlen)
|
|
286 {
|
|
287 reset_screen_reverse (0x01, 0x02);
|
|
288 reset_screen_bold (0x40);
|
|
289 bold = 0;
|
|
290 goto end_syori;
|
|
291 }
|
|
292 w_putchar_move (c_b->buffer[k]);
|
|
293 if (col > end_of_line - CHAR_BYTE)
|
|
294 {
|
|
295 flushw_buf ();
|
|
296 if (col < end_of_line)
|
|
297 {
|
|
298 reset_screen_reverse (0x01, 0x02);
|
|
299 reset_screen_bold (0x40);
|
|
300 bold = 0;
|
|
301 putchar_move (' ');
|
|
302 set_screen_reverse (0x01, 0x02);
|
|
303 if (k >= bst && k < bend)
|
|
304 {
|
|
305 set_screen_bold (0x40);
|
|
306 bold = 1;
|
|
307 }
|
|
308 }
|
|
309 throw (end_of_line);
|
|
310 end_of_line += maxlength;
|
|
311 }
|
|
312
|
|
313 }
|
|
314 reset_screen_reverse (0x01, 0x02);
|
|
315 reset_screen_bold (0x40);
|
|
316 bold = 0;
|
|
317 }
|
|
318 if (k < mend)
|
|
319 {
|
|
320 set_screen_reverse (0x04, 0x08);
|
|
321 for (; k < mend; k++)
|
|
322 {
|
|
323
|
|
324 if (bold == 0 && k >= bst && k < bend)
|
|
325 {
|
|
326 set_screen_bold (0x40);
|
|
327 bold = 1;
|
|
328 }
|
|
329 else if (bold && (k < bst || k >= bend))
|
|
330 {
|
|
331 reset_screen_bold (0x40);
|
|
332 set_screen_reverse (0x04, 0x08);
|
|
333 bold = 0;
|
|
334 }
|
|
335
|
|
336 if (k >= end)
|
|
337 {
|
|
338 reset_screen_reverse (0x04, 0x08);
|
|
339 reset_screen_bold (0x40);
|
|
340 bold = 0;
|
|
341 goto normal_out;
|
|
342 }
|
|
343 tmp = char_len (c_b->buffer[k]);
|
|
344 if (col + tmp > c_b->vlen)
|
|
345 {
|
|
346 reset_screen_reverse (0x04, 0x08);
|
|
347 reset_screen_bold (0x40);
|
|
348 bold = 0;
|
|
349 goto end_syori;
|
|
350 }
|
|
351 w_putchar_move (c_b->buffer[k]);
|
|
352 if (col > end_of_line - CHAR_BYTE)
|
|
353 {
|
|
354 flushw_buf ();
|
|
355 if (col < end_of_line)
|
|
356 {
|
|
357 reset_screen_reverse (0x04, 0x08);
|
|
358 reset_screen_bold (0x40);
|
|
359 bold = 0;
|
|
360 putchar_move (' ');
|
|
361 set_screen_reverse (0x04, 0x08);
|
|
362 if (k >= bst && k < bend)
|
|
363 {
|
|
364 set_screen_bold (0x40);
|
|
365 bold = 1;
|
|
366 }
|
|
367 }
|
|
368 throw (end_of_line);
|
|
369 end_of_line += maxlength;
|
|
370 }
|
|
371 }
|
|
372 reset_screen_reverse (0x04, 0x08);
|
|
373 reset_screen_bold (0x40);
|
|
374 bold = 0;
|
|
375 }
|
|
376 }
|
|
377 if (k < c_b->maxlen && k < end)
|
|
378 {
|
|
379 set_screen_reverse (0x10, 0x20);
|
|
380 for (; k < c_b->maxlen; k++)
|
|
381 {
|
|
382
|
|
383 if (bold == 0 && k >= bst && k < bend)
|
|
384 {
|
|
385 set_screen_bold (0x40);
|
|
386 bold = 1;
|
|
387 }
|
|
388 else if (bold && (k < bst || k >= bend))
|
|
389 {
|
|
390 reset_screen_bold (0x40);
|
|
391 set_screen_reverse (0x10, 0x20);
|
|
392 bold = 0;
|
|
393 }
|
|
394
|
|
395 if (k >= end)
|
|
396 {
|
|
397 reset_screen_reverse (0x10, 0x20);
|
|
398 reset_screen_bold (0x40);
|
|
399 bold = 0;
|
|
400 goto normal_out;
|
|
401 }
|
|
402 tmp = char_len (c_b->buffer[k]);
|
|
403 if (col + tmp > c_b->vlen)
|
|
404 {
|
|
405 reset_screen_reverse (0x10, 0x20);
|
|
406 reset_screen_bold (0x40);
|
|
407 bold = 0;
|
|
408 goto end_syori;
|
|
409 }
|
|
410 w_putchar_move (c_b->buffer[k]);
|
|
411 if (col > end_of_line - CHAR_BYTE)
|
|
412 {
|
|
413 flushw_buf ();
|
|
414 if (col < end_of_line)
|
|
415 {
|
|
416 reset_screen_reverse (0x10, 0x20);
|
|
417 reset_screen_bold (0x40);
|
|
418 bold = 0;
|
|
419 putchar_move (' ');
|
|
420 set_screen_reverse (0x10, 0x20);
|
|
421 if (k >= bst && k < bend)
|
|
422 {
|
|
423 set_screen_bold (0x40);
|
|
424 bold = 1;
|
|
425 }
|
|
426 }
|
|
427 throw (end_of_line);
|
|
428 end_of_line += maxlength;
|
|
429 }
|
|
430 }
|
|
431 reset_screen_reverse (0x10, 0x20);
|
|
432 reset_screen_bold (0x40);
|
|
433 bold = 0;
|
|
434 }
|
|
435
|
|
436 normal_out:
|
|
437 if (clr_l == 1)
|
|
438 {
|
|
439 clr_line ();
|
|
440 oldmaxcol = col;
|
|
441 }
|
|
442 else if (clr_l == 2)
|
|
443 {
|
|
444 clr_line ();
|
|
445 oldmaxcol = col;
|
|
446 /* k = oldmaxcol - col;
|
|
447 oldmaxcol = col;
|
|
448 if(k > 0){
|
|
449 push_hrus();
|
|
450 for(; k > 0 ; k--){
|
|
451 putchar_move1(' ');
|
|
452 }
|
|
453 pop_hrus();
|
|
454 }
|
|
455 */
|
|
456 }
|
|
457 else
|
|
458 {
|
|
459 oldmaxcol = max (oldmaxcol, col);
|
|
460 }
|
|
461 flush ();
|
|
462 return;
|
|
463
|
|
464 end_syori:
|
|
465 for (k = col; k <= c_b->vlen; k++)
|
|
466 {
|
|
467 putchar_move ('$');
|
|
468 }
|
|
469 oldmaxcol = col;
|
|
470 flush ();
|
|
471 return;
|
|
472 }
|
|
473
|
|
474 /* 行の先頭処理 */
|
|
475 static void
|
|
476 t_cont_line_note ()
|
|
477 {
|
|
478 throw0 (0);
|
|
479 putchar_norm ('$');
|
|
480 }
|
|
481
|
|
482 /* 行の先頭処理 */
|
|
483 void
|
|
484 t_cont_line_note_delete ()
|
|
485 {
|
|
486 throw0 (0);
|
|
487 putchar_norm (' ');
|
|
488 }
|
|
489
|
|
490 /*画面のコラム0がバッファーのstart_point の時、コラムc にある文字を返す*/
|
|
491 static int
|
|
492 find_character_on_that_col (c, start_point)
|
|
493 int c; /* colum */
|
|
494 int start_point; /* in_buffer as vst */
|
|
495 {
|
|
496
|
|
497 int k;
|
|
498 register int end_of_line = maxlength - disp_mode_length - 1 - c_b->start_col;
|
|
499 int len = 0;
|
|
500 for (k = start_point; k <= c_b->maxlen; k++)
|
|
501 {
|
|
502 len += char_len (c_b->buffer[k]);
|
|
503 if (len >= c)
|
|
504 return (k);
|
|
505 if (len > end_of_line - CHAR_BYTE)
|
|
506 {
|
|
507 len = end_of_line;
|
|
508 end_of_line += maxlength;
|
|
509 }
|
|
510 }
|
|
511 /*error but default to 0 */
|
|
512 return (0);
|
|
513 }
|
|
514
|
|
515 /*画面のコラム0がバッファーのstart_point の時、文字cpの画面上の位置を返す。*/
|
|
516 /* static */
|
|
517 int
|
|
518 cur_ichi (cp, start_point)
|
|
519 register int cp;
|
|
520 int start_point;
|
|
521 {
|
|
522 register int k;
|
|
523 register int end_of_line = maxlength - disp_mode_length - 1 - c_b->start_col;
|
|
524 register int len = 0;
|
|
525 if (cp < start_point)
|
|
526 return (-1);
|
|
527 if (cp > c_b->maxlen)
|
|
528 cp = c_b->maxlen;
|
|
529
|
|
530 for (k = start_point; k < cp; k++)
|
|
531 {
|
|
532 len += char_len (c_b->buffer[k]);
|
|
533 if (len > end_of_line - CHAR_BYTE)
|
|
534 {
|
|
535 len = end_of_line;
|
|
536 end_of_line += maxlength;
|
|
537 }
|
|
538 }
|
|
539 return (len);
|
|
540 }
|
|
541
|
|
542
|
|
543 void
|
|
544 print_buf_msg (msg)
|
|
545 char *msg;
|
|
546 {
|
|
547 push_cursor ();
|
|
548 throw_c (0);
|
|
549 printf (msg);
|
|
550 pop_cursor ();
|
|
551 flush ();
|
|
552 }
|
|
553
|
|
554 /* vstをセットする*/
|
|
555 /* returns -1 if not changed
|
|
556 else returns new start colum
|
|
557 */
|
|
558 static int
|
|
559 set_vst ()
|
|
560 {
|
|
561 int tmp;
|
|
562 int vst1;
|
|
563
|
|
564 tmp = cur_ichi (c_b->t_c_p, 0);
|
|
565 vst1 = find_character_on_that_col ((tmp / (c_b->vlen - c_b->duplicate)) * (c_b->vlen - c_b->duplicate), 0);
|
|
566 if (cur_ichi (c_b->t_m_start, vst1) >= c_b->vlen)
|
|
567 {
|
|
568 vst1 = c_b->t_c_p;
|
|
569 }
|
|
570 c_b->vst = vst1;
|
|
571 return (vst1);
|
|
572 }
|
|
573
|
|
574
|
|
575 static char rk_modes[80];
|
|
576 extern char *romkan_dispmode (), *romkan_offmode ();
|
|
577
|
|
578 char *
|
|
579 get_rk_modes ()
|
|
580 {
|
|
581 char *p;
|
|
582
|
|
583 strcpy (rk_modes, (NULL == (p = romkan_dispmode ())? "[ ]" : p));
|
|
584 if ((p = (char *) strchr (rk_modes, ':')) != NULL && *(p + 1))
|
|
585 {
|
|
586 set_cur_env (*(++p));
|
|
587 *p = '\0';
|
|
588 }
|
|
589 return (rk_modes);
|
|
590 }
|
|
591
|
|
592 int
|
|
593 disp_mode ()
|
|
594 {
|
|
595 push_cursor ();
|
|
596 throw_col (0);
|
|
597 printf ("%s", get_rk_modes ());
|
|
598 pop_cursor ();
|
|
599 flush ();
|
|
600 return (0);
|
|
601 }
|
|
602
|
|
603 /* cursor status is saved before call it */
|
|
604 void
|
|
605 display_henkan_off_mode ()
|
|
606 {
|
|
607 char *p;
|
|
608
|
|
609 strcpy (rk_modes, (NULL == (p = romkan_offmode ())? "[---]" : p));
|
|
610 throw_col (0);
|
|
611 printf ("%s", rk_modes);
|
|
612 kk_restore_cursor ();
|
|
613 flush ();
|
|
614 }
|
|
615
|
|
616
|
|
617 /* カーソルを飛ばす*/
|
|
618 void
|
|
619 t_throw ()
|
|
620 {
|
|
621 throw0 (col + 1);
|
|
622 flush ();
|
|
623 }
|
|
624
|
|
625
|
|
626 void
|
|
627 clr_line ()
|
|
628 {
|
|
629 clr_end_screen ();
|
|
630 }
|