Menu

[7c54b3]: / joe / qw.c  Maximize  Restore  History

Download this file

173 lines (158 with data), 3.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
* Query windows
* Copyright
* (C) 1992 Joseph H. Allen
*
* This file is part of JOE (Joe's Own Editor)
*/
#include "types.h"
/* Event handler: display query window */
static void dispqw(W *w, int flg)
{
QW *qw = (QW *)w->object;
ptrdiff_t y;
/* Generate prompt */
for (y = 0; y != w->h; ++y) {
const char *s = qw->prompt;
ptrdiff_t l = qw->promptlen;
break_height(locale_map, &s, &l, qw->org_w, y);
w->t->t->updtab[w->y + y] = 1;
genfield(w->t->t,
w->t->t->scrn + (w->y + y) * w->t->t->co + w->x,
w->t->t->attr + (w->y + y) * w->t->t->co + w->x,
w->x,
w->y + y,
0,
s,
l,
BG_COLOR(bg_prompt),
w->w - w->x,
1,NULL);
w->cury = y;
w->curx = w->x + txtwidth(locale_map, s, l);
}
}
/* Display query window: leave cursor in target window */
static void dispqwn(W *w, int flg)
{
/* Set cursor position */
if (w->win->watom->follow && w->win->object)
w->win->watom->follow(w->win);
if (w->win->watom->disp && w->win->object)
w->win->watom->disp(w->win, 1);
dispqw(w, flg);
w->curx = w->win->curx;
w->cury = w->win->cury + w->win->y - w->y;
}
/* When user hits a key in a query window */
static int utypeqw(W *w, int c)
{
QW *qw = (QW *)w->object;
struct query_result *r;
int flg = qw->flg;
r = qw->result;
obj_free(qw->prompt);
joe_free(qw);
w->object = NULL;
wabort(w);
r->answer = c;
if (flg & QW_NOMACRO) {
co_sched(&r->t, 0);
return 0;
} else
return co_resume(&r->t, 0);
}
static int abortqw(W *w)
{
QW *qw = (QW *)w->object;
struct query_result *r = qw->result;
int flg = qw->flg;
obj_free(qw->prompt);
joe_free(qw);
r->answer = -1;
if (flg & QW_NOMACRO) {
co_sched(&r->t, -1);
return -1;
} else
return co_resume(&r->t, -1);
}
static WATOM watomqw = {
"query",
dispqw,
NULL,
abortqw,
NULL,
utypeqw,
NULL,
NULL,
NULL,
NULL,
TYPEQW
};
static WATOM watqwn = {
"querya",
dispqwn,
NULL,
abortqw,
NULL,
utypeqw,
NULL,
NULL,
NULL,
NULL,
TYPEQW
};
static WATOM watqwsr = {
"querysr",
dispqwn,
NULL,
abortqw,
NULL,
utypeqw,
NULL,
NULL,
NULL,
NULL,
TYPEQW
};
int query(W *w, /* Prompt goes below this window */
const char *prompt, /* Prompt text */
int len, /* Length of prompt text */
int flg) /* Options: 0 = normal, 1 = cursor left in original,
2 = same as 1, but QW type code is different. */
{
struct query_result t;
QW *qw;
W *n;
WATOM *a = &watomqw;
ptrdiff_t l = len;
const char *s = prompt;
ptrdiff_t h = break_height(locale_map, &s, &l, w->w, -1);
a = &watomqw;
if (flg & QW_STAY)
a = &watqwn;
if (flg & QW_SR)
a = &watqwsr;
n = wcreate(w->t, a, w, w, w->main, h, NULL);
if (!n) {
return -1;
}
wfit(n->t);
n->object = (void *) (qw = (QW *) joe_malloc(SIZEOF(QW)));
qw->parent = n;
qw->prompt = vsncpy(NULL, 0, prompt, len);
obj_perm(qw->prompt);
qw->promptlen = len;
qw->org_w = w->w;
qw->org_h = h;
qw->result = &t;
qw->flg = flg;
w->t->curwin = n;
/* We get woken up when user hits a key */
t.answer = -1;
if (flg & QW_NOMACRO)
co_suspend(&t.t, 0);
else
co_yield(&t.t, 0);
return t.answer;
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.