aboutsummaryrefslogtreecommitdiffstats
path: root/map.c
diff options
context:
space:
mode:
authorFumitoshi UKAI <ukai@debian.or.jp>2002-11-19 17:40:30 +0000
committerFumitoshi UKAI <ukai@debian.or.jp>2002-11-19 17:40:30 +0000
commita17f5fe8175ccab8f52513f0b8141f7fd6ef393a (patch)
tree37251032522383ab060e7a9faad9afcced46b353 /map.c
parent[w3m-dev 03450] Re: cygwin console on Win9X (diff)
downloadw3m-a17f5fe8175ccab8f52513f0b8141f7fd6ef393a.tar.gz
w3m-a17f5fe8175ccab8f52513f0b8141f7fd6ef393a.zip
[w3m-dev 03452] image map
* display.c (displayBuffer): use getCurrentMapLabel() * fm.h (MapArea): delete ifdef MENU_MAP (image_map_list): added * main.c (followA): don't call retrieveCurrentImg() ifdef USE_IMAGE use retrieveCurrentMap() ifndef USE_IMAGE (_followForm): indent (drawAnchorCursor0): add AnchorList (drawAnchorCuror): pass AnchorList to drawAnchorCursor0 (follow_map): follow_map_panel * map.c (searchMapList): added (nearestMapArea): n, min default value to -1 (searchMapArea): added (getCurrentMapLabel): added (getMapXY): moved (retrieveCurrentMap): added (follow_map_menu): parsed_tagarg -> name rewrite to search map list/area (follow_map_panel): parsed_tagarg -> name rewrite to search map list/area (newMapArea): delete ifdef MENU_MAP (append_map_info): added (page_info_panel): append_map_info * proto.h (follow_map_menu): parsed_tagarg -> name (follow_map_panel): parsed_tagarg -> name (getCurrentMapLabel): added (retrieveCurrentMap): added * rc.c (CMT_IMAGE_MAP_LIST): added (image_map_list): added From: Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
Diffstat (limited to 'map.c')
-rw-r--r--map.c278
1 files changed, 188 insertions, 90 deletions
diff --git a/map.c b/map.c
index 8bf19da..69b47fe 100644
--- a/map.c
+++ b/map.c
@@ -1,11 +1,24 @@
-/* $Id: map.c,v 1.13 2002/11/13 15:51:39 ukai Exp $ */
+/* $Id: map.c,v 1.14 2002/11/19 17:40:34 ukai Exp $ */
/*
* client-side image maps
*/
#include "fm.h"
#include <math.h>
-#ifdef MENU_MAP
+static MapList *
+searchMapList(Buffer *buf, char *name)
+{
+ MapList *ml;
+
+ if (name == NULL)
+ return NULL;
+ for (ml = buf->maplist; ml != NULL; ml = ml->next) {
+ if (!Strcmp_charp(ml->name, name))
+ break;
+ }
+ return ml;
+}
+
#ifdef USE_IMAGE
static int
inMapArea(MapArea * a, int x, int y)
@@ -63,7 +76,7 @@ nearestMapArea(MapList *ml, int x, int y)
{
ListItem *al;
MapArea *a;
- int i, l, n = 0, min = -1, limit = pixel_per_char * pixel_per_char
+ int i, l, n = -1, min = -1, limit = pixel_per_char * pixel_per_char
+ pixel_per_line * pixel_per_line;
if (!ml || !ml->area)
@@ -81,72 +94,157 @@ nearestMapArea(MapList *ml, int x, int y)
}
return n;
}
+
+static int
+searchMapArea(Buffer *buf, MapList *ml, Anchor *a_img)
+{
+ ListItem *al;
+ MapArea *a;
+ int i, n;
+ int px, py;
+
+ if (!(ml && ml->area && ml->area->nitem))
+ return -1;
+ if (! getMapXY(buf, a_img, &px, &py))
+ return -1;
+ n = - ml->area->nitem;
+ for (i = 0, al = ml->area->first; al != NULL; i++, al = al->next) {
+ a = (MapArea *) al->ptr;
+ if (!a)
+ continue;
+ if (n < 0 && inMapArea(a, px, py)) {
+ if (a->shape == SHAPE_DEFAULT) {
+ if (n == - ml->area->nitem)
+ n = -i;
+ }
+ else
+ n = i;
+ }
+ }
+ if (n == - ml->area->nitem)
+ return nearestMapArea(ml, px, py);
+ else if (n < 0)
+ return -n;
+ return n;
+}
+
+Str
+getCurrentMapLabel(Buffer *buf)
+{
+ Anchor *a_img, *a_form;
+ FormItemList *fi;
+ MapList *ml;
+ ListItem *al;
+ MapArea *a;
+ int i, n;
+ Str s;
+
+ a_img = retrieveCurrentImg(buf);
+ if (!(a_img && a_img->image && a_img->image->map))
+ return NULL;
+ a_form = retrieveCurrentForm(buf);
+ if (!(a_form && a_form->url))
+ return NULL;
+ fi = (FormItemList *)a_form->url;
+ if (!(fi && fi->parent && fi->parent->item))
+ return NULL;
+ fi = fi->parent->item;
+ ml = searchMapList(buf, fi->value ? fi->value->ptr : NULL);
+ if (!ml)
+ return NULL;
+ n = searchMapArea(buf, ml, a_img);
+ if (n < 0)
+ return NULL;
+ for (i = 0, al = ml->area->first; al != NULL; i++, al = al->next) {
+ a = (MapArea *) al->ptr;
+ if (!(a && i == n))
+ continue;
+ s = Sprintf("[%s]", a->alt);
+ if (*a->alt) {
+ ParsedURL pu;
+ parseURL2(a->url, &pu, baseURL(buf));
+ Strcat_char(s, ' ');
+ Strcat(s, parsedURL2Str(&pu));
+ }
+ return s;
+ }
+ return NULL;
+}
+
+int
+getMapXY(Buffer *buf, Anchor *a, int *x, int *y)
+{
+ if (!buf || !a || !a->image || !x || !y)
+ return 0;
+ *x = (int)((buf->currentColumn + buf->cursorX
+ - COLPOS(buf->currentLine, a->start.pos) + 0.5)
+ * pixel_per_char) - a->image->xoffset;
+ *y = (int)((buf->currentLine->linenumber - a->image->y + 0.5)
+ * pixel_per_line) - a->image->yoffset;
+ if (*x <= 0)
+ *x = 1;
+ if (*y <= 0)
+ *y = 1;
+ return 1;
+}
#endif
+Anchor *
+retrieveCurrentMap(Buffer *buf)
+{
+ Anchor *a;
+ FormItemList *fi;
+
+ a = retrieveCurrentForm(buf);
+ if (!a || !a->url)
+ return NULL;
+ fi = (FormItemList *)a->url;
+ if (fi->parent->method == FORM_METHOD_INTERNAL &&
+ !Strcmp_charp(fi->parent->action, "map"))
+ return a;
+ return NULL;
+}
+
MapArea *
-follow_map_menu(Buffer *buf, struct parsed_tagarg * arg, Anchor *a_img, int x,
- int y)
+follow_map_menu(Buffer *buf, char *name, Anchor *a_img, int x, int y)
{
MapList *ml;
ListItem *al;
MapArea *a;
- char *name;
- int i, n, selected = -1, initial;
+ int i, selected = -1, initial = 0;
+#ifdef MENU_MAP
char **label;
-#ifdef USE_IMAGE
- int px, py, map = 0;
#endif
- name = tag_get_value(arg, "link");
- if (name == NULL)
- return NULL;
-
- for (ml = buf->maplist; ml != NULL; ml = ml->next) {
- if (!Strcmp_charp(ml->name, name))
- break;
- }
- if (ml == NULL || ml->area == NULL)
+ ml = searchMapList(buf, name);
+ if (ml == NULL || ml->area == NULL || ml->area->nitem == 0)
return NULL;
- n = ml->area->nitem;
- if (n == 0)
- return NULL;
- label = New_N(char *, n + 1);
#ifdef USE_IMAGE
- if (getMapXY(buf, a_img, &px, &py))
- map = 1;
+ initial = searchMapArea(buf, ml, a_img);
+ if (initial < 0)
+ initial = 0;
+ else if (!image_map_list) {
+ selected = initial;
+ goto map_end;
+ }
#endif
- initial = -n;
+
+#ifdef MENU_MAP
+ label = New_N(char *, ml->area->nitem + 1);
for (i = 0, al = ml->area->first; al != NULL; i++, al = al->next) {
a = (MapArea *) al->ptr;
- if (a) {
+ if (a)
label[i] = *a->alt ? a->alt : a->url;
-#ifdef USE_IMAGE
- if (initial < 0 && map && inMapArea(a, px, py)) {
- if (a->shape == SHAPE_DEFAULT) {
- if (initial == -n)
- initial = -i;
- }
- else
- initial = i;
- }
-#endif
- }
else
label[i] = "";
}
- label[n] = NULL;
- if (initial == -n)
-#ifdef USE_IMAGE
- initial = map ? nearestMapArea(ml, px, py) : 0;
-#else
- initial = 0;
-#endif
- else if (initial < 0)
- initial *= -1;
+ label[ml->area->nitem] = NULL;
optionMenu(x, y, label, &selected, initial, NULL);
+#endif
+ map_end:
if (selected >= 0) {
for (i = 0, al = ml->area->first; al != NULL; i++, al = al->next) {
if (al->ptr && i == selected)
@@ -156,28 +254,22 @@ follow_map_menu(Buffer *buf, struct parsed_tagarg * arg, Anchor *a_img, int x,
return NULL;
}
-#else
+#ifndef MENU_MAP
char *map1 = "<HTML><HEAD><TITLE>Image map links</TITLE></HEAD>\
-<BODY><H1>Image map links</H1>";
+<BODY><H1>Image map links</H1>\
+<table>";
Buffer *
-follow_map_panel(Buffer *buf, struct parsed_tagarg *arg)
+follow_map_panel(Buffer *buf, char *name)
{
Str mappage;
MapList *ml;
ListItem *al;
MapArea *a;
- char *name;
ParsedURL pu;
+ char *url;
- name = tag_get_value(arg, "link");
- if (name == NULL)
- return NULL;
-
- for (ml = buf->maplist; ml != NULL; ml = ml->next) {
- if (!Strcmp_charp(ml->name, name))
- break;
- }
+ ml = searchMapList(buf, name);
if (ml == NULL)
return NULL;
@@ -187,54 +279,28 @@ follow_map_panel(Buffer *buf, struct parsed_tagarg *arg)
if (!a)
continue;
parseURL2(a->url, &pu, baseURL(buf));
- Strcat_charp(mappage, "<a href=\"");
- Strcat_charp(mappage, html_quote(parsedURL2Str(&pu)->ptr));
- Strcat_charp(mappage, "\">");
- Strcat_charp(mappage, html_quote(a->alt));
- Strcat_charp(mappage, " ");
- Strcat_charp(mappage, html_quote(a->url));
- Strcat_charp(mappage, "</a><br>\n");
+ url = html_quote(parsedURL2Str(&pu)->ptr);
+ Strcat_m_charp(mappage, "<tr><td>", html_quote(a->alt),
+ "<td><a href=\"", url, "\">", url, "</a>\n", NULL);
}
- Strcat_charp(mappage, "</body></html>");
+ Strcat_charp(mappage, "</table></body></html>");
return loadHTMLString(mappage);
}
#endif
-#ifdef USE_IMAGE
-int
-getMapXY(Buffer *buf, Anchor *a, int *x, int *y)
-{
- if (!buf || !a || !a->image || !x || !y)
- return 0;
- *x = (int)((buf->currentColumn + buf->cursorX
- - COLPOS(buf->currentLine, a->start.pos) + 0.5)
- * pixel_per_char) - a->image->xoffset;
- *y = (int)((buf->currentLine->linenumber - a->image->y + 0.5)
- * pixel_per_line) - a->image->yoffset;
- if (*x <= 0)
- *x = 1;
- if (*y <= 0)
- *y = 1;
- return 1;
-}
-#endif
-
MapArea *
newMapArea(char *url, char *target, char *alt, char *shape, char *coords)
{
MapArea *a = New(MapArea);
-#ifdef MENU_MAP
#ifdef USE_IMAGE
char *p;
int i, max;
#endif
-#endif
a->url = url;
a->target = target;
a->alt = alt ? alt : "";
-#ifdef MENU_MAP
#ifdef USE_IMAGE
a->shape = SHAPE_RECT;
if (shape) {
@@ -317,10 +383,38 @@ newMapArea(char *url, char *target, char *alt, char *shape, char *coords)
a->center_y /= a->ncoords / 2;
}
#endif
-#endif
return a;
}
+/* append image map links */
+static void
+append_map_info(Buffer *buf, Str tmp, FormItemList *fi)
+{
+ MapList *ml;
+ ListItem *al;
+ MapArea *a;
+ ParsedURL pu;
+ char *url;
+
+ ml = searchMapList(buf, fi->value ? fi->value->ptr : NULL);
+ if (ml == NULL)
+ return;
+
+ Strcat_charp(tmp, "<tr><td colspan=2>Links of current image map");
+ Strcat_charp(tmp, "<tr><td colspan=2><table>");
+ for (al = ml->area->first; al != NULL; al = al->next) {
+ a = (MapArea *) al->ptr;
+ if (!a)
+ continue;
+ parseURL2(a->url, &pu, baseURL(buf));
+ url = html_quote(parsedURL2Str(&pu)->ptr);
+ Strcat_m_charp(tmp, "<tr><td>&nbsp;&nbsp;<td>",
+ html_quote(a->alt), "<td><a href=\"", url, "\">", url,
+ "</a>\n", NULL);
+ }
+ Strcat_charp(tmp, "</table>");
+}
+
/* append frame URL */
static void
append_frame_info(Buffer *buf, Str html, struct frameset *set, int level)
@@ -436,9 +530,13 @@ page_info_panel(Buffer *buf)
}
a = retrieveCurrentForm(buf);
if (a != NULL) {
- s = Strnew_charp(form2str((FormItemList *)a->url));
+ FormItemList *fi = (FormItemList *)a->url;
+ s = Strnew_charp(form2str(fi));
Strcat_charp(tmp, "<tr><td nowrap>Method/type of current form<td>");
Strcat_charp(tmp, html_quote(s->ptr));
+ if (fi->parent->method == FORM_METHOD_INTERNAL &&
+ !Strcmp_charp(fi->parent->action, "map"))
+ append_map_info(buf, tmp, fi->parent->item);
}
Strcat_charp(tmp, "</table>\n");
if (buf->document_header != NULL) {