4
#include <grass/raster.h>
6
#include "local_proto.h"
11
int top, bottom, left, right;
14
static int pick(int, int, int);
15
static int downarrow(struct box *, int);
16
static int uparrow(struct box *, int);
17
static int dobox(struct box *, char *, int, int, int, int, int);
18
static int dotext(char *, int, int, int, int, int);
19
static int inbox(struct box *, int, int);
20
static int cancel_which(void);
24
static struct box cancel, more, less;
25
static int height, size, edge, count;
26
static int page, npages;
29
char name[GNAME_MAX], mapset[GMAPSET_MAX];
34
ask_gis_files(char *type, char *file, char *xname, char *xmapset,
38
static Objects objects[] = {
53
int top, bottom, left, right, center;
54
int topx, bottomx, leftx, rightx, widthx;
55
char name[GNAME_MAX], mapset[GMAPSET_MAX], cur_mapset[GMAPSET_MAX];
60
fd = fopen(file, "r");
62
G_fatal_error("ask_gis_files: can't read tempfile");
63
if (fread(&len1, sizeof(len1), 1, fd) != 1
64
|| fread(&len2, sizeof(len2), 1, fd) != 1 || len1 <= 0 || len2 <= 0) {
69
sprintf(msg, "Double click on %s file to be plotted", type);
72
* build a popup window at center of the screen.
73
* 35% the height and wide enough to hold 2 columms of file names
75
* the window is for choosing file names and will be laid out in 2 columns
77
* ------------------------------------------
78
* | CANCEL | (MORE) | (LESS) |
79
* ------------------------------------------
81
* ------------------------------------------
83
* ------------------------------------------
85
* ------------------------------------------
90
* ------------------------------------------
93
/* height of 1 line, based on NLINES taking up 35% vertical space */
94
height = (.35 * (SCREEN_BOTTOM - SCREEN_TOP)) / NLINES + 1;
96
/* size of text, 80% of line height */
97
text_size = .8 * height;
98
size = text_size - 1; /* fudge for computing pixels width of text */
100
/* indent for the text */
101
edge = .1 * height + 1;
103
/* this is a fudge to determine the length of the largest text */
104
len1 = 2 * len1; /* name in 2 columns */
105
len2 += strlen("mapset ");
106
len = (len1 > len2 ? len1 : len2);
108
/* width is for max chars plus sidecar for more/less */
109
width = len * size + height;
110
widthx = strlen(msg) * size;
114
/* define the window */
115
top = (SCREEN_TOP + SCREEN_BOTTOM - height * NLINES) / 2;
116
bottom = top + height * NLINES;
118
center = (SCREEN_LEFT + SCREEN_RIGHT) / 2;
120
right = (center + SCREEN_RIGHT + width) / 2;
121
if (right >= SCREEN_RIGHT)
122
right = SCREEN_RIGHT - 1;
123
left = right - width;
125
else if (position < 0) {
126
left = (center + SCREEN_LEFT - width) / 2;
127
if (left <= SCREEN_LEFT)
128
left = SCREEN_LEFT + 1;
129
right = left + width;
132
left = center + width / 2;
133
right = left + width;
136
topx = top - 3 * height;
137
bottomx = topx + 2 * height;
138
leftx = (left + right - widthx) / 2;
139
if (leftx < SCREEN_LEFT)
141
rightx = leftx + widthx;
143
/* save what is under these areas, so they can be restored */
144
R_panel_save(tempfile1, top, bottom + 1, left, right + 1);
145
R_panel_save(tempfile2, topx, bottomx + 1, leftx, rightx + 1);
147
/* fill it top with GREY, pick area with white */
148
R_standard_color(WHITE);
149
R_box_abs(left, top, right, bottom);
150
R_standard_color(GREY);
151
R_box_abs(leftx, topx, rightx, bottomx);
153
R_standard_color(BLACK);
154
Outline_box(top, bottom, left, right);
155
right -= height; /* reduce it to exclude sidecar */
156
Outline_box(top, bottom, left, right);
158
/* print messages above the files */
159
dotext(msg, topx, topx + height, leftx, rightx, 1);
160
dotext("Double click here to cancel", topx + height, bottomx, leftx,
163
cancel.bottom = bottomx;
165
cancel.right = rightx;
167
/* start the mouse in the cancel box */
168
Set_mouse_xy((leftx + rightx) / 2, (topx + bottomx) / 2);
170
dobox(&less, "", WHITE, top, right, right + height, 0);
171
dobox(&more, "", WHITE, bottom - height, right, right + height, 0);
173
/* as we read the file of names, keep track of pages so we can
177
page_offset = (long *)G_calloc(npages = 1, sizeof(long));
178
*page_offset = ftell(fd);
180
nlist = sizeof(list) / sizeof(list[0]);
181
for (stat = -1; stat < 0;) {
188
if (fgets(buf, sizeof buf, fd) == NULL
189
|| sscanf(buf, "%s %s", name, mapset) != 2)
191
if (new_mapset = (strcmp(cur_mapset, mapset) != 0)) {
198
if (count >= nlist || line + new_mapset >= NLINES) {
199
if (page + 1 == npages) {
202
(long *)G_realloc(page_offset, npages * sizeof(long));
203
page_offset[npages - 1] = offset;
209
char label[GMAPSET_MAX + 7];
211
strcpy(cur_mapset, mapset);
212
sprintf(label, "Mapset %s", mapset);
213
dobox(&dummy, label, WHITE, top + line * height, left, right,
218
dobox(&list[count].box, name, GREY, top + line * height,
219
left + width / 2, right, 0);
224
dobox(&list[count].box, name, GREY, top + line * height, left,
225
left + width / 2, 0);
228
strcpy(list[count].name, name);
229
strcpy(list[count].mapset, mapset);
232
downarrow(&more, page + 1 < npages ? BLACK : WHITE);
233
uparrow(&less, page > 0 ? BLACK : WHITE);
235
switch (Input_pointer(objects)) {
236
case -1: /* more or less */
238
case -2: /* cancel */
241
default: /* file picked */
242
strcpy(xname, list[which].name);
243
strcpy(xmapset, list[which].mapset);
247
fseek(fd, page_offset[page], 0);
248
R_standard_color(WHITE);
249
R_box_abs(left + 1, top + 1, right - 1, bottom - 1);
252
/* all done. restore what was under the window */
253
right += height; /* move it back over the sidecar */
254
R_standard_color(WHITE);
255
R_box_abs(left, top, right, bottom);
256
R_panel_restore(tempfile1);
257
R_panel_restore(tempfile2);
258
R_panel_delete(tempfile1);
259
R_panel_delete(tempfile2);
266
static int dobox(struct box *box, char *text, int color, int top, int left,
267
int right, int centered)
271
bottom = top + height;
272
/* fill inside of box with color */
273
R_standard_color(color);
274
R_box_abs(left + 1, top + 1, right - 1, bottom - 1);
276
/* draw box outline and text in black */
277
R_standard_color(BLACK);
278
Outline_box(top, bottom, left, right);
279
dotext(text, top, bottom, left, right, centered);
283
box->bottom = bottom;
290
static int uparrow(struct box *box, int color)
292
R_standard_color(color);
293
Uparrow(box->top + edge, box->bottom - edge, box->left + edge,
299
static int downarrow(struct box *box, int color)
301
R_standard_color(color);
302
Downarrow(box->top + edge, box->bottom - edge, box->left + edge,
308
static int pick(int x, int y, int button)
312
if (inbox(&more, x, y)) {
314
if (page + 1 >= npages)
319
if (inbox(&less, x, y)) {
326
if (inbox(&cancel, x, y)) {
331
R_standard_color(RED);
332
Outline_box(cancel.top, cancel.bottom, cancel.left, cancel.right);
336
/* search name list. handle double click */
337
for (n = 0; n < count; n++)
338
if (inbox(&list[n].box, x, y)) {
339
if (n == which) /* second click! */
343
R_standard_color(RED);
344
Outline_box(list[n].box.top, list[n].box.bottom,
345
list[n].box.left, list[n].box.right);
347
return 0; /* ignore first click */
354
static int cancel_which(void)
357
R_standard_color(BLACK);
358
Outline_box(cancel.top, cancel.bottom, cancel.left, cancel.right);
360
else if (which >= 0) {
361
R_standard_color(BLACK);
362
Outline_box(list[which].box.top, list[which].box.bottom,
363
list[which].box.left, list[which].box.right);
371
static int inbox(struct box *box, int x, int y)
373
return (x > box->left && x < box->right && y > box->top &&
377
static int dotext(char *text, int top, int bottom, int left, int right,
380
R_text_size(text_size, text_size);
381
R_move_abs(left + 1 + edge, bottom - 1 - edge);
383
R_move_rel((right - left - strlen(text) * size) / 2, 0);
384
R_set_window(top, bottom, left, right); /* for text clipping */
386
R_set_window(SCREEN_TOP, SCREEN_BOTTOM, SCREEN_LEFT, SCREEN_RIGHT);