1
/* $Id: map.c,v 1.30 2003/09/24 18:49:00 ukai Exp $ */
3
* client-side image maps
9
searchMapList(Buffer *buf, char *name)
15
for (ml = buf->maplist; ml != NULL; ml = ml->next) {
16
if (!Strcmp_charp(ml->name, name))
24
inMapArea(MapArea * a, int x, int y)
27
double r1, r2, s, c, t;
33
if (x >= a->coords[0] && y >= a->coords[1] &&
34
x <= a->coords[2] && y <= a->coords[3])
38
if ((x - a->coords[0]) * (x - a->coords[0])
39
+ (y - a->coords[1]) * (y - a->coords[1])
40
<= a->coords[2] * a->coords[2])
44
for (t = 0, i = 0; i < a->ncoords; i += 2) {
45
r1 = sqrt((double)(x - a->coords[i]) * (x - a->coords[i])
46
+ (double)(y - a->coords[i + 1]) * (y -
48
r2 = sqrt((double)(x - a->coords[i + 2]) * (x - a->coords[i + 2])
49
+ (double)(y - a->coords[i + 3]) * (y -
51
if (r1 == 0 || r2 == 0)
53
s = ((double)(x - a->coords[i]) * (y - a->coords[i + 3])
54
- (double)(x - a->coords[i + 2]) * (y -
57
c = ((double)(x - a->coords[i]) * (x - a->coords[i + 2])
58
+ (double)(y - a->coords[i + 1]) * (y -
63
if (fabs(t) > 2 * 3.14)
75
nearestMapArea(MapList *ml, int x, int y)
79
int i, l, n = -1, min = -1, limit = pixel_per_char * pixel_per_char
80
+ pixel_per_line * pixel_per_line;
84
for (i = 0, al = ml->area->first; al != NULL; i++, al = al->next) {
85
a = (MapArea *) al->ptr;
87
l = (a->center_x - x) * (a->center_x - x)
88
+ (a->center_y - y) * (a->center_y - y);
89
if ((min < 0 || l < min) && l < limit) {
99
searchMapArea(Buffer *buf, MapList *ml, Anchor *a_img)
106
if (!(ml && ml->area && ml->area->nitem))
108
if (!getMapXY(buf, a_img, &px, &py))
110
n = -ml->area->nitem;
111
for (i = 0, al = ml->area->first; al != NULL; i++, al = al->next) {
112
a = (MapArea *) al->ptr;
115
if (n < 0 && inMapArea(a, px, py)) {
116
if (a->shape == SHAPE_DEFAULT) {
117
if (n == -ml->area->nitem)
124
if (n == -ml->area->nitem)
125
return nearestMapArea(ml, px, py);
132
retrieveCurrentMapArea(Buffer *buf)
134
Anchor *a_img, *a_form;
141
a_img = retrieveCurrentImg(buf);
142
if (!(a_img && a_img->image && a_img->image->map))
144
a_form = retrieveCurrentForm(buf);
145
if (!(a_form && a_form->url))
147
fi = (FormItemList *)a_form->url;
148
if (!(fi && fi->parent && fi->parent->item))
150
fi = fi->parent->item;
151
ml = searchMapList(buf, fi->value ? fi->value->ptr : NULL);
154
n = searchMapArea(buf, ml, a_img);
157
for (i = 0, al = ml->area->first; al != NULL; i++, al = al->next) {
158
a = (MapArea *) al->ptr;
166
getMapXY(Buffer *buf, Anchor *a, int *x, int *y)
168
if (!buf || !a || !a->image || !x || !y)
170
*x = (int)((buf->currentColumn + buf->cursorX
171
- COLPOS(buf->currentLine, a->start.pos) + 0.5)
172
* pixel_per_char) - a->image->xoffset;
173
*y = (int)((buf->currentLine->linenumber - a->image->y + 0.5)
174
* pixel_per_line) - a->image->yoffset;
184
retrieveCurrentMap(Buffer *buf)
189
a = retrieveCurrentForm(buf);
192
fi = (FormItemList *)a->url;
193
if (fi->parent->method == FORM_METHOD_INTERNAL &&
194
!Strcmp_charp(fi->parent->action, "map"))
199
#if defined(USE_IMAGE) || defined(MENU_MAP)
201
follow_map_menu(Buffer *buf, char *name, Anchor *a_img, int x, int y)
205
int i, selected = -1;
212
ml = searchMapList(buf, name);
213
if (ml == NULL || ml->area == NULL || ml->area->nitem == 0)
217
initial = searchMapArea(buf, ml, a_img);
220
else if (!image_map_list) {
227
label = New_N(char *, ml->area->nitem + 1);
228
for (i = 0, al = ml->area->first; al != NULL; i++, al = al->next) {
229
a = (MapArea *) al->ptr;
231
label[i] = *a->alt ? a->alt : a->url;
235
label[ml->area->nitem] = NULL;
237
optionMenu(x, y, label, &selected, initial, NULL);
244
for (i = 0, al = ml->area->first; al != NULL; i++, al = al->next) {
245
if (al->ptr && i == selected)
246
return (MapArea *) al->ptr;
254
char *map1 = "<HTML><HEAD><TITLE>Image map links</TITLE></HEAD>\
255
<BODY><H1>Image map links</H1>\
259
follow_map_panel(Buffer *buf, char *name)
269
ml = searchMapList(buf, name);
273
mappage = Strnew_charp(map1);
274
for (al = ml->area->first; al != NULL; al = al->next) {
275
a = (MapArea *) al->ptr;
278
parseURL2(a->url, &pu, baseURL(buf));
279
p = parsedURL2Str(&pu)->ptr;
282
p = html_quote(url_unquote_conv(p, buf->document_charset));
285
Strcat_m_charp(mappage, "<tr valign=top><td><a href=\"", q, "\">",
286
html_quote(*a->alt ? a->alt : mybasename(a->url)),
287
"</a><td>", p, NULL);
289
Strcat_charp(mappage, "</table></body></html>");
291
newbuf = loadHTMLString(mappage);
294
newbuf->document_charset = buf->document_charset;
301
newMapArea(char *url, char *target, char *alt, char *shape, char *coords)
303
MapArea *a = New(MapArea);
311
a->alt = alt ? alt : "";
313
a->shape = SHAPE_RECT;
315
if (!strcasecmp(shape, "default"))
316
a->shape = SHAPE_DEFAULT;
317
else if (!strncasecmp(shape, "rect", 4))
318
a->shape = SHAPE_RECT;
319
else if (!strncasecmp(shape, "circ", 4))
320
a->shape = SHAPE_CIRCLE;
321
else if (!strncasecmp(shape, "poly", 4))
322
a->shape = SHAPE_POLY;
324
a->shape = SHAPE_UNKNOWN;
330
if (a->shape == SHAPE_UNKNOWN || a->shape == SHAPE_DEFAULT)
333
a->shape = SHAPE_UNKNOWN;
336
if (a->shape == SHAPE_RECT) {
337
a->coords = New_N(short, 4);
340
else if (a->shape == SHAPE_CIRCLE) {
341
a->coords = New_N(short, 3);
345
for (i = 0, p = coords; (a->shape == SHAPE_POLY || i < a->ncoords) && *p;) {
348
if (!IS_DIGIT(*p) && *p != '-' && *p != '+')
350
if (a->shape == SHAPE_POLY) {
353
a->coords = New_Reuse(short, a->coords, max + 2);
357
a->coords[i] = (short)atoi(p);
359
if (*p == '-' || *p == '+')
363
if (*p != ',' && !IS_SPACE(*p))
370
if (i != a->ncoords || (a->shape == SHAPE_POLY && a->ncoords < 6)) {
371
a->shape = SHAPE_UNKNOWN;
376
if (a->shape == SHAPE_POLY) {
377
a->ncoords = a->ncoords / 2 * 2;
378
a->coords[a->ncoords] = a->coords[0];
379
a->coords[a->ncoords + 1] = a->coords[1];
381
if (a->shape == SHAPE_CIRCLE) {
382
a->center_x = a->coords[0];
383
a->center_y = a->coords[1];
386
for (i = 0; i < a->ncoords / 2; i++) {
387
a->center_x += a->coords[2 * i];
388
a->center_y += a->coords[2 * i + 1];
390
a->center_x /= a->ncoords / 2;
391
a->center_y /= a->ncoords / 2;
397
/* append image map links */
399
append_map_info(Buffer *buf, Str tmp, FormItemList *fi)
407
ml = searchMapList(buf, fi->value ? fi->value->ptr : NULL);
412
"<tr valign=top><td colspan=2>Links of current image map",
413
"<tr valign=top><td colspan=2><table>", NULL);
414
for (al = ml->area->first; al != NULL; al = al->next) {
415
a = (MapArea *) al->ptr;
418
parseURL2(a->url, &pu, baseURL(buf));
419
q = html_quote(parsedURL2Str(&pu)->ptr);
421
p = html_quote(url_unquote_conv(a->url, buf->document_charset));
423
p = html_quote(a->url);
424
Strcat_m_charp(tmp, "<tr valign=top><td> <td><a href=\"",
426
html_quote(*a->alt ? a->alt : mybasename(a->url)),
427
"</a><td>", p, "\n", NULL);
429
Strcat_charp(tmp, "</table>");
434
append_link_info(Buffer *buf, Str html, LinkList * link)
443
Strcat_charp(html, "<hr width=50%><h1>Link information</h1><table>\n");
444
for (l = link; l; l = l->next) {
446
parseURL2(l->url, &pu, baseURL(buf));
447
url = html_quote(parsedURL2Str(&pu)->ptr);
451
Strcat_m_charp(html, "<tr valign=top><td><a href=\"", url, "\">",
452
l->title ? html_quote(l->title) : "(empty)", "</a><td>",
454
if (l->type == LINK_TYPE_REL)
455
Strcat_charp(html, "[Rel]");
456
else if (l->type == LINK_TYPE_REV)
457
Strcat_charp(html, "[Rev]");
461
url = html_quote(url_unquote_conv(l->url, buf->document_charset));
463
url = html_quote(l->url);
464
Strcat_m_charp(html, "<td>", url, NULL);
466
Strcat_m_charp(html, " (", html_quote(l->ctype), ")", NULL);
467
Strcat_charp(html, "\n");
469
Strcat_charp(html, "</table>\n");
472
/* append frame URL */
474
append_frame_info(Buffer *buf, Str html, struct frameset *set, int level)
482
for (i = 0; i < set->col * set->row; i++) {
483
union frameset_element frame = set->frame[i];
484
if (frame.element != NULL) {
485
switch (frame.element->attr) {
488
if (frame.body->url == NULL)
490
Strcat_charp(html, "<pre_int>");
491
for (j = 0; j < level; j++)
492
Strcat_charp(html, " ");
493
q = html_quote(frame.body->url);
494
Strcat_m_charp(html, "<a href=\"", q, "\">", NULL);
495
if (frame.body->name) {
496
p = html_quote(url_unquote_conv(frame.body->name,
497
buf->document_charset));
498
Strcat_charp(html, p);
501
p = html_quote(url_unquote_conv(frame.body->url,
502
buf->document_charset));
505
Strcat_m_charp(html, " ", p, "</a></pre_int><br>\n", NULL);
507
if (frame.body->ssl_certificate)
509
"<blockquote><h2>SSL certificate</h2><pre>\n",
510
html_quote(frame.body->ssl_certificate),
511
"</pre></blockquote>\n", NULL);
515
append_frame_info(buf, html, frame.set, level + 1);
523
* information of current page and link
526
page_info_panel(Buffer *buf)
528
Str tmp = Strnew_size(1024);
532
struct frameset *f_set = NULL;
541
Strcat_charp(tmp, "<html><head>\
542
<title>Information about current page</title>\
544
<h1>Information about current page</h1>\n");
548
if (all == 0 && buf->lastLine)
549
all = buf->lastLine->linenumber;
551
Strcat_charp(tmp, "<form method=internal action=charset>");
553
p = parsedURL2Str(&buf->currentURL)->ptr;
555
p = url_unquote_conv(p, 0);
556
Strcat_m_charp(tmp, "<table cellpadding=0>",
557
"<tr valign=top><td nowrap>Title<td>",
558
html_quote(buf->buffername),
559
"<tr valign=top><td nowrap>Current URL<td>",
561
"<tr valign=top><td nowrap>Document Type<td>",
562
buf->real_type ? html_quote(buf->real_type) : "unknown",
563
"<tr valign=top><td nowrap>Last Modified<td>",
564
html_quote(last_modified(buf)), NULL);
566
if (buf->document_charset != InnerCharset) {
567
list = wc_get_ces_list();
569
"<tr><td nowrap>Document Charset<td><select name=charset>");
570
for (; list->name != NULL; list++) {
571
sprintf(charset, "%d", (unsigned int)list->id);
572
Strcat_m_charp(tmp, "<option value=", charset,
573
(buf->document_charset == list->id) ? " selected>"
574
: ">", list->desc, NULL);
576
Strcat_charp(tmp, "</select>");
577
Strcat_charp(tmp, "<tr><td><td><input type=submit value=Change>");
581
"<tr valign=top><td nowrap>Number of lines<td>",
582
Sprintf("%d", all)->ptr,
583
"<tr valign=top><td nowrap>Transferred bytes<td>",
584
Sprintf("%d", buf->trbyte)->ptr, NULL);
586
a = retrieveCurrentAnchor(buf);
588
parseURL2(a->url, &pu, baseURL(buf));
589
p = parsedURL2Str(&pu)->ptr;
592
p = html_quote(url_unquote_conv(p, buf->document_charset));
596
"<tr valign=top><td nowrap>URL of current anchor<td><a href=\"",
597
q, "\">", p, "</a>", NULL);
599
a = retrieveCurrentImg(buf);
601
parseURL2(a->url, &pu, baseURL(buf));
602
p = parsedURL2Str(&pu)->ptr;
605
p = html_quote(url_unquote_conv(p, buf->document_charset));
609
"<tr valign=top><td nowrap>URL of current image<td><a href=\"",
610
q, "\">", p, "</a>", NULL);
612
a = retrieveCurrentForm(buf);
614
FormItemList *fi = (FormItemList *)a->url;
617
p = html_quote(url_unquote_conv(p, buf->document_charset));
621
"<tr valign=top><td nowrap>Method/type of current form <td>",
623
if (fi->parent->method == FORM_METHOD_INTERNAL
624
&& !Strcmp_charp(fi->parent->action, "map"))
625
append_map_info(buf, tmp, fi->parent->item);
627
Strcat_charp(tmp, "</table>\n");
629
Strcat_charp(tmp, "</form>");
632
append_link_info(buf, tmp, buf->linklist);
634
if (buf->document_header != NULL) {
635
Strcat_charp(tmp, "<hr width=50%><h1>Header information</h1><pre>\n");
636
for (ti = buf->document_header->first; ti != NULL; ti = ti->next)
637
Strcat_m_charp(tmp, "<pre_int>", html_quote(ti->ptr),
638
"</pre_int>\n", NULL);
639
Strcat_charp(tmp, "</pre>\n");
642
if (buf->frameset != NULL)
643
f_set = buf->frameset;
644
else if (buf->bufferprop & BP_FRAME &&
645
buf->nextBuffer != NULL && buf->nextBuffer->frameset != NULL)
646
f_set = buf->nextBuffer->frameset;
649
Strcat_charp(tmp, "<hr width=50%><h1>Frame information</h1>\n");
650
append_frame_info(buf, tmp, f_set, 0);
653
if (buf->ssl_certificate)
654
Strcat_m_charp(tmp, "<h1>SSL certificate</h1><pre>\n",
655
html_quote(buf->ssl_certificate), "</pre>\n", NULL);
658
Strcat_charp(tmp, "</body></html>");
659
newbuf = loadHTMLString(tmp);
662
newbuf->document_charset = buf->document_charset;