[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
lynx-dev [PATCH 2.8.4dev.19] table line wrap
From: |
Ilya Zakharevich |
Subject: |
lynx-dev [PATCH 2.8.4dev.19] table line wrap |
Date: |
Sat, 17 Mar 2001 21:37:36 -0500 |
User-agent: |
Mutt/1.2.5i |
This patch removes approx. 1/4 of gotchas with LYshiftWin (at least
the scrollbar shows again...).
It also removes a bogus dependency between wide-screen display and
line wrapping outside tables. For this, I needed to replace LYcols
inside GridText.c by one of 3 choices: LYcols, DISPLAY_COLS, and
WRAP_COLS. This auto-magically enables half-intelligent line wrapping
inside tables: all one needs to change is the macro for WRAP_COLS.
Keep in mind that LYcols_cu is unpenetrable to me, so I mostly left
the logic to calculate it as it was.
If your Lynx is menu-capable (but my #ifdefs may be a little bit too
restrictive), you get 5 additional choices for the strategy of
line-wrapping inside tables: in addition to no-line-wraps (as in
dev.19), you can line wrap at the screen width, 3/4, 2/3, 1/2, 1/3 and
1/4.
There is a gotcha with line-wrapping inside tables: it works
as-I-expect-it only on *new lines* inside cells. For the cells which
are on the same line as the previous cell, you get bogus line breaks.
This should be easy to fix, but I want to separate straightforward
stuff (such as this patch) from the half-intelligent stuff.
Enjoy,
Ilya
--- ./src/GridText.c-pre Sat Mar 17 02:02:18 2001
+++ ./src/GridText.c Sat Mar 17 20:57:38 2001
@@ -61,6 +61,18 @@ unsigned int cached_styles[CACHEH][CACHE
#include <LYJustify.h>
+#ifdef USE_CURSES_PADS
+# define DISPLAY_COLS (LYwideLines ? MAX_COLS : LYcols)
+# define WRAP_COLS(text) ((text)->stbl ? \
+ (LYtableCols <= 0 \
+ ? DISPLAY_COLS : LYtableCols * LYcols/12) \
+ : LYcols)
+#else
+# define DISPLAY_COLS LYcols
+# define WRAP_COLS(text) LYcols
+#endif
+
+
#ifdef USE_COLOR_STYLE_UNUSED
void LynxClearScreenCache NOARGS
{
@@ -771,7 +783,7 @@ PUBLIC HText * HText_new ARGS1(
self->old_dtd = Old_DTD;
self->keypad_mode = keypad_mode;
self->disp_lines = LYlines;
- self->disp_cols = LYcols;
+ self->disp_cols = DISPLAY_COLS;
#endif
/*
* If we are going to render the List Page, always merge in hidden
@@ -1104,8 +1116,8 @@ PRIVATE int display_line ARGS4(
* go over the COLS limit on the display.
*/
j = (int)line->offset;
- if (j > (int)LYcols - 1)
- j = (int)LYcols - 1;
+ if (j > (int)DISPLAY_COLS - 1)
+ j = (int)DISPLAY_COLS - 1;
#ifdef USE_SLANG
SLsmg_forward (j);
i = j;
@@ -1146,7 +1158,7 @@ PRIVATE int display_line ARGS4(
&HitOffset,
&LenNeeded);
if (cp_tgt) {
- if (((int)line->offset + LenNeeded) >= LYcols) {
+ if (((int)line->offset + LenNeeded) >= DISPLAY_COLS) {
cp_tgt = NULL;
} else {
text->page_has_target = YES;
@@ -1160,7 +1172,7 @@ PRIVATE int display_line ARGS4(
#endif /* SHOW_WHEREIS_TARGETS */
#endif /* USE_COLOR_STYLE */
- while ((i < LYcols) && ((buffer[0] = *data) != '\0')) {
+ while ((i < DISPLAY_COLS) && ((buffer[0] = *data) != '\0')) {
#ifndef USE_COLOR_STYLE
#if defined(SHOW_WHEREIS_TARGETS)
@@ -1346,7 +1358,7 @@ PRIVATE int display_line ARGS4(
/*
* For CJK strings, by Masanobu Kimura.
*/
- if (i >= LYcols) goto after_while;
+ if (i >= DISPLAY_COLS) goto after_while;
buffer[1] = *data;
buffer[2] = '\0';
@@ -1646,7 +1658,7 @@ PRIVATE void display_scrollbar ARGS1(
LynxChangeStyle(s, ABS_ON);
}
#endif /* USE_COLOR_STYLE */
- LYmove(1, LYcols - 1);
+ LYmove(1, LYcols + LYshiftWin - 1);
addch_raw(ACS_UARROW);
#ifdef USE_COLOR_STYLE
LynxChangeStyle(s, STACK_OFF);
@@ -1667,7 +1679,7 @@ PRIVATE void display_scrollbar ARGS1(
if (i-1 <= h - bot_skip && i > h - bot_skip)
LynxChangeStyle(s_sb_bar, STACK_OFF);
#endif /* USE_COLOR_STYLE */
- LYmove(i + off, LYcols - 1);
+ LYmove(i + off, LYcols + LYshiftWin - 1);
if (i > top_skip && i <= h - bot_skip)
LYaddch(ACS_BLOCK);
else
@@ -1687,7 +1699,7 @@ PRIVATE void display_scrollbar ARGS1(
LynxChangeStyle(s, ABS_ON);
}
#endif /* USE_COLOR_STYLE */
- LYmove(h + 2, LYcols - 1);
+ LYmove(h + 2, LYcols + LYshiftWin - 1);
addch_raw(ACS_DARROW);
#ifdef USE_COLOR_STYLE
LynxChangeStyle(s, STACK_OFF);
@@ -1928,7 +1940,7 @@ PRIVATE void display_page ARGS3(
text->T.output_utf8, YES,
NULL,
&LenNeeded)) != NULL) &&
- ((int)line->offset + LenNeeded) < LYcols) {
+ ((int)line->offset + LenNeeded) < DISPLAY_COLS) {
int itmp = 0;
int written = 0;
int x_pos = offset + (int)(cp - data);
@@ -2318,7 +2330,7 @@ PUBLIC void HText_beginAppend ARGS1(
#ifdef USE_SLANG
#define LYcols_cu (dump_output_immediately ? MAX_COLS : SLtt_Screen_Cols)
#else
-#define LYcols_cu (dump_output_immediately ? MAX_COLS : LYcols)
+#define LYcols_cu (dump_output_immediately ? MAX_COLS : DISPLAY_COLS)
#endif
/* Add a new line of text
@@ -2929,9 +2941,11 @@ PRIVATE void split_line ARGS2(
ctrl_chars_on_previous_line--;
/* @@ first line indent */
- spare = (LYcols-1) -
+ spare = (WRAP_COLS(text)-1) -
(int)style->rightIndent - indent +
ctrl_chars_on_previous_line - previous->size;
+ if (spare < 0 && LYwideLines) /* Can be wider than screen */
+ spare = 0;
if (spare > 0 && !dump_output_immediately &&
text->T.output_utf8 && ctrl_chars_on_previous_line) {
@@ -3096,7 +3110,7 @@ PRIVATE void split_line ARGS2(
&& justify_max_void_percent > 0
&& justify_max_void_percent <= 100
&& justify_max_void_percent >= ((100*spare)
- / ((LYcols - 1)
+ / ((WRAP_COLS(text) - 1)
- (int)style->rightIndent
- indent
+ ctrl_chars_on_previous_line))) {
@@ -3991,7 +4005,7 @@ PUBLIC void HText_appendCharacter ARGS2(
else
target_cu = target + (here_cu - here);
- if (target > (LYcols-1) - (int)style->rightIndent &&
+ if (target > (WRAP_COLS(text)-1) - (int)style->rightIndent &&
HTOutputFormat != WWW_SOURCE) {
new_line(text);
} else {
@@ -3999,8 +4013,8 @@ PUBLIC void HText_appendCharacter ARGS2(
* Can split here. - FM
*/
text->permissible_split = line->size;
- if (target_cu > (LYcols-1))
- target -= target_cu - (LYcols-1);
+ if (target_cu > (WRAP_COLS(text)-1))
+ target -= target_cu - (WRAP_COLS(text)-1);
if (line->size == 0) {
line->offset = line->offset + target - here;
} else {
@@ -4022,7 +4036,7 @@ check_WrapSource:
*/
int target = (int)(line->offset + line->size) - ctrl_chars_on_this_line;
int target_cu = target + utfxtra_on_this_line;
- if (target >= (LYcols-1) - style->rightIndent -
+ if (target >= (WRAP_COLS(text)-1) - style->rightIndent -
(((HTCJK != NOCJK) && text->kanji_buf) ? 1 : 0) ||
(text->T.output_utf8 &&
target_cu + UTF_XLEN(ch) >= (LYcols_cu-1))
@@ -4061,7 +4075,7 @@ check_WrapSource:
*/
if (text->IgnoreExcess &&
(((indent + (int)line->offset + (int)line->size) +
- (int)style->rightIndent - ctrl_chars_on_this_line) >= (LYcols-1) ||
+ (int)style->rightIndent - ctrl_chars_on_this_line) >=
(WRAP_COLS(text)-1) ||
((indent + (int)line->offset + (int)line->size) +
utfxtra_on_this_line - ctrl_chars_on_this_line) >= (LYcols_cu-1)))
return;
@@ -4075,7 +4089,7 @@ check_WrapSource:
((line->size > 0) &&
(int)(line->data[line->size-1] ==
LY_SOFT_HYPHEN ?
- 1 : 0))) >= (LYcols - 1) ||
+ 1 : 0))) >= (WRAP_COLS(text) - 1)
||
(text->T.output_utf8 &&
(((indent + (int)line->offset + (int)line->size) +
utfxtra_on_this_line - ctrl_chars_on_this_line +
@@ -4119,7 +4133,7 @@ check_WrapSource:
}
} else if ((int)line->size >= (int)(MAX_LINE-1)) {
/*
- * Never overrun memory if LYcols is set to a large value - KW
+ * Never overrun memory if DISPLAY_COLS is set to a large value - KW
*/
new_line(text);
}
@@ -4568,7 +4582,7 @@ PRIVATE int HText_insertBlanksInStblLine
alignment = style->alignment;
indent = style->leftIndent;
/* Calculate spare character positions */
- spare = (LYcols-1) -
+ spare = (WRAP_COLS(me)-1) -
(int)style->rightIndent - indent - max_width;
if (spare < 0 && (int)style->rightIndent + spare >= 0) {
/*
@@ -6473,7 +6487,7 @@ PUBLIC BOOL HText_getFirstTargetInLine A
utf_flag, YES,
&HitOffset,
&LenNeeded)) != NULL) &&
- (LineOffset + LenNeeded) < LYcols) {
+ (LineOffset + LenNeeded) < DISPLAY_COLS) {
/*
* We had a hit so load the results,
* remove IsSpecial characters from
@@ -8267,10 +8281,10 @@ PUBLIC BOOLEAN HTdocument_settings_chang
trace_setting_change("OLD_DTD", HTMainText->old_dtd, Old_DTD);
trace_setting_change("KEYPAD_MODE",
HTMainText->keypad_mode, keypad_mode);
- if (HTMainText->disp_lines != LYlines || HTMainText->disp_cols !=
LYcols)
+ if (HTMainText->disp_lines != LYlines || HTMainText->disp_cols !=
DISPLAY_COLS)
CTRACE((tfp,
"HTdocument_settings_changed: Screen size has changed (was
%dx%d, now %dx%d)\n",
- HTMainText->disp_cols, HTMainText->disp_lines, LYcols,
LYlines));
+ HTMainText->disp_cols, HTMainText->disp_lines, DISPLAY_COLS,
LYlines));
}
return (HTMainText->clickable_images != clickable_images ||
@@ -8283,7 +8297,7 @@ PUBLIC BOOLEAN HTdocument_settings_chang
HTMainText->soft_dquotes != soft_dquotes ||
HTMainText->old_dtd != Old_DTD ||
HTMainText->keypad_mode != keypad_mode ||
- HTMainText->disp_cols != LYcols);
+ HTMainText->disp_cols != DISPLAY_COLS);
}
#endif
@@ -8516,10 +8530,10 @@ PUBLIC int HText_getCurrentColumn ARGS1(
PUBLIC int HText_getMaximumColumn ARGS1(
HText *, text)
{
- int column = (LYcols-2);
+ int column = (DISPLAY_COLS-2);
if (text) {
- column = ((int)text->style->rightIndent ? (LYcols-2) :
- ((LYcols-1) - (int)text->style->rightIndent));
+ column = ((int)text->style->rightIndent ? (DISPLAY_COLS-2) :
+ ((DISPLAY_COLS-1) - (int)text->style->rightIndent));
}
return column;
}
@@ -9632,7 +9646,7 @@ PUBLIC int HText_beginInput ARGS3(
* text entry lines can be long, and will be scrolled
* horizontally within the editing window. - FM
*/
- MaximumSize = (LYcols - 1) -
+ MaximumSize = (WRAP_COLS(text) - 1) -
(int)text->style->leftIndent -
(int)text->style->rightIndent;
@@ -9662,8 +9676,8 @@ PUBLIC int HText_beginInput ARGS3(
* are types with small placeholders, and/or are a
* type which is handled via a popup window. - FM
*/
- if (f->size > LYcols-10)
- f->size = LYcols-10; /* maximum */
+ if (f->size > WRAP_COLS(text)-10)
+ f->size = WRAP_COLS(text)-10; /* maximum */
break;
}
@@ -13075,8 +13089,8 @@ PRIVATE void move_to_glyph ARGS10(
* go over the COLS limit on the display.
*/
i = (int)offset;
- if (i > (int)LYcols - 1)
- i = (int)LYcols - 1;
+ if (i > (int)DISPLAY_COLS - 1)
+ i = (int)DISPLAY_COLS - 1;
linkvlen = hightext ? LYmbcsstrlen(hightext, utf_flag, YES) : 0;
@@ -13107,7 +13121,7 @@ PRIVATE void move_to_glyph ARGS10(
&HitOffset,
&LenNeeded);
if (cp_tgt) {
- if ((int)offset + LenNeeded >= LYcols ||
+ if ((int)offset + LenNeeded >= DISPLAY_COLS ||
((int)offset + HitOffset >= XP + linkvlen)) {
cp_tgt = NULL;
} else {
@@ -13128,7 +13142,7 @@ PRIVATE void move_to_glyph ARGS10(
* XP_draw_min) is found, or when we reach the link itself (if
* highlight is non-NULL). - kw
*/
- while ((i < LYcols - 1) && data < end_of_data && (*data != '\0')) {
+ while ((i < DISPLAY_COLS - 1) && data < end_of_data && (*data != '\0')) {
if (data && hightext && i >= XP && !incurlink) {
@@ -13474,7 +13488,7 @@ PRIVATE void move_to_glyph ARGS10(
/*
* For CJK strings, by Masanobu Kimura.
*/
- if (drawing && (i < LYcols - 1)) {
+ if (drawing && (i < DISPLAY_COLS - 1)) {
buffer[1] = *data;
LYaddstr(buffer);
buffer[1] = '\0';
--- ./src/LYCurses.c-pre Fri Mar 9 01:55:38 2001
+++ ./src/LYCurses.c Sat Mar 17 20:58:22 2001
@@ -50,7 +50,8 @@ char *XCursesProgramName = "Lynx";
#ifdef USE_CURSES_PADS
WINDOW *LYwin = 0;
int LYshiftWin = 0;
-int LYlineWrap = TRUE;
+int LYwideLines = FALSE;
+int LYtableCols = 0; /* in 1/12 of screen width */
#endif
/*
@@ -946,7 +947,7 @@ PUBLIC void start_curses NOARGS
#ifdef USE_CURSES_PADS
LYwin = newpad(LYlines, MAX_COLS);
LYshiftWin = 0;
- LYlineWrap = TRUE;
+ LYwideLines = FALSE;
#endif
#if defined(USE_KEYMAPS) && defined(NCURSES_VERSION)
--- ./src/LYCurses.h-pre Fri Mar 9 01:07:48 2001
+++ ./src/LYCurses.h Sat Mar 17 20:58:32 2001
@@ -269,9 +269,13 @@ extern int LYcols; /* replaces COLS */
#ifdef USE_CURSES_PADS
extern WINDOW *LYwin;
extern int LYshiftWin;
-extern int LYlineWrap;
+extern int LYwideLines;
+extern int LYtableCols;
#else
#define LYwin stdscr
+#define LYshiftWin 0
+#define LYwideLines 0
+#define LYtableCols 0
#endif
#if defined(USE_COLOR_TABLE) || defined(USE_SLANG)
--- ./src/LYMainLoop.c-pre Thu Mar 8 21:40:12 2001
+++ ./src/LYMainLoop.c Sat Mar 17 21:13:08 2001
@@ -5152,39 +5152,77 @@ PUBLIC void handle_LYK_CHDIR NOARGS
#ifdef USE_CURSES_PADS
PRIVATE void handle_LYK_SHIFT_LEFT ARGS1(BOOLEAN *, flag)
{
- if (LYlineWrap) {
+ if (!LYwideLines) {
HTAlert(SHIFT_VS_LINEWRAP);
- } else {
- if (LYshiftWin > 0) {
- LYshiftWin--;
- *flag = TRUE;
- }
+ return;
+ }
+ if (LYshiftWin > 0) {
+ LYshiftWin--;
+ *flag = TRUE;
}
}
PRIVATE void handle_LYK_SHIFT_RIGHT ARGS1(BOOLEAN *, flag)
{
- if (LYlineWrap) {
+ if (!LYwideLines) {
HTAlert(SHIFT_VS_LINEWRAP);
- } else {
- LYshiftWin++;
- *flag = TRUE;
+ return;
}
+ LYshiftWin++;
+ *flag = TRUE;
}
PRIVATE BOOLEAN handle_LYK_LINEWRAP_TOGGLE ARGS2(
int *, cmd,
BOOLEAN *, flag)
{
- LYlineWrap = !LYlineWrap;
- if (LYlineWrap != 0) {
- LYcols = LYscreenWidth();
+#if defined(USE_MOUSE) && (defined(NCURSES) || defined(PDCURSES))
+ static char *choices[] = {
+ "Try to fit screen width",
+ "No line wrap in columns",
+ "Wrap columns at screen width",
+ "Wrap columns at 3/4 screen width",
+ "Wrap columns at 2/3 screen width",
+ "Wrap columns at 1/2 screen width",
+ "Wrap columns at 1/3 screen width",
+ "Wrap columns at 1/4 screen width",
+ NULL
+ };
+ static int wrap[] = {
+ 0,
+ 0,
+ 12, /* In units of 1/12 */
+ 9,
+ 8,
+ 6,
+ 4,
+ 3
+ };
+ int c;
+
+ /* Somehow the mouse is over the number instead of being over the
+ name, so we decrease x. */
+ c = LYChoosePopup(!LYwideLines, LYlines /2 - 2, LYcols/2-6,
+ choices, TABLESIZE(choices) - 1, FALSE, TRUE);
+ /*
+ * LYhandlePopupList() wasn't really meant to be used
+ * outside of old-style Options menu processing. One result of
+ * mis-using it here is that we have to deal with side-effects
+ * regarding SIGINT signal handler and the term_options global
+ * variable. - kw
+ */
+ if (term_options)
+ return;
+ LYwideLines = c;
+ LYtableCols = wrap[c];
+#else
+ LYwideLines = !LYwideLines;
+#endif /* USE_MOUSE && (NCURSES || PDCURSES) */
+
+ if (LYwideLines == 0)
LYshiftWin = 0;
- } else {
- LYcols = MAX_COLS;
- }
*flag = TRUE;
- HTUserMsg(LYlineWrap ? LINEWRAP_ON : LINEWRAP_OFF);
+ HTUserMsg(LYwideLines ? LINEWRAP_OFF : LINEWRAP_ON);
return reparse_or_reload(cmd);
}
#endif
--- ./src/TRSTable.c-pre Sat Mar 17 02:27:12 2001
+++ ./src/TRSTable.c Sat Mar 17 20:09:10 2001
@@ -10,6 +10,7 @@
#include <HTStyle.h> /* for HT_LEFT, HT_CENTER, HT_RIGHT */
#include <LYCurses.h>
#include <TRSTable.h>
+#include <LYGlobalDefs.h>
#include <LYLeaks.h>
@@ -21,7 +22,11 @@
#define ROWS_GROWBY 2
#endif
-#define MAX_STBL_POS (LYcols-1)
+#ifdef USE_CURSES_PADS
+# define MAX_STBL_POS (LYwideLines ? MAX_COLS - 1 : LYcols-1)
+#else
+# define MAX_STBL_POS (LYcols-1)
+#endif
/* must be different from HT_ALIGN_NONE and HT_LEFT, HT_CENTER etc.: */
#define RESERVEDCELL (-2) /* cell's alignment field is overloaded, this
; To UNSUBSCRIBE: Send "unsubscribe lynx-dev" to address@hidden
- lynx-dev [PATCH 2.8.4dev.19] table line wrap,
Ilya Zakharevich <=