w3m

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/w3m.git/
Log | Files | Refs | README

commit b616bfabc552ddd667e3597dc3056b3e0fce7455
parent 32aa09939a41677af8565552b3a8a7f31463d65b
Author: ukai <ukai>
Date:   Tue, 19 Nov 2002 17:40:30 +0000

[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:
MChangeLog | 32++++++++++++++++++++++++++++++++
Mdisplay.c | 24++++++++++++++++--------
Mfm.h | 3+--
Mmain.c | 65+++++++++++++++++++++++++++++++++++++++++++++--------------------
Mmap.c | 276+++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------
Mproto.h | 11++++++-----
Mrc.c | 4++++
7 files changed, 291 insertions(+), 124 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,35 @@ +2002-11-20 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp> + + * [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 + 2002-11-20 Yoshinobu Sakane <sakane@d4.bsd.nes.nec.co.jp> * [w3m-dev 03450] Re: cygwin console on Win9X diff --git a/display.c b/display.c @@ -226,7 +226,7 @@ void displayBuffer(Buffer *buf, int mode) { Str msg; - Anchor *aa = NULL; + Str s = NULL; int ny = 0; if (buf->topLine == NULL && readBufferCache(buf) == 0) { /* clear_buffer */ @@ -341,14 +341,22 @@ displayBuffer(Buffer *buf, int mode) #endif Strcat_charp(msg, " <"); Strcat_charp(msg, buf->buffername); - if (displayLink) - aa = retrieveCurrentAnchor(buf); - if (aa) { - ParsedURL url; - Str s; + if (displayLink) { +#ifdef USE_IMAGE + s = getCurrentMapLabel(buf); + if (!s) +#endif + { + Anchor *a = retrieveCurrentAnchor(buf); + if (a) { + ParsedURL pu; + parseURL2(a->url, &pu, baseURL(buf)); + s = parsedURL2Str(&pu); + } + } + } + if (s) { int l; - parseURL2(aa->url, &url, baseURL(buf)); - s = parsedURL2Str(&url); l = buf->width - 2; if (s->length > l) { if (l >= 4) { diff --git a/fm.h b/fm.h @@ -290,7 +290,6 @@ typedef struct _MapArea { char *url; char *target; char *alt; -#ifdef MENU_MAP #ifdef USE_IMAGE char shape; short *coords; @@ -298,7 +297,6 @@ typedef struct _MapArea { short center_x; short center_y; #endif -#endif } MapArea; typedef struct _MapList { @@ -878,6 +876,7 @@ global int displayImage init(TRUE); global int autoImage init(TRUE); global int useExtImageViewer init(TRUE); global int maxLoadImage init(4); +global int image_map_list init(TRUE); #else global int displayImage init(FALSE); /* XXX: emacs-w3m use display_image=off */ #endif diff --git a/main.c b/main.c @@ -2757,9 +2757,15 @@ followA(void) return; } if (a && a->image && a->image->ismap) { - getMapXY(Currentbuf, retrieveCurrentImg(Currentbuf), &x, &y); + getMapXY(Currentbuf, a, &x, &y); map = 1; } +#else + a = retrieveCurrentMap(Currentbuf); + if (a) { + _followForm(FALSE); + return; + } #endif a = retrieveCurrentAnchor(Currentbuf); if (a == NULL) { @@ -3240,7 +3246,10 @@ _followForm(int submit) buf->form_submit = save_submit_formlist(fi); } } - else if ((fi->parent->method == FORM_METHOD_INTERNAL && (!Strcmp_charp(fi->parent->action, "map") || !Strcmp_charp(fi->parent->action, "none"))) || Currentbuf->bufferprop & BP_INTERNAL) { /* internal */ + else if ((fi->parent->method == FORM_METHOD_INTERNAL && + (!Strcmp_charp(fi->parent->action, "map") || + !Strcmp_charp(fi->parent->action, "none"))) || + Currentbuf->bufferprop & BP_INTERNAL) { /* internal */ do_internal(tmp2->ptr, tmp->ptr); } else { @@ -3275,16 +3284,16 @@ _followForm(int submit) } static void -drawAnchorCursor0(Buffer *buf, int hseq, int prevhseq, int tline, int eline, - int active) +drawAnchorCursor0(Buffer *buf, AnchorList *al, int hseq, int prevhseq, + int tline, int eline, int active) { int i, j; Line *l; Anchor *an; l = buf->topLine; - for (j = 0; j < buf->href->nanchor; j++) { - an = &buf->href->anchors[j]; + for (j = 0; j < al->nanchor; j++) { + an = &al->anchors[j]; if (an->start.line < tline) continue; if (an->start.line >= eline) @@ -3324,13 +3333,15 @@ drawAnchorCursor(Buffer *buf) int hseq, prevhseq; int tline, eline; - if (buf->firstLine == NULL) + if (!buf->firstLine || !buf->hmarklist) return; - if (buf->href == NULL) + if (!buf->href && !buf->formitem) return; an = retrieveCurrentAnchor(buf); - if (an != NULL) + if (!an) + an = retrieveCurrentMap(buf); + if (an) hseq = an->hseq; else hseq = -1; @@ -3338,8 +3349,14 @@ drawAnchorCursor(Buffer *buf) eline = tline + buf->LINES; prevhseq = buf->hmarklist->prevhseq; - drawAnchorCursor0(buf, hseq, prevhseq, tline, eline, 1); - drawAnchorCursor0(buf, hseq, -1, tline, eline, 0); + if (buf->href) { + drawAnchorCursor0(buf, buf->href, hseq, prevhseq, tline, eline, 1); + drawAnchorCursor0(buf, buf->href, hseq, -1, tline, eline, 0); + } + if (buf->formitem) { + drawAnchorCursor0(buf, buf->formitem, hseq, prevhseq, tline, eline, 1); + drawAnchorCursor0(buf, buf->formitem, hseq, -1, tline, eline, 0); + } buf->hmarklist->prevhseq = hseq; } @@ -4002,7 +4019,8 @@ pginfo(void) void follow_map(struct parsed_tagarg *arg) { -#ifdef MENU_MAP + char *name = tag_get_value(arg, "link"); +#if defined(MENU_MAP) || defined(USE_IMAGE) Anchor *an; MapArea *a; int x, y; @@ -4011,9 +4029,22 @@ follow_map(struct parsed_tagarg *arg) an = retrieveCurrentImg(Currentbuf); x = Currentbuf->cursorX + Currentbuf->rootX; y = Currentbuf->cursorY + Currentbuf->rootY; - a = follow_map_menu(Currentbuf, arg, an, x, y); - if (a == NULL || a->url == NULL || *(a->url) == '\0') + a = follow_map_menu(Currentbuf, name, an, x, y); + if (a == NULL || a->url == NULL || *(a->url) == '\0') { +#endif +#ifndef MENU_MAP + Buffer *buf = follow_map_panel(Currentbuf, name); + + if (buf != NULL) { +#ifdef JP_CHARSET + buf->document_code = Currentbuf->document_code; +#endif /* JP_CHARSET */ + cmd_loadBuffer(buf, BP_NORMAL, LB_NOLINK); + } +#endif +#if defined(MENU_MAP) || defined(USE_IMAGE) return; + } if (*(a->url) == '#') { gotoLabel(a->url + 1); return; @@ -4037,12 +4068,6 @@ follow_map(struct parsed_tagarg *arg) } cmd_loadURL(a->url, baseURL(Currentbuf), parsedURL2Str(&Currentbuf->currentURL)->ptr); -#else - Buffer *buf; - - buf = follow_map_panel(Currentbuf, arg); - if (buf != NULL) - cmd_loadBuffer(buf, BP_NORMAL, LB_NOLINK); #endif } diff --git a/map.c b/map.c @@ -5,7 +5,20 @@ #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) { diff --git a/proto.h b/proto.h @@ -360,15 +360,16 @@ extern void form_write_data(FILE * f, char *boundary, char *name, char *value); extern void form_write_from_file(FILE * f, char *boundary, char *name, char *filename, char *file); extern void follow_map(struct parsed_tagarg *arg); -#ifdef MENU_MAP -extern MapArea *follow_map_menu(Buffer *buf, struct parsed_tagarg *arg, - Anchor *a_img, int x, int y); -#else -extern Buffer *follow_map_panel(Buffer *buf, struct parsed_tagarg *arg); +extern MapArea *follow_map_menu(Buffer *buf, char *name, Anchor *a_img, int x, + int y); +#ifndef MENU_MAP +extern Buffer *follow_map_panel(Buffer *buf, char *name); #endif #ifdef USE_IMAGE extern int getMapXY(Buffer *buf, Anchor *a, int *x, int *y); +extern Str getCurrentMapLabel(Buffer *buf); #endif +extern Anchor *retrieveCurrentMap(Buffer *buf); extern MapArea *newMapArea(char *url, char *target, char *alt, char *shape, char *coords); extern Buffer *page_info_panel(Buffer *buf); diff --git a/rc.c b/rc.c @@ -76,6 +76,7 @@ static char *config_file = NULL; #define CMT_EXT_IMAGE_VIEWER "画像を外部ビューワで表示" #define CMT_IMAGE_SCALE "画像のスケール(%)" #define CMT_IMGDISPLAY "画像を表示するためのコマンド" +#define CMT_IMAGE_MAP_LIST "イメージマップのリンク先一覧を表示" #endif #define CMT_MULTICOL "ファイル名のマルチカラム表示" #define CMT_ALT_ENTITY "エンティティを ASCII の代替表現で表す" @@ -229,6 +230,7 @@ static char *config_file = NULL; #define CMT_EXT_IMAGE_VIEWER "Use external image viewer" #define CMT_IMAGE_SCALE "Scale of image (%)" #define CMT_IMGDISPLAY "External command to display image" +#define CMT_IMAGE_MAP_LIST "Use link list of image map" #endif #define CMT_MULTICOL "Display file names in multi-column format" #define CMT_ALT_ENTITY "Use ASCII equivalents to display entities" @@ -539,6 +541,8 @@ struct param_ptr params1[] = { NULL}, {"imgdisplay", P_STRING, PI_TEXT, (void *)&Imgdisplay, CMT_IMGDISPLAY, NULL}, + {"image_map_list", P_INT, PI_ONOFF, (void *)&image_map_list, + CMT_IMAGE_MAP_LIST, NULL}, #endif {"show_lnum", P_INT, PI_ONOFF, (void *)&showLineNum, CMT_SHOW_NUM, NULL}, {"show_srch_str", P_INT, PI_ONOFF, (void *)&show_srch_str,