1
/* $XTermId: cursor.c,v 1.55 2010/04/17 17:12:01 tom Exp $ */
1
/* $XTermId: cursor.c,v 1.68 2013/08/08 08:16:40 Iwamoto.Kouichi Exp $ */
4
* Copyright 2002-2009,2010 by Thomas E. Dickey
4
* Copyright 2002-2010,2012 by Thomas E. Dickey
6
6
* All Rights Reserved
68
68
CursorSet(TScreen * screen, int row, int col, unsigned flags)
73
col = (col < 0 ? 0 : col);
74
set_cur_col(screen, (col <= screen->max_col ? col : screen->max_col));
75
max_row = screen->max_row;
72
int max_col = screen->max_col;
73
int max_row = screen->max_row;
76
use_col += screen->lft_marg;
77
max_col = screen->rgt_marg;
79
use_col = (use_col < 0 ? 0 : use_col);
80
set_cur_col(screen, (use_col <= max_col ? use_col : max_col));
76
82
if (flags & ORIGIN) {
77
83
use_row += screen->top_marg;
78
84
max_row = screen->bot_marg;
80
86
use_row = (use_row < 0 ? 0 : use_row);
81
87
set_cur_row(screen, (use_row <= max_row ? use_row : max_row));
82
screen->do_wrap = False;
84
TRACE(("CursorSet(%d,%d) margins [%d..%d] -> %d,%d %s\n",
91
TRACE(("CursorSet(%d,%d) margins V[%d..%d] H[%d..%d] -> %d,%d %s\n",
90
99
(flags & ORIGIN ? "origin" : "normal")));
97
106
CursorBack(XtermWidget xw, int n)
108
#define WRAP_MASK (REVERSEWRAP | WRAPAROUND)
99
109
TScreen *screen = TScreenOf(xw);
110
int offset, in_row, length, rev;
111
int left = ScrnLeftMargin(xw);
112
int before = screen->cur_col;
102
if ((rev = (xw->flags & (REVERSEWRAP | WRAPAROUND)) ==
103
(REVERSEWRAP | WRAPAROUND)) != 0
114
if ((rev = (xw->flags & WRAP_MASK) == WRAP_MASK) != 0
115
&& screen->do_wrap) {
106
if ((screen->cur_col -= n) < 0) {
119
/* if the cursor is already before the left-margin, we have to let it go */
123
if ((screen->cur_col -= n) < left) {
108
if ((i = ((j = MaxCols(screen))
109
* screen->cur_row) + screen->cur_col) < 0) {
110
k = j * MaxRows(screen);
111
i += ((-i) / k + 1) * k;
125
in_row = ScrnRightMargin(xw) - left + 1;
126
offset = (in_row * screen->cur_row) + screen->cur_col - left;
128
length = in_row * MaxRows(screen);
129
offset += ((-offset) / length + 1) * length;
113
set_cur_row(screen, i / j);
114
set_cur_col(screen, i % j);
131
set_cur_row(screen, (offset / in_row));
132
set_cur_col(screen, (offset % in_row) + left);
117
set_cur_col(screen, 0);
135
set_cur_col(screen, left);
120
screen->do_wrap = False;
124
142
* moves the cursor forward n, no wraparound
127
CursorForward(TScreen * screen, int n)
145
CursorForward(XtermWidget xw, int n)
147
TScreen *screen = TScreenOf(xw);
129
148
#if OPT_DEC_CHRSET
130
149
LineData *ld = getLineData(screen, screen->cur_row);
132
151
int next = screen->cur_col + n;
133
int max = LineMaxCol(screen, ld);
154
if (IsLeftRightMode(xw)) {
155
max = screen->rgt_marg;
156
if (screen->cur_col > max)
157
max = screen->max_col;
159
max = LineMaxCol(screen, ld);
138
165
set_cur_col(screen, next);
139
screen->do_wrap = False;
197
224
* if cursor high enough, no scrolling necessary.
199
226
if (screen->cur_row > screen->bot_marg
200
|| screen->cur_row + amount <= screen->bot_marg) {
227
|| screen->cur_row + amount <= screen->bot_marg
228
|| (IsLeftRightMode(xw)
229
&& !ScrnIsColInMargins(screen, screen->cur_col))) {
201
230
CursorDown(screen, amount);
232
CursorDown(screen, j = screen->bot_marg - screen->cur_row);
233
xtermScroll(xw, amount - j);
205
CursorDown(screen, j = screen->bot_marg - screen->cur_row);
206
xtermScroll(xw, amount - j);
220
248
* if cursor low enough, no reverse indexing needed
222
250
if (screen->cur_row < screen->top_marg
223
|| screen->cur_row - amount >= screen->top_marg) {
251
|| screen->cur_row - amount >= screen->top_marg
252
|| (IsLeftRightMode(xw)
253
&& !ScrnIsColInMargins(screen, screen->cur_col))) {
224
254
CursorUp(screen, amount);
256
RevScroll(xw, amount - (screen->cur_row - screen->top_marg));
257
CursorUp(screen, screen->cur_row - screen->top_marg);
228
RevScroll(xw, amount - (screen->cur_row - screen->top_marg));
229
CursorUp(screen, screen->cur_row - screen->top_marg);
234
263
* (Note: xterm doesn't implement SLH, SLL which would affect use of this)
237
CarriageReturn(TScreen * screen)
266
CarriageReturn(XtermWidget xw)
239
set_cur_col(screen, 0);
240
screen->do_wrap = False;
268
TScreen *screen = TScreenOf(xw);
269
int left = ScrnLeftMargin(xw);
272
if (xw->flags & ORIGIN) {
274
} else if (screen->cur_col >= left) {
278
* If origin-mode is not active, it is possible to use cursor
279
* addressing outside the margins. In that case we will go to the
280
* first column rather than following the margin.
285
set_cur_col(screen, col);
330
376
* Move the cursor to the first column of the n-th next line.
333
CursorNextLine(TScreen * screen, int count)
379
CursorNextLine(XtermWidget xw, int count)
381
TScreen *screen = TScreenOf(xw);
335
383
CursorDown(screen, count < 1 ? 1 : count);
336
CarriageReturn(screen);
341
389
* Move the cursor to the first column of the n-th previous line.
344
CursorPrevLine(TScreen * screen, int count)
392
CursorPrevLine(XtermWidget xw, int count)
394
TScreen *screen = TScreenOf(xw);
346
396
CursorUp(screen, count < 1 ? 1 : count);
347
CarriageReturn(screen);
402
* Return col/row values which can be passed to CursorSet() preserving the
403
* current col/row, e.g., accounting for DECOM.
406
CursorCol(XtermWidget xw)
408
TScreen *screen = TScreenOf(xw);
409
int result = screen->cur_col;
410
if (xw->flags & ORIGIN) {
411
result -= ScrnLeftMargin(xw);
419
CursorRow(XtermWidget xw)
421
TScreen *screen = TScreenOf(xw);
422
int result = screen->cur_row;
423
if (xw->flags & ORIGIN) {
424
result -= screen->top_marg;
353
433
set_cur_row(TScreen * screen, int value)