fl_help_view.cxx
来自「SRI international 发布的OAA框架软件」· CXX 代码 · 共 2,703 行 · 第 1/5 页
CXX
2,703 行
// 'Fl_Help_View::get_length()' - Get a length value, either absolute or %.
//
int
Fl_Help_View::get_length(const char *l) { // I - Value
int val; // Integer value
if (!l[0]) return 0;
val = atoi(l);
if (l[strlen(l) - 1] == '%') {
if (val > 100) val = 100;
else if (val < 0) val = 0;
val = val * (hsize_ - 24) / 100;
}
return val;
}
//
// 'Fl_Help_View::handle()' - Handle events in the widget.
//
int // O - 1 if we handled it, 0 otherwise
Fl_Help_View::handle(int event) // I - Event to handle
{
int i; // Looping var
int xx, yy; // Adjusted mouse position
Fl_Help_Link *linkp; // Current link
char target[32]; // Current target
switch (event)
{
case FL_PUSH :
if (Fl_Group::handle(event))
return (1);
case FL_MOVE :
xx = Fl::event_x() - x() + leftline_;
yy = Fl::event_y() - y() + topline_;
break;
case FL_LEAVE :
fl_cursor(FL_CURSOR_DEFAULT);
default :
return (Fl_Group::handle(event));
}
// Handle mouse clicks on links...
for (i = nlinks_, linkp = links_; i > 0; i --, linkp ++)
if (xx >= linkp->x && xx < linkp->w &&
yy >= linkp->y && yy < linkp->h)
break;
if (!i)
{
fl_cursor(FL_CURSOR_DEFAULT);
return (1);
}
// Change the cursor for FL_MOTION events, and go to the link for
// clicks...
if (event == FL_MOVE)
fl_cursor(FL_CURSOR_HAND);
else
{
fl_cursor(FL_CURSOR_DEFAULT);
strlcpy(target, linkp->name, sizeof(target));
set_changed();
if (strcmp(linkp->filename, filename_) != 0 && linkp->filename[0])
{
char dir[1024]; // Current directory
char temp[1024], // Temporary filename
*tempptr; // Pointer into temporary filename
if (strchr(directory_, ':') != NULL &&
strchr(linkp->filename, ':') == NULL)
{
if (linkp->filename[0] == '/')
{
strlcpy(temp, directory_, sizeof(temp));
if ((tempptr = strrchr(strchr(directory_, ':') + 3, '/')) != NULL)
strlcpy(tempptr, linkp->filename, sizeof(temp));
else
strlcat(temp, linkp->filename, sizeof(temp));
}
else
snprintf(temp, sizeof(temp), "%s/%s", directory_, linkp->filename);
}
else if (linkp->filename[0] != '/' && strchr(linkp->filename, ':') == NULL)
{
if (directory_[0])
snprintf(temp, sizeof(temp), "%s/%s", directory_, linkp->filename);
else
{
getcwd(dir, sizeof(dir));
snprintf(temp, sizeof(temp), "file:%s/%s", dir, linkp->filename);
}
}
else
strlcpy(temp, linkp->filename, sizeof(temp));
if (linkp->name[0])
snprintf(temp + strlen(temp), sizeof(temp) - strlen(temp), "#%s",
linkp->name);
load(temp);
}
else if (target[0])
topline(target);
else
topline(0);
leftline(0);
}
return (1);
}
//
// 'Fl_Help_View::Fl_Help_View()' - Build a Fl_Help_View widget.
//
Fl_Help_View::Fl_Help_View(int xx, // I - Left position
int yy, // I - Top position
int ww, // I - Width in pixels
int hh, // I - Height in pixels
const char *l)
: Fl_Group(xx, yy, ww, hh, l),
scrollbar_(xx + ww - 17, yy, 17, hh - 17),
hscrollbar_(xx, yy + hh - 17, ww - 17, 17)
{
color(FL_BACKGROUND2_COLOR, FL_SELECTION_COLOR);
title_[0] = '\0';
defcolor_ = FL_FOREGROUND_COLOR;
bgcolor_ = FL_BACKGROUND_COLOR;
textcolor_ = FL_FOREGROUND_COLOR;
linkcolor_ = FL_SELECTION_COLOR;
textfont_ = FL_TIMES;
textsize_ = 12;
value_ = NULL;
ablocks_ = 0;
nblocks_ = 0;
blocks_ = (Fl_Help_Block *)0;
nfonts_ = 0;
link_ = (Fl_Help_Func *)0;
alinks_ = 0;
nlinks_ = 0;
links_ = (Fl_Help_Link *)0;
atargets_ = 0;
ntargets_ = 0;
targets_ = (Fl_Help_Target *)0;
directory_[0] = '\0';
filename_[0] = '\0';
topline_ = 0;
leftline_ = 0;
size_ = 0;
hsize_ = 0;
scrollbar_.value(0, hh, 0, 1);
scrollbar_.step(8.0);
scrollbar_.show();
scrollbar_.callback(scrollbar_callback);
hscrollbar_.value(0, ww, 0, 1);
hscrollbar_.step(8.0);
hscrollbar_.show();
hscrollbar_.callback(hscrollbar_callback);
hscrollbar_.type(FL_HORIZONTAL);
end();
}
//
// 'Fl_Help_View::~Fl_Help_View()' - Destroy a Fl_Help_View widget.
//
Fl_Help_View::~Fl_Help_View()
{
if (nblocks_)
free(blocks_);
if (nlinks_)
free(links_);
if (ntargets_)
free(targets_);
if (value_)
free((void *)value_);
}
//
// 'Fl_Help_View::load()' - Load the specified file.
//
int // O - 0 on success, -1 on error
Fl_Help_View::load(const char *f)// I - Filename to load (may also have target)
{
FILE *fp; // File to read from
long len; // Length of file
char *target; // Target in file
char *slash; // Directory separator
const char *localname; // Local filename
char error[1024]; // Error buffer
char newname[1024]; // New filename buffer
strlcpy(newname, f, sizeof(newname));
if ((target = strrchr(newname, '#')) != NULL)
*target++ = '\0';
if (link_)
localname = (*link_)(this, newname);
else
localname = filename_;
if (!localname)
return (0);
strlcpy(filename_, newname, sizeof(filename_));
strlcpy(directory_, newname, sizeof(directory_));
// Note: We do not support Windows backslashes, since they are illegal
// in URLs...
if ((slash = strrchr(directory_, '/')) == NULL)
directory_[0] = '\0';
else if (slash > directory_ && slash[-1] != '/')
*slash = '\0';
if (value_ != NULL)
{
free((void *)value_);
value_ = NULL;
}
if (strncmp(localname, "ftp:", 4) == 0 ||
strncmp(localname, "http:", 5) == 0 ||
strncmp(localname, "https:", 6) == 0 ||
strncmp(localname, "ipp:", 4) == 0 ||
strncmp(localname, "mailto:", 7) == 0 ||
strncmp(localname, "news:", 5) == 0)
{
// Remote link wasn't resolved...
snprintf(error, sizeof(error),
"<HTML><HEAD><TITLE>Error</TITLE></HEAD>"
"<BODY><H1>Error</H1>"
"<P>Unable to follow the link \"%s\" - "
"no handler exists for this URI scheme.</P></BODY>",
localname);
value_ = strdup(error);
}
else
{
if (strncmp(localname, "file:", 5) == 0)
localname += 5; // Adjust for local filename...
if ((fp = fopen(localname, "rb")) != NULL)
{
fseek(fp, 0, SEEK_END);
len = ftell(fp);
rewind(fp);
value_ = (const char *)calloc(len + 1, 1);
fread((void *)value_, 1, len, fp);
fclose(fp);
}
else
{
snprintf(error, sizeof(error),
"<HTML><HEAD><TITLE>Error</TITLE></HEAD>"
"<BODY><H1>Error</H1>"
"<P>Unable to follow the link \"%s\" - "
"%s.</P></BODY>",
localname, strerror(errno));
value_ = strdup(error);
}
}
format();
if (target)
topline(target);
else
topline(0);
return (0);
}
//
// 'Fl_Help_View::resize()' - Resize the help widget.
//
void
Fl_Help_View::resize(int xx, // I - New left position
int yy, // I - New top position
int ww, // I - New width
int hh) // I - New height
{
Fl_Widget::resize(xx, yy, ww, hh);
scrollbar_.resize(x() + w() - 17, y(), 17, h() - 17);
hscrollbar_.resize(x(), y() + h() - 17, w() - 17, 17);
format();
}
//
// 'Fl_Help_View::topline()' - Set the top line to the named target.
//
void
Fl_Help_View::topline(const char *n) // I - Target name
{
Fl_Help_Target key, // Target name key
*target; // Pointer to matching target
if (ntargets_ == 0)
return;
strlcpy(key.name, n, sizeof(key.name));
target = (Fl_Help_Target *)bsearch(&key, targets_, ntargets_, sizeof(Fl_Help_Target),
(compare_func_t)compare_targets);
if (target != NULL)
topline(target->y);
}
//
// 'Fl_Help_View::topline()' - Set the top line by number.
//
void
Fl_Help_View::topline(int t) // I - Top line number
{
if (!value_)
return;
if (size_ < (h() - 24) || t < 0)
t = 0;
else if (t > size_)
t = size_;
topline_ = t;
scrollbar_.value(topline_, h() - 24, 0, size_);
do_callback();
clear_changed();
redraw();
}
//
// 'Fl_Help_View::leftline()' - Set the left position.
//
void
Fl_Help_View::leftline(int l) // I - Left position
{
if (!value_)
return;
if (hsize_ < (w() - 24) || l < 0)
l = 0;
else if (l > hsize_)
l = hsize_;
leftline_ = l;
hscrollbar_.value(leftline_, w() - 24, 0, hsize_);
redraw();
}
//
// 'Fl_Help_View::value()' - Set the help text directly.
//
void
Fl_Help_View::value(const char *v) // I - Text to view
{
if (!v)
return;
if (value_ != NULL)
free((void *)value_);
value_ = strdup(v);
format();
set_changed();
topline(0);
leftline(0);
}
//
// 'quote_char()' - Return the character code associated with a quoted char.
//
static int // O - Code or -1 on error
quote_char(const char *p) { // I - Quoted string
int i; // Looping var
static struct {
const char *name;
int namelen;
int code;
} *nameptr, // Pointer into name array
names[] = { // Quoting names
{ "Aacute;", 7, 193 },
{ "aacute;", 7, 225 },
{ "Acirc;", 6, 194 },
{ "acirc;", 6, 226 },
{ "acute;", 6, 180 },
{ "AElig;", 6, 198 },
{ "aelig;", 6, 230 },
{ "Agrave;", 7, 192 },
{ "agrave;", 7, 224 },
{ "amp;", 4, '&' },
{ "Aring;", 6, 197 },
{ "aring;", 6, 229 },
{ "Atilde;", 7, 195 },
{ "atilde;", 7, 227 },
{ "Auml;", 5, 196 },
{ "auml;", 5, 228 },
{ "brvbar;", 7, 166 },
{ "Ccedil;", 7, 199 },
{ "ccedil;", 7, 231 },
{ "cedil;", 6, 184 },
{ "cent;", 5, 162 },
{ "copy;", 5, 169 },
{ "curren;", 7, 164 },
{ "deg;", 4, 176 },
{ "divide;", 7, 247 },
{ "Eacute;", 7, 201 },
{ "eacute;", 7, 233 },
{ "Ecirc;", 6, 202 },
{ "ecirc;", 6, 234 },
{ "Egrave;", 7, 200 },
{ "egrave;", 7, 232 },
{ "ETH;", 4, 208 },
{ "eth;", 4, 240 },
{ "Euml;", 5, 203 },
{ "euml;", 5, 235 },
{ "frac12;", 7, 189 },
{ "frac14;", 7, 188 },
{ "frac34;", 7, 190 },
{ "gt;", 3, '>' },
{ "Iacute;", 7, 205 },
{ "iacute;", 7, 237 },
{ "Icirc;", 6, 206 },
{ "icirc;", 6, 238 },
{ "iexcl;", 6, 161 },
{ "Igrave;", 7, 204 },
{ "igrave;", 7, 236 },
{ "iquest;", 7, 191 },
{ "Iuml;", 5, 207 },
{ "iuml;", 5, 239 },
{ "laquo;", 6, 171 },
{ "lt;", 3, '<' },
{ "macr;", 5, 175 },
{ "micro;", 6, 181 },
{ "middot;", 7, 183 },
{ "nbsp;", 5, ' ' },
{ "not;", 4, 172 },
{ "Ntilde;", 7, 209 },
{ "ntilde;", 7, 241 },
{ "Oacute;", 7, 211 },
{ "oacute;", 7, 243 },
{ "Ocirc;", 6, 212 },
{ "ocirc;", 6, 244 },
{ "Ograve;", 7, 210 },
{ "ograve;", 7, 242 },
{ "ordf;", 5, 170 },
{ "ordm;", 5, 186 },
{ "Oslash;", 7, 216 },
{ "oslash;", 7, 248 },
{ "Otilde;", 7, 213 },
{ "otilde;", 7, 245 },
{ "Ouml;", 5, 214 },
{ "ouml;", 5, 246 },
{ "para;", 5, 182 },
{ "plusmn;", 7, 177 },
{ "pound;", 6, 163 },
{ "quot;", 5, '\"' },
{ "raquo;", 6, 187 },
{ "reg;", 4, 174 },
{ "sect;", 5, 167 },
{ "shy;", 4, 173 },
{ "sup1;", 5, 185 },
{ "sup2;", 5, 178 },
{ "sup3;", 5, 179 },
{ "szlig;", 6, 223 },
{ "THORN;", 6, 222 },
{ "thorn;", 6, 254 },
{ "times;", 6, 215 },
{ "Uacute;", 7, 218 },
{ "uacute;", 7, 250 },
{ "Ucirc;", 6, 219 },
{ "ucirc;", 6, 251 },
{ "Ugrave;", 7, 217 },
{ "ugrave;", 7, 249 },
{ "uml;", 4, 168 },
{ "Uuml;", 5, 220 },
{ "uuml;", 5, 252 },
{ "Yacute;", 7, 221 },
{ "yacute;", 7, 253 },
{ "yen;", 4, 165 },
{ "yuml;", 5, 255 }
};
if (isdigit(*p)) return atoi(p);
for (i = (int)(sizeof(names) / sizeof(names[0])), name
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?