1
|
0a1,97
|
2
|
> /*
|
3
|
> ** Module : Toolkit.c
|
4
|
> ** Abstract : ncurses library interface code
|
5
|
> **
|
6
|
> ** Modifications Copyright (c) 2005-2009, Golden Code Development Corporation.
|
7
|
> ** The original LGPL license terms apply
|
8
|
> **
|
9
|
> ** -#- -I- --Date-- --JPRM-- ----------------Description-----------------
|
10
|
> ** 001 NVS 20050915 @22725 First modification. Added two new functions
|
11
|
> ** suspend() and resume() to temporary suspend
|
12
|
> ** ncurses preserving the screen environment
|
13
|
> ** and restore it later.
|
14
|
> ** 002 NVS 20060118 @23962 drawBoxNative() function didn't have
|
15
|
> ** attribute parameter. Added.
|
16
|
> ** 003 NVS 20060118 @23970 blankBoxNative() function didn't have
|
17
|
> ** attribute parameter. Added.
|
18
|
> ** 004 NVS 20060124 @24047 Renamed addHorizontalLine and addString to
|
19
|
> ** addHorizontalLineNative and addStringNative
|
20
|
> ** respectively to allow addition of capture
|
21
|
> ** logic to Toolkit.java
|
22
|
> ** 005 GES 20060213 @24591 Added functions for pseudo-tty and process
|
23
|
> ** launching. Based on original work by EVL
|
24
|
> ** see his entry in @23680.
|
25
|
> ** 006 GES 20060217 @24651 Massive rework new features and for correct
|
26
|
> ** functioning of the redirected terminal
|
27
|
> ** output mode/terminal switching.
|
28
|
> ** 007 GES 20060222 @24652 Removed the redirected terminal support
|
29
|
> ** since ncurses cannot be made to properly
|
30
|
> ** handle all features needed.
|
31
|
> ** 008 GES 20060222 @24658 Changed some API names to match Java layer
|
32
|
> ** changes.
|
33
|
> ** 009 GES 20060322 @25183 Added terminal type control methods.
|
34
|
> ** 010 ECF 20060614 @27248 Changed keyboard timeout to 500 msec. This
|
35
|
> ** helps reduce flicker and wild cursor
|
36
|
> ** movements when repainting large screen areas
|
37
|
> ** because getch() causes NCURSES to sync() so
|
38
|
> ** reducing the number of times it is called
|
39
|
> ** causes sync() to be called less and thus
|
40
|
> ** there is less flashing.
|
41
|
> ** 011 GES 20060712 @28034 Process reaping fix by overriding SIGCHLD.
|
42
|
> ** 012 EVL 20060802 @28356 Adding implementation for the
|
43
|
> ** JNI setCursorStatus. The cursor is turned off
|
44
|
> ** when param is false and turned on when param
|
45
|
> ** is true. Returns previos state as boolean.
|
46
|
> ** 013 GES 20060817 @28657 Force the master and slave pty configurations
|
47
|
> ** to a true RAW mode.
|
48
|
> ** 014 NVS 20060821 @28702 curs_set failure should not be fatal.
|
49
|
> ** 015 GES 20060828 @28936 Disable sync during getch() to eliminate
|
50
|
> ** terminal corruption issues since ncurses is
|
51
|
> ** NOT thread safe. This change makes our 2
|
52
|
> ** thread approach (1 thread does getch() and
|
53
|
> ** all other ncurses processing is on another
|
54
|
> ** thread) safe enough to work reliably.
|
55
|
> ** 016 NVS 20070308 @32295 Reworked the process launch function to use
|
56
|
> ** fork() and pipe() calls instead of forkpty()
|
57
|
> ** and to leave unused stdio handles atatched to
|
58
|
> ** the parent's TTY.
|
59
|
> ** 017 NVS 20070309 @32354 Improved error handling in process launch
|
60
|
> ** method. Multiple negative error codes can be
|
61
|
> ** returned to report the precise reason.
|
62
|
> ** 018 NVS 20080212 @37026 Interactive processes are launched with some
|
63
|
> ** additional handling: the terminal gets
|
64
|
> ** cleared before the application, paused with
|
65
|
> ** the default "press space bar..." message
|
66
|
> ** when it's done, and stderr is redirected to
|
67
|
> ** stdout while it's running.
|
68
|
> ** The calling process is set up to ignore some
|
69
|
> ** job control related signals. This handling is
|
70
|
> ** inherited by child process as well.
|
71
|
> ** 019 GES 20080326 @37695 Modified the addStringNative method to take
|
72
|
> ** a byte[] instead of a string. This allows
|
73
|
> ** the peer code on the Java side to convert
|
74
|
> ** the UNICODE string into a properly encoded
|
75
|
> ** native byte array which can then be output
|
76
|
> ** here. This allows characters above the 7-bit
|
77
|
> ** ASCII range to be properly supported and is
|
78
|
> ** needed for I18N support.
|
79
|
> ** 020 CA 20081107 @40436 Removed all clipping code. Clipping is the
|
80
|
> ** responsability of the charva Toolkit class.
|
81
|
> ** 021 NVS 20090209 @41275 Added new method addArrayNative() which does
|
82
|
> ** bulk output of the screenful of the data,
|
83
|
> ** where every character position is either a
|
84
|
> ** skip indicator (-1) or a fully prepared code
|
85
|
> ** with character, attribute and color included.
|
86
|
> ** 022 SIY 20090702 @43031 Read screen size once at startup. This prevents
|
87
|
> ** mismatch between Java and C parts if terminal
|
88
|
> ** size changes at run time. Note that although this
|
89
|
> ** is desired behavior for our purposes, this might
|
90
|
> ** be inconvenient in general case.
|
91
|
> ** 023 LMR 20101129 Moved code dealing with child process management
|
92
|
> ** (initializeFileDescriptor(), logic in init()
|
93
|
> ** to ignore signals,
|
94
|
> ** Java_charva_awt_Toolkit_pseudoTerminalLaunch(),
|
95
|
> ** Java_charva_awt_Toolkit_pseudoTerminalWait())
|
96
|
> ** to p2j/src/native/process.c.
|
97
|
> */
|
98
|
>
|
99
|
45a143,145
|
100
|
> #include <signal.h>
|
101
|
> #include <termios.h>
|
102
|
> #include <fcntl.h>
|
103
|
51d150
|
104
|
< static void my_addch_with_clip(int chr_);
|
105
|
55,62d153
|
106
|
< // Here are the boundaries of the clipping rectangle.
|
107
|
< // Note that "right" refers to the righmost column INCLUDED in the rectangle
|
108
|
< // and "bottom" refers to the bottom row that is INCLUDED in the rectangle.
|
109
|
< static int left, top, right, bottom;
|
110
|
<
|
111
|
< // This is a local copy of the cursor position, used for clipping.
|
112
|
< static int cursorx=0, cursory=0;
|
113
|
<
|
114
|
65a157,165
|
115
|
> // pointer to the structure of the interactive terminal
|
116
|
> static SCREEN* terminal = NULL;
|
117
|
>
|
118
|
> // cache field IDs for performance
|
119
|
> static jfieldID jfd = NULL;
|
120
|
>
|
121
|
> // terminal size at the moment of initialization of the library
|
122
|
> static int base_rows = 0;
|
123
|
> static int base_cols = 0;
|
124
|
69a170,179
|
125
|
> void throwException(JNIEnv* env, char* name, char* msg)
|
126
|
> {
|
127
|
> jclass jcls = (*env)->FindClass(env, name);
|
128
|
>
|
129
|
> if (jcls != NULL)
|
130
|
> {
|
131
|
> (*env)->ThrowNew(env, jcls, msg);
|
132
|
> }
|
133
|
> }
|
134
|
>
|
135
|
167,168c277
|
136
|
< JNIEXPORT void JNICALL Java_charva_awt_Toolkit_init
|
137
|
< (JNIEnv *env, jobject jo)
|
138
|
---
|
139
|
> JNIEXPORT void JNICALL Java_charva_awt_Toolkit_init(JNIEnv *env, jobject jo)
|
140
|
170,178c279,311
|
141
|
< char *strcap;
|
142
|
< int i;
|
143
|
<
|
144
|
< initscr();
|
145
|
< keypad(stdscr, TRUE); // enable keyboard mapping
|
146
|
< timeout(100); // wait up to 100msec for input
|
147
|
< noecho(); /* don't echo input */
|
148
|
< raw();
|
149
|
< nonl();
|
150
|
---
|
151
|
> char *strcap;
|
152
|
> char *termname;
|
153
|
> int i;
|
154
|
>
|
155
|
> termname = getenv("TERM");
|
156
|
>
|
157
|
> if (termname == NULL || *termname == '\0')
|
158
|
> {
|
159
|
> termname = "vt100";
|
160
|
> }
|
161
|
>
|
162
|
> // use this instead of initscr because there is no way to query the
|
163
|
> // current terminal and when you use multiple terms, newterm overwrites
|
164
|
> // the current terminal... so you can never get it if you don't use
|
165
|
> // newterm directly
|
166
|
> terminal = newterm(termname, stdout, stdin);
|
167
|
>
|
168
|
> if (terminal == NULL)
|
169
|
> {
|
170
|
> char* spec = "Interactive terminal of type %s cannot be initialized.";
|
171
|
> char* errmsg = malloc(strlen(spec) + strlen(termname) + 1);
|
172
|
> sprintf(errmsg, spec, termname);
|
173
|
> throwException(env, "java/lang/IllegalStateException", errmsg);
|
174
|
> return;
|
175
|
> }
|
176
|
>
|
177
|
> keypad(stdscr, TRUE); // enable keyboard mapping
|
178
|
> timeout(500); // wait up to 500msec for input
|
179
|
> noecho(); // don't echo input
|
180
|
> raw();
|
181
|
> nonl();
|
182
|
> auto_getch_refresh(FALSE); // disable sync during getch()
|
183
|
> def_prog_mode(); // save our state (after our mode changes)
|
184
|
180c313
|
185
|
< hascolors = has_colors();
|
186
|
---
|
187
|
> hascolors = has_colors();
|
188
|
183,191c316,324
|
189
|
< /* For some reason, if the mouse_interval is nonzero, the button-presses
|
190
|
< * are reported very erratically. So we disable click resolution by
|
191
|
< * setting mouse_interval to 0.
|
192
|
< */
|
193
|
< mousemask(BUTTON1_RELEASED | BUTTON1_PRESSED |
|
194
|
< BUTTON2_RELEASED | BUTTON2_PRESSED |
|
195
|
< BUTTON3_RELEASED | BUTTON3_PRESSED,
|
196
|
< NULL);
|
197
|
< mouseinterval(0);
|
198
|
---
|
199
|
> /* For some reason, if the mouse_interval is nonzero, the button-presses
|
200
|
> * are reported very erratically. So we disable click resolution by
|
201
|
> * setting mouse_interval to 0.
|
202
|
> */
|
203
|
> mousemask(BUTTON1_RELEASED | BUTTON1_PRESSED |
|
204
|
> BUTTON2_RELEASED | BUTTON2_PRESSED |
|
205
|
> BUTTON3_RELEASED | BUTTON3_PRESSED,
|
206
|
> NULL);
|
207
|
> mouseinterval(0);
|
208
|
194c327,378
|
209
|
< atexit((void (*)(void))endwin);
|
210
|
---
|
211
|
> getmaxyx(stdscr, base_rows, base_cols);
|
212
|
>
|
213
|
> atexit((void (*)(void))endwin);
|
214
|
>
|
215
|
> }
|
216
|
>
|
217
|
> // simple reset of terminal type
|
218
|
> void restartTerminal(JNIEnv *env, char* termname)
|
219
|
> {
|
220
|
> int err = 0;
|
221
|
> int rc = restartterm(termname, fileno(stdout), &err);
|
222
|
>
|
223
|
> if (rc == ERR)
|
224
|
> {
|
225
|
> char* spec = "Failure resetting terminal of type %s (error %i).";
|
226
|
> char* errmsg = malloc(strlen(spec) + strlen(termname) + 15);
|
227
|
> sprintf(errmsg, spec, termname, err);
|
228
|
> throwException(env, "java/lang/IllegalStateException", errmsg);
|
229
|
> }
|
230
|
> }
|
231
|
>
|
232
|
> // set the NCURSES terminal type
|
233
|
> JNIEXPORT void JNICALL Java_charva_awt_Toolkit_setTermType(JNIEnv *env,
|
234
|
> jclass cls,
|
235
|
> jstring name)
|
236
|
> {
|
237
|
> char* termname = (char*) (*env)->GetStringUTFChars(env, name, NULL);
|
238
|
>
|
239
|
> if (termname == NULL)
|
240
|
> {
|
241
|
> // out of memory!
|
242
|
> exit(-1);
|
243
|
> }
|
244
|
>
|
245
|
> restartTerminal(env, strdup(termname));
|
246
|
>
|
247
|
> (*env)->ReleaseStringUTFChars(env, name, termname);
|
248
|
> }
|
249
|
>
|
250
|
> // returns the termname() or "" on any failure
|
251
|
> char* safe_termname()
|
252
|
> {
|
253
|
> char* term = termname();
|
254
|
> return (term == NULL) ? "" : term;
|
255
|
> }
|
256
|
>
|
257
|
> // return the NCURSES terminal type
|
258
|
> JNIEXPORT jstring JNICALL Java_charva_awt_Toolkit_getTermType(JNIEnv *env,
|
259
|
> jclass cls)
|
260
|
> {
|
261
|
> return (*env)->NewStringUTF(env, safe_termname());
|
262
|
> }
|
263
|
196c380,385
|
264
|
< Java_charva_awt_Toolkit_resetClipRect(env, jo);
|
265
|
---
|
266
|
> // reset NCURSES state associated with the terminal type (without changing
|
267
|
> // the type), this is effectively the same as setTermType(getTermType())
|
268
|
> JNIEXPORT void JNICALL Java_charva_awt_Toolkit_resetTermType(JNIEnv *env,
|
269
|
> jclass cls)
|
270
|
> {
|
271
|
> restartTerminal(env, termname());
|
272
|
215c404
|
273
|
< // Java_charva_awt_Toolkit_resetClipRect(env, jo);
|
274
|
---
|
275
|
> // Java_charva_awt_Toolkit_resetClipRectNative(env, jo);
|
276
|
222c411
|
277
|
< JNIEXPORT void JNICALL Java_charva_awt_Toolkit_sync
|
278
|
---
|
279
|
> JNIEXPORT void JNICALL Java_charva_awt_Toolkit_syncNative
|
280
|
225c414
|
281
|
< refresh();
|
282
|
---
|
283
|
> refresh();
|
284
|
248c437,459
|
285
|
< JNIEXPORT void JNICALL Java_charva_awt_Toolkit_setCursor
|
286
|
---
|
287
|
> JNIEXPORT void JNICALL Java_charva_awt_Toolkit_suspend
|
288
|
> (JNIEnv *env, jobject jo)
|
289
|
> {
|
290
|
> def_prog_mode(); /* Save the tty modes */
|
291
|
> endwin(); /* End curses mode temporarily */
|
292
|
> }
|
293
|
>
|
294
|
> JNIEXPORT void JNICALL Java_charva_awt_Toolkit_resume
|
295
|
> (JNIEnv *env, jobject jo)
|
296
|
> {
|
297
|
> reset_prog_mode(); /* Return to the previous tty mode*/
|
298
|
> /* stored by def_prog_mode() */
|
299
|
> doupdate(); /* Do refresh() to restore the */
|
300
|
> /* Screen contents */
|
301
|
> }
|
302
|
>
|
303
|
> JNIEXPORT void JNICALL Java_charva_awt_Toolkit_resetMode
|
304
|
> (JNIEnv *env, jobject jo)
|
305
|
> {
|
306
|
> reset_prog_mode();
|
307
|
> }
|
308
|
>
|
309
|
> JNIEXPORT jboolean JNICALL Java_charva_awt_Toolkit_setCursorNative
|
310
|
250a462
|
311
|
> int x, y;
|
312
|
251a464,468
|
313
|
>
|
314
|
> // Set current cursor position
|
315
|
> getyx(stdscr, y, x);
|
316
|
>
|
317
|
> return y == y_ && x == x_;
|
318
|
254,257c471,472
|
319
|
< /* Draw a string of text, taking into account the clipping rectangle.
|
320
|
< */
|
321
|
< JNIEXPORT void JNICALL Java_charva_awt_Toolkit_addString
|
322
|
< (JNIEnv *env, jobject jo, jstring jstr, jint attrib, jint colorpair)
|
323
|
---
|
324
|
> JNIEXPORT jboolean JNICALL Java_charva_awt_Toolkit_setCursorStatus
|
325
|
> (JNIEnv *env, jobject jo, jboolean on)
|
326
|
259,266c474,500
|
327
|
< const jchar *chrs;
|
328
|
< jboolean isCopy;
|
329
|
< jsize stringlength;
|
330
|
< int i;
|
331
|
< int attr = attrib;
|
332
|
<
|
333
|
< if (colors_started)
|
334
|
< attr |= COLOR_PAIR(colorpair);
|
335
|
---
|
336
|
> int rc = ERR;
|
337
|
> jboolean ret;
|
338
|
>
|
339
|
> if( on )
|
340
|
> rc = curs_set( 1 );
|
341
|
> else
|
342
|
> rc = curs_set( 0 );
|
343
|
>
|
344
|
> if ( rc == 1 || rc == 2 )
|
345
|
> ret = true;
|
346
|
> else if ( rc == 0 )
|
347
|
> ret = false;
|
348
|
> else
|
349
|
> {
|
350
|
> char* spec;
|
351
|
> char* termname = getenv("TERM");
|
352
|
> if ( rc == ERR )
|
353
|
> return true;
|
354
|
> else
|
355
|
> spec = "Unexpected return from curs_set() for terminal of type %s (%d).";
|
356
|
> char* errmsg = malloc(strlen(spec) + strlen(termname) + 32);
|
357
|
> sprintf(errmsg, spec, termname, rc);
|
358
|
> throwException(env, "java/lang/IllegalStateException", errmsg);
|
359
|
> }
|
360
|
>
|
361
|
> return ret;
|
362
|
> }
|
363
|
268,269c502,509
|
364
|
< chrs = (*env)->GetStringChars(env, jstr, &isCopy);
|
365
|
< stringlength = (*env)->GetStringLength(env, jstr);
|
366
|
---
|
367
|
> /*
|
368
|
> * Draw a string of text.
|
369
|
> */
|
370
|
> JNIEXPORT void JNICALL Java_charva_awt_Toolkit_addStringNative
|
371
|
> (JNIEnv *env, jobject jo, jbyteArray jstr, jint len, jint attrib, jint colorpair)
|
372
|
> {
|
373
|
> int i;
|
374
|
> int attr = attrib;
|
375
|
271,283c511,532
|
376
|
< if (cursory < top || cursory > bottom) {
|
377
|
< cursorx += stringlength;
|
378
|
< }
|
379
|
< else {
|
380
|
< for (i=0; i<stringlength; i++) {
|
381
|
< if (cursorx >= left && cursorx <= right)
|
382
|
< my_addch(chrs[i] | attr);
|
383
|
< else {
|
384
|
< cursorx++;
|
385
|
< move(cursory, cursorx);
|
386
|
< }
|
387
|
< }
|
388
|
< }
|
389
|
---
|
390
|
> if (colors_started)
|
391
|
> attr |= COLOR_PAIR(colorpair);
|
392
|
>
|
393
|
> if (len <= 0)
|
394
|
> return;
|
395
|
>
|
396
|
> jbyte* chrs = (jbyte*) malloc(len * sizeof(jbyte));
|
397
|
>
|
398
|
> if (chrs == NULL)
|
399
|
> {
|
400
|
> throwException(env, "java/lang/OutOfMemoryError", "Cannot copy data.");
|
401
|
> }
|
402
|
>
|
403
|
> (*env)->GetByteArrayRegion(env, jstr, 0, len, chrs);
|
404
|
>
|
405
|
> for (i = 0; i < len; i++)
|
406
|
> {
|
407
|
> // remove the automatic sign extension (we want to treat this as
|
408
|
> // an unsigned 8-bit number)
|
409
|
> int extended = 0x000000FF & (int) chrs[i];
|
410
|
> my_addch(extended | attr);
|
411
|
> }
|
412
|
285c534,535
|
413
|
< (*env)->ReleaseStringChars(env, jstr, chrs);
|
414
|
---
|
415
|
> (*env)->DeleteLocalRef(env, jstr);
|
416
|
> free(chrs);
|
417
|
288c538
|
418
|
< JNIEXPORT void JNICALL Java_charva_awt_Toolkit_addChar
|
419
|
---
|
420
|
> JNIEXPORT void JNICALL Java_charva_awt_Toolkit_addCharNative
|
421
|
296c546,587
|
422
|
< my_addch_with_clip(chr_ | attr);
|
423
|
---
|
424
|
> my_addch(chr_ | attr);
|
425
|
> }
|
426
|
>
|
427
|
> /* This function outputs the screenful of data at once using an array of codes
|
428
|
> where every character position is either a skip indicator (-1) or a fully
|
429
|
> prepared code with character, attribute and color included.
|
430
|
> The final step is the cursor positioning.
|
431
|
> */
|
432
|
> JNIEXPORT void JNICALL Java_charva_awt_Toolkit_addArrayNative
|
433
|
> (JNIEnv *env, jobject jo, jintArray arr_, jint cx_, jint cy_)
|
434
|
> {
|
435
|
> int i, j, chr;
|
436
|
> jboolean isCopy = JNI_FALSE;
|
437
|
>
|
438
|
> jint* arrp = (*env)->GetIntArrayElements(env, arr_, &isCopy);
|
439
|
> jint* arp = arrp;
|
440
|
>
|
441
|
> if (arp == NULL)
|
442
|
> {
|
443
|
> return;
|
444
|
> }
|
445
|
>
|
446
|
> for (i = 0; i < base_rows; i++)
|
447
|
> {
|
448
|
> for (j = 0; j < base_cols; j++)
|
449
|
> {
|
450
|
> chr = *arp++;
|
451
|
>
|
452
|
> if (chr == -1)
|
453
|
> {
|
454
|
> continue;
|
455
|
> }
|
456
|
>
|
457
|
> my_move(i, j);
|
458
|
> my_addch(chr);
|
459
|
> }
|
460
|
> }
|
461
|
>
|
462
|
> my_move(cy_, cx_);
|
463
|
> refresh();
|
464
|
>
|
465
|
> (*env)->ReleaseIntArrayElements(env, arr_, arrp, JNI_ABORT);
|
466
|
300c591,592
|
467
|
< (JNIEnv *env, jobject jo, jint left_, jint top_, jint right_, jint bottom_, jint colorpair_)
|
468
|
---
|
469
|
> (JNIEnv *env, jobject jo, jint left_, jint top_, jint right_, jint bottom_,
|
470
|
> jint attrib, jint colorpair_)
|
471
|
303c595
|
472
|
< int attr = 0;
|
473
|
---
|
474
|
> int attr = attrib;
|
475
|
308,312c600,601
|
476
|
< // If the top of the box is outside the clipping rectangle, don't bother
|
477
|
< // to draw the top.
|
478
|
< if (top_ >= top && top_ <= bottom) {
|
479
|
< my_move(top_, left_);
|
480
|
< my_addch_with_clip(ACS_ULCORNER | attr); // upper left corner
|
481
|
---
|
482
|
> my_move(top_, left_);
|
483
|
> my_addch(ACS_ULCORNER | attr); // upper left corner
|
484
|
314,318c603,604
|
485
|
< for (i=left_+1; i<right_; i++) {
|
486
|
< my_addch_with_clip(ACS_HLINE | attr); // top horizontal line
|
487
|
< }
|
488
|
<
|
489
|
< my_addch_with_clip(ACS_URCORNER | attr); // upper right corner
|
490
|
---
|
491
|
> for (i=left_+1; i<right_; i++) {
|
492
|
> my_addch(ACS_HLINE | attr); // top horizontal line
|
493
|
321,324c607
|
494
|
< // If the bottom of the box is outside the clipping rectangle, don't bother
|
495
|
< if (bottom_ >= top && bottom_ <= bottom) {
|
496
|
< my_move(bottom_, left_);
|
497
|
< my_addch_with_clip(ACS_LLCORNER | attr); // lower left corner
|
498
|
---
|
499
|
> my_addch(ACS_URCORNER | attr); // upper right corner
|
500
|
326,327c609,610
|
501
|
< for (i=left_+1; i<right_; i++)
|
502
|
< my_addch_with_clip(ACS_HLINE | attr); // bottom horizontal line
|
503
|
---
|
504
|
> my_move(bottom_, left_);
|
505
|
> my_addch(ACS_LLCORNER | attr); // lower left corner
|
506
|
329,331c612,613
|
507
|
< my_move(bottom_, right_);
|
508
|
< my_addch_with_clip(ACS_LRCORNER | attr); // lower right corner
|
509
|
< }
|
510
|
---
|
511
|
> for (i=left_+1; i<right_; i++)
|
512
|
> my_addch(ACS_HLINE | attr); // bottom horizontal line
|
513
|
333,339c615,617
|
514
|
< // If the left side of the box is outside the clipping rectangle, don't
|
515
|
< // bother.
|
516
|
< if (left_ >= left && left_ <= right) {
|
517
|
< for (i=top_+1; i<bottom_; i++) {
|
518
|
< my_move(i, left_);
|
519
|
< my_addch_with_clip(ACS_VLINE | attr); // left vertical line
|
520
|
< }
|
521
|
---
|
522
|
> for (i=top_+1; i<bottom_; i++) {
|
523
|
> my_move(i, left_);
|
524
|
> my_addch(ACS_VLINE | attr); // left vertical line
|
525
|
341,348c619,622
|
526
|
< //
|
527
|
< // If the right side of the box is outside the clipping rectangle, don't
|
528
|
< // bother.
|
529
|
< if (right_ >= left && right_ <= right) {
|
530
|
< for (i=top_+1; i<bottom_; i++) {
|
531
|
< my_move(i, right_);
|
532
|
< my_addch_with_clip(ACS_VLINE | attr); // right vertical line
|
533
|
< }
|
534
|
---
|
535
|
>
|
536
|
> for (i=top_+1; i<bottom_; i++) {
|
537
|
> my_move(i, right_);
|
538
|
> my_addch(ACS_VLINE | attr); // right vertical line
|
539
|
353c627,628
|
540
|
< (JNIEnv *env, jobject jo, jint left_, jint top_, jint right_, jint bottom_, jint colorpair_)
|
541
|
---
|
542
|
> (JNIEnv *env, jobject jo, jint left_, jint top_, jint right_, jint bottom_,
|
543
|
> jint attrib, jint colorpair_)
|
544
|
356c631
|
545
|
< int attr = 0;
|
546
|
---
|
547
|
> int attr = attrib;
|
548
|
362,363d636
|
549
|
< if (row < top || row > bottom)
|
550
|
< continue; // do some clipping
|
551
|
367c640
|
552
|
< my_addch_with_clip(' ' | attr);
|
553
|
---
|
554
|
> my_addch(' ' | attr);
|
555
|
406c679
|
556
|
< JNIEXPORT jint JNICALL Java_charva_awt_Toolkit_getScreenColumns
|
557
|
---
|
558
|
> JNIEXPORT jint JNICALL Java_charva_awt_Toolkit_getScreenColumnsNative
|
559
|
409,411c682
|
560
|
< int x, y;
|
561
|
< getmaxyx(stdscr, y, x);
|
562
|
< return (jint) x;
|
563
|
---
|
564
|
> return (jint) base_cols;
|
565
|
416c687
|
566
|
< JNIEXPORT jint JNICALL Java_charva_awt_Toolkit_getScreenRows
|
567
|
---
|
568
|
> JNIEXPORT jint JNICALL Java_charva_awt_Toolkit_getScreenRowsNative
|
569
|
419,421c690
|
570
|
< int x, y;
|
571
|
< getmaxyx(stdscr, y, x);
|
572
|
< return (jint) y;
|
573
|
---
|
574
|
> return (jint) base_rows;
|
575
|
426c695
|
576
|
< JNIEXPORT void JNICALL Java_charva_awt_Toolkit_addVerticalLine
|
577
|
---
|
578
|
> JNIEXPORT void JNICALL Java_charva_awt_Toolkit_addVerticalLineNative
|
579
|
436,437c705
|
580
|
< x = cursorx;
|
581
|
< y = cursory;
|
582
|
---
|
583
|
> getyx(stdscr, y, x);
|
584
|
441c709
|
585
|
< my_addch_with_clip(ACS_VLINE | attr);
|
586
|
---
|
587
|
> my_addch(ACS_VLINE | attr);
|
588
|
447c715
|
589
|
< JNIEXPORT void JNICALL Java_charva_awt_Toolkit_addHorizontalLine
|
590
|
---
|
591
|
> JNIEXPORT void JNICALL Java_charva_awt_Toolkit_addHorizontalLineNative
|
592
|
457,458c725
|
593
|
< x = cursorx;
|
594
|
< y = cursory;
|
595
|
---
|
596
|
> getyx(stdscr, y, x);
|
597
|
462c729
|
598
|
< my_addch_with_clip(ACS_HLINE | attr);
|
599
|
---
|
600
|
> my_addch(ACS_HLINE | attr);
|
601
|
488,512d754
|
602
|
< /* Set a clipping rectangle
|
603
|
< */
|
604
|
< JNIEXPORT void JNICALL Java_charva_awt_Toolkit_setClipRectNative
|
605
|
< (JNIEnv *env, jobject jo, jint left_, jint top_, jint right_, jint bottom_)
|
606
|
< {
|
607
|
< left = left_;
|
608
|
< top = top_;
|
609
|
< right = right_;
|
610
|
< bottom = bottom_;
|
611
|
< }
|
612
|
<
|
613
|
< /* Reset the clipping rectangle to the screen size.
|
614
|
< * Unfortunately this does not work reliably on xterm windows where the window
|
615
|
< * size can change at runtime. The ncurses library appears not to update the
|
616
|
< * value of the window reliably.
|
617
|
< */
|
618
|
< JNIEXPORT void JNICALL Java_charva_awt_Toolkit_resetClipRect
|
619
|
< (JNIEnv *env, jobject jo)
|
620
|
< {
|
621
|
< left = top = 0;
|
622
|
< getmaxyx(stdscr, bottom, right);
|
623
|
< bottom--;
|
624
|
< right--;
|
625
|
< }
|
626
|
<
|
627
|
566a809
|
628
|
>
|
629
|
728,732c971
|
630
|
< /* This calls the standard curses "addch" function but also updates the
|
631
|
< * local copy of the cursor position, so that the clipping works correctly.
|
632
|
< * It is called by functions that can clip more efficiently by doing their
|
633
|
< * own clipping (such as addString, which knows when it starts whether the
|
634
|
< * row is above, inside or below the clipping rectangle).
|
635
|
---
|
636
|
> /* This calls the standard curses "addch" function.
|
637
|
737d975
|
638
|
< cursorx++;
|
639
|
740,741c978
|
640
|
< /* This calls the standard curses "move" function but also updates a local
|
641
|
< * copy of the cursor position so that clipping works correctly.
|
642
|
---
|
643
|
> /* This calls the standard curses "move" function.
|
644
|
746,768d982
|
645
|
<
|
646
|
< /* Keep track of the cursor position so that we can use the clipping
|
647
|
< * rectangle effectively.
|
648
|
< */
|
649
|
< cursorx = x_;
|
650
|
< cursory = y_;
|
651
|
< }
|
652
|
<
|
653
|
< /* Write a character to the virtual screen if the cursor position is within
|
654
|
< * the clipping rectangle, and (whether the character was clipped or not)
|
655
|
< * updates the cursor position.
|
656
|
< */
|
657
|
< static void my_addch_with_clip(int chr_)
|
658
|
< {
|
659
|
< if (cursory >= top && cursory <= bottom &&
|
660
|
< cursorx >= left && cursorx <= right) {
|
661
|
<
|
662
|
< my_addch(chr_);
|
663
|
< }
|
664
|
< else {
|
665
|
< cursorx++;
|
666
|
< move(cursory, cursorx);
|
667
|
< }
|