commit 1441eb26e6533659a0a46623c347323aac8c2a19
parent a769c86f6e1c6edbf6d69829cb4d19cbed7fd8fa
Author: ukai <ukai>
Date: Thu, 21 Nov 2002 17:05:00 +0000
[w3m-dev 03456] tiling of tab
* display.c (displayBuffer): use LastTab->y
(redrawNLine): fix column calculation
* fm.h (TabBuffer): add x1, x2, y
* main.c (calcTabPos): added
(main): calcTabPos()
(mouse_scroll_line): rewrite
(process_mouse): use LastTab->y
(_newT): calcTabPos()
(calcTabPos): added
(deleteTab): calcTabPos()
(moveTab): calcTabPos()
From: Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
Diffstat:
M | ChangeLog | | | 15 | +++++++++++++++ |
M | display.c | | | 21 | ++++++++++----------- |
M | fm.h | | | 3 | +++ |
M | main.c | | | 81 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------- |
4 files changed, 92 insertions(+), 28 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,3 +1,18 @@
+2002-11-22 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
+
+ * [w3m-dev 03456] tiling of tab
+ * display.c (displayBuffer): use LastTab->y
+ (redrawNLine): fix column calculation
+ * fm.h (TabBuffer): add x1, x2, y
+ * main.c (calcTabPos): added
+ (main): calcTabPos()
+ (mouse_scroll_line): rewrite
+ (process_mouse): use LastTab->y
+ (_newT): calcTabPos()
+ (calcTabPos): added
+ (deleteTab): calcTabPos()
+ (moveTab): calcTabPos()
+
2002-11-22 Fumitoshi UKAI <ukai@debian.or.jp>
* doc/README.mouse_menu: added
diff --git a/display.c b/display.c
@@ -255,7 +255,7 @@ displayBuffer(Buffer *buf, int mode)
buf->rootX = 0;
buf->COLS = COLS - buf->rootX;
if (nTab2 > 1) {
- ny = (nTab2 - 1) / nTabLine() + 2;
+ ny = LastTab->y + 2;
if (ny > LASTLINE)
ny = LASTLINE;
}
@@ -447,7 +447,7 @@ redrawNLine(Buffer *buf, int n)
#endif /* USE_COLOR */
if (nTab2 > 1) {
TabBuffer *t;
- int nx = nTabLine(), col = COLS - 2, x, l;
+ int l;
i = 0;
move(0, 0);
@@ -456,31 +456,30 @@ redrawNLine(Buffer *buf, int n)
clrtoeolx();
i++;
}
- for (t = FirstTab; t; t = t->nextTab, i++) {
- x = col * (i % nx) / nx;
- move(i / nx, x);
+ clrtoeolx();
+ for (t = FirstTab; t; t = t->nextTab) {
+ move(t->y, t->x1);
if (t == CurrentTab)
bold();
addch('[');
l = strlen(t->currentBuffer->buffername);
- if (col / nx - 2 > l)
- addnstr_sup(" ", (col / nx - 2 - l) / 2);
+ if (t->x2 - t->x1 - 2 > l)
+ addnstr_sup(" ", (t->x2 - t->x1 - 1 - l) / 2);
if (t == CurrentTab)
EFFECT_ACTIVE_START;
addstr(t->currentBuffer->buffername);
if (t == CurrentTab)
EFFECT_ACTIVE_END;
clrtoeolx();
- x = col * (i % nx + 1) / nx - 1;
- move(i / nx, x);
+ move(t->y, t->x2);
addch(']');
if (t == CurrentTab)
boldend();
clrtoeolx();
}
- move(0, col);
+ move(0, COLS - 2);
addstr(" x");
- move((nTab2 - 1) / nx + 1, 0);
+ move(LastTab->y + 1, 0);
for (i = 0; i < COLS; i++)
addch('~');
}
diff --git a/fm.h b/fm.h
@@ -452,6 +452,9 @@ typedef struct _TabBuffer {
struct _TabBuffer *prevTab;
Buffer *currentBuffer;
Buffer *firstBuffer;
+ short x1;
+ short x2;
+ short y;
} TabBuffer;
typedef struct _DownloadList {
diff --git a/main.c b/main.c
@@ -101,6 +101,7 @@ void set_buffer_environ(Buffer *);
static void _followForm(int);
static void _goLine(char *);
static void _newT(void);
+static void calcTabPos(void);
static void followTab(TabBuffer * tab);
static void moveTab(TabBuffer * t, TabBuffer * t2, int right);
static int check_target = TRUE;
@@ -895,6 +896,7 @@ main(int argc, char **argv, char **envp)
if (CurrentTab == NULL) {
FirstTab = LastTab = CurrentTab = newTab();
nTab = 1;
+ calcTabPos();
Firstbuf = Currentbuf = newbuf;
}
else {
@@ -935,6 +937,7 @@ main(int argc, char **argv, char **envp)
if (!FirstTab) {
FirstTab = LastTab = CurrentTab = newTab();
nTab = 1;
+ calcTabPos();
}
if (!Firstbuf || Firstbuf == NO_BUFFER) {
Firstbuf = Currentbuf = newBuffer(INIT_BUFFER_WIDTH);
@@ -4785,21 +4788,13 @@ mouse_scroll_line(void)
static TabBuffer *
posTab(int x, int y)
{
- TabBuffer *t;
- int i, n, col = COLS - 2;
-
- if (col <= 0)
- return NULL;
- n = nTabLine();
- n = x * n / col + y * n;
- i = 0;
- if (mouse_menu) {
- if (n == 0)
- return NO_TABBUFFER;
- i++;
+ TabBuffer *tab;
+
+ for (tab = FirstTab; tab; tab = tab->nextTab) {
+ if (tab->x1 <= x && x <= tab->x2 && tab->y == y)
+ return tab;
}
- for (t = FirstTab; t && i < n; t = t->nextTab, i++) ;
- return t;
+ return NULL;
}
static void
@@ -4836,11 +4831,11 @@ process_mouse(int btn, int x, int y)
int ny = 0;
if (nTab2 > 1)
- ny = (nTab2 - 1) / nTabLine() + 1;
+ ny = LastTab->y + 1;
if (btn == MOUSE_BTN_UP) {
switch (press_btn) {
case MOUSE_BTN1_DOWN:
- if (nTab2 > 1 && y < ny) {
+ if (ny && y < ny) {
if (press_y == y && press_x == x) {
if (y == 0 && x >= COLS - 2) {
deleteTab(CurrentTab);
@@ -4958,7 +4953,7 @@ process_mouse(int btn, int x, int y)
}
break;
case MOUSE_BTN2_DOWN:
- if (nTab2 > 1 && y < ny) {
+ if (ny && y < ny) {
if (press_y == y && press_x == x) {
t = posTab(x, y);
if (t == NO_TABBUFFER) {
@@ -5616,6 +5611,7 @@ _newT(void)
CurrentTab->nextTab = tag;
CurrentTab = tag;
nTab++;
+ calcTabPos();
}
void
@@ -5654,6 +5650,55 @@ numTab(int n)
return tab;
}
+static void
+calcTabPos(void)
+{
+ TabBuffer *tab;
+ int lcol = 0, rcol = 2, col;
+ int n1, n2, na, nx, ny, ix, iy;
+
+ if (nTab <= 0)
+ return;
+ n1 = (COLS - rcol - lcol) / TabCols;
+ if (n1 >= nTab) {
+ n2 = 1;
+ ny = 1;
+ }
+ else {
+ if (n1 < 0)
+ n1 = 0;
+ n2 = COLS / TabCols;
+ if (n2 == 0)
+ n2 = 1;
+ ny = (nTab - n1 - 1) / n2 + 2;
+ }
+ na = n1 + n2 * (ny - 1);
+ n1 -= (na - nTab) / ny;
+ if (n1 < 0)
+ n1 = 0;
+ na = n1 + n2 * (ny - 1);
+ tab = FirstTab;
+ for (iy = 0; iy < ny && tab; iy++) {
+ if (iy == 0) {
+ nx = n1;
+ col = COLS - rcol - lcol;
+ }
+ else {
+ nx = n2 - (na - nTab + (iy - 1)) / (ny - 1);
+ col = COLS;
+ }
+ for (ix = 0; ix < nx && tab; ix++, tab = tab->nextTab) {
+ tab->x1 = col * ix / nx;
+ tab->x2 = col * (ix + 1) / nx - 1;
+ tab->y = iy;
+ if (iy == 0) {
+ tab->x1 += lcol;
+ tab->x2 += lcol;
+ }
+ }
+ }
+}
+
TabBuffer *
deleteTab(TabBuffer * tab)
{
@@ -5677,6 +5722,7 @@ deleteTab(TabBuffer * tab)
CurrentTab = tab->nextTab;
}
nTab--;
+ calcTabPos();
buf = tab->firstBuffer;
while (buf && buf != NO_BUFFER) {
next = buf->nextBuffer;
@@ -5875,6 +5921,7 @@ moveTab(TabBuffer * t, TabBuffer * t2, int right)
FirstTab = t;
t2->prevTab = t;
}
+ calcTabPos();
displayBuffer(Currentbuf, B_FORCE_REDRAW);
}