commit 97bae32decb08b42760838770f30dc963a16275d
parent bf17175fde529a1d6bac7b787d56fafaf7add19a
Author: ukai <ukai>
Date: Thu, 21 Nov 2002 16:31:35 +0000
[w3m-dev 03455] mouse menu
* configure (config.h): MOUSE_FILE
* display.c (displayBuffer): nTab -> nTab2, N_TAB -> nTabLine()
(redrawNLine): nTab -> nTab2, N_TAB -> nTabLine()
mouse_menu support
* fm.h (nTab2): added
(N_TAB): deleted
(NO_TABBUFFER): added
(struct _MouseMenu): added
(mouse_menu_map): added
(mouse_menu): added
* func.c (initMouseMenu): added
* main.c (main): initMouseMenu()
(posTab): mouse_menu support
(mouse_menu_action): added
(process_mouse): mouse_menu support
(reinit): initMouseMenu()
(nTabLine): added
(moveTab): check NO_TABBUFFER
* proto.h (nTabLine): added
(initMouseMenu): added
* rc.c (sync_with_option): initMouseMenu()
From: Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
Diffstat:
M | ChangeLog | | | 25 | +++++++++++++++++++++++++ |
M | configure | | | 1 | + |
M | display.c | | | 18 | ++++++++++++------ |
M | fm.h | | | 9 | +++++++-- |
M | func.c | | | 65 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
M | main.c | | | 101 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- |
M | proto.h | | | 4 | ++++ |
M | rc.c | | | 3 | +++ |
8 files changed, 208 insertions(+), 18 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,3 +1,28 @@
+2002-11-22 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
+
+ * [w3m-dev 03455] mouse menu
+ * configure (config.h): MOUSE_FILE
+ * display.c (displayBuffer): nTab -> nTab2, N_TAB -> nTabLine()
+ (redrawNLine): nTab -> nTab2, N_TAB -> nTabLine()
+ mouse_menu support
+ * fm.h (nTab2): added
+ (N_TAB): deleted
+ (NO_TABBUFFER): added
+ (struct _MouseMenu): added
+ (mouse_menu_map): added
+ (mouse_menu): added
+ * func.c (initMouseMenu): added
+ * main.c (main): initMouseMenu()
+ (posTab): mouse_menu support
+ (mouse_menu_action): added
+ (process_mouse): mouse_menu support
+ (reinit): initMouseMenu()
+ (nTabLine): added
+ (moveTab): check NO_TABBUFFER
+ * proto.h (nTabLine): added
+ (initMouseMenu): added
+ * rc.c (sync_with_option): initMouseMenu()
+
2002-11-22 Fumitoshi UKAI <ukai@debian.or.jp>
* NEWS: func: NEXT, PREV
diff --git a/configure b/configure
@@ -2420,6 +2420,7 @@ $def_use_xface
#define CONFIG_FILE "config"
#define KEYMAP_FILE "keymap"
#define MENU_FILE "menu"
+#define MOUSE_FILE "mouse"
#define COOKIE_FILE "cookie"
#define HISTORY_FILE "history"
diff --git a/display.c b/display.c
@@ -254,8 +254,8 @@ displayBuffer(Buffer *buf, int mode)
else
buf->rootX = 0;
buf->COLS = COLS - buf->rootX;
- if (nTab > 1) {
- ny = (nTab - 1) / N_TAB + 2;
+ if (nTab2 > 1) {
+ ny = (nTab2 - 1) / nTabLine() + 2;
if (ny > LASTLINE)
ny = LASTLINE;
}
@@ -445,12 +445,18 @@ redrawNLine(Buffer *buf, int n)
#endif /* USE_BG_COLOR */
}
#endif /* USE_COLOR */
- if (nTab > 1) {
+ if (nTab2 > 1) {
TabBuffer *t;
- int nx = N_TAB, col = COLS - 2, x, l;
+ int nx = nTabLine(), col = COLS - 2, x, l;
+ i = 0;
move(0, 0);
- for (t = FirstTab, i = 0; t; t = t->nextTab, i++) {
+ if (mouse_menu) {
+ addstr(mouse_menu);
+ clrtoeolx();
+ i++;
+ }
+ for (t = FirstTab; t; t = t->nextTab, i++) {
x = col * (i % nx) / nx;
move(i / nx, x);
if (t == CurrentTab)
@@ -474,7 +480,7 @@ redrawNLine(Buffer *buf, int n)
}
move(0, col);
addstr(" x");
- move((nTab - 1) / nx + 1, 0);
+ move((nTab2 - 1) / nx + 1, 0);
for (i = 0; i < COLS; i++)
addch('~');
}
diff --git a/fm.h b/fm.h
@@ -805,9 +805,9 @@ global int open_tab_blank init(FALSE);
global int open_tab_dl_list init(FALSE);
global int close_tab_back init(FALSE);
global int nTab;
+#define nTab2 (mouse_menu ? (nTab + 1) : nTab)
global int TabCols init(10);
-#define N_TAB ((COLS - 2 > TabCols * nTab) ? nTab \
- : (nTab - 1) / ((nTab * TabCols - 1) / (COLS - 2) + 1) + 1)
+#define NO_TABBUFFER ((TabBuffer *)1)
#define Currentbuf (CurrentTab->currentBuffer)
#define Firstbuf (CurrentTab->firstBuffer)
global DownloadList *FirstDL init(NULL);
@@ -991,7 +991,12 @@ global int reverse_mouse init(FALSE);
global int relative_wheel_scroll init(FALSE);
global int fixed_wheel_scroll_count init(5);
global int relative_wheel_scroll_ratio init(30);
+struct _MouseMenu {
+ void (*func) ();
+ char *data;
+} mouse_menu_map[3][10];
#endif /* USE_MOUSE */
+global char *mouse_menu init(NULL);
#ifdef USE_COOKIE
global int default_use_cookie init(TRUE);
diff --git a/func.c b/func.c
@@ -320,3 +320,68 @@ getQWord(char **str)
*str = p;
return tmp->ptr;
}
+
+#ifdef USE_MOUSE
+void
+initMouseMenu(void)
+{
+ FILE *mf;
+ Str line;
+ char *p, *s;
+ int f, b, x, x2;
+
+ mouse_menu = NULL;
+ for (b = 1; b <= 3; b++) {
+ for (x = 0; x < 10; x++) {
+ mouse_menu_map[b - 1][x].func = NULL;
+ mouse_menu_map[b - 1][x].data = NULL;
+ }
+ }
+ if ((mf = fopen(rcFile(MOUSE_FILE), "rt")) == NULL)
+ return;
+
+ while (!feof(mf)) {
+ line = Strfgets(mf);
+ Strchop(line);
+ Strremovefirstspaces(line);
+ if (line->length == 0)
+ continue;
+ p = line->ptr;
+ s = getWord(&p);
+ if (*s == '#') /* comment */
+ continue;
+ if (!strcmp(s, "menu")) {
+ s = getQWord(&p);
+ if (*s)
+ mouse_menu = Strnew_charp(s)->ptr;
+ continue;
+ }
+ if (strcmp(s, "button"))
+ continue; /* error */
+ s = getWord(&p);
+ b = atoi(s);
+ if (!(b >= 1 && b <= 3))
+ continue; /* error */
+ s = getWord(&p);
+ x = atoi(s);
+ if (!(IS_DIGIT(*s) && x >= 0 && x <= 9))
+ continue; /* error */
+ s = getWord(&p);
+ x2 = atoi(s);
+ if (!(IS_DIGIT(*s) && x2 >= 0 && x2 <= 9))
+ continue; /* error */
+ s = getWord(&p);
+ f = getFuncList(s);
+ if (f < 0)
+ continue; /* error */
+ s = getQWord(&p);
+ if (!*s)
+ s = NULL;
+ for (; x <= x2; x++) {
+ mouse_menu_map[b - 1][x].func = w3mFuncList[f].func;
+ mouse_menu_map[b - 1][x].data = s;
+ }
+ }
+ fclose(mf);
+}
+#endif
diff --git a/main.c b/main.c
@@ -746,6 +746,9 @@ main(int argc, char **argv, char **envp)
setupscreen();
#endif /* not SIGWINCH */
initKeymap(TRUE);
+#ifdef USE_MOUSE
+ initMouseMenu();
+#endif /* MOUSE */
#ifdef USE_MENU
initMenu();
#endif /* MENU */
@@ -4787,12 +4790,44 @@ posTab(int x, int y)
if (col <= 0)
return NULL;
- n = x * N_TAB / col + y * N_TAB;
- for (t = FirstTab, i = 0; t && i < n; t = t->nextTab, i++) ;
+ n = nTabLine();
+ n = x * n / col + y * n;
+ i = 0;
+ if (mouse_menu) {
+ if (n == 0)
+ return NO_TABBUFFER;
+ i++;
+ }
+ for (t = FirstTab; t && i < n; t = t->nextTab, i++) ;
return t;
}
static void
+mouse_menu_action(int btn, int x)
+{
+ switch (btn) {
+ case MOUSE_BTN1_DOWN:
+ btn = 0;
+ break;
+ case MOUSE_BTN2_DOWN:
+ btn = 1;
+ break;
+ case MOUSE_BTN3_DOWN:
+ btn = 2;
+ break;
+ default:
+ return;
+ }
+ if (x >= 0 && x <= 9 && mouse_menu_map[btn][x].func) {
+ CurrentKey = -1;
+ CurrentKeyData = NULL;
+ CurrentCmdData = mouse_menu_map[btn][x].data;
+ (*mouse_menu_map[btn][x].func) ();
+ CurrentCmdData = NULL;
+ }
+}
+
+static void
process_mouse(int btn, int x, int y)
{
int delta_x, delta_y, i;
@@ -4800,20 +4835,26 @@ process_mouse(int btn, int x, int y)
TabBuffer *t;
int ny = 0;
- if (nTab > 1)
- ny = (nTab - 1) / N_TAB + 1;
+ if (nTab2 > 1)
+ ny = (nTab2 - 1) / nTabLine() + 1;
if (btn == MOUSE_BTN_UP) {
switch (press_btn) {
case MOUSE_BTN1_DOWN:
- if (nTab > 1 && y < ny) {
+ if (nTab2 > 1 && y < ny) {
if (press_y == y && press_x == x) {
if (y == 0 && x >= COLS - 2) {
deleteTab(CurrentTab);
- displayBuffer(Currentbuf, B_NORMAL);
+ displayBuffer(Currentbuf, B_FORCE_REDRAW);
+ return;
}
t = posTab(x, y);
- if (t)
- CurrentTab = t;
+ if (t == NULL)
+ return;
+ if (t == NO_TABBUFFER) {
+ mouse_menu_action(press_btn, x);
+ return;
+ }
+ CurrentTab = t;
displayBuffer(Currentbuf, B_FORCE_REDRAW);
return;
}
@@ -4829,6 +4870,8 @@ process_mouse(int btn, int x, int y)
t = posTab(x, y);
if (t == NULL)
return;
+ if (t == NO_TABBUFFER)
+ t = NULL; /* open new tab */
cursorXY(Currentbuf, press_x - Currentbuf->rootX,
press_y - Currentbuf->rootY);
if (Currentbuf->cursorY == press_y - Currentbuf->rootY &&
@@ -4915,9 +4958,13 @@ process_mouse(int btn, int x, int y)
}
break;
case MOUSE_BTN2_DOWN:
- if (nTab > 1 && y < ny) {
+ if (nTab2 > 1 && y < ny) {
if (press_y == y && press_x == x) {
t = posTab(x, y);
+ if (t == NO_TABBUFFER) {
+ mouse_menu_action(press_btn, x);
+ return;
+ }
if (t) {
deleteTab(t);
displayBuffer(Currentbuf, B_FORCE_REDRAW);
@@ -4928,6 +4975,15 @@ process_mouse(int btn, int x, int y)
backBf();
break;
case MOUSE_BTN3_DOWN:
+ if (nTab2 > 1 && y < ny) {
+ if (press_y == y && press_x == x) {
+ t = posTab(x, y);
+ if (t == NO_TABBUFFER) {
+ mouse_menu_action(press_btn, x);
+ return;
+ }
+ }
+ }
#ifdef USE_MENU
if (x >= Currentbuf->rootX && y > ny)
cursorXY(Currentbuf, x - Currentbuf->rootX,
@@ -5438,6 +5494,9 @@ reinit()
initCookie();
#endif
initKeymap(TRUE);
+#ifdef USE_MOUSE
+ initMouseMenu();
+#endif
#ifdef USE_MENU
initMenu();
#endif
@@ -5467,6 +5526,13 @@ reinit()
return;
}
+#ifdef USE_MOUSE
+ if (!strcasecmp(resource, "MOUSE_MENU")) {
+ initMouseMenu();
+ return;
+ }
+#endif
+
#ifdef USE_MENU
if (!strcasecmp(resource, "MENU")) {
initMenu();
@@ -5559,6 +5625,19 @@ newT(void)
displayBuffer(Currentbuf, B_REDRAW_IMAGE);
}
+int
+nTabLine(void)
+{
+ int n = nTab2;
+
+ if (COLS - 2 > TabCols * n)
+ return n;
+ n = (n - 1) / ((n * TabCols - 1) / (COLS - 2) + 1) + 1;
+ if (n > (COLS - 2) / TabCols)
+ n = (COLS - 2) / TabCols;
+ return n ? n : 1;
+}
+
TabBuffer *
numTab(int n)
{
@@ -5763,7 +5842,9 @@ tabrURL(void)
void
moveTab(TabBuffer * t, TabBuffer * t2, int right)
{
- if (!t || !t2 || t == t2)
+ if (t2 == NO_TABBUFFER)
+ t2 = FirstTab;
+ if (!t || !t2 || t == t2 || t == NO_TABBUFFER)
return;
if (t->prevTab) {
if (t->nextTab)
diff --git a/proto.h b/proto.h
@@ -225,6 +225,7 @@ extern char *inputAnswer(char *prompt);
extern int matchattr(char *p, char *attr, int len, Str *value);
extern void readHeader(URLFile *uf, Buffer *newBuf, int thru, ParsedURL *pu);
extern char *checkHeader(Buffer *buf, char *field);
+extern int nTabLine(void);
extern TabBuffer *newTab(void);
extern TabBuffer *deleteTab(TabBuffer *tab);
extern void addDownloadList(pid_t pid, char *url, char *save, char *lock,
@@ -626,6 +627,9 @@ extern int getKey(char *s);
extern char *getKeyData(int key);
extern char *getWord(char **str);
extern char *getQWord(char **str);
+#ifdef USE_MOUSE
+extern void initMouseMenu(void);
+#endif
#ifdef USE_MENU
extern void new_menu(Menu *menu, MenuItem *item);
diff --git a/rc.c b/rc.c
@@ -1322,6 +1322,9 @@ sync_with_option(void)
AcceptMedia = acceptableMimeTypes();
if (fmInitialized) {
initKeymap(FALSE);
+#ifdef USE_MOUSE
+ initMouseMenu();
+#endif /* MOUSE */
#ifdef USE_MENU
initMenu();
#endif /* MENU */