~ubuntu-branches/ubuntu/trusty/xterm/trusty

« back to all changes in this revision

Viewing changes to cursor.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2013-10-28 22:15:39 UTC
  • mfrom: (1.4.15) (11.1.37 sid)
  • Revision ID: package-import@ubuntu.com-20131028221539-hkfkjoqjk7i2djqz
Tags: 297-1ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - debian/patches/950_ubuntu_charclass_highlight.diff: Enable URL
    highlighting.
  - debian/patches/Add 951_uxterm_utf8_title.diff: Set utf8Titles to true
    by default when using uxterm, so that it displays utf8 directories in
    titles properly.  May cause issues with apps that use control
    sequences for updating the xterm titlebar - users should use xterm or
    set utf8Title to false in this case.
  - debian/gbp.conf: Use "Ubuntu" in "debian-branch" directly.
  - Use autotools-dev's debhelper integration to update
    config.guess/config.sub for each build.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 $ */
2
2
 
3
3
/*
4
 
 * Copyright 2002-2009,2010 by Thomas E. Dickey
 
4
 * Copyright 2002-2010,2012 by Thomas E. Dickey
5
5
 * 
6
6
 *                         All Rights Reserved
7
7
 * 
68
68
CursorSet(TScreen * screen, int row, int col, unsigned flags)
69
69
{
70
70
    int use_row = row;
71
 
    int max_row;
72
 
 
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;
 
71
    int use_col = col;
 
72
    int max_col = screen->max_col;
 
73
    int max_row = screen->max_row;
 
74
 
 
75
    if (flags & ORIGIN) {
 
76
        use_col += screen->lft_marg;
 
77
        max_col = screen->rgt_marg;
 
78
    }
 
79
    use_col = (use_col < 0 ? 0 : use_col);
 
80
    set_cur_col(screen, (use_col <= max_col ? use_col : max_col));
 
81
 
76
82
    if (flags & ORIGIN) {
77
83
        use_row += screen->top_marg;
78
84
        max_row = screen->bot_marg;
79
85
    }
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;
83
 
 
84
 
    TRACE(("CursorSet(%d,%d) margins [%d..%d] -> %d,%d %s\n",
 
88
 
 
89
    ResetWrap(screen);
 
90
 
 
91
    TRACE(("CursorSet(%d,%d) margins V[%d..%d] H[%d..%d] -> %d,%d %s\n",
85
92
           row, col,
86
93
           screen->top_marg,
87
94
           screen->bot_marg,
 
95
           screen->lft_marg,
 
96
           screen->rgt_marg,
88
97
           screen->cur_row,
89
98
           screen->cur_col,
90
99
           (flags & ORIGIN ? "origin" : "normal")));
96
105
void
97
106
CursorBack(XtermWidget xw, int n)
98
107
{
 
108
#define WRAP_MASK (REVERSEWRAP | WRAPAROUND)
99
109
    TScreen *screen = TScreenOf(xw);
100
 
    int i, j, k, rev;
 
110
    int offset, in_row, length, rev;
 
111
    int left = ScrnLeftMargin(xw);
 
112
    int before = screen->cur_col;
101
113
 
102
 
    if ((rev = (xw->flags & (REVERSEWRAP | WRAPAROUND)) ==
103
 
         (REVERSEWRAP | WRAPAROUND)) != 0
104
 
        && screen->do_wrap)
 
114
    if ((rev = (xw->flags & WRAP_MASK) == WRAP_MASK) != 0
 
115
        && screen->do_wrap) {
105
116
        n--;
106
 
    if ((screen->cur_col -= n) < 0) {
 
117
    }
 
118
 
 
119
    /* if the cursor is already before the left-margin, we have to let it go */
 
120
    if (before < left)
 
121
        left = 0;
 
122
 
 
123
    if ((screen->cur_col -= n) < left) {
107
124
        if (rev) {
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;
 
127
            if (offset < 0) {
 
128
                length = in_row * MaxRows(screen);
 
129
                offset += ((-offset) / length + 1) * length;
112
130
            }
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);
115
133
            do_xevents();
116
134
        } else {
117
 
            set_cur_col(screen, 0);
 
135
            set_cur_col(screen, left);
118
136
        }
119
137
    }
120
 
    screen->do_wrap = False;
 
138
    ResetWrap(screen);
121
139
}
122
140
 
123
141
/*
124
142
 * moves the cursor forward n, no wraparound
125
143
 */
126
144
void
127
 
CursorForward(TScreen * screen, int n)
 
145
CursorForward(XtermWidget xw, int n)
128
146
{
 
147
    TScreen *screen = TScreenOf(xw);
129
148
#if OPT_DEC_CHRSET
130
149
    LineData *ld = getLineData(screen, screen->cur_row);
131
150
#endif
132
151
    int next = screen->cur_col + n;
133
 
    int max = LineMaxCol(screen, ld);
 
152
    int max;
 
153
 
 
154
    if (IsLeftRightMode(xw)) {
 
155
        max = screen->rgt_marg;
 
156
        if (screen->cur_col > max)
 
157
            max = screen->max_col;
 
158
    } else {
 
159
        max = LineMaxCol(screen, ld);
 
160
    }
134
161
 
135
162
    if (next > max)
136
163
        next = max;
137
164
 
138
165
    set_cur_col(screen, next);
139
 
    screen->do_wrap = False;
 
166
    ResetWrap(screen);
140
167
}
141
168
 
142
169
/*
157
184
        next = screen->max_row;
158
185
 
159
186
    set_cur_row(screen, next);
160
 
    screen->do_wrap = False;
 
187
    ResetWrap(screen);
161
188
}
162
189
 
163
190
/*
179
206
        next = 0;
180
207
 
181
208
    set_cur_row(screen, next);
182
 
    screen->do_wrap = False;
 
209
    ResetWrap(screen);
183
210
}
184
211
 
185
212
/*
197
224
     * if cursor high enough, no scrolling necessary.
198
225
     */
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);
202
 
        return;
 
231
    } else {
 
232
        CursorDown(screen, j = screen->bot_marg - screen->cur_row);
 
233
        xtermScroll(xw, amount - j);
203
234
    }
204
 
 
205
 
    CursorDown(screen, j = screen->bot_marg - screen->cur_row);
206
 
    xtermScroll(xw, amount - j);
207
235
}
208
236
 
209
237
/*
220
248
     * if cursor low enough, no reverse indexing needed
221
249
     */
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);
225
 
        return;
 
255
    } else {
 
256
        RevScroll(xw, amount - (screen->cur_row - screen->top_marg));
 
257
        CursorUp(screen, screen->cur_row - screen->top_marg);
226
258
    }
227
 
 
228
 
    RevScroll(xw, amount - (screen->cur_row - screen->top_marg));
229
 
    CursorUp(screen, screen->cur_row - screen->top_marg);
230
259
}
231
260
 
232
261
/*
234
263
 * (Note: xterm doesn't implement SLH, SLL which would affect use of this)
235
264
 */
236
265
void
237
 
CarriageReturn(TScreen * screen)
 
266
CarriageReturn(XtermWidget xw)
238
267
{
239
 
    set_cur_col(screen, 0);
240
 
    screen->do_wrap = False;
 
268
    TScreen *screen = TScreenOf(xw);
 
269
    int left = ScrnLeftMargin(xw);
 
270
    int col;
 
271
 
 
272
    if (xw->flags & ORIGIN) {
 
273
        col = left;
 
274
    } else if (screen->cur_col >= left) {
 
275
        col = left;
 
276
    } else {
 
277
        /*
 
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.
 
281
         */
 
282
        col = 0;
 
283
    }
 
284
 
 
285
    set_cur_col(screen, col);
 
286
    ResetWrap(screen);
241
287
    do_xevents();
242
288
}
243
289
 
330
376
 * Move the cursor to the first column of the n-th next line.
331
377
 */
332
378
void
333
 
CursorNextLine(TScreen * screen, int count)
 
379
CursorNextLine(XtermWidget xw, int count)
334
380
{
 
381
    TScreen *screen = TScreenOf(xw);
 
382
 
335
383
    CursorDown(screen, count < 1 ? 1 : count);
336
 
    CarriageReturn(screen);
 
384
    CarriageReturn(xw);
337
385
    do_xevents();
338
386
}
339
387
 
341
389
 * Move the cursor to the first column of the n-th previous line.
342
390
 */
343
391
void
344
 
CursorPrevLine(TScreen * screen, int count)
 
392
CursorPrevLine(XtermWidget xw, int count)
345
393
{
 
394
    TScreen *screen = TScreenOf(xw);
 
395
 
346
396
    CursorUp(screen, count < 1 ? 1 : count);
347
 
    CarriageReturn(screen);
 
397
    CarriageReturn(xw);
348
398
    do_xevents();
349
399
}
350
400
 
 
401
/*
 
402
 * Return col/row values which can be passed to CursorSet() preserving the
 
403
 * current col/row, e.g., accounting for DECOM.
 
404
 */
 
405
int
 
406
CursorCol(XtermWidget xw)
 
407
{
 
408
    TScreen *screen = TScreenOf(xw);
 
409
    int result = screen->cur_col;
 
410
    if (xw->flags & ORIGIN) {
 
411
        result -= ScrnLeftMargin(xw);
 
412
        if (result < 0)
 
413
            result = 0;
 
414
    }
 
415
    return result;
 
416
}
 
417
 
 
418
int
 
419
CursorRow(XtermWidget xw)
 
420
{
 
421
    TScreen *screen = TScreenOf(xw);
 
422
    int result = screen->cur_row;
 
423
    if (xw->flags & ORIGIN) {
 
424
        result -= screen->top_marg;
 
425
        if (result < 0)
 
426
            result = 0;
 
427
    }
 
428
    return result;
 
429
}
 
430
 
351
431
#if OPT_TRACE
352
432
int
353
433
set_cur_row(TScreen * screen, int value)