fl_help_view.cxx
来自「SRI international 发布的OAA框架软件」· CXX 代码 · 共 2,703 行 · 第 1/5 页
CXX
2,703 行
fsize = textsize_;
pre = 1;
}
if (strcasecmp(buf, "LI") == 0)
{
fl_font(FL_SYMBOL, fsize);
fl_draw("\267", xx - fsize + x() - leftline_, yy + y());
}
pushfont(font, fsize);
}
else if (strcasecmp(buf, "A") == 0 &&
get_attr(attrs, "HREF", attr, sizeof(attr)) != NULL)
fl_color(linkcolor_);
else if (strcasecmp(buf, "/A") == 0)
fl_color(textcolor_);
else if (strcasecmp(buf, "B") == 0 ||
strcasecmp(buf, "STRONG") == 0)
pushfont(font |= FL_BOLD, fsize);
else if (strcasecmp(buf, "TD") == 0 ||
strcasecmp(buf, "TH") == 0)
{
int tx, ty, tw, th;
if (tolower(buf[1]) == 'h')
pushfont(font |= FL_BOLD, fsize);
else
pushfont(font = textfont_, fsize);
tx = block->x - 4 - leftline_;
ty = block->y - topline_ - fsize - 3;
tw = block->w - block->x + 7;
th = block->h + fsize - 5;
if (tx < 0)
{
tw += tx;
tx = 0;
}
if (ty < 0)
{
th += ty;
ty = 0;
}
tx += x();
ty += y();
if (block->bgcolor != bgcolor_)
{
fl_color(block->bgcolor);
fl_rectf(tx, ty, tw, th);
fl_color(textcolor_);
}
if (block->border)
fl_rect(tx, ty, tw, th);
}
else if (strcasecmp(buf, "I") == 0 ||
strcasecmp(buf, "EM") == 0)
pushfont(font |= FL_ITALIC, fsize);
else if (strcasecmp(buf, "CODE") == 0 ||
strcasecmp(buf, "TT") == 0)
pushfont(font = FL_COURIER, fsize);
else if (strcasecmp(buf, "KBD") == 0)
pushfont(font = FL_COURIER_BOLD, fsize);
else if (strcasecmp(buf, "VAR") == 0)
pushfont(font = FL_COURIER_ITALIC, fsize);
else if (strcasecmp(buf, "/HEAD") == 0)
head = 0;
else if (strcasecmp(buf, "/H1") == 0 ||
strcasecmp(buf, "/H2") == 0 ||
strcasecmp(buf, "/H3") == 0 ||
strcasecmp(buf, "/H4") == 0 ||
strcasecmp(buf, "/H5") == 0 ||
strcasecmp(buf, "/H6") == 0 ||
strcasecmp(buf, "/B") == 0 ||
strcasecmp(buf, "/STRONG") == 0 ||
strcasecmp(buf, "/I") == 0 ||
strcasecmp(buf, "/EM") == 0 ||
strcasecmp(buf, "/CODE") == 0 ||
strcasecmp(buf, "/TT") == 0 ||
strcasecmp(buf, "/KBD") == 0 ||
strcasecmp(buf, "/VAR") == 0)
popfont(font, fsize);
else if (strcasecmp(buf, "/PRE") == 0)
{
popfont(font, fsize);
pre = 0;
}
else if (strcasecmp(buf, "IMG") == 0)
{
Fl_Shared_Image *img = 0;
int width, height;
char wattr[8], hattr[8];
get_attr(attrs, "WIDTH", wattr, sizeof(wattr));
get_attr(attrs, "HEIGHT", hattr, sizeof(hattr));
width = get_length(wattr);
height = get_length(hattr);
if (get_attr(attrs, "SRC", attr, sizeof(attr))) {
img = get_image(attr, width, height);
if (!width) width = img->w();
if (!height) height = img->h();
}
if (!width || !height) {
if (get_attr(attrs, "ALT", attr, sizeof(attr)) == NULL) {
strcpy(attr, "IMG");
}
}
ww = width;
if (needspace && xx > block->x)
xx += (int)fl_width(' ');
if ((xx + ww) > block->w)
{
if (line < 31)
line ++;
xx = block->line[line];
yy += hh;
hh = 0;
}
if (img)
img->draw(xx + x() - leftline_,
yy + y() - fl_height() + fl_descent() + 2);
xx += ww;
if ((height + 2) > hh)
hh = height + 2;
needspace = 0;
}
}
else if (*ptr == '\n' && pre)
{
*s = '\0';
s = buf;
fl_draw(buf, xx + x() - leftline_, yy + y());
if (line < 31)
line ++;
xx = block->line[line];
yy += hh;
hh = fsize + 2;
needspace = 0;
ptr ++;
}
else if (isspace(*ptr))
{
if (pre)
{
if (*ptr == ' ')
*s++ = ' ';
else
{
// Do tabs every 8 columns...
while (((s - buf) & 7))
*s++ = ' ';
}
}
ptr ++;
needspace = 1;
}
else if (*ptr == '&')
{
ptr ++;
int qch = quote_char(ptr);
if (qch < 0)
*s++ = '&';
else {
*s++ = qch;
ptr = strchr(ptr, ';') + 1;
}
if ((fsize + 2) > hh)
hh = fsize + 2;
}
else
{
*s++ = *ptr++;
if ((fsize + 2) > hh)
hh = fsize + 2;
}
}
*s = '\0';
if (s > buf && !pre && !head)
{
ww = (int)fl_width(buf);
if (needspace && xx > block->x)
xx += (int)fl_width(' ');
if ((xx + ww) > block->w)
{
if (line < 31)
line ++;
xx = block->line[line];
yy += hh;
hh = 0;
}
}
if (s > buf && !head)
fl_draw(buf, xx + x() - leftline_, yy + y());
}
fl_pop_clip();
}
//
// 'Fl_Help_View::format()' - Format the help text.
//
void
Fl_Help_View::format()
{
int i; // Looping var
int done; // Are we done yet?
Fl_Help_Block *block, // Current block
*cell; // Current table cell
int cells[MAX_COLUMNS],
// Cells in the current row...
row; // Current table row (block number)
const char *ptr, // Pointer into block
*start, // Pointer to start of element
*attrs; // Pointer to start of element attributes
char *s, // Pointer into buffer
buf[1024], // Text buffer
attr[1024], // Attribute buffer
wattr[1024], // Width attribute buffer
hattr[1024], // Height attribute buffer
linkdest[1024]; // Link destination
int xx, yy, ww, hh; // Size of current text fragment
int line; // Current line in block
int links; // Links for current line
unsigned char font, fsize; // Current font and size
unsigned char border; // Draw border?
int talign, // Current alignment
newalign, // New alignment
head, // In the <HEAD> section?
pre, // <PRE> text?
needspace; // Do we need whitespace?
int table_width, // Width of table
table_offset; // Offset of table
int column, // Current table column number
columns[MAX_COLUMNS];
// Column widths
Fl_Color tc, rc; // Table/row background color
// Reset document width...
hsize_ = w() - 24;
done = 0;
while (!done)
{
// Reset state variables...
done = 1;
nblocks_ = 0;
nlinks_ = 0;
ntargets_ = 0;
size_ = 0;
bgcolor_ = color();
textcolor_ = textcolor();
linkcolor_ = selection_color();
tc = rc = bgcolor_;
strcpy(title_, "Untitled");
if (!value_)
return;
// Setup for formatting...
initfont(font, fsize);
line = 0;
links = 0;
xx = 4;
yy = fsize + 2;
ww = 0;
column = 0;
border = 0;
hh = 0;
block = add_block(value_, xx, yy, hsize_, 0);
row = 0;
head = 0;
pre = 0;
talign = LEFT;
newalign = LEFT;
needspace = 0;
linkdest[0] = '\0';
table_offset = 0;
for (ptr = value_, s = buf; *ptr;)
{
if ((*ptr == '<' || isspace(*ptr)) && s > buf)
{
// Get width...
*s = '\0';
ww = (int)fl_width(buf);
if (!head && !pre)
{
// Check width...
if (ww > hsize_) {
hsize_ = ww;
done = 0;
break;
}
if (needspace && xx > block->x)
ww += (int)fl_width(' ');
// printf("line = %d, xx = %d, ww = %d, block->x = %d, block->w = %d\n",
// line, xx, ww, block->x, block->w);
if ((xx + ww) > block->w)
{
line = do_align(block, line, xx, newalign, links);
xx = block->x;
yy += hh;
block->h += hh;
hh = 0;
}
if (linkdest[0])
add_link(linkdest, xx, yy - fsize, ww, fsize);
xx += ww;
if ((fsize + 2) > hh)
hh = fsize + 2;
needspace = 0;
}
else if (pre)
{
// Add a link as needed...
if (linkdest[0])
add_link(linkdest, xx, yy - hh, ww, hh);
xx += ww;
if ((fsize + 2) > hh)
hh = fsize + 2;
// Handle preformatted text...
while (isspace(*ptr))
{
if (*ptr == '\n')
{
if (xx > hsize_) break;
line = do_align(block, line, xx, newalign, links);
xx = block->x;
yy += hh;
block->h += hh;
hh = fsize + 2;
}
else
xx += (int)fl_width(' ');
if ((fsize + 2) > hh)
hh = fsize + 2;
ptr ++;
}
if (xx > hsize_) {
hsize_ = xx;
done = 0;
break;
}
needspace = 0;
}
else
{
// Handle normal text or stuff in the <HEAD> section...
while (isspace(*ptr))
ptr ++;
}
s = buf;
}
if (*ptr == '<')
{
start = ptr;
ptr ++;
if (strncmp(ptr, "!--", 3) == 0)
{
// Comment...
ptr += 3;
if ((ptr = strstr(ptr, "-->")) != NULL)
{
ptr += 3;
continue;
}
else
break;
}
while (*ptr && *ptr != '>' && !isspace(*ptr))
if (s < (buf + sizeof(buf) - 1))
*s++ = *ptr++;
else
ptr ++;
*s = '\0';
s = buf;
// puts(buf);
attrs = ptr;
while (*ptr && *ptr != '>')
ptr ++;
if (*ptr == '>')
ptr ++;
if (strcasecmp(buf, "HEAD") == 0)
head = 1;
else if (strcasecmp(buf, "/HEAD") == 0)
head = 0;
else if (strcasecmp(buf, "TITLE") == 0)
{
// Copy the title in the document...
for (s = title_;
*ptr != '<' && *ptr && s < (title_ + sizeof(title_) - 1);
*s++ = *ptr++);
*s = '\0';
s = buf;
}
else if (strcasecmp(buf, "A") == 0)
{
if (get_attr(attrs, "NAME", attr, sizeof(attr)) != NULL)
add_target(attr, yy - fsize - 2);
if (get_attr(attrs, "HREF", attr, sizeof(attr)) != NULL)
strlcpy(linkdest, attr, sizeof(linkdest));
}
else if (strcasecmp(buf, "/A") == 0)
linkdest[0] = '\0';
else if (strcasecmp(buf, "BODY") == 0)
{
bgcolor_ = get_color(get_attr(attrs, "BGCOLOR", attr, sizeof(attr)),
color());
textcolor_ = get_color(get_attr(attrs, "TEXT", attr, sizeof(attr)),
textcolor());
linkcolor_ = get_color(get_attr(attrs, "LINK", attr, sizeof(attr)),
selection_color());
}
else if (strcasecmp(buf, "BR") == 0)
{
line = do_align(block, line, xx, newalign, links);
xx = block->x;
block->h += hh;
yy += hh;
hh = 0;
}
else if (strcasecmp(buf, "CENTER") == 0 ||
strcasecmp(buf, "P") == 0 ||
strcasecmp(buf, "H1") == 0 ||
strcasecmp(buf, "H2") == 0 ||
strcasecmp(buf, "H3") == 0 ||
strcasecmp(buf, "H4") == 0 ||
strcasecmp(buf, "H5") == 0 ||
strcasecmp(buf, "H6") == 0 ||
strcasecmp(buf, "UL") == 0 ||
strcasecmp(buf, "OL") == 0 ||
strcasecmp(buf, "DL") == 0 ||
strcasecmp(buf, "LI") == 0 ||
strcasecmp(buf, "DD") == 0 ||
strcasecmp(buf, "DT") == 0 ||
strcasecmp(buf, "HR") == 0 ||
strcasecmp(buf, "PRE") == 0 ||
strcasecmp(buf, "TABLE") == 0)
{
block->end = start;
line = do_align(block, line, xx, newalign, links);
xx = block->x;
block->h += hh;
if (strcasecmp(buf, "UL") == 0 ||
strcasecmp(buf, "OL") == 0 ||
strcasecmp(buf, "DL") == 0)
{
block->h += fsize + 2;
xx += 4 * fsize;
}
else if (strcasecmp(buf, "TABLE") == 0)
{
if (get_attr(attrs, "BORDER", attr, sizeof(attr)))
border = (uchar)atoi(attr);
else
border = 0;
tc = rc = get_color(get_attr(attrs, "BGCOLOR", attr, sizeof(attr)), bgcolor_);
block->h += fsize + 2;
format_table(&table_width, columns, start);
if ((xx + table_width) > hsize_) {
hsize_ = xx + table_width;
done = 0;
break;
}
switch (get_align(attrs, talign))
{
default :
table_offset = 0;
break;
case CENTER :
table_offset = (hsize_ - table_width) / 2 - textsize_;
break;
case RIGHT :
table_offset = hsize_ - table_width - textsize_;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?